<?php  
session_start(); 
	include("connect.php");	
	include("connectp.php");
	header("Access-Control-Allow-Origin: *");

		$q = $db7->prepare("select * from res_item_master");
	//$q->bindValue(':p1', "$par1");
	//$q->bindValue(':p2',  "$par2");
	$q->execute();
	
	
	
	
	$response = array();
	$posts = array();
	
	$result="0";
	
	if ($q->rowCount() > 0)
	{
		$i=1;
		while($i<=$q->rowCount())
		{
			$rt = $q->fetch(PDO::FETCH_ASSOC);
			
			 	$itemid=$rt['itemmid'];
				
				 $uedit="<a href='itemedit.php?id=".$rt['itemmid']."' data-toggle='tooltip' data-placement='top' title='Edit' class='fa fa-edit fa-lg'>  </a>"; 
			
			
				 $udelete="<a href='itemdelete.php?id=".$rt['itemmid']."' onclick='return confirm(&#39;Are you sure you want to delete ?&#39;);' data-toggle='tooltip' data-placement='top' title='Delete' class='far fa-trash-alt fa-lg'>  </a>"; 
				
				
				 $view="<a href='itemdetail.php?id=".$rt['itemmid']."' data-toggle='tooltip' data-placement='top' title='View' class='fa fa-eye fa-lg' >  </a>"; 
				
				$duplicate="<form action='itemadd.php' method='post' style='flex: 1; margin-right: 2px;'><button  class='fa fa-clone fa-lg' name='itemid' type='submit' value='$itemid'></button></form> ";
				$duplicate="";
				/* $duplicate="<a href='itemadd.php?id=".$rt['itemid']."' data-toggle='tooltip' data-placement='top' title='Duplicate' class='fa fa-clone' >  </a>"; */
				
				$op=$uedit."&nbsp;&nbsp; ".$udelete;
				
		
				$itemname=$rt['itemname'];
				
				$itemunit=$rt['itemunit'];
				
				$itemdetail=$rt['itemdetail'];
				
				
						

				
				$posts[] = array('srno'=> $i++,'itemname'=> $itemname, 'iunitmaster'=> $itemunit, 'itemdetail'=> $itemdetail, 'op'=> $op);
		}
		 
		$response['posts'] = $posts;
		echo stripslashes(json_encode( array('data' => $posts)));
		//mysqli_close($conn);
		//return;
	}
	
   else
	{
		$result="0";
		$msg="Invalid Error";
		
		$posts[] = array('p1'=> $result,'p2'=> $msg);
	
		$response['posts'] = $posts;
		echo stripslashes(json_encode( array('item' => $posts)));
	}
   
	mysqli_close($conn);	
?>