if (isset($table_description["columns"]["position"]) && $bigtree["form"]["default_position"] == "Top" && !$_POST["id"]) { $max = sqlrows(sqlquery("SELECT id FROM `{$table}`")) + sqlrows(sqlquery("SELECT id FROM `bigtree_pending_changes` WHERE `table` = '" . sqlescape($table) . "'")); $item["position"] = $max; } // Let's stick it in the database or whatever! $data_action = $_POST["save_and_publish"] || $_POST["save_and_publish_x"] || $_POST["save_and_publish_y"] ? "publish" : "save"; $did_publish = false; // We're an editor or "Save" was chosen if ($bigtree["access_level"] == "e" || $data_action == "save") { // We have an existing module entry we're saving a change to. if ($edit_id) { BigTreeAutoModule::submitChange($bigtree["module"]["id"], $table, $edit_id, $item, $many_to_many, $tags); $admin->growl($bigtree["module"]["name"], "Saved " . $bigtree["form"]["title"] . " Draft"); // It's a new entry, so we create a pending item. } else { $edit_id = "p" . BigTreeAutoModule::createPendingItem($bigtree["module"]["id"], $table, $item, $many_to_many, $tags); $admin->growl($bigtree["module"]["name"], "Created " . $bigtree["form"]["title"] . " Draft"); } // We're a publisher and we want to publish } elseif ($bigtree["access_level"] == "p" && $data_action == "publish") { // If we have an edit_id we're modifying something that exists. if ($edit_id) { // If the edit id starts with a "p" it's a pending entry we're publishing. if (substr($edit_id, 0, 1) == "p") { $edit_id = BigTreeAutoModule::publishPendingItem($table, substr($edit_id, 1), $item, $many_to_many, $tags); $admin->growl($bigtree["module"]["name"], "Updated & Published " . $bigtree["form"]["title"]); $did_publish = true; // Otherwise we're updating something that is already published } else { BigTreeAutoModule::updateItem($table, $edit_id, $item, $many_to_many, $tags); $admin->growl($bigtree["module"]["name"], "Updated " . $bigtree["form"]["title"]);
$bigtree["entry"] = BigTreeAutoModule::sanitizeData($bigtree["form"]["table"], $bigtree["entry"]); // Make some easier to write out vars for below. $tags = $_POST["_tags"]; $new_id = false; $table = $bigtree["form"]["table"]; $item = $bigtree["entry"]; $many_to_many = $bigtree["many-to-many"]; // Check to see if this is a positioned element // If it is and the form is setup to create new items at the top and this is a new record, update the position column. $table_description = BigTree::describeTable($table); if (isset($table_description["columns"]["position"]) && $bigtree["form"]["default_position"] == "Top" && !$_POST["id"]) { $max = sqlrows(sqlquery("SELECT id FROM `{$table}`")) + sqlrows(sqlquery("SELECT id FROM `bigtree_pending_changes` WHERE `table` = '" . sqlescape($table) . "'")); $item["position"] = $max; } if ($bigtree["form"]["default_pending"]) { $edit_id = "p" . BigTreeAutoModule::createPendingItem($bigtree["module"]["id"], $table, $item, $many_to_many, $tags, $bigtree["form"]["hooks"]["publish"]); } else { $edit_id = BigTreeAutoModule::createItem($table, $item, $many_to_many, $tags); $did_publish = true; } // If there's a callback function for this module, let's get'r'done. if ($bigtree["form"]["hooks"]["post"]) { call_user_func($bigtree["form"]["hooks"]["post"], $edit_id, $item, $did_publish); } // Publish Hook if ($did_publish && $bigtree["form"]["hooks"]["publish"]) { call_user_func($bigtree["form"]["hooks"]["publish"], $table, $edit_id, $item, $many_to_many, $tags); } // Track resource allocation $admin->allocateResources($bigtree["module"]["id"], $edit_id); // Put together saved form information for the error or crop page in case we need it.