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.
This commit is contained in:
dave 2006-10-11 07:21:35 +00:00
parent 1e9f68a35e
commit 373b876b1b
3 changed files with 191 additions and 112 deletions

View File

@ -34,7 +34,7 @@
{
echo "<a href=\"judges_invite.php\">".i18n("Invite Judges")."</a><br />";
}
echo "<a href=\"judges_judges.php\">".i18n("Judges List")."</a><br />";
echo "<a href=\"judges_judges.php\">".i18n("Manage Judges")."</a> ".i18n("- Add, Delete, Edit, and List judges")."<br />";
echo "<a href=\"judges_teams.php\">".i18n("Manage Judging Teams")."</a><br />";
echo "<a href=\"judges_teams_members.php\">".i18n("Manage Judging Team Members")."</a><br />";
echo "<a href=\"judges_timeslots.php\">".i18n("Manage Judging Timeslots")."</a><br />";

View File

@ -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;
}
};
?>

View File

@ -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 "<h2>".i18n("Edit %1",array($this->recordType))."</h2>";
echo "<input type=\"hidden\" name=\"TableEditorAction\" value=\"editsave\">";
echo "<input type=\"hidden\" name=\"editsave\" value=\"{$_GET['edit']}\">";
$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 "<table class=\"tableedit\">";
foreach($this->editfields AS $f=>$n)
{
echo "<tr><th valign=\"top\">".i18n($n)."</th><td>";
//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 "<input type=\"text\" ".$this->fieldInputOptions[$f]." id=\"$f\" name=\"$f\" value=\"".htmlspecialchars($editdata->$f)."\"/>";
echo "<input type=\"text\" ".$this->fieldInputOptions[$f]." id=\"$f\" name=\"$f\" value=\"".htmlspecialchars($editdata[$f])."\"/>";
else
echo "<input type=\"text\" size=\"$inputsize\" maxlength=\"$inputmaxlen\" id=\"$f\" name=\"$f\" value=\"".htmlspecialchars($editdata->$f)."\"/>";
echo "<input type=\"text\" size=\"$inputsize\" maxlength=\"$inputmaxlen\" id=\"$f\" name=\"$f\" value=\"".htmlspecialchars($editdata[$f])."\"/>";
break;
case "textarea":
if($this->fieldInputOptions[$f])
echo "<textarea id=\"$f\" name=\"$f\" ".$this->fieldInputOptions[$f].">".htmlspecialchars($editdata->$f)."</textarea>";
echo "<textarea id=\"$f\" name=\"$f\" ".$this->fieldInputOptions[$f].">".htmlspecialchars($editdata[$f])."</textarea>";
else
echo "<textarea id=\"$f\" name=\"$f\" rows=\"5\" cols=\"50\">".htmlspecialchars($editdata->$f)."</textarea>";
echo "<textarea id=\"$f\" name=\"$f\" rows=\"5\" cols=\"50\">".htmlspecialchars($editdata[$f])."</textarea>";
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 "<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";
}
}
@ -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 "<option $sel value=\"".$opt."\">".i18n($opt)."</option>\n";
}
echo "<option value=\"\">-------------</option>";
@ -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 "<option $sel value=\"".$opt->$f."\">".i18n($opt->$f)."</option>\n";
}
echo "</select>";
@ -756,8 +784,20 @@ class TableEditor
else
echo "<input type=\"text\" size=\"$inputsize\" maxlength=\"$inputmaxlen\" id=\"".$f."_text\" name=\"".$f."_text\" value=\"\" />";
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 "<input type=\"checkbox\" name=\"{$f}_text\" value=\"\" $ch> {$this->fieldOptions[$f][$k]}<br>";
}
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 "<table width=\"10\" align=\"left\" cellspacing=0 cellpadding=0>";
@ -773,7 +813,7 @@ class TableEditor
case "time":
list($hh,$mm,$ss)=split(":",$editdata->$f);
list($hh,$mm,$ss)=split(":",$editdata[$f]);
echo "<table width=\"10\" cellspacing=0 cellpadding=0>";
echo "<tr><td class=\"tableedit\">";
@ -784,24 +824,24 @@ class TableEditor
echo "</table>";
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 "<A href=\"{$this->uploadPath}/{$editdata->$f}\">{$editdata->$f}</a>";
echo "<A href=\"{$this->uploadPath}/{$editdata[$f]}\">{$editdata[$f]}</a>";
}
else
{
echo $editdata->$f;
echo $editdata[$f];
}
echo " (".filesize($this->uploadPath."/".$editdata->$f)." bytes) <input type=\"checkbox\" name=\"clear[]\" value=\"$f\">delete<br />";
echo " (".filesize($this->uploadPath."/".$editdata[$f])." bytes) <input type=\"checkbox\" name=\"clear[]\" value=\"$f\">delete<br />";
}
else
{
echo $editdata->$f." (does not exist)<br />";
echo $editdata[$f]." (does not exist)<br />";
}
}
echo "<input type=\"file\" ".$this->fieldInputOptions[$f]." id=\"$f\" name=\"$f\" />";
@ -810,7 +850,7 @@ class TableEditor
default:
echo "<input type=\"text\" id=\"$f\" name=\"$f\" value=\"".htmlspecialchars($editdata->$f)."\"/>";
echo "<input type=\"text\" id=\"$f\" name=\"$f\" value=\"".htmlspecialchars($editdata[$f])."\"/>";
}
echo "</td></tr>";
@ -1009,7 +1049,7 @@ class TableEditor
{
echo "<td valign=\"top\">";
//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 "<A href=\"{$this->uploadPath}/{$r->$f}\">{$r->$f}</a>";
}