static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) { switch ($item->getType()) { case 'PluginFormcreatorForm': Document_Item::displayTabContentForItem($item); break; } return true; }
/** * Clean the date in the relation tables for the deleted item * Clear N/N Relation **/ function cleanRelationTable() { global $CFG_GLPI, $DB; // If this type have INFOCOM, clean one associated to purged item if (in_array($this->getType(), $CFG_GLPI['infocom_types'])) { $infocom = new Infocom(); if ($infocom->getFromDBforDevice($this->getType(), $this->fields['id'])) { $infocom->delete(array('id' => $infocom->fields['id'])); } } // If this type have NETPORT, clean one associated to purged item if (in_array($this->getType(), $CFG_GLPI['networkport_types'])) { $query = "SELECT `id`\n FROM `glpi_networkports`\n WHERE (`items_id` = '" . $this->fields['id'] . "'\n AND `itemtype` = '" . $this->getType() . "')"; $result = $DB->query($query); while ($data = $DB->fetch_array($result)) { $q = "DELETE\n FROM `glpi_networkports_networkports`\n WHERE (`networkports_id_1` = '" . $data["id"] . "'\n OR `networkports_id_2` = '" . $data["id"] . "')"; $result2 = $DB->query($q); } $query = "DELETE\n FROM `glpi_networkports`\n WHERE (`items_id` = '" . $this->fields['id'] . "'\n AND `itemtype` = '" . $this->getType() . "')"; $result = $DB->query($query); } // If this type is RESERVABLE clean one associated to purged item if (in_array($this->getType(), $CFG_GLPI['reservation_types'])) { $rr = new ReservationItem(); if ($rr->getFromDBbyItem($this->getType(), $this->fields['id'])) { $rr->delete(array('id' => $infocom->fields['id'])); } } // If this type have CONTRACT, clean one associated to purged item if (in_array($this->getType(), $CFG_GLPI['contract_types'])) { $ci = new Contract_Item(); $ci->cleanDBonItemDelete($this->getType(), $this->fields['id']); } // If this type have DOCUMENT, clean one associated to purged item if (in_array($this->getType(), $CFG_GLPI["document_types"])) { $di = new Document_Item(); $di->cleanDBonItemDelete($this->getType(), $this->fields['id']); } }
public function saveAnswers($datas) { $form = new PluginFormcreatorForm(); $form->getFromDB($datas['formcreator_form']); $query = "SELECT q.`id`, q.`fieldtype`, q.`name`\n FROM glpi_plugin_formcreator_questions q\n LEFT JOIN glpi_plugin_formcreator_sections s ON s.`id` = q.`plugin_formcreator_sections_id`\n WHERE s.`plugin_formcreator_forms_id` = {$datas['formcreator_form']}"; $result = $GLOBALS['DB']->query($query); // Update form answers if (isset($_POST['save_formanswer'])) { $status = $_POST['status']; $this->update(array('id' => (int) $datas['id'], 'status' => $status, 'comment' => isset($_POST['comment']) ? $_POST['comment'] : 'NULL')); // Update questions answers if ($status == 'waiting') { while ($question = $GLOBALS['DB']->fetch_array($result)) { if ($question['fieldtype'] != 'file') { $answer = new PluginFormcreatorAnswer(); $found = $answer->find('`plugin_formcreator_formanwers_id` = ' . (int) $datas['id'] . ' AND `plugin_formcreator_question_id` = ' . $question['id']); $found = array_shift($found); $data_value = $datas['formcreator_field_' . $question['id']]; if (isset($data_value)) { if (is_array($data_value)) { foreach ($data_value as $key => $value) { $data_value[$key] = $value; } $answer_value = json_encode($data_value); } else { $answer_value = $data_value; } } else { $answer_value = ''; } $answer->update(array('id' => $found['id'], 'answer' => $answer_value)); } elseif (isset($_FILES['formcreator_field_' . $question['id']]['tmp_name']) && is_file($_FILES['formcreator_field_' . $question['id']]['tmp_name'])) { $doc = new Document(); $answer = new PluginFormcreatorAnswer(); $found = $answer->find('`plugin_formcreator_formanwers_id` = ' . (int) $datas['id'] . ' AND `plugin_formcreator_question_id` = ' . $question['id']); $found = array_shift($found); $file_datas = array(); $file_datas["name"] = $form->fields['name'] . ' - ' . $question['name']; $file_datas["entities_id"] = isset($_SESSION['glpiactive_entity']) ? $_SESSION['glpiactive_entity'] : $form->fields['entities_id']; $file_datas["is_recursive"] = $form->fields['is_recursive']; Document::uploadDocument($file_datas, $_FILES['formcreator_field_' . $question['id']]); if ($docID = $doc->add($file_datas)) { $table = getTableForItemType('Document'); $filename = $_FILES['formcreator_field_' . $question['id']]['name']; $query = "UPDATE {$table} SET filename = '" . $filename . "' WHERE id = " . $docID; $GLOBALS['DB']->query($query); $docItem = new Document_Item(); $docItemId = $docItem->add(array('documents_id' => $docID, 'itemtype' => __CLASS__, 'items_id' => (int) $datas['id'])); $answer->update(array('id' => $found['id'], 'answer' => $docID)); } } } } // Create new form answer object } else { // Does the form need to be validate ? if ($form->fields['validation_required']) { $status = 'waiting'; } else { $status = 'accepted'; } $id = $this->add(array('entities_id' => isset($_SESSION['glpiactive_entity']) ? $_SESSION['glpiactive_entity'] : $form->fields['entities_id'], 'is_recursive' => $form->fields['is_recursive'], 'plugin_formcreator_forms_id' => $datas['formcreator_form'], 'requester_id' => isset($_SESSION['glpiID']) ? $_SESSION['glpiID'] : 0, 'validator_id' => isset($datas['formcreator_validator']) ? $datas['formcreator_validator'] : 0, 'status' => $status, 'request_date' => date('Y-m-d H:i:s'))); // Save questions answers while ($question = $GLOBALS['DB']->fetch_assoc($result)) { // If the answer is set, check if it is an array (then implode id). if (isset($datas[$question['id']])) { $question_answer = $datas[$question['id']]; if (is_array(json_decode($question_answer))) { $question_answer = json_decode($question_answer); foreach ($question_answer as $key => $value) { $question_answer[$key] = $value; } $question_answer = json_encode($question_answer); } else { $question_answer = $question_answer; } } else { $question_answer = ''; } $answer = new PluginFormcreatorAnswer(); $answerID = $answer->add(array('plugin_formcreator_formanwers_id' => $id, 'plugin_formcreator_question_id' => $question['id'], 'answer' => $question_answer)); // If the question is a file field, save the file as a document if ($question['fieldtype'] == 'file' && isset($_FILES['formcreator_field_' . $question['id']]['tmp_name']) && is_file($_FILES['formcreator_field_' . $question['id']]['tmp_name'])) { $doc = new Document(); $file_datas = array(); $file_datas["name"] = $form->fields['name'] . ' - ' . $question['name']; $file_datas["entities_id"] = isset($_SESSION['glpiactive_entity']) ? $_SESSION['glpiactive_entity'] : $form->fields['entities_id']; $file_datas["is_recursive"] = $form->fields['is_recursive']; Document::uploadDocument($file_datas, $_FILES['formcreator_field_' . $question['id']]); if ($docID = $doc->add($file_datas)) { $table = getTableForItemType('Document'); $filename = $_FILES['formcreator_field_' . $question['id']]['name']; $query = "UPDATE {$table} SET filename = '" . $filename . "' WHERE id = " . $docID; $GLOBALS['DB']->query($query); $docItem = new Document_Item(); $docItemId = $docItem->add(array('documents_id' => $docID, 'itemtype' => __CLASS__, 'items_id' => $id)); $answer->update(array('id' => $answerID, 'answer' => $docID)); } } } } NotificationEvent::raiseEvent('plugin_formcreator_form_created', $this); if ($form->fields['validation_required'] || $status == 'accepted') { switch ($status) { case 'waiting': // Notify the validator NotificationEvent::raiseEvent('plugin_formcreator_need_validation', $this); break; case 'refused': // Notify the requester NotificationEvent::raiseEvent('plugin_formcreator_refused', $this); break; case 'accepted': // Notify the requester if (!$this->generateTarget()) { Session::addMessageAfterRedirect(__('Cannot generate targets!', 'formcreator'), true, ERROR); $this->update(array('id' => $this->getID(), 'status' => 'waiting')); } NotificationEvent::raiseEvent('plugin_formcreator_accepted', $this); return false; break; } } Session::addMessageAfterRedirect(__('The form have been successfully saved!', 'formcreator'), true, INFO); }
/** * add files (from $this->input['_filename']) to an ITIL object * create document if needed * create link from document to ITIL object * * @param $donotif Boolean if we want to raise notification (default 1) * @param $disablenotif (default 0) * * @return array of doc added name **/ function addFiles($donotif = 1, $disablenotif = 0) { global $CFG_GLPI; if (!isset($this->input['_filename']) || count($this->input['_filename']) == 0) { return array(); } $docadded = array(); foreach ($this->input['_filename'] as $key => $file) { $doc = new Document(); $docitem = new Document_Item(); $docID = 0; $filename = GLPI_TMP_DIR . "/" . $file; $input2 = array(); // Crop/Resize image file if needed if (isset($this->input['_coordinates']) && !empty($this->input['_coordinates'][$key])) { $image_coordinates = json_decode(urldecode($this->input['_coordinates'][$key]), true); Toolbox::resizePicture($filename, $filename, $image_coordinates['img_w'], $image_coordinates['img_h'], $image_coordinates['img_y'], $image_coordinates['img_x'], $image_coordinates['img_w'], $image_coordinates['img_h'], 0); } else { Toolbox::resizePicture($filename, $filename, 0, 0, 0, 0, 0, 0, 0); } //If file tag is present if (isset($this->input['_tag_filename']) && !empty($this->input['_tag_filename'][$key])) { $this->input['_tag'][$key] = $this->input['_tag_filename'][$key]; } // Check for duplicate if ($doc->getFromDBbyContent($this->fields["entities_id"], $filename)) { if (!$doc->fields['is_blacklisted']) { $docID = $doc->fields["id"]; } // File already exist, we replace the tag by the existing one if (isset($this->input['_tag'][$key]) && $docID > 0 && isset($this->input['content'])) { $this->input['content'] = preg_replace('/' . Document::getImageTag($this->input['_tag'][$key]) . '/', Document::getImageTag($doc->fields["tag"]), $this->input['content']); $docadded[$docID]['tag'] = $doc->fields["tag"]; } } else { //TRANS: Default document to files attached to tickets : %d is the ticket id $input2["name"] = addslashes(sprintf(__('Document Ticket %d'), $this->getID())); if ($this->getType() == 'Ticket') { $input2["tickets_id"] = $this->getID(); // Insert image tag if (isset($this->input['_tag'][$key])) { $input2["tag"] = $this->input['_tag'][$key]; } } $input2["entities_id"] = $this->fields["entities_id"]; $input2["documentcategories_id"] = $CFG_GLPI["documentcategories_id_forticket"]; $input2["_only_if_upload_succeed"] = 1; $input2["entities_id"] = $this->fields["entities_id"]; $input2["_filename"] = array($file); $docID = $doc->add($input2); } if ($docID > 0) { if ($docitem->add(array('documents_id' => $docID, '_do_notif' => $donotif, '_disablenotif' => $disablenotif, 'itemtype' => $this->getType(), 'items_id' => $this->getID()))) { $docadded[$docID]['data'] = sprintf(__('%1$s - %2$s'), stripslashes($doc->fields["name"]), stripslashes($doc->fields["filename"])); if (isset($input2["tag"])) { $docadded[$docID]['tag'] = $input2["tag"]; unset($this->input['_filename'][$key]); unset($this->input['_tag'][$key]); } if (isset($this->input['_coordinates'][$key])) { unset($this->input['_coordinates'][$key]); } } } // Only notification for the first New doc $donotif = 0; } // Ticket update if (isset($this->input['content'])) { if ($CFG_GLPI["use_rich_text"]) { $this->input['content'] = $this->convertTagToImage($this->input['content'], true, $docadded); $this->input['_forcenotif'] = true; } else { $this->fields['content'] = $this->setSimpleTextContent($this->input['content']); $this->updateInDB(array('content')); } } return $docadded; }
/** * @since version 0.90 * * @param $item * @param $id * @param $params **/ static function showSubForm(CommonDBTM $item, $id, $params) { if ($item instanceof Document_Item) { Document_Item::showAddFormForItem($params['parent'], ''); } else { if (method_exists($item, "showForm")) { $item->showForm($id, $params); } } }
/** * 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 " <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> "; 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'> </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 " <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 " <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 " "; 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() . "&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 " "; 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 " "; 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; }
public static function addDocumentCategory(Document $document) { $config = PluginOrderConfig::getConfig(); if (isset($document->input['itemtype']) && $document->input['itemtype'] == __CLASS__ && !$document->input['documentcategories_id']) { $category = $config->getDefaultDocumentCategory(); if ($category) { $document->update(array('id' => $document->getID(), 'documentcategories_id' => $category)); } } // Fomrat document name if (isset($document->input['itemtype']) && $document->input['itemtype'] == __CLASS__ && $document->input['documentcategories_id'] && $config->canRenameDocuments()) { // Get document category $documentCategory = new PluginOrderDocumentCategory(); if (!$documentCategory->getFromDBByQuery(" WHERE `documentcategories_id` = '" . $document->input['documentcategories_id'] . "'")) { $documentCategory->getEmpty(); } // Get order linked to document $document_item = new Document_Item(); if ($document_item->getFromDBByQuery(" WHERE `documents_id` = '" . $document->fields['id'] . "' AND `itemtype` = '" . self::getType() . "'")) { // Update document name $order = new self(); $order->getFromDB($document_item->fields['items_id']); $extension = explode('.', $document->fields['filename']); $tag = ""; if (!empty($documentCategory->fields['documentcategories_prefix'])) { $tag = $documentCategory->fields['documentcategories_prefix'] . "-"; } $document->fields['filename'] = $tag . $order->fields['num_order'] . "." . $extension[1]; $document->updateInDB(array('filename')); } } }
/** * @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'> </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 " <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() . "&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; }
public function save($form, $input) { $datas = array(); $ticket = new Ticket(); $docItem = new Document_Item(); // Get default request type $query = "SELECT id FROM `glpi_requesttypes` WHERE `name` LIKE 'Formcreator';"; $result = $GLOBALS['DB']->query($query) or die($DB->error()); list($requesttypes_id) = $GLOBALS['DB']->fetch_array($result); $datas['requesttypes_id'] = $requesttypes_id; // Get predefined Fields $ttp = new TicketTemplatePredefinedField(); $predefined_fields = $ttp->getPredefinedFields($this->fields['tickettemplates_id'], true); $datas = array_merge($datas, $predefined_fields); $datas['name'] = $this->parseTags($this->fields['name'], $form, $input); $datas['content'] = $this->parseTags($this->fields['comment'], $form, $input); $datas['entities_id'] = isset($_SESSION['glpiactive_entity']) ? $_SESSION['glpiactive_entity'] : $form->fields['entities_id']; $ticketID = $ticket->add($datas); if (!empty($_SESSION['formcreator_documents'])) { foreach ($_SESSION['formcreator_documents'] as $docID) { $docItem->add(array('documents_id' => $docID, 'itemtype' => 'Ticket', 'items_id' => $ticketID)); } } }
/** * Copy order documents into the newly generated item * @since 1.5.3 * @param unknown_type $itemtype * @param unknown_type $items_id * @param unknown_type $orders_id * @param unknown_type $entity */ public static function copyDocuments($itemtype, $items_id, $orders_id, $entity) { global $CFG_GLPI; $config = PluginOrderConfig::getConfig(); if ($config->canCopyDocuments() && in_array($itemtype, $CFG_GLPI["document_types"])) { $document = new Document(); $docitem = new Document_Item(); $item = new $itemtype(); $item->getFromDB($items_id); $is_recursive = 0; foreach (getAllDatasFromTable('glpi_documents_items', "`itemtype`='PluginOrderOrder'\n AND `items_id`='{$orders_id}'") as $doc) { //Create a new document $document->getFromDB($doc['documents_id']); if ($document->getEntityID() != $entity && !$document->fields['is_recursive'] || !in_array($entity, getSonsOf('glpi_entities', $document->getEntityID()))) { $found_docs = getAllDatasFromTable('glpi_documents', "`entities_id`='{$entity}'\n AND `sha1sum`='" . $document->fields['sha1sum'] . "'"); if (empty($found_docs)) { $tmpdoc = $document->fields; $tmpdoc['entities_id'] = $entity; unset($tmpdoc['id']); $documents_id = $document->add($tmpdoc); $is_recursive = $document->fields['is_recursive']; } else { $found_doc = array_pop($found_docs); $documents_id = $found_doc['id']; $is_recursive = $found_doc['is_recursive']; } } else { $documents_id = $document->getID(); $is_recursive = $document->fields['is_recursive']; } //Link the document to the newly generated item $fields['documents_id'] = $documents_id; $fields['entities_id'] = $entity; $fields['items_id'] = $items_id; $fields['itemtype'] = $itemtype; $fields['is_recursive'] = $is_recursive; $newID = $docitem->add($fields); } } }
/** * Add a document to a existing ticket * for an authenticated user * * @param $params array of options (ticket, uri, name, base64, comment) * only one of uri and base64 must be set * name is mandatory when base64 set, for extension check (filename) * @param $protocol the communication protocol used * * @return array of hashtable **/ static function methodAddTicketDocument($params, $protocol) { global $DB, $CFG_GLPI; if (isset($params['help'])) { return array('ticket' => 'integer,mandatory', 'uri' => 'string,optional', 'base64' => 'string,optional', 'content' => 'string,optional', 'close' => 'bool,optional', 'reopen' => 'bool,optional', 'source' => 'string,optional', 'private' => 'bool,optional', 'help' => 'bool,optional'); } if (!Session::getLoginUserID()) { return self::Error($protocol, WEBSERVICES_ERROR_NOTAUTHENTICATED); } $ticket = new Ticket(); if (!isset($params['ticket'])) { return self::Error($protocol, WEBSERVICES_ERROR_MISSINGPARAMETER, '', 'ticket'); } if (!is_numeric($params['ticket'])) { return self::Error($protocol, WEBSERVICES_ERROR_BADPARAMETER, '', 'ticket'); } if (!$ticket->can($params['ticket'], 'r')) { return self::Error($protocol, WEBSERVICES_ERROR_NOTFOUND); } if (in_array($ticket->fields["status"], $ticket->getClosedStatusArray())) { return self::Error($protocol, WEBSERVICES_ERROR_NOTALLOWED, '', 'closed ticket'); } if (!$ticket->canAddFollowups()) { return self::Error($protocol, WEBSERVICES_ERROR_NOTALLOWED, '', 'access denied'); } if (isset($params['name']) && !empty($params['name'])) { $document_name = addslashes($params['name']); } else { $document_name = addslashes(sprintf(__('%1$s %2$s'), _x('phone', 'Number'), $ticket->fields['id'])); } $filename = tempnam(GLPI_DOC_DIR . '/_tmp', 'PWS'); $response = parent::uploadDocument($params, $protocol, $filename, $document_name); //An error occured during document upload if (parent::isError($protocol, $response)) { return $response; } $doc = new Document(); $documentitem = new Document_Item(); $docid = $doc->getFromDBbyContent($ticket->fields["entities_id"], $filename); if ($docid) { $input = array('itemtype' => $ticket->getType(), 'items_id' => $ticket->getID(), 'documents_id' => $doc->getID()); if ($DB->request('glpi_documents_items', $input)->numrows()) { return self::Error($protocol, WEBSERVICES_ERROR_FAILED, '', 'document already associated to this ticket'); } $new = $documentitem->add($input); } else { $input = array('itemtype' => $ticket->getType(), 'items_id' => $ticket->getID(), 'tickets_id' => $ticket->getID(), 'entities_id' => $ticket->getEntityID(), 'is_recursive' => $ticket->isRecursive(), 'documentcategories_id' => $CFG_GLPI["documentcategories_id_forticket"]); $new = $doc->add($input); } // to not add it twice during followup unset($_FILES['filename']); if (!$new) { return self::Error($protocol, WEBSERVICES_ERROR_FAILED, '', self::getDisplayError()); } if (isset($params['comment']) && !empty($params['comment'])) { $params['content'] = $params['comment']; unset($params['comment']); } if (isset($params['content']) && !empty($params['content'])) { return self::methodAddTicketFollowup($params, $protocol); } return self::methodGetTicket(array('ticket' => $params['ticket']), $protocol); }
case "add_userprofile": $right = new Profile_User(); if (isset($_POST['profiles_id']) && $_POST['profiles_id'] > 0 && isset($_POST['entities_id']) && $_POST['entities_id'] >= 0) { $input['entities_id'] = $_POST['entities_id']; $input['profiles_id'] = $_POST['profiles_id']; $input['is_recursive'] = $_POST['is_recursive']; foreach ($_POST["item"] as $key => $val) { if ($val == 1) { $input['users_id'] = $key; $right->add($input); } } } break; case "add_document": $documentitem = new Document_Item(); foreach ($_POST["item"] as $key => $val) { $input = array('itemtype' => $_POST["itemtype"], 'items_id' => $key, 'documents_id' => $_POST['docID']); if ($documentitem->can(-1, 'w', $input)) { $documentitem->add($input); } } break; case "add_contact": if ($_POST["itemtype"] == 'Supplier') { $contactsupplier = new Contact_Supplier(); foreach ($_POST["item"] as $key => $val) { $input = array('suppliers_id' => $key, 'contacts_id' => $_POST['conID']); if ($contactsupplier->can(-1, 'w', $input)) { $contactsupplier->add($input); }
function post_addItem() { global $DB; // Manage add from template if (isset($this->input["_oldID"])) { // ADD Documents $query = "SELECT `documents_id`\n FROM `glpi_documents_items`\n WHERE `items_id` = '" . $this->input["_oldID"] . "'\n AND `itemtype` = '" . $this->getType() . "';"; $result = $DB->query($query); if ($DB->numrows($result) > 0) { $docitem = new Document_Item(); while ($data = $DB->fetch_array($result)) { $docitem->add(array('documents_id' => $data["documents_id"], 'itemtype' => $this->getType(), 'items_id' => $this->fields['id'])); } } } }
function post_addItem() { global $CFG_GLPI; $projet_projet = new PluginProjetProjet_Projet(); // From interface if (isset($this->input['_link'])) { $this->input['_link']['plugin_projet_projets_id_1'] = $this->fields['id']; // message if projet doesn't exist if (!empty($this->input['_link']['plugin_projet_projets_id_2'])) { if ($projet_projet->can(-1, 'w', $this->input['_link'])) { $projet_projet->add($this->input['_link']); } else { Session::addMessageAfterRedirect(__('Unknown project', 'projet'), false, ERROR); } } } // Manage add from template if (isset($this->input["_oldID"])) { //add parent PluginProjetProjet_Projet::cloneItem($this->input["_oldID"], $this->fields['id']); // ADD Documents Document_Item::cloneItem($this->getType(), $this->input["_oldID"], $this->fields['id']); // ADD Contracts Contract_Item::cloneItem($this->getType(), $this->input["_oldID"], $this->fields['id']); // ADD items PluginProjetProjet_Item::cloneItem($this->input["_oldID"], $this->fields['id']); // ADD tasks PluginProjetTask::cloneItem($this->input["_oldID"], $this->fields['id']); } if (isset($this->input['withtemplate']) && $this->input["withtemplate"] != 1 && isset($this->input['send_notification']) && $this->input['send_notification'] == 1) { if ($CFG_GLPI["use_mailing"]) { NotificationEvent::raiseEvent("new", $this); } } }
/** * Save form datas to the target * * @param PluginFormcreatorFormanswer $formanswer Answers previously saved */ public function save(PluginFormcreatorFormanswer $formanswer) { $datas = array(); $ticket = new Ticket(); $docItem = new Document_Item(); $form = new PluginFormcreatorForm(); $form->getFromDB($formanswer->fields['plugin_formcreator_forms_id']); // Get default request type $query = "SELECT id FROM `glpi_requesttypes` WHERE `name` LIKE 'Formcreator';"; $result = $GLOBALS['DB']->query($query) or die($GLOBALS['DB']->error()); list($requesttypes_id) = $GLOBALS['DB']->fetch_array($result); $datas['requesttypes_id'] = $requesttypes_id; // Get predefined Fields $ttp = new TicketTemplatePredefinedField(); $predefined_fields = $ttp->getPredefinedFields($this->fields['tickettemplates_id'], true); $datas = array_merge($datas, $predefined_fields); // Parse datas and tags $datas['name'] = addslashes($this->parseTags($this->fields['name'], $formanswer)); $datas['content'] = htmlentities($this->parseTags($this->fields['comment'], $formanswer)); $datas['entities_id'] = isset($_SESSION['glpiactive_entity']) ? $_SESSION['glpiactive_entity'] : $form->fields['entities_id']; $datas['_users_id_requester'] = 0; $datas['_users_id_recipient'] = $_SESSION['glpiID']; $datas['_tickettemplates_id'] = $this->fields['tickettemplates_id']; // Define due date $answer = new PluginFormcreatorAnswer(); $found = $answer->find('plugin_formcreator_formanwers_id = ' . (int) $formanswer->fields['id'] . ' AND plugin_formcreator_question_id = ' . (int) $this->fields['due_date_question']); $date = array_shift($found); $str = "+" . $this->fields['due_date_value'] . " " . $this->fields['due_date_period']; switch ($this->fields['due_date_rule']) { case 'answer': $due_date = $date['answer']; break; case 'ticket': $due_date = date('Y-m-d H:i:s', strtotime($str)); break; case 'calcul': $due_date = date('Y-m-d H:i:s', strtotime($date['answer'] . " " . $str)); break; default: $due_date = null; break; } if (!is_null($due_date)) { $datas['due_date'] = $due_date; } // Select ticket actors $query = "SELECT id, actor_type, actor_value, use_notification\n FROM glpi_plugin_formcreator_targettickets_actors\n WHERE plugin_formcreator_targettickets_id = " . $this->getID() . "\n AND actor_role = 'requester'"; $result = $GLOBALS['DB']->query($query); // If there is only one requester add it on creation, otherwize we will add them later if ($GLOBALS['DB']->numrows($result) == 1) { $actor = $GLOBALS['DB']->fetch_array($result); switch ($actor['actor_type']) { case 'creator': $user_id = $formanswer->fields['requester_id']; break; case 'validator': $user_id = $formanswer->fields['validator_id']; break; case 'person': case 'group': case 'supplier': $user_id = $actor['actor_value']; break; case 'question_person': case 'question_group': case 'question_supplier': $answer = new PluginFormcreatorAnswer(); $found = $answer->find('`plugin_formcreator_question_id` = ' . (int) $actor['actor_value'] . ' AND `plugin_formcreator_formanwers_id` = ' . (int) $formanswer->fields['id']); $found = array_shift($found); if (empty($found['answer'])) { continue; } else { $user_id = (int) $found['answer']; } break; } $datas['_users_id_requester'] = $user_id; } // Create the target ticket if (!($ticketID = $ticket->add($datas))) { return false; } // Add link between Ticket and FormAnswer $itemlink = new Item_Ticket(); $itemlink->add(array('itemtype' => 'PluginFormcreatorFormanswer', 'items_id' => $formanswer->fields['id'], 'tickets_id' => $ticketID)); // Add actors to ticket $query = "SELECT id, actor_role, actor_type, actor_value, use_notification\n FROM glpi_plugin_formcreator_targettickets_actors\n WHERE plugin_formcreator_targettickets_id = " . $this->getID(); $result = $GLOBALS['DB']->query($query); while ($actor = $GLOBALS['DB']->fetch_array($result)) { // If actor type is validator and if the form doesn't have a validator, continue to other actors if ($actor['actor_type'] == 'validator' && !$form->fields['validation_required']) { continue; } switch ($actor['actor_role']) { case 'requester': $role = CommonITILActor::REQUESTER; break; case 'observer': $role = CommonITILActor::OBSERVER; break; case 'assigned': $role = CommonITILActor::ASSIGN; break; } switch ($actor['actor_type']) { case 'creator': $user_id = $formanswer->fields['requester_id']; break; case 'validator': $user_id = $formanswer->fields['validator_id']; break; case 'person': case 'group': case 'supplier': $user_id = $actor['actor_value']; break; case 'question_person': case 'question_group': case 'question_supplier': $answer = new PluginFormcreatorAnswer(); $found = $answer->find('`plugin_formcreator_question_id` = ' . (int) $actor['actor_value'] . ' AND `plugin_formcreator_formanwers_id` = ' . (int) $formanswer->fields['id']); $found = array_shift($found); if (empty($found['answer'])) { continue; } else { $user_id = (int) $found['answer']; } break; } switch ($actor['actor_type']) { case 'creator': case 'validator': case 'person': case 'question_person': $obj = new Ticket_User(); $obj->add(array('tickets_id' => $ticketID, 'users_id' => $user_id, 'type' => $role, 'use_notification' => $actor['use_notification'])); break; case 'group': case 'question_group': $obj = new Group_Ticket(); $obj->add(array('tickets_id' => $ticketID, 'groups_id' => $user_id, 'type' => $role, 'use_notification' => $actor['use_notification'])); break; case 'supplier': case 'question_supplier': $obj = new Supplier_Ticket(); $obj->add(array('tickets_id' => $ticketID, 'suppliers_id' => $user_id, 'type' => $role, 'use_notification' => $actor['use_notification'])); break; } } // Attach documents to ticket $found = $docItem->find("itemtype = 'PluginFormcreatorFormanswer' AND items_id = " . (int) $formanswer->getID()); if (count($found) > 0) { foreach ($found as $document) { $docItem->add(array('documents_id' => $document['documents_id'], 'itemtype' => 'Ticket', 'items_id' => $ticketID)); } } // Attach validation message as first ticket followup if validation is required and // if is set in ticket target configuration // /!\ Followup is directly saved to the database to avoid double notification on ticket // creation and add followup if ($form->fields['validation_required'] && $this->fields['validation_followup']) { $message = addslashes(__('Your form have been accepted by the validator', 'formcreator')); if (!empty($formanswer->fields['comment'])) { $message .= "\n" . addslashes($formanswer->fields['comment']); } $query = "INSERT INTO `glpi_ticketfollowups` SET\n `tickets_id` = {$ticketID},\n `date` = NOW(),\n `users_id` = {$_SESSION['glpiID']},\n `content` = \"{$message}\""; $GLOBALS['DB']->query($query); } return true; }
/** form for Task * * @param $ID Integer : Id of the task * @param $options array * - parent Object : the object **/ function showForm($ID, $options = array()) { global $DB, $CFG_GLPI; $rand_template = mt_rand(); $rand_text = mt_rand(); $rand_type = mt_rand(); $rand_time = mt_rand(); if (isset($options['parent']) && !empty($options['parent'])) { $item = $options['parent']; } $fkfield = $item->getForeignKeyField(); if ($ID > 0) { $this->check($ID, READ); } else { // Create item $options[$fkfield] = $item->getField('id'); $this->check(-1, CREATE, $options); } $rand = mt_rand(); $this->showFormHeader($options); $canplan = !$item->isStatusExists(CommonITILObject::PLANNED) || $item->isAllowedStatus($item->fields['status'], CommonITILObject::PLANNED); $rowspan = 5; if ($this->maybePrivate()) { $rowspan++; } if (isset($this->fields["state"])) { $rowspan++; } echo "<tr class='tab_bg_1'>"; echo "<td rowspan='{$rowspan}' style='width:100px'>" . __('Description') . "</td>"; echo "<td rowspan='{$rowspan}' style='width:50%' id='content{$rand_text}'>" . "<textarea name='content' style='width: 95%; height: 160px' id='task{$rand_text}'>" . $this->fields["content"] . "</textarea>"; echo Html::scriptBlock("\$(document).ready(function() { \$('#content{$rand}').autogrow(); });"); echo "</td>"; echo "<input type='hidden' name='{$fkfield}' value='" . $this->fields[$fkfield] . "'>"; echo "</td></tr>\n"; echo "<tr class='tab_bg_1'>"; echo "<td style='width:100px'>" . _n('Task template', 'Task templates', 1) . "</td><td>"; TaskTemplate::dropdown(array('value' => 0, 'entity' => $this->getEntityID(), 'rand' => $rand_template, 'on_change' => 'tasktemplate_update(this.value)')); echo "</td>"; echo "</tr>"; echo Html::scriptBlock(' function tasktemplate_update(value) { jQuery.ajax({ url: "' . $CFG_GLPI["root_doc"] . '/ajax/task.php", type: "POST", data: { tasktemplates_id: value } }).done(function(datas) { datas.taskcategories_id = isNaN(parseInt(datas.taskcategories_id)) ? 0 : parseInt(datas.taskcategories_id); datas.actiontime = isNaN(parseInt(datas.actiontime)) ? 0 : parseInt(datas.actiontime); $("#task' . $rand_text . '").html(datas.content); $("#dropdown_taskcategories_id' . $rand_type . '").select2("val", parseInt(datas.taskcategories_id)); $("#dropdown_actiontime' . $rand_time . '").select2("val", parseInt(datas.actiontime)); }); } '); if ($ID > 0) { echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Date') . "</td>"; echo "<td>"; Html::showDateTimeField("date", array('value' => $this->fields["date"], 'timestep' => 1, 'maybeempty' => false)); echo "</tr>"; } else { echo "<tr class='tab_bg_1'>"; echo "<td colspan='2'> "; echo "</tr>"; } echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Category') . "</td><td>"; TaskCategory::dropdown(array('value' => $this->fields["taskcategories_id"], 'rand' => $rand_type, 'entity' => $item->fields["entities_id"], 'condition' => "`is_active` = '1'")); echo "</td></tr>\n"; if (isset($this->fields["state"])) { echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Status') . "</td><td>"; Planning::dropdownState("state", $this->fields["state"]); echo "</td></tr>\n"; } if ($this->maybePrivate()) { echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Private') . "</td>"; echo "<td>"; Dropdown::showYesNo('is_private', $this->fields["is_private"]); echo "</td>"; echo "</tr>"; } echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Duration') . "</td><td>"; $toadd = array(); for ($i = 9; $i <= 100; $i++) { $toadd[] = $i * HOUR_TIMESTAMP; } Dropdown::showTimeStamp("actiontime", array('min' => 0, 'max' => 8 * HOUR_TIMESTAMP, 'value' => $this->fields["actiontime"], 'rand' => $rand_time, 'addfirstminutes' => true, 'inhours' => true, 'toadd' => $toadd)); echo "</td></tr>\n"; if ($ID <= 0) { Document_Item::showSimpleAddForItem($item); } echo "<tr class='tab_bg_1'>"; echo "<td>" . __('By') . "</td>"; echo "<td colspan='2'>"; echo Html::image($CFG_GLPI['root_doc'] . "/pics/user.png") . " "; echo _n('User', 'Users', 1); $rand_user = mt_rand(); $params = array('name' => "users_id_tech", 'value' => $ID > -1 ? $this->fields["users_id_tech"] : Session::getLoginUserID(), 'right' => "own_ticket", 'rand' => $rand_user, 'entity' => $item->fields["entities_id"], 'width' => ''); $params['toupdate'] = array('value_fieldname' => 'users_id', 'to_update' => "user_available{$rand_user}", 'url' => $CFG_GLPI["root_doc"] . "/ajax/planningcheck.php"); User::dropdown($params); echo " <a href='#' onClick=\"" . Html::jsGetElementbyID('planningcheck' . $rand) . ".dialog('open');\">"; echo " <img src='" . $CFG_GLPI["root_doc"] . "/pics/reservation-3.png'\n title=\"" . __s('Availability') . "\" alt=\"" . __s('Availability') . "\"\n class='calendrier'>"; echo "</a>"; Ajax::createIframeModalWindow('planningcheck' . $rand, $CFG_GLPI["root_doc"] . "/front/planning.php?checkavailability=checkavailability" . "&itemtype=" . $item->getType() . "&{$fkfield}=" . $item->getID(), array('title' => __('Availability'))); echo "<br />"; echo Html::image($CFG_GLPI['root_doc'] . "/pics/group.png") . " "; echo _n('Group', 'Groups', 1) . " "; $rand_group = mt_rand(); $params = array('name' => "groups_id_tech", 'value' => $ID > -1 ? $this->fields["groups_id_tech"] : Dropdown::EMPTY_VALUE, 'condition' => "is_task", 'rand' => $rand_group, 'entity' => $item->fields["entities_id"]); $params['toupdate'] = array('value_fieldname' => 'users_id', 'to_update' => "group_available{$rand_group}", 'url' => $CFG_GLPI["root_doc"] . "/ajax/planningcheck.php"); Group::dropdown($params); echo "</td>\n"; echo "<td>"; if ($canplan) { echo __('Planning'); } if (!empty($this->fields["begin"])) { if (Session::haveRight('planning', Planning::READMY)) { echo "<script type='text/javascript' >\n"; echo "function showPlan" . $ID . $rand_text . "() {\n"; echo Html::jsHide("plan{$rand_text}"); $params = array('action' => 'add_event_classic_form', 'form' => 'followups', 'users_id' => $this->fields["users_id_tech"], 'groups_id' => $this->fields["groups_id_tech"], 'id' => $this->fields["id"], 'begin' => $this->fields["begin"], 'end' => $this->fields["end"], 'rand_user' => $rand_user, 'rand_group' => $rand_group, 'entity' => $item->fields["entities_id"], 'itemtype' => $this->getType(), 'items_id' => $this->getID()); Ajax::updateItemJsCode("viewplan{$rand_text}", $CFG_GLPI["root_doc"] . "/ajax/planning.php", $params); echo "}"; echo "</script>\n"; echo "<div id='plan{$rand_text}' onClick='showPlan" . $ID . $rand_text . "()'>\n"; echo "<span class='showplan'>"; } if (isset($this->fields["state"])) { echo Planning::getState($this->fields["state"]) . "<br>"; } printf(__('From %1$s to %2$s'), Html::convDateTime($this->fields["begin"]), Html::convDateTime($this->fields["end"])); if (isset($this->fields["users_id_tech"]) && $this->fields["users_id_tech"] > 0) { echo "<br>" . getUserName($this->fields["users_id_tech"]); } if (isset($this->fields["groups_id_tech"]) && $this->fields["groups_id_tech"] > 0) { echo "<br>" . Dropdown::getDropdownName('glpi_groups', $this->fields["groups_id_tech"]); } if (Session::haveRight('planning', Planning::READMY)) { echo "</span>"; echo "</div>\n"; echo "<div id='viewplan{$rand_text}'></div>\n"; } } else { if ($canplan) { echo "<script type='text/javascript' >\n"; echo "function showPlanUpdate{$rand_text}() {\n"; echo Html::jsHide("plan{$rand_text}"); $params = array('action' => 'add_event_classic_form', 'form' => 'followups', 'entity' => $item->fields['entities_id'], 'rand_user' => $rand_user, 'rand_group' => $rand_group, 'itemtype' => $this->getType(), 'items_id' => $this->getID()); Ajax::updateItemJsCode("viewplan{$rand_text}", $CFG_GLPI["root_doc"] . "/ajax/planning.php", $params); echo "};"; echo "</script>"; if ($canplan) { echo "<div id='plan{$rand_text}' onClick='showPlanUpdate{$rand_text}()'>\n"; echo "<span class='vsubmit'>" . __('Plan this task') . "</span>"; echo "</div>\n"; echo "<div id='viewplan{$rand_text}'></div>\n"; } } else { _e('None'); } } echo "</td></tr>"; if (!empty($this->fields["begin"]) && PlanningRecall::isAvailable()) { echo "<tr class='tab_bg_1'><td>" . _x('Planning', 'Reminder') . "</td><td class='center'>"; PlanningRecall::dropdown(array('itemtype' => $this->getType(), 'items_id' => $this->getID())); echo "</td><td colspan='2'></td></tr>"; } $this->showFormButtons($options); return true; }
This file is part of GLPI. GLPI is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. GLPI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GLPI. If not, see <http://www.gnu.org/licenses/>. -------------------------------------------------------------------------- */ /** @file * @brief * @since version 0.84 */ include '../inc/includes.php'; Session::checkCentralAccess(); $document_item = new Document_Item(); if (isset($_POST["add"])) { $document_item->check(-1, CREATE, $_POST); if ($document_item->add($_POST)) { Event::log($_POST["documents_id"], "documents", 4, "document", sprintf(__('%s adds a link with an item'), $_SESSION["glpiname"])); } Html::back(); } Html::displayErrorAndDie("lost");
/** * @since version 0.90 * * @param $item * @param $id * @param $params **/ static function showSubForm(CommonDBTM $item, $id, $params) { if ($item instanceof Document_Item) { $ticket = new self(); $ticket->getFromDB($params['tickets_id']); Document_Item::showAddFormForItem($ticket, ''); } else { if (method_exists($item, "showForm")) { $item->showForm($id, $params); } } }
$track->check($_POST['tickets_id'], READ); $input = array('tickets_id' => $_POST['tickets_id'], 'users_id' => Session::getLoginUserID(), 'use_notification' => 1, 'type' => CommonITILActor::OBSERVER); $ticket_user->add($input); Event::log($_POST['tickets_id'], "ticket", 4, "tracking", sprintf(__('%s adds an actor'), $_SESSION["glpiname"])); Html::redirect($CFG_GLPI["root_doc"] . "/front/ticket.form.php?id=" . $_POST['tickets_id']); } else { if (isset($_POST['addme_assign'])) { $ticket_user = new Ticket_User(); $track->check($_POST['tickets_id'], READ); $input = array('tickets_id' => $_POST['tickets_id'], 'users_id' => Session::getLoginUserID(), 'use_notification' => 1, 'type' => CommonITILActor::ASSIGN); $ticket_user->add($input); Event::log($_POST['tickets_id'], "ticket", 4, "tracking", sprintf(__('%s adds an actor'), $_SESSION["glpiname"])); Html::redirect($CFG_GLPI["root_doc"] . "/front/ticket.form.php?id=" . $_POST['tickets_id']); } else { if (isset($_REQUEST['delete_document'])) { $document_item = new Document_Item(); $found_document_items = $document_item->find("itemtype = 'Ticket' " . " AND items_id = " . intval($_REQUEST['tickets_id']) . " AND documents_id = " . intval($_REQUEST['documents_id'])); foreach ($found_document_items as $item) { $document_item->delete($item, true); } Html::back(); } } } } } } } } } if (isset($_GET["id"]) && $_GET["id"] > 0) {
/** * add files (from $_FILES) to an ITIL object * create document if needed * create link from document to ITIL object * * @param $id Integer ID of the ITIL object * @param $donotif Boolean if we want to raise notification (default 1) * * @return array of doc added name **/ function addFiles($id, $donotif = 1) { global $CFG_GLPI; if (!isset($_FILES) || !isset($_FILES['filename'])) { return array(); } $docadded = array(); $doc = new Document(); $docitem = new Document_Item(); // if multiple files are uploaded $TMPFILE = array(); if (is_array($_FILES['filename']['name'])) { foreach ($_FILES['filename']['name'] as $key => $filename) { if (!empty($filename)) { $TMPFILE[$key]['filename']['name'] = $filename; $TMPFILE[$key]['filename']['type'] = $_FILES['filename']['type'][$key]; $TMPFILE[$key]['filename']['tmp_name'] = $_FILES['filename']['tmp_name'][$key]; $TMPFILE[$key]['filename']['error'] = $_FILES['filename']['error'][$key]; $TMPFILE[$key]['filename']['size'] = $_FILES['filename']['size'][$key]; } } } else { $TMPFILE = array($_FILES); } foreach ($TMPFILE as $_FILES) { if (isset($_FILES['filename']) && count($_FILES['filename']) > 0 && $_FILES['filename']["size"] > 0) { // Check for duplicate if ($doc->getFromDBbyContent($this->fields["entities_id"], $_FILES['filename']['tmp_name'])) { $docID = $doc->fields["id"]; } else { $input2 = array(); //TRANS: Default document to files attached to tickets : %d is the ticket id $input2["name"] = addslashes(sprintf(__('Document Ticket %d'), $id)); if ($this->getType() == 'Ticket') { $input2["tickets_id"] = $id; } $input2["entities_id"] = $this->fields["entities_id"]; $input2["documentcategories_id"] = $CFG_GLPI["documentcategories_id_forticket"]; $input2["_only_if_upload_succeed"] = 1; $input2["entities_id"] = $this->fields["entities_id"]; $docID = $doc->add($input2); } if ($docID > 0) { if ($docitem->add(array('documents_id' => $docID, '_do_notif' => $donotif, 'itemtype' => $this->getType(), 'items_id' => $id))) { $docadded[] = sprintf(__('%1$s - %2$s'), stripslashes($doc->fields["name"]), stripslashes($doc->fields["filename"])); } } } else { if (!empty($_FILES['filename']['name']) && isset($_FILES['filename']['error']) && $_FILES['filename']['error']) { Session::addMessageAfterRedirect(__('Failed to send the file (probably too large)'), false, ERROR); } } // Only notification for the first New doc $donotif = 0; } unset($_FILES); return $docadded; }
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] . " : " . 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] . " : </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] . " :</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] . " :</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] . " "; 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] . " : </span></td>"; echo "<td>"; if ($ID) { if ($this->fields["slas_id"] > 0) { echo "<span class='tracking_small'> "; echo convDateTime($this->fields["due_date"]) . "</span>"; echo "</td></tr><tr><td><span class='tracking_small'>" . $LANG['sla'][1] . " :</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] . " : </strong>" . $slalevel->getName() . '<br><br>'; } $nextaction = new SlaLevel_Ticket(); if ($nextaction->getFromDBForTicket($this->fields["id"])) { $commentsla .= '<strong>' . $LANG['sla'][8] . " : </strong>" . convDateTime($nextaction->fields['date']) . '<br>'; if ($slalevel->getFromDB($nextaction->fields['slalevels_id'])) { $commentsla .= '<strong>' . $LANG['sla'][6] . " : </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 " <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] . " : </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] . " : </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] . " : </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] . " : </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] . " : </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] . " : </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] . " : </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] . " : </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] . " : </th>"; echo "<td>"; if ($canupdate && $canpriority) { $idpriority = self::dropdownPriority("priority", $this->fields["priority"], false, true); $idajax = 'change_priority_' . mt_rand(); echo " <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] . " : </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] . " : "; } else { echo $LANG['validation'][0] . " : "; } 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] . " : </th>"; echo "<td class='left' colspan='3'>"; Dropdown::showInteger('hour', $options['hour'], 0, 100); echo " " . $LANG['job'][21] . " "; Dropdown::showInteger('minute', $options['minute'], 0, 59); echo " " . $LANG['job'][22] . " "; 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] . " :</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() . ") :"; 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] . ' : ' . Document_Item::countForItem($this); echo "</th>"; } echo "</tr>"; echo "<tr class='tab_bg_1'>"; echo "<th width='10%'>" . $LANG['joblist'][6] . " : </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 " <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 " " . $LANG['job'][38] . " " . $LANG['common'][2] . " : "; 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 " "; 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; }
This file is part of GLPI. GLPI is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. GLPI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GLPI. If not, see <http://www.gnu.org/licenses/>. -------------------------------------------------------------------------- */ /** @file * @brief * @since version 0.84 */ include '../inc/includes.php'; Session::checkCentralAccess(); $document_item = new Document_Item(); if (isset($_POST["add"])) { $document_item->check(-1, 'w', $_POST); if ($document_item->add($_POST)) { Event::log($_POST["documents_id"], "documents", 4, "document", sprintf(__('%s adds a link with an item'), $_SESSION["glpiname"])); } Html::back(); } Html::displayErrorAndDie("lost");
function post_addItem() { // Manage add from template if (isset($this->input["_oldID"])) { // ADD Documents Document_Item::cloneItem($this->getType(), $this->input["_oldID"], $this->fields['id']); // ADD Infocoms Infocom::cloneItem($this->getType(), $this->input["_oldID"], $this->fields['id']); } }
/** form for Task * * @param $ID Integer : Id of the task * @param $options array * - parent Object : the object **/ function showForm($ID, $options = array()) { global $DB, $CFG_GLPI; if (isset($options['parent']) && !empty($options['parent'])) { $item = $options['parent']; } $fkfield = $item->getForeignKeyField(); if ($ID > 0) { $this->check($ID, READ); } else { // Create item $options[$fkfield] = $item->getField('id'); $this->check(-1, CREATE, $options); } $rand = mt_rand(); $this->showFormHeader($options); $canplan = !$item->isStatusExists(CommonITILObject::PLANNED) || $item->isAllowedStatus($item->fields['status'], CommonITILObject::PLANNED); $rowspan = 3; if ($this->maybePrivate()) { $rowspan++; } if (isset($this->fields["state"])) { $rowspan++; } echo "<tr class='tab_bg_1'>"; echo "<td rowspan='{$rowspan}' class='middle'>" . __('Description') . "</td>"; echo "<td class='center middle' rowspan='{$rowspan}'>" . "<textarea id ='content{$rand}' name='content' cols='50' rows='{$rowspan}'>" . $this->fields["content"] . "</textarea>"; echo Html::scriptBlock("\$(document).ready(function() { \$('#content{$rand}').autogrow(); });"); echo "</td>"; if ($ID > 0) { echo "<td>" . __('Date') . "</td>"; echo "<td>"; Html::showDateTimeField("date", array('value' => $this->fields["date"], 'timestep' => 1, 'maybeempty' => false)); } else { echo "<td colspan='2'> "; } echo "<input type='hidden' name='{$fkfield}' value='" . $this->fields[$fkfield] . "'>"; echo "</td></tr>\n"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Category') . "</td><td>"; TaskCategory::dropdown(array('value' => $this->fields["taskcategories_id"], 'entity' => $item->fields["entities_id"])); echo "</td></tr>\n"; if (isset($this->fields["state"])) { echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Status') . "</td><td>"; Planning::dropdownState("state", $this->fields["state"]); echo "</td></tr>\n"; } if ($this->maybePrivate()) { echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Private') . "</td>"; echo "<td>"; Dropdown::showYesNo('is_private', $this->fields["is_private"]); echo "</td>"; echo "</tr>"; } echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Duration') . "</td><td>"; $toadd = array(); for ($i = 9; $i <= 100; $i++) { $toadd[] = $i * HOUR_TIMESTAMP; } Dropdown::showTimeStamp("actiontime", array('min' => 0, 'max' => 8 * HOUR_TIMESTAMP, 'value' => $this->fields["actiontime"], 'addfirstminutes' => true, 'inhours' => true, 'toadd' => $toadd)); echo "</td></tr>\n"; Document_Item::showSimpleAddForItem($item); echo "<tr class='tab_bg_1'>"; echo "<td>" . __('By'); echo " <a href='#' onClick=\"" . Html::jsGetElementbyID('planningcheck' . $rand) . ".dialog('open');\">"; echo "<img src='" . $CFG_GLPI["root_doc"] . "/pics/reservation-3.png'\n title=\"" . __s('Availability') . "\" alt=\"" . __s('Availability') . "\"\n class='calendrier'>"; echo "</a>"; Ajax::createIframeModalWindow('planningcheck' . $rand, $CFG_GLPI["root_doc"] . "/front/planning.php?checkavailability=checkavailability" . "&itemtype=" . $item->getType() . "&{$fkfield}=" . $item->getID(), array('title' => __('Availability'))); echo "</td>"; echo "<td class='center'>"; $rand_user = mt_rand(); $params = array('name' => "users_id_tech", 'value' => $this->fields["users_id_tech"] ? $this->fields["users_id_tech"] : Session::getLoginUserID(), 'right' => "own_ticket", 'rand' => $rand_user, 'entity' => $item->fields["entities_id"]); $params['toupdate'] = array('value_fieldname' => 'users_id', 'to_update' => "user_available{$rand_user}", 'url' => $CFG_GLPI["root_doc"] . "/ajax/planningcheck.php"); User::dropdown($params); echo "</td>\n"; if ($canplan) { echo "<td>" . __('Planning') . "</td>"; } echo "<td>"; if (!empty($this->fields["begin"])) { if (Session::haveRight('planning', Planning::READMY)) { echo "<script type='text/javascript' >\n"; echo "function showPlan" . $ID . "() {\n"; echo Html::jsHide('plan'); $params = array('form' => 'followups', 'users_id' => $this->fields["users_id_tech"], 'id' => $this->fields["id"], 'begin' => $this->fields["begin"], 'end' => $this->fields["end"], 'rand_user' => $rand_user, 'entity' => $item->fields["entities_id"], 'itemtype' => $this->getType(), 'items_id' => $this->getID()); Ajax::updateItemJsCode('viewplan', $CFG_GLPI["root_doc"] . "/ajax/planning.php", $params); echo "}"; echo "</script>\n"; echo "<div id='plan' onClick='showPlan" . $ID . "()'>\n"; echo "<span class='showplan'>"; } if (isset($this->fields["state"])) { echo Planning::getState($this->fields["state"]) . "<br>"; } printf(__('From %1$s to %2$s'), Html::convDateTime($this->fields["begin"]), Html::convDateTime($this->fields["end"])); echo "<br>" . getUserName($this->fields["users_id_tech"]); if (Session::haveRight('planning', Planning::READMY)) { echo "</span>"; echo "</div>\n"; echo "<div id='viewplan'></div>\n"; } } else { if ($canplan) { echo "<script type='text/javascript' >\n"; echo "function showPlanUpdate() {\n"; echo Html::jsHide('plan'); $params = array('form' => 'followups', 'entity' => $_SESSION["glpiactive_entity"], 'rand_user' => $rand_user, 'itemtype' => $this->getType(), 'items_id' => $this->getID()); Ajax::updateItemJsCode('viewplan', $CFG_GLPI["root_doc"] . "/ajax/planning.php", $params); echo "};"; echo "</script>"; if ($canplan) { echo "<div id='plan' onClick='showPlanUpdate()'>\n"; echo "<span class='vsubmit'>" . __('Plan this task') . "</span>"; echo "</div>\n"; echo "<div id='viewplan'></div>\n"; } } else { _e('None'); } } echo "</td></tr>"; if (!empty($this->fields["begin"]) && PlanningRecall::isAvailable()) { echo "<tr class='tab_bg_1'><td>" . _x('Planning', 'Reminder') . "</td><td class='center'>"; PlanningRecall::dropdown(array('itemtype' => $this->getType(), 'items_id' => $this->getID())); echo "</td></tr>"; } $this->showFormButtons($options); return true; }
function post_addItem() { global $DB; // Manage add from template if (isset($this->input["_oldID"])) { // ADD Devices Item_devices::cloneItem($this->getType(), $this->input["_oldID"], $this->fields['id']); // ADD Infocoms Infocom::cloneItem($this->getType(), $this->input["_oldID"], $this->fields['id']); // ADD volumes ComputerDisk::cloneComputer($this->input["_oldID"], $this->fields['id']); // ADD software Computer_SoftwareVersion::cloneComputer($this->input["_oldID"], $this->fields['id']); Computer_SoftwareLicense::cloneComputer($this->input["_oldID"], $this->fields['id']); // ADD Contract Contract_Item::cloneItem($this->getType(), $this->input["_oldID"], $this->fields['id']); // ADD Documents Document_Item::cloneItem($this->getType(), $this->input["_oldID"], $this->fields['id']); // ADD Ports NetworkPort::cloneItem($this->getType(), $this->input["_oldID"], $this->fields['id']); // Add connected devices Computer_Item::cloneComputer($this->input["_oldID"], $this->fields['id']); } }
function post_addItem() { if (isset($this->input["items_id"]) && isset($this->input["itemtype"]) && ($this->input["items_id"] > 0 || $this->input["items_id"] == 0 && $this->input["itemtype"] == 'Entity') && !empty($this->input["itemtype"])) { $docitem = new Document_Item(); $docitem->add(array('documents_id' => $this->fields['id'], 'itemtype' => $this->input["itemtype"], 'items_id' => $this->input["items_id"])); Event::log($this->fields['id'], "documents", 4, "document", sprintf(__('%s adds a link with an item'), $_SESSION["glpiname"])); } }
function post_addItem() { global $DB, $CFG_GLPI; // Manage add from template if (isset($this->input["_oldID"])) { // ADD Devices Item_devices::cloneItem($this->getType(), $this->input["_oldID"], $this->fields['id']); // ADD Infocoms Infocom::cloneItem($this->getType(), $this->input["_oldID"], $this->fields['id']); // ADD Ports NetworkPort::cloneItem($this->getType(), $this->input["_oldID"], $this->fields['id']); // ADD Contract Contract_Item::cloneItem($this->getType(), $this->input["_oldID"], $this->fields['id']); // ADD Documents Document_Item::cloneItem($this->getType(), $this->input["_oldID"], $this->fields['id']); // ADD Computers Computer_Item::cloneItem($this->getType(), $this->input["_oldID"], $this->fields['id']); } }
/** Generate bigdump : add documents to an item * * @param $type item type * @param $ID item ID **/ function addDocuments($type, $ID) { global $DOC_PER_ITEM, $DB, $FIRST, $LAST, $DOCUMENTS; $nb = mt_rand(0, $DOC_PER_ITEM); $docs = array(); for ($i=0 ; $i<$nb ; $i++) { $docs[] = mt_rand($FIRST["document"], $LAST["document"]); } $docs = array_unique($docs); $di = new Document_Item(); foreach ($docs as $val) { if (isset($DOCUMENTS[$val])) { list($entID, $recur) = explode('-',$DOCUMENTS[$val]); $di->add(array('documents_id' => $val, 'itemtype' => $type, 'items_id' => $ID, 'entities_id' => $entID, 'is_recursive' => $recur)); } } }
static function addDocument($options) { //configure adding doc $time_file = date("Y-m-d-H-i"); $name = ""; if ($options["itemtype"] == 'Computer') { $name = "computer"; } else { if ($options["itemtype"] == 'NetworkEquipment') { $name = "networking"; } else { if ($options["itemtype"] == 'Peripheral') { $name = "peripheral"; } else { if ($options["itemtype"] == 'Monitor') { $name = "monitor"; } else { if ($options["itemtype"] == 'Printer') { $name = "printer"; } else { if ($options["itemtype"] == 'PluginRacksRack') { $name = "rack"; } } } } } } $filename = "infocoms_" . $options["suppliername"] . "_" . $name . "_" . $options["ID"] . ".html"; //on enregistre $path = GLPI_DOC_DIR . "/_uploads/"; $filepath = $path . $filename; $datas = array("url" => $options["url"], "download" => true, "file" => $filepath, "suppliername" => $options["suppliername"]); self::cURLData($datas); $doc = new document(); $input = array(); $input["entities_id"] = $options["entities_id"]; $input["name"] = addslashes("infocoms_" . $options["suppliername"] . "_" . $name . "_" . $options["ID"]); $input["upload_file"] = $filename; $input["documentcategories_id"] = $options["rubrique"]; $input["mime"] = "text/html"; $input["date_mod"] = date("Y-m-d H:i:s"); $input["users_id"] = Session::getLoginUserID(); $newdoc = $doc->add($input); $docitem = new Document_Item(); $docitem->add(array('documents_id' => $newdoc, 'itemtype' => $options["itemtype"], 'items_id' => $options["ID"], 'entities_id' => $input["entities_id"])); $temp = new PluginManufacturersimportsLog(); $temp->deleteByCriteria(array('itemtype' => $options["itemtype"], 'items_id' => $options["ID"])); return $newdoc; }
/** * @param $type * @param $model_id * @param $tab_ids * @param $location **/ static function replace($type, $model_id, $tab_ids, $location) { global $DB, $CFG_GLPI, $PLUGIN_HOOKS; $model = new PluginUninstallModel(); $model->getConfig($model_id); $overwrite = $model->fields["overwrite"]; echo "<div class='center'>"; echo "<table class='tab_cadre_fixe'><tr><th>" . __('Replacement', 'uninstall') . "</th></tr>"; echo "<tr class='tab_bg_2'><td>"; $count = 0; $tot = count($tab_ids); Html::createProgressBar(__('Please wait, replacement is running...', 'uninstall')); foreach ($tab_ids as $olditem_id => $newitem_id) { $count++; $olditem = new $type(); $olditem->getFromDB($olditem_id); $newitem = new $type(); $newitem->getFromDB($newitem_id); //Hook to perform actions before item is being replaced $olditem->fields['_newid'] = $newitem_id; $olditem->fields['_uninstall_event'] = $model_id; $olditem->fields['_action'] = 'replace'; Plugin::doHook("plugin_uninstall_replace_before", $olditem); // Retrieve informations //States if ($model->fields['states_id'] != 0) { $olditem->update(array('id' => $olditem_id, 'states_id' => $model->fields['states_id']), false); } // METHOD REPLACEMENT 1 : Archive if ($model->fields['replace_method'] == self::METHOD_PURGE) { $name_out = str_shuffle(Toolbox::getRandomString(5) . time()); $plugin = new Plugin(); if ($plugin->isActivated('PDF')) { // USE PDF EXPORT $plugin->load('pdf', true); include_once GLPI_ROOT . "/lib/ezpdf/class.ezpdf.php"; //Get all item's tabs $tab = array_keys($olditem->defineTabs()); //Tell PDF to also export item's main tab, and in first position array_unshift($tab, "_main_"); $itempdf = new $PLUGIN_HOOKS['plugin_pdf'][$type]($olditem); $out = $itempdf->generatePDF(array($olditem_id), $tab, 1, false); $name_out .= ".pdf"; } else { //TODO Which datas ? Add Defaults... $out = __('Replacement', 'uninstall') . "\r\n"; $datas = $olditem->fields; unset($datas['comment']); foreach ($datas as $k => $v) { $out .= $k . ";"; } $out .= "\r\n"; foreach ($datas as $k => $v) { $out .= $v . ";"; } // USE CSV EXPORT $name_out .= ".csv"; } // Write document $out_file = GLPI_DOC_DIR . "/_uploads/" . $name_out; $open_file = fopen($out_file, 'a'); fwrite($open_file, $out); fclose($open_file); // Compute comment text $comment = __('This document is the archive of this replaced item', 'uninstall') . " " . self::getCommentsForReplacement($olditem, false, false); // Create & Attach new document to current item $doc = new Document(); $input = array('name' => addslashes(__('Archive of old material', 'uninstall')), 'upload_file' => $name_out, 'comment' => addslashes($comment), 'add' => __('Add'), 'entities_id' => $newitem->getEntityID(), 'is_recursive' => $newitem->isRecursive(), 'link' => "", 'documentcategories_id' => 0, 'items_id' => $olditem_id, 'itemtype' => $type); //Attached the document to the old item, to generate an accurate name $document_added = $doc->add($input); //Attach the document to the new item, once the document's name is correct $docItem = new Document_Item(); $docItemId = $docItem->add(array('documents_id' => $document_added, 'itemtype' => $type, 'items_id' => (int) $newitem_id)); } // General Informations - NAME if ($model->fields["replace_name"]) { if ($overwrite || empty($newitem->fields['name'])) { $newitem->update(array('id' => $newitem_id, 'name' => $olditem->getField('name')), false); } } $data['id'] = $newitem->getID(); // General Informations - SERIAL if ($model->fields["replace_serial"]) { if ($overwrite || empty($newitem->fields['serial'])) { $newitem->update(array('id' => $newitem_id, 'serial' => $olditem->getField('serial')), false); } } // General Informations - OTHERSERIAL if ($model->fields["replace_otherserial"]) { if ($overwrite || empty($newitem->fields['otherserial'])) { $newitem->update(array('id' => $newitem_id, 'otherserial' => $olditem->getField('otherserial')), false); } } // Documents if ($model->fields["replace_documents"] && in_array($type, $CFG_GLPI["document_types"])) { $doc_item = new Document_Item(); foreach (self::getAssociatedDocuments($olditem) as $document) { $doc_item->update(array('id' => $document['assocID'], 'itemtype' => $type, 'items_id' => $newitem_id), false); } } // Contracts if ($model->fields["replace_contracts"] && in_array($type, $CFG_GLPI["contract_types"])) { $contract_item = new Contract_Item(); foreach (self::getAssociatedContracts($olditem) as $contract) { $contract_item->update(array('id' => $contract['id'], 'itemtype' => $type, 'items_id' => $newitem_id), false); } } // Infocoms if ($model->fields["replace_infocoms"] && in_array($type, $CFG_GLPI["infocom_types"])) { $infocom = new Infocom(); if ($overwrite) { // Delete current Infocoms of new item if ($infocom->getFromDBforDevice($type, $newitem_id)) { //Do not log infocom deletion in the new item's history $infocom->dohistory = false; $infocom->deleteFromDB(1); } } // Update current Infocoms of old item if ($infocom->getFromDBforDevice($type, $olditem_id)) { $infocom->update(array('id' => $infocom->getID(), 'itemtype' => $type, 'items_id' => $newitem_id), false); } } // Reservations if ($model->fields["replace_reservations"] && in_array($type, $CFG_GLPI["reservation_types"])) { $resaitem = new ReservationItem(); if ($overwrite) { // Delete current reservation of new item $resa_new = new Reservation(); $resa_new->getFromDB($newitem_id); if ($resa_new->is_reserved()) { $resa_new = new ReservationItem(); $resa_new->getFromDBbyItem($type, $newitem_id); if (count($resa_new->fields)) { $resa_new->deleteFromDB(1); } } } // Update old reservation for attribute to new item $resa_old = new Reservation(); $resa_old->getFromDB($olditem_id); if ($resa_old->is_reserved()) { $resa_old = new ReservationItem(); $resa_old->getFromDBbyItem($type, $olditem_id); if (count($resa_old->fields)) { $resa_old->update(array('id' => $resa_old->getID(), 'itemtype' => $type, 'items_id' => $newitem_id), false); } } } // User if ($model->fields["replace_users"] && in_array($type, $CFG_GLPI["linkuser_types"])) { $data = array(); $data['id'] = $newitem->getID(); if ($newitem->isField('users_id') && ($overwrite || empty($data['users_id']))) { $data['users_id'] = $olditem->getField('users_id'); } if ($newitem->isField('contact') && ($overwrite || empty($data['contact']))) { $data['contact'] = $olditem->getField('contact'); } if ($newitem->isField('contact_num') && ($overwrite || empty($data['contact_num']))) { $data['contact_num'] = $olditem->getField('contact_num'); } $newitem->update($data, false); } // Group if ($model->fields["replace_groups"] && in_array($type, $CFG_GLPI["linkgroup_types"])) { if ($newitem->isField('groups_id') && ($overwrite || empty($data['groups_id']))) { $newitem->update(array('id' => $newitem_id, 'groups_id' => $olditem->getField('groups_id')), false); } } // Tickets if ($model->fields["replace_tickets"] && in_array($type, $CFG_GLPI["ticket_types"])) { $ticket_item = new Item_Ticket(); foreach (self::getAssociatedTickets($type, $olditem_id) as $ticket) { $ticket_item->update(array('id' => $ticket['id'], 'items_id' => $newitem_id), false); } } //Array netport_types renamed in networkport_types in GLPI 0.80 if (isset($CFG_GLPI["netport_types"])) { $netport_types = $CFG_GLPI["netport_types"]; } else { $netport_types = $CFG_GLPI["networkport_types"]; } // NetPorts if ($model->fields["replace_netports"] && in_array($type, $netport_types)) { $netport_item = new NetworkPort(); foreach (self::getAssociatedNetports($type, $olditem_id) as $netport) { $netport_item->update(array('id' => $netport['id'], 'itemtype' => $type, 'items_id' => $newitem_id), false); } } // Directs connections if ($model->fields["replace_direct_connections"] && in_array($type, array('Computer'))) { $comp_item = new Computer_Item(); foreach (self::getAssociatedItems($olditem) as $itemtype => $connections) { foreach ($connections as $connection) { $comp_item->update(array('id' => $connection['id'], 'computers_id' => $newitem_id, 'itemtype' => $itemtype), false); } } } // Location if ($location != 0 && $olditem->isField('locations_id')) { $olditem->getFromDB($olditem_id); switch ($location) { case -1: break; default: $olditem->update(array('id' => $olditem_id, 'locations_id' => $location), false); break; } } $plug = new Plugin(); if ($plug->isActivated('ocsinventoryng')) { //Delete computer from OCS if ($model->fields["remove_from_ocs"] == 1) { PluginUninstallUninstall::deleteComputerInOCSByGlpiID($olditem_id); } //Delete link in glpi_ocs_link if ($model->fields["delete_ocs_link"] || $model->fields["remove_from_ocs"]) { PluginUninstallUninstall::deleteOcsLink($olditem_id); } } if ($plug->isActivated('fusioninventory')) { if ($model->fields['raz_fusioninventory']) { PluginUninstallUninstall::deleteFusionInventoryLink(get_class($olditem), $olditem_id); } } // METHOD REPLACEMENT 1 : Purge if ($model->fields['replace_method'] == self::METHOD_PURGE) { // Retrieve, Compute && Update NEW comment field $comment = self::getCommentsForReplacement($olditem, true); $comment .= "\n- " . __('See attached document', 'uninstall'); $newitem->update(array('id' => $newitem_id, 'comment' => addslashes($comment)), false); // If old item is attached in PDF/CSV // Delete AND Purge it in DB if ($document_added) { $olditem->delete(array('id' => $olditem_id), true); } } // METHOD REPLACEMENT 2 : Delete AND Comment if ($model->fields['replace_method'] == self::METHOD_DELETE_AND_COMMENT) { //Add comment on the new item first $comment = self::getCommentsForReplacement($olditem, true); $newitem->update(array('id' => $newitem_id, 'comment' => Toolbox::addslashes_deep($comment)), false); // Retrieve, Compute && Update OLD comment field $comment = self::getCommentsForReplacement($newitem, false); $olditem->update(array('id' => $olditem_id, 'comment' => Toolbox::addslashes_deep($comment)), false); // Delete OLD item from DB (not PURGE) PluginUninstallUninstall::addUninstallLog($type, $olditem_id, 'replaced_by'); $olditem->delete(array('id' => $olditem_id), 0, false); } //Plugin hook after replacement Plugin::doHook("plugin_uninstall_replace_after", $olditem); //Add history PluginUninstallUninstall::addUninstallLog($type, $newitem_id, 'replace'); Html::changeProgressBarPosition($count, $tot + 1); } Html::changeProgressBarPosition($count, $tot, __('Replacement successful', 'uninstall')); echo "</td></tr>"; echo "</table></div>"; }