X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/timetracker.git/blobdiff_plain/afb1ca7aaa68c5b34da82ed58b7e06df1c1525ab..7ca15b5853146dd809f2ad3f5b2e1d9dab4f8dd4:/WEB-INF/lib/ttAdmin.class.php diff --git a/WEB-INF/lib/ttAdmin.class.php b/WEB-INF/lib/ttAdmin.class.php index d6b9696a..6008dcab 100644 --- a/WEB-INF/lib/ttAdmin.class.php +++ b/WEB-INF/lib/ttAdmin.class.php @@ -31,8 +31,8 @@ import('ttUser'); // ttAdmin class is used to perform admin tasks. class ttAdmin { - var $err = null; // Error object, passed to us as reference. - // We use it to communicate errors to caller. + var $err = null; // Error object, passed to us as reference. + // We use it to communicate errors to caller. // Constructor. function __construct(&$err = null) { @@ -65,22 +65,19 @@ class ttAdmin { // Mark user binds as deleted. $sql = "update tt_user_project_binds set status = NULL where user_id = $user_id"; $affected = $mdb2->exec($sql); - if (is_a($affected, 'PEAR_Error')) - return false; + if (is_a($affected, 'PEAR_Error')) return false; // Mark favorite reports as deleted. $sql = "update tt_fav_reports set status = NULL where user_id = $user_id"; $affected = $mdb2->exec($sql); - if (is_a($affected, 'PEAR_Error')) - return false; + if (is_a($affected, 'PEAR_Error')) return false; // Mark user as deleted. global $user; $modified_part = ', modified = now(), modified_ip = '.$mdb2->quote($_SERVER['REMOTE_ADDR']).', modified_by = '.$mdb2->quote($user->id); $sql = "update tt_users set status = NULL $modified_part where id = $user_id"; $affected = $mdb2->exec($sql); - if (is_a($affected, 'PEAR_Error')) - return false; + if (is_a($affected, 'PEAR_Error')) return false; return true; } @@ -104,6 +101,7 @@ class ttAdmin { $affected = $mdb2->exec($sql); if (is_a($affected, 'PEAR_Error')) return false; } + return true; } @@ -183,8 +181,8 @@ class ttAdmin { return true; } - // validateTeamInfo validates team information entered by user. - function validateTeamInfo($fields) { + // validateGroupInfo validates group information entered by user. + function validateGroupInfo($fields) { global $i18n; global $auth; @@ -233,9 +231,9 @@ class ttAdmin { return $result; } - // updateTeam validates user input and updates the team with new information. - function updateTeam($team_id, $fields) { - if (!$this->validateTeamInfo($fields)) return false; // Can't continue as user input is invalid. + // updateGroup validates user input and updates the group with new information. + function updateGroup($team_id, $fields) { + if (!$this->validateGroupInfo($fields)) return false; // Can't continue as user input is invalid. global $user; $mdb2 = getConnection(); @@ -264,21 +262,68 @@ class ttAdmin { return true; } - // setCreatedByAdmin sets created_by field for both group and its top manager to admin account. - function setCreatedByAdmin($team_id, $user_id) { + // validateUserInfo validates account information entered by user. + function validateUserInfo($fields) { + global $i18n; global $user; - $mdb2 = getConnection(); + global $auth; - // Update created_by for group. - $sql = "update tt_teams set created_by = $user->id where id = $team_id"; - $affected = $mdb2->exec($sql); - if (is_a($affected, 'PEAR_Error')) { - $this->err->add($i18n->getKey('error.db')); - return false; + $result = true; + + if (!ttValidString($fields['name'])) { + $this->err->add($i18n->getKey('error.field'), $i18n->getKey('label.person_name')); + $result = false; + } + if (!ttValidString($fields['login'])) { + $this->err->add($i18n->getKey('error.field'), $i18n->getKey('label.login')); + $result = false; + } + // If we change login, it must be unique. + if ($fields['login'] != $user->login) { + if (ttUserHelper::getUserByLogin($fields['login'])) { + $this->err->add($i18n->getKey('error.user_exists')); + $result = false; + } + } + if (!$auth->isPasswordExternal() && ($fields['password1'] || $fields['password2'])) { + if (!ttValidString($fields['password1'])) { + $this->err->add($i18n->getKey('error.field'), $i18n->getKey('label.password')); + $result = false; + } + if (!ttValidString($fields['password2'])) { + $this->err->add($i18n->getKey('error.field'), $i18n->getKey('label.confirm_password')); + $result = false; + } + if ($fields['password1'] !== $fields['password2']) { + $this->err->add($i18n->getKey('error.not_equal'), $i18n->getKey('label.password'), $i18n->getKey('label.confirm_password')); + $result = false; + } + } + if (!ttValidEmail($fields['email'], true)) { + $this->err->add($i18n->getKey('error.field'), $i18n->getKey('label.email')); + $result = false; } - // Update created_by for top manager. - $sql = "update tt_users set created_by = $user->id where id = $user_id"; + return $result; + } + + // updateSelf validates user input and updates admin account with new information. + function updateSelf($fields) { + if (!$this->validateUserInfo($fields)) return false; // Can't continue as user input is invalid. + + global $user; + global $i18n; + $mdb2 = getConnection(); + + // Update self. + $user_id = $user->id; + $login_part = 'login = '.$mdb2->quote($fields['login']); + if ($fields['password1']) + $password_part = ', password = md5('.$mdb2->quote($fields['password1']).')'; + $name_part = ', name = '.$mdb2->quote($fields['name']); + $email_part = ', email = '.$mdb2->quote($fields['email']); + $modified_part = ', modified = now(), modified_ip = '.$mdb2->quote($_SERVER['REMOTE_ADDR']).', modified_by = '.$mdb2->quote($user->id); + $sql = 'update tt_users set '.$login_part.$password_part.$name_part.$email_part.$modified_part.'where id = '.$user_id; $affected = $mdb2->exec($sql); if (is_a($affected, 'PEAR_Error')) { $this->err->add($i18n->getKey('error.db'));