From 53e04060039f7c488fa5ca6bc018103763b901c5 Mon Sep 17 00:00:00 2001 From: Nik Okuntseff Date: Sun, 17 Mar 2019 14:17:23 +0000 Subject: [PATCH] Work in progress on project attachments. --- WEB-INF/config.php.dist | 5 ++++ WEB-INF/lib/ttFileHelper.class.php | 48 ++++++++++++++++++++++++++++-- WEB-INF/lib/ttOrgHelper.class.php | 4 +-- WEB-INF/templates/footer.tpl | 2 +- project_files.php | 6 ++-- 5 files changed, 58 insertions(+), 7 deletions(-) diff --git a/WEB-INF/config.php.dist b/WEB-INF/config.php.dist index d8bfe0c1..b9ae7bd0 100644 --- a/WEB-INF/config.php.dist +++ b/WEB-INF/config.php.dist @@ -197,3 +197,8 @@ define('AUTH_MODULE', 'db'); // Height in pixels for the note input field in time.php. Defaults to 40. // define('NOTE_INPUT_HEIGHT', 100); + +// $GLOBALS['FILE_STORAGE_PARAMS'] = array( +// 'uri' => 'localhost', // File storage uri. +// 'site_id' => '1', // This site id for file storage facility. +// 'site_key' => 'debug_key'); // This site key for file storage facility. diff --git a/WEB-INF/lib/ttFileHelper.class.php b/WEB-INF/lib/ttFileHelper.class.php index 611df39e..26a28677 100644 --- a/WEB-INF/lib/ttFileHelper.class.php +++ b/WEB-INF/lib/ttFileHelper.class.php @@ -28,15 +28,59 @@ // ttFileHelper class is used for attachment handling. class ttFileHelper { - var $errors = null; // Errors go here. Set in constructor by reference. + var $errors = null; // Errors go here. Set in constructor by reference. + var $storage_uri = null; + var $site_id = null; + var $site_key = null; // Constructor. function __construct(&$errors) { $this->errors = &$errors; + + if (isset($GLOBALS['FILE_STORAGE_PARAMS']) && is_array($GLOBALS['FILE_STORAGE_PARAMS'])) { + $params = $GLOBALS['FILE_STORAGE_PARAMS']; + $this->storage_uri = $params['uri']; + $this->site_id = $params['site_id']; + $this->site_key = $params['site_key']; + } } // putFile - puts uploaded file in remote storage. - function putFile() { + function putFile($description) { + + $url = $this->storage_uri; + $fields = array('description' => urlencode($description), +// 'fname' => urlencode($_POST['first_name']), +// 'title' => urlencode($_POST['title']), +// 'company' => urlencode($_POST['institution']), +// 'age' => urlencode($_POST['age']), +// 'email' => urlencode($_POST['email']), +// 'phone' => urlencode($_POST['phone']) + ); + + // url-ify the data for the POST. + foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; } + $fields_string = rtrim($fields_string, '&'); + + // Open connection. + $ch = curl_init(); + + // Set the url, number of POST vars, POST data. + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_POST, count($fields)); + curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); + + // Execute a post rewuest. + $result = curl_exec($ch); + + // Close connection. + curl_close($ch); + + if ($result) { + $result_array = json_decode($result, true); + $file_id = $mdb2->quote($result_array['id']); + } unlink($_FILES['newfile']['tmp_name']); return false; // Not implemented. diff --git a/WEB-INF/lib/ttOrgHelper.class.php b/WEB-INF/lib/ttOrgHelper.class.php index 07b70b5f..346ea5d1 100644 --- a/WEB-INF/lib/ttOrgHelper.class.php +++ b/WEB-INF/lib/ttOrgHelper.class.php @@ -63,7 +63,7 @@ class ttOrgHelper { return false; } - // The getInactiveOrgs is a maintenance function that returns an array of inactive organization ids (max 10 for now). + // The getInactiveOrgs is a maintenance function that returns an array of inactive organization ids (max 25 for now). static function getInactiveOrgs() { $inactive_orgs = array(); $mdb2 = getConnection(); @@ -72,7 +72,7 @@ class ttOrgHelper { $cutoff_timestamp = $mdb2->quote(date('Y-m-d', strtotime('-1 year'))); $sql = "select org_id from". " (select max(accessed) as last_access, org_id from tt_users where org_id > 0 group by org_id order by last_access, org_id) as t". - " where last_access is null or last_access < $cutoff_timestamp limit 10"; // Max 10 orgs at a time for now... + " where last_access is null or last_access < $cutoff_timestamp limit 25"; // Max 25 orgs at a time for now... $res = $mdb2->query($sql); if (!is_a($res, 'PEAR_Error')) { while ($val = $res->fetchRow()) { diff --git a/WEB-INF/templates/footer.tpl b/WEB-INF/templates/footer.tpl index c1d42357..d8614a7a 100644 --- a/WEB-INF/templates/footer.tpl +++ b/WEB-INF/templates/footer.tpl @@ -12,7 +12,7 @@
-
 Anuko Time Tracker 1.18.59.4872 | Copyright © Anuko | +  Anuko Time Tracker 1.18.59.4873 | Copyright © Anuko | {$i18n.footer.credits} | {$i18n.footer.license} | {$i18n.footer.improve} diff --git a/project_files.php b/project_files.php index 08e9b5f2..affc6d72 100644 --- a/project_files.php +++ b/project_files.php @@ -70,8 +70,10 @@ if ($request->isPost()) { if (!ttValidString($cl_description, true)) $err->add($i18n->get('error.field'), $i18n->get('label.description')); // Finished validating user input. - $fileHelper = new ttFileHelper($err); - $fileHelper->putFile(); + if ($err->no()) { + $fileHelper = new ttFileHelper($err); + $fileHelper->putFile($cl_description); + } // if ($err->no()) $msg->add($i18n->get('form.import.success')); } // isPost -- 2.20.1