00001 <?php
00002
00003
00004
00005
00006
00007
00008 class ContactBaseController extends ControllerBase {
00009
00010
00011
00012
00013 public function get_routes() {
00014 $base = $this->get_base_route();
00015 $ret = array(
00016 'form' => new ExactMatchRoute("$base/", $this, 'contact_form', new NoCacheCacheManager()),
00017 );
00018 return $ret;
00019 }
00020
00021
00022
00023
00024
00025
00026 protected function get_base_route() {
00027 return 'contact';
00028 }
00029
00030
00031
00032
00033
00034
00035 public function action_contact_form($page_data) {
00036 $page_data->in_history = false;
00037 $page_data->head->robots_index = ROBOTS_NOINDEX_FOLLOW;
00038 $page_data->breadcrumb = array(tr('Contact', 'contact'));
00039 $page_data->head->title = tr('Contact Us', 'contact');
00040 $page_data->head->description = tr('Send us an e-mail through the contact form.', 'contact');
00041
00042 Load::tools('formhandler');
00043 $formhandler = new FormHandler('frmcontact');
00044 if ($page_data->has_post_data()) {
00045 $this->do_contact_form($page_data, $formhandler);
00046 }
00047
00048 $view = ViewFactory::create_view(IViewFactory::CONTENT, 'contact/form', $page_data);
00049 $formhandler->prepare_view($view);
00050 $view->render();
00051 }
00052
00053
00054
00055
00056
00057
00058
00059 private function do_contact_form(PageData $page_data, FormHandler $formhandler) {
00060 $err = $formhandler->validate();
00061 if ($err->is_ok()) {
00062 Load::commands('generics/mail');
00063 $post = $page_data->get_post();
00064 $data = $post->get_array();
00065 if (empty($data['name'])) { $err->merge(tr('Please provide a name.')); }
00066 if (empty($data['email'])) {
00067 $err->merge(tr('Please provide an email address.'));
00068 } elseif (!Validation::is_email($data['email'])) {
00069 $err->merge(tr('Your email address looks invalid.'));
00070 }
00071 if (empty($data['message'])) { $err->merge(tr('The message should not be empty.')); }
00072 if (empty($data['subject'])) { $data['subject'] = tr('Contact Form Message', 'contact'); }
00073 if ($err->is_ok()) {
00074 $cmd = new MailCommand($data['subject'], Config::get_value(Config::MAIL_SUPPORT), 'contact/mail', $post->get_array());
00075 $err->merge($cmd->execute());
00076 }
00077 }
00078 $formhandler->finish($err, tr('Your message has been send successfully.', 'contact'));
00079 }
00080
00081 }