function print_review($array)
{
    echo "<table border=\"1\" style=\"white-space: nowrap; border-collapse:collapse\">";
    foreach ($array as $row) {
        if (preg_match('[^A(0|1)00.{5}]i', $row['A'])) {
            $student_id = $row['A'];
            $query = "select `student_id` " . "FROM course_section, attendance " . "WHERE course_section.section_id = attendance.section_id " . "AND attendance.student_id = '" . $student_id . "'";
            if (mysql_num_rows(mysql_query($query)) === 0) {
                echo '<tr>';
                foreach ($row as $data) {
                    echo "<td bgcolor=\"#FF0000\">" . $data . "</td>";
                }
                echo '</tr>';
            } else {
                echo '<tr>';
                foreach ($row as $data) {
                    echo '<td >' . $data . '</td>';
                }
                echo '</tr>';
            }
        } else {
            echo '<tr>';
            foreach ($row as $data) {
                if (preg_match('/^\\d{5}$/', $data)) {
                    echo '<td >' . date("d/M", strtotime(int_to_time($data))) . '</td>';
                } else {
                    echo '<td >' . $data . '</td>';
                }
            }
            echo '</tr>';
        }
    }
    echo '</table>';
    echo '<br>';
    echo '<br>';
    echo '<br>';
}
function insert_attendance($data_array)
{
    $dates = find_course_info($data_array)[1];
    $course_code = find_course_info($data_array)[0][0];
    $section = find_course_info($data_array)[0][1];
    $crn_query = "SELECT `CRN` FROM `course` " . "WHERE `course_code`='" . $course_code . "'";
    $crn = mysql_result(mysql_query($crn_query), 0);
    //the assumption here is that no two rows in Course_section have same values for course_crn
    $sec_query = "SELECT `section_id`, `instructor_id` FROM `Course_Section` " . "WHERE `course_CRN` = '" . $crn . "' AND `section` = '" . $section . "'";
    $section_id = mysql_result(mysql_query($sec_query), 0);
    //echo $section_id;
    $instructor_id = mysql_result(mysql_query($sec_query), 0, "instructor_id");
    $tot = 0;
    foreach (students_info($data_array) as $student) {
        $student_id = $student[0];
        for ($i = 3; $i < count($student); $i++) {
            $date = int_to_time($dates[$i - 3]);
            $status = mysql_real_escape_string($student[$i]);
            //print_r($student);
            $insert_attendance = "INSERT INTO `Attendance` (`attendance_id`, `student_id`, `section_id`, `course_CRN`, `instructor_id`, `status`, `date`, `timestamp`) " . "SELECT '',  '" . $student_id . "', '" . $section_id . "',  '" . $crn . "',  '" . $instructor_id . "',  NULLIF('" . $status . "', ' '), '" . $date . "', NOW() FROM dual " . "WHERE NOT EXISTS (" . " SELECT * FROM `Attendance` " . "WHERE " . "`student_id` = '" . $student_id . "' " . "AND `section_id` = '" . $section_id . "' " . "AND `course_CRN` = '" . $crn . "' " . "AND `instructor_id`='" . $instructor_id . "' " . "AND `date` = '" . $date . "' ) " . "LIMIT 1";
            mysql_query($insert_attendance);
            $tot = $tot + mysql_affected_rows();
            echo mysql_error();
        }
    }
    echo $tot . " new attendances added" . '<br>';
    echo mysql_error();
}