3 # function mask_fields($list)
7 # foreach ($list as $field => $data)
13 function build_form($name, $mask)
18 $jscode[] = 'Rico.onLoad( function() {';
19 $jscode[] = "form_init();";
22 $ret[] = '<div class="form">';
23 if (empty($mask['edit_title']))
24 $ret[] = '<p class="title">Datensatz bearbeiten</p>';
26 $ret[] = sprintf('<p class="title">%s</p>', $mask['edit_title']);
27 $ret[] = '<form id="form_edit">';
29 $ret[] = '<input type="hidden" id="edit_id" name="id" value="">';
30 $ret[] = sprintf('<input type="hidden" id="edit_source" name="source" value="%s">', $name);
32 foreach ($mask['edit'] as $id => $info) {
33 if ($info['type'] == 'hidden') {
34 $ret[] = sprintf('<input type="hidden" id="edit_%s" name="%s">', $id, $id);
35 } else if ($info['type'] == 'text' || $info['type'] == 'passwd' ||
36 $info['type'] == 'decimal' || $info['type'] == 'number') {
37 $v = array('id="edit_'.$id.'"',
39 $v[] = 'size="'.(empty($info['size'])?'10':$info['size']).'"';
40 $v[] = 'type="'.($info['type']=='passwd'?'password':'text').'"';
41 $ret[] = sprintf('<label for="edit_%s">%s</label><br>', $id, $info['name']);
42 $ret[] = sprintf('<input %s>', implode(' ', $v));
43 } elseif ($info['type'] == 'date') {
44 $ret[] = sprintf('<label for="edit_%s">%s</label><br>', $id, $info['name']);
45 $ret[] = sprintf('<input id="edit_%s" name="%s" size="8"> '.
46 '<img class="calendar" src="images/icons/calendar.gif" onclick="calendar(\'edit_%s\',event)" />',
48 } elseif ($info['type'] == 'boolean') {
49 $ret[] = sprintf('<label for="edit_%s">%s</label><br>', $id, $info['name']);
50 $ret[] = sprintf('<input type="checkbox" id="edit_%s" name="%s">', $id, $id);
51 } elseif ($info['type'] == 'select') {
52 $v = array('id="edit_'.$id.'"',
54 if (array_key_exists('onchange',$info))
55 $v[] = sprintf('onchange="%s"', $info['onchange']);
57 $ret[] = sprintf('<label for="edit_%s">%s</label><br>', $id, $info['name']);
58 $ret[] = sprintf('<select %s>', implode(' ', $v));
59 if (is_array($info['options'])) $options = $info['options'];
60 else $options = query_db($info['options']);
61 foreach ($options as $row)
62 $ret[] = sprintf('<option value="%s">%s</option>', $row['id'], $row['text']);
64 } elseif ($info['type'] == 'textarea') {
65 $ret[] = sprintf('<label for="edit_%s">%s</label><br>', $id, $info['name']);
66 $v = array('id="edit_'.$id.'"',
68 $v[] = sprintf('cols="%d"', empty($info['columns'])?33:$info['columns']);
69 $v[] = sprintf('rows="%d"', empty($info['rows'])?5:$info['columns']);
70 $ret[] = sprintf('<textarea %s></textarea>', implode(' ', $v));
72 if (array_key_exists('comment',$info))
73 $ret[] = sprintf('<span class="comment">%s</span>', $info['comment']);
74 if ($info['type'] != 'hidden')
78 $ret[] = '<span id="form_status"> </span>';
79 $ret[] = '<div class="buttons">';
80 $ret[] = '<button id="button_save" onclick="return form_save(this);">Speichern</button>';
81 $ret[] = '<span></span>';
82 $ret[] = '<button id="button_insert" onclick="return form_insert(this);">Hinzufügen</button>';
83 $ret[] = '<span></span>';
84 $ret[] = '<button id="button_delete" onclick="return form_delete(this);">Löschen</button>';
93 function build_grid($name, $mask)
98 $jscode[] = 'Rico.writeDebugMsg = function(msg, resetFlag) {};';
100 $opts = array("click: gridDrillDown",
101 "menuEvent: 'contextmenu'",
102 "highlightElem: 'menuRow'");
104 if (array_key_exists('rows', $mask)) $opts[] = 'visibleRows: ' . $mask['rows'];
105 if (array_key_exists('sort', $mask)) $opts[] = 'sortCol: ' . $mask['sort'];
106 if ($mask['prefetch'] === false) $opts[] = 'prefetch: false';
107 # $opts[] = 'frozenColumns: ' . count($mask['list']);
108 $opts[] = 'saveColumnInfo: {width: true, filter: true, sort: true}';
110 $ret[] = sprintf('<table id="grid_%s" class="ricoLiveGrid">', $name);
114 foreach ($mask['list'] as $field => $data) {
115 $ret[] = sprintf(' <th>%s</th>', $data['name']);
116 $s = array(sprintf("FieldName: 'input_%s'", $field),
117 sprintf("ColName: 'input_%s'", $data['name']));
119 if ($data['visible'] === false) $s[] = 'visible: false';
120 if ($data['width'] > 0) $s[] = 'width: ' . $data['width'];
121 if (array_key_exists('type', $data)) $s[] = "type: '" . $data['type'] . "'";
122 if (array_key_exists('specs', $data)) $s[] = $data['specs'];
123 if (array_key_exists('control', $data)) $s[] = 'control: ' . $data['control'];
124 $specs[] = '{' . implode(', ', $s) . '}';
126 if (array_key_exists('sql', $data))
127 $fields[] = $data['sql'] . ' AS ' . $field;
132 grid_sql($name, $mask);
137 $opts[] = 'columnSpecs: [' . implode(', ', $specs) . ']';
139 if (strstr($opts[count($opts)-1], 'filterUI') !== false) $opts[] = 'FilterLocation: -1';
141 $jscode[] = 'var grid;';
142 $jscode[] = 'Rico.onLoad( function() {';
143 $jscode[] = sprintf("var %s_opts = {\n %s\n};", $name, implode(",\n ", $opts));
144 $jscode[] = sprintf("grid = new Rico.LiveGrid ('grid_%s', new Rico.Buffer.AjaxSQL('ajax/ricoXMLquery.php'), %s_opts);", $name, $name);
145 $jscode[] = "grid.menu = new Rico.GridMenu();";
146 $jscode[] = "grid.edit = new Rico.TableEdit(grid);";
148 $jscode[] = "Rico.acceptLanguage('de-de,de;q=0.8,en;q=0.5,en-us;q=0.3');";
149 $jscode[] = "Rico.loadModule('Effect','Calendar','LiveGridForms','LiveGridAjax','LiveGridMenu');";
154 function build_details($name, $details)
158 $ret[] = '<div class="box" id="details">';
159 $ret[] = sprintf('<h3>%s</h3>', $details['title']);
160 if (array_key_exists('subtitle', $details))
161 $ret[] = sprintf('<p class="subtitle">%s</p>', $details['subtitle']);
162 if (array_key_exists('html',$details)) {
163 $ret[] = $details['html'];
164 } elseif (array_key_exists('list',$details)) {
166 foreach ($details['list'] as $name => $info) {
167 $ret[] = sprintf('<li>%s: <span id="detail_%s"></span></li>', $info['name'], $name);
176 function build_select($name, $details)
180 $ret[] = '<div class="form">';
181 $ret[] = sprintf('<p class="title">%s</p>', $details['title']);
182 $ret[] = sprintf ('<select%s>', array_key_exists('onchange',$details)?sprintf(' onchange="%s"',$details['onchange']):'');
183 if (is_array($details['options']))
184 $options = $details['options'];
186 $options = query_db($details['options']);
188 if (array_key_exists('default',$details))
189 $ret[] = sprintf('<option value="">%s</option>', $details['default']);
191 foreach ($options as $row) {
192 $selected = array_key_exists('selected',$details) && $details['selected'] == $row['id'] ? true : false;
193 $ret[] = sprintf('<option value="%s"%s>%s</option>', $row['id'], $selected?' selected':'',$row['text']);
196 $ret[] = '</select>';
202 function build_mask($name, $mask)
204 $grid = build_grid($name, $mask);
205 $status = array('<span id="status"></span><br>');
207 if (array_key_exists('details', $mask))
208 $details = build_details($name, $mask['details']);
212 if (array_key_exists('select', $mask))
213 $select = build_select($name, $mask['select']);
217 if (array_key_exists('edit', $mask))
218 $edit = build_form($name, $mask);
222 $title = $mask['title'];
223 if (array_key_exists('subtitle', $mask))
224 $title .= ' – ' . $mask['subtitle'];
227 $head[] = sprintf('<h3>%s</h3>', $title);
228 $head[] = '<div class="right">';
230 return array_merge($head,
232 array('</div>','<div class="left">'),
247 if (load_mask($name) === false)
250 $jsfiles[] = 'lib/functions.js';
251 $jsfiles[] = 'lib/rico/rico.js';
253 if (array_key_exists('table',$mask) && array_key_exists('list',$mask))
254 $ret = build_mask($name, $mask);
256 return sprintf('<span id="source" style="display: none;">%s</span>', $_GET['mask'])
257 . implode("\n", $ret);