/home/awneajlw/.trash/search-results.php
<?php
if (session_status() == PHP_SESSION_NONE) {
session_start();
}
require_once 'config/database.php';
require_once 'includes/auth.php';
// Check if user is logged in
if (!isLoggedIn()) {
header('Location: welcome.php');
exit();
}
// Get search parameters
$search_query = isset($_GET['q']) ? trim($_GET['q']) : '';
$search_results = [];
// If search query exists, search in orders
if (!empty($search_query)) {
try {
$database = new Database();
$db = $database->getConnection();
// Create orders table if it doesn't exist
$create_table_sql = "CREATE TABLE IF NOT EXISTS orders (
id INT AUTO_INCREMENT PRIMARY KEY,
user_id INT NOT NULL,
tracking_id VARCHAR(50) NOT NULL,
patient_name VARCHAR(100) NOT NULL,
whatsapp_number VARCHAR(20),
frame_detail TEXT,
lens_type VARCHAR(100),
booking_date DATE,
delivery_date DATE,
total_amount DECIMAL(10,2),
advance DECIMAL(10,2),
balance DECIMAL(10,2),
special_note TEXT,
right_sph DECIMAL(5,2),
right_cyl DECIMAL(5,2),
right_axis INT,
left_sph DECIMAL(5,2),
left_cyl DECIMAL(5,2),
left_axis INT,
near_add DECIMAL(5,2),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci";
$db->exec($create_table_sql);
$user_id = $_SESSION['user_id'];
$query = "SELECT * FROM orders WHERE user_id = ? AND (
patient_name LIKE ? OR
tracking_id LIKE ? OR
whatsapp_number LIKE ? OR
frame_detail LIKE ? OR
lens_type LIKE ?
) ORDER BY created_at DESC LIMIT 10";
$search_term = '%' . $search_query . '%';
$stmt = $db->prepare($query);
$stmt->execute([$user_id, $search_term, $search_term, $search_term, $search_term, $search_term]);
$search_results = $stmt->fetchAll(PDO::FETCH_ASSOC);
} catch (Exception $e) {
$search_error = 'Search failed. Please try again.';
}
}
// Get shop data
$shop_data = [
'shop_name' => 'AINAK STORE',
'address' => '95176 Gloria Ranch, Pollichworth',
'whatsapp' => '+923325122739',
'facebook' => 'f ainakstore',
'instagram' => 'ainakstore',
'website' => 'ainakstore.com'
];
if (isLoggedIn()) {
try {
$database = new Database();
$db = $database->getConnection();
$user_id = $_SESSION['user_id'];
$query = "SELECT s.*, u.name as owner_name, u.email
FROM shops s
JOIN users u ON s.user_id = u.id
WHERE s.user_id = ?";
$stmt = $db->prepare($query);
$stmt->execute([$user_id]);
$user_shop = $stmt->fetch(PDO::FETCH_ASSOC);
if ($user_shop) {
$shop_data = [
'shop_name' => $user_shop['shop_name'] ?: 'My Shop',
'address' => $user_shop['shop_address'] ?: 'Address not provided',
'whatsapp' => $user_shop['shop_phone'] ?: '+923325122739',
'facebook' => 'f ' . strtolower(str_replace(' ', '', $user_shop['shop_name'])),
'instagram' => strtolower(str_replace(' ', '', $user_shop['shop_name'])),
'website' => $user_shop['shop_email'] ?: strtolower(str_replace(' ', '', $user_shop['shop_name'])) . '.com'
];
}
} catch (Exception $e) {
// Use default shop data
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Search Results - OPTI SLIP</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css" rel="stylesheet">
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Inter', sans-serif;
background: linear-gradient(135deg, #1e3a8a 0%, #3730a3 100%);
min-height: 100vh;
padding: 20px;
}
.search-container {
max-width: 800px;
margin: 0 auto;
}
.search-header {
display: flex;
align-items: center;
margin-bottom: 30px;
gap: 15px;
}
.back-btn {
background: #10b981;
color: white;
border: none;
border-radius: 50%;
width: 40px;
height: 40px;
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
transition: all 0.3s ease;
text-decoration: none;
}
.back-btn:hover {
background: #059669;
transform: scale(1.05);
color: white;
}
.search-title {
color: white;
font-size: 24px;
font-weight: 600;
}
.search-results-card {
background: white;
border-radius: 20px;
padding: 30px;
box-shadow: 0 20px 40px rgba(0,0,0,0.1);
margin-bottom: 20px;
}
.logo-section {
display: flex;
align-items: center;
justify-content: center;
margin-bottom: 30px;
gap: 10px;
}
.logo-icon {
width: 40px;
height: 40px;
background: linear-gradient(135deg, #10b981 0%, #059669 100%);
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
color: white;
font-size: 18px;
margin: 0 5px;
}
.logo-text {
font-size: 24px;
font-weight: 700;
color: #1e3a8a;
margin-left: 10px;
}
.order-details {
margin-bottom: 30px;
}
.detail-row {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 20px;
margin-bottom: 15px;
}
.detail-item {
display: flex;
flex-direction: column;
}
.detail-label {
font-size: 12px;
color: #6b7280;
margin-bottom: 5px;
font-weight: 500;
}
.detail-value {
font-size: 16px;
color: #1f2937;
font-weight: 600;
padding: 8px 0;
border-bottom: 1px solid #e5e7eb;
}
.special-note-section {
margin: 30px 0;
}
.section-title {
font-size: 18px;
font-weight: 700;
color: #1f2937;
margin-bottom: 15px;
}
.note-text {
color: #6b7280;
line-height: 1.6;
font-size: 14px;
}
.prescription-section {
margin: 30px 0;
}
.prescription-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 30px;
margin-bottom: 20px;
}
.eye-section {
background: #f9fafb;
padding: 20px;
border-radius: 12px;
border: 1px solid #e5e7eb;
}
.eye-title {
font-size: 16px;
font-weight: 700;
color: #1f2937;
margin-bottom: 15px;
text-align: center;
}
.prescription-row {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
gap: 10px;
margin-bottom: 10px;
}
.prescription-item {
text-align: center;
}
.prescription-label {
font-size: 12px;
color: #6b7280;
margin-bottom: 5px;
}
.prescription-value {
font-size: 16px;
font-weight: 600;
color: #1f2937;
}
.add-section {
text-align: center;
margin-top: 20px;
}
.add-value {
font-size: 18px;
font-weight: 700;
color: #10b981;
}
.action-buttons {
display: flex;
gap: 20px;
justify-content: center;
margin-top: 40px;
}
.action-btn {
background: linear-gradient(135deg, #10b981 0%, #059669 100%);
color: white;
border: none;
padding: 15px 30px;
border-radius: 12px;
font-weight: 600;
font-size: 16px;
cursor: pointer;
transition: all 0.3s ease;
display: flex;
align-items: center;
gap: 10px;
}
.action-btn:hover {
transform: translateY(-2px);
box-shadow: 0 10px 20px rgba(16, 185, 129, 0.3);
}
.no-results {
text-align: center;
color: #6b7280;
font-size: 18px;
padding: 60px 20px;
}
.search-form {
background: white;
border-radius: 15px;
padding: 20px;
margin-bottom: 30px;
box-shadow: 0 10px 20px rgba(0,0,0,0.1);
}
.search-input-group {
display: flex;
gap: 10px;
}
.search-input {
flex: 1;
padding: 12px 15px;
border: 2px solid #e5e7eb;
border-radius: 10px;
font-size: 16px;
transition: all 0.3s ease;
}
.search-input:focus {
outline: none;
border-color: #10b981;
box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.1);
}
.search-btn {
background: linear-gradient(135deg, #10b981 0%, #059669 100%);
color: white;
border: none;
padding: 12px 20px;
border-radius: 10px;
font-weight: 600;
cursor: pointer;
transition: all 0.3s ease;
}
.search-btn:hover {
transform: translateY(-2px);
box-shadow: 0 5px 15px rgba(16, 185, 129, 0.3);
}
@media (max-width: 768px) {
.detail-row {
grid-template-columns: 1fr;
gap: 15px;
}
.prescription-grid {
grid-template-columns: 1fr;
gap: 20px;
}
.action-buttons {
flex-direction: column;
align-items: center;
}
.search-input-group {
flex-direction: column;
}
.logo-section {
flex-direction: column;
gap: 15px;
}
}
</style>
</head>
<body>
<div class="search-container">
<!-- Search Header -->
<div class="search-header">
<a href="home.php" class="back-btn">
<i class="fas fa-arrow-left"></i>
</a>
<h1 class="search-title">Search Results</h1>
</div>
<!-- Search Form -->
<div class="search-form">
<form method="GET" action="search-results.php">
<div class="search-input-group">
<input type="text" name="q" class="search-input"
placeholder="Search by patient name, tracking ID, phone number..."
value="<?php echo htmlspecialchars($search_query); ?>">
<button type="submit" class="search-btn">
<i class="fas fa-search me-2"></i>Search
</button>
</div>
</form>
</div>
<?php if (!empty($search_query)): ?>
<?php if (!empty($search_results)): ?>
<?php foreach ($search_results as $order): ?>
<div class="search-results-card">
<!-- Logo Section -->
<div class="logo-section">
<div class="logo-icon">
<i class="fas fa-glasses"></i>
</div>
<div class="logo-icon">
<i class="fas fa-qrcode"></i>
</div>
<div class="logo-text">OPTI SLIP</div>
</div>
<!-- Order Details -->
<div class="order-details">
<div class="detail-row">
<div class="detail-item">
<span class="detail-label">Patient Name</span>
<span class="detail-value"><?php echo htmlspecialchars($order['patient_name'] ?: 'XXXXXXXXXX'); ?></span>
</div>
<div class="detail-item">
<span class="detail-label">WhatsApp Number</span>
<span class="detail-value"><?php echo htmlspecialchars($order['whatsapp_number'] ?: 'XXXXXXXXXX'); ?></span>
</div>
</div>
<div class="detail-row">
<div class="detail-item">
<span class="detail-label">Frame Detail</span>
<span class="detail-value"><?php echo htmlspecialchars($order['frame_detail'] ?: 'XXXXXXXXXX'); ?></span>
</div>
<div class="detail-item">
<span class="detail-label">Lens Type</span>
<span class="detail-value"><?php echo htmlspecialchars($order['lens_type'] ?: 'XXXXXXXXXX'); ?></span>
</div>
</div>
<div class="detail-row">
<div class="detail-item">
<span class="detail-label">Booking Date</span>
<span class="detail-value"><?php echo $order['booking_date'] ? date('d/m/Y', strtotime($order['booking_date'])) : 'XXXXXX'; ?></span>
</div>
<div class="detail-item">
<span class="detail-label">Total Amount</span>
<span class="detail-value">PKR <?php echo number_format($order['total_amount'], 2); ?></span>
</div>
</div>
</div>
<!-- Special Note Section -->
<?php if (!empty($order['special_note'])): ?>
<div class="special-note-section">
<h3 class="section-title">Special Note</h3>
<p class="note-text"><?php echo htmlspecialchars($order['special_note']); ?></p>
</div>
<?php endif; ?>
<!-- Prescription Section -->
<div class="prescription-section">
<h3 class="section-title">Prescription</h3>
<div class="prescription-grid">
<!-- Right Eye -->
<div class="eye-section">
<div class="eye-title">Right Eye</div>
<div class="prescription-row">
<div class="prescription-item">
<div class="prescription-label">SPH</div>
<div class="prescription-value"><?php echo number_format($order['right_sph'] ?? 0, 2); ?></div>
</div>
<div class="prescription-item">
<div class="prescription-label">CYL</div>
<div class="prescription-value"><?php echo number_format($order['right_cyl'] ?? 0, 2); ?></div>
</div>
<div class="prescription-item">
<div class="prescription-label">AXIS</div>
<div class="prescription-value"><?php echo $order['right_axis'] ?? 0; ?></div>
</div>
</div>
</div>
<!-- Left Eye -->
<div class="eye-section">
<div class="eye-title">Left Eye</div>
<div class="prescription-row">
<div class="prescription-item">
<div class="prescription-label">SPH</div>
<div class="prescription-value"><?php echo number_format($order['left_sph'] ?? 0, 2); ?></div>
</div>
<div class="prescription-item">
<div class="prescription-label">CYL</div>
<div class="prescription-value"><?php echo number_format($order['left_cyl'] ?? 0, 2); ?></div>
</div>
<div class="prescription-item">
<div class="prescription-label">AXIS</div>
<div class="prescription-value"><?php echo $order['left_axis'] ?? 0; ?></div>
</div>
</div>
</div>
</div>
<!-- Add Section -->
<div class="add-section">
<div class="prescription-label">Add</div>
<div class="add-value"><?php echo number_format($order['near_add'] ?? 0, 2); ?></div>
</div>
</div>
<!-- Action Buttons -->
<div class="action-buttons">
<button class="action-btn" onclick="shareOrder(<?php echo $order['id']; ?>)">
<i class="fas fa-share-alt"></i>
Share
</button>
<button class="action-btn" onclick="printOrder(<?php echo $order['id']; ?>)">
<i class="fas fa-print"></i>
Print
</button>
</div>
</div>
<?php endforeach; ?>
<?php else: ?>
<div class="search-results-card">
<div class="no-results">
<i class="fas fa-search" style="font-size: 48px; color: #d1d5db; margin-bottom: 20px;"></i>
<h3>No results found</h3>
<p>Try searching with different keywords or check your spelling.</p>
</div>
</div>
<?php endif; ?>
<?php else: ?>
<div class="search-results-card">
<div class="no-results">
<i class="fas fa-search" style="font-size: 48px; color: #d1d5db; margin-bottom: 20px;"></i>
<h3>Search Orders</h3>
<p>Enter a search term to find patient orders by name, tracking ID, or phone number.</p>
</div>
</div>
<?php endif; ?>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<script>
function shareOrder(orderId) {
if (navigator.share) {
navigator.share({
title: 'OPTI SLIP Order',
text: 'Check out this order from OPTI SLIP',
url: window.location.href
});
} else {
// Fallback: copy to clipboard
navigator.clipboard.writeText(window.location.href).then(() => {
alert('Order link copied to clipboard!');
});
}
}
function printOrder(orderId) {
window.print();
}
// Auto-focus search input
document.addEventListener('DOMContentLoaded', function() {
const searchInput = document.querySelector('.search-input');
if (searchInput) {
searchInput.focus();
}
});
</script>
</body>
</html>