diff --git a/admin/registration_receivedforms.php b/admin/registration_receivedforms.php index 11b4105..5d0a82c 100644 --- a/admin/registration_receivedforms.php +++ b/admin/registration_receivedforms.php @@ -168,8 +168,54 @@ echo mysql_Error(); { //actually set it to 'closed' mysql_query("UPDATE registrations SET status='complete' WHERE num='".$_POST['registration_number']."'"); - //FIXME: assign the project number here as well! + $q=mysql_query("SELECT id FROM registrations WHERE num='".$_POST['registration_number']."'"); + $r=mysql_fetch_object($q); + $reg_id=$r->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'"); + if(mysql_num_rows($searchq)) + { + //first, put them all in an array + $proj_nums=array(); + while($searchr=mysql_fetch_object($searchq)) + { + $proj_nums[]=$r->projectnumber; + } + + //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); + 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 happy(i18n("Registration of form %1 successfully completed",array($registration_number))); + echo happy(i18n("Assigned Project Number: %1",array($projectnumber))); } else if($_POST['action']=="receivedyesnocash" && $_POST['registration_number']) diff --git a/admin/reports_checkin.php b/admin/reports_checkin.php index 65f73a7..bbea06e 100644 --- a/admin/reports_checkin.php +++ b/admin/reports_checkin.php @@ -17,6 +17,7 @@ if($catr=mysql_fetch_object($catq)) registrations.num AS reg_num, registrations.status, projects.title, + projects.projectnumber, projects.projectdivisions_id FROM registrations @@ -81,7 +82,7 @@ if($catr=mysql_fetch_object($catq)) $table['data'][]=array($status_text,$r->proj_num,$r->title,$students,i18n($divr->division_shortform)); } else - $table['data'][]=array($r->proj_num,$r->title,$students,i18n($divr->division_shortform)); + $table['data'][]=array($r->projectnumber,$r->title,$students,i18n($divr->division_shortform)); }