admin_control_snippets.php 5 KB
<?php
/**
* @author:  Bunzia Alexander <nifus@mail.ru> <http://www.weblancer.net/users/nifus/>
* @copyright: Copyright (c) 2010, Bunzia Alexander
* @version: 1.0
* @license: http://www.gnu.org/copyleft/gpl.html GNU/GPL
* @package HiLo CMS
*/

class admin_control_snippets{
	private $error = false;
	private $act = 'index';
	private $JsHttpRequest = false;
	private $table = 'system_snippets';
	  
	public function __construct(){
	global $MAIN_PAGE;
		define('M_PATH',MAIN_SOURCE_PATH.'/modules/'.$MAIN_PAGE -> dirname() );
		define('M_URL',MAIN_SOURCE_URL.'/modules/'.$MAIN_PAGE -> dirname() );
		define('A_CHARSET', $MAIN_PAGE -> charset() );
		include_once(M_PATH.'/inc/url.php');
		include_once(M_PATH.'/inc/class.snippets.php');
		include_once(MAIN_SOURCE_PATH.'/inc/class.html.php');
		include(MAIN_SOURCE_PATH.'/ext/ajax/JsHttpRequest.php');
		$this -> JsHttpRequest = new JsHttpRequest( A_CHARSET );
		$this -> act = !empty($_REQUEST['act']) ? $_REQUEST['act'] : $this -> act;
		$GLOBALS['_RESULT']['id_request'] = !empty($_REQUEST['id_request']) ? $_REQUEST['id_request'] : 0;
		
		preg_match('#^'.$MAIN_PAGE -> dirname().'_(.*)$#iUs',$_REQUEST['p_name'],$res);
		$this -> path =$res[1];
		$this -> path_tmpl = M_PATH.'/tmpl/'.$this -> path;
	}
	
	public function get(){
		$func = $this -> act;
		if ( !method_exists($this ,$func) ){
			sys_error(ERROR_404);
		}
		return $this -> $func();
	}
	

	private function index(){
		$t = new PHPTAL( $this -> path_tmpl.'/main.html' );
		$p = new snippetsQuery('f');
		$p -> where_main_rows();
		$p -> orderby_id('DESC');
		$p -> get('f.*,snippet_id as lang_links',false);
		$t -> rows = $p -> rows();
		
		  //  список модулей
		  
		 include_once(MAIN_SOURCE_PATH.'/modules/admin/inc/class.modules.php');
		
		$s = new select_box();
	  $s -> empty_record(true,0);
	  $m = modules::query('m');
	  $m -> where_active(1);
	  $m -> get('m_path,m_name');
	  while( $row = $m -> row() ){
		  $s -> set($row['m_path'],$row['m_name']);
		}		
		$t -> module_list = $s -> get();
		
		return $t -> execute();
	}
	

	private function ajax_reload(){
		sys_block_disable();
		$t = new PHPTAL(  $this -> path_tmpl.'/inc/tmpl_row.html' );
		$t -> execute = true;
		$p = new snippetsQuery('f');
		//$p -> set_debug(1);
		$p -> where_main_rows();
		$p -> where_module($_POST['filter_module']);
		
		$p -> orderby_id('DESC');
		$p -> get('f.*,snippet_id as lang_links',false);
		$t -> rows = $p -> rows();
		$GLOBALS['_RESULT']['content'] = $t -> execute();
		exit();
	}


	private function ajax_delete(){
		sys_block_disable();
		$m = snippets::load_id($_POST['id']);
		if ( false===$m ){
			die( A_EMPTY_ID );
		}
		$m -> delete();
		exit();
	}
	

	private function ajax_edit(){
		sys_block_disable();
		$p = new snippetsQuery('p');
		if ( !$p -> where_id($_GET['id']) ){
			$row = array( 'lang_list'=>filedsGetSnippets::lang_list() );
		}else{
			$p -> get('*, lang as lang_list');
			$row = $p ->  row();
		}
		$t = new PHPTAL( $this -> path_tmpl.'/edit.html' );
		$e = html_control::editor('codemirror');
		$e -> set_name('desc');
		$e -> set_attr('cols',10);
		$t -> editor = $e -> show();
		
		$t -> row = $row ;
		$t -> lang_edit = false;  // редактируем ключевую запись
		$t -> link_id =$_GET['id'];
		$t -> lang = !empty($_GET['lang']) ? $_GET['lang'] : MAIN_LANG;
		echo '<?xml version="1.0" encoding="UTF-8"?><body><title>Редактировать</title><content><![CDATA['.$t -> execute().']]></content></body>';
		
		exit();
	}
	

	
	
	
	
	private function ajax_save(){
		sys_block_disable();
		$p = snippets::load_id($_POST['id']);
		if ( false===$p ){
			$create=true;
			$p =  snippets::create();
		}
		//$p -> set_debug(1);
		foreach( $_POST['form'] as $k=>$v ){
		  $p -> set($k,$v);
		}
		$p -> set('snippet',$_POST['snippet']);
    $id = ($create===true) ? $p -> insert() : $p -> update();
    if ( $create===true && empty($_POST['form']['link_id']) ){
		    //$p -> set_debug(1);
		    $p -> set('link_id',$id);
        $p -> update();
		 }
		exit();
	}
	
	////
	
	private function ajax_lang_edit(){
		sys_block_disable();
		$t = new PHPTAL( $this -> path_tmpl.'/edit.html' );
		$t -> lang_edit = true;  // редактируем ключевую запись
		$p = new snippetsQuery('p');
		//$p -> set_debug(1);
		$p -> where_link($_GET['id']);
		$p -> where_lang($_GET['lang']);
		$p -> get('*, lang as lang_list');
		if ( $p-> get_count_rows()!=0 ){
		  $row = $p ->  row();
		}else{
		  //  получим данные родителя
		  $p = new snippetsQuery('p');
		  //$p -> set_debug(1);
		  $p -> where_id($_GET['id']);
		  $p -> get('link_id,f_func,m_path');
		  $row = $p ->  row();
			
		}
		$t -> row = $row;
		$t -> lang = !empty($_GET['lang']) ? $_GET['lang'] : MAIN_LANG;
		$t -> link_id = $_GET['id'];
		
		$e = html_control::editor('codemirror');
		$e -> set_name('desc');
		$e -> set_attr('cols',10);
		$t -> editor = $e -> show();
		echo '<?xml version="1.0" encoding="UTF-8"?><body><title>'.M_ADMIN_SP_ADD_EDIT_PAGE.'</title><content><![CDATA['.$t -> execute().']]></content></body>';
		exit();
	}

}

?>