]> wagnertech.de Git - timetracker.git/blobdiff - WEB-INF/lib/ttFileHelper.class.php
Work in progress on attachment delete.
[timetracker.git] / WEB-INF / lib / ttFileHelper.class.php
index 7c8324b6fc7ee0c88b45a6ee6ad2f3a7cc7ee438..80c9fd31461bccdd916a5601cb368b8b422faf66 100644 (file)
@@ -125,7 +125,7 @@ class ttFileHelper {
     $group_id = $user->getGroup();
     $org_id = $user->org_id;
 
-    $fields = array('site_id' => urlencode($this->site_id),
+    $curl_fields = array('site_id' => urlencode($this->site_id),
       'site_key' => urlencode($this->site_key),
       'org_id' => urlencode($org_id),
       'org_key' => urlencode($this->getOrgKey()),
@@ -139,7 +139,7 @@ class ttFileHelper {
     );
 
     // url-ify the data for the POST.
-    foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
+    foreach($curl_fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
     $fields_string = rtrim($fields_string, '&');
 
     // Open connection.
@@ -216,4 +216,44 @@ class ttFileHelper {
     $val = $res->fetchRow();
     return $val['group_key'];
   }
+
+  // getProjectFiles obtains a list of files for a project.
+  function getProjectFiles($project_id) {
+    global $user;
+    $mdb2 = getConnection();
+
+    $group_id = $user->getGroup();
+    $org_id = $user->org_id;
+
+    $result = array();
+    $sql = "select id, remote_id, file_name as name, description from tt_files".
+      " where entity_type = 'project' and entity_id = $project_id".
+      " and group_id = $group_id and org_id = $org_id and status = 1 order by id";
+    $res = $mdb2->query($sql);
+    if (!is_a($res, 'PEAR_Error')) {
+      while ($val = $res->fetchRow()) {
+        $result[] = $val;
+      }
+    }
+    return $result;
+  }
+
+  // get - obtains file details from local database. 
+  static function get($id) {
+    global $user;
+    $mdb2 = getConnection();
+
+    $group_id = $user->getGroup();
+    $org_id = $user->org_id;
+
+    $sql = "select id, remote_id, file_key, entity_type, entity_id, file_name, description, status from tt_files".
+      " 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')) {
+      $val = $res->fetchRow();
+      if ($val && $val['id'])
+        return $val;
+    }
+    return false;
+  }
 }