Example #1
0
function report($con, $rollno, $comp_name, $c_id, $from, $till, $type, $schedule, $holid, $chart, $p)
{
    $comp_roll = $rollno;
    $query2 = "\n                    SELECT timestamp \n                    FROM attendance \n                    WHERE userid='{$rollno}'\tAND DATE(timestamp) BETWEEN '{$from}' AND '{$till}' \n\t\t\t\t\t\t";
    $result2 = mysqli_query($con, $query2) or die("Error: " . mysqli_error($con));
    //array storing student's TimeStamp in the entered window of $from and $till
    $ts = array();
    while ($row2 = mysqli_fetch_array($result2)) {
        array_push($ts, $row2['timestamp']);
    }
    //length of array storing student's timestamp
    $ts_length = count($ts);
    //counter
    $i = 0;
    // Set timezone
    date_default_timezone_set('UTC');
    // Start date
    $date = $from;
    // End date
    $end_date = $till;
    //finding total expected classes
    //outer loop goes from '$from' to '$till'
    //in each outer loop inner loop goes from '$ts[0]' to '$ts[$ts_length - 1]
    //if students entry time in '$ts' is between scheduled classes then assign present
    //no need to asssign absent because it has been done in initialized
    //holidays are considered while printing
    //so consider
    //1.scheduled class
    //2.extra class
    //3.cancel class
    while (strtotime($date) <= strtotime($end_date)) {
        $dt = new DateTime($date);
        $day = $dt->format('l');
        //day
        $d = $dt->format('Y-m-d');
        //date
        //counter
        $i = 0;
        //will enter the loop only if student is present at-least once
        while ($i < $ts_length) {
            $user_timestamp = date_create($ts[$i]);
            $user_date = date_format($user_timestamp, 'Y-m-d');
            $user_time = date_format($user_timestamp, 'H:i:s');
            //if only one class on this date
            //condition = count + date + start_time + finishing_time
            if ($schedule[$day][0] == 1 and $d == $user_date and $user_time >= $schedule[$day][1] and $user_time <= $schedule[$day][2]) {
                //in time range of class
                if (cancel_check($con, $d, $c_id, $schedule[$day][1], $schedule[$day][2])) {
                    //if not cancelled then it's scheduled
                    $chart[$d][5] = "Scheduled";
                    $chart[$d][6] = $user_time;
                    $chart[$d][7] = "Present";
                } else {
                    //if cancelled
                    $chart[$d][5] = "Cancel";
                    $chart[$d][6] = "";
                    $chart[$d][7] = "";
                }
            } else {
                if ($schedule[$day][0] == 1 and $d == $user_date and $user_time <= $schedule[$day][1] || $user_time >= $schedule[$day][2]) {
                }
            }
            //if two classes on this date
            if ($schedule[$day][0] == 2) {
                //if first isn't cancelled
                if (cancel_check($con, $d, $c_id, $schedule[$day][1], $schedule[$day][2])) {
                    if ($d == $user_date and $user_time >= $schedule[$day][1] and $user_time <= $schedule[$day][2]) {
                        //if student entry time is in scheduled class timing
                        $chart[$d][5] = "Scheduled";
                        $chart[$d][6] = $user_time;
                        $chart[$d][7] = "Present";
                    } else {
                        if ($d == $user_date and $user_time <= $schedule[$day][1] || $user_time >= $schedule[$day][2]) {
                        }
                    }
                } else {
                    $chart[$d][5] = "Cancelled";
                    $chart[$d][6] = " ";
                    $chart[$d][7] = " ";
                }
                //if second class of the day isn't cancelled
                if (cancel_check($con, $d, $c_id, $schedule[$day][3], $schedule[$day][4])) {
                    //if user entry time is between scheduled class
                    if ($d == $user_date and $user_time >= $schedule[$day][3] and $user_time <= $schedule[$day][4]) {
                        $chart[$d][9][0][5] = "Scheduled";
                        $chart[$d][9][0][6] = $user_time;
                        $chart[$d][9][0][7] = "Present";
                    } else {
                        if ($d == $user_date and $user_time <= $schedule[$day][3] || $user_time >= $schedule[$day][4]) {
                        }
                    }
                } else {
                    $chart[$d][9][0][5] = "Cancelled";
                    $chart[$d][9][0][6] = " ";
                    $chart[$d][9][0][7] = " ";
                }
            }
            //if three classes on this date
            if ($schedule[$day][0] == 3) {
                //if first isn't cancelled
                if (cancel_check($con, $d, $c_id, $schedule[$day][1], $schedule[$day][2])) {
                    if ($d == $user_date and $user_time >= $schedule[$day][1] and $user_time <= $schedule[$day][2]) {
                        //if student entry time is in scheduled class timing
                        $chart[$d][5] = "Scheduled";
                        $chart[$d][6] = $user_time;
                        $chart[$d][7] = "Present";
                    } else {
                        if ($d == $user_date and $user_time <= $schedule[$day][1] || $user_time >= $schedule[$day][2]) {
                        }
                    }
                } else {
                    $chart[$d][5] = "Cancelled";
                    $chart[$d][6] = " ";
                    $chart[$d][7] = " ";
                }
                //if second class of the day isn't cancelled
                if (cancel_check($con, $d, $c_id, $schedule[$day][3], $schedule[$day][4])) {
                    //if user entry time is between scheduled class
                    if ($d == $user_date and $user_time >= $schedule[$day][3] and $user_time <= $schedule[$day][4]) {
                        $chart[$d][9][0][5] = "Scheduled";
                        $chart[$d][9][0][6] = $user_time;
                        $chart[$d][9][0][7] = "Present";
                    } else {
                        if ($d == $user_date and $user_time <= $schedule[$day][3] || $user_time >= $schedule[$day][4]) {
                        }
                    }
                } else {
                    $chart[$d][9][0][5] = "Cancelled";
                    $chart[$d][9][0][6] = " ";
                    $chart[$d][9][0][7] = " ";
                }
                //if third class of the day isn't cancelled
                if (cancel_check($con, $d, $c_id, $schedule[$day][6], $schedule[$day][7])) {
                    //if user entry time is between scheduled class
                    if ($d == $user_date and $user_time >= $schedule[$day][6] and $user_time <= $schedule[$day][7]) {
                        $chart[$d][9][1][5] = "Scheduled";
                        $chart[$d][9][1][6] = $user_time;
                        $chart[$d][9][1][7] = "Present";
                    } else {
                        if ($d == $user_date and $user_time <= $schedule[$day][6] || $user_time >= $schedule[$day][7]) {
                        }
                    }
                } else {
                    $chart[$d][9][1][5] = "Cancelled";
                    $chart[$d][9][1][6] = " ";
                    $chart[$d][9][1][7] = " ";
                }
            }
            //checking for extra classes
            //add to chart and also decide present or absent
            $query = "\n                            SELECT time1_start , time1_end\n                            FROM alter_class \n                            WHERE course_id='{$c_id}' AND date='{$d}' AND type='E'\n\t\t\t\t\t\t";
            $result = mysqli_query($con, $query) or die("Error: " . mysqli_error($con));
            $extra = array();
            $count = 0;
            $chart[$d][8] = 0;
            while ($row = mysqli_fetch_array($result)) {
                $chart2[$d][0] = $d;
                $chart2[$d][1] = $day;
                $chart2[$d][2] = $row['time1_start'];
                $chart2[$d][3] = $row['time1_end'];
                $chart2[$d][4] = "Extra";
                $chart2[$d][5] = "";
                $chart2[$d][6] = "Absent";
                if ($user_time >= $row['time1_start'] and $user_time <= $row['time1_end']) {
                    $chart2[$d][5] = $user_time;
                    $chart2[$d][6] = "Present";
                }
                $extra[$count] = array($chart2[$d][0], $chart2[$d][1], $chart2[$d][2], $chart2[$d][3], $chart2[$d][4], $chart2[$d][5], $chart2[$d][6]);
                $count = $count + 1;
            }
            $chart[$d][10] = $extra;
            $chart[$d][8] = $count;
            //next index of $ts[]
            $i = $i + 1;
        }
        //end of inner while loop
        //for those students whose $ts_length=0
        //chart has been initialized as absent for all scheduled class
        //so add information about only extra classes now
        if ($ts_length == 0) {
            //checking for extra classes
            $query1 = "\n                            SELECT time1_start , time1_end\n                            FROM alter_class \n                            WHERE course_id='{$c_id}' AND date='{$d}' AND type='E'\n\t\t\t\t\t\t";
            $result1 = mysqli_query($con, $query1) or die("Error: " . mysqli_error($con));
            $extraaa = array();
            $counttt = 0;
            $chart[$d][8] = 0;
            while ($row = mysqli_fetch_array($result1)) {
                $chart[$d][8] = 1;
                $chart2[$d][0] = $d;
                $chart2[$d][1] = $day;
                $chart2[$d][2] = $row['time1_start'];
                $chart2[$d][3] = $row['time1_end'];
                $chart2[$d][4] = "Extra";
                $chart2[$d][5] = "";
                $chart2[$d][6] = "Absent";
                $extraaa[$counttt] = array($chart2[$d][0], $chart2[$d][1], $chart2[$d][2], $chart2[$d][3], $chart2[$d][4], $chart2[$d][5], $chart2[$d][6]);
                $counttt = $counttt + 1;
            }
            $chart[$d][10] = $extraaa;
            $chart[$d][8] = $counttt;
        }
        //end of ts=0 condition
        $date = date("Y-m-d", strtotime("+1 day", strtotime($date)));
    }
    //outer while loop ends
    //if user wanted to export this data
    //variable $_SESSION['Export'] has been set in class_attend file in if(array_exist(export))
    if ($_SESSION['Export'] != "Yes") {
        print_chart($chart, $from, $till, $type, $holid, $comp_name, $comp_roll, $p);
    } else {
        export($chart, $from, $till, $type, $holid, $comp_name, $comp_roll, $p);
    }
}
Example #2
0
function report($con, $rollno, $c_id, $from, $till, $type, $schedule)
{
    //intialize holiday array
    //$holid[date] = 1 if holiday or else 0
    $holid = array();
    $holid = initialize_holid($holid, $from, $till, $con);
    //$schedule = array();
    //$schedule = get_schedule($schedule, $c_id, $con);
    /*
    //setting default schedule 
    //setting all values to 00:00:00
    //$schedule = array();
    //$schedule = initialize_schedule($schedule);
    
    //query for expected scheduling and extra classes	
    $query1 = "
            	SELECT count , time1_start , time1_end , time2_start , time2_end , day		  
    			FROM course_schedule 
    			WHERE course_id = '$c_id'
    	          ";
    
    $result1 = mysqli_query($con, $query1) or die("Error: " . mysqli_error($con));
    
    //scheduled is day wise
    //so following thing have been saved 
    //0 -   count   -   how many classes ?
    //1 -   time1_start
    //2 -   time1_end
    //3 -   time2_start
    //4 -   time2_end
    //5 -   day
    
    while ($row1 = mysqli_fetch_array($result1)) 
    {
        $schedule[$row1['day']] = array($row1['count'], $row1['time1_start'], $row1['time1_end'], $row1['time2_start'], $row1['time2_end'], $row1['day']);
    }//scheduled array for all scheduled slots in week stored
    */
    //setting up the chart table
    //actual report
    $chart = array();
    $chart1 = array();
    $chart2 = array();
    //chart_initialize
    $chart = initialize_chart($chart, $chart1, $schedule, $from, $till, $con, $c_id);
    //timestamp of student in then given interval (independent of all courses)
    $query2 = "\n\t\t\t\t\t\tSELECT timestamp \n\t\t\t\t\t\tFROM attendance \n\t\t\t\t\t\tWHERE userid='{$rollno}'\tAND DATE(timestamp) BETWEEN '{$from}' AND '{$till}' \n\t\t\t\t\t\t";
    $result2 = mysqli_query($con, $query2) or die("Error: " . mysqli_error($con));
    //array storing student's timestamp
    $ts = array();
    while ($row2 = mysqli_fetch_array($result2)) {
        array_push($ts, $row2['timestamp']);
    }
    //length of array storing student's timestamp
    $ts_length = count($ts);
    echo "ts    -   {$ts_length}<br>";
    //counter
    $i = 0;
    // Set timezone
    date_default_timezone_set('UTC');
    // Start date
    $date = $from;
    // End date
    $end_date = $till;
    //finding total expected classes
    while (strtotime($date) <= strtotime($end_date)) {
        //outer loop goes from '$from' to '$till' checking for classes and timestamp in $ts
        //in ech outer loop inner loop goes from '$ts[0]' to '$ts[$ts_length - 1]
        //if students entry time in '$ts' is between scheduled classes then assign present
        $dt = new DateTime($date);
        $day = $dt->format('l');
        //day
        $d = $dt->format('Y-m-d');
        //date
        //counter
        $i = 0;
        //will enter the loop only if student is present atleast once
        while ($i < $ts_length) {
            $user_timestamp = date_create($ts[$i]);
            $user_date = date_format($user_timestamp, 'Y-m-d');
            $user_time = date_format($user_timestamp, 'H:i:s');
            //if only one class on this date
            //condition = count + date + start_time + finishing_time
            if ($schedule[$day][0] == 1 and $d == $user_date and $user_time >= $schedule[$day][1] and $user_time <= $schedule[$day][2]) {
                //in time range of class
                if (cancel_check($con, $d, $c_id, $schedule[$day][1], $schedule[$day][2])) {
                    //if not cancelled then it's scheduled
                    $chart[$d][5] = "Scheduled";
                    $chart[$d][6] = $user_time;
                    $chart[$d][7] = "Present";
                } else {
                    //if cancelled
                    $chart[$d][5] = "Cancel";
                    $chart[$d][6] = "";
                    $chart[$d][7] = "";
                }
            } else {
                if ($schedule[$day][0] == 1 and $d == $user_date and $user_time <= $schedule[$day][1] || $user_time >= $schedule[$day][2]) {
                }
            }
            //if two classes on this date
            if ($schedule[$day][0] == 2) {
                //if first isn't cancelled
                if (cancel_check($con, $d, $c_id, $schedule[$day][1], $schedule[$day][2])) {
                    if ($d == $user_date and $user_time >= $schedule[$day][1] and $user_time <= $schedule[$day][2]) {
                        //if student entry time is in scheduled class timing
                        $chart[$d][5] = "Scheduled";
                        $chart[$d][6] = $user_time;
                        $chart[$d][7] = "Present";
                    } else {
                        if ($d == $user_date and $user_time <= $schedule[$day][1] || $user_time >= $schedule[$day][2]) {
                        }
                    }
                } else {
                    $chart[$d][5] = "Cancelled";
                    $chart[$d][6] = " ";
                    $chart[$d][7] = " ";
                }
                //if second class of the day isn't cancelled
                if (cancel_check($con, $d, $c_id, $schedule[$day][3], $schedule[$day][4])) {
                    //if user entry time is between scheduled class
                    if ($d == $user_date and $user_time >= $schedule[$day][3] and $user_time <= $schedule[$day][4]) {
                        $chart[$d][9][5] = "Scheduled";
                        $chart[$d][9][6] = $user_time;
                        $chart[$d][9][7] = "Present";
                    } else {
                        if ($d == $user_date and $user_time <= $schedule[$day][3] || $user_time >= $schedule[$day][4]) {
                        }
                    }
                } else {
                    $chart[$d][9][5] = "Cancelled";
                    $chart[$d][9][6] = " ";
                    $chart[$d][9][7] = " ";
                }
            }
            //checking for extra classes
            $query = "\n                            SELECT time1_start , time1_end\n                            FROM alter_class \n                            WHERE course_id='{$c_id}' AND date='{$d}' AND type='E'\n\t\t\t";
            $result = mysqli_query($con, $query) or die("Error: " . mysqli_error($con));
            while ($row = mysqli_fetch_array($result)) {
                $chart[$d][8] = 1;
                $chart2[$d][0] = $d;
                $chart2[$d][1] = $day;
                $chart2[$d][2] = $row['time1_start'];
                $chart2[$d][3] = $row['time1_end'];
                $chart2[$d][4] = "Extra";
                $chart2[$d][5] = "";
                $chart2[$d][6] = "Absent";
                if ($user_time >= $row['time1_start'] and $user_time <= $row['time1_end']) {
                    $chart2[$d][5] = $user_time;
                    $chart2[$d][6] = "Present";
                }
                $chart[$d][10] = array($chart2[$d][0], $chart2[$d][1], $chart2[$d][2], $chart2[$d][3], $chart2[$d][4], $chart2[$d][5], $chart2[$d][6]);
            }
            //next index of $ts[]
            $i = $i + 1;
        }
        //checking for extra finished
        //for those students whose $ts_length=0
        if ($ts_length == 0) {
            //checking for extra classes
            $query1 = "\n                            SELECT time1_start , time1_end\n                            FROM alter_class \n                            WHERE course_id='{$c_id}' AND date='{$d}' AND type='E'\n\t\t\t";
            $result1 = mysqli_query($con, $query1) or die("Error: " . mysqli_error($con));
            while ($row = mysqli_fetch_array($result1)) {
                $chart[$d][8] = 1;
                $chart2[$d][0] = $d;
                $chart2[$d][1] = $day;
                $chart2[$d][2] = $row['time1_start'];
                $chart2[$d][3] = $row['time1_end'];
                $chart2[$d][4] = "Extra";
                $chart2[$d][5] = "";
                $chart2[$d][6] = "Absent";
                $chart[$d][10] = array($chart2[$d][0], $chart2[$d][1], $chart2[$d][2], $chart2[$d][3], $chart2[$d][4], $chart2[$d][5], $chart2[$d][6]);
            }
        }
        $date = date("Y-m-d", strtotime("+1 day", strtotime($date)));
    }
    //while loop ends
    print_chart($chart, $from, $till, $type, $holid);
}