summaryrefslogtreecommitdiff
path: root/includes/sys_template.php
blob: 06d5ef720069438099dbbb871b12bc38ec97cdbd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?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;.');
	}
}

function table_body($array) {
	$html = "";
	foreach ($array as $line) {
		$html .= "<tr>";
		if (is_array($line)) {
			foreach ($line as $td)
				$html .= "<td>" . $td . "</td>";
		} else {
			$html .= "<td>" . $line . "</td>";
		}
		$html .= "</tr>";
	}
	return $html;
}

function html_options($name, $options, $selected = "") {
	$html = "";
	foreach ($options as $value => $label)
		$html .= '<input type="radio"' . ($value == $selected ? ' checked="checked"' : '') . ' name="' . $name . '" value="' . $value . '"> ' . $label;

	return $html;
}

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;
}
?>