本文整理汇总了PHP中Document_Item类的典型用法代码示例。如果您正苦于以下问题:PHP Document_Item类的具体用法?PHP Document_Item怎么用?PHP Document_Item使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Document_Item类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: displayTabContentForItem
static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0)
{
switch ($item->getType()) {
case 'PluginFormcreatorForm':
Document_Item::displayTabContentForItem($item);
break;
}
return true;
}
示例2: cleanRelationTable
/**
* Clean the date in the relation tables for the deleted item
* Clear N/N Relation
**/
function cleanRelationTable()
{
global $CFG_GLPI, $DB;
// If this type have INFOCOM, clean one associated to purged item
if (in_array($this->getType(), $CFG_GLPI['infocom_types'])) {
$infocom = new Infocom();
if ($infocom->getFromDBforDevice($this->getType(), $this->fields['id'])) {
$infocom->delete(array('id' => $infocom->fields['id']));
}
}
// If this type have NETPORT, clean one associated to purged item
if (in_array($this->getType(), $CFG_GLPI['networkport_types'])) {
$query = "SELECT `id`\n FROM `glpi_networkports`\n WHERE (`items_id` = '" . $this->fields['id'] . "'\n AND `itemtype` = '" . $this->getType() . "')";
$result = $DB->query($query);
while ($data = $DB->fetch_array($result)) {
$q = "DELETE\n FROM `glpi_networkports_networkports`\n WHERE (`networkports_id_1` = '" . $data["id"] . "'\n OR `networkports_id_2` = '" . $data["id"] . "')";
$result2 = $DB->query($q);
}
$query = "DELETE\n FROM `glpi_networkports`\n WHERE (`items_id` = '" . $this->fields['id'] . "'\n AND `itemtype` = '" . $this->getType() . "')";
$result = $DB->query($query);
}
// If this type is RESERVABLE clean one associated to purged item
if (in_array($this->getType(), $CFG_GLPI['reservation_types'])) {
$rr = new ReservationItem();
if ($rr->getFromDBbyItem($this->getType(), $this->fields['id'])) {
$rr->delete(array('id' => $infocom->fields['id']));
}
}
// If this type have CONTRACT, clean one associated to purged item
if (in_array($this->getType(), $CFG_GLPI['contract_types'])) {
$ci = new Contract_Item();
$ci->cleanDBonItemDelete($this->getType(), $this->fields['id']);
}
// If this type have DOCUMENT, clean one associated to purged item
if (in_array($this->getType(), $CFG_GLPI["document_types"])) {
$di = new Document_Item();
$di->cleanDBonItemDelete($this->getType(), $this->fields['id']);
}
}
示例3: 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));
}
//.........这里部分代码省略.........
示例4: addFiles
/**
* 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;
}
示例5: showSubForm
/**
* @since version 0.90
*
* @param $item
* @param $id
* @param $params
**/
static function showSubForm(CommonDBTM $item, $id, $params)
{
if ($item instanceof Document_Item) {
Document_Item::showAddFormForItem($params['parent'], '');
} else {
if (method_exists($item, "showForm")) {
$item->showForm($id, $params);
}
}
}
示例6: getCentral
//.........这里部分代码省略.........
echo "</script>\n";
echo "<div id='desc{$rand}' class='tracking' onClick='showDesc{$rand}()'>\n";
if (!empty($ticket->fields["content"])) {
echo nl2br($ticket->fields["content"]);
} else {
_e('Empty description');
}
echo "</div>\n";
echo "<div id='viewdesc{$rand}'></div>\n";
if (!$ID) {
echo "<script type='text/javascript' >\n\n showDesc{$rand}();\n </script>";
}
echo $tt->getEndHiddenFieldValue('content', $ticket);
} else {
echo nl2br($ticket->fields["content"]);
}
// * Added by plugin surveyticket
}
// End of adding by plugin
echo "</td>";
echo "</tr>";
echo "<tr class='tab_bg_1'>";
// Permit to add doc when creating a ticket
if (!$ID) {
echo "<th width='{$colsize1}%'>" . sprintf(__('File (%s)'), Document::getMaxUploadSize());
echo "<img src='" . $CFG_GLPI["root_doc"] . "/pics/aide.png' class='pointer' alt=\"" . __s('Help') . "\" onclick=\"window.open('" . $CFG_GLPI["root_doc"] . "/front/documenttype.list.php','Help','scrollbars=1,resizable=1,width=1000," . "height=800')\">";
echo " ";
Ticket::showDocumentAddButton();
echo "</th>";
echo "<td width='{$colsize2}%'>";
echo "<div id='uploadfiles'><input type='file' name='filename[]' size='20'></div></td>";
} else {
echo "<th colspan='2'>";
$docnb = Document_Item::countForItem($ticket);
echo "<a href=\"" . $ticket->getLinkURL() . "&forcetab=Document_Item\$1\">";
//TRANS: %d is the document number
echo sprintf(_n('%d associated document', '%d associated documents', $docnb), $docnb);
echo "</a></th>";
}
if ($view_linked_tickets) {
echo "<th width='{$colsize3}%'>" . _n('Linked ticket', 'Linked tickets', 2);
$rand_linked_ticket = mt_rand();
if ($canupdate) {
echo " ";
echo "<img onClick=\"Ext.get('linkedticket{$rand_linked_ticket}').setDisplayed('block')\"\n title=\"" . __s('Add') . "\" alt=\"" . __s('Add') . "\"\n class='pointer' src='" . $CFG_GLPI["root_doc"] . "/pics/add_dropdown.png'>";
}
echo '</th>';
echo "<td width='{$colsize4}%'>";
if ($canupdate) {
echo "<div style='display:none' id='linkedticket{$rand_linked_ticket}'>";
Ticket_Ticket::dropdownLinks('_link[link]', isset($values["_link"]) ? $values["_link"]['link'] : '');
printf(__('%1$s: %2$s'), __('Ticket'), __('ID'));
echo "<input type='hidden' name='_link[tickets_id_1]' value='{$ID}'>\n";
echo "<input type='text' name='_link[tickets_id_2]'\n value='" . (isset($values["_link"]) ? $values["_link"]['tickets_id_2'] : '') . "'\n size='10'>\n";
echo " ";
echo "</div>";
if (isset($values["_link"]) && !empty($values["_link"]['tickets_id_2'])) {
echo "<script language='javascript'>Ext.get('linkedticket{$rand_linked_ticket}').\n setDisplayed('block');</script>";
}
}
Ticket_Ticket::displayLinkedTicketsTo($ID);
echo "</td>";
} else {
echo "<td></td>";
}
echo "</tr>";
示例7: addDocumentCategory
public static function addDocumentCategory(Document $document)
{
$config = PluginOrderConfig::getConfig();
if (isset($document->input['itemtype']) && $document->input['itemtype'] == __CLASS__ && !$document->input['documentcategories_id']) {
$category = $config->getDefaultDocumentCategory();
if ($category) {
$document->update(array('id' => $document->getID(), 'documentcategories_id' => $category));
}
}
// Fomrat document name
if (isset($document->input['itemtype']) && $document->input['itemtype'] == __CLASS__ && $document->input['documentcategories_id'] && $config->canRenameDocuments()) {
// Get document category
$documentCategory = new PluginOrderDocumentCategory();
if (!$documentCategory->getFromDBByQuery(" WHERE `documentcategories_id` = '" . $document->input['documentcategories_id'] . "'")) {
$documentCategory->getEmpty();
}
// Get order linked to document
$document_item = new Document_Item();
if ($document_item->getFromDBByQuery(" WHERE `documents_id` = '" . $document->fields['id'] . "' AND `itemtype` = '" . self::getType() . "'")) {
// Update document name
$order = new self();
$order->getFromDB($document_item->fields['items_id']);
$extension = explode('.', $document->fields['filename']);
$tag = "";
if (!empty($documentCategory->fields['documentcategories_prefix'])) {
$tag = $documentCategory->fields['documentcategories_prefix'] . "-";
}
$document->fields['filename'] = $tag . $order->fields['num_order'] . "." . $extension[1];
$document->updateInDB(array('filename'));
}
}
}
示例8: showForm
//.........这里部分代码省略.........
}
echo "</table>";
echo "<table class='tab_cadre_fixe' id='mainformtable2'>";
echo "<tr class='tab_bg_1'>";
echo "<th width='{$colsize1}%'>" . __('Status') . "</th>";
echo "<td width='{$colsize2}%'>";
self::dropdownStatus(array('value' => $this->fields["status"], 'showtype' => 'allowed'));
echo "</td>";
echo "<th width='{$colsize1}%'>" . __('Urgency') . "</th>";
echo "<td width='{$colsize2}%'>";
// Only change during creation OR when allowed to change priority OR when user is the creator
$idurgency = self::dropdownUrgency(array('value' => $this->fields["urgency"]));
echo "</td></tr>";
echo "<tr class='tab_bg_1'>";
echo "<th>" . __('Category') . "</th>";
echo "<td >";
$opt = array('value' => $this->fields["itilcategories_id"], 'entity' => $this->fields["entities_id"], 'condition' => "`is_problem`='1'");
ITILCategory::dropdown($opt);
echo "</td>";
echo "<th>" . __('Impact') . "</th>";
echo "<td>";
$idimpact = self::dropdownImpact(array('value' => $this->fields["impact"]));
echo "</td></tr>";
echo "<tr class='tab_bg_1'>";
echo "<th>" . __('Total duration') . "</th>";
echo "<td>" . parent::getActionTime($this->fields["actiontime"]) . "</td>";
echo "<th class='left'>" . __('Priority') . "</th>";
echo "<td>";
$idpriority = parent::dropdownPriority(array('value' => $this->fields["priority"], 'withmajor' => true));
$idajax = 'change_priority_' . mt_rand();
echo " <span id='{$idajax}' style='display:none'></span>";
$params = array('urgency' => '__VALUE0__', 'impact' => '__VALUE1__', 'priority' => $idpriority);
Ajax::updateItemOnSelectEvent(array($idurgency, $idimpact), $idajax, $CFG_GLPI["root_doc"] . "/ajax/priority.php", $params);
echo "</td>";
echo "</tr>";
echo "</table>";
$this->showActorsPartForm($ID, $options);
echo "<table class='tab_cadre_fixe' id='mainformtable3'>";
echo "<tr class='tab_bg_1'>";
echo "<th width='{$colsize1}%'>" . __('Title') . "</th>";
echo "<td colspan='3'>";
$rand = mt_rand();
echo "<script type='text/javascript' >\n";
echo "function showName{$rand}() {\n";
echo "Ext.get('name{$rand}').setDisplayed('none');";
$params = array('maxlength' => 250, 'size' => 110, 'name' => 'name', 'data' => rawurlencode($this->fields["name"]));
Ajax::updateItemJsCode("viewname{$rand}", $CFG_GLPI["root_doc"] . "/ajax/inputtext.php", $params);
echo "}";
echo "</script>\n";
echo "<div id='name{$rand}' class='tracking left' onClick='showName{$rand}()'>\n";
if (empty($this->fields["name"])) {
_e('Without title');
} else {
echo $this->fields["name"];
}
echo "</div>\n";
echo "<div id='viewname{$rand}'></div>\n";
if (!$ID) {
echo "<script type='text/javascript' >\n\n showName{$rand}();\n </script>";
}
echo "</td></tr>";
echo "<tr class='tab_bg_1'>";
echo "<th>" . __('Description') . "</th>";
echo "<td colspan='3'>";
$rand = mt_rand();
echo "<script type='text/javascript' >\n";
echo "function showDesc{$rand}() {\n";
echo "Ext.get('desc{$rand}').setDisplayed('none');";
$params = array('rows' => 6, 'cols' => 110, 'name' => 'content', 'data' => rawurlencode($this->fields["content"]));
Ajax::updateItemJsCode("viewdesc{$rand}", $CFG_GLPI["root_doc"] . "/ajax/textarea.php", $params);
echo "}";
echo "</script>\n";
echo "<div id='desc{$rand}' class='tracking' onClick='showDesc{$rand}()'>\n";
if (!empty($this->fields["content"])) {
echo nl2br($this->fields["content"]);
} else {
_e('Empty description');
}
echo "</div>\n";
echo "<div id='viewdesc{$rand}'></div>\n";
if (!$ID) {
echo "<script type='text/javascript' >\n\n showDesc{$rand}();\n </script>";
}
echo "</td></tr>";
if ($ID) {
echo "<tr class='tab_bg_1'>";
echo "<th colspan='2' width='" . ($colsize1 + $colsize2) . "%'>";
$docnb = Document_Item::countForItem($this);
echo "<a href=\"" . $this->getLinkURL() . "&forcetab=Document_Item\$1\">";
//TRANS: %d is the document number
echo sprintf(_n('%d associated document', '%d associated documents', $docnb), $docnb);
echo "</a></th>";
echo "<td colspan='2'></td>";
echo "</tr>";
}
$options['colspan'] = 2;
$this->showFormButtons($options);
$this->addDivForTabs();
return true;
}
示例9: 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));
}
}
}
示例10: 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);
}
}
}
示例11: methodAddTicketDocument
/**
* 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);
}
示例12: Profile_User
case "add_userprofile":
$right = new Profile_User();
if (isset($_POST['profiles_id']) && $_POST['profiles_id'] > 0 && isset($_POST['entities_id']) && $_POST['entities_id'] >= 0) {
$input['entities_id'] = $_POST['entities_id'];
$input['profiles_id'] = $_POST['profiles_id'];
$input['is_recursive'] = $_POST['is_recursive'];
foreach ($_POST["item"] as $key => $val) {
if ($val == 1) {
$input['users_id'] = $key;
$right->add($input);
}
}
}
break;
case "add_document":
$documentitem = new Document_Item();
foreach ($_POST["item"] as $key => $val) {
$input = array('itemtype' => $_POST["itemtype"], 'items_id' => $key, 'documents_id' => $_POST['docID']);
if ($documentitem->can(-1, 'w', $input)) {
$documentitem->add($input);
}
}
break;
case "add_contact":
if ($_POST["itemtype"] == 'Supplier') {
$contactsupplier = new Contact_Supplier();
foreach ($_POST["item"] as $key => $val) {
$input = array('suppliers_id' => $key, 'contacts_id' => $_POST['conID']);
if ($contactsupplier->can(-1, 'w', $input)) {
$contactsupplier->add($input);
}
示例13: post_addItem
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']));
}
}
}
}
示例14: post_addItem
function post_addItem()
{
global $CFG_GLPI;
$projet_projet = new PluginProjetProjet_Projet();
// From interface
if (isset($this->input['_link'])) {
$this->input['_link']['plugin_projet_projets_id_1'] = $this->fields['id'];
// message if projet doesn't exist
if (!empty($this->input['_link']['plugin_projet_projets_id_2'])) {
if ($projet_projet->can(-1, 'w', $this->input['_link'])) {
$projet_projet->add($this->input['_link']);
} else {
Session::addMessageAfterRedirect(__('Unknown project', 'projet'), false, ERROR);
}
}
}
// Manage add from template
if (isset($this->input["_oldID"])) {
//add parent
PluginProjetProjet_Projet::cloneItem($this->input["_oldID"], $this->fields['id']);
// ADD Documents
Document_Item::cloneItem($this->getType(), $this->input["_oldID"], $this->fields['id']);
// ADD Contracts
Contract_Item::cloneItem($this->getType(), $this->input["_oldID"], $this->fields['id']);
// ADD items
PluginProjetProjet_Item::cloneItem($this->input["_oldID"], $this->fields['id']);
// ADD tasks
PluginProjetTask::cloneItem($this->input["_oldID"], $this->fields['id']);
}
if (isset($this->input['withtemplate']) && $this->input["withtemplate"] != 1 && isset($this->input['send_notification']) && $this->input['send_notification'] == 1) {
if ($CFG_GLPI["use_mailing"]) {
NotificationEvent::raiseEvent("new", $this);
}
}
}
示例15: save
/**
* 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':
//.........这里部分代码省略.........