CommunityID/modules/default/controllers/FeedbackController.php

112 lines
3.3 KiB
PHP
Raw Normal View History

2019-07-17 20:08:50 +00:00
<?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
*/
2019-07-17 20:16:19 +00:00
class FeedbackController extends CommunityID_Controller_Action
2019-07-17 20:08:50 +00:00
{
protected $_numCols = 1;
public function init()
{
parent::init();
2019-07-17 20:16:19 +00:00
if ($this->user->role != Users_Model_User::ROLE_ADMIN && $this->underMaintenance) {
2019-07-17 20:08:50 +00:00
return $this->_redirectForMaintenance();
}
}
public function indexAction()
{
$appSession = Zend_Registry::get('appSession');
if (isset($appSession->feedbackForm)) {
$form = $appSession->feedbackForm;
unset($appSession->feedbackForm);
} else {
2019-07-17 20:16:19 +00:00
$form = new Form_Feedback(null, $this->view->base);
2019-07-17 20:08:50 +00:00
}
$this->view->form = $form;
}
public function sendAction()
{
2019-07-17 20:16:19 +00:00
$form = new Form_Feedback(null, $this->view->base);
2019-07-17 20:08:50 +00:00
$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();
2019-07-17 20:19:00 +00:00
$this->_helper->FlashMessenger->addMessage($this->view->translate('Thank you for your interest. Your message has been routed.'));
2019-07-17 20:08:50 +00:00
} catch (Zend_Mail_Protocol_Exception $e) {
2019-07-17 20:19:00 +00:00
$this->_helper->FlashMessenger->addMessage($this->view->translate('Sorry, the feedback couldn\'t be delivered. Please try again later.'));
2019-07-17 20:08:50 +00:00
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());
}
2019-07-17 20:19:00 +00:00
$mail = new Zend_Mail('UTF-8');
2019-07-17 20:08:50 +00:00
$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
);
2019-07-17 20:16:19 +00:00
$mail->setFrom($configEmail->supportemail);
2019-07-17 20:08:50 +00:00
$mail->addTo($configEmail->supportemail);
$mail->setSubject('Community-ID feedback form');
return $mail;
}
}