<?php


  $TABLE_HEADLINE = lang("tab_adminboard");
  $FORUMS_HEADLINE = lang("tab_adminforums");
  $USERS_HEADLINE = lang("tab_adminusers");
  $USERRANKS_HEADLINE = lang("tab_adminuserranks");
  
  $LINK_BOARD = ($board_config->seo ? "$main_path/sbb-admin.html" : "$main_script?todo=admin");
  $LINK_FORUMS = ($board_config->seo ? "$main_path/sbb-admin-forums.html" : "$main_script?todo=adminforums");
  $LINK_USERS = ($board_config->seo ? "$main_path/sbb-admin-users.html" : "$main_script?todo=adminusers");
  $LINK_USERRANKS = ($board_config->seo ? "$main_path/sbb-admin-userranks.html" : "$main_script?todo=adminuserranks");
  
  $DESCR_ADD_FORUM = lang("hl_create_forum");
  $DESCR_ADD_CATEGORY = lang("hl_create_category");
  $DESCR_CATEGORY = lang("descr_category");
  $DESCR_VIEW_PERMISSIONS = lang("descr_view_permissions");
  $DESCR_POST_PERMISSIONS = lang("descr_post_permissions");
  $DESCR_REPLY_PERMISSIONS = lang("descr_reply_permissions");

  $BACK = lang("back");

  $sbb_add2title .= " - " . he(lang("tab_adminforums"));
  
  if (!$section) {
    $YOUR_FORUMS_HEADLINE = lang("defined_forums");
    $YOUR_CATEGORIES_HEADLINE = lang("defined_categories");
    
    $CONFIRM_DELFORUM = lang("conf_delforum");
    $CONFIRM_DELCATEGORY = lang("conf_delcategory");
    
    //the forums
    $forums = $SBBForums->GetForums();
    if (!$SBBForums->count) {
      $NO_FORUMS = lang("no_forums");
    } else {
      
      $category[0]->title = lang("not_categorized");      
      $j=0;
      for ($i=0;$i<$SBBForums->count;$i++) {
        $row = $forums[$i];
        unset($cat_hl,$cat_descr);
        if ($row->cat_id != $tmp_cat_id) {
          $cat_hl = $category[$row->cat_id]->title;
          $cat_descr = $category[$row->cat_id]->descr;
          $j=0;
        }
        $FORUMS_ARR[] = array("ID" => $row->id,
                              "CATHL" => $cat_hl,
                              "CATDESCR" => $cat_descr,
                              "TITLE" => $row->title,
                              "DESCR" => ($row->descr ? $row->descr : "&nbsp;"),
                              "POS" => $row->pos,
                              "IMG_FORUM_SUFFIX" => "",
                              "IMG_UP_SUFFIX" => ($j==0?"_dis":""),
                              "UP_LINK" => ($j>0?"$main_script?action=admin_forum&amp;saction=up&amp;id=" . $row->id:"#"),
                              "IMG_DOWN_SUFFIX" => ($j==($SBBForums->cat_count[$row->cat_id]-1)?"_dis":""),
                              "DOWN_LINK" => ($j==($SBBForums->cat_count[$row->cat_id]-1)?"#":"$main_script?action=admin_forum&amp;saction=down&amp;id=" . $row->id),
                              "FORUM_LINK" => ($board_config->seo ? "$main_path/sbbf" . $row->id . adddescr2link($row->title) . ".html" : "$main_script?todo=show_topics&amp;fid=" . $row->id)
                        );
        $tmp_cat_id = $row->cat_id;
        $j++;
      }
    }
    
    
    
    
    //the categories
    $categories = $SBBForums->GetCategories();
    $NO_CATEGORIES = lang("no_categories");
    if ($SBBForums->count) {
      for ($i=0;$i<$SBBForums->count;$i++) {
        $row = $categories[$i];
        $CATEGORIES_ARR[] = array("ID" => $row->id,
                                  "TITLE" => $row->title,
                                  "DESCR" => ($row->descr ? $row->descr : "&nbsp;"),
                                  "POS" => $row->pos,
                                  "IMG_FORUM_SUFFIX" => "",
                                  "IMG_UP_SUFFIX" => ($i==0?"_dis":""),
                                  "UP_LINK" => ($i>0?"$main_script?action=admin_forum&amp;saction=upc&amp;id=" . $row->id:"#"),
                                  "IMG_DOWN_SUFFIX" => ($i==($SBBForums->count-1)?"_dis":""),
                                  "DOWN_LINK" => ($i==($SBBForums->count-1)?"#":"$main_script?action=admin_forum&amp;saction=downc&amp;id=" . $row->id),
                        );
      }
    }
  }

  $TEMPLATE_FLAGS["SHOWFORUMS"] = true;
  if ($section == "edit") {
    $TEMPLATE_FLAGS["SHOWFORUMS"] = false;
    $TEMPLATE_FLAGS["EDITFORUM"] = true;
    $id = intval($_REQUEST["id"]);
    if ($id) {
      if (!$action) {
        $forum_title = $forum[$id]->title;
        $forum_descr = $forum[$id]->descr;
        $cat_id = $forum[$id]->cat_id;
        $vperm = $forum[$id]->viewing_permission;
        $pperm = $forum[$id]->posting_permission;
        $rperm = $forum[$id]->reply_permission;
      }
      $YOUR_FORUMS_HEADLINE = lang("hl_edit_forum");
    } else {
      $YOUR_FORUMS_HEADLINE = lang("hl_create_forum");
    }
    //categories
    $cat_options = "<option value='0'>" . lang("no_category") . "</option>\n";
    for ($i=0;$i<count($categories);$i++) {
      $this_cat = $categories[$i];
      $cat_options .= "<option value='" . $this_cat->id . "'>" . $this_cat->title . "</option>\n";
    }
    $cat_options = str_replace("value='$cat_id'", "value='$cat_id' selected='selected'", $cat_options);
    
    //permissions
    $perm_options = "<option value='0'>" . lang("perm_all") . "</option>
      <option value='1'>" . lang("perm_reg") . "</option>
      <option value='2'>" . lang("perm_mod") . "</option>
      <option value='3'>" . lang("perm_adm") . "</option>\n";
    $vperm_options = str_replace("value='$vperm'", "value='$vperm' selected='selected'", $perm_options);
    $pperm_options = str_replace("value='$pperm'", "value='$pperm' selected='selected'", $perm_options);
    $rperm_options = str_replace("value='$rperm'", "value='$rperm' selected='selected'", $perm_options);
    
    $DESCR_TITLE = lang("forum_title");
    $DESCR_DESCR = lang("forum_descr");
    $DESCR_SUBMIT = lang("save_settings");
    
        
    //The Form
    $FORM_VAL_ID = $id;
    $FORM_VAL_TITLE = he($forum_title);
    $FORM_VAL_DESCR = he($forum_descr);
    $FORM_OPTIONS_CAT_ID = $cat_options;
    $FORM_OPTIONS_VPERM = $vperm_options;
    $FORM_OPTIONS_PPERM = $pperm_options;
    $FORM_OPTIONS_RPERM = $rperm_options;
    
    
  }
  
  if ($section == "editc") {
    $TEMPLATE_FLAGS["SHOWFORUMS"] = false;
    $TEMPLATE_FLAGS["EDITCATEGORY"] = true;
    $id = intval($_REQUEST["id"]);
    if ($id) {
      if (!$action) {
        $category_title = $category[$id]->title;
        $category_descr = $category[$id]->descr;
      }
      $YOUR_FORUMS_HEADLINE = lang("hl_edit_category");
    } else {
      $YOUR_FORUMS_HEADLINE = lang("hl_create_category");
    }
    $DESCR_TITLE = lang("category_title");
    $DESCR_DESCR = lang("category_descr");
    $DESCR_SUBMIT = lang("save_settings");
        
    //The Form
    $FORM_VAL_ID = $id;
    $FORM_VAL_TITLE = he($category_title);
    $FORM_VAL_DESCR = he($category_descr);
    
  }


  /************
   * initiate template and assign variables
   ************/         

  $adminforumsVARS = array('TABLE_HEADLINE' => $TABLE_HEADLINE,
                          'FORUMS_HEADLINE' => $FORUMS_HEADLINE,
                          'LINK_BOARD' => $LINK_BOARD,
                          'USERS_HEADLINE' => $USERS_HEADLINE,
                          'LINK_USERS' => $LINK_USERS,
                          'YOUR_FORUMS_HEADLINE' => $YOUR_FORUMS_HEADLINE,
                          'LINK_FORUMS' => $LINK_FORUMS,
                          'YOUR_CATEGORIES_HEADLINE' => $YOUR_CATEGORIES_HEADLINE,
                          'DESCR_ADD_CATEGORY' => $DESCR_ADD_CATEGORY,
                          'YOUR_CATEGORIES_HEADLINE' => $YOUR_CATEGORIES_HEADLINE,
                          'CONFIRM_DELCATEGORY' => $CONFIRM_DELCATEGORY,
                          'NO_CATEGORIES' => $NO_CATEGORIES,
                          'FORM_OPTIONS_CAT_ID' => $FORM_OPTIONS_CAT_ID,
                          'DESCR_CATEGORY' => $DESCR_CATEGORY,
                          'FORM_OPTIONS_VPERM' => $FORM_OPTIONS_VPERM,
                          'DESCR_VIEW_PERMISSIONS' => $DESCR_VIEW_PERMISSIONS,
                          'FORM_OPTIONS_PPERM' => $FORM_OPTIONS_PPERM,
                          'DESCR_POST_PERMISSIONS' => $DESCR_POST_PERMISSIONS,
                          'FORM_OPTIONS_RPERM' => $FORM_OPTIONS_RPERM,
                          'DESCR_REPLY_PERMISSIONS' => $DESCR_REPLY_PERMISSIONS,
                          'LINK_USERRANKS' => $LINK_USERRANKS,
                          'USERRANKS_HEADLINE' => $USERRANKS_HEADLINE,
                          'NO_FORUMS' => $NO_FORUMS,
                          'LINK_ADD_FORUM' => $LINK_ADD_FORUM,
                          'DESCR_ADD_FORUM' => $DESCR_ADD_FORUM,
                          'DESCR_DESCR' => $DESCR_DESCR,
                          'DESCR_TITLE' => $DESCR_TITLE,
                          'DESCR_SUBMIT' => $DESCR_SUBMIT,
                          'CONFIRM_DELFORUM' => $CONFIRM_DELFORUM,
                          'FORM_VAL_ID' => $FORM_VAL_ID,
                          'FORM_VAL_TITLE' => $FORM_VAL_TITLE,
                          'FORM_VAL_DESCR' => $FORM_VAL_DESCR,
                          'BACK' => $BACK,

                          //arrays
                          'CONF' => $GLOBAL_TEMPLATE_VARS,
                          'FLAGS' => $TEMPLATE_FLAGS,
                          'FORUMS_ARR' => $FORUMS_ARR,
                          'CATEGORIES_ARR' => $CATEGORIES_ARR
                          );

  $QuickSkin = new QuickSkin("admin-forums.html");
  $QuickSkin->assign($adminforumsVARS);
  $content .= $QuickSkin->result();
  unset($QuickSkin);

     

?>