From f647ad4ae1c38612335a5b6eca143038ea27ad45 Mon Sep 17 00:00:00 2001 From: Stefan Puraner Date: Wed, 2 Mar 2016 15:04:12 +0100 Subject: [PATCH] bugfixes --- include/lehrveranstaltung.class.php | 33 +- include/organisationseinheit.class.php | 1508 ++++++++++++------------ include/studienordnung.class.php | 6 +- system/dbupdate_3.2.php | 25 +- 4 files changed, 807 insertions(+), 765 deletions(-) diff --git a/include/lehrveranstaltung.class.php b/include/lehrveranstaltung.class.php index 795715538..79cfc24b3 100644 --- a/include/lehrveranstaltung.class.php +++ b/include/lehrveranstaltung.class.php @@ -66,6 +66,7 @@ class lehrveranstaltung extends basis_db public $bezeichnung_arr = array(); public $semester_alternativ; // smallint public $farbe; + public $lehrauftrag=true; public $studienplan_lehrveranstaltung_id; public $studienplan_lehrveranstaltung_id_parent; @@ -82,6 +83,7 @@ class lehrveranstaltung extends basis_db public $benotung=false; public $lvinfo=false; public $curriculum=true; + public $export=true; /** * Konstruktor @@ -161,6 +163,7 @@ class lehrveranstaltung extends basis_db $this->benotung = $this->db_parse_bool($row->benotung); $this->lvinfo = $this->db_parse_bool($row->lvinfo); + $this->lehrauftrag = $this->db_parse_bool($row->lehrauftrag); $this->bezeichnung_arr['German'] = $this->bezeichnung; $this->bezeichnung_arr['English'] = $this->bezeichnung_english; @@ -229,6 +232,7 @@ class lehrveranstaltung extends basis_db $lv_obj->benotung = $this->db_parse_bool($row->benotung); $lv_obj->lvinfo = $this->db_parse_bool($row->lvinfo); + $lv_obj->lehrauftrag = $this->db_parse_bool($row->lehrauftrag); $lv_obj->bezeichnung_arr['German'] = $row->bezeichnung; $lv_obj->bezeichnung_arr['English'] = $row->bezeichnung_english; @@ -363,6 +367,7 @@ class lehrveranstaltung extends basis_db $lv_obj->farbe = $row->farbe; $lv_obj->benotung = $this->db_parse_bool($row->benotung); $lv_obj->lvinfo = $this->db_parse_bool($row->lvinfo); + $lv_obj->lehrauftrag = $this->db_parse_bool($row->lehrauftrag); $lv_obj->bezeichnung_arr['German'] = $row->bezeichnung; $lv_obj->bezeichnung_arr['English'] = $row->bezeichnung_english; @@ -492,6 +497,7 @@ class lehrveranstaltung extends basis_db $lv_obj->farbe = $row->farbe; $lv_obj->benotung = $this->db_parse_bool($row->benotung); $lv_obj->lvinfo = $this->db_parse_bool($row->lvinfo); + $lv_obj->lehrauftrag = $this->db_parse_bool($row->lehrauftrag); $lv_obj->bezeichnung_arr['German'] = $row->bezeichnung; $lv_obj->bezeichnung_arr['English'] = $row->bezeichnung_english; @@ -572,6 +578,7 @@ class lehrveranstaltung extends basis_db $lv_obj->farbe = $row->farbe; $lv_obj->benotung = $this->db_parse_bool($row->benotung); $lv_obj->lvinfo = $this->db_parse_bool($row->lvinfo); + $lv_obj->lehrauftrag = $this->db_parse_bool($row->lehrauftrag); $lv_obj->bezeichnung_arr['German'] = $row->bezeichnung; $lv_obj->bezeichnung_arr['English'] = $row->bezeichnung_english; @@ -730,7 +737,7 @@ class lehrveranstaltung extends basis_db semester, ects, semesterstunden, anmerkung, lehre, lehreverzeichnis, aktiv, insertamum, insertvon, planfaktor, planlektoren, planpersonalkosten, plankostenprolektor, updateamum, updatevon, sort, zeugnis, projektarbeit, sprache, koordinator, bezeichnung_english, orgform_kurzbz, incoming, lehrtyp_kurzbz, oe_kurzbz, - raumtyp_kurzbz, anzahlsemester, semesterwochen, lvnr, semester_alternativ, farbe,sws,lvs,alvs,lvps,las,benotung,lvinfo) VALUES (' . + raumtyp_kurzbz, anzahlsemester, semesterwochen, lvnr, semester_alternativ, farbe,sws,lvs,alvs,lvps,las,benotung,lvinfo, lehrauftrag) VALUES (' . $this->db_add_param($this->studiengang_kz) . ', ' . $this->db_add_param($this->bezeichnung) . ', ' . $this->db_add_param($this->kurzbz) . ', ' . @@ -772,7 +779,8 @@ class lehrveranstaltung extends basis_db $this->db_add_param($this->lvps).','. $this->db_add_param($this->las).','. $this->db_add_param($this->benotung, FHC_BOOLEAN).','. - $this->db_add_param($this->lvinfo, FHC_BOOLEAN) + $this->db_add_param($this->lvinfo, FHC_BOOLEAN).','. + $this->db_add_param($this->lehrauftrag, FHC_BOOLEAN) .');'; } else @@ -826,6 +834,7 @@ class lehrveranstaltung extends basis_db 'las = '.$this->db_add_param($this->las).', '. 'benotung = '.$this->db_add_param($this->benotung, FHC_BOOLEAN).', '. 'lvinfo = '.$this->db_add_param($this->lvinfo, FHC_BOOLEAN).' '. + 'lehrauftrag = '.$this->db_add_param($this->lehrauftrag, FHC_BOOLEAN).' '. 'WHERE lehrveranstaltung_id = ' . $this->db_add_param($this->lehrveranstaltung_id, FHC_INTEGER, false) . ';'; } @@ -933,6 +942,7 @@ class lehrveranstaltung extends basis_db $lv_obj->farbe = $row->farbe; $lv_obj->benotung = $this->db_parse_bool($row->benotung); $lv_obj->lvinfo = $this->db_parse_bool($row->lvinfo); + $lv_obj->lehrauftrag = $this->db_parse_bool($row->lehrauftrag); $lv_obj->bezeichnung_arr['German'] = $row->bezeichnung; $lv_obj->bezeichnung_arr['English'] = $row->bezeichnung_english; @@ -1025,6 +1035,7 @@ class lehrveranstaltung extends basis_db $l->farbe = $row->farbe; $l->benotung = $this->db_parse_bool($row->benotung); $l->lvinfo = $this->db_parse_bool($row->lvinfo); + $l->lehrauftrag = $this->db_parse_bool($row->lehrauftrag); $l->bezeichnung_arr['German'] = $row->bezeichnung; $l->bezeichnung_arr['English'] = $row->bezeichnung_english; @@ -1142,6 +1153,7 @@ class lehrveranstaltung extends basis_db $lv_obj->farbe = $row->farbe; $lv_obj->benotung = $this->db_parse_bool($row->benotung); $lv_obj->lvinfo = $this->db_parse_bool($row->lvinfo); + $lv_obj->lehrauftrag = $this->db_parse_bool($row->lehrauftrag); $lv_obj->bezeichnung_arr['German'] = $row->bezeichnung; $lv_obj->bezeichnung_arr['English'] = $row->bezeichnung_english; @@ -1176,7 +1188,8 @@ class lehrveranstaltung extends basis_db tbl_studienplan_lehrveranstaltung.koordinator as stpllv_koordinator, tbl_studienplan_lehrveranstaltung.studienplan_lehrveranstaltung_id_parent, tbl_studienplan_lehrveranstaltung.sort stpllv_sort, - tbl_studienplan_lehrveranstaltung.curriculum + tbl_studienplan_lehrveranstaltung.curriculum, + tbl_studienplan_lehrveranstaltung.export FROM lehre.tbl_lehrveranstaltung JOIN lehre.tbl_studienplan_lehrveranstaltung USING(lehrveranstaltung_id) @@ -1234,6 +1247,7 @@ class lehrveranstaltung extends basis_db $obj->stpllv_sort = $row->stpllv_sort; $obj->benotung = $this->db_parse_bool($row->benotung); $obj->lvinfo = $this->db_parse_bool($row->lvinfo); + $obj->lehrauftrag = $this->db_parse_bool($row->lehrauftrag); $obj->bezeichnung_arr['German'] = $row->bezeichnung; $obj->bezeichnung_arr['English'] = $row->bezeichnung_english; @@ -1246,6 +1260,7 @@ class lehrveranstaltung extends basis_db $obj->studienplan_lehrveranstaltung_id = $row->studienplan_lehrveranstaltung_id; $obj->studienplan_lehrveranstaltung_id_parent = $row->studienplan_lehrveranstaltung_id_parent; $obj->curriculum = $this->db_parse_bool($row->curriculum); + $obj->export = $this->db_parse_bool($row->export); $obj->new = false; $this->lehrveranstaltungen[] = $obj; @@ -1322,6 +1337,7 @@ class lehrveranstaltung extends basis_db $obj->benotung = $this->db_parse_bool($lv->benotung); $obj->lvinfo =$this->db_parse_bool( $lv->lvinfo); $obj->zeugnis = $this->db_parse_bool($lv->zeugnis); + $obj->lehrauftrag = $this->db_parse_bool($lv->lehrauftrag); $values[] = $obj; @@ -1346,6 +1362,7 @@ class lehrveranstaltung extends basis_db $obj->benotung = $this->db_parse_bool($this->benotung); $obj->lvinfo =$this->db_parse_bool( $this->lvinfo); $obj->zeugnis = $this->db_parse_bool($this->zeugnis); + $obj->lehrauftrag = $this->db_parse_bool($this->lehrauftrag); $values[] = $obj; } @@ -1395,7 +1412,9 @@ class lehrveranstaltung extends basis_db $obj->lvinfo = $lv->lvinfo; $obj->zeugnis = $lv->zeugnis; $obj->curriculum = $lv->curriculum; - + $obj->export = $lv->export; + $obj->lehrauftrag = $lv->lehrauftrag; + $obj->lehre = $lv->lehre; $obj->children = array(); if(count($lv->childs) > 0) { @@ -1424,6 +1443,7 @@ class lehrveranstaltung extends basis_db $obj->lvinfo =$this->db_parse_bool( $this->lvinfo); $obj->zeugnis = $this->db_parse_bool($this->zeugnis); $obj->curriculum = $this->db_parse_bool($this->curriculum); + $obj->lehrauftrag = $this->lehrauftrag; $values[] = $obj; } @@ -1525,6 +1545,7 @@ class lehrveranstaltung extends basis_db $lv_obj->farbe = $row->farbe; $lv_obj->benotung = $this->db_parse_bool($row->benotung); $lv_obj->lvinfo = $this->db_parse_bool($row->lvinfo); + $lv_obj->lehrauftrag = $this->db_parse_bool($row->lehrauftrag); $lv_obj->bezeichnung_arr['German'] = $row->bezeichnung; $lv_obj->bezeichnung_arr['English'] = $row->bezeichnung_english; @@ -1690,6 +1711,7 @@ class lehrveranstaltung extends basis_db $lv_obj->oe_kurzbz = $row->oe_kurzbz; $lv_obj->benotung = $this->db_parse_bool($row->benotung); $lv_obj->lvinfo = $this->db_parse_bool($row->lvinfo); + $lv_obj->lehrauftrag = $this->db_parse_bool($row->lehrauftrag); $lv_obj->bezeichnung_arr['German'] = $row->bezeichnung; $lv_obj->bezeichnung_arr['English'] = $row->bezeichnung_english; @@ -1817,6 +1839,7 @@ class lehrveranstaltung extends basis_db $lv_obj->farbe = $row->farbe; $lv_obj->benotung = $this->db_parse_bool($row->benotung); $lv_obj->lvinfo = $this->db_parse_bool($row->lvinfo); + $lv_obj->lehrauftrag = $this->db_parse_bool($row->lehrauftrag); $lv_obj->studiengang_kurzbzlang = $row->studiengang_kurzbzlang; @@ -1942,6 +1965,7 @@ class lehrveranstaltung extends basis_db $lv_obj->farbe = $row->farbe; $lv_obj->benotung = $this->db_parse_bool($row->benotung); $lv_obj->lvinfo = $this->db_parse_bool($row->lvinfo); + $lv_obj->lehrauftrag = $this->db_parse_bool($row->lehrauftrag); $lv_obj->bezeichnung_arr['German'] = $row->bezeichnung; $lv_obj->bezeichnung_arr['English'] = $row->bezeichnung_english; @@ -2206,6 +2230,7 @@ class lehrveranstaltung extends basis_db $obj->farbe = $row->farbe; $obj->benotung = $this->db_parse_bool($row->benotung); $obj->lvinfo = $this->db_parse_bool($row->lvinfo); + $obj->lehrauftrag = $this->db_parse_bool($row->lehrauftrag); $obj->bezeichnung_arr['German'] = $row->bezeichnung; $obj->bezeichnung_arr['English'] = $row->bezeichnung_english; diff --git a/include/organisationseinheit.class.php b/include/organisationseinheit.class.php index 57e0d2104..e6e0c4bd3 100644 --- a/include/organisationseinheit.class.php +++ b/include/organisationseinheit.class.php @@ -1,754 +1,754 @@ -, - * Andreas Oesterreicher , - * Rudolf Hangl and - * Gerald Simane-Sequens - * Stefan Puraner - */ -/** - * Klasse Organisationseinheit - * - */ -require_once(dirname(__FILE__).'/basis_db.class.php'); - -class organisationseinheit extends basis_db -{ - public static $oe_parents_array=array(); - public $new; // @var boolean - public $errormsg; // @var string - public $result; - - //Tabellenspalten - public $oe_kurzbz; - public $oe_parent_kurzbz; - public $bezeichnung; - public $organisationseinheittyp_kurzbz; - public $aktiv=true; - public $lehre=true; - public $mailverteiler=false; - public $standort_id; - - public $oe_kurzbz_orig; - public $beschreibung; - - - /** - * Konstruktor - * @param $oe_kurzbz Kurzbz der Organisationseinheit - */ - public function __construct($oe_kurzbz=null) - { - parent::__construct(); - - if($oe_kurzbz != null) - $this->load($oe_kurzbz); - } - - /** - * Liefert alle Organisationseinheiten - * @param $aktiv - * @param $lehre - * @param $order Sortierreihenfolge. Standard: organisationseinheittyp_kurzbz, oe_kurzbz - * @return true wenn ok, false im Fehlerfall - */ - public function getAll($aktiv=null, $lehre=null, $order='organisationseinheittyp_kurzbz, oe_kurzbz') - { - $qry = "SELECT * FROM public.tbl_organisationseinheit WHERE 1=1"; - - if(!is_null($aktiv)) - $qry.=" AND aktiv=".$this->db_add_param($aktiv, FHC_BOOLEAN); - - if(!is_null($lehre)) - $qry.=" AND lehre=".$this->db_add_param($lehre, FHC_BOOLEAN); - - $qry .=" ORDER BY ".$order; - - if($this->db_query($qry)) - { - while($row = $this->db_fetch_object()) - { - $obj = new organisationseinheit(); - - $obj->oe_kurzbz = $row->oe_kurzbz; - $obj->oe_parent_kurzbz = $row->oe_parent_kurzbz; - $obj->bezeichnung = $row->bezeichnung; - $obj->organisationseinheittyp_kurzbz = $row->organisationseinheittyp_kurzbz; - $obj->aktiv = $this->db_parse_bool($row->aktiv); - $obj->mailverteiler = $this->db_parse_bool($row->mailverteiler); - $obj->lehre = $this->db_parse_bool($row->lehre); - - $this->result[] = $obj; - } - return true; - } - else - { - $this->errormsg = 'Fehler beim Laden der Organisationseinheiten'; - return false; - } - } - - /** - * Laedt eine Organisationseinheit - * @param $oe_kurzbz - * @return true wenn ok, false im Fehlerfall - */ - public function load($oe_kurzbz) - { - if($oe_kurzbz == '') - { - $this->errormsg = 'kurzbz darf nicht leer sein'; - return false; - } - - $qry = "SELECT * FROM public.tbl_organisationseinheit WHERE oe_kurzbz=".$this->db_add_param($oe_kurzbz).";"; - - if(!$this->db_query($qry)) - { - $this->errormsg = 'Fehler beim Laden des Datensatzes'; - return false; - } - - if($row=$this->db_fetch_object()) - { - $this->oe_kurzbz = $row->oe_kurzbz; - $this->bezeichnung = $row->bezeichnung; - $this->oe_parent_kurzbz = $row->oe_parent_kurzbz; - $this->organisationseinheittyp_kurzbz = $row->organisationseinheittyp_kurzbz; - $this->aktiv = $this->db_parse_bool($row->aktiv); - $this->mailverteiler = $this->db_parse_bool($row->mailverteiler); - $this->lehre = $this->db_parse_bool($row->lehre); - $this->standort_id = $row->standort_id; - } - else - { - $this->errormsg = 'Es ist kein Datensatz mit dieser ID vorhanden'; - return false; - } - - return true; - } - - /** - * Laedt alle Organisationseinheiten an oberster Stelle - * - * @return true wenn ok, false wenn Fehler - */ - public function getHeads() - { - $qry = "SELECT * FROM public.tbl_organisationseinheit WHERE oe_parent_kurzbz is null"; - - if($this->db_query($qry)) - { - while($row = $this->db_fetch_object()) - { - $obj = new organisationseinheit(); - - $obj->oe_kurzbz = $row->oe_kurzbz; - $obj->oe_parent_kurzbz = $row->oe_parent_kurzbz; - $obj->bezeichnung = $row->bezeichnung; - $obj->organisationseinheittyp_kurzbz = $row->organisationseinheittyp_kurzbz; - $obj->aktiv = $this->db_parse_bool($row->aktiv); - $obj->mailverteiler = $this->db_parse_bool($row->mailverteiler); - $obj->lehre = $this->db_parse_bool($row->lehre); - - $this->result[] = $obj; - } - return true; - } - else - { - $this->errormsg = 'Fehler bei Abfrage'; - return false; - } - } - - /** - * Liefert die ChildNodes einer Organisationseinheit - * - * @param $oe_kurzbz - * @return Array mit den Childs inkl dem Uebergebenen Element - */ - public function getChilds($oe_kurzbz) - { - $childs[] = $oe_kurzbz; - - $dbversion = $this->db_version(); - if($dbversion['server']>=8.4) - { - //ab PostgreSQL Version 8.4 wird die Rekursion von der DB aufgeloest - $qry = " - WITH RECURSIVE oes(oe_kurzbz, oe_parent_kurzbz) as - ( - SELECT oe_kurzbz, oe_parent_kurzbz FROM public.tbl_organisationseinheit - WHERE oe_kurzbz=".$this->db_add_param($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;"; - if($myresult = $this->db_query($qry)) - { - while($row = $this->db_fetch_object($myresult)) - { - $childs[] = $row->oe_kurzbz; - } - } - else - { - $this->errormsg = 'Fehler beim Ermitteln der Childs'; - } - return $childs; - } - else - { - //vor 8.4 muss die Rekursion in PHP aufgeloest werden - $qry = "SELECT * FROM public.tbl_organisationseinheit WHERE oe_parent_kurzbz = ".$this->db_add_param($oe_kurzbz); - - if($myresult = $this->db_query($qry)) - { - while($row = $this->db_fetch_object($myresult)) - { - $childs = array_merge($childs, $this->getChilds($row->oe_kurzbz)); - } - } - else - { - $this->errormsg = 'Fehler beim Ermitteln der Childs'; - } - return $childs; - } - } - - /** - * Liefert die Direkten KindElemente der Organisationseinheit - * - * @param $oe_kurzbz - * @return Array mit den Childs inkl derm Uebergebenen Element - */ - public function getDirectChilds($oe_kurzbz) - { - $childs = array(); - $qry = "SELECT * FROM public.tbl_organisationseinheit WHERE oe_parent_kurzbz = ".$this->db_add_param($oe_kurzbz)." ORDER BY organisationseinheittyp_kurzbz DESC, bezeichnung"; - - if($this->db_query($qry)) - { - while($row = $this->db_fetch_object()) - { - $childs[] = $row->oe_kurzbz; - } - } - else - { - $this->errormsg = 'Fehler beim Ermitteln der Childs'; - } - return $childs; - } - - /** - * Speichert eine Organisationseinheit - * - * @param $new - * @return boolean - */ - public function save($new=null) - { - if(is_null($new)) - $new = $this->new; - - if($new) - { - //Neu anlegen - $qry = 'INSERT INTO public.tbl_organisationseinheit(oe_kurzbz, oe_parent_kurzbz, bezeichnung, - organisationseinheittyp_kurzbz, aktiv, mailverteiler, lehre) VALUES('. - $this->db_add_param($this->oe_kurzbz).','. - $this->db_add_param($this->oe_parent_kurzbz).','. - $this->db_add_param($this->bezeichnung).','. - $this->db_add_param($this->organisationseinheittyp_kurzbz).','. - $this->db_add_param($this->aktiv, FHC_BOOLEAN).','. - $this->db_add_param($this->mailverteiler, FHC_BOOLEAN).','. - $this->db_add_param($this->lehre, FHC_BOOLEAN).');'; - } - else - { - if($this->oe_kurzbz=='') - { - $this->errormsg = 'Kurzbezeichnung darf nicht leer sein'; - return false; - } - - if($this->oe_kurzbz_orig=='') - { - $this->oe_kurzbz_orig=$this->oe_kurzbz; - } - - $qry = 'UPDATE public.tbl_organisationseinheit SET '. - ' oe_kurzbz='.$this->db_add_param($this->oe_kurzbz).','. - ' oe_parent_kurzbz='.$this->db_add_param($this->oe_parent_kurzbz).','. - ' bezeichnung='.$this->db_add_param($this->bezeichnung).','. - ' organisationseinheittyp_kurzbz='.$this->db_add_param($this->organisationseinheittyp_kurzbz).','. - ' aktiv='.$this->db_add_param($this->aktiv, FHC_BOOLEAN).','. - ' mailverteiler='.$this->db_add_param($this->mailverteiler, FHC_BOOLEAN).','. - ' lehre='.$this->db_add_param($this->lehre, FHC_BOOLEAN). - " WHERE oe_kurzbz=".$this->db_add_param($this->oe_kurzbz_orig, FHC_STRING, false).";"; - } - - if($this->db_query($qry)) - { - return true; - } - else - { - $this->errormsg = 'Fehler beim Speichern der Organisationseinheit'; - return false; - } - } - - /** - * Laedt alle Organisationseinheittypen - * - * @return boolean - */ - public function getTypen() - { - $qry = "SELECT * FROM public.tbl_organisationseinheittyp ORDER BY bezeichnung"; - - if($result = $this->db_query($qry)) - { - while($row = $this->db_fetch_object($result)) - { - $obj = new organisationseinheit(); - - $obj->organisationseinheittyp_kurzbz = $row->organisationseinheittyp_kurzbz; - $obj->bezeichnung = $row->bezeichnung; - $obj->beschreibung = $row->beschreibung; - - $this->result[] = $obj; - } - return true; - } - else - { - $this->errormsg = 'Fehler beim Laden der Typen'; - return false; - } - } - - /** - * Laedt die Organisationseinheiten die als Array uebergeben werden - * @param $kurzbzs Array mit den kurzbezeichnungen - * @param $order Sortierreihenfolge - * @param $aktiv wenn true dann nur aktive sonst alle - * @return true wenn ok, false im Fehlerfall - */ - public function loadArray($kurzbzs, $order=null, $aktiv=true) - { - if(count($kurzbzs)==0) - return true; - - $kurzbzs = $this->db_implode4SQL($kurzbzs); - - $qry = 'SELECT * FROM public.tbl_organisationseinheit WHERE oe_kurzbz in('.$kurzbzs.')'; - if ($aktiv) - $qry.=' AND aktiv=true'; - - if($order!=null) - $qry .=" ORDER BY $order"; - - if(!$result = $this->db_query($qry)) - { - $this->errormsg = 'Datensatz konnte nicht geladen werden'; - return false; - } - - while($row = $this->db_fetch_object($result)) - { - $obj = new organisationseinheit(); - - $obj->oe_kurzbz = $row->oe_kurzbz; - $obj->oe_parent_kurzbz = $row->oe_parent_kurzbz; - $obj->bezeichnung = $row->bezeichnung; - $obj->organisationseinheittyp_kurzbz = $row->organisationseinheittyp_kurzbz; - $obj->aktiv = $this->db_parse_bool($row->aktiv); - $obj->mailverteiler = $this->db_parse_bool($row->mailverteiler); - $obj->lehre = $this->db_parse_bool($row->lehre); - - $this->result[] = $obj; - } - - return true; - } - - /** - * Laedt die Organisationseinheiten in ein Array - * das Array enthaelt danach Key alle Organisationseinheiten und als Value dessen Parent OE - */ - public function loadParentsArray() - { - $qry = 'SELECT * FROM public.tbl_organisationseinheit'; - - if($this->db_query($qry)) - { - while($row = $this->db_fetch_object()) - { - organisationseinheit::$oe_parents_array[$row->oe_kurzbz]=$row->oe_parent_kurzbz; - } - } - } - - /** - * Liefert die OEs die im Tree ueberhalb der uebergebene OE liegen - * - * @param $oe_kurzbz - */ - public function getParents($oe_kurzbz) - { - $parents=array(); - - $qry="WITH RECURSIVE oes(oe_kurzbz, oe_parent_kurzbz) as - ( - SELECT oe_kurzbz, oe_parent_kurzbz FROM public.tbl_organisationseinheit - WHERE oe_kurzbz=".$this->db_add_param($oe_kurzbz)." and aktiv = true - UNION ALL - SELECT o.oe_kurzbz, o.oe_parent_kurzbz FROM public.tbl_organisationseinheit o, oes - WHERE o.oe_kurzbz=oes.oe_parent_kurzbz and aktiv = true - ) - SELECT oe_kurzbz - FROM oes"; - if($result = $this->db_query($qry)) - { - while($row = $this->db_fetch_object($result)) - { - $parents[]=$row->oe_kurzbz; - } - return $parents; - } - else - { - $this->errormsg='Fehler beim Laden der Daten'; - return false; - } - } - - /** - * Prueft ob $child eine Organisationseinheit unterhalb der OE $oe_kurzbz ist - * - * @param $oe_kurzbz parent organisationseinheit - * @param $child child organisationseinheit - * @return true wenn child, false wenn nicht - */ - public function isChild($oe_kurzbz, $child) - { - if(count(organisationseinheit::$oe_parents_array)<=0) - { - $this->loadParentsArray(); - } - - if(!isset(organisationseinheit::$oe_parents_array[$child])) - { - $this->errormsg = 'Organisationseinheit existiert nicht'; - return false; - } - - $childs = array_keys(organisationseinheit::$oe_parents_array, $oe_kurzbz); - - foreach ($childs as $row) - { - if($row==$child) - { - return true; - } - else - { - if($this->isChild($row, $child)) - return true; - } - } - - return false; - } - - /** - * Baut die Datenstruktur für senden als JSON Objekt auf - */ - public function cleanResult() - { - $data = array(); - if(count($this->result)>0) - { - foreach($this->result as $oeEinheit) - { - $obj = new stdClass(); - $obj->oe_kurzbz = $oeEinheit->oe_kurzbz; - $obj->oe_parent_kurzbz = $oeEinheit->oe_parent_kurzbz; - $obj->bezeichnung = $oeEinheit->bezeichnung; - $obj->organisationseinheittyp_kurzbz = $oeEinheit->organisationseinheittyp_kurzbz; - $obj->aktiv = $oeEinheit->aktiv; - $obj->mailverteiler = $oeEinheit->mailverteiler; - $obj->lehre = $oeEinheit->lehre; - $data[]=$obj; - } - } - else - { - $obj = new stdClass(); - $obj->oe_kurzbz = $this->oe_kurzbz; - $obj->oe_parent_kurzbz = $this->oe_parent_kurzbz; - $obj->bezeichnung = $this->bezeichnung; - $obj->organisationseinheittyp_kurzbz = $this->organisationseinheittyp_kurzbz; - $obj->aktiv = $this->aktiv; - $obj->mailverteiler = $this->mailverteiler; - $obj->lehre = $this->lehre; - $data[]=$obj; - } - return $data; - } - - /** - * Lädt Organisationseinheiten nach ihrem Typ - * @param type $oetyp_kurzbz - * @return boolean true, wenn ok; false, im Fehlerfall - */ - public function getByTyp($oetyp_kurzbz) - { - $qry = 'SELECT * FROM public.tbl_organisationseinheit WHERE organisationseinheittyp_kurzbz='.$this->db_add_param($oetyp_kurzbz).';'; - - if($this->db_query($qry)) - { - while($row = $this->db_fetch_object()) - { - $obj = new organisationseinheit(); - - $obj->oe_kurzbz = $row->oe_kurzbz; - $obj->oe_parent_kurzbz = $row->oe_parent_kurzbz; - $obj->bezeichnung = $row->bezeichnung; - $obj->organisationseinheittyp_kurzbz = $row->organisationseinheittyp_kurzbz; - $obj->aktiv = $this->db_parse_bool($row->aktiv); - $obj->mailverteiler = $this->db_parse_bool($row->mailverteiler); - $obj->lehre = $this->db_parse_bool($row->lehre); - - $this->result[] = $obj; - } - return true; - } - else - { - $this->errormsg = 'Fehler beim Laden der Organisationseinheiten'; - return false; - } - } - - /** - * Sucht nach einer Organisationseinheit - * @param type $searchItem - * @return boolean true, wenn ok; false, im Fehlerfall - */ - public function search($searchItem) - { - $qry = 'SELECT * FROM public.tbl_organisationseinheit WHERE - ( - LOWER(bezeichnung) LIKE LOWER(\'%'.$this->db_escape((implode(' ',$searchItem))).'%\') - OR - LOWER(organisationseinheittyp_kurzbz) LIKE LOWER(\'%'.$this->db_escape((implode(' ',$searchItem))).'%\') - )'; - foreach($searchItem as $value) - { - $qry.=' OR (LOWER(oe_kurzbz)=LOWER('.$this->db_add_param($value).')) - OR (LOWER(bezeichnung)=LOWER('.$this->db_add_param($value).'))'; - } - $qry.= ' ORDER BY organisationseinheittyp_kurzbz, bezeichnung;'; - - if($this->db_query($qry)) - { - while($row = $this->db_fetch_object()) - { - $obj = new organisationseinheit(); - - $obj->oe_kurzbz = $row->oe_kurzbz; - $obj->oe_parent_kurzbz = $row->oe_parent_kurzbz; - $obj->bezeichnung = $row->bezeichnung; - $obj->organisationseinheittyp_kurzbz = $row->organisationseinheittyp_kurzbz; - $obj->aktiv = $this->db_parse_bool($row->aktiv); - $obj->mailverteiler = $this->db_parse_bool($row->mailverteiler); - $obj->lehre = $this->db_parse_bool($row->lehre); - - $this->result[] = $obj; - } - return true; - } - else - { - $this->errormsg = 'Fehler beim Laden der Organisationseinheiten'; - return false; - } - } - - /** - * Laedt alle Organisationseinheiten, sortiert nach den am haeufigsten vom User in der Zeitaufzeichnung verwendeten - * - *

Optionaler Zeitraum (Tage in die Vergangenheit), in denen die OE verwendet wurde
- * Optionale Anzahl an Ereignissen im angegebenen Zeitraum, um die OE zu beruecksichtigen

- * - * @param string $user uid - * @param integer $zeitraum Anzahl Tage in die Vergangenheit, die fuer das Auftreten der OE beruecksichtigt werden sollen - * @param integer $anzahl_ereignisse default: 3 Wie oft soll diese OE mindestens in $zeitraum vorkommen, um beruecksichtigt zu werden - * @param boolean $aktiv - */ - public function getFrequent($user, $zeitraum=null, $anzahl_ereignisse='3', $aktiv=null) - { - if(!is_numeric($anzahl_ereignisse)) - { - $this->errormsg = "anzahl_ereignisse muss eine gueltige Zahl sein"; - return false; - } - - if (!is_null($zeitraum) && $zeitraum>0 && is_numeric($zeitraum)) - $zeit = "AND tbl_zeitaufzeichnung.start>=(now()::date-$zeitraum)"; - else - $zeit = ""; - - $qry = "SELECT - oe_kurzbz, - oe_parent_kurzbz, - bezeichnung, - organisationseinheittyp_kurzbz, - aktiv, - lehre, - count(tbl_zeitaufzeichnung.zeitaufzeichnung_id) - FROM campus.tbl_zeitaufzeichnung - JOIN public.tbl_organisationseinheit ON(oe_kurzbz IN (oe_kurzbz_1,oe_kurzbz_2)) - WHERE tbl_zeitaufzeichnung.uid=".$this->db_add_param($user)." - $zeit - GROUP BY tbl_organisationseinheit.oe_kurzbz HAVING COUNT(*) > $anzahl_ereignisse - - UNION - - SELECT - oe_kurzbz, - oe_parent_kurzbz, - bezeichnung, - organisationseinheittyp_kurzbz, - aktiv, - lehre, - '0' - FROM public.tbl_organisationseinheit"; - - if(!is_null($aktiv)) - $qry.=" WHERE aktiv=".$this->db_add_param($aktiv, FHC_BOOLEAN); - - $qry .=" ORDER BY count DESC,bezeichnung,oe_kurzbz"; - - if($this->db_query($qry)) - { - while($row = $this->db_fetch_object()) - { - $obj = new organisationseinheit(); - - $obj->oe_kurzbz = $row->oe_kurzbz; - $obj->oe_parent_kurzbz = $row->oe_parent_kurzbz; - $obj->bezeichnung = $row->bezeichnung; - $obj->organisationseinheittyp_kurzbz = $row->organisationseinheittyp_kurzbz; - $obj->aktiv = $this->db_parse_bool($row->aktiv); - $obj->lehre = $this->db_parse_bool($row->lehre); - $obj->anzahl = $row->count; - - $this->result[] = $obj; - } - return true; - } - else - { - $this->errormsg = 'Fehler beim Laden der Organisationseinheiten'; - return false; - } - } - - /** - * Gibt alle Standorte zurück - * @param $aktiv - * @param $lehre - * @return boolean|array false im Fehlerfall, ansonsten ein Array - */ - public function getAllStandorte($aktiv=null, $lehre=null) - { - $result = array(); - $qry = "SELECT DISTINCT standort FROM public.tbl_organisationseinheit WHERE standort IS NOT NULL"; - - if(!is_null($aktiv)) - $qry.=" AND aktiv=".$this->db_add_param($aktiv, FHC_BOOLEAN); - - if(!is_null($lehre)) - $qry.=" AND lehre=".$this->db_add_param($lehre, FHC_BOOLEAN); - - if($this->db_query($qry)) - { - while($row = $this->db_fetch_object()) - { - $result[] = $row->standort; - } - - return $result; - } - else - { - $this->errormsg = 'Fehler beim Laden der Standorte'; - return false; - } - } - - /** - * Ermittelt die Stundenobergrenze fuer Lektoren - * Dabei wird im OE Baum nach oben nach Stundengrenzen gesucht und die niedrigste Stundengrenze ermittelt - * @param $oe_kurzbz Organisationseinheit - * @param $fixangestellt boolean legt fest ob die Grenze - * fuer Freie oder Fixangestellte Lektoren ermittelt werden soll - * @return array(oe_kurzbz, numeric Anzahl der Stunden) - */ - public function getStundengrenze($oe_kurzbz, $fixangestellt=true) - { - if($fixangestellt) - $fixfrei='fix'; - else - $fixfrei='frei'; - - $qry = " - WITH RECURSIVE oes(oe_kurzbz, oe_parent_kurzbz) as - ( - SELECT oe_kurzbz, oe_parent_kurzbz FROM public.tbl_organisationseinheit - WHERE oe_kurzbz=".$this->db_add_param($oe_kurzbz)." - UNION ALL - SELECT o.oe_kurzbz, o.oe_parent_kurzbz FROM public.tbl_organisationseinheit o, oes - WHERE o.oe_kurzbz=oes.oe_parent_kurzbz - ) - SELECT oe_kurzbz, warn_semesterstunden_".$fixfrei." as stunden - FROM oes JOIN public.tbl_organisationseinheit USING(oe_kurzbz) - ORDER BY warn_semesterstunden_".$fixfrei." asc limit 1"; - - if($result = $this->db_query($qry)) - { - if($row = $this->db_fetch_object($result)) - { - return array($row->oe_kurzbz, $row->stunden); - } - } - } -} -?> +, + * Andreas Oesterreicher , + * Rudolf Hangl and + * Gerald Simane-Sequens + * Stefan Puraner + */ +/** + * Klasse Organisationseinheit + * + */ +require_once(dirname(__FILE__).'/basis_db.class.php'); + +class organisationseinheit extends basis_db +{ + public static $oe_parents_array=array(); + public $new; // @var boolean + public $errormsg; // @var string + public $result; + + //Tabellenspalten + public $oe_kurzbz; + public $oe_parent_kurzbz; + public $bezeichnung; + public $organisationseinheittyp_kurzbz; + public $aktiv=true; + public $lehre=true; + public $mailverteiler=false; + public $standort_id; + + public $oe_kurzbz_orig; + public $beschreibung; + + + /** + * Konstruktor + * @param $oe_kurzbz Kurzbz der Organisationseinheit + */ + public function __construct($oe_kurzbz=null) + { + parent::__construct(); + + if($oe_kurzbz != null) + $this->load($oe_kurzbz); + } + + /** + * Liefert alle Organisationseinheiten + * @param $aktiv + * @param $lehre + * @param $order Sortierreihenfolge. Standard: organisationseinheittyp_kurzbz, oe_kurzbz + * @return true wenn ok, false im Fehlerfall + */ + public function getAll($aktiv=null, $lehre=null, $order='organisationseinheittyp_kurzbz, oe_kurzbz') + { + $qry = "SELECT * FROM public.tbl_organisationseinheit WHERE 1=1"; + + if(!is_null($aktiv)) + $qry.=" AND aktiv=".$this->db_add_param($aktiv, FHC_BOOLEAN); + + if(!is_null($lehre)) + $qry.=" AND lehre=".$this->db_add_param($lehre, FHC_BOOLEAN); + + $qry .=" ORDER BY ".$order; + + if($this->db_query($qry)) + { + while($row = $this->db_fetch_object()) + { + $obj = new organisationseinheit(); + + $obj->oe_kurzbz = $row->oe_kurzbz; + $obj->oe_parent_kurzbz = $row->oe_parent_kurzbz; + $obj->bezeichnung = $row->bezeichnung; + $obj->organisationseinheittyp_kurzbz = $row->organisationseinheittyp_kurzbz; + $obj->aktiv = $this->db_parse_bool($row->aktiv); + $obj->mailverteiler = $this->db_parse_bool($row->mailverteiler); + $obj->lehre = $this->db_parse_bool($row->lehre); + + $this->result[] = $obj; + } + return true; + } + else + { + $this->errormsg = 'Fehler beim Laden der Organisationseinheiten'; + return false; + } + } + + /** + * Laedt eine Organisationseinheit + * @param $oe_kurzbz + * @return true wenn ok, false im Fehlerfall + */ + public function load($oe_kurzbz) + { + if($oe_kurzbz == '') + { + $this->errormsg = 'kurzbz darf nicht leer sein'; + return false; + } + + $qry = "SELECT * FROM public.tbl_organisationseinheit WHERE oe_kurzbz=".$this->db_add_param($oe_kurzbz).";"; + + if(!$this->db_query($qry)) + { + $this->errormsg = 'Fehler beim Laden des Datensatzes'; + return false; + } + + if($row=$this->db_fetch_object()) + { + $this->oe_kurzbz = $row->oe_kurzbz; + $this->bezeichnung = $row->bezeichnung; + $this->oe_parent_kurzbz = $row->oe_parent_kurzbz; + $this->organisationseinheittyp_kurzbz = $row->organisationseinheittyp_kurzbz; + $this->aktiv = $this->db_parse_bool($row->aktiv); + $this->mailverteiler = $this->db_parse_bool($row->mailverteiler); + $this->lehre = $this->db_parse_bool($row->lehre); + $this->standort_id = $row->standort_id; + } + else + { + $this->errormsg = 'Es ist kein Datensatz mit dieser ID vorhanden'; + return false; + } + + return true; + } + + /** + * Laedt alle Organisationseinheiten an oberster Stelle + * + * @return true wenn ok, false wenn Fehler + */ + public function getHeads() + { + $qry = "SELECT * FROM public.tbl_organisationseinheit WHERE oe_parent_kurzbz is null"; + + if($this->db_query($qry)) + { + while($row = $this->db_fetch_object()) + { + $obj = new organisationseinheit(); + + $obj->oe_kurzbz = $row->oe_kurzbz; + $obj->oe_parent_kurzbz = $row->oe_parent_kurzbz; + $obj->bezeichnung = $row->bezeichnung; + $obj->organisationseinheittyp_kurzbz = $row->organisationseinheittyp_kurzbz; + $obj->aktiv = $this->db_parse_bool($row->aktiv); + $obj->mailverteiler = $this->db_parse_bool($row->mailverteiler); + $obj->lehre = $this->db_parse_bool($row->lehre); + + $this->result[] = $obj; + } + return true; + } + else + { + $this->errormsg = 'Fehler bei Abfrage'; + return false; + } + } + + /** + * Liefert die ChildNodes einer Organisationseinheit + * + * @param $oe_kurzbz + * @return Array mit den Childs inkl dem Uebergebenen Element + */ + public function getChilds($oe_kurzbz) + { + $childs[] = $oe_kurzbz; + + $dbversion = $this->db_version(); + if($dbversion['server']>=8.4) + { + //ab PostgreSQL Version 8.4 wird die Rekursion von der DB aufgeloest + $qry = " + WITH RECURSIVE oes(oe_kurzbz, oe_parent_kurzbz) as + ( + SELECT oe_kurzbz, oe_parent_kurzbz FROM public.tbl_organisationseinheit + WHERE oe_kurzbz=".$this->db_add_param($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;"; + if($myresult = $this->db_query($qry)) + { + while($row = $this->db_fetch_object($myresult)) + { + $childs[] = $row->oe_kurzbz; + } + } + else + { + $this->errormsg = 'Fehler beim Ermitteln der Childs'; + } + return $childs; + } + else + { + //vor 8.4 muss die Rekursion in PHP aufgeloest werden + $qry = "SELECT * FROM public.tbl_organisationseinheit WHERE oe_parent_kurzbz = ".$this->db_add_param($oe_kurzbz); + + if($myresult = $this->db_query($qry)) + { + while($row = $this->db_fetch_object($myresult)) + { + $childs = array_merge($childs, $this->getChilds($row->oe_kurzbz)); + } + } + else + { + $this->errormsg = 'Fehler beim Ermitteln der Childs'; + } + return $childs; + } + } + + /** + * Liefert die Direkten KindElemente der Organisationseinheit + * + * @param $oe_kurzbz + * @return Array mit den Childs inkl derm Uebergebenen Element + */ + public function getDirectChilds($oe_kurzbz) + { + $childs = array(); + $qry = "SELECT * FROM public.tbl_organisationseinheit WHERE oe_parent_kurzbz = ".$this->db_add_param($oe_kurzbz)." ORDER BY organisationseinheittyp_kurzbz DESC, bezeichnung"; + + if($this->db_query($qry)) + { + while($row = $this->db_fetch_object()) + { + $childs[] = $row->oe_kurzbz; + } + } + else + { + $this->errormsg = 'Fehler beim Ermitteln der Childs'; + } + return $childs; + } + + /** + * Speichert eine Organisationseinheit + * + * @param $new + * @return boolean + */ + public function save($new=null) + { + if(is_null($new)) + $new = $this->new; + + if($new) + { + //Neu anlegen + $qry = 'INSERT INTO public.tbl_organisationseinheit(oe_kurzbz, oe_parent_kurzbz, bezeichnung, + organisationseinheittyp_kurzbz, aktiv, mailverteiler, lehre) VALUES('. + $this->db_add_param($this->oe_kurzbz).','. + $this->db_add_param($this->oe_parent_kurzbz).','. + $this->db_add_param($this->bezeichnung).','. + $this->db_add_param($this->organisationseinheittyp_kurzbz).','. + $this->db_add_param($this->aktiv, FHC_BOOLEAN).','. + $this->db_add_param($this->mailverteiler, FHC_BOOLEAN).','. + $this->db_add_param($this->lehre, FHC_BOOLEAN).');'; + } + else + { + if($this->oe_kurzbz=='') + { + $this->errormsg = 'Kurzbezeichnung darf nicht leer sein'; + return false; + } + + if($this->oe_kurzbz_orig=='') + { + $this->oe_kurzbz_orig=$this->oe_kurzbz; + } + + $qry = 'UPDATE public.tbl_organisationseinheit SET '. + ' oe_kurzbz='.$this->db_add_param($this->oe_kurzbz).','. + ' oe_parent_kurzbz='.$this->db_add_param($this->oe_parent_kurzbz).','. + ' bezeichnung='.$this->db_add_param($this->bezeichnung).','. + ' organisationseinheittyp_kurzbz='.$this->db_add_param($this->organisationseinheittyp_kurzbz).','. + ' aktiv='.$this->db_add_param($this->aktiv, FHC_BOOLEAN).','. + ' mailverteiler='.$this->db_add_param($this->mailverteiler, FHC_BOOLEAN).','. + ' lehre='.$this->db_add_param($this->lehre, FHC_BOOLEAN). + " WHERE oe_kurzbz=".$this->db_add_param($this->oe_kurzbz_orig, FHC_STRING, false).";"; + } + + if($this->db_query($qry)) + { + return true; + } + else + { + $this->errormsg = 'Fehler beim Speichern der Organisationseinheit'; + return false; + } + } + + /** + * Laedt alle Organisationseinheittypen + * + * @return boolean + */ + public function getTypen() + { + $qry = "SELECT * FROM public.tbl_organisationseinheittyp ORDER BY bezeichnung"; + + if($result = $this->db_query($qry)) + { + while($row = $this->db_fetch_object($result)) + { + $obj = new organisationseinheit(); + + $obj->organisationseinheittyp_kurzbz = $row->organisationseinheittyp_kurzbz; + $obj->bezeichnung = $row->bezeichnung; + $obj->beschreibung = $row->beschreibung; + + $this->result[] = $obj; + } + return true; + } + else + { + $this->errormsg = 'Fehler beim Laden der Typen'; + return false; + } + } + + /** + * Laedt die Organisationseinheiten die als Array uebergeben werden + * @param $kurzbzs Array mit den kurzbezeichnungen + * @param $order Sortierreihenfolge + * @param $aktiv wenn true dann nur aktive sonst alle + * @return true wenn ok, false im Fehlerfall + */ + public function loadArray($kurzbzs, $order=null, $aktiv=true) + { + if(count($kurzbzs)==0) + return true; + + $kurzbzs = $this->db_implode4SQL($kurzbzs); + + $qry = 'SELECT * FROM public.tbl_organisationseinheit WHERE oe_kurzbz in('.$kurzbzs.')'; + if ($aktiv) + $qry.=' AND aktiv=true'; + + if($order!=null) + $qry .=" ORDER BY $order"; + + if(!$result = $this->db_query($qry)) + { + $this->errormsg = 'Datensatz konnte nicht geladen werden'; + return false; + } + + while($row = $this->db_fetch_object($result)) + { + $obj = new organisationseinheit(); + + $obj->oe_kurzbz = $row->oe_kurzbz; + $obj->oe_parent_kurzbz = $row->oe_parent_kurzbz; + $obj->bezeichnung = $row->bezeichnung; + $obj->organisationseinheittyp_kurzbz = $row->organisationseinheittyp_kurzbz; + $obj->aktiv = $this->db_parse_bool($row->aktiv); + $obj->mailverteiler = $this->db_parse_bool($row->mailverteiler); + $obj->lehre = $this->db_parse_bool($row->lehre); + + $this->result[] = $obj; + } + + return true; + } + + /** + * Laedt die Organisationseinheiten in ein Array + * das Array enthaelt danach Key alle Organisationseinheiten und als Value dessen Parent OE + */ + public function loadParentsArray() + { + $qry = 'SELECT * FROM public.tbl_organisationseinheit'; + + if($this->db_query($qry)) + { + while($row = $this->db_fetch_object()) + { + organisationseinheit::$oe_parents_array[$row->oe_kurzbz]=$row->oe_parent_kurzbz; + } + } + } + + /** + * Liefert die OEs die im Tree ueberhalb der uebergebene OE liegen + * + * @param $oe_kurzbz + */ + public function getParents($oe_kurzbz) + { + $parents=array(); + + $qry="WITH RECURSIVE oes(oe_kurzbz, oe_parent_kurzbz) as + ( + SELECT oe_kurzbz, oe_parent_kurzbz FROM public.tbl_organisationseinheit + WHERE oe_kurzbz=".$this->db_add_param($oe_kurzbz)." and aktiv = true + UNION ALL + SELECT o.oe_kurzbz, o.oe_parent_kurzbz FROM public.tbl_organisationseinheit o, oes + WHERE o.oe_kurzbz=oes.oe_parent_kurzbz and aktiv = true + ) + SELECT oe_kurzbz + FROM oes"; + if($result = $this->db_query($qry)) + { + while($row = $this->db_fetch_object($result)) + { + $parents[]=$row->oe_kurzbz; + } + return $parents; + } + else + { + $this->errormsg='Fehler beim Laden der Daten'; + return false; + } + } + + /** + * Prueft ob $child eine Organisationseinheit unterhalb der OE $oe_kurzbz ist + * + * @param $oe_kurzbz parent organisationseinheit + * @param $child child organisationseinheit + * @return true wenn child, false wenn nicht + */ + public function isChild($oe_kurzbz, $child) + { + if(count(organisationseinheit::$oe_parents_array)<=0) + { + $this->loadParentsArray(); + } + + if(!isset(organisationseinheit::$oe_parents_array[$child])) + { + $this->errormsg = 'Organisationseinheit existiert nicht'; + return false; + } + + $childs = array_keys(organisationseinheit::$oe_parents_array, $oe_kurzbz); + + foreach ($childs as $row) + { + if($row==$child) + { + return true; + } + else + { + if($this->isChild($row, $child)) + return true; + } + } + + return false; + } + + /** + * Baut die Datenstruktur für senden als JSON Objekt auf + */ + public function cleanResult() + { + $data = array(); + if(count($this->result)>0) + { + foreach($this->result as $oeEinheit) + { + $obj = new stdClass(); + $obj->oe_kurzbz = $oeEinheit->oe_kurzbz; + $obj->oe_parent_kurzbz = $oeEinheit->oe_parent_kurzbz; + $obj->bezeichnung = $oeEinheit->bezeichnung; + $obj->organisationseinheittyp_kurzbz = $oeEinheit->organisationseinheittyp_kurzbz; + $obj->aktiv = $oeEinheit->aktiv; + $obj->mailverteiler = $oeEinheit->mailverteiler; + $obj->lehre = $oeEinheit->lehre; + $data[]=$obj; + } + } + else + { + $obj = new stdClass(); + $obj->oe_kurzbz = $this->oe_kurzbz; + $obj->oe_parent_kurzbz = $this->oe_parent_kurzbz; + $obj->bezeichnung = $this->bezeichnung; + $obj->organisationseinheittyp_kurzbz = $this->organisationseinheittyp_kurzbz; + $obj->aktiv = $this->aktiv; + $obj->mailverteiler = $this->mailverteiler; + $obj->lehre = $this->lehre; + $data[]=$obj; + } + return $data; + } + + /** + * Lädt Organisationseinheiten nach ihrem Typ + * @param type $oetyp_kurzbz + * @return boolean true, wenn ok; false, im Fehlerfall + */ + public function getByTyp($oetyp_kurzbz) + { + $qry = 'SELECT * FROM public.tbl_organisationseinheit WHERE organisationseinheittyp_kurzbz='.$this->db_add_param($oetyp_kurzbz).';'; + + if($this->db_query($qry)) + { + while($row = $this->db_fetch_object()) + { + $obj = new organisationseinheit(); + + $obj->oe_kurzbz = $row->oe_kurzbz; + $obj->oe_parent_kurzbz = $row->oe_parent_kurzbz; + $obj->bezeichnung = $row->bezeichnung; + $obj->organisationseinheittyp_kurzbz = $row->organisationseinheittyp_kurzbz; + $obj->aktiv = $this->db_parse_bool($row->aktiv); + $obj->mailverteiler = $this->db_parse_bool($row->mailverteiler); + $obj->lehre = $this->db_parse_bool($row->lehre); + + $this->result[] = $obj; + } + return true; + } + else + { + $this->errormsg = 'Fehler beim Laden der Organisationseinheiten'; + return false; + } + } + + /** + * Sucht nach einer Organisationseinheit + * @param type $searchItem + * @return boolean true, wenn ok; false, im Fehlerfall + */ + public function search($searchItem) + { + $qry = 'SELECT * FROM public.tbl_organisationseinheit WHERE + ( + LOWER(bezeichnung) LIKE LOWER(\'%'.$this->db_escape((implode(' ',$searchItem))).'%\') + OR + LOWER(organisationseinheittyp_kurzbz) LIKE LOWER(\'%'.$this->db_escape((implode(' ',$searchItem))).'%\') + )'; + foreach($searchItem as $value) + { + $qry.=' OR (LOWER(oe_kurzbz)=LOWER('.$this->db_add_param($value).')) + OR (LOWER(bezeichnung)=LOWER('.$this->db_add_param($value).'))'; + } + $qry.= ' ORDER BY organisationseinheittyp_kurzbz, bezeichnung;'; + + if($this->db_query($qry)) + { + while($row = $this->db_fetch_object()) + { + $obj = new organisationseinheit(); + + $obj->oe_kurzbz = $row->oe_kurzbz; + $obj->oe_parent_kurzbz = $row->oe_parent_kurzbz; + $obj->bezeichnung = $row->bezeichnung; + $obj->organisationseinheittyp_kurzbz = $row->organisationseinheittyp_kurzbz; + $obj->aktiv = $this->db_parse_bool($row->aktiv); + $obj->mailverteiler = $this->db_parse_bool($row->mailverteiler); + $obj->lehre = $this->db_parse_bool($row->lehre); + + $this->result[] = $obj; + } + return true; + } + else + { + $this->errormsg = 'Fehler beim Laden der Organisationseinheiten'; + return false; + } + } + + /** + * Laedt alle Organisationseinheiten, sortiert nach den am haeufigsten vom User in der Zeitaufzeichnung verwendeten + * + *

Optionaler Zeitraum (Tage in die Vergangenheit), in denen die OE verwendet wurde
+ * Optionale Anzahl an Ereignissen im angegebenen Zeitraum, um die OE zu beruecksichtigen

+ * + * @param string $user uid + * @param integer $zeitraum Anzahl Tage in die Vergangenheit, die fuer das Auftreten der OE beruecksichtigt werden sollen + * @param integer $anzahl_ereignisse default: 3 Wie oft soll diese OE mindestens in $zeitraum vorkommen, um beruecksichtigt zu werden + * @param boolean $aktiv + */ + public function getFrequent($user, $zeitraum=null, $anzahl_ereignisse='3', $aktiv=null) + { + if(!is_numeric($anzahl_ereignisse)) + { + $this->errormsg = "anzahl_ereignisse muss eine gueltige Zahl sein"; + return false; + } + + if (!is_null($zeitraum) && $zeitraum>0 && is_numeric($zeitraum)) + $zeit = "AND tbl_zeitaufzeichnung.start>=(now()::date-$zeitraum)"; + else + $zeit = ""; + + $qry = "SELECT + oe_kurzbz, + oe_parent_kurzbz, + bezeichnung, + organisationseinheittyp_kurzbz, + aktiv, + lehre, + count(tbl_zeitaufzeichnung.zeitaufzeichnung_id) + FROM campus.tbl_zeitaufzeichnung + JOIN public.tbl_organisationseinheit ON(oe_kurzbz IN (oe_kurzbz_1,oe_kurzbz_2)) + WHERE tbl_zeitaufzeichnung.uid=".$this->db_add_param($user)." + $zeit + GROUP BY tbl_organisationseinheit.oe_kurzbz HAVING COUNT(*) > $anzahl_ereignisse + + UNION + + SELECT + oe_kurzbz, + oe_parent_kurzbz, + bezeichnung, + organisationseinheittyp_kurzbz, + aktiv, + lehre, + '0' + FROM public.tbl_organisationseinheit"; + + if(!is_null($aktiv)) + $qry.=" WHERE aktiv=".$this->db_add_param($aktiv, FHC_BOOLEAN); + + $qry .=" ORDER BY count DESC,bezeichnung,oe_kurzbz"; + + if($this->db_query($qry)) + { + while($row = $this->db_fetch_object()) + { + $obj = new organisationseinheit(); + + $obj->oe_kurzbz = $row->oe_kurzbz; + $obj->oe_parent_kurzbz = $row->oe_parent_kurzbz; + $obj->bezeichnung = $row->bezeichnung; + $obj->organisationseinheittyp_kurzbz = $row->organisationseinheittyp_kurzbz; + $obj->aktiv = $this->db_parse_bool($row->aktiv); + $obj->lehre = $this->db_parse_bool($row->lehre); + $obj->anzahl = $row->count; + + $this->result[] = $obj; + } + return true; + } + else + { + $this->errormsg = 'Fehler beim Laden der Organisationseinheiten'; + return false; + } + } + + /** + * Gibt alle Standorte zurück + * @param $aktiv + * @param $lehre + * @return boolean|array false im Fehlerfall, ansonsten ein Array + */ + public function getAllStandorte($aktiv=null, $lehre=null) + { + $result = array(); + $qry = "SELECT DISTINCT standort FROM public.tbl_organisationseinheit WHERE standort IS NOT NULL"; + + if(!is_null($aktiv)) + $qry.=" AND aktiv=".$this->db_add_param($aktiv, FHC_BOOLEAN); + + if(!is_null($lehre)) + $qry.=" AND lehre=".$this->db_add_param($lehre, FHC_BOOLEAN); + + if($this->db_query($qry)) + { + while($row = $this->db_fetch_object()) + { + $result[] = $row->standort; + } + + return $result; + } + else + { + $this->errormsg = 'Fehler beim Laden der Standorte'; + return false; + } + } + + /** + * Ermittelt die Stundenobergrenze fuer Lektoren + * Dabei wird im OE Baum nach oben nach Stundengrenzen gesucht und die niedrigste Stundengrenze ermittelt + * @param $oe_kurzbz Organisationseinheit + * @param $fixangestellt boolean legt fest ob die Grenze + * fuer Freie oder Fixangestellte Lektoren ermittelt werden soll + * @return array(oe_kurzbz, numeric Anzahl der Stunden) + */ + public function getStundengrenze($oe_kurzbz, $fixangestellt=true) + { + if($fixangestellt) + $fixfrei='fix'; + else + $fixfrei='frei'; + + $qry = " + WITH RECURSIVE oes(oe_kurzbz, oe_parent_kurzbz) as + ( + SELECT oe_kurzbz, oe_parent_kurzbz FROM public.tbl_organisationseinheit + WHERE oe_kurzbz=".$this->db_add_param($oe_kurzbz)." + UNION ALL + SELECT o.oe_kurzbz, o.oe_parent_kurzbz FROM public.tbl_organisationseinheit o, oes + WHERE o.oe_kurzbz=oes.oe_parent_kurzbz + ) + SELECT oe_kurzbz, warn_semesterstunden_".$fixfrei." as stunden + FROM oes JOIN public.tbl_organisationseinheit USING(oe_kurzbz) + ORDER BY warn_semesterstunden_".$fixfrei." asc limit 1"; + + if($result = $this->db_query($qry)) + { + if($row = $this->db_fetch_object($result)) + { + return array($row->oe_kurzbz, $row->stunden); + } + } + } +} +?> diff --git a/include/studienordnung.class.php b/include/studienordnung.class.php index 17c1cc366..c8a92e362 100644 --- a/include/studienordnung.class.php +++ b/include/studienordnung.class.php @@ -155,9 +155,9 @@ class studienordnung extends basis_db } else { - $qry = 'SELECT sto.*, s.bezeichnung as status_bezeichnung FROM lehre.tbl_studienordnung + $qry = 'SELECT sto.*, s.bezeichnung as status_bezeichnung, sem.* FROM lehre.tbl_studienordnung sto JOIN lehre.tbl_studienordnungstatus s USING(status_kurzbz) - LEFT JOIN lehre.tbl_studienordnung_semester USING (studienordnung_id) + LEFT JOIN lehre.tbl_studienordnung_semester sem USING (studienordnung_id) WHERE studiengang_kz='.$this->db_add_param($studiengang_kz, FHC_INTEGER, false); if (!is_null($studiensemester_kurzbz)) @@ -746,7 +746,7 @@ class studienordnung extends basis_db $this->studiengangkurzbzlang = $row->studiengangkurzbzlang; $this->akadgrad_id = $row->akadgrad_id; $this->standort_id = $row->standort_id; - $this->status_kurzb = $row->status_kurzb; + $this->status_kurzbz = $row->status_kurzbz; $this->updateamum = $row->updateamum; $this->updatevon = $row->updatevon; $this->insertamum = $row->insertamum; diff --git a/system/dbupdate_3.2.php b/system/dbupdate_3.2.php index 478010e5e..b7774c25c 100644 --- a/system/dbupdate_3.2.php +++ b/system/dbupdate_3.2.php @@ -178,10 +178,27 @@ if (!$result = @$db->db_query("SELECT curriculum FROM lehre.tbl_studienplan_lehr echo ' lehre.tbl_studienplan_lehrveranstaltung: Spalte curriculum hinzugefügt.
'; } +//Spalte export in lehre.tbl_studienordnung_lehrveranstaltung +if (!$result = @$db->db_query("SELECT export FROM lehre.tbl_studienplan_lehrveranstaltung LIMIT 1;")) +{ + $qry = "ALTER TABLE lehre.tbl_studienplan_lehrveranstaltung ADD COLUMN export BOOLEAN DEFAULT TRUE;"; + if (!$db->db_query($qry)) + echo 'lehre.tbl_studienplan_lehrveranstaltung: ' . $db->db_last_error() . '
'; + else + echo ' lehre.tbl_studienplan_lehrveranstaltung: Spalte export hinzugefügt.
'; +} +//Spalte lehrauftrag in lehre.tbl_lehrveranstaltung +if (!$result = @$db->db_query("SELECT lehrauftrag FROM lehre.tbl_lehrveranstaltung LIMIT 1;")) +{ + $qry = "ALTER TABLE lehre.tbl_lehrveranstaltung ADD COLUMN lehrauftrag BOOLEAN DEFAULT TRUE;"; - + if (!$db->db_query($qry)) + echo 'lehre.tbl_lehrveranstaltung: ' . $db->db_last_error() . '
'; + else + echo ' lehre.tbl_lehrveranstaltung: Spalte lehrauftrag hinzugefügt.
'; +} //sozialversicherungsnummer auf char(16) erhöhen @@ -676,7 +693,7 @@ if (!$result = @$db->db_query("SELECT status_kurzbz FROM lehre.tbl_studienordnun { $qry = "ALTER TABLE lehre.tbl_studienordnung ADD COLUMN status_kurzbz varchar(32); - ALTER TABLE lehre.tbl_studienordnung ADD CONSTRAINT status_kurzbz FOREIGN KEY (status_kurzbz) REFERENCES addon.tbl_stgv_studienordnungstatus (status_kurzbz) ON DELETE RESTRICT ON UPDATE CASCADE; + ALTER TABLE lehre.tbl_studienordnung ADD CONSTRAINT status_kurzbz FOREIGN KEY (status_kurzbz) REFERENCES lehre.tbl_studienordnungstatus (status_kurzbz) ON DELETE RESTRICT ON UPDATE CASCADE; UPDATE lehre.tbl_studienordnung SET status_kurzbz = 'approved'; "; @@ -806,9 +823,9 @@ if (!$result = @$db->db_query("SELECT 1 FROM public.tbl_bewerbungstermine LIMIT "; if (!$db->db_query($qry)) - echo 'public.tbl_studienordnungstatus: ' . $db->db_last_error() . '
'; + echo 'public.tbl_bewerbungstermine: ' . $db->db_last_error() . '
'; else - echo ' public.tbl_studienordnungstatus: Tabelle hinzugefuegt
'; + echo ' public.tbl_bewerbungstermine: Tabelle hinzugefuegt
'; } //Tabelle lehre.tbl_studienordnungstatus