Issues (4868)

addressbook/inc/class.addressbook_hooks.inc.php (11 issues)

1
<?php
2
/**
3
 * EGroupware Addressbook - admin, preferences and sidebox-menus and other hooks
4
 *
5
 * @link http://www.egroupware.org
6
 * @package addressbook
7
 * @author Ralf Becker <[email protected]>
8
 * @copyright (c) 2006-16 by Ralf Becker <[email protected]>
9
 * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
10
 * @version $Id$
11
 */
12
13
use EGroupware\Api;
14
use EGroupware\Api\Link;
15
use EGroupware\Api\Framework;
16
use EGroupware\Api\Egw;
17
use EGroupware\Api\Acl;
18
19
/**
20
 * Class containing admin, preferences and sidebox-menus and other hooks
21
 */
22
class addressbook_hooks
23
{
24
	/**
25
	 * hooks to build projectmanager's sidebox-menu plus the admin and preferences sections
26
	 *
27
	 * @param string/array $args hook args
0 ignored issues
show
Documentation Bug introduced by
The doc comment string/array at position 0 could not be parsed: Unknown type name 'string/array' at position 0 in string/array.
Loading history...
28
	 */
29
	static function all_hooks($args)
30
	{
31
		$appname = 'addressbook';
32
		$location = is_array($args) ? $args['location'] : $args;
33
		//echo "<p>contacts_admin_prefs::all_hooks(".print_r($args,True).") appname='$appname', location='$location'</p>\n";
34
35
		if ($location == 'sidebox_menu')
36
		{
37
			if ($_GET['menuaction'] == 'addressbook.addressbook_ui.view')
38
			{
39
				display_sidebox($appname, lang('Contact data'), array(
0 ignored issues
show
Deprecated Code introduced by
The function display_sidebox() has been deprecated: use $GLOBALS['egw']->framework->sidebox() ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

39
				/** @scrutinizer ignore-deprecated */ display_sidebox($appname, lang('Contact data'), array(

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
40
					array(
41
						'text'    => '<div id="addressbook_view_sidebox"/>',
42
						'no_lang' => true,
43
						'link'    => false,
44
						'icon'    => false,
45
					),
46
					'menuOpened'  => true,	// display it open by default
47
				));
48
			}
49
			// Magic etemplate2 favorites menu (from nextmatch widget)
50
			display_sidebox($appname, lang('Favorites'), Framework\Favorites::list_favorites('addressbook'));
0 ignored issues
show
Deprecated Code introduced by
The function display_sidebox() has been deprecated: use $GLOBALS['egw']->framework->sidebox() ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

50
			/** @scrutinizer ignore-deprecated */ display_sidebox($appname, lang('Favorites'), Framework\Favorites::list_favorites('addressbook'));

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
51
52
			$file = array(
53
				'Addressbook list' => Egw::link('/index.php',array(
54
					'menuaction' => 'addressbook.addressbook_ui.index',
55
					'ajax' => 'true')),
56
				array(
57
					'text' => lang('Add %1',lang(Link::get_registry($appname, 'entry'))),
0 ignored issues
show
The call to lang() has too many arguments starting with lang(EGroupware\Api\Link...try($appname, 'entry')). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

57
					'text' => /** @scrutinizer ignore-call */ lang('Add %1',lang(Link::get_registry($appname, 'entry'))),

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
58
					'no_lang' => true,
59
					'link' => "javascript:egw.open('','$appname','add')"
60
				),
61
				'Advanced search' => "javascript:egw_openWindowCentered2('".
62
					Egw::link('/index.php',array('menuaction' => 'addressbook.addressbook_ui.search'),false).
63
					"','_blank',870,610,'yes')",
64
				'Placeholders'    => Egw::link('/index.php','menuaction=api.EGroupware\\Api\\Contacts\\Merge.show_replacements')
65
			);
66
			display_sidebox($appname,lang('Addressbook menu'),$file);
0 ignored issues
show
Deprecated Code introduced by
The function display_sidebox() has been deprecated: use $GLOBALS['egw']->framework->sidebox() ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

66
			/** @scrutinizer ignore-deprecated */ display_sidebox($appname,lang('Addressbook menu'),$file);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
67
		}
68
69
		if ($GLOBALS['egw_info']['user']['apps']['admin'] && $location != 'preferences')
70
		{
71
			$file = Array(
72
				'Site configuration' => Egw::link('/index.php',array(
73
					'menuaction' => 'admin.uiconfig.index',
74
					'appname'    => $appname,
75
					'ajax'       => 'true',
76
				)),
77
				'Global Categories'  => Egw::link('/index.php',array(
78
					'menuaction' => 'admin.admin_categories.index',
79
					'appname'    => $appname,
80
					'global_cats'=> True,
81
					'ajax'       => 'true',
82
				)),
83
			);
84
			// custom fields are not availible in LDAP
85
			if ($GLOBALS['egw_info']['server']['contact_repository'] != 'ldap')
86
			{
87
				$file['Custom fields'] = Egw::link('/index.php',array(
88
					'menuaction' => 'admin.admin_customfields.index',
89
					'appname'    => $appname,
90
					'use_private'=> 1,
91
					'ajax'       => 'true'
92
				));
93
			}
94
			if ($location == 'admin')
95
			{
96
				display_section($appname,$file);
97
			}
98
			else
99
			{
100
				display_sidebox($appname,lang('Admin'),$file);
0 ignored issues
show
Deprecated Code introduced by
The function display_sidebox() has been deprecated: use $GLOBALS['egw']->framework->sidebox() ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

100
				/** @scrutinizer ignore-deprecated */ display_sidebox($appname,lang('Admin'),$file);

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
101
			}
102
		}
103
	}
104
105
	/**
106
	 * populates $settings for the Api\Preferences
107
	 *
108
	 * @param array|string $hook_data
109
	 * @return array
110
	 */
111
	static function settings($hook_data)
112
	{
113
		$settings = array(
114
			array(
115
				'type'  => 'section',
116
				'title' => lang('General settings'),
117
				'no_lang'=> true,
118
				'xmlrpc' => False,
119
				'admin'  => False
120
			),
121
		);
122
		$settings['add_default'] = array(
123
			'type'   => 'select',
124
			'label'  => 'Default addressbook for adding contacts',
125
			'name'   => 'add_default',
126
			'help'   => 'Which addressbook should be selected when adding a contact AND you have no add rights to the current addressbook.',
127
			'values' => !$hook_data['setup'] ? ExecMethod('addressbook.addressbook_ui.get_addressbooks',Acl::ADD) : array(),
0 ignored issues
show
Deprecated Code introduced by
The function ExecMethod() has been deprecated: use autoloadable class-names, instanciate and call method or use static methods ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

127
			'values' => !$hook_data['setup'] ? /** @scrutinizer ignore-deprecated */ ExecMethod('addressbook.addressbook_ui.get_addressbooks',Acl::ADD) : array(),

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
128
			'xmlrpc' => True,
129
			'admin'  => False,
130
		);
131
		if ($GLOBALS['egw_info']['server']['contact_repository'] != 'ldap')
132
		{
133
			$settings['private_addressbook'] = array(
134
				'type'   => 'check',
135
				'label'  => 'Enable an extra private addressbook',
136
				'name'   => 'private_addressbook',
137
				'help'   => 'Do you want a private addressbook, which can not be viewed by users, you grant access to your personal addressbook?',
138
				'xmlrpc' => True,
139
				'admin'  => False,
140
				'forced' => false,
141
			);
142
		}
143
		$settings['hide_accounts'] = array(
144
			'type'   => 'select',
145
			'values' => array('1' => lang('Hide all accounts'), '0' => lang('Show active accounts'), 'none' => lang('Show all accounts')),
146
			'label'  => 'Hide accounts from addressbook',
147
			'name'   => 'hide_accounts',
148
			'help'   => 'Hides accounts completly from the adressbook.',
149
			'xmlrpc' => True,
150
			'admin'  => false,
151
			'default'=> '0'
152
		);
153
		$settings['hide_groups_as_lists'] = array(
154
			'type'   => 'check',
155
			'label'  => 'Hide user groups as distribution lists',
156
			'name'   => 'hide_groups_as_lists',
157
			'help'   => 'User groups are automatically shown as distribution lists.',
158
			'xmlrpc' => False,
159
			'admin'  => false,
160
			'default'=> '0'
161
		);
162
		$contacts = new Api\Contacts();
163
		$fileas_options = $contacts->fileas_options();
164
		foreach(Api\Contacts\Storage::$duplicate_fields as $key => $label)
165
		{
166
			$duplicate_options[$key] = lang($label);
167
		}
168
169
		$settings['link_title'] = array(
170
			'type'   => 'select',
171
			'label'  => 'Link title for contacts show',
172
			'name'   => 'link_title',
173
			'values' => array(
174
				'n_fileas' => lang('own sorting').' ('.lang('default').': '.lang('Company').': '.lang('lastname').', '.lang('firstname').')',
175
			)+$fileas_options,	// plus all fileas types
176
			'help'   => 'What should links to the addressbook display in other applications. Empty values will be left out. You need to log in anew, if you change this setting!',
177
			'xmlrpc' => True,
178
			'admin'  => false,
179
			'default'=> 'org_name: n_family, n_given',
180
		);
181
		if (($cf_opts = Api\Contacts::cf_options()))
182
		{
183
			$settings['link_title_cf'] = array(
184
				'type'  => 'multiselect',
185
				'label' => 'Add a customfield to link title',
186
				'name'  => 'link_title_cf',
187
				'values' => $cf_opts,
188
				'help'  =>  'Add customfield to links of addressbook, which displays in other applications. The default value is none customfield.',
189
				'xmlrpc' => True,
190
				'admin'  => false,
191
			);
192
		}
193
		$settings['addr_format'] = array(
194
			'type'   => 'select',
195
			'label'  => 'Default address format',
196
			'name'   => 'addr_format',
197
			'values' => array(
198
				'postcode_city' => lang('zip code').' '.lang('City'),
199
				'city_state_postcode' => lang('City').' '.lang('State').' '.lang('zip code'),
200
			),
201
			'help'   => 'Which address format should the addressbook use for countries it does not know the address format. If the address format of a country is known, it uses it independent of this setting.',
202
			'xmlrpc' => True,
203
			'admin'  => false,
204
			'default'=> 'postcode_city',
205
		);
206
		$settings['fileas_default'] = array(
207
			'type'   => 'select',
208
			'label'  => 'Default file as format',
209
			'name'   => 'fileas_default',
210
			'values' => $fileas_options,
211
			'help'   => 'Default format for fileas, eg. for new entries.',
212
			'xmlrpc' => True,
213
			'admin'  => false,
214
			'default'=> 'org_name: n_family, n_given',
215
		);
216
		$settings['duplicate_fields'] = array(
217
			'type'		=> 'multiselect',
218
			'label'		=> 'Fields to check for duplicates',
219
			'name'		=> 'duplicate_fields',
220
			'values'	=> $duplicate_options,
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $duplicate_options seems to be defined by a foreach iteration on line 164. Are you sure the iterator is never empty, otherwise this variable is not defined?
Loading history...
221
			'help'		=> 'Fields to consider when looking for duplicate contacts.',
222
			'admin'		=> false,
223
			'default'	=> 'n_family,org_name,contact_email'
224
		);
225
		$settings['duplicate_threshold'] = array(
226
			'type'   => 'input',
227
			'size'   => 5,
228
			'label'  => 'Duplicate threshold',
229
			'name'   => 'duplicate_threshold',
230
			'help'   => 'How many fields must match for the record to be considered a duplicate.',
231
			'xmlrpc' => True,
232
			'default'=> 3,
233
			'admin'  => False
234
		);
235
236
		$crm_list_options = array(
237
			'~edit~'    => lang('Edit contact'),
238
			'infolog' => lang('Open %1 CRM view', lang('infolog')),
0 ignored issues
show
The call to lang() has too many arguments starting with lang('infolog'). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

238
			'infolog' => /** @scrutinizer ignore-call */ lang('Open %1 CRM view', lang('infolog')),

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
239
			'infolog-organisation' => lang('infolog-organisation'),
240
		);
241
		if($GLOBALS['egw_info']['user']['apps']['tracker'])
242
		{
243
			$crm_list_options['tracker'] = lang('Open %1 CRM view', lang('tracker'));
244
		}
245
		$settings['crm_list'] = array(
246
			'type'   => 'select',
247
			'label'  => 'Default action on double-click',
248
			'name'   => 'crm_list',
249
			'values' => $crm_list_options,
250
			'help'   => 'When viewing a contact, show linked entries from the selected application',
251
			'xmlrpc' => True,
252
			'admin'  => false,
253
			'default'=> 'infolog',
254
		);
255
256
		$settings['geolocation_src'] = array(
257
			'type'   => 'select',
258
			'label'  => 'Default GeoLocation source address',
259
			'name'   => 'geolocation_src',
260
			'values' => array(
261
				'browser' => lang('Browser location'),
262
				'one' => lang('Business address'),
263
				'two' => lang('Private address')
264
			),
265
			'help'   => 'Select a source address to be used in GeoLocation routing system',
266
			'xmlrpc' => True,
267
			'admin'  => false,
268
			'default'=> 'browser',
269
		);
270
271
		$settings[] = array(
272
			'type'  => 'section',
273
			'title' => lang('Data exchange settings'),
274
			'no_lang'=> true,
275
			'xmlrpc' => False,
276
			'admin'  => False
277
		);
278
		// CSV Export
279
280
		if ($GLOBALS['egw_info']['user']['apps']['filemanager'])
281
		{
282
			$settings['default_document'] = array(
283
				'type'   => 'vfs_file',
284
				'size'   => 60,
285
				'label'  => 'Default document to insert contacts',
286
				'name'   => 'default_document',
287
				'help'   => lang('If you specify a document (full vfs path) here, %1 displays an extra document icon for each entry. That icon allows to download the specified document with the data inserted.', lang('addressbook')).' '.
288
					lang('The document can contain placeholder like {{%1}}, to be replaced with the data.','n_fn').' '.
289
					lang('The following document-types are supported:'). implode(',',Api\Storage\Merge::get_file_extensions()),
290
				'run_lang' => false,
291
				'xmlrpc' => True,
292
				'admin'  => False,
293
			);
294
			$settings['document_dir'] = array(
295
				'type'   => 'vfs_dirs',
296
				'size'   => 60,
297
				'label'  => 'Directory with documents to insert contacts',
298
				'name'   => 'document_dir',
299
				'help'   => lang('If you specify a directory (full vfs path) here, %1 displays an action for each document. That action allows to download the specified document with the data inserted.',lang('addressbook')).' '.
300
					lang('The document can contain placeholder like {{%1}}, to be replaced with the data.','n_fn').' '.
301
					lang('The following document-types are supported:'). implode(',',Api\Storage\Merge::get_file_extensions()),
302
				'run_lang' => false,
303
				'xmlrpc' => True,
304
				'admin'  => False,
305
				'default' => '/templates/addressbook',
306
			);
307
		}
308
309
		if ($GLOBALS['egw_info']['user']['apps']['felamimail'] || $GLOBALS['egw_info']['user']['apps']['mail'])
310
		{
311
			$settings['force_mailto'] = array(
312
				'type'   => 'check',
313
				'label'  => 'Open EMail addresses in external mail program',
314
				'name'   => 'force_mailto',
315
				'help'   => 'Default is to open EMail addresses in EGroupware EMail application, if user has access to it.',
316
				'xmlrpc' => True,
317
				'admin'  => False,
318
				'default'=> false,
319
			);
320
		}
321
322
		// Import / Export for nextmatch
323
		if ($GLOBALS['egw_info']['user']['apps']['importexport'])
324
		{
325
			$settings['vcard_charset'] = array(
326
				'type'   => 'select',
327
				'label'  => 'Charset for the vCard import and export',
328
				'name'   => 'vcard_charset',
329
				'values' => Api\Translation::get_installed_charsets(),
330
				'help'   => 'Which charset should be used for the vCard import and export.',
331
				'xmlrpc' => True,
332
				'admin'  => false,
333
				'default'=> 'utf-8',
334
			);
335
		}
336
		return $settings;
337
	}
338
339
	/**
340
	 * Hook called by link-class to include calendar in the appregistry of the linkage
341
	 *
342
	 * @param array/string $location location and other parameters (not used)
0 ignored issues
show
Documentation Bug introduced by
The doc comment array/string at position 0 could not be parsed: Unknown type name 'array/string' at position 0 in array/string.
Loading history...
343
	 * @return array with method-names
344
	 */
345
	static function search_link($location)
346
	{
347
		unset($location);	// not used, but required by function signature
348
349
		$links = array(
350
			'query' => 'api.EGroupware\\Api\\Contacts.link_query',
351
			'title' => 'api.EGroupware\\Api\\Contacts.link_title',
352
			'titles' => 'api.EGroupware\\Api\\Contacts.link_titles',
353
			'view' => array(
354
				'menuaction' => 'addressbook.addressbook_ui.view',
355
				'ajax' => 'true'
356
			),
357
			'view_id' => 'contact_id',
358
			'list'	=>	array(
359
				'menuaction' => 'addressbook.addressbook_ui.index',
360
				'ajax' => 'true'
361
			 ),
362
			'edit' => array(
363
				'menuaction' => 'addressbook.addressbook_ui.edit'
364
			),
365
			'edit_id' => 'contact_id',
366
			'edit_popup'  => '870x610',
367
			'add' => array(
368
				'menuaction' => 'addressbook.addressbook_ui.edit'
369
			),
370
			'add_app'    => 'link_app',
371
			'add_id'     => 'link_id',
372
			'add_popup'  => '870x610',
373
			'file_access_user' => true,	// file_access supports 4th parameter $user
374
			'file_access'=> 'api.EGroupware\\Api\\Contacts.file_access',
375
			'default_types' => array('n' => array('name' => 'contact', 'options' => array('icon' => 'navbar.png','template' => 'addressbook.edit'))),
376
			// registers an addtional type 'addressbook-email', returning only contacts with email, title has email appended
377
			'additional' => array(
378
				'addressbook-email' => array(
379
					'query' => 'api.EGroupware\\Api\\Contacts.link_query_email',
380
					'view' => array(
381
						'menuaction' => 'addressbook.addressbook_ui.view',
382
						'ajax' => 'true'
383
					),
384
					'view_id' => 'contact_id',
385
				),
386
			),
387
			'merge' => true,
388
			'entry' => 'Contact',
389
			'entries' => 'Contacts',
390
			'modification_time' => array(
391
				'key'    => 'contact_id',
392
				'column' => 'egw_addressbook.contact_modified',
393
				'type'   => 'int'
394
			),
395
			'owner' => array(
396
				'key'    => 'egw_addressbook.contact_id',
397
				'column' => 'egw_addressbook.contact_owner'
398
			)
399
		);
400
		return $links;
401
	}
402
403
	/**
404
	 * Hook called to retrieve a app specific exportLimit
405
	 *
406
	 * @param array/string $location location and other parameters (not used)
0 ignored issues
show
Documentation Bug introduced by
The doc comment array/string at position 0 could not be parsed: Unknown type name 'array/string' at position 0 in array/string.
Loading history...
407
	 * @return the export_limit to be applied for the app, may be empty, int or string
408
	 */
409
	static function getAppExportLimit($location)
410
	{
411
		unset($location);	// not used, but required by function signature
412
413
		return $GLOBALS['egw_info']['server']['contact_export_limit'];
414
	}
415
416
	/**
417
	 * Register contacts as calendar resources (items which can be sheduled by the calendar)
418
	 *
419
	 * @param array $args hook-params (not used)
420
	 * @return array
421
	 */
422
	static function calendar_resources($args)
423
	{
424
		unset($args);	// not used, but required by function signature
425
426
		return array(
427
			'type' => 'c',// one char type-identifiy for this resources
428
			'info' => 'api.EGroupware\\Api\\Contacts.calendar_info',// info method, returns array with id, type & name for a given id
429
		);
430
	}
431
432
	/**
433
	 * Register addressbook for group-acl
434
	 *
435
	 * @param array $args hook-params (not used)
436
	 * @return boolean|string true=standard group acl link, of string with link
437
	 */
438
	static function group_acl($args)
439
	{
440
		unset($args);	// not used, but required by function signature
441
442
		// addressbook uses group-acl, only if contacts-backend is NOT LDAP, as the ACL can not be modified there
443
		return $GLOBALS['egw_info']['server']['contact_repository'] != 'ldap';
444
	}
445
446
	/**
447
	 * For which groups should no group acl be used: addressbook always
448
	 *
449
	 * @param string|array $data
450
	 * @return boolean|array true, false or array with group-account_id's
451
	 */
452
	static function not_enum_group_acls($data)
453
	{
454
		unset($data);	// not used, but required by function signature
455
456
		return true;
457
	}
458
459
	/**
460
	 * ACL rights and labels used
461
	 *
462
	 * @param string|array string with location or array with parameters incl. "location", specially "owner" for selected Acl owner
463
	 * @return array Acl::(READ|ADD|EDIT|DELETE|PRIVAT|CUSTOM(1|2|3)) => $label pairs
464
	 */
465
	public static function acl_rights($params)
466
	{
467
		unset($params);	// not used, but required by function signature
468
469
		return array(
470
			Acl::READ    => 'read',
471
			Acl::EDIT    => 'edit',
472
			Acl::ADD     => 'add',
473
			Acl::DELETE  => 'delete',
474
		);
475
	}
476
477
	/**
478
	 * Hook to tell framework we use standard categories method
479
	 *
480
	 * @param string|array $data hook-data or location
481
	 * @return boolean
482
	 */
483
	public static function categories($data)
484
	{
485
		unset($data);	// not used, but required by function signature
486
487
		return true;
488
	}
489
490
	/**
491
	 * Called before displaying site configuration
492
	 *
493
	 * @param array $config
494
	 * @return array with additional config to merge and "sel_options" values
495
	 */
496
	public static function config(array $config)
497
	{
498
		$bocontacts = new Api\Contacts();
499
500
		// get the list of account fields
501
		$own_account_acl = array();
502
		foreach($bocontacts->contact_fields as $field => $label)
503
		{
504
			// some fields the user should never be allowed to edit or are covert by an other attribute (n_fn for all n_*)
505
			if (!in_array($field,array('id','tid','owner','created','creator','modified','modifier','private','n_prefix','n_given','n_middle','n_family','n_suffix')))
506
			{
507
				$own_account_acl[$field] = $label;
508
			}
509
		}
510
		$own_account_acl['link_to'] = 'Links';
511
		if ($config['account_repository'] != 'ldap')	// no custom-fields in ldap
512
		{
513
			foreach(Api\Storage\Customfields::get('addressbook') as $name => $data)
514
			{
515
				$own_account_acl['#'.$name] = $data['label'];
516
			}
517
		}
518
519
		$org_fields = $own_account_acl;
520
		unset($org_fields['n_fn'], $org_fields['account_id']);
521
		// Remove country codes as an option, it will be added by BO constructor
522
		unset($org_fields['adr_one_countrycode'], $org_fields['adr_two_countrycode']);
523
524
		$supported_fields = $bocontacts->get_fields('supported',null,0);	// fields supported by the backend (ldap schemas!)
525
		// get the list of account fields
526
		$copy_fields = array();
527
		foreach($bocontacts->contact_fields as $field => $label)
528
		{
529
			// some fields the user should never be allowed to copy or are coverted by an other attribute (n_fn for all n_*)
530
			if (!in_array($field,array('id','tid','created','creator','modified','modifier','account_id','uid','etag','n_fn')))
531
			{
532
				$copy_fields[$field] = $label;
533
			}
534
		}
535
		if ($config['contact_repository'] != 'ldap')	// no custom-fields in ldap
536
		{
537
			foreach(Api\Storage\Customfields::get('addressbook') as $name => $data)
538
			{
539
				$copy_fields['#'.$name] = $data['label'];
540
			}
541
		}
542
		// Remove country codes as an option, it will be added by UI constructor
543
		if(in_array('adr_one_countrycode', $supported_fields))
544
		{
545
			unset($copy_fields['adr_one_countrycode'], $copy_fields['adr_two_countrycode']);
546
		}
547
548
		$repositories = array('sql' => 'SQL');
549
		// check account-repository, contact-repository LDAP is only availible for account-repository == ldap
550
		if ($config['account_repository'] == 'ldap' || !$config['account_repository'] && $config['auth_type'] == 'ldap')
551
		{
552
			$repositories['ldap'] = 'LDAP';
553
			$repositories['sql-ldap'] = 'SQL --> LDAP ('.lang('read only').')';
554
		}
555
		// geolocation pre-defined maps
556
		$geoLocation = array(
557
			array('value' => 'https://maps.here.com/directions/drive{{%rs=/%rs}}%r0,%t0,%z0,%c0{{%d=/%d}}%r1,%t1,%z1+%c1', 'label' => 'Here Maps'),
558
			array('value' => 'http://maps.google.com/{{%rs=?saddr=%rs}}%r0+%t0+%z0+%c0{{%d=&daddr=%d}}%r1+%t1+%z1+%c1', 'label' => 'Google Maps'),
559
			array('value' => 'https://www.bing.com/maps/{{%rs=?rtp=adr.%rs}}%r0+%t0+%z0+%c0{{%d=~adr.%d}}%r1+%t1+%z1+%c1', 'label' => 'Bing Maps')
560
		);
561
		$ret = array(
562
			'sel_options' => array(
563
				'own_account_acl' => $own_account_acl,
564
				'org_fileds_to_update' => $org_fields,	// typo has to stay, as it was there allways and we would loose existing config :(
565
				'copy_fields' => $copy_fields,
566
				'fileas' => $bocontacts->fileas_options(),
567
				'contact_repository' => $repositories,
568
				'geolocation_url' => $geoLocation,
569
			)
570
		);
571
		foreach(Api\Storage\Customfields::get('addressbook') as $tid => $data)
572
		{
573
			$ret['sel_options']['index_load_cfs'][$tid] = $data['name'];
574
		}
575
576
		if (empty($config['geolocation_url']))	$ret ['geolocation_url'] = $geoLocation[0]['value'];
577
		return $ret;
578
	}
579
}
580