Exemplo n.º 1
0
/**
 * Extract files
 *
 * @param string $schemaDir  Schema directory
 * @param string $schemaFile Schema files
 * @param bool   $delOldDir  Delete old directory
 *
 * @return void
 */
function extractFiles($schemaDir, $schemaFile, $delOldDir = false)
{
    $baseDir = "modules/hprimxml/xsd";
    $destinationDir = "{$baseDir}/{$schemaDir}";
    $archivePath = "{$baseDir}/{$schemaFile}";
    if ($delOldDir && file_exists($destinationDir)) {
        if (CMbPath::remove($destinationDir)) {
            echo "<div class='info'>Suppression de {$destinationDir}</div>";
        } else {
            echo "<div class='error'>Impossible de supprimer le dossier {$destinationDir}</div>";
            return;
        }
    }
    if (false != ($nbFiles = CMbPath::extract($archivePath, $destinationDir))) {
        echo "<div class='info'>Extraction de {$nbFiles} fichiers pour {$schemaDir}</div>";
    } else {
        echo "<div class='error'>Impossible d'extraire l'archive {$schemaFile}</div>";
        return;
    }
    if (CAppUI::conf("hprimxml concatenate_xsd")) {
        $rootFiles = glob("{$destinationDir}/msg*.xsd");
        $includeFiles = array_diff(glob("{$destinationDir}/*.xsd"), $rootFiles);
        foreach ($rootFiles as $rootFile) {
            $xsd = new CHPrimXMLSchema();
            $xsd->loadXML(file_get_contents($rootFile));
            $xpath = new DOMXPath($xsd);
            $importFiles = array();
            foreach ($includeFiles as $includeFile) {
                $include = new DOMDOcument();
                $include->loadXML(file_get_contents($includeFile));
                $isImport = false;
                foreach ($importFiles as $key => $value) {
                    if (strpos($includeFile, $key) !== false) {
                        $isImport = true;
                        break;
                    }
                }
                foreach ($include->documentElement->childNodes as $child) {
                    $impNode = $xsd->importNode($child, true);
                    $existing = false;
                    if (in_array($impNode->nodeName, array("xsd:simpleType", "xsd:complexType"))) {
                        $name = $impNode->getAttribute('name');
                        $existing = $xpath->query("//{$impNode->nodeName}[@name='{$name}']")->length > 0;
                    }
                    if ($isImport) {
                        $xsd->documentElement->setAttribute("xmlns:insee", "http://www.hprim.org/inseeXML");
                    }
                    if (!$existing) {
                        $xsd->documentElement->appendChild($impNode);
                    }
                }
            }
            $xsd->purgeImportedNamespaces();
            $xsd->purgeIncludes();
            file_put_contents(substr($rootFile, 0, -4) . ".xml", $xsd->saveXML());
            echo "<div class='info'>Schéma concatené</div>";
        }
    }
}
Exemplo n.º 2
0
 /**
  * CMbSemaphore Constructor
  *
  * @param string $key semaphore identifier
  */
 function __construct($key)
 {
     $this->path = CAppUI::conf("root_dir") . "/tmp/locks";
     CMbPath::forceDir($this->path);
     $this->process = getmypid();
     $prefix = CApp::getAppIdentifier();
     $this->key = "{$prefix}-sem-{$key}";
 }
 /**
  * @see parent::__construct()
  */
 function __construct($key, $label = null)
 {
     parent::__construct($key, $label);
     $this->path = CAppUI::conf("root_dir") . "/tmp/locks";
     $this->process = getmypid();
     $this->filename = "{$this->path}/" . $this->getLockKey();
     CMbPath::forceDir(dirname($this->filename));
 }
 /**
  * @see parent::init()
  */
 function init()
 {
     if (!CMbPath::forceDir($this->dir)) {
         trigger_error("Shared memory could not be initialized, ensure that '{$this->dir}' is writable");
         CApp::rip();
     }
     return true;
 }
Exemplo n.º 5
0
 /**
  * Construct
  *
  * @param string $key lock identifier
  */
 function __construct($key)
 {
     $this->path = CAppUI::conf("root_dir") . "/tmp/locks";
     $this->process = getmypid();
     $prefix = CApp::getAppIdentifier();
     $this->key = "{$prefix}-lock-{$key}";
     $this->filename = "{$this->path}/{$this->key}";
     CMbPath::forceDir(dirname($this->filename));
 }
Exemplo n.º 6
0
 /**
  * Standard constructor
  *
  * @param mixed  $handle       File handle of file path
  * @param string $profile_name Profile name, one of openoffice and excel
  *
  * @return CCSVFile
  */
 function __construct($handle = null, $profile_name = self::PROFILE_EXCEL)
 {
     if ($handle) {
         $this->handle = $handle;
         if (is_string($handle)) {
             $this->handle = fopen($handle, "r+");
         }
     } else {
         $this->handle = CMbPath::getTempFile();
     }
     $this->setProfile($profile_name);
 }
 /**
  * Embed all the external resources of the current output buffer inside a single file and outputs it.
  *
  * @param string $path Path to save the files to
  * 
  * @return void|string
  */
 private static function allInOne($path = null, $options = array())
 {
     if ($path) {
         self::$_path = rtrim($path, "/\\") . "/";
     }
     CApp::setMemoryLimit("256M");
     self::$_fp_out = CMbPath::getTempFile();
     $re_img = "/<img([^>]*)src\\s*=\\s*[\"']([^\"']+)[\"']([^>]*)(>|\$)/i";
     $re_link = "/<link[^>]*rel=\"stylesheet\"[^>]*href\\s*=\\s*[\"']([^\"']+)[\"'][^>]*>/i";
     $re_script = "/<script[^>]*src\\s*=\\s*[\"']([^\"']+)[\"'][^>]*>\\s*<\\/script>/i";
     $re_a = "/<a([^>]*)href\\s*=\\s*[\"']embed:([^\"']+)[\"']([^>]*)>/i";
     $ignore_scripts = !empty($options["ignore_scripts"]);
     // End Output Buffering
     ob_end_clean();
     ob_start();
     rewind(self::$_fp_in);
     while (!feof(self::$_fp_in)) {
         $line = fgets(self::$_fp_in);
         $line = preg_replace_callback($re_img, array('self', 'replaceImgSrc'), $line);
         $line = preg_replace_callback($re_link, array('self', 'replaceStylesheet'), $line);
         if (!$ignore_scripts) {
             $line = preg_replace_callback($re_script, array('self', 'replaceScriptSrc'), $line);
         }
         if (self::$_path) {
             $line = preg_replace_callback($re_a, array('self', 'replaceAEmbed'), $line);
         }
         fwrite(self::$_fp_out, $line);
     }
     ob_end_clean();
     $length = 0;
     rewind(self::$_fp_out);
     $full_str = "";
     while (!feof(self::$_fp_out)) {
         $line = fgets(self::$_fp_out);
         $length += strlen($line);
         $line = str_replace("[[AIO-length]]", CMbString::toDecaBinary($length), $line);
         if (strpos($line, "[[AIO-memory]]") !== false) {
             $line = str_replace("[[AIO-memory]]", self::getOutputMemory(true), $line);
         }
         if ($path) {
             $full_str .= $line;
         } else {
             echo $line;
         }
     }
     return $full_str;
 }
Exemplo n.º 8
0
}
if (md5($pass) != "aa450aff6d0f4974711ff4c5536ed4cb") {
    CAppUI::stepAjax("Mot de passe incorrect.\nAttention, fonctionnalité à utiliser avec une extrême prudence", UI_MSG_ERROR);
}
// Chrono start
$chrono = new Chronometer();
$chrono->start();
$segment = CValue::get("segment", 1000);
$step = CValue::get("step", 1);
$from = $step > 1 ? 100 + $segment * ($step - 2) : 0;
$to = $step > 1 ? 100 + ($step - 1) * $segment : 100;
$padded = str_pad($step, "3", "0", STR_PAD_LEFT);
$htmpath = "tmp/ordre/medecin{$padded}.htm";
$xmlpath = "tmp/ordre/medecin{$padded}.xml";
$csvpath = "tmp/ordre/medecin{$padded}.csv";
CMbPath::forceDir(dirname($htmpath));
$mode = CValue::get("mode");
// Step 1: Emulates an HTTP request
if ($mode == "get") {
    $departement = CValue::get("departement");
    $cookiepath = CAppUI::getTmpPath("cookie.txt");
    $page = $step - 1;
    $url_ch1 = "http://www.conseil-national.medecin.fr/annuaire";
    $url_ch2 = "http://www.conseil-national.medecin.fr/annuaire/resultats?page={$page}";
    $post = array("sexe" => 3, "departement" => $departement, "op" => "Recherche", "form_build_id" => "form-c2b45a67c53fdd389338ffee58d2c1c2", "form_id" => "cn_search_med_advanced_form");
    $ch = curl_init();
    $ch2 = curl_init();
    curl_setopt($ch, CURLOPT_COOKIEJAR, $cookiepath);
    curl_setopt($ch, CURLOPT_COOKIEFILE, $cookiepath);
    curl_setopt($ch, CURLOPT_VERBOSE, 1);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
Exemplo n.º 9
0
 */
function getNum($value)
{
    return preg_replace("/[^0-9]/", "", $value);
}
CApp::setTimeLimit(3600);
CSessionHandler::writeClose();
if (empty($_FILES["import"]["tmp_name"])) {
    return;
}
$dir = "tmp/import_etab_externe";
CMbPath::forceDir($dir);
$archive = "{$dir}/archive.zip";
move_uploaded_file($_FILES["import"]["tmp_name"], $archive);
// Extract the data files
if (null == ($nbFiles = CMbPath::extract($archive, $dir))) {
    CAppUI::setMsg("Erreur, impossible d'extraire l'archive", UI_MSG_ERROR);
    return;
} else {
    CAppUI::setMsg("{$nbFiles} fichiers extraits", UI_MSG_OK);
}
$files = glob("{$dir}/*.csv");
foreach ($files as $_file) {
    $fp = fopen($_file, "r");
    $csv = new CCSVFile($fp);
    $csv->readLine();
    // first line
    while ($line = $csv->readLine()) {
        if (!isset($line[1])) {
            continue;
        }
Exemplo n.º 10
0
    CAppUI::setMsg("Certaines informations sont manquantes au traitement de la traduction.", UI_MSG_ERROR);
    redirect();
    return;
}
$translateModule = new CMbConfig();
$translateModule->sourcePath = null;
// Ecriture du fichier
$translateModule->options = array("name" => "locales");
if ($module_name != "common") {
    $translateModule->targetPath = "modules/{$module_name}/locales/{$language}.php";
} else {
    $translateModule->targetPath = "locales/{$language}/common.php";
}
$translateModule->sourcePath = $translateModule->targetPath;
if (!is_file($translateModule->targetPath)) {
    CMbPath::forceDir(dirname($translateModule->targetPath));
    file_put_contents($translateModule->targetPath, '<?php $locales["module-' . $module_name . '-court"] = "' . $module_name . '";');
}
$translateModule->load();
foreach ($strings as $key => $valChaine) {
    if ($valChaine !== "") {
        $translateModule->values[$key] = CMbString::purifyHTML(stripslashes($valChaine));
    } else {
        unset($translateModule->values[$key]);
    }
}
uksort($translateModule->values, "strnatcmp");
$error = $translateModule->update($translateModule->values, false);
SHM::remKeys("locales-{$language}-*");
if ($error instanceof PEAR_Error) {
    CAppUI::setMsg("Error while saving locales file : {$error->message}", UI_MSG_ERROR);
Exemplo n.º 11
0
$url = CValue::get('url');
$format = CValue::get('format');
if (!$file_id && !$url) {
    return "";
}
if ($file_id) {
    $file = new CFile();
    $file->load($file_id);
    $file->canDo();
    if (!$file->_can->read) {
        return "";
    }
    //@TODO le faire marcher avec du datauri
    if (strpos($file->file_type, "svg") !== false) {
        echo json_encode("?m=files&a=fileviewer&file_id={$file->_id}&phpTumb=1&suppressHeaders=1");
        CApp::rip();
        //echo CApp::json(file_get_contents($file->_file_path));
    } elseif ($format == 'uri') {
        $data = $file->getDataURI();
        CApp::json($data);
    }
} elseif ($url) {
    $mime_type = CMbPath::guessMimeType($url);
    $content = @file_get_contents($url);
    if ($content) {
        $data = "data:" . $mime_type . ";base64," . urlencode(base64_encode($content));
        CApp::json($data);
    } else {
        return "";
    }
}
Exemplo n.º 12
0
 /**
  * Get all stats for one file
  *
  * @param string $file File name
  *
  * @return null
  */
 function stat($file)
 {
     /**
      * Recursive increment routine
      *
      * @param array &$stats Stats
      * @param array $parts  Parts
      *
      * @return array
      */
     function increment(&$stats, $parts)
     {
         if (!isset($stats)) {
             $stats = array("count" => null, "items" => null);
         }
         $stats["count"]++;
         if ($first = array_shift($parts)) {
             increment($stats["items"][$first], $parts);
         }
     }
     // Recursive call
     $stats = null;
     foreach ($this->getFlattenAlerts() as $_alert) {
         $parts = explode(".", $_alert["source"]);
         increment($stats, $parts);
     }
     // Create the file
     $path = $this->makeReportPath($file, "json");
     CMbPath::forceDir(dirname($path));
     touch($path);
     file_put_contents($path, json_encode($stats));
     return $stats;
 }
Exemplo n.º 13
0
<?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();
<?php

/**
 * $Id: ajax_vw_supervision_pictures.php 20428 2013-09-20 12:14:48Z phenxdesign $
 *
 * @package    Mediboard
 * @subpackage Patients
 * @author     SARL OpenXtrem <*****@*****.**>
 * @license    GNU General Public License, see http://www.gnu.org/licenses/gpl.html
 * @version    $Revision: 20428 $
 */
CCanDo::checkAdmin();
$timed_picture_id = CValue::get("timed_picture_id");
$tree = CMbPath::getTree(CSupervisionTimedPicture::PICTURES_ROOT);
$smarty = new CSmartyDP();
$smarty->assign("tree", $tree);
$smarty->assign("timed_picture_id", $timed_picture_id);
$smarty->display("inc_vw_supervision_pictures.tpl");
Exemplo n.º 15
0
     $export = new CMbObjectExport($_patient, $backrefs_tree);
     $callback = function (CStoredObject $object, $node, $depth) use($export, $dir, $ignore_files, $generate_pdfpreviews) {
         switch ($object->_class) {
             case "CCompteRendu":
                 /** @var CCompteRendu $object */
                 if ($generate_pdfpreviews) {
                     $object->makePDFpreview(true);
                 }
                 break;
             case "CFile":
                 if ($ignore_files) {
                     break;
                 }
                 /** @var CFile $object */
                 $_dir = "{$dir}/{$object->object_class}/{$object->object_id}";
                 CMbPath::forceDir($_dir);
                 file_put_contents($_dir . "/" . $object->file_real_filename, @$object->getBinaryContent());
                 break;
             default:
                 // Do nothing
         }
     };
     $export->empty_values = false;
     $export->setObjectCallback($callback);
     $export->setForwardRefsTree($fwdrefs_tree);
     $xml = $export->toDOM()->saveXML();
     file_put_contents("{$dir}/export.xml", $xml);
     //CMbPath::zip($dir, dirname($dir)."/export-$date.zip");
 } catch (CMbException $e) {
     $e->stepAjax(UI_MSG_ERROR);
 }
Exemplo n.º 16
0
<?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
 */
$dir = CFile::$directory . "/test";
CAppUI::stepAjax("Test de création de répertoire et d'un fichier dans ce répertoire", UI_MSG_WARNING);
// Création d'un répertoire
$directory_create = CMbPath::forceDir($dir);
if (!$directory_create) {
    CAppUI::stepAjax("Création de répertoire échoué", UI_MSG_ERROR);
    CApp::rip();
}
CAppUI::stepAjax("Création de répertoire Ok", UI_MSG_OK);
// Création d'un fichier
$file_create = file_put_contents($dir . "/test_file", "a");
if (!$file_create) {
    CAppUI::stepAjax("Création de fichier échoué", UI_MSG_ERROR);
    @unlink($dir);
    CApp::rip();
}
CAppUI::stepAjax("Création de fichier Ok", UI_MSG_OK);
// Suppression du fichier et du dossier
@unlink($dir . "/test_file");
Exemplo n.º 17
0
$chir_id = CValue::getOrSession("chir_id");
$traitement = CValue::get("traitement", 0);
$list = CValue::get("list", 0);
if ($traitement && $chir_id) {
    CFactureRejet::traitementDossier($chir_id);
}
// Liste des chirurgiens
$user = new CMediusers();
$listChir = $user->loadPraticiens(PERM_EDIT);
//Listing des fichiers
$count_files = 0;
$files = array();
$erreur = null;
$fs_source_reception = CExchangeSource::get("reception-tarmed-CMediusers-{$chir_id}", "file_system", true, null, false);
if ($fs_source_reception->_id && $fs_source_reception->active) {
    $count_files = CMbPath::countFiles($fs_source_reception->host);
    if ($count_files < 1000) {
        try {
            $files = $fs_source_reception->receive();
        } catch (CMbException $e) {
            $erreur = CAppUI::tr($e->getMessage());
        }
    }
}
$rejet = new CFactureRejet();
$rejet->praticien_id = $chir_id;
$rejet->file_name = CValue::getOrSession("file_name");
$rejet->num_facture = CValue::getOrSession("num_facture");
$rejet->date = CValue::getOrSession("date");
$rejet->motif_rejet = CValue::getOrSession("motif_rejet");
$rejet->statut = CValue::getOrSession("statut");
Exemplo n.º 18
0
$name_canonical = CValue::post("name_canonical");
$name_short = CValue::post("name_short");
$name_long = CValue::post("name_long");
$license = CValue::post("license");
$licenses = array("GNU GPL" => "GNU General Public License, see http://www.gnu.org/licenses/gpl.html", "OXOL" => "OXOL, see http://www.mediboard.org/public/OXOL");
$license = CValue::read($licenses, $license, $licenses["GNU GPL"]);
// Only alphanumeric caracters
$name_canonical = preg_replace("/[^\\w\\s]/", "", $name_canonical);
$name_short = CMbString::purifyHTML($name_short);
$name_long = CMbString::purifyHTML($name_long);
if (is_dir("modules/{$name_canonical}")) {
    CAppui::stepAjax("Module '{$name_canonical}' existe déjà", UI_MSG_ERROR);
}
$zip_path = "dev/sample_module.zip";
$destination = "tmp/sample_module";
if (false == ($files_count = CMbPath::extract($zip_path, $destination))) {
    CAppui::stepAjax("Impossible d'extraire l'archive '{$zip_path}'</div>", UI_MSG_ERROR);
}
rename("{$destination}/sample_module", "{$destination}/{$name_canonical}");
$path = "{$destination}/{$name_canonical}";
$files = array_merge(glob("{$path}/*"), glob("{$path}/classes/*"), glob("{$path}/locales/*"), glob("{$path}/templates/*"));
$translate = array('{NAME_CANONICAL}' => $name_canonical, '{NAME_SHORT}' => $name_short, '{NAME_LONG}' => $name_long, '{LICENSE}' => $license);
foreach ($files as $_file) {
    if (is_dir($_file)) {
        continue;
    }
    file_put_contents($_file, strtr(file_get_contents($_file), $translate));
}
rename("{$destination}/{$name_canonical}", "modules/{$name_canonical}");
CAppUI::setMsg("Module '{$name_canonical}' créé", UI_MSG_OK);
CAppUI::js("location.reload()");
Exemplo n.º 19
0
<?php

/**
 * $Id$
 *
 * @package    Mediboard
 * @subpackage System
 * @author     SARL OpenXtrem <*****@*****.**>
 * @license    GNU General Public License, see http://www.gnu.org/licenses/gpl.html
 * @version    $Revision$
 */
CCanDo::checkAdmin();
// Size in KB
$size = CValue::get("size", 100);
$size = min($size, 10 * 1024);
// Cap it to 10MB MAX
$big_file = CAppUI::getTmpPath("bandwidth_test/big.bin");
CMbPath::forceDir(dirname($big_file));
file_put_contents($big_file, str_pad("", 1024 * $size, "a"));
// Must be a "normal" char so that it's not url encoded
$empty_file = CAppUI::getTmpPath("bandwidth_test/empty.bin");
file_put_contents($empty_file, "");
Exemplo n.º 20
0
 /**
  * Force directories creation for file upload
  *
  * @return void
  */
 function forceDir()
 {
     // Check global directory
     if (!CMbPath::forceDir(self::$directory)) {
         trigger_error("Files directory is not writable : " . self::$directory, E_USER_WARNING);
         return;
     }
     // Checks complete file directory
     CMbPath::forceDir($this->_absolute_dir);
 }
if (null == ($remote_name = $clCconfig["remote_name"])) {
    CAppUI::stepAjax("Remote name not configured", UI_MSG_ERROR);
}
if (null == ($remote_url = $clCconfig["remote_url"])) {
    CAppUI::stepAjax("Remote URL not configured", UI_MSG_ERROR);
}
if (false === ($content = file_get_contents($remote_url))) {
    CAppUI::stepAjax("Couldn't connect to remote url", UI_MSG_ERROR);
}
// Check imported catalogue document
$doc = new CMbXMLDocument();
if (!$doc->loadXML($content)) {
    CAppUI::stepAjax("Document is not well formed", UI_MSG_ERROR);
}
$tmpPath = "tmp/dPlabo/import_catalogue.xml";
CMbPath::forceDir(dirname($tmpPath));
$doc->save($tmpPath);
$doc->load($tmpPath);
if (!$doc->schemaValidate("modules/{$m}/remote/catalogue.xsd")) {
    CAppUI::stepAjax("Document is not valid", UI_MSG_ERROR);
}
CAppUI::stepAjax("Document is valid", UI_MSG_OK);
// Check access to idSante400
$canSante400 = CModule::getCanDo("dPsante400");
if (!$canSante400->edit) {
    CAppUI::stepAjax("No permission for module 'dPsante400' or module not installed", UI_MSG_ERROR);
}
// Import catalogue
$cat = new SimpleXMLElement($content);
try {
    importCatalogue($cat);
 /**
  * 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;
 }
Exemplo n.º 23
0
 /**
  * @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();
     }
 }
Exemplo n.º 24
0
 /**
  * Construction
  * Directories initialisation
  * Standard data assignment
  *
  * @param string $dir The template directory
  */
 function __construct($dir = null)
 {
     global $version, $can, $m, $a, $tab, $g, $action, $actionType, $dialog, $ajax, $suppressHeaders, $uistyle;
     $rootDir = CAppUI::conf("root_dir");
     $extraPath = self::$extraPath;
     if (!$dir) {
         $root = $extraPath ? "{$rootDir}/{$extraPath}" : $rootDir;
         $dir = "{$root}/modules/{$m}";
     }
     $this->compile_dir = "{$rootDir}/tmp/templates_c/";
     // Directories initialisation
     $this->template_dir = "{$dir}/templates/";
     // Check if the cache dir is writeable
     if (!is_dir($this->compile_dir)) {
         CMbPath::forceDir($this->compile_dir);
     }
     // Delimiter definition
     $this->left_delimiter = "{{";
     $this->right_delimiter = "}}";
     // Default modifier for security reason
     $this->default_modifiers = array("@cleanField");
     // Register mediboard functions
     $this->register_block("tr", array($this, "tr"));
     $this->register_block("main", array($this, "main"));
     $this->register_function("mb_default", array($this, "mb_default"));
     $this->register_function("mb_ditto", array($this, "mb_ditto"));
     $this->register_function("mb_class", array($this, "mb_class"));
     $this->register_function("mb_value", array($this, "mb_value"));
     $this->register_function("mb_include", array($this, "mb_include"));
     $this->register_function("mb_script", array($this, "mb_script"));
     $this->register_function("thumb", array($this, "thumb"));
     $this->register_function("unique_id", array($this, "unique_id"));
     $this->register_function("mb_didacticiel", array($this, "mb_didacticiel"));
     $this->register_modifier("idex", array($this, "idex"));
     $this->register_modifier("conf", array($this, "conf"));
     $this->register_modifier("pad", array($this, "pad"));
     $this->register_modifier("json", array($this, "json"));
     $this->register_modifier("purify", array($this, "purify"));
     $this->register_modifier("markdown", array($this, "markdown"));
     $this->register_modifier("iso_date", array($this, "iso_date"));
     $this->register_modifier("iso_time", array($this, "iso_time"));
     $this->register_modifier("iso_datetime", array($this, "iso_datetime"));
     $this->register_modifier("rel_datetime", array($this, "rel_datetime"));
     $this->register_modifier("week_number_month", array($this, "week_number_month"));
     $this->register_modifier("const", array($this, "_const"));
     $this->register_modifier("static", array($this, "_static"));
     $this->register_modifier("static_call", array($this, "static_call"));
     $this->register_modifier("cleanField", array($this, "cleanField"));
     $this->register_modifier("stripslashes", array($this, "stripslashes"));
     $this->register_modifier("emphasize", array($this, "emphasize"));
     $this->register_modifier("ireplace", array($this, "ireplace"));
     $this->register_modifier("ternary", array($this, "ternary"));
     $this->register_modifier("trace", array($this, "trace"));
     $this->register_modifier("currency", array($this, "currency"));
     $this->register_modifier("percent", array($this, "percent"));
     $this->register_modifier("spancate", array($this, "spancate"));
     $this->register_modifier("float", array($this, "float"));
     $this->register_modifier("integer", array($this, "integer"));
     $this->register_modifier("decabinary", array($this, "decabinary"));
     $this->register_modifier("decasi", array($this, "decasi"));
     $this->register_modifier("module_installed", array($this, "module_installed"));
     $this->register_modifier("module_active", array($this, "module_active"));
     $this->register_modifier("JSAttribute", array($this, "JSAttribute"));
     $this->register_modifier("nozero", array($this, "nozero"));
     $this->register_modifier("ide", array($this, "ide"));
     $this->register_function("mb_token", array($this, "mb_token"));
     $modules = CModule::getActive();
     foreach ($modules as $mod) {
         $mod->canDo();
     }
     // Standard data assignment
     $this->assign("style", $uistyle);
     $this->assign("app", CAppUI::$instance);
     $this->assign("conf", CAppUI::conf());
     $this->assign("user", CAppUI::$instance->user_id);
     // shouldn't be necessary
     $this->assign("version", $version);
     $this->assign("suppressHeaders", $suppressHeaders);
     $this->assign("can", $can);
     $this->assign("m", $m);
     $this->assign("a", $a);
     $this->assign("tab", $tab);
     $this->assign("action", $action);
     $this->assign("actionType", $actionType);
     $this->assign("g", $g);
     $this->assign("dialog", $dialog);
     $this->assign("ajax", $ajax);
     $this->assign("modules", $modules);
     $this->assign("base_url", CApp::getBaseUrl());
     $this->assign("current_group", CGroups::loadCurrent());
     $this->assign("dnow", CMbDT::date());
     $this->assign("dtnow", CMbDT::dateTime());
     $this->assign("tnow", CMbDT::time());
 }
Exemplo n.º 25
0
<?php

/**
 * $Id: httpreq_do_add_insee.php 19219 2013-05-21 12:26:07Z phenxdesign $
 *
 * @package    Mediboard
 * @subpackage Patients
 * @author     SARL OpenXtrem <*****@*****.**>
 * @license    GNU General Public License, see http://www.gnu.org/licenses/gpl.html
 * @version    $Revision: 19219 $
 */
CCanDo::checkAdmin();
$sourcePath = "modules/dPpatients/INSEE/insee.tar.gz";
$targetDir = "tmp/insee";
$targetPath = "tmp/insee/insee.sql";
// Extract the SQL dump
if (null == ($nbFiles = CMbPath::extract($sourcePath, $targetDir))) {
    CAppUI::stepAjax("Erreur, impossible d'extraire l'archive", UI_MSG_ERROR);
}
CAppUI::stepAjax("Extraction de {$nbFiles} fichier(s)", UI_MSG_OK);
$ds = CSQLDataSource::get("INSEE");
if (null == ($lineCount = $ds->queryDump($targetPath, true))) {
    $msg = $ds->error();
    CAppUI::stepAjax("Erreur de requête SQL: {$msg}", UI_MSG_ERROR);
}
CAppUI::stepAjax("import effectué avec succès de {$lineCount} lignes", UI_MSG_OK);
 /**
  * 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;
 }
<?php

/**
 * $Id: ajax_edit_supervision_timed_picture.php 20428 2013-09-20 12:14:48Z phenxdesign $
 *
 * @package    Mediboard
 * @subpackage Patients
 * @author     SARL OpenXtrem <*****@*****.**>
 * @license    GNU General Public License, see http://www.gnu.org/licenses/gpl.html
 * @version    $Revision: 20428 $
 */
CCanDo::checkAdmin();
$supervision_timed_picture_id = CValue::getOrSession("supervision_timed_picture_id");
$picture = new CSupervisionTimedPicture();
$picture->load($supervision_timed_picture_id);
$picture->loadRefsNotes();
$picture->loadRefsFiles();
$tree = CMbPath::getTree("modules/dPpatients/images/supervision");
$smarty = new CSmartyDP();
$smarty->assign("picture", $picture);
$smarty->assign("tree", $tree);
$smarty->display("inc_edit_supervision_timed_picture.tpl");
Exemplo n.º 28
0
 private function _getFile($source_file, $destination_file = null)
 {
     $source_base = basename($source_file);
     if (!$destination_file) {
         $destination_file = "tmp/{$source_base}";
     }
     $destination_info = pathinfo($destination_file);
     CMbPath::forceDir($destination_info["dirname"]);
     if (!$this->connexion) {
         throw new CMbException("CSourceFTP-connexion-failed", $this->hostname);
     }
     // Download the file
     if (!@ftp_get($this->connexion, $destination_file, $source_file, constant($this->mode))) {
         throw new CMbException("CSourceFTP-download-file-failed", $source_file, $destination_file);
     }
     return $destination_file;
 }
 * @category Forms
 * @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();
$tmp_filename = $_FILES["import"]["tmp_name"];
$dom = new DOMDocument();
$dom->load($tmp_filename);
$xpath = new DOMXPath($dom);
if ($xpath->query("/mediboard-export")->length == 0) {
    CAppUI::js("window.parent.ExClass.uploadError()");
    CApp::rip();
}
$temp = CAppUI::getTmpPath("ex_class_import");
$uid = preg_replace('/[^\\d]/', '', uniqid("", true));
$filename = "{$temp}/{$uid}";
CMbPath::forceDir($temp);
move_uploaded_file($tmp_filename, $filename);
// Cleanup old files (more than 4 hours old)
$other_files = glob("{$temp}/*");
$now = time();
foreach ($other_files as $_other_file) {
    if (filemtime($_other_file) < $now - 3600 * 4) {
        unlink($_other_file);
    }
}
CAppUI::js("window.parent.ExClass.uploadSaveUID('{$uid}')");
CApp::rip();
Exemplo n.º 30
0
 /**
  * Install the library
  *
  * @return int The number of extracted files
  */
 function install()
 {
     $mbpath = $this->getRootPath();
     $pkgsDir = $mbpath . "libpkg";
     $libsDir = $mbpath . "lib";
     $filePath = "{$pkgsDir}/{$this->fileName}";
     // For libraries archive not contained in directory
     if ($this->extraDir) {
         $libsDir .= "/{$this->extraDir}";
     }
     return CMbPath::extract($filePath, $libsDir);
 }