Files
FHC-Core/include/fas/feedback.class.php
T
2006-11-30 16:24:41 +00:00

148 lines
4.5 KiB
PHP

<?php
/* Copyright (C) 2006 Technikum-Wien
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
*
* Authors: Christian Paminger <christian.paminger@technikum-wien.at>,
* Andreas Oesterreicher <andreas.oesterreicher@technikum-wien.at> and
* Rudolf Hangl <rudolf.hangl@technikum-wien.at>.
*/
class feedback
{
var $conn; // resource DB-Handle
var $errormsg; // string
var $new; // boolean
var $feedback = array(); // feedback Objekt
//Tabellenspalten
var $feedback_id; // integer
var $betreff; // varchar(128)
var $text; // text
var $datum; // date
var $uid; // varchar(16)
// *************************************************************************
// * Konstruktor - Uebergibt die Connection und laedt optional eine Lehrform
// * @param $conn Datenbank-Connection
// * $feedback_id
// * $unicode Gibt an ob die Daten mit UNICODE Codierung
// * oder LATIN9 Codierung verarbeitet werden sollen
// *************************************************************************
function feedback($conn, $feedback_id=null, $unicode=false)
{
$this->conn = $conn;
if($unicode)
$qry = "SET CLIENT_ENCODING TO 'UNICODE';";
else
$qry = "SET CLIENT_ENCODING TO 'LATIN9';";
if(!pg_query($conn,$qry))
{
$this->errormsg = 'Encoding konnte nicht gesetzt werden';
return false;
}
if($feedback_id!=null)
$this->load($feedback_id);
}
// *********************************************************
// * Laedt ein Feedback
// * @param
// *********************************************************
function load($feedback_id)
{
return true;
}
// *******************************************
// * Prueft die Variablen vor dem Speichern
// * auf Gueltigkeit.
// * @return true wenn ok, false im Fehlerfall
// *******************************************
function validate()
{
if(strlen($this->betreff)>128)
{
$this->errormsg = 'Betreff darf nicht laenger als 128 Zeichen sein';
return false;
}
if(strlen($this->uid)>16)
{
$this->errormsg = 'UID darf nicht laenger als 16 Zeichen sein';
return false;
}
return true;
}
// ************************************************
// * wenn $var '' ist wird NULL zurueckgegeben
// * wenn $var !='' ist werden Datenbankkritische
// * Zeichen mit Backslash versehen und das Ergbnis
// * unter Hochkomma gesetzt.
// ************************************************
function addslashes($var)
{
return ($var!=''?"'".addslashes($var)."'":'null');
}
// ************************************************************
// * Speichert Feedback in die Datenbank
// * Wenn $new auf true gesetzt ist wird ein neuer Datensatz
// * angelegt, ansonsten der Datensatz upgedated
// * @return true wenn erfolgreich, false im Fehlerfall
// ************************************************************
function save()
{
//Variablen auf Gueltigkeit pruefen
if(!$this->validate())
return false;
if($this->new)
{
//ToDo: Feedback_ID wieder entfernen und per Seq fuellen
$qry = 'INSERT INTO tbl_feedback (feedback_id, betreff, text, datum, uid)
VALUES('.$this->addslashes($this->feedback_id).','.
$this->addslashes($this->betreff).','.
$this->addslashes($this->text).','.
$this->addslashes($this->datum).','.
$this->addslashes($this->uid).');';
}
else
{
$qry = 'UPDATE tbl_feedback SET'.
' betreff='.$this->addslashes($this->betreff).','.
' text='.$this->addslashes($this->text).','.
' datum='.$this->addslashes($this->datum).','.
' uid='.$this->addslashes($this->uid).
" WHERE feedback_id='".addslashes($this->feedback_id)."'";
}
if(pg_query($this->conn,$qry))
{
//Log schreiben
return true;
}
else
{
$this->errormsg = 'Fehler beim Speichern des Feedbacks:'.$qry;
return false;
}
}
}
?>