示例#1
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);
 }