2015-10-09 14:13:52 +02:00
< ? php
2016-10-25 11:37:01 +02:00
2015-10-09 14:13:52 +02:00
/**
2016-10-25 11:37:01 +02:00
* ticketcase short summary .
2015-10-09 14:13:52 +02:00
*
2016-10-25 11:37:01 +02:00
* ticketcase description .
2015-10-09 14:13:52 +02:00
*
* @ version 1.0
* @ author MoronO
*/
class PluginProcessmakerCase extends CommonDBTM {
2017-05-06 18:38:24 +02:00
/**
* Summary of getTabNameForItem
* @ param CommonGLPI $item is the item
* @ param mixed $withtemplate has template
* @ return array os strings
*/
function getTabNameForItem ( CommonGLPI $item , $withtemplate = 0 ) {
global $LANG ;
$item_id = $item -> getID ();
$item_type = $item -> getType ();
if ( self :: getCaseFromItemTypeAndItemId ( $item_type , $item_id )) {
2017-12-29 16:32:39 +01:00
return array ( 'processmakercases' => $LANG [ 'processmaker' ][ 'item' ][ 'tab' ] . " <sup class='tab_nb'> " . $this -> fields [ 'case_status' ] . " </sup> " );
2017-05-06 18:38:24 +02:00
} else {
return array ( 'processmakercases' => $LANG [ 'processmaker' ][ 'item' ][ 'tab' ] );
}
2016-10-25 11:37:01 +02:00
2017-05-06 18:38:24 +02:00
}
2016-10-25 11:37:01 +02:00
/**
* Summary of getCaseIdFromItemTypeAndItemId
2017-05-06 18:38:24 +02:00
* @ param mixed $itemType is the item type
* @ param mixed $itemId is the item id
* @ return mixed case id
2016-10-25 11:37:01 +02:00
*/
2017-05-06 18:38:24 +02:00
static function getCaseIdFromItemTypeAndItemId ( $itemType , $itemId ) {
global $DB ;
$query = " SELECT * FROM glpi_plugin_processmaker_cases WHERE items_id= $itemId and itemtype=' $itemType '; " ;
if (( $res = $DB -> query ( $query ) ) && $DB -> numrows ( $res ) > 0 ) {
$row = $DB -> fetch_array ( $res );
return $row [ 'id' ];
}
return false ;
}
2016-10-25 11:37:01 +02:00
/**
* Summary of getCaseFromItemTypeAndItemId
2017-05-06 18:38:24 +02:00
* @ param mixed $itemType is the item type
* @ param mixed $itemId is the item id
2016-10-25 11:37:01 +02:00
* @ return mixed : returns false when there is no case associated with the item , else fills in the item fields from DB , and returns true
*/
2017-05-06 18:38:24 +02:00
function getCaseFromItemTypeAndItemId ( $itemType , $itemId ) {
2016-10-25 11:37:01 +02:00
2017-05-06 18:38:24 +02:00
if ( $caseId = self :: getCaseIdFromItemTypeAndItemId ( $itemType , $itemId )) {
return $this -> getFromDB ( $caseId );
}
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 getFromDB
2017-05-06 18:38:24 +02:00
* @ param mixed $ID id of needed object
* @ return mixed object if found , else false
2016-10-25 11:37:01 +02:00
*/
2017-05-06 18:38:24 +02:00
function getFromDB ( $ID ) {
global $DB ;
// Search for object in database and fills 'fields'
2016-10-25 11:37:01 +02:00
2017-05-06 18:38:24 +02:00
// != 0 because 0 is consider as empty
if ( strlen ( $ID ) == 0 ) {
return false ;
}
2016-10-25 11:37:01 +02:00
2017-05-06 18:38:24 +02:00
$query = " SELECT *
2016-10-25 11:37:01 +02:00
FROM `".$this->getTable()."`
WHERE `".$this->getIndexName()."` = '".$ID."' " ;
2017-05-06 18:38:24 +02:00
if (( $result = $DB -> query ( $query )) && $DB -> numrows ( $result ) == 1 ) {
$this -> fields = $DB -> fetch_assoc ( $result );
$this -> post_getFromDB ();
2016-10-25 11:37:01 +02:00
2017-05-06 18:38:24 +02:00
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 getVariables
* Gets variables from a case .
* @ param array $vars an array of variable name that will be read from the case as case variables
2017-05-06 18:38:24 +02:00
* @ return array an associative array ( variable_name => value ) . The returned array can be empty if requested variables are not found .
2016-10-25 11:37:01 +02:00
*/
2017-05-06 18:38:24 +02:00
function getVariables ( $vars = array () ) {
global $PM_DB ;
2016-10-25 11:37:01 +02:00
2017-05-06 18:38:24 +02:00
$locVars = array ( );
$app_data = array (); // by default
2016-10-25 11:37:01 +02:00
2017-05-06 18:38:24 +02:00
$caseId = $this -> getID ();
2016-10-25 11:37:01 +02:00
2017-05-06 18:38:24 +02:00
$query = " SELECT APP_DATA FROM APPLICATION WHERE APP_UID=' $caseId '; " ;
2016-10-25 11:37:01 +02:00
2017-05-06 18:38:24 +02:00
if (( $res = $PM_DB -> query ( $query )) && $PM_DB -> numrows ( $res ) > 0 ) {
$row = $PM_DB -> fetch_assoc ( $res );
$app_data = unserialize ( $row [ 'APP_DATA' ] );
$locVars = array_intersect_key ( $app_data , array_flip ( $vars ) );
}
2016-10-25 11:37:01 +02:00
2017-05-06 18:38:24 +02:00
return $locVars ;
}
2016-10-25 11:37:01 +02:00
/**
* Summary of sendVariables
* Sends variables to a case .
* BEWARE that this will not work correctly for values containning special chars like \
* instead use the web service function from PluginProcessmakerProcessmaker class
* @ param array $vars an array of associative variables ( name => value ) that will be injected into the case as case variables
* @ return true if variables have been saved to the case , false otherwise
*/
2017-05-06 18:38:24 +02:00
function sendVariables ( $vars = array () ) {
global $PM_DB ;
2016-10-25 11:37:01 +02:00
2017-05-06 18:38:24 +02:00
$variablesSent = false ; // be default
$app_data = array (); // by default
2016-10-25 11:37:01 +02:00
2017-05-06 18:38:24 +02:00
$caseId = $this -> getID ();
2016-10-25 11:37:01 +02:00
2017-05-06 18:38:24 +02:00
$query = " SELECT APP_DATA FROM APPLICATION WHERE APP_UID=' $caseId '; " ;
2016-10-25 11:37:01 +02:00
2017-05-06 18:38:24 +02:00
if (( $res = $PM_DB -> query ( $query )) && $PM_DB -> numrows ( $res ) > 0 ) {
$row = $PM_DB -> fetch_assoc ( $res );
$app_data = unserialize ( $row [ 'APP_DATA' ] );
}
2016-10-25 11:37:01 +02:00
2017-05-06 18:38:24 +02:00
$app_data = array_replace ( $app_data , $vars );
$serialized = serialize ( $app_data );
2016-10-25 11:37:01 +02:00
2017-05-06 18:38:24 +02:00
$query = " UPDATE APPLICATION SET APP_DATA=' $serialized ' WHERE APP_UID=' $caseId '; " ;
$res = $PM_DB -> query ( $query );
2016-10-25 11:37:01 +02:00
2017-05-06 18:38:24 +02:00
if ( $PM_DB -> affected_rows () == 1 ) {
$variablesSent = true ;
}
2016-10-25 11:37:01 +02:00
2017-05-06 18:38:24 +02:00
return $variablesSent ;
}
2016-10-25 11:37:01 +02:00
/**
* Summary of displayTabContentForItem
2017-05-06 18:38:24 +02:00
* @ param CommonGLPI $item is the item
* @ param mixed $tabnum is the tab num
* @ param mixed $withtemplate has template
2016-10-25 11:37:01 +02:00
* @ return mixed
*/
2017-05-06 18:38:24 +02:00
static function displayTabContentForItem ( CommonGLPI $item , $tabnum = 1 , $withtemplate = 0 ) {
global $LANG , $DB , $CFG_GLPI ;
$config = PluginProcessmakerConfig :: getInstance ();
if ( $config -> fields [ 'maintenance' ] == 0 ) {
$item_id = $item -> getID ();
$item_type = $item -> getType ();
////retrieve container for current tab
//$container = new self;
//$found_c = $container->find("`itemtype` = '$item_type' AND `items_id` = $item_id ");
//echo "Show the frame";
$rand = rand ();
echo " <form style='margin-bottom: 0px' name='processmaker_form $rand ' id='processmaker_form $rand ' method='post' action=' " . Toolbox :: getItemTypeFormURL ( " PluginProcessmakerProcessmaker " ) . " '> " ;
echo " <div class='center'> <table id='processmakercasemenu' style='margin-bottom: 0px' class='tab_cadre_fixe'> " ;
echo Html :: scriptBlock ( " $ ('#processmakercasemenu').css('max-width', 'none'); " );
echo " <tr><th colspan='4'> " . $LANG [ 'processmaker' ][ 'item' ][ 'tab' ] . " </th></tr> " ;
$pmCaseUser = false ; // initial value: no user
// first search for the case
if ( self :: getCaseIdFromItemTypeAndItemId ( $item_type , $item_id )) {
$myProcessMaker = new PluginProcessmakerProcessmaker ( );
$myProcessMaker -> login ();
$caseInfo = $myProcessMaker -> getCaseFromItem ( $item_type , $item_id );
if ( $caseInfo -> caseStatus != 'CANCELLED' && $caseInfo -> caseStatus != 'COMPLETED' ) {
// need to get info on the thread of the GLPI current user
// we must retreive currentGLPI user from this array
$GLPICurrentPMUserId = PluginProcessmakerUser :: getPMUserId ( Session :: getLoginUserID () );
$pmCaseUser = $caseInfo -> currentUsers [ 0 ]; // by default currently manage only one task at a time, must define tab management for several tasks
foreach ( $caseInfo -> currentUsers as $caseUser ) {
if ( $caseUser -> userId == $GLPICurrentPMUserId ) {
$pmCaseUser = $caseUser ;
break ;
}
}
}
$locDelIndex = 1 ; // by default
switch ( $caseInfo -> caseStatus ) {
case " CANCELLED " :
echo " <tr><th colspan='4'> " . $LANG [ 'processmaker' ][ 'item' ][ 'cancelledcase' ] . " </th></tr> " ;
$paramsURL = " DEL_INDEX=1 " ;
// echo "<tr class='tab_bg_1' ><td id='GLPI-PM-DEL_INDEX' ><script>var GLPI_DEL_INDEX = 1; </script></td></tr>" ;
break ;
case " DRAFT " :
case " TO_DO " :
$paramsURL = " DEL_INDEX= " . $pmCaseUser -> delIndex . " &action= " . $caseInfo -> caseStatus ;
$locDelIndex = $pmCaseUser -> delIndex ;
if ( $pmCaseUser -> userId != '' ) {
echo " <tr class='tab_bg_1'> " ;
if ( $GLPICurrentPMUserId == $pmCaseUser -> userId ) {
// then propose a button to cancel case only when assigned user is == to glpi current user
echo " <td class='tab_bg_2' > " ;
echo $LANG [ 'processmaker' ][ 'item' ][ 'cancelcase' ];
echo " </td><td class='tab_bg_2'> " ;
echo " <input type='hidden' name='action' value='unpausecase_or_reassign_or_delete'> " ;
echo " <input type='hidden' name='plugin_processmaker_caseId' value=' " . $caseInfo -> caseId . " '> " ;
//echo "<input type='hidden' name='plugin_processmaker_delIndex' value='".$pmCaseUser->delIndex."'>";
//echo "<input type='hidden' name='plugin_processmaker_userId' value='".$pmCaseUser->userId."'>";
echo " <input onclick='ret = confirm( \" " . $LANG [ 'processmaker' ][ 'item' ][ 'buttoncancelcaseconfirmation' ] . " \" ) ; cancelMyMask = !ret ; return ret;' type='submit' name='cancel' value=' " . $LANG [ 'processmaker' ][ 'item' ][ 'buttoncancelcase' ] . " ' class='submit'> " ;
echo " </td> " ;
}
if ( $caseInfo -> caseStatus == " DRAFT " || ( plugin_processmaker_haveRight ( " deletecase " , DELETE ) && $_SESSION [ 'glpiactiveprofile' ][ 'interface' ] == 'central' )) {
// then propose a button to delete case
echo " <td class='tab_bg_2'> " ;
echo $LANG [ 'processmaker' ][ 'item' ][ 'deletecase' ];
echo " </td><td class='tab_bg_2'> " ;
echo " <input type='hidden' name='action' value='unpausecase_or_reassign_or_delete'> " ;
echo " <input type='hidden' name='plugin_processmaker_caseId' value=' " . $caseInfo -> caseId . " '> " ;
echo " <input onclick='ret = confirm( \" " . $LANG [ 'processmaker' ][ 'item' ][ 'buttondeletecaseconfirmation' ] . " \" ); cancelMyMask = !ret ; return ret;' type='submit' name='delete' value=' " . $LANG [ 'processmaker' ][ 'item' ][ 'buttondeletecase' ] . " ' class='submit' > " ;
echo " </td> " ;
}
echo " </form> " ;
echo " </td></tr> " ;
}
break ;
case " COMPLETED " :
echo " <tr><th colspan='4'> " . $LANG [ 'processmaker' ][ 'item' ][ 'completedcase' ] . " </th></tr> " ;
$paramsURL = " DEL_INDEX= " ; // DEL_INDEX is not set to tell PM to show the current task i.e.: the last one
break ;
}
2016-10-25 11:37:01 +02:00
2017-05-06 18:38:24 +02:00
$proj = new PluginProcessmakerProcess ;
$proj -> getFromDBbyExternalID ( $caseInfo -> processId );
$project_type = $proj -> fields [ 'project_type' ];
// then propose a button to view case history
2017-12-29 16:32:39 +01:00
//echo "<tr class='tab_bg_1' >";
//echo "<td class='tab_bg_2' colspan='1'>";
//echo "<input type='button' class='submit' onclick=\"javascript:Actions.tabFrame('caseMap');\" value='".$LANG['processmaker']['item']['case']['viewcasemap']."'>";
//echo "</td>";
//echo "<td class='tab_bg_2' colspan='1'>";
//echo "<input type='button' class='submit' onclick=\"javascript:Actions.tabFrame('caseHistory');\" value='".$LANG['processmaker']['item']['case']['viewcasehistory']."'>";
//echo "</td>";
//echo "<td class='tab_bg_2' colspan='1'>";
//echo "<input type='button' class='submit' onclick=\"javascript:Actions.tabFrame('caseChangeLogHistory');\" value='".$LANG['processmaker']['item']['case']['viewcasechangeloghistory']."'>";
//echo "</td>";
//echo "<td class='tab_bg_2' colspan='1'>";
//echo "<input type='button' class='submit' onclick=\"javascript:Actions.tabFrame('historyDynaformPage');\" value='".$LANG['processmaker']['item']['case']['viewdynaforms']."'>";
//echo "</td>";
//echo "</tr>";
2016-10-25 11:37:01 +02:00
echo " </table> " ;
2017-05-06 18:38:24 +02:00
echo " <script type='text/javascript' src=' " . $CFG_GLPI [ " root_doc " ] . " /plugins/processmaker/js/cases.js'></script> " ; //?rand=$rand'
2016-10-25 11:37:01 +02:00
// processmakertabpaneltable is used to align the tabs
echo " <table id=processmakertabpaneltable style='margin-bottom: 0px; width:100%;' class='tab_cadre_fixe'> " ;
2017-05-06 18:38:24 +02:00
echo Html :: scriptBlock ( " $ ('#processmakertabpaneltable').css('max-width', 'none'); " );
echo " <tr><td> " ;
2016-10-25 11:37:01 +02:00
2017-12-29 16:32:39 +01:00
//////////////////////////
2016-10-25 11:37:01 +02:00
// Processmaker tab panels
// need to have a global variable which contains tab id
// used only one time for activated panel
2017-12-29 16:32:39 +01:00
//////////////////////////
2017-05-06 18:38:24 +02:00
$arrayProcessmakerTabPanel = array ();
2016-10-25 11:37:01 +02:00
echo " <div id=processmakertabpanel > " ;
2017-12-29 16:32:39 +01:00
//////////////
// Define tabs
//////////////
2016-10-25 11:37:01 +02:00
echo " <ul> " ;
//echo " <li><a href='#tabs-1'>Nunc tincidunt</a></li>";
2017-12-29 16:32:39 +01:00
//$arrayProcessmakerTabPanel[] = "tabs-1";
$arrayProcessmakerTabPanel = [];
2017-05-06 18:38:24 +02:00
if ( $pmCaseUser ) {
foreach ( $caseInfo -> currentUsers as $caseUser ) {
2017-12-29 16:32:39 +01:00
$title = $LANG [ 'processmaker' ][ 'item' ][ 'task' ][ 'task' ] . $caseUser -> taskName ;
echo " <li><a href='#task- " . $caseUser -> delIndex . " ' title=' $title '> " . ( $caseUser -> userId != $GLPICurrentPMUserId ? " <i><sub> $title </sub></i> " : $title ) . " </a></li> " ;
2017-05-06 18:38:24 +02:00
$arrayProcessmakerTabPanel [] = " task- " . $caseUser -> delIndex ;
}
} else {
// no user means CANCELLED or COMPLETED
// then create artificial panel to host case infos
2017-12-29 16:32:39 +01:00
echo " <li><a href='#caseInfo' title=' " . $LANG [ 'processmaker' ][ 'item' ][ 'case' ][ 'caseinfo' ] . " '> " . $LANG [ 'processmaker' ][ 'item' ][ 'case' ][ 'caseinfo' ] . " </a></li> " ;
2017-05-06 18:38:24 +02:00
$arrayProcessmakerTabPanel [] = " caseInfo " ;
}
2017-12-29 16:32:39 +01:00
// add default panels: map, history, log and dynaforms
$defaultTabs = [ 'caseMap' => 'viewcasemap' , 'caseHistory' => 'viewcasehistory' , 'caseChangeLogHistory' => 'viewcasechangeloghistory' , 'historyDynaformPage' => 'viewdynaforms' ];
foreach ( $defaultTabs as $tab => $tabText ) {
echo " <li><a href='# $tab ' onclick= \" javascript:Actions.tabFrame(' $tab ');return false; \" title=' " . $LANG [ 'processmaker' ][ 'item' ][ 'case' ][ $tabText ] . " '> " . $LANG [ 'processmaker' ][ 'item' ][ 'case' ][ $tabText ] . " </a></li> " ;
}
2016-10-25 11:37:01 +02:00
echo " </ul> " ;
2017-12-29 16:32:39 +01:00
////////////////
// Define panels
////////////////
2017-05-06 18:38:24 +02:00
if ( $pmCaseUser ) {
$csrf = Session :: getNewCSRFToken ();
foreach ( $caseInfo -> currentUsers as $caseUser ) {
// for each task, if task is to be claimed, we need to verify that current user can claim it by checking if he/she is in the group assigned to the task
$hide_claim_button = false ; // by default
if ( ! $caseUser -> userId ) {
// current task is to claimed
// get task user list
$query = " SELECT items_id, itemtype FROM glpi_plugin_processmaker_tasks WHERE case_id = ' " . $caseInfo -> caseId . " ' AND del_index = " . $caseUser -> delIndex ;
foreach ( $DB -> request ( $query ) as $row ) {
// normally there is only one task
$task = getItemForItemtype ( $row [ 'itemtype' ] );
$task -> getFromDB ( $row [ 'items_id' ] );
// check if this group can be found in the current user's groups
if ( ! isset ( $_SESSION [ 'glpigroups' ]) || ! in_array ( $task -> fields [ 'groups_id_tech' ], $_SESSION [ 'glpigroups' ] )) {
$hide_claim_button = true ;
}
}
}
echo " <div id='task- " . $caseUser -> delIndex . " '> " ;
// to load users for task re-assign only when task is not to be 'claimed'
if ( $caseUser -> userId ) {
echo " <div class='tab_bg_2' id='divUsers- " . $caseUser -> delIndex . " ' >Loading...</div> " ;
echo " <script> $ ('#divUsers- " . $caseUser -> delIndex . " ').load( ' " . $CFG_GLPI [ " root_doc " ] . " /plugins/processmaker/ajax/task_users.php?caseId= " . $caseInfo -> caseId . " &itemId= " . $item_id . " &itemType= " . $item_type . " &userId= " . $caseUser -> userId . " &taskId= " . $caseUser -> taskId . " &delIndex= " . $caseUser -> delIndex . " &delThread= " . $caseUser -> delThread . " &rand= $rand ' ); </script> " ;
}
echo " <iframe id='caseiframe-task- " . $caseUser -> delIndex . " ' onload='onTaskFrameLoad( event, " . $caseUser -> delIndex . " , " . ( $hide_claim_button ? " true " : " false " ) . " , \" $csrf\ " ); ' style=' border : none ; ' class=' tab_bg_2 ' width=' 100 % ' src=' " ;
2018-01-26 14:26:30 +01:00
echo $myProcessMaker -> serverURL . " /cases/cases_Open?sid= " . $_SESSION [ " pluginprocessmaker " ][ " session " ][ " id " ] . " &APP_UID= " . $caseInfo -> caseId . " &DEL_INDEX= " . $caseUser -> delIndex . " &action=TO_DO " ;
echo " &rand= $rand &glpi_domain= { $config -> fields [ 'domain' ] } '></iframe></div> " ;
2017-05-06 18:38:24 +02:00
}
} else {
2016-10-25 11:37:01 +02:00
// no user means CANCELLED or COMPLETED
// then create artificial panel to host case infos
echo " <div id='caseInfo'> " ;
2017-05-10 12:31:44 +02:00
$url = $myProcessMaker -> serverURL . " /cases/cases_Open?sid= " . $_SESSION [ " pluginprocessmaker " ][ " session " ][ " id " ] . " &APP_UID= " . $caseInfo -> caseId . " & " . $paramsURL . " &action=TO_DO " ;
2018-01-26 14:26:30 +01:00
echo " <iframe id= \" caseiframe-caseInfo \" onload= \" onOtherFrameLoad( 'caseInfo', 'caseiframe-caseInfo', 'body' ); \" style= \" border:none; \" class= \" tab_bg_2 \" width= \" 100% \" src= \" $url &rand= $rand &glpi_domain= { $config -> fields [ 'domain' ] } \" ></iframe></div> " ;
2016-10-25 11:37:01 +02:00
}
2017-12-29 16:32:39 +01:00
// default panels
// map, history, log and dynaforms
// will be added dynamically by the addTabPanel function
2017-05-06 18:38:24 +02:00
echo " </div> " ;
2016-10-25 11:37:01 +02:00
// end of tabs/panels
echo " </td></tr> " ;
2017-05-06 18:38:24 +02:00
echo " <tr class='tab_bg_1' ><td colspan=4 > " ;
if ( $pmCaseUser ) {
$activePanel = 'task-' . $pmCaseUser -> delIndex ;
2016-10-25 11:37:01 +02:00
} else {
2017-05-06 18:38:24 +02:00
$activePanel = 'caseInfo' ;
2016-10-25 11:37:01 +02:00
}
2018-01-26 14:26:30 +01:00
$caseMapUrl = $myProcessMaker -> serverURL . ( $project_type == 'bpmn' ? " /designer?prj_uid= " . $caseInfo -> processId . " &prj_readonly=true&app_uid= " . $caseInfo -> caseId : " /cases/ajaxListener?action=processMap&rand= $rand " ) . " &glpi_domain= { $config -> fields [ 'domain' ] } " ;
2017-05-06 18:38:24 +02:00
echo " <script>
2016-10-25 11:37:01 +02:00
function addTabPanel ( name , title , html ){
//debugger ;
if ( ! $ ( '#processmakertabpanel' )[ 0 ] . children [ name ] ) { // panel is not yet existing, create one
//var num_tabs = $('#processmakertabpanel ul li').length ;
2017-12-29 16:32:39 +01:00
if ( $ ( '#processmakertabpanel a[href=\"#' + name + '\"]' ) . length == 0 ) {
$ ( '#processmakertabpanel ul' ) . append ( '<li><a href=\'#' + name + '\'>' + title + '</a></li>' );
}
2016-10-25 11:37:01 +02:00
//debugger ;
$ ( '#processmakertabpanel' ) . append ( '<div id=\'' + name + '\'>' + html + '</div>' );
$ ( '#processmakertabpanel' ) . tabs ( 'refresh' ); // to show the panel
}
var tabIndex = $ ( '#processmakertabpanel a[href=\"#' + name + '\"]' ) . parent () . index ();
$ ( '#processmakertabpanel' ) . tabs ( 'option' , 'active' , tabIndex ) ; // to activate it
//$('#processmakertabpanel').tabs( 'option', 'collapsible', true );
}
var historyGridListChangeLogGlobal = { viewIdHistory : '' , viewIdDin : '' , viewDynaformName : '' , idHistory : '' } ;
var ActionTabFrameGlobal = { tabData : '' , tabName : '' , tabTitle : '' } ;
var Actions = { tabFrame : function ( actionToDo ) {
// debugger ;
if ( actionToDo == 'caseMap' ) {
addTabPanel ( actionToDo ,
'".$LANG[' processmaker '][' item '][' case '][' casemap ']."' ,
2016-10-28 15:29:14 +02:00
'<iframe id=\'caseiframe-' + actionToDo + '\' style=\'border: none;\' onload=\'onOtherFrameLoad( \"' + actionToDo + '\", \"caseiframe-' + actionToDo + '\", \"body\", ".($project_type==' bpmn ' ? "true" : "false" )." );\' width=\'100%\' src=\'$caseMapUrl\' ></iframe>'
2016-10-25 11:37:01 +02:00
);
} else
if ( actionToDo == 'caseHistory' ) {
addTabPanel ( actionToDo ,
'".$LANG[' processmaker '][' item '][' case '][' casehistory ']."' ,
2018-01-26 14:26:30 +01:00
'<iframe id=\'caseiframe-' + actionToDo + '\' style=\'border: none;\' onload=\'onOtherFrameLoad( \"' + actionToDo + '\", \"caseiframe-' + actionToDo + '\", \"body\", 0 );\' height=\'600px\' width=\'100%\' src=\'".$myProcessMaker->serverURL."/cases/ajaxListener?action=caseHistory&rand=$rand&glpi_domain={$config->fields[' domain ']}\' ></iframe>'
2016-10-25 11:37:01 +02:00
);
} else
if ( actionToDo == 'caseChangeLogHistory' ) {
addTabPanel ( actionToDo ,
'".$LANG[' processmaker '][' item '][' case '][' casechangeloghistory ']."' ,
2018-01-26 14:26:30 +01:00
'<iframe id=\'caseiframe-' + actionToDo + '\' style=\'border: none;\' onload=\'onOtherFrameLoad( \"' + actionToDo + '\", \"caseiframe-' + actionToDo + '\", \"body\", 0 );\' height=\'600px\' width=\'100%\' src=\'".$myProcessMaker->serverURL."/cases/ajaxListener?action=changeLogHistory&rand=$rand&glpi_domain={$config->fields[' domain ']}\' ></iframe>'
2016-10-25 11:37:01 +02:00
);
} else
if ( actionToDo == 'dynaformViewFromHistory' ) {
actionToDo = 'dynaformChangeLogViewHistory_' + historyGridListChangeLogGlobal . viewIdDin + historyGridListChangeLogGlobal . dynDate . replace ( / / g , '_' ) . replace ( /:/ g , '-' ) ;
ajaxResponse = $ . parseJSON ( historyGridListChangeLogGlobal . viewDynaformName );
addTabPanel ( actionToDo ,
ajaxResponse . dynTitle + ' <sup>(' + historyGridListChangeLogGlobal . dynDate + ')</sup>' ,
2018-01-26 14:26:30 +01:00
'<iframe id=\'caseiframe-' + actionToDo + '\' style=\'border: none;\' onload=\'onOtherFrameLoad( \"' + actionToDo + '\", \"caseiframe-' + actionToDo + '\", \"body\", 0 );\' width=\'100%\' src=\'".$myProcessMaker->serverURL."/cases/ajaxListener?action=dynaformViewFromHistory&DYN_UID=' + historyGridListChangeLogGlobal . viewIdDin + \ " &HISTORY_ID= \" + historyGridListChangeLogGlobal.viewIdHistory + '&rand= $rand &glpi_domain= { $config -> fields [ 'domain' ] } \ ' ></iframe>'
2016-10-25 11:37:01 +02:00
);
} else
if ( actionToDo == 'historyDynaformPage' ) {
addTabPanel ( actionToDo ,
'".$LANG[' processmaker '][' item '][' case '][' dynaforms ']."' ,
2018-01-26 14:26:30 +01:00
'<iframe id=\'caseiframe-' + actionToDo + '\' style=\'border: none;\' onload=\'onOtherFrameLoad( \"' + actionToDo + '\", \"caseiframe-' + actionToDo + '\", \"body\", 0 );\' width=\'100%\' src=\'".$myProcessMaker->serverURL."/cases/casesHistoryDynaformPage_Ajax?actionAjax=historyDynaformPage&rand=$rand&glpi_domain={$config->fields[' domain ']}\' ></iframe>'
2016-10-25 11:37:01 +02:00
);
} else
if ( actionToDo . search ( '^changeLog' ) == 0 ) {
actionToDo = 'changeLog' ;
addTabPanel ( actionToDo ,
'".$LANG[' processmaker '][' item '][' case '][' changelog ']."' ,
2018-01-26 14:26:30 +01:00
'<iframe id=\'caseiframe-' + actionToDo + '\' style=\'border: none;\' onload=\'onOtherFrameLoad( \"' + actionToDo + '\", \"caseiframe-' + actionToDo + '\", \"body\", 0 );\' height=\'600px\' width=\'100%\' src=\'".$myProcessMaker->serverURL."/cases/ajaxListener?action=changeLogTab&idHistory=' + historyGridListChangeLogGlobal . idHistory + '&rand=$rand&glpi_domain={$config->fields[' domain ']}\' ></iframe>'
2016-10-25 11:37:01 +02:00
);
} else
if ( actionToDo . search ( '^historyDynaformGridPreview' ) == 0 ) {
actionToDo = actionToDo . replace ( '_' , '$' ) ;
var act = actionToDo . replace ( '$' , '&DYN_UID=' ) ;
addTabPanel ( actionToDo ,
ActionTabFrameGlobal . tabTitle ,
2018-01-26 14:26:30 +01:00
'<iframe id=\'caseiframe-' + actionToDo + '\' style=\'border: none;\' onload=\'onOtherFrameLoad( \"' + actionToDo + '\", \"caseiframe-' + actionToDo + '\", \"form\", 0 );\' width=\'100%\' src=\'".$myProcessMaker->serverURL."/cases/casesHistoryDynaformPage_Ajax?actionAjax=' + act + '&rand=$rand&glpi_domain={$config->fields[' domain ']}\' ></iframe>'
2016-10-25 11:37:01 +02:00
);
} else
if ( actionToDo . search ( '^historyDynaformGridHistory' ) == 0 ) {
var ajaxResponse = $ . parseJSON ( ActionTabFrameGlobal . tabData );
var act = 'showDynaformListHistory&PRO_UID=' + ajaxResponse . PRO_UID + '&APP_UID=' + ajaxResponse . APP_UID + '&TAS_UID=-1&DYN_UID=' + ajaxResponse . DYN_UID ;
addTabPanel ( actionToDo ,
ActionTabFrameGlobal . tabTitle ,
2018-01-26 14:26:30 +01:00
'<iframe id=\'caseiframe-' + actionToDo + '\' style=\'border: none;\' onload=\'onOtherFrameLoad( \"' + actionToDo + '\", \"caseiframe-' + actionToDo + '\", \"body\", 0 );\' height=\'600px\' width=\'100%\' src=\'".$myProcessMaker->serverURL."/cases/casesHistoryDynaformPage_Ajax?actionAjax=' + act + '&rand=$rand&glpi_domain={$config->fields[' domain ']}\' ></iframe>'
2016-10-25 11:37:01 +02:00
);
} else
if ( actionToDo . search ( '^dynaformChangeLogViewHistory' ) == 0 ) {
var ajaxResponse = $ . parseJSON ( ActionTabFrameGlobal . tabData );
actionToDo = 'dynaformChangeLogViewHistory' + ajaxResponse . dynUID + ajaxResponse . dynDate ;
//actionToDo = actionToDo.replace(' ', '_').replace(':', '-');
var act = 'dynaformChangeLogViewHistory&DYN_UID=' + ajaxResponse . dynUID + '&HISTORY_ID=' + ajaxResponse . tablename ;
addTabPanel ( actionToDo ,
ActionTabFrameGlobal . tabTitle ,
2018-01-26 14:26:30 +01:00
'<iframe id=\'caseiframe-' + actionToDo + '\' style=\'border: none;\' onload=\'onOtherFrameLoad( \"' + actionToDo + '\", \"caseiframe-' + actionToDo + '\", \"form\", 0 );\' width=\'100%\' src=\'".$myProcessMaker->serverURL."/cases/casesHistoryDynaformPage_Ajax?actionAjax=' + act + '&rand=$rand&glpi_domain={$config->fields[' domain ']}\' ></iframe>'
2016-10-25 11:37:01 +02:00
);
}
}
} ;
$ ( function () {
//debugger;
$ ( '#processmakertabpanel' ) . tabs ( { active : " .array_search( $activePanel , $arrayProcessmakerTabPanel ). " });
//$('#processmakertabpanel').scrollabletabs();
//$('#processmakertabpanel').position({
// my: 'left top',
// at: 'left top',
// of: '#processmakertabpaneltable'
//});
$ ( '#processmakertabpanel' ) . removeClass ( 'ui-tabs' ) ;
//debugger ;
$ ( '#processmakertabpanel' ) . tabs ({ activate : function ( event , ui ) {
try {
//debugger;
if ( typeof onOtherFrameLoad == 'function' )
var newPanel = ui . newPanel . selector . replace ( '#' , '' ) ;
var panelType = newPanel . split ( '-' )[ 0 ] . split ( '$' )[ 0 ] . split ( '_' ) ;
var searchTag = '' ;
switch ( panelType [ 0 ] ) {
case 'task' :
searchTag = 'table' ;
break ;
case 'historyDynaformGridPreview' :
case 'dynaformChangeLogViewHistory' :
searchTag = 'form' ;
break ;
case 'caseInfo' :
case 'caseMap' :
case 'caseHistory' :
case 'changeLog' :
case 'historyDynaformPage' :
case 'dynaformChangeLogViewHistory' :
case 'historyDynaformGridHistory' :
default :
searchTag = 'body' ;
break ;
}
2016-10-28 15:29:14 +02:00
onOtherFrameLoad ( newPanel , 'caseiframe-' + newPanel , searchTag , " .( $project_type =='bpmn' ? " true " : " false " ). " ) ;
2016-10-25 11:37:01 +02:00
} catch ( evt ) {
//debugger;
}
}
});
2017-05-06 18:38:24 +02:00
" ;
2016-10-25 11:37:01 +02:00
echo " });
" ;
2017-05-06 18:38:24 +02:00
echo " </script> " ;
2016-10-25 11:37:01 +02:00
2017-05-06 18:38:24 +02:00
echo " </td></tr> " ;
2016-10-25 11:37:01 +02:00
2017-05-06 18:38:24 +02:00
} else {
//********************************
// no running case for this ticket
// propose to start one
//********************************
echo " <tr><th colspan='4'> " . $LANG [ 'processmaker' ][ 'item' ][ 'nocase' ];
// check if item is not solved nor closed
if ( $item -> fields [ 'status' ] != 'solved' && $item -> fields [ 'status' ] != 'closed' && $_SESSION [ 'glpiactiveprofile' ][ 'interface' ] != 'helpdesk' ) {
// propose case start
echo " - " . $LANG [ 'processmaker' ][ 'item' ][ 'startone' ];
echo " </th></tr> " ;
echo " <tr class='tab_bg_2'><td class='tab_bg_2' colspan='1'> " ;
echo $LANG [ 'processmaker' ][ 'item' ][ 'selectprocess' ] . " " ;
echo " <input type='hidden' name='action' value='newcase'> " ;
echo " <input type='hidden' name='id' value=' $item_id '> " ;
echo " <input type='hidden' name='itemtype' value=' $item_type '> " ;
// Dropdown::show('PluginProcessmakerProcessmaker', array( 'entity' => $item->fields['entities_id'], 'name' => 'plugin_processmaker_process_id', 'condition' => "is_active=1")); // condition is used to prevent start of none-active cases
PluginProcessmakerProcess :: dropdown ( array ( 'value' => 0 , 'entity' => $item -> fields [ 'entities_id' ], 'name' => 'plugin_processmaker_process_id' , 'condition' => " is_active=1 " ));
echo " </td><td class='tab_bg_2'> " ;
echo " <input type='submit' name='additem' value=' " . $LANG [ 'processmaker' ][ 'item' ][ 'start' ] . " ' class='submit'> " ;
echo " </td></tr> " ;
} else {
echo " </th></tr> " ;
}
}
2016-10-25 11:37:01 +02:00
2017-05-06 18:38:24 +02:00
echo " </table> " ;
Html :: closeForm ( true );
//echo "</form>";
2016-10-25 11:37:01 +02:00
2017-05-06 18:38:24 +02:00
} else {
// under maintenance
echo $LANG [ 'processmaker' ][ 'config' ][ 'undermaintenance' ];
}
2016-10-25 11:37:01 +02:00
2017-05-06 18:38:24 +02:00
return true ;
}
2016-10-25 11:37:01 +02:00
/**
* Summary of deleteTasks
* will delete all tasks associated with this case from the item
* @ return true if tasks have been deleted from associated item and from case table
*/
private function deleteTasks ( ) {
2017-05-06 18:38:24 +02:00
global $DB ;
$ret = false ;
2016-10-25 11:37:01 +02:00
2017-12-29 16:32:39 +01:00
$query = " DELETE from glpi_ " . strtolower ( $this -> fields [ 'itemtype' ]) . " tasks where id in (select items_id from glpi_plugin_processmaker_tasks where case_id=' " . $this -> fields [ 'id' ] . " ') " ;
2017-05-06 18:38:24 +02:00
if ( $DB -> query ( $query )) {
$query = " DELETE from glpi_plugin_processmaker_tasks where case_id=' " . $this -> fields [ 'id' ] . " ' " ;
if ( $DB -> query ( $query )) {
$ret = true ;
2016-10-25 11:37:01 +02:00
}
2017-05-06 18:38:24 +02:00
}
return $ret ;
2016-10-25 11:37:01 +02:00
}
/**
* Summary of deleteCase
* will delete case and all tasks associated with this case from the item
* @ return true if case and tasks have been deleted from associated item and from case table
*/
2017-05-06 18:38:24 +02:00
function deleteCase ( ) {
global $DB ;
$ret = false ;
2016-10-25 11:37:01 +02:00
2017-05-06 18:38:24 +02:00
if ( $this -> deleteTasks ()) {
if ( $this -> deleteFromDB ( )) {
$ret = true ;
}
}
return $ret ;
}
2016-10-25 11:37:01 +02:00
/**
* Summary of cancelTasks
* will mark as information all to_do tasks
* BEWARE that this will only be done when case is in TO_DO status
* @ return true if tasks have been deleted from associated item and from case table
*/
2017-05-06 18:38:24 +02:00
private function cancelTasks ( ) {
global $DB ;
$ret = false ;
if ( isset ( $this -> fields [ 'case_status' ]) && $this -> fields [ 'case_status' ] == " TO_DO " ) {
$query = " UPDATE glpi_ " . $this -> fields [ 'itemtype' ] . " tasks SET state=0,users_id_tech=0,begin=NULL,end=NULL WHERE state=1 AND id in (select items_id from glpi_plugin_processmaker_tasks where case_id=' " . $this -> fields [ 'id' ] . " ') " ;
if ( $DB -> query ( $query )) {
$ret = true ;
}
}
return $ret ;
}
2016-10-25 11:37:01 +02:00
/**
* Summary of cancelCase
* will cancel case and mark 'to_do' tasks associated with this case from the item as information
* BEWARE that this will only be done when case is in TO_DO status
* @ return true if case and tasks have been cancelled or marked from associated item and from case table
*/
2017-05-06 18:38:24 +02:00
function cancelCase ( ) {
global $DB ;
$ret = false ;
if ( isset ( $this -> fields [ 'case_status' ]) && $this -> fields [ 'case_status' ] == " TO_DO " ) {
if ( $this -> cancelTasks ()) {
if ( $this -> update ( array ( 'id' => $this -> getID (), 'case_status' => 'CANCELLED' ) )) {
$ret = true ;
}
}
}
2016-10-25 11:37:01 +02:00
2017-05-06 18:38:24 +02:00
return $ret ;
}
2016-10-25 11:37:01 +02:00
/**
* Summary of canSolve
* To know if a Ticket ( Problem or Change ) can be solved
* i . e . the case permits solving of item
2017-05-06 18:38:24 +02:00
* @ param mixed $item is the item
* @ return bool true to permit solve , false otherwise
2016-10-25 11:37:01 +02:00
*/
2017-05-06 18:38:24 +02:00
public static function canSolve ( $item ) {
$myCase = new self ;
if ( $myCase -> getCaseFromItemTypeAndItemId ( $item [ 'item' ] -> getType (), $item [ 'item' ] -> getID () )) {
$pmVar = $myCase -> getVariables ( array ( 'GLPI_ITEM_CAN_BE_SOLVED' ) );
if ( $myCase -> fields [ 'case_status' ] != 'COMPLETED' && $myCase -> fields [ 'case_status' ] != 'CANCELLED' && ( ! isset ( $pmVar [ 'GLPI_ITEM_CAN_BE_SOLVED' ]) || $pmVar [ 'GLPI_ITEM_CAN_BE_SOLVED' ] != 1 )) {
// then item can't be solved
return false ;
}
}
return true ;
}
2016-10-25 11:37:01 +02:00
/**
* Summary of getToDoTasks
* @ param mixed $parm is a Ticket , a Problem or a Change
* @ return array list of tasks with status 'to do' for case associated with item
*/
2017-05-06 18:38:24 +02:00
public static function getToDoTasks ( $parm ) {
$myCase = new self ;
if ( $myCase -> getCaseFromItemTypeAndItemId ( $parm -> getType (), $parm -> getID () )) {
return PluginProcessmakerTask :: getToDoTasks ( $myCase -> getID (), $parm -> getType () . " Task " );
}
return array ();
}
2016-10-25 11:37:01 +02:00
}