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