init
[garradin.git] / include / libs / template_lite / plugins / function.html_checkboxes.php
1 <?php
2 /**
3 * Template_Lite {html_checkbox} function plugin
4 *
5 * Type: function
6 * Name: textbox
7 * Purpose: Creates a checkbox
8 * Input:
9 * - name = the name of the checkbox
10 * - value = optional value for the checkbox
11 * - checked = boolean - whether the box is checked or not
12 * Author: Paul Lockaby <paul@paullockaby.com>
13 */
14 function tpl_function_html_checkboxes($params, &$tpl)
15 {
16 require_once("shared.escape_chars.php");
17 $name = null;
18 $value = null;
19 $checked = null;
20 $extra = '';
21
22 foreach($params as $_key => $_value)
23 {
24 switch($_key)
25 {
26 case 'name':
27 case 'value':
28 $$_key = $_value;
29 break;
30 case 'checked':
31 if ($_key == 'true' || $_key == 'yes' || $_key == 'on')
32 {
33 $$_key = true;
34 }
35 else
36 {
37 $$_key = false;
38 }
39 break;
40 default:
41 if(!is_array($_key))
42 {
43 $extra .= ' ' . $_key . '="' . tpl_escape_chars($_value) . '"';
44 }
45 else
46 {
47 throw new Template_Exception("html_checkbox: attribute '$_key' cannot be an array", $tpl);
48 }
49 }
50 }
51
52 if (!isset($name) || empty($name))
53 {
54 throw new Template_Exception("html_checkbox: missing 'name' parameter", $tpl);
55 return;
56 }
57
58 $toReturn = '<input type="checkbox" name="' . tpl_escape_chars($name) . '"';
59 if (isset($checked))
60 {
61 $toReturn .= ' checked';
62 }
63 if (isset($value))
64 {
65 $toReturn .= ' value="' . tpl_escape_chars($value) . '"';
66 }
67 $toReturn .= ' ' . $extra . ' />';
68 return $toReturn;
69 }
70 ?>