forked from science-ation/science-ation
- Move the project number generation into a header
- Add an option to the project editor to regenerate the project number - Fix a bug in the project number generation. Include YEAR in the project number check (and in the number generation) so we don't find a project from last year (that already has a number), and decide not to generate one for a project from this year. The $checkNumQuery was returning 2 rows.. one from 2006, one from 2007. Two projects from different years had the same registrations.num (665983) in my test.. about 10% of the projects at the VDSF collided with numbers from previous years.
This commit is contained in:
parent
c7560b91d4
commit
4789d78e2f
@ -23,7 +23,7 @@
|
||||
?>
|
||||
<?
|
||||
require("../common.inc.php");
|
||||
// include "register_participants.inc.php";
|
||||
require("../register_participants.inc.php");
|
||||
auth_required('admin');
|
||||
|
||||
//send the header
|
||||
@ -35,6 +35,14 @@
|
||||
if($_POST['registration_id']) $registration_id=$_POST['registration_id'];
|
||||
else if($_GET['registration_id']) $registration_id=$_GET['registration_id'];
|
||||
|
||||
|
||||
if($_POST['action']=="genprojnum") {
|
||||
mysql_query("UPDATE projects SET projectnumber=NULL WHERE id='{$_POST['id']}'");
|
||||
$pn = generate_project_number($registration_id);
|
||||
// print("Generated Project Number [$pn]");
|
||||
mysql_query("UPDATE projects SET projectnumber='$pn' WHERE id='{$_POST['id']}'");
|
||||
}
|
||||
|
||||
if($_POST['action']=="save")
|
||||
{
|
||||
// {
|
||||
@ -285,6 +293,17 @@ if($projectinfo)
|
||||
echo "</table>";
|
||||
echo "<input type=\"submit\" value=\"".i18n("Save Project Information")."\" />\n";
|
||||
echo "</form>";
|
||||
|
||||
|
||||
echo ("<br /><br /><h3>".i18n("Other Actions")."</h3><br />");
|
||||
|
||||
echo "<form name=\"projectform\" method=\"post\" action=\"project_editor.php\">\n";
|
||||
echo "<input type=\"hidden\" name=\"action\" value=\"genprojnum\">\n";
|
||||
echo "<input type=\"hidden\" name=\"id\" value=\"$projectinfo->id\">\n";
|
||||
echo "<input type=\"hidden\" name=\"registration_id\" value=\"$registration_id\">\n";
|
||||
echo "<input type=\"submit\" value=\"".i18n("Re-Generate Project Number")."\" />\n";
|
||||
echo "</form>";
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -193,74 +193,23 @@ echo mysql_Error();
|
||||
}
|
||||
else if(($_POST['action']=="receivedyes" || $_POST['action']=="receivedyesnocash") && $_POST['registration_number']) {
|
||||
|
||||
$checkNumQuery=mysql_query("SELECT projectnumber FROM projects, registrations WHERE projects.registrations_id = registrations.id AND "
|
||||
. "num='".$_POST['registration_number']."'");
|
||||
$regnum = intval($_POST['registration_number']);
|
||||
$checkNumQuery=mysql_query("SELECT projectnumber
|
||||
FROM projects, registrations
|
||||
WHERE projects.registrations_id = registrations.id
|
||||
AND num='$regnum'
|
||||
AND registrations.year='{$config['FAIRYEAR']}'");
|
||||
$checkNumResults=mysql_fetch_object($checkNumQuery);
|
||||
$projectnum=$checkNumResults->projectnumber;
|
||||
if($projectnum == null)
|
||||
{
|
||||
$q=mysql_query("SELECT id FROM registrations WHERE num='".$_POST['registration_number']."'");
|
||||
$q=mysql_query("SELECT id FROM registrations WHERE num='$regnum' AND year='{$config['FAIRYEAR']}'");
|
||||
$r=mysql_fetch_object($q);
|
||||
$reg_id=$r->id;
|
||||
$q=mysql_query("SELECT projects.projectcategories_id,
|
||||
projects.projectdivisions_id,
|
||||
projectcategories.category_shortform,
|
||||
projectdivisions.division_shortform
|
||||
FROM
|
||||
projects,
|
||||
projectcategories,
|
||||
projectdivisions
|
||||
WHERE
|
||||
registrations_id='$reg_id'
|
||||
AND projects.projectdivisions_id=projectdivisions.id
|
||||
AND projects.projectcategories_id=projectcategories.id
|
||||
AND projectcategories.year='{$config['FAIRYEAR']}'
|
||||
AND projectdivisions.year='{$config['FAIRYEAR']}'
|
||||
");
|
||||
echo mysql_error();
|
||||
$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);
|
||||
$projectnumber=str_replace('d',$r->division_shortform,$projectnumber);
|
||||
$projectnumber=str_replace('c',$r->category_shortform,$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[]=$searchr->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']."'");
|
||||
$reg_id = $r->id;
|
||||
|
||||
$projectnumber = generate_project_number($reg_id);
|
||||
|
||||
mysql_query("UPDATE projects SET projectnumber='$projectnumber' WHERE registrations_id='$reg_id' AND year='{$config['FAIRYEAR']}'");
|
||||
echo happy(i18n("Assigned Project Number: %1",array($projectnumber)));
|
||||
}
|
||||
if($_POST['action']=="receivedyes")
|
||||
|
@ -264,5 +264,88 @@ function tourStatus($reg_id="")
|
||||
}
|
||||
|
||||
|
||||
function generate_project_number($registration_id)
|
||||
{
|
||||
global $config;
|
||||
|
||||
$reg_id = $registration_id;
|
||||
|
||||
$q=mysql_query("SELECT projects.projectcategories_id,
|
||||
projects.projectdivisions_id,
|
||||
projectcategories.category_shortform,
|
||||
projectdivisions.division_shortform
|
||||
FROM
|
||||
projects,
|
||||
projectcategories,
|
||||
projectdivisions
|
||||
WHERE
|
||||
registrations_id='$reg_id'
|
||||
AND projects.projectdivisions_id=projectdivisions.id
|
||||
AND projects.projectcategories_id=projectcategories.id
|
||||
AND projectcategories.year='{$config['FAIRYEAR']}'
|
||||
AND projectdivisions.year='{$config['FAIRYEAR']}'
|
||||
");
|
||||
echo mysql_error();
|
||||
print("SELECT projects.projectcategories_id,
|
||||
projects.projectdivisions_id,
|
||||
projectcategories.category_shortform,
|
||||
projectdivisions.division_shortform
|
||||
FROM
|
||||
projects,
|
||||
projectcategories,
|
||||
projectdivisions
|
||||
WHERE
|
||||
registrations_id='$reg_id'
|
||||
AND projects.projectdivisions_id=projectdivisions.id
|
||||
AND projects.projectcategories_id=projectcategories.id
|
||||
AND projectcategories.year='{$config['FAIRYEAR']}'
|
||||
AND projectdivisions.year='{$config['FAIRYEAR']}'
|
||||
");
|
||||
$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);
|
||||
$projectnumber=str_replace('d',$r->division_shortform,$projectnumber);
|
||||
$projectnumber=str_replace('c',$r->category_shortform,$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[]=$searchr->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);
|
||||
|
||||
return $projectnumber;
|
||||
}
|
||||
|
||||
?>
|
||||
|
Loading…
Reference in New Issue
Block a user