-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexport.php
86 lines (57 loc) · 1.52 KB
/
export.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
//session_start();
$nojunk='';
require_once 'project_common.php';
require_once 'base/verify_login.php';
$link=get_link($GLOBALS['main_user'],$GLOBALS['main_pass']);
//////////////////Code for salary//////////
//echo '<pre>';print_r($_POST);echo '</pre>';
$ex_sample_id=explode(',',$_POST['sample_id']);
//print_r($ex_sample_id);
//export_h_examination($link);
$fp = fopen('php://output', 'w');
if ($fp)
{
header('Content-Type: text/csv');
header('Content-Disposition: attachment; filename="export.csv"');
}
$ex_list=export_h_examination($link);
fputcsv($fp, $ex_list);
foreach($ex_sample_id as $val)
{
$result_data=export_h_result($link,$val,$ex_list);
fputcsv($fp, $result_data);
}
function export_h_examination($link)
{
$sql='select * from profile order by profile_id';
$result=run_query($link,$GLOBALS['database'],$sql);
$ret=array(0=>'DbID');
//print_r($ret);
while($ar=mysqli_fetch_assoc($result))
{
$explod=explode(',',$ar['examination_id_list']);
foreach($explod as $v)
{
$ex_detail=get_one_examination_details($link,$v);
$ret[$v]=$ex_detail['name'];
}
}
return $ret;
}
function export_h_result($link,$sample_id,$ex_list)
{
foreach($ex_list as $k=>$v)
{
$sql='select * from result where sample_id=\''.$sample_id.'\' and examination_id=\''.$k.'\'';
//echo $sql;
$result=run_query($link,$GLOBALS['database'],$sql);
$ar=get_single_row($result);
//print_r($ar);
$ret[$k]=isset($ar['result'])?$ar['result']:'';
//print_r( $ret);
}
$ret['0']=$sample_id;
return $ret;
}
?>