[2] | 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'); |
---|
[64] | 13 | include_once(PHPGW_API_INC.'/class.config.inc.php'); |
---|
[2] | 14 | |
---|
| 15 | class functions |
---|
| 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(); |
---|
[64] | 29 | var $current_config; |
---|
[2] | 30 | |
---|
| 31 | function functions() |
---|
| 32 | { |
---|
| 33 | $this->db_functions = new db_functions; |
---|
[64] | 34 | $GLOBALS['phpgw']->db = $this->db_functions->db; |
---|
| 35 | |
---|
| 36 | //$c = CreateObject('phpgwapi.config','expressoAdmin1_2'); |
---|
| 37 | $c = new config; |
---|
| 38 | $c->read_repository(); |
---|
| 39 | $this->current_config = $c->config_data; |
---|
[2] | 40 | } |
---|
| 41 | |
---|
| 42 | // Account and type of access. Return: Have access ? (true/false) |
---|
| 43 | function check_acl($account_lid, $access) |
---|
| 44 | { |
---|
| 45 | $acl = $this->read_acl($account_lid); |
---|
[64] | 46 | $array_acl = $this->make_array_acl($acl['acl']); |
---|
[2] | 47 | |
---|
[107] | 48 | switch($access) |
---|
| 49 | { |
---|
| 50 | case list_users: |
---|
[317] | 51 | if ($array_acl[acl_add_users] || $array_acl[acl_edit_users] || $array_acl[acl_delete_users] || $array_acl[acl_change_users_password] || $array_acl[acl_change_users_quote] || $array_acl[acl_edit_sambausers_attributes] || $array_acl[acl_view_users] || $array_acl[acl_manipulate_corporative_information] || $array_acl[acl_edit_users_phonenumber] ) |
---|
[107] | 52 | return true; |
---|
| 53 | break; |
---|
| 54 | case list_groups: |
---|
| 55 | if ($array_acl[acl_add_groups] || $array_acl[acl_edit_groups] || $array_acl[acl_delete_groups]) |
---|
| 56 | return true; |
---|
| 57 | break; |
---|
| 58 | case list_maillists: |
---|
| 59 | if ($array_acl[acl_add_maillists] || $array_acl[acl_edit_maillists] || $array_acl[acl_delete_maillists]) |
---|
| 60 | return true; |
---|
| 61 | break; |
---|
| 62 | case list_sectors: |
---|
| 63 | if ($array_acl[acl_create_sectors] || $array_acl[acl_edit_sectors] || $array_acl[acl_delete_sectors]) |
---|
| 64 | return true; |
---|
| 65 | break; |
---|
| 66 | case list_computers: |
---|
| 67 | if ($array_acl[acl_create_computers] || $array_acl[acl_edit_computers] || $array_acl[acl_delete_computers]) |
---|
| 68 | return true; |
---|
| 69 | break; |
---|
| 70 | |
---|
| 71 | case display_groups: |
---|
| 72 | if ( $array_acl[acl_edit_users] || $array_acl[acl_view_users] || ($array_acl[acl_edit_sambausers_attributes] && ($this->current_config['expressoAdmin_samba_support'] == 'true')) ) |
---|
| 73 | return true; |
---|
| 74 | break; |
---|
| 75 | case display_emailconfig: |
---|
| 76 | if ($array_acl[acl_edit_users] || $array_acl[acl_view_users]) |
---|
| 77 | return true; |
---|
| 78 | break; |
---|
| 79 | case display_applications: |
---|
| 80 | if ($array_acl[acl_edit_users] || $array_acl[acl_view_users]) |
---|
| 81 | return true; |
---|
| 82 | break; |
---|
| 83 | case display_emaillists: |
---|
| 84 | if ($array_acl[acl_edit_users] || $array_acl[acl_view_users]) |
---|
| 85 | return true; |
---|
| 86 | break; |
---|
| 87 | |
---|
[317] | 88 | case list_institutional_accounts: |
---|
| 89 | if ($array_acl[acl_add_institutional_accounts] || $array_acl[acl_edit_institutional_accounts] || $array_acl[acl_delete_institutional_accounts]) |
---|
| 90 | return true; |
---|
[1913] | 91 | break; |
---|
| 92 | case list_shared_accounts: |
---|
| 93 | if ($array_acl[acl_add_shared_accounts] || $array_acl[acl_edit_shared_accounts] || $array_acl[acl_delete_shared_accounts]) |
---|
| 94 | return true; |
---|
[317] | 95 | break; |
---|
| 96 | |
---|
| 97 | |
---|
[107] | 98 | default: |
---|
| 99 | return $array_acl["acl_$access"]; |
---|
| 100 | } |
---|
| 101 | return false; |
---|
| 102 | } |
---|
| 103 | |
---|
| 104 | /* OLD FUNCTION |
---|
| 105 | function check_acl($account_lid, $access) |
---|
| 106 | { |
---|
| 107 | $acl = $this->read_acl($account_lid); |
---|
| 108 | $array_acl = $this->make_array_acl($acl['acl']); |
---|
| 109 | |
---|
[2] | 110 | //What access ?? In the IF, verify if have access. |
---|
| 111 | switch($access) |
---|
| 112 | { |
---|
| 113 | case list_users: |
---|
[64] | 114 | if ($array_acl[acl_add_users] || $array_acl[acl_edit_users] || $array_acl[acl_delete_users] || $array_acl[acl_change_users_password] || $array_acl[acl_change_users_quote] || $array_acl[acl_edit_sambausers_attributes] || $array_acl[acl_view_users] || $array_acl[acl_manipulate_corporative_information]) |
---|
[2] | 115 | return true; |
---|
| 116 | break; |
---|
| 117 | case add_users: |
---|
[64] | 118 | if ($array_acl[acl_add_users]) |
---|
[2] | 119 | return true; |
---|
| 120 | break; |
---|
| 121 | case edit_users: |
---|
[64] | 122 | if ($array_acl[acl_edit_users]) |
---|
[2] | 123 | return true; |
---|
| 124 | break; |
---|
| 125 | case delete_users: |
---|
[64] | 126 | if ($array_acl[acl_delete_users]) |
---|
[2] | 127 | return true; |
---|
| 128 | break; |
---|
| 129 | case rename_users: |
---|
[64] | 130 | if ($array_acl[acl_rename_users]) |
---|
[2] | 131 | return true; |
---|
| 132 | break; |
---|
[32] | 133 | case view_users: |
---|
[64] | 134 | if ($array_acl[acl_view_users]) |
---|
[32] | 135 | return true; |
---|
| 136 | break; |
---|
[107] | 137 | case edit_users_picture: |
---|
| 138 | if ($array_acl[acl_edit_users_picture]) |
---|
| 139 | return true; |
---|
| 140 | break; |
---|
[63] | 141 | case manipulate_corporative_information: |
---|
[64] | 142 | if ($array_acl[acl_manipulate_corporative_information]) |
---|
[63] | 143 | return true; |
---|
| 144 | break; |
---|
[2] | 145 | case change_users_password: |
---|
[64] | 146 | if ($array_acl[acl_change_users_password]) |
---|
[2] | 147 | return true; |
---|
| 148 | break; |
---|
| 149 | case change_users_quote: |
---|
[64] | 150 | if ($array_acl[acl_change_users_quote]) |
---|
[2] | 151 | return true; |
---|
| 152 | break; |
---|
| 153 | case set_user_default_password: |
---|
[64] | 154 | if ($array_acl[acl_set_user_default_password]) |
---|
[2] | 155 | return true; |
---|
| 156 | break; |
---|
[63] | 157 | case empty_user_inbox: |
---|
[64] | 158 | if (($array_acl[acl_empty_user_inbox]) && ($array_acl[acl_edit_users])) |
---|
[63] | 159 | return true; |
---|
| 160 | break; |
---|
[107] | 161 | case edit_sambausers_attributes: case list_maillists: |
---|
| 162 | if ($array_acl[acl_add_maillists] || $array_acl[acl_edit_maillists] || $array_acl[acl_delete_maillists]) |
---|
| 163 | return true; |
---|
| 164 | break; |
---|
| 165 | |
---|
[64] | 166 | if ($array_acl[acl_edit_sambausers_attributes]) |
---|
[2] | 167 | return true; |
---|
| 168 | break; |
---|
[27] | 169 | case edit_sambadomains: |
---|
[64] | 170 | if ($array_acl[acl_edit_sambadomains]) |
---|
[27] | 171 | return true; |
---|
| 172 | break; |
---|
[2] | 173 | |
---|
| 174 | case list_groups: |
---|
[64] | 175 | if ($array_acl[acl_add_groups] || $array_acl[acl_edit_groups] || $array_acl[acl_delete_groups]) |
---|
[2] | 176 | return true; |
---|
| 177 | break; |
---|
| 178 | case add_groups: |
---|
[64] | 179 | if ($array_acl[acl_add_groups]) |
---|
[2] | 180 | return true; |
---|
| 181 | break; |
---|
| 182 | case edit_groups: |
---|
[64] | 183 | if ($array_acl[acl_edit_groups]) |
---|
[2] | 184 | return true; |
---|
| 185 | break; |
---|
| 186 | case delete_groups: |
---|
[64] | 187 | if ($array_acl[acl_delete_groups]) |
---|
[2] | 188 | return true; |
---|
| 189 | break; |
---|
[46] | 190 | case edit_email_groups: |
---|
[64] | 191 | if ($array_acl[acl_edit_email_groups]) |
---|
[46] | 192 | return true; |
---|
| 193 | break; |
---|
[2] | 194 | |
---|
| 195 | case list_maillists: |
---|
[64] | 196 | if ($array_acl[acl_add_maillists] || $array_acl[acl_edit_maillists] || $array_acl[acl_delete_maillists]) |
---|
[2] | 197 | return true; |
---|
| 198 | break; |
---|
| 199 | case add_maillists: |
---|
[64] | 200 | if ($array_acl[acl_add_maillists]) |
---|
[2] | 201 | return true; |
---|
| 202 | break; |
---|
| 203 | case edit_maillists: |
---|
[64] | 204 | if ($array_acl[acl_edit_maillists]) |
---|
[2] | 205 | return true; |
---|
| 206 | break; |
---|
| 207 | case delete_maillists: |
---|
[64] | 208 | if ($array_acl[acl_delete_maillists]) |
---|
[2] | 209 | return true; |
---|
| 210 | break; |
---|
| 211 | |
---|
| 212 | case list_sectors: |
---|
[64] | 213 | if ($array_acl[acl_create_sectors] || $array_acl[acl_edit_sectors] || $array_acl[acl_delete_sectors]) |
---|
[2] | 214 | return true; |
---|
| 215 | break; |
---|
| 216 | case create_sectors: |
---|
[64] | 217 | if ($array_acl[acl_create_sectors]) |
---|
[2] | 218 | return true; |
---|
| 219 | break; |
---|
| 220 | case edit_sectors: |
---|
[64] | 221 | if ($array_acl[acl_edit_sectors]) |
---|
[2] | 222 | return true; |
---|
| 223 | break; |
---|
| 224 | case delete_sectors: |
---|
[64] | 225 | if ($array_acl[acl_delete_sectors]) |
---|
[2] | 226 | return true; |
---|
| 227 | break; |
---|
| 228 | |
---|
| 229 | case view_global_sessions: |
---|
[64] | 230 | if ($array_acl[acl_view_global_sessions]) |
---|
[2] | 231 | return true; |
---|
| 232 | break; |
---|
| 233 | |
---|
| 234 | case list_computers: |
---|
[64] | 235 | if ($array_acl[acl_create_computers] || $array_acl[acl_edit_computers] || $array_acl[acl_delete_computers]) |
---|
[2] | 236 | return true; |
---|
| 237 | break; |
---|
| 238 | case create_computers: |
---|
[64] | 239 | if ($array_acl[acl_create_computers]) |
---|
[2] | 240 | return true; |
---|
| 241 | break; |
---|
| 242 | case edit_computers: |
---|
[64] | 243 | if ($array_acl[acl_edit_computers]) |
---|
[2] | 244 | return true; |
---|
| 245 | break; |
---|
| 246 | case delete_computers: |
---|
[64] | 247 | if ($array_acl[acl_delete_computers]) |
---|
[2] | 248 | return true; |
---|
| 249 | break; |
---|
| 250 | |
---|
| 251 | case view_logs: |
---|
[64] | 252 | if ($array_acl[acl_view_logs]) |
---|
[2] | 253 | return true; |
---|
| 254 | break; |
---|
[64] | 255 | |
---|
| 256 | case display_groups: |
---|
| 257 | if ( $array_acl[acl_edit_users] || $array_acl[acl_view_users] || ($array_acl[acl_edit_sambausers_attributes] && ($this->current_config['expressoAdmin_samba_support'] == 'true')) ) |
---|
| 258 | return true; |
---|
| 259 | break; |
---|
| 260 | case display_emailconfig: |
---|
| 261 | if ($array_acl[acl_edit_users] || $array_acl[acl_view_users]) |
---|
| 262 | return true; |
---|
| 263 | break; |
---|
| 264 | case display_applications: |
---|
| 265 | if ($array_acl[acl_edit_users] || $array_acl[acl_view_users]) |
---|
| 266 | return true; |
---|
| 267 | break; |
---|
| 268 | case display_emaillists: |
---|
| 269 | if ($array_acl[acl_edit_users] || $array_acl[acl_view_users]) |
---|
| 270 | return true; |
---|
| 271 | break; |
---|
[2] | 272 | |
---|
| 273 | default: |
---|
[107] | 274 | return $array_acl["acl_$access"]; |
---|
[2] | 275 | } |
---|
| 276 | return false; |
---|
| 277 | } |
---|
[107] | 278 | */ |
---|
[2] | 279 | |
---|
| 280 | // Read acl from db |
---|
| 281 | function read_acl($account_lid) |
---|
| 282 | { |
---|
[64] | 283 | $acl = $this->db_functions->read_acl($account_lid); |
---|
| 284 | |
---|
| 285 | $result['acl'] = $acl[0]['acl']; |
---|
| 286 | $result['manager_lid'] = $acl[0]['manager_lid']; |
---|
| 287 | $result['raw_context'] = $acl[0]['context']; |
---|
| 288 | |
---|
| 289 | $all_contexts = split("%", $acl[0]['context']); |
---|
| 290 | foreach ($all_contexts as $index=>$context) |
---|
| 291 | { |
---|
| 292 | $result['contexts'][] = $context; |
---|
| 293 | $result['contexts_display'][] = str_replace(", ", ".", ldap_dn2ufn( $context )); |
---|
| 294 | } |
---|
| 295 | |
---|
[2] | 296 | return $result; |
---|
| 297 | } |
---|
| 298 | |
---|
| 299 | // Make a array read humam |
---|
[317] | 300 | // Last acl: 2.147.483.648 -> edit users phonephone |
---|
| 301 | // Last acl: 4.294.967.296 -> add institutional accounts |
---|
| 302 | // Last acl: 8.589.934.592 -> edit institutional accounts |
---|
| 303 | // Last acl: 17.179.869.184 -> remove institutional accounts |
---|
[1913] | 304 | // Last acl: 34.359.738.368 -> add share accounts |
---|
| 305 | // Last acl: 68.719.476.736 -> edit share accounts |
---|
| 306 | // Last acl: 137.438.953.472 -> delete share accounts |
---|
| 307 | // Last acl: 274.877.906.944 -> edit share accounts acl |
---|
| 308 | // Last acl: 549.755.813.888 -> edit quota share quote |
---|
| 309 | // Last acl: 1.099.511.627.776 -> empty share accounts inbox |
---|
| 310 | |
---|
[2] | 311 | function make_array_acl($acl) |
---|
| 312 | { |
---|
[107] | 313 | $array_acl_tmp = array(); |
---|
| 314 | $tmp = array( "acl_add_users", |
---|
| 315 | "acl_edit_users", |
---|
| 316 | "acl_delete_users", |
---|
| 317 | "acl_EMPTY1", |
---|
| 318 | "acl_add_groups", |
---|
| 319 | "acl_edit_groups", |
---|
| 320 | "acl_delete_groups", |
---|
| 321 | "acl_change_users_password", |
---|
| 322 | "acl_add_maillists", |
---|
| 323 | "acl_edit_maillists", |
---|
| 324 | "acl_delete_maillists", |
---|
| 325 | "acl_EMPTY2", |
---|
| 326 | "acl_create_sectors", |
---|
| 327 | "acl_edit_sectors", |
---|
| 328 | "acl_delete_sectors", |
---|
| 329 | "acl_edit_sambausers_attributes", |
---|
| 330 | "acl_view_global_sessions", |
---|
| 331 | "acl_view_logs", |
---|
| 332 | "acl_change_users_quote", |
---|
| 333 | "acl_set_user_default_password", |
---|
| 334 | "acl_create_computers", |
---|
| 335 | "acl_edit_computers", |
---|
| 336 | "acl_delete_computers", |
---|
| 337 | "acl_rename_users", |
---|
| 338 | "acl_edit_sambadomains", |
---|
| 339 | "acl_view_users", |
---|
| 340 | "acl_edit_email_groups", |
---|
| 341 | "acl_empty_user_inbox", |
---|
| 342 | "acl_manipulate_corporative_information", |
---|
[283] | 343 | "acl_edit_users_picture", |
---|
[317] | 344 | "acl_edit_scl_email_lists", |
---|
| 345 | "acl_edit_users_phonenumber", |
---|
| 346 | "acl_add_institutional_accounts", |
---|
| 347 | "acl_edit_institutional_accounts", |
---|
[1913] | 348 | "acl_remove_institutional_accounts", |
---|
| 349 | "acl_add_shared_accounts", |
---|
| 350 | "acl_edit_shared_accounts", |
---|
| 351 | "acl_delete_shared_accounts", |
---|
| 352 | "acl_edit_shared_accounts_acl", |
---|
| 353 | "acl_edit_shared_accounts_quote", |
---|
| 354 | "acl_empty_shared_accounts_inbox" |
---|
[107] | 355 | ); |
---|
[1913] | 356 | |
---|
[107] | 357 | foreach ($tmp as $index => $right) |
---|
| 358 | { |
---|
| 359 | $bin = ''; |
---|
| 360 | for ($i=0; $i<$index; $i++) |
---|
| 361 | { |
---|
| 362 | $bin .= '0'; |
---|
| 363 | } |
---|
| 364 | $bin = '1' . $bin; |
---|
| 365 | |
---|
[317] | 366 | $array_acl[$right] = $this->safeBitCheck(bindec($bin), $acl); |
---|
| 367 | } |
---|
[107] | 368 | return $array_acl; |
---|
[2] | 369 | } |
---|
[548] | 370 | |
---|
[597] | 371 | function get_inactive_users($contexts) { |
---|
[548] | 372 | $retorno = array(); |
---|
| 373 | $tempUsers = array(); |
---|
| 374 | //Pego no LDAP todos os usuários dos contextos em questão. |
---|
| 375 | $usuariosLdap = $this->get_list('accounts','',$contexts); |
---|
| 376 | foreach($usuariosLdap as $usuarioLdap) { |
---|
| 377 | $tempUsers[$usuarioLdap["account_id"]] = $usuarioLdap["account_lid"]; |
---|
| 378 | } |
---|
| 379 | $ids = implode(",",array_keys($tempUsers)); //Consigo a lista de uids daquele contexto para mandar na query para o banco. |
---|
| 380 | |
---|
| 381 | //Pego nas configurações do expresso o número de dias necessários para inatividade. |
---|
| 382 | $timeToExpire = $GLOBALS['phpgw_info']['server']['time_to_account_expires']; |
---|
| 383 | |
---|
| 384 | |
---|
| 385 | $ultimoTsValido = time() - ($timeToExpire * 86400); //O último timestamp válido é dado pelo de agora menos o número de dias para expirar vezes a quantidade de segundos existente em 1 dia. |
---|
| 386 | $query = "select account_id,max(li) as last_login from phpgw_access_log where account_id in (".$ids.") group by account_id having max(li) < ".$ultimoTsValido." order by max(li)"; |
---|
[317] | 387 | |
---|
[548] | 388 | $GLOBALS['phpgw']->db->query($query); |
---|
| 389 | while($GLOBALS['phpgw']->db->next_record()) |
---|
| 390 | { |
---|
| 391 | $result = $GLOBALS['phpgw']->db->row(); |
---|
| 392 | array_push($retorno,array("uidNumber"=>$result["account_id"],"login"=> $tempUsers[$result["account_id"]],"li"=>$result["last_login"])); |
---|
| 393 | } |
---|
| 394 | |
---|
| 395 | return $retorno; |
---|
| 396 | } |
---|
| 397 | |
---|
[317] | 398 | function safeBitCheck($number,$comparison) |
---|
| 399 | { |
---|
| 400 | $binNumber = base_convert($number,10,2); |
---|
| 401 | $binComparison = strrev(base_convert($comparison,10,2)); |
---|
| 402 | $str = strlen($binNumber); |
---|
| 403 | |
---|
| 404 | if ( ($str <= strlen($binComparison)) && ($binComparison{$str-1}==="1") ) |
---|
| 405 | return '1'; |
---|
| 406 | else |
---|
| 407 | return '0'; |
---|
| 408 | } |
---|
[2] | 409 | |
---|
[64] | 410 | function get_list($type, $query, $contexts) |
---|
[2] | 411 | { |
---|
| 412 | $dn = $GLOBALS['phpgw_info']['server']['ldap_root_dn']; |
---|
| 413 | $passwd = $GLOBALS['phpgw_info']['server']['ldap_root_pw']; |
---|
| 414 | $ldap_conn = ldap_connect($GLOBALS['phpgw_info']['server']['ldap_host']); |
---|
| 415 | ldap_set_option($ldap_conn, LDAP_OPT_PROTOCOL_VERSION, 3); |
---|
| 416 | ldap_set_option($ldap_conn, LDAP_OPT_REFERRALS, 0); |
---|
| 417 | ldap_bind($ldap_conn,$dn,$passwd); |
---|
[2712] | 418 | |
---|
| 419 | $sort = array( ); |
---|
[2] | 420 | if ($type == 'accounts') |
---|
| 421 | { |
---|
| 422 | $justthese = array("uidnumber", "uid", "cn", "mail"); |
---|
[47] | 423 | $filter="(&(phpgwAccountType=u)(|(uid=*".$query."*)(sn=*".$query."*)(cn=*".$query."*)(givenName=*".$query."*)(mail=$query*)(mailAlternateAddress=$query*)))"; |
---|
[64] | 424 | |
---|
| 425 | $tmp = array(); |
---|
| 426 | foreach ($contexts as $index=>$context) |
---|
| 427 | { |
---|
| 428 | $search=ldap_search($ldap_conn, $context, $filter, $justthese); |
---|
| 429 | $info = ldap_get_entries($ldap_conn, $search); |
---|
| 430 | |
---|
| 431 | for ($i=0; $i < $info['count']; $i++) |
---|
| 432 | { |
---|
| 433 | $tmp[$info[$i]['uid'][0]]['account_id'] = $info[$i]['uidnumber'][0]; |
---|
| 434 | $tmp[$info[$i]['uid'][0]]['account_lid'] = $info[$i]['uid'][0]; |
---|
| 435 | $tmp[$info[$i]['uid'][0]]['account_cn'] = $info[$i]['cn'][0]; |
---|
| 436 | $tmp[$info[$i]['uid'][0]]['account_mail']= $info[$i]['mail'][0]; |
---|
| 437 | $sort[] = $info[$i]['uid'][0]; |
---|
| 438 | } |
---|
| 439 | } |
---|
[2] | 440 | ldap_close($ldap_conn); |
---|
| 441 | |
---|
[64] | 442 | if (count($sort)) |
---|
[2] | 443 | { |
---|
[64] | 444 | natcasesort($sort); |
---|
| 445 | foreach ($sort as $user_uid) |
---|
| 446 | $return[$user_uid] = $tmp[$user_uid]; |
---|
| 447 | } |
---|
| 448 | |
---|
| 449 | return $return; |
---|
[2] | 450 | } |
---|
| 451 | elseif($type == 'groups') |
---|
| 452 | { |
---|
[64] | 453 | $filter="(&(phpgwAccountType=g)(cn=*$query*))"; |
---|
[2] | 454 | $justthese = array("gidnumber", "cn", "description"); |
---|
| 455 | |
---|
| 456 | $tmp = array(); |
---|
[64] | 457 | foreach ($contexts as $index=>$context) |
---|
[2] | 458 | { |
---|
[64] | 459 | $search=ldap_search($ldap_conn, $context, $filter, $justthese); |
---|
| 460 | $info = ldap_get_entries($ldap_conn, $search); |
---|
| 461 | for ($i=0; $i < $info['count']; $i++) |
---|
| 462 | { |
---|
| 463 | $tmp[$info[$i]['cn'][0]]['cn']= $info[$i]['cn'][0]; |
---|
| 464 | $tmp[$info[$i]['cn'][0]]['description']= $info[$i]['description'][0]; |
---|
| 465 | $tmp[$info[$i]['cn'][0]]['gidnumber']= $info[$i]['gidnumber'][0]; |
---|
| 466 | $sort[] = $info[$i]['cn'][0]; |
---|
| 467 | } |
---|
[2] | 468 | } |
---|
[64] | 469 | ldap_close($ldap_conn); |
---|
| 470 | |
---|
| 471 | natcasesort($sort); |
---|
| 472 | foreach ($sort as $group_cn) |
---|
| 473 | $return[$group_cn] = $tmp[$group_cn]; |
---|
| 474 | |
---|
| 475 | return $return; |
---|
[2] | 476 | } |
---|
| 477 | elseif($type == 'maillists') |
---|
| 478 | { |
---|
| 479 | $filter="(&(phpgwAccountType=l)(|(cn=*".$query."*)(uid=*".$query."*)(mail=*".$query."*)))"; |
---|
| 480 | $justthese = array("uidnumber", "cn", "uid", "mail"); |
---|
[64] | 481 | |
---|
[2] | 482 | $tmp = array(); |
---|
[64] | 483 | foreach ($contexts as $index=>$context) |
---|
[2] | 484 | { |
---|
[64] | 485 | $search=ldap_search($ldap_conn, $context, $filter, $justthese); |
---|
| 486 | $info = ldap_get_entries($ldap_conn, $search); |
---|
| 487 | |
---|
| 488 | for ($i=0; $i < $info['count']; $i++) |
---|
| 489 | { |
---|
| 490 | $tmp[$info[$i]['uid'][0]]['uid'] = $info[$i]['uid'][0]; |
---|
| 491 | $tmp[$info[$i]['uid'][0]]['name'] = $info[$i]['cn'][0]; |
---|
| 492 | $tmp[$info[$i]['uid'][0]]['uidnumber'] = $info[$i]['uidnumber'][0]; |
---|
| 493 | $tmp[$info[$i]['uid'][0]]['email'] = $info[$i]['mail'][0]; |
---|
| 494 | $sort[] = $info[$i]['uid'][0]; |
---|
| 495 | } |
---|
[2] | 496 | } |
---|
[64] | 497 | ldap_close($ldap_conn); |
---|
| 498 | |
---|
| 499 | natcasesort($sort); |
---|
| 500 | foreach ($sort as $maillist_uid) |
---|
| 501 | $return[$maillist_uid] = $tmp[$maillist_uid]; |
---|
| 502 | |
---|
| 503 | return $return; |
---|
[2] | 504 | } |
---|
| 505 | elseif($type == 'computers') |
---|
| 506 | { |
---|
| 507 | $filter="(&(objectClass=sambaSAMAccount)(|(sambaAcctFlags=[W ])(sambaAcctFlags=[DW ])(sambaAcctFlags=[I ])(sambaAcctFlags=[S ]))(cn=*".$query."*))"; |
---|
| 508 | $justthese = array("cn","uidNumber","description"); |
---|
[64] | 509 | |
---|
[2] | 510 | $tmp = array(); |
---|
[64] | 511 | foreach ($contexts as $index=>$context) |
---|
[2] | 512 | { |
---|
[64] | 513 | $search=ldap_search($ldap_conn, $context, $filter, $justthese); |
---|
| 514 | $info = ldap_get_entries($ldap_conn, $search); |
---|
| 515 | for ($i=0; $i < $info['count']; $i++) |
---|
| 516 | { |
---|
| 517 | $tmp[$info[$i]['cn'][0]]['cn'] = $info[$i]['cn'][0]; |
---|
| 518 | $tmp[$info[$i]['cn'][0]]['uidNumber'] = $info[$i]['uidnumber'][0]; |
---|
| 519 | $tmp[$info[$i]['cn'][0]]['description'] = utf8_decode($info[$i]['description'][0]); |
---|
| 520 | $sort[] = $info[$i]['cn'][0]; |
---|
| 521 | } |
---|
| 522 | |
---|
[2] | 523 | } |
---|
[64] | 524 | ldap_close($ldap_conn); |
---|
[2] | 525 | |
---|
[396] | 526 | if (!empty($sort)) |
---|
| 527 | { |
---|
| 528 | natcasesort($sort); |
---|
| 529 | foreach ($sort as $computer_cn) |
---|
| 530 | $return[$computer_cn] = $tmp[$computer_cn]; |
---|
| 531 | } |
---|
[16] | 532 | |
---|
[64] | 533 | return $return; |
---|
[16] | 534 | } |
---|
| 535 | } |
---|
| 536 | |
---|
[208] | 537 | function get_organizations($context, $selected='', $referral=false, $show_invisible_ou=true, $master=false) |
---|
[23] | 538 | { |
---|
| 539 | $s = CreateObject('phpgwapi.sector_search_ldap'); |
---|
[208] | 540 | $sectors_info = $s->get_organizations($context, $selected, $referral, $show_invisible_ou, $master); |
---|
[23] | 541 | return $sectors_info; |
---|
[1516] | 542 | } |
---|
| 543 | |
---|
| 544 | /* |
---|
| 545 | Funciona de maneira similar ao get_sectors_list, porém retorna a propria OU do contexto |
---|
| 546 | e monta o array de retorno de forma diferente, necessário para algumas mudanças implementadas |
---|
| 547 | no método admin.uisectors.list_sectors. |
---|
| 548 | */ |
---|
| 549 | function get_organizations2($contexts, $selected='', $referral=false, $show_invisible_ou=true) { |
---|
| 550 | |
---|
| 551 | $dn = $GLOBALS['phpgw_info']['server']['ldap_root_dn']; |
---|
| 552 | $passwd = $GLOBALS['phpgw_info']['server']['ldap_root_pw']; |
---|
| 553 | $ldap_conn = ldap_connect($GLOBALS['phpgw_info']['server']['ldap_host']); |
---|
| 554 | |
---|
| 555 | ldap_set_option($ldap_conn, LDAP_OPT_PROTOCOL_VERSION, 3); |
---|
| 556 | |
---|
| 557 | if ($referral) |
---|
| 558 | ldap_set_option($ldap_conn, LDAP_OPT_REFERRALS, 1); |
---|
| 559 | else |
---|
| 560 | ldap_set_option($ldap_conn, LDAP_OPT_REFERRALS, 0); |
---|
| 561 | |
---|
| 562 | ldap_bind($ldap_conn,$dn,$passwd); |
---|
| 563 | |
---|
| 564 | $justthese = array("dn","diskQuota","usersQuota","actualDiskQuota"); |
---|
| 565 | $filter = "(ou=*)"; |
---|
| 566 | foreach ($contexts as $context) { |
---|
| 567 | $search=ldap_search($ldap_conn, $context, $filter, $justthese); |
---|
[208] | 568 | |
---|
[1516] | 569 | ldap_sort($ldap_conn, $search, "ou"); |
---|
| 570 | $info = ldap_get_entries($ldap_conn, $search); |
---|
| 571 | ldap_close($ldap_conn); |
---|
| 572 | |
---|
| 573 | // Retiro o count do array info e inverto o array para ordenaçãoo. |
---|
| 574 | for ($i=0; $i<$info["count"]; $i++) |
---|
| 575 | { |
---|
| 576 | $dn = $info[$i]["dn"]; |
---|
| 577 | |
---|
| 578 | // Necessário, pq em uma busca com ldapsearch ou=*, traz tb o próprio ou. |
---|
| 579 | //if (strtolower($dn) == $context) |
---|
| 580 | //continue; |
---|
| 581 | |
---|
| 582 | $array_dn = ldap_explode_dn ( $dn, 1 ); |
---|
| 583 | |
---|
| 584 | $array_dn_reverse = array_reverse ( $array_dn, true ); |
---|
| 585 | |
---|
| 586 | // Retirar o indice count do array. |
---|
| 587 | array_pop ( $array_dn_reverse ); |
---|
| 588 | |
---|
| 589 | $inverted_dn[implode ( "#", $array_dn_reverse )] = $info[$i]; |
---|
| 590 | } |
---|
| 591 | } |
---|
| 592 | // Ordenação por chave |
---|
| 593 | ksort($inverted_dn); |
---|
| 594 | |
---|
| 595 | // Construção do select |
---|
| 596 | $level = 0; |
---|
| 597 | $options = array(); |
---|
| 598 | foreach ($inverted_dn as $dn=>$info_ou) |
---|
| 599 | { |
---|
| 600 | $display = ''; |
---|
| 601 | $info_retorno = array(); |
---|
| 602 | $array_dn_reverse = explode ( "#", $dn ); |
---|
| 603 | $array_dn = array_reverse ( $array_dn_reverse, true ); |
---|
| 604 | |
---|
| 605 | $level = count( $array_dn ) - (int)(count(explode(",", $GLOBALS['phpgw_info']['server']['ldap_context'])) + 1); |
---|
| 606 | |
---|
| 607 | if ($level == 0) |
---|
| 608 | $display .= '+'; |
---|
| 609 | else |
---|
| 610 | { |
---|
| 611 | for ($i=0; $i<$level; $i++) |
---|
| 612 | $display .= '---'; |
---|
| 613 | } |
---|
| 614 | |
---|
| 615 | reset ( $array_dn ); |
---|
| 616 | $display .= ' ' . (current ( $array_dn ) ); |
---|
| 617 | |
---|
| 618 | $info_retorno['display'] = $display; |
---|
| 619 | $info_retorno['dn'] = $info_ou['dn']; |
---|
| 620 | $info_retorno['diskquota'] = $info_ou['diskquota'][0]; |
---|
| 621 | $info_retorno['usersquota'] = $info_ou['usersquota'][0]; |
---|
| 622 | // $info_retorno['actualdiskquota'] = round($this->get_actual_disk_usage($info_ou['dn']),2);//$info_ou['actualdiskquota'][0]; |
---|
| 623 | // $info_retorno['actualnumusers'] = $this->get_num_users($info_ou['dn']); |
---|
| 624 | |
---|
| 625 | array_push($options,$info_retorno); |
---|
| 626 | |
---|
| 627 | } |
---|
| 628 | return $options; |
---|
| 629 | } |
---|
| 630 | |
---|
| 631 | function get_info($context, $referral = false) { |
---|
| 632 | $dn = $GLOBALS['phpgw_info']['server']['ldap_root_dn']; |
---|
| 633 | $passwd = $GLOBALS['phpgw_info']['server']['ldap_root_pw']; |
---|
| 634 | $ldap_conn = ldap_connect($GLOBALS['phpgw_info']['server']['ldap_host']); |
---|
| 635 | |
---|
| 636 | ldap_set_option($ldap_conn, LDAP_OPT_PROTOCOL_VERSION, 3); |
---|
| 637 | |
---|
| 638 | if ($referral) |
---|
| 639 | ldap_set_option($ldap_conn, LDAP_OPT_REFERRALS, 1); |
---|
| 640 | else |
---|
| 641 | ldap_set_option($ldap_conn, LDAP_OPT_REFERRALS, 0); |
---|
| 642 | |
---|
| 643 | ldap_bind($ldap_conn,$dn,$passwd); |
---|
| 644 | |
---|
| 645 | $filter="(objectClass=organizationalUnit)"; |
---|
| 646 | $search=ldap_search($ldap_conn, $context, $filter); |
---|
| 647 | $result = ldap_get_entries($ldap_conn, $search); |
---|
| 648 | return $result; |
---|
| 649 | |
---|
| 650 | } |
---|
| 651 | |
---|
| 652 | function get_num_users($context,$selected='', $referral=false, $show_invisible_ou=true) { |
---|
| 653 | $dn = $GLOBALS['phpgw_info']['server']['ldap_root_dn']; |
---|
| 654 | $passwd = $GLOBALS['phpgw_info']['server']['ldap_root_pw']; |
---|
| 655 | $ldap_conn = ldap_connect($GLOBALS['phpgw_info']['server']['ldap_host']); |
---|
| 656 | |
---|
| 657 | ldap_set_option($ldap_conn, LDAP_OPT_PROTOCOL_VERSION, 3); |
---|
| 658 | |
---|
| 659 | if ($referral) |
---|
| 660 | ldap_set_option($ldap_conn, LDAP_OPT_REFERRALS, 1); |
---|
| 661 | else |
---|
| 662 | ldap_set_option($ldap_conn, LDAP_OPT_REFERRALS, 0); |
---|
| 663 | |
---|
| 664 | ldap_bind($ldap_conn,$dn,$passwd); |
---|
| 665 | |
---|
| 666 | $justthese = array("dn"); |
---|
| 667 | $filter = "(objectClass=inetOrgPerson)"; |
---|
| 668 | $search=ldap_search($ldap_conn, $context, $filter, $justthese); |
---|
| 669 | |
---|
| 670 | $retorno = ldap_count_entries($ldap_conn, $search); |
---|
| 671 | ldap_close($ldap_conn); |
---|
| 672 | |
---|
| 673 | return $retorno; |
---|
| 674 | } |
---|
| 675 | |
---|
| 676 | //Checa se existe quota para mais um usuï¿œrio no setor... se existir retorna true, senï¿œo false. |
---|
| 677 | function existe_quota_usuario($setor) { |
---|
| 678 | $num_users = $this->get_num_users($setor['dn']); |
---|
| 679 | //return $num_users . " --- " . $setor['usersquota'][0] |
---|
| 680 | if(($num_users>=$setor['usersquota'][0]) && ($setor['usersquota'][0]!=-1)) { |
---|
| 681 | return false; |
---|
| 682 | } |
---|
| 683 | return true; |
---|
| 684 | } |
---|
| 685 | |
---|
| 686 | //Checa se existe quota em disco para mais um usuï¿œrio no setor... se existir retorna true, senï¿œo false. |
---|
| 687 | function existe_quota_disco($setor,$quota_novo_usuario) { |
---|
| 688 | settype($quota_novo_usuario,"float"); |
---|
| 689 | $quota_novo_usuario /= 1024; //A quota vï¿œm da interface em megabytes, deve se tornar gigabyte. |
---|
| 690 | |
---|
| 691 | $nova_quota = $this->get_actual_disk_usage($setor['dn']) + $quota_novo_usuario; |
---|
| 692 | if(( $nova_quota >= $setor['diskquota'][0] ) && ($setor['diskquota'][0] != -1)) { |
---|
| 693 | return false; |
---|
| 694 | } |
---|
| 695 | return true; |
---|
| 696 | } |
---|
| 697 | |
---|
| 698 | // Soma as quotas de todos os usuï¿œrios daquele contexto. |
---|
| 699 | function get_actual_disk_usage($context) { |
---|
| 700 | $quota_usada=0; |
---|
| 701 | $contexts = array($context); |
---|
| 702 | $usuarios = $this->get_list('accounts', '', $contexts); |
---|
| 703 | |
---|
| 704 | $imap_functions = new imap_functions(); |
---|
| 705 | foreach($usuarios as $usuario) { |
---|
| 706 | $temp = $imap_functions->get_user_info($usuario['account_lid']); |
---|
| 707 | if($temp['mailquota'] != -1) //Usuï¿œrio sem cota nï¿œo conta... |
---|
| 708 | $quota_usada += ($temp['mailquota'] / 1024); |
---|
| 709 | } |
---|
| 710 | return $quota_usada; |
---|
| 711 | } |
---|
| 712 | |
---|
[33] | 713 | function get_sectors($selected='', $referral=false, $show_invisible_ou=true) |
---|
| 714 | { |
---|
| 715 | $s = CreateObject('phpgwapi.sector_search_ldap'); |
---|
| 716 | $sectors_info = $s->get_sectors($selected, $referral, $show_invisible_ou); |
---|
| 717 | return $sectors_info; |
---|
| 718 | } |
---|
| 719 | |
---|
[2] | 720 | // Get list of all levels, this function is used for sectors module. |
---|
[64] | 721 | function get_sectors_list($contexts) |
---|
[2] | 722 | { |
---|
[64] | 723 | $a_sectors = array(); |
---|
| 724 | |
---|
[46] | 725 | $dn = $GLOBALS['phpgw_info']['server']['ldap_root_dn']; |
---|
| 726 | $passwd = $GLOBALS['phpgw_info']['server']['ldap_root_pw']; |
---|
| 727 | $ldap_conn = ldap_connect($GLOBALS['phpgw_info']['server']['ldap_host']); |
---|
| 728 | |
---|
| 729 | ldap_set_option($ldap_conn, LDAP_OPT_PROTOCOL_VERSION, 3); |
---|
[64] | 730 | ldap_set_option($ldap_conn, LDAP_OPT_REFERRALS, 0); |
---|
[46] | 731 | ldap_bind($ldap_conn,$dn,$passwd); |
---|
| 732 | |
---|
| 733 | $justthese = array("dn"); |
---|
[89] | 734 | $filter = "(ou=*)"; |
---|
[64] | 735 | |
---|
[89] | 736 | $systemName = strtolower($GLOBALS['phpgw_info']['server']['system_name']); |
---|
| 737 | if ($systemName != '') |
---|
| 738 | $filter = "(&$filter(phpgwSystem=$systemName))"; |
---|
| 739 | |
---|
[64] | 740 | foreach ($contexts as $context) |
---|
| 741 | { |
---|
| 742 | $search=ldap_search($ldap_conn, $context, $filter, $justthese); |
---|
| 743 | $info = ldap_get_entries($ldap_conn, $search); |
---|
| 744 | for ($i=0; $i<$info["count"]; $i++) |
---|
| 745 | { |
---|
| 746 | $a_sectors[] = $info[$i]['dn']; |
---|
| 747 | } |
---|
| 748 | } |
---|
[46] | 749 | |
---|
| 750 | ldap_close($ldap_conn); |
---|
| 751 | |
---|
| 752 | // Retiro o count do array info e inverto o array para ordenação. |
---|
[64] | 753 | foreach ($a_sectors as $context) |
---|
[46] | 754 | { |
---|
[64] | 755 | $array_dn = ldap_explode_dn ( $context, 1 ); |
---|
[46] | 756 | |
---|
| 757 | $array_dn_reverse = array_reverse ( $array_dn, true ); |
---|
| 758 | |
---|
| 759 | // Retirar o indice count do array. |
---|
| 760 | array_pop ( $array_dn_reverse ); |
---|
| 761 | |
---|
[64] | 762 | $inverted_dn[$context] = implode ( "#", $array_dn_reverse ); |
---|
[46] | 763 | } |
---|
| 764 | |
---|
| 765 | // Ordenação |
---|
| 766 | natcasesort($inverted_dn); |
---|
| 767 | |
---|
| 768 | // Construção do select |
---|
| 769 | $level = 0; |
---|
| 770 | $options = array(); |
---|
| 771 | foreach ($inverted_dn as $dn=>$invert_ufn) |
---|
| 772 | { |
---|
| 773 | $display = ''; |
---|
| 774 | |
---|
| 775 | $array_dn_reverse = explode ( "#", $invert_ufn ); |
---|
| 776 | $array_dn = array_reverse ( $array_dn_reverse, true ); |
---|
| 777 | |
---|
| 778 | $level = count( $array_dn ) - (int)(count(explode(",", $GLOBALS['phpgw_info']['server']['ldap_context'])) + 1); |
---|
| 779 | |
---|
| 780 | if ($level == 0) |
---|
| 781 | $display .= '+'; |
---|
| 782 | else |
---|
| 783 | { |
---|
| 784 | for ($i=0; $i<$level; $i++) |
---|
| 785 | $display .= '---'; |
---|
| 786 | } |
---|
| 787 | |
---|
| 788 | reset ( $array_dn ); |
---|
| 789 | $display .= ' ' . (current ( $array_dn ) ); |
---|
| 790 | |
---|
| 791 | $dn = trim(strtolower($dn)); |
---|
| 792 | $options[$dn] = $display; |
---|
| 793 | } |
---|
| 794 | return $options; |
---|
| 795 | } |
---|
| 796 | |
---|
[2] | 797 | function exist_account_lid($account_lid) |
---|
| 798 | { |
---|
| 799 | $conection = $GLOBALS['phpgw']->common->ldapConnect(); |
---|
| 800 | $sri = ldap_search($conection, $GLOBALS['phpgw_info']['server']['ldap_context'], "uid=" . $account_lid); |
---|
| 801 | $result = ldap_get_entries($conection, $sri); |
---|
| 802 | return $result['count']; |
---|
| 803 | } |
---|
| 804 | |
---|
| 805 | function exist_email($mail) |
---|
| 806 | { |
---|
| 807 | $conection = $GLOBALS['phpgw']->common->ldapConnect(); |
---|
| 808 | $sri = ldap_search($conection, $GLOBALS['phpgw_info']['server']['ldap_context'], "mail=" . $mail); |
---|
| 809 | $result = ldap_get_entries($conection, $sri); |
---|
| 810 | ldap_close($conection); |
---|
| 811 | |
---|
| 812 | if ($result['count'] == 0) |
---|
| 813 | return false; |
---|
| 814 | else |
---|
| 815 | return true; |
---|
| 816 | } |
---|
| 817 | |
---|
| 818 | function array_invert($array) |
---|
| 819 | { |
---|
| 820 | $result[] = end($array); |
---|
| 821 | while ($item = prev($array)) |
---|
| 822 | $result[] = $item; |
---|
| 823 | return $result; |
---|
| 824 | } |
---|
| 825 | |
---|
| 826 | function get_next_id() |
---|
| 827 | { |
---|
| 828 | // Busco o ID dos accounts |
---|
| 829 | $query_accounts = "SELECT id FROM phpgw_nextid WHERE appname = 'accounts'"; |
---|
| 830 | $GLOBALS['phpgw']->db->query($query_accounts); |
---|
| 831 | while($GLOBALS['phpgw']->db->next_record()) |
---|
| 832 | { |
---|
| 833 | $result_accounts[] = $GLOBALS['phpgw']->db->row(); |
---|
| 834 | } |
---|
| 835 | $accounts_id = $result_accounts[0]['id']; |
---|
| 836 | |
---|
| 837 | // Busco o ID dos groups |
---|
| 838 | $query_groups = "SELECT id FROM phpgw_nextid WHERE appname = 'groups'"; |
---|
| 839 | $GLOBALS['phpgw']->db->query($query_groups); |
---|
| 840 | while($GLOBALS['phpgw']->db->next_record()) |
---|
| 841 | { |
---|
| 842 | $result_groups[] = $GLOBALS['phpgw']->db->row(); |
---|
| 843 | } |
---|
| 844 | $groups_id = $result_groups[0]['id']; |
---|
| 845 | |
---|
| 846 | //Retorna o maior dos ID's |
---|
| 847 | if ($accounts_id >= $groups_id) |
---|
| 848 | return $accounts_id; |
---|
| 849 | else |
---|
| 850 | return $groups_id; |
---|
| 851 | } |
---|
| 852 | |
---|
[64] | 853 | function make_list_app($account_lid, $user_applications='', $disabled='') |
---|
[2] | 854 | { |
---|
| 855 | // create list of ALL available apps |
---|
| 856 | $availableAppsGLOBALS = $GLOBALS['phpgw_info']['apps']; |
---|
| 857 | |
---|
| 858 | // create list of available apps for the user |
---|
[64] | 859 | $query = "SELECT * FROM phpgw_expressoadmin_apps WHERE manager_lid = '".$account_lid."'"; |
---|
[2] | 860 | $GLOBALS['phpgw']->db->query($query); |
---|
| 861 | while($GLOBALS['phpgw']->db->next_record()) |
---|
| 862 | { |
---|
| 863 | $availableApps[] = $GLOBALS['phpgw']->db->row(); |
---|
| 864 | } |
---|
| 865 | |
---|
| 866 | // Retira alguns modulos |
---|
| 867 | if (count($availableApps)) |
---|
| 868 | { |
---|
| 869 | foreach ($availableApps as $key => $value) |
---|
| 870 | { |
---|
| 871 | if ($value['app'] != 'phpgwapi') |
---|
| 872 | $tmp[] = $availableApps[$key]; |
---|
| 873 | } |
---|
| 874 | } |
---|
| 875 | $availableApps = $tmp; |
---|
| 876 | |
---|
| 877 | // Cria um array com as aplicacoes disponiveis para o manager, com as atributos das aplicacoes. |
---|
| 878 | $availableAppsUser = array(); |
---|
| 879 | if (count($availableApps)) |
---|
| 880 | { |
---|
| 881 | foreach($availableApps as $app => $title) |
---|
| 882 | { |
---|
| 883 | if ($availableAppsGLOBALS[$title['app']]) |
---|
| 884 | $availableAppsUser[$title['app']] = $availableAppsGLOBALS[$title['app']]; |
---|
| 885 | } |
---|
| 886 | } |
---|
| 887 | |
---|
| 888 | // Loop para criar dinamicamente uma tabela com 3 colunas, cada coluna com um aplicativo e um check box. |
---|
| 889 | $applications_list = ''; |
---|
| 890 | $app_col1 = ''; |
---|
| 891 | $app_col2 = ''; |
---|
| 892 | $app_col3 = ''; |
---|
| 893 | $total_apps = count($availableAppsUser); |
---|
| 894 | $i = 0; |
---|
| 895 | foreach($availableAppsUser as $app => $data) |
---|
| 896 | { |
---|
| 897 | // 1 coluna |
---|
| 898 | if (($i +1) % 3 == 1) |
---|
| 899 | { |
---|
| 900 | $checked = $user_applications[$app] ? 'CHECKED' : ''; |
---|
| 901 | $app_col1 = sprintf("<td>%s</td><td width='10'><input type='checkbox' name='apps[%s]' value='1' %s %s></td>\n", |
---|
| 902 | $data['title'],$app,$checked, $disabled); |
---|
| 903 | if ($i == ($total_apps-1)) |
---|
| 904 | $applications_list .= sprintf('<tr bgcolor="%s">%s</tr>','#DDDDDD', $app_col1); |
---|
| 905 | } |
---|
| 906 | |
---|
| 907 | // 2 coluna |
---|
| 908 | if (($i +1) % 3 == 2) |
---|
| 909 | { |
---|
| 910 | $checked = $user_applications[$app] ? 'CHECKED' : ''; |
---|
| 911 | $app_col2 = sprintf("<td>%s</td><td width='10'><input type='checkbox' name='apps[%s]' value='1' %s %s></td>\n", |
---|
| 912 | $data['title'],$app,$checked, $disabled); |
---|
| 913 | |
---|
| 914 | if ($i == ($total_apps-1)) |
---|
| 915 | $applications_list .= sprintf('<tr bgcolor="%s">%s%s</tr>','#DDDDDD', $app_col1,$app_col2); |
---|
| 916 | } |
---|
| 917 | // 3 coluna |
---|
| 918 | if (($i +1) % 3 == 0) |
---|
| 919 | { |
---|
| 920 | $checked = $user_applications[$app] ? 'CHECKED' : ''; |
---|
| 921 | $app_col3 = sprintf("<td>%s</td><td width='10'><input type='checkbox' name='apps[%s]' value='1' %s %s></td>\n", |
---|
| 922 | $data['title'],$app,$checked, $disabled); |
---|
| 923 | |
---|
| 924 | // Cria nova linha |
---|
| 925 | $applications_list .= sprintf('<tr bgcolor="%s">%s%s%s</tr>','#DDDDDD', $app_col1, $app_col2, $app_col3); |
---|
| 926 | } |
---|
| 927 | $i++; |
---|
| 928 | } |
---|
| 929 | return $applications_list; |
---|
| 930 | } |
---|
| 931 | |
---|
| 932 | function exist_attribute_in_ldap($dn, $attribute, $value) |
---|
| 933 | { |
---|
| 934 | $connection = $GLOBALS['phpgw']->common->ldapConnect(); |
---|
| 935 | $search = ldap_search($connection, $dn, $attribute. "=" . $value); |
---|
| 936 | $result = ldap_get_entries($connection, $search); |
---|
| 937 | ldap_close($connection); |
---|
| 938 | //_debug_array($result); |
---|
| 939 | if ($result['count'] == 0) |
---|
| 940 | return false; |
---|
| 941 | else |
---|
| 942 | return true; |
---|
| 943 | } |
---|
| 944 | |
---|
| 945 | function getReturnExecuteForm(){ |
---|
| 946 | $response = $_SESSION['response']; |
---|
| 947 | $_SESSION['response'] = null; |
---|
| 948 | return $response; |
---|
| 949 | } |
---|
| 950 | |
---|
[317] | 951 | function lang($key) |
---|
| 952 | { |
---|
| 953 | if ($_SESSION['phpgw_info']['expressoAdmin']['lang'][$key]) |
---|
| 954 | return $_SESSION['phpgw_info']['expressoAdmin']['lang'][$key]; |
---|
| 955 | else |
---|
| 956 | return $key . '*'; |
---|
| 957 | } |
---|
[355] | 958 | |
---|
| 959 | |
---|
| 960 | function checkCPF($cpf) |
---|
| 961 | { |
---|
| 962 | $nulos = array("12345678909","11111111111","22222222222","33333333333", |
---|
| 963 | "44444444444","55555555555","66666666666","77777777777", |
---|
| 964 | "88888888888","99999999999","00000000000"); |
---|
| 965 | |
---|
[379] | 966 | /* formato do CPF */ |
---|
| 967 | if (!(ereg("^[0-9]{3}[.][0-9]{3}[.][0-9]{3}[-][0-9]{2}$",$cpf))) |
---|
| 968 | return false; |
---|
| 969 | |
---|
[355] | 970 | /* Retira todos os caracteres que nao sejam 0-9 */ |
---|
| 971 | $cpf = ereg_replace("[^0-9]", "", $cpf); |
---|
| 972 | |
---|
| 973 | /*Retorna falso se houver letras no cpf */ |
---|
| 974 | if (!(ereg("[0-9]",$cpf))) |
---|
| 975 | return false; |
---|
| 976 | |
---|
| 977 | /* Retorna falso se o cpf for nulo */ |
---|
| 978 | if( in_array($cpf, $nulos) ) |
---|
| 979 | return false; |
---|
| 980 | |
---|
| 981 | /*Calcula o penúltimo dígito verificador*/ |
---|
| 982 | $acum=0; |
---|
| 983 | for($i=0; $i<9; $i++) |
---|
| 984 | { |
---|
| 985 | $acum+= $cpf[$i]*(10-$i); |
---|
| 986 | } |
---|
| 987 | |
---|
| 988 | $x=$acum % 11; |
---|
| 989 | $acum = ($x>1) ? (11 - $x) : 0; |
---|
| 990 | /* Retorna falso se o digito calculado eh diferente do passado na string */ |
---|
| 991 | if ($acum != $cpf[9]){ |
---|
| 992 | return false; |
---|
| 993 | } |
---|
| 994 | /*Calcula o último dígito verificador*/ |
---|
| 995 | $acum=0; |
---|
| 996 | for ($i=0; $i<10; $i++) |
---|
| 997 | { |
---|
| 998 | $acum+= $cpf[$i]*(11-$i); |
---|
| 999 | } |
---|
| 1000 | |
---|
| 1001 | $x=$acum % 11; |
---|
| 1002 | $acum = ($x > 1) ? (11-$x) : 0; |
---|
| 1003 | /* Retorna falso se o digito calculado eh diferente do passado na string */ |
---|
| 1004 | if ( $acum != $cpf[10]) |
---|
| 1005 | { |
---|
| 1006 | return false; |
---|
| 1007 | } |
---|
| 1008 | /* Retorna verdadeiro se o cpf eh valido */ |
---|
| 1009 | return true; |
---|
| 1010 | } |
---|
[414] | 1011 | |
---|
| 1012 | function make_lang($ram_lang) |
---|
| 1013 | { |
---|
| 1014 | $a_lang = split("_", $ram_lang); |
---|
| 1015 | $a_lang_reverse = array_reverse ( $a_lang, true ); |
---|
| 1016 | array_pop ( $a_lang_reverse ); |
---|
| 1017 | $a_lang = array_reverse ( $a_lang_reverse, true ); |
---|
| 1018 | $a_new_lang = implode ( " ", $a_lang ); |
---|
| 1019 | return lang($a_new_lang); |
---|
| 1020 | } |
---|
| 1021 | |
---|
| 1022 | function make_dinamic_lang($template_obj, $block) |
---|
| 1023 | { |
---|
| 1024 | $tpl_vars = $template_obj->get_undefined($block); |
---|
| 1025 | $array_langs = array(); |
---|
| 1026 | |
---|
| 1027 | foreach ($tpl_vars as $atribute) |
---|
| 1028 | { |
---|
| 1029 | $lang = strstr($atribute, 'lang_'); |
---|
| 1030 | if($lang !== false) |
---|
| 1031 | { |
---|
| 1032 | //$template_obj->set_var($atribute, $this->make_lang($atribute)); |
---|
| 1033 | $array_langs[$atribute] = $this->make_lang($atribute); |
---|
| 1034 | } |
---|
| 1035 | } |
---|
| 1036 | return $array_langs; |
---|
| 1037 | } |
---|
[2] | 1038 | } |
---|
| 1039 | |
---|
| 1040 | class sectors_object |
---|
| 1041 | { |
---|
| 1042 | var $sector_name; |
---|
| 1043 | var $sector_context; |
---|
| 1044 | var $sector_level; |
---|
| 1045 | var $sector_leaf; |
---|
| 1046 | var $sectors_list = array(); |
---|
| 1047 | var $level; |
---|
| 1048 | |
---|
| 1049 | function sectors_object($sector_name, $sector_context, $sector_level, $sector_leaf) |
---|
| 1050 | { |
---|
| 1051 | $this->sector_name = $sector_name; |
---|
| 1052 | $this->sector_context = $sector_context; |
---|
| 1053 | $this->sector_level = $sector_level; |
---|
| 1054 | $this->sector_leaf = $sector_leaf; |
---|
| 1055 | } |
---|
[548] | 1056 | } |
---|