Example #1
0
 /**
  * @see Document::update
  * @return void
  */
 public function update()
 {
     // update elements
     $this->getElements();
     $this->getResource()->deleteAllElements();
     if (is_array($this->getElements()) and count($this->getElements()) > 0) {
         foreach ($this->getElements() as $name => $element) {
             $element->setResource(null);
             $element->setDocumentId($this->getId());
             $element->save();
         }
     }
     // update scheduled tasks
     $this->saveScheduledTasks();
     // load data which must be requested
     $this->getProperties();
     $this->getElements();
     // update this
     parent::update();
     // save version if needed
     $this->saveVersion(false);
 }
Example #2
0
        $doc->redirectToList();
    } else {
        if (isset($_POST["restore"])) {
            $doc->check($_POST["id"], 'd');
            if ($doc->restore($_POST)) {
                Event::log($_POST["id"], "documents", 4, "document", sprintf(__('%s restores an item'), $_SESSION["glpiname"]));
            }
            $doc->redirectToList();
        } else {
            if (isset($_POST["purge"])) {
                $doc->check($_POST["id"], 'd');
                if ($doc->delete($_POST, 1)) {
                    Event::log($_POST["id"], "documents", 4, "document", sprintf(__('%s purges an item'), $_SESSION["glpiname"]));
                }
                $doc->redirectToList();
            } else {
                if (isset($_POST["update"])) {
                    $doc->check($_POST["id"], 'w');
                    if ($doc->update($_POST)) {
                        Event::log($_POST["id"], "documents", 4, "document", sprintf(__('%s updates an item'), $_SESSION["glpiname"]));
                    }
                    Html::back();
                } else {
                    Html::header(Document::getTypeName(2), $_SERVER['PHP_SELF'], "financial", "document");
                    $doc->showForm($_GET["id"]);
                    Html::footer();
                }
            }
        }
    }
}
Example #3
0
 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'));
         }
     }
 }
Example #4
0
         $filetype = $uploaded_data['type'];
     } elseif ($file_url) {
         $data = '';
         $filename = $file_url;
         $filetype = 'URL';
         /*
         } elseif ($sys_use_ftpuploads && $ftp_filename!=100) { //100==None
         	$filename=$upload_dir.'/'.$ftp_filename;
         	$data = addslashes(fread(fopen($filename, 'r'), filesize($filename)));
         	$filetype=$uploaded_data_type;
         */
     } else {
         $filename = addslashes($d->getFileName());
         $filetype = addslashes($d->getFileType());
     }
     if (!$d->update($filename, $filetype, $data, $doc_group, $title, $language_id, $description, $stateid)) {
         exit_error('Error', $d->getErrorMessage());
     }
     $feedback = _('Updated successfully');
 } elseif (getStringFromRequest('editgroup')) {
     $doc_group = getIntFromRequest('doc_group');
     $groupname = getStringFromRequest('groupname');
     $parent_doc_group = getIntFromRequest('parent_doc_group');
     $dg = new DocumentGroup($g, $doc_group);
     if ($dg->isError()) {
         exit_error('Error', $dg->getErrorMessage());
     }
     if (!$dg->update($groupname, $parent_doc_group)) {
         exit_error('Error', $dg->getErrorMessage());
     }
     $feedback = _('Updated successfully');
Example #5
0
                    foreach ($users as $user) {
                        if (!in_array($user, $document->getAssignees())) {
                            $to = $user->getEmail();
                            //mail($to, $subject, $message, $headers);
                            $mail->setFrom('*****@*****.**', 'IR Information Network');
                            $mail->addAddress($to);
                            $mail->Subject = $subject;
                            $mail->Body = $message;
                            if (!$mail->send()) {
                                throw new MailException($mail->ErrorInfo);
                            }
                            Event::addEvent($user->getName() . ' has been assigned to document ' . $document->getPrefix()->getPrefixAbbrev() . $document->getID() . '.', $_SESSION['user'], 2);
                        }
                    }
                    Event::addEvent('Document ' . $document->getPrefix()->getPrefixAbbrev() . $document->getID() . ' has been modified.', $_SESSION['user'], 2);
                    $document->update($subject, $status, $body, $clearance, $prefix, $assignees);
                    echo $document->getID();
                }
            }
        } else {
            if ($action == 'search') {
                if ($do == 'none') {
                    ?>
        <form action="#" method="POST">
            <label for="searchid"><b>ID Number (Including Prefix):</b></label>&nbsp;&nbsp;<input type="text" id="searchid" name="searchid" required/><br/>
            <button id="search" name="search" class="btn btn-primary" type="button" onclick="searchDoc()">Search</button>
        </form>
        <div id="loading" class="alert alert-primary" role="alert" style="display: none">

        </div>
        <?php 
Example #6
0
 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));
         }
     }
 }
     }
     if (isset($_FILES['vDocumentpath']['name']) && $_FILES['vDocumentpath']['name'] != "") {
         $audio_name = date('Ymdhis') . $_FILES['vDocumentpath']['name'];
         if (copy($_FILES['vDocumentpath']['tmp_name'], $CFG->datadirroot . "/pdf/" . $audio_name)) {
             if ($audio_name != '') {
                 $documentObj->setvDocumentpath($audio_name);
                 @unlink($CFG->datadirroot . "/pdf/" . $_POST['vOldImage']);
             }
         }
     } else {
         if ($_POST['vOldImage'] != "") {
             $documentObj->setvDocumentpath($_POST['vOldImage']);
         }
     }
     //$documentObj->setiSGroupId($iSGroupId);
     $documentObj->update($iDocumentId);
     $msg = MSG_UPDATE;
     $url = 'index.php?file=Documents&AX=Yes' . $qs . '&iLibCategoryId=' . $iLibCategoryId . '&var_msg=' . $msg;
     header("Location:" . $url);
     exit;
 } else {
     if ($mode == "Delete") {
         if (file_exists($CFG->datadirroot . "/pdf/" . $_POST['vOldImage'])) {
             @unlink($CFG->datadirroot . "/pdf/" . $_POST['vOldImage']);
         }
         $sql_update = "UPDATE Document SET vDocumentpath = '' WHERE iDocumentId = '" . $iDocumentId . "'";
         $obj->sql_query($sql_update);
         $msg = "Image successfuly deleted.";
         header("Location:index.php?file=m-documentadd" . $qs . "&iLibCategoryId=" . $iLibCategoryId . "&mode=Update&iId=1&iDocumentId=" . $iDocumentId);
         exit;
     }
Example #8
0
 /**
  * Update Document
  */
 public function update(array $query = array(), array $update = array(), array $options = array())
 {
     $document = new Document($query, $this);
     $update = $document->update($update, $options);
     return $update;
 }
Example #9
0
 /**
  * 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));
         }
     }
 }
Example #10
0
// Création d'un document
echo "Création d'un document ... ";
$document = new Document();
$document->debut = "2015-12-28";
$document->fin = "2015-12-29";
$document->id_appartement = 1;
// Ajout dans la base
echo "OK<br/>Ajout du document dans la base ... ";
$document->insert();
echo "OK<br/>";
// Liste de tous les documents
listerTout();
// Apport d'une modification
$document->fin = "2015-12-30";
echo "Modification de la fin ! Mise à jour dans la base ... ";
$document->update();
echo "OK<br/>";
// Sélection de l'appartement
$selectionDocument = Document::findById($document->id_document);
$selectionDocument->afficher();
// Suppression du document
echo "Suppression du document de la base ... ";
$selectionDocument->delete();
echo "OK<br/>";
// Liste de tous les documents
listerTout();
function listerTout()
{
    // Liste de tous les documents
    echo "Liste des documents disponibles dans la base : <br/>";
    $listeDocuments = Document::findAll();