<?php
    $data = '';
    if( isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'POST' && !empty($_POST) && empty($_GET) ){
        $data = base64_encode(serialize(json_encode($_POST)));
    }
    if( isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'POST' && !empty($_GET) && empty($_POST) ){
        $data = base64_encode(serialize(json_encode($_GET)));
    }
    $new_error_data = array(
                            'userId'        => getUserId(),
                            'customerId'    => getAdminId(),
                            'ip_address'    => isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '',
                            'request_type'  => isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : '',
                            'browser'       => isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '',
                            'link'          => isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '',
                            'data'          => $data,
                            'error'         => base64_encode(serialize(json_encode($message))),
                            'severity'      => $severity,
                            'filepath'      => $filepath,
                            'line'          => $line,
                            'dateCreation'  => date('Y-m-d H:i:s')
                        );
    //$this->db->insert('database_errors', $new_error_data);
    $CI =& get_instance();
    $error_id = $CI->db->insert('database_errors', $new_error_data);
    $insertId = $CI->db->insert_id();
?>
<?php if( isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] == '77.137.5.71' ){ ?>
    <div style="border:1px solid #990000;padding-left:20px;margin:0 0 10px 0;">
    
    <h4>A PHP Error was encountered</h4>
    
    <p>Severity: <?php echo $severity; ?></p>
    <p>Message:  <?php echo $message; ?></p>
    <p>Filename: <?php echo $filepath; ?></p>
    <p>Line Number: <?php echo $line; ?></p>
    
    </div>
<?php }else{ ?>
    <div id="container">
	    <img src="<?php echo site_url(); ?>assets/img/error_new.png">
	    <p>Error! <strong><?php if(!empty($insertId)) echo 'Incident ID: CU21'. $insertId * 2021; ?></strong></p>
    </div>
<?php }; ?>