Refactoring in export to use a generic get function to keep things simple.
[timetracker.git] / WEB-INF / lib / ttUser.class.php
index 469345b..8617454 100644 (file)
@@ -192,10 +192,11 @@ class ttUser {
     $result = array();
     $mdb2 = getConnection();
 
+    $group_id = $this->behalf_group_id ? $this->behalf_group_id : $this->group_id;
     // Do a query with inner join to get assigned projects.
     $sql = "select p.id, p.name, p.description, p.tasks, upb.rate from tt_projects p
       inner join tt_user_project_binds upb on (upb.user_id = ".$this->getActiveUser()." and upb.project_id = p.id and upb.status = 1)
-      where p.group_id = $this->group_id and p.status = 1 order by p.name";
+      where p.group_id = $group_id and p.status = 1 order by p.name";
     $res = $mdb2->query($sql);
     if (!is_a($res, 'PEAR_Error')) {
       while ($val = $res->fetchRow()) {
@@ -409,6 +410,20 @@ class ttUser {
     return $groups;
   }
 
+  // getSubgroups obtains a list of immediate subgroups.
+  function getSubgroups() {
+    $mdb2 = getConnection();
+
+    $sql = "select id, name from tt_groups where org_id = $this->org_id and parent_id = ".$this->getActiveGroup();;
+    $res = $mdb2->query($sql);
+    if (!is_a($res, 'PEAR_Error')) {
+      while ($val = $res->fetchRow()) {
+        $groups[] = array('id'=>$val['id'],'name'=>$val['name']);
+      }
+    }
+    return $groups;
+  }
+
   // getUser function is used to manage users in group and returns user details.
   // At the moment, the function is used for user edits and deletes.
   function getUser($user_id) {