<?php
/**
* PHP versions 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 QuickTicket
* @author Philippe Vandenberghe <hide@address.com>
* @copyright 2008-2012 The PHP Group
* @version 2.5 build:20101222
*/
session_start();
require_once('bin/qti_init.php');
$oVIP->selfurl = 'qti_index.php';
// --------
// SECURITY
// --------
if ( $_SESSION[QT]['board_offline']=='1' ) HtmlPage(99);
if ( $_SESSION[QT]['visitor_right']<1 && $oVIP->role=='V' ) HtmlPage(11);
// --------
// INITIALIZE
// --------
$arrDomains = GetDomains();
$arrStats = GetStats();
// --------
// HTML START
// --------
$oHtml->scripts = array();
include('qti_p_header.php');
// --------
// MY BOARD
// --------
if ( $oVIP->role!='V' )
{
$intMyTopics = 0;
$intMyAssign = 0;
// COUNT MY TOPICS [firstpostuser]
$oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE firstpostuser='.$oVIP->id.' AND type="T" AND status<>"Z"' );
$row = $oDB->Getrow();
$intMyTopics = intval($row['countid']);
if ( $oVIP->IsStaff() )
{
$oDB->Query( 'SELECT count(id) as countid FROM '.TABTOPIC.' WHERE actorid='.$oVIP->id.' AND type="T" AND status<>"Z"' );
$row = $oDB->Getrow();
$intMyAssign = intval($row['countid']);
}
// SHOW MY BUTTONS
// ----------------
if ( $intMyTopics>0 || $intMyAssign>0 ) {
// ----------------
echo '<!-- My board -->',N;
echo '<div class="myboard">',N;
echo '<table class="button" cellspacing="0"><tr class="button">';
if ( $intMyTopics>0 )
{
echo '<td><span class="myboardtitle">',$L['My_last_topic'],'</span></td><td style="width:140px" class="button button_myboard"> <a href="',Href('qti_find.php'),'?a=user&k1=',$oVIP->id,'&k2=',urlencode($oVIP->username),'" class="button">',$L['All_my_topics'],' (',$intMyTopics,')</a> </td>';
}
else
{
echo '<td><span class="myboardtitle">',$L['My_last_topic'],'</span></td><td>',$L['None'],'</td>';
}
if ( $oVIP->IsStaff() ) {
if ( $intMyAssign>0 ) {
echo '<td style="width:5px"> </td>';
echo '<td style="width:140px" class="button button_myboard"> <a href="',Href('qti_find.php'),'?a=actor&k1=',$oVIP->id,'&k2=',urlencode($oVIP->username),'" class="button">',$L['All_my_assigned'],' (',$intMyAssign,')</a> </td>';
}}
echo '</tr></table>',N;
// MY LAST TICKET
if ( $intMyTopics>0 )
{
include('bin/qti_fn_sql.php');
// User's query: tickets issued by user (for staff, tickets assigned to [lastpostuser])
$oDB->Query( LimitSQL('t.*,p.icon,p.title,p.textmsg,f.numfield FROM (('.TABTOPIC.' t INNER JOIN '.TABPOST.' p ON t.firstpostid = p.id) INNER JOIN '.TABSECTION.' f on t.forum=f.id) WHERE t.'.($intMyTopics>0 && $oVIP->IsStaff() ? 'last' : 'first').'postuser='.$oVIP->id.' AND t.type="T" AND t.status<>"Z"','t.lastpostdate DESC',0,1,1) );
$row = $oDB->Getrow();
if ( is_array($row) )
{
$oTopic = new cTopic($row);
// find section title and reduce long titles
if ( isset($oVIP->sections[$oTopic->parentid]) ) { $strSection=$oVIP->sections[$oTopic->parentid]; } else { $strSection='unknown section'; }
if ( strlen($oTopic->title)>30 ) $oTopic->title=substr($oTopic->title,0,25).'...';
if ( strlen($strSection)>30 ) $strSection=substr($strSection,0,25).'...';
$strText = '<p style="text-align:right; margin:0" class="small"><i>'.QTdatestr($oTopic->firstpostdate,'$','$',true,true).', '.$L['I_wrote'].'</i></p><p class="small">'.$oTopic->preview.'</p>';
$strLasttext = '';
if ( $oTopic->firstpostid!=$oTopic->lastpostid )
{
$oPost = new cPost($oTopic->lastpostid);
$strLasttext = '<p class="myboard_line small" style="text-align:right"><i>'.QTdatestr($oPost->issuedate,'$','$',true,true).', '.strtolower($L['Last_message'].' '.$L['By']).' '.$oPost->username.'</i></p><p class="small">'.QTunbbc(QTcompact($oPost->text,250,' ')).'</p>';
}
echo '<table class="hidden" cellspacing="0">',N;
echo '<tr class="hidden">',N;
echo '<td class="myboard">',$oTopic->GetIcon($_SESSION[QT]['skin_dir'],Href('qti_topic.php?t='.$oTopic->id)),( $row['numfield']=='N' ? '' : ' · '.sprintf($row['numfield'],$oTopic->numid) ),' · <a class="topic" href="',Href('qti_topic.php'),'?s=',$oTopic->parentid,'&t=',$oTopic->id,'">',$oTopic->title,'</a> · <span class="small">',$L['Section'],': ',$strSection,'</span></td>',N;
echo '</tr>',N;
echo '<tr valign="top">',N;
echo '<td class="myboard">'.$strText.($strLasttext!='' ? $strLasttext : '').'</td>',N;
echo '</tr>',N;
echo '</table>',N;
}
}
echo '</div>',N,N;
// ----------------
}
// ----------------
}
// Optimising queries: Search all lastpost and Sections attributes
$arrLastPostId = array();
$oDB->Query( 'SELECT forum,MAX(id) as maxid FROM '.TABPOST.' GROUP BY forum' );
while($row = $oDB->Getrow())
{
$arrLastPostId[intval($row['forum'])] = intval($row['maxid']);
}
$arrAllSections = GetSections($oVIP->role); // Get all sections at once (result is ordered)
// --------
// DOMAIN / SECTIONS
// --------
$intDom = 0;
$intSec = 0;
foreach($arrDomains as $intDomid=>$strDomtitle)
{
// Group sections by domain. Step required by optimisation. (result remains in the same order as in $arrAllSections)
$arrSections = array();
foreach($arrAllSections as $s=>$arr) { if ( $arr['domainid']==$intDomid ) $arrSections[$s]=$arr; }
$intDom++;
if ( count($arrSections)>0 )
{
echo '<!-- domain ',$intDomid,': ',$strDomtitle,' -->',N;
echo '<table class="data_s" cellspacing="0">',N;
echo '<colgroup span="5"><col width="35"></col><col></col><col width="150"></col><col width="60"></col><col width="60"></col></colgroup>',N;
echo '<tr class="data_s">',N;
echo '<td class="colhd colhdico colhdfirst"> </td>',N;
echo '<td class="colhd">',$strDomtitle,'</td>',N;
echo '<td class="colhd">',$L['Last_message'],'</td>',N;
echo '<td class="colhd">',$L['Topics'],'</td>',N;
echo '<td class="colhd colhdlast">',$L['Replys'],'</td>',N;
echo '</tr>',N;
// SHOW SECTIONS
$strAlt='r1';
foreach($arrSections as $s=>$arrSection)
{
$intSec++;
$oSEC = new cSection($arrSection,(isset($arrLastPostId[$s]) ? $arrLastPostId[$s] : true)); //use query optimisation
echo '<tr class="data_s ',$strAlt,'">',N;
echo '<td class="colct ',$strAlt,' colfirst" >',AsImg($oSEC->GetLogo(),'S',$L['Ico_section_'.$oSEC->type.'_'.$oSEC->status],'ico ico_s','','qti_topics.php?s='.$oSEC->id),'</td>',N;
echo '<td class="colct ',$strAlt,'"><a class="section" href="',Href('qti_topics.php'),'?s=',$oSEC->id,'" >',$oSEC->name,'</a><br /><span class="sectiondesc">',$oSEC->descr,'</span></td>',N;
echo '<td class="colct ',$strAlt,'">';
if ( $oSEC->items<1 )
{
echo S;
}
else
{
if ( isset($oSEC->lastpostid) )
{
echo QTdatestr($oSEC->lastpostdate,'$','$',true,true,true);
echo ' <a href="',Href('qti_topic.php'),'?t=',$oSEC->lastposttopic,'#p',$oSEC->lastpostid,'" title="',$L['H_Goto_message'],'">',$L['Goto_message'],'</a><br />',strtolower($L['By']),' <a href="',Href('qti_user.php'),'?id=',$oSEC->lastpostuser,'" title="',$L['Ico_user_p'],'" class="small">',$oSEC->lastpostname,'</a>';
}
else
{
echo S;
}
}
echo '</td>',N;
echo '<td class="colct center ',$strAlt,'">',(isset($arrStats[$s]) ? $arrStats[$s]['topics'] : 0),'</td>',N;
echo '<td class="colct center ',$strAlt,' collast">',(isset($arrStats[$s]) ? $arrStats[$s]['replies'] : 0),'</td>',N;
echo '</tr>',N;
if ( $strAlt=='r1' ) { $strAlt='r2'; } else { $strAlt='r1'; }
}
echo '<tr class="data_s">',N;
echo '<td class="colft colftfirst"></td>',N;
echo '<td class="colft"></td>',N;
echo '<td class="colft"></td>',N;
echo '<td class="colft"></td>',N;
echo '<td class="colft colftlast"></td>',N;
echo '</tr>',N;
echo '</table>',N;
if ( $intDom<count($arrDomains) ) echo '<p class="dom_sep"></p>',N;
}
}
// No public section
if ( $intSec==0 )
{
echo '<p>',( $oVIP->role=='V' ? $L['E_no_public_section'] : $L['E_no_visible_section'] ),'</p>';
}
// --------
// HTML END
// --------
if ( isset($oSEC) ) unset($oSEC);
include('qti_p_footer.php');
?>