Location: PHPKode > projects > QT-registrations > qtregistrations/qtr_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    QT-registerations
* @author     Philippe Vandenberghe <hide@address.com>
* @copyright  2008-2012 The PHP Group
* @version    2.4 build:20100313
*/

session_start();
require_once('bin/qtr_init.php');
if ( !$oVIP->CanView('V3') ) HtmlPage(11);
if ( !isset($_SESSION[QT]['editing']) ) $_SESSION[QT]['editing']=false;

$s = -1;
$t = -1;
$tt = 'ticket';
$page = 1;
QThttpvar('s t tt page','int int str int');
if ( $s<0 || $t<0 ) die('Missing section or topic id...');
if ( $page<1 ) $page=1;
$intLimit = 0;
if ( $page>1 ) $intLimit = ($page-1)*$_SESSION[QT]['replies_per_page'];

$bCanEdit = false;
if ( $oVIP->role!='V' ) $bCanEdit=true;
if ( isset($_GET['edit']) ) $_SESSION[QT]['editing']=($_GET['edit']=='1' ? true : false);
if ( isset($_POST['edit']) ) $_SESSION[QT]['editing']=($_POST['edit']=='1' ? true : false);
if ( !$bCanEdit ) $_SESSION[QT]['editing']=false;
if ( isset($_GET['helpframe']) ) $_SESSION[QT]['helpframe']=($_GET['helpframe']=='1' ? true : false);

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

// Tabs dictionary

CheckDico('tab tabdesc');

if ( $tt=='ticket' && $_SESSION[QT]['editing'] ) require_once('bin/qtr_fn_tags.php');

$oSEC = new cSection($s);
$oTopic = new cTopic($t,$oVIP->id);

// exit according to section settings
if ( $oSEC->type!=0 && !$oVIP->IsStaff() )
{
$oVIP->selfname = $L['Section'];
$oVIP->exitname = ObjTrans('index','i',$_SESSION[QT]['index_name']);
if ( $oSEC->type==1 ) $oVIP->EndMessage(NULL,$L['R_staff'],$_SESSION[QT]['skin_dir'],0);
if ( $oSEC->type==2 && $oVIP->role=='V' ) $oVIP->EndMessage(NULL,$L['R_member'].'<br/><br/><a href="'.Href('qtr_login.php').'?s='.$s.'&t='.$t.'">'.$L['Login'].'</a>',$_SESSION[QT]['skin_dir'],0);
if ( $oSEC->type==2 && $oVIP->role=='U' && $oTopic->firstpostuser!=$oVIP->id ) $oVIP->EndMessage(NULL,$L['E_topic_private']."<br/>".$L['R_member'],$_SESSION[QT]['skin_dir'],0);
}

$arrTabs = array();
$arrOtherTabs = array();

if ( $oTopic->type!='T' )
{
  // get only basic tabs in case of news/inspection topic
  $arrTabs = GetSectionTabs(-2);
  if ( isset($arrTabs['ticket']) )
  {
  if ( $oTopic->type=='A' ) { $arrTabs['ticket']->tabname=L('News'); $arrTabs['ticket']->tabdesc=L('News'); }
  if ( $oTopic->type=='I' ) { $arrTabs['ticket']->tabname=L('Inspection'); $arrTabs['ticket']->tabdesc=L('Inspection'); }
  }
}
else
{
  $arrTabs = GetSectionTabs($s);

  // add 'other' to the tabs (if $arrOtherTabs is not empty)
  $arr = $oTopic->GetDataTabs(array_keys($arrTabs));
  if ( count($arr)>0 )
  {
    $arrTabs['other'] = cTab::GetTab('other');
    // create a new list with the db-properties of the other tabs
    foreach($arr as $str) $arrOtherTabs[$str] = cTab::GetTab($str);
  }
}

$strCommand = '';
if ( isset($_GET['view']) ) { $_SESSION[QT]['viewmode'] = $_GET['view']; }

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

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

if ( $oVIP->IsStaff() ) include('qtr_p_staffmenu.php'); // define staff menu and process submitted staff actions

// MAP MODULE

$bMap = UseModule('map');
if ( $bMap && $tt!='ticket' ) $bMap=false;
if ( $bMap ) { $strCheck=$s; include('qtrm_map_ini.php'); }

// BUTTONS

if ( $oSEC->status==1 )
{
  $strCommand = '<td class="button" style="width:120px"><span class="button_off">&nbsp;'.$L['E_section_closed'].'&nbsp;</span></td>';
}
else
{
  $strCommand = '<td class="button" style="width:120px">&nbsp;<a class="button" href="'.Href('qtr_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" style="width:120px"><span class="button_off">&nbsp;'.$L['Post_new_topic'].'&nbsp;</span></td>';
  }
}
$strCommand = ( QTR_BACKBUTTON ? '<td class="button" style="width:20px"><a href="'.Href($oVIP->exiturl).'" class="button">'.QTR_BACKBUTTON.'</a></td>' : '').$strCommand;

// TOPIC DESCRIPTION AND MAP

$strDescr = '';
$strLocation = '';

// topic description

if ( $_SESSION[QT]['section_desc']=='1' )
{
  if ( $oTopic->numid >= 0 && $oSEC->numfield!='N' )
  {
  $strDescr .= '<p id="topic_reference">';
  $strDescr .= sprintf($oSEC->numfield,$oTopic->numid);
  if ( $oTopic->type=='T') $strDescr .= ' &middot; '.$oVIP->statuses[$oTopic->status]['statusname'];
  $strDescr .= '</p>';
  }
}

// tags

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

// --------
// HTML START // java is required (tabs and edit data)
// --------

$strHeadScript = '';

if ( $tt=='ticket' && !$_SESSION[QT]['editing'] )
{
  $strHeadScript .= '
  <script type="text/javascript" src="bin/qt_jquery.js"></script>
  <script type="text/javascript">
  <!--
  $(document).ready(function() {
    $(".tag").hover(function() {
      var oTag = $(this);
      $.post("qtr_j_tag.php",{s:"'.$s.'",val:oTag.html(),lang:"'.GetIso().'",na:""}, function(data) { oTag.attr({title:data}); } );
      });
    });
  -->
  </script>
  ';
}

if ( $tt=='ticket' && $_SESSION[QT]['editing'] )
{
  $oVIP->arrCss[] = '../bin/css/qt_jquery.css';

  $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 .= '{n:"'.$strKey.'",d:"'.($strKey==$strDesc ? ' ' : substr($strDesc,0,64)).'"},'; }
  $str = substr($str,0,-1);

  $strHeadScript .= '
  <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,
      width:250,
      matchContains:1,
      multiple:true,
      multipleSeparator:";",
      formatItem: function(row) { return (row.d==" ") ? row.n : (row.n+"<span class=small> - " + row.d + "</span>"); },
      formatResult: function(row) { return row.n; }
      });      
    $(".tag").hover(function() {
      var oTag = $(this);
      $.post("qtr_j_tag.php",{s:"'.$s.'",val:oTag.html(),lang:"'.GetIso().'",na:"..."}, function(data) { oTag.attr({title:data}); } );
      });
    });
  -->
  </script>
  ';
}
if ( $tt!='ticket' && $_SESSION[QT]['editing'] )
{
  $strHeadScript .= '
  <script type="text/javascript" src="bin/qt_jquery.js"></script>
  <script type="text/javascript" src="bin/qt_jquery_date.js"></script>
  ';
}

if ( $bMap ) {
if ( !empty($oTopic->x) && !empty($oTopic->y) ) {
  $strBodyAddOnunload='GUnload()';
}}

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

include('qtr_p_header.php');

// Moderator action

if ( isset($strStaffMenu) ) echo $strStaffMenu;

// DISPLAY BUTTON

echo '
<table class="button button_top" cellspacing="0">
<tr class="button">
',$strCommand,'
<td>&nbsp;</td>
</tr>
</table>
<!-- End button and pager -->
';

// DISPLAY TOPIC DESCRIPITION

if ( !empty($strDescr) )
{
  echo $strDescr,N;
}

// DISPLAY TABS

echo HtmlTabs($arrTabs, $oVIP->selfurl.'?s='.$s.'&amp;t='.$t, $tt , 6, true, true, $L['E_editing']);

// DISPLAY TAB PANEL

echo '<table class="pan" cellspacing="0">
<tr class="pan">
<td class="pan">
<div class="pan_top">',(isset($arrTabs[$tt]->tabdesc) ? $arrTabs[$tt]->tabdesc : $tt),'</div>
';

switch($tt)
{
case 'ticket':   include('qtr_topic_t.php'); break;
case 'messages': include('qtr_topic_m.php'); break;
case 'documents':include('qtr_topic_d.php'); break;
case 'other':    include('qtr_topic_xo.php'); break;
default:         include('qtr_topic_x.php');
}

echo '
</td>
</tr>
</table>
';

// QuickSearch frame

if ( $tt=='ticket' && isset($arrTags) ) {
if ( is_array($arrTags) ) {
if ( count($arrTags)>0 ) {

  echo '<p class="small">',$L['Search_tag'],' ';
  foreach($arrTags as $strTag)
  {
    if ( !empty($strTag) ) echo '<span class="tagline" title=""><a class="tag small" href="',Href('qtr_find.php'),'?a=tst&amp;s=',$s,'&amp;y=',date('Y'),'&amp;k1=-1&amp;k2=-1&amp;k3=',urlencode($strTag),'">',$strTag,'</a></span> ';
  }
  echo '</p>';

}}}

// Helpframe

if ( !isset($_SESSION[QT]['helpframe']) ) $_SESSION[QT]['helpframe']=false;

if ( !in_array($tt,array('ticket','messages','documents')) ) {
if ( !empty($arrTabs[$tt]->tabframe) ) {

  $strHelp = QTconv($arrTabs[$tt]->tabframe,'4');
  if ( substr($strHelp,0,1)=='@' ) { $bUrl=true; $strHelp=trim(substr($strHelp,1)); }  else { $bUrl=false; }
  if ( $bUrl && substr($strHelp,0,1)=='@' ) { $bIframe=false; $strHelp=trim(substr($strHelp,1)); }  else { $bIframe=true; }

  if ( $_SESSION[QT]['helpframe'] )
  {
    echo '<p>';
    echo ($bIframe ? '<a href="'.Href().'?s='.$s.'&t='.$t.'&tt='.$tt.'&helpframe=0" onclick="return qtEdited(bEdited,\''.$L['E_editing'].'\');">'.$L['Helpframe_hide'].'</a>' : '<span class="disable">'.$L['Helpframe_hide'].'</span>' );
    echo ($bIframe ? ' &middot; <a href="#" onclick="document.getElementById(\'tabiframe\').src=\''.$strHelp.'\'; return false;">'.$L['Helpframe_refresh'].'</a>' : '' );
    echo ($bUrl ? ' &middot; <a href="'.$strHelp.'" target="_blank">'.$L['Helpframe_window'].'</a>' : '');
    echo '</p>';

    if ( $bUrl )
    {    
      if ( $bIframe )
      {
      echo '<iframe id="tabiframe" class="tabiframe" width="100%" height="500px" src="'.$strHelp.'"></iframe>';
      }
      else
      {
      echo '<p class="disable">The web site is accessible only in a separate window...</p>';
      }
    }
    else
    {
    echo $strHelp;
    }
  }
  else
  {
    echo '<p>';
    echo ($bIframe ? '<a href="'.Href().'?s='.$s.'&t='.$t.'&tt='.$tt.'&helpframe=1" onclick="return qtEdited(bEdited,\''.$L['E_editing'].'\');">'.$L['Helpframe_show'].'</a>' : '<span class="disable">'.$L['Helpframe_show'].'</span>' );
    echo ($bUrl ? ' &middot; <a href="'.$strHelp.'" target="_blank">'.$L['Helpframe_window'].'</a>' : '' );
    echo '</p>';
  }

}}

// --------
// HTML END
// --------

// MAP MODULE
if ( $bMap ) { $bSmallMap=($_SESSION[QT]['viewmode']=='C'); include('qtrm_map_load.php'); }

include('qtr_p_footer.php');

?>
Return current item: QT-registrations