3 # function mask_fields($list)
7 # foreach ($list as $field => $data)
13 function build_form($name, $fields)
17 $ret[] = '<div class="form">';
18 $ret[] = '<form id="form_edit">';
20 $ret[] = '<input type="hidden" id="edit_id" name="id" value="">';
21 $ret[] = sprintf('<input type="hidden" id="edit_source" name="source" value="%s">', $name);
23 foreach ($fields as $id => $info) {
24 if ($info['type'] == 'text' || $info['type'] == 'passwd' || $info['type'] == 'number') {
25 $v = array('id="edit_'.$id.'"',
27 $v[] = 'size="'.(empty($info['size'])?'10':$info['size']).'"';
28 $v[] = 'type="'.($info['type']=='passwd'?'password':'text').'"';
29 $ret[] = sprintf('<label for="edit_%s">%s</label><br>', $id, $info['name']);
30 $ret[] = sprintf('<input %s><br>', implode(' ', $v));
31 } elseif ($info['type'] == 'boolean') {
32 $ret[] = sprintf('<label for="edit_%s">%s</label><br>', $id, $info['name']);
33 $ret[] = sprintf('<input type="checkbox" id="edit_%s" name="%s"><br>', $id, $id);
34 } elseif ($info['type'] == 'select') {
35 $ret[] = sprintf('<label for="edit_%s">%s</label><br>', $id, $info['name']);
36 $ret[] = sprintf('<select id="edit_%s" name="%s">', $id, $id);
37 if (is_array($info['options'])) $options = $info['options'];
38 else $options = query_db($info['options']);
39 foreach ($options as $row)
40 $ret[] = sprintf('<option value="%s">%s</option>', $row['id'], $row['text']);
41 $ret[] = '</select><br>';
42 } elseif ($info['type'] == 'date') {
43 error_log('type = date');
47 $ret[] = '<span id="form_status"></span>';
48 $ret[] = '<div class="buttons">';
49 $ret[] = '<button id="button_save" onclick="return form_save(this);">Speichern</button>';
50 $ret[] = '<span></span>';
51 $ret[] = '<button id="button_insert" onclick="return form_insert(this);">Hinzufügen</button>';
52 $ret[] = '<span></span>';
53 $ret[] = '<button id="button_delete" onclick="return form_delete(this);">Löschen</button>';
62 function build_grid($name, $mask)
67 $jscode[] = 'Rico.writeDebugMsg = function(msg, resetFlag) {};';
69 $opts = array("click: gridDrillDown",
70 "menuEvent: 'contextmenu'",
71 "highlightElem: 'menuRow'");
73 if (array_key_exists('rows', $mask)) $opts[] = 'visibleRows: ' . $mask['rows'];
74 if (array_key_exists('sort', $mask)) $opts[] = 'sortCol: ' . $mask['sort'];
75 if ($mask['prefetch'] === false) $opts[] = 'prefetch: false';
76 # $opts[] = 'frozenColumns: ' . count($mask['list']);
77 $opts[] = 'saveColumnInfo: {width: true, filter: true, sort: true}';
79 $ret[] = sprintf('<table id="grid_%s" class="ricoLiveGrid">', $name);
83 foreach ($mask['list'] as $field => $data) {
84 $ret[] = sprintf(' <th>%s</th>', $data['name']);
85 $s = array(sprintf("FieldName: 'input_%s'", $field),
86 sprintf("ColName: 'input_%s'", $data['name']));
88 if ($data['visible'] === false) $s[] = 'visible: false';
89 if ($data['width'] > 0) $s[] = 'width: ' . $data['width'];
90 if (array_key_exists('type', $data)) $s[] = "type: '" . $data['type'] . "'";
91 if (array_key_exists('specs', $data)) $s[] = $data['specs'];
92 $specs[] = '{' . implode(', ', $s) . '}';
94 if (array_key_exists('sql', $data))
95 $fields[] = $data['sql'] . ' AS ' . $field;
99 $_SESSION['grid_' . $name] = sprintf("SELECT %s FROM %s",
100 implode(',', $fields), $mask['table']);
101 if (array_key_exists('join', $mask)) $_SESSION['grid_' . $name] .= ' JOIN ' . join(' JOIN ', $mask['join']);
102 if (array_key_exists('where', $mask)) $_SESSION['grid_' . $name] .= ' WHERE ' . $mask['where'];
107 $opts[] = 'columnSpecs: [' . implode(', ', $specs) . ']';
109 if (strstr($opts[count($opts)-1], 'filterUI') !== false) $opts[] = 'FilterLocation: -1';
111 $jscode[] = 'var grid;';
112 $jscode[] = 'Rico.onLoad( function() {';
113 $jscode[] = sprintf("var %s_opts = {\n %s\n};", $name, implode(",\n ", $opts));
114 $jscode[] = sprintf("grid = new Rico.LiveGrid ('grid_%s', new Rico.Buffer.AjaxSQL('ajax/ricoXMLquery.php'), %s_opts);", $name, $name);
115 $jscode[] = "grid.menu = new Rico.GridMenu();";
116 $jscode[] = "grid.edit = new Rico.TableEdit(grid);";
118 $jscode[] = "Rico.acceptLanguage('de-de,de;q=0.8,en;q=0.5,en-us;q=0.3');";
119 $jscode[] = "Rico.loadModule('Effect','Calendar','LiveGridForms','LiveGridAjax','LiveGridMenu');";
124 function build_details($name, $details)
129 $ret[] = '<div class="box" id="details">';
130 $ret[] = sprintf('<h3>%s</h3>', $details['title']);
131 if (array_key_exists('subtitle', $details))
132 $ret[] = sprintf('<p class="subtitle">%s</p>', $details['subtitle']);
134 foreach ($details['list'] as $name => $info) {
135 $ret[] = sprintf('<li>%s: <span id="detail_%s"></span></li>', $info['name'], $name);
143 function build_mask($name, $mask)
145 $grid = build_grid($name, $mask);
146 $status = array('<span id="status"></span><br>');
148 if (array_key_exists('details', $mask))
149 $details = build_details($name, $mask['details']);
153 if (array_key_exists('edit', $mask))
154 $edit = build_form($name, $mask['edit']);
158 $title = $mask['title'];
159 if (array_key_exists('subtitle', $mask))
160 $title .= ' – ' . $mask['subtitle'];
163 $head[] = sprintf('<h3>%s</h3>', $title);
164 $head[] = '<div class="right">';
166 return array_merge($head,
168 array('</div>','<div class="left">'),
182 if (load_mask($name) === false)
185 $jsfiles[] = 'lib/functions.js';
186 $jsfiles[] = 'lib/rico/rico.js';
188 if (array_key_exists('table',$mask) && array_key_exists('list',$mask))
189 $ret = build_mask($name, $mask);
191 error_log(count($ret));
192 return implode("\n", $ret);