active = &$_SESSION['cms']['edit']['user_management']['activ_id']; if ($this->active) { $this->user = $this->user (); } $this->status = $this->status (); } //*************************** // GETTER / SETTER //*************************** public function __get ($name) { switch ($name) { case "edit_groups": $userGroups = User::get ("groups"); $allGroups = User::getEditGroups (true); $groups = array (); if (isset ($userGroups['all']) || User::get ("is_admin")) { $groups = $allGroups; } else { foreach ($allGroups as $group => $name) { if (isset ($userGroups[$group]) || $group=="self") { $groups[$group] = $name; } } } return $groups; case "is_admin": return User::get ("is_admin"); case "may_edit_users": return User::get ("is_admin") || User::get ("may_edit_users"); case "may_make_backups": return User::get ("is_admin") || User::get ("may_make_backups"); case "may_edit_i18n": return User::get ("is_admin") || User::get ("may_edit_i18n"); default: return $this->$name; } } public function __set ($name, $value) { } private function status () { $status['has_ldap_user'] = false; foreach (User::getList () as $key => $row) { $status['has_ldap_user'] |= $row['status'] & User::STATUS_LDAP_USER; } $status['values'] = User::getList ($this->active); if (isset ($status['values'][0])) { $status['values'] = $status['values'][0]; $status['values']['password'] = $status['values']['password'] ? "****" : ""; } $status['values']['may_make_backups'] = isset ($status['values']['may_make_backups']) ? $status['values']['may_make_backups'] : ""; $status['values']['may_edit_i18n'] = isset ($status['values']['may_edit_i18n']) ? $status['values']['may_edit_i18n'] : ""; $status['values']['ldap_user'] = isset ($status['values']['status']) ? ($status['values']['status'] & User::STATUS_LDAP_USER) : 0; $status['messages'] = array (); $status['quickbar']['disabledButtons']['save'] = true; if (!History::getFirstUndo ($this->active, "user", false)) { $status['quickbar']['disabledButtons']['undo'] = true; } if (!History::getFirstRedo ($this->active, "user", false)) { $status['quickbar']['disabledButtons']['redo'] = true; } $status['quickbar']['disabledButtons']['delete'] = !$this->active; $status['statusbar']['value'] = ""; // Elementname, User, letzte Änderung,... if (User::get ("is_admin")) { $status['statusbar']['value'] .= " #{$this->active}"; } return $status; } public function user () { if ($this->active == -1) { $user = array ('id' => 0, 'realname' => "", 'username' => "", 'password' => "", 'groups' => "", 'may_edit_users' => "", 'may_make_backups' => "", 'may_edit_i18n' => "", 'is_admin' => "", 'ldap_user' => false); } else { $user = User::getList ($this->active); $user['may_make_backups'] = isset ($user['may_make_backups']) ? $user['may_make_backups'] : ""; $user['may_edit_i18n'] = isset ($user['may_edit_i18n']) ? $user['may_edit_i18n'] : ""; $user['password'] = $user['password'] ? "****" : ""; $user['ldap_user'] = $user['status'] & User::STATUS_LDAP_USER; } return $user; } public function userList () { $values = User::getList (); foreach ($values as $key => $row) { $values[$key]['may_make_backups'] = isset ($values[$key]['may_make_backups']) ? $values[$key]['may_make_backups'] : ""; $values[$key]['may_edit_i18n'] = isset ($values[$key]['may_edit_i18n']) ? $values[$key]['may_edit_i18n'] : ""; $values[$key]['password'] = $row['password'] ? "****" : ""; $values[$key]['ldap_user'] = $row['status'] & User::STATUS_LDAP_USER; } return $values; } public function addNewUser () { $this->active = -1; } public function select ($id) { $this->active = $id; } public function save ($values) { if (isset ($values['password'])) { if (strlen ($values['password']) < 6) { return $this->message ("password is to short"); } if (!preg_match ("/[a-zA-Z]+(\W|\d)|(\W|\d)+[a-zA-Z]/", $values['password'])) { return $this->message ("password must contain a-Z and 0-9 or special characters"); } } if (!$this->active && empty ($values['username'])) { return $this->message ("username missing"); } if (User::set ($this->active, $values) == -1) { return $this->message ("username already exists"); } else { $this->select (0); } } public function del () { User::del ($this->active); $this->active = 0; } public function undo () { if ($undo = History::getFirstUndo ($this->active, "user", false)) { History::restore ($undo['id']); $this->status = $this->status (); } } public function redo () { if ($undo = History::getFirstRedo ($this->active, "user", false)) { History::restore ($undo['id']); $this->status = $this->status (); } } public function message ($text) { return I18n::tr ("edit", "user_management/$text", $text); } // Wandelt das gegebene Array/Text in eine Form um, die direkt einer JavaScript Variablen zugewiesen werden kann public function toJavaScript ($value) { if (is_array ($value)) { $values = array (); foreach ($value as $key => $val) { $values[] = "'$key':".$this->toJavaScript ($val); } return "{".implode (",", $values)."}"; } else { $value = Database::escape ($value); return ($value===true) ? "true" : (($value===false) ? "false" : "'$value'"); } } } ?>