<?
/*
   This file is part of the 'Science Fair In A Box' project
   SFIAB Website: http://www.sfiab.ca

   Copyright (C) 2005 Sci-Tech Ontario Inc <info@scitechontario.org>
   Copyright (C) 2005 James Grant <james@lightbox.org>

   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.
*/
?>
<?
 require("../common.inc.php");
 auth_required('admin');
 require("../lpdf.php");
 require("../lcsv.php");

 $type=$_POST['type'];
 $title=$_POST['title'];
 $projectnumber=$_POST['projectnumber'];
 $firstname=$_POST['firstname'];
 $lastname=$_POST['lastname'];
 $category=$_POST['category'];
 $division=$_POST['division'];

 if($title == "" && $projectnumber == "" && $firstname == "" && $lastnmae == "" && $category == "" && $division == "")
 {

  send_header("Administration - Reports");
  echo "<a href=\"index.php\">&lt;&lt; ".i18n("Back to Administration")."</a>&nbsp;&nbsp;";
  echo "<a href=\"reports.php\">&lt;&lt; ".i18n("Back to Reports")."</a><br />";
  echo "<br />";
  echo "<table><tr><td>";
  echo i18n("Day of Fair Registration/Checkin Forms").": ";
  echo "</td>";

  /*
    We need to prompt them for the fields.  We will display check boxes for
    every field.  By default all of the fields are checked.
  */
  echo "\n\n";
  echo "<form action=\"reports_projects_tablelabels.php\" method=\"post\">\n";
    echo "<input type=\"hidden\" value=\"pdf\" name=\"type\">\n";

    echo "<table>\n";
      echo "<tr>\n";
        echo "<td>\n";
          echo "<input type=\"checkbox\" name=\"title\" checked> Project Title\n";
        echo "</td>\n";
      echo "</tr>\n";
      echo "<tr>\n";
        echo "<td>\n";
          echo "<input type=\"checkbox\" name=\"projectnumber\" checked> Project Number\n";
        echo "</td>\n";
      echo "</tr>\n";
      echo "<tr>\n";
        echo "<td>\n";
          echo "<input type=\"checkbox\" name=\"firstname\" checked> Student's First Name\n";
        echo "</td>\n";
      echo "</tr>\n";
      echo "<tr>\n";
        echo "<td>\n";
          echo "<input type=\"checkbox\" name=\"lastname\" checked> Student's Surname Name\n";
        echo "</td>\n";
      echo "</tr>\n";
      echo "<tr>\n";
        echo "<td>\n";
          echo "<input type=\"checkbox\" name=\"category\" checked> Project Category\n";
        echo "</td>\n";
      echo "</tr>\n";
      echo "<tr>\n";
        echo "<td>\n";
          echo "<input type=\"checkbox\" name=\"division\" checked> Project Division\n";
        echo "</td>\n";
      echo "</tr>\n";
      echo "<tr>\n";
        echo "<td>\n";
          echo "<input type=\"submit\" value=\"Continue\">\n";
        echo "</td>\n";
      echo "</tr>\n";
    echo "</table>";
  echo "</form>\n";

  send_footer();


 }
 else
 {

	if($type=="pdf")
	{

		$rep=new lpdf(	i18n($config['fairname']),
				i18n(""),
				$_SERVER['DOCUMENT_ROOT'].$config['SFIABDIRECTORY']."/data/logo-200.gif"
				);

		$rep->newPage(11,8.5);
		$rep->setFontSize(11);
	}
	else if($type=="csv")
	{
		$rep=new lcsv(i18n("Table Labels"));
	}

	$projq=mysql_query("SELECT
				registrations.id AS reg_id,
				registrations.num AS reg_num,
				projects.id,
				projects.title,
				projects.projectnumber,
				projects.projectdivisions_id,
				projects.projectcategories_id,
				projectdivisions.division,
				projectcategories.category
			FROM
				registrations
				LEFT JOIN projectdivisions ON projectdivisions.id=projects.projectdivisions_id
				LEFT JOIN projectcategories ON projectcategories.id=projects.projectcategories_id
				LEFT JOIN projects on projects.registrations_id=registrations.id

			WHERE
				projects.year='".$config['FAIRYEAR']."'
				AND projectdivisions.year='".$config['FAIRYEAR']."'
				AND projectcategories.year='".$config['FAIRYEAR']."'
				AND ( registrations.status='complete' OR registrations.status='paymentpending' )
			ORDER BY
				projects.projectnumber
			");
			echo mysql_error();

	while($proj=mysql_fetch_object($projq))
	{
		$rep->setFontSize(22);
		if($title)
			$rep->addtext($proj->title,"center");
		else
			$rep->nextLine();

		$rep->setFontSize(150);
		if($projectnumber)
			$rep->addtext($proj->projectnumber,"center");
		else
			$rep->nextLine();

		$rep->setFontSize(22);


		$sq=mysql_query("SELECT students.firstname,
					students.lastname
				FROM
					students
				WHERE
					students.registrations_id='$proj->reg_id'
				");


		$students="";
		$studnum=0;
		while($studentinfo=mysql_fetch_object($sq))
		{
			if($studnum>0) $students.=", ";

			if($firstname && $lastname)
				$students.="$studentinfo->firstname $studentinfo->lastname";
			else if($firstname)
				$students.="$studentinfo->firstname";
			else if($lastname)
				$students.="$studentinfo->lastname";
			$studnum++;
		}
		$rep->nextLine();
		$rep->nextLine();
		$rep->addText($students,"center");
		$rep->nextLine();
		$rep->nextLine();
		if($category && $division)
			$rep->addText(i18n($proj->category)." - ".i18n($proj->division),"center");
		else if($category)
			$rep->addText(i18n($proj->category),"center");
		else if($division)
			$rep->addText(i18n($proj->division),"center");

		$rep->newPage();
	}

	$rep->output();
}
?>