<?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:       http://www.virtualizor.com/ (SOFTACULOUS VIRTUALIZOR)
// ----------------------------------------------------------
// Please Read the Terms of use at http://www.virtualizor.com
// ----------------------------------------------------------
//===========================================================
// (c)Softaculous Ltd.
//===========================================================
//////////////////////////////////////////////////////////////

if(!defined('SOFTACULOUS')){

	die('Hacking Attempt');

}

function plans_theme(){

global $user, $globals, $l, $theme, $softpanel, $iscripts, $catwise, $error, $emailtemps, $plans, $done, $_users;

softheader(__('$0 - Plans', array(APP)));

echo '<div class="container-fluid py-4">
	<div class="container">
		<div class="row">
			<div class="col-12">
				<div class="sai-card p-4">
					<div class="sai_main_head">
						<i class="far fa-edit sai-icon d-inline-block mr-1"></i>
						<h2 class="sai-heading d-inline-block mb-2 position-relative" style="top:-5px;">'.__('Plans').'</h2>
						<hr class = "sai_main_head_hr"/>
					</div>
				
		<div class="sai_form">';

		error_handle($error);

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

				function delconf(){
					return confirm("'.__js('Are you sure want to delete this plan ?').'");
				};

				function add_plan(){
					window.location.href = "'.$globals['ind'].'act=addplans";
				}

	// ]]></script>';

		if(!empty($done)){
			echo '<div class="alert alert-success text-center">
			<i class="fas fa-check sai_icons mr-2"></i>
			'.__('The plan has been deleted successfully. Refresh this $0 Page$1', array('<a href="'.$globals['index'].'act=plans">', '</a>')).'
			</div>';
		}

		if(empty($plans)){
			echo '<div class="row my-2 text-center">
				<div class="col-12 col-lg-10 alert alert-warning p-3 mx-auto">
					<i class="fas fa-exclamation-triangle fa-2x mr-2"></i>'.__('There are no Plans. $0 Add a Plan now$1', array('<a href="'.$globals['index'].'act=addplans">', '</a>')).'
				</div>
			</div>';
		}else{

			echo '<table border="0" cellpadding="5" cellspacing="1" class="soft-table-list table" align="center">
			<tr>
				<thead class="sai-sub-type">
					<td>'.__('Plans').'</td>
					<td colspan="2">'.__('Options').'</td>
					<td><input type="checkbox" onclick="check(document.getElementsByName(\'insids[]\'), this);" /></td>
				</thead>
			</tr>';
			$i=1;

			// Sort the plans alphabetically
			ksort($plans);

			foreach($plans as $k => $v){
				
				// Show name
				$v['show_name'] = get_filename($v['name']);
				
				echo '<tr class="'.($i % 2 == 0 ? "sai_evenrowcolor" : "sai_oddrowcolor").'">		
					<td width="80%">'.$v['show_name'].'</td>
					<td width="25">
						<a href="'.$globals['ind'].'act=editplans&plan='.$v['show_name'].'" class="text-decoration-none">
							<i class="fas fa-pencil-alt px-1 sai_icons" style="color:#FF5D00;" title="'.__('Edit Plan').'"></i>
						</a>
					</td>
				<form accept-charset="'.$globals['charset'].'" method="post" action="'.$globals['ind'].'act=plans&delete='.$v['show_name'].'" class="form-horizontal">
					<td width="25" >'.csrf_display().'
						<button type="submit" onclick="return delconf();" title="'.__('Delete Plan(s)').'"  class="text-decoration-none remove-btn">
							<i class="fas fa-trash-alt sai_icons" style="color:red;"></i>
						</button>
					</td>
				</form>
				<td>
					<input type="checkbox" name="insids[]" id="'.$v['show_name'].'" value="'.$v['show_name'].'">
				</td>
			</tr>';
			$i++;
		}

echo '</table>

		<center>
			<a href="'.$globals['ind'].'act=addplans" class="text-decoration-none">
				<input type="submit" class="flat-butt" value="'.__('Add Plan').'">
			</a>
		</center>
		'.(empty($globals['lictype']) ? '<div class="sai_exp2 p-3 text-center">'.__('NOTE: This feature is disabled in the free version of $0', array(APP)).'</div>' : '').'
			<div class="row">
				<div class="col-12 col-lg-6 ml-auto mt-4 text-right">
					<span class="sai-label">
						'.__('With Selected').': 
						<select name="multi_options" id="multi_options" class="form-control d-inline-block w-50">
							<option name="todo" id="todo" value="0">---</option>
							<option name="todo" id="todo" value="mult_rem">'.__('Delete Plan(s)').'</option>
						</select>
						'.csrf_display().'
						<input type="button" value="'.__('Go').'" onclick="show_confirm()" class="flat-butt">
						
					</span>
				</div>
				
			</div>
			<div id="rem_div"></div>';
		}

		echo '<script language="javascript" type="text/javascript"><!-- // --><![CDATA[
		insids = new Array();
		removed = new Object();

		function show_confirm(){
			
			insids = new Array();
			removed = new Object();
			
			if($_("multi_options").value != "mult_rem"){
				return false;
			}

			// Build the list of Installations to remove
			var field = document.getElementsByName(\'insids[]\');
				insids = new Array();
				var c = 0;
				for(i = 0; i < field.length; i++){
					if(field[i].checked == true){
						insids[c] = field[i].value;
						c++;
					}
				
			}
			//alert(insids);
			
			if(c == 0){
				alert("'.__js('No plan(s) selected to remove.').'");
				return false;
			}
			
			var r = confirm("'.__js('Are you sure you wish to remove the selected Plan(s) ? The action will be irreversible. No further confirmations will be asked !').'");
			if(r != true){
				return false;
			}

			remove_by_id(insids[0], "", 0);
		}

		function remove_by_id(insid, re, oldinsid){

			removed[insid] = false;
			
			if(re.length > 0 && oldinsid > 0){
				if(re == "removed"){
					removed[insid] = true;
				}
			}
			
			nextinsid = 0;
			
			// Find the next INSTALLATION to remove
			for(i = 0; i < insids.length; i++){
				if(typeof(removed[insids[i]]) != "undefined"){
					continue;
				}
				nextinsid = insids[i];
				break;
			}

			// If there is something left to be removed
			if(insid != 0){
				
				var csrf_token = $("#csrf_token").val(); 
				
				try{
					$.ajax({
						type: "POST",
						data: "csrf_token="+csrf_token,
						url: "'.$globals['index'].'act=plans&delete="+insid+"&ajax=1&random="+Math.random(),
						// Checking for error
						success: function(data){
							remove_by_id(nextinsid, data, insid);	
						}
					});
					
					$_("rem_div").innerHTML = "<br /><br /><p align=\"center\"><img src=\"' . $theme['images'] . 'ajax_remove.gif\"> <br />'.__js('Removing Plan'). ': " +insid+ "<br /></p>";
					return true;
				}catch(e){
					return false;
				}
			}
			$_("rem_div").innerHTML = "";
			alert("'.__js('The selected Plan(s) have been removed. The page will now be reloaded !').'");
			location.reload(true);
			return true;
		}


		$(document).ready(function(){
			
			$(".sai_altrowstable tr").mouseover(function(){
				var old_class = $(this).attr("class");
				//alert(old_class);
				$(this).attr("class", "sai_tr_bgcolor");
				
				$(this).mouseout(function(){
					$(this).attr("class", old_class);
				});
			});
			
		});

		// ]]></script>';

		echo'</div>
		</div>
	</div>
</div>
</div>
</div>';

softfooter();

}

?>