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']));
33 * assigns all the interesting data from an ldap result to
36 function tpl_entry($in){
43 // handle named entries
44 foreach($RFIELDS as $key => $name){
45 if(empty($in[$key])) continue;
47 // keep arrays for multi fields
49 $name = substr($name,1);
50 if(is_array($in[$key])){
51 $out[$name] = $in[$key];
53 $out[$name] = array($in[$key]);
56 if(is_array($in[$key])){
57 $out[$name] = $in[$key][0];
59 $out[$name] = $in[$key];
65 if (empty($out['dn'])) { $out['dn']=''; }
66 $out['dn'] = normalize_dn($out['dn']);
67 $conf['publicbook'] = normalize_dn($conf['publicbook']);
69 if(stristr($out['dn'],$conf['publicbook'])){
70 $out['type'] = 'public';
72 $out['type'] = 'private';
76 // join marker field to markers
77 if(is_array($out['marker'])) $out['markers'] = join(', ',$out['marker']);
79 $out['qrcode'] = tpl_qrcode($out);
87 $smarty->assign('entry',$out);
90 function tpl_qrcode($in){
91 $data = "BEGIN:VCARD\n";
92 $data .= "N:{$in['name']};{$in['givenname']}\n";
93 if($in['mobile']) $data .= "TEL;CELL:{$in['mobile']}\n";
94 if($in['phone']) $data .= "TEL;WORK:{$in['phone']}\n";
95 if($in['homephone']) $data .= "TEL;HOME:{$in['homephone']}\n";
96 if($in['mail'][0]) $data .= "EMAIL:{$in['mail'][0]}\n";
98 $data = rawurlencode($data);
100 return 'http://chart.apis.google.com/chart?cht=qr&chld=L|5&chs=500x500&chl='.$data.'&.png';
105 * assigns the last LDAP error to the template
107 function tpl_ldaperror($message=""){
109 global $__LDAPERROR__;
111 $errno = ldap_errno($LDAP_CON);
113 $__LDAPERROR__ .= ldap_err2str($errno);
114 if(!empty($message)){
115 $__LDAPERROR__ .= "($message)";
116 }elseif($errno == 4){
117 $__LDAPERROR__ .= "(You need to increase this limit in your server config)";
119 $__LDAPERROR__ .= '<br />';
121 $smarty->assign("LDAPERRORS",$__LDAPERROR__);
125 * assigns all markers to the template
127 function tpl_markers(){
132 if(!$conf['extended']) return;
136 $sr = ldap_list($LDAP_CON,$conf['publicbook'],"ObjectClass=inetOrgPerson",array("marker"));
137 $result1 = ldap_get_binentries($LDAP_CON, $sr);
138 //check users private addressbook
139 if(!empty($_SESSION['ldapab']['binddn']) && $conf['privatebook']){
140 $sr = @ldap_list($LDAP_CON,
141 $conf['privatebook'].','.$_SESSION['ldapab']['binddn'],
142 "ObjectClass=inetOrgPerson",array("marker"));
143 $result2 = ldap_get_binentries($LDAP_CON, $sr);
147 $result = array_merge((array)$result1,(array)$result2);
150 foreach ($result as $entry){
151 if(!empty($entry['marker']) && count($entry['marker'])){
152 foreach($entry['marker'] as $marker){
153 array_push($markers, $marker);
158 $markers = array_unique($markers);
159 sort($markers,SORT_STRING);
161 $smarty->assign('markers',$markers);
165 * Assigns all distinct organization names to the template
174 $result = ldap_queryabooks("ObjectClass=inetOrgPerson",array($FIELDS['organization']));
177 foreach ($result as $entry){
178 if(!empty($entry[$FIELDS['organization']][0])){
179 array_push($orgs, $entry[$FIELDS['organization']][0]);
183 $orgs = array_unique($orgs);
185 $smarty->assign('orgs',$orgs);
189 * assigns all categories to the template
191 function tpl_categories(){
196 if(!$conf['openxchange']) return;
198 $categories = array();
200 $sr = ldap_list($LDAP_CON,$conf['publicbook'],"ObjectClass=OXUserObject",array("OXUserCategories"));
201 $result1 = ldap_get_binentries($LDAP_CON, $sr);
202 //check users private addressbook
203 if(!empty($_SESSION['ldapab']['binddn']) && $conf['privatebook']){
204 $sr = @ldap_list($LDAP_CON,
205 $conf['privatebook'].','.$_SESSION['ldapab']['binddn'],
206 "ObjectClass=OXUserObject",array("OXUserCategories"));
207 $result2 = ldap_get_binentries($LDAP_CON, $sr);
209 $result = array_merge((array)$result1,(array)$result2);
212 foreach ($result as $entry){
213 if(count($entry['OXUserCategories'])){
214 foreach($entry['OXUserCategories'] as $category){
215 array_push($categories, $category);
220 $categories = array_unique($categories);
221 sort($categories,SORT_STRING);
223 $smarty->assign('categories',$categories);
227 * assigns all timezones to the template
229 function tpl_timezone(){
234 if(!$conf['openxchange']) return;
238 $sr = ldap_list($LDAP_CON,$conf['publicbook'],"ObjectClass=OXUserObject",array("OXTimeZone"));
239 $result1 = ldap_get_binentries($LDAP_CON, $sr);
240 //check users private addressbook
241 if(!empty($_SESSION['ldapab']['binddn']) && $conf['privatebook']){
242 $sr = @ldap_list($LDAP_CON,
243 $conf['privatebook'].','.$_SESSION['ldapab']['binddn'],
244 "ObjectClass=OXUserObject",array("OXTimeZone"));
245 $result2 = ldap_get_binentries($LDAP_CON, $sr);
247 $result = array_merge((array)$result1,(array)$result2);
250 foreach ($result as $entry){
251 if(count($entry['OXTimeZone'])){
252 foreach($entry['OXTimeZone'] as $tz){
253 array_push($timezone, $tz);
258 $timezone = array_unique($timezone);
259 sort($timezone,SORT_STRING);
261 $smarty->assign('timezone',$timezone);
265 * assigns all countries to the template
267 function tpl_country(){
272 if(!$conf['openxchange']) return;
276 $sr = ldap_list($LDAP_CON,$conf['publicbook'],"ObjectClass=OXUserObject",array("userCountry"));
277 $result1 = ldap_get_binentries($LDAP_CON, $sr);
278 //check users private addressbook
279 if(!empty($_SESSION['ldapab']['binddn']) && $conf['privatebook']){
280 $sr = @ldap_list($LDAP_CON,
281 $conf['privatebook'].','.$_SESSION['ldapab']['binddn'],
282 "ObjectClass=OXUserObject",array("userCountry"));
283 $result2 = ldap_get_binentries($LDAP_CON, $sr);
285 $result = array_merge((array)$result1,(array)$result2);
288 foreach ($result as $entry){
289 if(count($entry['userCountry'])){
290 foreach($entry['userCountry'] as $c){
291 array_push($country, $c);
296 $country = array_unique($country);
297 sort($country,SORT_STRING);
299 $smarty->assign('country',$country);