* @copyright 2005 by http://wombat.exit0.net * @package wombatModule * @subpackage Contact */ /** * Display standard contact form and mail results. * * @version 1.0.0 * @package wombatModule * @subpackage Contact */ class wbModule_Contact extends wbModule { /** * Module parameter * * - tmpldir: template folder * - subject: email subject * - contact: which details from contact.xml should be used? * - from: senders email address - if null, address of contact will be used - don't do that * * @access private * @var array $_params */ var $_params = array( 'tmpldir' => 'module/Contact', 'subject' => 'Wombat Site Contact Request', 'contact' => 'info', 'from' => null ); /** * some request defaults * * @access private * @var array $_params */ var $_requestDefaults = array( 'action' => '_no_action_set', ); /** * recieve content * * @access public * @return string $html */ function getHtml() { $this->_tmpl =& wbFactory::singleton( 'patTemplate' ); $params = array( 'template_dir' => $this->_params['tmpldir'] ); $form =& wbFactory::singleton( 'patForms', $params ); if( $this->_request['action'] == 'save' ) { $form->setSubmitted( true ); // is form valid if( $form->validateForm() ) { $data = $form->getValues(); if( !$this->_checkReload() ) { $this->_processEnquiry( $data ); } $this->_loadTemplates( 'success' ); $this->_tmpl->addVars( 'wbModule_Contact', $data, 'DATA_' ); return $this->_tmpl->getParsedTemplate( 'wbModule_Contact' ); } } wbDebugger::addMsg( 'Module:Contact', wbDebugger::sprint_r( $this->_params ), 'Params' ); $form->renderForm( array( 'template' => 'wbModule_Contact', 'errorTemplateContainer' => 'formErrors', 'errorTemplate' => 'formErrors_entry' ) ); return $this->_tmpl->getParsedTemplate( 'wbModule_Contact' ); } /** * do something with recieved data * * * @access public * @param array $data form data * @return boolean $resutl true on success */ function _processEnquiry( $data ) { $conf =& wbFactory::singleton( 'patConfiguration' ); $conf->loadConfig( 'contact.xml' ); $contact = $conf->getConfigValue(); if( !empty( $contact[$this->_params['contact']] ) ) { $contact = $contact[$this->_params['contact']]; } else { $contact = $contact['default']; } $timestamp = $from = $this->_params['from']; if( !$from ) { $from = $contact['from']; } // header $emailHdr = array( 'From' => $from, 'Reply-To' => '"' . $data['name'] . '" <'. $data['email'] .'>', 'To' => $contact['from'], 'Subject' => $this->_params['subject'], 'X-Mailer' => 'Wombat System', 'X-Wombat-Processor' => 'wbModule_Contact', 'X-Wombat-Timestamp' => gmdate( 'Y-m-d H:i:s' ) ); // Body $this->_loadTemplates( 'email' ); $data['timestamp'] = date( 'Y-m-d H:i:s' ); $this->_tmpl->addVars( 'wbModule_Contact_email', $contact, 'CONTACT_' ); $this->_tmpl->addVars( 'wbModule_Contact_email', $data, 'DATA_' ); $emailBody = $this->_tmpl->getParsedTemplate( 'wbModule_Contact_email' ); // run mailer $mailer =& wbFactory::singleton( 'Mail' ); if( wbDebugger::isActive() ) { wbDebugger::addMsg( 'Module:Contact', wbDebugger::sprint( $emailBody ), 'Body' ); return true; } $result = $mailer->send( $contact['email'], $emailHdr, $emailBody ); if( PEAR::isError( $result ) ) { return false; } return true; } } ?>