$file->author_id = $user_id; $file->fillFields(); $file->updateFormFields(); $file->forceDir(); } if ($file->_id && !file_exists($file->_file_path)) { $file->forceDir(); } $file->file_name = $compte_rendu->nom . ".pdf"; $c1 = preg_replace("!\\s!", '', $save_content); $c2 = preg_replace("!\\s!", '', $compte_rendu->_source); // Si la source envoyée et celle présente en base sont différentes, on regénère le PDF // Suppression des espaces, tabulations, retours chariots et sauts de lignes pour effectuer le md5 if ($compte_rendu->valide || md5($c1) != md5($c2) || !$file->_id || !file_exists($file->_file_path) || file_get_contents($file->_file_path) == "") { $htmltopdf = new CHtmlToPDF($compte_rendu->factory); $content = CCompteRendu::restoreId($content); $htmltopdf->generatePDF($content, 0, $compte_rendu, $file); $file->doc_size = filesize($file->_file_path); } // Il peut y avoir plusieurs cfiles pour un même compte-rendu, à cause // de n requêtes simultanées pour la génération du pdf. // On supprime donc les autres cfiles. $compte_rendu->loadRefsFiles(); $files = $compte_rendu->_ref_files; if ($file->_id) { unset($files[$file->_id]); } foreach ($files as $_file) { $_file->delete(); } $file->store();
/** * Enregistrement du document / modèle * * @return string */ function store() { $this->completeField("content_id", "_source", "language", "version"); if (!$this->creation_date) { $this->creation_date = CMbDT::dateTime(); if ($this->_id) { $this->creation_date = $this->loadFirstLog()->date; } } // Prevent source modification when not editing the doc $this->loadContent($this->_send || $this->_source === null); $source_modified = $this->_ref_content->content != $this->_source || $this->fieldModified("margin_top") || $this->fieldModified("margin_left") || $this->fieldModified("margin_right") || $this->fieldModified("margin_bottom") || $this->fieldModified("page_height") || $this->fieldModified("page_width") || $this->fieldModified("header_id") || $this->fieldModified("preface_id") || $this->fieldModified("ending_id") || $this->fieldModified("footer_id"); if ($source_modified || $this->fieldModified("valide")) { // Empty PDF File /** @var CFile $_file */ foreach ($this->loadBackRefs("files") as $_file) { $_file->fileEmpty(); } } if ($source_modified) { // Bug IE : delete id attribute $this->_source = CCompteRendu::restoreId($this->_source); $this->doc_size = strlen($this->_source); // Send status to obsolete $this->completeField("etat_envoi"); if ($source_modified && $this->etat_envoi == "oui") { $this->etat_envoi = "obsolete"; } } $this->_ref_content->content = $this->_source; if (!$this->_id) { $parent_modele = $this->loadModele(); $parent_modele->loadContent(false); // Si issu d'une duplication depuis un document existant, alors on reprend la version du document d'origine // L'incrément de version se fait en fin de store if ($parent_modele->object_id) { $this->version = $parent_modele->version; $parent_modele->isAutoLock(); // Si le document existant est verrouillé, alors on l'archive if ($parent_modele->valide || $parent_modele->_is_auto_locked) { $parent_modele->annule = 1; $parent_modele->store(); } } } if ($msg = $this->_ref_content->store()) { CAppUI::setMsg($msg, UI_MSG_ERROR); } // Prevent modele_id = compte_rendu_id // But, allow to save the content if ($this->_id === $this->modele_id) { $this->modele_id = ""; } // Detect the fields not completed $matches = array(); preg_match_all("/(field|name)\">(\\[)+[^\\]]+(\\])+<\\/span>/ms", $this->_source, $matches); $this->fields_missing = count($matches[0]); if (!$this->content_id) { $this->content_id = $this->_ref_content->_id; } if (!$this->_id) { $this->author_id = CMediusers::get()->_id; } if ($this->factory == "none" || !$this->factory) { $this->factory = CAppUI::pref("dPcompteRendu choice_factory"); if (!$this->factory) { $this->factory = "CWkHtmlToPDFConverter"; } } $this->version++; return parent::store(); }