function buildFinalObject($OLP)
{
    //-- OLP = one long page
    $Final_Object = new nuReport($OLP, $OLP->displayJavaScript());
    $Final_Object->page_height = $OLP->page_height;
    $Final_Object->page_width = $OLP->page_width;
    $new_page = new nuPage();
    $reportSectionsArray = $GLOBALS['nuSections'];
    unset($GLOBALS['nuSections']);
    for ($G = 0; $G < count($reportSectionsArray); $G++) {
        unset($section_array);
        unset($record);
        unset($controls);
        unset($S);
        $nuS = gzuncompress($reportSectionsArray[$G]['the_section']);
        eval($nuS);
        //-- make section_array, record and controls from table record
        $S = new nuSection($emptySection, $new_page);
        //-- build a section using nothing
        $S->load_from_array($section_array, $record);
        for ($ct = 0; $ct < count($controls); $ct++) {
            //-- add controls to rebuilt section
            $S->controls[$ct] = new nuControl(null, null);
            $S->controls[$ct]->load_from_array($controls[$ct]);
        }
        if ($S->original_height > $OLP->get_remaining_height()) {
            //====start another page because the next section won't fit
            $new_section = new nuSection($S, $new_page);
            $new_section->height = $OLP->get_remaining_height();
            //-- build a blank section the size of the remaining height
            $new_section->name = 'Padding';
            //-- name this section as 'PageBreak'
            buildClassCode($new_section, count($Final_Object->pages));
            //==========page footer===========================
            if ($S->name != "Report_Header") {
                $page_footer = $OLP->page_footer;
                $temp_section = new nuSection($page_footer, $new_page);
                for ($pf = 0; $pf < count($page_footer->controls); $pf++) {
                    $temp_control = new nuControl($page_footer->controls[$pf], $S);
                    $temp_control->text_string = formatControlValue($temp_control, $S->record, $OLP);
                    $temp_section->controls[] = $temp_control;
                }
                $temp_section->record = $new_section->record;
                buildClassCode($temp_section, count($Final_Object->pages));
            }
            //==========end page footer=======================
            $Final_Object->pages[] = $new_page;
            $new_page = new nuPage();
            //-- build new page
            //==========page header===========================
            if ($S->name != "Report_Header") {
                $page_header = $OLP->page_header;
                $temp_section = new nuSection($page_header, $new_page);
                for ($pf = 0; $pf < count($page_header->controls); $pf++) {
                    $temp_control = new nuControl($page_header->controls[$pf], $S);
                    $temp_control->text_string = formatControlValue($temp_control, $S->record, $OLP);
                    $temp_section->controls[] = $temp_control;
                }
                $temp_section->record = $new_section->record;
                buildClassCode($temp_section, count($Final_Object->pages));
            }
            //==========end page header=======================
            $OLP->reset_remaining_height();
        }
        while (!$S->finished('while')) {
            $new_section = new nuSection($S, $new_page);
            for ($c = 0; $c < count($S->controls); $c++) {
                //-- LOOP THROUGH ALL CONTROLS
                if ($S->controls[$c]->top + 1 < $OLP->get_remaining_height()) {
                    $new_control = new nuControl($S->controls[$c], $S);
                    //-- setup control properties
                    if ($new_control->type == 'PageBreak') {
                        $new_section->height = $new_section->section_height();
                        //-- resize height to lowest control
                        $OLP->reduce_remaining_height($new_section->height);
                        //-- reset the remaining height of the page
                        buildClassCode($new_section, count($Final_Object->pages));
                        $new_section = new nuSection($S, $new_page);
                        $new_section->height = $OLP->get_remaining_height();
                        //-- build a blank section the size of the remaining height
                        $new_section->name = 'PageBreak';
                        //-- name this section as 'PageBreak'
                        break;
                    } else {
                        $new_control->top = $S->controls[$c]->top();
                        //-- set height to 0 if not first time through
                        $usable_height = $OLP->get_remaining_height() - $new_control->top;
                        //-- area this control has to fit in
                        $new_control->text_string = $S->controls[$c]->get_lines($usable_height);
                        //-- put fittable rows into the control
                        if ($new_control->type == 'Graph') {
                            $new_control->last_used = 0;
                            //-- set graph as completed
                        }
                        $new_control->height = count($new_control->text_string) * $new_control->height;
                        //-- resize height of this control
                        $new_section->controls[] = $new_control;
                        //-- add control to current section
                    }
                } else {
                    if ($OLP->get_remaining_height() > 0) {
                        $S->controls[$c]->top = $S->controls[$c]->top - $OLP->get_remaining_height();
                        //-- reduce control's top for next section
                    }
                }
            }
            if ($new_control->type != 'PageBreak') {
                $new_section->height = $new_section->section_height();
                //-- resize height to lowest control
            }
            $OLP->reduce_remaining_height($new_section->height);
            //-- reset the remaining height of the page
            buildClassCode($new_section, count($Final_Object->pages));
            if (!$S->finished('if') or $new_control->type == 'PageBreak') {
                //-- add a page break
                $new_section = new nuSection($S, $new_page);
                $new_section->height = $OLP->get_remaining_height();
                //-- build a blank section the size of the remaining height
                $new_section->name = 'Padding';
                //-- name this section as 'PageBreak'
                buildClassCode($new_section, count($Final_Object->pages));
                //==========page footer===========================
                if ($S->name != "Report_Header") {
                    $page_footer = $OLP->page_footer;
                    $temp_section = new nuSection($page_footer, $new_page);
                    for ($pf = 0; $pf < count($page_footer->controls); $pf++) {
                        $temp_control = new nuControl($page_footer->controls[$pf], $S);
                        $temp_control->text_string = formatControlValue($temp_control, $S->record, $OLP);
                        $temp_section->controls[] = $temp_control;
                    }
                    $temp_section->record = $new_section->record;
                    buildClassCode($temp_section, count($Final_Object->pages));
                }
                //==========end page footer=======================
                $Final_Object->pages[] = $new_page;
                $new_page = new nuPage();
                //-- build new page
                //==========page header===========================
                if ($S->name != "Report_Header") {
                    $page_header = $OLP->page_header;
                    $temp_section = new nuSection($page_header, $new_page);
                    for ($pf = 0; $pf < count($page_header->controls); $pf++) {
                        $temp_control = new nuControl($page_header->controls[$pf], $S);
                        $temp_control->text_string = formatControlValue($temp_control, $S->record, $OLP);
                        $temp_section->controls[] = $temp_control;
                    }
                    $temp_section->record = $new_section->record;
                    buildClassCode($temp_section, count($Final_Object->pages));
                }
                //==========end page header=======================
                //-- push down remaining objects by the remaining gap that couldn't be used on this page
                $push_down_from = $S->push_down_from();
                $add_height = $OLP->get_remaining_height();
                $grow_section = false;
                for ($pd = $push_down_from; $pd < count($S->controls); $pd++) {
                    $S->controls[$pd]->top = $S->controls[$pd]->top + $add_height;
                    $grow_section = true;
                }
                if ($grow_section) {
                    $S->height = $S->height + $add_height;
                }
                $OLP->reset_remaining_height();
            }
        }
    }
    //==========padding between report footer and page footer
    $new_section = new nuSection($S, $new_page);
    $new_section->height = $OLP->get_remaining_height();
    //-- build a blank section the size of the remaining height
    $new_section->name = 'PageBreak';
    //-- name this section as 'PageBreak'
    buildClassCode($new_section, count($Final_Object->pages));
    //==========page footer===========================
    $page_footer = $OLP->page_footer;
    $temp_section = new nuSection($page_footer, $new_page);
    $temp_section->record = $S->record;
    for ($pf = 0; $pf < count($page_footer->controls); $pf++) {
        $temp_control = new nuControl($page_footer->controls[$pf], $S);
        $temp_control->text_string = formatControlValue($temp_control, $S->record, $OLP);
        $temp_section->controls[] = $temp_control;
    }
    $temp_section->record = $new_section->record;
    buildClassCode($temp_section, count($Final_Object->pages));
    $Final_Object->pages[] = $new_page;
    build_report($Final_Object);
    tofile('end ' . date('Y-m-d H:i:s'));
}