/**
  * Show the form to edit a forum
  *
  * @access	public
  * @param	string		[new|edit]
  * @param	boolean		Whether to change forum to category/back
  * @return	void		Outputs to screen
  **/
 public function forumForm($type = 'edit', $changetype = 0)
 {
     //-----------------------------------------
     // INIT
     //-----------------------------------------
     $addnew_type = ($this->request['type'] and $this->request['type']) ? $this->request['type'] : 'forum';
     $form = array();
     $forum = array();
     $forum_id = $this->request['f'] ? intval($this->request['f']) : 0;
     $parentid = intval($this->request['p']) ? intval($this->request['p']) : -1;
     $cat_id = $this->request['c'] ? intval($this->request['c']) : 0;
     $f_name = $this->request['name'] ? $this->request['name'] : '';
     $subcanpost = $cat_id == 1 ? 0 : 1;
     $perm_matrix = "";
     $dd_state = array(0 => array(1, $this->lang->words['for_active']), 1 => array(0, $this->lang->words['for_readonly']));
     $dd_moderate = array(0 => array(0, $this->lang->words['for_no']), 1 => array(1, $this->lang->words['for_modall']), 2 => array(2, $this->lang->words['for_modtop']), 3 => array(3, $this->lang->words['for_modrep']));
     $dd_prune = array(0 => array(1, $this->lang->words['for_today']), 1 => array(5, $this->lang->words['for_last5']), 2 => array(7, $this->lang->words['for_last7']), 3 => array(10, $this->lang->words['for_last10']), 4 => array(15, $this->lang->words['for_last15']), 5 => array(20, $this->lang->words['for_last20']), 6 => array(25, $this->lang->words['for_last25']), 7 => array(30, $this->lang->words['for_last30']), 8 => array(60, $this->lang->words['for_last60']), 9 => array(90, $this->lang->words['for_last90']), 10 => array(100, $this->lang->words['for_showall']));
     $dd_order = array(0 => array('last_post', $this->lang->words['for_s_last']), 1 => array('title', $this->lang->words['for_s_topic']), 2 => array('starter_name', $this->lang->words['for_s_name']), 3 => array('posts', $this->lang->words['for_s_post']), 4 => array('views', $this->lang->words['for_s_view']), 5 => array('start_date', $this->lang->words['for_s_date']), 6 => array('last_poster_name', $this->lang->words['for_s_poster']));
     $dd_by = array(0 => array('Z-A', $this->lang->words['for_desc']), 1 => array('A-Z', $this->lang->words['for_asc']));
     $dd_filter = array(0 => array('all', $this->lang->words['for_all']), 1 => array('open', $this->lang->words['for_open']), 2 => array('hot', $this->lang->words['for_hot']), 3 => array('poll', $this->lang->words['for_poll']), 4 => array('locked', $this->lang->words['for_locked']), 5 => array('moved', $this->lang->words['for_moved']), 6 => array('istarted', $this->lang->words['for_istarted']), 7 => array('ireplied', $this->lang->words['for_ireplied']));
     //-----------------------------------------
     // EDIT
     //-----------------------------------------
     if ($type == 'edit') {
         //-----------------------------------------
         // Check
         //-----------------------------------------
         if (!$forum_id) {
             $this->registry->output->showError($this->lang->words['for_noforumselected'], 11314);
         }
         //-----------------------------------------
         // Do not show forum in forum list
         //-----------------------------------------
         $this->forum_functions->exclude_from_list = $forum_id;
         //-----------------------------------------
         // Get this forum
         //-----------------------------------------
         $forum = $this->DB->buildAndFetch(array('select' => 'f.*', 'from' => array('forums' => 'f'), 'where' => 'f.id=' . $this->request['f'], 'add_join' => array(array('select' => 'p.*', 'from' => array('permission_index' => 'p'), 'where' => "p.perm_type_id=f.id AND p.app='forums' AND p.perm_type='forum'", 'type' => 'left'))));
         //-----------------------------------------
         // Check
         //-----------------------------------------
         if ($forum['id'] == "") {
             $this->registry->output->showError($this->lang->words['for_noid'], 11315);
         }
         //-----------------------------------------
         // Set up code buttons
         //-----------------------------------------
         $addnew_type = $forum['parent_id'] == -1 ? 'category' : 'forum';
         if ($changetype) {
             $addnew_type = $addnew_type == 'category' ? 'forum' : 'category';
         }
         if ($addnew_type == 'category') {
             $title = sprintf($this->lang->words['for_editcat'], $forum['name']);
             $button = $this->lang->words['for_editcat_button'];
             $code = "doedit";
         } else {
             $title = sprintf($this->lang->words['for_editfor'], $forum['name']);
             $button = $this->lang->words['for_editfor_button'];
             $code = "doedit";
         }
         if ($addnew_type == 'category') {
             $convert = "<input type='submit' class='realbutton' onclick='ACPForums.convert()' value='{$this->lang->words['for_changefor']}' />";
         } else {
             $convert = "<input type='submit' class='realbutton' onclick='ACPForums.convert()' value='{$this->lang->words['for_changecat']}' />";
         }
     } else {
         # Ensure there is an ID
         $this->request['f'] = 0;
         if ($changetype) {
             $addnew_type = $addnew_type == 'category' ? 'forum' : 'category';
         }
         if ($addnew_type == 'category') {
             $forum = array('sub_can_post' => $subcanpost, 'name' => $f_name ? $f_name : $this->lang->words['for_newcat'], 'parent_id' => $parentid, 'use_ibc' => 1, 'quick_reply' => 1, 'allow_poll' => 1, 'prune' => 100, 'topicfilter' => 'all', 'sort_key' => 'last_post', 'sort_order' => 'Z-A', 'inc_postcount' => 1, 'description' => '', 'status' => 0, 'redirect_url' => '', 'password' => '', 'password_override' => '', 'redirect_on' => 0, 'redirect_hits' => 0, 'permission_showtopic' => '', 'permission_custom_error' => '', 'use_html' => 0, 'allow_pollbump' => 0, 'forum_allow_rating' => 0, 'preview_posts' => 0, 'notify_modq_emails' => 0, 'can_view_others' => 1);
             $title = $this->lang->words['for_addcat'];
             $button = $this->lang->words['for_addcat'];
             $code = "donew";
         } else {
             $forum = array('sub_can_post' => $subcanpost, 'name' => $f_name ? $f_name : $this->lang->words['for_newfor'], 'parent_id' => $parentid, 'use_ibc' => 1, 'quick_reply' => 1, 'allow_poll' => 1, 'prune' => 100, 'topicfilter' => 'all', 'sort_key' => 'last_post', 'sort_order' => 'Z-A', 'inc_postcount' => 1, 'description' => '', 'status' => 1, 'redirect_url' => '', 'password' => '', 'password_override' => '', 'redirect_on' => 0, 'redirect_hits' => 0, 'permission_showtopic' => '', 'permission_custom_error' => '', 'use_html' => 0, 'allow_pollbump' => 0, 'forum_allow_rating' => 0, 'preview_posts' => 0, 'notify_modq_emails' => 0, 'min_posts' => 0, 'hide_last_info' => 0, 'can_view_others' => 1);
             $title = $this->lang->words['for_addfor'];
             $button = $this->lang->words['for_addfor'];
             $code = "donew";
         }
         if ($addnew_type == 'category') {
             $convert = "<input type='submit' class='realbutton' onclick='ACPForums.convert()' value='{$this->lang->words['for_changefor']}' />";
         } else {
             $convert = "<input type='submit' class='realbutton' onclick='ACPForums.convert()' value='{$this->lang->words['for_changecat']}' />";
         }
     }
     //-----------------------------------------
     // Build forumlist
     //-----------------------------------------
     $forumlist = $this->forum_functions->adForumsForumList();
     //-----------------------------------------
     // Build group list
     //-----------------------------------------
     $mem_group = array();
     foreach ($this->caches['group_cache'] as $g_id => $group) {
         $mem_group[] = array($g_id, $group['g_title']);
     }
     //-----------------------------------------
     // Page title...
     //-----------------------------------------
     //$this->registry->output->html_help_title = $title;
     //-----------------------------------------
     // Generate form items
     //-----------------------------------------
     # Main settings
     $form['name'] = $this->registry->output->formInput('name', (isset($_POST['name']) and $_POST['name']) ? IPSText::parseCleanValue($_POST['name']) : $forum['name']);
     $form['description'] = $this->registry->output->formTextarea("description", IPSText::br2nl((isset($_POST['description']) and $_POST['description']) ? $_POST['description'] : $forum['description']));
     $form['parent_id'] = $this->registry->output->formDropdown("parent_id", $forumlist, (isset($_POST['parent_id']) and $_POST['parent_id']) ? $_POST['parent_id'] : $forum['parent_id']);
     $form['status'] = $this->registry->output->formDropdown("status", $dd_state, (isset($_POST['status']) and $_POST['status']) ? $_POST['status'] : $forum['status']);
     $form['sub_can_post'] = $this->registry->output->formYesNo('sub_can_post', (isset($_POST['sub_can_post']) and $_POST['sub_can_post']) ? $_POST['sub_can_post'] : ($forum['sub_can_post'] == 1 ? 0 : 1));
     # Redirect options
     $form['redirect_url'] = $this->registry->output->formInput('redirect_url', (isset($_POST['redirect_url']) and $_POST['redirect_url']) ? $_POST['redirect_url'] : $forum['redirect_url']);
     $form['redirect_on'] = $this->registry->output->formYesNo('redirect_on', (isset($_POST['redirect_on']) and $_POST['redirect_on']) ? $_POST['redirect_on'] : $forum['redirect_on']);
     $form['redirect_hits'] = $this->registry->output->formInput('redirect_hits', (isset($_POST['redirect_hits']) and $_POST['redirect_hits']) ? $_POST['redirect_hits'] : $forum['redirect_hits']);
     # Permission settings
     $form['permission_showtopic'] = $this->registry->output->formYesNo('permission_showtopic', (isset($_POST['permission_showtopic']) and $_POST['permission_showtopic']) ? $_POST['permission_showtopic'] : $forum['permission_showtopic']);
     $form['permission_custom_error'] = $this->registry->output->formTextarea("permission_custom_error", IPSText::br2nl((isset($_POST['permission_custom_error']) and $_POST['permission_custom_error']) ? $_POST['permission_custom_error'] : $forum['permission_custom_error']));
     # Forum settings
     $form['use_html'] = $this->registry->output->formYesNo('use_html', (isset($_POST['use_html']) and $_POST['use_html']) ? $_POST['use_html'] : $forum['use_html']);
     $form['use_ibc'] = $this->registry->output->formYesNo('use_ibc', (isset($_POST['use_ibc']) and $_POST['use_ibc']) ? $_POST['use_ibc'] : $forum['use_ibc']);
     $form['quick_reply'] = $this->registry->output->formYesNo('quick_reply', (isset($_POST['quick_reply']) and $_POST['quick_reply']) ? $_POST['quick_reply'] : $forum['quick_reply']);
     $form['allow_poll'] = $this->registry->output->formYesNo('allow_poll', (isset($_POST['allow_poll']) and $_POST['allow_poll']) ? $_POST['allow_poll'] : $forum['allow_poll']);
     $form['allow_pollbump'] = $this->registry->output->formYesNo('allow_pollbump', (isset($_POST['allow_pollbump']) and $_POST['allow_pollbump']) ? $_POST['allow_pollbump'] : $forum['allow_pollbump']);
     $form['inc_postcount'] = $this->registry->output->formYesNo('inc_postcount', (isset($_POST['inc_postcount']) and $_POST['inc_postcount']) ? $_POST['inc_postcount'] : $forum['inc_postcount']);
     $form['forum_allow_rating'] = $this->registry->output->formYesNo('forum_allow_rating', (isset($_POST['forum_allow_rating']) and $_POST['forum_allow_rating']) ? $_POST['forum_allow_rating'] : $forum['forum_allow_rating']);
     $form['min_posts_post'] = $this->registry->output->formInput('min_posts_post', (isset($_POST['min_posts_post']) and $_POST['min_posts_post']) ? $_POST['min_posts_post'] : $forum['min_posts_post']);
     $form['min_posts_view'] = $this->registry->output->formInput('min_posts_view', (isset($_POST['min_posts_view']) and $_POST['min_posts_view']) ? $_POST['min_posts_view'] : $forum['min_posts_view']);
     $form['can_view_others'] = $this->registry->output->formYesNo('can_view_others', (isset($_POST['can_view_others']) and $_POST['can_view_others']) ? $_POST['can_view_others'] : $forum['can_view_others']);
     $form['hide_last_info'] = $this->registry->output->formYesNo('hide_last_info', (isset($_POST['hide_last_info']) and $_POST['hide_last_info']) ? $_POST['hide_last_info'] : $forum['hide_last_info']);
     # Mod settings
     $form['preview_posts'] = $this->registry->output->formDropdown("preview_posts", $dd_moderate, (isset($_POST['preview_posts']) and $_POST['preview_posts']) ? $_POST['preview_posts'] : $forum['preview_posts']);
     $form['notify_modq_emails'] = $this->registry->output->formInput('notify_modq_emails', (isset($_POST['notify_modq_emails']) and $_POST['notify_modq_emails']) ? $_POST['notify_modq_emails'] : $forum['notify_modq_emails']);
     $form['password'] = $this->registry->output->formInput('password', (isset($_POST['password']) and $_POST['password']) ? $_POST['password'] : $forum['password']);
     $form['password_override'] = $this->registry->output->formMultiDropdown('password_override[]', $mem_group, (isset($_POST['password_override']) and $_POST['password_override']) ? $_POST['password_override'] : explode(",", $forum['password_override']));
     # Sorting settings
     $form['prune'] = $this->registry->output->formDropdown("prune", $dd_prune, (isset($_POST['prune']) and $_POST['prune']) ? $_POST['prune'] : $forum['prune']);
     $form['sort_key'] = $this->registry->output->formDropdown("sort_key", $dd_order, (isset($_POST['sort_key']) and $_POST['sort_key']) ? $_POST['sort_key'] : $forum['sort_key']);
     $form['sort_order'] = $this->registry->output->formDropdown("sort_order", $dd_by, (isset($_POST['sort_order']) and $_POST['sort_order']) ? $_POST['sort_order'] : $forum['sort_order']);
     $form['topicfilter'] = $this->registry->output->formDropdown("topicfilter", $dd_filter, (isset($_POST['topicfilter']) and $_POST['topicfilter']) ? $_POST['topicfilter'] : $forum['topicfilter']);
     # Trim the form for categories...
     $form['addnew_type'] = $addnew_type;
     $this->request['type'] = $addnew_type;
     $form['addnew_type_upper'] = ucwords($addnew_type);
     $form['convert_button'] =& $convert;
     //-----------------------------------------
     // Show permission matrix
     //-----------------------------------------
     if ($type != 'edit' or $addnew_type == 'category') {
         /* Permission Class */
         require_once IPS_ROOT_PATH . 'sources/classes/class_public_permissions.php';
         $permissions = new classPublicPermissions(ipsRegistry::instance());
         if ($addnew_type == 'category') {
             $perm_matrix = $permissions->adminPermMatrix('forum', $forum, 'forums', 'view');
         } else {
             $perm_matrix = $permissions->adminPermMatrix('forum', $forum);
         }
     }
     //-----------------------------------------
     // Show form...
     //-----------------------------------------
     $this->registry->output->html .= $this->html->forumForm($form, $button, $code, $title, $forum, $perm_matrix);
     //-----------------------------------------
     // Nav and print
     //-----------------------------------------
     //ipsRegistry::getClass('adminOuput')->nav[] = array( $this->form_code, 'Manage Forums' );
     //ipsRegistry::getClass('adminOuput')->nav[] = array( '', 'Add/Edit '.ucwords($addnew_type) );
 }
 /**
  * Shows the forum permission preview popup
  *
  * @access	public
  * @return	void
  **/
 public function previewForumPermissions()
 {
     /* Check ID */
     $perm_id = intval($this->request['id']);
     if (!$perm_id) {
         $this->registry->output->showError($this->lang->words['per_setid'], 11342);
     }
     /* Query the set name */
     $this->DB->build(array('select' => '*', 'from' => 'forum_perms', 'where' => "perm_id=" . $perm_id));
     $this->DB->execute();
     if (!($perms = $this->DB->fetch())) {
         $this->registry->output->showError($this->lang->words['per_setid'], 11343);
     }
     /* Type of permission to preview */
     switch ($this->request['t']) {
         case 'start':
             $human_type = $this->lang->words['per_start'];
             $code_word = 'perm_4';
             break;
         case 'reply':
             $human_type = $this->lang->words['per_reply'];
             $code_word = 'perm_3';
             break;
         case 'show':
             $human_type = $this->lang->words['per_show'];
             $code_word = 'perm_view';
             break;
         case 'upload':
             $human_type = $this->lang->words['per_upload'];
             $code_word = 'perm_5';
             break;
         case 'download':
             $human_type = $this->lang->words['per_download'];
             $code_word = 'perm_6';
             break;
         default:
             $human_type = $this->lang->words['per_read'];
             $code_word = 'perm_2';
             break;
     }
     /* Get forums */
     $theforums = $this->forumfunc->adForumsForumList(1);
     /* Loop through forums */
     $rows = array();
     foreach ($theforums as $v) {
         $id = $v[0];
         $name = $v[1];
         $this->registry->class_forums->forum_by_id[$id][$code_word] = isset($this->registry->class_forums->forum_by_id[$id][$code_word]) ? $this->registry->class_forums->forum_by_id[$id][$code_word] : '';
         if ($this->registry->class_forums->forum_by_id[$id][$code_word] == '*') {
             $rows[] = array('css' => 'color:green', 'name' => $name);
         } else {
             if (preg_match("/(^|,)" . $perm_id . "(,|\$)/", $this->registry->class_forums->forum_by_id[$id][$code_word])) {
                 $rows[] = array('css' => 'color:green;font-weight:bold', 'name' => $name);
             } else {
                 if ($code_word != 'perm_view' and $this->registry->class_forums->forum_by_id[$id]['parent_id'] == 'root') {
                     /* Categories */
                     $rows[] = array('css' => 'color:grey', 'name' => $name);
                 } else {
                     /* No Access */
                     $rows[] = array('css' => 'color:red;font-weight:bold', 'name' => $name);
                 }
             }
         }
     }
     $type_drop = $this->registry->output->formDropdown('t', array(array('start', $this->lang->words['per_start_m']), array('reply', $this->lang->words['per_reply_m']), array('read', $this->lang->words['per_read_m']), array('show', $this->lang->words['per_show_m']), array('upload', $this->lang->words['per_upload_m']), array('download', $this->lang->words['per_download_m'])), $this->request['t']);
     /* Output */
     $this->registry->output->html .= $this->html->previewForumPermissions($id, $perms['perm_name'], $type_drop, $rows, $human_type);
     $this->registry->output->printPopupWindow();
 }