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 */ 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_item = new Document_Item(); $document = new Document(); foreach (getAllDatasFromTable('glpi_documents_items', "`itemtype`='PluginOrderOrder'\n AND `items_id`='{$orders_id}'") as $doc) { $document->getFromDB($doc['documents_id']); $mime = $document->fields['mime']; $newdocument = clone $document; $newdocument->fields['entities_id'] = $entity; unset($newdocument->fields['id']); $newID = $document->add($newdocument->fields); $tmp['itemtype'] = $itemtype; $tmp['items_id'] = $items_id; $tmp['documents_id'] = $newID; $document_item->add($tmp); //force mimetype $document->update(array('id' => $newID, 'mime' => $mime)); } } }
/** * 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 files (from $_FILES) to a ticket * create document if needed * create link from document to ticket * * @param $id of the ticket * * @return array of doc added name **/ function addFiles($id) { global $LANG, $CFG_GLPI; if (!isset($_FILES)) { return array(); } $docadded = array(); $doc = new Document(); $docitem = new Document_Item(); // add Document if exists if (isset($_FILES['multiple'])) { unset($_FILES['multiple']); $TMPFILE = $_FILES; } 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(); $input2["name"] = addslashes($LANG['tracking'][24] . " {$id}"); $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, 'itemtype' => $this->getType(), 'items_id' => $id))) { $docadded[] = stripslashes($doc->fields["name"] . " - " . $doc->fields["filename"]); } } } else { if (!empty($_FILES['filename']['name']) && isset($_FILES['filename']['error']) && $_FILES['filename']['error']) { addMessageAfterRedirect($LANG['document'][46], false, ERROR); } } } unset($_FILES); return $docadded; }
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); }
/** 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)); } } }
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");
/** * Résultat de la création du sous-lieu + ajout dans la base de données */ static function showFormResCreateLocation($opt) { global $CFG_GLPI, $DB; $filename = $opt["document_id"] . $opt["name"] . "." . $opt["extension"]; $filepath = "/_uploads/" . $filename; $id = 0; if ($opt["test"] == "existLocation") { $query = "SELECT `id`,`name`\n FROM `glpi_locations`\n WHERE `id` = '" . $opt["locations_id"] . "'"; $result = $DB->query($query); while ($data = $DB->fetch_assoc($result)) { $name = $data['name']; $id = $data['id']; } } else { if ($opt["test"] == "newLocation") { $locations_id = $opt["locations_idParent"]; } } $params = array("name" => $opt["name"], "document_id" => $opt["document_id"], "filepath" => $filepath, "filename" => $filename, "entities_id" => $opt["entities_id"], "locations_id" => $opt["locations_id"], "id" => $id, "itemtype" => "Location"); //FONCTION QUI PERMET D'AJOUTER LE LIEU DANS LA BASE DE DONNEES $dropdown = new Location(); //AJOUT DU LIEU if ($opt["test"] == 'newLocation') { if ($newID = $dropdown->add($params)) { } else { $locations_found = $dropdown->find("`name` = '" . $params['name'] . "' AND `entities_id` = '" . $params['entities_id'] . "' AND `locations_id` = '" . $params['locations_id'] . "'", '', '1'); $newID = key($locations_found); } $opt["locations_id"] = $newID; } if ($opt["locations_id"] != $opt["locations_idParent"]) { //AJOUT DU DOC ASSOCIE AU LIEU $doc = new Document(); $documentitem = new Document_Item(); $self = new self(); $input = array(); $input["entities_id"] = $opt["entities_id"]; $input["name"] = $opt["name"]; $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); // Add new location if ($opt["test"] == 'newLocation') { // We check if the element already exists $restrict = "`items_id` = '" . $newID . "' AND `itemtype` = 'Location'"; if (countElementsInTable("glpi_plugin_positions_positions", $restrict) != 0) { Session::addMessageAfterRedirect(__('This item is already bound to a location', 'positions'), false, ERROR); Html::redirect($CFG_GLPI["root_doc"] . "/plugins/positions/front/map.php?locations_id=" . $opt["locations_idParent"]); // If not we can add its position and picture } else { $documentitem->add(array('documents_id' => $newdoc, 'itemtype' => 'Location', 'items_id' => $newID, 'entities_id' => $opt["entities_id"])); $param = array("items_id" => $newID, "entities_id" => $opt["entities_id"], "locations_id" => $opt["locations_idParent"], "itemtype" => "Location", "x_coordinates" => -800, "y_coordinates" => -150); $self->add($param); if ($opt["checked"] == 'on') { self::showMapCreateLocation($opt); } else { if ($opt["checked"] == 'off') { Html::redirect($CFG_GLPI["root_doc"] . "/plugins/positions/front/map.php?locations_id=" . $opt["locations_id"]); } } } // Add existing location } else { if ($opt["test"] == 'existLocation') { $documentitem->add(array('documents_id' => $newdoc, 'itemtype' => 'Location', 'items_id' => $id)); $param = array("items_id" => $id, "entities_id" => $opt["entities_id"], "locations_id" => $opt["locations_idParent"], "itemtype" => "Location", "x_coordinates" => -800, "y_coordinates" => -150); $self->add($param); if ($opt["checked"] == 'on') { self::showMapCreateLocation($opt); } else { if ($opt["checked"] == 'off') { Html::redirect($CFG_GLPI["root_doc"] . "/plugins/positions/front/map.php?locations_id=" . $opt["locations_id"]); } } } } } else { Session::addMessageAfterRedirect(__('This item is already bound to a location', 'positions'), false, ERROR); Html::redirect($CFG_GLPI["root_doc"] . "/plugins/positions/front/map.php?locations_id=" . $opt["locations_id"]); } }
function post_addItem() { global $DB, $CFG_GLPI; // Manage add from template if (isset($this->input["_oldID"])) { // ADD Infocoms $ic = new Infocom(); $ic->cloneItem($this->getType(), $this->input["_oldID"], $this->fields['id']); // ADD Ports $query = "SELECT `id`\n FROM `glpi_networkports`\n WHERE `items_id` = '" . $this->input["_oldID"] . "'\n AND `itemtype` = '" . $this->getType() . "'"; $result = $DB->query($query); if ($DB->numrows($result) > 0) { while ($data = $DB->fetch_array($result)) { $np = new NetworkPort(); $npv = new NetworkPort_Vlan(); $np->getFromDB($data["id"]); unset($np->fields["id"]); unset($np->fields["ip"]); unset($np->fields["mac"]); unset($np->fields["netpoints_id"]); $np->fields["items_id"] = $this->fields['id']; $portid = $np->addToDB(); foreach ($DB->request('glpi_networkports_vlans', array('networkports_id' => $data["id"])) as $vlan) { $npv->assignVlan($portid, $vlan['vlans_id']); } } } // ADD Contract $query = "SELECT `contracts_id`\n FROM `glpi_contracts_items`\n WHERE `items_id` = '" . $this->input["_oldID"] . "'\n AND `itemtype` = '" . $this->getType() . "'"; $result = $DB->query($query); if ($DB->numrows($result) > 0) { $contractitem = new Contract_Item(); while ($data = $DB->fetch_array($result)) { $contractitem->add(array('contracts_id' => $data["contracts_id"], 'itemtype' => $this->getType(), 'items_id' => $this->fields['id'])); } } // 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'])); } } } }
/** * @see CommonDBTM::doSpecificMassiveActions() **/ function doSpecificMassiveActions($input = array()) { $res = array('ok' => 0, 'ko' => 0, 'noright' => 0); switch ($input['action']) { case "add_document": case "add_document_item": $documentitem = new Document_Item(); foreach ($input["item"] as $key => $val) { if (isset($input['items_id'])) { // Add items to documents $input2 = array('itemtype' => $input["item_itemtype"], 'items_id' => $input["items_id"], 'documents_id' => $key); } else { if (isset($input['documents_id'])) { // Add document to item $input2 = array('itemtype' => $input["itemtype"], 'items_id' => $key, 'documents_id' => $input['documents_id']); } else { return false; } } if ($documentitem->can(-1, 'w', $input2)) { if ($documentitem->add($input2)) { $res['ok']++; } else { $res['ko']++; } } else { $res['noright']++; } } break; case "remove_document": case "remove_document_item": foreach ($input["item"] as $key => $val) { if (isset($input['items_id'])) { // Remove item to documents $input2 = array('itemtype' => $input["item_itemtype"], 'items_id' => $input["items_id"], 'documents_id' => $key); } else { if (isset($input['documents_id'])) { // Remove contract to items $input2 = array('itemtype' => $input["itemtype"], 'items_id' => $key, 'documents_id' => $input['documents_id']); } else { return false; } } $docitem = new Document_Item(); if ($docitem->can(-1, 'w', $input2)) { if ($item = getItemForItemtype($input2["itemtype"])) { if ($item->getFromDB($input2['items_id'])) { $doc = new self(); if ($doc->getFromDB($input2['documents_id'])) { if ($docitem->getFromDBForItems($doc, $item)) { if ($docitem->delete(array('id' => $docitem->getID()))) { $res['ok']++; } else { $res['ko']++; } } else { $res['ko']++; } } else { $res['ko']++; } } else { $res['ko']++; } } else { $res['ko']++; } } else { $res['noright']++; } } break; default: return parent::doSpecificMassiveActions($input); } return $res; }
function post_addItem() { global $LANG; if (isset($this->input["items_id"]) && $this->input["items_id"] > 0 && isset($this->input["itemtype"]) && !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", $_SESSION["glpiname"] . " " . $LANG['log'][32]); } }
*/ // ---------------------------------------------------------------------- // Original Author of file: Julien Dombre // Purpose of file: // ---------------------------------------------------------------------- define('GLPI_ROOT', '..'); include GLPI_ROOT . "/inc/includes.php"; if (!isset($_GET["id"])) { $_GET["id"] = -1; } $doc = new Document(); $documentitem = new Document_Item(); if (isset($_POST["add"])) { $doc->check(-1, 'w', $_POST); if (isset($_POST['itemtype']) && isset($_POST['items_id']) && isset($_FILES['filename']['tmp_name']) && $doc->getFromDBbyContent($_POST["entities_id"], $_FILES['filename']['tmp_name'])) { $documentitem->add(array('documents_id' => $doc->fields['id'], 'itemtype' => $_POST['itemtype'], 'items_id' => $_POST['items_id'])); } else { $newID = $doc->add($_POST); $name = ""; if (isset($_POST["name"])) { $name = $_POST["name"]; } else { if (isset($_FILES['filename']) && isset($_FILES['filename']['name'])) { $name = $_FILES['filename']['name']; } } Event::log($newID, "documents", 4, "document", $_SESSION["glpiname"] . " " . $LANG['log'][20] . " " . $name . "."); } glpi_header($_SERVER['HTTP_REFERER']); } else { if (isset($_POST["delete"])) {
function post_addItem() { global $DB, $CFG_GLPI; // Manage add from template if (isset($this->input["_oldID"])) { // ADD Infocoms $ic = new Infocom(); $ic->cloneItem($this->getType(), $this->input["_oldID"], $this->fields['id']); // ADD Contract $query = "SELECT `contracts_id`\n FROM `glpi_contracts_items`\n WHERE `items_id` = '" . $this->input["_oldID"] . "'\n AND `itemtype` = '" . $this->getType() . "'"; $result = $DB->query($query); if ($DB->numrows($result) > 0) { $contractitem = new Contract_Item(); while ($data = $DB->fetch_array($result)) { $contractitem->add(array('contracts_id' => $data["contracts_id"], 'itemtype' => $this->getType(), 'items_id' => $this->fields['id'])); } } // 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'])); } } } }
/** * * @param type $items_id id of the ticket */ static function createSubTicket($items_id) { global $CFG_GLPI; if ($_POST['slas_id'] == 0 || $_POST['groupsubticket'] == 0) { // return; } $ticket = new Ticket(); $ticketFollowup = new TicketFollowup(); $ticketTask = new TicketTask(); $document_Item = new Document_Item(); $ticket_User = new Ticket_User(); $group_Ticket = new Group_Ticket(); // Disable send notification $use_mailing = $CFG_GLPI["use_mailing"]; $CFG_GLPI["use_mailing"] = false; $ticket->getFromDB($items_id); unset($ticket->fields['id']); $ticket->fields['_link']['link'] = 1; $ticket->fields['_link']['tickets_id_1'] = 0; $ticket->fields['_link']['tickets_id_2'] = $items_id; $ticket->fields['bypassgrouponadd'] = true; $ticket->fields['slas_id'] = $_POST['slas_id']; $ticket->fields['date'] = date("Y-m-d H:i:s"); $ticket->fields = Toolbox::addslashes_deep($ticket->fields); foreach ($ticket->fields as $key => $value) { if ($value == '') { unset($ticket->fields[$key]); } } $new_tickets_id = $ticket->add($ticket->fields); $a_followups = $ticketFollowup->find("`tickets_id`='" . $items_id . "'", "`id`"); foreach ($a_followups as $data) { unset($data['id']); $data = Toolbox::addslashes_deep($data); $data['tickets_id'] = $new_tickets_id; $ticketFollowup->add($data); } $a_tasks = $ticketTask->find("`tickets_id`='" . $items_id . "'", "`id`"); foreach ($a_tasks as $data) { unset($data['id']); $data = Toolbox::addslashes_deep($data); $data['tickets_id'] = $new_tickets_id; foreach ($data as $key => $value) { if ($value == '') { unset($data[$key]); } } $ticketTask->add($data); } $a_documents = $document_Item->find("`items_id`='" . $items_id . "'\n AND `itemtype`='Ticket'", "`id`"); foreach ($a_documents as $data) { unset($data['id']); $data = Toolbox::addslashes_deep($data); $data['items_id'] = $new_tickets_id; $document_Item->add($data); } $a_ticketusers = $ticket_User->find("`tickets_id`='" . $items_id . "'\n AND `type`='1'", "`id`"); foreach ($a_ticketusers as $data) { unset($data['id']); $data = Toolbox::addslashes_deep($data); $data['tickets_id'] = $new_tickets_id; $ticket_User->add($data); } $a_ticketgroups = $group_Ticket->find("`tickets_id`='" . $items_id . "'\n AND `type`='1'", "`id`"); foreach ($a_ticketgroups as $data) { unset($data['id']); $data = Toolbox::addslashes_deep($data); $data['tickets_id'] = $new_tickets_id; $group_Ticket->add($data); } $CFG_GLPI["use_mailing"] = $use_mailing; $input = array(); $input['tickets_id'] = $new_tickets_id; $input['groups_id'] = $_POST['groupsubticket']; $input['type'] = 2; $group_Ticket->add($input); }
/** * 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 generatePdf($itemtype, $data, $saveas) { global $CFG_GLPI, $PDF, $DB; $ID = $data["id"]; //name if (!empty($data["name"])) { $name_item = Toolbox::decodeFromUtf8($data["name"]); } else { $name_item = ""; } //user if (!empty($data["users_id"])) { $user_item = Toolbox::decodeFromUtf8(Html::clean(getUserName($data["users_id"]))); } else { if (!empty($data["groups_id"])) { $user_item = Toolbox::decodeFromUtf8(Dropdown::getDropdownName("glpi_groups", $data["groups_id"])); } else { $user_item = ""; } } //fabricant if (!empty($data["manufacturers_id"])) { $fabricant_item = Toolbox::decodeFromUtf8(Dropdown::getDropdownName("glpi_manufacturers", $data["manufacturers_id"])); } else { $fabricant_item = ""; } //serial if (!empty($data["serial"])) { $serial_item = Toolbox::decodeFromUtf8($data["serial"]); } else { $serial_item = ""; } $class = $itemtype . "Type"; $item = new $class(); $typefield = getForeignKeyFieldForTable(getTableForItemType($itemtype . "Type")); $item->getFromDB($data[$typefield]); if (!empty($typefield) && !empty($item->fields["name"])) { $type_item = Toolbox::decodeFromUtf8($item->fields["name"]); } else { $type_item = ""; } //infocoms $ic = new Infocom(); if ($ic->getfromDBforDevice($itemtype, $ID)) { //immobilizationsheets_item if (!empty($ic->fields["immo_number"])) { $immobilizationsheets_item = Toolbox::decodeFromUtf8($ic->fields["immo_number"]); } else { $immobilizationsheets_item = ""; } //buy_date if (!empty($ic->fields["buy_date"])) { $buy_date_item = Toolbox::decodeFromUtf8(Html::convdate($ic->fields["buy_date"])); } else { $buy_date_item = ""; } //use_date if (!empty($ic->fields["use_date"])) { $use_date_item = Toolbox::decodeFromUtf8(Html::convdate($ic->fields["use_date"])); } else { $use_date_item = ""; } //order_number if (!empty($ic->fields["order_number"])) { $order_number_item = Toolbox::decodeFromUtf8($ic->fields["order_number"]); } else { $order_number_item = ""; } //value_item if (!empty($ic->fields["value"])) { $value_item = Toolbox::decodeFromUtf8(Html::clean(Html::formatNumber($ic->fields["value"]))); } else { $value_item = ""; } //sink_time if (!empty($ic->fields["sink_time"])) { $sink_time_item = Toolbox::decodeFromUtf8(sprintf(_n('%d year', '%d years', $ic->fields["sink_time"]), $ic->fields["sink_time"])); } else { $sink_time_item = ""; } //sink_type if (!empty($ic->fields["sink_type"])) { $sink_type_item = Toolbox::decodeFromUtf8(Infocom::getAmortTypeName($ic->fields["sink_type"])); } else { $sink_type_item = ""; } } else { $immobilizationsheets_item = ""; $buy_date_item = ""; $use_date_item = ""; $order_number_item = ""; $value_item = ""; $sink_time_item = ""; $sink_type_item = ""; } //composants $devtypes = self::getDeviceTypes(); if ($itemtype == 'Computer') { $device2 = new $devtypes[2](); $query2 = "SELECT `deviceprocessors_id`\n FROM `" . getTableForItemType('items_' . $devtypes[2]) . "`\n WHERE `items_id` = '{$ID}'"; $result2 = $DB->query($query2); $number2 = $DB->numrows($result2); $device3 = new $devtypes[3](); $query3 = "SELECT SUM(`size`) AS total\n FROM `" . getTableForItemType('items_' . $devtypes[3]) . "`\n WHERE `items_id` = '{$ID}'"; $result3 = $DB->query($query3); $number3 = $DB->numrows($result3); $query3b = "SELECT `devicememories_id`\n FROM `" . getTableForItemType('items_' . $devtypes[3]) . "`\n WHERE `items_id` = '{$ID}'"; $result3b = $DB->query($query3b); $number3b = $DB->numrows($result3b); $device4 = new $devtypes[4](); $query4 = "SELECT `deviceharddrives_id`,`capacity`\n FROM `" . getTableForItemType('items_' . $devtypes[4]) . "`\n WHERE `items_id` = '{$ID}'"; $result4 = $DB->query($query4); $number4 = $DB->numrows($result4); $device5 = new $devtypes[6](); $query5 = "SELECT `devicedrives_id`\n FROM `" . getTableForItemType('items_' . $devtypes[6]) . "`\n WHERE `items_id` = '{$ID}'"; $result5 = $DB->query($query5); $number5 = $DB->numrows($result5); if ($number2 != 0) { while ($data2 = $DB->fetch_array($result2)) { //proc_item if (!empty($data2["deviceprocessors_id"])) { $query_proc = "SELECT `designation`\n FROM `glpi_deviceprocessors`\n WHERE `id` = '" . $data2["deviceprocessors_id"] . "'"; $result_proc = $DB->query($query_proc); $number_proc = $DB->numrows($result_proc); if ($number_proc != 0) { while ($data_proc = $DB->fetch_array($result_proc)) { $proc_item = Toolbox::decodeFromUtf8($data_proc["designation"]); } } } } } else { $proc_item = ""; } if ($number3 != 0) { while ($data3 = $DB->fetch_array($result3)) { //ram_item $ram_item = $data3["total"]; } } else { $ram_item = ""; } $ram_type_item = ""; if ($number3b != 0) { while ($data3b = $DB->fetch_array($result3b)) { //ram_type_item if (!empty($data3b["devicememories_id"])) { $query_ram = "SELECT `glpi_devicememorytypes`.`name`\n FROM `glpi_devicememories`,`glpi_devicememorytypes`\n WHERE `glpi_devicememories`.`id` = '" . $data3b["devicememories_id"] . "'\n AND `glpi_devicememorytypes`.`id` = `glpi_devicememories`.`devicememorytypes_id` "; $result_ram = $DB->query($query_ram); $number_ram = $DB->numrows($result_ram); if ($number_ram != 0) { while ($data_ram = $DB->fetch_array($result_ram)) { $ram_type_item = Toolbox::decodeFromUtf8($data_ram["name"]); } } else { $ram_type_item = ""; } } } } else { $ram_type_item = ""; } $hdd_item = ""; $hdd_designation_item = ""; $hdd_interface_item = ""; if ($number4 != 0) { while ($data4 = $DB->fetch_array($result4)) { //hdd_item $hdd_size_item = Toolbox::decodeFromUtf8($data4["capacity"]); if (!empty($data4["deviceharddrives_id"])) { $query_hdd = "SELECT `designation`\n FROM `glpi_deviceharddrives`\n WHERE `id` = '" . $data4["deviceharddrives_id"] . "'"; $result_hdd = $DB->query($query_hdd); $number_hdd = $DB->numrows($result_hdd); if ($number_hdd != 0) { while ($data_hdd = $DB->fetch_array($result_hdd)) { $hdd_designation_item = Toolbox::decodeFromUtf8($data_hdd["designation"]); } } else { $hdd_designation_item = ""; } $query_hdd1 = "SELECT `glpi_interfacetypes`.`name`\n FROM `glpi_deviceharddrives`,`glpi_interfacetypes`\n WHERE `glpi_deviceharddrives`.`id` = '" . $data4["deviceharddrives_id"] . "'\n AND `glpi_interfacetypes`.`id` = `glpi_deviceharddrives`.`interfacetypes_id` "; //replace interface by FK_interface 0.72.1 $result_hdd1 = $DB->query($query_hdd1); $number_hdd1 = $DB->numrows($result_hdd1); if ($number_hdd1 != 0) { while ($data_hdd1 = $DB->fetch_array($result_hdd1)) { $hdd_interface_item = Toolbox::decodeFromUtf8($data_hdd1["name"]); } } } else { $hdd_interface_item = ""; } $hdd_item .= $hdd_designation_item . " " . $hdd_interface_item . " (" . $hdd_size_item . " Mo)"; if ($number4 > 1) { $hdd_item .= " - "; } } } else { $hdd_item = ""; } $lecteur_item = ""; if ($number5 != 0) { while ($data5 = $DB->fetch_array($result5)) { //lecteur_item if (!empty($data5["items_id"])) { $query_lecteur = "SELECT `designation`\n FROM `glpi_devicedrives`\n WHERE `id` = '" . $data5["interfacetypes_id"] . "'"; $result_lecteur = $DB->query($query_lecteur); $number_lecteur = $DB->numrows($result_lecteur); if ($number_lecteur != 0) { while ($data_lecteur = $DB->fetch_array($result_lecteur)) { $lecteur_item .= Toolbox::decodeFromUtf8($data_lecteur["designation"]); if ($number5 > 1) { $lecteur_item .= " - "; } } } } } } else { $lecteur_item = ""; } //softwares $query6 = "SELECT `glpi_softwares`.`name`,`glpi_softwarelicenses`.`softwareversions_id_buy`,`glpi_softwarelicenses`.`serial`\n FROM `glpi_softwarelicenses`\n INNER JOIN `glpi_computers_softwarelicenses` ON (`glpi_softwarelicenses`.`id` = `glpi_computers_softwarelicenses`.`softwarelicenses_id` AND `glpi_computers_softwarelicenses`.`computers_id` = '{$ID}') \n INNER JOIN `glpi_softwares` ON (`glpi_softwarelicenses`.`softwares_id` = `glpi_softwares`.`id`) "; $result6 = $DB->query($query6); $number6 = $DB->numrows($result6); } //Affichage //$PDF->addJpegFromFile('../pics/immobilizationsheets.jpg',285,785,32,32); //title $PDF->ezSetDy(-20); $title = array(array('' => Toolbox::decodeFromUtf8(__('IDENTIFICATION IMMOBILIZATION SHEET', 'immobilizationsheets')))); $cols = array('' => array('width' => 530, 'justification' => 'center')); $PDF->ezTable($title, '', '', array('cols' => $cols, 'showHeadings' => 0, 'fontSize' => 12, 'showLines' => 0, 'shaded' => 2, 'shadeCol' => array(0.8, 0.8, 0.8), 'shadeCol2' => array(0.8, 0.8, 0.8))); $PDF->ezSetDy(-10); //partie 1 $PDF->ezSetDy(-20); $title1 = array(array('' => Toolbox::decodeFromUtf8(__('I - PART TO BE FILLED BY THE PERSON IN CHARGE FOR THE PURCHASES', 'immobilizationsheets')))); $cols = array('' => array('width' => 530, 'justification' => 'left')); $PDF->ezTable($title1, '', '', array('cols' => $cols, 'showHeadings' => 0, 'fontSize' => 10, 'showLines' => 0, 'shaded' => 2, 'shadeCol' => array(0.8, 0.8, 0.8), 'shadeCol2' => array(0.8, 0.8, 0.8))); $title2 = array(array('' => Toolbox::decodeFromUtf8(__('(transfer the original to the administrator network so computer equipement, the assistant of management in the other cases)', 'immobilizationsheets')))); $cols = array('' => array('width' => 530, 'justification' => 'left')); $PDF->ezTable($title2, '', '', array('cols' => $cols, 'showHeadings' => 0, 'fontSize' => 8, 'showLines' => 0, 'shaded' => 2, 'shadeCol' => array(0.8, 0.8, 0.8), 'shadeCol2' => array(0.8, 0.8, 0.8))); $PDF->ezSetDy(-10); //Date mise en service $PDF->ezText("<u>" . Toolbox::decodeFromUtf8(__('Startup date')) . "</u> : " . $buy_date_item, 8, array("justification" => "left")); $PDF->ezSetDy(-10); //ligne1 (entreprise / fournisseur) $data1 = array(array('0' => Toolbox::decodeFromUtf8(__('MY ENTERPRISE', 'immobilizationsheets')), '1' => Toolbox::decodeFromUtf8(strtoupper(__('Supplier'))))); $cols1 = array('0' => array('width' => 265, 'justification' => 'center'), '1' => array('width' => 265, 'justification' => 'center')); $PDF->ezTable($data1, '', __('COMPUTER IDENTIFICATION', 'immobilizationsheets'), array('showHeadings' => 0, 'cols' => $cols1)); //ligne2 (4 / 9) $data2 = array(array('0' => Toolbox::decodeFromUtf8(__('Assignment number (si non informatique)', 'immobilizationsheets')), '1' => '', '2' => Toolbox::decodeFromUtf8(__('Brand')), '3' => $fabricant_item)); $cols2 = array('0' => array('width' => 132.5, 'fontSize' => 8, 'justification' => 'left'), '1' => array('width' => 132.5, 'justification' => 'left'), '2' => array('width' => 132.5, 'justification' => 'left'), '3' => array('width' => 132.5, 'justification' => 'left')); $PDF->ezTable($data2, '', '', array('showHeadings' => 0, 'cols' => $cols2, 'fontSize' => 8)); //ligne3 (5 / 10) $data3 = array(array('0' => Toolbox::decodeFromUtf8(__('Invoice number')), '1' => $order_number_item, '2' => Toolbox::decodeFromUtf8(__('Type')), '3' => $type_item)); $cols3 = array('0' => array('width' => 132.5, 'fontSize' => 8, 'justification' => 'left'), '1' => array('width' => 132.5, 'justification' => 'left'), '2' => array('width' => 132.5, 'justification' => 'left'), '3' => array('width' => 132.5, 'justification' => 'left')); $PDF->ezTable($data3, '', '', array('showHeadings' => 0, 'cols' => $cols3, 'fontSize' => 8)); //ligne4 (6 / 11) $data4 = array(array('0' => Toolbox::decodeFromUtf8(__('Value')), '1' => $value_item, '2' => Toolbox::decodeFromUtf8(__('Serial Number')), '3' => $serial_item)); $cols4 = array('0' => array('width' => 132.5, 'fontSize' => 8, 'justification' => 'left'), '1' => array('width' => 132.5, 'justification' => 'left'), '2' => array('width' => 132.5, 'justification' => 'left'), '3' => array('width' => 132.5, 'justification' => 'left')); $PDF->ezTable($data4, '', '', array('showHeadings' => 0, 'cols' => $cols4, 'fontSize' => 8)); //ligne5 (7 / 12) $data5 = array(array('0' => Toolbox::decodeFromUtf8(__('Assignment (client / inv. …)', 'immobilizationsheets')), '1' => '', '2' => Toolbox::decodeFromUtf8(__('Permanent number', 'immobilizationsheets')), '3' => $immobilizationsheets_item)); $cols5 = array('0' => array('width' => 132.5, 'fontSize' => 8, 'justification' => 'left'), '1' => array('width' => 132.5, 'justification' => 'left'), '2' => array('width' => 132.5, 'justification' => 'left'), '3' => array('width' => 132.5, 'justification' => 'left')); $PDF->ezTable($data5, '', '', array('showHeadings' => 0, 'cols' => $cols5, 'fontSize' => 8)); $PDF->ezSetDy(-10); //trigramme $data6 = array(array('0' => Toolbox::decodeFromUtf8(__('Trigram and visa of the person in charge', 'immobilizationsheets')), '1' => '')); $cols6 = array('0' => array('width' => 430, 'fontSize' => 8, 'justification' => 'right'), '1' => array('width' => 100, 'justification' => 'left')); $PDF->ezTable($data6, '', '', array('showHeadings' => 0, 'cols' => $cols6, 'xPos' => 'center', 'xOreintation' => 'right', 'fontSize' => 8)); //partie 2 $PDF->ezSetDy(-20); $title1 = array(array('' => Toolbox::decodeFromUtf8(__('II - PART TO BE FILLED BY THE NETWORK ADMINISTRATOR', 'immobilizationsheets')))); $cols = array('' => array('width' => 530, 'justification' => 'left')); $PDF->ezTable($title1, '', '', array('cols' => $cols, 'showHeadings' => 0, 'fontSize' => 10, 'showLines' => 0, 'shaded' => 2, 'shadeCol' => array(0.8, 0.8, 0.8), 'shadeCol2' => array(0.8, 0.8, 0.8))); $title2 = array(array('' => Toolbox::decodeFromUtf8(__('(transfer to the assistant of management)', 'immobilizationsheets')))); $cols = array('' => array('width' => 530, 'justification' => 'left')); $PDF->ezTable($title2, '', '', array('cols' => $cols, 'showHeadings' => 0, 'fontSize' => 8, 'showLines' => 0, 'shaded' => 2, 'shadeCol' => array(0.8, 0.8, 0.8), 'shadeCol2' => array(0.8, 0.8, 0.8))); $PDF->ezSetDy(-10); //ligne1 (name / user) $data1 = array(array('0' => Toolbox::decodeFromUtf8(__('User name / sector', 'immobilizationsheets')), '1' => $user_item, '2' => Toolbox::decodeFromUtf8(__('Name')), '3' => $name_item)); $cols1 = array('0' => array('width' => 132.5, 'justification' => 'center'), '1' => array('width' => 132.5, 'justification' => 'center'), '2' => array('width' => 132.5, 'justification' => 'center'), '3' => array('width' => 132.5, 'justification' => 'center')); $PDF->ezTable($data1, '', __('PRINCIPAL ASSIGNMENT', 'immobilizationsheets'), array('fontSize' => 8, 'showHeadings' => 0, 'cols' => $cols1)); $PDF->ezSetDy(-10); if ($itemtype == 'Computer') { //title config mat?ielle $title = array(array('' => Toolbox::decodeFromUtf8(__('HARDWARE CONFIGURATION', 'immobilizationsheets')))); $cols = array('' => array('width' => 530, 'justification' => 'center')); $PDF->ezTable($title, '', '', array('cols' => $cols, 'showHeadings' => 0, 'fontSize' => 12, 'showLines' => 1)); $PDF->ezSetDy(-10); //ligne1 (processeur / ram quantit?/ ram type) $data1 = array(array('0' => Toolbox::decodeFromUtf8(__('Processor')), '1' => $proc_item, '2' => Toolbox::decodeFromUtf8(__('Memory')), '3' => Toolbox::decodeFromUtf8(__('Quantity', 'immobilizationsheets')), '4' => $ram_item, '5' => Toolbox::decodeFromUtf8(__('Type')), '6' => $ram_type_item)); $cols1 = array('0' => array('width' => 55, 'justification' => 'center'), '1' => array('width' => 200, 'justification' => 'left'), '2' => array('width' => 55, 'justification' => 'center'), '3' => array('width' => 55, 'justification' => 'center'), '4' => array('width' => 55, 'justification' => 'center'), '5' => array('width' => 55, 'justification' => 'center'), '6' => array('width' => 55, 'justification' => 'center')); $PDF->ezTable($data1, '', '', array('fontSize' => 8, 'showHeadings' => 0, 'cols' => $cols1)); //ligne2 (Disque dur / Lecteur) $data1 = array(array('0' => Toolbox::decodeFromUtf8(__('Hard drive')), '1' => $hdd_item, '2' => Toolbox::decodeFromUtf8(__('Drive')), '3' => $lecteur_item)); $cols1 = array('0' => array('width' => 55, 'justification' => 'center'), '1' => array('width' => 200, 'justification' => 'left'), '2' => array('width' => 55, 'justification' => 'center'), '3' => array('width' => 220, 'justification' => 'center')); $PDF->ezTable($data1, '', '', array('fontSize' => 8, 'showHeadings' => 0, 'cols' => $cols1)); $PDF->ezSetDy(-10); //titre suppl?ent $PDF->ezText("<u>" . Toolbox::decodeFromUtf8(__('Additional cards or peripherals', 'immobilizationsheets')) . "</u> : ", 8, array("justification" => "left")); $PDF->ezSetDy(-10); if ($number6 > 0) { //title config logicielle $title = array(array('' => Toolbox::decodeFromUtf8(__('SOFTWARE CONFIGURATION', 'immobilizationsheets')))); $cols = array('' => array('width' => 530, 'justification' => 'center')); $PDF->ezTable($title, '', '', array('cols' => $cols, 'showHeadings' => 0, 'fontSize' => 12, 'showLines' => 1)); $PDF->ezSetDy(-10); //titre logiciels $PDF->ezText("<u>" . Toolbox::decodeFromUtf8(__('Oem/Delivered software', 'immobilizationsheets')) . "</u> : ", 8, array("justification" => "left")); $PDF->ezSetDy(-10); //ligne1 (name / version / licence) $data0 = array(array('0' => Toolbox::decodeFromUtf8(__('Name')), '1' => Toolbox::decodeFromUtf8(__('Version')), '2' => Toolbox::decodeFromUtf8(__('License number')))); $cols1 = array('0' => array('width' => 240, 'justification' => 'left'), '1' => array('width' => 50, 'justification' => 'center'), '2' => array('width' => 240, 'justification' => 'center')); $PDF->ezTable($data0, '', '', array('fontSize' => 8, 'showHeadings' => 0, 'cols' => $cols1)); while ($data6 = $DB->fetch_array($result6)) { $soft_name_item = $data6["name"]; $soft_version_item = Dropdown::getDropdownName("glpi_softwareversions", $data6["softwareversions_id_buy"]); $soft_license_item = $data6["serial"]; $data1 = array(array('0' => $soft_name_item, '1' => $soft_version_item, '2' => $soft_license_item)); $cols1 = array('0' => array('width' => 240, 'justification' => 'left'), '1' => array('width' => 50, 'justification' => 'center'), '2' => array('width' => 240, 'justification' => 'center')); $PDF->ezTable($data1, '', '', array('fontSize' => 8, 'showHeadings' => 0, 'cols' => $cols1)); } $PDF->ezSetDy(-10); } } //trigramme $data6 = array(array('0' => Toolbox::decodeFromUtf8(__('Trigram and visa of the person in charge', 'immobilizationsheets')), '1' => '')); $cols6 = array('0' => array('width' => 430, 'fontSize' => 8, 'justification' => 'right'), '1' => array('width' => 100, 'justification' => 'left')); $PDF->ezTable($data6, '', '', array('showHeadings' => 0, 'cols' => $cols6, 'xPos' => 'center', 'xOreintation' => 'right', 'fontSize' => 8)); //partie 3 $PDF->ezSetDy(-20); $title1 = array(array('' => Toolbox::decodeFromUtf8(__('III - PART TO BE FILLED BY THE MANAGEMENT ASSISTANT', 'immobilizationsheets')))); $cols = array('' => array('width' => 530, 'justification' => 'left')); $PDF->ezTable($title1, '', '', array('cols' => $cols, 'showHeadings' => 0, 'fontSize' => 10, 'showLines' => 0, 'shaded' => 2, 'shadeCol' => array(0.8, 0.8, 0.8), 'shadeCol2' => array(0.8, 0.8, 0.8))); $title2 = array(array('' => Toolbox::decodeFromUtf8(__('(for checking, visa and classification)', 'immobilizationsheets')))); $cols = array('' => array('width' => 530, 'justification' => 'left')); $PDF->ezTable($title2, '', '', array('cols' => $cols, 'showHeadings' => 0, 'fontSize' => 8, 'showLines' => 0, 'shaded' => 2, 'shadeCol' => array(0.8, 0.8, 0.8), 'shadeCol2' => array(0.8, 0.8, 0.8))); $PDF->ezSetDy(-20); //title $title = array(array('' => Toolbox::decodeFromUtf8(__('CALCULATION OF AMORTIZATION', 'immobilizationsheets')))); $cols = array('' => array('width' => 530, 'justification' => 'center')); $PDF->ezTable($title, '', '', array('cols' => $cols, 'showHeadings' => 0, 'fontSize' => 12, 'showLines' => 1)); $PDF->ezSetDy(-10); //Base d'amortissement $amort0 = array(array('0' => Toolbox::decodeFromUtf8(__('Base amortization', 'immobilizationsheets')), '1' => $sink_type_item)); $cols1 = array('0' => array('width' => 130, 'fontSize' => 8, 'justification' => 'left'), '1' => array('width' => 400, 'justification' => 'left')); $PDF->ezTable($amort0, '', '', array('showHeadings' => 0, 'cols' => $cols1, 'fontSize' => 8, 'showLines' => 0)); $PDF->ezSetDy(-10); //Duree d'amortissement $amort1 = array(array('0' => Toolbox::decodeFromUtf8(__('Amortization duration')), '1' => $sink_time_item)); $cols1 = array('0' => array('width' => 130, 'fontSize' => 8, 'justification' => 'left'), '1' => array('width' => 400, 'justification' => 'left')); $PDF->ezTable($amort1, '', '', array('showHeadings' => 0, 'cols' => $cols1, 'fontSize' => 8, 'showLines' => 0)); $PDF->ezSetDy(-10); //Date de debut d'amortissement $amort2 = array(array('0' => Toolbox::decodeFromUtf8(__('Date of beginning of amortization', 'immobilizationsheets')), '1' => $use_date_item)); $cols1 = array('0' => array('width' => 130, 'fontSize' => 8, 'justification' => 'left'), '1' => array('width' => 400, 'justification' => 'left')); $PDF->ezTable($amort2, '', '', array('showHeadings' => 0, 'cols' => $cols1, 'fontSize' => 8, 'showLines' => 0)); $PDF->ezSetDy(-10); //visa $amort1 = array(array('0' => Toolbox::decodeFromUtf8(__('VISA A.G.', 'immobilizationsheets')), '1' => "")); $cols6 = array('0' => array('width' => 430, 'fontSize' => 8, 'justification' => 'right'), '1' => array('width' => 100, 'justification' => 'left')); $PDF->ezTable($data6, '', '', array('showHeadings' => 0, 'cols' => $cols6, 'xPos' => 'center', 'xOreintation' => 'right', 'fontSize' => 8)); //end $PDF->addInfo('Author', Toolbox::decodeFromUtf8(Html::clean(getUserName(Session::getLoginUserID())))); $config = new PluginImmobilizationsheetsConfig(); if ($config->getFromDB(1)) { if ($saveas == 1) { if ($config->fields["use_backup"] == 1) { $path = GLPI_DOC_DIR . "/_uploads/"; $time_file = date("Y-m-d-H-i-s"); $filename = "immo_" . $time_file . "_" . $data["name"] . ".pdf"; $filepath = $path . $filename; $fp = fopen($filepath, 'wb'); fwrite($fp, $PDF->output()); fclose($fp); $doc = new document(); $input = array(); $input["entities_id"] = $data["entities_id"]; $input["name"] = addslashes(self::getTypeName(1) . " " . $data["name"] . " " . $time_file); $input["upload_file"] = $filename; $input["documentcategories_id"] = $config->fields["documentcategories_id"]; $input["type"] = "application/pdf"; $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' => $itemtype, 'items_id' => $ID, 'entities_id' => $input["entities_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"])); } }
/** * 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; }
/** * @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>"; }
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'])); } } } }
public function post_addItem() { global $CFG_GLPI; // Manage add from template if (isset($this->input["_oldID"])) { // ADD Documents $docitem = new Document_Item(); $restrict = "`items_id` = '" . $this->input["_oldID"] . "' AND `itemtype` = '" . $this->getType() . "'"; $docs = getAllDatasFromTable("glpi_documents_items", $restrict); if (!empty($docs)) { foreach ($docs as $doc) { $docitem->add(array('documents_id' => $doc["documents_id"], 'itemtype' => $this->getType(), 'items_id' => $this->fields['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); } } } break; case "add_contract":
/** * 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; }
/** * 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); }
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; }
function addFilesTickets($id, $question_name, $entities_id) { global $LANG, $CFG_GLPI; $docadded = array(); $doc = new Document(); $docitem = new Document_Item(); // if multiple files are uploaded $TMPFILE = array(); if (is_array($_FILES[$question_name]['name'])) { $_FILES['filename'] = $_FILES[$question_name]; foreach ($_FILES[$question_name]['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[$question_name]) && count($_FILES[$question_name]) > 0 && $_FILES[$question_name]["size"] > 0) { $_FILES['filename'] = $_FILES[$question_name]; // Check for duplicate if ($doc->getFromDBbyContent($entities_id, $_FILES['filename']['tmp_name'])) { $docID = $doc->fields["id"]; } else { $input2 = array(); $input2["name"] = addslashes(__('Document Ticket') . " {$id}"); $input2["tickets_id"] = $id; $input2["entities_id"] = $entities_id; $input2["documentcategories_id"] = $CFG_GLPI["documentcategories_id_forticket"]; $input2["_only_if_upload_succeed"] = 1; $input2["entities_id"] = $entities_id; $docID = $doc->add($input2); if ($docID > 0) { if ($docitem->add(array('documents_id' => $docID, 'itemtype' => 'Ticket', 'items_id' => $id))) { $docadded[] = stripslashes($doc->fields["name"] . " - " . $doc->fields["filename"]); } } } } } unset($_FILES['filename']); return true; }