/** * Stores the given MOC's data */ public function save() { $db = DB::get_db(); $sql = sprintf("INSERT INTO mocs (code) VALUES ('%s')", $db->real_escape_string($this->code)); if (!$db->query($sql)) { error_log("Unable to insert new MOC: " . $db->error . " (sql: {$sql})"); return FALSE; } $this->id = $db->insert_id; if ($this->create_directory_or_delete()) { // Force a reload in case further reads occur MOC::load_all_from_db(); return TRUE; } return FALSE; }
<?php require_once __DIR__ . "/includes/root.php"; must_allow("manage mocs"); $moc = MOC::find($_GET["id"]); if ($moc->delete()) { audit("delete MOC", sprintf("ID: %d, Code: %s", $moc->id, $moc->code)); $renderer->flash_success("Deleted MARC Org Code"); } else { $renderer->flash_alert("Error trying to delete MARC Org Code; is the directory empty?"); } header("Location: mocs-list.php");
<?php require_once __DIR__ . "/includes/root.php"; must_allow("manage mocs"); $mocs = MOC::all(); $renderer->variable("mocs", $mocs); $renderer->variable("title", "MARC Org Code List"); $renderer->render("mocs-list");
<?php require_once __DIR__ . "/includes/root.php"; must_allow("manage mocs"); $moc = new MOC(); $moc->code = $_POST["code"]; $errors = $moc->errors(); if (count($errors) == 0) { if (!$moc->save()) { array_push($errors, "Unknown error trying to save a MARC Org Code! Try again or contact support."); } } if (count($errors) == 0) { audit("new MOC", sprintf("Code: %s", $moc->code)); $renderer->flash_success("Saved MARC Org Code"); header("Location: mocs-list.php"); } else { $renderer->variable("errors", $errors); $renderer->variable("moc", $moc); $renderer->variable("title", "Creating a new MARC Org Code"); $renderer->render("mocs-form"); }