4 * assigns some standard variables to smarty templates
12 if(empty($_SESSION['ldapab']['username'])){
13 $_SESSION['ldapab']['username'] = '';
15 if(empty($_SESSION['ldapab']['binddn'])){
16 $_SESSION['ldapab']['binddn'] = '';
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']);
24 $smarty->assign('home','index.php');
26 $smarty->assign('conf',$conf);
27 $smarty->assign('lang',$lang);
28 $smarty->assign('fields',$FIELDS);
29 $smarty->assign('lettertabs',explode(' ',$lang['lettertabs']));
31 if(isset($FIELDS['country'])){
32 include dirname(__FILE__).'/iso3166.php';
33 $smarty->assign('iso3166',$iso3166);
38 * assigns all the interesting data from an ldap result to
41 function tpl_entry($in){
48 // handle named entries
49 foreach($RFIELDS as $key => $name){
50 if(empty($in[$key])) continue;
52 // keep arrays for multi fields
54 $name = substr($name,1);
55 if(is_array($in[$key])){
56 $out[$name] = $in[$key];
58 $out[$name] = array($in[$key]);
61 if(is_array($in[$key])){
62 $out[$name] = $in[$key][0];
64 $out[$name] = $in[$key];
70 if (empty($out['dn'])) { $out['dn']=''; }
71 $out['dn'] = normalize_dn($out['dn']);
72 $conf['publicbook'] = normalize_dn($conf['publicbook']);
74 if(stristr($out['dn'],$conf['publicbook'])){
75 $out['type'] = 'public';
77 $out['type'] = 'private';
81 // join marker field to markers
82 if(is_array($out['marker'])) $out['markers'] = join(', ',$out['marker']);
84 $out['qrcode'] = tpl_qrcode($out);
92 $smarty->assign('entry',$out);
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);
105 return 'http://chart.apis.google.com/chart?cht=qr&chld=L|5&chs=500x500&chl='.$data.'&.png';
110 * assigns the last LDAP error to the template
112 function tpl_ldaperror($message=""){
114 global $__LDAPERROR__;
116 $errno = ldap_errno($LDAP_CON);
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)";
124 $__LDAPERROR__ .= '<br />';
126 $smarty->assign("LDAPERRORS",$__LDAPERROR__);
130 * assigns all markers to the template
132 function tpl_markers(){
137 if(!$conf['extended']) return;
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);
152 $result = array_merge((array)$result1,(array)$result2);
155 foreach ($result as $entry){
156 if(!empty($entry['marker']) && count($entry['marker'])){
157 foreach($entry['marker'] as $marker){
158 array_push($markers, $marker);
163 $markers = array_unique($markers);
164 sort($markers,SORT_STRING);
166 $smarty->assign('markers',$markers);
170 * Assigns all distinct organization names to the template
179 $result = ldap_queryabooks("ObjectClass=inetOrgPerson",array($FIELDS['organization']));
182 foreach ($result as $entry){
183 if(!empty($entry[$FIELDS['organization']][0])){
184 array_push($orgs, $entry[$FIELDS['organization']][0]);
188 $orgs = array_unique($orgs);
190 $smarty->assign('orgs',$orgs);
194 * assigns all categories to the template
196 function tpl_categories(){
201 if(!$conf['openxchange']) return;
203 $categories = array();
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);
214 $result = array_merge((array)$result1,(array)$result2);
217 foreach ($result as $entry){
218 if(count($entry['OXUserCategories'])){
219 foreach($entry['OXUserCategories'] as $category){
220 array_push($categories, $category);
225 $categories = array_unique($categories);
226 sort($categories,SORT_STRING);
228 $smarty->assign('categories',$categories);
232 * assigns all timezones to the template
234 function tpl_timezone(){
239 if(!$conf['openxchange']) return;
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);
252 $result = array_merge((array)$result1,(array)$result2);
255 foreach ($result as $entry){
256 if(count($entry['OXTimeZone'])){
257 foreach($entry['OXTimeZone'] as $tz){
258 array_push($timezone, $tz);
263 $timezone = array_unique($timezone);
264 sort($timezone,SORT_STRING);
266 $smarty->assign('timezone',$timezone);
270 * assigns all countries to the template
272 function tpl_country(){
277 if(!$conf['openxchange']) return;
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);
290 $result = array_merge((array)$result1,(array)$result2);
293 foreach ($result as $entry){
294 if(count($entry['userCountry'])){
295 foreach($entry['userCountry'] as $c){
296 array_push($country, $c);
301 $country = array_unique($country);
302 sort($country,SORT_STRING);
304 $smarty->assign('country',$country);