//Sort Branches/Departments first
            foreach ($tmp_schedule_shifts as $day_epoch => $day_tmp_schedule_shift) {
                ksort($day_tmp_schedule_shift);
                $tmp_schedule_shifts[$day_epoch] = $day_tmp_schedule_shift;
                foreach ($day_tmp_schedule_shift as $branch => $department_schedule_shifts) {
                    ksort($tmp_schedule_shifts[$day_epoch][$branch]);
                }
            }
            //Sort each department by start time.
            foreach ($tmp_schedule_shifts as $day_epoch => $day_tmp_schedule_shift) {
                foreach ($day_tmp_schedule_shift as $branch => $department_schedule_shifts) {
                    foreach ($department_schedule_shifts as $department => $department_schedule_shift) {
                        //var_dump($department_schedule_shift);
                        $schedule_shifts[$day_epoch][$branch][$department] = Sort::multiSort($department_schedule_shift, 'start_time', 'last_name');
                    }
                }
            }
        }
        //print_r($schedule_shift_totals);
        $calendar_array = TTDate::getCalendarArray($start_date, $end_date, $current_user_prefs->getStartWeekDay(), FALSE);
        $smarty->assign_by_ref('calendar_array', $calendar_array);
        $hlf = TTnew('HolidayListFactory');
        $holiday_array = $hlf->getArrayByPolicyGroupUserId($user_ids, $start_date, $end_date);
        $smarty->assign_by_ref('holidays', $holiday_array);
        $smarty->assign_by_ref('schedule_shifts', $schedule_shifts);
        $smarty->assign_by_ref('schedule_shift_totals', $schedule_shift_totals);
        $smarty->assign_by_ref('do', $do);
        break;
}
Debug::writeToLog();
$smarty->display('schedule/ViewScheduleWeek.tpl');
 function getSchedule($filter_data, $start_week_day = 0, $group_schedule = FALSE)
 {
     global $current_user, $current_user_prefs;
     //Individual is one schedule per employee, or all on one schedule.
     if (!is_array($filter_data)) {
         return FALSE;
     }
     $current_epoch = time();
     //Debug::Text('Start Date: '. TTDate::getDate('DATE', $start_date) .' End Date: '. TTDate::getDate('DATE', $end_date) , __FILE__, __LINE__, __METHOD__,10);
     Debug::text(' Start Date: ' . TTDate::getDate('DATE+TIME', $filter_data['start_date']) . ' End Date: ' . TTDate::getDate('DATE+TIME', $filter_data['end_date']) . ' Start Week Day: ' . $start_week_day, __FILE__, __LINE__, __METHOD__, 10);
     $pdf = new TTPDF('L', 'pt', 'Letter');
     $left_margin = 20;
     $top_margin = 20;
     $pdf->setMargins($left_margin, $top_margin);
     $pdf->SetAutoPageBreak(TRUE, 30);
     //$pdf->SetAutoPageBreak(FALSE);
     $pdf->SetFont('freesans', '', 10);
     $border = 0;
     $adjust_x = 0;
     $adjust_y = 0;
     if ($group_schedule == FALSE) {
         $valid_schedules = 0;
         $sf = TTnew('ScheduleFactory');
         $tmp_schedule_shifts = $sf->getScheduleArray($filter_data);
         //Re-arrange array by user_id->date
         if (is_array($tmp_schedule_shifts)) {
             foreach ($tmp_schedule_shifts as $day_epoch => $day_schedule_shifts) {
                 foreach ($day_schedule_shifts as $day_schedule_shift) {
                     $raw_schedule_shifts[$day_schedule_shift['user_id']][$day_epoch][] = $day_schedule_shift;
                 }
             }
         }
         unset($tmp_schedule_shifts);
         //Debug::Arr($raw_schedule_shifts, 'Raw Schedule Shifts: ', __FILE__, __LINE__, __METHOD__,10);
         if (isset($raw_schedule_shifts) and is_array($raw_schedule_shifts)) {
             foreach ($raw_schedule_shifts as $user_id => $day_schedule_shifts) {
                 foreach ($day_schedule_shifts as $day_epoch => $day_schedule_shifts) {
                     foreach ($day_schedule_shifts as $day_schedule_shift) {
                         //Debug::Arr($day_schedule_shift, 'aDay Schedule Shift: ', __FILE__, __LINE__, __METHOD__,10);
                         $tmp_schedule_shifts[$day_epoch][$day_schedule_shift['branch']][$day_schedule_shift['department']][] = $day_schedule_shift;
                         if (isset($schedule_shift_totals[$day_epoch]['total_shifts'])) {
                             $schedule_shift_totals[$day_epoch]['total_shifts']++;
                         } else {
                             $schedule_shift_totals[$day_epoch]['total_shifts'] = 1;
                         }
                         //$week_of_year = TTDate::getWeek( strtotime($day_epoch) );
                         $week_of_year = TTDate::getWeek(strtotime($day_epoch), $start_week_day);
                         if (!isset($schedule_shift_totals[$day_epoch]['labels'])) {
                             $schedule_shift_totals[$day_epoch]['labels'] = 0;
                         }
                         if ($day_schedule_shift['branch'] != '--' and !isset($schedule_shift_totals[$day_epoch]['branch'][$day_schedule_shift['branch']])) {
                             $schedule_shift_totals[$day_epoch]['branch'][$day_schedule_shift['branch']] = TRUE;
                             $schedule_shift_totals[$day_epoch]['labels']++;
                         }
                         if ($day_schedule_shift['department'] != '--' and !isset($schedule_shift_totals[$day_epoch]['department'][$day_schedule_shift['branch']][$day_schedule_shift['department']])) {
                             $schedule_shift_totals[$day_epoch]['department'][$day_schedule_shift['branch']][$day_schedule_shift['department']] = TRUE;
                             $schedule_shift_totals[$day_epoch]['labels']++;
                         }
                         if (!isset($max_week_data[$week_of_year]['shift'])) {
                             Debug::text('Date: ' . $day_epoch . ' Week: ' . $week_of_year . ' Setting Max Week shift to 0', __FILE__, __LINE__, __METHOD__, 10);
                             $max_week_data[$week_of_year]['shift'] = 1;
                             $max_week_data[$week_of_year]['labels'] = 0;
                         }
                         if (isset($max_week_data[$week_of_year]['shift']) and $schedule_shift_totals[$day_epoch]['total_shifts'] + $schedule_shift_totals[$day_epoch]['labels'] > $max_week_data[$week_of_year]['shift'] + $max_week_data[$week_of_year]['labels']) {
                             Debug::text('Date: ' . $day_epoch . ' Week: ' . $week_of_year . ' Setting Max Week shift to: ' . $schedule_shift_totals[$day_epoch]['total_shifts'] . ' Labels: ' . $schedule_shift_totals[$day_epoch]['labels'], __FILE__, __LINE__, __METHOD__, 10);
                             $max_week_data[$week_of_year]['shift'] = $schedule_shift_totals[$day_epoch]['total_shifts'];
                             $max_week_data[$week_of_year]['labels'] = $schedule_shift_totals[$day_epoch]['labels'];
                         }
                         //Debug::Arr($schedule_shift_totals, ' Schedule Shift Totals: ', __FILE__, __LINE__, __METHOD__,10);
                         //Debug::Arr($max_week_data, ' zMaxWeekData: ', __FILE__, __LINE__, __METHOD__,10);
                     }
                 }
                 if (isset($tmp_schedule_shifts)) {
                     //Sort Branches/Departments first
                     foreach ($tmp_schedule_shifts as $day_epoch => $day_tmp_schedule_shift) {
                         ksort($day_tmp_schedule_shift);
                         $tmp_schedule_shifts[$day_epoch] = $day_tmp_schedule_shift;
                         foreach ($day_tmp_schedule_shift as $branch => $department_schedule_shifts) {
                             ksort($tmp_schedule_shifts[$day_epoch][$branch]);
                         }
                     }
                     //Sort each department by start time.
                     foreach ($tmp_schedule_shifts as $day_epoch => $day_tmp_schedule_shift) {
                         foreach ($day_tmp_schedule_shift as $branch => $department_schedule_shifts) {
                             foreach ($department_schedule_shifts as $department => $department_schedule_shift) {
                                 $department_schedule_shift = Sort::multiSort($department_schedule_shift, 'start_time');
                                 $this->schedule_shifts[$day_epoch][$branch][$department] = $department_schedule_shift;
                             }
                         }
                     }
                 }
                 unset($day_tmp_schedule_shift, $department_schedule_shifts, $department_schedule_shift, $tmp_schedule_shifts, $branch, $department);
                 $calendar_array = TTDate::getCalendarArray($filter_data['start_date'], $filter_data['end_date'], $start_week_day);
                 //var_dump($calendar_array);
                 if (!is_array($calendar_array) or !isset($this->schedule_shifts) or !is_array($this->schedule_shifts)) {
                     continue;
                     //Skip to next user.
                 }
                 $ulf = TTnew('UserListFactory');
                 $ulf->getByIdAndCompanyId($user_id, $current_user->getCompany());
                 if ($ulf->getRecordCount() != 1) {
                     continue;
                 } else {
                     $user_obj = $ulf->getCurrent();
                     $pdf->AddPage();
                     $pdf->setXY(670, $top_margin);
                     $pdf->SetFont('freesans', '', 10);
                     $pdf->Cell(100, 15, TTDate::getDate('DATE+TIME', $current_epoch), $border, 0, 'R');
                     $pdf->setXY($left_margin, $top_margin);
                     $pdf->SetFont('freesans', 'B', 25);
                     $pdf->Cell(0, 25, $user_obj->getFullName() . ' - ' . TTi18n::getText('Schedule'), $border, 0, 'C');
                     $pdf->Ln();
                 }
                 $pdf->SetFont('freesans', 'B', 16);
                 $pdf->Cell(0, 15, TTDate::getDate('DATE', $filter_data['start_date']) . ' - ' . TTDate::getDate('DATE', $filter_data['end_date']), $border, 0, 'C');
                 //$pdf->Ln();
                 $pdf->Ln();
                 $pdf->Ln();
                 $pdf->SetFont('freesans', '', 8);
                 $cell_width = floor(($pdf->GetPageWidth() - $left_margin * 2) / 7);
                 $cell_height = 100;
                 $i = 0;
                 $total_days = count($calendar_array) - 1;
                 $boader = 1;
                 foreach ($calendar_array as $calendar) {
                     if ($i == 0) {
                         //Calendar Header
                         $pdf->SetFont('freesans', 'B', 8);
                         $calendar_header = TTDate::getDayOfWeekArrayByStartWeekDay($start_week_day);
                         foreach ($calendar_header as $header_name) {
                             $pdf->Cell($cell_width, 15, $header_name, 1, 0, 'C');
                         }
                         $pdf->Ln();
                         unset($calendar_header, $header_name);
                     }
                     $month_name = NULL;
                     if ($i == 0 or $calendar['isNewMonth'] == TRUE) {
                         $month_name = $calendar['month_name'];
                     }
                     if ($i > 0 and $i % 7 == 0) {
                         $this->writeWeekSchedule($pdf, $cell_width, $week_date_stamps, $max_week_data, $left_margin, $group_schedule, $start_week_day);
                         unset($week_date_stamps);
                     }
                     $pdf->SetFont('freesans', 'B', 8);
                     $pdf->Cell($cell_width / 2, 15, $month_name, 'LT', 0, 'L');
                     $pdf->Cell($cell_width / 2, 15, $calendar['day_of_month'], 'RT', 0, 'R');
                     $week_date_stamps[] = $calendar['date_stamp'];
                     $i++;
                 }
                 $this->writeWeekSchedule($pdf, $cell_width, $week_date_stamps, $max_week_data, $left_margin, $group_schedule, $start_week_day, TRUE);
                 $valid_schedules++;
                 unset($this->schedule_shifts, $calendar_array, $week_date_stamps, $max_week_data, $day_epoch, $day_schedule_shifts, $day_schedule_shift, $schedule_shift_totals);
             }
         }
         unset($raw_schedule_shifts);
     } else {
         $valid_schedules = 1;
         $sf = TTnew('ScheduleFactory');
         $raw_schedule_shifts = $sf->getScheduleArray($filter_data);
         if (is_array($raw_schedule_shifts)) {
             foreach ($raw_schedule_shifts as $day_epoch => $day_schedule_shifts) {
                 foreach ($day_schedule_shifts as $day_schedule_shift) {
                     //Debug::Arr($day_schedule_shift, 'bDay Schedule Shift: ', __FILE__, __LINE__, __METHOD__,10);
                     $tmp_schedule_shifts[$day_epoch][$day_schedule_shift['branch']][$day_schedule_shift['department']][] = $day_schedule_shift;
                     if (isset($schedule_shift_totals[$day_epoch]['total_shifts'])) {
                         $schedule_shift_totals[$day_epoch]['total_shifts']++;
                     } else {
                         $schedule_shift_totals[$day_epoch]['total_shifts'] = 1;
                     }
                     //$week_of_year = TTDate::getWeek( strtotime($day_epoch) );
                     $week_of_year = TTDate::getWeek(strtotime($day_epoch), $start_week_day);
                     Debug::text(' Date: ' . TTDate::getDate('DATE', strtotime($day_epoch)) . ' Week: ' . $week_of_year . ' TMP: ' . TTDate::getWeek(strtotime('20070721'), $start_week_day), __FILE__, __LINE__, __METHOD__, 10);
                     if (!isset($schedule_shift_totals[$day_epoch]['labels'])) {
                         $schedule_shift_totals[$day_epoch]['labels'] = 0;
                     }
                     if ($day_schedule_shift['branch'] != '--' and !isset($schedule_shift_totals[$day_epoch]['branch'][$day_schedule_shift['branch']])) {
                         $schedule_shift_totals[$day_epoch]['branch'][$day_schedule_shift['branch']] = TRUE;
                         $schedule_shift_totals[$day_epoch]['labels']++;
                     }
                     if ($day_schedule_shift['department'] != '--' and !isset($schedule_shift_totals[$day_epoch]['department'][$day_schedule_shift['branch']][$day_schedule_shift['department']])) {
                         $schedule_shift_totals[$day_epoch]['department'][$day_schedule_shift['branch']][$day_schedule_shift['department']] = TRUE;
                         $schedule_shift_totals[$day_epoch]['labels']++;
                     }
                     if (!isset($max_week_data[$week_of_year]['shift'])) {
                         Debug::text('Date: ' . $day_epoch . ' Week: ' . $week_of_year . ' Setting Max Week shift to 0', __FILE__, __LINE__, __METHOD__, 10);
                         $max_week_data[$week_of_year]['shift'] = 1;
                         $max_week_data[$week_of_year]['labels'] = 0;
                     }
                     if (isset($max_week_data[$week_of_year]['shift']) and $schedule_shift_totals[$day_epoch]['total_shifts'] + $schedule_shift_totals[$day_epoch]['labels'] > $max_week_data[$week_of_year]['shift'] + $max_week_data[$week_of_year]['labels']) {
                         Debug::text('Date: ' . $day_epoch . ' Week: ' . $week_of_year . ' Setting Max Week shift to: ' . $schedule_shift_totals[$day_epoch]['total_shifts'] . ' Labels: ' . $schedule_shift_totals[$day_epoch]['labels'], __FILE__, __LINE__, __METHOD__, 10);
                         $max_week_data[$week_of_year]['shift'] = $schedule_shift_totals[$day_epoch]['total_shifts'];
                         $max_week_data[$week_of_year]['labels'] = $schedule_shift_totals[$day_epoch]['labels'];
                     }
                 }
             }
         }
         //print_r($tmp_schedule_shifts);
         //print_r($max_week_data);
         if (isset($tmp_schedule_shifts)) {
             //Sort Branches/Departments first
             foreach ($tmp_schedule_shifts as $day_epoch => $day_tmp_schedule_shift) {
                 ksort($day_tmp_schedule_shift);
                 $tmp_schedule_shifts[$day_epoch] = $day_tmp_schedule_shift;
                 foreach ($day_tmp_schedule_shift as $branch => $department_schedule_shifts) {
                     ksort($tmp_schedule_shifts[$day_epoch][$branch]);
                 }
             }
             //Sort each department by start time.
             foreach ($tmp_schedule_shifts as $day_epoch => $day_tmp_schedule_shift) {
                 foreach ($day_tmp_schedule_shift as $branch => $department_schedule_shifts) {
                     foreach ($department_schedule_shifts as $department => $department_schedule_shift) {
                         $department_schedule_shift = Sort::multiSort($department_schedule_shift, 'last_name');
                         $this->schedule_shifts[$day_epoch][$branch][$department] = $department_schedule_shift;
                     }
                 }
             }
         }
         //Debug::Arr($this->schedule_shifts, 'Schedule Shifts: ', __FILE__, __LINE__, __METHOD__,10);
         $calendar_array = TTDate::getCalendarArray($filter_data['start_date'], $filter_data['end_date'], $start_week_day);
         //var_dump($calendar_array);
         if (!is_array($calendar_array) or !isset($this->schedule_shifts) or !is_array($this->schedule_shifts)) {
             return FALSE;
         }
         $pdf->AddPage();
         $pdf->setXY(670, $top_margin);
         $pdf->SetFont('freesans', '', 10);
         $pdf->Cell(100, 15, TTDate::getDate('DATE+TIME', $current_epoch), $border, 0, 'R');
         $pdf->setXY($left_margin, $top_margin);
         $pdf->SetFont('freesans', 'B', 25);
         $pdf->Cell(0, 25, 'Employee Schedule', $border, 0, 'C');
         $pdf->Ln();
         $pdf->SetFont('freesans', 'B', 10);
         $pdf->Cell(0, 15, TTDate::getDate('DATE', $filter_data['start_date']) . ' - ' . TTDate::getDate('DATE', $filter_data['end_date']), $border, 0, 'C');
         $pdf->Ln();
         $pdf->Ln();
         $pdf->SetFont('freesans', '', 8);
         $cell_width = floor(($pdf->GetPageWidth() - $left_margin * 2) / 7);
         $cell_height = 100;
         $i = 0;
         $total_days = count($calendar_array) - 1;
         $boader = 1;
         foreach ($calendar_array as $calendar) {
             if ($i == 0) {
                 //Calendar Header
                 $pdf->SetFont('freesans', 'B', 8);
                 $calendar_header = TTDate::getDayOfWeekArrayByStartWeekDay($start_week_day);
                 foreach ($calendar_header as $header_name) {
                     $pdf->Cell($cell_width, 15, $header_name, 1, 0, 'C');
                 }
                 $pdf->Ln();
                 unset($calendar_header, $header_name);
             }
             $month_name = NULL;
             if ($i == 0 or $calendar['isNewMonth'] == TRUE) {
                 $month_name = $calendar['month_name'];
             }
             if ($i > 0 and $i % 7 == 0) {
                 $this->writeWeekSchedule($pdf, $cell_width, $week_date_stamps, $max_week_data, $left_margin, $group_schedule, $start_week_day);
                 unset($week_date_stamps);
             }
             $pdf->SetFont('freesans', 'B', 8);
             $pdf->Cell($cell_width / 2, 15, $month_name, 'LT', 0, 'L');
             $pdf->Cell($cell_width / 2, 15, $calendar['day_of_month'], 'RT', 0, 'R');
             $week_date_stamps[] = $calendar['date_stamp'];
             $i++;
         }
         $this->writeWeekSchedule($pdf, $cell_width, $week_date_stamps, $max_week_data, $left_margin, $group_schedule, $start_week_day, TRUE);
     }
     if ($valid_schedules > 0) {
         $output = $pdf->Output('', 'S');
         return $output;
     }
     return FALSE;
 }
 function _outputPDFSchedule($format)
 {
     Debug::Text(' Format: ' . $format, __FILE__, __LINE__, __METHOD__, 10);
     $current_company = $this->getUserObject()->getCompanyObject();
     if (!is_object($current_company)) {
         Debug::Text('Invalid company object...', __FILE__, __LINE__, __METHOD__, 10);
         return FALSE;
     }
     $filter_data = $this->getFilterConfig();
     $columns = Misc::trimSortPrefix($this->getOptions('columns'));
     $adjust_x = 10;
     $adjust_y = 10;
     //Required fields
     // 'first_name', 'last_name', 'branch', 'department', 'start_time', 'end_time'
     $start_week_day = 0;
     if (is_object($this->getUserObject()) and is_object($this->getUserObject()->getUserPreferenceObject())) {
         $start_week_day = $this->getUserObject()->getUserPreferenceObject()->getStartWeekDay();
     }
     //Debug::Arr($this->form_data, 'Form Data: ', __FILE__, __LINE__, __METHOD__,10);
     //Debug::Arr($this->data, 'Data: ', __FILE__, __LINE__, __METHOD__,10);
     $this->getProgressBarObject()->start($this->getAMFMessageID(), 2, NULL, TTi18n::getText('Querying Database...'));
     //Iterations need to be 2, otherwise progress bar is not created.
     $this->getProgressBarObject()->set($this->getAMFMessageID(), 2);
     $sf = TTNew('ScheduleFactory');
     //getScheduleArray() doesn't accept pay_period_ids, so no data is returned if a time period of "last_pay_period" is selected.
     if (isset($filter_data['pay_period_id'])) {
         unset($filter_data['pay_period_id']);
         $filter_data['start_date'] = TTDate::getBeginDayEpoch(time() - 86400 * 14);
         //Default to the last 14days.
         $filter_data['end_date'] = TTDate::getEndDayEpoch(time() - 86400);
     }
     $raw_schedule_shifts = $sf->getScheduleArray($filter_data);
     if (is_array($raw_schedule_shifts)) {
         //Debug::Arr($raw_schedule_shifts, 'Raw Schedule Shifts: ', __FILE__, __LINE__, __METHOD__,10);
         $this->getProgressBarObject()->start($this->getAMFMessageID(), count($raw_schedule_shifts, COUNT_RECURSIVE), NULL, TTi18n::getText('Retrieving Data...'));
         $key = 0;
         foreach ($raw_schedule_shifts as $date_stamp => $day_schedule_shifts) {
             foreach ($day_schedule_shifts as $shift_arr) {
                 $this->form_data['schedule_by_branch'][$shift_arr['branch']][$shift_arr['department']][$shift_arr['last_name'] . $shift_arr['first_name']][$date_stamp][] = $shift_arr;
                 //Need to be able to sort employees by last name first. Use names as keys instead of user_ids.
                 //$this->form_data['schedule_by_user'][$shift_arr['user_id']][$date_stamp][$shift_arr['branch']][$shift_arr['department']][] = $shift_arr;
                 $this->form_data['schedule_by_user'][$shift_arr['last_name'] . '_' . $shift_arr['first_name']][$date_stamp][$shift_arr['branch']][$shift_arr['department']][] = $shift_arr;
                 if (!isset($this->form_data['dates']['start_date']) or $this->form_data['dates']['start_date'] > $date_stamp) {
                     $this->form_data['dates']['start_date'] = $date_stamp;
                 }
                 if (!isset($this->form_data['dates']['end_date']) or $this->form_data['dates']['end_date'] < $date_stamp) {
                     $this->form_data['dates']['end_date'] = $date_stamp;
                 }
                 $this->getProgressBarObject()->set($this->getAMFMessageID(), $key);
                 $key++;
             }
         }
         unset($date_stamp, $raw_schedule_shifts, $day_schedule_shifts);
     } else {
         Debug::Text('No schedule shifts returned...', __FILE__, __LINE__, __METHOD__, 10);
     }
     //Initialize array element if it doesn't exist to prevent PHP warning.
     if (!isset($this->form_data['schedule_by_user'])) {
         $this->form_data['schedule_by_user'] = array();
     }
     //Debug::Arr($this->form_data['schedule_by_branch'], '2Raw Schedule Shifts: ', __FILE__, __LINE__, __METHOD__,10);
     //Debug::Arr($this->form_data['dates'], 'Dates: ', __FILE__, __LINE__, __METHOD__,10);
     //If pay periods are requested, we need to convert those to start/end dates.
     if (isset($this->form_data['dates']['start_date']) and isset($this->form_data['dates']['end_date']) and (!isset($filter_data['start_date']) or !isset($filter_data['end_date']))) {
         $filter_data['start_date'] = strtotime($this->form_data['dates']['start_date']);
         $filter_data['end_date'] = strtotime($this->form_data['dates']['end_date']);
     }
     if (isset($filter_data['start_date']) and isset($filter_data['end_date'])) {
         $pdf_created_date = time();
         $this->pdf = new TTPDF($this->config['other']['page_orientation'], 'mm', $this->config['other']['page_format'], $this->getUserObject()->getCompanyObject()->getEncoding());
         $this->pdf->SetAuthor(APPLICATION_NAME);
         $this->pdf->SetTitle($this->title);
         $this->pdf->SetSubject(APPLICATION_NAME . ' ' . TTi18n::getText('Report'));
         $this->pdf->setMargins($this->config['other']['left_margin'], $this->config['other']['top_margin'], $this->config['other']['right_margin']);
         //Debug::Arr($this->config['other'], 'Margins: ', __FILE__, __LINE__, __METHOD__,10);
         $this->pdf->SetAutoPageBreak(FALSE, 0);
         $this->pdf->SetFont($this->config['other']['default_font'], '', $this->_pdf_fontSize(10));
         //Debug::Arr($this->form_data, 'zabUser Raw Data: ', __FILE__, __LINE__, __METHOD__,10);
         $calendar_array = TTDate::getCalendarArray($filter_data['start_date'], $filter_data['end_date'], $start_week_day);
         //Debug::Arr($calendar_array, 'Calendar Array: ', __FILE__, __LINE__, __METHOD__,10);
         switch ($format) {
             case 'pdf_schedule_group':
             case 'pdf_schedule_group_print':
             case 'pdf_schedule_group_pagebreak':
             case 'pdf_schedule_group_pagebreak_print':
                 //
                 // Group - Separate (branch/department on their own pages)
                 //
                 //Start displaying dates/times here. Start with header.
                 $column_widths = array('line' => 5, 'label' => 30, 'day' => ($this->pdf->getPageWidth() - $this->config['other']['left_margin'] - $this->config['other']['right_margin'] - 30) / 7);
                 if (isset($this->form_data['schedule_by_branch'])) {
                     $this->pdf->AddPage($this->config['other']['page_orientation'], 'Letter');
                     $n = 0;
                     ksort($this->form_data['schedule_by_branch']);
                     foreach ($this->form_data['schedule_by_branch'] as $branch => $level_2) {
                         ksort($level_2);
                         foreach ($level_2 as $department => $level_3) {
                             ksort($level_3);
                             if ($format == 'pdf_schedule_group_pagebreak' or $format == 'pdf_schedule_group_pagebreak_print') {
                                 //Insert page breaks after each branch/department in this mode.
                                 if ($n > 0) {
                                     $this->pdf->AddPage($this->config['other']['page_orientation'], 'Letter');
                                 }
                                 $page_break = TRUE;
                             } else {
                                 $page_break = $n == 0 ? TRUE : $this->scheduleCheckPageBreak(30, TRUE);
                             }
                             $this->scheduleHeader($branch, $department, NULL, $page_break);
                             $this->scheduleDayOfWeekNameHeader($start_week_day, $column_widths, $format);
                             //FIXME: Find a better way to determine how many iterations there will be in this loop.
                             $this->getProgressBarObject()->start($this->getAMFMessageID(), count($calendar_array), NULL, TTi18n::getText('Generating Schedules...'));
                             $key = 0;
                             $i = 0;
                             foreach ($calendar_array as $calendar_day) {
                                 if ($i % 7 == 0) {
                                     $calendar_week_array = array_slice($calendar_array, $i, 7);
                                     if ($i != 0) {
                                         $this->scheduleFooterWeek();
                                     }
                                     $this->scheduleWeekHeader($calendar_week_array, $column_widths, $format);
                                     $s = 0;
                                     foreach ($level_3 as $user_id => $user_schedule) {
                                         if ($this->_pdf_checkMaximumPageLimit() == FALSE) {
                                             Debug::Text('Exceeded maximum page count...', __FILE__, __LINE__, __METHOD__, 10);
                                             //Exceeded maximum pages, stop processing.
                                             $this->_pdf_displayMaximumPageLimitError();
                                             break 4;
                                         }
                                         //Handle page break.
                                         $page_break_height = 5;
                                         if ($this->scheduleCheckPageBreak($page_break_height, TRUE) == TRUE) {
                                             $this->scheduleHeader($branch, $department);
                                             $this->scheduleDayOfWeekNameHeader($start_week_day, $column_widths, $format);
                                             $this->scheduleWeekHeader($calendar_week_array, $column_widths, $format, TRUE);
                                         }
                                         if ($s % 2 == 0) {
                                             $this->pdf->setFillColor(255, 255, 255);
                                         } else {
                                             $this->pdf->setFillColor(245, 245, 245);
                                         }
                                         if ($this->scheduleUserWeek($user_schedule, $calendar_week_array, $start_week_day, $column_widths, $format, $key) == TRUE) {
                                             $s++;
                                         }
                                     }
                                 }
                                 $this->getProgressBarObject()->set($this->getAMFMessageID(), $key);
                                 if ($key % 25 == 0 and $this->isSystemLoadValid() == FALSE) {
                                     return FALSE;
                                 }
                                 $key++;
                                 $i++;
                             }
                             $this->scheduleFooterWeek($column_widths);
                             $this->scheduleFooter();
                         }
                         $n++;
                     }
                 } else {
                     $this->scheduleNoData();
                 }
                 break;
             case 'pdf_schedule_group_combined':
             case 'pdf_schedule_group_combined_print':
                 ksort($this->form_data['schedule_by_user']);
                 //Start displaying dates/times here. Start with header.
                 $column_widths = array('line' => 5, 'label' => 30, 'day' => ($this->pdf->getPageWidth() - $this->config['other']['left_margin'] - $this->config['other']['right_margin'] - 30) / 7);
                 $this->getProgressBarObject()->start($this->getAMFMessageID(), count($this->form_data['schedule_by_user']) * (count($calendar_array) / 7), NULL, TTi18n::getText('Generating Schedules...'));
                 $this->pdf->AddPage($this->config['other']['page_orientation'], 'Letter');
                 $this->scheduleHeader();
                 $this->scheduleDayOfWeekNameHeader($start_week_day, $column_widths, $format);
                 $key = 0;
                 $i = 0;
                 foreach ($calendar_array as $calendar_day) {
                     if ($i % 7 == 0) {
                         $calendar_week_array = array_slice($calendar_array, $i, 7);
                         if ($i != 0) {
                             $this->scheduleFooterWeek();
                         }
                         $this->scheduleWeekHeader($calendar_week_array, $column_widths, $format);
                         foreach ($this->form_data['schedule_by_user'] as $user_id => $user_schedule) {
                             if ($this->_pdf_checkMaximumPageLimit() == FALSE) {
                                 Debug::Text('Exceeded maximum page count...', __FILE__, __LINE__, __METHOD__, 10);
                                 //Exceeded maximum pages, stop processing.
                                 $this->_pdf_displayMaximumPageLimitError();
                                 break 2;
                             }
                             $s = 0;
                             //Handle page break.
                             if ($this->scheduleCheckPageBreak(5, TRUE) == TRUE) {
                                 $this->scheduleFooterWeek($column_widths);
                                 $this->scheduleHeader();
                                 $this->scheduleDayOfWeekNameHeader($start_week_day, $column_widths, $format);
                                 $this->scheduleWeekHeader($calendar_week_array, $column_widths, $format, TRUE);
                             }
                             $this->pdf->setFillColor(255, 255, 255);
                             if ($this->scheduleUserWeek($user_schedule, $calendar_week_array, $start_week_day, $column_widths, $format, $key) == TRUE) {
                                 $s++;
                             }
                             $this->getProgressBarObject()->set($this->getAMFMessageID(), $key);
                             if ($key % 25 == 0 and $this->isSystemLoadValid() == FALSE) {
                                 return FALSE;
                             }
                             $key++;
                         }
                         $this->scheduleFooterWeek($column_widths);
                     }
                     $i++;
                 }
                 $this->scheduleFooter();
                 break;
             case 'pdf_schedule':
             case 'pdf_schedule_print':
                 ksort($this->form_data['schedule_by_user']);
                 //Start displaying dates/times here. Start with header.
                 $column_widths = array('line' => 5, 'label' => 0, 'day' => ($this->pdf->getPageWidth() - $this->config['other']['left_margin'] - $this->config['other']['right_margin'] - 0) / 7);
                 if (isset($this->form_data['schedule_by_user'])) {
                     $this->getProgressBarObject()->start($this->getAMFMessageID(), count($this->form_data['schedule_by_user']) * (count($calendar_array) / 7), NULL, TTi18n::getText('Generating Schedules...'));
                     $key = 0;
                     foreach ($this->form_data['schedule_by_user'] as $user_full_name => $user_schedule) {
                         $this->pdf->AddPage($this->config['other']['page_orientation'], 'Letter');
                         $split_name = explode('_', $user_full_name);
                         $this->scheduleHeader(NULL, NULL, $split_name[1] . ' ' . $split_name[0]);
                         unset($split_name);
                         $this->scheduleDayOfWeekNameHeader($start_week_day, $column_widths, $format);
                         $i = 0;
                         foreach ($calendar_array as $calendar_day) {
                             if ($i % 7 == 0) {
                                 if ($this->_pdf_checkMaximumPageLimit() == FALSE) {
                                     Debug::Text('Exceeded maximum page count...', __FILE__, __LINE__, __METHOD__, 10);
                                     //Exceeded maximum pages, stop processing.
                                     $this->_pdf_displayMaximumPageLimitError();
                                     break 2;
                                 }
                                 $calendar_week_array = array_slice($calendar_array, $i, 7);
                                 if ($i != 0) {
                                     $this->scheduleFooterWeek();
                                 }
                                 $this->scheduleWeekHeader($calendar_week_array, $column_widths, $format);
                                 //Handle page break.
                                 $page_break_height = 5;
                                 if ($this->scheduleCheckPageBreak($page_break_height, TRUE) == TRUE) {
                                     $this->scheduleHeader();
                                     $this->scheduleDayOfWeekNameHeader($start_week_day, $column_widths, $format);
                                     $this->scheduleWeekHeader($calendar_week_array, $column_widths, $format, TRUE);
                                 }
                                 $this->pdf->setFillColor(255, 255, 255);
                                 $this->scheduleUserWeek($user_schedule, $calendar_week_array, $start_week_day, $column_widths, $format, $key);
                             }
                             $this->getProgressBarObject()->set($this->getAMFMessageID(), $key);
                             if ($key % 25 == 0 and $this->isSystemLoadValid() == FALSE) {
                                 return FALSE;
                             }
                             $key++;
                             $i++;
                         }
                         $this->scheduleFooterWeek($column_widths);
                         $this->scheduleFooter();
                     }
                 } else {
                     $this->scheduleNoData();
                 }
                 break;
         }
         $output = $this->pdf->Output('', 'S');
         return $output;
     } else {
         Debug::Text('No start/end date specified...', __FILE__, __LINE__, __METHOD__, 10);
     }
     Debug::Text('No data to return...', __FILE__, __LINE__, __METHOD__, 10);
     return FALSE;
 }