Пример #1
0
 function getItem($id = NULL)
 {
     $id = $id ? $id : $this->getState('id');
     $this->setState('id', $id);
     $limit = $this->getState('limit') ? ' LIMIT ' . $this->getState('limit') : '';
     $q = $this->getListQuery($this->getStates());
     $item = new struct_core_alias($this->query($q->toString(), $q->getValues()));
     $theme_id = $item->themeid ? $item->themeid : 0;
     $theme2_id = $theme_id;
     if ($item->group_id) {
         $theme2_id = rad_dbpdo::query('SELECT theme_id FROM ' . RAD . 'themes WHERE theme_aliasid=? AND theme_folder=?', array($item->group_id, $item->themefolder));
         $theme2_id = !empty($theme2_id['theme_id']) ? (int) $theme2_id['theme_id'] : $theme_id;
     }
     if ($this->getState('join.aliasgroup')) {
         $table = new model_core_table('aliases');
         $ali_item = $table->getItem($id);
     }
     if (!$this->getState('without_joins')) {
         foreach ($this->queryAll('select params_presonal,inc_id,inc_name,inc_filename,controller,order_sort,rp_name,rp_id,id_module,m_name,ia.id as incinal_id, ia.params_hash as params_hash, 0 as is_ga ' . ($this->getState('join.original_params', false) ? ', ip_params AS original_params ' : '') . 'from ' . RAD . 'includes_in_aliases ia ' . 'inner join ' . RAD . 'includes on include_id=inc_id ' . 'inner join ' . RAD . 'modules m on m.m_id=id_module ' . 'inner join ' . RAD . 'positions p on position_id=p.rp_id ' . ($this->getState('join.original_params', false) ? ' left join ' . RAD . 'includes_params ip ON ip.ip_incid=ia.include_id ' : '') . 'where alias_id=' . $id . ' and ia.theme_id=' . $theme_id . (($this->getState('join.aliasgroup') and isset($ali_item) and $ali_item->group_id) ? ' UNION (' . 'select params_presonal,inc_id,inc_name,inc_filename,controller,order_sort,rp_name,rp_id,id_module,m_name,ia.id as incinal_id, ia.params_hash as params_hash, 1 as is_ga ' . ($this->getState('join.original_params', false) ? ', ip_params AS original_params ' : '') . 'from ' . RAD . 'includes_in_aliases ia ' . 'inner join ' . RAD . 'includes on include_id=inc_id ' . 'inner join ' . RAD . 'modules m on m.m_id=id_module ' . 'inner join ' . RAD . 'positions p on position_id=p.rp_id ' . ($this->getState('join.original_params', false) ? ' left join ' . RAD . 'includes_params ip ON ip.ip_incid=ia.include_id ' : '') . 'where alias_id=' . $ali_item->group_id . ' and ia.theme_id=' . $theme2_id . ')' : '') . ' order by rp_name, order_sort') as $idi) {
             $item->includes[] = new struct_core_include($idi);
             $item->includes[count($item->includes) - 1]->is_ga = (bool) $idi['is_ga'];
         }
     }
     if ($this->getState('join_description')) {
         $wlangid = $this->getState('ald_langid');
         $wlangid = $wlangid ? ' AND ald_langid=' . $wlangid : '';
         foreach ($this->queryAll('SELECT * FROM ' . RAD . 'aliases_description where ald_aliasid=' . $id . $wlangid) as $idd) {
             $item->description[$idd['ald_langid']] = new struct_core_aliases_description($idd);
         }
     }
     return $item;
 }
Пример #2
0
 /**
  * Simple log now text in param to DB table, also record in table time and other data
  * @param string text
  */
 public static function logerr($text)
 {
     if (rad_config::getParam('logger.loginDB', false)) {
         $flush = rad_input::getFlushInput();
         //die(rad_config::getParam('loader_class'));
         $flush['input'] = call_user_func(array(rad_config::getParam('loader_class'), 'getFlushData'));
         $flush = serialize($flush);
         $flush = str_replace('"', '\\"', $flush);
         rad_dbpdo::exec('insert into ' . RAD . 'logger(dt,flush,`text`)values(now(),"' . $flush . '","' . $text . '")');
     }
 }
Пример #3
0
 /**
  * Get URL using URL alias
  * @static
  * @param string $alias
  * @return false|string
  */
 public static function getUrlByAlias($alias)
 {
     $result = rad_dbpdo::query('SELECT item_type, item_id, lang_id FROM ' . RAD . 'url_aliases WHERE alias=:alias', array('alias' => $alias));
     if (empty($result['item_type'])) {
         return false;
     }
     $lng = rad_lang::getLangByID($result['lang_id']);
     rad_lang::changeLanguage($lng->lng_code);
     switch ($result['item_type']) {
         //List all supported item types here (if they don't need some special processing)
         case 'product':
             return rad_input::makeURL('alias=' . $result['item_type'] . '&p=' . $result['item_id'], false);
         default:
             return false;
             //For not supported item types
     }
 }
Пример #4
0
 /**
  * Check connection to sql server and connect ti server if not connected
  *
  * @param array mixed $config - global config
  * @param $driver_options - PDO driver options
  */
 protected static function check_connection($config = null, $driver_options = null)
 {
     if (!self::$dbc) {
         if (!$config) {
             $config =& $GLOBALS['config'];
         }
         if (!empty($config['db_config'])) {
             $db_config =& $config['db_config'];
         } else {
             throw new rad_exception('db_config not found at config!');
         }
         try {
             $db_config['db_port'] = $db_config['db_port'] ?: 3306;
             self::$dbc = new PDO("{$db_config['db_server']}:host={$db_config['db_hostname']};port={$db_config['db_port']};dbname={$db_config['db_databasename']}", $db_config['db_username'], $db_config['db_password'], $driver_options);
             self::$connected = true;
             self::exec(rad_config::getParam('setNames'));
         } catch (PDOException $e) {
             throw new rad_exception('PDO Error!: ' . $e->getMessage());
         }
     }
 }
Пример #5
0
 public static function ErrorHandler($errno, $errstr = '', $errfile = '', $errline = '', $errcontext = '')
 {
     if (!error_reporting()) {
         return;
     }
     //Error suppressed with @ operator
     $errorType = array(E_ERROR => 'ERROR', E_WARNING => 'WARNING', E_PARSE => 'PARSING ERROR', E_NOTICE => 'NOTICE', E_CORE_ERROR => 'CORE ERROR', E_CORE_WARNING => 'CORE WARNING', E_COMPILE_ERROR => 'COMPILE ERROR', E_COMPILE_WARNING => 'COMPILE WARNING', E_USER_ERROR => 'USER ERROR', E_USER_WARNING => 'USER WARNING', E_USER_NOTICE => 'USER NOTICE', E_STRICT => 'STRICT NOTICE', E_RECOVERABLE_ERROR => 'RECOVERABLE ERROR');
     if (count($errcontext)) {
         $errcontext = count($errcontext) . ' entries';
     }
     if (array_key_exists($errno, $errorType)) {
         $err = $errorType[$errno];
     } else {
         $err = 'CAUGHT EXCEPTION';
     }
     $message = "{$err}[{$errno}]: {$errstr} in file [{$errfile}] at line [{$errline}] context [{$errcontext}]";
     echo $message . "<hr>";
     if (rad_dbpdo::connected()) {
         rad_dblogger::logerr($message);
     } else {
         rad_dblogger::logerr2txt($message);
     }
 }
Пример #6
0
 function installSQL()
 {
     $ver = $this->request('version');
     if ($ver and $this->request('hash') == $this->hash()) {
         $update = rad_update::getInstance();
         $update->setUrl($this->_url);
         $update->setCurrentVersion($ver);
         if ($update->checkUpdates()) {
             $response = $update->getUpdatesList();
             if (!empty($response->sql)) {
                 $vars = array('RAD' => RAD);
                 foreach ($response->sql as $sql) {
                     $update->execSQL($sql->sql, $vars);
                     if (!empty($sql->inserted_id)) {
                         $vars[$sql->inserted_id] = rad_dbpdo::lastInsertId();
                     }
                 }
             }
             die('Done!');
         } else {
             die('Have no updates!');
         }
     } else {
         $this->redirect('404');
     }
 }
Пример #7
0
 /**
  * Executes the SQL with vars
  * @param string $sql
  * @param mixed $vars
  * @example
  * rad_update::execSQL('INSERT INTO @RAD@settings(fldName, fldValue, position, description, rtype, defValue)VALUES("test", "test",100,"description","modules","@value@")', array('value'=>'defValue'));
  * @return rad_update
  */
 public function execSQL($sql, $vars = null)
 {
     if (!empty($vars) and is_array($vars)) {
         foreach ($vars as $key => $value) {
             if (is_scalar($value)) {
                 $sql = str_replace('@' . $key . '@', $value, $sql);
             }
         }
     }
     echo $sql . "\r\n";
     rad_dbpdo::exec($sql);
     if ((int) rad_dbpdo::errorCode()) {
         echo "\r\n" . (int) rad_dbpdo::errorCode();
         print_r(rad_dbpdo::errorInfo());
         echo "\r\n";
     }
     return $this;
 }
Пример #8
0
 /**
  * Returns true if has alternative transaction
  * @return boolean
  */
 function hasActiveTransaction()
 {
     return rad_dbpdo::hasActiveTransaction();
 }
Пример #9
0
 /**
  * Returns the aliases with input_class name array
  * @return mixed array
  */
 public static function getAliasInputClasses()
 {
     $result = array();
     $res = rad_dbpdo::queryAll('SELECT alias,input_class from ' . RAD . 'aliases where input_class!=\'\';');
     foreach ($res as $id) {
         $result[$id['alias']] = $id['input_class'];
     }
     return $result;
 }
Пример #10
0
 public static function clearParams($params)
 {
     $result = false;
     if (count($params)) {
         foreach ($params as $id => $param) {
             $res = rad_dbpdo::queryAll('select * from ' . RAD . 'settings WHERE fldName LIKE :param', array('param' => $param));
             if (count($res)) {
                 foreach ($res as $id) {
                     $item = new struct_core_settings($id);
                     $item->remove();
                     $result = true;
                 }
             }
         }
     }
     return $result;
 }
Пример #11
0
 function save()
 {
     $model = rad_instances::get('model_core_lang');
     $id = (int) $this->request('lng_id');
     if ($id > 0) {
         $item = $model->getItem($id);
         $item->lng_id = $id;
     } else {
         $item = new struct_core_lang();
     }
     $item->lng_name = $this->request('lng_name');
     $item->lng_code = $this->request('lng_code');
     $item->lng_position = $this->request('lng_position');
     $item->lng_active = (int) $this->request('lng_active');
     $item->lng_mainsite = (int) $this->request('lng_mainsite');
     $item->lng_mainadmin = (int) $this->request('lng_mainadmin');
     $item->lng_maincontent = (int) $this->request('lng_maincontent');
     if ($id > 0) {
         $model->updateItem($item);
     } else {
         $model->insertItem($item);
         $id = rad_dbpdo::lastInsertId();
     }
     echo $this->request('lng_id') > 0 ? 0 : $id;
     exit;
 }
Пример #12
0
 /**
  * Gets all child ID's
  * @param $id mixed current category(s) ID
  * @return array id all child
  */
 function getAllChildId($id)
 {
     $model = rad_instances::get('model_coremenus_tree');
     $all = (array) $id;
     $cur = $all;
     while (count($cur) > 0) {
         $a = rad_dbpdo::queryAll('select tre_id from ' . RAD . 'tree where tre_pid in (' . join(',', $cur) . ') order by tre_position');
         $cur = array();
         foreach ($a as $i) {
             $cur[] = (int) $i['tre_id'];
         }
         $all = array_merge($all, $cur);
     }
     return $all;
 }
Пример #13
0
 /**
  *
  * @param string $social_id identifire from social site 
  * @param string $provider social site name
  * @return id user or false
  */
 public static function social_login($social_id, $provider, $sessionTime = NULL)
 {
     //$sessionTime =($sessionTime)?$sessionTime:rad_config::getParam('CookieExpireTime');
     $provider_row = 'u_' . $provider . '_id';
     $id = rad_dbpdo::query('SELECT u_id, u_email, u_pass, is_admin FROM ' . RAD . 'users WHERE `' . $provider_row . '`=:' . $provider_row, array($provider_row => $social_id));
     if (!empty($id['u_id'])) {
         self::$error_code = 0;
         self::$is_admin = $id['is_admin'];
         self::$user = rad_user::getUserByID($id['u_id']);
         rad_user::setUser(self::$user);
         $_SESSION['user_dump'] = self::$user;
         $_SESSION['user'] = $id['u_email'];
         $_SESSION['pass'] = md5($id['u_pass']);
         return self::$user;
     }
     self::$error_code = self::ERROR_WRONG_PASSWORD;
     return false;
 }
Пример #14
0
 /**
  * Load item by it primary key
  */
 public function load()
 {
     $pk = $this->getPrimaryKey();
     $this->CopyToStruct(rad_dbpdo::query('SELECT ' . implode(',', $this->getKeys('`', true)) . ' FROM ' . $this->_getTableName() . ' WHERE `' . $pk . '`=?', array($this->{$pk})));
     return $this;
 }
Пример #15
0
 /**
  * Check user by its username and password
  *
  * @var string login
  * @var string password
  *
  * @return struct_core_users
  */
 public static function checkUser(&$login = '', &$password = '')
 {
     $res = rad_dbpdo::query('select * from ' . RAD . 'users where u_login=:login and u_pass=:pass and u_active=1 limit 1', array('login' => $login, 'pass' => md5($password)));
     if (count($res)) {
         return new struct_core_users($res);
     } else {
         return null;
     }
 }
Пример #16
0
 /**
  * Query an a element and return the mixed array of rad_struct
  * @param string $result_struct
  * @param string $limit
  * @return mixed array of rad_struct
  */
 function getItems($result_struct, $limit = null)
 {
     $limit = $limit ? ' LIMIT ' . $limit : '';
     $result = null;
     $res = rad_dbpdo::queryAll($this->toString() . $limit, $this->getValues());
     if ($res) {
         foreach ($res as $id) {
             $result[] = new $result_struct($id);
         }
     }
     return $result;
 }
Пример #17
0
 /**
  * Get values for codes
  * @param array $codes
  * @return array code=>value
  */
 public static function getCodeValues($codes)
 {
     if (count($codes)) {
         $codes = array_unique($codes);
         $i = 0;
         $in = '';
         foreach ($codes as $idc => $code) {
             $in .= $i ? ',' : '';
             $in .= "'" . str_replace("'", "", $code) . "'";
             $i++;
         }
         $result = array();
         foreach (rad_dbpdo::queryAll('SELECT lnv_code,lnv_value from ' . RAD . 'langvalues where lnv_lang =? and lnv_code in(' . $in . ')', array(self::$langID)) as $idv) {
             $result[$idv['lnv_code']] = $idv['lnv_value'];
         }
         return $result;
     } else {
         //codes length of array is null
     }
 }