forked from science-ation/science-ation
a660ea4e3f
Modify all scripts to 'exit' at the beginning with a message... if anyone wants to run these scripts, they should be smart enough to be able to edit the file and comment out the 'exit' call.
95 lines
3.1 KiB
PHP
95 lines
3.1 KiB
PHP
<?
|
|
/*
|
|
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";
|
|
|
|
$projq=mysql_query("SELECT id FROM registrations WHERE status='complete' OR status='paymentpending' AND year='2008'");
|
|
while($projr=mysql_fetch_object($projq))
|
|
{
|
|
$reg_id=$projr->id;
|
|
$q=mysql_query("SELECT projects.projectcategories_id, projects.projectdivisions_id FROM projects WHERE registrations_id='$reg_id'");
|
|
$r=mysql_fetch_object($q);
|
|
|
|
$projectnumber=$config['project_num_format'];
|
|
//first replace the division and category
|
|
$projectnumber=str_replace('D',$r->projectdivisions_id,$projectnumber);
|
|
$projectnumber=str_replace('C',$r->projectcategories_id,$projectnumber);
|
|
|
|
//now change the N to a % so we can use it as a wildcard
|
|
$querynum=str_replace('N','%',$projectnumber);
|
|
$searchq=mysql_query("SELECT projectnumber FROM projects WHERE year='".$config['FAIRYEAR']."' AND projectnumber LIKE '$querynum'");
|
|
print("SELECT projectnumber FROM projects WHERE year='".$config['FAIRYEAR']."' AND projectnumber LIKE '$querynum'\n");
|
|
$searchnum=mysql_num_rows($searchq);
|
|
echo "searchnum=$searchnum \n";
|
|
if(mysql_num_rows($searchq))
|
|
{
|
|
//first, put them all in an array
|
|
$proj_nums=array();
|
|
while($searchr=mysql_fetch_object($searchq))
|
|
{
|
|
$proj_nums[]=$searchr->projectnumber;
|
|
}
|
|
print_r($proj_nums);
|
|
|
|
//we will eventually find a good number, so lets loop forever until we find a good one
|
|
$testnum=1;
|
|
$Nnum=1;
|
|
$ok=false;
|
|
do
|
|
{
|
|
$Nnum=sprintf("%02d",$testnum);
|
|
$test_projectnumber=str_replace('N',$Nnum,$projectnumber);
|
|
echo "seeing if $test_projectnumber is in proj_nums\n";
|
|
if(!in_array($test_projectnumber,$proj_nums))
|
|
$ok=true;
|
|
$testnum++;
|
|
}while(!$ok);
|
|
|
|
|
|
}
|
|
else
|
|
{
|
|
$Nnum="01";
|
|
}
|
|
|
|
$projectnumber=str_replace('N',$Nnum,$projectnumber);
|
|
mysql_query("UPDATE projects SET projectnumber='$projectnumber' WHERE registrations_id='$reg_id' AND year='".$config['FAIRYEAR']."'");
|
|
if($projectnumber)
|
|
{
|
|
echo "Assigned new project number $projectnumber\n";
|
|
}
|
|
else
|
|
{
|
|
echo "Eeek! couldnt assign project number for $reg_id";
|
|
exit;
|
|
}
|
|
$assigned++;
|
|
}
|
|
echo "assigned=$assigned";
|
|
|
|
?>
|