Privileges on Export

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

Privileges on Export

Post by morrellaberdeen »

Is it possible to set privileges on the export to Word, Excel, Printer Friendly, etc, so that only certain users can do so and others cannot?


danielc
User
Posts: 1601

Post by danielc »

You can only set in Page_Load server event for your page:
if (CurrentUserLevel() == x) // set your desired user level to hide the export option
{$item = @$this->ExportOptions->Items["print"]; // print or excel or word
if ($item)
$item->Visible = FALSE;}


morrellaberdeen
User
Posts: 187

Post by morrellaberdeen »

It worked when I use it to hide a single export option, for example - excel. However, I want to hide excel, word, print, email. I tried repeating the code for each of these exports separately and it did not work. I know I maybe missing the syntax somewhere. How do I adjust the code so that all of the above exports are hidden?


danielc
User
Posts: 1601

Post by danielc »

Can you show us the code? If you repeat the code with the modification of item["xxx"], it will work.


morrellaberdeen
User
Posts: 187

Post by morrellaberdeen »

This is the code. I have also repeated it with the - function Page_Load() - line in every section. If I leave only the first, it works. Once I repeat, the list page is blank and is not even loading the table.

// Page Load event
function Page_Load() {
//echo "Page Load";
if (CurrentUserLevel() == 1) // set your desired user level to hide the export option
{
$item = @$this->ExportOptions->Items["excel"]; // print or excel or word
if ($item)
$item->Visible = FALSE;}
}
{
//echo "Page Load";
if (CurrentUserLevel() == 1) // set your desired user level to hide the export option
{
$item = @$this->ExportOptions->Items["print"]; // print or excel or word
if ($item)
$item->Visible = FALSE;}
}

{
//echo "Page Load";
if (CurrentUserLevel() == 1) // set your desired user level to hide the export option
{
$item = @$this->ExportOptions->Items["word"]; // print or excel or word
if ($item)
$item->Visible = FALSE;}
}


danielc
User
Posts: 1601

Post by danielc »

Check your extra bracket. It is something like:

if (CurrentUserLevel() == 1)
{
$item = @$this->ExportOptions->Items["word"]; // print or excel or word
if ($item)
$item->Visible = FALSE;

$item = @$this->ExportOptions->Items["print"]; // print or excel or word
if ($item)
$item->Visible = FALSE;

...
}


morrellaberdeen
User
Posts: 187

Post by morrellaberdeen »

See the code below. This is now the problem I am having. According to this code, these export options are only hidden when the CurrentUserLevel is 1. Certainly with the admin I should be able to see all the options. I am however, only seeing excel or whatever option is listed first in the code.

// Page Load event
function Page_Load() {
//echo "Page Load";
if (CurrentUserLevel() == 1) // set your desired user level to hide the export option


$item = @$this->ExportOptions->Items["excel"]; // print or excel or word
if ($item)
$item->Visible = FALSE;

$item = @$this->ExportOptions->Items["word"]; // print or excel or word
if ($item)
$item->Visible = FALSE;

$item = @$this->ExportOptions->Items["print"]; // print or excel or word
if ($item)
$item->Visible = FALSE;
}


morrellaberdeen
User
Posts: 187

Post by morrellaberdeen »

The strangest things are happening and I am beginning to think that this goes beyond the code. See the post just above this. I complained that only excel was showing. I changed in the code word to Word and print to Print, meaning I made the first letter uppercase. All showed but ignored the CurrentUserLevel == 1. Excel remained hidden from that userlevel as excel was still all lowercase. So I made the first letter in excel uppercase. Excel then began to do just what Word and Print was doing, that is, remaining visible when CurrentUserLevel == 1. However as I mentioned in the prior post, if I make them all lower case, only the first export item function as it should - in this case excel.


danielc
User
Posts: 1601

Post by danielc »

You need to put bracket for your if condition:
if (CurrentUserLevel() == 1) {
...
}

I have tried the code without issue (just lowercase, excel/word/print). You may need to dump your variable to check.


morrellaberdeen
User
Posts: 187

Post by morrellaberdeen »

Thanks for your much help and patience. It worked well.


mobhar
User
Posts: 11746

Post by mobhar »

Be careful! :)

That code is only for hiding the export icons, but if your users obviously know about the export link, then they are still able to export your data by typing the URL from their browser address.

For example:
h++p://www.yourwebapp.com/customerslist.php?export=print
or
h++p://www.yourwebapp.com/customerslist.php?export=excel


morrellaberdeen
User
Posts: 187

Post by morrellaberdeen »

Thanks for the advice.


mobhar
User
Posts: 11746

Post by mobhar »

You're welcome.


Post Reply