Example #1
0
 function update()
 {
     $this->load->helper('html2text');
     $id = $this->input->post('id');
     $subject = $this->input->post('subject');
     $htmlbody = $this->input->post('htmlbody');
     $textbody = html_to_plaintext($htmlbody);
     $attachments = $this->input->post('attachment');
     $db = new DbConn();
     if (!$id) {
         // New template
         $db->exec('insert into mail_templates () values ()');
         $id = $db->last_insert_id();
     }
     $rows = $db->exec('insert into mail_template_versions (templateid, subject, html, plaintext, datecreated, creator)
                    values (?, ?, ?, ?, ?, ?)', (int) $id, $subject, $htmlbody, $textbody, date_create(), $this->admin->id());
     if ($rows != 1) {
         throw new RuntimeException("Insertion failed!");
     }
     $newId = $db->last_insert_id();
     // process attachments
     if ($attachments) {
         foreach ($attachments as $attachId) {
             $attachId = (int) $attachId;
             $db->exec('insert into templatevers_to_attachments (templateverid, attachmentid) values (?, ?)', $newId, $attachId);
         }
     }
     $template = get_mail_template($id);
     $role = $template ? $template->role : '(unknown)';
     log_event(LOG_MAIL_TEMPLATE_EDITED, NULL, $role);
     redirect("admin/emails/index/{$id}");
 }
Example #2
0
<?php

require_once 'common.inc';
$id = $_POST['id'];
$subject = $_POST['subject'];
$htmlbody = $_POST['htmlbody'];
$textbody = html_to_plaintext($htmlbody);
$db = new DbConn();
if (!$id) {
    # New template
    $db->exec('insert into mail_templates () values ()');
    $id = $db->last_insert_id();
}
$rows = $db->exec('insert into mail_template_versions (templateid, subject, html, plaintext) values (?, ?, ?, ?)', (int) $id, $subject, $htmlbody, $textbody);
if ($rows != 1) {
    throw new RuntimeException("Insertion failed!");
}
redirect("list.php?highlight={$id}");