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')); } } }
function AssertDocument(Document $document, $id, $title) { $this->assertEquals($id, $document->getID()); $this->assertEquals($title, $document->getTitle()); }
</p> </form> <?php docman_footer(array()); } else { if (getStringFromRequest('deletedoc') && $docid) { $d = new Document($g, $docid); if ($d->isError()) { exit_error('Error', $d->getErrorMessage()); } docman_header(_('Document Manager Administration'), _('Edit Groups'), ''); ?> <p> <form action="<?php echo $PHP_SELF . '?deletedoc=1&docid=' . $d->getID() . '&group_id=' . $d->Group->getID(); ?> " method="post"> <input type="hidden" name="submit" value="1" /><br /> <?php echo _('You are about to permanently delete this document.'); ?> <p> <input type="checkbox" name="sure" value="1"><?php echo _('I\'m Sure.'); ?> <br /> <input type="checkbox" name="really_sure" value="1"><?php echo _('I\'m Really Sure.'); ?> <br />
/** * Copy order documents into the newly generated item * @since 1.5.3 * @param unknown_type $itemtype * @param unknown_type $items_id * @param unknown_type $orders_id * @param unknown_type $entity */ public static function copyDocuments($itemtype, $items_id, $orders_id, $entity) { global $CFG_GLPI; $config = PluginOrderConfig::getConfig(); if ($config->canCopyDocuments() && in_array($itemtype, $CFG_GLPI["document_types"])) { $document = new Document(); $docitem = new Document_Item(); $item = new $itemtype(); $item->getFromDB($items_id); $is_recursive = 0; foreach (getAllDatasFromTable('glpi_documents_items', "`itemtype`='PluginOrderOrder'\n AND `items_id`='{$orders_id}'") as $doc) { //Create a new document $document->getFromDB($doc['documents_id']); if ($document->getEntityID() != $entity && !$document->fields['is_recursive'] || !in_array($entity, getSonsOf('glpi_entities', $document->getEntityID()))) { $found_docs = getAllDatasFromTable('glpi_documents', "`entities_id`='{$entity}'\n AND `sha1sum`='" . $document->fields['sha1sum'] . "'"); if (empty($found_docs)) { $tmpdoc = $document->fields; $tmpdoc['entities_id'] = $entity; unset($tmpdoc['id']); $documents_id = $document->add($tmpdoc); $is_recursive = $document->fields['is_recursive']; } else { $found_doc = array_pop($found_docs); $documents_id = $found_doc['id']; $is_recursive = $found_doc['is_recursive']; } } else { $documents_id = $document->getID(); $is_recursive = $document->fields['is_recursive']; } //Link the document to the newly generated item $fields['documents_id'] = $documents_id; $fields['entities_id'] = $entity; $fields['items_id'] = $items_id; $fields['itemtype'] = $itemtype; $fields['is_recursive'] = $is_recursive; $newID = $docitem->add($fields); } } }
/** * Add a document to a existing ticket * for an authenticated user * * @param $params array of options (ticket, uri, name, base64, comment) * only one of uri and base64 must be set * name is mandatory when base64 set, for extension check (filename) * @param $protocol the communication protocol used * * @return array of hashtable **/ static function methodAddTicketDocument($params, $protocol) { global $DB, $CFG_GLPI; if (isset($params['help'])) { return array('ticket' => 'integer,mandatory', 'uri' => 'string,optional', 'base64' => 'string,optional', 'content' => 'string,optional', 'close' => 'bool,optional', 'reopen' => 'bool,optional', 'source' => 'string,optional', 'private' => 'bool,optional', 'help' => 'bool,optional'); } if (!Session::getLoginUserID()) { return self::Error($protocol, WEBSERVICES_ERROR_NOTAUTHENTICATED); } $ticket = new Ticket(); if (!isset($params['ticket'])) { return self::Error($protocol, WEBSERVICES_ERROR_MISSINGPARAMETER, '', 'ticket'); } if (!is_numeric($params['ticket'])) { return self::Error($protocol, WEBSERVICES_ERROR_BADPARAMETER, '', 'ticket'); } if (!$ticket->can($params['ticket'], 'r')) { return self::Error($protocol, WEBSERVICES_ERROR_NOTFOUND); } if (in_array($ticket->fields["status"], $ticket->getClosedStatusArray())) { return self::Error($protocol, WEBSERVICES_ERROR_NOTALLOWED, '', 'closed ticket'); } if (!$ticket->canAddFollowups()) { return self::Error($protocol, WEBSERVICES_ERROR_NOTALLOWED, '', 'access denied'); } if (isset($params['name']) && !empty($params['name'])) { $document_name = addslashes($params['name']); } else { $document_name = addslashes(sprintf(__('%1$s %2$s'), _x('phone', 'Number'), $ticket->fields['id'])); } $filename = tempnam(GLPI_DOC_DIR . '/_tmp', 'PWS'); $response = parent::uploadDocument($params, $protocol, $filename, $document_name); //An error occured during document upload if (parent::isError($protocol, $response)) { return $response; } $doc = new Document(); $documentitem = new Document_Item(); $docid = $doc->getFromDBbyContent($ticket->fields["entities_id"], $filename); if ($docid) { $input = array('itemtype' => $ticket->getType(), 'items_id' => $ticket->getID(), 'documents_id' => $doc->getID()); if ($DB->request('glpi_documents_items', $input)->numrows()) { return self::Error($protocol, WEBSERVICES_ERROR_FAILED, '', 'document already associated to this ticket'); } $new = $documentitem->add($input); } else { $input = array('itemtype' => $ticket->getType(), 'items_id' => $ticket->getID(), 'tickets_id' => $ticket->getID(), 'entities_id' => $ticket->getEntityID(), 'is_recursive' => $ticket->isRecursive(), 'documentcategories_id' => $CFG_GLPI["documentcategories_id_forticket"]); $new = $doc->add($input); } // to not add it twice during followup unset($_FILES['filename']); if (!$new) { return self::Error($protocol, WEBSERVICES_ERROR_FAILED, '', self::getDisplayError()); } if (isset($params['comment']) && !empty($params['comment'])) { $params['content'] = $params['comment']; unset($params['comment']); } if (isset($params['content']) && !empty($params['content'])) { return self::methodAddTicketFollowup($params, $protocol); } return self::methodGetTicket(array('ticket' => $params['ticket']), $protocol); }
} } } else { if ($action == 'delete') { if ($do == 'none') { ?> <a onclick="load('documents', 'delete', 'delete', {id: '<?php echo $_GET['id']; ?> '})">Continue?</a> (<b>NOTE:</b> This action cannot be reversed!) <?php } else { if ($do == 'delete') { $document = new Document($_GET['id']); $document->delete(); Event::addEvent('Document ' . $document->getPrefix()->getPrefixAbbrev() . $document->getID() . ' has been deleted.', $_SESSION['user'], 3); ?> <script> load('documents', 'view', 'none', {}); </script> <?php } } } else { if ($action == 'sign') { $document = new Document($_GET['id']); $document->sign($_SESSION['user']); ?> <script> load('documents', 'view', 'none', {id: '<?php echo $_GET['id'];
static function addDocumentCategory(Document $document) { if (isset($document->input['itemtype']) && $document->input['itemtype'] == __CLASS__ && !$document->input['documentcategories_id']) { $config = PluginOrderConfig::getConfig(); $category = $config->getDefaultDocumentCategory(); if ($category) { $document->update(array('id' => $document->getID(), 'documentcategories_id' => $category)); } } }