| 1 |
<?php |
|---|
| 2 |
// TODO: * Test 'processfunctions' |
|---|
| 3 |
|
|---|
| 4 |
class component { |
|---|
| 5 |
var $_compname; // Component name (e.g. users, devices, etc.) |
|---|
| 6 |
var $_type; // Type name of this component ( e.g. setup, tool etc.) |
|---|
| 7 |
|
|---|
| 8 |
var $_guielems_top; // Array of guielements |
|---|
| 9 |
var $_guielems_middle; // Array of guielements |
|---|
| 10 |
var $_guielems_bottom; // Array of guielements |
|---|
| 11 |
|
|---|
| 12 |
var $_jsfuncs; // Array of JavaScript functions |
|---|
| 13 |
var $_guifuncs; // Array of gui functions |
|---|
| 14 |
var $_processfuncs; // Array of process functions |
|---|
| 15 |
|
|---|
| 16 |
var $_sorted_guielems; |
|---|
| 17 |
var $_sorted_jsfuncs; |
|---|
| 18 |
var $_sorted_guifuncs; |
|---|
| 19 |
var $_sorted_processfuncs; |
|---|
| 20 |
|
|---|
| 21 |
var $_lists; // Array of lists |
|---|
| 22 |
|
|---|
| 23 |
function component($compname, $type = 'setup') { |
|---|
| 24 |
$this->_compname = $compname; |
|---|
| 25 |
$this->_type = $type; |
|---|
| 26 |
|
|---|
| 27 |
$this->_sorted_guielems = true; |
|---|
| 28 |
$this->_sorted_jsfuncs = true; |
|---|
| 29 |
$this->_sorted_guifuncs = true; |
|---|
| 30 |
$this->_sorted_processfuncs = true; |
|---|
| 31 |
} |
|---|
| 32 |
|
|---|
| 33 |
function addguielem($section, $guielem, $sortorder = 5, $placement = null) { |
|---|
| 34 |
// Note that placement is only used in 'middle', eg, a named module |
|---|
| 35 |
if ( $sortorder < 0 || $sortorder > 9 ) { |
|---|
| 36 |
trigger_error('$sortorder must be between 0 and 9 in component->addguielem()'); |
|---|
| 37 |
return; |
|---|
| 38 |
} |
|---|
| 39 |
|
|---|
| 40 |
switch ($section) { |
|---|
| 41 |
case '_top': |
|---|
| 42 |
$this->_guielems_top[$sortorder][] = $guielem; |
|---|
| 43 |
break; |
|---|
| 44 |
case '_bottom': |
|---|
| 45 |
$this->_guielems_bottom[$sortorder][] = $guielem; |
|---|
| 46 |
break; |
|---|
| 47 |
default: |
|---|
| 48 |
$this->_guielems_middle[$section][$sortorder][] = $guielem; |
|---|
| 49 |
if (!isset($this->_guielems_middle[$section]['placement'])) { |
|---|
| 50 |
if ($placement === null) { |
|---|
| 51 |
$this->_guielems_middle[$section]['placement'] = $sortorder; |
|---|
| 52 |
} else { |
|---|
| 53 |
$this->_guielems_middle[$section]['placement'] = $placement; |
|---|
| 54 |
} |
|---|
| 55 |
} |
|---|
| 56 |
break; |
|---|
| 57 |
} |
|---|
| 58 |
|
|---|
| 59 |
$this->_sorted_guielems = false; |
|---|
| 60 |
} |
|---|
| 61 |
|
|---|
| 62 |
function addjsfunc($function, $jstext, $sortorder = 5) { |
|---|
| 63 |
if ( $sortorder < 0 || $sortorder > 9 ) { |
|---|
| 64 |
trigger_error('$sortorder must be between 0 and 9 in component->addjsfunc()'); |
|---|
| 65 |
return; |
|---|
| 66 |
} |
|---|
| 67 |
|
|---|
| 68 |
$this->_jsfuncs[$function][$sortorder][] = $jstext; |
|---|
| 69 |
|
|---|
| 70 |
$this->_sorted_jsfuncs = false; |
|---|
| 71 |
} |
|---|
| 72 |
|
|---|
| 73 |
function addguifunc($function, $sortorder = 5) { |
|---|
| 74 |
if ( $sortorder < 0 || $sortorder > 9 ) { |
|---|
| 75 |
trigger_error('$sortorder must be between 0 and 9 in component->addguifunc()'); |
|---|
| 76 |
return; |
|---|
| 77 |
} |
|---|
| 78 |
if ( !function_exists($function) ) { |
|---|
| 79 |
trigger_error("$function does not exist"); |
|---|
| 80 |
return; |
|---|
| 81 |
} |
|---|
| 82 |
|
|---|
| 83 |
$this->_guifuncs[$sortorder][] = $function; |
|---|
| 84 |
|
|---|
| 85 |
$this->_sorted_guifuncs = false; |
|---|
| 86 |
} |
|---|
| 87 |
|
|---|
| 88 |
function addprocessfunc($function, $sortorder = 5) { |
|---|
| 89 |
if ( $sortorder < 0 || $sortorder > 9 ) { |
|---|
| 90 |
trigger_error('$sortorder must be between 0 and 9 in component->addprocessfunc()'); |
|---|
| 91 |
return; |
|---|
| 92 |
} |
|---|
| 93 |
if ( !function_exists($function) ) { |
|---|
| 94 |
trigger_error("$function does not exist"); |
|---|
| 95 |
return; |
|---|
| 96 |
} |
|---|
| 97 |
|
|---|
| 98 |
$this->_processfuncs[$sortorder][] = $function; |
|---|
| 99 |
|
|---|
| 100 |
$this->_sorted_processfuncs = false; |
|---|
| 101 |
} |
|---|
| 102 |
|
|---|
| 103 |
function addoptlist($listname, $sort = true) { |
|---|
| 104 |
if ( (isset($listname) ? $listname : '') == '') { |
|---|
| 105 |
trigger_error('missing $listname in component->addoptlist()'); |
|---|
| 106 |
return; |
|---|
| 107 |
} elseif (isset($this->_lists[$listname]) && is_array($this->_lists[$listname]) ) { |
|---|
| 108 |
trigger_error("list $listname already exists"); |
|---|
| 109 |
} |
|---|
| 110 |
|
|---|
| 111 |
// does this list need sorting ? |
|---|
| 112 |
$this->_lists[$listname]['sort'] = $sort; |
|---|
| 113 |
// nothing really, but an array will be here after addlistitem |
|---|
| 114 |
$this->_lists[$listname]['array'] = array(); |
|---|
| 115 |
} |
|---|
| 116 |
|
|---|
| 117 |
function setoptlistopts($listname, $opt, $val) { |
|---|
| 118 |
$this->_lists[$listname][$opt] = $val; |
|---|
| 119 |
} |
|---|
| 120 |
|
|---|
| 121 |
function addoptlistitem($listname, $value, $text, $uselang = true) { |
|---|
| 122 |
// must add the list before using it |
|---|
| 123 |
if ( !isset($this->_lists[$listname]) ) { |
|---|
| 124 |
$this->addoptlist($listname); |
|---|
| 125 |
} |
|---|
| 126 |
|
|---|
| 127 |
// use i4l ????? |
|---|
| 128 |
$text = ($uselang) ? _($text) : $text; |
|---|
| 129 |
|
|---|
| 130 |
// add the item |
|---|
| 131 |
$this->_lists[$listname]['array'][] = array('text' => $text, 'value' => $value); |
|---|
| 132 |
} |
|---|
| 133 |
|
|---|
| 134 |
function getoptlist($listname) { |
|---|
| 135 |
if ( isset($this->_lists[$listname]['array']) ) { |
|---|
| 136 |
// sort the array by text |
|---|
| 137 |
if ( $this->_lists[$listname]['sort'] ) { |
|---|
| 138 |
asort($this->_lists[$listname]['array']); |
|---|
| 139 |
} |
|---|
| 140 |
|
|---|
| 141 |
// and return it! |
|---|
| 142 |
return $this->_lists[$listname]['array']; |
|---|
| 143 |
} else { |
|---|
| 144 |
trigger_error("'$listname' does not exist in component->getoptlist()"); |
|---|
| 145 |
return null; |
|---|
| 146 |
} |
|---|
| 147 |
} |
|---|
| 148 |
|
|---|
| 149 |
function addgeneralarray($arrayname) { |
|---|
| 150 |
if ( (isset($arrayname) ? $arrayname : '') == '') { |
|---|
| 151 |
trigger_error('missing $arrayname in component->addarray()'); |
|---|
| 152 |
return; |
|---|
| 153 |
} elseif ( isset($this->_lists[$arrayname]) && is_array($this->_lists[$arrayname]) ) { |
|---|
| 154 |
trigger_error("array $arrayname already exists"); |
|---|
| 155 |
} |
|---|
| 156 |
|
|---|
| 157 |
// nothing really, but an array will be here after addlistitem |
|---|
| 158 |
$this->_lists[$arrayname] = array(); |
|---|
| 159 |
} |
|---|
| 160 |
|
|---|
| 161 |
function addgeneralarrayitem($arrayname, $arraykey, $item) { |
|---|
| 162 |
if ( !isset($this->_lists[$arrayname]) ) { |
|---|
| 163 |
$this->addgeneralarray($arrayname); |
|---|
| 164 |
} |
|---|
| 165 |
|
|---|
| 166 |
$this->_lists[$arrayname][$arraykey] = $item; |
|---|
| 167 |
} |
|---|
| 168 |
|
|---|
| 169 |
function getgeneralarray($arrayname) { |
|---|
| 170 |
if ( isset($this->_lists[$arrayname]) ) { |
|---|
| 171 |
return $this->_lists[$arrayname]; |
|---|
| 172 |
} else { |
|---|
| 173 |
trigger_error("'$arrayname' does not exist in component->getgeneralarray()"); |
|---|
| 174 |
return null; |
|---|
| 175 |
} |
|---|
| 176 |
} |
|---|
| 177 |
|
|---|
| 178 |
function getgeneralarrayitem($arrayname, $arraykey) { |
|---|
| 179 |
if ( isset($this->_lists[$arrayname][$arraykey]) ) { |
|---|
| 180 |
return $this->_lists[$arrayname][$arraykey]; |
|---|
| 181 |
} else { |
|---|
| 182 |
trigger_error("'$arraykey' does not exist in array '$arrayname'"); |
|---|
| 183 |
return null; |
|---|
| 184 |
} |
|---|
| 185 |
} |
|---|
| 186 |
|
|---|
| 187 |
function sortguielems() { |
|---|
| 188 |
// sort top gui elements |
|---|
| 189 |
if ( is_array($this->_guielems_top) ) |
|---|
| 190 |
ksort($this->_guielems_top); |
|---|
| 191 |
|
|---|
| 192 |
// sort middle gui elements |
|---|
| 193 |
if ( is_array($this->_guielems_middle) ) { |
|---|
| 194 |
foreach ( array_keys($this->_guielems_middle) as $section ) { |
|---|
| 195 |
ksort($this->_guielems_middle[$section]); |
|---|
| 196 |
} |
|---|
| 197 |
ksort($this->_guielems_middle); |
|---|
| 198 |
} |
|---|
| 199 |
|
|---|
| 200 |
// sort bottom gui elements |
|---|
| 201 |
if ( is_array($this->_guielems_top) ) |
|---|
| 202 |
ksort($this->_guielems_top); |
|---|
| 203 |
|
|---|
| 204 |
|
|---|
| 205 |
$this->_sorted_guielems = true; |
|---|
| 206 |
} |
|---|
| 207 |
|
|---|
| 208 |
function sortjsfuncts() { |
|---|
| 209 |
// sort js funcs |
|---|
| 210 |
if ( is_array($this->_jsfuncs) ) { |
|---|
| 211 |
foreach ( array_keys($this->_jsfuncs) as $function ) { |
|---|
| 212 |
ksort($this->_jsfuncs[$function]); |
|---|
| 213 |
} |
|---|
| 214 |
ksort($this->_jsfuncs); |
|---|
| 215 |
} |
|---|
| 216 |
|
|---|
| 217 |
$this->_sorted_jsfuncs = true; |
|---|
| 218 |
} |
|---|
| 219 |
|
|---|
| 220 |
function sortguifuncs() { |
|---|
| 221 |
// sort process functions |
|---|
| 222 |
if ( is_array($this->_guifuncs) ) { |
|---|
| 223 |
ksort($this->_guifuncs); |
|---|
| 224 |
} |
|---|
| 225 |
|
|---|
| 226 |
$this->_sorted_guifuncs = true; |
|---|
| 227 |
} |
|---|
| 228 |
|
|---|
| 229 |
function sortprocessfuncs() { |
|---|
| 230 |
// sort process functions |
|---|
| 231 |
if ( is_array($this->_processfuncs) ) { |
|---|
| 232 |
ksort($this->_processfuncs); |
|---|
| 233 |
} |
|---|
| 234 |
|
|---|
| 235 |
$this->_sorted_processfuncs = true; |
|---|
| 236 |
} |
|---|
| 237 |
|
|---|
| 238 |
function generateconfigpage() { |
|---|
| 239 |
$htmlout = ''; |
|---|
| 240 |
$formname = "frm_$this->_compname"; |
|---|
| 241 |
$hasoutput = false; |
|---|
| 242 |
|
|---|
| 243 |
if ( !$this->_sorted_guielems ) |
|---|
| 244 |
$this->sortguielems(); |
|---|
| 245 |
|
|---|
| 246 |
// Start of form |
|---|
| 247 |
$htmlout .= "<form name=\"$formname\" action=\"".$_SERVER['PHP_SELF']."\" method=\"post\" onsubmit=\"return ".$formname."_onsubmit();\">\n"; |
|---|
| 248 |
$htmlout .= "<input type=\"hidden\" name=\"display\" value=\"$this->_compname\" />\n"; |
|---|
| 249 |
$htmlout .= "<input type=\"hidden\" name=\"type\" value=\"$this->_type\" />\n\n"; |
|---|
| 250 |
|
|---|
| 251 |
// Start of table |
|---|
| 252 |
$htmlout .= "<table><!-- start of table $formname -->\n"; |
|---|
| 253 |
|
|---|
| 254 |
// Gui Elements / JavaScript validation |
|---|
| 255 |
// Top |
|---|
| 256 |
if ( is_array($this->_guielems_top) ) { |
|---|
| 257 |
$hasoutput = true; |
|---|
| 258 |
foreach ( array_keys($this->_guielems_top) as $sortorder ) { |
|---|
| 259 |
foreach ( array_keys($this->_guielems_top[$sortorder]) as $idx ) { |
|---|
| 260 |
$elem = $this->_guielems_top[$sortorder][$idx]; |
|---|
| 261 |
$htmlout .= $elem->generatehtml(); |
|---|
| 262 |
$this->addjsfunc('onsubmit()', $elem->generatevalidation()); |
|---|
| 263 |
} |
|---|
| 264 |
} |
|---|
| 265 |
} |
|---|
| 266 |
|
|---|
| 267 |
// Middle |
|---|
| 268 |
if ( is_array($this->_guielems_middle) ) { |
|---|
| 269 |
$hasoutput = true; |
|---|
| 270 |
for ($placement = 0; $placement < 10; $placement++) { |
|---|
| 271 |
foreach ( array_keys($this->_guielems_middle) as $section ) { |
|---|
| 272 |
if ($this->_guielems_middle[$section]['placement'] !== $placement) |
|---|
| 273 |
continue; |
|---|
| 274 |
// Header for $section |
|---|
| 275 |
$htmlout .= "\t<tr>\n"; |
|---|
| 276 |
$htmlout .= "\t\t<td colspan=\"2\">"; |
|---|
| 277 |
$htmlout .= "<h5><br>" . _($section) . "</h5><hr>"; |
|---|
| 278 |
$htmlout .= "</td>\n"; |
|---|
| 279 |
$htmlout .= "\t</tr>\n"; |
|---|
| 280 |
|
|---|
| 281 |
// Elements |
|---|
| 282 |
foreach ( array_keys($this->_guielems_middle[$section]) as $sortorder ) { |
|---|
| 283 |
if ($sortorder == 'placement') |
|---|
| 284 |
continue; |
|---|
| 285 |
foreach ( array_keys($this->_guielems_middle[$section][$sortorder]) as $idx ) { |
|---|
| 286 |
$elem = $this->_guielems_middle[$section][$sortorder][$idx]; |
|---|
| 287 |
$htmlout .= $elem->generatehtml(); |
|---|
| 288 |
$this->addjsfunc('onsubmit()', $elem->generatevalidation()); |
|---|
| 289 |
} |
|---|
| 290 |
} |
|---|
| 291 |
} |
|---|
| 292 |
} |
|---|
| 293 |
// Spacer before bottom |
|---|
| 294 |
if ( is_array($this->_guielems_bottom) ) { |
|---|
| 295 |
$htmlout .= "\t<tr>\n"; |
|---|
| 296 |
$htmlout .= "\t\t<td colspan=\"2\">"; |
|---|
| 297 |
$htmlout .= " "; |
|---|
| 298 |
$htmlout .= "</td>\n"; |
|---|
| 299 |
$htmlout .= "\t</tr>\n"; |
|---|
| 300 |
} |
|---|
| 301 |
} |
|---|
| 302 |
|
|---|
| 303 |
// Bottom |
|---|
| 304 |
if ( is_array($this->_guielems_bottom) ) { |
|---|
| 305 |
$hasoutput = true; |
|---|
| 306 |
foreach ( array_keys($this->_guielems_bottom) as $sortorder ) { |
|---|
| 307 |
foreach ( array_keys($this->_guielems_bottom[$sortorder]) as $idx ) { |
|---|
| 308 |
$elem = $this->_guielems_bottom[$sortorder][$idx]; |
|---|
| 309 |
$htmlout .= $elem->generatehtml(); |
|---|
| 310 |
$this->addjsfunc('onsubmit()', $elem->generatevalidation()); |
|---|
| 311 |
} |
|---|
| 312 |
} |
|---|
| 313 |
} |
|---|
| 314 |
|
|---|
| 315 |
// End of table |
|---|
| 316 |
$htmlout .= "\t<tr>\n"; |
|---|
| 317 |
$htmlout .= "\t\t<td colspan=\"2\">"; |
|---|
| 318 |
$htmlout .= "<br><br><h6>"; |
|---|
| 319 |
$htmlout .= "<input name=\"Submit\" type=\"submit\" value=\""._("Submit")."\">"; |
|---|
| 320 |
$htmlout .= "</h6>"; |
|---|
| 321 |
$htmlout .= "</td>\n"; |
|---|
| 322 |
$htmlout .= "\t</tr>\n"; |
|---|
| 323 |
$htmlout .= "</table><!-- end of table $formname -->\n\n"; |
|---|
| 324 |
|
|---|
| 325 |
if ( !$this->_sorted_jsfuncs ) |
|---|
| 326 |
$this->sortjsfuncts(); |
|---|
| 327 |
|
|---|
| 328 |
// Javascript |
|---|
| 329 |
$htmlout .= "<script type=\"text/javascript\">\n<!--\n"; |
|---|
| 330 |
$htmlout .= "var theForm = document.$formname;\n\n"; |
|---|
| 331 |
|
|---|
| 332 |
// TODO: * Create standard JS to go thru each text box looking for first one not hidden and set focus |
|---|
| 333 |
if ( is_array($this->_jsfuncs) ) { |
|---|
| 334 |
foreach ( array_keys($this->_jsfuncs) as $function ) { |
|---|
| 335 |
// Functions |
|---|
| 336 |
$htmlout .= "function ".$formname."_$function {\n"; |
|---|
| 337 |
foreach ( array_keys($this->_jsfuncs[$function]) as $sortorder ) { |
|---|
| 338 |
foreach ( array_keys($this->_jsfuncs[$function][$sortorder]) as $idx ) { |
|---|
| 339 |
$func = $this->_jsfuncs[$function][$sortorder][$idx]; |
|---|
| 340 |
$htmlout .= ( isset($func) ) ? "$func" : ''; |
|---|
| 341 |
} |
|---|
| 342 |
} |
|---|
| 343 |
if ( $function == 'onsubmit()' ) |
|---|
| 344 |
$htmlout .= "\treturn true;\n"; |
|---|
| 345 |
$htmlout .= "}\n"; |
|---|
| 346 |
} |
|---|
| 347 |
} |
|---|
| 348 |
$htmlout .= "//-->\n</script>"; |
|---|
| 349 |
|
|---|
| 350 |
// End of form |
|---|
| 351 |
$htmlout .= "\n</form>\n\n"; |
|---|
| 352 |
|
|---|
| 353 |
if ( $hasoutput ) { |
|---|
| 354 |
return $htmlout; |
|---|
| 355 |
} else { |
|---|
| 356 |
return ''; |
|---|
| 357 |
} |
|---|
| 358 |
} |
|---|
| 359 |
|
|---|
| 360 |
function processconfigpage() { |
|---|
| 361 |
if ( !$this->_sorted_processfuncs ) |
|---|
| 362 |
$this->sortprocessfuncs(); |
|---|
| 363 |
|
|---|
| 364 |
if ( is_array($this->_processfuncs) ) { |
|---|
| 365 |
foreach ( array_keys($this->_processfuncs) as $sortorder ) { |
|---|
| 366 |
foreach ( $this->_processfuncs[$sortorder] as $func ) { |
|---|
| 367 |
$func($this->_compname); |
|---|
| 368 |
} |
|---|
| 369 |
} |
|---|
| 370 |
} |
|---|
| 371 |
} |
|---|
| 372 |
|
|---|
| 373 |
function buildconfigpage() { |
|---|
| 374 |
if ( !$this->_sorted_guifuncs ) |
|---|
| 375 |
$this->sortguifuncs(); |
|---|
| 376 |
|
|---|
| 377 |
if ( is_array($this->_guifuncs) ) { |
|---|
| 378 |
foreach ( array_keys($this->_guifuncs) as $sortorder ) { |
|---|
| 379 |
foreach ( $this->_guifuncs[$sortorder] as $func ) { |
|---|
| 380 |
$func($this->_compname); |
|---|
| 381 |
} |
|---|
| 382 |
} |
|---|
| 383 |
} |
|---|
| 384 |
} |
|---|
| 385 |
|
|---|
| 386 |
function isequal($compname, $type) { |
|---|
| 387 |
return $this->_compname == $compname && $this->_type == $type; |
|---|
| 388 |
} |
|---|
| 389 |
} |
|---|
| 390 |
|
|---|
| 391 |
class guielement { |
|---|
| 392 |
var $_elemname; |
|---|
| 393 |
var $_html; |
|---|
| 394 |
var $_javascript; |
|---|
| 395 |
|
|---|
| 396 |
function guielement($elemname, $html = '', $javascript = '') { |
|---|
| 397 |
// name that will be the id tag |
|---|
| 398 |
$this->_elemname = $elemname; |
|---|
| 399 |
|
|---|
| 400 |
// normally the $html will be the actual page output, obviously here in the base class it's meaningless |
|---|
| 401 |
// this does mean, of course, this constructor MUST be called before any child class constructor code |
|---|
| 402 |
// otherwise $html will be blanked out |
|---|
| 403 |
$this->_html = $html; |
|---|
| 404 |
$this->_javascript = $javascript; |
|---|
| 405 |
} |
|---|
| 406 |
|
|---|
| 407 |
function generatehtml() { |
|---|
| 408 |
return $this->_html; |
|---|
| 409 |
} |
|---|
| 410 |
|
|---|
| 411 |
function generatevalidation() { |
|---|
| 412 |
return $this->_javascript; |
|---|
| 413 |
} |
|---|
| 414 |
} |
|---|
| 415 |
|
|---|
| 416 |
// Hidden field |
|---|
| 417 |
// Odd ball this one as neither guiinput or guitext ! |
|---|
| 418 |
class gui_hidden extends guielement { |
|---|
| 419 |
function gui_hidden($elemname, $currentvalue = '') { |
|---|
| 420 |
// call parent class contructor |
|---|
| 421 |
guielement::guielement($elemname, '', ''); |
|---|
| 422 |
|
|---|
| 423 |
$this->_html = "<input type=\"hidden\" name=\"$this->_elemname\" id=\"$this->_elemname\" value=\"" . htmlentities($currentvalue) . "\">"; |
|---|
| 424 |
|
|---|
| 425 |
// make it a new row |
|---|
| 426 |
$this->_html = "\t<tr>\n\t\t<td>" . $this->_html . "</td>\n\t</tr>\n"; |
|---|
| 427 |
} |
|---|
| 428 |
} |
|---|
| 429 |
|
|---|
| 430 |
/* |
|---|
| 431 |
************************************************************ |
|---|
| 432 |
** guiinput is the base class of all form fields ** |
|---|
| 433 |
************************************************************ |
|---|
| 434 |
*/ |
|---|
| 435 |
|
|---|
| 436 |
class guiinput extends guielement { |
|---|
| 437 |
var $currentvalue; |
|---|
| 438 |
var $prompttext; |
|---|
| 439 |
var $helptext; |
|---|
| 440 |
var $jsvalidation; |
|---|
| 441 |
var $failvalidationmsg; |
|---|
| 442 |
var $canbeempty; |
|---|
| 443 |
|
|---|
| 444 |
var $html_input; |
|---|
| 445 |
|
|---|
| 446 |
function guiinput($elemname, $currentvalue = '', $prompttext = '', $helptext = '', $jsvalidation = '', $failvalidationmsg = '', $canbeempty = true) { |
|---|
| 447 |
// call parent class contructor |
|---|
| 448 |
guielement::guielement($elemname, '', ''); |
|---|
| 449 |
|
|---|
| 450 |
// current valid of the field |
|---|
| 451 |
$this->currentvalue = $currentvalue; |
|---|
| 452 |
// this will appear on the left column |
|---|
| 453 |
$this->prompttext = _($prompttext); |
|---|
| 454 |
// tooltip over prompttext (optional) |
|---|
| 455 |
$this->helptext = $helptext; |
|---|
| 456 |
// JavaScript validation field on the element |
|---|
| 457 |
$this->jsvalidation = $jsvalidation; |
|---|
| 458 |
// Msg to use if above validation fails (forced to use gettext language stuff) |
|---|
| 459 |
$this->failvalidationmsg = _($failvalidationmsg); |
|---|
| 460 |
// Can this field be empty ? |
|---|
| 461 |
$this->canbeempty = $canbeempty; |
|---|
| 462 |
|
|---|
| 463 |
// this will be the html that makes up the input element |
|---|
| 464 |
$this->html_input = ''; |
|---|
| 465 |
} |
|---|
| 466 |
|
|---|
| 467 |
function generatevalidation() { |
|---|
| 468 |
$output = ''; |
|---|
| 469 |
|
|---|
| 470 |
if ($this->jsvalidation != '') { |
|---|
| 471 |
$thefld = "theForm." . $this->_elemname; |
|---|
| 472 |
$thefldvalue = $thefld . ".value"; |
|---|
| 473 |
|
|---|
| 474 |
if ($this->canbeempty) { |
|---|
| 475 |
$output .= "\tdefaultEmptyOK = true;\n"; |
|---|
| 476 |
} else { |
|---|
| 477 |
$output .= "\tdefaultEmptyOK = false;\n"; |
|---|
| 478 |
} |
|---|
| 479 |
|
|---|
| 480 |
$output .= "\tif (" . str_replace("()", "(" . $thefldvalue . ")", $this->jsvalidation) . ") \n"; |
|---|
| 481 |
$output .= "\t\treturn warnInvalid(" . $thefld . ", \"" . $this->failvalidationmsg . "\");\n"; |
|---|
| 482 |
$output .= "\n"; |
|---|
| 483 |
} |
|---|
| 484 |
|
|---|
| 485 |
return $output; |
|---|
| 486 |
} |
|---|
| 487 |
|
|---|
| 488 |
function generatehtml() { |
|---|
| 489 |
// this effectivly creates the template using the prompttext and html_input |
|---|
| 490 |
// we would expect the $html_input to be set by the child class |
|---|
| 491 |
|
|---|
| 492 |
$output = ''; |
|---|
| 493 |
|
|---|
| 494 |
// start new row |
|---|
| 495 |
$output .= "\t<tr>\n"; |
|---|
| 496 |
|
|---|
| 497 |
// prompt in first column |
|---|
| 498 |
$output .= "\t\t<td>"; |
|---|
| 499 |
if ($this->helptext != '') { |
|---|
| 500 |
$output .= "<a href=\"#\" class=\"info\">$this->prompttext<span>$this->helptext</span></a>"; |
|---|
| 501 |
} else { |
|---|
| 502 |
$output .= $this->prompttext; |
|---|
| 503 |
} |
|---|
| 504 |
$output .= "</td>\n"; |
|---|
| 505 |
|
|---|
| 506 |
// actual input in second row |
|---|
| 507 |
$output .= "\t\t<td>"; |
|---|
| 508 |
$output .= $this->html_input; |
|---|
| 509 |
$output .= "</td>\n"; |
|---|
| 510 |
|
|---|
| 511 |
// end this row |
|---|
| 512 |
$output .= "\t</tr>\n"; |
|---|
| 513 |
|
|---|
| 514 |
return $output; |
|---|
| 515 |
} |
|---|
| 516 |
} |
|---|
| 517 |
|
|---|
| 518 |
// Textbox |
|---|
| 519 |
class gui_textbox extends guiinput { |
|---|
| 520 |
function gui_textbox($elemname, $currentvalue = '', $prompttext = '', $helptext = '', $jsvalidation = '', $failvalidationmsg = '', $canbeempty = true, $maxchars = 0) { |
|---|
| 521 |
// call parent class contructor |
|---|
| 522 |
$parent_class = get_parent_class($this); |
|---|
| 523 |
parent::$parent_class($elemname, $currentvalue, $prompttext, $helptext, $jsvalidation, $failvalidationmsg, $canbeempty); |
|---|
| 524 |
|
|---|
| 525 |
$maxlength = ($maxchars > 0) ? " maxlength=\"$maxchars\"" : ''; |
|---|
| 526 |
$this->html_input = "<input type=\"text\" name=\"$this->_elemname\" id=\"$this->_elemname\"$maxlength value=\"" . htmlentities($this->currentvalue) . "\">"; |
|---|
| 527 |
} |
|---|
| 528 |
} |
|---|
| 529 |
|
|---|
| 530 |
// Password |
|---|
| 531 |
class gui_password extends guiinput { |
|---|
| 532 |
function gui_password($elemname, $currentvalue = '', $prompttext = '', $helptext = '', $jsvalidation = '', $failvalidationmsg = '', $canbeempty = true, $maxchars = 0) { |
|---|
| 533 |
// call parent class contructor |
|---|
| 534 |
$parent_class = get_parent_class($this); |
|---|
| 535 |
parent::$parent_class($elemname, $currentvalue, $prompttext, $helptext, $jsvalidation, $failvalidationmsg, $canbeempty); |
|---|
| 536 |
|
|---|
| 537 |
$maxlength = ($maxchars > 0) ? " maxlength=\"$maxchars\"" : ''; |
|---|
| 538 |
$this->html_input = "<input type=\"password\" name=\"$this->_elemname\" id=\"$this->_elemname\"$maxlength value=\"" . htmlentities($this->currentvalue) . "\">"; |
|---|
| 539 |
} |
|---|
| 540 |
} |
|---|
| 541 |
|
|---|
| 542 |
// Select box |
|---|
| 543 |
class gui_selectbox extends guiinput { |
|---|
| 544 |
function gui_selectbox($elemname, $valarray, $currentvalue = '', $prompttext = '', $helptext = '', $canbeempty = true, $onchange = '') { |
|---|
| 545 |
if (!is_array($valarray)) { |
|---|
| 546 |
trigger_error('$valarray must be a valid array in gui_selectbox'); |
|---|
| 547 |
return; |
|---|
| 548 |
} |
|---|
| 549 |
|
|---|
| 550 |
// currently no validation fucntions availble for select boxes |
|---|
| 551 |
// using the normal $canbeempty to flag if a blank option is provided |
|---|
| 552 |
$parent_class = get_parent_class($this); |
|---|
| 553 |
parent::$parent_class($elemname, $currentvalue, $prompttext, $helptext); |
|---|
| 554 |
|
|---|
| 555 |
$this->html_input = $this->buildselectbox($valarray, $currentvalue, $canbeempty, $onchange); |
|---|
| 556 |
} |
|---|
| 557 |
|
|---|
| 558 |
// Build select box |
|---|
| 559 |
function buildselectbox($valarray, $currentvalue, $canbeempty, $onchange) { |
|---|
| 560 |
$output = ''; |
|---|
| 561 |
$onchange = ($onchange != '') ? " onchange=\"$onchange\"" : ''; |
|---|
| 562 |
|
|---|
| 563 |
$output .= "\n\t\t\t<select name=\"$this->_elemname\" id=\"$this->_elemname\"$onchange>\n"; |
|---|
| 564 |
// include blank option if required |
|---|
| 565 |
if ($canbeempty) |
|---|
| 566 |
$output .= "<option value=\"\"> </option>"; |
|---|
| 567 |
|
|---|
| 568 |
// build the options |
|---|
| 569 |
foreach ($valarray as $item) { |
|---|
| 570 |
$itemvalue = (isset($item['value']) ? $item['value'] : ''); |
|---|
| 571 |
$itemtext = (isset($item['text']) ? _($item['text']) : ''); |
|---|
| 572 |
$itemselected = ($currentvalue == $itemvalue) ? ' selected' : ''; |
|---|
| 573 |
|
|---|
| 574 |
$output .= "\t\t\t\t<option value=\"$itemvalue\"$itemselected>$itemtext</option>\n"; |
|---|
| 575 |
} |
|---|
| 576 |
$output .= "\t\t\t</select>\n\t\t"; |
|---|
| 577 |
|
|---|
| 578 |
return $output; |
|---|
| 579 |
} |
|---|
| 580 |
} |
|---|
| 581 |
|
|---|
| 582 |
class gui_radio extends guiinput { |
|---|
| 583 |
function gui_radio($elemname, $valarray, $currentvalue = '', $prompttext = '', $helptext = '') { |
|---|
| 584 |
if (!is_array($valarray)) { |
|---|
| 585 |
trigger_error('$valarray must be a valid array in gui_radio'); |
|---|
| 586 |
return; |
|---|
| 587 |
} |
|---|
| 588 |
|
|---|
| 589 |
$parent_class = get_parent_class($this); |
|---|
| 590 |
parent::$parent_class($elemname, $currentvalue, $prompttext, $helptext); |
|---|
| 591 |
|
|---|
| 592 |
$this->html_input = $this->buildradiobuttons($valarray, $currentvalue); |
|---|
| 593 |
} |
|---|
| 594 |
|
|---|
| 595 |
function buildradiobuttons($valarray, $currentvalue) { |
|---|
| 596 |
$output = ''; |
|---|
| 597 |
|
|---|
| 598 |
foreach ($valarray as $item) { |
|---|
| 599 |
$itemvalue = (isset($item['value']) ? $item['value'] : ''); |
|---|
| 600 |
$itemtext = (isset($item['text']) ? _($item['text']) : ''); |
|---|
| 601 |
$itemchecked = ($currentvalue == $itemvalue) ? ' checked=checked' : ''; |
|---|
| 602 |
|
|---|
| 603 |
$output .= "<input type=\"radio\" name=\"$this->_elemname\" id=\"$this->_elemname\" value=\"$this->_elemname=$itemvalue\"$itemchecked/>$itemtext \n"; |
|---|
| 604 |
} |
|---|
| 605 |
return $output; |
|---|
| 606 |
} |
|---|
| 607 |
} |
|---|
| 608 |
|
|---|
| 609 |
/* |
|---|
| 610 |
************************************************************ |
|---|
| 611 |
** guitext is the base class of all text fields (e.g. h1) ** |
|---|
| 612 |
************************************************************ |
|---|
| 613 |
*/ |
|---|
| 614 |
|
|---|
| 615 |
class guitext extends guielement { |
|---|
| 616 |
var $html_text; |
|---|
| 617 |
|
|---|
| 618 |
function guitext($elemname, $html_text = '') { |
|---|
| 619 |
// call parent class contructor |
|---|
| 620 |
guielement::guielement($elemname, '', ''); |
|---|
| 621 |
|
|---|
| 622 |
$this->html_text = $html_text; |
|---|
| 623 |
} |
|---|
| 624 |
|
|---|
| 625 |
function generatehtml() { |
|---|
| 626 |
// this effectivly creates the template using the html_text |
|---|
| 627 |
// we would expect the $html_text to be set by the child class |
|---|
| 628 |
|
|---|
| 629 |
$output = ''; |
|---|
| 630 |
|
|---|
| 631 |
// start new row |
|---|
| 632 |
$output .= "\t<tr>\n"; |
|---|
| 633 |
|
|---|
| 634 |
// actual input in second row |
|---|
| 635 |
$output .= "\t\t<td colspan=\"2\">"; |
|---|
| 636 |
$output .= $this->html_text; |
|---|
| 637 |
$output .= "</td>\n"; |
|---|
| 638 |
|
|---|
| 639 |
// end this row |
|---|
| 640 |
$output .= "\t</tr>\n"; |
|---|
| 641 |
|
|---|
| 642 |
return $output; |
|---|
| 643 |
} |
|---|
| 644 |
} |
|---|
| 645 |
|
|---|
| 646 |
// Label -- just text basically! |
|---|
| 647 |
class gui_label extends guitext { |
|---|
| 648 |
function gui_label($elemname, $text, $uselang = true) { |
|---|
| 649 |
// call parent class contructor |
|---|
| 650 |
$parent_class = get_parent_class($this); |
|---|
| 651 |
parent::$parent_class($elemname, $text); |
|---|
| 652 |
|
|---|
| 653 |
// Use languagues |
|---|
| 654 |
if ( $uselang ) |
|---|
| 655 |
$text = _($text); |
|---|
| 656 |
|
|---|
| 657 |
// nothing really needed here as it's just whatever text was passed |
|---|
| 658 |
// but suppose we should do something with the element name |
|---|
| 659 |
$this->html_text = "<span id=\"$this->_elemname\">$text</span>"; |
|---|
| 660 |
} |
|---|
| 661 |
} |
|---|
| 662 |
|
|---|
| 663 |
// Main page header |
|---|
| 664 |
class gui_pageheading extends guitext { |
|---|
| 665 |
function gui_pageheading($elemname, $text, $uselang = true) { |
|---|
| 666 |
// call parent class contructor |
|---|
| 667 |
$parent_class = get_parent_class($this); |
|---|
| 668 |
parent::$parent_class($elemname, $text); |
|---|
| 669 |
|
|---|
| 670 |
// Use languagues |
|---|
| 671 |
if ( $uselang ) |
|---|
| 672 |
$text = _($text); |
|---|
| 673 |
|
|---|
| 674 |
// H2 |
|---|
| 675 |
$this->html_text = "<h2 id=\"$this->_elemname\">$text</h2>"; |
|---|
| 676 |
} |
|---|
| 677 |
} |
|---|
| 678 |
|
|---|
| 679 |
// Second level / sub header |
|---|
| 680 |
class gui_subheading extends guitext { |
|---|
| 681 |
function gui_subheading($elemname, $text, $uselang = true) { |
|---|
| 682 |
// call parent class contructor |
|---|
| 683 |
$parent_class = get_parent_class($this); |
|---|
| 684 |
parent::$parent_class($elemname, $text); |
|---|
| 685 |
|
|---|
| 686 |
// Use languagues |
|---|
| 687 |
if ( $uselang ) |
|---|
| 688 |
$text = _($text); |
|---|
| 689 |
|
|---|
| 690 |
// H3 |
|---|
| 691 |
$this->html_text = "<h3 id=\"$this->_elemname\">$text</h3>"; |
|---|
| 692 |
} |
|---|
| 693 |
} |
|---|
| 694 |
|
|---|
| 695 |
// URL / Link |
|---|
| 696 |
class gui_link extends guitext { |
|---|
| 697 |
function gui_link($elemname, $text, $url, $uselang = true) { |
|---|
| 698 |
// call parent class contructor |
|---|
| 699 |
$parent_class = get_parent_class($this); |
|---|
| 700 |
parent::$parent_class($elemname, $text); |
|---|
| 701 |
|
|---|
| 702 |
// Use languagues |
|---|
| 703 |
if ( $uselang ) |
|---|
| 704 |
$text = _($text); |
|---|
| 705 |
|
|---|
| 706 |
// A tag |
|---|
| 707 |
$this->html_text = "<a href=\"$url\" id=\"$this->_elemname\">$text</a>"; |
|---|
| 708 |
} |
|---|
| 709 |
} |
|---|
| 710 |
?> |
|---|