2015-10-09 14:13:52 +02:00
< ? php
2016-10-25 11:37:01 +02:00
include_once ( " ../../../inc/includes.php " );
2015-10-09 14:13:52 +02:00
2017-05-06 18:38:24 +02:00
switch ( $_POST [ " action " ]) {
case 'newcase' :
2019-05-21 10:47:15 +02:00
if ( isset ( $_POST [ 'items_id' ]) && $_POST [ 'items_id' ] > 0 ) {
2017-04-28 14:57:49 +02:00
2019-05-21 10:47:15 +02:00
// then this case will be bound to an item
2018-07-04 11:24:29 +02:00
if ( $_POST [ 'plugin_processmaker_processes_id' ] > 0 ) {
$resultCase = $PM_SOAP -> startNewCase ( $_POST [ 'plugin_processmaker_processes_id' ], $_POST [ 'itemtype' ], $_POST [ 'items_id' ], Session :: getLoginUserID ());
2017-04-28 14:57:49 +02:00
2017-05-06 18:38:24 +02:00
if ( $resultCase -> status_code == 0 ) {
2018-07-04 11:24:29 +02:00
$case = new PluginProcessmakerCase ;
if ( $case -> getFromGUID ( $resultCase -> caseId )) {
$link = $case -> getLinkURL ();
2019-07-29 08:33:55 +02:00
$task = new PluginProcessmakerTask ( $_POST [ 'itemtype' ] . 'Task' );
2019-05-21 10:47:15 +02:00
$task -> getFromDBByRequest ([
'WHERE' => [
'plugin_processmaker_cases_id' => $case -> getID ()
],
]);
//$task->getFromDBByQuery(" WHERE `plugin_processmaker_cases_id`=".$case->getID()); // normally there is only one and only one first task
2018-07-04 11:24:29 +02:00
//$link .= '&forcetab=PluginProcessmakerTask$'.$task->getID();
2019-05-21 10:47:15 +02:00
Session :: setActiveTab ( 'PluginProcessmakerCase' , 'PluginProcessmakerTask$' . $task -> fields [ 'id' ]);
2018-07-04 11:24:29 +02:00
$item = new $_POST [ 'itemtype' ];
$item -> getFromDB ( $_POST [ 'items_id' ]);
unset ( $_SERVER [ 'REQUEST_URI' ]); // to prevent use of processmaker.form.php in NavigateList
2018-08-02 16:57:00 +02:00
Session :: initNavigateListItems ( 'PluginProcessmakerCase' ,
2018-07-04 11:24:29 +02:00
//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
$_POST [ 'itemtype' ] :: getTypeName ( 1 ), $item -> fields [ " name " ]));
Html :: redirect ( $link );
}
2017-05-06 18:38:24 +02:00
Html :: back ();
2015-10-09 14:13:52 +02:00
} else {
2018-08-02 16:57:00 +02:00
Session :: addMessageAfterRedirect ( PluginProcessmakerProcessmaker :: getPMErrorMessage ( $resultCase -> status_code ) . " <br> " . $resultCase -> message . " ( " . $resultCase -> status_code . " ) " , true , ERROR );
2015-10-09 14:13:52 +02:00
}
2017-05-06 18:38:24 +02:00
} else {
Html :: back ();
}
} else { // the case is created before the ticket (used for post-only case creation before ticket creation)
2019-05-21 10:47:15 +02:00
$pm_user_guid = PluginProcessmakerUser :: getPMUserId ( Session :: getLoginUserID () );
2018-07-04 11:24:29 +02:00
$resultCase = $PM_SOAP -> newCase ( $_POST [ 'plugin_processmaker_processes_id' ],
2019-05-21 10:47:15 +02:00
[ 'GLPI_ITEM_CAN_BE_SOLVED' => 0 ,
'GLPI_SELFSERVICE_CREATED' => '1' ,
'GLPI_ITEM_TYPE' => 'Ticket' ,
'GLPI_URL' => $CFG_GLPI [ 'url_base' ],
// Specific to Tickets
// GLPI_TICKET_TYPE will contains 1 (= incident) or 2 (= request)
'GLPI_TICKET_TYPE' => $_POST [ 'type' ],
'GLPI_ITEM_REQUESTER_GLPI_ID' => Session :: getLoginUserID (),
'GLPI_ITEM_REQUESTER_PM_ID' => $pm_user_guid
] );
2017-05-06 18:38:24 +02:00
if ( $resultCase -> status_code == 0 ) {
// case is created
// Must show it...
//
$rand = rand ( );
2018-07-04 11:24:29 +02:00
Html :: redirect ( $CFG_GLPI [ 'root_doc' ] . " /plugins/processmaker/front/processmaker.helpdesk.form.php?processes_id= " . $_POST [ 'plugin_processmaker_processes_id' ] . " &case_guid= " . $resultCase -> caseId . " &rand= $rand &itilcategories_id= " . $_POST [ " itilcategories_id " ] . " &type= " . $_REQUEST [ " type " ] . " &entities_id= " . $_REQUEST [ 'entities_id' ]);
2017-04-28 14:57:49 +02:00
2017-05-06 18:38:24 +02:00
} else {
2019-01-14 16:19:24 +01:00
Session :: addMessageAfterRedirect ( PluginProcessmakerProcessmaker :: getPMErrorMessage ( $resultCase -> status_code ) . " <br> $resultCase->message ( $resultCase->status_code ) " , true , ERROR );
2017-05-06 18:38:24 +02:00
Html :: redirect ( $CFG_GLPI [ " root_doc " ] . " /front/helpdesk.public.php?create_ticket=1 " );
}
}
2017-04-28 14:57:49 +02:00
break ;
2017-05-06 18:38:24 +02:00
case 'unpausecase_or_reassign_or_delete' :
2018-07-04 11:24:29 +02:00
if ( isset ( $_POST [ 'unpause' ])) {
$locCase = new PluginProcessmakerCase ;
$locCase -> getFromDB ( $_POST [ 'cases_id' ]);
$pmResultUnpause = $locCase -> unpauseCase ( $_POST [ 'delIndex' ], $_POST [ 'users_id' ]);
2017-05-06 18:38:24 +02:00
if ( $pmResultUnpause -> status_code == 0 ) {
Html :: back ();
} else {
echo " Error unpausing case: " . $pmResultUnpause -> message . " \n " ;
}
2018-07-04 11:24:29 +02:00
} else if ( isset ( $_POST [ 'reassign' ])) {
// here we should re-assign the current task to $_POST['users_id_recipient']
//$GLPINewPMUserId = PluginProcessmakerUser::getPMUserId( $_POST['users_id_recipient'] );
2019-08-06 15:26:07 +02:00
if ( $_POST [ 'users_id' ] != $_POST [ 'users_id_recipient' ] && $_POST [ 'users_id_recipient' ] != 0 ) { // normally should be different as of the dropdown prevents already used
2018-07-04 11:24:29 +02:00
$locCase = new PluginProcessmakerCase ;
$locCase -> getFromDB ( $_POST [ 'cases_id' ]);
$pmResponse = $locCase -> reassignCase ( $_POST [ 'delIndex' ],
$_POST [ 'taskGuid' ],
$_POST [ 'delThread' ],
$_POST [ 'users_id' ],
$_POST [ 'users_id_recipient' ]);
if ( $pmResponse ) {
2018-08-02 16:57:00 +02:00
Session :: addMessageAfterRedirect ( __ ( 'Task re-assigned!' , 'processmaker' ), true , INFO );
2017-05-06 18:38:24 +02:00
} else {
2018-08-02 16:57:00 +02:00
Session :: addMessageAfterRedirect ( __ ( 'Error re-assigning task: ' , 'processmaker' ) . $pmResponse -> message , true , ERROR );
2017-05-06 18:38:24 +02:00
}
} else {
2019-08-06 15:26:07 +02:00
if ( $_POST [ 'users_id_recipient' ] == 0 ) {
Session :: addMessageAfterRedirect ( __ ( 'Can\'t un-assign Task!' , 'processmaker' ), true , ERROR );
} else {
if ( $_POST [ 'users_id' ] === $_POST [ 'users_id_recipient' ] ) { // normally should be different as of the dropdown prevents already used
Session :: addMessageAfterRedirect ( __ ( 'Task already assigned to this person!' , 'processmaker' ), true , ERROR );
}
}
2017-05-06 18:38:24 +02:00
}
2019-01-14 16:19:24 +01:00
//} else if (isset($_POST['delete'])) {
// // delete case from case table, this will also delete the tasks
// $locCase = new PluginProcessmakerCase;
// if ($locCase->getFromDB($_POST['cases_id']) && $locCase->deleteCase()) {
// // request delete from pm itself
// $PM_SOAP->login(true);
// $resultPM = $PM_SOAP->deleteCase($locCase->fields['case_guid']);
// if ($resultPM->status_code == 0) {
// Session::addMessageAfterRedirect($LANG['processmaker']['item']['case']['deleted'], true, INFO);
// } else {
// Session::addMessageAfterRedirect($LANG['processmaker']['item']['case']['errordeleted'], true, ERROR);
// }
// } else {
// Session::addMessageAfterRedirect($LANG['processmaker']['item']['case']['errordeleted'], true, ERROR);
// }
//} else if (isset($_POST['cancel'])) {
// // cancel case from PM
// $locCase = new PluginProcessmakerCase;
// $locCase->getFromDB($_POST['cases_id']);
// $resultPM = $PM_SOAP->cancelCase($locCase->fields['case_guid']); //, $_POST['plugin_processmaker_del_index'], $_POST['plugin_processmaker_users_id'] ) ;
// if ($resultPM->status_code === 0) {
// //$locCase = new PluginProcessmakerCase;
// //$locCase->getFromDB($_POST['cases_id']);
// if ($locCase->cancelCase()) {
// Session::addMessageAfterRedirect($LANG['processmaker']['item']['case']['cancelled'], true, INFO);
// } else {
// Session::addMessageAfterRedirect($LANG['processmaker']['item']['case']['errorcancelled'], true, ERROR);
// }
// } else {
// if ($resultPM->status_code == 100 && $locCase->deleteCase()) { // case is draft then delete it
// // request delete from pm itself
// $PM_SOAP->login(true);
// $resultPM = $PM_SOAP->deleteCase($locCase->fields['case_guid']);
// if ($resultPM->status_code == 0) {
// Session::addMessageAfterRedirect($LANG['processmaker']['item']['case']['deleted'], true, INFO);
// } else {
// Session::addMessageAfterRedirect($LANG['processmaker']['item']['case']['errordeleted'], true, ERROR);
// }
// } else {
// Session::addMessageAfterRedirect($LANG['processmaker']['item']['case']['errorcancelled']. " " . $resultPM->message, true, ERROR);
// }
// }
2017-05-06 18:38:24 +02:00
}
2017-04-28 14:57:49 +02:00
2017-05-06 18:38:24 +02:00
break ;
2015-10-09 14:13:52 +02:00
}
2018-07-04 11:24:29 +02:00
// to return to item
2015-10-09 14:13:52 +02:00
Html :: back ();