diff --git a/Config/bootstrap.php b/Config/bootstrap.php index d9cc612eb..5bb37c100 100644 --- a/Config/bootstrap.php +++ b/Config/bootstrap.php @@ -38,6 +38,7 @@ App::uses('ModelBehavior', 'Model'); App::uses('AppController', 'Controller'); App::uses('AppHelper', 'View/Helper'); + App::uses('InfinitasEmail', 'Core/Emails/Network/Email'); App::uses('ClearCache', 'Data.Lib'); App::uses('EventCore', 'Events.Lib'); diff --git a/Config/email.php b/Config/email.php new file mode 100644 index 000000000..248fd1679 --- /dev/null +++ b/Config/email.php @@ -0,0 +1,53 @@ + The name of a supported transport; valid options are as follows: + * Mail - Send using PHP mail function + * Smtp - Send using SMTP + * Debug - Do not send the email, just return the result + * + * You can add custom transports (or override existing transports) by adding the + * appropriate file to app/Network/Email. Transports should be named 'YourTransport.php', + * where 'Your' is the name of the transport. + * + * from => + * The origin email. See CakeEmail::from() about the valid values + * + */ +class EmailConfig { + + public $gmail = array( + 'host' => 'ssl://smtp.gmail.com', + 'port' => 465, + 'username' => 'infinitastest@gmail.com', + 'password' => 'testtesttest', + 'transport' => 'Smtp' + ); + +} diff --git a/Core/Emails/Network/Email/InfinitasEmail.php b/Core/Emails/Network/Email/InfinitasEmail.php new file mode 100644 index 000000000..169389269 --- /dev/null +++ b/Core/Emails/Network/Email/InfinitasEmail.php @@ -0,0 +1,5 @@ +Controller->{$this->Controller->modelClass}->alias . '.' . $this->Controller->{$this->Controller->modelClass}->primaryKey] = $id; $this->Controller->request->data = $this->Controller->{$this->Controller->modelClass}->find('first', $query); + if(empty($this->Controller->request->data)) { $this->Controller->notice('invalid'); } diff --git a/Core/Libs/Controller/Component/MassActionComponent.php b/Core/Libs/Controller/Component/MassActionComponent.php index 88be10179..3d3d7f7cb 100644 --- a/Core/Libs/Controller/Component/MassActionComponent.php +++ b/Core/Libs/Controller/Component/MassActionComponent.php @@ -256,8 +256,9 @@ public function __handleDeletes($ids) { * they will be inactive and inactive records will be active. * * @param array $ids array of ids. + * @param string $message optional string you want the notice to display */ - public function toggle($ids) { + public function toggle($ids, $message = null) { if(!$this->Controller->{$this->Controller->modelClass}->hasField('active')) { throw new Exception(sprintf('The model "%s" does not have an active field', $this->Controller->modelClass)); } @@ -286,6 +287,16 @@ public function toggle($ids) { if ($this->Controller->{$this->Controller->modelClass}->updateAll($newValues, $conditions)) { $this->Controller->{$this->Controller->modelClass}->afterSave(false); + + if (!empty($message)) { + $this->Controller->notice( + $message, + array( + 'redirect' => true + ) + ); + } + $this->Controller->notice( sprintf(__('The %s were toggled'), $this->Controller->prettyModelName), array( @@ -547,7 +558,8 @@ public function generic($action = 'add', $ids = null) { if (!empty($ids)) { $url = array_merge($url, $ids); } - - $this->Controller->redirect(array_merge($url, $this->Controller->request->params['named'], (array)$this->request->params['pass'])); + + $this->Controller->redirect(array_merge($url, $this->Controller->request->params['named'], (array)$this->Controller->request->params['pass'])); } -} \ No newline at end of file + +} diff --git a/Core/Newsletter/Controller/NewslettersController.php b/Core/Newsletter/Controller/NewslettersController.php index 4db0d470e..4a139972a 100644 --- a/Core/Newsletter/Controller/NewslettersController.php +++ b/Core/Newsletter/Controller/NewslettersController.php @@ -244,6 +244,22 @@ public function admin_index() { } public function admin_add() { + if ($this->request->isPost()) { + $campaignId = $this->request->data['Newsletter']['campaign_id']; + + $campaign = $this->Newsletter->Campaign->find('first', array( + 'fields' => array( + 'template_id' + ), + 'conditions' => array( + 'Campaign.id' => $campaignId + ) + ) + ); + + $this->request->data['Newsletter']['template_id'] = $campaign['Campaign']['template_id']; + } + parent::admin_add(); $campaigns = $this->Newsletter->Campaign->find('list'); @@ -268,6 +284,8 @@ public function admin_view($id = null) { } $newsletter = $this->Newsletter->read(null, $id); + $templateId = $newsletter['Newsletter']['template_id']; + $template = $this->Newsletter->Template->read(null, $templateId); if (!empty($this->request->data)) { $id = $this->request->data['Newsletter']['id']; @@ -282,24 +300,20 @@ public function admin_view($id = null) { ) ); } - + $sent = 0; foreach($addresses as $address) { - $this->Email->from = 'Infinitas Test Mail <' . $newsletter['Newsletter']['from'] . '>'; - $this->Email->to = 'Test <' . $address . '>'; + $email = new InfinitasEmail('gmail'); + $email->from(array($newsletter['Newsletter']['from'] => 'Infinitas')); + $email->to($address); - $this->Email->subject = strip_tags($newsletter['Newsletter']['subject']); - $this->set('email', $newsletter['Template']['header'] . $newsletter['Newsletter']['html'] . $newsletter['Template']['footer']); + $email->subject(strip_tags($newsletter['Newsletter']['subject'])); - if ($this->Email->send()) { + if ($email->send($template['Template']['header'] . $newsletter['Newsletter']['html'] . $template['Template']['footer'])) { $sent++; } - - pr($this->Email->smtpError); - - $this->Email->reset(); - } - + } + $this->notice(sprintf(__('%s mails were sent'), $sent)); } @@ -310,6 +324,12 @@ public function admin_view($id = null) { $this->set('newsletter', $this->Newsletter->read(null, $id)); } + public function admin_edit($id = null) { + parent::admin_edit(); + + $this->set('campaigns', $this->Newsletter->Campaign->find('list')); + } + public function admin_preview($id = null) { $this->layout = 'ajax'; @@ -338,6 +358,7 @@ public function admin_preview($id = null) { ); $this->set('data', $newsletter['Template']['header'] . $newsletter['Newsletter']['html'] . $newsletter['Template']['footer']); + Configure::write('debug', 0); } } @@ -451,4 +472,38 @@ public function admin_stopAll() { ) ); } + + public function admin_mass() { + if ($this->MassAction->getAction() == 'send') { + $ids = $this->{$this->modelClass}->find( + 'list', + array( + 'conditions' => array( + $this->{$this->modelClass}->alias . '.active' => 0, + $this->{$this->modelClass}->alias . '.' . $this->{$this->modelClass}->primaryKey => $this->MassAction->getIds($this->MassAction->getAction(), $this->request->data[$this->modelClass]) + ) + ) + ); + + if(empty($ids)) { + $this->notice( + __d('newsletter', 'Nothing to send'), + array( + 'level' => 'warning', + 'redirect' => '' + ) + ); + } + + if (count($ids) == 1) { + $message = 'Newsletter is now sending'; + } else { + $message = 'The Newsletters are now sending'; + } + + $this->MassAction->toggle(array_keys($ids), $message); + } + + parent::admin_mass(); + } } \ No newline at end of file diff --git a/Core/Newsletter/View/Newsletters/admin_view.ctp b/Core/Newsletter/View/Newsletters/admin_view.ctp index 6509da610..b389e4be3 100755 --- a/Core/Newsletter/View/Newsletters/admin_view.ctp +++ b/Core/Newsletter/View/Newsletters/admin_view.ctp @@ -27,7 +27,7 @@

Form->create('Newsletter', array('action' => 'view')); - echo '

', __('Enter the email addresses you would like to send to seperated by a , {comma}.'), '

'; + echo '

', __('Enter the email addresses you would like to send to seperated by a , {comma} (but with no spaces)'), '

'; echo $this->Form->input('id', array('value' => $this->data['Newsletter']['id'])); echo $this->Form->input('email_addresses', array('type' => 'textarea', 'class' => 'title')); echo $this->Form->end('Send the test');