本文整理汇总了PHP中Document_Item::add方法的典型用法代码示例。如果您正苦于以下问题:PHP Document_Item::add方法的具体用法?PHP Document_Item::add怎么用?PHP Document_Item::add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Document_Item
的用法示例。
在下文中一共展示了Document_Item::add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: save
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));
}
}
}
示例2: copyDocuments
/**
* 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));
}
}
}
示例3: copyDocuments
/**
* 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);
}
}
}
示例4: addFiles
/**
* 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;
}
示例5: saveAnswers
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));
}
//.........这里部分代码省略.........
示例6: addDocuments
/** 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));
}
}
}
示例7: sprintf
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");
示例8: showFormResCreateLocation
/**
* 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"]);
}
}
示例9: Infocom
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']));
}
}
}
}
示例10: doSpecificMassiveActions
/**
* @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;
}
示例11:
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]);
}
}
示例12: Document
*/
// ----------------------------------------------------------------------
// 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"])) {
示例13: Infocom
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']));
}
}
}
}
示例14: createSubTicket
/**
*
* @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);
}
示例15: addFiles
/**
* 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;
}