PHPMaker by default will generate your list pages and view pages that contain a set of "Export to ..." feature for all of those pages (assuming: you selected "Print", "CSV", "HTML", "Excel", "Word", "XML", "PDF", and "Email" from PHP tab -> List/View Page Options (Global) sub-tab -> Export groupbox. If you do not want those all generated pages contain the certain "Export to ..." features, or you want to hide some of those "Export to ..." features for the certain pages and or for the certain users, then the following customization is definitely for you!
For example, in the list of customer page, you only want to display the "Export to Excel" feature and you want to hide the others (Export to Word, Export to PDF, Export to HTML, Printer Friendly, Export to CSV, Export to XML, and Send to Email) for users with Operator level, whereas for users with Manager level (for example), only "Export to Excel", "Export to PDF", and "Send to Email", and then for Administrator level, all of those "Export to ..." features are enabled or to be shown properly as usual.
So, the question is: How should you do that, so you can define the access permission for "Export to ..." features dynamically? Well, now you don’t have to worry anymore, as I have successfully created this feature by customizing the PHPMaker template. Now you can define the certain "Export to ..." feature for the certain users you want in the generated list and view pages. You can define it from the User Levels page by giving the checked mark that related to its level and page.
It now also has the ability to prevent users accessing the certain Export by entering URL directly via browser. For example, users which do not have permission to export record to Excel, they will not see the link "Export to Excel" (this is fine), but they still can export records by entering the related URL from the browser directly (this is bad). By implementing this update, then system will automatically prevent such users to access the forbidden export to Excel URL/page.
All we have to do is customizing PHPMaker template files so this template can be used for your future projects too. In other words, we will not customize the generated script files.
Please note that if you enable Export from PHP -> List/View Page Options (Global) but you have not enabled Dynamic User Levels from Advanced Security -> User Levels, then the anonymous users will still be able to see the Export icon links in the List or View page (it actually depends on your setting above). So, if you want to restrict the Export features for the anonymous users, then you have to enable the Dynamic User Levels setting from Advanced Security menu above.
Updated on May 30, 2012: This customization has been implemented in PHPMaker version 9.0.2, it matches to each other, and as a result, it works properly.
Updated on July 21, 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 4, 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 28, 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: This customization below 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 C:\Program Files\PHPMaker 9\languages\english.xml file, and find this code:
<phrase id="PermissionView" value="View"/>
after that line, please insert the following code:
<phrase id="PermissionPrinterFriendly" value="Printer Friendly"/> <phrase id="PermissionExportToHTML" value="Export to HTML"/> <phrase id="PermissionExportToExcel" value="Export to Excel"/> <phrase id="PermissionExportToWord" value="Export to Word"/> <phrase id="PermissionExportToPDF" value="Export to PDF"/> <phrase id="PermissionExportToXML" value="Export to XML"/> <phrase id="PermissionExportToCSV" value="Export to CSV"/> <phrase id="PermissionExportToEmail" value="Export to Email"/>
Do the same way with your another .xml language file. For example, I am also using Indonesian, then I will search in my C:\Program Files\PHPMaker 9\languages\indonesian.xml file the following code:
<phrase id="PermissionView" value="Tampilan"/>
after that line, I will insert the following code:
<phrase id="PermissionPrinterFriendly" value="Ramah Cetakan"/> <phrase id="PermissionExportToHTML" value="Ekspor ke HTML"/> <phrase id="PermissionExportToExcel" value="Ekspor ke Excel"/> <phrase id="PermissionExportToWord" value="Ekspor ke Word"/> <phrase id="PermissionExportToPDF" value="Ekspor ke PDF"/> <phrase id="PermissionExportToXML" value="Ekspor ke XML"/> <phrase id="PermissionExportToCSV" value="Ekspor ke CSV"/> <phrase id="PermissionExportToEmail" value="Ekspor ke Email"/>
-
Open your \Script\ewcfg.php file, and find this code:
@define("EW_ALLOW_ADMIN", 16, TRUE); // Admin
after that line, please insert the following code:
// Begin of modification Permission Access for Export To Feature, by Masino Sinaga, May 5, 2012 define("MS_ALLOW_EXPORT_TO_PRINT", 128, TRUE); // Printer Friendly define("MS_ALLOW_EXPORT_TO_EXCEL", 256, TRUE); // Export to Excel define("MS_ALLOW_EXPORT_TO_WORD", 512, TRUE); // Export to Word define("MS_ALLOW_EXPORT_TO_HTML", 1024, TRUE); // Export to HTML define("MS_ALLOW_EXPORT_TO_XML", 2048, TRUE); // Export to XML define("MS_ALLOW_EXPORT_TO_CSV", 4096, TRUE); // Export to CSV define("MS_ALLOW_EXPORT_TO_PDF", 8192, TRUE); // Export to PDF define("MS_ALLOW_EXPORT_TO_EMAIL", 16384, TRUE); // Export to Email // End of modification Permission Access for Export To Feature, by Masino Sinaga, May 5, 2012
-
Open your \Script\phpfn.php file, and find this code:
function setCanAdmin($b) { if ($b) { $this->CurrentUserLevel = ($this->CurrentUserLevel | EW_ALLOW_ADMIN); } else { $this->CurrentUserLevel = ($this->CurrentUserLevel & (~ EW_ALLOW_ADMIN)); } }
after the last line of that code, please insert the following code:
// Begin of modification Permission Access for Export To Feature, by Masino Sinaga, May 5, 2012 // Can export to Print function CanExportToPrint() { return (($this->CurrentUserLevel & MS_ALLOW_EXPORT_TO_PRINT) == MS_ALLOW_EXPORT_TO_PRINT); } function setCanExportToPrint($b) { if ($b) { $this->CurrentUserLevel = ($this->CurrentUserLevel | MS_ALLOW_EXPORT_TO_PRINT); } else { $this->CurrentUserLevel = ($this->CurrentUserLevel & (~ MS_ALLOW_EXPORT_TO_PRINT)); } } // Can export to HTML function CanExportToHTML() { return (($this->CurrentUserLevel & MS_ALLOW_EXPORT_TO_HTML) == MS_ALLOW_EXPORT_TO_HTML); } function setCanExportToHTML($b) { if ($b) { $this->CurrentUserLevel = ($this->CurrentUserLevel | MS_ALLOW_EXPORT_TO_HTML); } else { $this->CurrentUserLevel = ($this->CurrentUserLevel & (~ MS_ALLOW_EXPORT_TO_HTML)); } } // Can export to Excel function CanExportToExcel() { return (($this->CurrentUserLevel & MS_ALLOW_EXPORT_TO_EXCEL) == MS_ALLOW_EXPORT_TO_EXCEL); } function setCanExportToExcel($b) { if ($b) { $this->CurrentUserLevel = ($this->CurrentUserLevel | MS_ALLOW_EXPORT_TO_EXCEL); } else { $this->CurrentUserLevel = ($this->CurrentUserLevel & (~ MS_ALLOW_EXPORT_TO_EXCEL)); } } // Can export to Word function CanExportToWord() { return (($this->CurrentUserLevel & MS_ALLOW_EXPORT_TO_WORD) == MS_ALLOW_EXPORT_TO_WORD); } function setCanExportToWord($b) { if ($b) { $this->CurrentUserLevel = ($this->CurrentUserLevel | MS_ALLOW_EXPORT_TO_WORD); } else { $this->CurrentUserLevel = ($this->CurrentUserLevel & (~ MS_ALLOW_EXPORT_TO_WORD)); } } // Can export to PDF function CanExportToPDF() { return (($this->CurrentUserLevel & MS_ALLOW_EXPORT_TO_PDF) == MS_ALLOW_EXPORT_TO_PDF); } function setCanExportToPDF($b) { if ($b) { $this->CurrentUserLevel = ($this->CurrentUserLevel | MS_ALLOW_EXPORT_TO_PDF); } else { $this->CurrentUserLevel = ($this->CurrentUserLevel & (~ MS_ALLOW_EXPORT_TO_PDF)); } } // Can export to XML function CanExportToXML() { return (($this->CurrentUserLevel & MS_ALLOW_EXPORT_TO_XML) == MS_ALLOW_EXPORT_TO_XML); } function setCanExportToXML($b) { if ($b) { $this->CurrentUserLevel = ($this->CurrentUserLevel | MS_ALLOW_EXPORT_TO_XML); } else { $this->CurrentUserLevel = ($this->CurrentUserLevel & (~ MS_ALLOW_EXPORT_TO_XML)); } } // Can export to CSV function CanExportToCSV() { return (($this->CurrentUserLevel & MS_ALLOW_EXPORT_TO_CSV) == MS_ALLOW_EXPORT_TO_CSV); } function setCanExportToCSV($b) { if ($b) { $this->CurrentUserLevel = ($this->CurrentUserLevel | MS_ALLOW_EXPORT_TO_CSV); } else { $this->CurrentUserLevel = ($this->CurrentUserLevel & (~ MS_ALLOW_EXPORT_TO_CSV)); } } // Can export to Email function CanExportToEmail() { return (($this->CurrentUserLevel & MS_ALLOW_EXPORT_TO_EMAIL) == MS_ALLOW_EXPORT_TO_EMAIL); } function setCanExportToEmail($b) { if ($b) { $this->CurrentUserLevel = ($this->CurrentUserLevel | MS_ALLOW_EXPORT_TO_EMAIL); } else { $this->CurrentUserLevel = ($this->CurrentUserLevel & (~ MS_ALLOW_EXPORT_TO_EMAIL)); } } // End of modification Permission Access for Export To Feature, by Masino Sinaga, May 5, 2012
-
Open your \Script\add-script.php file, and find this code:
intval($AllowView) + intval($AllowSearch); }
after the last line of that code, please insert the following code:
// Begin of modification Permission Access for Export To Feature, by Masino Sinaga, May 5, 2012 $AllowExportToPrint = @$_POST["x__AllowExportToPrint"]; if ($AllowExportToPrint == "") $AllowExportToPrint = 0; $AllowExportToHTML = @$_POST["x__AllowExportToHTML"]; if ($AllowExportToHTML == "") $AllowExportToHTML = 0; $AllowExportToExcel = @$_POST["x__AllowExportToExcel"]; if ($AllowExportToExcel == "") $AllowExportToExcel = 0; $AllowExportToWord = @$_POST["x__AllowExportToWord"]; if ($AllowExportToWord == "") $AllowExportToWord = 0; $AllowExportToPDF = @$_POST["x__AllowExportToPDF"]; if ($AllowExportToPDF == "") $AllowExportToPDF = 0; $AllowExportToXML = @$_POST["x__AllowExportToXML"]; if ($AllowExportToXML == "") $AllowExportToXML = 0; $AllowExportToCSV = @$_POST["x__AllowExportToCSV"]; if ($AllowExportToCSV == "") $AllowExportToCSV = 0; $AllowExportToEmail = @$_POST["x__AllowExportToEmail"]; if ($AllowExportToEmail == "") $AllowExportToEmail = 0; $this->Priv = $this->Priv + intval($AllowExportToPrint) + intval($AllowExportToHTML) + intval($AllowExportToExcel) + intval($AllowExportToWord) + intval($AllowExportToPDF) + intval($AllowExportToXML) + intval($AllowExportToCSV) + intval($AllowExportToEmail); // End of modification Permission Access for Export To Feature, by Masino Sinaga, May 5, 2012
-
Still in that \Script\add-script.php file, find again this code:
<label><input type="checkbox" name="x__AllowAdd" id="Add" value="<?php echo EW_ALLOW_ADD ?>" /><!--##@PermissionAddCopy##--></label> <label><input type="checkbox" name="x__AllowDelete" id="Delete" value="<?php echo EW_ALLOW_DELETE ?>" /><!--##@PermissionDelete##--></label> <label><input type="checkbox" name="x__AllowEdit" id="Edit" value="<?php echo EW_ALLOW_EDIT ?>" /><!--##@PermissionEdit##--></label> <?php if (defined("EW_USER_LEVEL_COMPAT")) { ?> <label><input type="checkbox" name="x__AllowList" id="List" value="<?php echo EW_ALLOW_LIST ?>" /><!--##@PermissionListSearchView##--></label> <?php } else { ?> <label><input type="checkbox" name="x__AllowList" id="List" value="<?php echo EW_ALLOW_LIST ?>" /><!--##@PermissionList##--></label> <label><input type="checkbox" name="x__AllowView" id="View" value="<?php echo EW_ALLOW_VIEW ?>" /><!--##@PermissionView##--></label> <label><input type="checkbox" name="x__AllowSearch" id="Search" value="<?php echo EW_ALLOW_SEARCH ?>" /><!--##@PermissionSearch##--></label> <?php } ?>
then replace it with the following code:
<label><input type="checkbox" name="x__AllowAdd" id="Add" value="<?php echo EW_ALLOW_ADD ?>" /><!--##@PermissionAddCopy##--></label><br /> <label><input type="checkbox" name="x__AllowDelete" id="Delete" value="<?php echo EW_ALLOW_DELETE ?>" /><!--##@PermissionDelete##--></label><br /> <label><input type="checkbox" name="x__AllowEdit" id="Edit" value="<?php echo EW_ALLOW_EDIT ?>" /><!--##@PermissionEdit##--></label><br /> <?php if (defined("EW_USER_LEVEL_COMPAT")) { ?> <label><input type="checkbox" name="x__AllowList" id="List" value="<?php echo EW_ALLOW_LIST ?>" /><!--##@PermissionListSearchView##--></label><br /> <?php } else { ?> <label><input type="checkbox" name="x__AllowList" id="List" value="<?php echo EW_ALLOW_LIST ?>" /><!--##@PermissionList##--></label><br /> <label><input type="checkbox" name="x__AllowView" id="View" value="<?php echo EW_ALLOW_VIEW ?>" /><!--##@PermissionView##--></label><br /> <label><input type="checkbox" name="x__AllowSearch" id="Search" value="<?php echo EW_ALLOW_SEARCH ?>" /><!--##@PermissionSearch##--></label><br /> <?php } ?> <?php // Begin of modification Permission Access for Export To Feature, by Masino Sinaga, May 5, 2012 ?> <label><input type="checkbox" name="x__AllowExportToPrint" id="Print" value="<?php echo MS_ALLOW_EXPORT_TO_PRINT ?>" /><!--##@PermissionPrinterFriendly##--></label><br /> <label><input type="checkbox" name="x__AllowExportToExcel" id="Excel" value="<?php echo MS_ALLOW_EXPORT_TO_EXCEL ?>" /><!--##@PermissionExportToExcel##--></label><br /> <label><input type="checkbox" name="x__AllowExportToWord" id="Word" value="<?php echo MS_ALLOW_EXPORT_TO_WORD ?>" /><!--##@PermissionExportToWord##--></label><br /> <label><input type="checkbox" name="x__AllowExportToHTML" id="HTML" value="<?php echo MS_ALLOW_EXPORT_TO_HTML ?>" /><!--##@PermissionExportToHTML##--></label><br /> <label><input type="checkbox" name="x__AllowExportToXML" id="XML" value="<?php echo MS_ALLOW_EXPORT_TO_XML ?>" /><!--##@PermissionExportToXML##--></label><br /> <label><input type="checkbox" name="x__AllowExportToCSV" id="CSV" value="<?php echo MS_ALLOW_EXPORT_TO_CSV ?>" /><!--##@PermissionExportToCSV##--></label><br /> <label><input type="checkbox" name="x__AllowExportToPDF" id="PDF" value="<?php echo MS_ALLOW_EXPORT_TO_PDF ?>" /><!--##@PermissionExportToPDF##--></label><br /> <label><input type="checkbox" name="x__AllowExportToEmail" id="Email" value="<?php echo MS_ALLOW_EXPORT_TO_EMAIL ?>" /><!--##@PermissionExportToEmail##--></label><br /> <?php // End of modification Permission Access for Export To Feature, by Masino Sinaga, May 5, 2012 ?>
-
Open your \Script\share-script.php file, and find this code:
global $Language; // Printer friendly $item = &$this->ExportOptions->Add("print"); $item->Body = <!--##=sExportPrintUrl##--> . <!--##=sPrinterFriendlyCaption##--> . "</a>"; $item->Visible = <!--##=ew_Val(bPrinterFriendly)##-->; // Export to Excel $item = &$this->ExportOptions->Add("excel"); $item->Body = <!--##=sExportExcelUrl##--> . <!--##=sExportToExcelCaption##--> . "</a>"; $item->Visible = <!--##=ew_Val(bExportExcel)##-->; // Export to Word $item = &$this->ExportOptions->Add("word"); $item->Body = <!--##=sExportWordUrl##--> . <!--##=sExportToWordCaption##--> . "</a>"; $item->Visible = <!--##=ew_Val(bExportWord)##-->; <!--## if (CTRL.CtrlID == "list" || CTRL.CtrlID == "view") { ##--> // Export to Html $item = &$this->ExportOptions->Add("html"); $item->Body = <!--##=sExportHtmlUrl##--> . <!--##=sExportToHtmlCaption##--> . "</a>"; $item->Visible = <!--##=ew_Val(bExportHtml)##-->; // Export to Xml $item = &$this->ExportOptions->Add("xml"); $item->Body = <!--##=sExportXmlUrl##--> . <!--##=sExportToXmlCaption##--> . "</a>"; $item->Visible = <!--##=ew_Val(bExportXml)##-->; // Export to Csv $item = &$this->ExportOptions->Add("csv"); $item->Body = <!--##=sExportCsvUrl##--> . <!--##=sExportToCsvCaption##--> . "</a>"; $item->Visible = <!--##=ew_Val(bExportCsv)##-->; // Export to Pdf $item = &$this->ExportOptions->Add("pdf"); $item->Body = <!--##=sExportPdfUrl##--> . <!--##=sExportToPdfCaption##--> . "</a>"; $item->Visible = <!--##=ew_Val(bExportPDF)##-->; // Export to Email $item = &$this->ExportOptions->Add("email"); <!--## if (CTRL.CtrlID == "list") { ##--> $item->Body = "<a name=\"emf_<!--##=gsTblVar##-->\" id=\"emf_<!--##=gsTblVar##-->\" href=\"javascript:void(0);\" onclick=\"ew_EmailDialogShow({lnk:'emf_<!--##=gsTblVar##-->',hdr:ewLanguage.Phrase('ExportToEmail'),f:<!--##=sJsFormName##-->,sel:<!--##=ew_JsVal(bExportSelectedOnly)##-->});\">" . <!--##=sExportToEmailCaption##--> . "</a>"; <!--## } else if (CTRL.CtrlID == "view") { ##--> $item->Body = "<a name=\"emf_<!--##=gsTblVar##-->\" id=\"emf_<!--##=gsTblVar##-->\" href=\"javascript:void(0);\" onclick=\"ew_EmailDialogShow({lnk:'emf_<!--##=gsTblVar##-->',hdr:ewLanguage.Phrase('ExportToEmail'),key:" . ew_ArrayToJsonAttr($this->RecKey) . ",sel:false});\">" . <!--##=sExportToEmailCaption##--> . "</a>"; <!--## } ##--> $item->Visible = <!--##=ew_Val(bExportEmail)##-->; <!--## } ##-->
then replace it with the following code:
// Begin of modification Permission Access for Export To Feature, by Masino Sinaga, May 5, 2012 global $Language, $Security; // <-- Added $Security variable by Masino Sinaga // Printer friendly <!--## if (bDynamicUserLevel) { ##--> if ($Security->CanExportToPrint() || $Security->IsAdmin() ) { <!--## } ##--> $item = &$this->ExportOptions->Add("print"); $item->Body = <!--##=sExportPrintUrl##--> . <!--##=sPrinterFriendlyCaption##--> . "</a>"; $item->Visible = <!--##=ew_Val(bPrinterFriendly)##-->; } // Export to Excel <!--## if (bDynamicUserLevel) { ##--> if ($Security->CanExportToExcel() || $Security->IsAdmin() ) { <!--## } ##--> $item = &$this->ExportOptions->Add("excel"); $item->Body = <!--##=sExportExcelUrl##--> . <!--##=sExportToExcelCaption##--> . "</a>"; $item->Visible = <!--##=ew_Val(bExportExcel)##-->; <!--## if (bDynamicUserLevel) { ##--> } <!--## } ##--> // Export to Word <!--## if (bDynamicUserLevel) { ##--> if ($Security->CanExportToWord() || $Security->IsAdmin() ) { <!--## } ##--> $item = &$this->ExportOptions->Add("word"); $item->Body = <!--##=sExportWordUrl##--> . <!--##=sExportToWordCaption##--> . "</a>"; $item->Visible = <!--##=ew_Val(bExportWord)##-->; } <!--## if (CTRL.CtrlID == "list" || CTRL.CtrlID == "view") { ##--> // Export to Html <!--## if (bDynamicUserLevel) { ##--> if ($Security->CanExportToHTML() || $Security->IsAdmin() ) { <!--## } ##--> $item = &$this->ExportOptions->Add("html"); $item->Body = <!--##=sExportHtmlUrl##--> . <!--##=sExportToHtmlCaption##--> . "</a>"; $item->Visible = <!--##=ew_Val(bExportHtml)##-->; <!--## if (bDynamicUserLevel) { ##--> } <!--## } ##--> // Export to Xml <!--## if (bDynamicUserLevel) { ##--> if ($Security->CanExportToXML() || $Security->IsAdmin() ) { <!--## } ##--> $item = &$this->ExportOptions->Add("xml"); $item->Body = <!--##=sExportXmlUrl##--> . <!--##=sExportToXmlCaption##--> . "</a>"; $item->Visible = <!--##=ew_Val(bExportXml)##-->; <!--## if (bDynamicUserLevel) { ##--> } <!--## } ##--> // Export to Csv <!--## if (bDynamicUserLevel) { ##--> if ($Security->CanExportToCSV() || $Security->IsAdmin() ) { <!--## } ##--> $item = &$this->ExportOptions->Add("csv"); $item->Body = <!--##=sExportCsvUrl##--> . <!--##=sExportToCsvCaption##--> . "</a>"; $item->Visible = <!--##=ew_Val(bExportCsv)##-->; <!--## if (bDynamicUserLevel) { ##--> } <!--## } ##--> // Export to Pdf <!--## if (bDynamicUserLevel) { ##--> if ($Security->CanExportToPDF() || $Security->IsAdmin() ) { <!--## } ##--> $item = &$this->ExportOptions->Add("pdf"); $item->Body = <!--##=sExportPdfUrl##--> . <!--##=sExportToPdfCaption##--> . "</a>"; $item->Visible = <!--##=ew_Val(bExportPDF)##-->; <!--## if (bDynamicUserLevel) { ##--> } <!--## } ##--> // Export to Email <!--## if (bDynamicUserLevel) { ##--> if ($Security->CanExportToEmail() || $Security->IsAdmin() ) { <!--## } ##--> $item = &$this->ExportOptions->Add("email"); <!--## if (CTRL.CtrlID == "list") { ##--> $item->Body = "<a name=\"emf_<!--##=gsTblVar##-->\" id=\"emf_<!--##=gsTblVar##-->\" href=\"javascript:void(0);\" onclick=\"ew_EmailDialogShow({lnk:'emf_<!--##=gsTblVar##-->',hdr:ewLanguage.Phrase('ExportToEmail'),f:<!--##=sJsFormName##-->,sel:<!--##=ew_JsVal(bExportSelectedOnly)##-->});\">" . <!--##=sExportToEmailCaption##--> . "</a>"; <!--## } else if (CTRL.CtrlID == "view") { ##--> $item->Body = "<a name=\"emf_<!--##=gsTblVar##-->\" id=\"emf_<!--##=gsTblVar##-->\" href=\"javascript:void(0);\" onclick=\"ew_EmailDialogShow({lnk:'emf_<!--##=gsTblVar##-->',hdr:ewLanguage.Phrase('ExportToEmail'),key:" . ew_ArrayToJsonAttr($this->RecKey) . ",sel:false});\">" . <!--##=sExportToEmailCaption##--> . "</a>"; <!--## } ##--> $item->Visible = <!--##=ew_Val(bExportEmail)##-->; <!--## if (bDynamicUserLevel) { ##--> } <!--## } ##--> <!--## } ##--> // End of modification Permission Access for Export To Feature, by Masino Sinaga, May 5, 2012
-
Open your \Script\userpriv.php file, and find this code:
for ($i = 0; $i < $this->TableNameCount; $i++) { if (defined("EW_USER_LEVEL_COMPAT")) { $this->Privileges[$i] = intval(@$_POST["Add_" . $i]) + intval(@$_POST["Delete_" . $i]) + intval(@$_POST["Edit_" . $i]) + intval(@$_POST["List_" . $i]); } else { $this->Privileges[$i] = intval(@$_POST["Add_" . $i]) + intval(@$_POST["Delete_" . $i]) + intval(@$_POST["Edit_" . $i]) + intval(@$_POST["List_" . $i]) + intval(@$_POST["View_" . $i]) + intval(@$_POST["Search_" . $i]); } }
then replace it with the following code:
// Begin of modification Permission Access for Export To Feature, by Masino Sinaga, May 5, 2012 for ($i = 0; $i < $this->TableNameCount; $i++) { if (defined("EW_USER_LEVEL_COMPAT")) { $this->Privileges[$i] = intval(@$_POST["Add_" . $i]) + intval(@$_POST["Delete_" . $i]) + intval(@$_POST["Edit_" . $i]) + intval(@$_POST["List_" . $i]) + intval(@$_POST["Printer_" . $i]) + intval(@$_POST["HTML_" . $i]) + intval(@$_POST["Excel_" . $i]) + intval(@$_POST["Word_" . $i]) + intval(@$_POST["PDF_" . $i]) + intval(@$_POST["XML_" . $i]) + intval(@$_POST["CSV_" . $i]) + intval(@$_POST["Email_" . $i]); } else { $this->Privileges[$i] = intval(@$_POST["Add_" . $i]) + intval(@$_POST["Delete_" . $i]) + intval(@$_POST["Edit_" . $i]) + intval(@$_POST["List_" . $i]) + intval(@$_POST["View_" . $i]) + intval(@$_POST["Search_" . $i]) + intval(@$_POST["Printer_" . $i]) + intval(@$_POST["HTML_" . $i]) + intval(@$_POST["Excel_" . $i]) + intval(@$_POST["Word_" . $i]) + intval(@$_POST["PDF_" . $i]) + intval(@$_POST["XML_" . $i]) + intval(@$_POST["CSV_" . $i]) + intval(@$_POST["Email_" . $i]); } } // End of modification Permission Access for Export To Feature, by Masino Sinaga, May 5, 2012
-
Still in that \Script\userpriv.php file, find again this code (only for PHPMaker < 9.1.0):
[code lang="php"]
->Disabled ?> />
[/code]of if you are using PHPMaker >= 9.1.0, then find this code:
<td><table class="ewTableHeaderBtn"><tr><td><!--##@PermissionSearch##--><input type="checkbox" name="Search" id="Search" onclick="ew_SelectAll(this);"<?php echo $<!--##=sPageObj##-->->Disabled ?> /></td></tr></table></td> <?php } ?>
after the last line of that code, please insert the following code:
<?php // Begin of modification Permission Access for Export To Feature, by Masino Sinaga, May 5, 2012 ?> <td><!--##@PermissionPrinterFriendly##--><input type="checkbox" name="Printer" id="Printer" onclick="ew_SelectAll(this);"<?php echo $<!--##=sPageObj##-->->sDisabled ?> /></td> <td><!--##@PermissionExportToExcel##--><input type="checkbox" name="Excel" id="Excel" onclick="ew_SelectAll(this);"<?php echo $<!--##=sPageObj##-->->sDisabled ?> /></td> <td><!--##@PermissionExportToWord##--><input type="checkbox" name="Word" id="Word" onclick="ew_SelectAll(this);"<?php echo $<!--##=sPageObj##-->->sDisabled ?> /></td> <td><!--##@PermissionExportToHTML##--><input type="checkbox" name="HTML" id="HTML" onclick="ew_SelectAll(this);"<?php echo $<!--##=sPageObj##-->->sDisabled ?> /></td> <td><!--##@PermissionExportToXML##--><input type="checkbox" name="XML" id="XML" onclick="ew_SelectAll(this);"<?php echo $<!--##=sPageObj##-->->sDisabled ?> /></td> <td><!--##@PermissionExportToCSV##--><input type="checkbox" name="CSV" id="CSV" onclick="ew_SelectAll(this);"<?php echo $<!--##=sPageObj##-->->sDisabled ?> /></td> <td><!--##@PermissionExportToPDF##--><input type="checkbox" name="PDF" id="PDF" onclick="ew_SelectAll(this);"<?php echo $<!--##=sPageObj##-->->sDisabled ?> /></td> <td><!--##@PermissionExportToEmail##--><input type="checkbox" name="Email" id="Email" onclick="ew_SelectAll(this);"<?php echo $<!--##=sPageObj##-->->sDisabled ?> /></td> <td><!--##@TableOrView##--></td> <?php // End of modification Permission Access for Export To Feature, by Masino Sinaga, May 5, 2012 ?>
-
Still in that \Script\userpriv.php file, find again this code (only for you who are using PHPMaker <= 9.0.3):
[code lang="php"]
->TempPriv & EW_ALLOW_SEARCH) == EW_ALLOW_SEARCH) { ?> checked="checked"->Disabled ?> />
[/code]and for those of you who are using PHPMaker >= 9.0.4 and < 9.1.0, then find this following code: [code lang="php"]
->TempPriv & EW_ALLOW_SEARCH) == EW_ALLOW_SEARCH) { ?> checked="checked"->Disabled ?> />
[/code]and for those of you who are using PHPMaker >= 9.1.0, then find this code:
<td class="ewCheckbox"><input type="checkbox" name="Search_<?php echo $i ?>" id="Search_<?php echo $i ?>" value="64"<?php if (($<!--##=sPageObj##-->->TempPriv & EW_ALLOW_SEARCH) == EW_ALLOW_SEARCH) { ?> checked="checked"<?php } ?><?php echo $<!--##=sPageObj##-->->Disabled ?> /></td> <?php } ?>
after the last line of that code, please insert the following code (only for you who are using PHPMaker <= 9.0.3): [code lang="php"]
->TempPriv & MS_ALLOW_EXPORT_TO_PRINT) == MS_ALLOW_EXPORT_TO_PRINT) { ?> checked="checked"->sDisabled ?> /> ->TempPriv & MS_ALLOW_EXPORT_TO_EXCEL) == MS_ALLOW_EXPORT_TO_EXCEL) { ?> checked="checked"->sDisabled ?> /> ->TempPriv & MS_ALLOW_EXPORT_TO_WORD) == MS_ALLOW_EXPORT_TO_WORD) { ?> checked="checked"->sDisabled ?> /> ->TempPriv & MS_ALLOW_EXPORT_TO_HTML) == MS_ALLOW_EXPORT_TO_HTML) { ?> checked="checked"->sDisabled ?> /> ->TempPriv & MS_ALLOW_EXPORT_TO_XML) == MS_ALLOW_EXPORT_TO_XML) { ?> checked="checked"->sDisabled ?> /> ->TempPriv & MS_ALLOW_EXPORT_TO_CSV) == MS_ALLOW_EXPORT_TO_CSV) { ?> checked="checked"->sDisabled ?> /> ->TempPriv & MS_ALLOW_EXPORT_TO_PDF) == MS_ALLOW_EXPORT_TO_PDF) { ?> checked="checked"->sDisabled ?> /> ->TempPriv & MS_ALLOW_EXPORT_TO_EMAIL) == MS_ALLOW_EXPORT_TO_EMAIL) { ?> checked="checked"->sDisabled ?> /> ->GetTableCaption($i) ?>
[/code]whereas for those of you who are using PHPMaker >= 9.0.4, then please insert the following code:
<?php // Begin of modification Permission Access for Export To Feature, by Masino Sinaga, May 5, 2012 ?> <td class="ewUserPermission"><input type="checkbox" name="Printer_<?php echo $i ?>" id="Printer_<?php echo $i ?>" value="128"<?php if (($<!--##=sPageObj##-->->TempPriv & MS_ALLOW_EXPORT_TO_PRINT) == MS_ALLOW_EXPORT_TO_PRINT) { ?> checked="checked"<?php } ?><?php echo $<!--##=sPageObj##-->->sDisabled ?> /></td> <td class="ewUserPermission"><input type="checkbox" name="Excel_<?php echo $i ?>" id="Excel_<?php echo $i ?>" value="256"<?php if (($<!--##=sPageObj##-->->TempPriv & MS_ALLOW_EXPORT_TO_EXCEL) == MS_ALLOW_EXPORT_TO_EXCEL) { ?> checked="checked"<?php } ?><?php echo $<!--##=sPageObj##-->->sDisabled ?> /></td> <td class="ewUserPermission"><input type="checkbox" name="Word_<?php echo $i ?>" id="Word_<?php echo $i ?>" value="512"<?php if (($<!--##=sPageObj##-->->TempPriv & MS_ALLOW_EXPORT_TO_WORD) == MS_ALLOW_EXPORT_TO_WORD) { ?> checked="checked"<?php } ?><?php echo $<!--##=sPageObj##-->->sDisabled ?> /></td> <td class="ewUserPermission"><input type="checkbox" name="HTML_<?php echo $i ?>" id="HTML_<?php echo $i ?>" value="1024"<?php if (($<!--##=sPageObj##-->->TempPriv & MS_ALLOW_EXPORT_TO_HTML) == MS_ALLOW_EXPORT_TO_HTML) { ?> checked="checked"<?php } ?><?php echo $<!--##=sPageObj##-->->sDisabled ?> /></td> <td class="ewUserPermission"><input type="checkbox" name="XML_<?php echo $i ?>" id="XML_<?php echo $i ?>" value="2048"<?php if (($<!--##=sPageObj##-->->TempPriv & MS_ALLOW_EXPORT_TO_XML) == MS_ALLOW_EXPORT_TO_XML) { ?> checked="checked"<?php } ?><?php echo $<!--##=sPageObj##-->->sDisabled ?> /></td> <td class="ewUserPermission"><input type="checkbox" name="CSV_<?php echo $i ?>" id="CSV_<?php echo $i ?>" value="4096"<?php if (($<!--##=sPageObj##-->->TempPriv & MS_ALLOW_EXPORT_TO_CSV) == MS_ALLOW_EXPORT_TO_CSV) { ?> checked="checked"<?php } ?><?php echo $<!--##=sPageObj##-->->sDisabled ?> /></td> <td class="ewUserPermission"><input type="checkbox" name="PDF_<?php echo $i ?>" id="PDF_<?php echo $i ?>" value="8192"<?php if (($<!--##=sPageObj##-->->TempPriv & MS_ALLOW_EXPORT_TO_PDF) == MS_ALLOW_EXPORT_TO_PDF) { ?> checked="checked"<?php } ?><?php echo $<!--##=sPageObj##-->->sDisabled ?> /></td> <td class="ewUserPermission"><input type="checkbox" name="Email_<?php echo $i ?>" id="Email_<?php echo $i ?>" value="16384"<?php if (($<!--##=sPageObj##-->->TempPriv & MS_ALLOW_EXPORT_TO_EMAIL) == MS_ALLOW_EXPORT_TO_EMAIL) { ?> checked="checked"<?php } ?><?php echo $<!--##=sPageObj##-->->sDisabled ?> /></td> <td><span class="phpmaker"><?php echo $<!--##=sPageObj##-->->GetTableCaption($i) ?></span></td> <?php // End of modification Permission Access for Export To Feature, by Masino Sinaga, May 5, 2012 ?>
-
Open your \Script\phpcommon-scripts.php file, and find this code:
$gsExportFile = $this->TableVar; // Get export file, used in header <!--## } ##-->
after the last line of that code, please insert the following code:
<!--## if (bDynamicUserLevel) { ##--> // Begin of modification Permission Access for Export To Feature, by Masino Sinaga, To prevent users entering from URL, May 12, 2012 global $gsExport; if ($gsExport=="print") { if (!$Security->CanExportToPrint() && !$Security->IsAdmin()) { echo $Language->Phrase("nopermission"); exit(); } } elseif ($gsExport=="excel") { if (!$Security->CanExportToExcel() && !$Security->IsAdmin()) { echo $Language->Phrase("nopermission"); exit(); } } elseif ($gsExport=="word") { if (!$Security->CanExportToWord() && !$Security->IsAdmin()) { echo $Language->Phrase("nopermission"); exit(); } } elseif ($gsExport=="html") { if (!$Security->CanExportToHTML() && !$Security->IsAdmin()) { echo $Language->Phrase("nopermission"); exit(); } } elseif ($gsExport=="csv") { if (!$Security->CanExportToCSV() && !$Security->IsAdmin()) { echo $Language->Phrase("nopermission"); exit(); } } elseif ($gsExport=="xml") { if (!$Security->CanExportToXML() && !$Security->IsAdmin()) { echo $Language->Phrase("nopermission"); exit(); } } elseif ($gsExport=="pdf") { if (!$Security->CanExportToPDF() && !$Security->IsAdmin()) { echo $Language->Phrase("nopermission"); exit(); } } elseif ($gsExport=="email") { if (!$Security->CanExportToEmail() && !$Security->IsAdmin()) { echo $Language->Phrase("nopermission"); exit(); } } // End of modification Permission Access for Export To Feature, by Masino Sinaga, To prevent users entering from URL, May 12, 2012 <!--## } ##-->
Make sure you don’t miss this step, as this will prevent users that do not have permission for the certain “export” to enter the URL directly from the address of browser. Keep in mind that users which have Administrator level still be able to use this "Export to ..." features.
- Finally, re-generate your script files using PHPMaker application as always.
[/hidepost]
I had to modify the userpriv.php template from
to
I’m using 9.0.3. I was getting numerous errors with sDisabled as undefined. After the change I made, it worked perfectly.
I’m curious what the differences are between how you got it to work and I didn’t. Am I doing something wrong or am I missing a step? Should I actually be using sDisabled and have it defined somewhere?
Keith, please implement the customization in the following article I wrote: How to Prevent Error “Notice: Undefined property: classname” in Websites that Generated with PHPMaker 9.0.1 in order to prevent the error.
This does not seem to be working in 9.0.4
One problem seems to be Step 9.
In the search parameters, you have us looking for:
but the replacement code does not have:
the alignment of the export checkboxes appear to offset from the header of the list.
Please explain your statement in more detail as following:
Have you read all the instruction in step 9 completely? Did you implement step 9?
Just for your information, I had tested it in 9.0.4, and it works properly.
I have implemented Step 9 several times with the same results.
userpriv.php continues to give me an error until I add another after (or before) the one that is replaced in step 9.
When I do replace it, I no longer get an error but the export links are checkboxes to the right of the table header.
Actually, there is no export links in userpriv.php page, since from this userpriv.php page, users which have admin level will be able to define which pages should be assigned with the certain export permissions via those checkboxes.
Make sure you have implemented step 8 and 9 correctly, as I did not get any trouble here. Step 8 for customizing the checkboxes in table header, whereas step 9 for customizing the checkboxes in the table rows of User Level Permissions.
In addition, this customization actually similar to this article:
How to Restrict Access Permission to “Export to …” in Website Created With PHPMaker 8.0.3.
As you can see the screenshot from that article, the new userpriv.php page (after implementing customization) will change. There are 8 additional columns added, each of them has the checkbox for defining the export permission for the certain table/view/page.
I get no additional columns except the header column. Can you send me your userpriv.php for 9.0.4 and I can compare it with what I have?
Sure. I just sent it to your email.
Looks like you already corrected the instructions on your end. they originally indicated to replace the code in 9.0.4 and they now indicate to insert it.
It’s working correctly on my end now.
I have followed the instructions several times.
there is a missing right brace “}” in the userpriv.php code
When I attempt to run userpriv.php, I get the following error:
Parse error: syntax error, unexpected $end in /home/support/public_html/sandbox/userpriv.php on line 590
Ah I see. I think there was a misunderstood for step number 9. Replacing in the last part of the step 9 meant inserting the replacement code. I wrote it “replace” before, meant that replacing the replacement code in < = 9.0.3 with the customization for >= 9.0.4. I just changed the instruction become “insert” instead of “replace”. Thanks for reminding this.
The code in Step 8 does not exist in PHPMaker 9.1.
I found what appears to be the code on line #152, but it contains additional elements to close the row and table.
I could also not find an exact match for Step 6 in PHPMaker 9.1 either.
Actually, it exists already, but only partial. I just updated the instruction in step 8 by adding for version >= 9.1.0.
Regarding step 6, it’s around line 2239 – 2278 in the original \Script\share-script.php file. Keep in mind that you will not find it if you have implemented my another customization regarding “Export To” features. So, I suggest you to implement my customization from the article which has the order by Date smaller first.
It seems that PHPMaker views don’t get a checkbox on the list page so that the records can be exported.
Make sure you have selected “Selected records” from PHP -> List/View Page Options (Global) -> Export -> Export type, and then re-generate your script files.
Masino,
I have done all of that. the database List pages work perfectly. the list pages for the PHPMaker “custom view” pages do not have the checkboxes to select the records.
It can be happened if the Custom View does not have the Primary Key. Make sure you have defined the Primary Key for the Custom View from PHPMaker. Afterwards, re-generate your script files again.
Ahhhh
that’s it.