Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- public function viewlist() {
- //first, lets get our default branch and agency, based on the logged in user
- $LoggedInUser = $this->Member;
- if(Permission::check("ACCESS_BRANCH_ADMINISTRATION")) {
- $branchId = $LoggedInUser->Branch()->ID;
- $travelAgencyId = $LoggedInUser->Branch()->TravelAgency()->ID;
- }
- if(Permission::check("ACCESS_AGENCY_ADMINISTRATION")) {
- $branchId = null;
- $travelAgencyId = $LoggedInUser->Branch()->TravelAgency()->ID;
- }
- if(Permission::check("ADMIN")) {
- $branchId = null;
- $travelAgencyId = null;
- }
- //now, we might have added a filter
- $travelAgencyId = (isset($this->requestParams['travelAgencyId'])) ? $this->requestParams['travelAgencyId'] : $travelAgencyId;
- $branchId = (isset($this->requestParams['branchId'])) ? $this->requestParams['branchId'] : $branchId;
- //lets make sure these requested options actually exist
- if($branchId) {
- $Branch = Branch::getById($branchId);
- if(!$Branch) return $this->forTemplate("DataObjectAccessError");
- }
- if($travelAgencyId) {
- $TravelAgency = TravelAgency::getById($travelAgencyId);
- if(!$TravelAgency) return $this->forTemplate("DataObjectAccessError");
- }
- //now lets check to make sure we actually have access
- if(! (UserRole::checkAccessPermission($LoggedInUser->ID, $branchId, null) ||
- UserRole::checkAccessPermission($LoggedInUser->ID, null, $travelAgencyId)))
- {
- return $this->forTemplate("PermissionFailure");
- }
- //lets grab all the other URL paramaters, or set them as null if they dont exist
- $firstName = (isset($this->requestParams['firstName'])) ? $this->requestParams['firstName'] : null;
- $surname = (isset($this->requestParams['surname'])) ? $this->requestParams['surname'] : null;
- $email = (isset($this->requestParams['email'])) ? $this->requestParams['email'] : null;
- $phoneNumber = (isset($this->requestParams['phonenumber'])) ? $this->requestParams['phonenumber'] : null;
- $fax = (isset($this->requestParams['fax'])) ? $this->requestParams['fax'] : null;
- $orderByColumn = (isset($this->requestParams['orderByColumn'])) ? $this->requestParams['orderByColumn'] : null;
- $orderByType = (isset($this->requestParams['orderByType'])) ? $this->requestParams['orderByType'] : null;
- $itemStart = (isset($this->requestParams['start'])) ? $this->requestParams['start'] : null;
- $itemQuantity = (isset($this->requestParams['itemQuantity'])) ? $this->requestParams['itemQuantity'] : null;
- //now lets build the form
- $Branches = Branch::getList();
- $BranchesMap = $Branches->toDropDownMap();
- $BranchesDropdown = new DropdownField('branchId', 'Branch', $BranchesMap, $branchId);
- $BranchesDropdown->setHasEmptyDefault(true);
- $TravelAgencies = TravelAgency::getList();
- $TravelAgenciesMap = $TravelAgencies->toDropDownMap();
- $TravelAgenciesDropdown = new DropdownField('travelAgencyId', 'Travel Agency', $TravelAgenciesMap, $travelAgencyId);
- $TravelAgenciesDropdown->setHasEmptyDefault(true);
- $fields = new FieldSet(
- new TextField("firstName", "First Name"),
- new TextField("surname", "Last Name"),
- new TextField("email", "Email"),
- new TextField("phonenumber", "Phone Number"),
- new TextField("fax", "Fax"),
- $BranchesDropdown,
- $TravelAgenciesDropdown
- );
- $actions = new FieldSet(new FormAction('searchUsers', 'Search Users'));
- $this->SearchUsersForm = new Form($this, 'viewlist', $fields, $actions);
- //now let's pass all that data to the function that grabs all the information and drops it into a DataObjectSet
- $Users = UserRole::getList($branchId, $travelAgencyId, $firstName, $surname, $email, $phoneNumber, $fax, $orderByColumn, $orderByType, $itemStart, $itemQuantity);
- $this->Users = $Users;
- return $this->forTemplate("Users");
- }
- ?>
Add Comment
Please, Sign In to add comment