public function register() { if ($this->session->userdata('loggedin')) { $this->load->helper('url'); redirect($this->domain); } $this->load->library('form_validation'); $this->load->helper('form'); $this->load->helper('build_data'); $post = $this->input->post(); $message = 'Please fill all the required fields.'; $status = 'error'; $countries = $this->db->query('CALL GetCountry()'); $countries = buildDataDropdown($countries, 'CountryID', 'CountryName'); // To get the parameter redirect after $get = $this->input->get(); if (!empty($post)) { $this->form_validation->set_rules('fullname', 'Full name', 'required'); $this->form_validation->set_rules('email', 'Email', 'required|valid_email'); $this->form_validation->set_rules('password', 'Password', 'required'); $this->form_validation->set_rules('gender', 'Gender', 'required'); $this->form_validation->set_rules('CountryID', 'Country', 'required'); if ($this->form_validation->run() == TRUE) { $res = $this->db->query('CALL RegisterUser(?,?,?,?,?)', array($post['fullname'], $post['email'], sha1($post['password']), $post['gender'], $post['CountryID'])); $data = $res->result()[0]; if ($data->UserID != -1) { $this->session->set_userdata('loggedin', true); $this->session->set_userdata('userid', $data->UserID); $this->session->set_userdata('username', $post['fullname']); $this->session->set_userdata('useremail', $post['email']); $this->session->set_userdata('isAdmin', 0); $this->session->set_userdata('userphoto', 'default'); if (isset($get['redirect_after'])) { $this->session->set_userdata('redirect_now', true); $this->session->set_userdata('redirect_after', $get['redirect_after']); } $message = 'Successfully signed up.'; $status = 'success'; } else { $this->setCustomError('email', 'Email has been registered. Please try another email.'); } } } $this->load->vars(array('redirect_after' => isset($get['redirect_after']) ? $get['redirect_after'] : false, 'countries' => $countries)); if ($this->input->is_ajax_request()) { loadMessage($message, $status); } else { $this->load->vars(array('site_title' => 'Register')); } $this->render($post); }
public function callDefaultData($type = 'search', $with_sort = false) { $food_types = $this->db->query('CALL GetAllFoodType()'); $food_types = buildDataDropdown($food_types, 'FoodTypeID', 'FoodTypeName'); $cuisines = $this->db->query('CALL GetAllCuisine()'); $cuisines = buildDataDropdown($cuisines, 'CuisineID', 'CuisineName'); $food_process = array(); // For translation purpose, we will hardcode Food process from db if ($this->site_lang == 'indonesian') { $food_process = array(7 => lang('grilled'), 1 => lang('fried'), 3 => lang('steamed'), 2 => lang('baked'), 5 => lang('boiled'), 6 => lang('not_cooked'), 4 => lang('stir_fry')); } else { if ($this->site_lang == 'english') { $food_process = array(2 => lang('baked'), 5 => lang('boiled'), 1 => lang('fried'), 7 => lang('grilled'), 6 => lang('not_cooked'), 3 => lang('steamed'), 4 => lang('stir_fry')); } } $price_ranges = array(); $estimation_peoples = array(); $measure_sizes = array(); $compositions = array(); $sorts = array(); if ($type == 'create') { // $food_process = $this->db->query('CALL GetAllFoodProcess()'); // $food_process = buildDataDropdown($food_process, 'FoodProcessID', 'FoodProcessName'); $price_ranges = $this->db->query('CALL GetAllPriceRange()'); $price_ranges = buildDataDropdown($price_ranges, 'PriceRangeID', 'PriceRangeName'); $estimation_peoples = $this->db->query('CALL GetAllEstPeople()'); $estimation_peoples = buildDataDropdown($estimation_peoples, 'EstPeopleID', 'EstPeopleName'); // Add word 'People', need to do it here for translation purpose $lengthEP = count($estimation_peoples); for ($n = 1; $n <= $lengthEP; $n++) { $estimation_peoples[$n] = sprintf('%s %s', $estimation_peoples[$n], $this->lang->line('people')); } $measure_sizes = $this->db->query('CALL GetAllMeasureSize()'); $measure_sizes = buildDataDropdown($measure_sizes, 'MeasureSizeID', 'MeasureSizeName'); $compositions = $this->db->query('CALL GetAllComposition()'); $compositions = buildDataAutocomplete($compositions, 'CompositionID', 'CompositionName'); } if (!empty($with_sort)) { $sorts = array(0 => $this->lang->line('alphabet'), 1 => $this->lang->line('latest_recipe'), 2 => $this->lang->line('popular_recipe')); } $this->load->vars(array('food_types' => $food_types, 'cuisines' => $cuisines, 'food_process' => $food_process, 'price_ranges' => $price_ranges, 'estimation_peoples' => $estimation_peoples, 'measure_sizes' => $measure_sizes, 'compositions' => json_encode($compositions), 'sorts' => $sorts)); }