[387] | 1 | <?php |
---|
[2360] | 2 | |
---|
| 3 | /*************************************************************************** |
---|
| 4 | * Expresso Livre * |
---|
| 5 | * http://www.expressolivre.org * |
---|
| 6 | * -------------------------------------------- * |
---|
| 7 | * This program is free software; you can redistribute it and/or modify it * |
---|
| 8 | * under the terms of the GNU General Public License as published by the * |
---|
| 9 | * Free Software Foundation; either version 2 of the License, or (at your * |
---|
| 10 | * option) any later version. * |
---|
| 11 | \**************************************************************************/ |
---|
[176] | 12 | include_once("class.imap_functions.inc.php"); |
---|
[342] | 13 | include_once("class.functions.inc.php"); |
---|
[176] | 14 | |
---|
| 15 | function ldapRebind($ldap_connection, $ldap_url) |
---|
| 16 | { |
---|
| 17 | @ldap_bind($ldap_connection, $_SESSION['phpgw_info']['expressomail']['ldap_server']['acc'],$_SESSION['phpgw_info']['expressomail']['ldap_server']['pw']); |
---|
| 18 | } |
---|
[387] | 19 | |
---|
[2] | 20 | class ldap_functions |
---|
| 21 | { |
---|
| 22 | var $ds; |
---|
| 23 | var $ldap_host; |
---|
| 24 | var $ldap_context; |
---|
| 25 | var $imap; |
---|
[342] | 26 | var $external_srcs; |
---|
| 27 | var $max_result; |
---|
| 28 | var $functions; |
---|
| 29 | function ldap_functions(){ |
---|
| 30 | // todo: Page Configuration for External Catalogs. |
---|
| 31 | @include("../contactcenter/setup/external_catalogs.inc.php"); |
---|
[1740] | 32 | $this->external_srcs= ( isset( $external_srcs ) ) ? $external_srcs : NULL; |
---|
[387] | 33 | $this->max_result = 200; |
---|
| 34 | $this->functions = new functions(); |
---|
| 35 | } |
---|
[342] | 36 | // Using ContactCenter configuration. |
---|
| 37 | function ldapConnect($refer = false,$catalog = 0){ |
---|
| 38 | if ($catalog > 0 && is_array($this->external_srcs)){ |
---|
| 39 | $this->ldap_host = $this->external_srcs[$catalog]['host']; |
---|
| 40 | $this->ldap_context = $this->external_srcs[$catalog]['dn']; |
---|
| 41 | $this->bind_dn = $this->external_srcs[$catalog]['acc']; |
---|
| 42 | $this->bind_dn_pw = $this->external_srcs[$catalog]['pw']; |
---|
| 43 | $this->object_class = $this->external_srcs[$catalog]['obj']; |
---|
| 44 | $this->base_dn = $this->external_srcs[$catalog]['dn']; |
---|
| 45 | $this->branch = $this->external_srcs[$catalog]['branch']; |
---|
| 46 | }else { |
---|
[325] | 47 | $this->ldap_host = $_SESSION['phpgw_info']['expressomail']['ldap_server']['host']; |
---|
| 48 | $this->ldap_context = $_SESSION['phpgw_info']['expressomail']['ldap_server']['dn']; |
---|
| 49 | $this->bind_dn = $_SESSION['phpgw_info']['expressomail']['ldap_server']['acc']; |
---|
| 50 | $this->bind_dn_pw = $_SESSION['phpgw_info']['expressomail']['ldap_server']['pw']; |
---|
[387] | 51 | $this->branch = 'ou'; |
---|
[325] | 52 | } |
---|
[387] | 53 | |
---|
[325] | 54 | $this->ds = ldap_connect($this->ldap_host); |
---|
[2] | 55 | ldap_set_option($this->ds, LDAP_OPT_PROTOCOL_VERSION, 3); |
---|
[37] | 56 | ldap_set_option($this->ds, LDAP_OPT_REFERRALS, $refer); |
---|
[342] | 57 | if ($refer) { |
---|
[176] | 58 | ldap_set_rebind_proc($this->ds, ldapRebind); |
---|
| 59 | } |
---|
[387] | 60 | @ldap_bind($this->ds,$this->bind_dn,$this->bind_dn_pw ); |
---|
[2] | 61 | } |
---|
| 62 | |
---|
[205] | 63 | //Teste jakjr retornando o DS |
---|
| 64 | function ldapConnect2($refer = false){ |
---|
| 65 | $ds = ldap_connect($_SESSION['phpgw_info']['expressomail']['ldap_server']['host']); |
---|
[387] | 66 | |
---|
[205] | 67 | if (!$ds) |
---|
| 68 | return false; |
---|
[387] | 69 | |
---|
[205] | 70 | ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3); |
---|
| 71 | ldap_set_option($ds, LDAP_OPT_REFERRALS, $refer); |
---|
| 72 | if ($refer) |
---|
| 73 | ldap_set_rebind_proc($ds, ldapRebind); |
---|
| 74 | @ldap_bind($ds, $_SESSION['phpgw_info']['expressomail']['ldap_server']['acc'],$_SESSION['phpgw_info']['expressomail']['ldap_server']['pw']); |
---|
[387] | 75 | |
---|
| 76 | return $ds; |
---|
[205] | 77 | } |
---|
| 78 | |
---|
| 79 | |
---|
[108] | 80 | // usa o host e context do setup. |
---|
[2] | 81 | function ldapRootConnect($refer = false){ |
---|
| 82 | $this->ldap_host = $_SESSION['phpgw_info']['expressomail']['server']['ldap_host']; |
---|
| 83 | $this->ldap_context = $_SESSION['phpgw_info']['expressomail']['server']['ldap_context']; |
---|
| 84 | $this->ds = ldap_connect($this->ldap_host); |
---|
| 85 | ldap_set_option($this->ds, LDAP_OPT_PROTOCOL_VERSION, 3); |
---|
[37] | 86 | ldap_set_option($this->ds, LDAP_OPT_REFERRALS, $refer); |
---|
[387] | 87 | ldap_bind($this->ds, $_SESSION['phpgw_info']['expressomail']['server']['ldap_root_dn'],$_SESSION['phpgw_info']['expressomail']['server']['ldap_root_pw']); |
---|
[2] | 88 | |
---|
| 89 | } |
---|
| 90 | |
---|
| 91 | function quicksearch($params) |
---|
[387] | 92 | { |
---|
[95] | 93 | include_once("class.functions.inc.php"); |
---|
[387] | 94 | $functions = new functions; |
---|
[108] | 95 | |
---|
[325] | 96 | $search_for = utf8_encode($params['search_for']); |
---|
[2] | 97 | $field = $params['field']; |
---|
| 98 | $ID = $params['ID']; |
---|
[644] | 99 | |
---|
[325] | 100 | $search_for = explode(" ",$search_for); |
---|
| 101 | $aux=""; |
---|
| 102 | foreach ($search_for as $search) |
---|
[644] | 103 | { |
---|
| 104 | if(!$aux) |
---|
[325] | 105 | { |
---|
| 106 | $aux=$search; |
---|
[644] | 107 | } |
---|
| 108 | else |
---|
| 109 | { |
---|
[657] | 110 | if (strlen($search) > 2) |
---|
| 111 | { |
---|
[644] | 112 | $aux=$aux."*".$search; |
---|
[325] | 113 | } |
---|
[657] | 114 | else |
---|
| 115 | { |
---|
| 116 | $aux=$aux." ".$search; |
---|
| 117 | } |
---|
| 118 | } |
---|
[644] | 119 | } |
---|
[325] | 120 | $search_for=$aux; |
---|
[644] | 121 | |
---|
[2] | 122 | $contacts_result = array(); |
---|
| 123 | $contacts_result['field'] = $field; |
---|
| 124 | $contacts_result['ID'] = $ID; |
---|
[387] | 125 | |
---|
[2] | 126 | // follow the referral |
---|
| 127 | $this->ldapConnect(true); |
---|
[387] | 128 | |
---|
[2] | 129 | if ($this->ds) |
---|
[342] | 130 | { |
---|
| 131 | if (($field != 'null') && ($ID != 'null')) |
---|
[325] | 132 | { |
---|
[1918] | 133 | $filter="(& (&(|(phpgwAccountType=u)(phpgwAccountType=g)(phpgwAccountType=l)(phpgwAccountType=i)(phpgwAccountType=s))(mail=*)) (|(cn=*$search_for*)(mail=*$search_for*)) (!(phpgwaccountvisible=-1)) )"; |
---|
[325] | 134 | $justthese = array("cn", "mail", "telephoneNumber", "mobile", "phpgwAccountVisible", "uid", "employeeNumber", "ou"); |
---|
[342] | 135 | } |
---|
[37] | 136 | else |
---|
[342] | 137 | { |
---|
[271] | 138 | $filter="(& (phpgwAccountType=u)(cn=*$search_for*) (!(phpgwaccountvisible=-1)) )"; |
---|
[342] | 139 | $justthese = array("cn", "mail", "telephoneNumber", "mobile", "phpgwAccountVisible","jpegPhoto", "uid", "employeeNumber", "ou"); |
---|
| 140 | } |
---|
| 141 | $sr=@ldap_search($this->ds, $this->ldap_context, $filter, $justthese, 0, $this->max_result + 1); |
---|
| 142 | if(!$sr) |
---|
| 143 | return null; |
---|
[325] | 144 | $count_entries = ldap_count_entries($this->ds,$sr); |
---|
[342] | 145 | |
---|
[387] | 146 | // Get user org dn. |
---|
[271] | 147 | $user_dn = $_SESSION['phpgw_info']['expressomail']['user']['account_dn']; |
---|
| 148 | $user_sector_dn = ldap_explode_dn ( $user_dn, false ); |
---|
| 149 | array_shift($user_sector_dn); |
---|
| 150 | array_shift($user_sector_dn); |
---|
| 151 | $user_sector_dn = implode(",", $user_sector_dn); |
---|
[387] | 152 | |
---|
[271] | 153 | // New search only on user sector |
---|
[342] | 154 | if ($count_entries > $this->max_result) |
---|
| 155 | { |
---|
[108] | 156 | // Close old ldap conection |
---|
| 157 | ldap_close($this->ds); |
---|
[387] | 158 | |
---|
[108] | 159 | // Reopen a local ldap connection, following referral |
---|
| 160 | $this->ldapRootConnect(true); |
---|
[387] | 161 | |
---|
[342] | 162 | $sr= ldap_search($this->ds, $user_sector_dn, $filter, $justthese); |
---|
| 163 | if(!$sr) |
---|
| 164 | return null; |
---|
[108] | 165 | $count_entries = ldap_count_entries($this->ds,$sr); |
---|
[387] | 166 | |
---|
[342] | 167 | if ($count_entries > $this->max_result){ |
---|
[108] | 168 | $return = array(); |
---|
| 169 | $return['status'] = false; |
---|
[387] | 170 | $return['error'] = "many results"; |
---|
[108] | 171 | return $return; |
---|
| 172 | } |
---|
[95] | 173 | else |
---|
| 174 | { |
---|
| 175 | $quickSearch_only_in_userSector = true; |
---|
| 176 | } |
---|
| 177 | } |
---|
[387] | 178 | |
---|
[37] | 179 | $info = ldap_get_entries($this->ds, $sr); |
---|
[387] | 180 | |
---|
[2] | 181 | $tmp = array(); |
---|
[271] | 182 | $tmp_users_from_user_org = array(); |
---|
[387] | 183 | |
---|
[342] | 184 | if (!$quickSearch_only_in_userSector) { |
---|
| 185 | $catalogsNum=count($this->external_srcs); |
---|
| 186 | for ($i=0; $i<=count($this->external_srcs); $i++) { |
---|
| 187 | if ($this->external_srcs[$i]["quicksearch"]) { |
---|
[325] | 188 | $this->ldapConnect(true,$i); |
---|
| 189 | $filter="(|(cn=*$search_for*)(mail=*$search_for*))"; |
---|
[342] | 190 | $justthese = array("cn", "mail", "telephoneNumber", "mobile", "phpgwAccountVisible", "uid","employeeNumber", "ou"); |
---|
| 191 | $sr=@ldap_search($this->ds, $this->ldap_context, $filter, $justthese, 0, $this->max_result+1); |
---|
| 192 | if(!$sr) |
---|
| 193 | return null; |
---|
[325] | 194 | $count_entries = ldap_count_entries($this->ds,$sr); |
---|
| 195 | $search = ldap_get_entries($this->ds, $sr); |
---|
[387] | 196 | for ($j=0; $j<$search["count"]; $j++) { |
---|
| 197 | $info[] = $search[$j]; |
---|
[342] | 198 | } |
---|
[325] | 199 | $info["count"] = count($info)-1; |
---|
| 200 | } |
---|
[271] | 201 | } |
---|
[342] | 202 | } |
---|
| 203 | |
---|
[325] | 204 | for ($i=0; $i<$info["count"]; $i++) |
---|
[342] | 205 | { |
---|
| 206 | if ($quickSearch_only_in_userSector) |
---|
[271] | 207 | { |
---|
[325] | 208 | $tmp[$info[$i]["mail"][0] . '%' . $info[$i]["telephonenumber"][0] . '%'. $info[$i]["mobile"][0] . '%' . $info[$i]["uid"][0] . '%' . $info[$i]["jpegphoto"]['count'] . '%' . $info[$i]["employeenumber"][0] . '%' . $info[$i]["ou"][0]] = utf8_decode($info[$i]["cn"][0]); |
---|
[342] | 209 | } |
---|
[325] | 210 | else |
---|
[342] | 211 | { |
---|
| 212 | if (preg_match("/$user_sector_dn/i", $info[$i]['dn'])) |
---|
[325] | 213 | { |
---|
| 214 | $tmp_users_from_user_org[$info[$i]["mail"][0] . '%' . $info[$i]["telephonenumber"][0] . '%'. $info[$i]["mobile"][0] . '%' . $info[$i]["uid"][0] . '%' . $info[$i]["jpegphoto"]['count'] . '%' . $info[$i]["employeenumber"][0] . '%' . $info[$i]["ou"][0]] = utf8_decode($info[$i]["cn"][0]); |
---|
[342] | 215 | } |
---|
[271] | 216 | else |
---|
[342] | 217 | { |
---|
[325] | 218 | $tmp[$info[$i]["mail"][0] . '%' . $info[$i]["telephonenumber"][0] . '%'. $info[$i]["mobile"][0] . '%' . $info[$i]["uid"][0] . '%' . $info[$i]["jpegphoto"]['count'] . '%' . $info[$i]["employeenumber"][0] . '%' . $info[$i]["ou"][0]] = utf8_decode($info[$i]["cn"][0]); |
---|
[271] | 219 | } |
---|
| 220 | } |
---|
[342] | 221 | } |
---|
[271] | 222 | natcasesort($tmp_users_from_user_org); |
---|
[2] | 223 | natcasesort($tmp); |
---|
[387] | 224 | |
---|
[37] | 225 | if (($field != 'null') && ($ID != 'null')) |
---|
[2] | 226 | { |
---|
[271] | 227 | $i = 0; |
---|
[387] | 228 | |
---|
[271] | 229 | $tmp = array_merge($tmp, $tmp_users_from_user_org); |
---|
| 230 | natcasesort($tmp); |
---|
[387] | 231 | |
---|
[37] | 232 | foreach ($tmp as $info => $cn) |
---|
| 233 | { |
---|
| 234 | $contacts_result[$i] = array(); |
---|
| 235 | $contacts_result[$i]["cn"] = $cn; |
---|
[325] | 236 | list ($contacts_result[$i]["mail"], $contacts_result[$i]["phone"], $contacts_result[$i]["mobile"], $contacts_result[$i]["uid"], $contacts_result[$i]["jpegphoto"], $contacts_result[$i]["employeenumber"], $contacts_result[$i]["ou"]) = split ('%', $info); |
---|
[37] | 237 | $i++; |
---|
| 238 | } |
---|
[95] | 239 | $contacts_result['quickSearch_only_in_userSector'] = $quickSearch_only_in_userSector; |
---|
[2] | 240 | } |
---|
[37] | 241 | else |
---|
| 242 | { |
---|
[271] | 243 | $options_users_from_user_org = ''; |
---|
[37] | 244 | $options = ''; |
---|
[271] | 245 | |
---|
| 246 | /* List of users from user org */ |
---|
| 247 | $i = 0; |
---|
| 248 | foreach ($tmp_users_from_user_org as $info => $cn) |
---|
| 249 | { |
---|
| 250 | $contacts_result[$i] = array(); |
---|
| 251 | $options_users_from_user_org .= $this->make_quicksearch_card($info, $cn); |
---|
| 252 | $i++; |
---|
| 253 | } |
---|
| 254 | |
---|
| 255 | /* List of users from others org */ |
---|
[37] | 256 | foreach ($tmp as $info => $cn) |
---|
| 257 | { |
---|
| 258 | $contacts_result[$i] = array(); |
---|
[271] | 259 | $options .= $this->make_quicksearch_card($info, $cn); |
---|
[37] | 260 | $i++; |
---|
| 261 | } |
---|
[387] | 262 | |
---|
[95] | 263 | if ($quickSearch_only_in_userSector) |
---|
| 264 | { |
---|
[271] | 265 | if ($options != '') |
---|
| 266 | { |
---|
| 267 | $head_option = |
---|
| 268 | '<tr class="quicksearchcontacts_unselected">' . |
---|
| 269 | '<td colspan="2" width="100%" align="center">' . |
---|
[342] | 270 | str_replace("%1", $this->max_result,$this->functions->getLang('More than %1 results were found')) . '.<br>' . |
---|
| 271 | $this->functions->getLang('Showing only the results found in your organization') . '.'; |
---|
[271] | 272 | '</td>' . |
---|
| 273 | '</tr>'; |
---|
| 274 | $contacts_result = $head_option . $options_users_from_user_org . $options; |
---|
| 275 | } |
---|
| 276 | else |
---|
| 277 | { |
---|
| 278 | $return = array(); |
---|
| 279 | $return['status'] = false; |
---|
| 280 | $return['error'] = "many results"; |
---|
| 281 | return $return; |
---|
| 282 | } |
---|
[108] | 283 | } |
---|
[271] | 284 | else |
---|
| 285 | { |
---|
| 286 | if (($options_users_from_user_org != '') && ($options != '')) |
---|
| 287 | { |
---|
| 288 | $head_option0 = |
---|
| 289 | '<tr class="quicksearchcontacts_unselected">' . |
---|
| 290 | '<td colspan="2" width="100%" align="center" style="background:#EEEEEE"><B>' . |
---|
[342] | 291 | $this->functions->getLang('Users from your organization') . '</B> ['.count($tmp_users_from_user_org).']'; |
---|
| 292 | '</td>' . |
---|
[271] | 293 | '</tr>'; |
---|
| 294 | |
---|
| 295 | $head_option1 = |
---|
| 296 | '<tr class="quicksearchcontacts_unselected">' . |
---|
| 297 | '<td colspan="2" width="100%" align="center" style="background:#EEEEEE"><B>' . |
---|
[342] | 298 | $this->functions->getLang('Users from others organizations') . '</B> ['.count($tmp).']'; |
---|
| 299 | '</td>' . |
---|
[271] | 300 | '</tr>'; |
---|
| 301 | } |
---|
| 302 | $contacts_result = $head_option0 . $options_users_from_user_org . $head_option1 . $options; |
---|
| 303 | } |
---|
[37] | 304 | } |
---|
[2] | 305 | } |
---|
| 306 | ldap_close($this->ds); |
---|
| 307 | return $contacts_result; |
---|
| 308 | } |
---|
| 309 | |
---|
[271] | 310 | function make_quicksearch_card($info, $cn) |
---|
| 311 | { |
---|
| 312 | include_once("class.functions.inc.php"); |
---|
[387] | 313 | $functions = new functions; |
---|
| 314 | |
---|
[271] | 315 | $contacts_result = array(); |
---|
| 316 | $contacts_result["cn"] = $cn; |
---|
| 317 | list ($contacts_result["mail"], $contacts_result["phone"], $contacts_result["mobile"], $contacts_result["uid"], $contacts_result["jpegphoto"]) = split ('%', $info); |
---|
[387] | 318 | |
---|
[271] | 319 | if ($contacts_result['jpegphoto']) |
---|
| 320 | $photo_link = '<img src="./inc/show_user_photo.php?mail='.$contacts_result['mail'].'">'; |
---|
| 321 | else |
---|
[1495] | 322 | $photo_link = '<img src="./templates/default/images/photo.jpg">'; |
---|
[387] | 323 | |
---|
[271] | 324 | $phoneUser = $contacts_result['phone']; |
---|
[387] | 325 | |
---|
[271] | 326 | if($_SESSION['phpgw_info']['user']['preferences']['expressoMail']['voip_enabled'] && $phoneUser) { |
---|
[342] | 327 | $phoneUser = '<a title="'.$this->functions->getLang("Call to Comercial Number").'" href="#" onclick="InfoContact.connectVoip(\''.$phoneUser.'\',\'com\')">'.$phoneUser.'</a>'; |
---|
[271] | 328 | if($contacts_result['mobile']){ |
---|
[342] | 329 | $phoneUser .= ' / <a title="'.$this->functions->getLang("Call to Mobile Number").'" href="#" onclick="InfoContact.connectVoip(\''.$contacts_result['mobile'].'\',\'mob\')">'.$contacts_result['mobile'].'</a>'; |
---|
[271] | 330 | } |
---|
| 331 | } |
---|
[644] | 332 | // Begin: nickname, firstname and lastname for QuickAdd. |
---|
| 333 | $fn = $contacts_result["cn"]; |
---|
| 334 | $array_name = explode(" ", $fn); |
---|
| 335 | if(count($array_name) > 1){ |
---|
| 336 | $fn = $array_name[0]; |
---|
| 337 | array_shift($array_name); |
---|
| 338 | $sn = implode(" ",$array_name); |
---|
| 339 | } |
---|
| 340 | // End: |
---|
[271] | 341 | $option = |
---|
| 342 | '<tr class="quicksearchcontacts_unselected">' . |
---|
| 343 | '<td class="cc" width="1%">' . |
---|
[342] | 344 | '<a title="'.$this->functions->getLang("Write message").'" onClick="javascript:QuickSearchUser.create_new_message(\''.$contacts_result["cn"].'\', \''.$contacts_result["mail"].'\')">' . |
---|
[271] | 345 | $photo_link . |
---|
| 346 | '</a>' . |
---|
| 347 | '</td>' . |
---|
| 348 | '<td class="cc">' . |
---|
| 349 | '<span name="cn">' . $contacts_result['cn'] . '</span>' . '<br>' . |
---|
[342] | 350 | '<a title="'.$this->functions->getLang("Write message").'" onClick="javascript:QuickSearchUser.create_new_message(\''.$contacts_result["cn"].'\', \''.$contacts_result["mail"].'\')">' . |
---|
[271] | 351 | '<font color=blue>' . |
---|
[644] | 352 | '<span name="mail">' . $contacts_result['mail'] . '</span></a></font>'. |
---|
[2517] | 353 | '<img src="templates/default/images/user_card.png" style="cursor: pointer;" title="'.$this->functions->getLang("Add Contact").'" onclick="javascript:connector.loadScript(\'jscode/ccQuickAdd\');ccQuickAddOne.showList(\''.$fn.','.$fn.','.$sn.','.$contacts_result["mail"].'\')">'. |
---|
[644] | 354 | '<br>' . |
---|
[271] | 355 | $phoneUser . |
---|
| 356 | '</td>' . |
---|
[644] | 357 | '</tr>'; |
---|
[271] | 358 | return $option; |
---|
| 359 | } |
---|
| 360 | |
---|
[387] | 361 | function get_catalogs(){ |
---|
[325] | 362 | $catalogs = array(); |
---|
[387] | 363 | $catalogs[0] = $this->functions->getLang("Global Catalog"); |
---|
| 364 | if($this->external_srcs) |
---|
[342] | 365 | foreach ($this->external_srcs as $key => $valor ){ |
---|
[325] | 366 | $catalogs[$key] = $valor['name']; |
---|
| 367 | } |
---|
| 368 | return $catalogs; |
---|
| 369 | } |
---|
[2] | 370 | function get_organizations($params){ |
---|
| 371 | $organizations = array(); |
---|
[325] | 372 | $params['referral']?$referral = $params['referral']:$referral = false; |
---|
| 373 | $cat = $params['catalog']; |
---|
[2] | 374 | |
---|
[325] | 375 | $this->ldapConnect($referral,$cat); |
---|
| 376 | |
---|
| 377 | if($this->branch != '') { |
---|
[1363] | 378 | $filter="(&(".$this->branch."=*)(!(phpgwAccountVisible=-1)))"; |
---|
[325] | 379 | $justthese = array("$this->branch"); |
---|
[342] | 380 | $sr = ldap_list($this->ds, $this->ldap_context, $filter, $justthese); |
---|
| 381 | $info = ldap_get_entries($this->ds, $sr); |
---|
[387] | 382 | |
---|
[342] | 383 | for ($i=0; $i<$info["count"]; $i++) |
---|
| 384 | $organizations[$i] = $info[$i]["ou"][0]; |
---|
[325] | 385 | |
---|
[342] | 386 | ldap_close($this->ds); |
---|
[387] | 387 | sort($organizations); |
---|
[342] | 388 | return $organizations; |
---|
[325] | 389 | }else{ |
---|
| 390 | return null; |
---|
[2] | 391 | } |
---|
[342] | 392 | } |
---|
[2] | 393 | function get_organizations2($params){ |
---|
| 394 | $organizations = array(); |
---|
| 395 | $referral = $params['referral']; |
---|
| 396 | $this->ldapRootConnect($referral); |
---|
| 397 | if ($this->ds) { |
---|
[1363] | 398 | $filter="(&(ou=*)(!(phpgwAccountVisible=-1)))"; |
---|
[2] | 399 | $justthese = array("ou"); |
---|
| 400 | $sr = ldap_list($this->ds, $this->ldap_context, $filter, $justthese); |
---|
| 401 | $info = ldap_get_entries($this->ds, $sr); |
---|
[387] | 402 | |
---|
[2] | 403 | for ($i=0; $i<$info["count"]; $i++) |
---|
| 404 | { |
---|
| 405 | $organizations[$i]['ou'] = $info[$i]["ou"][0]; |
---|
| 406 | $organizations[$i]['dn'] = $info[$i]["dn"]; |
---|
| 407 | } |
---|
[387] | 408 | |
---|
[2] | 409 | ldap_close($this->ds); |
---|
[387] | 410 | sort($organizations); |
---|
[2] | 411 | } |
---|
| 412 | return $organizations; |
---|
| 413 | } |
---|
[925] | 414 | |
---|
| 415 | //Busca usuarios de um contexto e ja retorna as options do select - usado por template serpro; |
---|
| 416 | function search_users($params) |
---|
| 417 | { |
---|
| 418 | $this->ldapConnect(false,0); |
---|
| 419 | //Monta lista de Grupos e Usuarios |
---|
| 420 | $users = Array(); |
---|
| 421 | $groups = Array(); |
---|
| 422 | $user_context= $this->ldap_context; |
---|
| 423 | $owner = $_SESSION['phpgw_info']['expressomail']['user']['owner']; |
---|
| 424 | $filtro =utf8_encode($params['filter']); |
---|
| 425 | $context =utf8_encode($params['context']);//adicionado |
---|
[2] | 426 | |
---|
[925] | 427 | if ($this->ds) |
---|
| 428 | { |
---|
| 429 | $justthese = array("gidNumber","cn"); |
---|
| 430 | if ($params['type'] == 'search') |
---|
[1633] | 431 | $sr=ldap_search($this->ds, $context, ("(&(phpgwaccounttype=g)(!(phpgwaccountvisible=-1))(cn=*$filtro*))"),$justthese); |
---|
[925] | 432 | else |
---|
[1639] | 433 | $sr=ldap_list($this->ds, $context ? $context : $user_context, ("(&(phpgwaccounttype=g)(!(phpgwaccountvisible=-1))(cn=*".$filtro."*))"),$justthese); |
---|
[925] | 434 | $info = ldap_get_entries($this->ds, $sr); |
---|
| 435 | for ($i=0; $i<$info["count"]; $i++) |
---|
| 436 | $groups[$uids=$info[$i]["gidnumber"][0]] = Array('name' => $uids=$info[$i]["cn"][0], 'type' => g); |
---|
| 437 | $justthese = array("phpgwaccountvisible","uidNumber","cn"); |
---|
| 438 | if ($params['type'] == 'search') |
---|
| 439 | // $sr=ldap_search($this->ds, $user_context, ("(&(phpgwaccounttype=u)(!(phpgwaccountvisible=-1))(phpgwaccountstatus=A)(|(cn=*$filtro*)(mail=$filtro*)))"),$justthese); |
---|
| 440 | $sr=ldap_search($this->ds, $context, ("(&(phpgwaccounttype=u)(!(phpgwaccountvisible=-1))(phpgwaccountstatus=A)(|(cn=*$filtro*)(mail=$filtro*)))"),$justthese); |
---|
| 441 | else |
---|
[1639] | 442 | $sr=ldap_list($this->ds, $context ? $context : $user_context, ("(&(phpgwaccounttype=u)(!(phpgwaccountvisible=-1))(phpgwaccountstatus=A)(|(cn=*$filtro*)(mail=$filtro*)))"),$justthese); |
---|
[925] | 443 | |
---|
| 444 | $info = ldap_get_entries($this->ds, $sr); |
---|
| 445 | for ($i=0; $i<$info["count"]; $i++) |
---|
| 446 | { |
---|
| 447 | if ($info[$i]["phpgwaccountvisible"][0] == '-1') |
---|
| 448 | continue; |
---|
| 449 | $users[$uids=$info[$i]["uidnumber"][0]] = Array('name' => $uids=$info[$i]["cn"][0], 'type' => u); |
---|
| 450 | } |
---|
| 451 | } |
---|
| 452 | ldap_close($this->ds); |
---|
| 453 | |
---|
| 454 | @asort($users); |
---|
| 455 | @reset($users); |
---|
| 456 | @asort($groups); |
---|
| 457 | @reset($groups); |
---|
| 458 | $user_options =''; |
---|
| 459 | $group_options =''; |
---|
| 460 | |
---|
| 461 | foreach($groups as $id => $user_array) { |
---|
| 462 | $newId = $id.'U'; |
---|
| 463 | $group_options .= '<option value="'.$newId.'">'.utf8_decode($user_array['name']).'</option>'."\n"; |
---|
| 464 | } |
---|
| 465 | foreach($users as $id => $user_array) { |
---|
| 466 | if($owner != $id){ |
---|
| 467 | $newId = $id.'U'; |
---|
| 468 | $user_options .= '<option value="'.$newId.'">'.utf8_decode($user_array['name']).'</option>'."\n"; |
---|
| 469 | } |
---|
| 470 | } |
---|
[2802] | 471 | return json_encode( array("users" => $user_options, "groups" => $group_options) ); |
---|
[925] | 472 | } |
---|
| 473 | |
---|
[2] | 474 | function catalogsearch($params) |
---|
[387] | 475 | { |
---|
[325] | 476 | $cn = $params['search_for'] ? "*".utf8_encode($params['search_for'])."*" : "*"; |
---|
[387] | 477 | $max_result = $params['max_result'] ? $params['max_result'] : $this->max_result; |
---|
[325] | 478 | $catalog = $params['catalog']; |
---|
[2] | 479 | $error = False; |
---|
[387] | 480 | |
---|
[381] | 481 | $this->ldapConnect(true,$catalog); |
---|
[387] | 482 | |
---|
| 483 | $params['organization'] == 'all' ? $user_context = $this->ldap_context :$user_context = $this->branch."=".$params['organization'].",".$this->ldap_context; |
---|
| 484 | |
---|
| 485 | if ($this->ds) { |
---|
[325] | 486 | if ($catalog == 0){ |
---|
| 487 | //os atributos "employeeNumber" e "ou" foram adicionado ao vetor de busca; |
---|
| 488 | $justthese = array("cn", "mail", "phpgwaccounttype", "phpgwAccountVisible", "employeeNumber", "ou"); |
---|
| 489 | $filter="(&(|(phpgwAccountType=u)(phpgwAccountType=l))(cn=".$cn."))"; |
---|
| 490 | //$user_context = "ou=".$params['organization'].",".$this->ldap_context; |
---|
| 491 | }else { |
---|
| 492 | //os atributos "employeeNumber" e "ou" foram adicionado ao vetor de busca; |
---|
| 493 | $justthese = array("cn", "mail", "employeeNumber", "ou"); |
---|
| 494 | $filter="(&(objectClass=".$this->object_class.")(cn=".$cn."))"; |
---|
| 495 | //$user_context = $this->branch."=".$params['organization'].",".$external_srcs[$catalog]['dn']; |
---|
| 496 | } |
---|
[387] | 497 | |
---|
[381] | 498 | $sr=@ldap_search($this->ds, $user_context, $filter, $justthese, 0, $max_result+1); |
---|
[342] | 499 | if(!$sr) |
---|
| 500 | return null; |
---|
[2] | 501 | $count_entries = ldap_count_entries($this->ds,$sr); |
---|
[381] | 502 | if ($count_entries > $max_result){ |
---|
[2] | 503 | $info = null; |
---|
[387] | 504 | $error = True; |
---|
[2] | 505 | } |
---|
| 506 | else |
---|
[387] | 507 | $info = ldap_get_entries($this->ds, $sr); |
---|
| 508 | |
---|
| 509 | ldap_close($this->ds); |
---|
| 510 | |
---|
[2] | 511 | $u_tmp = array(); |
---|
| 512 | $g_tmp = array(); |
---|
[387] | 513 | |
---|
[2] | 514 | for ($i=0; $i<$info["count"]; $i++){ |
---|
[325] | 515 | if((!$catalog==0)||(strtoupper($info[$i]["phpgwaccounttype"][0]) == 'U') && ($info[$i]["phpgwaccountvisible"][0] != '-1')) |
---|
| 516 | //aqui eh feita a concatenacao do departamento ao cn; |
---|
| 517 | $u_tmp[$info[$i]["mail"][0]] = utf8_decode($info[$i]["cn"][0]). '%' . $info[$i]["ou"][0]; |
---|
[387] | 518 | if((!$catalog==0)||(strtoupper($info[$i]["phpgwaccounttype"][0]) == 'L') && ($info[$i]["phpgwaccountvisible"][0] != '-1')) |
---|
[325] | 519 | $g_tmp[$info[$i]["mail"][0]] = utf8_decode($info[$i]["cn"][0]); |
---|
[387] | 520 | } |
---|
| 521 | |
---|
[2] | 522 | natcasesort($u_tmp); |
---|
| 523 | natcasesort($g_tmp); |
---|
[387] | 524 | |
---|
[2] | 525 | $i = 0; |
---|
[387] | 526 | $users = array(); |
---|
[325] | 527 | |
---|
[387] | 528 | foreach ($u_tmp as $mail => $cn){ |
---|
| 529 | |
---|
[325] | 530 | $tmp = explode("%", $cn); //explode o cn pelo caracter "%" e joga em $tmp; |
---|
| 531 | $name = $tmp[0]; //pega o primeiro item (cn) do vetor resultante do explode acima; |
---|
| 532 | $department = $tmp[1]; //pega o segundo item (ou) do vetor resultanto do explode acima; |
---|
| 533 | $users[$i++] = array("name" => $name, "email" => $mail, "department" => $department); |
---|
| 534 | |
---|
[2] | 535 | } |
---|
| 536 | unset($u_tmp); |
---|
[387] | 537 | |
---|
| 538 | $i = 0; |
---|
[2] | 539 | $groups = array(); |
---|
[387] | 540 | |
---|
| 541 | foreach ($g_tmp as $mail => $cn){ |
---|
[2] | 542 | $groups[$i++] = array("name" => $cn, "email" => $mail); |
---|
| 543 | } |
---|
| 544 | unset($g_tmp); |
---|
[387] | 545 | |
---|
[2] | 546 | return array('users' => $users, 'groups' => $groups, 'error' => $error); |
---|
[387] | 547 | }else |
---|
[2] | 548 | return null; |
---|
| 549 | } |
---|
[387] | 550 | |
---|
[2] | 551 | function get_emails_ldap(){ |
---|
| 552 | |
---|
| 553 | $result['mail']= array(); |
---|
[387] | 554 | $result['mailalter']= array(); |
---|
[2] | 555 | $user = $_SESSION['phpgw_info']['expressomail']['user']['account_lid']; |
---|
| 556 | $this->ldapRootConnect(false); |
---|
| 557 | if ($this->ds) { |
---|
[387] | 558 | $filter="uid=".$user; |
---|
[2] | 559 | $justthese = array("mail","mailAlternateAddress"); |
---|
| 560 | $sr = ldap_search($this->ds,$this->ldap_context, $filter, $justthese); |
---|
| 561 | $ent = ldap_get_entries($this->ds, $sr); |
---|
| 562 | ldap_close($this->ds); |
---|
[387] | 563 | |
---|
[2] | 564 | for ($i=0; $i<$ent["count"]; $i++){ |
---|
| 565 | $result['mail'][] = $ent[$i]["mail"][0]; |
---|
[387] | 566 | $result['mailalter'][] = $ent[$i]["mailalternateaddress"][0]; |
---|
[2] | 567 | } |
---|
| 568 | } |
---|
| 569 | return $result; |
---|
| 570 | } |
---|
[387] | 571 | |
---|
[342] | 572 | //Busca usuarios de um contexto e ja retorna as options do select; |
---|
[2] | 573 | function get_available_users($params) |
---|
[37] | 574 | { |
---|
| 575 | $this->ldapRootConnect(); |
---|
[342] | 576 | //Monta lista de Grupos e Usuarios |
---|
[37] | 577 | $users = Array(); |
---|
| 578 | $groups = Array(); |
---|
| 579 | $user_context= $params['context']; |
---|
| 580 | $owner = $_SESSION['phpgw_info']['expressomail']['user']['owner']; |
---|
[2] | 581 | |
---|
[37] | 582 | if ($this->ds) |
---|
| 583 | { |
---|
| 584 | $justthese = array("gidNumber","cn"); |
---|
| 585 | if ($params['type'] == 'search') |
---|
| 586 | $sr=ldap_search($this->ds, $user_context, ("(&(cn=*)(phpgwaccounttype=g)(!(phpgwaccountvisible=-1)))"),$justthese); |
---|
| 587 | else |
---|
| 588 | $sr=ldap_list($this->ds, $user_context, ("(&(cn=*)(phpgwaccounttype=g)(!(phpgwaccountvisible=-1)))"),$justthese); |
---|
| 589 | $info = ldap_get_entries($this->ds, $sr); |
---|
| 590 | for ($i=0; $i<$info["count"]; $i++) |
---|
[387] | 591 | $groups[$uids=$info[$i]["gidnumber"][0]] = Array('name' => $uids=$info[$i]["cn"][0], 'type' => g); |
---|
[37] | 592 | $justthese = array("phpgwaccountvisible","uidNumber","cn"); |
---|
| 593 | if ($params['type'] == 'search') |
---|
| 594 | $sr=ldap_search($this->ds, $user_context, ("(&(cn=*)(phpgwaccounttype=u)(!(phpgwaccountvisible=-1)))"),$justthese); |
---|
| 595 | else |
---|
| 596 | $sr=ldap_list($this->ds, $user_context, ("(&(cn=*)(phpgwaccounttype=u)(!(phpgwaccountvisible=-1)))"),$justthese); |
---|
[2] | 597 | |
---|
[37] | 598 | $info = ldap_get_entries($this->ds, $sr); |
---|
| 599 | for ($i=0; $i<$info["count"]; $i++) |
---|
| 600 | { |
---|
| 601 | if ($info[$i]["phpgwaccountvisible"][0] == '-1') |
---|
| 602 | continue; |
---|
| 603 | $users[$uids=$info[$i]["uidnumber"][0]] = Array('name' => $uids=$info[$i]["cn"][0], 'type' => u); |
---|
| 604 | } |
---|
| 605 | } |
---|
| 606 | ldap_close($this->ds); |
---|
[387] | 607 | |
---|
[37] | 608 | @asort($users); |
---|
[387] | 609 | @reset($users); |
---|
[37] | 610 | @asort($groups); |
---|
| 611 | @reset($groups); |
---|
| 612 | $user_options =''; |
---|
| 613 | $group_options =''; |
---|
[2] | 614 | |
---|
[37] | 615 | foreach($groups as $id => $user_array) { |
---|
| 616 | $newId = $id.'U'; |
---|
| 617 | $group_options .= '<option value="'.$newId.'">'.utf8_decode($user_array['name']).'</option>'."\n"; |
---|
| 618 | } |
---|
| 619 | foreach($users as $id => $user_array) { |
---|
| 620 | if($owner != $id){ |
---|
| 621 | $newId = $id.'U'; |
---|
| 622 | $user_options .= '<option value="'.$newId.'">'.utf8_decode($user_array['name']).'</option>'."\n"; |
---|
| 623 | } |
---|
| 624 | } |
---|
[2802] | 625 | return json_encode( array("users" => $user_options, "groups" => $group_options) ); |
---|
[37] | 626 | } |
---|
| 627 | |
---|
[342] | 628 | //Busca usuarios de um contexto e ja retorna as options do select; |
---|
[2] | 629 | function get_available_users2($params) |
---|
| 630 | { |
---|
| 631 | $this->ldapRootConnect(); |
---|
[387] | 632 | |
---|
[2] | 633 | $context= $params['context']; |
---|
| 634 | $justthese = array("cn", "uid", "cn"); |
---|
[21] | 635 | $filter = "(&(phpgwaccounttype=u)(!(phpgwaccountvisible=-1)))"; |
---|
[2] | 636 | |
---|
[387] | 637 | if ($this->ds) |
---|
[2] | 638 | { |
---|
| 639 | $sr=ldap_search($this->ds, $context, $filter, $justthese); |
---|
| 640 | $entries = ldap_get_entries($this->ds, $sr); |
---|
[387] | 641 | |
---|
[2] | 642 | for ($i=0; $i<$entries["count"]; $i++){ |
---|
| 643 | if($_SESSION['phpgw_info']['expressomail']['user']['account_lid'] != $entries[$i]["uid"][0]){ |
---|
| 644 | $u_tmp[$entries[$i]["uid"][0]] = $entries[$i]["cn"][0]; |
---|
| 645 | } |
---|
| 646 | } |
---|
[387] | 647 | |
---|
[2] | 648 | natcasesort($u_tmp); |
---|
| 649 | |
---|
| 650 | $i = 0; |
---|
| 651 | $users = array(); |
---|
[387] | 652 | |
---|
[2] | 653 | if (count($u_tmp)) |
---|
| 654 | { |
---|
| 655 | foreach ($u_tmp as $uidnumber => $cn) |
---|
| 656 | { |
---|
| 657 | $options .= "<option value=$uidnumber>$cn</option>"; |
---|
| 658 | } |
---|
| 659 | unset($u_tmp); |
---|
| 660 | } |
---|
| 661 | |
---|
| 662 | ldap_close($this->ds); |
---|
| 663 | return $options; |
---|
| 664 | } |
---|
| 665 | } |
---|
[387] | 666 | |
---|
[2] | 667 | function uid2cn($uid) |
---|
[387] | 668 | { |
---|
[2] | 669 | // do not follow the referral |
---|
| 670 | $this->ldapRootConnect(false); |
---|
| 671 | if ($this->ds) |
---|
| 672 | { |
---|
[387] | 673 | $filter="(&(phpgwAccountType=u)(uid=$uid))"; |
---|
[2] | 674 | $justthese = array("cn"); |
---|
[344] | 675 | $sr=@ldap_search($this->ds, $this->ldap_context, $filter, $justthese); |
---|
| 676 | if(!$sr) |
---|
| 677 | return false; |
---|
[2] | 678 | $info = ldap_get_entries($this->ds, $sr); |
---|
[325] | 679 | return utf8_decode($info[0]["cn"][0]); |
---|
[2] | 680 | } |
---|
| 681 | return false; |
---|
| 682 | } |
---|
[757] | 683 | function uidnumber2uid($uidnumber) |
---|
| 684 | { |
---|
| 685 | // do not follow the referral |
---|
| 686 | $this->ldapRootConnect(false); |
---|
| 687 | if ($this->ds) |
---|
| 688 | { |
---|
| 689 | $filter="(&(phpgwAccountType=u)(uidnumber=$uidnumber))"; |
---|
| 690 | $justthese = array("uid"); |
---|
| 691 | $sr=@ldap_search($this->ds, $this->ldap_context, $filter, $justthese); |
---|
| 692 | if(!$sr) |
---|
| 693 | return false; |
---|
| 694 | $info = ldap_get_entries($this->ds, $sr); |
---|
| 695 | return $info[0]["uid"][0]; |
---|
| 696 | } |
---|
| 697 | return false; |
---|
| 698 | } |
---|
[387] | 699 | function getSharedUsersFrom($params){ |
---|
[2] | 700 | $filter = ''; |
---|
[1912] | 701 | $i = 0; |
---|
| 702 | //Added to save if must save sent messages in shared folder |
---|
| 703 | $acl_save_sent_in_shared = array(); |
---|
| 704 | |
---|
[371] | 705 | if($params['uids']) { |
---|
[387] | 706 | $uids = explode(";",$params['uids']); |
---|
[1912] | 707 | $this->imap = new imap_functions(); |
---|
[371] | 708 | foreach($uids as $index => $uid){ |
---|
[387] | 709 | $params = array(); |
---|
[1912] | 710 | //Added to save if user has create permission |
---|
| 711 | $acl_create_message = array(); |
---|
[371] | 712 | $acl = $this->imap->getacltouser($uid); |
---|
[1912] | 713 | if ( preg_match("/a/",$acl )){ |
---|
| 714 | $filter .= "(uid=$uid)"; |
---|
| 715 | if ( preg_match("/p/",$acl )){ |
---|
| 716 | $acl_save_sent_in_shared[ $i ] =$uid; |
---|
| 717 | $i++; |
---|
| 718 | } |
---|
| 719 | } |
---|
| 720 | } |
---|
[2] | 721 | } |
---|
[1912] | 722 | |
---|
[387] | 723 | $this->ldapRootConnect(false); |
---|
[371] | 724 | if ($this->ds) { |
---|
[1912] | 725 | $justthese = array("cn","mail","uid"); |
---|
[371] | 726 | if($filter) { |
---|
[1912] | 727 | $filter="(&(|(phpgwAccountType=u)(phpgwAccountType=s))(|$filter))"; |
---|
[371] | 728 | $sr = ldap_search($this->ds, $this->ldap_context, $filter, $justthese); |
---|
[387] | 729 | ldap_sort($this->ds,$sr,"cn"); |
---|
| 730 | $info = ldap_get_entries($this->ds, $sr); |
---|
[1912] | 731 | $var = print_r($acl_save_sent_in_shared, true); |
---|
| 732 | for ($i = 0;$i < $info["count"]; $i++){ |
---|
[371] | 733 | $info[$i]['cn'][0] = utf8_decode($info[$i]['cn'][0]); |
---|
[1912] | 734 | //verify if user has permission to save sent messages in a shared folder |
---|
| 735 | if ( in_array( $info[$i]['uid'][0],$acl_save_sent_in_shared) ){ |
---|
| 736 | $info[$i]['save_shared'][0] = 'y'; |
---|
| 737 | } else $info[$i]['save_shared'][0] = 'n'; |
---|
| 738 | } |
---|
[371] | 739 | } |
---|
[1912] | 740 | |
---|
[371] | 741 | $info['myname'] = $_SESSION['phpgw_info']['expressomail']['user']['fullname']; |
---|
[387] | 742 | |
---|
[371] | 743 | //Find institucional_account. |
---|
| 744 | $filter="(&(phpgwAccountType=i)(mailForwardingAddress=".$_SESSION['phpgw_info']['expressomail']['user']['email']."))"; |
---|
[387] | 745 | $sr = ldap_search($this->ds, $this->ldap_context, $filter, $justthese); |
---|
[448] | 746 | ## |
---|
| 747 | # @AUTHOR Rodrigo Souza dos Santos |
---|
| 748 | # @DATE 2008/09/17 |
---|
| 749 | # @BRIEF Changing to ensure that the variable session is always with due value. |
---|
| 750 | ## |
---|
| 751 | if(ldap_count_entries($this->ds,$sr)) |
---|
| 752 | { |
---|
| 753 | ldap_sort($this->ds,$sr,"cn"); |
---|
| 754 | $result = ldap_get_entries($this->ds, $sr); |
---|
| 755 | for ($j = 0;$j < $result["count"]; $j++){ |
---|
| 756 | $info[$i]['cn'][0] = utf8_decode($result[$j]['cn'][0]); |
---|
[1912] | 757 | $info[$i]['mail'][0] = $result[$j]['mail'][0]; |
---|
| 758 | $info[$i]['save_shared'][0] = 'n'; |
---|
| 759 | $info[$i++]['uid'][0] = $result[$j]['uid'][0]; |
---|
[448] | 760 | } |
---|
[371] | 761 | } |
---|
[448] | 762 | |
---|
| 763 | $_SESSION['phpgw_info']['expressomail']['user']['shared_mailboxes'] = $info; |
---|
[1912] | 764 | |
---|
[2] | 765 | return $info; |
---|
| 766 | } |
---|
| 767 | } |
---|
[27] | 768 | |
---|
[205] | 769 | function getUserByEmail($params) |
---|
| 770 | { |
---|
| 771 | $filter="(&(phpgwAccountType=u)(mail=" . $params['email'] . "))"; |
---|
| 772 | $ldap_context = $_SESSION['phpgw_info']['expressomail']['ldap_server']['dn']; |
---|
| 773 | $justthese = array("cn","uid","telephoneNumber","jpegPhoto","mobile"); |
---|
| 774 | |
---|
[27] | 775 | // Follow the referral |
---|
[205] | 776 | $ds = $this->ldapConnect2(true); |
---|
| 777 | if ($ds) |
---|
[387] | 778 | { |
---|
[342] | 779 | $sr=@ldap_search($ds, $ldap_context, $filter, $justthese); |
---|
[387] | 780 | |
---|
[205] | 781 | if (!$sr) |
---|
| 782 | return null; |
---|
[387] | 783 | |
---|
[205] | 784 | $entry = ldap_first_entry($ds, $sr); |
---|
[387] | 785 | |
---|
| 786 | if($entry) { |
---|
[381] | 787 | $obj = array("cn" => utf8_decode(current(ldap_get_values($ds, $entry, "cn"))), |
---|
[205] | 788 | "email" => $params['email'], |
---|
| 789 | "uid" => ldap_get_values($ds, $entry, "uid"), |
---|
[27] | 790 | "type" => "global", |
---|
[205] | 791 | "mobile" => @ldap_get_values($ds, $entry, "mobile"), |
---|
| 792 | "telefone" => @ldap_get_values($ds, $entry, "telephonenumber") |
---|
| 793 | ); |
---|
[27] | 794 | |
---|
[320] | 795 | $_SESSION['phpgw_info']['expressomail']['contact_photo'] = @ldap_get_values_len($ds, $entry, "jpegphoto"); |
---|
[205] | 796 | ldap_close($ds); |
---|
[27] | 797 | return $obj; |
---|
[205] | 798 | } |
---|
[27] | 799 | } |
---|
| 800 | return null; |
---|
| 801 | } |
---|
[1500] | 802 | |
---|
| 803 | function uid2uidnumber($uid) |
---|
| 804 | { |
---|
| 805 | // do not follow the referral |
---|
| 806 | $this->ldapRootConnect(false); |
---|
| 807 | if ($this->ds) |
---|
| 808 | { |
---|
| 809 | $filter="(&(phpgwAccountType=u)(uid=$uid))"; |
---|
| 810 | $justthese = array("uidnumber"); |
---|
| 811 | $sr=@ldap_search($this->ds, $this->ldap_context, $filter, $justthese); |
---|
| 812 | if(!$sr) |
---|
| 813 | return false; |
---|
| 814 | $info = ldap_get_entries($this->ds, $sr); |
---|
| 815 | return $info[0]["uidnumber"][0]; |
---|
| 816 | } |
---|
| 817 | return false; |
---|
| 818 | } |
---|
[2] | 819 | } |
---|
[108] | 820 | ?> |
---|