/** * Updates a seller contact. * * @param int $seller_id Seller ID. * @param int $id Contact ID. * * @return void */ public function put_index($seller_id = null, $id = null) { $contact = $this->get_contact($id); $validator = \Validation_Contact::update('seller'); if (!$validator->run(\Input::put())) { throw new HttpBadRequestException($validator->errors()); } $data = $validator->validated(); $contact = \Service_Contact::update($contact, $data); if (!$contact) { throw new HttpServerErrorException(); } $this->response($contact); }
/** * POST Edit action. * * @param int $id Contact ID. * * @return void */ public function post_edit($id = null) { $this->get_edit($id); $validator = Validation_Contact::update(); if (!$validator->run()) { Session::set_alert('error', __('form.error')); $this->view->errors = $validator->error(); return; } $contact = $this->get_contact($id); $data = $validator->validated(); if (!Service_Contact::update($contact, $data)) { Session::set_alert('error', 'There was an error updating the contact.'); return; } Session::set_alert('success', 'The contact has been updated.'); Response::redirect('settings/contacts'); }
/** * Sending mails * * @since 1.0.0 First time this method was introduced * @since 1.1.0 Added jQuery Textarea Characters Counter Plugin * * @link http://roy-jin.appspot.com/jsp/textareaCounter.jsp * * @uses Request::query * @uses Route::get * @uses Route::uri * @uses URL::query * @uses URL::site * @uses Validation::rule * @uses Config::get * @uses Config::load * @uses Assets::js */ public function action_mail() { $this->title = __('Contact us'); $config = Config::load('contact'); Assets::js('textareaCounter', 'media/js/jquery.textareaCounter.plugin.js', array('jquery'), FALSE, array('weight' => 10)); Assets::js('greet/form', 'media/js/greet.form.js', array('textareaCounter'), FALSE, array('weight' => 15)); //Add schema.org support $this->schemaType = 'ContactPage'; // Set form destination $destination = !is_null($this->request->query('destination')) ? array('destination' => $this->request->query('destination')) : array(); // Set form action $action = Route::get('contact')->uri(array('action' => $this->request->action())) . URL::query($destination); // Get user $user = User::active_user(); // Set mail types $types = $config->get('types', array()); $view = View::factory('contact/form')->set('destination', $destination)->set('action', $action)->set('config', $config)->set('types', $types)->set('user', $user)->bind('post', $post)->bind('errors', $this->_errors); // Initiate Captcha if ($config->get('use_captcha', FALSE) and !$this->_auth->logged_in()) { $captcha = Captcha::instance(); $view->set('captcha', $captcha); } if ($this->valid_post('contact')) { $post = Validation_Contact::factory($this->request->post()); if ($post->check()) { // Create the email subject $subject = __('[:category] :subject', array(':category' => $types[$post['category']], ':subject' => Text::plain($post['subject']))); // Create the email body $body = View::factory('email/contact')->set('name', $post['name'])->set('body', $post['body'])->set('config', Config::load('site'))->render(); // Create an email message $email = Email::factory()->to(Text::plain($this->_config->get('site_email', '*****@*****.**')), __('Webmaster :site', array(':site' => Template::getSiteName())))->subject($subject)->from($post['email'], Text::plain($post['name']))->message($body, 'text/html'); // @todo message type should be configurable // Send the message $email->send(); Log::info(':name sent an e-mail regarding :cat', array(':name' => Text::plain($post['name']), ':cat' => $types[$post['category']])); Message::success(__('Your message has been sent.')); // Always redirect after a successful POST to prevent refresh warnings $this->request->redirect(Route::get('contact')->uri(), 200); } else { $this->_errors = $post->errors('contact', TRUE); } } $this->response->body($view); }