]> git.sur5r.net Git - contagged/blob - index.php
initial checkin
[contagged] / index.php
1 <?
2   require_once('init.php');
3   ldap_login();
4
5   //prepare filter
6   $ldapfilter = _makeldapfilter();
7
8   //check public addressbook
9   $sr = ldap_list($LDAP_CON,$conf[publicbook],$ldapfilter);
10   $result1 = ldap_get_binentries($LDAP_CON, $sr);
11   //check users private addressbook
12   if(!empty($_SESSION[ldapab][binddn])){
13     $sr = @ldap_list($LDAP_CON,
14                     $conf[privatebook].','.$_SESSION[ldapab][binddn],
15                     $ldapfilter);
16     $result2 = ldap_get_binentries($LDAP_CON, $sr);
17   }
18   
19   $result = array_merge($result1,$result2);
20
21   $list = '';
22   if(count($result)==1 && $_REQUEST[search]){
23     //only one result on a search -> display page
24     header("Location: entry.php?dn=".$result[0][dn]);
25     exit;
26   }elseif(count($result)){
27     $keys = array_keys($result);
28     uksort($keys,"_namesort");
29     foreach($keys as $key){
30       tpl_entry($result[$key]);
31       $list .= $smarty->fetch('list_entry.tpl');
32     }
33   }
34
35   //save location in session
36   $_SESSION[ldapab][lastlocation]=$_SERVER["REQUEST_URI"];
37    
38   //prepare templates
39   tpl_std();
40   tpl_markers();
41   $smarty->assign('list',$list);
42   //display templates
43   $smarty->display('header.tpl');
44   $smarty->display('list_filter.tpl');
45   $smarty->display('list.tpl');
46   $smarty->display('footer.tpl');
47
48   //------- functions -----------//
49
50   /**
51    * callback function to sort entries by name
52    * uses global $result
53    */
54   function _namesort($a,$b){
55     global $result;
56     $x = $result[$a][sn][0].$result[$a][givenName][0];
57     $y = $result[$b][sn][0].$result[$b][givenName][0];
58     return(strcasecmp($x,$y));
59   }
60
61
62   /**
63    * Creates an LDAP filter from given request variables search or filter
64    */
65   function _makeldapfilter(){
66     //handle given filter
67
68     $filter = $_REQUEST['filter'];
69     $search = $_REQUEST['search'];
70     $org    = $_REQUEST['org'];
71     $marker = $_REQUEST['marker'];
72     $_SESSION[ldapab][filter] = $filter;
73     if(empty($filter)) $filter='a';
74
75     if(!empty($marker)){
76       $marker = utf8_encode($marker);
77       $ldapfilter = "(&(objectClass=contactPerson)(marker=$marker))";
78     }elseif(!empty($search)){
79       $search = trim($search);
80       $words=preg_split('/\s+/',$search);
81       $filter='';
82       foreach($words as $word){
83         $word = utf8_encode($word);
84         $filter .= "(|(|(sn=*$word*)(givenName=*$word*))(o=*$word*))";
85       }
86       $ldapfilter = "(&(objectClass=inetOrgPerson)$filter)";
87     }elseif(!empty($org)){
88       $org = utf8_encode($org);
89       $ldapfilter = "(&(objectClass=inetOrgPerson)(o=$org))";
90     }elseif($filter=='other'){
91       $other='';
92       for ($i=ord('a');$i<=ord('z');$i++){
93         $other .= '(!(sn='.chr($i).'*))';
94       }
95       $ldapfilter = "(&(objectClass=inetOrgPerson)$other)";
96     }else{
97       $filter = utf8_encode($filter);
98       $ldapfilter = "(&(objectClass=inetOrgPerson)(sn=$filter*))";
99     }
100     return $ldapfilter;
101   }
102 ?>