[ Index ] |
|
Code source de eGroupWare 1.2.106-2 |
1 <?php 2 /**************************************************************************\ 3 * eGroupWare - Registration * 4 * http://www.egroupware.org * 5 * This file written by Jason Wies (Zone) <zone@users.sourceforge.net> * 6 * Based on calendar/inc/class.boholiday.inc.php by Mark Peters * 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.bomanagefields.inc.php 19547 2005-11-02 11:45:52Z ralfbecker $ */ 15 16 class bomanagefields 17 { 18 var $public_functions = Array( 19 'get_field_list' => True 20 ); 21 22 var $debug = False; 23 var $base_url = '/index.php'; 24 25 var $so; 26 var $fields; 27 28 function bomanagefields() 29 { 30 $this->so =& CreateObject ('registration.somanagefields'); 31 $this->fields = $this->get_field_list (); 32 } 33 34 function save_fields ($fields) 35 { 36 $current_fields = $this->get_field_list (); 37 38 $name_transforms = array ( 39 'email' => 'email', 40 'first_name' => 'n_given', 41 'last_name' => 'n_family', 42 'address' => 'adr_one_street', 43 'city' => 'adr_one_locality', 44 'state' => 'adr_one_region', 45 'zip' => 'adr_one_postalcode', 46 'country' => 'adr_one_countryname', 47 'gender' => 'gender', 48 'phone' => 'tel_work', 49 'birthday' => 'bday' 50 ); 51 52 reset ($fields); 53 while (list (,$field_info) = each ($fields)) 54 { 55 $orig_name = $field_info['field_name']; 56 unset ($changed); 57 58 if (($field_info['field_type'] == 'text' || $field_info['field_type'] == 'textarea' || $field_info['field_type'] == 'dropdown' || $field_info['field_type'] == 'checkbox') && !$field_info['field_name']) 59 { 60 continue; 61 } 62 63 reset ($name_transforms); 64 while (list ($type, $transform_name) = each ($name_transforms)) 65 { 66 if ($field_info['field_type'] == $type) 67 { 68 $field_info['field_name'] = $transform_name; 69 $changed = 1; 70 break; 71 } 72 } 73 74 if ($changed && ($field_info['field_name'] != $orig_name)) 75 { 76 unset ($this->fields[$orig_name]); 77 } 78 79 unset ($update); 80 81 if (is_array ($current_fields[$field_info['field_name']])) 82 { 83 $update = 1; 84 } 85 86 if (!$field_info['field_order']) 87 { 88 $field_info['field_order'] = $this->get_next_field_order ($fields); 89 } 90 91 if ($update) 92 { 93 if ($this->debug) 94 { 95 echo "<br>UPDATE - $field_info[field_name]"; 96 } 97 $this->so->update_field ($field_info); 98 } 99 else 100 { 101 if ($this->debug) 102 { 103 echo "<br>INSERT - $field_info[field_name]"; 104 } 105 $this->so->insert_field ($field_info); 106 } 107 } 108 109 reset ($current_fields); 110 while (list (,$field_info) = each ($current_fields)) 111 { 112 if (!is_array ($fields[$field_info['field_name']])) 113 { 114 if ($this->debug) 115 { 116 echo "<br>REMOVE - $field_info[field_name]"; 117 } 118 $this->so->remove_field ($field_info); 119 } 120 } 121 } 122 123 function get_field_list () 124 { 125 $fields = $this->so->get_field_list (); 126 127 $rarray = array (); 128 if (is_array ($fields)) 129 { 130 reset ($fields); 131 while (list ($num, $field_info) = each ($fields)) 132 { 133 /* Convert the stored database values into comma delimited form */ 134 135 $field_values = unserialize (base64_decode ($field_info['field_values'])); 136 $fields[$num]['field_values'] = $field_values; 137 138 $rarray[$field_info['field_name']] = $fields[$num]; 139 } 140 } 141 142 return $rarray; 143 } 144 145 function submit ($post_vars) 146 { 147 if (!is_array ($post_vars)) 148 { 149 return -1; 150 } 151 152 /* This is all we have to do to add a new entry. Neat, hun? */ 153 if ($post_vars['reg_new_name'] != 'reg_new' && !$post_vars['reg_new_remove']) 154 { 155 $this->fields[$post_vars['reg_new_name']] = array ( 156 'field_name' => 'reg_new' 157 ); 158 } 159 160 $fields = $this->fields; 161 reset ($fields); 162 while (list ($num, $field_info) = each ($fields)) 163 { 164 $name = $field_info['field_name']; 165 if ($post_vars[$name . '_remove']) 166 { 167 unset ($this->fields[$name]); 168 } 169 else 170 { 171 if ($post_vars[$name . '_name'] != $name) 172 { 173 unset ($this->fields[$name]); 174 } 175 176 $updated_field_info = array ( 177 'field_name' => $post_vars[$name . '_name'], 178 'field_text' => $post_vars[$name . '_text'], 179 'field_type' => $post_vars[$name . '_type'], 180 'field_values' => $post_vars[$name . '_values'], 181 'field_required' => $post_vars[$name . '_required'] ? 'Y' : 'N', 182 'field_order' => $post_vars[$name . '_order'] 183 ); 184 185 $this->fields[$post_vars[$name . '_name']] = $updated_field_info; 186 } 187 } 188 189 $rv = $this->save_fields ($this->fields); 190 191 return $rv; 192 } 193 194 function get_next_field_order ($fields) 195 { 196 reset ($fields); 197 while (list (,$field_info) = each ($fields)) 198 { 199 if ($field_info['field_order'] > $max) 200 { 201 $max = $field_info['field_order']; 202 } 203 } 204 205 return ($max + 1); 206 } 207 208 function check_admin() 209 { 210 $admin = False; 211 if (@$GLOBALS['egw_info']['user']['apps']['admin']) 212 { 213 $admin = True; 214 } 215 216 if (!$admin) 217 { 218 Header ('Location: ' . $GLOBALS['egw']->link ('/index.php')); 219 } 220 } 221 } 222 ?>
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 |