[ Index ] |
|
Code source de eGroupWare 1.2.106-2 |
1 <?php 2 /**************************************************************************\ 3 * eGroupWare - InfoLog: Administration of custom fields, type and status * 4 * http://www.egroupware.org * 5 * Written and (c) by Ralf Becker <RalfBecker@outdoor-training.de> * 6 * -------------------------------------------- * 7 * This program is free software; you can redistribute it and/or modify it * 8 * under the terms of the GNU General Public License as published by the * 9 * Free Software Foundation; either version 2 of the License, or (at your * 10 * option) any later version. * 11 \**************************************************************************/ 12 13 /* $Id: class.uicustomfields.inc.php 19761 2005-11-12 13:25:59Z ralfbecker $ */ 14 15 /** 16 * Administration of custom fields, type and status 17 * 18 * @package infolog 19 * @author Ralf Becker <RalfBecker@outdoor-training.de> 20 * @copyright (c) by Ralf Becker <RalfBecker@outdoor-training.de> 21 * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License 22 */ 23 class uicustomfields 24 { 25 var $public_functions = array 26 ( 27 'edit' => True 28 ); 29 30 function uicustomfields( ) 31 { 32 $this->bo =& CreateObject('infolog.boinfolog'); 33 $this->tmpl =& CreateObject('etemplate.etemplate'); 34 $this->types = &$this->bo->enums['type']; 35 $this->status = &$this->bo->status; 36 $this->config = &$this->bo->config; 37 $this->fields = &$this->bo->customfields; 38 } 39 40 /** 41 * Edit/Create an InfoLog Custom fields, typ and status 42 * 43 * @param array $content Content from the eTemplate Exec 44 */ 45 function edit($content=null) 46 { 47 $GLOBALS['egw_info']['flags']['app_header'] = lang('InfoLog').' - '.lang('Custom fields, typ and status'); 48 if (is_array($content)) 49 { 50 //echo '<pre style="text-align: left;">'; print_r($content); echo "</pre>\n"; 51 list($action) = @each($content['button']); 52 switch($action) 53 { 54 case 'create': 55 $this->create($content); 56 break; 57 case 'delete': 58 $this->delete($content); 59 break; 60 default: 61 if (!$content['status']['create'] && !$content['status']['delete'] && 62 !$content['fields']['create'] && !$content['fields']['delete']) 63 { 64 break; // typ change 65 } 66 case 'save': 67 case 'apply': 68 $this->update($content); 69 if ($action != 'save') 70 { 71 break; 72 } 73 case 'cancel': 74 $GLOBALS['egw']->redirect_link('/admin/'); 75 exit; 76 } 77 } 78 else 79 { 80 list($typ) = each($this->types); 81 $content = array( 82 'typ' => $typ, 83 ); 84 } 85 $readonlys = array(); 86 $readonlys['button[delete]'] = isset($this->bo->stock_enums['type'][$content['typ']]); 87 88 $content['status'] = array( 89 'default' => $this->status['defaults'][$content['typ']] 90 ); 91 $n = 0; 92 foreach($this->status[$content['typ']] as $name => $label) 93 { 94 $content['status'][++$n] = array( 95 'name' => $name, 96 'label' => $label, 97 'disabled' => False 98 ); 99 $preserv_status[$n]['old_name'] = $name; 100 if (isset($this->bo->stock_status[$content['typ']][$name])) 101 { 102 $readonlys['status']["delete[$name]"] = 103 $readonlys['status'][$n.'[name]'] = True; 104 } 105 $readonlys['status']["create$name"] = True; 106 } 107 $content['status'][++$n] = array('name'=>''); // new line for create 108 $readonlys['status']["delete[]"] = True; 109 110 //echo 'customfields=<pre style="text-align: left;">'; print_r($this->fields); echo "</pre>\n"; 111 $content['fields'] = array(); 112 $n = 0; 113 foreach($this->fields as $name => $data) 114 { 115 if (is_array($data['values'])) 116 { 117 $values = ''; 118 foreach($data['values'] as $var => $value) 119 { 120 $values .= (!empty($values) ? "\n" : '').$var.'='.$value; 121 } 122 $data['values'] = $values; 123 } 124 $content['fields'][++$n] = $data + array( 125 'name' => $name 126 ); 127 $preserv_fields[$n]['old_name'] = $name; 128 $readonlys['fields']["create$name"] = True; 129 } 130 $content['fields'][++$n] = array('typ'=>'','order' => 10 * $n); // new line for create 131 $readonlys['fields']["delete[]"] = True; 132 133 //echo '<p>uicustomfields.edit(content = <pre style="text-align: left;">'; print_r($content); echo "</pre>\n"; 134 //echo 'readonlys = <pre style="text-align: left;">'; print_r($readonlys); echo "</pre>\n"; 135 $this->tmpl->read('infolog.customfields'); 136 $this->tmpl->exec('infolog.uicustomfields.edit',$content,array( 137 'typ' => $this->types, 138 ),$readonlys,array( 139 'status' => $preserv_status, 140 'fields' => $preserv_fields 141 )); 142 } 143 144 function update_fields(&$content) 145 { 146 $typ = $content['typ']; 147 $fields = &$content['fields']; 148 149 $create = $fields['create']; 150 unset($fields['create']); 151 152 if ($fields['delete']) 153 { 154 list($delete) = each($fields['delete']); 155 unset($fields['delete']); 156 } 157 158 foreach($fields as $field) 159 { 160 $name = trim($field['name']); 161 $old_name = $field['old_name']; 162 163 if (!empty($delete) && $delete == $old_name) 164 { 165 unset($this->fields[$old_name]); 166 continue; 167 } 168 if (isset($field['name']) && empty($name) && ($create || !empty($old_name))) // empty name not allowed 169 { 170 $content['error_msg'] = lang('Name must not be empty !!!'); 171 } 172 if (isset($field['old_name'])) 173 { 174 if (!empty($name) && $old_name != $name) // renamed 175 { 176 unset($this->fields[$old_name]); 177 } 178 elseif (empty($name)) 179 { 180 $name = $old_name; 181 } 182 } 183 elseif (empty($name)) // new item and empty ==> ignore it 184 { 185 continue; 186 } 187 $values = array(); 188 if (!empty($field['values'])) 189 { 190 foreach(explode("\n",$field['values']) as $line) 191 { 192 list($var,$value) = split('=',trim($line),2); 193 $var = trim($var); 194 $values[$var] = empty($value) ? $var : $value; 195 } 196 } 197 $this->fields[$name] = array( 198 'typ' => $field['typ'], 199 'label' => empty($field['label']) ? $name : $field['label'], 200 'help' => $field['help'], 201 'values'=> $values, 202 'len' => $field['len'], 203 'rows' => intval($field['rows']), 204 'order' => intval($field['order']) 205 ); 206 } 207 if (!function_exists('sort_by_order')) 208 { 209 function sort_by_order($arr1,$arr2) 210 { 211 return $arr1['order'] - $arr2['order']; 212 } 213 } 214 uasort($this->fields,sort_by_order); 215 216 $n = 0; 217 foreach($this->fields as $name => $data) 218 { 219 $this->fields[$name]['order'] = ($n += 10); 220 } 221 } 222 223 function update_status(&$content) 224 { 225 $typ = $content['typ']; 226 $status = &$content['status']; 227 228 $default = $status['default']; 229 unset($status['default']); 230 231 $create = $status['create']; 232 unset($status['create']); 233 234 if ($status['delete']) 235 { 236 list($delete) = each($status['delete']); 237 unset($status['delete']); 238 } 239 240 foreach($status as $stat) 241 { 242 $name = trim($stat['name']); 243 $old_name = $stat['old_name']; 244 245 if (!empty($delete) && $delete == $old_name) 246 { 247 unset($this->status[$typ][$old_name]); 248 continue; 249 } 250 if (isset($stat['name']) && empty($name) && ($create || !empty($old_name))) // empty name not allowed 251 { 252 $content['error_msg'] = lang('Name must not be empty !!!'); 253 } 254 if (isset($stat['old_name'])) 255 { 256 if (!empty($name) && $old_name != $name) // renamed 257 { 258 unset($this->status[$typ][$old_name]); 259 260 if ($default == $old_name) 261 { 262 $default = $name; 263 } 264 } 265 elseif (empty($name)) 266 { 267 $name = $old_name; 268 } 269 } 270 elseif (empty($name)) // new item and empty ==> ignore it 271 { 272 continue; 273 } 274 $this->status[$typ][$name] = empty($stat['label']) ? $name : $stat['label']; 275 } 276 $this->status['defaults'][$typ] = empty($default) ? $name : $default; 277 if (!isset($this->status[$typ][$this->status['defaults'][$typ]])) 278 { 279 list($this->status['defaults'][$typ]) = @each($this->status[$typ]); 280 } 281 } 282 283 function update(&$content) 284 { 285 $this->update_status($content); 286 $this->update_fields($content); 287 288 // save changes to repository 289 $this->save_repository(); 290 } 291 292 function delete(&$content) 293 { 294 if (isset($this->bo->stock_enums['type'][$content['typ']])) 295 { 296 $content['error_msg'] .= lang("You can't delete one of the stock types !!!"); 297 return; 298 } 299 unset($this->types[$content['typ']]); 300 unset($this->status[$content['typ']]); 301 unset($this->status['defaults'][$content['typ']]); 302 $content['typ'] = ''; 303 304 // save changes to repository 305 $this->save_repository(); 306 } 307 308 function create(&$content) 309 { 310 $new_name = trim($content['new_name']); 311 unset($content['new_name']); 312 if (empty($new_name) || isset($this->types[$new_name])) 313 { 314 $content['error_msg'] .= empty($new_name) ? 315 lang('You have to enter a name, to create a new typ!!!') : 316 lang("Typ '%1' already exists !!!",$new_name); 317 } 318 else 319 { 320 $this->types[$new_name] = $new_name; 321 $this->status[$new_name] = array( 322 'ongoing' => 'ongoing', 323 'done' => 'done' 324 ); 325 $this->status['defaults'][$new_name] = 'ongoing'; 326 327 // save changes to repository 328 $this->save_repository(); 329 330 $content['typ'] = $new_name; // show the new entry 331 } 332 } 333 334 function save_repository() 335 { 336 // save changes to repository 337 $this->config->value('types',$this->types); 338 //echo '<p>uicustomfields::save_repository() \$this->status=<pre style="text-aling: left;">'; print_r($this->status); echo "</pre>\n"; 339 $this->config->value('status',$this->status); 340 //echo '<p>uicustomfields::save_repository() \$this->fields=<pre style="text-aling: left;">'; print_r($this->fields); echo "</pre>\n"; 341 $this->config->value('customfields',$this->fields); 342 343 $this->config->save_repository(); 344 } 345 }
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 |