From 373b876b1b2e0e9b59b84e722dad9720357093cb Mon Sep 17 00:00:00 2001 From: dave Date: Wed, 11 Oct 2006 07:21:35 +0000 Subject: [PATCH] Hacked up the editor a bit more. - Added a "multicheck" input type for languages (english, french) - Added a proof of concept cross reference to the judge class, it pulls the languages out of the judges_language database - Completely broke the save mechanism. - Converted the tableeditor edit routines to read from the input class - Converted the tableeditor edit routines to use assoc arrays, instead of -> (easier to pull from mysql and then add cross references to it. --- admin/judges.php | 2 +- judge.class.php | 47 +++++++- tableeditor.class.php | 254 ++++++++++++++++++++++++------------------ 3 files changed, 191 insertions(+), 112 deletions(-) diff --git a/admin/judges.php b/admin/judges.php index a3a0306c..7261a272 100644 --- a/admin/judges.php +++ b/admin/judges.php @@ -34,7 +34,7 @@ { echo "".i18n("Invite Judges")."
"; } - echo "".i18n("Judges List")."
"; + echo "".i18n("Manage Judges")." ".i18n("- Add, Delete, Edit, and List judges")."
"; echo "".i18n("Manage Judging Teams")."
"; echo "".i18n("Manage Judging Team Members")."
"; echo "".i18n("Manage Judging Timeslots")."
"; diff --git a/judge.class.php b/judge.class.php index a1107b68..f0518f2c 100644 --- a/judge.class.php +++ b/judge.class.php @@ -19,19 +19,36 @@ function editor_setup($editor) 'lastname' => 'Last Name' ); + /* Most of these should be moved to the base class, as they + * will be the same for all person groups */ $e = array( 'firstname' => 'First Name', 'lastname' => 'Last Name', + 'email' => 'Email Address', 'address' =>"Address 1", 'address2' =>"Address 2", + 'city' => 'City', + 'province' => 'Province', + 'postalcode' => 'Postal Code', + 'phonework' => 'Phone (Work)', + 'phonecell' => 'Phone (Cell)', + 'organization' => 'Organization', + 'language' => 'Language(s)', 'complete' => "Complete" ); $editor->setTable('judges'); $editor->setListFields($l); $editor->setEditFields($e); -// $editor->setFieldOptions('complete', array('yes','no')); -} + /* 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'); +} /* Functions for $this */ @@ -40,12 +57,34 @@ function judge() { } -function load() +function load($id) { + $q=mysql_query("SELECT judges.* + FROM judges + WHERE judges.id='$id'"); + echo mysql_error(); + + print("Loading Judge ID $id\n"); + + /* 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'"); + while($r=mysql_fetch_object($q)) { + $j['language'][$r->languages_lang] = 1; + } + + print_r($j); + + return $j; } }; - ?> diff --git a/tableeditor.class.php b/tableeditor.class.php index ef5a6eee..74f6a4ca 100644 --- a/tableeditor.class.php +++ b/tableeditor.class.php @@ -72,6 +72,7 @@ if(!$icon_extension) } + /** * The main class * @package tableeditor @@ -90,6 +91,7 @@ class TableEditor var $fieldOptions=array(); var $fieldValidation=array(); var $fieldDefaults=array(); + var $fieldInputType=array(); var $fieldInputOptions=array(); var $fieldFilterList=array(); var $actionButtons=array(); @@ -252,6 +254,11 @@ class TableEditor $this->fieldDefaults[$f]=$v; } + function setFieldInputType($f, $t) + { + $this->fieldInputType[$f]=$t; + } + function setFieldInputOptions($f,$o) { $this->fieldInputOptions[$f]=$o; @@ -293,6 +300,101 @@ class TableEditor $this->DEBUG=$d; } + function getFieldType($f) + { + $inputtype = ''; + $inputmaxlen = 0; + $inputsize = 0; + + //figure out what kind of input this should be + $q=mysql_query("SHOW COLUMNS FROM `{$this->table}` LIKE '$f'"); + $r=mysql_fetch_object($q); + + if(ereg("([a-z]*)\(([0-9,]*)\)",$r->Type,$regs)) + { + switch($regs[1]) + { + case "varchar": + $inputtype="text"; + $inputmaxlen=$regs[2]; + if($regs[2]>50) $inputsize=50; else $inputsize=$regs[2]; + break; + + case "int": + $inputtype="text"; + $inputmaxlen=10; + $inputsize=10; + break; + + case "decimal": + $inputtype="text"; + $inputmaxlen=10; + $inputsize=10; + break; + + case "tinyint": + $inputtype="text"; + $inputmaxlen=5; + $inputsize=4; + break; + + default: + $inputtype="text"; + $inputmaxlen=$regs[2]; + if($regs[2]>50) $inputsize=50; else $inputsize=$regs[2]; + break; + } + } + else if(ereg("([a-z]*)",$r->Type,$regs)) + { + switch($regs[1]) + { + case "text": + $inputtype="textarea"; + break; + case "date": + $inputtype="date"; + break; + case "time": + $inputtype="time"; + break; + case "enum": + //an enum is a select box, but we already know what the options should be + //so rip out the options right now and add them + $inputtype="select"; + $enums=substr(ereg_replace("'","",$r->Type),5,-1); + $toks=split(",",$enums); + foreach($toks as $tok) + { + $this->fieldOptions[$f][]=$tok; + } + break; + } + } + + if(substr($f,0,4)=="sel_") + { + $inputtype="select_or_text"; + } + + if(substr($f,0,8)=="filename" && $this->uploadPath) + { + $inputtype="file"; + } + + + if(array_key_exists($f,$this->fieldOptions)) + { + //only change to select if the type is not select_or_Text + //if we are already select or text, then the options will appear + //first in the list, then any options that arent there by default + //will appear under them in the dropdown + if($inputtype!="select_or_text") + $inputtype="select"; + } + return array($inputtype, $inputmaxlen, $inputsize); + } + function execute() { if($_GET['TableEditorAction']=="sort" && $_GET['sort']) @@ -569,7 +671,7 @@ class TableEditor if(count($this->fieldDefaults)) { foreach($this->fieldDefaults AS $f=>$n) - $editdata->$f=$n; + $editdata[$f]=$n; } } else if($action=="edit") @@ -577,122 +679,48 @@ class TableEditor echo "

".i18n("Edit %1",array($this->recordType))."

"; echo ""; echo ""; - $query="SELECT {$this->primaryKey}"; + $person = new $this->classname(); + $e = $person->load($_GET['edit']); +/* $query="SELECT {$this->primaryKey}"; foreach($this->editfields AS $f=>$n) $query.=", `$f`"; $query.=" FROM `{$this->table}`"; $query.=" WHERE {$this->primaryKey}='{$_GET['edit']}'"; if($this->DEBUG) echo $query; $editquery=mysql_query($query); - $editdata=mysql_fetch_object($editquery); + $editdata=mysql_fetch_object($editquery);*/ + $editdata = $e; } echo ""; foreach($this->editfields AS $f=>$n) { echo ""; @@ -1009,7 +1049,7 @@ class TableEditor { echo "
".i18n($n).""; - - //figure out what kind of input this should be - $q=mysql_query("SHOW COLUMNS FROM `{$this->table}` LIKE '$f'"); - $r=mysql_fetch_object($q); - - if(ereg("([a-z]*)\(([0-9,]*)\)",$r->Type,$regs)) - { - switch($regs[1]) - { - case "varchar": - $inputtype="text"; - $inputmaxlen=$regs[2]; - if($regs[2]>50) $inputsize=50; else $inputsize=$regs[2]; - break; - - case "int": - $inputtype="text"; - $inputmaxlen=10; - $inputsize=10; - break; - - case "decimal": - $inputtype="text"; - $inputmaxlen=10; - $inputsize=10; - break; - - case "tinyint": - $inputtype="text"; - $inputmaxlen=5; - $inputsize=4; - break; - - default: - $inputtype="text"; - $inputmaxlen=$regs[2]; - if($regs[2]>50) $inputsize=50; else $inputsize=$regs[2]; - break; - } - } - else if(ereg("([a-z]*)",$r->Type,$regs)) - { - switch($regs[1]) - { - case "text": - $inputtype="textarea"; - break; - case "date": - $inputtype="date"; - break; - case "time": - $inputtype="time"; - break; - case "enum": - //an enum is a select box, but we already know what the options should be - //so rip out the options right now and add them - $inputtype="select"; - $enums=substr(ereg_replace("'","",$r->Type),5,-1); - $toks=split(",",$enums); - foreach($toks as $tok) - { - $this->fieldOptions[$f][]=$tok; - } - break; - } - } - - if(substr($f,0,4)=="sel_") - { - $inputtype="select_or_text"; - } - - if(substr($f,0,8)=="filename" && $this->uploadPath) - { - $inputtype="file"; - } - - - if(array_key_exists($f,$this->fieldOptions)) - { - //only change to select if the type is not select_or_Text - //if we are already select or text, then the options will appear - //first in the list, then any options that arent there by default - //will appear under them in the dropdown - if($inputtype!="select_or_text") - $inputtype="select"; + + /* If we know the input type, assume the user knows what they are doing, else, + * try to query it from the databse */ + if(isset($this->fieldInputType[$f])) { + $inputtype = $this->fieldInputType[$f]; + $inputmaxlen = 0; // FIXME + $inputsize = 0; // FIXME + } else { + list($inputtype, $inputmaxlen, $inputsize) = $this->getFieldType($f); } switch($inputtype) { case "text": if($this->fieldInputOptions[$f]) - echo "fieldInputOptions[$f]." id=\"$f\" name=\"$f\" value=\"".htmlspecialchars($editdata->$f)."\"/>"; + echo "fieldInputOptions[$f]." id=\"$f\" name=\"$f\" value=\"".htmlspecialchars($editdata[$f])."\"/>"; else - echo "$f)."\"/>"; + echo ""; break; case "textarea": if($this->fieldInputOptions[$f]) - echo ""; + echo ""; else - echo ""; + echo ""; break; case "select": if($this->fieldInputOptions[$f]) @@ -705,12 +733,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 "\n"; } else { - if($opt == $editdata->$f) $sel="selected=\"selected\""; else $sel=""; + if($opt == $editdata[$f]) $sel="selected=\"selected\""; else $sel=""; echo "\n"; } } @@ -731,7 +759,7 @@ class TableEditor { foreach($this->fieldOptions[$f] AS $opt) { - if($opt == $editdata->$f) $sel="selected=\"selected\""; else $sel=""; + if($opt == $editdata[$f]) $sel="selected=\"selected\""; else $sel=""; echo "\n"; } echo ""; @@ -743,7 +771,7 @@ class TableEditor if(is_array($this->fieldOptions[$f]) && in_array($opt->$f,$this->fieldOptions[$f])) continue; - if($opt->$f == $editdata->$f) $sel="selected=\"selected\""; else $sel=""; + if($opt->$f == $editdata[$f]) $sel="selected=\"selected\""; else $sel=""; echo "\n"; } echo ""; @@ -756,8 +784,20 @@ class TableEditor else echo ""; break; + case "multicheck": + $ks = array_keys($this->fieldOptions[$f]); + foreach($ks as $k) { + if(array_key_exists($k, $editdata[$f])) { + $ch = ' checked=checked '; + } else { + $ch = ''; + } + echo " {$this->fieldOptions[$f][$k]}
"; + } + break; + case "date": - list($yy,$mm,$dd)=split("-",$editdata->$f); + list($yy,$mm,$dd)=split("-",$editdata[$f]); //if we put a small width here, then it prevents it from expanding to whatever width it feels like. echo ""; @@ -773,7 +813,7 @@ class TableEditor case "time": - list($hh,$mm,$ss)=split(":",$editdata->$f); + list($hh,$mm,$ss)=split(":",$editdata[$f]); echo "
"; echo "
"; @@ -784,24 +824,24 @@ class TableEditor echo "
"; break; case "file": - if($editdata->$f) + if($editdata[$f]) { - if(file_exists($this->uploadPath."/".$editdata->$f)) + if(file_exists($this->uploadPath."/".$editdata[$f])) { //only show a link to the file if the upload path is inside the document root if(strstr(realpath($this->uploadPath),$_SERVER['DOCUMENT_ROOT'])) { - echo "uploadPath}/{$editdata->$f}\">{$editdata->$f}"; + echo "uploadPath}/{$editdata[$f]}\">{$editdata[$f]}"; } else { - echo $editdata->$f; + echo $editdata[$f]; } - echo " (".filesize($this->uploadPath."/".$editdata->$f)." bytes) delete
"; + echo " (".filesize($this->uploadPath."/".$editdata[$f])." bytes) delete
"; } else { - echo $editdata->$f." (does not exist)
"; + echo $editdata[$f]." (does not exist)
"; } } echo "fieldInputOptions[$f]." id=\"$f\" name=\"$f\" />"; @@ -810,7 +850,7 @@ class TableEditor default: - echo "$f)."\"/>"; + echo ""; } echo "
"; //only show a link to the file if the upload path is inside the document root - if(strstr(realpath($this->uploadPath),$_SERVER['DOCUMENT_ROOT']) && file_exists($this->uploadPath."/".$editdata->$f)) + if(strstr(realpath($this->uploadPath),$_SERVER['DOCUMENT_ROOT']) && file_exists($this->uploadPath."/".$editdata[$f])) { echo "uploadPath}/{$r->$f}\">{$r->$f}"; }