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