";
foreach ($items as $key => $item) {
$id = $name . '_' . $key;
$sel = array_search($key, $selected) !== false ? ' checked="checked"' : "";
$html .= '
';
}
$html .= "";
return form_element($label, $html);
}
/**
* Rendert eine Checkbox
*/
function form_checkbox($name, $label, $selected, $value = 'checked') {
return form_element("", '');
}
/**
* Rendert einen Infotext in das Formular
*/
function form_info($label, $text) {
return form_element($label, $text, "");
}
/**
* Rendert den Absenden-Button eines Formulars
*/
function form_submit($name, $label) {
return form_element('', "");
}
/**
* Rendert ein Formular-Textfeld
*/
function form_text($name, $label, $value, $disabled = false) {
$disabled = $disabled ? ' disabled="disabled"' : '';
return form_element($label, '', 'form_' . $name);
}
/**
* Rendert ein Formular-Passwortfeld
*/
function form_password($name, $label, $disabled = false) {
$disabled = $disabled ? ' disabled="disabled"' : '';
return form_element($label, '', 'form_' . $name);
}
/**
* Rendert ein Formular-Textfeld
*/
function form_textarea($name, $label, $value, $disabled = false) {
$disabled = $disabled ? ' disabled="disabled"' : '';
return form_element($label, '', 'form_' . $name);
}
/**
* Rendert ein Formular-Auswahlfeld
*/
function form_select($name, $label, $values, $selected) {
return form_element($label, html_select_key('form_' . $name, $name, $values, $selected), 'form_' . $name);
}
/**
* Rendert ein Formular-Element
*/
function form_element($label, $input, $for = "") {
return '';
}
/**
* Rendert ein Formular
*/
function form($elements, $action = "") {
return '';
}
/**
* Generiert HTML Code für eine "Seite". Fügt dazu die übergebenen Elemente zusammen.
*/
function page($elements) {
return join($elements);
}
/**
* Rendert eine Datentabelle
*/
function table($columns, $rows, $data = true) {
if (count($rows) == 0)
return info("No data available.", true);
$html = "";
$html .= '';
$html .= '';
foreach ($columns as $key => $column)
$html .= '' . $column . ' | ';
$html .= '
';
$html .= '';
foreach ($rows as $row) {
$html .= '';
foreach ($columns as $key => $column)
if (isset ($row[$key]))
$html .= '' . $row[$key] . ' | ';
else
$html .= ' | ';
$html .= '
';
}
$html .= '';
$html .= '
';
return $html;
}
/**
* Rendert einen Knopf
*/
function button($href, $label, $class = "") {
return '' . $label . '';
}
/**
* Rendert eine Toolbar mit Knöpfen
*/
function buttons($buttons = array ()) {
return '' . join($buttons) . '
';
}
// Load and render template
function template_render($file, $data) {
if (file_exists($file)) {
$template = file_get_contents($file);
if (is_array($data))
foreach ($data as $name => $content) {
$template = str_replace("%" . $name . "%", $content, $template);
}
return $template;
} else {
die('Cannot find template file «' . $file . '».');
}
}
function shorten($str) {
if (strlen($str) < 50)
return $str;
return '' . substr($str, 0, 47) . '...';
}
function table_body($array) {
$html = "";
foreach ($array as $line) {
$html .= "";
if (is_array($line)) {
foreach ($line as $td)
$html .= "" . $td . " | ";
} else {
$html .= "" . $line . " | ";
}
$html .= "
";
}
return $html;
}
function html_options($name, $options, $selected = "") {
$html = "";
foreach ($options as $value => $label)
$html .= ' ' . $label;
return $html;
}
function html_select_key($id, $name, $rows, $selected) {
$html = '';
return $html;
}
?>