countForItem() static public method

static public countForItem ( CommonDBTM $item )
$item CommonDBTM CommonDBTM object
Ejemplo n.º 1
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;
 }
Ejemplo n.º 2
0
 /**
  * @param $ID
  * @param $options   array
  **/
 function showForm($ID, $options = array())
 {
     global $CFG_GLPI, $DB;
     if (!static::canView()) {
         return false;
     }
     // In percent
     $colsize1 = '13';
     $colsize2 = '37';
     // Set default options
     if (!$ID) {
         $values = array('_users_id_requester' => Session::getLoginUserID(), '_users_id_requester_notif' => array('use_notification' => 1, 'alternative_email' => ''), '_groups_id_requester' => 0, '_users_id_assign' => 0, '_users_id_assign_notif' => array('use_notification' => 1, 'alternative_email' => ''), '_groups_id_assign' => 0, '_users_id_observer' => 0, '_users_id_observer_notif' => array('use_notification' => 1, 'alternative_email' => ''), '_groups_id_observer' => 0, '_suppliers_id_assign' => 0, 'priority' => 3, 'urgency' => 3, 'impact' => 3, 'content' => '', 'name' => '', 'entities_id' => $_SESSION['glpiactive_entity'], 'itilcategories_id' => 0);
         foreach ($values as $key => $val) {
             if (!isset($options[$key])) {
                 $options[$key] = $val;
             }
         }
         if (isset($options['tickets_id'])) {
             $ticket = new Ticket();
             if ($ticket->getFromDB($options['tickets_id'])) {
                 $options['content'] = $ticket->getField('content');
                 $options['name'] = $ticket->getField('name');
                 $options['impact'] = $ticket->getField('impact');
                 $options['urgency'] = $ticket->getField('urgency');
                 $options['priority'] = $ticket->getField('priority');
                 $options['itilcategories_id'] = $ticket->getField('itilcategories_id');
             }
         }
     }
     $this->initForm($ID, $options);
     $showuserlink = 0;
     if (Session::haveRight('user', 'r')) {
         $showuserlink = 1;
     }
     $this->showTabs($options);
     $this->showFormHeader($options);
     echo "<tr class='tab_bg_1'>";
     echo "<th class='left' width='{$colsize1}%'>" . __('Opening date') . "</th>";
     echo "<td class='left' width='{$colsize2}%'>";
     if (isset($options['tickets_id'])) {
         echo "<input type='hidden' name='_tickets_id' value='" . $options['tickets_id'] . "'>";
     }
     $date = $this->fields["date"];
     if (!$ID) {
         $date = date("Y-m-d H:i:s");
     }
     Html::showDateTimeFormItem("date", $date, 1, false);
     echo "</td>";
     echo "<th width='{$colsize1}%'>" . __('Due date') . "</th>";
     echo "<td width='{$colsize2}%' class='left'>";
     if ($this->fields["due_date"] == 'NULL') {
         $this->fields["due_date"] = '';
     }
     Html::showDateTimeFormItem("due_date", $this->fields["due_date"], 1, true);
     echo "</td></tr>";
     if ($ID) {
         echo "<tr class='tab_bg_1'><th>" . __('By') . "</th><td>";
         User::dropdown(array('name' => 'users_id_recipient', 'value' => $this->fields["users_id_recipient"], 'entity' => $this->fields["entities_id"], 'right' => 'all'));
         echo "</td>";
         echo "<th>" . __('Last update') . "</th>";
         echo "<td>" . Html::convDateTime($this->fields["date_mod"]) . "\n";
         if ($this->fields['users_id_lastupdater'] > 0) {
             printf(__('%1$s: %2$s'), __('By'), getUserName($this->fields["users_id_lastupdater"], $showuserlink));
         }
         echo "</td></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>" . __('Date of solving') . "</th>";
         echo "<td>";
         Html::showDateTimeFormItem("solvedate", $this->fields["solvedate"], 1, false);
         echo "</td>";
         if (in_array($this->fields["status"], $this->getClosedStatusArray())) {
             echo "<th>" . __('Closing date') . "</th>";
             echo "<td>";
             Html::showDateTimeFormItem("closedate", $this->fields["closedate"], 1, false);
             echo "</td>";
         } else {
             echo "<td colspan='2'>&nbsp;</td>";
         }
         echo "</tr>";
     }
     echo "</table>";
     echo "<table class='tab_cadre_fixe' id='mainformtable2'>";
     echo "<tr class='tab_bg_1'>";
     echo "<th width='{$colsize1}%'>" . __('Status') . "</th>";
     echo "<td width='{$colsize2}%'>";
     self::dropdownStatus(array('value' => $this->fields["status"], 'showtype' => 'allowed'));
     echo "</td>";
     echo "<th width='{$colsize1}%'>" . __('Urgency') . "</th>";
     echo "<td width='{$colsize2}%'>";
     // Only change during creation OR when allowed to change priority OR when user is the creator
     $idurgency = self::dropdownUrgency(array('value' => $this->fields["urgency"]));
     echo "</td></tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<th>" . __('Category') . "</th>";
     echo "<td >";
     $opt = array('value' => $this->fields["itilcategories_id"], 'entity' => $this->fields["entities_id"], 'condition' => "`is_problem`='1'");
     ITILCategory::dropdown($opt);
     echo "</td>";
     echo "<th>" . __('Impact') . "</th>";
     echo "<td>";
     $idimpact = self::dropdownImpact(array('value' => $this->fields["impact"]));
     echo "</td></tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<th>" . __('Total duration') . "</th>";
     echo "<td>" . parent::getActionTime($this->fields["actiontime"]) . "</td>";
     echo "<th class='left'>" . __('Priority') . "</th>";
     echo "<td>";
     $idpriority = parent::dropdownPriority(array('value' => $this->fields["priority"], 'withmajor' => true));
     $idajax = 'change_priority_' . mt_rand();
     echo "&nbsp;<span id='{$idajax}' style='display:none'></span>";
     $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 "</table>";
     $this->showActorsPartForm($ID, $options);
     echo "<table class='tab_cadre_fixe' id='mainformtable3'>";
     echo "<tr class='tab_bg_1'>";
     echo "<th width='{$colsize1}%'>" . __('Title') . "</th>";
     echo "<td colspan='3'>";
     $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' => 110, 'name' => 'name', 'data' => rawurlencode($this->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($this->fields["name"])) {
         _e('Without title');
     } else {
         echo $this->fields["name"];
     }
     echo "</div>\n";
     echo "<div id='viewname{$rand}'></div>\n";
     if (!$ID) {
         echo "<script type='text/javascript' >\n\n         showName{$rand}();\n         </script>";
     }
     echo "</td></tr>";
     echo "<tr class='tab_bg_1'>";
     echo "<th>" . __('Description') . "</th>";
     echo "<td colspan='3'>";
     $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' => 110, 'name' => 'content', 'data' => rawurlencode($this->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($this->fields["content"])) {
         echo nl2br($this->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 "</td></tr>";
     if ($ID) {
         echo "<tr class='tab_bg_1'>";
         echo "<th colspan='2'  width='" . ($colsize1 + $colsize2) . "%'>";
         $docnb = Document_Item::countForItem($this);
         echo "<a href=\"" . $this->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>";
         echo "<td colspan='2'></td>";
         echo "</tr>";
     }
     $options['colspan'] = 2;
     $this->showFormButtons($options);
     $this->addDivForTabs();
     return true;
 }
Ejemplo n.º 3
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;
 }
Ejemplo n.º 4
0
 function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)
 {
     if (!$withtemplate) {
         if ($item->getType() == __CLASS__) {
             return __('See the map', 'positions');
         } else {
             if ($item->getType() == "Location") {
                 if ($_SESSION['glpishow_count_on_tabs']) {
                     return self::createTabEntry(Document::getTypeName(Session::getPluralNumber()), Document_Item::countForItem($item));
                 }
                 return Document::getTypeName(Session::getPluralNumber());
             } else {
                 if (in_array($item->getType(), self::getTypes(true)) && Session::haveRight('plugin_positions', READ)) {
                     if ($_SESSION['glpishow_count_on_tabs']) {
                         return self::createTabEntry(self::getTypeName(Session::getPluralNumber()), self::countForItem($item));
                     }
                     return self::getTypeName(Session::getPluralNumber());
                 }
             }
         }
     }
     return '';
 }