X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=WEB-INF%2Flib%2FttExportHelper.class.php;h=88ea5acb21031eada41991a37ee5c26af6af1fbc;hb=074e8daef75c2b729e75f350b52935a6b7ecfba8;hp=0e1164787dbc6e81685eaf871b4e1de1455d621c;hpb=e3ed046e205a14772a8157def21fea9a14acdde8;p=timetracker.git diff --git a/WEB-INF/lib/ttExportHelper.class.php b/WEB-INF/lib/ttExportHelper.class.php index 0e116478..88ea5acb 100644 --- a/WEB-INF/lib/ttExportHelper.class.php +++ b/WEB-INF/lib/ttExportHelper.class.php @@ -36,6 +36,7 @@ class ttExportHelper { // The following arrays are maps between entity ids in the file versus the database. // We write to the file sequentially (1,2,3...) while in the database the entities have different ids. var $userMap = array(); // User ids. + var $roleMap = array(); // Role ids. var $projectMap = array(); // Project ids. var $taskMap = array(); // Task ids. var $clientMap = array(); // Client ids. @@ -71,8 +72,13 @@ class ttExportHelper { fwrite($file, " team."]]>\n"); fwrite($file, "\n"); + // Prepare role map. + $roles = ttExportHelper::getAllRoles(); + foreach ($roles as $key=>$role_item) + $this->roleMap[$role_item['id']] = $key + 1; + // Prepare user map. - $users = ttTeamHelper::getAllUsers($user->team_id, true); + $users = ttExportHelper::getAllUsers(); foreach ($users as $key=>$user_item) $this->userMap[$user_item['id']] = $key + 1; @@ -106,10 +112,22 @@ class ttExportHelper { foreach ($custom_field_options as $key=>$option) $this->customFieldOptionMap[$option['id']] = $key + 1; + // Write roles. + fwrite($file, "\n"); + foreach ($roles as $role) { + fwrite($file, " roleMap[$role['id']]."\" rank=\"".$role['rank']."\"". + " rights=\"".$role['rights']."\" status=\"".$role['status']."\">\n"); + fwrite($file, " \n"); + fwrite($file, " \n"); + } + fwrite($file, "\n"); + unset($roles); + // 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=\"".$user_item['role']."\" 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"); } @@ -261,7 +279,7 @@ class ttExportHelper { $user_list .= (strlen($user_list) == 0? '' : ',').$this->userMap[$v]; } } - fwrite($file, "\tuserMap[$fav_report['user_id']]."\"". + fwrite($file, " userMap[$fav_report['user_id']]."\"". " client_id=\"".$this->clientMap[$fav_report['client_id']]."\"". " cf_1_option_id=\"".$this->customFieldOptionMap[$fav_report['cf_1_option_id']]."\"". " project_id=\"".$this->projectMap[$fav_report['project_id']]."\"". @@ -283,14 +301,15 @@ class ttExportHelper { " show_custom_field_1=\"".$fav_report['show_custom_field_1']."\"". " group_by=\"".$fav_report['group_by']."\"". " show_totals_only=\"".$fav_report['show_totals_only']."\">\n"); - fwrite($file, "\t\t\n"); - fwrite($file, "\t\n"); + fwrite($file, " \n"); + fwrite($file, " \n"); } fwrite($file, "\n"); unset($fav_reports); // Cleanup. unset($users); + $this->roleMap = array(); $this->userMap = array(); $this->projectMap = array(); $this->taskMap = array(); @@ -336,4 +355,39 @@ class ttExportHelper { fclose ($in_file); return true; } + + // getAllRoles - obtains all roles defined for team. + static function getAllRoles() { + global $user; + $mdb2 = getConnection(); + + $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 getAllUsers obtains all users in team for the purpose of export. + static function getAllUsers() { + 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')) { + while ($val = $res->fetchRow()) { + $result[] = $val; + } + return $result; + } + return false; + } }