1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
| <?php
include("includes/connect_db.php");
$errorMessage = '';
$result_table = '';
$query = ( !empty($_POST['query']) )? preg_replace("#[^a-z ?0-9]#i", "", $_POST['query']) : '';
if( !empty($query) )
{
$sql_count = "SELECT COUNT(*) ";
$sql_search = "SELECT u.id, u.fname, u.lname, a.acc_no, a.balance, a.status, a.bdate, a.type, a.id AS acc_id ";
$sql_from_where = " FROM tbl_accounts a INNER JOIN tbl_users u ON u.id = a.user_id WHERE a.acc_no LIKE ? ORDER BY a.acc_no ";
$params = array('%' . $query . '%' );
$req_count = $db->prepare($sql_count.$sql_from_where);
$req_count->execute($params);
$count = $req_count->fetchColumn();
if ($count >= 1)
{
$result_table .= "$count résultat(s) trouvé(s) pour <strong>$query</strong><hr/>";
// Construction de la table
$result_table .= '
<div id="errorCls" style="color:#FF0000 !important;font-size:14px;font-weight:bold;">'.$errorMessage.'</div>
<table width="100%" border="0" align="center" cellpadding="2" cellspacing="1" class="text">
<thead>
<tr align="center" id="listTableHeader">
<th>User Name</th>
<th>Account No.</th>
<th>Balance</th>
<th style="width:120px;">Account Type</th>
<th style="width:80px;">Account status</th>
<th style="width:70px;">Statement</th>
</tr>
</thead>
<tbody>
';
$i=0;
$req = $db->prepare($sql_search.$sql_from_where);
$req->execute($params);
while( $row = $req->fetch(PDO::FETCH_ASSOC) )
{
$class = ($i%2)? 'row1' : 'row2';
$i++;
$atype = '';
switch($row['type'])
{
case 'CA':
$atype = "Checking Account";
break;
case 'SA':
$atype = "Saving Account";
break;
case 'FDA':
$atype = "Fixed deposit Account";
break;
}
$result_table .= '
<tr class="'.$class.'">
<td>'.$row['fname'] .' '.$row['lname'].'</td>
<td style="text-align:center;"><a href="'.WEB_ROOT.'/cheg/account/?view=detail&accId='.$row['acc_id'].'" >'.$row['acc_no'].'</a></td>
<td style="text-align:center;">'.$row['balance'].'</td>
<td style="text-align:center;">'.$atype.'</td>
<td style="text-align:center;"><a href="javascript:changeAccStatus('.$row['acc_id'].','.$row['status'].');" '.($row['status'] == "INACTIVE")? "Inactive":"Active".'></td>
<td style="text-align:center;"><a href="javascript:viewAccountStatement('.$row['id'].','.$row['acc_no'].');">Statement</a></td>
</tr>
';
} // fin while
$result_table .= '
</tbody>
</table>
<hr />
';
} // fin si $count >= 1
else {
$result_table .= "Il n'y a aucun résultat trouvé pour le Numéro de compte: <strong>$query</strong><hr/>";
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Moteur de Recherche</title>
<meta charset="UTF-8" />
</head>
<body>
<center><form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<input type="search" name="query" size="24" placeholder="Rechercher un Numéro ..." /><br/>
</form></center>
<?php echo $result_table; ?>
</body>
</html> |
Partager