function action_update() { log_debug("journal_process", "Executing action_update()"); /* Start Transaction */ $sql_obj = new sql_query(); $sql_obj->trans_begin(); /* If no ID supplied, create a new journal entry first */ if (empty($this->structure["id"])) { $mode = "create"; if (!$this->action_create()) { return 0; } } else { $mode = "update"; } /* Handle some optional fields */ if (!isset($this->structure["content"])) { $this->structure["content"] = ""; } if (!isset($this->structure["userid"])) { // automated system user $this->structure["userid"] = 0; } /* Update journal record */ $sql_obj->string = "UPDATE `journal` SET " . "userid='" . $this->structure["userid"] . "', " . "customid='" . $this->structure["customid"] . "', " . "timestamp='" . $this->structure["timestamp"] . "', " . "title='" . $this->structure["title"] . "', " . "content='" . $this->structure["content"] . "' " . "WHERE id='" . $this->structure["id"] . "' LIMIT 1"; $sql_obj->execute(); /* If journal entry is a file, upload the data TODO: this currently only works for form uploads */ if ($this->structure["type"] == "file") { if (isset($_FILES["upload"]["name"])) { log_write("debug", "journal_process", "Uploading file against journal entry from POST form data"); // output file data $file_obj = new file_storage(); $file_obj->data["type"] = "journal"; $file_obj->data["customid"] = $this->structure["id"]; if ($file_obj->load_data_bytype()) { log_debug("journal_process", "Old file exists, will overwrite."); // unset the title variable - otherwise the action_update_form function will retain the existing title $file_obj->data["file_name"] = NULL; } else { log_debug("journal_process", "No previous file exists, performing clean upload."); } // call the upload function if (!$file_obj->action_update_form("upload")) { log_write("error", "journal_process", "Unable to upload file for journal entry id " . $this->structure["id"] . ""); } } else { // not uploading log_write("debug", "journal_process", "No file POST data provided, not uploading file to journal - assuming manual DB upload"); } } /* Commit */ if (error_check()) { $sql_obj->trans_rollback(); log_write("error", "journal_process", "An error occured whilst updating the journal."); return 0; } else { $sql_obj->trans_commit(); if ($this->structure["type"] != "event") { if ($mode == "update") { log_write("notification", "journal_process", "Journal entry updated successfully."); } else { log_write("notification", "journal_process", "New record added to the journal successfully."); } } return 1; } return 0; }
Update the logo file if required */ if ($_FILES["COMPANY_LOGO"]["size"] > 1) { // set file variables $file_obj->data["type"] = "COMPANY_LOGO"; $file_obj->data["customid"] = "0"; // see if a file already exists if ($file_obj->load_data_bytype()) { log_debug("process", "Old file exists, will overwrite."); } else { log_debug("process", "No previous file exists, performing clean upload."); } // force the filename $file_obj->data["file_name"] = "company_logo.png"; // call the upload function if (!$file_obj->action_update_form("COMPANY_LOGO")) { log_write("error", "process", "Unable to upload company logo"); } } /* Commit */ if (error_check()) { $sql_obj->trans_rollback(); log_write("error", "process", "An error occured whilst updating configuration, no changes have been applied."); } else { $sql_obj->trans_commit(); log_write("notification", "process", "Company configuration updated successfully"); } header("Location: ../index.php?page=admin/config_company.php"); exit(0);