WaWi Kontoverwaltung Grundgerüst

This commit is contained in:
Andreas Österreicher
2010-10-11 13:45:20 +00:00
parent d53b294eb3
commit da66c02f8e
3 changed files with 538 additions and 0 deletions
+282
View File
@@ -0,0 +1,282 @@
<?php
/* Copyright (C) 2010 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
* Karl Burkhart <burkhart@technikum-wien.at>.
*/
/**
* Klasse WaWi Konto
*/
require_once(dirname(__FILE__).'/basis_db.class.php');
class wawi_konto extends basis_db
{
public $new; // boolean
public $result = array(); // adresse Objekt
//Tabellenspalten
public $adresse_id; // integer
public $person_id; // integer
public $name; // string
public $strasse; // string
public $plz; // string
public $ort; // string
public $gemeinde; // string
public $nation; // string
public $typ; // string
public $heimatadresse; // boolean
public $zustelladresse; // boolean
public $firma_id; // integer
public $updateamum; // timestamp
public $updatevon; // string
public $insertamum; // timestamp
public $insertvon; // string
public $ext_id; // integer
/**
* Konstruktor
* @param $konto_id ID des Kontos das geladen werden soll (Default=null)
*/
public function __construct($konto_id=null)
{
parent::__construct();
if(!is_null($konto_id))
$this->load($konto_id);
}
/**
* Laedt das Konto mit der ID $konto_id
* @param $konto_id ID des zu ladenden Kontos
* @return true wenn ok, false im Fehlerfall
*/
public function load($konto_id)
{
//Pruefen ob konto_id eine gueltige Zahl ist
if(!is_numeric($konto_id) || $konto_id == '')
{
$this->errormsg = 'Konto_id muss eine Zahl sein';
return false;
}
//Daten aus der Datenbank lesen
$qry = "SELECT * FROM wawi.tbl_konto WHERE konto_id='".addslashes($konto_id)."'";
if(!$this->db_query($qry))
{
$this->errormsg = 'Fehler bei einer Datenbankabfrage';
return false;
}
if($row = $this->db_fetch_object())
{
$this->konto_id = $row->konto_id;
$this->aktiv = ($row->aktiv=='t'?true:false);
//...
}
else
{
$this->errormsg = 'Es ist kein Datensatz mit dieser ID vorhanden';
return false;
}
return true;
}
/**
* Laedt alle Konten
* @param $aktiv wenn true werden nur die aktiven Datensaetze geladen, sonst alle
* @param $order Sortierreihenfolge
* @return true wenn ok, false im Fehlerfall
*/
public function getAll($aktiv=null, $order='beschreibung DESC')
{
//Daten aus der Datenbank lesen
$qry = 'SELECT * FROM wawi.tbl_konto';
if(!is_null($aktiv))
{
$qry.='WHERE aktiv='.($aktiv?'true':'false');
}
if($order!='')
$qry .= ' ORDER BY '.$order;
if(!$this->db_query($qry))
{
$this->errormsg = 'Fehler bei einer Datenbankabfrage';
return false;
}
while($row = $this->db_fetch_object())
{
$obj = new wawi_konto();
$obj->konto_id = $row->konto_id;
//...
$this->result[] = $obj;
}
return true;
}
/**
* Prueft die Variablen auf Gueltigkeit
* @return true wenn ok, false im Fehlerfall
*/
protected function validate()
{
if(mb_strlen($this->bezeichnung)>265)
{
$this->errormsg = 'Bezeichnung darf nicht laenger als 256 Zeichen sein.';
return false;
}
$this->errormsg = '';
return true;
}
/**
* Speichert den aktuellen Datensatz in die Datenbank
* Wenn $neu auf true gesetzt ist wird ein neuer Datensatz angelegt
* andernfalls wird der Datensatz mit der ID in $adresse_id aktualisiert
* @param $new wenn true wird ein Insert durchgefuehrt, wenn false ein Update
* und wenn null wird das new-Objekt der Klasse verwendet
* @return true wenn ok, false im Fehlerfall
*/
public function save($new=null)
{
if(is_null($new))
$new = $this->new;
//Variablen pruefen
if(!$this->validate())
return false;
if($this->new)
{
//Neuen Datensatz einfuegen
$qry='BEGIN;INSERT INTO public.tbl_adresse (person_id, name, strasse, plz, typ, ort, nation, insertamum, insertvon,
gemeinde, heimatadresse, zustelladresse, firma_id, updateamum, updatevon, ext_id) VALUES('.
$this->addslashes($this->person_id).', '.
$this->addslashes($this->name).', '.
$this->addslashes($this->strasse).', '.
$this->addslashes($this->plz).', '.
$this->addslashes(trim($this->typ)).', '.
$this->addslashes($this->ort).', '.
$this->addslashes($this->nation).', now(), '.
$this->addslashes($this->insertvon).', '.
$this->addslashes($this->gemeinde).', '.
($this->heimatadresse?'true':'false').', '.
($this->zustelladresse?'true':'false').', '.
($this->firma_id!=null?$this->addslashes($this->firma_id):'null').', now(), '.
$this->addslashes($this->updatevon).', '.
$this->addslashes($this->ext_id).');';
}
else
{
//Pruefen ob adresse_id eine gueltige Zahl ist
if(!is_numeric($this->adresse_id))
{
$this->errormsg = 'adresse_id muss eine gültige Zahl sein: '.$this->adresse_id."\n";
return false;
}
$qry='UPDATE public.tbl_adresse SET'.
' person_id='.$this->addslashes($this->person_id).', '.
' name='.$this->addslashes($this->name).', '.
' strasse='.$this->addslashes($this->strasse).', '.
' plz='.$this->addslashes($this->plz).', '.
' typ='.$this->addslashes(trim($this->typ)).', '.
' ort='.$this->addslashes($this->ort).', '.
' nation='.$this->addslashes($this->nation).', '.
' gemeinde='.$this->addslashes($this->gemeinde).', '.
' firma_id='.$this->addslashes($this->firma_id).','.
' updateamum= now(), '.
' updatevon='.$this->addslashes($this->updatevon).', '.
' heimatadresse='.($this->heimatadresse?'true':'false').', '.
' zustelladresse='.($this->zustelladresse?'true':'false').' '.
'WHERE adresse_id='.$this->adresse_id.';';
}
if($this->db_query($qry))
{
if($this->new)
{
//naechste ID aus der Sequence holen
$qry="SELECT currval('public.tbl_adresse_adresse_id_seq') as id;";
if($this->db_query($qry))
{
if($row = $this->db_fetch_object())
{
$this->adresse_id = $row->id;
$this->db_query('COMMIT');
}
else
{
$this->db_query('ROLLBACK');
$this->errormsg = "Fehler beim Auslesen der Sequence";
return false;
}
}
else
{
$this->db_query('ROLLBACK');
$this->errormsg = 'Fehler beim Auslesen der Sequence';
return false;
}
}
}
else
{
$this->errormsg = 'Fehler beim Speichern des Adress-Datensatzes';
return false;
}
return $this->adresse_id;
}
/**
* Loescht den Datenensatz mit der ID die uebergeben wird
* @param $adresse_id ID die geloescht werden soll
* @return true wenn ok, false im Fehlerfall
*/
public function delete($adresse_id)
{
//Pruefen ob adresse_id eine gueltige Zahl ist
if(!is_numeric($adresse_id) || $adresse_id == '')
{
$this->errormsg = 'adresse_id muss eine gültige Zahl sein'."\n";
return false;
}
//loeschen des Datensatzes
$qry="DELETE FROM public.tbl_adresse WHERE adresse_id='".addslashes($adresse_id)."';";
if($this->db_query($qry))
{
return true;
}
else
{
$this->errormsg = 'Fehler beim Löschen der Daten'."\n";
return false;
}
}
}
?>
+201
View File
@@ -0,0 +1,201 @@
A:link {text-decoration: none;
color: blue;
}
A:visited {text-decoration: none;
color: blue;
}
A:active {text-decoration: underline;
color: blue;
}
A.neutral:link {text-decoration: underline;
color: black;
}
A.neutral:visited {text-decoration: underline;
color: black;
}
A.neutral:active {text-decoration: underline;
color: black;
}
B {
font-family: Verdana,Lucida,Helvetica,Arial;
}
BODY,H1,H2,H3,H4,H5,H6,P,I,TD,TH {
font-family: Verdana,Lucida,Helvetica,Arial;
color:black;
}
BODY,TD,TH,P,I {
font-size: 9pt;
}
td.blue { font-family: Verdana,Lucida,Helvetica,Arial;
font-size: 1pt;
background:blue
}
td.darkgray {
font-family: Verdana,Lucida,Helvetica,Arial;
font-size: 1pt;
background:darkgray;
}
td.grays{white-space:nowrap;
font-family: Verdana,Lucida,Helvetica,Arial;
font-size: 8pt;
font-weight: normal;
background:#EEEEEE;
}
td.white{ width:170pt;
text-align:right;
white-space:nowrap;
font-family: Verdana,Lucida,Helvetica,Arial;
font-size: 10pt;
font-weight: normal;
background:#FFFFFF;
}
td.yellow {
font-family: Verdana,Lucida,Helvetica,Arial;
font-size: 10pt;
background:#E1DD00;
}
th.yellow {
white-space:nowrap;
font-family: Verdana,Lucida,Helvetica,Arial;
font-size: 9pt;
font-weight: 900;
background:#E1DD00;
background:#DCE4EF;
}
th.yellows {
white-space:nowrap;
font-family: Verdana,Lucida,Helvetica,Arial;
font-size: 8pt;
font-weight: 600;
background:#E1DD00;
background:#DCE4EF;
}
H1 {
font-size: 14pt;
font-weight: 900;
}
H3,H2 {
font-size: 12pt;
font-weight: 900;
}
div.firma {
border-style:none;
border-width:thin;
font-family: Verdana,Lucida,Helvetica,Arial;
font-size: 10pt;
font-weight: 900;
background-color:yellow;
width:627;
vertical-align:middle;
}
div.DCE4EF {
border-style:none;
border-width:thin;
font-family: Verdana,Lucida,Helvetica,Arial;
font-size: 10pt;
font-weight: 900;
background:#DCE4EF;
width:627;
vertical-align:middle;
}
.liste {
font-family: Arial,Lucida,Verdana,Helvetica;
FONT-SIZE: 9pt;
color:black;
}
.mod {
color: #000;
}
.del {
color: #ee2222;
}
.new {
color: #22bb22;
}
INPUT, SELECT {
font-family: Courier New,Arial,TimesNewRoman;
font-size: 9pt;
border: 1px solid #ccc;
}
.number {
text-align: right;
}
.button_gr {
font-family: Arial,Helvetica;
font-size: 9pt;
background: #aaffaa;
}
.button {
font-family: Arial,Helvetica;
font-size: 9pt;
}
TD.black {
font-family: Lucida,Verdana,Helvetica,Arial;
font-size: 9pt;
color:black;
}
TD.content {
font-family: Lucida,Verdana,Helvetica,Arial;
FONT-SIZE: 9pt;
color:lightgreen;
}
TD.small {
text-align:left;
font-family: Lucida,Verdana,Helvetica,Arial;
font-size: 8pt;
font-weight: normal;
color:white;
background:blue
}
BODY { background-color:#F5F5F5;
margin-left:5pt;
}
BODY.v1 {
background-color:#F5F5F5;
padding:0pt;
margin:0pt;
margin-height=0pt;
margin-width=0pt;
}
ul {list-style-type:none}
ul.disc {list-style-type:disc}
.frmField {background: #dedede;}
+55
View File
@@ -0,0 +1,55 @@
<?php
require_once('../include/wawi_konto.class.php');
$konto = new wawi_konto();
if($konto->getAll())
{
foreach($konto->result as $row)
{
//Zeilen der Tabelle ausgeben
$row->kontonummer;
if($row->akiv)
}
}
if($isset($_GET['edit']) || isset($_GET['new']))
{
//Formular ausgeben
}
if($isset($_GET['delete']))
{
//Eintrag loeschen
$konto->delete($id);
}
if(isset($_GET['save']))
{
//Daten in der DB speichern
$konto = new wawi_konto();
$aktiv = isset($_POST['aktiv']);
if(isset($_POST['konto_id']))
{
//Update eines bestehenden Datensatzes
if(!$konto->load($id))
die('ID nicht gefunden');
$konto->new = false;
}
else
{
//Neuer Datensatz
$konto->new = true;
}
$konto->beschreibung = $beschreibung;
//...
if(!$konto->save())
{
die('Fehler beim Speichern:'.$konto->errormsg);
}
}
?>