2015-10-09 14:13:52 +02:00
< ? php
if ( ! defined ( 'GLPI_ROOT' )) {
2017-05-06 18:38:24 +02:00
die ( " Sorry. You can't access directly to this file " );
2015-10-09 14:13:52 +02:00
}
/**
* Summary of variableStruct
* class used to define case variables passed at case start or injected during process at any time .
*/
class variableStruct {
2017-05-06 18:38:24 +02:00
public $name ;
public $value ;
2015-10-09 14:13:52 +02:00
}
/**
2016-10-25 11:37:01 +02:00
* Summary of getVariableStruct
2015-10-09 14:13:52 +02:00
* class used to get case variables at any time during process .
*/
class getVariableStruct {
2017-05-06 18:38:24 +02:00
public $name ;
2015-10-09 14:13:52 +02:00
}
2017-05-06 18:38:24 +02:00
$pmHideSolution = false ;
2015-10-09 14:13:52 +02:00
2017-02-28 13:56:37 +01:00
2017-05-06 18:38:24 +02:00
if ( ! function_exists ( 'http_formdata_flat_hierarchy' )) {
/**
* Summary of http_formdata_flat_hierarchy
* @ param mixed $data
* @ return array
*/
function http_formdata_flat_hierarchy ( $data ) {
2019-01-14 16:19:24 +01:00
$vars = [];
2017-05-06 18:38:24 +02:00
foreach ( $data as $key => $value ) {
if ( is_array ( $value )) {
2019-01-14 16:19:24 +01:00
$temp = [];
2017-05-06 18:38:24 +02:00
foreach ( $value as $k2 => $val2 ) {
$temp [ $key . '[' . $k2 . ']' ] = $val2 ;
2015-10-09 14:13:52 +02:00
}
2017-05-06 18:38:24 +02:00
$vars = array_merge ( $vars , http_formdata_flat_hierarchy ( $temp ) );
} else {
$vars [ $key ] = $value ;
}
}
return $vars ;
}
2015-10-09 14:13:52 +02:00
2017-02-28 13:56:37 +01:00
}
2015-10-09 14:13:52 +02:00
2017-05-06 18:38:24 +02:00
if ( ! function_exists ( 'stripcslashes_deep' )) {
/**
* Strip c slash for variable & array
*
* @ param $value array or string : item to stripslashes ( array or string )
*
* @ return stripcslashes item
2017-05-04 15:35:32 +02:00
**/
function stripcslashes_deep ( $value ) {
$value = is_array ( $value ) ?
array_map ( 'stripcslashes_deep' , $value ) :
stripcslashes ( $value );
return $value ;
}
}
2015-10-09 14:13:52 +02:00
/**
* PluginProcessmakerProcessmaker short summary .
*
* PluginProcessmakerProcessmaker description .
*
* @ version 1.0
* @ author MoronO
*/
class PluginProcessmakerProcessmaker extends CommonDBTM {
2016-10-25 11:37:01 +02:00
2017-05-06 18:38:24 +02:00
var $serverURL ;
2016-10-25 11:37:01 +02:00
2017-05-06 18:38:24 +02:00
var $config ;
private $pmSoapClient = null ;
private $pmWorkspace = " " ;
private $pmAdminSession = false ;
2016-10-25 11:37:01 +02:00
2017-05-06 18:38:24 +02:00
private $taskWriter = 0 ;
private $pm_group_guid = '' ; // guid for default user group in Process Maker is used for all GLPI user synchronization into ProcessMaker
var $lasterror ;
var $lang ;
2016-10-25 11:37:01 +02:00
2018-07-04 11:24:29 +02:00
static $rightname = '' ;
2015-10-09 14:13:52 +02:00
2018-08-02 16:57:00 +02:00
const ERROR_CREATING_CASE = 11 ;
const ERROR_NO_RIGHTS = 14 ;
const ERROR_CREATING_CASE2 = 100 ;
2018-07-04 11:24:29 +02:00
///**
//* Return the table used to store this object
//*
//* @return string
//**/
2017-12-29 16:32:39 +01:00
static function getTable ( $classname = null ) {
2017-05-06 18:38:24 +02:00
return " glpi_plugin_processmaker_processes " ;
}
2016-10-25 11:37:01 +02:00
2018-08-02 16:57:00 +02:00
/**
* Summary of getAllTypeArray
* @ return string []
*/
static function getAllPMErrorArray () {
2019-01-14 16:19:24 +01:00
$tab = [ self :: ERROR_CREATING_CASE => _x ( 'errors' , 'Error creating case!' , 'processmaker' ),
2018-08-02 16:57:00 +02:00
self :: ERROR_NO_RIGHTS => _x ( 'errors' , 'Can\'t create case: no rights for it!' , 'processmaker' ),
2019-01-14 16:19:24 +01:00
self :: ERROR_CREATING_CASE2 => _x ( 'errors' , 'Error creating case!' , 'processmaker' )];
2018-08-02 16:57:00 +02:00
return $tab ;
}
/**
* Summary of getProcessTypeName
* @ param mixed $value
* @ return mixed
*/
static function getPMErrorMessage ( $value ) {
$tab = static :: getAllPMErrorArray ();
// Return $value if not defined
return ( isset ( $tab [ $value ]) ? $tab [ $value ] : $value );
}
2017-05-06 18:38:24 +02:00
/**
* Summary of addTicketFollowup
* @ param mixed $itemId
* @ param mixed $txtForFollowup
* @ param integer $users_id optional , if null will uses logged - in user
*/
2019-01-14 16:19:24 +01:00
public function addTicketFollowup ( $itemId , $txtForFollowup , $users_id = null ) {
2018-07-26 11:18:47 +02:00
global $DB ;
2017-05-06 18:38:24 +02:00
$fu = new TicketFollowup ();
$fu -> getEmpty (); // to get default values
$input = $fu -> fields ;
if ( isset ( $txtForFollowup [ 'GLPI_TICKET_FOLLOWUP_CONTENT' ] )) {
2018-07-26 11:18:47 +02:00
$input [ 'content' ] = $DB -> escape ( $txtForFollowup [ 'GLPI_TICKET_FOLLOWUP_CONTENT' ]);
2016-10-25 11:37:01 +02:00
}
2017-05-06 18:38:24 +02:00
if ( isset ( $txtForFollowup [ 'GLPI_TICKET_FOLLOWUP_IS_PRIVATE' ] )) {
2018-07-26 11:18:47 +02:00
$input [ 'is_private' ] = $txtForFollowup [ 'GLPI_TICKET_FOLLOWUP_IS_PRIVATE' ];
2016-10-25 11:37:01 +02:00
}
2017-05-06 18:38:24 +02:00
if ( isset ( $txtForFollowup [ 'GLPI_TICKET_FOLLOWUP_REQUESTTYPES_ID' ] )) {
2018-07-26 11:18:47 +02:00
$input [ 'requesttypes_id' ] = $txtForFollowup [ 'GLPI_TICKET_FOLLOWUP_REQUESTTYPES_ID' ];
2016-10-25 11:37:01 +02:00
}
2018-07-26 11:18:47 +02:00
$input [ 'tickets_id' ] = $itemId ;
$input [ 'users_id' ] = ( isset ( $users_id ) ? $users_id : Session :: getLoginUserID ( true )); // $this->taskWriter;
2016-10-25 11:37:01 +02:00
2017-05-06 18:38:24 +02:00
$fu -> add ( $input );
}
2016-10-25 11:37:01 +02:00
2015-10-09 14:13:52 +02:00
2017-05-06 18:38:24 +02:00
/**
* Summary of openSoap
* @ return true if open succeeded , and pmSoapClient is initialized
* false otherwise
*/
2019-01-14 16:19:24 +01:00
private function openSoap () {
2015-10-09 14:13:52 +02:00
2017-05-06 18:38:24 +02:00
try {
if ( $this -> pmSoapClient == null ) {
$this -> lang = substr ( $_SESSION [ " glpilanguage " ], 0 , 2 );
if ( strlen ( $this -> lang ) <> 2 ) {
$this -> lang = " en " ; // by default
}
$this -> config = PluginProcessmakerConfig :: getInstance ();
$this -> pmWorkspace = $this -> config -> fields [ 'pm_workspace' ];
$this -> serverURL = trim ( $this -> config -> fields [ 'pm_server_URL' ], '/' ) . '/sys' . $this -> config -> fields [ 'pm_workspace' ] . '/' . $this -> lang . '/' . $this -> config -> fields [ 'pm_theme' ];
$this -> taskWriter = $this -> config -> fields [ 'users_id' ];
$this -> pm_group_guid = $this -> config -> fields [ 'pm_group_guid' ];
2019-01-14 16:19:24 +01:00
2019-05-21 10:47:15 +02:00
//$cipher_list = openssl_get_cipher_methods(true);
2019-01-14 16:19:24 +01:00
$wsdl = $this -> serverURL . " /services/wsdl2 " ;
$context [ 'ssl' ] = [ 'verify_peer_name' => $this -> config -> fields [ 'ssl_verify' ], // Verification of peer name
'verify_peer' => $this -> config -> fields [ 'ssl_verify' ], // Verification of SSL certificate used
2019-05-21 10:47:15 +02:00
//'ciphers' => 'RSA',
2019-01-14 16:19:24 +01:00
];
2019-05-21 10:47:15 +02:00
$options = [ 'stream_context' => stream_context_create ( $context ),
'soap_version' => SOAP_1_2 ,
'compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP ,
'keep_alive' => false ,
//'trace' => true,
//'exceptions' => false,
//'proxy_host' => 'localhost',
//'proxy_port' => 8889
2019-01-14 16:19:24 +01:00
];
$this -> pmSoapClient = new SoapClient ( $wsdl , $options );
2017-05-06 18:38:24 +02:00
}
2015-10-09 14:13:52 +02:00
2017-05-06 18:38:24 +02:00
return true ;
} catch ( Exception $e ) {
Toolbox :: logDebug ( $e );
$this -> lasterror = $e ;
return false ; //null ;
}
}
2015-10-09 14:13:52 +02:00
2018-07-04 11:24:29 +02:00
/**
* Summary of getPMSessionID
* @ param mixed $case_guid
* @ return mixed
*/
function getPMSessionID () {
return $_SESSION [ " pluginprocessmaker " ][ " session " ][ 'id' ];
}
2017-05-06 18:38:24 +02:00
/**
* Summary of login
* @ param mixed $admin_or_user if true will be admin , otherwise is user name ( or user id ), or current user
* @ return true if login has been correctly done with current GLPI user , or if a PM session was already open
* false if an exception occured ( like SOAP error or PM login error )
*/
2019-01-14 16:19:24 +01:00
function login ( $admin_or_user = false , $case_guid = 'default' ) {
2017-05-06 18:38:24 +02:00
global $DB , $PM_DB ;
try {
$locSession = new stdClass ; // by default empty object
if ( $this -> openSoap ( )) {
$cookie_lifetime = ini_get ( 'session.cookie_lifetime' );
if ( $cookie_lifetime == 0 ) {
$cookie_lifetime = 15 * 60 ; //= 15 minutes
}
if ( $admin_or_user === true ) { // admin rights has been requested, then force new login
$config = PluginProcessmakerConfig :: getInstance ();
2019-01-14 16:19:24 +01:00
$locSession = $this -> pmSoapClient -> login ( [ 'userid' => $config -> fields [ 'pm_admin_user' ], 'password' => Toolbox :: decrypt ( $config -> fields [ 'pm_admin_passwd' ], GLPIKEY )] );
2017-05-06 18:38:24 +02:00
if ( is_object ( $locSession ) && $locSession -> status_code == 0 ) {
$_SESSION [ " pluginprocessmaker " ][ " session " ][ " admin " ] = true ;
$_SESSION [ " pluginprocessmaker " ][ " session " ][ " id " ] = $locSession -> message ;
$_SESSION [ " pluginprocessmaker " ][ " session " ][ " date " ] = $locSession -> timestamp ;
$this -> pmAdminSession = true ;
return true ;
}
} else if ( empty ( $_SESSION [ " pluginprocessmaker " ][ " session " ][ " date " ]) || ( $_SESSION [ " pluginprocessmaker " ][ " session " ][ " admin " ] == true )
|| $this -> pmAdminSession == true
|| date_add ( date_create ( $_SESSION [ " pluginprocessmaker " ][ " session " ][ " date " ] ), new DateInterval ( " PT " . $cookie_lifetime . " S " ) ) < date_create ( date ( " Y-m-d H:i:s " ) ) ) {
2019-01-14 16:19:24 +01:00
// get user from glpi_users table
2017-05-06 18:38:24 +02:00
$gusr = new User ;
if ( is_numeric ( $admin_or_user )) {
2019-01-14 16:19:24 +01:00
$gusr -> getFromDB ( $admin_or_user );
2019-05-21 10:47:15 +02:00
} else if ( $admin_or_user !== false ) {
2019-01-14 16:19:24 +01:00
$gusr -> getFromDBbyName ( $admin_or_user );
2017-05-06 18:38:24 +02:00
} else {
2019-01-14 16:19:24 +01:00
$gusr -> getFromDB ( Session :: getLoginUserID ());
2017-05-06 18:38:24 +02:00
}
2019-01-14 16:19:24 +01:00
if ( $gusr ) {
// get user from glpi_plugin_processmaker_users table
$pmusr = new PluginProcessmakerUser ;
$pmusr -> getFromDB ( $gusr -> getID ());
//if (!isset($pmusr->fields['password']) || $pmusr->fields['password'] == "") {
if ( is_object ( $pmusr ) && array_key_exists ( 'pm_users_id' , $pmusr -> fields )) {
$pass = md5 ( Toolbox :: encrypt ( $gusr -> getID () . $gusr -> getName () . time (), GLPIKEY ) );
//$pmusr->update( array('id' => $pmusr->getID(), 'password' => $pass) );
// and must be updated also in PM db
$PM_DB -> query ( " UPDATE RBAC_USERS SET USR_PASSWORD=' " . $pass . " ' WHERE USR_UID=' " . $pmusr -> fields [ 'pm_users_id' ] . " ' " );
$PM_DB -> query ( " UPDATE USERS SET USR_PASSWORD=' " . $pass . " ' WHERE USR_UID=' " . $pmusr -> fields [ 'pm_users_id' ] . " ' " );
//}
//$locSession = $this->pmSoapClient->login( array( 'userid' => $gusr->fields['name'], 'password' => 'md5:'.$pmusr->fields['password']) );
$locSession = $this -> pmSoapClient -> login ( [ 'userid' => $gusr -> fields [ 'name' ], 'password' => 'md5:' . $pass ] );
if ( is_object ( $locSession ) && $locSession -> status_code == 0 ) {
$_SESSION [ " pluginprocessmaker " ][ " session " ][ " id " ] = $locSession -> message ;
$_SESSION [ " pluginprocessmaker " ][ " session " ][ " date " ] = $locSession -> timestamp ;
$_SESSION [ " pluginprocessmaker " ][ " session " ][ " admin " ] = false ;
$this -> pmAdminSession = false ;
return true ;
}
} else {
Toolbox :: logDebug ( " Processmaker Plugin: $admin_or_user - User not existing in glpi_plugin_processmaker_users table. " );
return false ;
}
} else {
Toolbox :: logDebug ( " Processmaker Plugin: $admin_or_user - User not existing in glpi_users table. " );
return false ;
2017-05-06 18:38:24 +02:00
}
} else {
return true ; // means a session is already existing in $_SESSION["pluginprocessmaker"]["session"]
}
}
2015-10-09 14:13:52 +02:00
2017-05-06 18:38:24 +02:00
$this -> pmAdminSession = false ;
unset ( $_SESSION [ " pluginprocessmaker " ][ " session " ]);
Toolbox :: logDebug ( " Processmaker Plugin: $admin_or_user - Soap problem: " . print_r ( $locSession , true ) );
$this -> lasterror = $locSession ;
return false ;
} catch ( Exception $e ) {
$this -> pmAdminSession = false ;
unset ( $_SESSION [ " pluginprocessmaker " ][ " session " ]);
Toolbox :: logDebug ( $e );
return false ;
}
}
2015-10-09 14:13:52 +02:00
2016-10-25 11:37:01 +02:00
2017-05-06 18:38:24 +02:00
/**
* Summary of processList
* Returns list of processes
* Embedded processList () PM web service call ( definition : http :// wiki . processmaker . com / index . php / 2.0 / ProcessMaker_WSDL_Web_Services #processList.28.29)
* A session must be open before with login ()
* Normalizes output to an array , even when only one element is returned by PM
* @ return an array of processListStruct objects
*/
2019-01-14 16:19:24 +01:00
function processList () {
2017-05-06 18:38:24 +02:00
try {
2019-01-14 16:19:24 +01:00
$pmProcessList = $this -> pmSoapClient -> processList ( [ 'sessionId' => $this -> getPMSessionID ()] );
2017-05-06 18:38:24 +02:00
if ( isset ( $pmProcessList -> processes )) {
if ( is_array ( $pmProcessList -> processes )) {
return $pmProcessList -> processes ;
} else {
2019-01-14 16:19:24 +01:00
return [ 0 => $pmProcessList -> processes ];
2015-10-09 14:13:52 +02:00
}
2017-05-06 18:38:24 +02:00
}
2016-10-25 11:37:01 +02:00
2017-05-06 18:38:24 +02:00
return false ;
2016-10-25 11:37:01 +02:00
2017-05-06 18:38:24 +02:00
} catch ( Exception $e ) {
Toolbox :: logDebug ( $e );
return false ;
}
}
2015-10-09 14:13:52 +02:00
2017-05-06 18:38:24 +02:00
/**
* Summary of getCaseInfo
* returns information about a given case ( as long as the logged in user has privileges to access the case ) .
* Embedded getCaseInfo () PM web service call ( definition : http :// wiki . processmaker . com / index . php / 2.0 / ProcessMaker_WSDL_Web_Services #getCaseInfo.28.29)
* A session must be open before with login ()
* Normalizes output of currentUsers to an array , even when only one element is returned by PM ,
* Note : currentUsers field doesn ' t exist when case is CANCELLED
2018-07-04 11:24:29 +02:00
* @ param $caseGuid : The case GUID , which can be obtained with the caseList () function
2017-05-06 18:38:24 +02:00
* @ param $delIndex : The delegation index , which is a positive integer to identify the current task of the case . If empty then use current delIndex .
* @ return a getCaseInfoResponse object , or false exception occured
*/
2019-01-14 16:19:24 +01:00
function getCaseInfo ( $caseGuid , $delIndex = '' ) {
2017-05-06 18:38:24 +02:00
try {
2019-01-14 16:19:24 +01:00
$pmCaseInfo = $this -> pmSoapClient -> getCaseInfo ( [ 'sessionId' => $this -> getPMSessionID (), 'caseId' => $caseGuid , 'delIndex' => $delIndex ] );
2018-08-02 16:57:00 +02:00
if ( property_exists ( $pmCaseInfo , 'currentUsers' )) {
switch ( $pmCaseInfo -> caseStatus ) {
case 'DRAFT' :
case 'TO_DO' :
// case 'CANCELLED' :
if ( is_object ( $pmCaseInfo -> currentUsers )) {
2019-01-14 16:19:24 +01:00
$pmCaseInfo -> currentUsers = [ 0 => $pmCaseInfo -> currentUsers ];
2018-08-02 16:57:00 +02:00
}
if ( $pmCaseInfo -> currentUsers [ 0 ] -> delThreadStatus == 'PAUSE' ) {
$pmCaseInfo -> caseStatus = " PAUSED " ;
}
break ;
}
2017-05-06 18:38:24 +02:00
}
return $pmCaseInfo ;
} catch ( Exception $e ) {
Toolbox :: logDebug ( $e );
return false ;
}
2015-10-09 14:13:52 +02:00
2017-05-06 18:38:24 +02:00
}
2015-10-09 14:13:52 +02:00
2017-05-06 18:38:24 +02:00
/**
* Summary of routeCase
* routes a case ( i . e . , moves the case to the next task in the process according to its routing rules ) .
* Embedded routeCase () PM web service call ( definition : http :// wiki . processmaker . com / index . php / 2.0 / ProcessMaker_WSDL_Web_Services #routeCase.28.29)
* A session must be open before with login ()
2018-07-04 11:24:29 +02:00
* @ param $case_guid The case ID , which can be obtained with the caseList () function
2017-05-06 18:38:24 +02:00
* @ param $delIndex The delegation index , which is a positive integer to identify the current task of the case . If empty then use current delIndex .
* @ return a routeCaseResponse object , or false exception occured . routing is normalized to be always an array of routeListStruct
*/
2018-07-04 11:24:29 +02:00
function routeCase ( $case_guid , $delIndex ) {
2017-05-06 18:38:24 +02:00
try {
2019-01-14 16:19:24 +01:00
$pmRouteCaseResponse = $this -> pmSoapClient -> routeCase ( [ 'sessionId' => $this -> getPMSessionID (), 'caseId' => $case_guid , 'delIndex' => $delIndex ] );
2017-05-06 18:38:24 +02:00
if ( $pmRouteCaseResponse -> status_code != 0 ) {
Toolbox :: logDebug ( 'routeCase res:' , $pmRouteCaseResponse );
}
2016-10-25 11:37:01 +02:00
2017-05-06 18:38:24 +02:00
if ( property_exists ( $pmRouteCaseResponse , 'routing' ) && is_object ( $pmRouteCaseResponse -> routing )) {
2019-01-14 16:19:24 +01:00
$pmRouteCaseResponse -> routing = [ 0 => $pmRouteCaseResponse -> routing ];
2017-05-06 18:38:24 +02:00
}
2016-10-25 11:37:01 +02:00
2017-05-06 18:38:24 +02:00
return $pmRouteCaseResponse ;
} catch ( Exception $e ) {
Toolbox :: logDebug ( $e );
return false ;
}
}
2016-10-25 11:37:01 +02:00
2017-05-06 18:38:24 +02:00
/**
* Summary of triggerList
* Returns list of triggers
* Embedded triggerList () PM web service call ( definition : http :// wiki . processmaker . com / index . php / 2.0 / ProcessMaker_WSDL_Web_Services #triggerList.28.29)
* A session must be open before with login ()
* Normalizes output to an array , even when only one element is returned by PM
* @ return an array of triggerListStruct objects , or false when exception occured
*/
2019-01-14 16:19:24 +01:00
function triggerList () {
2017-05-06 18:38:24 +02:00
try {
2019-01-14 16:19:24 +01:00
$pmTriggerList = $this -> pmSoapClient -> triggerList ( [ 'sessionId' => $this -> getPMSessionID ()] );
2017-05-06 18:38:24 +02:00
if ( is_array ( $pmTriggerList -> triggers )) {
return $pmTriggerList -> triggers ;
} else {
2019-01-14 16:19:24 +01:00
return [ 0 => $pmTriggerList -> triggers ];
2017-05-06 18:38:24 +02:00
}
} catch ( Exception $e ) {
Toolbox :: logDebug ( $e );
return false ;
}
}
2016-10-25 11:37:01 +02:00
2017-05-06 18:38:24 +02:00
/**
* Summary of taskList
* Returns list of tasks to which the logged - in user is assigned
* Embedded taskList () PM web service call ( definition : http :// wiki . processmaker . com / index . php / 2.0 / ProcessMaker_WSDL_Web_Services #taskList.28.29)
* A session must be open before with login ()
* Normalizes output to an array , even when only one element is returned by PM
* @ return an array of taskListStruct objects , or false when exception occured
*/
2019-01-14 16:19:24 +01:00
function taskList () {
2017-05-06 18:38:24 +02:00
try {
2019-01-14 16:19:24 +01:00
$pmTaskList = $this -> pmSoapClient -> taskList ( [ 'sessionId' => $this -> getPMSessionID ()] );
2017-05-06 18:38:24 +02:00
if ( is_array ( $pmTaskList -> tasks )) {
return $pmTaskList -> tasks ;
} else {
2019-01-14 16:19:24 +01:00
return [ 0 => $pmTaskList -> tasks ];
2017-05-06 18:38:24 +02:00
}
} catch ( Exception $e ) {
Toolbox :: logDebug ( $e );
return false ;
}
}
2015-10-09 14:13:52 +02:00
2016-10-25 11:37:01 +02:00
2017-05-06 18:38:24 +02:00
/**
* Summary of taskCase
* Returns list of tasks to which the logged - in user is assigned
* Embedded taskList () PM web service call ( definition : http :// wiki . processmaker . com / index . php / 2.0 / ProcessMaker_WSDL_Web_Services #taskList.28.29)
* A session must be open before with login ()
* Normalizes output to an array , even when only one element is returned by PM
* @ return array of taskListStruct objects , or false when exception occured
*/
2018-07-04 11:24:29 +02:00
function taskCase ( $case_guid ) {
2017-05-06 18:38:24 +02:00
try {
2019-01-14 16:19:24 +01:00
$pmTaskCase = $this -> pmSoapClient -> taskCase ( [ 'sessionId' => $this -> getPMSessionID (), 'caseId' => $case_guid ] );
2017-05-06 18:38:24 +02:00
if ( is_array ( $pmTaskCase -> taskCases )) {
return $pmTaskCase -> taskCases ;
} else {
2019-01-14 16:19:24 +01:00
return [ 0 => $pmTaskCase -> taskCases ];
2017-05-06 18:38:24 +02:00
}
} catch ( Exception $e ) {
Toolbox :: logDebug ( $e );
return false ;
}
}
2016-10-25 11:37:01 +02:00
2017-05-06 18:38:24 +02:00
/**
* Summary of claimCase
2018-07-04 11:24:29 +02:00
* @ param mixed $case_guid
2017-05-06 18:38:24 +02:00
* @ param mixed $delIndex
* @ return mixed
*/
2018-07-04 11:24:29 +02:00
function claimCase ( $case_guid , $delIndex ) {
2017-05-06 18:38:24 +02:00
try {
2019-01-14 16:19:24 +01:00
$pmClaimCase = $this -> pmSoapClient -> claimCase ( [ 'sessionId' => $this -> getPMSessionID (), 'guid' => $case_guid , 'delIndex' => $delIndex ] );
2017-05-06 18:38:24 +02:00
return $pmClaimCase ;
} catch ( Exception $e ) {
Toolbox :: logDebug ( $e );
return false ;
}
}
2016-10-25 11:37:01 +02:00
2017-05-06 18:38:24 +02:00
/**
* Summary of unpauseCase
* Unpauses a specified case .
* Embedded UnpauseCase () PM web service call ( definition : http :// wiki . processmaker . com / index . php / 2.0 / ProcessMaker_WSDL_Web_Services #UnpauseCase.28.29)
* A session must be open before with login ()
* Normalizes output to an array , even when only one element is returned by PM
2018-07-04 11:24:29 +02:00
* @ param $caseGuid The unique ID of the case .
2017-05-06 18:38:24 +02:00
* @ param $delIndex The delegation index of the current task in the case .
2018-07-04 11:24:29 +02:00
* @ param $userGuid The unique ID of the user who will unpause the case .
2017-05-06 18:38:24 +02:00
* @ return an array of UnpauseCaseStruct , or false when exception occured
*/
2019-01-14 16:19:24 +01:00
function unpauseCase ( $caseGuid , $delIndex , $userGuid ) {
2017-05-06 18:38:24 +02:00
try {
2019-01-14 16:19:24 +01:00
$pmUnpauseCase = $this -> pmSoapClient -> unpauseCase ( [ 'sessionId' => $this -> getPMSessionID (), 'caseUid' => $caseGuid , 'delIndex' => $delIndex , 'userUid' => $userGuid ] );
2017-05-06 18:38:24 +02:00
if ( is_array ( $pmUnpauseCase -> processes )) {
return $pmUnpauseCase -> processes ;
} else {
2019-01-14 16:19:24 +01:00
return [ 0 => $pmUnpauseCase -> processes ];
2017-05-06 18:38:24 +02:00
}
} catch ( Exception $e ) {
Toolbox :: logDebug ( $e );
return false ;
}
}
2015-10-09 14:13:52 +02:00
2017-05-06 18:38:24 +02:00
/**
* Summary of caseList
* returns a list of the cases for the logged - in user .
* Embedded caseList () PM web service call ( definition : http :// wiki . processmaker . com / index . php / 2.0 / ProcessMaker_WSDL_Web_Services #caseList.28.29)
* A session must be open before with login ()
* Normalizes output to an array , even when only one element is returned by PM
* @ return an array of cases , or false when exception occured
*/
2019-01-14 16:19:24 +01:00
function caseList () {
2017-05-06 18:38:24 +02:00
try {
2019-01-14 16:19:24 +01:00
$pmCaseList = $this -> pmSoapClient -> caseList ( [ 'sessionId' => $this -> getPMSessionID ()] );
2017-05-06 18:38:24 +02:00
if ( is_array ( $pmCaseList -> cases )) {
return $pmCaseList -> cases ;
} else {
2019-01-14 16:19:24 +01:00
return [ 0 => $pmCaseList -> cases ];
2017-05-06 18:38:24 +02:00
}
} catch ( Exception $e ) {
Toolbox :: logDebug ( $e );
return false ;
}
}
2015-10-09 14:13:52 +02:00
2018-03-19 16:56:18 +01:00
/**
* Summary of systemInformation
* returns information about the PM system
* Embedded systemInformation () PM web service call ( definition : http :// wiki . processmaker . com / index . php / ProcessMaker_WSDL_Web_Services #systemInformation.28.29)
* A session must be open before with login ()
* @ return an object containing information , or false when exception occured
*/
2019-01-14 16:19:24 +01:00
function systemInformation () {
2018-03-19 16:56:18 +01:00
try {
2019-01-14 16:19:24 +01:00
$pmSystemInfo = $this -> pmSoapClient -> systemInformation ( [ 'sessionId' => $this -> getPMSessionID ()] );
2018-03-19 16:56:18 +01:00
return $pmSystemInfo ;
2019-01-14 16:19:24 +01:00
} catch ( Exception $e ) {
2018-03-19 16:56:18 +01:00
Toolbox :: logDebug ( $e );
return false ;
}
}
2017-05-06 18:38:24 +02:00
/**
* Summary of reassignCase
* reassigns a case to a different user . Note that the logged - in user needs to have the PM_REASSIGNCASE permission in his / her role in order to be able to reassign the case .
* Embedded caseList () PM web service call ( definition : http :// wiki . processmaker . com / index . php / 2.0 / ProcessMaker_WSDL_Web_Services #reassignCase.28.29)
* A session must be open before with login ()
2018-07-04 11:24:29 +02:00
* @ param $caseGuid The case GUID , which can be obtained with the caseList () function .
2017-05-06 18:38:24 +02:00
* @ param $delIndex The current delegation index number of the case , which can be obtained with the caseList () function .
2018-07-04 11:24:29 +02:00
* @ param $userGuidSource The PM user GUID who is currently assigned the case , which can be obtained with the caseList () function .
* @ param $userGuidTarget The PM target user GUID who will be newly assigned to the case , which can be obtained with userList () . The case can only be reassigned to a user who is one of the assigned users or ad - hoc users to the current task in the case .
* @ return stdClass , a pmResponse object , or false when exception occured
2017-05-06 18:38:24 +02:00
*/
2018-07-04 11:24:29 +02:00
function reassignCase ( $caseGuid , $delIndex , $userGuidSource , $userGuidTarget ) {
2017-05-06 18:38:24 +02:00
try {
2018-07-04 11:24:29 +02:00
$pmResults = $this -> pmSoapClient -> reassignCase ( [ 'sessionId' => $this -> getPMSessionID (),
'caseId' => $caseGuid ,
'delIndex' => $delIndex ,
'userIdSource' => $userGuidSource ,
'userIdTarget' => $userGuidTarget ] );
2017-05-06 18:38:24 +02:00
return $pmResults ;
} catch ( Exception $e ) {
Toolbox :: logDebug ( $e );
return false ;
}
}
2016-10-25 11:37:01 +02:00
2015-10-09 14:13:52 +02:00
2017-05-06 18:38:24 +02:00
/**
* Summary of deleteCase
* Deletes a case
* Embedded deleteCase () PM web service call ( definition : http :// wiki . processmaker . com / index . php / 2.0 / ProcessMaker_WSDL_Web_Services #deleteCase.28.29)
* A session must be open before with login ()
* Beware that at any time you may delete a case !!!
* @ param $caseUid The case ID , which can be obtained with the caseList () function .
* @ return A deleteCaseResponse object , or false when exception occured
*/
2019-01-14 16:19:24 +01:00
function deleteCase ( $caseUid ) {
2017-05-06 18:38:24 +02:00
try {
2019-01-14 16:19:24 +01:00
$deleteCaseResponse = $this -> pmSoapClient -> deleteCase ( [ 'sessionId' => $this -> getPMSessionID (), 'caseUid' => $caseUid ] );
2017-05-06 18:38:24 +02:00
return $deleteCaseResponse ;
} catch ( Exception $e ) {
Toolbox :: logDebug ( $e );
return false ;
}
}
2016-10-25 11:37:01 +02:00
2017-05-06 18:38:24 +02:00
/**
* Summary of cancelTask
* Cancels a task
* Embedded cancelCase () PM web service call ( definition : http :// wiki . processmaker . com / index . php / 2.0 / ProcessMaker_WSDL_Web_Services #cancelCase.28.29)
* A session must be open before with login ()
* Beware that this will only cancel the task with delIndex
* in the case of // tasks you must call cancelTask for each running task.
* in the case of one and only one task running , then it will cancel the case
* @ param $caseUid The case ID , which can be obtained with the caseList () function .
* @ param $delIndex The delegation index of the current task in the case .
* @ param $userUid : The unique ID of the user who will unpause the case .
* @ return A cancelCaseResponse object , or false when exception occured
*/
2019-01-14 16:19:24 +01:00
function cancelTask ( $caseUid , $delIndex , $userUid ) {
2017-05-06 18:38:24 +02:00
try {
2019-01-14 16:19:24 +01:00
$cancelTaskResponse = $this -> pmSoapClient -> cancelCase ( [ 'sessionId' => $this -> getPMSessionID (), 'caseUid' => $caseUid , 'delIndex' => $delIndex , 'userUid' => $userUid ] );
2017-05-06 18:38:24 +02:00
return $cancelTaskResponse ;
} catch ( Exception $e ) {
Toolbox :: logDebug ( $e );
return false ;
}
}
2015-10-09 14:13:52 +02:00
2016-10-25 11:37:01 +02:00
2017-05-06 18:38:24 +02:00
/**
* Summary of cancelCase
* Cancels a case
* Embedded cancelCase () PM web service call ( definition : http :// wiki . processmaker . com / index . php / 2.0 / ProcessMaker_WSDL_Web_Services #cancelCase.28.29)
* A session must be open before with login ()
* Beware that this will cancel all running task
* in the case of // tasks you must call cancelCase for each running task.
* in the case of one and only one task is running , then it will cancel the case
* @ param $caseUid The case ID , which can be obtained with the caseList () function .
* @ param $delIndex The delegation index of the current task in the case .
* @ param $userUid : The unique ID of the user who will unpause the case .
* @ return A cancelCaseResponse object , or false when exception occured
*/
2019-01-14 16:19:24 +01:00
function cancelCase ( $caseUid ) {
2017-05-06 18:38:24 +02:00
try {
$pmCaseInfo = $this -> getCaseInfo ( $caseUid );
if ( $pmCaseInfo -> status_code == 0 ) {
foreach ( $pmCaseInfo -> currentUsers as $pmUser ) {
$pmCancelTask = $this -> cancelTask ( $caseUid , $pmUser -> delIndex , $pmUser -> userId );
if ( $pmCancelTask -> status_code != 0 ) {
return $pmCancelTask ;
}
2015-10-09 14:13:52 +02:00
}
2017-05-06 18:38:24 +02:00
}
return $pmCancelTask ;
} catch ( Exception $e ) {
Toolbox :: logDebug ( $e );
return false ;
}
}
2016-10-25 11:37:01 +02:00
2017-05-06 18:38:24 +02:00
/**
* Summary of newCaseImpersonate
* Starts a new case under the name of the logged - in user .
* The task that will be started is the default one ( = must be unique in process definition ) !
* logged - in user must be assigned to this task , otherwise use newCaseImpersonate () to start the case .
* New case is started with DRAFT status .
* Embedded newCaseImpersonate () PM web service call ( definition : http :// wiki . processmaker . com / index . php / 2.0 / ProcessMaker_WSDL_Web_Services #newCaseImpersonate.28.29)
* A session must be open before with login (), in order to call this function .
2018-07-04 11:24:29 +02:00
* @ param $processes_id integer : The GLPI ID of the process that must be used to start a new case
2017-05-06 18:38:24 +02:00
* @ param $userId The ID of the user who initiates the case , which can be obtained with userList () .
* @ param $vars an array of associative variables ( name => value ) that will be injected into the case as case variables
* @ return A newCaseResponse object , or false when exception occured
*/
2019-01-14 16:19:24 +01:00
function newCaseImpersonate ( $processes_id , $userId , $vars = null ) {
2017-05-06 18:38:24 +02:00
try {
2018-07-04 11:24:29 +02:00
$this -> getFromDB ( $processes_id );
2016-10-25 11:37:01 +02:00
2017-05-06 18:38:24 +02:00
if ( $vars !== null ) {
2019-01-14 16:19:24 +01:00
$aVars = [];
2017-05-06 18:38:24 +02:00
foreach ( $vars as $key => $val ) {
$obj = new variableStruct ();
$obj -> name = $key ;
$obj -> value = $val ;
$aVars [] = $obj ;
2015-10-09 14:13:52 +02:00
}
2017-05-06 18:38:24 +02:00
} else {
$aVars = '' ;
}
2019-01-14 16:19:24 +01:00
$newCaseResponse = $this -> pmSoapClient -> newCaseImpersonate ( [ 'sessionId' => $this -> getPMSessionID (), 'processId' => $this -> fields [ 'process_guid' ], 'userId' => $userId , 'taskId' => '' , 'variables' => $aVars ] );
2017-05-06 18:38:24 +02:00
return $newCaseResponse ;
} catch ( Exception $e ) {
Toolbox :: logDebug ( $e );
return false ;
}
}
2016-10-25 11:37:01 +02:00
2017-05-06 18:38:24 +02:00
/**
* Summary of newCase
* Starts a new case under the name of the logged - in user .
* The task that will be started is the default one ( = must be unique in process definition ) !
* logged - in user must be assigned to this task , otherwise use newCaseImpersonate () to start the case .
* New case is started with DRAFT status .
* Embedded newCase () PM web service call ( definition : http :// wiki . processmaker . com / index . php / 2.0 / ProcessMaker_WSDL_Web_Services #newCase.28.29)
* A session must be open before with login ()
2018-07-04 11:24:29 +02:00
* @ param $processes_id integer : the GLPI ID of the process which will be instantied into a case
2017-05-06 18:38:24 +02:00
* @ param array $vars an array of associative variables ( name => value ) that will be injected into the case as case variables
2018-07-04 11:24:29 +02:00
* @ return boolean | newCaseResponse : false when exception occured
2017-05-06 18:38:24 +02:00
*/
2019-01-14 16:19:24 +01:00
function newCase ( $processes_id , $vars = []) {
2017-05-06 18:38:24 +02:00
try {
2018-07-04 11:24:29 +02:00
$this -> getFromDB ( $processes_id );
2017-05-06 18:38:24 +02:00
2019-01-14 16:19:24 +01:00
$aVars = [];
2017-05-06 18:38:24 +02:00
foreach ( $vars as $key => $val ) {
$obj = new variableStruct ();
$obj -> name = $key ;
$obj -> value = $val ;
$aVars [] = $obj ;
}
2015-10-09 14:13:52 +02:00
2019-01-14 16:19:24 +01:00
$newCaseResponse = $this -> pmSoapClient -> newCase ( [ 'sessionId' => $this -> getPMSessionID (), 'processId' => $this -> fields [ 'process_guid' ], 'taskId' => '' , 'variables' => $aVars ] );
2016-10-25 11:37:01 +02:00
2017-05-06 18:38:24 +02:00
return $newCaseResponse ;
} catch ( Exception $e ) {
Toolbox :: logDebug ( $e );
return false ;
}
}
/**
* Summary of sendVariables
* Sends variables to a case .
* Embedded sendVariables () PM web service call ( definition : http :// wiki . processmaker . com / index . php / 2.0 / ProcessMaker_WSDL_Web_Services #sendVariables.28.29)
* A session must be open before with login ()
2018-07-04 11:24:29 +02:00
* @ param string $caseGuid The GUID of the case
2017-05-06 18:38:24 +02:00
* @ param array $vars an array of associative variables ( name => value ) that will be injected into the case as case variables
* @ return A pmResponse object , or false when exception occured
*/
2019-01-14 16:19:24 +01:00
function sendVariables ( $caseGuid , $vars = []) {
2017-05-06 18:38:24 +02:00
if ( count ( $vars ) == 0 ) { // nothing to send
return true ;
}
try {
2019-01-14 16:19:24 +01:00
$aVars = [];
2017-05-06 18:38:24 +02:00
foreach ( $vars as $key => $val ) {
$obj = new variableStruct ();
$obj -> name = $key ;
if ( is_array ( $val )) {
$obj -> value = join ( " | " , $val );
} else {
$obj -> value = $val ;
2015-10-09 14:13:52 +02:00
}
2017-05-06 18:38:24 +02:00
$aVars [] = $obj ;
}
2016-10-25 11:37:01 +02:00
2019-01-14 16:19:24 +01:00
$pmResponse = $this -> pmSoapClient -> sendVariables ( [ 'sessionId' => $this -> getPMSessionID (), 'caseId' => $caseGuid , 'variables' => $aVars ] );
2016-10-25 11:37:01 +02:00
2017-05-06 18:38:24 +02:00
return $pmResponse ;
} catch ( Exception $e ) {
Toolbox :: logDebug ( $e );
return false ;
}
}
2016-10-25 11:37:01 +02:00
2017-05-06 18:38:24 +02:00
/**
* Summary of getVariables
* Gets variables from a case .
* Embedded getVariables () PM web service call ( definition : http :// wiki . processmaker . com / index . php / 2.0 / ProcessMaker_WSDL_Web_Services #getVariables.28.29)
* A session must be open before with login ()
2018-07-04 11:24:29 +02:00
* @ param string $case_guid The uID of the case
2017-05-06 18:38:24 +02:00
* @ param array $vars an array of variable name that will be read from the case as case variables Normalizes output to an array , even when only one element is returned by PM Normalizes output to an array , even when only one element is returned by PM
* Normalizes output to an array , even when only one element is returned by PM
* @ return array : an associative array ( variable_name => value ), or false when exception occured . The return array can be empty if requested variables are not found .
*/
2019-01-14 16:19:24 +01:00
function getVariables ( $case_guid , $vars = []) {
2017-05-06 18:38:24 +02:00
try {
2019-01-14 16:19:24 +01:00
$aVars = [];
2017-05-06 18:38:24 +02:00
foreach ( $vars as $key => $name ) {
$obj = new getVariableStruct ();
$obj -> name = $name ;
$aVars [] = $obj ;
}
2016-10-25 11:37:01 +02:00
2019-01-14 16:19:24 +01:00
$pmvariableListResponse = $this -> pmSoapClient -> getVariables ( [ 'sessionId' => $this -> getPMSessionID (), 'caseId' => $case_guid , 'variables' => $aVars ] );
2016-10-25 11:37:01 +02:00
2019-01-14 16:19:24 +01:00
$variablesArray = [];
2016-10-25 11:37:01 +02:00
2017-05-06 18:38:24 +02:00
if ( $pmvariableListResponse -> status_code == 0 && isset ( $pmvariableListResponse -> variables )) {
if ( is_array ( $pmvariableListResponse -> variables )) {
foreach ( $pmvariableListResponse -> variables as $variable ) {
$variablesArray [ $variable -> name ] = $variable -> value ;
} } else {
$variablesArray [ $pmvariableListResponse -> variables -> name ] = $pmvariableListResponse -> variables -> value ;
}
}
2016-10-25 11:37:01 +02:00
2017-05-06 18:38:24 +02:00
return $variablesArray ;
} catch ( Exception $e ) {
Toolbox :: logDebug ( $e );
return false ;
}
}
2016-10-25 11:37:01 +02:00
2017-05-06 18:38:24 +02:00
/**
* Summary of groupList
* returns a list of the groups . For privileges to see the list , the logged - in user must have the PM_USERS permission in his / her role .
* Embedded groupList () PM web service call ( definition : http :// wiki . processmaker . com / index . php / 2.0 / ProcessMaker_WSDL_Web_Services #groupList.28.29)
* A session must be open before with login ()
* Normalizes output to an array , even when only one element is returned by PM
* @ return an array of groupListStruct , or false when exception occured
*/
2019-01-14 16:19:24 +01:00
function groupList () {
2017-05-06 18:38:24 +02:00
try {
2019-01-14 16:19:24 +01:00
$pmGroupList = $this -> pmSoapClient -> groupList ( [ 'sessionId' => $this -> getPMSessionID ()] );
2017-05-06 18:38:24 +02:00
if ( is_array ( $pmGroupList -> groups )) {
return $pmGroupList -> groups ;
} else {
2019-01-14 16:19:24 +01:00
return [ 0 => $pmGroupList -> groups ];
2017-05-06 18:38:24 +02:00
}
} catch ( Exception $e ) {
Toolbox :: logDebug ( $e );
return false ;
}
}
2015-10-09 14:13:52 +02:00
2017-05-06 18:38:24 +02:00
/**
* Summary of assignUserToGroup
* assigns a user to a group . For privileges to assign a user , the logged - in user must have the PM_USERS permission in his / her role .
* Embedded assignUserToGroup () PM web service call ( definition : http :// wiki . processmaker . com / index . php / 2.0 / ProcessMaker_WSDL_Web_Services #assignUserToGroup.28.29)
* A session must be open before with login ()
* @ param $userId a Processmaker user id ( see userList ())
* @ param $groupId a Processmaker group id ( see groupList ())
* @ return A pmResponse object , or false when exception occured
*/
2019-01-14 16:19:24 +01:00
function assignUserToGroup ( $userId , $groupId ) {
2017-05-06 18:38:24 +02:00
try {
2019-01-14 16:19:24 +01:00
$pmResults = $this -> pmSoapClient -> assignUserToGroup ([ 'sessionId' => $this -> getPMSessionID (),
2017-05-06 18:38:24 +02:00
'userId' => $userId ,
'groupId' => $groupId
2019-01-14 16:19:24 +01:00
] );
2017-05-06 18:38:24 +02:00
return $pmResults ;
} catch ( Exception $e ) {
Toolbox :: logDebug ( $e );
return false ;
}
}
2015-10-09 14:13:52 +02:00
2017-05-06 18:38:24 +02:00
/**
* Summary of createGroup
* creates a new group . For privileges to create a group , the logged - in user must have the PM_USERS permission in his / her role .
* group will be created as 'ACTIVE'
* Embedded createGroup () PM web service call ( definition : http :// wiki . processmaker . com / index . php / 2.0 / ProcessMaker_WSDL_Web_Services #createGroup.28.29)
* A session must be open before with login ()
* @ param $name : the name of the group to be created
* @ return A pmResponse object , or false when exception occured
*/
2019-01-14 16:19:24 +01:00
function createGroup ( $name ) {
2017-05-06 18:38:24 +02:00
try {
2019-01-14 16:19:24 +01:00
$pmResults = $this -> pmSoapClient -> createGroup ([ 'sessionId' => $this -> getPMSessionID (),
'name' => $name ] );
2017-05-06 18:38:24 +02:00
return $pmResults ;
} catch ( Exception $e ) {
Toolbox :: logDebug ( $e );
return false ;
}
}
2015-10-09 14:13:52 +02:00
2017-05-06 18:38:24 +02:00
/**
* Summary of updateGroup
* updates group directly into Processmaker DB
* @ param $group_id : guid of the pm group
* @ param $groupStatus : new status to be set to $group_id , could be 'ACTIVE' or 'INACTIVE'
* @ return true if group status has been modified , false otherwise
*/
2019-01-14 16:19:24 +01:00
function updateGroup ( $group_id , $groupStatus ) {
2017-05-06 18:38:24 +02:00
global $PM_DB ;
$query = " UPDATE GROUPWF SET GRP_STATUS=' $groupStatus ' WHERE GRP_UID=' $group_id '; " ;
$PM_DB -> query ( $query );
if ( $PM_DB -> affected_rows != 1 ) {
return false ;
} else {
return true ;
}
}
2015-10-09 14:13:52 +02:00
2017-05-06 18:38:24 +02:00
/**
* Summary of userList
* returns a list of the Processmaker users . For privileges to see the list , the logged - in user must have the PM_USERS permission in his / her role .
* Embedded userList () PM web service call ( definition : http :// wiki . processmaker . com / index . php / 2.0 / ProcessMaker_WSDL_Web_Services #userList.28.29)
* A session must be open before with login ()
* Normalizes output to an array , even if only one element is returned by PM
* @ return an array of userListStruct , or false when exception occured
*/
2019-01-14 16:19:24 +01:00
function userList () {
2017-05-06 18:38:24 +02:00
try {
2019-01-14 16:19:24 +01:00
$pmUserList = $this -> pmSoapClient -> userList ( [ 'sessionId' => $this -> getPMSessionID ()] );
2017-05-06 18:38:24 +02:00
if ( is_array ( $pmUserList -> users )) {
return $pmUserList -> users ;
} else {
2019-01-14 16:19:24 +01:00
return [ 0 => $pmUserList -> users ];
2017-05-06 18:38:24 +02:00
}
} catch ( Exception $e ) {
Toolbox :: logDebug ( $e );
return false ;
}
}
2015-10-09 14:13:52 +02:00
2017-05-06 18:38:24 +02:00
/**
* Summary of createUser
* creates a new user . For privileges to create a user , the logged - in user must have the PM_USERS permission in his / her role .
* Embedded createUser () PM web service call ( definition : http :// wiki . processmaker . com / index . php / 2.0 / ProcessMaker_WSDL_Web_Services #createUser.28.29)
* A session must be open before with login ()
* @ param $userId The username for the new user . The unique ID for the user will be automatically generated . Is the user Windows login !
* @ param $firstname The user ' s first name . If empty ( == null or == " " ) will default to $userId .
* @ param $lastname The user ' s last name . If empty ( == null or == " " ) will default to $userId .
* @ param $email The user ' s email address . If empty ( == null or == " " ) will default to $userId @ DoNotReply . com .
* @ param $role The user 's role, such as ' PROCESSMAKER_ADMIN ', ' PROCESSMAKER_MANAGER ' or ' PROCESSMAKER_OPERATOR ' . Possible values can be looked up with the roleList () function .
* @ param $password The user 's password, such as ' Be @ gle2 ' . ( It will be automatically converted into an MD5 hash when inserted in the database . )
* @ param $status The user ' s status , such as " ACTIVE " , " INACTIVE " .
* @ return returns a createUserResponse object , or false if exception occurred
*/
2019-01-14 16:19:24 +01:00
function createUser ( $userId , $firstname , $lastname , $email , $role , $password , $status ) {
2017-05-06 18:38:24 +02:00
try {
if ( $firstname == null || $firstname == " " ) {
$firstname = $userId ;
}
if ( $lastname == null || $lastname == " " ) {
$lastname = $userId ;
}
if ( $email == " " ) {
$email = $userId . " @DoNotReply.com " ;
}
2019-01-14 16:19:24 +01:00
$pmResults = $this -> pmSoapClient -> createUser ([ 'sessionId' => $this -> getPMSessionID (),
2017-05-06 18:38:24 +02:00
'userId' => $userId ,
'firstname' => $firstname ,
'lastname' => $lastname ,
'email' => $email ,
'role' => $role ,
'password' => $password ,
2019-01-14 16:19:24 +01:00
'status' => $status ] );
2017-05-06 18:38:24 +02:00
return $pmResults ;
} catch ( Exception $e ) {
Toolbox :: logDebug ( $e );
return false ;
}
}
2015-10-09 14:13:52 +02:00
2016-10-25 11:37:01 +02:00
2017-05-06 18:38:24 +02:00
/**
* Summary of updateUser
* updates user information .
* Embedded updateUser () PM web service call ( definition : http :// wiki . processmaker . com / index . php / 2.0 / ProcessMaker_WSDL_Web_Services #updateUser.28.29)
* A session must be open before with login ()
* @ param $userUid the unique Id for the user ( Processmaker user id )
* @ param $userName is the user logon . IT IS STRONGLY ADVISE NOT TO CHANGE THIS INFORMATION
* @ param $firstname The user ' s first name . If empty ( == null or == " " ) will default to $userName .
* @ param $lastname The user ' s last name . If empty ( == null or == " " ) will default to $userName .
* @ param $status The user ' s status , such as " ACTIVE " , " INACTIVE " .
* @ return returns a UpdateUserResponse object , or false if exception occurred
*/
2019-01-14 16:19:24 +01:00
function updateUser ( $userUid , $userName , $firstName , $lastName , $status ) {
2017-05-06 18:38:24 +02:00
try {
if ( $firstName == null || $firstName == " " ) {
$firstName = $userName ;
}
if ( $lastName == null || $lastName == " " ) {
$lastName = $userName ;
}
2015-10-09 14:13:52 +02:00
2019-01-14 16:19:24 +01:00
$pmResults = $this -> pmSoapClient -> updateUser ([ 'sessionId' => $this -> getPMSessionID (),
2017-05-06 18:38:24 +02:00
'userUid' => $userUid ,
'userName' => $userName ,
'firstName' => $firstName ,
'lastName' => $lastName ,
'status' => $status
2019-01-14 16:19:24 +01:00
] );
2017-05-06 18:38:24 +02:00
return $pmResults ;
} catch ( Exception $e ) {
Toolbox :: logDebug ( $e );
return false ;
}
}
2016-10-25 11:37:01 +02:00
2017-05-06 18:38:24 +02:00
/**
* Summary of executeTrigger
* executes a ProcessMaker trigger .
* Note that triggers which are tied to case derivation will be executed automatically , so this function does not need to be called when deriving cases .
* Embedded executeTrigger () PM web service call ( definition : http :// wiki . processmaker . com / index . php / 2.0 / ProcessMaker_WSDL_Web_Services #executeTrigger.28.29)
* A session must be open before with login ()
* @ param $caseId The case ID , which is can be found with caseList () .
* @ param $triggerIndex The ID of the trigger to execute , which can be found with triggerList () .
* @ param $delIndex The delegation index number of the case , which can be found with caseList () .
* @ return A pmResponse object . If successful , the message will contain " executed: <TRIGGER_CODE> " . Otherwise false in case of SOAP error
*/
2019-01-14 16:19:24 +01:00
function executeTrigger ( $caseId , $triggerIndex , $delIndex ) {
2017-05-06 18:38:24 +02:00
try {
2019-01-14 16:19:24 +01:00
$pmResults = $this -> pmSoapClient -> executeTrigger ([ 'sessionId' => $this -> getPMSessionID (), 'caseId' => $caseId , 'triggerIndex' => $triggerIndex , 'delIndex' => $delIndex ] );
2017-05-06 18:38:24 +02:00
return $pmResults ;
} catch ( Exception $e ) {
Toolbox :: logDebug ( $e );
return false ;
}
}
2016-10-25 11:37:01 +02:00
2017-05-06 18:38:24 +02:00
/**
* summary of cronInfo
* Gives localized information about 1 cron task
* @ param $name of the task
* @ return array of strings
*/
static function cronInfo ( $name ) {
switch ( $name ) {
case 'pmusers' :
2019-01-14 16:19:24 +01:00
return [ 'description' => __ ( 'Syncs GLPI users and groups into ProcessMaker.' , 'processmaker' )];
2017-05-06 18:38:24 +02:00
case 'pmorphancases' :
2019-01-14 16:19:24 +01:00
return [ 'description' => __ ( 'Cleaning of orphan cases.' , 'processmaker' ), 'parameter' => __ ( 'Number of days to keep orphan cases' , 'processmaker' )];
2017-05-06 18:38:24 +02:00
case 'pmtaskactions' :
2019-01-14 16:19:24 +01:00
return [ 'description' => __ ( 'To apply task actions between cases.' , 'processmaker' )];
2017-05-06 18:38:24 +02:00
}
2019-01-14 16:19:24 +01:00
return [];
2017-05-06 18:38:24 +02:00
}
2015-10-09 14:13:52 +02:00
2016-10-25 11:37:01 +02:00
/**
2017-02-28 13:56:37 +01:00
* summary of cronPMTaskActions
* Execute 1 task managed by the plugin
* @ param : $task CronTask class for log / stat
* @ return integer
* > 0 : done
* < 0 : to be run again ( not finished )
* 0 : nothing to do
*/
2019-01-14 16:19:24 +01:00
static function cronPMTaskActions ( $crontask = null ) {
2018-07-04 11:24:29 +02:00
global $DB , $PM_DB , $PM_SOAP ;
2019-01-14 16:19:24 +01:00
$dbu = new DbUtils ;
2018-01-29 15:05:49 +01:00
2018-07-04 11:24:29 +02:00
// also create a GLPI session with the processmaker task writer
$usr = new User ;
$config = PluginProcessmakerConfig :: getInstance ();
$usr -> getFromDB ( $config -> fields [ 'users_id' ]);
$save_session = $_SESSION ;
$usr -> loadMinimalSession ( 0 , true );
$_SESSION [ 'glpiparententities' ] = [];
2017-02-28 13:56:37 +01:00
$actionCode = 0 ; // by default
2017-05-06 18:38:24 +02:00
$error = false ;
2019-01-14 16:19:24 +01:00
if ( $crontask ) {
$crontask -> setVolume ( 0 ); // start with zero
}
2017-02-28 13:56:37 +01:00
2017-05-06 18:38:24 +02:00
$existingpmsession = isset ( $_SESSION [ " pluginprocessmaker " ][ " session " ]);
$formerusers_id = 0 ;
2017-02-28 13:56:37 +01:00
// get the list of taskactions to be done
2018-07-04 11:24:29 +02:00
$locCase = new PluginProcessmakerCase ;
2019-01-14 16:19:24 +01:00
foreach ( $DB -> request ( $dbu -> getTableForItemType ( 'PluginProcessmakerCrontaskaction' ), ' `state` = ' . PluginProcessmakerCrontaskaction :: DATA_READY ) as $taskaction ) {
2018-07-04 11:24:29 +02:00
if ( $locCase -> getFromDB ( $taskaction [ 'plugin_processmaker_cases_id' ])) {
// there is an existing case for this crontaskaction.
try {
2017-02-28 13:56:37 +01:00
2019-01-14 16:19:24 +01:00
$users_id = $taskaction [ 'users_id' ];
if ( $formerusers_id != $users_id ) {
2018-07-04 11:24:29 +02:00
unset ( $_SESSION [ " pluginprocessmaker " ][ " session " ]); // to reset previous user login if any
}
2017-02-28 13:56:37 +01:00
2019-01-14 16:19:24 +01:00
$caselink = new PluginProcessmakerCaselink ;
$caselink -> getFromDB ( $taskaction [ 'plugin_processmaker_caselinks_id' ]);
// get current task in current case
$PM_SOAP -> login ( true );
$caseinfo = $locCase -> getCaseInfo ();
$currenttask = false ;
if ( property_exists ( $caseinfo , 'currentUsers' )) {
foreach ( $caseinfo -> currentUsers as $loctask ) {
if ( $loctask -> taskId == $caselink -> fields [ 'targettask_guid' ]) {
$currenttask = $loctask ;
break ;
2018-07-04 11:24:29 +02:00
}
2017-12-29 16:32:39 +01:00
}
}
2017-02-28 13:56:37 +01:00
2019-01-14 16:19:24 +01:00
// if $currenttask is false then it means that the target task MUST not derived
if ( $currenttask ) {
if ( $caselink -> fields [ 'is_targettoimpersonate' ] && ! $taskaction [ 'is_targettoclaim' ]) {
// 1) get the current assigned user for this task
// then must login with the user assigned to the task, and not with the user who did the current task
if ( $currenttask -> userId != '' ) {
// 3) change login: impersonate
$users_id = PluginProcessmakerUser :: getGLPIUserId ( $loctask -> userId );
}
2018-07-04 11:24:29 +02:00
}
2017-02-28 13:56:37 +01:00
2019-01-14 16:19:24 +01:00
$PM_SOAP -> login ( $users_id );
2017-02-28 13:56:37 +01:00
2019-01-14 16:19:24 +01:00
$postdata = json_decode ( $taskaction [ 'postdata' ], true );
// must filter arrays as arrays are grids and index must start at 1 instead of 0 like in json
// TODO: to check if it would be possible to do this in a more generic way
foreach ( $postdata [ 'form' ] as & $field ) {
if ( is_array ( $field )) {
if ( count ( $field ) > 0 ) {
// then must reindex the array starting to 1 instead of 0
array_unshift ( $field , '' );
unset ( $field [ 0 ]);
} else {
$field [] = " " ;
}
}
}
2017-02-28 13:56:37 +01:00
2019-01-14 16:19:24 +01:00
if ( $taskaction [ 'is_targettoclaim' ] && ! $caselink -> fields [ 'is_targettoimpersonate' ]) {
// must do a claim before solving task
if ( ! $PM_SOAP -> claimCase ( $postdata [ 'APP_UID' ], $postdata [ 'DEL_INDEX' ] )) {
throw new Exception ( " Can't claim case " );
}
2017-02-28 13:56:37 +01:00
2019-01-14 16:19:24 +01:00
// do not send notifications
$donotif = self :: saveNotification ( false );
2017-02-28 13:56:37 +01:00
2019-01-14 16:19:24 +01:00
// now manage tasks associated with item
$PM_SOAP -> claimTask ( $postdata [ 'APP_UID' ], $postdata [ 'DEL_INDEX' ], $users_id );
2017-02-28 13:56:37 +01:00
2019-01-14 16:19:24 +01:00
self :: restoreNotification ( $donotif );
2017-02-28 13:56:37 +01:00
2019-01-14 16:19:24 +01:00
}
2017-02-28 13:56:37 +01:00
2019-01-14 16:19:24 +01:00
$tkaction = new PluginProcessmakerCrontaskaction ;
$tkaction -> update ( [ 'id' => $taskaction [ 'id' ], 'state' => PluginProcessmakerCrontaskaction :: DONE ] );
$PM_SOAP -> derivateCase ( $locCase , $postdata , $users_id );
if ( $crontask ) {
$crontask -> addVolume ( 1 );
}
if ( $crontask ) {
$crontask -> log ( " Applied task action id: ' " . $taskaction [ 'id' ] . " ' " );
}
} else {
$tkaction = new PluginProcessmakerCrontaskaction ;
$tkaction -> update ( [ 'id' => $taskaction [ 'id' ], 'state' => PluginProcessmakerCrontaskaction :: NOT_DONE ] );
if ( $crontask ) {
$crontask -> log ( " Task action id: ' " . $taskaction [ 'id' ] . " ' case task not found or not open! " );
}
}
} catch ( Exception $e ) {
if ( $crontask ) {
$crontask -> log ( " Can't apply task action id: ' " . $taskaction [ 'id' ] . " ' " );
}
2018-07-04 11:24:29 +02:00
$error = true ;
}
2017-02-28 13:56:37 +01:00
2019-01-14 16:19:24 +01:00
$formerusers_id = $users_id ;
2018-07-04 11:24:29 +02:00
}
2017-02-28 13:56:37 +01:00
}
2017-05-06 18:38:24 +02:00
if ( $existingpmsession ) {
unset ( $_SESSION [ " pluginprocessmaker " ][ " session " ]); // reset the one created during the foreach
2017-02-28 13:56:37 +01:00
if ( ! Session :: isCron ()) {
2018-07-04 11:24:29 +02:00
$PM_SOAP -> login (); // re-log default user
2017-02-28 13:56:37 +01:00
}
}
2018-07-04 11:24:29 +02:00
// restore previous session
Session :: destroy ();
Session :: start ();
$_SESSION = $save_session ;
2018-01-29 15:05:49 +01:00
2017-05-06 18:38:24 +02:00
if ( $error ) {
return - 1 ;
} else {
2017-02-28 13:56:37 +01:00
return $actionCode ;
2017-05-06 18:38:24 +02:00
}
2017-02-28 13:56:37 +01:00
}
2018-07-04 11:24:29 +02:00
2017-02-28 13:56:37 +01:00
/**
* summary of cronPMOrphanCases
2016-10-25 11:37:01 +02:00
* Execute 1 task managed by the plugin
* @ param : $task CronTask class for log / stat
* @ return integer
* > 0 : done
* < 0 : to be run again ( not finished )
* 0 : nothing to do
*/
2017-05-06 18:38:24 +02:00
static function cronPMOrphanCases ( $task ) {
2018-07-04 11:24:29 +02:00
global $PM_DB , $DB , $PM_SOAP ;
2017-05-06 18:38:24 +02:00
2018-07-04 11:24:29 +02:00
//plugin_processmaker_post_init();
2017-05-06 18:38:24 +02:00
2018-07-04 11:24:29 +02:00
// get list of case assigned to GLPI items
2019-01-14 16:19:24 +01:00
$draftCases = [ 0 ];
2018-08-10 14:57:54 +02:00
$query = " SELECT id FROM glpi_plugin_processmaker_cases WHERE case_status = 'DRAFT'; " ;
2017-05-06 18:38:24 +02:00
foreach ( $DB -> request ( $query ) as $row ) {
2018-08-10 14:57:54 +02:00
$draftCases [] = $row [ 'id' ];
2017-05-06 18:38:24 +02:00
}
$actionCode = 0 ; // by default
$error = false ;
$task -> setVolume ( 0 ); // start with zero
if ( count ( $draftCases ) > 0 ) {
2018-07-04 11:24:29 +02:00
//$PM_SOAP = new self;
$PM_SOAP -> login ( true );
2017-05-06 18:38:24 +02:00
$query = " SELECT * FROM APPLICATION
2016-10-25 11:37:01 +02:00
WHERE APP_DATA LIKE '%s:24:\"GLPI_SELFSERVICE_CREATED\";s:1:\"1\"%'
AND APP_STATUS = 'DRAFT'
AND DATEDIFF ( NOW (), APP_UPDATE_DATE ) > " . $task->fields ['param']. "
AND APP_NUMBER NOT IN ( " .implode(',', $draftCases ). " );
2017-05-06 18:38:24 +02:00
" ;
foreach ( $PM_DB -> request ( $query ) as $row ) {
2018-07-04 11:24:29 +02:00
$ret = $PM_SOAP -> deleteCase ( $row [ 'APP_UID' ] );
2017-05-06 18:38:24 +02:00
$task -> addVolume ( 1 );
if ( $ret !== false ) {
$task -> log ( " Deleted case num: ' " . $row [ 'APP_NUMBER' ] . " ' " );
$actionCode = 1 ;
} else {
$task -> log ( " Can't delete case num: ' " . $row [ 'APP_NUMBER' ] . " ' " );
$error = true ;
}
}
}
if ( $error ) {
return - 1 ;
} else {
return $actionCode ;
}
2015-10-09 14:13:52 +02:00
2017-05-06 18:38:24 +02:00
}
2017-09-01 10:47:29 +02:00
2017-05-06 18:38:24 +02:00
/**
* summary of cronPMUsers
* Executes 1 task managed by the plugin
* @ param $task CronTask class for log / stat
* @ return integer
* > 0 : done
* < 0 : to be run again ( not finished )
* 0 : nothing to do
*/
static function cronPMUsers ( $task ) {
2018-07-04 11:24:29 +02:00
global $DB , $PM_DB , $PM_SOAP ;
2017-05-06 18:38:24 +02:00
2018-07-04 11:24:29 +02:00
//plugin_processmaker_post_init();
2017-05-06 18:38:24 +02:00
$actionCode = 0 ; // by default
$error = false ;
$task -> setVolume ( 0 ); // start with zero
// start a processmaker session
2018-07-13 15:58:47 +02:00
if ( ! isset ( $PM_SOAP )) {
$PM_SOAP = new PluginProcessmakerProcessmaker ();
}
2018-07-04 11:24:29 +02:00
if ( ! $PM_SOAP -> login ( true )) {
$task -> log ( " Error PM: ' " . print_r ( $PM_SOAP -> lasterror , true ) . " ' " );
2017-05-06 18:38:24 +02:00
return - 1 ;
}
2018-07-04 11:24:29 +02:00
$pmGroupList = $PM_SOAP -> groupList ( );
2017-05-06 18:38:24 +02:00
foreach ( $pmGroupList as $pmGroup ) {
2018-07-04 11:24:29 +02:00
if ( $pmGroup -> guid == $PM_SOAP -> pm_group_guid ) {
2017-05-06 18:38:24 +02:00
break ; // to get the name :)
}
}
2019-01-14 16:19:24 +01:00
$pmUserList = [];
2018-07-04 11:24:29 +02:00
foreach ( $PM_SOAP -> userList () as $pmuser ) {
2019-01-14 16:19:24 +01:00
$pmUserList [ strtolower ( $pmuser -> name )] = [ 'name' => $pmuser -> name , 'guid' => $pmuser -> guid , 'status' => $pmuser -> status ];
2017-05-06 18:38:24 +02:00
}
// get the complete user list from GLPI DB
2019-01-14 16:19:24 +01:00
$glpiUserList = [];
2017-05-06 18:38:24 +02:00
foreach ( $DB -> request ( " SELECT glpi_users.id, glpi_users.name, glpi_users.realname, glpi_users.firstname, glpi_users.is_active, glpi_users.is_deleted, glpi_plugin_processmaker_users.pm_users_id as pmUserId
FROM glpi_users
LEFT JOIN glpi_plugin_processmaker_users on glpi_plugin_processmaker_users . id = glpi_users . id
WHERE name not like '*%' " ) as $dbgroup ) {
$glpiUserList [ strtolower ( $dbgroup [ 'name' ])] = $dbgroup ;
}
$arrayDiff = array_diff_key ( $glpiUserList , $pmUserList );
foreach ( $arrayDiff as $user ) {
if ( $user [ 'is_active' ] != 0 && $user [ 'is_deleted' ] != 1 ) {
$status = " ACTIVE " ;
$task -> addVolume ( 1 );
$pass = substr ( Toolbox :: encrypt ( $user [ 'id' ] . $user [ 'name' ] . time (), GLPIKEY ), 0 , 20 );
2018-07-04 11:24:29 +02:00
$pmResult = $PM_SOAP -> createUser ( $user [ 'name' ], $user [ 'firstname' ], $user [ 'realname' ], " " , " PROCESSMAKER_OPERATOR " , $pass , $status );
2017-05-06 18:38:24 +02:00
if ( $pmResult -> status_code == 0 ) {
$task -> log ( " Added user: ' " . $user [ 'name' ] . " ' " );
// then assign user to group
2018-07-04 11:24:29 +02:00
$pmResult2 = $PM_SOAP -> assignUserToGroup ( $pmResult -> userUID , $pmGroup -> guid );
2017-05-06 18:38:24 +02:00
if ( $pmResult2 -> status_code == 0 ) {
$task -> log ( " Added user: ' " . $user [ 'name' ] . " ' to ' " . $pmGroup -> name . " ' group " );
} else {
$task -> log ( " Error PM: ' " . $pmResult2 -> message . " ' " );
}
// insert into DB the link between glpi users and pm user
$pmuser = new PluginProcessmakerUser ;
if ( $pmuser -> getFromDB ( $user [ 'id' ] )) {
2019-01-14 16:19:24 +01:00
$pmuser -> update ( [ 'id' => $user [ 'id' ], 'pm_users_id' => $pmResult -> userUID , 'password' => md5 ( $pass ) ] );
2017-05-06 18:38:24 +02:00
} else {
2019-01-14 16:19:24 +01:00
$pmuser -> add ( [ 'id' => $user [ 'id' ], 'pm_users_id' => $pmResult -> userUID , 'password' => md5 ( $pass ) ] );
2017-05-06 18:38:24 +02:00
}
$actionCode = 1 ;
} else {
$task -> log ( " Error adding user: ' " . $user [ 'name' ] . " ' " );
$task -> log ( " Error PM: ' " . $pmResult -> message . " ' " );
$actionCode = - 1 ;
$error = true ;
}
} else {
unset ( $glpiUserList [ $user [ 'name' ]] );
}
}
if ( ! $error ) {
// now should refresh the existing users
$arrayIntersect = array_intersect_key ( $glpiUserList , $pmUserList );
foreach ( $arrayIntersect as $user ) {
if ( $user [ 'pmUserId' ] == null || ( $user [ 'pmUserId' ] != $pmUserList [ strtolower ( $user [ 'name' ])][ 'guid' ])) { //must be inserted into DB
// insert into DB the link between glpi users and pm user
$pmuser = new PluginProcessmakerUser ;
if ( $pmuser -> getFromDB ( $user [ 'id' ] )) {
2019-01-14 16:19:24 +01:00
$ret = $pmuser -> update ( [ 'id' => $user [ 'id' ], 'pm_users_id' => $pmUserList [ strtolower ( $user [ 'name' ])][ 'guid' ] ] );
2017-05-06 18:38:24 +02:00
} else {
2019-01-14 16:19:24 +01:00
$ret = $pmuser -> add ( [ 'id' => $user [ 'id' ], 'pm_users_id' => $pmUserList [ strtolower ( $user [ 'name' ])][ 'guid' ] ] );
2017-05-06 18:38:24 +02:00
}
//$query = "REPLACE INTO glpi_plugin_processmaker_users (glpi_users_id, pm_users_id) VALUES (".$user['id'].", '". $pmUserList[strtolower($user['name'])]['guid']."');" ;
//$DB->query( $query ) or
if ( ! $ret ) {
$task -> log ( " Cannot update user: ' " . $user [ 'id' ] . " ' into glpi_plugin_processmaker_users! " );
}
}
if ( $user [ 'is_active' ] == 0 || $user [ 'is_deleted' ] == 1 ) {
$status = " INACTIVE " ;
} else {
$status = " ACTIVE " ;
}
if ( $status != $pmUserList [ strtolower ( $user [ 'name' ])][ 'status' ]) {
$task -> addVolume ( 1 );
2018-07-04 11:24:29 +02:00
$pmResult = $PM_SOAP -> updateUser ( $pmUserList [ strtolower ( $user [ 'name' ])][ 'guid' ], $user [ 'name' ], $user [ 'firstname' ], $user [ 'realname' ], $status );
2017-05-06 18:38:24 +02:00
if ( $pmResult -> status_code == 0 ) {
$task -> log ( " Updated user: ' " . $user [ 'name' ] . " ', status: ' " . $pmUserList [ strtolower ( $user [ 'name' ])][ 'status' ] . " ' -> ' " . $status . " ' " );
$actionCode = 1 ;
} else {
$task -> log ( " Error updating user: ' " . $user [ 'name' ] . " ' " );
$task -> log ( " Error PM: ' " . $pmResult -> message . " ' " );
$actionCode = - 1 ;
$error = true ;
}
}
2016-10-25 11:37:01 +02:00
2017-05-06 18:38:24 +02:00
}
}
2016-10-25 11:37:01 +02:00
2017-05-06 18:38:24 +02:00
// now we should desactivate PM users who are not in glpi user list
//if( !$error ) {
// $status = "INACTIVE" ;
// $arrayDiff = array_diff_key( $pmUserList , $glpiUserList ) ;
// foreach( $arrayDiff as $user ){
// $task->addVolume(1);
// if( $user['status'] == 'ACTIVE' && $user['name'] != 'admin' && $user['name'] != 'glpi'){
// $pmResult = $myProcessMaker->updateUser( $user['guid'], $user['name'], null, null, $status ) ;
// if( $pmResult->status_code == 0) {
// $task->log( "Updated user: '".$user['name']."', status: '".$user['status']."' -> '".$status."'" ) ;
// $actionCode = 1 ;
// } else {
// $task->log( "Error updating user: '".$user['name']."'" ) ;
// $task->log( "Error PM: '".$pmResult->message."'" ) ;
// $actionCode = -1 ;
// $error = true ;
// }
// }
// }
//}
// so now treat GLPI groups
2019-01-14 16:19:24 +01:00
$glpiGroupList = [];
2017-05-06 18:38:24 +02:00
foreach ( $DB -> request ( " SELECT id, name, is_task, is_usergroup FROM glpi_groups WHERE is_task=1 AND is_usergroup=1 " ) as $dbgroup ) {
$glpiGroupList [ $dbgroup [ 'name' ]] = $dbgroup ;
}
2016-10-25 11:37:01 +02:00
2017-05-06 18:38:24 +02:00
$pmGroupList = self :: getPMGroups (); // array();
2016-10-25 11:37:01 +02:00
2017-05-06 18:38:24 +02:00
// here we can compare group lists like done for the users
$arrayDiff = array_diff_key ( $glpiGroupList , $pmGroupList );
2016-10-25 11:37:01 +02:00
2017-05-06 18:38:24 +02:00
// then for each group we must check if it exists, and if not create a real PM group
foreach ( $arrayDiff as $group ) {
// it is not existing in PM
// then create
2018-07-04 11:24:29 +02:00
$pmResult = $PM_SOAP -> createGroup ( $group [ 'name' ] );
2017-05-06 18:38:24 +02:00
if ( $pmResult -> status_code == 0 ) {
$task -> addVolume ( 1 );
$task -> log ( " Added group: ' " . $group [ 'name' ] . " ' " );
}
}
2016-10-25 11:37:01 +02:00
2017-05-06 18:38:24 +02:00
// review and update all users in each group
$pmGroupList = self :: getPMGroups (); // array();
// now should refresh the existing users into groups
$arrayDiff = array_intersect_key ( $glpiGroupList , $pmGroupList );
foreach ( $arrayDiff as $group ) {
// for each group will delete users and re-create them
// not really optimized, but this way we are sure that groups are synchronized
// must be redesigned
$query = " DELETE FROM GROUP_USER WHERE GROUP_USER.GRP_UID=' " . $pmGroupList [ $group [ 'name' ]][ 'CON_ID' ] . " '; " ;
$PM_DB -> query ( $query );
// and insert all users from real GLPI group
foreach ( $DB -> request ( " SELECT glpi_groups_users.users_id, glpi_plugin_processmaker_users.pm_users_id
2017-02-28 13:56:37 +01:00
FROM glpi_groups
JOIN glpi_groups_users ON glpi_groups_users . groups_id = glpi_groups . id
JOIN glpi_plugin_processmaker_users ON glpi_plugin_processmaker_users . id = glpi_groups_users . users_id
WHERE glpi_groups . name = '".$group[' name ']."' " ) as $user ) {
2017-05-06 18:38:24 +02:00
$query = " INSERT INTO GROUP_USER (`GRP_UID`, `USR_UID`) VALUES ( ' " . $pmGroupList [ $group [ 'name' ]][ 'CON_ID' ] . " ', ' " . $user [ 'pm_users_id' ] . " ' ) " ;
$PM_DB -> query ( $query );
}
$task -> addVolume ( 1 );
$task -> log ( " Updated users into PM group: ' " . $group [ 'name' ] . " ' " );
}
2016-10-25 11:37:01 +02:00
2017-05-06 18:38:24 +02:00
// now should renew the duedate of the users
$PM_DB -> query ( " UPDATE USERS SET USR_DUE_DATE='2035-12-31' WHERE USR_DUE_DATE<>'2035-12-31'; " );
$PM_DB -> query ( " UPDATE RBAC_USERS SET USR_DUE_DATE='2035-12-31' WHERE USR_DUE_DATE<>'2035-12-31'; " );
2016-10-25 11:37:01 +02:00
2017-05-06 18:38:24 +02:00
if ( $error ) {
return - 1 ;
} else {
return $actionCode ;
}
2016-10-25 11:37:01 +02:00
}
2017-05-06 18:38:24 +02:00
public static function plugin_pre_item_add_processmaker ( $parm ) {
global $PM_DB ;
2016-10-25 11:37:01 +02:00
2018-07-04 11:24:29 +02:00
if ( isset ( $parm -> input [ 'processmaker_caseguid' ])) {
2017-05-06 18:38:24 +02:00
// a case is already started for this ticket, then change ticket title and ticket type and ITILCategory
2015-10-09 14:13:52 +02:00
2017-05-06 18:38:24 +02:00
$myProcessMaker = new PluginProcessmakerProcessmaker ( );
$myProcessMaker -> login ( );
2018-07-04 11:24:29 +02:00
$caseInfo = $myProcessMaker -> getCaseInfo ( $parm -> input [ 'processmaker_caseguid' ], $parm -> input [ 'processmaker_delindex' ]);
2017-05-06 18:38:24 +02:00
$parm -> input [ 'name' ] = $PM_DB -> escape ( $caseInfo -> caseName );
2015-10-09 14:13:52 +02:00
2019-05-21 10:47:15 +02:00
$casegetvariables = [ 'GLPI_ITEM_TITLE' , 'GLPI_ITEM_INITIAL_DUE_DATE' , 'GLPI_ITEM_DUE_DATE' ];
$caseresetvariables = [];
$caseDueDate = $myProcessMaker -> getVariables ( $parm -> input [ 'processmaker_caseguid' ], $casegetvariables );
if ( array_key_exists ( 'GLPI_ITEM_INITIAL_DUE_DATE' , $caseDueDate )) {
$parm -> input [ 'time_to_resolve' ] = $caseDueDate [ 'GLPI_ITEM_INITIAL_DUE_DATE' ];
$caseresetvariables [ 'GLPI_ITEM_INITIAL_DUE_DATE' ] = '' ;
}
if ( array_key_exists ( 'GLPI_ITEM_DUE_DATE' , $caseDueDate )) {
$parm -> input [ 'time_to_resolve' ] = $caseDueDate [ 'GLPI_ITEM_DUE_DATE' ];
$caseresetvariables [ 'GLPI_ITEM_DUE_DATE' ] = '' ;
2017-05-06 18:38:24 +02:00
}
2019-05-21 10:47:15 +02:00
$re = '/^(?\'date\'[0-9]{4}-[0-1][0-9]-[0-3][0-9])( (?\'time\'[0-2][0-9]:[0-5][0-9]:[0-5][0-9]))*$/' ;
if ( preg_match ( $re , $parm -> input [ 'time_to_resolve' ], $matches ) && ! array_key_exists ( 'time' , $matches )) {
$parm -> input [ 'time_to_resolve' ] .= " 23:59:59 " ;
}
2017-05-06 18:38:24 +02:00
$txtItemTitle = $caseInfo -> caseName ;
2019-05-21 10:47:15 +02:00
if ( array_key_exists ( 'GLPI_ITEM_TITLE' , $caseDueDate )) {
$txtItemTitle = $caseDueDate [ 'GLPI_ITEM_TITLE' ];
// reset item title case variable
$caseresetvariables [ 'GLPI_ITEM_TITLE' ] = '' ;
2017-05-06 18:38:24 +02:00
}
$parm -> input [ 'name' ] = $PM_DB -> escape ( $txtItemTitle );
2019-05-21 10:47:15 +02:00
if ( count ( $caseresetvariables )) {
$resultSave = $myProcessMaker -> sendVariables ( $parm -> input [ 'processmaker_caseguid' ], $caseresetvariables );
}
2017-05-06 18:38:24 +02:00
$procDef = new PluginProcessmakerProcess ;
2018-07-04 11:24:29 +02:00
$procDef -> getFromGUID ( $caseInfo -> processId );
2017-05-06 18:38:24 +02:00
if ( isset ( $parm -> input [ 'type' ])) {
$parm -> input [ 'type' ] = $procDef -> fields [ 'type' ];
}
if ( isset ( $parm -> input [ 'itilcategories_id' ])) {
$parm -> input [ 'itilcategories_id' ] = $procDef -> fields [ 'itilcategories_id' ];
}
}
}
2015-10-09 14:13:52 +02:00
2019-05-21 10:47:15 +02:00
/**
* Summary of plugin_item_add_processmaker
* @ param mixed $parm
* @ return void
*/
2017-05-06 18:38:24 +02:00
public static function plugin_item_add_processmaker ( $parm ) {
2018-07-04 11:24:29 +02:00
global $DB , $GLOBALS , $PM_SOAP ;
2017-05-06 18:38:24 +02:00
2018-07-04 11:24:29 +02:00
if ( isset ( $parm -> input [ 'processmaker_caseguid' ])) {
2017-05-06 18:38:24 +02:00
// a case is already started for this ticket, then bind them together
2018-07-04 11:24:29 +02:00
$itemtype = $parm -> getType ();
$items_id = $parm -> fields [ 'id' ];
$case_guid = $parm -> input [ 'processmaker_caseguid' ];
2017-05-06 18:38:24 +02:00
2018-07-04 11:24:29 +02:00
$caseInfo = $PM_SOAP -> getCaseInfo ( $case_guid ); //$parm->input['processmaker_delindex']);
2017-05-06 18:38:24 +02:00
2018-07-04 11:24:29 +02:00
$myCase = new PluginProcessmakerCase ;
$myCase -> add ([ 'id' => $parm -> input [ 'processmaker_casenum' ],
'itemtype' => $itemtype ,
'items_id' => $items_id ,
'entities_id' => $parm -> fields [ 'entities_id' ],
'name' => $caseInfo -> caseName ,
'case_guid' => $case_guid ,
'case_status' => $caseInfo -> caseStatus ,
'plugin_processmaker_processes_id' => $parm -> input [ 'processmaker_processes_id' ]
]);
2017-05-06 18:38:24 +02:00
// here we create a fake task that will be used to store the creator of the case
// this is due for traceability only
2019-01-14 16:19:24 +01:00
$PM_SOAP -> add1stTask ( $myCase -> getID (), $myCase -> fields [ 'itemtype' ], $myCase -> fields [ 'items_id' ], $caseInfo , [ 'notif' => false ] ); // no notif
2017-09-01 10:47:29 +02:00
// before routing, send items_id and itemtype
// as this information was not available at case creation
2019-05-21 10:47:15 +02:00
$myCase -> sendVariables ( [ " GLPI_TICKET_ID " => $items_id ,
" GLPI_ITEM_ID " => $items_id ,
" GLPI_ITEM_TYPE " => $itemtype ,
] );
2016-10-25 11:37:01 +02:00
2019-05-21 10:47:15 +02:00
$PM_SOAP -> derivateCase ( $myCase , [ 'DEL_INDEX' => $parm -> input [ 'processmaker_delindex' ]]);
2018-07-04 11:24:29 +02:00
} else { //if( array_key_exists('_head', $parm->input) ) { // this ticket have been created via email receiver.
2017-05-06 18:38:24 +02:00
$ptnProcessToStart = " /##TicketProcess: \ s*#([0-9a-f] { 32}) \ s*##/i " ;
$str = $parm -> input [ 'content' ];
if ( preg_match ( $ptnProcessToStart , $str , $matches ) > 0 ) {
// and it is requested to start a case of process
2018-07-04 11:24:29 +02:00
$processGuid = $matches [ 1 ];
2017-05-06 18:38:24 +02:00
$hasCase = self :: getCaseIdFromItem ( 'Ticket' , $parm -> fields [ 'id' ] );
2018-07-04 11:24:29 +02:00
if ( $hasCase === false ) {
2017-05-06 18:38:24 +02:00
// check writer
$writer = new User ;
$writer -> getFromDB ( $parm -> fields [ 'users_id_recipient' ] );
2018-07-04 11:24:29 +02:00
//$PM_SOAP = new PluginProcessmakerProcessmaker();
$PM_SOAP -> login ( $writer -> fields [ 'name' ] );
2017-05-06 18:38:24 +02:00
$locProcess = new PluginProcessmakerProcess ;
2018-07-04 11:24:29 +02:00
if ( $locProcess -> getFromGUID ( $processGuid )) {
2017-05-06 18:38:24 +02:00
$found = false ;
2018-07-04 11:24:29 +02:00
// check rights of writer to start this $processGuid on the Ticket entity
2017-05-06 18:38:24 +02:00
foreach ( Profile_User :: getUserProfiles ( $writer -> getID () ) as $profID ) {
if ( in_array ( $parm -> fields [ 'entities_id' ], PluginProcessmakerProcess :: getEntitiesForProfileByProcess ( $locProcess -> getID (), $profID , true ) )) {
$found = true ;
break ;
2016-10-25 11:37:01 +02:00
}
}
2017-05-06 18:38:24 +02:00
if ( $found ) {
2018-07-04 11:24:29 +02:00
$PM_SOAP -> startNewCase ( $locProcess -> getID (), 'Ticket' , $parm -> fields [ 'id' ], $writer -> getID () );
2017-05-06 18:38:24 +02:00
}
2016-10-25 11:37:01 +02:00
}
}
2017-05-06 18:38:24 +02:00
}
}
return ;
}
2015-10-09 14:13:52 +02:00
2016-10-25 11:37:01 +02:00
2017-05-06 18:38:24 +02:00
public static function plugin_pre_item_add_processmaker_followup ( $parm ) {
//global $DB ;
2016-10-25 11:37:01 +02:00
2017-05-06 18:38:24 +02:00
}
2015-10-09 14:13:52 +02:00
2016-10-25 11:37:01 +02:00
2019-01-14 16:19:24 +01:00
/**
* Summary of addWatcher
* add $techId as watcher to $glpi_item when techId has no rights on it
* @ param string $itemType is the type of the CommonITILObject
* @ param integer $itemId is the id of the ITIL object
* @ param integer $techId is the users_id to be added
* @ return boolean true if added ,
*/
public static function addWatcher ( $itemType , $itemId , $techId ) {
2018-01-24 14:52:02 +01:00
if ( $techId && $itemType != '' && $itemId > 0 ) {
2019-01-14 16:19:24 +01:00
$dbu = new DbUtils ;
$glpi_item = $dbu -> getItemForItemtype ( $itemType );
2017-05-06 18:38:24 +02:00
$glpi_item -> getFromDB ( $itemId );
2017-02-28 13:56:37 +01:00
// then we should check if this user has rights on the item, if not then we must add it to the watcher list!
2019-01-14 16:19:24 +01:00
$glpi_item = $dbu -> getItemForItemtype ( $itemType );
2017-05-06 18:38:24 +02:00
$glpi_item -> getFromDB ( $itemId );
if ( ! $glpi_item -> isUser ( CommonITILActor :: REQUESTER , $techId )
2017-02-28 13:56:37 +01:00
&& ! $glpi_item -> isUser ( CommonITILActor :: OBSERVER , $techId )
2017-09-01 10:47:29 +02:00
&& ! $glpi_item -> isUser ( CommonITILActor :: ASSIGN , $techId ) ) {
2018-01-24 14:52:02 +01:00
2017-02-28 13:56:37 +01:00
// then we must add this tech user to watcher list
2019-01-14 16:19:24 +01:00
$glpi_item_user = $dbu -> getItemForItemtype ( $glpi_item -> getType () . " _User " );
2018-01-24 14:52:02 +01:00
// do not send notifications
$donotif = self :: saveNotification ( false );
2019-01-14 16:19:24 +01:00
$glpi_item_user -> add ( [ $glpi_item :: getForeignKeyField () => $glpi_item -> getId (), 'users_id' => $techId , 'type' => CommonITILActor :: OBSERVER , '_disablenotif' => true ] );
2018-01-24 14:52:02 +01:00
self :: restoreNotification ( $donotif );
2017-02-28 13:56:37 +01:00
return true ;
}
}
return false ;
}
2016-10-25 11:37:01 +02:00
2017-05-06 18:38:24 +02:00
/**
* Summary of addTask
* adds a GLPI task to given item
2018-07-04 11:24:29 +02:00
* @ param $cases_id integer the GLPI id of the case
2018-07-13 15:58:47 +02:00
* @ param $itemtype string item type to which a task will be added
2018-07-04 11:24:29 +02:00
* @ param $items_id integer item id to which a task will be added
2017-05-06 18:38:24 +02:00
* @ param $caseInfo mixed getCaseInfoResponse object ( see : getCaseInfo () function )
* @ param $delIndex integer index of the delegation
* @ param $techId integer GLPI user id to which a task must be assigned , if == 0 will use $groupId and / or $pmTaskId
2018-07-04 11:24:29 +02:00
* @ param $groupId string PM group guid to assign to task , used when $techId == 0
* @ param $pmTaskId string PM task guid , used when $groupId == 0 AND $techID == 0
2017-05-06 18:38:24 +02:00
* @ param $options array of options , default values are
* 'txtTaskContent' => '' ,
* 'start_date' => '' ,
* 'end_date' => '' ,
* 'notif' => true
* @ return
*/
2019-01-14 16:19:24 +01:00
public function addTask ( $cases_id , $itemtype , $items_id , $caseInfo , $delIndex , $techId , $groupId , $pmTaskId , $delThread , $options = []) {
2018-08-02 16:57:00 +02:00
global $DB , $PM_DB , $_SESSION ;
2019-05-21 10:47:15 +02:00
2019-01-14 16:19:24 +01:00
$dbu = new DbUtils ;
2019-05-21 10:47:15 +02:00
2019-01-14 16:19:24 +01:00
$default_options = [
2017-05-06 18:38:24 +02:00
'txtTaskContent' => '' ,
'start_date' => '' ,
'end_date' => '' ,
2019-05-21 10:47:15 +02:00
'reminder' => '' ,
2017-05-06 18:38:24 +02:00
'notif' => true
2019-01-14 16:19:24 +01:00
];
2019-05-21 10:47:15 +02:00
2017-05-06 18:38:24 +02:00
foreach ( $default_options as $key => $opt ) {
if ( ! isset ( $options [ $key ])) {
$options [ $key ] = $opt ;
}
}
2015-10-09 14:13:52 +02:00
2019-01-14 16:19:24 +01:00
$glpi_task = $dbu -> getItemForItemtype ( " { $itemtype } Task " );
2017-05-06 18:38:24 +02:00
$glpi_task -> getEmpty ();
2019-01-14 16:19:24 +01:00
$input = []; // will contain all data for the Task
2017-05-06 18:38:24 +02:00
2018-07-13 15:58:47 +02:00
$input [ getForeignKeyFieldForItemType ( $itemtype )] = $items_id ;
2017-05-06 18:38:24 +02:00
// search for task category
//
$pmtaskcat = new PluginProcessmakerTaskCategory ;
2018-07-04 11:24:29 +02:00
$pmtaskcat -> getFromGUID ( $pmTaskId );
2017-05-06 18:38:24 +02:00
$input [ 'taskcategories_id' ] = $pmtaskcat -> fields [ 'taskcategories_id' ];
// load process information
$pmProcess = new PluginProcessmakerProcess ;
2018-07-04 11:24:29 +02:00
$pmProcess -> getFromDB ( $pmtaskcat -> fields [ 'plugin_processmaker_processes_id' ] );
2017-05-06 18:38:24 +02:00
if ( $options [ 'start_date' ] == '' ) {
$options [ 'start_date' ] = new DateTime ( $_SESSION [ " glpi_currenttime " ] );
} else {
$options [ 'start_date' ] = new DateTime ( $options [ 'start_date' ] );
}
2016-10-25 11:37:01 +02:00
2017-05-06 18:38:24 +02:00
$input [ 'begin' ] = $options [ 'start_date' ] -> format ( " Y-m-d H:i:s " );
2016-10-25 11:37:01 +02:00
2017-05-06 18:38:24 +02:00
if ( $options [ 'end_date' ] == '' || $options [ 'end_date' ] <= $input [ 'begin' ]) {
$options [ 'end_date' ] = clone $options [ 'start_date' ];
$options [ 'end_date' ] -> add ( new DateInterval ( 'PT15M' ) );
} else {
$options [ 'end_date' ] = new DateTime ( $options [ 'end_date' ] );
}
$input [ 'end' ] = $options [ 'end_date' ] -> format ( " Y-m-d H:i:s " );
$input [ 'plan' ][ 'begin' ] = $input [ 'begin' ];
$temp = $options [ 'start_date' ] -> diff ( $options [ 'end_date' ] );
$input [ 'plan' ][ '_duration' ] = $temp -> d * DAY_TIMESTAMP + $temp -> h * HOUR_TIMESTAMP + $temp -> i * MINUTE_TIMESTAMP + $temp -> s ;
if ( $input [ 'plan' ][ '_duration' ] == 0 ) {
$input [ 'plan' ][ '_duration' ] = 60 ; // at least
}
2016-10-25 11:37:01 +02:00
2017-05-06 18:38:24 +02:00
$input [ 'users_id' ] = $this -> taskWriter ;
// manage groups
2019-05-21 10:47:15 +02:00
if ( $techId == 0 ) { // then we must look-up DB to get the group that will be assigned to the task
2017-05-06 18:38:24 +02:00
$groupname = '' ;
if ( $groupId == 0 ) {
$query = " SELECT CONTENT.CON_VALUE FROM TASK_USER
JOIN CONTENT ON CONTENT . CON_ID = TASK_USER . USR_UID AND CONTENT . CON_CATEGORY = 'GRP_TITLE' AND CONTENT . CON_LANG = 'en'
WHERE TASK_USER . TAS_UID = '$pmTaskId' AND TASK_USER . TU_RELATION = 2 LIMIT 1 ; " ;
} else {
$query = " SELECT CON_VALUE FROM CONTENT
WHERE CONTENT . CON_ID = '$groupId' AND CONTENT . CON_CATEGORY = 'GRP_TITLE' AND CONTENT . CON_LANG = 'en' ; " ;
}
// as there is a LIMIT of 1
// or
// as there is only one group per guid
// then we should have at maximun 1 record
foreach ( $PM_DB -> request ( $query ) as $onlyrec ) {
$groupname = $onlyrec [ 'CON_VALUE' ];
}
2016-10-25 11:37:01 +02:00
2017-05-06 18:38:24 +02:00
$groups_id_tech = 0 ;
$query = " SELECT id AS glpi_group_id FROM glpi_groups WHERE name LIKE ' $groupname '; " ;
$res = $DB -> query ( $query );
if ( $DB -> numrows ( $res ) > 0 ) {
$row = $DB -> fetch_array ( $res );
$groups_id_tech = $row [ 'glpi_group_id' ];
}
} else {
// adds the user tech to ticket watcher if neccessary
2018-07-13 15:58:47 +02:00
self :: addWatcher ( $itemtype , $items_id , $techId );
2017-05-06 18:38:24 +02:00
}
// manage task description
$input [ 'content' ] = " " ; // by default empty :)
if ( $pmProcess -> fields [ " insert_task_comment " ]) {
2018-08-02 16:57:00 +02:00
$input [ 'content' ] .= " ##processmaker.taskcomment## \n " ;
2017-05-06 18:38:24 +02:00
}
2018-05-04 16:06:49 +02:00
if ( $options [ 'txtTaskContent' ] != '' ) {
$input [ 'content' ] .= $options [ 'txtTaskContent' ] . " \n " ;
} else if ( ! $pmProcess -> fields [ " hide_case_num_title " ]) {
2018-08-02 16:57:00 +02:00
$input [ 'content' ] .= __ ( 'Case title: ' , 'processmaker' ) . $caseInfo -> caseName . " \n " ;
2017-05-06 18:38:24 +02:00
}
2018-05-04 16:06:49 +02:00
2018-08-02 16:57:00 +02:00
$input [ 'content' ] .= " ##processmakercase.url## " ;
2017-05-06 18:38:24 +02:00
$input [ 'is_private' ] = 0 ;
$input [ 'actiontime' ] = 0 ;
$input [ 'state' ] = 1 ; // == TO_DO
$input [ 'users_id_tech' ] = 0 ; // by default as it can't be empty
if ( $techId ) {
$input [ 'users_id_tech' ] = $techId ;
} else if ( $groups_id_tech ) {
$input [ 'groups_id_tech' ] = $groups_id_tech ;
}
2019-05-21 10:47:15 +02:00
if ( $options [ 'reminder' ] != '' && $techId ) {
$input [ '_planningrecall' ] = [ 'before_time' => $options [ 'reminder' ],
'itemtype' => get_class ( $glpi_task ),
'items_id' => '' ,
'users_id' => $techId ,
'field' => 'begin' ];
}
2018-07-13 15:58:47 +02:00
$donotif = self :: saveNotification ( false ); // do not send notification yet as the PluginProcessmakerTask is not yet added to DB
2017-05-06 18:38:24 +02:00
$glpi_task -> add ( Toolbox :: addslashes_deep ( $input ) );
2018-01-24 14:52:02 +01:00
self :: restoreNotification ( $donotif );
2017-05-06 18:38:24 +02:00
2018-07-13 15:58:47 +02:00
// to prevent error message for overlapping planning
2019-05-21 10:47:15 +02:00
if ( isset ( $_SESSION [ " MESSAGE_AFTER_REDIRECT " ][ WARNING ])) {
unset ( $_SESSION [ " MESSAGE_AFTER_REDIRECT " ][ WARNING ]);
2018-07-13 15:58:47 +02:00
}
2017-05-06 18:38:24 +02:00
if ( $glpi_task -> getId () > 0 ) {
// stores link to task in DB
2018-07-04 11:24:29 +02:00
//$tmp = new PluginProcessmakerTask($glpi_task->getType());
//$tmp->add([ 'itemtype' => $glpi_task->getType(),
// 'items_id' => $glpi_task->getId(),
// 'plugin_processmaker_cases_id' => $cases_id,
// 'del_index' => $delIndex
// ], [], false);
$query = " INSERT INTO glpi_plugin_processmaker_tasks (items_id, itemtype, plugin_processmaker_cases_id, plugin_processmaker_taskcategories_id, del_index, del_thread)
VALUES ({ $glpi_task -> getId ()}, '{$glpi_task->getType()}' , $cases_id , { $pmtaskcat -> fields [ 'id' ]}, $delIndex , $delThread ); " ;
2017-05-06 18:38:24 +02:00
$DB -> query ( $query );
}
2018-07-13 15:58:47 +02:00
// send notification if needed for new task as now we have the PluginProcessmakerTask in the DB
$donotif = self :: saveNotification ( $options [ 'notif' ]);
$item = new $itemtype ;
$item -> getFromDB ( $items_id );
2019-01-14 16:19:24 +01:00
NotificationEvent :: raiseEvent ( 'add_task' , $item , [ 'task_id' => $glpi_task -> getID (), 'is_private' => isset ( $glpi_task -> fields [ 'is_private' ]) ? $glpi_task -> fields [ 'is_private' ] : 0 ]);
2018-07-13 15:58:47 +02:00
self :: restoreNotification ( $donotif );
2017-05-06 18:38:24 +02:00
}
2018-01-24 14:52:02 +01:00
private static function saveNotification ( $donotif ) {
global $CFG_GLPI ;
// $CFG_GLPI["use_notifications"] is available since 9.2
$savenotif = isset ( $CFG_GLPI [ " use_notifications " ]) ? $CFG_GLPI [ " use_notifications " ] : $CFG_GLPI [ " use_mailing " ];
if ( ! $donotif ) {
isset ( $CFG_GLPI [ " use_notifications " ]) ? $CFG_GLPI [ " use_notifications " ] = false : $CFG_GLPI [ " use_mailing " ] = false ;
}
return $savenotif ;
}
private static function restoreNotification ( $savenotif ) {
global $CFG_GLPI ;
// $CFG_GLPI["use_notifications"] is available since 9.2
isset ( $CFG_GLPI [ " use_notifications " ]) ? $CFG_GLPI [ " use_notifications " ] = $savenotif : $CFG_GLPI [ " use_mailing " ] = $savenotif ;
}
2017-05-06 18:38:24 +02:00
/**
* Summary of add1stTask
* adds a GLPI task to ticket
2018-07-04 11:24:29 +02:00
* @ param $cases_id integer the GLPI id of the case
* @ param $itemType string itemtype of object ( Ticket , Problem , .... )
2017-05-06 18:38:24 +02:00
* @ param $itemId integer item id to which a task will be added
* @ param $caseInfo mixed getCaseInfoResponse object ( see : getCaseInfo () function )
* @ param $options array of options , defaults are :
* 'txtTaskContent' => '' , is content of the task
* 'userId' => false , is user id to be assigned to task
* 'notif' => true , if true notifications will be sent
* @ return
*/
2019-01-14 16:19:24 +01:00
public function add1stTask ( $cases_id , $itemType , $itemId , $caseInfo , $options = []) {
2017-05-06 18:38:24 +02:00
2019-01-14 16:19:24 +01:00
$default_options = [
2017-05-06 18:38:24 +02:00
'txtTaskContent' => '' ,
'userId' => false ,
'notif' => true
2019-01-14 16:19:24 +01:00
];
2017-05-06 18:38:24 +02:00
foreach ( $default_options as $key => $opt ) {
if ( ! isset ( $options [ $key ])) {
$options [ $key ] = $opt ;
}
}
$start_date = new DateTime ( $_SESSION [ " glpi_currenttime " ] );
$official_date_time = $_SESSION [ " glpi_currenttime " ];
$_SESSION [ " glpi_currenttime " ] = $start_date -> sub ( new DateInterval ( " PT1S " )) -> format ( " Y-m-d H:i:s " );
$userId = $options [ 'userId' ] ? $options [ 'userId' ] : Session :: getLoginUserID ();
unset ( $options [ 'userId' ]); // unset it as it's not in the options of addTask
2018-07-04 11:24:29 +02:00
$this -> addTask ( $cases_id ,
$itemType ,
2017-05-06 18:38:24 +02:00
$itemId ,
$caseInfo ,
$caseInfo -> currentUsers [ 0 ] -> delIndex ,
$userId ,
0 ,
$caseInfo -> currentUsers [ 0 ] -> taskId ,
2018-07-04 11:24:29 +02:00
$caseInfo -> currentUsers [ 0 ] -> delThread ,
2017-05-06 18:38:24 +02:00
$options
);
$_SESSION [ " glpi_currenttime " ] = $official_date_time ;
}
/**
* Summary of setItemStatus
* @ param mixed $itemtype
* @ param mixed $itemId
* @ param mixed $newstatus
*/
2019-01-14 16:19:24 +01:00
public function setItemStatus ( $itemtype , $itemId , $newstatus ) {
$dbu = new DbUtils ;
$item = $dbu -> getItemForItemtype ( $itemtype );
2017-05-06 18:38:24 +02:00
if ( $item -> getFromDB ( $itemId )) { //&& $itemtype::isAllowedStatus( $item->fields['status'], $newstatus )) {
2016-10-25 11:37:01 +02:00
//$item->fields['status'] = $newstatus ;
2019-01-14 16:19:24 +01:00
$item -> update ( [ 'id' => $itemId , 'status' => $newstatus ] );
2018-05-14 16:56:52 +02:00
}
}
/**
* Summary of setItemTitle
* @ param mixed $itemtype
* @ param mixed $itemId
* @ param mixed $newtitle
*/
2019-01-14 16:19:24 +01:00
public function setItemTitle ( $itemtype , $itemId , $newtitle ) {
$dbu = new DbUtils ;
$item = $dbu -> getItemForItemtype ( $itemtype );
2018-05-14 16:56:52 +02:00
if ( $item -> getFromDB ( $itemId )) {
2018-07-04 11:24:29 +02:00
$item -> update ( [ 'id' => $itemId , 'name' => $newtitle ] );
2018-05-14 16:56:52 +02:00
}
}
2019-05-21 10:47:15 +02:00
/**
* Summary of setItemDuedate
* @ param mixed $itemtype
* @ param mixed $itemId
* @ param mixed $duedate
*/
public function setItemDuedate ( $itemtype , $itemId , $duedate ) {
$dbu = new DbUtils ;
$item = $dbu -> getItemForItemtype ( $itemtype );
if ( $item -> getFromDB ( $itemId )) {
$item -> update ( [ 'id' => $itemId , 'time_to_resolve' => $duedate ] );
}
}
2018-05-14 16:56:52 +02:00
/**
* Summary of setItemSolution
2018-07-04 11:24:29 +02:00
* @ param mixed $itemType
* @ param mixed $itemId
* @ param mixed $casevariablevalues
2018-05-14 16:56:52 +02:00
*/
public function setItemSolution ( $itemType , $itemId , $casevariablevalues ) {
2019-01-14 16:19:24 +01:00
$dbu = new DbUtils ;
$item = $dbu -> getItemForItemtype ( $itemType );
2018-05-14 16:56:52 +02:00
if ( $item -> getFromDB ( $itemId )) {
// default values
$solutiontemplates_id = 0 ;
$solutiontypes_id = 0 ;
$solution = '' ;
2018-07-04 11:24:29 +02:00
$to_update = false ;
2018-05-14 16:56:52 +02:00
// check solution template
if ( array_key_exists ( 'GLPI_ITEM_SET_SOLUTION_TEMPLATE_ID' , $casevariablevalues )
&& $casevariablevalues [ 'GLPI_ITEM_SET_SOLUTION_TEMPLATE_ID' ] != ''
&& $casevariablevalues [ 'GLPI_ITEM_SET_SOLUTION_TEMPLATE_ID' ] != 0 ) {
// get template
$template = new SolutionTemplate ;
$template -> getFromDB ( $casevariablevalues [ 'GLPI_ITEM_SET_SOLUTION_TEMPLATE_ID' ]);
2019-01-14 16:19:24 +01:00
$entities = $template -> isRecursive () ? $dbu -> getSonsOf ( Entity :: getTable (), $template -> getEntityID ()) : [ $template -> getEntityID ()];
2018-05-14 16:56:52 +02:00
// and check entities
if ( in_array ( $item -> getEntityID (), $entities )) {
$solutiontemplates_id = $template -> getID ();
$solutiontypes_id = $template -> fields [ 'solutiontypes_id' ];
$solution = $template -> fields [ 'content' ];
2018-07-04 11:24:29 +02:00
$to_update = true ;
2018-05-14 16:56:52 +02:00
}
}
// check solution type
if ( array_key_exists ( 'GLPI_ITEM_SET_SOLUTION_TYPE_ID' , $casevariablevalues )
&& $casevariablevalues [ 'GLPI_ITEM_SET_SOLUTION_TYPE_ID' ] != ''
&& $casevariablevalues [ 'GLPI_ITEM_SET_SOLUTION_TYPE_ID' ] != 0 ) {
// get solution type
$type = new SolutionType ;
$type -> getFromDB ( $casevariablevalues [ 'GLPI_ITEM_SET_SOLUTION_TYPE_ID' ]);
2019-01-14 16:19:24 +01:00
$entities = $type -> isRecursive () ? $dbu -> getSonsOf ( Entity :: getTable (), $type -> getEntityID ()) : [ $type -> getEntityID ()];
2018-05-14 16:56:52 +02:00
// and check entities
if ( in_array ( $item -> getEntityID (), $entities )) {
$solutiontypes_id = $type -> getID ();
2018-07-04 11:24:29 +02:00
$to_update = true ;
2018-05-14 16:56:52 +02:00
}
}
// Check solution description
if ( array_key_exists ( 'GLPI_ITEM_APPEND_TO_SOLUTION_DESCRIPTION' , $casevariablevalues )
&& $casevariablevalues [ 'GLPI_ITEM_APPEND_TO_SOLUTION_DESCRIPTION' ] != '' ) {
if ( $solution != '' ) {
$solution .= " \n " ;
}
2019-01-14 16:19:24 +01:00
$solution .= $casevariablevalues [ 'GLPI_ITEM_APPEND_TO_SOLUTION_DESCRIPTION' ];
2018-07-04 11:24:29 +02:00
$to_update = true ;
2018-05-14 16:56:52 +02:00
}
2018-07-04 11:24:29 +02:00
if ( $to_update ) {
$item -> update ( [ 'id' => $itemId , 'solutiontemplates_id' => $solutiontemplates_id , 'solutiontypes_id' => $solutiontypes_id , 'solution' => $solution ] );
}
2017-05-06 18:38:24 +02:00
}
}
2016-10-25 11:37:01 +02:00
2017-05-06 18:38:24 +02:00
/**
* Summary of computeTaskDuration
2017-09-01 10:47:29 +02:00
* @ param mixed $task
* @ param mixed $entity
2017-05-06 18:38:24 +02:00
* @ return mixed
*/
2019-01-14 16:19:24 +01:00
function computeTaskDuration ( $begin , $end , $entity ) {
2015-10-09 14:13:52 +02:00
2019-01-14 16:19:24 +01:00
$calendars_id = Entity :: getUsedConfig ( 'calendars_id' , $entity );
$calendar = new Calendar ();
2015-10-09 14:13:52 +02:00
2019-01-14 16:19:24 +01:00
// Using calendar
if ( $calendars_id > 0 && $calendar -> getFromDB ( $calendars_id )) {
return max ( 0 , $calendar -> getActiveTimeBetween ( $begin , $end ));
2017-05-06 18:38:24 +02:00
}
2019-01-14 16:19:24 +01:00
// Not calendar defined
return max ( 0 , strtotime ( $end ) - strtotime ( $begin ));
2017-05-06 18:38:24 +02:00
}
2015-10-09 14:13:52 +02:00
2017-05-06 18:38:24 +02:00
2016-10-25 11:37:01 +02:00
2017-05-06 18:38:24 +02:00
/**
* Summary of solveTask
2018-07-04 11:24:29 +02:00
* @ param string $cases_id GLPI case id
2017-05-06 18:38:24 +02:00
* @ param int $delIndex
* @ param array $options
2019-01-14 16:19:24 +01:00
* 'txtToAppend' => '' : text to append to solved task
* 'notif' => true : if true will send notifications
* 'users_id_tech' => is the users_id of the tech that solved the task
* 'begin' => is the new begin date of the task
* 'end' => is the new end date of the task
* 'toInformation' => is the new status of the task ( usually set to INFORMATION )
*
2017-05-06 18:38:24 +02:00
*/
2019-01-14 16:19:24 +01:00
public function solveTask ( $cases_id , $delIndex , $options = []) {
2018-01-24 14:52:02 +01:00
global $DB ;
2017-05-06 18:38:24 +02:00
2018-07-04 11:24:29 +02:00
$query = " SELECT * FROM glpi_plugin_processmaker_tasks WHERE plugin_processmaker_cases_id= $cases_id and del_index= $delIndex ; " ;
2017-05-06 18:38:24 +02:00
$res = $DB -> query ( $query );
if ( $DB -> numrows ( $res ) > 0 ) {
2019-01-14 16:19:24 +01:00
$dbu = new DbUtils ;
2017-05-06 18:38:24 +02:00
$row = $DB -> fetch_array ( $res );
$glpi_task = new $row [ 'itemtype' ];
$glpi_task -> getFromDB ( $row [ 'items_id' ] );
2019-01-14 16:19:24 +01:00
$hostItem = $dbu -> getItemForItemtype ( $glpi_task -> getItilObjectItemType () );
2017-05-06 18:38:24 +02:00
$itemFKField = getForeignKeyFieldForItemType ( $glpi_task -> getItilObjectItemType () );
$hostItem -> getFromDB ( $glpi_task -> fields [ $itemFKField ] );
2019-01-14 16:19:24 +01:00
// change current glpi_currenttime to be sure that date_mode for solved task will not be identical than date_mode of the newly started task
//$end_date = new DateTime( $_SESSION["glpi_currenttime"] );
$saved_date_time = $_SESSION [ " glpi_currenttime " ];
$_SESSION [ " glpi_currenttime " ] = ( new DateTime ( $saved_date_time )) -> sub ( new DateInterval ( " PT1S " )) -> format ( " Y-m-d H:i:s " );
$default_options = [
'txtToAppend' => '' ,
'notif' => true ,
'users_id_tech' => null ,
'begin' => $glpi_task -> fields [ 'begin' ] > $_SESSION [ " glpi_currenttime " ] ?
( new DateTime ( $_SESSION [ " glpi_currenttime " ])) -> sub ( new DateInterval ( " PT1S " )) -> format ( " Y-m-d H:i:s " ) :
$glpi_task -> fields [ 'begin' ],
'end' => $_SESSION [ " glpi_currenttime " ],
'toInformation' => false
];
foreach ( $default_options as $key => $opt ) {
if ( ! isset ( $options [ $key ]) || ( $options [ $key ] === '' )) {
$options [ $key ] = $opt ;
}
}
$duration = $this -> computeTaskDuration ( $options [ 'begin' ], $options [ 'end' ], $hostItem -> fields [ 'entities_id' ]);
2017-05-06 18:38:24 +02:00
if ( $options [ 'txtToAppend' ] != " " ) {
$options [ 'txtToAppend' ] = " \n <hr> " . $options [ 'txtToAppend' ];
}
2019-01-14 16:19:24 +01:00
$params = [ 'id' => $row [ 'items_id' ],
'state' => $options [ 'toInformation' ] ? Planning :: INFO : Planning :: DONE ,
'begin' => $options [ 'begin' ],
'end' => $options [ 'end' ],
$itemFKField => $hostItem -> getID (),
'actiontime' => $duration ,
'users_id_tech' => ( isset ( $options [ 'users_id_tech' ]) ? $options [ 'users_id_tech' ] : Session :: getLoginUserID ()),
//'groups_id_tech' => 0,
'content' => $DB -> escape ( $glpi_task -> fields [ 'content' ] . $options [ 'txtToAppend' ])
];
2018-01-24 14:52:02 +01:00
$donotif = self :: saveNotification ( $options [ 'notif' ]);
2019-01-14 16:19:24 +01:00
$glpi_task -> update ( $params );
2018-01-24 14:52:02 +01:00
self :: restoreNotification ( $donotif );
2018-07-04 11:24:29 +02:00
// Close the task
2019-01-14 16:19:24 +01:00
$DB -> query ( " UPDATE glpi_plugin_processmaker_tasks SET del_thread_status = ' " . PluginProcessmakerTask :: CLOSED . " ' WHERE id = { $row [ 'id' ] } " );
2017-04-28 14:57:49 +02:00
2019-01-14 16:19:24 +01:00
// restore current glpi time
$_SESSION [ " glpi_currenttime " ] = $saved_date_time ;
}
2016-10-25 11:37:01 +02:00
2017-05-06 18:38:24 +02:00
}
2016-10-25 11:37:01 +02:00
2017-05-06 18:38:24 +02:00
/**
* Summary of claimTask
* will unassign group , and assign tech
2018-07-04 11:24:29 +02:00
* @ param mixed $cases_id GLPI case id
2017-05-06 18:38:24 +02:00
* @ param mixed $delIndex
* @ param mixed $users_id_tech optional is the id of the tech
* who ' s claimed the task , default current logged - in user
*/
2019-01-14 16:19:24 +01:00
public function claimTask ( $cases_id , $delIndex , $users_id_tech = null ) {
2017-05-06 18:38:24 +02:00
global $DB ;
2017-02-28 13:56:37 +01:00
2018-07-04 11:24:29 +02:00
$query = " SELECT * FROM glpi_plugin_processmaker_tasks WHERE plugin_processmaker_cases_id=' $cases_id ' and del_index= $delIndex ; " ;
2017-05-06 18:38:24 +02:00
$res = $DB -> query ( $query );
if ( $DB -> numrows ( $res ) > 0 ) {
2019-01-14 16:19:24 +01:00
$dbu = new DbUtils ;
2017-05-06 18:38:24 +02:00
$row = $DB -> fetch_array ( $res );
$glpi_task = new $row [ 'itemtype' ];
$glpi_task -> getFromDB ( $row [ 'items_id' ] );
2017-02-28 13:56:37 +01:00
2017-05-06 18:38:24 +02:00
$itemType = str_replace ( 'Task' , '' , $row [ 'itemtype' ] );
2019-01-14 16:19:24 +01:00
$glpi_item = $dbu -> getItemForItemtype ( $itemType );
2017-05-06 18:38:24 +02:00
$glpi_item -> getFromDB ( $glpi_task -> fields [ getForeignKeyFieldForItemType ( $itemType ) ] );
2015-10-09 14:13:52 +02:00
2019-01-14 16:19:24 +01:00
$glpi_task -> update ( [ 'id' => $row [ 'items_id' ],
2017-05-06 18:38:24 +02:00
$glpi_item -> getForeignKeyField () => $glpi_item -> getId (),
'users_id_tech' => ( isset ( $users_id_tech ) ? $users_id_tech : Session :: getLoginUserID ()),
2019-01-14 16:19:24 +01:00
'groups_id_tech' => 0 ]);
2017-05-06 18:38:24 +02:00
}
}
2016-10-25 11:37:01 +02:00
2015-10-09 14:13:52 +02:00
/**
* Summary of getCaseIdFromItem
* get case id for an id item_id of type item_type ( if a case if attached to it )
2017-05-06 18:38:24 +02:00
* @ param string $item_type , the type for the item ( " Ticket " , " Problem " , ... )
* @ param integer $item_id , the id for the item
2017-02-28 13:56:37 +01:00
* @ return string the case guid , false if no case is attached to item , or if an error occurred
2015-10-09 14:13:52 +02:00
*/
2019-01-14 16:19:24 +01:00
public static function getCaseIdFromItem ( $item_type , $item_id ) {
2017-05-06 18:38:24 +02:00
global $DB ;
2016-10-25 11:37:01 +02:00
2017-05-06 18:38:24 +02:00
$query = " SELECT * FROM glpi_plugin_processmaker_cases WHERE `itemtype` = ' $item_type ' AND `items_id` = $item_id ; " ;
$res = $DB -> query ( $query );
if ( $DB -> numrows ( $res ) > 0 ) {
2018-07-04 11:24:29 +02:00
// case is existing for this item
2017-05-06 18:38:24 +02:00
// then get info from db
$row = $DB -> fetch_array ( $res );
2016-10-25 11:37:01 +02:00
2017-05-06 18:38:24 +02:00
return $row [ 'id' ];
}
2016-10-25 11:37:01 +02:00
2017-05-06 18:38:24 +02:00
return false ;
}
2016-10-25 11:37:01 +02:00
2018-07-04 11:24:29 +02:00
/**
* Summary of getCaseGuidFromItem
* get case id for an id item_id of type item_type ( if a case if attached to it )
* @ param string $item_type , the type for the item ( " Ticket " , " Problem " , ... )
* @ param integer $item_id , the id for the item
* @ return string the case guid , false if no case is attached to item , or if an error occurred
*/
2019-01-14 16:19:24 +01:00
public static function getCaseGuidFromItem ( $item_type , $item_id ) {
2018-07-04 11:24:29 +02:00
global $DB ;
$query = " SELECT * FROM glpi_plugin_processmaker_cases WHERE `itemtype` = ' $item_type ' AND `items_id` = $item_id ; " ;
$res = $DB -> query ( $query );
if ( $DB -> numrows ( $res ) > 0 ) {
// case is existing for this item
// then get info from db
$row = $DB -> fetch_array ( $res );
return $row [ 'case_guid' ];
}
return false ;
}
2015-10-09 14:13:52 +02:00
/**
* Summary of getCaseFromItem
* get case infos for an id item_id of type item_type ( if a case if attached to it )
2017-05-06 18:38:24 +02:00
* @ param string $item_type , the type for the item ( " Ticket " , " Problem " , ... )
* @ param integer $item_id , the id for the item
2015-10-09 14:13:52 +02:00
* @ return getCaseInfoResponse object , false if no case is attached to item , or if an error occurred
*/
2019-01-14 16:19:24 +01:00
public function getCaseFromItem ( $item_type , $item_id ) {
2017-05-06 18:38:24 +02:00
global $DB ;
2018-07-04 11:24:29 +02:00
$caseId = self :: getCaseGuidFromItem ( $item_type , $item_id );
2017-05-06 18:38:24 +02:00
if ( $caseId !== false ) {
$caseInfo = $this -> getCaseInfo ( $caseId );
if ( $caseInfo !== false && $caseInfo -> status_code == 0 ) {
return $caseInfo ;
} else {
return false ; // means any error
}
} else {
return false ; // means no case
}
}
2016-10-25 11:37:01 +02:00
2015-10-09 14:13:52 +02:00
/**
* Summary of multiexplode
* @ param $delimiters
* @ param $string
* @ return
*/
2017-05-06 18:38:24 +02:00
static function multiexplode ( $delimiters , $string ) {
2016-10-25 11:37:01 +02:00
2017-05-06 18:38:24 +02:00
$ready = str_replace ( $delimiters , $delimiters [ 0 ], $string );
$launch = explode ( $delimiters [ 0 ], $ready );
return $launch ;
}
2016-10-25 11:37:01 +02:00
2018-05-04 16:06:49 +02:00
/**
2018-07-04 11:24:29 +02:00
* Summary of pre_show_item_processmaker
2018-05-04 16:06:49 +02:00
* @ param $params
*/
2018-07-04 11:24:29 +02:00
public static function pre_show_item_processmaker ( $params ) {
2017-05-06 18:38:24 +02:00
if ( ! is_array ( $params [ 'item' ]) && is_subclass_of ( $params [ 'item' ], 'CommonITILTask' )) {
// must check if Task is bound to a PM task
$pmTask = new PluginProcessmakerTask ( $params [ 'item' ] -> getType ());
2018-07-04 11:24:29 +02:00
if ( $pmTask -> getFromDB ( $params [ 'item' ] -> getId ())) { //$pmTask->getFromDBByQuery("WHERE itemtype='".$params['item']->getType()."' and items_id=".$params['item']->getId())) {
2017-05-06 18:38:24 +02:00
$params [ 'item' ] -> fields [ 'can_edit' ] = false ; // to prevent task edition
// replace ##ticket.url##_PluginProcessmakerCase$processmakercases by a setActiveTab to the Case panel
$taskCat = new TaskCategory ;
$taskCat -> getFromDB ( $params [ 'item' ] -> fields [ 'taskcategories_id' ] );
$taskComment = isset ( $taskCat -> fields [ 'comment' ]) ? $taskCat -> fields [ 'comment' ] : '' ;
if ( Session :: haveTranslations ( 'TaskCategory' , 'comment' )) {
$params [ 'item' ] -> fields [ 'content' ] = str_replace ( '##processmaker.taskcomment##' ,
DropdownTranslation :: getTranslatedValue ( $taskCat -> getID (), 'TaskCategory' , 'comment' , $_SESSION [ 'glpilanguage' ], $taskComment ), $params [ 'item' ] -> fields [ 'content' ] );
} else {
$params [ 'item' ] -> fields [ 'content' ] = str_replace ( '##processmaker.taskcomment##' , $taskComment , $params [ 'item' ] -> fields [ 'content' ] );
}
$taskJSId = " viewitem " . $params [ 'item' ] -> getType () . $params [ 'item' ] -> getId () . $params [ 'options' ][ 'rand' ];
2018-05-04 16:06:49 +02:00
// special case for <hr> which will provoke the rendering to be split into several <p>
// add <p></p> which othervise will be missing
if ( stripos ( $params [ 'item' ] -> fields [ 'content' ], '<hr>' ) !== false ) {
$params [ 'item' ] -> fields [ 'content' ] = str_ireplace ( '<hr>' , '<hr><p>' , $params [ 'item' ] -> fields [ 'content' ]) . '</p>' ;
}
2018-07-04 11:24:29 +02:00
$tmpCase = new PluginProcessmakerCase ;
$tmpCase -> getFromDB ( $pmTask -> fields [ 'plugin_processmaker_cases_id' ]);
$urlLink = $tmpCase -> getLinkURL () . '&forcetab=PluginProcessmakerTask$' . $pmTask -> fields [ 'items_id' ];
2017-05-06 18:38:24 +02:00
echo Html :: scriptBlock ( "
2018-05-04 16:06:49 +02:00
$ ( '#$taskJSId' ) . find ( '.item_content' ) . children () . not ( '.read_more' ) . on ( 'click' , function ( ) {
2016-10-25 11:37:01 +02:00
//debugger;
2018-07-04 11:24:29 +02:00
document . location = '$urlLink'
2016-10-25 11:37:01 +02:00
} ) . css ( 'cursor' , 'pointer' ) ;
2019-01-14 16:19:24 +01:00
$ ( 'tr[id=\"$taskJSId\"]' ) . children () . on ( 'click' , function ( ) {
//debugger;
document . location = '$urlLink'
} ) . css ( 'cursor' , 'pointer' ) ;
2017-05-06 18:38:24 +02:00
" );
2018-05-04 16:06:49 +02:00
2019-01-14 16:19:24 +01:00
$params [ 'item' ] -> fields [ 'content' ] = str_replace ( [ " \n ##processmakercase.url## " , '\n##processmakercase.url##' , '##processmakercase.url##' ], " " , $params [ 'item' ] -> fields [ 'content' ] );
2017-05-06 18:38:24 +02:00
2018-07-04 11:24:29 +02:00
// in order to set NavigationList
Session :: initNavigateListItems ( 'PluginProcessmakerCase' ,
//TRANS : %1$s is the itemtype name,
// %2$s is the name of the item (used for headings of a list)
2018-08-02 16:57:00 +02:00
sprintf ( '%1$s = %2$s' ,
2018-07-04 11:24:29 +02:00
$params [ 'options' ][ 'parent' ] -> getTypeName ( 1 ), $params [ 'options' ][ 'parent' ] -> fields [ " name " ]));
2017-05-06 18:38:24 +02:00
}
}
}
2016-10-25 11:37:01 +02:00
2015-10-09 14:13:52 +02:00
/**
2017-02-28 13:56:37 +01:00
* Summary of pre_show_tab_arbehaviours
* @ param array $params info about tab to be shown
* @ return void
2015-10-09 14:13:52 +02:00
*/
2017-05-06 18:38:24 +02:00
static function pre_show_tab_processmaker ( $params ) {
2018-08-02 16:57:00 +02:00
global $pmHideSolution ;
2017-05-06 18:38:24 +02:00
$plugin = new Plugin ();
$itemtype = $params [ 'item' ] -> getType ();
switch ( $itemtype ) {
case 'Ticket' :
case 'Problem' :
case 'Change' :
2018-08-06 16:12:16 +02:00
if ( $params [ 'options' ][ 'id' ] && $params [ 'options' ][ 'itemtype' ] == $itemtype ) {
2017-05-06 18:38:24 +02:00
// then we are in an ITIL Object
if ( isset ( $_SESSION [ 'glpiactiveprofile' ][ 'interface' ]) && $_SESSION [ 'glpiactiveprofile' ][ 'interface' ] != " helpdesk " ) {
$tabnum = $params [ 'options' ][ 'tabnum' ];
// tabnum 1 : Processing Ticket, tabnum 2 : Solution
if ( $tabnum == 2 or $tabnum == 1 ) {
// we must check if we can solve item even if PM case is still running (ex: PIR tasks for Change Management)
$pmCanSolve = PluginProcessmakerCase :: canSolve ( $params );
if ( ! $pmCanSolve ) {
2018-08-06 16:12:16 +02:00
// don't display message if arbehaviours is install and activated
if ( ! $plugin -> isInstalled ( 'arbehaviours' ) || ! $plugin -> isActivated ( 'arbehaviours' )) {
2018-08-02 16:57:00 +02:00
$messageOne = __ ( 'A \'Case\' is running!' , 'processmaker' );
$messageTwo = __ ( 'You must manage it first (see \'Process - Case\' tab)!' , 'processmaker' );
2017-05-06 18:38:24 +02:00
// output explicit message to explain why it's not possible to add solution
$message = " <div style='margin-bottom: 20px;' class='box'>
2015-10-09 14:13:52 +02:00
< div class = 'box-tleft' >
< div class = 'box-tright' >
< div class = 'box-tcenter' >
</ div >
</ div >
</ div >
< div class = 'box-mleft' >
< div class = 'box-mright' >
< div class = 'box-mcenter' >
< h3 >
2017-02-28 13:56:37 +01:00
< span class = 'red' > " . $messageOne . "
2015-10-09 14:13:52 +02:00
< br >
</ span >
</ h3 >
< h3 >
2017-02-28 13:56:37 +01:00
< span > " . $messageTwo . "
2015-10-09 14:13:52 +02:00
</ span >
</ h3 >
</ div >
</ div >
</ div >
< div class = 'box-bleft' >
< div class = 'box-bright' >
< div class = 'box-bcenter' >
</ div >
</ div >
</ div >
</ div > " ;
2017-05-06 18:38:24 +02:00
}
$pmHideSolution = true ;
$itemtype = strtolower ( $itemtype );
if ( $tabnum == 1 && isset ( $_SESSION [ 'glpiactiveprofile' ][ $itemtype . '_status' ])) {
2018-08-06 16:12:16 +02:00
// don't display message if arbehaviours is install and activated
if ( ! $plugin -> isInstalled ( 'arbehaviours' ) || ! $plugin -> isActivated ( 'arbehaviours' )) {
2017-05-06 18:38:24 +02:00
self :: displayMessage ( $message , '' , WARNING );
//save current $_SESSION['glpiactiveprofile'][$itemtype.'_status'']
$_SESSION [ 'glpiactiveprofile' ][ $itemtype . '_status_save' ] = $_SESSION [ 'glpiactiveprofile' ][ $itemtype . '_status' ];
// for all $params['options']['itemtype']. status, disable solved ( life cycles )
foreach ( $_SESSION [ 'glpiactiveprofile' ][ $itemtype . '_status' ] as $key => $value ) {
$_SESSION [ 'glpiactiveprofile' ][ $itemtype . '_status' ][ $key ][ CommonITILObject :: SOLVED ] = 0 ;
}
}
} else {
// then output a new div and hide solution for content
echo $message ;
echo " <div id='toHideSolution' style='display: none;'> " ;
}
}
}
}
}
}
}
public static function post_show_tab_processmaker ( $params ) {
global $pmHideSolution ;
$itemtype = $params [ 'item' ] -> getType ();
switch ( $itemtype ) {
case 'Ticket' :
case 'Problem' :
case 'Change' :
if ( $params [ 'options' ][ 'id' ]) {
// then we are in an itil object
if ( isset ( $_SESSION [ 'glpiactiveprofile' ][ 'interface' ]) && $_SESSION [ 'glpiactiveprofile' ][ 'interface' ] != " helpdesk " ) {
$tabnum = $params [ 'options' ][ 'tabnum' ];
if ( $tabnum == 2 or $tabnum == 1 ) {
// then we are showing the Solution tab or Processing Ticket tab
if ( $pmHideSolution ) {
echo " </div> " ;
}
$itemtype = strtolower ( $itemtype );
// replace $_SESSION['glpiactiveprofile'][$itemtype.'_status'] with saved value
if ( $tabnum == 1 && isset ( $_SESSION [ 'glpiactiveprofile' ][ $itemtype . '_status_save' ])) {
$_SESSION [ 'glpiactiveprofile' ][ $itemtype . '_status' ] = $_SESSION [ 'glpiactiveprofile' ][ $itemtype . '_status_save' ];
}
}
}
}
break ;
}
}
2016-10-25 11:37:01 +02:00
2017-02-28 13:56:37 +01:00
2015-10-09 14:13:52 +02:00
/**
* Summary of getItemUsers
* returns an array of glpi ids and pm ids for each user type assigned to given ticket
2017-05-06 18:38:24 +02:00
* @ param string $itemtype
* @ param integer $itemId is the ID of the titem
2015-10-09 14:13:52 +02:00
* @ param integer $userType is 1 for ticket requesters , 2 for ticket technicians , and if needed , 3 for watchers
* @ return array of users in the returned array
*/
2019-01-14 16:19:24 +01:00
public static function getItemUsers ( $itemtype , $itemId , $userType ) {
global $DB ;
$dbu = new DbUtils ;
$users = [ ];
2016-10-25 11:37:01 +02:00
2019-01-14 16:19:24 +01:00
//$itemtable = $dbu->getTableForItemType( $itemtype ) ;
2017-05-06 18:38:24 +02:00
$item = new $itemtype ();
$item_users = $item -> userlinkclass ;
2019-01-14 16:19:24 +01:00
$item_userstable = $dbu -> getTableForItemType ( $item_users );
2017-05-06 18:38:24 +02:00
$itemlink = getForeignKeyFieldForItemType ( $itemtype );
2016-10-25 11:37:01 +02:00
2017-05-06 18:38:24 +02:00
$query = " select glpi_plugin_processmaker_users.pm_users_id as pm_users_id, glpi_plugin_processmaker_users.id as id from $item_userstable
2016-10-25 11:37:01 +02:00
left join glpi_plugin_processmaker_users on glpi_plugin_processmaker_users . id = $item_userstable . users_id
where $item_userstable . $itemlink = $itemId and $item_userstable . type = $userType
2017-05-06 18:38:24 +02:00
order by $item_userstable . id " ;
foreach ( $DB -> request ( $query ) as $dbuser ) {
2019-01-14 16:19:24 +01:00
$users [] = [ 'glpi_id' => $dbuser [ 'id' ], 'pm_id' => $dbuser [ 'pm_users_id' ] ];
2017-05-06 18:38:24 +02:00
}
2016-10-25 11:37:01 +02:00
2017-05-06 18:38:24 +02:00
return $users ;
}
2016-10-25 11:37:01 +02:00
2015-10-09 14:13:52 +02:00
/**
* Summary of saveForm
* This function posts dynaform variables to PM , using the CURL module .
2019-05-21 10:47:15 +02:00
* @ param array $request : is the $_REQUEST server array
2017-02-28 13:56:37 +01:00
* //@param string $cookie: is the $_SERVER['HTTP_COOKIE'] string
2015-10-09 14:13:52 +02:00
* @ return mixed : returns false if request failed , otherwise , returns true
*/
2019-01-14 16:19:24 +01:00
public function saveForm ( $request ) {
2019-05-21 10:47:15 +02:00
2019-01-14 16:19:24 +01:00
$loggable = false ;
2017-05-06 18:38:24 +02:00
$request = stripcslashes_deep ( $request );
$ch = curl_init ();
2015-10-09 14:13:52 +02:00
2017-02-28 13:56:37 +01:00
//to be able to trace network traffic with a local proxy
2019-01-14 16:19:24 +01:00
// curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1 );
// curl_setopt($ch, CURLOPT_PROXY, "localhost:8888");
2018-01-29 15:05:49 +01:00
2019-01-14 16:19:24 +01:00
//curl_setopt($ch, CURLINFO_HEADER_OUT, 1);
//curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
2018-01-29 15:05:49 +01:00
curl_setopt ( $ch , CURLOPT_HEADER , 1 );
2017-05-06 18:38:24 +02:00
curl_setopt ( $ch , CURLOPT_RETURNTRANSFER , 1 );
2019-01-14 16:19:24 +01:00
curl_setopt ( $ch , CURLOPT_VERBOSE , 1 );
curl_setopt ( $ch , CURLOPT_HTTPHEADER , [ " Expect: " ]);
curl_setopt ( $ch , CURLOPT_SSL_VERIFYPEER , $this -> config -> fields [ 'ssl_verify' ]);
curl_setopt ( $ch , CURLOPT_SSL_VERIFYHOST , $this -> config -> fields [ 'ssl_verify' ]);
//curl_setopt($ch, CURLOPT_HEADERFUNCTION, "HandleHeaderLine");
2019-05-21 10:47:15 +02:00
// to store cookies in memory
2019-01-14 16:19:24 +01:00
// ( replace HandleHeaderLine function )
curl_setopt ( $ch , CURLOPT_COOKIEFILE , " " );
2016-10-25 11:37:01 +02:00
2019-01-14 16:19:24 +01:00
// ### first call to open case and get cookies GET ###
2018-07-04 11:24:29 +02:00
curl_setopt ( $ch , CURLOPT_URL , $this -> serverURL . " /cases/cases_Open?sid= " . $this -> getPMSessionID () . " &APP_UID= " . $request [ 'APP_UID' ] . " &DEL_INDEX= " . $request [ 'DEL_INDEX' ] . " &action=TO_DO " );
2017-05-06 18:38:24 +02:00
$response = curl_exec ( $ch );
2019-01-14 16:19:24 +01:00
if ( $loggable ) {
Toolbox :: logInFile ( " pmtrace " , " URL: \n " . $this -> serverURL . " /cases/cases_Open?sid= " . $this -> getPMSession () . " \n Response: \n " . $response . " \n \n \n " );
}
2015-10-09 14:13:52 +02:00
2019-01-14 16:19:24 +01:00
// change option to indicate that the next call will be POST
2017-05-06 18:38:24 +02:00
curl_setopt ( $ch , CURLOPT_POST , 1 );
2019-01-14 16:19:24 +01:00
// get and format post values
$data = http_formdata_flat_hierarchy ( $request );
// check if any files are in the $_FILES global array
// and add them to the curl POST
2019-06-18 10:01:08 +02:00
$fileForm = isset ( $_FILES [ 'form' ][ 'name' ]) ? $_FILES [ 'form' ][ 'name' ] : null ;
if ( isset ( $fileForm ) && ! empty ( $fileForm [ array_keys ( $fileForm )[ 0 ]][ 1 ][ array_keys ( $fileForm [ array_keys ( $fileForm )[ 0 ]][ 1 ])[ 0 ]])) {
2019-01-14 16:19:24 +01:00
foreach ( $_FILES [ 'form' ][ 'name' ] as $key => $file ) {
if ( is_array ( $file )) {
// it's a grid which contains documents
foreach ( $file as $row => $col ) {
2019-05-21 10:47:15 +02:00
foreach ( $col as $control => $filename ) {
$cfile = new CURLFile ( $_FILES [ 'form' ][ 'tmp_name' ][ $key ][ $row ][ $control ], $_FILES [ 'form' ][ 'type' ][ $key ][ $row ][ $control ], $_FILES [ 'form' ][ 'name' ][ $key ][ $row ][ $control ]);
2019-01-14 16:19:24 +01:00
$data [ " form[ $key ][ $row ][ $control ] " ] = $cfile ;
}
}
} else {
2019-05-21 10:47:15 +02:00
$cfile = new CURLFile ( $_FILES [ 'form' ][ 'tmp_name' ][ $key ], $_FILES [ 'form' ][ 'type' ][ $key ], $_FILES [ 'form' ][ 'name' ][ $key ]);
2019-01-14 16:19:24 +01:00
$data [ " form[ $key ] " ] = $cfile ;
}
}
}
// to get all cookies in one variable
2019-05-21 10:47:15 +02:00
//$cookies = curl_getinfo($ch, CURLINFO_COOKIELIST);
2019-01-14 16:19:24 +01:00
curl_setopt ( $ch , CURLOPT_HTTPHEADER , [ " Expect: " ]);
curl_setopt ( $ch , CURLOPT_POSTFIELDS , $data ); // inject POST values
// add agent and referer params
//$agent = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)';
//$referer = $this->getSiteURL();
//curl_setopt($ch, CURLOPT_USERAGENT, $agent);
//curl_setopt($ch, CURLOPT_REFERER, $referer);
// ### 2nd call to save Data POST ###
2017-05-06 18:38:24 +02:00
curl_setopt ( $ch , CURLOPT_URL , $this -> serverURL . " /cases/cases_SaveData?UID= " . $request [ 'UID' ] . " &APP_UID= " . $request [ 'APP_UID' ] );
$response = curl_exec ( $ch );
2015-10-09 14:13:52 +02:00
2017-05-06 18:38:24 +02:00
curl_close ( $ch );
2019-01-14 16:19:24 +01:00
if ( $loggable ) {
Toolbox :: logInFile ( " pmtrace " , " URL: \n " . $this -> serverURL . " /cases/cases_SaveData?UID= " . $request [ 'UID' ] . " &APP_UID= " . $request [ 'APP_UID' ] . " \n Data: \n " . print_r ( $data , true ) . " \n Response: \n " . $response . " \n \n \n " );
}
2016-10-25 11:37:01 +02:00
2017-05-06 18:38:24 +02:00
return ( $response ? true : false );
}
2016-10-25 11:37:01 +02:00
2019-01-14 16:19:24 +01:00
/**
* Function to get current site url with protocol ( http or https )
* @ return string
*/
function getSiteURL () {
$protocol = ( ! empty ( $_SERVER [ 'HTTPS' ]) && $_SERVER [ 'HTTPS' ] !== 'off' || $_SERVER [ 'SERVER_PORT' ] == 443 ) ? " https:// " : " http:// " ;
$domainName = $_SERVER [ 'HTTP_HOST' ];
return $protocol . $domainName ;
}
2018-07-25 14:09:52 +02:00
/**
* Summary of initCaseAndShowTab
* Is used to workaround a SESSION issue in PM server
* PM server stores case context in SESSION variables ,
* which leads to issues when viewing two different cases
* in two different tabs of the same browser .
* This workaround will artificially load cases_Open page to force
* initialization of those SESSION variables to prevent mix of values
* when viewing tabs like map , change log , history , and dynaforms
2018-08-02 16:57:00 +02:00
*
2018-07-25 14:09:52 +02:00
* it will also manage the glpi_domain parameter
2018-08-02 16:57:00 +02:00
*
2018-07-25 14:09:52 +02:00
* @ param mixed $currentCase array that contains APP_UID , DEL_INDEX
* @ param mixed $iFrameUrl string which is the url of the tab panel
2018-08-02 16:57:00 +02:00
* @ param mixed $rand integer
2018-07-25 14:09:52 +02:00
*/
public function initCaseAndShowTab ( $currentCase , $iFrameUrl , $rand ) {
$iFrameUrl = urlencode ( $iFrameUrl );
echo " <div id='openCase- $rand '></div> " ;
// will use ajax to be sure that cases_Open page is fully loaded before load of the $iFrameUrl
// this mechanism is mandatory to have correct management of cookies, as cookies transport the session id,
// and such the SESSION variables that contain the case context
echo " <script type='text/javascript'>
( function () {
function urldecode ( url ) {
return decodeURIComponent ( url . replace ( / \ +/ g , ' ' ));
}
$ . ajax ( { url : '".$this->serverURL."/cases/cases_Open?sid=".$this->getPMSessionID()."&APP_UID={$currentCase[' APP_UID ']}&DEL_INDEX={$currentCase[' DEL_INDEX ']}&action=TO_DO&glpi_init_case=1&glpi_domain={$this->config->fields[' domain ']}' ,
2019-01-14 16:19:24 +01:00
xhrFields : { withCredentials : true },
success : function ( jqXHR ) {
//debugger;
var str = urldecode ( '$iFrameUrl' );
$ ( '#openCase-$rand' ) . after ( str );
},
error : function ( jqXHR ) {
// debugger;
},
cache : false ,
crossDomain : true
}
2018-07-25 14:09:52 +02:00
);
}) ();
</ script > " ;
}
2015-10-09 14:13:52 +02:00
/**
2019-01-14 16:19:24 +01:00
* Summary of plugin_item_get_data_processmaker
2016-10-25 11:37:01 +02:00
* @ param mixed $item
2015-10-09 14:13:52 +02:00
*/
2019-01-14 16:19:24 +01:00
public static function plugin_item_get_data_processmaker ( $item ) {
2018-07-13 15:58:47 +02:00
global $_SESSION , $CFG_GLPI ;
2019-01-14 16:19:24 +01:00
if ( isset ( $item -> data ) && isset ( $item -> data [ 'tasks' ] )) {
2019-05-21 10:47:15 +02:00
$pmtask = new PluginProcessmakerTask ( $pmtask_itemtype );
2019-01-14 16:19:24 +01:00
foreach ( $item -> data [ 'tasks' ] as & $task ) {
2018-07-13 15:58:47 +02:00
$pmtask_itemtype = $item -> obj -> getType () . 'Task' ;
$pmtask_items_id = $task [ '##task.id##' ];
2019-01-14 16:19:24 +01:00
// for each task, we must check if it is in our task table
// and if yes, then process the content
2019-05-21 10:47:15 +02:00
$restrict = [
'WHERE' => [
'itemtype' => $pmtask_itemtype ,
'items_id' => $pmtask_items_id
],
];
//if ($pmtask->getFromDBByQuery("WHERE itemtype = '$pmtask_itemtype' AND items_id = $pmtask_items_id")) {
if ( $pmtask -> getFromDBByRequest ( $restrict )) {
2019-01-14 16:19:24 +01:00
if ( ! in_array ( " tasks " , $item -> html_tags )) {
$item -> html_tags [] = " tasks " ; // to force GLPI to keep the below HTML tags, otherwise it will apply a Html::entities_deep() to the task.description
}
2018-08-02 16:57:00 +02:00
$task [ '##task.description##' ] = str_replace ( '##processmaker.taskcomment##' , $task [ '##task.categorycomment##' ], $task [ '##task.description##' ] );
2019-01-14 16:19:24 +01:00
$task [ '##task.description##' ] = Html :: nl2br_deep ( $task [ '##task.description##' ]);
2019-05-21 10:47:15 +02:00
//$restrict=[
// 'WHERE' => [
// 'itemtype' => $pmtask_itemtype,
// 'items_id' => $pmtask_items_id
// ],
// ];
//$pmtask->getFromDBByRequest($restrict);
2019-01-14 16:19:24 +01:00
//$caseurl = urldecode($CFG_GLPI["url_base"]."/index.php?redirect=PluginProcessmakerCase_".$pmtask->fields['plugin_processmaker_cases_id']);
$caseurl = $CFG_GLPI [ " url_base " ] . " /index.php?redirect= " . urlencode ( " /plugins/processmaker/front/case.form.php?id= " . $pmtask -> fields [ 'plugin_processmaker_cases_id' ]);
$caseurl = " <a href=' $caseurl '> $caseurl </a> " ;
2018-08-02 16:57:00 +02:00
$task [ '##task.description##' ] = str_replace ( '##processmakercase.url##' , $caseurl , $task [ '##task.description##' ]);
}
2016-10-25 11:37:01 +02:00
}
}
2017-05-06 18:38:24 +02:00
}
2015-10-09 14:13:52 +02:00
2017-02-28 13:56:37 +01:00
/**
2019-01-14 16:19:24 +01:00
* Summary of plugin_item_get_pdfdata_processmaker
2017-02-28 13:56:37 +01:00
* @ param mixed $item
*/
2019-01-14 16:19:24 +01:00
public static function plugin_item_get_pdfdata_processmaker ( $item ) {
2017-05-06 18:38:24 +02:00
if ( isset ( $item -> datas )) {
$config = PluginProcessmakerConfig :: getInstance ();
$taskCat = new TaskCategory ;
2019-01-14 16:19:24 +01:00
$dbu = new DbUtils ;
2017-05-06 18:38:24 +02:00
// save current translations
if ( isset ( $_SESSION [ 'glpi_dropdowntranslations' ] )) {
$trans = $_SESSION [ 'glpi_dropdowntranslations' ];
}
// load available translations for this user
$_SESSION [ 'glpi_dropdowntranslations' ] = DropdownTranslation :: getAvailableTranslations ( $_SESSION [ 'glpilanguage' ]);
$taskCat -> getFromDB ( $item -> datas [ 'taskcategories_id' ] );
2019-01-14 16:19:24 +01:00
$ancestors = $dbu -> getAncestorsOf ( 'glpi_taskcategories' , $item -> datas [ 'taskcategories_id' ]);
2017-05-06 18:38:24 +02:00
if ( in_array ( $config -> fields [ 'taskcategories_id' ], $ancestors )) {
$loc_completename = DropdownTranslation :: getTranslatedValue ( $taskCat -> getID (), 'TaskCategory' , 'completename' , $_SESSION [ 'glpilanguage' ], $taskCat -> fields [ 'completename' ] );
$loc_comment = DropdownTranslation :: getTranslatedValue ( $taskCat -> getID (), 'TaskCategory' , 'comment' , $_SESSION [ 'glpilanguage' ], $taskCat -> fields [ 'comment' ] );
2019-05-21 10:47:15 +02:00
$item -> datas [ 'content' ] = $loc_completename . " \n \n " . str_replace ( " ##processmaker.taskcomment## " , $loc_comment , $item -> datas [ 'content' ]);
$item -> datas [ 'content' ] = str_replace ( " ##processmakercase.url## " , '' , $item -> datas [ 'content' ]);
2017-05-06 18:38:24 +02:00
}
// restore default translations
if ( isset ( $trans )) {
$_SESSION [ 'glpi_dropdowntranslations' ] = $trans ;
} else {
unset ( $_SESSION [ 'glpi_dropdowntranslations' ] );
2017-02-28 13:56:37 +01:00
}
}
2017-05-06 18:38:24 +02:00
}
2017-02-28 13:56:37 +01:00
/**
2015-10-09 14:13:52 +02:00
* Summary of getProcessesWithCategoryAndProfile
2016-10-25 11:37:01 +02:00
* @ param mixed $category
* @ param mixed $type
* @ param mixed $profile
* @ param mixed $entity
2015-10-09 14:13:52 +02:00
*/
2019-01-14 16:19:24 +01:00
public static function getProcessesWithCategoryAndProfile ( $category , $type , $profile , $entity ) {
2017-05-06 18:38:24 +02:00
global $DB ;
2019-01-14 16:19:24 +01:00
$dbu = new DbUtils ;
$processList = [ ];
$entityAncestors = implode ( " , " , $dbu -> getAncestorsOf ( $dbu -> getTableForItemType ( 'Entity' ), $entity ) );
2017-05-06 18:38:24 +02:00
if ( strlen ( $entityAncestors ) > 0 ) {
$entityAncestors = " OR (entities_id IN ( $entityAncestors ) AND is_recursive = 1) " ;
}
2015-10-09 14:13:52 +02:00
2017-05-06 18:38:24 +02:00
$query = " SELECT DISTINCT glpi_plugin_processmaker_processes.id, glpi_plugin_processmaker_processes.name FROM glpi_plugin_processmaker_processes
2018-07-04 11:24:29 +02:00
INNER JOIN glpi_plugin_processmaker_processes_profiles ON glpi_plugin_processmaker_processes_profiles . plugin_processmaker_processes_id = glpi_plugin_processmaker_processes . id
2017-05-06 18:38:24 +02:00
WHERE is_active = 1 AND itilcategories_id = $category AND `type` = $type AND profiles_id = $profile AND ( entities_id = $entity $entityAncestors ) " ;
foreach ( $DB -> request ( $query ) as $row ) {
$processList [] = $row ;
}
return $processList ;
}
2018-07-04 11:24:29 +02:00
/**
* Summary of startNewCase
* @ param mixed $processes_id integer : GLPI process id
2019-05-21 10:47:15 +02:00
* @ param mixed $itemtype string : item type 'Ticket' , 'Change' or 'Problem'
2018-07-04 11:24:29 +02:00
* @ param mixed $items_id integer : id to thte item
* @ param mixed $users_id integer : GLPI user id
* @ return mixed
*/
2019-05-21 10:47:15 +02:00
public function startNewCase ( $processes_id , $itemtype , $items_id , $users_id = null ) {
2017-05-06 18:38:24 +02:00
global $DB , $CFG_GLPI ;
2019-05-21 10:47:15 +02:00
$requesters = PluginProcessmakerProcessmaker :: getItemUsers ( $itemtype , $items_id , CommonITILActor :: REQUESTER ); // 1 for requesters
2017-05-06 18:38:24 +02:00
if ( ! key_exists ( 0 , $requesters )) {
$requesters [ 0 ][ 'glpi_id' ] = 0 ;
$requesters [ 0 ][ 'pm_id' ] = 0 ;
}
2018-07-04 11:24:29 +02:00
//$impersonateCase = false;
//if (!$users_id) {
// // then we are going to take the item creator to set it as case creator and
// $impersonateCase = true;
2017-05-06 18:38:24 +02:00
2018-07-04 11:24:29 +02:00
//}
2017-05-06 18:38:24 +02:00
// get item info to retreive title, description and duedate
2019-05-21 10:47:15 +02:00
$item = new $itemtype ;
$item -> getFromDB ( $items_id );
2017-05-06 18:38:24 +02:00
2019-05-21 10:47:15 +02:00
if ( $item -> countUsers ( CommonITILActor :: ASSIGN ) == 0
|| ! $item -> isUser ( CommonITILActor :: ASSIGN , $users_id ) ) {
$item -> update ( [ 'id' => $items_id , '_itil_assign' => [ '_type' => 'user' , 'users_id' => $users_id ] ] );
2017-05-06 18:38:24 +02:00
}
2019-05-21 10:47:15 +02:00
if ( ! isset ( $item -> fields [ 'time_to_resolve' ]) || $item -> fields [ 'time_to_resolve' ] == null ) {
$item -> fields [ 'time_to_resolve' ] = " " ;
2017-05-06 18:38:24 +02:00
}
2018-07-04 11:24:29 +02:00
$resultCase = $this -> newCase ( $processes_id ,
2019-05-21 10:47:15 +02:00
[ 'GLPI_ITEM_CAN_BE_SOLVED' => 0 ,
'GLPI_TICKET_ID' => $items_id ,
'GLPI_ITEM_ID' => $items_id ,
'GLPI_ITEM_TYPE' => $itemtype ,
'GLPI_ITEM_STATUS' => $item -> fields [ 'status' ],
'GLPI_TICKET_REQUESTER_GLPI_ID' => $requesters [ 0 ][ 'glpi_id' ],
'GLPI_ITEM_REQUESTER_GLPI_ID' => $requesters [ 0 ][ 'glpi_id' ],
'GLPI_TICKET_REQUESTER_PM_ID' => $requesters [ 0 ][ 'pm_id' ],
'GLPI_ITEM_REQUESTER_PM_ID' => $requesters [ 0 ][ 'pm_id' ],
'GLPI_TICKET_TITLE' => $item -> fields [ 'name' ],
'GLPI_ITEM_TITLE' => $item -> fields [ 'name' ],
'GLPI_TICKET_DESCRIPTION' => $item -> fields [ 'content' ],
'GLPI_ITEM_DESCRIPTION' => $item -> fields [ 'content' ],
'GLPI_ITEM_OPENING_DATE' => $item -> fields [ 'date' ],
'GLPI_TICKET_DUE_DATE' => $item -> fields [ 'time_to_resolve' ],
'GLPI_ITEM_DUE_DATE' => $item -> fields [ 'time_to_resolve' ],
'GLPI_ITEM_ITIL_CATEGORY_ID' => $item -> fields [ 'itilcategories_id' ],
'GLPI_TICKET_URGENCY' => $item -> fields [ 'urgency' ],
'GLPI_ITEM_URGENCY' => $item -> fields [ 'urgency' ],
'GLPI_ITEM_IMPACT' => $item -> fields [ 'impact' ],
'GLPI_ITEM_PRIORITY' => $item -> fields [ 'priority' ],
// Specific to Tickets and Changes
// GLPI_ITEM_GLOBAL_VALIDATION will be '' when Problem, else it will be the global_validation field
'GLPI_TICKET_GLOBAL_VALIDATION' => $itemtype == 'Problem' ? '' : $item -> fields [ 'global_validation' ],
'GLPI_ITEM_GLOBAL_VALIDATION' => $itemtype == 'Problem' ? '' : $item -> fields [ 'global_validation' ],
'GLPI_TICKET_TECHNICIAN_GLPI_ID' => $users_id ,
'GLPI_ITEM_TECHNICIAN_GLPI_ID' => $users_id ,
'GLPI_TICKET_TECHNICIAN_PM_ID' => PluginProcessmakerUser :: getPMUserId ( $users_id ),
'GLPI_ITEM_TECHNICIAN_PM_ID' => PluginProcessmakerUser :: getPMUserId ( $users_id ),
'GLPI_URL' => $CFG_GLPI [ 'url_base' ],
// Specific to Tickets
// GLPI_TICKET_TYPE will contains 1 (= incident) or 2 (= request), or '' if itemtype is not Ticket
'GLPI_TICKET_TYPE' => $itemtype == 'Ticket' ? $item -> fields [ 'type' ] : ''
]);
2017-05-06 18:38:24 +02:00
if ( $resultCase -> status_code === 0 ) {
2018-07-04 11:24:29 +02:00
$caseInfo = $this -> getCaseInfo ( $resultCase -> caseId );
2016-10-25 11:37:01 +02:00
2018-07-04 11:24:29 +02:00
// save info to DB
$locCase = new PluginProcessmakerCase ;
2019-05-21 10:47:15 +02:00
$locCase -> add ( [ 'id' => $resultCase -> caseNumber ,
'itemtype' => $itemtype ,
'items_id' => $items_id ,
'case_guid' => $resultCase -> caseId ,
'case_status' => $caseInfo -> caseStatus ,
'name' => $caseInfo -> caseName ,
'entities_id' => $item -> fields [ 'entities_id' ],
2018-07-04 11:24:29 +02:00
'plugin_processmaker_processes_id' => $processes_id ,
2019-05-21 10:47:15 +02:00
'plugin_processmaker_cases_id' => 0
2019-01-14 16:19:24 +01:00
],
[], true );
2016-10-25 11:37:01 +02:00
2019-05-21 10:47:15 +02:00
$this -> add1stTask ( $locCase -> getID (), $itemtype , $items_id , $caseInfo , [ 'userId' => $users_id ] );
2017-02-28 13:56:37 +01:00
}
2015-10-09 14:13:52 +02:00
2017-05-06 18:38:24 +02:00
return $resultCase ;
}
2017-02-28 13:56:37 +01:00
/**
* Summary of derivateCase
* in $request must be present
* 'UID' , 'APP_UID' and DEL_INDEX '
*
* @ param mixed $myCase
* @ param mixed $request
* @ param mixed $users_id
*/
2019-01-14 16:19:24 +01:00
public function derivateCase ( $myCase , $request , $users_id = null ) {
2017-05-06 18:38:24 +02:00
//$cookies,
2018-07-13 15:58:47 +02:00
global $PM_DB , $CFG_GLPI ;
2017-05-06 18:38:24 +02:00
2018-07-04 11:24:29 +02:00
$itemtype = $myCase -> getField ( 'itemtype' );
$items_id = $myCase -> getField ( 'items_id' );
$item = new $itemtype ;
$item -> getFromDB ( $items_id );
// save the dynaform variables into the current case
2019-05-21 10:47:15 +02:00
if ( isset ( $request [ 'UID' ]) && isset ( $request [ 'APP_UID' ]) && isset ( $request [ '__DynaformName__' ])) {
$resultSave = $this -> saveForm ( $request );
}
2017-05-06 18:38:24 +02:00
// now derivate the case !!!
2018-07-04 11:24:29 +02:00
$pmRouteCaseResponse = $this -> routeCase ( $myCase -> fields [ 'case_guid' ], $request [ 'DEL_INDEX' ]);
2018-05-14 16:56:52 +02:00
$casevariables = [ " GLPI_ITEM_TASK_CONTENT " ,
" GLPI_ITEM_APPEND_TO_TASK " ,
" GLPI_NEXT_GROUP_TO_BE_ASSIGNED " ,
" GLPI_ITEM_TITLE " ,
" GLPI_TICKET_FOLLOWUP_CONTENT " ,
" GLPI_TICKET_FOLLOWUP_IS_PRIVATE " ,
" GLPI_TICKET_FOLLOWUP_REQUESTTYPES_ID " ,
" GLPI_ITEM_TASK_ENDDATE " ,
" GLPI_ITEM_TASK_STARTDATE " ,
2019-05-21 10:47:15 +02:00
" GLPI_ITEM_TASK_REMINDER " ,
2019-01-14 16:19:24 +01:00
" GLPI_ITEM_SOLVED_TASK_ENDDATE " ,
" GLPI_ITEM_SOLVED_TASK_STARTDATE " ,
" GLPI_ITEM_SOLVED_TASK_SETINFO " ,
2018-05-14 16:56:52 +02:00
" GLPI_ITEM_SET_STATUS " ,
2019-05-21 10:47:15 +02:00
" GLPI_ITEM_STATUS " ,
2018-05-14 16:56:52 +02:00
" GLPI_ITEM_SET_SOLUTION_TEMPLATE_ID " ,
" GLPI_ITEM_SET_SOLUTION_TYPE_ID " ,
2019-05-21 10:47:15 +02:00
" GLPI_ITEM_APPEND_TO_SOLUTION_DESCRIPTION " ,
" GLPI_ITEM_INITIAL_DUE_DATE " ,
" GLPI_ITEM_DUE_DATE "
2018-05-14 16:56:52 +02:00
];
2017-05-06 18:38:24 +02:00
// now tries to get some variables to setup content for new task and to append text to solved task
2018-07-04 11:24:29 +02:00
$casevariablevalues = $myCase -> getVariables ( $casevariables );
2018-05-14 16:56:52 +02:00
2017-05-06 18:38:24 +02:00
$itemSetStatus = '' ;
2018-05-14 16:56:52 +02:00
if ( array_key_exists ( 'GLPI_ITEM_SET_STATUS' , $casevariablevalues )) {
$itemSetStatus = $casevariablevalues [ 'GLPI_ITEM_SET_STATUS' ];
2017-05-06 18:38:24 +02:00
}
2019-05-21 10:47:15 +02:00
if ( array_key_exists ( 'GLPI_ITEM_STATUS' , $casevariablevalues )) {
$itemSetStatus = $casevariablevalues [ 'GLPI_ITEM_STATUS' ];
}
2017-05-06 18:38:24 +02:00
$txtItemTitle = '' ;
2018-05-14 16:56:52 +02:00
if ( array_key_exists ( 'GLPI_ITEM_TITLE' , $casevariablevalues )) {
$txtItemTitle = $casevariablevalues [ 'GLPI_ITEM_TITLE' ];
2017-05-06 18:38:24 +02:00
}
$txtToAppendToTask = '' ;
2018-05-14 16:56:52 +02:00
if ( array_key_exists ( 'GLPI_ITEM_APPEND_TO_TASK' , $casevariablevalues )) {
$txtToAppendToTask = $casevariablevalues [ 'GLPI_ITEM_APPEND_TO_TASK' ];
2017-05-06 18:38:24 +02:00
}
$txtTaskContent = '' ;
2018-05-14 16:56:52 +02:00
if ( array_key_exists ( 'GLPI_ITEM_TASK_CONTENT' , $casevariablevalues )) {
$txtTaskContent = $casevariablevalues [ 'GLPI_ITEM_TASK_CONTENT' ];
2017-05-06 18:38:24 +02:00
}
$groupId = 0 ;
2018-05-14 16:56:52 +02:00
if ( array_key_exists ( 'GLPI_NEXT_GROUP_TO_BE_ASSIGNED' , $casevariablevalues )) {
$groupId = $casevariablevalues [ 'GLPI_NEXT_GROUP_TO_BE_ASSIGNED' ];
2017-05-06 18:38:24 +02:00
}
$taskStartDate = '' ;
$taskEndDate = '' ;
2018-05-14 16:56:52 +02:00
if ( array_key_exists ( 'GLPI_ITEM_TASK_ENDDATE' , $casevariablevalues )) {
$taskEndDate = $casevariablevalues [ 'GLPI_ITEM_TASK_ENDDATE' ];
2017-05-06 18:38:24 +02:00
}
2018-05-14 16:56:52 +02:00
if ( array_key_exists ( 'GLPI_ITEM_TASK_STARTDATE' , $casevariablevalues )) {
$taskStartDate = $casevariablevalues [ 'GLPI_ITEM_TASK_STARTDATE' ];
2017-05-06 18:38:24 +02:00
if ( $taskEndDate == '' ) {
// at least
$taskEndDate = $taskStartDate ;
}
}
2019-05-21 10:47:15 +02:00
$taskReminder = '' ;
if ( array_key_exists ( 'GLPI_ITEM_TASK_REMINDER' , $casevariablevalues )) {
$taskReminder = $casevariablevalues [ 'GLPI_ITEM_TASK_REMINDER' ];
}
2019-01-14 16:19:24 +01:00
$solvedTaskStartDate = '' ;
$solvedTaskEndDate = '' ;
if ( array_key_exists ( 'GLPI_ITEM_SOLVED_TASK_ENDDATE' , $casevariablevalues )) {
$solvedTaskEndDate = $casevariablevalues [ 'GLPI_ITEM_SOLVED_TASK_ENDDATE' ];
}
if ( array_key_exists ( 'GLPI_ITEM_SOLVED_TASK_STARTDATE' , $casevariablevalues )) {
$solvedTaskStartDate = $casevariablevalues [ 'GLPI_ITEM_SOLVED_TASK_STARTDATE' ];
if ( $solvedTaskEndDate == '' ) {
// at least
$solvedTaskEndDate = $solvedTaskStartDate ;
}
}
$solvedTaskSetToInformation = '' ;
if ( array_key_exists ( 'GLPI_ITEM_SOLVED_TASK_SETINFO' , $casevariablevalues )) {
$solvedTaskSetToInformation = $casevariablevalues [ 'GLPI_ITEM_SOLVED_TASK_SETINFO' ];
}
2017-05-06 18:38:24 +02:00
$createFollowup = false ; // by default
2018-05-14 16:56:52 +02:00
if ( array_key_exists ( 'GLPI_TICKET_FOLLOWUP_CONTENT' , $casevariablevalues ) && $casevariablevalues [ 'GLPI_TICKET_FOLLOWUP_CONTENT' ] != '' ) {
2017-05-06 18:38:24 +02:00
//&& array_key_exists( 'GLPI_TICKET_FOLLOWUP_IS_PRIVATE', $infoForTasks )
//&& array_key_exists( 'GLPI_TICKET_FOLLOWUP_REQUESTTYPES_ID', $infoForTasks )
$createFollowup = true ;
}
2019-05-21 10:47:15 +02:00
$item_duedate = '' ;
if ( array_key_exists ( 'GLPI_ITEM_INITIAL_DUE_DATE' , $casevariablevalues )) {
$item_duedate = $casevariablevalues [ 'GLPI_ITEM_INITIAL_DUE_DATE' ];
}
if ( array_key_exists ( 'GLPI_ITEM_DUE_DATE' , $casevariablevalues )) {
$item_duedate = $casevariablevalues [ 'GLPI_ITEM_DUE_DATE' ];
}
$re = '/^(?\'date\'[0-9]{4}-[0-1][0-9]-[0-3][0-9])( (?\'time\'[0-2][0-9]:[0-5][0-9]:[0-5][0-9]))*$/' ;
if ( preg_match ( $re , $item_duedate , $matches ) && ! array_key_exists ( 'time' , $matches )) {
$item_duedate .= " 23:59:59 " ;
}
2017-05-06 18:38:24 +02:00
// reset those variables
2018-05-14 16:56:52 +02:00
$resetcasevariables = [];
2019-01-14 16:19:24 +01:00
foreach ( $casevariables as $val ) {
2018-05-14 16:56:52 +02:00
$resetcasevariables [ $val ] = '' ;
}
2018-07-04 11:24:29 +02:00
$resultSave = $myCase -> sendVariables ( $resetcasevariables );
2017-05-06 18:38:24 +02:00
// print_r( $pmRouteCaseResponse ) ;
// die() ;
// now manage tasks associated with item
// switch own task to 'done' and create a new one
2019-01-14 16:19:24 +01:00
$this -> solveTask ( $myCase -> getID (),
$request [ 'DEL_INDEX' ],
[ 'txtToAppend' => $txtToAppendToTask ,
'users_id_tech' => $users_id ,
'begin' => $solvedTaskStartDate ,
'end' => $solvedTaskEndDate ,
'toInformation' => $solvedTaskSetToInformation
] );
2017-05-06 18:38:24 +02:00
// create a followup if requested
2018-07-04 11:24:29 +02:00
if ( $createFollowup && $itemtype == 'Ticket' ) {
$this -> addTicketFollowup ( $items_id , $casevariablevalues );
2017-05-06 18:38:24 +02:00
}
if ( $txtItemTitle != '' ) {
// we are going to change the title of current GLPI Item
2018-07-04 11:24:29 +02:00
$this -> setItemTitle ( $itemtype , $items_id , $txtItemTitle );
2017-05-06 18:38:24 +02:00
}
2019-05-21 10:47:15 +02:00
if ( $item_duedate != '' ) {
// we are going to change the due date (time to resolve) of current GLPI Item
$this -> setItemDuedate ( $itemtype , $items_id , $item_duedate );
2017-05-06 18:38:24 +02:00
}
2018-05-14 16:56:52 +02:00
if ( array_key_exists ( 'GLPI_ITEM_SET_SOLUTION_TEMPLATE_ID' , $casevariablevalues )
|| array_key_exists ( 'GLPI_ITEM_SET_SOLUTION_TYPE_ID' , $casevariablevalues )
|| array_key_exists ( 'GLPI_ITEM_APPEND_TO_SOLUTION_DESCRIPTION' , $casevariablevalues )) {
// case requests to add a solution to ticket
2018-07-04 11:24:29 +02:00
$this -> setItemSolution ( $itemtype , $items_id , $casevariablevalues );
}
2019-05-21 10:47:15 +02:00
if ( $itemSetStatus != '' ) {
$this -> setItemStatus ( $itemtype , $items_id , $itemSetStatus );
}
2018-07-04 11:24:29 +02:00
// get the new case info
$caseInfo = $myCase -> getCaseInfo ( $request [ 'DEL_INDEX' ]); // not sure that it should passed this
// now create the new tasks if any
if ( property_exists ( $pmRouteCaseResponse , 'routing' )) {
// we may have several task to create
foreach ( $pmRouteCaseResponse -> routing as $route ) {
// must check if task has started a sub-process
$locTaskCat = new PluginProcessmakerTaskCategory ;
if ( $locTaskCat -> getFromGUID ( $route -> taskId ) && $locTaskCat -> fields [ 'is_subprocess' ]) {
// look for APP_UID
$res = $PM_DB -> query ( " SELECT APP_UID FROM SUB_APPLICATION WHERE APP_PARENT=' { $myCase -> fields [ 'case_guid' ] } ' AND DEL_INDEX_PARENT= { $route -> delIndex } AND SA_STATUS='ACTIVE' " ); // AND DEL_THREAD_PARENT={$route->delThread} seems like it is not set to correct threadIndex
if ( $res && $PM_DB -> numrows ( $res ) == 1 ) {
// then new task is a sub-process,
$row = $PM_DB -> fetch_assoc ( $res );
// now need to get the PRO_UID
$sub_caseInfo = self :: getCaseInfo ( $row [ 'APP_UID' ]);
$locProc = new PluginProcessmakerProcess ;
$locProc -> getFromGUID ( $sub_caseInfo -> processId );
$subCase = new PluginProcessmakerCase ;
$subCase -> add ([ 'id' => $sub_caseInfo -> caseNumber ,
'case_guid' => $sub_caseInfo -> caseId ,
'itemtype' => $itemtype ,
'items_id' => $items_id ,
'name' => $sub_caseInfo -> caseName ,
'entities_id' => $item -> fields [ 'entities_id' ],
'case_status' => $sub_caseInfo -> caseStatus ,
'plugin_processmaker_processes_id' => $locProc -> getID (),
'plugin_processmaker_cases_id' => $myCase -> getID ()]);
// then create associated task
if ( property_exists ( $sub_caseInfo , 'currentUsers' )) {
// there should be only one task
$sub_route = $sub_caseInfo -> currentUsers [ 0 ];
$this -> addTask ( $subCase -> getID (), $itemtype ,
$items_id ,
$sub_caseInfo ,
$sub_route -> delIndex ,
PluginProcessmakerUser :: getGLPIUserId ( $sub_route -> userId ),
0 ,
$sub_route -> taskId ,
$sub_route -> delThread ,
2019-01-14 16:19:24 +01:00
[ 'txtTaskContent' => $txtTaskContent ,
2019-05-21 10:47:15 +02:00
'start_date' => $taskStartDate ,
'end_date' => $taskEndDate ,
'reminder' => $taskReminder ]
2018-07-04 11:24:29 +02:00
);
// if end date was specified, then must change due date of the PM task
if ( $taskEndDate != '' ) {
$PM_DB -> query ( " UPDATE APP_DELEGATION SET DEL_TASK_DUE_DATE=' $taskEndDate ' WHERE APP_UID=' " . $sub_caseInfo -> caseId . " ' AND DEL_INDEX= " . $sub_route -> delIndex );
}
}
// must also send to new sub-process some GLPI variables
// like any newly started cases
// get the value of GLPI_ITEM_CAN_BE_SOLVED to transmit it to sub-case
2018-07-13 15:58:47 +02:00
$requesters = PluginProcessmakerProcessmaker :: getItemUsers ( $itemtype , $items_id , CommonITILActor :: REQUESTER ); // 1 for requesters
if ( ! key_exists ( 0 , $requesters )) {
$requesters [ 0 ][ 'glpi_id' ] = 0 ;
$requesters [ 0 ][ 'pm_id' ] = 0 ;
}
$glpi_variables = [ 'GLPI_ITEM_CAN_BE_SOLVED' => 0 ,
'GLPI_TICKET_ID' => $items_id ,
'GLPI_ITEM_ID' => $items_id ,
'GLPI_ITEM_TYPE' => $itemtype ,
2019-05-21 10:47:15 +02:00
'GLPI_ITEM_STATUS' => $item -> fields [ 'status' ],
2018-07-13 15:58:47 +02:00
'GLPI_TICKET_REQUESTER_GLPI_ID' => $requesters [ 0 ][ 'glpi_id' ],
'GLPI_ITEM_REQUESTER_GLPI_ID' => $requesters [ 0 ][ 'glpi_id' ],
'GLPI_TICKET_REQUESTER_PM_ID' => $requesters [ 0 ][ 'pm_id' ],
'GLPI_ITEM_REQUESTER_PM_ID' => $requesters [ 0 ][ 'pm_id' ],
'GLPI_TICKET_TITLE' => $item -> fields [ 'name' ],
'GLPI_ITEM_TITLE' => $item -> fields [ 'name' ],
'GLPI_TICKET_DESCRIPTION' => $item -> fields [ 'content' ],
'GLPI_ITEM_DESCRIPTION' => $item -> fields [ 'content' ],
2019-01-14 16:19:24 +01:00
'GLPI_ITEM_OPENING_DATE' => $item -> fields [ 'date' ],
2019-05-21 10:47:15 +02:00
'GLPI_TICKET_DUE_DATE' => $item -> fields [ 'time_to_resolve' ],
2019-01-14 16:19:24 +01:00
'GLPI_ITEM_DUE_DATE' => $item -> fields [ 'time_to_resolve' ],
2018-07-13 15:58:47 +02:00
'GLPI_ITEM_ITIL_CATEGORY_ID' => $item -> fields [ 'itilcategories_id' ],
'GLPI_TICKET_URGENCY' => $item -> fields [ 'urgency' ],
'GLPI_ITEM_URGENCY' => $item -> fields [ 'urgency' ],
'GLPI_ITEM_IMPACT' => $item -> fields [ 'impact' ],
'GLPI_ITEM_PRIORITY' => $item -> fields [ 'priority' ],
2019-05-21 10:47:15 +02:00
// Specific to Tickets and Changes
// GLPI_ITEM_GLOBAL_VALIDATION will be '' when Problem, else it will be the global_validation field
'GLPI_TICKET_GLOBAL_VALIDATION' => $itemtype == 'Problem' ? '' : $item -> fields [ 'global_validation' ],
'GLPI_ITEM_GLOBAL_VALIDATION' => $itemtype == 'Problem' ? '' : $item -> fields [ 'global_validation' ],
2018-07-13 15:58:47 +02:00
'GLPI_TICKET_TECHNICIAN_GLPI_ID' => $users_id ,
'GLPI_ITEM_TECHNICIAN_GLPI_ID' => $users_id ,
'GLPI_TICKET_TECHNICIAN_PM_ID' => PluginProcessmakerUser :: getPMUserId ( $users_id ),
'GLPI_ITEM_TECHNICIAN_PM_ID' => PluginProcessmakerUser :: getPMUserId ( $users_id ),
2019-05-21 10:47:15 +02:00
'GLPI_URL' => $CFG_GLPI [ 'url_base' ],
// Specific to Tickets
// GLPI_TICKET_TYPE will contains 1 (= incident) or 2 (= request)
'GLPI_TICKET_TYPE' => $itemtype == 'Ticket' ? $item -> fields [ 'type' ] : ''
2018-07-13 15:58:47 +02:00
];
$subCase -> sendVariables ( $glpi_variables );
2018-07-04 11:24:29 +02:00
// evolution of case status: DRAFT, TO_DO, COMPLETED, CANCELLED
2019-01-14 16:19:24 +01:00
$subCase -> update ( [ 'id' => $subCase -> getID (), 'case_status' => $sub_caseInfo -> caseStatus , 'name' => $sub_caseInfo -> caseName ] );
2018-07-04 11:24:29 +02:00
}
} else {
$this -> addTask ( $myCase -> getID (), $itemtype ,
$items_id ,
$caseInfo ,
$route -> delIndex ,
PluginProcessmakerUser :: getGLPIUserId ( $route -> userId ),
$groupId ,
$route -> taskId ,
$route -> delThread ,
2019-01-14 16:19:24 +01:00
[ 'txtTaskContent' => $txtTaskContent ,
2019-05-21 10:47:15 +02:00
'start_date' => $taskStartDate ,
'end_date' => $taskEndDate ,
'reminder' => $taskReminder ]
2018-07-04 11:24:29 +02:00
);
// if end date was specified, then must change due date of the PM task
if ( $taskEndDate != '' ) {
$PM_DB -> query ( " UPDATE APP_DELEGATION SET DEL_TASK_DUE_DATE=' $taskEndDate ' WHERE APP_UID=' " . $caseInfo -> caseId . " ' AND DEL_INDEX= " . $route -> delIndex );
}
}
}
2019-01-14 16:19:24 +01:00
} else {
// must check if current case is a sub-process, and if it has ended, then must reflect parent case into the current item.
if ( $myCase -> fields [ 'plugin_processmaker_cases_id' ] != 0 ) {
// current case is a sub-case of $myCase->fields['plugin_processmaker_cases_id']
$parentCase = new PluginProcessmakerCase ;
$parentCase -> getFromDB ( $myCase -> fields [ 'plugin_processmaker_cases_id' ]);
$parentCaseInfo = $parentCase -> getCaseInfo ();
// then create associated task
if ( property_exists ( $parentCaseInfo , 'currentUsers' )) {
// we may have several new task
foreach ( $parentCaseInfo -> currentUsers as $open_task ) {
// must check if $open_task is not is_subprocess and is not already existing in the item
$locTaskCat = new PluginProcessmakerTaskCategory ;
$locTask = new PluginProcessmakerTask ();
2019-05-21 10:47:15 +02:00
$locTaskRestrict = [
'WHERE' => [
'plugin_processmaker_cases_id' => $parentCase -> getID (),
'plugin_processmaker_taskcategories_id' => $locTaskCat -> getID (),
'del_index' => $open_task -> delIndex
],
];
2019-01-14 16:19:24 +01:00
if ( $locTaskCat -> getFromGUID ( $open_task -> taskId )
2018-07-04 11:24:29 +02:00
&& ! $locTaskCat -> fields [ 'is_subprocess' ]
2019-05-21 10:47:15 +02:00
&& ! $locTask -> getFromDBByRequest ( $locTaskRestrict )) {
2019-01-14 16:19:24 +01:00
$this -> addTask ( $parentCase -> getID (), $itemtype ,
2018-07-04 11:24:29 +02:00
$items_id ,
$parentCaseInfo ,
$open_task -> delIndex ,
PluginProcessmakerUser :: getGLPIUserId ( $open_task -> userId ),
0 ,
$open_task -> taskId ,
$open_task -> delThread ,
2019-01-14 16:19:24 +01:00
[ 'txtTaskContent' => $txtTaskContent ,
2019-05-21 10:47:15 +02:00
'start_date' => $taskStartDate ,
'end_date' => $taskEndDate ,
'reminder' => $taskReminder ]
2018-07-04 11:24:29 +02:00
);
2019-01-14 16:19:24 +01:00
// if end date was specified, then must change due date of the PM task
if ( $taskEndDate != '' ) {
$PM_DB -> query ( " UPDATE APP_DELEGATION SET DEL_TASK_DUE_DATE=' $taskEndDate ' WHERE APP_UID=' " . $sub_caseInfo -> caseId . " ' AND DEL_INDEX= " . $open_task -> delIndex );
}
2018-07-04 11:24:29 +02:00
}
}
}
2019-01-14 16:19:24 +01:00
// evolution of case status: DRAFT, TO_DO, COMPLETED, CANCELLED
$parentCase -> update ( [ 'id' => $parentCase -> getID (), 'case_status' => $parentCaseInfo -> caseStatus , 'name' => $parentCaseInfo -> caseName ] );
2018-07-04 11:24:29 +02:00
}
2018-05-14 16:56:52 +02:00
}
2017-05-06 18:38:24 +02:00
// evolution of case status: DRAFT, TO_DO, COMPLETED, CANCELLED
2019-01-14 16:19:24 +01:00
$myCase -> update ( [ 'id' => $myCase -> getID (), 'case_status' => $caseInfo -> caseStatus , 'name' => $caseInfo -> caseName ] );
2018-07-04 11:24:29 +02:00
2017-05-06 18:38:24 +02:00
}
2017-02-28 13:56:37 +01:00
/**
* Summary of getPMGroups
* @ return array
*/
2019-01-14 16:19:24 +01:00
public static function getPMGroups () {
2017-05-06 18:38:24 +02:00
global $PM_DB ;
2019-01-14 16:19:24 +01:00
$pmGroupList = [];
2017-05-06 18:38:24 +02:00
foreach ( $PM_DB -> request ( " SELECT * FROM CONTENT WHERE CONTENT.CON_CATEGORY='GRP_TITLE' AND CONTENT.CON_LANG='en' " ) as $dbgroup ) {
$pmGroupList [ $dbgroup [ 'CON_VALUE' ]] = $dbgroup ;
}
return $pmGroupList ;
}
2017-02-28 13:56:37 +01:00
/**
* Summary of displayMessage
* Show a html message bottom - right of screen
* @ param string $html_message message to be shown
* @ param string $title if '' then title bar is not shown ( default '' )
* @ param string $msgtype the type of the message ( ERROR | WARNING | INFO )
* @ return void
**/
2019-01-14 16:19:24 +01:00
static private function displayMessage ( $html_message , $title = '' , $msgtype = 'info_msg' ) {
2017-05-06 18:38:24 +02:00
//set title and css class
switch ( $msgtype ) {
case ERROR :
$title = __ ( 'Error' );
$class = 'err_msg' ;
break ;
case WARNING :
$title = __ ( 'Warning' );
$class = 'warn_msg' ;
break ;
case INFO :
$title = __ ( 'Information' );
$class = 'info_msg' ;
break ;
}
echo " <div id= \" message_after_redirect_ $msgtype\ " title = \ " $title\ " > " ;
echo $html_message ;
echo " </div> " ;
$scriptblock = "
2017-02-28 13:56:37 +01:00
$ ( document ) . ready ( function () {
var _of = window ;
var _at = 'right-20 bottom-20' ;
//calculate relative dialog position
$ ( '.message_after_redirect' ) . each ( function () {
var _this = $ ( this );
if ( _this . attr ( 'aria-describedby' ) != 'message_after_redirect_$msgtype' ) {
_of = _this ;
_at = 'right top-' + ( 10 + _this . outerHeight ());
}
});
$ ( '#message_after_redirect_$msgtype' ) . dialog ({
dialogClass : 'message_after_redirect $class' ,
minHeight : 40 ,
minWidth : 200 ,
position : {
my : 'right bottom' ,
at : _at ,
of : _of ,
collision : 'none'
},
autoOpen : false ,
show : {
effect : 'slide' ,
direction : 'down' ,
'duration' : 800
}
})
. dialog ( 'open' ); " ;
2017-05-06 18:38:24 +02:00
//do not autoclose errors
if ( $msgtype != ERROR ) {
$scriptblock .= "
2017-02-28 13:56:37 +01:00
// close dialog on outside click
$ ( document . body ) . on ( 'click' , function ( e ){
if ( $ ( '#message_after_redirect_$msgtype' ) . dialog ( 'isOpen' )
&& ! $ ( e . target ) . is ( '.ui-dialog, a' )
&& ! $ ( e . target ) . closest ( '.ui-dialog' ) . length ) {
$ ( '#message_after_redirect_$msgtype' ) . dialog ( 'close' );
// redo focus on initial element
e . target . focus ();
}
}); " ;
2017-05-06 18:38:24 +02:00
}
2017-02-28 13:56:37 +01:00
2017-05-06 18:38:24 +02:00
$scriptblock .= "
2017-02-28 13:56:37 +01:00
});
" ;
2017-05-06 18:38:24 +02:00
echo Html :: scriptBlock ( $scriptblock );
}
2018-02-01 16:01:09 +01:00
2018-08-02 16:57:00 +02:00
/**
* Summary of underMaintenance
* Shows a nice ( ? ) under maintenance message
*/
static function showUnderMaintenance () {
global $CFG_GLPI ;
echo " <div class='center'> " ;
echo Html :: image ( $CFG_GLPI [ 'root_doc' ] . '/plugins/processmaker/pics/under_maintenance.png' );
echo " <p style='font-weight: bold;'> " ;
2019-05-21 10:47:15 +02:00
echo __ ( 'ProcessMaker plugin is under maintenance, please retry later, thank you.' , 'processmaker' );
2018-08-02 16:57:00 +02:00
echo " </p> " ;
echo " </div> " ;
}
2019-05-21 10:47:15 +02:00
/**
* Summary of echoDomain
*/
function echoDomain () {
if ( isset ( $this -> config -> fields [ 'domain' ]) && $this -> config -> fields [ 'domain' ] != '' ) {
$script = "
( function () {
var id = 'commonDomainGlpiPmScript_Wjd4uWisWHLt9I' ;
//debugger;
if ( $ ( '#' + id ) . length == 0 ) {
//debugger;
var d = document , g = d . createElement ( 'script' ), s = d . getElementsByTagName ( 'script' )[ 0 ];
g . type = 'text/javascript' ;
g . id = id ;
g . text = 'try { document.domain = \'".$this->config->fields[' domain ']."\'; } catch(ev) { /*console.log(ev);*/ }' ;
s . parentNode . insertBefore ( g , s );
}
})(); " ;
echo Html :: scriptBlock ( $script );
}
}
2017-05-06 18:38:24 +02:00
}