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__ .= '\n';
102 $smarty->assign("LDAPERRORS",$__LDAPERROR__);
106 * assigns all markers to the template
108 function tpl_markers(){
113 if(!$conf['extended']) return;
117 $sr = ldap_list($LDAP_CON,$conf['publicbook'],"ObjectClass=inetOrgPerson",array("marker"));
118 $result1 = ldap_get_binentries($LDAP_CON, $sr);
119 //check users private addressbook
120 if(!empty($_SESSION['ldapab']['binddn'])){
121 $sr = @ldap_list($LDAP_CON,
122 $conf['privatebook'].','.$_SESSION['ldapab']['binddn'],
123 "ObjectClass=inetOrgPerson",array("marker"));
124 $result2 = ldap_get_binentries($LDAP_CON, $sr);
128 $result = array_merge((array)$result1,(array)$result2);
131 foreach ($result as $entry){
132 if(!empty($entry['marker']) && count($entry['marker'])){
133 foreach($entry['marker'] as $marker){
134 array_push($markers, $marker);
139 $markers = array_unique($markers);
140 sort($markers,SORT_STRING);
142 $smarty->assign('markers',$markers);
146 * Assigns all distinct organization names to the template
155 $result = ldap_queryabooks("ObjectClass=inetOrgPerson",array($FIELDS['organization']));
158 foreach ($result as $entry){
159 if(!empty($entry[$FIELDS['organization']][0])){
160 array_push($orgs, $entry[$FIELDS['organization']][0]);
164 $orgs = array_unique($orgs);
166 $smarty->assign('orgs',$orgs);
170 * assigns all categories to the template
172 function tpl_categories(){
177 if(!$conf['openxchange']) return;
179 $categories = array();
181 $sr = ldap_list($LDAP_CON,$conf['publicbook'],"ObjectClass=OXUserObject",array("OXUserCategories"));
182 $result1 = ldap_get_binentries($LDAP_CON, $sr);
183 //check users private addressbook
184 if(!empty($_SESSION['ldapab']['binddn'])){
185 $sr = @ldap_list($LDAP_CON,
186 $conf['privatebook'].','.$_SESSION['ldapab']['binddn'],
187 "ObjectClass=OXUserObject",array("OXUserCategories"));
188 $result2 = ldap_get_binentries($LDAP_CON, $sr);
190 $result = array_merge((array)$result1,(array)$result2);
193 foreach ($result as $entry){
194 if(count($entry['OXUserCategories'])){
195 foreach($entry['OXUserCategories'] as $category){
196 array_push($categories, $category);
201 $categories = array_unique($categories);
202 sort($categories,SORT_STRING);
204 $smarty->assign('categories',$categories);
208 * assigns all timezones to the template
210 function tpl_timezone(){
215 if(!$conf['openxchange']) return;
219 $sr = ldap_list($LDAP_CON,$conf['publicbook'],"ObjectClass=OXUserObject",array("OXTimeZone"));
220 $result1 = ldap_get_binentries($LDAP_CON, $sr);
221 //check users private addressbook
222 if(!empty($_SESSION['ldapab']['binddn'])){
223 $sr = @ldap_list($LDAP_CON,
224 $conf['privatebook'].','.$_SESSION['ldapab']['binddn'],
225 "ObjectClass=OXUserObject",array("OXTimeZone"));
226 $result2 = ldap_get_binentries($LDAP_CON, $sr);
228 $result = array_merge((array)$result1,(array)$result2);
231 foreach ($result as $entry){
232 if(count($entry['OXTimeZone'])){
233 foreach($entry['OXTimeZone'] as $tz){
234 array_push($timezone, $tz);
239 $timezone = array_unique($timezone);
240 sort($timezone,SORT_STRING);
242 $smarty->assign('timezone',$timezone);
246 * assigns all countries to the template
248 function tpl_country(){
253 if(!$conf['openxchange']) return;
257 $sr = ldap_list($LDAP_CON,$conf['publicbook'],"ObjectClass=OXUserObject",array("userCountry"));
258 $result1 = ldap_get_binentries($LDAP_CON, $sr);
259 //check users private addressbook
260 if(!empty($_SESSION['ldapab']['binddn'])){
261 $sr = @ldap_list($LDAP_CON,
262 $conf['privatebook'].','.$_SESSION['ldapab']['binddn'],
263 "ObjectClass=OXUserObject",array("userCountry"));
264 $result2 = ldap_get_binentries($LDAP_CON, $sr);
266 $result = array_merge((array)$result1,(array)$result2);
269 foreach ($result as $entry){
270 if(count($entry['userCountry'])){
271 foreach($entry['userCountry'] as $c){
272 array_push($country, $c);
277 $country = array_unique($country);
278 sort($country,SORT_STRING);
280 $smarty->assign('country',$country);