forked from science-ation/science-ation
- 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:
parent
b8f2e52401
commit
29e14c2514
@ -53,6 +53,7 @@ function openjudgeinfo(id)
|
|||||||
$icon_exitension = $config['icon_extension'];
|
$icon_exitension = $config['icon_extension'];
|
||||||
|
|
||||||
$editor = new TableEditor('judge');
|
$editor = new TableEditor('judge');
|
||||||
|
|
||||||
$editor->setDebug(true);
|
$editor->setDebug(true);
|
||||||
$editor->execute();
|
$editor->execute();
|
||||||
|
|
||||||
|
129
judge.class.php
129
judge.class.php
@ -1,6 +1,6 @@
|
|||||||
<?
|
<?
|
||||||
|
|
||||||
|
/* Just the fields in the judges table, we use this twice */
|
||||||
$judges_fields = array( 'firstname' => 'First Name',
|
$judges_fields = array( 'firstname' => 'First Name',
|
||||||
'lastname' => 'Last Name',
|
'lastname' => 'Last Name',
|
||||||
'email' => 'Email Address',
|
'email' => 'Email Address',
|
||||||
@ -24,10 +24,8 @@ $judges_fields = array( 'firstname' => 'First Name',
|
|||||||
'complete' => "Complete");
|
'complete' => "Complete");
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class person {
|
class person {
|
||||||
var $id;
|
var $id;
|
||||||
// var $fields;
|
|
||||||
|
|
||||||
function person($person_id=NULL)
|
function person($person_id=NULL)
|
||||||
{
|
{
|
||||||
@ -38,10 +36,7 @@ function person($person_id=NULL)
|
|||||||
print("ID $person_id construction called\n");
|
print("ID $person_id construction called\n");
|
||||||
$this->id = $person_id;
|
$this->id = $person_id;
|
||||||
}
|
}
|
||||||
// $this->fields = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -51,6 +46,16 @@ class judge extends person {
|
|||||||
function tableEditorSetup($editor)
|
function tableEditorSetup($editor)
|
||||||
{
|
{
|
||||||
global $judges_fields;
|
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
|
/* Setup the table editor with the fields we want to display
|
||||||
* when displaying a list of judges, and also the type of each
|
* when displaying a list of judges, and also the type of each
|
||||||
* field where required */
|
* field where required */
|
||||||
@ -63,22 +68,45 @@ function tableEditorSetup($editor)
|
|||||||
* will be the same for all person groups */
|
* will be the same for all person groups */
|
||||||
$e = array_merge($judges_fields,
|
$e = array_merge($judges_fields,
|
||||||
array( 'language' => 'Language(s)',
|
array( 'language' => 'Language(s)',
|
||||||
|
|
||||||
));
|
));
|
||||||
|
|
||||||
|
$e = array_merge($e, $catf);
|
||||||
|
|
||||||
$editor->setTable('judges');
|
$editor->setTable('judges');
|
||||||
$editor->setListFields($l);
|
$editor->setListFields($l);
|
||||||
$editor->setEditFields($e);
|
$editor->setEditFields($e);
|
||||||
|
|
||||||
|
print_r($e);
|
||||||
|
print("<br>\n");
|
||||||
/* Build an array of langauges that we support */
|
/* Build an array of langauges that we support */
|
||||||
$langs = array();
|
$langs = array();
|
||||||
$q=mysql_query("SELECT * FROM languages WHERE active='Y'");
|
$q=mysql_query("SELECT * FROM languages WHERE active='Y'");
|
||||||
while($r=mysql_fetch_object($q)) {
|
while($r=mysql_fetch_object($q)) {
|
||||||
$langs[$r->lang] = $r->langname;
|
$langs[$r->lang] = $r->langname;
|
||||||
}
|
}
|
||||||
|
|
||||||
$editor->setFieldOptions('language', $langs);
|
$editor->setFieldOptions('language', $langs);
|
||||||
$editor->setFieldInputType('language', 'multicheck');
|
$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 */
|
/* Functions for $this */
|
||||||
@ -88,11 +116,12 @@ function judge($judge_id=NULL)
|
|||||||
{
|
{
|
||||||
global $judges_fields;
|
global $judges_fields;
|
||||||
person::person($judge_id);
|
person::person($judge_id);
|
||||||
// $this->fields = $judges_fields;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function tableEditorLoad()
|
function tableEditorLoad()
|
||||||
{
|
{
|
||||||
|
global $config;
|
||||||
|
|
||||||
$id = $this->id;
|
$id = $this->id;
|
||||||
|
|
||||||
print("Loading Judge ID $id\n");
|
print("Loading Judge ID $id\n");
|
||||||
@ -112,8 +141,21 @@ function tableEditorLoad()
|
|||||||
$q=mysql_query("SELECT languages_lang
|
$q=mysql_query("SELECT languages_lang
|
||||||
FROM judges_languages
|
FROM judges_languages
|
||||||
WHERE judges_id='$id'");
|
WHERE judges_id='$id'");
|
||||||
while($r=mysql_fetch_object($q)) {
|
$j['language'] = array();
|
||||||
$j['language'][$r->languages_lang] = 1;
|
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);
|
print_r($j);
|
||||||
@ -123,44 +165,34 @@ function tableEditorLoad()
|
|||||||
|
|
||||||
function tableEditorSave($data)
|
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 $judges_fields;
|
||||||
|
global $config;
|
||||||
|
|
||||||
$query = "";
|
$query = "";
|
||||||
|
|
||||||
$insert_mode = ($this->id == false) ? 1 : 0;
|
/* Construct an insert query if we have to */
|
||||||
|
if($this->id == false) {
|
||||||
if($insert_mode) {
|
$query = "INSERT INTO judges (id) VALUES ('')";
|
||||||
$query="INSERT INTO judges (";
|
mysql_query($query);
|
||||||
//create list of fields to insert
|
$this->id = mysql_insert_id();
|
||||||
foreach($data AS $f=>$n)
|
|
||||||
$query.="`$f`,";
|
|
||||||
//rip off the last comma
|
|
||||||
$query=substr($query,0,-1);
|
|
||||||
$query.=") VALUES (";
|
|
||||||
} else {
|
|
||||||
$query="UPDATE `judges` SET ";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach($judges_fields AS $f=>$n)
|
/* Now just update the record */
|
||||||
{
|
$query="UPDATE `judges` SET ";
|
||||||
if($insert_mode) $field = '';
|
|
||||||
else $field = "`$f`=";
|
|
||||||
|
|
||||||
|
foreach($judges_fields AS $f=>$n) {
|
||||||
$n = $data[$f];
|
$n = $data[$f];
|
||||||
|
$query .= "`$f`=$n,";
|
||||||
$query .= $field.$n.",";
|
|
||||||
}
|
}
|
||||||
//rip off the last comma
|
//rip off the last comma
|
||||||
$query=substr($query,0,-1);
|
$query=substr($query,0,-1);
|
||||||
|
|
||||||
if($insertmode) {
|
$query .= " WHERE id='{$this->id}'";
|
||||||
$query.=")";
|
|
||||||
} else {
|
|
||||||
$query.=" WHERE id='{$this->id}'";
|
|
||||||
}
|
|
||||||
|
|
||||||
echo $query;
|
echo $query;
|
||||||
// mysql_query($query);
|
mysql_query($query);
|
||||||
|
|
||||||
print("data: \n");
|
print("data: \n");
|
||||||
print_r($data);
|
print_r($data);
|
||||||
@ -170,7 +202,7 @@ echo $query;
|
|||||||
/* First delete all the languages, then insert the ones the judge
|
/* First delete all the languages, then insert the ones the judge
|
||||||
* has selected */
|
* has selected */
|
||||||
$query = "DELETE FROM judges_languages WHERE judges_id='{$this->id}'";
|
$query = "DELETE FROM judges_languages WHERE judges_id='{$this->id}'";
|
||||||
//mysql_query($query);
|
mysql_query($query);
|
||||||
|
|
||||||
print_r($data['language']);
|
print_r($data['language']);
|
||||||
$keys = array_keys($data['language']);
|
$keys = array_keys($data['language']);
|
||||||
@ -179,11 +211,28 @@ echo $query;
|
|||||||
judges_languages (judges_id,languages_lang)
|
judges_languages (judges_id,languages_lang)
|
||||||
VALUES ('{$this->id}','$k')";
|
VALUES ('{$this->id}','$k')";
|
||||||
print("$query");
|
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);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -695,12 +695,12 @@ class TableEditor
|
|||||||
{
|
{
|
||||||
if(is_array($opt))
|
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";
|
echo "<option $sel value=\"".$opt['key']."\">".i18n($opt['val'])."</option>\n";
|
||||||
}
|
}
|
||||||
else
|
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";
|
echo "<option $sel value=\"".$opt."\">".i18n($opt)."</option>\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,7 @@ input {
|
|||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
color: #FFFFFF;
|
color: #FFFFFF;
|
||||||
background-color: #880000;
|
background-color: #5C6F90;
|
||||||
padding: 3px;
|
padding: 3px;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -53,7 +53,6 @@ input {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.tableedit {
|
.tableedit {
|
||||||
border-collapse: collapse;
|
|
||||||
border-spacing: 1px;
|
border-spacing: 1px;
|
||||||
color: black;
|
color: black;
|
||||||
margin-left: 20px;
|
margin-left: 20px;
|
||||||
@ -63,16 +62,16 @@ input {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.tableedit td {
|
.tableedit td {
|
||||||
border: 0px solid #880000;
|
border: 0px solid #5C6F90;
|
||||||
padding: 2px;
|
padding: 2px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.tableedit th {
|
.tableedit th {
|
||||||
border: 1px solid #880000;
|
border: 1px solid #5C6F90;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
text-align: left;
|
text-align: left;
|
||||||
color: #FFFFFF;
|
color: #FFFFFF;
|
||||||
background-color: #880000;
|
background-color: #5C6F90;
|
||||||
padding: 2px;
|
padding: 2px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user