<?php

//////////////////////////////////////////////////////////////
//===========================================================
// admin_acl_theme.php
//===========================================================
// SOFTACULOUS VIRTUALIZOR
// Version : 2.2.5
// Inspired by the DESIRE to be the BEST OF ALL
// ----------------------------------------------------------
// Started by: Julien
// Date:       19th July 2012
// 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 admin_acl_theme(){

global $theme, $globals, $kernel, $user, $l, $acls, $error, $done;

softheader($l['<title>']);
					
$buttons = array(
				0 => array(
					'name' => __('Add ACL'),
					'act'  => 'add_admin_acl'
				)
			);

$GLOBALS['breadcrumbs'] = array('dashboard', 'lm_users', 'lms_admin_acl');

echo page_header(__('Administrator Access Control List'), 'fas fa-users','', 0, 0, $buttons);

error_handle($error);

if(!is_allowed('adminacl')){
	softfooter();
	return;
}

echo '<script language="javascript" type="text/javascript"><!-- // --><![CDATA[

function Delacl(aclid ,ele){

	aclid = aclid || 0;
	
	// List of ids to delete
	var acl_list = new Array();
	
	if(aclid < 1){
		
		if($(ele).parent().prev().find("select").val() != 1){
			showalert("'.__J('No Action Selected !').'","1");
			return false;
		}
		
		$(".ios:checked").each(function() {
			acl_list.push($(this).val());
		});
		
	}else{
		
		acl_list.push(aclid);
		
	}
	
	if(acl_list.length < 1){
		showalert("'.__J('Nothing selected !').'","1");
		return false;
	}
	
	showalert("'.__J('Are you sure, you want to delete the selected item(s) ?').'" ,"3" ,function(confirm){
		if(confirm == false){
			return false;
		}else{
			var finalData = new Object();
			finalData["delete"] = acl_list.join(",");
			
			//alert(finalData);
			//return false;
			
			$("#progress_bar").show();
			
			$.ajax({
				type: "POST",
				url: "'.$globals['index'].'act=admin_acl&api=json",
				data : finalData,
				dataType : "json",
				success: function(data){
					$("#progress_bar").hide();
					if("done" in data){
						setTimeout(function(){showalert("'.__J('The action was completed successfully. Reloading the Page !').'");
						$("#alert-modal").on("hidden.bs.modal", function (e) {
						location.reload(true);
						});} ,200);
					}
					if("error" in data){
						setTimeout(function(){showalert(data["error"],"1");} ,200);
					}
					
				},
				error: function(data) {
					$("#progress_bar").hide();
					//alert(data.description);
					return false;
				}
			});
		}
	});
	
	
	
	
	return false;
};

// ]]></script>';
if(!empty($done)){
	show_alert(__('The ACL was successfully deleted'));
}
echo '<div class="card p-2 mx-3">';
if(empty($acls)){
	show_alert(__('There are no ACLs defined.'),'2');
	echo '<br><br><div class="notice"><b>NOTE : </b>&nbsp; '.__('There are no ACLs defined.').'</div>';
	
}else{
	echo'<div class="row mx-auto w-100 mb-3">
	<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="acl_task_select" class="custom-select" id="acl_task_select">
						<option value="0">---</option>
						<option value="1">'.__('Delete').'</option>
					</select>
                </div>
                <div class="pl-2">
					<button type="submit" class="go_btn" id ="adminacl_submit" name="adminacl_submit" onclick="Delacl(0 ,this); return false;">'.__('Go').'</button>
                </div>
            </div>
		</div>
	</div>
	<div class="col-sm-8 col-lg-8 col-md-6 d-flex align-items-center justify-content-end p-0 mt-2 mt-md-0 mt-lg-0 mt-2 mt-md-0 mt-lg-0">';
		page_links($globals['num_res'], $globals['cur_page'], $globals['reslen']);
		echo get_num_records($globals['num_res']).'
	</div>
</div>
<form accept-charset="'.$globals['charset'].'" name="multi_acl" id="multi_acl" method="post" action="" class="form-horizontal">
<div class="w-100 mx-auto sticky">
<table class="table table-hover tablesorter common-table">
	<tr>
		<th class="min_width z-index-1" align="center">
			'.get_checkbox('select_all', '', 'select_all', array('chk_it' => 0), '', 'select_all').'
		</th>
		<th class="min_width" align="center" width="50">'.__('ID').'</th>
		<th align="center">'.__('Name').'</th>
		<th class="text-right" width="80">'.__('Manage').'</th>
	</tr>
	<tbody>';

$i=1;	
foreach($acls as $k => $v){
	echo '<tr>
		<td valign="top" align="center">
			'.get_checkbox('adminacl_list[]', '', '', array('chk_it' => 0), $k).'
		</td>
		<td align="center">'.$v['aclid'].'</td>
		<td>'.$v['acl_name'].'</td>
		<td align="center">
			<div class="badge badge_container">
				<a class="badge badge-manage" href="?act=edit_admin_acl&aclid='.$v['aclid'].'" title="'.__('Edit').'"><span><i class="fas fa-pencil-alt"></i></span></a>
				<a class="badge badge-trash"href="javascript:void(0);" onclick="return Delacl('.$k.');" title="'.__('Delete').'"><span><i class="fas fa-trash"></i></span></a>
			</div>
		</td>
		</tr>';	
	$i++;
}

echo '</tbody></table></div>
<div class="row mx-auto w-100 mt-5">
	<div class="col-sm-8 col-lg-8 col-md-6 mb-3 p-0">';
		page_links($globals['num_res'], $globals['cur_page'], $globals['reslen']);
	echo'
	</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="acl_task_select" class="custom-select" id="acl_task_select">
						<option value="0">---</option>
						<option value="1">'.__('Delete').'</option>
					</select>
                </div>
                <div class="pl-2">
					<button type="submit" class="go_btn" id ="adminacl_submit" name="adminacl_submit" onclick="Delacl(0 ,this); return false;">'.__('Go').'</button>
                </div>
            </div>
		</div>
	</div>
</div>
</form>

<div id="progress_bar" style="display:none;">
	<br />
	<center>
		<font id="progress_txt" size="4">'.__('Please wait, Action in Progress.').'</font>
	</center>
	<div class="my-2" align="center">
		<div class="progress w-50">
			<div class="progress-bar bg-primary progress-bar-striped progress-bar-animated w-100">
			</div>
		</div>
	</div>
	<center>
		'.__('You will be notified once the Action is Completed.').'
	</center>
</div>';
}

echo 
'<div class="text-center my-4">
	<a href="index.php?act=add_admin_acl" class="go_btn">'.__('Add ACL').'</a>
</div></div><br><br>

';
softfooter();

}
?>
