Restrict export options

This public forum is for user-to-user discussions of PHPMaker. Note that this is not support forum.
Post Reply
daveb
User
Posts: 32

Restrict export options

Post by daveb »

I would like to stop exports of large files to avoid timeouts. The page is used for multiple purposes so requiring search criteria does not work. I would like to do this by checking if search criteria have been entered and then deciding whether to stop the export. In Page_Export:

$doc->Text = $this->SearchWhere;
 if ($this->SearchWhere == "")
 {
   $this->SearchWhere = '" 0 == NULL"' ;
 } 

The SearchWhere has the correct clause and shows in the exported header, but I can not find a value that makes the search fail . The Page_Export and Row_Export only appear to switch back and forth, but not allow the export to be cancelled.


arbei
User
Posts: 9384

Post by arbei »

The Page_Export and Row_Export are for customizing export content only. When the events are fired, the page is already exporting. You better check the search criteria in Page_Load and use Security()->setCanExport(false) to disable export.


daveb
User
Posts: 32

Post by daveb »

I was trying to check that the Security option was correct and tried it unconditionally to stop all exports, but the exports still ran. Is the

Security()->setCanExport(false)

the correct function to use? If I can get that right, then I can work on the criteria to selectively stop the export.

Thanks


arbei
User
Posts: 9384

Post by arbei »

If you are not checking search criteria, you better use TablePermission_Loaded server event and use $this->setCanExport(false). If you need to check search criteria, you need to use an event fired after the search criteria is loaded, TablePermission_Loaded is too early. If the user cannot export, the export button will not be shown. Of course, canExport() only works if security with users table is enabled.
Also, note that export is done by API, the API does not have any info about the search criteria. If you use the URL to access the API directly, the export still works unless TablePermission_Loaded server event is used.


daveb
User
Posts: 32

Post by daveb »

I want the export to run unless there are no criteria set. I tried to set the security() value in the Page_Load event to check that it would stop the export - then I could figure out the criteria later. I have decided to create another view for exporting - then I can use the "require search criteria" option as it will not interfere with the add/edit pages


Post Reply