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 => $data) {
23 if ($data['type'] == 'text') {
24 $v = array('id="edit_'.$id.'"',
26 'size="'.$data['size'].'"',
28 $ret[] = sprintf('<label for="edit_%s"><b>%s</b></label><br>', $id, $data['name']);
29 $ret[] = sprintf('<input %s><br>', implode(' ', $v));
31 } elseif ($data['type'] == 'date') {
32 error_log('type = date');
36 $ret[] = '<div align="center"><button onclick="return form_save(this);">Speichern</button></div>';
44 function mask_grid($name, $mask)
48 $jscode[] = 'Rico.writeDebugMsg = function(msg, resetFlag) {};';
50 $opts = array("click: gridDrillDown",
51 "menuEvent: 'contextmenu'",
52 "highlightElem: 'menuRow'");
54 if (array_key_exists('rows', $mask)) $opts[] = 'visibleRows: ' . $mask['rows'];
55 if (array_key_exists('sort', $mask)) $opts[] = 'sortCol: ' . $mask['sort'];
56 if ($mask['prefetch'] === false) $opts[] = 'prefetch: false';
57 # $opts[] = 'frozenColumns: ' . count($mask['list']);
58 $opts[] = 'saveColumnInfo: {width: true, filter: true, sort: true}';
60 $ret[] = sprintf('<table id="grid_%s" class="ricoLiveGrid">', $name);
64 foreach ($mask['list'] as $field => $data) {
65 $ret[] = sprintf(' <th>%s</th>', $data['name']);
66 $s = array(sprintf("FieldName: 'input_%s'", $field),
67 sprintf("ColName: 'input_%s'", $data['name']));
69 if ($data['visible'] === false) $s[] = 'visible: false';
70 if ($data['width'] > 0) $s[] = 'width: ' . $data['width'];
71 if (array_key_exists('type', $data)) $s[] = "type: '" . $data['type'] . "'";
72 if (array_key_exists('specs', $data)) $s[] = $data['specs'];
73 $specs[] = '{' . implode(', ', $s) . '}';
75 if (array_key_exists('sql', $data))
76 $fields[] = $data['sql'] . ' AS ' . $field;
80 $_SESSION['grid_' . $name] = sprintf("SELECT %s FROM %s",
81 implode(',', $fields), $mask['table']);
82 if (array_key_exists('join', $mask)) $_SESSION['grid_' . $name] .= ' JOIN ' . join(' JOIN ', $mask['join']);
87 $opts[] = 'columnSpecs: [' . implode(', ', $specs) . ']';
89 if (strstr($opts[count($opts)-1], 'filterUI') !== false) $opts[] = 'FilterLocation: -1';
91 $jscode[] = 'var grid;';
92 $jscode[] = 'Rico.onLoad( function() {';
93 $jscode[] = sprintf("var %s_opts = {\n %s\n};", $name, implode(",\n ", $opts));
94 $jscode[] = sprintf("grid = new Rico.LiveGrid ('grid_%s', new Rico.Buffer.AjaxSQL('ajax/ricoXMLquery.php'), %s_opts);", $name, $name);
95 $jscode[] = "grid.menu = new Rico.GridMenu();";
96 $jscode[] = "grid.edit = new Rico.TableEdit(grid);";
98 $jscode[] = "Rico.acceptLanguage('de-de,de;q=0.8,en;q=0.5,en-us;q=0.3');";
99 $jscode[] = "Rico.loadModule('Effect','Calendar','LiveGridForms','LiveGridAjax','LiveGridMenu');";
101 if (array_key_exists('edit', $mask))
102 $ret = array_merge($ret, build_form($mask['edit']));
114 if (load_mask($name) === false)
117 $jsfiles[] = 'lib/functions.js';
118 $jsfiles[] = 'lib/rico/rico.js';
120 if (array_key_exists('table',$mask) && array_key_exists('list',$mask)) {
121 $ret = mask_grid($name, $mask);
124 return implode("\n", $ret);