Page 1 of 2

User defined buttons

Posted: Sun Oct 13, 2013 6:48 am
by janosh

Hi there,
Is it possible with PHPMaker 10 to define my own buttons underneath the table, which execute a server side script when clicked?
regards,
janosh


Re: User defined buttons

Posted: Sun Oct 13, 2013 2:15 pm
by mobhar

Yes, it is. But you cannot run the server event on its click event. You should run the Javascript code on the click event.

Put this following code into your "Page_Render" server event of the List page in order to insert the new button:

$options = &$this->OtherOptions;
$option = $options["action"];
$item = &$option->Add("mybutton");
$item->Body = "<a class=\"ewAction\" href=\"\" onclick=\"YourJavaScritpFunction();return false;\">My New Button</a>";

However, if you want to execute your own php code in the certain php file, try to change the last line of that code above, become:

$item->Body = "<a class=\"ewAction\" href=\"yourphpfile.php\" >My New Button</a>";


Re: User defined buttons

Posted: Mon Oct 14, 2013 3:20 am
by starquest321

Can you gave an idea of what this would be used for so I can enhance my own project? What are you doing with your own buttons server side for example?


Re: User defined buttons

Posted: Mon Nov 11, 2013 10:44 pm
by janosh

Hi starquest321,
In my case I use that button for "Approval". After the user has reviewd all relevant records in the list page, s/he can click on [Approve] button and then a flag gets set on server side for every selected record.
brgds,
janosh


Re: User defined buttons

Posted: Tue Nov 12, 2013 12:56 pm
by sentnel

Hello again!

My problem is constructing the URL, referencing the variable.

This:
$item->Body = "<a class=\"ewAction\" href=\"yourphpfile.php?\" >My New Button</a>";

How do I end up with a URL like this:
yourphpfile.php?purchaseorder=800

If I try someting like this
$item->Body = "<a class=\"ewAction\" href=\"printordencompra.php?purchaseorder=$ordernumber">Print Purchase Order</a>";

I get a blank page. Thanks for your help!


Re: User defined buttons

Posted: Tue Nov 12, 2013 1:23 pm
by mobhar

@sentnel,

You have to handle the receiving variable in your "printordencompra.php" file by using $_GET["purchaseorder"] variable.

For example, in your "printordencompra.php" file, make sure you have already had the following code before processing the value:
<?php
$mypurchaseorder = "";
if (isset($GET["purchaseorder"])) {
$mypurchaseorder = $
GET["purchaseorder"];
} else {
$mypurchaseorder = "No purchase order provided";
}
echo $mypurchaseorder; // just to make sure the value is right
?>

Also, make sure you have already had a correct value in $ordernumber variable before clicking on that custom link.


Re: User defined buttons

Posted: Tue Nov 12, 2013 7:14 pm
by sentnel

Thanks mobhar!

I have no problem receiving the variable, the problem is "sending" the variable. My problem is here:

$item->Body = "<a class=\"ewAction\" href=\"yourphpfile.php?\" >My New Button</a>";

How do I properly format this to include and send the "purchaseorder" variable after "yourphpfile.php?\"?

Thanks again!


Re: User defined buttons

Posted: Tue Nov 12, 2013 7:45 pm
by mobhar

Try this:

$ordernumber = "800"; // make sure the order number is correct
$item->Body = "<a class=\"ewAction\" href=\"printordencompra.php?purchaseorder=" . $ordernumber . "">Print Purchase Order</a>";


Re: User defined buttons

Posted: Wed Nov 13, 2013 11:46 am
by sentnel

Didn't work.

Also tried:
$item->Body = "<a class=\"ewAction\" href=\"printordencompra.php?purchaseorder=" . $ordernumber . "">Print Purchase Order</a>";

and:
$item->Body = "<a class=\"ewAction\" href=\"printordencompra.php?purchaseorder= $ordernumber">Print Purchase Order</a>";

The application won't even load, just get a blank screen. :-(


Re: User defined buttons

Posted: Wed Nov 13, 2013 11:51 am
by mobhar

In which server event did you put the code?


Re: User defined buttons

Posted: Wed Nov 13, 2013 12:41 pm
by danielc

sentnel wrote:
$item->Body = "<a class=\"ewAction\" href=\"printordencompra.php?purchaseorder="
. $ordernumber . "">Print Purchase Order</a>";

Miss \ for your " after $ordernumber:
$item->Body = "<a class=\"ewAction\" href=\"printordencompra.php?purchaseorder=" . $ordernumber . "\">Print Purchase Order</a>";


Re: User defined buttons

Posted: Thu Nov 14, 2013 7:00 am
by sentnel

Thanks a lot to all!

For future reference this the complete solution:

Code into your "Page_Render" server event of the List page:

$options = &$this->OtherOptions;
$option = $options["action"];
$item = &$option->Add("mybutton");    
$ordernumber=$this->ordenCompraDetail->CurrentValue;
$item->Body = "<a class=\"ewAction\" href=\"printordencompra.php?orden_compra=" . $ordernumber . "\">Print Purchase Order</a>";

Thanks again to all!


Re: User defined buttons

Posted: Wed Dec 13, 2017 9:25 am
by Fakiro82

Hi,
i'm sorry. I tried to use your suggestion but i don't understand how pass orderId value.

Can someone help me?

This is my code in ListPage --> Page Render:

if (!isset($_GET["showdetail"])) {
$options = &$this->OtherOptions;
$option = $options["action"];
$item = &$option->Add("mybutton");
$ordineFattura = $this->OrderID->CurrentValue;
//$item->Body = "<a class=btn href=Fattura.php?StampaOrdine=OrdersMaster&fk_OrderId=" .$ordineFattura. ">Stampa Fattura</a>";
$item->Body = "<a class=\"ewAction\" href=\"Fattura.php?orden_compra=" . $ordineFattura . "\">Print Purchase Order</a>";
}
}

Thank you.
Andrea.


Re: User defined buttons

Posted: Wed Dec 13, 2017 6:28 pm
by mobhar

Fakiro82 wrote:
i don't understand how pass orderId value.

You need to put your code in "Page_Render" of "List Page" that belongs to your detail table (not in master table).


Re: User defined buttons

Posted: Wed Dec 13, 2017 8:36 pm
by Fakiro82

Hi mobhar,
My code is in OrderDetails Table (Detail Table). My Master Table is Orders table, but I don't know how can i do to pass value OrderID.
Probably my error is here:

$ordineFattura = $this->OrderID->CurrentValue;

because OrderId-->CurrentValue is empty. Right? Can you help me?

Thank you so much for your all suggestion.

Andrea.


Re: User defined buttons

Posted: Wed Dec 13, 2017 9:08 pm
by mobhar

Make sure you have already open the Master/Detail List page in order to pass the OrderID value, the URL should be like this (assume you are using the demo project), for example:

orderdetailslist.php?showmaster=orders&fk_OrderID=11076

So, to make sure the button will be shown up only when the Master/Detail List page is displayed (not in the individual detail List page), then change your code become:

if ($this->getCurrentMasterTable() != "") { // make sure the detail list page is being displayed when it contains the master table (Master/Detail List page)
$options = &$this->OtherOptions;
$option = $options["action"];
$item = &$option->Add("mybutton");
$ordineFattura = $this->OrderID->CurrentValue;
//$item->Body = "<a class=btn href=Fattura.php?StampaOrdine=OrdersMaster&fk_OrderId=" .$ordineFattura. ">Stampa Fattura</a>";
$item->Body = "<a class=\"ewAction\" href=\"Fattura.php?orden_compra=" . $ordineFattura . "\">Print Purchase Order</a>";
}


Re: User defined buttons

Posted: Thu Dec 14, 2017 9:12 am
by Fakiro82

Hi mobhar,
first of all thank you so much.
Then, I tried with your suggest and I rewrited the code like below:

// Page Render event
function Page_Render() {
//echo "Page Render";

if ($this->getCurrentMasterTable() != "") { // make sure the detail list page is being displayed when it contains the master table (Master/Detail List page)
$options = &$this->OtherOptions;
$option = $options["action"];
$item = &$option->Add("mybutton"); 
//$ordineFattura = $this->OrderID->CurrentValue;
$item->Body = "<a class=\"ewAction\" href=\"Fattura.php?OrderID=".urlencode($this->OrderId->CurrentValue)."\">Genera Fattura</a>";

}
}

The script works only If I add ".urlencode($this->OrderId->CurrentValue)." in URL. but If I insert ".$ordineFattura." in URL it doesn't work ($ordineFattura is always empty and I didn't find the problem). I don't know if this ( ".urlencode($this->OrderId->CurrentValue).") is the right way to solve the problem but it works. I would like to make it work like you suggest me.

Thank you so much mobhar.

Andrea.


Re: User defined buttons

Posted: Thu Dec 14, 2017 10:59 am
by mobhar

Change:
//$ordineFattura = $this->OrderID->CurrentValue;
$item->Body = "<a class=\"ewAction\" href=\"Fattura.php?OrderID=".urlencode($this->OrderId->CurrentValue)."\">Genera Fattura</a>";

to:
$ordineFattura = urlencode($this->OrderID->CurrentValue);
$item->Body = "<a class=\"ewAction\" href=\"Fattura.php?OrderID=".$ordineFattura."\">Genera Fattura</a>";


Re: User defined buttons

Posted: Thu Dec 14, 2017 12:39 pm
by mobhar

Sorry, this code:
$ordineFattura = urlencode($this->OrderID->CurrentValue);

should be:
$ordineFattura = urlencode($this->OrderId->CurrentValue); // case-sensitive field name


Re: User defined buttons

Posted: Thu Dec 14, 2017 4:37 pm
by Fakiro82

Hi mobhar,
Now it's works.

Thank you so much.

Andrea.