$obb['TransportContracts'] = $id; $obb['Contracts'] = $contractId; $text .= $sep . templateParser::parse_template($linePart, $obb); $sep = $leValue . $lsValue . $tdTemp[count($tdTemp) - 1]; } } else { $tcount = strrpos($text, "<tr"); $text = substr($text, 0, $tcount); $tcount = strpos($parts[1], "</tr>") + 5; $parts[1] = substr($parts[1], $tcount); } $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); //$doc->setCSSFile("modules/AOS_PDF_Templates/export.css"); //$doc->newSession("WordSection1", $sugar_config['site_url'].'/modules/AOS_PDF_Templates/test_files/header.htm', $sugar_config['site_url'].'/modules/AOS_PDF_Templates/test_files/header.htm' ); //$doc->addText($printable); //$doc->endSession(); $header_t = '<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns:st1="urn:schemas-microsoft-com:office:smarttags" xmlns="http://www.w3.org/TR/REC-html40"> <head> <meta http-equiv=Content-Type content="text/html; charset=unicode"> <meta name=ProgId content=Word.Document>
function populate_service_lines($text, $lineItems, $element = 'tr') { $firstValue = ''; $firstNum = 0; $lastValue = ''; $lastNum = 0; $startElement = '<' . $element; $endElement = '</' . $element . '>'; $text = str_replace("\$aos_services_quotes_service", "\$aos_services_quotes_product", $text); //Find first and last valid line values $product_quote = new AOS_Products_Quotes(); foreach ($product_quote->field_defs as $name => $arr) { if (!(isset($arr['dbType']) && strtolower($arr['dbType']) == 'id' || $arr['type'] == 'id' || $arr['type'] == 'link')) { $curNum = strpos($text, '$aos_services_quotes_' . $name); if ($curNum) { if ($curNum < $firstNum || $firstNum == 0) { $firstValue = '$aos_products_quotes_' . $name; $firstNum = $curNum; } if ($curNum > $lastNum) { $lastValue = '$aos_products_quotes_' . $name; $lastNum = $curNum; } } } } if ($firstValue !== '' && $lastValue !== '') { $text = str_replace("\$aos_products", "\$aos_null", $text); $text = str_replace("\$aos_services", "\$aos_products", $text); //Converting Text $tparts = explode($firstValue, $text); $temp = $tparts[0]; //check if there is only one line item if ($firstNum == $lastNum) { $linePart = $firstValue; } else { $tparts = explode($lastValue, $tparts[1]); $linePart = $firstValue . $tparts[0] . $lastValue; } $tcount = strrpos($temp, $startElement); $lsValue = substr($temp, $tcount); $tcount = strpos($lsValue, ">") + 1; $lsValue = substr($lsValue, 0, $tcount); //Read line end values $tcount = strpos($tparts[1], $endElement) + strlen($endElement); $leValue = substr($tparts[1], 0, $tcount); $tdTemp = explode($lsValue, $temp); $linePart = $lsValue . $tdTemp[count($tdTemp) - 1] . $linePart . $leValue; $parts = explode($linePart, $text); $text = $parts[0]; //Converting Line Items if (count($lineItems) != 0) { foreach ($lineItems as $id => $productId) { if ($productId == null || $productId == '0') { $obb['AOS_Products_Quotes'] = $id; $text .= templateParser::parse_template($linePart, $obb); } } } $text .= $parts[1]; } return $text; }