<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of errors
 *
 * @author dghai
 */
require_once 'admin_config.php';
require_once 'admin_dao.php';

define('E_VROOM_INSERT_FAILED',                 -7);
define('E_VROOM_EXECUTE_QUERY_FAILED',          -6);
define('E_VROOM_PREPARE_QUERY_FAILED',          -5);
define('E_VROOM_LOAD_RECV_PRI_KEY_FAILED',      -4);
define('E_VROOM_LOAD_SEND_PUB_KEY_FAILED',      -3);
define('E_VROOM_INVALID_FUNCTION_CALL',         -2);
define('E_VROOM_DB_CONNECT_FAILED',             -1);
define('E_VROOM_LOGIN_FAILED',                   1);

$allErrorDescriptions = array(
    E_VROOM_INSERT_FAILED               =>
        'There was error inserting data into the database.',
    E_VROOM_EXECUTE_QUERY_FAILED        =>
        'There was an error executing the query.',
    E_VROOM_PREPARE_QUERY_FAILED        =>
        'Mysqli had problems with preparing the statement to send to DB.',
    E_VROOM_LOAD_RECV_PRI_KEY_FAILED    =>
        'There was an error loading private key to decrypt data.',
    E_VROOM_LOAD_SEND_PUB_KEY_FAILED    =>
        'Loading public key to encrypt data before sending to iPad... failed. Anyway, what\'s up?',
    E_VROOM_INVALID_FUNCTION_CALL       =>   
        'An invalid function call was made. Expected number of parameters were not delivered.',
    E_VROOM_DB_CONNECT_FAILED           =>
        'Could not connect to the database with the given credentials.',
    E_VROOM_LOGIN_FAILED                =>
        'ACCESS_DENIED',
);
class Admin_ErrorObject {
    public $errorCode;
    public $errorDescription;
    
    private $_config;
    
    function __construct($errorCode, $errorDescription = '') 
    {
        global $allErrorDescriptions;
        $this->errorCode = $errorCode;
        if($errorDescription != '')
            $this->errorDescription = $errorDescription;
        else
            $this->errorDescription = $allErrorDescriptions[$errorCode];
        
        $this->_config = new admin_config();
        $this->LogError($errorCode);
    }
    private function LogError($errorCode)
    {
        if(!$this->_config->IsSavingErrorToDbEnabled())
        {
            return;
        }
        if($errorCode == E_VROOM_DB_CONNECT_FAILED)
        {
            //TODO: Log $request to file or server's error log
            return;
        }
        //TODO: Log $request error to DB
    }
}

?>
