public function register_user()
{
if ($this->input->post()) {
$this->form_validation->set_rules('first_name', 'First Name', 'required|is_unique[user.first_name]');
$this->form_validation->set_rules('last_name', 'Last Name', 'required');
$this->form_validation->set_rules('user_name', 'User Name', 'trim|required|valid_email|is_unique[user.user_name]');
$this->form_validation->set_rules('user_password', 'Paswword', 'required');
$this->form_validation->set_rules('con_user_password', 'Confirm Password', 'required|matches[user_password]');
if (empty($_FILES['profile']['name']))
{
$this->form_validation->set_rules('profile', 'Profile Pic', 'required');
}
if ($this->form_validation->run() == FALSE) {
$this->load->view('register');
} else {
$referal_code = $this->input->post('referal_code');
$earnings = 50;
if ($referal_code != "") {
$data = $this->user_model->getRefralCode($referal_code);
if ($data) {
$earnings = 100;
$referal_code = $data['referal_code'];
$earningsAdd = $data['earnings'] + 200;
$user = array(
'earnings' => $earningsAdd
);
$this->db->where('referal_code', $referal_code);
$this->db->update('user', $user);
} else {
$earnings = 50;
}
}
$user = array(
'first_name' => $this->input->post('first_name'),
'last_name' => $this->input->post('last_name'),
'user_name' => $this->input->post('user_name'),
'user_password' => md5($this->input->post('user_password')),
'referal_code' => strtoupper(substr(md5(time() . rand(10000, 99999)), 0, 6)),
'earnings' => $earnings,
'profile' =>$this->upload_image($_FILES)
);
$this->user_model->register_user($user);
redirect('User/login_view', 'refresh');
}
} else {
$this->load->view('register');
}
}
0 Comments