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