Location: PHPKode > projects > QuickTicket > quickticket/qti_form_del.php
<?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');
if ( !$oVIP->CanView('V6') ) die(Error(11));

// INITIALISE

$s = -1; // section
$t = -1; // topic
$p = -1; // post
$ok = '';// submitted
QThttpvar('s t p ok', 'int int int str',true,true,true);
if ( $s<0 ) die('Missing parameters s');
if ( $t<0 ) die('Missing parameters t');
if ( $p<0 ) die('Missing parameters p');

$oSEC = new cSection($s);
$oTopic = new cTopic($t);
$oPost = new cPost($p);

$bReason = true;
$strDisabled = '';

$oVIP->selfurl = 'qti_form_del.php';
$oVIP->selfname = $L['Message'];
$oVIP->exiturl = 'qti_topic.php?t='.$t;
$oVIP->exitname = $L['Topics'];

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

if ( isset($_POST['ok']) )
{

  // check user is creator (or Staff)

  if ( $oVIP->role=='V' ) die($L['E_member']);
  if ( $oVIP->role=='U' && $oPost->userid!=$oVIP->id ) die($L['E_member']);

  // topic delete if only one post

  if ( $oTopic->lastpostid==$p && $oTopic->firstpostid==$p )
  {
    // check & delete attachment
    if ( !empty($oPost->attach) ) if ( file_exists(QTI_DIR_DOC.$oPost->attach) ) unlink(QTI_DIR_DOC.$oPost->attach);
    // delete post and topic
    cTopic::Drop($t);
    $oSEC->UpdateStats(array('tags'=>$oSEC->tags));
    $oVIP->exiturl = 'qti_topics.php?s='.$s;
  }
  else
  {
    // physical delete if last post (or in case of inspection)
    if ( $oTopic->lastpostid==$p || $oTopic->type=='I' )
    {
      // check & delete attachment
      if ( !empty($oPost->attach) ) if ( file_exists(QTI_DIR_DOC.$oPost->attach) ) unlink(QTI_DIR_DOC.$oPost->attach);
      // delete post
      $oDB->Query('DELETE FROM '.TABPOST.' WHERE id='.$p);
      $oTopic->UpdateStats(0); // This update firstpost/lastpost (and do not perform close-topic check)
    }
    else
    {
      // logical delete if not last post
      $str = trim($_POST['text']); if ( get_magic_quotes_gpc() ) $str = stripslashes($str);
      $str = substr(QTconv($str,'6'),0,255);
      if ( $oDB->type=='db2' )
      {
      $oDB->Query('UPDATE '.TABPOST.' SET type="D",title="'.$L['Message_deleted'].'", textmsg="'.addslashes($str).'",textmsg2="'.addslashes($str).'", modifdate="'.Date('Ymd His').'", modifuser='.$oVIP->id.' WHERE id='.$p);
      }
      else
      {
      $oDB->Query('UPDATE '.TABPOST.' SET type="D",title="'.$L['Message_deleted'].'", textmsg="'.addslashes($str).'", modifdate="'.Date('Ymd His').'", modifuser='.$oVIP->id.' WHERE id='.$p);
      }
    }
    $oVIP->exiturl = 'qti_topic.php?t='.$t;
  }

  // exit
  $oVIP->EndMessage(NULL,$L['S_delete'],$_SESSION[QT]['skin_dir'],2);

}

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

$oVIP->selfname = $L['Delete'];
if ( $oTopic->lastpostid==$p || $oTopic->type=='I' || $oPost->type=='P' ) $bReason=false;

// CONTENT

include('qti_p_header.php');

echo '<h2>'.$oVIP->selfname.'</h2><br />',N;
echo '<form method="post" action="',Href(),'">',N;
echo '<input type="hidden" name="s" value="',$s,'" />';
echo '<input type="hidden" name="t" value="',$t,'" />';
echo '<input type="hidden" name="p" value="',$p,'" />';
echo '<table class="data_o" cellspacing="0">',N;

echo '<tr class="data_o">';
echo '<td class="colhd colhdfirst" style="width:100px">',$L['Author'],'</td>';
echo '<td class="colct">',$oPost->username,' (',QTdatestr($oPost->issuedate,'$','$',true),')</td>';
echo '</tr>',N;

echo '<tr class="data_o">';

// TITLE

if ( $oTopic->type==='I' && $oPost->type!='P' )
{
  echo '<td class="colhd colhdfirst"><label for="title">',L('Score'),'</label></td>',N;
  echo '<td class="colct">',$oPost->GetScoreImage($oTopic),'</td>',N;
}
else
{
  if ( $oSEC->titlefield!=0 )
  {
  echo '<td class="colhd colhdfirst"><label for="title">',$L['Title'],'</label></td>',N;
  echo '<td class="colct">',$oPost->title,'</td>',N;
  }
}
echo '</tr>',N;
echo '<tr class="data_o">';
echo '<td class="colhd colhdfirst"><label for="oldtext">'.$L['Message'].'</label><br /></td>';
echo '<td class="colct">',($oPost->icon=='00' ? '' : '<img class="ico_prefi" src="'.$_SESSION[QT]['skin_dir'].'/ico_prefix_'.$oSEC->prefix.'_0'.$i.'.gif" label="smile" title="'.$L['Ico_prefix'][$oSEC->prefix.'_0'.$i].'" /> '),QTbbc($oPost->text),'</td>';
echo '</tr>',N;
if ( $_SESSION[QT]['upload']!='0' ) {
if ( !empty($oPost->attach) ) {
echo '<tr class="data_o">';
echo '<td class="colhd colhdfirst">',$L['Attachment'],'</td>';
echo '<td class="colct"><input'.QDIS.' type="text" size="75" value="',$oPost->attach,'" /><input type="hidden" id="attach" name="attach" value="'.$oPost->attach.'" /></td>';
echo '</tr>',N;
}}
if ( $bReason )
{
echo '<tr class="data_o">';
echo '<td class="colhd colhdfirst"><label for="text">',$L['Reason'],'</label><br /></td>';
echo '<td class="colct">';
echo '<textarea id="text" name="text" rows="2" wrap="virtual" cols="80"></textarea></td>';
echo '</tr>',N;
}
echo '<tr class="data_o">';
echo '<td class="colhd colhdfirst">&nbsp;</td>';
echo '<td class="colct"><input type="submit" name="ok" value="',$L['Delete'],'" />&nbsp;';
if ( !empty($error) ) echo '<span class="error">',$error,'</span>';
echo '</td>';
echo '</tr>',N;
echo '</table></form><br />',N;

// HTML END

include('qti_p_footer.php');

?>
Return current item: QuickTicket