switch ($action) { case 'edit': $local_template = $templateModel->getRecord($_GET['id']); $pdf_external_id = $local_template['pdf_external_id']; $settings = new App\Model\Settings($db, 'pdf'); $settings = $settings->getAll(); $selectTemplateHtml = '<option value="">Empty</option>'; if(array_key_exists('pdf_sendwithus_key', $settings) && isset($settings['pdf_sendwithus_key'])){ $API_KEY = $settings['pdf_sendwithus_key']; $tags = explode(',', trim($settings['pdf_sendwithus_tags'])); $options = array(); $api = new API($API_KEY, $options); $response = $api->emails(); foreach($response as $template){ $matched = count(array_filter($tags)) == 0; foreach($tags as $tag){ if (isset($template->tags) && in_array(trim($tag), $template->tags)) { $matched = true; break; } } if($matched){ $selected = $pdf_external_id == $template->id ? "selected='selected'" : ""; $selectTemplateHtml .= "<option value='". $template->id ."'".$selected.">". $template->name ."</option>"; } } }
function addNewMailTemplate($mail_templates_id=0) { $db=new DBConnection(); if($mail_templates_id&&!$_POST['_form_submit']) { $_SESSION['admin']['uedit']=$mail_templates_id; $query='SELECT * FROM mail_templates WHERE mail_templates_id='.($mail_templates_id+0).''; $res=$db->rq($query); foreach ($db->fetch($res) AS $RowName=>$RowValue) { $_POST[$RowName]=$RowValue; } } $settingsModel = new App\Model\Settings($db, 'mail_settings'); $settings = $settingsModel->getAll(); $API_KEY = $settings['sendwithus_key']; $options = array(); $api = new API($API_KEY, $options); $response = $api->emails(); $tags = explode(',', trim($settings['sendwithus_tags'])); $selectTemplateHtml = '<option value="">Empty</option>'; foreach($response as $template) { $matched = count(array_filter($tags)) == 0; foreach($tags as $tag){ if (isset($template->tags) && in_array(trim($tag), $template->tags)) { $matched = true; break; } } if($matched){ $selectTemplateHtml .= "<option value='". $template->id ."' ".(isset($_POST['mail_external_id']) && $_POST['mail_external_id'] == "$template->id" ? "selected='selected'" : "") .">". $template->name ."</option>"; } } // End $db->close(); $templateVariables = Array( 'mail_template_title', 'user_first_name', 'user_username', 'user_last_name', 'user_account_num', 'user_password', 'user_password_org', 'trade_details', 'trade_date', 'trade_sell_status', 'trade_buy_status', 'trade_value', 'transfer_value', 'transfer_date', 'thanks', 'company_name', 'site_url', 'funding_overviews', 'trading_overviews', 'trade_ref', 'user_account_name', 'user_admin_ref', 'user_phone', 'user_email', 'user_mailing_address', 'user_city', 'user_state', 'user_postal', 'user_country', 'user_advisor1', 'user_advisor2', 'user_app_date' ); sort($templateVariables); $templateVariablesContent = ''; if(count($templateVariables) == 0){ $templateVariablesContent = '<p>Variables are not defined for this template type.</p>'; }else{ $templateVariablesContent .= '<ul class="variable_list">'; foreach($templateVariables as $var){ $templateVariablesContent .= "<li>{{$var}}</li>"; } $templateVariablesContent .= '</ul>'; } $pcontent=''; $pcontent.=' <div class="mainHolder"> <div class="hintHolder ui-state-default"><b>'.(($mail_templates_id>0)?'Editing':'Creating New').' Mail Template</b></div> <script type="text/javascript" src="../js/jquery.validate.js"></script> <script type="text/javascript" src="js/tiny_mce/tiny_mce.js"></script> <script type="text/javascript" src="js/jquery.simplemodal-1.3.3.min.js"></script> <link type="text/css" href="css/basic.css" rel="stylesheet" media="screen" /> <script type="text/javascript"> jQuery(function ($) { $(".basic").click(function (e) { var themeId = $("#MailTemplate").val(); var contentBody = tinyMCE.get("mail_html").getContent(); $.ajax({ type:"post", url: "ajax_theme.php", data: {action: "GetTemplateById" ,themeId : themeId, contentBody:contentBody }, success: function(data) { $(".mailTArea").html(data); tinyMCE.get("mail_html").setContent(data); } }) return false; }); }); $(document).ready(function(){ ShowTemplate(); }); $(document).ready(function(){ $("#MailTemplate").change(function(){ tinyMCE.get("mail_html").setContent("loading...", {format : "raw"}); $(".mailTArea").html("loading..."); ShowTemplate(); }); }); function ShowTemplate(){ var externalId = $("#MailTemplate").val(); $.ajax({ type:"post", url: "ajax_theme.php", dataType: "json", data: {action: "GetTemplateById" ,templateId : externalId }, success: function(data) { tinyMCE.get("mail_html").setContent(data.html, {format : "raw"}); $(".mailTArea").html(data.text); $("#template_name").val(data.name); $("#template_version").val(data.id); } }); } tinyMCE.init({ // General options mode : "textareas", theme : "advanced", editor_selector : "mceEditor", readonly : true, visual: false }); </script> <div id="basic-modal-content" style="display:none"> </div> <form name="addNewMailTemplate" method="POST" id="MainForms" action=""> <fieldset class="mainFormHolder left" style="width:800px;"> <legend>Template information</legend> <div class="formsLeft">Title:</div> <div class="formsRight"> <input class="text-input" type="text" name="mail_template_title" id="mail_template_title" value="'.$_POST['mail_template_title'].'" /> (used in admin area only) </div> <br /> <div class="formsLeft">Mail From:</div> <div class="formsRight"> <input class="text-input" type="text" name="mail_from_mail" id="mail_from_mail" value="'.$_POST['mail_from_mail'].'" /> (ex: noreply@site.com) </div> <br /> <div class="formsLeft">Mail BCC:</div> <div class="formsRight"> <input class="text-input" type="text" name="mail_bcc" id="mail_bcc" value="'.$_POST['mail_bcc'].'" /> (ex: noreply@site.com) </div> <br /> <div class="formsLeft">Mail From Name:</div> <div class="formsRight"> <input class="text-input" type="text" name="mail_from" id="mail_from" value="'.$_POST['mail_from'].'" /> (ex: John Doe) </div> <br /> <div class="formsLeft">Mail Subject:</div> <div class="formsRight"> <input class="text-input" type="text" name="mail_subject" id="mail_subject" value="'.$_POST['mail_subject'].'" /> </div> <br /> <div class="formsLeft">Auto Mail?:</div> <div class="formsRight"> <select name="mail_single" class="text-input"> <option value="1"'.(($_POST['mail_single']==1)?' selected':'').'>No</option> <option value="0"'.(($_POST['mail_single']==0)?' selected':'').'>Yes</option> </select> </div> <br /> <div class="formsLeft">Theme:</div> <div class="formsRight"> <select name="mail_external_id" id="MailTemplate" class="text-input">'.$selectTemplateHtml.'</select> </div> <br /> <div class="formsLeft">HTML Content:</div> <div class="formsRight"> <br /> <textarea name="mail_html" style="width:100%" class="mceEditor">Loading...</textarea> </div> <br /> <div class="formsLeft">Plain Text Content:</div> <div class="formsRight"> <br /> <textarea name="mail_plain" style="width:100%" class="mailTArea">Loading...</textarea> </div> <input type="hidden" id="template_name" name="template_name" value="" /> <input type="hidden" id="template_version" name="template_version" value="" /> <input type="hidden" name="_form_submit" value="1" /> <input type="submit" name="_submit" value="'.getLang('sform_savebtn').'" class="submitBtn ui-state-default" />'; if($mail_templates_id) { $pcontent.=' <input type="hidden" name="mtid" value="'.$mail_templates_id.'"> <input type="button" name="_delete" value="'.getLang('sform_delbtn').'" class="submitBtn ui-state-default" onclick="if(confirm(\'Are you sure you want to delete this mail template?\')) location=\'?action=delete&mtid='.($_POST['mail_templates_id']+0).'\';" />'; } $pcontent.=' <input type="button" name="_cancel" value="'.getLang('sform_backbtn').'" class="submitBtn ui-state-default" onclick="location=\'mails_templates.php\';" /> </fieldset> <fieldset class="mainFormHolder left" style="width: 300px;"> <legend>Variables</legend> '.$templateVariablesContent.' </fieldset> <br class="clear" /> </form> </div>'; return $pcontent; }
<?php // Copyright SQCRM. For licensing, reuse, modification and distribution see license.txt /** * @author Abhik Chakraborty */ use sendwithus\API; require_once BASE_PATH . '/plugins/EmailerSendWithUs/libs/sendwithus/vendor/autoload.php'; $emailer = new EmailerSendWithUs(); $api_key = $emailer->get_api_key(); $entity_selected = false; $templates_found = false; $groups_found = false; $api = new API($api_key); // get the templates $templates = $api->emails(); $templates_array = array(); if (is_array($templates) && count($templates) > 0) { foreach ($templates as $key => $templateObj) { if (property_exists($templateObj, 'name') && property_exists($templateObj, 'id')) { $templates_array[$templateObj->id] = $templateObj->name; } } $templates_found = true; } //get the groups, sending email to a selected group feature is not added yet /*$groups = $api->list_groups(); $groups_array = array(); if (is_array($groups->groups) && count($groups->groups) > 0) { foreach ($groups->groups as $key=>$groupsObj) { $groups_array[$groupsObj->id] = $groupsObj->name;
public function testGetEmails() { $r = $this->api->emails(); $this->assertNotNull($r); print 'Got emails'; }