 

<table width="100%" border="0" cellspacing="0" cellpadding="0" align="center">
  <tr>
    <td width="67%"><h1 style="color:#000000;" align="center"><?php  echo $page_title;?></h1></td>
  </tr>
</table>


<?php
$catid= $s->GetFieldValue('crm_picklist',"picklist_title='Leads' and status=1",'picklist_id');
$table="support_troubletickets";
 
 if($_REQUEST['Delete'])
 {
     
	for($i=0;$i<count($_REQUEST['leadid']);$i++)
	{
				$cond="mst_leadid='".$_REQUEST['leadid'][$i]."'";
			    $row= $s->DeleteRecord('crm_lead_items', $cond);
				
	 			$cond="leadid='".$_REQUEST['leadid'][$i]."'";
			    $row= $s->DeleteRecord('support_troubletickets', $cond);
	}
  }
 

 ?>
 <script language="javascript" >
function LeadData()
{	
	myCheckboxArray = document.myform.elements["leadid[]"];
	var t=myCheckboxArray.length;
	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>
 
 
  <form action="" method="post" name="myform" >
<table width="50%" border="0">
  <tr>
    <td>To:<br /><input name="todate" type="text"  class="datepicker"/></td>
	<td>From:<br /><input name="fromdate" type="text"  class="datepicker"/></td>
    <td>Status:<br /><?php $lstatus=array('Attempted to Contact','Cold','Contact in Future','Hot','Junk Lead','Lost Lead','Qualified','Not Contacted','Pre Qualified','Warm','Active','Techno commercial submitted','Negotiation going on','Proposal submitted','Negotiation done','Proposal to be submitted','Contact in Future','Contacted')?>
	<select name="lead_status"  style="width:150px;">
	<option value="0">--All--</option>	
	<?php for($k=0;$k<count($lstatus);$k++)
	{?>
	<option value="<?php  echo $lstatus[$k];?>" <?php  echo $lead_status==$lstatus[$k]?'selected':''?> ><?php  echo $lstatus[$k];?></option>
	<?php 
	}
	?>
	</select></td>
	<td><input name="Search" type="submit"  value="Search"/></td>
  </tr>
</table>
</form>

<?php
 

if($_REQUEST['Search'])
{
	$todate=ConvertSQLDate($_REQUEST['todate']);
 $fromdate=ConvertSQLDate($_REQUEST['fromdate']);
 $lead_status=$_REQUEST['lead_status'];
	
	
	if($_REQUEST['todate']!='' && $_REQUEST['fromdate']!='' )
	{
		$filter[]="leads_date between '".$todate."' and '".$fromdate."'";
	}
 	if($_REQUEST['lead_status']!='0')
	{
		$filter[]="lead_status='".$lead_status."'";
		
	}
    if($_REQUEST['lead_status']=='0')
	{
		$getlead=DB_query( "select * from support_troubletickets where (groupid ='".$_SESSION['ACGRoleId']."' or created_by in(".$user_ids.") ) and Convert_IntoAccountStatus='N' and  deleted_status='N' and CompanyId='".$_SESSION['ACGCompanyId']."'",$db);
	}
if($filter!='')
{
	$filter1=implode(" and ",$filter);
    $GetLead="select * from support_troubletickets where (groupid ='".$_SESSION['ACGRoleId']."' or created_by in(".$user_ids.") ) and Convert_IntoAccountStatus='N' and  deleted_status='N' and CompanyId='".$_SESSION['ACGCompanyId']."' and $filter1 ";
	 
	 $getlead=DB_query( "select * from support_troubletickets where (groupid ='".$_SESSION['ACGRoleId']."' or created_by in(".$user_ids.") ) and Convert_IntoAccountStatus='N' and  deleted_status='N' and CompanyId='".$_SESSION['ACGCompanyId']."' and $filter1 " ,$db);
	
	 
}}
else
{
 	echo "select * from support_troubletickets where  1=1 and  CompanyId='".$_SESSION['ACGCompanyId']."'";
       $getlead=DB_query("select * from support_troubletickets where  1=1 and  CompanyId='".$_SESSION['ACGCompanyId']."'",$db);
 }
 

  
?><br />
 
 <form action="" method="post" name="myform" >
 <table width="100%" border="0" align="center" cellspacing="1" cellpadding="2">
 <tr>
 <td style="padding-left:5px; color:#666666; font-size:16px; padding-bottom:5px;margin-bottom:5px;"> <strong>Actions</strong></td>
 <td colspan="9" style="padding-left:50px;">
 
 <table  border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td>        <a href="<?php echo "index.php?route=Support/TroubleTicket".$rurl.'&action=AddNew'?>"><input type="button" name="Create" value="Add" style="background-color:#d1d4be; color:#006699; font-weight:800; padding-top:3px; padding-bottom:3px;" /></a></td>
<td>		 <input type="submit" name="Delete" value="Delete" style="background-color:#d1d4be; color:#FF0000; padding-top:3px; padding-bottom:3px;" /></td>
<?php 
if($_REQUEST['Search'])
{?>
    <td>	
	<a href="leads_exp.php"><input type="button" name="Export" value="Export" style="background-color:#d1d4be; color:#006699; font-weight:800; padding-top:3px; padding-bottom:3px;" /></a></td>
	<?php }?>
</tr>
</table> </td>
 </tr>

 <tr>
 <td colspan="9" style="height:10px;"></td>
 </tr>

  <tr  bgcolor="#CCCCCC" height="25px;" style="font-weight:bold;">
  <td  ><input name="leadid" type="checkbox"   id="leadid" onclick="LeadData()"    />  </td>
	<td width="170"><center>
	  Ticket No
	</center></td>
		 
	<td width="173"><center>
	  Title
	</center></td>
	<td width="188"><center>
	  Product Name 
	</center></td>
	<td width="257"><center>
	  Status
	</center>	</td>
	<td width="163"><center>
	  Priority
	</center></td>
	<td width="179"><center>
	  Assigned to
	</center></td>
 
  </tr>
<?php $i=1;
$roleSql="SELECT * FROM `www_users` WHERE id='".$_SESSION['UserID']."'";
$roleid=Db_query($roleSql,$db);
$roleRow=DB_fetch_array($roleid);
$RoleID= $roleRow['rolepid'];
if(DB_num_rows($getlead)>0)
{

	 while($row_lead=DB_fetch_array($getlead))
	 {
	 ?>
  <tr bgcolor="#dfdfdf">
    <td>
   <input name="leadid[]" type="checkbox" id="leadid_<?php echo $i; ?>"   value="<?php  echo $row_lead['leadid']?>" />
 <a href="index.php?route=Support/TroubleTicket&amp;action=Edit&amp;ticketid=<?php echo $row_lead['ticketid'].$rurl;?>">
  <img src="images/icon_edit.gif" width="10px"  height="10" /></a>
  <a href="index.php?route=Support/TroubleTicketView&action=View&ticketid=<?php echo $row_lead['ticketid'].$rurl;?>">
  <img src="images/search.gif" width="10px"  height="10" /></a></td>

  <td><center><?php  echo $row_lead['ticket_no'];// ConvertSQLDate($row_lead['created_date'])?></center></td>
  <td><center><?php  echo $row_lead['ticket_title'] ?></center></td>
    <td><center>
    	<?php
    	$ItemName=$s->getField('item_master','id',$row_lead['product_id'],'StockID');
		
    	?>
    	
    	<?php  echo $ItemName?></center></td>

	<td><center><?php  echo $row_lead['status']?></center></td>
	
	<td><center><?php  echo $row_lead['priority']?></center></td>
	<td>
	<?php echo $GroupName=$s->getField('securityroles','secroleid',$row_lead['groupid'],'secrolename');?>
	</td>
 </tr>
   <?php $i++; } 
   }
   else
   {?>
   	<tr>
   		<td colspan="8"><font color="#FF0000"><?php echo "No Records Found"; ?></font></td>
	</tr>
   	
  <?php }?>
</table>
</form>