From 3ff03dc4f0a72432b34c00da620272cf011e4ddd Mon Sep 17 00:00:00 2001 From: Yuchen Pei Date: Thu, 29 Jul 2021 14:17:20 +1000 Subject: Publishing h-node.org code. - this is the h-node.org code, except - removed a js file (3x copies at three different locations) without license / copyright headers - /Js/linkToForm.js - /Public/Js/linkToForm.js - /admin/Public/Js/linkToForm.js - removed config files containing credentials - /Application/Include/params.php - /Config/Config.php - /admin/Application/Include/params.php - /admin/Config/Config.php - added license and copyright header to one php file - /admin/Library/ErrorReporting.php (almost identical to /Library/ErrorReporting.php which has the headers) --- h-source/Library/Form/Form.php | 120 +++++++---------------------------------- 1 file changed, 18 insertions(+), 102 deletions(-) (limited to 'h-source/Library/Form/Form.php') diff --git a/h-source/Library/Form/Form.php b/h-source/Library/Form/Form.php index 9b05c51..a1a9fda 100755 --- a/h-source/Library/Form/Form.php +++ b/h-source/Library/Form/Form.php @@ -2,7 +2,7 @@ // EasyGiant is a PHP framework for creating and managing dynamic content // -// Copyright (C) 2009 - 2014 Antonio Gallo (info@laboratoriolibero.com) +// Copyright (C) 2009 - 2011 Antonio Gallo // See COPYRIGHT.txt and LICENSE.txt. // // This file is part of EasyGiant @@ -25,15 +25,6 @@ if (!defined('EG')) die('Direct access not allowed!'); //create the HTML of the whole form class Form_Form { - //default attributes of the entries - public static $defaultEntryAttributes = array( - "entryClass" => null, - "className" => null, - "idName" => null, - "submitClass" => "btn btn-primary", - "formWrap" => null, - ); - public $entry = array(); //associative array containing the entries of the form (objects that inherit the class form_entryModel). Each element of the array corresponds to one field of the table public $action = null; //the action of the form @@ -62,9 +53,8 @@ class Form_Form { { throw new Exception("class $entryObjName not defined: the entry $entryName can't be set"); } - $this->entry[$entryName] = new $entryObjName($entryName); - $this->entry[$entryName]->labelString = getFieldLabel($entryName); + $this->entry[$entryName]->labelString = $entryName.':'; //set the type $this->entry[$entryName]->type = $entryType; if (isset($options)) @@ -82,18 +72,17 @@ class Form_Form { $type = array_key_exists('type',$entry) ? $entry['type'] : 'InputText'; $options = array_key_exists('options',$entry) ? $entry['options'] : null; $this->setEntry($name,$type,$options); - - $entryClass = array_key_exists('entryClass',$entry) ? $entry['entryClass'] : self::$defaultEntryAttributes['entryClass']; - $labelString = array_key_exists('labelString',$entry) ? $entry['labelString'] : getFieldLabel($name); - $idName = array_key_exists('idName',$entry) ? $entry['idName'] : self::$defaultEntryAttributes['idName']; - $className = array_key_exists('className',$entry) ? $entry['className'] : self::$defaultEntryAttributes['className']; + + $entryClass = array_key_exists('entryClass',$entry) ? $entry['entryClass'] : null; + $labelString = array_key_exists('labelString',$entry) ? $entry['labelString'] : "$name:"; + $idName = array_key_exists('idName',$entry) ? $entry['idName'] : null; + $className = array_key_exists('className',$entry) ? $entry['className'] : null; $labelClass = array_key_exists('labelClass',$entry) ? $entry['labelClass'] : null; $defaultValue = array_key_exists('defaultValue',$entry) ? $entry['defaultValue'] : null; $wrap = array_key_exists('wrap',$entry) ? $entry['wrap'] : array(); $deleteButton = array_key_exists('deleteButton',$entry) ? $entry['deleteButton'] : null; $reverse = array_key_exists('reverse',$entry) ? $entry['reverse'] : null; - $attributes = array_key_exists('attributes',$entry) ? $entry['attributes'] : null; - + $this->entry[$name]->entryClass = $entryClass; $this->entry[$name]->labelString = $labelString; $this->entry[$name]->idName = $idName; @@ -103,13 +92,12 @@ class Form_Form { $this->entry[$name]->wrap = $wrap; $this->entry[$name]->deleteButton = $deleteButton; $this->entry[$name]->reverse = $reverse; - $this->entry[$name]->attributes = $attributes; } } //function to create the HTML of the form //$values: an associative array ('entryName'=>'value') - //$subset: subset to print (comma seprated list of string or array) + //$subset: subset to print public function render($values = null, $subset = null) { @@ -125,99 +113,27 @@ class Form_Form { $fid = isset($this->id) ? "id='".$this->id."'" : null; $fname = isset($this->name) ? "name='".$this->name."'" : null; $fclass = isset($this->className) ? "class='".$this->className."'" : null; - $fenctype = isset($this->enctype) ? " enctype='".$this->enctype."' " : null; + $fenctype = isset($this->enctype) ? " enctype=".$this->enctype." " : null; $htmlForm = "
\n"; - if (!isset($subset)) - { - $subset = array_keys($values); - } - else - { - $subset = !is_array($subset) ? explode(',',$subset) : $subset; - } -// $subset = (isset($subset)) ? explode(',',$subset) : array_keys($values); - - //first cicle: write the HTML of tabs if there are any - $tabsHtml = null; - $fCount = 0; - foreach ($subset as $key => $entry) - { - if (is_array($entry)) - { - $currClass = $fCount === 0 ? "current_tab" : null; - $cleanKey = encode($key); - $tabsHtml .= "\t
  • $key
  • \n"; - $fCount++; - } - } - if (isset($tabsHtml)) - { - $htmlForm .= "\n"; - } + $subset = (isset($subset)) ? explode(',',$subset) : array_keys($values); - $fCount = 0; - foreach ($subset as $k => $entry) + foreach ($subset as $entry) { - - $cleanK = encode($k); - if (!is_array($entry)) - { - if (array_key_exists($entry,$this->entry)) - { - $value = array_key_exists($entry,$values) ? $values[$entry] : $this->entry[$entry]->defaultValue; - $htmlForm .= $this->entry[$entry]->render($value); - } - } - else + + if (array_key_exists($entry,$this->entry)) { - $tHtml = null; - $displClass = $fCount === 0 ? null : "display_none"; - foreach ($entry as $e) - { - if (array_key_exists($e,$this->entry)) - { - $value = array_key_exists($e,$values) ? $values[$e] : $this->entry[$e]->defaultValue; - $tHtml .= $this->entry[$e]->render($value); - } - } - $htmlForm .= "
    $tHtml
    "; - $fCount++; + $value = array_key_exists($entry,$values) ? $values[$entry] : $this->entry[$entry]->defaultValue; + $htmlForm .= $this->entry[$entry]->render($value); } + } - $htmlForm .= "
    "; foreach ($this->submit as $name => $value) { - if (!is_array($value)) - { - $submitClass= ""; - if (!is_array(self::$defaultEntryAttributes['submitClass'])) - { - $submitClass = self::$defaultEntryAttributes['submitClass']; - } - else - { - if (array_key_exists($value,self::$defaultEntryAttributes['submitClass'])) - { - $submitClass = self::$defaultEntryAttributes['submitClass'][$value]; - } - } - $htmlForm .= "".Html_Form::submit($name, $value, $submitClass, $name).""; - } - else - { - array_unshift($value,$name); - $htmlForm .= call_user_func_array(array("Html_Form","submit"),$value); - } + $htmlForm .= "
    \n\n
    \n"; } - $htmlForm .= "
    "; $htmlForm .= "
    \n"; - - if (isset(self::$defaultEntryAttributes["formWrap"]) and is_array(self::$defaultEntryAttributes["formWrap"]) and count(self::$defaultEntryAttributes["formWrap"]) === 2) - { - return self::$defaultEntryAttributes["formWrap"][0] . $htmlForm . self::$defaultEntryAttributes["formWrap"][1]; - } return $htmlForm; } -- cgit v1.2.3