# 1. figure out what action is being attempted (none/default is view) # 2. figure out which metadata term set is being acted on (if none specified then list all visible) # 3. confirm that the user is allowed to take that action on that object (if not then list all visible with an appropriate warning) # 4. branch behavior based on the action ############################# # 1. figure out what action is being attempted (none/default is view) $action = 'view'; if (isset($_REQUEST['action']) && $_REQUEST['action'] == 'list') { $action = 'list'; } elseif (isset($_REQUEST['action']) && in_array($_REQUEST['action'], Action::$VALID_ACTIONS)) { $action = $_REQUEST['action']; } # 2. figure out which metadata term set is being acted on (if none specified then list all visible) $mdts = ''; if ($action == 'create') { $mdts = new Metadata_Term_Set(['name' => util_lang('new_metadata_term_set') . ' ' . util_currentDateTimeString(), 'DB' => $DB]); } elseif ($action != 'list' && isset($_REQUEST['metadata_term_set_id']) && is_numeric($_REQUEST['metadata_term_set_id'])) { $mdts = Metadata_Term_Set::getOneFromDb(['metadata_term_set_id' => $_REQUEST['metadata_term_set_id']], $DB); } if (!$mdts || !$mdts->matchesDb) { $action = 'list'; } # 3. confirm that the user is allowed to take that action on that object (if not, redirect them to the home page with an appropriate warning) if ($action != 'list' && !$USER->canActOnTarget($ACTIONS[$action], $mdts)) { $action = 'list'; } if ($action != 'delete') { require_once '../app_head.php'; } # 4. branch behavior based on the action # update - update the object with the data coming in, then show the object (w/ 'saved' message)
public static function createNewNotebookForUser($user_id, $db_connection) { $n = new Notebook(['notebook_id' => 'NEW', 'created_at' => util_currentDateTimeString_asMySQL(), 'updated_at' => util_currentDateTimeString_asMySQL(), 'user_id' => $user_id, 'name' => util_lang('new_notebook_title') . ' ' . util_currentDateTimeString(), 'notes' => util_lang('new_notebook_notes'), 'flag_workflow_published' => false, 'flag_workflow_validated' => false, 'flag_delete' => false, 'DB' => $db_connection]); return $n; }