<?php

//////////////////////////////////////////////////////////////
//===========================================================
// listrecipes_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 recipes_theme(){

global $theme, $globals, $kernel, $users, $l, $error, $done, $SESS, $recipe;

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

$GLOBALS['breadcrumbs'] = array('dashboard', 'lm_recipes', 'lms_recipes');

echo page_header(__('Recipes'), 'icon icon-recipes', '', 1, 0, $buttons);

error_handle($error);

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

function Delrecipe(rid ,ele){

	rid = rid || 0;
	
	// List of ids to delete
	var usr_list = new Array();
	if(rid < 1){
		
		if($(ele).parent().prev().find("select").val() == 0){
			showalert("'.__J('No action selected !').'" ,"1");
			return false;
		}
		// Multi action
		var multi_action = $(ele).parent().prev().find("select").val();
		var act_val = $(ele).parent().prev().find("select").val();
		
		$(".ios:checked").each(function() {
			usr_list.push($(this).val());
		});
	
	}else{
		
		usr_list.push(rid);
		
		// Single action
		var multi_action = "delete";
		var act_val = "'.__J('Delete').'";
		
		if(usr_list.length < 1){
			showalert("'.__J('Nothing selected !').'" ,"1");
			return false;
		}
	}
	
	if(usr_list.length < 1){
		showalert("'.__J('Nothing selected !').'" ,"1");
		return false;
	}
	
	showalert("'.__J('Are you sure, you want to ').'"+ act_val + "'.__J(' the selected item(s)').'" ,"3" ,function(confirm){
		if(confirm == false){
			return false;
		}else{
			var finalData = new Object();
			finalData[multi_action] = usr_list.join(",");
			
			//alert(finalData);
			//return false;
			
			$("#progress_bar").show();
			
			$.ajax({
				type: "POST",
				url: "'.$globals['index'].'act=recipes&api=json",
				data : finalData,
				dataType : "json",
				success: function(data, a, b){
					$("#progress_bar").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);
						});} ,200);
					}
				},
				error: function(data) {
					$("#progress_bar").hide();
					//alert(data.description);
					return false;
				}
			});
		}
	});
	
	return false;
};

// ]]></script>
<div class="card p-2 mx-3">
<div id="showsearch" style="display:'.(optREQ('search') || (!empty($recipe) && !empty($globals['showsearch'])) ? "" : "none").';">
<form accept-charset="'.$globals['charset'].'" name="recipes" method="GET" action="" class="form-horizontal">
<input type="hidden" name="act" value="recipes">
<div class="form-group_head">
	<div class="row mx-auto w-100">
		<div class="col-sm-3"></div>
		<div class="col-sm-3">
			<label>'.__('ID').'</label>
			<input type="text" class="form-control" name="rid" id="rid" size="15" value="'.REQval('rid','').'" />
		</div>
		<div class="col-sm-3">
			<label>'.__('Search Recipe').'</label>&nbsp;<i class="fas text-primary fa-info-circle" tooltip="'.__('You can do a Wildcard search using *<br>e.g. abc* will match recipe starting with abc').'"></i>
			<input type="text" class="form-control" name="rname" id="rname" size="30" value="'.REQval('rname', '').'"/> &nbsp;
		</div>
	</div>
	<div class="row mx-auto w-100 my-2">
		<div class="col-sm-12 sm_space text-center"><input type="submit" class="go_btn mt-2" name="search" value="'.__('Search').'"/></div>
	</div>
</div>
</form>
</div>';

if($done){
	show_alert(__('Recipe was deleted successfully'));
}

if(empty($recipe)){
	optREQ('search') ? show_alert(__('No results were found for your search query'), "2") : "";
	echo '<div class="notice"><b>NOTE : </b>&nbsp; '.(optREQ('search') ? __('No results were found for your search query') : __('There are no recipes. <a href="index.php?act=addrecipe">Add a Recipe 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" id="user_task_select" class="custom-select">
							<option value="0">---</option>
							<option value="delete">'.__('Delete').'</option>
							<option value="activate">'.__('Activate').'</option>
							<option value="deactivate">'.__('Deactivate').'</option>
						</select>
					</div>
					<div class="pl-2">
						<input type="submit" id ="user_submit" class="go_btn" name="user_submit" value="'.__('Go').'" 	onclick="Delrecipe(0 ,this); return false;">
					</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 get_num_records($globals['num_res']).'
		</div>
	</div>
<form accept-charset="'.$globals['charset'].'" name="multi_recipes" id="multi_recipes" method="post" action="">
<div class="w-100 mx-auto sticky">
<table align="center" cellpadding="8" cellspacing="1" border="0" width="95%" class="table table-hover tablesorter common-table" class="form-horizontal">
<tr class="table_heading">
	<th class="z-index-1 min_width">
		'.get_checkbox('select_all', '', 'select_all', array('chk_it' => 0), '', 'select_all').'
	</th>
	<th class="min_width">'.__('ID').'</th>
	<th width="90" class="text-center">'.__('Recipe Logo').'</th>
	<th>'.__('Recipe Name').'</th>
	<th>'.__('Description').'</th>
	<th>'.__('Own By').'</th>
	<th class="min_width text-center">'.__('Status').'</th>
	<th colspan="2" class="min_width text-right pr-3">'.__('Manage').'</th>
</tr>';

$i = 1;

foreach($recipe as $k => $v){	
	if(!empty($v['status'])){  	 	 
		$status_img = '<h5 class="p-0 m-0"><a class="badge badge-success">'.__('Active').'</a></h5>';
	}else{  	 	 
		$status_img = '<h5 class="p-0 m-0"><a class="badge badge-danger">'.__('Inactive').'</a></h5>';
	}
	echo '<tr>
			<td width="2" valign="middle" align="center">
				'.get_checkbox('recipe_list[]', '', '', array('chk_it' => 0), $k).'
			</td>
			<td align="center">'.$v['rid'].'</td>
			<td align="center"><img src="'.(empty($v['logo']) ? $theme['images'].'recipes.png' : $v['logo']).'" title="'.$v['name'].'" width="32px"></td>
			<td>'.$v['name'].'</td>
			<td>'.$v['desc'].'</td>
			<td>'.$v['user'].'</td>
			<td align="center">'.$status_img.'</td>
			<td width="24" align="center">
				<div class="badge_container">
					<a class="badge badge-manage" href="'.$globals['ind'].'act=editrecipe&rid='.$k.'" title="'.__('Edit Recipe').'"><i class="fas fa-pencil-alt"></i></a>
					<a class="badge badge-trash" href="javascript:void(0);" onclick="return Delrecipe('.$k.');"  title="'.__('Delete Recipe').'"><i class="fas fa-trash"></i></a>
				</div>
			</td>
		</tr>';
	
	$i++;
}

echo '</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" id="user_task_select" class="custom-select">
						<option value="0">---</option>
						<option value="delete">'.__('Delete').'</option>
						<option value="activate">'.__('Activate').'</option>
						<option value="deactivate">'.__('Deactivate').'</option>
					</select>
                </div>
                <div class="pl-2">
					<input type="submit" id ="user_submit" class="go_btn" name="user_submit" value="'.__('Go').'" onclick="Delrecipe(0 ,this); return false;">
                </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" 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

echo '<br />
<div class="text-center my-4">
	<a href="'.$globals['ind'].'act=addrecipe" title="'.__('Add Recipe').'" class="go_btn">'.__('Add Recipe').'</a>
</div><br>';

echo '</div>';

softfooter();

}
?>