1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
| function editAction() {
$contactId = $this->_request->get('id');
$isAdd = $this->_getParam('isAdd', false);
if ($this->_request->isPost()) {
$post = array_map('utf8_decode', $this->_request->getPost());
$datas=array (
'ctct_name' => htmlspecialchars($post['contact_name'], ENT_QUOTES),
'ctct_firstname' => htmlspecialchars($post['contact_firstname'], ENT_QUOTES),
'ctct_mail' => htmlspecialchars($post['contact_mail'], ENT_QUOTES),
'ctct_phone' => ereg_replace("([0-9]{1}).([0-9]{2}).([0-9]{2}).([0-9]{2}).([0-9]{2})", "\\1\\2\\3\\4\\5", $post['contact_phone']),
'ctct_genre' => (int)$post['contact_genre'],
'grp_id' => (int)$post['contact_group']
);
if (!$isAdd) {
$res = $this->model->updateContact($contactId, $datas);
} else {
$res = $this->model->insertContact($datas);
}
#Fast_Debug::show($isAdd, $res);
if (!$res->success) {
$res->error = UNAVALABLE;
}
$this->response = $res;
} else {
if (!$isAdd) {
$data = $this->model->getContactById($contactId);
if (isset($data->contact_phone)) {
$data->contact_phone = ereg_replace("([0-9]{1})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})", "0\\1 \\2 \\3 \\4 \\5", $data->contact_phone);
} else {
$data->contact_phone = null;
}
} else {
$data = null;
}
if ($data) {
$this->_setListResponse(array($data));
} else {
$this->_setListResponse(null);
}
}
} |
Partager