function processView()
 {
     if (isset($_REQUEST['cohortids'])) {
         foreach ($_REQUEST['cohortids'] as $id) {
             if ($id) {
                 $this->_cohortids[] = $id;
             }
         }
         $_SESSION['attendance']['cohortids'] = $this->_cohortids;
     }
     $this->_attendance_date = process_widget('attendance_date', array('type' => 'date'));
     if (empty($this->_attendance_date)) {
         // Default to last Sunday, unless today is Sunday
         $default_day = defined('ATTENDANCE_DEFAULT_DAY') ? ATTENDANCE_DEFAULT_DAY : 'Sunday';
         $this->_attendance_date = date('Y-m-d', date('l') == $default_day ? time() : strtotime('last ' . $default_day));
     }
     if (empty($_REQUEST['params_submitted']) && empty($_REQUEST['attendances_submitted'])) {
         if (!empty($_SESSION['attendance'])) {
             $this->_age_brackets = array_get($_SESSION['attendance'], 'age_brackets');
             $this->_statuses = array_get($_SESSION['attendance'], 'statuses');
             $this->_cohortids = array_get($_SESSION['attendance'], 'cohortids');
             $this->_show_photos = array_get($_SESSION['attendance'], 'show_photos', FALSE);
             $this->_parallel_mode = array_get($_SESSION['attendance'], 'parallel_mode', FALSE);
         }
     }
     if (!empty($_REQUEST['params_submitted']) || !empty($_REQUEST['attendances_submitted'])) {
         if (!empty($_REQUEST['age_brackets_all'])) {
             unset($_REQUEST['age_brackets']);
         }
         if (!empty($_REQUEST['statuses_all'])) {
             unset($_REQUEST['statuses']);
         }
         $this->_age_brackets = $_SESSION['attendance']['age_brackets'] = array_get($_REQUEST, 'age_brackets');
         $this->_statuses = $_SESSION['attendance']['statuses'] = array_get($_REQUEST, 'statuses');
         $this->_show_photos = $_SESSION['attendance']['show_photos'] = array_get($_REQUEST, 'show_photos', FALSE);
         $this->_parallel_mode = $_SESSION['attendance']['parallel_mode'] = array_get($_REQUEST, 'parallel_mode', FALSE);
     }
     foreach ($this->_cohortids as $id) {
         $this->_record_sets[$id] = new Attendance_Record_set($this->_attendance_date, $id, $this->_age_brackets, $this->_statuses);
         if ($this->_show_photos) {
             $this->_record_sets[$id]->show_photos = TRUE;
         }
     }
     if (!empty($_REQUEST['release'])) {
         foreach ($this->_record_sets as $set) {
             $set->releaseLock();
         }
     } else {
         if (!empty($_REQUEST['params_submitted'])) {
             foreach ($this->_record_sets as $cohortid => $set) {
                 if (!$set->checkAllowedDate()) {
                     add_message(_('"Attendance for "') . $set->getCohortName() . _('" cannot be recorded on a "') . date('l', strtotime($this->_attendance_date)), 'error');
                     unset($this->_record_sets[$cohortid]);
                     $this->_cohortids = array_diff($this->_cohortids, array($cohortid));
                     continue;
                 }
                 if (!$set->acquireLock()) {
                     add_message(_('"Another user is currently recording attendance for "') . $set->getCohortName() . _('".  Please wait until they finish then try again."'), 'error');
                     unset($this->_record_sets[$cohortid]);
                     $this->_cohortids = array_diff($this->_cohortids, array($cohortid));
                 }
             }
         }
     }
     if (!empty($_REQUEST['attendances_submitted'])) {
         // Process step 2
         if ($_SESSION['enter_attendance_token'] == $_REQUEST['enter_attendance_token']) {
             // Clear the token from the session on disk
             $_SESSION['enter_attendance_token'] = NULL;
             session_write_close();
             session_start();
             // Process the form
             foreach ($this->_record_sets as $i => $set) {
                 if (!$set->haveLock() && !$set->acquireLock()) {
                     add_message("Unfortunately your lock on '" . $set->getCohortName() . "' has expired and been acquired by another user.  Please wait until they finish and try again.", 'error');
                 } else {
                     if ($set->processForm($i)) {
                         $set->save();
                         if ((int) $set->congregationid) {
                             Headcount::save('congregation', $this->_attendance_date, $set->congregationid, $_REQUEST['headcount']['congregation'][$set->congregationid]);
                         } else {
                             Headcount::save('person_group', $this->_attendance_date, $set->groupid, $_REQUEST['headcount']['group'][$set->groupid]);
                         }
                         $set->releaseLock();
                     }
                 }
             }
         } else {
             trigger_error('Could not save attendances - synchronizer token does not match.  This probably means the request was duplicated somewhere along the line.  If you see your changes below, they have been saved by the other request');
             sleep(3);
             // Give the other one time to finish before we load again
             // Pretend we are back in step 2
             $_POST['attendances_submitted'] = FALSE;
             $_SESSION['enter_attendance_token'] = md5(time());
         }
     }
 }
 function processView()
 {
     if (empty($_REQUEST['params_submitted']) && empty($_REQUEST['attendances_submitted'])) {
         if (!empty($_SESSION['attendance'])) {
             $this->_age_bracket = array_get($_SESSION['attendance'], 'age_bracket');
             $this->_congregationids = array_get($_SESSION['attendance'], 'congregationids');
             $this->_groupid = array_get($_SESSION['attendance'], 'groupid');
             $this->_show_photos = array_get($_SESSION['attendance'], 'show_photos', FALSE);
         }
         // Default to last Sunday, unless today is Sunday
         $this->_attendance_date = date('Y-m-d', date('D') == 'Sun' ? time() : strtotime('last Sunday'));
     }
     if (!empty($_REQUEST['params_submitted']) || !empty($_REQUEST['attendances_submitted'])) {
         $this->_attendance_date = process_widget('attendance_date', array('type' => 'date'));
         $this->_age_bracket = $_SESSION['attendance']['age_bracket'] = array_get($_REQUEST, 'age_bracket');
         $this->_show_photos = $_SESSION['attendance']['show_photos'] = array_get($_REQUEST, 'show_photos', FALSE);
         $status = NULL;
         // TODO
         if ($_REQUEST['for_type'] == 'congregationid') {
             $cids = process_widget('congregationid', array('type' => 'reference', 'references' => 'congregation', 'multiple' => true));
             foreach ($cids as $cid) {
                 if ($cid && !in_array($cid, $this->_congregationids)) {
                     $this->_congregationids[] = $cid;
                     $this->_record_sets[] = new Attendance_Record_Set($this->_attendance_date, $this->_age_bracket, $status, $cid, 0);
                 }
             }
             $_SESSION['attendance']['congregationids'] = $this->_congregationids;
             $_SESSION['attendance']['groupid'] = null;
         } else {
             $this->_groupid = process_widget('groupid', array('type' => 'reference', 'references' => 'person_group', 'allow_empty' => false));
             if ($this->_groupid) {
                 $this->_record_sets[] = new Attendance_Record_Set($this->_attendance_date, $this->_age_bracket, $status, NULL, $this->_groupid);
                 $_SESSION['attendance']['congregationids'] = array();
                 $_SESSION['attendance']['groupid'] = $this->_groupid;
             }
         }
         if ($this->_show_photos) {
             foreach ($this->_record_sets as $set) {
                 $set->show_photos = TRUE;
             }
         }
     }
     if (!empty($_REQUEST['attendances_submitted'])) {
         // Process step 2
         if ($_SESSION['enter_attendance_token'] == $_REQUEST['enter_attendance_token']) {
             // Clear the token from the session on disk
             $_SESSION['enter_attendance_token'] = NULL;
             session_write_close();
             session_start();
             // Process the form
             foreach ($this->_record_sets as $i => $set) {
                 if ($set->processForm($i)) {
                     $set->save();
                     if ((int) $set->congregationid) {
                         Headcount::save('congregation', $this->_attendance_date, $set->congregationid, $_REQUEST['headcount']['congregation'][$set->congregationid]);
                     } else {
                         Headcount::save('person_group', $this->_attendance_date, $set->groupid, $_REQUEST['headcount']['group'][$set->groupid]);
                     }
                 }
             }
         } else {
             trigger_error('Could not save attendances - synchronizer token does not match.  This probably means the request was duplicated somewhere along the line.  If you see your changes below, they have been saved by the other request');
             sleep(3);
             // Give the other one time to finish before we load again
             // Pretend we are back in step 2
             $_POST['attendances_submitted'] = FALSE;
             $_SESSION['enter_attendance_token'] = md5(time());
         }
     }
 }