engelsystem/includes/sys_template.php

58 lines
1.4 KiB
PHP
Raw Normal View History

2011-06-02 00:48:29 +02:00
<?php
// 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 &laquo;' . $file . '&raquo;.');
}
}
2011-06-02 16:56:45 +02:00
2011-07-13 14:29:40 +02:00
function shorten($str) {
if (strlen($str) < 50)
return $str;
return substr($str, 0, 47) . '...';
}
2011-07-11 20:40:27 +02:00
function table_body($array) {
$html = "";
foreach ($array as $line) {
$html .= "<tr>";
if (is_array($line)) {
2011-07-11 21:58:06 +02:00
foreach ($line as $td)
$html .= "<td>" . $td . "</td>";
2011-07-11 20:40:27 +02:00
} else {
$html .= "<td>" . $line . "</td>";
}
$html .= "</tr>";
}
return $html;
}
2011-06-02 16:56:45 +02:00
function html_options($name, $options, $selected = "") {
$html = "";
foreach ($options as $value => $label)
2011-06-03 07:44:50 +02:00
$html .= '<input type="radio"' . ($value == $selected ? ' checked="checked"' : '') . ' name="' . $name . '" value="' . $value . '"> ' . $label;
2011-06-02 16:56:45 +02:00
return $html;
}
2011-06-02 20:18:01 +02:00
function html_select_key($name, $rows, $selected) {
$html = '<select name="' . $name . '">';
foreach ($rows as $key => $row)
if (($key == $selected) || ($row == $selected))
$html .= '<option value="' . $key . '" selected="selected">' . $row . '</option>';
else
$html .= '<option value="' . $key . '">' . $row . '</option>';
$html .= '</select>';
return $html;
}
?>