ExportData($request); } public function ExportData(Vtiger_Request $request) { $adb = PearDatabase::getInstance(); $moduleName = $request->get('source_module'); $this->moduleInstance = Vtiger_Module_Model::getInstance($moduleName); $this->focus = CRMEntity::getInstance($moduleName); $orderBy = $request->get('orderby'); $sortOrder = $request->get('sortorder'); $PDFMakerModel = Vtiger_Module_Model::getInstance('PDFMaker'); $mode = $request->getMode(); if ($mode == "ExportAllData") { $result = $PDFMakerModel->GetListviewResult($orderBy, $sortOrder, false); } elseif ($mode == "ExportCurrentPage") { $result = $PDFMakerModel->GetListviewResult($orderBy, $sortOrder, $request); } else { $sql = $this->getExportQuery($request); if (!empty($orderby)) { $sql .= " ORDER BY "; if ($orderBy == "owner" || $orderBy == "sharingtype") { $sql .= "vtiger_pdfmaker_settings"; } else { $sql .= "vtiger_pdfmaker"; } $sql .= "." . $orderBy . " " . $sortOrder; } $result = $adb->pquery($sql, array()); } $entries = array(); $num_rows = $adb->num_rows($result); while ($row = $adb->fetchByAssoc($result)) { $currModule = $row['module']; $templateid = $row['templateid']; $Template_Permissions_Data = $PDFMakerModel->returnTemplatePermissionsData($currModule, $templateid); if ($Template_Permissions_Data["detail"] === false) { continue; } $entries[] = $row; } $this->output($entries); } public function getExportQuery(Vtiger_Request $request) { $query = "SELECT vtiger_pdfmaker_displayed.*, vtiger_pdfmaker.*, vtiger_pdfmaker_settings.* FROM vtiger_pdfmaker LEFT JOIN vtiger_pdfmaker_settings USING(templateid) LEFT JOIN vtiger_pdfmaker_displayed USING(templateid)"; $idList = $this->getRecordsListFromRequest($request); $query .= "WHERE vtiger_pdfmaker.deleted = '0'"; if (!empty($idList)) { $idList = implode(',', $idList); $query .= 'AND vtiger_pdfmaker.templateid IN (' . $idList . ')'; } return $query; } public function output($entries) { $c = ""; foreach ($entries as $pdftemplateResult) { $Margins = array( "top" => $pdftemplateResult["margin_top"], "bottom" => $pdftemplateResult["margin_bottom"], "left" => $pdftemplateResult["margin_left"], "right" => $pdftemplateResult["margin_right"] ); $Decimals = array( "point" => $pdftemplateResult["decimal_point"], "decimals" => $pdftemplateResult["decimals"], "thousands" => $pdftemplateResult["thousands_separator"] ); $templatename = $pdftemplateResult["filename"]; $nameOfFile = $pdftemplateResult["file_name"]; $description = $pdftemplateResult["description"]; $module = $pdftemplateResult["module"]; $body = $pdftemplateResult["body"]; $header = $pdftemplateResult["header"]; $footer = $pdftemplateResult["footer"]; $format = $pdftemplateResult["format"]; $orientation = $pdftemplateResult["orientation"]; $c .= ""; } header('Content-Type: application/xhtml+xml'); header("Content-Disposition: attachment; filename=export.xml"); echo ""; echo ""; echo $c; echo ""; exit; } private function cdataEncode($text, $encode = false) { $From = array(""); $To = array("<|!|[%|CDATA|[%|", "|%]|]|>"); if ($text != "") { $pos1 = strpos("", $text); if ($pos1 === false && $pos2 === false && $encode == false) { $content = $text; } else { $text = decode_html($text); $encode_text = str_replace($From, $To, $text); $content = ""; } } else { $content = ""; } return $content; } }