00001 <?php
00002
00006 class FormInput
00007 {
00010 protected $inputType;
00011
00014 protected $label;
00015
00018 protected $ref;
00019
00022 protected $validType;
00023
00026 protected $required;
00027
00030 protected $value;
00031
00034 protected $items;
00035
00038 protected $appearance;
00039
00042 protected $description;
00043
00044
00058 function __construct($inputType, $label, $ref="", $validType="", $required="",
00059 $value="", $items="", $appearance="", $description="") {
00060 $this->inputType = $inputType;
00061 $this->label = $label;
00062 $this->ref = $ref;
00063 $this->validType = $validType;
00064 $this->required = $required;
00065 $this->value = $value;
00066 $this->items = $items;
00067 $this->appearance = $appearance;
00068 $this->description = $description;
00069 }
00070
00071
00076 public function buildInstance() {
00077 if ($this->inputType == "text") {
00078 return "";
00079 }
00080 if ($this->required == true)
00081 $requiredString = "true";
00082 else
00083 $requiredString = "false";
00084 $string = '';
00085 $openTag = " <$this->ref type='$this->validType' required='$requiredString()'";
00086
00087
00088 if ($this->value == "") {
00089 $string.="$openTag />\n";
00090 }
00091
00092 else if (is_array($this->value) && count($this->value) > 0) {
00093 $string = '';
00094 $first = true;
00095 foreach($this->value as $value) {
00096 $value = SXMLHelper::contentToXML($value);
00097
00098 if ($first) {
00099 $string .= "$openTag>$value</$this->ref>\n";
00100 $first = false;
00101 }
00102 else
00103 $string.=" <$this->ref>$value</$this->ref>\n";
00104 }
00105 }
00106
00107 else {
00108
00109 $value = SXMLHelper::contentToXML($this->value);
00110 $string.="$openTag>$value</$this->ref>\n";
00111 }
00112
00113 return $string;
00114 }
00115
00116
00121 public function buildInput() {
00122 $description = SXMLHelper::contentToXML($this->description);
00123 $label = SXMLHelper::contentToXML($this->label);
00124
00125
00126 if ($this->inputType == "text") {
00127 $string = "<text>\n".
00128 " <label>$label</label>\n";
00129 if($this->description != "") {
00130 $string .= " <description>$description</description>\n";
00131 }
00132 $string .= "</text>\n";
00133 return $string;
00134 }
00135
00136
00137 $string="<$this->inputType ref=\"$this->ref\"";
00138 if ($this->appearance != "")
00139 $string.=" appearance=\"$this->appearance\"";
00140 $string.=">\n".
00141 " <label>$label</label>\n";
00142 if($this->description != "") {
00143 $string.=" <description>$description</description>\n";
00144 }
00145
00146
00147
00148
00149
00150
00151 if ( ($this->inputType=="select" || $this->inputType=="select1") && is_array($this->items)) {
00152 $isAssociative = (array_keys($this->items) != array_keys(array_keys($this->items)));
00153 foreach($this->items as $key=>$item)
00154 {
00155
00156 if (!is_array($item)) {
00157
00158 if ($isAssociative)
00159 $item = array($item, $key);
00160
00161 else
00162 $item = array($item, $item);
00163 }
00164 $string.=" <item>\n".
00165 " <label>".str_replace("&", "&", $item[0])."</label>\n".
00166 " <value>".str_replace("&", "&", $item[1])."</value>\n".
00167 " </item>\n";
00168 }
00169 }
00170
00171 $string.="</$this->inputType>\n";
00172
00173 return $string;
00174 }
00175
00176
00180 public function setDescription($d) {
00181 $this->description = $d;
00182 }
00183
00184
00185 }
00186
00187 ?>