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