
­­­­­­­­­­­­­­­­­­
<!DOCTYPE html>
<html>
<?php
declare(strict_types=1);
require __DIR__ . '/BaseController.php';

class ContactsController extends BaseController {
  public function index(): void {
    $u = require_login($this->pdo, $this->config);

    $q = trim($_GET['q'] ?? '');
    if ($q !== '') {
      $like = '%' . $q . '%';
      $st = $this->pdo->prepare("SELECT * FROM contacts WHERE mobile LIKE ? OR full_name LIKE ? ORDER BY id DESC LIMIT 100");
      $st->execute([$like, $like]);
      $rows = $st->fetchAll();
    } else {
      $rows = $this->pdo->query("SELECT * FROM contacts ORDER BY id DESC LIMIT 100")->fetchAll();
    }
    $this->render('contacts/index.php', ['rows' => $rows, 'q' => $q]);
  }
}
