From 4c1fbba34812dd2cec5d8ec346e45fc5a83100f5 Mon Sep 17 00:00:00 2001 From: james Date: Tue, 19 Apr 2005 19:23:10 +0000 Subject: [PATCH] add script that will go through and assign all projectnumbers for all completed registrations --- scripts/assignprojectnumbers.php | 82 ++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 scripts/assignprojectnumbers.php diff --git a/scripts/assignprojectnumbers.php b/scripts/assignprojectnumbers.php new file mode 100644 index 0000000..f45a79b --- /dev/null +++ b/scripts/assignprojectnumbers.php @@ -0,0 +1,82 @@ + + Copyright (C) 2005 James Grant + + 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. +*/ +?> +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']."'"); + echo "Assigned new project number $projectnumber\n"; + + } + +?>