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