public static function handle_routes($app) { $app->get('/contacts', function () { $model = new ContactModel(); $contacts = !$type ? $model->get_contacts() : $model->get_contacts($type); echo json_encode($contacts); }); $app->get('/contacts/:type', function ($type) { $model = new ContactModel(); $contacts = !$type ? $model->get_contacts() : $model->get_contacts($type); echo json_encode($contacts); }); $app->get('/contact/:id', function ($id) { $model = new ContactModel(); $contact = $model->get_contact($id); echo json_encode($contact); }); $app->get('/like/contacts/:param', function ($param) { $model = new ContactModel(); $contacts = $model->like_contacts($param); echo json_encode($contacts); }); $app->get('/like/company/:param', function ($param) { $model = new CompanyModel(); $companies = $model->like_companies($param); echo json_encode($companies); }); }
public function __construct($url) { $this->url = $url; if ($url[1] == "send") { $this->mode = "send"; $contactModel = new ContactModel(); $contactModel->sendMessage("test", "*****@*****.**"); } }
/** * 存储一条消息 * @param Array $message */ public function save($data) { $message = $this->filter($data); if (!$this->check($message)) { $this->setErrCode(Error::PARAMS_ERROR); return false; } $messageId = Dao\MessageIdModel::getId(); $message['messageId'] = $messageId; $message['sendTime'] = date('Y-m-d H:i:s'); $userModel = new UserModel($this->userId); $message['isRead'] = 0; if ($userModel->getTalkId($message['sender']) == $message['receiver']) { $message['isRead'] = 1; } $messageDao = new Dao\MessageModel(Table::message($messageId)); $relationSenderDao = new Dao\RelationModel(Table::relation($message['sender'])); $relationReceiverDao = new Dao\RelationModel(Table::relation($message['sender'])); $relationData = array('sender' => $message['sender'], 'receiver' => $message['receiver'], 'senderNickname' => $message['senderNickname'], 'receiverNickname' => $message['receiverNickname'], 'messageId' => $messageId, 'isRead' => $message['isRead']); $pdo = PdoFactory::instance(Dao\MessageModel::DB_MASTER); $pdo->beginTransaction(); try { if (!$messageDao->save($message)) { throw new \Exception('save message fail!'); } if (!$relationSenderDao->has($messageId) && $relationSenderDao->save($relationData)) { throw new \Exception('save sender relation fail!'); } if (!$relationReceiverDao->has($messageId) && $relationReceiverDao->save($relationData)) { throw new \Exception('save receiver relation fail!'); } $pdo->commit(); } catch (\Exception $e) { $pdo->rollBack(); $this->setErrCode(Error::SAVE_MESSAGE_ERROR); Log::fatal(self::LOG_DIR, $e->getMessage()); return false; } $messageContentModel = new MessageContentModel(); //处理消息关系 $message['summary'] = $messageContentModel->getMessageSummary($message['content']); $contactModel = new ContactModel($this->userId); $contactModel->addContact($message); //追加未读消息 if ($message['isRead'] == 0) { $userModel->appendUnreadMessage($message['sender'], $messageId); } return true; }
public static function emailSent() { require_once 'Contact.model.php'; require_once 'User.model.php'; require_once 'Upload.model.php'; $data = array(); if (isset($_POST['send'])) { $senderName = htmlentities($_POST['name']); $senderEmail = htmlentities($_POST['email']); $senderMsg = htmlentities($_POST['message']); $subject = $_POST['subject']; $sellerEmail = $_POST['sellerEmail']; try { $result = ContactModel::sendEmailtoSeller($senderName, $senderEmail, $senderMsg, $subject, $sellerEmail); $data['template'] = 'emailSuccess.html'; $data['states'] = UserModel::getStates(); $data['categories'] = UploadModel::getCategories(); } catch (Exception $e) { $data['error'] = $e->getMessage(); $data['template'] = 'error.html'; $data['states'] = UserModel::getStates(); $data['categories'] = UploadModel::getCategories(); } } else { $data['redirect'] = '?/User/home'; } return $data; }
public function contactAction(Request $request) { $data_page = $this->index('basic_page'); $form = new ContactModel($request); if ($request->isPost()) { if ($form->isValid()) { $form->saveToDB(); mail(Config::get('admin_email'), "Сообщение от пользователя {$form->name} ", $form->name . PHP_EOL . $form->email . PHP_EOL . $form->message . PHP_EOL . $form->date); $form->name = ''; $form->email = ''; $form->message = ''; Session::setFlash(__t('message_send')); } else { Session::setFlash(__t('message_not_send')); } } $args = array('form' => $form, 'data_page' => $data_page, 'img' => $data_page['img']); return $this->render($args); }
public function contactAction(Request $request) { $form = new ContactModel($request); $msg = $request->get('msg'); if ($request->isPost()) { if ($form->isValid()) { $this->redirect('/index.php?rout=index/contact&id=3&msg=Сообщение отправленно'); $form->saveToDb(); mail('*****@*****.**', 'HELLOW', $form->name . PHP_EOL . $form->email . PHP_EOL . $form->message . PHP_EOL . $form->date); $form->name = ''; $form->email = ''; $form->message = ''; } else { $msg = 'Fail!!!'; } } $args = array('form' => $form, 'msg' => $msg); return $this->render('contact', $args); }
public function actionIndex() { $messages = ""; $error_type = ""; $success = ""; $name = ""; $email = ""; $description = ""; $error = false; if (Yii::app()->getRequest()->ispostRequest) { $name = Yii::app()->request->getParam('name'); $email = Yii::app()->request->getParam('email'); $description = Yii::app()->request->getParam('description'); if (empty($name)) { $error = true; $error_type = 'name'; $messages = "Vui lòng nhập họ tên!"; } elseif (!EmailHelper::isEmailAddress($email)) { $error = true; $error_type = 'email'; $messages = "Email không hợp lệ!"; } elseif (empty($description)) { $error = true; $error_type = 'description'; $messages = "Vui lòng nhập thông tin liên hệ !"; } else { $contact = new ContactModel(); $contact->name = $name; $contact->content = $description; $contact->email = $email; $contact->project_des = !empty(Yii::app()->session['project_des']) ? Yii::app()->session['project_des'] : ''; $contact->project_name = !empty(Yii::app()->session['project_name']) ? Yii::app()->session['project_name'] : ''; $contact->project_pirce = !empty(Yii::app()->session['project_price']) ? Yii::app()->session['project_price'] : ''; $contact->project_type = !empty(Yii::app()->session['project_type']) ? Yii::app()->session['project_type'] : ''; $contact->project_time = !empty(Yii::app()->session['project_time']) ? Yii::app()->session['project_time'] : ''; $contact->created_time = date('Y-m-d H:i:s'); $contact->save(); $success = true; $messages = "Quý khách đã gửi liên hệ thành công, chúng tôi sẽ liên hệ lại trong thời gian sớm nhất!"; } } $this->render('index', compact('error', 'messages', 'error_type', 'name', 'email', 'description', 'success')); }
public function save() { if (!isset($_POST['contactFormSubmit'])) { header('Location: /contact/index'); } $errors = array(); $check = true; $firstName = isset($_POST['first_name']) ? trim($_POST['first_name']) : NULL; $lastName = isset($_POST['last_name']) ? trim($_POST['last_name']) : NULL; $email = isset($_POST['email']) ? trim($_POST['email']) : ""; $message = isset($_POST['message']) ? trim($_POST['message']) : ""; if (empty($email)) { $check = false; array_push($errors, "E-mail is required!"); } else { if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { $check = false; array_push($errors, "Invalid E-mail!"); } } if (empty($message)) { $check = false; array_push($errors, "Message is required!"); } if (!$check) { $this->_setView('index'); $this->_view->set('title', 'Invalid form data!'); $this->_view->set('errors', $errors); $this->_view->set('formData', $_POST); return $this->_view->output(); } try { $contact = new ContactModel(); $contact->setFirstName($firstName); $contact->setLastName($lastName); $contact->setEmail($email); $contact->setMessage($message); $contact->store(); $this->_setView('success'); $this->_view->set('title', 'Store success!'); $data = array('firstName' => $firstName, 'lastName' => $lastName, 'email' => $email, 'message' => $message); $this->_view->set('userData', $data); } catch (Exception $e) { $this->_setView('index'); $this->_view->set('title', 'There was an error saving the data!'); $this->_view->set('formData', $_POST); $this->_view->set('saveError', $e->getMessage()); } return $this->_view->output(); }
public static function model($className = __CLASS__) { return parent::model($className); }
* This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * 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"; $config = new Config(); $webPage = new PJSWebPage($config->getTitle() . ' - Delete Contact'); $act = Tools::Param('act'); if ("Delete Contact" === $act) { $contactModel = new ContactModel(); $contactModel->populateFromForm(); if (!$contactModel->validateForDelete()) { $contactView = new ContactFormView('Delete Contact', $contactModel); $body = "<h2>Invalid data</h2>\n" . $contactView->getForm(); } else { $contactController = new ContactController(); $contactController->delete($contactModel); $body = "Deleted contact # " . $contactModel->getId() . "<br />\n"; } } else { $contactController = new ContactController(); $contactModel = $contactController->get(Tools::param('id')); $contactView = new ContactFormView('Delete Contact', $contactModel); $body = $contactView->getForm(); }
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer the ID of the model to be loaded */ public function loadModel($id) { $model = ContactModel::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
* This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * 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"; $config = new Config(); $webPage = new PJSWebPage($config->getTitle() . ' - Edit Contact'); $act = Tools::Param('act'); if ("Edit Contact" === $act) { $contactModel = new ContactModel(); $contactModel->populateFromForm(); if (!$contactModel->validateForUpdate()) { $view = new ContactFormView('Edit Contact', $contactModel); $body = "<h2>Invalid data</h2>\n" . $view->getForm(); } else { $contactController = new ContactController(); $newId = $contactController->update($contactModel); if ($newId > 0) { $body = "Edited contact # " . $newId . "<br />\n"; } } } else { $contactController = new ContactController(); $contactModel = $contactController->get(Tools::param('id')); $view = new ContactFormView('Edit Contact', $contactModel);
if (!$auth->isAuthorized()) { $auth->forbidden(); exit(0); // Should never get here but just in case... } $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);
$config = new Config(); $webPage = new PJSWebPage($config->getTitle() . "Contacts - Add Contact"); $body = ''; $act = Tools::Param('act'); if ("Add Contact" === $act) { $model = new ContactModel(); $model->populateFromForm(); if (!$model->validateForAdd()) { $view = new ContactFormView('Add Contact', $model); $body = "<h2>Invalid data</h2>\n" . $view->getForm(); } else { $contactController = new ContactController(); $newId = $contactController->add($model); if ($newId > 0) { $body = "Added contact # " . $newId . "<br />\n"; } } } else { $body = ""; $contactModel = new ContactModel(); $companyId = '' === Tools::param('contactCompanyId') ? 0 : Tools::param('contactCompanyId'); $contactModel->setContactCompanyId($companyId); $contactModel->setContactName(Tools::param('contactName')); $contactModel->setContactEmail(Tools::param('contactEmail')); $contactModel->setContactPhone(Tools::param('contactPhone')); $contactModel->setContactAlternatePhone(Tools::param('contactAlternatePhone')); $view = new ContactFormView("Add Contact", $contactModel); $body = $view->getForm(); } $webPage->setBody($body); $webPage->displayPage();
* 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;
public function deleteMessageAction() { if (Session::hasUser('admin')) { $request = new Request(); $contactModel = new ContactModel($request); $contactModel->deleteMessage($request->get('id')); $this->redirect('/admin/messages'); } else { throw new Exception('Access is forbidden', 403); } }
/** * @param ContactModel $model * @see ControllerBase::update() */ public function update($model) { if ($model->validateForUpdate()) { try { $query = <<<SQL UPDATE contact SET contactCompanyId = ? , contactName = ? , contactEmail = ? , contactPhone = ? , contactAlternatePhone = ? WHERE id = ? SQL; $id = $model->getId(); $contactCompanyId = $model->getContactCompanyId(); $contactName = $model->getContactName(); $contactEmail = $model->getContactEmail(); $contactPhone = $model->getContactPhone(); $contactAlternatePhone = $model->getContactAlternatePhone(); $stmt = $this->_dbh->prepare($query); if (!$stmt) { throw new ControllerException('Prepared statement failed for ' . $query); } if (!$stmt->bind_param('issssi', $contactCompanyId, $contactName, $contactEmail, $contactPhone, $contactAlternatePhone, $id)) { throw new ControllerException('Binding parameters for prepared statement failed.'); } if (!$stmt->execute()) { throw new ControllerException('Failed to execute UPDATE statement. (' . $this->_dbh->error . ')'); } /** * @SuppressWarnings checkAliases */ if (!$stmt->close()) { throw new ControllerException('Something broke while trying to close the prepared statement.'); } return $id; } catch (Exception $e) { throw new ControllerException($e->getMessage()); } } else { throw new ControllerException("Invalid data."); } }