<?php
	include "db_connection/db_connection.php";
	include "config/config.php";

	if($_SESSION['admin_login_id'] == '')
	{
		echo "<script>window.location='../index.php';</script>";
	}
	
	$ot=1;
	if(isset($_GET['ot'])!=''){
		$ot = $_GET['ot'];
	}
	$check_acc  = check_access('37');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="https://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />
<title><?php echo $PROJECT_TITLE ?></title>

<link href="css/styles.css" rel="stylesheet" type="text/css" />
<link href="css/new_paging.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">

<!--[if IE]> <link href="css/ie.css" rel="stylesheet" type="text/css"> <![endif]-->

<script type="text/javascript" src="js/po_entry_add_JS.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js"></script>

<script type="text/javascript" src="js/plugins/forms/ui.spinner.js"></script>
<script type="text/javascript" src="js/plugins/forms/jquery.mousewheel.js"></script>
 
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8/jquery-ui.min.js"></script>

<script type="text/javascript" src="js/plugins/charts/excanvas.min.js"></script>
<script type="text/javascript" src="js/plugins/charts/jquery.flot.js"></script>
<script type="text/javascript" src="js/plugins/charts/jquery.flot.orderBars.js"></script>
<script type="text/javascript" src="js/plugins/charts/jquery.flot.pie.js"></script>
<script type="text/javascript" src="js/plugins/charts/jquery.flot.resize.js"></script>
<script type="text/javascript" src="js/plugins/charts/jquery.sparkline.min.js"></script>

<script type="text/javascript" src="js/plugins/tables/jquery.dataTables.js"></script>
<script type="text/javascript" src="js/plugins/tables/jquery.sortable.js"></script>
<script type="text/javascript" src="js/plugins/tables/jquery.resizable.js"></script>

<script type="text/javascript" src="js/plugins/forms/autogrowtextarea.js"></script>
<script type="text/javascript" src="js/plugins/forms/jquery.uniform.js"></script>
<script type="text/javascript" src="js/plugins/forms/jquery.inputlimiter.min.js"></script>
<script type="text/javascript" src="js/plugins/forms/jquery.tagsinput.min.js"></script>
<script type="text/javascript" src="js/plugins/forms/jquery.maskedinput.min.js"></script>
<script type="text/javascript" src="js/plugins/forms/jquery.autotab.js"></script>
<script type="text/javascript" src="js/plugins/forms/jquery.chosen.min.js"></script>
<script type="text/javascript" src="js/plugins/forms/jquery.dualListBox.js"></script>
<script type="text/javascript" src="js/plugins/forms/jquery.cleditor.js"></script>
<script type="text/javascript" src="js/plugins/forms/jquery.ibutton.js"></script>
<script type="text/javascript" src="js/plugins/forms/jquery.validationEngine-en.js"></script>
<script type="text/javascript" src="js/plugins/forms/jquery.validationEngine.js"></script>

<script type="text/javascript" src="js/plugins/uploader/plupload.js"></script>
<script type="text/javascript" src="js/plugins/uploader/plupload.html4.js"></script>
<script type="text/javascript" src="js/plugins/uploader/plupload.html5.js"></script>
<script type="text/javascript" src="js/plugins/uploader/jquery.plupload.queue.js"></script>

<script type="text/javascript" src="js/plugins/wizards/jquery.form.wizard.js"></script>
<script type="text/javascript" src="js/plugins/wizards/jquery.validate.js"></script>
<script type="text/javascript" src="js/plugins/wizards/jquery.form.js"></script>

<script type="text/javascript" src="js/plugins/ui/jquery.collapsible.min.js"></script>
<script type="text/javascript" src="js/plugins/ui/jquery.breadcrumbs.js"></script>
<script type="text/javascript" src="js/plugins/ui/jquery.tipsy.js"></script>
<script type="text/javascript" src="js/plugins/ui/jquery.progress.js"></script>
<script type="text/javascript" src="js/plugins/ui/jquery.timeentry.min.js"></script>
<script type="text/javascript" src="js/plugins/ui/jquery.colorpicker.js"></script>
<script type="text/javascript" src="js/plugins/ui/jquery.jgrowl.js"></script>
<script type="text/javascript" src="js/plugins/ui/jquery.fancybox.js"></script>
<script type="text/javascript" src="js/plugins/ui/jquery.fileTree.js"></script>
<script type="text/javascript" src="js/plugins/ui/jquery.sourcerer.js"></script>

<script type="text/javascript" src="js/plugins/others/jquery.fullcalendar.js"></script>
<script type="text/javascript" src="js/plugins/others/jquery.elfinder.js"></script>

<script type="text/javascript" src="js/plugins/ui/jquery.easytabs.min.js"></script>
<script type="text/javascript" src="js/files/bootstrap.js"></script>
<script type="text/javascript" src="js/files/functions.js"></script>

<script type="text/javascript" src="js/charts/chart.js"></script>
<script type="text/javascript" src="js/charts/hBar_side.js"></script>

<!-- Shared on MafiaShare.net  --><!-- Shared on MafiaShare.net  --></head>

<body onload="document.getElementById('addpage').focus();">

<!-- Top line begins -->
<?php include "header_footer/header.php"; ?>
<!-- Top line ends -->


<!-- Sidebar begins -->
<?php include "menus/left_menu.php"; ?>
<!-- Sidebar ends -->

<!-- Content begins -->
<div id="content">

<?php include "menus/top_menu.php"; ?>
    <!-- Breadcrumbs line -->
    <div class="breadLine">
        <div class="bc">
            <ul id="breadcrumbs" class="breadcrumbs">
                <li><a href="#">Dashboard</a></li>
                <li><a href="javascript:">Guest Request</a></li>
            </ul>
        </div>
	<?php include "menus/top_left_menu.php"; ?>

    </div>

    <!-- Main content -->
    <div class="wrapper">
	<?php 
	$disp='none';
		if(isset($_POST['sub_search1'])){
			$disp='block';
		}
		$disp_r = '25';
		if(isset($_POST['disp_rec'])!=''){
			$disp_r = $_POST['disp_rec'];
		}
		?>
<?php if($check_acc==1){?>
       <?php /*?> <ul class="middleNavR">
            <!--<li><a href="#" title="Add an article" class="tipN"><img src="images/icons/middlenav/create.png" alt="" /></a></li>
            <li><a href="#" title="Upload files" class="tipN"><img src="images/icons/middlenav/upload.png" alt="" /></a></li>-->  
          <li><a href="design_sel.php" id="addpage" title="Select New Designs" class="tipN"><img src="images/icons/middlenav/add.png" alt="" /></a></li>
            <!--<li><a href="#" title="Messages" class="tipN"><img src="images/icons/middlenav/dialogs.png" alt="" /></a><strong>8</strong></li>
            <li><a href="#" title="Check statistics" class="tipN"><img src="images/icons/middlenav/stats.png" alt="" /></a></li>-->
    	</ul> <?php */?>
    	<!-- Chart --><!-- 6 + 6 -->

    	<div class="widget"> <!--style="width:600px; margin-left:150px;"-->
        <div class="whead"><h6>Guest Request List</h6><h6 style="float:right; margin-right:5%;"><?php echo $disp_r;?> Entries</h6><div class="clear"></div>
		<div class="tablePars" style="display:<?php echo $disp;?>; padding:0px; border-top:1px solid #cdcdcd;" id="disp_search">
		<div style="float: left; margin-top: 10px;">
		<form name="cli_form" id="cli_form" action="guest_ord_req_list.php" method="post">
		<table class="table" style="font-size:12px; color:#909090" id="myTable">
            <thead>
            <tr>
            <td style="text-align:center; vertical-align:middle; width:5%;">&nbsp;</td>
            <td style="text-align:left; vertical-align:middle;width:5%; padding:0px; "><input type="text" name="party_code" id="party_code" value="<?php echo @$_POST['party_code'];?>" placeholder="Party Code" ></td>
			<td style="text-align:left; vertical-align:middle;width:5%; padding:0px; "><input type="text" name="req_date" id="req_date" value="<?php echo @$_POST['req_date'];?>" placeholder="Req.Date	" ></td>
            <td style="text-align:left; vertical-align:middle;width:5%; padding:0px;"><input type="submit" value="Submit" class="buttonM bBlack formSubmit" style="float: right; margin-left:20px;"></td>
            <td style="text-align:right; vertical-align:middle;"><select style="opacity:none; margin-right:10px;" name="disp_rec" id="disp_rec" onchange="$('#cli_form').submit();" aria-controls="dynamic" style="opacity: 0;"><option value="25" <?php if(isset($_POST['disp_rec'])=='25'){ echo "selected"; }?>>25</option><option value="50" <?php if(isset($_POST['disp_rec'])=='50'){ echo "selected"; }?>>50</option><option value="75" <?php if(isset($_POST['disp_rec'])=='75'){ echo "selected"; }?>>75</option><option value="100" <?php if(isset($_POST['disp_rec'])=='100'){ echo "selected"; }?>>100</option></select></td>
            </tr>
			</table>
		</div>
			</form>
		</div>
		</div>
        <div id="dyn" class="hiddenpars">
		<form>
        	<a href="javascript:0" id="searchlink" onfocus="foc(this.id)" onblur="stnon(this.id)" class="tOptions" title="Options" onclick="$('#disp_search').slideToggle();"><img src="images/icons/options.png" alt="" /></a>
            <table class="table table-hover table-bordered" style="width:100%; font-size:12px; color:#909090" id="myTable">
            <thead>
            <tr>
            <th width="26" style="text-align:center; vertical-align:middle;">S.No<span class="sorting" style="display: block;"></span></th>
            <th width="79" style="text-align:left; vertical-align:middle;">Party Code</th>
            <th width="79" style="text-align:center; vertical-align:middle;">Req.Date</th>
            <th width="136" style="text-align:center; vertical-align:middle;">No of Req Designs</th>
            <th width="136" style="text-align:center; vertical-align:middle;">No of Req Dies</th>
            <th width="118" style="text-align:center; vertical-align:middle;">Add Party </th>
            <th width="77" style="text-align:center; vertical-align:middle;">View</th>
			<th width="112" style="text-align:center; vertical-align:middle;">PO Approve </th>
			 <!--<th width="61">Status</th>-->
            </tr>
            </thead>
            <tbody>
            <?php
			$where ='';

			if(isset($_POST['party_code'])!=''){
				$where .= " and (ip_address='".trim($_POST['party_code'])."' or cmp_name='".trim($_POST['party_code'])."')";
			}

			if($_POST['req_date']!=''){
				$dt_arr = explode("/",trim($_POST['req_date']));
				$dt_search = $dt_arr['0']."-".$dt_arr['1']."-".$dt_arr['2'];
			$where .= " and entry_date='".trim($dt_search)."'";
			}
			$startrec = 1;

			$no_rec = $disp_r;

			if(isset($_GET['page'])!=''){
				$page=$_GET['page'];
			} else {
				$page=1;
			}
			$limX = ($page-1) * $no_rec;
			$page_id= base64_encode(base64_encode(base64_encode(2))); //THIS IS FOR PAGE IDENTIFICATION IN BL FILE for active inactive
			$bck_flg = base64_encode(base64_encode(base64_encode(1)));
			$flg1 = base64_encode(base64_encode(base64_encode(3)));

			$SLCT = "SELECT * FROM guest_user WHERE (`ip_address`!='' OR `cmp_name`!='') ".$where." ORDER BY guest_id DESC Limit ".$limX.",".$no_rec."";
			//echo $SLCT;
			$QURY = mysqli_query($connect,$SLCT);
			//$FTCH1 = mysqli_fetch_object($QURY1);
			$loop=1;

			if(mysqli_num_rows($QURY)>0)
			{
			while($FTCH = mysqli_fetch_object($QURY))
			{
				$pa_id	=	base64_encode(base64_encode(base64_encode($FTCH->party_det_id)));

				$guest_id = base64_encode(base64_encode(base64_encode($FTCH->guest_id)));

				$SLCT_dd = "SELECT IFNULL(SUM(master_pieces),'0') AS tot_pic,COUNT(*) AS sel_cnt FROM  `guest_user_details`,design_det WHERE design_det.design_det_id=guest_user_details.design_det_id AND `guest_user_id` ='$FTCH->guest_id'";
				$QURY_dd = mysqli_query($connect,$SLCT_dd);
				$FTCH_dd = mysqli_fetch_object($QURY_dd);

				$v1 = '';
				$SLCT_Ec = "SELECT * FROM  `guest_user_details` WHERE `guest_user_id` ='$FTCH->guest_id' AND ord_status = 'no'";
				//echo $SLCT_Ec."<br >";
				$QURY_Ec = mysqli_query($connect,$SLCT_Ec);
				if(mysqli_num_rows($QURY_Ec)>0)
				{
					$nu_rows = mysqli_num_rows($QURY_Ec);
					$v1 = $v1.$FTCH->guest_id.",";
				}
				else
				{
					//$v1 = $v1.$FTCH->guest_id.",";
					$nu_rows = 0;
				}
				if($loop%2 != "0")
					$bg = "fff";
				else
					$bg = "f2f2f2";
			?>
            <tr style="background-color:#<?php echo $bg ?>">
            <td align="center" style="vertical-align: middle; "><?php echo $loop ?></td>
            <td align="center" style="vertical-align: middle; "><a href="guest_user_view.php?guest_id=<?php echo base64_encode(base64_encode(base64_encode($FTCH->guest_id))); ?>" id="updlink1<?php echo $loop ?>" onfocus="foc(this.id)" onblur="stnon(this.id)"><?php if($FTCH->cmp_name != ''){ echo $FTCH->cmp_name; }else{ echo $FTCH->ip_address; } ?></a></td>
            <td align="center" style="vertical-align: middle; "><?php if($FTCH->entry_date == '' || $FTCH->entry_date == '00-00-0000'){ } else { echo str_replace("-","/",$FTCH->entry_date); } ?></td>
            <td align="center" style="vertical-align: middle; "><?php echo $FTCH_dd->sel_cnt; ?></td>            
            <td align="center" style="vertical-align: middle; "><?php echo $FTCH_dd->tot_pic; ?></td>
            <td align="center" style="vertical-align: middle; "><?php if($FTCH->cmp_name != ''){ if($FTCH->party_det_id==0){ ?><a href="bl/guest_party_BL.php?guest_id=<?php echo $guest_id; ?>" id="updlink2<?php echo $loop ?>" onfocus="foc(this.id)" onblur="stnon(this.id)">Add</a><?php }else{ echo "Added"; } } else { echo "-----"; }?></td>
            <td align="center" class="center" style="vertical-align: middle; ">
            <?php if($FTCH_dd->sel_cnt>0){ ?>
            <a href="guest_ord_req_view.php?guest_id=<?php echo base64_encode(base64_encode(base64_encode(base64_encode($FTCH->guest_id)))); ?>" id="updlink3<?php echo $loop ?>" onfocus="foc(this.id)" onblur="stnon(this.id)">View</a>
            <?php }else{ echo "---"; } ?>
            </td>
			<td align="center" class="center" style="vertical-align: middle; "><?php if($nu_rows>0)	{ 
					if($FTCH->party_det_id!=0){ ?>
 <a href="cli_ord_req_view.php?pa_id=<?php echo $pa_id ?>&bck_flg=<?php echo $bck_flg; ?>&flg=<?php echo $flg1; ?>" id="updlink4<?php echo $loop ?>" onfocus="foc(this.id)" onblur="stnon(this.id)">Approve</a><?php 
					}
					else
					{
						echo "-----"; 
					}
				}
			else
			{
				if($FTCH->party_det_id!=0)
				{
					echo "Approved"; 
				}
				else
				{
					echo "-----"; 
				}
			} ?></td>
            </tr>
            <?php
			$loop ++;
			 }
			 }
			 else { ?>
			 <tr><td colspan="10">There are no records to display.</td></tr>
				 
			<?php  }
			// To find pagination 

			$SLCT_page = "SELECT * FROM guest_user WHERE (`ip_address`!='' OR `cmp_name`!='') ".$where." ORDER BY guest_id DESC";
			$QURY_page = mysqli_query($connect,$SLCT_page);
			$total_pages= mysqli_num_rows($QURY_page);
			$num_results_on_page = '25';//$disp_r;

			$page = isset($_GET['page']) && is_numeric($_GET['page']) ? $_GET['page'] : 1;

			 ?>
            </tbody>
            </table>
			<?php if (ceil($total_pages / $num_results_on_page) > 0): ?>
			<span id="paging">
			<ul class="pagination" style="float:right;">
				<?php if ($page > 1): ?>
				<li class="prev"><a href="guest_ord_req_list.php?ot=<?php echo $ot;?>&page=<?php echo $page-1 ?>">Prev</a></li>
				<?php endif; ?>

				<?php if($page > 3): ?>
				<li class="start"><a href="guest_ord_req_list.php?ot=<?php echo $ot;?>&page=1">1</a></li>
				<li class="dots">...</li>
				<?php endif;?>

				<?php if ($page-2 > 0): ?><li class="page"><a href="guest_ord_req_list.php?ot=<?php echo $ot;?>&page=<?php echo $page-2 ?>"><?php echo $page-2 ?></a></li><?php endif; ?>
				<?php if ($page-1 > 0): ?><li class="page"><a href="guest_ord_req_list.php?ot=<?php echo $ot;?>&page=<?php echo $page-1 ?>"><?php echo $page-1 ?></a></li><?php endif; ?>

				<li class="currentpage"><a href="guest_ord_req_list.php?ot=<?php echo $ot;?>&page=<?php echo $page ?>"><?php echo $page ?></a></li>

				<?php if ($page+1 < ceil($total_pages / $num_results_on_page)+1): ?><li class="page"><a href="guest_ord_req_list.php?ot=<?php echo $ot;?>&page=<?php echo $page+1 ?>"><?php echo $page+1 ?></a></li><?php endif; ?>
				<?php if ($page+2 < ceil($total_pages / $num_results_on_page)+1): ?><li class="page"><a href="guest_ord_req_list.php?ot=<?php echo $ot;?>&page=<?php echo $page+2 ?>"><?php echo $page+2 ?></a></li><?php endif; ?>

				<?php if ($page < ceil($total_pages / $num_results_on_page)-2): ?>
				<li class="dots">...</li>
				<li class="end"><a href="guest_ord_req_list.php?ot=<?php echo $ot;?>&page=<?php echo ceil($total_pages / $num_results_on_page) ?>"><?php echo ceil($total_pages / $num_results_on_page) ?></a></li>
				<?php endif; ?>

				<?php if ($page < ceil($total_pages / $num_results_on_page)): ?>
				<li class="next"><a href="guest_ord_req_list.php?ot=<?php echo $ot;?>&page=<?php echo $page+1 ?>">Next</a></li>
				<?php endif; ?>
			</ul>
			</span>
<?php endif; ?>
		  </form>
        </div>
        </div>
        <div class="fluid"><!-- Media table --></div>
<?php } else {  echo ACCESS_MSG;} ?>
    </div>
    <!-- Main content ends -->
</div>
<!-- Content ends -->
<?php /*?><?php include "header_footer/footer.php"; ?><?php */?>
</body>
</html>
