Esempio n. 1
0
 /**
  * Install a new template
  *
  * @param   integer $id_theme Theme ID
  * @param   string	$name Theme name (theme folder name)
  * @return  array	Array of errors
  */
 public function install_tpl($id_theme, $name)
 {
     $error = array();
     // check if already installed
     if ($this->exists($id_theme, $name)) {
         $error[] = array('error' => '_ALREADY_INSTALLED', 'label' => $name);
     } else {
         // check if template file exists
         if (file_exists('themes/' . $name . '_install.php')) {
             // load template installer (SQL instructions)
             require_once 'themes/' . $name . '_install.php';
             // install
             $result = $this->db->single_exec($sql);
             if ($result[1]) {
                 // refactory permissions on templates table
                 $perm = new Permission_model();
                 $perm->refactory_table($_SESSION['xuid'], 1, 'templates');
                 return $result[0];
             } else {
                 $error[] = array('error' => '_TEMPLATE_NOT_INSTALLED', 'label' => $name);
             }
         } else {
             $error[] = array('error' => '_TEMPLATE_INSTALLER_NOT_FOUND', 'label' => $name);
         }
     }
     return $error;
 }
Esempio n. 2
0
 /**
  * Register new page
  *
  * @access	private
  * @param   array 	$_post _POST array
  * @return  void
  */
 private function adding($_post)
 {
     $msg = null;
     // check permissions
     $msg = AdmUtils_helper::chk_priv_level($_SESSION['xuid'], '_page_creation', 0, 4);
     if (is_null($msg)) {
         // remove slash from url
         if ($_post['id_area'] > 1) {
             $_post['name'] = str_replace('/', '-', $_post['name']);
         }
         // handle _post
         $post = array('lang' => $_post['lang'], 'id_area' => $_post['id_area'], 'url' => X4Utils_helper::unspace($_post['name'], true), 'name' => $_post['name'], 'title' => $_post['name'], 'description' => $_post['description'], 'xfrom' => $_post['xfrom'], 'tpl' => $_post['tpl']);
         // load model
         $mod = new Page_model($_post['id_area'], $_post['lang']);
         // check if a page with the same URL already exists
         $check = (bool) $mod->exists($post['url']);
         if ($check) {
             $msg = AdmUtils_helper::set_msg(false, '', $this->dict->get_word('_PAGE_ALREADY_EXISTS', 'msg'));
         } else {
             // set css for the template of the new page
             $tmod = new Template_model();
             $css = $tmod->get_css($_post['id_area'], $_post['tpl']);
             $post['css'] = $css;
             // set xrif for admin pages
             if ($_post['id_area'] == 1) {
                 $post['xid'] = 'pages';
             }
             // insert the new page
             $result = $mod->insert_page($post, $this->site->site->domain);
             // add permission
             if ($result[1]) {
                 $perm = new Permission_model();
                 $array[] = array('action' => 'insert', 'id_what' => $result[0], 'id_user' => $_SESSION['xuid'], 'level' => 4);
                 $result = $perm->pexec('pages', $array, $post['id_area']);
                 // refresh article permissions
                 $perm->refactory_table($_SESSION['xuid'], array($post['id_area']), 'articles');
             }
             // set message
             $msg = AdmUtils_helper::set_msg($result);
             // set what update
             if ($result[1]) {
                 $msg->update[] = array('element' => 'topic', 'url' => BASE_URL . 'pages/index/' . $post['id_area'] . '/' . $post['lang'] . '/' . str_replace('/', '-', $post['xfrom']), 'title' => null);
             }
         }
     }
     $this->response($msg);
 }
Esempio n. 3
0
 /**
  * Install a theme
  *
  * @param   string	$theme_name Theme name
  * @return  void
  */
 public function install($theme_name)
 {
     $msg = null;
     // check permission
     $msg = AdmUtils_helper::chk_priv_level($_SESSION['xuid'], '_theme_install', 0, 4);
     if (is_null($msg)) {
         $qs = X4Route_core::get_query_string();
         // perform the install
         $theme = new Theme_model();
         $result = $theme->install($theme_name);
         // if result is an array an error occurred
         if (is_array($result)) {
             $this->notice(false, '_theme_not_installed');
             die;
         } else {
             // installed
             // set message
             $this->dict->get_words();
             $msg = AdmUtils_helper::set_msg(true);
             // add permission on new theme
             if ($result) {
                 $perm = new Permission_model();
                 $array[] = array('action' => 'insert', 'id_what' => $result, 'id_user' => $_SESSION['xuid'], 'level' => 4);
                 $result = $perm->pexec('themes', $array, 1);
                 // refactory permissions
                 $perm->refactory_table($_SESSION['xuid'], array(1), 'themes');
                 $perm->refactory_table($_SESSION['xuid'], array(1), 'templates');
                 $perm->refactory_table($_SESSION['xuid'], array(1), 'menus');
             }
             $msg->update[] = array('element' => 'tdown', 'url' => BASE_URL . 'themes', 'title' => null);
         }
     }
     $this->response($msg);
 }
Esempio n. 4
0
 /**
  * Register New files form data
  *
  * @access	private
  * @param   array 	$_post _POST array
  * @param   array 	$file_array Files labels array
  * @return  void
  */
 private function adding($_post, $file_array)
 {
     $msg = null;
     // check permission
     $msg = AdmUtils_helper::chk_priv_level($_SESSION['xuid'], '_file_upload', 0, 4);
     if (is_null($msg)) {
         $error = array();
         $mod = new File_model();
         $path = $mod->file_path;
         $filename = X4Files_helper::upload('xname', $path);
         // check for errors
         if ($filename[1]) {
             $post = array();
             $files = $filename[0];
             $n = sizeof($files);
             // handle _post for each area
             for ($i = 0; $i < $n; $i++) {
                 $xtype = X4Files_helper::get_type_by_name($files[$i]);
                 $areas = array();
                 foreach ($_post['id_area'] as $ii) {
                     $areas[] = $ii;
                     $post[] = array('id_area' => $ii, 'xtype' => $xtype, 'category' => X4Utils_helper::unspace($_post['category']), 'subcategory' => X4Utils_helper::unspace($_post['subcategory']), 'name' => $files[$i], 'alt' => $_POST['dida_' . ($i + 1)], 'xon' => 1);
                 }
             }
             // insert new files
             $result = $mod->insert_file($post);
             if ($result[1]) {
                 // add permission
                 $perm = new Permission_model();
                 foreach ($areas as $i) {
                     $perm->refactory_table($_SESSION['xuid'], array($i), 'files');
                 }
             }
             // set message
             $msg = AdmUtils_helper::set_msg($result);
             // set what update
             if ($result[1]) {
                 $msg->update[] = array('element' => 'topic', 'url' => BASE_URL . 'files/index/' . $post[0]['id_area'] . '/' . urlencode($post[0]['category']) . '/' . urlencode($post[0]['subcategory']), 'title' => null);
             }
         } else {
             // build msg
             $str = array();
             foreach ($filename[0] as $k => $v) {
                 // each field
                 foreach ($v as $i) {
                     // each error
                     $str[] = $file_array[$k] . _TRAIT_ . $this->dict->get_word(strtoupper($i), 'msg');
                 }
             }
             $msg = AdmUtils_helper::set_msg(false, '', implode('<br />', $str));
         }
     }
     $this->response($msg);
 }