Updated super/conferences.php, adding a rollback if there are errors in copying a conference.

Added compvars.php, which is a test script for comparing data after it's been rolled over from one conference to another - used to test the rollover in super/conferences.php.
Updated usage of the role "student", replacing it with "participant".
This commit is contained in:
jacob 2010-11-26 16:50:17 +00:00
parent 57561c829d
commit 1e1fa0097a
8 changed files with 225 additions and 46 deletions

View File

@ -230,7 +230,7 @@ function account_add_role($accounts_id, $roles_id, $conferences_id, $password =
return 'invalidrole';
}
// get the type of the role (eg. "judge", "student", etc.)
// get the type of the role (eg. "judge", "participant", etc.)
$role = mysql_result(mysql_query("SELECT type FROM roles WHERE id = $roles_id"), 0);
// and see if it's a valid one for this conference
@ -303,13 +303,13 @@ function account_add_role_allowed($accounts_id, $roles_id, $conferences_id){
while($returnval && $row = mysql_fetch_assoc($query)){
switch($row['type']){
case 'student':
case 'participant':
// Student cant' add any other role
$returnval = false;
break;
default:
if($role == 'student') {
// No role can add the student role
if($role == 'participant') {
// No role can add the participant role
$returnval = false;
}

View File

@ -273,7 +273,7 @@ if(array_key_exists('users_id', $_SESSION)) {
if(in_array('sponsor', $_SESSION['roles'])) {
// echo "<li><a href=\"{$config['SFIABDIRECTORY']}/sponsor_main.php\">".i18n("Sponsor Home").'</a></li>';
}
if(in_array('student', $_SESSION['roles'])) {
if(in_array('participant', $_SESSION['roles'])) {
echo "<li><a href=\"{$config['SFIABDIRECTORY']}/register_participants_main.php\">".i18n("Participant Home").'</a></li>';
}
}

127
scripts/compvars.php Executable file
View File

@ -0,0 +1,127 @@
#!/usr/bin/php
<?
/*
This is a test script to compare the data that is stored for two conferences.
It's raison d'etre is to ensure that the new conference rollover process is
working properly.
*/
require_once("../common.inc.php");
if($_SERVER['DOCUMENT_ROOT'] != "") {
echo "This script must be run from a shell";
exit();
}
if($argc != 3 || !is_numeric($argv[1]) || !is_numeric($argv[2])){
echo "This script is used to compare the variables stored for two separate conferences.\n";
echo "\tUsage:\n\tcompvars confid1 confid2\n";
exit();
}
$confid1 = $argv[1];
$confid2 = $argv[2];
compTable('config', array('var'), array('val', 'category', 'type'));
compTable('dates', array('name'), array());
compTable('award_types', array('id'), array('type', 'order'));
compTable('pagetext', array('textname'), array('textdescription', 'text'));
compTable('projectcategories', array('id', 'category'), array('category_shortform', 'mingrade', 'maxgrade'));
compTable('projectdivisions', array('id', 'division'), array('division_shortform', 'cwsfdivisionid'));
compTable('projectsubdivisions', array('id'), array('subdivision', 'projectdivisions_id'));
compTable('safetyquestions', array('ord'), array('question', 'type', 'required'));
compTable('award_awards', array('order'), array());
compTable('award_types', array('type'), array('order'));
//compTable('award_awards_projectcategories', array('award_awards_id', 'projectcategories_id'), array());
//compTable('award_awards_projectdivisions', array('award_awards_id', 'projectdivisions_id'), array());
//compTable('award_prizes JOIN award_awards ON award_awards.id = award_prizes.award_awards_id', array('order', 'prize'), array());
compTable('schools', array('accesscode'), array('school', 'address', 'postalcode'));
compTable('questions', array('ord', 'db_heading'), array('section', 'question', 'type'));
compTable('regfee_items', array('name'), array());
compTable('volunteer_positions', array('name'), array('start', 'end', 'desc', 'meet_place'));
compTable('judges_timeslots', array('name'), array());
function compTable($tableName, $keys, $fields){
global $confid1, $confid2;
$selection = array_merge($fields, array_diff($keys, $fields));
// get data from our conferences
$data1 = selectDat($tableName, $selection, $keys, $confid1);
$data2 = selectDat($tableName, $selection, $keys, $confid2);
echo "\n --- Comparing the table '$tableName' for conferences $confid1 and $confid2, checking field(s): {" . implode(', ', $fields) . "}, using keys {" . implode(':', $keys) . "} ---\n";
$keys1 = array_keys($data1);
$keys2 = array_keys($data2);
// show whether or not any key values are set in this table for one of these conferences but not the other
$keyDiff = array_diff($keys1, $keys2);
if(count($keyDiff) > 0){
echo "The following key values are used in conference #$confid1, but not conference #$confid2:\n";
echo implode(', ', $keyDiff) . "\n";
}else{
echo "conference #$confid2 has all of the key values used in conference #$confid1 in table $tableName.\n";
}
$keyDiff = array_diff($keys2, $keys1);
if(count($keyDiff) > 0){
echo "The following key values are used in conference #$confid2, but not conference #$confid1:\n";
echo implode(', ', $keyDiff) . "\n";
}else{
echo "conference #$confid1 has all of the key values used in conference #$confid2 in table $tableName.\n";
}
// now show if any of the records have different field values in the same key index
if(count($fields) > 0){
$saidMessage = false;
$commonkeys = array_intersect($keys1, $keys2);
$numfields = count($fields);
foreach($commonkeys as $key){
$badFields = array();
for($n = 0; $n < $numfields; $n++){
if($data1[$key][$fields[$n]] != $data2[$key][$fields[$n]]){
$badFields[] = $fields[$n];
}
}
if(count($badFields) > 0){
if(!$saidMessage){
echo "The following records have different values for the same keys:\n";
$saidMessage = true;
}
echo "$key : ";
foreach($badFields as $fieldName){
echo "$fieldName: ({$data1[$key][$fieldName]} != {$data2[$key][$fieldName]}) ";
}
echo "\n";
}
}
if(!$saidMessage){
echo "All common key names have matching values for these two sets.\n";
}
}
}
function selectDat($tableName, $selection, $keys, $confid){
$query = "SELECT `" . implode('`,`', $selection) . "` FROM $tableName WHERE conferences_id = $confid";
$q = mysql_query($query);
$data = array();
if(mysql_error() != ''){
echo "$query\n" . mysql_error() . "\n";
print_r(debug_backtrace());
}
while($row = mysql_fetch_assoc($q)){
$keyVals = array();
foreach($keys as $k){
$keyVals[] = $row[$k];
unset($row[$k]);
}
$data[implode(':', $keyVals)] = $row;
}
return $data;
}

View File

@ -628,7 +628,7 @@ function handle_complete_step(){
function create_conference($params){
$cname = mysql_real_escape_string($params['name']);
$ctype = $params['type'];
mysql_query("INSERT INTO conferences (oid, name, type, status) VALUES (1, '" . mysql_real_escape_string($cname) . "', '$ctype', 'pending')");
mysql_query("INSERT INTO conferences (oid, name, type, status) VALUES (1, '" . $cname . "', '$ctype', 'pending')");
//if its created brand spanking new, we set the copyoriginal and copyparent to be the same as the id
$id=mysql_insert_id();
@ -727,6 +727,9 @@ function copy_conference($params){
name => the new name
}*/
// start a list of all tables that have been updated
$completedTables = array();
// we'll start by creating the new conference
$oldConfId = $params['mastercopy'];
$oldConf = mysql_fetch_assoc(mysql_query("SELECT * FROM conferences WHERE id = {$oldConfId}"));
@ -750,7 +753,8 @@ function copy_conference($params){
'".mysql_real_escape_string($r->name)."',
'".mysql_real_escape_string($r->description)."',
'".mysql_real_escape_string($newConfId)."')");
if(mysql_error() != ''){ wizard_draw_step('error', 'SQL error before line #' . __LINE__ . ': <br/>' . mysql_error()); return false; }
$completedTables[] = 'dates';
if(mysql_error() != ''){ wizard_draw_step('error', 'SQL error before line #' . __LINE__ . ': <br/>' . mysql_error()); rollback($newConfId, $completedTables); return false; }
// page text
$q = mysql_query("SELECT * FROM pagetext WHERE conferences_id = $oldConfId");
@ -762,7 +766,8 @@ function copy_conference($params){
'".mysql_real_escape_string($r->lastupdate)."',
'".mysql_real_escape_string($newConfId)."',
'".mysql_real_escape_string($r->lang)."')");
if(mysql_error() != ''){ wizard_draw_step('error', 'SQL error before line #' . __LINE__ . ': <br/>' . mysql_error()); return false; }
$completedTables[] = 'pagetext';
if(mysql_error() != ''){ wizard_draw_step('error', 'SQL error before line #' . __LINE__ . ': <br/>' . mysql_error()); rollback($newConfId, $completedTables); return false; }
// project categories
$q = mysql_query("SELECT * FROM projectcategories WHERE conferences_id = $oldConfId");
@ -774,7 +779,8 @@ function copy_conference($params){
'".mysql_real_escape_string($r->mingrade)."',
'".mysql_real_escape_string($r->maxgrade)."',
'".mysql_real_escape_string($newConfId)."')");
if(mysql_error() != ''){ wizard_draw_step('error', 'SQL error before line #' . __LINE__ . ': <br/>' . mysql_error()); return false; }
$completedTables[] = 'projectcategories';
if(mysql_error() != ''){ wizard_draw_step('error', 'SQL error before line #' . __LINE__ . ': <br/>' . mysql_error()); rollback($newConfId, $completedTables); return false; }
// project divisions
$q=mysql_query("SELECT * FROM projectdivisions WHERE conferences_id=$oldConfId");
@ -785,7 +791,8 @@ function copy_conference($params){
'".mysql_real_escape_string($r->division_shortform)."',
'".mysql_real_escape_string($r->cwsfdivisionid)."',
'".mysql_real_escape_string($newConfId)."')");
if(mysql_error() != ''){ wizard_draw_step('error', 'SQL error before line #' . __LINE__ . ': <br/>' . mysql_error()); return false; }
$completedTables[] = 'projectdivisions';
if(mysql_error() != ''){ wizard_draw_step('error', 'SQL error before line #' . __LINE__ . ': <br/>' . mysql_error()); rollback($newConfId, $completedTables); return false; }
// project subdivisions
$q=mysql_query("SELECT * FROM projectsubdivisions WHERE conferences_id=$oldConfId");
@ -795,7 +802,8 @@ function copy_conference($params){
'".mysql_real_escape_string($r->projectsubdivisions_id)."',
'".mysql_real_escape_string($r->subdivision)."',
'".mysql_real_escape_string($newConfId)."')");
if(mysql_error() != ''){ wizard_draw_step('error', 'SQL error before line #' . __LINE__ . ': <br/>' . mysql_error()); return false; }
$completedTables[] = 'projectsubdivisions';
if(mysql_error() != ''){ wizard_draw_step('error', 'SQL error before line #' . __LINE__ . ': <br/>' . mysql_error()); rollback($newConfId, $completedTables); return false; }
// safety questions
$q=mysql_query("SELECT * FROM safetyquestions WHERE conferences_id=$oldConfId");
@ -806,7 +814,8 @@ function copy_conference($params){
'".mysql_real_escape_string($r->required)."',
'".mysql_real_escape_string($r->ord)."',
'".mysql_real_escape_string($newConfId)."')");
if(mysql_error() != ''){ wizard_draw_step('error', 'SQL error before line #' . __LINE__ . ': <br/>' . mysql_error()); return false; }
$completedTables[] = 'safetyquestions';
if(mysql_error() != ''){ wizard_draw_step('error', 'SQL error before line #' . __LINE__ . ': <br/>' . mysql_error()); rollback($newConfId, $completedTables); return false; }
// awards
$q=mysql_query("SELECT * FROM award_awards WHERE conferences_id=$oldConfId");
@ -823,7 +832,11 @@ function copy_conference($params){
$errorMessage .= roll($oldConfId, $newConfId, 'award_prizes', "award_awards_id='{$r->id}'",
array('award_awards_id' => $award_awards_id));
}
if($errorMessage != ''){ wizard_draw_step('error', 'SQL error before line #' . __LINE__ . ': <br/>' . $errorMessage); return false; }
$completedTables[] = 'award_awards';
$completedTables[] = 'award_awards_projectcategories';
$completedTables[] = 'award_awards_projectdivisions';
$completedTables[] = 'award_prizes';
if($errorMessage != ''){ wizard_draw_step('error', 'SQL error before line #' . __LINE__ . ': <br/>' . $errorMessage); rollback($newConfId, $completedTables); return false; }
// award types
$q=mysql_query("SELECT * FROM award_types WHERE conferences_id = $oldConfId");
@ -833,7 +846,8 @@ function copy_conference($params){
'".mysql_real_escape_string($r->type)."',
'".mysql_real_escape_string($r->order)."',
'".mysql_real_escape_string($newConfId)."')");
if(mysql_error() != ''){ wizard_draw_step('error', 'SQL error before line #' . __LINE__ . ': <br/>' . mysql_error()); return false; }
$completedTables[] = 'award_types';
if(mysql_error() != ''){ wizard_draw_step('error', 'SQL error before line #' . __LINE__ . ': <br/>' . mysql_error()); rollback($newConfId, $completedTables); return false; }
// schools
$q=mysql_query("SELECT * FROM schools WHERE conferences_id=$oldConfId");
@ -865,7 +879,8 @@ function copy_conference($params){
'".mysql_real_escape_string($r->projectlimitper)."',
'".mysql_real_escape_string($newConfId)."')");
}
if(mysql_error() != ''){ wizard_draw_step('error', 'SQL error before line #' . __LINE__ . ': <br/>' . mysql_error()); return false; }
$completedTables[] = 'schools';
if(mysql_error() != ''){ wizard_draw_step('error', 'SQL error before line #' . __LINE__ . ': <br/>' . mysql_error()); rollback($newConfId, $completedTables); return false; }
// questions
$q = mysql_query("SELECT * FROM questions WHERE conferences_id = $oldConfId");
@ -879,18 +894,21 @@ function copy_conference($params){
'".mysql_real_escape_string($r->type)."',
'".mysql_real_escape_string($r->required)."',
'".mysql_real_escape_string($r->ord)."')");
if(mysql_error() != ''){ wizard_draw_step('error', 'SQL error before line #' . __LINE__ . ': <br/>' . mysql_error()); return false; }
$completedTables[] = 'questions';
if(mysql_error() != ''){ wizard_draw_step('error', 'SQL error before line #' . __LINE__ . ': <br/>' . mysql_error()); rollback($newConfId, $completedTables); return false; }
// regfee items
$errorMessage = roll($oldConfId, $newConfId, 'regfee_items');
if($errorMessage != ''){ wizard_draw_step('error', 'SQL error before line #' . __LINE__ . ': <br/>' . $errorMessage); return false; }
$completedTables[] = 'regfee_items';
if($errorMessage != ''){ wizard_draw_step('error', 'SQL error before line #' . __LINE__ . ': <br/>' . $errorMessage); rollback($newConfId, $completedTables); return false; }
// volunteer positions
$errorMessage = roll($oldConfId, $newConfId, 'volunteer_positions');
if($errorMessage != ''){ wizard_draw_step('error', 'SQL error before line #' . __LINE__ . ': <br/>' . $errorMessage); return false; }
$completedTables[] = 'volunteer_positions';
if($errorMessage != ''){ wizard_draw_step('error', 'SQL error before line #' . __LINE__ . ': <br/>' . $errorMessage); rollback($newConfId, $completedTables); return false; }
// timeslots and rounds
$q = mysql_query("SELECT * FROM judges_timeslots WHERE conferences_id='$oldConfId' AND round_id='0'");
$q = mysql_query("SELECT snoobaloo * FROM judges_timeslots WHERE conferences_id='$oldConfId' AND round_id='0'");
$errorMessage = mysql_error();
while($errorMessage == '' && $r=mysql_fetch_assoc($q)) {
if($params['rollDates'] == 'yes'){
@ -918,18 +936,41 @@ function copy_conference($params){
}
$errorMessage .= mysql_error();
}
if($errorMessage != ''){ wizard_draw_step('error', 'SQL error before line #' . __LINE__ . ': <br/>' . $errorMessage); return false; }
$completedTables[] = 'judges_timeslots';
if($errorMessage != ''){ wizard_draw_step('error', 'SQL error before line #' . __LINE__ . ': <br/>' . $errorMessage); rollback($newConfId, $completedTables); return false; }
// admin, config, and committee users
$errorMessage = conferences_copy_users($oldConfId, $newConfId, array('admin', 'config', 'committee'));
if($errorMessage != 'ok'){ wizard_draw_step('error', 'SQL error before line #' . __LINE__ . ': <br/>' . $errorMessage); return false; }
$completedTables[] = 'users';
$completedTables[] = 'user_roles';
if($errorMessage != 'ok'){ wizard_draw_step('error', 'SQL error before line #' . __LINE__ . ': <br/>' . $errorMessage); rollback($newConfId, $completedTables); return false; }
// WHEW! If we've made it this far, the conference has successfully been copied
// end the previous conference if applicable
if($params['endexisting'] == true){
// let's go ahead and end the conference that we just copied
mysql_query("UPDATE conferences SET status = 'ended' WHERE id = '$oldConfId'");
if(mysql_error() != ''){
wizard_draw_step('error', i18n("The conference was copied successfully, but not successfully ended. You will need to end the original conference manually.") . "<br/> SQL error:<br/>" . mysql_error());
return false;
}
}
return true;
}
// undo all of the conference rolling over that was done by copy_conference. This only gets called if an error occurs
// while copying to the new conference. In that case, all of the newly added data relevant to the conference is deleted,
// as well as the conference itself
function rollback($conferences_id, $tables){
foreach($tables as $table){
mysql_query("DELETE FROM `$table` WHERE `conferences_id` = $conferences_id");
}
mysql_query("DELETE FROM conferences WHERE id = $conferences_id");
}
// return empty string on success, error message otherwise
function roll($oldConfId, $newConfId, $table, $where='', $replace=array()){
/* Field Type Null Key Default Extra
@ -966,7 +1007,7 @@ function roll($oldConfId, $newConfId, $table, $where='', $replace=array()){
$q=mysql_query("SELECT * FROM $table WHERE conferences_id='$oldConfId' AND $where");
if(mysql_error() != '') $errMessage .= mysql_error() . "<br/>";
$names = '`'.join('`,`', $fields).'`';
$names = '`' . implode('`,`', $fields) . '`';
/* Process data */
while($r=mysql_fetch_assoc($q)) {

View File

@ -276,7 +276,7 @@ function user_get_role_fields($role){
'cat_prefs','div_prefs','divsub_prefs',
'expertise_other','languages', 'highest_psd');
break;
case 'student':
case 'participant':
$fields = array('grade', 'schools_id');
break;
case 'fair':
@ -363,7 +363,7 @@ function user_role_field_required($role, $fieldname){
$returnval = 0;
$requiredFields = array(
'judge' => array('years_school','years_regional','years_national','languages'),
'student' => array('schools_id'),
'participant' => array('schools_id'),
'fair' => array('fairs_id'),
'sponsor' => array('sponsors_id','primary','position'),
'volunteer' => array('languages')
@ -531,7 +531,7 @@ function user_get_fields($userRoles = null){
switch($conference['type']){
case 'sciencefair':
$specialFieldRoles = array(
'special_awards' => array('judge', 'student'),
'special_awards' => array('judge', 'participant'),
'available_times' => array('judge'),
'available_events' => array('volunteer'),
'volunteer_positions' => array('volunteer')
@ -618,6 +618,7 @@ function user_check_role_complete($u, $role){
return $result;
}
// save the user in their current state. returns 'ok' on success, error message otherwise
function user_save(&$u)
{
global $conference;
@ -647,7 +648,7 @@ function user_save(&$u)
'willing_chair','special_award_only',
'cat_prefs','div_prefs','divsub_prefs',
'expertise_other','languages', 'highest_psd');
// $fields_for_role['student'] = array('schools_id');
$fields_for_role['participant'] = array('schools_id', 'grade');
$fields_for_role['fair'] = array('fairs_id');
$fields_for_role['sponsor'] = array('sponsors_id','primary','position');
$fields_for_role['teacher'] = array();
@ -952,13 +953,13 @@ function user_add_role_allowed(&$u, $role)
{
foreach(array_keys($u['orig']['roles']) as $ur) {
switch($ur) {
case 'student':
case 'participant':
/* Student cant' add any other role */
return false;
default:
if($role == 'student') {
/* No role can add the student role */
if($role == 'particpant') {
/* No role can add the participant role */
return false;
}
@ -1180,6 +1181,16 @@ function user_judge_registration_status()
return "open";
}
function user_participant_registration_status(){
global $config;
$now = date('Y-m-d H:i:s');
if(is_array($config['dates']) && array_key_exists('regopen', $config['dates'])){
if($now < $config['dates']['regopen']) return "notopenyet";
if($now > $config['dates']['regclose']) return "closed";
}
return 'open';
}
$user_fields_map = array(
/* Account -- Email requirement is set based on username, which
* is always required. Password is not required unless they type

View File

@ -97,7 +97,7 @@ $tabs = array( 'fairinfo' => array(
'personal' => array(
'label' => 'Personal',
'name' => 'Personal Information',
'types' => array('teacher','student','judge','committee','volunteer','sponsor','fair'),
'types' => array('teacher','participant','judge','committee','volunteer','sponsor','fair'),
'file' => 'user_personal.php',
'status_func' => 'user_personal_info_status',
),
@ -153,21 +153,21 @@ $tabs = array( 'fairinfo' => array(
'account' => array(
'label' => 'Account/Login',
'name' => 'Change Username/Email/Password',
'types' => array('teacher','student','judge','committee','volunteer','sponsor','fair'),
'types' => array('teacher','participant','judge','committee','volunteer','sponsor','fair'),
'file' => 'user_account.php',
'status_func' => false,
),
'roles' => array(
'label' => 'Roles',
'name' => 'Add/Remove Roles',
'types' => array('teacher','student','judge','committee','volunteer','sponsor','fair'),
'types' => array('teacher','participant','judge','committee','volunteer','sponsor','fair'),
'file' => 'user_roles.php',
'status_func' => false,
),
'school' => array(
'label' => 'School',
'name' => 'Select School Information',
'types' => array('teacher','student','principal','parent'),
'types' => array('teacher','participant','principal','parent'),
'file' => 'user_school.php',
'status_func' => false
)

View File

@ -77,7 +77,7 @@ if(isset($_SESSION['accounts_id'])) {
/* Always open, because they could have been auto-created
$reg_open = 'open';
break;
case 'student':
case 'participant':
default:
if($_GET['action']!="logout")
exit;

View File

@ -263,15 +263,17 @@ function draw_signup_form($type){
// $password_expiry_days = $config['judges_password_expiry_days'];
// $welcome_email = "judge_welcome";
break;
/*
case 'student':
$reg_open = 'closed';
// $reg_mode = $config['judge_registration_type'];
// $reg_single_password = $config['judge_registration_singlepassword'];
$password_expiry_days = 0;
$welcome_email = "register_students_welcome";
case 'participant':
$reg_open = user_participant_registration_status();
$reg_mode = $config['participant_registration_type'];
// $reg_open = 'closed';
// $reg_mode = $config['judge_registration_type'];
// $reg_single_password = $config['judge_registration_singlepassword'];
// $password_expiry_days = 0;
// $welcome_email = "register_students_welcome";
break;
*/
default:
echo "Role type '$type' is not handled";
return;
@ -279,6 +281,7 @@ function draw_signup_form($type){
if($reg_open == 'open'){
switch($reg_mode){
case 'open':
case 'openorinvite':
echo '<p>' . i18n("Registration is open. Please click the 'Register' button if you wish to register.");
echo " &nbsp; <button onclick=\"register('" . $type . "');\">" . i18n('Register') . "</button>";
echo '</p>';
@ -297,9 +300,6 @@ function draw_signup_form($type){
case 'invite':
output_page_text("register_{$type}_invite");
break;
case 'openorinvite':
echo "\"$reg_mode\" registration is not yet handled";
break;
default:
echo "Unhandled registration mode: $reg_mode";
}