AssignMethod($pageObject->body['end'], "assignBodyEnd", $pageObject);
$xt->assignbyref("body", $pageObject->body);
$xt->assign("grid_block", true);
$xt->assign("grid_header", true);
$xt->assign("TranStockCode_fieldheader", true);
$xt->assign("DESCRIP_fieldheader", true);
$xt->assign("SUM_Fact_SalesValue__fieldheader", true);
if (@$_REQUEST["format"] && $_REQUEST["format"] != "pdf") {
    //$pages[0]["page_summary"] = false;
    //$xt->assign_loopsection("pages", $pages);
    $xt->assign("pdflink_block", false);
    $xt->assign("divideintopages_block", false);
    $pageObject->body["begin"] = "";
    $pageObject->body["end"] = "";
    $xt->assignbyref("body", $pageObject->body);
}
if (@$_REQUEST["format"] !== "pdf") {
    $xt->assign("bodyattrs", 'style="margin:10px;"');
}
$usePage2pdf = postvalue("pdf");
if (!$usePage2pdf) {
    if (@$_REQUEST["format"] == "excel" || @$_REQUEST["format"] == "word") {
        $xt->load_template($pageObject->templatefile);
        $contents = $pageObject->prepareWordOrExcelTemplate($xt->template);
        $xt->template = $contents;
        xt_process_template($xt, $xt->template);
    } else {
        $pageObject->display($pageObject->templatefile);
    }
} else {
}
function xt_process_template(&$xt, $str)
{
    //	parse template file tag by tag
    $start = 0;
    $literal = false;
    $len = strlen($str);
    while (true) {
        $pos = strpos($str, "{", $start);
        if ($pos === false) {
            echo substr($str, $start, $len - $start);
            break;
        }
        $section = false;
        $var = false;
        $message = false;
        if (substr($str, $pos + 1, 6) == "BEGIN ") {
            $section = true;
        } elseif (substr($str, $pos + 1, 1) == '$') {
            $var = true;
        } elseif (substr($str, $pos + 1, 14) == 'mlang_message ') {
            $message = true;
        } else {
            //	no tag, just '{' char
            echo substr($str, $start, $pos - $start + 1);
            $start = $pos + 1;
            continue;
        }
        echo substr($str, $start, $pos - $start);
        if ($section) {
            //	section
            $endpos = strpos($str, "}", $pos);
            if ($endpos === false) {
                $xt->report_error("Page is broken");
                return;
            }
            $section_name = trim(substr($str, $pos + 7, $endpos - $pos - 7));
            $endtag = "{END " . $section_name . "}";
            $endpos1 = strpos($str, $endtag, $endpos);
            if ($endpos1 === false) {
                echo "End tag not found:" . htmlspecialchars($endtag);
                $xt->report_error("Page is broken");
                return;
            }
            $section = substr($str, $endpos + 1, $endpos1 - $endpos - 1);
            $start = $endpos1 + strlen($endtag);
            $var = xt_getvar($xt, $section_name);
            if ($var === false) {
                continue;
            }
            $begin = "";
            $end = "";
            if (is_array($var)) {
                $begin = @$var["begin"];
                $end = @$var["end"];
                $var = @$var["data"];
            }
            if (!is_array($var)) {
                //	if section
                echo $begin;
                xt_process_template($xt, $section);
                $xt->processVar($end, $varparams);
            } else {
                //	foreach section
                echo $begin;
                $keys = array_keys($var);
                foreach ($keys as $i) {
                    $xt->xt_stack[] =& $var[$i];
                    if (is_array($var[$i]) && array_key_exists("begin", $var[$i])) {
                        echo $var[$i]["begin"];
                    }
                    xt_process_template($xt, $section);
                    array_pop($xt->xt_stack);
                    if (is_array($var[$i]) && array_key_exists("end", $var[$i])) {
                        echo $var[$i]["end"];
                    }
                }
                $xt->processVar($end, $varparams);
            }
        } elseif ($var) {
            //	display a variable or call a function
            $endpos = strpos($str, "}", $pos);
            if ($endpos === false) {
                $xt->report_error("Page is broken");
                return;
            }
            $varparams = array();
            $var_name = trim(substr($str, $pos + 2, $endpos - $pos - 2));
            if (strpos($var_name, " ") !== FALSE) {
                $varparams = explode(" ", $var_name);
                $var_name = $varparams[0];
                unset($varparams[0]);
            }
            $start = $endpos + 1;
            $var = xt_getvar($xt, $var_name);
            if ($var === false) {
                continue;
            }
            $xt->processVar($var, $varparams);
        } elseif ($message) {
            $endpos = strpos($str, "}", $pos);
            if ($endpos === false) {
                $xt->report_error("Page is broken");
                return;
            }
            $tag = trim(substr($str, $pos + 15, $endpos - $pos - 15));
            $start = $endpos + 1;
            echo htmlspecialchars(mlang_message($tag));
        }
    }
}
Beispiel #3
0
 function display($template)
 {
     $this->load_template($template);
     $this->Testing();
     xt_process_template($this, $this->template);
 }