Location: PHPKode > projects > QuickTicket > quickticket/quickticket/qti_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.
 *
 * @category   Troubleticket
 * @package    QuickTicket
 * @author     Philippe Vandenberghe <hide@address.com>
 * @copyright  2008-2012 The PHP Group
 * @license    http://www.php.net/license  PHP License 3.0
 * @version    1.9.0.3 build:20081001
 * @link       http://www.qt-cute.org/doc/package/qti
 * @since      File available since Release 1.0.0
 * @deprecated File deprecated in Release 2.0.0
 *
 */

session_start();
require_once('bin/qti_init.php');
if ( $_SESSION[QT]['visitor_right']<3 && $oVIP->role=='V' )
{
  include('qti_p_header.php');
  HtmlMsg(0);
  echo $L['R_login_register'];
  HtmlMsg(1);
  include('qti_p_footer.php');
  exit;
}
if ( !$oVIP->CanAccess('MUV',3,true) ) $oVIP->EndMessage('!',$L['R_member'],$_SESSION[QT]['skin_dir'],0);

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

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

// ---------
// SUBMITTED
// ---------
//
// When Moderator change actor+status, actor must be changed first to notify him on the status change...
//
if (isset($_POST['Msection']))
{
  $s = intval($_POST['Msection']);
  $t = intval($_POST['Mtopic']);
  $oVIP->exiturl = 'qti_topics.php?s='.$s;
  $oVIP->exitname = $L['Section'];

  if ( empty($_POST['Mactor']) && empty($_POST['Maction']) )
  {
    if ( headers_sent() )
    {
    echo '<a href="qti_topic.php?s=',$s,'&amp;t=',$t,'">No action</a><meta http-equiv="REFRESH" content="0;url=qti_topic.php?s=',$s,'&amp;t=',$t,'">';
    }
    else
    {
    header('Location: qti_topic.php?s='.$s.'&t='.$t);
    }
    exit;
  }

  if ( !empty($_POST['Mactor']) )
  {
    if ( !isset($t) ) die('Missing topic id');

    if ( $_POST['Mactor']=='actor*' )
    {
      if ( headers_sent() )
      {
      echo '<a href="qti_cmd.php?a=topicactor&amp;s=',$s,'&amp;t=',$t,'&amp;v=*&amp;old=',$_POST['Moldactor'],'">',$L['Change'],' ',$L['Status'],'</a><meta http-equiv="REFRESH" content="0;url=qti_cmd.php?a=topicactor&amp;s=',$s,'&amp;t=',$t,'&amp;v=*&amp;old=',$_POST['Moldactor'],'">';
      }
      else
      {
      header('Location: qti_cmd.php?a=topicactor&s='.$s.'&t='.$t.'&v=*&old='.$_POST['Moldactor']);
      }
      exit;
    }

    $oTopic = new cTopic($t);
    $oTopic->SetActor($_POST['Mactor']);
    // exit (if no action, if action, continue with action
    if ( empty($_POST['Maction']) )
    {
      $oVIP->selfname = $L['Change'].S.$L['Userrole_MA'];
      $oVIP->EndMessage(NULL,$L['S_update'],$_SESSION[QT]['skin_dir'],2);
    }
  }

  if ( substr($_POST['Maction'],0,7)=='status_' )
  {
    if ( headers_sent() )
    {
    echo '<a href="qti_cmd.php?a=topicstatus&amp;s=',$s,'&amp;t=',$t,'&amp;v=',substr($_POST['Maction'],-1,1),'">',$L['Change'],' ',$L['Status'],'</a><meta http-equiv="REFRESH" content="0;url=qti_cmd.php?a=topicstatus&amp;s=$s&amp;t=$t&amp;v='.substr($_POST['Maction'],-1,1).'">';
    }
    else
    {
    header('Location: qti_cmd.php?a=topicstatus&s='.$s.'&t='.$t.'&v='.substr($_POST['Maction'],-1,1));
    }
    exit;
  }

  if ( substr($_POST['Maction'],0,5)=='type_' )
  {
    if ( headers_sent() )
    {
    echo '<a href="qti_cmd.php?a=topictype&amp;s=',$s,'&amp;t=',$t,'&amp;v=',substr($_POST['Maction'],-1,1),'">',$L['Change'],' ',$L['Status'],'</a><meta http-equiv="REFRESH" content="0;url=qti_cmd.php?a=topicstatus&amp;s=$s&amp;t=$t&amp;v='.substr($_POST['Maction'],-1,1).'">';
    }
    else
    {
    header('Location: qti_cmd.php?a=topictype&s='.$s.'&t='.$t.'&v='.substr($_POST['Maction'],-1,1));
    }
    exit;
  }

  if ($_POST['Maction']=='reply')
  {
    if ( headers_sent() )
    {
    echo '<a href="qti_form_edit.php?s=',$s,'&amp;t=',$t,'&amp;a=re">',$L['Post_reply'],'</a><meta http-equiv="REFRESH" content="0;url=qti_form_edit.php?s=',$s,'&amp;t=',$t,'&amp;a=re">';
    }
    else
    {
    header('Location: qti_form_edit.php?s='.$s.'&t='.$t.'&a=re');
    }
    exit;
  }
  if ($_POST['Maction']=='move')
  {
    if ( headers_sent() )
    {
    echo '<a href="qti_cmd.php?a=topicmove&amp;s=',$s,'&amp;t=',$t,'">',$L['Move'],'</a><meta http-equiv="REFRESH" content="0;url=qti_cmd.php?a=topicmove&amp;s=',$s,'&amp;t=',$t,'">';
    }
    else
    {
    header('Location: qti_cmd.php?a=topicmove&s='.$s.'&t='.$t);
    }
    exit;
  }
  if ($_POST['Maction']=='delete')
  {
    if ( headers_sent() )
    {
    echo '<a href="qti_cmd.php?a=topicdelete&amp;s=',$s,'&amp;t=',$t,'">',$L['Delete'],'</a><meta http-equiv="REFRESH" content="0;url=qti_cmd.php?a=topicdelete&amp;s=',$s,'&amp;t=',$t,'">';
    }
    else
    {
    header('Location: qti_cmd.php?a=topicdelete&s='.$s.'&t='.$t);
    }
    exit;
  }
}

// INITIALISE

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

include('bin/qti_fn_limitsql.php');

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

  if ( $oSEC->type==1 && ($oVIP->role=='V' || $oVIP->role=='U') )
  {
  // exit
  $oVIP->selfname = $L['Section'];
  $oVIP->exitname = ObjectName('index','i',$_SESSION[QT]['index_name']);
  $oVIP->EndMessage(NULL,$L['R_moderator'],$_SESSION[QT]['skin_dir'],0);
  }
  if ( $oSEC->type==2 && $oVIP->role=='V' )
  {
  // exit
  $oVIP->selfname = $L['Section'];
  $oVIP->exitname = ObjectName('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 = ObjectName('index','i',$_SESSION[QT]['index_name']);
  $oVIP->EndMessage(NULL,$L['E_topic_private']."<br/>".$L['R_member'],$_SESSION[QT]['skin_dir'],0);
  }

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

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

// MAP MODULE

$bMap = UseModule('map');
if ( $bMap ) { if ( empty($_SESSION[QT]['m_map_gkey']) ) $bMap=false; }
if ( $bMap ) { require_once('qtim_map_lib.php'); if ( !QTgcanmap($s) ) $bMap=false; }
if ( $bMap ) include(Translate('qtim_map.inc'));

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

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

$arrJava = array('img'=>true,'bbc'=>$_SESSION[QT]['show_quick_reply']>'0','iestyle'=>true);

include('qti_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("$oVIP->selfurl?s={$oSEC->id}&t={$oTopic->id}",$intPosts,$_SESSION[QT]['topics_per_page'],$PAGEcurr);
if ($pager!='') $pager = $L['Page'].$pager;

// BUTTONS

if ( $oSEC->status==1 )
{
  $strCommand = '<td class="td_button" style="width:120px"><span class="a_button_off">&nbsp;'.$L['E_section_closed'].'&nbsp;</span></td>'.N;
}
else
{
  $strCommand = '<td class="td_button" style="width:120px">&nbsp;<a class="a_button" href="qti_form_edit.php?s='.$oSEC->id.'&amp;t='.$oTopic->id.'&amp;a=re">'.$L['Post_reply'].'</a>&nbsp;</td>'.N;
  if ( $oTopic->status=='Z' || $oTopic->status=='0' ) $strCommand = '<td class="td_button" style="width:120px"><span class="a_button_off">&nbsp;'.$L['Topic_closed'].'&nbsp;</span></td>'.N;

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

$strCommand = ( QTI_BACKBUTTON ? '<td class="td_button" style="width:20px"><a href="'.$oVIP->exiturl.'" class="a_button">'.QTI_BACKBUTTON.'</a></td>' : '').$strCommand;

// -- Displays Button line and pager --

echo '<!-- Button and pager -->',N;

// Moderator action
if ( $oVIP->role=='M' || $oVIP->role=='A' )
{
  // list of status
  $strStatus = '';
  foreach ($_SESSION['qtiTstatus'] as $strId => $strValue)
  {
  $strStatus .= '<option value="status_'.$strId.'"'.($oTopic->status==$strId ? ' class="bold"' : '').'>'.$L['Status'].': '.$strValue['statusname'].'</option>';
  }
  // list of types
  $strTypes = '';
  foreach ($_SESSION['qtiTtypes'] as $strId => $strValue)
  {
  $strTypes .= '<option value="type_'.$strId.'"'.($oTopic->type==$strId ? ' class="bold"' : '').'>'.$L['Type'].': '.$strValue['name'].'</option>';
  }
  // list of actors (take the top 12, then reorder by name)
  $arr = GetUsers('M','','numpost DESC,name ASC');
  $arrModerators = array();
  $i=1;
  foreach ($arr as $intKey=>$strValue) { $arrModerators[$intKey]=$strValue; $i++; if ( $i>12 ) break; }
  asort($arrModerators);
  $strActors = '';
  foreach ($arrModerators as $intId => $strName) { $strActors .= '<option value="'.$intId.'"'.($oTopic->actorid==$intId ? ' class="bold"' : '').'>'.$strName.'</option>'; }
  if ( count($arr)>12 )
  {
  $strActors .= '<option value="" disabled="disabled">-----------------</option>';
  $strActors .= '<option value="actor*">'.$L['More'].'...</option>';
  }

echo '
<form method="post" action="qti_topic.php" id="modaction">
<div class="div_modboard">
<span class="span_modboard">',$L['Topic'],S,'<input type="hidden" name="Msection" value="',$oTopic->section,'"/>
<input type="hidden" name="Mtopic" value="',$oTopic->id,'"/>
<input type="hidden" name="Mref" value="',$oTopic->numid,'"/>
<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>',S,$L['Change_actor'],S,'
<select name="Mactor" class="small" onchange="document.getElementById(\'modaction\').submit();">
<option value="">',S,'</option>',$strActors,'
</select> <input type="submit" name="Msubmit" value="',$L['Ok'],'" class="small" id="action_ok"/>
<script type="text/javascript">
<!--
document.getElementById("action_ok").style.visibility="hidden";
document.getElementById("action_ok").value="";
-->
</script>
</span>
</div>
</form>
';
}
// End Moderator action

// 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">'.N;
  $strDescr .= sprintf($oSEC->numfield,$oTopic->numid);
  if ( $oTopic->type=='T') $strDescr .= '<br/>'.$_SESSION['qtiTstatus'][$oTopic->status]['statusname'];
  $strDescr .= '</p>'.N;
  }
}
// map module
if ( $bMap )
{
  if ( !empty($oTopic->y) && !empty($oTopic->x) )
  {
  if ( $_SESSION[QT]['viewmode']=='C' )
  {
  $strLocation .= '
  <div class="div_gmap" style="margin:0 0 0 auto;width:375px;">
  <div id="map_canvas" style="width:100%; height:180px;"></div>
  '.(($oTopic->firstpostuser==$oVIP->id || $oVIP->role=='A' || $oVIP->role=='M') ? '<p class="p_gmap" style="margin:4px 0 0 0">'.$L['map']['editmove'].'</p>' : '' ).'</div>
  ';
  }
  else
  {
  $strLocation .= '
  <div class="div_gmap" style="margin:0;">
  <div id="map_canvas" style="width:100%; height:350px;"></div>
  '.(($oTopic->firstpostuser==$oVIP->id || $oVIP->role=='A' || $oVIP->role=='M') ? '<p class="p_gmap" style="margin:4px 0 0 0">'.$L['map']['editmove'].'</p>' : '' ).'</div>
  ';
  }
  }
  else
  {
  $strLocation .= '<p class="p_gmap">'.$L['map']['E_noposition'].'</p>';
  }
}

// display topic descripition and map
if ( !empty($strDescr) || !empty($strLocation) )
{
  echo '
  <!-- Ticket description -->
  <table class="ta_hidden" cellspacing="0">
  <colgroup span="2"><col width="180"></col><col></col></colgroup>
  <tr class="tr_hidden">
  <td class="td_hidden">',$strDescr,'</td>
  <td class="td_hidden">',$strLocation,'</td>
  </tr>
  </table>
  <!-- Ticket description -->';
}

// DISPLAY PAGER

echo '<table class="ta_button ta_button_top" cellspacing="0">',N;
echo '<tr class="tr_button">',N;
echo $strCommand,'<td id="zone_pager_top">',$pager,'</td>',N;
echo '</tr>',N,'</table>',N;
echo '<!-- End button and pager -->',N,N;

// CONTENT

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

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

  /* ooooooo */
  $strState = 'p.id,p.forum,p.topic,p.icon,p.title,p.type,p.userid,p.username,p.issuedate,p.modifdate,p.modifuser,p.modifname,p.attach,p.textmsg, u.role, u.location, u.avatar, u.signature
  FROM '.TABPOST.' p, '.TABUSER.' u WHERE p.userid = u.id AND p.topic='.$oTopic->id;
  $strQuery = LimitSQL($strState,'p.id ASC',$limit,$_SESSION[QT]['replies_per_page'],$intPosts);
  $oDB->Query($strQuery);
  /* ooooooo */
  $iMsgNum = $limit;
  $iMsgAdd = 1;
  $intWhile= 0;
  $strAlt = '1';
  $strSep = '<div class="div_post_sep_'.($_SESSION[QT]['viewmode']=='N' ? 'n' : 'c').'"></div>'.N;
  $bButton = true;
  $bAvatar = true;
  /* ooooooo */
  include('qti_topic_inc.php');
  /* ooooooo */

// BUTTON LINE AND PAGER
if ( $intPosts>1 )
{
echo '<!-- Button and pager -->',N;
echo '<table class="ta_button ta_button_bot" cellspacing="0">',N;
echo '<tr class="tr_button">',N;
echo $strCommand,'<td id="zone_pager_bot">',$pager,'</td>',N;
echo '</tr>',N;
echo '</table>',N;
echo '<!-- End button and pager -->',N,N;
}

// QUICK REPLY

if ( $_SESSION[QT]['show_quick_reply']=='1' )
{
  if ( $oSEC->status=='0' && $oTopic->status!='Z' && $oTopic->status!='0' )
  {
    if ( $oVIP->role=='V' && $_SESSION[QT]['visitor_right']<7 )
    {
    }
    else
    {
    echo '  <!-- Quick reply -->',N;
    echo '  <div class="fs_quickreply">',N;
    $intMax = $_SESSION[QT]['chars_per_post'];
    echo '  <script type="text/javascript">
    <!--
    function ValidateForm(theForm)
    {
      if (theForm.text.value.length==0) { alert(html_entity_decode("',$L['E_mandatory'],': ',$L['Message'],'")); return false; }
      if (theForm.text.value.length>'.$intMax.') { alert("Message too long: Maxlenght < ',$intMax,'"); return false; }
      return null;
    }
    -->
    </script>',N;
    echo '<form method="post" action="qti_form_edit.php" onsubmit="return ValidateForm(this);">',N;
    echo '<input type="hidden" name="section" value="',$oSEC->id,'"/>
    <input type="hidden" name="topic" value="',$oTopic->id,'"/>
    <input type="hidden" name="action" value="re"/>
    <input type="hidden" name="ref" value="',$oTopic->numid,'"/>
    <input type="hidden" name="icon" value="00"/>
    <input type="hidden" name="title" value=""/>',N;
    echo $L['Quick_reply'],S,S,N;
    include('qti_form_button.php');
    echo '&nbsp;&nbsp;<input type="submit" id="dopreview" name="dopreview" value="',$L['Advanced_reply'],'" class="small"/><br/>',N;
    echo '<a href="textarea"></a>';
    echo '<textarea id="text" name="text" rows="5" wrap="virtual" cols="85"></textarea>';
    echo '&nbsp;<input type="submit" id="dosend" name="dosend" value="',$L['Send'],'"/>',N;
    echo '</form>',N,'</div>',N;
    echo '<!-- End Quick reply -->',N,N;
    }
  }
}

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

if ( $bMap ) {
if ( !empty($oTopic->y) && !empty($oTopic->x) ) {

  $y = floatval($oTopic->y);
  $x = floatval($oTopic->x);
  $str = ( $oSEC->numfield=='N' ? '' : sprintf($oSEC->numfield,$oTopic->numid) );

  $oMapPoint = new cMapPoint($y,$x,$str);
  if ( isset($_SESSION[QT]['m_map'][$s]['icon']) )        $oMapPoint->icon        = $_SESSION[QT]['m_map'][$s]['icon'];
  if ( isset($_SESSION[QT]['m_map'][$s]['shadow']) )      $oMapPoint->shadow      = $_SESSION[QT]['m_map'][$s]['shadow'];
  if ( isset($_SESSION[QT]['m_map'][$s]['printicon']) )   $oMapPoint->printicon   = $_SESSION[QT]['m_map'][$s]['printicon'];
  if ( isset($_SESSION[QT]['m_map'][$s]['printshadow']) ) $oMapPoint->printshadow = $_SESSION[QT]['m_map'][$s]['printshadow'];
  $arrMapPoints = array( $oMapPoint );

  $strFooterAddScript = QTgmappoints($L['map'],$y,$x,'',$arrMapPoints,false,$_SESSION[QT]['viewmode']=='C').N.'mapload();';

}}

include('qti_p_footer.php');

?>
Return current item: QuickTicket