diff --git a/etemplate/inc/class.boetemplate.inc.php b/etemplate/inc/class.boetemplate.inc.php index a307a52a13..f343d8d9a4 100644 --- a/etemplate/inc/class.boetemplate.inc.php +++ b/etemplate/inc/class.boetemplate.inc.php @@ -40,14 +40,6 @@ 'date' => '', // Datefield, size='' timestamp or size=format like 'm/d/Y' 'select' => 'Selectbox', // Selectbox ($sel_options[$name] or $content[options-$name] is array with options) // if size > 1 then multiple selections, size lines showed - 'select-percent' => 'Select Percentage', - 'select-priority' => 'Select Priority', - 'select-access' => 'Select Access', - 'select-country' => 'Select Country', - 'select-state' => 'Select State', // US-states - 'select-cat' => 'Select Category', // Category-Selection, size: -1=Single+All, 0=Single, >0=Multiple with size lines - 'select-account' => 'Select Account', // label=accounts(default),groups,both - // size: -1=Single+not assigned, 0=Single, >0=Multiple 'raw' => 'Raw', // Raw html in $content[$cell['name']] 'file' => 'FileUpload' // show an input type='file', set the local name as ${name}_path ); diff --git a/etemplate/inc/class.editor.inc.php b/etemplate/inc/class.editor.inc.php index 71cd46d2cc..42fb6a96e7 100644 --- a/etemplate/inc/class.editor.inc.php +++ b/etemplate/inc/class.editor.inc.php @@ -410,7 +410,7 @@ if (substr($content['name'],0,9) == 'etemplate') { $m = new editor(False); - $additional = $m->messages + $this->etemplate->types + $this->aligns; + $additional = $m->messages + $this->etemplate->types + $this->extensions + $this->aligns; } $msg = $this->etemplate->writeLangFile($content['name'],'en',$additional); } @@ -708,7 +708,21 @@ if (ereg('class\\.([a-zA-Z0-9_]*)_widget.inc.php',$file,$regs) && ($ext = $this->etemplate->loadExtension($regs[1].'.'.$app,$this->etemplate))) { - $extensions[$regs[1]] = $ext; + if (is_array($ext)) + { + if (!is_array($extensions)) + { + $extensions = $ext; + } + else + { + $extensions += $ext; + } + } + else + { + $extensions[$regs[1]] = $ext; + } } } return $extensions; diff --git a/etemplate/inc/class.html.inc.php b/etemplate/inc/class.html.inc.php index d2a0da0d87..3d1674513c 100644 --- a/etemplate/inc/class.html.inc.php +++ b/etemplate/inc/class.html.inc.php @@ -27,6 +27,51 @@ class html //echo "
HTTP_USER_AGENT='$GLOBALS[HTTP_USER_AGENT]', UserAgent: '$this->user_agent', Version: '$this->ua_version', img_title: '$this->prefered_img_title'
\n"; } + /* + * Function: Allows to show and select one item from an array + * Parameters: $name string with name of the submitted var which holds the key of the selected item form array + * $key key(s) of already selected item(s) from $arr, eg. '1' or '1,2' or array with keys + * $arr array with items to select, eg. $arr = array ( 'y' => 'yes','n' => 'no','m' => 'maybe'); + * $no_lang if !$no_lang send items through lang() + * $options additional options (e.g. 'multiple') + * On submit $XXX is the key of the selected item (XXX is the content of $name) + * Returns: string to set for a template or to echo into html page + */ + function select($name, $key, $arr=0,$no_lang=0,$options='',$multiple=0) + { + // should be in class common.sbox + if (!is_array($arr)) + { + $arr = array('no','yes'); + } + if (0+$multiple > 0) + { + $options .= ' MULTIPLE SIZE='.(0+$multiple); + if (substr($name,-2) != '[]') + { + $name .= '[]'; + } + } + $out = "\n"; + + return $out; + } + function div($content,$options='') { return "nextmatch_widget.pre_process: value = "; _debug_array($value); + // save values in persistent extension_data to be able use it in post_process + //$extension_data = $value; + + list($rows,$type) = explode(',',$cell['size']); + + switch ($cell['type']) + { + case 'select-percent': + for ($i=0; $i <= 100; $i+=10) + { + $cell['sel_options'][$i] = "$i%"; + } + $value = intval(($value+5) / 10) * 10; + $cell['no_lang'] = True; + break; + + case 'select-priority': + $cell['sel_options'] = array('','low','normal','high'); + break; + + case 'select-access': + $cell['sel_options'] = array( + 'private' => 'Private', + 'public' => 'Global public', + 'group' => 'Group public' + ); + break; + + case 'select-country': + $cell['sel_options'] = $this->countrys; + $cell['no_lang'] = True; + break; + + case 'select-state': + $cell['sel_options'] = $this->states; + $cell['no_lang'] = True; + break; + + case 'select-cat': + if (!is_object($GLOBALS['phpgw']->categories)) + { + $GLOBALS['phpgw']->categories = CreateObject('phpgwapi.categories'); + } + if ($type != 'all') + { + $cats = $GLOBALS['phpgw']->categories->return_array($type,0); + } + else + { + $cats = $GLOBALS['phpgw']->categories->return_sorted_array(0); + } + while (list(,$cat) = @each($cats)) + { + for ($j=0,$s=''; $j < $cat['level']; $j++) + { + $s .= ' '; + } + $s .= $GLOBALS['phpgw']->strip_html($cat['name']); + if ($cat['app_name'] == 'phpgw') + { + $s .= ' <' . lang('Global') . '>'; + } + if ($cat['owner'] == '-1') + { + $s .= ' <' . lang('Global') . ' ' . lang($this->app_name) . '>'; + } + $cell['sel_options'][$cat['id']] = $s; + } + $cell['no_lang'] = True; + break; + + case 'select-account': + $accs = $GLOBALS['phpgw']->accounts->get_list(empty($type) ? 'accounts' : $type); // default is accounts + + while (list(,$acc) = each($accs)) + { + $cell['sel_options'][$acc['account_id']] = $this->accountInfo($a['account_id'],$a,$longnames,$type=='both'); + } + $cell['no_lang'] = True; + break; + + case 'select-month': + $cell['sel_options'] = $this->monthnames; + break; + } + return True; // extra Label Ok + } + + function accountInfo($id,$account_data=0,$longnames=0,$show_type=0) + { + if (!$id) + { + return ' '; + } + + if (!is_array($account_data)) + { + $accounts = createobject('phpgwapi.accounts',$id); + $accounts->db = $GLOBALS['phpgw']->db; + $accounts->read_repository(); + $account_data = $accounts->data; + } + $info = $show_type ? '('.$account_data['account_type'].') ' : ''; + + switch ($longnames) + { + case 2: $info .= '<'.$account_data['account_lid'].'> '; // fall-through + case 1: $info .= $account_data['account_firstname'].' '.$account_data['account_lastname']; break; + default: $info .= $account_data['account_lid']; break; + } + return $info; + } + } \ No newline at end of file diff --git a/etemplate/inc/class.uietemplate.inc.php b/etemplate/inc/class.uietemplate.inc.php index 2670a5f4bb..e6473bb1d5 100644 --- a/etemplate/inc/class.uietemplate.inc.php +++ b/etemplate/inc/class.uietemplate.inc.php @@ -26,13 +26,13 @@ @example if the user submitts the form. Vor the complete param's see the description of exec. @param $debug enables debug messages: 0=no, 1=calls to show and process_show, 2=content of process_show @param 3=calls to show_cell OR template- or cell-type name - @param $html,$sbox instances of html and sbox2 class used to generate the html + @param $html instances of html class used to generate the html */ class etemplate extends boetemplate { var $debug; // 1=calls to show and process_show, 2=content after process_show, // 3=calls to show_cell and process_show_cell, or template-name or cell-type - var $html,$sbox; // instance of html / sbox2-class + var $html; // instance of html-class var $class_conf = array('nmh' => 'th','nmr0' => 'row_on','nmr1' => 'row_off'); /*! @@ -50,7 +50,6 @@ 'process_show' => True, ); $this->html = CreateObject('etemplate.html'); // should be in the api (older version in infolog) - $this->sbox = CreateObject('etemplate.sbox2'); // older version is in the api $this->boetemplate($name,$load_via); @@ -342,11 +341,7 @@ } $name = $this->expand_name($cell['name'],$show_c,$show_row,$content['.c'],$content['.row'],$content); - /*if (strstr($name,'|')) // extension which uses whole content array - { - $value = $content; - } - else*/if (ereg('^([^[]*)(\\[.*\\])$',$name,$regs)) // name contains array-index + if (ereg('^([^[]*)(\\[.*\\])$',$name,$regs)) // name contains array-index { $form_name = $cname == '' ? $name : $cname.'['.$regs[1].']'.$regs[2]; eval(str_replace(']',"']",str_replace('[',"['",'$value = $content['.$regs[1].']'.$regs[2].';'))); @@ -372,16 +367,13 @@ } $extra_label = True; - if (!$this->types[$cell['type']] && $this->haveExtension($cell['type'],'pre_process')) + list($type,$sub_type) = explode('-',$cell['type']); + if ((!$this->types[$cell['type']] || !empty($sub_type)) && $this->haveExtension($type,'pre_process')) { - $ext_type = $cell['type']; + $ext_type = $type; $extra_label = $this->extensionPreProcess($ext_type,$form_name,$value,$cell,$readonlys[$name]); - /*if (strstr($name,'|')) - { - $content = $this->complete_array_merge($content,$value); - } - else*/if (!$regs) + if (!$regs) { $content[$name] = $value; // set result for template } @@ -417,7 +409,8 @@ $options .= ' onChange="'.($cell['onchange']=='1'?'this.form.submit();':$cell['onchange']).'"'; } } - switch ($cell['type']) + list($type,$sub_type) = explode('-',$cell['type']); + switch ($type) { case 'label': // size: [[b]old][[i]talic] $value = strlen($value) > 1 && !$cell['no_lang'] ? lang($value) : $value; @@ -455,22 +448,47 @@ $GLOBALS['phpgw_info']['etemplate']['to_process'][$form_name] = $cell['type']; break; case 'checkbox': + if (!empty($cell['size'])) + { + list($true_val,$false_val,$ro_true,$ro_false) = explode(',',$cell['size']); + $value = $value == $true_val; + } + else + { + $ro_true = 'x'; + $ro_false = ''; + } if ($value) { $options .= ' CHECKED'; } - $html .= $this->html->input($form_name,'1','CHECKBOX',$options); - if (!$readonly) - $GLOBALS['phpgw_info']['etemplate']['to_process'][$form_name] = $cell['type']; + if ($readonly) + { + $html .= $value ? $this->html->bold($ro_true) : $ro_false; + } + else + { + $html .= $this->html->input($form_name,'1','CHECKBOX',$options); + $GLOBALS['phpgw_info']['etemplate']['to_process'][$form_name] = array( + 'type' => $cell['type'], + 'values' => $cell['size'] + ); + } break; case 'radio': // size: value if checked if ($value == $cell['size']) { $options .= ' CHECKED'; } - $html .= $this->html->input($form_name,$cell['size'],'RADIO',$options); - if (!$readonly) + if ($readonly) + { + $html .= $value == $cell['size'] ? $this->html->bold('x') : ''; + } + else + { + $html .= $this->html->input($form_name,$cell['size'],'RADIO',$options); $GLOBALS['phpgw_info']['etemplate']['to_process'][$form_name] = $cell['type']; + } break; case 'button': if ($this->java_script() && $cell['onchange']) @@ -548,62 +566,47 @@ $html .= $cell['obj']->show($content,$sel_options,$readonlys,$cname,$show_c,$show_row); break; case 'select': // size:[linesOnMultiselect] - if (isset($sel_options[$name])) + if (!empty($cell['sel_options'])) + { + if (!is_array($cell)) + { + $sel_options = array(); + $opts = explode(',',$cell['sel_options']); + while (list(,$opt) = each($opts)) + { + list($k,$v) = explode('=',$opt); + $sel_options[$k] = $v; + } + } + else + { + $sel_options = $cell['sel_options']; + } + } + elseif (isset($sel_options[$name])) { $sel_options = $sel_options[$name]; } elseif (isset($sel_options[$org_name])) { $sel_options = $sel_options[$org_name]; - } elseif (isset($content["options-$name"])) + } + elseif (isset($content["options-$name"])) { $sel_options = $content["options-$name"]; } - $html .= $this->sbox->getArrayItem($form_name.'[]',$value,$sel_options,$cell['no_lang'], - $options,$cell['size']); - if (!$readonly) - $GLOBALS['phpgw_info']['etemplate']['to_process'][$form_name] = $cell['type']; - break; - case 'select-percent': - $html .= $this->sbox->getPercentage($form_name,$value,$options); - if (!$readonly) - $GLOBALS['phpgw_info']['etemplate']['to_process'][$form_name] = $cell['type']; - break; - case 'select-priority': - $html .= $this->sbox->getPriority($form_name,$value,$options); - if (!$readonly) - $GLOBALS['phpgw_info']['etemplate']['to_process'][$form_name] = $cell['type']; - break; - case 'select-access': - $html .= $this->sbox->getAccessList($form_name,$value,$options); - if (!$readonly) - $GLOBALS['phpgw_info']['etemplate']['to_process'][$form_name] = $cell['type']; - break; - case 'select-country': - $html .= $this->sbox->getCountry($form_name,$value,$options); - if (!$readonly) - $GLOBALS['phpgw_info']['etemplate']['to_process'][$form_name] = $cell['type']; - break; - case 'select-state': - $html .= $this->sbox->list_states($form_name,$value); // no helptext - old Function!!! - if (!$readonly) - $GLOBALS['phpgw_info']['etemplate']['to_process'][$form_name] = $cell['type']; - break; - case 'select-cat': - $html .= $this->sbox->getCategory($form_name.'[]',$value,$cell['size'] >= 0, - False,$cell['size'],$options); - if (!$readonly) - $GLOBALS['phpgw_info']['etemplate']['to_process'][$form_name] = $cell['type']; - break; - case 'select-account': - $type = substr(strstr($cell['size'],','),1); - if ($type == '') + list($multiple) = explode(',',$cell['size']); + + if ($readonly) { - $type = 'accounts'; // default is accounts + $html .= $cell['no_lang'] ? $sel_options[$value] : lang($sel_options[$value]); } - $html .= $this->sbox->getAccount($form_name.'[]',$value,2,$type,0+$cell['size'],$options); - if (!$readonly) + else + { + $html .= $this->html->select($form_name.($multiple > 1 ? '[]' : ''),$value,$sel_options, + $cell['no_lang'],$options,$multiple); $GLOBALS['phpgw_info']['etemplate']['to_process'][$form_name] = $cell['type']; + } break; case 'image': $image = $this->html->image(substr($this->name,0,strpos($this->name,'.')), @@ -630,7 +633,8 @@ } break; } - if ($ext_type && !$readonly) // extension-processing need to be after all other + if ($ext_type && !$readonly && // extension-processing need to be after all other and only with diff. name + !isset($GLOBALS['phpgw_info']['etemplate']['to_process'][$form_name])) { $GLOBALS['phpgw_info']['etemplate']['to_process'][$form_name] = 'ext-'.$ext_type; } @@ -677,14 +681,24 @@ } if ($this->debug >= 1 || $this->debug == $this->name && $this->name) { - echo "
process_show($this->name) start: content ="; _debug_array($GLOBALS['HTTP_POST_VARS']/*$content*/); + echo "
process_show($this->name) start: content ="; _debug_array($content); } $content_in = $cname ? array($cname => $content) : $content; $content = array(); reset($to_process); while (list($form_name,$type) = each($to_process)) { + if (is_array($type)) + { + $attr = $type; + $type = $attr['type']; + } + else + { + $attr = array(); + } $value = $this->get_array($content_in,$form_name); + //echo "
process_show($this->name) $type: $form_name = '$value'
\n"; list($type,$sub) = explode('-',$type); switch ($type) { @@ -713,6 +727,11 @@ { $value = 0; // need to be reported too } + if (!empty($attr['values'])) + { + list($true_val,$false_val) = explode(',',$attr['values']); + $value = $value ? $true_val : $false_val; + } $this->set_array($content,$form_name,$value); break; default: