/** * Redirect the current user to the login page. After they login or register, * they'll be sent back to $back_to * @param string $back_to The URL to come bak to after login. Default $back_to * is the current URL * @param string $message A message to show on the login page like "Login first, sucka" */ public static function redirectAndComeback($back_to = FALSE, $message = FALSE) { $CI =& get_instance(); # Come back to a diferent page? if (!$back_to) { $back_to = current_url(); } $CI->session->set_userdata('back_to', $back_to); # Set a message if ($message) { UserHelper::setNotice($message); } redirect(base_url() . 'login'); }
/** * The search page call */ function index() { $this->load->helper('form'); $this->load->library('form_validation'); $submit = $this->input->post('submit'); $search_results = array(); $search_term = $this->input->get_post('term', TRUE); if ($submit) { if ($this->form_validation->run('search')) { $this->load->model('spark'); $search_results = Spark::search($search_term); } else { UserHelper::setNotice('Whoops. There were some errors. Check below and re-submit!'); } } $data['search_term'] = $search_term; $data['sparks'] = $search_results; echo json_encode($data); }
/** * The POST call to add a version to a package * Redirect to the package page on success */ public function add() { $submit = $this->input->post('submit'); if ($submit) { $this->load->library('form_validation'); $this->load->model('version'); $this->load->model('spark'); $insert = elements(array('spark_id', 'tag'), $_POST); if ($this->form_validation->run('add-version')) { if (Version::insert($insert)) { UserHelper::setNotice("Version added!"); } } else { UserHelper::setNotice("Try to enter a valid tag!", FALSE); } $spark = Spark::getById($insert['spark_id']); redirect(base_url() . 'packages/' . $spark->name . '/show'); } show_error("Whatcha doin' here?"); }
/** * Show the spark search page */ function search() { $this->load->helper('form'); $this->load->library('form_validation'); $submit = $this->input->post('submit'); $search_results = array(); $search_term = $this->input->post('term'); $data['ratings'] = array(); if ($submit) { if ($this->form_validation->run('search')) { $this->load->model('spark'); $this->load->model('rating'); $search_results = Spark::search($search_term); $ids = array(); foreach ($search_results as $s) { $ids[] = $s->id; } $data['ratings'] = $this->rating->getRatingsFromList($ids); } else { UserHelper::setNotice('Whoops. There were some errors. Check below and re-submit!'); } } $data['search_term'] = $search_term; $data['sparks'] = $search_results; $data['description'] = 'These are the most recently registered sparks with at least one release.'; $this->load->view('search/listing', $data); }
/** * Called when to show the edit page for a user's profile. Works of the current * logged in user */ public function edit() { $this->load->model('contributor'); $this->load->helper('form'); $this->load->library('form_validation'); $contributor_id = UserHelper::getId(); $contributor = Contributor::findById($contributor_id); $submit = $this->input->post('submit'); if ($submit) { if ($this->form_validation->run('edit_profile')) { $update = elements(array('email', 'website', 'real_name', 'password'), $_POST); Contributor::update($contributor_id, $update); if ($update['password']) { UserHelper::setNotice("Nice, everything saved, including your new password"); } else { UserHelper::setNotice("Nice, everything saved"); } } else { UserHelper::setNotice("Hrm, there was a problem (see below)", FALSE); } } $data = array('contributor' => $contributor); $this->load->view('contributors/edit', $data); }