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

  $show = $_REQUEST["show"];

  if (!$forum[$fid]) {  //forum not avail
    $content .= "<div class='infobox'>" . lang("forum_notfound") . "</div>";
  } else {              //forum avail
  
      $SBBAuth->update_last_visit();
  
      $breadcrumps[] = "<a href='" . ($board_config->seo ? "$main_path/sbbf" . $fid . adddescr2link($forum[$fid]->title) . ".html" : "$main_script?todo=show_topics&amp;fid=$fid") . "'>" . $forum[$fid]->title . "</a>";

        //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("createtopic");
        $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) {
          $hide_blocks[] = "ISMOD";
          unset($show);
        }
        if (!$f_auth_uid) $hide_blocks[] = "LOGGEDIN";

        
        //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
          $hide_blocks[] = "NOTOPICS";
          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" => he(substr(strip_tags(strip_bbcodes($row->detail)),0,155)) . "...",
                              "TOPIC_CLASS" => ($row->unseen ? "b" : ""),
                            );
            //showhide for sticky topics icon
            if (!$row->sticky) $hide_blocks[] = "TOPIC_IS_STICKY" . intval($row->id);
            //showhide for attachments in topic icon
            if (!$row->attachment) $hide_blocks[] = "TOPIC_HAS_ATTACHMENT" . intval($row->id);
            //mark watched topics
            if (!$row->watched) $hide_blocks[] = "TOPIC_WATCH" . intval($row->id);
            //poll within topic
            if (!$board_config->en_polls || !$row->poll_title) $hide_blocks[] = "TOPIC_WITH_POLL" . intval($row->id);
          }
        }

        //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 = pagination($SBBTopics->pages,$SBBTopics->p);
        $PAGE = $SBBTopics->p;
        if ($show) {
          $PAGER_SUFFIX = "&amp;show=$show";
          $DESCR_ADM_TOPICS = lang("default_topics_view");
        } else {
          $hide_blocks[] = "TCB";
          $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");

        //hide navblock if empty
        if (!$NAV_PAGES) $hide_blocks[] = "NAV_PAGES";
        
        //txt export
        $LINK_RSSFEED = ($board_config->seo ? "$main_path/sbbf" . $fid . ".rss" : "$rel_path/rss.php?fid=$fid");  
        
    /************
     * initiate template and assign variables
     ************/  
      $tpl->load_file("show_topics", "$template_path/show_topics.html");
      $tpl->parse_loop('show_topics', 'TOPICS');
      if ($NAV_PAGES) $tpl->parse_loop('show_topics', 'NAV_PAGES');
      if ($hide_blocks) $tpl->parse_hide('show_topics', $hide_blocks);
      //write the template-file to the content-var
      $content .= $tpl->pget('show_topics', array('CONF_MAINSCRIPT', 'CONF_RELPATH', 'CONF_LANG', 'CONF_TEMPLATE_PATH', 'CONF_FORUMTITLE', 'LINK_RSSFEED', 'DESCR_RSS',
        'DESCR_TOPIC', 'DESCR_AUTHOR', 'DESCR_VIEWS', 'DESCR_POLL', 'DESCR_REPLIES', 'DESCR_LASTPOST', 'CONF_MAINSCRIPT', 'NO_TOPICS', 'IMG_NEWTOPIC_TITLE', 'IMG_STICKY_TITLE', 'IMG_ATTACHMENT_TITLE', 'IMG_TOPIC_SUFFIX', 'IMG_WATCH_TITLE', 'DESCR_WATCHFORUM','IMG_WATCH_PREFIX', 'FORUM_ID', 'DESCR_ADM_TOPICS', 'PAGE', 'PAGER_SUFFIX', 'NEW_SHOW_VAL', 'DESCR_TOGGLE_SELECTION', 'DESCR_DEL_SELECTED_TOPICS', 'CONFIRM_DELTOPICS',
        'LINK_ADD_TOPIC', 'LINK_PAGE_PREFIX'));

    
    }




?>