sma-website /courses/schedulecsv.php

Language PHP Lines 100
MD5 Hash c578ea3014729b4a3e606bc993ef61ac Estimated Cost $1,780 (why?)
Repository https://bitbucket.org/molusc/sma-website.git View Raw File
  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
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
<?php
//require_once('../Connections/bryanmadge.php');

$hostname = "localhost";
$database = "wf-c32a-0dfcce";
$username = "wf-c32a-0dfcce";
$password = "bma";
$bryanmadge = mysql_connect($hostname, $username, $password) or trigger_error(mysql_error(),E_USER_ERROR); 

require_once('../includes/config.php');  // must always be a relative path
//require_once('../includes/FirePHPCore/fb.php');
$sql = "SELECT c.catalog_id AS Code, 
			'No' AS 'Web', 
			'No' AS 'Demand', 
			CONCAT(DATE_FORMAT(s.course_date, '%m/%d/%Y'), ' ', REPLACE(IF(t.coursetime REGEXP '^[0-9]{2}', LEFT(t.coursetime, 5), ''), '.', ':')) AS 'Start', 
			CONCAT(DATE_FORMAT(s.course_date, '%m/%d/%Y'), ' ', REPLACE(IF(t.coursetime REGEXP '^[0-9]{2}', RIGHT(t.coursetime, 5), ''), '.', ':')) AS 'End', 
			s.course_classification AS 'ID', 
			t.clubname AS 'Location', 
			'admin@symmonsmadge.co.uk' AS 'Email', 
			'25' AS 'Language', 
			'www.symmonsmadge.co.uk/booking_form.php' AS 'URL', 
			'' AS 'Comment', 
			t.standardfees AS 'Price', 
			'GBP' AS 'Currency', 
			'Symmons Madge Associates' AS 'Vendor', 
			'Public' AS 'Type', 
			'Public' AS 'Customer', 
			REPLACE(REPLACE(title, CHAR(147), '\"'), CHAR(148), '\"') AS 'Title'
		FROM (catalog c INNER JOIN schedule s 
		ON c.catalog_id=s.course_title_id) INNER JOIN trainingclubs t ON s.clubprefix=t.clubprefix
		ORDER BY course_date";
//var_dump($sql);
//fb($sql, '$sql');
mysql_select_db($database, $bryanmadge);
//var_dump($bryanmadge);
$result = mysql_query($sql, $bryanmadge) or die(mysql_error());

//exportMysqlToCsv($res);
$filename = 'export.csv';
//function exportMysqlToCsv($result,$filename = 'export.csv')
//{
	$csv_terminated = "\r\n";
	$csv_separator = ",";
	$csv_enclosed = '"';
	$csv_escaped = "\\";
//	$sql_query = "select * from $table";
	// Gets the data from the database
//	$result = mysql_query($sql_query);
	$fields_cnt = mysql_num_fields($result);
	$schema_insert = '';
	for ($i = 0; $i < $fields_cnt; $i++)
	{
		$l = $csv_enclosed . str_replace($csv_enclosed, $csv_escaped . $csv_enclosed,
			stripslashes(mysql_field_name($result, $i))) . $csv_enclosed;
		$schema_insert .= $l;
		$schema_insert .= $csv_separator;
	} // end for
	$out = trim(substr($schema_insert, 0, -1));
	$out .= $csv_terminated;
	// Format the data
	while ($row = mysql_fetch_array($result))
	{
		$schema_insert = '';
		for ($j = 0; $j < $fields_cnt; $j++)
		{
			if ($row[$j] == '0' || $row[$j] != '')
			{
				if ($csv_enclosed == '')
				{
					$schema_insert .= $row[$j];
				} else
				{
					$schema_insert .= $csv_enclosed .
					str_replace($csv_enclosed, $csv_escaped . $csv_enclosed, $row[$j]) . $csv_enclosed;
				}
			} else
			{
				$schema_insert .= '';
			}
			if ($j < $fields_cnt - 1)
			{
				$schema_insert .= $csv_separator;
			}
		} // end for
		$out .= $schema_insert;
		$out .= $csv_terminated;
	} // end while
	header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
	header("Content-Length: " . strlen($out));
	// Output to browser with appropriate mime type, you choose ;)
	//header("Content-type: text/x-csv");
	//header("Content-type: text/csv");
	//header("Content-type: application/csv");
	//header("Content-Disposition: attachment; filename=$filename");
	echo $out;
	exit;
//}


?>
Back to Top