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) { $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'] = ' '; $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 }