Location: PHPKode > projects > QuickTicket > quickticket/quickticket/bin/qti_class_post.php
<?php

// QuickTicket 1.9.0.3 build:20081001

class cPost
{

// --------

var $id = -1;
var $topic = -1;
var $section = -1;
var $type = 'P';
var $icon = '00';
var $title = '';
var $issuedate = '0';
var $text = '';
var $modifdate = '0';
var $modifuser;
var $modifname;
var $attach;
var $userid;
var $username;
var $userrole;
var $userloca;
var $useravat;
var $usersign;
var $num;

// --------

function cPost($aPost=null,$intNum=null)
{
  if ( isset($aPost) )
  {
    if ( is_int($aPost) )
    {
      if ( $aPost<0 ) die('No post '.$aPost);
      global $oDB;
      $oDB->Query('SELECT p.*,u.role,u.location,u.avatar,u.signature FROM '.TABPOST.' p LEFT JOIN '.TABUSER.' u ON p.userid=u.id WHERE p.id='.$aPost);
      $row = $oDB->Getrow();
      $this->MakeFromArray($row);
    }
    elseif ( is_array($aPost) )
    {
      $this->MakeFromArray($aPost);
    }
    elseif ( strtolower(get_class($aPost))=='cpost' )
    {
      $this->id       = $aPost->id;
      $this->topic    = $aPost->topic;
      $this->section  = $aPost->section;
      $this->type     = $aPost->type;
      $this->icon     = $aPost->icon;
      $this->title    = $aPost->title;
      $this->text     = $aPost->text;
      $this->issuedate= $aPost->issuedate;
      $this->userid   = $aPost->userid;
      $this->username = $aPost->username;
      $this->userrole = $aPost->userrole;
      $this->userloca = $aPost->userloca;
      $this->useravat = $aPost->useravat;
      $this->usersign = $aPost->usersign;
      $this->modifdate= $aPost->modifdate;
      $this->modifuser= $aPost->modifuser;
      $this->modifname= $aPost->modifname;
      $this->attach   = $aPost->attach;
    }
    else
    {
      die('Invalide constructor parameter#1 for class cPost');
    }

    if ( $this->type=='D' ) $this->title = '&nbsp;';

  }
  if ( isset($intNum) ) $this->num = intval($intNum);
  if ( $_SESSION[QT]['viewmode']=='C' ) $this->text = QTcompactline($this->text);
}

// --------

function MakeFromArray($aPost)
{
  if ( !is_array($aPost) ) die('cPost->MakeFromArray: aPost is not an array');
  foreach ($aPost as $strKey => $oValue) {
  switch ($strKey) {
    case 'id':       $this->id     = intval($oValue); break;
    case 'forum':    $this->section= intval($oValue); break;
    case 'topic':    $this->topic  = intval($oValue); break;
    case 'type':     $this->type   = $oValue; break;
    case 'icon':     $this->icon   = $oValue; break;
    case 'title':    $this->title  = $oValue; break;
    case 'textmsg':  $this->text = $oValue; break;
    case 'issuedate':$this->issuedate = $oValue; break;
    case 'userid':   $this->userid   = intval($oValue); break;
    case 'username': $this->username = $oValue; break;
    case 'role':     $this->userrole = $oValue; break;
    case 'location': $this->userloca = $oValue; break;
    case 'avatar':   $this->useravat = $oValue; break;
    case 'signature':$this->usersign = $oValue; break;
    case 'modifdate':$this->modifdate= $oValue; break;
    case 'modifuser':$this->modifuser= intval($oValue); break;
    case 'modifname':$this->modifname= $oValue; break;
    case 'attach':   $this->attach   = $oValue; break;
  }}
}

// --------

function InsertPost($bUserStat=true)
{
  global $oDB;

  // insert

  $oDB->Query(
  'INSERT INTO '.TABPOST.'
  (
  id,forum,topic,title,type,icon,userid,username,issuedate,textmsg'.( !empty($this->attach) ? ',attach' : '').'
  )
  VALUES
  (
  '.$this->id.','.$this->section.','.$this->topic.',"'.addslashes(QTconv($this->title,'3',QTI_CONVERT_AMP,false)).'","'.$this->type.'","'.$this->icon.'",'.$this->userid.',"'.addslashes($this->username).'","'.Date('Ymd His').'","'.addslashes(QTconv($this->text,'3',QTI_CONVERT_AMP,false)).'"'.( !empty($this->attach) ? ',"'.$this->attach.'"' : '').'
  )'
  );

  // lastpost

  $_SESSION['qti_usr_lastpost'] = time();

    // added for db2 and ifx
    if ( $oDB->type=='db2' || $oDB->type=='ifx')
    {
    $oDB->Query('UPDATE '.TABPOST.' SET textmsg2="'.addslashes(substr(QTconv($this->text,'3',QTI_CONVERT_AMP,false),0,255)).'" WHERE id='.$this->id);
    }

  $_SESSION[QT]['sys_messages']++;
  if ( isset($_SESSION['qti_usr_posts_today']) )
  {
    if ( $this->type=='P' || $this->type=='R' ) $_SESSION['qti_usr_posts_today']++;
  }

  if ( $bUserStat )
  {
  $oDB->Query('UPDATE '.TABUSER.' SET lastdate="'.Date('Ymd His').'", numpost=numpost+1, ip="'.$oDB->ip.'" WHERE id='.$this->userid);
  $_SESSION[QT.'_usr_posts']++;
  }
}

// --------

function Dropattach()
{
  if ( $this->id<0 ) die('Post->Dropattach: Wrong post id');
  
  global $oDB;
  if ( file_exists(QTI_DOC_FOLDER.$this->id.'_'.$this->attach) ) unlink(QTI_DOC_FOLDER.$this->id.'_'.$this->attach);
  $oDB->Query('UPDATE '.TABPOST.' SET attach="" WHERE id='.$this->id);
  $this->attach = NULL;
  if ( strstr($this->text,'[img]@[/img]') ) $this->text = str_replace('[img]@[/img]','',$this->text);
}

// --------

function Show($oSEC,$oTopic,$bAvatar=true,$strEndLine='',$strSep='',$strSkin='skin/default',$strAlt='1')
{
  // Check

  if ( !isset($oSEC) ) die('oPost->Show: Missing $oSEC');
  if ( !isset($oTopic) ) die('oPost->Show: Missing $oTopic');

  // Process

  global $L;

  // prepare icon

  if ( $this->type=='P' )
  {
    if ( strtolower($oTopic->type)=='a' )
    {
      $strIcon = AsImg($strSkin.'/ico_topic_a_0.gif','T',$L['Ico_topic_a_0'],'ico ico_t');
    }
    else
    {
      if ( isset($_SESSION['qtiTstatus'][$oTopic->status]['statusname']) )
      {
      $strIcon = AsImg($strSkin.'/'.$_SESSION['qtiTstatus'][$oTopic->status]['icon'],'T',$_SESSION['qtiTstatus'][$oTopic->status]['statusname'],'ico ico_t');
      }
      else
      {
      $strIcon = AsImg('admin/ico_status.gif/ico_topic_a_0.gif','T','unknown status','ico ico_t');
      }
    }
  }
  else
  {
    $strIcon = AsImg($strSkin.'/ico_post_'.strtolower($this->type).'.gif','P',$L['Ico_post_'.strtolower($this->type)],'ico ico_p');
  }

  // prepare title

  if ( $this->type=='D' )
  {
    $strTitle = '<span title="'.$this->text.'">'.$L['Message_deleted'].'</span>';
  }
  else
  {
    $strTitle = $this->title;
    if ( !empty($oSEC->wisheddate) && !empty($oTopic->wisheddate) )
    {
    $strTitle .= '<span class="small"> &middot; '.$L['Wisheddate'].': '.QTdate($oTopic->wisheddate,array('n','date',$_SESSION[QT]['formatdate'],null,$L['dateSQL'])).'</span>';
    }
  }

  // message container

  echo '
  <a id="p',$this->id,'"></a>
  <div class="div_post">
  <table class="ta_hidden" cellspacing="0">
  <colgroup span="2">
  <col style="width:25px"></col>
  <col></col>
  </colgroup>
  ';

  // message title

  echo '
  <tr class="tr_hidden">
  <td class="td_p_ico',$strAlt,'">',$strIcon,'</td>
  <td class="td_p_tit',$strAlt,'">
  <table class="ta_hidden" cellpadding="0">
  <tr class="tr_hidden">
  <td class="td_hidden"><span class="p_post_title">',$strTitle,'</span></td>
  <td class="td_hidden" style="text-align:right">
  <span class="p_post_title">',($_SESSION[QT]['viewmode']=='C' ? '<a href="qti_usr.php?id='.$this->userid.'" class="a_post_title">'.$this->username.'</a>' : ''),S,QTdate($this->issuedate,array('n','todaytime',$_SESSION[QT]['formatdate'],$_SESSION[QT]['formattime'],$L['dateSQL'])),( $this->num>=0 ? '&nbsp;['.$this->num.']' : ''),'</span>';
  // ----------
  // module note
  if ( isset($_SESSION[QT]['m_note']) )
  {
  if ( $_SESSION[QT]['m_note']=='1' ) MakeWarningButton($this);
  }
  // ----------
  echo '</td>
  </tr>
  </table>
  </td>
  </tr>
  ';

  // message body

  if ( $this->type!='D' )
  {
    echo '<tr class="tr_hidden">',N;
    echo '<td class="td_p_smi',$strAlt,'">',($this->icon!='00' ? AsImg($strSkin.'/ico_prefix_'.$oSEC->prefix.'_'.$this->icon.'.gif','[o]',$L['Ico_prefix'][$oSEC->prefix.'_'.$this->icon],'ico ico_prefix') : S),'</td>',N;
    echo '<td class="td_p_msg',$strAlt,'">',N;

    // avatar
    $strAvatar = '';
    if ( $_SESSION[QT]['viewmode']!='C' && $bAvatar )
    {
      if ( !empty($this->useravat) ) $strAvatar = 'avatar/'.$this->userid.'.'.$this->useravat;
      $strAvatar = AsImgBox(AsImg($strAvatar,'',$this->username,null,null,'qti_usr.php?id='.$this->userid),'div_pic_msg',null,array($this->username,($this->userrole!='U' ? $L['Userrole'][$this->userrole] : ''),$this->userloca),'qti_usr.php?id='.$this->userid).N;
    }
    echo $strAvatar;

    // message attachment and signature
    echo '<p class="p_post_msg">';
      // format the text
      $str = QTbbc($this->text,'html','<br/>',0,'</p>','<p class="p_post_msg">',' ');
      // show the image (if any)
      if ( $_SESSION[QT]['viewmode']!='C' ) {
      if ( !empty($this->attach) ) {
      if ( in_array(substr($this->attach,-4,4),array('.gif','.jpg','jpeg','.png')) ) {
      if ( strstr($str, 'src="@"') ) {
        $str = str_replace('src="@"','src="'.QTI_DOC_FOLDER.$this->id.'_'.$this->attach.'"',$str);
      }}}}
    echo $str,"</p>\n";

    if ( !empty($this->attach) )
    {
    echo '<p class="p_attachment">'.AsImg($strSkin.'/ico_attachment.gif','A',$L['Attachment'],'ico ico_user');
    echo '&nbsp;<a href="'.QTI_DOC_FOLDER.$this->id.'_'.$this->attach.'" class="a_attachment" target="_blank">'.$this->attach.'</a></p>',N;
    }
    if ( $_SESSION[QT]['viewmode']!='C' ){
    if ( $this->type!='F' ) {
    if ( !empty($this->usersign) ) {
      echo '<p class="p_post_sign">',QTbbc($this->usersign),'</p>',N;
    }}}

    // command line
    echo $strEndLine;
    echo '</td>',N,'</tr>',N;
  }

  // end message container

  echo '
  </table>
  </div>
  ';
}

// --------

}

?>
Return current item: QuickTicket