|
1 | | -<?php |
2 | | - |
3 | | -// ---------------------------------------------------------------------- |
4 | | -// Original Author of file: Olivier Moron |
5 | | -// Purpose of file: to return list of processes which can be started by end-user |
6 | | -// ---------------------------------------------------------------------- |
7 | | - |
8 | | -// Direct access to file |
9 | | -if (strpos($_SERVER['PHP_SELF'], "dropdownProcesses.php")) { |
10 | | - include ("../../../inc/includes.php"); |
11 | | - header("Content-Type: text/html; charset=UTF-8"); |
12 | | - Html::header_nocache(); |
13 | | -} |
14 | | - |
15 | | -if (!defined('GLPI_ROOT')) { |
16 | | - die("Can not access directly to this file"); |
17 | | -} |
18 | | - |
19 | | - |
20 | | -Session::checkLoginUser(); |
21 | | - |
22 | | -if (isset($_REQUEST["entity_restrict"]) |
23 | | - && !is_array($_REQUEST["entity_restrict"]) |
24 | | - && (substr($_REQUEST["entity_restrict"], 0, 1) === '[') |
25 | | - && (substr($_REQUEST["entity_restrict"], -1) === ']')) { |
26 | | - $_REQUEST["entity_restrict"] = json_decode($_REQUEST["entity_restrict"]); |
27 | | - $_REQUEST["entity_restrict"] = $_REQUEST["entity_restrict"][0]; |
28 | | -} |
29 | | - |
30 | | -// Security |
31 | | -if (!($item = getItemForItemtype($_REQUEST['itemtype']))) { |
32 | | - exit(); |
33 | | -} |
34 | | - |
35 | | -$one_item = -1; |
36 | | -if (isset($_POST['_one_id'])) { |
37 | | - $one_item = $_POST['_one_id']; |
38 | | -} |
39 | | -// Count real items returned |
40 | | -$count = 0; |
41 | | - |
42 | | -if (!isset($_REQUEST['emptylabel']) || ($_REQUEST['emptylabel'] == '')) { |
43 | | - $_REQUEST['emptylabel'] = Dropdown::EMPTY_VALUE; |
44 | | -} |
45 | | - |
46 | | -$search=""; |
47 | | -if (!empty($_REQUEST['searchText'])) { |
48 | | - $search = ['LIKE', Search::makeTextSearchValue($_REQUEST['searchText'])]; |
49 | | -} |
50 | | - |
51 | | -$processes = []; |
52 | | - |
53 | | -// Empty search text : display first |
54 | | -if (empty($_REQUEST['searchText'])) { |
55 | | - if ($_REQUEST['display_emptychoice']) { |
56 | | - if (($one_item < 0) || ($one_item == 0)) { |
57 | | - array_push($processes, ['id' => 0, |
58 | | - 'text' => $_REQUEST['emptylabel']]); |
59 | | - } |
60 | | - } |
61 | | -} |
62 | | - |
63 | | -$processall = (isset($_REQUEST['specific_tags']['process_restrict']) && !$_REQUEST['specific_tags']['process_restrict']); |
64 | | -$count_cases_per_item = isset($_REQUEST['specific_tags']['count_cases_per_item']) ? $_REQUEST['specific_tags']['count_cases_per_item'] : []; |
65 | | - |
66 | | -$result = PluginProcessmakerProcess::getSqlSearchResult(false, $search); |
67 | | - |
68 | | -//if ($DB->numrows($result)) { |
69 | | -// while ($data = $DB->fetch_array($result)) { |
70 | | -//if ($result->numrows()) { |
71 | | - foreach ($result as $data) { |
72 | | - $process_entities = PluginProcessmakerProcess::getEntitiesForProfileByProcess($data["id"], $_SESSION['glpiactiveprofile']['id'], true); |
73 | | - $can_add = $data['max_cases_per_item'] == 0 || !isset($count_cases_per_item[$data["id"]]) || $count_cases_per_item[$data["id"]] < $data['max_cases_per_item']; |
74 | | - if ($processall |
75 | | - || ($data['maintenance'] != 1 |
76 | | - && in_array( $_REQUEST["entity_restrict"], $process_entities) |
77 | | - && $can_add) ) { |
78 | | - |
79 | | - array_push( $processes, ['id' => $data["id"], |
80 | | - 'text' => $data["name"] |
81 | | - ]); |
82 | | - $count++; |
83 | | - } |
84 | | - } |
85 | | -//} |
86 | | - |
87 | | -$ret['results'] = $processes; |
88 | | -$ret['count'] = $count; |
89 | | -echo json_encode($ret); |
| 1 | +<?php |
| 2 | + |
| 3 | +// ---------------------------------------------------------------------- |
| 4 | +// Original Author of file: Olivier Moron |
| 5 | +// Purpose of file: to return list of processes which can be started by end-user |
| 6 | +// ---------------------------------------------------------------------- |
| 7 | + |
| 8 | +// Direct access to file |
| 9 | +if (strpos($_SERVER['PHP_SELF'], "dropdownProcesses.php")) { |
| 10 | + include ("../../../inc/includes.php"); |
| 11 | + header("Content-Type: text/html; charset=UTF-8"); |
| 12 | + Html::header_nocache(); |
| 13 | +} |
| 14 | + |
| 15 | +if (!defined('GLPI_ROOT')) { |
| 16 | + die("Can not access directly to this file"); |
| 17 | +} |
| 18 | + |
| 19 | + |
| 20 | +Session::checkLoginUser(); |
| 21 | + |
| 22 | +if (isset($_REQUEST["entity_restrict"]) |
| 23 | + && !is_array($_REQUEST["entity_restrict"]) |
| 24 | + && (substr($_REQUEST["entity_restrict"], 0, 1) === '[') |
| 25 | + && (substr($_REQUEST["entity_restrict"], -1) === ']')) { |
| 26 | + $_REQUEST["entity_restrict"] = json_decode($_REQUEST["entity_restrict"]); |
| 27 | + $_REQUEST["entity_restrict"] = $_REQUEST["entity_restrict"][0]; |
| 28 | +} |
| 29 | + |
| 30 | +// Security |
| 31 | +if (!($item = getItemForItemtype($_REQUEST['itemtype']))) { |
| 32 | + exit(); |
| 33 | +} |
| 34 | + |
| 35 | +$one_item = -1; |
| 36 | +if (isset($_POST['_one_id'])) { |
| 37 | + $one_item = $_POST['_one_id']; |
| 38 | +} |
| 39 | +// Count real items returned |
| 40 | +$count = 0; |
| 41 | + |
| 42 | +if (!isset($_REQUEST['emptylabel']) || ($_REQUEST['emptylabel'] == '')) { |
| 43 | + $_REQUEST['emptylabel'] = Dropdown::EMPTY_VALUE; |
| 44 | +} |
| 45 | + |
| 46 | +$search=""; |
| 47 | +if (!empty($_REQUEST['searchText'])) { |
| 48 | + $search = ['LIKE', Search::makeTextSearchValue($_REQUEST['searchText'])]; |
| 49 | +} |
| 50 | + |
| 51 | +$processes = []; |
| 52 | + |
| 53 | +// Empty search text : display first |
| 54 | +if (empty($_REQUEST['searchText'])) { |
| 55 | + if ($_REQUEST['display_emptychoice']) { |
| 56 | + if (($one_item < 0) || ($one_item == 0)) { |
| 57 | + array_push($processes, ['id' => 0, |
| 58 | + 'text' => $_REQUEST['emptylabel']]); |
| 59 | + } |
| 60 | + } |
| 61 | +} |
| 62 | + |
| 63 | +$processall = (isset($_REQUEST['specific_tags']['process_restrict']) && !$_REQUEST['specific_tags']['process_restrict']); |
| 64 | +$count_cases_per_item = isset($_REQUEST['specific_tags']['count_cases_per_item']) ? $_REQUEST['specific_tags']['count_cases_per_item'] : []; |
| 65 | + |
| 66 | +$result = PluginProcessmakerProcess::getSqlSearchResult(false, $search); |
| 67 | + |
| 68 | +//if ($DB->numrows($result)) { |
| 69 | +// while ($data = $DB->fetch_array($result)) { |
| 70 | +//if ($result->numrows()) { |
| 71 | + foreach ($result as $data) { |
| 72 | + $process_entities = PluginProcessmakerProcess::getEntitiesForProfileByProcess($data["id"], $_SESSION['glpiactiveprofile']['id'], true); |
| 73 | + $can_add = $data['max_cases_per_item'] == 0 || !isset($count_cases_per_item[$data["id"]]) || $count_cases_per_item[$data["id"]] < $data['max_cases_per_item']; |
| 74 | + if ($processall |
| 75 | + || ($data['maintenance'] != 1 |
| 76 | + && in_array( $_REQUEST["entity_restrict"], $process_entities) |
| 77 | + && $can_add) ) { |
| 78 | + |
| 79 | + array_push( $processes, ['id' => $data["id"], |
| 80 | + 'text' => $data["name"] |
| 81 | + ]); |
| 82 | + $count++; |
| 83 | + } |
| 84 | + } |
| 85 | +//} |
| 86 | + |
| 87 | +$ret['results'] = $processes; |
| 88 | +$ret['count'] = $count; |
| 89 | +echo json_encode($ret); |
0 commit comments