Пример #1
0
 /**
  * Show files (table view)
  *
  * @param   integer $id_area Area ID
  * @param   string  $category category
  * @param   string  $subcategory subcategory
  * @param   integer	$type type index
  * @param   integer	$pp pagination index
  * @return  void
  */
 public function index($id_area = 2, $category = '-', $subcategory = '-', $xtype = -1, $pp = 0, $str = '')
 {
     // load dictionary
     $this->dict->get_wordarray(array('files'));
     $amod = new Area_model();
     list($id_area, $areas) = $amod->get_my_areas($id_area);
     // get page
     $page = $this->get_page('files');
     $navbar = array($this->site->get_bredcrumb($page));
     $category = urldecode($category);
     $subcategory = urldecode($subcategory);
     // content
     $view = new X4View_core('container');
     $view->content = new X4View_core('files/file_list');
     $view->content->page = $page;
     $view->content->navbar = $navbar;
     $view->content->id_area = $id_area;
     $view->content->xtype = $xtype;
     $view->content->category = $category;
     $view->content->subcategory = $subcategory;
     $view->content->str = $str;
     $mod = new File_model();
     $view->content->items = X4Pagination_helper::paginate($mod->get_files($id_area, $category, $subcategory, $xtype, $str), $pp);
     $view->content->file_path = $mod->file_path;
     // area switcher
     $view->content->areas = $areas;
     // type switcher
     $view->content->types = $mod->get_types();
     // files category switcher
     $view->content->categories = $mod->get_cat($id_area);
     // files subcategory switcher
     $view->content->subcategories = $mod->get_subcat($id_area, $category);
     $view->render(TRUE);
 }
Пример #2
0
 /**
  * Show modules
  *
  * @param   integer $id_area Area ID
  * @param   string  $area Area name
  * @return  void
  */
 public function index($id_area = 2, $area = 'public')
 {
     // load dictionary
     $this->dict->get_wordarray(array('modules'));
     $area = new Area_model();
     list($id_area, $areas) = $area->get_my_areas($id_area);
     $view = new X4View_core('container');
     $view->content = new X4View_core('modules/module_list');
     // get page
     $page = $this->get_page('modules');
     $navbar = array($this->site->get_bredcrumb($page));
     $view->content->navbar = $navbar;
     $view->content->page = $page;
     $view->content->id_area = $id_area;
     $view->content->area = $area->get_by_id($id_area);
     // get installed and installable plugins
     $mod = new X4Plugin_model();
     $view->content->plugged = $mod->get_installed($id_area);
     $chk = AdmUtils_helper::get_ulevel(1, $_SESSION['xuid'], '_module_install');
     $view->content->pluggable = !$chk || $chk->level < 4 ? array() : $mod->get_installable($id_area);
     // area switcher
     $view->content->areas = $areas;
     $view->render(TRUE);
 }
Пример #3
0
<?php

defined('ROOT') or die('No direct script access.');
/**
 * X3 CMS - A smart Content Management System
 *
 * @author		Paolo Certo
 * @copyright	(c) CBlu.net di Paolo Certo
 * @license		http://www.gnu.org/licenses/agpl.htm
 * @package		X3CMS
 */
// x3flags area_uninstall
$mod_name = 'x3flags';
$required = array();
$sql = array();
$a = new Area_model();
$area = $a->get_by_id($plugin->id_area);
$sql[] = 'DELETE FROM param WHERE xrif = \'' . $mod_name . '\' AND id_area = ' . $area->id;
$sql[] = 'DELETE FROM dictionary WHERE what = \'' . $mod_name . '\' AND area = \'' . $area->name . '\'';
$sql[] = 'DELETE FROM modules WHERE id = ' . intval($id);
Пример #4
0
    /**
     * New / Edit article form
     * The form is simplified if site use simple editing
     *
     * @param   integer $id_area Area ID
     * @param   string	$lang Language code
     * @param   integer	$code_context Context code
     * @param   string	$bid, the unique ID of articles
     * @param   integer	$id_page Page ID (for simple editing)
     * @param   boolean	$duplicate Duplicate article resetting bid
     * @return  void
     */
    public function edit($id_area = 2, $lang = '', $code_context = 0, $bid = 0, $id_page = 0, $duplicate = 0)
    {
        // set language
        $lang = empty($lang) ? X4Route_core::$lang : $lang;
        // load dictionaries
        $this->dict->get_wordarray(array('form', 'articles'));
        // referer
        $qs = X4Route_core::get_query_string();
        $referer = isset($qs['ref']) ? $qs['ref'] : '';
        $mod = new Article_model();
        // simple editing
        if ($id_page && $bid != 'x3') {
            $bid = $mod->get_bid_by_id_page($id_page);
        }
        // get object
        $item = $bid && $bid != 'x3' ? $mod->get_by_bid($bid) : new Article_obj($id_area, $lang, $code_context);
        // dedicated page when called from composer
        if ($bid == 'x3') {
            $item->id_page = $id_page;
        }
        // if duplicate reset bid
        if ($duplicate) {
            $item->name = _COPY_OF . ' ' . $item->name;
            $item->bid = $mod->get_new_bid();
        }
        // build the form
        $fields = array();
        $fields[] = array('label' => null, 'type' => 'html', 'value' => '<div class="band double-inner-pad clearfix"><div id="left-box" class="four-fifth md-three-fourth sm-two-third xs-one-whole">');
        $fields[] = array('label' => null, 'type' => 'hidden', 'value' => $referer, 'name' => 'from');
        $fields[] = array('label' => null, 'type' => 'hidden', 'value' => $item->bid, 'name' => 'bid');
        $lmod = new Language_model();
        if ($id_page == 0 || $bid == 'x3') {
            // advanced editing
            // area
            $amod = new Area_model();
            $fields[] = array('label' => null, 'type' => 'html', 'value' => '<div class="band clearfix"><div class="one-fourth sm-one-half pad-right xs-one-whole xs-pad-none">');
            $fields[] = array('label' => _AREA, 'type' => 'select', 'value' => $item->id_area, 'options' => array($amod->get_areas(), 'id', 'name'), 'name' => 'id_area', 'extra' => 'class="large spinner spin2"');
            $fields[] = array('label' => null, 'type' => 'hidden', 'value' => 'module|' . BASE_URL . 'articles/refresh_module|id_area', 'name' => 'spinner1_data');
            $fields[] = array('label' => null, 'type' => 'html', 'value' => '</div><div class="one-fourth sm-one-half pad-right xs-one-whole sm-pad-none">');
            // language
            $fields[] = array('label' => _LANGUAGE, 'type' => 'select', 'value' => $item->lang, 'options' => array($lmod->get_languages(), 'code', 'language'), 'name' => 'lang', 'extra' => 'class="large spinner spin2"');
            // value = id_to_update|url|ids_to_get
            $fields[] = array('label' => null, 'type' => 'hidden', 'value' => 'code_context|' . BASE_URL . 'articles/refresh_context|id_area|lang', 'name' => 'spinner2_data');
            $fields[] = array('label' => null, 'type' => 'html', 'value' => '</div><div class="one-fourth sm-one-half pad-right xs-one-whole xs-pad-none">');
            // contexts
            $cmod = new Context_model();
            $fields[] = array('label' => _CONTEXT, 'type' => 'select', 'value' => $item->code_context, 'options' => array($cmod->get_contexts($item->id_area, $item->lang), 'code', 'name'), 'name' => 'code_context', 'extra' => 'class="large spin2"');
            $fields[] = array('label' => null, 'type' => 'hidden', 'value' => $item->code_context, 'name' => 'old_context');
            // value = id_to_update|url|ids_to_get
            $fields[] = array('label' => null, 'type' => 'hidden', 'value' => 'id_page|' . BASE_URL . 'articles/refresh_pages|id_area|lang|code_context', 'name' => 'spinner3_data');
            $fields[] = array('label' => null, 'type' => 'html', 'value' => '</div><div class="one-fourth sm-one-half xs-one-whole">');
            $fields[] = array('label' => _PAGE, 'type' => 'select', 'value' => $item->id_page, 'options' => $item->id_page ? array($cmod->get_pages($item->id_area, $item->lang, 1), 'id', 'name') : array(), 'name' => 'id_page', 'extra' => 'class="large"');
            $fields[] = array('label' => null, 'type' => 'html', 'value' => '</div></div>');
        } else {
            // simple editing
            // hidden fields
            $fields[] = array('label' => null, 'type' => 'hidden', 'value' => $item->id_area, 'name' => 'id_area');
            $fields[] = array('label' => null, 'type' => 'hidden', 'value' => $item->lang, 'name' => 'lang');
            $fields[] = array('label' => null, 'type' => 'hidden', 'value' => $item->code_context, 'name' => 'code_context');
            $fields[] = array('label' => null, 'type' => 'hidden', 'value' => $item->code_context, 'name' => 'old_context');
            $fields[] = array('label' => null, 'type' => 'hidden', 'value' => $item->id_page, 'name' => 'id_page');
        }
        // classification section
        $fields[] = array('label' => _NAME, 'type' => 'text', 'value' => stripslashes($item->name), 'name' => 'name', 'rule' => 'required', 'extra' => 'class="large"');
        // content
        $fields[] = array('label' => _CONTENT, 'type' => 'textarea', 'value' => $item->content, 'name' => 'content');
        if (EDITOR_SCRIPTS) {
            // content
            $fields[] = array('label' => _SCRIPT, 'type' => 'textarea', 'value' => htmlentities($item->js), 'name' => 'js', 'extra' => 'class="NoEditor"', 'suggestion' => _SCRIPT_MSG);
        } else {
            $fields[] = array('label' => null, 'type' => 'hidden', 'value' => $item->js, 'name' => 'js');
        }
        // plugin section
        $fields[] = array('label' => null, 'type' => 'html', 'value' => '<h3>' . _PLUGIN . '</h3>
						<div class="band clearfix"><div class="one-half pad-right">');
        $plugin = new X4Plugin_model();
        // for APC
        $fields[] = array('label' => null, 'type' => 'hidden', 'value' => $item->module, 'name' => 'old_module');
        $fields[] = array('label' => null, 'type' => 'hidden', 'value' => $item->param, 'name' => 'old_param');
        $fields[] = array('label' => _MODULE, 'type' => 'select', 'value' => $item->module, 'options' => array($plugin->get_modules($id_area, 0), 'name', 'description', ''), 'name' => 'module', 'extra' => 'class="large"');
        $fields[] = array('label' => null, 'type' => 'html', 'value' => '</div><div class="one-half pad-left">');
        $fields[] = array('label' => _PARAM, 'type' => 'text', 'value' => $item->param, 'name' => 'param', 'extra' => 'class="large"');
        $fields[] = array('label' => null, 'type' => 'html', 'value' => '</div></div></div>
				<div id="right-box" class="one-fifth md-one-fourth sm-one-third xs-one-whole xs-hidden">');
        // time window section
        $fields[] = array('label' => null, 'type' => 'html', 'value' => '<h2>' . _TIME_WINDOW . '</h2><div class="band clearfix inner-pad"><div class="one-half sm-one-whole">');
        $fields[] = array('label' => null, 'type' => 'hidden', 'value' => $item->date_in, 'name' => 'old_date_in');
        $fields[] = array('label' => _START_DATE, 'type' => 'text', 'value' => date('Y-m-d', $item->date_in), 'name' => 'date_in', 'rule' => 'required|date', 'extra' => 'class="date date_toggled large"');
        $fields[] = array('label' => null, 'type' => 'html', 'value' => '</div><div class="one-half sm-one-whole">');
        $fields[] = array('label' => _END_DATE, 'type' => 'text', 'value' => $item->date_out == 0 ? '' : date('Y-m-d', $item->date_out), 'name' => 'date_out', 'rule' => 'date', 'extra' => 'class="date date_toggled large"', 'suggestion' => _NO_END_MSG);
        // classification section
        $fields[] = array('label' => null, 'type' => 'html', 'value' => '</div></div><h2>' . _ORGANIZATION . '</h2>');
        // categories
        $camod = new Category_model();
        $fields[] = array('label' => _CATEGORY, 'type' => 'select', 'value' => $item->category, 'options' => array($camod->get_categories($item->id_area, $item->lang), 'name', 'description', 0), 'name' => 'category', 'extra' => 'class="large"');
        // xkeys
        $fields[] = array('label' => _KEYS, 'type' => 'text', 'value' => $item->xkeys, 'name' => 'xkeys', 'extra' => 'class="large"');
        // tags
        $fields[] = array('label' => _TAGS, 'type' => 'text', 'value' => $item->tags, 'name' => 'tags', 'extra' => 'class="large"');
        // author
        $fields[] = array('label' => _AUTHOR, 'type' => 'text', 'value' => empty($item->author) ? $_SESSION['mail'] : $item->author, 'name' => 'author', 'rule' => 'required', 'extra' => 'class="large"');
        if (EDITOR_OPTIONS) {
            // options section
            $fields[] = array('label' => null, 'type' => 'html', 'value' => '<h2>' . _OPTIONS . '</h2>
                            <div class="band clearfix">
                                <div class="one-half sm-one-whole">');
            $fields[] = array('label' => _SHOW_AUTHOR, 'type' => 'checkbox', 'value' => $item->show_author, 'name' => 'show_author', 'checked' => $item->show_author);
            $fields[] = array('label' => null, 'type' => 'html', 'value' => '</div><div class="one-half sm-one-whole">');
            $fields[] = array('label' => _SHOW_DATE, 'type' => 'checkbox', 'value' => $item->show_date, 'name' => 'show_date', 'checked' => $item->show_date);
            $fields[] = array('label' => null, 'type' => 'html', 'value' => '</div><div class="one-half sm-one-whole">');
            $fields[] = array('label' => _SHOW_TAGS, 'type' => 'checkbox', 'value' => $item->show_tags, 'name' => 'show_tags', 'checked' => $item->show_tags);
            $fields[] = array('label' => null, 'type' => 'html', 'value' => '</div><div class="one-half sm-one-whole">');
            $fields[] = array('label' => _SHOW_ACTIONS, 'type' => 'checkbox', 'value' => $item->show_actions, 'name' => 'show_actions', 'checked' => $item->show_actions);
            $fields[] = array('label' => null, 'type' => 'html', 'value' => '</div></div>');
        }
        $fields[] = array('label' => null, 'type' => 'html', 'value' => '</div></div>');
        /*
        // TODO: maybe in the future
        		$fields[] = array(
        			'label' => _SCHEMA,
        			'type' => 'textarea', 
        			'value' => $item->xschema,
        			'name' => 'xschema',
        			'extra' => 'class="mceNoEditor"'
        		);
        */
        // if submitted
        if (X4Route_core::$post) {
            $e = X4Validation_helper::form($fields, 'editor');
            if ($e) {
                $this->editing($item, $_POST);
            } else {
                $this->notice($fields);
            }
            die;
        }
        // content
        $view = new X4View_core('tabber');
        $view->tabs = array();
        $view->down = new X4View_core('editor');
        $view->down->close = false;
        // Set the navbar
        $page = $this->get_page('articles/edit');
        $ref = isset($_SESSION['referer']) ? $_SESSION['referer'] : 'index/' . $id_area . '/' . $lang;
        $navbar = array($this->site->get_bredcrumb($page), array('articles' => $ref));
        $pmod = new Page_model();
        if ($id_page && $bid != 'x3') {
            // simple editing
            $page = $pmod->get_by_id($id_page);
            $view->title = _CONTENT_EDITOR . ' <a class="bta" href="' . BASE_URL . 'pages/index/' . $page->id_area . '/' . $page->lang . '/' . $page->xfrom . '/1" title="' . _GO_BACK . '">' . stripslashes($page->name) . '</a>' . _TRAIT_ . $lang;
            $view->down->js = '';
        } else {
            // generic back
            $back = '<a class="bta" href="' . BASE_URL . 'pages/index/' . $id_area . '/' . $lang . '/home/1" title="' . _GO_BACK . '">' . _PAGES . '</a>';
            if ($bid) {
                if ($item->id_page) {
                    // back to the right page
                    $page = $pmod->get_by_id($item->id_page);
                    $back = ADVANCED_EDITING ? '<a class="bta" href="' . BASE_URL . 'sections/compose/' . $page->id . '" title="' . _GO_BACK . '">' . stripslashes($page->name) . '</a>' : '<a class="bta" href="' . BASE_URL . 'pages/index/' . $page->id_area . '/' . $page->lang . '/' . $page->xfrom . '/1" title="' . _GO_BACK . '">' . stripslashes($page->name) . '</a>';
                }
                $view->title = $back . _TRAIT_ . _EDIT_ARTICLE . _TRAIT_ . $lang;
            } else {
                $view->title = $back . _TRAIT_ . _ADD_ARTICLE . _TRAIT_ . $lang;
            }
            $view->down->js = '
<script>
window.addEvent("domready", function()
{
	if ($chk($("spinner1_data"))) {
		var sdata = $("spinner1_data").get("value").split("|");
		spinnerize(sdata, ".spinner");
	}
	
	if ($chk($("spinner2_data"))) {
		var sdata = $("spinner2_data").get("value").split("|");
		spinnerize(sdata, ".spinner");
	}
	
	if ($chk($("spinner3_data"))) {
		var sdata = $("spinner3_data").get("value").split("|");
		spinnerize(sdata, ".spin2");
	}
});
</script>
			';
        }
        $view->down->js .= '
<script>
window.addEvent("domready", function()
{
	X3.content("filters","articles/filter/' . $id_area . '/' . $lang . '", "' . addslashes(X4Utils_helper::navbar($navbar, ' . ')) . '");
	buttonize("tabber", "bta", "topic");
	pickerize(1);
	
	$("module").addEvent("change", function(event, target){
    	event.preventDefault();
    	v = this.get("value");
    	if (v.length == 0) {
    	   $("param").set("value", "");
    	} else {
    	   X3.modal("", "' . _ARTICLE_PARAM_SETTING . '", "' . BASE_URL . 'articles/param/' . $id_area . '/' . $lang . '/"+v);
    	}
    });
    
    $("param").addEvent("focus", function(event, target){
    	event.preventDefault();
    	m = $("module").get("value");
    	if (m != "") {
            v = this.get("value");
            X3.modal("", "' . _ARTICLE_PARAM_SETTING . '", "' . BASE_URL . 'articles/param/' . $id_area . '/' . $lang . '/"+m+"/"+v);
        }
    });
});
</script>';
        // form builder
        $view->down->form = X4Form_helper::doform('editor', $_SERVER["REQUEST_URI"], $fields, array(_RESET, _SUBMIT, 'buttons'), 'post', '', 'onclick="setForm(\'editor\', \'content\');"');
        $view->down->tinymce = new X4View_core('tinymce');
        $view->down->tinymce->id_area = $id_area;
        // rtl
        if ($lmod->rtl($lang)) {
            $view->down->tinymce->rtl = 1;
        }
        $view->render(TRUE);
    }
Пример #5
0
 /**
  * Initialize area: create default pages
  *
  * @param   integer	$id_area Area ID
  * @param   string	$lang Language code
  * @return  void
  */
 public function init($id_area, $lang)
 {
     $msg = null;
     // check permissions
     $msg = AdmUtils_helper::chklevel($_SESSION['xuid'], '_page_creation', 0, 4);
     if (is_null($msg)) {
         $qs = X4Route_core::get_query_string();
         // get object: the area
         $area = new Area_model();
         $a = $area->get_by_id($id_area);
         $mod = new Page_model($id_area, $lang);
         // build the post array
         $post = array();
         if ($id_area == 1) {
             // admin area
             // uses admin area with language = SESSION['lang'] as base and duplicates all pages
             $pmod = new Page_model($id_area, $_SESSION['lang']);
             $pages = $pmod->get_pages();
             foreach ($pages as $i) {
                 $post[] = array($i->url, array('lang' => $lang, 'id_area' => $id_area, 'xid' => $i->xid, 'url' => $i->url, 'name' => $i->name, 'title' => $i->title, 'description' => $i->description, 'xfrom' => $i->xfrom, 'tpl' => $i->tpl, 'css' => $i->css, 'id_menu' => $i->id_menu, 'xpos' => $i->xpos, 'deep' => $i->deep, 'ordinal' => $i->ordinal, 'xon' => $i->xon));
             }
         } else {
             // other areas
             // home
             $post[] = array('home', array('lang' => $lang, 'id_area' => $id_area, 'xid' => 'pages', 'url' => 'home', 'name' => 'Home page', 'title' => 'Home page', 'description' => 'Home page', 'xfrom' => 'home', 'tpl' => 'base', 'css' => 'base', 'id_menu' => 0, 'xpos' => 0, 'deep' => 0, 'ordinal' => 'A', 'xon' => 1));
             // x3admin
             $post[] = array('x3admin', array('lang' => $lang, 'id_area' => $id_area, 'xid' => 'pages', 'url' => 'x3admin', 'name' => 'Editor', 'title' => 'Editor', 'description' => 'Editor', 'xfrom' => 'home', 'tpl' => 'base', 'css' => 'base', 'id_menu' => 0, 'xpos' => 1, 'deep' => 1, 'ordinal' => 'A0000001', 'hidden' => 1, 'xlock' => 1, 'xon' => 1));
             // msg
             $post[] = array('comunication', array('lang' => $lang, 'id_area' => $id_area, 'xid' => 'pages', 'url' => 'msg', 'name' => 'Communication', 'title' => 'Communication', 'description' => 'Communication', 'xfrom' => 'home', 'tpl' => 'base', 'css' => 'base', 'id_menu' => 0, 'xpos' => 2, 'deep' => 1, 'ordinal' => 'A0000002', 'hidden' => 1, 'xlock' => 1, 'xon' => 1));
             // search
             $post[] = array('search', array('lang' => $lang, 'id_area' => $id_area, 'xid' => 'pages', 'url' => 'search', 'name' => 'Search result', 'title' => 'Search result', 'description' => 'Search result', 'xfrom' => 'home', 'tpl' => 'base', 'css' => 'base', 'id_menu' => 0, 'xpos' => 3, 'deep' => 1, 'ordinal' => 'A0000003', 'hidden' => 1, 'xlock' => 1, 'xon' => 1));
             // if is a private area
             if ($a->private) {
                 // exit
                 $post[] = array('logout', array('lang' => $lang, 'id_area' => $id_area, 'xid' => 'pages', 'url' => 'logout', 'name' => 'Logout', 'title' => 'Logout', 'description' => 'Logout', 'xfrom' => 'home', 'tpl' => 'base', 'css' => 'base', 'id_menu' => 0, 'xpos' => 4, 'deep' => 1, 'ordinal' => 'A0000004', 'hidden' => 0, 'xlock' => 1, 'xon' => 1));
             }
         }
         // action
         $result = $mod->initialize_area($id_area, $lang, $post);
         // set message
         $this->dict->get_words();
         $msg = AdmUtils_helper::set_msg($result);
         if ($result[1]) {
             // create default contexts
             $mod->initialize_context($id_area, $lang);
             // refresh permissions
             $perm = new Permission_model();
             $perm->refactory($_SESSION['xuid']);
             // set update
             $msg->update[] = array('element' => $qs['div'], 'url' => urldecode($qs['url']), 'title' => null);
         }
     }
     $this->response($msg);
 }
Пример #6
0
 /**
  * New / Edit category form (use Ajax)
  *
  * @param   integer	$id_area Area ID
  * @param   integer	$id Category ID
  * @return  void
  */
 public function edit($id_area, $lang, $tag = '', $id = 0)
 {
     // load dictionaries
     $this->dict->get_wordarray(array('form', 'categories'));
     // handle id
     $chk = false;
     if ($id < 0) {
         $id = 0;
         $chk = true;
     }
     // get object
     $mod = new Category_model();
     $m = $id ? $mod->get_by_id($id) : new Category_obj($id_area, $lang, $tag);
     // build the form
     $fields = array();
     $fields[] = array('label' => null, 'type' => 'hidden', 'value' => $id, 'name' => 'id');
     if (MULTIAREA) {
         $amod = new Area_model();
         $fields[] = array('label' => _AREA, 'type' => 'select', 'value' => $m->id_area, 'options' => array($amod->get_areas(), 'id', 'name'), 'name' => 'id_area', 'extra' => 'class="large"');
     } else {
         $fields[] = array('label' => null, 'type' => 'hidden', 'value' => $m->id_area, 'name' => 'id_area');
     }
     if (MULTILANGUAGE) {
         $lmod = new Language_model();
         $fields[] = array('label' => _LANGUAGE, 'type' => 'select', 'value' => $m->lang, 'options' => array($lmod->get_languages(), 'code', 'language'), 'name' => 'lang', 'extra' => 'class="large"');
     } else {
         $fields[] = array('label' => null, 'type' => 'hidden', 'value' => $m->lang, 'name' => 'lang');
     }
     $fields[] = array('label' => _TITLE, 'type' => 'text', 'value' => $m->title, 'name' => 'title', 'rule' => 'required', 'extra' => 'class="large"');
     $fields[] = array('label' => _CATEGORY_TAG, 'type' => 'text', 'value' => $m->tag, 'name' => 'tag', 'extra' => 'class="large"', 'suggestion' => _CATEGORY_TAG_MSG);
     // if submitted
     if (X4Route_core::$post) {
         $e = X4Validation_helper::form($fields, 'editor');
         if ($e) {
             $this->editing($id, $_POST);
         } else {
             $this->notice($fields);
         }
         die;
     }
     // content
     $view = new X4View_core('editor');
     $view->title = $id ? _EDIT_CATEGORY : _ADD_CATEGORY;
     // form builder
     $view->form = X4Form_helper::doform('editor', $_SERVER["REQUEST_URI"], $fields, array(_RESET, _SUBMIT, 'buttons'), 'post', '', 'onclick="setForm(\'editor\');"');
     $view->js = '';
     if ($id > 0 || $chk) {
         $view->render(TRUE);
     } else {
         return $view->render();
     }
 }
Пример #7
0
 /**
  * New / Edit group form (use Ajax)
  *
  * @param   integer  $id item ID (if 0 then is a new item)
  * @return  void
  */
 public function edit($id = 0)
 {
     // load dictionaries
     $this->dict->get_wordarray(array('form', 'groups'));
     // get object
     $group = new Group_model();
     $g = $id ? $group->get_by_id($id) : new Group_obj();
     // build the form
     $fields = array();
     $fields[] = array('label' => null, 'type' => 'hidden', 'value' => $id, 'name' => 'id');
     $amod = new Area_model();
     if ($id) {
         // update a group
         $area = $amod->get_by_id($g->id_area, 'areas', 'title');
         $fields[] = array('label' => null, 'type' => 'html', 'value' => '<h4>' . _AREA . ': ' . $area->title . '</h4>');
         $fields[] = array('label' => null, 'type' => 'hidden', 'value' => $g->id_area, 'name' => 'id_area');
     } else {
         $fields[] = array('label' => _AREA, 'type' => 'select', 'value' => '', 'options' => array($amod->get_areas(), 'id', 'title'), 'name' => 'id_area', 'extra' => 'class="large"');
     }
     $fields[] = array('label' => _NAME, 'type' => 'text', 'value' => $g->name, 'name' => 'name', 'rule' => 'required', 'extra' => 'class="large"');
     $fields[] = array('label' => _DESCRIPTION, 'type' => 'textarea', 'value' => $g->description, 'name' => 'description', 'rule' => 'required', 'extra' => 'class="large"');
     // if submitted
     if (X4Route_core::$post) {
         $e = X4Validation_helper::form($fields, 'editor');
         if ($e) {
             $this->editing($_POST);
         } else {
             $this->notice($fields);
         }
         die;
     }
     // contents
     $view = new X4View_core('editor');
     $view->title = $id ? _EDIT_GROUP : _ADD_GROUP;
     // form builder
     $view->form = X4Form_helper::doform('editor', $_SERVER["REQUEST_URI"], $fields, array(_RESET, _SUBMIT, 'buttons'), 'post', '', 'onclick="setForm(\'editor\');"');
     $view->render(TRUE);
 }
Пример #8
0
 /**
  * Perform the importing of words
  *
  * @access	private
  * @param   array	$_post _POST array
  * @return  void
  */
 private function importing($_post)
 {
     $msg = null;
     // check permission
     $msg = AdmUtils_helper::chk_priv_level($_SESSION['xuid'], '_key_import', 0, 4);
     if (is_null($msg)) {
         // get key
         list($lang, $area, $what) = explode('-', $_post['what']);
         // handle _post
         $post = array('lang' => $_post['lang'], 'area' => $_post['area'], 'what' => $what, 'xon' => 1);
         // set the translator
         X4Core_core::auto_load('google_translate_library');
         $translator = new GoogleTranslate($lang, $post['lang']);
         // get words to import
         $dict = new Dictionary_model();
         if ($what == 'ALL') {
             // import all sections in an area
             $sections = $dict->get_sections($lang, $area);
             $result = true;
             foreach ($sections as $s) {
                 // get words in section
                 $words = $dict->get_words_to_import($lang, $area, $s->what, $post['lang'], $post['area']);
                 if (!empty($words)) {
                     $post['what'] = $s->what;
                     // import
                     foreach ($words as $i) {
                         $post['xkey'] = $i->xkey;
                         // try to translate
                         if ($lang != $post['lang']) {
                             $value = $translator->translate($i->xval);
                         } else {
                             $value = $i->xval;
                         }
                         // set the word
                         $post['xval'] = $value;
                         // insert
                         $result = $dict->insert($post);
                         // add permission
                         if ($result[1]) {
                             $amod = new Area_model();
                             $id_area = $amod->get_area_id($_post['area']);
                             $perm = new Permission_model();
                             $array[] = array('action' => 'insert', 'id_what' => $result[0], 'id_user' => $_SESSION['xuid'], 'level' => 4);
                             $res = $perm->pexec('dictionary', $array, $id_area);
                         }
                     }
                 }
             }
             // set what for redirect
             $what = 'global';
         } else {
             // import only one section
             $words = $dict->get_words_to_import($lang, $area, $what, $post['lang'], $post['area']);
             $result = true;
             // import
             foreach ($words as $i) {
                 $post['xkey'] = $i->xkey;
                 // try to translate
                 if ($lang != $post['lang']) {
                     $value = $translator->translate($i->xval);
                 } else {
                     $value = $i->xval;
                 }
                 // set the word
                 $post['xval'] = $value;
                 // insert
                 $result = $dict->insert($post);
                 // add permission
                 if ($result[1]) {
                     $amod = new Area_model();
                     $id_area = $amod->get_area_id($_post['area']);
                     $perm = new Permission_model();
                     $array[] = array('action' => 'insert', 'id_what' => $result[0], 'id_user' => $_SESSION['xuid'], 'level' => 4);
                     $res = $perm->pexec('dictionary', $array, $id_area);
                 }
             }
         }
         $msg = AdmUtils_helper::set_msg($result);
         // set what update
         if ($result[1]) {
             $msg->update[] = array('element' => 'tdown', 'url' => BASE_URL . 'dictionary/keys/' . $post['lang'] . '/' . $post['area'] . '/' . $what, 'title' => null);
         }
     }
     $this->response($msg);
 }
Пример #9
0
 /**
  * New / Edit user form (use Ajax)
  *
  * @param   integer  $id User ID (if 0 then is a new item)
  * @param   integer  $id_group Group ID (if 0 then is a new item)
  * @return  void
  */
 public function edit($id, $id_group = 0)
 {
     // load dictionaries
     $this->dict->get_wordarray(array('form', 'login', 'users'));
     $lang = X4Route_core::$lang;
     // get object
     $user = new User_model();
     $u = $id ? $user->get_by_id($id) : new User_obj($id_group, $lang);
     // get group
     $group = new Group_model();
     $g = $group->get_by_id($u->id_group, 'groups', 'id_area, name');
     // build the form
     $fields = array();
     $fields[] = array('label' => null, 'type' => 'hidden', 'value' => $u->id_group, 'name' => 'id_group');
     $fields[] = array('label' => null, 'type' => 'hidden', 'value' => $g->id_area, 'name' => 'id_area');
     $fields[] = array('label' => null, 'type' => 'html', 'value' => '<h4>' . _GROUP . ': ' . $g->name . '</h4>');
     $fields[] = array('label' => null, 'type' => 'html', 'value' => '<div class="band inner-pad clearfix"><div class="one-half xs-one-whole">');
     // languages
     $lmod = new Language_model();
     $fields[] = array('label' => ucfirst(_LANGUAGE), 'type' => 'select', 'value' => $u->lang, 'options' => array($lmod->get_languages(), 'code', 'language'), 'name' => 'lang', 'extra' => 'class="large"');
     $fields[] = array('label' => null, 'type' => 'html', 'value' => '</div><div class="one-half xs-one-whole">');
     $fields[] = array('label' => _USERNAME, 'type' => 'text', 'value' => $u->username, 'name' => 'username', 'suggestion' => _USERNAME_RULE, 'rule' => 'required|minlength§6|alphanumeric', 'extra' => 'class="large"');
     $fields[] = array('label' => null, 'type' => 'html', 'value' => '</div></div>');
     // password
     if ($id) {
         $fields[] = array('label' => null, 'type' => 'html', 'value' => '<h4 class="acenter zerom">' . _PASSWORD_CHANGE_MSG . '</h4>');
         $rule = '';
     } else {
         // for a new user you must insert a password
         $rule = 'required|';
     }
     $fields[] = array('label' => null, 'type' => 'html', 'value' => '<div class="band inner-pad clearfix"><div class="one-half xs-one-whole">');
     $fields[] = array('label' => _PASSWORD, 'type' => 'password', 'value' => '', 'name' => 'password', 'suggestion' => _PASSWORD_RULE, 'rule' => $rule . 'minlength§6|alphanumeric', 'extra' => 'class="large"');
     $fields[] = array('label' => null, 'type' => 'html', 'value' => '</div><div class="one-half xs-one-whole">');
     $fields[] = array('label' => _REPEAT_PASSWORD, 'type' => 'password', 'value' => '', 'name' => 'password2', 'rule' => $rule . 'equal-password', 'extra' => 'class="large"');
     $fields[] = array('label' => null, 'type' => 'html', 'value' => '</div></div>');
     $fields[] = array('label' => _DESCRIPTION, 'type' => 'textarea', 'value' => $u->description, 'name' => 'description', 'sanitize' => 'string', 'rule' => 'required');
     $fields[] = array('label' => null, 'type' => 'html', 'value' => '<div class="band inner-pad clearfix"><div class="one-half xs-one-whole">');
     $fields[] = array('label' => _EMAIL, 'type' => 'text', 'value' => $u->mail, 'name' => 'mail', 'rule' => 'required|mail', 'extra' => 'class="large"');
     $fields[] = array('label' => null, 'type' => 'html', 'value' => '</div><div class="one-half xs-one-whole">');
     $fields[] = array('label' => _PHONE, 'type' => 'text', 'value' => $u->phone, 'name' => 'phone', 'rule' => 'phone', 'extra' => 'class="large"');
     $fields[] = array('label' => null, 'type' => 'html', 'value' => '</div></div><div class="band inner-pad clearfix"><div class="one-half xs-one-whole">');
     $fields[] = array('label' => _LEVEL, 'type' => 'select', 'value' => $u->level, 'options' => array($user->get_levels(), 'id', 'name'), 'name' => 'level', 'extra' => 'class="large"');
     $fields[] = array('label' => null, 'type' => 'html', 'value' => '</div><div class="one-half xs-one-whole">');
     // permissions on areas
     $perm = new Permission_model();
     $area = new Area_model();
     $fields[] = array('label' => _DOMAIN, 'type' => 'select', 'value' => X4Utils_helper::obj2array($perm->get_aprivs($id), null, 'id_area'), 'options' => array($area->get_areas($g->id_area, false), 'id', 'name'), 'multiple' => 4, 'name' => 'domain', 'extra' => 'class="large"');
     $fields[] = array('label' => null, 'type' => 'html', 'value' => '</div></div>');
     // if submitted
     if (X4Route_core::$post) {
         $e = X4Validation_helper::form($fields, 'editor');
         if ($e) {
             $this->editing($id, $_POST);
         } else {
             $this->notice($fields);
         }
         die;
     }
     // contents
     $view = new X4View_core('editor');
     $view->title = $id ? _EDIT_USER : _ADD_USER;
     // form builder
     $view->form = X4Form_helper::doform('editor', $_SERVER["REQUEST_URI"], $fields, array(_RESET, _SUBMIT, 'buttons'), 'post', '', 'onclick="setForm(\'editor\');"');
     $view->render(TRUE);
 }
Пример #10
0
    /**
     * Rename area (secret method)
     * If for whatever reason you need to rename an area you can call this script
     * /admin/areas/reaname_area/ID_AREA/NEW_NAME
     *
     * @param   integer $id_area Area ID to rename
     * @param   string  $new_name New name to set
     * @return  string
     */
    public function rename_area($id_area, $new_name)
    {
        // Comment the next row to enable the method
        die('Operation disabled!');
        $mod = new Area_model();
        // clean the new name
        $new = X4Utils_helper::unspace(urldecode($new_name), true);
        // check if already exists
        $chk = $mod->exists($new, $id_area);
        // get the old area name
        $old = $mod->get_var($id_area, 'areas', 'name');
        if (!$chk && $old && $old != $new && strlen($new) > 2) {
            // replace name
            $res = $mod->rename_area($id_area, $old, $new);
            if ($res[1]) {
                echo '<h1>CONGRATULATIONS!</h1>';
                echo '<p>The changes on the database are applied.</p>';
                // print instructions for manual changes
                echo '<p>Follow this instructions to perform manual changes.</p>
				<ul>
					<li>Rename the folder /cms/controllers/' . $old . ' to /cms/controllers/' . $new . '</li>
					<li>Rename the folder /cms/views/' . $old . ' to /cms/views/' . $new . '</li>
					<li>In the file system/core/X4Route_core.php replace the old area name "' . $old . '" with the new "' . $new . '" in the static vars</li>
					<li>In the file cms/config/config.php replace the old area name "' . $old . '" with the new "' . $new . '" in the $default array</li>
				</ul>
				<p>Done!</p>
				
				<p>NOTE: this operation acts on the core system of the CMS, if you use plugins you have to check if they need to be changed.</p>';
            } else {
                echo '<h1>WARNING!</h1>';
                echo '<p>Something went wrong, changes are not applied.</p>';
            }
        } else {
            echo '<h1>WARNING!</h1>';
            if (!$old) {
                echo '<p>Not exists an area with ID ' . $id_area . '.</p>';
            } else {
                if (strlen($new) < 3) {
                    echo '<p>The new name "' . $new . '" is too short (the minimum is 3 chars).</p>';
                }
                if (!$chk) {
                    echo '<p>An area with the same name "' . $new . '" already exists.</p>';
                }
                if ($old == $new) {
                    echo '<p>The old name "' . $old . '" and the new name "' . $new . '" are equal.</p>';
                }
            }
        }
        die;
    }