]> git.sur5r.net Git - contagged/blob - template.php
use the organization attribute from namedentries() instead of hardcoded o
[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   if(empty($_SESSION['ldapab']['username'])){
12     $_SESSION['ldapab']['username'] = '';
13   }
14   if(empty($_SESSION['ldapab']['binddn'])){
15     $_SESSION['ldapab']['binddn'] = '';
16   }
17
18   $smarty->assign('user',$_SESSION['ldapab']['username']);
19   $smarty->assign('binddn',$_SESSION['ldapab']['binddn']);
20   if(!empty($_SESSION['ldapab']['lastlocation'])){
21     $smarty->assign('home',$_SESSION['ldapab']['lastlocation']);
22   }else{
23      $smarty->assign('home','index.php');
24   }
25   $smarty->assign('conf',$conf);
26   $smarty->assign('lang',$lang);
27   //$smarty->assign('dfexample',$dfexample);
28 }
29
30 /**
31  * assigns all the interesting data from an ldap result to
32  * the smarty template
33  */
34 function tpl_entry($in){
35   global $smarty;
36   global $conf;
37   $entries = namedentries();
38   $out=array();
39
40   //handle named entries
41   foreach(array_keys($entries) as $key){
42     if(!empty($in[$key])){
43       if(is_array($in[$key])){
44         $out[$entries[$key]] = $in[$key][0];
45       }else{
46         $out[$entries[$key]] = $in[$key];
47       }
48     }
49   }
50
51   //set the type
52   if (empty($out['dn'])) { $out['dn']=''; }
53   $out['dn']          = normalize_dn($out['dn']);
54   $conf['publicbook'] = normalize_dn($conf['publicbook']);
55   if($out['dn']){
56     if(strstr($out['dn'],$conf['publicbook'])){
57       $out['type'] = 'public';
58     }else{
59       $out['type'] = 'private';
60     }
61   }
62
63   //mail entries are handled specially
64   if (empty($in['mail'])) { $in['mail']=''; }
65   $out['mail'] = $in['mail'];
66   if ($conf['extended']){
67     //handle marker specially in extended mode
68     if (empty($in['marker'])) { $in['marker']=''; }
69     $out['marker'] = $in['marker'];
70     if(is_array($in['marker'])) $out['markers'] = join(', ',$in['marker']);
71   }
72   if ($conf['openxchange']){
73     //handle categories specially in openxchange mode
74     $out['categories'] = $in['OXUserCategories'];
75   }
76
77 /*print '<pre>';
78 print_r($out);
79 print '</pre>';*/
80
81   $smarty->assign('entry',$out);
82 }
83
84 /**
85  * assigns the last LDAP error to the template
86  */
87 function tpl_ldaperror($message=""){
88   global $LDAP_CON;
89   global $__LDAPERROR__;
90   global $smarty;
91   $errno = ldap_errno($LDAP_CON);
92   if($errno){
93     $__LDAPERROR__ .= ldap_err2str($errno);
94     if(!empty($message)){
95       $__LDAPERROR__ .= "($message)";
96     }
97     $__LDAPERROR__ .= '\n';
98   }
99   $smarty->assign("LDAPERRORS",$__LDAPERROR__);
100 }
101
102 /**
103  * assigns all markers to the template
104  */
105 function tpl_markers(){
106   global $conf;
107   global $LDAP_CON;
108   global $smarty;
109
110   if(!$conf['extended']) return;
111
112   $markers = array();
113
114   $sr = ldap_list($LDAP_CON,$conf['publicbook'],"ObjectClass=inetOrgPerson",array("marker"));
115   $result1 = ldap_get_binentries($LDAP_CON, $sr);
116   //check users private addressbook
117   if(!empty($_SESSION['ldapab']['binddn'])){
118     $sr = @ldap_list($LDAP_CON,
119                     $conf['privatebook'].','.$_SESSION['ldapab']['binddn'],
120                     "ObjectClass=inetOrgPerson",array("marker"));
121     $result2 = ldap_get_binentries($LDAP_CON, $sr);
122   }else{
123     $result2 = '';
124   }
125   $result = array_merge((array)$result1,(array)$result2);
126
127   if(count($result)){
128     foreach ($result as $entry){
129       if(!empty($entry['marker']) && count($entry['marker'])){
130         foreach($entry['marker'] as $marker){
131           array_push($markers, $marker);
132         }
133       }
134     }
135   }
136   $markers = array_unique($markers);
137   sort($markers,SORT_STRING);
138  
139   $smarty->assign('markers',$markers);
140 }
141
142 /**
143  * Assigns all distinct organization names to the template
144  */
145 function tpl_orgs(){
146   global $conf;
147   global $LDAP_CON;
148   global $smarty;
149
150   $f_entries = namedentries(true);
151   
152   $orgs = array();
153
154   $sr = ldap_list($LDAP_CON,$conf['publicbook'],"ObjectClass=inetOrgPerson",array($f_entries['organization']));
155   $result1 = ldap_get_binentries($LDAP_CON, $sr);
156   //check users private addressbook
157   if(!empty($_SESSION['ldapab']['binddn'])){
158     $sr = @ldap_list($LDAP_CON,
159                     $conf['privatebook'].','.$_SESSION['ldapab']['binddn'],
160                     "ObjectClass=inetOrgPerson",array($f_entries['organization']));
161     $result2 = ldap_get_binentries($LDAP_CON, $sr);
162   }
163   $result = array_merge((array)$result1,(array)$result2);
164
165   if(count($result)){
166     foreach ($result as $entry){
167       if(!empty($entry[$f_entries['organization']][0])){
168         array_push($orgs, $entry[$f_entries['organization']][0]);
169       }
170     }
171   }
172   $orgs = array_unique($orgs);
173   sort($orgs,SORT_STRING);
174   $smarty->assign('orgs',$orgs);
175 }
176
177 /**
178  * assigns all categories to the template
179  */
180 function tpl_categories(){
181   global $conf;
182   global $LDAP_CON;
183   global $smarty;
184
185   if(!$conf['openxchange']) return;
186
187   $categories = array();
188
189   $sr = ldap_list($LDAP_CON,$conf['publicbook'],"ObjectClass=OXUserObject",array("OXUserCategories"));
190   $result1 = ldap_get_binentries($LDAP_CON, $sr);
191   //check users private addressbook
192   if(!empty($_SESSION['ldapab']['binddn'])){
193     $sr = @ldap_list($LDAP_CON,
194                     $conf['privatebook'].','.$_SESSION['ldapab']['binddn'],
195                     "ObjectClass=OXUserObject",array("OXUserCategories"));
196     $result2 = ldap_get_binentries($LDAP_CON, $sr);
197   }
198   $result = array_merge((array)$result1,(array)$result2);
199
200   if(count($result)){
201     foreach ($result as $entry){
202       if(count($entry['OXUserCategories'])){
203         foreach($entry['OXUserCategories'] as $category){
204           array_push($categories, $category);
205         }
206       }
207     }
208   }
209   $categories = array_unique($categories);
210   sort($categories,SORT_STRING);
211  
212   $smarty->assign('categories',$categories);
213 }
214
215 /**
216  * assigns all timezones to the template
217  */
218 function tpl_timezone(){
219   global $conf;
220   global $LDAP_CON;
221   global $smarty;
222
223   if(!$conf['openxchange']) return;
224
225   $timezone = array();
226
227   $sr = ldap_list($LDAP_CON,$conf['publicbook'],"ObjectClass=OXUserObject",array("OXTimeZone"));
228   $result1 = ldap_get_binentries($LDAP_CON, $sr);
229   //check users private addressbook
230   if(!empty($_SESSION['ldapab']['binddn'])){
231     $sr = @ldap_list($LDAP_CON,
232                     $conf['privatebook'].','.$_SESSION['ldapab']['binddn'],
233                     "ObjectClass=OXUserObject",array("OXTimeZone"));
234     $result2 = ldap_get_binentries($LDAP_CON, $sr);
235   }
236   $result = array_merge((array)$result1,(array)$result2);
237
238   if(count($result)){
239     foreach ($result as $entry){
240       if(count($entry['OXTimeZone'])){
241         foreach($entry['OXTimeZone'] as $tz){
242           array_push($timezone, $tz);
243         }
244       }
245     }
246   }
247   $timezone = array_unique($timezone);
248   sort($timezone,SORT_STRING);
249  
250   $smarty->assign('timezone',$timezone);
251 }
252
253 /**
254  * assigns all countries to the template
255  */
256 function tpl_country(){
257   global $conf;
258   global $LDAP_CON;
259   global $smarty;
260
261   if(!$conf['openxchange']) return;
262
263   $country = array();
264
265   $sr = ldap_list($LDAP_CON,$conf['publicbook'],"ObjectClass=OXUserObject",array("userCountry"));
266   $result1 = ldap_get_binentries($LDAP_CON, $sr);
267   //check users private addressbook
268   if(!empty($_SESSION['ldapab']['binddn'])){
269     $sr = @ldap_list($LDAP_CON,
270                     $conf['privatebook'].','.$_SESSION['ldapab']['binddn'],
271                     "ObjectClass=OXUserObject",array("userCountry"));
272     $result2 = ldap_get_binentries($LDAP_CON, $sr);
273   }
274   $result = array_merge((array)$result1,(array)$result2);
275
276   if(count($result)){
277     foreach ($result as $entry){
278       if(count($entry['userCountry'])){
279         foreach($entry['userCountry'] as $c){
280           array_push($country, $c);
281         }
282       }
283     }
284   }
285   $country = array_unique($country);
286   sort($country,SORT_STRING);
287  
288   $smarty->assign('country',$country);
289 }
290
291 ?>