<?php

//////////////////////////////////////////////////////////////
//===========================================================
// vs_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 mediagroups_theme(){

global $theme, $globals, $cluster, $user, $oslist, $ostemplates, $distros, $l, $error, $mediagroups, $servers, $done, $deleted;

softheader($l['<title>']);
					
echo '<script language="javascript" type="text/javascript"><!-- // --><![CDATA[

function Delmediagrp(mgid ,ele){

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

// ]]></script>

';

$buttons = array(
	0 => array(
		'name' => __('Add Media Group'),
		'act'  => 'addmg'
	)
);

$GLOBALS['breadcrumbs'] = ['dashboard', 'lm_mediagroups', 'lms_mediagroups'];

echo page_header(__('Media Groups'), 'fas fa-compact-disc','', 1, 0,$buttons);

echo '<div class="card p-2 mx-3">';

error_handle($error);

if(!empty($done)){
	show_alert(__('The Media Group has been deleted successfully'));
}

if(!empty($deleted)){
	show_alert(__('The Media Group has been deleted'), "2");
	echo '<div class="notice"><b>NOTE : </b>&nbsp; '.__('The Media Group has been deleted').'</div>';
}

echo '<div id="showsearch" style="display:'.(optREQ('search') || (!empty($mediagroups) && !empty($globals['showsearch'])) ? "" : "none").';">
<form accept-charset="'.$globals['charset'].'" name="ippool" method="GET" action="" class="form-horizontal">
<input type="hidden" name="act" value="mediagroups">
		
<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="mgid" id="mgid" size="25" value="'.REQval('mgid','').'"/></div>
		<div class="col-sm-3"><label>'.__('Group Name').'</label><input type="text" class="form-control" name="mg_name" id="mg_name" size="25" value="'.REQval('mg_name','').'"/></div>
	</div>
	<div class="row mx-auto w-100">
		<div class="col-sm-12 sm_space mt-3 text-center"><button type="submit" name="search" class="go_btn mt-2" value="Search"/>'.__('Search').'</button></div>
	</div>
</div>
</form>
</div>';

if(empty($mediagroups)){
	show_alert((optREQ('search') ? __('No results were found for your search query') : __('There are no Media Groups. <a href="index.php?act=addmg">Add a Media Group now</a>')), "2");
	echo '<div class="notice"><b>NOTE : </b>&nbsp; '.(optREQ('search') ? __('No results were found for your search query') : __('There are no Media Groups. <a href="index.php?act=addmg">Add a Media Group 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 class="custom-select" name="mediagrp_task_select" id="mediagrp_task_select">
							<option value="0">---</option>
							<option value="1">'.__('Delete').'</option>
						</select>
					</div>
					<div class="pl-2">
						<input type="submit" id ="mediagrp_submit" class="go_btn" name="mediagrp_submit" value="'.__('Go').'" onclick="Delmediagrp(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_mediagrp" id="multi_mediagrp" 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 align="center" class="min_width">'.__('Type').'</th>
	<th align="center">'.__('Name').'</th>
	<th align="center">'.__('Description').'</th>
	<th align="center">'.__('Templates').'</th>
	<th align="center" colspan="2" class="min_width">'.__('Manage').'</th>
</tr>';

$i = 1;

foreach($mediagroups as $k => $v){

echo '<tr>
	<td width="20" valign="middle" align="center">
		'.get_checkbox('mediagrp_list[]', '', '', array('chk_it' => 0), $k).'
	</td>
	<td align="center">'.$k.'</td>
	<td align="center"><script>document.write(show_virtname("'.$v['mg_type'].(empty($v['hvm']) ? '' : 'hvm').'"));</script></td>
	<td>'.$v['mg_name'].'</td>
	<td>'.$v['mg_desc'].'</td>
	<td>'.(empty($v['mg_media']) ? '<em>'.__('None').'</em>' : implode(', ', $v['mg_media'])).'</td>
	<td align="center" width="24">
		<div class="badge_container">
			<a class="badge badge-manage" href="'.$globals['ind'].'act=editmg&mgid='.$k.'" title="'.__('Edit').'"><i class="fas fa-pencil-alt"></i></a>
			<a class="badge badge-trash" href="javascript:void(0);" onclick="return Delmediagrp('.$k.');" title="'.__('Delete').'"><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 class="custom-select" name="mediagrp_task_select" id="mediagrp_task_select">
						<option value="0">---</option>
						<option value="1">'.__('Delete').'</option>
					</select>
                </div>
                <div class="pl-2">
					<input type="submit" id ="mediagrp_submit" class="go_btn" name="mediagrp_submit" value="'.__('Go').'" onclick="Delmediagrp(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>
<div class="text-center my-4">
	<a href="'.$globals['ind'].'act=addmg" class="go_btn">'.__('Add Media Group').'</a>
</div>
<br/>';

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

}

