<?php
include("auth.php");
include("common.php");


if ($_POST['status'] == "active")
	$status_clause = " AND active = 1 ";
else if ($_POST['status'] == "inactive")
	$status_clause = " AND active = 0 ";
else
	$status_clause = "";

if ($_POST['council'] == "-1")
	$c_clause = "";
else 
	$c_clause = " AND council_id = ".$_POST['council'];
	

$PERSONTYPE =  array(1=>"Learner",2=>"Tutor", 3=>"Coordinator", 4=>"Board Member", 5=>"Volunteer");

//learner
$SQL[1]="SELECT * FROM learner WHERE 1=1 ".$status_clause.$c_clause;
//tutor
$SQL[2]="SELECT * FROM tutor  WHERE 1=1 ".$status_clause.$c_clause;
//coord
$SQL[3]="SELECT * FROM coordinator  WHERE 1=1 ".$status_clause.$c_clause;
//board mem
$SQL[4]="SELECT * FROM volunteer WHERE vtype_id=2 ".$status_clause.$c_clause;
//vol proper
$SQL[5]="SELECT * FROM volunteer WHERE vtype_id=1 ".$status_clause.$c_clause;

$userclasses= $_POST['userclass'];


$output="'".date("F j Y")."  \n";
$output.=" , PERSON, FIRST NAME, LAST NAME, STREET ADDRESS, CITY, PROVINCE, POSTAL CODE, EMAIL, HOME PHONE, WORK PHONE, ALT PHONE \n";

$i=1;

foreach($userclasses as $thevalue) 
{
	
	$results = llnb_query($SQL[$thevalue]);
	while($row = llnb_fetch_assoc($results))
	{
		$output.= $i.",".$PERSONTYPE[$thevalue].",".$row['firstname'].",".$row['lastname'].",".$row['address'].",".$row['city'].",".fetchProvName($row['prov']).",".$row['postalcode'].",".$row['email'].",".dispPhone($row['homephone']).",".dispPhone($row['workphone']).",".dispPhone($row['altphone'])."\n";
		$i++;
	}
	mysql_free_result($results);
	
}



header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=\"llnb-data.csv\"");

echo $output;


?>