/**
  * function __construct
  * <pre>
  * Initialize the object.
  * </pre>
  * @param $pathModuleRoot [STRING] The path to the module's root dir.
  * @param $viewer [OBJECT] The viewer object.
  * @param $sortBy [STRING] Field data to sort listManager by.
  * @param $managerInit [INTEGER] Initialization value for the listManager.
  * @return [void]
  */
 function __construct($pathModuleRoot, $viewer, $sortBy)
 {
     parent::__construct(page_ViewGroups::DISPLAY_FIELDS);
     $this->pathModuleRoot = $pathModuleRoot;
     $this->viewer = $viewer;
     //Get person ID
     $accessManager = new RowManager_AccessManager();
     $accessManager->loadByViewerID($this->viewer->getViewerID());
     $this->personID = $accessManager->getPersonID();
     echo "ViewerID: " . $this->viewer->getViewerID() . " <br>personID: " . $this->personID . "<br>";
     /*
      * The code below contains the different permission cases for view groups.
      * 
      * Check 1 = check if the user is a SUPER ADMIN
      * Check 2 = check if the user is a STAFF and which campuses he/she is assigned to, taken from HRDB
      * Check 3 =check cim_sch_permissionCampusAdmin for which CAMPUSES this user is ADMIN for
      * Check 4 = check cim_sch_permissionGroupAdmin for which GROUPS this user is ADMIN for
      * If check 1-4 FAIL then ViewGroup will show nothing. (This user is a normal user and have not created any groups .
      */
     $multiTableManager = new MultiTableManager();
     $groupManager = new RowManager_GroupManager();
     $superAdminManager = new RowManager_PermissionsSuperAdminManager();
     //SUPER ADMIN
     //Check if user's Viewer_id is in the PermissionSuperAdmin table
     if ($superAdminManager->loadByViewerID($this->viewer->getViewerID())) {
         // the viewer is a super admin
         echo "ViewerID[" . $this->viewer->getViewerID() . "] is a super admin<br/>";
         $campusGroupManager = new RowManager_CampusGroupManager();
         $multiTableManager->addRowManager($groupManager);
         $multiTableManager->addRowManager($campusGroupManager, new JoinPair($campusGroupManager->getJoinOnGroupID(), $groupManager->getJoinOnGroupID(), JOIN_TYPE_LEFT));
     } else {
         //STAFF
         // This array stores all the campuses associated to the user.
         //This array is continually populated
         $campusArray = array();
         //check HRDB if the user is a staff
         $assignmentManager = new RowManager_AssignmentsManager();
         $assignmentManager->setPersonID($this->personID);
         $assignmentManager->setAssignmentStatus(CA_STAFF);
         $assList = new ListIterator($assignmentManager);
         $assList->setFirst();
         while ($assList->moveNext()) {
             $assMan = $assList->getCurrent(new RowManager_AssignmentsManager());
             //for each campuses found, store in array
             $campusArray[] = $assMan->getCampusID();
         }
         //CAMPUS ADMIN
         //Check cim_sch_permissionsCampusAdmin for the viewer id of the user
         $permissionsCampusAdmin = new RowManager_PermissionsCampusAdminManager();
         $permissionsCampusAdmin->setViewerID($this->viewer->getViewerID());
         $campusAdminList = new ListIterator($permissionsCampusAdmin);
         $campusAdminList->setFirst();
         while ($campusAdminList->moveNext()) {
             $permCampus = $campusAdminList->getCurrent(new RowManager_PermissionsCampusAdminManager());
             //for each campuses found, store in array
             $campusArray[] = $permCampus->getCampusID();
         }
         //remove any duplicate campus ID in the array
         $campusArray = array_unique($campusArray);
         //GROUP ADMIN
         $permissionsGroupAdminManager = new RowManager_PermissionsGroupAdminManager();
         $campusGroupManager = new RowManager_CampusGroupManager();
         //send a list of campues and the viewer ID to constrict the search condition
         //The Viewer_id is use to check the cim_sch_permissionsGroupAdmin table for
         // groups that were created by the user
         $searchCond = $campusGroupManager->returnSearchCondition($campusArray, $this->viewer->getViewerID());
         //create the appropriate join between 3 tables
         //Join cim_sch_group and cim_sch_permissionsGroupAdmin and cim_sch_campusGroup
         $multiTableManager->addRowManager($groupManager);
         $multiTableManager->addRowManager($campusGroupManager, new JoinPair($campusGroupManager->getJoinOnGroupID(), $groupManager->getJoinOnGroupID(), JOIN_TYPE_LEFT));
         $multiTableManager->addRowManager($permissionsGroupAdminManager, new JoinPair($permissionsGroupAdminManager->getJoinOnGroupID(), $groupManager->getJoinOnGroupID(), JOIN_TYPE_LEFT));
         $multiTableManager->addSearchCondition($searchCond);
     }
     /*Case 3: Group Admin - access to an individual group and can create other group admins 
     				(ex. DGL)
     				Normal User - can only submit schedule, assume this unless given other permissions
     					Check the group admin table 
     	
     				check cim_sch_permissiongroupadmin -> cim_sch_campusgroup -> cim_sch_group
     				filter on viewer id 
     
     
     		Case 4: All staff - implicit access to all groups on all campuses where their status is staff 
     				check cim_hrdb_staff table
     					if true
     						get all campuses from cim_hrdb_assignment where assignment status id = 3
     
     
             */
     /*$groupManager = new RowManager_GroupManager();
       $multiTableManager = new MultiTableManager();
       
       $campusGroupManager = new RowManager_CampusGroupManager();
       
       $multiTableManager->addRowManager( $campusGroupManager );
       $multiTableManager->addRowManager( $groupManager, new JoinPair( $campusGroupManager->getJoinOnGroupID(), $groupManager->getJoinOnGroupID(), JOIN_TYPE_RIGHT ) );*/
     // $dataAccessObject = $multiTableManager;
     $multiTableManager->setSortOrder('campus_id');
     //******Not sure this is the way to do it*****
     //       $this->listManager = new GroupList( $sortBy );
     $this->listManager = $multiTableManager->getListIterator();
     // now initialize the labels for this page
     // start by loading the default field labels for this Module
     $languageID = $viewer->getLanguageID();
     $seriesKey = modulecim_sch::MULTILINGUAL_SERIES_KEY;
     $pageKey = modulecim_sch::MULTILINGUAL_PAGE_FIELDS;
     $this->labels = new MultilingualManager($languageID, $seriesKey, $pageKey);
     // then load the page specific labels for this page
     $pageKey = page_ViewGroups::MULTILINGUAL_PAGE_KEY;
     $this->labels->loadPageLabels($pageKey);
     $this->labels->setSeriesKey(SITE_LABEL_SERIES_SITE);
     $this->labels->loadPageLabels(SITE_LABEL_PAGE_FORM_LINKS);
 }
 /**
  * function getHTML
  * <pre>
  * This method returns the HTML data generated by this object.
  * </pre>
  * @return [STRING] HTML Display data.
  */
 function getHTML()
 {
     // Uncomment the following line if you want to create a template
     // tailored for this page:
     //$path = $this->pathModuleRoot.'templates/';
     // Otherwise use the standard Templates for the site:
     $path = SITE_PATH_TEMPLATES;
     /*
      * store the link values
      */
     // example:
     // $this->linkValues[ 'view' ] = 'add/new/href/data/here';
     // store the link labels
     $this->linkLabels['edit'] = $this->labels->getLabel('[Edit]');
     $this->linkLabels['del'] = $this->labels->getLabel('[Delete]');
     $this->linkLabels['cont'] = $this->labels->getLabel('[Continue]');
     // $this->linkLabels[ 'view' ] = 'new link label here';
     /*
      * store any additional link Columns
      */
     // example:
     //$title = $this->labels->getLabel( '[title_groups]');
     //$columnLabel = $this->labels->getLabel( '[groups]');
     //$link = $this->linkValues[ 'groups' ];
     //$fieldName = 'accessgroup_id';
     //$this->addLinkColumn( $title, $columnLabel, $link, $fieldName);
     /*
      * Update any label tags ...
      */
     // example:
     // $name = $user->getName();
     // $this->labels->setLabelTag( '[Title]', '[userName]', $name);
     // NOTE:  this parent method prepares the $this->template with the
     // common AdminBox data.
     $this->prepareTemplate($path);
     // store the statevar id to edit
     $this->template->set('editEntryID', $this->campusgroup_id);
     // store all the fields to the template
     $this->setFormFieldsToTemplate();
     /*
      * Form related Template variables:
      */
     /*
      * Insert the date start/end values for the following date fields:
      */
     // example:
     //$this->template->set( 'startYear_[fieldName]', 2000);
     //$this->template->set( 'endYear_[fieldName]', 2010);
     /*
      * List related Template variables :
      */
     // Store the XML Node name for the Data Access Field List
     $xmlNodeName = RowManager_CampusGroupManager::XML_NODE_NAME;
     $this->template->set('rowManagerXMLNodeName', $xmlNodeName);
     // store the primary key field name for the data being displayed
     $this->template->set('primaryKeyFieldName', 'campusgroup_id');
     // store data list to the template
     // NOTE: we initialize it here to make sure we capture any new data
     // from a recent processData() call.
     $dataAccessManager = new RowManager_CampusGroupManager();
     $dataAccessManager->setGroupID($this->group_id);
     $dataAccessManager->setSortOrder($this->sortBy);
     //        $this->dataList = new CampusGroupList( $this->sortBy );
     $this->dataList = $dataAccessManager->getListIterator();
     $this->template->setXML('dataList', $this->dataList->getXML());
     /*
      * Add any additional data required by the template here
      */
     // get a list of all campus_ids
     $campus = new RowManager_CampusManager();
     $campus->setSortOrder('campus_desc');
     $campusList = new ListIterator($campus);
     $campusArray = $campusList->getDropListArray();
     $this->template->set('list_campus_id', $campusArray);
     $templateName = 'siteAdminBox.php';
     // if you are creating a custom template for this page then
     // replace $templateName with the following:
     //$templateName = 'page_ManageCampusGroup.php';
     return $this->template->fetch($templateName);
 }
Example #3
0
}
// check to see if the parameter 'skipTables' was provided
//$skipTables = isset($_REQUEST['skipTables']);
$skipTables = true;
// if NOT then reset the tables...
if (!$skipTables) {
    /*
     * CampusGroup Table
     *
     * Stores the relationships between the group and campus
     *
     * campusgroup_id [INTEGER]  ID of campus group
     * group_id [INTEGER]  ID of a group
     * campus_id [INTEGER]  ID of a campus
     */
    $CampusGroup = new RowManager_CampusGroupManager();
    $CampusGroup->dropTable();
    $CampusGroup->createTable();
    /*
     * Group Table
     *
     * Contains the meta data for each of the groups
     *
     * group_id [INTEGER]  ID of the group
     * groupType_id [INTEGER]  ID of the group type
     * group_name [STRING]  The name of the group
     * group_desc [STRING]  The description of the group
     */
    $Group = new RowManager_GroupManager();
    $Group->dropTable();
    $Group->createTable();
 function displayGroups()
 {
     // This array get passed back to the template multiple time
     $groupCollectionArray = array();
     $multiTableManager = new MultiTableManager();
     $groupManager = new RowManager_GroupManager();
     $superAdminManager = new RowManager_PermissionsSuperAdminManager();
     //SUPER ADMIN
     //Check if user's Viewer_id is in the PermissionSuperAdmin table
     //If the user is a super admin then show all gorups per campus including public groups
     if ($superAdminManager->loadByViewerID($this->viewer->getViewerID())) {
         // the viewer is a super admin
         echo "ViewerID[" . $this->viewer->getViewerID() . "] is a super admin<br/>";
         $campusManager = new RowManager_CampusManager();
         $campusArray = array();
         $this->listIterator = $campusManager->getListIterator();
         $this->listIterator->setFirst();
         while ($this->listIterator->moveNext()) {
             $group = $this->listIterator->getCurrent(new RowManager_CampusManager());
             $campusArray[] = $group->getCampusID();
         }
         //echo "<pre>".print_r($campusArray)."</pre>";
         foreach ($campusArray as $key => $campusID) {
             $campusManager = new RowManager_CampusManager($campusID);
             $campusGroupManager = new RowManager_CampusGroupManager();
             $campusGroupManager->setCampusID($campusID);
             $groupManager = new RowManager_GroupManager();
             $multiTableManager = new MultiTableManager();
             $multiTableManager->addRowManager($groupManager);
             $multiTableManager->addRowManager($campusGroupManager, new JoinPair($campusGroupManager->getJoinOnGroupID(), $groupManager->getJoinOnGroupID(), JOIN_TYPE_RIGHT));
             $multiTableManager->addRowManager($campusManager, new JoinPair($campusManager->getJoinOnCampusID(), $campusGroupManager->getJoinOnCampusID(), JOIN_TYPE_RIGHT));
             //Go through the result and save all the groups of that campus to an array
             $campusGroupArray = array();
             $this->listIterator = $multiTableManager->getListIterator();
             $this->listIterator->setFirst();
             while ($this->listIterator->moveNext()) {
                 $group = $this->listIterator->getCurrent(new RowManager_CampusGroupManager());
                 $campusGroupArray[] = $group;
             }
             //set the campusID and CampusDesc for the $campusGroupArray
             $groupCollectionArray[] = new GroupCollection($campusManager->getShortDesc(), $campusID, $campusGroupArray);
         }
         //TODO - not a correct join
         //TODO - get all campus ID and groups
         //TODO - get all public groups
     } else {
         //STAFF OR STUDENT
         //If the user is a student or staff then they should have campus assignmnets in cim_hrdb_assignment
         //Find all the campuses and save them in the $campusAssigment array
         $campusAssignments = array();
         $statusArray = array();
         $statusArray[] = CA_STAFF;
         $statusArray[] = CA_STUDENT;
         foreach ($statusArray as $key => $statusID) {
             // filter from the cim_hrdb_assignment table
             $assignmentManager = new RowManager_AssignmentsManager();
             $assignmentManager->setPersonID($this->personID);
             $assignmentManager->setAssignmentStatus($statusID);
             $assignmentList = new ListIterator($assignmentManager);
             $assignmentList->setFirst();
             while ($assignmentList->moveNext()) {
                 $assManager = $assignmentList->getCurrent(new RowManager_AssignmentsManager());
                 $campusAssignments[] = $assManager->getCampusID();
             }
         }
         //CAMPUS ADMIN
         //some users can be admin to a campus that they are neither a student or staff for
         //Check cim_sch_permissionsCampusAdmin for the viewer id of the user
         //for each found save the campusID in the $campusAssignments table
         $permissionsCampusAdmin = new RowManager_PermissionsCampusAdminManager();
         $permissionsCampusAdmin->setViewerID($this->viewer->getViewerID());
         $campusAdminList = new ListIterator($permissionsCampusAdmin);
         $campusAdminList->setFirst();
         while ($campusAdminList->moveNext()) {
             $permCampus = $campusAdminList->getCurrent(new RowManager_PermissionsCampusAdminManager());
             //for each campuses found, store in array
             $campusAssignments[] = $permCampus->getCampusID();
         }
         //remove any duplicate campus ID in the array
         $campusAssignments = array_unique($campusAssignments);
         //After collection all the campusIDs lets go through each campusID and get the groups
         //for each campusID find all the groups in $campusGroupManager table
         //Save the groups in an array taged with the campusID, Shortdesc
         foreach ($campusAssignments as $key => $campusID) {
             //Set the campusID so we can get the shortDesc at the end
             $campusManager = new RowManager_CampusManager($campusID);
             //Join cim_sch_Group and cim_sch_campusgroup
             $campusGroupManager = new RowManager_CampusGroupManager();
             $campusGroupManager->setCampusID($campusID);
             $multiTableManager = new MultiTableManager();
             $multiTableManager->addRowManager($campusGroupManager);
             $groupManager = new RowManager_GroupManager();
             $multiTableManager->addRowManager($groupManager, new JoinPair($campusGroupManager->getJoinOnGroupID(), $groupManager->getJoinOnGroupID()));
             //Go through the result and save all the groups of that campus to an array
             $campusGroupArray = array();
             $this->listIterator = $multiTableManager->getListIterator();
             $this->listIterator->setFirst();
             while ($this->listIterator->moveNext()) {
                 $group = $this->listIterator->getCurrent(new RowManager_GroupManager());
                 $campusGroupArray[] = $group;
             }
             //set the campusID and CampusDesc for the $campusGroupArray
             $groupCollectionArray[] = new GroupCollection($campusManager->getShortDesc(), $campusID, $campusGroupArray);
         }
         //GROUP ADMIN
         //The user might be a group admin so we should display that group as well
         //We have to find the which groups the user is admin for in cim_sch_permissionsGroupAdmin
         //For each of these gorups, look in cim_sch_campusGroup table and find and store the campusID in an array
         //Use the campusID array and for each campusID and only save the gorups with the same campusID
         //Save all the gorups in the $gorupCollectionArray
         //Set a fillter for only show results if its the user's ViewerID
         $permissionsGroupAdminManager = new RowManager_PermissionsGroupAdminManager();
         $permissionsGroupAdminManager->setViewerID($this->viewer->getViewerID());
         //Set Fillter to only show results that are a campus group
         $groupManager = new RowManager_GroupManager();
         $groupManager->setGroupTypeID(1);
         //Make the join of tables cim_sch_group, cim_sch_campusGroup, cim_sch_permissionsGroupAdmin
         $campusGroupManager = new RowManager_CampusGroupManager();
         $multiTableManager = new MultiTableManager();
         $multiTableManager->addRowManager($groupManager);
         $multiTableManager->addRowManager($campusGroupManager, new JoinPair($campusGroupManager->getJoinOnGroupID(), $groupManager->getJoinOnGroupID(), JOIN_TYPE_RIGHT));
         $multiTableManager->addRowManager($permissionsGroupAdminManager, new JoinPair($permissionsGroupAdminManager->getJoinOnGroupID(), $groupManager->getJoinOnGroupID(), JOIN_TYPE_RIGHT));
         //Go through the results and save the campusID of that group
         $campusGroupArray = array();
         $this->listIterator = $multiTableManager->getListIterator();
         $this->listIterator->setFirst();
         while ($this->listIterator->moveNext()) {
             $group = $this->listIterator->getCurrent(new RowManager_CampusGroupManager());
             $campusGroupArray[] = $group->getCampusID();
         }
         //For each campus found, go through the result again and fillter by campusID
         //Only the groups of the same campusID are saved together
         foreach ($campusGroupArray as $key => $campusID) {
             //This allows us to get the campus shortDesc at the end
             $campusManager = new RowManager_CampusManager($campusID);
             //same code as before to join the tables
             $permissionsGroupAdminManager = new RowManager_PermissionsGroupAdminManager();
             $permissionsGroupAdminManager->setViewerID($this->viewer->getViewerID());
             $campusGroupManager = new RowManager_CampusGroupManager();
             $campusGroupManager->setCampusID($campusID);
             $groupManager = new RowManager_GroupManager();
             $groupManager->setGroupTypeID(1);
             $multiTableManager = new MultiTableManager();
             $multiTableManager->addRowManager($groupManager);
             $multiTableManager->addRowManager($campusGroupManager, new JoinPair($campusGroupManager->getJoinOnGroupID(), $groupManager->getJoinOnGroupID(), JOIN_TYPE_RIGHT));
             $multiTableManager->addRowManager($permissionsGroupAdminManager, new JoinPair($permissionsGroupAdminManager->getJoinOnGroupID(), $groupManager->getJoinOnGroupID(), JOIN_TYPE_RIGHT));
             //go through the results and save the gorups
             $campusGroupArray = array();
             $this->listIterator = $multiTableManager->getListIterator();
             $this->listIterator->setFirst();
             while ($this->listIterator->moveNext()) {
                 $group = $this->listIterator->getCurrent(new RowManager_GroupManager());
                 $campusGroupArray[] = $group;
             }
             //set the campusID and CampusDesc for the $campusGroupArray
             $groupCollectionArray[] = new GroupCollection($campusManager->getShortDesc(), $campusID, $campusGroupArray);
         }
         //PUBLIC Groups
         //Show all groups in cim_sch_group with the groupTypeID of 2 (public)
         //The public gorup does not have a campus assign
         $campusID = 0;
         //The public gorup desc is public, this is shown in the template
         $publicGroupDesc = "Public";
         //Set the public gorup fillter
         $thisIsAPublicGroup = 2;
         $groupManager = new RowManager_GroupManager();
         $groupManager->setGroupTypeID($thisIsAPublicGroup);
         //go through the results and save the groups
         $groupArray = array();
         $this->listIterator = $groupManager->getListIterator();
         $this->listIterator->setFirst();
         while ($this->listIterator->moveNext()) {
             $group = $this->listIterator->getCurrent(new RowManager_GroupManager());
             $groupArray[] = $group;
         }
         //save the public groups to the array
         $groupCollectionArray[] = new GroupCollection($publicGroupDesc, $campusID, $groupArray);
     }
     //END OF IF
     //KSL
     //NORMAL
     /*
     		 $campusAssignments = array();
     
     		 $statusArray = array();
     		 $statusArray[] = CA_STAFF;
     		 $statusArray[] = CA_STUDENT;
     		 foreach( $statusArray as $key=>$statusID )
     		 {
     		 // filter from the cim_hrdb_assignment table
     		 $assignmentManager = new RowManager_AssignmentsManager();
     		 $assignmentManager->setPersonID( $this->personID );
     		 $assignmentManager->setAssignmentStatus( $statusID );
     
     		  
     
     		 $assignmentList = new ListIterator( $assignmentManager );
     		 $assignmentList->setFirst();
     		 while ( $assignmentList->moveNext() )
     		 {
     		 $assManager = $assignmentList->getCurrent( new RowManager_AssignmentsManager() );
     		 $campusAssignments[] = $assManager->getCampusID();
     		 }
     
     		 }
     		 // echo "<pre>".print_r($campusAssignments, true)."</pre>";
     
     		 // STEP 2:  get the appropriate groups
     		 foreach( $campusAssignments as $key=>$campusID )
     		 {
     		 $campusManager = new RowManager_CampusManager( $campusID );
     
     		 $campusGroupManager = new RowManager_CampusGroupManager();
     		 $campusGroupManager->setCampusID( $campusID );
     
     		 $multiTableManager = new MultiTableManager();
     		 $multiTableManager->addRowManager($campusGroupManager);
     		  
     		 $groupManager = new RowManager_GroupManager();
     		 $multiTableManager->addRowManager( $groupManager, new JoinPair( $campusGroupManager->getJoinOnGroupID(), $groupManager->getJoinOnGroupID() ) );
     
     		 $campusGroupArray = array();
     		 $this->listIterator = $multiTableManager->getListIterator();
     		 $this->listIterator->setFirst();
     		 while( $this->listIterator->moveNext() )
     		 {
     		 $group = $this->listIterator->getCurrent(new RowManager_GroupManager());
     		 $campusGroupArray[] = $group;
     		 }
     
     		 $groupCollectionArray[] = new GroupCollection( $campusManager->getShortDesc(), $campusID, $campusGroupArray );
     		 }*/
     return $this->template->set('groupCollectionArray', $groupCollectionArray);
 }