Location: PHPKode > projects > QuickTalk Forum > quicktalk/qtf_topics.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('V2') ) HtmlPage(11);
include('bin/qtf_fn_sql.php');

$s = -1; QThttpvar('s','int'); if ( $s<0 ) die('Missing section id...');

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

if ( isset($_POST['Mok']) )
{
  if ( $_POST['Maction']=='nt' ) HtmlRedirect('qtf_form_edit.php?s='.$s.'&amp;a=nt',$L['Post_new_topic']);
  if ( $_POST['Maction']=='show_Z' ) $_SESSION[QT]['show_closed']='1';
  if ( $_POST['Maction']=='hide_Z' ) $_SESSION[QT]['show_closed']='0';
  if ( $_POST['Maction']=='print' ) { echo 'No yet developped';  exit; }
  if ( $_POST['d_last']!=='-' && $_POST['d_last']!=='' ) $_SESSION[QT]['lastcolumn']=$_POST['d_last']; // can be '0' (none)
}

// ---------
// INITIALISE
// ---------

$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);
}

$oVIP->selfurl = 'qtf_topics.php';
$oVIP->selfname = $L['Section'].': '.$oSEC->name;

$strCommand = '';
$arrMe[] = array();

$strOrder = 'lastpostdate';
$strDirec = 'DESC';
$intPage = 1;
$intLimit = 0;
if ( isset($_GET['page']) ) { $intLimit = (intval($_GET['page'])-1)*$_SESSION[QT]['topics_per_page']; $intPage = intval($_GET['page']); }
if ( isset($_GET['order']) ) $strOrder = $_GET['order'];
if ( isset($_GET['dir']) ) $strDirec = $_GET['dir'];

// Criteria sql: topics visible for current user ONLY

$strWhere = '';
if ( $oSEC->type==2 && !$oVIP->IsStaff() ) $strWhere .= ' AND (t.firstpostuser='.$oVIP->id.' OR t.type="A")';
if ( $_SESSION[QT]['show_closed']=='0' ) $strWhere.=' AND t.status<>"1"';
$strOnTop = '';
if ( $_SESSION[QT]['news_on_top']==1 )
{ 
  $strOnTop = 'CASE t.type WHEN "A" THEN "A" ELSE "Z" END as typea,';
}

// Count topics visible for current user ONLY

$oDB->Query( 'SELECT count(*) as countid FROM '.TABTOPIC.' t WHERE t.forum='.$oSEC->id.$strWhere );
$row = $oDB->Getrow();
$intTopics = intval($row['countid']);

// FORUM OPTIONS

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?s='.$oSEC->id.'&amp;a=nt">'.$L['Post_new_topic'].'</a>&nbsp;</td>';
  if ( $oVIP->role=='V' && $_SESSION[QT]['visitor_right']<7 )
  {
  $strCommand = '<td class="button disabled" style="width:120px">&nbsp;'.$L['Post_new_topic'].'&nbsp;</td>';
  }
}
$strCommand .= ( $intTopics<3 || $_SESSION[QT]['board_offline']=='1' || ($oVIP->role=='V' && $_SESSION[QT]['visitor_right']<5) ? '' : '<td class="button" style="width:30px"><span class="button">&nbsp;'.AsImg($_SESSION[QT]['skin_dir'].'/ico_search.gif','Search',$L['Search'],'ico i_topic','',Href('qtf_search.php').'?s='.$s).'&nbsp;</span></td>' );

$byuser = '';
if ( ($oSEC->type==2) && ($oVIP->role!='M') && ( $oVIP->role!='A' )) $byuser = "AND t.firstpostuser={$oVIP->id}";

$strShowclosed = '';
if ( $_SESSION[QT]['show_closed']=='0' ) $strShowclosed='AND t.status="0"';

// BUTTON LINE AND PAGER

$oDB->Query('SELECT count(*) as countid FROM '.TABTOPIC." t WHERE t.forum={$oSEC->id} $strShowclosed ".$byuser);
$row = $oDB->Getrow();
$intCount = $row['countid'];

$strPager = MakePager("$oVIP->selfurl?s={$oSEC->id}",$intTopics,$_SESSION[QT]['topics_per_page'],$intPage);
if ($strPager!='') $strPager = $L['Page'].$strPager;

// BUTTONS

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

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

include('qtf_p_header.php');

// Moderator Actions
if ( $oVIP->role=='M' || $oVIP->role=='A' )
{
$arr = array('views'=>$L['Views'],'status'=>$L['Status'],'id'=>'Id'); if ( !empty($_SESSION[QT]['tags']) ) $arr['tags']=$L['Tags'];
echo '
<form method="post" action="qtf_topics.php?s=',$s,'" id="modaction">
<div class="modboard">
<span class="modboard">',$L['Userrole'][$oVIP->role],' <select name="Maction" class="small" onchange="document.getElementById(\'action_ok\').click();">
<option value="">',S,'</option> 
<option value="nt">',$L['Post_new_topic'],'...</option>
<option value="" disabled="disabled">---------------</option>
<option value="show_Z"',($_SESSION[QT]['show_closed'] ? ' class="bold"' : ''),'>',$L['Topic_closed_show'],'</option>
<option value="hide_Z"',(!$_SESSION[QT]['show_closed'] ? ' class="bold"' : ''),'>',$L['Topic_closed_hide'],'</option>
</select> ',$L['Last_column'],S;
echo '<select id="d_last" name="d_last" class="small" onchange="document.getElementById(\'action_ok\').click();">';
echo '<option value="">',S,'</option>';
echo QTasTag($arr,'',array('current'=>$oSEC->d_last,'classC'=>'bold'));
echo '<option value="none" '.($oSEC->d_last=='none' ? ' class="bold"' : '').' class="small">('.$L['None'].')</option>
</select> <input type="submit" name="Mok" value="',$L['Ok'],'" class="small" id="action_ok"/>
<script type="text/javascript">document.getElementById("action_ok").style.display="none";</script>
</span>
</div>
</form>
';
}
// End Moderator actions

if ( $_SESSION[QT]['section_desc']=='1' )
{
  if ( !empty($oSEC->descr) ) echo '<p id="sectiondesc">',$oSEC->descr,'</p>',N;
}

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

// End if no results

if ( $intTopics==0 ) { TableEmpty($L['E_no_topic'].'...'); include('qtf_p_footer.php'); exit; }

// LIST TOPICS

// Last column: can be '0' (moderator requests no-field)
if ( isset($_SESSION[QT]['lastcolumn']) ) $oSEC->d_last=$_SESSION[QT]['lastcolumn'];
switch($oSEC->d_last)
{
case 'replies': $str=$L['Replys']; break;
case 'views': $str=$L['Views']; break;
case 'status': $str=$L['Status']; break;
case 'id': $str='Id'; break;
case 'actorname': $str=$L['Userrole_MA']; break;
case 'notifiedname': $str=$L['Userrole_UN']; break;
case 'tags': $str=$L['Tags']; break;
case 'modifdate': $str=$L['Modified']; break;
case 'coord': $str=$L['Coord']; break;
default: $str=$oSEC->d_last;
}

echo '<table class="data_t" cellspacing="0" summary="subjects">',N;
echo '<tr class="data_t">',N;

// ========
$arrFLD = array();
$arrFLD['icon'] = new cFLD('icon','&bull;','colhd colhdico colhdfirst','','colct colico colfirst','','ASC'); $arrFLD['icon']->uid='status';
if ( $oSEC->numfield!='N' ) 
$arrFLD['numid'] = new cFLD('numid',$L['Ref'],'colhd colhdref','','colct colref','','DESC');
if ( !empty($oSEC->prefix) )
$arrFLD['smile'] = new cFLD('smile','&nbsp;','colhd colhdsmi','','colct colsmi');
$arrFLD['title'] = new cFLD('title',$L['Topics'],'colhd','','colct','','DESC');
if ( QTF_LIST_ME )
$arrFLD['you'] = new cFLD('you','&nbsp;','colhd center','width:10px','colct center');
$arrFLD['firstpostname'] = new cFLD('firstpostname',$L['Author'],'colhd','width:140px','colct','','ASC');
$arrFLD['lastpostdate'] = new cFLD('lastpostdate',$L['Last_message'],'colhd','width:140px','colct','','ASC');
if ( $oSEC->d_last=='none' || empty($oSEC->d_last) || $oSEC->d_last=='N' || $oSEC->d_last=='replies' )
{
$arrFLD['replies'] = new cFLD('replies',$L['Replys'],'colhd center colhdlast','width:75px','colct center collast','','DESC');
}
else
{
$arrFLD['replies'] = new cFLD('replies',$L['Replys'],'colhd center','width:75px','colct center','','DESC');
$arrFLD[$oSEC->d_last] = new cFLD($oSEC->d_last,$str,'colhd center colhdlast','width:80px','colct center collast','',($oSEC->d_last=='tags' ? FALSE : 'ASC'));
}
if ( isset($arrFLD['status']) ) $arrFLD['status']->class_dynamic=array('colbg_%s','status',array('0'=>'opened','1'=>'closed'));
if ( isset($arrFLD['numid']) ) $arrFLD['numid']->class_dynamic=array('colbg_%s','status',array('0'=>'opened','1'=>'closed'));
// ========
TableHeader($arrFLD,$intCount,"$oVIP->selfurl?s=$oSEC->id&amp;page=1",$strOrder,$strDirec);
// ========

echo '</tr>',N;

// ========
if ( QTF_LIST_ME && $oVIP->numpost>0 )
{
  $oDB->Query('SELECT topic,issuedate FROM '.TABPOST.' WHERE forum='.$s.' AND type="R" AND userid='.$oVIP->id);
  while($row=$oDB->Getrow()) $arrMe[intval($row['topic'])] = $row['issuedate'];
}
// ========
$strState = $strOnTop.'t.*, p.title, p.icon, p.textmsg FROM '.TABTOPIC.' t INNER JOIN '.TABPOST.' p ON t.firstpostid=p.id WHERE t.forum='.$oSEC->id.$strWhere;
if ( $strOrder=='title' ) { $strFullOrder='p.title'; } else { $strFullOrder='t.'.$strOrder; }
$oDB->Query( LimitSQL($strState,(empty($strOnTop) ? '' : 'typea ASC, ').$strFullOrder.' '.$strDirec,$intLimit,$_SESSION[QT]['topics_per_page'],$intCount) );
// ========
$intWhile=0;
$strAlt='r1';
while($row=$oDB->Getrow())
{
  TableRowShow($arrFLD,TableRowFormat($arrFLD,$row,true,$oSEC),'data_t '.$strAlt,$row);
  if ( $strAlt=='r1' ) { $strAlt='r2'; } else { $strAlt='r1'; }
  
  $intWhile++; 
  //odbcbreak
  if ( $intWhile>=$_SESSION[QT]['topics_per_page'] ) break;  
}
// ========

echo '<tr class="data_t">',N;
echo '<td class="colft colftfirst"></td>',N;
for ($i=0;$i<(count($arrFLD)-2);$i++) echo '<td class="colft"></td>',N;
echo '<td class="colft colftlast"></td>
</tr>
</table>
';

// BUTTON LINE AND PAGER

$strCsv = ($oVIP->role=='V' ? '' : HtmlCsvLink(Href('qtf_topics_csv.php').'?s='.$s,$intTopics,$intPage));
if ( !empty($strCsv) )
{
  $strPager = $strCsv.' &middot; '.$strPager;
  if ( substr($strPager,-10,10)==' &middot; ' ) $strPager = substr($strPager,0,-10);
}

// display button, pager and csv

if ( $intTopics>2 )
{
echo '<table class="pagerbot" cellspacing="0" summary="pages and commands"><tr class="pagerbot">',$strCommand,'<td>&nbsp;</td><td id="pager_zb">&nbsp;',$strPager,'</td></tr></table>
';
}
else
{
echo '<p id="pager_zb" class="csv">&nbsp;',$strPager,'</p>';
}

// TAGS FILTRING

if ( QTF_LIST_TAG && !empty($_SESSION[QT]['tags']) )
{
  require_once('bin/qtf_fn_tags.php');
  $arrTags = $oSEC->GetTagsUsed($s,50);
  if ( count($arrTags)>0 ) 
  {
    if ( count($arrTags)>5 ) 
    {
    echo '<p class="tagbox">'.$L['Show_only_tag'],'</p><div class="tagbox">';
    foreach($arrTags as $strTag)
    {
      echo '<a class="tag',(count($arrTags)>12 ? ' small' : ''),'" href="qtf_find.php?a=tst&amp;s=',$s,'&amp;y=',date('Y'),'&amp;k1=-1&amp;k2=-1&amp;k3=',$strTag,'">',$strTag,'</a>&nbsp; ';
    }
    echo '</div>';
    }
    else
    {
    echo '<p class="tagline">'.$L['Show_only_tag'];
    foreach($arrTags as $strTag)
    {
      echo ' <span class="tagline" title=""><a class="tag" href="qtf_find.php?a=tst&amp;s=',$s,'&amp;y=',date('Y'),'&amp;k1=-1&amp;k2=-1&amp;k3=',$strTag,'">',$strTag,'</a></span>';
    }
    echo '</p>';
    }
  }
}

// HTML END

include('qtf_p_footer.php');

?>
Return current item: QuickTalk Forum