[ Index ] |
|
Code source de eGroupWare 1.2.106-2 |
1 <?php 2 /**************************************************************************\ 3 * eGroupWare - eTemplate Widget for custom fields * 4 * http://www.egroupware.org * 5 * Written by Ralf Becker <RalfBecker@outdoor-training.de> and * 6 * Cornelius Weiss <egw@von-und-zu-weiss.de> * 7 * -------------------------------------------- * 8 * This program is free software; you can redistribute it and/or modify it * 9 * under the terms of the GNU General Public License as published by the * 10 * Free Software Foundation; either version 2 of the License, or (at your * 11 * option) any later version. * 12 \**************************************************************************/ 13 14 /* $Id: class.customfields_widget.inc.php 19723 2005-11-10 12:10:17Z nelius_weiss $ */ 15 16 /** 17 * This widget generates a template for customfields based on definitions in epgw_config table 18 * 19 * @package etemplate 20 * @subpackage extensions 21 * @author RalfBecker-At-outdoor-training.de 22 * @author Cornelius Weiss <egw@von-und-zu-weiss.de> 23 * @license GPL - GNU General Public License 24 */ 25 class customfields_widget 26 { 27 var $public_functions = array( 28 'pre_process' => True, 29 ); 30 var $human_name = 'custom fields'; 31 32 /** 33 * @var $prefix string Prefix for every custiomfield name returned in $content (# for general (admin) customfields) 34 */ 35 var $prefix = '#'; 36 37 function customfields_widget($ui) 38 { 39 $this->appname = $GLOBALS['egw_info']['flags']['currentapp']; 40 $this->config =& CreateObject('phpgwapi.config',$this->appname); 41 $this->config->appname = $this->appname; 42 $config = $this->config->read_repository(); 43 //merge old config_name in egw_config table 44 $config_name = isset($config['customfields']) ? 'customfields' : 'custom_fields'; 45 $this->customfields = $config[$config_name]; 46 $this->advanced_search = $GLOBALS['egw_info']['etemplate']['advanced_search']; 47 48 } 49 50 function pre_process($name,&$value,&$cell,&$readonlys,&$extension_data,&$tmpl) 51 { 52 $readonly = $cell['readonly'] || $readonlys[$name]; 53 54 // infolog compability 55 if ($this->appname == 'infolog') 56 { 57 $typ = $value['###typ###']; 58 unset($value['###typ###']); 59 $this->customfields = $value; 60 } 61 62 if(!is_array($this->customfields)) 63 { 64 $cell['type'] = 'label'; 65 return True; 66 } 67 68 $tpl =& new etemplate; 69 $tpl->init('*** generated custom fields','','',0,'',0,0); // make an empty template 70 71 //echo '<pre style="text-align: left;">'; print_r($value); echo "</pre>\n"; 72 foreach($this->customfields as $name => $field) 73 { 74 if (!empty($field['typ']) && $field['typ'] != $typ) 75 { 76 continue; // not for our typ 77 } 78 if(empty($field['type'])) 79 { 80 if (count($field['values'])) $field['type'] = 'select'; // selectbox 81 elseif ($field['rows'] > 1) $field['type'] = 'textarea'; // textarea 82 elseif (intval($field['len']) > 0) $field['type'] = 'text'; // regular input field 83 else $field['type'] = 'label'; // header-row 84 } 85 86 $row_class = 'row'; 87 $label = &$tpl->new_cell(++$n,'label',$field['label'],'',array( 88 'no_lang' => substr(lang($field['label']),-1) == '*' ? 2 : 0 89 )); 90 switch ($field['type']) 91 { 92 case 'select' : 93 if($this->advanced_search) $field['values'][''] = lang('doesn\'t matter'); 94 foreach($field['values'] as $key => $val) 95 { 96 if (substr($val = lang($val),-1) != '*') 97 { 98 $field['values'][$key] = $val; 99 } 100 } 101 $input = &$tpl->new_cell($n,'hbox'); 102 if($this->advanced_search) 103 { 104 $not = &$tpl->add_child($input, $check = &$tpl->empty_cell('checkbox','!'.$this->prefix.$name,array( 105 'label' => 'NOT', 106 'no_lang' => True 107 ))); 108 unset($not); 109 unset($check); 110 } 111 $select = &$tpl->add_child($input, $item = &$tpl->empty_cell('select',$this->prefix.$name,array( 112 'sel_options' => $field['values'], 113 'size' => $field['rows'], 114 'no_lang' => True 115 ))); 116 unset($select); 117 unset($item); 118 break; 119 case 'label' : 120 $label['span'] = 'all'; 121 $tpl->new_cell($n); // is needed even if its over-span-ed 122 $row_class = 'th'; 123 break; 124 case 'checkbox' : 125 $input = &$tpl->new_cell($n,'checkbox','',$this->prefix.$name); 126 break; 127 case 'radio' : 128 $input = &$tpl->new_cell($n,'groupbox','','',''); 129 $m = 0; 130 foreach ($field['values'] as $key => $val) 131 { 132 $radio = $tpl->empty_cell('radio',$this->prefix.$name); 133 $radio['label'] = $val; 134 $radio['size'] = $key; 135 $tpl->add_child($input,$radio); 136 unset($radio); 137 } 138 break; 139 case 'text' : 140 case 'textarea' : 141 default : 142 $field['len'] = $field['len'] ? $field['len'] : 20; 143 if($field['rows'] <= 1) 144 { 145 list($max,$shown) = explode(',',$field['len']); 146 $input = &$tpl->new_cell($n,'text','',$this->prefix.$name,array( 147 'size' => intval($shown > 0 ? $shown : $max).','.intval($max) 148 )); 149 } 150 else 151 { 152 $input = &$tpl->new_cell($n,'textarea','',$this->prefix.$name,array( 153 'size' => $field['rows'].($field['len'] > 0 ? ','.(int)$field['len'] : '') 154 )); 155 } 156 break; 157 } 158 if ($readonly) $input['readonly'] = true; 159 160 if (!empty($field['help']) && $row_class != 'th') 161 { 162 $input['help'] = $field['help']; 163 $input['no_lang'] = substr(lang($help),-1) == '*' ? 2 : 0; 164 } 165 $tpl->set_row_attributes($n,0,$row_class,'top'); 166 } 167 // create an empty line which (should) take all the remaining height 168 $tpl->new_cell(++$n,'label','','',array( 169 'span' => 'all' 170 )); 171 $tpl->set_row_attributes($n,'99%','row'); 172 173 // set width of 1. (label) column to 100 174 $tpl->set_column_attributes(0,'100'); 175 176 $tpl->set_rows_cols(); // msie (at least 5.5 shows nothing with div overflow=auto) 177 $tpl->size = '100%,100%'.($tpl->html->user_agent != 'msie' ? ',,,,,auto' : ''); 178 //echo '<pre style="text-align: left;">'; print_r($tpl); echo "</pre>\n"; 179 180 if (count($tpl->data) < 2) 181 { 182 $cell['type'] = 'label'; 183 return True; 184 } 185 $cell['size'] = ''; // no separate namespace 186 $cell['type'] = 'template'; 187 $cell['name'] = $tpl->name; 188 $cell['obj'] = &$tpl; 189 190 return True; // extra Label is ok 191 } 192 }
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 17:20:01 2007 | par Balluche grâce à PHPXref 0.7 |