Files
luos/workflow/engine/methods/cases/casesMenuLoader.php

249 lines
10 KiB
PHP
Raw Normal View History

<?php
2017-12-04 13:25:35 +00:00
$action = isset($_GET['action']) ? G::sanitizeInput($_GET['action']) : 'default';
2017-12-04 13:25:35 +00:00
$userId = isset($_SESSION['USER_LOGGED']) ? $_SESSION['USER_LOGGED'] : '00000000000000000000000000000000';
switch ($action) {
case 'getAllCounters':
getAllCounters();
break;
/*----------------------------------********---------------------------------*/
case 'getAllCountersEnterprise':
getAllCountersEnterprise();
break;
/*----------------------------------********---------------------------------*/
2010-12-02 23:34:41 +00:00
default: //this is the starting call
getLoadTreeMenuData();
break;
}
2017-12-04 13:25:35 +00:00
function getLoadTreeMenuData()
{
2017-12-04 13:25:35 +00:00
header("content-type: text/xml");
2020-01-30 16:26:32 -04:00
$menuInstance = new Menu();
$menuInstance->load('cases');
2020-01-30 16:26:32 -04:00
$types = ['to_do', 'draft', 'cancelled', 'sent', 'paused', 'completed'];
$typesId = ['CASES_INBOX' => 'to_do', 'CASES_DRAFT' => 'draft', 'CASES_CANCELLED' => 'cancelled',
'CASES_SENT' => 'sent', 'CASES_PAUSED' => 'paused', 'CASES_COMPLETED' => 'completed'];
// If the feature for highlight the home folders is disabled, add unassigned list to tree options with counters
if (!HIGHLIGHT_HOME_FOLDER_ENABLE) {
$types[] = 'selfservice';
$typesId['CASES_SELFSERVICE'] = 'selfservice';
}
/*----------------------------------********---------------------------------*/
2017-12-04 13:25:35 +00:00
$licensedFeatures = PMLicensedFeatures::getSingleton();
if ($licensedFeatures->verifyfeature('7TTeDBQeWRoZTZKYjh4eFpYUlRDUUEyVERPU3FxellWank=')) {
2020-01-30 16:26:32 -04:00
$typesId['CONSOLIDATED_CASES'] = 'batch_routing';
$types[] = 'batch_routing';
}
/*----------------------------------********---------------------------------*/
2020-01-30 16:26:32 -04:00
$list = [];
$list['count'] = ' ';
2020-01-30 16:26:32 -04:00
$empty = [];
foreach ($types as $key => $val) {
$empty[$val] = $list;
}
2020-01-30 16:26:32 -04:00
$count = $empty;
// Now drawing the tree view using the menu options from menu/cases.php
$menuCases = [];
for ($i = 0; $i < count($menuInstance->Options); $i++) {
if ($menuInstance->Types[$i] == 'blockHeader') {
$currentBlockID = $menuInstance->Id[$i];
$menuCases[$currentBlockID]['blockTitle'] = $menuInstance->Labels[$i];
if ($menuInstance->Options[$i] != "") {
$menuCases[$currentBlockID]['link'] = $menuInstance->Options[$i];
}
2020-01-30 16:26:32 -04:00
} elseif ($menuInstance->Types[$i] == 'blockNestedTree') {
$currentBlockID = $menuInstance->Id[$i];
$menuCases[$currentBlockID]['blockTitle'] = $menuInstance->Labels[$i];
$menuCases[$currentBlockID]['blockType'] = $menuInstance->Types[$i];
$menuCases[$currentBlockID]['loaderurl'] = $menuInstance->Options[$i];
} elseif ($menuInstance->Types[$i] == 'blockHeaderNoChild') {
$currentBlockID = $menuInstance->Id[$i];
$menuCases[$currentBlockID]['blockTitle'] = $menuInstance->Labels[$i];
$menuCases[$currentBlockID]['blockType'] = $menuInstance->Types[$i];
$menuCases[$currentBlockID]['link'] = $menuInstance->Options[$i];
} elseif ($menuInstance->Types[$i] == 'rootNode') {
$menuCases[$currentBlockID]['blockItems'][$menuInstance->Id[$i]] = [
'label' => $menuInstance->Labels[$i],
'link' => $menuInstance->Options[$i],
'icon' => (isset($menuInstance->Icons[$i]) && $menuInstance->Icons[$i] != '') ? $menuInstance->Icons[$i] : 'kcmdf.png'
];
FEATURE, was added a feature to enable load three level nodes on cases tree menu on HOME tab Now we can set from any menu file (core or plugin) a three level nodes on cases menu: Example: $G_TMP_MENU->AddIdRawOption('TEST1', '#', 'Enterprise Search', '', '', 'blockHeader'); $G_TMP_MENU->AddIdRawOption('TEST2', '#', 'New Seach', '', ''); $G_TMP_MENU->AddIdRawOption('TEST3', '#', 'Saved Searches (9)', '', ''); $G_TMP_MENU->AddIdRawOption('TEST4', '#', 'Favorites', '', '', 'rootNode'); $G_TMP_MENU->AddIdRawOption('TEST5', '#', 'test child 2.1', '', '', 'childNode'); $G_TMP_MENU->AddIdRawOption('TEST6', '#', 'test child 2.2', '', '', 'childNode'); $G_TMP_MENU->AddIdRawOption('TEST7', '#', 'test child 2.3', '', '', 'childNode'); $G_TMP_MENU->AddIdRawOption('TEST8', '#', 'test child 3', '', '', ''); $G_TMP_MENU->AddIdRawOption('TEST9', '#', 'test child 4', '', '', ''); On the last parameter was added two new menu types "rootNode" and "childNode" On the example the first node will be set by "blockHeader" menu type all menu options below that will be added such as its child nodes Now, if a menu option has a type "rootNode" (...'Favorites', '', '', 'rootNode'...) all menu options below this with type "childNode" (...'test child 2.2', '', '', 'childNode'...) will be consireded as its child nodes of menu with type "rootNode", inmediatly a menu option without any menu type is found (..'test child 3', '', '', ''..), this menu and all menu options like it will be added as child nodes of the last menu option with "blockHeader". The result of the example will be something like this: + Enterprise Search - New search - Saved Searches (9) + Favorites - test child 2.1 - test child 2.2 - test child 2.3 - test child 3 - test child 4 ...
2013-08-01 19:06:05 -04:00
$index = $i;
2020-01-30 16:26:32 -04:00
list($childs, $index) = getChilds($menuInstance, ++$index);
2020-01-30 16:26:32 -04:00
$menuCases[$currentBlockID]['blockItems'][$menuInstance->Id[$i]]['childs'] = $childs;
FEATURE, was added a feature to enable load three level nodes on cases tree menu on HOME tab Now we can set from any menu file (core or plugin) a three level nodes on cases menu: Example: $G_TMP_MENU->AddIdRawOption('TEST1', '#', 'Enterprise Search', '', '', 'blockHeader'); $G_TMP_MENU->AddIdRawOption('TEST2', '#', 'New Seach', '', ''); $G_TMP_MENU->AddIdRawOption('TEST3', '#', 'Saved Searches (9)', '', ''); $G_TMP_MENU->AddIdRawOption('TEST4', '#', 'Favorites', '', '', 'rootNode'); $G_TMP_MENU->AddIdRawOption('TEST5', '#', 'test child 2.1', '', '', 'childNode'); $G_TMP_MENU->AddIdRawOption('TEST6', '#', 'test child 2.2', '', '', 'childNode'); $G_TMP_MENU->AddIdRawOption('TEST7', '#', 'test child 2.3', '', '', 'childNode'); $G_TMP_MENU->AddIdRawOption('TEST8', '#', 'test child 3', '', '', ''); $G_TMP_MENU->AddIdRawOption('TEST9', '#', 'test child 4', '', '', ''); On the last parameter was added two new menu types "rootNode" and "childNode" On the example the first node will be set by "blockHeader" menu type all menu options below that will be added such as its child nodes Now, if a menu option has a type "rootNode" (...'Favorites', '', '', 'rootNode'...) all menu options below this with type "childNode" (...'test child 2.2', '', '', 'childNode'...) will be consireded as its child nodes of menu with type "rootNode", inmediatly a menu option without any menu type is found (..'test child 3', '', '', ''..), this menu and all menu options like it will be added as child nodes of the last menu option with "blockHeader". The result of the example will be something like this: + Enterprise Search - New search - Saved Searches (9) + Favorites - test child 2.1 - test child 2.2 - test child 2.3 - test child 3 - test child 4 ...
2013-08-01 19:06:05 -04:00
$i = $index;
} else {
2020-01-30 16:26:32 -04:00
$menuCases[$currentBlockID]['blockItems'][$menuInstance->Id[$i]] = [
'label' => $menuInstance->Labels[$i],
'link' => $menuInstance->Options[$i],
'icon' => (isset($menuInstance->Icons[$i]) && $menuInstance->Icons[$i] != '') ? $menuInstance->Icons[$i] : 'kcmdf.png'
];
if (isset($typesId[$menuInstance->Id[$i]])) {
$menuCases[$currentBlockID]['blockItems'][$menuInstance->Id[$i]]['cases_count'] = $count[$typesId[$menuInstance->Id[$i]]]['count'];
}
}
}
// Build xml nodes for a specific child node by its "id" on var "$_POST['node']" passed in a POST request
if (isset($_POST['node']) && in_array($_POST['node'], array_keys($menuCases))) {
$xml = new SimpleXMLElement('<?xml version="1.0" standalone="yes"?><menu_cases />');
if (array_key_exists('blockItems', $menuCases[$_POST['node']]) && is_array($menuCases[$_POST['node']]['blockItems'])) {
foreach ($menuCases[$_POST['node']]['blockItems'] as $key => $item) {
$option = $xml->addChild('option');
$option->addAttribute('id', $key);
$option->addAttribute('title', $item['label']);
$option->addAttribute('url', $item['link']);
if (! empty($item['cases_count'])) {
$option->addAttribute('cases_count', $item['cases_count']);
}
}
}
2020-01-30 16:26:32 -04:00
// This function generates an xml, so it prevents the output of a badly formed xml
// by cleaning any content prior to this function with ob_clean
2017-07-14 08:02:14 -04:00
ob_clean();
echo $xml->asXML();
die;
}
// Build xml document for all tree nodes
$xml = new SimpleXMLElement('<?xml version="1.0" standalone="yes"?><menu_cases />');
foreach ($menuCases as $menuId => $menuBlock) {
if (isset($menuBlock['blockItems']) && count($menuBlock['blockItems']) > 0) {
// adding "menu_block" node
$menuBlockNode = $xml->addChild('menu_block');
$menuBlockNode->addAttribute('id', $menuId);
$menuBlockNode->addAttribute('blockTitle', $menuBlock['blockTitle']);
if (! empty($menuBlock['link'])) {
$menuBlockNode->addAttribute('url', $menuBlock['link']);
}
2020-01-30 16:26:32 -04:00
// Adding "menu_block" child nodes
2017-12-04 13:25:35 +00:00
foreach ($menuBlock['blockItems'] as $id => $menu) {
FEATURE, was added a feature to enable load three level nodes on cases tree menu on HOME tab Now we can set from any menu file (core or plugin) a three level nodes on cases menu: Example: $G_TMP_MENU->AddIdRawOption('TEST1', '#', 'Enterprise Search', '', '', 'blockHeader'); $G_TMP_MENU->AddIdRawOption('TEST2', '#', 'New Seach', '', ''); $G_TMP_MENU->AddIdRawOption('TEST3', '#', 'Saved Searches (9)', '', ''); $G_TMP_MENU->AddIdRawOption('TEST4', '#', 'Favorites', '', '', 'rootNode'); $G_TMP_MENU->AddIdRawOption('TEST5', '#', 'test child 2.1', '', '', 'childNode'); $G_TMP_MENU->AddIdRawOption('TEST6', '#', 'test child 2.2', '', '', 'childNode'); $G_TMP_MENU->AddIdRawOption('TEST7', '#', 'test child 2.3', '', '', 'childNode'); $G_TMP_MENU->AddIdRawOption('TEST8', '#', 'test child 3', '', '', ''); $G_TMP_MENU->AddIdRawOption('TEST9', '#', 'test child 4', '', '', ''); On the last parameter was added two new menu types "rootNode" and "childNode" On the example the first node will be set by "blockHeader" menu type all menu options below that will be added such as its child nodes Now, if a menu option has a type "rootNode" (...'Favorites', '', '', 'rootNode'...) all menu options below this with type "childNode" (...'test child 2.2', '', '', 'childNode'...) will be consireded as its child nodes of menu with type "rootNode", inmediatly a menu option without any menu type is found (..'test child 3', '', '', ''..), this menu and all menu options like it will be added as child nodes of the last menu option with "blockHeader". The result of the example will be something like this: + Enterprise Search - New search - Saved Searches (9) + Favorites - test child 2.1 - test child 2.2 - test child 2.3 - test child 3 - test child 4 ...
2013-08-01 19:06:05 -04:00
if (! empty($menu['childs'])) {
$rootNode = $menuBlockNode->addChild('menu_block');
$rootNode->addAttribute('id', $id);
$rootNode->addAttribute('title', $menu['label']);
$rootNode->addAttribute('url', $menu['link']);
$rootNode->addAttribute('expanded', true);
foreach ($menu['childs'] as $id => $child) {
$childNode = $rootNode->addChild('option');
$childNode->addAttribute('id', $id);
$childNode->addAttribute('title', $child['label']);
$childNode->addAttribute('url', $child['link']);
}
continue;
}
$option = $menuBlockNode->addChild('option');
$option->addAttribute('id', $id);
$option->addAttribute('title', $menu['label']);
$option->addAttribute('url', $menu['link']);
if (! empty($menu['cases_count'])) {
$option->addAttribute('cases_count', $menu['cases_count']);
}
}
} elseif (isset($menuBlock['blockType']) && $menuBlock['blockType'] == "blockNestedTree") {
$menuBlockNode = $xml->addChild('menu_block');
$menuBlockNode->addAttribute('id', $menuId);
$menuBlockNode->addAttribute('folderId', "0");
$menuBlockNode->addAttribute('blockTitle', $menuBlock['blockTitle']);
$menuBlockNode->addAttribute('blockNestedTree', $menuBlock['loaderurl']);
} elseif (isset($menuBlock['blockType']) && $menuBlock['blockType'] == "blockHeaderNoChild") {
$menuBlockNode = $xml->addChild('menu_block');
$menuBlockNode->addAttribute('id', $menuId);
$menuBlockNode->addAttribute('blockTitle', $menuBlock['blockTitle']);
$menuBlockNode->addAttribute('blockHeaderNoChild', "blockHeaderNoChild");
$menuBlockNode->addAttribute('url', $menuBlock['link']);
}
}
2020-01-30 16:26:32 -04:00
// This function generates an xml, so it prevents the output of a badly formed xml
// by cleaning any content prior to this function with ob_clean
2017-07-13 12:18:58 -04:00
ob_clean();
echo $xml->asXML();
die;
}
/*----------------------------------********---------------------------------*/
function getAllCountersEnterprise()
{
try {
$userUid = (isset($_SESSION['USER_LOGGED']) && $_SESSION['USER_LOGGED'] != '') ? $_SESSION['USER_LOGGED'] : null;
$lists = new \ProcessMaker\BusinessModel\Lists();
$response = $lists->getCounters($userUid);
echo G::json_encode($response);
} catch (\Exception $e) {
throw (new Exception($e->getMessage()));
}
}
/*----------------------------------********---------------------------------*/
2017-12-04 13:25:35 +00:00
function getAllCounters()
{
2017-12-04 13:25:35 +00:00
$userUid = (isset($_SESSION['USER_LOGGED']) && $_SESSION['USER_LOGGED'] != '') ? $_SESSION['USER_LOGGED'] : null;
2017-12-04 13:25:35 +00:00
$aTypes = array();
$aTypes['to_do'] = 'CASES_INBOX';
$aTypes['draft'] = 'CASES_DRAFT';
$aTypes['cancelled'] = 'CASES_CANCELLED';
$aTypes['sent'] = 'CASES_SENT';
$aTypes['paused'] = 'CASES_PAUSED';
$aTypes['completed'] = 'CASES_COMPLETED';
$aTypes['selfservice'] = 'CASES_SELFSERVICE';
2010-12-02 23:34:41 +00:00
//$aTypes['to_revise'] = 'CASES_TO_REVISE';
//$aTypes['to_reassign'] = 'CASES_TO_REASSIGN';
$case = new \ProcessMaker\BusinessModel\Cases();
$aCount = $case->getListCounters($userUid, array_keys($aTypes));
2017-12-04 13:25:35 +00:00
$response = array();
$i = 0;
foreach ($aCount as $type => $count) {
$response[$i] = new stdclass();
$response[$i]->item = $aTypes[$type];
$response[$i]->count = $count;
$i ++;
}
2017-12-04 13:25:35 +00:00
echo G::json_encode($response);
}
FEATURE, was added a feature to enable load three level nodes on cases tree menu on HOME tab Now we can set from any menu file (core or plugin) a three level nodes on cases menu: Example: $G_TMP_MENU->AddIdRawOption('TEST1', '#', 'Enterprise Search', '', '', 'blockHeader'); $G_TMP_MENU->AddIdRawOption('TEST2', '#', 'New Seach', '', ''); $G_TMP_MENU->AddIdRawOption('TEST3', '#', 'Saved Searches (9)', '', ''); $G_TMP_MENU->AddIdRawOption('TEST4', '#', 'Favorites', '', '', 'rootNode'); $G_TMP_MENU->AddIdRawOption('TEST5', '#', 'test child 2.1', '', '', 'childNode'); $G_TMP_MENU->AddIdRawOption('TEST6', '#', 'test child 2.2', '', '', 'childNode'); $G_TMP_MENU->AddIdRawOption('TEST7', '#', 'test child 2.3', '', '', 'childNode'); $G_TMP_MENU->AddIdRawOption('TEST8', '#', 'test child 3', '', '', ''); $G_TMP_MENU->AddIdRawOption('TEST9', '#', 'test child 4', '', '', ''); On the last parameter was added two new menu types "rootNode" and "childNode" On the example the first node will be set by "blockHeader" menu type all menu options below that will be added such as its child nodes Now, if a menu option has a type "rootNode" (...'Favorites', '', '', 'rootNode'...) all menu options below this with type "childNode" (...'test child 2.2', '', '', 'childNode'...) will be consireded as its child nodes of menu with type "rootNode", inmediatly a menu option without any menu type is found (..'test child 3', '', '', ''..), this menu and all menu options like it will be added as child nodes of the last menu option with "blockHeader". The result of the example will be something like this: + Enterprise Search - New search - Saved Searches (9) + Favorites - test child 2.1 - test child 2.2 - test child 2.3 - test child 3 - test child 4 ...
2013-08-01 19:06:05 -04:00
function getChilds($menu, $index)
{
$childs = array();
for ($i = $index; $i < count($menu->Options); $i++) {
if ($menu->Types[$i] == 'childNode') {
$childs[$menu->Id[$i]] = array(
'label' => $menu->Labels[$i],
'link' => $menu->Options[$i],
'icon' => ''
);
} else {
//TODO we can add more recursive logic here to enable more childs levels
break;
}
}
return array($childs, --$i);
}