Introduced a debug option and a localization string for holidays.
[timetracker.git] / WEB-INF / lib / ttTaskHelper.class.php
index 2c0fbe1..0156740 100644 (file)
@@ -35,9 +35,11 @@ class ttTaskHelper {
     global $user;
  
     $mdb2 = getConnection();
+    $group_id = $user->getGroup();
+    $org_id = $user->org_id;
 
     $sql = "select id, name, description, status from tt_tasks
-      where id = $id and group_id = $user->group_id and (status = 0 or status = 1)";
+      where id = $id and group_id = $group_id and org_id = $org_id and (status = 0 or status = 1)";
     $res = $mdb2->query($sql);
 
     if (!is_a($res, 'PEAR_Error')) {
@@ -53,15 +55,17 @@ class ttTaskHelper {
   // getAssignedProjects - returns an array of projects associatied with a task.
   static function getAssignedProjects($task_id)
   {
-       global $user;
+    global $user;
        
     $result = array();
     $mdb2 = getConnection();
+    $group_id = $user->getGroup();
+    $org_id = $user->org_id;
     
     // Do a query with inner join to get assigned projects.
     $sql = "select p.id, p.name from tt_projects p
       inner join tt_project_task_binds ptb on (ptb.project_id = p.id and ptb.task_id = $task_id)
-      where p.group_id = $user->group_id and p.status = 1 order by p.name";
+      where p.group_id = $group_id and p.org_id = $org_id and p.status = 1 order by p.name";
     $res = $mdb2->query($sql);
     if (!is_a($res, 'PEAR_Error')) {
       while ($val = $res->fetchRow()) {
@@ -133,10 +137,11 @@ class ttTaskHelper {
  // insert function inserts a new task into database.
   static function insert($fields)
   {
+    global $user;
     $mdb2 = getConnection();
 
-    $group_id = (int) $fields['group_id'];
-    $org_id = (int) $fields['org_id'];
+    $group_id = $user->getGroup();
+    $org_id = $user->org_id;
     $name = $fields['name'];
     $description = $fields['description'];
     $projects = $fields['projects'];
@@ -149,11 +154,8 @@ class ttTaskHelper {
     if (is_a($affected, 'PEAR_Error'))
       return false;
 
-    $sql = "select last_insert_id() as last_insert_id";
-    $res = $mdb2->query($sql);
-    $val = $res->fetchRow();
-    $last_id = $val['last_insert_id'];
-    
+    $last_id = $mdb2->lastInsertID('tt_tasks', 'id');
+
     if (is_array($projects)) {
       foreach ($projects as $p_id) {
         // Insert task binds into tt_project_task_binds table.
@@ -192,7 +194,7 @@ class ttTaskHelper {
     global $user;
     $mdb2 = getConnection();
 
-    $group_id = $user->getActiveGroup();
+    $group_id = $user->getGroup();
     $org_id = $user->org_id;
     $task_id = (int)$fields['task_id'];
     $name = $fields['name'];
@@ -269,17 +271,17 @@ class ttTaskHelper {
 
   // sort function sorts task ids passed as comma-separated list by their name.
   static function sort($comma_separated) {
-       // We can't sort an empty string.
-       if (!$comma_separated)
-         return $comma_separated;
-                 
+    // We can't sort an empty string.
+    if (!$comma_separated)
+      return $comma_separated;
+
     $mdb2 = getConnection();
-      
-       $sql = "select id, name from tt_tasks where id in ($comma_separated)";
+
+    $sql = "select id, name from tt_tasks where id in ($comma_separated)";
     $res = $mdb2->query($sql);
     if (is_a($res, 'PEAR_Error'))
       die ($res->getMessage());
-    
+
     $task_arr = array();
     while ($val = $res->fetchRow()) {
       $task_arr[] = array('id'=>$val['id'],'name'=>$val['name']);
@@ -289,7 +291,7 @@ class ttTaskHelper {
     for($i = 0; $i < count($task_arr); $i++) {
          $task_ids[] = $task_arr[$i]['id'];
     }
-       $result = implode(',', $task_ids);
+    $result = implode(',', $task_ids);
     return $result;
   }
 }