* @copyright: Copyright (c) 2010, Bunzia Alexander * @version: 1.0 * @license: http://www.gnu.org/copyleft/gpl.html GNU/GPL * @package: HiLo CMS */ include_once(MAIN_SOURCE_PATH.'/inc/class.query.php'); include_once(MAIN_SOURCE_PATH.'/inc/class.objects.php'); /* include_once(MAIN_SOURCE_PATH.'/modules/admin/cache/config.php'); include_once(MAIN_SOURCE_PATH.'/modules/admin/inc/url.php'); include_once(MAIN_SOURCE_PATH.'/modules/admin/lang/'.MAIN_LANG.'/lang.php'); */ class filedsSetPlugins { /* static function n_alias($v,$id){ if ( empty($v) ){ throw new Exception('Ошибка: нужно заполнить поле "Адрес"!'); } if ( !sys_is_alias($v) ){ throw new Exception('Ошибка: адрес содержит запрещённые символы"!'); } if ( plugins::is_exists($v,$id) ){ throw new Exception('Ошибка: материал с таким адресом уже существует"!'); } return $v; } */ } class filedsGetPlugins { static function module_list($v){ include_once(MAIN_SOURCE_PATH.'/inc/class.html.php'); $l = new module_select_box(); return $l -> get($v); } static function lang_list($v){ $plugins = array('ru'=>'ru','en'=>'en'); $s = new select_box(); $s -> selected_id($$v); $s -> empty_record(false); foreach( $plugins as $k=>$v ){ $s -> set($k,$v); } return $s -> get(); } } class pluginsQuery extends query{ var $fields_get = 'filedsGetPlugins'; /** * @var string $alias Алиас для исплользования в mysql запросе */ public function __construct($alias){ $this -> set_table(MAIN_PLUGINS_TBL ); $this -> set_alias($alias); } public function include_module($alias,$cols=false){ global $MAIN_DB; $this -> include_table( MAIN_MODULES_TBL ,$alias,'m_id',$cols ); } public function where_id($v){ $v = intval($v); if ( empty($v) ){ return FALSE; } return $this -> set_where( $this -> alias.'.plugin_id',$v); } public function where_name($v){ return $this -> set_where( $this -> alias.'.name',$v); } public function where_module($v){ return $this -> set_where( $this -> alias.'.path',$v); } public function orderby_id($v){ return $this -> set_orderby($this -> alias.'.plugin_id',$v); } /** * Произвольная сортировка */ public function orderby_rand(){ return $this -> set_orderby('RAND()'); } } // end class pluginsQuery class plugins extends objects{ public $table = "system_plugins"; public $key = "plugin_id"; public $fields = 'filedsSetPlugins'; //STATIC static function load_id($id){ $m = new pluginsQuery('m'); if ( !$m -> where_id($id) ){ return FALSE; } $m -> get('*'); if ( !$m -> get_count_rows() ){ return FALSE; } return new plugins($id,$m -> row()); } static function load_name($v){ $m = new pluginsQuery('m'); if ( !$m -> where_name($v) ){ return FALSE; } $m -> get('*'); if ( !$m -> get_count_rows() ){ return FALSE; } return new plugins($id,$m -> row()); } static function create(){ //global $MAIN_DB; //$sql = "INSERT INTO ".$MAIN_DB -> prefix( self::$table)." (".self::$key.") VALUES(0)"; //$MAIN_DB -> query($sql); //$id = $MAIN_DB -> insert_id(); return new plugins(0,array() ); } public function update(){ global $MAIN_DB; /* if ( !empty($this -> last_error ) ){ return false; }*/ if ( sizeof($this -> set_info)==0 ){ sys_error(500,E_EMPTY_ARRAY); } $sql = array(); foreach( $this -> set_info as $k=>$v ){ $sql[]="`$k`='".sys_in_sql($v)."'"; } $sql = " UPDATE ".MAIN_PLUGINS_TBL." SET ".implode(',',$sql)." WHERE ".$this -> key."='".$this -> key_value."'"; if ( !empty($this -> debug) ){ die($sql); } $MAIN_DB -> query($sql); //plugins::search_index($this -> key_value); // формируем новую запись в таблицу поиска return $this -> key_value; } public function insert(){ global $MAIN_DB; if ( sizeof($this -> set_info)==0 ){ sys_error(500,E_EMPTY_ARRAY); } $sql = array(); foreach( $this -> set_info as $k=>$v ){ $sql[]="`$k`='".sys_in_sql($v)."'"; } $sql = "INSERT INTO ".MAIN_PLUGINS_TBL." SET ".implode(',',$sql).""; if ( !empty($this -> debug) ){ die($sql); } $MAIN_DB -> query($sql); $id = $MAIN_DB -> insert_id(); return $id; } public function delete(){ global $MAIN_DB; $sql = "DELETE FROM ".MAIN_PLUGINS_TBL." WHERE ".$this -> key."='".$this -> key_value."'"; $MAIN_DB -> query($sql); return TRUE; } } // end class ?>