File: C:/Inetpub/vhosts/alnaeem.server.ly/httpdocs/0.0/JARD.PHP
<?php
header('Content-Type: text/html; charset=utf-8');
$serverName = "148.251.211.105";
$connectionOptions = array(
"Database" => "TRDB",
"Uid" => "sa",
"PWD" => "cnTIzk2nQM7193o5NQ",
"CharacterSet" => "UTF-8",
"TrustServerCertificate" => true
);
$conn = sqlsrv_connect($serverName, $connectionOptions);
if (!$conn) {
die("<p style='color:red;'>❌ فشل الاتصال بقاعدة البيانات:</p>" . print_r(sqlsrv_errors(), true));
}
$search = isset($_GET['search']) ? trim($_GET['search']) : '';
$search_st = isset($_GET['search_st']) ? $_GET['search_st'] : '';
$branches = [
'1'=>'بن غشير ألعاب',
'2'=>'جرابة',
'3'=>'سيتى مول',
'4'=>'حى الاندلس',
'5'=>'زناته',
'10'=>'مصراته',
'13'=>'المشتل',
'12'=>'المطار'
];
$results = [];
if($search !== '' || $search_st !== ''){
$where = [];
$params = [];
if($search !== ''){
$where[] = "(COD1 LIKE ? OR COD2 LIKE ? OR COD3 LIKE ? OR COD4 LIKE ? OR ITEM_NO_OLD LIKE ? OR ITEM_AR LIKE ?)";
for($i=0;$i<6;$i++) $params[] = "%$search%";
}
if($search_st !== ''){
$where[] = "ST = ?";
$params[] = $search_st;
}
$where_sql = '';
if(count($where) > 0){
$where_sql = 'WHERE ' . implode(' AND ', $where);
}
$sql = "SELECT ITEM_AR, QTY, PRSPIC1_OUT, COD1, ST
FROM JARD
$where_sql
ORDER BY ITEM_AR, ST";
$stmt = sqlsrv_query($conn, $sql, $params);
if($stmt === false){
die(print_r(sqlsrv_errors(), true));
}
while($row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)){
$results[] = $row;
}
}
?>
<!DOCTYPE html>
<html lang="ar">
<head>
<meta charset="UTF-8">
<title>بحث الأصناف </title>
<style>
body{font-family:tahoma; direction:rtl; margin:10px; font-size:40px; line-height:1.6;}
.search-row{display:flex; gap:5px; margin-bottom:10px; flex-wrap:wrap;}
.search-row input, .search-row select{flex:1 1 45%; padding:12px; font-size:35px; box-sizing:border-box;}
.search-row button{flex:1 1 45%; padding:12px; font-size:40px; background:#007bff; color:#fff; border:none; border-radius:5px; cursor:pointer;}
.search-row button:hover{background:#0056b3;}
table{width:100%; border-collapse:collapse; margin-top:10px; font-size:40px;}
table th, table td{border:1px solid #ccc; padding:10px; text-align:center; word-break:break-word;}
table th{background:#f0f0f0;}
td.ITEM_AR{white-space:normal; line-height:1.5em; max-width:250px; font-size:40px;} /* النص الطويل يتقسم لسطرين */
td.FR{width:60px; font-size:35px;} /* خانة رقم الفرع */
td.PRICE{width:90px; font-size:35px;} /* عرض سعر الوحدة أصغر لتوفير مساحة للاسم */
td.QTY{width:90px; font-size:35px;} /* عرض الكمية */
@media(max-width:600px){
.search-row{flex-direction:column;}
.search-row input, .search-row select, .search-row button{flex:1 1 100%;}
table th, table td{font-size:18px; padding:8px;}
td.ITEM_AR{max-width:110px;}
td.FR{width:50px;}
td.PRICE{width:90px;}
td.QTY{width:90px;}
}
</style>
</head>
<body>
<h3>بحث الأصناف</h3>
<form method="GET">
<div class="search-row">
<input type="text" name="search" placeholder="الكود أو اسم الصنف" value="<?= htmlspecialchars($search) ?>">
<select name="search_st">
<option value="">كل الفروع</option>
<?php foreach($branches as $num=>$name): ?>
<option value="<?= $num ?>" <?= $search_st == $num ? 'selected' : '' ?>><?= $name ?></option>
<?php endforeach; ?>
</select>
<button type="submit">بحث</button>
</div>
</form>
<?php if(count($results) > 0): ?>
<table>
<tr>
<th>FR</th>
<th>إسم الصنف</th>
<th>الكمية</th>
<th>السعر</th>
</tr>
<?php foreach($results as $row): ?>
<tr>
<td class="FR"><?= $row['ST'] ?></td>
<td class="ITEM_AR"><?= nl2br(htmlspecialchars($row['ITEM_AR'])) ?></td>
<td class="QTY"><?= number_format($row['QTY']) ?></td>
<td class="PRICE"><?= number_format($row['PRSPIC1_OUT']) ?></td>
</tr>
<?php endforeach; ?>
</table>
<?php elseif($search !== '' || $search_st !== ''): ?>
<p>لا توجد نتائج</p>
<?php endif; ?>
</body>
</html>