table = $table;
$this->key = $key;
$this->value = $value;
$this->refField = $refField;
$this->condition = $condition;
$this->clickButton = $clickButton;
$this->masterField = $masterField;
}
}
class UT_FieldStruct {
var $DBField = "";
var $desc = "";
var $width = 0;
var $len = 0;
var $default = "";
var $listType = 0;
var $editType = 0;
var $option = 0;
var $extra = "";
var $cond = "";
}
class UT_Template {
var $DateFormat = "Y-m-d";
var $Validation = "";
function PRI_date($timestamp) {
if (($timestamp != "" ) && ($timestamp != 0)) {
return date($this->DateFormat, $timestamp);
} else
return "";
}
function PRI_mktime($timestr) {
if (($timestr != "" ) && ($timestr != 0)) {
list($date, $time) = explode(' ', $timestr);
list($yyyy, $mm, $dd) = explode('-', $date);
list($hr, $min, $ss) = explode(':', $time);
return mktime(intval($hr), intval($min), intval($ss), intval($mm), intval($dd), intval($yyyy));
} else
return 0;
}
function jAlert($field, $fieldDesc){
$output = " $('body').append(\"
".$fieldDesc." field is a mandatory field. Try again!
\");\r\n";
$output .= " $( '#ALERT_dialog_message' ).dialog({modal: true, close: function(ev, ui) { $(this).remove(); }, buttons: {\r\n";
$output .= " Ok: function(){\r\n";
$output .= " $( this ).dialog( 'close' ); $('#".$field."').focus();\r\n";
$output .= " }}\r\n";
$output .= " });\r\n";
return $output;
}
function fileImage($ext){
$ext = strtolower($ext);
switch($ext){
case "jpg":
case "gif":
case "png":
$tImg = " ";
break;
case "pdf":
$tImg = " ";
break;
case "doc":
$tImg = " ";
break;
case "xls":
$tImg = " ";
break;
default:
$tImg = " ";
}
return $tImg;
}
function mandatoryCheck() {
$output = $this->Validation;
$space = " ";
if(is_array($this->UT_Value->desc))
$this->UT_Value->desc = $this->UT_Value->desc[0];
else
$this->UT_Value->desc = $this->UT_Value->desc;
if ($this->UT_Value->option & __UT_TEMPLATE_OPTION_MANDATORY__) {
switch (true) {
case ($this->UT_Value->editType & __UT_TEMPLATE_EDITTYPE_FILE__):
case ($this->UT_Value->editType & __UT_TEMPLATE_EDITTYPE_INPUTBOX__):
case ($this->UT_Value->editType & __UT_TEMPLATE_EDITTYPE_TEXTBOX__):
$output .= $space . "if ( $('#" . $this->UT_Value->DBField . "').val()=='') {\r\n";
$output .= $space . $this->jAlert($this->UT_Value->DBField , $this->UT_Value->desc);
$output .= $space . " return false;\r\n";
$output .= $space . "}\r\n\r\n";
break;
case ($this->UT_Value->editType & __UT_TEMPLATE_EDITTYPE_PASSWORD__):
$output .= $space . "if (UT_INPUTFORM." . $this->UT_Value->DBField . ".value=='') {\r\n";
$output .= $space . " alert('*** " . $this->UT_Value->desc . " *** is a mandatory field. Try again');\r\n";
$output .= $space . " UT_INPUTFORM." . $this->UT_Value->DBField . ".focus();\r\n";
$output .= $space . " return false;\r\n";
$output .= $space . "}\r\n\r\n";
break;
case ($this->UT_Value->editType & __UT_TEMPLATE_EDITTYPE_DATESTR__):// tested, ok
$output .= $space . "if ( $('#" . $this->UT_Value->DBField . "').val()=='') {\r\n";
$output .= $space . $this->jAlert($this->UT_Value->DBField , $this->UT_Value->desc);
$output .= $space . " return false;\r\n";
$output .= $space . "}\r\n\r\n";
break;
case ($this->UT_Value->editType & __UT_TEMPLATE_EDITTYPE_DATETIME__):
break;
case ($this->UT_Value->editType & __UT_TEMPLATE_EDITTYPE_SELECTION__):
case ($this->UT_Value->editType & __UT_TEMPLATE_EDITTYPE_CHECKBOX__):
case ($this->UT_Value->editType & __UT_TEMPLATE_EDITTYPE_RADIO__):
$output .= $space . "if ( $('#" . $this->UT_Value->DBField . "').val()==0) {\r\n";
$output .= $space . $this->jAlert($this->UT_Value->DBField , $this->UT_Value->desc);
$output .= $space . " $('#" . $this->UT_Value->DBField . "').focus();\r\n";
$output .= $space . " return false;\r\n";
$output .= $space . "}\r\n\r\n";
break;
case ($this->UT_Value->editType & __UT_TEMPLATE_EDITTYPE_FILE__):
break;
}
}
return $output;
}
function PRI_extractIncrPattern($value, $pattern="#") {
$ret = strstr($value, $pattern);
if ($ret != str_pad("", strlen($ret), $pattern)) {
$ret = $this->PRI_extractIncrPattern(substr($ret, 1));
}
return $ret;
}
function PRI_loadDBValue_selection($value) {
$db = new DB;
$tmpArray = array();
$sqlCondition = "";
if ($this->UT_Value->extra->condition != "") {
if ($sqlCondition != "")
$sqlCondition .= " and ";
$sqlCondition .= $this->UT_Value->extra->condition;
}
// Changes for TEMPLATE Version 2.0 2013年11月5日
if ($sqlCondition != "")
$sqlCondition = " where " . __UT_TEMPLATE_DBFIELD_STATUS__ . "=" . __UT_REC_ACTIVE__ . " and " . $sqlCondition;
// Changes for TEMPLATE Version 2.0 2013年11月5日
if (is_array($this->UT_Value->extra->value)) {
$i = 0;
foreach($this->UT_Value->extra->value as $index => $dbValue) {
if ($i++ == 0)
$sqlValue = "concat(" . $dbValue;
else
$sqlValue .= ", ' ', " . $dbValue;
}
$sqlValue .= ") as UT_SELECTION_VALUE";
}
else {
$sqlValue = $this->UT_Value->extra->value . " as UT_SELECTION_VALUE";
}
if($this->UT_Value->extra->separateLine != "") {
$sqlValue .= ", " . $this->UT_Value->extra->separateLine;
}
$sqlstr = "select " . $this->UT_Value->extra->key . ", " . $sqlValue . " from " . $this->UT_Value->extra->table . $sqlCondition;
$db->query($sqlstr);
while($db->next_record()) {
$tmpArray[$db->f($this->UT_Value->extra->key)] = ($this->UT_Value->extra->separateLine != "" ? $db->f($this->UT_Value->extra->separateLine) . " - " : "") . $db->f("UT_SELECTION_VALUE");
}
return ($tmpArray);
}
function PRI_constructDBValue_selection($tmpArray, $value) {
if ($this->UT_Value->option & __UT_TEMPLATE_OPTION_READONLY__) {
$output .= " ";
}
else {
$output .= " \r\n";
if ($tmpArray[0] == "")
$output .= " -- " . $this->UT_Value->desc . " -- \r\n";
}
foreach($tmpArray as $i => $selection) {
while(is_array($selection)) {
$selection = $selection[0];
}
if ($this->UT_Value->option & __UT_TEMPLATE_OPTION_READONLY__) {
if ($i == $value)
$output .= " " . $selection . " \r\n";
}
else {
if ($i == $value)
$output .= " " . $selection . " \r\n";
else
$output .= " " . $selection . " \r\n";
}
}
if (!($this->UT_Value->option & __UT_TEMPLATE_OPTION_READONLY__))
$output .= " ";
$output .= "UT_Value->DBField . ">
";
$output .= " \r\n";
return ($output);
}
function PRI_loadDBValue_File($value) {
$tmpArray = explode(".", $value);
switch(strtolower($tmpArray[sizeof($tmpArray) - 1])) {
case "jpg":
case "gif":
$tmpWidthDesc = "";
list($width, $height, $type, $attr) = getimagesize($this->UT_Value->extra[0] . $value);
if ($width > 400)
$tmpWidthDesc = " width=400";
$output .= " " . $value . " \r\n";
$output .= " \r\n";
break;
case "pdf":
$output .= " " . $value . " \r\n";
$output .= " \r\n";
break;
case "doc":
case "xls":
break;
}
return ($output);
}
// *******************************************************************
// * New data
// *******************************************************************
function newDBValue() {
$retValue = "";
if ( !(($this->UT_Value->option & __UT_TEMPLATE_OPTION_PRIMARYKEY__) || ($this->UT_Value->option & __UT_TEMPLATE_OPTION_AUTOINCREMENT__)) &&
(isset($_GET["UT_SCH_" . $this->UT_Value->DBField])) ) {
$retValue = $this->loadDBValue($_GET["UT_SCH_" . $this->UT_Value->DBField]);
}
else {
if (is_array($this->UT_Value->default))
$retValue = $this->loadDBValue($this->UT_Value->default[0]);
else
$retValue = $this->loadDBValue($this->UT_Value->default);
}
return $retValue;
}
// *******************************************************************
// * load data
// *******************************************************************
function loadDBValue($in_value, $width = '120') {
$output = "";
$additionDesc = "";
$value = htmlspecialchars($in_value, ENT_QUOTES);// chiu add
if ($this->UT_Value->option & __UT_TEMPLATE_OPTION_MANDATORY__)
$additionDesc = "* ";
if(is_array($this->UT_Value->desc))
$this->UT_Value->desc = $this->UT_Value->desc[1];
else
$this->UT_Value->desc = $this->UT_Value->desc;
switch (true) {
case ($this->UT_Value->editType & __UT_TEMPLATE_EDITTYPE_INPUTBOX__):
switch (true) {
case ($this->UT_Value->option & __UT_TEMPLATE_OPTION_HIDDEN__):
$output .= " \r\n";
break;
case ($this->UT_Value->option & __UT_TEMPLATE_OPTION_READONLY__):
if (is_array($this->UT_Value->default))
$tmp_value = sprintf($this->UT_Value->default[1], $value);
else
$tmp_value = $value;
$output .= "" . $this->UT_Value->desc . " \r\n";
$output .= " " . $tmp_value . " \r\n";
$output .= " \r\n";
$output .= " \r\n";
break;
case ($this->UT_Value->option & __UT_TEMPLATE_OPTION_PRIMARYKEY__):
if ($value == "") {
$value = "--";
}
$output .= "" . $this->UT_Value->desc . $additionDesc . " \r\n";
$output .= " " . $value . " \r\n";
$output .= " \r\n";
$output .= " \r\n";
break;
case ($this->UT_Value->option & __UT_TEMPLATE_OPTION_AUTOINCREMENT__):
if ($value == "") {
$value = "##########"; // if no default value, use the 10 digit value
}
$output .= "" . $this->UT_Value->desc . $additionDesc . " \r\n";
$output .= " " . $value . " \r\n";
$output .= " \r\n";
$output .= " \r\n";
break;
default:
if ($this->UT_Value->option & __UT_TEMPLATE_OPTION_AUTOCOMPLETE__) {
$output .= "\r\n";
}
$output .= "" . $this->UT_Value->desc . $additionDesc . " \r\n";
$output .= " UT_Value->DBField . ">
\r\n";
$output .= " \r\n";
break;
}
break;
case ($this->UT_Value->editType & __UT_TEMPLATE_EDITTYPE_TEXTBOX__):
switch (true) {
case ($this->UT_Value->option & __UT_TEMPLATE_OPTION_HIDDEN__):
break;
case ($this->UT_Value->option & __UT_TEMPLATE_OPTION_READONLY__):
$output .= "" . $this->UT_Value->desc . $additionDesc . " \r\n";
$output .= " " . $in_value . " \r\n";
$output .= " \r\n";
break;
default:
$output .= "" . $this->UT_Value->desc . $additionDesc . " \r\n";
$output .= " \r\n";
$output .= " \r\n";
break;
}
break;
case ($this->UT_Value->editType & __UT_TEMPLATE_EDITTYPE_DATETIME__):
switch (true) {
case ($this->UT_Value->option & __UT_TEMPLATE_OPTION_HIDDEN__):
$output .= " \r\n";
break;
case ($this->UT_Value->option & __UT_TEMPLATE_OPTION_READONLY__):
// $value = $this->PRI_date($value);
$output .= "" . $this->UT_Value->desc . $additionDesc . " \r\n";
$output .= " " . $this->PRI_date($value) . " \r\n";
$output .= " \r\n";
$output .= " \r\n";
break;
default:
$output .= "" . $this->UT_Value->desc . $additionDesc . " \r\n";
$output .= " \r\n";
$output .= " \r\n";
$output .= " \r\n";
$output .= " \r\n";
break;
}
break;
case ($this->UT_Value->editType & __UT_TEMPLATE_EDITTYPE_DATESTR__):
switch (true) {
case ($this->UT_Value->option & __UT_TEMPLATE_OPTION_HIDDEN__):
$output .= " \r\n";
break;
case ($this->UT_Value->option & __UT_TEMPLATE_OPTION_READONLY__):
if($value){
$date_arr = explode(' ', $value);
}
switch ($this->UT_Value->extra) {
case "DT":
break;
case "D":
$value = $date_arr[0];
break;
case "T":
$value = $date_arr[1];
break;
}
$output .= "" . $this->UT_Value->desc . $additionDesc . " \r\n";
$output .= " " . $value . " \r\n";
$output .= " \r\n";
$output .= " \r\n";
break;
default:
list($date, $time) = explode(' ', $value);
switch ($this->UT_Value->extra) {
case "DT":
$js_picker .= "var tmp_".$this->UT_Value->DBField." = $('#".$this->UT_Value->DBField."');\r\n";
$js_picker .= "tmp_".$this->UT_Value->DBField.".datetimepicker({ dateFormat: 'yy-mm-dd', timeFormat: 'hh:mm tt' } );\r\n";
break;
case "D":
$value = $date;
$js_picker .= "$( '#".$this->UT_Value->DBField."' ).datepicker({ dateFormat: 'yy-mm-dd' });\r\n";
break;
case "T":
$value = $time;
$js_picker .= "$( '#".$this->UT_Value->DBField."' ).timepicker({ timeFormat: 'hh:mm tt' });\r\n";
break;
default:
$js_picker .= "$( '#".$this->UT_Value->DBField."' ).datepicker({ dateFormat: 'yy-mm-dd' });\r\n";
break;
}
$output .= "" . $this->UT_Value->desc . $additionDesc . " \r\n";
$output .= " \r\n";
$output .= " \r\n";
$output .= " \r\n";
$output .= " \r\n";
break;
}
break;
case ($this->UT_Value->editType & __UT_TEMPLATE_EDITTYPE_CHECKBOX__):
switch (true) {
case ($this->UT_Value->option & __UT_TEMPLATE_OPTION_FOREIGNKEY__):
$tmpArray = $this->PRI_loadDBValue_selection($value);
break;
default:
$tmpArray = $this->UT_Value->extra;
break;
}
$output .= "" . $this->UT_Value->desc . $additionDesc . " \r\n";
$output .= " \r\n";
$output .= " \r\n";
$output .= " \r\n";
$output .= " \r\n";
break;
case ($this->UT_Value->editType & __UT_TEMPLATE_EDITTYPE_RADIO__):
$output .= "" . $this->UT_Value->desc . $additionDesc . " \r\n";
$output .= " \r\n";
foreach($this->UT_Value->extra as $i => $selection) {
if ($i == $value)
$output .= " " . $selection . "\r\n";
else
$output .= " " . $selection . "\r\n";
}
$output .= " \r\n";
$output .= "\r\n";
break;
case ($this->UT_Value->editType & __UT_TEMPLATE_EDITTYPE_SELECTION__):
switch (true) {
/*******************************************************/
/********** Selection & Master Detail (START) **********/
case ($this->UT_Value->option & __UT_TEMPLATE_OPTION_AUTOCOMPLETE__):
$output .= "\r\n";
$tmpArray = $this->PRI_loadDBValue_selection($value);
break;
/********** Selection & Master Detail (START) **********/
/*******************************************************/
/*******************************************************/
/********** Selection & Master Detail (START) **********/
case ($this->UT_Value->option & __UT_TEMPLATE_OPTION_MASTERDETAIL_REF__ && $this->UT_Value->option & __UT_TEMPLATE_OPTION_FOREIGNKEY__):
$output .= "\r\n";
$tmpArray = array();
break;
/********** Selection & Reload (END) **********/
/*******************************************************/
/*******************************************************/
/********** Selection & Foreignkey (START) **********/
case ($this->UT_Value->option & __UT_TEMPLATE_OPTION_FOREIGNKEY__):
$tmpArray = $this->PRI_loadDBValue_selection($value);
break;
/********** Selection & Foreignkey (END) **********/
default:
$tmpArray = $this->UT_Value->extra;
break;
}
$output .= "" . $this->UT_Value->desc . $additionDesc . " \r\n";
if ($this->UT_Value->option & __UT_TEMPLATE_OPTION_AUTOCOMPLETE__) {
$output .= " \r\n";
$output .= " \r\n";
$output .= " \r\n";
$output .= " UT_Value->DBField . ">
\r\n";
$output .= " \r\n";
}
else {
$output .= $this->PRI_constructDBValue_selection($tmpArray, $value);
}
$output .= "\r\n";
/********** Selection & NOT Readonly (END) ***********/
break;
case ($this->UT_Value->editType & __UT_TEMPLATE_EDITTYPE_PASSWORD__):
if ($this->UT_Value->option & __UT_TEMPLATE_OPTION_MD5_PASSWORD__) {
$output .= " \r\n";
$this->Validation .= "if( $('#". $this->UT_Value->DBField . "').val() != \"" . $value . "\" ){ $('#". $this->UT_Value->DBField . "_MD5_Changed').val('1'); }\r\n";// let program know it changed or not
}
$output .= "" . $this->UT_Value->desc . $additionDesc . " \r\n";
$output .= " \r\n";
$output .= " \r\n";
$output .= "Re-Type " . $this->UT_Value->desc . $additionDesc . "* \r\n";
$output .= " \r\n";
$output .= " \r\n";
$this->Validation .= "if( ($('#". $this->UT_Value->DBField . "').val() != $('#". $this->UT_Value->DBField . "2').val() ) || $('#". $this->UT_Value->DBField . "').val()=='' ){\r\n";
$this->Validation .= " $('#". $this->UT_Value->DBField . "').focus();\r\n";
$this->Validation .= " alert('Password not match');\r\n";
$this->Validation .= " return false;\r\n";
$this->Validation .= "};\r\n\r\n";
break;
case ($this->UT_Value->editType & __UT_TEMPLATE_EDITTYPE_FILE__):
switch (true) {
case ($this->UT_Value->option & __UT_TEMPLATE_OPTION_IMG__):
$tFileType = "IMAGE"; // for detect resize
break;
default:
$tFileType = "FILE";
}
//$UTValue["Image"] = new UT_Template;
// $UTValue["Image"]->set_var("Image", "Image", 60, 100, "", 1, 256, 16, array("../uploadFolder/news/", "['jpg', 'jpeg', 'gif', 'png']", "5000000", "215", "143"));
if($this->UT_Value->extra[1]!='')
$tExt = $this->UT_Value->extra[1];
else
$tExt ="[]";
if($this->UT_Value->extra[2]!='')
$tSizeLimit = $this->UT_Value->extra[2];
else
$tSizeLimit ="0";
$output .= "" . $this->UT_Value->desc . $additionDesc . " \r\n";
$output .= " ";
$output .= "
";
## upload plugin here
$output .= "
\r\n
\r\n
Please enable JavaScript to use file uploader.
\r\n
\r\n
\r\n
\r\n";
$output .= " \r\n";
$output .= " \r\n";
break;
}
return $output;
}
function searchInputBox($value) {
$output = "";
$output .= " UT_Value->DBField . " id=UT_SCH_" . $this->UT_Value->DBField . " value='" . $value . "' size=20 maxlength=" . $this->UT_Value->len . "> \r\n";
return $output;
}
function searchDate($value) {
$output = "";
$output .= "\r\n";
$output .= "UT_Value->DBField . "_Cond>< = > \r\n";
$output .= " UT_Value->DBField . " value='" . $this->PRI_date($value) . "' size=30 maxlength=" . $this->UT_Value->len . ">\r\n";
$output .= "\r\n";
$output .= " \r\n";
return $output;
}
function searchSelection($value) {
$output = "";
if ($value == "")
$value = $this->UT_Value->default;
switch (true) {
case ($this->UT_Value->option & __UT_TEMPLATE_OPTION_MASTERDETAIL_REF__):
case ($this->UT_Value->option & __UT_TEMPLATE_OPTION_FOREIGNKEY__):
$output .= "\r\n";
$tmpArray = $this->PRI_loadDBValue_selection($value);
break;
case ($this->UT_Value->option & __UT_TEMPLATE_OPTION_FOREIGNKEY__):
$tmpArray = $this->PRI_loadDBValue_selection($value);
break;
default:
$tmpArray = $this->UT_Value->extra;
break;
}
$output .= "\r\n";
$output .= "UT_Value->DBField . " id=" . $this->UT_Value->DBField . ">\r\n";
if ($tmpArray[0] == "")
$output .= " -- " . $this->UT_Value->desc . " -- \r\n";
foreach($tmpArray as $i => $selection) {
/*
if ($i == $value)
$output .= " " . $selection . " \r\n";
else
*/
$output .= " " . $selection . " \r\n";
}
$output .= " \r\n";
$output .= " \r\n";
return $output;
}
function listingSearch() {
$Output = "";
if ($this->UT_Value->listType & __UT_TEMPLATE_LISTTYPE_SEARCH__) {
if (is_array($this->UT_Value->desc)) {
$Output .= "" . $this->UT_Value->desc[0] . " : \r\n";
}else{
$Output .= "" . $this->UT_Value->desc . " : \r\n";
}
$value = $_GET["UT_SCH_" . $this->UT_Value->DBField];
switch (true) {
case ($this->UT_Value->editType & __UT_TEMPLATE_EDITTYPE_INPUTBOX__):
case ($this->UT_Value->editType & __UT_TEMPLATE_EDITTYPE_TEXTBOX__):
$Output .= $this->searchInputBox($value);
break;
case ($this->UT_Value->editType & __UT_TEMPLATE_EDITTYPE_DATETIME__):
$Output .= $this->searchDate($value);
break;
case ($this->UT_Value->editType & __UT_TEMPLATE_EDITTYPE_DATESTR__):
list($date, $time) = preg_split(' ', $value);
switch ($this->UT_Value->extra) {
case "DT":
break;
case "D":
$value = $date;
break;
case "T":
$value = $time;
break;
}
$Output .= $this->listInputBox($value);
break;
case ($this->UT_Value->editType & __UT_TEMPLATE_EDITTYPE_SELECTION__):
case ($this->UT_Value->editType & __UT_TEMPLATE_EDITTYPE_CHECKBOX__):
case ($this->UT_Value->editType & __UT_TEMPLATE_EDITTYPE_RADIO__):
$Output .= $this->searchSelection($value);
break;
}
}
return $Output;
}
// *******************************************************************
// * Searching
// *******************************************************************
function listSearchValue() {
$Output = "";
if (($this->UT_Value->listType & __UT_TEMPLATE_LISTTYPE_SEARCH__) &&
($_GET["UT_SCH_" . $this->UT_Value->DBField] != "")) {
switch (true) {
case ($this->UT_Value->editType & __UT_TEMPLATE_EDITTYPE_INPUTBOX__):
case ($this->UT_Value->editType & __UT_TEMPLATE_EDITTYPE_TEXTBOX__):
if ($this->UT_Value->option & __UT_TEMPLATE_OPTION_PRIMARYKEY__)
$Output .= $this->UT_Value->DBField . "=" . $_GET["UT_SCH_" . $this->UT_Value->DBField];
else
$Output .= $this->UT_Value->DBField . " like '%" . $_GET["UT_SCH_" . $this->UT_Value->DBField] . "%'";
break;
case ($this->UT_Value->editType & __UT_TEMPLATE_EDITTYPE_DATETIME__):
if ($_GET["UT_SCH_" . $this->UT_Value->DBField] != "")
$Output .= $this->UT_Value->DBField . " like '%" . $_GET["UT_SCH_" . $this->UT_Value->DBField] . "%'";
break;
case ($this->UT_Value->editType & __UT_TEMPLATE_EDITTYPE_DATESTR__):
list($date, $time) = preg_split(' ', $value);
switch ($this->UT_Value->extra) {
case "DT":
break;
case "D":
$value = $date;
break;
case "T":
$value = $time;
break;
}
$Output .= $this->listInputBox($value);
break;
case ($this->UT_Value->editType & __UT_TEMPLATE_EDITTYPE_SELECTION__):
if ($this->UT_Value->editType & __UT_TEMPLATE_OPTION_FOREIGNKEY__) {
if ($_GET["UT_SCH_" . $this->UT_Value->DBField] != 0) {
$Output .= $this->UT_Value->DBField . " = '" . $_GET["UT_SCH_" . $this->UT_Value->DBField] . "'";
}
}
else {
$Output .= $this->UT_Value->DBField . " = '" . $_GET["UT_SCH_" . $this->UT_Value->DBField] . "'";
}
break;
case ($this->UT_Value->editType & __UT_TEMPLATE_EDITTYPE_CHECKBOX__):
case ($this->UT_Value->editType & __UT_TEMPLATE_EDITTYPE_RADIO__):
break;
}
}
return $Output;
}
// *******************************************************************
// * Listing
// *******************************************************************
//chiu add
function addDiv($element, $div_id){
$tmp = "".$element."
";
return $tmp;
}
function listInputBox($value, $div_id="") {
if($div_id!="")
return ("" . $this->addDiv($value, $div_id) . " \r\n");
else
return ("" . $value . " \r\n");
}
function listTextBox($value, $div_id="") {
$value = substr($value, 0, $this->UT_Value->len);
if($div_id!="")
return ("" . $this->addDiv($value, $div_id) . " \r\n");
else
return ("" . $value . " \r\n");
}
function listDate($value, $div_id="") {
$value = $this->PRI_date($value);
if($div_id!="")
return ("" . $this->addDiv($value, $div_id) . " \r\n");
else
return ("" . $value . " \r\n");
}
function listSelection($value, $div_id="") {
switch (true) {
case ($this->UT_Value->option & __UT_TEMPLATE_OPTION_FOREIGNKEY__):
$db = new DB;
if (is_array($this->UT_Value->extra->value)) {
$i = 0;
foreach($this->UT_Value->extra->value as $index => $dbValue) {
if ($i++ == 0)
$sqlValue = "concat(" . $dbValue;
else
$sqlValue .= ", ' ', " . $dbValue;
}
$sqlValue .= ") as UT_SELECTION_VALUE";
}
else {
$sqlValue = $this->UT_Value->extra->value . " as UT_SELECTION_VALUE";
}
$tmpValue = "";
$sqlstr = "select " . $sqlValue . " from " . $this->UT_Value->extra->table . " where " . $this->UT_Value->extra->key . "='" . htmlspecialchars($value, ENT_QUOTES) . "'";
$db->query($sqlstr);
while ($db->next_record()) {
// if ($tmpValue == "")
$tmpValue .= $db->f("UT_SELECTION_VALUE");
// else
// $tmpValue .= ", " . $db->f("UT_SELECTION_VALUE");
}
if (($this->UT_Value->option & __UT_TEMPLATE_OPTION_LINK__) && ($this->UT_Value->extra->clickButton != "")) {
$tmpStyle = "style a:link='color: orange'";
$tmpValue = "" . $tmpValue . " ";
}
if($div_id!="")
return ("" . $this->addDiv($tmpValue, $div_id) . " \r\n");
else
return ("" . $tmpValue . " \r\n");
break;
case ($this->UT_Value->option & __UT_TEMPLATE_OPTION_RELOAD__):
default:
$selection = $this->UT_Value->extra[$value];
while(is_array($selection)) {
$selection = $selection[0];
}
if($div_id!="")
return ("" . $this->addDiv($selection, $div_id) . " \r\n");
else
return ("" . $selection . " \r\n");
}
}
function listFile($value, $div_id="") {
if($value){
$path_parts = pathinfo($value);
$tImg = $this->fileImage($path_parts['extension']);
}
if ($value && file_exists($this->UT_Value->extra[0] . "thumbs/" . $value) && ( $this->UT_Value->option & __UT_TEMPLATE_OPTION_IMG__ ) ){
return ("".$tImg." \r\n");
}else if ($value && file_exists($this->UT_Value->extra[0] . $value) && ( $this->UT_Value->option & __UT_TEMPLATE_OPTION_IMG__ ) ){
return ("".$tImg." \r\n");
}
if ($value && file_exists($this->UT_Value->extra[0] . $value)){
return ("".$tImg." \r\n");
}else
return (" \r\n");
}
// __UT_TEMPLATE_EDITTYPE_BUTTON__
function listButton($value, $div_id="") {
$retVal = "";
if ($value) {
if ($this->UT_Value->desc != "")
$tmpDesc = $this->UT_Value->default;
else
$tmpDesc = "Click";
switch($value[1]) {
case __UT_MODE_NEW__:
$retVal = " ";
break;
case __UT_MODE_VIEW__:
$retVal = " ";
break;
}
} else {
$retVal = " \r\n";
}
return ($retVal);
}
function listingHeader($sort, $listFile, $adminpath, $page, $order, $direction=false) {
$Output = "";
$neworder = __UT_TEMPLATE_DIRECTION_DESCENDING__;// -1
if ($order == '')
$UT_ORDER = __UT_TEMPLATE_DIRECTION_DESCENDING__;//-1
if ($this->UT_Value->listType & __UT_TEMPLATE_LISTTYPE_SHOW__) {
if ($direction) {
if ($order == __UT_TEMPLATE_DIRECTION_DESCENDING__) {
$neworder = __UT_TEMPLATE_DIRECTION_ASCENDING__;
$tmp = " ";
}
else {
$tmp .= " ";
}
}
$otheInput = "";
foreach($_GET as $i => $value) {
if (($i != "UT_SORT") && ($i != "UT_PAGE") && ($i != "UT_ORDER"))
$otheInput .= "&" . $i . "=" . $value;
}
if(is_array($this->UT_Value->desc)){// list and edit different display
$Output = "" . $this->UT_Value->desc[0];
}else{
$Output = " " . $this->UT_Value->desc;
}
$Output .= $tmp . " \r\n";
}
return $Output;
}
function listingValue($value, $div_id="") {
$ret = "";
if (is_array($this->UT_Value->default))
$value = sprintf($this->UT_Value->default[1], $value);
if ($this->UT_Value->listType & __UT_TEMPLATE_LISTTYPE_SHOW__) {
switch (true) {
case ($this->UT_Value->editType & __UT_TEMPLATE_EDITTYPE_INPUTBOX__):
$ret = $this->listInputBox($value, $div_id);
break;
case ($this->UT_Value->editType & __UT_TEMPLATE_EDITTYPE_TEXTBOX__):
$ret = $this->listTextBox($value, $div_id);
break;
case ($this->UT_Value->editType & __UT_TEMPLATE_EDITTYPE_DATETIME__):
$ret = $this->listDate($value, $div_id);
break;
case ($this->UT_Value->editType & __UT_TEMPLATE_EDITTYPE_DATESTR__):
list($date, $time) = explode(' ', $value);
switch ($this->UT_Value->extra) {
case "DT":
break;
case "D":
$value = $date;
break;
case "T":
$value = $time;
break;
}
$ret = $this->listInputBox($value, $div_id);
break;
case ($this->UT_Value->editType & __UT_TEMPLATE_EDITTYPE_SELECTION__):
case ($this->UT_Value->editType & __UT_TEMPLATE_EDITTYPE_CHECKBOX__):
case ($this->UT_Value->editType & __UT_TEMPLATE_EDITTYPE_RADIO__):
$ret = $this->listSelection($value, $div_id);
break;
case ($this->UT_Value->editType & __UT_TEMPLATE_EDITTYPE_FILE__):
$ret = $this->listFile($value, $div_id);
break;
case ($this->UT_Value->editType & __UT_TEMPLATE_EDITTYPE_BUTTON__):
$ret = $this->listButton($value, $div_id);
break;
}
}
return ($ret);
}
// *******************************************************************
// * saveDBValue
// *******************************************************************
function saveDBValue($value) {
//$value = addslashes($value);
global $id;
$output = "";
switch (true) {
case ($this->UT_Value->editType & __UT_TEMPLATE_EDITTYPE_INPUTBOX__):
$output = "'" . str_replace("'", "\'", $value) . "'";// if here addslashes,
// $output = "'" . $value . "'";
break;
case ($this->UT_Value->editType & __UT_TEMPLATE_EDITTYPE_TEXTBOX__):
$output = "'" . $value . "'";
// $output = "'" . str_replace("'", "\'", $value) . "'";// if here addslashes,
// " and ' will add addslashes,will display error
break;
case ($this->UT_Value->editType & __UT_TEMPLATE_EDITTYPE_PASSWORD__):
if ($this->UT_Value->option & __UT_TEMPLATE_OPTION_MD5_PASSWORD__) {
if ($_REQUEST[$this->UT_Value->DBField . "_MD5_Changed"] == 1)
$output = "'" . md5($value) . "'";
else
$output = "'" . md5($value) . "'";
}
else
$output = "'" . $value . "'";
break;
case ($this->UT_Value->editType & __UT_TEMPLATE_EDITTYPE_DATESTR__):
$output = "'" . str_replace("/", "-", $value) . "'" ;
break;
case ($this->UT_Value->editType & __UT_TEMPLATE_EDITTYPE_DATETIME__):
if ($value != "") {
switch (true) {
case ($this->UT_Value->option & __UT_TEMPLATE_OPTION_HIDDEN__):
case ($this->UT_Value->option & __UT_TEMPLATE_OPTION_READONLY__):
$output = $this->PRI_mktime($value);
break;
default:
$output = $this->PRI_mktime($value);
break;
}
}
else
$output = 0;
break;
case ($this->UT_Value->editType & __UT_TEMPLATE_EDITTYPE_SELECTION__):
case ($this->UT_Value->editType & __UT_TEMPLATE_EDITTYPE_CHECKBOX__):
case ($this->UT_Value->editType & __UT_TEMPLATE_EDITTYPE_RADIO__):
$output = "'" . $value . "'";
break;
case ($this->UT_Value->editType & __UT_TEMPLATE_EDITTYPE_FILE__):
$output = "'" . $value . "'";
break;
}
return $output;
}
function set_var($field, $desc, $width, $len, $default, $listType, $editType, $optType="", $extra="", $cond="") {
$this->UT_Value->DBField = $field;
$this->UT_Value->desc = $desc;
$this->UT_Value->width = $width;
$this->UT_Value->len = $len;
$this->UT_Value->default = $default;
$this->UT_Value->listType = $listType;
$this->UT_Value->editType = $editType;
$this->UT_Value->option = $optType;
$this->UT_Value->extra = $extra;
$this->UT_Value->cond = $cond;
}
function UT_Template() {
$UT_Value = UT_FieldStruct;
}
}
}// end if
?>