/** * download an attachment * this function is registered in xajax * @param string $list_title title of current list * @param int $attachment_id * @return xajaxResponse every xajax registered function needs to return this object */ function action_download_attachment($list_title, $attachment_id) { global $logging; global $user; global $user_start_time_array; $logging->info("USER_ACTION " . __METHOD__ . " (user="******", attachment_id={$attachment_id})"); # store start time $user_start_time_array[__METHOD__] = microtime(TRUE); # create necessary objects $response = new xajaxResponse(); # get the file name and the attachment $list_table_attachment = new ListTableAttachment($list_title); $attachment_array = $list_table_attachment->select_record($attachment_id); $file_name = str_replace(" ", " ", $attachment_array[4]); $attachment = $attachment_array[5]; # create a temp file with attachment $tmp_file_name = "download_" . $user->get_name() . strftime("_%d%m%Y_%H%M%S"); $file_handler = fopen("uploads/" . $tmp_file_name, "w"); fwrite($file_handler, $attachment); fclose($file_handler); # call the export handler $response->script("document.location.href = 'php/Html.Export.php?tmp_file={$tmp_file_name}&file_name={$file_name}'"); # log total time for this function $logging->info(get_function_time_str(__METHOD__)); return $response; }
/** * delete an existing ListTableItem from database * delete all connected ListTableNote objects * @param $encoded_key_string string unique identifier of ListTableItem to be deleted * @return bool indicates if ListTableItem has been deleted */ function delete($encoded_key_string) { global $list_table_description; $this->_log->trace("deleting record from ListTable (encoded_key_string=" . $encoded_key_string . ")"); # get the id of this record $record = self::select_record($encoded_key_string); if (count($record) == 0) { return FALSE; } $record_id = $record[DB_ID_FIELD_NAME]; # delete all notes for all fields foreach ($this->db_field_names as $db_field_name) { if ($this->fields[$db_field_name][1] == FIELD_TYPE_DEFINITION_NOTES_FIELD) { if ($this->_list_table_note->delete_record_notes($record_id) == FALSE) { # copy error strings from list_table_note $this->error_message_str = $this->_list_table_note->get_error_message_str(); $this->error_log_str = $this->_list_table_note->get_error_log_str(); $this->error_str = $this->_list_table_note->get_error_str(); return FALSE; } } } # delete all attachments for this record if ($this->_list_table_attachment->delete_record_attachments($record_id) == FALSE) { # copy error strings from list_table_note $this->error_message_str = $this->_list_table_attachment->get_error_message_str(); $this->error_log_str = $this->_list_table_attachment->get_error_log_str(); $this->error_str = $this->_list_table_attachment->get_error_str(); return FALSE; } # delete record if (parent::delete($encoded_key_string) == FALSE) { return FALSE; } # update list table description if ($this->_update_list_table_description_statistics() == FALSE) { return FALSE; } $this->_log->trace("deleted record from ListTable"); return TRUE; }