X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=WEB-INF%2Flib%2FttTeamHelper.class.php;h=6dede8b23f66420a88371e14335527a4bd09d314;hb=f340e538c5e269b9035905e808220a5683b079c4;hp=60be9b53c3e435bc41e8fc7b8488bc01cb6a5d69;hpb=5f8dbb1200edc65ce3aed3fb1bc2fde0a4d3a156;p=timetracker.git diff --git a/WEB-INF/lib/ttTeamHelper.class.php b/WEB-INF/lib/ttTeamHelper.class.php index 60be9b53..6dede8b2 100644 --- a/WEB-INF/lib/ttTeamHelper.class.php +++ b/WEB-INF/lib/ttTeamHelper.class.php @@ -103,23 +103,68 @@ class ttTeamHelper { return $user_list; } - // The getUsers obtains all active and inactive (but not deleted) users in a given team. - static function getUsers() { + // The swapRolesWith swaps existing user role with that of another user. + static function swapRolesWith($user_id) { global $user; $mdb2 = getConnection(); - $sql = "select id, name from tt_users where team_id = $user->team_id and (status = 1 or status = 0) order by upper(name)"; + $sql = "select u.id, u.role_id from tt_users u left join tt_roles r on (u.role_id = r.id) where u.id = $user_id and u.team_id = $user->team_id and u.status = 1 and r.rank < $user->rank"; + $res = $mdb2->query($sql); + if (is_a($res, 'PEAR_Error')) + return false; + $val = $res->fetchRow(); + if (!$val['id'] || !$val['role_id']) + return false; + + // Promote user. + $sql = "update tt_users set role_id = $user->role_id where id = $user_id and team_id = $user->team_id"; + $affected = $mdb2->exec($sql); + if (is_a($affected, 'PEAR_Error')) return false; + + // Demote self. + $role_id = $val['role_id']; + $sql = "update tt_users set role_id = $role_id where id = $user->id and team_id = $user->team_id"; + $affected = $mdb2->exec($sql); + if (is_a($affected, 'PEAR_Error')) return false; + + return true; + } + + // The getUsersForSwap obtains all users a current user can swap roles with. + static function getUsersForSwap() { + global $user; + $mdb2 = getConnection(); + + $sql = "select u.id, u.name, r.rank, r.rights from tt_users u left join tt_roles r on (u.role_id = r.id) where u.team_id = $user->team_id and u.status = 1 and r.rank < $user->rank order by upper(u.name)"; $res = $mdb2->query($sql); $user_list = array(); if (is_a($res, 'PEAR_Error')) return false; while ($val = $res->fetchRow()) { + $isClient = in_array('track_own_time', explode(',', $val['rights'])) ? 0 : 1; // Clients do not have data entry right. + if ($isClient) + continue; // Skip adding clients. $user_list[] = $val; } return $user_list; } + // The getUsers obtains all active and inactive (but not deleted) users in a given team. + static function getUsers() { + global $user; + $mdb2 = getConnection(); + $sql = "select id, name from tt_users where team_id = $user->team_id and (status = 1 or status = 0) order by upper(name)"; + $res = $mdb2->query($sql); + $user_list = array(); + if (is_a($res, 'PEAR_Error')) + return false; + while ($val = $res->fetchRow()) { + $user_list[] = $val; + } + return $user_list; + } + // The getInactiveUsers obtains all inactive users in a given team. static function getInactiveUsers($team_id, $all_fields = false) { $mdb2 = getConnection(); @@ -822,6 +867,7 @@ class ttTeamHelper { // The update function updates team information. static function update($team_id, $fields) { + global $user; $mdb2 = getConnection(); $name_part = 'name = '.$mdb2->quote($fields['name']); $currency_part = ''; @@ -852,10 +898,11 @@ class ttTeamHelper { if (isset($fields['config'])) $config_part = ', config = '.$mdb2->quote($fields['config']); if (isset($fields['lock_spec'])) $lock_spec_part = ', lock_spec = '.$mdb2->quote($fields['lock_spec']); if (isset($fields['workday_minutes'])) $workday_minutes_part = ', workday_minutes = '.$mdb2->quote($fields['workday_minutes']); + $modified_part = ', modified = now(), modified_ip = '.$mdb2->quote($_SERVER['REMOTE_ADDR']).', modified_by = '.$mdb2->quote($user->id); $sql = "update tt_teams set $name_part $currency_part $lang_part $decimal_mark_part $date_format_part $time_format_part $week_start_part $tracking_mode_part $task_required_part $record_type_part - $bcc_email_part $plugins_part $config_part $lock_spec_part $workday_minutes_part where id = $team_id"; + $bcc_email_part $plugins_part $config_part $lock_spec_part $workday_minutes_part $modified_part where id = $team_id"; $affected = $mdb2->exec($sql); if (is_a($affected, 'PEAR_Error')) return false;