X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/timetracker.git/blobdiff_plain/1d5c3f76d103fb5d6a91587060438e936c0124b5..4d07dc7fef357e5139f35df6271cc15dc6bea955:/WEB-INF/lib/ttRoleHelper.class.php diff --git a/WEB-INF/lib/ttRoleHelper.class.php b/WEB-INF/lib/ttRoleHelper.class.php index 08e1a218..7e103943 100644 --- a/WEB-INF/lib/ttRoleHelper.class.php +++ b/WEB-INF/lib/ttRoleHelper.class.php @@ -50,6 +50,40 @@ class ttRoleHelper { return false; } + // The getRoleByName looks up a role by name. + static function getRoleByName($role_name) { + + $mdb2 = getConnection(); + global $user; + + $sql = "select id from tt_roless where team_id = $user->team_id and name = ". + $mdb2->quote($role_name)." and (status = 1 or status = 0)"; + $res = $mdb2->query($sql); + + if (!is_a($res, 'PEAR_Error')) { + $val = $res->fetchRow(); + if ($val['id']) + return $val; + } + return false; + } + + // update function updates a role in the database. + static function update($fields) { + global $user; + $mdb2 = getConnection(); + + $id = (int)$fields['id']; + if (isset($fields['name'])) $name_part = 'name = '.$mdb2->quote($fields['name']); + if (isset($fields['description'])) $descr_part = ', description = '.$mdb2->quote($fields['description']); + if (isset($fields['status'])) $status_part = ', status = '.(int)$fields['status']; + if (isset($fields['rights'])) $rights_part = ', rights = '.$mdb2->quote($fields['rights']); + $parts = trim($name_part.$descr_part.$status_part.$rights_part, ','); + $sql = "update tt_roles set $parts where id = $id and team_id = $user->team_id"; + $affected = $mdb2->exec($sql); + return (!is_a($affected, 'PEAR_Error')); + } + // delete - marks the role as deleted. static function delete($role_id) { global $user;