Location: PHPKode > projects > QuickTalk Forum > quicktalk/qtf_topic.php
<?php

/**
* PHP versions 4 and 5
*
* LICENSE: This source file is subject to version 3.0 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://www.php.net/license. If you did not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to hide@address.com so we can mail you a copy immediately.
*
* @package    QuickTalk
* @author     Philippe Vandenberghe <hide@address.com>
* @copyright  2008-2012 The PHP Group
* @version    2.5 build:20100924
*/

session_start();
require_once('bin/qtf_init.php');
if ( !$oVIP->CanView('V3') ) HtmlPage(11);
require_once('bin/qtf_fn_tags.php');

// ---------
// PRE SETTINGS
// ---------

$t = -1;
if ( isset($_GET['t']) ) $t=intval($_GET['t']);
if ( isset($_POST['t']) ) $t=intval($_POST['t']);

if ( $t<0 ) die('Missing topic id... (t)');

$oTopic = new cTopic($t,$oVIP->id); //provide userid to update stats
$s = $oTopic->section;

// ---------
// SUBMITTED
// ---------

if ( isset($_POST['Maction']) )
{
  $oVIP->exiturl  = 'qtf_topics.php?s='.$s;
  $oVIP->exitname = $L['Section'];
  if ( empty($_POST['Maction']) ) HtmlRedirect(Href('qtf_topic.php').'?t='.$t);
  if ( substr($_POST['Maction'],0,7)=='status_' ) HtmlRedirect(Href('qtf_change.php').'?a=topicstatus&amp;s='.$s.'&amp;t='.$t.'&amp;v='.substr($_POST['Maction'],-1,1),$L['Change'].' '.$L['Status']);
  if ( substr($_POST['Maction'],0,5)=='type_' ) HtmlRedirect(Href('qtf_change.php').'?a=topictype&amp;s='.$s.'&amp;t='.$t.'&amp;v='.substr($_POST['Maction'],-1,1),$L['Change'].' '.$L['Type']);
  if ( $_POST['Maction']=='reply' ) HtmlRedirect(Href('qtf_form_edit.php').'?a=re&amp;t='.$t,$L['Post_reply']);
  if ( $_POST['Maction']=='move' ) HtmlRedirect(Href('qtf_change.php').'?a=topicmove&amp;t='.$t,$L['Move']);
  if ( $_POST['Maction']=='delete' ) HtmlRedirect(Href('qtf_change.php').'?a=topicdelete&amp;t='.$t,$L['Delete']);
}

// INITIALISE

include('bin/qtf_fn_sql.php');

$oSEC = new cSection($s);

  if ( $oSEC->type=='1' && ($oVIP->role=='V' || $oVIP->role=='U') )
  {
  // exit
  $oVIP->selfname = $L['Section'];
  $oVIP->exitname = ObjTrans('index','i',$_SESSION[QT]['index_name']);
  $oVIP->EndMessage(NULL,$L['R_staff'],$_SESSION[QT]['skin_dir'],0);
  }
  if ( $oSEC->type=='2' && $oVIP->role=='V' )
  {
  // exit
  $oVIP->selfname = $L['Section'];
  $oVIP->exitname = ObjTrans('index','i',$_SESSION[QT]['index_name']);
  $oVIP->EndMessage(NULL,$L['R_member'],$_SESSION[QT]['skin_dir'],0);
  }

  if ( $oSEC->type=='2' && $oVIP->role=='U' && $oTopic->firstpostuser != $oVIP->id )
  {
  // exit
  $oVIP->selfname = $L['Section'];
  $oVIP->exitname = ObjTrans('index','i',$_SESSION[QT]['index_name']);
  $oVIP->EndMessage(NULL,$L['E_topic_private'].'<br/>'.$L['R_member'],$_SESSION[QT]['skin_dir'],0);
  }

$oPost = new cPost();

$strCommand= '';
$limit     = 0;
$PAGEcurr  = 1;
if ( isset($_GET['page']) ) { $limit = ($_GET['page']-1)*$_SESSION[QT]['replies_per_page']; $PAGEcurr=intval($_GET['page']); }
if ( isset($_GET['view']) ) { $_SESSION[QT]['viewmode'] = $_GET['view']; }

$oVIP->selfurl = 'qtf_topic.php';
$oVIP->exiturl = 'qtf_topics.php?s='.$s;
$oVIP->selfname = $L['Messages'];

// CHANGE TAGS

if ( isset($_POST['addtag']) )
{
  $str = strip_tags(trim($_POST['tag']));
  if ( !empty($str) && $str!='*' ) $oTopic->TagsAdd($str,$oSEC);
}
if ( isset($_POST['deltag']) )
{
  $str = strip_tags($_POST['tag']);
  if ( !empty($str) ) $oTopic->TagsDel($str,$oSEC);
}

// --------
// HTML START
// --------

$strHeadScript = '';

if ( $_SESSION[QT]['show_quick_reply']!='0' && $_SESSION[QT]['bbc']=='1' )
{
  $oVIP->arrJava[]='bin/qtf_bbc.js';
  $oVIP->arrCss[] = '../bin/css/qtf_bbc.css';
  $intBbc=1; // buttons for quick reply
}

if ( $_SESSION[QT]['tags']!='0' ) {
if ( $oVIP->role<=$_SESSION[QT]['tags'] && $oTopic->status!='1' ) {

  $arr1 = TagsRead(GetIso(),$s);
  $arr2 = TagsRead(GetIso(),'*');
  $arrTags = array_merge($arr1,$arr2);
  if ( count($arrTags)<100 )
  {
    $arr1 = $oSEC->GetTagsUsed();
    foreach($arr1 as $strKey=>$strDesc) { if ( !isset($arrTags[$strKey]) ) $arrTags[$strKey]=$strDesc; }
  }
  $str = '';
  foreach($arrTags as $strKey=>$strDesc) { $str .= '"'.$strKey.'",'; }
  $str = substr($str,0,-1);

  $strHeadScript .= '
  <link rel="stylesheet" type="text/css" href="bin/css/qt_jquery.css"/>
  <script type="text/javascript" src="bin/qt_jquery.js"></script>
  <script type="text/javascript" src="bin/qt_jquery_auto.js"></script>
  <script type="text/javascript">
  <!--
  $(document).ready(function() {
    $("#tag").autocomplete(['.$str.'],{
      minChars:0,
      matchContains:1,
      width:200,
      multiple:true,
      multipleSeparator:";"
      });      
    });
  -->
  </script>
  ';
}}

if ( $_SESSION[QT]['show_quick_reply']!='0' ) $intBbc=1;

$bJava=true;
include('qtf_p_header.php');

// COUNT RECORDS

$oDB->Query('SELECT count(p.id) as countid FROM '.TABPOST.' p WHERE p.forum='.$oSEC->id.' AND p.topic='.$oTopic->id);
$row = $oDB->Getrow();
$intPosts = $row['countid'];

// PAGER

$pager = MakePager('qtf_topic.php?t='.$oTopic->id,$intPosts,$_SESSION[QT]['topics_per_page'],$PAGEcurr);
if ( $pager!='' ) $pager = $L['Page'].$pager;

// BUTTONS

if ( $oSEC->status=='1' )
{
  $strCommand = '<td class="button disabled" style="width:120px">&nbsp;'.$L['E_section_closed'].'&nbsp;</td>';
}
else
{
  $strCommand = '<td class="button" style="width:120px">&nbsp;<a href="qtf_form_edit.php?t='.$oTopic->id.'&amp;a=re">'.$L['Post_reply'].'</a>&nbsp;</td>';
  if ( $oTopic->status=='1' ) $strCommand = '<td class="button disabled" style="width:120px">&nbsp;'.$L['Topic_closed'].'&nbsp;</td>';

  if ( ($oVIP->role=='V') && ($_SESSION[QT]['visitor_right']<6) )
  {
  $strCommand = '<td class="button disabled" style="width:120px">&nbsp;'.$L['Post_reply'].'&nbsp;</td>';
  }
}

$strCommand = $oVIP->BackButton().$strCommand;

// -- Displays Button line and pager --

// Moderator action

if ( $oVIP->role=='M' || $oVIP->role=='A' )
{
  // list of status
  $strStatus = '';
  foreach($oVIP->GetStatuses() as $strId=>$strValue)
  {
    $strStatus .= '<option value="status_'.$strId.'"'.($oTopic->status==$strId ? ' class="bold"' : '').'>'.$L['Status'].': '.$strValue.'</option>';
  }
  // list of types
  $strTypes = '';
  foreach($oVIP->GetTypes() as $strId=>$strValue)
  {
    $strTypes .= '<option value="type_'.$strId.'"'.($oTopic->type==$strId ? ' class="bold"' : '').'>'.$L['Type'].': '.$strValue['name'].'</option>';
  }

// returned topic action
echo '<form method="post" action="qtf_topic.php" id="modaction">
<div class="modboard">
<span class="modboard">',$L['Topic'],S,'<input type="hidden" name="s" value="',$oTopic->section,'"/>
<input type="hidden" name="t" value="',$oTopic->id,'"/>
';
echo '<select name="Maction" class="small" onchange="document.getElementById(\'modaction\').submit();">
<option value="">',S,'</option>
<option value="reply">',$L['Post_reply'],'...</option>
<option value="move">',$L['Move'],'...</option>
<option value="delete">',$L['Delete'],'...</option>
<option value="" disabled="disabled">-----------------</option>',$strStatus,'
<option value="" disabled="disabled">-----------------</option>',$strTypes,'
</select> <input type="submit" name="Msubmit" value="',$L['Ok'],'" class="small" id="action_ok"/>
<script type="text/javascript">document.getElementById("action_ok").style.display="none";</script>
</span>
</div>
</form>',N;
}

if ( $_SESSION[QT]['section_desc']=='1' )
{
  if ( $oTopic->numid >= 0 && $oSEC->numfield!='N' ) 
  {
  echo '<!-- Topic description -->',N,'<p id="topic_reference">';
  printf($oSEC->numfield,$oTopic->numid);
  echo '</p>',N,'<!-- Topic description -->',N,N;
  }
}

echo '
<table class="pagertop" cellspacing="0" summary="page and command"><tr class="pagertop">',$strCommand,'<td>&nbsp;</td><td id="pager_zt">&nbsp;',$pager,'</td></tr></table>
';

// CONTENT

// stop if no post (or user not creator)

if ( $intPosts==0 )
{
  echo '<br/>',$L['None'],'... ',$L['E_topic_private'],'<br/><br/>',N;
  include('qtf_p_footer.php');
  exit;
}

// ========
$state = 'p.*, u.role, u.location, u.picture, u.signature FROM '.TABPOST.' p, '.TABUSER.' u WHERE p.userid = u.id AND p.topic='.$oTopic->id;
$oDB->Query( LimitSQL($state,'p.id ASC',$limit,$_SESSION[QT]['replies_per_page'],$intPosts) );
// ========
$iMsgNum = $limit;
$intWhile= 0;
$strAlt  = 'r1';
$strSep  = '<div class="post_sep_'.($_SESSION[QT]['viewmode']=='N' ? 'n' : 'c').'"></div>'.N;
// ========
while ( $row=$oDB->Getrow() )
{
  $iMsgNum = $iMsgNum+1;
  $oPost = new cPost($row,$iMsgNum);
  if ( $_SESSION[QT]['viewmode']=='C' ) $oPost->text = QTcompact($oPost->text);
  $strButton = '';
  if ( $oVIP->auth )
  {
    if ( !$oTopic->status && !$oSEC->status )
    {
    $strButton .= '<td class="buttonsmall" style="width:50px">&nbsp;<a href="qtf_form_edit.php?t='.$oTopic->id.'&amp;a=qu&amp;p='.$oPost->id.'">'.$L['Quote'].'</a>&nbsp;</td>'.N;
    }
    if ( $oPost->userid==$oVIP->id || $oVIP->IsStaff() )
    {
    $strButton .= '<td class="buttonsmall" style="width:50px">&nbsp;<a href="qtf_form_edit.php?t='.$oTopic->id.'&amp;p='.$oPost->id.'&amp;a=ed">'.$L['Edit'].'</a>&nbsp;</td>'.N;
    $strButton .= '<td class="buttonsmall" style="width:50px">&nbsp;<a href="qtf_form_del.php?s='.$oSEC->id.'&amp;t='.$oTopic->id.'&amp;p='.$oPost->id.'&amp;a=de">'.$L['Delete'].'</a>&nbsp;</td>'.N;
    }
  }
  if ( !empty($oPost->modifuser) ) $strButton .= '<td class="post_modif"><span class="small">&nbsp;'.$L['Modified_by'].' <a href="qtf_user.php?id='.$oPost->modifuser.'" class="small">'.$oPost->modifname.'</a> ('.QTdatestr($oPost->modifdate,'$','$',true).')</span></td>'.N;
  if ( !empty($strButton) ) $strButton .= '<td class="hidden">'.S.'</td>'.N;
  if ( !empty($strButton) ) $strButton = '<table class="hidden" cellspacing="0" style="margin:10px 0 1px 0;" summary="message controls"><tr>'.$strButton.'</tr></table>'.N;

  // SHOW MESSAGE

  $oPost->Show($oSEC,$oTopic,true,$strButton,$strSep,$_SESSION[QT]['skin_dir'],$strAlt);
  if ( $strAlt=='r1' ) { $strAlt='r2'; } else { $strAlt='r1'; }
  $intWhile++;

  // SHOW TAGS
  
  if ( $oPost->type=='P' && $_SESSION[QT]['tags']!='0' )
  {
    $arrTags=explode(';',$oTopic->tags);
    
    if ( $oVIP->role<=$_SESSION[QT]['tags'] && $oTopic->status!='1' )
    {
      echo '<div class="tags small" style="text-align:right">',$L['Tags'],' ';
      foreach($arrTags as $strTag)
      {
        if ( !empty($strTag) ) echo '<span class="tagline" title="" onclick="document.getElementById(\'tag\').value=this.innerHTML;">',$strTag,'</span> ';
      }  
      echo (count($arrTags)>5 ? '</div><div class="tags small" style="text-align:right">' : ''),'<form method="post" action="',$oVIP->selfurl,'?s=',$s,'&amp;t=',$t,'">',N;
      echo '<input type="hidden" name="s" value="',$s,'"/>';
      echo '<input type="hidden" name="t" value="',$t,'"/>';
      echo '<input type="text" class="small" size="18" id="tag" name="tag" maxlength="24" value=""/>';
      echo '<input type="submit" class="small" name="addtag" id="addtag" title="',$L['Add'],'" value="+" onclick="if (document.getElementById(\'tag\').value==\'\') return false;"/>';
      echo '<input type="submit" class="small" name="deltag" id="deltag" title="',$L['Delete_tags'],'" value="-"  onclick="if (document.getElementById(\'tag\').value==\'\') return false;"/>';
      echo '</form>',N;
      echo '</div>';
    }
    else
    {
      if ( !empty($oTopic->tags) ) 
      {
      echo '<div class="tags small" style="text-align:right">',$L['Tags'],'&nbsp;';
      foreach($arrTags as $strTag)
      {
        echo '<span class="tagline">',$strTag,'</span> ';
      }  
      echo '</div>';
      }
    }
  }

  // END

  if ( $intWhile<$intPosts ) echo $strSep;
}
// ========

// BUTTON LINE AND PAGER

if ( $intPosts>1 )
{
echo '
<table class="pagerbot" cellspacing="0" summary="page and command"><tr class="pagerbot">',$strCommand,'<td>&nbsp;</td><td id="pager_zb">&nbsp;',$pager,'</td></tr></table>
';
}

if ( $oTopic->status && !empty($oTopic->statusdate) )
{
echo '<p class="disabled">',$L['Topic_closed'],' ',strtolower(QTdatestr($oTopic->statusdate,'$','$',true)),'</p>';
}

// QUICK REPLY

if ( $_SESSION[QT]['show_quick_reply']=='1' ) {
if ( !$oSEC->status && !$oTopic->status ) {
if ( $oVIP->role=='V' && $_SESSION[QT]['visitor_right']<7 ) {} else {

echo '
<!-- Quick reply -->
<div class="quickreply">
<script type="text/javascript">
<!--
function ValidateForm(theForm)
{
  if (theForm.text.value.length==0) { alert(qtHtmldecode("',$L['E_mandatory'],': ',$L['Message'],'")); return false; }
  if (theForm.text.value.length>',$_SESSION[QT]['chars_per_post'],') { alert(qtHtmldecode("',$L['E_too_long'],': ',$L['Maximum'],' ',$_SESSION[QT]['chars_per_post'],'")); return false; }
  return null;
}
-->
</script>
';
echo '<form method="post" action="qtf_form_edit.php" onsubmit="return ValidateForm(this);">
<table class="hidden" cellspacing="0" summary="reply form">
<tr class="hidden">
<td style="height:22px">
';
if ( $_SESSION[QT]['bbc']=='1' )
{
echo '<ul class="bbc"><li class="txt">',$L['Quick_reply'],'</li>';
include('qtf_form_button.php');
}
else
{
echo $L['Quick_reply'];
}
echo '&nbsp;&nbsp;<input type="submit" id="dopreview" name="dopreview" value="',$L['Advanced_reply'],'" class="small"/>&nbsp;<input type="submit" id="dosend" name="dosend" value="',$L['Send'],'" class="small"/>
</td>
</tr>
';
echo '<tr class="hidden">
<td class="hidden">
<a href="textarea"></a><textarea id="text" name="text" rows="5" cols="85"></textarea>&nbsp;
<input type="hidden" name="t" value="',$oTopic->id,'"/>
<input type="hidden" name="a" value="re"/>
<input type="hidden" name="ref" value="',$oTopic->numid,'"/>
<input type="hidden" name="icon" value="00"/>
<input type="hidden" name="title" value=""/>
</td>
</tr>
</table>
';
echo '</form>
</div>
<!-- End Quick reply -->
';
  
}}}

// HTML END

include('qtf_p_footer.php');

?>
Return current item: QuickTalk Forum