$text .= $parts[1];
}
$converted = templateParser::parse_template($text, $object_arr);
$header = templateParser::parse_template($header, $object_arr);
$footer = templateParser::parse_template($footer, $object_arr);
$printable = str_replace("\n", "<br />", $converted);
if ($task == 'pdf' || $task == 'emailpdf') {
    $file_name = $mod_strings['LBL_PDF_NAME'] . "_" . str_replace(" ", "_", $module->name) . ".pdf";
    ob_clean();
    try {
        $pdf = new mPDF('en', 'A4', '', 'DejaVuSansCondensed', 15, 15, 16, 16, 8, 8);
        $pdf->setAutoFont();
        $pdf->SetHTMLHeader($header);
        $pdf->SetHTMLFooter($footer);
        $pdf->writeHTML($printable);
        if ($task == 'pdf') {
            $pdf->Output($file_name, "D");
        } else {
            $fp = fopen($sugar_config['upload_dir'] . 'attachfile.pdf', 'wb');
            fclose($fp);
            $pdf->Output($sugar_config['upload_dir'] . 'attachfile.pdf', 'F');
            sendEmail::send_email($module, $module_type, '', $file_name, true);
        }
    } catch (mPDF_exception $e) {
        echo $e;
    }
} else {
    if ($task == 'email') {
        sendEmail::send_email($module, $module_type, $printable, '', false);
    }
}
        $pdf->WriteHTML($printable);
        if ($task == 'pdf') {
            $pdf->Output($file_name, "D");
        } else {
            $fp = fopen($sugar_config['upload_dir'] . 'attachfile.pdf', 'wb');
            fclose($fp);
            $pdf->Output($sugar_config['upload_dir'] . 'attachfile.pdf', 'F');
            $sendEmail = new sendEmail();
            $sendEmail->send_email($bean, $bean->module_dir, '', $file_name, true);
        }
    } catch (mPDF_exception $e) {
        echo $e;
    }
} elseif ($task == 'email') {
    $sendEmail = new sendEmail();
    $sendEmail->send_email($bean, $bean->module_dir, $printable, '', false);
}
function populate_group_lines($text, $lineItemsGroups, $lineItems, $element = 'table')
{
    $firstValue = '';
    $firstNum = 0;
    $lastValue = '';
    $lastNum = 0;
    $startElement = '<' . $element;
    $endElement = '</' . $element . '>';
    $groups = new AOS_Line_Item_Groups();
    foreach ($groups->field_defs as $name => $arr) {
        if (!(isset($arr['dbType']) && strtolower($arr['dbType']) == 'id' || $arr['type'] == 'id' || $arr['type'] == 'link')) {
            $curNum = strpos($text, '$aos_line_item_groups_' . $name);
            if ($curNum) {
                if ($curNum < $firstNum || $firstNum == 0) {