Guest User

Untitled

a guest
Jun 23rd, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.79 KB | None | 0 0
  1. <?php
  2. public function viewlist() {
  3.  
  4. //first, lets get our default branch and agency, based on the logged in user
  5. $LoggedInUser = $this->Member;
  6.  
  7. if(Permission::check("ACCESS_BRANCH_ADMINISTRATION")) {
  8. $branchId = $LoggedInUser->Branch()->ID;
  9. $travelAgencyId = $LoggedInUser->Branch()->TravelAgency()->ID;
  10. }
  11. if(Permission::check("ACCESS_AGENCY_ADMINISTRATION")) {
  12. $branchId = null;
  13. $travelAgencyId = $LoggedInUser->Branch()->TravelAgency()->ID;
  14. }
  15. if(Permission::check("ADMIN")) {
  16. $branchId = null;
  17. $travelAgencyId = null;
  18. }
  19.  
  20. //now, we might have added a filter
  21. $travelAgencyId = (isset($this->requestParams['travelAgencyId'])) ? $this->requestParams['travelAgencyId'] : $travelAgencyId;
  22. $branchId = (isset($this->requestParams['branchId'])) ? $this->requestParams['branchId'] : $branchId;
  23.  
  24. //lets make sure these requested options actually exist
  25. if($branchId) {
  26. $Branch = Branch::getById($branchId);
  27. if(!$Branch) return $this->forTemplate("DataObjectAccessError");
  28. }
  29. if($travelAgencyId) {
  30. $TravelAgency = TravelAgency::getById($travelAgencyId);
  31. if(!$TravelAgency) return $this->forTemplate("DataObjectAccessError");
  32. }
  33.  
  34. //now lets check to make sure we actually have access
  35. if(! (UserRole::checkAccessPermission($LoggedInUser->ID, $branchId, null) ||
  36. UserRole::checkAccessPermission($LoggedInUser->ID, null, $travelAgencyId)))
  37. {
  38. return $this->forTemplate("PermissionFailure");
  39. }
  40.  
  41. //lets grab all the other URL paramaters, or set them as null if they dont exist
  42.  
  43. $firstName = (isset($this->requestParams['firstName'])) ? $this->requestParams['firstName'] : null;
  44. $surname = (isset($this->requestParams['surname'])) ? $this->requestParams['surname'] : null;
  45. $email = (isset($this->requestParams['email'])) ? $this->requestParams['email'] : null;
  46. $phoneNumber = (isset($this->requestParams['phonenumber'])) ? $this->requestParams['phonenumber'] : null;
  47. $fax = (isset($this->requestParams['fax'])) ? $this->requestParams['fax'] : null;
  48.  
  49. $orderByColumn = (isset($this->requestParams['orderByColumn'])) ? $this->requestParams['orderByColumn'] : null;
  50. $orderByType = (isset($this->requestParams['orderByType'])) ? $this->requestParams['orderByType'] : null;
  51. $itemStart = (isset($this->requestParams['start'])) ? $this->requestParams['start'] : null;
  52. $itemQuantity = (isset($this->requestParams['itemQuantity'])) ? $this->requestParams['itemQuantity'] : null;
  53.  
  54.  
  55. //now lets build the form
  56. $Branches = Branch::getList();
  57. $BranchesMap = $Branches->toDropDownMap();
  58. $BranchesDropdown = new DropdownField('branchId', 'Branch', $BranchesMap, $branchId);
  59. $BranchesDropdown->setHasEmptyDefault(true);
  60.  
  61. $TravelAgencies = TravelAgency::getList();
  62. $TravelAgenciesMap = $TravelAgencies->toDropDownMap();
  63. $TravelAgenciesDropdown = new DropdownField('travelAgencyId', 'Travel Agency', $TravelAgenciesMap, $travelAgencyId);
  64. $TravelAgenciesDropdown->setHasEmptyDefault(true);
  65.  
  66. $fields = new FieldSet(
  67. new TextField("firstName", "First Name"),
  68. new TextField("surname", "Last Name"),
  69. new TextField("email", "Email"),
  70. new TextField("phonenumber", "Phone Number"),
  71. new TextField("fax", "Fax"),
  72. $BranchesDropdown,
  73. $TravelAgenciesDropdown
  74. );
  75.  
  76. $actions = new FieldSet(new FormAction('searchUsers', 'Search Users'));
  77.  
  78. $this->SearchUsersForm = new Form($this, 'viewlist', $fields, $actions);
  79.  
  80. //now let's pass all that data to the function that grabs all the information and drops it into a DataObjectSet
  81. $Users = UserRole::getList($branchId, $travelAgencyId, $firstName, $surname, $email, $phoneNumber, $fax, $orderByColumn, $orderByType, $itemStart, $itemQuantity);
  82.  
  83. $this->Users = $Users;
  84.  
  85. return $this->forTemplate("Users");
  86.  
  87. }
  88.  
  89. ?>
Add Comment
Please, Sign In to add comment