@@ -20,7 +20,8 @@ discard block |
||
| 20 | 20 | * are in one assiozative array which is complely managed by {Im|Ex}port plugins |
| 21 | 21 | * @todo testing |
| 22 | 22 | */ |
| 23 | -class importexport_definition implements importexport_iface_egw_record { |
|
| 23 | +class importexport_definition implements importexport_iface_egw_record |
|
| 24 | +{ |
|
| 24 | 25 | |
| 25 | 26 | const _appname = 'importexport'; |
| 26 | 27 | const _defintion_talbe = 'egw_importexport_definitions'; |
@@ -65,26 +66,36 @@ discard block |
||
| 65 | 66 | * |
| 66 | 67 | * @param string $_identifier |
| 67 | 68 | */ |
| 68 | - public function __construct( $_identifier='' ) { |
|
| 69 | + public function __construct( $_identifier='' ) |
|
| 70 | + { |
|
| 69 | 71 | $this->so_sql = new Api\Storage\Base(self::_appname ,self::_defintion_talbe); |
| 70 | 72 | $this->user = $GLOBALS['egw_info']['user']['user_id']; |
| 71 | 73 | $this->is_admin = $GLOBALS['egw_info']['user']['apps']['admin'] || $GLOBALS['egw_setup'] ? true : false; |
| 72 | 74 | // compability to string identifiers |
| 73 | - if (!is_numeric($_identifier) && strlen($_identifier) > 3) $_identifier = $this->name2identifier($_identifier); |
|
| 75 | + if (!is_numeric($_identifier) && strlen($_identifier) > 3) |
|
| 76 | + { |
|
| 77 | + $_identifier = $this->name2identifier($_identifier); |
|
| 78 | + } |
|
| 74 | 79 | |
| 75 | - if ((int)$_identifier != 0) { |
|
| 80 | + if ((int)$_identifier != 0) |
|
| 81 | + { |
|
| 76 | 82 | $this->definition = $this->so_sql->read(array('definition_id' => $_identifier)); |
| 77 | - if ( empty( $this->definition ) ) { |
|
| 83 | + if ( empty( $this->definition ) ) |
|
| 84 | + { |
|
| 78 | 85 | throw new Exception('Error: No such definition with identifier :"'.$_identifier.'"!'); |
| 79 | 86 | } |
| 80 | - if ( !( importexport_definitions_bo::is_permitted($this->get_record_array()) || $this->is_admin)) { |
|
| 87 | + if ( !( importexport_definitions_bo::is_permitted($this->get_record_array()) || $this->is_admin)) |
|
| 88 | + { |
|
| 81 | 89 | throw new Exception('Error: User "'.$this->user.'" is not permitted to get definition with identifier "'.$_identifier.'"!'); |
| 82 | 90 | } |
| 83 | 91 | try |
| 84 | 92 | { |
| 85 | 93 | $options_data = importexport_arrayxml::xml2array( $this->definition['plugin_options'] ); |
| 86 | 94 | $this->definition['plugin_options'] = (array)$options_data['root']; |
| 87 | - if($this->definition['filter']) $filter = importexport_arrayxml::xml2array( $this->definition['filter'] ); |
|
| 95 | + if($this->definition['filter']) |
|
| 96 | + { |
|
| 97 | + $filter = importexport_arrayxml::xml2array( $this->definition['filter'] ); |
|
| 98 | + } |
|
| 88 | 99 | $this->definition['filter'] = $filter['root']; |
| 89 | 100 | } |
| 90 | 101 | catch (Exception $e) |
@@ -100,12 +111,15 @@ discard block |
||
| 100 | 111 | * @param string $_name |
| 101 | 112 | * @return int |
| 102 | 113 | */ |
| 103 | - private function name2identifier( $_name ) { |
|
| 114 | + private function name2identifier( $_name ) |
|
| 115 | + { |
|
| 104 | 116 | $identifiers = $this->so_sql->search(array('name' => $_name),true); |
| 105 | - if (isset($identifiers[1])) { |
|
| 117 | + if (isset($identifiers[1])) |
|
| 118 | + { |
|
| 106 | 119 | throw new Exception('Error: Definition: "'.$_name. '" is not unique! Can\'t convert to identifier'); |
| 107 | 120 | } |
| 108 | - if ( empty( $identifiers[0] ) ) { |
|
| 121 | + if ( empty( $identifiers[0] ) ) |
|
| 122 | + { |
|
| 109 | 123 | // not a good idea, till we don't have different exceptions so far |
| 110 | 124 | // throw new Exception('Error: No such definition :"'.$_name.'"!'); |
| 111 | 125 | $identifiers = array( array( 'definition_id' => 0 ) ); |
@@ -113,11 +127,14 @@ discard block |
||
| 113 | 127 | return $identifiers[0]['definition_id']; |
| 114 | 128 | } |
| 115 | 129 | |
| 116 | - public function __get($_attribute_name) { |
|
| 117 | - if (!array_key_exists($_attribute_name,$this->attributes)) { |
|
| 130 | + public function __get($_attribute_name) |
|
| 131 | + { |
|
| 132 | + if (!array_key_exists($_attribute_name,$this->attributes)) |
|
| 133 | + { |
|
| 118 | 134 | throw new Exception('Error: "'. $_attribute_name. '" is not an attribute defintion'); |
| 119 | 135 | } |
| 120 | - switch ($_attribute_name) { |
|
| 136 | + switch ($_attribute_name) |
|
| 137 | + { |
|
| 121 | 138 | case 'allowed_users' : |
| 122 | 139 | return $this->get_allowed_users(); |
| 123 | 140 | case 'plugin_options' : |
@@ -129,11 +146,14 @@ discard block |
||
| 129 | 146 | } |
| 130 | 147 | } |
| 131 | 148 | |
| 132 | - public function __set($_attribute_name,$_data) { |
|
| 133 | - if (!array_key_exists($_attribute_name,$this->attributes)) { |
|
| 149 | + public function __set($_attribute_name,$_data) |
|
| 150 | + { |
|
| 151 | + if (!array_key_exists($_attribute_name,$this->attributes)) |
|
| 152 | + { |
|
| 134 | 153 | throw new Exception('Error: "'. $_attribute_name. '" is not an attribute defintion'); |
| 135 | 154 | } |
| 136 | - switch ($_attribute_name) { |
|
| 155 | + switch ($_attribute_name) |
|
| 156 | + { |
|
| 137 | 157 | case 'allowed_users' : |
| 138 | 158 | return $this->set_allowed_users($_data); |
| 139 | 159 | case 'plugin_options' : |
@@ -151,7 +171,8 @@ discard block |
||
| 151 | 171 | * |
| 152 | 172 | * @return array |
| 153 | 173 | */ |
| 154 | - private function get_allowed_users() { |
|
| 174 | + private function get_allowed_users() |
|
| 175 | + { |
|
| 155 | 176 | return explode(',',substr($this->definition['allowed_users'],1,-1)); |
| 156 | 177 | } |
| 157 | 178 | |
@@ -160,7 +181,8 @@ discard block |
||
| 160 | 181 | * |
| 161 | 182 | * @param array $_allowed_users |
| 162 | 183 | */ |
| 163 | - private function set_allowed_users( $_allowed_users ) { |
|
| 184 | + private function set_allowed_users( $_allowed_users ) |
|
| 185 | + { |
|
| 164 | 186 | $this->definition['allowed_users'] = ','.implode(',',(array)$_allowed_users) .','; |
| 165 | 187 | } |
| 166 | 188 | |
@@ -169,7 +191,8 @@ discard block |
||
| 169 | 191 | * |
| 170 | 192 | * @return array |
| 171 | 193 | */ |
| 172 | - private function get_options() { |
|
| 194 | + private function get_options() |
|
| 195 | + { |
|
| 173 | 196 | return $this->definition['plugin_options']; |
| 174 | 197 | } |
| 175 | 198 | |
@@ -178,9 +201,11 @@ discard block |
||
| 178 | 201 | * |
| 179 | 202 | * @param array $options |
| 180 | 203 | */ |
| 181 | - private function set_options(array $_plugin_options) { |
|
| 204 | + private function set_options(array $_plugin_options) |
|
| 205 | + { |
|
| 182 | 206 | // Check conditions |
| 183 | - foreach ( $_plugin_options['conditions'] as $key => $condition ) { |
|
| 207 | + foreach ( $_plugin_options['conditions'] as $key => $condition ) |
|
| 208 | + { |
|
| 184 | 209 | if(!$condition['string']) |
| 185 | 210 | { |
| 186 | 211 | unset($_plugin_options['conditions'][$key]); |
@@ -194,7 +219,8 @@ discard block |
||
| 194 | 219 | * |
| 195 | 220 | * @return array |
| 196 | 221 | */ |
| 197 | - private function get_filter() { |
|
| 222 | + private function get_filter() |
|
| 223 | + { |
|
| 198 | 224 | return $this->definition['filter']; |
| 199 | 225 | } |
| 200 | 226 | |
@@ -203,7 +229,8 @@ discard block |
||
| 203 | 229 | * |
| 204 | 230 | * @param filter array of field => settings |
| 205 | 231 | */ |
| 206 | - private function set_filter(Array $filter) { |
|
| 232 | + private function set_filter(Array $filter) |
|
| 233 | + { |
|
| 207 | 234 | $this->definition['filter'] = $filter; |
| 208 | 235 | } |
| 209 | 236 | |
@@ -215,7 +242,8 @@ discard block |
||
| 215 | 242 | * |
| 216 | 243 | * @return array complete record as associative array |
| 217 | 244 | */ |
| 218 | - public function get_record_array() { |
|
| 245 | + public function get_record_array() |
|
| 246 | + { |
|
| 219 | 247 | $definition = $this->definition; |
| 220 | 248 | $definition['allowed_users'] = $this->get_allowed_users(); |
| 221 | 249 | $definition['plugin_options'] = $this->get_options(); |
@@ -228,7 +256,8 @@ discard block |
||
| 228 | 256 | * |
| 229 | 257 | *@return string tiltle |
| 230 | 258 | */ |
| 231 | - public function get_title() { |
|
| 259 | + public function get_title() |
|
| 260 | + { |
|
| 232 | 261 | return $this->definition['name']; |
| 233 | 262 | } |
| 234 | 263 | |
@@ -237,13 +266,16 @@ discard block |
||
| 237 | 266 | * |
| 238 | 267 | * @return void |
| 239 | 268 | */ |
| 240 | - public function set_record( array $_record ) { |
|
| 269 | + public function set_record( array $_record ) |
|
| 270 | + { |
|
| 241 | 271 | $this->definition = array_intersect_key( $_record, $this->attributes ); |
| 242 | 272 | |
| 243 | 273 | // anything which is not an attribute is perhaps a plugin_option. |
| 244 | 274 | // If not, it gets whiped out on save time. |
| 245 | - foreach ( $_record as $attribute => $value) { |
|
| 246 | - if ( !array_key_exists( $attribute, $this->attributes ) ) { |
|
| 275 | + foreach ( $_record as $attribute => $value) |
|
| 276 | + { |
|
| 277 | + if ( !array_key_exists( $attribute, $this->attributes ) ) |
|
| 278 | + { |
|
| 247 | 279 | $this->definition['plugin_options'][$attribute] = $value; |
| 248 | 280 | } |
| 249 | 281 | } |
@@ -261,7 +293,8 @@ discard block |
||
| 261 | 293 | * |
| 262 | 294 | * @return int identifier of this record |
| 263 | 295 | */ |
| 264 | - public function get_identifier() { |
|
| 296 | + public function get_identifier() |
|
| 297 | + { |
|
| 265 | 298 | return $this->definition['definition_id']; |
| 266 | 299 | } |
| 267 | 300 | |
@@ -272,7 +305,8 @@ discard block |
||
| 272 | 305 | * |
| 273 | 306 | * @return string Full URL of an icon, or appname/icon_name |
| 274 | 307 | */ |
| 275 | - public function get_icon() { |
|
| 308 | + public function get_icon() |
|
| 309 | + { |
|
| 276 | 310 | return self::_appname . '/navbar'; |
| 277 | 311 | } |
| 278 | 312 | |
@@ -281,8 +315,10 @@ discard block |
||
| 281 | 315 | * |
| 282 | 316 | * @return string identifier |
| 283 | 317 | */ |
| 284 | - public function save ( $_dst_identifier ) { |
|
| 285 | - if ( strlen($this->definition['name']) < 3 ) { |
|
| 318 | + public function save ( $_dst_identifier ) |
|
| 319 | + { |
|
| 320 | + if ( strlen($this->definition['name']) < 3 ) |
|
| 321 | + { |
|
| 286 | 322 | throw new Exception('Error: Can\'t save definition, no valid name given!'); |
| 287 | 323 | } |
| 288 | 324 | |
@@ -290,7 +326,8 @@ discard block |
||
| 290 | 326 | $this->so_sql->data['plugin_options'] = importexport_arrayxml::array2xml( $this->definition['plugin_options'] ); |
| 291 | 327 | $this->so_sql->data['filter'] = importexport_arrayxml::array2xml( $this->definition['filter'] ); |
| 292 | 328 | $this->so_sql->data['modified'] = time(); |
| 293 | - if ($this->so_sql->save( array( 'definition_id' => $_dst_identifier ))) { |
|
| 329 | + if ($this->so_sql->save( array( 'definition_id' => $_dst_identifier ))) |
|
| 330 | + { |
|
| 294 | 331 | throw new Exception('Error: Api\Storage\Base was not able to save definition: '.$this->get_identifier()); |
| 295 | 332 | } |
| 296 | 333 | |
@@ -303,7 +340,8 @@ discard block |
||
| 303 | 340 | * @param string $_dst_identifier |
| 304 | 341 | * @return string dst_identifier |
| 305 | 342 | */ |
| 306 | - public function copy ( $_dst_identifier ) { |
|
| 343 | + public function copy ( $_dst_identifier ) |
|
| 344 | + { |
|
| 307 | 345 | $dst_object = clone $this; |
| 308 | 346 | try { |
| 309 | 347 | $dst_object->set_owner($this->user); |
@@ -324,8 +362,10 @@ discard block |
||
| 324 | 362 | * @param string $_dst_identifier |
| 325 | 363 | * @return string dst_identifier |
| 326 | 364 | */ |
| 327 | - public function move ( $_dst_identifier ) { |
|
| 328 | - if ($this->user != $this->get_owner() && !$this->is_admin) { |
|
| 365 | + public function move ( $_dst_identifier ) |
|
| 366 | + { |
|
| 367 | + if ($this->user != $this->get_owner() && !$this->is_admin) |
|
| 368 | + { |
|
| 329 | 369 | throw('Error: User '. $this->user. 'does not have permissions to move definition '.$this->get_identifier()); |
| 330 | 370 | } |
| 331 | 371 | $old_object = clone $this; |
@@ -346,11 +386,14 @@ discard block |
||
| 346 | 386 | * @return void |
| 347 | 387 | * |
| 348 | 388 | */ |
| 349 | - public function delete () { |
|
| 350 | - if($this->user != $this->get_owner() && !$this->is_admin) { |
|
| 389 | + public function delete () |
|
| 390 | + { |
|
| 391 | + if($this->user != $this->get_owner() && !$this->is_admin) |
|
| 392 | + { |
|
| 351 | 393 | throw('Error: User '. $this->user. 'does not have permissions to delete definition '.$this->get_identifier()); |
| 352 | 394 | } |
| 353 | - if(!$this->so_sql->delete()) { |
|
| 395 | + if(!$this->so_sql->delete()) |
|
| 396 | + { |
|
| 354 | 397 | throw('Error: Api\Storage\Base was not able to delete definition: '.$this->get_identifier()); |
| 355 | 398 | } |
| 356 | 399 | } |
@@ -359,7 +402,8 @@ discard block |
||
| 359 | 402 | * destructor |
| 360 | 403 | * |
| 361 | 404 | */ |
| 362 | - public function __destruct() { |
|
| 405 | + public function __destruct() |
|
| 406 | + { |
|
| 363 | 407 | unset($this->so_sql); |
| 364 | 408 | } |
| 365 | 409 | |
@@ -46,11 +46,13 @@ discard block |
||
| 46 | 46 | 'title' => $cat['description'], |
| 47 | 47 | ); |
| 48 | 48 | } |
| 49 | - if(count($cat_list) > 0) { |
|
| 49 | + if(count($cat_list) > 0) |
|
| 50 | + { |
|
| 50 | 51 | $this->mapping_fields[lang('Categories')] = $cat_list; |
| 51 | 52 | } |
| 52 | 53 | |
| 53 | - foreach($bocontacts->customfields as $name => $data) { |
|
| 54 | + foreach($bocontacts->customfields as $name => $data) |
|
| 55 | + { |
|
| 54 | 56 | $this->mapping_fields['#'.$name] = $data['label']; |
| 55 | 57 | } |
| 56 | 58 | unset($this->mapping_fields['jpegphoto']); // can't cvs import that |
@@ -75,7 +77,8 @@ discard block |
||
| 75 | 77 | |
| 76 | 78 | function wizard_step50(&$content, &$sel_options, &$readonlys, &$preserv) |
| 77 | 79 | { |
| 78 | - if($content['field_mapping'][0] == lang('Categories')) { |
|
| 80 | + if($content['field_mapping'][0] == lang('Categories')) |
|
| 81 | + { |
|
| 79 | 82 | unset($content['field_mapping'][0]); |
| 80 | 83 | } |
| 81 | 84 | $result = parent::wizard_step50($content, $sel_options, $readonlys, $preserv); |
@@ -86,7 +89,10 @@ discard block |
||
| 86 | 89 | |
| 87 | 90 | function wizard_step60(&$content, &$sel_options, &$readonlys, &$preserv) |
| 88 | 91 | { |
| 89 | - if($this->debug) error_log('addressbook.importexport.addressbook_csv_import::wizard_step60->$content '.print_r($content,true)); |
|
| 92 | + if($this->debug) |
|
| 93 | + { |
|
| 94 | + error_log('addressbook.importexport.addressbook_csv_import::wizard_step60->$content '.print_r($content,true)); |
|
| 95 | + } |
|
| 90 | 96 | unset($content['no_owner_map']); |
| 91 | 97 | // return from step60 |
| 92 | 98 | if ($content['step'] == 'wizard_step60') |
@@ -108,13 +114,16 @@ discard block |
||
| 108 | 114 | { |
| 109 | 115 | $content['msg'] = $this->steps['wizard_step60']; |
| 110 | 116 | $content['step'] = 'wizard_step60'; |
| 111 | - if(!array_key_exists($content['contact_owner']) && $content['plugin_options']) { |
|
| 117 | + if(!array_key_exists($content['contact_owner']) && $content['plugin_options']) |
|
| 118 | + { |
|
| 112 | 119 | $content['contact_owner'] = $content['plugin_options']['contact_owner']; |
| 113 | 120 | } |
| 114 | - if(!array_key_exists($content['owner_from_csv']) && $content['plugin_options']) { |
|
| 121 | + if(!array_key_exists($content['owner_from_csv']) && $content['plugin_options']) |
|
| 122 | + { |
|
| 115 | 123 | $content['owner_from_csv'] = $content['plugin_options']['owner_from_csv']; |
| 116 | 124 | } |
| 117 | - if(!array_key_exists($content['change_owner']) && $content['plugin_options']) { |
|
| 125 | + if(!array_key_exists($content['change_owner']) && $content['plugin_options']) |
|
| 126 | + { |
|
| 118 | 127 | $content['change_owner'] = $content['plugin_options']['change_owner']; |
| 119 | 128 | } |
| 120 | 129 | |
@@ -124,7 +133,8 @@ discard block |
||
| 124 | 133 | { |
| 125 | 134 | $sel_options['contact_owner'][$content['contact_owner']] = lang("'%1' is not allowed ('%2')!", $content['contact_owner'], implode(',',array_keys($sel_options['contact_owner']))); |
| 126 | 135 | } |
| 127 | - if(!in_array('owner', $content['field_mapping'])) { |
|
| 136 | + if(!in_array('owner', $content['field_mapping'])) |
|
| 137 | + { |
|
| 128 | 138 | $content['no_owner_map'] = true; |
| 129 | 139 | } |
| 130 | 140 | |