示例#1
0
 /**
  * Register Edit / New Context form data
  *
  * @access	private
  * @param   integer $id item ID (if 0 then is a new item)
  * @param   array 	$_post _POST array
  * @return  void
  */
 private function editing($id, $_post)
 {
     $msg = null;
     // check permission
     $msg = $id ? AdmUtils_helper::chk_priv_level($_SESSION['xuid'], 'contexts', $id, 3) : AdmUtils_helper::chk_priv_level($_SESSION['xuid'], '_context_creation', 0, 4);
     if (is_null($msg)) {
         // handle _post
         $post = array('id_area' => $_post['id_area'], 'lang' => $_post['lang'], 'name' => strtolower($_post['name']), 'xkey' => X4Utils_helper::unspace($_post['name']));
         $mod = new Context_model();
         // check if context already exists
         $check = $mod->exists($post, $id);
         if ($check) {
             $msg = AdmUtils_helper::set_msg(false, '', $this->dict->get_word('_CONTEXT_ALREADY_EXISTS', 'msg'));
         } else {
             // update or insert
             if ($id) {
                 $result = $mod->update($id, $post);
                 // check if dictionary name for the context already exists
                 if ($result[1]) {
                     $mod->check_dictionary($post);
                 }
             } else {
                 // get the code of the new context
                 $code = $mod->get_max_code($post['id_area'], $post['lang']);
                 // this implies that the site can't have more than 33 languages
                 // you have 3 default contexts (draft, page, multipages) for each language and for each area
                 $post['code'] = $code > 100 ? $code + 1 : 101;
                 $result = $mod->insert($post);
                 if ($result[1]) {
                     // add item into dictionary
                     $mod->check_dictionary($post, 1);
                     // create permission
                     $perm = new Permission_model();
                     $array[] = array('action' => 'insert', 'id_what' => $result[0], 'id_user' => $_SESSION['xuid'], 'level' => 4);
                     $res = $perm->pexec('contexts', $array, $post['id_area']);
                 }
             }
             // set message
             $msg = AdmUtils_helper::set_msg($result);
             // set what update
             if ($result[1]) {
                 $msg->update[] = array('element' => 'topic', 'url' => BASE_URL . 'contexts/index/' . $post['id_area'] . '/' . $post['lang'], 'title' => null);
             }
         }
     }
     $this->response($msg);
 }