$companyId = Tools::param('contactCompanyId'); $name = Tools::param('contactName'); $email = Tools::param('contactEmail'); $phone = Tools::param('contactPhone'); $alternatePhone = Tools::param('contactAlternatePhone'); $rowId = Tools::param('rowId'); $result = 'OK'; $contactId = ''; $newContactModel = null; try { $contactModel = new ContactModel(); $contactModel->setContactCompanyId($companyId); $contactModel->setContactName($name); $contactModel->setContactEmail($email); $contactModel->setContactPhone($phone); $contactModel->setContactAlternatePhone($alternatePhone); $contactController = new ContactController(); $contactId = $contactController->add($contactModel); if (!($contactId > 0)) { throw new ControllerException("Add failed."); } $newContactModel = $contactController->get($contactId); $contactRowView = new ContactListView(); $row = $contactRowView->displayContactRow($newContactModel, 'list'); } catch (ControllerException $e) { $contactRowView = new ContactListView('html', null); $contactModel->setId($rowId); $row = $contactRowView->displayContactRow($contactModel, 'add', 'Add Contact record failed. ' . $e->getMessage()); } $result = array('result' => $result, 'row' => $row, 'newId' => $contactId); echo json_encode($result) . PHP_EOL;
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * */ require_once "Libs/autoload.php"; $auth = new Auth(); if (!$auth->isAuthorized()) { $auth->forbidden(); exit(0); // Should never get here but just in case... } $result = "OK"; $id = Tools::param('id'); $mode = Tools::param('mode'); $html = ''; $contactListView = new ContactListView('html', null); if ('add' == $mode) { $contactModel = new ContactModel(); $contactModel->setId($id); $html = $contactListView->displayContactRow($contactModel, $mode); } else { $contactController = new ContactController(); $contactModel = $contactController->get($id); $html = $contactListView->displayContactRow($contactModel, $mode); } $result = array('result' => $result, 'row' => $html); echo json_encode($result) . PHP_EOL;