3 # function mask_fields($list)
7 # foreach ($list as $field => $data)
13 function build_form($fields)
17 $ret[] = '<div class="form">';
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"><b>%s</b></label><br>', $id, $info['name']);
29 $ret[] = sprintf('<input %s><br>', implode(' ', $v));
31 } elseif ($info['type'] == 'date') {
32 error_log('type = date');
36 $ret[] = '<div align="center"><button onclick="return form_save(this);">Speichern</button></div>';
44 function build_grid($name, $mask)
49 $jscode[] = 'Rico.writeDebugMsg = function(msg, resetFlag) {};';
51 $opts = array("click: gridDrillDown",
52 "menuEvent: 'contextmenu'",
53 "highlightElem: 'menuRow'");
55 if (array_key_exists('rows', $mask)) $opts[] = 'visibleRows: ' . $mask['rows'];
56 if (array_key_exists('sort', $mask)) $opts[] = 'sortCol: ' . $mask['sort'];
57 if ($mask['prefetch'] === false) $opts[] = 'prefetch: false';
58 # $opts[] = 'frozenColumns: ' . count($mask['list']);
59 $opts[] = 'saveColumnInfo: {width: true, filter: true, sort: true}';
61 $ret[] = sprintf('<table id="grid_%s" class="ricoLiveGrid">', $name);
65 foreach ($mask['list'] as $field => $data) {
66 $ret[] = sprintf(' <th>%s</th>', $data['name']);
67 $s = array(sprintf("FieldName: 'input_%s'", $field),
68 sprintf("ColName: 'input_%s'", $data['name']));
70 if ($data['visible'] === false) $s[] = 'visible: false';
71 if ($data['width'] > 0) $s[] = 'width: ' . $data['width'];
72 if (array_key_exists('type', $data)) $s[] = "type: '" . $data['type'] . "'";
73 if (array_key_exists('specs', $data)) $s[] = $data['specs'];
74 $specs[] = '{' . implode(', ', $s) . '}';
76 if (array_key_exists('sql', $data))
77 $fields[] = $data['sql'] . ' AS ' . $field;
81 $_SESSION['grid_' . $name] = sprintf("SELECT %s FROM %s",
82 implode(',', $fields), $mask['table']);
83 if (array_key_exists('join', $mask)) $_SESSION['grid_' . $name] .= ' JOIN ' . join(' JOIN ', $mask['join']);
84 if (array_key_exists('where', $mask)) $_SESSION['grid_' . $name] .= ' WHERE ' . $mask['where'];
89 $opts[] = 'columnSpecs: [' . implode(', ', $specs) . ']';
91 if (strstr($opts[count($opts)-1], 'filterUI') !== false) $opts[] = 'FilterLocation: -1';
93 $jscode[] = 'var grid;';
94 $jscode[] = 'Rico.onLoad( function() {';
95 $jscode[] = sprintf("var %s_opts = {\n %s\n};", $name, implode(",\n ", $opts));
96 $jscode[] = sprintf("grid = new Rico.LiveGrid ('grid_%s', new Rico.Buffer.AjaxSQL('ajax/ricoXMLquery.php'), %s_opts);", $name, $name);
97 $jscode[] = "grid.menu = new Rico.GridMenu();";
98 $jscode[] = "grid.edit = new Rico.TableEdit(grid);";
100 $jscode[] = "Rico.acceptLanguage('de-de,de;q=0.8,en;q=0.5,en-us;q=0.3');";
101 $jscode[] = "Rico.loadModule('Effect','Calendar','LiveGridForms','LiveGridAjax','LiveGridMenu');";
106 function build_details($name, $details)
111 $ret[] = '<div class="box" id="details">';
112 $ret[] = sprintf('<h3>%s</h3>', $details['title']);
113 if (array_key_exists('subtitle', $details))
114 $ret[] = sprintf('<p class="subtitle">%s</p>', $details['subtitle']);
116 foreach ($details['list'] as $name => $info) {
117 $ret[] = sprintf('<li>%s: <span id="detail_%s"></span></li>', $info['name'], $name);
125 function build_mask($name, $mask)
127 $grid = build_grid($name, $mask);
129 if (array_key_exists('details', $mask))
130 $details = build_details($name, $mask['details']);
134 $title = $mask['title'];
135 if (array_key_exists('subtitle', $mask))
136 $title .= ' – ' . $mask['subtitle'];
139 $head[] = sprintf('<h3>%s</h3>', $title);
140 $head[] = '<div class="right">';
142 return array_merge($head,
144 array('</div>','<div class="left">'),
156 if (load_mask($name) === false)
159 $jsfiles[] = 'lib/functions.js';
160 $jsfiles[] = 'lib/rico/rico.js';
162 if (array_key_exists('table',$mask) && array_key_exists('list',$mask))
163 $ret = build_mask($name, $mask);
165 if (array_key_exists('edit', $mask))
166 $ret = array_merge($ret, build_form($mask['edit']));
168 return implode("\n", $ret);