2016-10-25 11:37:01 +02:00
< ? php
/**
* tasks short summary .
*
* tasks description .
*
* @ version 1.0
* @ author MoronO
*/
class PluginProcessmakerTask extends CommonITILTask
{
2017-05-06 18:38:24 +02:00
private $itemtype ;
2019-01-14 16:19:24 +01:00
function __construct ( $itemtype = 'TicketTask' ) {
2017-05-06 18:38:24 +02:00
parent :: __construct ();
2019-01-14 16:19:24 +01:00
$this -> itemtype = $itemtype ;
2017-05-06 18:38:24 +02:00
}
2016-10-25 11:37:01 +02:00
2018-08-06 16:12:16 +02:00
const OPEN = 'OPEN' ;
const CLOSED = 'CLOSED' ;
2018-07-04 11:24:29 +02:00
/**
* Name of the type
*
* @ param $nb : number of item in the type ( default 0 )
**/
2019-01-14 16:19:24 +01:00
static function getTypeName ( $nb = 0 ) {
2018-08-02 16:57:00 +02:00
return _n ( 'Process case task' , 'Process case tasks' , $nb , 'processmaker' );
2018-07-04 11:24:29 +02:00
}
function getItilObjectItemType () {
return str_replace ( 'Task' , '' , $this -> itemtype );
}
2016-10-25 11:37:01 +02:00
/**
* Summary of getFromDB
* @ param mixed $items_id
* @ param mixed $itemtype
* @ return bool
*/
2017-05-06 18:38:24 +02:00
function getFromDB ( $items_id ) {
global $DB ;
2016-10-25 11:37:01 +02:00
2017-05-06 18:38:24 +02:00
if ( $this -> getFromDBByQuery ( " WHERE itemtype=' " . $this -> itemtype . " ' AND items_id= $items_id ; " )) {
$task = new $this -> itemtype ;
if ( $task -> getFromDB ( $items_id )) {
// then we should add our own fields
$task -> fields [ 'items_id' ] = $this -> fields [ 'id' ];
$task -> fields [ 'itemtype' ] = $this -> fields [ 'itemtype' ];
unset ( $this -> fields [ 'id' ] );
unset ( $this -> fields [ 'items_id' ] );
unset ( $this -> fields [ 'itemtype' ] );
foreach ( $this -> fields as $field => $val ) {
$task -> fields [ $field ] = $val ;
}
$this -> fields = $task -> fields ;
return true ;
}
}
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
/**
* Summary of getToDoTasks
* returns all 'to do' tasks associated with this case
* @ param mixed $case_id
*/
2019-01-14 16:19:24 +01:00
public static function getToDoTasks ( $case_id , $itemtype ) {
2017-05-06 18:38:24 +02:00
global $DB ;
2019-01-14 16:19:24 +01:00
$ret = [];
$dbu = new DbUtils ;
$selfTable = $dbu -> getTableForItemType ( __CLASS__ );
2018-08-06 16:12:16 +02:00
//$itemTypeTaskTable = getTableForItemType( $itemtype );
2016-10-25 11:37:01 +02:00
2018-08-07 14:17:34 +02:00
$query = " SELECT ` $selfTable `.`items_id` as taskID from $selfTable
2018-08-06 16:12:16 +02:00
WHERE `$selfTable` . `del_thread_status` = '".self::OPEN."' AND `$selfTable` . `plugin_processmaker_cases_id` = '$case_id' ; " ;
//$query = "SELECT $itemTypeTaskTable.id as taskID from $itemTypeTaskTable
// INNER JOIN $selfTable on $selfTable.items_id=$itemTypeTaskTable.id
// WHERE $itemTypeTaskTable.state=1 and $selfTable.plugin_processmaker_cases_id='$case_id';";
2017-05-06 18:38:24 +02:00
foreach ( $DB -> request ( $query ) as $row ) {
$ret [ $row [ 'taskID' ]] = $row [ 'taskID' ];
}
return $ret ;
}
2016-10-25 11:37:01 +02:00
2019-01-14 16:19:24 +01:00
static function canView () {
2017-05-06 18:38:24 +02:00
return true ;
2016-10-25 11:37:01 +02:00
}
static function populatePlanning ( $params ) {
2019-01-14 16:19:24 +01:00
//global $CFG_GLPI;
$events = [];
2017-02-28 13:56:37 +01:00
2017-05-06 18:38:24 +02:00
if ( isset ( $params [ 'start' ])) {
2017-02-28 13:56:37 +01:00
$params [ 'begin' ] = '2000-01-01 00:00:00' ;
2017-04-28 14:57:49 +02:00
if ( $params [ 'type' ] == 'group' ) {
$params [ 'who_group' ] = $params [ 'who' ];
$params [ 'whogroup' ] = $params [ 'who' ];
2017-05-06 18:38:24 +02:00
$params [ 'who' ] = 0 ;
2017-04-28 14:57:49 +02:00
}
2016-10-25 11:37:01 +02:00
2019-01-14 16:19:24 +01:00
$objects = [ 'TicketTask' , 'ChangeTask' , 'ProblemTask' ];
//foreach ($objects as $itemtype) {
foreach ( $_SESSION [ 'glpi_plannings' ][ 'filters' ] as $tasktype => $iteminfo ) {
if ( ! $iteminfo [ 'display' ] || ! in_array ( $tasktype , $objects )) {
continue ;
}
$ret = CommonITILTask :: genericPopulatePlanning ( $tasktype , $params );
foreach ( $ret as $key => $event ) {
// if todo or done but need to show them (=planning)
if ( $event [ 'state' ] == Planning :: TODO || $event [ 'state' ] == Planning :: INFO || ( $params [ 'display_done_events' ] == 1 && $event [ 'state' ] == Planning :: DONE )) {
// check if task is one within a case
$pmTask = new PluginProcessmakerTask ( $tasktype );
if ( $pmTask -> getFromDB ( $event [ strtolower ( $tasktype ) . 's_id' ])) { // $pmTask->getFromDBByQuery( " WHERE itemtype = 'TicketTask' AND items_id = ". $event['tickettasks_id'] ) ) {
$event [ 'editable' ] = false ;
//$event['url'] .= '&forcetab=PluginProcessmakerCase$processmakercases';
$tmpCase = new PluginProcessmakerCase ;
$tmpCase -> getFromDB ( $pmTask -> fields [ 'plugin_processmaker_cases_id' ]);
$event [ 'url' ] = $tmpCase -> getLinkURL () . '&forcetab=PluginProcessmakerTask$' . $pmTask -> fields [ 'items_id' ];
$taskCat = new TaskCategory ;
$taskCat -> getFromDB ( $pmTask -> fields [ 'taskcategories_id' ] );
$taskComment = isset ( $taskCat -> fields [ 'comment' ]) ? $taskCat -> fields [ 'comment' ] : '' ;
if ( Session :: haveTranslations ( 'TaskCategory' , 'comment' )) {
$taskComment = DropdownTranslation :: getTranslatedValue ( $taskCat -> getID (), 'TaskCategory' , 'comment' , $_SESSION [ 'glpilanguage' ], $taskComment );
}
$event [ 'content' ] = str_replace ( '##processmaker.taskcomment##' , $taskComment , $event [ 'content' ] );
$event [ 'content' ] = str_replace ( [ '\n##processmakercase.url##' , '##processmakercase.url##' ], " " , $event [ 'content' ] ); //<a href=\"".$event['url']."\">"."Click to manage task"."</a>
//if( $event['state'] == 1 && $event['end'] < $params['start'] ) { // if todo and late
// $event['name'] = $event['end'].' '.$event['name'] ; //$event['begin'].' to '.$event['end'].' '.$event['name'] ;
// $event['end'] = $params['start'].' 24:00:00'; //.$CFG_GLPI['planning_end'];
//}
$events [ $key ] = $event ;
}
2016-10-25 11:37:01 +02:00
}
}
}
}
2017-05-06 18:38:24 +02:00
return $events ;
2016-10-25 11:37:01 +02:00
}
2019-01-14 16:19:24 +01:00
function getTabNameForItem ( CommonGLPI $case , $withtemplate = 0 ) {
2018-08-06 16:12:16 +02:00
global $DB , $PM_DB ;
2018-08-02 16:57:00 +02:00
$tab = [];
2018-07-04 11:24:29 +02:00
$caseInfo = $case -> getCaseInfo ();
if ( property_exists ( $caseInfo , 'currentUsers' )) {
2019-01-14 16:19:24 +01:00
$dbu = new DbUtils ;
2018-07-13 15:58:47 +02:00
$GLPICurrentPMUserId = PluginProcessmakerUser :: getPMUserId ( Session :: getLoginUserID ());
// get all tasks that are OPEN for this case
$tasks = [];
$query = " SELECT * FROM `glpi_plugin_processmaker_tasks` WHERE `plugin_processmaker_cases_id`= { $case -> fields [ 'id' ] } AND `del_thread_status`='OPEN' " ;
2019-01-14 16:19:24 +01:00
foreach ( $DB -> request ( $query ) as $task ) {
2018-07-13 15:58:47 +02:00
$tasks [ $task [ 'del_index' ]] = $task ;
}
2018-08-06 16:12:16 +02:00
//// get all tasks that are OPEN for any sub-case of this case
//$sub_cases = [];
//$query = "SELECT `glpi_plugin_processmaker_tasks`.* FROM `glpi_plugin_processmaker_tasks`
// JOIN `glpi_plugin_processmaker_cases` on `glpi_plugin_processmaker_cases`.`id`=`glpi_plugin_processmaker_tasks`.`plugin_processmaker_cases_id`
// WHERE `glpi_plugin_processmaker_cases`.`plugin_processmaker_cases_id`={$case->fields['id']} AND `del_thread_status`='OPEN'";
//foreach($DB->request($query) as $task) {
// $sub_cases[$task['plugin_processmaker_cases_id']][$task['del_index']] = $task;
//}
2018-07-13 15:58:47 +02:00
2018-07-27 16:13:15 +02:00
$caseInfo -> currentUsers = $case -> sortTasks ( $caseInfo -> currentUsers , $GLPICurrentPMUserId );
2018-07-13 15:58:47 +02:00
2018-08-06 16:12:16 +02:00
$main_tasks = []; //will contains the tasks that are main-processes
foreach ( $caseInfo -> currentUsers as $caseUser ) {
2018-07-04 11:24:29 +02:00
$title = $caseUser -> taskName ;
if ( isset ( $tasks [ $caseUser -> delIndex ])) {
$hide_claim_button = false ;
if ( $caseUser -> userId == '' ) { // task to be claimed
2019-01-14 16:19:24 +01:00
$itemtask = $dbu -> getItemForItemtype ( $tasks [ $caseUser -> delIndex ][ 'itemtype' ]);
2018-07-04 11:24:29 +02:00
$itemtask -> getFromDB ( $tasks [ $caseUser -> delIndex ][ 'items_id' ]);
// check if this group can be found in the current user's groups
if ( ! isset ( $_SESSION [ 'glpigroups' ]) || ! in_array ( $itemtask -> fields [ 'groups_id_tech' ], $_SESSION [ 'glpigroups' ] )) {
$hide_claim_button = true ;
}
}
$tab [ $tasks [ $caseUser -> delIndex ][ 'id' ]] = ( $caseUser -> userId != '' && $caseUser -> userId != $GLPICurrentPMUserId ) || $hide_claim_button ? " <i><sub> $title </sub></i> " : $title ;
2018-08-06 16:12:16 +02:00
} else {
$main_tasks [ $caseUser -> delIndex ] = $caseUser ;
2018-07-04 11:24:29 +02:00
}
}
2018-08-06 16:12:16 +02:00
foreach ( $main_tasks as $task ) {
$res = $PM_DB -> query ( " SELECT APP_UID FROM SUB_APPLICATION WHERE APP_PARENT=' { $case -> fields [ 'case_guid' ] } ' AND DEL_INDEX_PARENT= { $task -> delIndex } AND SA_STATUS='ACTIVE' " );
if ( $res && $PM_DB -> numrows ( $res ) == 1 ) {
$row = $PM_DB -> fetch_assoc ( $res );
$loc_case = new PluginProcessmakerCase ;
$loc_case -> getFromGUID ( $row [ 'APP_UID' ]);
$tab [ $loc_case -> getID () . " - " . $task -> delIndex ] = " <i><sub>> " . $task -> taskName . " </sub></i> " ;
}
}
//$sub_case = new PluginProcessmakerCase;
//foreach ($sub_cases as $sub_cases_id => $sub_tasks) {
// $sub_case->getFromDB($sub_cases_id);
// $sub_case_info = $sub_case->getCaseInfo();
// $sub_case_info->currentUsers = $sub_case->sortTasks($sub_case_info->currentUsers, $GLPICurrentPMUserId);
// foreach ($sub_case_info->currentUsers as $caseUser) {
// $title = $caseUser->taskName;
// if (isset($sub_tasks[$caseUser->delIndex])) {
// $hide_claim_button = false;
// if ($caseUser->userId == '') { // task to be claimed
// $itemtask = getItemForItemtype($sub_tasks[$caseUser->delIndex]['itemtype']);
// $itemtask->getFromDB($sub_tasks[$caseUser->delIndex]['items_id']);
// // check if this group can be found in the current user's groups
// if (!isset($_SESSION['glpigroups']) || !in_array( $itemtask->fields['groups_id_tech'], $_SESSION['glpigroups'] )) {
// $hide_claim_button = true;
// }
// }
// $tab["$sub_cases_id-".$sub_tasks[$caseUser->delIndex]['id']] = ($caseUser->userId != '' && $caseUser->userId != $GLPICurrentPMUserId) || $hide_claim_button ? "<i><sub>> $title</sub></i>" : "> $title";
// }
// }
//}
2018-07-13 15:58:47 +02:00
2018-08-06 16:12:16 +02:00
}
2018-07-13 15:58:47 +02:00
2018-08-06 16:12:16 +02:00
return $tab ;
2018-07-04 11:24:29 +02:00
}
/**
* Summary of displayTabContentForItem
* @ param CommonGLPI $case the PluginProcessmakerCase
2018-07-13 15:58:47 +02:00
* @ param integer $tabnum contains the PluginProcessmakerTask id
2018-07-04 11:24:29 +02:00
* @ param mixed $withtemplate
*/
2019-01-14 16:19:24 +01:00
static function displayTabContentForItem ( CommonGLPI $case , $tabnum = 1 , $withtemplate = 0 ) {
2018-08-06 16:12:16 +02:00
global $CFG_GLPI , $PM_SOAP , $DB , $PM_DB ;
2019-01-14 16:19:24 +01:00
$dbu = new DbUtils ;
2018-08-06 16:12:16 +02:00
// check if we are going to view a sub-task, then redirect to sub-case itself
if ( preg_match ( '/^(?\'cases_id\'\d+)-(\d+)$/' , $tabnum , $matches )) {
// Show sub-task list
// get all tasks that are OPEN for any sub-case of this case
$sub_tasks = [];
$query = " SELECT `glpi_plugin_processmaker_tasks`.* FROM `glpi_plugin_processmaker_tasks`
WHERE `glpi_plugin_processmaker_tasks` . `plugin_processmaker_cases_id` = { $matches [ 'cases_id' ]} AND `del_thread_status` = 'OPEN' " ;
2019-01-14 16:19:24 +01:00
foreach ( $DB -> request ( $query ) as $task ) {
2018-08-06 16:12:16 +02:00
$sub_tasks [ $task [ 'plugin_processmaker_cases_id' ]][ $task [ 'del_index' ]] = $task ;
}
$sub_case = new PluginProcessmakerCase ;
$sub_case -> getFromDB ( $matches [ 'cases_id' ]);
$sub_case_url = $sub_case -> getLinkURL () . '&forcetab=PluginProcessmakerTask$' ;
$query = " SELECT `DEL_INDEX`, `DEL_DELEGATE_DATE` FROM `APP_DELEGATION` WHERE `APP_UID`=' { $sub_case -> fields [ 'case_guid' ] } ' " ;
$sub_tasks_pm = [];
2019-01-14 16:19:24 +01:00
foreach ( $PM_DB -> request ( $query ) as $row ) {
2018-08-06 16:12:16 +02:00
$sub_tasks_pm [ $row [ 'DEL_INDEX' ]] = $row [ 'DEL_DELEGATE_DATE' ];
}
$sub_case_info = $sub_case -> getCaseInfo ();
echo " <div class='center'> " ;
echo " <table style='margin-bottom: 0px' class='tab_cadre_fixe'> " ;
echo " <tr><th colspan=4> " . __ ( 'Sub-case task(s)' , 'processmaker' ) . " </th></tr> " ;
if ( property_exists ( $sub_case_info , 'currentUsers' ) && count ( $sub_case_info -> currentUsers ) > 0 ) {
echo " <tr style='font-weight: bold;'>
< th > " .__('Task', 'processmaker'). " </ th >
< th > " .__('Task guid', 'processmaker'). " </ th >
< th > " .__('Current user', 'processmaker'). " </ th >
< th > " .__('Task delegation date', 'processmaker'). " </ th >
</ tr > " ;
2019-01-14 16:19:24 +01:00
foreach ( $sub_case_info -> currentUsers as $currentTask ) {
2018-08-06 16:12:16 +02:00
echo " <tr> " ;
$sub_case_url .= $sub_tasks [ $matches [ 'cases_id' ]][ $currentTask -> delIndex ][ 'id' ];
echo " <td class='tab_bg_2'><a href=' $sub_case_url '> " . $currentTask -> taskName . " </a></td> " ;
echo " <td class='tab_bg_2'> " . $currentTask -> taskId . " </td> " ;
if ( $currentTask -> userName == '' ) {
echo " <td class='tab_bg_2'> " . __ ( 'To be claimed' , 'processmaker' ) . " </td> " ;
} else {
echo " <td class='tab_bg_2'> " . $currentTask -> userName . " </td> " ;
}
echo " <td class='tab_bg_2'> " . $sub_tasks_pm [ $currentTask -> delIndex ] . " </td> " ;
echo " </tr> " ;
}
} else {
echo " <td colspan=4> " . __ ( 'None' ) . " </td> " ;
}
echo " </table> " ;
echo " </div> " ;
return ;
}
2018-07-04 11:24:29 +02:00
$hide_claim_button = false ;
$config = $PM_SOAP -> config ;
$rand = rand ();
// get infos for the current task
2019-01-14 16:19:24 +01:00
$task = $dbu -> getAllDataFromTable ( 'glpi_plugin_processmaker_tasks' , " id = $tabnum " );
2018-07-04 11:24:29 +02:00
// shows the re-assign form
$caseInfo = $case -> getCaseInfo ();
$currentUser = null ;
foreach ( $caseInfo -> currentUsers as $locTask ) {
if ( $locTask -> delIndex == $task [ $tabnum ][ 'del_index' ]) {
$currentUser = $locTask ;
break ;
}
}
if ( isset ( $currentUser )) {
if ( $currentUser -> userId && $task [ $tabnum ][ 'del_index' ]) {
// to load users for task re-assign only when task is not to be 'claimed' and if task is not a sub-case
echo " <div class='tab_bg_2' id='divUsers- " . $currentUser -> delIndex . " '><div class='loadingindicator'> " . __ ( 'Loading...' ) . " </div></div> " ;
echo " <script> $ ('#divUsers- { $task [ $tabnum ][ 'del_index' ] } ').load( ' " . $CFG_GLPI [ " root_doc " ] . " /plugins/processmaker/ajax/task_users.php?cases_id= "
. $case -> getID ()
. " &items_id= "
. $case -> fields [ 'items_id' ]
. " &itemtype= "
. $case -> fields [ 'itemtype' ]
. " &users_id= "
. PluginProcessmakerUser :: getGLPIUserId ( $currentUser -> userId )
. " &taskGuid= "
. $currentUser -> taskId
. " &delIndex= { $task [ $tabnum ][ 'del_index' ] } &delThread= { $currentUser -> delThread } &rand= $rand ' ); </script> " ;
} else {
// manages the claim
// current task is to be claimed
// get the assigned group to the item task
2019-01-14 16:19:24 +01:00
$itemtask = $dbu -> getItemForItemtype ( $task [ $tabnum ][ 'itemtype' ] );
2018-07-04 11:24:29 +02:00
$itemtask -> getFromDB ( $task [ $tabnum ][ 'items_id' ] );
// check if this group can be found in the current user's groups
if ( ! isset ( $_SESSION [ 'glpigroups' ]) || ! in_array ( $itemtask -> fields [ 'groups_id_tech' ], $_SESSION [ 'glpigroups' ] )) {
$hide_claim_button = true ;
}
}
}
echo " <script type='text/javascript' src=' " . $CFG_GLPI [ " root_doc " ] . " /plugins/processmaker/js/cases.js'></script> " ;
$csrf = Session :: getNewCSRFToken ();
2019-01-14 16:19:24 +01:00
//echo "<iframe id='caseiframe-task-{$task[$tabnum]['del_index']}' onload=\"onTaskFrameLoad( event, {$task[$tabnum]['del_index']}, "
// .($hide_claim_button?"true":"false")
// .", '$csrf' );\" style='border:none;' class='tab_bg_2' width='100%' src='";
//echo $PM_SOAP->serverURL
// ."/cases/cases_Open?sid="
// .$PM_SOAP->getPMSessionID()
// ."&APP_UID="
// .$case->fields['case_guid']
// ."&DEL_INDEX="
// .$task[$tabnum]['del_index']
// ."&action=TO_DO";
//echo "&rand=$rand&glpi_domain={$config->fields['domain']}'></iframe></div>";
$url = $PM_SOAP -> serverURL
. " /cases/cases_Open?sid= " . $PM_SOAP -> getPMSessionID ()
. " &APP_UID= " . $case -> fields [ 'case_guid' ]
. " &DEL_INDEX= " . $task [ $tabnum ][ 'del_index' ]
. " &action=TO_DO "
. " &rand= $rand "
. " &glpi_domain= { $config -> fields [ 'domain' ] } " ;
$encoded_url = urlencode ( $url );
2018-07-04 11:24:29 +02:00
echo " <iframe id='caseiframe-task- { $task [ $tabnum ][ 'del_index' ] } ' onload= \" onTaskFrameLoad( event, { $task [ $tabnum ][ 'del_index' ] } , "
2019-01-14 16:19:24 +01:00
. ( $hide_claim_button ? " true " : " false " ) . " , ' $csrf '); \" style='border:none;' class='tab_bg_2' width='100%' src=' $url '></iframe></div> " ;
echo Html :: scriptBlock ( "
$ ( '#tabspanel' ) . next ( 'div[id^=\"tabs\"]' ) . on ( 'tabsbeforeactivate' , function ( event , ui ) {
function urldecode ( url ) {
return decodeURIComponent ( url . replace ( / \ +/ g , ' ' ));
}
var iframe_id = 'caseiframe-task-{$task[$tabnum][' del_index ']}' ;
var iframe = ui . newPanel . children ( 'iframe[id=\"' + iframe_id + '\"]' );
if ( iframe . length != 0 ) {
var str = urldecode ( '$encoded_url' );
$ . ajax ( { url : str ,
xhrFields : { withCredentials : true },
success : function ( jqXHR ) {
//debugger;
},
error : function ( jqXHR ) {
// debugger;
},
cache : false ,
crossDomain : true
}
);
}
});
" );
2018-07-04 11:24:29 +02:00
}
2016-10-25 11:37:01 +02:00
}