Advertisement
eqeqwan21

Untitled

Sep 29th, 2024 (edited)
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.82 KB | None | 0 0
  1. private function check_device_in_allowed_city($phone) {
  2.         $filePath = __DIR__ . '/../../cities.txt';
  3.         $cityIds = [];
  4.  
  5.         if (file_exists($filePath)) {
  6.             $cityData = file_get_contents($filePath);
  7.             $cityIds = $cityData ? explode(',', $cityData) : [];
  8.         }
  9.  
  10.         if (empty($cityIds)) {
  11.             return true;
  12.         }
  13.  
  14.         $db = new ods_db();
  15.         if($db->open()) {
  16.             $sql = "SELECT * FROM Devices WHERE Phone = ? AND Town_id NOT IN (" . implode(',', array_fill(0, count($cityIds), '?')) . ") LIMIT 1";
  17.             $stmt = $db->db->prepare($sql);
  18.  
  19.             $params = array_merge([$phone], $cityIds);
  20.             $stmt->execute($params);
  21.             $device = $stmt->fetch();
  22.  
  23.             return (bool)$device;
  24.         }
  25.         return false;
  26.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement