diff --git a/include/basis.class.php b/include/basis.class.php index b139e5d98..9c52ad9ad 100644 --- a/include/basis.class.php +++ b/include/basis.class.php @@ -58,5 +58,22 @@ class basis { return ($var!=''?"'".addslashes($var)."'":'null'); } + + /** + * Splittet ein Array auf um es zB in der IN Klausel eines SQL Befehles zu verwenden + * Die einzelnen Elemente werden unter Hochkomma gesetzt und mit Beistrich getrennt. + * @param $array + */ + public function implode4SQL($array) + { + $string = ''; + foreach($array as $row) + { + if($string!='') + $string.=','; + $string.="'".addslashes($row)."'"; + } + return $string; + } } ?> \ No newline at end of file diff --git a/include/benutzerberechtigung.class.php b/include/benutzerberechtigung.class.php index e50a97755..525096df2 100644 --- a/include/benutzerberechtigung.class.php +++ b/include/benutzerberechtigung.class.php @@ -786,6 +786,95 @@ class benutzerberechtigung extends basis_db sort($oe_kurzbz); return $oe_kurzbz; } + + /** + * Gibt Array mit den Kostenstellen zurueck fuer welche die + * Person eine Berechtigung besitzt. + * Optional wird auf Berechtigung eingeschraenkt. + */ + public function getKostenstelle($berechtigung_kurzbz=null) + { + $oe_kurzbz=array(); + $not = array(); + $not_id = array(); + $kst_id = array(); + $kostenstellen = array(); + $timestamp=time(); + $all=false; + $oe = new organisationseinheit(); + foreach ($this->berechtigungen as $b) + { + if (($berechtigung_kurzbz==$b->berechtigung_kurzbz || $berechtigung_kurzbz==null || mb_substr($berechtigung_kurzbz,0,mb_strpos($berechtigung_kurzbz,':'))==$b->berechtigung_kurzbz) + && (($timestamp>$b->starttimestamp || $b->starttimestamp==null) && ($timestamp<$b->endetimestamp || $b->endetimestamp==null))) + { + if($b->negativ) + { + //Negativ-Recht + if(!is_null($b->oe_kurzbz)) + { + $childoes = $oe->getChilds($b->oe_kurzbz); + foreach($childoes as $row) + $not[] = $row; + } + elseif($b->kostenstelle_id!='') + { + $not_id[] = $b->kostenstelle_id; + } + else + return array(); + } + else + { + if(!is_null($b->oe_kurzbz)) + { + $childoes = $oe->getChilds($b->oe_kurzbz); + foreach($childoes as $row) + $oe_kurzbz[] = $row; + } + elseif($b->kostenstelle_id!='') + { + $kst_id[]=$b->kostenstelle_id; + } + else + { + $all=true; + break; + } + } + } + } + + $qry = "SELECT distinct kostenstelle_id FROM wawi.tbl_kostenstelle"; + + if(!$all) + { + $qry.=" + WHERE + ("; + if(count($kst_id)>0) + $qry.=" kostenstelle_id IN(".$this->implode4SQL($kst_id).")"; + if(count($oe_kurzbz)>0) + { + if(count($kst_id)>0) + $qry.= ' OR '; + $qry.=" oe_kurzbz IN(".$this->implode4SQL($oe_kurzbz).")"; + } + $qry.=")"; + if(count($not_id)>0) + $qry.=" AND kostenstelle_id NOT IN(".$this->implode4SQL($not_id).")"; + if(count($not)>0) + $qry.=" AND oe_kurzbz NOT IN(".$this->implode4SQL($not).")"; + } + + if($result = $this->db_query($qry)) + { + while($row = $this->db_fetch_object($result)) + { + $kostenstellen[] = $row->kostenstelle_id; + } + } + return $kostenstellen; + } } ?> \ No newline at end of file diff --git a/include/wawi_kostenstelle.class.php b/include/wawi_kostenstelle.class.php index 32e4b45bb..c274ade6c 100644 --- a/include/wawi_kostenstelle.class.php +++ b/include/wawi_kostenstelle.class.php @@ -490,4 +490,41 @@ class wawi_kostenstelle extends basis_db return false; } } + + /** + * Laedt die Kostenstellen die als Array uebergeben werden + */ + public function loadArray($array) + { + $qry = 'SELECT * FROM wawi.tbl_kostenstelle WHERE kostenstelle_id IN('.$this->implode4SQL($array).');'; + + if(!$this->db_query($qry)) + { + $this->errormsg = 'Fehler bei der Datenbankabfrage.'; + return false; + } + + while($row = $this->db_fetch_object()) + { + $obj = new wawi_kostenstelle(); + + $obj->kostenstelle_id = $row->kostenstelle_id; + $obj->oe_kurzbz = $row->oe_kurzbz; + $obj->bezeichnung = $row->bezeichnung; + $obj->kurzbz = $row->kurzbz; + $obj->aktiv = ($row->aktiv=='t'?true:false); + $obj->budget = $row->budget; + $obj->updateamum = $row->updateamum; + $obj->updatevon = $row->updatevon; + $obj->insertamum = $row->insertamum; + $obj->insertvon = $row->insertvon; + $obj->ext_id = $row->ext_id; // ext_id = kostenstelle_id + $obj->kostenstelle_nr = $row->kostenstelle_nr; + $obj->deaktiviertamum = $row->deaktiviertamum; + $obj->deaktiviertvon = $row->deaktiviertvon; + + $this->result[] = $obj; + } + return true; + } } \ No newline at end of file