private function addEditActivityCommon($bAsVol, $lVolID, $lActivityID)
 {
     //---------------------------------------------------------------------
     //
     //---------------------------------------------------------------------
     global $gbDateFormatUS;
     $this->load->helper('dl_util/verify_id');
     verifyID($this, $lVolID, 'volunteer ID');
     $displayData = array();
     $displayData['lVolID'] = $lVolID = (int) $lVolID;
     $displayData['lActivityID'] = $lActivityID = (int) $lActivityID;
     $displayData['bNew'] = $bNew = $lActivityID <= 0;
     $displayData['bAsVol'] = $bAsVol;
     //-------------------------
     // models & helpers
     //-------------------------
     $this->load->model('vols/mvol_event_hours', 'clsVolHours');
     $this->load->model('vols/mvol', 'clsVol');
     $this->load->model('people/mpeople', 'clsPeople');
     $this->load->model('util/mlist_generic', 'clsList');
     $this->load->helper('dl_util/time_date');
     // for date verification
     $params = array('enumStyle' => 'terse');
     $this->load->library('generic_rpt', $params);
     $this->load->helper('dl_util/web_layout');
     $this->clsVolHours->loadVolActivitiesViaID($lActivityID);
     $act =& $this->clsVolHours->unActivity[0];
     //-------------------------
     // validation rules
     //-------------------------
     $this->form_validation->set_error_delimiters('<div class="formError">', '</div>');
     $this->form_validation->set_rules('ddlStart', 'Start Time', 'trim|callback_vactVerifyStart');
     $this->form_validation->set_rules('ddlDuration', 'Duration', 'trim|callback_vactVerifyDuration');
     $this->form_validation->set_rules('ddlActivity', 'Activity', 'trim|callback_vactVerifyAct');
     $this->form_validation->set_rules('ddlJobCode', 'Job Code', 'trim');
     $this->form_validation->set_rules('txtDate', 'Date of Volunteer Activity', 'trim|required' . '|callback_verifyUnDateValid');
     $this->form_validation->set_rules('txtNotes', 'Notes', 'trim');
     if ($this->form_validation->run() == FALSE) {
         $displayData['formData'] = new stdClass();
         $this->load->library('generic_form');
         // first time displayed, no user data entry errors
         if (validation_errors() == '') {
             if (is_null($act->dteActivityDate)) {
                 $displayData['formData']->txtDate = '';
                 $displayData['formData']->lStartTime = strDisplayTimeDDL(null, true, true);
             } else {
                 $displayData['formData']->txtDate = strNumericDateViaMysqlDate($act->mysqlActivityDate, $gbDateFormatUS);
                 $displayData['formData']->lStartTime = strDisplayTimeDDL($act->dteActivityDate, true, true);
             }
             $displayData['formData']->strNotes = $act->strNotes;
             $displayData['formData']->enumDuration = strDurationDDL(true, false, lDurationHrsToQuarters($act->dHoursWorked), true);
             // activity generic list
             $this->clsList->strBlankDDLName = '&nbsp;';
             $this->clsList->enumListType = CENUM_LISTTYPE_VOLACT;
             $displayData['formData']->strVolActivity = $this->clsList->strLoadListDDL('ddlActivity', true, $act->lActivityID);
             // job code generic list
             $this->clsList->enumListType = CENUM_LISTTYPE_VOLJOBCODES;
             $this->clsList->strBlankDDLName = '(no job code)';
             $displayData['strDDLJobCode'] = $this->clsList->strLoadListDDL('ddlJobCode', true, $act->lJobCode);
         } else {
             setOnFormError($displayData);
             $displayData['formData']->txtDate = set_value('txtDate');
             $displayData['formData']->lStartTime = $lStartTime = strDisplayTimeDDL(set_value('ddlStart'), true, true);
             $displayData['formData']->strNotes = set_value('txtNotes');
             $displayData['formData']->enumDuration = strDurationDDL(true, false, set_value('ddlDuration'), true);
             // activity generic list
             $this->clsList->strBlankDDLName = '&nbsp;';
             $this->clsList->enumListType = CENUM_LISTTYPE_VOLACT;
             $displayData['formData']->strVolActivity = $this->clsList->strLoadListDDL('ddlActivity', true, set_value('ddlActivity'));
             // job code generic list
             $this->clsList->enumListType = CENUM_LISTTYPE_VOLJOBCODES;
             $this->clsList->strBlankDDLName = '(no job code)';
             $displayData['strDDLJobCode'] = $this->clsList->strLoadListDDL('ddlJobCode', true, set_value('ddlJobCode'));
         }
         $this->clsVol->loadVolRecsViaVolID($lVolID, true);
         $displayData['contextSummary'] = $this->clsVol->volHTMLSummary(0);
         //--------------------------
         // breadcrumbs
         //--------------------------
         if ($bAsVol) {
             $displayData['pageTitle'] = 'Log volunteer hours';
         } else {
             $displayData['pageTitle'] = anchor('main/menu/vols', 'Volunteers', 'class="breadcrumb"') . ' | ' . anchor('/volunteers/vol_record/volRecordView/' . $lVolID, 'Record', 'class="breadcrumb"') . ' | Log volunteer hours';
         }
         $displayData['title'] = CS_PROGNAME . ' | Volunteers';
         $displayData['nav'] = $this->mnav_brain_jar->navData();
         $displayData['mainTemplate'] = 'vols/hrs_unscheduled_add_edit_view';
         $this->load->vars($displayData);
         $this->load->view('template');
     } else {
         $act->lVolID = $lVolID;
         $act->strNotes = trim($_POST['txtNotes']);
         $act->lActivityID = (int) trim($_POST['ddlActivity']);
         $act->dHoursWorked = (int) trim($_POST['ddlDuration']) / 4;
         $strDate = trim($_POST['txtDate']);
         MDY_ViaUserForm($strDate, $lMon, $lDay, $lYear, $gbDateFormatUS);
         $lDDLStart = (int) $_POST['ddlStart'];
         quartersToHrsMin($lDDLStart, $lHours, $lMinutes);
         $act->dteActivityDate = mktime($lHours, $lMinutes, 0, $lMon, $lDay, $lYear);
         $act->lJobCode = (int) $_POST['ddlJobCode'];
         if ($act->lJobCode <= 0) {
             $act->lJobCode = null;
         }
         //------------------------------------
         // update db tables and return
         //------------------------------------
         if ($bNew) {
             $lActivityID = $this->clsVolHours->addUnscheduledHrs();
             $this->session->set_flashdata('msg', 'Volunteer hours were recorded.');
         } else {
             $this->clsVolHours->updateUnscheduledHrs($lActivityID);
             $this->session->set_flashdata('msg', 'Record updated');
         }
         if ($bAsVol) {
             redirect('vol_reg/vol_hours/view');
         } else {
             redirect('reports/pre_vol_hours/viaVolID/' . $lVolID . '/false');
         }
     }
 }
 function addEditShift($lEventDateID, $lShiftID)
 {
     //---------------------------------------------------------------------
     //
     //---------------------------------------------------------------------
     global $genumDateFormat;
     $this->load->helper('dl_util/verify_id');
     verifyID($this, $lEventDateID, 'event date ID');
     if ($lShiftID . '' != '0') {
         verifyID($this, $lShiftID, 'shift ID');
     }
     $displayData = array();
     //-----------------------------
     // models and helpers
     //-----------------------------
     $this->load->model('vols/mvol_event_dates_shifts', 'clsShifts');
     $this->load->model('vols/mvol_event_dates', 'clsVolEventDates');
     $this->load->model('util/mlist_generic', 'cList');
     $this->load->helper('dl_util/time_date');
     $displayData['lEventDateID'] = $lEventDateID = (int) $lEventDateID;
     $displayData['lShiftID'] = $lShiftID = (int) $lShiftID;
     $displayData['bNew'] = $bNew = $lShiftID <= 0;
     $this->clsShifts->loadShiftsViaEventShiftID($lShiftID);
     $displayData['shift'] = $shift =& $this->clsShifts->shifts[0];
     $this->cList->enumListType = CENUM_LISTTYPE_VOLJOBCODES;
     $this->cList->strBlankDDLName = '(no job code)';
     $this->clsVolEventDates->loadEventDateViaDateID($lEventDateID);
     $edate =& $this->clsVolEventDates->dates[0];
     $lEventID = $edate->lVolEventID;
     $displayData['dteEvent'] = $edate->dteEvent;
     if ($bNew) {
         $shift->lKeyID = -1;
         $shift->lEventDateID = $lEventDateID;
         $shift->dteEventStartTime = strtotime('12:00:00 PM');
     }
     // validation rules
     $this->form_validation->set_error_delimiters('<div class="formError">', '</div>');
     $this->form_validation->set_rules('txtShiftName', 'Shift Name', 'trim|required');
     $this->form_validation->set_rules('txtShiftNote', 'Shift Notes', 'trim');
     $this->form_validation->set_rules('txtNumVols', '# Volunteers Needed', 'trim|required|callback_stripCommas|numeric');
     $this->form_validation->set_message('is_natural_no_zero', 'Please select an entry for %s');
     $this->form_validation->set_rules('ddlShiftStart', 'Shift Starting Time', 'trim|required|is_natural_no_zero');
     $this->form_validation->set_rules('ddlShiftDuration', 'Shift Duration', 'trim|required');
     $this->form_validation->set_rules('ddlJobCode', 'Job Code', 'trim');
     if ($this->form_validation->run() == FALSE) {
         $displayData['formData'] = new stdClass();
         $params = array('enumStyle' => 'terse');
         $this->load->library('generic_rpt', $params);
         $this->load->model('vols/mvol_events', 'clsVolEvents');
         $this->clsVolEvents->loadEventsViaEID($lEventID);
         $displayData['contextSummary'] = $this->clsVolEvents->volEventHTMLSummary(0);
         $this->load->library('generic_form');
         if (validation_errors() == '') {
             $displayData['formData']->txtShiftName = $shift->strShiftName;
             $displayData['formData']->txtShiftNotes = $shift->strDescription;
             $displayData['formData']->txtNumVols = $shift->lNumVolsNeeded;
             $displayData['formData']->lEventStartTime = strDisplayTimeDDL($shift->dteEventStartTime, true);
             $displayData['formData']->enumDuration = strDurationDDL(true, true, $shift->enumDuration);
             // load job code ddl
             $displayData['strDDLJobCode'] = $this->cList->strLoadListDDL('ddlJobCode', true, $shift->lJobCode);
         } else {
             setOnFormError($displayData);
             $displayData['formData']->txtShiftName = set_value('txtShiftName');
             $displayData['formData']->txtShiftNotes = set_value('txtShiftNotes');
             $displayData['formData']->txtNumVols = set_value('txtNumVols');
             $displayData['formData']->lEventStartTime = strDisplayTimeDDL(set_value('ddlShiftStart'), true);
             $displayData['formData']->enumDuration = strDurationDDL(true, true, set_value('ddlShiftDuration'));
             // load job code ddl
             $displayData['strDDLJobCode'] = $this->cList->strLoadListDDL('ddlJobCode', true, set_value('ddlJobCode'));
         }
         //--------------------------
         // breadcrumbs
         //--------------------------
         $displayData['pageTitle'] = anchor('main/menu/vols', 'Volunteers', 'class="breadcrumb"') . ' | ' . anchor('volunteers/events_schedule/viewEventsList', 'Event List', 'class="breadcrumb"') . ' | ' . anchor('volunteers/events_record/viewEvent/' . $lEventID, 'Event', 'class="breadcrumb"') . ' | ' . anchor('volunteers/event_dates_view/viewDates/' . $lEventDateID, 'Event Date', 'class="breadcrumb"') . ' | ' . ($bNew ? 'Add New' : 'Edit') . ' Event Shift';
         $displayData['title'] = CS_PROGNAME . ' | Volunteers';
         $displayData['nav'] = $this->mnav_brain_jar->navData();
         $displayData['mainTemplate'] = 'vols/vol_event_date_shift_add_edit_view';
         $this->load->vars($displayData);
         $this->load->view('template');
     } else {
         $shift->strShiftName = trim($_POST['txtShiftName']);
         $shift->strDescription = trim($_POST['txtShiftNotes']);
         $shift->dteEventStartTime = (int) $_POST['ddlShiftStart'];
         $shift->enumDuration = $_POST['ddlShiftDuration'];
         $shift->lNumVolsNeeded = (int) $_POST['txtNumVols'];
         $shift->lJobCode = (int) $_POST['ddlJobCode'];
         if ($shift->lJobCode <= 0) {
             $shift->lJobCode = null;
         }
         if ($bNew) {
             $lShiftID = $this->clsShifts->lAddNewEventShift();
         } else {
             $shift->lKeyID = $lShiftID;
             $this->clsShifts->updateEventShift();
         }
         $this->session->set_flashdata('msg', 'The event shift was ' . ($bNew ? 'added' : 'updated'));
         redirect('/volunteers/event_dates_view/viewDates/' . $lEventDateID);
     }
 }