}
// getRoleByRank looks up a role by its rank.
- static function getRoleByRank($rank) {
+ static function getRoleByRank($rank, $team_id) {
global $user;
$mdb2 = getConnection();
$rank = (int) $rank; // Cast to int just in case for better security.
- $sql = "select id from tt_roles where team_id = $user->team_id and rank = $rank and (status = 1 or status = 0)";
+ $sql = "select id from tt_roles where team_id = $team_id and rank = $rank and (status = 1 or status = 0)";
$res = $mdb2->query($sql);
if (!is_a($res, 'PEAR_Error')) {
return true;
}
- // rolesExist - checks whether roles for team already exist.
- static function rolesExist()
- {
- $mdb2 = getConnection();
- global $user;
-
- $sql = "select count(*) as count from tt_roles where team_id = $user->team_id";
- $res = $mdb2->query($sql);
- if (!is_a($res, 'PEAR_Error')) {
- $val = $res->fetchRow();
- if ($val['count'] > 0)
- return true; // Roles for team exist.
- }
- return false;
- }
-
// createPredefinedRoles - creates a set of predefined roles for the team to use.
static function createPredefinedRoles($team_id, $lang)
{
}
return false;
}
-
- // migrateLegacyRole makes changes to user database record and assigns a user to
- // one of pre-defined roles, which are created if necessary.
- // No changes to $this instance are done.
- function migrateLegacyRole() {
- // Do nothing if we already have a role_id.
- if ($this->role_id) return false;
-
- // Create default roles if necessary.
- import ('ttRoleHelper');
- if (!ttRoleHelper::rolesExist()) ttRoleHelper::createDefaultRoles(); // TODO: refactor or remove after roles revamp.
-
- // Obtain new role id based on legacy role.
- $role_id = ttRoleHelper::getRoleByRank($this->legacy_role);
- if (!$role_id) return false; // Role not found, nothing to do.
-
- $mdb2 = getConnection();
- $sql = "update tt_users set role_id = $role_id where id = $this->id and team_id = $this->team_id";
- $affected = $mdb2->exec($sql);
- if (is_a($affected, 'PEAR_Error'))
- return false;
-
- return true;
- }
}
<br>
<table cellspacing="0" cellpadding="4" width="100%" border="0">
<tr>
- <td align="center"> Anuko Time Tracker 1.17.45.4080 | Copyright © <a href="https://www.anuko.com/lp/tt_3.htm" target="_blank">Anuko</a> |
+ <td align="center"> Anuko Time Tracker 1.17.45.4081 | Copyright © <a href="https://www.anuko.com/lp/tt_3.htm" target="_blank">Anuko</a> |
<a href="https://www.anuko.com/lp/tt_4.htm" target="_blank">{$i18n.footer.credits}</a> |
<a href="https://www.anuko.com/lp/tt_5.htm" target="_blank">{$i18n.footer.license}</a> |
<a href="https://www.anuko.com/lp/tt_7.htm" target="_blank">{$i18n.footer.improve}</a>
require_once('initialize.php');
import('ttUserHelper');
import('ttTaskHelper');
-import('ttUser');
+import('ttRoleHelper');
// setChange - executes an sql statement. TODO: rename this function to something better.
// Better yet, redo the entire thing and make an installer.
$mdb2 = getConnection();
- $sql = "select u.id, u.status from tt_users u inner join `tt_site_config` sc on (sc.param_name = 'version_db' and sc.param_value = '1.17.44') where u.role_id is NULL and u.status is NOT NULL";
+ $sql = "select u.id, u.team_id, u.role, u.status, t.lang from tt_users u inner join `tt_site_config` sc on (sc.param_name = 'version_db' and sc.param_value = '1.17.44') left join tt_teams t on (u.team_id = t.id) where u.role_id is NULL and u.status is NOT NULL";
$res = $mdb2->query($sql);
- if (is_a($res, 'PEAR_Error')) {
- die($res->getMessage());
- }
+ if (is_a($res, 'PEAR_Error')) die($res->getMessage());
$users_updated = 0;
// Iterate through users.
while ($val = $res->fetchRow()) {
$user_id = $val['id'];
+ $team_id = $val['team_id'];
+ $lang = $val['lang'];
+ $legacy_role = $val['role'];
+
+ $sql = "select count(*) as count from tt_roles where team_id = $team_id";
+ $result = $mdb2->query($sql);
+ if (is_a($result, 'PEAR_Error')) die($result->getMessage());
+ $row = $result->fetchRow();
+ if ($row['count'] == 0)
+ ttRoleHelper::createPredefinedRoles($team_id, $lang);
- // Code only works on active users. Temporarily activate a user.
- $deactivate = false;
- if ($val['status'] == 0) {
- $deactivate = true; // To deactivate later.
- $sql = "update tt_users set status = 1 where id = $user_id";
- $mdb2->exec($sql);
- }
-
- $user = new ttUser(null, $user_id);
- $i18n = new I18n();
- $i18n->load($val['lang']);
- if ($user->login)
- $user->migrateLegacyRole();
+ // Obtain new role id based on legacy role.
+ $role_id = ttRoleHelper::getRoleByRank($legacy_role, $team_id);
+ if (!$role_id) continue; // Role not found, nothing to do.
- if ($deactivate) {
- // Deactivate temporarily activated user back.
- $sql = "update tt_users set status = 0 where id = $user_id";
- $mdb2->exec($sql);
- }
+ $sql = "update tt_users set role_id = $role_id where id = $user_id and team_id = $team_id";
+ $affected = $mdb2->exec($sql);
+ if (is_a($affected, 'PEAR_Error')) die($affected->getMessage());
- unset($user);
- unset($i18n);
$users_updated++;
// if ($users_updated >= 1000) break; // TODO: uncomment for large user sets to run multiple times.
}
if (!ttValidString($cl_description, true)) $err->add($i18n->getKey('error.field'), $i18n->getKey('label.description'));
if ($err->no()) {
- $existing_role = ttRoleHelper::getRoleByRank($cl_rank);
+ $existing_role = ttRoleHelper::getRoleByRank($cl_rank, $user->team_id);
if (!$existing_role) {
// Insert a role with default user rights.
if (ttRoleHelper::insert(array(
exit();
}
-// If there are no roles in team, introduce default ones.
-if (!ttRoleHelper::rolesExist()) ttRoleHelper::createDefaultRoles(); // TODO: refactor or remove after roles revamp.
-
$smarty->assign('active_roles', ttTeamHelper::getActiveRoles($user->team_id));
$smarty->assign('inactive_roles', ttTeamHelper::getInactiveRoles($user->team_id));
$smarty->assign('title', $i18n->getKey('title.roles'));
$cl_email = $user_details['email'];
$cl_rate = str_replace('.', $user->decimal_mark, $user_details['rate']);
$cl_role = $user_details['role_id'];
-
- // In case role_id is not yet assigned...
- if (!$cl_role && $user_details['role'])
- $cl_role = ttRoleHelper::getRoleByRank($user_details['role']); // TODO: remove after roles revamp.
-
$cl_client_id = $user_details['client_id'];
$cl_status = $user_details['status'];
$cl_projects = array();
// Get users.
$active_users = ttTeamHelper::getActiveUsers(array('getAllFields'=>true));
if($user->canManageTeam()) {
-
- // If there are no roles in team, introduce default ones.
- if (!ttRoleHelper::rolesExist()) ttRoleHelper::createDefaultRoles(); // TODO: refactor or remove after roles revamp.
- // This is here temporarily so that we have roles to work with to manage users.
- // Normally, this should be done during an upgrade step (not yet implemented).
-
$can_delete_manager = (1 == count($active_users));
$inactive_users = ttTeamHelper::getInactiveUsers($user->team_id, true);
}