public function search_date() { $search_date = ''; if ($_POST['pat_birth'] != '') { $pat_birth = ThaitoDBDate($_POST['pat_birth']); $search_date .= " and pat_birth = '{$pat_birth}' "; $_POST['pat_birth'] = DBtoThaiDate($pat_birth); } $date_start = ThaitoDBDate($this->input->post('date_start')); $date_end = ThaitoDBDate($this->input->post('date_end')); if ($date_start != '' or $date_end != '') { if ($date_start != '' && $date_end == '') { $date_end = date('Y-m-d'); } elseif ($date_start == '' && $date_end != '') { $date_start = date('Y-m-d'); } elseif ($date_start > $date_end) { $date_start = ThaitoDBDate($this->input->post('date_end')); $date_end = ThaitoDBDate($this->input->post('date_start')); } elseif ($date_end < $date_start) { $date_end = ThaitoDBDate($this->input->post('date_start')); $date_start = ThaitoDBDate($this->input->post('date_end')); } $date_start_set = $date_start; $date_end_set = $date_end; if ($date_start > $date_end or $date_end < $date_start) { $date_start = $date_end_set; $date_end = $date_start_set; } $table_check_pat = array('list_teach', 'list_pat_check', 'list_pat_checked', 'list_owner_doc'); if (in_array($this->router->fetch_method(), $table_check_pat)) { $search_date .= " and check_pat.date between '{$date_start}' and '{$date_end}' "; } else { $search_date .= " and date between '{$date_start}' and '{$date_end}' "; } $_POST['date_start'] = DBtoThaiDate($date_start); $_POST['date_end'] = DBtoThaiDate($date_end); } return $search_date; }
public function query($pat_id = false) { $data['pat_id'] = $pat_id; $check_null = array('road', 'street', 'c_road', 'c_treet', 'pat_tel_local', 'pat_mobile_local', 'pat_tel_current', 'pat_mobile_current'); foreach ($check_null as $key => $value) { if ($this->input->post($value) == '') { $_POST[$value] = " - "; } } $param = array('hn' => $this->input->post('hn'), 'prefix' => $this->input->post('prefix'), 'pat_name' => $this->input->post('pat_name'), 'pat_lname' => $this->input->post('pat_lname'), 'pat_right' => $this->input->post('pat_right'), 'pat_birth' => ThaitoDBDate($this->input->post('pat_birth')), 'pat_year' => $this->input->post('pat_year'), 'pat_sex' => $this->input->post('pat_sex'), 'pat_status' => $this->input->post('pat_status'), 'pat_nationality' => $this->input->post('pat_nationality'), 'pat_race' => $this->input->post('pat_race'), 'pat_raligion' => $this->input->post('pat_raligion'), 'pat_id_card' => $this->input->post('pat_id_card'), 'pat_address_local' => '<b>เลขที่</b>..... ' . $this->input->post('no') . ' .....<b>หมู่ที่</b>..... ' . $this->input->post('moo') . ' .....<b>ถนน</b>..... ' . $this->input->post('road') . ' .....<b>ซอย</b>..... ' . $this->input->post('street') . ' .....<br><b>ตำบล</b>..... ' . $this->input->post('tombol') . ' .....<b>อำเภอ</b>..... ' . $this->input->post('aumper') . ' <br>.....<b>จังหวัด</b>..... ' . $this->input->post('j_province') . ' .....<b>รหัสไปรษณีย์</b>..... ' . $this->input->post('zipcode') . ' .....<b>ประเทศ</b>..... ' . $this->input->post('country'), 'pat_tel_local' => $this->input->post('pat_tel_local'), 'pat_mobile_local' => $this->input->post('pat_mobile_local'), 'pat_address_current' => '<b>เลขที่</b>.....' . $this->input->post('c_no') . ' .....<b>หมู่ที่</b>..... ' . $this->input->post('c_moo') . ' .....<b>ถนน</b>..... ' . $this->input->post('c_road') . ' .....<b>ซอย</b>..... ' . $this->input->post('c_street') . ' .....<br><b>ตำบล</b>..... ' . $this->input->post('c_tombol') . ' .....<b>อำเภอ</b>..... ' . $this->input->post('c_aumper') . '<br> .....<b>จังหวัด</b>..... ' . $this->input->post('c__province') . ' .....<b>รหัสไปรษณีย์</b>..... ' . $this->input->post('c_zipcode') . ' .....<b>ประเทศ</b>..... ' . $this->input->post('c_country'), 'pat_tel_current' => $this->input->post('pat_tel_current'), 'pat_mobile_current' => $this->input->post('pat_mobile_current'), 'pat_contact_name' => $this->input->post('pat_contact_name'), 'pat_contact_lname' => $this->input->post('pat_contact_lname'), 'pat_contact_rel' => $this->input->post('pat_contact_rel'), 'pat_contact_tel' => $this->input->post('pat_contact_tel'), 'pat_contact_mobile' => $this->input->post('pat_contact_mobile'), 'pat_job_before' => $this->input->post('pat_job_before'), 'pat_job_current' => $this->input->post('pat_job_current'), 'pat_cause' => $this->input->post('pat_cause'), 'pat_date_amp_left' => $this->input->post('pat_date_amp_left_text') != '' ? $this->input->post('pat_date_amp_left_text') : ThaitoDBDate($this->input->post('pat_date_amp_left')), 'pat_date_amp_right' => $this->input->post('pat_date_amp_right_text') != '' ? $this->input->post('pat_date_amp_right_text') : ThaitoDBDate($this->input->post('pat_date_amp_right')), 'amp_type_other' => $this->input->post('amp_type_other'), 'pat_pros_place_radio' => $this->input->post('pat_pros_place_radio'), 'pat_pros_place' => $this->input->post('pat_pros_place'), 'pat_pros_date' => $this->input->post('pat_pros_date'), 'pat_move_ment' => $this->input->post('pat_move_ment'), 'pat_move_ment_tool' => $this->input->post('pat_move_ment_tool'), 'amp_type_id' => $this->input->post('amp_type_id'), 'status' => '1', 'date' => date('Y-m-d')); if ($this->input->post('skip') == 1) { unset($param['pat_address_current']); $param['pat_address_current'] = $param['pat_address_local']; $param['pat_tel_current'] = $param['pat_tel_local']; $param['pat_mobile_current'] = $param['pat_mobile_local']; } if ($this->input->post('skip') == 1) { $data_adr_current = $data_adr_local; unset($data_adr_current['ads_type']); $data_adr_current['ads_type'] = 2; } if ($pat_id == false) { $this->general_model->insert('patients', $param); $pat_id = $this->db->insert_id(); $data_adr_local = array('pat_id' => $pat_id, 'no' => $this->input->post('no'), 'moo' => $this->input->post('moo'), 'road' => $this->input->post('road'), 'street' => $this->input->post('street'), 'tombol' => $this->input->post('tombol'), 'aumper' => $this->input->post('aumper'), 'province' => $this->input->post('j_province'), 'zipcode' => $this->input->post('zipcode'), 'country' => $this->input->post('country'), 'ads_type' => 1); $data_adr_current = array('pat_id' => $pat_id, 'no' => $this->input->post('c_no'), 'moo' => $this->input->post('c_moo'), 'road' => $this->input->post('c_road'), 'street' => $this->input->post('c_street'), 'tombol' => $this->input->post('c_tombol'), 'aumper' => $this->input->post('c_aumper'), 'province' => $this->input->post('c_province'), 'zipcode' => $this->input->post('c_zipcode'), 'country' => $this->input->post('c_country'), 'ads_type' => 2); $this->general_model->insert('adress', $data_adr_local); $this->general_model->insert('adress', $data_adr_current); } else { // var_dump($param);die(); $this->general_model->update('patients', $param, "pat_id = '{$pat_id}'"); $data_adr_local = array('no' => $this->input->post('no'), 'moo' => $this->input->post('moo'), 'road' => $this->input->post('road'), 'street' => $this->input->post('street'), 'tombol' => $this->input->post('tombol'), 'aumper' => $this->input->post('aumper'), 'province' => $this->input->post('j_province'), 'zipcode' => $this->input->post('zipcode'), 'country' => $this->input->post('country')); $this->general_model->update('adress', $data_adr_local, "pat_id = '{$pat_id}' and ads_type = 1"); // var_dump($data_adr_local);die(); $data_adr_current = array('no' => $this->input->post('c_no'), 'moo' => $this->input->post('c_moo'), 'road' => $this->input->post('c_road'), 'street' => $this->input->post('c_street'), 'tombol' => $this->input->post('c_tombol'), 'aumper' => $this->input->post('c_aumper'), 'province' => $this->input->post('c_province'), 'zipcode' => $this->input->post('c_zipcode'), 'country' => $this->input->post('c_country')); $this->general_model->update('adress', $data_adr_current, "pat_id = '{$pat_id}' and ads_type = 2 "); // echo $this->db->last_query(); // var_dump($data_adr_current);die(); } $this->load->library('image_lib'); foreach ($_FILES as $key => $value) { if ($_FILES[$key]['name'] != '') { $data_upload_pic2 = array(); $config2 = array(); $config2['file_name'] = $pat_id . '_' . $key; $config2['allowed_types'] = '|jpg|jpeg|png'; $config2['overwrite'] = false; $config2['upload_path'] = './file_upload/pic/'; $this->load->library('upload', $config2); $this->upload->do_upload($key); $data_upload_pic2 = $this->upload->data(); $data_pic2 = array($key => $data_upload_pic2['file_name']); $this->db->where('pat_id', $pat_id); $this->db->update('patients', $data_pic2); $config['image_library'] = 'gd2'; $config['source_image'] = './file_upload/pic/' . $data_upload_pic2['file_name']; $config['maintain_ratio'] = TRUE; $config['width'] = 500; $config['height'] = 400; $this->image_lib->clear(); $this->image_lib->initialize($config); $this->image_lib->resize(); } } redirect(base_url() . 'patient/profile/' . $pat_id); }