execute("SELECT * FROM ticket_log INNER JOIN ticket_user ON ticket_log.Author = ticket_user.TUserId and ticket_log.Ticket=:id ORDER BY ticket_log.TLogId DESC", array('id' => $ticket_id)); $row = $statement->fetchAll(); $result = Array(); foreach($row as $log){ $instanceAuthor = Ticket_User::constr_TUserId($log['Author']); $instanceAuthor->setExternId($log['ExternId']); $instanceAuthor->setPermission($log['Permission']); $instanceLog = new self(); $instanceLog->setTLogId($log['TLogId']); $instanceLog->setTimestamp($log['Timestamp']); $instanceLog->setAuthor($instanceAuthor); $instanceLog->setTicket($ticket_id); $instanceLog->setQuery($log['Query']); $result[] = $instanceLog; } return $result; } //Creates a log entry public static function createLogEntry( $ticket_id, $author_id, $action, $arg = -1) { global $TICKET_LOGGING; if($TICKET_LOGGING){ $dbl = new DBLayer("lib"); $query = "INSERT INTO ticket_log (Timestamp, Query, Ticket, Author) VALUES (now(), :query, :ticket, :author )"; $values = Array('ticket' => $ticket_id, 'author' => $author_id, 'query' => json_encode(array($action,$arg))); $dbl->execute($query, $values); } } //return constructed element based on TLogId public static function constr_TLogId( $id) { $instance = new self(); $instance->setTLogId($id); return $instance; } //returns list of all logs of a ticket public static function getAllLogs($ticket_id) { $dbl = new DBLayer("lib"); $statement = $dbl->execute("SELECT * FROM ticket_log INNER JOIN ticket_user ON ticket_log.Author = ticket_user.TUserId and ticket_log.Ticket=:id", array('id' => $ticket_id)); $row = $statement->fetchAll(); $result = Array(); foreach($row as $log){ $instance = new self(); $instance->set($log); $result[] = $instance; } return $result; } ////////////////////////////////////////////Methods//////////////////////////////////////////////////// public function __construct() { } //set values public function set($values) { $this->setTLogId($values['TLogId']); $this->setTimestamp($values['Timestamp']); $this->setQuery($values['Query']); $this->setTicket($values['Ticket']); $this->setAuthor($values['Author']); } //Load with tlogId public function load_With_TLogId( $id) { $dbl = new DBLayer("lib"); $statement = $dbl->execute("SELECT * FROM ticket_log WHERE TLogId=:id", array('id' => $id)); $row = $statement->fetch(); $this->set($row); } //update private data to DB. public function update(){ $dbl = new DBLayer("lib"); $query = "UPDATE ticket_log SET Timestamp = :timestamp, Query = :query, Author = :author, Ticket = :ticket WHERE TLogId=:id"; $values = Array('id' => $this->getTLogId(), 'timestamp' => $this->getTimestamp(), 'query' => $this->getQuery(), 'author' => $this->getAuthor(), 'ticket' => $this->getTicket() ); $statement = $dbl->execute($query, $values); } ////////////////////////////////////////////Getters//////////////////////////////////////////////////// public function getTLogId(){ return $this->tLogId; } public function getTimestamp(){ return $this->timestamp; } public function getQuery(){ return $this->query; } public function getAuthor(){ return $this->author; } public function getTicket(){ return $this->ticket; } public function getAction(){ $decodedQuery = json_decode($this->query); return $decodedQuery[0]; } public function getArgument(){ $decodedQuery = json_decode($this->query); return $decodedQuery[1]; } public function getActionTextArray(){ global $DEFAULT_LANGUAGE; global $AMS_TRANS; //if language get param is given = set cookie //else if no get param is given and a cookie is set, use that language, else use default. if ( isset( $_GET['language'] ) ) { //check if the language is supported if ( file_exists( $AMS_TRANS . '/' . $_GET['language'] . '.ini' ) ){ //if it's supported, set cookie! setcookie( 'language',$_GET['language'], time() + 60*60*24*30 ); $language = $_GET['language']; }else{ //the language is not supported, use the default. $language = $DEFAULT_LANGUAGE; } }else{ //if no get param is given, check if a cookie value for language is set if ( isset( $_COOKIE['language'] ) ) { $language = $_COOKIE['language']; } //else use the default else{ $language = $DEFAULT_LANGUAGE; } } $variables = parse_ini_file( $AMS_TRANS . '/' . $language . '.ini', true ); $result = array(); foreach ( $variables['ticket_log'] as $key => $value ){ $result[$key] = $value; } return $result; } ////////////////////////////////////////////Setters//////////////////////////////////////////////////// public function setTLogId($id){ $this->tLogId = $id; } public function setTimestamp($t){ $this->timestamp = $t; } public function setQuery($q){ $this->query = $q; } public function setAuthor($a){ $this->author = $a; } public function setTicket($t){ $this->ticket = $t; } }