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