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,7 +12,12 @@ require_once("$default->owl_fs_root/lib/class.AuthLdap.php"); | ||
| 12 | * @author Mukhtar Dharsey | 12 | * @author Mukhtar Dharsey |
| 13 | * @package dmslib | 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 | * Handle to the ldap util class | 23 | * Handle to the ldap util class |
| @@ -29,7 +34,8 @@ class UserManager { | @@ -29,7 +34,8 @@ class UserManager { | ||
| 29 | * @return array | 34 | * @return array |
| 30 | * returns an array containing the users found | 35 | * returns an array containing the users found |
| 31 | */ | 36 | */ |
| 32 | - function listLdapUsers($userNameSearch) { | 37 | + function listLdapUsers($userNameSearch) |
| 38 | + { | ||
| 33 | global $default; | 39 | global $default; |
| 34 | 40 | ||
| 35 | // user attributes to search for | 41 | // user attributes to search for |
| @@ -40,19 +46,25 @@ class UserManager { | @@ -40,19 +46,25 @@ class UserManager { | ||
| 40 | $ldap->server = $server; | 46 | $ldap->server = $server; |
| 41 | $ldap->dn = $default->ldapRootDn; | 47 | $ldap->dn = $default->ldapRootDn; |
| 42 | 48 | ||
| 43 | - if ( $ldap->connect()) { | 49 | + if ( $ldap->connect()) |
| 50 | + { | ||
| 44 | // search for the users | 51 | // search for the users |
| 45 | // append and prepend wildcards | 52 | // append and prepend wildcards |
| 46 | $userArray = $ldap->getUsers("*" . $userNameSearch . "*", $attributes); | 53 | $userArray = $ldap->getUsers("*" . $userNameSearch . "*", $attributes); |
| 47 | - if ($userArray) { | 54 | + if ($userArray) |
| 55 | + { | ||
| 48 | // return the array | 56 | // return the array |
| 49 | return $userArray; | 57 | return $userArray; |
| 50 | - } else { | 58 | + } |
| 59 | + else | ||
| 60 | + { | ||
| 51 | // the search failed, bail | 61 | // the search failed, bail |
| 52 | return false; | 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 | return false; | 68 | return false; |
| 57 | } | 69 | } |
| 58 | } | 70 | } |
| @@ -165,7 +177,8 @@ class UserManager { | @@ -165,7 +177,8 @@ class UserManager { | ||
| 165 | * @return boolean | 177 | * @return boolean |
| 166 | * True if the deletion was successful, else false if not or nonexistant. | 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 | global $default; | 182 | global $default; |
| 170 | // create a connection | 183 | // create a connection |
| 171 | $sql = new Owl_DB; | 184 | $sql = new Owl_DB; |
| @@ -266,7 +279,8 @@ class UserManager { | @@ -266,7 +279,8 @@ class UserManager { | ||
| 266 | * @return array | 279 | * @return array |
| 267 | * An array of usernames | 280 | * An array of usernames |
| 268 | */ | 281 | */ |
| 269 | - function listUsers(){ | 282 | + function listUsers() |
| 283 | + { | ||
| 270 | 284 | ||
| 271 | global $default; | 285 | global $default; |
| 272 | $users = array (); | 286 | $users = array (); |
| @@ -359,7 +373,7 @@ class UserManager { | @@ -359,7 +373,7 @@ class UserManager { | ||
| 359 | $sql = new Owl_DB; | 373 | $sql = new Owl_DB; |
| 360 | 374 | ||
| 361 | //do validation that userid exists | 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 | $result = $sql->query($query); | 377 | $result = $sql->query($query); |
| 364 | $row = $sql->num_rows($result); | 378 | $row = $sql->num_rows($result); |
| 365 | 379 | ||
| @@ -370,7 +384,7 @@ class UserManager { | @@ -370,7 +384,7 @@ class UserManager { | ||
| 370 | } | 384 | } |
| 371 | 385 | ||
| 372 | //add user to the table | 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 | $result = $sql->query($query); | 388 | $result = $sql->query($query); |
| 375 | 389 | ||
| 376 | if(!'result') | 390 | if(!'result') |
| @@ -404,7 +418,7 @@ class UserManager { | @@ -404,7 +418,7 @@ class UserManager { | ||
| 404 | $sql = new Owl_DB; | 418 | $sql = new Owl_DB; |
| 405 | 419 | ||
| 406 | //do validation that userid exists | 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 | $result = $sql->query($query); | 422 | $result = $sql->query($query); |
| 409 | $row = $sql->num_rows($result); | 423 | $row = $sql->num_rows($result); |
| 410 | 424 | ||
| @@ -416,7 +430,7 @@ class UserManager { | @@ -416,7 +430,7 @@ class UserManager { | ||
| 416 | } | 430 | } |
| 417 | 431 | ||
| 418 | //if user id exists delete it from the users table | 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 | $result = $sql->query($query); | 434 | $result = $sql->query($query); |
| 421 | 435 | ||
| 422 | if(!'result') | 436 | if(!'result') |
| @@ -447,7 +461,7 @@ class UserManager { | @@ -447,7 +461,7 @@ class UserManager { | ||
| 447 | $sql = new Owl_DB; | 461 | $sql = new Owl_DB; |
| 448 | 462 | ||
| 449 | //do validation that userid exists | 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 | $result = $sql->query($query); | 465 | $result = $sql->query($query); |
| 452 | $row = $sql->num_rows($result); | 466 | $row = $sql->num_rows($result); |
| 453 | 467 | ||
| @@ -459,7 +473,7 @@ class UserManager { | @@ -459,7 +473,7 @@ class UserManager { | ||
| 459 | } | 473 | } |
| 460 | 474 | ||
| 461 | //if user id exists delete it from the users table | 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 | $result = $sql->query($query); | 477 | $result = $sql->query($query); |
| 464 | 478 | ||
| 465 | if(!'result') | 479 | if(!'result') |
| @@ -475,14 +489,18 @@ class UserManager { | @@ -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 | * @param $username | 498 | * @param $username |
| 482 | * The username for which we want its ID | 499 | * The username for which we want its ID |
| 483 | * @return Integer | 500 | * @return Integer |
| 484 | * The username's Id | 501 | * The username's Id |
| 485 | */ | 502 | */ |
| 503 | + | ||
| 486 | function getUserID($username) | 504 | function getUserID($username) |
| 487 | { | 505 | { |
| 488 | global $default; | 506 | global $default; |
| @@ -504,7 +522,7 @@ class UserManager { | @@ -504,7 +522,7 @@ class UserManager { | ||
| 504 | if ($rows == 0) | 522 | if ($rows == 0) |
| 505 | { | 523 | { |
| 506 | // duplicate username | 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 | $default->log->debug($default->errorMessage); | 526 | $default->log->debug($default->errorMessage); |
| 509 | return false; | 527 | return false; |
| 510 | } | 528 | } |
| @@ -513,6 +531,92 @@ class UserManager { | @@ -513,6 +531,92 @@ class UserManager { | ||
| 513 | return $id; | 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 | ?> |