/**
  * function __construct
  * <pre>
  * Initialize the object.
  * </pre>
  * @param $pathModuleRoot [STRING] The path to this module's root directory
  * @param $viewer [OBJECT] The viewer object.
  * @param $formAction [STRING] The action on a form submit
  * @param $ [INTEGER] Value used to initialize the rowManager
  * @return [void]
  */
 function __construct($pathModuleRoot, $viewer, $formAction, $person_id, $campus_id, $person_year_id = '')
 {
     // NOTE: be sure to call the parent constructor before trying to
     //       use the ->formXXX arrays...
     parent::__construct($formAction, FormProcessor_EditStudentYearInSchool::FORM_FIELDS, FormProcessor_EditStudentYearInSchool::FORM_FIELD_TYPES);
     $this->pathModuleRoot = $pathModuleRoot;
     $this->viewer = $viewer;
     $this->formAction = $formAction;
     $this->campus_id = $campus_id;
     $this->person_id = $person_id;
     $this->person_year_id = $person_year_id;
     //        if ($person_year_id == '')
     //        {
     // 	       if (isset($person_id))
     // 	       {
     // 		       if (isset($campus_id))
     // 		       {
     // 		       }
     // 	       }
     //        }
     /**** Check privileges and initialize campus drop-down list ***/
     // Now load the access Priviledge manager of this viewer
     $this->adminManager = new RowManager_AdminManager();
     // Get the person ID
     $accessManager = new RowManager_AccessManager();
     $accessManager->loadByViewerID($this->viewer->getViewerID());
     $personID = $accessManager->getPersonID();
     // Get the permissions the person has.
     $this->adminManager->loadByPersonID($personID);
     if ($this->adminManager->hasSitePriv()) {
         $campusManager = new RowManager_CampusManager();
         $campusManager->setSortOrder('campus_desc');
         $this->campusList = $campusManager->getListIterator();
         $this->accessibleCampuses = $this->campusList->getDropListArray();
     } else {
         if ($this->adminManager->hasCampusPriv()) {
             $campusAdminManager = new RowManager_CampusAdminManager();
             $adminID = $this->adminManager->getID();
             // echo 'adminID['.$adminID.']<br/>';
             $campusAdminManager->setAdminID($adminID);
             $multiTableManager = new MultiTableManager();
             $multiTableManager->addRowManager($campusAdminManager);
             $multiTableManager->setSortOrder('campus_desc');
             $campusManager = new RowManager_CampusManager();
             $multiTableManager->addRowManager($campusManager, new JoinPair($campusManager->getJoinOnCampusID(), $campusAdminManager->getJoinOnCampusID()));
             $this->campusList = $multiTableManager->getListIterator();
             $this->accessibleCampuses = array();
             $this->campusList->setFirst();
             while ($this->campusList->moveNext()) {
                 $campusAdminObject = $this->campusList->getCurrent(new RowManager_CampusAdminManager());
                 $campusObject = $this->campusList->getCurrent(new RowManager_CampusManager());
                 $this->accessibleCampuses[$campusAdminObject->getCampusID()] = $campusObject->getLabel();
             }
         } else {
             if ($this->adminManager->isStaff($viewer->getID())) {
                 $staffManager = new RowManager_StaffManager();
                 $staffManager->setPersonID($personID);
                 $multiTableManager = new MultiTableManager();
                 $multiTableManager->addRowManager($staffManager);
                 $multiTableManager->setSortOrder('campus_desc');
                 $assignmentManager = new RowManager_AssignmentsManager();
                 $multiTableManager->addRowManager($assignmentManager, new JoinPair($assignmentManager->getJoinOnPersonID(), $staffManager->getJoinOnPersonID()));
                 $campusManager = new RowManager_CampusManager();
                 $multiTableManager->addRowManager($campusManager, new JoinPair($campusManager->getJoinOnCampusID(), $assignmentManager->getJoinOnCampusID()));
                 $this->campusList = $multiTableManager->getListIterator();
                 $this->accessibleCampuses = array();
                 $this->campusList->setFirst();
                 while ($this->campusList->moveNext()) {
                     $campusAssignObject = $this->campusList->getCurrent(new RowManager_AssignmentsManager());
                     $campusObject = $this->campusList->getCurrent(new RowManager_CampusManager());
                     $this->accessibleCampuses[$campusAssignObject->getCampusID()] = $campusObject->getLabel();
                 }
             } else {
                 $campusManager = new RowManager_CampusManager();
                 $campusManager->setSortOrder('campus_desc');
                 $this->campusList = $campusManager->getListIterator();
                 $this->accessibleCampuses = $this->campusList->getDropListArray();
             }
         }
     }
     // modify the campus_id if necessary
     if ($this->campus_id == FormProcessor_EditStudentYearInSchool::DISPLAY_ALL_ID) {
         // setting the campus id to blank will get entries from all the campuses
         $this->campus_id = '';
     } else {
         if ($this->campus_id == '') {
             // no campus has been specified
             // choose a default campus if none specified
             // echo 'No campus specified<br/>';
             // get the first element from the accessible list
             foreach ($this->accessibleCampuses as $key => $value) {
                 $this->campus_id = $key;
                 break;
             }
             // assert campus_id should now be something
             if ($this->campus_id == '') {
                 die("ERROR - campusID not set to anything<br/>");
             }
         }
     }
     /*** end privilege checking and campus droplist setup ***/
     //         echo 'campus = '.$this->campus_id;
     // create new rowManager (a List Iterator obj.)
     $statuses = '0,1,6';
     // filter by assignment status in ('undefined', 'current student', 'unknown')
     $this->rowManager = new PersonYearList($this->campus_id, $statuses, 'year_id,person_lname');
     // figure out the important fields for the rowItems
     $fieldsOfInterest = implode(',', $this->formFields);
     $this->primaryIDs = array();
     // for each row item ...
     $this->rowManager->setFirst();
     $i = 0;
     $valid_values = explode(',', RowManager_PersonYearManager::FIELD_LIST);
     while ($rowItem = $this->rowManager->getNext()) {
         // make sure rowItems have valid entries in the DB
         if (!$rowItem->isLoaded()) {
             $rowItem->createNewEntry();
         }
         // set the fields of interest ...
         $rowItem->setFieldsOfInterest($fieldsOfInterest);
         // get the primaryID of this rowItem
         $primaryID = $rowItem->getPrimaryKeyValue();
         $this->primaryIDs[$i] = $primaryID;
         $person_id = -1;
         // now initialize beginning form values from rowItem object
         for ($indx = 0; $indx < count($this->formFields); $indx++) {
             $key = $this->formFields[$indx];
             if (in_array($key, $valid_values)) {
                 $this->formValues[$key . $primaryID] = $rowItem->getValueByFieldName($key);
                 if ($key == 'person_id') {
                     $person_id = $this->formValues[$key . $primaryID];
                 }
             } else {
                 if ($person_id != '-1') {
                     $person_manager = new RowManager_PersonManager($person_id);
                     $this->formValues[$key . $primaryID] = $person_manager->getValueByFieldName($key);
                 } else {
                     $this->formValues[$key . $primaryID] = "";
                 }
             }
         }
         // next field
         $i++;
     }
     // next rowItem in rowManager
     //         echo 'array = <pre>'.print_r($this->formValues,true).'</pre>';
     // now initialize the labels for this page
     // start by loading the default field labels for this Module
     $languageID = $viewer->getLanguageID();
     $seriesKey = modulecim_hrdb::MULTILINGUAL_SERIES_KEY;
     $pageKey = modulecim_hrdb::MULTILINGUAL_PAGE_FIELDS;
     $this->labels = new MultilingualManager($languageID, $seriesKey, $pageKey);
     // then load the page specific labels for this page
     $pageKey = FormProcessor_EditStudentYearInSchool::MULTILINGUAL_PAGE_KEY;
     $this->labels->loadPageLabels($pageKey);
     // load the site default form link labels
     $this->labels->setSeriesKey(SITE_LABEL_SERIES_SITE);
     $this->labels->loadPageLabels(SITE_LABEL_PAGE_FORM_LINKS);
 }