[ Index ] |
|
Code source de eGroupWare 1.2.106-2 |
1 <?php 2 /**************************************************************************\ 3 * eGroupWare - IWATS - Intelligent Web Agent Ticket System * 4 * http://www.eGroupWare.org * 5 * Written by Drago Bokal <drago DOT bokal AT fmf DOT uni-lj DOT si> * 6 * Joe Stewart <joestewart AT users DOT sourceforge DOT net> * 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.et_media.inc.php,v 1.2 2002/10/19 11:11:03 ralfbecker Exp $ */ 15 16 include_once (EGW_INCLUDE_ROOT . '/etemplate/inc/class.so_sql.inc.php'); 17 $GLOBALS['egw_info']['flags']['included_classes']['so_sql'] = True; 18 19 20 /**! 21 @class generic_list 22 @author dragob 23 @abstract given a table and some e-templates enables listing, adding, editing and deleting the entries of the table 24 @discussion How to use generic_list 25 @discussion 1. Create a database table (using eTemplate DBTools). 26 @discussion Table must have an integer primary key. 27 @discussion Table may have an integer foreign key which represent a master-slave relationship 28 @discussion (in a one to many relationship, our table is on the "many" or "slave" side). 29 @discussion 2. Create a list entry template using eTemplate. 30 @discussion Template must contain a set of labels whose Name field must be set to 31 @discussion "${row}[field_name]", where field_name could be any field in the created table 32 @discussion Template must have Edit and Delete buttons, whose Name field must be set 33 @discussion edit[$row_cont[key_field]] and delete[$row_cont[key_field]] 34 @discussion Template may have other command buttons, whose Name field must be set to 35 @discussion command[$row_cont[key_field]] 36 @discussion 3. Create a list template using eTemplate. 37 @discussion Template must have a message row for displaying variable "msg" 38 @discussion Template must use list entry template as a subtemplate, and its Options must be 39 @discussion "entry". 40 @discussion Template must have an Add button whose Name is set to "add". 41 @discussion Template may have other command buttons, whose Name field must be set to 42 @discussion "command" 43 @discussion 4. Create an edit template using eTemplate. 44 @discussion Template must have a message row for displaying variable "msg" 45 @discussion Template must assume the variables will have the names of the table fields. 46 @discussion Template must have a Save button whose Name is set to "save". 47 @discussion Template must have a Cancel button whose Name is set to "cancel". 48 @discussion Template may have other command buttons, whose Name field must be set to 49 @discussion "command" 50 @discussion 5. Create an delete template using eTemplate. 51 @discussion Template must have a message row for displaying variable "msg" 52 @discussion Template must assume the variables will have the names of the table fields. 53 @discussion Template must have a Yes button whose Name is set to "yes". 54 @discussion Template must have a No button whose Name is set to "no". 55 @discussion Template may have other command buttons, whose Name field must be set to 56 @discussion "command" 57 @discussion 6. Create a file class.ui_myclass.inc.php looking like 58 @discussion 59 @discussion include_once(EGW_INCLUDE_ROOT . '/.../inc/class.generic_list.inc.php'); 60 @discussion $GLOBALS['egw_info']['flags']['included_classes']['generic_list'] = True; 61 @discussion 62 @discussion class ui_myclass extends generic_list 63 @discussion { 64 @discussion 65 @discussion function ui_myclass() 66 @discussion { 67 @discussion parent::create('my_application', 'my_table', 68 @discussion 'ui_myclass', 'key_field', 'my_list_template', 69 @discussion 'my_edit_template', 'my_add_template', 'my_delete_template', 70 @discussion 'master_fk_field'); 71 @discussion } 72 @discussion 73 @discussion } 74 @discussion 7. If the list or edit templates contain optional command buttons, 75 @discussion override the edit_elt method 76 @discussion function edit_elt($content='',$msg = '') 77 @discussion { 78 @discussion if (isset($content['my_command1'])) { 79 @discussion //process my_command1; 80 @discussion } 81 @discussion else if (isset($content['my_command2'])) { 82 @discussion //process my_command2; 83 @discussion } 84 @discussion else { 85 @discussion parent::edit_elt($content,$msg); 86 @discussion } 87 @discussion } 88 @discussion 8. If the delete templates contain optional command buttons, 89 @discussion override the delete_elt method in a similar fashion. 90 @discussion 91 @discussion 9. If any of the templates contain select lists, 92 @discussion override the get_sel_fields method. 93 @discussion 94 @discussion function get_sel_fields($content,$template) 95 @discussion { 96 @discussion if ($template==$this->edit_template) { 97 @discussion return( 98 @discussion array( // the options for our selectboxes for states 99 @discussion 'field_name1' => array( 100 @discussion 'key1'=>'value1', 101 @discussion 'key2'=>'value2', 102 @discussion 'key3'=>'value3' 103 @discussion ), 104 @discussion 'field_name2' => array( 105 @discussion 'key1'=>'value1', 106 @discussion 'key2'=>'value2', 107 @discussion 'key3'=>'value3' 108 @discussion ) 109 @discussion ) 110 @discussion ); 111 @discussion } 112 @discussion return array(); 113 @discussion } 114 @discussion 115 @discussion 10. If any of the templates contains fields that are not table fields, 116 @discussion override the preprocess_content method. This is useful if some integer 117 @discussion foreign key fields are to be replaced with their string descriptors. 118 @discussion 119 @discussion function preprocess_content($content,$template) 120 @discussion { 121 @discussion if ($template==$this->list_template) { 122 @discussion $content+=array( 123 @discussion 'new_field1'=>'value1', 124 @discussion 'new_field2'=>'value2', 125 @discussion 'new_field3'=>'value3' 126 @discussion ); 127 @discussion } 128 @discussion else if ($template==$this->edit_template) { 129 @discussion $content+=array( 130 @discussion ... 131 @discussion ); 132 @discussion } 133 @discussion return $content; 134 @discussion } 135 @discussion} 136 @discussion 11. If your table is in a master-slave relationship to some other, call 137 @discussion your class using some code similar to: 138 @discussion 139 @discussion ExecMethod('my_application.my_class.list_all', 140 @discussion array('master_key_field'=>master_key_value)); 141 @discussion exit; 142 @discussion 12. If your table is not in a master-slave relationship to some other, call 143 @discussion your class using some code similar to: 144 @discussion 145 @discussion ExecMethod('my_application.my_class.list_all'); 146 @discussion exit; 147 */ 148 149 class generic_list_so extends so_sql 150 { 151 var $application; 152 var $table; 153 var $class_name; 154 var $id; 155 var $master; 156 var $master_id; 157 158 function generic_list_so($app, $tab, $cls, $id, $mas='', $mas_val=0) 159 { 160 $this->application=$app; 161 $this->table=$tab; 162 $this->class_name=$app.'.'.$cls; 163 $this->id=$id; 164 $this->master=$mas; 165 $this->master_id=$mas_val; 166 167 $this->so_sql($this->application,$this->table); // sets up our storage layer using the table 168 $this->empty_on_write = "''"; // what to write in the db, if a column is empty, the default is NULL 169 170 } 171 172 function get_master_id() 173 { 174 return $this->master_id; 175 } 176 177 function check_master($content) 178 { 179 if (($this->master!='') && ($this->master_id==0)) { 180 if (isset($content[$this->master])) 181 $this->master_id=$content[$this->master]; 182 else 183 $this->master_id=$_GET[$this->master]; 184 } 185 return $this->master_id>0; 186 } 187 188 189 function list_elts() 190 { 191 if ($this->master_id>0) { 192 return $this->search($this->master.'='.$this->master_id,False); 193 } 194 else { 195 return $this->search('',False); 196 } 197 } 198 199 function get_data() 200 { 201 return $this->data; 202 } 203 204 function process_content(&$content) 205 { 206 if ($this->master_id>0) { 207 $content = $content+$this->get_master_array(); 208 } 209 210 if ($content[$this->id] > 0) // if we have an id --> read the entry 211 { 212 $this->read($content); 213 } 214 $this->data_merge($content); // merge content with our internal data-array ($this->data) 215 216 return $content; 217 } 218 219 function get_master_array() 220 { 221 return $this->master_id>0?array($this->master => $this->master_id):array(); 222 } 223 224 function get_id_array($master) 225 { 226 if ($master) { 227 return array($this->id => $this->data[$this->id])+$this->get_master_array(); 228 } 229 else { 230 return array($this->id => $this->data[$this->id]); 231 } 232 } 233 234 function get_id() 235 { 236 return $this->data[$this->id]; 237 } 238 239 function read_id($content) 240 { 241 if ($content[$this->id]>0) { 242 $this->read($content); 243 $this->data_merge($content); 244 return $content[$this->id]; 245 } 246 else { 247 $this->read(array($this->id=>$content)); 248 $content[$this->id]; 249 } 250 return False; 251 } 252 253 } 254
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 |