<?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 emailtemp_theme(){

global $theme, $l, $globals, $kernel, $user, $error, $emailtemps, $done, $notice;

softheader($l['<title>']);
					
echo '
<script>
$(document).ready(function(){
	$(".temp_select").on("click", function(){
		var id = $(this).attr("id");
		var checkboxes = $("."+id);

		var is_checked = $(this).prop("checked");

		checkboxes.each(function(){
			
			if(is_checked){
				$(this).prop("checked", true);
			}else{
				$(this).prop("checked", false);
			}
		});
	});
})

function show_confirm(ele){
	multi_action = $(ele).parent().prev().find("select").val();
	if(multi_action == "0"){
		showalert("'.__J('No action selected !').'","1");
		return false;
	}
	var temp_list = new Array();
	var field = document.getElementsByName(\'temp_list[]\');
	for(i = 0; i < field.length; i++){
		if(field[i].checked){
			temp_list[temp_list.length] = field[i].value;
		}
	}
	if(temp_list.length == 0){
		showalert("'.__J('No Template Selected !').'","1");
		return false;
	}

	url = "'.$globals['index'].'act=emailtemp&action="+multi_action+"&temp_action=1&api=json";
	$.each(temp_list, function(k, v){
		$("#"+v).css("display", "block");
	})
	$.ajax({type: "POST",
		url: url,
		data:"templates="+temp_list.join(","),
		success:function(response){
			showalert("'.__J('The action was completed successfully. Reloading Page!').'");
			$.each(temp_list, function(k, v){
				$("#"+v).css("display", "none");
			})
			$("#alert-modal").on("hidden.bs.modal", function (e) {
				location.reload(true);
			});
		}
	});
}

</script>';
echo page_header(__('Email Templates'), 'fas fa-paper-plane', '', 0, 0, '');

$breadcrummbs = array('dashboard', 'lm_config', 'lms_emailtemp');

echo get_breadcrumb($breadcrummbs);

error_handle($error);

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=" w-100 mx-auto sticky">
';
$i=0;
foreach($emailtemps as $k => $v){

$ll = email_templates($k);

if($ll['is_admin'] == 1){
	$admin_email_temp[] = '<tr>
	<td width="20" valign="top" align="center">
		'.(!in_array($k, $globals['no_disable_templates']) ? get_checkbox('temp_list[]', '', '', array('chk_it' => 0), $k, 'admin_select') : '').'
	</td>
	<td><div class="d-flex">'.$v['temp'].'<div class="ml-3 loader" id="'.$k.'" style="display:none;"></div></div></td>
	<td>'.__('Admin').'</td>
	<td>
		<!-- <i class="fas fa-circle '.(!empty($ll['is_disable']) ? "fa-circle-red" : "fa-circle-green").'" title="'.(!empty($ll['is_disable']) ? __('Disabled') : __('Enabled')).'"></i> -->
		<h5 class="p-0 m-0"><a class="badge '.(!empty($ll['is_disable']) ? 'badge-danger' : 'badge-success').'" title="'.(!empty($ll['is_disable']) ? __('Disabled') : __('Enabled')).'">'.(!empty($ll['is_disable']) ? __('Disabled') : __('Enabled')).'</a></h5>
	</td>
	<td>
		<div class="badge_container">
			<a class="badge badge-manage" href="'.$globals['ind'].'act=editemailtemp&temp='.$k.'"><i class="fas fa-pencil-alt"></i></a>
		</div>
	</td>
</tr>';
}

if($ll['is_admin'] == 0){
	$user_email_temp[] = '<tr>
	<td width="20" valign="top" align="center">
		'.(!in_array($k, $globals['no_disable_templates']) ? get_checkbox('temp_list[]', '', '', array('chk_it' => 0), $k, 'user_select') : '').'
	</td>
	<td><div class="d-flex">'.$v['temp'].'<div class="ml-3 loader" id="'.$k.'" style="display:none;"></div></div></td>
	<td>'.__('User').'</td>
	<td>
		<!-- <i class="fas fa-circle '.(!empty($ll['is_disable']) ? "fa-circle-red" : "fa-circle-green").'" title="'.(!empty($ll['is_disable']) ? __('Disabled') : __('Enabled')).'"></i> -->
		<h5 class="p-0 m-0"><a class="badge '.(!empty($ll['is_disable']) ? 'badge-danger' : 'badge-success').'" title="'.(!empty($ll['is_disable']) ? __('Disabled') : __('Enabled')).'">'.(!empty($ll['is_disable']) ? __('Disabled') : __('Enabled')).'</a></h5>
	</td>
	<td>
		<div class="badge_container">
			<a class="badge badge-manage" href="'.$globals['ind'].'act=editemailtemp&temp='.$k.'"><i class="fas fa-pencil-alt"></i></a>
		</div>
	</td>
</tr>';
}

if($ll['is_admin'] == 2){
	$admin_user_email_temp[] = '<tr>
	<td width="20" valign="top" align="center">
		'.(!in_array($k, $globals['no_disable_templates']) ? get_checkbox('temp_list[]', '', '', array('chk_it' => 0), $k, 'admin_user_select') : '').'
	</td>
	<td><div class="d-flex">'.$v['temp'].'<div class="ml-3 loader" id="'.$k.'" style="display:none;"></div></div></td>
	<td>'.__('Admin/User').'</td>
	<td>
		<!--<i class="fas fa-circle '.(!empty($ll['is_disable']) ? "fa-circle-red" : "fa-circle-green").'" title="'.(!empty($ll['is_disable']) ? __('Disabled') : __('Enabled')).'"></i>-->
		<h5 class="p-0 m-0"><a class="badge '.(!empty($ll['is_disable']) ? 'badge-danger' : 'badge-success').'" title="'.(!empty($ll['is_disable']) ? __('Disabled') : __('Enabled')).'">'.(!empty($ll['is_disable']) ? __('Disabled') : __('Enabled')).'</a></h5>
	</td>
	<td>
		<div class="badge_container">
			<a class="badge badge-manage" href="'.$globals['ind'].'act=editemailtemp&temp='.$k.'"><i class="fas fa-pencil-alt"></i></a>
		</div>
	</td>
</tr>';
}
$i++;
}

echo '
<div class="card p-2 mx-3">
<div class="row mx-auto w-100">
	<div class="col-sm-8 col-lg-8 col-md-6 mb-3 p-0">
		'.get_num_records(count($emailtemps)).'
	</div>
	<div class="col-sm-4 col-lg-4 col-md-6 text-right mb-3">
		<div class="bottom-menu float-right w-100">
            <div class="row my-auto">
				<div class="p-0">
					<label>'.__('With selected:').'</label>
				</div>
				<div class="col p-0">
					<select name="multi_options" id="multi_options" class="custom-select w-100">
						<option value="0">---</option>
						<option value="enable_temp">'.__('Enable Template').'</option>
						<option value="disable_temp">'.__('Disable Template').'</option>
					</select>
				</div>
				<div class="pl-2">
					<input type="button" value="'.__('GO').'" onclick="show_confirm(this);" class="go_btn"/>
				</div>
			</div>
		</div>
	</div>
</div>
<table class="table table-hover tablesorter common-table" align="center">
<tr class="table_heading">
	<th class="z-index-1 min_width">
		'.get_checkbox('select_all', '', 'admin_select', array('chk_it' => 0), '', 'temp_select').'
	</th>
	<th align="center">'.__('Admin').' '.__('Email Templates').'</th>
	<th class="min_width" align="center">'.__('Type').'</th>
	<th class="min_width" align="center">'.__('Status').'</th>
	<th class="min_width" align="center">'.__('Manage').'</th>
</tr>
'.implode('', $admin_email_temp).'
</table>
<table class="table table-hover tablesorter" align="center">
<tr>
	<th class="z-index-1 min_width">
		'.get_checkbox('select_all', '', 'user_select', array('chk_it' => 0), '', 'temp_select').'
	</th>
	<th align="center">'.__('User').' '.__('Email Templates').'</th>
	<th class="min_width" align="center">'.__('Type').'</th>
	<th class="min_width" align="center">'.__('Status').'</th>
	<th class="min_width" align="center">'.__('Manage').'</th>
</tr>
'.implode('', $user_email_temp).'
</table>
<table class="table table-hover tablesorter" align="center">
<tr>
	<th class="z-index-1 min_width">
		'.get_checkbox('select_all', '', 'admin_user_select', array('chk_it' => 0), '', 'temp_select').'
	</th>
	<th align="center">'.__('Admin/User').' '.__('Email Templates').'</th>
	<th class="min_width" align="center">'.__('Type').'</th>
	<th class="min_width" align="center">'.__('Status').'</th>
	<th class="min_width" align="center">'.__('Manage').'</th>
</tr>
'.implode('', $admin_user_email_temp).'
</table>
<div class="row mx-auto w-100 mb-3">
	<div class="col-sm-8 col-lg-8 col-md-6 d-flex align-items-center p-0">
		'.get_num_records(count($emailtemps)).'
	</div>
	<div class="col-sm-4 col-lg-4 col-md-6 text-right d-flex align-items-center">
		<div class="bottom-menu float-right w-100">
            <div class="row my-auto">
				<div class="p-0">
					<label>'.__('With selected:').'</label>
				</div>
				<div class="col p-0">
					<select name="multi_options" id="multi_options" class="custom-select w-100">
						<option value="0">---</option>
						<option value="enable_temp">'.__('Enable Template').'</option>
						<option value="disable_temp">'.__('Disable Template').'</option>
					</select>
				</div>
				<div class="pl-2">
					<input type="button" value="'.__('GO').'" onclick="show_confirm(this);" class="go_btn"/>
				</div>
			</div>
		</div>
	</div>
</div>
</div>';

}

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

}