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