<? if($_SESSION['page'] == '4' and $_SESSION['section'] == '4') {

?>
<link href="../admin.css" rel="stylesheet" type="text/css" />

<table width="95%" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#CCCCCC">
      <tr>
        <td><table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
          <tr>
            <td class="Main_Text"><a class="Main_Text">Search for  Cases</a></td>
            <td width="10%" class="Main_Text"><div align="right"><img src="image/more_info.gif" width="32" height="32" border="0" /></a></div></td>
          </tr>
          <tr>
            <td colspan="2">
            
<? if ($_GET['stat'] == '' ) {?>            
            <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src="image/subheader_icon.gif" width="12" height="12" /><strong class="text2">&nbsp;&nbsp;Search</strong></p>
            <div align="center"><br />
              <form id="form1" name="form1" method="post" action="index.php?stat=search">
                <table width="60%" border="0">
                  <tr>
                    <td class="Main_Text1">Search By</td>
                    <td class="Main_SText_case">
                    <select name="Searchby" id="Searchby">
                      <option value="cus_name">Customer Name</option>
                      <option value="cus_mobile">Customer Mobile</option>
                      <option value="cus_cpr">Customer CPR</option>
                    </select>
                    </td>
                  </tr>
                  <tr>
                    <td class="Main_Text1">Search</td>
                    <td class="Main_SText_case"><input type="text" name="Search1" id="Search1" /></td>
                  </tr>
                </table>
                <p>
                  <input name="Submit" type="submit" class="Button1" id="Submit" value="   Search   " />
                </p>
              </form>
              <br />
              <br />
              <br />
              </div>
              <? } if ($_GET['stat'] == 'search' ) {?>            
          
            <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src="image/subheader_icon.gif" width="12" height="12" /><strong class="text2">&nbsp;&nbsp;Search</strong></p>
            
              </p>
              <? 
			  
			 if ($_POST['Searchby'] == 'cus_name') { 
				  $cus_name = str_replace("%"," ",$_POST['Search1']);
				  $result1 = mysql_query("SELECT * FROM ".$dcm_table_start."customer where cus_name like '%".$cus_name."%'",$db); 
			 	}
			 if ($_POST['Searchby'] == 'cus_mobile') { 
				  $cus_name = str_replace("%"," ",$_POST['Search1']);
				 // $result1 = mysql_query("SELECT * FROM ".$dcm_table_start."customer where cus_mobile like '%".$cus_name."%'",$db); 
				  $result1 = mysql_query("SELECT dcm_customer.*, dcm_cus_tele.telephone FROM dcm_cus_tele RIGHT JOIN dcm_customer ON dcm_cus_tele.cus_id = dcm_customer.cus_id where cus_mobile like '%".$cus_name."%' or dcm_cus_tele.telephone like '%".$cus_name."%' "); 

				  
				  
			  }
			  
			 if ($_POST['Searchby'] == 'cus_cpr') { 
				  $cus_name = str_replace("%"," ",$_POST['Search1']);
				  $result1 = mysql_query("SELECT * FROM ".$dcm_table_start."customer where (CPR  = '".$cus_name."' or CR = '".$cus_name."')",$db); 
			  }
			  
			  	//			  $result1 = mysql_query("SELECT * FROM ".$dcm_table_start."customer where (CPR = '".$_POST['CPR']."' or CR ='".$_POST['CPR']."') and cus_name like '%".$cus_name."%'",$db); 

			  
			  
?>



              <table width="95%" border="0" align="center">
                <tr>
                  <td  class="Main_Text1">Total</td>
                  <td  class="Main_SText">&nbsp;<? echo mysql_num_rows($result1);?> Customer</td>
                  <td>&nbsp;</td>
                  <td>&nbsp;</td>
                  <td>&nbsp;</td>
                  <td>&nbsp;</td>
                </tr>
                <tr>
                  <td  class="Main_Text1">CPR / CR</td>
                  <td  class="Main_Text1">Customer  Name</td>
                  <td  class="Main_Text1">mobile</td>
                  <td  class="Main_Text1">Address</td>
                  <td  class="Main_Text1">Fax</td>
                  <td  class="Main_Text1">Case id</td>
                </tr>
                <? 
					while($row = mysql_fetch_array($result1)){ 
					$query1 = mysql_query("SELECT * FROM ".$dcm_table_start."case where cus_id = ".$row['cus_id']);	
				?>
                <tr>
                  <td  class="Main_SText_case">&nbsp;<strong><? echo $row['CPR']; ?><? echo $row['CR']; ?></strong></td>
                  <td  class="Main_SText_case">&nbsp;<? echo $row['cus_name']; ?></td>
                  <td  class="Main_SText_case">&nbsp;<? echo $row['cus_mobile']; ?></td>
                  <td  class="Main_SText_case">&nbsp;<? echo $row['cus_address']; ?></td>
                  <td  class="Main_SText_case">&nbsp;<? echo $row['cus_fax']; ?></td>
                  <td class="Main_SText_case1"><div align="center"><? while($row_4_2 = mysql_fetch_array($query1)){
?><a href="index.php?section=1&stat=select&case_id=<? echo $row_4_2['case_id']?>" class="Main_SText_case">
                    <? echo $row_4_2['case_id']."( ".$row_4_2['manage_uid']." )</a><br />"; }  ?></div></td>
                </tr>
                <?
						}
						?>
              </table>
              <p>
            <? } ?>              </td>
          </tr>
        </table></td>
      </tr>
</table>
 
<? } ?>
