<?
/* 
   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.
*/
?>
<?
echo "To run this script, edit it and comment out the 'exit' (and this message) at the beginning";
//exit;
include "../common.inc.php";

$numprojects=150;


function getrand($ar)
{
	return $ar[rand(0,count($ar)-1)];
}

//the following work as one in x where x is the number below
$prob_dual=3;
$prob_unpaid=10;


$firstnames=array("James","Bob","Ali","Erin","Julia","Dave","Steve","Bryan","Jane","Elizabeth","Norm","Sue","Eric","Terry","Arthur","Angel","Allison","Jeremy","Jacqueline","Derek","Kristen","Greg","Cheryl","Debbie","Heather","Donald","Linda","George","Patrica","Carmel","Dawn","Scott","Brad","Bruce","Paul","Guillaume");

$lastnames=array("Grant","Browning","Mehdi","Borque","Temple","Culhane","Sargent","Sing","Belanger","Desjardin","Jones","Smith","Brown","Johnson","Williams","White","Thompson","Baker");

$domains=array("lightbox.org","microsoft.com","yahoo.com","msn.com","gmail.com","reach.net","slicer.ca","cwsf.ca","sfiab.ca");

$nouns=array("age","animal","arm","baby","ball","bat","bear","boat","camp","car","child","circle","city","cotton","design","dog","dress","duck","ear","egg","enemy");
$starters=array("effects of","study of","analysis of");
$joiners=array("on","combined with","broken apart by","burned with","attacked by","left alone with");

$numschools=$pdo->prepare("SELECT id FROM schools WHERE year='2011'");
$numschools->execute();
while($s=$numschools->fetch(PDO::FETCH_OBJ))
{
	//1 in 4 chance of actually using this school
	$o=rand(1,4);
	if($o==1)
		$schools[]=$s->id;
}
$ns=count($schools);

for($x=0;$x<$numprojects;$x++)
{
	$id=0;
	$regnum=rand(100000,999999);
	$email=strtolower(getrand($firstnames)."@".getrand($domains));
	$pd=rand(1,$prob_unpaid);
	if($pd==1) $status='paymentpending'; else $status='complete';

	$q=$pdo->prepare("INSERT INTO registrations (num,email,start,status,year) VALUES ('$regnum','$email',NOW(),'$status',2011)");
	$q->execute();
	if($id=$pdo->lastInsertId())
	{

		$peeps=rand(1,$prob_dual);
		if($peeps==1) $num=2; else $num=1;

		$gradenum=rand(1,10);
		if($gradenum<7) { $grade=rand(7,8); $cat=1;} 
		else if($gradenum<9) { $grade=rand(9,10); $cat=2; }
		else if($gradenum<10) { $grade=rand(11,12); $cat=3; }

		$schools_id=$schools[rand(0,$ns)];

		for($a=1;$a<=$num;$a++)
		{
			$sexnum=rand(1,3);
			if($sexnum<3) $sex="male"; else $sex="female";

			$firstname=getrand($firstnames);
			$email=strtolower($firstname)."@".getrand($domains);
			$stmt = $pdo->prepare("INSERT INTO students (registrations_id,firstname,lastname,email,sex,grade,year,schools_id) VALUES ('$id','$firstname','".getrand($lastnames)."','$email','$sex','$grade','2011','$schools_id')");
			$stmt->execute();
		}

		$div=rand(1,6);
		$title=ucwords(getrand($starters)." ".getrand($nouns)." ".getrand($joiners)." ".getrand($nouns));

		$req_enum=rand(1,4);
		if($req_enum==1) $req_e="yes"; else $req_e="no";

		$req_tnum=rand(1,30);
		if($req_tnum==1) $req_t="no"; else $req_t="yes";

		$langnum=rand(1,10);
		if($langnum<4) $lang="fr"; else $lang="en";


		$stmt = $pdo->prepare("INSERT INTO projects (registrations_id,projectcategories_id,projectdivisions_id,title,year,req_electricity,req_table,language) VALUES ('$id','$cat','$div','$title $lang',2011,'$req_e','$req_t','$lang')");
		$stmt->execute();
	}
}

?>
