function offerChoices () { #---------------------------------------------------------------------- global $chosenId, $chosenConfirm; adminHeadline( 'Change Person' ); echo "<p style='width:45em'>Choose 'Fix' if you want to replace a person's information in the database. It will modify the Persons table accordingly and the Results table if the person's name is different. This should be used to fix mistakes in the database.</p>\n"; echo "<p style='width:45em'>Choose 'Update' if the person's name or country has been changed. It will add a new entry in the Persons table and make it the current information for that person (subId=1) but it will not modify the Results table so previous results keep the old name.</p>\n"; echo "<hr />"; echo "<form method='POST'>\n"; echo "<table class='prereg'>\n"; textField( 'id', 'WCA Id', $chosenId, 11 ); if( ! $chosenConfirm ) { echo "<tr><td> </td><td style='text-align:center'>"; echo "<input type='submit' id='confirm' name='confirm' value='Confirm' style='background-color:#9F3;font-weight:bold' /> "; echo "</td></tr></table></form>"; return; } $persons = dbQuery( "SELECT * FROM Persons WHERE id='$chosenId' AND subId=1" ); if( count( $persons ) == 0 ){ noticeBox(false, 'Unknown WCA Id '.$chosenId); return; } $person = array_shift( $persons ); extract( $person ); #--- Name textField( 'name', 'Name', $name, 50 ); #--- Country $countries = dbQuery( "SELECT * FROM Countries" ); $fieldC = ''; foreach( $countries as $country ){ $cId = $country['id' ]; $cName = $country['name']; if( $cId == $countryId ) $fieldC .= " <option value=\"$cId\" selected='selected' >$cName</option>\n"; else $fieldC .= " <option value=\"$cId\">$cName</option>\n"; } echo " <tr><td width='30%'><label for='countryId'><b>Country</b></label></td>\n"; echo " <td><select id='countryId' name='countryId'>\n"; echo $fieldC; echo " </select></td></tr>\n"; #--- Gender if( $gender == 'm' ) $fieldG = "Male : <input type='radio' id='gender' name='gender' value='m' checked='checked' /> Female : <input type='radio' id='gender' name='gender' value='f' />"; else if( $gender == 'f' ) $fieldG = "Male : <input type='radio' id='gender' name='gender' value='m' /> Female : <input type='radio' id='gender' name='gender' value='f' checked='checked' />"; else $fieldG = "Male : <input type='radio' id='gender' name='gender' value='m' /> Female : <input type='radio' id='gender' name='gender' value='f' />"; echo " <tr><td width='30%'><label for='gender'><b>Gender</b></label></td><td>$fieldG</td></tr>\n"; #--- DoB echo " <tr><td><b>Date of birth</b></td><td>"; echo numberSelect( "day", "Day", 1, 31, $day ); echo numberSelect( "month", "Month", 1, 12, $month ); echo numberSelect( "year", "Year", date("Y"), date("Y")-100, $year ); echo "</td></tr>\n"; #--- Submit echo "<tr><td> </td><td style='text-align:center'>"; echo "<input type='submit' id='update' name='update' value='Update' style='background-color:#9F3;font-weight:bold' /> "; ?> <script> (function() { $('#update').click(function(e) { if(!confirm("Are you sure that you want to \"update\", not \"fix\", the competitor's data? (see information above)")) { e.preventDefault(); } }); })(); </script> <?php echo "<input type='submit' id='fix' name='fix' value='Fix' style='background-color:#9F3;font-weight:bold' /> "; echo "</td></tr></table></form>"; }
function showField($fieldSpec) { #---------------------------------------------------------------------- list($id, $type, $rest) = explode(' ', $fieldSpec, 3); #--------------------- if ($type == 'hidden') { #--------------------- $value = $rest; echo "<input id='{$id}' name='{$id}' type='hidden' value='{$value}' />"; } #--------------------- if ($type == 'text') { #--------------------- list($default, $size, $label) = explode(' ', $rest, 3); $fieldHtml = "<input id='{$id}' name='{$id}' type='text' value='{$default}' size='{$size}' />"; $type = 'standard'; } #--------------------- if ($type == 'readonly') { #--------------------- list($default, $size, $label) = explode(' ', $rest, 3); $fieldHtml = "<input id='{$id}' name='{$id}' type='text' value='{$default}' size='{$size}' readonly='readonly' />"; $type = 'standard'; } #--------------------- if ($type == 'name') { #--------------------- list($size, $label, $default) = explode(' ', $rest, 3); $fieldHtml = "<input id='{$id}' name='{$id}' type='text' value='{$default}' size='{$size}' />"; $fieldHtml .= "<input type='submit' id='search' name='search' value='Search' />"; $type = 'standard'; } #--------------------- if ($type == 'namelist') { #--------------------- global $persons; list($label) = explode(' ', $rest, 1); $fieldHtml = "<select id='{$id}' name='{$id}'>\n"; foreach ($persons as $person) { $personName = $person['name']; $personId = $person['id']; $fieldHtml .= " <option value='{$personId}'>{$personName}</option>\n"; } $fieldHtml .= "</select>"; $fieldHtml .= "<input type='submit' id='confirm' name='confirm' value='Load' />"; $type = 'standard'; } #--------------------- if ($type == 'country') { #--------------------- list($label, $default) = explode(' ', $rest, 2); $fieldHtml = "<select id='{$id}' name='{$id}'>\n"; $countries = dbQuery("SELECT * FROM Countries ORDER BY name"); foreach ($countries as $country) { $countryId = $country['id']; $countryName = $country['name']; if ($countryId == $default) { $fieldHtml .= " <option value=\"{$countryId}\" selected='selected' >{$countryName}</option>\n"; } else { $fieldHtml .= " <option value=\"{$countryId}\">{$countryName}</option>\n"; } } $fieldHtml .= "</select>"; $type = 'standard'; } #--------------------- if ($type == 'gender') { #--------------------- list($default, $label) = explode(' ', $rest, 2); if ($default == 'm') { $fieldHtml = "Male : <input type='radio' id='{$id}' name='{$id}' value='m' checked='checked' /> Female : <input type='radio' id='{$id}' name='{$id}' value='f' />"; } else { if ($default == 'f') { $fieldHtml = "Male : <input type='radio' id='{$id}' name='{$id}' value='m' /> Female : <input type='radio' id='{$id}' name='{$id}' value='f' checked='checked' />"; } else { $fieldHtml = "Male : <input type='radio' id='{$id}' name='{$id}' value='m' /> Female : <input type='radio' id='{$id}' name='{$id}' value='f' />"; } } $type = 'standard'; } #--------------------- if ($type == 'date') { #--------------------- list($defaultDay, $defaultMonth, $defaultYear, $label) = explode(' ', $rest, 4); echo " <tr><td>{$label}</td><td>"; echo numberSelect("{$id}Day", "Day", 1, 31, $defaultDay); echo numberSelect("{$id}Month", "Month", 1, 12, $defaultMonth); echo numberSelect("{$id}Year", "Year", date("Y"), date("Y") - 100, $defaultYear); echo "</td></tr>\n"; } #--------------------- if ($type == 'area') { #--------------------- list($cols, $rows, $label, $default) = explode(' ', $rest, 4); $fieldHtml = "<textarea id='{$id}' name='{$id}' cols='{$cols}' rows='{$rows}'>{$default}</textarea>"; $type = 'standard'; } #--------------------- if ($type == 'standard') { #--------------------- echo " <tr><td width='30%'><label for='{$id}'>{$label}</label></td><td>{$fieldHtml}</td></tr>\n"; } #--------------------- if ($type == 'event') { #--------------------- $eventId = substr($id, 1); $event = getEvent($eventId); $eventName = $event['cellName']; $eventFormat = $event['format']; list($personLimit, $timeLimit, $timeFormat, $default) = explode(' ', $rest, 4); if ($timeLimit) { $timeFormat = $timeFormat == 's' ? 'single' : 'average'; if ($eventFormat == 'multi') { if ($timeLimit > 1) { $timeLimit = "{$timeLimit} cubes"; } else { $timeLimit = "1 cube"; } } else { $timeLimit = formatValue($timeLimit, $eventFormat); } $timeLimit = " ({$timeFormat} limit {$timeLimit})"; } if ($default) { echo "<input id='{$id}' name='{$id}' type='checkbox' value='yes' checked='checked' />"; } else { echo "<input id='{$id}' name='{$id}' type='checkbox' value='yes' />"; } if (count(dbQuery("SELECT * FROM Events WHERE id='{$eventId}' AND rank<990"))) { echo " <label for='{$id}'>{$eventName}{$timeLimit}</label><br />"; } else { echo " <label for='{$id}' style='color:#999'>{$eventName}{$timeLimit}</label><br />"; } } }