<?php
  
  include ("$www_dir/classes/topics.class.php");
  $SBBTopics = new SBBTopics();
  $SBBTopics->fid = $fid;

  $show = $_REQUEST["show"];

  $NAV_PAGES = array();

  if (!$forum[$fid]) {  //forum not avail
    /************
     * initiate template and assign variables
     ************/         
    $QuickSkin = new QuickSkin("status_messages.html");
    $QuickSkin->assign("INFO",lang("forum_notfound"));
    $content .= $QuickSkin->result();
    unset($QuickSkin);
  } else {              //forum avail
  
      $SBBAuth->update_last_visit();
  
      $breadcrumps[] = array("link" => $board_config->seo ? "$main_path/sbbf" . $fid . adddescr2link($forum[$fid]->title) . ".html" : "$main_script?todo=show_topics&amp;fid=$fid", 
                           "descr" => $forum[$fid]->title);

        //TEMPLATE_VARIABLES
        $DESCR_TOPIC = lang("topics");
        $DESCR_AUTHOR = lang("author");
        $DESCR_VIEWS = lang("views");
        $DESCR_REPLIES = lang("replies");
        $DESCR_LASTPOST = lang("last_post");
        $DESCR_POLL = lang("poll");
        $IMG_NEWTOPIC_TITLE = lang("btn_new_topic");
        $IMG_STICKY_TITLE = lang("important_topic");
        $IMG_WATCH_TITLE = lang("topic_on_watchlist");
        $IMG_ATTACHMENT_TITLE = lang("attachments");
    
        $DESCR_RSS = lang("rss_subscribe");
    
        $LINK_ADD_TOPIC = ($board_config->seo ? "$main_path/sbb-add-topic.html?fid=$fid" : "$main_script?todo=add_topic&amp;fid=$fid");

        $FORUM_ID = $fid;

        if (!$is_mod) {
          unset($show);
        }

        //check if forum is watched
        if ($SBBTopics->forum_watched()) {
          $DESCR_WATCHFORUM = lang("unwatch_forum");
          $IMG_WATCH_PREFIX = "un";  //prefix for the lock image (unlock/lock)
        } else {
          $DESCR_WATCHFORUM = lang("watch_forum");
        }

        
        //get topics
        $SBBTopics->GetTopics();
        
        if (!$SBBTopics->count) { //no topics found
          //TEMPLATE_VARS
          $NO_TOPICS = lang("no_topics");
        } else { //found topics
          for ($i=0;$i<$SBBTopics->count;$i++) {
            $row = $SBBTopics->topics[$i];
            $this_user = forum_user($row->uid);
            $this_a_user = ($row->a_uid ? forum_user($row->a_uid) : $this_user);
            //assign to template array
            $TOPICS[] = array("IMG_TOPIC_ADD2" => (!$row->reply ? "no" : ""),
                              "IMG_TOPIC_SUFFIX" => ($row->locked ? "_locked" : ""),
                              "TOPIC_ID" => $row->id,
                              "TOPIC_TITLE" => $row->topic,
                              "LINK_TOPIC" => ($board_config->seo ? "$main_path/sbbt" . $row->id . adddescr2link($row->topic) . ".html?" : "$main_script?todo=viewtopic&amp;tid=" . $row->id . "&amp;"),
                              "PAGES" => $board_config->posts_per_page ? ceil(($row->reply+1)/$board_config->posts_per_page) : 1,
                              "TOPIC_POSTER" => ($this_user ? 
                                                 "<a href='" . ($board_config->seo ? "$main_path/sbb-user" . $this_user->id . adddescr2link($his_user->user) . ".html" : "$main_script?todo=showprofile&amp;uid=" . $this_user->id) . "' class='anu " . nick_class($this_user->is_admin, $this_user->is_mod) . "'>" . $this_user->user . "</a>" : 
                                                 $row->name),
                              "TOPIC_VIEWS" => $row->view,
                              "TOPIC_REPLIES" => $row->reply,
                              "TOPIC_LASTDATE" => date($date_time_format,strtotime($row->a_datetime ? $row->a_datetime : $row->datetime)),
                              "TOPIC_LASTUSER" => ($this_a_user ? 
                                                   "<a href='" . ($board_config->seo ? "$main_path/sbb-user" . $this_a_user->id . adddescr2link($this_a_user->user) . ".html" : "$main_script?todo=showprofile&amp;uid=" . $this_user->id) . "' class='anu " . nick_class($this_a_user->is_admin, $this_a_user->is_mod) . "'>" . $this_a_user->user . "</a>" : 
                                                   $row->a_name),
                              "TOPIC_LASTPOSTID" => $row->reply,
                              "IMG_LASTTOPICTITLE" => lang("to_last_topic"),
                              "TOPIC_LEAD" => stripQuotes(substr(strip_tags(strip_bbcodes($row->detail)),0,155)) . "...",
                              "TOPIC_CLASS" => ($row->unseen ? "b" : ""),
                              "IS_STICKY" => $row->sticky,
                              "HAS_ATTACHMENTS" => $row->attachment,
                              "HAS_POLL" => $board_config->en_polls && $row->poll_title ? true : false,
                              "WATCHED" => $row->watched,
                            );
          }
        }

        //pagination
        $LINK_PAGE_PREFIX = ($board_config->seo ? "$main_path/sbbf" . $fid . adddescr2link($forum[$fid]->title) . ".html?p=" : "$main_script?todo=show_topics&amp;fid=$fid&amp;p=");
        $NAV_PAGES = pagination2ndGen($SBBTopics->pages,$SBBTopics->p);
        $PAGE = $SBBTopics->p;
        if ($show) {
          $PAGER_SUFFIX = "&amp;show=$show";
          $DESCR_ADM_TOPICS = lang("default_topics_view");
          $TEMPLATE_FLAGS["TCB"] = true;
        } else {
          $NEW_SHOW_VAL = "adm_topics";
          $DESCR_ADM_TOPICS = lang("adm_topics");
        }
        
        $DESCR_TOGGLE_SELECTION = lang("descr_toggle_selection");
        $DESCR_DEL_SELECTED_TOPICS = lang("descr_del_selected_topics");
        $CONFIRM_DELTOPICS = lang("confirm_deltopics");
        
        //txt export
        $LINK_RSSFEED = ($board_config->seo ? "$main_path/sbbf" . $fid . ".rss" : "$rel_path/rss.php?fid=$fid");  
        
    /************
     * initiate template and assign variables
     ************/  

      $showtopicsVARS = array('LINK_RSSFEED' => $LINK_RSSFEED,
                              'DESCR_RSS' => $DESCR_RSS,
                              'DESCR_TOPIC' => $DESCR_TOPIC,
                              'DESCR_AUTHOR' => $DESCR_AUTHOR,
                              'DESCR_VIEWS' => $DESCR_VIEWS,
                              'DESCR_POLL' => $DESCR_POLL,
                              'DESCR_REPLIES' => $DESCR_REPLIES,
                              'DESCR_LASTPOST' => $DESCR_LASTPOST,
                              'CONF_MAINSCRIPT' => $CONF_MAINSCRIPT,
                              'NO_TOPICS' => $NO_TOPICS,
                              'IMG_NEWTOPIC_TITLE' => $IMG_NEWTOPIC_TITLE,
                              'IMG_STICKY_TITLE' => $IMG_STICKY_TITLE,
                              'IMG_ATTACHMENT_TITLE' => $IMG_ATTACHMENT_TITLE,
                              'IMG_TOPIC_SUFFIX' => $IMG_TOPIC_SUFFIX,
                              'IMG_WATCH_TITLE' => $IMG_WATCH_TITLE,
                              'DESCR_WATCHFORUM' => $DESCR_WATCHFORUM,
                              'IMG_WATCH_PREFIX' => $IMG_WATCH_PREFIX,
                              'FORUM_ID' => $FORUM_ID,
                              'DESCR_ADM_TOPICS' => $DESCR_ADM_TOPICS,
                              'PAGE' => $PAGE,
                              'PAGER_SUFFIX' => $PAGER_SUFFIX,
                              'NEW_SHOW_VAL' => $NEW_SHOW_VAL,
                              'DESCR_TOGGLE_SELECTION' => $DESCR_TOGGLE_SELECTION,
                              'DESCR_DEL_SELECTED_TOPICS' => $DESCR_DEL_SELECTED_TOPICS,
                              'CONFIRM_DELTOPICS' => $CONFIRM_DELTOPICS,
                              'LINK_ADD_TOPIC' => $LINK_ADD_TOPIC,
                              'LINK_PAGE_PREFIX' => $LINK_PAGE_PREFIX,

                              "CONF" => $GLOBAL_TEMPLATE_VARS,
                              "TOPICS" => $TOPICS,
                              "FLAGS" => $TEMPLATE_FLAGS, 
                              "NAV_PAGES" => $NAV_PAGES
                              );

      $QuickSkin = new QuickSkin("show_topics.html");
      $QuickSkin->assign($showtopicsVARS);
      $content .= $QuickSkin->result();
      unset($QuickSkin);
    

    }




?>