Copyright (C) 2011 Dennis Spanogle This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ ?> "; exit; } $filename = "EMPTY FILE Do Not Download Not Implemented.csv"; if ($CSVoption == 1) { // here is what I want in the data. may take several queries to get it. Need one record for each record in eval_projects_entries $header = "\"ProjectNum\",\"AppersonNum\",\"ShortTitle\",\"Title\",\"IsTeamProject\",\"FloorNum\",\"Language\",\"TeamProjectNote\",\"JudgeTeamNum\",\"JudgeTeamName\",\"JudgeTeamTime\",\"JudgeTeamLeader\",\"Category\",\"CatShort\",\"Division\",\"DivShort\",\"Year\",\"AppersonBarCode\",\"scheme_Id\",\"score\""; $filename = "SFIAB_Eval_Projects_Judges_Data.csv"; } if ($CSVoption == 5 ){ // Apperson Scanner Student data.// "Student ID","FirstName","LastName" $header = "\"Student ID\",\"FirstName\",\"LastName\""; $filename = "SFIAB_Eval_Appperson_Student_data.csv"; } // **********************************************write the header out to the file ************************************ $download = $header."\r\n"; $num_records = mysql_num_rows($q); while($r=mysql_fetch_object($q)) { // get some sepecial items from the raw data. // this is for test only at this time. will be used in the Apperson Scanner export and import. // to create the file necessary to preslug the score forms. // Barcode = 1 or 2 for team, 4 digits exn, 4 digits team number, 2 digits checksum? $AppPrjNum = substr($r->projectnumber , 1); if ( strlen($AppPrjNum) < 4 ) { $AppPrjNum = sprintf( "%04d",$AppPrjNum); // "0".$AppPrjNum; } $teamtime = $r->tsdate." ".$r->tsstarttime."-".$r->tsendtime; $tcode = "1"; $Teamnote = ""; if ($r->IsTeam == "yes"){ $tcode = "2"; // passed $Teamworknote when page opened $Teamnote = $Teamworknote; } $fmtTeamNum = sprintf("%04d", $r->team_num); $StudentID = $tcode.$AppPrjNum.$fmtTeamNum; // calculate the checksum $checksum = (int)substr($StudentID,0,1); $checksum += (int)substr($StudentID,1,1); $checksum +=(int) substr($StudentID,2,1); $checksum += (int)substr($StudentID,3,1); $checksum += (int)substr($StudentID,4,1); $checksum += (int)substr($StudentID,5,1); $checksum += (int)substr($StudentID,6,1); $checksum += (int)substr($StudentID,7,1); $checksum += (int)substr($StudentID,8,1); $checksum = sprintf("%02d",$checksum); $AppBarCode = "<".$tcode.$AppPrjNum.$fmtTeamNum."/".$checksum.">"; // Get the Team leader name (to be done) $TeamLeader = "n/a"; // ready to create the files if($CSVoption == 1){ // $header = "\"ProjectNum\",\"AppersonNum\",\"ShortTitle\",\"Title\",\"IsTeam\",\"FloorNum\",\"Language\",\"TeamNote\",\"TeamNum \",\"TeamName\",\"TeamTime\",\"TeamLeader\",\"Category\",\"CatShort\",\"Division\",\"DivShort\",\"Year\",\"AppersonBarCode\",\"scheme_Id\",\"criteria_id\",\"Level_id\",\"score\""; $title = str_replace("\"","'",$r->title); $recordout = "\"".$r->projectnumber."\",\"".$AppPrjNum."\",\"".$r->shorttitle."\",\"".$title."\",\"".$r->IsTeam."\",\"".$r->floornumber."\",\"".$r->language."\",\"".$Teamnote."\",\"". $r->team_num."\",\"".$r->team_name."\",\"".$teamtime."\",\"".$TeamLeader."\",\"".$r->category."\",\"".$r->category_shortform."\",\"".$r->division."\",\"".$r->division_shortform."\",\"".$r->year."\",\"". $AppBarCode."\",\"".$r->scheme_id."\",\"".$r->score."\""; // ********************************************write the record out to the file************************************************ $download = $download.$recordout."\r\n"; } if ($CSVoption == 5){ // Apperson Scanner Student data // "TPPPPJJJJ", "PRJ PPPPP 'TEAM' TITLETruncated?","JUN JJJJ JLASTNAME, JFIRSTNAME" $Teamnote = ""; if ($r->IsTeam == "yes"){ $Teamnote = "(Team Project)"; } $Firstname = "Proj ".$r->projectnumber." ".$Teamnote." ".$r->title; if(strlen($Firstname) > 100){ $Firstname = substr($Firstname,100); // limit to 100 max in Apperson Datalink } // replace and double quotes in $Firstname with single quotes so CSV import will work. $Firstname = str_replace("\"","'",$Firstname); $recordout = "\"".$StudentID."\",\"".$Firstname."\",\"JudgeTeamNum ".$r->team_num."\""; // ********************************************write the record out to the file************************************************ $download = $download.$recordout."\r\n"; } } // while $r=mysql_fetch_object($q) ob_start(); header("Content-type: text/x-csv"); header("Content-disposition: inline; filename=".$filename); header("Content-length: ".strlen($download)); header("Pragma: public"); echo $download; //header("Location: index.php"); //ob_get_status() exit; ?>