Esempio n. 1
0
 static function getInstance()
 {
     if (null == self::$_instance) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }
 /**
  * Магический метод получения любых классов
  *
  * @param $name
  * @param array $params
  * @throws Exception
  */
 public static function __callStatic($name, $params = array())
 {
     /**
      * Получаем имя класса из имени функции
      */
     $className = "C" . CUtils::strRight($name, "get");
     if (!class_exists($className)) {
         throw new Exception("В приложении не объявлен класс " . $className);
     }
     /**
      * @var CActiveModel $simpleClass
      */
     $simpleClass = new $className();
     $table = $simpleClass->getRecord()->getTable();
     $id = $params[0];
     /**
      * Попробуем сначала получить из кэша
      */
     $keySeek = $table . "_" . $id;
     if (CApp::getApp()->cache->hasCache($keySeek)) {
         return CApp::getApp()->cache->get($keySeek);
     }
     $ar = CActiveRecordProvider::getById($table, $id);
     if (!is_null($ar)) {
         $obj = new $className($ar);
         CApp::getApp()->cache->set($keySeek, $obj, 60);
         return $obj;
     }
 }
Esempio n. 3
0
 public static function linkCss($link)
 {
     if (strstr($link, 'css/') == 0) {
         $link = CApp::settings("APPLICATION")->template_path . $link;
     }
     return '<link href="' . $link . '" type="text/css" rel="stylesheet">';
 }
Esempio n. 4
0
 public static function getInstance()
 {
     if (is_null(self::$_instance)) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }
 public function run()
 {
     $this->ts = time();
     $this->plat = CApp::app()->tty()->getParam('plat', 1);
     $this->action = CApp::app()->tty()->getParam('action', 'exchange');
     $this->auto = CApp::app()->tty()->getParam('auto');
     $this->begin_ts = strtotime(CApp::app()->tty()->getParam('begin', date('Y-m-d H:i:s', $this->ts - $this->timeSlice)));
     $this->end_ts = strtotime(CApp::app()->tty()->getParam('end', date('Y-m-d H:i:s', $this->ts)));
     //自动补数据(补单)
     if ($this->auto) {
         $this->begin_ts = strtotime(date('Ymd', strtotime("-1 day")) . ' 00:00:00');
         $this->end_ts = strtotime(date('Ymd', strtotime("-1 day")) . ' 23:59:59');
     }
     //不能跨月   否则取当天时间
     if (date('Ym', $this->begin_ts) != date('Ym', $this->end_ts)) {
         $this->end_ts = strtotime(date('Ymd', $this->begin_ts) . ' 23:59:59');
         $this->flag = false;
     }
     /*
     if ($this->action == 'union_exchange')
     {
     	$this->op_id = CApp::app()->tty()->getParam('op_id');
     }
     */
     if (!array_key_exists($this->plat, $this->curl)) {
         die('Error plat!');
     }
     $this->handleData();
 }
Esempio n. 6
0
 public function __construct()
 {
     $_dbConf = CApp::app()->getConf('Db');
     foreach ($_dbConf as $identify => $conf) {
         $this->_Db[$identify] = CDb::createDb($conf['host'], $conf['user'], $conf['pwd'], $conf['dbName']);
     }
 }
Esempio n. 7
0
 /**
  * Синглтон приложения
  *
  * @static
  * @param array $config
  * @return CApp
  */
 public static function createApplication(array $config)
 {
     if (is_null(self::$_inst)) {
         self::$_inst = new CApp($config);
     }
     return self::$_inst;
 }
 /**
  * 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");
 }
Esempio n. 9
0
 /**
  * Change prat usernames to prat ids
  *
  * @return bool
  */
 protected function swapPratIds()
 {
     $ds = CSQLDataSource::get("std");
     CApp::setTimeLimit(1800);
     $user = new CUser();
     // Changement des chirurgiens
     $query = "SELECT id_chir\r\n        FROM plagesop\r\n        GROUP BY id_chir";
     $listPlages = $ds->loadList($query);
     foreach ($listPlages as $plage) {
         $where["user_username"] = "******" . $plage["id_chir"] . "'";
         $user->loadObject($where);
         if ($user->user_id) {
             $query = "UPDATE plagesop\r\n            SET chir_id = '{$user->user_id}'\r\n            WHERE id_chir = '{$user->user_username}'";
             $ds->exec($query);
             $ds->error();
         }
     }
     //Changement des anesthésistes
     $query = "SELECT id_anesth\r\n         FROM plagesop\r\n         GROUP BY id_anesth";
     $listPlages = $ds->loadList($query);
     foreach ($listPlages as $plage) {
         $where["user_username"] = "******" . $plage["id_anesth"] . "'";
         $user->loadObject($where);
         if ($user->user_id) {
             $query = "UPDATE plagesop\r\n            SET anesth_id = '{$user->user_id}'\r\n            WHERE id_anesth = '{$user->user_username}'";
             $ds->exec($query);
             $ds->error();
         }
     }
     return true;
 }
 /**
  * Получить настройку по псевдониму или ключевому полю
  *
  * @param $key
  * @return CSetting
  */
 public static function getSetting($key)
 {
     if (is_string($key)) {
         $key = strtoupper($key);
     }
     $cacheKey = CACHE_APPLICATION_SETTINGS . '_' . $key;
     if (!CApp::getApp()->cache->hasCache($cacheKey)) {
         $found = false;
         if (is_string($key)) {
             foreach (CActiveRecordProvider::getWithCondition(TABLE_SETTINGS, "UPPER(alias) = '" . $key . "'")->getItems() as $item) {
                 $found = true;
                 $setting = new CSetting($item);
                 CApp::getApp()->cache->set(CACHE_APPLICATION_SETTINGS . '_' . $setting->getId(), $setting);
                 CApp::getApp()->cache->set($cacheKey, $setting);
             }
         } elseif (is_numeric($key)) {
             $item = CActiveRecordProvider::getById(TABLE_SETTINGS, $key);
             if (!is_null($item)) {
                 $found = true;
                 $setting = new CSetting($item);
                 CApp::getApp()->cache->set(CACHE_APPLICATION_SETTINGS . '_' . $setting->alias, $setting);
                 CApp::getApp()->cache->set($cacheKey, $setting);
             }
         }
         if (!$found) {
             CApp::getApp()->cache->set($cacheKey, null);
         }
     }
     return CApp::getApp()->cache->get($cacheKey);
 }
Esempio n. 11
0
 static function mine($parent_class)
 {
     $classes = CApp::getChildClasses($parent_class);
     $limit = CAppUI::conf("dataminer_limit");
     foreach ($classes as $_class) {
         $miner = new $_class();
         $report = $miner->mineSome($limit, "mine");
         $dt = CMbDT::dateTime();
         echo "<{$dt}> Miner: {$_class}. Success mining count is '" . $report["success"] . "'\n";
         if (!$report["failure"]) {
             echo "<{$dt}> Miner: {$_class}. Failure mining counts is '" . $report["failure"] . "'\n";
         }
         $miner = new $_class();
         $report = $miner->mineSome($limit, "remine");
         $dt = CMbDT::dateTime();
         echo "<{$dt}> Reminer: {$_class}. Success remining count is '" . $report["success"] . "'\n";
         if (!$report["failure"]) {
             echo "<{$dt}> Reminer: {$_class}. Failure remining counts is '" . $report["failure"] . "'\n";
         }
         $miner = new $_class();
         $report = $miner->mineSome($limit, "postmine");
         $dt = CMbDT::dateTime();
         echo "<{$dt}> Postminer: {$_class}. Success postmining count is '" . $report["success"] . "'\n";
         if (!$report["failure"]) {
             echo "<{$dt}> Postminer: {$_class}. Failure postmining counts is '" . $report["failure"] . "'\n";
         }
     }
 }
 /**
  * @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;
 }
Esempio n. 13
0
 public function update($arrayNewTranslate, $arrayOldTranslate)
 {
     $arrDiff = array_diff($arrayNewTranslate, $arrayOldTranslate);
     $arrIntersect = array_intersect($arrayNewTranslate, $arrayOldTranslate);
     $arrResult = array_merge($arrDiff, $arrIntersect);
     CApp::setTranslateArray($arrResult);
     return $arrResult;
 }
Esempio n. 14
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}";
 }
Esempio n. 15
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));
 }
 /**
  * @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();
     }
 }
Esempio n. 17
0
 public function deleteAction($id)
 {
     if ($_SESSION["userRole"] == CApp::settings("USER_ROLES")->ADMIN && $_GET["view"] == "delete" && !empty($_GET["id"])) {
         $model = new UserModel();
         $model->deleteById($id);
         CApp::redirect(CApp::getLink(array("controller" => "user", "view" => "index")));
     } else {
         CApp::redirect("/");
     }
 }
/**
 * 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);
}
 public function actionGetObject($id)
 {
     $cache_id = $this->taxonomy . "_item_" . $id;
     if (is_null(CApp::getApp()->cache->get($cache_id))) {
         $taxonomy = CTaxonomyManager::getTaxonomy($this->taxonomy);
         $term = $taxonomy->getTerm($id);
         CApp::getApp()->cache->set($cache_id, $term, 30);
     }
     return CApp::getApp()->cache->get($cache_id);
 }
/**
 * 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}");
}
Esempio n. 21
0
 public function __construct($class, $msg = NULL)
 {
     if ($msg != NULL) {
         $this->message = $msg . " в файле " . $this->file . " в строке #" . $this->line;
     }
     if (CApp::settings("APPLICATION")->settings['logs_on']) {
         $log = new CLog();
         $log->logging($class, $this->message);
     }
 }
Esempio n. 22
0
 /**
  * Сериализовать бин на диск
  *
  * @param CStatefullBean $bean
  */
 public function serializeBean(CStatefullBean $bean)
 {
     if (is_a(CApp::getApp()->getApp(), "CCacheDummy")) {
         if (file_exists($this->cacheDir . $bean->getBeanId())) {
             unlink($this->cacheDir . $bean->getBeanId());
         }
         file_put_contents($this->cacheDir . $bean->getBeanId(), serialize($bean));
     } else {
         CApp::getApp()->cache->set("bean_" . $bean->getBeanId(), $bean);
     }
 }
Esempio n. 23
0
 public static function createCApp()
 {
     define('__CUU__', str_replace(array('//', '\\'), array('/', '/'), dirname(__FILE__)));
     define('__CORE__', __CUU__ . '/Core');
     define('__EXT__', __CUU__ . '/Ext');
     define('__LIB__', __CUU__ . '/Lib');
     define('__VIEW__', __CUU__ . '/View');
     //set_include_path(get_include_path().PATH_SEPARATOR.__CORE__);
     spl_autoload_register(array('CApp', 'autoLoad'));
     return self::$_app = CFactory::SFactory('CApp');
 }
Esempio n. 24
0
 /**
  * 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;
 }
Esempio n. 25
0
 public function cacheClearAction()
 {
     $dirname = $_SERVER["DOCUMENT_ROOT"] . "/cache/";
     $dir = opendir($dirname);
     while (($file = readdir($dir)) !== false) {
         if (is_file($dirname . "/" . $file)) {
             unlink($dirname . "/" . $file);
         }
     }
     $path = CApp::getLink(array("controller" => "site", "view" => "settings"));
     CApp::redirect($path);
 }
Esempio n. 26
0
 protected function render($view, $controller = "site", $arrResult = array(), $template = TEMPLATE)
 {
     $cache = new CCache(604800);
     $flagCache = false;
     if (!$cache->cacheExists(CApp::getHashCurPage()) && false) {
         $flagCache = true;
         $cache->startCache();
     }
     include_once $_SERVER["DOCUMENT_ROOT"] . "/engine/templates/" . $template . "/header.php";
     include_once $_SERVER["DOCUMENT_ROOT"] . "/engine/templates/" . $template . "/views/" . strtolower($controller) . "/" . $view . ".php";
     include_once $_SERVER["DOCUMENT_ROOT"] . "/engine/templates/" . $template . "/footer.php";
     if ($flagCache) {
         $cache->writeCache(filterGetValue(CApp::getHashCurPage()));
     }
 }
Esempio n. 27
0
 public function getRouter()
 {
     $sControler = $this->getParam($this->_c);
     if (strpos($sControler, '/') > 0) {
         list($controller, $action) = explode('/', $sControler);
         if (!$controller && CApp::app()->getConf('defaultController')) {
             $controller = CApp::app()->getConf('defaultController');
         }
         if (!$action && CApp::app()->getConf('defaultAction')) {
             $action = CApp::app()->getConf('defaultAction');
         }
         return array('controller' => $controller . 'Controller', 'action' => $action);
     }
     return array();
 }
Esempio n. 28
0
 public static function getInstance()
 {
     if (self::$instance == null) {
         $dsn = CApp::settings('APPLICATION')->db['dsn'];
         $user = CApp::settings('APPLICATION')->db['db_user'];
         $pass = CApp::settings('APPLICATION')->db['db_pass'];
         self::$instance = new CModelConnectDB($dsn, $user, $pass);
         return self::$instance->getDBConnection();
     } else {
         /**
          * Using the one connection to Database for all
          *
          * if it need, it may return false to deny for all other except one
          */
         return false;
     }
 }
Esempio n. 29
0
 protected function render($view, $controller = "site", $arrResult = [], $template = null)
 {
     if ($template == null) {
         $template = CApp::settings('APPLICATION')->templates['default'];
     }
     $cache = new CCache(604800);
     $flagCache = false;
     if (!$cache->cacheExists(CApp::getHashCurPage()) && CApp::settings("APPLICATION")->settings['cache_on']) {
         $flagCache = true;
         $cache->startCache();
     }
     include $_SERVER["DOCUMENT_ROOT"] . "/engine/templates/" . $template . "/header.php";
     include $_SERVER["DOCUMENT_ROOT"] . "/engine/templates/" . $template . "/views/" . strtolower($controller) . "/" . $view . ".php";
     include $_SERVER["DOCUMENT_ROOT"] . "/engine/templates/" . $template . "/footer.php";
     if ($flagCache) {
         $cache->writeCache(filterGetValue(CApp::getHashCurPage()));
     }
 }
Esempio n. 30
0
 public function __construct()
 {
     $_dbConf = CApp::app()->getConf('Db');
     $_Dbs = array();
     if (!$_dbConf) {
         return NULL;
     }
     foreach ($_dbConf as $identify => $conf) {
         switch (!empty($conf['lib'])) {
             case 1:
                 $LibClass = 'C' . ucfirst(strtolower($conf['lib']));
                 $_Dbs[$identify] = $this->_Dbs[$identify] = $LibClass::createDb($conf);
             default:
                 $_Dbs[$identify] = $this->_Dbs[$identify] = CMysql::createDb($conf);
                 break;
         }
     }
     $this->_DbConf = array_shift($_dbConf);
     return !empty($this->_Dbs) ? $this->_Db = array_shift($_Dbs) : NULL;
 }