<?php

/*
 @ �� ��  �� enter.php
 @ �� ��  �� ��վ�����ļ�
 @ ��     �� /.

*/


// ===== 【安全加固】优先加载统一的 mysql_* -> mysqli 兼容层 =====
// 本文件顶部原本内联了一份旧版兼容层实现，其中 mysql_real_escape_string 在数据库连接
// 未就绪时会直接返回原始字符串(可导致 SQL 注入)。现改为在下方内联块之前先加载已加固
// 的 php_compat_patch.php：函数已定义，下方 if(!function_exists(...)) 内联块将自动跳过，
// 从而全站统一使用安全的兼容层(含字符集安全转义与预处理助手)。
require_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'php_compat_patch.php');

// ===== mysql_* ���ݲ㣨���� PHP 7.0+��=====
if (!function_exists('mysql_connect')) {

    // ȫ�ִ洢���Ӷ���
    $GLOBALS['__mysql_compat_link'] = null;

    function mysql_connect($server, $username, $password) {
        $GLOBALS['__mysql_compat_link'] = mysqli_connect($server, $username, $password);
        if (!$GLOBALS['__mysql_compat_link']) {
            error_log('���ݿ�����ʧ��: ' . mysqli_connect_error() . ' (������: ' . mysqli_connect_errno() . ')');
            return false;
        }
        return $GLOBALS['__mysql_compat_link'];
    }

    function mysql_pconnect($server, $username, $password) {
        // mysqli û�г־����ӵ�ֱ�ӵȼۣ�����ͨ���Ӵ���
        return mysql_connect($server, $username, $password);
    }

    function mysql_select_db($database, $link = null) {
        $link = $link ?: $GLOBALS['__mysql_compat_link'];
        return mysqli_select_db($link, $database);
    }

    function mysql_query($query, $link = null) {
        $link = $link ?: $GLOBALS['__mysql_compat_link'];
        return mysqli_query($link, $query);
    }

    function mysql_fetch_array($result, $type = MYSQLI_BOTH) {
        if (!$result) return false;
        return mysqli_fetch_array($result, $type);
    }

    function mysql_fetch_assoc($result) {
        if (!$result) return false;
        return mysqli_fetch_assoc($result);
    }

    function mysql_fetch_row($result) {
        if (!$result) return false;
        return mysqli_fetch_row($result);
    }

    function mysql_num_rows($result) {
        if (!$result) return 0;
        return mysqli_num_rows($result);
    }

    function mysql_num_fields($result) {
        if (!$result) return 0;
        return mysqli_num_fields($result);
    }

    function mysql_affected_rows($link = null) {
        $link = $link ?: $GLOBALS['__mysql_compat_link'];
        return mysqli_affected_rows($link);
    }

    function mysql_insert_id($link = null) {
        $link = $link ?: $GLOBALS['__mysql_compat_link'];
        return mysqli_insert_id($link);
    }

    function mysql_errno($link = null) {
        $link = $link ?: $GLOBALS['__mysql_compat_link'];
        return mysqli_errno($link);
    }

    function mysql_error($link = null) {
        $link = $link ?: $GLOBALS['__mysql_compat_link'];
        return mysqli_error($link);
    }

    function mysql_real_escape_string($str, $link = null) {
        $link = $link ?: $GLOBALS['__mysql_compat_link'];
        // �ؼ��޸��������Ӷ���Ϊ null ʱ������ԭ�ַ�������ֱ�ӵ��� mysqli_real_escape_string
        if (!$link) {
            error_log('mysql_real_escape_string: ���ݿ�����δ����������ԭʼ�ַ���');
            return $str;
        }
        return mysqli_real_escape_string($link, $str);
    }

    function mysql_free_result($result) {
        if ($result) mysqli_free_result($result);
    }

    function mysql_data_seek($result, $row) {
        return mysqli_data_seek($result, $row);
    }

    function mysql_field_name($result, $i) {
        $info = mysqli_fetch_field_direct($result, $i);
        return $info ? $info->name : false;
    }

    function mysql_field_type($result, $i) {
        $info = mysqli_fetch_field_direct($result, $i);
        return $info ? $info->type : false;
    }

    function mysql_field_len($result, $i) {
        $info = mysqli_fetch_field_direct($result, $i);
        return $info ? $info->length : false;
    }

    function mysql_field_table($result, $i) {
        $info = mysqli_fetch_field_direct($result, $i);
        return $info ? $info->table : false;
    }

    function mysql_field_flags($result, $i) {
        $info = mysqli_fetch_field_direct($result, $i);
        return $info ? $info->flags : false;
    }

    function mysql_list_fields($database, $table, $link = null) {
        $link = $link ?: $GLOBALS['__mysql_compat_link'];
        return mysqli_query($link, "SELECT * FROM `$table` LIMIT 0");
    }

    function mysql_close($link = null) {
        $link = $link ?: $GLOBALS['__mysql_compat_link'];
        return mysqli_close($link);
    }

    // ���� MYSQL_ASSOC / MYSQL_NUM / MYSQL_BOTH ����
    if (!defined('MYSQL_ASSOC'))  define('MYSQL_ASSOC',  MYSQLI_ASSOC);
    if (!defined('MYSQL_NUM'))    define('MYSQL_NUM',    MYSQLI_NUM);
    if (!defined('MYSQL_BOTH'))   define('MYSQL_BOTH',   MYSQLI_BOTH);
}
// ===== ���ݲ���� =====

// �޸���PHP �� # ��ע�ͷ��ţ�#include_once ���ᱻִ�У�Ӧ��Ϊ include_once
//include_once 'php_compat_patch.php';
define( '_EXEC', 1 );//������ֹ�Ƿ����ʵ�

define('PATH_BASE', dirname(__FILE__));								//��Ŀ¼����
define( 'DS', DIRECTORY_SEPARATOR );									//Ŀ¼�����
//$_SERVER["DOCUMENT_ROOT"]
define('PATH_CONTROLLER',PATH_BASE.DS.'templates');			//��ʼ��·��ģ��,�����������ģ�����Ǹ��ļ���
require(PATH_BASE.DS.'libraries'.DS.'includes'.DS.'common.php');		//���ؿ����

// ���ԣ�������ݿ������Ƿ��ѽ���
if (function_exists('mysql_connect')) {
    // �� dispatch ǰ���ȫ�����ӱ���
    if (empty($GLOBALS['__mysql_compat_link'])) {
        error_log('���棺dispatch ִ��ǰ���ݿ�����δ����');
    }
}

$controller=new Controller();
$controller->dispatch($_GET);


?>