Exemplo n.º 1
0
 /**
  * get SQL condition for filtered dropdown assign groups
  * @param int $tickets_id
  * @param int $itilcategories_id
  * @return string
  */
 static function getSQLCondition($tickets_id, $itilcategories_id)
 {
     $ticket = new Ticket();
     $group = new Group();
     $params = array('entities_id' => $_SESSION['glpiactive_entity'], 'is_recursive' => 1);
     if (!empty($tickets_id) && $ticket->getFromDB($tickets_id)) {
         // == UPDATE EXISTING TICKET ==
         $params['entities_id'] = $ticket->fields['entities_id'];
         $params['condition'] = " AND " . ($ticket->fields['type'] == Ticket::DEMAND_TYPE ? "`is_request`='1'" : "`is_incident`='1'");
     }
     $found_groups = self::getGroupsForCategory($itilcategories_id, $params);
     $groups_id_toshow = array();
     //init
     if (!empty($found_groups)) {
         for ($lvl = 1; $lvl <= 4; $lvl++) {
             if (isset($found_groups['groups_id_level' . $lvl])) {
                 if ($found_groups['groups_id_level' . $lvl] === "all") {
                     foreach (PluginItilcategorygroupsGroup_Level::getAllGroupForALevel($lvl, $params['entities_id']) as $groups_id) {
                         if ($group->getFromDB($groups_id)) {
                             $groups_id_toshow[] = $group->getID();
                         }
                     }
                 } else {
                     foreach ($found_groups['groups_id_level' . $lvl] as $groups_id) {
                         if (countElementsInTableForEntity("glpi_groups", $ticket->getEntityID(), "`id`='{$groups_id}'") > 0) {
                             $group->getFromDB($groups_id);
                             $groups_id_toshow[] = $group->getID();
                         }
                     }
                 }
             }
         }
     }
     $condition = "";
     if (count($groups_id_toshow) > 0) {
         // transform found groups (2 dimensions) in a flat array
         $groups_id_toshow_flat = array();
         array_walk_recursive($groups_id_toshow, function ($v, $k) use(&$groups_id_toshow_flat) {
             array_push($groups_id_toshow_flat, $v);
         });
         $newarray = implode(", ", $groups_id_toshow_flat);
         $condition = " id IN ({$newarray})";
     }
     return $condition;
 }
<?php

include "../../../inc/includes.php";
Session::checkCentralAccess();
$level = new PluginItilcategorygroupsGroup_Level();
if (isset($_POST["add"])) {
    $level->add($_POST);
    Html::back();
} else {
    if (isset($_POST["update"])) {
        $level->update($_POST);
        Html::back();
    }
}
Html::displayErrorAndDie("lost");
Exemplo n.º 3
0
function plugin_pre_item_update_itilcategorygroups($item)
{
    if (isset($_REQUEST['massiveaction']) && isset($_REQUEST['lvl']) && $item instanceof Group) {
        $group_level = new PluginItilcategorygroupsGroup_Level();
        if (!$group_level->getFromDB($item->fields['id'])) {
            $group_level->add(array('groups_id' => $item->fields['id'], 'lvl' => $_REQUEST['lvl']));
        } else {
            $group_level->update(array('groups_id' => $item->fields['id'], 'lvl' => $_REQUEST['lvl']));
        }
    }
    return $item;
}