<?php include("includes/config.php");
	include("includes/func.php");
	include('templates/header.php'); 
	if (($_SESSION['id'] == ""))
	{
		redirect("login");
	}
	
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
	$Delet_Rect	=	'';
	
	if(isset($_GET['action']))
	{
		$Action_Mes	=	$_GET['action'];
	}
	
	if($Action_Mes == 'delete_message')
	{
		$message_idd	=	$_GET['message_id'];
		$Sql_Mess	=	"DELETE FROM `message` WHERE `id` = $message_idd";	
		if(mysql_query($Sql_Mess))
		{
			$Delet_Rect	=	"Message Deleted Successfully";	
		}
	}

/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/		
?>
<div id="mainPanel">
	<h2><?php echo $Get_XML_Responce->readXmlArrtibut('content.xml', 'Dashboard');?></h2>
   
     <div style="text-align:left; color:green;">
    	<?php
        if ($_SESSION['msg'] != '') { 
			    print $_SESSION['msg'];
                $_SESSION['msg'] = '';
        }
		?>
    </div>  
   
   <?php if($_SESSION['usertype'] == 'Admin') {	?>
               
    <h3><?php echo $Get_XML_Responce->readXmlArrtibut('xml_dashboard.xml', 'alt_box'); ?></h3>
    <table width="100%" id="tabling1" cellpadding="0" cellspacing="0">
    	<tr>
        	<td class="col2" style="width:23%"><span class="blue"><?php echo $Get_XML_Responce->readXmlArrtibut('xml_dashboard.xml', 'alt_box_category'); ?></span></td>
            <td class="col2" style="width:23%"><span class="blue"><?php echo $Get_XML_Responce->readXmlArrtibut('xml_dashboard.xml', 'alt_Product'); ?></span></td>
            <td class="col2" style="width:18%"><span class="blue"><?php echo $Get_XML_Responce->readXmlArrtibut('xml_dashboard.xml', 'alt_threshol_value'); ?></span></td>
            <td class="col2" style="width:18%"><span class="blue"><?php echo $Get_XML_Responce->readXmlArrtibut('xml_dashboard.xml', 'alt_Current_Stock'); ?></span></td>
            <td class="col2" style="width:18%"><span class="blue"><?php echo $Get_XML_Responce->readXmlArrtibut('xml_dashboard.xml', 'alt_Difference'); ?></span></td>
        </tr>
        <tr colspan="4" id="empty_alerts"  style="display:none;"><td colspan="4"><span style="color:red;">No Alert Found!</span></td></tr>
        <?php
		$sql = "Select product.producttitle, product.currentstocklevel, product.alertcount, category.desc
		From product
		INNER JOIN `category` ON `product`.catid = `category`. id
		Where product.currentstocklevel = '0' ";
		$results = mysql_query($sql);
		if($count = mysql_num_rows($results))
		{
			while($rows = mysql_fetch_array($results))
			{
				$Difference	=	$rows["alertcount"] - $rows["currentstocklevel"];
				
				echo '<tr>';
					echo '<td class="col2">'.$rows["desc"].'</td>';
					echo '<td class="col2">'.$rows["producttitle"].'</td>';
					echo '<td class="col2">'.$rows["alertcount"].'</td>';
					echo '<td class="col2">'.$rows["currentstocklevel"].'</td>';
					echo '<td class="col2">'.$Difference.'</td>';
				echo '</tr>';
			}
		}
		else
		{
			echo "<script type='text/javascript'> document.getElementById('empty_alerts').style.display = ''; </script>";
		}
        ?>
    </table>
    <?php }?>
<!-------------------------------------------------------------------------------------------------88888888888888888----->
<?php	if($_SESSION['usertype'] == 'Admin')
	{ 	
	
	if($Delet_Rect != '')
	{
		echo "<span style='color:green'>$Delet_Rect</span>";
	}
	
	$Me		=	1;
	$Sql_M	=	"select a.*, b.* from users AS a, message as b where a.id = b.user and b.stokc_pin = 1";

	$Exe_Qyer	=	mysql_query($Sql_M);
	$Number_of_message	=	mysql_num_rows($Exe_Qyer);
	while($row_m	=	mysql_fetch_array($Exe_Qyer))
	{
		$Message_ID	=	$row_m['id'];
		$Html_M	=	$Html_M . '<tr>';
		$Html_M	=	$Html_M .  '<td>'.$Me.'</td>';
									
		
		$Html_M	=	$Html_M .  '<td>'.$row_m['firstname'].' '.$row_m['lastname'].'</td>'; 
		$Html_M	=	$Html_M .  '<td>'.$row_m['message'].'</td>';
		$Html_M	=	$Html_M .  '<td>'.$row_m['current_date'].'</td>';
			
		$Html_M	=	$Html_M .  '<td>';
		
		$Html_M	=	$Html_M .  '<a href="index.php?action=delete_message&message_id='.$Message_ID.'" onclick="return confirm(\'Are you sure want to delete this message?\');"><img src="images/delete.png" alt="Delete" /></a>';
		
		$Html_M	=	$Html_M .  '</td>';
			
		$Html_M	=	$Html_M .  '</tr>';
		
		$Me++;
		
	}
	
	
	$Header_M	=	'<table width="100%" id="tabling1" cellpadding="0" cellspacing="0">';
    	$Header_M	= 	$Header_M . '<tr>';
        	$Header_M	= 	$Header_M . '<td width="3%" class="col2"><span class="blue">#</span></td>';
        	
				$Header_M	=	$Header_M .  '<td width="15%" class="col2"><span class="blue">Name</span></td>';
				$Header_M	= 	$Header_M . '<td width="70%" class="col2"><span class="blue">Message</span></td>'; 
			
        	$Header_M	= 	$Header_M . '<td width="15%" class="col2"><span class="blue">Date</span></td>  ';
			$Header_M	= 	$Header_M . '<td width="5%" class="col2"><span class="blue">Action</span></td>  ';          
      	$Header_M	= 	$Header_M . '</tr>';
	  
	  $Footer_M	=	'</table>';
	
	  if($Number_of_message > 0){		  
		  echo "<br />";
		  echo "<h3>Message</h3>";
		  echo $Header_M;
		  echo $Html_M;
		  echo $Footer_M;
	  }
	}
	
	?>
<br />
<!-------------------------------------------------------------------------------------------88888888888888888888888888----------->	
   	<?php if($_SESSION['usertype'] == 'Admin') {	?>	 
         <div style="margin-bottom:20px"></div>
  		 <a href="order_parchase.php" class="form_button"><?php echo $Get_XML_Responce->readXmlArrtibut('xml_dashboard.xml', 'DashBoard_Create_Order'); ?></a>
    <?php }?> 
    <div style="margin-bottom:20px"></div>
    <h3><?php echo $Get_XML_Responce->readXmlArrtibut('xml_dashboard.xml', 'DashBoard_Open_Orders'); ?></h3>
    <table width="100%" id="tabling1" cellpadding="0" cellspacing="0">
    	<tr>
        	<td class="col2" style="width:45%"><span class="blue"><?php echo $Get_XML_Responce->readXmlArrtibut('xml_dashboard.xml', 'DashBoard_Order_Number'); ?> </span></td>
            <td class="col2" style="width:45%"><span class="blue"><?php echo $Get_XML_Responce->readXmlArrtibut('xml_dashboard.xml', 'DashBoard_Order_date'); ?></span></td>
            <td class="col2" style="width:10%"><span class="blue"><?php echo $Get_XML_Responce->readXmlArrtibut('xml_dashboard.xml', 'DashBoard_Action'); ?></span></td>
        </tr>
        <tr colspan="3" id="empty_open_order"  style="display:none;"><td colspan="3"><span style="color:red;"><?php echo $Get_XML_Responce->readXmlArrtibut('xml_dashboard.xml', 'DashBoard_No_Open_Order_Found'); ?></span></td></tr>
        <?php
		$sql = "Select `purchaseorder`.id, `purchaseorder`.OrderNo, `purchaseorder`.orderdate
		From `purchaseorder`
		Where `purchaseorder`.orderstatusid = (Select id From orderstatus Where status = 'Open')  ORDER BY `id`  DESC";
		
		$results = mysql_query($sql);
		if($count = mysql_num_rows($results))
		{
			while($rows = mysql_fetch_array($results))
			{	
				echo '<tr>';
					echo '<td class="col2">'.$rows["OrderNo"].'</td>';
					echo '<td class="col2">'.$rows["orderdate"].'</td>';
					echo '<td class="col2"><a href="edit_order_purchase.php?id='.$rows["id"].'" class="form_button">'.$Get_XML_Responce->readXmlArrtibut('xml_dashboard.xml', 'DashBoard_Detail').'</a>';
					  if($_SESSION['usertype'] == 'Admin'){  	
					  				echo '<a href="edit_order_purchase_all.php?id='.$rows["id"].'" class="form_button">'.$Get_XML_Responce->readXmlArrtibut('xml_dashboard.xml', 'DashBoard_Edit').'</a></td>';
					  }
				echo '</tr>';
			}
		}
		else{
			echo "<script type='text/javascript'> document.getElementById('empty_open_order').style.display = ''; </script>";
		}
        ?>
    </table>
    <div style="margin-bottom:20px"></div>
   <?php if($_SESSION['usertype'] == 'Admin') {	?> 
    <h3><?php echo $Get_XML_Responce->readXmlArrtibut('xml_dashboard.xml', 'DashBoard_Archived_Orders'); ?></h3>
    <table width="100%" id="tabling1" cellpadding="0" cellspacing="0">
    	<tr>
        	<td class="col2" style="width:30%"><span class="blue"><?php echo $Get_XML_Responce->readXmlArrtibut('xml_dashboard.xml', 'DashBoard_Order_Number'); ?> </span></td>
            <td class="col2" style="width:30%"><span class="blue"><?php echo $Get_XML_Responce->readXmlArrtibut('xml_dashboard.xml', 'DashBoard_Order_date'); ?></span></td>
            <td class="col2" style="width:30%"><span class="blue"><?php echo $Get_XML_Responce->readXmlArrtibut('xml_dashboard.xml', 'DashBoard_User_Name'); ?></span></td>
            <td class="col2" style="width:10%"><span class="blue"><?php echo $Get_XML_Responce->readXmlArrtibut('xml_dashboard.xml', 'DashBoard_Action'); ?></span></td>
        </tr>
        <tr colspan="3" id="empty_achived_order"  style="display:none;"><td colspan="3"><span style="color:red;"><?php echo $Get_XML_Responce->readXmlArrtibut('xml_dashboard.xml', 'DashBoard_No_Archived_Order_Found'); ?></span></td></tr>
        <?php
		$sql = "Select `purchaseorder`.id, `purchaseorder`.OrderNo, `purchaseorder`.orderdate, users.username
		From `purchaseorder`
		Inner Join users ON purchaseorder.ordercreatedby = users.id
		Where `purchaseorder`.orderstatusid = (Select id From orderstatus Where status = 'Closed')  ORDER BY `id`  DESC";
		
		$results = mysql_query($sql);
		if($count = mysql_num_rows($results))
		{
			while($rows = mysql_fetch_array($results))
			{	
				echo '<tr>';
					echo '<td class="col2">'.$rows["OrderNo"].'</td>';
					echo '<td class="col2">'.$rows["orderdate"].'</td>';
					echo '<td class="col2">'.$rows["username"].'</td>';
					echo '<td class="col2"><a href="edit_order_purchase.php?id='.$rows["id"].'&status=closed" class="form_button">'.$Get_XML_Responce->readXmlArrtibut('xml_dashboard.xml', 'DashBoard_Detail').'</a>';
				echo '</tr>';
			}
		}
		else{
			echo "<script type='text/javascript'> document.getElementById('empty_achived_order').style.display = ''; </script>";
		}
        ?>
    </table>
   <?php } ?> 
</div>
<?php include('templates/footer.php'); ?>