[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'); |
---|
| 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 | // Account and type of access. Return: Have access ? (true/false) |
---|
| 36 | function check_acl($account_lid, $access) |
---|
| 37 | { |
---|
| 38 | $acl = $this->read_acl($account_lid); |
---|
| 39 | $array_acl = $this->make_array_acl($acl[0][acl]); |
---|
| 40 | |
---|
| 41 | //What access ?? In the IF, verify if have access. |
---|
| 42 | switch($access) |
---|
| 43 | { |
---|
| 44 | case list_users: |
---|
| 45 | 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]) |
---|
| 46 | return true; |
---|
| 47 | break; |
---|
| 48 | case add_users: |
---|
| 49 | if ($array_acl[add_users]) |
---|
| 50 | return true; |
---|
| 51 | break; |
---|
| 52 | case edit_users: |
---|
| 53 | if ($array_acl[edit_users]) |
---|
| 54 | return true; |
---|
| 55 | break; |
---|
| 56 | case delete_users: |
---|
| 57 | if ($array_acl[delete_users]) |
---|
| 58 | return true; |
---|
| 59 | break; |
---|
| 60 | case rename_users: |
---|
| 61 | if ($array_acl[rename_users]) |
---|
| 62 | return true; |
---|
| 63 | break; |
---|
| 64 | case change_users_password: |
---|
| 65 | if ($array_acl[change_users_password]) |
---|
| 66 | return true; |
---|
| 67 | break; |
---|
| 68 | case change_users_quote: |
---|
| 69 | if ($array_acl[change_users_quote]) |
---|
| 70 | return true; |
---|
| 71 | break; |
---|
| 72 | case set_user_default_password: |
---|
| 73 | if ($array_acl[set_user_default_password]) |
---|
| 74 | return true; |
---|
| 75 | break; |
---|
| 76 | case edit_sambausers_attributes: |
---|
| 77 | if ($array_acl[edit_sambausers_attributes]) |
---|
| 78 | return true; |
---|
| 79 | break; |
---|
| 80 | |
---|
| 81 | case list_groups: |
---|
| 82 | if ($array_acl[add_groups] || $array_acl[edit_groups] || $array_acl[delete_groups]) |
---|
| 83 | return true; |
---|
| 84 | break; |
---|
| 85 | case add_groups: |
---|
| 86 | if ($array_acl[add_groups]) |
---|
| 87 | return true; |
---|
| 88 | break; |
---|
| 89 | case edit_groups: |
---|
| 90 | if ($array_acl[edit_groups]) |
---|
| 91 | return true; |
---|
| 92 | break; |
---|
| 93 | case delete_groups: |
---|
| 94 | if ($array_acl[delete_groups]) |
---|
| 95 | return true; |
---|
| 96 | break; |
---|
| 97 | |
---|
| 98 | case list_maillists: |
---|
| 99 | if ($array_acl[add_maillists] || $array_acl[edit_maillists] || $array_acl[delete_maillists]) |
---|
| 100 | return true; |
---|
| 101 | break; |
---|
| 102 | case add_maillists: |
---|
| 103 | if ($array_acl[add_maillists]) |
---|
| 104 | return true; |
---|
| 105 | break; |
---|
| 106 | case edit_maillists: |
---|
| 107 | if ($array_acl[edit_maillists]) |
---|
| 108 | return true; |
---|
| 109 | break; |
---|
| 110 | case delete_maillists: |
---|
| 111 | if ($array_acl[delete_maillists]) |
---|
| 112 | return true; |
---|
| 113 | break; |
---|
| 114 | |
---|
| 115 | case list_sectors: |
---|
| 116 | if ($array_acl[create_sectors] || $array_acl[edit_sectors] || $array_acl[delete_sectors]) |
---|
| 117 | return true; |
---|
| 118 | break; |
---|
| 119 | case create_sectors: |
---|
| 120 | if ($array_acl[create_sectors]) |
---|
| 121 | return true; |
---|
| 122 | break; |
---|
| 123 | case edit_sectors: |
---|
| 124 | if ($array_acl[edit_sectors]) |
---|
| 125 | return true; |
---|
| 126 | break; |
---|
| 127 | case delete_sectors: |
---|
| 128 | if ($array_acl[delete_sectors]) |
---|
| 129 | return true; |
---|
| 130 | break; |
---|
| 131 | |
---|
| 132 | case manage_wf_sectors: |
---|
| 133 | if ($array_acl[manage_wf_sectors]) |
---|
| 134 | return true; |
---|
| 135 | break; |
---|
| 136 | |
---|
| 137 | case view_global_sessions: |
---|
| 138 | if ($array_acl[view_global_sessions]) |
---|
| 139 | return true; |
---|
| 140 | break; |
---|
| 141 | |
---|
| 142 | case list_computers: |
---|
| 143 | if ($array_acl[create_computers] || $array_acl[edit_computers] || $array_acl[delete_computers]) |
---|
| 144 | return true; |
---|
| 145 | break; |
---|
| 146 | case create_computers: |
---|
| 147 | if ($array_acl[create_computers]) |
---|
| 148 | return true; |
---|
| 149 | break; |
---|
| 150 | case edit_computers: |
---|
| 151 | if ($array_acl[edit_computers]) |
---|
| 152 | return true; |
---|
| 153 | break; |
---|
| 154 | case delete_computers: |
---|
| 155 | if ($array_acl[delete_computers]) |
---|
| 156 | return true; |
---|
| 157 | break; |
---|
| 158 | |
---|
| 159 | case view_logs: |
---|
| 160 | if ($array_acl[view_logs]) |
---|
| 161 | return true; |
---|
| 162 | break; |
---|
| 163 | |
---|
| 164 | default: |
---|
| 165 | return false; |
---|
| 166 | } |
---|
| 167 | |
---|
| 168 | return false; |
---|
| 169 | } |
---|
| 170 | |
---|
| 171 | // Read acl from db |
---|
| 172 | function read_acl($account_lid) |
---|
| 173 | { |
---|
| 174 | /* |
---|
| 175 | $query = "SELECT * FROM phpgw_expressoadmin WHERE manager_lid = '" . $account_lid . "'"; |
---|
| 176 | $GLOBALS['phpgw']->db->query($query); |
---|
| 177 | while($GLOBALS['phpgw']->db->next_record()) |
---|
| 178 | { |
---|
| 179 | $result[] = $GLOBALS['phpgw']->db->row(); |
---|
| 180 | } |
---|
| 181 | */ |
---|
| 182 | $result = $this->db_functions->read_acl($account_lid); |
---|
| 183 | $context_array = ldap_explode_dn($result[0]['context'], 1); |
---|
| 184 | $tmp = array_shift($context_array); |
---|
| 185 | $result[0]['context_display'] = implode(".", $context_array); |
---|
| 186 | return $result; |
---|
| 187 | } |
---|
| 188 | |
---|
| 189 | // Make a array read humam |
---|
| 190 | function make_array_acl($acl) |
---|
| 191 | { |
---|
| 192 | $array_acl['add_users'] = $acl & 1; |
---|
| 193 | $array_acl['edit_users'] = $acl & 2; |
---|
| 194 | $array_acl['delete_users'] = $acl & 4; |
---|
| 195 | $array_acl['rename_users'] = $acl & 8388608; |
---|
| 196 | $array_acl['add_groups'] = $acl & 16; |
---|
| 197 | $array_acl['edit_groups'] = $acl & 32; |
---|
| 198 | $array_acl['delete_groups'] = $acl & 64; |
---|
| 199 | $array_acl['change_users_password'] = $acl & 128; |
---|
| 200 | $array_acl['change_users_quote'] = $acl & 262144; |
---|
| 201 | $array_acl['set_user_default_password'] = $acl & 524288; |
---|
| 202 | $array_acl['edit_sambausers_attributes'] = $acl & 32768; |
---|
| 203 | $array_acl['add_maillists'] = $acl & 256; |
---|
| 204 | $array_acl['edit_maillists'] = $acl & 512; |
---|
| 205 | $array_acl['delete_maillists'] = $acl & 1024; |
---|
| 206 | $array_acl['create_sectors'] = $acl & 4096; |
---|
| 207 | $array_acl['edit_sectors'] = $acl & 8192; |
---|
| 208 | $array_acl['delete_sectors'] = $acl & 16384; |
---|
| 209 | $array_acl['view_global_sessions'] = $acl & 65536; |
---|
| 210 | $array_acl['view_logs'] = $acl & 131072; |
---|
| 211 | $array_acl['create_computers'] = $acl & 1048576; |
---|
| 212 | $array_acl['edit_computers'] = $acl & 2097152; |
---|
| 213 | $array_acl['delete_computers'] = $acl & 4194304; |
---|
| 214 | return $array_acl; |
---|
| 215 | } |
---|
| 216 | |
---|
| 217 | function get_list($type, $query, $context) |
---|
| 218 | { |
---|
| 219 | $dn = $GLOBALS['phpgw_info']['server']['ldap_root_dn']; |
---|
| 220 | $passwd = $GLOBALS['phpgw_info']['server']['ldap_root_pw']; |
---|
| 221 | $ldap_conn = ldap_connect($GLOBALS['phpgw_info']['server']['ldap_host']); |
---|
| 222 | ldap_set_option($ldap_conn, LDAP_OPT_PROTOCOL_VERSION, 3); |
---|
| 223 | ldap_set_option($ldap_conn, LDAP_OPT_REFERRALS, 0); |
---|
| 224 | ldap_bind($ldap_conn,$dn,$passwd); |
---|
| 225 | |
---|
| 226 | if ($type == 'accounts') |
---|
| 227 | { |
---|
| 228 | |
---|
| 229 | $justthese = array("uidnumber", "uid", "cn", "mail"); |
---|
| 230 | $filter="(&(phpgwAccountType=u)(|(uid=*".$query."*)(sn=*".$query."*)(cn=*".$query."*)(givenName=*".$query."*)(mail=$query*)))"; |
---|
| 231 | $search=ldap_search($ldap_conn, $context, $filter, $justthese); |
---|
| 232 | ldap_sort($ldap_conn, $search, "uid"); |
---|
| 233 | $info = ldap_get_entries($ldap_conn, $search); |
---|
| 234 | ldap_close($ldap_conn); |
---|
| 235 | |
---|
| 236 | $i = 0; |
---|
| 237 | $tmp = array(); |
---|
| 238 | for ($i=0; $i < $info['count']; $i++) |
---|
| 239 | { |
---|
| 240 | $tmp[$i][account_id] = $info[$i]['uidnumber'][0]; |
---|
| 241 | $tmp[$i][account_lid] = $info[$i]['uid'][0]; |
---|
| 242 | $tmp[$i][account_cn] = $info[$i]['cn'][0]; |
---|
| 243 | $tmp[$i][account_mail] = $info[$i]['mail'][0]; |
---|
| 244 | } |
---|
| 245 | return $tmp; |
---|
| 246 | } |
---|
| 247 | elseif($type == 'groups') |
---|
| 248 | { |
---|
| 249 | $filter="(&(phpgwAccountType=g)(cn=*".$query."*))"; |
---|
| 250 | $justthese = array("gidnumber", "cn", "description"); |
---|
| 251 | $search=ldap_search($ldap_conn, $context, $filter, $justthese); |
---|
| 252 | ldap_sort($ldap_conn, $search, "cn"); |
---|
| 253 | $info = ldap_get_entries($ldap_conn, $search); |
---|
| 254 | ldap_close($ldap_conn); |
---|
| 255 | |
---|
| 256 | $i = 0; |
---|
| 257 | $tmp = array(); |
---|
| 258 | for ($i=0; $i < $info['count']; $i++) |
---|
| 259 | { |
---|
| 260 | $tmp[$i][cn] = $info[$i][cn][0]; |
---|
| 261 | $tmp[$i][description] = $info[$i][description][0]; |
---|
| 262 | $tmp[$i][gidnumber] = $info[$i][gidnumber][0]; |
---|
| 263 | } |
---|
| 264 | return $tmp; |
---|
| 265 | } |
---|
| 266 | elseif($type == 'maillists') |
---|
| 267 | { |
---|
| 268 | $filter="(&(phpgwAccountType=l)(|(cn=*".$query."*)(uid=*".$query."*)(mail=*".$query."*)))"; |
---|
| 269 | $justthese = array("uidnumber", "cn", "uid", "mail"); |
---|
| 270 | $search=ldap_search($ldap_conn, $context, $filter, $justthese); |
---|
| 271 | ldap_sort($ldap_conn, $search, "uid"); |
---|
| 272 | $info = ldap_get_entries($ldap_conn, $search); |
---|
| 273 | ldap_close($ldap_conn); |
---|
| 274 | |
---|
| 275 | $i = 0; |
---|
| 276 | $tmp = array(); |
---|
| 277 | for ($i=0; $i < $info['count']; $i++) |
---|
| 278 | { |
---|
| 279 | $tmp[$i]['uid'] = $info[$i]['uid'][0]; |
---|
| 280 | $tmp[$i]['name'] = $info[$i]['cn'][0]; |
---|
| 281 | $tmp[$i]['uidnumber'] = $info[$i]['uidnumber'][0]; |
---|
| 282 | $tmp[$i]['email'] = $info[$i]['mail'][0]; |
---|
| 283 | } |
---|
| 284 | return $tmp; |
---|
| 285 | } |
---|
| 286 | elseif($type == 'computers') |
---|
| 287 | { |
---|
| 288 | $filter="(&(objectClass=sambaSAMAccount)(|(sambaAcctFlags=[W ])(sambaAcctFlags=[DW ])(sambaAcctFlags=[I ])(sambaAcctFlags=[S ]))(cn=*".$query."*))"; |
---|
| 289 | $justthese = array("cn","uidNumber","description"); |
---|
| 290 | $search=ldap_search($ldap_conn, $context, $filter, $justthese); |
---|
| 291 | ldap_sort($ldap_conn, $search, "cn"); |
---|
| 292 | $info = ldap_get_entries($ldap_conn, $search); |
---|
| 293 | ldap_close($ldap_conn); |
---|
| 294 | $tmp = array(); |
---|
| 295 | for ($i=0; $i < $info['count']; $i++) |
---|
| 296 | { |
---|
| 297 | $tmp[$i]['cn'] = $info[$i]['cn'][0]; |
---|
| 298 | $tmp[$i]['uidNumber'] = $info[$i]['uidnumber'][0]; |
---|
| 299 | $tmp[$i]['description'] = utf8_decode($info[$i]['description'][0]); |
---|
| 300 | } |
---|
| 301 | return $tmp; |
---|
| 302 | } |
---|
| 303 | } |
---|
| 304 | |
---|
| 305 | function get_organizations($context, $selected='') |
---|
| 306 | { |
---|
| 307 | //echo $selected; |
---|
| 308 | |
---|
| 309 | $first_sector_ufn = ldap_dn2ufn($context); |
---|
| 310 | $first_sector_string = split(",", $first_sector_ufn); |
---|
| 311 | |
---|
| 312 | $s = CreateObject('phpgwapi.sector_search_ldap'); |
---|
| 313 | $sectors_info = $s->sector_search($context); |
---|
| 314 | |
---|
| 315 | $sector_select = ""; |
---|
| 316 | $sector_select .= "<option value='" .$context . "'"; |
---|
| 317 | $sector_select .= ">".strtoupper($first_sector_string[0])."</option>\n"; |
---|
| 318 | |
---|
| 319 | foreach($sectors_info as $sector) |
---|
| 320 | { |
---|
| 321 | if ($sector->sector_level == 1) |
---|
| 322 | { |
---|
| 323 | $sector->sector_name = '+ '.$sector->sector_name; |
---|
| 324 | } |
---|
| 325 | else |
---|
| 326 | { |
---|
| 327 | $sector_space = ''; |
---|
| 328 | for ($i=1; $i < $sector->sector_level; $i++) |
---|
| 329 | $sector_space = '---'.$sector_space; |
---|
| 330 | $sector->sector_name = $sector_space.' '.$sector->sector_name; |
---|
| 331 | } |
---|
| 332 | $sector_select .= '<option value="' . strtolower($sector->sector_context) . '"'; |
---|
| 333 | |
---|
| 334 | if (trim(strtolower($sector->sector_context)) == $selected) |
---|
| 335 | $sector_select .= ' selected>' . $sector->sector_name . "</option>\n"; |
---|
| 336 | else |
---|
| 337 | $sector_select .= '>' . $sector->sector_name . "</option>\n"; |
---|
| 338 | } |
---|
| 339 | //$sector_select .= "</select>"; |
---|
| 340 | return $sector_select; |
---|
| 341 | } |
---|
| 342 | |
---|
[16] | 343 | function get_organizations2($context, $selected='') |
---|
| 344 | { |
---|
| 345 | $dn = $GLOBALS['phpgw_info']['server']['ldap_root_dn']; |
---|
| 346 | $passwd = $GLOBALS['phpgw_info']['server']['ldap_root_pw']; |
---|
| 347 | $ldap_conn = ldap_connect($GLOBALS['phpgw_info']['server']['ldap_host']); |
---|
| 348 | |
---|
| 349 | ldap_set_option($ldap_conn, LDAP_OPT_PROTOCOL_VERSION, 3); |
---|
| 350 | ldap_set_option($ldap_conn, LDAP_OPT_REFERRALS, 0); |
---|
| 351 | ldap_bind($ldap_conn,$dn,$passwd); |
---|
| 352 | |
---|
| 353 | $justthese = array("dn"); |
---|
| 354 | $search=ldap_search($ldap_conn, $context, "ou=*", $justthese); |
---|
| 355 | |
---|
| 356 | ldap_sort($ldap_conn, $search, "ou"); |
---|
| 357 | $info = ldap_get_entries($ldap_conn, $search); |
---|
| 358 | ldap_close($ldap_conn); |
---|
| 359 | |
---|
| 360 | // Retiro o count do array info e inverto o array para ordenação. |
---|
| 361 | for ($i=0; $i<$info["count"]; $i++) |
---|
| 362 | { |
---|
| 363 | $dn = $info[$i]["dn"]; |
---|
| 364 | |
---|
| 365 | // Necessário, pq em uma busca com ldapsearch ou=*, traz tb o próprio ou. |
---|
| 366 | if (strtolower($dn) == $context) |
---|
| 367 | continue; |
---|
| 368 | |
---|
| 369 | $array_dn = ldap_explode_dn ( $dn, 1 ); |
---|
| 370 | |
---|
| 371 | $array_dn_reverse = array_reverse ( $array_dn, true ); |
---|
| 372 | |
---|
| 373 | array_pop ( $array_dn_reverse ); |
---|
| 374 | |
---|
| 375 | $inverted_dn[$dn] = implode ( ".", $array_dn_reverse ); |
---|
| 376 | } |
---|
| 377 | |
---|
| 378 | // Ordenação |
---|
| 379 | natcasesort($inverted_dn); |
---|
| 380 | |
---|
| 381 | // Construção do select |
---|
| 382 | $level = 0; |
---|
| 383 | foreach ($inverted_dn as $dn=>$invert_ufn) |
---|
| 384 | { |
---|
| 385 | $display = ''; |
---|
| 386 | |
---|
| 387 | $array_dn_reverse = explode ( ".", $invert_ufn ); |
---|
| 388 | $array_dn = array_reverse ( $array_dn_reverse, true ); |
---|
| 389 | |
---|
| 390 | $level = count( $array_dn ) - 4; |
---|
| 391 | |
---|
| 392 | if ($level == 0) |
---|
| 393 | $display .= '+'; |
---|
| 394 | else { |
---|
| 395 | for ($i=0; $i<$level; $i++) |
---|
| 396 | $display .= '---'; |
---|
| 397 | } |
---|
| 398 | |
---|
| 399 | reset ( $array_dn ); |
---|
| 400 | $display .= ' ' . (current ( $array_dn ) ); |
---|
| 401 | |
---|
| 402 | $dn = trim(strtolower($dn)); |
---|
| 403 | if ( $dn == $selected ) |
---|
| 404 | $select = ' selected'; |
---|
| 405 | else |
---|
| 406 | $select = ''; |
---|
| 407 | $options .= "<option value='$dn'$select>$display</option>"; |
---|
| 408 | } |
---|
| 409 | |
---|
| 410 | // Cria a primeira entrada na combo |
---|
| 411 | $first_sector_ufn = ldap_dn2ufn($context); |
---|
| 412 | $first_sector_string = split(",", $first_sector_ufn); |
---|
| 413 | $options = "<option value='$context'>" . strtoupper($first_sector_string[0]) . "</option>" . $options; |
---|
| 414 | |
---|
| 415 | return $options; |
---|
| 416 | } |
---|
| 417 | |
---|
[2] | 418 | function get_sectors($context, $selected='') |
---|
| 419 | { |
---|
| 420 | $query = "SELECT sector FROM phpgw_expressoadmin_sectors WHERE organization = '" . $context . "'"; |
---|
| 421 | $GLOBALS['phpgw']->db->query($query); |
---|
| 422 | while($GLOBALS['phpgw']->db->next_record()) |
---|
| 423 | { |
---|
| 424 | $query_result[] = $GLOBALS['phpgw']->db->row(); |
---|
| 425 | } |
---|
| 426 | |
---|
| 427 | if (count($query_result) > 0) |
---|
| 428 | { |
---|
| 429 | foreach ($query_result as $index=>$tmp) |
---|
| 430 | { |
---|
| 431 | $sector = $tmp['sector']; |
---|
| 432 | if ($sector == $selected) |
---|
| 433 | $sector_options .= "<option value='$sector' selected>$sector</option>"; |
---|
| 434 | else |
---|
| 435 | $sector_options .= "<option value='$sector'>$sector</option>"; |
---|
| 436 | } |
---|
| 437 | return $sector_options; |
---|
| 438 | } |
---|
| 439 | else |
---|
| 440 | return false; |
---|
| 441 | } |
---|
| 442 | |
---|
| 443 | // Get list of all levels, this function is used for sectors module. |
---|
| 444 | function get_sectors_list($context) |
---|
| 445 | { |
---|
| 446 | $connection = $GLOBALS['phpgw']->common->ldapConnect(); |
---|
| 447 | ldap_set_option($connection, LDAP_OPT_PROTOCOL_VERSION, 3); |
---|
| 448 | ldap_set_option($connection, LDAP_OPT_REFERRALS, 0); |
---|
| 449 | |
---|
| 450 | if ($connection) |
---|
| 451 | { |
---|
| 452 | $bind=ldap_bind($connection); |
---|
| 453 | $filter="ou=*"; |
---|
| 454 | $justthese = array("ou"); |
---|
| 455 | $search=ldap_list($connection, $context, $filter, $justthese); |
---|
| 456 | ldap_sort($connection ,$search, "ou"); |
---|
| 457 | $info = ldap_get_entries($connection, $search); |
---|
| 458 | for ($i=0; $i<$info["count"]; $i++) |
---|
| 459 | { |
---|
| 460 | $this->level++; |
---|
| 461 | $next_context[$i] = 'ou='.$info[$i]["ou"][0].','.$context; |
---|
| 462 | $obj = new sectors_object($info[$i]["ou"][0], $next_context[$i], $this->level, 'False'); |
---|
| 463 | array_push($this->sectors_list, $obj); |
---|
| 464 | $this->get_sectors_list($next_context[$i]); |
---|
| 465 | } |
---|
| 466 | } |
---|
| 467 | ldap_close($connection); |
---|
| 468 | $this->level--; |
---|
| 469 | return $this->sectors_list; |
---|
| 470 | } |
---|
| 471 | |
---|
| 472 | function exist_account_lid($account_lid) |
---|
| 473 | { |
---|
| 474 | $conection = $GLOBALS['phpgw']->common->ldapConnect(); |
---|
| 475 | $sri = ldap_search($conection, $GLOBALS['phpgw_info']['server']['ldap_context'], "uid=" . $account_lid); |
---|
| 476 | $result = ldap_get_entries($conection, $sri); |
---|
| 477 | return $result['count']; |
---|
| 478 | } |
---|
| 479 | |
---|
| 480 | function exist_email($mail) |
---|
| 481 | { |
---|
| 482 | $conection = $GLOBALS['phpgw']->common->ldapConnect(); |
---|
| 483 | $sri = ldap_search($conection, $GLOBALS['phpgw_info']['server']['ldap_context'], "mail=" . $mail); |
---|
| 484 | $result = ldap_get_entries($conection, $sri); |
---|
| 485 | ldap_close($conection); |
---|
| 486 | |
---|
| 487 | if ($result['count'] == 0) |
---|
| 488 | return false; |
---|
| 489 | else |
---|
| 490 | return true; |
---|
| 491 | } |
---|
| 492 | |
---|
| 493 | function array_invert($array) |
---|
| 494 | { |
---|
| 495 | $result[] = end($array); |
---|
| 496 | while ($item = prev($array)) |
---|
| 497 | $result[] = $item; |
---|
| 498 | return $result; |
---|
| 499 | } |
---|
| 500 | |
---|
| 501 | function get_next_id() |
---|
| 502 | { |
---|
| 503 | // Busco o ID dos accounts |
---|
| 504 | $query_accounts = "SELECT id FROM phpgw_nextid WHERE appname = 'accounts'"; |
---|
| 505 | $GLOBALS['phpgw']->db->query($query_accounts); |
---|
| 506 | while($GLOBALS['phpgw']->db->next_record()) |
---|
| 507 | { |
---|
| 508 | $result_accounts[] = $GLOBALS['phpgw']->db->row(); |
---|
| 509 | } |
---|
| 510 | $accounts_id = $result_accounts[0]['id']; |
---|
| 511 | |
---|
| 512 | // Busco o ID dos groups |
---|
| 513 | $query_groups = "SELECT id FROM phpgw_nextid WHERE appname = 'groups'"; |
---|
| 514 | $GLOBALS['phpgw']->db->query($query_groups); |
---|
| 515 | while($GLOBALS['phpgw']->db->next_record()) |
---|
| 516 | { |
---|
| 517 | $result_groups[] = $GLOBALS['phpgw']->db->row(); |
---|
| 518 | } |
---|
| 519 | $groups_id = $result_groups[0]['id']; |
---|
| 520 | |
---|
| 521 | //Retorna o maior dos ID's |
---|
| 522 | if ($accounts_id >= $groups_id) |
---|
| 523 | return $accounts_id; |
---|
| 524 | else |
---|
| 525 | return $groups_id; |
---|
| 526 | } |
---|
| 527 | |
---|
| 528 | function increment_id($id, $type) |
---|
| 529 | { |
---|
| 530 | $sql = "UPDATE phpgw_nextid set id = '".$id."' WHERE appname = '" . $type . "'"; |
---|
| 531 | $GLOBALS['phpgw']->db->query($sql); |
---|
| 532 | } |
---|
| 533 | |
---|
| 534 | function make_list_app($account_lid, $context, $user_applications, $disabled='') |
---|
| 535 | { |
---|
| 536 | // create list of ALL available apps |
---|
| 537 | $availableAppsGLOBALS = $GLOBALS['phpgw_info']['apps']; |
---|
| 538 | |
---|
| 539 | // create list of available apps for the user |
---|
| 540 | $query = "SELECT * FROM phpgw_expressoadmin_apps WHERE manager_lid = '".$account_lid."' AND context = '".$context."'"; |
---|
| 541 | $GLOBALS['phpgw']->db->query($query); |
---|
| 542 | while($GLOBALS['phpgw']->db->next_record()) |
---|
| 543 | { |
---|
| 544 | $availableApps[] = $GLOBALS['phpgw']->db->row(); |
---|
| 545 | } |
---|
| 546 | |
---|
| 547 | // Retira alguns modulos |
---|
| 548 | if (count($availableApps)) |
---|
| 549 | { |
---|
| 550 | foreach ($availableApps as $key => $value) |
---|
| 551 | { |
---|
| 552 | if ($value['app'] != 'phpgwapi') |
---|
| 553 | $tmp[] = $availableApps[$key]; |
---|
| 554 | } |
---|
| 555 | } |
---|
| 556 | $availableApps = $tmp; |
---|
| 557 | |
---|
| 558 | // Cria um array com as aplicacoes disponiveis para o manager, com as atributos das aplicacoes. |
---|
| 559 | $availableAppsUser = array(); |
---|
| 560 | if (count($availableApps)) |
---|
| 561 | { |
---|
| 562 | foreach($availableApps as $app => $title) |
---|
| 563 | { |
---|
| 564 | if ($availableAppsGLOBALS[$title['app']]) |
---|
| 565 | $availableAppsUser[$title['app']] = $availableAppsGLOBALS[$title['app']]; |
---|
| 566 | } |
---|
| 567 | } |
---|
| 568 | |
---|
| 569 | // Loop para criar dinamicamente uma tabela com 3 colunas, cada coluna com um aplicativo e um check box. |
---|
| 570 | $applications_list = ''; |
---|
| 571 | $app_col1 = ''; |
---|
| 572 | $app_col2 = ''; |
---|
| 573 | $app_col3 = ''; |
---|
| 574 | $total_apps = count($availableAppsUser); |
---|
| 575 | $i = 0; |
---|
| 576 | foreach($availableAppsUser as $app => $data) |
---|
| 577 | { |
---|
| 578 | // 1 coluna |
---|
| 579 | if (($i +1) % 3 == 1) |
---|
| 580 | { |
---|
| 581 | $checked = $user_applications[$app] ? 'CHECKED' : ''; |
---|
| 582 | $app_col1 = sprintf("<td>%s</td><td width='10'><input type='checkbox' name='apps[%s]' value='1' %s %s></td>\n", |
---|
| 583 | $data['title'],$app,$checked, $disabled); |
---|
| 584 | if ($i == ($total_apps-1)) |
---|
| 585 | $applications_list .= sprintf('<tr bgcolor="%s">%s</tr>','#DDDDDD', $app_col1); |
---|
| 586 | } |
---|
| 587 | |
---|
| 588 | // 2 coluna |
---|
| 589 | if (($i +1) % 3 == 2) |
---|
| 590 | { |
---|
| 591 | $checked = $user_applications[$app] ? 'CHECKED' : ''; |
---|
| 592 | $app_col2 = sprintf("<td>%s</td><td width='10'><input type='checkbox' name='apps[%s]' value='1' %s %s></td>\n", |
---|
| 593 | $data['title'],$app,$checked, $disabled); |
---|
| 594 | |
---|
| 595 | if ($i == ($total_apps-1)) |
---|
| 596 | $applications_list .= sprintf('<tr bgcolor="%s">%s%s</tr>','#DDDDDD', $app_col1,$app_col2); |
---|
| 597 | } |
---|
| 598 | // 3 coluna |
---|
| 599 | if (($i +1) % 3 == 0) |
---|
| 600 | { |
---|
| 601 | $checked = $user_applications[$app] ? 'CHECKED' : ''; |
---|
| 602 | $app_col3 = sprintf("<td>%s</td><td width='10'><input type='checkbox' name='apps[%s]' value='1' %s %s></td>\n", |
---|
| 603 | $data['title'],$app,$checked, $disabled); |
---|
| 604 | |
---|
| 605 | // Cria nova linha |
---|
| 606 | $applications_list .= sprintf('<tr bgcolor="%s">%s%s%s</tr>','#DDDDDD', $app_col1, $app_col2, $app_col3); |
---|
| 607 | } |
---|
| 608 | $i++; |
---|
| 609 | } |
---|
| 610 | return $applications_list; |
---|
| 611 | } |
---|
| 612 | |
---|
| 613 | function exist_attribute_in_ldap($dn, $attribute, $value) |
---|
| 614 | { |
---|
| 615 | $connection = $GLOBALS['phpgw']->common->ldapConnect(); |
---|
| 616 | $search = ldap_search($connection, $dn, $attribute. "=" . $value); |
---|
| 617 | $result = ldap_get_entries($connection, $search); |
---|
| 618 | ldap_close($connection); |
---|
| 619 | //_debug_array($result); |
---|
| 620 | if ($result['count'] == 0) |
---|
| 621 | return false; |
---|
| 622 | else |
---|
| 623 | return true; |
---|
| 624 | } |
---|
| 625 | |
---|
| 626 | function getReturnExecuteForm(){ |
---|
| 627 | $response = $_SESSION['response']; |
---|
| 628 | $_SESSION['response'] = null; |
---|
| 629 | return $response; |
---|
| 630 | } |
---|
| 631 | |
---|
| 632 | function write_log2($action, $groupinfo='', $userinfo='', $appinfo='', $msg_log='') |
---|
| 633 | { |
---|
| 634 | $sql = "INSERT INTO phpgw_expressoadmin_log (date, manager, action, groupinfo, userinfo, appinfo, msg) " |
---|
| 635 | . "VALUES('now','" . $_SESSION['phpgw_info']['expresso']['user']['account_lid'] . "','" . strtolower($action) . "','" . strtolower($groupinfo) . "','" . strtolower($userinfo) . "','" . strtolower($appinfo) . "','" .strtolower($msg_log) . "')"; |
---|
| 636 | $GLOBALS['phpgw']->db->query($sql); |
---|
| 637 | return; |
---|
| 638 | } |
---|
| 639 | |
---|
| 640 | } |
---|
| 641 | |
---|
| 642 | class sectors_object |
---|
| 643 | { |
---|
| 644 | var $sector_name; |
---|
| 645 | var $sector_context; |
---|
| 646 | var $sector_level; |
---|
| 647 | var $sector_leaf; |
---|
| 648 | var $sectors_list = array(); |
---|
| 649 | var $level; |
---|
| 650 | |
---|
| 651 | function sectors_object($sector_name, $sector_context, $sector_level, $sector_leaf) |
---|
| 652 | { |
---|
| 653 | $this->sector_name = $sector_name; |
---|
| 654 | $this->sector_context = $sector_context; |
---|
| 655 | $this->sector_level = $sector_level; |
---|
| 656 | $this->sector_leaf = $sector_leaf; |
---|
| 657 | } |
---|
| 658 | } |
---|