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