[3514] | 1 | <?php |
---|
| 2 | /**********************************************************************************\ |
---|
| 3 | * Expresso Administraᅵᅵo * |
---|
| 4 | * by Joao Alfredo Knopik Junior (joao.alfredo@gmail.com, jakjr@celepar.pr.gov.br) * |
---|
| 5 | * --------------------------------------------------------------------------------* |
---|
| 6 | * This program is free software; you can redistribute it and/or modify it * |
---|
| 7 | * under the terms of the GNU General Public License as published by the * |
---|
| 8 | * Free Software Foundation; either version 2 of the License, or (at your * |
---|
| 9 | * option) any later version. * |
---|
| 10 | \**********************************************************************************/ |
---|
| 11 | |
---|
| 12 | include_once('class.db_functions.inc.php'); |
---|
| 13 | |
---|
| 14 | class functions |
---|
| 15 | { |
---|
| 16 | |
---|
| 17 | var $public_functions = array |
---|
| 18 | ( |
---|
| 19 | 'make_array_acl' => True, |
---|
| 20 | 'check_acl' => True, |
---|
| 21 | 'read_acl' => True, |
---|
| 22 | 'exist_account_lid' => True, |
---|
| 23 | 'exist_email' => True, |
---|
| 24 | 'array_invert' => True |
---|
| 25 | ); |
---|
| 26 | |
---|
| 27 | var $nextmatchs; |
---|
| 28 | var $sectors_list = array(); |
---|
| 29 | |
---|
| 30 | function functions() |
---|
| 31 | { |
---|
| 32 | $this->db_functions = new db_functions; |
---|
| 33 | } |
---|
| 34 | |
---|
| 35 | |
---|
| 36 | // Account and type of access. Return: Have access ? (true/false) |
---|
| 37 | function check_acl($account_lid, $access) |
---|
| 38 | { |
---|
| 39 | $acl = $this->read_acl($account_lid); |
---|
| 40 | $array_acl = $this->make_array_acl($acl[0][acl]); |
---|
| 41 | |
---|
| 42 | //What access ?? In the IF, verify if have access. |
---|
| 43 | switch($access) |
---|
| 44 | { |
---|
| 45 | case list_users: |
---|
| 46 | if ($array_acl[add_users] || $array_acl[edit_users] || $array_acl[delete_users] || $array_acl[change_users_password] || $array_acl[change_users_quote] || $array_acl[edit_sambausers_attributes] || $array_acl[view_users]) |
---|
| 47 | return true; |
---|
| 48 | break; |
---|
| 49 | case add_users: |
---|
| 50 | if ($array_acl[add_users]) |
---|
| 51 | return true; |
---|
| 52 | break; |
---|
| 53 | case edit_users: |
---|
| 54 | if ($array_acl[edit_users]) |
---|
| 55 | return true; |
---|
| 56 | break; |
---|
| 57 | case delete_users: |
---|
| 58 | if ($array_acl[delete_users]) |
---|
| 59 | return true; |
---|
| 60 | break; |
---|
| 61 | case rename_users: |
---|
| 62 | if ($array_acl[rename_users]) |
---|
| 63 | return true; |
---|
| 64 | break; |
---|
| 65 | case view_users: |
---|
| 66 | if ($array_acl[view_users]) |
---|
| 67 | return true; |
---|
| 68 | break; |
---|
| 69 | case change_users_password: |
---|
| 70 | if ($array_acl[change_users_password]) |
---|
| 71 | return true; |
---|
| 72 | break; |
---|
| 73 | case change_users_quote: |
---|
| 74 | if ($array_acl[change_users_quote]) |
---|
| 75 | return true; |
---|
| 76 | break; |
---|
| 77 | case set_user_default_password: |
---|
| 78 | if ($array_acl[set_user_default_password]) |
---|
| 79 | return true; |
---|
| 80 | break; |
---|
| 81 | case edit_sambausers_attributes: |
---|
| 82 | if ($array_acl[edit_sambausers_attributes]) |
---|
| 83 | return true; |
---|
| 84 | break; |
---|
| 85 | case edit_sambadomains: |
---|
| 86 | if ($array_acl[edit_sambadomains]) |
---|
| 87 | return true; |
---|
| 88 | break; |
---|
| 89 | |
---|
| 90 | case list_groups: |
---|
| 91 | if ($array_acl[add_groups] || $array_acl[edit_groups] || $array_acl[delete_groups]) |
---|
| 92 | return true; |
---|
| 93 | break; |
---|
| 94 | case add_groups: |
---|
| 95 | if ($array_acl[add_groups]) |
---|
| 96 | return true; |
---|
| 97 | break; |
---|
| 98 | case edit_groups: |
---|
| 99 | if ($array_acl[edit_groups]) |
---|
| 100 | return true; |
---|
| 101 | break; |
---|
| 102 | case delete_groups: |
---|
| 103 | if ($array_acl[delete_groups]) |
---|
| 104 | return true; |
---|
| 105 | break; |
---|
| 106 | case edit_email_groups: |
---|
| 107 | if ($array_acl[edit_email_groups]) |
---|
| 108 | return true; |
---|
| 109 | break; |
---|
| 110 | |
---|
| 111 | case list_maillists: |
---|
| 112 | if ($array_acl[add_maillists] || $array_acl[edit_maillists] || $array_acl[adm_maillists] || $array_acl[delete_maillists]) |
---|
| 113 | return true; |
---|
| 114 | break; |
---|
| 115 | case add_maillists: |
---|
| 116 | if ($array_acl[add_maillists]) |
---|
| 117 | return true; |
---|
| 118 | break; |
---|
| 119 | case edit_maillists: |
---|
| 120 | if ($array_acl[edit_maillists]) |
---|
| 121 | return true; |
---|
| 122 | break; |
---|
| 123 | case adm_maillists: |
---|
| 124 | if ($array_acl[adm_maillists]) |
---|
| 125 | return true; |
---|
| 126 | break; |
---|
| 127 | case delete_maillists: |
---|
| 128 | if ($array_acl[delete_maillists]) |
---|
| 129 | return true; |
---|
| 130 | break; |
---|
| 131 | |
---|
| 132 | case list_sectors: |
---|
| 133 | if ($array_acl[create_sectors] || $array_acl[edit_sectors] || $array_acl[delete_sectors]) |
---|
| 134 | return true; |
---|
| 135 | break; |
---|
| 136 | case create_sectors: |
---|
| 137 | if ($array_acl[create_sectors]) |
---|
| 138 | return true; |
---|
| 139 | break; |
---|
| 140 | case edit_sectors: |
---|
| 141 | if ($array_acl[edit_sectors]) |
---|
| 142 | return true; |
---|
| 143 | break; |
---|
| 144 | case delete_sectors: |
---|
| 145 | if ($array_acl[delete_sectors]) |
---|
| 146 | return true; |
---|
| 147 | break; |
---|
| 148 | |
---|
| 149 | case view_global_sessions: |
---|
| 150 | if ($array_acl[view_global_sessions]) |
---|
| 151 | return true; |
---|
| 152 | break; |
---|
| 153 | |
---|
| 154 | case list_computers: |
---|
| 155 | if ($array_acl[create_computers] || $array_acl[edit_computers] || $array_acl[delete_computers]) |
---|
| 156 | return true; |
---|
| 157 | break; |
---|
| 158 | case create_computers: |
---|
| 159 | if ($array_acl[create_computers]) |
---|
| 160 | return true; |
---|
| 161 | break; |
---|
| 162 | case edit_computers: |
---|
| 163 | if ($array_acl[edit_computers]) |
---|
| 164 | return true; |
---|
| 165 | break; |
---|
| 166 | case delete_computers: |
---|
| 167 | if ($array_acl[delete_computers]) |
---|
| 168 | return true; |
---|
| 169 | break; |
---|
| 170 | |
---|
| 171 | case view_logs: |
---|
| 172 | if ($array_acl[view_logs]) |
---|
| 173 | return true; |
---|
| 174 | break; |
---|
| 175 | |
---|
| 176 | default: |
---|
| 177 | return false; |
---|
| 178 | } |
---|
| 179 | |
---|
| 180 | return false; |
---|
| 181 | } |
---|
| 182 | |
---|
| 183 | // Read acl from db |
---|
| 184 | function read_acl($account_lid) |
---|
| 185 | { |
---|
| 186 | $result = $this->db_functions->read_acl($account_lid); |
---|
| 187 | $context_array = ldap_explode_dn($result[0]['context'], 1); |
---|
| 188 | $result[0]['context_display'] = ldap_dn2ufn ( $result[0]['context'] ); |
---|
| 189 | return $result; |
---|
| 190 | } |
---|
| 191 | |
---|
| 192 | // Make a array read humam |
---|
| 193 | // Last acl: 33.554.432, 67.108.864 |
---|
| 194 | function make_array_acl($acl) |
---|
| 195 | { |
---|
| 196 | $array_acl['add_users'] = $acl & 1; |
---|
| 197 | $array_acl['edit_users'] = $acl & 2; |
---|
| 198 | $array_acl['delete_users'] = $acl & 4; |
---|
| 199 | $array_acl['rename_users'] = $acl & 8388608; |
---|
| 200 | $array_acl['view_users'] = $acl & 33554432; |
---|
| 201 | $array_acl['add_groups'] = $acl & 16; |
---|
| 202 | $array_acl['edit_groups'] = $acl & 32; |
---|
| 203 | $array_acl['delete_groups'] = $acl & 64; |
---|
| 204 | $array_acl['edit_email_groups'] = $acl & 67108864; |
---|
| 205 | $array_acl['change_users_password'] = $acl & 128; |
---|
| 206 | $array_acl['change_users_quote'] = $acl & 262144; |
---|
| 207 | $array_acl['set_user_default_password'] = $acl & 524288; |
---|
| 208 | $array_acl['edit_sambausers_attributes'] = $acl & 32768; |
---|
| 209 | $array_acl['edit_sambadomains'] = $acl & 16777216; |
---|
| 210 | $array_acl['add_maillists'] = $acl & 256; |
---|
| 211 | $array_acl['edit_maillists'] = $acl & 512; |
---|
| 212 | $array_acl['delete_maillists'] = $acl & 1024; |
---|
| 213 | $array_acl['adm_maillists'] = $acl & 2048; |
---|
| 214 | $array_acl['create_sectors'] = $acl & 4096; |
---|
| 215 | $array_acl['edit_sectors'] = $acl & 8192; |
---|
| 216 | $array_acl['delete_sectors'] = $acl & 16384; |
---|
| 217 | $array_acl['view_global_sessions'] = $acl & 65536; |
---|
| 218 | $array_acl['view_logs'] = $acl & 131072; |
---|
| 219 | $array_acl['create_computers'] = $acl & 1048576; |
---|
| 220 | $array_acl['edit_computers'] = $acl & 2097152; |
---|
| 221 | $array_acl['delete_computers'] = $acl & 4194304; |
---|
| 222 | return $array_acl; |
---|
| 223 | } |
---|
| 224 | |
---|
| 225 | function auto_list($type, $context, $admlista) |
---|
| 226 | { |
---|
| 227 | $common = new common(); |
---|
| 228 | $ldap_conn = $GLOBALS['phpgw']->common->ldapConnect(); |
---|
| 229 | |
---|
| 230 | if ($type == 'maillists') |
---|
| 231 | { |
---|
| 232 | |
---|
| 233 | //filtro de busca das listas de e-mail, busca apenas as listas permitidas ao usuario conectado; |
---|
| 234 | //$context = $GLOBALS['phpgw_info']['server']['ldap_context']; |
---|
| 235 | $filter="(&(phpgwAccountType=l)(admlista=$admlista)(|(cn=*)(uid=*)))"; |
---|
| 236 | $justthese = array("uidnumber", "cn", "uid", "mail"); |
---|
| 237 | $search=ldap_search($ldap_conn, $context, $filter, $justthese); |
---|
| 238 | ldap_sort($ldap_conn, $search, "uid"); |
---|
| 239 | $info = ldap_get_entries($ldap_conn, $search); |
---|
| 240 | ldap_close($ldap_conn); |
---|
| 241 | |
---|
| 242 | $i = 0; |
---|
| 243 | $tmp = array(); |
---|
| 244 | for ($i=0; $i < $info['count']; $i++) |
---|
| 245 | { |
---|
| 246 | $tmp[$i]['uid'] = $info[$i]['uid'][0]; |
---|
| 247 | $tmp[$i]['name'] = $info[$i]['cn'][0]; |
---|
| 248 | $tmp[$i]['uidnumber'] = $info[$i]['uidnumber'][0]; |
---|
| 249 | $tmp[$i]['email'] = $info[$i]['mail'][0]; |
---|
| 250 | } |
---|
| 251 | return $tmp; |
---|
| 252 | } |
---|
| 253 | } |
---|
| 254 | |
---|
| 255 | function get_list($type, $query, $context, $admlista) |
---|
| 256 | { |
---|
| 257 | $common = new common(); |
---|
| 258 | $ldap_conn = $GLOBALS['phpgw']->common->ldapConnect();//$common->ldapConnect(); |
---|
| 259 | if ($type == 'accounts') |
---|
| 260 | { |
---|
| 261 | $justthese = array("uidnumber", "uid", "cn", "mail", "objectclass"); |
---|
| 262 | //$filter="(&(phpgwAccountType=u)(|(uid=*".$query."*)(sn=*".$query."*)(cn=*".$query."*)(givenName=*".$query."*)(mail=$query*)(mailAlternateAddress=$query*)))"; |
---|
| 263 | //$filter="(&(objectclass=".$GLOBALS['phpgw_info']['server']['atributousuarios'].")(|(uid=*".$query."*)(sn=*".$query."*)(cn=*".$query."*)(givenName=*".$query."*)(mail=$query*)))"; |
---|
| 264 | $filter="(&(objectclass=".$GLOBALS['phpgw_info']['server']['atributousuarios'].")(|(uid=*".$query."*)(sn=*".$query."*)(cn=*".$query."*)(givenName=*".$query."*)(mail=$query*)))"; |
---|
| 265 | $search=ldap_search($ldap_conn, $context, $filter, $justthese); |
---|
| 266 | ldap_sort($ldap_conn, $search, "cn"); |
---|
| 267 | $info = ldap_get_entries($ldap_conn, $search); |
---|
| 268 | ldap_close($ldap_conn); |
---|
| 269 | |
---|
| 270 | $i = 0; |
---|
| 271 | $tmp = array(); |
---|
| 272 | $ldap_found=false; |
---|
| 273 | for ($i=0; $i < $info['count']; $i++) |
---|
| 274 | { |
---|
| 275 | $tmp[$i][account_id] = $info[$i]['uidnumber'][0]; |
---|
| 276 | $tmp[$i][account_lid] = $info[$i]['uid'][0]; |
---|
| 277 | $tmp[$i][account_cn] = $info[$i]['cn'][0]; |
---|
| 278 | $tmp[$i][account_mail] = $info[$i]['mail'][0]; |
---|
| 279 | $tmp[$i][account_expresso] = false; |
---|
| 280 | $tmp[$i][account_deleted] = false; |
---|
| 281 | $ldap_found=true; |
---|
| 282 | foreach ($info[$i]['objectclass'] as $objectclass) |
---|
| 283 | { |
---|
| 284 | if (strcasecmp($objectclass, 'phpgwaccount') == 0) |
---|
| 285 | { |
---|
| 286 | $tmp[$i][account_expresso] = true; |
---|
| 287 | } |
---|
| 288 | } |
---|
| 289 | //$tmp[$i][account_expresso] = true; |
---|
| 290 | } |
---|
| 291 | // fazendo a pesquisa tambem no banco de dados |
---|
| 292 | // eh cpf? |
---|
| 293 | if ((strlen($query) == 11)and(!$ldap_found)) |
---|
| 294 | { |
---|
| 295 | // inferindo o uidnumber |
---|
| 296 | $uidnumber=substr($query,0,strlen($query)-2); |
---|
| 297 | while (strpos($uidnumber,'0')===0) |
---|
| 298 | { |
---|
| 299 | $uidnumber=substr($uidnumber,1); |
---|
| 300 | } |
---|
| 301 | // consulta pelo uidnumber na tabela das acls |
---|
| 302 | $sql="SELECT DISTINCT acl_account FROM phpgw_acl WHERE acl_account='".$uidnumber."'"; |
---|
| 303 | $GLOBALS['phpgw']->db->query($sql); |
---|
| 304 | while($GLOBALS['phpgw']->db->next_record()) |
---|
| 305 | { |
---|
| 306 | $find=false; |
---|
| 307 | foreach ($tmp as $ldap) |
---|
| 308 | { |
---|
| 309 | if ($ldap[account_id] == $GLOBALS['phpgw']->db->f(0)) |
---|
| 310 | { |
---|
| 311 | $find=true; |
---|
| 312 | } |
---|
| 313 | } |
---|
| 314 | if (!$find) |
---|
| 315 | { |
---|
| 316 | $tmp[$i][account_id] = $GLOBALS['phpgw']->db->f(0); |
---|
| 317 | $tmp[$i][account_lid] = $query; |
---|
| 318 | $tmp[$i][account_cn] = "Nao encontrado no RHDS"; |
---|
| 319 | $tmp[$i][account_mail] = "Nao encontrado no RHDS"; |
---|
| 320 | $tmp[$i][account_expresso] = false; |
---|
| 321 | $tmp[$i][account_deleted] = true; |
---|
| 322 | ++$i; |
---|
| 323 | } |
---|
| 324 | } |
---|
| 325 | } |
---|
| 326 | |
---|
| 327 | return $tmp; |
---|
| 328 | } |
---|
| 329 | elseif($type == 'groups') |
---|
| 330 | { |
---|
| 331 | $filter="(&(phpgwAccountType=g)(cn=*".$query."*))"; |
---|
| 332 | $justthese = array("gidnumber", "cn", "description"); |
---|
| 333 | $search=ldap_search($ldap_conn, $context, $filter, $justthese); |
---|
| 334 | ldap_sort($ldap_conn, $search, "cn"); |
---|
| 335 | $info = ldap_get_entries($ldap_conn, $search); |
---|
| 336 | ldap_close($ldap_conn); |
---|
| 337 | |
---|
| 338 | $i = 0; |
---|
| 339 | $tmp = array(); |
---|
| 340 | for ($i=0; $i < $info['count']; $i++) |
---|
| 341 | { |
---|
| 342 | $tmp[$i][cn] = $info[$i][cn][0]; |
---|
| 343 | $tmp[$i][description] = $info[$i][description][0]; |
---|
| 344 | $tmp[$i][gidnumber] = $info[$i][gidnumber][0]; |
---|
| 345 | } |
---|
| 346 | return $tmp; |
---|
| 347 | } |
---|
| 348 | elseif($type == 'maillists') |
---|
| 349 | { |
---|
| 350 | |
---|
| 351 | // $filter="(&(phpgwAccountType=l)(|(cn=*".$query."*)(uid=*".$query."*)(mail=*".$query."*)))"; |
---|
| 352 | // $filter="(&(phpgwAccountType=l)(|(cn=*".$query."*)(uid=*".$query."*)(mail=*".$query."*)(admlista=$admlista)))"; |
---|
| 353 | |
---|
| 354 | //filtro de busca das listas de e-mail, busca apenas as listas permitidas ao usuario conectado; |
---|
| 355 | $context = $GLOBALS['phpgw_info']['server']['ldap_context']; |
---|
| 356 | $filter="(&(phpgwAccountType=l)(admlista=$admlista)(|(cn=*".$query."*)(uid=*".$query."*)))"; |
---|
| 357 | $justthese = array("uidnumber", "cn", "uid", "mail"); |
---|
| 358 | $search=ldap_search($ldap_conn, $context, $filter, $justthese); |
---|
| 359 | ldap_sort($ldap_conn, $search, "uid"); |
---|
| 360 | $info = ldap_get_entries($ldap_conn, $search); |
---|
| 361 | ldap_close($ldap_conn); |
---|
| 362 | |
---|
| 363 | $i = 0; |
---|
| 364 | $tmp = array(); |
---|
| 365 | for ($i=0; $i < $info['count']; $i++) |
---|
| 366 | { |
---|
| 367 | $tmp[$i]['uid'] = $info[$i]['uid'][0]; |
---|
| 368 | $tmp[$i]['name'] = $info[$i]['cn'][0]; |
---|
| 369 | $tmp[$i]['uidnumber'] = $info[$i]['uidnumber'][0]; |
---|
| 370 | $tmp[$i]['email'] = $info[$i]['mail'][0]; |
---|
| 371 | } |
---|
| 372 | return $tmp; |
---|
| 373 | } |
---|
| 374 | elseif($type == 'computers') |
---|
| 375 | { |
---|
| 376 | $filter="(&(objectClass=sambaSAMAccount)(|(sambaAcctFlags=[W ])(sambaAcctFlags=[DW ])(sambaAcctFlags=[I ])(sambaAcctFlags=[S ]))(cn=*".$query."*))"; |
---|
| 377 | $justthese = array("cn","uidNumber","description"); |
---|
| 378 | $search=ldap_search($ldap_conn, $context, $filter, $justthese); |
---|
| 379 | ldap_sort($ldap_conn, $search, "cn"); |
---|
| 380 | $info = ldap_get_entries($ldap_conn, $search); |
---|
| 381 | ldap_close($ldap_conn); |
---|
| 382 | $tmp = array(); |
---|
| 383 | for ($i=0; $i < $info['count']; $i++) |
---|
| 384 | { |
---|
| 385 | $tmp[$i]['cn'] = $info[$i]['cn'][0]; |
---|
| 386 | $tmp[$i]['uidNumber'] = $info[$i]['uidnumber'][0]; |
---|
| 387 | $tmp[$i]['description'] = utf8_decode($info[$i]['description'][0]); |
---|
| 388 | } |
---|
| 389 | return $tmp; |
---|
| 390 | } |
---|
| 391 | } |
---|
| 392 | |
---|
| 393 | //Criado nova funᅵᅵo bem mais eficiente! |
---|
| 394 | /* |
---|
| 395 | function get_organizations($context, $selected='') |
---|
| 396 | { |
---|
| 397 | //echo $selected; |
---|
| 398 | |
---|
| 399 | $first_sector_ufn = ldap_dn2ufn($context); |
---|
| 400 | $first_sector_string = split(",", $first_sector_ufn); |
---|
| 401 | |
---|
| 402 | $s = CreateObject('phpgwapi.sector_search_ldap'); |
---|
| 403 | $sectors_info = $s->sector_search($context); |
---|
| 404 | |
---|
| 405 | $sector_select = ""; |
---|
| 406 | $sector_select .= "<option value='" .$context . "'"; |
---|
| 407 | $sector_select .= ">".strtoupper($first_sector_string[0])."</option>\n"; |
---|
| 408 | |
---|
| 409 | foreach($sectors_info as $sector) |
---|
| 410 | { |
---|
| 411 | if ($sector->sector_level == 1) |
---|
| 412 | { |
---|
| 413 | $sector->sector_name = '+ '.$sector->sector_name; |
---|
| 414 | } |
---|
| 415 | else |
---|
| 416 | { |
---|
| 417 | $sector_space = ''; |
---|
| 418 | for ($i=1; $i < $sector->sector_level; $i++) |
---|
| 419 | $sector_space = '---'.$sector_space; |
---|
| 420 | $sector->sector_name = $sector_space.' '.$sector->sector_name; |
---|
| 421 | } |
---|
| 422 | $sector_select .= '<option value="' . strtolower($sector->sector_context) . '"'; |
---|
| 423 | |
---|
| 424 | if (trim(strtolower($sector->sector_context)) == $selected) |
---|
| 425 | $sector_select .= ' selected>' . $sector->sector_name . "</option>\n"; |
---|
| 426 | else |
---|
| 427 | $sector_select .= '>' . $sector->sector_name . "</option>\n"; |
---|
| 428 | } |
---|
| 429 | //$sector_select .= "</select>"; |
---|
| 430 | return $sector_select; |
---|
| 431 | } |
---|
| 432 | */ |
---|
| 433 | |
---|
| 434 | /* |
---|
| 435 | function get_organizations($context, $selected='', $show_invisible_ou=false) |
---|
| 436 | { |
---|
| 437 | $dn = $GLOBALS['phpgw_info']['server']['ldap_root_dn']; |
---|
| 438 | $passwd = $GLOBALS['phpgw_info']['server']['ldap_root_pw']; |
---|
| 439 | $ldap_conn = ldap_connect($GLOBALS['phpgw_info']['server']['ldap_host']); |
---|
| 440 | |
---|
| 441 | ldap_set_option($ldap_conn, LDAP_OPT_PROTOCOL_VERSION, 3); |
---|
| 442 | ldap_set_option($ldap_conn, LDAP_OPT_REFERRALS, 0); |
---|
| 443 | ldap_bind($ldap_conn,$dn,$passwd); |
---|
| 444 | |
---|
| 445 | $justthese = array("dn"); |
---|
| 446 | $filter = $show_invisible_ou ? "(ou=*)" : "(& (ou=*) (!(phpgwAccountVisible=-1)) )"; |
---|
| 447 | $search=ldap_search($ldap_conn, $context, $filter, $justthese); |
---|
| 448 | |
---|
| 449 | ldap_sort($ldap_conn, $search, "ou"); |
---|
| 450 | $info = ldap_get_entries($ldap_conn, $search); |
---|
| 451 | ldap_close($ldap_conn); |
---|
| 452 | |
---|
| 453 | // Retiro o count do array info e inverto o array para ordenaᅵᅵo. |
---|
| 454 | for ($i=0; $i<$info["count"]; $i++) |
---|
| 455 | { |
---|
| 456 | $dn = $info[$i]["dn"]; |
---|
| 457 | |
---|
| 458 | // Necessï¿œrio, pq em uma busca com ldapsearch ou=*, traz tb o prï¿œprio ou. |
---|
| 459 | if (strtolower($dn) == $context) |
---|
| 460 | continue; |
---|
| 461 | |
---|
| 462 | $array_dn = ldap_explode_dn ( $dn, 1 ); |
---|
| 463 | |
---|
| 464 | $array_dn_reverse = array_reverse ( $array_dn, true ); |
---|
| 465 | |
---|
| 466 | array_pop ( $array_dn_reverse ); |
---|
| 467 | |
---|
| 468 | $inverted_dn[$dn] = implode ( ".", $array_dn_reverse ); |
---|
| 469 | } |
---|
| 470 | |
---|
| 471 | // Ordenaᅵᅵo |
---|
| 472 | natcasesort($inverted_dn); |
---|
| 473 | |
---|
| 474 | // Construᅵᅵo do select |
---|
| 475 | $level = 0; |
---|
| 476 | foreach ($inverted_dn as $dn=>$invert_ufn) |
---|
| 477 | { |
---|
| 478 | $display = ''; |
---|
| 479 | |
---|
| 480 | $array_dn_reverse = explode ( ".", $invert_ufn ); |
---|
| 481 | $array_dn = array_reverse ( $array_dn_reverse, true ); |
---|
| 482 | |
---|
| 483 | $level = count( $array_dn ) - 4; |
---|
| 484 | |
---|
| 485 | if ($level == 0) |
---|
| 486 | $display .= '+'; |
---|
| 487 | else { |
---|
| 488 | for ($i=0; $i<$level; $i++) |
---|
| 489 | $display .= '---'; |
---|
| 490 | } |
---|
| 491 | |
---|
| 492 | reset ( $array_dn ); |
---|
| 493 | $display .= ' ' . (current ( $array_dn ) ); |
---|
| 494 | |
---|
| 495 | $dn = trim(strtolower($dn)); |
---|
| 496 | if ( $dn == $selected ) |
---|
| 497 | $select = ' selected'; |
---|
| 498 | else |
---|
| 499 | $select = ''; |
---|
| 500 | $options .= "<option value='$dn'$select>$display</option>"; |
---|
| 501 | } |
---|
| 502 | |
---|
| 503 | // Cria a primeira entrada na combo |
---|
| 504 | $first_sector_ufn = ldap_dn2ufn($context); |
---|
| 505 | $first_sector_string = split(",", $first_sector_ufn); |
---|
| 506 | $options = "<option value='$context'>" . strtoupper($first_sector_string[0]) . "</option>" . $options; |
---|
| 507 | |
---|
| 508 | return $options; |
---|
| 509 | } |
---|
| 510 | */ |
---|
| 511 | |
---|
| 512 | function get_organizations($context, $selected='', $referral=false, $show_invisible_ou=true) |
---|
| 513 | { |
---|
| 514 | $s = CreateObject('phpgwapi.sector_search_ldap'); |
---|
| 515 | $sectors_info = $s->get_organizations($context, $selected, $referral, $show_invisible_ou); |
---|
| 516 | return $sectors_info; |
---|
| 517 | } |
---|
| 518 | |
---|
| 519 | function get_sectors($selected='', $referral=false, $show_invisible_ou=true) |
---|
| 520 | { |
---|
| 521 | $s = CreateObject('phpgwapi.sector_search_ldap'); |
---|
| 522 | $sectors_info = $s->get_sectors($selected, $referral, $show_invisible_ou); |
---|
| 523 | return $sectors_info; |
---|
| 524 | } |
---|
| 525 | |
---|
| 526 | /* |
---|
| 527 | function get_sectors($context, $selected='') |
---|
| 528 | { |
---|
| 529 | $query = "SELECT sector FROM phpgw_expressoadmin_sectors WHERE organization = '" . $context . "'"; |
---|
| 530 | $GLOBALS['phpgw']->db->query($query); |
---|
| 531 | while($GLOBALS['phpgw']->db->next_record()) |
---|
| 532 | { |
---|
| 533 | $query_result[] = $GLOBALS['phpgw']->db->row(); |
---|
| 534 | } |
---|
| 535 | |
---|
| 536 | if (count($query_result) > 0) |
---|
| 537 | { |
---|
| 538 | foreach ($query_result as $index=>$tmp) |
---|
| 539 | { |
---|
| 540 | $sector = $tmp['sector']; |
---|
| 541 | if ($sector == $selected) |
---|
| 542 | $sector_options .= "<option value='$sector' selected>$sector</option>"; |
---|
| 543 | else |
---|
| 544 | $sector_options .= "<option value='$sector'>$sector</option>"; |
---|
| 545 | } |
---|
| 546 | return $sector_options; |
---|
| 547 | } |
---|
| 548 | else |
---|
| 549 | return false; |
---|
| 550 | } |
---|
| 551 | */ |
---|
| 552 | |
---|
| 553 | // Get list of all levels, this function is used for sectors module. |
---|
| 554 | /* |
---|
| 555 | function get_sectors_list($context) |
---|
| 556 | { |
---|
| 557 | $connection = $GLOBALS['phpgw']->common->ldapConnect(); |
---|
| 558 | ldap_set_option($connection, LDAP_OPT_PROTOCOL_VERSION, 3); |
---|
| 559 | ldap_set_option($connection, LDAP_OPT_REFERRALS, 0); |
---|
| 560 | |
---|
| 561 | if ($connection) |
---|
| 562 | { |
---|
| 563 | $bind=ldap_bind($connection); |
---|
| 564 | $filter="ou=*"; |
---|
| 565 | $justthese = array("ou"); |
---|
| 566 | $search=ldap_list($connection, $context, $filter, $justthese); |
---|
| 567 | ldap_sort($connection, $search, "ou"); |
---|
| 568 | $info = ldap_get_entries($connection, $search); |
---|
| 569 | for ($i=0; $i<$info["count"]; $i++) |
---|
| 570 | { |
---|
| 571 | $this->level++; |
---|
| 572 | $next_context[$i] = 'ou='.$info[$i]["ou"][0].','.$context; |
---|
| 573 | $obj = new sectors_object($info[$i]["ou"][0], $next_context[$i], $this->level, 'False'); |
---|
| 574 | array_push($this->sectors_list, $obj); |
---|
| 575 | $this->get_sectors_list($next_context[$i]); |
---|
| 576 | } |
---|
| 577 | } |
---|
| 578 | ldap_close($connection); |
---|
| 579 | $this->level--; |
---|
| 580 | return $this->sectors_list; |
---|
| 581 | } |
---|
| 582 | */ |
---|
| 583 | |
---|
| 584 | // Get list of all levels, this function is used for sectors module. |
---|
| 585 | function get_sectors_list($context, $selected='', $referral=false ,$show_invisible_ou=false) |
---|
| 586 | { |
---|
| 587 | $dn = $GLOBALS['phpgw_info']['server']['ldap_root_dn']; |
---|
| 588 | $passwd = $GLOBALS['phpgw_info']['server']['ldap_root_pw']; |
---|
| 589 | $ldap_conn = ldap_connect($GLOBALS['phpgw_info']['server']['ldap_host']); |
---|
| 590 | |
---|
| 591 | ldap_set_option($ldap_conn, LDAP_OPT_PROTOCOL_VERSION, 3); |
---|
| 592 | |
---|
| 593 | if ($referral) |
---|
| 594 | ldap_set_option($ldap_conn, LDAP_OPT_REFERRALS, 1); |
---|
| 595 | else |
---|
| 596 | ldap_set_option($ldap_conn, LDAP_OPT_REFERRALS, 0); |
---|
| 597 | |
---|
| 598 | ldap_bind($ldap_conn,$dn,$passwd); |
---|
| 599 | |
---|
| 600 | $justthese = array("dn"); |
---|
| 601 | $filter = "(ou=*)"; |
---|
| 602 | $search=ldap_search($ldap_conn, $context, $filter, $justthese); |
---|
| 603 | |
---|
| 604 | ldap_sort($ldap_conn, $search, "ou"); |
---|
| 605 | $info = ldap_get_entries($ldap_conn, $search); |
---|
| 606 | ldap_close($ldap_conn); |
---|
| 607 | |
---|
| 608 | // Retiro o count do array info e inverto o array para ordenaᅵᅵo. |
---|
| 609 | for ($i=0; $i<$info["count"]; $i++) |
---|
| 610 | { |
---|
| 611 | $dn = $info[$i]["dn"]; |
---|
| 612 | |
---|
| 613 | // Necessï¿œrio, pq em uma busca com ldapsearch ou=*, traz tb o prï¿œprio ou. |
---|
| 614 | if (strtolower($dn) == $context) |
---|
| 615 | continue; |
---|
| 616 | |
---|
| 617 | $array_dn = ldap_explode_dn ( $dn, 1 ); |
---|
| 618 | |
---|
| 619 | $array_dn_reverse = array_reverse ( $array_dn, true ); |
---|
| 620 | |
---|
| 621 | // Retirar o indice count do array. |
---|
| 622 | array_pop ( $array_dn_reverse ); |
---|
| 623 | |
---|
| 624 | $inverted_dn[$dn] = implode ( "#", $array_dn_reverse ); |
---|
| 625 | } |
---|
| 626 | |
---|
| 627 | // Ordenaᅵᅵo |
---|
| 628 | natcasesort($inverted_dn); |
---|
| 629 | |
---|
| 630 | // Construᅵᅵo do select |
---|
| 631 | $level = 0; |
---|
| 632 | $options = array(); |
---|
| 633 | foreach ($inverted_dn as $dn=>$invert_ufn) |
---|
| 634 | { |
---|
| 635 | $display = ''; |
---|
| 636 | |
---|
| 637 | $array_dn_reverse = explode ( "#", $invert_ufn ); |
---|
| 638 | $array_dn = array_reverse ( $array_dn_reverse, true ); |
---|
| 639 | |
---|
| 640 | $level = count( $array_dn ) - (int)(count(explode(",", $GLOBALS['phpgw_info']['server']['ldap_context'])) + 1); |
---|
| 641 | |
---|
| 642 | if ($level == 0) |
---|
| 643 | $display .= '+'; |
---|
| 644 | else |
---|
| 645 | { |
---|
| 646 | for ($i=0; $i<$level; $i++) |
---|
| 647 | $display .= '---'; |
---|
| 648 | } |
---|
| 649 | |
---|
| 650 | reset ( $array_dn ); |
---|
| 651 | $display .= ' ' . (current ( $array_dn ) ); |
---|
| 652 | |
---|
| 653 | $dn = trim(strtolower($dn)); |
---|
| 654 | $options[$dn] = $display; |
---|
| 655 | } |
---|
| 656 | return $options; |
---|
| 657 | } |
---|
| 658 | |
---|
| 659 | function exist_account_lid($account_lid) |
---|
| 660 | { |
---|
| 661 | $conection = $GLOBALS['phpgw']->common->ldapConnect(); |
---|
| 662 | $sri = ldap_search($conection, $GLOBALS['phpgw_info']['server']['ldap_context'], "uid=" . $account_lid); |
---|
| 663 | $result = ldap_get_entries($conection, $sri); |
---|
| 664 | return $result['count']; |
---|
| 665 | } |
---|
| 666 | |
---|
| 667 | function exist_email($mail) |
---|
| 668 | { |
---|
| 669 | $conection = $GLOBALS['phpgw']->common->ldapConnect(); |
---|
| 670 | $sri = ldap_search($conection, $GLOBALS['phpgw_info']['server']['ldap_context'], "mail=" . $mail); |
---|
| 671 | $result = ldap_get_entries($conection, $sri); |
---|
| 672 | ldap_close($conection); |
---|
| 673 | |
---|
| 674 | if ($result['count'] == 0) |
---|
| 675 | return false; |
---|
| 676 | else |
---|
| 677 | return true; |
---|
| 678 | } |
---|
| 679 | |
---|
| 680 | function array_invert($array) |
---|
| 681 | { |
---|
| 682 | $result[] = end($array); |
---|
| 683 | while ($item = prev($array)) |
---|
| 684 | $result[] = $item; |
---|
| 685 | return $result; |
---|
| 686 | } |
---|
| 687 | |
---|
| 688 | function get_next_id() |
---|
| 689 | { |
---|
| 690 | // Busco o ID dos accounts |
---|
| 691 | $query_accounts = "SELECT id FROM phpgw_nextid WHERE appname = 'accounts'"; |
---|
| 692 | $GLOBALS['phpgw']->db->query($query_accounts); |
---|
| 693 | while($GLOBALS['phpgw']->db->next_record()) |
---|
| 694 | { |
---|
| 695 | $result_accounts[] = $GLOBALS['phpgw']->db->row(); |
---|
| 696 | } |
---|
| 697 | $accounts_id = $result_accounts[0]['id']; |
---|
| 698 | |
---|
| 699 | // Busco o ID dos groups |
---|
| 700 | $query_groups = "SELECT id FROM phpgw_nextid WHERE appname = 'groups'"; |
---|
| 701 | $GLOBALS['phpgw']->db->query($query_groups); |
---|
| 702 | while($GLOBALS['phpgw']->db->next_record()) |
---|
| 703 | { |
---|
| 704 | $result_groups[] = $GLOBALS['phpgw']->db->row(); |
---|
| 705 | } |
---|
| 706 | $groups_id = $result_groups[0]['id']; |
---|
| 707 | |
---|
| 708 | //Retorna o maior dos ID's |
---|
| 709 | if ($accounts_id >= $groups_id) |
---|
| 710 | return $accounts_id; |
---|
| 711 | else |
---|
| 712 | return $groups_id; |
---|
| 713 | } |
---|
| 714 | |
---|
| 715 | function increment_id($id, $type) |
---|
| 716 | { |
---|
| 717 | $sql = "UPDATE phpgw_nextid set id = '".$id."' WHERE appname = '" . $type . "'"; |
---|
| 718 | $GLOBALS['phpgw']->db->query($sql); |
---|
| 719 | } |
---|
| 720 | |
---|
| 721 | function make_list_app($account_lid, $context, $user_applications, $disabled='') |
---|
| 722 | { |
---|
| 723 | // create list of ALL available apps |
---|
| 724 | $availableAppsGLOBALS = $GLOBALS['phpgw_info']['apps']; |
---|
| 725 | |
---|
| 726 | // create list of available apps for the user |
---|
| 727 | $query = "SELECT * FROM phpgw_expressoadmin_apps WHERE manager_lid = '".$account_lid."' AND context = '".$context."'"; |
---|
| 728 | $GLOBALS['phpgw']->db->query($query); |
---|
| 729 | while($GLOBALS['phpgw']->db->next_record()) |
---|
| 730 | { |
---|
| 731 | $availableApps[] = $GLOBALS['phpgw']->db->row(); |
---|
| 732 | } |
---|
| 733 | |
---|
| 734 | // Retira alguns modulos |
---|
| 735 | if (count($availableApps)) |
---|
| 736 | { |
---|
| 737 | foreach ($availableApps as $key => $value) |
---|
| 738 | { |
---|
| 739 | if ($value['app'] != 'phpgwapi') |
---|
| 740 | $tmp[] = $availableApps[$key]; |
---|
| 741 | } |
---|
| 742 | } |
---|
| 743 | $availableApps = $tmp; |
---|
| 744 | |
---|
| 745 | // Cria um array com as aplicacoes disponiveis para o manager, com as atributos das aplicacoes. |
---|
| 746 | $availableAppsUser = array(); |
---|
| 747 | if (count($availableApps)) |
---|
| 748 | { |
---|
| 749 | foreach($availableApps as $app => $title) |
---|
| 750 | { |
---|
| 751 | if ($availableAppsGLOBALS[$title['app']]) |
---|
| 752 | $availableAppsUser[$title['app']] = $availableAppsGLOBALS[$title['app']]; |
---|
| 753 | } |
---|
| 754 | } |
---|
| 755 | |
---|
| 756 | // Loop para criar dinamicamente uma tabela com 3 colunas, cada coluna com um aplicativo e um check box. |
---|
| 757 | $applications_list = ''; |
---|
| 758 | $app_col1 = ''; |
---|
| 759 | $app_col2 = ''; |
---|
| 760 | $app_col3 = ''; |
---|
| 761 | $total_apps = count($availableAppsUser); |
---|
| 762 | $i = 0; |
---|
| 763 | foreach($availableAppsUser as $app => $data) |
---|
| 764 | { |
---|
| 765 | // 1 coluna |
---|
| 766 | if (($i +1) % 3 == 1) |
---|
| 767 | { |
---|
| 768 | $checked = $user_applications[$app] ? 'CHECKED' : ''; |
---|
| 769 | $app_col1 = sprintf("<td>%s</td><td width='10'><input type='checkbox' name='apps[%s]' value='1' %s %s></td>\n", |
---|
| 770 | $data['title'],$app,$checked, $disabled); |
---|
| 771 | if ($i == ($total_apps-1)) |
---|
| 772 | $applications_list .= sprintf('<tr bgcolor="%s">%s</tr>','#DDDDDD', $app_col1); |
---|
| 773 | } |
---|
| 774 | |
---|
| 775 | // 2 coluna |
---|
| 776 | if (($i +1) % 3 == 2) |
---|
| 777 | { |
---|
| 778 | $checked = $user_applications[$app] ? 'CHECKED' : ''; |
---|
| 779 | $app_col2 = sprintf("<td>%s</td><td width='10'><input type='checkbox' name='apps[%s]' value='1' %s %s></td>\n", |
---|
| 780 | $data['title'],$app,$checked, $disabled); |
---|
| 781 | |
---|
| 782 | if ($i == ($total_apps-1)) |
---|
| 783 | $applications_list .= sprintf('<tr bgcolor="%s">%s%s</tr>','#DDDDDD', $app_col1,$app_col2); |
---|
| 784 | } |
---|
| 785 | // 3 coluna |
---|
| 786 | if (($i +1) % 3 == 0) |
---|
| 787 | { |
---|
| 788 | $checked = $user_applications[$app] ? 'CHECKED' : ''; |
---|
| 789 | $app_col3 = sprintf("<td>%s</td><td width='10'><input type='checkbox' name='apps[%s]' value='1' %s %s></td>\n", |
---|
| 790 | $data['title'],$app,$checked, $disabled); |
---|
| 791 | |
---|
| 792 | // Cria nova linha |
---|
| 793 | $applications_list .= sprintf('<tr bgcolor="%s">%s%s%s</tr>','#DDDDDD', $app_col1, $app_col2, $app_col3); |
---|
| 794 | } |
---|
| 795 | $i++; |
---|
| 796 | } |
---|
| 797 | return $applications_list; |
---|
| 798 | } |
---|
| 799 | |
---|
| 800 | function exist_attribute_in_ldap($dn, $attribute, $value) |
---|
| 801 | { |
---|
| 802 | $connection = $GLOBALS['phpgw']->common->ldapConnect(); |
---|
| 803 | $search = ldap_search($connection, $dn, $attribute. "=" . $value); |
---|
| 804 | $result = ldap_get_entries($connection, $search); |
---|
| 805 | ldap_close($connection); |
---|
| 806 | //_debug_array($result); |
---|
| 807 | if ($result['count'] == 0) |
---|
| 808 | return false; |
---|
| 809 | else |
---|
| 810 | return true; |
---|
| 811 | } |
---|
| 812 | |
---|
| 813 | function getReturnExecuteForm(){ |
---|
| 814 | $response = $_SESSION['response']; |
---|
| 815 | $_SESSION['response'] = null; |
---|
| 816 | return $response; |
---|
| 817 | } |
---|
| 818 | |
---|
| 819 | function write_log2($action, $groupinfo='', $userinfo='', $appinfo='', $msg_log='') |
---|
| 820 | { |
---|
| 821 | $sql = "INSERT INTO phpgw_expressoadmin_log (date, manager, action, groupinfo, userinfo, appinfo, msg) " |
---|
| 822 | . "VALUES('now','" . $_SESSION['phpgw_info']['expresso']['user']['account_lid'] . "','" . strtolower($action) . "','" . strtolower($groupinfo) . "','" . strtolower($userinfo) . "','" . strtolower($appinfo) . "','" .strtolower($msg_log) . "')"; |
---|
| 823 | $GLOBALS['phpgw']->db->query($sql); |
---|
| 824 | return; |
---|
| 825 | } |
---|
| 826 | |
---|
| 827 | } |
---|
| 828 | |
---|
| 829 | class sectors_object |
---|
| 830 | { |
---|
| 831 | var $sector_name; |
---|
| 832 | var $sector_context; |
---|
| 833 | var $sector_level; |
---|
| 834 | var $sector_leaf; |
---|
| 835 | var $sectors_list = array(); |
---|
| 836 | var $level; |
---|
| 837 | |
---|
| 838 | function sectors_object($sector_name, $sector_context, $sector_level, $sector_leaf) |
---|
| 839 | { |
---|
| 840 | $this->sector_name = $sector_name; |
---|
| 841 | $this->sector_context = $sector_context; |
---|
| 842 | $this->sector_level = $sector_level; |
---|
| 843 | $this->sector_leaf = $sector_leaf; |
---|
| 844 | } |
---|
| 845 | } |
---|