Added import timestamp and IP for team import operation.
[timetracker.git] / WEB-INF / lib / ttTeamHelper.class.php
index 9f3e0a9..2aff793 100644 (file)
@@ -85,7 +85,7 @@ class ttTeamHelper {
     while ($val = $res->fetchRow()) {
       // Localize top manager role name, as it is not localized in db.
       if ($val['rank'] == 512)
-        $val['role_name'] = $i18n->getKey('role.top_manager.label');
+        $val['role_name'] = $i18n->get('role.top_manager.label');
       $user_list[] = $val;
     }
 
@@ -108,6 +108,7 @@ class ttTeamHelper {
     global $user;
     $mdb2 = getConnection();
 
+    // Obtain role id for the user we are swapping ourselves with.
     $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'))
@@ -116,14 +117,16 @@ class ttTeamHelper {
     if (!$val['id'] || !$val['role_id'])
       return false;
 
+    $modified_part = ', modified = now(), modified_ip = '.$mdb2->quote($_SERVER['REMOTE_ADDR']).', modified_by = '.$mdb2->quote($user->id);
+
     // Promote user.
-    $sql = "update tt_users set role_id = $user->role_id where id = $user_id and team_id = $user->team_id";
+    $sql = "update tt_users set role_id = $user->role_id".$modified_part." 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";
+    $sql = "update tt_users set role_id = $role_id".$modified_part." where id = $user->id and team_id = $user->team_id";
     $affected = $mdb2->exec($sql);
     if (is_a($affected, 'PEAR_Error')) return false;
 
@@ -141,7 +144,7 @@ class ttTeamHelper {
     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.
+      $isClient = in_array('track_own_time', explode(',', $val['rights'])) ? 0 : 1; // Clients do not have track_own_time right.
       if ($isClient)
         continue; // Skip adding clients.
       $user_list[] = $val;
@@ -753,6 +756,7 @@ class ttTeamHelper {
   // The insert function creates a new team.
   static function insert($fields) {
 
+    global $user;
     $mdb2 = getConnection();
 
     // Start with team name and currency.
@@ -835,6 +839,9 @@ class ttTeamHelper {
       $values .= ', '.$mdb2->quote($fields['config']);
     }
 
+    $columns .= ', created, created_ip, created_by';
+    $values .= ', now(), '.$mdb2->quote($_SERVER['REMOTE_ADDR']).', '.$mdb2->quote($user->id);
+
     $sql = "insert into tt_teams ($columns) values($values)";
     $affected = $mdb2->exec($sql);