- Update the project numbering system by also adding a sort field (defaults to

the project number field if blank).
- Add a new number option 'X', which counts among ALL projects, not just the
  ones in the same division/cat.
- Add a padding argument to N or X  (N0...N9) defaults to 2 for N, and 3 for X.
- Adds 3 columns to the project table:
	- projectsort: for storing the expanded text
	- projectnumber_seq: for storing the N or X number for projects
	- projectsort_seq: for storing the N or X number for the sort order
- Add a new config option for sorting, and expand the text for the
  projectnumber.
- Change the default sorting for reports and project lists to use the
  projectsort category.
- Remove the gvrsf_tn option from the database, it's not needed now.
This commit is contained in:
dave 2007-12-29 08:46:40 +00:00
parent a5998ca3dd
commit e8face39d6
7 changed files with 116 additions and 50 deletions

View File

@ -42,10 +42,17 @@
if($_POST['action']=="genprojnum") {
mysql_query("UPDATE projects SET projectnumber=NULL WHERE id='{$_POST['id']}'");
$pn = generateProjectNumber($registration_id);
$id = intval($_POST['id']);
mysql_query("UPDATE projects SET projectnumber=NULL,projectsort=NULL,
projectnumber_seq='0',projectsort_seq='0'
WHERE id='$id'");
echo mysql_error();
list($pn,$ps,$pns,$pss) = generateProjectNumber($registration_id);
// print("Generated Project Number [$pn]");
mysql_query("UPDATE projects SET projectnumber='$pn' WHERE id='{$_POST['id']}'");
mysql_query("UPDATE projects SET projectnumber='$pn',projectsort='$ps',
projectnumber_seq='$pns',projectsort_seq='$pss'
WHERE id='$id'");
echo mysql_error();
}
if($_POST['action']=="save")

View File

@ -211,8 +211,10 @@ echo mysql_Error();
if($projectnum == null)
{
$projectnumber = generateProjectNumber($reg_id);
mysql_query("UPDATE projects SET projectnumber='$projectnumber' WHERE registrations_id='$reg_id' AND year='{$config['FAIRYEAR']}'");
list($projectnumber,$ps,$pns,$pss) = generateProjectNumber($reg_id);
mysql_query("UPDATE projects SET projectnumber='$projectnumber',
projectsort='$ps',projectnumber_seq='$pns',projectsort_seq='$pss'
WHERE registrations_id='$reg_id' AND year='{$config['FAIRYEAR']}'");
echo happy(i18n("Assigned Project Number: %1",array($projectnumber)));
}
else

View File

@ -307,7 +307,7 @@ function reportReload()
//only go through the columns if there are columns to go through
if(count($report['col'])) {
foreach($report['col'] as $o=>$d) {
echo "<tr><td>Column ".($x + 1).": </td>";
echo "<tr><td>Column&nbsp;".($x + 1).": </td>";
echo "<td>";
if(intval($x) != intval($o)) {
echo ("WARNING, out of order!");
@ -318,7 +318,7 @@ function reportReload()
}
}
for(;$x<$n_columns;$x++) {
echo "<tr><td>Column ".($x + 1).": </td>";
echo "<tr><td>Column&nbsp;".($x + 1).": </td>";
echo "<td>";
field_selector("col[$x][field]", "col$x", '');
echo "</td></tr>";

View File

@ -31,7 +31,8 @@ $report_students_fields = array(
'name' => 'Project Number',
'header' => '#',
'width' => 0.5,
'table' => 'CAST(projects.projectnumber AS UNSIGNED)' ),
'table' => 'projects.projectnumber',
'table_sort' => 'projects.projectsort'),
'last_name' => array(
'name' => 'Student -- Last Name',
@ -489,14 +490,13 @@ $report_students_fields = array(
'header' => '',
'width' => 0.1,
'table' => "CONCAT(' ')"),
'gvrsf_tn' => array (
/* 'gvrsf_tn' => array (
'name' => 'GVRSF Project Number (Table Number)',
'header' => '#',
'width' => 0.6,
'table' => "CAST(projects.projectnumber AS UNSIGNED) AS GVRSFTBL, CONCAT(projectcategories.category_shortform, ' ', projects.projectnumber, ' ', projectdivisions.division_shortform)",
'table_sort' => 'GVRSFTBL'),
*/
'easyparse_allnames' => array(
'name' => "Easy Parse -- All Student Names (REQUIRES MYSQL 5.0) ",
'header' => 'Student(s)',

View File

@ -1 +1 @@
91
92

View File

@ -47,7 +47,7 @@ function getProjectsEligibleForAward($award_id)
AND projects.projectnumber is not null
AND projects.year='".$config['FAIRYEAR']."'
ORDER BY
projectnumber
projectsort
");
$projects=array();
while($prjr=mysql_fetch_object($prjq))
@ -206,7 +206,7 @@ function getProjectsNominatedForSpecialAward($award_id)
AND projects.projectnumber is not null
AND projects.year='".$config['FAIRYEAR']."'
ORDER BY
projectnumber
projectsort
");
$projects=array();
while($prjr=mysql_fetch_object($prjq))
@ -251,7 +251,7 @@ function getSpecialAwardsNominatedByRegistrationID($id)
AND projects.projectnumber is not null
AND projects.year='".$config['FAIRYEAR']."'
ORDER BY
projectnumber
projectsort
");
$projects=array();
while($prjr=mysql_fetch_object($prjq))

View File

@ -319,49 +319,106 @@ function generateProjectNumber($registration_id)
echo mysql_error();
$r=mysql_fetch_object($q);
$projectnumber=$config['project_num_format'];
$p=array('number'=>array(), 'sort'=>array() );
$p['number']['str'] = $config['project_num_format'];
$p['sort']['str'] = trim($config['project_sort_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);
if($p['sort']['str'] == '') $p['sort']['str'] = $p['number']['str'];
//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;
/* Replace each letter with {letter}, so that we can do additional
* replacements below, without risking subsituting in a letter that may
* get replaced. */
foreach(array('number','sort') as $x) {
$p[$x]['str']=ereg_replace('[CcDd]', '{\\0}', $p[$x]['str']);
$p[$x]['str']=ereg_replace('(N|X)([0-9])?', '{\\0}', $p[$x]['str']);
}
//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);
/* Do some replacements that we don' thave to do anything fancy with,
* and setup some variables for future queries */
foreach(array('number','sort') as $x) {
$p[$x]['str']=str_replace('{D}',$r->projectdivisions_id,$p[$x]['str']);
$p[$x]['str']=str_replace('{C}',$r->projectcategories_id,$p[$x]['str']);
$p[$x]['str']=str_replace('{d}',$r->division_shortform,$p[$x]['str']);
$p[$x]['str']=str_replace('{c}',$r->category_shortform,$p[$x]['str']);
$p[$x]['n_used'] = array();
$p[$x]['x_used'] = array();
}
/* Build a total list of projects for finding a global number, and
* while constructing the list, build a list for the division/cat
* sequence number */
$q = mysql_query("SELECT projectnumber_seq,projectsort_seq,
projectdivisions_id,projectcategories_id
FROM projects
WHERE year='{$config['FAIRYEAR']}'
AND projectnumber_seq!='0'
AND projectnumber IS NOT NULL");
echo mysql_error();
while($i = mysql_fetch_object($q)) {
if( ($r->projectdivisions_id == $i->projectdivisions_id)
&&($r->projectcategories_id == $i->projectcategories_id) ) {
$p['number']['n_used'][] = $i->projectnumber_seq;
$p['sort']['n_used'][] = $i->projectsort_seq;
}
$p['number']['x_used'][] = $i->projectnumber_seq;
$p['sort']['x_used'][] = $i->projectsort_seq;
}
/* We only support one N or X to keep things simple, find which
* one we need and how much to pad it */
foreach(array('number','sort') as $x) {
if(ereg("(N|X)([0-9])?", $p[$x]['str'], $regs)) {
$p[$x]['seq_type'] = $regs[1];
if($regs[2] != '')
$p[$x]['seq_pad'] = $regs[2];
else
{
$Nnum="01";
$p[$x]['seq_pad'] = ($regs[1] == 'N') ? 2 : 3;
if($regs[1] == 'N')
$p[$x]['used'] = $p[$x]['n_used'];
else
$p[$x]['used'] = $p[$x]['x_used'];
} else {
/* FIXME: maybe we should error here? Not having an N
* or an X in the projectnumber or projectsort is a bad
* thing */
$p[$x]['seq_type'] = '';
$p[$x]['seq_pad'] = 0;
$p[$x]['used'] = array();
}
}
$projectnumber=str_replace('N',$Nnum,$projectnumber);
/* Find the lowest unused number. FIXME: this could be a config
* option, we could search for the lowest unused number (if projects
* get deleted), or we could just go +1 beyond the highest */
foreach(array('number','sort') as $x) {
if($p[$x]['seq_type'] == '') continue;
$n = 0;
while(1) {
$n++;
if(in_array($n, $p[$x]['used'])) continue;
return $projectnumber;
$r = sprintf("%'0{$p[$x]['seq_pad']}d", $n);
$str = ereg_replace("{(N|X)([0-9])?}", $r, $p[$x]['str']);
$p[$x]['str'] = $str;
$p[$x]['n'] = $n;
break;
}
/* If we're using the same number type for sorting, then we, in
* theory, know what that number is, so we can go ahead and
* blindly use it */
if($p['number']['seq_type'] == $p['sort']['seq_type']) {
$r = sprintf("%'0{$p['sort']['seq_pad']}d", $n);
$p['sort']['str'] = ereg_replace("{(N|X)([0-9])?}", $r, $p['sort']['str']);
$p['sort']['n'] = $n;
break;
}
}
return array($p['number']['str'], $p['sort']['str'],
$p['number']['n'], $p['sort']['n']);
}
function computeRegistrationFee($regid)