public function edit() { $user = $this->input->post(); $id = intval($user['id']); $user_db = $this->user_model->get(null, $id); $rules = $this->user_model->rules; if ($user['username'] != $user_db->username) { $rules['username']['rules'] .= '|is_unique[user.username]'; } if ($user['email'] != $user_db->email) { $rules['email']['rules'] .= '|is_unique[user.email]'; } $this->form_validation->set_rules($rules); if ($this->form_validation->run()) { $user['password'] = hash_pass($user['password']); if ($id = $this->user_model->save($user, $id)) { $data['status'] = 'success'; $data['msg'] = 'Sửa thông tin thành viên thành công.'; $data['reload'] = logged_url('user'); } else { $data['status'] = 'error'; $data['msg'] = 'Không thể sửa thông tin thành viên, hãy thử lại.'; $data['reload'] = true; } } else { $data['status'] = 'error'; $data['msg']['form_error'] = show_form_error($rules); } echo json_encode($data); }
public function edit() { $form = $this->input->post(); $id = intval($form['form_id']); $form_db = $this->form_model->get(null, $id); $rules = $this->form_model->rules; if ($form['form_title'] != $form_db->form_title) { $rules['form_title']['rules'] .= '|is_unique[forms.form_title]'; } $this->form_validation->set_rules($rules); if ($this->form_validation->run()) { if ($id = $this->form_model->save($form, $id)) { $data['status'] = 'success'; $data['msg'] = 'Sửa nội dung mẫu đơn thành công.'; } else { $data['status'] = 'error'; $data['msg'] = 'Không thể sửa nội dung mẫu đơn, hãy thử lại.'; $data['reload'] = true; } } else { $data['status'] = 'error'; $data['msg']['form_error'] = show_form_error($rules); } echo json_encode($data); }
public function edit() { $lecturer = $this->input->post(); $id = intval($lecturer['id']); unset($lecturer['id']); $lecturer_db = $this->lecturer_model->get(null, $id); $rules = $this->lecturer_model->rules; if ($lecturer['userid'] != $lecturer_db->userid) { $rules['userid']['rules'] .= '|is_unique[lecturer.userid]'; } $this->form_validation->set_rules($rules); if ($this->form_validation->run()) { $lecturer['birthday'] = date_format(date_create($lecturer['birthday']), 'Y-m-d H:j:s'); if ($this->lecturer_model->save($lecturer, $id)) { $data['status'] = 'success'; $data['msg'] = 'Thêm giảng viên mới thành công.'; $data['reload'] = logged_url('lecturers'); } else { $data['status'] = 'error'; $data['msg'] = 'Không thể thêm giảng viên mới, hãy làm mới và thử lại.'; } } else { $data['status'] = 'error'; $data['msg']['form_error'] = show_form_error($rules); } echo json_encode($data); }
public function edit() { $ap = $this->input->post(); $id = intval($ap['ap_id']); unset($ap['ap_id']); $assigned_db = $this->ap_model->get(null, $id); $rules = $this->ap_model->rules; if ($assigned_db->student_id != $ap['student_id']) { $rules['student_id']['rules'] .= '|is_unique[assigning_practice.student_id]'; } $this->form_validation->set_rules($rules); if ($this->form_validation->run()) { if ($id = $this->ap_model->save($ap, $id)) { $data['status'] = 'success'; $data['msg'] = 'Phân công thành công.'; $data['reload'] = logged_url('assigning_practice'); } else { $data['status'] = 'error'; $data['msg'] = 'Không thể phân công, hãy làm mới và thử lại.'; } } else { $data['status'] = 'error'; $data['msg']['form_error'] = show_form_error($rules); } echo json_encode($data); }
/** * Sửa thông tin sinh viên * @return void */ public function edit() { // Lưu thông tin từ view $student = $this->input->post(); // Lấy ID của sinh viên từ view $id = intval($student['id']); // Lấy thông tin sinh viên từ csdl $student_db = $this->student_model->get(null, $id); // Lấy các quy tắc chuẩn hóa dữ liệu form từ model $rules = $this->student_model->rules; // Nếu đổi mã sinh viên khác, chắc chắn không trùng với các sinh viên khác if ($student['mssv'] != $student_db->mssv) { $rules['mssv']['rules'] .= '|is_unique[student.mssv]'; } // Nếu đổi email khác, chắc chắn không trùng với các sinh viên khác if ($student['email'] != $student_db->email) { $rules['email']['rules'] .= '|is_unique[student.email]'; } // Áp dụng các quy tắc $this->form_validation->set_rules($rules); // Các trường nhập vào đúng quy tắc if ($this->form_validation->run()) { $student['birthday'] = date_format(date_create($student['birthday']), 'Y-m-d H:j:s'); // Lưu thông tin sinh viên if ($id = $this->student_model->save($student, $id)) { // Lưu thành công $data['status'] = 'success'; $data['msg'] = 'Cập nhật thông tin sinh viên thành công.'; $data['reload'] = logged_url('student'); } else { // Lưu thất bại $data['status'] = 'error'; $data['msg'] = 'Không thể cập nhật thông tin sinh viên, hãy thử lại.'; $data['reload'] = true; } } else { // Dữ liệu từ form không chính xác $data['status'] = 'error'; $data['msg']['form_error'] = show_form_error($rules); } // Trả kết quả cho view echo json_encode($data); }
public function edit() { // Lưu thông tin từ view $company = $this->input->post(); // Lấy địa chỉ ID của công ty $id = intval($company['id']); // Lấy thông tin của công ty từ csdl $company_db = $this->company_model->get(null, $id); // Nếu thay đổi tên công ty, kiểm tra xem có trùng tên với các công ty khác không if ($company['name'] != $company_db->name) { $rules['name']['rules'] .= '|is_unique[company.name]'; } // Lưu các quy tắc từ model $rules = $this->company_model->rules; // Áp dụng các quy tắc $this->form_validation->set_rules($rules); // Dữ liệu từ form là chuẩn if ($this->form_validation->run()) { // Lưu thông tin công ty if ($id = $this->company_model->save($company, $id)) { // THành công $data['status'] = 'success'; $data['msg'] = 'Sửa thông tin công ty thành công.'; $datae['reload'] = logged_url('companies'); } else { // Thất bại $data['status'] = 'error'; $data['msg'] = 'Không thể sửa thông tin công ty, hãy thử lại.'; $data['reload'] = true; } } else { // Dữ liệu từ form không chính xáv $data['status'] = 'error'; $data['msg']['form_error'] = show_form_error($rules); } // Trả kết quả về cho view echo json_encode($data); }
public function edit() { $file = $_FILES['pr_attachment']; $config['upload_path'] = FCPATH . 'uploads/'; $config['allowed_types'] = 'pdf|docx|doc|xls|xlsx|ppt|pptx'; $config['max_size'] = '1000000'; $config['encrypt_name'] = true; $this->load->library('upload', $config); if (!$this->upload->do_upload('pr_attachment')) { $data['status'] = 'error'; $data['msg'] = 'Không thể tải lên tập tin, xin vui lòng thử lại.'; } else { $pr_id = intval($this->input->post('pr_id')); $rules = $this->pr_model->rules; $this->form_validation->set_rules($rules); if ($this->form_validation->run()) { $upload_data = $this->upload->data(); $report['pr_attachment'] = $upload_data['file_name']; $report['pr_title'] = $this->input->post('pr_title'); $report['user_id'] = $this->session->userdata('user')['id']; if ($this->pr_model->save($report, $pr_id)) { $data['status'] = 'success'; $data['msg'] = 'Sửa báo cáo thành công!'; $data['reload'] = logged_url('practice_report'); } else { $data['status'] = 'error'; $data['msg'] = 'Không thể sửa báo cáo, vui lòng làm mới và thử lại.'; } } else { unlink(FCPATH . 'uploads/' . $report['pr_attachment']); $data['status'] = 'error'; $data['msg']['form_error'] = show_form_error($rules); } } echo json_encode($data); }