00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 class Mage_Contacts_IndexController extends Mage_Core_Controller_Front_Action
00035 {
00036
00037 const XML_PATH_EMAIL_RECIPIENT = 'contacts/email/recipient_email';
00038 const XML_PATH_EMAIL_SENDER = 'contacts/email/sender_email_identity';
00039 const XML_PATH_EMAIL_TEMPLATE = 'contacts/email/email_template';
00040 const XML_PATH_ENABLED = 'contacts/contacts/enabled';
00041
00042 public function preDispatch()
00043 {
00044 parent::preDispatch();
00045
00046 if( !Mage::getStoreConfigFlag(self::XML_PATH_ENABLED) ) {
00047 $this->norouteAction();
00048 }
00049 }
00050
00051 public function indexAction()
00052 {
00053 $this->loadLayout();
00054 $this->getLayout()->getBlock('contactForm')
00055 ->setFormAction( Mage::getUrl('*/*/post') );
00056
00057 $this->_initLayoutMessages('customer/session');
00058 $this->_initLayoutMessages('catalog/session');
00059 $this->renderLayout();
00060 }
00061
00062 public function postAction()
00063 {
00064 $post = $this->getRequest()->getPost();
00065 if ( $post ) {
00066 $translate = Mage::getSingleton('core/translate');
00067
00068 $translate->setTranslateInline(false);
00069 try {
00070 $postObject = new Varien_Object();
00071 $postObject->setData($post);
00072
00073 $error = false;
00074
00075 if (!Zend_Validate::is(trim($post['name']) , 'NotEmpty')) {
00076 $error = true;
00077 }
00078
00079 if (!Zend_Validate::is(trim($post['comment']) , 'NotEmpty')) {
00080 $error = true;
00081 }
00082
00083 if (!Zend_Validate::is(trim($post['email']), 'EmailAddress')) {
00084 $error = true;
00085 }
00086 if ($error) {
00087 throw new Exception();
00088 }
00089 $mailTemplate = Mage::getModel('core/email_template');
00090
00091 $mailTemplate->setDesignConfig(array('area' => 'frontend'))
00092 ->setReplyTo($post['email'])
00093 ->sendTransactional(
00094 Mage::getStoreConfig(self::XML_PATH_EMAIL_TEMPLATE),
00095 Mage::getStoreConfig(self::XML_PATH_EMAIL_SENDER),
00096 Mage::getStoreConfig(self::XML_PATH_EMAIL_RECIPIENT),
00097 null,
00098 array('data' => $postObject)
00099 );
00100
00101 if (!$mailTemplate->getSentSuccess()) {
00102 throw new Exception();
00103 }
00104
00105 $translate->setTranslateInline(true);
00106
00107 Mage::getSingleton('customer/session')->addSuccess(Mage::helper('contacts')->__('Your inquiry was submitted and will be responded to as soon as possible. Thank you for contacting us.'));
00108 $this->_redirect('*/*/');
00109
00110 return;
00111 } catch (Exception $e) {
00112 $translate->setTranslateInline(true);
00113
00114 Mage::getSingleton('customer/session')->addError(Mage::helper('contacts')->__('Unable to submit your request. Please, try again later'));
00115 $this->_redirect('*/*/');
00116 return;
00117 }
00118
00119 } else {
00120 $this->_redirect('*/*/');
00121 }
00122 }
00123
00124 }