/** * display a value according to a field * * @since version 0.83 * * @param $field String name of the field * @param $values String / Array with the value to display * @param $options Array of option * * @return a string **/ static function getSpecificValueToDisplay($field, $values, array $options = array()) { if (!is_array($values)) { $values = array($field => $values); } switch ($field) { case 'priority': return CommonITILObject::getPriorityName($values[$field]); case 'visibility': return self::getVisibilityName($values[$field]); case 'state': return Planning::getState($values[$field]); } return parent::getSpecificValueToDisplay($field, $values, $options); }
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'> </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 " <a class='vsubmit' href='" . $this->getLinkURL() . "&forcetab=TicketFollowup\$1&_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 " <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 " <a href='" . $this->getFormURL() . "?id=" . $ID . "&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 " "; 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') . "'> "; } } else { if (self::canUpdate()) { echo "<input type='submit' class='submit' name='update' value='" . _sx('button', 'Save') . "'> "; } } 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; }
/** * Display a line for a ticket * * @param $id Integer ID of the ticket * @param $followups Boolean show followup columns * @param $output_type Integer type of output (default Search::HTML_OUTPUT) * @param $row_num Integer row number (default 0) * @param $id_for_massaction Integer default 0 means no massive action (default 0) * */ static function showShort($id, $followups, $output_type = Search::HTML_OUTPUT, $row_num = 0, $id_for_massaction = 0) { global $CFG_GLPI; $rand = mt_rand(); /// TODO to be cleaned. Get datas and clean display links // Prints a job in short form // Should be called in a <table>-segment // Print links or not in case of user view // Make new job object and fill it from database, if success, print it $job = new self(); $candelete = Session::haveRight("delete_ticket", "1"); $canupdate = Session::haveRight("update_ticket", "1"); $showprivate = Session::haveRight("show_full_ticket", "1"); $align = "class='center"; $align_desc = "class='left"; if ($followups) { $align .= " top'"; $align_desc .= " top'"; } else { $align .= "'"; $align_desc .= "'"; } if ($job->getFromDB($id)) { $item_num = 1; $bgcolor = $_SESSION["glpipriority_" . $job->fields["priority"]]; echo Search::showNewLine($output_type, $row_num % 2); $check_col = ''; if (($candelete || $canupdate) && $output_type == Search::HTML_OUTPUT && $id_for_massaction) { $check_col = Html::getMassiveActionCheckBox(__CLASS__, $id_for_massaction); } echo Search::showItem($output_type, $check_col, $item_num, $row_num, $align); // First column $first_col = sprintf(__('%1$s: %2$s'), __('ID'), $job->fields["id"]); if ($output_type == Search::HTML_OUTPUT) { $first_col .= "<br><img src='" . self::getStatusIconURL($job->fields["status"]) . "'\n alt=\"" . self::getStatus($job->fields["status"]) . "\" title=\"" . self::getStatus($job->fields["status"]) . "\">"; } else { $first_col = sprintf(__('%1$s - %2$s'), $first_col, self::getStatus($job->fields["status"])); } echo Search::showItem($output_type, $first_col, $item_num, $row_num, $align); // Second column if ($job->fields['status'] == self::CLOSED) { $second_col = sprintf(__('Closed on %s'), ($output_type == Search::HTML_OUTPUT ? '<br>' : '') . Html::convDateTime($job->fields['closedate'])); } else { if ($job->fields['status'] == self::SOLVED) { $second_col = sprintf(__('Solved on %s'), ($output_type == Search::HTML_OUTPUT ? '<br>' : '') . Html::convDateTime($job->fields['solvedate'])); } else { if ($job->fields['begin_waiting_date']) { $second_col = sprintf(__('Put on hold on %s'), ($output_type == Search::HTML_OUTPUT ? '<br>' : '') . Html::convDateTime($job->fields['begin_waiting_date'])); } else { if ($job->fields['due_date']) { $second_col = sprintf(__('%1$s: %2$s'), __('Due date'), ($output_type == Search::HTML_OUTPUT ? '<br>' : '') . Html::convDateTime($job->fields['due_date'])); } else { $second_col = sprintf(__('Opened on %s'), ($output_type == Search::HTML_OUTPUT ? '<br>' : '') . Html::convDateTime($job->fields['date'])); } } } } echo Search::showItem($output_type, $second_col, $item_num, $row_num, $align . " width=130"); // Second BIS column $second_col = Html::convDateTime($job->fields["date_mod"]); echo Search::showItem($output_type, $second_col, $item_num, $row_num, $align . " width=90"); // Second TER column if (count($_SESSION["glpiactiveentities"]) > 1) { $second_col = Dropdown::getDropdownName('glpi_entities', $job->fields['entities_id']); echo Search::showItem($output_type, $second_col, $item_num, $row_num, $align . " width=100"); } // Third Column echo Search::showItem($output_type, "<span class='b'>" . parent::getPriorityName($job->fields["priority"]) . "</span>", $item_num, $row_num, "{$align} bgcolor='{$bgcolor}'"); // Fourth Column $fourth_col = ""; if (isset($job->users[CommonITILActor::REQUESTER]) && count($job->users[CommonITILActor::REQUESTER])) { foreach ($job->users[CommonITILActor::REQUESTER] as $d) { $userdata = getUserName($d["users_id"], 2); $fourth_col .= sprintf(__('%1$s %2$s'), "<span class='b'>" . $userdata['name'] . "</span>", Html::showToolTip($userdata["comment"], array('link' => $userdata["link"], 'display' => false))); $fourth_col .= "<br>"; } } if (isset($job->groups[CommonITILActor::REQUESTER]) && count($job->groups[CommonITILActor::REQUESTER])) { foreach ($job->groups[CommonITILActor::REQUESTER] as $d) { $fourth_col .= Dropdown::getDropdownName("glpi_groups", $d["groups_id"]); $fourth_col .= "<br>"; } } echo Search::showItem($output_type, $fourth_col, $item_num, $row_num, $align); // Fifth column $fifth_col = ""; if (isset($job->users[CommonITILActor::ASSIGN]) && count($job->users[CommonITILActor::ASSIGN])) { foreach ($job->users[CommonITILActor::ASSIGN] as $d) { $userdata = getUserName($d["users_id"], 2); $fifth_col .= sprintf(__('%1$s %2$s'), "<span class='b'>" . $userdata['name'] . "</span>", Html::showToolTip($userdata["comment"], array('link' => $userdata["link"], 'display' => false))); $fifth_col .= "<br>"; } } if (isset($job->groups[CommonITILActor::ASSIGN]) && count($job->groups[CommonITILActor::ASSIGN])) { foreach ($job->groups[CommonITILActor::ASSIGN] as $d) { $fifth_col .= Dropdown::getDropdownName("glpi_groups", $d["groups_id"]); $fifth_col .= "<br>"; } } if (isset($job->suppliers[CommonITILActor::ASSIGN]) && count($job->suppliers[CommonITILActor::ASSIGN])) { foreach ($job->suppliers[CommonITILActor::ASSIGN] as $d) { $fifth_col .= Dropdown::getDropdownName("glpi_suppliers", $d["suppliers_id"]); $fifth_col .= "<br>"; } } echo Search::showItem($output_type, $fifth_col, $item_num, $row_num, $align); // Sixth Colum $sixth_col = ""; $is_deleted = false; if (!empty($job->fields["itemtype"]) && $job->fields["items_id"] > 0) { if ($item = getItemForItemtype($job->fields["itemtype"])) { if ($item->getFromDB($job->fields["items_id"])) { $is_deleted = $item->isDeleted(); $sixth_col .= $item->getTypeName(); $sixth_col .= "<br><span class='b'>"; if ($item->canView()) { $sixth_col .= $item->getLink(array('linkoption' => $output_type == Search::HTML_OUTPUT)); } else { $sixth_col .= $item->getNameID(); } $sixth_col .= "</span>"; } } } else { if (empty($job->fields["itemtype"])) { $sixth_col = __('General'); } } echo Search::showItem($output_type, $sixth_col, $item_num, $row_num, $is_deleted ? " class='center deleted' " : $align); // Seventh column echo Search::showItem($output_type, "<span class='b'>" . Dropdown::getDropdownName('glpi_itilcategories', $job->fields["itilcategories_id"]) . "</span>", $item_num, $row_num, $align); // Eigth column $eigth_column = "<span class='b'>" . $job->fields["name"] . "</span> "; // Add link if ($job->canViewItem()) { $eigth_column = "<a id='ticket" . $job->fields["id"] . "{$rand}' href=\"" . $CFG_GLPI["root_doc"] . "/front/ticket.form.php?id=" . $job->fields["id"] . "\">{$eigth_column}</a>"; if ($followups && $output_type == Search::HTML_OUTPUT) { $eigth_column .= TicketFollowup::showShortForTicket($job->fields["id"]); } else { $eigth_column = sprintf(__('%1$s (%2$s)'), $eigth_column, sprintf(__('%1$s - %2$s'), $job->numberOfFollowups($showprivate), $job->numberOfTasks($showprivate))); } } if ($output_type == Search::HTML_OUTPUT) { $eigth_column = sprintf(__('%1$s %2$s'), $eigth_column, Html::showToolTip($job->fields['content'], array('display' => false, 'applyto' => "ticket" . $job->fields["id"] . $rand))); } echo Search::showItem($output_type, $eigth_column, $item_num, $row_num, $align_desc . "width='300'"); // Finish Line echo Search::showEndLine($output_type); } else { echo "<tr class='tab_bg_2'>"; echo "<td colspan='6' ><i>" . __('No ticket in progress.') . "</i></td></tr>"; } }
/** * Generate link for ticket satisfaction * * @since version 0.84 (before in entitydata.class) * * @param $ticket ticket object * * @return url contents **/ static function generateLinkSatisfaction($ticket) { global $DB; $url = self::getUsedConfig('inquest_config', $ticket->fields['entities_id'], 'inquest_URL'); if (strstr($url, "[TICKET_ID]")) { $url = str_replace("[TICKET_ID]", $ticket->fields['id'], $url); } if (strstr($url, "[TICKET_NAME]")) { $url = str_replace("[TICKET_NAME]", urlencode($ticket->fields['name']), $url); } if (strstr($url, "[TICKET_CREATEDATE]")) { $url = str_replace("[TICKET_CREATEDATE]", $ticket->fields['date'], $url); } if (strstr($url, "[TICKET_SOLVEDATE]")) { $url = str_replace("[TICKET_SOLVEDATE]", $ticket->fields['solvedate'], $url); } if (strstr($url, "[REQUESTTYPE_ID]")) { $url = str_replace("[REQUESTTYPE_ID]", $ticket->fields['requesttypes_id'], $url); } if (strstr($url, "[REQUESTTYPE_NAME]")) { $url = str_replace("[REQUESTTYPE_NAME]", urlencode(Dropdown::getDropdownName('glpi_requesttypes', $ticket->fields['requesttypes_id'])), $url); } if (strstr($url, "[TICKET_PRIORITY]")) { $url = str_replace("[TICKET_PRIORITY]", $ticket->fields['priority'], $url); } if (strstr($url, "[TICKET_PRIORITYNAME]")) { $url = str_replace("[TICKET_PRIORITYNAME]", urlencode(CommonITILObject::getPriorityName($ticket->fields['priority'])), $url); } if (strstr($url, "[TICKETCATEGORY_ID]")) { $url = str_replace("[TICKETCATEGORY_ID]", $ticket->fields['itilcategories_id'], $url); } if (strstr($url, "[TICKETCATEGORY_NAME]")) { $url = str_replace("[TICKETCATEGORY_NAME]", urlencode(Dropdown::getDropdownName('glpi_itilcategories', $ticket->fields['itilcategories_id'])), $url); } if (strstr($url, "[TICKETTYPE_ID]")) { $url = str_replace("[TICKETTYPE_ID]", $ticket->fields['type'], $url); } if (strstr($url, "[TICKET_TYPENAME]")) { $url = str_replace("[TICKET_TYPENAME]", Ticket::getTicketTypeName($ticket->fields['type']), $url); } if (strstr($url, "[SOLUTIONTYPE_ID]")) { $url = str_replace("[SOLUTIONTYPE_ID]", $ticket->fields['solutiontypes_id'], $url); } if (strstr($url, "[SOLUTIONTYPE_NAME]")) { $url = str_replace("[SOLUTIONTYPE_NAME]", urlencode(Dropdown::getDropdownName('glpi_solutiontypes', $ticket->fields['solutiontypes_id'])), $url); } if (strstr($url, "[SLA_ID]")) { $url = str_replace("[SLA_ID]", $ticket->fields['slas_id'], $url); } if (strstr($url, "[SLA_NAME]")) { $url = str_replace("[SLA_NAME]", urlencode(Dropdown::getDropdownName('glpi_slas', $ticket->fields['slas_id'])), $url); } if (strstr($url, "[SLALEVEL_ID]")) { $url = str_replace("[SLALEVEL_ID]", $ticket->fields['slalevels_id'], $url); } if (strstr($url, "[SLALEVEL_NAME]")) { $url = str_replace("[SLALEVEL_NAME]", urlencode(Dropdown::getDropdownName('glpi_slalevels', $ticket->fields['slalevels_id'])), $url); } return $url; }
/** * @see NotificationTarget::getDatasForTemplate() **/ function getDatasForTemplate($event, $options = array()) { global $CFG_GLPI, $DB; //----------- Reservation infos -------------- // $events = $this->getAllEvents(); $item = $this->obj; $this->datas['##project.action##'] = $events[$event]; $this->datas['##project.url##'] = $this->formatURL($options['additionnaloption']['usertype'], "Project_" . $item->getField("id")); $this->datas["##project.name##"] = $item->getField('name'); $this->datas["##project.code##"] = $item->getField('code'); $this->datas["##project.description##"] = $item->getField('content'); $this->datas["##project.comments##"] = $item->getField('comment'); $this->datas["##project.creationdate##"] = Html::convDateTime($item->getField('date')); $this->datas["##project.lastupdatedate##"] = Html::convDateTime($item->getField('date_mod')); $this->datas["##project.priority##"] = CommonITILObject::getPriorityName($item->getField('priority')); $this->datas["##project.percent##"] = Dropdown::getValueWithUnit($item->getField('percent_done'), "%"); $this->datas["##project.planstartdate##"] = Html::convDateTime($item->getField('plan_start_date')); $this->datas["##project.planenddate##"] = Html::convDateTime($item->getField('plan_end_date')); $this->datas["##project.realstartdate##"] = Html::convDateTime($item->getField('real_start_date')); $this->datas["##project.realenddate##"] = Html::convDateTime($item->getField('real_end_date')); $this->datas["##project.plannedduration##"] = Html::timestampToString(ProjectTask::getTotalPlannedDurationForProject($item->getID()), false); $this->datas["##project.effectiveduration##"] = Html::timestampToString(ProjectTask::getTotalEffectiveDurationForProject($item->getID()), false); $entity = new Entity(); $this->datas["##project.entity##"] = ''; $this->datas["##project.shortentity##"] = ''; if ($entity->getFromDB($this->getEntity())) { $this->datas["##project.entity##"] = $entity->getField('completename'); $this->datas["##project.shortentity##"] = $entity->getField('name'); } $this->datas["##project.father##"] = ''; if ($item->getField('projects_id')) { $this->datas["##project.father##"] = Dropdown::getDropdownName('glpi_projects', $item->getField('projects_id')); } $this->datas["##project.state##"] = ''; if ($item->getField('projectstates_id')) { $this->datas["##project.state##"] = Dropdown::getDropdownName('glpi_projectstates', $item->getField('projectstates_id')); } $this->datas["##project.type##"] = ''; if ($item->getField('projecttypes_id')) { $this->datas["##project.type##"] = Dropdown::getDropdownName('glpi_projecttypes', $item->getField('projecttypes_id')); } $this->datas["##project.manager##"] = ''; if ($item->getField('users_id')) { $user_tmp = new User(); $user_tmp->getFromDB($item->getField('users_id')); $this->datas["##project.manager##"] = $user_tmp->getName(); } $this->datas["##project.managergroup##"] = ''; if ($item->getField('groups_id')) { $this->datas["##project.managergroup##"] = Dropdown::getDropdownName('glpi_groups', $item->getField('groups_id')); } // Team infos $restrict = "`projects_id` = '" . $item->getField('id') . "'"; $items = getAllDatasFromTable('glpi_projectteams', $restrict); $this->datas['teammembers'] = array(); if (count($items)) { foreach ($items as $data) { if ($item2 = getItemForItemtype($data['itemtype'])) { if ($item2->getFromDB($data['items_id'])) { $tmp = array(); $tmp['##teammember.itemtype##'] = $item2->getTypeName(); $tmp['##teammember.name##'] = $item2->getName(); $this->datas['teammembers'][] = $tmp; } } } } $this->datas['##project.numberofteammembers##'] = count($this->datas['teammembers']); // Task infos $restrict = "`projects_id`='" . $item->getField('id') . "'"; $restrict .= " ORDER BY `date` DESC, `id` ASC"; $tasks = getAllDatasFromTable('glpi_projecttasks', $restrict); $this->datas['tasks'] = array(); foreach ($tasks as $task) { $tmp = array(); $tmp['##task.creationdate##'] = Html::convDateTime($task['date']); $tmp['##task.lastupdatedate##'] = Html::convDateTime($task['date_mod']); $tmp['##task.name##'] = $task['name']; $tmp['##task.description##'] = $task['content']; $tmp['##task.comments##'] = $task['comment']; $tmp['##task.state##'] = Dropdown::getDropdownName('glpi_projectstates', $task['projectstates_id']); $tmp['##task.type##'] = Dropdown::getDropdownName('glpi_projecttasktypes', $task['projecttasktypes_id']); $tmp['##task.percent##'] = Dropdown::getValueWithUnit($task['percent_done'], "%"); $this->datas["##task.planstartdate##"] = ''; $this->datas["##task.planenddate##"] = ''; $this->datas["##task.realstartdate##"] = ''; $this->datas["##task.realenddate##"] = ''; if (!is_null($task['plan_start_date'])) { $tmp['##task.planstartdate##'] = Html::convDateTime($task['plan_start_date']); } if (!is_null($task['plan_end_date'])) { $tmp['##task.planenddate##'] = Html::convDateTime($task['plan_end_date']); } if (!is_null($task['real_start_date'])) { $tmp['##task.realstartdate##'] = Html::convDateTime($task['real_start_date']); } if (!is_null($task['real_end_date'])) { $tmp['##task.realenddate##'] = Html::convDateTime($task['real_end_date']); } $this->datas['tasks'][] = $tmp; } $this->datas["##project.numberoftasks##"] = count($this->datas['tasks']); //costs infos $restrict = "`projects_id`='" . $item->getField('id') . "'"; $restrict .= " ORDER BY `begin_date` DESC, `id` ASC"; $costs = getAllDatasFromTable('glpi_projectcosts', $restrict); $this->datas['costs'] = array(); $this->datas["##project.totalcost##"] = 0; foreach ($costs as $cost) { $tmp = array(); $tmp['##cost.name##'] = $cost['name']; $tmp['##cost.comment##'] = $cost['comment']; $tmp['##cost.datebegin##'] = Html::convDate($cost['begin_date']); $tmp['##cost.dateend##'] = Html::convDate($cost['end_date']); $tmp['##cost.cost##'] = Html::formatNumber($cost['cost']); $tmp['##cost.budget##'] = Dropdown::getDropdownName('glpi_budgets', $cost['budgets_id']); $this->datas["##project.totalcost##"] += $cost['cost']; $this->datas['costs'][] = $tmp; /// TODO add ticket costs ? } $this->datas["##project.numberofcosts##"] = count($this->datas['costs']); // History infos $this->datas['log'] = array(); // Use list_limit_max or load the full history ? foreach (Log::getHistoryData($item, 0, $CFG_GLPI['list_limit_max']) as $data) { $tmp = array(); $tmp["##project.log.date##"] = $data['date_mod']; $tmp["##project.log.user##"] = $data['user_name']; $tmp["##project.log.field##"] = $data['field']; $tmp["##project.log.content##"] = $data['change']; $this->datas['log'][] = $tmp; } $this->datas["##project.numberoflogs##"] = count($this->datas['log']); // Changes infos $restrict = "`projects_id`='" . $item->getField('id') . "'"; $changes = getAllDatasFromTable('glpi_changes_projects', $restrict); $this->datas['changes'] = array(); if (count($changes)) { $change = new Change(); foreach ($changes as $data) { if ($change->getFromDB($data['changes_id'])) { $tmp = array(); $tmp['##change.id##'] = $data['changes_id']; $tmp['##change.date##'] = $change->getField('date'); $tmp['##change.title##'] = $change->getField('name'); $tmp['##change.url##'] = $this->formatURL($options['additionnaloption']['usertype'], "change_" . $data['changes_id']); $tmp['##change.content##'] = $change->getField('content'); $this->datas['changes'][] = $tmp; } } } $this->datas['##project.numberofchanges##'] = count($this->datas['changes']); // Document $query = "SELECT `glpi_documents`.*\n FROM `glpi_documents`\n LEFT JOIN `glpi_documents_items`\n ON (`glpi_documents`.`id` = `glpi_documents_items`.`documents_id`)\n WHERE `glpi_documents_items`.`itemtype` = 'Project'\n AND `glpi_documents_items`.`items_id` = '" . $item->getField('id') . "'"; $this->datas["documents"] = array(); if ($result = $DB->query($query)) { while ($data = $DB->fetch_assoc($result)) { $tmp = array(); $tmp['##document.id##'] = $data['id']; $tmp['##document.name##'] = $data['name']; $tmp['##document.weblink##'] = $data['link']; $tmp['##document.url##'] = $this->formatURL($options['additionnaloption']['usertype'], "document_" . $data['id']); $downloadurl = "/front/document.send.php?docid=" . $data['id']; $tmp['##document.downloadurl##'] = $this->formatURL($options['additionnaloption']['usertype'], $downloadurl); $tmp['##document.heading##'] = Dropdown::getDropdownName('glpi_documentcategories', $data['documentcategories_id']); $tmp['##document.filename##'] = $data['filename']; $this->datas['documents'][] = $tmp; } } $this->datas["##project.urldocument##"] = $this->formatURL($options['additionnaloption']['usertype'], "Project_" . $item->getField("id") . '_Document_Item$1'); $this->datas["##project.numberofdocuments##"] = count($this->datas['documents']); // Items infos $restrict = "`projects_id` = '" . $item->getField('id') . "'"; $items = getAllDatasFromTable('glpi_items_projects', $restrict); $this->datas['items'] = array(); if (count($items)) { foreach ($items as $data) { if ($item2 = getItemForItemtype($data['itemtype'])) { if ($item2->getFromDB($data['items_id'])) { $tmp = array(); $tmp['##item.itemtype##'] = $item2->getTypeName(); $tmp['##item.name##'] = $item2->getField('name'); $tmp['##item.serial##'] = $item2->getField('serial'); $tmp['##item.otherserial##'] = $item2->getField('otherserial'); $tmp['##item.contact##'] = $item2->getField('contact'); $tmp['##item.contactnum##'] = $item2->getField('contactnum'); $tmp['##item.location##'] = ''; $tmp['##item.user##'] = ''; $tmp['##item.group##'] = ''; $tmp['##item.model##'] = ''; //Object location if ($item2->getField('locations_id') != NOT_AVAILABLE) { $tmp['##item.location##'] = Dropdown::getDropdownName('glpi_locations', $item2->getField('locations_id')); } //Object user if ($item2->getField('users_id')) { $user_tmp = new User(); if ($user_tmp->getFromDB($item2->getField('users_id'))) { $tmp['##item.user##'] = $user_tmp->getName(); } } //Object group if ($item2->getField('groups_id')) { $tmp['##item.group##'] = Dropdown::getDropdownName('glpi_groups', $item2->getField('groups_id')); } $modeltable = getSingular($item2->getTable()) . "models"; $modelfield = getForeignKeyFieldForTable($modeltable); if ($item2->isField($modelfield)) { $tmp['##item.model##'] = $item2->getField($modelfield); } $this->datas['items'][] = $tmp; } } } } $this->datas['##project.numberofitems##'] = count($this->datas['items']); $this->getTags(); foreach ($this->tag_descriptions[NotificationTarget::TAG_LANGUAGE] as $tag => $values) { if (!isset($this->datas[$tag])) { $this->datas[$tag] = $values['label']; } } }
function getWidgetContentForItem($widgetId) { global $CFG_GLPI, $DB; if (empty($this->form)) { $this->init(); } switch ($widgetId) { case $this->getType() . "1": $plugin = new Plugin(); if ($plugin->isActivated("tasklists")) { $widget = new PluginMydashboardDatatable(); $headers = array(__('Name'), __('Priority'), _n('Context', 'Contexts', 1, 'tasklists'), __('User'), __('Percent done'), __('Due date'), __('Action')); $query = "SELECT `glpi_plugin_tasklists_tasks`.*,`glpi_plugin_tasklists_tasktypes`.`completename` as 'type' \n FROM `glpi_plugin_tasklists_tasks`\n LEFT JOIN `glpi_plugin_tasklists_tasktypes` ON (`glpi_plugin_tasklists_tasks`.`plugin_tasklists_tasktypes_id` = `glpi_plugin_tasklists_tasktypes`.`id`) \n WHERE NOT `glpi_plugin_tasklists_tasks`.`is_deleted`\n AND `glpi_plugin_tasklists_tasks`.`state` < 2 "; $query .= getEntitiesRestrictRequest('AND', 'glpi_plugin_tasklists_tasks'); $query .= "ORDER BY `glpi_plugin_tasklists_tasks`.`priority`DESC "; $tasks = array(); if ($result = $DB->query($query)) { if ($DB->numrows($result)) { while ($data = $DB->fetch_array($result)) { //$groups = Group_User::getGroupUsers($data['groups_id']); $groupusers = Group_User::getGroupUsers($data['groups_id']); $groups = array(); foreach ($groupusers as $groupuser) { $groups[] = $groupuser["id"]; } if ($data['visibility'] == 1 && $data['users_id'] == Session::getLoginUserID() || $data['visibility'] == 2 && ($data['users_id'] == Session::getLoginUserID() || in_array(Session::getLoginUserID(), $groups)) || $data['visibility'] == 3) { $ID = $data['id']; $rand = mt_rand(); $url = Toolbox::getItemTypeFormURL("PluginTasklistsTask") . "?id=" . $data['id']; $tasks[$data['id']][0] = "<a id='task" . $data["id"] . $rand . "' target='_blank' href='{$url}'>" . $data['name'] . "</a>"; $tasks[$data['id']][0] .= Html::showToolTip($data['comment'], array('applyto' => 'task' . $data["id"] . $rand, 'display' => false)); $bgcolor = $_SESSION["glpipriority_" . $data['priority']]; $tasks[$data['id']][1] = "<div class='center' style='background-color:{$bgcolor};'>" . CommonITILObject::getPriorityName($data['priority']) . "</div>"; $tasks[$data['id']][2] = $data['type']; $tasks[$data['id']][3] = getUserName($data['users_id']); $tasks[$data['id']][4] = Dropdown::getValueWithUnit($data['percent_done'], "%"); $due_date = $data['due_date']; $display = Html::convDate($data['due_date']); if ($due_date <= date('Y-m-d') && !empty($due_date)) { $display = "<div class='deleted'>" . Html::convDate($data['due_date']) . "</div>"; } $tasks[$data['id']][5] = $display; $tasks[$data['id']][6] = "<div align='center'>"; if (Session::haveRight("plugin_tasklists", UPDATE)) { $tasks[$data['id']][6] .= "<a class='pointer' onclick=\" submitGetLink('" . $CFG_GLPI['root_doc'] . "/plugins/tasklists/front/task.form.php', {'done': 'done', 'id': '" . $data['id'] . "', '_glpi_csrf_token': '" . Session::getNewCSRFToken() . "', '_glpi_simple_form': '1'});\"><img src='" . $CFG_GLPI['root_doc'] . "/plugins/tasklists/pics/ok.png' title='" . __('Mark as done', 'tasklists') . "'></a>"; } if (Session::haveRight("plugin_tasklists", UPDATENOTE)) { $link = " <a href=\"javascript:" . Html::jsGetElementbyID('comment' . $rand) . ".dialog('open');\">"; $link .= "<img class='pointer' src='" . $CFG_GLPI['root_doc'] . "/plugins/tasklists/pics/plus.png' title='" . __('Add comment', 'tasklists') . "'>"; $link .= "</a>"; $link .= Ajax::createIframeModalWindow('comment' . $rand, $CFG_GLPI["root_doc"] . "/plugins/tasklists/front/comment.form.php?id=" . $ID, array('title' => __('Add comment', 'tasklists'), 'reloadonclose' => false, 'width' => 1100, 'display' => false, 'height' => 300)); $tasks[$data['id']][6] .= $link; } $tasks[$data['id']][6] .= "</div>"; } } } } $widget->setTabDatas($tasks); $widget->setTabNames($headers); $widget->setOption("bSort", false); $widget->toggleWidgetRefresh(); $link = "<div align='right'><a class='vsubmit' href=\"javascript:" . Html::jsGetElementbyID('task') . ".dialog('open');\">"; $link .= __('Add task', 'tasklists'); $link .= "</a></div>"; $link .= Ajax::createIframeModalWindow('task', $CFG_GLPI["root_doc"] . "/plugins/tasklists/front/task.form.php", array('title' => __('Add task', 'tasklists'), 'reloadonclose' => false, 'width' => 1180, 'display' => false, 'height' => 600)); $widget->appendWidgetHtmlContent($link); $widget->setWidgetTitle(__("Tasks list", 'tasklists')); return $widget; } else { $widget = new PluginMydashboardDatatable(); $widget->setWidgetTitle(__("Tasks list", 'tasklists')); return $widget; } break; } }