<?php
//#################################################################################################
// Bug class
//#################################################################################################
// chillyCMS - Content Management System
// Copyright (C) 2008
// Stefanie Wiegand <hide@address.com> & Johannes Cox <hide@address.com>
//
// This program is licensed under the GPL 3.0 license. For more information see LICENSE.txt.
//#################################################################################################
defined('DOIT') or die('Restricted access');
class Bug {
//Class variables//////////////////////////////////////////////////////////////////////////
private $id;
private $mainmodid;
private $name;
private $insertdate;
private $state;
private $type;
private $description;
private $comment;
private $dialogue;
private $reporter;
private $reporter_name;
private $responsible;
private $severity;
//Functions////////////////////////////////////////////////////////////////////////////////
//Constructor for creating/uploading a module
function __construct() {
global $page,$mysession;
$this->id = 0;
$this->mainmodid = $page->id;
$this->name = '';
$this->insertdate = false;
$this->state = 0;
$this->type = 0;
$this->description = '';
$this->comment = '';
$this->dialogue = array();
$this->reporter = $mysession->user->uid;
$this->reporter_name = $mysession->user->uname;
$this->responsible = 0;
$this->severity = 0;
}
//Destructor
function __destruct() {
$this->id=$this->mainmodid=$this->name=$this->insertdate=$this->state=$this->type=
$this->description=$this->comment=$this->dialogue=$this->reporter=
$this->reporter_name=$this->responsible=$this->severity=false;
}
//Getter
public function __get($name) {
if (isset($this->$name)) { return $this->$name; }
else { return false; }
}
//Setter
public function __set($name,$value) {
if (isset($name, $this->$name)) { $this->$name=$value; }
else { return false; }
}
//Store to database
function store($savetype='insert') {
global $page,$mysession;
//check values!
$this->name=escape_html($this->name);
$this->description=escape_html($this->description);
$this->comment=escape_html($this->comment);
if ($savetype == 'update') {
$sql = 'update mod_bugtrap set `name`=\''.$this->name.'\',`state`='.$this->state.',`type`='.
$this->type.',`description`=\''.$this->description.'\',`comment`=\''.$this->comment.
'\',`responsible`='.$this->responsible.',`severity`=\''.$this->severity.'\' where id='.$this->id;
//save dialogue
$laststatement = array_pop($this->dialogue);
//check values!
if (isset($laststatement['uname'])) {
$laststatement['uname']=escape_html($laststatement['uname']);
}
if (isset($laststatement['statement'])) {
$laststatement['statement']=escape_html($laststatement['statement']);
}
if (is_array($laststatement) && !empty($laststatement)) {
$sql2 = 'insert into mod_bugtrap_dialogue (`bugid`,`uname`,`date`,`statement`) values ('.
$this->id.",'".$laststatement['uname']."','".$laststatement['date']."','".
$laststatement['statement']."')";
if (!$page->query($sql2)) { return false; }
}
} else {
$reporter = intval($mysession->user->uid);
if ($reporter==0) { $reporter = 'null'; }
$sql = 'insert into mod_bugtrap (`mainmodid`,`name`,`insertdate`,`state`,`type`,'.
'`description`,`comment`,`reporter`,`responsible`,`severity`) values ('.
$page->id.',\''.$this->name.'\',now(),1,'.$this->type.',\''.$this->description.
'\',\''.$this->comment.'\','.$reporter.','.$this->responsible.','.$this->severity.')';
}
if ($page->query($sql)) { return true; } else { return false; }
}
//fill in data
function fill($mainmodid,$name,$state,$type,$description,$comment,$dialogue,$responsible,$severity) {
$this->mainmodid = $mainmodid;
$this->name = $name;
$this->state = $state;
$this->type = $type;
$this->description = $description;
$this->comment = $comment;
$this->dialogue = array($dialogue);
$this->responsible = $responsible;
$this->severity = $severity;
if ($this->responsible==0) { $this->responsible = 'null'; }
}
//Load data from database
function load($id) {
global $page;
if (file_exists(PATH.'/modules/bugtrap/languages/'.$page->language.'.php')) {
include(PATH.'/modules/bugtrap/languages/'.$page->language.'.php');
} else {
include(PATH.'/modules/bugtrap/languages/en.php');
}
$sql = 'select b.*,u.`name` as uname from mod_bugtrap as b '.
'left join system_users as u on b.`reporter`=u.`uid` '.
'where b.`id`='.$id.' limit 1';
$page->query($sql);
$result = $page->db->getdata();
//get whole dialogue
$sql = 'select * from mod_bugtrap_dialogue where `bugid`='.$id.' order by `date` desc';
$page->query($sql);
$dialogue = $page->db->getdata_array();
if (empty($dialogue)) { $dialogue = array(array()); }
if (is_array($result) && !empty($result)) {
$this->id = $id;
$this->mainmodid = $result["mainmodid"];
$this->name = $result["name"];
$this->insertdate = $result["insertdate"];
$this->state = $result["state"];
$this->type = $result["type"];
$this->description = $result["description"];
$this->comment = $result["comment"];
$this->dialogue = $dialogue;
$this->reporter = $result["reporter"];
$this->reporter_name = $result["uname"];
$this->responsible = $result["responsible"];
$this->severity = $result["severity"];
if (!isset($mod_bugtrap_states[$this->state])) { $this->state = 1; }
if (!isset($mod_bugtrap_types[$this->type])) { $this->type = 0; }
if (!isset($mod_bugtrap_severities[$this->severity])) { $this->severity = 1; }
} else {
$this->__destruct();
}
}
} ?>