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