import v1.0.0-RC4 | 2009-05-20
This commit is contained in:
111
modules/default/controllers/FeedbackController.php
Normal file
111
modules/default/controllers/FeedbackController.php
Normal file
@ -0,0 +1,111 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* @copyright Copyright (C) 2005-2009 Keyboard Monkeys Ltd. http://www.kb-m.com
|
||||
* @license http://creativecommons.org/licenses/BSD/ BSD License
|
||||
* @author Keyboard Monkey Ltd
|
||||
* @since CommunityID 0.9
|
||||
* @package CommunityID
|
||||
* @packager Keyboard Monkeys
|
||||
*/
|
||||
|
||||
class FeedbackController extends Monkeys_Controller_Action
|
||||
{
|
||||
protected $_numCols = 1;
|
||||
|
||||
public function init()
|
||||
{
|
||||
parent::init();
|
||||
|
||||
if ($this->user->role != User::ROLE_ADMIN && $this->underMaintenance) {
|
||||
return $this->_redirectForMaintenance();
|
||||
}
|
||||
}
|
||||
|
||||
public function indexAction()
|
||||
{
|
||||
$appSession = Zend_Registry::get('appSession');
|
||||
if (isset($appSession->feedbackForm)) {
|
||||
$form = $appSession->feedbackForm;
|
||||
unset($appSession->feedbackForm);
|
||||
} else {
|
||||
$form = new FeedbackForm(null, $this->view->base);
|
||||
}
|
||||
$this->view->form = $form;
|
||||
}
|
||||
|
||||
public function sendAction()
|
||||
{
|
||||
$form = new FeedbackForm(null, $this->view->base);
|
||||
$formData = $this->_request->getPost();
|
||||
$form->populate($formData);
|
||||
|
||||
if (!$form->isValid($formData)) {
|
||||
$appSession = Zend_Registry::get('appSession');
|
||||
$appSession->feedbackForm = $form;
|
||||
return $this->_forward('index', null, null);
|
||||
}
|
||||
|
||||
$mail = self::getMail(
|
||||
$form->getValue('name'),
|
||||
$form->getValue('email'),
|
||||
$form->getValue('feedback')
|
||||
);
|
||||
|
||||
try {
|
||||
$mail->send();
|
||||
$this->_helper->FlashMessenger->addMessage('Thank you for your interest. Your message has been routed.');
|
||||
} catch (Zend_Mail_Protocol_Exception $e) {
|
||||
$this->_helper->FlashMessenger->addMessage('Sorry, the feedback couldn\'t be delivered. Please try again later.');
|
||||
if ($this->_config->logging->level == Zend_Log::DEBUG) {
|
||||
$this->_helper->FlashMessenger->addMessage($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
$this->_redirect('');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Zend_Mail
|
||||
* @throws Zend_Mail_Protocol_Exception
|
||||
*/
|
||||
public static function getMail($name, $email, $feedback)
|
||||
{
|
||||
// can't use $this-_config 'cause it's a static function
|
||||
$configEmail = Zend_Registry::get('config')->email;
|
||||
|
||||
switch (strtolower($configEmail->transport)) {
|
||||
case 'smtp':
|
||||
Zend_Mail::setDefaultTransport(
|
||||
new Zend_Mail_Transport_Smtp(
|
||||
$configEmail->host,
|
||||
$configEmail->toArray()
|
||||
)
|
||||
);
|
||||
break;
|
||||
case 'mock':
|
||||
Zend_Mail::setDefaultTransport(new Zend_Mail_Transport_Mock());
|
||||
break;
|
||||
default:
|
||||
Zend_Mail::setDefaultTransport(new Zend_Mail_Transport_Sendmail());
|
||||
}
|
||||
|
||||
$mail = new Zend_Mail();
|
||||
$mail->setBodyText(<<<EOD
|
||||
Dear Administrator,
|
||||
|
||||
The community-id feedback form has just been used to send you the following:
|
||||
|
||||
Name: $name
|
||||
E-mail: $email
|
||||
Feedback:
|
||||
$feedback
|
||||
EOD
|
||||
);
|
||||
$mail->setFrom('support@community-id.org');
|
||||
$mail->addTo($configEmail->supportemail);
|
||||
$mail->setSubject('Community-ID feedback form');
|
||||
|
||||
return $mail;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user