]> git.sur5r.net Git - contagged/blob - template.php
7448a2424db58020ab41a35fd127b330e49e7362
[contagged] / template.php
1 <?
2
3 /**
4  * assigns some standard variables to smarty templates
5  */
6 function tpl_std(){
7   global $smarty;
8   global $lang;
9   global $conf;
10
11   $smarty->assign('user',$_SESSION[ldapab][username]);
12   $smarty->assign('binddn',$_SESSION[ldapab][binddn]);
13   if(!empty($_SESSION[ldapab][lastlocation])){
14     $smarty->assign('home',$_SESSION[ldapab][lastlocation]);
15   }else{
16      $smarty->assign('home','index.php');
17   }
18   $smarty->assign('conf',$conf);
19   $smarty->assign('lang',$lang);
20   $smarty->assign('dfexample',$dfexample);
21 }
22
23 /**
24  * assigns all the interesting data from an ldap result to
25  * the smarty template
26  */
27 function tpl_entry($in){
28   global $smarty;
29   global $conf;
30   $entries = namedentries();
31
32
33   //handle named entries
34   foreach(array_keys($entries) as $key){
35     if($in[$key]){
36       if(is_array($in[$key])){
37         $out[$entries[$key]] = $in[$key][0];
38       }else{
39         $out[$entries[$key]] = $in[$key];
40       }
41     }
42   }
43
44   //set the type
45   $out['dn']        = normalize_dn($out['dn']);
46   $conf[publicbook] = normalize_dn($conf[publicbook]);
47   if($out['dn']){
48     if(strstr($out['dn'],$conf[publicbook])){
49       $out[type] = 'public';
50     }else{
51       $out[type] = 'private';
52     }
53   }
54
55   //mail entries are handled special
56   $out['mail'] = $in['mail'];
57   if ($conf[extended]){
58     //handle marker special in extended mode
59     $out['marker'] = $in['marker'];
60   }
61
62   //decode array
63   utf8_decode_array($out);
64
65 /*print '<pre>';
66 print_r($out);
67 print '</pre>';*/
68
69   $smarty->assign('entry',$out);
70 }
71
72 /**
73  * assigns the last LDAP error to the template
74  */
75 function tpl_ldaperror($message=""){
76   global $LDAP_CON;
77   global $__LDAPERROR__;
78   global $smarty;
79   $errno = ldap_errno($LDAP_CON);
80   if($errno){
81     $__LDAPERROR__ .= ldap_err2str($errno);
82     if(!empty($message)){
83       $__LDAPERROR__ .= "($message)";
84     }
85     $__LDAPERROR__ .= '\n';
86   }
87   $smarty->assign("LDAPERRORS",$__LDAPERROR__);
88 }
89
90 /**
91  * assigns all markers to the template
92  */
93 function tpl_markers(){
94   global $conf;
95   global $LDAP_CON;
96   global $smarty;
97
98   if(!$conf[extended]) return;
99
100   $markers = array();
101
102   $sr = ldap_list($LDAP_CON,$conf[publicbook],"ObjectClass=inetOrgPerson",array("marker"));
103   $result1 = ldap_get_binentries($LDAP_CON, $sr);
104   //check users private addressbook
105   if(!empty($_SESSION[ldapab][binddn])){
106     $sr = @ldap_list($LDAP_CON,
107                     $conf[privatebook].','.$_SESSION[ldapab][binddn],
108                     "ObjectClass=inetOrgPerson",array("marker"));
109     $result2 = ldap_get_binentries($LDAP_CON, $sr);
110   }
111   $result = array_merge($result1,$result2);
112
113   if(count($result)){
114     foreach ($result as $entry){
115       if(count($entry['marker'])){
116         foreach($entry['marker'] as $marker){
117           array_push($markers, $marker);
118         }
119       }
120     }
121   }
122   $markers = array_unique($markers);
123   sort($markers,SORT_STRING);
124  
125   utf8_decode_array($markers);
126   $smarty->assign('markers',$markers);
127 }
128
129 /**
130  * Assigns all distinct organization names to the template
131  */
132 function tpl_orgs(){
133   global $conf;
134   global $LDAP_CON;
135   global $smarty;
136
137   $orgs = array();
138
139   $sr = ldap_list($LDAP_CON,$conf[publicbook],"ObjectClass=inetOrgPerson",array("o"));
140   $result1 = ldap_get_binentries($LDAP_CON, $sr);
141   //check users private addressbook
142   if(!empty($_SESSION[ldapab][binddn])){
143     $sr = @ldap_list($LDAP_CON,
144                     $conf[privatebook].','.$_SESSION[ldapab][binddn],
145                     "ObjectClass=inetOrgPerson",array("o"));
146     $result2 = ldap_get_binentries($LDAP_CON, $sr);
147   }
148   $result = array_merge($result1,$result2);
149
150   if(count($result)){
151     foreach ($result as $entry){
152       if(!empty($entry[o][0])){
153         array_push($orgs, $entry[o][0]);
154       }
155     }
156   }
157   $orgs = array_unique($orgs);
158   sort($orgs,SORT_STRING);
159   utf8_decode_array($orgs);
160   $smarty->assign('orgs',$orgs);
161 }
162
163 ?>