Exemplo n.º 1
0
 /**
  * processAction
  * Update the record previously selected
  * @return unknown_type
  */
 public function processAction()
 {
     $controller = Zend_Controller_Front::getInstance()->getRequest()->getControllerName();
     $redirector = Zend_Controller_Action_HelperBroker::getStaticHelper('redirector');
     $form = $this->getForm("/admin/{$controller}/process");
     $request = $this->getRequest();
     // Create the buttons in the edit form
     $this->view->buttons = array(array("url" => "#", "label" => $this->translator->translate('Save'), "params" => array('css' => null, 'id' => 'submit')), array("url" => "/admin/{$controller}/list", "label" => $this->translator->translate('List'), "params" => array('css' => null, 'id' => 'submit')), array("url" => "/admin/{$controller}/new/", "label" => $this->translator->translate('New'), "params" => array('css' => null)));
     // Check if we have a POST request
     if (!$request->isPost()) {
         return $this->_helper->redirector('list', $controller, 'admin');
     }
     if ($form->isValid($request->getPost())) {
         // Get the id
         $id = intval($this->getRequest()->getParam('template_id'));
         // Get the values posted
         $params = $request->getPost();
         // Save all the data
         $id = EmailsTemplates::saveAll($id, $params, $this->session->langid);
         $redirector->gotoUrl("/admin/{$controller}/edit/id/{$id}");
     } else {
         $this->view->form = $form;
         $this->view->title = $this->translator->translate("E-Mail Template");
         $this->view->description = $this->translator->translate("Here you can edit the e-mail template");
         return $this->render('applicantform');
     }
 }
Exemplo n.º 2
0
 public static function getEmailTemplate($template, $language_id = null)
 {
     $fallbackLocale = "en_US";
     $subject = "";
     $locale = Shineisp_Registry::get('Zend_Locale')->toString();
     if (empty($language_id)) {
         $language_id = Languages::get_language_id($locale);
     } else {
         $locale = Languages::get_locale($language_id);
     }
     $EmailTemplate = EmailsTemplates::findByCode($template, null, false, $language_id);
     // Template missing from DB. Let's add it.
     if (!is_object($EmailTemplate) || !isset($EmailTemplate->EmailsTemplatesData) || !isset($EmailTemplate->EmailsTemplatesData->{0}) || !isset($EmailTemplate->EmailsTemplatesData->{0}->subject)) {
         $filename = PUBLIC_PATH . "/languages/emails/" . $locale . "/" . $template . ".htm";
         // Check if the file exists
         if (!file_exists($filename)) {
             $filename = PUBLIC_PATH . "/languages/emails/" . $fallbackLocale . "/" . $template . ".htm";
             Shineisp_Commons_Utilities::log("This email template has not been found: {$filename}");
             $language_id = 1;
             // set the right default language id
             // Also the fallback template is missing. Something strange is going on.....
             if (!file_exists($filename)) {
                 Shineisp_Commons_Utilities::log("The default email template has not been found: {$filename}");
                 return array('template' => "Template: " . $template . " not found", 'subject' => $template);
             }
         }
         // Get the content of the file
         $body = '';
         foreach (file($filename) as $line) {
             // Get the subject written in the template file
             if (preg_match('/<!--@subject\\s*(.*?)\\s*@-->/', $line, $matches)) {
                 $subject = $matches[1];
                 // Get the subject
                 $subject = trim($subject);
                 continue;
             }
             // Delete all the comments
             $body .= preg_replace('#\\{\\*.*\\*\\}#suU', '', $line);
         }
         $isp = Isp::getActiveISP();
         $body = trim($body);
         $subject = trim($subject);
         // check if the string contains html tags and if it does not contain tags
         // means that it is a simple text. In this case add the tag "<br/>" for each return carrier
         if (!self::isHtml($body)) {
             $body = nl2br($body);
         }
         // Store mail in DB
         $array = array('type' => 'general', 'name' => $template, 'code' => $template, 'plaintext' => 0, 'active' => 1, 'fromname' => is_array($isp) && isset($isp['company']) ? $isp['company'] : 'ShineISP', 'fromemail' => is_array($isp) && isset($isp['email']) ? $isp['email'] : '*****@*****.**', 'subject' => $subject, 'html' => $body);
         // Save the data
         EmailsTemplates::saveAll(null, $array, $language_id);
         // Return the email template
         return array_merge($array, array('template' => $body, 'subject' => $subject));
     }
     // template is numeric but there is not template in db. something strange happened. Exit.
     if (is_numeric($template) && !is_object($EmailTemplate)) {
         return false;
     }
     $email = array('subject' => $EmailTemplate->EmailsTemplatesData->{0}->subject, 'plaintext' => intval($EmailTemplate->plaintext), 'fromname' => $EmailTemplate->EmailsTemplatesData->{0}->fromname, 'fromemail' => $EmailTemplate->EmailsTemplatesData->{0}->fromemail, 'cc' => $EmailTemplate->cc, 'bcc' => $EmailTemplate->bcc, 'template' => '');
     if (!empty($EmailTemplate->EmailsTemplatesData->{0}->html) && !empty($EmailTemplate->EmailsTemplatesData->{0}->text)) {
         // Both version are present
         $body = intval($EmailTemplate->plaintext) ? $EmailTemplate->EmailsTemplatesData->{0}->text : $EmailTemplate->EmailsTemplatesData->{0}->html;
     } else {
         if (empty($EmailTemplate->EmailsTemplatesData->{0}->html) && !empty($EmailTemplate->EmailsTemplatesData->{0}->text)) {
             // Only TEXT version
             $body = $EmailTemplate->EmailsTemplatesData->{0}->text;
         } else {
             // Only HTML version
             $body = $EmailTemplate->EmailsTemplatesData->{0}->html;
         }
     }
     $email['template'] = $body;
     return $email;
 }