summaryrefslogtreecommitdiff
path: root/www/admin/addressbook/index.php
blob: 9ff597ed3bd81a2e02b8e0888a8025e4cf6bbda7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<?php
/*
 (c) 2004 Klaraedalens Datakonsult AB
 (c) 2003 Tassilo Erlewein <tassilo.erlewein@erfrakon.de>
 (c) 2003 Martin Konold <martin.konold@erfrakon.de>
 This program is Free Software under the GNU General Public License (>=v2).
 Read the file COPYING that comes with this packages for details.
*/

require_once('KolabAdmin/include/mysmarty.php');
require_once('KolabAdmin/include/headers.php');
require_once('KolabAdmin/include/locale.php');
require_once('KolabAdmin/include/authenticate.php');
require_once('KolabAdmin/include/form.class.php');

$errors = array();

/**** Authentication etc. ***/
$sidx = 'addressbook';

if( $auth->group() != 'maintainer' && $auth->group() != 'admin') {
  debug("auth->group=".$auth->group());
  array_push($errors, _("Error: You don't have Permissions to access this Menu"));
}

require_once('KolabAdmin/include/menu.php');

/**** Submenu for current page ***/
$menuitems[$sidx]['selected'] = 'selected';

/**** Extract data from LDAP ***/

// read selector for register display
if (isset($HTTP_GET_VARS['alphaselect'])) $alphaselect = $HTTP_GET_VARS['alphaselect'];
else $alphaselect = "[A-F]";
if (isset($HTTP_GET_VARS['page'])) $page = $HTTP_GET_VARS['page'];
else $page = "1";

// Get all entries & dynamically split the letters with growing entries
$entries = array();
if( !$errors ) {
  if (isset($_SESSION['base_dn'])) $base_dn = $_SESSION['base_dn'];
  else $base_dn = 'k=kolab';
  $userfilter = "cn=*";
  $filterattr = KolabForm::getRequestVar('filterattr');
  $filtertype = KolabForm::getRequestVar('filtertype');
  $filtervalue = KolabForm::getRequestVar('filtervalue');
  if( !in_array( $filterattr, array( 'cn', 'mail' ) ) ) $filterattr = 'cn';
  if( isset( $filtervalue ) && !empty( $filtervalue ) ) {
	switch( $filtertype ) {
	case 'contains': // contains
	  $userfilter = "$filterattr=*".$ldap->escape($filtervalue).'*';
	  break;
	case 'is': // is
	  $userfilter = "$filterattr=".$ldap->escape($filtervalue);
	  break;
	case 'begins': // begins with
	  $userfilter = "$filterattr=".$ldap->escape($filtervalue).'*';
	  break;
	case 'ends': // ends with
	  $userfilter = "$filterattr=*".$ldap->escape($filtervalue);
	  break;
	}
  }
  $alphalimit = '';
  if( isset( $_REQUEST['alphalimit']) ) {
	$ala='sn'; // alpha limit attibute
	switch( $_REQUEST['alphalimit'] ) {
	case 'a': $alphalimit = "(|($ala=a*)($ala=b*)($ala=c*)($ala=d*)($ala=e*)($ala=f*))"; break;
	case 'g': $alphalimit = "(|($ala=g*)($ala=h*)($ala=i*)($ala=j*)($ala=k*)($ala=l*))"; break;
	case 'm': $alphalimit = "(|($ala=m*)($ala=n*)($ala=o*)($ala=p*)($ala=q*)($ala=r*))"; break;
	case 's': $alphalimit = "(|($ala=s*)($ala=t*)($ala=u*)($ala=v*)($ala=w*)($ala=x*)($ala=y*)($ala=z*))"; break;
	case 'other': $alphalimit = "(|($ala=æ*)($ala=ø*)($ala=å*)($ala=ä*)($ala=ö*)($ala=ü*)($ala=0*)($ala=1*)($ala=2*)($ala=3*)($ala=4*)($ala=5*)($ala=6*)($ala=7*)($ala=8*)($ala=9*))"; break;
	default: $alphalimit = '';
	}
  }
  $filter = "(&($userfilter)$alphalimit(objectclass=inetOrgPerson)(!(uid=*))(sn=*))";
  $result = ldap_search($ldap->connection, $base_dn, $filter);
  if( $result ) {
	$count = ldap_count_entries($ldap->connection, $result);
	$title = "Manage Address Book ($count Addresses)";
	// if there are more than 2000 entries, split in 26 categories for every letter,
	// or if more than 50, put in groups, or else just show all.
	if ( false && $count > 2000) {
	  // ... TODO
	  $template = 'addrlistalpha.tpl';
	} else if( false && $count > 50 ) {
	  // ... TODO
	  $template = 'addrlistgroup.tpl';
	}  else {
	  $template = 'addrlistall.tpl';
	  ldap_sort($ldap->connection,$result,'sn');
	  $entry = ldap_first_entry($ldap->connection, $result);
	  while( $entry ) {
		$attrs = ldap_get_attributes($ldap->connection, $entry);
		$dn = ldap_get_dn($ldap->connection,$entry);
		$deleted = array_key_exists('kolabDeleteflag',$attrs)?$attrs['kolabDeleteflag'][0]:"FALSE";
		$mail = $attrs['mail'][0];
		$sn = $attrs['sn'][0];
		$cn = $attrs['cn'][0];
		$fn = KolabLDAP::getGivenName($cn, $sn);
		$entries[] = array( 'dn' => $dn,
							'sn' => $sn,
							'fn' => $fn,
							'mail' => $mail,
							'deleted' => $deleted );
		$entry = ldap_next_entry( $ldap->connection,$entry );
	  }
	}
  }
}

/**** Insert into template and output ***/
$smarty = new MySmarty();
$smarty->assign( 'errors', $errors );
$smarty->assign( 'uid', $auth->uid() );
$smarty->assign( 'group', $auth->group() );
$smarty->assign( 'page_title', $menuitems[$sidx]['title'] );
$smarty->assign( 'self_url', $_SERVER['PHP_SELF'] );

$smarty->assign( 'filterattrs', array( 'cn'   => _('Name'),
									   'mail' => _('Email') ) );
$smarty->assign( 'filtertypes', array( 'contains'   => _('contains'),
									   'is' => _('is'),
									   'begins'  => _('begins with'),
									   'ends'  => _('ends with') ) );
$smarty->assign( 'filterattr', $filterattr );
$smarty->assign( 'filtertype', $filtertype );
$smarty->assign( 'filtervalue', $filtervalue );

$smarty->assign( 'entries', $entries );
$smarty->assign( 'menuitems', $menuitems );
$smarty->assign( 'submenuitems', 
				 array_key_exists('submenu', 
								  $menuitems[$sidx])?$menuitems[$sidx]['submenu']:array() );
$smarty->assign( 'maincontent', $template );
$smarty->display('page.tpl');

/*
  Local variables:
  mode: php
  indent-tabs-mode: t
  tab-width: 4
  buffer-file-coding-system: utf-8
  End:
 */
?>