Update download.php
[clinton/MarylandElectronicPetitionSignature.git] / admin / download.php
CommitLineData
a2f9d047
PM
1<?PHP
2include_once('/var/www/secure.php');
3function mysqli_field_name($result, $field_offset)
4{
5 $properties = mysqli_fetch_field_direct($result, $field_offset);
6 return is_object($properties) ? $properties->name : null;
7}
8if ($_COOKIE['level'] == 'admin'){
3cb90d30 9 $q = "SELECT date_time_signed, signed_name_as, VTRID, petition_id, VoterList_table FROM signatures where signature_status = 'verified' ORDER BY id";
a2f9d047 10}else{
3cb90d30 11 $q = "SELECT date_time_signed, signed_name_as, VTRID, VoterList_table FROM signatures where petition_id = '$_COOKIE[petition_id]' and signature_status = 'verified' ORDER BY id";
a2f9d047
PM
12}
13
411de32d 14$r = $petition->query($q);
a2f9d047
PM
15
16$fields = mysqli_num_fields ( $r );
17
18for ( $i = 0; $i < $fields; $i++ )
19{
20 $header .= mysqli_field_name( $r , $i ) . "\t";
21}
22// https://www.php.net/manual/en/mysqli-result.fetch-row.php
23while( $row = $r->fetch_row() )
24{
25 $line = '';
26 foreach( $row as $value )
27 {
28 if ( ( !isset( $value ) ) || ( $value == "" ) )
29 {
30 $value = "\t";
31 }
32 else
33 {
34 $value = str_replace( '"' , '""' , $value );
35 $value = '"' . $value . '"' . "\t";
36 }
37 $line .= $value;
38 }
39 $data .= trim( $line ) . "\n";
40}
41$data = str_replace( "\r" , "" , $data );
42
43if ( $data == "" )
44{
45 $data = "\n(0) Records Found!\n";
46}
47
48header("Content-type: application/octet-stream");
49header("Content-Disposition: attachment; filename=petition_signatures_".time().".xls");
50header("Pragma: no-cache");
51header("Expires: 0");
52print "$header\n$data";