/**
  * Install a plugin
  *
  * @param integer	$id_area Area ID
  * @param string	$plugin_name Plugin name
  * @return  void
  */
 public function install($id_area, $plugin_name)
 {
     $msg = null;
     // check permission
     $msg = AdmUtils_helper::chk_priv_level($_SESSION['xuid'], '_module_install', 0, 4);
     if (is_null($msg)) {
         $qs = X4Route_core::get_query_string();
         // load global dictionary
         $this->dict->get_words();
         // install the plugin
         $mod = new X4Plugin_model();
         $result = $mod->install($id_area, $plugin_name);
         // the result is an array only if an error occurred
         if (is_array($result) && !empty($result)) {
             // build msg
             $str = array();
             foreach ($result as $i) {
                 $str[] = $i['label'] . _TRAIT_ . $this->dict->get_word(strtoupper($i['error'][0]), 'msg');
             }
             $msg = AdmUtils_helper::set_msg(false, '', implode('<br />', $str));
         } else {
             // set message
             $msg = AdmUtils_helper::set_msg(true);
             // installed
             if ($result) {
                 $area = $mod->get_by_id($id_area, 'areas', 'name');
                 // add permission
                 $mod = new Permission_model();
                 $array[] = array('action' => 'insert', 'id_what' => $result, 'id_user' => $_SESSION['xuid'], 'level' => 4);
                 $result = $mod->pexec('modules', $array, $id_area);
                 // refresh deep, xpos and ordinal
                 $mod = new Menu_model();
                 $mod->ordinal(1, X4Route_core::$lang, 'modules', 'A0021005');
                 $msg->update[] = array('element' => 'topic', 'url' => BASE_URL . 'modules/index/' . $id_area . '/' . $area->name, 'title' => null);
             }
         }
     }
     $this->response($msg);
 }
 /**
  * Register Edit / New Area 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 permissions
     $msg = $id ? AdmUtils_helper::chk_priv_level($_SESSION['xuid'], 'areas', $id, 2) : AdmUtils_helper::chk_priv_level($_SESSION['xuid'], '_area_creation', 0, 4);
     if (is_null($msg)) {
         // handle _post
         $post = array('lang' => $_post['lang'], 'name' => X4Utils_helper::unspace($_post['name']), 'title' => $_post['title'], 'description' => $_post['description'], 'id_theme' => $_post['id_theme'], 'private' => intval(isset($_post['private'])) && $_post['private'], 'folder' => $_post['folder']);
         $mod = new Area_model();
         // check if area name already exists
         $check = (bool) $mod->exists($post['name'], $id);
         if ($check) {
             $msg = AdmUtils_helper::set_msg(false, '', $this->dict->get_word('_AREA_ALREADY_EXISTS', 'msg'));
         } else {
             // Redirect checker
             $redirect = false;
             // enable logs
             if (LOGS && DEVEL) {
                 $mod->set_log(true);
             }
             // update or insert
             if ($id) {
                 $result = $mod->update($id, $post);
                 if ($id == 1 && X4Route_core::$lang != $post['lang']) {
                     $redirect = true;
                 }
             } else {
                 $result = $mod->insert($post);
                 // create permissions
                 if ($result[1]) {
                     $id = $result[0];
                     $perm = new Permission_model();
                     // aprivs permissions
                     $domain = X4Utils_helper::obj2array($perm->get_aprivs($_SESSION['xuid']), null, 'id_area');
                     $domain[] = $result[0];
                     $res = $perm->set_aprivs($_SESSION['xuid'], $domain);
                     // privs permissions
                     $array[] = array('action' => 'insert', 'id_what' => $id, 'id_user' => $_SESSION['xuid'], 'level' => 4);
                     $res = $perm->pexec('areas', $array, $id);
                 }
             }
             if ($result[1]) {
                 // refresh languages related to area
                 $lang = new Language_model();
                 $lang->set_alang($id, $_post['languages'], $_post['lang']);
                 // update theme settings
                 if ($_post['id'] && $_post['id_theme'] != $_post['old_id_theme']) {
                     $menu = new Menu_model();
                     // reset tpl, css, id_menu, ordinal
                     $result = $menu->reset($_post['id']);
                     $langs = $lang->get_languages();
                     // restore ordinal
                     foreach ($langs as $i) {
                         $menu->ordinal($_post['id'], $i->code, 'home', 'A');
                     }
                 }
                 if (APC) {
                     apc_clear_cache();
                     apc_clear_cache('user');
                     apc_clear_cache('opcode');
                 }
             }
             // set message
             $msg = AdmUtils_helper::set_msg($result);
             // set what update
             if ($result[1]) {
                 if ($redirect) {
                     X4Route_core::redirect($this->site->site->domain . '/admin');
                 } else {
                     $msg->update[] = array('element' => 'topic', 'url' => BASE_URL . 'areas', 'title' => null);
                 }
             }
         }
     }
     $this->response($msg);
 }