$pdf->SetFont($format_font, '', 24);
$pdf->SetTextColor(0, 0, 0);
$pdf->SetDrawColor(0, 0, 0);
$pdf->Cell(0, 10, $sheet_title);
$pdf->SetXY(10, 55);
$pdf->SetFont($format_font, '', 14);
$sheet_subtitle = $proj_num . " " . $proj_name;
$sheet_date = "Current at " . $current_date;
$pdf->Cell(0, 7.5, $sheet_subtitle, 0, 1, L, 0);
$pdf->Cell(0, 7.5, $sheet_date, 0, 1, L, 0);
$pdf->SetXY(10, 70);
$pdf->SetLineWidth(0.5);
$sql_checklist = "SELECT * FROM intranet_project_checklist_items LEFT JOIN intranet_project_checklist ON checklist_item = item_id AND checklist_project = {$proj_id} WHERE checklist_required != 1 ORDER BY item_group, item_order, checklist_date DESC, item_name";
$result_checklist = mysql_query($sql_checklist, $conn) or die(mysql_error());
$y = $pdf->GetY() + 10;
$pdf->SetY($y);
$pdf->SetTextColor(0, 0, 0);
$pdf->SetLineWidth(0.3);
$pdf->SetFont("Helvetica", 'B', 7);
$pdf->Cell(65, 5, "Item", B, 0, L, 0);
$pdf->Cell(15, 5, "Required", B, 0, L, 0);
$pdf->Cell(30, 5, "Date Completed", B, 0, L, 0);
$pdf->Cell(80, 5, "Comment", B, 1, L, 0);
$pdf->SetTextColor(0, 0, 0);
$pdf->SetFont($format_font, '', 7);
$pdf->SetFillColor(240, 240, 240);
$pdf->SetLineWidth(0.1);
$fill = 0;
$group = NULL;
while ($array_checklist = mysql_fetch_array($result_checklist)) {
    $item_id = $array_checklist['item_id'];
     $format_font = $settings_pdffont;
     $format_font_2 = $settings_pdffont . ".php";
 } else {
     $format_font = "franklingothicbook";
     $format_font_2 = "franklingothicbook.php";
 }
 //  Use FDPI to get the template
 define('FPDF_FONTPATH', 'fpdf/font/');
 require 'fpdf/fpdi.php';
 $pdf = new fpdi();
 $pagecount = $pdf->setSourceFile("pdf/template.pdf");
 $tplidx = $pdf->ImportPage(1);
 $pdf->addPage();
 $pdf->useTemplate($tplidx, 0, 0, 210, 297);
 $pdf->AddFont($format_font, '', $format_font_2);
 $pdf->SetY(50);
 $pdf->SetFont($format_font, '', 14);
 // Determine name of project
 $sql = "SELECT proj_num, proj_name FROM intranet_projects WHERE proj_id = '{$proj_submit}'";
 $result = mysql_query($sql, $conn) or die(mysql_error());
 $array = mysql_fetch_array($result);
 $proj_num = $array['proj_num'];
 $proj_name = $array['proj_name'];
 $print_submit_begin = date("l, jS F Y", $_POST[submit_begin]);
 $print_submit_begin = "from " . $print_submit_begin;
 if ($_POST[submit_end] > 0) {
     $print_submit_end = $_POST[submit_end];
 } else {
     $print_submit_end = time();
 }
 $print_submit_end = date("l jS F Y", $print_submit_end);
    } else {
        $y_current = $y_right + 5;
    }
    $x_current = 10;
    $pdf->SetXY($x_current, $y_current);
    StyleBody(10);
    $pdf->SetFillColor(220, 220, 220);
    $pdf->Cell(0, 5, $input, 0, 2, L, true);
    $pdf->Cell(0, 5, '', 0, 2, L, false);
    $x_current = 10;
    $y_current = $pdf->GetY();
}
// Begin creating the page
$project_counter = 1;
$page_count = 1;
$pdf->SetY(35);
$pdf->SetFont('Helvetica', '', 18);
$pdf->SetTextColor(0, 0, 0);
$pdf->Cell(0, 10, "Planning Conditions Tracker");
$pdf->SetY(50);
$pdf->SetFont('Helvetica', 'b', 18);
// Determine name of project
$sql = "SELECT * FROM intranet_projects WHERE proj_id = '{$proj_id}'";
$result = mysql_query($sql, $conn) or die(mysql_error());
$array = mysql_fetch_array($result);
$proj_num = $array['proj_num'];
$proj_name = $array['proj_name'];
$proj_desc = $array['proj_desc'];
$proj_address_1 = $array['proj_address_1'];
$proj_address_2 = $array['proj_address_2'];
$proj_address_3 = $array['proj_address_3'];
 $format_font_2 = "franklingothicbook.php";
 //}
 //  Use FDPI to get the template
 define('FPDF_FONTPATH', 'fpdf/font/');
 require 'fpdf/fpdi.php';
 $pdf = new fpdi();
 $pagecount = $pdf->setSourceFile("pdf/template.pdf");
 $tplidx = $pdf->ImportPage(1);
 $pdf->addPage();
 $pdf->useTemplate($tplidx);
 $pdf->SetAutoPageBreak(0, 1.5);
 $pdf->AddFont($format_font, '', $format_font_2);
 // Page headers
 $project_counter = 1;
 $page_count = 1;
 $pdf->SetY(35);
 $pdf->SetFont('Helvetica', 'b', 24);
 $pdf->SetTextColor($format_bg_r, $format_bg_g, $format_bg_b);
 $pdf->Cell(0, 10, "Timesheet Analysis");
 $pdf->SetTextColor(0, 0, 0);
 $pdf->SetY(50);
 $pdf->SetFont('Helvetica', 'b', 18);
 $print_title = "Generated " . TimeFormatDetailed(time());
 $print_envelope = "Timesheet Datum: " . TimeFormat($settings_timesheetstart);
 $pdf->SetFillColor(220, 220, 220);
 $pdf->MultiCell(0, 8, $print_title, 0, L, 0);
 $pdf->SetFont('Helvetica', 'b', 12);
 $pdf->MultiCell(0, 5, $print_envelope, 0, L, 0);
 $pdf->MultiCell(0, 5, $print_profit_text, 0, L, 0);
 $pdf->Cell(0, 5, '', 0, 2);
 $pdf->SetFont($format_font, '', 10);
    $sheet_subtitle_print = $sheet_subtitle . ", Sheet " . $page_number_current;
    // . " of " . $page_number_total ;
    $sheet_title = "Drawing Issue Matrix";
    $pdf->SetFont($format_font, '', 16);
    $pdf->SetTextColor(150, 150, 150);
    $pdf->SetDrawColor(150, 150, 150);
    $pdf->Cell(0, 8, $sheet_title, 0, 1);
    $pdf->SetFont($format_font, '', 12);
    $pdf->Cell(0, 6, $sheet_subtitle_print, 0, 1);
    $pdf->SetLineWidth(0.5);
}
$pdf->SetXY(10, 45);
// And now the list of drawings issued
unset($current_drawing);
$y = $pdf->GetY();
$pdf->SetY($y);
function HeadingLine()
{
    global $pdf;
    global $proj_id;
    global $conn;
    global $format_font;
    $array_issued = array();
    $pdf->SetTextColor(200, 200, 200);
    $pdf->SetLineWidth(0.15);
    $pdf->SetFont("Helvetica", 'B', 6);
    $pdf->Cell(20, 8, "Drawing", B, 0, L, 0);
    $pdf->Cell(60, 8, "Drawing Title", BR, 0, L, 0);
    $pdf->SetTextColor(0, 0, 0);
    $pdf->SetFont($format_font, '', 5);
    $current_y = $pdf->GetY();
     } else {
         $pdf->SetDrawColor($color_array[0], $color_array[1], $color_array[2]);
     }
     if ($datum_start < 230 && $datum_start + $duration > 0) {
         $pdf->Cell($duration, $rowheight, '', T, 1, L, FALSE);
     } else {
         $pdf->Cell(0, $rowheight, '', 0, 1, L, FALSE);
     }
     $pdf->SetLineWidth(0.2);
     $pdf->SetX(10);
 }
 $array_total = array();
 // Header
 $project_counter = 1;
 $page_count = 1;
 $pdf->SetY(10);
 $pdf->SetFont('Helvetica', 'b', 14);
 if (date("n", $timestart) < 4) {
     $quarter = "Q1";
 } elseif (date("n", $timestart) < 7) {
     $quarter = "Q2";
 } elseif (date("n", $timestart) < 10) {
     $quarter = "Q3";
 } else {
     $quarter = "Q4";
 }
 $quarter = $quarter . " " . date("Y", $timestart);
 $sheet_title = "Project Resourcing, " . $quarter;
 $pdf->SetTextColor($format_bg_r, $format_bg_g, $format_bg_b);
 $pdf->Cell(169.5, 10, $sheet_title, 0, 0);
 $pdf->SetFont('Helvetica', '', 8);