From 1e1fa0097ab25be03dd52018b648b5ea3befe929 Mon Sep 17 00:00:00 2001 From: jacob Date: Fri, 26 Nov 2010 16:50:17 +0000 Subject: [PATCH] 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". --- account.inc.php | 8 +-- common.inc.php | 2 +- scripts/compvars.php | 127 ++++++++++++++++++++++++++++++++++++++++++ super/conferences.php | 77 +++++++++++++++++++------ user.inc.php | 25 ++++++--- user_edit.php | 8 +-- user_login.php | 2 +- user_main.php | 22 ++++---- 8 files changed, 225 insertions(+), 46 deletions(-) create mode 100755 scripts/compvars.php diff --git a/account.inc.php b/account.inc.php index f2ac3b8..98a459c 100644 --- a/account.inc.php +++ b/account.inc.php @@ -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; } diff --git a/common.inc.php b/common.inc.php index 5848910..5067429 100644 --- a/common.inc.php +++ b/common.inc.php @@ -273,7 +273,7 @@ if(array_key_exists('users_id', $_SESSION)) { if(in_array('sponsor', $_SESSION['roles'])) { // echo "
  • ".i18n("Sponsor Home").'
  • '; } - if(in_array('student', $_SESSION['roles'])) { + if(in_array('participant', $_SESSION['roles'])) { echo "
  • ".i18n("Participant Home").'
  • '; } } diff --git a/scripts/compvars.php b/scripts/compvars.php new file mode 100755 index 0000000..a3def19 --- /dev/null +++ b/scripts/compvars.php @@ -0,0 +1,127 @@ +#!/usr/bin/php + 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; +} diff --git a/super/conferences.php b/super/conferences.php index 593e033..feac1c6 100644 --- a/super/conferences.php +++ b/super/conferences.php @@ -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__ . ':
    ' . mysql_error()); return false; } + $completedTables[] = 'dates'; + if(mysql_error() != ''){ wizard_draw_step('error', 'SQL error before line #' . __LINE__ . ':
    ' . 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__ . ':
    ' . mysql_error()); return false; } + $completedTables[] = 'pagetext'; + if(mysql_error() != ''){ wizard_draw_step('error', 'SQL error before line #' . __LINE__ . ':
    ' . 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__ . ':
    ' . mysql_error()); return false; } + $completedTables[] = 'projectcategories'; + if(mysql_error() != ''){ wizard_draw_step('error', 'SQL error before line #' . __LINE__ . ':
    ' . 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__ . ':
    ' . mysql_error()); return false; } + $completedTables[] = 'projectdivisions'; + if(mysql_error() != ''){ wizard_draw_step('error', 'SQL error before line #' . __LINE__ . ':
    ' . 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__ . ':
    ' . mysql_error()); return false; } + $completedTables[] = 'projectsubdivisions'; + if(mysql_error() != ''){ wizard_draw_step('error', 'SQL error before line #' . __LINE__ . ':
    ' . 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__ . ':
    ' . mysql_error()); return false; } + $completedTables[] = 'safetyquestions'; + if(mysql_error() != ''){ wizard_draw_step('error', 'SQL error before line #' . __LINE__ . ':
    ' . 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__ . ':
    ' . $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__ . ':
    ' . $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__ . ':
    ' . mysql_error()); return false; } + $completedTables[] = 'award_types'; + if(mysql_error() != ''){ wizard_draw_step('error', 'SQL error before line #' . __LINE__ . ':
    ' . 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__ . ':
    ' . mysql_error()); return false; } + $completedTables[] = 'schools'; + if(mysql_error() != ''){ wizard_draw_step('error', 'SQL error before line #' . __LINE__ . ':
    ' . 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__ . ':
    ' . mysql_error()); return false; } + $completedTables[] = 'questions'; + if(mysql_error() != ''){ wizard_draw_step('error', 'SQL error before line #' . __LINE__ . ':
    ' . 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__ . ':
    ' . $errorMessage); return false; } + $completedTables[] = 'regfee_items'; + if($errorMessage != ''){ wizard_draw_step('error', 'SQL error before line #' . __LINE__ . ':
    ' . $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__ . ':
    ' . $errorMessage); return false; } + $completedTables[] = 'volunteer_positions'; + if($errorMessage != ''){ wizard_draw_step('error', 'SQL error before line #' . __LINE__ . ':
    ' . $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__ . ':
    ' . $errorMessage); return false; } + $completedTables[] = 'judges_timeslots'; + if($errorMessage != ''){ wizard_draw_step('error', 'SQL error before line #' . __LINE__ . ':
    ' . $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__ . ':
    ' . $errorMessage); return false; } - + $completedTables[] = 'users'; + $completedTables[] = 'user_roles'; + if($errorMessage != 'ok'){ wizard_draw_step('error', 'SQL error before line #' . __LINE__ . ':
    ' . $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.") . "
    SQL error:
    " . 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() . "
    "; - $names = '`'.join('`,`', $fields).'`'; + $names = '`' . implode('`,`', $fields) . '`'; /* Process data */ while($r=mysql_fetch_assoc($q)) { diff --git a/user.inc.php b/user.inc.php index 7dc9600..fb8ff38 100644 --- a/user.inc.php +++ b/user.inc.php @@ -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 diff --git a/user_edit.php b/user_edit.php index 172d1d9..d0affba 100644 --- a/user_edit.php +++ b/user_edit.php @@ -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 ) diff --git a/user_login.php b/user_login.php index e3a1896..6018a28 100644 --- a/user_login.php +++ b/user_login.php @@ -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; diff --git a/user_main.php b/user_main.php index daad272..954d214 100644 --- a/user_main.php +++ b/user_main.php @@ -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 '

    ' . i18n("Registration is open. Please click the 'Register' button if you wish to register."); echo "   "; echo '

    '; @@ -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"; }