+ // Site id found.
+ $this->site_id = $val['id'];
+
+ // Obtain site key.
+ $sql = "select param_value as site_key from tt_site_config where param_name = 'locker_key'";
+ $res = $mdb2->query($sql);
+ $val = $res->fetchRow();
+ $this->site_key = $val['site_key'];
+ }
+ }
+
+ // putFile - puts uploaded file in remote storage.
+ function putFile($fields) {
+ global $i18n;
+ global $user;
+ $mdb2 = getConnection();
+
+ $group_id = $user->getGroup();
+ $org_id = $user->org_id;
+
+ $fields = array('site_id' => urlencode($this->site_id),
+ 'site_key' => urlencode($this->site_key),
+ 'org_id' => urlencode($org_id),
+ 'org_key' => urlencode($this->getOrgKey()),
+ 'group_id' => urlencode($group_id),
+ 'group_key' => urlencode($this->getGroupKey()),
+ 'user_id' => urlencode($fields['user_id']), // May be null.
+ 'user_key' => urlencode($fields['user_key']), // May be null.
+ 'file_name' => urlencode($fields['file_name']),
+ 'description' => urlencode($fields['description']),
+ // TODO: add file content here, too. Will this work for large files?
+ //
+ );
+
+ // 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, $this->putfile_uri);
+ 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);
+
+ // Delete uploaded file.
+ unlink($_FILES['newfile']['tmp_name']);
+
+ if (!$result) return false;
+
+ $result_array = json_decode($result, true);
+ $file_id = (int) $result_array['file_id'];
+ $file_key = $result_array['file_key'];
+ $file_error = $result_array['file_error'];
+
+ if (!$file_id || !$file_key) {
+ if ($file_error) {
+ // Add an error from file storage facility if we have it.
+ $this->errors->add($file_error);