<?php
// Create new controller: application/controllers/Verify.php

defined('BASEPATH') OR exit('No direct script access allowed');

class Verify extends CI_Controller {

    public function index($key = '') {
        // Get the key from URL
        if($key == ''){
            show_404();
            return;
        }
        
        // Clean the key
        $key = $this->security->xss_clean($key);
        
        // Query database for the exit permit
        $query = $this->db->query("SELECT * FROM exit_permit WHERE random_key='$key' LIMIT 1");
        
        if($query->num_rows() == 0){
            // No record found
            $data['error'] = 'Invalid verification key. No record found.';
            $data['clients'] = array();
        } else {
            // Record found
            $data['clients'] = $query->result_array();
            $data['error'] = '';
        }
        
        // Load the view
        $this->load->view('exit_permit.php', $data);
    }
}