/** * Generate a pdf preview for the document * * @param boolean $force_generating [optional] * @param boolean $auto_print [optional] * * @return string|null */ function makePDFpreview($force_generating = false, $auto_print = true) { if ((!CAppUI::conf("dPcompteRendu CCompteRendu pdf_thumbnails") || !CAppUI::pref("pdf_and_thumbs")) && !$force_generating) { return null; } $this->loadRefsFwd(); $file = $this->loadFile(); // Fichier existe déjà et rempli et que la génération n'est pas forcée if (!$force_generating && $file->_id && file_exists($file->_file_path) && filesize($file->_file_path)) { return null; } // Création du CFile si inexistant if (!$file->_id || !file_exists($file->_file_path)) { $file->setObject($this); $file->file_name = $this->nom . ".pdf"; $file->file_type = "application/pdf"; $file->author_id = CMediusers::get()->_id; $file->fillFields(); $file->updateFormFields(); $file->forceDir(); } // Génération du contenu PDF $margins = array($this->margin_top, $this->margin_right, $this->margin_bottom, $this->margin_left); $this->loadContent(); $content = $this->loadHTMLcontent($this->_source, '', $margins, CCompteRendu::$fonts[$this->font], $this->size, $auto_print); $htmltopdf = new CHtmlToPDF($this->factory); $htmltopdf->generatePDF($content, 0, $this, $file); $file->doc_size = filesize($file->_file_path); $this->_ref_file = $file; return $this->_ref_file->store(); }
/** * @see parent::doStore() */ function doStore() { if (isset($_FILES['attachment'])) { $mail_id = CValue::post('mail_id'); $mail = new CUserMail(); $mail->load($mail_id); $files = array(); foreach ($_FILES['attachment']['error'] as $key => $file_error) { if (isset($_FILES['attachment']['name'][$key])) { $files[] = array('name' => $_FILES['attachment']['name'][$key], 'tmp_name' => $_FILES['attachment']['tmp_name'][$key], 'error' => $_FILES['attachment']['error'][$key], 'size' => $_FILES['attachment']['size'][$key]); } } foreach ($files as $_key => $_file) { if ($_file['error'] == UPLOAD_ERR_NO_FILE) { continue; } if ($_file['error'] != 0) { CAppUI::setMsg(CAppUI::tr("CFile-msg-upload-error-" . $_file["error"]), UI_MSG_ERROR); continue; } $attachment = new CMailAttachments(); $attachment->name = $_file['name']; $content_type = mime_content_type($_file['tmp_name']); $attachment->type = $attachment->getTypeInt($content_type); $attachment->bytes = $_file['size']; $attachment->mail_id = $mail_id; $content_type = explode('/', $content_type); $attachment->subtype = strtoupper($content_type[1]); $attachment->disposition = 'ATTACHMENT'; $attachment->extension = substr(strrchr($attachment->name, '.'), 1); $attachment->part = $mail->countBackRefs('mail_attachments') + 1; $attachment->store(); $file = new CFile(); $file->setObject($attachment); $file->author_id = CAppUI::$user->_id; $file->file_name = $attachment->name; $file->file_date = CMbDT::dateTime(); $file->fillFields(); $file->updateFormFields(); $file->doc_size = $attachment->bytes; $file->file_type = mime_content_type($_file['tmp_name']); $file->moveFile($_file, true); if ($msg = $file->store()) { CAppUI::setMsg(CAppUI::tr('CMailAttachments-error-upload-file') . ':' . CAppUI::tr($msg), UI_MSG_ERROR); CApp::rip(); } $attachment->file_id = $file->_id; if ($msg = $attachment->store()) { CAppUI::setMsg($msg, UI_MSG_ERROR); CApp::rip(); } } CAppUI::setMsg('CMailAttachments-msg-added', UI_MSG_OK); } else { parent::doStore(); } }
/** * parse file for indexing * @todo convert to using the FileSystem methods */ public function index(CFile $file) { /* Workaround for indexing large files: ** Based on the value defined in config data, ** files with file_size greater than specified limit ** are not indexed for searching. ** Negative value :<=> no filesize limit */ $index_max_file_size = w2PgetConfig('index_max_file_size', 0); if ($file->file_size > 0 && ($index_max_file_size < 0 || (int) $file->file_size <= $index_max_file_size * 1024)) { // get the parser application $parser = w2PgetConfig('parser_' . $file->file_type); if (!$parser) { $parser = w2PgetConfig('parser_default'); } if (!$parser) { return false; } // buffer the file $file->_filepath = W2P_BASE_DIR . '/files/' . $file->file_project . '/' . $file->file_real_filename; if (file_exists($file->_filepath)) { $fp = fopen($file->_filepath, 'rb'); $x = fread($fp, $file->file_size); fclose($fp); $ignore = w2PgetSysVal('FileIndexIgnoreWords'); $ignore = $ignore['FileIndexIgnoreWords']; $ignore = explode(',', $ignore); $x = strtolower($x); $x = preg_replace("/[^A-Za-z0-9 ]/", "", $x); foreach ($ignore as $ignoreWord) { $x = str_replace(" {$ignoreWord} ", ' ', $x); } $x = str_replace(' ', ' ', $x); $words = explode(' ', $x); foreach ($words as $index => $word) { if ('' == trim($word)) { continue; } $q = $this->query; $q->addTable('files_index'); $q->addInsert('file_id', $file->file_id); $q->addInsert('word', $word); $q->addInsert('word_placement', $index); $q->exec(); $q->clear(); } } else { //TODO: if the file doesn't exist.. should we delete the db record? } } $file->file_indexed = 1; $file->store(); return count($words); }
$bulk_file_folder = dPgetParam($_POST, 'bulk_file_folder', 'O'); if (is_array($selected) && count($selected)) { $upd_file = new CFile(); foreach ($selected as $key => $val) { if ($key) { $upd_file->load($key); } if (isset($_POST['bulk_file_project']) && $bulk_file_project != '' && $bulk_file_project != 'O') { if ($upd_file->file_id) { // move the file on filesystem if the affiliated project was changed if ($upd_file->file_project != $bulk_file_project) { $oldProject = $upd_file->file_project; $upd_file->file_project = $bulk_file_project; $res = $upd_file->moveFile($oldProject, $upd_file->file_real_filename); if (!$res) { $AppUI->setMsg('At least one File could not be moved', UI_MSG_ERROR); } } $upd_file->store(); } } if (isset($_POST['bulk_file_folder']) && $bulk_file_folder != '' && $bulk_file_folder != 'O') { if ($upd_file->file_id) { $upd_file->file_folder = $bulk_file_folder; $upd_file->store(); } } echo db_error(); } } $AppUI->redirect($redirect);
/** * Store a CFile linked to $this * * @param string $filename File name * @param string $filedata File contents * * @return bool */ function addFile($filename, $filedata) { $file = new CFile(); $file->setObject($this); $file->file_name = $filename; $file->file_type = "text/plain"; $file->doc_size = strlen($filedata); $file->author_id = CAppUI::$instance->user_id; $file->fillFields(); if (!$file->putContent($filedata)) { return false; } $file->store(); return true; }
function set_file_attachment($session, $file) { global $db; require_once 'soap/config_upload.php'; // require_once ('base.php'); $error = new SoapError(); if (!validate_authenticated($session)) { $error->set_error('invalid_login'); return array('id' => -1, 'error' => $error->get_soap_array()); } $AppUI =& $_SESSION['AppUI']; $GLOBALS['AppUI'] = $AppUI; $module_name = 'files'; $perms =& $AppUI->acl(); $canAccess = $perms->checkModule($module_name, 'access'); $canAuthor = $perms->checkModule($module_name, 'add'); $GLOBALS['perms'] = $perms; if (!$canAccess || !$canAuthor) { $error->set_error('no_access'); return array('id' => -1, 'error' => $error->get_soap_array()); } $modclass = $AppUI->getModuleClass($module_name); if (file_exists($modclass)) { include_once $modclass; } else { $error->set_error('no_module'); return array('id' => -1, 'error' => $error->get_soap_array()); } $module_name = 'tasks'; $modclass = $AppUI->getModuleClass($module_name); if (file_exists($modclass)) { include_once $modclass; } else { $error->set_error('no_module'); return array('id' => -1, 'error' => $error->get_soap_array()); } $focus = new CFile(); $task = new CTask(); $task->load($file['task_id']); /// $error->description.=$file['location']; //$file['location'] = base64_decode($file['location']); //$file['filename'] = base64_decode($file['filename']); /*if (filesize($file['location'] > $config_upload['upload_maxsize']){ $error->set_error('no_file'); return array('id'=>-1, 'error'=>$error->get_soap_array()); }*/ $file_real_filename = uniqid(rand()); $new_location = DP_BASE_DIR . '/files/' . $task->task_project . '/' . $file_real_filename; /// $error->description.=$new_location; if (!is_dir(DP_BASE_DIR . '/files/' . $task->task_project)) { mkdir(DP_BASE_DIR . '/files/' . $task->task_project); } copy($file['location'], $new_location); if (file_exists($new_location)) { // return array('id'=>$new_location, 'error'=>$error->get_soap_array()); if (!empty($file['filename'])) { $upload_filename = $file['filename']; $ext_pos = strrpos($upload_filename, "."); $file_ext = substr($upload_filename, $ext_pos + 1); // $error->description.="file_ext: ".$file_ext; // return array('id'=>-1, 'error'=>$error->get_soap_array()); /* if (in_array($file_ext, $config_upload['upload_badext'])) { $upload_filename .= ".txt"; $file_ext = "txt"; }*/ $focus->file_name = $upload_filename; $focus->file_owner = $AppUI->user_id; // $error->description.="file_owner_id: ".$AppUI->user_id; $focus->file_real_filename = $file_real_filename; $focus->file_project = $task->task_project; $focus->file_date = str_replace("'", '', $db->DBTimeStamp(time())); // $error->description.="file_task_id: ".$task->task_id; $focus->file_task = $task->task_id; $focus->file_folder = 0; $focus->file_size = filesize($new_location); $focus->file_parent = 0; $focus->file_folder = 0; $focus->file_version = 1; $focus->file_version_id = getNextVersionID(); $focus->file_category = 1; $focus->file_type = ext2mime($file_ext); $focus->store(); // $error->description.="file_file: ".$focus->file_type; } else { $error->set_error('no_file'); return array('id' => -1, 'error' => $error->get_soap_array()); } } else { $error->set_error('no_file'); return array('id' => -1, 'error' => $error->get_soap_array()); } return array('id' => $focus->file_id, 'error' => $error->get_soap_array()); }
/** * Create a CFile attachment to given CMbObject * @return string store-like message, null if successful */ function addFile(CMbObject $object) { $user = CUser::get(); $this->saveFile(); $file = new CFile(); $file->object_id = $object->_id; $file->object_class = $object->_class; $file->file_name = "{$object->_guid}.xml"; $file->file_type = "text/xml"; $file->doc_size = filesize($this->documentfilename); $file->file_date = CMbDT::dateTime(); $file->file_real_filename = uniqid(rand()); $file->author_id = $user->_id; $file->private = 0; if (!$file->moveFile($this->documentfilename)) { return "error-CFile-move-file"; } return $file->store(); }
/** * @see parent::doStore() */ function doStore() { $upload = null; if (CValue::POST("_from_yoplet") == 1) { /** @var CFile $obj */ $obj = $this->_obj; $array_file_name = array(); $path = CAppUI::conf("dPfiles yoplet_upload_path"); if (!$path) { $path = "tmp"; } // On retire les backslashes d'escape $file_name = stripslashes($this->request['_file_path']); // Récupération du nom de l'image en partant de la fin de la chaîne // et en rencontrant le premier \ ou / preg_match('@[\\\\/]([^\\\\/]*)$@i', $file_name, $array_file_name); $file_name = $array_file_name[1]; $extension = strrchr($file_name, '.'); $_rename = $this->request['_rename'] ? $this->request['_rename'] : 'upload'; $file_path = "{$path}/" . $this->request['_checksum']; $obj->file_name = $_rename == 'upload' ? $file_name : $_rename . $extension; $obj->_old_file_path = $this->request['_file_path']; $obj->doc_size = filesize($file_path); $obj->author_id = CAppUI::$user->_id; if (CModule::getActive("cda")) { $obj->type_doc = $this->request["type_doc"]; } $obj->fillFields(); $obj->updateFormFields(); $obj->file_type = CMbPath::guessMimeType($file_name); if ($msg = $obj->store()) { CAppUI::setMsg($msg, UI_MSG_ERROR); } else { $obj->forceDir(); $obj->moveFile($file_path); } return parent::doStore(); } $_file_category_id = CValue::post("_file_category_id"); $language = CValue::post("language"); $type_doc = CValue::post("type_doc"); $named = CValue::post("named"); $rename = CValue::post("_rename"); CValue::setSession("_rename", $rename); if (isset($_FILES["formfile"])) { $aFiles = array(); $upload =& $_FILES["formfile"]; foreach ($upload["error"] as $fileNumber => $etatFile) { if (!$named) { $rename = $rename ? $rename . strrchr($upload["name"][$fileNumber], '.') : ""; } if ($upload["name"][$fileNumber]) { $aFiles[] = array("_mode" => "file", "name" => $upload["name"][$fileNumber], "type" => CMbPath::guessMimeType($upload["name"][$fileNumber]), "tmp_name" => $upload["tmp_name"][$fileNumber], "error" => $upload["error"][$fileNumber], "size" => $upload["size"][$fileNumber], "language" => $language, "type_doc" => $type_doc, "file_category_id" => $_file_category_id, "object_id" => CValue::post("object_id"), "object_class" => CValue::post("object_class"), "_rename" => $rename); } } // Pasted images, via Data uri if (!empty($_POST["formdatauri"])) { $data_uris = $_POST["formdatauri"]; $data_names = $_POST["formdatauri_name"]; foreach ($data_uris as $fileNumber => $fileContent) { $parsed = $this->parseDataUri($fileContent); $_name = $data_names[$fileNumber]; if (!$named) { $ext = strrchr($_name, '.'); if ($ext === false) { $ext = "." . substr(strrchr($parsed["mime"], '/'), 1); $_name .= $ext; } $rename = $rename ? $rename . $ext : ""; } $temp = tempnam(sys_get_temp_dir(), "up_"); file_put_contents($temp, $parsed["data"]); if ($data_names[$fileNumber]) { $aFiles[] = array("_mode" => "datauri", "name" => $_name, "type" => $parsed["mime"], "tmp_name" => $temp, "error" => 0, "size" => strlen($parsed["data"]), "language" => $language, "type_doc" => $type_doc, "file_category_id" => $_file_category_id, "object_id" => CValue::post("object_id"), "object_class" => CValue::post("object_class"), "_rename" => $rename); } } } $merge_files = CValue::post("_merge_files"); if ($merge_files) { $pdf = new CMbPDFMerger(); $this->_obj = new $this->_obj->_class(); /** @var CFile $obj */ $obj = $this->_obj; $file_name = ""; $nb_converted = 0; foreach ($aFiles as $key => $file) { $converted = 0; if ($file["error"] == UPLOAD_ERR_NO_FILE) { continue; } if ($file["error"] != 0) { CAppUI::setMsg(CAppUI::tr("CFile-msg-upload-error-" . $file["error"]), UI_MSG_ERROR); continue; } // Si c'est un pdf, on le rajoute sans aucun traitement if (substr(strrchr($file["name"], '.'), 1) == "pdf") { $file_name .= substr($file["name"], 0, strpos($file["name"], '.')); $pdf->addPDF($file["tmp_name"], 'all'); $nb_converted++; $converted = 1; } else { if ($obj->isPDFconvertible($file["name"]) && $obj->convertToPDF($file["tmp_name"], $file["tmp_name"] . "_converted")) { $pdf->addPDF($file["tmp_name"] . "_converted", 'all'); $file_name .= substr($file["name"], 0, strpos($file["name"], '.')); $nb_converted++; $converted = 1; } else { $other_file = new CFile(); $other_file->bind($file); $other_file->file_name = $file["name"]; $other_file->file_type = $file["type"]; $other_file->doc_size = $file["size"]; $other_file->fillFields(); $other_file->private = CValue::post("private"); if (false == ($res = $other_file->moveTemp($file))) { CAppUI::setMsg("Fichier non envoyé", UI_MSG_ERROR); continue; } $other_file->author_id = CAppUI::$user->_id; if ($msg = $other_file->store()) { CAppUI::setMsg("Fichier non enregistré: {$msg}", UI_MSG_ERROR); continue; } CAppUI::setMsg("Fichier enregistré", UI_MSG_OK); } } // Pour le nom du pdf de fusion, on concatène les noms des fichiers if ($key != count($aFiles) - 1 && $converted) { $file_name .= "-"; } } // Si des fichiers ont été convertis et ajoutés à PDFMerger, // création du cfile. if ($nb_converted) { $obj->file_name = $file_name . ".pdf"; $obj->file_type = "application/pdf"; $obj->author_id = CAppUI::$user->_id; $obj->private = CValue::post("private"); $obj->object_id = CValue::post("object_id"); $obj->object_class = CValue::post("object_class"); $obj->updateFormFields(); $obj->fillFields(); $obj->forceDir(); $tmpname = tempnam("/tmp", "pdf_"); $pdf->merge('file', $tmpname); $obj->doc_size = strlen(file_get_contents($tmpname)); $obj->moveFile($tmpname); //rename($tmpname, $obj->_file_path . "/" .$obj->file_real_filename); if ($msg = $obj->store()) { CAppUI::setMsg("Fichier non enregistré: {$msg}", UI_MSG_ERROR); } else { CAppUI::setMsg("Fichier enregistré", UI_MSG_OK); } } } else { foreach ($aFiles as $file) { if ($file["error"] == UPLOAD_ERR_NO_FILE) { continue; } if ($file["error"] != 0) { CAppUI::setMsg(CAppUI::tr("CFile-msg-upload-error-" . $file["error"]), UI_MSG_ERROR); continue; } // Reinstanciate $this->_obj = new $this->_obj->_class(); /** @var CFile $obj */ $obj = $this->_obj; $obj->bind($file); $obj->file_name = empty($file["_rename"]) ? $file["name"] : $file["_rename"]; $obj->file_type = $file["type"]; if ($obj->file_type == "application/x-download") { $obj->file_type = CMbPath::guessMimeType($obj->file_name); } $obj->doc_size = $file["size"]; $obj->fillFields(); $obj->private = CValue::post("private"); if ($file["_mode"] == "file") { $res = $obj->moveTemp($file); } else { $res = $obj->moveFile($file["tmp_name"]); } if (false == $res) { CAppUI::setMsg("Fichier non envoyé", UI_MSG_ERROR); continue; } // File owner on creation if (!$obj->file_id) { $obj->author_id = CAppUI::$user->_id; } if ($msg = $obj->store()) { CAppUI::setMsg("Fichier non enregistré: {$msg}", UI_MSG_ERROR); continue; } CAppUI::setMsg("Fichier enregistré", UI_MSG_OK); } } // Redaction du message et renvoi if (CAppUI::isMsgOK() && $this->redirectStore) { $this->redirect =& $this->redirectStore; } if (!CAppUI::isMsgOK() && $this->redirectError) { $this->redirect =& $this->redirectError; } } else { parent::doStore(); } }
/** * Edition des journaux selon le type * * @param bool $read lecture * @param bool $create_journal Création du journal * * @return void */ function editJournal($read = true, $create_journal = true) { if ($create_journal) { $journal = new CJournalBill(); $journal->type = $this->type_pdf; $journal->nom = "Journal_" . $this->type_pdf . "_" . CMbDT::date(); $journal->_factures = $this->factures; if ($msg = $journal->store()) { mbTrace($msg); } else { $this->journal_id = $journal->_id; } } // Creation du PDF $this->pdf = new CMbPdf('l', 'mm'); $this->pdf->setPrintHeader(false); $this->pdf->setPrintFooter(false); $this->font = "vera"; $this->fontb = $this->font . "b"; $this->pdf->setFont($this->font, '', 8); $this->page = 0; $this->editEntete(); switch ($this->type_pdf) { case "paiement": $this->editPaiements(); break; case "debiteur": $this->editDebiteur(); break; case "rappel": $this->editRappel(); break; case "checklist": $this->editCheckList(); break; } if ($create_journal) { $file = new CFile(); $file->file_name = $journal->nom . ".pdf"; $file->file_type = "application/pdf"; $file->author_id = CMediusers::get()->_id; $file->file_category_id = 1; $file->setObject($journal); $file->fillFields(); $file->putContent($this->pdf->Output('Factures.pdf', "S")); if ($msg = $file->store()) { echo $msg; } if ($this->type_pdf == "checklist") { $user = CMediusers::get(); $printer = new CPrinter(); $printer->function_id = $user->function_id; $printer->label = "justif"; $printer->loadMatchingObject(); if (!$printer->_id) { CAppUI::setMsg("Les imprimantes ne sont pas paramétrées", UI_MSG_ERROR); echo CAppUI::getMsg(); return false; } $file = new CFile(); $pdf = $this->pdf->Output('Factures.pdf', "S"); $file_path = tempnam("tmp", "facture"); $file->_file_path = $file_path; file_put_contents($file_path, $pdf); $printer->loadRefSource()->sendDocument($file); unlink($file_path); } } if ($read) { //Affichage du fichier pdf $this->pdf->Output('Factures.pdf', "I"); } }
$q->addQuery('file_version_id'); $q->addOrder('file_version_id DESC'); $q->setLimit(1); $latest_file_version = $q->loadResult(); $q->clear(); $obj->file_version_id = $latest_file_version + 1; } else { $q = new w2p_Database_Query(); $q->addTable('files'); $q->addUpdate('file_checkout', ''); $q->addWhere('file_version_id = ' . (int) $obj->file_version_id); $q->exec(); $q->clear(); } } $result = $obj->store($AppUI); if (is_array($result)) { $AppUI->setMsg($result, UI_MSG_ERROR, true); $AppUI->holdObject($obj); $AppUI->redirect('m=files&a=addedit'); } if ($result) { // Notification $obj->load($obj->file_id); $obj->notify($notify); $obj->notifyContacts($notifyContacts); $AppUI->setMsg($file_id ? 'updated' : 'added', UI_MSG_OK, true); if ($obj->file_task) { $redirect = 'm=tasks&a=view&task_id=' . $obj->file_task; } elseif ($obj->file_project) { $redirect = 'm=projects&a=view&project_id=' . $obj->file_project;
$svg->file_type = "image/svg+xml"; $svg->author_id = $file->author_id; $svg->loadMatchingObject(); $svg->fillFields(); $svg->setObject($file->_ref_object); $svg->updateFormFields(); if (strpos($svg->file_name, ".") === false) { $svg->file_name = $svg->file_name . ".svg"; } if (strpos($svg->file_name, ".fjs") !== false) { $svg->file_name = str_replace(".fjs", ".svg", $svg->file_name); } // @TODO : replace url by datauri $content = str_replace(array("&a=fileviewer", "&file_id", "&suppressHeaders"), array("&a=fileviewer", "&file_id", "&suppressHeaders"), $content); if ($result = $svg->putContent(stripslashes($content))) { if ($msg = $svg->store()) { CAppUI::stepAjax($msg, UI_MSG_ERROR); } else { CAppUI::stepAjax("Dessin exporté avec succès", UI_MSG_OK); } } if ($remove_draft) { $msg = $file->delete(); CAppUI::stepAjax($msg ? $msg : "CFile-msg-delete", $msg ? UI_MSG_WARNING : UI_MSG_OK); } } else { if ($result = $file->putContent(stripslashes($content))) { // no extensio; if (strpos($file->file_name, ".") === false) { $file->file_name .= ".fjs"; }
/** * Make a PDF document archive of the sejour (based on soins/print_dossier_soins) * * @param string $title File title * @param bool $replace Replace existing file * * @return bool * @throws CMbException */ function makePDFarchive($title = "Dossier complet", $replace = false) { if (!CModule::getActive("soins")) { return false; } $query = array("m" => "soins", "a" => "print_dossier_soins", "sejour_id" => $this->_id, "dialog" => 1, "offline" => 1, "limit" => 10000, "_aio" => 1, "_aio_ignore_scripts" => 1); $base = $_SERVER["SCRIPT_NAME"] . "?" . http_build_query($query, "", "&"); $result = CApp::serverCall("http://127.0.0.1{$base}"); $content = $result["body"]; $file = new CFile(); $file->setObject($this); $file->file_name = "{$title}.pdf"; $file->file_type = "application/pdf"; /*if ($file->loadMatchingObject()) { if ($replace) { $file->delete(); // New file $file = new CFile(); $file->setObject($this); $file->file_name = "$title.pdf"; $file->file_type = "application/pdf"; } }*/ $file->fillFields(); $file->updateFormFields(); $file->forceDir(); $file->author_id = CAppUI::$user->_id; $compte_rendu = new CCompteRendu(); $compte_rendu->_orientation = "portrait"; $format = CCompteRendu::$_page_formats["a4"]; $page_width = round(72 / 2.54 * $format[0], 2); $page_height = round(72 / 2.54 * $format[1], 2); $compte_rendu->_page_format = array(0, 0, $page_width, $page_height); $content = str_replace("<!DOCTYPE html>", "", $content); CHtmlToPDFConverter::init("CWkHtmlToPDFConverter"); //CHtmlToPDFConverter::init("CPrinceXMLConverter"); $pdf = CHtmlToPDFConverter::convert($content, $compte_rendu->_page_format, $compte_rendu->_orientation); $file->putContent($pdf); if ($msg = $file->store()) { throw new CMbException($msg); } return true; }
// has moved projects, we need to move the file as well if ($move_files) { require_once $AppUI->getModuleClass('files'); $filehandler = new CFile(); $q = new DBQuery(); $q->addTable('files', 'f'); $q->addQuery('file_id'); $q->addWhere('file_task = ' . (int) $obj->task_id); $files = $q->loadColumn(); if (!empty($files)) { foreach ($files as $file) { $filehandler->load($file); $realname = $filehandler->file_real_filename; $filehandler->file_project = $obj->task_project; $filehandler->moveFile($move_files, $realname); $filehandler->store(); } } } $AppUI->setMsg($task_id ? 'Task updated' : 'Task added', UI_MSG_OK); } if (isset($hassign)) { $obj->updateAssigned($hassign, $hperc_assign_ar); } if (isset($hdependencies)) { // && !empty($hdependencies)) { // there are dependencies set! // backup initial start and end dates $tsd = new CDate($obj->task_start_date); $ted = new CDate($obj->task_end_date); // updating the table recording the
<?php /** * $Id$ * * @category Files * @package Mediboard * @author SARL OpenXtrem <*****@*****.**> * @license GNU General Public License, see http://www.gnu.org/licenses/gpl.html * @version $Revision$ * @link http://www.mediboard.org */ CCanDo::checkEdit(); $object_class = CValue::post("object_class"); $object_id = CValue::post("object_id"); $content = CValue::post("content"); $file_name = CValue::post("file_name"); $file = new CFile(); $file->file_name = $file_name; $file->object_class = $object_class; $file->object_id = $object_id; $file->fillFields(); $file->putContent(base64_decode($content)); $file->file_type = CMbPath::guessMimeType($file_name); if ($msg = $file->store()) { CAppUI::setMsg($msg, UI_MSG_ERROR); } else { CAppUI::setMsg("CFile-msg-moved"); } echo CAppUI::getMsg();
$text->load($text_html); $content_type = "text/html"; } else { $text = new CContentAny(); $text->load($text_plain); } $file = new CFile(); $file->setObject($object); $file->author_id = CAppUI::$user->_id; $file->file_name = "sans_titre"; $file->file_category_id = $category_id; if ($mail->subject) { $file->file_name = $mail->subject; } if ($rename_text) { $file->file_name = $rename_text; } $file->file_type = $content_type; $file->fillFields(); $file->putContent($text->content); if ($str = $file->store()) { CAppUI::stepAjax($str, UI_MSG_ERROR); } else { $mail->text_file_id = $file->_id; $mail->store(); CAppUI::stepAjax("CUserMail-content-attached", UI_MSG_OK); } } if (!$text_html && !$text_plain && $attach_list == "") { CAppUI::stepAjax("CMailAttachments-msg-noAttachSelected", UI_MSG_ERROR); }
$obj->_message = $co_cancel ? 'reverted' : 'checked out'; if ($not) { $obj->notify(); } if ($notcont) { $obj->notifyContacts(); } } //Checkout Cancellation if ($co_cancel) { if ($msg = $obj->checkout('', '')) { $AppUI->setMsg($msg, UI_MSG_ERROR); } else { $AppUI->setMsg('File checkout reverted', UI_MSG_OK); } } if ($msg = $obj->store()) { $AppUI->setMsg($msg, UI_MSG_ERROR); } $params = 'file_id=' . $file_id; $session_id = SID; session_write_close(); // are the params empty // Fix to handle cookieless sessions if ($session_id != "") { $params .= "&" . $session_id; } if ($co_cancel != 1) { //header("Refresh: 0; URL=fileviewer.php?$params"); echo '<script type="text/javascript">fileloader = window.open("fileviewer.php?' . $params . '", "mywindow","location=1,status=1,scrollbars=0,width=20,height=20");' . 'fileloader.moveTo(0,0);</script>'; }
/** * PDF conversion of a file * * @param string $file_path path to the file * @param string $pdf_path path the pdf file * * @return bool */ function convertToPDF($file_path = null, $pdf_path = null) { global $rootName; // Vérifier si openoffice est lancé if (!CFile::openofficeLaunched()) { return 0; } // Vérifier sa charge en mémoire CFile::openofficeOverload(); if (!$file_path && !$pdf_path) { $file = new CFile(); $file->setObject($this); $file->private = $this->private; $file->file_name = $this->file_name . ".pdf"; $file->file_type = "application/pdf"; $file->author_id = CAppUI::$user->_id; $file->fillFields(); $file->updateFormFields(); $file->forceDir(); $save_name = $this->_file_path; if ($msg = $file->store()) { CAppUI::setMsg($msg, UI_MSG_ERROR); return 0; } $file_path = $this->_file_path; $pdf_path = $file->_file_path; } // Requête post pour la conversion. // Cela permet de mettre un time limit afin de garder le contrôle de la conversion. ini_set("default_socket_timeout", 10); $fileContents = base64_encode(file_get_contents($file_path)); $url = CAppUI::conf("base_url") . "/index.php?m=dPfiles&a=ajax_ooo_convert&suppressHeaders=1"; $data = array("file_data" => $fileContents, "pdf_path" => $pdf_path); // Fermeture de la session afin d'écrire dans le fichier de session CSessionHandler::writeClose(); // Le header Connection: close permet de forcer a couper la connexion lorsque la requête est effectuée $ctx = stream_context_create(array('http' => array('method' => 'POST', 'header' => "Content-type: application/x-www-form-urlencoded charset=UTF-8\r\n" . "Connection: close\r\n" . "Cookie: mediboard=" . session_id() . "\r\n", 'content' => http_build_query($data)))); // La requête post réouvre la session $res = file_get_contents($url, false, $ctx); if (isset($file) && $res == 1) { $file->doc_size = filesize($pdf_path); if ($msg = $file->store()) { CAppUI::setMsg($msg, UI_MSG_ERROR); return 0; } } // Si la conversion a échoué // on relance le service s'il ne répond plus. if ($res != 1) { CFile::openofficeOverload(1); } return $res; }
/** * create the CFiles attached to the mail * * @param CMailAttachments[] $attachList The list of CMailAttachment * @param CPop $popClient the CPop client * * @return void */ function attachFiles($attachList, $popClient) { //size limit $size_required = CAppUI::pref("getAttachmentOnUpdate"); if ($size_required == "") { $size_required = 0; } foreach ($attachList as $_attch) { $_attch->mail_id = $this->_id; $_attch->loadMatchingObject(); if (!$_attch->_id) { $_attch->store(); } //si preference taille ok OU que la piece jointe est incluse au texte => CFile if ($_attch->bytes <= $size_required || $_attch->disposition == "INLINE") { $file = new CFile(); $file->setObject($_attch); $file->author_id = CAppUI::$user->_id; if (!$file->loadMatchingObject()) { $file_pop = $popClient->decodeMail($_attch->encoding, $popClient->openPart($this->uid, $_attch->getpartDL())); $file->file_name = $_attch->name; //apicrypt attachment if (strpos($_attch->name, ".apz") !== false) { $file_pop = CApicrypt::uncryptAttachment($popClient->source->object_id, $file_pop); } //file type detection $first = is_array($file_pop) ? reset($file_pop) : $file_pop; $mime = $this->extensionDetection($first); //file name $infos = pathinfo($_attch->name); $extension = $infos['extension']; $mime_extension = strtolower(end(explode("/", $mime))); if (strtolower($extension) != $mime_extension) { $file->file_name = $infos['filename'] . "." . $mime_extension; } $file->file_type = $mime ? $mime : $_attch->getType($_attch->type, $_attch->subtype); $file->fillFields(); $file->updateFormFields(); $file->putContent($file_pop); $file->store(); } } } }
/** * OBX Segment with reference pointer to external report * * @param DOMNode $OBX DOM node * @param CMbObject $object object * @param String $name name * * @return bool */ function getReferencePointerToExternalReport(DOMNode $OBX, CMbObject $object, $name) { $exchange_hl7v2 = $this->_ref_exchange_hl7v2; $sender = $exchange_hl7v2->_ref_sender; //Récupération de l'emplacement et du type du fichier (full path) $observation = $this->getObservationValue($OBX); $rp = explode("^", $observation); $pointer = CMbArray::get($rp, 0); $type = CMbArray::get($rp, 2); // Création d'un lien Hypertext sur l'objet if ($type == "HTML") { $hyperlink = new CHyperTextLink(); $hyperlink->setObject($object); $hyperlink->name = $name; $hyperlink->link = $pointer; $hyperlink->loadMatchingObject(); if ($msg = $hyperlink->store()) { $this->codes[] = "E343"; return false; } return true; } // Chargement des objets associés à l'expéditeur /** @var CInteropSender $sender_link */ $object_links = $sender->loadRefsObjectLinks(); if (!$object_links) { $this->codes[] = "E340"; return false; } $sender_link = new CInteropSender(); $files_category = new CFilesCategory(); // On récupère toujours une seule catégorie, et une seule source associée à l'expéditeur foreach ($object_links as $_object_link) { if ($_object_link->_ref_object instanceof CFilesCategory) { $files_category = $_object_link->_ref_object; } if ($_object_link->_ref_object instanceof CInteropSender) { $sender_link = $_object_link->_ref_object; continue 1; } } // Aucun expéditeur permettant de récupérer les fichiers if (!$sender_link->_id) { $this->codes[] = "E340"; return false; } $authorized_sources = array("CSenderFileSystem", "CSenderFTP"); // L'expéditeur n'est pas prise en charge pour la réception de fichiers if (!CMbArray::in($sender_link->_class, $authorized_sources)) { $this->codes[] = "E341"; return false; } $sender_link->loadRefsExchangesSources(); // Aucune source permettant de récupérer les fichiers if (!$sender_link->_id) { $this->codes[] = "E342"; return false; } $source = $sender_link->getFirstExchangesSources(); $path = str_replace("\\", "/", $pointer); $path = basename($path); if ($source instanceof CSourceFileSystem) { $path = $source->getFullPath() . "/{$path}"; } // Exception déclenchée sur la lecture du fichier try { $content = $source->getData("{$path}"); } catch (Exception $e) { $this->codes[] = "E345"; return false; } if (!$type) { $type = CMbPath::getExtension($path); } $file_type = $this->getFileType($type); $file_name = $this->getObservationFilename($OBX); // Gestion du CFile $file = new CFile(); $file->setObject($object); $file->file_name = $file_name ? $file_name : $name; $file->file_type = $file_type; $file->loadMatchingObject(); if ($files_category->_id && $sender->_configs["associate_category_to_a_file"]) { $file->file_category_id = $files_category->_id; } $file->file_date = "now"; $file->doc_size = strlen($content); $file->fillFields(); $file->updateFormFields(); $file->putContent($content); if ($msg = $file->store()) { $this->codes[] = "E343"; } $this->codes[] = "I340"; return true; }
function store($object_id) { global $AppUI, $db, $_FILES, $m, $_POST; $file_uploaded = false; // instantiate the file object and eventually load exsiting file data $obj = new CFile(); if ($_POST[$this->field_name . '_id']) { $obj->load($_POST[$this->field_name . '_id']); // create an old object for the case that // the file must be replaced if ($_POST[$this->field_name . '_id'] > 0) { $oldObj = new CFile(); $oldObj->load($_POST[$this->field_name . '_id']); } } // if the cf lives in the projects module // affiliate the file to the suitable project if ($m == 'projects' && !empty($_POST['project_id'])) { $obj->file_project = $_POST['project_id']; } // todo: implement task affiliation here, too $upload = null; if (isset($_FILES[$this->field_name])) { $upload = $_FILES[$this->field_name]; if ($upload['size'] > 0) { // store file with a unique name $obj->file_name = $upload['name']; $obj->file_type = $upload['type']; $obj->file_size = $upload['size']; $obj->file_date = str_replace("'", '', $db->DBTimeStamp(time())); $obj->file_real_filename = uniqid(rand()); $obj->file_owner = $AppUI->user_id; $obj->file_version++; $obj->file_version_id = $obj->file_id; $res = $obj->moveTemp($upload); if ($res) { $file_uploaded = true; } if ($msg = $obj->store()) { $AppUI->setMsg($msg, UI_MSG_ERROR); } else { // reset the cf field_name to the file_id $this->setValue($obj->file_id); } } } // Delete the existing (old) file in case of file replacement // (through addedit not through c/o-versions) if ($_POST[$this->field_name . '_id'] && $upload['size'] > 0 && $file_uploaded) { $oldObj->deleteFile(); } if ($upload['size'] > 0 && $file_uploaded) { return parent::store($object_id); } else { if ($upload['size'] > 1 && !$file_uploaded) { $AppUI->setMsg('File could not be stored!', UI_MSG_ERROR, true); return true; } } }
/** * Traitement des retours en erreur d'xml d'un praticien * * @param int $chir_id praticien de la consultation * * @return void|string */ static function traitementDossier($chir_id) { $files = array(); $fs_source_reception = CExchangeSource::get("reception-tarmed-CMediusers-{$chir_id}", "file_system", true, null, false); if (!$fs_source_reception->_id || !$fs_source_reception->active) { return null; } $count_files = CMbPath::countFiles($fs_source_reception->host); if ($count_files < 100) { try { $files = $fs_source_reception->receive(); } catch (CMbException $e) { return CAppUI::tr($e->getMessage()); } } $delfile_read_reject = CAppUI::conf("dPfacturation Other delfile_read_reject", CGroups::loadCurrent()); foreach ($files as $_file) { $fs = new CSourceFileSystem(); $rejet = new self(); $rejet->praticien_id = $chir_id; $rejet->file_name = basename($_file); if ($msg = $rejet->store()) { return $msg; } $rejet->readXML($fs->getData($_file)); //Sauvegarde du XML en CFile $new_file = new CFile(); $new_file->setObject($rejet); $new_file->file_name = basename($_file); $new_file->file_type = "application/xml"; $new_file->author_id = CAppUI::$user->_id; $new_file->fillFields(); $new_file->updateFormFields(); $new_file->forceDir(); $new_file->putContent(trim($fs->getData($_file))); if ($msg = $new_file->store()) { mbTrace($msg); } //Suppression du fichier selon configuration if ($delfile_read_reject) { $fs->delFile($_file); } } return null; }
$file->getDataURI(); $_data["file_uri"] = $file->_data_uri; } //user $user = CMediusers::get($user_id); // file $file = new CFile(); $file->setObject($context); $file->file_name = CAppUI::tr("CFile-create-mozaic") . " de " . CAppUI::tr($context->_class) . " du " . CMbDT::dateToLocale(CMbDT::date()) . ".pdf"; $file->file_type = "application/pdf"; $file->file_category_id = $cat_id; $file->author_id = CMediusers::get()->_id; $file->fillFields(); $file->updateFormFields(); $file->forceDir(); $file->store(); $cr = new CCompteRendu(); $cr->_page_format = "A4"; $cr->_orientation = "portrait"; // use template for header and footer $template_header = new CTemplateManager(); $context->fillTemplate($template_header); $header = CCompteRendu::getSpecialModel($user, "CPatient", "[ENTETE MOZAIC]"); if ($header->_id) { $header->loadContent(); $template_header->renderDocument($header->_source); } else { $template_header->document = "<p style=\"text-align:center;\">" . $context->_view . "</p>"; } $template_footer = new CTemplateManager(); $context->fillTemplate($template_footer);
/** * Store the file * * @param String $prefix Prefix for the name of file * @param String $file_name Name of file * @param String $file_type Type file * @param CSejour $sejour Sejour * @param Array &$erreur Error * * @return bool */ function storeFile($prefix, $file_name, $file_type, $sejour, &$erreur) { /** @var CInteropSender $sender */ $sender = $this->_ref_sender; $exchange_hpr = $this->_ref_exchange_hpr; $file = false; $object_links = $sender->loadRefsObjectLinks(); foreach ($object_links as $_object_link) { /** @var CInteropSender $sender_link */ $sender_link = $_object_link->loadRefObject(); $sender_link->loadRefsExchangesSources(); foreach ($sender_link->_ref_exchanges_sources as $_source) { $path = $_source->getFullPath($file_name); /** @var CExchangeSource $_source */ $data = $_source->getData($path); if (!$data) { continue; } $file = new CFile(); $file->file_name = "{$prefix} {$file_name}"; $file->file_type = $file_type; $file->fillFields(); $file->setObject($sejour); $file->putContent($data); if ($msg = $file->store()) { $erreur[] = new CHPrimSanteError($exchange_hpr, "P", "17", array("OBX", $this->loop, $this->identifier_patient), "10.6", CMbString::removeAllHTMLEntities($msg)); continue; } } } if (!$file) { $erreur[] = new CHPrimSanteError($exchange_hpr, "P", "18", array("OBX", $this->loop, $this->identifier_patient), "10.6"); return false; } return true; }