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);
32 * assigns all the interesting data from an ldap result to
35 function tpl_entry($in){
42 // handle named entries
43 foreach($RFIELDS as $key => $name){
44 if(empty($in[$key])) continue;
46 // keep arrays for multi fields
48 $name = substr($name,1);
49 if(is_array($in[$key])){
50 $out[$name] = $in[$key];
52 $out[$name] = array($in[$key]);
55 if(is_array($in[$key])){
56 $out[$name] = $in[$key][0];
58 $out[$name] = $in[$key];
64 if (empty($out['dn'])) { $out['dn']=''; }
65 $out['dn'] = normalize_dn($out['dn']);
66 $conf['publicbook'] = normalize_dn($conf['publicbook']);
68 if(strstr($out['dn'],$conf['publicbook'])){
69 $out['type'] = 'public';
71 $out['type'] = 'private';
75 // join marker field to markers
76 if(is_array($out['marker'])) $out['markers'] = join(', ',$out['marker']);
84 $smarty->assign('entry',$out);
88 * assigns the last LDAP error to the template
90 function tpl_ldaperror($message=""){
92 global $__LDAPERROR__;
94 $errno = ldap_errno($LDAP_CON);
96 $__LDAPERROR__ .= ldap_err2str($errno);
98 $__LDAPERROR__ .= "($message)";
100 $__LDAPERROR__ .= "(You need to increase this limit in your server config)";
102 $__LDAPERROR__ .= '<br />';
104 $smarty->assign("LDAPERRORS",$__LDAPERROR__);
108 * assigns all markers to the template
110 function tpl_markers(){
115 if(!$conf['extended']) return;
119 $sr = ldap_list($LDAP_CON,$conf['publicbook'],"ObjectClass=inetOrgPerson",array("marker"));
120 $result1 = ldap_get_binentries($LDAP_CON, $sr);
121 //check users private addressbook
122 if(!empty($_SESSION['ldapab']['binddn'])){
123 $sr = @ldap_list($LDAP_CON,
124 $conf['privatebook'].','.$_SESSION['ldapab']['binddn'],
125 "ObjectClass=inetOrgPerson",array("marker"));
126 $result2 = ldap_get_binentries($LDAP_CON, $sr);
130 $result = array_merge((array)$result1,(array)$result2);
133 foreach ($result as $entry){
134 if(!empty($entry['marker']) && count($entry['marker'])){
135 foreach($entry['marker'] as $marker){
136 array_push($markers, $marker);
141 $markers = array_unique($markers);
142 sort($markers,SORT_STRING);
144 $smarty->assign('markers',$markers);
148 * Assigns all distinct organization names to the template
157 $result = ldap_queryabooks("ObjectClass=inetOrgPerson",array($FIELDS['organization']));
160 foreach ($result as $entry){
161 if(!empty($entry[$FIELDS['organization']][0])){
162 array_push($orgs, $entry[$FIELDS['organization']][0]);
166 $orgs = array_unique($orgs);
168 $smarty->assign('orgs',$orgs);
172 * assigns all categories to the template
174 function tpl_categories(){
179 if(!$conf['openxchange']) return;
181 $categories = array();
183 $sr = ldap_list($LDAP_CON,$conf['publicbook'],"ObjectClass=OXUserObject",array("OXUserCategories"));
184 $result1 = ldap_get_binentries($LDAP_CON, $sr);
185 //check users private addressbook
186 if(!empty($_SESSION['ldapab']['binddn'])){
187 $sr = @ldap_list($LDAP_CON,
188 $conf['privatebook'].','.$_SESSION['ldapab']['binddn'],
189 "ObjectClass=OXUserObject",array("OXUserCategories"));
190 $result2 = ldap_get_binentries($LDAP_CON, $sr);
192 $result = array_merge((array)$result1,(array)$result2);
195 foreach ($result as $entry){
196 if(count($entry['OXUserCategories'])){
197 foreach($entry['OXUserCategories'] as $category){
198 array_push($categories, $category);
203 $categories = array_unique($categories);
204 sort($categories,SORT_STRING);
206 $smarty->assign('categories',$categories);
210 * assigns all timezones to the template
212 function tpl_timezone(){
217 if(!$conf['openxchange']) return;
221 $sr = ldap_list($LDAP_CON,$conf['publicbook'],"ObjectClass=OXUserObject",array("OXTimeZone"));
222 $result1 = ldap_get_binentries($LDAP_CON, $sr);
223 //check users private addressbook
224 if(!empty($_SESSION['ldapab']['binddn'])){
225 $sr = @ldap_list($LDAP_CON,
226 $conf['privatebook'].','.$_SESSION['ldapab']['binddn'],
227 "ObjectClass=OXUserObject",array("OXTimeZone"));
228 $result2 = ldap_get_binentries($LDAP_CON, $sr);
230 $result = array_merge((array)$result1,(array)$result2);
233 foreach ($result as $entry){
234 if(count($entry['OXTimeZone'])){
235 foreach($entry['OXTimeZone'] as $tz){
236 array_push($timezone, $tz);
241 $timezone = array_unique($timezone);
242 sort($timezone,SORT_STRING);
244 $smarty->assign('timezone',$timezone);
248 * assigns all countries to the template
250 function tpl_country(){
255 if(!$conf['openxchange']) return;
259 $sr = ldap_list($LDAP_CON,$conf['publicbook'],"ObjectClass=OXUserObject",array("userCountry"));
260 $result1 = ldap_get_binentries($LDAP_CON, $sr);
261 //check users private addressbook
262 if(!empty($_SESSION['ldapab']['binddn'])){
263 $sr = @ldap_list($LDAP_CON,
264 $conf['privatebook'].','.$_SESSION['ldapab']['binddn'],
265 "ObjectClass=OXUserObject",array("userCountry"));
266 $result2 = ldap_get_binentries($LDAP_CON, $sr);
268 $result = array_merge((array)$result1,(array)$result2);
271 foreach ($result as $entry){
272 if(count($entry['userCountry'])){
273 foreach($entry['userCountry'] as $c){
274 array_push($country, $c);
279 $country = array_unique($country);
280 sort($country,SORT_STRING);
282 $smarty->assign('country',$country);