* @copyright: Copyright (c) 2010, Bunzia Alexander * @version: 1.0 * @license: http://www.gnu.org/copyleft/gpl.html GNU/GPL */ include_once(MAIN_SOURCE_PATH.'/modules/admin/lang/'.MAIN_LANG.'/lang.php'); include_once(MAIN_SOURCE_PATH.'/inc/class.objects.php'); include_once(MAIN_SOURCE_PATH.'/inc/class.query.php'); class filedsSetPages { //static $id = false; // адрес новости static function f_name($v){ if ( empty($v) ){ throw new Exception('Ошибка: название страницы не указано'); } return $v; } static function p_name($v){ if ( empty($v) ){ throw new Exception('Ошибка: программный файл не указан'); } if ( !pages::check_page($v) ){ throw new Exception('Ошибка: программный файл имеет неправильное название'); } return $v; } static function m_dirname($v){ if ( empty($v) ){ throw new Exception('Ошибка: каталог не указан'); } return $v; } static function m_id($v){ $v = intval($v); if ( empty($v) ){ throw new Exception('Ошибка: номер модуля не указан'); } return $v; } static function f_func($v){ if ( empty($v) ){ throw new Exception('Ошибка:не указано название функции'); } return $v; } static function f_access($v){ return !empty($v) ? 1 : 0; } static function f_active($v){ return !empty($v) ? 1 : 0; } static function f_tmpl($v){ if ( empty($v) ){ throw new Exception('Ошибка: шаблон не выбран'); } if ( !file_exists(MAIN_SOURCE_PATH.'/tmpl/files/'.$v) ){ throw new Exception('Ошибка: шаблон не существует'); } return $v; } } class filedsGetPages { static $__var = array(); // для хранения временных переменных // проверяем, нет ли новых модулей. Если есть, то заносим их в базу static function new_modules(){ if ( !$handle = opendir(MAIN_SOURCE_PATH.'/modules') ) { return false; } $result = array(); // перебираем всё в папке modules while (false !== ($path = readdir($handle) ) ) { // ищем модуль path в базе данных $m = new modulesQuery('m'); if ( !$m -> where_path($path) ){ continue; } //$m -> set_debug(1); $m -> get('COUNT(*)'); list($exists) = $m -> row(); if ( !empty($exists) ){ continue; } if ( !file_exists(MAIN_SOURCE_PATH.'/modules/'.$path.'/info.php') ){ continue; } include_once(MAIN_SOURCE_PATH.'/modules/'.$path.'/lang/'.MAIN_LANG.'/lang.php'); include_once(MAIN_SOURCE_PATH.'/modules/'.$path.'/info.php'); if ( !is_array($m_info) || sizeof($m_info)==0 ){ continue; } $pages = array(); foreach( $m_info['page'] as $page => $name ){ $pages[]=array('name'=>$name); } $result[]=array('m_name'=>$m_info['name'],'m_path'=>$path,'pages'=>$pages); } return $result; } static function active_modules_ul($v){ include_once(MAIN_SOURCE_PATH.'/modules/admin/inc/class.module.php'); $s = new select_box(); $s -> empty_record(true,0); $m = new modulesQuery('m'); $m -> where_active(1); $m -> get('m_path,m_name'); while( $row = $m -> row() ){ $s -> set($row['m_path'],$row['m_name']); } return $s -> get(); } static function module_title($v){ if ( self::$__var['modulte_title']==$v ){ return FALSE; }else{ self::$__var['modulte_title']=$v; return TRUE; } } static function lang_links($v){ if ( false === MAIN_MULTILANG ){ return false; } $langs = explode(',',MAIN_LANGS); $result = array(); foreach( $langs as $l ){ $q = new pagesQuery('q'); //$q -> set_debug(1); $q -> where_link($v); $q -> where_lang($l); $q -> get('COUNT(*)'); list($count) = $q -> row(); $result[] = array('lang'=>$l,'exists'=> (( $count ) ? 1 : 0) ); } return $result; } static function lang_list($v){ if ( false === MAIN_MULTILANG ){ return false; } $langs = explode(',',MAIN_LANGS); $s = new select_box(); $s -> selected_id($v); $s -> empty_record(false); foreach( $langs as $lng ) { $s -> set($lng,$lng); } return $s -> get(); } static function count_blocks($v,$row){ global $MAIN_DB; $sql = "SELECT COUNT(*) FROM ".MAIN_PLB_TBL." WHERE t_id='$v'"; list($count) = $MAIN_DB -> fetch_array( $MAIN_DB -> query($sql) ); return $count; } // вернём список групп для которых разрешён доступ к файлу v static function groups($v,$row){ global $MAIN_DB; $groups = array(); $sql = "SELECT g_id FROM ".MAIN_GRP_PAGES_LINK_TBL." WHERE f_id='$v'"; $res = $MAIN_DB -> query($sql); while( list($g_id) = $MAIN_DB -> fetch_array($res) ){ $groups[]=$g_id; } return $groups; } static function group_list($v){ $gps = self::groups($v); $groups = users::groups(); $s = new select_box(); $s -> selected_id($gps); $s -> empty_record(false); foreach( $groups AS $g_id => $g_name ){ $s -> set($g_id,$g_name ); } return $s -> get(); } static function tmpl_list($v){ // список папок include_once(MAIN_SOURCE_PATH.'/modules/admin/inc/class.tmpl.php'); $t = new tmpl_q('t'); //$t -> set_debug(1); $t -> get('t.t_id,t.t_name'); $s = new select_box(); $s -> selected_id($v); $s -> empty_record(false); while( list($t_id,$t_name) = $t -> row() ){ $s -> set($t_id,$t_name); } return $s -> get(); } } class pagesQuery extends query{ var $fields_get = 'filedsGetPages'; public function __construct($alias){ $this -> set_table(MAIN_PAGES_TBL ); $this -> set_alias($alias); } public function include_modules($alias,$cols=''){ $this -> include_table(MAIN_MODULES_TBL,$alias,'m_id',$cols ); return true; } public function include_tmpl($alias,$cols=''){ $this -> include_table(MAIN_TMPL_TBL,$alias,'t_id',$cols ); return true; } public function where_id($v){ $v = intval($v); if ( empty($v) ){ return FALSE; } return $this -> set_where( $this -> alias.'.f_id',$v); } public function where_pname($v){ if ( !pages::check_page($v) ){ return FALSE; } return $this -> set_where( $this -> alias.'.p_name',$v); } public function where_ffunc($v){ return $this -> set_where( $this -> alias.'.f_func',$v); } public function where_link($v){ if ( false===MAIN_MULTILANG ){ return false; } $v = intval($v); if ( empty($v) ){ return false; } return $this -> set_where( $this -> alias.'.link_id',$v); } public function where_lang($v){ if ( false===MAIN_MULTILANG ){ return false; } if ( empty($v) ){ return false; } return $this -> set_where( $this -> alias.'.lang',$v); } public function where_mpath($m_path){ if ( empty($m_path) || !sys_check_module_name($m_path) ){ return false; } return $this -> set_where( $this -> alias.'.m_dirname',$m_path); } public function where_mid($v){ $v = intval($v); if ( empty($v) ){ return FALSE; } return $this -> set_where( $this -> alias.'.m_id',$v); } public function where_main_rows(){ if ( false===MAIN_MULTILANG ){ return false; } return $this -> set_anothe_where( $this -> alias.'.f_id='.$this -> alias.'.link_id'); } public function orderby_mid($v){ $a = $this -> get_alias(MAIN_MODULES_TBL); return $this -> set_orderby($a.'.m_id',$v); } public function orderby_active($v){ return $this -> set_orderby($this -> alias.'.f_active',$v); } public function orderby_fname($v){ return $this -> set_orderby($this -> alias.'.f_name',$v); } public function orderby_ftitle($v){ return $this -> set_orderby($this -> alias.'.f_title',$v); } public function orderby_fid($v){ return $this -> set_orderby($this -> alias.'.f_id',$v); } } // end pagesQuery class pages extends objects{ public $table = "system_pages"; public $key = "f_id"; public $fields = 'filedsSetPages'; public function id(){ return $this -> info['f_id']; } public function module(){ return $this -> info['m_dirname']; } /** * Удаление страницы * * @return: bool */ /*public function delete(){ global $MAIN_DB; $id = $this -> id(); if ( empty($id) ){ sys_error(ERROR_500,A_EMPTY_ID); } $sql = "DELETE FROM ".MAIN_PAGES_TBL." WHERE f_id='$id'"; $MAIN_DB -> query($sql); // чистим таблицу связей страницы и групп пользователей $sql = "DELETE FROM ".MAIN_GRP_PAGES_LINK_TBL." WHERE f_id='$id'"; $MAIN_DB -> query($sql); return TRUE; } */ /*public function update(){ global $MAIN_DB; if ( false===$this -> main_key ){ $this -> make_error(ERROR_500,A_EMPTY_ID); } if ( !empty($this -> error) ){ return $this -> error; } if ( sizeof($this -> set_info)==0 ){ $this -> make_error(ERROR_500,A_EMPTY_ARRAY); } $sql = array(); foreach( $this -> set_info as $k=>$v ){ $sql[]="`$k`='".sys_in_sql($v)."'"; } $sql = " UPDATE ".MAIN_PAGES_TBL." SET ".implode(',',$sql)." WHERE f_id='".$this -> main_key."'"; if ( !empty($this -> debug) ){ die($sql); } $MAIN_DB -> query($sql); return true; }*/ /*public function insert(){ global $MAIN_DB; // при инициализации значений произошла ошибка if ( false!==$this -> error() ){ return $this -> error(); } if ( sizeof($this -> set_info)==0 ){ $this -> make_error(ERROR_500,A_EMPTY_ARRAY); } // так как запись новая, нужно проверить уникальные ключи на повторение if ( pages::exists_page($this -> set_info['p_name']) ){ $this -> make_error(ERROR_MESSAGE, sprintf(A_EXISTS_PAGE,$this -> set_info['p_name'])); return false; } if ( pages::exists_func($this -> set_info['f_func']) ){ $this -> make_error(ERROR_MESSAGE, sprintf(A_EXISTS_FUNC,$this -> set_info['f_func'])); return false; } $sql = array(); foreach( $this -> set_info as $k=>$v ){ $sql[]="`$k`='".sys_in_sql($v)."'"; } $sql = " INSERT INTO ".MAIN_PAGES_TBL." SET ".implode(',',$sql).""; if ( !empty($this -> debug) ){ die($sql); } $MAIN_DB -> query($sql); return $MAIN_DB -> insert_id(); }*/ public function set_group($array){ global $MAIN_DB; if ( $this -> key_value ===false ){ $this -> make_error(ERROR_500); exit(); } if ( !is_array($array) ){ $array = array(); } $sql = "DELETE FROM ".MAIN_GRP_PAGES_LINK_TBL." WHERE f_id='".$this -> key_value."'"; $MAIN_DB -> query($sql); foreach( $array AS $g_id ){ $g_id = intval($g_id); if ( empty($g_id) ){ continue; } $sql = " INSERT INTO ".MAIN_GRP_PAGES_LINK_TBL." SET f_id='".$this -> key_value."', g_id='$g_id'"; $MAIN_DB -> query($sql); } } static function exists_page($v){ global $MAIN_DB; $u = new pagesQuery('m'); $u -> where_pname($v); $u -> get('COUNT(*)'); list($count) = $u -> row(); if ( $count>0 ){ return true; } return false; } static function exists_func($v){ global $MAIN_DB; $u = new pagesQuery('m'); $u -> where_ffunc($v); $u -> get('COUNT(*)'); list($count) = $u -> row(); if ( $count>0 ){ return true; } return false; } //STATIC static function check_page($text) { if ( empty($text) ){ return FALSE; } if ( preg_match('#[^a-z0-9-_]#iU',$text) ){ return FALSE; } return TRUE; } static function load_id($id){ $m = new pagesQuery('m'); if ( !$m -> where_id($id) ){ return false; } $m -> get('*'); if ( !$m -> get_count_rows() ){ return false; } return new pages($id,$m -> row()); } static function load_pname($id){ $m = new pagesQuery('m'); if (!$m -> where_pname($id) ){ return false; } $m -> get('*'); if ( !$m -> get_count_rows() ){ return false; } $row = $m -> row(); return new pages($row['f_id'],$m -> row()); } static function create(){ return new pages( array(0,'f_id'=>0) ); } // добавляем языки static function add_langs($page_id) { if ( false===MAIN_MULTILANG ) { return false; } $p = pages::load_id($page_id); if ( false===$p ) { return false; } $langs = explode(',',MAIN_LANGS); foreach( $langs as $l ){ // основной язык уже добавлен if ( $l==MAIN_LANG ) { continue; } //проверяем, вдруг язык уже добавлен $pq = new pagesQuery('p'); $pq -> where_link($p -> link_id); $pq -> where_lang($l); $pq -> get('COUNT(*)'); list($count) = $pq -> row(); if ( $count>0 ){ continue; } $new_page = pages::create(); $new_page -> set('lang',$l); $new_page -> set('link_id',$p -> link_id ); $new_page -> set('p_name',$p -> p_name ); $new_page -> set('m_dirname',$p -> m_dirname ); $new_page -> set('f_func',$p -> f_func ); $new_page -> set('f_encoding',$p -> f_encoding ); //$new_page -> set('f_locale',$p -> f_locale ); $new_page -> set('f_active',$p -> f_active ); $new_page -> set('m_id',$p -> m_id ); $new_page -> set('f_access',$p -> f_access ); $new_page -> set('t_id',$p -> t_id); $new_page -> set('t_id',$p -> t_id); $new_page -> insert(); } } } ?>