X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=WEB-INF%2Flib%2FttExportHelper.class.php;h=375de2f371caab138d0c49605d01ae8b583ed39e;hb=2ffa361a7610cbd1334754da314e4783226df689;hp=0c8084e2fc43350c630f3c37ddb30f0b4ffca216;hpb=8d79e78a49803d07856cd68ab733157dfed6f793;p=timetracker.git diff --git a/WEB-INF/lib/ttExportHelper.class.php b/WEB-INF/lib/ttExportHelper.class.php index 0c8084e2..375de2f3 100644 --- a/WEB-INF/lib/ttExportHelper.class.php +++ b/WEB-INF/lib/ttExportHelper.class.php @@ -73,12 +73,12 @@ class ttExportHelper { fwrite($file, "\n"); // Prepare role map. - $roles = ttTeamHelper::getAllRoles($user->team_id); + $roles = $this->getRoles(); foreach ($roles as $key=>$role_item) $this->roleMap[$role_item['id']] = $key + 1; // Prepare user map. - $users = ttExportHelper::getAllUsers(); + $users = $this->getUsers(); foreach ($users as $key=>$user_item) $this->userMap[$user_item['id']] = $key + 1; @@ -114,10 +114,9 @@ class ttExportHelper { // Write roles. fwrite($file, "\n"); - $roles = ttTeamHelper::getAllRoles($user->team_id); foreach ($roles as $role) { fwrite($file, " roleMap[$role['id']]."\" rank=\"".$role['rank']."\"". - " rights=\"".$role['rights']."\">\n"); + " rights=\"".$role['rights']."\" status=\"".$role['status']."\">\n"); fwrite($file, " \n"); fwrite($file, " \n"); } @@ -127,7 +126,8 @@ class ttExportHelper { // Write users. fwrite($file, "\n"); foreach ($users as $user_item) { - fwrite($file, " userMap[$user_item['id']]."\" login=\"".htmlentities($user_item['login'])."\" password=\"".$user_item['password']."\" role_id=\"".$this->roleMap[$user_item['role_id']]."\" client_id=\"".$this->clientMap[$user_item['client_id']]."\" rate=\"".$user_item['rate']."\" email=\"".$user_item['email']."\" status=\"".$user_item['status']."\">\n"); + $role_id = $user_item['rank'] == 512 ? 0 : $this->roleMap[$user_item['role_id']]; // Special role_id 0 (not null) for top manager. + fwrite($file, " userMap[$user_item['id']]."\" login=\"".htmlentities($user_item['login'])."\" password=\"".$user_item['password']."\" role_id=\"".$role_id."\" client_id=\"".$this->clientMap[$user_item['client_id']]."\" rate=\"".$user_item['rate']."\" email=\"".$user_item['email']."\" status=\"".$user_item['status']."\">\n"); fwrite($file, " \n"); fwrite($file, " \n"); } @@ -237,7 +237,7 @@ class ttExportHelper { foreach ($records as $record) { $key++; $this->logMap[$record['id']] = $key; - fwrite($file, " userMap[$record['user_id']]."\" date=\"".$record['date']."\" start=\"".$record['start']."\" finish=\"".$record['finish']."\" duration=\"".($record['start']?"":$record['duration'])."\" client_id=\"".$this->clientMap[$record['client_id']]."\" project_id=\"".$this->projectMap[$record['project_id']]."\" task_id=\"".$this->taskMap[$record['task_id']]."\" invoice_id=\"".$this->invoiceMap[$record['invoice_id']]."\" billable=\"".$record['billable']."\" paid=\"".$record['paid']."\" status=\"".$record['status']."\">\n"); + fwrite($file, " userMap[$record['user_id']]."\" date=\"".$record['date']."\" start=\"".$record['start']."\" finish=\"".$record['finish']."\" duration=\"".($record['start']?"":$record['duration'])."\" client_id=\"".$this->clientMap[$record['client_id']]."\" project_id=\"".$this->projectMap[$record['project_id']]."\" task_id=\"".$this->taskMap[$record['task_id']]."\" invoice_id=\"".$this->invoiceMap[$record['invoice_id']]."\" billable=\"".$record['billable']."\" paid=\"".$record['paid']."\" status=\"".$record['status']."\">\n"); fwrite($file, " \n"); fwrite($file, " \n"); } @@ -291,6 +291,8 @@ class ttExportHelper { " period_end=\"".$fav_report['period_end']."\"". " show_client=\"".$fav_report['show_client']."\"". " show_invoice=\"".$fav_report['show_invoice']."\"". + " show_paid=\"".$fav_report['show_paid']."\"". + " show_ip=\"".$fav_report['show_ip']."\"". " show_project=\"".$fav_report['show_project']."\"". " show_start=\"".$fav_report['show_start']."\"". " show_duration=\"".$fav_report['show_duration']."\"". @@ -356,12 +358,47 @@ class ttExportHelper { return true; } - // The getAllUsers obtains all users in team. - static function getAllUsers() { + /* + * Note about the utility functions below. + * We have roughly 4 groups of operations: + * 1) Regular system usage for tracking time, etc. + * 2) Registration process - used infrequently. + * 3) Admin usage - used infrequently. + * 4) Export - used infrequently. + * + * It is tempting to have a generic function to get things done for + * all situations. However, as registration, export and admin access are one-off + * operations, while regular system usage is daily and must be efficient, + * the current approach is to have SEPARATE functions for each mode. + * + * This is because each mode requires a slightly different approach, + * and we don't want to over-complicate things. + */ + + // getRoles - obtains all roles defined for team. + function getRoles() { global $user; $mdb2 = getConnection(); - $sql = "select * from tt_users where team_id = $user->team_id order by upper(name)"; // Note: deleted users are included. + $result = array(); + $sql = "select * from tt_roles where team_id = $user->team_id"; + $res = $mdb2->query($sql); + $result = array(); + if (!is_a($res, 'PEAR_Error')) { + while ($val = $res->fetchRow()) { + $result[] = $val; + } + return $result; + } + return false; + } + + // The getUsers obtains all users in team for the purpose of export. + function getUsers() { + global $user; + $mdb2 = getConnection(); + + $sql = "select u.*, r.rank from tt_users u left join tt_roles r on (u.role_id = r.id) where u.team_id = $user->team_id order by upper(u.name)"; // Note: deleted users are included. $res = $mdb2->query($sql); $result = array(); if (!is_a($res, 'PEAR_Error')) {