/** * Function: save * * @param int $id - the id of the screen for which data should be saved * * This function saves configuration changes for screens. Most of it is * straightforward. Since the blocks and agency-stop pairs are stored in * different tables, the function pulls those data out and saves them in their * respective tables. * */ public function save($id = 0) { // MSC check that a new id does not clash with an already-created ID // Load the screen model $this->load->model('screen_model'); // Create a placeholder screen that will be filled with variables and then saved. $updatevals = new Screen_model(); $updatevals->id = $id; // Admins can't own screens if (!$this->session->userdata('admin')) { $updatevals->user_id = $this->session->userdata('id'); } // Collect all the posted variables from the HTML form into one variable for // easier access. Delete the submit "variable", which is really just the // submit button. $postvars = $this->input->post(); unset($postvars->submit); // For each of the variables, check to see if the variable name ends with _op (opening) // or _cl (closing). If so, these variables are the sleep and wake times for the screen. // We only want to write them if they have values. Beware that Code Igniter // may treat blank submission as an empty string, which cannot be written // to a timestamp type in PostgreSQL. foreach ($postvars as $key => $value) { if (substr($key, strlen($key) - 3) == '_op' || substr($key, strlen($key) - 3) == '_cl') { if (strlen($value) > 0) { $updatevals->{$key} = $value; } } else { $updatevals->{$key} = $value; } } // Call a function that now writes these values to the database. $updatevals->save_screen_values($id); // Redirect the user back to the edit screen to see the changes he just // made. If he created a new screen or changed the screen id, he may // be directed back to the screen listing page. if ($updatevals->id == $id) { redirect("screen_admin/edit/{$id}"); } else { redirect('screen_admin'); } }