Still remember about the customization I made and wrote it in the previous article which has titled How to Add Row/Record Number Column on the List Pages in Websites that Created with PHPMaker 9.0.2? Well, that customization is only for adding the record number column on the List pages, and not for the Exported List pages (either using Printer Friendly, Export to Excel, Export to Word, Export to HTML, Export to XML, Export to CSV, or Export to PDF).
You will find that record number column will never show up in your Exported List pages. This could be happened since PHPMaker handles the export data differs with adding a new column in the list pages.
So this following customization below will add the record number column in the exported list pages. This record number column will sit on the very left of your exported list. You may hide or show this record number column anytime you want, by simply adjusting the related constant in your ewcfg9.php (configuration) file.
In addition, we will also change the output of Printer Friendly feature. Currently, when you are displaying the List page in Printer Friendly, then you will see that the stylesheet will be included in it. So, we will remove it in order to make it more makes sense as well as its name says Printer Friendly. This is very useful if your users often use this feature in order to print the data from your web application.
Updated on July 22, 2012: This customization has been implemented in PHPMaker version 9.0.3, it matches to each other, and as a result, it works properly.
Updated on September 5, 2012: This customization has been implemented in PHPMaker version 9.0.4, it matches to each other, and as a result, it works properly.
Updated on November 29, 2012: This customization has been implemented in PHPMaker version 9.1.0, it matches to each other, and as a result, it works properly.
Updated on February 9, 2013: This customization has been implemented in PHPMaker version 9.2.0, it matches to each other, and as a result, it works properly.
Updated on June 17, 2013: The customization has been handled by using MasinoFixedWidthSite extension. You don’t need to implement the customization below if you use my extensions together with the original PHPMaker Template and Extension files.
[hidepost]
-
Open your \Script\ewcfg.php file, and find this code:
// General
before that line, please insert the following code:
// Begin of modification Add Record Number Column on Exported List, modified by Masino Sinaga, June 3, 2012 define("MS_SHOW_RECNUM_COLUMN_ON_EXPORTED_LIST", TRUE, TRUE); // whether to show record number column on the exported list // End of modification Add Record Number Column on Exported List, modified by Masino Sinaga, June 3, 2012 -
Open your C:\Program Files\PHPMaker 9\languages\english.xml file, and find this code:
</global>
before that line, please insert the following code:
<phrase id="RecNo" value="Record Number"/>Don't forget to do the same way for your another .xml language file(s); if any.
-
Still in that \Script\ewcfg.php file, find again this code:
$EW_EXPORT = array( "email" => "cExportEmail", "html" => "cExportHtml", "word" => "cExportWord", "excel" => "cExportExcel", "pdf" => "cExportPdf", "csv" => "cExportCsv", "xml" => "cExportXml" );
then replace it with the following code:
// Begin of modification Add Record Number Column on Exported List, modified by Masino Sinaga, June 3, 2012 $EW_EXPORT = array( "email" => "cExportEmail", "html" => "cExportHtml", "print" => "cExportPrint", "word" => "cExportWord", "excel" => "cExportExcel", "pdf" => "cExportPdf", "csv" => "cExportCsv", "xml" => "cExportXml" ); // End of modification Add Record Number Column on Exported List, modified by Masino Sinaga, June 3, 2012
-
Open your \Script\phpfn.php file, and find this code:
// Add HTML tags function ExportHeaderAndFooter() { $header = "<html><head>\r\n";then replace it with the following code:
// Add HTML tags function ExportHeaderAndFooter() { // Begin of modification Add Record Number Column on Exported List, modified by Masino Sinaga, June 3, 2012 global $Language; $header = "<html><head><title>".$Language->ProjectPhrase("BodyTitle")."</title>\r\n"; // End of modification Add Record Number Column on Exported List, modified by Masino Sinaga, June 3, 2012 -
Still in that \Script\phpfn.php file, find again this code:
// Table Footer function ExportTableFooter() { $this->Text .= "</table>"; }before the first line of that code, please insert the following code:
// Begin of modification Add Record Number Column on Exported List, modified by Masino Sinaga, June 3, 2012 function ExportText($txt) { switch ($this->Table->Export) { case "html": case "print": case "email": case "word": case "excel": case "pdf": $this->Text .= "<td>" . $txt . "</td>"; break; case "csv": if ($this->Line <> "") $this->Line .= ","; $this->Line .= "\"" . str_replace("\"", "\"\"", strval($txt)) . "\""; break; } } // End of modification Add Record Number Column on Exported List, modified by Masino Sinaga, June 3, 2012 -
Open your \Script\phpfn.php file, and find this code:
class cExportHtml extends cExportBase { // Same as base class }after the last line of that code, please insert the following code:
// Begin of modification Add Record Number Column on Exported List, modified by Masino Sinaga, June 3, 2012 class cExportPrint extends cExportBase { function ExportHeaderAndFooter() { global $Language; $header = "<html><head><title>".$Language->ProjectPhrase("BodyTitle")."</title>\r\n"; $header .= $this->CharsetMetaTag(); $header .= "<style type=\"text/css\">.table-bi { background: #fff; border-collapse: collapse; margin-bottom:7px; font-family:tahoma;font-size:8pt; } .table-bi td { border: 1px solid #bbb; background: #fff; padding: 5px; } .table-bi th { border: 1px solid #aaa; text-align: left; background: #F7F7F7; font-weight: bold; padding: 6px; }</style>\r\n"; $header .= "</" . "head>\r\n<body>\r\n"; $this->Text = $header . $this->Text . "</body></html>"; } function ExportTableHeader() { $this->Text .= "<table class=\"table-bi\">"; } function ExportText($txt) { $this->Text .= "<th>" . $txt . "</th>"; } // Begin a row function BeginExportRow($rowcnt = 0, $usestyle = TRUE) { $this->RowCnt++; $this->FldCnt = 0; if ($this->Horizontal) { $this->Text .= "<tr>"; } } // Export a field function ExportField(&$fld) { $this->FldCnt++; if ($this->Horizontal) { $this->ExportValue($fld); } else { // Vertical, export as a row $this->RowCnt++; $this->Text .= "<tr class=\"" . (($this->FldCnt % 2 == 1) ? "ewExportTableRow" : "ewExportTableAltRow") . "\">" . "<th>" . $fld->ExportCaption() . "</th>"; $this->Text .= "<td" . ((EW_EXPORT_CSS_STYLES) ? $fld->CellStyles() : "") . ">" . $fld->ExportValue() . "</td></tr>"; } } // Export a value (caption, field value, or aggregate) function ExportValueEx(&$fld, $val, $usestyle = TRUE) { if ($this->RowCnt == 1) { $this->Text .= "<th>"; $this->Text .= strval($val); $this->Text .= "</th>"; } else { $this->Text .= "<td" . (($usestyle && EW_EXPORT_CSS_STYLES) ? $fld->CellStyles() : "") . ">"; $this->Text .= strval($val); $this->Text .= "</td>"; } } } // End of modification Add Record Number Column on Exported List, modified by Masino Sinaga, June 3, 2012 -
Open your \Script\list-script.php file, and find this code:
if (in_array($this->Export, array("html","word","excel","xml","csv","email","pdf"))) {then replace it with the following code:
// Begin of modification Add Record Number Column on Exported List, modified by Masino Sinaga, June 3, 2012 if (in_array($this->Export, array("html","print","word","excel","xml","csv","email","pdf"))) { // End of modification Add Record Number Column on Exported List, modified by Masino Sinaga, June 3, 2012 -
Open your \Script\view-script.php file, and find this code:
if (in_array($this->Export, array("html","word","excel","xml","csv","email","pdf"))) {then replace it with the following code:
// Begin of modification Add Record Number Column on Exported List, modified by Masino Sinaga, June 3, 2012 if (in_array($this->Export, array("html","print","word","excel","xml","csv","email","pdf"))) { // End of modification Add Record Number Column on Exported List, modified by Masino Sinaga, June 3, 2012 -
Open your \Script\info.php file, and find this code:
function ExportDocument(&$Doc, &$Recordset, $StartRec, $StopRec, $ExportPageType = "") {after that line, please insert the following code:
global $Language;
-
Still in that \Script\info.php file, find again this code for PHPMaker version < 9.1.0:
[code lang="php"]
$Doc->ExportCaption($);
} else {
[/code]and if you are using PHPMaker version >= 9.1.0, then find this code:
if (goFld.FldView) { ##--> if ($<!--##=gsFldObj##-->->Exportable) $Doc->ExportCaption($<!--##=gsFldObj##-->); <!--## } } } // AllField ##--> } else {after the last line of that code, please insert this following code; both for PHPMaker version < 9.1.0 and version >= 9.1.0:
// Begin of modification Add Record Number Column on Exported List, modified by Masino Sinaga, June 3, 2012 if (MS_SHOW_RECNUM_COLUMN_ON_EXPORTED_LIST) { $Doc->ExportText($Language->Phrase('RecNo')); } // End of modification Add Record Number Column on Exported List, modified by Masino Sinaga, June 3, 2012 -
Still in that \Script\info.php file, find again this code for PHPMaker version < 9.1.0:
[code lang="php"]
$Doc->ExportField($);
} else {
[/code]or if you are using PHPMaker version >= 9.1.0, then find this code:
if (goFld.FldView) { ##--> if ($<!--##=gsFldObj##-->->Exportable) $Doc->ExportField($<!--##=gsFldObj##-->); <!--## } } } // AllField ##--> } else {after the last line of that code, please insert this following code; both for PHPMaker version < 9.1.0 and >= 9.1.0:
// Begin of modification Add Record Number Column on Exported List, modified by Masino Sinaga, June 3, 2012 if (MS_SHOW_RECNUM_COLUMN_ON_EXPORTED_LIST) { $Doc->ExportText($RecCnt); } // End of modification Add Record Number Column on Exported List, modified by Masino Sinaga, June 3, 2012 -
Still in that \Script\info.php file, find again this code:
$Doc->BeginExportRow(-1);
after that line, please insert the following code:
// Begin of modification Add Record Number Column on Exported List, modified by Masino Sinaga, June 3, 2012 if (MS_SHOW_RECORD_NUMBER_COLUMN_ON_LIST) { $Doc->ExportText(''); // Add an additional column in the aggregate row if necessary } // End of modification Add Record Number Column on Exported List, modified by Masino Sinaga, June 3, 2012 -
Open your \extensions\PHPExcel\phpexcel-script.php file, and find this code:
// Table footer function ExportTableFooter() {}before the first line of that code, please insert the following code:
// Begin of modification Add Record Number Column on Exported List, modified by Masino Sinaga, June 3, 2012 function ExportText($txt) { $this->FldCnt++; if ($this->Horizontal) { $this->phpexcel->getActiveSheet()->setCellValueByColumnAndRow($this->FldCnt - 1, $this->RowCnt, $txt); } else { // Vertical, export as a row $this->phpexcel->getActiveSheet()->setCellValueByColumnAndRow(1, 1, $txt); $this->RowCnt++; } } // End of modification Add Record Number Column on Exported List, modified by Masino Sinaga, June 3, 2012 - Finally, re-generate your script files using PHPMaker as always.
[/hidepost]
Regardng step 8. There are two occurences of that code in 9.0.2
Which one do I use (or both of them)?
For the step 8, please use the first occurance, whereas the step 9, please use the second occurance.
When I attempt to export, I get the following error:
Notice: Undefined variable: Language in C:\xampp\htdocs\weekendsupport.org\weekends_info.php on line 3072
Fatal error: Call to a member function Phrase() on a non-object in C:\xampp\htdocs\weekendsupport.org\weekends_info.php on line 3072
the line in question is line #3 below:
// Begin of modification Add Record Number Column on Exported List, modified by Masino Sinaga, June 3, 2012
if (MS_SHOW_RECNUM_COLUMN_ON_EXPORTED_LIST) {
$Doc->ExportText($Language->Phrase(‘RecNo’));
}
// End of modification Add Record Number Column on Exported List, modified by Masino Sinaga, June 3, 2012
I attempted to place “global $Language” in the function, but that did not work. I have confirmed that I do have “RecNo” defined in the language file.
Did you put “global $Language” below this following code in \Script\info.php file?
function ExportDocument(&$Doc, &$Recordset, $StartRec, $StopRec, $ExportPageType = "") {If so, then it should work properly as I did not get any error message regarding it.
Yes. That’s how I got it to work. AT least, partially. The export to PDF does not work. All other exports seem to function properly.
Is this something that can be corrected?
We are investigating it. Will let you know the results afterwards.
How are you doing on this one?
Keith, there is no problem here. I have just tried, export to PDF from the list page that contains the table works perfectly. The record number column shows up properly in the PDF file. Make sure you have already setup from Tools -> Extensions -> DOMPDF -> Advanced (tab) -> Tables/Views (tab), and then in “ExportList” column, give the checked mark at the desired table(s).