<?php global $wpdb;global $iris_db; 
 $getss=$wpdb->query("SHOW TABLES LIKE 'gdpr_website_setting'");
if($getss==0){
$wpdb->query("CREATE TABLE `gdpr_website_setting` (
  `id` int(11) NOT NULL,
  `website` varchar(40) DEFAULT NULL,
  `enable` varchar(10) DEFAULT NULL,
  `datetime` timestamp NULL DEFAULT CURRENT_TIMESTAMP
) ENGINE=MyISAM DEFAULT CHARSET=utf8");
	$wpdb->query("ALTER TABLE `gdpr_website_setting` ADD PRIMARY KEY(`id`)");
	$wpdb->query("ALTER TABLE `gdpr_website_setting` CHANGE `id` `id` INT(11) NOT NULL AUTO_INCREMENT;");
	$wpdb->query("insert into gdpr_website_setting (`website`,`enable`) values('".$_SERVER['SERVER_NAME']."','yes')");
}

if($_POST){
	
	$qry=$wpdb->get_row("select id from gdpr_website_setting where website='".$_POST['website']."'");
	if($qry->id!=''){
		//updating old data
		$up_qry2=$wpdb->query("update gdpr_website_setting set `website`='".$_POST['website']."',`enable`='".$_POST['enable']."'");
		$up_qry=$iris_db->query("update gdpr_website_setting set `website`='".$_POST['website']."',`enable`='".$_POST['enable']."'");
		if($up_qry){
			header("location:admin.php?page=gdpr-settings&&status=Data Updated!");
		}
		else {
			header("location:admin.php?page=gdpr-settings&&status=Error in Data Updates!");
		}
	}
	else{
		//inserting new data
		$up_qry2=$wpdb->query("insert into gdpr_website_setting (`website`,`enable`) values('".$_POST['website']."','".$_POST['enable']."')");
		$up_qry=$iris_db->query("insert into gdpr_website_setting (`website`,`enable`) values('".$_POST['website']."','".$_POST['enable']."')");
		//echo "insert into gdpr_website_setting (`website`,`enable`) values('".$_POST['website']."','".$_POST['enable']."')"; exit();
		if($up_qry){
			header("location:admin.php?page=gdpr-settings&&status=Data Updated!");
		}
		else {
			header("location:admin.php?page=gdpr-settings&&status=Error in Data Updates!");
		}
	}
}
?>
<?php $get_qry=$wpdb->get_row("select `enable` from gdpr_website_setting where website='".$_SERVER['SERVER_NAME']."'");?>
<?php if(isset($_REQUEST['status'])){echo '<h2 style="width:97%; padding:1%; background-color:yellow;">'.$_REQUEST['status'].'</h2>';}?>
<h1>GDPR Cookies Settings</h1><hr>
<form action="" method="post" style="font-size:17px;">
<input type="hidden" name="website" value="<?php echo $_SERVER['SERVER_NAME']; ?>"/>
<strong>Enable GDPR Cookies</strong> <input type="checkbox" name="enable" value="yes" <?php if($get_qry->enable=='yes'){echo 'checked';} else{}?>/><input type="submit"/>
<br>
	<small>On disabled state, the prior version of cookies bar will be enabled.</small>

</form>
<hr>
	<h3>Current Status : <?php
	if($get_qry->enable=='yes'){echo 'Enable on the website.';} else{echo 'Disabled on the website';}
	?></h3>