static function field($type = '', $name = '', $label = '', $value = '', $required = false, $id = '', $readonly = false, $properties = '') { $output = ''; $label_text = ''; $varname = $name; $properties = DevArray::toArray($properties); if (!isset($properties['class'])) { $properties['class'] = $type ? $type : 'formdata'; } foreach ($properties as $a => $b) { $attribs[] = "{$a}=\"{$b}\""; } $attrib = implode(' ', $attribs); $id = 'id="' . ($id != '' ? $id : $name) . '"'; $disabled = $readonly === false ? '' : 'readonly'; if ($readonly == 3) { $type = 'static'; } if ($label != '' && $type != 'static') { $label_text = '<label for="' . $name . '">' . ($required ? '*' : '') . $label . ': </label>'; } if ($type != 'date' && $type != 'select') { $name .= is_array($value) ? '[]' : ''; } $value = DevArray::toArray($value, true); switch ($type) { default: case 'text': foreach ($value as $a) { $output .= $label_text . ' <br />' . "\n\t" . '<input type="text" ' . $disabled . ' name="' . $name . '" ' . $id . ' value="' . $a . '" ' . $attrib . ' /><br />'; } break; case 'prompt': foreach ($value as $a) { $output .= $label_text . ' <br />' . "\n\t" . '<input type="text" ' . $disabled . ' name="' . $name . '" ' . $id . ' value="' . $a . '" ' . $attrib . ' onFocus="this.value=\'\'" /><br />'; } break; case 'password': foreach ($value as $a) { $output .= $label_text . ' <br />' . "\n\t" . '<input type="password" ' . $disabled . ' name="' . $name . '" ' . $id . ' value="' . $a . '" ' . $attrib . ' /><br />'; } break; case 'textarea': foreach ($value as $a) { $output .= $label_text . ' <br />' . "\n\t" . '<textarea ' . $disabled . ' name="' . $name . '" ' . $id . ' ' . $attrib . '>' . $a . '</textarea><br />'; } break; case 'select': $output .= $label_text . ' <br />' . "\n"; $output .= '<select name="' . $name . '" ' . $disabled . ' ' . $id . ' ' . $attrib . '>' . "\n"; $value = DevArray::toArray($value); global ${$varname}; foreach ($value as $a => $b) { if (is_array($b)) { $output .= "\t" . '<optgroup label="' . $a . '">' . "\n"; foreach ($b as $c => $d) { $output .= "\t\t" . '<option value="' . $d . '"'; //if the select option being drawn is the same as the //variable by the same name of this element, mark it as selected if (${$varname} == $d) { $output .= ' selected="selected"'; } $output .= '>' . $c . '</option>' . "\n"; } $output .= "\t" . '</optgroup>' . "\n"; } else { $output .= "\t" . '<option value="' . $b . '"'; //if the select option being drawn is the same as the //variable by the same name of this element, mark it as selected if (${$varname} == $b) { $output .= ' selected="selected"'; } $output .= '>' . $a . '</option>' . "\n"; } } $output .= '</select><br />'; break; case 'multiple': $output .= $label_text . ' <br />' . "\n"; $output .= '<select name="' . $name . '" ' . $disabled . ' ' . $id . ' ' . $attrib . ' size="6" multiple="multiple">' . "\n"; $value = DevArray::toArray($value); global ${$varname}; foreach ($value as $a => $b) { if (is_array($b)) { $output .= "\t" . '<optgroup label="' . $a . '">' . "\n"; foreach ($b as $c => $d) { $output .= "\t\t" . '<option value="' . $d . '"'; //if the select option being drawn is the same as the //variable by the same name of this element, mark it as selected if (is_array(${$varname})) { if (in_array($d, ${$varname})) { $output .= ' selected="selected"'; } elseif (${$varname} == $d) { $output .= ' selected="selected"'; } } $output .= '>' . $c . '</option>' . "\n"; } $output .= "\t" . '</optgroup>' . "\n"; } else { $output .= "\t" . '<option value="' . $b . '"'; //if the select option being drawn is the same as the //variable by the same name of this element, mark it as selected if (is_array(${$varname})) { if (in_array($b, ${$varname})) { $output .= ' selected="selected"'; } elseif (${$varname} == $b) { $output .= ' selected="selected"'; } } $output .= '>' . $a . '</option>' . "\n"; } } $output .= '</select><br />'; break; case 'hidden': foreach ($value as $a) { $output .= '<input type="hidden" ' . $disabled . ' name="' . $name . '" ' . $id . ' value="' . $a . '" />'; } break; case 'checkbox': if (DevArray::isAssoc($value)) { $output .= ($required ? '*' : '') . $label . '<br />'; $i = 1; foreach ($value as $a => $b) { $output .= '<input ' . $attrib . ' type="checkbox" ' . $disabled . ' name="' . $name . '" ' . substr_replace($id, $i . '"', -1, strlen($id)); global ${$varname}; if (${$varname} == $b) { $output .= ' checked="checked"'; } $output .= ' value="' . $b . '" />'; $output .= '<label for="' . $varname . $i . '">' . substr($a, 0, strlen($a)) . " </label><br /> \n"; $i++; } } else { foreach ($value as $a) { $output .= '<input type="checkbox" ' . $disabled . ' name="' . $name . '" ' . $id; global ${$varname}; if (${$varname} == $a) { $output .= ' checked="checked"'; } $output .= ' value="' . $a . '" /> '; $output .= '<label for="' . $varname . '">' . substr($label, 0, strlen($label)) . " </label><br /> \n"; } } break; case 'radio': if (DevArray::isAssoc($value)) { $output .= ($required ? '*' : '') . $label . '<br />'; $i = 1; foreach ($value as $a => $b) { $output .= '<input ' . $attrib . ' type="radio" ' . $disabled . ' name="' . $name . '" ' . substr_replace($id, $i . '"', -1, strlen($id)); global ${$varname}; if (${$varname} == $b) { $output .= ' checked="checked"'; } $output .= ' value="' . $b . '" />'; $output .= '<label for="' . $varname . $i . '">' . substr($a, 0, strlen($a)) . " </label><br /> \n"; $i++; } } else { foreach ($value as $a) { $output .= '<input type="radio" ' . $disabled . ' name="' . $name . '" ' . $id; global ${$varname}; if (${$varname} == $a) { $output .= ' checked="checked"'; } $output .= ' value="' . $a . '" /> '; $output .= '<label for="' . $varname . '">' . substr($label, 0, strlen($label)) . " </label><br /> \n"; } } break; case 'date': $output .= Form::date($name, $label, $value[0], $readonly); break; case 'calendar': $output .= $label_text . "\n\t" . '<SCRIPT LANGUAGE="JavaScript" ID="js' . $name . '"> var cal' . $name . ' = new CalendarPopup("datediv1"); cal' . $name . '.setCssPrefix("DATE"); </SCRIPT> <SCRIPT LANGUAGE="JavaScript">writeSource("js' . $name . '");</SCRIPT> <input type="text" ' . $disabled . ' name="' . $name . '" ' . $id . ' value="' . $value[0] . '" ' . $attrib . ' /> <A HREF="#" onclick="cal' . $name . '.select(document.getElementById(\'' . $name . '\'),\'anchor' . $name . '\',\'yyyy-MM-dd\'); return false;" TITLE="cal' . $name . '.select(document.getElementById(\'' . $id . '\'),\'anchor1x\',\'yyyy-MM-dd\'); return false;" NAME="anchor' . $name . '" ID="anchor' . $name . '"><img src="' . $image_path . 'calendar.gif" alt="select" title="select" border="0" /></A><br />'; break; case 'time': $output .= Form::date($name, $label); break; case 'file': foreach ($value as $a) { if (!$readonly && $a == '') { $output .= $label_text . ' - ' . $a . ' <br />' . "\n\t" . '<input type="file" ' . $disabled . ' name="' . $name . '" ' . $id . ' /><br />'; } else { $output = Form::field('checkbox', $name, $label . ' (' . $a . ')', $a, $required, $name, $readonly, $properties); } } break; case 'richtext': foreach ($value as $a) { //Code provided by Kevin Roth at www.kevinroth.com/rte/demo.htm //Requires following form header: /* <script language="JavaScript" type="text/javascript"> <!-- function submitForm() { //make sure hidden and iframe values are in sync before submitting form //to sync only 1 rte, use updateRTE(rte) //to sync all rtes, use updateRTEs //updateRTE(\'rte1\'); updateRTEs(); //change the following line to true to submit form return true; } //Usage: initRTE(imagesPath, includesPath, cssFile, genXHTML) initRTE("images/", "", "", true); //--> </script> */ //and included JS file and 'onsubmit="return submitForm();"' in form. $output .= ' <noscript>'; $output .= Form::field('textarea', $name, $label, $a, '', $id, $readonly); $output .= ' </noscript> <script language="JavaScript" type="text/javascript"> <!-- var ' . $name . '_val = ""; '; //$output .= "\n"; $a = html_entity_decode($a); $val_search = array('"', '</script>', '</textarea>', '</noscript>'); $val_replace = array('\\"', '</script>', '</textarea>', '</noscript>'); $a = str_replace($val_search, $val_replace, $a); $val_array = explode("\n", $a); //foreach ($val_array as $a) $output .= $name . '_val += "' . html_entity_decode(rtrim($a)) . '\n";' . "\n"; foreach ($val_array as $var) { $output .= $name . '_val += "' . rtrim($var) . '\\n";' . "\n"; } $output .= ' //--> </script> '; //$output .= Form::field('hidden', $name . '_hidden', '', $a); if ($id == 'id="big"') { $w = '100%'; $h = 400; } else { $w = 450; $h = 200; } $output .= ' <script language="JavaScript" type="text/javascript"> <!-- ' . $name . '_val = ' . $name . '_val.replace(/<\\/script>/gi, "<" + "/script>"); ' . $name . '_val = ' . $name . '_val.replace(/<\\/textarea>/gi, "<" + "/textarea>"); ' . $name . '_val = ' . $name . '_val.replace(/<\\/noscript>/gi, "<" + "/noscript>"); writeRichText(\'' . $name . '\', ' . $name . '_val, \'' . $w . '\', \'' . $h . '\', true, ' . ($readonly ? 'true' : 'false') . '); //--> </script> '; } break; case 'static': foreach ($value as $a) { $output .= $label . '<br /><span ' . implode(' ', $attribs) . ' name="' . $name . '" ' . $id . '>' . $a . '</span>'; $output .= Form::field('hidden', $name, '', $a); } break; case 'submit': foreach ($value as $a) { $output .= '<input type="submit" ' . $disabled . ' name="' . $name . '" ' . $id . ' value="' . $a . '" onclick="this.disabled=false;this.value=' . htmlentities($label != '' ? $label : 'Submitting...') . ';" ' . $attrib . ' /><br />'; } break; case 'reset': foreach ($value as $a) { $output .= '<input type="reset" ' . $disabled . ' name="' . $name . '" ' . $id . ' value="' . $a . '" ' . $attrib . ' /><br />'; } break; case 'button': foreach ($value as $a) { $output .= '<input type="button" ' . $disabled . ' name="' . $name . '" ' . $id . ' value="' . $a . '" ' . $attrib . ' /><br />'; } break; } if ($label != '' && $type != 'hidden') { $output .= "<br />\n"; } return $output; }
public function render() { $header = $this->config('headers'); $trunc = $this->config('truncate'); $file_dir = $this->config('document_dir'); $cols = $this->config('columns'); $link_style = $this->config('link_style'); // $href = $this->config('href'); // $fields = $this->config('fields'); $query_r = $this->config('query'); $content_r = $this->content(); extract($this->_config); $hori = 0; $output = '<table class="dev_table"' . ($header === false ? '' : ' id="anyid"') . '>'; $bg = false; $href = HTML::href($href); $count = 0; $new_row = 1; foreach ($content_r as $row) { $fields = $fields != '' && $fields >= 0 && $fields < count($row) ? $fields : count($row); if ($count == 0) { if ($header !== false) { $header = is_array($header) && count($header) == count($row) ? $header : $row; if (DevArray::isAssoc($header)) { $header = array_keys($header); } $output .= '<tr>'; $i = 0; foreach ($header as $a) { if ($i == 0 && $link_style != 1 && $link_style !== 0) { $output .= '<th>'; $output .= ''; $output .= "</th>"; } if ($i > 0) { $output .= '<th>'; $output .= $a; $output .= "</th>"; } $i++; if ($i > $fields) { break; } } $output .= "</tr>\n"; } } //manage columns if ($hori == 0) { $output .= '<tr>'; } $i = 0; foreach ($row as $a => $b) { if ($i > 0 || $header === false && $link_style != 1) { if (!($icon != '' && $fields == 2 && $i == 2)) { $output .= '<td>'; } if (($i == 1 || $icon != '' && ($i = 2)) && $link_style == 1) { $output .= '<a class="contentBox" href="' . $href . '?' . $varname . '=' . $value . (DevArray::isAssoc($query_r) ? '&' . http_build_query($query_r) : '') . '">'; } if (!$show_image || $trunc != '') { $data = HTML::format($b, '', $trunc); } else { $data = $b; } if ($i != 1) { $data = HTML::file($data, $file_dir); } if ($icon != '' && $i == 1) { $data = HTML::image($data == '' ? $icon : $data, $img_dir, '', '50', '', '', '', '', '', $icon) . ($fields == 1 ? "<br />" . $data : ''); } elseif ($show_image) { $data = HTML::image($data, $img_dir, $data, '100', '', true, '', false); } $output .= $data; if ($i == 1 && $link_style == 1) { $output .= "</a>"; } if (!($icon != '' && $fields == 2 && $i == 1)) { $output .= "</td>"; } } elseif ($i == 0) { if ($link_style == 2) { $output .= '<td>'; $output .= Form::open($href) . Form::field('hidden', $a, '', $b) . Form::field('submit', 'submit', '', 'Go'); if (DevArray::isAssoc($query_r)) { foreach ($query_r as $c => $d) { $output .= Form::feld('hidden', $c, '', $d); } } $output .= Form::close(); $output .= "</td>"; } elseif ($link_style == 3) { $output .= '<td>'; $output .= Form::field('checkbox', $a . '[]', '', $b); if (DevArray::isAssoc($query_r)) { foreach ($query_r as $c => $d) { $output .= Form::field('hidden', $c, '', $d); } } $output .= "</td>"; } else { $varname = $a; $value = $b; } } $i++; if ($i > $fields) { break; } } $output .= "\n"; if ($hori < $cols) { $hori++; } else { $output .= "</tr>\n"; $hori = 0; } $count++; } if ($hori != 0) { $output .= "</tr>\n"; } $output .= "</table>\n"; return $output; }