/**
  * Connect to a AS400 DB2 SQL server via ODBC driver
  * 
  * @throws Error on misconfigured or anavailable server
  * 
  * @return void
  */
 static function connect()
 {
     if (self::$dbh) {
         return;
     }
     $config = CAppUI::conf("sante400");
     if (null == ($dsn = $config["dsn"])) {
         trigger_error("Data Source Name not defined, please configure module", E_USER_ERROR);
         CApp::rip();
     }
     // Fake data source for chrono purposes
     CSQLDataSource::$dataSources[$dsn] = new CMySQLDataSource();
     $ds =& CSQLDataSource::$dataSources[$dsn];
     $ds->dsn = $dsn;
     self::$chrono =& CSQLDataSource::$dataSources[$dsn]->chrono;
     self::$chrono->start();
     $prefix = $config["prefix"];
     try {
         self::$dbh = new PDO("{$prefix}:{$dsn}", $config["user"], $config["pass"]);
         self::$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
     } catch (PDOException $e) {
         mbTrace("cauguht failure on first datasource");
         if (null == ($dsn = $config["other_dsn"])) {
             throw $e;
         }
         self::$dbh = new PDO("{$prefix}:{$dsn}", $config["user"], $config["pass"]);
         self::$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
     }
     self::$chrono->stop("connection");
     self::traceChrono("connection");
 }
 /**
  * @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;
 }
 /**
  * @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();
     }
 }
/**
 * Fonction utilitaire pour la sauvegarde rapide d'un object avec génération du message
 *
 * @param CMbObject $object Objet à enregister
 *
 * @return void
 */
function storeObject($object)
{
    $title = $object->_id ? "-msg-modify" : "-msg-create";
    if ($msg = $object->store()) {
        CAppUI::setMsg($msg, UI_MSG_ERROR);
        echo CAppUI::getMsg();
        CApp::rip();
    }
    CAppUI::setMsg(CAppUI::tr(get_class($object) . $title), UI_MSG_OK);
}
/**
 * Redirect to the last page
 *
 * @return void
 */
function redirect()
{
    if (CValue::post("ajax")) {
        echo CAppUI::getMsg();
        CApp::rip();
    }
    $m = CValue::post("m");
    $tab = CValue::post("tab");
    CAppUI::redirect("m={$m}&tab={$tab}");
}
 /**
  * check if the sejour need to be unlock
  *
  * @param CSejour $sejour
  *
  * @return bool
  */
 static function checkForSejour($sejour, $modal = true)
 {
     if (!self::canAccess($sejour)) {
         $smarty = new CSmartyDP("modules/admin");
         $smarty->assign("sejour", $sejour);
         $smarty->assign("bris", new CBrisDeGlace());
         $smarty->assign("modale", $modal);
         $smarty->display("need_bris_de_glace.tpl");
         CApp::rip();
     }
     return true;
 }
 /**
  * Effectue la redirection d'après la règle
  *
  * @return bool
  */
 function applyRedirection()
 {
     $scheme = "http" . (isset($_SERVER["HTTPS"]) ? "s" : "");
     $host = $_SERVER["SERVER_NAME"];
     $port = $_SERVER["SERVER_PORT"] == 80 ? "" : ":{$_SERVER['SERVER_PORT']}";
     $params = $_SERVER["REQUEST_URI"];
     $this->parseUrl();
     if ($this->_complete_to["scheme"] == $scheme && $this->_complete_to["host"] == $host) {
         return true;
     }
     if ($this->from == "*") {
         header("Location: {$this->to}{$params}");
         CApp::rip();
     }
     if ($this->_complete_from["scheme"] == $scheme && $this->_complete_from["host"] == $host) {
         $scheme = $this->_complete_to["scheme"];
         $host = $this->_complete_to["host"];
         $redirection = $scheme . "://" . $host;
         $redirection .= $params;
         header("Location: {$redirection}");
         CApp::rip();
     }
     return false;
 }
 function doRedirect($demandeSynchro = false)
 {
     if ($this->ajax) {
         if ($this->synchro) {
             $del = CValue::post("del", 0);
             $tmp_repas_id = CValue::post("_tmp_repas_id", 0);
             $msgSystem = CAppUI::getMsg();
             $smarty = new CSmartyDP("modules/dPrepas");
             $smarty->assign("del", $del);
             $smarty->assign("tmp_repas_id", $tmp_repas_id);
             $smarty->assign("demandeSynchro", $demandeSynchro);
             $smarty->assign("msgSystem", $msgSystem);
             $smarty->assign("callBack", $this->callBack);
             if ($demandeSynchro) {
                 $smarty->assign("object", $this->_old);
             }
             $smarty->display("add_del_repas_offline.tpl");
         }
         CApp::rip();
     }
     if ($this->redirect !== null) {
         CAppUI::redirect($this->redirect);
     }
 }
Beispiel #9
0
 /**
  * @see parent::store()
  */
 function store()
 {
     if ($this instanceof CSejour || $this instanceof COperation) {
         global $can;
         $this->loadOldObject();
         $this->completeField("cloture_activite_1", "cloture_activite_4", 'codes_ccam');
         if (!$can->admin && CAppUI::conf("dPsalleOp CActeCCAM signature") && ($this->cloture_activite_1 || $this->cloture_activite_4) && $this->fieldModified("codes_ccam") && strcmp($this->codes_ccam, $this->_old->codes_ccam)) {
             $new_code = substr($this->codes_ccam, strlen($this->_old->codes_ccam) + 1);
             $code_ccam = new CDatedCodeCCAM($new_code);
             $code_ccam->getRemarques();
             $activites = $code_ccam->getActivites();
             if (isset($activites[1]) && $this->cloture_activite_1) {
                 CAppUI::setMsg("Impossible de rajouter un code : l'activité 1 est clôturée", UI_MSG_ERROR);
                 echo CAppUI::getMsg();
                 CApp::rip();
             }
             if (isset($activites[4]) && $this->cloture_activite_4) {
                 CAppUI::setMsg("Impossible de rajouter un code : l'activité 4 est clôturée", UI_MSG_ERROR);
                 echo CAppUI::getMsg();
                 CApp::rip();
             }
         }
     }
     // Standard store
     if ($msg = parent::store()) {
         return $msg;
     }
     if ($this->_delete_actes && $this->_id) {
         if ($msg = $this->deleteActes()) {
             return $msg;
         }
     }
     return null;
 }
 /**
  * Make JavaScript callback
  *
  * @return void
  */
 function doCallback()
 {
     $messages = CAppUI::$instance->messages;
     echo CAppUI::getMsg();
     $fields = $this->_obj->getProperties();
     $fields["_guid"] = $this->_obj->_guid;
     $fields["_class"] = $this->_obj->_class;
     foreach ($messages as &$_level) {
         $_keys = array_map("utf8_encode", array_keys($_level));
         $_values = array_map("utf8_encode", array_values($_level));
         $_level = array_combine($_keys, $_values);
     }
     $fields["_ui_messages"] = $messages;
     $id = $this->_obj->_id ? $this->_obj->_id : 0;
     if ($this->callBack) {
         CAppUI::callbackAjax($this->callBack, $id, $fields);
     } else {
         $guid = "{$this->className}-{$id}";
         CAppUI::callbackAjax("Form.onSubmitComplete", $guid, $fields);
     }
     if (!CAppUI::$mobile) {
         CApp::rip();
     }
 }
 /**
  * Stream document for object
  *
  * @param CCompteRendu $compte_rendu Document
  * @param CMbObject    $object       Object
  * @param string       $factory      Factory name
  *
  * @return void
  */
 static function streamDocForObject($compte_rendu, $object, $factory = null)
 {
     ob_clean();
     $template = new CTemplateManager();
     $source = $compte_rendu->getFullContentFromModel();
     $object->fillTemplate($template);
     $template->renderDocument($source);
     $htmltopdf = new CHtmlToPDF($factory);
     $htmltopdf->generatePDF($template->document, 1, $compte_rendu, new CFile());
     CApp::rip();
 }
 /**
  * Output the content to the standard output
  * 
  * @return void
  */
 static function output($options = array())
 {
     if (self::$_aio) {
         $path = CAppUI::getTmpPath("embed-" . md5(uniqid("", true)));
         if (self::$_aio === "savefile") {
             $str = self::allInOne($path);
             file_put_contents("{$path}/index.html", $str);
             $zip_path = "{$path}.zip";
             CMbPath::zip($path, $zip_path);
             header("Content-Type: application/zip");
             header("Content-Disposition: attachment; filename=\"" . basename($zip_path) . "\";");
             header("Content-Transfer-Encoding: binary");
             header("Content-Length: " . filesize($zip_path));
             readfile($zip_path);
             unlink($zip_path);
             CMbPath::remove($path);
             CApp::rip();
         } else {
             self::allInOne(null, $options);
         }
     } else {
         // Flush zero-ifies ob_get_length
         self::$flushed_output_length += ob_get_length();
         ob_end_flush();
     }
 }
/**
 * $Id: do_prescription_export.php 19460 2013-06-07 09:39:26Z kgrisel $
 *
 * @package    Mediboard
 * @subpackage Labo
 * @author     SARL OpenXtrem <*****@*****.**>
 * @license    GNU General Public License, see http://www.gnu.org/licenses/gpl.html
 * @version    $Revision: 19460 $
 */
function redirect()
{
    echo CAppUI::getMsg();
    CApp::rip();
}
Beispiel #14
0
 /**
  * Display an AJAX step, and exit on error messages
  *
  * @param string $msg  The internationalized message
  * @param int    $type [optional] Message type as a UI constant
  * @param mixed  $_    [optional] Any number of printf-like parameters to be applied
  *
  * @return void
  * @todo Switch parameter order, like stepMessage()
  * @todo Rename to ajaxNsg()
  */
 static function stepAjax($msg, $type = UI_MSG_OK, $_ = null)
 {
     $args = func_get_args();
     $msg = CAppUI::tr($msg, array_slice($args, 2));
     $msg = CMbString::purifyHTML($msg);
     $class = self::getErrorClass($type);
     echo "\n<div class='{$class}'>{$msg}</div>";
     if ($type == UI_MSG_ERROR) {
         CApp::rip();
     }
 }
Beispiel #15
0
 /**
  * Correction de problèmes de dom
  * 
  * @param string $str source html
  * 
  * @return string 
  */
 function fixBlockElements($str)
 {
     $xml = new DOMDocument('1.0', 'iso-8859-1');
     $str = CMbString::convertHTMLToXMLEntities($str);
     $str = CHtmlToPDF::cleanWord($str);
     // Suppression des caractères de contrôle
     $from = array(chr(3), chr(7));
     $to = array("", "");
     $str = str_replace($from, $to, $str);
     $xml->loadXML(utf8_encode($str));
     $html =& $xml->getElementsByTagName("body")->item(0);
     if (is_null($html)) {
         $html =& $xml->firstChild;
     }
     if (is_null($html)) {
         CAppUI::stepAjax("CCompteRendu-empty-doc");
         CApp::rip();
     }
     $xpath = new DOMXpath($xml);
     $elements = $xpath->query("*/div[@id='body']");
     if (!is_null($elements)) {
         foreach ($elements as $_element) {
             CHtmlToPDF::removeAlign($_element);
         }
     }
     // Solution temporaire pour les problèmes de mise en page avec domPDF
     while ($elements = $xpath->query("//span[@class='field']")) {
         if ($elements->length == 0) {
             break;
         }
         foreach ($elements as $_element) {
             foreach ($_element->childNodes as $child) {
                 /** @var DOMElement $child */
                 $_element->parentNode->insertBefore($child->cloneNode(true), $_element);
             }
             $_element->parentNode->removeChild($_element);
         }
     }
     $this->recursiveRemove($html);
     $this->recursiveRemoveNestedFont($html);
     $this->resizeTable($html);
     // Suppression des sauts de pages dans l'entête et le pied de page
     $elements = $xpath->query("//div[@id='header']//hr[@class='pagebreak']");
     if (!is_null($elements)) {
         foreach ($elements as $_element) {
             $_element->parentNode->removeChild($_element);
         }
     }
     $elements = $xpath->query("//div[@id='footer']//hr[@class='pagebreak']");
     if (!is_null($elements)) {
         foreach ($elements as $_element) {
             $_element->parentNode->removeChild($_element);
         }
     }
     $str = $xml->saveHTML();
     $str = preg_replace("/<br>/", "<br/>", $str);
     return $str;
 }
/**
 * import the patient file
 *
 * @param string   $file        path to the file
 * @param int      $start       start int
 * @param int      $count       number of iterations
 * @param resource $file_import file for report
 *
 * @return null
 */
function importFile($file, $start, $count, $file_import)
{
    $fp = fopen($file, 'r');
    $csv_file = new CCSVFile($fp);
    $csv_file->column_names = $csv_file->readLine();
    if ($start == 0) {
        $start++;
    } elseif ($start > 1) {
        $csv_file->jumpLine($start);
    }
    $group_id = CGroups::loadCurrent()->_id;
    $treated_line = 0;
    while ($treated_line < $count) {
        $treated_line++;
        $patient = new CPatient();
        $_patient = $csv_file->readLine(true);
        if (!$_patient) {
            CAppUI::stepAjax('Importation terminée', UI_MSG_OK);
            CApp::rip();
        }
        $patient->bind($_patient);
        $patient->loadFromIPP($group_id);
        if ($patient->_id) {
            $start++;
            continue;
        }
        $nom = $_patient['nom'] ? $_patient['nom'] : $_patient['nom_jeune_fille'];
        if (!$patient->nom) {
            if ($patient->nom_jeune_fille) {
                $patient->nom = $patient->nom_jeune_fille;
            } else {
                CMbDebug::log("Ligne #{$start} : Pas de nom");
                $start++;
                continue;
            }
        }
        $naissance = null;
        if ($patient->naissance) {
            $naissance = preg_replace('/(\\d{2})\\/(\\d{2})\\/(\\d{4})/', '\\3-\\2-\\1', $patient->naissance);
            $patient->naissance = $naissance;
        }
        $patient->repair();
        if (!$patient->naissance) {
            CMbDebug::log($_patient);
            CMbDebug::log("Ligne #{$start} : Date de naissance invalide ({$_patient['naissance']})");
            $start++;
            continue;
        }
        $patient->loadMatchingPatient();
        if (!$patient->_id) {
            $patient->bind($_patient);
            $patient->nom = $nom;
            $patient->naissance = $naissance;
            $patient->tel = preg_replace("/[^0-9]/", "", $patient->tel);
            $patient->tel_autre = preg_replace("/[^0-9]/", "", $patient->tel_autre);
            $patient->sexe = strtolower($patient->sexe);
            $patient->repair();
            if ($msg = $patient->store()) {
                CMbDebug::log($patient, null, true);
                CMbDebug::log("Ligne #{$start} :{$msg}");
                $start++;
                continue;
            }
        }
        $ipp = CIdSante400::getMatch($patient->_class, CPatient::getTagIPP($group_id), $patient->_IPP, $patient->_id);
        if ($ipp->_id && $ipp->id400 != $patient->_IPP) {
            CMbDebug::log("Ligne #{$start} : Ce patient possède déjà un IPP ({$ipp->id400})");
            $start++;
            continue;
        }
        if (!$ipp->_id) {
            if ($msg = $ipp->store()) {
                CMbDebug::log("Ligne #{$start} :{$msg}");
                $start++;
                continue;
            }
        }
        CAppUI::setMsg('CPatient-msg-create', UI_MSG_OK);
    }
    echo CAppUI::getMsg();
}
Beispiel #17
0
 /**
  * Close the parameter list definition and provides inspection information on info mode
  *
  * @return void
  */
 public static function checkin()
 {
     if (CValue::request("enslave")) {
         CView::enforceSlave();
     }
     if (!CValue::request("info")) {
         return;
     }
     // Dump properties on raw
     if (CValue::request("raw")) {
         echo json_encode(self::$props);
         CApp::rip();
     }
     // Show properties
     $smarty = new CSmartyDP("modules/system");
     $smarty->assign("props", self::$props);
     $smarty->display("view_info.tpl");
     CApp::rip();
 }
 * @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();
 function loadHashAssoc($query)
 {
     $cur = $this->exec($query);
     $cur or CApp::rip();
     oci_fetch_all($cur, $rows, 0, -1, OCI_FETCHSTATEMENT_BY_ROW + OCI_ASSOC);
     $hashlist = array();
     foreach ($rows as $hash) {
         $key = reset($hash);
         $hashlist[$key] = $hash;
     }
     $this->freeResult($cur);
     return $hashlist;
 }