forked from science-ation/science-ation
- Don't need this anymore.
This commit is contained in:
parent
cac041186a
commit
48424d9f31
392
judge.class.php
392
judge.class.php
@ -1,392 +0,0 @@
|
||||
<?
|
||||
|
||||
/* Just the fields in the judges table, we use this twice */
|
||||
$judges_fields = array( 'firstname' => 'First Name',
|
||||
'lastname' => 'Last Name',
|
||||
'email' => 'Email Address',
|
||||
'password' => 'Password',
|
||||
'passwordexpiry' => 'Password Expiry',
|
||||
'phonehome' => 'Phone (Home)',
|
||||
'phonecell' => 'Phone (Cell)',
|
||||
'phonework' => 'Phone (Work)',
|
||||
'phoneworkext' => 'Phone Ext. (Work)',
|
||||
'organization' => 'Organization',
|
||||
// 'created' => 'Created',
|
||||
// 'lastlogin' => 'Last Login',
|
||||
'address' =>"Address 1",
|
||||
'address2' =>"Address 2",
|
||||
'city' => 'City',
|
||||
'province' => $config['provincestate'],
|
||||
'postalcode' => $config['postalzip'],
|
||||
// 'deleted' => 'Deleted',
|
||||
// 'deleteddatetime' => 'Deleted Date/Time',
|
||||
'expertise_other' => 'Other Expertise/Notes',
|
||||
'typepref' => 'Type Request',
|
||||
'complete' => "Complete");
|
||||
|
||||
/* 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 */
|
||||
$judges_table_fields = array( 'id' => 'ID',
|
||||
'firstname' => 'First Name',
|
||||
'lastname' => 'Last Name',
|
||||
'email' => 'Email Address',
|
||||
'complete' => 'Complete',
|
||||
// 'year' => 'Year',
|
||||
);
|
||||
|
||||
|
||||
class person {
|
||||
var $id;
|
||||
|
||||
function person($person_id=NULL)
|
||||
{
|
||||
if($person_id == NULL) {
|
||||
// print("Empty constructor called\n");
|
||||
$this->id = FALSE;
|
||||
} else {
|
||||
// print("ID $person_id construction called\n");
|
||||
$this->id = $person_id;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class judge extends person /*implements TableEditorInterface*/ {
|
||||
|
||||
/* Static members for the table editor */
|
||||
function tableEditorSetup($editor)
|
||||
{
|
||||
global $judges_fields, $judges_table_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 Pref|{$r->category}:";
|
||||
}
|
||||
|
||||
$div = array();
|
||||
$diff = 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;
|
||||
/* yes, catf */
|
||||
$catf["divpref_{$r->id}"] = "Expertise|{$r->division}:";
|
||||
}
|
||||
|
||||
$q = mysql_query("SELECT * FROM award_awards WHERE year='{$config['FAIRYEAR']}'
|
||||
AND (award_types_id=2 OR award_types_id=5) ORDER BY id");
|
||||
while($r=mysql_fetch_object($q)) {
|
||||
// $divshort[$r->id]=$r->division_shortform;
|
||||
$sa[$r->id]=$r->name;
|
||||
/* yes, catf */
|
||||
$catf["sa_{$r->id}"] = "Special Award|{$r->name}:";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/* Most of these should be moved to the base class, as they
|
||||
* 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->setRecordType('Judge');
|
||||
$editor->setListFields($judges_table_fields);
|
||||
$editor->setEditFields($e);
|
||||
|
||||
$editor->setFieldOptions('complete', array(
|
||||
array('key' => 'yes', 'val' => 'Yes'),
|
||||
array('key' => 'no', 'val' => 'No')));
|
||||
$editor->setFieldOptions('year', array(
|
||||
array('key' => 'NULL', 'val' => 'Inactive'),
|
||||
array('key' => $config['FAIRYEAR'], 'val' => $config['FAIRYEAR'])));
|
||||
|
||||
// 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');
|
||||
|
||||
|
||||
/* 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');
|
||||
}
|
||||
$expertisechoices=array(
|
||||
array('key' => 1, 'val' => "(1) Low"),
|
||||
array('key' => 2, 'val' => "(2) Med-Low"),
|
||||
array('key' => 3, 'val' => "(3) Medium"),
|
||||
array('key' => 4, 'val' => "(4) Med-High"),
|
||||
array('key' => 5, 'val' => "(5) High") );
|
||||
|
||||
foreach($div as $did=>$division) {
|
||||
$editor->setFieldOptions("divpref_$did", $expertisechoices);
|
||||
$editor->setFieldInputType("divpref_$did", 'select');
|
||||
}
|
||||
|
||||
if(count($sa)) {
|
||||
foreach($sa as $said=>$special_award) {
|
||||
$editor->setFieldOptions("sa_$said", array(
|
||||
array('key' => 'yes', 'val' => 'Would like to judge'),
|
||||
array('key' => '', 'val' => '')));
|
||||
$editor->setFieldInputType("sa_$said", 'select');
|
||||
}
|
||||
}
|
||||
|
||||
$editor->setFieldOptions('typepref', array(
|
||||
array('key' => 'speconly', 'val' => 'Special Award Judge Only'),
|
||||
array('key' => '', 'val' => 'Regular Judge')));
|
||||
$editor->SetFieldInputType('typepref', 'select');
|
||||
|
||||
|
||||
$editor->createOption('judges_show_what');
|
||||
}
|
||||
|
||||
/* STATIC */
|
||||
function tableEditorGetList($editor)
|
||||
{
|
||||
//return $editor->defaultGetList();
|
||||
global $config;
|
||||
global $judges_table_fields;
|
||||
|
||||
$show_what = $editor->getOption('judges_show_what');
|
||||
|
||||
$sel = array_keys($judges_table_fields);
|
||||
$from = array('judges');
|
||||
$where = array();
|
||||
|
||||
switch($show_what) {
|
||||
case "all":
|
||||
// $editor->additionalListTableLeftJoin("judges_years", "judges_years.judges_id=judges.id");
|
||||
// $editor->filterList("(judges_years.year={$config['FAIRYEAR']} OR judges_years.year IS NULL)");
|
||||
break;
|
||||
case "current_year_active":
|
||||
$from[] = "LEFT JOIN `judges_years` ON judges_years.judges_id=judges.id";
|
||||
$where[] = "judges_years.year={$config['FAIRYEAR']}";
|
||||
break;
|
||||
case "current_year_complete":
|
||||
$from[] = "LEFT JOIN `judges_years` ON judges_years.judges_id=judges.id";
|
||||
$where[] = "judges_years.judges_id=judges.id";
|
||||
$where[] = "judges_years.year={$config['FAIRYEAR']}";
|
||||
$where[] = "judges.complete='yes'";
|
||||
break;
|
||||
}
|
||||
//only show non-deleted judges
|
||||
$where[] = "judges.deleted='no'";
|
||||
|
||||
return array($sel, $from, $where);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* Functions for $this */
|
||||
|
||||
|
||||
function judge($judge_id=NULL)
|
||||
{
|
||||
global $judges_fields;
|
||||
person::person($judge_id);
|
||||
}
|
||||
|
||||
function tableEditorLoad()
|
||||
{
|
||||
global $config;
|
||||
|
||||
$id = $this->id;
|
||||
|
||||
// print("Loading Judge ID $id\n");
|
||||
|
||||
$q=mysql_query("SELECT judges.*
|
||||
FROM judges
|
||||
WHERE judges.id='$id'");
|
||||
echo mysql_error();
|
||||
|
||||
|
||||
/* We assume that the field names in the array we want to return
|
||||
* are the same as those in the database, so we'll turn the entire
|
||||
* query into a single associative array */
|
||||
$j = mysql_fetch_assoc($q);
|
||||
|
||||
/* Now turn on the ones this judge has selected */
|
||||
$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;
|
||||
}
|
||||
}
|
||||
$q=mysql_query("SELECT *
|
||||
FROM judges_expertise
|
||||
WHERE judges_id='$id'
|
||||
AND year='{$config['FAIRYEAR']}'");
|
||||
if(mysql_num_rows($q)) {
|
||||
while($r=mysql_fetch_object($q)) {
|
||||
$j["divpref_{$r->projectdivisions_id}"] = $r->val;
|
||||
}
|
||||
}
|
||||
|
||||
$q=mysql_query("SELECT *
|
||||
FROM judges_specialaward_sel
|
||||
WHERE judges_id='$id'
|
||||
AND year='{$config['FAIRYEAR']}'");
|
||||
if(mysql_num_rows($q)) {
|
||||
while($r=mysql_fetch_object($q)) {
|
||||
$j["sa_{$r->award_awards_id}"] = 'yes';
|
||||
}
|
||||
}
|
||||
|
||||
// print_r($j);
|
||||
|
||||
return $j;
|
||||
}
|
||||
|
||||
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 = "";
|
||||
|
||||
/* 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();
|
||||
}
|
||||
|
||||
/* Now just update the record */
|
||||
$query="UPDATE `judges` SET ";
|
||||
|
||||
foreach($judges_fields AS $f=>$n) {
|
||||
$n = $data[$f];
|
||||
$query .= "`$f`=$n,";
|
||||
}
|
||||
//rip off the last comma
|
||||
$query=substr($query,0,-1);
|
||||
|
||||
$query .= " WHERE id='{$this->id}'";
|
||||
|
||||
// echo $query;
|
||||
mysql_query($query);
|
||||
|
||||
|
||||
/* judges_languages */
|
||||
/* 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);
|
||||
|
||||
// print_r($data['language']);
|
||||
$keys = array_keys($data['language']);
|
||||
foreach($keys as $k) {
|
||||
$query = "INSERT INTO
|
||||
judges_languages (judges_id,languages_lang)
|
||||
VALUES ('{$this->id}','$k')";
|
||||
// print("$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);
|
||||
|
||||
}
|
||||
}
|
||||
/* Find all the divpref_[number] keys */
|
||||
$query = "DELETE FROM judges_expertise WHERE judges_id='{$this->id}'";
|
||||
// print($query);
|
||||
mysql_query($query);
|
||||
$keys = array_keys($data);
|
||||
foreach($keys as $k) {
|
||||
if(ereg("^divpref_([0-9]*)$", $k, $regs)) {
|
||||
if($data[$k] == "''") continue;
|
||||
$query = "INSERT INTO judges_expertise
|
||||
(judges_id,projectdivisions_id,val,year)
|
||||
values ('{$this->id}','{$regs[1]}',{$data[$k]},'{$config['FAIRYEAR']}')";
|
||||
// print($query."<br>\n");
|
||||
mysql_query($query);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
$query = "DELETE FROM judges_specialaward_sel WHERE judges_id='{$this->id}'";
|
||||
mysql_query($query);
|
||||
$keys = array_keys($data);
|
||||
foreach($keys as $k) {
|
||||
if(ereg("^sa_([0-9]*)$", $k, $regs)) {
|
||||
if($data[$k] == "''") continue;
|
||||
$query = "INSERT INTO judges_specialaward_sel
|
||||
(judges_id,award_awards_id,year)
|
||||
values ('{$this->id}','{$regs[1]}','{$config['FAIRYEAR']}')";
|
||||
// print($query."<br>\n");
|
||||
mysql_query($query);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function tableEditorDelete()
|
||||
{
|
||||
global $config;
|
||||
|
||||
$id = $this->id;
|
||||
|
||||
mysql_query("DELETE FROM judges_teams_link WHERE judges_id='$id' AND year=".$config['FAIRYEAR']."'");
|
||||
mysql_query("DELETE FROM judges_years WHERE judges_id='$id' AND year='".$config['FAIRYEAR']."'");
|
||||
mysql_query("UPDATE judges SET deleted='yes', deleteddatetime=NOW() WHERE id='$id'");
|
||||
|
||||
echo happy(i18n("Successfully deleted the judge"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
?>
|
Loading…
Reference in New Issue
Block a user