<?php

class common_controller extends mainController {

    private $modal = null;
    private $vehicle_class;

    public function landing() {
        echo 1;
    }

    public function __construct() {
        //false to don't check login, since no login in data collector anymore
        parent::__construct(false);
        $this->vehicle_class = new Vehicle();
    }

    //ex how to call: http://localhost/trusto/common_controller/InsertCallerID?caller_id={{caller_id}}
    public function InsertCallerID() {
        if (empty($_GET['caller_id']) || empty($_SERVER['HTTP_REFERER']) || $_SERVER['HTTP_REFERER'] != 'http://www.trustotech.com/POSCallerID/')
            exit;
        $time = date('Y-m-d H:i:s');
        $data = [&$time, &$_GET['caller_id']];
        $db = DBConnectorFactory::loadDriver();
        $db->prepare_Stmt("Insert INTO tbl_pos_caller_id Set caller_time = ?,caller_phone_number = ?", $data);
        $error = $db->error();
        return $error;
    }

    //ex how to call: http://localhost/trusto/common_controller/GenerateQRCode?code=abc
    public function GenerateQRCode() {
        if (empty($_GET['code']))
            exit;
        Forms::generate_qrcode($_GET['code']);
    }

    //ex how to call: http://localhost/trusto/common_controller/GenerateBarCodeImage?code=123
    public function GenerateBarCodeImage() {
        if (empty($_GET['code']))
            exit;
        //Forms::generate_barcode($_GET['code'], false);
        //we stop above and use below since in some small size barcode width the printed barcode can not be scanned
        Forms::generate_type_barcode($_GET['code'], false);
    }

    //ex how to call: http://localhost/trusto/common_controller/GenerateTypeBarCodeImage?code=123&type=C128
    public function GenerateTypeBarCodeImage() {
        if (empty($_GET['code']))
            exit;
        Forms::generate_type_barcode($_GET['code'], false, (empty($_GET['type']) ? null : $_GET['type']));
    }

    public function vehicle_cron_job() {
        $this->vehicle_class->vehicle_rent_cron();
    }

}
