function occindex($content = null)
 {
     if (is_array($content)) {
         if ($content['nm']['rows']['delete']) {
             list($id) = each($content['nm']['rows']['delete']);
             unset($content['nm']['rows']['delete']);
             if ($this->occ->delete(array('cp_occ_id' => $id))) {
                 $content['msg'] = lang('Occurence deleted');
             } else {
                 $content['msg'] = lang('Delete failed!');
             }
         }
     } else {
         $content['msg'] = $_GET['msg'];
     }
     // initializing of thwe nextmatch widget, through reading of stored sessiondata
     $content['nm'] = $GLOBALS['egw']->session->appsession('occ_session_data', 'courseprotocol');
     $content['nm'] = array('get_rows' => 'courseprotocol.uicourseprotocol.get_rows_occ', 'filter_label' => '', 'filter_help' => '', 'no_filter' => True, 'no_filter2' => True, 'never_hide' => True, 'lettersearch' => False, 'searchletter' => '', 'start' => 0, 'order' => 'cp_occ_date', 'sort' => 'DESC', 'col_filter' => array(), 'default_cols' => '!cp_occ_analy');
     $content['msg'] = $_GET['msg'];
     //_debug_array($content);
     $this->tmpl->read('courseprotocol.occindex');
     $this->tmpl->set_cell_attribute('debuginfo', 'disabled', !$debug);
     $this->tmpl->set_cell_attribute('myhrule', 'disabled', !$separator);
     $this->tmpl->exec('courseprotocol.uicourseprotocol.occindex', $content, array('cp_occ_type' => $this->oc_types), array(), $preserv);
     // the debug info will be displayed at the very end of the page
     //_debug_array($content);
 }
 function needs_save($cont = '', $posted_app = '', $posted_table = '', $edited_table = '')
 {
     if (!$posted_app && is_array($cont)) {
         if (isset($cont['yes'])) {
             $this->app = $cont['app'];
             $this->table = $cont['table'];
             $this->read($this->app, $this->data);
             $this->data[$this->table] = $cont['edited_table'];
             $this->changes = $cont['changes'];
             if ($cont['new_version']) {
                 $this->update($this->app, $this->data, $cont['new_version']);
             } else {
                 foreach ($this->data as $tname => $tinfo) {
                     $tables .= ($tables ? ',' : '') . "'{$tname}'";
                 }
                 $this->setup_version($this->app, '', $tables);
             }
             $msg .= $this->write($this->app, $this->data) ? lang('File writen') : lang('Error: writing file (no write-permission for the webserver) !!!');
         }
         $this->changes = array();
         // return to edit with everything set, so the user gets the table he asked for
         $this->edit(array('app' => $cont['new_app'], 'table_name' => $cont['app'] == $cont['new_app'] ? $cont['new_table'] : '', 'posted_app' => $cont['new_app']), $msg);
         return True;
     }
     $new_app = $this->app;
     // these are the ones, the users whiches to change too
     $new_table = $this->table;
     $this->app = $posted_app;
     $this->data = array();
     $this->read($posted_app, $this->data);
     if (isset($this->data[$posted_table]) && $this->tables_identical($this->data[$posted_table], $edited_table)) {
         if ($new_app != $this->app) {
             $this->app = $new_app;
             // if we change init the data empty
             $this->data = array();
         }
         return False;
         // continue edit
     }
     $content = array('app' => $posted_app, 'table' => $posted_table, 'version' => $this->setup_version($posted_app));
     $preserv = $content + array('new_app' => $new_app, 'new_table' => $new_table, 'edited_table' => $edited_table, 'changes' => $this->changes);
     $new_version = explode('.', $content['version']);
     $minor = count($new_version) - 1;
     $new_version[$minor] = sprintf('%03d', 1 + $new_version[$minor]);
     $content['new_version'] = implode('.', $new_version);
     $tmpl = new etemplate('etemplate.db-tools.ask_save');
     if (!file_exists(PHPGW_SERVER_ROOT . "/{$posted_app}/setup/tables_current.inc.php")) {
         $tmpl->disable_cells('version');
         $tmpl->disable_cells('new_version');
     }
     $tmpl->exec('etemplate.db_tools.needs_save', $content, array(), array(), $preserv);
     return True;
     // dont continue in edit
 }
 function show($post_vars = '')
 {
     if ($this->debug) {
         echo "<p>etemplate.editor.show: content=";
         _debug_array($post_vars);
     }
     if (!is_array($post_vars)) {
         $post_vars = array();
     }
     if (!is_array($this->extensions) && isset($post_vars['**extensions**'])) {
         $this->extensions = $post_vars['**extensions**'];
         unset($post_vars['**extensions**']);
     }
     if (isset($_GET['name']) && !$this->etemplate->read($_GET) || isset($post_vars['name']) && !$this->etemplate->read($post_vars)) {
         $msg = lang('Error: Template not found !!!');
         if (isset($post_vars['name'])) {
             $post_vars['version'] = '';
             // trying it without version
             if ($this->etemplate->read($post_vars)) {
                 $msg = lang('only an other Version found !!!');
             }
         }
     }
     if (!$msg && isset($post_vars['delete'])) {
         $this->delete(array(), 'show');
         return;
     }
     if (isset($post_vars['edit'])) {
         $this->edit();
         return;
     }
     list($app) = explode('.', $this->etemplate->name);
     if ($app && $app != 'etemplate') {
         $GLOBALS['phpgw']->translation->add_app($app);
         // load translations for app
     }
     $content = $this->etemplate->as_array() + array('msg' => $msg);
     $show = new etemplate('etemplate.editor.show');
     if (!$msg && isset($post_vars['values']) && !isset($post_vars['vals'])) {
         $cont = $post_vars['cont'];
         for ($r = 1; list($key, $val) = @each($cont); ++$r) {
             $vals["@{$r}"] = $key;
             $vals["A{$r}"] = is_array($val) ? htmlspecialchars(serialize($val)) . '#SeR#' : $val;
         }
         $show->data[$show->rows]['A']['name'] = 'etemplate.editor.values';
         $show->data[$show->rows]['A']['size'] = 'vals';
         $content['vals'] = $vals;
     } else {
         $show->data[$show->rows]['A']['obj'] =& $this->etemplate;
         $vals = $post_vars['vals'];
         $olds = $post_vars['olds'];
         for ($r = 1; isset($vals["A{$r}"]); ++$r) {
             $content['cont'][$olds["@{$r}"]] = substr($vals["A{$r}"], -5) == '#SeR#' ? unserialize(substr($vals["A{$r}"], 0, -5)) : $vals["A{$r}"];
         }
     }
     $show->exec('etemplate.editor.show', $content, array(), '', array('olds' => $vals, '**extensions**' => $this->extensions), '');
 }
 function pre_process($name, &$value, &$cell, &$readonlys, &$extension_data, &$tmpl)
 {
     $nm_global =& $GLOBALS['phpgw_info']['etemplate']['nextmatch'];
     //echo "<p>nextmatch_widget.pre_process(name='$name',type='$cell[type]'): value = "; _debug_array($value);
     //echo "<p>nextmatch_widget.pre_process(name='$name',type='$cell[type]'): nm_global = "; _debug_array($nm_global);
     $extension_data = array('type' => $cell['type']);
     switch ($cell['type']) {
         case 'nextmatch-sortheader':
             $cell['type'] = 'button';
             $cell['onchange'] = True;
             if (!$cell['help']) {
                 $cell['help'] = 'click to order after that criteria';
             }
             if ($this->last_part($name) == $nm_global['order']) {
                 $cell[1] = $cell;
                 $cell[1]['span'] .= ',activ_sortcolumn';
                 $cell[2] = $tmpl->empty_cell('image', $nm_global['sort'] != 'DESC' ? 'down' : 'up');
                 $cell['type'] = 'hbox';
                 $cell['size'] = '2,0,0';
                 $cell['name'] = $cell['label'] = '';
             } else {
                 $cell['span'] .= ',inactiv_sortcolumn';
             }
             return True;
         case 'nextmatch-filterheader':
             $cell['type'] = 'select';
             if (!$cell['size']) {
                 $cell['size'] = 'All';
             }
             if (!$cell['help']) {
                 $cell['help'] = 'select which values to show';
             }
             $cell['onchange'] = True;
             $extension_data['old_value'] = $value = $nm_global['col_filter'][$this->last_part($name)];
             return True;
     }
     list($app, $class, $method) = explode('.', $value['get_rows']);
     $obj = CreateObject($app . '.' . $class);
     if (!is_object($obj) || !method_exists($obj, $method)) {
         echo "<p>nextmatch_widget::pre_process({$name}): '{$value['get_rows']}' is no valid method !!!</p>\n";
         //return;
     } else {
         $total = $value['total'] = $obj->{$method}($value, $value['rows'], $readonlys['rows']);
     }
     if ($value['start'] > $total) {
         $value['start'] = 0;
         $total = $obj->{$method}($value, $value['rows'], $readonlys['rows']);
     }
     list($template, $options) = explode(',', $cell['size']);
     if ($template) {
         $value['template'] = $template;
     }
     if (!is_object($value['template'])) {
         $value['template'] = new etemplate($value['template'], $tmpl->as_array());
     }
     if ($total < 1) {
         $value['template']->data[0]['h2'] = ',1';
         // disable the data row
     }
     $max = $GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'];
     if ($total <= $max && $options && $value['search'] == '' && ($value['no_cat'] || !$value['cat_id']) && ($value['no_filter'] || !$value['filter'] || $value['filter'] == 'none') && ($value['no_filter2'] || !$value['filter2'] || $value['filter2'] == 'none')) {
         // disable whole nextmatch line if no scrolling necessary
         if ($value['header_left'] || $value['header_right']) {
             $nextmatch = new etemplate('etemplate.nextmatch_widget.header_only');
             $cell['size'] = $cell['name'];
             $cell['obj'] =& $nextmatch;
             $cell['name'] = $nextmatch->name;
         } else {
             $cell['size'] = $cell['name'] . '[rows]';
             $cell['obj'] =& $value['template'];
             $cell['name'] = $value['template']->name;
         }
     } else {
         $nextmatch = new etemplate('etemplate.nextmatch_widget');
         if ($value['no_cat']) {
             $nextmatch->disable_cells('cat_id');
         }
         if ($value['no_filter']) {
             $nextmatch->disable_cells('filter');
         }
         if ($value['no_filter2']) {
             $nextmatch->disable_cells('filter2');
         }
         $start = $value['start'];
         $end = $start + $max > $total ? $total : $start + $max;
         $value['range'] = $total ? 1 + $start . ' - ' . $end : '0';
         $nextmatch->set_cell_attribute('first', 'readonly', $start <= 0);
         $nextmatch->set_cell_attribute('left', 'readonly', $start <= 0);
         $nextmatch->set_cell_attribute('right', 'readonly', $start + $max >= $total);
         $nextmatch->set_cell_attribute('last', 'readonly', $start + $max >= $total);
         $cell['size'] = $cell['name'];
         $cell['obj'] =& $nextmatch;
         $cell['name'] = $nextmatch->name;
     }
     $cell['type'] = 'template';
     $cell['label'] = $cell['help'] = '';
     // save values in persistent extension_data to be able use it in post_process
     $extension_data += $value;
     foreach (array('sort', 'order', 'col_filter') as $n) {
         $nm_global[$n] = $value[$n];
     }
     $value['bottom'] = $value;
     // copy the values for the bottom-bar
     return False;
     // NO extra Label
 }
 function pre_process($form_name, &$value, &$cell, &$readonlys, &$extension_data, &$tmpl)
 {
     $dom_enabled = 0;
     //$GLOBALS['phpgw_info']['etemplate']['dom_enabled'];
     $labels = explode('|', $cell['label']);
     $helps = explode('|', $cell['help']);
     $names = explode('|', $cell['name']);
     $tab = new etemplate('etemplate.tab_widget.tab' . ($dom_enabled ? '_dom' : ''));
     $tab_active = new etemplate('etemplate.tab_widget.tab_active');
     $tabs = new etemplate();
     $tabs->init('*** generated tabs', '', '', 0, '', 0, 0);
     // make an empty template
     foreach ($names as $k => $name) {
         if (!strstr($name, '.')) {
             $name = $names[$k] = $tmpl->name . '.' . $name;
         }
         if ($extension_data == $name) {
             $selected_tab = $name;
         }
     }
     if (empty($selected_tab)) {
         $extension_data = $selected_tab = $names[0];
     }
     $tab_row = array();
     // generate the tab row
     while (list($k, $name) = each($names)) {
         if (!strstr($name, '.')) {
             $name = $names[$k] = $tmpl->name . '.' . $name;
         }
         $tcell = $tabs->empty_cell();
         if ($extension_data == $name) {
             // save selected tab in persistent extension_data to use it in post_process
             $selected_tab = $name;
             $tcell['obj'] = $tab_active;
             $tcell['name'] = $tab_active->name;
         } else {
             $tcell['obj'] = $tab;
             $tcell['name'] = $tab->name;
         }
         if ($dom_enabled) {
             $tcell['obj']->set_cell_attribute('tab', 'onclick', "activate_tab('{$name}','{$cell['name']}');");
             $tcell['obj']->set_cell_attribute('tab', 'id', $name . '-tab');
         }
         $tcell['type'] = 'template';
         $tcell['size'] = $cell['name'] . '[' . $name . ']';
         $value[$name] = array('name' => $name, 'label' => $labels[$k], 'help' => $helps[$k]);
         $tab_row[$tabs->num2chrs($k)] = $tcell;
     }
     // add one empty cell to take all the space of the row
     $tab_row[$k = $tabs->num2chrs(sizeof($tab_row))] = $tabs->empty_cell();
     $tabs->data[0][$k] = '99%';
     // width
     $tabs->data[0]['c1'] = ',bottom';
     $tabs->data[1] = $tab_row;
     $tabs->set_rows_cols();
     $tabs->size = "{$cell['width']},,,0,0";
     $tab_widget = new etemplate('etemplate.tab_widget');
     $tab_widget->set_cell_attribute('@tabs', 'obj', $tabs);
     if ($dom_enabled) {
         $tab_widget->set_cell_attribute('@body', 'type', 'deck');
         $tab_widget->set_cell_attribute('@body', 'width', $cell['width']);
         $tab_widget->set_cell_attribute('@body', 'height', $cell['height']);
         $tab_widget->set_cell_attribute('@body', 'size', count($names));
         $tab_widget->set_cell_attribute('@body', 'class', $cell['class']);
         foreach ($names as $n => $name) {
             $bcell = $tab_widget->empty_cell();
             $bcell['type'] = 'template';
             $bcell['obj'] = new etemplate($name, $tmpl->as_array());
             $bcell['name'] = $name;
             $tab_widget->set_cell_attribute('@body', $n + 1, $bcell);
         }
         $tab_widget->set_cell_attribute('@body', 'name', $cell['name']);
     } else {
         $stab = new etemplate($selected_tab, $tmpl->as_array());
         $options = array_pad(explode(',', $stab->size), 3, '');
         $options[3] = ($options[3] != '' ? $options[3] . ' ' : '') . 'tab_body';
         $stab->size = implode(',', $options);
         $tab_widget->set_cell_attribute('@body', 'obj', $stab);
     }
     $tab_widget->set_cell_attribute('@body', 'name', $selected_tab);
     $cell['type'] = 'template';
     $cell['obj'] =& $tab_widget;
     $cell['label'] = $cell['help'] = '';
     return False;
     // NO extra Label
 }
 function pre_process($name, &$value, &$cell, &$readonlys, &$extension_data, &$tmpl)
 {
     if ($cell['type'] == 'link-to' && ($cell['readonly'] || $readonlys)) {
         // readonly ==> omit the whole widget
         $cell = $tmpl->empty_cell();
         return;
     }
     if ($cell['type'] == 'link-string') {
         $str = '';
         if (is_array($value)) {
             foreach ($value as $link) {
                 $str .= ($str !== '' ? ', ' : '') . $tmpl->html->a_href($tmpl->html->htmlspecialchars($this->link->title($link['app'], $link['id'])), $this->link->view($link['app'], $link['id'], $link));
             }
         }
         $cell['type'] = 'html';
         $cell['readonly'] = True;
         // is allways readonly
         $value = $str;
         return True;
     }
     if (!is_array($value)) {
         $value = array('to_id' => $value, 'to_app' => $GLOBALS['phpgw_info']['flags']['currentapp']);
     }
     if ($this->debug) {
         echo "<p>start: {$cell['type']}[{$name}]::pre_process: value =";
         _debug_array($value);
         echo "extension_data[{$cell['type']}][{$name}] =";
         _debug_array($extension_data);
     }
     switch ($type = $cell['type']) {
         case 'link-to':
             if ($value['button'] == 'upload' && !empty($value['file']) && $value['file']['tmp_name'] != 'none') {
                 $value = $extension_data;
                 $value['remark'] = '';
                 $tpl = new etemplate('etemplate.link_widget.attach');
             } elseif ($value['button'] == 'search' && count($ids = $this->link->query($value['app'], $value['query']))) {
                 $extension_data['app'] = $value['app'];
                 $value = $extension_data;
                 $value['options-id'] = $ids;
                 $value['remark'] = '';
                 $tpl = new etemplate('etemplate.link_widget.create');
             } else {
                 if (!$value['button']) {
                     $extension_data = $value;
                 }
                 $value = array_merge($extension_data, $value);
                 $value['options-app'] = $this->link->app_list();
                 $tpl = new etemplate('etemplate.link_widget.search');
                 $tpl->set_cell_attribute('msg', 'disabled', $value['button'] != 'search');
             }
             break;
         case 'link-list':
             $app = $value['to_app'];
             $id = isset($extension_data['to_id']) ? $extension_data['to_id'] : $value['to_id'];
             if ($this->debug) {
                 echo "<p>link-list-widget[{$name}].preprocess: value=";
                 _debug_array($value);
             }
             if (!isset($value['title'])) {
                 $value['title'] = $this->link->title($app, $id);
             }
             $links = $this->link->get_links($app, $id);
             $value['anz_links'] = count($links);
             $extension_data = $value;
             if (!count($links)) {
                 $cell = $tmpl->empty_cell();
                 $value = '';
                 return True;
             }
             $tpl = new etemplate('etemplate.link_widget.list');
             $tpl->data[0]['A'] = $tmpl->data[0]['A'];
             // set width of first col like the tmpl. calling us
             for ($row = $tpl->rows - 1; list(, $link) = each($links); ++$row) {
                 $value[$row] = $link;
                 $value[$row]['title'] = $this->link->title($link['app'], $link['id'], $link);
                 if (!is_array($link['id'])) {
                     $value[$row]['view'] = $this->link->view($link['app'], $link['id'], $link);
                 }
             }
             break;
     }
     $cell['size'] = $cell['name'];
     $cell['type'] = 'template';
     $cell['name'] = $tpl->name;
     $cell['obj'] =& $tpl;
     if ($this->debug) {
         echo "<p>end: {$type}" . "[{$name}]::pre_process: value =";
         _debug_array($value);
     }
     return True;
     // extra Label is ok
 }
 function import_dump($app)
 {
     include $path = PHPGW_SERVER_ROOT . "/{$app}/setup/etemplates.inc.php";
     $templ = new etemplate($app);
     for ($n = 0; isset($templ_data[$n]); ++$n) {
         for (reset($this->db_cols); list($db_col, $name) = each($this->db_cols);) {
             $templ->{$name} = $templ_data[$n][$name];
         }
         $templ->data = unserialize(stripslashes($templ->data));
         if (!$templ->modified) {
             $templ->modified = filemtime($path);
         }
         $templ->save();
     }
     return lang("%1 new eTemplates imported for Application '%2'", $n, $app);
 }
 function cell2widget($cell, &$spanned, $etempl, &$root, &$embeded_too)
 {
     $type = $cell['type'];
     if (is_array($type)) {
         list(, $type) = each($type);
     }
     if (substr($type, 0, 6) == 'select') {
         $type = $cell['size'] > 1 ? 'select-multi' : 'select';
     }
     $widgetattr2xul = isset($this->widget2xul[$type]) ? $this->widget2xul[$type] : array();
     $type = isset($widgetattr2xul['.name']) ? $widgetattr2xul['.name'] : $type;
     list($parent, $child, $child2) = explode(',', $type);
     $widget = new xmlnode($parent);
     $attr_widget =& $widget;
     if ($child) {
         $child = new xmlnode($child);
         $attr_widget =& $child;
     }
     if ($child2) {
         $child2 = new xmlnode($child2);
     }
     if (isset($widgetattr2xul['.set'])) {
         $attrs = explode(',', $widgetattr2xul['.set']);
         while (list(, $attr) = each($attrs)) {
             list($attr, $val) = explode('=', $attr);
             $widget->set_attribute($attr, $val);
         }
     }
     switch ($parent) {
         case 'nextmatch':
             list($tpl) = explode(',', $cell['size']);
             $embeded = new etemplate($tpl, $etempl->as_array());
             if ($embeded_too) {
                 $this->etempl2grid($embeded, $root, $embeded_too);
             }
             $cell['size'] = $embeded->name;
             unset($embeded);
             break;
         case 'tabbox':
             $labels = explode('|', $cell['label']);
             unset($cell['label']);
             $helps = explode('|', $cell['help']);
             unset($cell['help']);
             $names = explode('|', $cell['name']);
             unset($cell['name']);
             for ($n = 0; $n < count($labels); ++$n) {
                 $tab = new xmlnode('tab');
                 $tab->set_attribute('label', $labels[$n]);
                 $tab->set_attribute('statustext', $helps[$n]);
                 $child->add_node($tab);
                 $embeded = new etemplate($names[$n], $etempl->as_array());
                 if ($embeded_too) {
                     $this->etempl2grid($embeded, $root, $embeded_too);
                 }
                 $grid = new xmlnode('grid');
                 $grid->set_attribute('id', $embeded->name);
                 $child2->add_node($grid);
                 unset($embeded);
             }
             break;
         case 'menulist':
             // id,options belongs to the 'menupopup' child
             if ($cell['span']) {
                 $widget->set_attribute('span', $cell['span']);
                 unset($cell['span']);
             }
             // fall-trought
         // fall-trought
         case 'listbox':
             if ($cell['type'] != 'select') {
                 $attr_widget->set_attribute('type', $cell['type']);
             }
             break;
         case 'vbox':
         case 'hbox':
             list($anz, $options) = split(',', $cell['size'], 2);
             for ($n = 1; $n <= $anz; ++$n) {
                 $widget->add_node($this->cell2widget($cell[$n], $no_span, $etempl, $root, $embeded_too));
                 unset($cell[$n]);
             }
             $cell['size'] = $options;
             break;
         case 'grid':
             if ($cell['name'][0] != '@' && $embeded_too) {
                 $embeded = new etemplate();
                 if ($embeded->read($name = $embeded->expand_name($cell['name'], 0, 0), 'default', 'default', 0, '', $etempl->as_array())) {
                     $this->etempl2grid($embeded, $root, $embeded_too);
                 }
                 $cell['name'] = $embeded->name;
                 unset($embeded);
             }
             break;
     }
     while (list($attr, $val) = each($cell)) {
         if (is_array($val)) {
             list(, $val) = each($val);
         }
         if (isset($widgetattr2xul[$attr])) {
             $attr = $widgetattr2xul[$attr];
         } elseif (isset($this->attr2xul[$attr])) {
             $attr = $this->attr2xul[$attr];
         }
         $this->set_attributes2($attr_widget, $attr, $val, $spanned);
     }
     if ($child) {
         $widget->add_node($child);
     }
     if ($child2) {
         $widget->add_node($child2);
     }
     return $widget;
 }
 function pre_process($name, &$value, &$cell, &$readonlys, &$extension_data, &$tmpl)
 {
     $type = $cell['type'];
     list($data_format, $options) = explode(',', $cell['size']);
     if ($type == 'date-houronly' && empty($data_format)) {
         $data_format = 'H';
     }
     $extension_data = array('data_format' => $data_format, 'type' => $type);
     if (!$value) {
         $value = array('Y' => '', 'm' => '', 'd' => '', 'H' => '', 'i' => '');
     } elseif ($data_format != '') {
         $date = split('[- /.:,]', $value);
         //echo "date=<pre>"; print_r($date); echo "</pre>";
         $mdy = split('[- /.:,]', $data_format);
         $value = array();
         foreach ($date as $n => $dat) {
             switch ($mdy[$n]) {
                 case 'Y':
                     $value['Y'] = $dat;
                     break;
                 case 'm':
                     $value['m'] = $dat;
                     break;
                 case 'd':
                     $value['d'] = $dat;
                     break;
                 case 'H':
                     $value['H'] = $dat;
                     break;
                 case 'i':
                     $value['i'] = $dat;
                     break;
             }
         }
     } else {
         // for the timeformats we use only seconds, no timezone conversation between server-time and UTC
         if (substr($type, -4) == 'only') {
             $value -= adodb_date('Z', 0);
         }
         $value = array('Y' => adodb_date('Y', $value), 'm' => adodb_date('m', $value), 'M' => substr(lang(adodb_date('F', $value)), 0, 3), 'd' => adodb_date('d', $value), 'H' => adodb_date('H', $value), 'i' => adodb_date('i', $value));
     }
     $time_0h0 = !(int) $value['H'] && !(int) $value['i'];
     $timeformat = array(3 => 'H', 4 => 'i');
     if ($this->timeformat == '12') {
         $value['a'] = $value['H'] < 12 ? 'am' : 'pm';
         if ($value['H'] > 12) {
             $value['H'] -= 12;
         }
         $timeformat += array(5 => 'a');
     }
     $format = split('[/.-]', $this->dateformat);
     $readonly = $cell['readonly'] || $readonlys;
     // no time also if $options&8 and readonly and time=0h0
     if ($type != 'date' && !($readonly && $options & 8 && $time_0h0)) {
         $format += $timeformat;
     }
     if ($readonly) {
         $sep = array(1 => $this->dateformat[1], 2 => $this->dateformat[1], 3 => ' ', 4 => ':');
         for ($str = '', $n = substr($type, -4) == 'only' ? 3 : 0; $n < count($format); ++$n) {
             if ($value[$format[$n]]) {
                 if (!$n && $options & 16) {
                     $str = lang(adodb_date('l', adodb_mktime(12, 0, 0, $value['m'], $value['d'], $value['Y']))) . ' ';
                 }
                 $str .= ($str != '' ? $sep[$n] : '') . $value[$format[$n]];
             }
             if ($type == 'date-houronly') {
                 ++$n;
             }
             // no minutes
         }
         $value = $str;
         $cell['type'] = 'label';
         if (!$cell['no_lang']) {
             $cell['no_lang'] = True;
             $cell['label'] = strlen($cell['label']) > 1 ? lang($cell['label']) : $cell['label'];
         }
         unset($cell['size']);
         return True;
     }
     $tpl = new etemplate();
     $tpl->init('*** generated fields for date', '', '', 0, '', 0, 0);
     // make an empty template
     $types = array('Y' => $options & 1 ? 'int' : 'select-year', 'm' => 'select-month', 'M' => 'select-month', 'd' => 'select-day', 'H' => 'select-number', 'i' => 'select-number');
     $opts = array('H' => $this->timeformat == '12' ? ',0,12' : ',0,23,01', 'i' => $value['i'] % 5 || $options & 4 ? ',0,59,01' : ',0,59,05');
     $help = array('Y' => 'Year', 'm' => 'Month', 'M' => 'Month', 'd' => 'Day', 'H' => 'Hour', 'i' => 'Minute');
     $row = array();
     for ($i = 0, $n = substr($type, -4) == 'only' ? 3 : 0; $n < ($type == 'date' ? 3 : 5); ++$n, ++$i) {
         $dcell = $tpl->empty_cell();
         // test if we can use jsCalendar
         if ($n == 0 && $this->jscal && $tmpl->java_script()) {
             $dcell['type'] = 'html';
             $dcell['name'] = 'str';
             $value['str'] = $this->jscal->input($name . '[str]', False, $value['Y'], $value['m'], $value['d'], lang($cell['help']));
             $n = 2;
             // no other fields
             $options &= ~2;
             // no set-today button
         } else {
             $dcell['type'] = $types[$format[$n]];
             $dcell['size'] = $opts[$format[$n]];
             $dcell['name'] = $format[$n];
             $dcell['help'] = lang($help[$format[$n]]) . ': ' . lang($cell['help']);
             // note: no lang on help, already done
         }
         if ($n == 4) {
             $dcell['label'] = ':';
             // put a : between hour and minute
         }
         $dcell['no_lang'] = 2;
         $row[$tpl->num2chrs($i)] =& $dcell;
         unset($dcell);
         if ($n == 2 && $options & 2) {
             $dcell = $tpl->empty_cell();
             $dcell['name'] = 'today';
             $dcell['label'] = 'Today';
             $dcell['help'] = 'sets today as date';
             $dcell['no_lang'] = True;
             if ($js = $tmpl->java_script()) {
                 $dcell['needed'] = True;
                 // to get a button
                 $dcell['onchange'] = "this.form.elements['{$name}" . "[Y]'].value='" . adodb_date('Y') . "'; this.form.elements['{$name}" . "[m]'].value='" . adodb_date('n') . "';this.form.elements['{$name}" . "[d]'].value='" . (0 + adodb_date('d')) . "'; return false;";
             }
             $dcell['type'] = $js ? 'button' : 'checkbox';
             $row[$tpl->num2chrs(++$i)] =& $dcell;
             unset($dcell);
         }
         if ($n == 2 && $type == 'date-time') {
             $dcell = $tpl->empty_cell();
             $dcell['type'] = 'html';
             $dcell['name'] = 'space';
             $value['space'] = ' &nbsp; &nbsp; ';
             $row[$tpl->num2chrs(++$i)] =& $dcell;
             unset($dcell);
         }
         if ($type == 'date-houronly') {
             $n++;
         }
         // no minutes
         if ($n == 4 && $type != 'date' && $this->timeformat == '12') {
             $dcell = $tpl->empty_cell();
             $dcell['type'] = 'radio';
             $dcell['name'] = 'a';
             $dcell['help'] = $cell['help'];
             $dcell['size'] = $dcell['label'] = 'am';
             $row[$tpl->num2chrs(++$i)] = $dcell;
             $dcell['size'] = $dcell['label'] = 'pm';
             $row[$tpl->num2chrs(++$i)] =& $dcell;
             unset($dcell);
         }
     }
     $tpl->data[0] = array();
     $tpl->data[1] =& $row;
     $tpl->set_rows_cols();
     $tpl->size = ',,,,0';
     $cell['size'] = $cell['name'];
     $cell['type'] = 'template';
     $cell['name'] = $tpl->name;
     $cell['obj'] =& $tpl;
     return True;
     // extra Label is ok
 }