/**
  * @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();
     }
 }
Example #2
0
    $file = new CFile();
    $file->load($_data["file_id"]);
    $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>";
}
 /**
  * load files linked to the present attachment
  *
  * @return CFile
  */
 function loadFiles()
 {
     //a file is already linked and we have the id
     $file = new CFile();
     if ($this->file_id) {
         $file->load($this->file_id);
         $file->loadRefsFwd();
         //TODO : fix this
     } else {
         $file->setObject($this);
         $file->loadMatchingObject();
     }
     $file->updateFormFields();
     return $this->_file = $file;
 }
Example #4
0
 /**
  * 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();
             }
         }
     }
 }
 /**
  * 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;
 }
 /**
  * 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;
 }
Example #7
0
 /**
  * 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;
 }
Example #8
0
    if ($msg = $file->delete()) {
        CAppUI::stepAjax($msg, UI_MSG_ERROR);
    } else {
        CAppUI::stepAjax("CFile-msg-delete", UI_MSG_OK);
    }
} else {
    $file->file_type = "image/fabricjs";
    if ($export) {
        $svg = new CFile();
        $svg->file_name = $file->file_name;
        $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("&amp;a=fileviewer", "&amp;file_id", "&amp;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);
            }
        }
Example #9
0
 /**
  * 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;
 }