1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11:
12: class Horde_Core_Ui_VarRenderer_TablesetHtml extends Horde_Core_Ui_VarRenderer_Html
13: {
14: protected function _renderVarInput_tableset($form, &$var, &$vars)
15: {
16: $header = $var->type->getHeader();
17: $name = $var->getVarName();
18: $values = $var->getValues();
19: $form_name = $form->getName();
20: $var_name = $var->getVarName() . '[]';
21: $checkedValues = $var->getValue($vars);
22: $actions = $this->_getActionScripts($form, $var);
23: $function_name = 'select' . $form_name . $var->getVarName();
24: $enable = Horde_Core_Translation::t("Select all");
25: $disable = Horde_Core_Translation::t("Select none");
26: $invert = Horde_Core_Translation::t("Invert selection");
27:
28: Horde::addScriptFile('tables.js', 'horde');
29:
30: $html = <<<EOT
31: <script type="text/javascript">
32: function $function_name()
33: {
34: for (var i = 0; i < document.$form_name.elements.length; i++) {
35: f = document.$form_name.elements[i];
36: if (f.name != '$var_name') {
37: continue;
38: }
39: if (arguments.length) {
40: f.checked = arguments[0];
41: } else {
42: f.checked = !f.checked;
43: }
44: }
45: }
46: </script>
47: <a href="#" onclick="$function_name(true); return false;">$enable</a>,
48: <a href="#" onclick="$function_name(false); return false;">$disable</a>,
49: <a href="#" onclick="$function_name(); return false;">$invert</a>
50: <table style="width: 100%" class="sortable striped" id="tableset_' . $name . '"><thead><tr>
51: <th> </th>
52: EOT;
53:
54: foreach ($header as $col_title) {
55: $html .= sprintf('<th class="leftAlign">%s</th>', $col_title);
56: }
57: $html .= '</tr></thead>';
58:
59: if (!is_array($checkedValues)) {
60: $checkedValues = array();
61: }
62: $i = 0;
63: foreach ($values as $value => $displays) {
64: $checked = (in_array($value, $checkedValues)) ? ' checked="checked"' : '';
65: $html .= '<tr>' .
66: sprintf('<td style="text-align: center"><input id="%s[]" type="checkbox" name="%s[]" value="%s"%s%s /></td>',
67: $name,
68: $name,
69: $value,
70: $checked,
71: $actions);
72: foreach ($displays as $col) {
73: $html .= sprintf('<td> %s</td>', $col);
74: }
75: $html .= '</tr>' . "\n";
76: $i++;
77: }
78:
79: $html .= '</table>'
80: . '<a href="#" onclick="' . $function_name . '(true); return false;">' . $enable . '</a>, '
81: . '<a href="#" onclick="' . $function_name . '(false); return false;">' . $disable . '</a>, '
82: . '<a href="#" onclick="' . $function_name . '(); return false;">' . $invert . '</a>';
83:
84: return $html;
85: }
86:
87: protected function _renderVarDisplay_tableset($form, &$var, &$vars)
88: {
89: $header = $var->type->getHeader();
90: $name = $var->getVarName();
91: $values = $var->getValues();
92: $checkedValues = $var->getValue($vars);
93: $actions = $this->_getActionScripts($form, $var);
94:
95: Horde::addScriptFile('tables.js', 'horde');
96: $html = '<table style="width: 100%" class="sortable striped" id="tableset_' . $name . '"><thead><tr>' .
97: '<th> </th>';
98: foreach ($header as $col_title) {
99: $html .= sprintf('<th class="leftAlign">%s</th>', $col_title);
100: }
101: $html .= '</tr></thead>';
102:
103: if (!is_array($checkedValues)) {
104: $checkedValues = array();
105: }
106: $i = 0;
107: foreach ($values as $value => $displays) {
108: $checked = '[ <span style="font-weight: bold; color: '
109: . (in_array($value, $checkedValues)) ? ' green">V' : 'red">X'
110: . '</span> ]';
111: $html .= '<tr>'.
112: sprintf('<td style="text-align: center">%s</td>', $checked);
113: foreach ($displays as $col) {
114: $html .= '<td> ' . $col . '</td>';
115: }
116: $html .= '</tr>';
117: $i++;
118: }
119:
120: return $html . '</table>';
121: }
122:
123: }
124: