From c0f1980b6e7e49795761028b28bd89f59d7899fc Mon Sep 17 00:00:00 2001 From: Gerald Simane Date: Tue, 9 Mar 2010 13:22:18 +0000 Subject: [PATCH] --- include/betriebsmittel.class.php | 979 +++++++++++++++++++++++-- include/betriebsmittelperson.class.php | 217 +++++- include/betriebsmitteltyp.class.php | 373 ++++++---- include/firma.class.php | 906 ++++++++++++++--------- include/kontakt.class.php | 739 ++++++++++--------- include/moodle_course.class.php | 1 + include/ort.class.php | 16 +- include/person.class.php | 103 +++ include/tw/cis_menu_main.inc.php | 19 +- include/tw/vilesci_menu_main.inc.php | 2 +- 10 files changed, 2415 insertions(+), 940 deletions(-) diff --git a/include/betriebsmittel.class.php b/include/betriebsmittel.class.php index 8fa04a89c..6dcda7c7a 100644 --- a/include/betriebsmittel.class.php +++ b/include/betriebsmittel.class.php @@ -15,20 +15,32 @@ * 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 , - * Andreas Oesterreicher and - * Rudolf Hangl . + * Authors: Christian Paminger < christian.paminger@technikum-wien.at > + * Andreas Oesterreicher < andreas.oesterreicher@technikum-wien.at > + * Rudolf Hangl < rudolf.hangl@technikum-wien.at > + * Gerald Simane-Sequens < gerald.simane-sequens@technikum-wien.at > */ + /** - * Klasse Betriebsmittel + * Klasse Betriebsmittel * @create 22-01-2007 */ require_once(dirname(__FILE__).'/basis_db.class.php'); -class betriebsmittel extends basis_db +class betriebsmittel extends basis_db { + public $schema_inventar='wawi'; +# private $schema_inventar='public'; + public $schema_wawi='public'; + + public $default_afa_jahre=5; + + + public $debug=false; // boolean public $new; // boolean public $result; + + //Tabellenspalten public $betriebsmittel_id; // integer @@ -42,7 +54,22 @@ class betriebsmittel extends basis_db public $insertvon; // string public $updateamum; // timestamp public $updatevon; // string - + // Neu wegen Inventar seq 2009-12 + public $beschreibung; // string + public $oe_kurzbz; // string + public $hersteller; // string + + public $seriennummer; // string + public $bestellung_id; // integer + public $bestelldetail_id; // integer + + public $afa; // string + + public $verwendung; // string + public $anmerkung; // string + public $leasing_bis; // date + + /** * Konstruktor * @param $betriebsmittel_id ID des Betrtiebsmittels, das geladen werden soll (Default=null) @@ -50,11 +77,11 @@ class betriebsmittel extends basis_db public function __construct($betriebsmittel_id=null) { parent::__construct(); - + if(!is_null($betriebsmittel_id)) $this->load($betriebsmittel_id); } - + /** * Laedt das Betriebsmittel mit der ID $betriebsmittel_id * @param $betriebsmittel_id ID des zu ladenden Betriebsmittel @@ -62,19 +89,23 @@ class betriebsmittel extends basis_db */ public function load($betriebsmittel_id) { + // Initialisieren + $this->result=array(); + $this->errormsg = ''; + if(!is_numeric($betriebsmittel_id)) { $this->errormsg = 'Betriebsmittel_id ist ungueltig'; return false; } - - $qry = "SELECT * FROM public.tbl_betriebsmittel WHERE betriebsmittel_id='".addslashes($betriebsmittel_id)."'"; - + + $qry = "SELECT * FROM ".$this->schema_inventar.".tbl_betriebsmittel WHERE betriebsmittel_id='".addslashes($betriebsmittel_id)."'"; + if($this->db_query($qry)) { if($row = $this->db_fetch_object()) { - + $this->betriebsmittel_id = $row->betriebsmittel_id; $this->beschreibung = $row->beschreibung; $this->betriebsmitteltyp = $row->betriebsmitteltyp; @@ -87,32 +118,44 @@ class betriebsmittel extends basis_db $this->insertvon = $row->insertvon; $this->insertamum = $row->insertamum; $this->ext_id = $row->ext_id; - return $this->result=$row; + // Neu wegen Inventar seq 2009-12 + $this->beschreibung = $row->beschreibung; // string + $this->oe_kurzbz = $row->oe_kurzbz; // string + $this->hersteller = $row->hersteller; // string + $this->seriennummer = $row->seriennummer; // string + $this->bestellung_id = $row->bestellung_id; // integer + $this->bestelldetail_id = $row->bestelldetail_id; // integer + $this->afa = $row->afa; // string + $this->verwendung = $row->verwendung; // string + $this->anmerkung = $row->anmerkung; // string + + $this->leasing_bis = $row->leasing_bis; // string + + return $this->result=$row; } - else + else { - $this->errormsg = 'Betriebsmittel wurde nicht gefunden'; + $this->errormsg = 'Betriebsmittel wurde nicht gefunden '.($this->debug?$this->db_last_error()."
$qry
":''); return false; } } - else + else { - $this->errormsg = 'Fehler beim Laden der Daten'; + $this->errormsg = 'Fehler beim Laden der Daten '.($this->debug?$this->db_last_error()."
$qry
":''); return false; } } - /** - * Prueft die Daten vor dem Speichern + * Prueft die Daten vor dem Speichern * auf Gueltigkeit */ protected function validate() { return true; } - + /** - * Speichert den aktuellen Datensatz in die Datenbank + * 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 $betriebsmittel_id aktualisiert * @return true wenn ok, false im Fehlerfall @@ -121,78 +164,106 @@ class betriebsmittel extends basis_db { if($new==null) $new=$this->new; - + if(!$this->validate()) return false; + if ($this->nummer) + $this->nummer=trim($this->nummer); + + + $this->afa=(!isset($this->afa) || empty($this->afa)?$this->default_afa_jahre:$this->afa); if($new) { - //Neuen Datensatz einfuegen - $qry='INSERT INTO public.tbl_betriebsmittel (beschreibung, betriebsmitteltyp, nummer, nummerintern, reservieren, ort_kurzbz, - ext_id, insertamum, insertvon, updateamum, updatevon) VALUES('. + //Neuen Datensatz einfuegen + $qry='INSERT INTO '.$this->schema_inventar.'.tbl_betriebsmittel (beschreibung, betriebsmitteltyp, nummer + , nummerintern, reservieren, ort_kurzbz + ,ext_id, insertamum, insertvon, updateamum, updatevon,oe_kurzbz,hersteller,seriennummer + ,bestellung_id,bestelldetail_id,afa,verwendung,anmerkung,leasing_bis) VALUES('. $this->addslashes($this->beschreibung).', '. $this->addslashes($this->betriebsmitteltyp).', '. $this->addslashes($this->nummer).', '. $this->addslashes($this->nummerintern).', '. - ($this->reservieren?'true':'false').', '. + ($this->reservieren?'true':'false').', '. $this->addslashes($this->ort_kurzbz).', '. - $this->addslashes($this->ext_id).', now(), '. - $this->addslashes($this->insertvon).', now(), '. - $this->addslashes($this->updatevon).');'; + $this->addslashes($this->ext_id).', '. + ($this->insertamum?$this->addslashes($this->insertamum):'now()').', '. + $this->addslashes($this->insertvon).', '. + ($this->updateamum?$this->addslashes($this->updateamum):'now()').', '. + $this->addslashes((empty($this->updatevon)?$this->updatevon:$this->insertvon)).', '. + $this->addslashes($this->oe_kurzbz).', '. + $this->addslashes($this->hersteller).', '. + $this->addslashes($this->seriennummer).', '. + $this->addslashes($this->bestellung_id).', '. + $this->addslashes($this->bestelldetail_id).', '. + $this->addslashes($this->afa).', '. + $this->addslashes($this->verwendung).', '. + $this->addslashes($this->anmerkung) .', '. + ($this->leasing_bis?$this->addslashes($this->leasing_bis):'null') .');' ; + } else - { + { if(!is_numeric($this->betriebsmittel_id)) { $this->errormsg = 'Betriebsmittel_id muss eine gueltige Zahl sein'; return false; } - - $qry='UPDATE public.tbl_betriebsmittel SET '. - 'betriebsmitteltyp='.$this->addslashes($this->betriebsmitteltyp).', '. - 'beschreibung='.$this->addslashes($this->beschreibung).', '. - 'nummer='.$this->addslashes($this->nummer).', '. - 'nummerintern='.$this->addslashes($this->nummerintern).', '. + + $qry='UPDATE '.$this->schema_inventar.'.tbl_betriebsmittel SET '. + 'betriebsmitteltyp='.$this->addslashes($this->betriebsmitteltyp).', '. + 'beschreibung='.$this->addslashes($this->beschreibung).', '. + 'nummer='.$this->addslashes($this->nummer).', '. + 'nummerintern='.$this->addslashes($this->nummerintern).', '. 'reservieren='.($this->reservieren?'true':'false').', '. 'ort_kurzbz='.$this->addslashes($this->ort_kurzbz).', '. 'ext_id='.$this->addslashes($this->ext_id).', '. - 'updateamum= now(), '. - 'updatevon='.$this->addslashes($this->updatevon).' '. + 'updateamum='.($this->updateamum?$this->addslashes($this->updateamum):'now()').', '. + 'updatevon='.$this->addslashes($this->updatevon).', '. + // Neu wegen Inventar seq 2009-12 + 'oe_kurzbz='.$this->addslashes($this->oe_kurzbz).', '. + 'hersteller='.$this->addslashes($this->hersteller).', '. + 'seriennummer='.$this->addslashes($this->seriennummer).', '. + 'bestellung_id='.$this->addslashes($this->bestellung_id).', '. + 'bestelldetail_id='.$this->addslashes($this->bestelldetail_id).', '. + 'afa='.($this->afa && is_numeric($this->afa)?$this->afa:$this->default_afa_jahre).', '. + 'verwendung='.$this->addslashes($this->verwendung).', '. + 'anmerkung='.$this->addslashes($this->anmerkung).', '. + 'leasing_bis='.($this->leasing_bis?$this->addslashes($this->leasing_bis):'null').' '. 'WHERE betriebsmittel_id='.$this->addslashes($this->betriebsmittel_id).';'; } - +##echo $qry; if($this->db_query($qry)) { if($new) { - $qry = "SELECT currval('public.tbl_betriebsmittel_betriebsmittel_id_seq') as id;"; + $qry = "SELECT currval('".$this->schema_inventar.".tbl_betriebsmittel_betriebsmittel_id_seq') as id;"; if($this->db_query($qry)) { if($row = $this->db_fetch_object()) { $this->betriebsmittel_id = $row->id; } - else + else { - $this->errormsg = 'Fehler beim Lesen der Sequence'; + $this->errormsg = 'Fehler beim Lesen der Sequence '.($this->debug?$this->db_last_error()."
$qry
":''); return false; } } - else + else { - $this->errormsg = 'Fehler beim Lesen der Sequence'; + $this->errormsg = 'Fehler beim Lesen der Sequence '.($this->debug?$this->db_last_error()."
$qry
":''); return false; } } - return true; + return $this->betriebsmittel_id; } - else + else { - $this->errormsg = "Fehler beim Speichern des Betriebsmittel-Datensatzes"; + $this->errormsg = 'Fehler beim Speichern des Betriebsmittel-Datensatzes '.($this->debug?$this->db_last_error()."
$qry
":''); return false; } } - /** * Loescht den Datenensatz mit der ID die uebergeben wird * @param $betriebsmittel_id ID die geloescht werden soll @@ -205,18 +276,16 @@ class betriebsmittel extends basis_db $this->errormsg = 'Betriebsmittel_id ist ungueltig'; return false; } - - $qry = "DELETE FROM public.tbl_betriebsmittel WHERE betriebsmittel_id='".addslashes($betriebsmittel_id)."'"; - + $qry = "DELETE FROM ".$this->schema_inventar.".tbl_betriebsmittel WHERE betriebsmittel_id='".addslashes($betriebsmittel_id)."'"; if($this->db_query($qry)) return true; - else + else { - $this->errormsg = 'Fehler beim Loeschen der Daten'; + $this->errormsg = 'Fehler beim Loeschen der Daten '.($this->debug?$this->db_last_error()."
$qry
":''); return false; } } - + /** * Laedt die Betriebsmittel * @@ -226,16 +295,22 @@ class betriebsmittel extends basis_db */ public function getBetriebsmittel($betriebsmitteltyp, $nummer) { - $qry = "SELECT * FROM public.tbl_betriebsmittel - WHERE betriebsmitteltyp='".addslashes($betriebsmitteltyp)."' AND nummer='".addslashes($nummer)."' - ORDER BY updateamum DESC"; - + // Initialisieren + $this->result=array(); + $this->errormsg = ''; + + $qry = ''; + $qry.= 'SELECT * '; + $qry.= ' FROM '.$this->schema_inventar.'.tbl_betriebsmittel '; + $qry.= " WHERE betriebsmitteltyp='".addslashes($betriebsmitteltyp)."' AND nummer='".addslashes($nummer)."'"; + $qry.= " ORDER BY updateamum DESC"; + if($this->db_query($qry)) { while($row = $this->db_fetch_object()) { $bm = new betriebsmittel(); - + $bm->betriebsmittel_id = $row->betriebsmittel_id; $bm->beschreibung = $row->beschreibung; $bm->betriebsmitteltyp = $row->betriebsmitteltyp; @@ -247,16 +322,794 @@ class betriebsmittel extends basis_db $bm->updatevon = $row->updatevon; $bm->insertamum = $row->insertamum; $bm->insertvon = $row->insertvon; - + // Neu wegen Inventar seq 2009-12 + $bm->beschreibung = $row->beschreibung; // string + $bm->oe_kurzbz = $row->oe_kurzbz; // string + $bm->hersteller = $row->hersteller; // string + $bm->seriennummer = $row->seriennummer; // string + $bm->bestellung_id = $row->bestellung_id; // integer + $bm->bestelldetail_id = $row->bestelldetail_id; // integer + $bm->afa = $row->afa; // string + $bm->verwendung = $row->verwendung; // string + $bm->anmerkung = $row->anmerkung; // string + $bm->leasing_bis = $row->leasing_bis; // date + $this->result[] = $bm; } return true; } - else + else { - $this->errormsg = 'Fehler beim Laden der Daten'; + $this->errormsg = 'Fehler beim Laden der Daten '.($this->debug?$this->db_last_error()."
$qry
":''); return false; } } + + /** + * Laedt ALLE Betriebsmittel + * + * @return boolean + */ + public function getALL() + { + // Initialisieren + $this->result=array(); + $this->errormsg = ''; + + $qry = ''; + $qry.= 'SELECT * '; + $qry.= ' FROM '.$this->schema_inventar.'.tbl_betriebsmittel '; + $qry.= " ORDER BY nummer"; + + if($this->db_query($qry)) + { + while($row = $this->db_fetch_object()) + { + $bm = new betriebsmittel(); + + $bm->betriebsmittel_id = $row->betriebsmittel_id; + $bm->beschreibung = $row->beschreibung; + $bm->betriebsmitteltyp = $row->betriebsmitteltyp; + $bm->nummer = $row->nummer; + $bm->nummerintern = $row->nummerintern; + $bm->reservieren = $row->reservieren; + $bm->ort_kurzbz = $row->ort_kurzbz; + $bm->updateamum = $row->updateamum; + $bm->updatevon = $row->updatevon; + $bm->insertamum = $row->insertamum; + $bm->insertvon = $row->insertvon; + // Neu wegen Inventar seq 2009-12 + $bm->oe_kurzbz = $row->oe_kurzbz; // string + $bm->hersteller = $row->hersteller; // string + $bm->seriennummer = $row->seriennummer; // string + $bm->bestellung_id = $row->bestellung_id; // integer + $bm->bestelldetail_id = $row->bestelldetail_id; // integer + $bm->afa = $row->afa; // string + $bm->verwendung = $row->verwendung; // string + $bm->anmerkung = $row->anmerkung; // string + $bm->leasing_bis = $row->leasing_bis; // date + $this->result[] = $bm; + } + return true; + } + else + { + $this->errormsg = 'Fehler beim Laden der Daten '.($this->debug?$this->db_last_error()."
$qry
":'');; + return false; + } + } + + + +// ------------------------------------------------------------------------------------------ +// Inventardaten lesen +// ------------------------------------------------------------------------------------------ + /** + * Laedt das Betriebsmittel mit der Nummer des Betriebsmittels $nummer + * @param $nummer Nummer des zu ladenden Betriebsmittel + * @return true wenn ok, false im Fehlerfall + */ + public function load_nummer($nummer) + { + // Initialisieren + $this->result=array(); + $this->errormsg = ''; + + $qry=''; + $qry.=' select * '; + $qry.=' from '.$this->schema_inventar.'.tbl_betriebsmittel '; + $qry.=' where nummer='.$this->addslashes($nummer); + + if($this->db_query($qry)) + { + if($row = $this->db_fetch_object()) + { + $this->betriebsmittel_id = $row->betriebsmittel_id; + $this->beschreibung = $row->beschreibung; + $this->betriebsmitteltyp = $row->betriebsmitteltyp; + $this->nummer = $row->nummer; + $this->nummerintern = $row->nummerintern; + $this->reservieren = ($row->reservieren=='t'?true:false); + $this->ort_kurzbz = $row->ort_kurzbz; + $this->updateamum = $row->updateamum; + $this->updatevon = $row->updatevon; + $this->insertvon = $row->insertvon; + $this->insertamum = $row->insertamum; + $this->ext_id = $row->ext_id; + // Neu wegen Inventar seq 2009-12 + $this->beschreibung = $row->beschreibung; // string + $this->oe_kurzbz = $row->oe_kurzbz; // string + $this->hersteller = $row->hersteller; // string + $this->seriennummer = $row->seriennummer; // string + $this->bestellung_id = $row->bestellung_id; // integer + $this->bestelldetail_id = $row->bestelldetail_id; // integer + $this->afa = $row->afa; // string + $this->verwendung = $row->verwendung; // string + $this->anmerkung = $row->anmerkung; // string + $this->leasing_bis = $row->leasing_bis; // date + return $this->result=$row; + } + else + { + return false; + } + } + else + { + $this->errormsg = 'Fehler beim Laden der Daten '.($this->debug?$this->db_last_error()."
$qry
":''); + return false; + } + } + /** + * Laedt die Organisation des Betriebsmittels $bestellung_id + * @param $bestellung_id Bestellnummer des zu ladenden Betriebsmittel + * @return true wenn ok, false im Fehlerfall + */ + public function load_betriebsmittel_oe($betriebsmittel_id) + { + // Initialisieren + $this->result=array(); + $this->errormsg = ''; + + if(!is_numeric($betriebsmittel_id)) + { + $this->errormsg = 'Betriebsmittel_id ist ungueltig'; + return false; + } + + $qry = "SELECT * FROM ".$this->schema_inventar.".tbl_betriebsmittel WHERE betriebsmittel_id='".addslashes($betriebsmittel_id)."'"; + if($res=$this->db_query($qry)) + { + if($row = $this->db_fetch_object($res)) + { + $this->betriebsmittel_id = $row->betriebsmittel_id; + $this->beschreibung = $row->beschreibung; + $this->betriebsmitteltyp = $row->betriebsmitteltyp; + $this->nummer = $row->nummer; + $this->nummerintern = $row->nummerintern; + $this->reservieren = ($row->reservieren=='t'?true:false); + $this->ort_kurzbz = $row->ort_kurzbz; + $this->updateamum = $row->updateamum; + $this->updatevon = $row->updatevon; + $this->insertvon = $row->insertvon; + $this->insertamum = $row->insertamum; + $this->ext_id = $row->ext_id; + // Neu wegen Inventar seq 2009-12 + $this->beschreibung = $row->beschreibung; // string + $this->hersteller = $row->hersteller; // string + $this->seriennummer = $row->seriennummer; // string + $this->bestellung_id = $row->bestellung_id; // integer + $this->bestelldetail_id = $row->bestelldetail_id; // integer + $this->afa = $row->afa; // string + $this->verwendung = $row->verwendung; // string + $this->anmerkung = $row->anmerkung; // string + $this->leasing_bis = $row->leasing_bis; // string + $this->oe_kurzbz = trim($row->oe_kurzbz); // string + + if (empty($this->oe_kurzbz)) + { + $qry="SELECT uid "; + $qry.=" FROM ".$this->schema_inventar.".tbl_betriebsmittel "; + $qry.=" JOIN ".$this->schema_inventar.".tbl_betriebsmittelperson USING(betriebsmittel_id) "; + $qry.=" JOIN campus.vw_benutzer USING(person_id) "; + + $qry.=" WHERE tbl_betriebsmittel.betriebsmittel_id='".addslashes($this->betriebsmittel_id)."' "; + $qry.=" order by retouram asc limit 1 "; + + $qry1 = "SELECT + *, tbl_benutzerfunktion.oe_kurzbz as oe_kurzbz, tbl_organisationseinheit.bezeichnung as oe_bezeichnung, + tbl_benutzerfunktion.semester, tbl_benutzerfunktion.bezeichnung as bf_bezeichnung + FROM + public.tbl_benutzerfunktion + JOIN public.tbl_funktion USING(funktion_kurzbz) + JOIN public.tbl_organisationseinheit USING(oe_kurzbz) + WHERE + uid=($qry) + AND tbl_organisationseinheit.aktiv + AND (tbl_benutzerfunktion.datum_von is null OR tbl_benutzerfunktion.datum_von<=now()) + AND (tbl_benutzerfunktion.datum_bis is null OR tbl_benutzerfunktion.datum_bis>=now()) + limit 1 + "; + if($res1=$this->db_query($qry1)) + { + $rows =array(); + if($rows = $this->db_fetch_object($res1)) + $this->oe_kurzbz = $rows->oe_kurzbz; + $row->oe_kurzbz=$this->oe_kurzbz; + } + } + return $this->result=$row; + } + else + { + $this->errormsg = 'Betriebsmittel wurde nicht gefunden '.($this->debug?$this->db_last_error()."
$qry
":''); + return false; + } + } + else + { + $this->errormsg = 'Fehler beim Laden der Daten '.($this->debug?$this->db_last_error()."
$qry
":''); + return false; + } + } + + + /** + * Laedt das Betriebsmittel mit der Bestell ID des Betriebsmittels $bestellung_id + * @param $bestellung_id Bestellnummer des zu ladenden Betriebsmittel + * @param $bestelldetail_id Bestellposition des zu ladenden Betriebsmittel + * @return true wenn ok, false im Fehlerfall + */ + public function load_bestellung_id($bestellung_id,$bestelldetail_id=null) + { + // Initialisieren + $this->result=array(); + $this->errormsg = ''; + + $qry=''; + $qry.=' select * '; + $qry.=' from '.$this->schema_inventar.'.tbl_betriebsmittel '; + $qry.=' where bestellung_id='.$this->addslashes($bestellung_id); + if (!is_null($bestelldetail_id) && !empty($bestelldetail_id) && is_numeric($bestelldetail_id) ) + $qry.=' and bestelldetail_id='.$this->addslashes($bestelldetail_id); + + if($this->db_query($qry)) + { + if($row = $this->db_fetch_object()) + { + $this->betriebsmittel_id = $row->betriebsmittel_id; + $this->beschreibung = $row->beschreibung; + $this->betriebsmitteltyp = $row->betriebsmitteltyp; + $this->nummer = $row->nummer; + $this->nummerintern = $row->nummerintern; + $this->reservieren = ($row->reservieren=='t'?true:false); + $this->ort_kurzbz = $row->ort_kurzbz; + $this->updateamum = $row->updateamum; + $this->updatevon = $row->updatevon; + $this->insertvon = $row->insertvon; + $this->insertamum = $row->insertamum; + $this->ext_id = $row->ext_id; + // Neu wegen Inventar seq 2009-12 + $this->beschreibung = $row->beschreibung; // string + $this->oe_kurzbz = $row->oe_kurzbz; // string + $this->hersteller = $row->hersteller; // string + $this->seriennummer = $row->seriennummer; // string + $this->bestellung_id = $row->bestellung_id; // integer + $this->bestelldetail_id = $row->bestelldetail_id; // integer + $this->afa = $row->afa; // string + $this->verwendung = $row->verwendung; // string + $this->anmerkung = $row->anmerkung; // string + $this->leasing_bis = $row->leasing_bis; // date + return $this->result=$row; + } + else + { + $this->errormsg = 'Betriebsmittel wurde nicht gefunden '.($this->debug?$this->db_last_error()."
$qry
":''); + return false; + } + } + else + { + $this->errormsg = 'Fehler beim Laden der Daten '.($this->debug?$this->db_last_error()."
$qry
":''); + return false; + } + } + + /** + * Laedt INVENTARTABELLE + * @param order_by SQL Sortierung der Abfrage + * @param nummer ID eines Inventars + * @param ort_kurzbz ort_kurzbz eines Inventars + * @param betriebsmitteltyp ort_kurzbz eines Inventars + * @param betriebsmittelstatus_kurzbz STATUS eines Inventars + * @param nummer Datensatzid eines Inventars + * @param bestellnr WAWI Bestellnummer des Inventars + * @param bestellung_id WAWI Rechnungsnummer des Inventars + * @param afa AfA Datum + * @param Jahr_Monat der WAWI Bestellerfassung + * @param firma_id der WAWI Bestellerfassung + + * @param inventur_jahr der Status Jahr - Status = inventur + * @param beschreibung der Inventarbeschreibung + * @param oe_kurzbz der Organisatzion + + * @return Daten Objekt wenn ok, false im Fehlerfall + */ + function betriebsmittel_inventar($order=null,$nummer=null,$ort_kurzbz=null,$betriebsmittelstatus_kurzbz=null,$betriebsmitteltyp=null,$bestellung_id=null,$bestelldetail_id=null,$bestellnr=null,$hersteller=null,$afa=null,$jahr_monat=null,$firma_id=null,$inventur_jahr=null,$beschreibung=null,$oe_kurzbz=null,$seriennummer=null,$person_id=null,$betriebsmittel_id=null) + { + // Init + $this->errormsg=''; + $this->result=array(); + + $nummer=trim($nummer); + $ort_kurzbz=trim($ort_kurzbz); + $firma_id=trim($firma_id); + + $qry=''; + $qry.='select distinct(tbl_betriebsmittel.nummer) '; +# $qry.=',tbl_betriebsmittelperson.person_id '; + $qry.=',tbl_betriebsmittel_betriebsmittelstatus.betriebsmittelbetriebsmittelstatus_id '; + $qry.=',tbl_betriebsmittel_betriebsmittelstatus.betriebsmittelstatus_kurzbz '; + $qry.=',tbl_betriebsmittel_betriebsmittelstatus.datum as betriebsmittelstatus_datum '; + $qry.=',tbl_betriebsmittelstatus.beschreibung as betriebsmittelstatus_beschreibung '; + $qry.=',tbl_betriebsmitteltyp.beschreibung as betriebsmitteltyp_beschreibung '; + $qry.=', tbl_betriebsmittel.*'; + $qry.=', wawi_be.*'; + $qry.=", trim(to_char(date_part('year', tbl_betriebsmittel_betriebsmittelstatus.datum) + tbl_betriebsmittel.afa , '9999') || '-' || to_char(tbl_betriebsmittel_betriebsmittelstatus.datum, 'MM-DD')) as betriebsmittelstatus_datum_afa "; + $qry.=' from '.$this->schema_inventar.'.tbl_betriebsmittel'; + + $qry.=' left outer join '.$this->schema_inventar.'.tbl_betriebsmitteltyp on (tbl_betriebsmitteltyp.betriebsmitteltyp=tbl_betriebsmittel.betriebsmitteltyp ) '; + $qry.=' left outer join '.$this->schema_inventar.'.tbl_betriebsmittel_betriebsmittelstatus on (tbl_betriebsmittel_betriebsmittelstatus.betriebsmittel_id=tbl_betriebsmittel.betriebsmittel_id ) '; + $qry.=' left outer join '.$this->schema_inventar.'.tbl_betriebsmittelstatus on (tbl_betriebsmittelstatus.betriebsmittelstatus_kurzbz=tbl_betriebsmittel_betriebsmittelstatus.betriebsmittelstatus_kurzbz ) '; + $qry.=' left outer join public.tbl_ort on (tbl_ort.ort_kurzbz=tbl_betriebsmittel.ort_kurzbz ) '; + $qry.=' left outer join '.$this->schema_inventar.'.tbl_betriebsmittelperson on (tbl_betriebsmittelperson.betriebsmittel_id=tbl_betriebsmittel.betriebsmittel_id ) '; + + // Verbindung zum WAWI aufbauen + $qry.=' left outer join dblink(\''.CONN_STRING_WAWI.'\',\' + select distinct bestellung.bestellung_id,bestellung.bestellnr,bestellung.titel,bestellung.firma_id,firma.firmenname from public.bestellung + left join public.firma on ( firma.firma_id=bestellung.firma_id ) \' ) + as wawi_be(bestellung_id int, bestellnr char(32), titel char(120), firma_id int, firmenname char(160) ) + on ( cast(wawi_be.bestellung_id as INTEGER)=cast(tbl_betriebsmittel.bestellung_id as INTEGER) and cast(tbl_betriebsmittel.bestellung_id as INTEGER)>0 ) '; + + $qry.=" where not tbl_betriebsmittel.betriebsmittel_id is null "; + $where=$this->betriebsmittel_inventar_get_where($nummer,$ort_kurzbz,$betriebsmittelstatus_kurzbz,$betriebsmitteltyp,$bestellung_id,$bestelldetail_id,$bestellnr,$hersteller,$afa,$jahr_monat,$firma_id,$inventur_jahr,$beschreibung,$oe_kurzbz,$seriennummer,$person_id,$betriebsmittel_id); + if ($where!='' && !$where) + return $this->result; + + // Select und Bedingung zusammen fuehren zu SQL Abfrage + $qry.=$where.(!is_null($order) && !empty($order)?' ORDER BY '. $order:''). (!$where?' limit 100 ':' limit 300 '); +## echo "
$qry
"; + if(!$result=$this->db_query($qry)) + { + $this->errormsg ='Probleme beim lesen der Betriebsmittel '.($this->debug?$this->db_last_error() ."
$qry
":'') ; + return false; + } + while($row = $this->db_fetch_object($result)) + $this->result[]=$row; +##var_dump($this->result); + return $this->result; + } +// Ende =========================================================================================== + + /** + * Laedt INVENTARTABELLE BESTELLUNG_ID + * @param nummer ID eines Inventars + * @param ort_kurzbz ort_kurzbz eines Inventars + * @param betriebsmitteltyp ort_kurzbz eines Inventars + * @param betriebsmittelstatus_kurzbz STATUS eines Inventars + * @param nummer Datensatzid eines Inventars + * @param bestellnr WAWI Bestellnummer des Inventars + * @param bestellung_id WAWI Rechnungsnummer des Inventars + * @param afa AfA Datum + * @param Jahr_Monat der WAWI Bestellerfassung + * @param firma_id der WAWI Bestellerfassung + + * @param inventur_jahr der Status Jahr - Status = inventur + * @param beschreibung der Inventarbeschreibung + * @param oe_kurzbz der Organisatzion + + * @return Daten Objekt wenn ok, false im Fehlerfall + */ + function betriebsmittel_inventar_bestellung_id($order=null,$nummer=null,$ort_kurzbz=null,$betriebsmittelstatus_kurzbz=null,$betriebsmitteltyp=null,$bestellung_id=null,$bestelldetail_id=null,$bestellnr=null,$hersteller=null,$afa=null,$jahr_monat=null,$firma_id=null,$inventur_jahr=null,$beschreibung=null,$oe_kurzbz=null,$seriennummer=null,$person_id=null,$betriebsmittel_id=null) + { + // Init + $this->errormsg=''; + $this->result=array(); + + $ort_kurzbz=trim($ort_kurzbz); + $qry=''; + $qry.='select distinct(tbl_betriebsmittel.bestellung_id) '; + $qry.=' from '.$this->schema_inventar.'.tbl_betriebsmittel'; + + $qry.=' left outer join '.$this->schema_inventar.'.tbl_betriebsmitteltyp on (tbl_betriebsmitteltyp.betriebsmitteltyp=tbl_betriebsmittel.betriebsmitteltyp ) '; + $qry.=' left outer join '.$this->schema_inventar.'.tbl_betriebsmittel_betriebsmittelstatus on (tbl_betriebsmittel_betriebsmittelstatus.betriebsmittel_id=tbl_betriebsmittel.betriebsmittel_id ) '; + $qry.=' left outer join '.$this->schema_inventar.'.tbl_betriebsmittelstatus on (tbl_betriebsmittelstatus.betriebsmittelstatus_kurzbz=tbl_betriebsmittel_betriebsmittelstatus.betriebsmittelstatus_kurzbz ) '; + $qry.=' left outer join public.tbl_ort on (tbl_ort.ort_kurzbz=tbl_betriebsmittel.ort_kurzbz ) '; + $qry.=' left outer join '.$this->schema_inventar.'.tbl_betriebsmittelperson on (tbl_betriebsmittelperson.betriebsmittel_id=tbl_betriebsmittel.betriebsmittel_id ) '; + + // Verbindung zum WAWI aufbauen + if ( $bestellnr || $firma_id || $beschreibung ) + $qry.=' left outer join dblink(\''.CONN_STRING_WAWI.'\',\' + select distinct bestellung.bestellung_id,bestellung.bestellnr,bestellung.titel,bestellung.firma_id,firma.firmenname from public.bestellung + left join public.firma on ( firma.firma_id=bestellung.firma_id ) \' ) + as wawi_be(bestellung_id int, bestellnr char(32), titel char(120), firma_id int, firmenname char(160) ) + on ( cast(wawi_be.bestellung_id as INTEGER)=cast(tbl_betriebsmittel.bestellung_id as INTEGER) and cast(tbl_betriebsmittel.bestellung_id as INTEGER)>0 ) '; + + $qry.=" where not tbl_betriebsmittel.bestellung_id is null "; + $where=''; + $where=$this->betriebsmittel_inventar_get_where($nummer,$ort_kurzbz,$betriebsmittelstatus_kurzbz,$betriebsmitteltyp,$bestellung_id,$bestelldetail_id,$bestellnr,$hersteller,$afa,$jahr_monat,$firma_id,$inventur_jahr,$beschreibung,$oe_kurzbz,$seriennummer); + + // Select und Bedingung zusammen fuehren zu SQL Abfrage + if (is_null($order) || empty($order) ) + $order='tbl_betriebsmittel.bestellung_id'; + + $qry.=$where.(!is_null($order) && !empty($order)?' ORDER BY '. $order:'').(!$where?' limit 20 ':' limit 50 '); + if(!$result=$this->db_query($qry)) + { + $this->errormsg ='Probleme beim lesen der Betriebsmittel '.($this->debug?$this->db_last_error() ."
$qry
":'') ; + return false; + } + while($row = $this->db_fetch_object($result)) + { + $this->result[]=$row; + } +#var_dump($this->result); +#exit; + return $this->result; + } +// ------------------------------------------- + + function betriebsmittel_inventar_get_where($nummer=null,$ort_kurzbz=null,$betriebsmittelstatus_kurzbz=null,$betriebsmitteltyp=null,$bestellung_id=null,$bestelldetail_id=null,$bestellnr=null,$hersteller=null,$afa=null,$jahr_monat=null,$firma_id=null,$inventur_jahr=null,$beschreibung=null,$oe_kurzbz=null,$seriennummer=null,$person_id=null,$betriebsmittel_id=null) + { +## echo " betriebsmittel_inventar($nummer
,$ort_kurzbz
,StatusKurz $betriebsmittelstatus_kurzbz
,$betriebsmitteltyp
,Bestellung ID $bestellung_id
,$bestelldetail_id
,Bestellnr $bestellnr
,$hersteller
,AFA $afa
,JJMM $jahr_monat
,Firma $firma_id
,Invent $inventur_jahr
,Beschr $beschreibung
,OE $oe_kurzbz
Seriennr $seriennummer
, person_id $person_id
, betriebsmittel_id $betriebsmittel_id
"; +#exit; + $where=''; + // Inventarnummer oder Betriebsmittelnummer + if (!is_null($nummer) && !empty($nummer) ) + { + $matchcode=mb_strtoupper(addslashes(str_replace(array('*','%',',',';',"'",'"',' '),'%',trim($nummer)))); +## $where.=" AND UPPER(trim(tbl_betriebsmittel.nummer)) like '%".$matchcode."%' " ; + $where.=" AND UPPER(trim(tbl_betriebsmittel.nummer)) like '".$matchcode."' " ; + } + if (!is_null($betriebsmittel_id) && !empty($betriebsmittel_id) ) + $where.=" AND tbl_betriebsmittel.betriebsmittel_id = ".$this->addslashes(trim($betriebsmittel_id)); + + // Inventarnummer oder Betriebsmittelnummer + if (!is_null($seriennummer) && !empty($seriennummer) ) + { + $matchcode=mb_strtoupper(addslashes(str_replace(array('*','%',',',';',"'",'"',' '),'%',trim($seriennummer)))); + $where.=" AND UPPER(trim(tbl_betriebsmittel.seriennummer)) like '%".$matchcode."%' " ; + } + + if (!is_null($hersteller) && $hersteller!='' ) + { + $matchcode=mb_strtoupper(addslashes(str_replace(array('*','%',',',';',"'",'"',' '),'%',trim($hersteller)))); + $where.=" AND UPPER(trim(tbl_betriebsmittel.hersteller)) like '%".$matchcode."%' " ; + } + + if (!is_null($beschreibung) && $beschreibung!='' ) + { + $matchcode=mb_strtoupper(addslashes(str_replace(array('*','%',',',';',"'",'"',' '),'%',trim($beschreibung)))); + $where.=" AND ( UPPER(trim(tbl_betriebsmittel.beschreibung)) like '%".$matchcode."%' "; + $where.=" or UPPER(trim(tbl_betriebsmittel.verwendung)) like '%".$matchcode."%' "; + if ( $bestellnr || $firma_id || $beschreibung ) + $where.=" or UPPER(trim(wawi_be.titel)) like '%". $matchcode ."%' " ; + $where.=" or UPPER(trim(tbl_betriebsmittel.anmerkung)) like '%".$matchcode."%' ) "; + + } + + if (!is_null($bestellung_id) && $bestellung_id!='' && is_numeric($bestellung_id)) + $where.=" AND tbl_betriebsmittel.bestellung_id=". addslashes(trim($bestellung_id)); + elseif (!is_null($bestellung_id) && $bestellung_id!='') + $where.=" AND UPPER(trim(to_char(tbl_betriebsmittel.bestellung_id,'999999999'))) like '". mb_strtoupper(addslashes(str_replace(array('*',';',' ',"'",'"'),'%',trim($bestellung_id)))) ."%' " ; + + if (!is_null($bestelldetail_id) && $bestelldetail_id!='' && is_numeric($bestelldetail_id)) + $where.=" AND tbl_betriebsmittel.bestelldetail_id=". addslashes(trim($bestelldetail_id)); + elseif (!is_null($bestelldetail_id) && $bestelldetail_id!='') + $where.=" AND UPPER(trim(to_char(tbl_betriebsmittel.bestelldetail_id,'999999999'))) like '". mb_strtoupper(addslashes(str_replace(array('*',';',' ',"'",'"'),'%',trim($bestelldetail_id)))) ."%' " ; + + if (!is_null($person_id) && $person_id!='' ) + { + $pWhere=''; + if (is_numeric($person_id) ) + $pWhere.=" AND ( tbl_betriebsmittelperson.person_id=". addslashes(trim($person_id)); + else + { + $matchcode=mb_strtoupper(addslashes(str_replace(array('*','%',',',';',"'",'"',' '),'%',trim($person_id)))); + $pWhere.=" AND ( tbl_betriebsmittelperson.person_id in (select person_id from campus.vw_benutzer where aktiv "; + $pWhere.=" and (UPPER(trim(uid)) like '%".$matchcode."%' "; + $pWhere.=" or UPPER(trim(to_char(person_id,'999999999'))) like '%".$matchcode."%' "; + $pWhere.=" or UPPER(trim(nachname)) like '%".addslashes($matchcode)."%' "; + $pWhere.=" or UPPER(trim(vorname)) like '%".addslashes($matchcode)."%' "; + $pWhere.=" or UPPER(trim(nachname || ' ' || vorname)) like '%".addslashes($matchcode)."%' "; + $pWhere.=" or UPPER(trim(vorname || ' ' || nachname)) like '%".addslashes($matchcode)."%' ) )"; + } + $where.=$pWhere; + + if (!is_null($oe_kurzbz) && $oe_kurzbz!='') + { +## where funktion_kurzbz='oezuordnung' + + $matchcode=mb_strtoupper(addslashes(str_replace(array('*','%',',',';',"'",'"',' '),'%',trim($oe_kurzbz)))); + $where.=" AND ( upper(trim(tbl_betriebsmittel.oe_kurzbz)) like '%". $matchcode."%' " ; + $where.=" or tbl_betriebsmittelperson.person_id in ( SELECT distinct vw_benutzer.person_id + FROM public.tbl_benutzerfunktion JOIN campus.vw_benutzer USING(uid) + where not funktion_kurzbz=null + and oe_kurzbz IN( + WITH RECURSIVE oes(oe_kurzbz, oe_parent_kurzbz) as + ( + SELECT oe_kurzbz, oe_parent_kurzbz FROM public.tbl_organisationseinheit + WHERE upper(trim(oe_kurzbz)) like '". $matchcode."' + UNION ALL + SELECT o.oe_kurzbz, o.oe_parent_kurzbz FROM public.tbl_organisationseinheit o, oes + WHERE o.oe_parent_kurzbz=oes.oe_kurzbz + ) + SELECT oe_kurzbz + FROM oes + GROUP BY oe_kurzbz )) + )"; + } + $where.=" )"; + } + // Organisation + else if (!is_null($oe_kurzbz) && $oe_kurzbz!='') + { + $matchcode=mb_strtoupper(addslashes(str_replace(array('*','%',',',';',"'",'"',' '),'%',trim($oe_kurzbz)))); + $where.=" AND ( upper(trim(tbl_betriebsmittel.oe_kurzbz)) like '". $matchcode."' " ; + $where.=" or tbl_betriebsmittelperson.person_id in ( SELECT distinct vw_benutzer.person_id + FROM public.tbl_benutzerfunktion JOIN campus.vw_benutzer USING(uid) + where not funktion_kurzbz=null + and oe_kurzbz IN( + WITH RECURSIVE oes(oe_kurzbz, oe_parent_kurzbz) as + ( + SELECT oe_kurzbz, oe_parent_kurzbz FROM public.tbl_organisationseinheit + WHERE upper(trim(oe_kurzbz)) like '". $matchcode."' + UNION ALL + SELECT o.oe_kurzbz, o.oe_parent_kurzbz FROM public.tbl_organisationseinheit o, oes + WHERE o.oe_parent_kurzbz=oes.oe_kurzbz + ) + SELECT oe_kurzbz + FROM oes + GROUP BY oe_kurzbz )) + )"; + } + +/* + + and tbl_betriebsmittelperson.person_id= ( SELECT distinct vw_benutzer.person_id + FROM public.tbl_benutzerfunktion JOIN campus.vw_benutzer USING(uid) + and (funktion_kurzbz='oezuordnung' OR funktion_kurzbz='Leitung') + and oe_kurzbz IN( + WITH RECURSIVE oes(oe_kurzbz, oe_parent_kurzbz) as + ( + SELECT oe_kurzbz, oe_parent_kurzbz FROM public.tbl_organisationseinheit + WHERE upper(trim(oe_kurzbz))=upper(trim('".addslashes($oe_kurzbz)."')) + UNION ALL + SELECT o.oe_kurzbz, o.oe_parent_kurzbz FROM public.tbl_organisationseinheit o, oes + WHERE o.oe_parent_kurzbz=oes.oe_kurzbz + ) + SELECT oe_kurzbz + FROM oes + GROUP BY oe_kurzbz limit 1 ) + +*/ + // Ort + if (!is_null($ort_kurzbz) && $ort_kurzbz!='') + { + $matchcode=mb_strtoupper(addslashes(str_replace(array('*','%',',',';',"'",'"',' '),'%',trim($ort_kurzbz)))); + $where.=" AND ( upper(trim(tbl_betriebsmittel.ort_kurzbz)) like '%". $matchcode."%' " ; + $where.=" OR upper(trim(tbl_ort.bezeichnung)) like '%".$matchcode."%' )" ; + } + + if (!is_null($betriebsmitteltyp) && !empty($betriebsmitteltyp) ) + $where.=" AND upper(trim(tbl_betriebsmittel.betriebsmitteltyp)) = ".$this->addslashes(mb_strtoupper(trim($betriebsmitteltyp))); + + // Datum Check + if (!is_null($afa) && $afa!='') + { + $afa=mb_strtoupper(trim(addslashes(str_replace(array('-',',',';','.','/','*','%',"'",'"'),'',trim($afa))))); + if (!empty($afa) && is_numeric($afa) && strlen($afa)>4) + $where.=" and not afa is null and trim(to_char(date_part('year', tbl_betriebsmittel_betriebsmittelstatus.datum) + tbl_betriebsmittel.afa , '9999') || to_char(tbl_betriebsmittel_betriebsmittelstatus.datum, 'MM')) = '".substr($afa,0,6)."'"; + else if (!empty($afa) && is_numeric($afa) && strlen($afa)>2) + $where.=" and not afa is null and trim(to_char(date_part('year', tbl_betriebsmittel_betriebsmittelstatus.datum) + tbl_betriebsmittel.afa ,'9999')) = '".substr($afa,0,4)."'"; + else + $where.=" and not afa is null and trim(to_char(date_part('year', tbl_betriebsmittel_betriebsmittelstatus.datum) + tbl_betriebsmittel.afa ,'9999')) <= '".Date('Y')."'"; + if (is_null($betriebsmittelstatus_kurzbz) || $betriebsmittelstatus_kurzbz=='' ) + $betriebsmittelstatus_kurzbz=mb_strtoupper('vorhanden'); + $where.=" and tbl_betriebsmittel_betriebsmittelstatus.betriebsmittelbetriebsmittelstatus_id in ( select max(betriebsmittelbetriebsmittelstatus_id) from wawi.tbl_betriebsmittel_betriebsmittelstatus ".($betriebsmittelstatus_kurzbz?" where not betriebsmittelbetriebsmittelstatus_id is null and upper(tbl_betriebsmittel_betriebsmittelstatus.betriebsmittelstatus_kurzbz) = ".$this->addslashes(mb_strtoupper(trim($betriebsmittelstatus_kurzbz))):'')." group by betriebsmittel_id ) "; + + } + elseif (!is_null($inventur_jahr) && $inventur_jahr!='') + { + $inventur_jahr=mb_strtoupper(trim(addslashes(str_replace(array('.','/','*','%',"'",'"'),'',trim($inventur_jahr))))); + if ($inventur_jahr>0) + { + $where.=" and to_char(tbl_betriebsmittel_betriebsmittelstatus.datum, 'YYYY') = '".($inventur_jahr)."'"; + $where.=" and tbl_betriebsmittel_betriebsmittelstatus.betriebsmittelbetriebsmittelstatus_id in ( select max(betriebsmittelbetriebsmittelstatus_id) from wawi.tbl_betriebsmittel_betriebsmittelstatus where not betriebsmittelbetriebsmittelstatus_id is null + and to_char(tbl_betriebsmittel_betriebsmittelstatus.datum, 'YYYY')='".$inventur_jahr."' ".($betriebsmittelstatus_kurzbz?" and upper(trim(betriebsmittelstatus_kurzbz))=".$this->addslashes(mb_strtoupper(trim($betriebsmittelstatus_kurzbz))):'')." group by betriebsmittel_id ) "; + } + else + { + $inventur_jahr=($inventur_jahr * -1); +# $where.=" and to_char(tbl_betriebsmittel_betriebsmittelstatus.datum, 'YYYY') = '".$inventur_jahr."'"; + $where.=" and not tbl_betriebsmittel_betriebsmittelstatus.betriebsmittelbetriebsmittelstatus_id in ( select max(betriebsmittelbetriebsmittelstatus_id) from wawi.tbl_betriebsmittel_betriebsmittelstatus where not betriebsmittelbetriebsmittelstatus_id is null + and to_char(tbl_betriebsmittel_betriebsmittelstatus.datum, 'YYYY')='".$inventur_jahr."' ".($betriebsmittelstatus_kurzbz?" and upper(trim(betriebsmittelstatus_kurzbz))=".$this->addslashes(mb_strtoupper(trim($betriebsmittelstatus_kurzbz))):'')." group by betriebsmittel_id ) "; + $betriebsmittelstatus_kurzbz='vorhanden'; + } + } + elseif (!is_null($jahr_monat) && $jahr_monat!='') + { + $jahr_monat=mb_strtoupper(trim(addslashes(str_replace(array('-','.','/','*','%',"'",'"'),'',trim($jahr_monat))))); + $jm=''; + if (!empty($jahr_monat) && is_numeric($jahr_monat) && strlen($jahr_monat)>6) + $jm=" and to_char(tbl_betriebsmittel_betriebsmittelstatus.datum, 'YYYYMMDD') = '".$jahr_monat."' "; + elseif (!empty($jahr_monat) && is_numeric($jahr_monat) && strlen($jahr_monat)>4) + $jm=" and to_char(tbl_betriebsmittel_betriebsmittelstatus.datum, 'YYYYMM') = '".$jahr_monat."' "; + elseif (!is_null($jahr_monat) && !empty($jahr_monat)) + $jm=" and to_char(tbl_betriebsmittel_betriebsmittelstatus.datum, 'YYYY') = '".$jahr_monat."' "; + $where.=$jm; + $where.=" and tbl_betriebsmittel_betriebsmittelstatus.betriebsmittelbetriebsmittelstatus_id in ( select max(betriebsmittelbetriebsmittelstatus_id) from wawi.tbl_betriebsmittel_betriebsmittelstatus where not betriebsmittelbetriebsmittelstatus_id is null ". $jm ." group by betriebsmittel_id ) "; + } + else if (!is_null($betriebsmittelstatus_kurzbz) && $betriebsmittelstatus_kurzbz!='') + $where.=" and tbl_betriebsmittel_betriebsmittelstatus.betriebsmittelbetriebsmittelstatus_id in ( select max(betriebsmittelbetriebsmittelstatus_id) from wawi.tbl_betriebsmittel_betriebsmittelstatus where not betriebsmittelbetriebsmittelstatus_id is null group by betriebsmittel_id ) "; + + // Bestellnummer + if (!is_null($bestellnr) && !empty($bestellnr) ) + { + $matchcode=mb_strtoupper(addslashes(str_replace(array('*','%',',',';',"'",'"',' '),'%',trim($bestellnr)))); + $where.=" AND UPPER(trim(wawi_be.bestellnr)) like '%".$matchcode."%' " ; + } + // Lieferant + if (!is_null($firma_id) && $firma_id!='' && is_numeric($firma_id)) + { + $where.=" AND wawi_be.firma_id=". trim($firma_id) ; + } + elseif (!is_null($firma_id) && $firma_id!='' ) + { + $matchcode=mb_strtoupper(addslashes(str_replace(array('*','%',',',';',"'",'"',' '),'%',trim($firma_id)))); + $where.=" AND UPPER(trim(wawi_be.firmenname)) like '%". $matchcode ."%' " ; + } + + if (!is_null($betriebsmittelstatus_kurzbz) && !empty($betriebsmittelstatus_kurzbz) ) + $where.=" and upper(trim(tbl_betriebsmittel_betriebsmittelstatus.betriebsmittelstatus_kurzbz)) = ".$this->addslashes(mb_strtoupper(trim($betriebsmittelstatus_kurzbz))) ; +##echo "
$where
"; + + return $where; + } + + + /** + * Laedt INVENTARTABELLE ORTE + * @param nummer ID eines Inventars + * @param ort_kurzbz ort_kurzbz eines Inventars + * @param betriebsmitteltyp ort_kurzbz eines Inventars + * @param betriebsmittelstatus_kurzbz STATUS eines Inventars + * @param nummer Datensatzid eines Inventars + * @param bestellnr WAWI Bestellnummer des Inventars + * @param bestellung_id WAWI Rechnungsnummer des Inventars + * @param afa AfA Datum + * @param Jahr_Monat der WAWI Bestellerfassung + * @param firma_id der WAWI Bestellerfassung + + * @param inventur_jahr der Status Jahr - Status = inventur + * @param beschreibung der Inventarbeschreibung + * @param oe_kurzbz der Organisatzion + + * @return Daten Objekt wenn ok, false im Fehlerfall + */ +/* + function betriebsmittel_inventar_orte($order=null,$nummer=null,$ort_kurzbz=null,$betriebsmittelstatus_kurzbz=null,$betriebsmitteltyp=null,$bestellung_id=null,$bestelldetail_id=null,$bestellnr=null,$hersteller=null,$afa=null,$jahr_monat=null,$firma_id=null,$inventur_jahr=null,$beschreibung=null,$oe_kurzbz=null,$seriennummer=null) + { + // Init + $this->errormsg=''; + $this->result=array(); + + $ort_kurzbz=trim($ort_kurzbz); + $qry=''; + $qry.='select distinct(tbl_betriebsmittel.ort_kurzbz),tbl_ort.bezeichnung '; + $qry.=' from '.$this->schema_inventar.'.tbl_betriebsmittel'; + $qry.=' left outer join '.$this->schema_inventar.'.tbl_betriebsmitteltyp on (tbl_betriebsmitteltyp.betriebsmitteltyp=tbl_betriebsmittel.betriebsmitteltyp ) '; + $qry.=' left outer join '.$this->schema_inventar.'.tbl_betriebsmittel_betriebsmittelstatus on (tbl_betriebsmittel_betriebsmittelstatus.betriebsmittel_id=tbl_betriebsmittel.betriebsmittel_id ) '; + $qry.=' left outer join '.$this->schema_inventar.'.tbl_betriebsmittelstatus on (tbl_betriebsmittelstatus.betriebsmittelstatus_kurzbz=tbl_betriebsmittel_betriebsmittelstatus.betriebsmittelstatus_kurzbz ) '; + $qry.=' left outer join public.tbl_ort on (tbl_ort.ort_kurzbz=tbl_betriebsmittel.ort_kurzbz ) '; + // Verbindung zum WAWI aufbauen + if ( $bestellnr || $firma_id || $beschreibung ) + $qry.=' left outer join dblink(\''.CONN_STRING_WAWI.'\',\' + select distinct bestellung.bestellung_id,bestellung.bestellnr,bestellung.titel,bestellung.firma_id,firma.firmenname from public.bestellung + left join public.firma on ( firma.firma_id=bestellung.firma_id ) \' ) + as wawi_be(bestellung_id int, bestellnr char(32), titel char(120), firma_id int, firmenname char(160) ) + on ( cast(wawi_be.bestellung_id as INTEGER)=cast(tbl_betriebsmittel.bestellung_id as INTEGER) and cast(tbl_betriebsmittel.bestellung_id as INTEGER)>0 ) '; + $qry.=" where not tbl_betriebsmittel.ort_kurzbz is null "; + + $where=''; + $where=$this->betriebsmittel_inventar_get_where($nummer,$ort_kurzbz,$betriebsmittelstatus_kurzbz,$betriebsmitteltyp,$bestellung_id,$bestelldetail_id,$bestellnr,$hersteller,$afa,$jahr_monat,$firma_id,$inventur_jahr,$beschreibung,$oe_kurzbz,$seriennummer); + + // Select und Bedingung zusammen fuehren zu SQL Abfrage + if (is_null($order) || empty($order) ) + $order='tbl_betriebsmittel.ort_kurzbz'; + + $qry.=$where.(!is_null($order) && !empty($order)?' ORDER BY '. $order:'').(!$where?' limit 30 ':' limit 90 '); + if(!$result=$this->db_query($qry)) + { + $this->errormsg ='Probleme beim lesen der Betriebsmittel '.($this->debug?$this->db_last_error() ."
$qry
":'') ; + return false; + } + while($row = $this->db_fetch_object($result)) + $this->result[]=$row; +#var_dump($this->result); + return $this->result; + } +*/ + + /** + * Laedt INVENTARTABELLE HERSTELLER + * @param nummer ID eines Inventars + * @param ort_kurzbz ort_kurzbz eines Inventars + * @param betriebsmitteltyp ort_kurzbz eines Inventars + * @param betriebsmittelstatus_kurzbz STATUS eines Inventars + * @param nummer Datensatzid eines Inventars + * @param bestellnr WAWI Bestellnummer des Inventars + * @param bestellung_id WAWI Rechnungsnummer des Inventars + * @param afa AfA Datum + * @param Jahr_Monat der WAWI Bestellerfassung + * @param firma_id der WAWI Bestellerfassung + + * @param inventur_jahr der Status Jahr - Status = inventur + * @param beschreibung der Inventarbeschreibung + * @param oe_kurzbz der Organisatzion + + * @return Daten Objekt wenn ok, false im Fehlerfall + */ +/* + function betriebsmittel_inventar_hersteller($order=null,$nummer=null,$ort_kurzbz=null,$betriebsmittelstatus_kurzbz=null,$betriebsmitteltyp=null,$bestellung_id=null,$bestelldetail_id=null,$bestellnr=null,$hersteller=null,$afa=null,$jahr_monat=null,$firma_id=null,$inventur_jahr=null,$beschreibung=null,$oe_kurzbz=null,$seriennummer=null) + { + // Init + $this->errormsg=''; + $this->result=array(); + + $ort_kurzbz=trim($ort_kurzbz); + $qry=''; + $qry.='select distinct(tbl_betriebsmittel.hersteller) '; + $qry.=' from '.$this->schema_inventar.'.tbl_betriebsmittel'; + + $qry.=' left outer join '.$this->schema_inventar.'.tbl_betriebsmitteltyp on (tbl_betriebsmitteltyp.betriebsmitteltyp=tbl_betriebsmittel.betriebsmitteltyp ) '; + $qry.=' left outer join '.$this->schema_inventar.'.tbl_betriebsmittel_betriebsmittelstatus on (tbl_betriebsmittel_betriebsmittelstatus.betriebsmittel_id=tbl_betriebsmittel.betriebsmittel_id ) '; + $qry.=' left outer join '.$this->schema_inventar.'.tbl_betriebsmittelstatus on (tbl_betriebsmittelstatus.betriebsmittelstatus_kurzbz=tbl_betriebsmittel_betriebsmittelstatus.betriebsmittelstatus_kurzbz ) '; + $qry.=' left outer join public.tbl_ort on (tbl_ort.ort_kurzbz=tbl_betriebsmittel.ort_kurzbz ) '; + // Verbindung zum WAWI aufbauen + if ( $bestellnr || $firma_id || $beschreibung ) + $qry.=' left outer join dblink(\''.CONN_STRING_WAWI.'\',\' + select distinct bestellung.bestellung_id,bestellung.bestellnr,bestellung.titel,bestellung.firma_id,firma.firmenname from public.bestellung + left join public.firma on ( firma.firma_id=bestellung.firma_id ) \' ) + as wawi_be(bestellung_id int, bestellnr char(32), titel char(120), firma_id int, firmenname char(160) ) + on ( cast(wawi_be.bestellung_id as INTEGER)=cast(tbl_betriebsmittel.bestellung_id as INTEGER) and cast(tbl_betriebsmittel.bestellung_id as INTEGER)>0 ) '; + + $qry.=" where not tbl_betriebsmittel.hersteller is null "; + + $where=$this->betriebsmittel_inventar_get_where($nummer,$ort_kurzbz,$betriebsmittelstatus_kurzbz,$betriebsmitteltyp,$bestellung_id,$bestelldetail_id,$bestellnr,$hersteller,$afa,$jahr_monat,$firma_id,$inventur_jahr,$beschreibung,$oe_kurzbz,$seriennummer); + + // Select und Bedingung zusammen fuehren zu SQL Abfrage + if (is_null($order) || empty($order) ) + $order='tbl_betriebsmittel.hersteller'; + + $qry.=$where.(!is_null($order) && !empty($order)?' ORDER BY '. $order:'').(!$where?' limit 20 ':' limit 50 '); + +#echo "
$qry
"; + + if(!$result=$this->db_query($qry)) + { + $this->errormsg ='Probleme beim lesen der Betriebsmittel '.($this->debug?$this->db_last_error() ."
$qry
":'') ; + return false; + } + while($row = $this->db_fetch_object($result)) + { + $this->result[]=$row; + } +#var_dump($this->result); +#exit; + return $this->result; + } +*/ + } -?> \ No newline at end of file +?> diff --git a/include/betriebsmittelperson.class.php b/include/betriebsmittelperson.class.php index c5f64acf3..b3b7a350a 100644 --- a/include/betriebsmittelperson.class.php +++ b/include/betriebsmittelperson.class.php @@ -27,6 +27,11 @@ require_once(dirname(__FILE__).'/basis_db.class.php'); class betriebsmittelperson extends basis_db { +# public $schema_inventar='public'; + public $schema_inventar='wawi'; + public $debug=false; // boolean + + public $new; // boolean public $result = array(); @@ -48,6 +53,7 @@ class betriebsmittelperson extends basis_db public $nummer; public $betriebsmitteltyp; public $beschreibung; + public $oe_kurzbz; /** * Konstruktor @@ -82,9 +88,8 @@ class betriebsmittelperson extends basis_db return false; } - $qry = "SELECT * FROM public.tbl_betriebsmittel JOIN public.tbl_betriebsmittelperson USING(betriebsmittel_id) + $qry = "SELECT * FROM ".$this->schema_inventar.".tbl_betriebsmittel JOIN ".$this->schema_inventar.".tbl_betriebsmittelperson USING(betriebsmittel_id) WHERE betriebsmittel_id='".addslashes($betriebsmittel_id)."' AND person_id='".addslashes($person_id)."'"; - if($this->db_query($qry)) { if($row = $this->db_fetch_object()) @@ -95,7 +100,6 @@ class betriebsmittelperson extends basis_db $this->nummer = $row->nummer; $this->nummerintern = $row->nummerintern; $this->reservieren = ($row->reservieren=='t'?true:false); - $this->ort_kurzbz = $row->ort_kurzbz; $this->person_id = $row->person_id; $this->anmerkung = $row->anmerkung; $this->kaution = $row->kaution; @@ -106,17 +110,18 @@ class betriebsmittelperson extends basis_db $this->updateamum = $row->updateamum; $this->updatevon = $row->updatevon; $this->ext_id = $row->ext_id; + $this->ort_kurzbz = $row->ort_kurzbz; return $this->result=$row; } else { - $this->errormsg = 'Es wurde kein passender Datensatz gefunden'; + $this->errormsg = 'Es wurde kein passender Datensatz gefunden '.($this->debug?$this->db_last_error()."
$qry
":''); return false; } } else { - $this->errormsg = 'Fehler beim Laden der Daten'; + $this->errormsg = 'Fehler beim Laden der Daten '.($this->debug?$this->db_last_error()."
$qry
":''); return false; } } @@ -181,21 +186,20 @@ class betriebsmittelperson extends basis_db if($new) { //Pruefen ob dieses Betriebsmittel dieser Person schon zugeordnet ist - $qry = "SELECT 1 FROM public.tbl_betriebsmittelperson - WHERE person_id='".addslashes($this->person_id)."' AND - betriebsmittel_id='".addslashes($this->betriebsmittel_id)."'"; - + $qry = "SELECT 1 FROM ".$this->schema_inventar.".tbl_betriebsmittelperson + WHERE person_id=".$this->addslashes($this->person_id)." AND + betriebsmittel_id=".$this->addslashes($this->betriebsmittel_id); + if($this->db_query($qry)) { if($this->db_num_rows()>0) { - $this->errormsg = 'Dieses Betriebsmittel ist der Person bereits zugeordnet'; + $this->errormsg = 'Dieses Betriebsmittel ist der Person bereits zugeordnet '.($this->debug?$this->db_last_error()."
$qry
":''); return false; } } //Neuen Datensatz einfuegen - - $qry='INSERT INTO public.tbl_betriebsmittelperson (betriebsmittel_id, person_id, anmerkung, kaution, + $qry='INSERT INTO '.$this->schema_inventar.'.tbl_betriebsmittelperson (betriebsmittel_id, person_id, anmerkung, kaution, ausgegebenam, retouram, ext_id, insertamum, insertvon, updateamum, updatevon) VALUES('. $this->addslashes($this->betriebsmittel_id).', '. $this->addslashes($this->person_id).', '. @@ -212,7 +216,7 @@ class betriebsmittelperson extends basis_db //Pruefen ob betriebsmittel_id eine gueltige Zahl ist if(!is_numeric($this->betriebsmittel_id) || !is_numeric($this->person_id)) { - $this->errormsg = 'betriebsmittel_id und Person_id muessen gueltige Zahlen sein'; + $this->errormsg = 'betriebsmittel_id und Person_id muessen gueltige Zahlen sein '.($this->debug?$this->db_last_error()."
$qry
":''); return false; } if($this->betriebsmittel_id_old=='') @@ -220,7 +224,7 @@ class betriebsmittelperson extends basis_db if($this->person_id_old=='') $this->person_id_old = $this->person_id; - $qry='UPDATE public.tbl_betriebsmittelperson SET '. + $qry='UPDATE '.$this->schema_inventar.'.tbl_betriebsmittelperson SET '. 'betriebsmittel_id='.$this->addslashes($this->betriebsmittel_id).', '. 'person_id='.$this->addslashes($this->person_id).', '. 'anmerkung='.$this->addslashes($this->anmerkung).', '. @@ -240,7 +244,7 @@ class betriebsmittelperson extends basis_db } else { - $this->errormsg = "Fehler beim Speichern der Betriebsmittelperson"; + $this->errormsg = "Fehler beim Speichern der Betriebsmittelperson ".($this->debug?$this->db_last_error()."
$qry
":'');; return false; } } @@ -251,28 +255,25 @@ class betriebsmittelperson extends basis_db * @param $person_id ID die geloescht werden soll * @return true wenn ok, false im Fehlerfall */ - public function delete($betriebsmittel_id, $person_id) + public function delete($betriebsmittel_id, $person_id=null) { if(!is_numeric($betriebsmittel_id)) { $this->errormsg = 'Betriebsmittel_id ist ungueltig'; return false; } - - if(!is_numeric($person_id)) + if($person_id && !is_numeric($person_id)) { $this->errormsg = 'Person_id ist ungueltig'; return false; } - - $qry = "DELETE FROM public.tbl_betriebsmittelperson - WHERE betriebsmittel_id='".addslashes($betriebsmittel_id)."' AND person_id='".addslashes($person_id)."'"; - + $qry = 'DELETE FROM '.$this->schema_inventar.'.tbl_betriebsmittelperson + WHERE betriebsmittel_id='.$this->addslashes($betriebsmittel_id).($person_id?' and person_id='.$this->addslashes($person_id):''); if($this->db_query($qry)) return true; else { - $this->errormsg = 'Fehler beim Loeschen der Daten'; + $this->errormsg = 'Fehler beim Loeschen der Daten '.($this->debug?$this->db_last_error()."
$qry
":'');; return false; } } @@ -284,13 +285,14 @@ class betriebsmittelperson extends basis_db */ public function getBetriebsmittelPerson($person_id, $betriebsmitteltyp=null) { + $this->result=array(); + $this->errormsg = ''; if(!is_numeric($person_id)) { $this->errormsg = 'Person_id ist ungueltig'; return false; } - - $qry = "SELECT * FROM public.tbl_betriebsmittel JOIN public.tbl_betriebsmittelperson USING(betriebsmittel_id) + $qry = "SELECT * FROM ".$this->schema_inventar.".tbl_betriebsmittel JOIN ".$this->schema_inventar.".tbl_betriebsmittelperson USING(betriebsmittel_id) WHERE person_id='".addslashes($person_id)."'"; if(!is_null($betriebsmitteltyp)) $qry.=" AND betriebsmitteltyp='".addslashes($betriebsmitteltyp)."'"; @@ -319,16 +321,175 @@ class betriebsmittelperson extends basis_db $bm->updateamum = $row->updateamum; $bm->updatevon = $row->updatevon; $bm->ext_id = $row->ext_id; - + $bm->oe_kurzbz = $row->oe_kurzbz; $this->result[] = $bm; } - return true; + if (count($this->result)==1) + { + $this->betriebsmittel_id = $this->result[0]->betriebsmittel_id; + $this->beschreibung = $this->result[0]->beschreibung; + $this->betriebsmitteltyp = $this->result[0]->betriebsmitteltyp; + $this->nummer = $this->result[0]->nummer; + $this->nummerintern = $this->result[0]->nummerintern; + $this->reservieren = ($this->result[0]->reservieren=='t'?true:false); + $this->ort_kurzbz = $this->result[0]->ort_kurzbz; + $this->person_id = $this->result[0]->person_id; + $this->anmerkung = $this->result[0]->anmerkung; + $this->kaution = $this->result[0]->kaution; + $this->ausgegebenam = $this->result[0]->ausgegebenam; + $this->retouram = $this->result[0]->retouram; + $this->insertamum = $this->result[0]->insertamum; + $this->insertvon = $this->result[0]->insertvon; + $this->updateamum = $this->result[0]->updateamum; + $this->updatevon = $this->result[0]->updatevon; + $this->ext_id = $this->result[0]->ext_id; + $this->oe_kurzbz = $this->result[0]->oe_kurzbz; + } + return $this->result; } else { - $this->errormsg = 'Fehler beim Laden der Daten'; + $this->errormsg = 'Fehler beim Laden der Daten '.($this->debug?$this->db_last_error()."
$qry
":'');; return false; } } + + /** + * Laedt das Betriebsmittel mit der ID $betriebsmittel_id + * @param $betriebsmittel_id ID des zu ladenden Betriebsmittels + * @return true wenn ok, false im Fehlerfall + */ + public function load_betriebsmittelpersonen($betriebsmittel_id) + { + $this->result=array(); + $this->errormsg=''; + + if(!is_numeric($betriebsmittel_id)) + { + $this->errormsg = 'Betriebsmittel_id ist ungueltig'; + return false; + } + + $qry=''; + $qry.='SELECT * '; + $qry.=' FROM '.$this->schema_inventar.'.tbl_betriebsmittel JOIN '.$this->schema_inventar.'.tbl_betriebsmittelperson USING(betriebsmittel_id)'; + $qry.=' WHERE betriebsmittel_id='.$this->addslashes($betriebsmittel_id); + $qry.=' order by ausgegebenam desc, retouram desc '; + $qry.=' limit 1'; + + if($this->db_query($qry)) + { + if($row = $this->db_fetch_object()) + { + $this->betriebsmittel_id = $row->betriebsmittel_id; + $this->beschreibung = $row->beschreibung; + $this->betriebsmitteltyp = $row->betriebsmitteltyp; + $this->nummer = $row->nummer; + $this->nummerintern = $row->nummerintern; + $this->reservieren = ($row->reservieren=='t'?true:false); + $this->ort_kurzbz = $row->ort_kurzbz; + $this->person_id = $row->person_id; + $this->anmerkung = $row->anmerkung; + $this->kaution = $row->kaution; + $this->ausgegebenam = $row->ausgegebenam; + $this->retouram = $row->retouram; + $this->insertamum = $row->insertamum; + $this->insertvon = $row->insertvon; + $this->updateamum = $row->updateamum; + $this->updatevon = $row->updatevon; + $this->ext_id = $row->ext_id; + $this->oe_kurzbz = $row->oe_kurzbz; + return $this->result=$row; + } + else + { + return false; + } + } + else + { + $this->errormsg = 'Fehler beim Laden der Daten '.($this->debug?$this->db_last_error()."
$qry
":''); + return false; + } + } + + /** + * Laedt das Betriebsmittel mit der ID $betriebsmittel_id + * @param $betriebsmittel_id ID des zu ladenden Betriebsmittels + * @return true wenn ok, false im Fehlerfall + */ + public function getbetriebsmittelpersonen($betriebsmittel_id) + { + $this->result=array(); + $this->errormsg=''; + + if(!is_numeric($betriebsmittel_id)) + { + $this->errormsg = 'Betriebsmittel_id ist ungueltig'; + return false; + } + $qry=''; + $qry.='SELECT * '; + $qry.=' FROM '.$this->schema_inventar.'.tbl_betriebsmittel JOIN '.$this->schema_inventar.'.tbl_betriebsmittelperson USING(betriebsmittel_id)'; + $qry.=' WHERE betriebsmittel_id='.$this->addslashes($betriebsmittel_id); + $qry.=' order by ausgegebenam desc, retouram desc'; + + if($this->db_query($qry)) + { + while($row = $this->db_fetch_object()) + { + $bm = new betriebsmittelperson(); + + $bm->betriebsmittel_id = $row->betriebsmittel_id; + $bm->beschreibung = $row->beschreibung; + $bm->betriebsmitteltyp = $row->betriebsmitteltyp; + $bm->nummer = $row->nummer; + $bm->nummerintern = $row->nummerintern; + $bm->reservieren = ($row->reservieren=='t'?true:false); + $bm->ort_kurzbz = $row->ort_kurzbz; + $bm->person_id = $row->person_id; + $bm->anmerkung = $row->anmerkung; + $bm->kaution = $row->kaution; + $bm->ausgegebenam = $row->ausgegebenam; + $bm->retouram = $row->retouram; + $bm->insertamum = $row->insertamum; + $bm->insertvon = $row->insertvon; + $bm->updateamum = $row->updateamum; + $bm->updatevon = $row->updatevon; + $bm->ext_id = $row->ext_id; + $bm->oe_kurzbz = $row->oe_kurzbz; + $this->result[] = $bm; + } + if (count($this->result)==1) + { + $this->betriebsmittel_id = $this->result[0]->betriebsmittel_id; + $this->beschreibung = $this->result[0]->beschreibung; + $this->betriebsmitteltyp = $this->result[0]->betriebsmitteltyp; + $this->nummer = $this->result[0]->nummer; + $this->nummerintern = $this->result[0]->nummerintern; + $this->reservieren = ($this->result[0]->reservieren=='t'?true:false); + $this->ort_kurzbz = $this->result[0]->ort_kurzbz; + $this->person_id = $this->result[0]->person_id; + $this->anmerkung = $this->result[0]->anmerkung; + $this->kaution = $this->result[0]->kaution; + $this->ausgegebenam = $this->result[0]->ausgegebenam; + $this->retouram = $this->result[0]->retouram; + $this->insertamum = $this->result[0]->insertamum; + $this->insertvon = $this->result[0]->insertvon; + $this->updateamum = $this->result[0]->updateamum; + $this->updatevon = $this->result[0]->updatevon; + $this->ext_id = $this->result[0]->ext_id; + $this->oe_kurzbz = $this->result[0]->oe_kurzbz; + } + + return $this->result; + } + else + { + $this->errormsg = 'Fehler beim Laden der Daten '.($this->debug?$this->db_last_error()."
$qry
":'');; + return false; + } + } + } ?> \ No newline at end of file diff --git a/include/betriebsmitteltyp.class.php b/include/betriebsmitteltyp.class.php index 4090c5c1d..2cfe377b4 100644 --- a/include/betriebsmitteltyp.class.php +++ b/include/betriebsmitteltyp.class.php @@ -1,144 +1,231 @@ -, - * Andreas Oesterreicher and - * Rudolf Hangl . - */ - -/** - * Klasse betriebsmitteltyp (FAS-Online) - * @create 13-01-2007 - */ -require_once(dirname(__FILE__).'/basis_db.class.php'); - -class betriebsmitteltyp extends basis_db -{ - public $new; - public $result = array(); - - //Tabellenspalten - public $betriebsmitteltyp; //string - public $beschreibung; //string - public $anzahl; //smallint - public $kaution; //numeric(5,2) - - /** - * Konstruktor - * @param $betriebsmitteltyp - */ - public function __construct($betriebsmitteltyp=null) - { - parent::__construct(); - - if($betriebsmitteltyp!=null) - $this->load($betriebsmitteltyp); - } - - /** - * Laedt die Funktion mit der ID $betriebsmitteltyp - * @param $betriebsmitteltyp - * @return true wenn ok, false im Fehlerfall - */ - public function load($betriebsmitteltyp) - { - $this->errormsg = 'Noch nicht implementiert'; - return false; - } - - /** - * Laedt alle BetriebsmittelTypen - * @return true wenn ok, false wenn Fehler - */ - public function getAll() - { - $qry = "SELECT * FROM public.tbl_betriebsmitteltyp ORDER BY betriebsmitteltyp"; - - if($this->db_query($qry)) - { - while($row = $this->db_fetch_object()) - { - $bmt = new betriebsmitteltyp(); - - $bmt->betriebsmitteltyp = $row->betriebsmitteltyp; - $bmt->beschreibung = $row->beschreibung; - $bmt->anzahl = $row->anzahl; - $bmt->kaution = $row->kaution; - - $this->result[] = $bmt; - } - return true; - } - else - { - $this->errormsg = 'Fehler beim Laden der Daten'; - return false; - } - } - - /** - * Speichert die Daten in die Datenbank - * @return true wenn erfolgreich, false im Fehlerfall - */ - public function save() - { - $dbanzahl=0; - $qry=''; - $qry1='SELECT * FROM public.tbl_betriebsmitteltyp WHERE beschreibung='.$this->addslashes($this->beschreibung).';'; - if($this->db_query($qry1)) - { - if($this->db_num_rows()>0) //eintrag gefunden - { - if($row1 = $this->db_fetch_object()) - { - if($row1->anzahl==null) - $dbanzahl=0; - else - $dbanzahl=$row1->anzahl; - - $qry='UPDATE public.tbl_betriebsmitteltyp SET '. - 'anzahl ='.addslashes($dbanzahl)."+".addslashes($this->anzahl).' '. - 'WHERE beschreibung='.$this->addslashes($this->beschreibung).';'; - } - } - else - { - $qry='INSERT INTO public.tbl_betriebsmitteltyp (betriebsmitteltyp, beschreibung, anzahl, kaution) VALUES('. - $this->addslashes($this->betriebsmitteltyp).', '. - $this->addslashes($this->beschreibung).', '. - $this->addslashes($this->anzahl).', '. - $this->addslashes($this->kaution).');'; - } - - if($this->db_query($qry)) - { - return true; - } - else - { - $this->errormsg = 'Fehler beim Speichern des Betriebsmitteltypen-Datensatzes'; - return false; - } - } - else - { - $this->errormsg = 'Fehler beim Zugriff auf den Betriebsmitteltypen-Datensatz'; - return false; - } - } -} +, + * Andreas Oesterreicher and + * Rudolf Hangl . + */ + +/** + * Klasse betriebsmitteltyp (FAS-Online) + * @create 13-01-2007 + */ +require_once(dirname(__FILE__).'/basis_db.class.php'); + +class betriebsmitteltyp extends basis_db +{ + private $schema_inventar='wawi'; + + public $debug=false; // boolean + public $new; // boolean + public $result = array(); + + //Tabellenspalten + public $betriebsmitteltyp; //string + public $beschreibung; //string + public $anzahl; //smallint + public $kaution; //numeric(5,2) + public $typ_code; //string(2) + + /** + * Konstruktor + * @param $betriebsmitteltyp + */ + public function __construct($betriebsmitteltyp=null) + { + parent::__construct(); + + if($betriebsmitteltyp!=null) + $this->load($betriebsmitteltyp); + } + + /** + * Laedt die Funktion mit der ID $betriebsmitteltyp + * @param $betriebsmitteltyp + * @return true wenn ok, false im Fehlerfall + */ + public function load($betriebsmitteltyp) + { + // Initialisieren Variable + $qry=''; + $where=''; + $this->result=array(); + $this->errormsg = ''; + // Select erzeugen + $qry.=' select * FROM '.$this->schema_inventar.'.tbl_betriebsmitteltyp'; + $qry.=" where betriebsmitteltyp >'' "; + + // Bedingungen hinzufuegen + $where.=" AND trim(UPPER(betriebsmitteltyp)) like '%".mb_strtoupper(trim(addslashes(str_replace(array('*',';',' ',"'",'"'),'%',trim($betriebsmitteltyp)))))."%' " ; + $qry.=$where; + + // Sortierung + $qry.=' order by betriebsmitteltyp '; + + // Datenbankabfrage - ausfuehren + if($this->db_query($qry)) + { + while($row = $this->db_fetch_object()) + { + $bmt = new betriebsmitteltyp(); + $bmt->betriebsmitteltyp = $row->betriebsmitteltyp; + $bmt->beschreibung = $row->beschreibung; + $bmt->anzahl = $row->anzahl; + $bmt->kaution = $row->kaution; + $bmt->typ_code = $row->typ_code; + $this->result[] = $bmt; + } + return $this->result; + } + else + { + $this->errormsg = 'Fehler beim Laden der Daten '.($this->debug?$this->db_last_error():''); + return false; + } + } + + /** + * Laedt alle BetriebsmittelTypen + * @return true wenn ok, false wenn Fehler + */ + public function getAll() + { + $this->result=array(); + $this->errormsg = ''; + $qry = "SELECT * FROM ".$this->schema_inventar.".tbl_betriebsmitteltyp ORDER BY betriebsmitteltyp"; + + if($this->db_query($qry)) + { + while($row = $this->db_fetch_object()) + { + $bmt = new betriebsmitteltyp(); + + $bmt->betriebsmitteltyp = $row->betriebsmitteltyp; + $bmt->beschreibung = $row->beschreibung; + $bmt->anzahl = $row->anzahl; + $bmt->kaution = $row->kaution; + $bmt->typ_code = $row->typ_code; + + $this->result[] = $bmt; + } + return true; + } + else + { + $this->errormsg = 'Fehler beim Laden der Daten '.($this->debug?$this->db_last_error():''); + return false; + } + } + + /** + * Speichert die Daten in die Datenbank + * @return true wenn erfolgreich, false im Fehlerfall + */ + public function save() + { + $this->errormsg = ''; + $dbanzahl=0; + $qry=''; + $qry1='SELECT * FROM '.$this->schema_inventar.'.tbl_betriebsmitteltyp WHERE beschreibung='.$this->addslashes($this->beschreibung).';'; + if($this->db_query($qry1)) + { + if($this->db_num_rows()>0) //eintrag gefunden + { + if($row1 = $this->db_fetch_object()) + { + if($row1->anzahl==null) + $dbanzahl=0; + else + $dbanzahl=$row1->anzahl; + + $qry='UPDATE '.$this->schema_inventar.'.tbl_betriebsmitteltyp SET '. + 'anzahl ='.addslashes($dbanzahl)."+".addslashes($this->anzahl).' '. + 'WHERE beschreibung='.$this->addslashes($this->beschreibung).'; ' ; + } + } + else + { + $qry='INSERT INTO '.$this->schema_inventar.'.tbl_betriebsmitteltyp (betriebsmitteltyp, beschreibung, anzahl, kaution,typ_code) VALUES('. + $this->addslashes($this->betriebsmitteltyp).', '. + $this->addslashes($this->beschreibung).', '. + $this->addslashes($this->anzahl).', '. + $this->addslashes($this->kaution).', '. + $this->addslashes($this->typ_code).');'; + } + + if($this->db_query($qry)) + { + return true; + } + else + { + $this->errormsg = 'Fehler beim Speichern des Betriebsmitteltypen-Datensatzes '.($this->debug?$this->db_last_error():''); + return false; + } + } + else + { + $this->errormsg = 'Fehler beim Zugriff auf den Betriebsmitteltypen-Datensatz '.($this->debug?$this->db_last_error():''); + return false; + } + } + + /** + * Speichert die Daten in die Datenbank + * @return true wenn erfolgreich, false im Fehlerfall + */ + public function update() + { + $this->errormsg = ''; + $qry='UPDATE '.$this->schema_inventar.'.tbl_betriebsmitteltyp SET '. + 'beschreibung ='.$this->addslashes($this->beschreibung).', '. + 'anzahl ='.$this->addslashes($this->anzahl).', '. + 'kaution ='.$this->addslashes($this->kaution).', '. + 'typ_code ='.$this->addslashes($this->typ_code).' '. + 'WHERE betriebsmitteltyp='.$this->addslashes($this->betriebsmitteltyp).'; ' ; + if($this->db_query($qry)) + { + return true; + } + else + { + $this->errormsg = 'Fehler beim Speichern des Betriebsmitteltypen-Datensatzes '.($this->debug?$this->db_last_error():''); + return false; + } + } + /** + * Speichert die Daten in die Datenbank + * @return true wenn erfolgreich, false im Fehlerfall + */ + public function check_beschreibung() + { + $this->errormsg = ''; + $qry='UPDATE '.$this->schema_inventar.'.tbl_betriebsmitteltyp SET '. + 'beschreibung = trim(betriebsmitteltyp) '. + ' where beschreibung is null '; + if($this->db_query($qry)) + { + return true; + } + else + { + $this->errormsg = 'Fehler beim Pruefen der Beschreibung des Betriebsmitteltypen-Datensatzes '.($this->debug?$this->db_last_error():''); + return false; + } + } +} ?> \ No newline at end of file diff --git a/include/firma.class.php b/include/firma.class.php index 3f75d82e0..e460c0347 100644 --- a/include/firma.class.php +++ b/include/firma.class.php @@ -1,358 +1,550 @@ -, - * Andreas Oesterreicher and - * Rudolf Hangl . - */ -/** - * Klasse firma - * @create 18-12-2006 - */ -require_once(dirname(__FILE__).'/basis_db.class.php'); - -class firma extends basis_db -{ - public $new; // boolean - public $result = array(); // adresse Objekt - - //Tabellenspalten - public $firma_id; // integer - public $name; // string - public $adresse; // string - public $email; // string - public $telefon; // string - public $fax; // string - public $anmerkung; // string - public $ext_id; // integer - public $insertamum; // timestamp - public $insertvon; // bigint - public $updateamum; // timestamp - public $updatevon; // bigint - public $firmentyp_kurzbz; - public $schule; // boolean - - /** - * Konstruktor - * @param $firma_id ID der Firma die geladen werden soll (Default=null) - */ - public function __construct($firma_id=null) - { - parent::__construct(); - - if(!is_null($firma_id)) - $this->load($firma_id); - } - - /** - * Laedt die Firma mit der ID $firma_id - * @param $firma_id ID der zu ladenden Funktion - * @return true wenn ok, false im Fehlerfall - */ - public function load($firma_id) - { - if(!is_numeric($firma_id)) - { - $this->errormsg = 'Firma_id ist ungueltig'; - return false; - } - - $qry = "SElECT * FROM public.tbl_firma WHERE firma_id='$firma_id'"; - - if($this->db_query($qry)) - { - if($row = $this->db_fetch_object()) - { - $this->firma_id = $row->firma_id; - $this->name = $row->name; - $this->adresse = $row->adresse; - $this->email = $row->email; - $this->telefon = $row->telefon; - $this->fax = $row->fax; - $this->anmerkung = $row->anmerkung; - $this->firmentyp_kurzbz = $row->firmentyp_kurzbz; - $this->updateamum = $row->updateamum; - $this->updatevon = $row->updatevon; - $this->insertamum = $row->insertamum; - $this->insertvon = $row->insertvon; - $this->ext_id = $row->ext_id; - $this->schule = ($row->schule=='t'?true:false); - return true; - } - else - { - $this->errormsg = 'Datensatz wurde nicht gefunden'; - return false; - } - } - else - { - $this->errormsg = 'Fehler beim Laden des Datensatzes'; - return false; - } - } - - /** - * Prueft die Variablen auf Gueltigkeit - * @return true wenn ok, false im Fehlerfall - */ - protected function validate() - { - //Gesamtlaenge pruefen - if(mb_strlen($this->name)>128) - { - $this->errormsg = 'Name darf nicht länger als 128 Zeichen sein'; - return false; - } - if(mb_strlen($this->anmerkung)>256) - { - $this->errormsg = 'Anmerkung darf nicht länger 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 $firma_id aktualisiert - * @return true wenn ok, false im Fehlerfall - */ - public function save() - { - //Variablen pruefen - if(!$this->validate()) - return false; - - if($this->new) - { - //Neuen Datensatz einfuegen - $qry='INSERT INTO public.tbl_firma (name, adresse, email, telefon, fax, anmerkung, - firmentyp_kurzbz, updateamum, updatevon, insertamum, insertvon, ext_id, schule) VALUES('. - $this->addslashes($this->name).', '. - $this->addslashes($this->adresse).', '. - $this->addslashes($this->email).', '. - $this->addslashes($this->telefon).', '. - $this->addslashes($this->fax).', '. - $this->addslashes($this->anmerkung).', '. - $this->addslashes($this->firmentyp_kurzbz).', '. - $this->addslashes($this->updateamum).', '. - $this->addslashes($this->updatevon).', '. - $this->addslashes($this->insertamum).', '. - $this->addslashes($this->insertvon).', '. - $this->addslashes($this->ext_id).','. - ($this->schule?'true':'false').'); '; - } - else - { - //Updaten des bestehenden Datensatzes - - //Pruefen ob firma_id eine gueltige Zahl ist - if(!is_numeric($this->firma_id)) - { - $this->errormsg = 'firma_id muss eine gueltige Zahl sein'; - return false; - } - - $qry='UPDATE public.tbl_firma SET '. - 'firma_id='.$this->addslashes($this->firma_id).', '. - 'name='.$this->addslashes($this->name).', '. - 'adresse='.$this->addslashes($this->adresse).', '. - 'email='.$this->addslashes($this->email).', '. - 'telefon='.$this->addslashes($this->telefon).', '. - 'fax='.$this->addslashes($this->fax).', '. - 'anmerkung='.$this->addslashes($this->anmerkung).', '. - 'updateamum= now(), '. - 'updatevon='.$this->addslashes($this->updatevon).', '. - 'firmentyp_kurzbz='.$this->addslashes($this->firmentyp_kurzbz).', '. - 'schule='.($this->schule?'true':'false').' '. - 'WHERE firma_id='.$this->addslashes($this->firma_id).';'; - } - - if($this->db_query($qry)) - { - if($this->new) - { - //Sequence lesen - $qry="SELECT currval('public.tbl_firma_firma_id_seq') as id;"; - if($this->db_query($qry)) - { - if($row = $this->db_fetch_object()) - { - $this->firma_id = $row->id; - $this->db_query('COMMIT'); - return true; - } - else - { - $this->errormsg = 'Fehler beim Auslesen der Sequence'; - $this->db_query('ROLLBACK'); - return false; - } - } - else - { - $this->errormsg = 'Fehler beim Auslesen der Sequence'; - $this->db_query('ROLLBACK'); - return false; - } - } - return true; - } - else - { - $this->errormsg = 'Fehler beim Speichern des Firma-Datensatzes'; - return false; - } - } - - /** - * Loescht den Datenensatz mit der ID die uebergeben wird - * @param $firma_id ID die geloescht werden soll - * @return true wenn ok, false im Fehlerfall - */ - public function delete($firma_id) - { - if(!is_numeric($firma_id)) - { - $this->errormsg = 'Firma_id ist ungueltig'; - return false; - } - - $qry = "SELECT * FROM public.tbl_firma WHERE firma_id='$firma_id'"; - - if($this->db_query($qry)) - return true; - else - { - $this->errormsg = 'Fehler beim Loeschen der Daten'; - return false; - } - } - - /** - * Laedt alle Firmen - * @return true wenn ok, false im Fehlerfall - */ - public function getAll() - { - $qry = "SElECT * FROM public.tbl_firma ORDER BY name"; - - if($this->db_query($qry)) - { - while($row = $this->db_fetch_object()) - { - $fa = new firma(); - - $fa->firma_id = $row->firma_id; - $fa->name = $row->name; - $fa->adresse = $row->adresse; - $fa->email = $row->email; - $fa->telefon = $row->telefon; - $fa->fax = $row->fax; - $fa->anmerkung = $row->anmerkung; - $fa->firmentyp_kurzbz = $row->firmentyp_kurzbz; - $fa->updateamum = $row->updateamum; - $fa->updatevon = $row->updatevon; - $fa->insertamum = $row->insertamum; - $fa->insertvon = $row->insertvon; - $fa->ext_id = $row->ext_id; - $fa->schule = ($row->schule=='t'?true:false); - $this->result[] = $fa; - } - return true; - } - else - { - $this->errormsg = 'Fehler beim Laden des Datensatzes'; - return false; - } - } - - /** - * Liefert alle vorhandenen Firmentypen - * @return true wenn ok, false im Fehlerfall - */ - public function getFirmenTypen() - { - $qry = "SELECT * FROM public.tbl_firmentyp ORDER BY firmentyp_kurzbz"; - - if($this->db_query($qry)) - { - while($row = $this->db_fetch_object()) - { - $fa = new firma(); - $fa->firmentyp_kurzbz = $row->firmentyp_kurzbz; - $fa->beschreibung = $row->beschreibung; - - $this->result[] = $fa; - } - return true; - } - else - { - $this->errormsg = 'Fehler beim Auslesen der Firmentypen'; - return false; - } - } - - /** - * Laedt alle Firmen eines bestimmen Firmentyps - * @return true wenn ok, false im Fehlerfall - */ - public function getFirmen($firmentyp_kurzbz='') - { - $qry = "SElECT * FROM public.tbl_firma"; - - if($firmentyp_kurzbz!='') - $qry.=" WHERE firmentyp_kurzbz='".addslashes($firmentyp_kurzbz)."'"; - $qry.=" ORDER BY name"; - - if($this->db_query($qry)) - { - while($row = $this->db_fetch_object()) - { - $fa = new firma(); - - $fa->firma_id = $row->firma_id; - $fa->name = $row->name; - $fa->adresse = $row->adresse; - $fa->email = $row->email; - $fa->telefon = $row->telefon; - $fa->fax = $row->fax; - $fa->anmerkung = $row->anmerkung; - $fa->firmentyp_kurzbz = $row->firmentyp_kurzbz; - $fa->updateamum = $row->updateamum; - $fa->updatevon = $row->updatevon; - $fa->insertamum = $row->insertamum; - $fa->insertvon = $row->insertvon; - $fa->ext_id = $row->ext_id; - $fa->schule = ($row->schule=='t'?true:false); - $this->result[] = $fa; - } - return true; - } - else - { - $this->errormsg = 'Fehler beim Laden des Datensatzes'; - return false; - } - } -} +, + * Andreas Oesterreicher and + * Rudolf Hangl and. + * Gerald Simane-Sequens < gerald.simane-sequens@technikum-wien.at>. + */ +/** + * Klasse firma + * @create 18-12-2006 + */ +require_once(dirname(__FILE__).'/basis_db.class.php'); + +class firma extends basis_db +{ + public $new; // boolean + public $result = array(); // adresse Objekt + + //Tabellenspalten + public $firma_id; // integer + public $name; // string + public $anmerkung; // string + public $ext_id; // integer + public $insertamum; // timestamp + public $insertvon; // bigint + public $updateamum; // timestamp + public $updatevon; // bigint + public $firmentyp_kurzbz; + public $schule; // boolean + // Neu in Rel. 2.0 + public $steuernummer; // string + public $gesperrt; // boolean + public $aktiv; // boolean + public $finanzamt; // string + + // firma_organisationseinheit + public $oe_kurzbz; // string + public $oe_parent_kurzbz; // string + public $firma_organisationseinheit_id; // integer + public $organisationseinheittyp_kurzbz; // string + + public $bezeichnung; // string + public $kundennummer; // integer + public $oe_aktiv; // boolean + public $mailverteiler; // string + + /** + * Konstruktor + * @param $firma_id ID der Firma die geladen werden soll (Default=null) + */ + public function __construct($firma_id=null) + { + parent::__construct(); + + if(!is_null($firma_id)) + $this->load($firma_id); + } + + /** + * Laedt die Firma mit der ID $firma_id + * @param $firma_id ID der zu ladenden Funktion + * @return true wenn ok, false im Fehlerfall + */ + public function load($firma_id) + { + if(!is_numeric($firma_id)) + { + $this->errormsg = 'Firma_id ist ungueltig'; + return false; + } + + $qry = "SElECT * FROM public.tbl_firma WHERE firma_id='$firma_id'"; + + if($this->db_query($qry)) + { + if($row = $this->db_fetch_object()) + { + $this->firma_id = $row->firma_id; + $this->name = $row->name; + $this->anmerkung = $row->anmerkung; + $this->firmentyp_kurzbz = $row->firmentyp_kurzbz; + $this->updateamum = $row->updateamum; + $this->updatevon = $row->updatevon; + $this->insertamum = $row->insertamum; + $this->insertvon = $row->insertvon; + $this->ext_id = $row->ext_id; + $this->schule = ($row->schule=='t'?true:false); + // Neu in Rel. 2.0 + $this->steuernummer = $row->steuernummer; + $this->gesperrt = ($row->gesperrt=='t'?true:false); + $this->aktiv = ($row->aktiv=='t'?true:false); + $this->finanzamt = $row->finanzamt; + + return true; + } + else + { + $this->errormsg = 'Datensatz wurde nicht gefunden'; + return false; + } + } + else + { + $this->errormsg = 'Fehler beim Laden des Datensatzes'; + return false; + } + } + + /** + * Prueft die Variablen auf Gueltigkeit + * @return true wenn ok, false im Fehlerfall + */ + protected function validate() + { + //Gesamtlaenge pruefen + if(mb_strlen($this->name)>128) + { + $this->errormsg = 'Name darf nicht länger als 128 Zeichen sein'; + return false; + } + if(mb_strlen($this->anmerkung)>256) + { + $this->errormsg = 'Anmerkung darf nicht länger 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 $firma_id aktualisiert + * @return true wenn ok, false im Fehlerfall + */ + public function save() + { + //Variablen pruefen + if(!$this->validate()) + return false; + + if($this->new) + { + //Neuen Datensatz einfuegen + $qry='INSERT INTO public.tbl_firma (name, anmerkung, + firmentyp_kurzbz, updateamum, updatevon, insertamum, insertvon, ext_id, schule,steuernummer, + gesperrt,aktiv,finanzamt) VALUES('. + $this->addslashes($this->name).', '. + $this->addslashes($this->anmerkung).', '. + $this->addslashes($this->firmentyp_kurzbz).', '. + $this->addslashes($this->updateamum).', '. + $this->addslashes($this->updatevon).', '. + $this->addslashes($this->insertamum).', '. + $this->addslashes($this->insertvon).', '. + $this->addslashes($this->ext_id).','. + ($this->schule?'true':'false').','. + $this->addslashes($this->steuernummer).', '. + ($this->gesperrt?'true':'false').','. + ($this->aktiv?'true':'false').','. + ($this->finanzamt?$this->addslashes($this->finanzamt):'null').' ); '; + } + else + { + //Updaten des bestehenden Datensatzes + + //Pruefen ob firma_id eine gueltige Zahl ist + if(!is_numeric($this->firma_id)) + { + $this->errormsg = 'firma_id muss eine gueltige Zahl sein'; + return false; + } + + $qry='UPDATE public.tbl_firma SET '. + 'firma_id='.$this->addslashes($this->firma_id).', '. + 'name='.$this->addslashes($this->name).', '. + 'anmerkung='.$this->addslashes($this->anmerkung).', '. + 'updateamum= now(), '. + 'updatevon='.$this->addslashes($this->updatevon).', '. + 'firmentyp_kurzbz='.$this->addslashes($this->firmentyp_kurzbz).', '. + 'schule='.($this->schule?'true':'false').', '. + 'steuernummer='.$this->addslashes($this->steuernummer).', '. + 'gesperrt='.($this->gesperrt?'true':'false').', '. + 'aktiv='.($this->aktiv?'true':'false').', '. + 'finanzamt='.($this->finanzamt?addslashes($this->finanzamt):'null').' '. + 'WHERE firma_id='.$this->addslashes($this->firma_id).';'; + } + + if($this->db_query($qry)) + { + if($this->new) + { + //Sequence lesen + $qry="SELECT currval('public.tbl_firma_firma_id_seq') as id;"; + if($this->db_query($qry)) + { + if($row = $this->db_fetch_object()) + { + $this->firma_id = $row->id; + $this->db_query('COMMIT'); + return true; + } + else + { + $this->errormsg = 'Fehler beim Auslesen der Sequence'; + $this->db_query('ROLLBACK'); + return false; + } + } + else + { + $this->errormsg = 'Fehler beim Auslesen der Sequence'; + $this->db_query('ROLLBACK'); + return false; + } + } + return true; + } + else + { + $this->errormsg = 'Fehler beim Speichern des Firma-Datensatzes'; + return false; + } + } + + /** + * Loescht den Datenensatz mit der ID die uebergeben wird + * @param $firma_id ID die geloescht werden soll + * @return true wenn ok, false im Fehlerfall + */ + public function delete($firma_id) + { + if(!is_numeric($firma_id)) + { + $this->errormsg = 'Firma_id ist ungueltig'; + return false; + } + + $qry = "SELECT * FROM public.tbl_firma WHERE firma_id='$firma_id'"; + + if($this->db_query($qry)) + return true; + else + { + $this->errormsg = 'Fehler beim Loeschen der Daten'; + return false; + } + } + + /** + * Laedt alle Firmen + * @return true wenn ok, false im Fehlerfall + */ + public function getAll() + { + $qry = "SElECT * FROM public.tbl_firma ORDER BY name"; + + if($this->db_query($qry)) + { + while($row = $this->db_fetch_object()) + { + $fa = new firma(); + + $fa->firma_id = $row->firma_id; + $fa->name = $row->name; + $fa->anmerkung = $row->anmerkung; + $fa->firmentyp_kurzbz = $row->firmentyp_kurzbz; + $fa->updateamum = $row->updateamum; + $fa->updatevon = $row->updatevon; + $fa->insertamum = $row->insertamum; + $fa->insertvon = $row->insertvon; + $fa->ext_id = $row->ext_id; + $fa->schule = ($row->schule=='t'?true:false); + // Neu in Rel. 2.0 + $fa->steuernummer = $row->steuernummer; + $fa->gesperrt = ($row->gesperrt=='t'?true:false); + $fa->aktiv = ($row->aktiv=='t'?true:false); + $fa->finanzamt = $row->finanzamt; + + $this->result[] = $fa; + } + return true; + } + else + { + $this->errormsg = 'Fehler beim Laden des Datensatzes'; + return false; + } + } + + /** + * Liefert alle vorhandenen Firmentypen + * @return true wenn ok, false im Fehlerfall + */ + public function getFirmenTypen() + { + $qry = "SELECT * FROM public.tbl_firmentyp ORDER BY firmentyp_kurzbz"; + + if($this->db_query($qry)) + { + while($row = $this->db_fetch_object()) + { + $fa = new firma(); + $fa->firmentyp_kurzbz = $row->firmentyp_kurzbz; + $fa->beschreibung = $row->beschreibung; + + $this->result[] = $fa; + } + return true; + } + else + { + $this->errormsg = 'Fehler beim Auslesen der Firmentypen'; + return false; + } + } + + /** + * Laedt alle Firmen eines bestimmen Firmentyps + * @return true wenn ok, false im Fehlerfall + */ + public function getFirmen($firmentyp_kurzbz='') + { + $qry = "SElECT * FROM public.tbl_firma"; + + if($firmentyp_kurzbz!='') + $qry.=" WHERE firmentyp_kurzbz='".addslashes($firmentyp_kurzbz)."'"; + $qry.=" ORDER BY name"; + + if($this->db_query($qry)) + { + while($row = $this->db_fetch_object()) + { + $fa = new firma(); + + $fa->firma_id = $row->firma_id; + $fa->name = $row->name; + $fa->anmerkung = $row->anmerkung; + $fa->firmentyp_kurzbz = $row->firmentyp_kurzbz; + $fa->updateamum = $row->updateamum; + $fa->updatevon = $row->updatevon; + $fa->insertamum = $row->insertamum; + $fa->insertvon = $row->insertvon; + $fa->ext_id = $row->ext_id; + $fa->schule = ($row->schule=='t'?true:false); + // Neu in Rel. 2.0 + $fa->steuernummer = $row->steuernummer; + $fa->gesperrt = ($row->gesperrt=='t'?true:false); + $fa->aktiv = ($row->aktiv=='t'?true:false); + $fa->finanzamt = $row->finanzamt; + + $this->result[] = $fa; + } + return true; + } + else + { + $this->errormsg = 'Fehler beim Laden des Datensatzes'; + return false; + } + } + + /** + * Laedt alle Firmen Standorte, und Adressen nach Suchstring und/oder eines bestimmen Firmentyps + * @return true wenn ok, false im Fehlerfall + */ + public function searchFirma($filter='',$firmentyp_kurzbz='') + { + $this->result = array(); + $this->errormsg = ''; + + $qry =" SElECT tbl_firma.* "; + $qry.=" ,tbl_standort.kurzbz,tbl_standort.adresse_id,tbl_standort.standort_id,tbl_standort.bezeichnung "; + $qry.=" ,person_id, tbl_adresse.name as adress_name, strasse, plz, ort, gemeinde,nation,typ,heimatadresse,zustelladresse "; + $qry.=" FROM public.tbl_firma, public.tbl_standort "; + $qry.=" left outer join public.tbl_adresse on ( tbl_adresse.adresse_id=tbl_standort.adresse_id ) "; + $qry.=" WHERE tbl_standort.firma_id=tbl_firma.firma_id "; + + if($filter!='') + $qry.= " and ( lower(tbl_firma.name) like lower('%$filter%') + OR lower(kurzbz) like lower('%$filter%') + + OR lower(tbl_adresse.name) like lower('%$filter%') + OR lower(plz) like lower('%$filter%') + OR lower(ort) like lower('%$filter%') + OR lower(strasse) like lower('%$filter%') + + OR lower(bezeichnung) like lower('%$filter%') + OR lower(anmerkung) like lower('%$filter%') + ".(is_numeric($filter)?" OR tbl_firma.firma_id='$filter'":'')." + ) "; + + if($firmentyp_kurzbz!='') + $qry.=" and firmentyp_kurzbz='".addslashes($firmentyp_kurzbz)."'"; + $qry.=" ORDER BY name "; + if($filter=='' && $firmentyp_kurzbz=='') + $qry.=" limit 500 "; + + if($this->db_query($qry)) + { + while($row = $this->db_fetch_object()) + { + $fa = new firma(); + + $fa->firma_id = $row->firma_id; + $fa->name = $row->name; + $fa->anmerkung = $row->anmerkung; + $fa->firmentyp_kurzbz = $row->firmentyp_kurzbz; + $fa->updateamum = $row->updateamum; + $fa->updatevon = $row->updatevon; + $fa->insertamum = $row->insertamum; + $fa->insertvon = $row->insertvon; + $fa->ext_id = $row->ext_id; + $fa->schule = ($row->schule=='t'?true:false); + // Neu in Rel. 2.0 + $fa->steuernummer = $row->steuernummer; + $fa->gesperrt = ($row->gesperrt=='t'?true:false); + $fa->aktiv = ($row->aktiv=='t'?true:false); + $fa->finanzamt = $row->finanzamt; + + // Standort + $fa->kurzbz = $row->kurzbz; + $fa->adresse_id = $row->adresse_id; + $fa->standort_id = $row->standort_id; + $fa->bezeichnung = $row->bezeichnung; + // Adresse + $fa->person_id = $row->person_id; + $fa->adresse_id = $row->adresse_id; + $fa->strasse = $row->strasse; + $fa->plz = $row->plz; + $fa->ort = $row->ort; + $fa->gemeinde = $row->gemeinde; + $fa->nation = $row->nation; + $fa->typ = $row->typ; + $fa->adress_name = $row->adress_name; + $fa->heimatadresse = ($row->heimatadresse=='t'?true:false); + $fa->zustelladresse = ($row->zustelladresse=='t'?true:false); + + $this->result[] = $fa; + } + return true; + } + else + { + $this->errormsg = 'Fehler beim Laden des Datensatzes'; + return false; + } + } + + /** + * Laedt alle Firmen - Organisationseinheiten nach Firmen ID und/oder OE Kurzbz und/oder Zwischentabellen ID + * @param $firma_id ID die gelesen werden soll + * @param $oe_kurzbz Organisationskurzbezeichnung + * @param $firma_organisationseinheit_id Zwischentabellen ID + * @return true wenn ok, false im Fehlerfall + */ + public function load_firmaorganisationseinheit($firma_id='',$oe_kurzbz='',$firma_organisationseinheit_id='') + { + $this->result = array(); + $this->errormsg = ''; + if($firma_id && !is_numeric($firma_id)) + { + $this->errormsg = 'Firma_id ist ungueltig'; + return false; + } + + $qry =" select tbl_firma.* "; + + $qry.=", tbl_firma_organisationseinheit.firma_organisationseinheit_id ,tbl_firma_organisationseinheit.kundennummer ,tbl_firma_organisationseinheit.oe_kurzbz "; + + $qry.=" ,tbl_organisationseinheit.oe_parent_kurzbz,tbl_organisationseinheit.bezeichnung,tbl_organisationseinheit.bezeichnung ,tbl_organisationseinheit.organisationseinheittyp_kurzbz,tbl_organisationseinheit.aktiv as oe_aktiv,tbl_organisationseinheit.mailverteiler "; + + $qry.=" FROM public.tbl_firma, public.tbl_firma_organisationseinheit "; + $qry.=" left outer join public.tbl_organisationseinheit on ( tbl_organisationseinheit.oe_kurzbz=tbl_firma_organisationseinheit.oe_kurzbz ) "; + $qry.=" WHERE tbl_firma.firma_id=tbl_firma_organisationseinheit.firma_id "; + + + if($firma_organisationseinheit_id!='') + $qry.=" and tbl_firma_organisationseinheit.firma_organisationseinheit_id='".addslashes($firma_organisationseinheit_id)."'"; + if($firma_id!='') + $qry.=" and tbl_firma_organisationseinheit.firma_id='".addslashes($firma_id)."'"; + if($oe_kurzbz!='') + $qry.=" and tbl_firma_organisationseinheit.oe_kurzbz='".addslashes($oe_kurzbz)."'"; + + $qry.=" ORDER BY tbl_firma_organisationseinheit.oe_kurzbz "; + + + if($this->db_query($qry)) + { + while($row = $this->db_fetch_object()) + { + $fa = new firma(); + + $fa->firma_id = $row->firma_id; + $fa->name = $row->name; + $fa->anmerkung = $row->anmerkung; + $fa->firmentyp_kurzbz = $row->firmentyp_kurzbz; + $fa->updateamum = $row->updateamum; + $fa->updatevon = $row->updatevon; + $fa->insertamum = $row->insertamum; + $fa->insertvon = $row->insertvon; + $fa->ext_id = $row->ext_id; + $fa->schule = ($row->schule=='t'?true:false); + // Neu in Rel. 2.0 + $fa->steuernummer = $row->steuernummer; + $fa->gesperrt = ($row->gesperrt=='t'?true:false); + $fa->aktiv = ($row->aktiv=='t'?true:false); + $fa->finanzamt = $row->finanzamt; + // firma_organisationseinheit + $fa->oe_kurzbz = $row->oe_kurzbz; + // organisationseinheit + $fa->firma_organisationseinheit_id = $row->firma_organisationseinheit_id; + $fa->oe_parent_kurzbz = $row->oe_parent_kurzbz; + $fa->organisationseinheittyp_kurzbz = $row->organisationseinheittyp_kurzbz; + $fa->bezeichnung = $row->bezeichnung; + $fa->kundennummer = $row->kundennummer; + + $fa->oe_aktiv = $row->oe_aktiv; + $fa->mailverteiler = $row->mailverteiler; + + $this->result[] = $fa; + } + return true; + } + else + { + $this->errormsg = 'Fehler beim Laden des Datensatzes'; + return false; + } + } + + + +} ?> \ No newline at end of file diff --git a/include/kontakt.class.php b/include/kontakt.class.php index 3adf0b72e..72f52c856 100644 --- a/include/kontakt.class.php +++ b/include/kontakt.class.php @@ -1,333 +1,408 @@ -, - * Andreas Oesterreicher and - * Rudolf Hangl . - */ -/** - * Klasse kontakt - * @create 20-12-2006 - */ -require_once(dirname(__FILE__).'/basis_db.class.php'); - -class kontakt extends basis_db -{ - public $new; // boolean - public $result = array(); // adresse Objekt - - //Tabellenspalten - public $kontakt_id; // integer - public $person_id; // integer - public $firma_id; // integer - public $kontakttyp; // string - public $anmerkung; // string - public $kontakt; // string - public $zustellung; // boolean - public $ext_id; // integer - public $insertamum; // timestamp - public $insertvon; // bigint - public $updateamum; // timestamp - public $updatevon; // bigint - - public $beschreibung; - public $firma_name; - - /** - * Konstruktor - * @param $kontakt_id ID der Adresse die geladen werden soll (Default=null) - */ - public function __construct($kontakt_id=null) - { - parent::__construct(); - - if(!is_null($kontakt_id)) - $this->load($kontakt_id); - } - - /** - * Laedt einen Kontakt mit der ID $kontakt_id - * @param $kontakt_id ID des zu ladenden Kontaktes - * @return true wenn ok, false im Fehlerfall - */ - public function load($kontakt_id) - { - if(!is_numeric($kontakt_id)) - { - $this->errormsg = 'Kontakt_id ist ungueltig'; - return false; - } - - $qry = "SELECT tbl_kontakt.*, tbl_firma.name as firma_name - FROM public.tbl_kontakt LEFT JOIN public.tbl_firma USING(firma_id) WHERE kontakt_id='$kontakt_id'"; - - if($this->db_query($qry)) - { - if($row = $this->db_fetch_object()) - { - $this->kontakt_id = $row->kontakt_id; - $this->person_id = $row->person_id; - $this->firma_id = $row->firma_id; - $this->firma_name = $row->firma_name; - $this->kontakttyp = $row->kontakttyp; - $this->anmerkung = $row->anmerkung; - $this->kontakt = $row->kontakt; - $this->zustellung = ($row->zustellung=='t'?true:false); - $this->updateamum = $row->updateamum; - $this->updatevon = $row->updatevon; - $this->insertamum = $row->insertamum; - $this->insertvon = $row->insertvon; - $this->ext_id = $row->ext_id; - return true; - } - else - { - $this->errormsg = 'Datensatz wurde nicht gefunden'; - return false; - } - } - else - { - $this->errormsg = 'Fehler beim Laden der Daten'; - return false; - } - } - - /** - * Prueft die Variablen auf Gueltigkeit - * @return true wenn ok, false im Fehlerfall - */ - public function validate() - { - - //Gesamtlaenge pruefen - //$this->errormsg='Eine der Gesamtlaengen wurde ueberschritten'; - if(mb_strlen($this->kontakttyp)>32) - { - $this->errormsg = 'kontakttyp darf nicht länger als 32 Zeichen sein'; - return false; - } - if(mb_strlen($this->anmerkung)>64) - { - $this->errormsg = 'anmerkung darf nicht länger als 64 Zeichen sein'; - return false; - } - if(mb_strlen($this->kontakt)>128) - { - $this->errormsg = 'kontakt darf nicht länger als 128 Zeichen sein'; - return false; - } - if($this->kontakttyp=='email' && !strstr($this->kontakt, '@')) - { - $this->errormsg = 'Wenn der Typ E-Mail ausgewählt wurde, muss der Kontakt ein @ enthalten!'; - 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 $kontakt_id aktualisiert - * @return true wenn ok, false im Fehlerfall - */ - public function save() - { - //Variablen pruefen - if(!$this->validate()) - return false; - - if($this->new) - { - //Neuen Datensatz einfuegen - - $qry='BEGIN;INSERT INTO public.tbl_kontakt (person_id, firma_id, kontakttyp, anmerkung, kontakt, zustellung, ext_id, insertamum, insertvon, updateamum, updatevon) VALUES('. - $this->addslashes($this->person_id).', '. - $this->addslashes($this->firma_id).', '. - $this->addslashes($this->kontakttyp).', '. - $this->addslashes($this->anmerkung).', '. - $this->addslashes($this->kontakt).', '. - ($this->zustellung?'true':'false').', '. - $this->addslashes($this->ext_id).', now(), '. - $this->addslashes($this->insertvon).', now(), '. - $this->addslashes($this->updatevon).');'; - } - else - { - //Updaten des bestehenden Datensatzes - - //Pruefen ob kontakt_id eine gueltige Zahl ist - if(!is_numeric($this->kontakt_id)) - { - $this->errormsg = 'kontakt_id muss eine gueltige Zahl sein'; - return false; - } - - $qry='UPDATE public.tbl_kontakt SET '. - 'person_id='.$this->addslashes($this->person_id).', '. - 'firma_id='.$this->addslashes($this->firma_id).', '. - 'kontakttyp='.$this->addslashes($this->kontakttyp).', '. - 'anmerkung='.$this->addslashes($this->anmerkung).', '. - 'kontakt='.$this->addslashes($this->kontakt).', '. - 'zustellung='.($this->zustellung?'true':'false').', '. - 'ext_id='.$this->addslashes($this->ext_id).', '. - 'updateamum= now(), '. - 'updatevon='.$this->addslashes($this->updatevon).' '. - 'WHERE kontakt_id='.$this->addslashes($this->kontakt_id).';'; - } - - if($this->db_query($qry)) - { - //Sequence auslesen um die eingefuegte ID zu ermitteln - if($this->new) - { - $qry = "SELECT currval('public.tbl_kontakt_kontakt_id_seq') as id"; - - if($this->db_query($qry)) - { - if($row = $this->db_fetch_object()) - { - $this->kontakt_id = $row->id; - $this->db_query('COMMIT'); - return true; - } - else - { - $this->errormsg = 'Fehler beim Auslesen er Sequence'; - $this->db_query('ROLLBACK'); - return false; - } - } - else - { - $this->errormsg = 'Fehler beim Auslesen der Sequence'; - $this->db_query('ROLLBACK'); - return false; - } - } - return true; - } - else - { - $this->errormsg = 'Fehler beim Speichern der Daten'; - return false; - } - } - - /** - * Loescht den Datenensatz mit der ID die uebergeben wird - * @param $kontakt_id ID die geloescht werden soll - * @return true wenn ok, false im Fehlerfall - */ - public function delete($kontakt_id) - { - if(!is_numeric($kontakt_id)) - { - $this->errormsg = 'Kontakt_id ist ungueltig'; - return false; - } - - $qry = "DELETE FROM public.tbl_kontakt WHERE kontakt_id='$kontakt_id'"; - - if($this->db_query($qry)) - return true; - else - { - $this->errormsg = 'Fehler beim Loeschen der Daten'; - return false; - } - } - - /** - * Laedt alle Kontaktdaten einer Person - * @param person_id - * @return boolean - */ - public function load_pers($person_id) - { - if(!is_numeric($person_id)) - { - $this->errormsg = 'Person_id ist ungueltig'; - return false; - } - - $qry = "SELECT tbl_kontakt.*, tbl_firma.name as firma_name - FROM public.tbl_kontakt LEFT JOIN public.tbl_firma USING(firma_id) WHERE person_id='$person_id'"; - - if($this->db_query($qry)) - { - while($row = $this->db_fetch_object()) - { - $obj = new kontakt(); - - $obj->kontakt_id = $row->kontakt_id; - $obj->person_id = $row->person_id; - $obj->firma_id = $row->firma_id; - $obj->firma_name = $row->firma_name; - $obj->kontakttyp = $row->kontakttyp; - $obj->anmerkung = $row->anmerkung; - $obj->kontakt = $row->kontakt; - $obj->zustellung = ($row->zustellung=='t'?true:false); - $obj->updateamum = $row->updateamum; - $obj->updatevon = $row->updatevon; - $obj->insertamum = $row->insertamum; - $obj->insertvon = $row->insertvon; - $obj->ext_id = $row->ext_id; - - $this->result[] = $obj; - } - - return true; - } - else - { - $this->errormsg = 'Fehler beim Laden der Daten'; - return false; - } - } - - /** - * Laedt alle Kontakttypen - * @return true wenn ok - * false im Fehlerfall - */ - public function getKontakttyp() - { - $qry = "SELECT * FROM public.tbl_kontakttyp ORDER BY beschreibung"; - - if($this->db_query($qry)) - { - while($row = $this->db_fetch_object()) - { - $obj = new kontakt(); - - $obj->kontakttyp = $row->kontakttyp; - $obj->beschreibung = $row->beschreibung; - - $this->result[] = $obj; - } - return true; - } - else - { - $this->errormsg = 'Fehler beim Laden der Daten'; - return false; - } - } -} +, + * Andreas Oesterreicher and + * Rudolf Hangl . + */ +/** + * Klasse kontakt + * @create 20-12-2006 + */ +require_once(dirname(__FILE__).'/basis_db.class.php'); + +class kontakt extends basis_db +{ + public $new; // boolean + public $result = array(); // adresse Objekt + + //Tabellenspalten + public $kontakt_id; // integer + public $person_id; // integer + public $firma_id; // integer + public $standort_id; // integer + + public $kontakttyp; // string + public $anmerkung; // string + public $kontakt; // string + public $zustellung; // boolean + public $ext_id; // integer + public $insertamum; // timestamp + public $insertvon; // bigint + public $updateamum; // timestamp + public $updatevon; // bigint + + public $beschreibung; + public $firma_name; + + + public $anrede; + public $titelpost; + public $titelpre; + public $nachname; + public $vorname; + public $vornamen; + + /** + * Konstruktor + * @param $kontakt_id ID der Adresse die geladen werden soll (Default=null) + */ + public function __construct($kontakt_id=null) + { + parent::__construct(); + + if(!is_null($kontakt_id)) + $this->load($kontakt_id); + } + + /** + * Laedt einen Kontakt mit der ID $kontakt_id + * @param $kontakt_id ID des zu ladenden Kontaktes + * @return true wenn ok, false im Fehlerfall + */ + public function load($kontakt_id) + { + if(!is_numeric($kontakt_id)) + { + $this->errormsg = 'Kontakt_id ist ungueltig'; + return false; + } + + $qry = "SELECT tbl_kontakt.*, tbl_firma.name as firma_name + FROM public.tbl_kontakt LEFT JOIN public.tbl_firma USING(firma_id) WHERE kontakt_id='$kontakt_id'"; + + if($this->db_query($qry)) + { + if($row = $this->db_fetch_object()) + { + $this->kontakt_id = $row->kontakt_id; + $this->person_id = $row->person_id; + $this->standort_id = $row->standort_id; + $this->firma_id = $row->firma_id; + $this->firma_name = $row->firma_name; + $this->kontakttyp = $row->kontakttyp; + $this->anmerkung = $row->anmerkung; + $this->kontakt = $row->kontakt; + $this->zustellung = ($row->zustellung=='t'?true:false); + $this->updateamum = $row->updateamum; + $this->updatevon = $row->updatevon; + $this->insertamum = $row->insertamum; + $this->insertvon = $row->insertvon; + $this->ext_id = $row->ext_id; + return true; + } + else + { + $this->errormsg = 'Datensatz wurde nicht gefunden'; + return false; + } + } + else + { + $this->errormsg = 'Fehler beim Laden der Daten'; + return false; + } + } + + /** + * Prueft die Variablen auf Gueltigkeit + * @return true wenn ok, false im Fehlerfall + */ + public function validate() + { + + //Gesamtlaenge pruefen + //$this->errormsg='Eine der Gesamtlaengen wurde ueberschritten'; + if(mb_strlen($this->kontakttyp)>32) + { + $this->errormsg = 'kontakttyp darf nicht länger als 32 Zeichen sein'; + return false; + } + if(mb_strlen($this->anmerkung)>64) + { + $this->errormsg = 'anmerkung darf nicht länger als 64 Zeichen sein'; + return false; + } + if(mb_strlen($this->kontakt)>128) + { + $this->errormsg = 'kontakt darf nicht länger als 128 Zeichen sein'; + return false; + } + if($this->kontakttyp=='email' && !strstr($this->kontakt, '@')) + { + $this->errormsg = 'Wenn der Typ E-Mail ausgewählt wurde, muss der Kontakt ein @ enthalten!'; + 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 $kontakt_id aktualisiert + * @return true wenn ok, false im Fehlerfall + */ + public function save() + { + //Variablen pruefen + if(!$this->validate()) + return false; + + if($this->new) + { + //Neuen Datensatz einfuegen + $qry='BEGIN;INSERT INTO public.tbl_kontakt (person_id, firma_id,standort_id, kontakttyp, anmerkung, kontakt, zustellung, ext_id, insertamum, insertvon, updateamum, updatevon) VALUES('. + $this->addslashes($this->person_id).', '. + $this->addslashes($this->firma_id).', '. + $this->addslashes($this->standort_id).', '. + $this->addslashes($this->kontakttyp).', '. + $this->addslashes($this->anmerkung).', '. + $this->addslashes($this->kontakt).', '. + ($this->zustellung?'true':'false').', '. + $this->addslashes($this->ext_id).', now(), '. + $this->addslashes($this->insertvon).', now(), '. + $this->addslashes($this->updatevon).');'; + } + else + { + //Updaten des bestehenden Datensatzes + + //Pruefen ob kontakt_id eine gueltige Zahl ist + if(!is_numeric($this->kontakt_id)) + { + $this->errormsg = 'kontakt_id muss eine gueltige Zahl sein'; + return false; + } + $qry='UPDATE public.tbl_kontakt SET '. + 'person_id='.$this->addslashes($this->person_id).', '. + 'firma_id='.$this->addslashes($this->firma_id).', '. + 'standort_id='.$this->addslashes($this->standort_id).', '. + 'kontakttyp='.$this->addslashes($this->kontakttyp).', '. + 'anmerkung='.$this->addslashes($this->anmerkung).', '. + 'kontakt='.$this->addslashes($this->kontakt).', '. + 'zustellung='.($this->zustellung?'true':'false').', '. + 'ext_id='.$this->addslashes($this->ext_id).', '. + 'updateamum= now(), '. + 'updatevon='.$this->addslashes($this->updatevon).' '. + 'WHERE kontakt_id='.$this->addslashes($this->kontakt_id).';'; + } + + if($this->db_query($qry)) + { + //Sequence auslesen um die eingefuegte ID zu ermitteln + if($this->new) + { + $qry = "SELECT currval('public.tbl_kontakt_kontakt_id_seq') as id"; + + if($this->db_query($qry)) + { + if($row = $this->db_fetch_object()) + { + $this->kontakt_id = $row->id; + $this->db_query('COMMIT'); + return true; + } + else + { + $this->errormsg = 'Fehler beim Auslesen er Sequence'; + $this->db_query('ROLLBACK'); + return false; + } + } + else + { + $this->errormsg = 'Fehler beim Auslesen der Sequence'; + $this->db_query('ROLLBACK'); + return false; + } + } + return true; + } + else + { + $this->errormsg = 'Fehler beim Speichern der Daten'; + return false; + } + } + + /** + * Loescht den Datenensatz mit der ID die uebergeben wird + * @param $kontakt_id ID die geloescht werden soll + * @return true wenn ok, false im Fehlerfall + */ + public function delete($kontakt_id) + { + if(!is_numeric($kontakt_id)) + { + $this->errormsg = 'Kontakt_id ist ungueltig'; + return false; + } + + $qry = "DELETE FROM public.tbl_kontakt WHERE kontakt_id='$kontakt_id'"; + + if($this->db_query($qry)) + return true; + else + { + $this->errormsg = 'Fehler beim Loeschen der Daten'; + return false; + } + } + + /** + * Laedt alle Kontaktdaten einer Person + * @param person_id + * @return boolean + */ + public function load_pers($person_id) + { + if(!is_numeric($person_id)) + { + $this->errormsg = 'Person_id ist ungueltig'; + return false; + } + + $qry = "SELECT tbl_kontakt.*, tbl_firma.name as firma_name + FROM public.tbl_kontakt LEFT JOIN public.tbl_firma USING(firma_id) WHERE person_id='$person_id'"; + + if($this->db_query($qry)) + { + while($row = $this->db_fetch_object()) + { + $obj = new kontakt(); + + $obj->kontakt_id = $row->kontakt_id; + $obj->person_id = $row->person_id; + $obj->standort_id = $row->standort_id; + $obj->firma_id = $row->firma_id; + $obj->firma_name = $row->firma_name; + $obj->kontakttyp = $row->kontakttyp; + $obj->anmerkung = $row->anmerkung; + $obj->kontakt = $row->kontakt; + $obj->zustellung = ($row->zustellung=='t'?true:false); + $obj->updateamum = $row->updateamum; + $obj->updatevon = $row->updatevon; + $obj->insertamum = $row->insertamum; + $obj->insertvon = $row->insertvon; + $obj->ext_id = $row->ext_id; + + $this->result[] = $obj; + } + + return true; + } + else + { + $this->errormsg = 'Fehler beim Laden der Daten'; + return false; + } + } + /** + * Laedt alle Kontaktdaten zu einem Standort + * @param standort_id + * @return boolean + */ + public function load_standort($standort_id='',$firma_id='') + { + if(!is_numeric($standort_id)) + { + $this->errormsg = 'Standort ist ungueltig'; + return false; + } + + $qry = "SELECT tbl_kontakt.*, tbl_standort.kurzbz as standort_kurzbz, tbl_standort.bezeichnung as standort_bezeichnung + ,tbl_person.anrede,tbl_person.titelpost,tbl_person.titelpre,tbl_person.nachname,tbl_person.vorname,tbl_person.vornamen + FROM public.tbl_kontakt + LEFT JOIN public.tbl_standort USING(standort_id,firma_id) + LEFT JOIN public.tbl_person USING(person_id) + WHERE standort_id>0 + "; + if(is_numeric($standort_id)) + $qry.=" and standort_id='".addslashes($standort_id)."'"; + if(is_numeric($firma_id)) + $qry.=" and tbl_kontakt.firma_id='".addslashes($firma_id)."'"; + + if($this->db_query($qry)) + { + while($row = $this->db_fetch_object()) + { + $obj = new kontakt(); + + $obj->kontakt_id = $row->kontakt_id; + $obj->person_id = $row->person_id; + $obj->standort_id = $row->standort_id; + $obj->firma_id = $row->firma_id; + $obj->standort_kurzbz = $row->standort_kurzbz; + $obj->standort_bezeichnung = $row->standort_bezeichnung; + $obj->kontakttyp = $row->kontakttyp; + $obj->anmerkung = $row->anmerkung; + $obj->kontakt = $row->kontakt; + $obj->zustellung = ($row->zustellung=='t'?true:false); + $obj->updateamum = $row->updateamum; + $obj->updatevon = $row->updatevon; + $obj->insertamum = $row->insertamum; + $obj->insertvon = $row->insertvon; + $obj->ext_id = $row->ext_id; + $obj->anrede=$row->anrede; + $obj->titelpost=$row->titelpost; + $obj->titelpre=$row->titelpre; + $obj->nachname=$row->nachname; + $obj->vorname=$row->vorname; + $obj->vornamen=$row->vornamen; + $this->result[] = $row; + } + + return true; + } + else + { + $this->errormsg = 'Fehler beim Laden der Daten'; + return false; + } + } + + /** + * Laedt alle Kontakttypen + * @return true wenn ok + * false im Fehlerfall + */ + public function getKontakttyp() + { + $qry = "SELECT * FROM public.tbl_kontakttyp ORDER BY beschreibung"; + + if($this->db_query($qry)) + { + while($row = $this->db_fetch_object()) + { + $obj = new kontakt(); + + $obj->kontakttyp = $row->kontakttyp; + $obj->beschreibung = $row->beschreibung; + + $this->result[] = $obj; + } + return true; + } + else + { + $this->errormsg = 'Fehler beim Laden der Daten'; + return false; + } + } +} ?> \ No newline at end of file diff --git a/include/moodle_course.class.php b/include/moodle_course.class.php index 94a5b1af3..98a91cbe9 100644 --- a/include/moodle_course.class.php +++ b/include/moodle_course.class.php @@ -1566,6 +1566,7 @@ class moodle_course extends basis_db } } } + var_dump($courses); return $courses; } diff --git a/include/ort.class.php b/include/ort.class.php index ee06b9e63..104fe07fa 100644 --- a/include/ort.class.php +++ b/include/ort.class.php @@ -43,7 +43,7 @@ class ort extends basis_db public $kosten; // numeric(8,2) public $ausstattung; public $stockwerk; // integer - public $standort_kurzbz; // varchar(16) + public $standort_id; // varchar(16) public $telefonklappe; // varchar(8) /** @@ -89,7 +89,7 @@ class ort extends basis_db $ort_obj->reservieren = ($row->reservieren=='t'?true:false); $ort_obj->ausstattung = $row->ausstattung; $ort_obj->stockwerk = $row->stockwerk; - $ort_obj->standort_kurzbz = $row->standort_kurzbz; + $ort_obj->standort_id = $row->standort_id; $ort_obj->telefonklappe = $row->telefonklappe; $this->result[] = $ort_obj; @@ -110,7 +110,7 @@ class ort extends basis_db return false; } - $qry = "SELECT * FROM public.tbl_ort WHERE ort_kurzbz = '".addslashes($ort_kurzbz)."';"; + $qry = "SELECT * FROM public.tbl_ort WHERE trim(ort_kurzbz) = '".addslashes(trim($ort_kurzbz))."';"; if(!$this->db_query($qry)) { @@ -132,7 +132,7 @@ class ort extends basis_db $this->reservieren = ($row->reservieren=='t'?true:false); $this->ausstattung = $row->ausstattung; $this->stockwerk = $row->stockwerk; - $this->standort_kurzbz = $row->standort_kurzbz; + $this->standort_id = $row->standort_id; $this->telefonklappe = $row->telefonklappe; } else @@ -189,7 +189,7 @@ class ort extends basis_db { //Neuen Datensatz anlegen $qry = 'INSERT INTO public.tbl_ort (ort_kurzbz, bezeichnung, planbezeichnung, max_person, aktiv, lehre, reservieren, lageplan, - dislozierung, kosten, stockwerk, standort_kurzbz, telefonklappe) VALUES ('. + dislozierung, kosten, stockwerk, standort_id, telefonklappe) VALUES ('. $this->addslashes($this->ort_kurzbz).', '. $this->addslashes($this->bezeichnung).', '. $this->addslashes($this->planbezeichnung).', '. @@ -201,7 +201,7 @@ class ort extends basis_db $this->addslashes($this->dislozierung).', '. $this->addslashes(str_replace(",",".",$this->kosten)).', '. $this->addslashes($this->stockwerk).','. - $this->addslashes($this->standort_kurzbz).','. + $this->addslashes($this->standort_id).','. $this->addslashes($this->telefonklappe).');'; } else @@ -218,7 +218,7 @@ class ort extends basis_db 'lageplan='.$this->addslashes($this->lageplan).', '. 'dislozierung='.$this->addslashes($this->dislozierung).', '. 'kosten='.$this->addslashes(str_replace(",",".",$this->kosten)).', '. - 'standort_kurzbz='.$this->addslashes($this->standort_kurzbz).', '. + 'standort_id='.$this->addslashes($this->standort_id).', '. 'telefonklappe='.$this->addslashes($this->telefonklappe).', '. 'stockwerk='.$this->addslashes($this->stockwerk).' '. 'WHERE ort_kurzbz = '.$this->addslashes($this->ort_kurzbz).';'; @@ -314,7 +314,7 @@ class ort extends basis_db $ort_obj->reservieren = ($row->reservieren=='t'?true:false); $ort_obj->ausstattung = $row->ausstattung; $ort_obj->stockwerk = $row->stockwerk; - $ort_obj->standort_kurzbz = $row->standort_kurzbz; + $ort_obj->standort_id = $row->standort_id; $ort_obj->telefonklappe = $row->telefonklappe; $this->result[] = $ort_obj; diff --git a/include/person.class.php b/include/person.class.php index 3058cf83c..9c6d46ed2 100644 --- a/include/person.class.php +++ b/include/person.class.php @@ -536,6 +536,109 @@ class person extends basis_db } return true; } + + + + /** + * Laedt alle standorte zu einer Person die dem Standort zugeordnet sind + * @param $standort_id ID des Standortes + * @param $person_id ID der Person die Zugeordnet ist + * @param $firma_id ID der Firma zu der die standortn geladen werden sollen + * @return true wenn ok, false im Fehlerfall + */ + public function load_personfunktion($standort_id='',$person_id='',$firma_id='',$funktion_kurzbz='',$personfunktionstandort_id='') + { + $this->result=array(); + $this->errormsg = ''; + + //Lesen der Daten aus der Datenbank + $qry=" SELECT tbl_person.* + ,tbl_personfunktionstandort.personfunktionstandort_id,tbl_personfunktionstandort.person_id ,tbl_personfunktionstandort.funktion_kurzbz ,tbl_personfunktionstandort.standort_id + ,tbl_personfunktionstandort.position,tbl_personfunktionstandort.anrede + ,tbl_standort.adresse_id,tbl_standort.kurzbz,tbl_standort.bezeichnung,tbl_standort.firma_id + ,tbl_funktion.beschreibung as funktion_beschreibung , tbl_funktion.aktiv as funktion_aktiv,tbl_funktion.fachbereich as funktion_fachbereich,tbl_funktion.semester as funktion_semester + "; + $qry.=" FROM public.tbl_person,public.tbl_personfunktionstandort + LEFT JOIN public.tbl_standort USING(standort_id) + LEFT JOIN public.tbl_funktion USING(funktion_kurzbz) + "; + $qry.=" WHERE tbl_person.person_id=tbl_personfunktionstandort.person_id"; + if($personfunktionstandort_id!='') + $qry.=" and tbl_personfunktionstandort.personfunktionstandort_id='".addslashes($personfunktionstandort_id)."'"; + if(is_numeric($standort_id)) + $qry.=" and tbl_personfunktionstandort.standort_id='".addslashes($standort_id)."'"; + if(is_numeric($person_id)) + $qry.=" and tbl_personfunktionstandort.person_id='".addslashes($person_id)."'"; + if(is_numeric($firma_id)) + $qry.=" and public.tbl_standort.firma_id='".addslashes($firma_id)."'"; + if($funktion_kurzbz!='') + $qry.=" and tbl_personfunktionstandort.funktion_kurzbz='".addslashes($funktion_kurzbz)."'"; + + + + if(!$this->db_query($qry)) + { + $this->errormsg = 'Fehler bei einer Datenbankabfrage'; + return false; + } + + while($row = $this->db_fetch_object()) + { + $adr_obj = new person(); + $adr_obj->person_id = $row->person_id; + $adr_obj->staatsbuergerschaft = $row->staatsbuergerschaft; + $adr_obj->geburtsnation = $row->geburtsnation; + $adr_obj->sprache = $row->sprache; + $adr_obj->anrede = $row->anrede; + $adr_obj->titelpost = $row->titelpost; + $adr_obj->titelpre = $row->titelpre; + $adr_obj->nachname = $row->nachname; + $adr_obj->vorname = $row->vorname; + $adr_obj->vornamen = $row->vornamen; + $adr_obj->gebdatum = $row->gebdatum; + $adr_obj->gebort = $row->gebort; + $adr_obj->gebzeit = $row->gebzeit; + $adr_obj->foto = $row->foto; + $adr_obj->anmerkungen = $row->anmerkung; + $adr_obj->homepage = $row->homepage; + $adr_obj->svnr = $row->svnr; + $adr_obj->ersatzkennzeichen = $row->ersatzkennzeichen; + $adr_obj->familienstand = $row->familienstand; + $adr_obj->geschlecht = $row->geschlecht; + $adr_obj->anzahlkinder = $row->anzahlkinder; + $adr_obj->aktiv = $row->aktiv; + $adr_obj->updateamum = $row->updateamum; + $adr_obj->updatevon = $row->updatevon; + $adr_obj->insertamum = $row->insertamum; + $adr_obj->insertvon = $row->insertvon; + $adr_obj->ext_id = $row->ext_id; + $adr_obj->kurzbeschreibung = $row->kurzbeschreibung; + + + $adr_obj->standort_id = $row->standort_id; + $adr_obj->adresse_id = $row->adresse_id; + $adr_obj->kurzbz = $row->kurzbz; + $adr_obj->bezeichnung = $row->bezeichnung; + $adr_obj->firma_id = $row->firma_id; + + $adr_obj->personfunktionstandort_id = $row->personfunktionstandort_id; + + $adr_obj->funktion_kurzbz = $row->funktion_kurzbz; + + $adr_obj->position = $row->position; + $adr_obj->anrede = $row->anrede; + + $adr_obj->funktion_beschreibung = $row->funktion_beschreibung; + $adr_obj->funktion_aktiv = ($row->funktion_aktiv=='t'?true:false); + $adr_obj->funktion_fachbereich = $row->funktion_fachbereich; + $adr_obj->funktion_semester = $row->funktion_semester; + + $this->result[] = $adr_obj; + } + return true; + } + + } ?> \ No newline at end of file diff --git a/include/tw/cis_menu_main.inc.php b/include/tw/cis_menu_main.inc.php index 196abd3ae..80e24598c 100644 --- a/include/tw/cis_menu_main.inc.php +++ b/include/tw/cis_menu_main.inc.php @@ -314,7 +314,7 @@   - menu item Unternehmens-
   kommunikation
+ menu item Unternehmens-
   kommunikation
@@ -581,7 +581,7 @@ - + @@ -611,10 +611,13 @@