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>%s</option>',
64 !empty($info['selected']) && $row['id'] == $info['selected'] ? ' selected' : '',
67 } elseif ($info['type'] == 'textarea') {
68 $ret[] = sprintf('<label for="edit_%s">%s</label><br>', $id, $info['name']);
69 $v = array('id="edit_'.$id.'"',
71 $v[] = sprintf('cols="%d"', empty($info['columns'])?33:$info['columns']);
72 $v[] = sprintf('rows="%d"', empty($info['rows'])?5:$info['columns']);
73 $ret[] = sprintf('<textarea %s></textarea>', implode(' ', $v));
75 if (array_key_exists('comment',$info))
76 $ret[] = sprintf('<span class="comment">%s</span>', $info['comment']);
77 if ($info['type'] != 'hidden')
81 $ret[] = '<span id="form_status"> </span>';
82 $ret[] = '<div class="buttons">';
83 $ret[] = '<button id="button_save" onclick="return form_save(this);">Speichern</button>';
84 $ret[] = '<span></span>';
85 $ret[] = '<button id="button_insert" onclick="return form_insert(this);">Hinzufügen</button>';
86 $ret[] = '<span></span>';
87 $ret[] = '<button id="button_delete" onclick="return form_delete(this);">Löschen</button>';
96 function build_grid($name, $mask)
101 $jscode[] = 'Rico.writeDebugMsg = function(msg, resetFlag) {};';
103 $opts = array("click: gridDrillDown",
104 "menuEvent: 'contextmenu'",
105 "highlightElem: 'menuRow'");
107 if (array_key_exists('rows', $mask)) $opts[] = 'visibleRows: ' . $mask['rows'];
108 if (array_key_exists('sort', $mask)) $opts[] = 'sortCol: ' . $mask['sort'];
109 if ($mask['prefetch'] === false) $opts[] = 'prefetch: false';
110 # $opts[] = 'frozenColumns: ' . count($mask['list']);
111 $opts[] = 'saveColumnInfo: {width: true, filter: true, sort: true}';
113 $ret[] = sprintf('<table id="grid_%s" class="ricoLiveGrid">', $name);
117 foreach ($mask['list'] as $field => $data) {
118 $ret[] = sprintf(' <th>%s</th>', $data['name']);
119 $s = array(sprintf("FieldName: 'input_%s'", $field),
120 sprintf("ColName: 'input_%s'", $data['name']));
122 if ($data['visible'] === false) $s[] = 'visible: false';
123 if ($data['width'] > 0) $s[] = 'width: ' . $data['width'];
124 if (array_key_exists('type', $data)) $s[] = "type: '" . $data['type'] . "'";
125 if (array_key_exists('specs', $data)) $s[] = $data['specs'];
126 if (array_key_exists('control', $data)) $s[] = 'control: ' . $data['control'];
127 $specs[] = '{' . implode(', ', $s) . '}';
129 if (array_key_exists('sql', $data))
130 $fields[] = $data['sql'] . ' AS ' . $field;
135 grid_sql($name, $mask);
140 $opts[] = 'columnSpecs: [' . implode(', ', $specs) . ']';
142 if (strstr($opts[count($opts)-1], 'filterUI') !== false) $opts[] = 'FilterLocation: -1';
144 $jscode[] = 'var grid;';
145 $jscode[] = 'Rico.onLoad( function() {';
146 $jscode[] = sprintf("var %s_opts = {\n %s\n};", $name, implode(",\n ", $opts));
147 $jscode[] = sprintf("grid = new Rico.LiveGrid ('grid_%s', new Rico.Buffer.AjaxSQL('ajax/ricoXMLquery.php'), %s_opts);", $name, $name);
148 $jscode[] = "grid.menu = new Rico.GridMenu();";
149 $jscode[] = "grid.edit = new Rico.TableEdit(grid);";
151 $jscode[] = "Rico.acceptLanguage('de-de,de;q=0.8,en;q=0.5,en-us;q=0.3');";
152 $jscode[] = "Rico.loadModule('Effect','Calendar','LiveGridForms','LiveGridAjax','LiveGridMenu');";
157 function build_details($name, $details)
161 $ret[] = '<div class="box" id="details">';
162 $ret[] = sprintf('<h3>%s</h3>', $details['title']);
163 if (array_key_exists('subtitle', $details))
164 $ret[] = sprintf('<p class="subtitle">%s</p>', $details['subtitle']);
165 if (array_key_exists('html',$details)) {
166 $ret[] = $details['html'];
167 } elseif (array_key_exists('list',$details)) {
169 foreach ($details['list'] as $name => $info) {
170 $ret[] = sprintf('<li>%s: <span id="detail_%s"></span></li>', $info['name'], $name);
179 function build_select($name, $details)
183 $ret[] = '<div class="form">';
184 $ret[] = sprintf('<p class="title">%s</p>', $details['title']);
185 $ret[] = sprintf ('<select%s>', array_key_exists('onchange',$details)?sprintf(' onchange="%s"',$details['onchange']):'');
186 if (is_array($details['options']))
187 $options = $details['options'];
189 $options = query_db($details['options']);
191 if (array_key_exists('default',$details))
192 $ret[] = sprintf('<option value="">%s</option>', $details['default']);
194 foreach ($options as $row) {
195 $selected = array_key_exists('selected',$details) && $details['selected'] == $row['id'] ? true : false;
196 $ret[] = sprintf('<option value="%s"%s>%s</option>', $row['id'], $selected?' selected':'',$row['text']);
199 $ret[] = '</select>';
205 function build_mask($name, $mask)
207 $grid = build_grid($name, $mask);
208 $status = array('<span id="status"></span><br>');
210 if (array_key_exists('details', $mask))
211 $details = build_details($name, $mask['details']);
215 if (array_key_exists('select', $mask))
216 $select = build_select($name, $mask['select']);
220 if (array_key_exists('edit', $mask))
221 $edit = build_form($name, $mask);
225 $title = $mask['title'];
226 if (array_key_exists('subtitle', $mask))
227 $title .= ' – ' . $mask['subtitle'];
230 $head[] = sprintf('<h3>%s</h3>', $title);
231 $head[] = '<div class="right">';
233 return array_merge($head,
235 array('</div>','<div class="left">'),
250 if (load_mask($name) === false)
253 $jsfiles[] = 'lib/functions.js';
254 $jsfiles[] = 'lib/rico/rico.js';
256 if (array_key_exists('table',$mask) && array_key_exists('list',$mask))
257 $ret = build_mask($name, $mask);
259 return sprintf('<span id="source" style="display: none;">%s</span>', $_GET['mask'])
260 . implode("\n", $ret);