+
+ /*
+ * 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();
+
+ $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')) {
+ while ($val = $res->fetchRow()) {
+ $result[] = $val;
+ }
+ return $result;
+ }
+ return false;
+ }