$phone = isset($_POST['phone']) ? $_POST['phone'] : ''; $participants = isset($_POST['participants']) ? $_POST['participants'] : ''; $observations = isset($_POST['observations']) ? $_POST['observations'] : ''; $customer = array('id' => $id, 'name' => $name, 'email' => $email, 'phone' => $phone, 'participants' => $participants, 'observations' => $observations); } /* echo 'action: '.$action; echo '$customer'; print_r($customer); */ $c = new Connection(); $conn = $c->getConnection(); $customerDAO = new CustomerDAO($conn); switch ($action) { case 'new': $insert_id = $customerDAO->create($customer); break; case 'update': $customerDAO->update($customer); break; case 'delete': //echo 'delete dao'.$id; exit; $customerDAO->delete($id); break; } if ($isAjax) { echo json_encode($response); exit; } else { header("Location: " . $siteUrl . "/customer_list.php?r=" . mt_rand(0, 9999999)); }
private function updatePost() { $id = (int) $_POST['id']; $full_name = trim(remove_slashes($_POST['full_name'])); $address = trim(remove_slashes($_POST['address'])); $email = trim(remove_slashes($_POST['email'])); $birthday = trim(remove_slashes($_POST['birthday'])); $city_id = (int) $_POST['city_id']; $note = trim(remove_slashes($_POST['note'])); $phone = trim(remove_slashes($_POST['phone'])); $this->registry->template->customer = array('id' => $id, 'full_name' => htmlspecialchars($full_name), 'address' => htmlspecialchars($address), 'email' => htmlspecialchars($email), 'birthday' => htmlspecialchars($birthday), 'city_id' => $city_id, 'note' => htmlspecialchars($note), 'phone' => htmlspecialchars($phone)); $messageStr = ''; if (!isset($full_name) || strlen($full_name) == 0) { $messageStr .= 'Họ và tên: không được bỏ trống.<br />'; } if (isset($email) && strlen($email) > 0) { if (!valid_email($email)) { $messageStr .= 'Email: không hợp lệ.<br />'; } } if (isset($birthday) && strlen($birthday) > 0) { if (!valid_date_vn($birthday)) { $messageStr .= 'Ngày sinh: không hợp lệ.<br />'; } } $messageStr = trim($messageStr); $customerDAO = new CustomerDAO(DataSource::getInstance()); if ($messageStr != '') { $this->registry->template->message = array('type' => 'error', 'value' => $messageStr); } else { $result = $customerDAO->update($id, $full_name, convert_date_to_us($birthday), $address, $email, $city_id, $note, $phone); if ($result) { $this->registry->template->message = array('type' => 'info', 'value' => 'Lưu thành công!'); } else { $this->registry->template->message = array('type' => 'error', 'value' => 'Có lỗi xảy ra.'); } } $tmp = $customerDAO->findById($id); $this->registry->template->customer_backup = $tmp; if (!$tmp) { $this->registry->template->message = array('type' => 'error_not_found', 'value' => 'Không tồn tại khách hàng này!'); } }