include 'includes/function.php';
include 'includes/session_define.php';
include 'includes/header.php';
include 'includes/menu.php';
?>
 <?php 
if (!isset($_SESSION['multiple_course_major'])) {
    redirect_to("select_multiple_course_report.php");
}
$student_list = array();
$major = $_SESSION['multiple_course_major'];
if ($major == "ALL") {
    $set = all_major_course();
    $course = $set['required'];
    $fcourse = $set['foundation'];
    $majorlist = getMajorsList();
    $majorlist = array_column($majorlist, 'major');
    for ($i = 0; $i < sizeof($majorlist); $i++) {
        $list['Option'] = $majorlist[$i];
        $student_list = array_merge($student_list, search_student($list));
    }
    $loop2 = sizeof($student_list);
    //echo "<pre>";print_r($student_list);
} else {
    $set = all_courses($major);
    $course = $set['required'];
    $fcourse = $set['foundation'];
    $list['Option'] = $major;
    $student_list = search_student($list);
    $loop2 = sizeof($student_list);
    //echo "<pre>";print_r($student_list);
    if (isset($_POST['start_year'])) {
        if ($i == $_POST['start_year']) {
            echo " selected";
        }
    }
    echo ">" . $i . "</option>";
}
?>
            </select>
         </td>
    </tr>
    <tr class="name">
    <td><label for="major">Major</label></td>
      <td><select name="major" id="major">
                    <?php 
$row = getMajorsList();
$loop = sizeof($row);
for ($i = 0; $i < $loop; $i++) {
    $option = $row[$i]['major'];
    //$option = $row[$i]['last_name'];
    echo '<option value="' . $option . '"';
    if (isset($_POST['major'])) {
        if ($option == $_POST['major']) {
            echo " selected";
        }
    }
    echo '>' . $option . '</option>';
}
?>
                  </select></td>
    </tr>
function all_major_course()
{
    $dbc = dbconnect('local');
    $resultset['required'] = array();
    $resultset['foundation'] = array();
    $list = getMajorsList();
    $list = array_column($list, 'major');
    //	echo "<pre>";print_r($list);
    //echo "<pre>";print_r($resultset);
    //echo "<pre>";print_r($result);
    for ($i = 0; $i < sizeof($list); $i++) {
        $result = all_courses($list[$i]);
        //print_r($result);
        if (!empty($result)) {
            $resultset['required'] = array_merge($resultset['required'], $result['required']);
            $resultset['foundation'] = array_merge($resultset['foundation'], $result['foundation']);
        }
    }
    $set['required'] = unique_array($resultset['required']);
    asort($set['required']);
    $set['foundation'] = unique_array($resultset['foundation']);
    asort($set['foundation']);
    //echo "<pre>";print_r($set);
    return $set;
}