-
Notifications
You must be signed in to change notification settings - Fork 0
/
export_excel.php
48 lines (48 loc) · 2.5 KB
/
export_excel.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php require_once("includes/Database.php"); ?>
<?php require_once("includes/functions.php");
$result;
$filename;
if((isset($_GET["location"])) && (isset($_GET["fordate"])) && (isset($_GET["todate"]))){
$location = escape_it($_GET["location"]);
$date = escape_it($_GET["fordate"]);
$to_date = escape_it($_GET["todate"]);
$filename = $location.$date."-".$to_date.".csv";
$result = view_Admin_From_To_Entries($location, $date, $to_date);}
elseif((isset($_GET["location"])) && (isset($_GET["fordate"]))){
$location = escape_it($_GET["location"]);
$date = escape_it($_GET["fordate"]);
$filename = "Attendance".$location.$date.".csv";
$result = view_Admin_Entries($location, $date);}
if(mysqli_num_rows($result) > 0){
$f = fopen('php://memory', 'w');
$sr_no = 1;
$new_array = array();
$array = array("Sr No", "Employee Id", "Staff Name", "Status Option", "Site Location", "Code", "Time In", "Time Out" , "Hours", "Comments", "Date");
function write_array($arrayy) {
global $f;
fputcsv($f, $arrayy);}
write_array($array);
$sr_no = 1;
while($entery = mysqli_fetch_assoc($result)){
$employee_id = convert($entery['attendance_emp_id']);
$employee_name = getemployeename($employee_id);
$employee_internal_id = get_Employee_Internalid($employee_id);
$attendance_id = convert($entery['attendance_id']);
$the_status_option = convert($entery['status_option']);
$the_site_location = convert($entery['site_location']);
$time_in = convert($entery['time_in']);
$time_out = convert($entery['time_out']);
$hours_worked = convert($entery['hours_worked']);
$the_remarks_option = convert($entery['remarks']);
$comment = convert($entery['comment']);
$date = convert($entery['attendance_for_date']);
$abc = array($sr_no++, $employee_internal_id, $employee_name, $the_status_option, $the_site_location, $the_remarks_option, $time_in, $time_out, $hours_worked, $comment, $date);
write_array($abc);}
header("Content-Disposition:attachment;filename='{$filename}'");
header("Content-Type:application/csv");
fseek($f, 0);
fpassthru($f);
fclose($f);}else{
echo "nothing to download";
}
?>