<?
/* 
   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-2009 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");
 require_once("../config_editor.inc.php");

 function roll($currentfairyear, $newfairyear, $table, $fields)
 {
	$q=mysql_query("SELECT * FROM $table WHERE year='$currentfairyear'");
	echo mysql_error();
	$names = '`'.join('`,`', $fields).'`';
	while($r=mysql_fetch_assoc($q)) {
		$vals = '';
		foreach($fields as $f) {
			$vals .= ",'".mysql_real_escape_string($r[$f])."'";
		}

		mysql_query("INSERT INTO $table(`year`,$names) VALUES ('$newfairyear'$vals)");
		echo mysql_error();	
	}
 }

$currentfairyear=2009;
$newfairyear=2010;

		echo i18n("Rolling schools")."<br />";
		//award types
		$q=mysql_query("SELECT * FROM schools WHERE year='$currentfairyear'");
		echo mysql_error();
		while($r=mysql_fetch_object($q)) {
			$puid = ($r->principal_uid == null) ? 'NULL' : ("'".intval($r->principal_uid)."'");
			$shuid = ($r->sciencehead_uid == null) ? 'NULL' : ("'".intval($r->sciencehead_uid)."'");


			mysql_query("INSERT INTO schools (school,schoollang,schoollevel,board,district,phone,fax,address,city,province_code,postalcode,principal_uid,schoolemail,sciencehead_uid,accesscode,lastlogin,junior,intermediate,senior,registration_password,projectlimit,projectlimitper,year) VALUES (
				'".mysql_real_escape_string($r->school)."',
				'".mysql_real_escape_string($r->schoollang)."',
				'".mysql_real_escape_string($r->schoollevel)."',
				'".mysql_real_escape_string($r->board)."',
				'".mysql_real_escape_string($r->district)."',
				'".mysql_real_escape_string($r->phone)."',
				'".mysql_real_escape_string($r->fax)."',
				'".mysql_real_escape_string($r->address)."',
				'".mysql_real_escape_string($r->city)."',
				'".mysql_real_escape_string($r->province_code)."',
				'".mysql_real_escape_string($r->postalcode)."',$puid,
				'".mysql_real_escape_string($r->schoolemail)."',$shuid,
				'".mysql_real_escape_string($r->accesscode)."',
				NULL,
				'".mysql_real_escape_string($r->junior)."',
				'".mysql_real_escape_string($r->intermediate)."',
				'".mysql_real_escape_string($r->senior)."',
				'".mysql_real_escape_string($r->registration_password)."',
				'".mysql_real_escape_string($r->projectlimit)."',
				'".mysql_real_escape_string($r->projectlimitper)."',
				'".mysql_real_escape_string($newfairyear)."')");
		}

?>
