示例#1
0
function parseMailTemplateFormular($ui, $session, &$template = null)
{
    $label = stripslashes($_POST["label"]);
    $body = stripslashes($_POST["body"]);
    if ($template == null) {
        $gliederung = $session->getStorage()->getGliederung($session->getVariable("gliederungid"));
        if (!$session->isAllowed("mailtemplates_create", $gliederung->getGliederungID())) {
            $ui->viewLogin();
            exit;
        }
        $template = new MailTemplate($session->getStorage());
        $template->setGliederung($gliederung);
    } else {
        $gliederung = $template->getGliederung();
        if (!$session->isAllowed("mailtemplates_modify", $gliederung->getGliederungID())) {
            $ui->viewLogin();
            exit;
        }
    }
    $template->setLabel($label);
    $template->setBody($body);
    // Headerfelder
    $headerfields = $session->getListVariable("headerfields");
    $headervalues = $session->getListVariable("headervalues");
    $headerfieldsindex = array_map('strtolower', $headerfields);
    foreach ($template->getHeaders() as $field => $header) {
        if (empty($field) || !in_array(strtolower($field), $headerfieldsindex)) {
            $template->delHeader($field);
        }
    }
    $headers = array_combine($headerfields, $headervalues);
    foreach ($headers as $field => $value) {
        if (!empty($field)) {
            $template->setHeader($field, $value);
        }
    }
    $template->save();
}
示例#2
0
 protected function getMailTemplate($session)
 {
     if ($this->mailtemplate != null) {
         return $this->mailtemplate;
     }
     if ($session->hasVariable("mailtemplatecode")) {
         $mailtemplate = unserialize(base64_decode($session->getVariable("mailtemplatecode")));
         $mailtemplate->setStorage($session->getStorage());
         return $mailtemplate;
     }
     if ($session->hasVariable("body")) {
         $mailtemplate = new MailTemplate($session->getStorage());
         $headers = array_combine($session->getListVariable("headerfields"), $session->getListVariable("headervalues"));
         foreach ($headers as $field => $value) {
             if (!empty($field)) {
                 $mailtemplate->setHeader($field, $value);
             }
         }
         $mailtemplate->setBody($session->getVariable("body"));
         return $mailtemplate;
     }
     return null;
 }