public function addEditTestResults($lTestLogID, $lClientID, $lPPTestID)
 {
     //-------------------------------------------------------------------------
     //
     //-------------------------------------------------------------------------
     global $gbDateFormatUS;
     if (!bTestForURLHack('showClients')) {
         return;
     }
     $this->load->helper('dl_util/verify_id');
     verifyID($this, $lClientID, 'client ID');
     verifyID($this, $lPPTestID, 'pre/post test ID');
     $displayData = array();
     $displayData['js'] = '';
     $displayData['lTestLogID'] = $lTestLogID = (int) $lTestLogID;
     $displayData['lClientID'] = $lClientID = (int) $lClientID;
     $displayData['lPPTestID'] = $lPPTestID = (int) $lPPTestID;
     $bNew = $lTestLogID <= 0;
     //-------------------------
     // models & helpers
     //-------------------------
     $this->load->model('client_features/mcpre_post_tests', 'cpptests');
     $this->load->model('admin/mpermissions', 'perms');
     $this->load->helper('clients/link_client_features');
     $this->load->library('util/dl_date_time', '', 'clsDateTime');
     $this->load->helper('dl_util/time_date');
     // for date verification
     $this->load->model('clients/mclients', 'clsClients');
     $this->load->helper('dl_util/web_layout');
     $this->load->helper('clients/client');
     $this->load->helper('js/check_boxes_in_div');
     $params = array('enumStyle' => 'terse');
     $this->load->library('generic_rpt', $params);
     $displayData['js'] .= checkUncheckInDiv();
     /*      
     $zzzlPos = strrpos(__FILE__, '\\'); $zzzlLen=strlen(__FILE__); echo('<font class="debug">'.substr(__FILE__, strrpos(__FILE__, '\\',-(($zzzlLen-$zzzlPos)+1))) .': '.__LINE__
     .":\$displayData['js'] = ".htmlspecialchars($displayData['js'])." <br></font>\n");
     */
     //-------------------------------------
     // load the client info
     //-------------------------------------
     $this->clsClients->loadClientsViaClientID($lClientID);
     $displayData['client'] = $this->clsClients->clients[0];
     //-------------------------
     // load the pre/post test
     //-------------------------
     $this->cpptests->loadPPTestsViaPPTID($lPPTestID);
     $displayData['pptest'] = $pptest =& $this->cpptests->pptests[0];
     $displayData['lPPTestID'] = $lPPTestID = $pptest->lKeyID;
     //-------------------------
     // load the test log
     //-------------------------
     $this->cpptests->loadTestLogViaTestLogID($lTestLogID, $lNumTests, $testLogInfo);
     $testInfo =& $testLogInfo[0];
     $this->cpptests->loadClientScores($lTestLogID, $lPPTestID, $lNumQuest, $QandA);
     $displayData['lNumQuests'] = $lNumQuest;
     $displayData['QandA'] =& $QandA;
     //-------------------------------------
     // validation rules
     //-------------------------------------
     $this->form_validation->set_error_delimiters('<div class="formError">', '</div>');
     $this->form_validation->set_rules('txtPretestDate', 'Pre-Test Date', 'trim|required' . '|callback_verifyDateValid');
     $this->form_validation->set_rules('txtPosttestDate', 'Post-Test Date', 'trim|required' . '|callback_verifyDateValid|callback_verifyCBH');
     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 ($bNew) {
                 $displayData['txtPretestDate'] = $displayData['txtPosttestDate'] = '';
             } else {
                 $displayData['txtPretestDate'] = strNumericDateViaUTS($testInfo->dtePreTest, $gbDateFormatUS);
                 $displayData['txtPosttestDate'] = strNumericDateViaUTS($testInfo->dtePostTest, $gbDateFormatUS);
             }
         } else {
             setOnFormError($displayData);
             $displayData['txtPretestDate'] = set_value('txtPretestDate');
             $displayData['txtPosttestDate'] = set_value('txtPosttestDate');
             $this->loadQAs($QandA);
         }
         /*-------------------------------------
              load the client summary block
           -------------------------------------*/
         $this->load->model('img_docs/mimage_doc', 'clsImgDoc');
         $this->load->helper('img_docs/image_doc');
         $this->load->helper('img_docs/link_img_docs');
         $params = array('enumStyle' => 'terse');
         $this->load->library('generic_rpt', $params, 'generic_rpt');
         $displayData['clsRpt'] = $this->generic_rpt;
         $displayData['contextSummary'] = $this->clsClients->strClientHTMLSummary(0);
         //-------------------------------------
         // stripes
         //-------------------------------------
         $this->load->model('util/mbuild_on_ready', 'clsOnReady');
         $this->clsOnReady->addOnReadyTableStripes();
         $this->clsOnReady->closeOnReady();
         $displayData['js'] .= $this->clsOnReady->strOnReady;
         //-------------------------------------
         // breadcrumbs and page layout
         //-------------------------------------
         $displayData['pageTitle'] = anchor('main/menu/client', 'Clients', 'class="breadcrumb"') . ' | ' . anchor('clients/client_record/view/' . $lClientID, 'Client Record', 'class="breadcrumb"') . ' | Pre/Post Test';
         $displayData['title'] = CS_PROGNAME . ' | Clients';
         $displayData['nav'] = $this->mnav_brain_jar->navData();
         $displayData['mainTemplate'] = 'cpre_post_tests/client_record_test_view';
         $this->load->vars($displayData);
         $this->load->view('template');
     } else {
         $this->loadQAs($QandA);
         $strDate = trim($_POST['txtPretestDate']);
         MDY_ViaUserForm($strDate, $lMon, $lDay, $lYear, $gbDateFormatUS);
         $testInfo->dtePreTest = strtotime($lMon . '/' . $lDay . '/' . $lYear);
         $strDate = trim($_POST['txtPosttestDate']);
         MDY_ViaUserForm($strDate, $lMon, $lDay, $lYear, $gbDateFormatUS);
         $testInfo->dtePostTest = strtotime($lMon . '/' . $lDay . '/' . $lYear);
         //------------------------------------
         // update db tables and return
         //------------------------------------
         if ($bNew) {
             $testInfo->lClientID = $lClientID;
             $testInfo->lPrePostID = $lPPTestID;
             $lTestLogID = $this->cpptests->lAddTestLogEntry($testInfo);
             $this->session->set_flashdata('msg', 'New test results added');
         } else {
             $this->cpptests->updateTestLogEntry($lTestLogID, $testInfo);
             $this->session->set_flashdata('msg', 'Test results updated');
         }
         $this->cpptests->saveTestResults($lTestLogID, $QandA);
         redirect_Client($lClientID);
     }
 }
 function addEditEvent($lEventID)
 {
     //---------------------------------------------------------------------
     //
     //---------------------------------------------------------------------
     global $gdteNow, $gbDateFormatUS;
     if (!bTestForURLHack('editPeopleBizVol')) {
         return;
     }
     $this->load->helper('dl_util/verify_id');
     if ($lEventID . '' != '0') {
         verifyID($this, $lEventID, 'event ID');
     }
     $displayData = array();
     $displayData['formData'] = new stdClass();
     $displayData['lEventID'] = $lEventID = (int) $lEventID;
     $displayData['bNew'] = $bNew = $lEventID <= 0;
     $displayData['js'] = '';
     /*
     			//-------------------------------
     			// javascript verification
     			//-------------------------------
     		$this->load->library('js_build/js_verify');
     		$this->load->helper('js/verify_vol_event');
     		$this->load->helper('js/verify_recurring');
     		$this->load->helper('dl_util/page_title');
     		$this->js_verify = new js_verify;
     		$this->js_verify->clearEmbedOpts();
     		$this->js_verify->bShow_isValidDate		  =
     		$this->js_verify->bShow_bVerifyString	  =
     		$this->js_verify->bShow_bVerifyRadio	  =
     		$this->js_verify->bShow_strRadioSelValue =
     		$this->js_verify->bShow_trim				  = true;
     		$displayData['js'] .= $this->js_verify->loadJavaVerify();
     		$displayData['js'] .= volEventVerify();
     		$displayData['js'] .= verifyRecurring();
     */
     //-------------------------
     // models & helpers
     //-------------------------
     $this->load->helper('dl_util/time_date');
     // for date verification
     $this->load->library('generic_form');
     $clsForm = new generic_form();
     // note - this form uses javascript verification due to the recurring options
     // (may be replaced by CI verification in the future)
     $this->load->model('vols/mvol_events', 'clsVolEvents');
     $this->load->model('vols/mvol_event_dates', 'clsVolEventDates');
     $this->load->model('util/mrecurring', 'clsRecurring');
     $this->load->helper('dl_util/recurring');
     $this->load->helper('dl_util/web_layout');
     $this->load->library('js_build/java_joe_radio');
     $clsJJR = new java_joe_radio();
     //-------------------------
     // validation rules
     //-------------------------
     $this->form_validation->set_error_delimiters('<div class="formError">', '</div>');
     $this->form_validation->set_rules('txtEvent', 'Event Name', 'trim|required');
     $this->form_validation->set_rules('txtNote', 'Decscription', 'trim');
     $this->form_validation->set_rules('txtLocation', 'Location', 'trim');
     $this->form_validation->set_rules('txtContact', 'Contact', 'trim');
     $this->form_validation->set_rules('txtPhone', 'Phone', 'trim');
     $this->form_validation->set_rules('txtEmail', 'EMail', 'trim|valid_email');
     $this->form_validation->set_rules('txtWebLink', 'Web Site', 'trim');
     if ($bNew) {
         $this->form_validation->set_rules('txtStart', 'Starting Date', 'trim|required|callback_verifyRecurring');
     }
     $this->clsVolEvents->loadEventsViaEID($lEventID);
     $event = $this->clsVolEvents->events[0];
     if ($this->form_validation->run() == FALSE) {
         $displayData['formData'] = new stdClass();
         $this->load->library('generic_form');
         $displayData['clsForm'] =& $clsForm;
         $displayData['strForm'] = $strForm = 'frmEditVolEvent';
         // first time displayed, no user data entry errors
         if (validation_errors() == '') {
             $displayData['formData']->strEventName = htmlspecialchars($event->strEventName);
             $displayData['formData']->strDescription = htmlspecialchars($event->strDescription);
             $displayData['formData']->strLocation = htmlspecialchars($event->strLocation);
             $displayData['formData']->strContact = htmlspecialchars($event->strContact);
             $displayData['formData']->strPhone = htmlspecialchars($event->strPhone);
             $displayData['formData']->strEmail = htmlspecialchars($event->strEmail);
             $displayData['formData']->strWebSite = htmlspecialchars($event->strWebSite);
             if ($bNew) {
                 $strDate = strNumericDateViaUTS($gdteNow, $gbDateFormatUS);
                 $selects = null;
                 $displayData['recurringOpts'] = strRecurringOpts($displayData, $clsForm, $selects, $strForm, $clsJJR, $strDate, $this->clsRecurring, 'txtStart', 'Event on', 'Event Schedule', 'Event on');
             }
         } else {
             setOnFormError($displayData);
             $strDate = set_value('txtStart');
             $displayData['formData']->strEventName = set_value('txtEvent');
             $displayData['formData']->strDescription = set_value('txtNote');
             $displayData['formData']->strLocation = set_value('txtLocation');
             $displayData['formData']->strContact = set_value('txtContact');
             $displayData['formData']->strPhone = set_value('txtPhone');
             $displayData['formData']->strEmail = set_value('txtEmail');
             $displayData['formData']->strWebSite = set_value('txtWebLink');
             if ($bNew) {
                 $selects = new stdClass();
                 $selects->lNumRecur = (int) $_POST['ddlRecur'];
                 $selects->rdoRecur = @$_POST['rdoRecur'];
                 $selects->rdoFixedLoose = @$_POST['rdoFixedLoose'];
                 $selects->chkWkSun = @$_POST['chkWkSun'] == 'TRUE';
                 $selects->chkWkMon = @$_POST['chkWkMon'] == 'TRUE';
                 $selects->chkWkTue = @$_POST['chkWkTue'] == 'TRUE';
                 $selects->chkWkWed = @$_POST['chkWkWed'] == 'TRUE';
                 $selects->chkWkThu = @$_POST['chkWkThu'] == 'TRUE';
                 $selects->chkWkFri = @$_POST['chkWkFri'] == 'TRUE';
                 $selects->chkWkSat = @$_POST['chkWkSat'] == 'TRUE';
                 $selects->chkWeekDaysOnly = @$_POST['chkWeekDaysOnly'] == 'TRUE';
                 $selects->chkFixed = array();
                 for ($idx = 1; $idx <= 31; ++$idx) {
                     $selects->chkFixed[$idx] = @$_POST['chkFixed' . $idx] == 'on';
                 }
                 $selects->chkRel_1st = @$_POST['chkRel_1st'] == 'TRUE';
                 $selects->chkRel_2nd = @$_POST['chkRel_2nd'] == 'TRUE';
                 $selects->chkRel_3rd = @$_POST['chkRel_3rd'] == 'TRUE';
                 $selects->chkRel_4th = @$_POST['chkRel_4th'] == 'TRUE';
                 $selects->chkRel_5th = @$_POST['chkRel_5th'] == 'TRUE';
                 $selects->chkRel_last = @$_POST['chkRel_last'] == 'TRUE';
                 $selects->chkRelSun = @$_POST['chkRelSun'] == 'on';
                 $selects->chkRelMon = @$_POST['chkRelMon'] == 'on';
                 $selects->chkRelTue = @$_POST['chkRelTue'] == 'on';
                 $selects->chkRelWed = @$_POST['chkRelWed'] == 'on';
                 $selects->chkRelThu = @$_POST['chkRelThu'] == 'on';
                 $selects->chkRelFri = @$_POST['chkRelFri'] == 'on';
                 $selects->chkRelSat = @$_POST['chkRelSat'] == 'on';
                 $displayData['recurringOpts'] = strRecurringOpts($displayData, $clsForm, $selects, $strForm, $clsJJR, $strDate, $this->clsRecurring, 'txtStart', 'Event on', 'Event Schedule', 'Event on');
             }
         }
         //--------------------------
         // breadcrumbs
         //--------------------------
         $displayData['pageTitle'] = anchor('main/menu/vols', 'Volunteers', 'class="breadcrumb"') . ' | ' . anchor('volunteers/events_schedule/viewEventsList', 'Event List', 'class="breadcrumb"');
         if (!$bNew) {
             $displayData['pageTitle'] .= ' | ' . anchor('volunteers/events_record/viewEvent/' . $lEventID, 'Event', 'class="breadcrumb"');
         }
         $displayData['pageTitle'] .= ' | ' . ($bNew ? 'Add New' : 'Edit') . '  Event';
         $displayData['title'] = CS_PROGNAME . ' | Vol. Events';
         $displayData['nav'] = $this->mnav_brain_jar->navData();
         $displayData['mainTemplate'] = 'vols/event_add_edit_view';
         $this->load->vars($displayData);
         $this->load->view('template');
     } else {
         $this->eventUpdate($lEventID);
     }
 }
 function addEditMeasurement($lClientID, $lMeasureID = '0')
 {
     //---------------------------------------------------------------
     //
     //---------------------------------------------------------------
     global $gbDateFormatUS, $gstrFormatDatePicker, $gdteNow, $genumMeasurePref, $gbMetric;
     $this->load->helper('dl_util/verify_id');
     verifyID($this, $lClientID, 'client ID');
     $displayData = array();
     $displayData['lClientID'] = $lClientID;
     $displayData['lMeasureID'] = $lMeasureID = (int) $lMeasureID;
     $displayData['bNew'] = $bNew = $lMeasureID <= 0;
     $displayData['js'] = '';
     /*------------------------------------------------
           models/libraries/helpers
       ------------------------------------------------*/
     $this->load->model('emr/mmeasurements', 'emrMeas');
     $this->load->model('clients/mclients', 'clsClients');
     $this->load->library('util/dl_date_time', '', 'clsDateTime');
     $this->load->helper('dl_util/time_date');
     $this->load->helper('dl_util/web_layout');
     $this->load->helper('emr/link_emr');
     $this->clsClients->loadClientsViaClientID($lClientID);
     $displayData['client'] = $client =& $this->clsClients->clients[0];
     $displayData['bShowOFC'] = $bShowOFC = $client->lAgeYears < 3;
     $this->emrMeas->loadMeasurementViaMeasID($lMeasureID);
     $measure =& $this->emrMeas->measurements[0];
     // validation rules
     $this->form_validation->set_error_delimiters('<div class="formError">', '</div>');
     $this->form_validation->set_rules('txtNotes', 'Notes', 'trim');
     //		$this->form_validation->set_rules('txtHeight',  'Height',     'trim|callback_stripCommas|numeric|callback_measVerifyHeight');
     $this->form_validation->set_rules('txtHeight', 'Height', 'callback_measVerifyHeight');
     $this->form_validation->set_rules('txtWeight', 'Weight', 'trim|callback_stripCommas|numeric|callback_measVerifyWeight');
     $this->form_validation->set_rules('txtOFC', 'OFC/Head Circumference', 'trim|callback_stripCommas|numeric|callback_measVerifyOFC');
     $this->form_validation->set_rules('txtDate', 'Measurement Date', 'trim|required' . '|callback_measRecVerifyDateValid' . '|callback_measRecVerifyDatePast');
     if ($this->form_validation->run() == FALSE) {
         $this->emrMeas->lNumMeasureViaCID($lClientID, true, true, true);
         /*-------------------------------------
               client summary
           -------------------------------------*/
         $displayData['formData'] = new stdClass();
         $this->load->model('img_docs/mimage_doc', 'clsImgDoc');
         $this->load->helper('img_docs/image_doc');
         $this->load->helper('img_docs/link_img_docs');
         $params = array('enumStyle' => 'terse');
         $this->load->library('generic_rpt', $params, 'generic_rpt');
         $displayData['clsRpt'] = $this->generic_rpt;
         $displayData['contextSummary'] = $this->clsClients->strClientHTMLSummary(0);
         /*-------------------------------------
              stripes
           -------------------------------------*/
         $this->load->model('util/mbuild_on_ready', 'clsOnReady');
         $this->clsOnReady->addOnReadyTableStripes();
         $this->clsOnReady->closeOnReady();
         $displayData['js'] .= $this->clsOnReady->strOnReady;
         $this->load->library('generic_form');
         if (validation_errors() == '') {
             if ($bNew) {
                 $displayData['formData']->strDate = strNumericDateViaUTS($gdteNow, $gbDateFormatUS);
                 $displayData['formData']->txtHeight = '';
                 $displayData['formData']->txtWeight = '';
                 $displayData['formData']->txtOFC = '';
                 $displayData['formData']->txtNotes = '';
             } else {
                 $displayData['formData']->strDate = strNumericDateViaUTS($measure->dteMeasurement, $gbDateFormatUS);
                 if ($gbMetric) {
                     $this->setMeasure($measure->sngHeightCM, $displayData['formData']->txtHeight, 1);
                     $this->setMeasure($measure->sngWeightKilos, $displayData['formData']->txtWeight, 1);
                     $this->setMeasure($measure->sngHeadCircCM, $displayData['formData']->txtOFC, 1);
                 } else {
                     $this->setMeasure($measure->sngHeightIn, $displayData['formData']->txtHeight, 1);
                     $this->setMeasure($measure->sngWeightLBS, $displayData['formData']->txtWeight, 1);
                     $this->setMeasure($measure->sngHeadCircIn, $displayData['formData']->txtOFC, 1);
                     $displayData['formData']->txtNotes = htmlspecialchars($measure->strNotes);
                 }
             }
         } else {
             setOnFormError($displayData);
             $displayData['formData']->strDate = set_value('txtDate');
             $displayData['formData']->txtHeight = set_value('txtHeight');
             $displayData['formData']->txtWeight = set_value('txtWeight');
             $displayData['formData']->txtOFC = set_value('txtOFC');
             $displayData['formData']->txtNotes = set_value('txtNotes');
         }
         //--------------------------
         // breadcrumbs
         //--------------------------
         $displayData['pageTitle'] = anchor('main/menu/client', 'Clients', 'class="breadcrumb"') . ' | ' . anchor('clients/client_record/view/' . $lClientID, 'Client Record', 'class="breadcrumb"') . ' | ' . anchor('emr/measurements/viewMeasurement/' . $lClientID, 'Measurements', 'class="breadcrumb"') . ' | ' . ($bNew ? 'Add' : 'Edit') . ' Measurements';
         $displayData['title'] = CS_PROGNAME . ' | Clients';
         $displayData['nav'] = $this->mnav_brain_jar->navData();
         $displayData['mainTemplate'] = 'emr/measurements_add_edit_view';
         $this->load->vars($displayData);
         $this->load->view('template');
     } else {
         $measure->lClientID = $lClientID;
         $strDate = trim($_POST['txtDate']);
         MDY_ViaUserForm($strDate, $lMon, $lDay, $lYear, $gbDateFormatUS);
         $measure->mySQLDateMeasure = strMoDaYr2MySQLDate($lMon, $lDay, $lYear);
         $measure->sngHeightCM = $this->strPrepMeasureForDB(trim($_POST['txtHeight']), $gbMetric ? CSTR_UNITS_CM : CSTR_UNITS_IN);
         $measure->sngWeightKilos = $this->strPrepMeasureForDB(trim($_POST['txtWeight']), $gbMetric ? CSTR_UNITS_KG : CSTR_UNITS_LB);
         $measure->sngHeadCircCM = $this->strPrepMeasureForDB(trim($_POST['txtOFC']), $gbMetric ? CSTR_UNITS_CM : CSTR_UNITS_IN);
         $measure->strNotes = trim($_POST['txtNotes']);
         if ($bNew) {
             $this->emrMeas->addNewMeasure();
             $this->session->set_flashdata('msg', 'The client measurements were added.');
         } else {
             $this->emrMeas->updateMeasure($lMeasureID);
             $this->session->set_flashdata('msg', 'The client measurements were updated.');
         }
         redirect_ClientMeasure($lClientID);
     }
     /*
     
           $displayData['client']    = $client    = $clsClients->clients[0];
     
           if (is_null($client->lLocationID)){
              $client->lLocationID  = (integer)$_POST['lLocationID'];
              $client->lStatusCatID = (integer)$_POST['lStatusCatID'];
              $client->lVocID       = (integer)$_POST['lVocID'];
           }
     
              // models associated with the client record
           $this->load->model('clients/mclient_locations',         'clsLocation');
           $this->load->model('sponsorship/msponsorship_programs', 'clsSponProg');
           $this->load->model('clients/mclient_status',            'clsClientStat');
           $this->load->model('clients/mclient_vocabulary',        'clsClientV');
           $this->load->helper('dl_util/time_date');
           $this->load->helper('dl_util/web_layout');
     
              // validation rules
           $this->form_validation->set_error_delimiters('<div class="formError">', '</div>');
           $this->form_validation->set_rules('txtFName',      'Client\'s First Name',  'trim|required');
           $this->form_validation->set_rules('txtMName',      'Client\'s Middle Name', 'trim');
           $this->form_validation->set_rules('txtLName',      'Client\'s Last Name',   'trim');
           $this->form_validation->set_rules('txtBDate',      'Birth date', 'trim|required|callback_clientRecVerifyBDateValid'
                                                                                        .'|callback_clientRecVerifyBDatePast');
           $this->form_validation->set_rules('txtPEntryDate', 'Enrollment date', 'trim|required|callback_clientRecVerifyEDateValid'
                                                                                             .'|callback_clientRecVerifyEDatePast');
           $this->form_validation->set_rules('txtMaxSpon',    'Max # of Sponsors',   'trim|required|is_natural');
           $this->form_validation->set_rules('rdoGender',     'Gender',   'required');
           $this->form_validation->set_rules('txtBio',        'Bio',      'trim');
           $this->form_validation->set_rules('ddlAttrib',     'Attributed to');
     
           $this->form_validation->set_rules('txtAddr1',      '',  'trim');
           $this->form_validation->set_rules('txtAddr2',      '',  'trim');
           $this->form_validation->set_rules('txtCity',       '',  'trim');
           $this->form_validation->set_rules('txtState',      '',  'trim');
           $this->form_validation->set_rules('txtZip',        '',  'trim');
           $this->form_validation->set_rules('txtCountry',    '',  'trim');
           $this->form_validation->set_rules('txtEmail',      'Email',  'trim|valid_email');
           $this->form_validation->set_rules('txtPhone',      '',  'trim');
           $this->form_validation->set_rules('txtCell',       '',  'trim');
     
           if ($bNew){
              $this->form_validation->set_rules('ddlStatus',  '',      'required|callback_clientRecVerifyInitStat');
           }
     
           if ($this->form_validation->run() == FALSE){
              $this->load->model  ('util/mlist_generic',     'clsList');
              $this->clsList->enumListType = CENUM_LISTTYPE_ATTRIB;
     
              $displayData['formData'] = new stdClass;
              $displayData['lLocationID'] = $lLocationID = $this->clsLocation->cl_lKeyID = $client->lLocationID;
              $this->clsLocation->loadLocationRec($lLocationID);
     
              $displayData['lVocID'] = $lVocID = $this->clsClientV->lVocID = $client->lVocID;
              $this->clsClientV->loadClientVocabulary(true, false);
              $displayData['clsClientV']  = $this->clsClientV;
              $displayData['clsLocation'] = $this->clsLocation;
              $this->clsSponProg->loadSponProgsViaLocID($lLocationID);
              $displayData['clsSponProg']   = $this->clsSponProg;
              $displayData['clsClientStat'] = $this->clsClientStat;
     
              $lSCID = $client->lStatusCatID;
              $this->clsClientStat->loadClientStatCatsEntries(
                                 true,  $lSCID,
                                 false, null,
                                 true,  false);
     
              $strMessage = '<font color="red">One or more client status entries must be established before
                                  adding clients.</font>';
              $displayData['bNoStatEntries'] = $bNoStatEntries = $this->clsClientStat->bTestNoStatEntries(
                                                $lSCID, true, $strMessage, $displayData['strNoStatErrMsg']);
     
     
              $this->load->library('generic_form');
     
              if (validation_errors()==''){
                 $displayData['formData']->txtFName = htmlspecialchars($client->strFName);
                 $displayData['formData']->txtMName = htmlspecialchars($client->strMName);
                 $displayData['formData']->txtLName = htmlspecialchars($client->strLName);
                 $displayData['strAttribDDL'] = $this->clsList->strLoadListDDL('ddlAttrib', true, $client->lAttribID);
     
                 if (is_null($client->dteBirth)){
                    $displayData['formData']->txtBDate = '';
                 }else {
                    $displayData['formData']->txtBDate = strNumericDateViaMysqlDate($client->dteBirth, $gbDateFormatUS);
                 }
                 if (is_null($client->dteEnrollment)){
                    $displayData['formData']->txtPEntryDate = '';
                 }else {
                    $displayData['formData']->txtPEntryDate = date($gstrFormatDatePicker, $client->dteEnrollment);
                 }
                 if ($bNew) $displayData['formData']->lInitStatID = -1;
     
                 if ($this->clsSponProg->lNumSponPrograms > 0){
                    foreach ($this->clsSponProg->sponProgs as $clsLocSP){
                       $lSCID = $clsLocSP->lKeyID;
                       $clsLocSP->bSupported = $this->clsSponProg->bClientInSponProgram($lClientID, $lSCID, $lcsp_lKeyID);
                    }
                 }
                 $displayData['formData']->txtMaxSpon = $client->lMaxSponsors;
                 $displayData['formData']->rdoGender  = $client->enumGender;
                 $displayData['formData']->txtBio     = htmlspecialchars($client->strBio);
     
                 $displayData['formData']->txtAddr1    = htmlspecialchars($client->strAddr1);
                 $displayData['formData']->txtAddr2    = htmlspecialchars($client->strAddr2);
                 $displayData['formData']->txtCity     = htmlspecialchars($client->strCity);
                 $displayData['formData']->txtState    = htmlspecialchars($client->strState);
                 $displayData['formData']->txtZip      = htmlspecialchars($client->strZip);
                 $displayData['formData']->txtCountry  = htmlspecialchars($client->strCountry);
                 $displayData['formData']->txtEmail    = htmlspecialchars($client->strEmail);
                 $displayData['formData']->txtPhone    = htmlspecialchars($client->strPhone);
                 $displayData['formData']->txtCell     = htmlspecialchars($client->strCell);
     
              }else{
                 setOnFormError($displayData);
                 $displayData['strAttribDDL']            = $this->clsList->strLoadListDDL('ddlAttrib', true, set_value('ddlAttrib'));
                 $displayData['formData']->txtFName      = set_value('txtFName');
                 $displayData['formData']->txtMName      = set_value('txtMName');
                 $displayData['formData']->txtLName      = set_value('txtLName');
                 $displayData['formData']->txtBDate      = set_value('txtBDate');
                 $displayData['formData']->txtPEntryDate = set_value('txtPEntryDate');
     
                 if ($bNew) $displayData['formData']->lInitStatID = set_value('ddlStatus');
     
                    // couldn't find a ci form validation way to do this....
                 if ($this->clsSponProg->lNumSponPrograms > 0){
                    if (isset($_POST['chkSP'])){
                       foreach ($this->clsSponProg->sponProgs as $clsLocSP){
                          $lSCID = $clsLocSP->lKeyID;
                          $clsLocSP->bSupported = in_array($lSCID, $_POST['chkSP']);
                       }
                    }
                 }
     
                 $displayData['formData']->txtMaxSpon = set_value('txtMaxSpon');
                 $displayData['formData']->rdoGender  = set_value('rdoGender');
                 $displayData['formData']->txtBio     = set_value('txtBio');
     
                 $displayData['formData']->txtAddr1   = set_value('txtAddr1');
                 $displayData['formData']->txtAddr2   = set_value('txtAddr2');
                 $displayData['formData']->txtCity    = set_value('txtCity');
                 $displayData['formData']->txtState   = set_value('txtState');
                 $displayData['formData']->txtZip     = set_value('txtZip');
                 $displayData['formData']->txtCountry = set_value('txtCountry');
                 $displayData['formData']->txtEmail   = set_value('txtEmail');
                 $displayData['formData']->txtPhone   = set_value('txtPhone');
                 $displayData['formData']->txtCell    = set_value('txtCell');
              }
     
                 //--------------------------
                 // breadcrumbs
                 //--------------------------
              if ($lClientID > 0){
                 $displayData['pageTitle']      = anchor('main/menu/client',                      'Clients', 'class="breadcrumb"')
                                           .' | '.anchor('clients/client_record/view/'.$lClientID, 'Client Record', 'class="breadcrumb"')
                                           .' | Edit Client Record';
              }else {
                 $displayData['pageTitle']      = anchor('main/menu/client',                      'Clients', 'class="breadcrumb"')
                                           .' | Add New Client Record';
              }
     
              $displayData['title']          = CS_PROGNAME.' | Clients';
              $displayData['nav']            = $this->mnav_brain_jar->navData();
     
              $displayData['mainTemplate']   = 'client/client_add_edit_view';
              $this->load->vars($displayData);
              $this->load->view('template');
           }else {
              $strBDate   = trim($_POST['txtBDate']);
              MDY_ViaUserForm($strBDate, $lMon, $lDay, $lYear, $gbDateFormatUS);
              $client->dteBirth = strMoDaYr2MySQLDate($lMon, $lDay, $lYear);
     
              $strEnrollDate = trim($_POST['txtPEntryDate']);
              MDY_ViaUserForm($strEnrollDate, $lMon, $lDay, $lYear, $gbDateFormatUS);
              $client->dteEnrollment = strtotime($lMon.'/'.$lDay.'/'.$lYear);
     
              $client->strFName      = trim($_POST['txtFName']);
              $client->strMName      = trim($_POST['txtMName']);
              $client->strLName      = trim($_POST['txtLName']);
              $client->strBio        = trim($_POST['txtBio']);
              $client->enumGender    = trim($_POST['rdoGender']);
              $client->lMaxSponsors  = (integer)trim($_POST['txtMaxSpon']);
     
              $client->strAddr1      = trim($_POST['txtAddr1']);
              $client->strAddr2      = trim($_POST['txtAddr2']);
              $client->strCity       = trim($_POST['txtCity']);
              $client->strState      = trim($_POST['txtState']);
              $client->strZip        = trim($_POST['txtZip']);
              $client->strCountry    = trim($_POST['txtCountry']);
              $client->strEmail      = trim($_POST['txtEmail']);
              $client->strPhone      = trim($_POST['txtPhone']);
              $client->strCell       = trim($_POST['txtCell']);
     
              $lAttrib = (integer)$_REQUEST['ddlAttrib'];
              if ($lAttrib <= 0){
                 $client->lAttribID = null;
              }else {
                 $client->lAttribID = $lAttrib;
              }
     
              if ($bNew){
                 $this->load->model('personalization/muser_fields', 'clsUF');
                 $this->load->model('personalization/muser_fields_create', 'clsUFC');
                 $this->load->model ('admin/mpermissions',           'perms');
                 $lClientID = $this->clsClients->lAddNewClient();
                 $this->clsClientStat->clientStatus = array();
     
                 $status = $this->clsClientStat->clientStatus[0] = new stdClass;
                 $status->lClientID             = $lClientID;
                 $status->lStatusID             = (integer)trim($_POST['ddlStatus']);
                 $status->bIncludeNotesInPacket = false;
                 $status->dteStatus             = $gdteNow;
                 $status->strStatusTxt          = 'Initial status';
                 $this->clsClientStat->lInsertClientStatus();
                 $this->session->set_flashdata('msg', 'The client record was added');
              }else {
                 $clsClients->updateClientRec();
                 $this->session->set_flashdata('msg', 'The client record was updated');
              }
     
                 //----------------------------------------
                 // update supported sponsor categories
                 //----------------------------------------
              $this->clsSponProg->clearClientSponPrograms($lClientID);
              if (isset($_POST['chkSP'])){
                 foreach ($_POST['chkSP'] as $lSCID){
                    $this->clsSponProg->setClientSponProgram($lClientID, (integer)$lSCID);
                 }
              }
              redirect('clients/client_record/view/'.$client->lKeyID);
           }
     */
 }