<?php

//////////////////////////////////////////////////////////////
//===========================================================
// dnsrecords_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 dnsrecords_theme(){

global $theme, $globals, $kernel, $user, $l, $cluster, $error, $servers, $done, $pdnsid, $dns_records, $pdns;

softheader($l['<title>']);

echo page_header(__('DNS Records'), 'fas fa-passport', '', 1, 0);

$breadcrumbs = ['dashboard', 'lm_pdns', 'lms_dnsrecords'];

echo get_breadcrumb($breadcrumbs);

error_handle($error);

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

function Deldnsrec(id ,ele){

	id = id || 0;
	
	// List of ids to delete
	var dnsrec_list = new Array();
	
	if(id < 1){
		
		if($(ele).parent().prev().find("select").val() != 1){
			showalert("'.__J('No Action Selected !').'" ,"1");
			return false;
		}
		
		$(".ios:checked").each(function() {
			dnsrec_list.push($(this).val());
		});
		
	}else{
		
		dnsrec_list.push(id);
		
	}
	
	if(dnsrec_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["del"] = dnsrec_list.join(",");
			
			//alert(finalData);
			//return false;
			
			$("#progress_bar").show();
			
			$.ajax({
				type: "POST",
				url: "'.$globals['index'].'act=dnsrecords&pdnsid='.$pdnsid.'&api=json",
				data : finalData,
				dataType : "json",
				success: function(data){
					$("#progress_bar").hide();
					if("done" in data){
						showalert("'.__J('The action was completed successfully. Reloading the Page !').'");
					}
					if("error" in data){
						showalert(data["error"] ,"1");
					}
					$("#alert-modal").on("hidden.bs.modal", function (e) {
					location.reload(true);
					});
				},
				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($dns_records) && !empty($globals['showsearch'])) ? "" : "none").';">
<form accept-charset="'.$globals['charset'].'" name="dnsrecords" method="GET" action="" class="form-horizontal">
<input type="hidden" name="act" value="dnsrecords">
<input type="hidden" name="pdnsid" value="'.$pdnsid.'">
<div class="form-group_head">
<div class="row mx-auto w-100">
	<div class="col-sm-4"><label>'.__('Zone ID').'</label>
	<input type="text" class="form-control" name="domain_id" id="domain_id" size="30" value="'.REQval('domain_id', '').'" /></div>
	<div class="col-sm-4"><label>'.__('Name').'</label>
	<input type="text" class="form-control" name="dns_name" id="dns_name" size="30" value="'.REQval('dns_name', '').'" /></div>
	<div class="col-sm-4"><label>'.__('RDNS IP').'</label>
	<input type="text" class="form-control" name="rdns_ip" id="rdns_ip" size="30" value="'.REQval('rdns_ip', '').'" /></div>
</div>
<div class="row mx-auto w-100">
	<div class="col-sm-4"><label>'.__('Domain').'</label>
	<input type="text" class="form-control" name="dns_domain" id="dns_domain" size="30" value="'.REQval('dns_domain', '').'" /></div>
	<div class="col-sm-4"><label>'.__('Record Type').'</label>
	<select name="record_type" class="custom-select" id="record_type" value="'.POSTselect('record_type', '').'">
		<option value="0">---</option>
		<option name="soa_record" id="soa_record" value="SOA" '.REQselect('record_type', 'SOA').'>SOA</option>
		<option name="ptr_record" id="ptr_record" value="PTR" '.REQselect('record_type', 'PTR').'>PTR</option>
		<option name="a_record" id="a_record" value="A" '.REQselect('record_type', 'A').'>A (host)</option>
		<option name="cname_record" id="cname_record" value="CNAME" '.REQselect('record_type', 'CNAME').'>CNAME (Aliases)</option>
		<option name="mx_record" id="mx_record" value="MX" '.REQselect('record_type', 'MX').'>MX (Mail Exchange)</option>
		<option name="txt_record" id="txt_record" value="TXT" '.REQselect('record_type', 'TXT').'>TXT (Text)</option>
		<option name="ns_record" id="ns_record" value="NS" '.REQselect('record_type', 'NS').'>NS (Name Servers)</option>
		<option name="aaaa_record" id="aaaa_record" value="AAAA" '.REQselect('record_type', 'AAAA').'>AAAA (IPV6 Hosts)</option>
	</select>
     </div>
</div>
<div class="row mx-auto w-100 my-2">
   <div class="col-sm-12 text-center">
		<input type="submit" name="search" value="'.__('Search').'" class="go_btn mt-2"/>
   </div>
</div>
</div>
</form>
</div>';

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

if(empty($dns_records)){
	
	if(empty($error) && 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 DNS Records.<a href="index.php?act=add_dnsrecord&pdnsid=">Add a DNS Record now</a>')).'</div>';
	
}
else{
echo'<div class="row mx-auto w-100">
	<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 get_num_records($globals['num_res']);
	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="dnsrec_task_select" id="dnsrec_task_select" class="custom-select">
						<option value="0">---</option>
						<option value="1">'.__('Delete').'</option>
					</select>
                </div>
                <div class="pl-2">
					<input type="submit" id ="domains_submit" class="go_btn" name="domains_submit" value="'.__('GO').'" onclick="Deldnsrec(0 ,this); return false;">
                </div>
            </div>
		</div>
	</div>
</div>
<form accept-charset="'.$globals['charset'].'" name="multi_dnsrec" id="multi_dnsrec" method="post" action="" class="form-horizontal">
<div class="w-100 mx-auto sticky">
	<table align="center" cellpadding="10" cellspacing="1" border="0" width="95%" class="table table-hover tablesorter">
		<tr>
			<th align="center" class="min_width">'.__('ID').'</th>
			<th align="center">'.__('Name').'</th>
			<th align="center">'.__('Domain').'</th>
			<th align="center">'.__('Type').'</th>
			<th align="center">'.__('TTL').'</th>
			<th align="center">'.__('Priority').'</th>
			<th align="center" width="10" class="min_width">'.__('Manage').'</th>
			<th class="z-index-1 min_width">
				'.get_checkbox('select_all', '', 'select_all', array('chk_it' => 0), '', 'select_all').'
			</th>	
		<tr>';
	$i = 1;

	foreach($dns_records as $k => $v){
		
		echo '<tr>
			<td align="left">'.$v['id'].'</td>
			<td>'.$v['name'].'</td>
			<td>'.$v['content'].'</td>
			<td align="center">'.$v['type'].'</td>
			<td align="center">'.$v['ttl'].'</td>
			<td align="center">'.(empty($v['prio']) ? '0' : $v['prio']).'</td>
			<td align="center">
				<div class="badge_container">
					<a class="badge badge-settings" href="'.$globals['index'].'act=add_dnsrecord&pdnsid='.$pdnsid.'&edit='.$v['id'].'&domain_id='.$_GET['domain_id'].'" title="'.__('Edit').'">
						<i class="fas fa-pencil-alt"></i>
					</a>
					'.(strtolower($v['type']) == 'soa' ? '' : '<a class="badge badge-trash" href="javascript:void(0);" onclick="return Deldnsrec('.$k.');" title="'.__('Do you want to delete this rDNS record?').'"><i class="fas fa-trash"></i></a>').'
				</div>
			</td>
			<td width="20" valign="middle" align="center">
				'.(strtolower($v['type']) == 'soa' ? '' : get_checkbox('dnsrec_list[]', '', '', array('chk_it' => 0), $k)).'
			</td>
		</tr>';
		$i++;
	}
echo '</table>
</div>
</form>
<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="dnsrec_task_select" id="dnsrec_task_select" class="custom-select" >
						<option value="0">---</option>
						<option value="1">'.__('Delete').'</option>
					</select>
                </div>
                <div class="pl-2">
					<input type="submit" id ="domains_submit" class="go_btn" name="domains_submit" value="'.__('GO').'" onclick="Deldnsrec(0 ,this); return false;">
                </div>
            </div>
		</div>
	</div>
</div>
<div class="text-center my-4">
	<a href="'.$globals['ind'].'act=add_dnsrecord&pdnsid='.$pdnsid.'&domain_id='.$_GET['domain_id'].'" class="go_btn">'.__('Add record').'</a>
</div>

<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>

<br />';
}

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

}

?>