<?php
// QuickTicket 1.9.0.3 build:20081001
class cStatus
{
// --------
function Add($id='',$name='',$icon='',$color='',$mailto='')
{
// Check
if ( !is_string($id) || empty($id) ) die('cStatus->Add: Argument #1 must be a string');
if ( !is_string($name) || empty($name) ) die('cStatus->Add: Argument #2 must be a string');
if ( !is_string($icon) ) die('cStatus->Add: Argument #3 must be a string');
if ( !is_string($color) ) die('cStatus->Add: Argument #4 must be a string');
if ( !is_string($mailto) ) die('cStatus->Add: Argument #5 must be a string');
// Process
global $oDB;
$qti_error = '';
$id = strtoupper(substr(trim($id),0,1));
$name = QTconv($name,'3',QTI_CONVERT_AMP);
// unique id and name
$oDB->Query('SELECT count(*) AS countid FROM '.TABSTATUS.' WHERE id="'.$id.'"');
$row=$oDB->Getrow();
if ( $row['countid']>0 ) $qti_error = "Status id [$id] already used";
$oDB->Query('SELECT count(*) AS countid FROM '.TABSTATUS.' WHERE name="'.addslashes($name).'"');
$row=$oDB->Getrow();
if ( $row['countid']>0 ) $qti_error = "Status name [$name] already used";
// save new status in this section and register lang
if ( empty($qti_error) )
{
$oDB->Query('INSERT INTO '.TABSTATUS.' (id,name,color,mailto,icon) VALUES ("'.$id.'","'.addslashes($name).'","'.$color.'","'.$mailto.'","'.$icon.'")');
}
// unregister
if ( isset($_SESSION['qtiTstatus']) ) unset($_SESSION['qtiTstatus']);
return $qti_error;
}
// --------
function Delete($id='',$to='A')
{
// Check
if ( !is_string($id) || empty($id) ) die('cStatus->Delete: Argument #1 must be a string');
if ( !is_string($to) || empty($to) ) die('cStatus->Delete: Argument #2 must be a string');
$id = strtoupper(substr(trim($id),0,1));
$to = strtoupper(substr(trim($to),0,1));
if ( $id=='A' || $id=='A' ) die('cStatus->Delete: Argument #1 cannot be A nor Z');
if ( $id==$to ) die('cStatus->Delete: Argument #1 equal #2');
// Process - status id > to and delete id
global $oDB;
$oDB->Query('UPDATE '.TABTOPIC.' SET status="'.$to.'" WHERE status="'.$id.'"');
$oDB->Query('DELETE FROM '.TABSTATUS.' WHERE id="'.$id.'"');
$oDB->Query('DELETE FROM '.TABLANG.' WHERE (objtype="status" OR objtype="statusdesc") AND objid="'.$id.'"');
if ( isset($_SESSION['qtiTstatus']) ) unset($_SESSION['qtiTstatus']);
}
// --------
function GetStatus($id='*')
{
// Check
if ( !is_string($id) || empty($id) ) die('cStatus->GetStatus: Argument #1 must be a string');
// This method creates an array of several statuses
// Each entry is an array of all the db-properties + the translations (statusname/statusdesc)
// statusname must be the first propertie (for usage in QTastags)
// Process
global $oDB;
$arr = array();
$oDB->Query('SELECT * FROM '.TABSTATUS.($id=='*' ? '' : ' WHERE id="'.$id.'"').' ORDER BY id');
while($row=$oDB->Getrow())
{
$arr[$row['id']]['statusname'] = ucfirst(str_replace('_',' ',$row['name']));
$arr[$row['id']]['statusdesc'] = '';
$arr[$row['id']]['name'] = $row['name'];
$arr[$row['id']]['icon'] = $row['icon'];
$arr[$row['id']]['mailto'] = $row['mailto'];
$arr[$row['id']]['color'] = $row['color'];
}
// find translations
$arrL = cLang::GetName('status',$_SESSION[QT]['lang_iso'],'*');
foreach ($arrL as $id=>$str)
{
if ( !empty($str) ) $arr[$id]['statusname'] = $str;
}
$arrL = cLang::GetName('statusdesc',$_SESSION[QT]['lang_iso'],'*');
foreach ($arrL as $id=>$str)
{
if ( !empty($str) ) $arr[$id]['statusdesc'] = $str;
}
return $arr;
}
// --------
function Rename($id='',$to='')
{
// Check
if ( !is_string($id) || empty($id) ) die('cStatus->Rename: Argument #1 must be a string');
if ( !is_string($to) || empty($to) ) die('cStatus->Rename: Argument #2 must be a string');
$id = strtoupper(substr(trim($id),0,1));
$to = strtoupper(substr(trim($id),0,1));
if ( $id=='A' || $id=='A' ) die('cStatus->Delete: Argument #1 cannot be A nor Z');
if ( $to=='A' || $to=='A' ) die('cStatus->Delete: Argument #2 cannot be A nor Z');
// Process
global $oDB;
$qti_error = '';
// Unique name
if ( empty($qti_error) )
{
$oDB->Query('SELECT count(*) AS countid FROM '.TABSTATUS.' WHERE status="'.$to.'"');
$row=$oDB->Getrow();
if ( $row['countid']>0 ) $qti_error = "Status id [$id] already used";
}
// save changes
if ( empty($qti_error) )
{
$oDB->Query('UPDATE '.TABTOPIC.' SET status="'.$to.'" WHERE status="'.$id.'"');
$oDB->Query('UPDATE '.TABSTATUS.' SET id="'.$to.'" WHERE id="'.$id.'"');
}
// exit
return $qti_error;
}
// --------
}
?>