1<?php
2/**
3 * @package tikiwiki
4 */
5// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project
6//
7// All Rights Reserved. See copyright.txt for details and a complete list of authors.
8// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
9// $Id$
10
11$section = 'mytiki';
12require_once('tiki-setup.php');
13$contactlib = TikiLib::lib('contact');
14
15$access->check_feature('feature_contacts', '', 'community');
16$access->check_user($user);
17
18if (! isset($cookietab)) {
19	$cookietab = '1';
20}
21if (isset($_REQUEST['prefs'])) {
22	$tikilib->set_user_preference($user, 'user_contacts_default_view', $_REQUEST['user_contacts_default_view']);
23	$cookietab = '1';
24}
25$smarty->assign('user_contacts_default_view', $tikilib->get_user_preference($user, 'user_contacts_default_view'), 'group');
26if (isset($_REQUEST['ext_remove'])) {
27	$contactlib->remove_ext($user, $_REQUEST['ext_remove']);
28	$cookietab = 2;
29}
30if (isset($_REQUEST['ext_add'])) {
31	$contactlib->add_ext($user, $_REQUEST['ext_add']);
32	$cookietab = 2;
33}
34if (isset($_REQUEST['ext_show'])) {
35	$contactlib->modify_ext($user, $_REQUEST['ext_show'], ['show' => 'y']);
36	$cookietab = 2;
37}
38if (isset($_REQUEST['ext_hide'])) {
39	$contactlib->modify_ext($user, $_REQUEST['ext_hide'], ['show' => 'n']);
40	$cookietab = 2;
41}
42if (isset($_REQUEST['ext_public'])) {
43	$contactlib->modify_ext($user, $_REQUEST['ext_public'], ['flagsPublic' => 'y']);
44	$cookietab = 2;
45}
46if (isset($_REQUEST['ext_private'])) {
47	$contactlib->modify_ext($user, $_REQUEST['ext_private'], ['flagsPublic' => 'n']);
48	$cookietab = 2;
49}
50$exts = & $contactlib->get_ext_list($user);
51$nb_exts = count($exts);
52// consistancy check
53foreach ($exts as $k => $ext) {
54	if ($ext['order'] != $k) {
55		$contactlib->modify_ext($user, $ext['fieldId'], ['order' => $k]);
56	}
57}
58if (isset($_REQUEST['ext_up'])) {
59	if (is_array($exts)) {
60		foreach ($exts as $k => $ext) {
61			if ($k > 0 && $ext['fieldId'] == $_REQUEST['ext_up']) {
62				$contactlib->modify_ext($user, $_REQUEST['ext_up'], ['order' => $k - 1]);
63				$contactlib->modify_ext($user, $exts[$k - 1]['fieldId'], ['order' => $k]);
64				break;
65			}
66		}
67	}
68	$cookietab = 2;
69}
70if (isset($_REQUEST['ext_down'])) {
71	if (is_array($exts)) {
72		foreach ($exts as $k => $ext) {
73			if ($k < $nb_exts && $ext['fieldId'] == $_REQUEST['ext_down']) {
74				$contactlib->modify_ext($user, $_REQUEST['ext_down'], ['order' => $k + 1]);
75				$contactlib->modify_ext($user, $exts[$k + 1]['fieldId'], ['order' => $k]);
76				break;
77			}
78		}
79	}
80	$cookietab = 2;
81}
82$exts = $contactlib->get_ext_list($user);
83$smarty->assign('exts', $exts);
84
85include_once('tiki-mytiki_shared.php');
86//ask_ticket('user-contacts_prefs');
87include_once('tiki-section_options.php');
88$smarty->assign('mid', 'tiki-user_contacts_prefs.tpl');
89$smarty->display("tiki.tpl");
90