Browse Source

fleat:php 初始版本

igb 4 weeks ago
parent
commit
f19c7ccf9d
1 changed files with 28 additions and 41 deletions
  1. 28 41
      customers.php

+ 28 - 41
customers.php

@@ -3,17 +3,13 @@ require_once 'conn.php';
 checkLogin();
 
 // 辅助函数
-function textEncode($str) {
-    return htmlspecialchars($str, ENT_QUOTES, 'UTF-8');
-}
+
 
 function textDecode($str) {
     return htmlspecialchars_decode($str, ENT_QUOTES);
 }
 
-function htmlEncode($str) {
-    return htmlspecialchars($str, ENT_QUOTES, 'UTF-8');
-}
+
 
 function htmlDecode($str) {
     return htmlspecialchars_decode($str, ENT_QUOTES);
@@ -231,7 +227,7 @@ $sqlStr = "SELECT id, cs_code, cs_name, cs_country, cs_address, cs_tel, cs_email
            OR cs_whatsappformat LIKE '%$keyscode%' 
            OR cs_email LIKE '%$keyscode%') 
            $fliterStr 
-           ORDER BY ${ordStr}cs_updatetime DESC";
+           ORDER BY {$ordStr}cs_updatetime DESC";
 
 ?>
 <!DOCTYPE html>
@@ -416,46 +412,37 @@ $hrefstr = "?keys=" . $keys;
                 cs_tel, cs_email, cs_whatsapp, cs_wechat, cs_linkedin, cs_facebook, 
                 cs_alibaba, colortag, cs_note, cs_claimFrom 
                 FROM customer 
-                WHERE is_silent=0 AND cs_deal>0 AND cs_belong=? 
-                AND (cs_code LIKE ? OR cs_name LIKE ? OR cs_email LIKE ? 
-                OR cs_wechat LIKE ? OR cs_telformat LIKE ? 
-                OR cs_whatsappformat LIKE ? OR cs_code LIKE ?) 
-                $filterStr 
-                ORDER BY colortag DESC, id DESC";
-
-        $stmt = $conn->prepare($sql);
-        $searchPattern = "%$keyscode%";
-        $stmt->bind_param("isssssss", 
-            $_SESSION['employee_id'],
-            $searchPattern, $searchPattern, $searchPattern,
-            $searchPattern, $searchPattern, $searchPattern,
-            $searchPattern
-        );
-
-        $stmt->execute();
-        $result = $stmt->get_result();
+                WHERE is_silent=0 AND cs_deal>0 AND cs_belong=" . (int)$_SESSION['employee_id'];
+        
+        $searchPattern = mysqli_real_escape_string($conn, $keyscode);
+        if(!empty($searchPattern)) {
+            $sql .= " AND (cs_code LIKE '%$searchPattern%' 
+                    OR cs_name LIKE '%$searchPattern%' 
+                    OR cs_email LIKE '%$searchPattern%'
+                    OR cs_wechat LIKE '%$searchPattern%' 
+                    OR cs_telformat LIKE '%$searchPattern%'
+                    OR cs_whatsappformat LIKE '%$searchPattern%' 
+                    OR cs_code LIKE '%$searchPattern%')";
+        }
+        
+        $sql .= " $filterStr ORDER BY colortag DESC, id DESC";
+        
+        $result = mysqli_query($conn, $sql);
 
         // Pagination logic
         $perPage = 20;
-        $totalRecords = $result->num_rows;
-        $totalPages = ceil($totalRecords / $perPage);
-        $page = min(max(1, $page), $totalPages);
-        $offset = ($page - 1) * $perPage;
+        $totalRecords = mysqli_num_rows($result);
+        $totalPages = max(1, ceil($totalRecords / $perPage));
+        $page = max(1, min((int)$page, $totalPages));
+        $offset = max(0, ($page - 1) * $perPage);
 
+        // Add pagination to query
         $sql .= " LIMIT $offset, $perPage";
-        $stmt = $conn->prepare($sql);
-        $stmt->bind_param("isssssss", 
-            $_SESSION['employee_id'],
-            $searchPattern, $searchPattern, $searchPattern,
-            $searchPattern, $searchPattern, $searchPattern,
-            $searchPattern
-        );
-        $stmt->execute();
-        $result = $stmt->get_result();
-
-        if ($result->num_rows > 0) {
+        $result = mysqli_query($conn, $sql);
+
+        if (mysqli_num_rows($result) > 0) {
             $tempNum = $offset;
-            while ($row = $result->fetch_assoc()) {
+            while ($row = mysqli_fetch_assoc($result)) {
                 $tempNum++;
                 ?>
                 <div class="tline color<?= $row['colortag'] ?>">