/**
  * Show / process email template form
  *
  * @param void
  * @return null
  */
 function edit()
 {
     if ($this->active_template->isNew()) {
         $this->httpError(HTTP_ERR_NOT_FOUND);
     }
     // if
     $locale = $this->request->get('locale', null);
     $template_data = $this->request->post('template');
     if (!is_array($template_data)) {
         $template_data = array('subject' => $this->active_template->getSubject($locale), 'body' => $this->active_template->getBody($locale));
     }
     // if
     $template_variables = $this->active_template->getVariables() ? explode("\n", $this->active_template->getVariables()) : null;
     $this->smarty->assign(array('template_data' => $template_data, 'template_variables' => $template_variables, 'locale' => $locale));
     if ($this->request->isSubmitted()) {
         if ($locale) {
             $this->active_template->writeLocaleProperties(array_var($template_data, 'subject'), array_var($template_data, 'body'), $locale);
         } else {
             $this->active_template->setAttributes($template_data);
         }
         // if
         $save = $this->active_template->save();
         if ($save && !is_error($save)) {
             flash_success('Email template has been updated');
             $this->redirectToUrl($this->active_template->getUrl());
         } else {
             $this->smarty->assign('errors', $save);
         }
         // if
     }
     // if
 }
예제 #2
0
 /**
  * Create new email template for this module
  *
  * @param string $name
  * @param string $subject
  * @param string $body
  * @param array $variables
  * @return boolean
  */
 function addEmailTemplate($name, $subject, $body, $variables = null)
 {
     $email_template = new EmailTemplate();
     $email_template->setAttributes(array('name' => $name, 'module' => $this->name, 'subject' => $subject, 'body' => $body, 'variables' => is_array($variables) ? implode("\n", $variables) : $variables));
     return $email_template->save();
 }