Inheritance: extends CommonDBTM
 /**
  * Find a user. Look for login OR firstname + lastname OR lastname + firstname
  *
  * @param value the user to look for
  * @param entity the entity where the user should have right
  *
  * @return the user ID if found or ''
  **/
 private static function findUser($value, $entity)
 {
     global $DB;
     $sql = "SELECT `id`\n              FROM `glpi_users`\n              WHERE LOWER(`name`) = '" . strtolower($value) . "'\n                 OR (CONCAT(LOWER(`realname`),' ',LOWER(`firstname`)) = '" . strtolower($value) . "'\n                    OR CONCAT(LOWER(`firstname`),' ',LOWER(`realname`)) = '" . strtolower($value) . "')";
     $result = $DB->query($sql);
     if ($DB->numrows($result) > 0) {
         //check if user has right on the current entity
         $ID = $DB->result($result, 0, "id");
         $entities = Profile_User::getUserEntities($ID, true);
         if (in_array($entity, $entities)) {
             return $ID;
         }
         return self::DROPDOWN_EMPTY_VALUE;
     }
     return self::DROPDOWN_EMPTY_VALUE;
 }
Example #2
0
GLPI is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

GLPI is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with GLPI. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/
/** @file
* @brief
*/
include '../inc/includes.php';
Session::checkCentralAccess();
$profile = new Profile();
$right = new Profile_User();
$user = new User();
if (isset($_POST["add"])) {
    $right->check(-1, CREATE, $_POST);
    if ($right->add($_POST)) {
        Event::log($_POST["users_id"], "users", 4, "setup", sprintf(__('%s adds a user to an entity'), $_SESSION["glpiname"]));
    }
    Html::back();
}
Html::displayErrorAndDie("lost");
    $data_fin = $_REQUEST['date2'];
} else {
    $data_ini = date("Y-01-01");
    $data_fin = date("Y-m-d");
}
# entity
$sql_e = "SELECT value FROM glpi_plugin_dashboard_config WHERE name = 'entity' AND users_id = " . $_SESSION['glpiID'] . "";
$result_e = $DB->query($sql_e);
$sel_ent = $DB->result($result_e, 0, 'value');
//select entity
if ($sel_ent == '' || $sel_ent == -1) {
    $query_ent1 = "\n\tSELECT entities_id\n\tFROM glpi_users\n\tWHERE id = " . $_SESSION['glpiID'] . " ";
    $res_ent1 = $DB->query($query_ent1);
    $user_ent = $DB->result($res_ent1, 0, 'entities_id');
    //get all user entities
    $entities = Profile_User::getUserEntities($_SESSION['glpiID'], true);
    $entities[] = $user_ent;
    $ent = implode(",", $entities);
    $entidade = "AND glpi_tickets.entities_id IN (" . $ent . ") ";
    $entidade1 = "";
} else {
    $entidade = "AND glpi_tickets.entities_id IN (" . $sel_ent . ") ";
}
?>

<html> 
<head>
<title> GLPI - <?php 
echo __('Tickets', 'dashboard') . '  ' . __('by SLAs', 'dashboard');
?>
 </title>
Example #4
0
 function cleanDBonPurge()
 {
     global $DB;
     $gpr = new ProfileRight();
     $gpr->cleanDBonItemDelete($this->getType(), $this->fields['id']);
     $gpu = new Profile_User();
     $gpu->cleanDBonItemDelete($this->getType(), $this->fields['id']);
     Rule::cleanForItemAction($this);
     // PROFILES and UNIQUE_PROFILE in RuleMailcollector
     Rule::cleanForItemCriteria($this, 'PROFILES');
     Rule::cleanForItemCriteria($this, 'UNIQUE_PROFILE');
     $gki = new KnowbaseItem_Profile();
     $gki->cleanDBonItemDelete($this->getType(), $this->fields['id']);
     $gr = new Profile_Reminder();
     $gr->cleanDBonItemDelete($this->getType(), $this->fields['id']);
 }
Example #5
0
 function showForm($ID, $options = array())
 {
     global $DB, $CFG_GLPI, $LANG;
     $canupdate = haveRight('update_ticket', '1');
     $canpriority = haveRight('update_priority', '1');
     $showuserlink = 0;
     if (haveRight('user', 'r')) {
         $showuserlink = 1;
     }
     if ($ID > 0) {
         $this->check($ID, 'r');
     } else {
         // Create item
         $this->check(-1, 'w', $options);
     }
     $this->showTabs($options);
     $canupdate_descr = $canupdate || $this->fields['status'] == 'new' && $this->isUser(self::REQUESTER, getLoginUserID()) && $this->numberOfFollowups() == 0 && $this->numberOfTasks() == 0;
     if (!$ID) {
         //Get all the user's entities
         $all_entities = Profile_User::getUserEntities($options["_users_id_requester"], true);
         $this->userentities = array();
         //For each user's entity, check if the technician which creates the ticket have access to it
         foreach ($all_entities as $tmp => $ID_entity) {
             if (haveAccessToEntity($ID_entity)) {
                 $this->userentities[] = $ID_entity;
             }
         }
         $this->countentitiesforuser = count($this->userentities);
         if ($this->countentitiesforuser > 0 && !in_array($this->fields["entities_id"], $this->userentities)) {
             // If entity is not in the list of user's entities,
             // then use as default value the first value of the user's entites list
             $this->fields["entities_id"] = $this->userentities[0];
         }
     }
     echo "<form method='post' name='form_ticket' enctype='multipart/form-data' action='" . $CFG_GLPI["root_doc"] . "/front/ticket.form.php'>";
     echo "<div class='spaced' id='tabsbody'>";
     echo "<table class='tab_cadre_fixe'>";
     // Optional line
     $ismultientities = isMultiEntitiesMode();
     echo '<tr><th colspan="4">';
     if ($ID) {
         echo $this->getTypeName() . " - " . $LANG['common'][2] . " {$ID} ";
         if ($ismultientities) {
             echo "(" . Dropdown::getDropdownName('glpi_entities', $this->fields['entities_id']) . ")";
         }
     } else {
         if ($ismultientities) {
             echo $LANG['job'][46] . "&nbsp;:&nbsp;" . Dropdown::getDropdownName("glpi_entities", $this->fields['entities_id']);
         } else {
             echo $LANG['job'][13];
         }
     }
     echo '</th></tr>';
     echo "<tr>";
     echo "<th class='left' colspan='2'>";
     echo "<table>";
     echo "<tr>";
     echo "<td><span class='tracking_small'>" . $LANG['joblist'][11] . "&nbsp;: </span></td>";
     echo "<td>";
     $date = $this->fields["date"];
     if (!$ID) {
         $date = date("Y-m-d H:i:s");
     }
     if ($canupdate) {
         showDateTimeFormItem("date", $date, 1, false);
     } else {
         echo convDateTime($date);
     }
     echo "</td></tr>";
     if ($ID) {
         echo "<tr><td><span class='tracking_small'>" . $LANG['common'][95] . " &nbsp;:</span></td><td>";
         if ($canupdate) {
             User::dropdown(array('name' => 'users_id_recipient', 'value' => $this->fields["users_id_recipient"], 'entity' => $this->fields["entities_id"], 'right' => 'all'));
         } else {
             echo getUserName($this->fields["users_id_recipient"], $showuserlink);
         }
         echo "</td></tr>";
     }
     echo "</table>";
     echo "</th>";
     echo "<th class='left' colspan='2'>";
     echo "<table>";
     if ($ID) {
         echo "<tr><td><span class='tracking_small'>" . $LANG['common'][26] . "&nbsp;:</span></td>";
         echo "<td><span class='tracking_small'>" . convDateTime($this->fields["date_mod"]) . "\n";
         if ($this->fields['users_id_lastupdater'] > 0) {
             echo $LANG['common'][95] . "&nbsp;";
             echo getUserName($this->fields["users_id_lastupdater"], $showuserlink);
         }
         echo "</span>";
         echo "</td></tr>";
     }
     // SLA
     echo "<tr>";
     echo "<td><span class='tracking_small'>" . $LANG['sla'][5] . "&nbsp;: </span></td>";
     echo "<td>";
     if ($ID) {
         if ($this->fields["slas_id"] > 0) {
             echo "<span class='tracking_small'>&nbsp;";
             echo convDateTime($this->fields["due_date"]) . "</span>";
             echo "</td></tr><tr><td><span class='tracking_small'>" . $LANG['sla'][1] . "&nbsp;:</span></td>";
             echo "<td><span class='tracking_small'>";
             echo Dropdown::getDropdownName("glpi_slas", $this->fields["slas_id"]);
             $commentsla = "";
             $slalevel = new SlaLevel();
             if ($slalevel->getFromDB($this->fields['slalevels_id'])) {
                 $commentsla .= '<strong>' . $LANG['sla'][6] . "&nbsp;:&nbsp;</strong>" . $slalevel->getName() . '<br><br>';
             }
             $nextaction = new SlaLevel_Ticket();
             if ($nextaction->getFromDBForTicket($this->fields["id"])) {
                 $commentsla .= '<strong>' . $LANG['sla'][8] . "&nbsp;:&nbsp;</strong>" . convDateTime($nextaction->fields['date']) . '<br>';
                 if ($slalevel->getFromDB($nextaction->fields['slalevels_id'])) {
                     $commentsla .= '<strong>' . $LANG['sla'][6] . "&nbsp;:&nbsp;</strong>" . $slalevel->getName() . '<br>';
                 }
             }
             $slaoptions = array();
             if (haveRight('config', 'r')) {
             }
             $slaoptions['link'] = getItemTypeFormURL('SLA') . "?id=" . $this->fields["slas_id"];
             showToolTip($commentsla, $slaoptions);
             if ($canupdate) {
                 echo "&nbsp;<input type='submit' class='submit' name='sla_delete' value='" . $LANG['sla'][7] . "'>";
             }
             echo "</span>";
         } else {
             showDateTimeFormItem("due_date", $this->fields["due_date"], 1, false, $canupdate);
         }
     } else {
         // New Ticket
         if ($this->fields["due_date"] == 'NULL') {
             $this->fields["due_date"] = '';
         }
         showDateTimeFormItem("due_date", $this->fields["due_date"], 1, false, $canupdate);
         /*         echo $LANG['choice'][2]." ".$LANG['sla'][1]." : ";
                  Dropdown::show('Sla',array('entity' => $this->fields["entities_id"],
                                             'value' =>$this->fields["slas_id"]));*/
     }
     echo "</td></tr>";
     if ($ID) {
         switch ($this->fields["status"]) {
             case 'closed':
                 echo "<tr>";
                 echo "<td><span class='tracking_small'>" . $LANG['joblist'][12] . "&nbsp;: </span></td>";
                 echo "<td>";
                 showDateTimeFormItem("closedate", $this->fields["closedate"], 1, false, $canupdate);
                 echo "</td></tr>";
                 break;
             case 'solved':
                 echo "<tr>";
                 echo "<td><span class='tracking_small'>" . $LANG['joblist'][14] . "&nbsp;: </span></td>";
                 echo "<td>";
                 showDateTimeFormItem("solvedate", $this->fields["solvedate"], 1, false, $canupdate);
                 echo "</td></tr>";
                 break;
         }
     }
     echo "</table>";
     echo "</th></tr>";
     echo "</table>";
     if (!$ID) {
         $this->showActorsPartForm($ID, $options);
     }
     echo "<table  class='tab_cadre_fixe'>";
     echo "<tr class='tab_bg_1'>";
     echo "<th width='10%'>" . $LANG['joblist'][0] . "&nbsp;: </th>";
     echo "<td width='40%'>";
     if ($canupdate) {
         self::dropdownStatus("status", $this->fields["status"], 2);
         // Allowed status
     } else {
         echo self::getStatus($this->fields["status"]);
     }
     echo "</td>";
     echo "<th>" . $LANG['common'][17] . "&nbsp;: </th>";
     echo "<td >";
     // Permit to set type when creating ticket without update right
     if ($canupdate || !$ID) {
         self::dropdownType('type', $this->fields["type"]);
     } else {
         echo self::getTicketTypeName($this->fields["type"]);
     }
     echo "</td>";
     echo "</tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<th>" . $LANG['joblist'][29] . "&nbsp;: </th>";
     echo "<td>";
     if ($canupdate && $canpriority || !$ID || $canupdate_descr) {
         // Only change during creation OR when allowed to change priority OR when user is the creator
         $idurgency = self::dropdownUrgency("urgency", $this->fields["urgency"]);
     } else {
         $idurgency = "value_urgency" . mt_rand();
         echo "<input id='{$idurgency}' type='hidden' name='urgency' value='" . $this->fields["urgency"] . "'>";
         echo self::getUrgencyName($this->fields["urgency"]);
     }
     echo "</td>";
     echo "<th>" . $LANG['common'][36] . "&nbsp;: </th>";
     echo "<td >";
     // Permit to set category when creating ticket without update right
     if ($canupdate || !$ID || $canupdate_descr) {
         $opt = array('value' => $this->fields["ticketcategories_id"], 'entity' => $this->fields["entities_id"]);
         if ($_SESSION["glpiactiveprofile"]["interface"] == "helpdesk") {
             $opt['condition'] = '`is_helpdeskvisible`=1';
         }
         if ($ID && $CFG_GLPI["is_ticket_category_mandatory"]) {
             $opt['display_emptychoice'] = false;
         }
         Dropdown::show('TicketCategory', $opt);
     } else {
         echo Dropdown::getDropdownName("glpi_ticketcategories", $this->fields["ticketcategories_id"]);
     }
     echo "</td>";
     echo "</tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<th>" . $LANG['joblist'][30] . "&nbsp;: </th>";
     echo "<td>";
     if ($canupdate) {
         $idimpact = self::dropdownImpact("impact", $this->fields["impact"]);
     } else {
         echo self::getImpactName($this->fields["impact"]);
     }
     echo "</td>";
     echo "<th class='left' rowspan='2'>" . $LANG['document'][14] . "&nbsp;: </th>";
     echo "<td rowspan='2'>";
     // Select hardware on creation or if have update right
     if ($canupdate || !$ID || $canupdate_descr) {
         if ($ID) {
             if ($this->fields['itemtype'] && class_exists($this->fields['itemtype']) && $this->fields["items_id"]) {
                 $item = new $this->fields['itemtype']();
                 if ($item->can($this->fields["items_id"], 'r')) {
                     echo $item->getTypeName() . " - " . $item->getLink(true);
                 } else {
                     echo $item->getTypeName() . " " . $item->getNameID();
                 }
             }
         }
         $dev_user_id = 0;
         if (!$ID) {
             $dev_user_id = $options['_users_id_requester'];
         } else {
             if (isset($this->users[self::REQUESTER]) && count($this->users[self::REQUESTER]) == 1) {
                 foreach ($this->users[self::REQUESTER] as $user_id_single) {
                     $dev_user_id = $user_id_single['users_id'];
                 }
             }
         }
         if ($dev_user_id > 0) {
             self::dropdownMyDevices($dev_user_id, $this->fields["entities_id"], $this->fields["itemtype"], $this->fields["items_id"]);
         }
         self::dropdownAllDevices("itemtype", $this->fields["itemtype"], $this->fields["items_id"], 1, $this->fields["entities_id"]);
     } else {
         if ($ID && $this->fields['itemtype'] && class_exists($this->fields['itemtype'])) {
             $item = new $this->fields['itemtype']();
             $item->getFromDB($this->fields['items_id']);
             echo $item->getTypeName() . " - " . $item->getNameID();
         } else {
             echo $LANG['help'][30];
         }
     }
     echo "</td>";
     echo "</tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<th class='left'>" . $LANG['joblist'][2] . "&nbsp;: </th>";
     echo "<td>";
     if ($canupdate && $canpriority) {
         $idpriority = self::dropdownPriority("priority", $this->fields["priority"], false, true);
         $idajax = 'change_priority_' . mt_rand();
         echo "&nbsp;<span id='{$idajax}' style='display:none'></span>";
     } else {
         $idajax = 'change_priority_' . mt_rand();
         $idpriority = 0;
         echo "<span id='{$idajax}'>" . self::getPriorityName($this->fields["priority"]) . "</span>";
     }
     if ($canupdate) {
         $params = array('urgency' => '__VALUE0__', 'impact' => '__VALUE1__', 'priority' => $idpriority);
         ajaxUpdateItemOnSelectEvent(array($idurgency, $idimpact), $idajax, $CFG_GLPI["root_doc"] . "/ajax/priority.php", $params);
     }
     echo "</td>";
     echo "</tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<th class='left'>" . $LANG['job'][44] . "&nbsp;: </th>";
     echo "<td>";
     if ($canupdate) {
         Dropdown::show('RequestType', array('value' => $this->fields["requesttypes_id"]));
     } else {
         echo Dropdown::getDropdownName('glpi_requesttypes', $this->fields["requesttypes_id"]);
     }
     echo "</td>";
     // Display validation state
     echo "<th>";
     if (!$ID) {
         echo $LANG['validation'][26] . "&nbsp;:&nbsp;";
     } else {
         echo $LANG['validation'][0] . "&nbsp;:&nbsp;";
     }
     echo "</th>";
     echo "<td>";
     if (!$ID) {
         User::dropdown(array('name' => "_add_validation", 'entity' => $this->fields['entities_id'], 'right' => 'validate_ticket'));
     } else {
         if ($canupdate) {
             TicketValidation::dropdownStatus('global_validation', array('global' => true, 'value' => $this->fields['global_validation']));
         } else {
             echo TicketValidation::getStatus($this->fields['global_validation']);
         }
     }
     echo "</td></tr>";
     // Need comment right to add a followup with the actiontime
     if (!$ID && haveRight("global_add_followups", "1")) {
         echo "<tr class='tab_bg_1'>";
         echo "<th>" . $LANG['job'][20] . "&nbsp;: </th>";
         echo "<td class='left' colspan='3'>";
         Dropdown::showInteger('hour', $options['hour'], 0, 100);
         echo "&nbsp;" . $LANG['job'][21] . "&nbsp;&nbsp;";
         Dropdown::showInteger('minute', $options['minute'], 0, 59);
         echo "&nbsp;" . $LANG['job'][22] . "&nbsp;&nbsp;";
         echo "</td>";
         echo "</tr>";
     }
     echo '</table>';
     if ($ID) {
         $this->showActorsPartForm($ID, $options);
     }
     echo "<table  class='tab_cadre_fixe'>";
     $view_linked_tickets = $ID || $canupdate;
     echo "<tr class='tab_bg_1'>";
     echo "<th width='10%'>" . $LANG['common'][57] . "&nbsp;:</th>";
     echo "<td width='50%'>";
     if (!$ID || $canupdate_descr) {
         $rand = mt_rand();
         echo "<script type='text/javascript' >\n";
         echo "function showName{$rand}() {\n";
         echo "Ext.get('name{$rand}').setDisplayed('none');";
         $params = array('maxlength' => 250, 'size' => 60, 'name' => 'name', 'data' => rawurlencode($this->fields["name"]));
         ajaxUpdateItemJsCode("viewname{$rand}", $CFG_GLPI["root_doc"] . "/ajax/inputtext.php", $params, false);
         echo "}";
         echo "</script>\n";
         echo "<div id='name{$rand}' class='tracking left' onClick='showName{$rand}()'>\n";
         if (empty($this->fields["name"])) {
             echo $LANG['reminder'][15];
         } else {
             echo $this->fields["name"];
         }
         echo "</div>\n";
         echo "<div id='viewname{$rand}'>\n";
         echo "</div>\n";
         if (!$ID) {
             echo "<script type='text/javascript' >\n\n            showName{$rand}();\n            </script>";
         }
     } else {
         if (empty($this->fields["name"])) {
             echo $LANG['reminder'][15];
         } else {
             echo $this->fields["name"];
         }
     }
     echo "</td>";
     // Permit to add doc when creating a ticket
     if (!$ID) {
         echo "<th>" . $LANG['document'][2] . " (" . Document::getMaxUploadSize() . ")&nbsp;:";
         echo "<img src='" . $CFG_GLPI["root_doc"] . "/pics/aide.png' class='pointer' alt=\"" . $LANG['central'][7] . "\" onclick=\"window.open('" . $CFG_GLPI["root_doc"] . "/front/documenttype.list.php','Help','scrollbars=1,resizable=1,width=1000,height=800')\">";
         echo "</th>";
         echo "<td>";
         echo "<input type='file' name='filename' value=\"\" size='25'></td>";
     } else {
         echo "<th colspan='2'>";
         echo $LANG['document'][20] . '&nbsp;: ' . Document_Item::countForItem($this);
         echo "</th>";
     }
     echo "</tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<th width='10%'>" . $LANG['joblist'][6] . "&nbsp;:&nbsp;</th>";
     echo "<td width='50%'>";
     if (!$ID || $canupdate_descr) {
         // Admin =oui on autorise la modification de la description
         $rand = mt_rand();
         echo "<script type='text/javascript' >\n";
         echo "function showDesc{$rand}() {\n";
         echo "Ext.get('desc{$rand}').setDisplayed('none');";
         $params = array('rows' => 6, 'cols' => 60, 'name' => 'content', 'data' => rawurlencode($this->fields["content"]));
         ajaxUpdateItemJsCode("viewdesc{$rand}", $CFG_GLPI["root_doc"] . "/ajax/textarea.php", $params, false);
         echo "}";
         echo "</script>\n";
         echo "<div id='desc{$rand}' class='tracking' onClick='showDesc{$rand}()'>\n";
         if (!empty($this->fields["content"])) {
             echo nl2br($this->fields["content"]);
         } else {
             echo $LANG['job'][33];
         }
         echo "</div>\n";
         echo "<div id='viewdesc{$rand}'></div>\n";
         if (!$ID) {
             echo "<script type='text/javascript' >\n\n            showDesc{$rand}();\n            </script>";
         }
     } else {
         echo nl2br($this->fields["content"]);
     }
     echo "</td>";
     if ($view_linked_tickets) {
         echo "<th width='10%'>";
         echo $LANG['job'][55];
         if ($canupdate) {
             $rand_linked_ticket = mt_rand();
             echo "&nbsp;&nbsp;<a class='tracking'\n                  onClick=\"Ext.get('linkedticket{$rand_linked_ticket}').setDisplayed('block')\">\n";
             echo $LANG['buttons'][8];
             echo "</a>\n";
         }
         echo '</th>';
         echo "<td>";
         Ticket_Ticket::displayLinkedTicketsTo($ID);
         if ($canupdate) {
             echo "<div style='display:none' id='linkedticket{$rand_linked_ticket}'>";
             Ticket_Ticket::dropdownLinks('_link[link]');
             echo "&nbsp;" . $LANG['job'][38] . "&nbsp;" . $LANG['common'][2] . "&nbsp;:&nbsp;";
             echo "<input type='hidden' name='_link[tickets_id_1]' value='{$ID}'>\n";
             echo "<input type='text' name='_link[tickets_id_2]' value='' size='10'>\n";
             echo "&nbsp;";
             echo "</div>";
         }
         echo "</td>";
     }
     echo "</tr>";
     if (!$ID || $canupdate || $canupdate_descr || haveRight("assign_ticket", "1") || haveRight("steal_ticket", "1")) {
         echo "<tr class='tab_bg_1'>";
         if ($ID) {
             if (haveRight('delete_ticket', 1)) {
                 echo "<td class='tab_bg_2 center' colspan='2'>";
                 echo "<input type='submit' class='submit' name='update' value='" . $LANG['buttons'][7] . "'></td>";
                 echo "<td class='tab_bg_2 center' colspan='2'>";
                 echo "<input type='submit' class='submit' name='delete' value='" . $LANG['buttons'][22] . "'" . addConfirmationOnAction($LANG['common'][50]) . ">";
             } else {
                 echo "<td class='tab_bg_2 center' colspan='4'>";
                 echo "<input type='submit' class='submit' name='update' value='" . $LANG['buttons'][7] . "'>";
             }
         } else {
             echo "<td class='tab_bg_2 center' colspan='2'>";
             echo "<input type='submit' name='add' value=\"" . $LANG['buttons'][8] . "\" class='submit'>";
             echo "</td><td class='tab_bg_2 center' colspan='2'>";
             echo "<input type='button' value=\"" . $LANG['buttons'][16] . "\" class='submit'\n                   onclick=\"window.location='" . $CFG_GLPI["root_doc"] . "/front/ticket.form.php'\">";
         }
         echo "</td></tr>";
     }
     echo "</table>";
     echo "<input type='hidden' name='id' value='{$ID}'>";
     echo "</div>";
     echo "</form>";
     $this->addDivForTabs();
     return true;
 }
Example #6
0
 /**
  * Clone of Ticket::showForm()
  * Change '$this' by '$ticket', 'self' by 'Ticket' and 'parent' by 'Ticket'
  */
 static function getCentral($ID = 0, $options = array())
 {
     global $CFG_GLPI;
     // * Added by plugin survey ticket
     $ticket = new Ticket();
     // * End of adding
     $default_values = Ticket::getDefaultValues();
     // Get default values from posted values on reload form
     if (!isset($options['template_preview'])) {
         if (isset($_POST)) {
             $values = $_POST;
         }
     }
     // Restore saved value or override with page parameter
     $saved = $ticket->restoreInput();
     foreach ($default_values as $name => $value) {
         if (!isset($values[$name])) {
             if (isset($saved[$name])) {
                 $values[$name] = $saved[$name];
             } else {
                 $values[$name] = $value;
             }
         }
     }
     // Default check
     if ($ID > 0) {
         $ticket->check($ID, 'r');
     } else {
         // Create item
         $ticket->check(-1, 'w', $values);
     }
     if (!$ID) {
         $ticket->userentities = array();
         if ($values["_users_id_requester"]) {
             //Get all the user's entities
             $all_entities = Profile_User::getUserEntities($values["_users_id_requester"], true, true);
             //For each user's entity, check if the technician which creates the ticket have access to it
             foreach ($all_entities as $tmp => $ID_entity) {
                 if (Session::haveAccessToEntity($ID_entity)) {
                     $ticket->userentities[] = $ID_entity;
                 }
             }
         }
         $ticket->countentitiesforuser = count($ticket->userentities);
         if ($ticket->countentitiesforuser > 0 && !in_array($ticket->fields["entities_id"], $ticket->userentities)) {
             // If entity is not in the list of user's entities,
             // then use as default value the first value of the user's entites list
             $ticket->fields["entities_id"] = $ticket->userentities[0];
             // Pass to values
             $values['entities_id'] = $ticket->userentities[0];
         }
     }
     if ($values['type'] <= 0) {
         $values['type'] = Entity::getUsedConfig('tickettype', $values['entities_id'], '', Ticket::INCIDENT_TYPE);
     }
     if (!isset($options['template_preview'])) {
         $options['template_preview'] = 0;
     }
     // Load ticket template if available :
     $tt = $ticket->getTicketTemplateToUse($options['template_preview'], $values['type'], $values['itilcategories_id'], $values['entities_id']);
     // Predefined fields from template : reset them
     if (isset($values['_predefined_fields'])) {
         $values['_predefined_fields'] = Toolbox::decodeArrayFromInput($values['_predefined_fields']);
     } else {
         $values['_predefined_fields'] = array();
     }
     // Store predefined fields to be able not to take into account on change template
     // Only manage predefined values on ticket creation
     $predefined_fields = array();
     if (!$ID) {
         if (isset($tt->predefined) && count($tt->predefined)) {
             foreach ($tt->predefined as $predeffield => $predefvalue) {
                 if (isset($default_values[$predeffield])) {
                     // Is always default value : not set
                     // Set if already predefined field
                     // Set if ticket template change
                     if ($values[$predeffield] == $default_values[$predeffield] || isset($values['_predefined_fields'][$predeffield]) && $values[$predeffield] == $values['_predefined_fields'][$predeffield] || isset($values['_tickettemplates_id']) && $values['_tickettemplates_id'] != $tt->getID()) {
                         // Load template data
                         $values[$predeffield] = $predefvalue;
                         $ticket->fields[$predeffield] = $predefvalue;
                         $predefined_fields[$predeffield] = $predefvalue;
                     }
                 }
             }
         } else {
             // No template load : reset predefined values
             if (count($values['_predefined_fields'])) {
                 foreach ($values['_predefined_fields'] as $predeffield => $predefvalue) {
                     if ($values[$predeffield] == $predefvalue) {
                         $values[$predeffield] = $default_values[$predeffield];
                     }
                 }
             }
         }
     }
     // Put ticket template on $values for actors
     $values['_tickettemplate'] = $tt;
     $canupdate = Session::haveRight('update_ticket', '1');
     $canpriority = Session::haveRight('update_priority', '1');
     $canstatus = $canupdate;
     if (in_array($ticket->fields['status'], $ticket->getClosedStatusArray())) {
         $canupdate = false;
     }
     $showuserlink = 0;
     if (Session::haveRight('user', 'r')) {
         $showuserlink = 1;
     }
     if (!$options['template_preview']) {
         $ticket->showTabs($options);
     } else {
         // Add all values to fields of tickets for template preview
         foreach ($values as $key => $val) {
             if (!isset($ticket->fields[$key])) {
                 $ticket->fields[$key] = $val;
             }
         }
     }
     // In percent
     $colsize1 = '13';
     $colsize2 = '29';
     $colsize3 = '13';
     $colsize4 = '45';
     $canupdate_descr = $canupdate || $ticket->fields['status'] == Ticket::INCOMING && $ticket->isUser(CommonITILActor::REQUESTER, Session::getLoginUserID()) && $ticket->numberOfFollowups() == 0 && $ticket->numberOfTasks() == 0;
     if (!$options['template_preview']) {
         echo "<form method='post' name='form_ticket' enctype='multipart/form-data' action='" . $CFG_GLPI["root_doc"] . "/front/ticket.form.php'>";
     }
     echo "<div class='spaced' id='tabsbody'>";
     echo "<table class='tab_cadre_fixe' id='mainformtable'>";
     // Optional line
     $ismultientities = Session::isMultiEntitiesMode();
     echo "<tr class='headerRow'>";
     echo "<th colspan='4'>";
     if ($ID) {
         $text = sprintf(__('%1$s - %2$s'), $ticket->getTypeName(1), sprintf(__('%1$s: %2$s'), __('ID'), $ID));
         if ($ismultientities) {
             $text = sprintf(__('%1$s (%2$s)'), $text, Dropdown::getDropdownName('glpi_entities', $ticket->fields['entities_id']));
         }
         echo $text;
     } else {
         if ($ismultientities) {
             printf(__('The ticket will be added in the entity %s'), Dropdown::getDropdownName("glpi_entities", $ticket->fields['entities_id']));
         } else {
             _e('New ticket');
         }
     }
     echo "</th></tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<th width='{$colsize1}%'>";
     echo $tt->getBeginHiddenFieldText('date');
     if (!$ID) {
         printf(__('%1$s%2$s'), __('Opening date'), $tt->getMandatoryMark('date'));
     } else {
         _e('Opening date');
     }
     echo $tt->getEndHiddenFieldText('date');
     echo "</th>";
     echo "<td width='{$colsize2}%'>";
     echo $tt->getBeginHiddenFieldValue('date');
     $date = $ticket->fields["date"];
     if ($canupdate) {
         Html::showDateTimeFormItem("date", $date, 1, false);
     } else {
         echo Html::convDateTime($date);
     }
     echo $tt->getEndHiddenFieldValue('date', $ticket);
     echo "</td>";
     // SLA
     echo "<th width='{$colsize3}%'>" . $tt->getBeginHiddenFieldText('due_date');
     if (!$ID) {
         printf(__('%1$s%2$s'), __('Due date'), $tt->getMandatoryMark('due_date'));
     } else {
         _e('Due date');
     }
     echo $tt->getEndHiddenFieldText('due_date');
     echo "</th>";
     echo "<td width='{$colsize4}%' class='nopadding'>";
     if ($ID) {
         if ($ticket->fields["slas_id"] > 0) {
             echo "<table width='100%'><tr><td class='nopadding'>";
             echo Html::convDateTime($ticket->fields["due_date"]);
             echo "</td><td class='b'>" . __('SLA') . "</td>";
             echo "<td class='nopadding'>";
             echo Dropdown::getDropdownName("glpi_slas", $ticket->fields["slas_id"]);
             $commentsla = "";
             $slalevel = new SlaLevel();
             if ($slalevel->getFromDB($ticket->fields['slalevels_id'])) {
                 $commentsla .= '<span class="b spaced">' . sprintf(__('%1$s: %2$s'), __('Escalation level'), $slalevel->getName()) . '</span><br>';
             }
             $nextaction = new SlaLevel_Ticket();
             if ($nextaction->getFromDBForTicket($ticket->fields["id"])) {
                 $commentsla .= '<span class="b spaced">' . sprintf(__('Next escalation: %s'), Html::convDateTime($nextaction->fields['date'])) . '</span>';
                 if ($slalevel->getFromDB($nextaction->fields['slalevels_id'])) {
                     $commentsla .= '<span class="b spaced">' . sprintf(__('%1$s: %2$s'), __('Escalation level'), $slalevel->getName()) . '</span>';
                 }
             }
             $slaoptions = array();
             if (Session::haveRight('config', 'r')) {
                 $slaoptions['link'] = Toolbox::getItemTypeFormURL('SLA') . "?id=" . $ticket->fields["slas_id"];
             }
             Html::showToolTip($commentsla, $slaoptions);
             if ($canupdate) {
                 echo "&nbsp;<input type='submit' class='submit' name='sla_delete' value='" . _sx('button', 'Delete permanently') . "'>";
             }
             echo "</td>";
             echo "</tr></table>";
         } else {
             echo "<table><tr><td class='nopadding'>";
             echo $tt->getBeginHiddenFieldValue('due_date');
             Html::showDateTimeFormItem("due_date", $ticket->fields["due_date"], 1, true, $canupdate);
             echo $tt->getEndHiddenFieldValue('due_date', $ticket);
             echo "</td>";
             if ($canupdate) {
                 echo "<td>";
                 echo $tt->getBeginHiddenFieldText('slas_id');
                 echo "<span id='sla_action'>";
                 echo "<a class='vsubmit' " . Html::addConfirmationOnAction(array(__('The assignment of a SLA to a ticket causes the recalculation of the due date.'), __("Escalations defined in the SLA will be triggered under this new date.")), "cleanhide('sla_action');cleandisplay('sla_choice');") . ">" . __('Assign a SLA') . '</a>';
                 echo "</span>";
                 echo "<span id='sla_choice' style='display:none'>";
                 echo "<span  class='b'>" . __('SLA') . "</span>&nbsp;";
                 Sla::dropdown(array('entity' => $ticket->fields["entities_id"], 'value' => $ticket->fields["slas_id"]));
                 echo "</span>";
                 echo $tt->getEndHiddenFieldText('slas_id');
                 echo "</td>";
             }
             echo "</tr></table>";
         }
     } else {
         // New Ticket
         echo "<table><tr><td class='nopadding'>";
         if ($ticket->fields["due_date"] == 'NULL') {
             $ticket->fields["due_date"] = '';
         }
         echo $tt->getBeginHiddenFieldValue('due_date');
         Html::showDateTimeFormItem("due_date", $ticket->fields["due_date"], 1, false, $canupdate);
         echo $tt->getEndHiddenFieldValue('due_date', $ticket);
         echo "</td>";
         if ($canupdate) {
             echo "<td class='nopadding b'>" . $tt->getBeginHiddenFieldText('slas_id');
             printf(__('%1$s%2$s'), __('SLA'), $tt->getMandatoryMark('slas_id'));
             echo $tt->getEndHiddenFieldText('slas_id') . "</td>";
             echo "<td class='nopadding'>" . $tt->getBeginHiddenFieldValue('slas_id');
             Sla::dropdown(array('entity' => $ticket->fields["entities_id"], 'value' => $ticket->fields["slas_id"]));
             echo $tt->getEndHiddenFieldValue('slas_id', $ticket);
             echo "</td>";
         }
         echo "</tr></table>";
     }
     echo "</td></tr>";
     if ($ID) {
         echo "<tr class='tab_bg_1'>";
         echo "<th width='{$colsize1}%'>" . __('By') . "</th>";
         echo "<td width='{$colsize2}%'>";
         if ($canupdate) {
             User::dropdown(array('name' => 'users_id_recipient', 'value' => $ticket->fields["users_id_recipient"], 'entity' => $ticket->fields["entities_id"], 'right' => 'all'));
         } else {
             echo getUserName($ticket->fields["users_id_recipient"], $showuserlink);
         }
         echo "</td>";
         echo "<th width='{$colsize3}%'>" . __('Last update') . "</th>";
         echo "<td width='{$colsize4}%'>";
         if ($ticket->fields['users_id_lastupdater'] > 0) {
             //TRANS: %1$s is the update date, %2$s is the last updater name
             printf(__('%1$s by %2$s'), Html::convDateTime($ticket->fields["date_mod"]), getUserName($ticket->fields["users_id_lastupdater"], $showuserlink));
         }
         echo "</td>";
         echo "</tr>";
     }
     if ($ID && (in_array($ticket->fields["status"], $ticket->getSolvedStatusArray()) || in_array($ticket->fields["status"], $ticket->getClosedStatusArray()))) {
         echo "<tr class='tab_bg_1'>";
         echo "<th width='{$colsize1}%'>" . __('Resolution date') . "</th>";
         echo "<td width='{$colsize2}%'>";
         Html::showDateTimeFormItem("solvedate", $ticket->fields["solvedate"], 1, false, $canupdate);
         echo "</td>";
         if (in_array($ticket->fields["status"], $ticket->getClosedStatusArray())) {
             echo "<th width='{$colsize3}%'>" . __('Close date') . "</th>";
             echo "<td width='{$colsize4}%'>";
             Html::showDateTimeFormItem("closedate", $ticket->fields["closedate"], 1, false, $canupdate);
             echo "</td>";
         } else {
             echo "<td colspan='2'>&nbsp;</td>";
         }
         echo "</tr>";
     }
     if ($ID) {
         echo "</table>";
         echo "<table  class='tab_cadre_fixe' id='mainformtable2'>";
     }
     echo "<tr class='tab_bg_1'>";
     echo "<th width='{$colsize1}%'>" . sprintf(__('%1$s%2$s'), __('Type'), $tt->getMandatoryMark('type')) . "</th>";
     echo "<td width='{$colsize2}%'>";
     // Permit to set type when creating ticket without update right
     if ($canupdate || !$ID) {
         $opt = array('value' => $ticket->fields["type"]);
         /// Auto submit to load template
         if (!$ID) {
             $opt['on_change'] = 'submit()';
         }
         $rand = Ticket::dropdownType('type', $opt);
         if ($ID) {
             $params = array('type' => '__VALUE__', 'entity_restrict' => $ticket->fields['entities_id'], 'value' => $ticket->fields['itilcategories_id'], 'currenttype' => $ticket->fields['type']);
             Ajax::updateItemOnSelectEvent("dropdown_type{$rand}", "show_category_by_type", $CFG_GLPI["root_doc"] . "/ajax/dropdownTicketCategories.php", $params);
         }
     } else {
         echo Ticket::getTicketTypeName($ticket->fields["type"]);
     }
     echo "</td>";
     echo "<th width='{$colsize3}%'>" . sprintf(__('%1$s%2$s'), __('Category'), $tt->getMandatoryMark('itilcategories_id')) . "</th>";
     echo "<td width='{$colsize4}%'>";
     // Permit to set category when creating ticket without update right
     if ($canupdate || !$ID || $canupdate_descr) {
         $opt = array('value' => $ticket->fields["itilcategories_id"], 'entity' => $ticket->fields["entities_id"]);
         if ($_SESSION["glpiactiveprofile"]["interface"] == "helpdesk") {
             $opt['condition'] = "`is_helpdeskvisible`='1' AND ";
         } else {
             $opt['condition'] = '';
         }
         /// Auto submit to load template
         if (!$ID) {
             $opt['on_change'] = 'submit()';
         }
         /// if category mandatory, no empty choice
         /// no empty choice is default value set on ticket creation, else yes
         if (($ID || $values['itilcategories_id']) && $tt->isMandatoryField("itilcategories_id") && $ticket->fields["itilcategories_id"] > 0) {
             $opt['display_emptychoice'] = false;
         }
         switch ($ticket->fields["type"]) {
             case Ticket::INCIDENT_TYPE:
                 $opt['condition'] .= "`is_incident`='1'";
                 break;
             case Ticket::DEMAND_TYPE:
                 $opt['condition'] .= "`is_request`='1'";
                 break;
             default:
                 break;
         }
         echo "<span id='show_category_by_type'>";
         ITILCategory::dropdown($opt);
         echo "</span>";
     } else {
         echo Dropdown::getDropdownName("glpi_itilcategories", $ticket->fields["itilcategories_id"]);
     }
     echo "</td>";
     echo "</tr>";
     if (!$ID) {
         echo "</table>";
         $ticket->showActorsPartForm($ID, $values);
         echo "<table class='tab_cadre_fixe' id='mainformtable3'>";
     }
     echo "<tr class='tab_bg_1'>";
     echo "<th width='{$colsize1}%'>" . $tt->getBeginHiddenFieldText('status');
     printf(__('%1$s%2$s'), __('Status'), $tt->getMandatoryMark('status'));
     echo $tt->getEndHiddenFieldText('status') . "</th>";
     echo "<td width='{$colsize2}%'>";
     echo $tt->getBeginHiddenFieldValue('status');
     if ($canstatus) {
         Ticket::dropdownStatus(array('value' => $ticket->fields["status"], 'showtype' => 'allowed'));
     } else {
         echo Ticket::getStatus($ticket->fields["status"]);
     }
     echo $tt->getEndHiddenFieldValue('status', $ticket);
     echo "</td>";
     echo "<th width='{$colsize3}%'>" . $tt->getBeginHiddenFieldText('requesttypes_id');
     printf(__('%1$s%2$s'), __('Request source'), $tt->getMandatoryMark('requesttypes_id'));
     echo $tt->getEndHiddenFieldText('requesttypes_id') . "</th>";
     echo "<td width='{$colsize4}%'>";
     echo $tt->getBeginHiddenFieldValue('requesttypes_id');
     if ($canupdate) {
         RequestType::dropdown(array('value' => $ticket->fields["requesttypes_id"]));
     } else {
         echo Dropdown::getDropdownName('glpi_requesttypes', $ticket->fields["requesttypes_id"]);
     }
     echo $tt->getEndHiddenFieldValue('requesttypes_id', $ticket);
     echo "</td>";
     echo "</tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<th>" . $tt->getBeginHiddenFieldText('urgency');
     printf(__('%1$s%2$s'), __('Urgency'), $tt->getMandatoryMark('urgency'));
     echo $tt->getEndHiddenFieldText('urgency') . "</th>";
     echo "<td>";
     if ($canupdate && $canpriority || !$ID || $canupdate_descr) {
         // Only change during creation OR when allowed to change priority OR when user is the creator
         echo $tt->getBeginHiddenFieldValue('urgency');
         $idurgency = Ticket::dropdownUrgency(array('value' => $ticket->fields["urgency"]));
         echo $tt->getEndHiddenFieldValue('urgency', $ticket);
     } else {
         $idurgency = "value_urgency" . mt_rand();
         echo "<input id='{$idurgency}' type='hidden' name='urgency' value='" . $ticket->fields["urgency"] . "'>";
         echo Ticket::getUrgencyName($ticket->fields["urgency"]);
     }
     echo "</td>";
     // Display validation state
     echo "<th>";
     if (!$ID) {
         echo $tt->getBeginHiddenFieldText('_add_validation');
         printf(__('%1$s%2$s'), __('Approval request'), $tt->getMandatoryMark('_add_validation'));
         echo $tt->getEndHiddenFieldText('_add_validation');
     } else {
         echo $tt->getBeginHiddenFieldText('global_validation');
         _e('Approval');
         echo $tt->getEndHiddenFieldText('global_validation');
     }
     echo "</th>";
     echo "<td>";
     if (!$ID) {
         echo $tt->getBeginHiddenFieldValue('_add_validation');
         $validation_right = '';
         if ($values['type'] == Ticket::INCIDENT_TYPE && Session::haveRight('create_incident_validation', 1)) {
             $validation_right = 'validate_incident';
         }
         if ($values['type'] == Ticket::DEMAND_TYPE && Session::haveRight('create_request_validation', 1)) {
             $validation_right = 'validate_request';
         }
         if (!empty($validation_right)) {
             User::dropdown(array('name' => "_add_validation", 'entity' => $ticket->fields['entities_id'], 'right' => $validation_right, 'value' => $values['_add_validation']));
         }
         echo $tt->getEndHiddenFieldValue('_add_validation', $ticket);
         if ($tt->isPredefinedField('global_validation')) {
             echo "<input type='hidden' name='global_validation' value='" . $tt->predefined['global_validation'] . "'>";
         }
     } else {
         echo $tt->getBeginHiddenFieldValue('global_validation');
         if ($canupdate) {
             TicketValidation::dropdownStatus('global_validation', array('global' => true, 'value' => $ticket->fields['global_validation']));
         } else {
             echo TicketValidation::getStatus($ticket->fields['global_validation']);
         }
         echo $tt->getEndHiddenFieldValue('global_validation', $ticket);
     }
     echo "</td></tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<th>" . $tt->getBeginHiddenFieldText('impact');
     printf(__('%1$s%2$s'), __('Impact'), $tt->getMandatoryMark('impact'));
     echo $tt->getEndHiddenFieldText('impact') . "</th>";
     echo "<td>";
     echo $tt->getBeginHiddenFieldValue('impact');
     if ($canupdate) {
         $idimpact = Ticket::dropdownImpact(array('value' => $ticket->fields["impact"]));
     } else {
         $idimpact = "value_impact" . mt_rand();
         echo "<input id='{$idimpact}' type='hidden' name='impact' value='" . $ticket->fields["impact"] . "'>";
         echo Ticket::getImpactName($ticket->fields["impact"]);
     }
     echo $tt->getEndHiddenFieldValue('impact', $ticket);
     echo "</td>";
     echo "<th rowspan='2'>" . $tt->getBeginHiddenFieldText('itemtype');
     printf(__('%1$s%2$s'), __('Associated element'), $tt->getMandatoryMark('itemtype'));
     if ($ID && $canupdate) {
         echo "&nbsp;<img title='" . __s('Update') . "' alt='" . __s('Update') . "'\n                      onClick=\"Ext.get('tickethardwareselection{$ID}').setDisplayed('block')\"\n                      class='pointer' src='" . $CFG_GLPI["root_doc"] . "/pics/showselect.png'>";
     }
     echo $tt->getEndHiddenFieldText('itemtype');
     echo "</th>";
     echo "<td rowspan='2'>";
     echo $tt->getBeginHiddenFieldValue('itemtype');
     // Select hardware on creation or if have update right
     if ($canupdate || !$ID || $canupdate_descr) {
         if ($ID) {
             if ($ticket->fields['itemtype'] && ($item = getItemForItemtype($ticket->fields['itemtype'])) && $ticket->fields["items_id"]) {
                 if ($item->can($ticket->fields["items_id"], 'r')) {
                     printf(__('%1$s - %2$s'), $item->getTypeName(), $item->getLink(array('comments' => true)));
                 } else {
                     printf(__('%1$s - %2$s'), $item->getTypeName(), $item->getNameID());
                 }
             }
         }
         $dev_user_id = 0;
         $dev_itemtype = $ticket->fields["itemtype"];
         $dev_items_id = $ticket->fields["items_id"];
         if (!$ID) {
             $dev_user_id = $values['_users_id_requester'];
             $dev_itemtype = $values["itemtype"];
             $dev_items_id = $values["items_id"];
         } else {
             if (isset($ticket->users[CommonITILActor::REQUESTER]) && count($ticket->users[CommonITILActor::REQUESTER]) == 1) {
                 foreach ($ticket->users[CommonITILActor::REQUESTER] as $user_id_single) {
                     $dev_user_id = $user_id_single['users_id'];
                 }
             }
         }
         if ($ID) {
             echo "<div id='tickethardwareselection{$ID}' style='display:none'>";
         }
         if ($dev_user_id > 0) {
             Ticket::dropdownMyDevices($dev_user_id, $ticket->fields["entities_id"], $dev_itemtype, $dev_items_id);
         }
         Ticket::dropdownAllDevices("itemtype", $dev_itemtype, $dev_items_id, 1, $dev_user_id, $ticket->fields["entities_id"]);
         if ($ID) {
             echo "</div>";
         }
         echo "<span id='item_ticket_selection_information'></span>";
     } else {
         if ($ID && $ticket->fields['itemtype'] && ($item = getItemForItemtype($ticket->fields['itemtype']))) {
             $item->getFromDB($ticket->fields['items_id']);
             printf(__('%1$s - %2$s'), $item->getTypeName(), $item->getNameID());
         } else {
             _e('General');
         }
     }
     echo $tt->getEndHiddenFieldValue('itemtype', $ticket);
     echo "</td>";
     echo "</tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<th>" . sprintf(__('%1$s%2$s'), __('Priority'), $tt->getMandatoryMark('priority')) . "</th>";
     echo "<td>";
     $idajax = 'change_priority_' . mt_rand();
     if ($canupdate && $canpriority && !$tt->isHiddenField('priority')) {
         $idpriority = Ticket::dropdownPriority(array('value' => $ticket->fields["priority"], 'withmajor' => true));
         echo "&nbsp;<span id='{$idajax}' style='display:none'></span>";
     } else {
         $idpriority = 0;
         echo "<span id='{$idajax}'>" . Ticket::getPriorityName($ticket->fields["priority"]) . "</span>";
     }
     if ($canupdate || $canupdate_descr) {
         $params = array('urgency' => '__VALUE0__', 'impact' => '__VALUE1__', 'priority' => $idpriority);
         Ajax::updateItemOnSelectEvent(array($idurgency, $idimpact), $idajax, $CFG_GLPI["root_doc"] . "/ajax/priority.php", $params);
     }
     echo "</td>";
     echo "</tr>";
     echo "<tr class='tab_bg_1'>";
     // Need comment right to add a followup with the actiontime
     if (!$ID && Session::haveRight("global_add_followups", "1")) {
         echo "<th>" . $tt->getBeginHiddenFieldText('actiontime');
         printf(__('%1$s%2$s'), __('Total duration'), $tt->getMandatoryMark('actiontime'));
         echo $tt->getEndHiddenFieldText('actiontime') . "</th>";
         echo "<td>";
         echo $tt->getBeginHiddenFieldValue('actiontime');
         Dropdown::showTimeStamp('actiontime', array('value' => $values['actiontime'], 'addfirstminutes' => true));
         echo $tt->getEndHiddenFieldValue('actiontime', $ticket);
         echo "</td>";
     } else {
         echo "<th></th><td></td>";
     }
     echo "<th>" . $tt->getBeginHiddenFieldText('locations_id');
     printf(__('%1$s%2$s'), __('Location'), $tt->getMandatoryMark('locations_id'));
     echo $tt->getEndHiddenFieldText('locations_id') . "</th>";
     echo "<td>";
     echo $tt->getBeginHiddenFieldValue('locations_id');
     if ($canupdate) {
         Location::dropdown(array('value' => $ticket->fields['locations_id'], 'entity' => $ticket->fields['entities_id']));
     } else {
         echo Dropdown::getDropdownName('glpi_locations', $ticket->fields["locations_id"]);
     }
     echo $tt->getEndHiddenFieldValue('locations_id', $ticket);
     echo "</td></tr>";
     echo "</table>";
     if ($ID) {
         $values['canupdate'] = $canupdate;
         $ticket->showActorsPartForm($ID, $values);
     }
     $view_linked_tickets = $ID || $canupdate;
     echo "<table class='tab_cadre_fixe' id='mainformtable4'>";
     echo "<tr class='tab_bg_1'>";
     echo "<th width='{$colsize1}%'>" . $tt->getBeginHiddenFieldText('name');
     printf(__('%1$s%2$s'), __('Title'), $tt->getMandatoryMark('name'));
     echo $tt->getEndHiddenFieldText('name') . "</th>";
     echo "<td width='" . (100 - $colsize1) . "%' colspan='3'>";
     if (!$ID || $canupdate_descr) {
         echo $tt->getBeginHiddenFieldValue('name');
         $rand = mt_rand();
         echo "<script type='text/javascript' >\n";
         echo "function showName{$rand}() {\n";
         echo "Ext.get('name{$rand}').setDisplayed('none');";
         $params = array('maxlength' => 250, 'size' => 90, 'name' => 'name', 'data' => rawurlencode($ticket->fields["name"]));
         Ajax::updateItemJsCode("viewname{$rand}", $CFG_GLPI["root_doc"] . "/ajax/inputtext.php", $params);
         echo "}";
         echo "</script>\n";
         echo "<div id='name{$rand}' class='tracking left' onClick='showName{$rand}()'>\n";
         if (empty($ticket->fields["name"])) {
             _e('Without title');
         } else {
             echo $ticket->fields["name"];
         }
         echo "</div>\n";
         echo "<div id='viewname{$rand}'>\n";
         echo "</div>\n";
         if (!$ID) {
             echo "<script type='text/javascript' >\n\n            showName{$rand}();\n            </script>";
         }
         echo $tt->getEndHiddenFieldValue('name', $ticket);
     } else {
         if (empty($ticket->fields["name"])) {
             _e('Without title');
         } else {
             echo $ticket->fields["name"];
         }
     }
     echo "</td>";
     echo "</tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<th width='{$colsize1}%'>" . $tt->getBeginHiddenFieldText('content');
     printf(__('%1$s%2$s'), __('Description'), $tt->getMandatoryMark('content'));
     echo $tt->getEndHiddenFieldText('content') . "</th>";
     echo "<td width='" . (100 - $colsize1) . "%' colspan='3'>";
     // * Added by plugin surveyticket
     $psTicketTemplate = new PluginSurveyticketTicketTemplate();
     $psSurvey = new PluginSurveyticketSurvey();
     $plugin_surveyticket_surveys_id = 0;
     $a_tickettemplates = current($psTicketTemplate->find("`tickettemplates_id`='" . $tt->fields['id'] . "'\n                                                      AND `type`='" . $values['type'] . "'\n                                                      AND `is_central`='1'"));
     if (isset($a_tickettemplates['plugin_surveyticket_surveys_id'])) {
         $psSurvey = new PluginSurveyticketSurvey();
         $psSurvey->getFromDB($a_tickettemplates['plugin_surveyticket_surveys_id']);
         if ($psSurvey->fields['is_active'] == 1) {
             $plugin_surveyticket_surveys_id = $a_tickettemplates['plugin_surveyticket_surveys_id'];
             $psSurvey = new PluginSurveyticketSurvey();
             $psSurvey->startSurvey($plugin_surveyticket_surveys_id);
         }
     } else {
         // End of adding by plugin
         if (!$ID || $canupdate_descr) {
             // Admin =oui on autorise la modification de la description
             echo $tt->getBeginHiddenFieldValue('content');
             $rand = mt_rand();
             echo "<script type='text/javascript' >\n";
             echo "function showDesc{$rand}() {\n";
             echo "Ext.get('desc{$rand}').setDisplayed('none');";
             $params = array('rows' => 6, 'cols' => 90, 'name' => 'content', 'data' => rawurlencode($ticket->fields["content"]));
             Ajax::updateItemJsCode("viewdesc{$rand}", $CFG_GLPI["root_doc"] . "/ajax/textarea.php", $params);
             echo "}";
             echo "</script>\n";
             echo "<div id='desc{$rand}' class='tracking' onClick='showDesc{$rand}()'>\n";
             if (!empty($ticket->fields["content"])) {
                 echo nl2br($ticket->fields["content"]);
             } else {
                 _e('Empty description');
             }
             echo "</div>\n";
             echo "<div id='viewdesc{$rand}'></div>\n";
             if (!$ID) {
                 echo "<script type='text/javascript' >\n\n            showDesc{$rand}();\n            </script>";
             }
             echo $tt->getEndHiddenFieldValue('content', $ticket);
         } else {
             echo nl2br($ticket->fields["content"]);
         }
         // * Added by plugin surveyticket
     }
     // End of adding by plugin
     echo "</td>";
     echo "</tr>";
     echo "<tr class='tab_bg_1'>";
     // Permit to add doc when creating a ticket
     if (!$ID) {
         echo "<th width='{$colsize1}%'>" . sprintf(__('File (%s)'), Document::getMaxUploadSize());
         echo "<img src='" . $CFG_GLPI["root_doc"] . "/pics/aide.png' class='pointer' alt=\"" . __s('Help') . "\" onclick=\"window.open('" . $CFG_GLPI["root_doc"] . "/front/documenttype.list.php','Help','scrollbars=1,resizable=1,width=1000," . "height=800')\">";
         echo "&nbsp;";
         Ticket::showDocumentAddButton();
         echo "</th>";
         echo "<td width='{$colsize2}%'>";
         echo "<div id='uploadfiles'><input type='file' name='filename[]' size='20'></div></td>";
     } else {
         echo "<th colspan='2'>";
         $docnb = Document_Item::countForItem($ticket);
         echo "<a href=\"" . $ticket->getLinkURL() . "&amp;forcetab=Document_Item\$1\">";
         //TRANS: %d is the document number
         echo sprintf(_n('%d associated document', '%d associated documents', $docnb), $docnb);
         echo "</a></th>";
     }
     if ($view_linked_tickets) {
         echo "<th width='{$colsize3}%'>" . _n('Linked ticket', 'Linked tickets', 2);
         $rand_linked_ticket = mt_rand();
         if ($canupdate) {
             echo "&nbsp;";
             echo "<img onClick=\"Ext.get('linkedticket{$rand_linked_ticket}').setDisplayed('block')\"\n                   title=\"" . __s('Add') . "\" alt=\"" . __s('Add') . "\"\n                   class='pointer' src='" . $CFG_GLPI["root_doc"] . "/pics/add_dropdown.png'>";
         }
         echo '</th>';
         echo "<td width='{$colsize4}%'>";
         if ($canupdate) {
             echo "<div style='display:none' id='linkedticket{$rand_linked_ticket}'>";
             Ticket_Ticket::dropdownLinks('_link[link]', isset($values["_link"]) ? $values["_link"]['link'] : '');
             printf(__('%1$s: %2$s'), __('Ticket'), __('ID'));
             echo "<input type='hidden' name='_link[tickets_id_1]' value='{$ID}'>\n";
             echo "<input type='text' name='_link[tickets_id_2]'\n                   value='" . (isset($values["_link"]) ? $values["_link"]['tickets_id_2'] : '') . "'\n                   size='10'>\n";
             echo "&nbsp;";
             echo "</div>";
             if (isset($values["_link"]) && !empty($values["_link"]['tickets_id_2'])) {
                 echo "<script language='javascript'>Ext.get('linkedticket{$rand_linked_ticket}').\n                      setDisplayed('block');</script>";
             }
         }
         Ticket_Ticket::displayLinkedTicketsTo($ID);
         echo "</td>";
     } else {
         echo "<td></td>";
     }
     echo "</tr>";
     if ((!$ID || $canupdate || $canupdate_descr || Session::haveRight("assign_ticket", "1") || Session::haveRight("steal_ticket", "1")) && !$options['template_preview']) {
         echo "<tr class='tab_bg_1'>";
         if ($ID) {
             if (Session::haveRight('delete_ticket', 1)) {
                 echo "<td class='tab_bg_2 center' colspan='2'>";
                 if ($ticket->fields["is_deleted"] == 1) {
                     echo "<input type='submit' class='submit' name='restore' value='" . _sx('button', 'Restore') . "'></td>";
                 } else {
                     echo "<input type='submit' class='submit' name='update' value='" . _sx('button', 'Save') . "'></td>";
                 }
                 echo "<td class='tab_bg_2 center' colspan='2'>";
                 if ($ticket->fields["is_deleted"] == 1) {
                     echo "<input type='submit' class='submit' name='purge' value='" . _sx('button', 'Delete permanently') . "' " . Html::addConfirmationOnAction(__('Confirm the final deletion?')) . ">";
                 } else {
                     echo "<input type='submit' class='submit' name='delete' value='" . _sx('button', 'Put in dustbin') . "'></td>";
                 }
             } else {
                 echo "<td class='tab_bg_2 center' colspan='4'>";
                 echo "<input type='submit' class='submit' name='update' value='" . _sx('button', 'Save') . "'>";
             }
             echo "<input type='hidden' name='_read_date_mod' value='" . $ticket->getField('date_mod') . "'>";
         } else {
             echo "<td class='tab_bg_2 center' colspan='4'>";
             echo "<input type='submit' name='add' value=\"" . _sx('button', 'Add') . "\" class='submit'>";
             if ($tt->isField('id') && $tt->fields['id'] > 0) {
                 echo "<input type='hidden' name='_tickettemplates_id' value='" . $tt->fields['id'] . "'>";
                 echo "<input type='hidden' name='_predefined_fields'\n                      value=\"" . Toolbox::prepareArrayForInput($predefined_fields) . "\">";
             }
         }
     }
     echo "</table>";
     echo "<input type='hidden' name='id' value='{$ID}'>";
     echo "</div>";
     if (!$options['template_preview']) {
         Html::closeForm();
         $ticket->addDivForTabs();
     }
     return true;
 }
 /**
  * @see RuleCollection::prepareInputDataForProcess()
  **/
 function prepareInputDataForProcess($input, $params)
 {
     $input['mailcollector'] = $params['mailcollector'];
     $input['_users_id_requester'] = $params['_users_id_requester'];
     $fields = $this->getFieldsToLookFor();
     //Add needed ticket datas for rules processing
     if (isset($params['ticket']) && is_array($params['ticket'])) {
         foreach ($params['ticket'] as $key => $value) {
             if (in_array($key, $fields) && !isset($input[$key])) {
                 $input[$key] = $value;
             }
         }
     }
     //Add needed headers for rules processing
     if (isset($params['headers']) && is_array($params['headers'])) {
         foreach ($params['headers'] as $key => $value) {
             if (in_array($key, $fields) && !isset($input[$key])) {
                 $input[$key] = $value;
             }
         }
     }
     //Add all user's groups
     if (in_array('groups', $fields)) {
         foreach (Group_User::getUserGroups($input['_users_id_requester']) as $group) {
             $input['GROUPS'][] = $group['id'];
         }
     }
     //Add all user's profiles
     if (in_array('profiles', $fields)) {
         foreach (Profile_User::getForUser($input['_users_id_requester']) as $profile) {
             $input['PROFILES'][$profile['profiles_id']] = $profile['profiles_id'];
         }
     }
     //If the criteria is "user has only one time the profile xxx"
     if (in_array('unique_profile', $fields)) {
         //Get all profiles
         $profiles = Profile_User::getForUser($input['_users_id_requester']);
         foreach ($profiles as $profile) {
             if (Profile_User::haveUniqueRight($input['_users_id_requester'], $profile['profiles_id'])) {
                 $input['UNIQUE_PROFILE'][$profile['profiles_id']] = $profile['profiles_id'];
             }
         }
     }
     //Store the number of profiles of which the user belongs to
     if (in_array('one_profile', $fields)) {
         $profiles = Profile_User::getForUser($input['_users_id_requester']);
         if (count($profiles) == 1) {
             $tmp = array_pop($profiles);
             $input['ONE_PROFILE'] = $tmp['profiles_id'];
         }
     }
     //Store the number of profiles of which the user belongs to
     if (in_array('known_domain', $fields)) {
         if (preg_match("/@(.*)/", $input['from'], $results)) {
             if (Entity::getEntityIDByDomain($results[1]) != -1) {
                 $input['KNOWN_DOMAIN'] = 1;
             } else {
                 $input['KNOWN_DOMAIN'] = 0;
             }
         }
     }
     return $input;
 }
 /**  Show groups of a user
  *
  * @param $user   User object
  **/
 static function showForUser(User $user)
 {
     global $CFG_GLPI;
     $ID = $user->fields['id'];
     if (!Group::canView() || !$user->can($ID, READ)) {
         return false;
     }
     $canedit = $user->can($ID, UPDATE);
     $rand = mt_rand();
     $groups = self::getUserGroups($ID);
     $used = array();
     if (!empty($groups)) {
         foreach ($groups as $data) {
             $used[$data["id"]] = $data["id"];
         }
     }
     if ($canedit) {
         echo "<div class='firstbloc'>";
         echo "<form name='groupuser_form{$rand}' id='groupuser_form{$rand}' method='post'";
         echo " action='" . Toolbox::getItemTypeFormURL('User') . "'>";
         echo "<table class='tab_cadre_fixe'>";
         echo "<tr class='tab_bg_1'><th colspan='6'>" . __('Associate to a group') . "</th></tr>";
         echo "<tr class='tab_bg_2'><td class='center'>";
         echo "<input type='hidden' name='users_id' value='{$ID}'>";
         // All entities "edited user" have access
         $strict_entities = Profile_User::getUserEntities($ID, true);
         // Keep only entities "connected user" have access
         foreach ($strict_entities as $key => $val) {
             if (!Session::haveAccessToEntity($val)) {
                 unset($strict_entities[$key]);
             }
         }
         $nb = countElementsInTableForEntity("glpi_groups", $strict_entities, '`is_usergroup`');
         if ($nb > count($used)) {
             Group::dropdown(array('entity' => $strict_entities, 'used' => $used, 'condition' => '`is_usergroup`'));
             echo "</td><td>" . __('Manager') . "</td><td>";
             Dropdown::showYesNo('is_manager');
             echo "</td><td>" . __('Delegatee') . "</td><td>";
             Dropdown::showYesNo('is_userdelegate');
             echo "</td><td class='tab_bg_2 center'>";
             echo "<input type='submit' name='addgroup' value=\"" . _sx('button', 'Add') . "\"\n                   class='submit'>";
         } else {
             _e('None');
         }
         echo "</td></tr>";
         echo "</table>";
         Html::closeForm();
         echo "</div>";
     }
     echo "<div class='spaced'>";
     if ($canedit && count($used)) {
         $rand = mt_rand();
         Html::openMassiveActionsForm('mass' . __CLASS__ . $rand);
         echo "<input type='hidden' name='users_id' value='" . $user->fields['id'] . "'>";
         $massiveactionparams = array('num_displayed' => count($used), 'container' => 'mass' . __CLASS__ . $rand);
         Html::showMassiveActions($massiveactionparams);
     }
     echo "<table class='tab_cadre_fixehov table-striped table-hover'>";
     $header_begin = "<tr>";
     $header_top = '';
     $header_bottom = '';
     $header_end = '';
     if ($canedit && count($used)) {
         $header_begin .= "<th width='10'>";
         $header_top .= Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand);
         $header_bottom .= Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand);
         $header_end .= "</th>";
     }
     $header_end .= "<th>" . Group::getTypeName(1) . "</th>";
     $header_end .= "<th>" . __('Dynamic') . "</th>";
     $header_end .= "<th>" . __('Manager') . "</th>";
     $header_end .= "<th>" . __('Delegatee') . "</th></tr>";
     echo $header_begin . $header_top . $header_end;
     $group = new Group();
     if (!empty($groups)) {
         Session::initNavigateListItems('Group', sprintf(__('%1$s = %2$s'), User::getTypeName(1), $user->getName()));
         foreach ($groups as $data) {
             if (!$group->getFromDB($data["id"])) {
                 continue;
             }
             Session::addToNavigateListItems('Group', $data["id"]);
             echo "<tr class='tab_bg_1'>";
             if ($canedit && count($used)) {
                 echo "<td width='10'>";
                 Html::showMassiveActionCheckBox(__CLASS__, $data["linkID"]);
                 echo "</td>";
             }
             $link = $data["completename"];
             if ($_SESSION["glpiis_ids_visible"]) {
                 $link = sprintf(__('%1$s (%2$s)'), $link, $data["id"]);
             }
             $href = "<a href='" . $CFG_GLPI["root_doc"] . "/front/group.form.php?id=" . $data["id"] . "'>" . $link . "</a>";
             if ($data["is_dynamic"]) {
                 $href = sprintf(__('%1$s (%2$s)'), $href, "<span class='b'>" . __('D') . "</span>");
             }
             echo "<td>" . $group->getLink() . "</td>";
             echo "<td class='center'>";
             if ($data['is_dynamic']) {
                 echo "<img src='" . $CFG_GLPI["root_doc"] . "/pics/ok.png' width='14' height='14' alt=\"" . __('Dynamic') . "\">";
             }
             echo "<td class='center'>";
             if ($data['is_manager']) {
                 echo "<img src='" . $CFG_GLPI["root_doc"] . "/pics/ok.png' width='14' height='14' alt=\"" . __('Manager') . "\">";
             }
             echo "</td><td class='center'>";
             if ($data['is_userdelegate']) {
                 echo "<img src='" . $CFG_GLPI["root_doc"] . "/pics/ok.png' width='14' height='14' alt=\"" . __('Delegatee') . "\">";
             }
             echo "</td></tr>";
         }
         echo $header_begin . $header_bottom . $header_end;
     } else {
         echo "<tr class='tab_bg_1'>";
         echo "<td colspan='5' class='center'>" . __('None') . "</td></tr>";
     }
     echo "</table>";
     if ($canedit && count($used)) {
         $massiveactionparams['ontop'] = false;
         Html::showMassiveActions($massiveactionparams);
         Html::closeForm();
     }
     echo "</div>";
 }
 /**  Show groups of a user
  *
  * @param $user the user
  **/
 static function showForUser(User $user)
 {
     global $CFG_GLPI, $LANG;
     $ID = $user->fields['id'];
     if (!haveRight("group", "r") || !$user->can($ID, 'r')) {
         return false;
     }
     $canedit = $user->can($ID, 'w');
     $rand = mt_rand();
     $nb_per_line = 3;
     if ($canedit) {
         $headerspan = $nb_per_line * 2;
         echo "<form name='groupuser_form{$rand}' id='groupuser_form{$rand}' method='post'";
         echo " action='" . getItemTypeFormURL('User') . "'>";
     } else {
         $headerspan = $nb_per_line;
     }
     $groups = self::getUserGroups($ID);
     $used = array();
     if (!empty($groups)) {
         foreach ($groups as $data) {
             $used[$data["id"]] = $data["id"];
         }
     }
     if ($canedit) {
         echo "<div class='firstbloc'>";
         echo "<table class='tab_cadre_fixe'>";
         echo "<tr class='tab_bg_1'><th colspan='2'>" . $LANG['setup'][604] . "</th></tr>";
         echo "<tr><td class='tab_bg_2 center'>";
         echo "<input type='hidden' name='users_id' value='{$ID}'>";
         // All entities "edited user" have access
         $strict_entities = Profile_User::getUserEntities($ID, true);
         // Keep only entities "connected user" have access
         foreach ($strict_entities as $key => $val) {
             if (!haveAccessToEntity($val)) {
                 unset($strict_entities[$key]);
             }
         }
         if (countElementsInTableForEntity("glpi_groups", $strict_entities) > count($used)) {
             Dropdown::show('Group', array('entity' => $strict_entities, 'used' => $used));
             echo "</td><td class='tab_bg_2 center'>";
             echo "<input type='submit' name='addgroup' value=\"" . $LANG['buttons'][8] . "\"\n                   class='submit'>";
         } else {
             echo $LANG['common'][49];
         }
         echo "</td></tr>";
         echo "</table></div>";
     }
     echo "<div class='spaced'>";
     echo "<table class='tab_cadre_fixehov'><tr>";
     echo "<th colspan='{$headerspan}'>" . $LANG['Menu'][36] . "&nbsp;(D=" . $LANG['profiles'][29] . ")</th>";
     echo "</tr>";
     if (!empty($groups)) {
         initNavigateListItems('Group', $user->getTypeName() . " = " . $user->getName());
         $i = 0;
         foreach ($groups as $data) {
             addToNavigateListItems('Group', $data["id"]);
             if ($i % $nb_per_line == 0) {
                 if ($i != 0) {
                     echo "</tr>";
                 }
                 echo "<tr class='tab_bg_1'>";
             }
             if ($canedit) {
                 echo "<td width='10'>";
                 $sel = "";
                 if (isset($_GET["select"]) && $_GET["select"] == "all") {
                     $sel = "checked";
                 }
                 echo "<input type='checkbox' name='item[" . $data["linkID"] . "]' value='1' {$sel}>";
                 echo "</td>";
             }
             echo "<td><a href='" . $CFG_GLPI["root_doc"] . "/front/group.form.php?id=" . $data["id"] . "'>" . $data["name"] . ($_SESSION["glpiis_ids_visible"] ? " (" . $data["id"] . ")" : "") . "</a>";
             echo "&nbsp;";
             if ($data["is_dynamic"]) {
                 echo "<strong>&nbsp;(D)</strong>";
             }
             echo "</td>";
             $i++;
         }
         while ($i % $nb_per_line != 0) {
             if ($canedit) {
                 echo "<td>&nbsp;</td>";
             }
             echo "<td>&nbsp;</td>";
             $i++;
         }
         echo "</tr>";
     } else {
         echo "<tr class='tab_bg_1'>";
         echo "<td colspan='{$headerspan}' class='center'>" . $LANG['common'][49] . "</td></tr>";
     }
     echo "</table>";
     if ($canedit) {
         if (count($used)) {
             openArrowMassive("groupuser_form{$rand}", true);
             closeArrowMassive('deletegroup', $LANG['buttons'][6]);
         }
         echo "</form>";
     }
     echo "</div>";
 }
Example #10
0
            break;
        case 3:
            Ticket::showListForUser($_POST["id"]);
            break;
        case 4:
            Group_User::showForUser($user);
            break;
        case 5:
            Document::showAssociated($user);
            break;
        case 6:
            $config = new Config();
            $user->computePreferences();
            $config->showFormUserPrefs($user->fields);
            break;
        case 11:
            Reservation::showForUser($_POST["id"]);
            break;
        case 12:
            Auth::showSynchronizationForm($_POST["id"]);
            break;
        case 13:
            Log::showForItem($user);
            break;
        default:
            if (!Plugin::displayAction($user, $_REQUEST['glpi_tab'])) {
                Profile_User::showForUser($user);
            }
    }
}
ajaxFooter();
 /**
  * Add new mail with lang to current email array
  *
  * @param $data : array of data (mail, lang)
  **/
 function addToAddressesList($data)
 {
     global $CFG_GLPI;
     $new_mail = trim(utf8_strtolower($data['email']));
     $new_lang = '';
     if (isset($data['language'])) {
         $new_lang = trim($data['language']);
     }
     $username = '';
     if (isset($data['name']) && !empty($data['name'])) {
         $username = $data['name'];
     }
     if (isset($data['id']) && $data['id'] > 0) {
         $user = new User();
         if (!$user->getFromDB($data['id']) || $user->getField('is_deleted') == 1 || $user->getField('is_active') == 0) {
             // unknown, deleted or disabled user
             return false;
         }
         $filt = getEntitiesRestrictRequest('AND', 'glpi_profiles_users', '', $this->getEntity(), true);
         $prof = Profile_User::getUserProfiles($data['id'], $filt);
         if (!count($prof)) {
             // No right on the entity of the object
             return false;
         }
         if (empty($username)) {
             $username = formatUserName(0, $user->getField('name'), $user->getField('realname'), $user->getField('firstname'), 0, 0, true);
         }
     }
     $notificationoption = $this->addAdditionnalUserInfo($data);
     if (!empty($new_mail)) {
         if (NotificationMail::isUserAddressValid($new_mail) && !isset($this->target[$new_mail])) {
             $this->target[$new_mail] = array('language' => empty($new_lang) ? $CFG_GLPI["language"] : $new_lang, 'email' => $new_mail, 'additionnaloption' => $notificationoption, 'username' => $username);
         }
     }
 }
(at your option) any later version.

GLPI is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with GLPI; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
--------------------------------------------------------------------------
*/
define('GLPI_ROOT', '..');
include GLPI_ROOT . "/inc/includes.php";
$profile = new Profile();
$right = new Profile_User();
$user = new User();
if (isset($_POST["add"])) {
    $right->check(-1, 'w', $_POST);
    if ($right->add($_POST)) {
        Event::log($_POST["users_id"], "users", 4, "setup", $_SESSION["glpiname"] . " " . $LANG['log'][61]);
    }
    glpi_header($_SERVER['HTTP_REFERER']);
} else {
    if (isset($_POST["delete"])) {
        if (isset($_POST["item"]) && count($_POST["item"])) {
            foreach ($_POST["item"] as $key => $val) {
                if ($val == 1) {
                    if ($right->can($key, 'w')) {
                        $right->delete(array('id' => $key));
                    }
Example #13
0
 /**
  * Show projet associated to an item
  *
  * @since version 0.84
  *
  * @param $item            CommonDBTM object for which associated projet must be displayed
  * @param $withtemplate    (default '')
  **/
 static function showForItem(CommonDBTM $item, $withtemplate = '')
 {
     global $DB, $CFG_GLPI;
     $ID = $item->getField('id');
     if ($item->isNewID($ID)) {
         return false;
     }
     if (!plugin_projet_haveRight('projet', 'r')) {
         return false;
     }
     if (!$item->can($item->fields['id'], 'r')) {
         return false;
     }
     if (empty($withtemplate)) {
         $withtemplate = 0;
     }
     $canedit = $item->canadditem('PluginProjetProjet');
     $rand = mt_rand();
     $is_recursive = $item->isRecursive();
     $query = "SELECT `glpi_plugin_projet_projets_items`.`id` AS assocID,\n                       `glpi_entities`.`id` AS entity,\n                       `glpi_plugin_projet_projets`.`name` AS assocName,\n                       `glpi_plugin_projet_projets`.*\n                FROM `glpi_plugin_projet_projets_items`\n                LEFT JOIN `glpi_plugin_projet_projets`\n                 ON (`glpi_plugin_projet_projets_items`.`plugin_projet_projets_id`=`glpi_plugin_projet_projets`.`id`)\n                LEFT JOIN `glpi_entities` ON (`glpi_plugin_projet_projets`.`entities_id`=`glpi_entities`.`id`)\n                WHERE `glpi_plugin_projet_projets_items`.`items_id` = '{$ID}'\n                      AND `glpi_plugin_projet_projets_items`.`itemtype` = '" . $item->getType() . "' ";
     $query .= getEntitiesRestrictRequest(" AND", "glpi_plugin_projet_projets", '', '', true);
     $query .= " ORDER BY `assocName`";
     $result = $DB->query($query);
     $number = $DB->numrows($result);
     $i = 0;
     $projets = array();
     $used = array();
     if ($numrows = $DB->numrows($result)) {
         while ($data = $DB->fetch_assoc($result)) {
             $projets[$data['assocID']] = $data;
             $used[$data['id']] = $data['id'];
         }
     }
     $projet = new PluginProjetProjet();
     if ($canedit && $withtemplate < 2) {
         // Restrict entity for knowbase
         $entities = "";
         $entity = $_SESSION["glpiactive_entity"];
         if ($item->isEntityAssign()) {
             /// Case of personal items : entity = -1 : create on active entity (Reminder case))
             if ($item->getEntityID() >= 0) {
                 $entity = $item->getEntityID();
             }
             if ($item->isRecursive()) {
                 $entities = getSonsOf('glpi_entities', $entity);
             } else {
                 $entities = $entity;
             }
         }
         $limit = getEntitiesRestrictRequest(" AND ", "glpi_plugin_projet_projets", '', $entities, true);
         $q = "SELECT COUNT(*)\n               FROM `glpi_plugin_projet_projets`\n               WHERE `is_deleted` = '0'\n               AND `is_template` = '0' ";
         if ($item->getType() != 'User') {
             $q .= " {$limit}";
         }
         $result = $DB->query($q);
         $nb = $DB->result($result, 0, 0);
         echo "<div class='firstbloc'>";
         if (plugin_projet_haveRight('projet', 'r') && $nb > count($used)) {
             echo "<form name='projet_form{$rand}' id='projet_form{$rand}' method='post'\n                   action='" . Toolbox::getItemTypeFormURL('PluginProjetProjet') . "'>";
             echo "<table class='tab_cadre_fixe'>";
             echo "<tr class='tab_bg_1'>";
             echo "<td colspan='4' class='center'>";
             echo "<input type='hidden' name='entities_id' value='{$entity}'>";
             echo "<input type='hidden' name='is_recursive' value='{$is_recursive}'>";
             echo "<input type='hidden' name='itemtype' value='" . $item->getType() . "'>";
             echo "<input type='hidden' name='items_id' value='{$ID}'>";
             if ($item->getType() == 'Ticket') {
                 echo "<input type='hidden' name='tickets_id' value='{$ID}'>";
             }
             if ($item->getType() != 'User') {
                 $projet->dropdownProjet("plugin_projet_projets_id", $entities, $used);
             } else {
                 $strict_entities = Profile_User::getUserEntities($ID, true);
                 if (!Session::haveAccessToOneOfEntities($strict_entities) && !isViewAllEntities()) {
                     $canedit = false;
                 }
                 if (countElementsInTableForEntity("glpi_plugin_projet_projets", $strict_entities) > count($used)) {
                     Dropdown::show('PluginProjetProjet', array('name' => "plugin_projet_projets_id", 'used' => $used, 'entity' => $strict_entities));
                 }
             }
             echo "</td><td class='center' width='20%'>";
             echo "<input type='submit' name='additem' value=\"" . _sx('button', 'Associate a project', 'projet') . "\" class='submit'>";
             echo "</td>";
             echo "</tr>";
             echo "</table>";
             Html::closeForm();
         }
         echo "</div>";
     }
     echo "<div class='spaced'>";
     if ($canedit && $number && $withtemplate < 2) {
         Html::openMassiveActionsForm('mass' . __CLASS__ . $rand);
         $massiveactionparams = array('num_displayed' => $number);
         Html::showMassiveActions(__CLASS__, $massiveactionparams);
     }
     echo "<table class='tab_cadre_fixe'>";
     if (Session::isMultiEntitiesMode()) {
         $colsup = 1;
     } else {
         $colsup = 0;
     }
     if ($item->getType() == "Group" || $item->getType() == "User") {
         echo "<tr><th colspan='" . (7 + $colsup) . "'>" . _n('Associated project', 'Associated projects', 2, 'projet') . ":</th></tr>";
     }
     echo "<tr>";
     if ($canedit && $number && $withtemplate < 2) {
         echo "<th width='10'>" . Html::getCheckAllAsCheckbox('mass' . __CLASS__ . $rand) . "</th>";
     }
     echo "<th>" . __('Name') . "</th>";
     if (Session::isMultiEntitiesMode()) {
         echo "<th>" . __('Entity') . "</th>";
     }
     echo "<th>" . __('Description') . "</th>";
     echo "<th>" . __('Progress') . "</th>";
     echo "<th>" . __('Start date') . "</th>";
     echo "<th>" . __('End date') . "</th>";
     echo "</tr>";
     $used = array();
     if ($number) {
         Session::initNavigateListItems('PluginProjetProjet', sprintf(__('%1$s = %2$s'), $item->getTypeName(1), $item->getName()));
         foreach ($projets as $data) {
             $projetID = $data["id"];
             $link = NOT_AVAILABLE;
             if ($projet->getFromDB($projetID)) {
                 $link = $projet->getLink();
             }
             Session::addToNavigateListItems('PluginProjetProjet', $projetID);
             $used[$projetID] = $projetID;
             $assocID = $data["assocID"];
             echo "<tr class='tab_bg_1" . ($data["is_deleted"] ? "_2" : "") . "'>";
             if ($canedit && $withtemplate < 2) {
                 echo "<td width='10'>";
                 Html::showMassiveActionCheckBox(__CLASS__, $data["assocID"]);
                 echo "</td>";
             }
             echo "<td class='center'>{$link}</td>";
             if (Session::isMultiEntitiesMode()) {
                 echo "<td class='center'>" . Dropdown::getDropdownName("glpi_entities", $data['entities_id']) . "</td>";
             }
             echo "<td align='center'>" . Html::resume_text($data["description"], 250) . "</td>";
             echo "<td align='center'>" . PluginProjetProjet::displayProgressBar('100', $data["advance"]) . "</td>";
             echo "<td class='center'>" . Html::convdate($data["date_begin"]) . "</td>";
             if ($data["date_end"] <= date('Y-m-d') && !empty($data["date_end"])) {
                 echo "<td class='center'><span class='red'>" . Html::convdate($data["date_end"]) . "</span></td>";
             } else {
                 echo "<td class='center'><span class='green'>" . Html::convdate($data["date_end"]) . "</span></td>";
             }
             echo "</tr>";
             $i++;
         }
     }
     echo "</table>";
     if ($canedit && $number && $withtemplate < 2) {
         $massiveactionparams['ontop'] = false;
         Html::showMassiveActions(__CLASS__, $massiveactionparams);
         Html::closeForm();
     }
     echo "</div>";
 }
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

GLPI is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with GLPI; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
--------------------------------------------------------------------------
*/
// ----------------------------------------------------------------------
// Original Author of file: Julien Dombre
// Purpose of file:
// ----------------------------------------------------------------------
// Direct access to file
if (strpos($_SERVER['PHP_SELF'], "dropdownUserEntities.php")) {
    include "../../../inc/includes.php";
    header("Content-Type: text/html; charset=UTF-8");
    Html::header_nocache();
}
if (!defined('GLPI_ROOT')) {
    die("Can not acces directly to this file");
}
Session::checkLoginUser();
$all_entities = Profile_User::getUserEntities($_POST["value"], true);
$value = current($all_entities);
Dropdown::show("Entity", array('name' => 'entities_id', 'value' => $value, 'entity' => $all_entities));
Example #15
0
GLPI is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

GLPI is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with GLPI. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
*/
/** @file
* @brief
*/
include '../inc/includes.php';
Session::checkCentralAccess();
$profile = new Profile();
$right = new Profile_User();
$user = new User();
if (isset($_POST["add"])) {
    $right->check(-1, 'w', $_POST);
    if ($right->add($_POST)) {
        Event::log($_POST["users_id"], "users", 4, "setup", sprintf(__('%s adds a user to an entity'), $_SESSION["glpiname"]));
    }
    Html::back();
}
Html::displayErrorAndDie("lost");
Example #16
0
 /**
  * @param $users_id
  **/
 static function manageDeletedUserInLdap($users_id)
 {
     global $CFG_GLPI;
     //The only case where users_id can be null if when a user has been imported into GLPi
     //it's dn still exists, but doesn't match the connection filter anymore
     //In this case, do not try to process the user
     if (!$users_id) {
         return true;
     }
     //User is present in DB but not in the directory : it's been deleted in LDAP
     $tmp['id'] = $users_id;
     $tmp['is_deleted_ldap'] = 1;
     $myuser = new self();
     $myuser->getFromDB($users_id);
     //User is already considered as delete from ldap
     if ($myuser->fields['is_deleted_ldap'] == 1) {
         return;
     }
     switch ($CFG_GLPI['user_deleted_ldap']) {
         //DO nothing
         default:
         case 0:
             $myuser->update($tmp);
             break;
             //Put user in dustbin
         //Put user in dustbin
         case 1:
             $myuser->delete($tmp);
             break;
             //Delete all user dynamic habilitations and groups
         //Delete all user dynamic habilitations and groups
         case 2:
             Profile_User::deleteRights($users_id, true);
             Group_User::deleteGroups($users_id, true);
             $myuser->update($tmp);
             break;
             //Deactivate the user
         //Deactivate the user
         case 3:
             $tmp['is_active'] = 0;
             $myuser->update($tmp);
             break;
             //Deactivate the user+ Delete all user dynamic habilitations and groups
         //Deactivate the user+ Delete all user dynamic habilitations and groups
         case 4:
             $tmp['is_active'] = 0;
             $myuser->update($tmp);
             Profile_User::deleteRights($users_id, true);
             Group_User::deleteGroups($users_id, true);
             break;
     }
     /*
           $changes[0] = '0';
           $changes[1] = '';
           $changes[2] = __('Deleted user in LDAP directory');
           Log::history($users_id, 'User', $changes, 0, Log::HISTORY_LOG_SIMPLE_MESSAGE);*/
 }
Example #17
0
         $entities = Profile_User::getUserEntitiesForRight($user->getID(), Planning::READGROUP);
         $groups = Group_User::getUserGroups($user->getID());
         foreach ($groups as $group) {
             if ($_GET["gID"] == $group['id'] && in_array($group['entities_id'], $entities)) {
                 $ismine = true;
             }
         }
     }
 }
 $canview = false;
 // If not mine check global right
 if (!$ismine) {
     // First check user
     $entities = Profile_User::getUserEntitiesForRight($user->getID(), Planning::READALL);
     if ($_GET["uID"]) {
         $userentities = Profile_User::getUserEntities($user->getID());
         $intersect = array_intersect($entities, $userentities);
         if (count($intersect)) {
             $canview = true;
         }
     }
     // Else check group
     if (!$canview && $_GET['gID']) {
         $group = new Group();
         if ($group->getFromDB($_GET['gID'])) {
             if (in_array($group->getEntityID(), $entities)) {
                 $canview = true;
             }
         }
     }
 }
Example #18
0
 /**
  * @see Rule::executeActions()
  **/
 function executeActions($output, $params)
 {
     if (count($this->actions)) {
         foreach ($this->actions as $action) {
             switch ($action->fields["action_type"]) {
                 case "assign":
                     switch ($action->fields["field"]) {
                         default:
                             $output[$action->fields["field"]] = $action->fields["value"];
                             break;
                         case "_affect_entity_by_user_entity":
                             //3 cases :
                             //1 - rule contains a criteria like : Profil is XXXX
                             //    -> in this case, profiles_id is stored in
                             //       $this->criterias_results['PROFILES'] (one value possible)
                             //2-   rule contains criteria "User has only one profile"
                             //    -> in this case, profiles_id is stored in
                             //       $this->criterias_results['PROFILES'] (one value possible) (same as 1)
                             //3   -> rule contains only one profile
                             $profile = 0;
                             //Case 2:
                             if (isset($this->criterias_results['ONE_PROFILE'])) {
                                 $profile = $this->criterias_results['ONE_PROFILE'];
                                 //Case 3
                             } else {
                                 if (isset($this->criterias_results['UNIQUE_PROFILE'])) {
                                     $profile = $this->criterias_results['UNIQUE_PROFILE'];
                                     //Case 1
                                 } else {
                                     if (isset($this->criterias_results['PROFILES'])) {
                                         $profile = $this->criterias_results['PROFILES'];
                                     }
                                 }
                             }
                             if ($profile) {
                                 $entities = array();
                                 if (isset($params['_users_id_requester'])) {
                                     // Not set when testing
                                     $entities = Profile_User::getEntitiesForProfileByUser($params['_users_id_requester'], $profile);
                                 }
                                 //Case 2 : check if there's only one profile for this user
                                 if (isset($this->criterias_results['ONE_PROFILE']) && count($entities) == 1 || !isset($this->criterias_results['ONE_PROFILE'])) {
                                     if (count($entities) == 1) {
                                         //User has right on only one entity
                                         $output['entities_id'] = array_pop($entities);
                                     } else {
                                         if (isset($this->criterias_results['UNIQUE_PROFILE'])) {
                                             $output['entities_id'] = array_pop($entities);
                                         } else {
                                             //Rights on more than one entity : get the user's prefered entity
                                             if (isset($params['_users_id_requester'])) {
                                                 // Not set when testing
                                                 $user = new User();
                                                 $user->getFromDB($params['_users_id_requester']);
                                                 $tmpid = $user->getField('entities_id');
                                                 // Retrieve all the entities (pref could be set on a child)
                                                 $entities = Profile_User::getEntitiesForProfileByUser($params['_users_id_requester'], $profile, true);
                                                 // If an entity is defined in user's preferences,
                                                 // and this entity allowed for this profile, use this one
                                                 // else do not set the rule as matched
                                                 if (in_array($tmpid, $entities)) {
                                                     $output['entities_id'] = $user->fields['entities_id'];
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                     }
                     break;
                 case "regex_result":
                     foreach ($this->regex_results as $regex_result) {
                         $entity_found = -1;
                         $res = RuleAction::getRegexResultById($action->fields["value"], $regex_result);
                         if ($res != null) {
                             switch ($action->fields["field"]) {
                                 case "_affect_entity_by_domain":
                                     $entity_found = Entity::getEntityIDByDomain(addslashes($res));
                                     break;
                                 case "_affect_entity_by_tag":
                                     $entity_found = Entity::getEntityIDByTag(addslashes($res));
                                     break;
                             }
                             //If an entity was found
                             if ($entity_found > -1) {
                                 $output['entities_id'] = $entity_found;
                                 break;
                             }
                         }
                     }
                     // switch (field)
                     break;
             }
         }
     }
     return $output;
 }
Example #19
0
         }
     }
     break;
 case "add_group":
     $groupuser = new Group_User();
     foreach ($_POST["item"] as $key => $val) {
         if ($val == 1) {
             $input = array('groups_id' => $_POST["groups_id"], 'users_id' => $key);
             if ($groupuser->can(-1, 'w', $input)) {
                 $groupuser->add($input);
             }
         }
     }
     break;
 case "add_userprofile":
     $right = new Profile_User();
     if (isset($_POST['profiles_id']) && $_POST['profiles_id'] > 0 && isset($_POST['entities_id']) && $_POST['entities_id'] >= 0) {
         $input['entities_id'] = $_POST['entities_id'];
         $input['profiles_id'] = $_POST['profiles_id'];
         $input['is_recursive'] = $_POST['is_recursive'];
         foreach ($_POST["item"] as $key => $val) {
             if ($val == 1) {
                 $input['users_id'] = $key;
                 $right->add($input);
             }
         }
     }
     break;
 case "add_document":
     $documentitem = new Document_Item();
     foreach ($_POST["item"] as $key => $val) {
Example #20
0
 /**
  * Display datas extracted from DB
  *
  * @param $data array of search datas prepared to get datas
  *
  * @return nothing
  **/
 static function displayDatas(array &$data)
 {
     global $CFG_GLPI;
     $item = null;
     if (class_exists($data['itemtype'])) {
         $item = new $data['itemtype']();
     }
     $rand = mt_rand();
     if (!isset($data['data']) || !isset($data['data']['totalcount'])) {
         return false;
     }
     // Contruct Pager parameters
     $globallinkto = Toolbox::append_params(array('criteria' => Toolbox::stripslashes_deep($data['search']['criteria']), 'metacriteria' => Toolbox::stripslashes_deep($data['search']['metacriteria'])), '&amp;');
     $parameters = "sort=" . $data['search']['sort'] . "&amp;order=" . $data['search']['order'] . '&amp;' . $globallinkto;
     if (isset($_GET['_in_modal'])) {
         $parameters .= "&amp;_in_modal=1";
     }
     // Global search header
     if ($data['display_type'] == self::GLOBAL_SEARCH) {
         if ($data['item']) {
             echo "<div class='center'><h2>" . $data['item']->getTypeName();
             // More items
             if ($data['data']['totalcount'] > $data['search']['start'] + self::GLOBAL_DISPLAY_COUNT) {
                 echo " <a href='" . $data['search']['target'] . "?{$parameters}'>" . __('All') . "</a>";
             }
             echo "</h2></div>\n";
         } else {
             return false;
         }
     }
     // If the begin of the view is before the number of items
     if ($data['data']['count'] > 0) {
         // Display pager only for HTML
         if ($data['display_type'] == self::HTML_OUTPUT) {
             // For plugin add new parameter if available
             if ($plug = isPluginItemType($data['itemtype'])) {
                 $function = 'plugin_' . $plug['plugin'] . '_addParamFordynamicReport';
                 if (function_exists($function)) {
                     $out = $function($data['itemtype']);
                     if (is_array($out) && count($out)) {
                         $parameters .= Toolbox::append_params($out, '&amp;');
                     }
                 }
             }
             $search_config_top = "";
             $search_config_bottom = "";
             if (!isset($_GET['_in_modal']) && Session::haveRightsOr('search_config', array(DisplayPreference::PERSONAL, DisplayPreference::GENERAL))) {
                 $search_config_top = $search_config_bottom = "<div class='pager_controls'><img alt=\"" . __s('Select default items to show') . "\" title=\"" . __s('Select default items to show') . "\" src='" . $CFG_GLPI["root_doc"] . "/pics/options_search.png' ";
                 $search_config_top .= " class='pointer' onClick=\"";
                 $search_config_top .= Html::jsGetElementbyID('search_config_top') . ".dialog('open');\">";
                 $search_config_bottom .= " class='pointer' onClick=\"";
                 $search_config_bottom .= Html::jsGetElementbyID('search_config_bottom') . ".dialog('open');\">";
                 $search_config_top .= Ajax::createIframeModalWindow('search_config_top', $CFG_GLPI["root_doc"] . "/front/displaypreference.form.php?itemtype=" . $data['itemtype'], array('title' => __('Select default items to show'), 'reloadonclose' => true, 'display' => false));
                 $search_config_bottom .= Ajax::createIframeModalWindow('search_config_bottom', $CFG_GLPI["root_doc"] . "/front/displaypreference.form.php?itemtype=" . $data['itemtype'], array('title' => __('Select default items to show'), 'reloadonclose' => true, 'display' => false));
             }
             if ($item !== null && $item->maybeDeleted()) {
                 $delete_ctrl = self::isDeletedSwitch($data['search']['is_deleted']);
                 $search_config_top .= $delete_ctrl;
             }
             Html::printPager($data['search']['start'], $data['data']['totalcount'], $data['search']['target'], $parameters, $data['itemtype'], 0, $search_config_top);
             $search_config_top .= "</div>";
             $search_config_bottom .= "</div>";
         }
         // Define begin and end var for loop
         // Search case
         $begin_display = $data['data']['begin'];
         $end_display = $data['data']['end'];
         // Form to massive actions
         $isadmin = $data['item'] && $data['item']->canUpdate();
         if (!$isadmin && InfoCom::canApplyOn($data['itemtype'])) {
             $isadmin = Infocom::canUpdate() || Infocom::canCreate();
         }
         if ($data['itemtype'] != 'AllAssets') {
             $showmassiveactions = count(MassiveAction::getAllMassiveActions($data['item'], $data['search']['is_deleted']));
         } else {
             $showmassiveactions = true;
         }
         $massformid = 'massform' . $data['itemtype'];
         if ($showmassiveactions && $data['display_type'] == self::HTML_OUTPUT) {
             Html::openMassiveActionsForm($massformid);
             $massiveactionparams = $data['search']['massiveactionparams'];
             $massiveactionparams['num_displayed'] = $end_display - $begin_display;
             $massiveactionparams['fixed'] = false;
             $massiveactionparams['is_deleted'] = $data['search']['is_deleted'];
             $massiveactionparams['container'] = $massformid;
             Html::showMassiveActions($massiveactionparams);
         }
         // Compute number of columns to display
         // Add toview elements
         $nbcols = count($data['data']['cols']);
         if ($data['display_type'] == self::HTML_OUTPUT && $showmassiveactions) {
             // HTML display - massive modif
             $nbcols++;
         }
         // Display List Header
         echo self::showHeader($data['display_type'], $end_display - $begin_display + 1, $nbcols);
         // New Line for Header Items Line
         $headers_line = '';
         $headers_line_top = '';
         $headers_line_bottom = '';
         $headers_line_top .= self::showBeginHeader($data['display_type']);
         $headers_line_top .= self::showNewLine($data['display_type']);
         if ($data['display_type'] == self::HTML_OUTPUT) {
             //          $headers_line_bottom .= self::showBeginHeader($data['display_type']);
             $headers_line_bottom .= self::showNewLine($data['display_type']);
         }
         $header_num = 1;
         if ($data['display_type'] == self::HTML_OUTPUT && $showmassiveactions) {
             // HTML display - massive modif
             $headers_line_top .= self::showHeaderItem($data['display_type'], Html::getCheckAllAsCheckbox($massformid), $header_num, "", 0, $data['search']['order']);
             if ($data['display_type'] == self::HTML_OUTPUT) {
                 $headers_line_bottom .= self::showHeaderItem($data['display_type'], Html::getCheckAllAsCheckbox($massformid), $header_num, "", 0, $data['search']['order']);
             }
         }
         // Display column Headers for toview items
         $metanames = array();
         foreach ($data['data']['cols'] as $key => $val) {
             $linkto = '';
             if (!$val['meta'] && (!isset($val['searchopt']['nosort']) || !$val['searchopt']['nosort'])) {
                 $linkto = $data['search']['target'] . (strpos($data['search']['target'], '?') ? '&amp;' : '?') . "itemtype=" . $data['itemtype'] . "&amp;sort=" . $val['id'] . "&amp;order=" . ($data['search']['order'] == "ASC" ? "DESC" : "ASC") . "&amp;start=" . $data['search']['start'] . "&amp;" . $globallinkto;
             }
             $name = $val["name"];
             // prefix by group name (corresponding to optgroup in dropdown) if exists
             if (isset($val['groupname'])) {
                 $name = $val['groupname'] . " - " . $name;
             }
             // Not main itemtype add itemtype to display
             if ($data['itemtype'] != $val['itemtype']) {
                 if (!isset($metanames[$val['itemtype']])) {
                     if ($metaitem = getItemForItemtype($val['itemtype'])) {
                         $metanames[$val['itemtype']] = $metaitem->getTypeName();
                     }
                 }
                 $name = sprintf(__('%1$s - %2$s'), $metanames[$val['itemtype']], $val["name"]);
             }
             $headers_line .= self::showHeaderItem($data['display_type'], $name, $header_num, $linkto, !$val['meta'] && $data['search']['sort'] == $val['id'], $data['search']['order']);
         }
         // Add specific column Header
         if (isset($CFG_GLPI["union_search_type"][$data['itemtype']])) {
             $headers_line .= self::showHeaderItem($data['display_type'], __('Item type'), $header_num);
         }
         // End Line for column headers
         $headers_line .= self::showEndLine($data['display_type']);
         $headers_line_top .= $headers_line;
         if ($data['display_type'] == self::HTML_OUTPUT) {
             $headers_line_bottom .= $headers_line;
         }
         $headers_line_top .= self::showEndHeader($data['display_type']);
         //          $headers_line_bottom .= self::showEndHeader($data['display_type']);
         echo $headers_line_top;
         // Init list of items displayed
         if ($data['display_type'] == self::HTML_OUTPUT) {
             Session::initNavigateListItems($data['itemtype']);
         }
         // Num of the row (1=header_line)
         $row_num = 1;
         $massiveaction_field = 'id';
         if ($data['itemtype'] != 'AllAssets' && isset($CFG_GLPI["union_search_type"][$data['itemtype']])) {
             $massiveaction_field = 'refID';
         }
         $typenames = array();
         // Display Loop
         foreach ($data['data']['rows'] as $rowkey => $row) {
             // Column num
             $item_num = 1;
             $row_num++;
             // New line
             echo self::showNewLine($data['display_type'], $row_num % 2, $data['search']['is_deleted']);
             $current_type = isset($row['TYPE']) ? $row['TYPE'] : $data['itemtype'];
             $massiveaction_type = $current_type;
             if ($data['itemtype'] != 'AllAssets' && isset($CFG_GLPI["union_search_type"][$data['itemtype']])) {
                 $massiveaction_type = $data['itemtype'];
             }
             // Add item in item list
             Session::addToNavigateListItems($current_type, $row["id"]);
             if ($data['display_type'] == self::HTML_OUTPUT && $showmassiveactions) {
                 // HTML display - massive modif
                 $tmpcheck = "";
                 if ($data['itemtype'] == 'Entity' && !in_array($row["id"], $_SESSION["glpiactiveentities"])) {
                     $tmpcheck = "&nbsp;";
                 } else {
                     if ($data['itemtype'] == 'User' && !Session::isViewAllEntities() && !Session::haveAccessToOneOfEntities(Profile_User::getUserEntities($row["id"], false))) {
                         $tmpcheck = "&nbsp;";
                     } else {
                         if ($data['item'] instanceof CommonDBTM && $data['item']->maybeRecursive() && !in_array($row["entities_id"], $_SESSION["glpiactiveentities"])) {
                             $tmpcheck = "&nbsp;";
                         } else {
                             $tmpcheck = Html::getMassiveActionCheckBox($massiveaction_type, $row[$massiveaction_field]);
                         }
                     }
                 }
                 echo self::showItem($data['display_type'], $tmpcheck, $item_num, $row_num, "width='10'");
             }
             // Print other toview items
             foreach ($data['data']['cols'] as $colkey => $col) {
                 if (!$col['meta']) {
                     echo self::showItem($data['display_type'], $row[$colkey]['displayname'], $item_num, $row_num, self::displayConfigItem($data['itemtype'], $col['id'], $row, $colkey));
                 } else {
                     // META case
                     echo self::showItem($data['display_type'], $row[$colkey]['displayname'], $item_num, $row_num);
                 }
             }
             if (isset($CFG_GLPI["union_search_type"][$data['itemtype']])) {
                 if (!isset($typenames[$row["TYPE"]])) {
                     if ($itemtmp = getItemForItemtype($row["TYPE"])) {
                         $typenames[$row["TYPE"]] = $itemtmp->getTypeName();
                     }
                 }
                 echo self::showItem($data['display_type'], $typenames[$row["TYPE"]], $item_num, $row_num);
             }
             // End Line
             echo self::showEndLine($data['display_type']);
         }
         // Create title
         $title = '';
         if ($data['display_type'] == self::PDF_OUTPUT_LANDSCAPE || $data['display_type'] == self::PDF_OUTPUT_PORTRAIT) {
             $title = self::computeTitle($data);
         }
         if ($data['display_type'] == self::HTML_OUTPUT) {
             echo $headers_line_bottom;
         }
         // Display footer
         echo self::showFooter($data['display_type'], $title);
         // Delete selected item
         if ($data['display_type'] == self::HTML_OUTPUT) {
             if ($showmassiveactions) {
                 $massiveactionparams['ontop'] = false;
                 Html::showMassiveActions($massiveactionparams);
                 // End form for delete item
                 Html::closeForm();
             } else {
                 echo "<br>";
             }
         }
         if ($data['display_type'] == self::HTML_OUTPUT) {
             // In case of HTML display
             Html::printPager($data['search']['start'], $data['data']['totalcount'], $data['search']['target'], $parameters, '', 0, $search_config_bottom);
         }
     } else {
         if ($item !== null && $item->maybeDeleted()) {
             echo "<div class='center'>" . self::isDeletedSwitch($data['search']['is_deleted']) . "</div><br/>";
         }
         echo self::showError($data['display_type']);
     }
 }
Example #21
0
 /**
  * Display content of Tab
  *
  * @param $ID of the item
  * @param $tab number of the tab
  *
  * @return true if handled (for class stack)
  */
 function showTabContent($ID, $tab)
 {
     global $CFG_GLPI;
     if (!$this->isNewID($ID)) {
         switch ($tab) {
             case -1:
                 // All
                 $this->showChildren($ID);
                 EntityData::showStandardOptions($this);
                 Profile_User::showForEntity($this);
                 $collection = new RuleRightCollection();
                 if ($collection->canList()) {
                     $ldaprule = new RuleRight();
                     $ldaprule->showAndAddRuleForm($this);
                 }
                 $collection = new RuleOcsCollection();
                 if ($collection->canList()) {
                     $ocsrule = new RuleOcs();
                     $ocsrule->showAndAddRuleForm($this);
                 }
                 $collection = new RuleMailCollectorCollection();
                 if ($collection->canList()) {
                     $mailcollector = new RuleMailCollector();
                     $mailcollector->showAndAddRuleForm($this);
                 }
                 Document::showAssociated($this);
                 EntityData::showNotificationOptions($this);
                 EntityData::showHelpdeskOptions($this);
                 EntityData::showInventoryOptions($this);
                 Plugin::displayAction($this, $tab);
                 break;
             case 2:
                 EntityData::showStandardOptions($this);
                 break;
             case 3:
                 Profile_User::showForEntity($this);
                 break;
             case 4:
                 $collection = new RuleRightCollection();
                 if ($collection->canList()) {
                     $ldaprule = new RuleRight();
                     $ldaprule->showAndAddRuleForm($this);
                 }
                 $collection = new RuleOcsCollection();
                 if ($collection->canList()) {
                     $ocsrule = new RuleOcs();
                     $ocsrule->showAndAddRuleForm($this);
                 }
                 $collection = new RuleMailCollectorCollection();
                 if ($collection->canList()) {
                     $mailcollector = new RuleMailCollector();
                     $mailcollector->showAndAddRuleForm($this);
                 }
                 break;
             case 5:
                 EntityData::showAdvancedOptions($this);
                 break;
             case 6:
                 Document::showAssociated($this);
                 break;
             case 7:
                 EntityData::showNotificationOptions($this);
                 break;
             case 8:
                 EntityData::showHelpdeskOptions($this);
                 break;
             case 9:
                 EntityData::showInventoryOptions($this);
                 break;
             case 10:
                 showNotesForm(getItemTypeFormURL('EntityData'), 'EntityData', $_POST["id"]);
                 break;
             default:
                 if (!Plugin::displayAction($this, $tab)) {
                     $this->showChildren($ID);
                 }
                 return false;
         }
     }
     return false;
 }
Example #22
0
 function showForm($ID, $options = array())
 {
     global $DB, $CFG_GLPI;
     $default_values = self::getDefaultValues();
     // Get default values from posted values on reload form
     // On get because of tabs
     // we use REQUEST because method differ with layout (lefttab : GET, vsplit: POST)
     if (!isset($options['template_preview'])) {
         if (isset($_REQUEST)) {
             $values = Html::cleanPostForTextArea($_REQUEST);
         }
     }
     // Restore saved value or override with page parameter
     $saved = $this->restoreInput();
     foreach ($default_values as $name => $value) {
         if (!isset($values[$name])) {
             if (isset($saved[$name])) {
                 $values[$name] = $saved[$name];
             } else {
                 $values[$name] = $value;
             }
         }
     }
     if (isset($values['content'])) {
         // Clean new lines to be fix encoding
         $order = array('\\r', '\\n', "\\");
         $replace = array("", "", "");
         $values['content'] = str_replace($order, $replace, $values['content']);
     }
     if (isset($values['name'])) {
         $values['name'] = str_replace("\\", "", $values['name']);
     }
     if (!$ID) {
         // Override defaut values from projecttask if needed
         if (isset($options['_projecttasks_id'])) {
             $pt = new ProjectTask();
             if ($pt->getFromDB($options['_projecttasks_id'])) {
                 $values['name'] = $pt->getField('name');
                 $values['content'] = $pt->getField('name');
             }
         }
     }
     // Check category / type validity
     if ($values['itilcategories_id']) {
         $cat = new ITILCategory();
         if ($cat->getFromDB($values['itilcategories_id'])) {
             switch ($values['type']) {
                 case self::INCIDENT_TYPE:
                     if (!$cat->getField('is_incident')) {
                         $values['itilcategories_id'] = 0;
                     }
                     break;
                 case self::DEMAND_TYPE:
                     if (!$cat->getField('is_request')) {
                         $values['itilcategories_id'] = 0;
                     }
                     break;
                 default:
                     break;
             }
         }
     }
     // Default check
     if ($ID > 0) {
         $this->check($ID, READ);
     } else {
         // Create item
         $this->check(-1, CREATE, $values);
     }
     if (!$ID) {
         $this->userentities = array();
         if ($values["_users_id_requester"]) {
             //Get all the user's entities
             $all_entities = Profile_User::getUserEntities($values["_users_id_requester"], true, true);
             //For each user's entity, check if the technician which creates the ticket have access to it
             foreach ($all_entities as $tmp => $ID_entity) {
                 if (Session::haveAccessToEntity($ID_entity)) {
                     $this->userentities[] = $ID_entity;
                 }
             }
         }
         $this->countentitiesforuser = count($this->userentities);
         if ($this->countentitiesforuser > 0 && !in_array($this->fields["entities_id"], $this->userentities)) {
             // If entity is not in the list of user's entities,
             // then use as default value the first value of the user's entites list
             $this->fields["entities_id"] = $this->userentities[0];
             // Pass to values
             $values['entities_id'] = $this->userentities[0];
         }
     }
     if ($values['type'] <= 0) {
         $values['type'] = Entity::getUsedConfig('tickettype', $values['entities_id'], '', Ticket::INCIDENT_TYPE);
     }
     if (!isset($options['template_preview'])) {
         $options['template_preview'] = 0;
     }
     // Load ticket template if available :
     if ($ID) {
         $tt = $this->getTicketTemplateToUse($options['template_preview'], $this->fields['type'], $this->fields['itilcategories_id'], $this->fields['entities_id']);
     } else {
         $tt = $this->getTicketTemplateToUse($options['template_preview'], $values['type'], $values['itilcategories_id'], $values['entities_id']);
     }
     // Predefined fields from template : reset them
     if (isset($values['_predefined_fields'])) {
         $values['_predefined_fields'] = Toolbox::decodeArrayFromInput($values['_predefined_fields']);
     } else {
         $values['_predefined_fields'] = array();
     }
     // Store predefined fields to be able not to take into account on change template
     // Only manage predefined values on ticket creation
     $predefined_fields = array();
     if (!$ID) {
         if (isset($tt->predefined) && count($tt->predefined)) {
             foreach ($tt->predefined as $predeffield => $predefvalue) {
                 if (isset($default_values[$predeffield])) {
                     // Is always default value : not set
                     // Set if already predefined field
                     // Set if ticket template change
                     if (count($values['_predefined_fields']) == 0 && $values[$predeffield] == $default_values[$predeffield] || isset($values['_predefined_fields'][$predeffield]) && $values[$predeffield] == $values['_predefined_fields'][$predeffield] || isset($values['_tickettemplates_id']) && $values['_tickettemplates_id'] != $tt->getID() || $predeffield == 'requesttypes_id' && empty($saved)) {
                         // Load template data
                         $values[$predeffield] = $predefvalue;
                         $this->fields[$predeffield] = $predefvalue;
                         $predefined_fields[$predeffield] = $predefvalue;
                     }
                 }
             }
             // All predefined override : add option to say predifined exists
             if (count($predefined_fields) == 0) {
                 $predefined_fields['_all_predefined_override'] = 1;
             }
         } else {
             // No template load : reset predefined values
             if (count($values['_predefined_fields'])) {
                 foreach ($values['_predefined_fields'] as $predeffield => $predefvalue) {
                     if ($values[$predeffield] == $predefvalue) {
                         $values[$predeffield] = $default_values[$predeffield];
                     }
                 }
             }
         }
     }
     // Put ticket template on $values for actors
     $values['_tickettemplate'] = $tt;
     $canupdate = Session::haveRight(self::$rightname, UPDATE);
     $canpriority = Session::haveRight(self::$rightname, self::CHANGEPRIORITY);
     $canstatus = $canupdate;
     if ($ID && in_array($this->fields['status'], $this->getClosedStatusArray())) {
         $canupdate = false;
         // No update for actors
         $values['_noupdate'] = true;
     }
     $showuserlink = 0;
     if (Session::haveRight('user', READ)) {
         $showuserlink = 1;
     }
     if ($options['template_preview']) {
         // Add all values to fields of tickets for template preview
         foreach ($values as $key => $val) {
             if (!isset($this->fields[$key])) {
                 $this->fields[$key] = $val;
             }
         }
     }
     // In percent
     $colsize1 = '13';
     $colsize2 = '29';
     $colsize3 = '13';
     $colsize4 = '45';
     $canupdate_descr = $canupdate || $this->fields['status'] == self::INCOMING && $this->isUser(CommonITILActor::REQUESTER, Session::getLoginUserID()) && $this->numberOfFollowups() == 0 && $this->numberOfTasks() == 0;
     if (!$options['template_preview']) {
         echo "<form method='post' name='form_ticket' enctype='multipart/form-data' action='" . $CFG_GLPI["root_doc"] . "/front/ticket.form.php'>";
         if (isset($options['_projecttasks_id'])) {
             echo "<input type='hidden' name='_projecttasks_id' value='" . $options['_projecttasks_id'] . "'>";
         }
     }
     echo "<div class='spaced' id='tabsbody'>";
     echo "<table class='tab_cadre_fixe' id='mainformtable'>";
     // Optional line
     $ismultientities = Session::isMultiEntitiesMode();
     echo "<tr class='headerRow responsive_hidden'>";
     echo "<th colspan='4'>";
     if ($ID) {
         $text = sprintf(__('%1$s - %2$s'), $this->getTypeName(1), sprintf(__('%1$s: %2$s'), __('ID'), $ID));
         if ($ismultientities) {
             $text = sprintf(__('%1$s (%2$s)'), $text, Dropdown::getDropdownName('glpi_entities', $this->fields['entities_id']));
         }
         echo $text;
     } else {
         if ($ismultientities) {
             printf(__('The ticket will be added in the entity %s'), Dropdown::getDropdownName("glpi_entities", $this->fields['entities_id']));
         } else {
             _e('New ticket');
         }
     }
     echo "</th></tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<th width='{$colsize1}%'>";
     echo $tt->getBeginHiddenFieldText('date');
     if (!$ID) {
         printf(__('%1$s%2$s'), __('Opening date'), $tt->getMandatoryMark('date'));
     } else {
         _e('Opening date');
     }
     echo $tt->getEndHiddenFieldText('date');
     echo "</th>";
     echo "<td width='{$colsize2}%'>";
     echo $tt->getBeginHiddenFieldValue('date');
     $date = $this->fields["date"];
     if ($canupdate) {
         Html::showDateTimeField("date", array('value' => $date, 'timestep' => 1, 'maybeempty' => false));
     } else {
         echo Html::convDateTime($date);
     }
     echo $tt->getEndHiddenFieldValue('date', $this);
     echo "</td><td colspan='2'></td></tr>";
     // SLTs
     echo "<tr class='tab_bg_1'>";
     echo "<th width='{$colsize1}%'>" . $tt->getBeginHiddenFieldText('time_to_own');
     if (!$ID) {
         printf(__('%1$s%2$s'), __('Time to own'), $tt->getMandatoryMark('time_to_own'));
     } else {
         _e('Time to own');
     }
     echo $tt->getEndHiddenFieldText('time_to_own');
     echo "</th>";
     echo "<td width='{$colsize2}%' class='nopadding'>";
     $slt = new SLT();
     $slt->showSltForTicket($this, SLT::TTO, $tt, $canupdate);
     echo "</td>";
     echo "<th width='{$colsize3}%'>" . $tt->getBeginHiddenFieldText('due_date');
     if (!$ID) {
         printf(__('%1$s%2$s'), __('Time to resolve'), $tt->getMandatoryMark('due_date'));
     } else {
         _e('Time to resolve');
     }
     echo $tt->getEndHiddenFieldText('due_date');
     echo "</th>";
     echo "<td width='{$colsize4}%' class='nopadding'>";
     $slt->showSltForTicket($this, SLT::TTR, $tt, $canupdate);
     echo "</td>";
     echo "</tr>";
     if ($ID) {
         echo "<tr class='tab_bg_1'>";
         echo "<th width='{$colsize1}%'>" . __('By') . "</th>";
         echo "<td width='{$colsize2}%'>";
         if ($canupdate) {
             User::dropdown(array('name' => 'users_id_recipient', 'value' => $this->fields["users_id_recipient"], 'entity' => $this->fields["entities_id"], 'right' => 'all'));
         } else {
             echo getUserName($this->fields["users_id_recipient"], $showuserlink);
         }
         echo "</td>";
         echo "<th width='{$colsize3}%'>" . __('Last update') . "</th>";
         echo "<td width='{$colsize4}%'>";
         if ($this->fields['users_id_lastupdater'] > 0) {
             //TRANS: %1$s is the update date, %2$s is the last updater name
             printf(__('%1$s by %2$s'), Html::convDateTime($this->fields["date_mod"]), getUserName($this->fields["users_id_lastupdater"], $showuserlink));
         }
         echo "</td>";
         echo "</tr>";
     }
     if ($ID && (in_array($this->fields["status"], $this->getSolvedStatusArray()) || in_array($this->fields["status"], $this->getClosedStatusArray()))) {
         echo "<tr class='tab_bg_1'>";
         echo "<th width='{$colsize1}%'>" . __('Resolution date') . "</th>";
         echo "<td width='{$colsize2}%'>";
         Html::showDateTimeField("solvedate", array('value' => $this->fields["solvedate"], 'timestep' => 1, 'maybeempty' => false, 'canedit' => $canupdate));
         echo "</td>";
         if (in_array($this->fields["status"], $this->getClosedStatusArray())) {
             echo "<th width='{$colsize3}%'>" . __('Close date') . "</th>";
             echo "<td width='{$colsize4}%'>";
             Html::showDateTimeField("closedate", array('value' => $this->fields["closedate"], 'timestep' => 1, 'maybeempty' => false, 'canedit' => $canupdate));
             echo "</td>";
         } else {
             echo "<td colspan='2'>&nbsp;</td>";
         }
         echo "</tr>";
     }
     if ($ID) {
         echo "</table>";
         echo "<table  class='tab_cadre_fixe' id='mainformtable2'>";
     }
     echo "<tr class='tab_bg_1'>";
     echo "<th width='{$colsize1}%'>" . sprintf(__('%1$s%2$s'), __('Type'), $tt->getMandatoryMark('type')) . "</th>";
     echo "<td width='{$colsize2}%'>";
     // Permit to set type when creating ticket without update right
     if ($canupdate || !$ID) {
         $opt = array('value' => $this->fields["type"]);
         /// Auto submit to load template
         if (!$ID) {
             $opt['on_change'] = 'this.form.submit()';
         }
         $rand = self::dropdownType('type', $opt);
         if ($ID) {
             $params = array('type' => '__VALUE__', 'entity_restrict' => $this->fields['entities_id'], 'value' => $this->fields['itilcategories_id'], 'currenttype' => $this->fields['type']);
             Ajax::updateItemOnSelectEvent("dropdown_type{$rand}", "show_category_by_type", $CFG_GLPI["root_doc"] . "/ajax/dropdownTicketCategories.php", $params);
         }
     } else {
         echo self::getTicketTypeName($this->fields["type"]);
     }
     echo "</td>";
     echo "<th width='{$colsize3}%'>" . sprintf(__('%1$s%2$s'), __('Category'), $tt->getMandatoryMark('itilcategories_id')) . "</th>";
     echo "<td width='{$colsize4}%'>";
     // Permit to set category when creating ticket without update right
     if ($canupdate || !$ID || $canupdate_descr) {
         $opt = array('value' => $this->fields["itilcategories_id"], 'entity' => $this->fields["entities_id"]);
         if ($_SESSION["glpiactiveprofile"]["interface"] == "helpdesk") {
             $opt['condition'] = "`is_helpdeskvisible`='1' AND ";
         } else {
             $opt['condition'] = '';
         }
         /// Auto submit to load template
         if (!$ID) {
             $opt['on_change'] = 'this.form.submit()';
         }
         /// if category mandatory, no empty choice
         /// no empty choice is default value set on ticket creation, else yes
         if (($ID || $values['itilcategories_id']) && $tt->isMandatoryField("itilcategories_id") && $this->fields["itilcategories_id"] > 0) {
             $opt['display_emptychoice'] = false;
         }
         switch ($this->fields["type"]) {
             case self::INCIDENT_TYPE:
                 $opt['condition'] .= "`is_incident`='1'";
                 break;
             case self::DEMAND_TYPE:
                 $opt['condition'] .= "`is_request`='1'";
                 break;
             default:
                 break;
         }
         echo "<span id='show_category_by_type'>";
         ITILCategory::dropdown($opt);
         echo "</span>";
     } else {
         echo Dropdown::getDropdownName("glpi_itilcategories", $this->fields["itilcategories_id"]);
     }
     echo "</td>";
     echo "</tr>";
     if (!$ID) {
         echo "</table>";
         $this->showActorsPartForm($ID, $values);
         echo "<table class='tab_cadre_fixe' id='mainformtable3'>";
     }
     echo "<tr class='tab_bg_1'>";
     echo "<th width='{$colsize1}%'>" . $tt->getBeginHiddenFieldText('status');
     printf(__('%1$s%2$s'), __('Status'), $tt->getMandatoryMark('status'));
     echo $tt->getEndHiddenFieldText('status') . "</th>";
     echo "<td width='{$colsize2}%'>";
     echo $tt->getBeginHiddenFieldValue('status');
     if ($canstatus) {
         self::dropdownStatus(array('value' => $this->fields["status"], 'showtype' => 'allowed'));
         TicketValidation::alertValidation($this, 'status');
     } else {
         echo self::getStatus($this->fields["status"]);
         if (in_array($this->fields["status"], $this->getClosedStatusArray()) && $this->isAllowedStatus($this->fields['status'], Ticket::INCOMING)) {
             echo "&nbsp;<a class='vsubmit' href='" . $this->getLinkURL() . "&amp;forcetab=TicketFollowup\$1&amp;_openfollowup=1'>" . __('Reopen') . "</a>";
         }
     }
     echo $tt->getEndHiddenFieldValue('status', $this);
     echo "</td>";
     echo "<th width='{$colsize3}%'>" . $tt->getBeginHiddenFieldText('requesttypes_id');
     printf(__('%1$s%2$s'), __('Request source'), $tt->getMandatoryMark('requesttypes_id'));
     echo $tt->getEndHiddenFieldText('requesttypes_id') . "</th>";
     echo "<td width='{$colsize4}%'>";
     echo $tt->getBeginHiddenFieldValue('requesttypes_id');
     if ($canupdate) {
         RequestType::dropdown(array('value' => $this->fields["requesttypes_id"], 'condition' => 'is_active = 1 AND is_ticketheader = 1'));
     } else {
         echo Dropdown::getDropdownName('glpi_requesttypes', $this->fields["requesttypes_id"]);
         echo Html::hidden('requesttypes_id', array('value' => $this->fields["requesttypes_id"]));
     }
     echo $tt->getEndHiddenFieldValue('requesttypes_id', $this);
     echo "</td>";
     echo "</tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<th>" . $tt->getBeginHiddenFieldText('urgency');
     printf(__('%1$s%2$s'), __('Urgency'), $tt->getMandatoryMark('urgency'));
     echo $tt->getEndHiddenFieldText('urgency') . "</th>";
     echo "<td>";
     if ($canupdate && $canpriority || !$ID || $canupdate_descr) {
         // Only change during creation OR when allowed to change priority OR when user is the creator
         echo $tt->getBeginHiddenFieldValue('urgency');
         $idurgency = self::dropdownUrgency(array('value' => $this->fields["urgency"]));
         echo $tt->getEndHiddenFieldValue('urgency', $this);
     } else {
         $idurgency = "value_urgency" . mt_rand();
         echo "<input id='{$idurgency}' type='hidden' name='urgency' value='" . $this->fields["urgency"] . "'>";
         echo $tt->getBeginHiddenFieldValue('urgency');
         echo parent::getUrgencyName($this->fields["urgency"]);
         echo $tt->getEndHiddenFieldValue('urgency', $this);
     }
     echo "</td>";
     // Display validation state
     echo "<th>";
     if (!$ID) {
         echo $tt->getBeginHiddenFieldText('_add_validation');
         printf(__('%1$s%2$s'), __('Approval request'), $tt->getMandatoryMark('_add_validation'));
         echo $tt->getEndHiddenFieldText('_add_validation');
     } else {
         echo $tt->getBeginHiddenFieldText('global_validation');
         _e('Approval');
         echo $tt->getEndHiddenFieldText('global_validation');
     }
     echo "</th>";
     echo "<td>";
     if (!$ID) {
         echo $tt->getBeginHiddenFieldValue('_add_validation');
         $validation_right = '';
         if ($values['type'] == self::INCIDENT_TYPE && Session::haveRight('ticketvalidation', TicketValidation::CREATEINCIDENT)) {
             $validation_right = 'validate_incident';
         }
         if ($values['type'] == self::DEMAND_TYPE && Session::haveRight('ticketvalidation', TicketValidation::CREATEREQUEST)) {
             $validation_right = 'validate_request';
         }
         if (!empty($validation_right)) {
             echo "<input type='hidden' name='_add_validation' value='" . $values['_add_validation'] . "'>";
             $params = array('name' => "users_id_validate", 'entity' => $this->fields['entities_id'], 'right' => $validation_right, 'users_id_validate' => $values['users_id_validate']);
             TicketValidation::dropdownValidator($params);
         }
         echo $tt->getEndHiddenFieldValue('_add_validation', $this);
         if ($tt->isPredefinedField('global_validation')) {
             echo "<input type='hidden' name='global_validation' value='" . $tt->predefined['global_validation'] . "'>";
         }
     } else {
         echo $tt->getBeginHiddenFieldValue('global_validation');
         if (Session::haveRightsOr('ticketvalidation', TicketValidation::getCreateRights()) && $canupdate) {
             TicketValidation::dropdownStatus('global_validation', array('global' => true, 'value' => $this->fields['global_validation']));
         } else {
             echo TicketValidation::getStatus($this->fields['global_validation']);
         }
         echo $tt->getEndHiddenFieldValue('global_validation', $this);
     }
     echo "</td></tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<th>" . $tt->getBeginHiddenFieldText('impact');
     printf(__('%1$s%2$s'), __('Impact'), $tt->getMandatoryMark('impact'));
     echo $tt->getEndHiddenFieldText('impact') . "</th>";
     echo "<td>";
     echo $tt->getBeginHiddenFieldValue('impact');
     if ($canupdate) {
         $idimpact = self::dropdownImpact(array('value' => $this->fields["impact"]));
     } else {
         $idimpact = "value_impact" . mt_rand();
         echo "<input id='{$idimpact}' type='hidden' name='impact' value='" . $this->fields["impact"] . "'>";
         echo parent::getImpactName($this->fields["impact"]);
     }
     echo $tt->getEndHiddenFieldValue('impact', $this);
     echo "</td>";
     echo "<th>" . $tt->getBeginHiddenFieldText('locations_id');
     printf(__('%1$s%2$s'), __('Location'), $tt->getMandatoryMark('locations_id'));
     echo $tt->getEndHiddenFieldText('locations_id') . "</th>";
     echo "<td>";
     echo $tt->getBeginHiddenFieldValue('locations_id');
     if ($canupdate || !$ID) {
         Location::dropdown(array('value' => $this->fields['locations_id'], 'entity' => $this->fields['entities_id']));
     } else {
         echo Dropdown::getDropdownName('glpi_locations', $this->fields["locations_id"]);
     }
     echo $tt->getEndHiddenFieldValue('locations_id', $this);
     echo "</td>";
     echo "</tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<th>" . $tt->getBeginHiddenFieldText('priority');
     printf(__('%1$s%2$s'), __('Priority'), $tt->getMandatoryMark('priority'));
     echo $tt->getEndHiddenFieldText('priority') . "</th>";
     echo "<td>";
     $idajax = 'change_priority_' . mt_rand();
     if ($canpriority && !$tt->isHiddenField('priority')) {
         $idpriority = parent::dropdownPriority(array('value' => $this->fields["priority"], 'withmajor' => true));
         $idpriority = 'dropdown_priority' . $idpriority;
         echo "&nbsp;<span id='{$idajax}' style='display:none'></span>";
     } else {
         $idpriority = 0;
         echo $tt->getBeginHiddenFieldValue('priority');
         echo "<span id='{$idajax}'>" . parent::getPriorityName($this->fields["priority"]) . "</span>";
         echo $tt->getEndHiddenFieldValue('priority', $this);
     }
     if ($canupdate || $canupdate_descr) {
         $params = array('urgency' => '__VALUE0__', 'impact' => '__VALUE1__', 'priority' => $idpriority);
         Ajax::updateItemOnSelectEvent(array('dropdown_urgency' . $idurgency, 'dropdown_impact' . $idimpact), $idajax, $CFG_GLPI["root_doc"] . "/ajax/priority.php", $params);
     }
     echo "</td>";
     echo "<th rowspan='2'>" . $tt->getBeginHiddenFieldText('items_id');
     printf(__('%1$s%2$s'), _n('Associated element', 'Associated elements', Session::getPluralNumber()), $tt->getMandatoryMark('items_id'));
     if ($ID && $canupdate) {
         echo "&nbsp;<a  href='" . $this->getFormURL() . "?id=" . $ID . "&amp;forcetab=Item_Ticket\$1'><img title='" . __s('Update') . "' alt='" . __s('Update') . "'\n                      class='pointer' src='" . $CFG_GLPI["root_doc"] . "/pics/showselect.png'></a>";
     }
     echo $tt->getEndHiddenFieldText('items_id');
     echo "</th>";
     if (!$ID) {
         echo "<td rowspan='2'>";
         echo $tt->getBeginHiddenFieldValue('items_id');
         $values['_canupdate'] = Session::haveRight('ticket', CREATE);
         if ($values['_canupdate']) {
             Item_Ticket::itemAddForm($this, $values);
         }
         echo $tt->getEndHiddenFieldValue('items_id', $this);
         echo "</td>";
     } else {
         echo "<td>";
         echo $tt->getBeginHiddenFieldValue('items_id');
         $values['_canupdate'] = $canupdate || $canupdate_descr;
         Item_Ticket::itemAddForm($this, $values);
         echo $tt->getEndHiddenFieldValue('items_id', $this);
         echo "</td>";
     }
     echo "</tr>";
     echo "<tr class='tab_bg_1'>";
     // Need comment right to add a followup with the actiontime
     if (!$ID && Session::haveRight('followup', TicketFollowup::ADDALLTICKET)) {
         echo "<th>" . $tt->getBeginHiddenFieldText('actiontime');
         printf(__('%1$s%2$s'), __('Total duration'), $tt->getMandatoryMark('actiontime'));
         echo $tt->getEndHiddenFieldText('actiontime') . "</th>";
         echo "<td>";
         echo $tt->getBeginHiddenFieldValue('actiontime');
         Dropdown::showTimeStamp('actiontime', array('value' => $values['actiontime'], 'addfirstminutes' => true));
         echo $tt->getEndHiddenFieldValue('actiontime', $this);
         echo "</td>";
     }
     echo "</tr>";
     echo "</table>";
     if ($ID) {
         $this->showActorsPartForm($ID, $values);
     }
     $view_linked_tickets = $ID || $canupdate;
     echo "<table class='tab_cadre_fixe' id='mainformtable4'>";
     echo "<tr class='tab_bg_1'>";
     echo "<th style='width:{$colsize1}%'>" . $tt->getBeginHiddenFieldText('name');
     printf(__('%1$s%2$s'), __('Title'), $tt->getMandatoryMark('name'));
     echo $tt->getEndHiddenFieldText('name') . "</th>";
     echo "<td colspan='3'>";
     if (!$ID || $canupdate_descr) {
         echo $tt->getBeginHiddenFieldValue('name');
         echo "<input type='text' style='width:98%' maxlength=250 name='name' " . " value=\"" . Html::cleanInputText($this->fields["name"]) . "\">";
         echo $tt->getEndHiddenFieldValue('name', $this);
     } else {
         if (empty($this->fields["name"])) {
             _e('Without title');
         } else {
             echo $this->fields["name"];
         }
     }
     echo "</td>";
     echo "</tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<th style='width:{$colsize1}%'>" . $tt->getBeginHiddenFieldText('content');
     printf(__('%1$s%2$s'), __('Description'), $tt->getMandatoryMark('content'));
     if (!$ID || $canupdate_descr) {
         $content = Toolbox::unclean_cross_side_scripting_deep(Html::entity_decode_deep($this->fields['content']));
         Html::showTooltip(nl2br(Html::Clean($content)));
     }
     echo $tt->getEndHiddenFieldText('content') . "</th>";
     echo "<td colspan='3'>";
     if (!$ID || $canupdate_descr) {
         // Admin =oui on autorise la modification de la description
         echo $tt->getBeginHiddenFieldValue('content');
         $rand = mt_rand();
         $rand_text = mt_rand();
         $rows = 6;
         $content_id = "content{$rand}";
         if ($CFG_GLPI["use_rich_text"]) {
             $this->fields["content"] = $this->setRichTextContent($content_id, $this->fields["content"], $rand);
             $rows = 10;
         } else {
             $this->fields["content"] = $this->setSimpleTextContent($this->fields["content"]);
         }
         echo "<div id='content{$rand_text}'>";
         echo "<textarea id='{$content_id}' name='content' style='width:100%' rows='{$rows}'>" . $this->fields["content"] . "</textarea></div>";
         echo Html::scriptBlock("\$(document).ready(function() { \$('#{$content_id}').autogrow(); });");
         echo $tt->getEndHiddenFieldValue('content', $this);
     } else {
         $content = Toolbox::unclean_cross_side_scripting_deep(Html::entity_decode_deep($this->fields['content']));
         echo nl2br(Html::Clean($content));
     }
     echo "</td>";
     echo "</tr>";
     echo "<tr class='tab_bg_1'>";
     if ($view_linked_tickets) {
         echo "<th style='width:{$colsize1}%'>" . _n('Linked ticket', 'Linked tickets', Session::getPluralNumber());
         $rand_linked_ticket = mt_rand();
         if ($canupdate) {
             echo "&nbsp;";
             echo "<img onClick=\"" . Html::jsShow("linkedticket{$rand_linked_ticket}") . "\"\n                   title=\"" . __s('Add') . "\" alt=\"" . __s('Add') . "\"\n                   class='pointer' src='" . $CFG_GLPI["root_doc"] . "/pics/add_dropdown.png'>";
         }
         echo '</th>';
         echo "<td colspan='3'>";
         if ($canupdate) {
             echo "<div style='display:none' id='linkedticket{$rand_linked_ticket}'>";
             echo "<table class='tab_format' width='100%'><tr><td width='30%'>";
             Ticket_Ticket::dropdownLinks('_link[link]', isset($values["_link"]) ? $values["_link"]['link'] : '');
             echo "<input type='hidden' name='_link[tickets_id_1]' value='{$ID}'>\n";
             echo "</td><td width='70%'>";
             $linkparam = array('name' => '_link[tickets_id_2]', 'displaywith' => array('id'));
             if (isset($values["_link"])) {
                 $linkparam['value'] = $values["_link"]['tickets_id_2'];
             }
             Ticket::dropdown($linkparam);
             echo "</td></tr></table>";
             echo "</div>";
             if (isset($values["_link"]) && !empty($values["_link"]['tickets_id_2'])) {
                 echo "<script language='javascript'>";
                 echo Html::jsShow("linkedticket{$rand_linked_ticket}");
                 echo "</script>";
             }
         }
         Ticket_Ticket::displayLinkedTicketsTo($ID);
         echo "</td>";
     }
     echo "</tr>";
     // View files added
     echo "<tr class='tab_bg_1'>";
     // Permit to add doc when creating a ticket
     echo "<th style='width:{$colsize1}%'>";
     echo $tt->getBeginHiddenFieldText('_documents_id');
     $doctitle = sprintf(__('File (%s)'), Document::getMaxUploadSize());
     printf(__('%1$s%2$s'), $doctitle, $tt->getMandatoryMark('_documents_id'));
     // Do not show if hidden.
     if (!$tt->isHiddenField('_documents_id')) {
         DocumentType::showAvailableTypesLink();
     }
     echo $tt->getEndHiddenFieldText('_documents_id');
     echo "</th>";
     echo "<td colspan='3'>";
     // Do not set values
     echo $tt->getEndHiddenFieldValue('_documents_id');
     if ($tt->isPredefinedField('_documents_id')) {
         if (isset($values['_documents_id']) && is_array($values['_documents_id']) && count($values['_documents_id'])) {
             echo "<span class='b'>" . __('Default documents:') . '</span>';
             echo "<br>";
             $doc = new Document();
             foreach ($values['_documents_id'] as $key => $val) {
                 if ($doc->getFromDB($val)) {
                     echo "<input type='hidden' name='_documents_id[{$key}]' value='{$val}'>";
                     echo "- " . $doc->getNameID() . "<br>";
                 }
             }
         }
     }
     echo "<div id='fileupload_info'></div>";
     echo "</td>";
     echo "</tr>";
     if ((!$ID || $canupdate || $canupdate_descr || Session::haveRightsOr(self::$rightname, array(self::ASSIGN, self::STEAL, DELETE, PURGE))) && !$options['template_preview']) {
         echo "<tr class='tab_bg_1'>";
         if ($ID) {
             if (Session::haveRightsOr(self::$rightname, array(UPDATE, DELETE, PURGE)) || $this->canDeleteItem() || $this->canUpdateItem()) {
                 echo "<td class='tab_bg_2 center' colspan='4'>";
                 if ($this->fields["is_deleted"] == 1) {
                     if (self::canPurge()) {
                         echo "<input type='submit' class='submit' name='restore' value='" . _sx('button', 'Restore') . "'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
                     }
                 } else {
                     if (self::canUpdate()) {
                         echo "<input type='submit' class='submit' name='update' value='" . _sx('button', 'Save') . "'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
                     }
                 }
                 if ($this->fields["is_deleted"] == 1) {
                     if (self::canPurge()) {
                         echo "<input type='submit' class='submit' name='purge' value='" . _sx('button', 'Delete permanently') . "' " . Html::addConfirmationOnAction(__('Confirm the final deletion?')) . ">";
                     }
                 } else {
                     if ($this->canDeleteItem()) {
                         echo "<input type='submit' class='submit' name='delete' value='" . _sx('button', 'Put in dustbin') . "'>";
                     }
                 }
                 echo "<input type='hidden' name='_read_date_mod' value='" . $this->getField('date_mod') . "'>";
                 echo "</td>";
             }
         } else {
             echo "<td class='tab_bg_2 center' colspan='4'>";
             echo "<input type='submit' name='add' value=\"" . _sx('button', 'Add') . "\" class='submit'>";
             if ($tt->isField('id') && $tt->fields['id'] > 0) {
                 echo "<input type='hidden' name='_tickettemplates_id' value='" . $tt->fields['id'] . "'>";
                 echo "<input type='hidden' name='_predefined_fields'\n                      value=\"" . Toolbox::prepareArrayForInput($predefined_fields) . "\">";
             }
         }
     }
     // File upload system
     $colspan = 3;
     if (!$CFG_GLPI['use_rich_text']) {
         $colspan = 4;
     }
     echo "<tr class='tab_bg_1'>";
     echo "<td colspan='{$colspan}'>";
     echo $tt->getBeginHiddenFieldValue('_documents_id');
     echo Html::file(array('multiple' => true, 'showfilecontainer' => 'fileupload_info', 'values' => array('filename' => $values['_filename'], 'tag' => $values['_tag_filename'])));
     echo "</td>";
     if ($CFG_GLPI['use_rich_text']) {
         echo "</tr>";
         echo "<tr class='tab_bg_1'>";
         echo "<td colspan='{$colspan}'>";
         if (!isset($rand)) {
             $rand = mt_rand();
         }
         if ($canupdate_descr) {
             echo Html::initImagePasteSystem($content_id, $rand);
         }
         echo "</td>";
     }
     echo "</tr>";
     echo "</table>";
     echo "<input type='hidden' name='id' value='{$ID}'>";
     echo "</div>";
     if (!$options['template_preview']) {
         Html::closeForm();
     }
     return true;
 }
 static function deleteRights($user_ID, $only_dynamic = false)
 {
     $crit['users_id'] = $user_ID;
     if ($only_dynamic) {
         $crit['is_dynamic'] = '1';
     }
     $obj = new Profile_User();
     $obj->deleteByCriteria($crit);
 }
Example #24
0
 /**
  * Show Links for an item
  *
  * @param $item                     CommonDBTM object
  * @param $withtemplate    integer  withtemplate param (default '')
  **/
 static function showForItem(CommonDBTM $item, $withtemplate = '')
 {
     global $DB, $CFG_GLPI;
     if (!self::canView()) {
         return false;
     }
     if ($item->isNewID($item->getID())) {
         return false;
     }
     $restrict = $item->getEntityID();
     if ($item->getType() == 'User') {
         $restrict = Profile_User::getEntitiesForUser($item->getID());
     }
     $query = "SELECT `glpi_links`.`id`,\n                       `glpi_links`.`link` AS link,\n                       `glpi_links`.`name` AS name ,\n                       `glpi_links`.`data` AS data,\n                       `glpi_links`.`open_window` AS open_window\n                FROM `glpi_links`\n                INNER JOIN `glpi_links_itemtypes`\n                     ON `glpi_links`.`id` = `glpi_links_itemtypes`.`links_id`\n                WHERE `glpi_links_itemtypes`.`itemtype`='" . $item->getType() . "' " . getEntitiesRestrictRequest(" AND", "glpi_links", "entities_id", $restrict, true) . "\n                ORDER BY name";
     $result = $DB->query($query);
     echo "<div class='spaced'><table class='tab_cadre_fixe'>";
     if ($DB->numrows($result) > 0) {
         echo "<tr><th>" . self::getTypeName(Session::getPluralNumber()) . "</th></tr>";
         while ($data = $DB->fetch_assoc($result)) {
             $links = self::getAllLinksFor($item, $data);
             foreach ($links as $link) {
                 echo "<tr class='tab_bg_2'>";
                 echo "<td class='center'>{$link}</td></tr>";
             }
         }
         echo "</table></div>";
     } else {
         echo "<tr class='tab_bg_2'><th>" . self::getTypeName(Session::getPluralNumber()) . "</th></tr>";
         echo "<tr class='tab_bg_2'><td class='center b'>" . __('No link defined') . "</td></tr>";
         echo "</table></div>";
     }
 }
Example #25
0
 /**
  * Add new mail with lang to current email array
  *
  * @param $data   array of data (mail, lang[, id for user])
  **/
 function addToAddressesList(array $data)
 {
     global $CFG_GLPI;
     // No email set : get default for user
     if (!isset($data['email']) && isset($data['users_id'])) {
         $data['email'] = UserEmail::getDefaultForUser($data['users_id']);
     }
     $new_mail = trim(Toolbox::strtolower($data['email']));
     $new_lang = '';
     // Default USER TYPE is ANONYMOUS
     $notificationoption = array('usertype' => self::ANONYMOUS_USER);
     if (isset($data['language'])) {
         $new_lang = trim($data['language']);
     }
     $username = '';
     if (isset($data['name']) && !empty($data['name'])) {
         $username = $data['name'];
     }
     if (isset($data['users_id']) && $data['users_id'] > 0) {
         $user = new User();
         if (!$user->getFromDB($data['users_id']) || $user->getField('is_deleted') == 1 || $user->getField('is_active') == 0 || !is_null($user->getField('begin_date')) && $user->getField('begin_date') > $_SESSION["glpi_currenttime"] || !is_null($user->getField('end_date')) && $user->getField('end_date') < $_SESSION["glpi_currenttime"]) {
             // unknown, deleted or disabled user
             return false;
         }
         $filt = getEntitiesRestrictRequest('AND', 'glpi_profiles_users', '', $this->getEntity(), true);
         $prof = Profile_User::getUserProfiles($data['users_id'], $filt);
         if (!count($prof)) {
             // No right on the entity of the object
             return false;
         }
         if (empty($username)) {
             $username = formatUserName(0, $user->getField('name'), $user->getField('realname'), $user->getField('firstname'), 0, 0, true);
         }
         // It is a GLPI user :
         $notificationoption['usertype'] = self::GLPI_USER;
         if (Auth::isAlternateAuth($user->fields['authtype']) || $user->fields['authtype'] == Auth::NOT_YET_AUTHENTIFIED && Auth::isAlternateAuth(Auth::checkAlternateAuthSystems())) {
             $notificationoption['usertype'] = self::EXTERNAL_USER;
         }
     }
     // Pass user type as argument ? forced for specific cases
     if (isset($data['usertype'])) {
         $notificationoption['usertype'] = $data['usertype'];
     }
     $notificationoption = array_merge($this->addAdditionnalUserInfo($data), $notificationoption);
     if (!empty($new_mail)) {
         if (NotificationMail::isUserAddressValid($new_mail) && !isset($this->target[$new_mail])) {
             $param = array('language' => empty($new_lang) ? $CFG_GLPI["language"] : $new_lang, 'email' => $new_mail, 'additionnaloption' => $notificationoption, 'username' => $username);
             if (isset($data['users_id']) && $data['users_id']) {
                 $param['users_id'] = $data['users_id'];
             }
             $this->target[$new_mail] = $param;
         }
     }
 }
Example #26
0
 /**
  * @param $users_id
  **/
 static function manageDeletedUserInLdap($users_id)
 {
     global $CFG_GLPI;
     //User is present in DB but not in the directory : it's been deleted in LDAP
     $tmp['id'] = $users_id;
     $myuser = new User();
     switch ($CFG_GLPI['user_deleted_ldap']) {
         //DO nothing
         default:
         case 0:
             break;
             //Put user in dustbin
         //Put user in dustbin
         case 1:
             $myuser->delete($tmp);
             break;
             //Delete all user dynamic habilitations and groups
         //Delete all user dynamic habilitations and groups
         case 2:
             Profile_User::deleteRights($users_id, true);
             Group_User::deleteGroups($users_id, true);
             break;
             //Deactivate the user
         //Deactivate the user
         case 3:
             $tmp['is_active'] = 0;
             $myuser->update($tmp);
             break;
     }
     $changes[0] = '0';
     $changes[1] = '';
     $changes[2] = __('Deleted user in LDAP directory');
     Log::history($users_id, 'User', $changes, 0, Log::HISTORY_LOG_SIMPLE_MESSAGE);
 }
Example #27
0
                }
        }
    } else {
        switch ($_REQUEST['glpi_tab']) {
            case -1:
                $prof->showFormInventory($_POST['target'], true, false);
                $prof->showFormTracking($_POST['target'], false, false);
                $prof->showFormAdmin($_POST['target'], false, true);
                Profile_User::showForProfile($prof);
                Plugin::displayAction($prof, $_REQUEST['glpi_tab']);
                break;
            case 2:
                $prof->showFormTracking($_POST['target']);
                break;
            case 3:
                $prof->showFormAdmin($_POST['target']);
                break;
            case 4:
                Profile_User::showForProfile($prof);
                break;
            case 12:
                Log::showForItem($prof);
                break;
            default:
                if (!Plugin::displayAction($prof, $_REQUEST['glpi_tab'])) {
                    $prof->showFormInventory($_POST['target']);
                }
        }
    }
}
ajaxFooter();