<?php


include_once("hooks/querycontrol.php");
include_once("hooks/_config_.php");

//$control = new queryinput();
class viewControlQuery extends queryinput
{

		const NETWORKTAB = "copn_netwrk";
		const CATETAB = "cop_categ";
		const TOTALMSCATE = "to_tlct_listdt";
		const STORETAB = "copn_storbnk";
		const COUPONTAB = "copn_cpnbnks";
		const ADMINSTAB = "cpn_admstrx";
		const UKEY = "_unk_ky";
		const CPNSTORNAME = "_cpon_stor";
		const CPNNAME = "_cpon_nam";
		const FEATURED_C = '_featr_cpon';
		const CODE_C = '_cpon_codchk';
		const DEALS_C = '_deal_cpon';
		const CHRISTMAS_C = '_cpon_discnt';
		const FREESHIP_C = '_freshp_cpon';
		const TABCATEFIELD = "_cpon_categ";
		const PAGXTAB = "jrnl_adpagx";
		const blMGTABSL = "_dc_trads_dtls";
		protected $_ukey = array("_unk_ky");
		protected $_ntValue = array("netwk_nam");
		protected $_colm  = '';
		protected $_stValue = array("_stor_nam");
		protected $_ctgValue = array("cate_nam");
		protected $_totalValue = array("*");
		protected $_item;
		protected $commonHeystack = array();
	
		// make conn	
		private function connt(){
			$conf = new config();
			return $conf->_conni();
		}

		public function bImgUrlList(){
		$biminit = $this->queryBuilder($this->_totalValue, self::blMGTABSL, $this->_colm);
		$bim = '';
		while($imgdata = mysqli_fetch_array($biminit, MYSQLI_NUM)){
			$bim .= "<div class='blimg_wrap'>";
			
				$bim .= "<div class='blimg_img'>";
					$bim .= "<img src='".$_SERVER['HTTP_HOST']."/assets/shared/posts/".$imgdata[4]."' width='70' height='40'>";
				$bim .= "</div>";
				
				$bim .= "<div class='blimg_link'>";
					$bim .= "".$_SERVER['HTTP_HOST']."/assets/shared/posts/".$imgdata[4];
				$bim .= "</div>";
			
			
			$bim .= "<div class='blimg_img'>";
			$bim .= "<a href='".$_SERVER['PHP_SELF']."?confirmdelete=".$this->encrypt($imgdata[3]."::blogimgx")."' title='Delete Image'><div id='delelte'></div></a>";
			$bim .= "</div>";
			$bim .= "</div>";
		} // while
		return $bim;
	}
public function subcatelist()
	{
		$initialz = $this->queryBuilder($this->_totalValue, self::CATETAB, $this->_colm);
		$r = '';
		while($mastercategory = mysqli_fetch_array($initialz, MYSQLI_NUM))
		{
			//$r .= "<div id='msghead'>";


				$r .= "<div class='m-2 d-inline-block'>
				<input type='checkbox' class='form-check-input' name='subctag[]' value='".$mastercategory[2].':#:'.$mastercategory[8]."'> 
				<label for='".$mastercategory[2]."'>".ucwords($mastercategory[2])."</label></div>";
				
				
			//$r .= "</div>";
		} // end 1st while
		return $r;
	} // end method
	
	public function editablecatelist($key)
	{
		$initialz = $this->queryBuilder($this->_totalValue, self::CATETAB, $this->_colm);
		$r = '';
		while($mastercategory = mysqli_fetch_array($initialz, MYSQLI_NUM))
		{
			//$r .= "<div id='msghead'>";


				//$r .= "<div id='subhead'><input type='checkbox' name='subctag[]' value='".$mastercategory[2].':#:'.$mastercategory[8]."'>".$mastercategory[2]."</div>";
			$initcat = $this->queryBuilder($this->_totalValue, self::TOTALMSCATE, array("cpn_unkkid" => $key));
			
				
				$r .= "<input type='checkbox' name='subctag[]' class='form-check-input ml-3 mt-2'" ;
		
					while($catcheck = mysqli_fetch_array($initcat, MYSQLI_NUM)){
						$kyid = $catcheck;
						foreach($kyid as $kl){
							if($kl == $mastercategory[2]) { 
							 
							 $r .= "checked='checked'";
					  
							 }else{
							  //$r .= "unchecked='unchecked'";
							 } // end if
						} // end loop
					} // end while 
	
				
				$r .= "value='".$mastercategory[2].':#:'.$mastercategory[8].':#:'.$key."' >". "<p class='m-2 d-inline-block  checkbox1'>".$mastercategory[2]."</p>";
				
				
			//$r .= "</div>";
		} // end 1st while
		return $r;
	} // end method
	
		public function deleteOldCate($ids)
	{
		if(is_array($ids)){
			foreach($ids as $id){
				list($az, $bz, $mdid) = explode(":#:", $id);
				$dQuery = $this->queryDelete(self::TOTALMSCATE, array("cpn_unkkid" => $mdid));
				if($dQuery) {
				return "Recored Deleted As your wish";
				}
			}
		}else{
				$dQuery = $this->queryDelete(self::TOTALMSCATE, array("cpn_unkkid" => $ids));
				if($dQuery) {
				return "Recored Deleted As your wish";
				}
		} // end if
	}
		
	public function subcatelistValidated($nameid)
	{
		$r = '';
		if(is_array($nameid)){
		
			foreach($nameid as $vlist){
			list($name, $id) = explode(":#:", $vlist);
				
				$r .= "<div class='bg-white'><input type='checkbox' name='subctag[]' class='form-check-input d-inline-block' checked='checked' value='".$name.':#:'.$id."'>".$name."</div>";
			} // end loop
		
		}else{
		
			$getsubc = $this->queryBuilder($this->_totalValue, self::TOTALMSCATE, array("cpn_unkkid" => $nameid));
			while($subcategorylist = mysqli_fetch_array($getsubc, MYSQLI_NUM))
			{
				$r .= "<div class='bg-light'><input type='checkbox' checked='checked' class='form-check-input d-inline-block'  name='subctag[]' value='".$subcategorylist[2].':#:'.$subcategorylist[6]."'>".$subcategorylist[2]."</div>";
			} // end 2nd while
		
		} // end if
		return $r;
	} // end method

	public function PageSubCatelistValidated($nameid)
	{
		$r = '';
		if(is_array($nameid)){
		
			foreach($nameid as $vlist){
			list($name, $id) = explode(":#:", $vlist);
				   
				$r .= "<div class='alert alert-light-success color-success'><i class='bi bi-check-circle'></i>
				<input type='checkbox' name='subctag[]' checked='checked' value='".$name.':#:'.$id."'>".$name."</div>";
			} // end loop
		
		}else{
		
			$getsubc = $this->queryBuilder($this->_totalValue, self::PAGCATGTAB, array("cpn_unkkid" => $nameid));
			while($subcategorylist = mysqli_fetch_array($getsubc, MYSQLI_NUM))
			{
				$r .= "<div class='alert alert-light-success color-success'><i class='bi bi-check-circle'></i>
				<input type='checkbox' checked='checked' name='subctag[]' value='".$subcategorylist[2].':#:'.$subcategorylist[6]."'>".$subcategorylist[2]."</div>";
			} // end 2nd while
		
		} // end if
		return $r;
	} // end method
	public function adminNum()
	{

	$number = mysqli_num_rows($this->queryBuilder($this->_totalValue, self::ADMINSTAB, $this->_colm));
	return $number;
	}
			
	public function networkNum()
	{

	$number = mysqli_num_rows($this->queryBuilder($this->_ntValue, self::NETWORKTAB, $this->_colm));
	return $number;
	}
	
	public function storeNum()
	{

	$number = mysqli_num_rows($this->queryBuilder($this->_stValue, self::STORETAB, $this->_colm));
	return $number;
	}

	public function DisablestoreNum()
	{

	$number = mysqli_num_rows($this->queryBuilder($this->_stValue, self::STORETAB, array("_stor_categ" => 1)));
	return "<i style='color:#FF6600;'>(".$number."*)</i>";
	}
	
	public function categoryNum()
	{

	$number = mysqli_num_rows($this->queryBuilder($this->_ctgValue, self::CATETAB, $this->_colm));
	return $number;
	}
	
	public function couponNum()
	{

	$number = mysqli_num_rows($this->queryBuilder($this->_totalValue, self::COUPONTAB, $this->_colm));
	return $number;
	}
	

	public function storeSearchView($search)
	{

		$sinitial = mysqli_query($this->connt(),"select * from copn_storbnk where _stor_nam like '%".$search."%'");
		if(mysqli_num_rows($sinitial) != 0){
		$sView = "<table id='viewtab' style='background:#FFFCD7;'>";
			$sView .= "<tr>";
			$sView .= "<th id='inhdrid'>ID</th>";
			$sView .= "<th id='inner_head'>Name</th>";
			$sView .= "<th id='inhdrid'>Disc.</th>";
			$sView .= "<th id='inner_head'>Meta Title</th>";
			$sView .= "<th id='inner_head'>Network</th>";
			
			$sView .= "<th id='inner_head'>Enter By</th>";
			$sView .= "<th id='inhdrid'>Action</th>";
			$sView .= "</tr>";
		while($view = mysqli_fetch_array($sinitial, MYSQLI_NUM)) {
			
			$sView .= "<tr>";
			$sView .= "<td id='inrid'>".$view[1]."</td>";
			$sView .= "<td id='inner'>".$view[2]."</td>";
			$sView .= "<td id='inrid'>".$view[5]."</td>";
			$sView .= "<td id='inner'>".$view[9]."</td>";
			$sView .= "<td id='inner'>".$view[13]."</td>";
			
			$sView .= "<td id='inner'>".$view[16]."</td>";
			$sView .= "<td id='inrid'><a href='".$_SERVER['PHP_SELF']."?confirmdelete=".$this->encrypt($view[14]."::store")."' title='Delete Entry'><div id='delelte'></div></a>
			<a href='".$_SERVER['PHP_SELF']."?edtuk=".$view[14]."&rfk=".$view[15]."' title='Edit Entry'><div id='entedit'></div></a> </td>";
			$sView .= "</tr>";
		
		} // end while  
		$sView .= "</table>";
		return $sView;
		}else{
		return "<ul><p style='color:#FF0000;'>!Sorry No Store Founded...</p></ul>";
		}
		
	}
	
	private function getcateg($categ)
	{
		$l = explode(":", $categ);
		foreach($l as $k => $vl) {
		$init_vl = $this->queryBuilder($this->_totalValue, self::CATETAB, array("_frgn_ky" => $vl));
			while($clV = mysqli_fetch_array($init_vl, MYSQLI_NUM)) {
				return $clV[2];
			} // end whl
		
		} // end loop
	
	}// end method

	public function storeView()
	{
		$initial = $this->queryBuilder($this->_totalValue, self::STORETAB, $this->_colm);
		 
		 $sView = "<table id='posterlistview' class='table table-striped'>";
			$sView .= "<tr>";
			//$sView .= "<th style='font-size: 18px;'>ID</th>";
			$sView .= "<th style='font-size: 18px;'>Id</th>";
			$sView .= "<th style='font-size: 18px;'>Store</th>";
			$sView .= "<th id='inner_head'>Meta Tittle</th>";
	
			$sView .= "<th style='font-size: 18px;'>Network</th>";
			$sView .= "<th style='font-size: 18px;'>Auther</th>";
				$sView .= "<th style='font-size: 18px;'>Edit</th>";
					$sView .= "<th style='font-size: 18px;'>Delete</th>";
			$sView .= "</tr>";
		while($view = mysqli_fetch_array($initial, MYSQLI_NUM)) {
			
			$sView .= "<tr>";
			//$sView .= "<td><font face='Poppins'>".$view[1]."</font></td>";
			$sView .= "<td><font face='Poppins'>".ucwords($view[1])."</font></td>";
			$sView .= "<td class='text-left'> <font face='Poppins'>".ucwords($view[2])."</font></td>";
			$sView .= "<td id='inrid'>".$view[9]."</td>";
			//$sView .= "<td id='inner'>".$view[6]."</td>";
			
			$sView .= "<td class='text-right'> <font face='Poppins'>".ucwords($view[13])."</font></td>";
			$sView .= "<td class='text-right'> <font face='Poppins'>".ucwords($view[16])."</font></td>";
				$sView .= "<td class='text-center'><a href='".$_SERVER['PHP_SELF']."?edtuk=".$view[14]."&rfk=".$view[15]."' title='Edit Entry'>
				<span class='bi bi-pencil'></span></a></td>";
			
			$sView .= "<td class='text-center'><a href='".$_SERVER['PHP_SELF']."?confirmdelete=".$this->encrypt($view[14]."::store")."' title='Delete Entry' style='color: #fff; text-align: center;  text-decoration: none;'><span class='bi bi-trash-fill text-danger'></span></a>
			 </td>";
		
			
			$sView .= "</tr>";
		
		} // end while  
		$sView .= "</table>";
		return $sView;
		
	}
	

	public function couponsSearchView($search)
	{
		$cinitial =  mysqli_query($this->connt(),"select * from ".self::COUPONTAB." where ".self::CPNSTORNAME." like '%".$search."%' OR ".self::CPNNAME." like '%".$search."%'");
		if(mysqli_num_rows($cinitial) != 0){
		$sView = "<table id='viewtab' style='background:#FFFCD7;'>";
			$sView .= "<tr>";
			$sView .= "<th id='inhdrid'>ID</th>";
			$sView .= "<th id='inner_head'>Name</th>";
			$sView .= "<th id='inner_head'>Code</th>";
			$sView .= "<th id='inhdrid'>Disc.</th>";
			$sView .= "<th id='inner_head'>Store</th>";
			
			$sView .= "<th id='inner_head'>Enter By</th>";
			$sView .= "<th id='inhdrid'>Action</th>";
			$sView .= "</tr>";
		while($view = mysqli_fetch_array($cinitial, MYSQLI_NUM)) {
			
			$sView .= "<tr>";
			$sView .= "<td id='inrid'>".$view[1]."</td>";
			$sView .= "<td id='inner'>".$view[2]."</td>";
			$sView .= "<td id='inner'>".$view[10]."</td>";
			$sView .= "<td id='inrid'>".$view[11]."</td>";
			$sView .= "<td id='inner'>".$view[17]."</td>";
			
			$sView .= "<td id='inner'>".$view[20]."</td>";
			$sView .= "<td id='inrid'><a href='".$_SERVER['PHP_SELF']."?confirmdelete=".$this->encrypt($view[18]."::coupons")."' title='Delete Entry'><div id='delelte'></div></a>
			<a href='".$_SERVER['PHP_SELF']."?cpnuk=".$this->encrypt($view[18])."&cpfk=".$this->encrypt($view[19])."' title='Edit Entry'><div id='entedit'></div></a> </td>";
			$sView .= "</tr>";
		
		} // end while  
		$sView .= "</table>";
		return $sView;
		}else{
		return "<ul><p style='color:#FF0000;'>!Sorry No Item Founded...</p></ul>";
		}
		
	}

	public function couponsView()
	{
		$initial = $this->queryBuilder($this->_totalValue, self::COUPONTAB, $this->_colm);
		$sView = "<table id='posterlistview' class='table table-striped'>";
			$sView .= "<tr>";
			//$sView .= "<th style='font-size: 18px;'>ID</th>";
			$sView .= "<th style='font-size: 18px;'>ID</th>";
			$sView .= "<th style='font-size: 18px;'>Name</th>";
			$sView .= "<th id='inner_head'>Code</th>";
			//$sView .= "<th id='inner_head'>Page Contents</th>";
			
			//$sView .= "<th id='inner_head'>Enter By</th>";
			$sView .= "<th style='font-size: 18px;'>Store</th>";
			$sView .= "<th style='font-size: 18px;'>Edit</th>";
				$sView .= "<th style='font-size: 18px;'>Delete</th>";
			$sView .= "</tr>";
		while($view = mysqli_fetch_array($initial, MYSQLI_NUM)) {
			
			$sView .= "<tr>";
			//$sView .= "<td><font face='Poppins'>".$view[1]."</font></td>";
			$sView .= "<td><font face='Poppins'>".ucwords($view[1])."</font></td>";
			$sView .= "<td class='text-left'> <font face='Poppins'>".ucwords($view[2])."</font></td>";
			$sView .= "<td id='inrid'>".$view[10]."</td>";
			//$sView .= "<td id='inner'>".$view[6]."</td>";
			
			$sView .= "<td class='text-right'> <font face='Poppins'>".ucwords($view[17])."</font></td>";
				$sView .= "<td class='text-center'><a href='".$_SERVER['PHP_SELF']."?cpnuk=".$this->encrypt($view[18])."&cpfk=".$this->encrypt($view[19])."' title='Edit Entry'>
				<span class='bi bi-pencil'></span></a></td>";
			
			$sView .= "<td class='text-center'><a href='".$_SERVER['PHP_SELF']."?confirmdelete=".$this->encrypt($view[18]."::coupons")."' title='Delete Entry' style='color: #fff; text-align: center;  text-decoration: none;'><span class='bi bi-trash-fill text-danger'></span></a></td>";
		
			
			$sView .= "</tr>";
		
		} // end while  
		$sView .= "</table>";
		return $sView;  
		
	}
	
public function storeCouponSortView($search)
	{
		$cinitial =  mysqli_query($this->connt(),"select * from ".self::COUPONTAB." where ".self::CPNSTORNAME." like '%".$search."%' OR ".self::CPNNAME." like '%".$search."%' ORDER BY _copn_stdat ASC");
		if(mysqli_num_rows($cinitial) != 0){
				$sView = "<div class='contentLeft'>";
			$sView .= "<ul>";
		while($view = mysqli_fetch_array($cinitial, MYSQLI_NUM)) {
			
			
			$sView .= "<li id='recordsArray_".$view[1]."'>";
			$sView .= "<div id='srt_d'>".$view[1]."</div>";
			$sView .= "<div id='srt_d'>".$view[13]."</div>";
			$sView .= "<div id='srt_dtls'>".$view[2]."</div>";
			$sView .= "</li>";
			
			
		} // end while  
		$sView .= "</ul>";
		$sView .= "</div>";
		return $sView;
		}else{
		return "<ul><p style='color:#FF0000;'>!Sorry No Item Founded From This Store...</p></ul>";
		}
		
	} // medthod 
	
	public function totalIndexCoupons($needle, $m)
	{
		$couponsindexnumber = $this->queryBuilder($this->_totalValue, self::COUPONTAB, $this->viewNeedle($needle, $m));
		return mysqli_num_rows($couponsindexnumber);
	}	
		
		public function indexcouponsView($needle, $m)
	{
		$initial = $this->queryBuilder($this->_totalValue, self::COUPONTAB, $this->viewNeedle($needle, $m));
		$count = mysqli_num_rows($initial);
		$count = $count - $count +1;
		$sView = "<table id='viewtab'>";
			$sView .= "<tr>";
			$sView .= "<th id='inhdrid'>ID</th>";
			$sView .= "<th id='inhdrid'>Sort Order</th>";
			$sView .= "<th id='inner_head'>Name</th>";
			//$sView .= "<th id='inner_head'>Code</th>";
			
			$sView .= "<th id='inner_head'>Store</th>";
			
			$sView .= "<th id='inner_head'>Enter By</th>";
			$sView .= "<th id='inhdrid'>Action</th>";
			$sView .= "</tr>";
		while($view = mysqli_fetch_array($initial, MYSQLI_NUM)) {
			
			$sView .= "<tr>";
			$sView .= "<td id='inrid'>".$view[1]."</td>";
			$sView .= "<td id='inrid'>".$count++."</td>";
			$sView .= "<td id='inner'>".$view[2]."</td>";
			//$sView .= "<td id='inner'>".$view[10]."</td>";
			
			$sView .= "<td id='inner'>".$view[17]."</td>";
			
			$sView .= "<td id='inner'>".$view[20]."</td>";
			$sView .= "<td id='inrid'>
			<a href='".$_SERVER['PHP_SELF']."?cpnsortuk=".$this->encrypt($view[18])."&cpsrtfk=".$this->encrypt($view[19])."' title='Edit Sort Order'><div id='entedit'></div></a> </td>";
			$sView .= "</tr>";
		
		} // end while  
		$sView .= "</table>";
		return $sView;
		
	}
	
	private function viewNeedle($needle, $match)
	{
		if($match == '') { $match = 1; }else{ $match = stripslashes($match); }
		$col = array();
		if($needle != '' && is_string($needle) && $needle == "featured"){
			$col = array(self::FEATURED_C => $match);
			return $col;
			
		}elseif($needle != '' && is_string($needle) && $needle == "code"){
			$col = array(self::CODE_C => $match);
			return $col;
			
		}elseif($needle != '' && is_string($needle) && $needle == "deals"){
			$col = array(self::DEALS_C => $match);
			return $col;
		}elseif($needle != '' && is_string($needle) && $needle == "christmas"){
			$col = array(self::CHRISTMAS_C => $match);
			return $col;
		}elseif($needle != '' && is_string($needle) && $needle == "freeship"){
			$col = array(self::FREESHIP_C => $match);
			return $col;
		}elseif($needle != '' && is_string($needle) && $needle == "coupon_category"){
			$col = array(self::TABCATEFIELD => $match);
			return $col;
		}
		
	}

	public function categoryView()
	{
		$initial = $this->queryBuilder($this->_totalValue, self::CATETAB, $this->_colm);
		$sView = "<table id='viewtab'>";
			$sView .= "<tr>";
			$sView .= "<th id='inhdrid'>ID</th>";
			$sView .= "<th id='inner_head'>Name</th>";
			$sView .= "<th id='inner_head'>Meta Title</th>";
			$sView .= "<th id='inner_head'>Meta Descp</th>";
			$sView .= "<th id='inner_head'>M-Keywords</th>";
			
			$sView .= "<th id='inner_head'>Enter By</th>";
			$sView .= "<th id='inhdrid'>Action</th>";
			$sView .= "</tr>";
		while($view = mysqli_fetch_array($initial, MYSQLI_NUM)) {
			
			$sView .= "<tr>";
			$sView .= "<td id='inrid'>".$view[1]."</td>";
			$sView .= "<td id='inner'>".$view[2]."</td>";
			$sView .= "<td id='inner'>".$view[4]."</td>";
			$sView .= "<td id='inrid'>".$view[5]."</td>";
			$sView .= "<td id='inner'>".$view[6]."</td>";
			
			$sView .= "<td id='inner'>".$view[9]."</td>";
			$sView .= "<td id='inrid'><a href='".$_SERVER['PHP_SELF']."?confirmdelete=".$this->encrypt($view[7]."::category")."' title='Delete Entry'><div id='delelte'></div></a>
			<a href='".$_SERVER['PHP_SELF']."?cteuk=".$this->encrypt($view[7])."&catefk=".$this->encrypt($view[8])."' title='Edit Entry'><div id='entedit'></div></a> </td>";
			$sView .= "</tr>";
		
		} // end while  
		$sView .= "</table>";
		return $sView;
	}
	
	public function networkView()
	{
		$initial = $this->queryBuilder($this->_totalValue, self::NETWORKTAB, $this->_colm);
		$sView = "<table id='posterlistview' class='table table-striped'>";
			$sView .= "<tr>";
			$sView .= "<th id='inhdrid'>ID</th>";
			$sView .= "<th id='inner_head'>Name</th>";
			$sView .= "<th id='inner_head'>Auther</th>";
			$sView .= "<th id='inner_head'>Edit</th>";
			$sView .= "<th id='inner_head'>Delete</th>";
	
			$sView .= "</tr>";
		while($view = mysqli_fetch_array($initial, MYSQLI_NUM)) {
			
			$sView .= "<tr>";
			$sView .= "<td id='inrid'>".$view[1]."</td>";
			$sView .= "<td id='inner'>".$view[2]."</td>";
	       $sView .= "<td id='inner'>".$view[6]."</td>";
				$sView .= "<td class='text-center'><a href='".$_SERVER['PHP_SELF']."?ntwuqk=".$this->encrypt($view[4])."&ntwrkfrk=".$this->encrypt($view[5])."' title='Edit Entry'>
				<span class='bi bi-pencil'></span></a></td>";
			
			$sView .= "<td class='text-center'><a href='".$_SERVER['PHP_SELF']."?confirmdelete=".$this->encrypt($view[4]."::network")."' title='Delete Entry' style='color: #fff; text-align: center;  text-decoration: none;'><span class='bi bi-trash-fill text-danger'></span></a></td>";
		
		} // end while  
		$sView .= "</table>";
		return $sView;
	}
	
public function controlUserMenu($user)
	{
		$getdetail = $this->queryBuilder($this->_totalValue, self::ADMINSTAB, array("_admnnm" => $user));
		$show_menu = '';
		$numer_option = '';
	
		while($CUM = mysqli_fetch_array($getdetail, MYSQLI_NUM)) {
		
		// allow full access
		if($CUM[14] == 1) {
		$numer_option = 0;
		}else{
		$numer_option = 1;
		} // end if
		
			$show_menu .= "<div id='topleft'>User Control</div>";
			// alw str
			if($CUM[9] == $numer_option){
				$show_menu .= "<a href='".$_SERVER['PHP_SELF']."?vcv=totalstore'><div id='leftmenu'>Total Stores</div></a>";
			}
			
			// alw cpn
			if($CUM[10] == $numer_option){
				$show_menu .= "<a href='".$_SERVER['PHP_SELF']."?vcv=totalcoupons'><div id='leftmenu'>Total Coupons</div></a>";
				$show_menu .= "<a href='".$_SERVER['PHP_SELF']."?vcv=sortcoupons'><div id='leftmenu'>Sort Coupons:</div></a>";
			}
			
			// alw cat
			if($CUM[11] == $numer_option){
				$show_menu .= "<a href='".$_SERVER['PHP_SELF']."?vcv=totalcategories'><div id='leftmenu'>Total Categories</div></a>";
				//$show_menu .= "<a href='".$_SERVER['PHP_SELF']."?vcv=totalsubcatgry'><div id='leftmenu'>Edit Sub Category</div></a>";
			}
			// alw cat
			if($CUM[12] == $numer_option){
				$show_menu .= "<a href='".$_SERVER['PHP_SELF']."?vcv=totalnetwork'><div id='leftmenu'>Total Networks</div></a>";
				//$show_menu .= "<a href='".$_SERVER['PHP_SELF']."?vcv=totaltagcloud'><div id='leftmenu'>Total Tags</div></a>";
			}
				// alw blog
			if($CUM[10] == $numer_option){
				$show_menu .= "<a href='".$_SERVER['PHP_SELF']."?vcv=addpage'><div id='leftmenu'>Total/Edit Blog</div></a>";
			;
			}
	
					// end first div user control
					$show_menu .= "<a href='".$_SERVER['PHP_SELF']."?vcv=adminstat'><div id='leftmenu'>User Setting</div></a>";
					
			$show_menu .= "<div id='topleft' style='margin-top:25px;'>Menus Module</div>";
						// alw str
			if($CUM[9] == $numer_option){
				$show_menu .= "<a href='".$_SERVER['PHP_SELF']."?mdwrt=addpage'><div id='leftmenu'>Create Blog</div></a>";
				$show_menu .= "<a href='".$_SERVER['PHP_SELF']."?mdwrt=addstore'><div id='leftmenu'>Store ( ".$this->storeNum()." ) ". $this->DisablestoreNum()."</div></a>";
			}
			
			// alw cpn
			if($CUM[10] == $numer_option){
				$show_menu .= "<a href='".$_SERVER['PHP_SELF']."?mdwrt=addcoupon'><div id='leftmenu'>Coupons ( ".$this->couponNum()." ) </div></a>";
			}
			
			// alw cat
			if($CUM[11] == $numer_option){
			
			$show_menu .= "<a href='".$_SERVER['PHP_SELF']."?mdwrt=addcategories'><div id='leftmenu'>Categories ( ".$this->categoryNum()." ) </div></a>";
			//$show_menu .= "<a href='".$_SERVER['PHP_SELF']."?mdwrt=addsubcatg'><div id='leftmenu'>Add Sub Category</div></a>";
			}
			
			// alw cat
			if($CUM[12] == $numer_option){
						
			$show_menu .= "<a href='".$_SERVER['PHP_SELF']."?mdwrt=addnetwork'><div id='leftmenu'>Network  ( " .$this->networkNum()." ) </div></a>";
			}
			// alw gallery
			if($CUM[10] == $numer_option){
						
			$show_menu .= "<a href='".$_SERVER['PHP_SELF']."?mdwrt=home_slider'><div id='leftmenu'>Gallery</div></a>";
						    
			}
			
					
		} // end while
		return $show_menu;
	}// end method

	public function adminView()
	{
		$initial = $this->queryBuilder($this->_totalValue, self::ADMINSTAB, $this->_colm);
		$sView = "<table id='posterlistview' class='table table-striped'>";
			$sView .= "<tr>";
			//$sView .= "<th style='font-size: 18px;'>ID</th>";
			$sView .= "<th style='font-size: 18px;'>ID</th>";
			$sView .= "<th style='font-size: 18px;'>User</th>";
			$sView .= "<th id='inner_head'>Password</th>";
			//$sView .= "<th id='inner_head'>Page Contents</th>";
			
			//$sView .= "<th id='inner_head'>Enter By</th>";
			$sView .= "<th style='font-size: 18px;'>IP</th>";
			$sView .= "<th style='font-size: 18px;'>Auther</th>";
			$sView .= "<th style='font-size: 18px;'>Edit</th>";
				$sView .= "<th style='font-size: 18px;'>Delete</th>";
			$sView .= "</tr>";
		while($view = mysqli_fetch_array($initial, MYSQLI_NUM)) {
			
			$sView .= "<tr>";
			//$sView .= "<td><font face='Poppins'>".$view[1]."</font></td>";
			$sView .= "<td><font face='Poppins'>".ucwords($view[1])."</font></td>";
			$sView .= "<td class='text-left'> <font face='Poppins'>".ucwords($view[2])."</font></td>";
			$sView .= "<td id='inrid'>".$view[3]."</td>";
			//$sView .= "<td id='inner'>".$view[6]."</td>";
			
			$sView .= "<td class='text-right'> <font face='Poppins'>".ucwords($view[4])."</font></td>";
				$sView .= "<td class='text-right'> <font face='Poppins'>".ucwords($view[8])."</font></td>";
				$sView .= "<td class='text-center'><a href='".$_SERVER['PHP_SELF']."?amnsfrk=".$this->encrypt($view[7])."' title='Edit Entry'>
				<span class='bi bi-pencil'></span></a></td>";
			
			$sView .= "<td class='text-center'><a href='".$_SERVER['PHP_SELF']."?confirmdelete=".$this->encrypt($view[6]."::admin")."' title='Delete Entry' style='color: #fff; text-align: center;  text-decoration: none;'><span class='bi bi-trash-fill text-danger'></span></a></td>";
		
			
			$sView .= "</tr>";
		
		} // end while  
		$sView .= "</table>";
		return $sView;
	}
	
	
		
	public function encrypt($code)
	{
		$code = base64_encode(base64_encode($code));
		return $code;
	} 
	public function decrypt($code)
	{
		$code = base64_decode(base64_decode($code));
		return $code;
	} 
	private function CommonHeyStack($heystack)
	{
		$this->commonHeystack = array("_unk_ky" => $heystack);
		return $this->commonHeystack;
	}
//$needle = array("netwk_nam", "_frgn_ky");
//$tb = "copn_netwrk";
//$heystack = ''; 

	
	public function process($item)
	{
		$this->_item = $this->decrypt($item);
		if(isset($this->_item) && $this->_item != '') {
			
			list($itemcode, $tablename) = explode("::", $this->_item);
			//check existance
					if($this->gettab($tablename) == self::blMGTABSL){
			$num = $this->queryBuilder($this->_totalValue, $this->gettab($tablename), $this->CommonHeyStack($itemcode));
				while($blg_del_img = mysqli_fetch_array($num, MYSQLI_NUM)){
					unlink('../../assets/shared/posts/'.$blg_del_img[4]);
				}
			} // bimg delete	
			$num = $this->queryBuilder($this->_ukey, $this->gettab($tablename), $this->CommonHeyStack($itemcode));
				if(mysqli_num_rows($num) != 0) {
				
				$query = "DELETE FROM ".$this->gettab($tablename)." WHERE ".self::UKEY." = '".$itemcode."' LIMIT 1";
				$result = mysqli_query($this->connt(), $query) or die(mysqli_error($this->connt()));
				return "<ul><p style='color:#ff0000;'>Entry Deleted</p></ul>";
				}else{
				return "<ul><p style='color:#ff0000;'>Record Does Not Exist / Already Deleted</p></ul>";
				}
	
		}else{
			return "Error In Deletion ";
				//echo $this->get();
		}
		
	}
	
	public function gettab($name)
	{
		if(isset($name) && $name == "store"){
			$tab = self::STORETAB;
		}elseif(isset($name) && $name == "coupons") {
			$tab = self::COUPONTAB;
		}elseif(isset($name) && $name == "category") {
			$tab = self::CATETAB;
		}elseif(isset($name) && $name == "network") {
			$tab = self::NETWORKTAB;
		}elseif(isset($name) && $name == "admin") {
			$tab = self::ADMINSTAB;
		}elseif(isset($name) && $name == "blogimgx") {
			$tab = self::blMGTABSL;
		}elseif(isset($name) && $name == "addxpages") {
			$tab = self::PAGXTAB;
		}
		return $tab;
	} 

	//blog
	/*	public function addedPageView()
	{
		$initial = $this->queryBuilder($this->_totalValue, self::PAGXTAB, $this->_colm);
		$sView = "<table id='viewtab'>";
			$sView .= "<tr>";
			$sView .= "<th id='inhdrid' style='width:25px;'>ID</th>";
			$sView .= "<th id='inner_head'>Page Name</th>";
			$sView .= "<th id='inner_head' style='width:65px;'>Folder</th>";
			//$sView .= "<th id='inner_head'>Meta Keywords</th>";
			//$sView .= "<th id='inner_head'>Page Contents</th>";
			
			//$sView .= "<th id='inner_head'>Enter By</th>";
			$sView .= "<th id='inhdrid'>Action</th>";
			$sView .= "</tr>";
		while($view = mysqli_fetch_array($initial, MYSQLI_NUM)) {
			
			$sView .= "<tr>";
			$sView .= "<td id='inrid' style='width:25px;'>".$view[1]."</td>";
			$sView .= "<td id='inner'>".$view[2]."</td>";
			$sView .= "<td id='inner' style='width:65px;'>".$view[4]."</td>";
			//$sView .= "<td id='inrid'>".$view[5]."</td>";
			//$sView .= "<td id='inner'>".$view[6]."</td>";
			
			//$sView .= "<td id='inner'>".$view[9]."</td>";
			$sView .= "<td id='inrid'><a href='".$_SERVER['PHP_SELF']."?confirmdelete=".$this->encrypt($view[7]."::addxpages")."' title='Delete Entry'><div id='delelte'></div></a>
			<a href='".$_SERVER['PHP_SELF']."?apguky=".$this->encrypt($view[7])."&apgnfk=".$this->encrypt($view[8])."' title='Edit Entry'><div id='entedit'></div></a> </td>";
			$sView .= "</tr>";
		
		} // end while  
		$sView .= "</table>";
		return $sView;
	} // method blog */
	
	
	public function addedPageView()
	{
		$initial = $this->queryBuilder($this->_totalValue, self::PAGXTAB, $this->_colm);
		$sView = "<table id='posterlistview' class='table table-striped'>";
			$sView .= "<tr>";
			//$sView .= "<th style='font-size: 18px;'>ID</th>";
			$sView .= "<th style='font-size: 18px;'>Post Tittle</th>";
			$sView .= "<th style='font-size: 18px;'>Root</th>";
			$sView .= "<th id='inner_head'>Meta Keywords</th>";
			//$sView .= "<th id='inner_head'>Page Contents</th>";
			
			//$sView .= "<th id='inner_head'>Enter By</th>";
			$sView .= "<th style='font-size: 18px;'>Auther</th>";
			$sView .= "<th style='font-size: 18px;'>Edit</th>";
				$sView .= "<th style='font-size: 18px;'>Delete</th>";
			$sView .= "</tr>";
		while($view = mysqli_fetch_array($initial, MYSQLI_NUM)) {
			
			$sView .= "<tr>";
			//$sView .= "<td><font face='Poppins'>".$view[1]."</font></td>";
			$sView .= "<td><font face='Poppins'>".ucwords($view[2])."</font></td>";
			$sView .= "<td class='text-left'> <font face='Poppins'>".ucwords($view[4])."</font></td>";
			$sView .= "<td id='inrid'>".$view[5]."</td>";
			//$sView .= "<td id='inner'>".$view[6]."</td>";
			
			$sView .= "<td class='text-right'> <font face='Poppins'>".ucwords($view[9])."</font></td>";
				$sView .= "<td class='text-center'><a href='".$_SERVER['PHP_SELF']."?apguky=".$this->encrypt($view[7])."&apgnfk=".$this->encrypt($view[8])."' title='Edit Entry'>
				<span class='bi bi-pencil'></span></a></td>";
			
			$sView .= "<td class='text-center'><a href='".$_SERVER['PHP_SELF']."?confirmdelete=".$this->encrypt($view[7]."::addxpages")."' title='Delete Entry' style='color: #fff; text-align: center;  text-decoration: none;'><span class='bi bi-trash-fill text-danger'></span></a>
			 </td>";
		
			
			$sView .= "</tr>";
		
		} // end while  
		$sView .= "</table>";
		// pagination

					if (isset($_GET["page"])) {    
						  $page  = $_GET["page"];    
						}else {    
						   $page=1;    
					} 
					$total_pages = 5;
					 $sView .= "<nav aria-label='Page navigation '>";
                            $sView .= "<ul class='pagination pagination-primary  justify-content-center'>";
                                    
										if($page>=2) {
										$sView .= "<li class='page-item disabled'>";
                                   			 $sView .= "<a class='page-link' href='".$_SERVER['PHP_SELF']."?vcv=totlxpage&page=".($page-1)."' tabindex='-1' aria-disabled='true'>Previous</a>";
											 $sView .= "</li>";
										} 
                                    
									for ($i=1; $i<=$total_pages; $i++) {   
										if ($i == $page) {   
											  $sView .= "<li class='page-item active'><a class='page-link' href='".$_SERVER['PHP_SELF']."?vcv=totlxpage&page=".$i."'>".$i." </a></li>";   
										  }               
										  else  {   
											  $sView .= "<li class='page-item'><a class='page-link' href='".$_SERVER['PHP_SELF']."?vcv=totlxpage&page=".$i."'>".$i." </a></li>";     
										  }   
									}
																	//echo $sView; 
										?>
									<script type='text/javascript'>  
									function go2Page()   
									{   
											var page = document.getElementById("page").value;   
											page = ((page><?php echo $total_pages; ?>)?<?php echo $total_pages; ?>:((page<1)?1:page));   
											window.location.href = '<?php echo $_SERVER['PHP_SELF']; ?>?vcv=totlxpage&page='+page;   
									}
									</script>	
									<?php
									
										if($page<$total_pages){  
										$sView .=    " <li class='page-item'>";
                              		 		$sView .=    "<a class='page-link' href='".$_SERVER['PHP_SELF']."?page=".($page+1)."'>Next</a>";
											 $sView .= "</li>";
									 	}
                                 
                	  $sView .=    "</nav>";
							
		return $sView;
	} // method blog
		
} // end class 
?>
