File size: 11,821 Bytes
4e26128
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>DigitalPersona 4500 Biometric System</title>
    <script src="https://cdn.tailwindcss.com"></script>
    <script src="https://unpkg.com/feather-icons"></script>
</head>
<body class="bg-gray-100">
    <div class="container mx-auto px-4 py-8">
        <div class="max-w-4xl mx-auto bg-white rounded-lg shadow-md overflow-hidden">
            <div class="bg-blue-600 py-4 px-6">
                <h1 class="text-2xl font-bold text-white">DigitalPersona 4500 Biometric System</h1>
            </div>
            
            <div class="p-6">
                <!-- Scanner Status -->
                <div id="scannerStatus" class="mb-6 p-4 border rounded-lg">
                    <h2 class="text-lg font-semibold mb-2">Scanner Status</h2>
                    <div class="flex items-center">
                        <div id="statusIndicator" class="w-4 h-4 rounded-full bg-red-500 mr-2"></div>
                        <span id="statusText" class="text-gray-700">Scanner not connected</span>
                    </div>
                </div>

                <!-- Fingerprint Capture -->
                <div class="mb-6 p-4 border rounded-lg">
                    <h2 class="text-lg font-semibold mb-4">Fingerprint Capture</h2>
                    <div class="flex flex-col md:flex-row gap-4">
                        <div class="flex-1">
                            <div class="border-2 border-dashed border-gray-300 rounded-lg h-64 flex items-center justify-center bg-gray-50" id="fingerprintImage">
                                <canvas id="fingerprintCanvas" width="300" height="300" style="display:none;"></canvas>
                                <img id="fingerprintImg" src="" style="max-width:100%; max-height:100%; display:none;">
                                <span class="text-gray-500" id="fingerprintPlaceholder">Fingerprint image will appear here</span>
                            </div>
                        </div>
                        <div class="flex-1">
                            <div class="space-y-4">
                                <div>
                                    <label class="block text-sm font-medium text-gray-700 mb-1">Customer ID</label>
                                    <input type="text" id="customerId" class="w-full px-3 py-2 border rounded-md">
                                </div>
                                <div>
                                    <label class="block text-sm font-medium text-gray-700 mb-1">Name</label>
                                    <input type="text" id="customerName" class="w-full px-3 py-2 border rounded-md">
                                </div>
                                <div>
                                    <label class="block text-sm font-medium text-gray-700 mb-1">Email</label>
                                    <input type="email" id="customerEmail" class="w-full px-3 py-2 border rounded-md">
                                </div>
                                <div class="flex space-x-2">
                                    <button id="captureBtn" class="px-4 py-2 bg-blue-600 text-white rounded-md hover:bg-blue-700">Capture Fingerprint</button>
                                    <button id="saveBtn" class="px-4 py-2 bg-green-600 text-white rounded-md hover:bg-green-700">Save Record</button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- Search Section -->
                <div class="mb-6 p-4 border rounded-lg">
                    <h2 class="text-lg font-semibold mb-4">Search Customer</h2>
                    <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
                        <div class="space-y-2">
                            <div class="flex space-x-2">
                                <input type="text" id="searchInput" placeholder="Enter Customer ID" class="flex-1 px-3 py-2 border rounded-md">
                                <button id="searchBtn" class="px-4 py-2 bg-blue-600 text-white rounded-md hover:bg-blue-700">Search by ID</button>
                            </div>
                        </div>
                        <div class="space-y-2">
                            <button id="searchFingerprintBtn" class="w-full px-4 py-2 bg-purple-600 text-white rounded-md hover:bg-purple-700">Search by Fingerprint</button>
                        </div>
                    </div>
                </div>

                <!-- Results Section -->
                <div id="resultsSection" class="p-4 border rounded-lg hidden">
                    <h2 class="text-lg font-semibold mb-4">Customer Details</h2>
                    <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
                        <div>
                            <p><span class="font-medium">Customer ID:</span> <span id="resultId"></span></p>
                            <p><span class="font-medium">Name:</span> <span id="resultName"></span></p>
                            <p><span class="font-medium">Email:</span> <span id="resultEmail"></span></p>
                            <p><span class="font-medium">Registered:</span> <span id="resultDate"></span></p>
                        </div>
                        <div>
                            <div class="border-2 border-gray-300 rounded-lg h-32 flex items-center justify-center bg-gray-50" id="resultFingerprint">
                                <img id="resultFingerprintImg" src="" style="max-width:100%; max-height:100%; display:none;">
                                <span class="text-gray-500" id="resultFingerprintPlaceholder">Fingerprint image</span>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <!-- Hidden form for fingerprint data -->
    <form id="fingerprintForm" method="post" action="save_fingerprint.php" style="display: none;">
        <input type="hidden" id="fingerprintData" name="fingerprint_data">
        <input type="hidden" id="formCustomerId" name="customer_id">
        <input type="hidden" id="formCustomerName" name="customer_name">
        <input type="hidden" id="formCustomerEmail" name="customer_email">
    </form>

    <!-- Include DigitalPersona Web SDK (local version) -->
    <script src="DPWebComponents.js"></script>
    
    <script>
        feather.replace();
        
        // Initialize DigitalPersona components
        let dpControl, dpReader, dpCapture;
        
        // Load SDK components after SDK is loaded
        function initDigitalPersona() {
            dpControl = new DPControl();
            dpReader = new DPReader();
            dpCapture = new DPCapture();
        }

        document.addEventListener('DOMContentLoaded', function() {
            // Wait for SDK to be ready
            if (typeof DPControl === 'undefined') {
                document.getElementById('statusText').textContent = 'SDK not loaded. Please install DigitalPersona SDK';
                return;
            }
            
            initDigitalPersona();
            
            // Initialize scanner
            dpControl.Initialize().then(() => {
                document.getElementById('statusIndicator').classList.remove('bg-red-500');
                document.getElementById('statusIndicator').classList.add('bg-green-500');
                document.getElementById('statusText').textContent = 'Scanner connected';
                
                return dpReader.EnumerateReaders();
            }).then(readers => {
                if (readers.length > 0) {
                    return dpReader.SelectReader(readers[0]);
                }
                throw new Error('No fingerprint readers found');
            }).catch(error => {
                console.error('Scanner error:', error);
                document.getElementById('statusText').textContent = 'Scanner error: ' + error.message;
            });

            // Capture button click
            document.getElementById('captureBtn').addEventListener('click', function() {
                dpCapture.Capture().then(fingerprintData => {
                    document.getElementById('fingerprintImage').innerHTML = 
                        '<div class="text-center"><i data-feather="fingerprint" class="w-16 h-16 text-blue-500 mx-auto"></i><p class="mt-2">Fingerprint captured</p></div>';
                    feather.replace();
                    
                    // Store fingerprint data for saving
                    document.getElementById('fingerprintData').value = btoa(String.fromCharCode(...new Uint8Array(fingerprintData)));
                }).catch(error => {
                    console.error('Capture error:', error);
                    alert('Error capturing fingerprint: ' + error.message);
                });
            });
            
            // Save button click
            document.getElementById('saveBtn').addEventListener('click', function() {
                const customerId = document.getElementById('customerId').value;
                const customerName = document.getElementById('customerName').value;
                const customerEmail = document.getElementById('customerEmail').value;
                const fingerprintData = document.getElementById('fingerprintData').value;
                
                if (!customerId || !customerName || !fingerprintData) {
                    alert('Please enter Customer ID, Name and capture fingerprint');
                    return;
                }
                
                // Set form values
                document.getElementById('formCustomerId').value = customerId;
                document.getElementById('formCustomerName').value = customerName;
                document.getElementById('formCustomerEmail').value = customerEmail;
                
                // Submit form
                document.getElementById('fingerprintForm').submit();
            });
            
            // Search button click
            document.getElementById('searchBtn').addEventListener('click', function() {
                const searchId = document.getElementById('searchInput').value;
                if (!searchId) {
                    alert('Please enter a Customer ID');
                    return;
                }
                
                fetch('search_customer.php?customer_id=' + searchId)
                    .then(response => response.json())
                    .then(data => {
                        if (data.error) {
                            alert(data.error);
                        } else {
                            document.getElementById('resultId').textContent = data.customer_id;
                            document.getElementById('resultName').textContent = data.customer_name;
                            document.getElementById('resultEmail').textContent = data.customer_email;
                            document.getElementById('resultDate').textContent = data.registration_date;
                            
                            // Display fingerprint image
                            visualizeFingerprint(data.fingerprint_data, 'resultFingerprintImg', 'resultFingerprintPlaceholder');
                            document.getElementById('resultsSection').classList.remove('hidden');
                        }
                    })
                    .catch(error => {
                        console.error('Error:', error);
                        alert('Error searching for customer');
                    });
            });
        });
    </script>
</body>
</html>