示例#1
0
function GetTemplateById()
{
	$connection = new DBConnection();
	$settingsModel = new App\Model\Settings($connection, 'mail_settings');
    $settings = $settingsModel->getAll();

    $API_KEY = $settings['sendwithus_key'];
    $options = array();
    $api = new API($API_KEY, $options);

    $templateId = $_POST['templateId'];
    if ($templateId != "")
    {
        $response = $api->get_template($templateId);
        $response = $api->get_template($templateId,$response->versions[0]->id);


        // Get html body
        /*
        $d = new DOMDocument;
        $mock = new DOMDocument;
        $d->loadHTML($response->html);
        $body = $d->getElementsByTagName('body')->item(0);
        foreach ($body->childNodes as $child){
            $mock->appendChild($mock->importNode($child, true));
        }
        $response->html = $mock->saveHTML();
        */
        echo json_encode($response);
    }else{
        echo json_encode(array('text'=>'' , 'html' => '','id' => '','name' => ''));
    }
}
示例#2
0
	}
}

if (array_get($_POST, 'mail_templates_id', 0) > 0){
	$query = 'SELECT * FROM mail_templates WHERE mail_templates_id='.($_POST['mail_templates_id']+0).' LIMIT 1';
	$res   = $db->rq($query);
	if(!isset($_POST['_back'])){
		$_POST = $db->fetch($res);
	}

    //
    $templateRow = $db->getRow('mail_templates','mail_templates_id="'.$_POST['mail_templates_id'].'"','mail_external_id, mail_template_title, mail_templates_id');
    $templateId = $templateRow["mail_external_id"];
    
	$settingsModel = new App\Model\Settings($db, 'mail_settings');
    $settings = $settingsModel->getAll();
    
	if(!$templateId){
		echo '<p>Sendwithus theme is not defined for this template "'.$templateRow['mail_template_title'].'"</p>';
		echo '<p><a href=\'mails_templates.php?action=edit&mtid='.$templateRow['mail_templates_id'].'\'>Go to edit</a></p>';
		exit();
	}

    $API_KEY = $settings['sendwithus_key'];
    $options = array();
    $api = new API($API_KEY, $options);
    $response = $api->get_template($templateId);
    $response = $api->get_template($templateId,$response->versions[0]->id);

    $_POST["mail_html"] = $response->html;
    $_POST["mail_plain"] = $response->text;
示例#3
0
function mailForm(){
    $connection = new DBConnection();
	$settings = new App\Model\Settings($connection, 'mail_settings');
    $_POST = $settings->getAll();

    $pcontent='';
    $pcontent.='
<div class="mainHolder">
    <script type="text/javascript" src="js/forms/mailSettings.js"></script>

    <div class="hintHolder ui-state-default">
        <b>Editing Mail Settings</b>
    </div>
    
    <form name="addNewExpDate" method="POST" id="MainForms" action="">
        <fieldset class="mainFormHolder">
            <legend>Transport type</legend>
            <div class="formsLeft">Transport:</div>
            <div class="formsRight">
                <select class="text-input" name="options[mail_transport]" id="mail_transport">
                    <option value="smtp" ' . (array_get($_POST, 'mail_transport') == 'smtp' ? 'selected="selected"' : '') . '>SMTP</option>
                    <option value="mandrill" ' . (array_get($_POST, 'mail_transport') == 'mandrill' ? 'selected="selected"' : '') . '>Mandrill</option>
                </select>
            </div>
        </fieldset>

        <fieldset class="mainFormHolder options options-smtp">
            <legend>SMTP Settings</legend>
            
            <div class="formsLeft">SMTP Host:</div>
            <div class="formsRight">
                <input class="text-input" type="text" name="options[mail_smtp_host]" id="mail_smtp_host" value="'.array_get($_POST, 'mail_smtp_host').'" autocomplete="off" />
            </div>
            <br />
            <div class="formsLeft">SMTP User:</div>
            <div class="formsRight">
                <input class="text-input" type="text" name="options[mail_smtp_user]" id="mail_smtp_user" value="'.array_get($_POST, 'mail_smtp_user').'" autocomplete="off" />
            </div>
            <br />
            <div class="formsLeft">SMTP Password:</div>
            <div class="formsRight">
                <input class="text-input" type="text" name="options[mail_smtp_password]" id="mail_smtp_password" value="'.array_get($_POST, 'mail_smtp_password').'" autocomplete="off" />
            </div>
            <br />
            <div class="formsLeft">SMTP Port:</div>
            <div class="formsRight">
                <input class="text-input" type="text" name="options[mail_smtp_port]" id="mail_smtp_port" value="'.array_get($_POST, 'mail_smtp_port').'" autocomplete="off" />
            </div>
        </fieldset>
        
        <fieldset class="mainFormHolder options options-mandrill">
            <legend>Mandrill Settings</legend>
            
            <div class="formsLeft">Host:</div>
            <div class="formsRight">
                <input class="text-input" type="text" name="options[mail_mandrill_host]" id="mail_mandrill_host" value="'.array_get($_POST, 'mail_mandrill_host').'" autocomplete="off" />
            </div>
            <br />
            <div class="formsLeft">Port:</div>
            <div class="formsRight">
                <input class="text-input" type="text" name="options[mail_mandrill_port]" id="mail_mandrill_port" value="'.array_get($_POST, 'mail_mandrill_port').'" autocomplete="off" />
            </div>
            <br />
            <div class="formsLeft">Username:</div>
            <div class="formsRight">
                <input class="text-input" type="text" name="options[mail_mandrill_user]" id="mail_mandrill_user" value="'.array_get($_POST, 'mail_mandrill_user').'" autocomplete="off" />
            </div>
            <br />
            <div class="formsLeft">API Key:</div>
            <div class="formsRight">
                <input class="text-input" type="text" name="options[mail_mandrill_password]" id="mail_mandrill_password" value="'.array_get($_POST, 'mail_mandrill_password').'" autocomplete="off" />
            </div>
        </fieldset>
        
        <fieldset class="mainFormHolder">
            <legend>Sendwithus Settings</legend>
            
            <div class="formsLeft">API Key:</div>
            <div class="formsRight">
                <input class="text-input" type="text" name="options[sendwithus_key]" id="sendwithus_key" value="'.array_get($_POST, 'sendwithus_key').'" autocomplete="off" />
            </div>
            <br />
            <div class="formsLeft">Tags:</div>
            <div class="formsRight">
                <input class="text-input" type="text" name="options[sendwithus_tags]" id="sendwithus_tags" value="'.array_get($_POST, 'sendwithus_tags').'" autocomplete="off" />
            </div>
        </fieldset>
        
        <fieldset class="mainFormHolder">
            <legend>Other Settings</legend>
            
            <div class="formsLeft">Mails to send per script run:</div>
            <div class="formsRight">
                <input class="text-input" type="text" name="options[mails_per_cron]" id="mails_per_cron" value="'.array_get($_POST, 'mails_per_cron').'" autocomplete="off" />
            </div>
        </fieldset>
        
        <input type="hidden" name="_form_submit" value="1" />
        <input type="submit" name="_submit" value="'.getLang('sform_savebtn').'" class="submitBtn ui-state-default" />
        <input type="button" name="_cancel" value="'.getLang('sform_backbtn').'" class="submitBtn ui-state-default" onclick="location=\'mails_smtp_settings.php\';" />
    </form>
</div>';
    return $pcontent;
}
示例#4
0
    
    if (count($upload->getValidFiles()) > 0) {
        foreach(new DirectoryIterator(UPLOAD_DIR) as $file) {
            if (!$file->isDot()) {
                unlink($file->getRealPath());
            }
        }
        
        $upload->save();
        
        $_POST['options']['pdf_logo'] = $upload->current()->filename;
    }
    
    foreach ($_POST['options'] as $name => $value){
        $settings->update($name, $value);
    }
    
    header('Location: settings_pdf.php');
    exit();
}

$connection = new DBConnection();
$settings = new App\Model\Settings($connection, 'pdf');

$view = new App\View\View('settings/pdf');
$view->settings = $settings->getAll();
$view->uploadUrl = UPLOAD_URL;

page_header();
echo $view->render();
page_footer();
示例#5
0
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;
}