function edit_profile($user_id)
{
// if there is any post param
$is_submit = $this->input->post('edit-profile-form');
// validation part
// The custom rules 'identity_available' and 'validate_password' can be found in '../libaries/MY_Form_validation.php'.
$validation_rules = array(
array('field' => 'firstname', 'label' => 'ชื่อจริง', 'rules' => 'required'),
array('field' => 'lastname', 'label' => 'นามสกุล', 'rules' => 'required'),
array('field' => 'nationality', 'label' => 'เชื้อชาติ', 'rules' => ''),
array('field' => 'citizen_id', 'label' => 'เลขที่บัตรประชาชน', 'rules' => 'required'),
array('field' => 'email', 'label' => 'email', 'rules' => 'required|valid_email|identity_available'),
array('field' => 'primary_lang', 'label' => 'ภาษาหลักที่เข้าใจ', 'rules' => ''),
array('field' => 'sex', 'label' => 'เพศ', 'rules' => ''),
array('field' => 'phone', 'label' => 'เบอร์โทรศัพท์', 'rules' => ''),
array('field' => 'mobile', 'label' => 'เบอร์โทรศัพท์มือถือ', 'rules' => ''),
array('field' => 'address1', 'label' => 'ที่อยู่', 'rules' => ''),
array('field' => 'address2', 'label' => 'ที่อยู่2', 'rules' => ''),
array('field' => 'province', 'label' => 'จังหวัด', 'rules' => ''),
array('field' => 'zipcode', 'label' => 'รหัสไปรษณีย์', 'rules' => ''),
);
$monk_validation_rule = array(
array('field' => 'preceptor', 'label' => 'พระอุปัชฌาย์', 'rules' => ''),
array('field' => 'priesthood_year', 'label' => 'ปีที่อุปสมบท', 'rules' => ''),
array('field' => 'priest_of_rank', 'label' => 'สมนศักดิ์', 'rules' => ''),
//array('field' => 'temple_id', 'label' => 'วัด', 'rules' => 'required'),
array('field' => 'monk_name', 'label' => 'ชื่อฉายา', 'rules' => ''),
array('field' => 'monk_id', 'label' => 'เลขที่ประจำตัวสงฆ์', 'rules' => ''),
);
$layman_validation_rule = array(
array('field' => 'education', 'label' => 'ระดับการศึกษา', 'rules' => ''),
array('field' => 'field_of_study', 'label' => 'สาขา', 'rules' => ''),
array('field' => 'occupation', 'label' => 'อาชีพ', 'rules' => ''),
array('field' => 'educational_institution', 'สถาบันการศึกษา' => 'อาชีพ', 'rules' => ''),
);
if (isset($is_submit))
{
// create user and profile
$result = false;
// set validation rule
$profile_type = $this->input->post('profile_type');
if ($profile_type == 1)
{
$this->form_validation->set_rules(array_merge($validation_rules, $layman_validation_rule));
}
else if ($profile_type == 2)
{
$this->form_validation->set_rules(array_merge($validation_rules, $monk_validation_rule));
}
// Run the validation.
if ($this->form_validation->run())
{
$result = $this->_prepare_data_and_update($user_id);
}
else
{
$this->data['error'] = validation_errors();
}
// create a user
if($result)
{
$this->session->set_flashdata('message', 'ทำการเปลี่ยนข้อมูลเรียบร้อยแล้ว');
//$this->send_change_password_confirmation();
redirect("admin/users/edit_profile/".$user_id, 'refresh');
}
}
$user = User::find($user_id);
$this->data['user_id'] = $user_id;
$this->data['staff'] = $user;
$this->data['profile'] = $user->profile;
$this->data['email'] = $user->uacc_email;
$this->data['firstname'] = $user->profile->firstname;
$this->data['lastname'] = $user->profile->lastname;
$this->data['addresses'] = $user->profile->addresses;
$this->data['secondary_langs'] = $user->profile->secondary_languages;
$this->data['profilelogs'] = Profilelog::all(); //ส่วนนี้จะดึงเอาข้อมูลที่ถูกแก้ไขแล้ว ที่ถูกเก็บไว้ที่ DB->profile_logs ดึงมาโชว์ทั้งหมด
// generate dropdown lists
$this->data['profile_type_list'] = ProfileType::get_select_list();
$this->data['sex_list'] = Sex::get_select_list();
$this->data['nationality_list'] = Nationality::get_select_list();
$this->data['primary_lang_list'] = Language::get_select_list();
$this->data['occupation_list'] = Occupation::get_select_list();
$this->data['secondary_lang_list'] = Language::get_select_list(); unset($this->data['secondary_lang_list'][""]);
$this->data['province_list'] = Province::get_select_list();
$this->data['priest_of_rank_list'] = PriestOfRank::get_select_list();
$this->data['temple_list'] = Temple::get_select_list();
$this->data['title'] = "แก้ไขประวัติของ".$user->profile->firstname.' '.$user->profile->lastname;
// style for this page
$this->data['page_styles'] = array("bootstrap-datetimepicker.min.css");
// script for this page
$this->data['page_scripts'] = array("moment.js", "bootstrap-datetimepicker.min.js", "admin.edit.user.profile.js");
// $this->data['inpage_script'] = "bookings/_calendar_js";
// specify view
$this->data['view_name'] = "/admin/users/edit_profile";
$this->load->view('layouts/main', $this->data);
}
controllers
private function _prepare_data_and_update($user_id)
{
$user = User::find($user_id);
$log_attribute = new Profilelog();
$log_attribute->profiles_id = $this->input->post('id');
$log_attribute->citizen_id = $this->input->post('citizen_id');
$log_attribute->firstname = $this->input->post('firstname');
$log_attribute->lastname = $this->input->post('lastname');
$log_attribute->save(); //ส่วนนี้เป็นข้อมูลที่จะจัดเก็บแล้วนำมาแสดง