* @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/autoCatalog/inc/class.autoCatalogCategory.php'); include_once(MAIN_SOURCE_PATH.'/modules/autoCatalog/inc/url.php'); include_once(MAIN_SOURCE_PATH.'/modules/autoCatalog/lang/'.MAIN_LANG.'/lang.php'); /* class htmlAutoCatalog extends htmlControl { static function orderById() { Hl::registerJs(MAIN_PATH.'/tmp/view/autoCatalog/js/admin.js'); retrun self::orderBy( 'item_id' ); } }*/ class filedsSetAutoCatalog { //static $id = false; // адрес новости static function alias($v){ $v = trim($v); if ( empty($v) ){ throw new Exception('Ошибка: нужно заполнить поле "Адрес"!'); } return sys_translit($v); } static function title($v){ $v = trim($v); if ( empty($v) ){ throw new Exception('Ошибка: нужно заполнить поле "Название"!'); } return $v; } static function category_id($v){ if ( empty($v) ){ throw new Exception('Ошибка: нужно выбрать Категорию!'); } return $v; } /* static function name($v){ $v = trim($v); if ( empty($v) ){ throw new Exception('Ошибка: нужно заполнить поле "Имя"!'); } return $v; } static function email($v){ if ( !sys_is_mail($v) ){ throw new Exception('Ошибка: нужно заполнить поле "E-Mail"!'); } return $v; } static function status($v){ return !empty($v) ? 1 : 0; }*/ } class filedsGetAutoCatalog { static $__var = array(); // для хранения временных переменных static function upl_img($v){ $a = new upload_img('image1'); $a -> set_max_size( 5000000 ); $a -> set_file($v); $a -> set_path( 'catalog/img'); $a -> set_base( MAIN_URL.'/media/catalog/img'); return $a -> get('img1',1,'form[preview_image]'); } static function upl_img2($v){ $a = new upload_img('image2'); $a -> set_max_size( 5000000 ); $a -> set_file($v); $a -> set_path( 'catalog/img'); $a -> set_base( MAIN_URL.'/media/catalog/img'); return $a -> get('img2',20,'form[images]'); } static function categorySelect($v){ $s = new select_box(); $s -> selected_id($v); $s -> empty_record(true,0,'-Выберите категорию-'); foreach( autoCatalog::$categoryes as $k=>$v ) { $s -> set($k,$v); } return $s -> get(); } static function categoryName($v){ return autoCatalog::$categoryes[$v]; } static function mainSrc($v){ if ( empty($v) ){ return false; } return MAIN_URL.'/media/catalog/img/'.$v; } static function itemUrl($v){ if ( empty($v) ){ return false; } return MAIN_URL.'/gal/'.$v.'.html'; } static function imagesArray($v){ if ( empty($v) ){ return false; } $v = explode('|',$v); $images = array(); foreach( $v as $img ){ $images[] = self::mainSrc($img); } return $images; } } class autoCatalogQuery extends query{ var $fields_get = 'filedsGetAutoCatalog'; /** * @var string $alias Алиас для исплользования в mysql запросе */ public function __construct($alias){ global $MAIN_DB; $this -> set_table( $MAIN_DB -> prefix("autocatalog")); $this -> set_alias( $alias ); } public function where_id($id){ $id = intval($id); if ( empty($id) ){ return false; } return $this -> set_where( $this -> alias.'.item_id',$id); } public function where_category($id){ if ( empty($id) ){ return false; } return $this -> set_where( $this -> alias.'.category_id',$id); } public function where_alias($v){ if ( false===sys_is_alias($v) ){ return false; } return $this -> set_where( $this -> alias.'.alias',$v); } public function orderby_id($v){ return $this -> set_orderby($this -> alias.'.item_id',$v); } public function orderby_sort($v){ return $this -> set_orderby($this -> alias.'.sort',$v); } public function orderby_title($v){ return $this -> set_orderby($this -> alias.'.title',$v); } public function orderby_rand($v){ return $this -> set_orderby('RAND()'); } public function orderby_time_add($v){ return $this -> set_orderby($this -> alias.'.time_add',$v); } } // end class class autoCatalog extends objects{ public $table = "autocatalog"; public $key = "item_id"; public $fields = 'filedsSetAutoCatalog'; static $categoryes = array('auto_v'=>'Внешний тюнинг', 'auto_vn'=>'Тюнинг интерьера', 'aero'=>'Аэрография'); static function query($a){ return new autoCatalogQuery($a); } static function existsAutoCatalog($alias){ $u = self::query('u'); //$u -> set_debug(1); $u -> where_alias($alias); $u -> get('COUNT(*)'); list($count) = $u -> row(); if ( $count>0 ){ return true; } return false; } static function create(){ return new self(0,array() ); } static function searchById($id){ $u = self::query('u'); if ( !$u -> where_id($id) ){ return FALSE; } if ( !$u -> get('u.*') ){ return FALSE; } if ( $u -> get_count_rows()==0 ){ return FALSE; } return new self( $id,$u -> row() ); } } // end class ?>