$FILE_NAME = $_SERVER['PHP_SELF'];
//QUERY the $semesterListArray
$SEMESTER_TABLE_NAME = $PAGE_INFO_ARRAY[$SEMESTER_PAGE_SWITCH]['TABLE_NAME'];
$SEMESTER_TABLE_KEY_NAMES_ARRAY = $TABLE_KEY_NAMES_ARRAY[$SEMESTER_PAGE_SWITCH];
$semesterListArray = table_data_query($SEMESTER_TABLE_NAME, $SEMESTER_TABLE_KEY_NAMES_ARRAY);
$semesterTargetArray = $_POST['semesterList'];
//QUERY the $courseListArray
$COURSE_TABLE_NAME = table_name_form($PAGE_INFO_ARRAY, $COURSE_PAGE_SWITCH, $semesterListArray, $semesterTargetArray);
$COURSE_TABLE_KEY_NAMES_ARRAY = table_key_names_array_get($COURSE_TABLE_NAME);
$courseListArray = table_data_query($COURSE_TABLE_NAME, $COURSE_TABLE_KEY_NAMES_ARRAY);
//Load $CLASS_TABLE_NAME
$CLASS_TABLE_NAME = table_name_form($PAGE_INFO_ARRAY, $CLASS_PAGE_SWITCH, $semesterListArray, $semesterTargetArray);
//Load import data
if ($_POST['upload']) {
    $classImportInfoArray = uploaded_file_data_load();
    $classInsertInfoArray = import_data_form($classImportInfoArray);
    //ADD the COURSE data
    $CLASS_TABLE_KEY_NAMES_ARRAY = array_picker($classImportInfoArray, 0);
    //Pick the table key names from import array.
    $CLASS_TABLE_KEY_NAMES_ARRAY = array_key_insert($CLASS_TABLE_KEY_NAMES_ARRAY, "ID", "ID");
    //The imporrt data not include ID key, so add it.
    $CLASS_TABLE_KEY_TYPES_ARRAY = table_key_types_auto_fill($CLASS_TABLE_KEY_TYPES_ARRAY, $CLASS_TABLE_KEY_NAMES_ARRAY, 0, "varchar(15)", 1);
    $CLASS_TABLE_KEY_TYPES_ARRAY = array_key_insert($CLASS_TABLE_KEY_TYPES_ARRAY, "ID", "int NOT NULL AUTO_INCREMENT, PRIMARY KEY(ID)");
    //COURSE_LEFT TABLE structure create
    $courseListArrayCount0 = count($courseListArray);
    for ($i = 0; $i < $courseListArrayCount0; $i++) {
        $CLASS_TABLE_KEY_NAMES_ARRAY = array_key_insert($CLASS_TABLE_KEY_NAMES_ARRAY, $courseListArray[$i]['COURSE_KEY_NAME'], $courseListArray[$i]['COURSE_KEY_NAME']);
        $CLASS_TABLE_KEY_TYPES_ARRAY = array_key_insert($CLASS_TABLE_KEY_TYPES_ARRAY, $courseListArray[$i]['COURSE_KEY_NAME'], "varchar(15)");
    }
    database_table_create($CLASS_TABLE_NAME, $CLASS_TABLE_KEY_NAMES_ARRAY, $CLASS_TABLE_KEY_TYPES_ARRAY);
    $tableKeyNumbersCount = count($classInsertInfoArray);
include 'functions/database_functions.php';
include 'functions/global_functions.php';
include 'functions/views_output_functions.php';
//Load the file name for post
$FILE_NAME = $_SERVER['PHP_SELF'];
//QUERY the $semesterListArray
$SEMESTER_TABLE_NAME = $PAGE_INFO_ARRAY[$SEMESTER_PAGE_SWITCH]['TABLE_NAME'];
$SEMESTER_TABLE_KEY_NAMES_ARRAY = $TABLE_KEY_NAMES_ARRAY[$SEMESTER_PAGE_SWITCH];
$semesterListArray = table_data_query($SEMESTER_TABLE_NAME, $SEMESTER_TABLE_KEY_NAMES_ARRAY);
$semesterTargetArray = $_POST['semesterList'];
//Load $COURSE_TABLE_NAME
$COURSE_TABLE_NAME = table_name_form($PAGE_INFO_ARRAY, $COURSE_PAGE_SWITCH, $semesterListArray, $semesterTargetArray);
//Load import data
if ($_POST['upload']) {
    $courseImportInfoArray = uploaded_file_data_load();
    $courseInsertInfoArray = import_data_form($courseImportInfoArray);
    //COURSE_KEY_NAME info add method.
    $courseInsertInfoArrayCount0 = count($courseInsertInfoArray);
    for ($i = 0; $i < $courseInsertInfoArrayCount0 - 1; $i++) {
        //[BUG][120501_1] Import file have a title line, so that "-1".
        $courseInsertInfoArray[$i]['COURSE_KEY_NAME'] = "COURSE_" . $i;
    }
    //ADD the COURSE data
    $COURSE_TABLE_KEY_NAMES_ARRAY = array_picker($courseImportInfoArray, 0);
    //Pick the table key names from import array.
    $COURSE_TABLE_KEY_NAMES_ARRAY = array_key_insert($COURSE_TABLE_KEY_NAMES_ARRAY, "id", "id");
    //The import data not include ID key, so add it.
    $COURSE_TABLE_KEY_NAMES_ARRAY = array_key_insert($COURSE_TABLE_KEY_NAMES_ARRAY, "COURSE_KEY_NAME", "COURSE_KEY_NAME");
    //The import data not include COURSE_KEY_NAME key, so add it.
    $COURSE_TABLE_KEY_TYPES_ARRAY = table_key_types_auto_fill($COURSE_TABLE_KEY_TYPES_ARRAY, $COURSE_TABLE_KEY_NAMES_ARRAY, 0, "varchar(15)", 1);
    $COURSE_TABLE_KEY_TYPES_ARRAY = array_key_insert($COURSE_TABLE_KEY_TYPES_ARRAY, "id", "int NOT NULL AUTO_INCREMENT, PRIMARY KEY(id)");