/** * proces an attachment (either do nothing, insert an attachment or delete an attachment) * @param $record_id int unique identifier of a ListTable object * @param $attachment_str string string representing attachment details * @return int number indicates the id of the new attachment or 0 when no record was added */ function insert($record_id, $attachment_id, $attachment_str) { $this->_log->trace("inserting ListTableAttachment (record_id={$record_id}, attachment_id={$attachment_id}, attachments_str={$attachment_str})"); $return_value = TRUE; $attachment_array = explode('|', $attachment_str); $full_tmp_name = "uploads/" . $attachment_array[0]; $type = $attachment_array[1]; $size = $attachment_array[2]; $name = $attachment_array[3]; $name_values_array = array(); $name_values_array[LISTTABLEATTACHMENT_RECORD_ID_FIELD_NAME] = $record_id; $name_values_array[LISTTABLEATTACHMENT_TYPE_FIELD_NAME] = $type; $name_values_array[LISTTABLEATTACHMENT_SIZE_FIELD_NAME] = $size; $name_values_array[LISTTABLEATTACHMENT_NAME_FIELD_NAME] = $name; if (file_exists($full_tmp_name) == FALSE) { $this->_handle_error("could not find file to attachment (file name=" . $full_tmp_name . ")", "ERROR_UPLOAD_FILE_NOT_FOUND"); return 0; } $file_handler = fopen($full_tmp_name, "r"); if ($file_handler == FALSE) { $this->_handle_error("could not open file to attachment (file name=" . $full_tmp_name . ")", "ERROR_UPLOAD_COULD_NOT_OPEN"); return 0; } $read_file_str = fread($file_handler, filesize($full_tmp_name)); fclose($file_handler); unlink($full_tmp_name); # add slashes to attachment $name_values_array[LISTTABLEATTACHMENT_ATTACHMENT_FIELD_NAME] = addslashes($read_file_str); # call parent insert() $new_attachment_id = parent::insert($name_values_array, $this->_user->get_name()); if ($new_attachment_id == 0) { return 0; } $this->_log->trace("processed ListTableAttachment"); return $new_attachment_id; }
/** * add a new record to database * @param $name_values_array array array containing name-values of the record * @return int number indicates the id of the new record or 0 when no record was added */ function insert($name_values_array) { $this->_log->trace("inserting record into UserDatabaseTable"); # replace decimal marks if (count($this->db_field_names_decimal_marks_to_replace) > 0) { $name_values_array = $this->_replace_decimal_marks($name_values_array, TRUE); } # call parent insert() $result = parent::insert($name_values_array, $this->_user->get_name()); if ($result == 0) { return 0; } $this->_log->trace("inserted record into UserDatabaseTable (result=" . $result . ")"); return $result; }
/** * add a new note to database * @param $record_id int unique identifier of a ListTable object * @param $field_name string field name * @param $note string the new note * @return int number indicates the id of the new note or 0 when no record was added */ function insert($record_id, $field_name, $note) { $this->_log->trace("inserting ListTableNote (record_id=" . $record_id . ", field_name=" . $field_name . ")"); $name_values_array = array(); $name_values_array[LISTTABLENOTE_RECORD_ID_FIELD_NAME] = $record_id; $name_values_array[LISTTABLENOTE_FIELD_NAME_FIELD_NAME] = $field_name; $name_values_array[LISTTABLENOTE_NOTE_FIELD_NAME] = $note; # call parent insert() $new_note_id = parent::insert($name_values_array, $this->_user->get_name()); if ($new_note_id == 0) { return 0; } $this->_log->trace("inserted ListTableNote"); return $new_note_id; }