<?php 
if($_REQUEST['Delete'])
{
	for($i=0;$i<count($_REQUEST['leadid']);$i++)
	{
	$condition="id='".$_REQUEST['leadid'][$i]."'";
	$s->DeleteRecord('crm_dot_request_form', $condition);
	}
	$s->pageLocation("index.php?route=CRM/view_dot_request_form".$rurl);
}



if($_REQUEST['Search'])
{
	if($_REQUEST['client']!='')
	{
		$filter[]="client='".$_REQUEST['client']."'";
	}
	if($_REQUEST['fromdate']!='' && $_REQUEST['todate']!='')
	{
		$filter[]="form_date between '".FormatDateForSQL($_REQUEST['fromdate'])."' and '".FormatDateForSQL($_REQUEST['todate'])."'";
	}
	if($filter!='')
	{
		$filter1=implode(" and ",$filter);
		$sql="select * from crm_dot_request_form where $filter1 order by id desc";
	}
}


else
{
$sql="select * from crm_dot_request_form order by id desc";
}
?>
 <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>
<link rel="stylesheet" href="css/new_mxerp.css">
<div class="body_contain">
<div class="tab_div">
<h1>Dot Sample Request Form</h1>
<form method="post" name="myform">
<div class="centre" id="slidingDiv">

<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>
		</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>
  <tr class="row1">
  	<td colspan="4"><p align="left">
	<?php if($_SESSION['frmAdd']==0){ ?> 
	<input type="button" value="Sample Request Entry" alt="Not Allowed" title="Not Allowed" class="search" />
	<?php }else{?>
	<a href="index.php?route=CRM/dot_request_form&modid=<?php echo $_REQUEST['modid'];?>&frmid=<?php echo $_REQUEST['frmid'];?>&NewRequisition=Yes"><input type="button" value="Sample Request Entry" class="search" /></a>
	<?php }?>
	<?php if($_SESSION['frmDelete']==0){ ?> 
	<input type="button" name="Delete" alt="Not Allowed" title="Not Allowed" value="Delete" class="search" />
	<?php }else{?>
	<input type="submit" name="Delete"  value="Delete" class="search" />
	<?php }?>
	</p>
</td>
  </tr>
</table>

</div>

<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">Executive</td>
    <td class="tabledata">Shade Name</td>
    <td class="tabledata">Dot In Date</td>
	<td class="tabledata">Dot Out Date</td>
	<td class="tabledata">Status</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/dot_request_form&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" alt="Not Allowed" title="Not Allowed"  height="12" />
	<?php }else{ ?>
	
		<a href="index.php?route=CRM/dot_request_form&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['form_date']); ?></td>
    <td><?php echo $s->GetFieldValue('clientmaster',"id='".$fetchArray['client']."'",'c_name'); ?></td>
    <td><?php echo $s->GetFieldValue('www_users',"id='".$fetchArray['executive']."'",'userid'); ?></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['dot_in_date']); ?></td>
	<td><?php echo ConvertSQLDate($fetchArray['dot_out_date']); ?></td>
	<td><?php echo $fetchArray['status']; ?></td>
  </tr>
  <?php $i++;} ?>
</table>
</form>
</div>
</div>
