Fixed sorting of projects in dropdown on the reports.php page.
[timetracker.git] / WEB-INF / lib / ttProjectHelper.class.php
index 362a2b6..399cba2 100644 (file)
@@ -28,6 +28,7 @@
 
 import('ttUserHelper');
 import('ttGroupHelper');
+import('ttClientHelper');
 
 // Class ttProjectHelper is used to help with project related tasks.
 class ttProjectHelper {
@@ -44,7 +45,7 @@ class ttProjectHelper {
     // Do a query with inner join to get assigned projects.
     $sql = "select p.id, p.name, p.tasks, upb.rate from tt_projects p".
       " inner join tt_user_project_binds upb on (upb.user_id = $user_id and upb.project_id = p.id and upb.status = 1)".
-      " where p.group_id = $group_id and p.org_id = $org_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 upper(p.name)";
     $res = $mdb2->query($sql);
     if (!is_a($res, 'PEAR_Error')) {
       while ($val = $res->fetchRow()) {
@@ -86,7 +87,7 @@ class ttProjectHelper {
 
     $result = array();
     $sql = "select id, name, tasks from tt_projects".
-      " where group_id = $group_id and org_id = $org_id and (status = 0 or status = 1) order by name";
+      " where group_id = $group_id and org_id = $org_id and (status = 0 or status = 1) order by upper(name)";
     $res = $mdb2->query($sql);
     if (!is_a($res, 'PEAR_Error')) {
       while ($val = $res->fetchRow()) {
@@ -108,7 +109,7 @@ class ttProjectHelper {
     $sql = "select p.id, p.name, p.tasks from tt_projects p".
       " inner join tt_client_project_binds cpb on (cpb.client_id = $user->client_id and cpb.project_id = p.id)".
       " where p.group_id = $group_id and p.org_id = $org_id and (p.status = 0 or p.status = 1)".
-      " order by p.name";
+      " order by upper(p.name)";
 
     $res = $mdb2->query($sql);
     if (!is_a($res, 'PEAR_Error')) {
@@ -164,6 +165,15 @@ class ttProjectHelper {
     global $user;
     $mdb2 = getConnection();
 
+    // Delete associated files.
+    if ($user->isPluginEnabled('at')) {
+      import('ttFileHelper');
+      global $err;
+      $fileHelper = new ttFileHelper($err);
+      if (!$fileHelper->deleteEntityFiles($id, 'project'))
+        return false;
+    }
+
     $group_id = $user->getGroup();
     $org_id = $user->org_id;
 
@@ -194,7 +204,9 @@ class ttProjectHelper {
     if (is_a($affected, 'PEAR_Error'))
       return false;
 
-    return true;
+    // Finally, delete the project from the projects field in tt_clients table.
+    $result = ttClientHelper::deleteProject($id);
+    return $result;
   }
   
   // insert function inserts a new project into database.
@@ -332,4 +344,23 @@ class ttProjectHelper {
     $affected = $mdb2->exec($sql);
     return (!is_a($affected, 'PEAR_Error'));
   }
+
+  // getAssignedUsers - returns an array of user ids assigned to a project.
+  static function getAssignedUsers($project_id) {
+    global $user;
+    $mdb2 = getConnection();
+
+    $group_id = $user->getGroup();
+    $org_id = $user->org_id;
+
+    $result = array();
+    $sql = "select user_id from tt_user_project_binds".
+      " where project_id = $project_id and group_id = $group_id and org_id = $org_id and status = 1";
+    $res = $mdb2->query($sql);
+    if (is_a($res, 'PEAR_Error')) return false;
+    while ($row = $res->fetchRow()) {
+      $result[] = $row['user_id'];
+    }
+    return $result;
+  }
 }