]> git.sur5r.net Git - contagged/blob - template.php
mod_auth_ldap, non-anon binding and openxchange support
[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   if ($conf[openxchange]){
62     //handle categories special in openxchange mode
63     $out['categories'] = $in['OXUserCategories'];
64   }
65
66   //decode array
67   utf8_decode_array($out);
68
69 /*print '<pre>';
70 print_r($out);
71 print '</pre>';*/
72
73   $smarty->assign('entry',$out);
74 }
75
76 /**
77  * assigns the last LDAP error to the template
78  */
79 function tpl_ldaperror($message=""){
80   global $LDAP_CON;
81   global $__LDAPERROR__;
82   global $smarty;
83   $errno = ldap_errno($LDAP_CON);
84   if($errno){
85     $__LDAPERROR__ .= ldap_err2str($errno);
86     if(!empty($message)){
87       $__LDAPERROR__ .= "($message)";
88     }
89     $__LDAPERROR__ .= '\n';
90   }
91   $smarty->assign("LDAPERRORS",$__LDAPERROR__);
92 }
93
94 /**
95  * assigns all markers to the template
96  */
97 function tpl_markers(){
98   global $conf;
99   global $LDAP_CON;
100   global $smarty;
101
102   if(!$conf[extended]) return;
103
104   $markers = array();
105
106   $sr = ldap_list($LDAP_CON,$conf[publicbook],"ObjectClass=inetOrgPerson",array("marker"));
107   $result1 = ldap_get_binentries($LDAP_CON, $sr);
108   //check users private addressbook
109   if(!empty($_SESSION[ldapab][binddn])){
110     $sr = @ldap_list($LDAP_CON,
111                     $conf[privatebook].','.$_SESSION[ldapab][binddn],
112                     "ObjectClass=inetOrgPerson",array("marker"));
113     $result2 = ldap_get_binentries($LDAP_CON, $sr);
114   }
115   $result = array_merge($result1,$result2);
116
117   if(count($result)){
118     foreach ($result as $entry){
119       if(count($entry['marker'])){
120         foreach($entry['marker'] as $marker){
121           array_push($markers, $marker);
122         }
123       }
124     }
125   }
126   $markers = array_unique($markers);
127   sort($markers,SORT_STRING);
128  
129   utf8_decode_array($markers);
130   $smarty->assign('markers',$markers);
131 }
132
133 /**
134  * Assigns all distinct organization names to the template
135  */
136 function tpl_orgs(){
137   global $conf;
138   global $LDAP_CON;
139   global $smarty;
140
141   $orgs = array();
142
143   $sr = ldap_list($LDAP_CON,$conf[publicbook],"ObjectClass=inetOrgPerson",array("o"));
144   $result1 = ldap_get_binentries($LDAP_CON, $sr);
145   //check users private addressbook
146   if(!empty($_SESSION[ldapab][binddn])){
147     $sr = @ldap_list($LDAP_CON,
148                     $conf[privatebook].','.$_SESSION[ldapab][binddn],
149                     "ObjectClass=inetOrgPerson",array("o"));
150     $result2 = ldap_get_binentries($LDAP_CON, $sr);
151   }
152   $result = array_merge($result1,$result2);
153
154   if(count($result)){
155     foreach ($result as $entry){
156       if(!empty($entry[o][0])){
157         array_push($orgs, $entry[o][0]);
158       }
159     }
160   }
161   $orgs = array_unique($orgs);
162   sort($orgs,SORT_STRING);
163   utf8_decode_array($orgs);
164   $smarty->assign('orgs',$orgs);
165 }
166
167 /**
168  * assigns all categories to the template
169  */
170 function tpl_categories(){
171   global $conf;
172   global $LDAP_CON;
173   global $smarty;
174
175   if(!$conf[openxchange]) return;
176
177   $categories = array();
178
179   $sr = ldap_list($LDAP_CON,$conf[publicbook],"ObjectClass=OXUserObject",array("OXUserCategories"));
180   $result1 = ldap_get_binentries($LDAP_CON, $sr);
181   //check users private addressbook
182   if(!empty($_SESSION[ldapab][binddn])){
183     $sr = @ldap_list($LDAP_CON,
184                     $conf[privatebook].','.$_SESSION[ldapab][binddn],
185                     "ObjectClass=OXUserObject",array("OXUserCategories"));
186     $result2 = ldap_get_binentries($LDAP_CON, $sr);
187   }
188   $result = array_merge($result1,$result2);
189
190   if(count($result)){
191     foreach ($result as $entry){
192       if(count($entry['OXUserCategories'])){
193         foreach($entry['OXUserCategories'] as $category){
194           array_push($categories, $category);
195         }
196       }
197     }
198   }
199   $categories = array_unique($categories);
200   sort($categories,SORT_STRING);
201  
202   utf8_decode_array($categories);
203   $smarty->assign('categories',$categories);
204 }
205
206 /**
207  * assigns all timezones to the template
208  */
209 function tpl_timezone(){
210   global $conf;
211   global $LDAP_CON;
212   global $smarty;
213
214   if(!$conf[openxchange]) return;
215
216   $timezone = array();
217
218   $sr = ldap_list($LDAP_CON,$conf[publicbook],"ObjectClass=OXUserObject",array("OXTimeZone"));
219   $result1 = ldap_get_binentries($LDAP_CON, $sr);
220   //check users private addressbook
221   if(!empty($_SESSION[ldapab][binddn])){
222     $sr = @ldap_list($LDAP_CON,
223                     $conf[privatebook].','.$_SESSION[ldapab][binddn],
224                     "ObjectClass=OXUserObject",array("OXTimeZone"));
225     $result2 = ldap_get_binentries($LDAP_CON, $sr);
226   }
227   $result = array_merge($result1,$result2);
228
229   if(count($result)){
230     foreach ($result as $entry){
231       if(count($entry['OXTimeZone'])){
232         foreach($entry['OXTimeZone'] as $tz){
233           array_push($timezone, $tz);
234         }
235       }
236     }
237   }
238   $timezone = array_unique($timezone);
239   sort($timezone,SORT_STRING);
240  
241   utf8_decode_array($timezone);
242   $smarty->assign('timezone',$timezone);
243 }
244
245 /**
246  * assigns all countries to the template
247  */
248 function tpl_country(){
249   global $conf;
250   global $LDAP_CON;
251   global $smarty;
252
253   if(!$conf[openxchange]) return;
254
255   $country = array();
256
257   $sr = ldap_list($LDAP_CON,$conf[publicbook],"ObjectClass=OXUserObject",array("userCountry"));
258   $result1 = ldap_get_binentries($LDAP_CON, $sr);
259   //check users private addressbook
260   if(!empty($_SESSION[ldapab][binddn])){
261     $sr = @ldap_list($LDAP_CON,
262                     $conf[privatebook].','.$_SESSION[ldapab][binddn],
263                     "ObjectClass=OXUserObject",array("userCountry"));
264     $result2 = ldap_get_binentries($LDAP_CON, $sr);
265   }
266   $result = array_merge($result1,$result2);
267
268   if(count($result)){
269     foreach ($result as $entry){
270       if(count($entry['userCountry'])){
271         foreach($entry['userCountry'] as $c){
272           array_push($country, $c);
273         }
274       }
275     }
276   }
277   $country = array_unique($country);
278   sort($country,SORT_STRING);
279  
280   utf8_decode_array($country);
281   $smarty->assign('country',$country);
282 }
283
284 ?>