desc = Setting::get ("list/{$this->parent_group_id}", "desc", (isset ($values['desc']) && $values['desc']) ? true : $this->desc); $this->min = Setting::get ("list/{$this->parent_group_id}", "min", (isset ($values['min']) && Base::is_int ($values['min'])) ? $values['min'] : $this->min); $this->max = Setting::get ("list/{$this->parent_group_id}", "max", (isset ($values['max']) && Base::is_int ($values['max'])) ? $values['max'] : $this->max); // Kompatibilitätspatch für Ältere Versionen [END] $this->parent = (isset ($values['parent']) && $values['parent'] instanceof Group) ? $values['parent'] : $this->parent; $this->parent_group_id = (isset ($values['parent_group_id']) && Base::is_int ($values['parent_group_id'])) ? $values['parent_group_id'] : ($this->parent ? ($this->parent->link_id ? $this->parent->link_id : $this->parent->online_id) : $this->parent_group_id); $this->interface = isset ($this->parent->interface) ? $this->parent->interface : $this->interface; $this->name = (isset ($values['name']) && is_string ($values['name'])) ? self::trimmName ($values['name']) : $this->name; $this->url = (isset ($values['url']) && is_string ($values['url'])) ? $values['url'] : ($this->parent ? $this->parent->url : $this->url); $this->desc = Setting::get ("list/{$this->parent_group_id}/{$this->name}", "desc", (isset ($values['desc']) && $values['desc']) ? true : $this->desc, true); $this->min = Setting::get ("list/{$this->parent_group_id}/{$this->name}", "min", (isset ($values['min']) && Base::is_int ($values['min'])) ? $values['min'] : $this->min, true); $this->max = Setting::get ("list/{$this->parent_group_id}/{$this->name}", "max", (isset ($values['max']) && Base::is_int ($values['max'])) ? $values['max'] : $this->max, true); $this->mark_groups = (isset ($values['mark_groups']) && is_bool ($values['mark_groups'])) ? $values['mark_groups'] : $this->mark_groups; // Wenn eingeloggt if (User::get ("id")) { // auf editier Rechte prüfen $this->edit_groups = (isset ($values['edit_groups']) && is_string ($values['edit_groups'])) ? $values['edit_groups'] : (($this->parent) ? $this->parent->edit_groups : $this->edit_groups); // auf vererbte Rechte aus den Settings prüfen $this->getEditGroups ($this->parent_group_id, $this->name); $this->edit_mode = isset ($values['edit_mode']) ? ($values['edit_mode'] & (Base::MODE_VIEW | Base::MODE_EDIT)) : ((($this->parent) ? $this->parent->edit_mode : $this->edit_mode) & Group::getEditMode ("{$this->parent_group_id}_{$this->name}", Base::MODE_VIEW | Base::MODE_EDIT)); } // Eintragsliste holen $this->groups = $this->getGroups ($this->parent_group_id, $this->name, $this->max_follow_links); // Iterator Position initialesieren $this->key = (isset ($values['key']) && Base::is_int ($values['key'])) ? (($values['key'] < 0) ? 0 : (($values['key'] > count ($this->groups)) ? count ($this->groups) : $values['key'])) : (($this->desc) ? ($this->count - 1) : 0); if ($this->editMode) { Base::session_open (); $_SESSION['cms']['list'][$this->parent_group_id][$this->name]['is_list'] = false; Base::session_close (); } } /** * Gibt den Wert für einige Objekt Variablen zurück * * \param name Name der abgefragten Objekt Variable. Definierte namen sind: * - group_id: ID der aktuellen Gruppe * - editMode: true wenn diese Liste im Editiermodus ist, sonst false * - hasNext: prft ob weitere Eintraege folgen * - hasSub: Prüft ob die aktuelle Gruppe Untergruppen hat * - alle privaten Objekt Variablen * * \return Wert der abgefragten Objekt Variable */ public function __get ($name) { switch ($name) { case "group_id": if (isset ($this->groups[$this->key])) { return $this->groups[$this->key]->link_id ? $this->groups[$this->key]->link_id : $this->groups[$this->key]->online_id; } else { Base::error ("Index out of range in List::\$group_id"); } case "editMode": return $this->edit_mode & Base::MODE_EDIT; case "hasNext": $pos = $this->key + (($this->desc) ? -1 : 1); return (!$this->max || (!$this->desc && $pos < $this->max) || ($this->desc && $pos >= ($this->count - $this->max))) ? isset ($this->groups[$pos]) : false; case "hasSub": return $this->groups[$this->key]->hasSub (); default: if (isset ($this->$name)) { return $this->$name; } else { Base::error ("Undefined property: List::\$$name"); } } } /** * Setz den Wert einiger Objekt Variablen * * \param name Name der Objekt Variable die gesetzt werden soll. Definierte namen sind: * - min: Minimale Anzahl von Gruppe (Länge der Liste) * - max: Maximale Anzahl von Gruppe (Länge der Liste) * - key: Aktuelle Position in Liste * - editMode: Der Editiermodus der Liste */ public function __set ($name, $value) { switch ($name) { case "min": $this->min = (Base::is_int ($value)) ? $value : 0; break; case "max": $this->max = (Base::is_int ($value)) ? $value : 0; break; case "key": $this->key = (Base::is_int ($value)) ? (($value < 0) ? 0 : (($value > $this->count) ? $this->count : $value)) : $this->key; break; case "edit_mode": $this->edit_mode = (Base::is_int ($value)) ? $value : Base::MODE_NONE; $this->groups = $this->getGroups ($this->parent_group_id, $this->name, $this->max_follow_links); $this->key = ($this->key > count ($this->groups)) ? count ($this->groups) : $this->key; /* foreach ($this->groups as $row) { $row->edit_mode = $this->edit_mode; } */ break; } } /** * Prüft ob eine Objekt Variable gesetzt ist * * \param name Name der Objekt Variable * * \return true wenn die Objekt Variable gesetzt ist, sonst false */ public function __isset ($name) { return isset ($this->$name); } /** * Löscht eine Objekt Variable * * \param name Name der Objekt Variable */ public function __unset ($name) { switch ($name) { case "min": $this->min = 0; break; case "max": $this->max = 0; break; case "key": $this->key = ($this->desc) ? ($this->count - 1) : 0; break; case "edit_mode": $this->edit_mode = Base::MODE_NONE; foreach ($this->groups as $row) { $row->edit_mode = Base::MODE_NONE; } break; } } /** * Setzt den den Iterator auf die erste Gruppe */ public function rewind () { $this->key = ($this->desc) ? ($this->count - 1) : 0; } /** * Setzt den den Iterator auf eine bestimmte Gruppe * * \param key Schlüssel der Gruppe */ public function seek ($key) { $this->key = ($this->desc) ? ($this->count - 1) : 0; } /** * Liefert die aktuelle Gruppe * * \return aktuelle Gruppe */ public function current () { return isset ($this->groups[$this->key]) ? $this->groups[$this->key] : $this->newGroup (); } /** * Liefert den Schlüssel zur aktuellen Gruppe * * \return Schlüssel der aktuellen Gruppe */ public function key () { return $this->key; } /** * Setzt den Iterator auf die nächste Gruppe und liefert diese zurück * * \return nächste Gruppe */ public function next () { if ($this->editMode) { Base::session_open (); $_SESSION['cms']['list'][$this->parent_group_id][$this->name]['is_list'] = true; Base::session_close (); } $this->key += ($this->desc) ? -1 : 1; return (!$this->max || (!$this->desc && $this->key < $this->max) || ($this->desc && $this->key >= ($this->count - $this->max))) ? ((isset ($this->groups[$this->key])) ? $this->groups[$this->key] : $this->newGroup ()) : $this->newGroup (); } /** * Prüft ob die Gruppe auf den der Iterator zeigt existiert * * \return true wenn die Gruppe existiert, sonst false */ public function valid () { $valid = (!$this->max || (!$this->desc && $this->key < $this->max) || ($this->desc && $this->key >= ($this->count - $this->max))) ? isset ($this->groups[$this->key]) : false; // Tag für hervorhebung einer Gruppe setzen if ($this->mark_groups) { if (isset ($this->mark_groups['after'])) { echo $this->mark_groups['after']; unset ($this->mark_groups['after']); } if ($valid) { $this->mark_groups = $this->groups[$this->key]->mark (); echo $this->mark_groups['before']; } } return $valid; } /** * Prüft ob eine Position in der Liste existiert \n * Bsp.: if ($liste[3]) * * \param pos Position in der Liste * * \return true wenn die Position in der Liste existiert, sonst false */ public function offsetExists ($pos) { return isset ($this->groups[$pos]); } /** * Liefert die Gruppe an eine Position in der Liste \n * Bsp.: $group = $liste[3] * * \param pos Position in der Liste * * \return Gruppe an der Position in der Liste */ public function offsetGet ($pos) { if ($pos && $this->editMode) { Base::session_open (); $_SESSION['cms']['list'][$this->parent_group_id][$this->name]['is_list'] = true; Base::session_close (); } $this->groups[$pos] = isset ($this->groups[$pos]) ? $this->groups[$pos] : $this->newGroup (); return $this->groups[$pos]; } /** * Setzt eine Gruppe an eine Position in der Liste \n * Bsp.: $liste[3] = $group_id; * * \param pos Position in der Liste * \param group Gruppe die zugewiesen werden soll * * \return bei Erfolg die Gruppe, sonst false */ public function offsetSet ($pos, $group) { return $this->insertGroup ($pos, $group); } /** * Löscht eine Position in der Liste \n * Bsp.: unset ($liste[3]) * * \param pos Position in der Liste */ public function offsetUnset ($pos) { $this->delGroup ($pos); } /** * Liefert die Länge der Liste \n * Bsp.: count ($liste) */ public function count () { return $this->count; } /** * Entfernd aus einem Namen alle für Listennamen unerlaupten Zeichen * * \param name Name der Normiert werdn soll * * \return Normierter Listenname */ public static function trimmName ($name) { return preg_replace ("/^[^a-zA-Z]+|[^a-zA-Z0-9- ]/s", "", $name); } /** * Setzt die User-Gruppen die in dieser Liste Editierrechte haben * * \param parent_group_id ID der Parent Gruppe * \param name Name der Gruppe */ private function getEditGroups ($parent_group_id, $name, $parents=array()) { if ($parent_group_id) { // Kompatibilitätspatch für ältere Versionen [START] $additional = Setting::get ("list/$parent_group_id", "additional", false); $inherit = Setting::get ("list/$parent_group_id", "inherit"); $edit_groups = Setting::get ("list/$parent_group_id", "edit_groups"); // Kompatibilitätspatch für ältere Versionen [END] $additional = Setting::get ("list/$parent_group_id/$name", "additional", $additional); $inherit = Setting::get ("list/$parent_group_id/$name", "inherit", $inherit); $edit_groups = Setting::get ("list/$parent_group_id/$name", "edit_groups", $edit_groups); if ($additional || $additional===false) { // auf vererbte Rechte prüfen $group = Group::getParent ($parent_group_id); if ($group && !in_array ($group['id'], $parents)) { $parents[] = $group['id']; $this->getEditGroups ($group['id'], $group['name'], $parents); } } if ($edit_groups && ($inherit || $parent_group_id == $this->parent_group_id)) { // rechte sollen vererbt werden, oder gehören zur aktuellen liste $this->edit_groups = ($additional) ? "{$this->edit_groups},$edit_groups" : $edit_groups; } } } /** * Alle Gruppen dieser Lieste holen * * \param parent_id Id der parent Gruppe * \param name name der Gruppe * \param follow_link Maximale Verschachtelungstiefe beim aufloesen von Links * \param src_id Gibt bei einer Linkverfolgung die id des Eintrages an, der den Links enthält * * \return Array mit Gruppen */ protected function getGroups ($parent_id, $name, $follow_link, $src_id=0) { $groups = array (); if ($this->name) { $follow_link--; foreach (Group::getChildList ($parent_id, $name, false, $this->edit_mode) as $pos => $row) { if ($row['link_group_id'] < 0 && $follow_link >= 0) { // Liste von Links einbinden $parent = Group::getParent (-$row['link_group_id']); if (!$parent) { // Linkziel existiert nicht mehr $group = $this->newGroup ($row['id']); $group->del (); $group->setStatus (Base::STATUS_ONLINE); } else { $links = $this->getGroups ($parent['id'], $parent['name'], $follow_link, $row['id']); array_splice ($groups, $pos, 0, $links); } } else if ($row['link_group_id'] > 0) { // Link einbinden array_push ($groups, $this->newGroup ($row['id'], $row['link_group_id'])); } else if ($src_id) { // Grupe ist ein Link array_push ($groups, $this->newGroup ($src_id, $row['online_group_id'] ? $row['online_group_id'] : $row['id'])); } else { // Grupe array_push ($groups, $this->newGroup ($row['id'])); } } } if (!$src_id) { if ($this->edit_mode & Base::MODE_EDIT && (User::getEditRight ($this->edit_groups) & Base::MODE_EDIT)) { array_push ($groups, $this->newGroup ()); } $this->count = count ($groups); if ($this->count < $this->min) { $groups = array_pad ($groups, $this->min, $this->newGroup ()); $this->count = $this->min; } } return $groups; } /** * Aktualesiert die Gruppen Liste */ public function updateGroups () { $this->groups = $this->getGroups ($this->parent_group_id, $this->name, $this->max_follow_links); } /** * Verschiebt eine Gruppe in diese Liste * * \param pos Position vor der die Gruppe eingefügt werden soll * \param id Id der Gruppe die verschoben werden soll * * \return ID der Gruppe die verschoben wurde */ protected function moveGroup ($pos=NULL, $id=0) { $pos = ($pos === NULL) ? $this->count () : $pos; $history = new History ("group move"); $history->groupStart (); $group = $this->newGroup ($id); $group->move ($this->groups[$pos]->id); $this->groups = array_splice ($this->groups, $pos, 0, $group); $this->count++; foreach ($this->groups as $pos => $group) { if ($group->id == $id) { $this->delEntrie ($pos); } } $history->groupEnd (); return $group->id; } /** * Kopiert eine Gruppe und fügt diesen vor der angegebenen Position ein * * \param pos Position vor der der Eintrag eingefgt werden soll * \param group Gruppe oder id einer Gruppe die kopiert werden soll * \param link Gibt an ob ein link erstellt werden soll anstatt einer Kopie * * \return die neuen Gruppe */ protected function insertGroup ($pos=NULL, $group=null, $link=false) { $pos = ($pos === NULL) ? $this->count () : $pos; $history = new History ("group insert"); $history->groupStart (); $newGroup = $this->newGroup (); if ($link) { $newGroup->setLink ($group instanceof Group ? $group->id : $group); } else { $newGroup->set ($group instanceof Group ? $group->id : $group); } $newGroup->move (isset ($this->groups[$pos]) ? $this->groups[$pos]->id : 0); array_splice ($this->groups, $pos, 0, array ($newGroup)); $this->count++; $history->groupEnd (); return $newGroup; } /** * loescht die Gruppe, der sich an der angegebenen Position befindet * * \param pos Position der Gruppe die gelöscht werden soll */ protected function delGroup ($pos) { if (isset ($this->groups[$pos])) { $this->groups[$pos]->del (); unset ($this->groups[$pos]); $this->count = count ($this->groups); if ($this->count < $this->min) { $this->groups[] = $this->newGroup (); $this->count++; } } } /** * Stellt die Gruppe online/offline, die sich an der angegebenen Position befindet * * \param pos Position der Gruppe die geloescht werden soll * \param status Status der gesetzt werden soll (Online, Offline) * * \return Der neue Status der Gruppe */ protected function statusGroup ($pos, $status) { return $this->groups[$pos]->setStatus ($status); } /** * Erzeugt ein neues Group Objekt (aber noch keinen Eintrag in der DB) * * \param id Id des Eintrages (wenn Null wird ein lehres Objekt erstellt) * \param link_id zeigt an ob es sich bei dem Objekt um einen Link handelt * * \return Die neue Gruppe */ private function newGroup ($id=0, $link_id=0) { require_once (dirname(__FILE__)."/../".strtolower ($this->interface)."/".strtolower ($this->interface).".inc.php"); $GroupClass = "Group".$this->interface; return new $GroupClass (array ('id' => $id, 'link_id' => $link_id, 'parent_id' => $this->parent_group_id, 'list' => $this, 'name' => $this->name, 'url' => $this->url, 'edit_mode' => $this->edit_mode, 'edit_groups' => $this->edit_groups)); } /** * Kopiert eine Gruppe und fügt diese vor der aktuellen ein * * \param group Gruppe die kopiert werden soll * * \return Die neue Gruppe */ public function insert ($group=null) { return $this->insertGroup ($this->key, $group); } /** * Fügt einen Link auf die angegebene Gruppe vor der aktuellen ein * * \param group Gruppe die verlinkt werden soll * * \return Die neue Gruppe */ public function insertLink ($group=null) { return $this->insertGroup ($this->key, $group); } /** * Kopiert alle Gruppen der Liste, der die angegebene Gruppe angehört, und fuegt diese vor der aktuellen ein * * \param id Id der Gruppe dessen Liste kopiert werden soll * * \return true wenn Kopieren erfolgreich war, sonst false */ public function insertAll ($id=0) { $history = new History ("group insert all"); $history->groupStart (); $ok = false; if ($parent = Group::getParent ($id)) { $ok = true; foreach (Group::getChildList ($parent['id'], $parent['name']) as $group) { $group = $this->insertGroup ($this->key, $group['id']); if (!$group->id) { $ok = false; } } } $history->groupStop(); return $ok; } /** * Verschiebt die angegebenen Gruppe vor die aktuelle Position * * \param id Id der Gruppe die verschoben werden soll * * \return ID der Gruppe */ public function move ($id=0) { return $this->moveGroup ($this->key, $id); } /** * Loescht die aktuelle Gruppe */ public function delete () { $this->delGroup ($this->key); } /** * Stellt die aktuelle Gruppe online/offline * * \param status Status der gesetzt werden soll (Online, Offline) * * \return Der neue Status der Gruppe */ public function setStatus ($status) { return $this->statusGroup ($this->key, $status); } /** * Stellt alle Gruppen der Liste, der die angegebene Gruppe angehoert, online/offline * * \param status Status der gesetzt werden soll (STATUS_ONLINE, STATUS_OFFLINE) * * \return true wenn die Aktion erfolgreich war, sonst false */ public function statusAll ($status) { $history = new History ("group set all online"); $history->groupStart (); $ok = true; foreach ($this->groups as $group) { if ($group->id && !$this->statusGroup ($this->key, $status)) { $ok = false; } } $history->groupStop(); return $ok; } /** * Liefert den String zum anzeigen eines Editierdots zum umschalten des Editier Modus * * \return String zum anzeigen eines Editierdots */ public function edit () { $group = ($this->count) ? $this->groups[0] : $this->newGroup (); return $group->edit (); } } ?>