9e5648ea3d6e2345d9e3f43aaef10e5d9eee3eae
[atutor.git] / mods / ecomm / payments_export_csv.php
1 <?php
2 exit;
3 define('AT_INCLUDE_PATH', '../../include/');
4 require(AT_INCLUDE_PATH.'vitals.inc.php');
5
6 $sql1 = stripslashes(urldecode($_GET['thisquery']));
7 $result1 = mysql_query($sql1,$db);
8 $today = date("Y-m-d_h-m-s");
9 $path = AT_CONTENT_DIR . 'payments_'.$today.'.csv';
10
11 function quote_csv($line) {
12         $line = str_replace('"','""', $line);
13         $line = str_replace(",", "", $line);
14         //$line = str_replace("\n", '\n', $line);
15         //$line = str_replace("\r", '\r', $line);
16         $line = str_replace("\x00", '\0', $line);
17         $line = trim($line);
18
19         return '"'.$line.'"';
20 }
21         $fp = fopen($path, 'w');
22         $this_purchase .= ''; 
23         while($row = mysql_fetch_array($result1)){
24                 $this_purchase .= quote_csv($row['shopid']);
25                 $this_purchase .= quote_csv($row['member_id']);
26                 $this_purchase .= quote_csv($row['firstname']);
27                 $this_purchase .= quote_csv($row['lastname']);
28                 $this_purchase .= quote_csv($row['email']);
29                 $this_purchase .= quote_csv($row['organization']);
30                 $this_purchase .= quote_csv($row['address']);
31                 $this_purchase .= quote_csv($row['postal']);
32                 $this_purchase .= quote_csv($row['telephone']);
33                 $this_purchase .= quote_csv($row['country']);
34                 $this_purchase .= quote_csv($row['miraid']);
35                 $this_purchase .= quote_csv($row['date']);
36                 $this_purchase .= quote_csv($row['course_name']);
37                 $this_purchase .= quote_csv($row['amount']);
38                 $this_purchase .= quote_csv($row['comments']);
39                 $this_purchase .= quote_csv($row['course_id'])."\r\n";
40         }
41         fputs($fp, $this_purchase);
42         fclose($fp);
43
44         header('Content-Type: application/x-excel');
45         header('Content-Disposition: inline; filename="payments_'.$today.'.csv"');
46         header('Expires: 0');
47         header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
48         header('Pragma: public');
49         echo $this_purchase;
50         exit;
51
52 ?>