- Fix the tableeditor to do a string compare for determining if something

should be SELECTED in the select type.  If the keys are 0, and there is no
  data, PHP does a numeric compare and matches them, when they shouldn't
  actually be matched.
- Add Load/Save for the judge category preferences
- Enable saving to mysql.  It works.
- Update the tableeditor css to use the same colours as sfiab
This commit is contained in:
dave 2006-10-17 06:44:27 +00:00
parent b8f2e52401
commit 29e14c2514
4 changed files with 96 additions and 47 deletions

View File

@ -53,6 +53,7 @@ function openjudgeinfo(id)
$icon_exitension = $config['icon_extension'];
$editor = new TableEditor('judge');
$editor->setDebug(true);
$editor->execute();

View File

@ -1,6 +1,6 @@
<?
/* Just the fields in the judges table, we use this twice */
$judges_fields = array( 'firstname' => 'First Name',
'lastname' => 'Last Name',
'email' => 'Email Address',
@ -24,10 +24,8 @@ $judges_fields = array( 'firstname' => 'First Name',
'complete' => "Complete");
class person {
var $id;
// var $fields;
function person($person_id=NULL)
{
@ -38,10 +36,7 @@ function person($person_id=NULL)
print("ID $person_id construction called\n");
$this->id = $person_id;
}
// $this->fields = NULL;
}
};
@ -51,6 +46,16 @@ class judge extends person {
function tableEditorSetup($editor)
{
global $judges_fields;
global $config;
$cat = array();
$catf = array();
$q=mysql_query("SELECT * FROM projectcategories WHERE year='".$config['FAIRYEAR']."' ORDER BY id");
while($r=mysql_fetch_object($q)) {
$cat[$r->id]=$r->category;
$catf["catpref_{$r->id}"] = "Category Preference ({$r->category})";
}
/* Setup the table editor with the fields we want to display
* when displaying a list of judges, and also the type of each
* field where required */
@ -63,22 +68,45 @@ function tableEditorSetup($editor)
* will be the same for all person groups */
$e = array_merge($judges_fields,
array( 'language' => 'Language(s)',
));
$e = array_merge($e, $catf);
$editor->setTable('judges');
$editor->setListFields($l);
$editor->setEditFields($e);
print_r($e);
print("<br>\n");
/* Build an array of langauges that we support */
$langs = array();
$q=mysql_query("SELECT * FROM languages WHERE active='Y'");
while($r=mysql_fetch_object($q)) {
$langs[$r->lang] = $r->langname;
}
$editor->setFieldOptions('language', $langs);
$editor->setFieldInputType('language', 'multicheck');
// $div = array();
// $q=mysql_query("SELECT * FROM projectdivisions WHERE year='".$config['FAIRYEAR']."' ORDER BY id");
// while($r=mysql_fetch_object($q)) {
// $divshort[$r->id]=$r->division_shortform;
// $div[$r->id]=$r->division;
// }
/* Pulled these out of register_judges.inc.php */
$preferencechoices=array(
array('key' => -2, 'val' => "Very Low"),
array('key' => -1, 'val' => "Low"),
array('key' => 0, 'val' => "Indifferent"),
array('key' => 1, 'val' => "Medium"),
array('key' => 2, 'val' => "High") );
foreach($cat as $cid=>$category) {
$editor->setFieldOptions("catpref_$cid", $preferencechoices);
$editor->setFieldInputType("catpref_$cid", 'select');
}
}
/* Functions for $this */
@ -88,11 +116,12 @@ function judge($judge_id=NULL)
{
global $judges_fields;
person::person($judge_id);
// $this->fields = $judges_fields;
}
function tableEditorLoad()
{
global $config;
$id = $this->id;
print("Loading Judge ID $id\n");
@ -112,9 +141,22 @@ function tableEditorLoad()
$q=mysql_query("SELECT languages_lang
FROM judges_languages
WHERE judges_id='$id'");
$j['language'] = array();
if(mysql_num_rows($q)) {
while($r=mysql_fetch_object($q)) {
$j['language'][$r->languages_lang] = 1;
}
}
$q=mysql_query("SELECT *
FROM judges_catpref
WHERE judges_id='$id'
AND year='{$config['FAIRYEAR']}'");
if(mysql_num_rows($q)) {
while($r=mysql_fetch_object($q)) {
$j["catpref_{$r->projectcategories_id}"] = $r->rank;
}
}
print_r($j);
@ -123,44 +165,34 @@ function tableEditorLoad()
function tableEditorSave($data)
{
/* If $this->id == false, then we need to INSERT a new record.
* if it's a number, then we want an UPDATE statement */
global $judges_fields;
global $config;
$query = "";
$insert_mode = ($this->id == false) ? 1 : 0;
/* Construct an insert query if we have to */
if($this->id == false) {
$query = "INSERT INTO judges (id) VALUES ('')";
mysql_query($query);
$this->id = mysql_insert_id();
}
if($insert_mode) {
$query="INSERT INTO judges (";
//create list of fields to insert
foreach($data AS $f=>$n)
$query.="`$f`,";
//rip off the last comma
$query=substr($query,0,-1);
$query.=") VALUES (";
} else {
/* Now just update the record */
$query="UPDATE `judges` SET ";
}
foreach($judges_fields AS $f=>$n)
{
if($insert_mode) $field = '';
else $field = "`$f`=";
foreach($judges_fields AS $f=>$n) {
$n = $data[$f];
$query .= $field.$n.",";
$query .= "`$f`=$n,";
}
//rip off the last comma
$query=substr($query,0,-1);
if($insertmode) {
$query.=")";
} else {
$query .= " WHERE id='{$this->id}'";
}
echo $query;
// mysql_query($query);
mysql_query($query);
print("data: \n");
print_r($data);
@ -170,7 +202,7 @@ echo $query;
/* First delete all the languages, then insert the ones the judge
* has selected */
$query = "DELETE FROM judges_languages WHERE judges_id='{$this->id}'";
//mysql_query($query);
mysql_query($query);
print_r($data['language']);
$keys = array_keys($data['language']);
@ -179,10 +211,27 @@ echo $query;
judges_languages (judges_id,languages_lang)
VALUES ('{$this->id}','$k')";
print("$query");
// mysql_query($query);
mysql_query($query);
}
/* judges_catpref */
$query = "DELETE FROM judges_catpref WHERE judges_id='{$this->id}'";
print($query);
mysql_query($query);
/* Find all the catpref_[number] keys */
$keys = array_keys($data);
foreach($keys as $k) {
if(ereg("^catpref_([0-9]*)$", $k, $regs)) {
if($data[$k] == "''") continue;
$query = "INSERT INTO judges_catpref
(judges_id,projectcategories_id,rank,year)
values ('{$this->id}','{$regs[1]}',{$data[$k]},'{$config['FAIRYEAR']}')";
print($query."<br>\n");
mysql_query($query);
}
}
}

View File

@ -695,12 +695,12 @@ class TableEditor
{
if(is_array($opt))
{
if($opt['key'] == $editdata[$f]) $sel="selected=\"selected\""; else $sel="";
if("{$opt['key']}" == "{$editdata[$f]}") $sel="selected=\"selected\""; else $sel="";
echo "<option $sel value=\"".$opt['key']."\">".i18n($opt['val'])."</option>\n";
}
else
{
if($opt == $editdata[$f]) $sel="selected=\"selected\""; else $sel="";
if("{$opt}" == "{$editdata[$f]}") $sel="selected=\"selected\""; else $sel="";
echo "<option $sel value=\"".$opt."\">".i18n($opt)."</option>\n";
}
}

View File

@ -38,7 +38,7 @@ input {
font-weight: bold;
text-align: center;
color: #FFFFFF;
background-color: #880000;
background-color: #5C6F90;
padding: 3px;
}
@ -53,7 +53,6 @@ input {
}
.tableedit {
border-collapse: collapse;
border-spacing: 1px;
color: black;
margin-left: 20px;
@ -63,16 +62,16 @@ input {
}
.tableedit td {
border: 0px solid #880000;
border: 0px solid #5C6F90;
padding: 2px;
}
.tableedit th {
border: 1px solid #880000;
border: 1px solid #5C6F90;
font-weight: bold;
text-align: left;
color: #FFFFFF;
background-color: #880000;
background-color: #5C6F90;
padding: 2px;
}