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(strstr($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']);
85 $smarty->assign('entry',$out);
89 * assigns the last LDAP error to the template
91 function tpl_ldaperror($message=""){
93 global $__LDAPERROR__;
95 $errno = ldap_errno($LDAP_CON);
97 $__LDAPERROR__ .= ldap_err2str($errno);
99 $__LDAPERROR__ .= "($message)";
100 }elseif($errno == 4){
101 $__LDAPERROR__ .= "(You need to increase this limit in your server config)";
103 $__LDAPERROR__ .= '<br />';
105 $smarty->assign("LDAPERRORS",$__LDAPERROR__);
109 * assigns all markers to the template
111 function tpl_markers(){
116 if(!$conf['extended']) return;
120 $sr = ldap_list($LDAP_CON,$conf['publicbook'],"ObjectClass=inetOrgPerson",array("marker"));
121 $result1 = ldap_get_binentries($LDAP_CON, $sr);
122 //check users private addressbook
123 if(!empty($_SESSION['ldapab']['binddn']) && $conf['privatebook']){
124 $sr = @ldap_list($LDAP_CON,
125 $conf['privatebook'].','.$_SESSION['ldapab']['binddn'],
126 "ObjectClass=inetOrgPerson",array("marker"));
127 $result2 = ldap_get_binentries($LDAP_CON, $sr);
131 $result = array_merge((array)$result1,(array)$result2);
134 foreach ($result as $entry){
135 if(!empty($entry['marker']) && count($entry['marker'])){
136 foreach($entry['marker'] as $marker){
137 array_push($markers, $marker);
142 $markers = array_unique($markers);
143 sort($markers,SORT_STRING);
145 $smarty->assign('markers',$markers);
149 * Assigns all distinct organization names to the template
158 $result = ldap_queryabooks("ObjectClass=inetOrgPerson",array($FIELDS['organization']));
161 foreach ($result as $entry){
162 if(!empty($entry[$FIELDS['organization']][0])){
163 array_push($orgs, $entry[$FIELDS['organization']][0]);
167 $orgs = array_unique($orgs);
169 $smarty->assign('orgs',$orgs);
173 * assigns all categories to the template
175 function tpl_categories(){
180 if(!$conf['openxchange']) return;
182 $categories = array();
184 $sr = ldap_list($LDAP_CON,$conf['publicbook'],"ObjectClass=OXUserObject",array("OXUserCategories"));
185 $result1 = ldap_get_binentries($LDAP_CON, $sr);
186 //check users private addressbook
187 if(!empty($_SESSION['ldapab']['binddn']) && $conf['privatebook']){
188 $sr = @ldap_list($LDAP_CON,
189 $conf['privatebook'].','.$_SESSION['ldapab']['binddn'],
190 "ObjectClass=OXUserObject",array("OXUserCategories"));
191 $result2 = ldap_get_binentries($LDAP_CON, $sr);
193 $result = array_merge((array)$result1,(array)$result2);
196 foreach ($result as $entry){
197 if(count($entry['OXUserCategories'])){
198 foreach($entry['OXUserCategories'] as $category){
199 array_push($categories, $category);
204 $categories = array_unique($categories);
205 sort($categories,SORT_STRING);
207 $smarty->assign('categories',$categories);
211 * assigns all timezones to the template
213 function tpl_timezone(){
218 if(!$conf['openxchange']) return;
222 $sr = ldap_list($LDAP_CON,$conf['publicbook'],"ObjectClass=OXUserObject",array("OXTimeZone"));
223 $result1 = ldap_get_binentries($LDAP_CON, $sr);
224 //check users private addressbook
225 if(!empty($_SESSION['ldapab']['binddn']) && $conf['privatebook']){
226 $sr = @ldap_list($LDAP_CON,
227 $conf['privatebook'].','.$_SESSION['ldapab']['binddn'],
228 "ObjectClass=OXUserObject",array("OXTimeZone"));
229 $result2 = ldap_get_binentries($LDAP_CON, $sr);
231 $result = array_merge((array)$result1,(array)$result2);
234 foreach ($result as $entry){
235 if(count($entry['OXTimeZone'])){
236 foreach($entry['OXTimeZone'] as $tz){
237 array_push($timezone, $tz);
242 $timezone = array_unique($timezone);
243 sort($timezone,SORT_STRING);
245 $smarty->assign('timezone',$timezone);
249 * assigns all countries to the template
251 function tpl_country(){
256 if(!$conf['openxchange']) return;
260 $sr = ldap_list($LDAP_CON,$conf['publicbook'],"ObjectClass=OXUserObject",array("userCountry"));
261 $result1 = ldap_get_binentries($LDAP_CON, $sr);
262 //check users private addressbook
263 if(!empty($_SESSION['ldapab']['binddn']) && $conf['privatebook']){
264 $sr = @ldap_list($LDAP_CON,
265 $conf['privatebook'].','.$_SESSION['ldapab']['binddn'],
266 "ObjectClass=OXUserObject",array("userCountry"));
267 $result2 = ldap_get_binentries($LDAP_CON, $sr);
269 $result = array_merge((array)$result1,(array)$result2);
272 foreach ($result as $entry){
273 if(count($entry['userCountry'])){
274 foreach($entry['userCountry'] as $c){
275 array_push($country, $c);
280 $country = array_unique($country);
281 sort($country,SORT_STRING);
283 $smarty->assign('country',$country);