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

   Copyright (C) 2008 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");
 require_once("../user.inc.php");

 user_auth_required('committee', 'admin');

 if($_GET['id']) {
	 $id=intval($_GET['id']);
	 $q=mysql_query("SELECT sponsorships.*, sponsors.organization FROM sponsorships,sponsors WHERE sponsorships.id='$id' AND sponsorships.sponsors_id=sponsors.id");
	 echo "<h2>Edit Sponsorship</h2>";
	 $sponsorship=mysql_fetch_object($q);
	 $formaction="sponsorshipedit";
 }
 else
 {
	 echo "<h2>Create New Sponsorship</h2>";
	 $formaction="sponsorshipadd";
	 $fundraising_type=$_GET['fundraising_type'];
 }

	echo "<input type=\"hidden\" name=\"action\" value=\"$formaction\">";
	echo "<input type=\"hidden\" name=\"sponsorships_id\" value=\"$id\">";
	 echo "<table cellspacing=0 cellpadding=0 class=\"SFIABDialogTable\">";
	 echo "<tr><th>".i18n("Sponsor")."</th>";
	 echo "<td>";

	if($formaction=="sponsorshipadd") {
	 $q=mysql_query("SELECT * FROM sponsors ORDER BY organization");
	 echo mysql_error();
	 echo "<select name=\"sponsors_id\">";
	 echo "<option value=\"\">".i18n("Choose")."</option>\n";
	 while($r=mysql_fetch_object($q)) {
		 if($r->id==$sponsorship->sponsors_id) $sel="selected=\"selected\""; else $sel="";
		 echo "<option $sel value=\"$r->id\">$r->organization</option>\n";
	 }
	 echo "</select>&nbsp;<a href=\"sponsors.php?action=add\">".i18n("Add")."</a>\n";
	}
	else {
		echo $sponsorship->organization;
	}
	 echo "</td></tr>\n";

	 echo "<tr><th>".i18n("Type")."</th>";
	 echo "<td>";
	 $q=mysql_query("SELECT * FROM fundraising WHERE year='{$config['FAIRYEAR']}' ORDER BY name");
	 echo mysql_error();
	 echo "<select name=\"fundraising_type\">";
	 echo "<option value=\"\">".i18n("Choose")."</option>\n";
	 while($r=mysql_fetch_object($q)) {
		 if($r->type==$sponsorship->fundraising_type || $r->type==$fundraising_type) $sel="selected=\"selected\""; else $sel="";
		 echo "<option $sel value=\"$r->type\">$r->name</option>\n";
	 }
	 echo "</select>\n";
	 echo "</td></tr>\n";
	 echo "<tr><th>".i18n("Amount")."</th><td><input type=\"text\" name=\"value\" value=\"$sponsorship->value\"></td></tr>\n";

	 echo "<tr><th>".i18n("Status")."</th>";
	 echo "<td>";
	 echo "<select name=\"status\">";
	 echo "<option value=\"\">".i18n("Choose")."</option>\n";
	 $statuses=array("pending","confirmed","received");
	 foreach($statuses AS $status) {
		 if($sponsorship->status==$status) $sel="selected=\"selected\""; else $sel="";
		 echo "<option $sel value=\"$status\">".i18n(ucfirst($status))."</option>\n";
	 }
	 echo "</select>\n";
	 echo "</td></tr>\n";

	 echo "<tr><th>".i18n("Probability")."</th>";
	 echo "<td>";
	 echo "<select name=\"probability\">";
	 echo "<option value=\"\">".i18n("Choose")."</option>\n";
	 $probs=array("25","50","75","90","95","99","100");
	 foreach($probs AS $prob) {
		 if($sponsorship->probability==$prob) $sel="selected=\"selected\""; else $sel="";
		 echo "<option $sel value=\"$prob\">$prob%</option>\n";
	 }
	 echo "</select>\n";
	 echo "</td></tr>\n";

	 echo "</table>\n";

?>
