<?php

//////////////////////////////////////////////////////////////
//===========================================================
// emailtemp_theme.php
//===========================================================
// SOFTACULOUS VIRTUALIZOR
// Version : 1.0
// Inspired by the DESIRE to be the BEST OF ALL
// ----------------------------------------------------------
// Started by: Alons
// Date:       8th Mar 2010
// Time:       23:00 hrs
// Site:       https://www.virtualizor.com/ (SOFTACULOUS VIRTUALIZOR)
// ----------------------------------------------------------
// Please Read the Terms of use at https://www.virtualizor.com
// ----------------------------------------------------------
//===========================================================
// (c)Softaculous Ltd.
//===========================================================
//////////////////////////////////////////////////////////////

if(!defined('VIRTUALIZOR')){

	die('Hacking Attempt');

}

function editemailtemp_theme(){

global $theme, $globals, $kernel, $user, $l, $error, $emailtemp, $ll, $done, $notice, $tempname;

softheader($l['<title>']);
					
echo page_header(__('Edit Email Template'), 'fas fa-paper-plane', '', 0, 0, '');

$breadcrummbs = array('dashboard', 'lm_emailtemp', 'lms_edit_emailtemp');

echo get_breadcrumb($breadcrummbs);

error_handle($error);

if(!empty($done)){
	show_alert(__('The email template was saved successfully'));
}

// We will load the tiny MCE if html is enabled
echo '
<script type="text/javascript" src="'.$theme['url'].'/js/tinymce/tinymce.min.js"></script>

<script>
	
	$(document).ready(function(){
		load_tinymce();
		$("#editemailtemp").submit(function(){
			load_tinymce();
		});
	});

</script>
';

// Are we allowed to edit
if(!empty($notice)){
	show_alert(__('This action not applicable for a slave server, please go above and change to localhost.'),"2");
	echo '<div class="notice"><b>'.__('Note').' : </b> &nbsp; '.__('This action not applicable for a slave server, please go above and change to localhost.').'</div>';
}else{

echo '
<div class="card mx-3 p-2">
	<form accept-charset="'.$globals['charset'].'" id="editemailtemp" name="editemailtemp" method="post" action="" class="form-horizontal">

		<div class="row mx-auto w-100 my-3">
			<div class="col-sm-3"><label class="control-label">'.__('Subject').'</label></div>
			<div class="col-sm-9"><input type="text" class="form-control" name="tempsub" value="'.htmlizer($ll['title']).'" size="73"></div>
		</div>
		<div class="row mx-auto w-100 my-3">
			<div class="col-sm-3"><label class="control-label">'.__('Content').'</label></div>
			<div class="col-sm-9">
				<textarea  cols="70" class="form-control" name="tempcontent" rows="15" id="tempcontent">'.htmlizer($ll['body']).'</textarea>
			</div>
		</div>';
			$html_flag = ($ll['mail_type'] == 'html' ? 'checked=checked' : '');
	echo'
	<div class="row mx-auto w-100 my-3">
		<div class="col-sm-3">
			<label class="control-label">'.__('Enable HTML Template').'&nbsp;<a class="info" data-placement="right" tooltip="'.__('If enabled, email will be sent in HTML format instead of plain text').'"><i class="fas text-primary fa-info-circle"></i></a></label>
		</div>
		
		<div class="col-sm-9">
			'.get_checkbox('mail_type', '', 'mail_type', array('chk_it' => 1), 1, '', array('onchange="load_tinymce();"', $html_flag)).'
		</div>
	</div>';

	if(!in_array($tempname, $globals['no_disable_templates'])){
		
		$html_flag = (!empty($ll['is_disable']) ? 'checked=checked' : '');
		echo'
		<div class="row mx-auto w-100 my-3">
			<div class="col-sm-3">
				<label class="control-label">'.__('Disable Email Template').'</label>
			</div>
		
			<div class="col-sm-9">
				'.get_checkbox('is_disable', '', 'is_disable', array('chk_it' => 1), 1,'', array($html_flag)).'
			</div>
		</div>';
		
	}

	echo '<script language="javascript" type="text/javascript"><!-- // --><![CDATA[
		
		function confirm_reset(){
			showalert("'.__J('Are you sure you want to Reset the email template?').'" ,"3" ,function(confirm){
				if(confirm == false){
				return false;
				}else{
					window.location = window.location+"&reset='.$tempname.'";
				}
			});
		}
		
		function load_tinymce(){
			
			if($("#mail_type").prop("checked") == true){
				
				var data = $("#tempcontent").val();
				$("#tempcontent").val(data);
				tinymce.init({
					selector:"textarea",
					plugins: [
						"advlist autolink lists link image charmap print preview hr anchor pagebreak",
						"searchreplace wordcount visualblocks visualchars code fullscreen",
						"insertdatetime nonbreaking save table contextmenu directionality",
						"emoticons template paste textcolor"
					],
					toolbar1: "insertfile undo redo | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent blockquote| link image",
					toolbar2: "preview media | forecolor backcolor emoticons | formatselect fontselect fontsizeselect ",
					force_br_newlines: false,
					force_p_newlines: false,
					forced_root_block: false,
				});
				
			}else{
				
				var tinyeditor = tinymce.get("tempcontent");
				
				if(tinyeditor){
					var data = tinyeditor.getContent().replace(/(<br>|<br \/>)/g, "\n");
					tinymce.remove("textarea");
					$("#tempcontent").val(data);
				}

			}
			
		};
		
		// ]]></script>';
		echo '

		<div class="row mx-auto w-100 my-3">
			<div class="col-sm-3"><label class="control-label"></label></div>
			<div class="col-sm-9">
				'.$ll['mail_vars'].'
			</div>
		</div>

		<br/>
		<center>
			<input type="submit" name="savetemplate" value="'.__('Save Email Template').'" class="go_btn"/> &nbsp;
			<input type="button" name="resettemplate" value="'.__('Reset Template').'" class="go_btn" onClick="confirm_reset();"/><br /><br />
			<a href="'.$globals['index'].'act=emailtemp" class="go_btn">'.__('Templates Overview').'</a>
		</center>

			</br>';
			
			echo '<br /><br />
	</form>';					
}

echo '</div>';
softfooter();

}

