function setRecurringScheduleControl($id)
 {
     $id = trim($id);
     $rsclf = new RecurringScheduleControlListFactory();
     if ($this->Validator->isResultSetWithRows('recurring_schedule', $rsclf->getByID($id), TTi18n::gettext('Recurring Schedule is invalid'))) {
         $this->data['recurring_schedule_control_id'] = $id;
         return TRUE;
     }
     return FALSE;
 }
     Debug::Text('Action: ' . $action, __FILE__, __LINE__, __METHOD__, 10);
     $saved_search_id = UserGenericDataFactory::searchFormDataHandler($action, $filter_data, URLBuilder::getURL(NULL, 'RecurringScheduleControlList.php'));
 default:
     BreadCrumb::setCrumb($title);
     extract(UserGenericDataFactory::getSearchFormData($saved_search_id, $sort_column));
     Debug::Text('Sort Column: ' . $sort_column, __FILE__, __LINE__, __METHOD__, 10);
     Debug::Text('Saved Search ID: ' . $saved_search_id, __FILE__, __LINE__, __METHOD__, 10);
     if (isset($filter_template_id) and $filter_template_id != '') {
         $filter_data['template_id'] = array($filter_template_id);
     }
     $sort_array = NULL;
     if ($sort_column != '') {
         $sort_array = array(Misc::trimSortPrefix($sort_column) => $sort_order);
     }
     URLBuilder::setURL($_SERVER['SCRIPT_NAME'], array('sort_column' => Misc::trimSortPrefix($sort_column), 'sort_order' => $sort_order, 'saved_search_id' => $saved_search_id, 'page' => $page));
     $rsclf = new RecurringScheduleControlListFactory();
     $ulf = new UserListFactory();
     if ($permission->Check('recurring_schedule', 'view') == FALSE) {
         if ($permission->Check('recurring_schedule', 'view_child')) {
             $filter_data['permission_children_ids'] = $permission_children_ids;
         }
         if ($permission->Check('recurring_schedule', 'view_own')) {
             $filter_data['permission_children_ids'][] = $current_user->getId();
         }
     }
     $rsclf->getSearchByCompanyIdAndArrayCriteria($current_company->getId(), $filter_data, $current_user_prefs->getItemsPerPage(), $page, NULL, $sort_array);
     $pager = new Pager($rsclf);
     $utlf = new UserTitleListFactory();
     $utlf->getByCompanyId($current_company->getId());
     $title_options = $utlf->getArrayByListFactory($utlf, FALSE, TRUE);
     $blf = new BranchListFactory();
//Add shifts 4hrs before they start.
$lookup_shift_offset = 3600 * 10;
//Lookup shifts that started X hrs before now.
$current_epoch = TTDate::getTime();
//$current_epoch = strtotime('06-Apr-07 6:00 AM');
Debug::text('Current Epoch: ' . TTDate::getDate('DATE+TIME', $current_epoch), __FILE__, __LINE__, __METHOD__, 10);
//Initial Start/End dates need to cover all timezones, we narrow it done further once we change to each users timezone later on.
$initial_start_date = TTDate::getBeginDayEpoch($current_epoch - $lookup_shift_offset);
$initial_end_date = $current_epoch + 86400;
Debug::text('Initial Start Date: ' . TTDate::getDate('DATE+TIME', $initial_start_date) . ' End Date: ' . TTDate::getDate('DATE+TIME', $initial_end_date), __FILE__, __LINE__, __METHOD__, 10);
$clf = new CompanyListFactory();
$clf->getAll();
if ($clf->getRecordCount() > 0) {
    foreach ($clf as $c_obj) {
        if ($c_obj->getStatus() != 30) {
            $rsclf = new RecurringScheduleControlListFactory();
            $rsclf->getByCompanyIdAndStartDateAndEndDate($c_obj->getId(), $initial_start_date, $initial_end_date);
            if ($rsclf->getRecordCount() > 0) {
                Debug::text('Recurring Schedule Control List Record Count: ' . $rsclf->getRecordCount(), __FILE__, __LINE__, __METHOD__, 10);
                foreach ($rsclf as $rsc_obj) {
                    //$rsclf->StartTransaction(); Wrap each individual schedule in its own transaction instead.
                    Debug::text('Recurring Schedule ID: ' . $rsc_obj->getID(), __FILE__, __LINE__, __METHOD__, 10);
                    //Debug::Arr($rsc_obj->getUser(), 'Users assigned to Schedule', __FILE__, __LINE__, __METHOD__, 10);
                    $user_ids = $rsc_obj->getUser();
                    $total_user_ids = count($user_ids);
                    if (is_array($user_ids) and $total_user_ids > 0) {
                        $i = 0;
                        foreach ($user_ids as $user_id) {
                            Debug::text('aaI: ' . $i . '/' . $total_user_ids . ' User ID: ' . $user_id, __FILE__, __LINE__, __METHOD__, 10);
                            //Get User object.
                            $ulf = new UserListFactory();
     }
     if ($rscf->isValid()) {
         $rscf->Save(FALSE);
         if (isset($data['user_ids'])) {
             $rscf->setUser($data['user_ids']);
         }
         if ($rscf->isValid()) {
             $rscf->Save();
             Redirect::Page(URLBuilder::getURL(NULL, 'RecurringScheduleControlList.php'));
             break;
         }
     }
 default:
     if (isset($id)) {
         BreadCrumb::setCrumb($title);
         $rsclf = new RecurringScheduleControlListFactory();
         $rsclf->getByIdAndCompanyId($id, $current_company->getID());
         foreach ($rsclf as $rsc_obj) {
             //Debug::Arr($station,'Department', __FILE__, __LINE__, __METHOD__,10);
             $data = array('id' => $rsc_obj->getId(), 'template_id' => $rsc_obj->getRecurringScheduleTemplateControl(), 'start_week' => $rsc_obj->getStartWeek(), 'start_date' => $rsc_obj->getStartDate(), 'end_date' => $rsc_obj->getEndDate(), 'auto_fill' => $rsc_obj->getAutoFill(), 'user_ids' => $rsc_obj->getUser(), 'created_date' => $rsc_obj->getCreatedDate(), 'created_by' => $rsc_obj->getCreatedBy(), 'updated_date' => $rsc_obj->getUpdatedDate(), 'updated_by' => $rsc_obj->getUpdatedBy(), 'deleted_date' => $rsc_obj->getDeletedDate(), 'deleted_by' => $rsc_obj->getDeletedBy());
         }
     } elseif ($action != 'submit') {
         Debug::Text('New Schedule', __FILE__, __LINE__, __METHOD__, 10);
         $data = array('start_week' => 1, 'start_date' => TTDate::getBeginWeekEpoch(TTDate::getTime()), 'end_date' => NULL);
     }
     //Select box options;
     $ulf = new UserListFactory();
     $ulf->getSearchByCompanyIdAndArrayCriteria($current_company->getId(), $filter_data);
     $user_options = UserListFactory::getArrayByListFactory($ulf, FALSE, TRUE);
     //$user_options = $ulf->getByCompanyIDArray( $current_company->getId(), TRUE );
     $rstclf = new RecurringScheduleTemplateControlListFactory();