<?php

/****
 * for the first just the admin is able to edit
 ****/ 

include ("$www_dir/classes/topics.class.php");
$SBBTopics = new SBBTopics();

$tid = intval($_REQUEST["tid"]);
$pid = intval($_REQUEST["pid"]);

$SBBTopics->tid = $tid;
$SBBTopics->pid = $pid;

$FORM_VAL_ACTION = "edit_post";
$hide_blocks[] = "TOPICFOUND";
$hide_blocks[] = "TOPICLOCKED";
$HEADLINE_VOTING = lang("create_poll");
$DESCR_CREATE_POLL_INFO = lang("create_poll_info");
$DESCR_VOTEQ = lang("poll_question");
$DESCR_VOTEA = lang("poll_options");
$DESCR_VOTEA_INFO = lang("poll_options_info");
if ($board_config->max_poll_options) $DESCR_VOTEA_SUBINFO = sprintf(lang("poll_options_subinfo"), $board_config->max_poll_options);
$DESCR_VOTEMULTIA = lang("poll_multi");
$DESCR_ENMULTI = lang("poll_multi_info");
$DESCR_DURATION = lang("poll_duration");
$DESCR_DURATION_INFO = lang("poll_duration_info");
$FORM_VAL_FTS = "";

$HEADLINE_ATTACHMENT = lang("add_attachment");
$DESCR_ATTACHMENT_INFO = sprintf(lang("descr_attachment_info"),$board_config->max_attachment_size);
$DESCR_ATT_FILE = lang("descr_att_file");
$DESCR_ATT_DESCR = lang("descr_att_descr");
$DESCR_OPTIONAL = lang("optional");
$DESCR_DELETE = lang("delete");

$CONFIRM_DELATTACHMENT = lang("confirm_delattachment");

$DESCR_MORE_SMILIES = lang("more_smilies");
$HEADLINE_SMILIES = lang("hl_more_smilies");

  //topicid is avail in every case
  $row = $SBBTopics->GetSingleTopic();
  
  if ($row->topic) {
    $breadcrumps[] = "<a href='" . ($board_config->seo ? "$main_path/sbbf" . $row->fid . adddescr2link($forum[$row->fid]->title) . ".html" : "$main_script?todo=show_topics&amp;fid=" . $row->fid) . "'>" . $forum[$row->fid]->title . "</a>";
    $breadcrumps[] = "<a href='" . ($board_config->seo ? "$main_path/sbbt" . $tid . adddescr2link($row->topic) . ".html" : "$main_script?todo=viewtopic&amp;tid=$tid") . "'>" . $row->topic . "</a>";
    $sbb_add2title .= " - " . he($row->topic);
  }
  
  $TOPIC_TITLE = $row->topic;
  $TOPIC_ID = $tid;
  $FORUM_ID = $row->fid;
  
  if (!$pid && $tid) {
    if (mysql_num_rows($res)) $postfound = true;
    if (!$action) {
      $topic = $row->topic;
      $message = $row->detail;
      $sticky = $row->sticky;
      $poll_title = $row->poll_title;
      $poll_options = $row->poll_options;
      $poll_multiple = $row->poll_multiple;
      $poll_duration = $row->poll_duration;
    }
    $is_topic = true;
    //check attachments
    if ($row->attachments) {
      $attcnt = count($row->attachments);
      for ($i=0;$i<$attcnt;$i++) {
        $thisatt = $row->attachments[$i];
        $ext = strtolower(substr(strrchr($thisatt->file_name,"."),1));
        $ATTACHMENTS[] = array("ATT_LINK" => ($board_config->seo ? "$main_path/sbbdl" . $thisatt->id . "t" . $thisatt->tid . ".$ext" : "$rel_path/d.php?id=" . $thisatt->id . "&amp;tid=" . $thisatt->tid),
                               "ATT_ID" => $thisatt->id,
                               "ATT_DESCR" => $thisatt->file_name,
                               "ATT_INFO" => $thisatt->descr . " " . fsize(filesize($www_data_dir . "/attachments/" . $thisatt->id . "/" . $thisatt->file_name)));
      }
    }
    
    
  } elseif ($pid && $tid) {
    $hide_blocks[] = "VOTING_PART";
    //the single post
    $row = $SBBTopics->GetSinglePost();

    if (mysql_num_rows($res)) $postfound = true;
        
    $POST_ID = $pid;
    
    if (!$action) {
      $topic = $row->a_topic;
      $message = $row->a_answer;
    }    
    //check attachments
    if ($row->attachments) {
      $attcnt = count($row->attachments);
      for ($i=0;$i<$attcnt;$i++) {
        $thisatt = $row->attachments[$i];
        $ext = strtolower(substr(strrchr($thisatt->file_name,"."),1));
        $ATTACHMENTS[] = array("ATT_LINK" => ($board_config->seo ? "$main_path/sbbdl" . $thisatt->id . "t" . $thisatt->tid . ".$ext" : "$rel_path/d.php?id=" . $thisatt->id . "&amp;tid=" . $thisatt->tid),
                               "ATT_ID" => $thisatt->id,
                               "ATT_DESCR" => $thisatt->file_name,
                               "ATT_INFO" => $thisatt->descr . " " . fsize(filesize($www_data_dir . "/attachments/" . $thisatt->id . "/" . $thisatt->file_name)));
      }
    }
  } 
  
  $HEADLINE_FORM = lang("editpost");

  if ($postfound) $hide_blocks[] = "POSTNOTFOUND";
  else {
    $hide_blocks[] = "POSTFOUND";
    $POST_NOT_FOUND =  lang("postnotfound");
  }
  
  //checkout external smilies
  $smilies = smilies();
  if (!$smilies["count"]) $hide_blocks[] = "EXTERNAL_SMILIES";
  else {
    $SMILIES = $smilies["files"]; //template vars will be set within smilies() -> functions.php
  }


  if ($f_auth_uid) $hide_blocks[] = "GUEST_NAME";
  
  //Template Vars
  $DESCR_TITLE = lang("title");
  $DESCR_MESSAGE = lang("your_message");
  $DESCR_SUBMIT = lang("submit");
  $DESCR_TOPICTYPE = lang("createas");
  $DESCR_STICKYOFF = lang("normal");
  $DESCR_STICKYON = lang("sticky");
  $BB_LISTENTRY_TITLE = lang("listitem");
  
  $FORM_VAL_VOTEQ = $poll_title;
  $FORM_VAL_VOTEA = stripslashes($poll_options);
  if ($poll_multiple) $FORM_CHECKED_ENMULTI = "checked";
  $FORM_VAL_DURATION = $poll_duration;
  
  $FORM_CHECKED_STICKYOFF = (!$sticky ? "checked" : "");
  $FORM_CHECKED_STICKYON = ($sticky ? "checked" : "");
  
  $FORM_VAL_TOPIC = he($topic);
  $FORM_VAL_MESSAGE = $message;
  
  if (!$is_topic && $is_mod) $hide_blocks[] = "DEFINE_TOPIC_TYPE";
  
  
        //$tpl->load_file("edit_post", "$template_path/edit_post.html");
        $tpl->load_file("edit_post", "$template_path/add_topic.html");
        if ($hide_blocks) $tpl->parse_hide('edit_post', $hide_blocks);
        $tpl->parse_loop('edit_post', 'ATTACHMENTS');
        $tpl->parse_loop('edit_post', 'SMILIES');
        //write the template-file to the content-var
        $content .= $tpl->pget('edit_post', array('CONF_MAINSCRIPT', 'CONF_RELPATH', 'ERROR', 'CONF_TEMPLATE_PATH', 
          'DESCR_TITLE', 'DESCR_MESSAGE', 'BB_LISTENTRY_TITLE', 'DESCR_SUBMIT', 'HEADLINE_FORM', 'DESCR_TOPICTYPE', 'DESCR_STICKYON', 'DESCR_STICKYOFF', 
          'FORM_VAL_TOPIC', 'FORM_VAL_MESSAGE', 'POST_NOT_FOUND', 'FORM_CHECKED_STICKYOFF', 'FORM_CHECKED_STICKYON',
          'POST_ID', 'TOPIC_ID', 'TOPIC_TITLE', 'FORUM_ID',
          'FORM_VAL_ACTION', 'CONFIRM_DELATTACHMENT', 'DESCR_MORE_SMILIES', 'HEADLINE_SMILIES',
          'HEADLINE_ATTACHMENT', 'DESCR_ATTACHMENT_INFO', 'DESCR_ATT_FILE', 'DESCR_ATT_DESCR', 'DESCR_OPTIONAL', 'DESCR_DELETE', 'FORM_VAL_ATT_DESCR',
          'FORM_VAL_VOTEQ', 'FORM_VAL_VOTEA', 'FORM_CHECKED_ENMULTI', 'FORM_VAL_DURATION', 'FORM_VAL_FTS', 'DESCR_CREATE_POLL_INFO',
          'HEADLINE_VOTING', 'DESCR_VOTEQ', 'DESCR_VOTEA', 'DESCR_VOTEA_INFO', 'DESCR_VOTEA_SUBINFO', 'DESCR_VOTEMULTIA', 'DESCR_ENMULTI', 'DESCR_DURATION', 'DESCR_DURATION_INFO'
          
          
          ));

?>