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