]> git.sur5r.net Git - contagged/blob - template.php
Catalan translation
[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   $orgs = array();
151
152   $sr = ldap_list($LDAP_CON,$conf['publicbook'],"ObjectClass=inetOrgPerson",array("o"));
153   $result1 = ldap_get_binentries($LDAP_CON, $sr);
154   //check users private addressbook
155   if(!empty($_SESSION['ldapab']['binddn'])){
156     $sr = @ldap_list($LDAP_CON,
157                     $conf['privatebook'].','.$_SESSION['ldapab']['binddn'],
158                     "ObjectClass=inetOrgPerson",array("o"));
159     $result2 = ldap_get_binentries($LDAP_CON, $sr);
160   }
161   $result = array_merge((array)$result1,(array)$result2);
162
163   if(count($result)){
164     foreach ($result as $entry){
165       if(!empty($entry['o'][0])){
166         array_push($orgs, $entry['o'][0]);
167       }
168     }
169   }
170   $orgs = array_unique($orgs);
171   sort($orgs,SORT_STRING);
172   $smarty->assign('orgs',$orgs);
173 }
174
175 /**
176  * assigns all categories to the template
177  */
178 function tpl_categories(){
179   global $conf;
180   global $LDAP_CON;
181   global $smarty;
182
183   if(!$conf['openxchange']) return;
184
185   $categories = array();
186
187   $sr = ldap_list($LDAP_CON,$conf['publicbook'],"ObjectClass=OXUserObject",array("OXUserCategories"));
188   $result1 = ldap_get_binentries($LDAP_CON, $sr);
189   //check users private addressbook
190   if(!empty($_SESSION['ldapab']['binddn'])){
191     $sr = @ldap_list($LDAP_CON,
192                     $conf['privatebook'].','.$_SESSION['ldapab']['binddn'],
193                     "ObjectClass=OXUserObject",array("OXUserCategories"));
194     $result2 = ldap_get_binentries($LDAP_CON, $sr);
195   }
196   $result = array_merge((array)$result1,(array)$result2);
197
198   if(count($result)){
199     foreach ($result as $entry){
200       if(count($entry['OXUserCategories'])){
201         foreach($entry['OXUserCategories'] as $category){
202           array_push($categories, $category);
203         }
204       }
205     }
206   }
207   $categories = array_unique($categories);
208   sort($categories,SORT_STRING);
209  
210   $smarty->assign('categories',$categories);
211 }
212
213 /**
214  * assigns all timezones to the template
215  */
216 function tpl_timezone(){
217   global $conf;
218   global $LDAP_CON;
219   global $smarty;
220
221   if(!$conf['openxchange']) return;
222
223   $timezone = array();
224
225   $sr = ldap_list($LDAP_CON,$conf['publicbook'],"ObjectClass=OXUserObject",array("OXTimeZone"));
226   $result1 = ldap_get_binentries($LDAP_CON, $sr);
227   //check users private addressbook
228   if(!empty($_SESSION['ldapab']['binddn'])){
229     $sr = @ldap_list($LDAP_CON,
230                     $conf['privatebook'].','.$_SESSION['ldapab']['binddn'],
231                     "ObjectClass=OXUserObject",array("OXTimeZone"));
232     $result2 = ldap_get_binentries($LDAP_CON, $sr);
233   }
234   $result = array_merge((array)$result1,(array)$result2);
235
236   if(count($result)){
237     foreach ($result as $entry){
238       if(count($entry['OXTimeZone'])){
239         foreach($entry['OXTimeZone'] as $tz){
240           array_push($timezone, $tz);
241         }
242       }
243     }
244   }
245   $timezone = array_unique($timezone);
246   sort($timezone,SORT_STRING);
247  
248   $smarty->assign('timezone',$timezone);
249 }
250
251 /**
252  * assigns all countries to the template
253  */
254 function tpl_country(){
255   global $conf;
256   global $LDAP_CON;
257   global $smarty;
258
259   if(!$conf['openxchange']) return;
260
261   $country = array();
262
263   $sr = ldap_list($LDAP_CON,$conf['publicbook'],"ObjectClass=OXUserObject",array("userCountry"));
264   $result1 = ldap_get_binentries($LDAP_CON, $sr);
265   //check users private addressbook
266   if(!empty($_SESSION['ldapab']['binddn'])){
267     $sr = @ldap_list($LDAP_CON,
268                     $conf['privatebook'].','.$_SESSION['ldapab']['binddn'],
269                     "ObjectClass=OXUserObject",array("userCountry"));
270     $result2 = ldap_get_binentries($LDAP_CON, $sr);
271   }
272   $result = array_merge((array)$result1,(array)$result2);
273
274   if(count($result)){
275     foreach ($result as $entry){
276       if(count($entry['userCountry'])){
277         foreach($entry['userCountry'] as $c){
278           array_push($country, $c);
279         }
280       }
281     }
282   }
283   $country = array_unique($country);
284   sort($country,SORT_STRING);
285  
286   $smarty->assign('country',$country);
287 }
288
289 ?>