Commit ef15281fcbcd5eea2d0a629cc4bf1891985f86a5
1 parent
8aa2f0a1
added group details for specific user
git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@254 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
1 changed file
with
122 additions
and
18 deletions
lib/administration/UserManager.inc
| ... | ... | @@ -12,7 +12,12 @@ require_once("$default->owl_fs_root/lib/class.AuthLdap.php"); |
| 12 | 12 | * @author Mukhtar Dharsey |
| 13 | 13 | * @package dmslib |
| 14 | 14 | */ |
| 15 | -class UserManager { | |
| 15 | + | |
| 16 | +//common admin functions that dont really form part of class | |
| 17 | +require ("$default->owl_fs_root/lib/administration/adminLib.inc"); | |
| 18 | + | |
| 19 | +class UserManager | |
| 20 | + { | |
| 16 | 21 | |
| 17 | 22 | /** |
| 18 | 23 | * Handle to the ldap util class |
| ... | ... | @@ -29,7 +34,8 @@ class UserManager { |
| 29 | 34 | * @return array |
| 30 | 35 | * returns an array containing the users found |
| 31 | 36 | */ |
| 32 | - function listLdapUsers($userNameSearch) { | |
| 37 | + function listLdapUsers($userNameSearch) | |
| 38 | + { | |
| 33 | 39 | global $default; |
| 34 | 40 | |
| 35 | 41 | // user attributes to search for |
| ... | ... | @@ -40,19 +46,25 @@ class UserManager { |
| 40 | 46 | $ldap->server = $server; |
| 41 | 47 | $ldap->dn = $default->ldapRootDn; |
| 42 | 48 | |
| 43 | - if ( $ldap->connect()) { | |
| 49 | + if ( $ldap->connect()) | |
| 50 | + { | |
| 44 | 51 | // search for the users |
| 45 | 52 | // append and prepend wildcards |
| 46 | 53 | $userArray = $ldap->getUsers("*" . $userNameSearch . "*", $attributes); |
| 47 | - if ($userArray) { | |
| 54 | + if ($userArray) | |
| 55 | + { | |
| 48 | 56 | // return the array |
| 49 | 57 | return $userArray; |
| 50 | - } else { | |
| 58 | + } | |
| 59 | + else | |
| 60 | + { | |
| 51 | 61 | // the search failed, bail |
| 52 | 62 | return false; |
| 53 | 63 | } |
| 54 | - } else { | |
| 55 | - $_SESSION["errorMessage"] = "LDAP error: (" . $ldap->ldapErrorCode ") " . $ldap->ldapErrorText; | |
| 64 | + } | |
| 65 | + else | |
| 66 | + { | |
| 67 | + // $_SESSION["errorMessage"] = "LDAP error: (" . $ldap->ldapErrorCode ") " . $ldap->ldapErrorText; | |
| 56 | 68 | return false; |
| 57 | 69 | } |
| 58 | 70 | } |
| ... | ... | @@ -165,7 +177,8 @@ class UserManager { |
| 165 | 177 | * @return boolean |
| 166 | 178 | * True if the deletion was successful, else false if not or nonexistant. |
| 167 | 179 | */ |
| 168 | - function removeUser($userID) { | |
| 180 | + function removeUser($userID) | |
| 181 | + { | |
| 169 | 182 | global $default; |
| 170 | 183 | // create a connection |
| 171 | 184 | $sql = new Owl_DB; |
| ... | ... | @@ -266,7 +279,8 @@ class UserManager { |
| 266 | 279 | * @return array |
| 267 | 280 | * An array of usernames |
| 268 | 281 | */ |
| 269 | - function listUsers(){ | |
| 282 | + function listUsers() | |
| 283 | + { | |
| 270 | 284 | |
| 271 | 285 | global $default; |
| 272 | 286 | $users = array (); |
| ... | ... | @@ -359,7 +373,7 @@ class UserManager { |
| 359 | 373 | $sql = new Owl_DB; |
| 360 | 374 | |
| 361 | 375 | //do validation that userid exists |
| 362 | - $query = "SELECT * FROM $default->owl_user_group_table WHERE user_id = $userID AND group_id = $groupID"; | |
| 376 | + $query = "SELECT * FROM $default->owl_users_groups_table WHERE user_id = $userID AND group_id = $groupID"; | |
| 363 | 377 | $result = $sql->query($query); |
| 364 | 378 | $row = $sql->num_rows($result); |
| 365 | 379 | |
| ... | ... | @@ -370,7 +384,7 @@ class UserManager { |
| 370 | 384 | } |
| 371 | 385 | |
| 372 | 386 | //add user to the table |
| 373 | - $query = "INSERT INTO $default->owl_user_group_table (user_id, group_id) VALUES($userID, $groupID)" ; | |
| 387 | + $query = "INSERT INTO $default->owl_users_groups_table (user_id, group_id) VALUES($userID, $groupID)" ; | |
| 374 | 388 | $result = $sql->query($query); |
| 375 | 389 | |
| 376 | 390 | if(!'result') |
| ... | ... | @@ -404,7 +418,7 @@ class UserManager { |
| 404 | 418 | $sql = new Owl_DB; |
| 405 | 419 | |
| 406 | 420 | //do validation that userid exists |
| 407 | - $query = "SELECT * FROM $default->owl_user_group_table WHERE user_id = $userID AND group_id = $groupID"; | |
| 421 | + $query = "SELECT * FROM $default->owl_users_groups_table WHERE user_id = $userID AND group_id = $groupID"; | |
| 408 | 422 | $result = $sql->query($query); |
| 409 | 423 | $row = $sql->num_rows($result); |
| 410 | 424 | |
| ... | ... | @@ -416,7 +430,7 @@ class UserManager { |
| 416 | 430 | } |
| 417 | 431 | |
| 418 | 432 | //if user id exists delete it from the users table |
| 419 | - $query = "DELETE FROM $default->owl_user_group_table WHERE user_id = $userID AND group_id = $groupID"; | |
| 433 | + $query = "DELETE FROM $default->owl_users_groups_table WHERE user_id = $userID AND group_id = $groupID"; | |
| 420 | 434 | $result = $sql->query($query); |
| 421 | 435 | |
| 422 | 436 | if(!'result') |
| ... | ... | @@ -447,7 +461,7 @@ class UserManager { |
| 447 | 461 | $sql = new Owl_DB; |
| 448 | 462 | |
| 449 | 463 | //do validation that userid exists |
| 450 | - $query = "SELECT * FROM $default->owl_user_group_table WHERE user_id = $userID"; | |
| 464 | + $query = "SELECT * FROM $default->owl_users_groups_table WHERE user_id = $userID"; | |
| 451 | 465 | $result = $sql->query($query); |
| 452 | 466 | $row = $sql->num_rows($result); |
| 453 | 467 | |
| ... | ... | @@ -459,7 +473,7 @@ class UserManager { |
| 459 | 473 | } |
| 460 | 474 | |
| 461 | 475 | //if user id exists delete it from the users table |
| 462 | - $query = "DELETE FROM $default->owl_user_group_table WHERE user_id = $userID"; | |
| 476 | + $query = "DELETE FROM $default->owl_users_groups_table WHERE user_id = $userID"; | |
| 463 | 477 | $result = $sql->query($query); |
| 464 | 478 | |
| 465 | 479 | if(!'result') |
| ... | ... | @@ -475,14 +489,18 @@ class UserManager { |
| 475 | 489 | |
| 476 | 490 | } |
| 477 | 491 | |
| 478 | - /** | |
| 479 | - * Adds a user to the unit. | |
| 492 | + | |
| 493 | + /* | |
| 494 | + * Function getUserID($username) | |
| 495 | + * | |
| 496 | + * gets the id of a user using their username | |
| 480 | 497 | * |
| 481 | 498 | * @param $username |
| 482 | 499 | * The username for which we want its ID |
| 483 | 500 | * @return Integer |
| 484 | 501 | * The username's Id |
| 485 | 502 | */ |
| 503 | + | |
| 486 | 504 | function getUserID($username) |
| 487 | 505 | { |
| 488 | 506 | global $default; |
| ... | ... | @@ -504,7 +522,7 @@ class UserManager { |
| 504 | 522 | if ($rows == 0) |
| 505 | 523 | { |
| 506 | 524 | // duplicate username |
| 507 | - $default->errorMessage = "UserManagerThe username " . $username . " does not exist<br>"; | |
| 525 | + $default->errorMessage = "UserManager::The username " . $username . " does not exist<br>"; | |
| 508 | 526 | $default->log->debug($default->errorMessage); |
| 509 | 527 | return false; |
| 510 | 528 | } |
| ... | ... | @@ -513,6 +531,92 @@ class UserManager { |
| 513 | 531 | return $id; |
| 514 | 532 | } |
| 515 | 533 | } |
| 534 | + | |
| 535 | + /* | |
| 536 | + * Function getGroups($userID) | |
| 537 | + * | |
| 538 | + * Gets the group that the user belongs to | |
| 539 | + * | |
| 540 | + * @param $userID | |
| 541 | + * The ID of the user | |
| 542 | + * @return Array | |
| 543 | + * array of groupID's and name | |
| 544 | + */ | |
| 545 | + function getGroups($userID) | |
| 546 | + { | |
| 547 | + global $default; | |
| 548 | + $groups = array(); | |
| 549 | + $sql = new Owl_DB; | |
| 550 | + | |
| 551 | + | |
| 552 | + // check that username exists if it does'nt return false | |
| 553 | + $query = "SELECT group_id FROM $default->owl_users_groups_table WHERE user_id = '" . $userID . "'"; | |
| 554 | + $sql->query($query); | |
| 555 | + $rows = $sql->num_rows($sql); | |
| 556 | + | |
| 557 | + // if no entry..user does not belong to any groups | |
| 558 | + if ($rows == 0) | |
| 559 | + { | |
| 560 | + // duplicate username | |
| 561 | + $default->errorMessage = "UserManager::The user does not belong to any groups<br>"; | |
| 562 | + $default->log->debug($default->errorMessage); | |
| 563 | + return false; | |
| 564 | + } | |
| 565 | + | |
| 566 | + $i =0; | |
| 567 | + | |
| 568 | + while($sql->next_record()) | |
| 569 | + { | |
| 570 | + $groups[$i] = array("id" => $sql->f("group_id"), | |
| 571 | + "name" => $this->getGroupName($sql->f("group_id")) | |
| 572 | + ); | |
| 573 | + $i++; | |
| 574 | + } | |
| 575 | + | |
| 576 | + return $groups; | |
| 577 | + } | |
| 578 | + | |
| 579 | + /* | |
| 580 | + * Function getGroupName($groupID) | |
| 581 | + * | |
| 582 | + * gets the id of a user using their username | |
| 583 | + * | |
| 584 | + * @param $username | |
| 585 | + * The username for which we want its ID | |
| 586 | + * @return char | |
| 587 | + * name of group | |
| 588 | + */ | |
| 589 | + | |
| 590 | + function getGroupName($groupID) | |
| 591 | + { | |
| 592 | + global $default; | |
| 593 | + | |
| 594 | + $sql = new Owl_DB; | |
| 595 | + | |
| 596 | + | |
| 597 | + // check that username exists if it does'nt return false | |
| 598 | + $query = "SELECT name FROM $default->owl_groups_table WHERE id = '" . $groupID . "'"; | |
| 599 | + $sql->query($query); | |
| 600 | + $rows = $sql->num_rows($sql); | |
| 601 | + // go into record set | |
| 602 | + $sql->next_record(); | |
| 603 | + | |
| 604 | + // store the id in a variable | |
| 605 | + $name = $sql->f("name"); | |
| 606 | + | |
| 607 | + // if no entry..group name does'nt exist | |
| 608 | + if ($rows == 0) | |
| 609 | + { | |
| 610 | + // duplicate username | |
| 611 | + $default->errorMessage = "UserManager::The group does not exist<br>"; | |
| 612 | + $default->log->debug($default->errorMessage); | |
| 613 | + return false; | |
| 614 | + } | |
| 615 | + else | |
| 616 | + { | |
| 617 | + return $name; | |
| 618 | + } | |
| 619 | + } | |
| 516 | 620 | |
| 517 | 621 | } |
| 518 | 622 | ?> | ... | ... |