From 1f1733e7923535ef16ac5eac8207d37d86b5be86 Mon Sep 17 00:00:00 2001 From: tsmr Date: Tue, 19 Jun 2018 14:31:55 +0200 Subject: [PATCH] Add link into map & disable status search --- ajax/launchURL.php | 27 +++++++--- inc/infotel.class.php | 117 ++++++++++++++++++++++++++++++++---------- 2 files changed, 109 insertions(+), 35 deletions(-) diff --git a/ajax/launchURL.php b/ajax/launchURL.php index 66dd33d..c9d4dd0 100644 --- a/ajax/launchURL.php +++ b/ajax/launchURL.php @@ -55,7 +55,7 @@ $options['criteria'][1]['searchtype'] = 'contains'; $options['criteria'][1]['value'] = $_POST["datetik"]; $options['criteria'][1]['link'] = 'AND'; - + if (empty($_POST["groups_id"])) { $options['criteria'][2]['field'] = 8; // technician group $options['criteria'][2]['searchtype'] = 'contains'; @@ -80,7 +80,7 @@ } $options['criteria'][4]['value'] = $_POST["entities_id"]; $options['criteria'][4]['link'] = 'AND'; - + $link = $CFG_GLPI["root_doc"] . '/front/ticket.php?is_deleted=0&' . Toolbox::append_params($options, "&"); echo $link; @@ -99,13 +99,24 @@ $options['criteria'][1]['searchtype'] = 'equals'; $options['criteria'][1]['value'] = $_POST["priority_id"]; $options['criteria'][1]['link'] = 'AND'; - + if ($_POST["type"] > 0) { $options['criteria'][2]['field'] = 14; // type $options['criteria'][2]['searchtype'] = 'equals'; $options['criteria'][2]['value'] = $_POST["type"]; $options['criteria'][2]['link'] = 'AND'; } + + $options['criteria'][3]['field'] = 80; // entities + $options['criteria'][3]['searchtype'] = 'equals'; + if (isset($_POST["sons"]) && $_POST["sons"] > 0) { + $options['criteria'][3]['searchtype'] = 'under'; + } + $options['criteria'][3]['value'] = $_POST["entities_id"]; + $options['criteria'][3]['link'] = 'AND'; + + + $link = $CFG_GLPI["root_doc"] . '/front/ticket.php?is_deleted=0&' . Toolbox::append_params($options, "&"); echo $link; @@ -177,7 +188,7 @@ $options['criteria'][2]['value'] = $_POST["category_id"]; $options['criteria'][2]['link'] = 'AND'; } - + if (empty($_POST["groups_id"])) { $options['criteria'][3]['field'] = 8; // technician group $options['criteria'][3]['searchtype'] = 'contains'; @@ -189,7 +200,7 @@ $options['criteria'][3]['value'] = $_POST["groups_id"]; $options['criteria'][3]['link'] = 'AND'; } - + $options['criteria'][4]['field'] = 80; // entities $options['criteria'][4]['searchtype'] = 'equals'; if (isset($_POST["sons"]) && $_POST["sons"] > 0) { @@ -197,7 +208,7 @@ } $options['criteria'][4]['value'] = $_POST["entities_id"]; $options['criteria'][4]['link'] = 'AND'; - + $link = $CFG_GLPI["root_doc"] . '/front/ticket.php?is_deleted=0&' . Toolbox::append_params($options, "&"); echo $link; @@ -223,14 +234,14 @@ $options['criteria'][1]['value'] = $_POST["locations_id"]; $options['criteria'][1]['link'] = 'AND'; } - + if ($_POST["type"] > 0) { $options['criteria'][2]['field'] = 14; // type $options['criteria'][2]['searchtype'] = 'equals'; $options['criteria'][2]['value'] = $_POST["type"]; $options['criteria'][2]['link'] = 'AND'; } - + $options['criteria'][3]['field'] = 80; // entities $options['criteria'][3]['searchtype'] = 'equals'; if (isset($_POST["sons"]) && $_POST["sons"] > 0) { diff --git a/inc/infotel.class.php b/inc/infotel.class.php index 09be412..726b1e6 100644 --- a/inc/infotel.class.php +++ b/inc/infotel.class.php @@ -128,7 +128,7 @@ public function getWidgetContentForItem($widgetId, $opt = []) { switch ($widgetId) { case $this->getType() . "1": - + // __("Opened tickets backlog", "mydashboard") $criterias = ['entities_id', 'is_recursive', 'groups_id', 'type']; $params = ["preferences" => $this->preferences, "criterias" => $criterias, @@ -259,7 +259,12 @@ function () { $.ajax({ url: '" . $CFG_GLPI['root_doc'] . "/plugins/mydashboard/ajax/launchURL.php', type: 'POST', - data:{datetik:datetik,groups_id:$groups_criteria,type:$type, entities_id:$entities_id_criteria, sons:$sons_criteria, widget:'$widgetId'}, + data:{datetik:datetik, + groups_id:$groups_criteria, + type:$type, + entities_id:$entities_id_criteria, + sons:$sons_criteria, + widget:'$widgetId'}, success:function(response) { window.open(response); } @@ -292,25 +297,29 @@ function () { case $this->getType() . "2": - $criterias = ['type']; + $criterias = ['entities_id', 'is_recursive', 'type']; $params = ["preferences" => $this->preferences, "criterias" => $criterias, "opt" => $opt]; $options = PluginMydashboardHelper::manageCriterias($params); - $opt = $options['opt']; - $crit = $options['crit']; - $type = $opt['type']; - $type_criteria = $crit['type']; - - $query = "SELECT DISTINCT + $opt = $options['opt']; + $crit = $options['crit']; + $type = $opt['type']; + $type_criteria = $crit['type']; + //$status_criteria = $crit['status']; + $entities_criteria = $crit['entities_id']; + $entities_id_criteria = $crit['entity']; + $sons_criteria = $crit['sons']; + //$status_search = json_encode($status_criteria); + $query = "SELECT DISTINCT `priority`, COUNT(`id`) AS nb FROM `glpi_tickets` - WHERE NOT `glpi_tickets`.`is_deleted` $type_criteria "; - $query .= getEntitiesRestrictRequest("AND", Ticket::getTable()) - . " AND `status` NOT IN (" . CommonITILObject::SOLVED . "," . CommonITILObject::CLOSED . ") - GROUP BY `priority` ORDER BY `priority` ASC"; + WHERE NOT `glpi_tickets`.`is_deleted` $type_criteria $entities_criteria"; + // $query .= " AND `status` IN('" . implode("', '", $status_criteria) . "')"; + $query .= " AND `status` NOT IN (" . CommonITILObject::SOLVED . "," . CommonITILObject::CLOSED . ") "; + $query .= " GROUP BY `priority` ORDER BY `priority` ASC"; $colors = []; $result = $DB->query($query); @@ -384,7 +393,11 @@ function() { $.ajax({ url: '" . $CFG_GLPI['root_doc'] . "/plugins/mydashboard/ajax/launchURL.php', type: 'POST', - data:{priority_id:priority_id, type:$type,widget:'$widgetId'}, + data:{priority_id:priority_id, + entities_id:$entities_id_criteria, + sons:$sons_criteria, + type:$type, + widget:'$widgetId'}, success:function(response) { window.open(response); } @@ -3167,7 +3180,7 @@ function() { case $this->getType() . "28": - $criterias = ['entities_id', 'is_recursive', 'type', 'groups_id', 'status']; + $criterias = ['entities_id', 'is_recursive', 'type', 'groups_id']; $params = ["preferences" => $this->preferences, "criterias" => $criterias, "opt" => $opt]; @@ -3176,12 +3189,15 @@ function() { $opt = $options['opt']; $crit = $options['crit']; - $type_criteria = $crit['type']; - $status_criteria = $crit['status']; - $entities_criteria = $crit['entities_id']; - $groups_criteria = $crit['groups_id']; - $widget = new PluginMydashboardHtml(); - $title = __("Map - Opened tickets by location", "mydashboard"); + $type = $opt['type']; + $type_criteria = $crit['type']; + //$status_criteria = $crit['status']; + $entities_criteria = $crit['entities_id']; + $entities_id_criteria = $crit['entity']; + $sons_criteria = $crit['sons']; + $groups_criteria = $crit['groups_id']; + $widget = new PluginMydashboardHtml(); + $title = __("Map - Opened tickets by location", "mydashboard"); $widget->setWidgetComment(__("Display Tickets by location (Latitude / Longitude). You must define a Google API Key and add it into setup", "mydashboard")); $widget->setWidgetTitle($title); $query = "SELECT DISTINCT @@ -3189,6 +3205,7 @@ function() { `glpi_locations`.`latitude`, `glpi_locations`.`longitude`, `glpi_locations`.`comment`, + `glpi_locations`.`id`, COUNT(`glpi_tickets`.`id`) AS `nb` FROM `glpi_tickets` LEFT JOIN `glpi_locations` ON (`glpi_tickets`.`locations_id` = `glpi_locations`.`id`) @@ -3200,8 +3217,8 @@ function() { if (isset($opt['groups_id']) && ($opt['groups_id'] != 0)) { $query .= " AND `glpi_groups_tickets`.`groups_id` = " . $groups_criteria; } - $query .= " AND `status` IN('".implode("', '", $status_criteria)."')"; - + // $query .= " AND `status` IN('" . implode("', '", $status_criteria) . "')"; + $query .= " AND `status` NOT IN (" . CommonITILObject::SOLVED . "," . CommonITILObject::CLOSED . ") "; $query .= " GROUP BY `glpi_tickets`.`locations_id`"; $result = $DB->query($query); @@ -3209,14 +3226,56 @@ function() { $locations = "["; $infos = "["; + if ($nb) { while ($data = $DB->fetch_array($result)) { if (!empty($data['latitude']) && !empty($data['longitude'])) { $name = addslashes($data['name']); $locations .= "['" . $name . "'," . $data['latitude'] . "," . $data['longitude'] . ",'" . $data['nb'] . "'],"; $comment = addslashes(str_replace("\r\n", "
", $data['comment'])); - $nb = $data['nb'] . " " . _n('Ticket', 'Tickets', $data['nb']); - $infos .= "['
' + '
$name
'+ '

$comment

'+ '

$nb

'+'
'],"; + + $options['reset'] = 'reset'; + $options['criteria'][0]['field'] = 12; // status + $options['criteria'][0]['searchtype'] = 'equals'; + $options['criteria'][0]['value'] = "notold"; + $options['criteria'][0]['link'] = 'AND'; + + $options['criteria'][1]['field'] = 83; // location + $options['criteria'][1]['searchtype'] = 'equals'; + $options['criteria'][1]['value'] = $data['id']; + $options['criteria'][1]['link'] = 'AND'; + + if ($type > 0) { + $options['criteria'][2]['field'] = 14; // type + $options['criteria'][2]['searchtype'] = 'equals'; + $options['criteria'][2]['value'] = $type; + $options['criteria'][2]['link'] = 'AND'; + } + + $options['criteria'][3]['field'] = 80; // entities + $options['criteria'][3]['searchtype'] = 'equals'; + if (isset($sons_criteria) && $sons_criteria > 0) { + $options['criteria'][3]['searchtype'] = 'under'; + } + $options['criteria'][3]['value'] = $entities_id_criteria; + $options['criteria'][3]['link'] = 'AND'; + + if (empty($groups_criteria)) { + $options['criteria'][4]['field'] = 8; // technician group + $options['criteria'][4]['searchtype'] = 'contains'; + $options['criteria'][4]['value'] = '^$'; + $options['criteria'][4]['link'] = 'AND'; + } else { + $options['criteria'][4]['field'] = 8; // technician group + $options['criteria'][4]['searchtype'] = 'equals'; + $options['criteria'][4]['value'] = $groups_criteria; + $options['criteria'][4]['link'] = 'AND'; + } + $link_ticket = $CFG_GLPI["root_doc"] . '/front/ticket.php?is_deleted=0&' . + Toolbox::append_params($options, "&"); + $nb = "" . $data['nb'] . " " . _n('Ticket', 'Tickets', $data['nb']) . ""; + + $infos .= "['
' + '
$name
'+ '

$comment

'+ '

$nb

'+'
'],"; } } } @@ -3265,7 +3324,6 @@ function initialize() { //iconURLPrefix + 'green.png', //iconURLPrefix + 'orange.png', ] - var iconsLength = icons.length; // Info Window Content var infoWindowContent = $infos; @@ -3282,7 +3340,12 @@ function initialize() { } marker = new google.maps.Marker({ position: position, - icon: {url:icons[0], scaledSize: new google.maps.Size(27, 43), labelOrigin: new google.maps.Point(14, 14),fillColor: '#FFF'}, + icon: { + url:icons[0], + scaledSize: new google.maps.Size(27, 43), + labelOrigin: new google.maps.Point(14, 14), + fillColor: '#FFF' + }, map: map, label: { text: markers[i][3],