| Server IP : 195.130.67.5 / Your IP : 216.73.217.154 Web Server : Microsoft-IIS/10.0 System : Windows NT WEBSERVER1 10.0 build 17763 (Windows Server 2016) i586 User : IUSR ( 0) PHP Version : 7.4.19 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /inetpub/wwwroot/icd/msc/sources/ |
Upload File : |
<?php
ini_set("display_errors", "1");
ini_set("display_startup_errors", "1");
error_reporting(E_ALL);
class FormSpacer{
const tpEmpty = 0;
const tpHeader = 1;
const tpComment = 2;
const tpRow = 3;
public $Title;
public $Type;
//Row Specific
public $leftCol = NULL;
public $rightCol = NULL;
function __construct($p_title, $p_type = 0) {
$this->Title = $p_title;
$this->Type = $p_type;
}
public function render($controller){
Utils::prline("<tr>");
$title = $this->Title;
$controller->replaceStrings($title);
switch ($this->Type) {
case FormSpacer::tpEmpty:
Utils::prline("<td colspan=\"2\" style=\"font-style: italic; font-size: 1.0em; padding: 10px 0px 0px 5px\"> </td>");
break;
case FormSpacer::tpHeader:
Utils::prline("<td colspan=\"2\" style=\"font-weight: bold; font-size: 1.15em; padding: 10px 0px 0px 5px\">{$title}</td>");
break;
case FormSpacer::tpComment:
Utils::prline("<td colspan=\"2\" style=\"font-style: italic; font-size: 1.0em; padding: 10px 0px 0px 5px\">{$title}</td>");
break;
case FormSpacer::tpRow:
Utils::prline("<td>{$this->leftCol}</td><td>{$this->rightCol}</td>");
break;
default:
break;
}
Utils::prline("</tr>");
}
}
class FormField{
const ftString = 1;
const ftTelephone = 2;
const ftEmail = 3;
const ftText = 4;
const ftDate = 5;
const ftDateTime = 6;
const ftCombo = 7;
const ftCheckbox = 8;
const ftPassword = 9;
const ieMinLength = 1;
const ieMaxLength = 2;
public $isKey = FALSE;
public $isHidden = FALSE;
public $readOnly = FALSE;
public $Name;
public $Type;
public $Value;
public $DefaultValue;
public $ruleMinLength;
public $ruleMaxLength;
public $IsValid;
public $InvalidError;
//Text Specific
public $textNumOfRows;
public $renderWidth = 390;
//Date Specific
public $MonthsList;
public $YearFrom;
public $YearTo;
//Combo Specific
public $comboSQL;
public $comboValues;
public $comboLabels;
//Password Specific
public $usernameField;
function __construct($fieldName, $fieldType) {
$this->Name = $fieldName;
$this->Type = $fieldType;
$this->IsValid = TRUE;
$this->InvalidError = NULL;
$this->ruleMinLength = 0;
$this->ruleMaxLength = -1;
}
public function getSQLCreateField(){
$s = "";
switch ($this->Type) {
case FormField::ftDate:
$s = "`{$this->Name}` date NOT NULL";
break;
case FormField::ftDateTime:
$s = "`{$this->Name}` datetime NOT NULL";
break;
case FormField::ftCheckbox:
$s = "`{$this->Name}` int NOT NULL";
break;
case FormField::ftText:
$s = "`{$this->Name}` text NOT NULL";
break;
default:
$s = "`{$this->Name}` varchar({$this->ruleMaxLength}) NOT NULL";
break;
}
return $s;
}
public function getLabel($controller = NULL){
$label = $this->Name;
if ($controller != NULL){
$Name_uc = strtoupper($this->Name);
$label = "@[LBL_{$Name_uc}]";
$controller->replaceStrings($label);
}
return $label;
}
public function renderTable($controller = NULL, $autoFocus = FALSE){
$Name_uc = strtoupper($this->Name);
$label = $this->Name;
if ($controller != NULL){
$label = "@[LBL_{$Name_uc}]";
$controller->replaceStrings($label);
}
Utils::prline("<tr>");
Utils::prline("<td class=\"tdL\">{$label}:</td>");
Utils::prline("<td class=\"tdR\">");
if ($this->Value == NULL && $this->DefaultValue != NULL){
$this->Value = $this->DefaultValue;
}
$dispValue = $this->Value;
switch ($this->Type) {
case FormField::ftPassword:
$dispValue = "******";
break;
case FormField::ftEmail:
$dispValue = "<a href=\"mailto:{$this->Value}\">{$this->Value}</a>";
break;
case FormField::ftDate:
$dispValue = Utils::dateStr($this->getUnixTime(), 1);
break;
case FormField::ftDateTime:
$dispValue = Utils::dateStr($this->getUnixTime(), 5);
break;
case FormField::ftCombo:
$values = array();
$labels = array();
if ($this->comboSQL){
}else{
$values = $this->comboValues;
$labels = $this->comboLabels;
}
$N = count($values);
for ($i=0; $i < $N; $i++) {
$curval = $values[$i];
$curlbl = $labels[$i];
$controller->replaceStrings($curlbl);
if ($curval == $this->Value){
$dispValue = $curlbl;
}
}
break;
case FormField::ftCheckbox:
$dispValue = ($this->Value != 0)? "yes" : "no";
break;
default:
$dispValue = $this->Value;
break;
}
Utils::prline("{$dispValue}");
//var_dump($this->Value);
/*
if (!$this->IsValid) {
echo " <span style=\"color: #DF4000\">*</span>";
}elseif ($this->ruleMinLength > 0) {
echo " <span style=\"color: #000000\">*</span>";
}
* */
Utils::prline("</td>");
Utils::prline("</tr>");
}
public function render($controller = NULL, $autoFocus = FALSE){
$Name_uc = strtoupper($this->Name);
$label = $this->Name;
if ($controller != NULL){
$label = "@[LBL_{$Name_uc}]";
$controller->replaceStrings($label);
}
Utils::prline("<tr>");
Utils::prline("<td class=\"tdL\">{$label}:</td>");
Utils::prline("<td class=\"tdR\">");
if ($this->Value == NULL && $this->DefaultValue != NULL){
$this->Value = $this->DefaultValue;
}
$af = ($autoFocus)? " autofocus=\"autofocus\"" : "";
$ro = ($this->readOnly)? " readonly=\"readonly\"" : "";
$escapedValue = ($this->Value) ? str_replace("\"", """, $this->Value) : "";
switch ($this->Type) {
case FormField::ftString:
Utils::prline("<input type=\"text\" {$ro} name=\"{$this->Name}\" value=\"{$escapedValue}\" style=\"width: {$this->renderWidth}px\" {$af}/>");
break;
case FormField::ftPassword:
Utils::prline("<input type=\"password\" {$ro} name=\"{$this->Name}\" value=\"{$escapedValue}\" style=\"width: {$this->renderWidth}px\" {$af}/>");
break;
case FormField::ftTelephone:
Utils::prline("<input type=\"text\" {$ro} name=\"{$this->Name}\" value=\"{$escapedValue}\" style=\"width: {$this->renderWidth}px\" {$af}/>");
break;
case FormField::ftEmail:
Utils::prline("<input type=\"text\" {$ro} name=\"{$this->Name}\" value=\"{$escapedValue}\" style=\"width: {$this->renderWidth}px\" {$af}/>");
break;
case FormField::ftText:
Utils::prline("<textarea name=\"{$this->Name}\" {$ro} style=\"width: {$this->renderWidth}px\" rows=\"{$this->textNumOfRows}\" {$af}>{$this->Value}</textarea>");
break;
case FormField::ftDate:
//var_dump($this->Value);
$isovalue = $this->getISODate();
Utils::prline("<input type=\"hidden\" name=\"{$this->Name}\" value=\"{$isovalue}\" />");
$selectedDay = Utils::arrayElem($this->Value, "d");
Utils::prline("<select name=\"{$this->Name}_d\" {$ro}>");
for ($i=1; $i <= 31; $i++) {
$selected = ($i == $selectedDay)? " selected=\"selected\"" : "";
Utils::prline("<option value=\"{$i}\"{$selected}>{$i}</option>");
}
Utils::prline("</select>");
$selectedMonth = Utils::arrayElem($this->Value, "m");
Utils::prline("<select name=\"{$this->Name}_m\" {$ro}>");
for ($i=1; $i <= 12; $i++) {
$selected = ($i == $selectedMonth)? " selected=\"selected\"" : "";
$monthName = ($this->MonthsList == NULL)? $i : $this->MonthsList[$i-1];
Utils::prline("<option value=\"{$i}\"{$selected}>{$monthName}</option>");
}
Utils::prline("</select>");
$selectedYear = Utils::arrayElem($this->Value, "y");
Utils::prline("<select name=\"{$this->Name}_y\" {$ro}>");
//YearFrom
for ($i=$this->YearFrom; $i <= $this->YearTo; $i++) {
$selected = ($i == $selectedYear)? " selected=\"selected\"" : "";
Utils::prline("<option value=\"{$i}\"{$selected}>{$i}</option>");
}
Utils::prline("</select>");
break;
case FormField::ftCombo:
Utils::prline("<select name=\"{$this->Name}\" {$af} {$ro}>");
$values = array();
$labels = array();
if ($this->comboSQL){
}else{
$values = $this->comboValues;
$labels = $this->comboLabels;
}
$N = count($values);
for ($i=0; $i < $N; $i++) {
$curval = $values[$i];
$curlbl = $labels[$i];
$controller->replaceStrings($curlbl);
$selected = ($curval == $this->Value)? " selected=\"selected\"" : "";
Utils::prline("<option value=\"{$curval}\"{$selected}>{$curlbl}</option>");
}
Utils::prline("</select>");
break;
case FormField::ftCheckbox:
$checked = ($this->Value != 0)? " checked=\"checked\"" : "";
Utils::prline("<input type=\"checkbox\" name=\"{$this->Name}\" {$ro} value=\"1\"{$checked} style=\"width: {$this->renderWidth}px\" {$af}/>");
break;
default:
Utils::prline("??? undefined field type for '{$this->Name}'");
break;
}
if (!$this->IsValid) {
echo " <span style=\"color: #DF4000\">*</span>";
}elseif ($this->ruleMinLength > 0) {
echo " <span style=\"color: #000000\">*</span>";
}
Utils::prline("</td>");
Utils::prline("</tr>");
}
public function getUnixTime(){
$isodate = $this->getISODate();
return strtotime($isodate);
}
public function getISODate(){
$ret = "";
if ($this->Type == FormField::ftDate){
$ret = Utils::arrayElem($this->Value, "y") . "-" . Utils::arrayElem($this->Value, "m") . "-" . Utils::arrayElem($this->Value, "d");
}
if ($this->Type == FormField::ftDateTime){
$ret = Utils::arrayElem($this->Value, "h") . ":" . Utils::arrayElem($this->Value, "n");
}
return $ret;
}
public function getSQLValue(){
$curValue = "";
$delim = "";
switch ($this->Type) {
case FormField::ftString:
case FormField::ftTelephone:
case FormField::ftEmail:
case FormField::ftText:
case FormField::ftCombo:
$delim = "'";
$curValue = DBUtils::escape_string($this->Value);
break;
case FormField::ftPassword:
if (strlen($this->Value) == 0){
$delim = "`";
$curValue = $this->Name;
}else{
$delim = "'";
$un = $this->usernameField->Value;
$curValue = CryptoUtils::getHashWithSalt($this->Value, $un);
}
break;
case FormField::ftDate:
case FormField::ftDateTime:
$delim = "'";
$curValue = $this->getISODate();
break;
case FormField::ftCheckbox:
$curValue = $this->Value;
break;
default:
break;
}
$ret = "{$delim}{$curValue}{$delim}";
return $ret;
}
public function IsPasswrdNotBlank(){
$ret = TRUE;
if ($this->Type == FormField::ftPassword){
$ret = (strlen($this->Value) > 0);
}
return $ret;
}
}
class FormFieldsSet{
public $tableName;
public $fieldsArray;
public $fieldsHash;
public $spacesHash;
public $groupsHash;
public $invalidsArray;
public $invalidsHash;
public $numOfInvalid;
public $MonthsList;
function __construct($tbl = NULL) {
$this->tableName = $tbl;
$this->spacesHash = array();
$this->groupsHash = array();
$this->fieldsArray = array();
$this->fieldsHash = array();
$this->invalidsArray = array();
$this->invalidsHash = array();
$this->numOfInvalid = 0;
$this->MonthsList = NULL;
}
public function loadFromSession($prefix = NULL){
foreach ($this->fieldsHash as $fname => $fld) {
$sesskey = $fname;
if (strlen($prefix) > 0) $sesskey = $prefix . "_" . $sesskey;
if (key_exists($sesskey, $_SESSION)){
$fld->Value = $_SESSION[$sesskey];
}else{
}
}
}
public function saveToSession($prefix = NULL){
foreach ($this->fieldsHash as $fname => $fld) {
$sesskey = $fname;
if (strlen($prefix) > 0) $sesskey = $prefix . "_" . $sesskey;
$_SESSION[$sesskey] = $fld->Value;
}
}
public function clearSession($prefix = NULL){
foreach ($this->fieldsHash as $fname => $fld) {
$sesskey = $fname;
if (strlen($prefix) > 0) $sesskey = $prefix . "_" . $sesskey;
$_SESSION[$sesskey] = $fld->DefaultValue;
}
}
public function getNumOfFields(){
return count($this->fieldsArray);
}
public function addRow($leftCol, $rightCol, $key = NULL){
$newspacer = new FormSpacer("", FormSpacer::tpRow);
$newspacer->leftCol = $leftCol;
$newspacer->rightCol = $rightCol;
if ($key === NULL) $key = $this->getNumOfFields();
if (key_exists($key, $this->spacesHash)){
$this->spacesHash[$key][] = $newspacer;
}else{
$this->spacesHash[$key] = array($newspacer);
}
}
public function addSpacer($type, $title = " ", $key = NULL){
$newspacer = new FormSpacer($title, $type);
if ($key === NULL) $key = $this->getNumOfFields();
if (key_exists($key, $this->spacesHash)){
$this->spacesHash[$key][] = $newspacer;
}else{
$this->spacesHash[$key] = array($newspacer);
}
}
function addNewField($fieldName, $fieldType){
$fld = new FormField($fieldName, $fieldType);
$this->fieldsArray[] = $fld;
$this->fieldsHash[$fieldName] = $fld;
return $fld;
}
public function addString($fieldName, $maxSize = 200){
$fld = $this->addNewField($fieldName, FormField::ftString);
$fld->ruleMaxLength = $maxSize;
return $fld;
}
public function addPassword($fieldName, $maxSize = 200){
$fld = $this->addNewField($fieldName, FormField::ftPassword);
$fld->ruleMaxLength = $maxSize;
return $fld;
}
public function addTelephone($fieldName, $maxSize = 200){
$fld = $this->addNewField($fieldName, FormField::ftTelephone);
$fld->ruleMaxLength = $maxSize;
return $fld;
}
public function addEmail($fieldName, $maxSize = 200){
$fld = $this->addNewField($fieldName, FormField::ftEmail);
$fld->ruleMaxLength = $maxSize;
return $fld;
}
public function addText($fieldName, $numOfRows = 10){
$fld = $this->addNewField($fieldName, FormField::ftText);
$fld->textNumOfRows = $numOfRows;
return $fld;
}
public function addDate($fieldName, $fromyear = NULL, $toyear = NULL, $defYear = NULL){
$fld = $this->addNewField($fieldName, FormField::ftDate);
$fld->MonthsList = $this->MonthsList;
$gc = getdate();
$thisyear = $gc['year'];
if ($defYear === NULL){
$defYear = $thisyear;
}else{
if ($defYear > 0){
}else{
$defYear = $thisyear + $defYear;
}
}
if ($fromyear !== NULL && $toyear !== NULL){
if ($fromyear < 0){
$fld->YearFrom = $thisyear+$fromyear;
$fld->YearTo = $thisyear+$toyear;
}else{
$fld->YearFrom = $fromyear;
$fld->YearTo = $toyear;
}
}else{
$fld->YearFrom = $thisyear-100;
$fld->YearTo = $thisyear+100;
}
$fld->DefaultValue = array("d" => 1, "m" => 1, "y" => $defYear);
return $fld;
}
public function addDateTime($fieldName){
$fld = $this->addNewField($fieldName, FormField::ftDateTime);
return $fld;
}
public function addComboFromArray($fieldName, $labels, $values = NULL, $maxSize = 200){
$fld = $this->addNewField($fieldName, FormField::ftCombo);
$fld->ruleMaxLength = $maxSize;
$fld->comboLabels = $labels;
$fld->comboValues = ($values == NULL) ? $labels : $values;
return $fld;
}
public function addComboFromSQL($fieldName, $query, $valueField, $labelField, $maxSize = 200){
$fld = $this->addNewField($fieldName, FormField::ftCombo);
$fld->ruleMaxLength = $maxSize;
$list = DBUtils::getObjects($query, $valueField);
$fld->comboLabels = array();
$fld->comboValues = array();
foreach ($list as $key => $value) {
$fld->comboValues[] = $key;
$fld->comboLabels[] = $value->$labelField;
}
return $fld;
//$fld = $this->addNewField($fieldName, FormField::ftCombo);
//return $fld;
}
public function addCheckbox($fieldName){
$fld = $this->addNewField($fieldName, FormField::ftCheckbox);
return $fld;
}
public function printAll(){
foreach ($this->fieldsHash as $fname => $fld) {
Utils::prline("{$fname} [{$fld->Type}] = '{$fld->Value}' v={$fld->IsValid} <br>");
}
Utils::prline("Num of Invalid Fields={$this->numOfInvalid}<br>");
foreach ($this->invalidsHash as $fname => $fld) {
Utils::prline("{$fname}<br>");
}
}
public function insertValuesToDB(){
$query = "INSERT INTO `{$this->tableName}` (";
$query .= $this->getSQLNamesList();
$query .= ") VALUES (";
$query .= $this->getSQLValuesList();
$query .= ")";
//Utils::prline($query);
return DBUtils::execute_query($query);
}
public function updateValuesToDB(){
$query = "UPDATE `{$this->tableName}` SET ";
$count = 0;
foreach ($this->fieldsHash as $fname => $fld) {
if (!$fld->isKey && $fld->IsPasswrdNotBlank()){
if ($count > 0) $query .= ", ";
$query .= "`{$fname}` = " . $fld->getSQLValue();
$count++;
}
}
$query .= " WHERE ";
foreach ($this->fieldsHash as $fname => $fld) {
if ($fld->isKey){
$query .= "`{$fname}` = " . $fld->getSQLValue();
}
}
//Utils::prline($query);
return DBUtils::execute_query($query);
}
public function getValuesFromDB($orderBy = NULL){
$query = "SELECT * FROM `{$this->tableName}` WHERE ";
foreach ($this->fieldsHash as $fname => $fld) {
if ($fld->isKey){
$query .= "`{$fname}` = " . $fld->getSQLValue();
}
}
if ($orderBy != NULL){
$query .= " ORDER BY {$orderBy}";
}
$rows = NULL;
$num = 0;
DBUtils::getrows($query, $rows, $num);
if ($num > 0){
$src = mysqli_fetch_assoc($rows);
foreach ($this->fieldsHash as $fname => $fld) {
if (key_exists($fname, $src)){
switch ($fld->Type) {
case FormField::ftDate:
$da = array();
$d = strtotime($src[$fname]);
$da = getdate($d);
$da['d'] = Utils::arrayElem($da, "mday");
$da['m'] = Utils::arrayElem($da, "mon");
$da['y'] = Utils::arrayElem($da, "year");
$fld->Value = $da;
break;
case FormField::ftDateTime:
$da = array();
$d = strtotime($src[$fname]);
$da = getdate($d);
$da['d'] = Utils::arrayElem($da, "mday");
$da['m'] = Utils::arrayElem($da, "mon");
$da['y'] = Utils::arrayElem($da, "year");
$da['h'] = Utils::arrayElem($src, "hours");
$da['n'] = Utils::arrayElem($src, "minutes");
$da['s'] = Utils::arrayElem($src, "seconds");
$fld->Value = $da;
break;
case FormField::ftPassword:
$fld->Value = "";
break;
case FormField::ftText:
$fld->Value = trim(Utils::arrayElem($src, $fname), " \r\n\0\x0B\t");
break;
case FormField::ftCheckbox:
$fld->Value = Utils::arrayElem($src, $fname, 0);
break;
default:
$fld->Value = Utils::arrayElem($src, $fname);
break;
}
}else{
switch ($fld->Type) {
case FormField::ftCheckbox:
$fld->Value = 0;
break;
default:
$fld->Value = NULL;
break;
}
}
if ($fld->Value == NULL && $fld->DefaultValue != NULL){
$fld->Value = $fld->DefaultValue;
}
}
}
}
public function getValues($fromPost = TRUE){
$src = ($fromPost) ? $_POST : $_GET;
foreach ($this->fieldsHash as $fname => $fld) {
if (key_exists($fname, $src)){
switch ($fld->Type) {
case FormField::ftDate:
$da = array();
$da['d'] = Utils::arrayElem($src, "{$fname}_d");
$da['m'] = Utils::arrayElem($src, "{$fname}_m");
$da['y'] = Utils::arrayElem($src, "{$fname}_y");
$fld->Value = $da;
break;
case FormField::ftDateTime:
$da = array();
$da['d'] = Utils::arrayElem($src, "{$fname}_d");
$da['m'] = Utils::arrayElem($src, "{$fname}_m");
$da['y'] = Utils::arrayElem($src, "{$fname}_y");
$da['h'] = Utils::arrayElem($src, "{$fname}_h");
$da['n'] = Utils::arrayElem($src, "{$fname}_n");
$da['s'] = Utils::arrayElem($src, "{$fname}_s");
$fld->Value = $da;
break;
case FormField::ftText:
$fld->Value = trim(Utils::arrayElem($src, $fname), " \r\n\0\x0B\t");
break;
case FormField::ftCheckbox:
$fld->Value = Utils::arrayElem($src, $fname, 0);
break;
default:
$fld->Value = Utils::arrayElem($src, $fname);
break;
}
}else{
switch ($fld->Type) {
case FormField::ftCheckbox:
$fld->Value = 0;
break;
default:
$fld->Value = NULL;
break;
}
}
if ($fld->Value == NULL && $fld->DefaultValue != NULL){
$fld->Value = $fld->DefaultValue;
}
}
}
public function checkValidity(){
$this->invalidsArray = array();
$this->invalidsHash = array();
$this->numOfInvalid = 0;
foreach ($this->fieldsHash as $fname => $fld) {
//$this->ruleMinLength = 0;
//$this->ruleMaxLength = 1024;
$fld->IsValid = TRUE;
$fld->InvalidError = NULL;
//CHECK MIN/MAX Lengths
if ($fld->Type == FormField::ftString || $fld->Type == FormField::ftPassword || $fld->Type == FormField::ftText || $fld->Type == FormField::ftTelephone || $fld->Type == FormField::ftEmail){
//if ($fld->Type == FormField::ftString || $fld->Type == FormField::ftText || $fld->Type == FormField::ftTelephone || $fld->Type == FormField::ftEmail){
$fldlen = strlen($fld->Value ?? "");
//Utils::prline("{$fld->Name}:{$fldlen}:{$fld->ruleMinLength}:{$fld->ruleMaxLength}<br>");
if ($fld->ruleMinLength > $fldlen) $fld->InvalidError = FormField::ieMinLength;
if ($fld->ruleMaxLength > 0 && $fld->ruleMaxLength < $fldlen) $fld->InvalidError = FormField::ieMaxLength;
$fld->IsValid = ($fld->InvalidError === NULL);
//}
}elseif ($fld->Type == FormField::ftCheckbox){
if ($fld->ruleMinLength > 0){
//var_dump($fld->Value);
$fld->IsValid = ($fld->Value != 0);
}
}
//Check Email Validity
if ($fld->Type == FormField::ftEmail){
$fld->IsValid = $fld->IsValid && Utils::isEmailValid($fld->Value);
}
if (!$fld->IsValid){
$this->numOfInvalid += 1;
$this->invalidsArray[] = $fld;
$this->invalidsHash[$fname] = $fld;
}
}
}
public function isValid($fieldname){
$ret = FALSE;
if (key_exists($fieldname, $this->fieldsHash)){
$ret = $this->fieldsHash[$fieldname]->IsValid;
}
return FALSE;
}
public function renderTable($controller = NULL){
$N = $this->getNumOfFields();
for ($i=0; $i < $N; $i++){
$fld = $this->fieldsArray[$i];
if (key_exists($i, $this->spacesHash)){
$spacers = $this->spacesHash[$i];
foreach ($spacers as $spkey => $spacer) {
$spacer->render($controller);
}
}
if (!$fld->isHidden){
$fld->renderTable($controller, ($i == 0));
}
}
if (key_exists($N, $this->spacesHash)){
$spacers = $this->spacesHash[$N];
foreach ($spacers as $spkey => $spacer) {
$spacer->render($controller);
}
}
}
public function render($controller = NULL){
$N = $this->getNumOfFields();
for ($i=0; $i < $N; $i++){
$fld = $this->fieldsArray[$i];
if (key_exists($i, $this->spacesHash)){
$spacers = $this->spacesHash[$i];
foreach ($spacers as $spkey => $spacer) {
$spacer->render($controller);
}
}
if (!$fld->isHidden){
$fld->render($controller, ($i == 0));
}
}
if (key_exists($N, $this->spacesHash)){
$spacers = $this->spacesHash[$N];
foreach ($spacers as $spkey => $spacer) {
$spacer->render($controller);
}
}
}
public function getSQLNamesList($includeKeys = TRUE){
$N = count($this->fieldsArray);
$s = "";
$count = 0;
for ($i=0; $i < $N; $i++) {
$curfld = $this->fieldsArray[$i];
if (($includeKeys || (!$includeKeys && !$curfld->isKey)) && !$curfld->isHidden){
if ($count >0){
$s .= ", ";
}
$curName = $curfld->Name;
$s .= "`{$curName}`";
$count++;
}
}
return $s;
}
public function getSQLValuesList($includeKeys = TRUE){
$N = count($this->fieldsArray);
$s = "";
$count = 0;
for ($i=0; $i < $N; $i++) {
$curfld = $this->fieldsArray[$i];
if (($includeKeys || (!$includeKeys && !$curfld->isKey)) && !$curfld->isHidden){
if ($count >0){
$s .= ", ";
}
/*
$curValue = "";
$delim = "";
switch ($curfld->Type) {
case FormField::ftString:
case FormField::ftTelephone:
case FormField::ftEmail:
case FormField::ftText:
case FormField::ftCombo:
$delim = "'";
$curValue = DBUtils::escape_string($curfld->Value);
break;
case FormField::ftPassword:
if (strlen($curfld->Value) == 0){
$delim = "`";
$curValue = $curfld->Name;
}else{
$delim = "'";
$curValue = DBUtils::escape_string($curfld->Value);
}
break;
case FormField::ftDate:
case FormField::ftDateTime:
$delim = "'";
$curValue = $curfld->getISODate();
break;
case FormField::ftCheckbox:
$curValue = $curfld->Value;
break;
default:
break;
}
$s .= "{$delim}{$curValue}{$delim}";
*
*/
$s .= $curfld->getSQLValue();
$count++;
}
}
return $s;
}
public function getSQLCreateTable($tableName){
$s = "";
$s .= "CREATE TABLE `{$tableName}` (\n";
$s .= " `Id` bigint(20) NOT NULL AUTO_INCREMENT,\n";
foreach ($this->fieldsHash as $fname => $fld) {
$s .= " " . $fld->getSQLCreateField() . ",\n";
}
$s .= " PRIMARY KEY (`Id`)\n";
$s .= ") ENGINE=InnoDB DEFAULT CHARSET=utf8\n";
return $s;
}
}
?>