<?php

//////////////////////////////////////////////////////////////
//===========================================================
// user_notice_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 user_notice_theme(){

global $theme, $globals, $cluster, $users, $l, $error, $done, $servergroups, $servers, $users_email, $notices;

softheader($l['<title>']);
					$add_notice_button = [0 => ['act' => 'add_user_notice', 'name' => __('Add User Notice')]];

$GLOBALS['breadcrumbs'] = array('dashboard', 'lm_user_notice', 'lms_user_notice');

echo page_header(__('User Notice'), 'fas fa-paper-plane', '', 0, 0, $add_notice_button);

error_handle($error);

if(!empty($done)){
	show_alert($done, '', 'user_notice');
}

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

var from_modal = 0;

function vpsmodal(uid){
	from_modal=1;
	action_chosen("delete", uid);
};

function action_chosen(action, uid ,ele){
	
action = action || "";
uid = uid || 0;

if(action == ""){
	if($(ele).parent().prev().find("select").val() == 0){
			showalert("'.__J('No action selected !').'","1");
			return false;
	}else{
		action = $(ele).parent().prev().find("select").val();
	}
}

// List of ids to delete
var usr_list = new Array();

if(uid < 1){
	
	$(".ios:checked").each(function(){
		usr_list.push($(this).val());
	});
	
}else{
	
	usr_list.push(uid);
	
}

if(usr_list.length < 1){
	showalert("'.__J('Nothing selected !').'","1");
	return false;
}

// Just check for delete action
if(action == "delete" && from_modal == 0){
	vpsmodal();
	from_modal = 1;
	return true;
}

// To delete the user
if(action == "delete"){
	
	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"] = usr_list.join(",");
			perform_action(finalData);
		}
	});
	
// To disable
}else if(action == "disable"){
	showalert("'.__J('Are you sure want to Disable the Plan ?').'" ,"3" ,function(confirm){
		if(confirm == false){
			return false;
		}else{
			var finalData = new Object();
			finalData["disable"] = usr_list.join(",");
			perform_action(finalData, uid);
			
		}
	});

// To Enable
}else if(action == "enable"){
	showalert("'.__J('Are you sure want to Enable the Plan ?').'" ,"3" ,function(confirm){
		if(confirm == false){
			return false;
		}else{
			var finalData = new Object();
			finalData["enable"] = usr_list.join(",");
			perform_action(finalData, uid);
			
		}
	});
	
// Not a valid action 
}else{
	showalert("'.__J('No action selected !').'","1");
	return false;
}

return false;
};

function perform_action(finalData, uid = 0){

//alert(finalData);
//return false;

$("#progress_bar").show();
$.ajax({
	type: "POST",
	url: "'.$globals['index'].'act=user_notice&api=json",
	data : finalData,
	dataType : "json",
	success: function(data){
		$("#progress_bar").hide();
		if(!empty(uid)){
			$("#showload_"+uid).hide();
		}
		if("done" in data){
			setTimeout(function(){showalert("'.__J('The action was completed sucessfully').'");
			$("#alert-modal").on("hidden.bs.modal", function (e) {
			location.reload(true);
			});} ,800);
		}
		
		if("error" in data){
			setTimeout(function(){showalert(data["error"],"1");
			$("#alert-modal").on("hidden.bs.modal", function (e) {
			location.reload(true);
			});} ,800);
		}
	},
	error: function(data) {
		if(!empty(uid)){
			$("#showload_"+uid).hide();
		}
		$("#progress_bar").hide();
		return false;
	}
});

return false;
}

</script>

<div class="card p-2 mx-3">';
if(empty($notices)){
	echo '<div class="notice"><b>'.__('Note').' : </b> &nbsp;'.__('There are no Notices added. &nbsp;<a href="index.php?act=add_user_notice">Add Notice now</a>').'</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="user_task_select" class="custom-select" id="user_task_select">
						<option value="0">---</option>
						<option value="delete">'.__('Delete').'</option>
						<option value="enable">'.__('Enable').'</option>
						<option value="disable">'.__('Disable').'</option>
					</select>
				</div>
				<div class="pl-2">
					<button type="submit" class="go_btn" id="user_submit" name="user_submit" onclick="action_chosen(\'\', 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">';
		page_links($globals['num_res'], $globals['cur_page'], $globals['reslen']);
		echo'
	</div>
</div>
<form accept-charset="'.$globals['charset'].'" name="multi_users" id="multi_users" method="post" action="" class="form-horizontal">
<div class="w-100 mx-auto sticky">
<table class="table table-hover tablesorter common-table">
	<tr class="table_heading">
		<th class="z-index-1 min_width" align="center">
			'.get_checkbox('select_all', '', 'select_all', array('chk_it' => 0), '', 'select_all').'
		</th>
		<!-- <th  class="min_width" align="center">'.__('Id').'</th>-->
		<th>'.__('Notice Name').'</th>
		<th>'.__('Notice Type').'</th>
		<th>'.__('Visible To').'</th>
		<th width="100">'.__('Enabled').'</th>
		<th class="text-right pr-3" colspan="3">'.__('Manage').'</th>
	</tr>
	<tbody>';

$i = 1;
$user = [-1 => 'all_users', 0 => 'users', 2 => 'cloud_users'];
$notice_type = ['primary', 'warning', 'success', 'danger'];

$user_lang['users'] = 'User';
$user_lang['cloud_users'] = 'Cloud';
$user_lang['all_users'] = 'All Users';

// r_print($notices);
foreach($notices as $k => $v){
	echo '<tr>
			<td width="20" valign="middle" align="center">
				'.get_checkbox('user_list[]', '', '', array('chk_it' => 0), $v['id']).'
			</td>
			<!-- <td align="center">'.$v['id'].'</td> -->
			<td>'.$v['notice_name'].'</td>
			<td>
				<h5 class="p-0 m-0"><a class="badge badge-'.$v['notice_type'].'">'.ucfirst($v['notice_type']).'</a></h5>
			</td>
			<td>'.$user_lang[$user[$v['user_type']]].'</td>
			<td align="center">
				<h5 class="p-0 m-0"><a class="badge '.(($v['enabled'] != 1) ? 'badge-danger' : 'badge-success').'" title="'.(($v['act_status'] != 1) ? __('Account is inactive') : __('Account is active')).'">'.(($v['enabled'] != 1) ? __('Inactive') : __('Active')).'</a></h5>
			</td>
			<td width="20" valign="middle" align="center">
				<div class="badge badge_container">
					<a class="badge badge-manage" href="'.$globals['ind'].'act=edit_user_notice&id='.$v['id'].'" title="'.__('Edit Notice').'"><i class="fas fa-pencil-alt"></i></a>
					<a class="badge badge-trash" href="javascript:void(0);" onclick="vpsmodal(\''.$v['id'].'\');"  title="'.__('Delete Recipe').'"><i class="fas fa-trash"></i></a>
				</div>
			</td>
		</tr>';
	
	$i++;
}

echo '</tbody></table>
</div>';
echo'<div class="row mx-auto w-100 mt-5">
	<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="user_task_select" class="custom-select" id="user_task_select">
						<option value="0">---</option>
						<option value="delete">'.__('Delete').'</option>
						<option value="enable">'.__('Enable').'</option>
						<option value="disable">'.__('Disable').'</option>
					</select>
				</div>
				<div class="pl-2">
					<button type="submit" class="go_btn" id="user_submit" name="user_submit" onclick="action_chosen(\'\', 0, this); return false;">'.__('Go').'</button>
				</div>
			</div>
		</div>
	</div>
	<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>
</form>
<div id="progress_bar" class="my-3" 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>';

}// End of else

softfooter();

}

?>
