Ejemplo n.º 1
0
function SqlResultScalar($con, $sql)
{
    $array = SqlResultArray($con, $sql);
    foreach ($array[0] as $scalar) {
        return $scalar;
    }
}
Ejemplo n.º 2
0
function MailChimpUpdateListFromDB($con, $listid)
{
    $list = SqlResultArray($con, "select listname from ctcweb9_ctc.mailchimp_lists where listid='{$listid}'");
    $listname = $list[0]["listname"];
    //$list = MailChimpSqlResultToArray($con,"select listname from ctcweb9_ctc.mailchimp_lists where listid='$listid'");
    //$listname = $list[0]["listname"];
    // Get the current state from the table
    $sql = "SELECT UCASE(primaryEmail) as K, primaryEmail as EMAIL,trim(firstName) as FNAME,trim(lastName) as LNAME, memberid, 'create' as Action\n            from ctcweb9_ctc.members m\n            join ctcweb9_ctc.mailchimp_subscriptions ms on ms.memberid = m.id\n            where listid='{$listid}' and primaryEmail != '' and not (primaryEmail is null)\n            order by primaryEmail";
    $list = SqlResultArray($con, $sql, "K");
    $changed = array();
    $changed[] = "listname={$listname} listid={$listid} sql returned " . count($list) . " items";
    // Get the current state from MailChimp
    for ($start = 0;; $start++) {
        $data = MailChimpRequest("lists/members", array("id" => $listid, "opts" => array("start" => $start, "limit" => 50)));
        $changed[] = "lists/members listname={$listname} listid={$listid} start={$start} returned " . count($data["data"]) . " items";
        if (count($data["data"]) == 0) {
            break;
        }
        foreach ($data["data"] as $member) {
            $email = $member["merges"]["EMAIL"];
            $fname = $member["merges"]["FNAME"];
            $lname = $member["merges"]["LNAME"];
            $key = strtoupper($email);
            if (!array_key_exists($key, $list)) {
                $list[$key] = $member["merges"];
                $list[$key]["Action"] = "delete";
            } else {
                if ($list[$key]["FNAME"] == $fname && $list[$key]["LNAME"] == $lname) {
                    $list[$key]["Action"] = "ignore";
                } else {
                    $list[$key]["Action"] = "update";
                    $list[$key]["old"] = "{$fname} {$lname}";
                }
            }
        }
    }
    $actions = array();
    // Generate subscribe or unsubscribe actions as necessary
    foreach ($list as $item) {
        $email = $item["EMAIL"];
        $fname = $item["FNAME"];
        $lname = $item["LNAME"];
        $changed[] = json_encode($item);
        if ($item["Action"] == 'delete' || $item["Action"] == 'update') {
            $changed[] = "remove {$email} from {$listname}";
            $actions[] = array("method" => "lists/unsubscribe", "args" => array("id" => $listid, "email" => array("email" => $email), "delete_member" => true, "send_goodbye" => false, "send_notify" => false));
        }
        if ($item["Action"] == 'create' || $item["Action"] == 'update') {
            $changed[] = "add {$email} to {$listname}";
            $actions[] = array("method" => "lists/subscribe", "args" => array("id" => $listid, "email" => array("email" => $email), "merge_vars" => array("FNAME" => $fname, "LNAME" => $lname), "double_optin" => false, "update_existing" => true));
        }
    }
    // Send all the actions to Mailchimp
    foreach ($actions as $action) {
        MailChimpRequest($action["method"], $action["args"]);
    }
    return $changed;
}
Ejemplo n.º 3
0
<?php

define('_JEXEC', 1);
define('JPATH_BASE', dirname(__DIR__));
// Assume mailchimp at top level in website
require_once JPATH_BASE . '/includes/defines.php';
require_once JPATH_BASE . '/includes/framework.php';
require_once 'alastair.php';
require_once 'mailchimp.inc.php';
$app = JFactory::getApplication('site');
$user = JFactory::getUser();
$config = JFactory::getConfig();
$username = $user->username;
$userrow = SqlResultArray($con, "SELECT primaryEmail,firstName,lastName FROM ctcweb9_ctc.view_members where loginname = '{$username}' ");
if (count($userrow)) {
    $userid = $userobj->id;
    $email = $userrow[0]['primaryEmail'];
    $fname = $userrow[0]['firstName'];
    $lname = $userrow[0]['lastName'];
} else {
    $url = $config->get('live_site');
    echo "<script>window.location.replace('{$url}');</script>";
    die('not logged on');
}
Ejemplo n.º 4
0
 }
 $raw = "ctc-id: " . str_replace("-", "", MakeGuid()) . "\n" . file_get_contents("{$dir}/{$file}");
 $msg = new PlancakeEmailParser($raw);
 $msgid = preg_replace('/,.*$/', "", $file);
 $from = $msg->getHeader("From");
 $subject = $msg->getHeader("Subject");
 $ctcid = $msg->getHeader("ctc-id");
 $body = GetHtmlFromMessage($msg);
 $css = ModerationConfig::GetCss();
 $step2Url = $live_site . "/" . ModerationConfig::Step2Url;
 $step2ImageUrl = $live_site . "/" . ModerationConfig::Step2DirectUrl;
 $lists = SqlResultArray($con, "select listid, listname from ctcweb9_ctc.mailchimp_lists");
 $headers = "MIME-Version: 1.0\r\n" . "Content-type: text/html;charset=UTF-8\r\n" . "From: <" . ModerationConfig::SrcName . "@" . ModerationConfig::SrcDomain . ">\r\n";
 $sender = ModerationConfig::SrcName . "@" . ModerationConfig::SrcDomain;
 echo "\t<table>\n\t\t\t<tr><th>msgid</th><td>{$msgid}</td>\n\t\t\t<tr><th>ctcid</th><td>{$ctcid}</td>\n\t\t\t<tr><th>Body</th><td>{$body}</td>";
 $moderators = SqlResultArray($con, "\n\t\t\tselect memberid, primaryemail, firstname, lastname\n\t\t\tfrom ctcweb9_ctc.members m\n\t\t\tjoin ctcweb9_ctc.members_roles mr on mr.memberid = m.id \n\t\t\tjoin ctcweb9_ctc.roles r on r.id = mr.roleid and r.role = " . SqlVal(ModerationConfig::ModeratorRoleName) . "");
 foreach ($moderators as $moderator) {
     $modid = $moderator["memberid"];
     $modemail = $moderator["primaryemail"];
     $modname = "{$moderator['firstname']} {$moderator['lastname']}";
     $props = " width='" . $css[".action"]["width"] . "px' \n\t\t\t\t   height='" . $css[".action"]["height"] . "px' target='ctcwindow' ";
     $th = "th style='border:solid 1px gray;'";
     $td = "td style='border:solid 1px gray;'";
     $modbody = "\t<p>" . ModerationConfig::Step1Preamble . "</p>\n\t\t\t\t\t<table style='border-collapse:collapse'>\n\t\t\t\t\t<tr><{$th}>Original Sender</th><{$td}>" . htmlentities($from) . "</td></tr>\n\t\t\t\t\t<tr><{$th}>Original Subject</th><{$td}>" . htmlentities($subject) . "</td></tr>\n\t\t\t\t\t<tr><{$th}>Original Body</th><{$td}>{$body}</td></tr>\n\t\t\t\t\t<tr><{$th}>Options</th><{$td}>";
     foreach ($lists as $list) {
         $args = array("action" => "sending", "msgid" => $msgid, "ctcid" => $ctcid, "modid" => $modid, "listid" => $list["listid"]);
         $title = "Click to send to the " . $list["listname"] . " list";
         $modbody .= "<a href='{$step2Url}?" . http_build_query($args) . "'>\n\t\t\t\t                  <img src='{$step2ImageUrl}?img=1&" . http_build_query($args) . "' {$props} title='" . htmlentities($title) . "'/></a><br/>";
     }
     $args = array("action" => "edit", "msgid" => $msgid, "ctcid" => $ctcid, "modid" => $modid);
     $title = "Click to edit before sending";
Ejemplo n.º 5
0
    $actionSizeY = $css[".action"]["height"];
    $actionGap = $css[".actiongap"]["height"];
    $icon = @imagecreatefrompng("{$action}.png") or die("cannot create png image - {$action}.png");
    $image = @imagecreatetruecolor($actionSizeX, $actionSizeY) or die("cannot create image");
    $colorfg = $css[".{$action}"]["color"];
    $colorbg = $css[".{$action}"]["background"];
    $fillX = $actionSizeX;
    $fillY = $actionSizeY - $actionGap;
    imagefilledrectangle($image, 0, 0, $actionSizeX, $actionSizeY, GetColor($image, "white"));
    imagefilledrectangle($image, 0, 0, $fillX - 1, $fillY - 1, GetColor($image, $colorbg));
    for ($x1 = 0, $y1 = 0, $x2 = $fillX - 1, $y2 = $fillY - 1; $x1 < $actionGap; $x1++, $y1++, $x2--, $y2--) {
        imagefilledrectangle($image, $x1, $y2, $x2, $y2, GetColor($image, $colorbg, "black"));
        imagefilledrectangle($image, $x2, $y1, $x2, $y2, GetColor($image, $colorbg, "black"));
        imagefilledrectangle($image, $x1, $y1, $x2, $y1, GetColor($image, $colorbg, "white"));
        imagefilledrectangle($image, $x1, $y1, $x1, $y2, GetColor($image, $colorbg, "white"));
    }
    imagettftext($image, $fillY * 0.6, 0, $fillY + $actionBorder, $fillY * 0.8, GetColor($image, $colorfg), "arial.ttf", $captionimg);
    imagecopyresized($image, $icon, $actionBorder, $actionBorder, 0, 0, imagesx($icon), imagesy($icon), imagesx($icon), imagesy($icon));
    header("Content-type: image/png");
    imagepng($image);
    imagedestroy($image);
    imagedestroy($icon);
} else {
    $config = JFactory::getConfig();
    $step2Url = $config->get('live_site') . "/" . ModerationConfig::Step2DirectUrl;
    $moderationconfig = new ReflectionClass("ModerationConfig");
    $data = array("action" => $action, "ctcid" => $ctcid, "msgid" => $msgid, "modid" => $modid, "ctcaction" => $ctcaction, "subject" => $subject, "body" => $body, "list" => $list, "lists" => $action == "edit" ? SqlResultArray($con, "select listid, listname from ctcweb9_ctc.mailchimp_lists") : null, "listid" => $listid, "listname" => $listname, "captionweb" => $captionweb, "formaction" => $step2Url, "livesite" => $config->get('live_site'), "editedhtml" => @file_get_contents("{$moderated}/cur/{$msgid}.edited.html"), "config" => $moderationconfig->getConstants(), "raw" => $raw);
    echo str_replace('$data', json_encode($data), file_get_contents("moderationStep2.html"));
}
?>