function _wpr_edit_mailout()
{
    global $wpdb;
    $id = $_GET['id'];
    $query = "select * from " . $wpdb->prefix . "wpr_newsletter_mailouts where id={$id} and status=0";
    $mailouts = $wpdb->get_results($query);
    if (count($mailouts) == 0) {
        ?>
        This newsletter has been sent. It cannot be edited.<br />
<br />

        <a href="admin.php?page=allbroadcasts" class="button">&laquo; Back </a>
        <?php 
        return;
    }
    $param = $mailouts[0];
    $param->htmlenabled = empty($param->htmlbody) ? 0 : 1;
    if (isset($_POST['subject'])) {
        $subject = $_POST['subject'];
        $nid = $_POST['newsletter'];
        $textbody = trim($_POST['body']);
        $htmlbody = trim($_POST['htmlbody']);
        $whentosend = $_POST['whentosend'];
        $date = $_POST['date'];
        $htmlenabled = isset($_POST['htmlenabled']) && $_POST['htmlenabled'] == "on";
        $hour = $_POST['hour'];
        $min = $_POST['minute'];
        $id = $_POST['mid'];
        if ($whentosend == "now") {
            $timeToSend = time();
        } else {
            $timeToSend = $_POST['actualTime'];
        }
        if (!(trim($subject) && trim($textbody))) {
            $error = "Subject and the Text Body are mandatory.";
        }
        if ($timeToSend < time() && !$error) {
            $error = "The time mentioned is in the past. Please enter a time in the future.";
        }
        if ($htmlenabled && !$error) {
            if (empty($htmlbody)) {
                $error = "HTML Body is empty. Enter the HTML body of this email";
            }
        }
        //if html body is present, it will be sent.
        if (!$htmlenabled) {
            $htmlbody = "";
        }
        $htmlenabled = $htmlenabled ? 1 : 0;
        if (!$error) {
            $query = "UPDATE " . $wpdb->prefix . "wpr_newsletter_mailouts set subject='{$subject}', textbody='{$textbody}', htmlbody='{$htmlbody}',time='{$timeToSend}', nid='{$nid}' where id={$id};";
            $wpdb->query($query);
            _wpr_mail_sending();
            return;
        }
        $param = (object) array("nid" => $nid, "textbody" => $textbody, "subject" => $subject, "htmlbody" => $htmlbody, "htmlenabled" => !empty($htmlbody), "whentosend" => $whentosend, "time" => $timeToSend, "title" => "New Mail", "buttontext" => "Save Broadcast");
    }
    wpr_mail_form($param, "new", $error);
}
Exemple #2
0
function wpr_newmail()
{
    global $wpdb;
    if (isset($_POST['subject'])) {
        date_default_timezone_set("UTC");
        $subject = $_POST['subject'];
        $nid = $_POST['newsletter'];
        $textbody = trim($_POST['body']);
        $htmlbody = trim($_POST['htmlbody']);
        $whentosend = $_POST['whentosend'];
        $date = $_POST['date'];
        $htmlenabled = $_POST['htmlenabled'] == "on";
        $hour = $_POST['hour'];
        $timezoneOffset = $_POST['timezoneoffset'];
        $min = $_POST['minute'];
        if ($whentosend == "now") {
            $timeToSend = time();
        } else {
            if (empty($date)) {
                $error = "The date field is required";
            } else {
                $sections = explode("/", $date);
                $timeToSend = mktime($hour, $min, 0, $sections[0], $sections[1], $sections[2]);
                $timeToSend = $timeToSend - $timezoneOffset;
            }
        }
        if (!(trim($subject) && trim($textbody))) {
            $error = "Subject and the Text Body are mandatory.";
        }
        if ($timeToSend < time() && !$error) {
            $error = "The time mentioned is in the past. Please enter a time in the future.";
            if ($htmlenabled && !$error) {
                if (empty($htmlbody)) {
                    $error = "HTML Body is empty. Enter the HTML body of this email";
                }
            }
        }
        if (!$htmlenabled) {
            $htmlbody = "";
        }
        if (!$error) {
            $query = "insert into " . $wpdb->prefix . "wpr_newsletter_mailouts (nid,subject,textbody,htmlbody,time,status) values ('{$nid}','{$subject}','{$textbody}','{$htmlbody}','{$timeToSend}',0);";
            $wpdb->query($query);
            _wpr_mail_sending();
            return;
        }
    }
    $param = (object) array("nid" => $nid, "textbody" => $textbody, "subject" => $subject, "htmlbody" => $htmlbody, "htmlenabled" => 1, "whentosend" => $whentosend, "date" => $date, "hour" => $hour, "minute" => $min, "title" => "New Mail");
    //There are no newsletters. Ask to create one before sending mailouts
    if (Newsletter::whetherNoNewslettersExist()) {
        ?>
        <h2>No Newsletters Found</h2>
            You need to create a newsletter before you can send a broadcast.
    <?php 
        return;
    }
    wpr_mail_form($param, "new", $error);
}