<?php
//******************************DELETE THE DATA************START HERE************AMIT**********01-11-12**********************


if($_REQUEST['leadid']!='')
{
if($_REQUEST['Delete'])
 {
 	for($i=0;$i<count($_REQUEST['leadid']);$i++)
	{
	 
		$condition="id='".$_REQUEST['leadid'][$i]."'";
		//echo "select panel_image from approval_dot_and_panel_entry where id='".$_REQUEST['leadid'][$i]."'";
		$image=DB_query("select panel_image from approval_dot_and_panel_entry where id='".$_REQUEST['leadid'][$i]."'",$db);
		$ImageName=DB_fetch_array($image);
		@unlink("CRM/ApprovalDotEntryForm/".$ImageName['panel_image']);
		$s->DeleteRecord('approval_dot_and_panel_entry',  $condition);
		$s->pageLocation("index.php?route=CRM/view_approval_dot_panel_entry_form".$rurl);
	}
  }
}


//
//if($_REQUEST['action']=='Delete')
//{
//	$condition="id='".$_REQUEST['id']."'";
//	$image=DB_query("select panel_image from approval_dot_and_panel_entry where id='".$_REQUEST['id']."'",$db);
//	$ImageName=DB_fetch_array($image);
//	@unlink("CRM/ApprovalDotEntryForm/".$ImageName['panel_image']);
//	$s->DeleteRecord('approval_dot_and_panel_entry',  $condition);
//	$s->pageLocation("index.php?route=CRM/view_approval_dot_panel_entry_form".$rurl);
//}



if($_REQUEST['Search'])
{
	if($_REQUEST['client']!='0')
	{
		$filter[]="client_id='".$_REQUEST['client']."'";
	}
	if($_REQUEST['status']!='0')
	{
		$filter[]="status='".$_REQUEST['status']."'";
	}
	if($_REQUEST['fromdate']!='' && $_REQUEST['todate']!='')
	{
		$filter[]="document_date between '".FormatDateForSQL($_REQUEST['fromdate'])."' and '".FormatDateForSQL($_REQUEST['todate'])."'";
	}
	if($filter!='')
	{
		$filter1=implode(" and ",$filter);
		$sql="select * from approval_dot_and_panel_entry where $filter1 order by id desc";
	}
}
else
{
$sql="select * from approval_dot_and_panel_entry order by id desc";
}
?>
<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div">
<h1>Approval Dot Panel Entry Form </h1>
<div class="centre" id="slidingDiv">
<form method="post">
		<table width="100%" cellpadding="3" cellspacing="0">
		<tr class="row1">
		<td class="tabledata1">Client</td>
		<td><select style="width:150px;"  name="client">
		<option value="0">Select Client</option>
		<?php
		  $ClientSQL="Select * from clientmaster where CompanyId='".$_SESSION['ACGCompanyId']."' and  Site IN ('".$_SESSION['AssignedBranch']."') and Zone in(".$_SESSION['AssignedSites'].")";
		$ClientRes=DB_query($ClientSQL,$db);
		while($ClientRow=DB_fetch_array($ClientRes))
		{
 		?>
		<option value="<?php echo $ClientRow['id']?>" <?php echo ($_REQUEST['client']==$ClientRow['id']?'selected':'');?>><?php echo $ClientRow['c_name']?></option>
		<?php  } ?>
 	</select></td>
		<td>Status</td>
		<td><select name="status" id="status" style="width:150px;">
					<option value="0">Select Staus</option>
					<option value="approved"<?php echo($_REQUEST['status']=='approved'?'selected':''); ?>>approved</option>
					<option value="unapproved"<?php echo($_REQUEST['status']=='unapproved'?'selected':''); ?>>Unapproved</option>
					<option value="requesttoad"<?php echo($_REQUEST['status']=='requesttoad'?'selected':''); ?>>Request To AD</option>
					<option value="forfutureReference"<?php echo($_REQUEST['status']=='forfutureReference'?'selected':''); ?>>For Future Reference</option>
					<option value="dispatchtoad"<?php echo($_REQUEST['status']=='dispatchtoad'?'selected':''); ?>>Dispatch To HO</option>
					<option value="underdevelopment"<?php echo($_REQUEST['status']=='underdevelopment'?'selected':''); ?>>Under Development</option>
					<option value="sentforapproval"<?php echo($_REQUEST['status']=='sentforapproval'?'selected':''); ?>>Sent For Approval</option>
					<option value="2ndtimerequest"<?php echo($_REQUEST['status']=='2ndtimerequest'?'selected':''); ?>>2nd Time Request</option>
					<option value="resend"<?php echo($_REQUEST['status']=='resend'?'selected':''); ?>>Resend</option>
				</select></td>
		</tr>

   <tr class="row1">
   <td class="tabledata1">From</td>
   <td class="demo"><input type="text" name="fromdate" class="datepicker"  style="width:150px;" value="<?php echo $_REQUEST['fromdate'];?>"/></td>
   <td class="tabledata1">To</td>
   <td><input type="text" name="todate"  class="datepicker"  style="width:150px;"  value="<?php echo $_REQUEST['todate'];?>"/></td>
  </tr>
  
   <tr class="row1">
   <td colspan="4"><p align="center"><input type="submit" name="Search" value="Search" class="search"></p></td>
  </tr>
  
  
</table>
</form>
	</div>
<form name="myform" method="post">	
<p align="left">
<?php if($_SESSION['frmAdd']==0){ ?> 
<input type="button" name="Create" value="ADD AD" alt="Not Allowed" title="Not Allowed" class="search" />
<?php }else{?>
<a href="index.php?route=CRM/Approval_dot_panel_entry_from&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>"><input type="button" name="Create" value="ADD AD" class="search" /></a>

<?php }?>

<?php if($_SESSION['frmDelete']==0){ ?>
<input type="button" name="Delete" value="Delete" alt="Not Allowed" title="Not Allowed" class="search" />
<?php }else{?>
<input type="submit" name="Delete" value="Delete" class="search" />
<?php }?>
</p>
<table width="100%" border="1" cellpadding="3" cellspacing="0">
  <tr>
  	<td class="tabledata"><input name="leadid" type="checkbox"   id="leadid" onclick="LeadData()"    /></td>
    <td class="tabledata">Form No</td>
    <td class="tabledata">Date</td>
    <td class="tabledata">Client Name</td>
	<td class="tabledata">Shade Name</td>
   
<!--    <td class="tabledata">Panel In Date</td>
	<td class="tabledata">Panel Out Date</td>-->	
	

	<td class="tabledata">Type</td>
	<td class="tabledata">Panel In Date</td>
	<td class="tabledata">Panel Out Date</td>
	<td class="tabledata">Request Date</td>
	<td class="tabledata">In Date</td>
	<td class="tabledata">Out Date</td>
	<td class="tabledata">Executive</td>
	<td class="tabledata">Status</td>
	<td class="tabledata">Created By</td>
	<td class="tabledata">Modify By</td>
  </tr>
  <?php 
  $sql1=DB_query($sql,$db);
  $i=0;
  while($fetchArray=DB_fetch_array($sql1)) {
   ?>
<tr class="row1">
	<td style="white-space:nowrap;"><input name="leadid[]" type="checkbox" id="leadid_<?php echo $i+1; ?>"   value="<?php  echo $fetchArray['id']?>" />
	<?php if($_SESSION['frmEdit']==0){ ?>
	<img src="images/icon_edit.gif" width="12px" alt="Not Allowed" title="Not Allowed"  height="12" />
	<?php }else{ ?>
	<a href="index.php?route=CRM/Approval_dot_panel_entry_from&action=Edit&id=<?php echo $fetchArray['id']; ?>&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>"><img src="images/icon_edit.gif" width="12px"  height="12" /></a>
	<?php }?>
	
	<?php if($_SESSION['frmView']==0){ ?> 
	<img src="images/search.gif" width="12px"  height="12" />
	<?php }else{ ?>
	<a href="index.php?route=CRM/Approval_dot_panel_entry_from&action=View&id=<?php echo $fetchArray['id']; ?>&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>"><img src="images/search.gif" width="12px"  height="12" /></a>
	<?php }?>
	</td>
    <td><?php echo $fetchArray['form_no']; ?></td>
    <td><?php echo ConvertSQLDate($fetchArray['document_date']); ?></td>
    <td><?php echo $s->GetFieldValue('clientmaster',"id='".$fetchArray['client_id']."'",'c_name'); ?></td>
	    <td><?php if(is_numeric($fetchArray['shade_name'])){
	
	 echo $s->GetFieldValue('item_master',"id='".$fetchArray['shade_name']."'",'item_name'); } else {  echo $fetchArray['shade_name']; }   ?></td>
    
<!--    <td><?php echo ConvertSQLDate($fetchArray['panel_in_date']); ?></td>
	<td><?php echo ConvertSQLDate($fetchArray['panel_out_date']); ?></td>
	<td><?php echo $fetchArray['status']; ?></td>
-->	
<td><?php if($fetchArray['panel']!='' && $fetchArray['approval_dot']==''){echo 'Panel';} if($fetchArray['approval_dot']!='' && $fetchArray['panel']==''){echo 'Approval Dot';} if($fetchArray['panel']!='' && $fetchArray['approval_dot']!=''){echo 'Panel'." / ".'Approval Dot';} ?></td>


<td><?php if($fetchArray['panel_in_date']!=''){echo ConvertSQLDate($fetchArray['panel_in_date']);}else{echo 'N/A';}  ?></td>
<td><?php if($fetchArray['panel_out_date']!=''){echo ConvertSQLDate($fetchArray['panel_out_date']);}else{echo 'N/A';}  ?></td>


<td><?php if($fetchArray['request_date']!=''){echo ConvertSQLDate($fetchArray['request_date']);}else{echo 'N/A';}  ?></td>
<td><?php if($fetchArray['in_date']!=''){echo ConvertSQLDate($fetchArray['in_date']);}else{echo 'N/A';}  ?></td>
<td><?php if($fetchArray['out_date']!=''){echo ConvertSQLDate($fetchArray['out_date']);}else{echo 'N/A';}  ?></td>
<td><?php echo $s->GetFieldValue('www_users',"id='".$fetchArray['executive']."'",'userid'); ?></td>

<td><?php if($fetchArray['status']=='approved'){echo 'Approved';} if($fetchArray['status']=='unapproved'){echo 'Unapproved';}if($fetchArray['status']=='requesttoad'){echo 'Request To AD';}if($fetchArray['status']=='forfutureReference'){echo 'For Future Reference';}if($fetchArray['status']=='dispatchtoad'){echo 'Dispatch To HO';}if($fetchArray['status']=='underdevelopment'){echo 'Under Development';}if($fetchArray['status']=='sentforapproval'){echo 'Sent For Approval';}if($fetchArray['status']=='2ndtimerequest'){echo '2nd Time Request';}if($fetchArray['status']=='resend'){echo 'Resend';} ?></td>


<td><?php echo  $s->GetFieldValue('www_users',"id='".$fetchArray['created_by']."'",'userid'); ?></td>
<td><?php echo  $s->GetFieldValue('www_users',"id='".$fetchArray['modify_by']."'",'userid'); ?></td>
  </tr>
  <?php $i++;} ?>
</table>
</form>
</div>
</div>
 <script language="javascript" >
function LeadData()
{	
	myCheckboxArray = document.myform.elements["leadid[]"];
	var t=myCheckboxArray.length;
	//alert(myCheckboxArray);
	if(document.getElementById('leadid').checked==true)
	{	
	if(t==undefined)
	document.getElementById('leadid_'+1).checked=true;		
	for (var i = 1; i <= t; i++)
	{
	document.getElementById('leadid_'+i).checked=true;	
	}	
	}
	else
	{
	if(t==undefined)		
	document.getElementById('leadid_'+1).checked=false;		
	for (var i = 1; i <= t; i++)
	{
	document.getElementById('leadid_'+i).checked=false;	
	}
	}
}
</script>