mirror of
https://github.com/FH-Complete/FHC-Core.git
synced 2026-06-01 20:29:29 +00:00
135 lines
4.0 KiB
PHP
135 lines
4.0 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 stunde
|
|
{
|
|
var $conn; // resource DB-Handle
|
|
var $errormsg; // string
|
|
var $new; // boolean
|
|
var $stunden = array(); // stunde Objekt
|
|
|
|
//Tabellenspalten
|
|
var $stunde; // smalint
|
|
var $beginn; // time without timezone
|
|
var $ende; // time without timezone
|
|
|
|
// *************************************************************************
|
|
// * Konstruktor - Uebergibt die Connection und laedt optional eine Stunde
|
|
// * @param $conn Datenbank-Connection
|
|
// * $stunde Stunde die geladen werden soll
|
|
// * $unicode Gibt an ob die Daten mit UNICODE Codierung
|
|
// * oder LATIN9 Codierung verarbeitet werden sollen
|
|
// *************************************************************************
|
|
function stunde($conn, $stunde=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($stunde!=null)
|
|
$this->load($stunde);
|
|
}
|
|
|
|
// *********************************************************
|
|
// * Laedt eine Stunde
|
|
// * @param $stunde
|
|
// *********************************************************
|
|
function load($stunde)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
// *******************************************
|
|
// * Prueft die Variablen vor dem Speichern
|
|
// * auf Gueltigkeit.
|
|
// * @return true wenn ok, false im Fehlerfall
|
|
// *******************************************
|
|
function validate()
|
|
{
|
|
if(!is_numeric($this->stunde))
|
|
{
|
|
$this->errormsg = 'Stunde muss eine gueltige Zahl 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 eine Stunde in die Datenbank
|
|
// * Wenn $new auf true gesetzt ist wird ein neuer Datensatz
|
|
// * angelegt, ansonsten der Datensatz mit $lehrfach_nr upgedated
|
|
// * @return true wenn erfolgreich, false im Fehlerfall
|
|
// ************************************************************
|
|
function save()
|
|
{
|
|
//Variablen auf Gueltigkeit pruefen
|
|
if(!$this->validate())
|
|
return false;
|
|
|
|
if($this->new)
|
|
{
|
|
$qry = "INSERT INTO lehre.tbl_stunde (stunde, beginn, ende)
|
|
VALUES('".$this->stunde."',".
|
|
$this->addslashes($this->beginn).','.
|
|
$this->addslashes($this->ende).');';
|
|
}
|
|
else
|
|
{
|
|
$qry = 'UPDATE lehre.tbl_stunde SET'.
|
|
' beginn='.$this->addslashes($this->beginn).','.
|
|
' ende='.$this->addslashes($this->ende).
|
|
" WHERE stunde=".$this->stunde;
|
|
}
|
|
|
|
if(pg_query($this->conn,$qry))
|
|
{
|
|
//Log schreiben
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
$this->errormsg = 'Fehler beim Speichern der Stunde:'.$qry;
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
?>
|