예제 #1
0
 /**
  * @see CommonDBTM::getSpecificMassiveActions()
  **/
 function getSpecificMassiveActions($checkitem = NULL)
 {
     $isadmin = static::canUpdate();
     $actions = parent::getSpecificMassiveActions($checkitem);
     if (ProblemTask::canCreate()) {
         $actions['add_task'] = __('Add a new task');
     }
     if (Session::haveRight("edit_all_problem", "1")) {
         $actions['add_actor'] = __('Add an actor');
     }
     if (Session::haveRight('transfer', 'r') && Session::isMultiEntitiesMode() && $isadmin) {
         $actions['add_transfer_list'] = _x('button', 'Add to transfer list');
     }
     return $actions;
 }
예제 #2
0
 /**
  * Show the availability of a user
  *
  * @since version 0.83
  *
  * @param $params   array of params
  *    must contain :
  *          - begin: begin date to check (default '')
  *          - end: end date to check (default '')
  *          - itemtype : User or Object type (Ticket...)
  *          - foreign key field of the itemtype to define which item to used
  *    optional :
  *          - limitto : limit display to a specific user
  *
  * @return Nothing (display function)
  **/
 static function checkAvailability($params = array())
 {
     global $CFG_GLPI, $DB;
     if (!isset($params['itemtype'])) {
         return false;
     }
     if (!($item = getItemForItemtype($params['itemtype']))) {
         return false;
     }
     if (!isset($params[$item->getForeignKeyField()]) || !$item->getFromDB($params[$item->getForeignKeyField()])) {
         return false;
     }
     // No limit by default
     if (!isset($params['limitto'])) {
         $params['limitto'] = 0;
     }
     if (isset($params['begin']) && !empty($params['begin'])) {
         $begin = $params['begin'];
     } else {
         $begin = date("Y-m-d");
     }
     if (isset($params['end']) && !empty($params['end'])) {
         $end = $params['end'];
     } else {
         $end = date("Y-m-d");
     }
     if ($end < $begin) {
         $end = $begin;
     }
     $realbegin = $begin . " " . $CFG_GLPI["planning_begin"];
     $realend = $end . " " . $CFG_GLPI["planning_end"];
     $users = array();
     switch ($item->getType()) {
         case 'User':
             $users[$item->getID()] = $item->getName();
             break;
         default:
             if (Toolbox::is_a($item, 'CommonITILObject')) {
                 foreach ($item->getUsers(CommonITILActor::ASSIGN) as $data) {
                     $users[$data['users_id']] = getUserName($data['users_id']);
                 }
                 foreach ($item->getGroups(CommonITILActor::ASSIGN) as $data) {
                     foreach (Group_User::getGroupUsers($data['groups_id']) as $data2) {
                         $users[$data2['id']] = formatUserName($data2["id"], $data2["name"], $data2["realname"], $data2["firstname"]);
                     }
                 }
             }
             if ($itemtype = 'Ticket') {
                 $task = new TicketTask();
             } else {
                 if ($itemtype = 'Problem') {
                     $task = new ProblemTask();
                 }
             }
             if ($task->getFromDBByQuery("WHERE `tickets_id` = " . $item->fields['id'])) {
                 $id = $task->fields['id'];
                 $users['users_id'] = getUserName($task->fields['users_id_tech']);
                 $group_id = $task->fields['groups_id_tech'];
                 if ($group_id) {
                     foreach (Group_User::getGroupUsers($group_id) as $data2) {
                         $users[$data2['id']] = formatUserName($data2["id"], $data2["name"], $data2["realname"], $data2["firstname"]);
                     }
                 }
             }
             break;
     }
     asort($users);
     // Use get method to check availability
     echo "<div class='center'><form method='GET' name='form' action='planning.php'>\n";
     echo "<table class='tab_cadre_fixe'>";
     $colspan = 5;
     if (count($users) > 1) {
         $colspan++;
     }
     echo "<tr class='tab_bg_1'><th colspan='{$colspan}'>" . __('Availability') . "</th>";
     echo "</tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<td>" . __('Start') . "</td>\n";
     echo "<td>";
     Html::showDateField("begin", array('value' => $begin, 'maybeempty' => false));
     echo "</td>\n";
     echo "<td>" . __('End') . "</td>\n";
     echo "<td>";
     Html::showDateField("end", array('value' => $end, 'maybeempty' => false));
     echo "</td>\n";
     if (count($users) > 1) {
         echo "<td width='40%'>";
         $data = array(0 => __('All'));
         $data += $users;
         Dropdown::showFromArray('limitto', $data, array('width' => '100%', 'value' => $params['limitto']));
         echo "</td>";
     }
     echo "<td class='center'>";
     echo "<input type='hidden' name='" . $item->getForeignKeyField() . "' value=\"" . $item->getID() . "\">";
     echo "<input type='hidden' name='itemtype' value=\"" . $item->getType() . "\">";
     echo "<input type='submit' class='submit' name='checkavailability' value=\"" . _sx('button', 'Search') . "\">";
     echo "</td>\n";
     echo "</tr>";
     echo "</table>";
     Html::closeForm();
     echo "</div>\n";
     if ($params['limitto'] > 0 && isset($users[$params['limitto']])) {
         $displayuser[$params['limitto']] = $users[$params['limitto']];
     } else {
         $displayuser = $users;
     }
     if (count($displayuser)) {
         foreach ($displayuser as $who => $whoname) {
             $params = array('who' => $who, 'who_group' => 0, 'whogroup' => 0, 'begin' => $realbegin, 'end' => $realend);
             $interv = array();
             foreach ($CFG_GLPI['planning_types'] as $itemtype) {
                 $interv = array_merge($interv, $itemtype::populatePlanning($params));
             }
             // Print Headers
             echo "<br><div class='center'><table class='tab_cadre_fixe'>";
             $colnumber = 1;
             $plan_begin = explode(":", $CFG_GLPI["planning_begin"]);
             $plan_end = explode(":", $CFG_GLPI["planning_end"]);
             $begin_hour = intval($plan_begin[0]);
             $end_hour = intval($plan_end[0]);
             if ($plan_end[1] != 0) {
                 $end_hour++;
             }
             $colsize = floor((100 - 15) / ($end_hour - $begin_hour));
             $timeheader = '';
             for ($i = $begin_hour; $i < $end_hour; $i++) {
                 $from = ($i < 10 ? '0' : '') . $i;
                 $timeheader .= "<th width='{$colsize}%' colspan='4'>" . $from . ":00</th>";
                 $colnumber += 4;
             }
             // Print Headers
             echo "<tr class='tab_bg_1'><th colspan='{$colnumber}'>";
             echo $whoname;
             echo "</th></tr>";
             echo "<tr class='tab_bg_1'><th width='15%'>&nbsp;</th>";
             echo $timeheader;
             echo "</tr>";
             $day_begin = strtotime($realbegin);
             $day_end = strtotime($realend);
             for ($time = $day_begin; $time < $day_end; $time += DAY_TIMESTAMP) {
                 $current_day = date('Y-m-d', $time);
                 echo "<tr><th>" . Html::convDate($current_day) . "</th>";
                 $begin_quarter = $begin_hour * 4;
                 $end_quarter = $end_hour * 4;
                 for ($i = $begin_quarter; $i < $end_quarter; $i++) {
                     $begin_time = date("Y-m-d H:i:s", strtotime($current_day) + $i * HOUR_TIMESTAMP / 4);
                     $end_time = date("Y-m-d H:i:s", strtotime($current_day) + ($i + 1) * HOUR_TIMESTAMP / 4);
                     // Init activity interval
                     $begin_act = $end_time;
                     $end_act = $begin_time;
                     reset($interv);
                     while ($data = current($interv)) {
                         if ($data["begin"] >= $begin_time && $data["end"] <= $end_time) {
                             // In
                             if ($begin_act > $data["begin"]) {
                                 $begin_act = $data["begin"];
                             }
                             if ($end_act < $data["end"]) {
                                 $end_act = $data["end"];
                             }
                             unset($interv[key($interv)]);
                         } else {
                             if ($data["begin"] < $begin_time && $data["end"] > $end_time) {
                                 // Through
                                 $begin_act = $begin_time;
                                 $end_act = $end_time;
                                 next($interv);
                             } else {
                                 if ($data["begin"] >= $begin_time && $data["begin"] < $end_time) {
                                     // Begin
                                     if ($begin_act > $data["begin"]) {
                                         $begin_act = $data["begin"];
                                     }
                                     $end_act = $end_time;
                                     next($interv);
                                 } else {
                                     if ($data["end"] > $begin_time && $data["end"] <= $end_time) {
                                         //End
                                         $begin_act = $begin_time;
                                         if ($end_act < $data["end"]) {
                                             $end_act = $data["end"];
                                         }
                                         unset($interv[key($interv)]);
                                     } else {
                                         // Defautl case
                                         next($interv);
                                     }
                                 }
                             }
                         }
                     }
                     if ($begin_act < $end_act) {
                         if ($begin_act <= $begin_time && $end_act >= $end_time) {
                             // Activity in quarter
                             echo "<td class='notavailable'>&nbsp;</td>";
                         } else {
                             // Not all the quarter
                             if ($begin_act <= $begin_time) {
                                 echo "<td class='partialavailableend'>&nbsp;</td>";
                             } else {
                                 echo "<td class='partialavailablebegin'>&nbsp;</td>";
                             }
                         }
                     } else {
                         // No activity
                         echo "<td class='available'>&nbsp;</td>";
                     }
                 }
                 echo "</tr>";
             }
             echo "<tr class='tab_bg_1'><td colspan='{$colnumber}'>&nbsp;</td></tr>";
             echo "</table></div>";
         }
     }
     echo "<div><table class='tab_cadre'>";
     echo "<tr class='tab_bg_1'>";
     echo "<th>" . __('Caption') . "</th>";
     echo "<td class='available' colspan=8>" . __('Available') . "</td>";
     echo "<td class='notavailable' colspan=8>" . __('Unavailable') . "</td>";
     echo "</tr>";
     echo "</table></div>";
 }
예제 #3
0
 /**
  * Transfer task categories for specified tickets
  *
  * @since version 0.83
  *
  * @param $itemtype  itemtype : Problem / Ticket
  * @param $ID        original ticket ID
  * @param $newID     new ticket ID
  **/
 function transferTaskCategory($itemtype, $ID, $newID)
 {
     global $DB;
     switch ($itemtype) {
         case 'Ticket':
             $table = 'glpi_tickettasks';
             $field = 'tickets_id';
             $task = new TicketTask();
             break;
         case 'Problem':
             $table = 'glpi_problemtasks';
             $field = 'problems_id';
             $task = new ProblemTask();
             break;
     }
     $query = "SELECT *\n                FROM `{$table}`\n                WHERE `{$field}` = '{$ID}'";
     if ($result = $DB->query($query)) {
         if ($DB->numrows($result) != 0) {
             while ($data = $DB->fetch_assoc($result)) {
                 $input = array();
                 if ($data['taskcategories_id'] > 0) {
                     $categ = new TaskCategory();
                     if ($categ->getFromDB($data['taskcategories_id'])) {
                         $inputcat['entities_id'] = $this->to;
                         $inputcat['completename'] = addslashes($categ->fields['completename']);
                         $catid = $categ->findID($inputcat);
                         if ($catid < 0) {
                             $catid = $categ->import($inputcat);
                         }
                         $input['id'] = $data['id'];
                         $input[$field] = $ID;
                         $input['taskcategories_id'] = $catid;
                         $task->update($input);
                     }
                 }
             }
         }
     }
 }
예제 #4
0
 function getSearchOptions()
 {
     $tab = array();
     $tab += $this->getSearchOptionsMain();
     $tab[63]['table'] = 'glpi_items_problems';
     $tab[63]['field'] = 'id';
     $tab[63]['name'] = _x('quantity', 'Number of items');
     $tab[63]['forcegroupby'] = true;
     $tab[63]['usehaving'] = true;
     $tab[63]['datatype'] = 'count';
     $tab[63]['massiveaction'] = false;
     $tab[63]['joinparams'] = array('jointype' => 'child');
     $tab[13]['table'] = 'glpi_items_problems';
     $tab[13]['field'] = 'items_id';
     $tab[13]['name'] = _n('Associated element', 'Associated elements', Session::getPluralNumber());
     $tab[13]['datatype'] = 'specific';
     $tab[13]['comments'] = true;
     $tab[13]['nosort'] = true;
     $tab[13]['nosearch'] = true;
     $tab[13]['additionalfields'] = array('itemtype');
     $tab[13]['joinparams'] = array('jointype' => 'child');
     $tab[13]['forcegroupby'] = true;
     $tab[13]['massiveaction'] = false;
     $tab[131]['table'] = 'glpi_items_problems';
     $tab[131]['field'] = 'itemtype';
     $tab[131]['name'] = _n('Associated item type', 'Associated item types', Session::getPluralNumber());
     $tab[131]['datatype'] = 'itemtypename';
     $tab[131]['itemtype_list'] = 'ticket_types';
     $tab[131]['nosort'] = true;
     $tab[131]['additionalfields'] = array('itemtype');
     $tab[131]['joinparams'] = array('jointype' => 'child');
     $tab[131]['forcegroupby'] = true;
     $tab[131]['massiveaction'] = false;
     $tab += $this->getSearchOptionsActors();
     $tab['analysis'] = __('Analysis');
     $tab[60]['table'] = $this->getTable();
     $tab[60]['field'] = 'impactcontent';
     $tab[60]['name'] = __('Impacts');
     $tab[60]['massiveaction'] = false;
     $tab[60]['datatype'] = 'text';
     $tab[61]['table'] = $this->getTable();
     $tab[61]['field'] = 'causecontent';
     $tab[61]['name'] = __('Causes');
     $tab[61]['massiveaction'] = false;
     $tab[61]['datatype'] = 'text';
     $tab[62]['table'] = $this->getTable();
     $tab[62]['field'] = 'symptomcontent';
     $tab[62]['name'] = __('Symptoms');
     $tab[62]['massiveaction'] = false;
     $tab[62]['datatype'] = 'text';
     $tab += Notepad::getSearchOptionsToAdd();
     $tab += ProblemTask::getSearchOptionsToAdd();
     $tab += $this->getSearchOptionsSolution();
     $tab += $this->getSearchOptionsStats();
     $tab += ProblemCost::getSearchOptionsToAdd();
     $tab['ticket'] = Ticket::getTypeName(Session::getPluralNumber());
     $tab[141]['table'] = 'glpi_problems_tickets';
     $tab[141]['field'] = 'id';
     $tab[141]['name'] = _x('quantity', 'Number of tickets');
     $tab[141]['forcegroupby'] = true;
     $tab[141]['usehaving'] = true;
     $tab[141]['datatype'] = 'count';
     $tab[141]['massiveaction'] = false;
     $tab[141]['joinparams'] = array('jointype' => 'child');
     return $tab;
 }