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