<?php
// QuickTicket 2.5 build:20101222
class cPost
{
// --------
public $id = -1;
public $topic = -1;
public $section = -1;
public $type = 'P';
public $icon = '00';
public $title = '';
public $issuedate = '0';
public $text = '';
public $modifdate = '0';
public $modifuser;
public $modifname;
public $attach;
public $userid;
public $username;
public $userrole;
public $userloca;
public $useravat;
public $usersign;
public $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.photo,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('Invalid constructor parameter#1 for class cPost');
}
if ( $this->type=='D' ) $this->title = ' ';
}
if ( isset($intNum) ) $this->num = intval($intNum);
if ( $_SESSION[QT]['viewmode']=='C' ) $this->text = QTcompact($this->text,0);
}
// --------
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 'photo': $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 CanEdit()
{
// By default, Staff can edit post of other staff (even Admin post)
global $oVIP;
if ( !$oVIP->auth ) return false;
if ( $this->userid==$oVIP->id || $oVIP->role=='A' ) return true;
if ( $oVIP->role=='M' )
{
if ( $this->userrole=='A' && !QTI_STAFFEDITADMIN ) return false;
if ( $this->userrole=='M' && !QTI_STAFFEDITSTAFF ) return false;
return true;
}
return false;
}
// --------
function InsertPost($bTopicStat=false,$bUserStat=false,$bCheckUserPostsToday=true)
{
global $oDB,$oVIP;
// 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).'","'.$this->issuedate.'","'.addslashes(QTconv($this->text,'3',QTI_CONVERT_AMP,false)).'"'.( !empty($this->attach) ? ',"'.$this->attach.'"' : '').')' );
// added for db2
if ( $oDB->type=='db2' )
{
$oDB->Query('UPDATE '.TABPOST.' SET textmsg2="'.addslashes(substr(QTconv($this->text,'3',QTI_CONVERT_AMP,false),0,255)).'" WHERE id='.$this->id);
}
// Update Topic's replies and lastpost (inserting a post does NOT change de modifdate of the topic!)
if ( $bTopicStat )
{
$oDB->Query('UPDATE '.TABTOPIC.' SET replies=replies+1,lastpostid='.$this->id.',lastpostuser='.$this->userid.',lastpostname="'.$this->username.'",lastpostdate="'.$this->issuedate.'" WHERE id='.$this->topic);
}
// Lastpost delay control
$_SESSION['qti_usr_lastpost'] = time();
// Number of posts today control
if ( isset($_SESSION['qti_usr_posts_today']) && $bCheckUserPostsToday )
{
if ( $this->type=='P' || $this->type=='R' ) $_SESSION['qti_usr_posts_today']++;
}
// User stat
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_DIR_DOC.$this->attach) ) unlink(QTI_DIR_DOC.$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 GetIcon($strSkin='skin/default',$strHref='')
{
return AsImg($strSkin.'/ico_post_'.strtolower($this->type).'.gif','P',L('Ico_post_'.strtolower($this->type)),'ico ico_p','',$strHref);
}
// --------
function GetScore($oTopic)
{
if ( $oTopic->type=='I' )
{
$i = strtolower(trim($this->title));
if ( $i==='' || is_null($i) || $i==='null' ) $i=-1;
if ( strlen($i)>4 ) $i = substr($i,0,4);
if ( is_numeric($i) ) { $i=floatval($i); } else { $i=-1; }
return $i;
}
return -1;
}
function GetScoreImage($oTopic,$bName=true)
{
$i = $this->GetScore($oTopic);
return ($i<0 ? S : ValueScalebar($i,$oTopic->ReadOptions('Ilevel')).($bName ? ' '.ValueName($i,$oTopic->ReadOptions('Ilevel')) : ''));
}
function GetScoreName($oTopic)
{
$i = $this->GetScore($oTopic);
return ($i<0 ? '' : ValueName($i,$oTopic->ReadOptions('Ilevel')));
}
// --------
function Show($oSEC,$oTopic,$bAvatar=true,$strEndLine='',$strSep='',$strSkin='skin/default',$strAlt='r1')
{
if ( !isset($oSEC) ) die('oPost->Show: Missing $oSEC');
if ( !isset($oTopic) ) die('oPost->Show: Missing $oTopic');
// Process
global $oVIP,$L,$bMap;
// Prepare icon
$strIcon = ($this->type=='P' ? $oTopic->GetIcon($strSkin) : $this->GetIcon($strSkin));
// Prepare title
if ( $this->type=='D' )
{
$strTitle = '<span title="'.$this->text.'">'.$L['Message_deleted'].'</span>';
}
else
{
$strTitle = $this->title;
if ( $oTopic->type=='I' && $this->type=='R' ) $strTitle = $this->GetScore($oTopic);
if ( $this->type=='P' && !empty($oSEC->wisheddate) && !empty($oTopic->wisheddate) )
{
if ( $oVIP->CanViewCalendar() ) { $strLink = '<a href="'.Href('qti_calendar.php').'?s='.$oTopic->parentid.'&v=wisheddate&y='.substr($oTopic->wisheddate,0,4).'&m='.substr($oTopic->wisheddate,4,2).'" title="'.$L['Ico_view_f_c'].': '.QTdatestr($oTopic->wisheddate,'Y-m-d','',true).'">%s <img class="ico i_modes" src="'.$_SESSION[QT]['skin_dir'].'/ico_view_f_c.gif" alt="C" /></a>'; } else { $strLink = '<a title="'.QTdatestr($oTopic->wisheddate,'Y-m-d','',true).'">%s</a>'; }
$strTitle .= '<span class="wisheddate"> · '.$L['Wisheddate'].': '.sprintf($strLink,QTdatestr($oTopic->wisheddate,'d M','',true)).'</span>';
}
}
// Coord
$strCoord='';
if ( isset($bMap) ) {
if ( $this->type=='P' )
if ( $bMap && !empty($oTopic->y) && !empty($oTopic->x) ) {
$y = floatval($oTopic->y);
$x = floatval($oTopic->x);
global $bMapGoogle;
$strCoord = ' <a href="javascript:void(0)"'.($bMapGoogle && !$_SESSION[QT]['m_map_hidelist'] ? ' onclick="map.setCenter(new GLatLng('.$y.','.$x.')); return false;"' : '').' title="'.$L['Coord'].': '.round($y,8).','.round($x,8).'"><img class="ico" src="'.$_SESSION[QT]['skin_dir'].'/ico_user_m_1.gif" alt="G" title="'.$L['Coord_latlon'].' '.QTdd2dms($y).','.QTdd2dms($x).'" /></a>';
}}
// Message container
echo '
<a id="p',$this->id,'"></a>
<div class="post">
<table class="hidden" cellspacing="0">
<colgroup span="2"><col style="width:25px"></col><col></col></colgroup>
';
// message title
echo '
<tr class="hidden">
<td class="post_icone ',$strAlt,'">',$strIcon,'</td>
<td class="post_title ',$strAlt,'">
<table class="hidden" cellpadding="0">
<tr class="hidden">
<td class="hidden"><p class="post_title">',$strTitle,$strCoord,'</p></td>
<td class="hidden" style="text-align:right"><p class="post_date">',($_SESSION[QT]['viewmode']=='C' || $oTopic->type=='I' ? '<a href="qti_user.php?id='.$this->userid.'" class="a_post_title">'.$this->username.'</a>' : ''),' ',QTdatestr($this->issuedate,'$','$',true),( isset($this->num) ? ' ['.$this->num.']' : ''),'</p>
</td>
</tr>
</table>
</td>
</tr>
';
// message body
if ( $this->type!='D' )
{
echo '<tr class="hidden">',N;
echo '<td class="post_smile ',$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="post_message ',$strAlt,'">',N;
// useravat
$strAvatar = ''; if ( is_string($bAvatar) ) $strAvatar = $bAvatar; // avatar can be replaced by something else (if string is provided)
if ( $_SESSION[QT]['viewmode']!='C' && $bAvatar===true )
{
if ( empty($this->useravat) )
{
$strAvatar = AsImgBox('','picboxmsg','',$this->username.'<br />'.($this->userrole!='U' ? $L['Userrole'][$this->userrole] : '').'<br />'.$this->userloca,'qti_user.php?id='.$this->userid);
}
else
{
$strAvatar = AsImgBox(AsImg(QTI_DIR_PIC.$this->useravat,'',$this->username,'message','','qti_user.php?id='.$this->userid),'picboxmsg','',$this->username.'<br />'.($this->userrole!='U' ? $L['Userrole'][$this->userrole] : '').'<br />'.$this->userloca,'qti_user.php?id='.$this->userid);
}
}
echo $strAvatar;
// message attachment and signature
echo '<p class="msgbody">';
// format the text
$str = QTbbc($this->text,'<br />','</p>','<p class="msgbody">');
// 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_DIR_DOC.$this->attach.'"',$str);
}}}}
echo $str,"</p>\n";
if ( !empty($this->attach) )
{
echo '<p class="attachment">'.AsImg($strSkin.'/ico_attachment.gif','A',$L['Attachment'],'ico i_user');
if ( strstr($this->attach,'/') ) { $str = substr(strrchr($this->attach,'/'),1); } else { $str=$this->attach; }
if ( substr($str,0,strlen($this->id.'_'))==($this->id).'_' ) $str = substr($str,strlen($this->id.'_'));
echo ' <a href="'.QTI_DIR_DOC.$this->attach.'" class="a_attachment" target="_blank">'.$str.'</a></p>',N;
}
if ( $_SESSION[QT]['viewmode']!='C' ){
if ( $this->type!='F' ) {
if ( !empty($this->usersign) ) {
echo '<p class="msgsign">',QTbbc($this->usersign),'</p>',N;
}}}
// command line
echo $strEndLine;
echo '</td>',N,'</tr>',N;
}
// end message container
echo '
</table>
</div>
';
}
// --------
function SetFromPost($bNew=true)
{
$error='';
global $oVIP,$strBehalf;
// Identify the user (can be onbehalf)
$this->modifuser = $oVIP->id;
$this->modifname = $oVIP->username;
if ( isset($_POST['behalf']) )
{
$strBehalf = trim($_POST['behalf']); if ( get_magic_quotes_gpc() ) $strBehalf = stripslashes($strBehalf);
if ( !is_null($strBehalf) && $strBehalf!=='' )
{
// Find behalf id
$strBehalf = htmlspecialchars($strBehalf,ENT_QUOTES);
$intBehalf = current(array_keys(GetUsers('name',$strBehalf) )); // can be FALSE when not found
if ( is_int($intBehalf) ) { $this->modifuser = $intBehalf; $this->modifname = $strBehalf; } else { $error=L('Send_on_behalf').' '.Error(1); }
}
}
// Identify creator as being the user. When editing existing message ($bNew=false) then autor remains unchanged
if ( $bNew )
{
$this->userid = $this->modifuser;
$this->username = $this->modifname;
}
// Read message values
if ( isset($_POST['icon']) ) $this->icon = $_POST['icon'];
if ( isset($_POST['title']) ) $this->title = QTunbbc(trim((get_magic_quotes_gpc() ? stripslashes($_POST['title']) : $_POST['title'])));
if ( isset($_POST['text']) ) $this->text = trim((get_magic_quotes_gpc() ? stripslashes($_POST['text']) : $_POST['text']));
if ( isset($_POST['wisheddate']) )
{
if ( !empty($_POST['wisheddate']) )
{
$str = QTdatestr(trim($_POST['wisheddate']),'Ymd','');
if ( !is_string($str) ) $error = L('Wisheddate').' '.Error(1);
if ( substr($str,0,6)=='Cannot' ) $error = L('Wisheddate').' '.Error(1);
if ( substr($str,0,4)=='1970' ) $error = L('Wisheddate').' '.Error(1);
if ( empty($error) ) $this->wisheddate = $str;
}
}
if ( isset($_POST['oldattach']) ) { $this->attach = $_POST['oldattach']; }
return $error;
}
// --------
}