[387] | 1 | <?php |
---|
[5243] | 2 | |
---|
[5399] | 3 | require_once(dirname(__FILE__).'/../../services/class.servicelocator.php'); |
---|
[176] | 4 | include_once("class.imap_functions.inc.php"); |
---|
[342] | 5 | include_once("class.functions.inc.php"); |
---|
[176] | 6 | |
---|
| 7 | function ldapRebind($ldap_connection, $ldap_url) |
---|
| 8 | { |
---|
| 9 | @ldap_bind($ldap_connection, $_SESSION['phpgw_info']['expressomail']['ldap_server']['acc'],$_SESSION['phpgw_info']['expressomail']['ldap_server']['pw']); |
---|
| 10 | } |
---|
[387] | 11 | |
---|
[2] | 12 | class ldap_functions |
---|
| 13 | { |
---|
| 14 | var $ds; |
---|
| 15 | var $ldap_host; |
---|
| 16 | var $ldap_context; |
---|
| 17 | var $imap; |
---|
[342] | 18 | var $external_srcs; |
---|
| 19 | var $max_result; |
---|
| 20 | var $functions; |
---|
[4457] | 21 | var $ldapService; |
---|
| 22 | |
---|
[342] | 23 | function ldap_functions(){ |
---|
| 24 | // todo: Page Configuration for External Catalogs. |
---|
| 25 | @include("../contactcenter/setup/external_catalogs.inc.php"); |
---|
[4457] | 26 | $this->ldapService = ServiceLocator::getService('ldap'); |
---|
[5134] | 27 | if(isset($external_srcs)) |
---|
[4457] | 28 | $this->external_srcs = $external_srcs; |
---|
| 29 | $this->max_result = $this->ldapService->limit; |
---|
[387] | 30 | $this->functions = new functions(); |
---|
| 31 | } |
---|
[342] | 32 | // Using ContactCenter configuration. |
---|
| 33 | function ldapConnect($refer = false,$catalog = 0){ |
---|
| 34 | if ($catalog > 0 && is_array($this->external_srcs)){ |
---|
| 35 | $this->ldap_host = $this->external_srcs[$catalog]['host']; |
---|
| 36 | $this->ldap_context = $this->external_srcs[$catalog]['dn']; |
---|
| 37 | $this->bind_dn = $this->external_srcs[$catalog]['acc']; |
---|
| 38 | $this->bind_dn_pw = $this->external_srcs[$catalog]['pw']; |
---|
| 39 | $this->object_class = $this->external_srcs[$catalog]['obj']; |
---|
| 40 | $this->base_dn = $this->external_srcs[$catalog]['dn']; |
---|
| 41 | $this->branch = $this->external_srcs[$catalog]['branch']; |
---|
| 42 | }else { |
---|
[325] | 43 | $this->ldap_host = $_SESSION['phpgw_info']['expressomail']['ldap_server']['host']; |
---|
| 44 | $this->ldap_context = $_SESSION['phpgw_info']['expressomail']['ldap_server']['dn']; |
---|
| 45 | $this->bind_dn = $_SESSION['phpgw_info']['expressomail']['ldap_server']['acc']; |
---|
| 46 | $this->bind_dn_pw = $_SESSION['phpgw_info']['expressomail']['ldap_server']['pw']; |
---|
[387] | 47 | $this->branch = 'ou'; |
---|
[325] | 48 | } |
---|
[387] | 49 | |
---|
[325] | 50 | $this->ds = ldap_connect($this->ldap_host); |
---|
[2] | 51 | ldap_set_option($this->ds, LDAP_OPT_PROTOCOL_VERSION, 3); |
---|
[37] | 52 | ldap_set_option($this->ds, LDAP_OPT_REFERRALS, $refer); |
---|
[342] | 53 | if ($refer) { |
---|
[176] | 54 | ldap_set_rebind_proc($this->ds, ldapRebind); |
---|
| 55 | } |
---|
[387] | 56 | @ldap_bind($this->ds,$this->bind_dn,$this->bind_dn_pw ); |
---|
[2] | 57 | } |
---|
| 58 | |
---|
[205] | 59 | //Teste jakjr retornando o DS |
---|
| 60 | function ldapConnect2($refer = false){ |
---|
| 61 | $ds = ldap_connect($_SESSION['phpgw_info']['expressomail']['ldap_server']['host']); |
---|
[387] | 62 | |
---|
[205] | 63 | if (!$ds) |
---|
| 64 | return false; |
---|
[387] | 65 | |
---|
[205] | 66 | ldap_set_option($ds, LDAP_OPT_PROTOCOL_VERSION, 3); |
---|
| 67 | ldap_set_option($ds, LDAP_OPT_REFERRALS, $refer); |
---|
| 68 | if ($refer) |
---|
[5134] | 69 | ldap_set_rebind_proc($ds, 'rebind'); |
---|
[205] | 70 | @ldap_bind($ds, $_SESSION['phpgw_info']['expressomail']['ldap_server']['acc'],$_SESSION['phpgw_info']['expressomail']['ldap_server']['pw']); |
---|
[387] | 71 | |
---|
| 72 | return $ds; |
---|
[205] | 73 | } |
---|
| 74 | |
---|
| 75 | |
---|
[108] | 76 | // usa o host e context do setup. |
---|
[2] | 77 | function ldapRootConnect($refer = false){ |
---|
| 78 | $this->ldap_host = $_SESSION['phpgw_info']['expressomail']['server']['ldap_host']; |
---|
| 79 | $this->ldap_context = $_SESSION['phpgw_info']['expressomail']['server']['ldap_context']; |
---|
| 80 | $this->ds = ldap_connect($this->ldap_host); |
---|
| 81 | ldap_set_option($this->ds, LDAP_OPT_PROTOCOL_VERSION, 3); |
---|
[37] | 82 | ldap_set_option($this->ds, LDAP_OPT_REFERRALS, $refer); |
---|
[387] | 83 | ldap_bind($this->ds, $_SESSION['phpgw_info']['expressomail']['server']['ldap_root_dn'],$_SESSION['phpgw_info']['expressomail']['server']['ldap_root_pw']); |
---|
[2] | 84 | |
---|
| 85 | } |
---|
| 86 | |
---|
| 87 | function quicksearch($params) |
---|
[387] | 88 | { |
---|
[95] | 89 | include_once("class.functions.inc.php"); |
---|
[387] | 90 | $functions = new functions; |
---|
[4929] | 91 | |
---|
[2] | 92 | $field = $params['field']; |
---|
| 93 | $ID = $params['ID']; |
---|
[4929] | 94 | |
---|
[4457] | 95 | $ldapService = ServiceLocator::getService('ldap'); |
---|
| 96 | $filter = $ldapService->getSearchFilter($params['search_for']); |
---|
[4929] | 97 | |
---|
[2] | 98 | $contacts_result = array(); |
---|
| 99 | $contacts_result['field'] = $field; |
---|
| 100 | $contacts_result['ID'] = $ID; |
---|
[5199] | 101 | $search_for = utf8_encode($params['search_for']); |
---|
| 102 | |
---|
| 103 | if($_SESSION['phpgw_info']['user']['preferences']['expressoMail']['extended_info']) |
---|
| 104 | $extendedinfo=true; |
---|
| 105 | else |
---|
| 106 | $extendedinfo=false; |
---|
[5237] | 107 | |
---|
[2] | 108 | // follow the referral |
---|
| 109 | $this->ldapConnect(true); |
---|
[4929] | 110 | |
---|
[2] | 111 | if ($this->ds) |
---|
[4929] | 112 | { |
---|
[5134] | 113 | $ldapService->connection = $this->ds; |
---|
[5199] | 114 | if($extendedinfo) |
---|
[5245] | 115 | $justthese = array("cn", "mail", "telephonenumber", "uid","uidNumber", "mobile", "phpgwaccountvisible", "employeenumber", "ou"); |
---|
[5199] | 116 | else |
---|
[5245] | 117 | $justthese = array("cn", "mail", "telephoneNumber", "phpgwAccountVisible", "uidNumber","uid"); |
---|
[4457] | 118 | $types = false; |
---|
[387] | 119 | |
---|
[4457] | 120 | if( $field == 'null' || $ID == 'null' ) |
---|
[4929] | 121 | { |
---|
[4457] | 122 | $justthese[] = "jpegphoto"; |
---|
| 123 | $types = 'u'; |
---|
| 124 | } |
---|
[387] | 125 | |
---|
[4457] | 126 | $filter = $ldapService->getSearchFilter( $params['search_for'], $types ); |
---|
[387] | 127 | |
---|
[4457] | 128 | $sr=@ldap_search($this->ds, $this->ldap_context, $filter, $justthese, 0, $this->max_result); |
---|
| 129 | |
---|
[4929] | 130 | if(!$sr) |
---|
| 131 | return null; |
---|
[4457] | 132 | |
---|
[4929] | 133 | $count_entries = ldap_count_entries($this->ds,$sr); |
---|
[4457] | 134 | |
---|
| 135 | $info = ldap_get_entries($this->ds, $sr); |
---|
| 136 | |
---|
| 137 | // New search only on user sector |
---|
[5238] | 138 | if ($count_entries == $this->max_result) |
---|
[4457] | 139 | { |
---|
| 140 | $overload = $count_entries; |
---|
[4929] | 141 | } |
---|
| 142 | else |
---|
| 143 | { |
---|
| 144 | $catalogsNum=count($this->external_srcs); |
---|
[4457] | 145 | for ($i=0; $i<=$catalogsNum; $i++) { |
---|
[5245] | 146 | if ($this->external_srcs[$i]["quicksearch"]) { |
---|
[4929] | 147 | $this->ldapConnect(true,$i); |
---|
| 148 | $filter="(|(cn=*$search_for*)(mail=*$search_for*))"; |
---|
[5199] | 149 | if($extendedinfo) |
---|
[5245] | 150 | $justthese = array("cn", "mail", "telephonenumber", "uid","uidNumber", "mobile", "phpgwaccountvisible", "employeenumber", "ou"); |
---|
[5199] | 151 | else |
---|
[5245] | 152 | $justthese = array("cn", "mail", "telephoneNumber", "phpgwAccountVisible","uidNumber", "uid"); |
---|
[4929] | 153 | $sr=@ldap_search($this->ds, $this->ldap_context, $filter, $justthese, 0, $this->max_result+1); |
---|
| 154 | if(!$sr) |
---|
| 155 | return null; |
---|
| 156 | $count_entries = ldap_count_entries($this->ds,$sr); |
---|
| 157 | $search = ldap_get_entries($this->ds, $sr); |
---|
| 158 | for ($j=0; $j<$search["count"]; $j++) { |
---|
| 159 | $info[] = $search[$j]; |
---|
| 160 | } |
---|
| 161 | $info["count"] = count($info)-1; |
---|
| 162 | } |
---|
[108] | 163 | } |
---|
[95] | 164 | } |
---|
[387] | 165 | |
---|
[4457] | 166 | $tmp = array(); |
---|
| 167 | $tmp_users_from_user_org = array(); |
---|
[387] | 168 | |
---|
[4929] | 169 | for ($i=0; $i<$info["count"]; $i++) |
---|
| 170 | { |
---|
[5245] | 171 | $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] | 172 | |
---|
[4457] | 173 | if (/*(!$quickSearch_only_in_userSector) &&*/ preg_match("/$user_sector_dn/i", $info[$i]['dn'])) |
---|
[4929] | 174 | { |
---|
[4457] | 175 | $tmp_users_from_user_org[$key] = utf8_decode($info[$i]["cn"][0]); |
---|
| 176 | continue; |
---|
[4929] | 177 | } |
---|
[342] | 178 | |
---|
[4457] | 179 | $tmp[$key] = utf8_decode($info[$i]["cn"][0]); |
---|
[4929] | 180 | } |
---|
[387] | 181 | |
---|
[4929] | 182 | natcasesort($tmp_users_from_user_org); |
---|
| 183 | natcasesort($tmp); |
---|
[387] | 184 | |
---|
[4929] | 185 | if (($field != 'null') && ($ID != 'null')) |
---|
| 186 | { |
---|
| 187 | $i = 0; |
---|
[387] | 188 | |
---|
[4929] | 189 | $tmp = array_merge($tmp, $tmp_users_from_user_org); |
---|
| 190 | natcasesort($tmp); |
---|
[271] | 191 | |
---|
[4929] | 192 | foreach ($tmp as $info => $cn) |
---|
| 193 | { |
---|
| 194 | $contacts_result[$i] = array(); |
---|
| 195 | $contacts_result[$i]["cn"] = $cn; |
---|
[5245] | 196 | 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); |
---|
[4929] | 197 | $i++; |
---|
| 198 | } |
---|
| 199 | $contacts_result['quickSearch_only_in_userSector'] = $quickSearch_only_in_userSector; |
---|
[4457] | 200 | $contacts_result['maxResult'] = $ldapService->limit; |
---|
[4929] | 201 | } |
---|
| 202 | else |
---|
| 203 | { |
---|
| 204 | $options_users_from_user_org = ''; |
---|
| 205 | $options = ''; |
---|
[271] | 206 | |
---|
[4457] | 207 | |
---|
[4929] | 208 | $i = 0; |
---|
| 209 | foreach ($tmp_users_from_user_org as $info => $cn) |
---|
| 210 | { |
---|
| 211 | $contacts_result[$i] = array(); |
---|
| 212 | $options_users_from_user_org .= $this->make_quicksearch_card($info, $cn); |
---|
| 213 | $i++; |
---|
| 214 | } |
---|
[387] | 215 | |
---|
[4457] | 216 | |
---|
[4929] | 217 | foreach ($tmp as $info => $cn) |
---|
| 218 | { |
---|
| 219 | $contacts_result[$i] = array(); |
---|
| 220 | $options .= $this->make_quicksearch_card($info, $cn); |
---|
| 221 | $i++; |
---|
| 222 | } |
---|
[271] | 223 | |
---|
[4457] | 224 | |
---|
[4929] | 225 | if (($options_users_from_user_org != '') && ($options != '')) |
---|
| 226 | { |
---|
| 227 | $head_option0 = |
---|
| 228 | '<tr class="quicksearchcontacts_unselected">' . |
---|
| 229 | '<td colspan="2" width="100%" align="center" style="background:#EEEEEE"><B>' . |
---|
| 230 | $this->functions->getLang('Users from your organization') . '</B> ['.count($tmp_users_from_user_org).']'; |
---|
| 231 | '</td>' . |
---|
| 232 | '</tr>'; |
---|
[4457] | 233 | |
---|
[4929] | 234 | $head_option1 = |
---|
| 235 | '<tr class="quicksearchcontacts_unselected">' . |
---|
| 236 | '<td colspan="2" width="100%" align="center" style="background:#EEEEEE"><B>' . |
---|
| 237 | $this->functions->getLang('Users from others organizations') . '</B> ['.count($tmp).']'; |
---|
| 238 | '</td>' . |
---|
| 239 | '</tr>'; |
---|
| 240 | } |
---|
[4457] | 241 | |
---|
| 242 | $head_option = ''; |
---|
| 243 | |
---|
| 244 | if( $overload ) |
---|
| 245 | $head_option = '<tr class="quicksearchcontacts_unselected">' . |
---|
| 246 | '<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> '. |
---|
| 247 | '</td>' . |
---|
| 248 | '</tr>'; |
---|
| 249 | |
---|
| 250 | $contacts_result = $head_option.$head_option0 . $options_users_from_user_org . $head_option1. $options; |
---|
| 251 | |
---|
[4929] | 252 | } |
---|
| 253 | } |
---|
[4457] | 254 | |
---|
[4929] | 255 | ldap_close($this->ds); |
---|
[4457] | 256 | |
---|
[4929] | 257 | return $contacts_result; |
---|
[2] | 258 | } |
---|
| 259 | |
---|
[5075] | 260 | |
---|
| 261 | /** |
---|
| 262 | * Método que faz o roteamento entre os métodos de busca (Catálogo pessoal, global e todos) |
---|
| 263 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
| 264 | * @author Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) |
---|
| 265 | * @sponsor Caixa Econômica Federal |
---|
| 266 | * @author Prognus Software Livre <airton@prognus.com.br | prognus@prognus.com.br> |
---|
| 267 | * @param <array> <$param> <parametros vindos do cliente> |
---|
| 268 | */ |
---|
| 269 | function quicksearchcontact($params) |
---|
| 270 | { |
---|
[5209] | 271 | if(array_key_exists('Type', $params)){ |
---|
[5196] | 272 | return $this->quickSearch($params); |
---|
| 273 | } |
---|
[5202] | 274 | |
---|
[5075] | 275 | $modal = false; |
---|
| 276 | if($params['catalog']) |
---|
| 277 | $modal = true; |
---|
| 278 | |
---|
[5316] | 279 | include_once dirname(__FILE__). '/../../header.inc.php'; |
---|
[5075] | 280 | |
---|
| 281 | if($modal) |
---|
| 282 | { |
---|
| 283 | if($params['catalog'] == "global") |
---|
| 284 | { |
---|
| 285 | return $this->quickSearchGlobal($params); |
---|
| 286 | } |
---|
| 287 | else |
---|
| 288 | { |
---|
| 289 | if($params['catalog'] == "personal") |
---|
| 290 | return $this->quickSearchPersonal($params); |
---|
| 291 | else |
---|
| 292 | return $this->quickSearchAll($params); |
---|
| 293 | } |
---|
| 294 | } |
---|
| 295 | else |
---|
| 296 | { |
---|
| 297 | if($_SESSION['phpgw_info']['user']['preferences']['expressoMail']['catalog_search'] == "global") |
---|
| 298 | { |
---|
| 299 | return $this->quickSearchGlobal($params); |
---|
| 300 | } |
---|
| 301 | else |
---|
| 302 | { |
---|
| 303 | if($_SESSION['phpgw_info']['user']['preferences']['expressoMail']['catalog_search'] == "personal") |
---|
| 304 | return $this->quickSearchPersonal($params); |
---|
| 305 | else |
---|
| 306 | //Veirifica se quem chamou foi o campo de pesquisa rápida Expresso_Mail |
---|
| 307 | if(($params['field'] == 'null') && ($params['ID'] == 'null')) |
---|
| 308 | return $this->quickSearch($params); |
---|
| 309 | else |
---|
| 310 | return $this->quickSearchAll($params); |
---|
| 311 | } |
---|
| 312 | } |
---|
| 313 | } |
---|
| 314 | |
---|
| 315 | |
---|
| 316 | |
---|
| 317 | /** |
---|
| 318 | * Método que faz a busca de usuários em todos os catálogos |
---|
| 319 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
| 320 | * @author Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) |
---|
| 321 | * @sponsor Caixa Econômica Federal |
---|
| 322 | * @author Prognus Software Livre <airton@prognus.com.br | prognus@prognus.com.br> |
---|
| 323 | * @param <array> <$param> <parametros vindos do cliente> |
---|
| 324 | * @return <array> <$retorno> <Array com os usuários de todos os catálogos, de acordo com o parâmetro> |
---|
| 325 | */ |
---|
| 326 | function quickSearchAll($params) |
---|
| 327 | { |
---|
| 328 | |
---|
| 329 | $retorno_personal = $this->quickSearchPersonal($params); |
---|
| 330 | $retorno_global = $this->quickSearchGlobal($params); |
---|
| 331 | //$retorno = $retorno_personal + $retorno_global; |
---|
| 332 | $retorno = array_merge($retorno_personal, $retorno_global); |
---|
[5172] | 333 | |
---|
[5075] | 334 | $retorno['type_catalog'] = "A"; |
---|
[5172] | 335 | $retorno['search_for'] = $params['search_for']; |
---|
[5075] | 336 | return $retorno; |
---|
| 337 | } |
---|
| 338 | |
---|
| 339 | |
---|
| 340 | /** |
---|
| 341 | * Método que faz a busca de usuários no Catálogo Pessoal |
---|
| 342 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
| 343 | * @author Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) |
---|
| 344 | * @sponsor Caixa Econômica Federal |
---|
| 345 | * @author Prognus Software Livre <airton@prognus.com.br | prognus@prognus.com.br> |
---|
| 346 | * @param <array> <$param> <parametros vindos do cliente> |
---|
| 347 | * @return <array> <$retorno> <Array com os usuários do Catálogo Pessoal, de acordo com o parâmetro> |
---|
| 348 | */ |
---|
| 349 | function quickSearchPersonal($params, $all=false) |
---|
| 350 | { |
---|
| 351 | $results = array(); |
---|
| 352 | $DBService = ServiceLocator::getService('db'); |
---|
| 353 | $results = $DBService->search_contacts($params['search_for']); |
---|
[5209] | 354 | $results2 = array(); |
---|
[5172] | 355 | $results2 = $DBService->search_groups($params['search_for']); |
---|
[5075] | 356 | |
---|
[5209] | 357 | if(is_array($results)){ |
---|
| 358 | if(is_array($results2)){ |
---|
| 359 | $results = array_merge($results, $results2); |
---|
| 360 | } |
---|
| 361 | } |
---|
| 362 | else if(is_array($results2)){ |
---|
| 363 | $results = $results2; |
---|
| 364 | } |
---|
| 365 | |
---|
[5075] | 366 | if(!$all) |
---|
| 367 | $results['type_catalog'] = "P"; |
---|
[5134] | 368 | |
---|
| 369 | foreach($results as $i=>$value) |
---|
| 370 | $results[$i]['type_contact'] = "P"; |
---|
| 371 | |
---|
[5172] | 372 | $results['search_for'] = $params['search_for']; |
---|
[5209] | 373 | |
---|
[5075] | 374 | return $results; |
---|
| 375 | } |
---|
| 376 | |
---|
| 377 | |
---|
| 378 | /** |
---|
| 379 | * Método que faz a busca de usuários no Catálogo Geral |
---|
| 380 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
| 381 | * @author Consórcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) |
---|
| 382 | * @sponsor Caixa Econômica Federal |
---|
| 383 | * @author Prognus Software Livre <airton@prognus.com.br | prognus@prognus.com.br> |
---|
| 384 | * @param <array> <$param> <parametros vindos do cliente> |
---|
| 385 | * @return <array> <$retorno> <Array com os usuários do Catálogo Global, de acordo com o parâmetro> |
---|
| 386 | */ |
---|
| 387 | function quickSearchGlobal($params, $all=false) |
---|
| 388 | { |
---|
[5316] | 389 | include_once dirname(__FILE__). '/../../header.inc.php'; |
---|
[5075] | 390 | $c = CreateObject('phpgwapi.config','contactcenter'); |
---|
| 391 | $all_data = $c->read_repository(); |
---|
| 392 | |
---|
| 393 | $searchable_fields = array(); |
---|
| 394 | foreach($all_data as $index => $value) |
---|
| 395 | { |
---|
| 396 | $parts = explode('_', $index); |
---|
| 397 | if (is_numeric($parts[3]) && $parts[1]=='attribute') |
---|
| 398 | { |
---|
[5134] | 399 | if($parts[2] == 'searchable' /*&& $value == 'true'*/) |
---|
[5075] | 400 | $searchable_fields[$all_data['cc_attribute_ldapname_' . $parts[3]]] = $all_data['cc_attribute_name_' . $parts[3]]; |
---|
| 401 | } |
---|
| 402 | } |
---|
| 403 | include_once("class.functions.inc.php"); |
---|
| 404 | $functions = new functions; |
---|
| 405 | $field = $params['field']; |
---|
| 406 | $ID = $params['ID']; |
---|
| 407 | $ldapService = ServiceLocator::getService('ldap'); |
---|
| 408 | $filter = $ldapService->getSearchFilter($params['search_for']); |
---|
| 409 | |
---|
| 410 | $contacts_result = array(); |
---|
| 411 | $contacts_result['field'] = $field; |
---|
| 412 | $contacts_result['ID'] = $ID; |
---|
| 413 | $search_for = utf8_encode($params['search_for']); |
---|
| 414 | |
---|
| 415 | $this->ldapConnect(true); |
---|
| 416 | if ($this->ds) |
---|
| 417 | { |
---|
| 418 | $ldapService->connection = $this->ds; |
---|
| 419 | $campos_extras = ''; |
---|
| 420 | $justthese = array("cn", "mail", "telephonenumber", "mobile", "phpgwaccountvisible", "uid", "employeenumber", "ou"); |
---|
| 421 | foreach($searchable_fields as $fields_ldap => $value_field) |
---|
| 422 | { |
---|
| 423 | $campos_extras .= $fields_ldap . "|" . $value_field . "#"; |
---|
| 424 | array_push($justthese, $fields_ldap); |
---|
| 425 | } |
---|
| 426 | $types = false; |
---|
| 427 | |
---|
| 428 | $campos_extras = substr($campos_extras,0,-1); |
---|
| 429 | |
---|
| 430 | if($field == 'null' || $ID == 'null') |
---|
| 431 | { |
---|
| 432 | $justthese[] = "jpegphoto"; |
---|
| 433 | $types = 'u'; |
---|
| 434 | } |
---|
| 435 | $filter = $ldapService->getSearchFilter($params['search_for'], $types); |
---|
| 436 | // Retirei o this->max_results, que limitava a busca. Agora ta retornando tudo amigo. |
---|
| 437 | $sr=@ldap_search($this->ds, $this->ldap_context, $filter, $justthese, 0); |
---|
| 438 | |
---|
| 439 | if(!$sr) |
---|
| 440 | return null; |
---|
| 441 | |
---|
| 442 | $count_entries = ldap_count_entries($this->ds,$sr); |
---|
| 443 | $info = ldap_get_entries($this->ds, $sr); |
---|
| 444 | $info_return = $info; |
---|
| 445 | //if($campos_extras != '') |
---|
| 446 | //array_push($info_return, $campos_extras); |
---|
| 447 | } |
---|
| 448 | ldap_close($this->ds); |
---|
[5199] | 449 | |
---|
[5075] | 450 | //Busca em Catalagos externos |
---|
| 451 | $catalogsNum=count($this->external_srcs); |
---|
| 452 | for ($i=0; $i<=$catalogsNum; $i++) { |
---|
| 453 | if ($this->external_srcs[$i]["quicksearch"]) |
---|
| 454 | { |
---|
| 455 | $this->ldapConnect(true,$i); |
---|
| 456 | $filter="(|(cn=*$search_for*)(mail=*$search_for*))"; |
---|
| 457 | $justthese = array("cn", "mail", "telephoneNumber", "mobile", "phpgwAccountVisible", "uid","employeeNumber", "ou"); |
---|
| 458 | $sr=@ldap_search($this->ds, $this->ldap_context, $filter, $justthese, 0, $this->max_result+1); |
---|
| 459 | if(!$sr) |
---|
| 460 | return null; |
---|
| 461 | $count_entries = ldap_count_entries($this->ds,$sr); |
---|
| 462 | $search = ldap_get_entries($this->ds, $sr); |
---|
| 463 | for ($j=0; $j<$search["count"]; $j++) { |
---|
| 464 | $info_return[] = $search[$j]; |
---|
| 465 | } |
---|
| 466 | $info_return["count"] = count($info_return)-1; |
---|
| 467 | } |
---|
| 468 | } |
---|
| 469 | //---------------------------------------------------------------// |
---|
| 470 | |
---|
| 471 | if($all == false) |
---|
| 472 | $info_return['type_catalog'] = "G"; |
---|
| 473 | |
---|
| 474 | $info_return['extra_ldap_fields'] = $campos_extras; |
---|
[5134] | 475 | |
---|
| 476 | foreach($info_return as $i=>$value) |
---|
| 477 | $info_return[$i]['type_contact'] = "G"; |
---|
[5172] | 478 | |
---|
| 479 | $info_return['search_for'] = $params['search_for']; |
---|
[5075] | 480 | return $info_return; |
---|
| 481 | } |
---|
| 482 | |
---|
[271] | 483 | function make_quicksearch_card($info, $cn) |
---|
| 484 | { |
---|
| 485 | include_once("class.functions.inc.php"); |
---|
[387] | 486 | $functions = new functions; |
---|
| 487 | |
---|
[271] | 488 | $contacts_result = array(); |
---|
| 489 | $contacts_result["cn"] = $cn; |
---|
[3388] | 490 | if($_SESSION['phpgw_info']['user']['preferences']['expressoMail']['extended_info']) |
---|
| 491 | $extendedinfo=true; |
---|
| 492 | else |
---|
| 493 | $extendedinfo=false; |
---|
[387] | 494 | |
---|
[5245] | 495 | list ($contacts_result["mail"], $contacts_result["phone"], $contacts_result["mobile"], $contacts_result["uid"], $contacts_result["jpegphoto"], $contacts_result["employeenumber"], $contacts_result["ou"]) = split ('%', $info); |
---|
[3388] | 496 | |
---|
[271] | 497 | if ($contacts_result['jpegphoto']) |
---|
| 498 | $photo_link = '<img src="./inc/show_user_photo.php?mail='.$contacts_result['mail'].'">'; |
---|
| 499 | else |
---|
[1495] | 500 | $photo_link = '<img src="./templates/default/images/photo.jpg">'; |
---|
[387] | 501 | |
---|
[271] | 502 | $phoneUser = $contacts_result['phone']; |
---|
[387] | 503 | |
---|
[271] | 504 | if($_SESSION['phpgw_info']['user']['preferences']['expressoMail']['voip_enabled'] && $phoneUser) { |
---|
[342] | 505 | $phoneUser = '<a title="'.$this->functions->getLang("Call to Comercial Number").'" href="#" onclick="InfoContact.connectVoip(\''.$phoneUser.'\',\'com\')">'.$phoneUser.'</a>'; |
---|
[271] | 506 | if($contacts_result['mobile']){ |
---|
[342] | 507 | $phoneUser .= ' / <a title="'.$this->functions->getLang("Call to Mobile Number").'" href="#" onclick="InfoContact.connectVoip(\''.$contacts_result['mobile'].'\',\'mob\')">'.$contacts_result['mobile'].'</a>'; |
---|
[271] | 508 | } |
---|
| 509 | } |
---|
[3388] | 510 | //verifica de existe o celular do funcionario ($contacts_result["mobile"]), se nao, $phoneUser fica vazia; |
---|
| 511 | |
---|
| 512 | $mobileUser = $contacts_result["mobile"]; |
---|
| 513 | if($mobileUser && !$voipMobile) { |
---|
| 514 | $phoneUser .= " / $mobileUser"; |
---|
| 515 | } |
---|
| 516 | $empNumber = $contacts_result["employeenumber"]; |
---|
[5245] | 517 | $uid = $contacts_result["uid"]; |
---|
[3388] | 518 | if($empNumber) { |
---|
| 519 | $empNumber = "$empNumber - "; |
---|
[5237] | 520 | } |
---|
[5245] | 521 | else if($uid){ |
---|
| 522 | $uid = "$uid - "; |
---|
[5237] | 523 | } |
---|
[3388] | 524 | $ou = $contacts_result["ou"]; |
---|
| 525 | if($ou) { |
---|
| 526 | $ou = "<br/>$ou" ; |
---|
| 527 | } |
---|
| 528 | |
---|
[644] | 529 | // Begin: nickname, firstname and lastname for QuickAdd. |
---|
| 530 | $fn = $contacts_result["cn"]; |
---|
| 531 | $array_name = explode(" ", $fn); |
---|
| 532 | if(count($array_name) > 1){ |
---|
| 533 | $fn = $array_name[0]; |
---|
| 534 | array_shift($array_name); |
---|
| 535 | $sn = implode(" ",$array_name); |
---|
| 536 | } |
---|
| 537 | // End: |
---|
[271] | 538 | $option = |
---|
| 539 | '<tr class="quicksearchcontacts_unselected">' . |
---|
| 540 | '<td class="cc" width="1%">' . |
---|
[342] | 541 | '<a title="'.$this->functions->getLang("Write message").'" onClick="javascript:QuickSearchUser.create_new_message(\''.$contacts_result["cn"].'\', \''.$contacts_result["mail"].'\')">' . |
---|
[271] | 542 | $photo_link . |
---|
| 543 | '</a>' . |
---|
| 544 | '</td>' . |
---|
| 545 | '<td class="cc">' . |
---|
[5245] | 546 | '<span name="cn">' . ($empNumber != "" ? $empNumber : $uid) . $contacts_result['cn'] . '</span>' . '<br>' . |
---|
[3388] | 547 | '<a title="'.$functions->getLang("Write message").'" onClick="javascript:QuickSearchUser.create_new_message(\''.$contacts_result["cn"].'\', \''.$contacts_result["mail"].'\')">' . |
---|
[271] | 548 | '<font color=blue>' . |
---|
[644] | 549 | '<span name="mail">' . $contacts_result['mail'] . '</span></a></font>'. |
---|
| 550 | '<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"].'\')">'. |
---|
| 551 | '<br>' . |
---|
[271] | 552 | $phoneUser . |
---|
[3388] | 553 | $ou . |
---|
[271] | 554 | '</td>' . |
---|
[644] | 555 | '</tr>'; |
---|
[271] | 556 | return $option; |
---|
| 557 | } |
---|
| 558 | |
---|
[387] | 559 | function get_catalogs(){ |
---|
[325] | 560 | $catalogs = array(); |
---|
[387] | 561 | $catalogs[0] = $this->functions->getLang("Global Catalog"); |
---|
| 562 | if($this->external_srcs) |
---|
[342] | 563 | foreach ($this->external_srcs as $key => $valor ){ |
---|
[325] | 564 | $catalogs[$key] = $valor['name']; |
---|
| 565 | } |
---|
| 566 | return $catalogs; |
---|
| 567 | } |
---|
[2] | 568 | function get_organizations($params){ |
---|
| 569 | $organizations = array(); |
---|
[325] | 570 | $params['referral']?$referral = $params['referral']:$referral = false; |
---|
| 571 | $cat = $params['catalog']; |
---|
[2] | 572 | |
---|
[325] | 573 | $this->ldapConnect($referral,$cat); |
---|
| 574 | |
---|
| 575 | if($this->branch != '') { |
---|
[1363] | 576 | $filter="(&(".$this->branch."=*)(!(phpgwAccountVisible=-1)))"; |
---|
[325] | 577 | $justthese = array("$this->branch"); |
---|
[342] | 578 | $sr = ldap_list($this->ds, $this->ldap_context, $filter, $justthese); |
---|
| 579 | $info = ldap_get_entries($this->ds, $sr); |
---|
[387] | 580 | |
---|
[3530] | 581 | if($info["count"] == 0) |
---|
| 582 | { |
---|
| 583 | $organizations[0]['ou'] = $this->ldap_context; |
---|
| 584 | } |
---|
| 585 | |
---|
[342] | 586 | for ($i=0; $i<$info["count"]; $i++) |
---|
| 587 | $organizations[$i] = $info[$i]["ou"][0]; |
---|
[325] | 588 | |
---|
[342] | 589 | ldap_close($this->ds); |
---|
[387] | 590 | sort($organizations); |
---|
[342] | 591 | return $organizations; |
---|
[325] | 592 | }else{ |
---|
| 593 | return null; |
---|
[2] | 594 | } |
---|
[342] | 595 | } |
---|
[2] | 596 | function get_organizations2($params){ |
---|
| 597 | $organizations = array(); |
---|
| 598 | $referral = $params['referral']; |
---|
| 599 | $this->ldapRootConnect($referral); |
---|
| 600 | if ($this->ds) { |
---|
[3530] | 601 | $filter="(&(objectClass=organizationalUnit)(!(phpgwAccountVisible=-1)))"; |
---|
[2] | 602 | $justthese = array("ou"); |
---|
| 603 | $sr = ldap_list($this->ds, $this->ldap_context, $filter, $justthese); |
---|
| 604 | $info = ldap_get_entries($this->ds, $sr); |
---|
[387] | 605 | |
---|
[3530] | 606 | |
---|
| 607 | if($info["count"] == 0) |
---|
[2] | 608 | { |
---|
[3530] | 609 | $organizations[0]['ou'] = $this->ldap_context; |
---|
| 610 | $organizations[0]['dn'] = $this->ldap_context; |
---|
[2] | 611 | } |
---|
[3530] | 612 | else{ |
---|
| 613 | for ($i=0; $i<$info["count"]; $i++) |
---|
| 614 | { |
---|
| 615 | $organizations[$i]['ou'] = $info[$i]["ou"][0]; |
---|
| 616 | $organizations[$i]['dn'] = $info[$i]["dn"]; |
---|
| 617 | } |
---|
| 618 | } |
---|
[2] | 619 | ldap_close($this->ds); |
---|
[387] | 620 | sort($organizations); |
---|
[2] | 621 | } |
---|
| 622 | return $organizations; |
---|
| 623 | } |
---|
[925] | 624 | //Busca usuarios de um contexto e ja retorna as options do select - usado por template serpro; |
---|
| 625 | function search_users($params) |
---|
[4929] | 626 | { |
---|
| 627 | $owner = $_SESSION['phpgw_info']['expressomail']['user']['owner']; |
---|
[4457] | 628 | $ldapService = ServiceLocator::getService('ldap'); |
---|
| 629 | $ldapService->connect($_SESSION['phpgw_info']['expressomail']['server']['ldap_host'], |
---|
| 630 | $_SESSION['phpgw_info']['expressomail']['server']['ldap_root_dn'], |
---|
| 631 | $_SESSION['phpgw_info']['expressomail']['server']['ldap_root_pw']); |
---|
[4929] | 632 | |
---|
[5134] | 633 | $groups = $ldapService->accountSearch($params['filter'], array("gidNumber","cn", 'uid'), $params['context'] , 'g', 'cn'); |
---|
| 634 | $users = $ldapService->accountSearch($params['filter'], array("uidNumber","cn", 'uid'), $params['context'] , 'u', 'cn'); |
---|
| 635 | $compartilhadas = $ldapService->accountSearch($params['filter'], array("uidNumber","cn",'uid'), $params['context'] , 's', 'cn'); |
---|
| 636 | |
---|
| 637 | |
---|
[4457] | 638 | $group_options = array(); |
---|
| 639 | $user_options = array(); |
---|
[5134] | 640 | $shared_options = array(); |
---|
| 641 | |
---|
[4457] | 642 | foreach($groups as $group) |
---|
[4929] | 643 | { |
---|
[5134] | 644 | $group_options[] = '"'.$group['gidnumber'].'U'.'":"'.$group['cn'].' ('.$group['uid'].')"'; |
---|
[925] | 645 | } |
---|
[4457] | 646 | foreach($users as $user) |
---|
[4929] | 647 | { |
---|
[5134] | 648 | if($owner != $user['uidnumber']) |
---|
| 649 | $user_options[] = '"'.$user['uidnumber'].'U'.'":"'.$user['cn'].' ('.$user['uid'].')"'; |
---|
| 650 | } |
---|
| 651 | foreach($compartilhadas as $shared) |
---|
| 652 | { |
---|
| 653 | if($owner != $shared['uidnumber']) |
---|
| 654 | $shared_options[] = '"'.$shared['uidnumber'].'U'.'":"'.$shared['cn'].' ('.$shared['uid'].')"'; |
---|
[4929] | 655 | } |
---|
| 656 | |
---|
[4457] | 657 | $user_options = '{'.implode( ',', $user_options ).'}'; |
---|
| 658 | $group_options = '{'.implode( ',', $group_options ).'}'; |
---|
[5134] | 659 | $shared_options = '{'.implode( ',', $shared_options ).'}'; |
---|
[4929] | 660 | |
---|
[5134] | 661 | return '{"users":'.$user_options.',"groups":'.$group_options.',"shared":'. $shared_options .'}'; |
---|
[4929] | 662 | } |
---|
[925] | 663 | |
---|
[2] | 664 | function catalogsearch($params) |
---|
[387] | 665 | { |
---|
[4457] | 666 | $ldapService = ServiceLocator::getService('ldap'); |
---|
| 667 | $filter = $ldapService->getSearchFilter($params['search_for'],array('u','l','s')); |
---|
| 668 | |
---|
[325] | 669 | $catalog = $params['catalog']; |
---|
[2] | 670 | $error = False; |
---|
[4929] | 671 | |
---|
[4457] | 672 | //if($_SESSION['phpgw_info']['user']['preferences']['expressoMail']['extended_info']) |
---|
| 673 | //$extendedinfo=true; |
---|
| 674 | //else |
---|
| 675 | //$extendedinfo=false; |
---|
[387] | 676 | |
---|
[3388] | 677 | |
---|
[381] | 678 | $this->ldapConnect(true,$catalog); |
---|
[387] | 679 | |
---|
| 680 | $params['organization'] == 'all' ? $user_context = $this->ldap_context :$user_context = $this->branch."=".$params['organization'].",".$this->ldap_context; |
---|
| 681 | |
---|
| 682 | if ($this->ds) { |
---|
[4929] | 683 | $justthese = array("cn", "mail", "phpgwaccounttype", "phpgwAccountVisible", "employeeNumber", "ou"); |
---|
[4457] | 684 | $sr=@ldap_search($this->ds, $user_context, $filter, $justthese, 0, $ldapService->limit+1); |
---|
[4929] | 685 | |
---|
[342] | 686 | if(!$sr) |
---|
| 687 | return null; |
---|
[2] | 688 | $count_entries = ldap_count_entries($this->ds,$sr); |
---|
[4457] | 689 | if ($count_entries > $ldapService->limit){ |
---|
[2] | 690 | $info = null; |
---|
[387] | 691 | $error = True; |
---|
[2] | 692 | } |
---|
| 693 | else |
---|
[387] | 694 | $info = ldap_get_entries($this->ds, $sr); |
---|
| 695 | |
---|
| 696 | ldap_close($this->ds); |
---|
| 697 | |
---|
[2] | 698 | $u_tmp = array(); |
---|
| 699 | $g_tmp = array(); |
---|
[387] | 700 | |
---|
[2] | 701 | for ($i=0; $i<$info["count"]; $i++){ |
---|
[325] | 702 | if((!$catalog==0)||(strtoupper($info[$i]["phpgwaccounttype"][0]) == 'U') && ($info[$i]["phpgwaccountvisible"][0] != '-1')) |
---|
| 703 | //aqui eh feita a concatenacao do departamento ao cn; |
---|
| 704 | $u_tmp[$info[$i]["mail"][0]] = utf8_decode($info[$i]["cn"][0]). '%' . $info[$i]["ou"][0]; |
---|
[387] | 705 | if((!$catalog==0)||(strtoupper($info[$i]["phpgwaccounttype"][0]) == 'L') && ($info[$i]["phpgwaccountvisible"][0] != '-1')) |
---|
[325] | 706 | $g_tmp[$info[$i]["mail"][0]] = utf8_decode($info[$i]["cn"][0]); |
---|
[387] | 707 | } |
---|
| 708 | |
---|
[2] | 709 | natcasesort($u_tmp); |
---|
| 710 | natcasesort($g_tmp); |
---|
[387] | 711 | |
---|
[2] | 712 | $i = 0; |
---|
[387] | 713 | $users = array(); |
---|
[325] | 714 | |
---|
[387] | 715 | foreach ($u_tmp as $mail => $cn){ |
---|
| 716 | |
---|
[325] | 717 | $tmp = explode("%", $cn); //explode o cn pelo caracter "%" e joga em $tmp; |
---|
| 718 | $name = $tmp[0]; //pega o primeiro item (cn) do vetor resultante do explode acima; |
---|
| 719 | $department = $tmp[1]; //pega o segundo item (ou) do vetor resultanto do explode acima; |
---|
| 720 | $users[$i++] = array("name" => $name, "email" => $mail, "department" => $department); |
---|
| 721 | |
---|
[2] | 722 | } |
---|
| 723 | unset($u_tmp); |
---|
[387] | 724 | |
---|
| 725 | $i = 0; |
---|
[2] | 726 | $groups = array(); |
---|
[387] | 727 | |
---|
| 728 | foreach ($g_tmp as $mail => $cn){ |
---|
[2] | 729 | $groups[$i++] = array("name" => $cn, "email" => $mail); |
---|
| 730 | } |
---|
| 731 | unset($g_tmp); |
---|
[387] | 732 | |
---|
[4457] | 733 | return array('users' => $users, 'groups' => $groups, 'error' => $error,'maxResult' => $ldapService->limit); |
---|
[387] | 734 | }else |
---|
[2] | 735 | return null; |
---|
| 736 | } |
---|
[387] | 737 | |
---|
[2] | 738 | function get_emails_ldap(){ |
---|
| 739 | |
---|
| 740 | $result['mail']= array(); |
---|
[387] | 741 | $result['mailalter']= array(); |
---|
[2] | 742 | $user = $_SESSION['phpgw_info']['expressomail']['user']['account_lid']; |
---|
| 743 | $this->ldapRootConnect(false); |
---|
| 744 | if ($this->ds) { |
---|
[387] | 745 | $filter="uid=".$user; |
---|
[2] | 746 | $justthese = array("mail","mailAlternateAddress"); |
---|
| 747 | $sr = ldap_search($this->ds,$this->ldap_context, $filter, $justthese); |
---|
| 748 | $ent = ldap_get_entries($this->ds, $sr); |
---|
| 749 | ldap_close($this->ds); |
---|
[387] | 750 | |
---|
[2] | 751 | for ($i=0; $i<$ent["count"]; $i++){ |
---|
| 752 | $result['mail'][] = $ent[$i]["mail"][0]; |
---|
[387] | 753 | $result['mailalter'][] = $ent[$i]["mailalternateaddress"][0]; |
---|
[2] | 754 | } |
---|
| 755 | } |
---|
| 756 | return $result; |
---|
| 757 | } |
---|
[387] | 758 | |
---|
[342] | 759 | //Busca usuarios de um contexto e ja retorna as options do select; |
---|
[2] | 760 | function get_available_users($params) |
---|
[37] | 761 | { |
---|
| 762 | $this->ldapRootConnect(); |
---|
[342] | 763 | //Monta lista de Grupos e Usuarios |
---|
[37] | 764 | $users = Array(); |
---|
| 765 | $groups = Array(); |
---|
| 766 | $user_context= $params['context']; |
---|
| 767 | $owner = $_SESSION['phpgw_info']['expressomail']['user']['owner']; |
---|
[2] | 768 | |
---|
[37] | 769 | if ($this->ds) |
---|
| 770 | { |
---|
| 771 | $justthese = array("gidNumber","cn"); |
---|
| 772 | if ($params['type'] == 'search') |
---|
| 773 | $sr=ldap_search($this->ds, $user_context, ("(&(cn=*)(phpgwaccounttype=g)(!(phpgwaccountvisible=-1)))"),$justthese); |
---|
| 774 | else |
---|
| 775 | $sr=ldap_list($this->ds, $user_context, ("(&(cn=*)(phpgwaccounttype=g)(!(phpgwaccountvisible=-1)))"),$justthese); |
---|
| 776 | $info = ldap_get_entries($this->ds, $sr); |
---|
| 777 | for ($i=0; $i<$info["count"]; $i++) |
---|
[387] | 778 | $groups[$uids=$info[$i]["gidnumber"][0]] = Array('name' => $uids=$info[$i]["cn"][0], 'type' => g); |
---|
[37] | 779 | $justthese = array("phpgwaccountvisible","uidNumber","cn"); |
---|
| 780 | if ($params['type'] == 'search') |
---|
| 781 | $sr=ldap_search($this->ds, $user_context, ("(&(cn=*)(phpgwaccounttype=u)(!(phpgwaccountvisible=-1)))"),$justthese); |
---|
| 782 | else |
---|
| 783 | $sr=ldap_list($this->ds, $user_context, ("(&(cn=*)(phpgwaccounttype=u)(!(phpgwaccountvisible=-1)))"),$justthese); |
---|
[2] | 784 | |
---|
[37] | 785 | $info = ldap_get_entries($this->ds, $sr); |
---|
| 786 | for ($i=0; $i<$info["count"]; $i++) |
---|
| 787 | { |
---|
| 788 | if ($info[$i]["phpgwaccountvisible"][0] == '-1') |
---|
| 789 | continue; |
---|
| 790 | $users[$uids=$info[$i]["uidnumber"][0]] = Array('name' => $uids=$info[$i]["cn"][0], 'type' => u); |
---|
| 791 | } |
---|
| 792 | } |
---|
| 793 | ldap_close($this->ds); |
---|
[387] | 794 | |
---|
[37] | 795 | @asort($users); |
---|
[387] | 796 | @reset($users); |
---|
[37] | 797 | @asort($groups); |
---|
| 798 | @reset($groups); |
---|
| 799 | $user_options =''; |
---|
| 800 | $group_options =''; |
---|
[2] | 801 | |
---|
[37] | 802 | foreach($groups as $id => $user_array) { |
---|
| 803 | $newId = $id.'U'; |
---|
| 804 | $group_options .= '<option value="'.$newId.'">'.utf8_decode($user_array['name']).'</option>'."\n"; |
---|
| 805 | } |
---|
| 806 | foreach($users as $id => $user_array) { |
---|
| 807 | if($owner != $id){ |
---|
| 808 | $newId = $id.'U'; |
---|
| 809 | $user_options .= '<option value="'.$newId.'">'.utf8_decode($user_array['name']).'</option>'."\n"; |
---|
| 810 | } |
---|
| 811 | } |
---|
| 812 | return array("users" => $user_options, "groups" => $group_options); |
---|
| 813 | } |
---|
| 814 | |
---|
[342] | 815 | //Busca usuarios de um contexto e ja retorna as options do select; |
---|
[2] | 816 | function get_available_users2($params) |
---|
| 817 | { |
---|
[4457] | 818 | $ldapService = ServiceLocator::getService('ldap'); |
---|
| 819 | $ldapService->connect($_SESSION['phpgw_info']['expressomail']['server']['ldap_host'], |
---|
| 820 | $_SESSION['phpgw_info']['expressomail']['server']['ldap_root_dn'], |
---|
| 821 | $_SESSION['phpgw_info']['expressomail']['server']['ldap_root_pw']); |
---|
[4929] | 822 | |
---|
[4457] | 823 | $entries = $ldapService->accountSearch($params['sentence'], array('cn', 'uid'), $params['context'], 'u', 'cn'); |
---|
[4929] | 824 | |
---|
[4457] | 825 | $options = array(); |
---|
[4929] | 826 | |
---|
[4457] | 827 | foreach ($entries as $value) |
---|
| 828 | $options[] = '"'.$value['uid'].'"'.':'.'"'.$value['cn'].'"'; |
---|
[4929] | 829 | |
---|
[4457] | 830 | return "{".implode(',',$options)."}"; |
---|
[4929] | 831 | } |
---|
[387] | 832 | |
---|
[2] | 833 | function uid2cn($uid) |
---|
[387] | 834 | { |
---|
[2] | 835 | // do not follow the referral |
---|
| 836 | $this->ldapRootConnect(false); |
---|
| 837 | if ($this->ds) |
---|
| 838 | { |
---|
[387] | 839 | $filter="(&(phpgwAccountType=u)(uid=$uid))"; |
---|
[2] | 840 | $justthese = array("cn"); |
---|
[344] | 841 | $sr=@ldap_search($this->ds, $this->ldap_context, $filter, $justthese); |
---|
| 842 | if(!$sr) |
---|
| 843 | return false; |
---|
[2] | 844 | $info = ldap_get_entries($this->ds, $sr); |
---|
[325] | 845 | return utf8_decode($info[0]["cn"][0]); |
---|
[2] | 846 | } |
---|
| 847 | return false; |
---|
| 848 | } |
---|
[757] | 849 | function uidnumber2uid($uidnumber) |
---|
| 850 | { |
---|
| 851 | // do not follow the referral |
---|
| 852 | $this->ldapRootConnect(false); |
---|
| 853 | if ($this->ds) |
---|
| 854 | { |
---|
| 855 | $filter="(&(phpgwAccountType=u)(uidnumber=$uidnumber))"; |
---|
| 856 | $justthese = array("uid"); |
---|
| 857 | $sr=@ldap_search($this->ds, $this->ldap_context, $filter, $justthese); |
---|
| 858 | if(!$sr) |
---|
| 859 | return false; |
---|
| 860 | $info = ldap_get_entries($this->ds, $sr); |
---|
| 861 | return $info[0]["uid"][0]; |
---|
| 862 | } |
---|
| 863 | return false; |
---|
| 864 | } |
---|
[387] | 865 | function getSharedUsersFrom($params){ |
---|
[2] | 866 | $filter = ''; |
---|
[1912] | 867 | $i = 0; |
---|
| 868 | //Added to save if must save sent messages in shared folder |
---|
| 869 | $acl_save_sent_in_shared = array(); |
---|
| 870 | |
---|
[371] | 871 | if($params['uids']) { |
---|
[387] | 872 | $uids = explode(";",$params['uids']); |
---|
[1912] | 873 | $this->imap = new imap_functions(); |
---|
[371] | 874 | foreach($uids as $index => $uid){ |
---|
[387] | 875 | $params = array(); |
---|
[1912] | 876 | //Added to save if user has create permission |
---|
| 877 | $acl_create_message = array(); |
---|
[371] | 878 | $acl = $this->imap->getacltouser($uid); |
---|
[1912] | 879 | if ( preg_match("/a/",$acl )){ |
---|
| 880 | $filter .= "(uid=$uid)"; |
---|
| 881 | if ( preg_match("/p/",$acl )){ |
---|
| 882 | $acl_save_sent_in_shared[ $i ] =$uid; |
---|
| 883 | $i++; |
---|
| 884 | } |
---|
| 885 | } |
---|
| 886 | } |
---|
[2] | 887 | } |
---|
[1912] | 888 | |
---|
[387] | 889 | $this->ldapRootConnect(false); |
---|
[371] | 890 | if ($this->ds) { |
---|
[1912] | 891 | $justthese = array("cn","mail","uid"); |
---|
[371] | 892 | if($filter) { |
---|
[1912] | 893 | $filter="(&(|(phpgwAccountType=u)(phpgwAccountType=s))(|$filter))"; |
---|
[371] | 894 | $sr = ldap_search($this->ds, $this->ldap_context, $filter, $justthese); |
---|
[387] | 895 | ldap_sort($this->ds,$sr,"cn"); |
---|
| 896 | $info = ldap_get_entries($this->ds, $sr); |
---|
[1912] | 897 | $var = print_r($acl_save_sent_in_shared, true); |
---|
| 898 | for ($i = 0;$i < $info["count"]; $i++){ |
---|
[371] | 899 | $info[$i]['cn'][0] = utf8_decode($info[$i]['cn'][0]); |
---|
[1912] | 900 | //verify if user has permission to save sent messages in a shared folder |
---|
| 901 | if ( in_array( $info[$i]['uid'][0],$acl_save_sent_in_shared) ){ |
---|
| 902 | $info[$i]['save_shared'][0] = 'y'; |
---|
| 903 | } else $info[$i]['save_shared'][0] = 'n'; |
---|
| 904 | } |
---|
[371] | 905 | } |
---|
[1912] | 906 | |
---|
[371] | 907 | $info['myname'] = $_SESSION['phpgw_info']['expressomail']['user']['fullname']; |
---|
[387] | 908 | |
---|
[371] | 909 | //Find institucional_account. |
---|
| 910 | $filter="(&(phpgwAccountType=i)(mailForwardingAddress=".$_SESSION['phpgw_info']['expressomail']['user']['email']."))"; |
---|
[387] | 911 | $sr = ldap_search($this->ds, $this->ldap_context, $filter, $justthese); |
---|
[448] | 912 | ## |
---|
| 913 | # @AUTHOR Rodrigo Souza dos Santos |
---|
| 914 | # @DATE 2008/09/17 |
---|
| 915 | # @BRIEF Changing to ensure that the variable session is always with due value. |
---|
| 916 | ## |
---|
| 917 | if(ldap_count_entries($this->ds,$sr)) |
---|
| 918 | { |
---|
| 919 | ldap_sort($this->ds,$sr,"cn"); |
---|
| 920 | $result = ldap_get_entries($this->ds, $sr); |
---|
| 921 | for ($j = 0;$j < $result["count"]; $j++){ |
---|
| 922 | $info[$i]['cn'][0] = utf8_decode($result[$j]['cn'][0]); |
---|
[1912] | 923 | $info[$i]['mail'][0] = $result[$j]['mail'][0]; |
---|
| 924 | $info[$i]['save_shared'][0] = 'n'; |
---|
| 925 | $info[$i++]['uid'][0] = $result[$j]['uid'][0]; |
---|
[448] | 926 | } |
---|
[371] | 927 | } |
---|
[448] | 928 | |
---|
| 929 | $_SESSION['phpgw_info']['expressomail']['user']['shared_mailboxes'] = $info; |
---|
[1912] | 930 | |
---|
[2] | 931 | return $info; |
---|
| 932 | } |
---|
| 933 | } |
---|
[27] | 934 | |
---|
[205] | 935 | function getUserByEmail($params) |
---|
| 936 | { |
---|
[3163] | 937 | $expires = 60*60*24*30; /* 30 days */ |
---|
| 938 | header("Cache-Control: maxage=".$expires); |
---|
| 939 | header("Pragma: public"); |
---|
| 940 | header("Expires: ".gmdate('D, d M Y H:i:s', time()+$expires)); |
---|
[205] | 941 | $filter="(&(phpgwAccountType=u)(mail=" . $params['email'] . "))"; |
---|
| 942 | $ldap_context = $_SESSION['phpgw_info']['expressomail']['ldap_server']['dn']; |
---|
[3388] | 943 | if($_SESSION['phpgw_info']['user']['preferences']['expressoMail']['extended_info']) |
---|
| 944 | $extendedinfo=true; |
---|
| 945 | else |
---|
| 946 | $extendedinfo=false; |
---|
[205] | 947 | |
---|
[3388] | 948 | if($extendedinfo) |
---|
| 949 | $justthese = array("cn","uid","telephoneNumber","jpegPhoto","mobile","ou","employeeNumber"); |
---|
| 950 | else |
---|
| 951 | $justthese = array("cn","uid","telephoneNumber","jpegPhoto","mobile"); |
---|
| 952 | |
---|
[27] | 953 | // Follow the referral |
---|
[205] | 954 | $ds = $this->ldapConnect2(true); |
---|
| 955 | if ($ds) |
---|
[387] | 956 | { |
---|
[342] | 957 | $sr=@ldap_search($ds, $ldap_context, $filter, $justthese); |
---|
[387] | 958 | |
---|
[205] | 959 | if (!$sr) |
---|
| 960 | return null; |
---|
[387] | 961 | |
---|
[205] | 962 | $entry = ldap_first_entry($ds, $sr); |
---|
[387] | 963 | |
---|
| 964 | if($entry) { |
---|
[381] | 965 | $obj = array("cn" => utf8_decode(current(ldap_get_values($ds, $entry, "cn"))), |
---|
[205] | 966 | "email" => $params['email'], |
---|
| 967 | "uid" => ldap_get_values($ds, $entry, "uid"), |
---|
[27] | 968 | "type" => "global", |
---|
[205] | 969 | "mobile" => @ldap_get_values($ds, $entry, "mobile"), |
---|
[3388] | 970 | "telefone" => @ldap_get_values($ds, $entry, "telephonenumber"), |
---|
| 971 | "ou" => @ldap_get_values($ds, $entry, "ou"), |
---|
| 972 | "employeeNumber" => @ldap_get_values($ds, $entry, "employeeNumber") |
---|
[205] | 973 | ); |
---|
[27] | 974 | |
---|
[320] | 975 | $_SESSION['phpgw_info']['expressomail']['contact_photo'] = @ldap_get_values_len($ds, $entry, "jpegphoto"); |
---|
[205] | 976 | ldap_close($ds); |
---|
[27] | 977 | return $obj; |
---|
[205] | 978 | } |
---|
[27] | 979 | } |
---|
| 980 | return null; |
---|
| 981 | } |
---|
[1500] | 982 | |
---|
| 983 | function uid2uidnumber($uid) |
---|
| 984 | { |
---|
| 985 | // do not follow the referral |
---|
| 986 | $this->ldapRootConnect(false); |
---|
| 987 | if ($this->ds) |
---|
| 988 | { |
---|
| 989 | $filter="(&(phpgwAccountType=u)(uid=$uid))"; |
---|
| 990 | $justthese = array("uidnumber"); |
---|
| 991 | $sr=@ldap_search($this->ds, $this->ldap_context, $filter, $justthese); |
---|
| 992 | if(!$sr) |
---|
| 993 | return false; |
---|
| 994 | $info = ldap_get_entries($this->ds, $sr); |
---|
| 995 | return $info[0]["uidnumber"][0]; |
---|
| 996 | } |
---|
| 997 | return false; |
---|
| 998 | } |
---|
[5134] | 999 | |
---|
| 1000 | function get_user_groups($uid) |
---|
| 1001 | { |
---|
| 1002 | |
---|
| 1003 | $organizations = array(); |
---|
| 1004 | |
---|
| 1005 | $this->ldapRootConnect(); |
---|
| 1006 | |
---|
| 1007 | $justthese = array("gidnumber","cn"); |
---|
| 1008 | $filter="(&(phpgwAccountType=g)(memberuid=".$uid."))"; |
---|
| 1009 | |
---|
| 1010 | $search = ldap_search($this->ds, $this->ldap_context, $filter, $justthese); |
---|
| 1011 | |
---|
| 1012 | $result = array(); |
---|
| 1013 | $entries = ldap_get_entries($this->ds, $search); |
---|
| 1014 | |
---|
| 1015 | |
---|
| 1016 | for ($i=0; $i<$entries['count']; $i++) |
---|
| 1017 | { |
---|
| 1018 | $result[ $entries[$i]['gidnumber'][0] ] = $entries[$i]['cn'][0]; |
---|
| 1019 | } |
---|
| 1020 | |
---|
| 1021 | return $result; |
---|
| 1022 | } |
---|
| 1023 | |
---|
| 1024 | function getMailByUid($pUid) |
---|
| 1025 | { |
---|
| 1026 | // do not follow the referral |
---|
| 1027 | $this->ldapRootConnect(false); |
---|
| 1028 | if ($this->ds) |
---|
| 1029 | { |
---|
| 1030 | $filter="(&(|(phpgwAccountType=u)(phpgwAccountType=s)(phpgwAccountType=l))(uid=$pUid))"; |
---|
| 1031 | $justthese = array("mail"); |
---|
| 1032 | $sr=@ldap_search($this->ds, $this->ldap_context, $filter, $justthese); |
---|
| 1033 | if(!$sr) |
---|
| 1034 | return false; |
---|
| 1035 | $info = ldap_get_entries($this->ds, $sr); |
---|
| 1036 | |
---|
| 1037 | |
---|
| 1038 | return utf8_decode($info[0]["mail"][0]); |
---|
| 1039 | } |
---|
| 1040 | return false; |
---|
| 1041 | } |
---|
| 1042 | |
---|
| 1043 | function mail2uid($mail) |
---|
| 1044 | { |
---|
| 1045 | if(!$this-ds) |
---|
| 1046 | $this->ldapRootConnect(false); |
---|
| 1047 | |
---|
| 1048 | $filter="(&(|(phpgwAccountType=u)(phpgwAccountType=s)(phpgwAccountType=i)(phpgwAccountType=g))(mail=$mail))"; |
---|
| 1049 | $justthese = array("uid"); |
---|
| 1050 | $sr=@ldap_search($this->ds, $this->ldap_context, $filter, $justthese); |
---|
| 1051 | if(!$sr) |
---|
| 1052 | return false; |
---|
| 1053 | $info = ldap_get_entries($this->ds, $sr); |
---|
| 1054 | return $info[0]["uid"][0]; |
---|
| 1055 | } |
---|
| 1056 | |
---|
| 1057 | |
---|
| 1058 | /** |
---|
| 1059 | * Retorna as contas compartilhas |
---|
| 1060 | * @param string $toaddress emails |
---|
| 1061 | * @param string $ccaddress emails |
---|
| 1062 | * @param string $ccoaddress emails |
---|
| 1063 | * @param array $groups array com os grupos que o usuario pertence |
---|
| 1064 | * @return array |
---|
| 1065 | */ |
---|
| 1066 | function returnSharedsAccounts($toaddress,$ccaddress,$ccoaddress) |
---|
| 1067 | { |
---|
| 1068 | |
---|
| 1069 | $arrayAllAddres = array(); |
---|
| 1070 | $arrayAllAddres = array_merge($arrayAllAddres , explode(',',$toaddress)); |
---|
| 1071 | $arrayAllAddres = array_merge($arrayAllAddres, explode(',',$ccaddress)); |
---|
| 1072 | $arrayAllAddres = array_merge($arrayAllAddres, explode(',',$ccoaddress)); |
---|
| 1073 | |
---|
| 1074 | $mailsArray = array(); |
---|
| 1075 | |
---|
| 1076 | foreach ($arrayAllAddres as $toAddres) |
---|
| 1077 | { |
---|
| 1078 | |
---|
| 1079 | if(strchr($toAddres,'@') && strchr($toAddres,'<') && strchr($toAddres,'>')) |
---|
| 1080 | { |
---|
| 1081 | $alias = substr($toAddres, strpos($toAddres,'<'), strpos($toAddres,'>')); |
---|
| 1082 | $alias = str_replace('<','', str_replace('>','',$alias)); |
---|
| 1083 | array_push($mailsArray, $alias); |
---|
| 1084 | } |
---|
| 1085 | else if(strchr($toAddres,'@')) |
---|
| 1086 | { |
---|
| 1087 | array_push($mailsArray, $toAddres); |
---|
| 1088 | } |
---|
| 1089 | } |
---|
| 1090 | $arraySharedAccounts = array(); |
---|
| 1091 | |
---|
| 1092 | $conexao = $this->ldapConnect2(true); |
---|
| 1093 | |
---|
| 1094 | |
---|
| 1095 | $mailFilter = ''; |
---|
| 1096 | |
---|
| 1097 | foreach ($mailsArray as $mail) |
---|
| 1098 | $mailFilter .= '(|(mail='.$mail.')(mailAlternateAddress='.$mail.'))'; |
---|
| 1099 | |
---|
| 1100 | |
---|
| 1101 | $filter = '(&(phpgwAccountType=s)(|'.$mailFilter.') )'; |
---|
| 1102 | $ldap_context = $_SESSION['phpgw_info']['expressomail']['server']['ldap_context']; |
---|
| 1103 | $justthese = array('cn','uid','mail'); |
---|
| 1104 | |
---|
| 1105 | if ($conexao) |
---|
| 1106 | { |
---|
| 1107 | $search = @ldap_search($conexao, $ldap_context, $filter, $justthese); |
---|
| 1108 | if($search) |
---|
| 1109 | { |
---|
| 1110 | $results = ldap_get_entries($conexao, $search); |
---|
| 1111 | |
---|
| 1112 | foreach ($results as $result) |
---|
| 1113 | { |
---|
| 1114 | if($result['mail'][0]) |
---|
| 1115 | array_push($arraySharedAccounts, $result['mail'][0]); |
---|
| 1116 | } |
---|
| 1117 | } |
---|
| 1118 | |
---|
| 1119 | } |
---|
| 1120 | |
---|
| 1121 | return $arraySharedAccounts; |
---|
| 1122 | } |
---|
| 1123 | /** |
---|
| 1124 | * Verifica se um email é uma conta compartilhada |
---|
| 1125 | * |
---|
| 1126 | * @license http://www.gnu.org/copyleft/gpl.html GPL |
---|
| 1127 | * @author Cons?rcio Expresso Livre - 4Linux (www.4linux.com.br) e Prognus Software Livre (www.prognus.com.br) |
---|
| 1128 | * @author Cristiano Corrêa Schmidt |
---|
| 1129 | * @param String $mail Email a ser verificado |
---|
| 1130 | * @return bolean |
---|
| 1131 | * @access public |
---|
| 1132 | */ |
---|
| 1133 | function isSharedAccountByMail($mail) |
---|
| 1134 | { |
---|
| 1135 | $return = false; |
---|
| 1136 | $conexao = $this->ldapConnect2(true); |
---|
| 1137 | $filter = '(&(phpgwAccountType=s)(mail='.$mail.'))'; |
---|
| 1138 | $ldap_context = $_SESSION['phpgw_info']['expressomail']['server']['ldap_context']; |
---|
| 1139 | $justthese = array('cn','uid','mail'); |
---|
| 1140 | if ($conexao) |
---|
| 1141 | { |
---|
| 1142 | $search = @ldap_search($conexao, $ldap_context, $filter, $justthese); |
---|
| 1143 | if(ldap_count_entries ($conexao , $search)) |
---|
| 1144 | $return = true; |
---|
| 1145 | } |
---|
| 1146 | |
---|
| 1147 | return $return; |
---|
| 1148 | } |
---|
[2] | 1149 | } |
---|
[108] | 1150 | ?> |
---|