3 # function mask_fields($list)
7 # foreach ($list as $field => $data)
13 function build_form($fields)
17 $ret[] = '<div class="form" style="clear: both;">';
18 $ret[] = '<form id="form_edit">';
20 $ret[] = '<input type="hidden" id="edit_id" name="id" value="">';
22 foreach ($fields as $id => $info) {
23 if ($info['type'] == 'text') {
24 $v = array('id="edit_'.$id.'"',
26 'size="'.$info['size'].'"',
28 $ret[] = sprintf('<label for="edit_%s">%s</label><br>', $id, $info['name']);
29 $ret[] = sprintf('<input %s><br>', implode(' ', $v));
30 } elseif ($info['type'] == 'select') {
31 $ret[] = sprintf('<label for="edit_%s">%s</label><br>', $id, $info['name']);
32 $ret[] = sprintf('<select id="edit_%s" name="%s">', $id, $id);
33 if (is_array($info['options'])) $options = $info['options'];
34 else $options = query_db($info['options']);
35 foreach ($options as $row)
36 $ret[] = sprintf('<option value="%s">%s</option>', $row['id'], $row['text']);
37 $ret[] = '</select><br>';
39 error_log('type = select');
40 } elseif ($info['type'] == 'date') {
41 error_log('type = date');
45 $ret[] = '<div align="center"><button onclick="return form_save(this);">Speichern</button></div>';
53 function build_grid($name, $mask)
58 $jscode[] = 'Rico.writeDebugMsg = function(msg, resetFlag) {};';
60 $opts = array("click: gridDrillDown",
61 "menuEvent: 'contextmenu'",
62 "highlightElem: 'menuRow'");
64 if (array_key_exists('rows', $mask)) $opts[] = 'visibleRows: ' . $mask['rows'];
65 if (array_key_exists('sort', $mask)) $opts[] = 'sortCol: ' . $mask['sort'];
66 if ($mask['prefetch'] === false) $opts[] = 'prefetch: false';
67 # $opts[] = 'frozenColumns: ' . count($mask['list']);
68 $opts[] = 'saveColumnInfo: {width: true, filter: true, sort: true}';
70 $ret[] = sprintf('<table id="grid_%s" class="ricoLiveGrid">', $name);
74 foreach ($mask['list'] as $field => $data) {
75 $ret[] = sprintf(' <th>%s</th>', $data['name']);
76 $s = array(sprintf("FieldName: 'input_%s'", $field),
77 sprintf("ColName: 'input_%s'", $data['name']));
79 if ($data['visible'] === false) $s[] = 'visible: false';
80 if ($data['width'] > 0) $s[] = 'width: ' . $data['width'];
81 if (array_key_exists('type', $data)) $s[] = "type: '" . $data['type'] . "'";
82 if (array_key_exists('specs', $data)) $s[] = $data['specs'];
83 $specs[] = '{' . implode(', ', $s) . '}';
85 if (array_key_exists('sql', $data))
86 $fields[] = $data['sql'] . ' AS ' . $field;
90 $_SESSION['grid_' . $name] = sprintf("SELECT %s FROM %s",
91 implode(',', $fields), $mask['table']);
92 if (array_key_exists('join', $mask)) $_SESSION['grid_' . $name] .= ' JOIN ' . join(' JOIN ', $mask['join']);
93 if (array_key_exists('where', $mask)) $_SESSION['grid_' . $name] .= ' WHERE ' . $mask['where'];
98 $opts[] = 'columnSpecs: [' . implode(', ', $specs) . ']';
100 if (strstr($opts[count($opts)-1], 'filterUI') !== false) $opts[] = 'FilterLocation: -1';
102 $jscode[] = 'var grid;';
103 $jscode[] = 'Rico.onLoad( function() {';
104 $jscode[] = sprintf("var %s_opts = {\n %s\n};", $name, implode(",\n ", $opts));
105 $jscode[] = sprintf("grid = new Rico.LiveGrid ('grid_%s', new Rico.Buffer.AjaxSQL('ajax/ricoXMLquery.php'), %s_opts);", $name, $name);
106 $jscode[] = "grid.menu = new Rico.GridMenu();";
107 $jscode[] = "grid.edit = new Rico.TableEdit(grid);";
109 $jscode[] = "Rico.acceptLanguage('de-de,de;q=0.8,en;q=0.5,en-us;q=0.3');";
110 $jscode[] = "Rico.loadModule('Effect','Calendar','LiveGridForms','LiveGridAjax','LiveGridMenu');";
115 function build_details($name, $details)
120 $ret[] = '<div class="box" id="details">';
121 $ret[] = sprintf('<h3>%s</h3>', $details['title']);
122 if (array_key_exists('subtitle', $details))
123 $ret[] = sprintf('<p class="subtitle">%s</p>', $details['subtitle']);
125 foreach ($details['list'] as $name => $info) {
126 $ret[] = sprintf('<li>%s: <span id="detail_%s"></span></li>', $info['name'], $name);
134 function build_mask($name, $mask)
136 $grid = build_grid($name, $mask);
138 if (array_key_exists('details', $mask))
139 $details = build_details($name, $mask['details']);
143 $title = $mask['title'];
144 if (array_key_exists('subtitle', $mask))
145 $title .= ' – ' . $mask['subtitle'];
148 $head[] = sprintf('<h3>%s</h3>', $title);
149 $head[] = '<div class="right">';
151 return array_merge($head,
153 array('</div>','<div class="left">'),
165 if (load_mask($name) === false)
168 $jsfiles[] = 'lib/functions.js';
169 $jsfiles[] = 'lib/rico/rico.js';
171 if (array_key_exists('table',$mask) && array_key_exists('list',$mask))
172 $ret = build_mask($name, $mask);
174 if (array_key_exists('edit', $mask))
175 $ret = array_merge($ret, build_form($mask['edit']));
177 return implode("\n", $ret);