]> git.sur5r.net Git - contagged/blob - inc/template.php
93095a182e60d956c1e892403f7769cd4431c76e
[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 }
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   }
101   $smarty->assign("LDAPERRORS",$__LDAPERROR__);
102 }
103
104 /**
105  * assigns all markers to the template
106  */
107 function tpl_markers(){
108   global $conf;
109   global $LDAP_CON;
110   global $smarty;
111
112   if(!$conf['extended']) return;
113
114   $markers = array();
115
116   $sr = ldap_list($LDAP_CON,$conf['publicbook'],"ObjectClass=inetOrgPerson",array("marker"));
117   $result1 = ldap_get_binentries($LDAP_CON, $sr);
118   //check users private addressbook
119   if(!empty($_SESSION['ldapab']['binddn'])){
120     $sr = @ldap_list($LDAP_CON,
121                     $conf['privatebook'].','.$_SESSION['ldapab']['binddn'],
122                     "ObjectClass=inetOrgPerson",array("marker"));
123     $result2 = ldap_get_binentries($LDAP_CON, $sr);
124   }else{
125     $result2 = '';
126   }
127   $result = array_merge((array)$result1,(array)$result2);
128
129   if(count($result)){
130     foreach ($result as $entry){
131       if(!empty($entry['marker']) && count($entry['marker'])){
132         foreach($entry['marker'] as $marker){
133           array_push($markers, $marker);
134         }
135       }
136     }
137   }
138   $markers = array_unique($markers);
139   sort($markers,SORT_STRING);
140
141   $smarty->assign('markers',$markers);
142 }
143
144 /**
145  * Assigns all distinct organization names to the template
146  */
147 function tpl_orgs(){
148   global $conf;
149   global $LDAP_CON;
150   global $smarty;
151   global $FIELDS;
152
153   $orgs = array();
154   $result = ldap_queryabooks("ObjectClass=inetOrgPerson",array($FIELDS['organization']));
155
156   if(count($result)){
157     foreach ($result as $entry){
158       if(!empty($entry[$FIELDS['organization']][0])){
159         array_push($orgs, $entry[$FIELDS['organization']][0]);
160       }
161     }
162   }
163   $orgs = array_unique($orgs);
164   natcasesort($orgs);
165   $smarty->assign('orgs',$orgs);
166 }
167
168 /**
169  * assigns all categories to the template
170  */
171 function tpl_categories(){
172   global $conf;
173   global $LDAP_CON;
174   global $smarty;
175
176   if(!$conf['openxchange']) return;
177
178   $categories = array();
179
180   $sr = ldap_list($LDAP_CON,$conf['publicbook'],"ObjectClass=OXUserObject",array("OXUserCategories"));
181   $result1 = ldap_get_binentries($LDAP_CON, $sr);
182   //check users private addressbook
183   if(!empty($_SESSION['ldapab']['binddn'])){
184     $sr = @ldap_list($LDAP_CON,
185                     $conf['privatebook'].','.$_SESSION['ldapab']['binddn'],
186                     "ObjectClass=OXUserObject",array("OXUserCategories"));
187     $result2 = ldap_get_binentries($LDAP_CON, $sr);
188   }
189   $result = array_merge((array)$result1,(array)$result2);
190
191   if(count($result)){
192     foreach ($result as $entry){
193       if(count($entry['OXUserCategories'])){
194         foreach($entry['OXUserCategories'] as $category){
195           array_push($categories, $category);
196         }
197       }
198     }
199   }
200   $categories = array_unique($categories);
201   sort($categories,SORT_STRING);
202
203   $smarty->assign('categories',$categories);
204 }
205
206 /**
207  * assigns all timezones to the template
208  */
209 function tpl_timezone(){
210   global $conf;
211   global $LDAP_CON;
212   global $smarty;
213
214   if(!$conf['openxchange']) return;
215
216   $timezone = array();
217
218   $sr = ldap_list($LDAP_CON,$conf['publicbook'],"ObjectClass=OXUserObject",array("OXTimeZone"));
219   $result1 = ldap_get_binentries($LDAP_CON, $sr);
220   //check users private addressbook
221   if(!empty($_SESSION['ldapab']['binddn'])){
222     $sr = @ldap_list($LDAP_CON,
223                     $conf['privatebook'].','.$_SESSION['ldapab']['binddn'],
224                     "ObjectClass=OXUserObject",array("OXTimeZone"));
225     $result2 = ldap_get_binentries($LDAP_CON, $sr);
226   }
227   $result = array_merge((array)$result1,(array)$result2);
228
229   if(count($result)){
230     foreach ($result as $entry){
231       if(count($entry['OXTimeZone'])){
232         foreach($entry['OXTimeZone'] as $tz){
233           array_push($timezone, $tz);
234         }
235       }
236     }
237   }
238   $timezone = array_unique($timezone);
239   sort($timezone,SORT_STRING);
240
241   $smarty->assign('timezone',$timezone);
242 }
243
244 /**
245  * assigns all countries to the template
246  */
247 function tpl_country(){
248   global $conf;
249   global $LDAP_CON;
250   global $smarty;
251
252   if(!$conf['openxchange']) return;
253
254   $country = array();
255
256   $sr = ldap_list($LDAP_CON,$conf['publicbook'],"ObjectClass=OXUserObject",array("userCountry"));
257   $result1 = ldap_get_binentries($LDAP_CON, $sr);
258   //check users private addressbook
259   if(!empty($_SESSION['ldapab']['binddn'])){
260     $sr = @ldap_list($LDAP_CON,
261                     $conf['privatebook'].','.$_SESSION['ldapab']['binddn'],
262                     "ObjectClass=OXUserObject",array("userCountry"));
263     $result2 = ldap_get_binentries($LDAP_CON, $sr);
264   }
265   $result = array_merge((array)$result1,(array)$result2);
266
267   if(count($result)){
268     foreach ($result as $entry){
269       if(count($entry['userCountry'])){
270         foreach($entry['userCountry'] as $c){
271           array_push($country, $c);
272         }
273       }
274     }
275   }
276   $country = array_unique($country);
277   sort($country,SORT_STRING);
278
279   $smarty->assign('country',$country);
280 }
281
282 ?>