Echo toolbar button names via PHP

Of course, it’s possible to have a single call. For instance, for 3 buttons:

procedure ProcedureAll(text, text2, text3: String);
begin
SetUiProp(“Toolbar1BHome”, “Caption”,text);
SetUiProp(“Toolbar1bprint”, “Caption”,text2);
  // and so on
end;

Then in PHP:
exo_runhescriptcom ("UserMain.ProcedureAll|$button1|$button2|$button3");

Yes, it works :slight_smile:

Thank-you

Thanks for reply @Gilmichel and @gdgsupport

The path to sqlite database is:

$database_name = $_SERVER['DOCUMENT_ROOT'].'/general.db';

The table contents are simple BLOBS:

("CREATE TABLE IF NOT EXISTS misc (contacturl BLOB, supporturl BLOB, supporttext BLOB, abouttext BLOB)");

("INSERT INTO misc (contacturl,supporturl,supporttext,abouttext) VALUES ('http://example.com','http://example.com/support/','Help Desk','About Us')");

Nothing advanced, simply like to echo URL to custom button created with scripting and do so with the heexteranl:// option.

heexternal:// should do its job if you give a correct URL… Try to inspect the HTML code output by your PHP page using the Chromium Developer Tools: verify that the
<a href=“heexternal://<?php echo $row[‘supporturl’];?>”><?php echo $row[‘supporttext’];?></a></p>
is correctly output.

Yes, I understand how to use the heexternal and php. Asking this:

Is it possible to also link the button to url and have open in users default browser using hescripting?

Have the button working with custom text, now like to link it to external site and open in users default browser. The question is can this be done in hescript?

To create and verify your database with php, you can do the following :

$database_name = $_SERVER[‘DOCUMENT_ROOT’].‘/general.db’;
if(!file_exists($database_name)){
$db = new SQLite3($database_name);
$set = “”;
$set .=‘PRAGMA foreign_keys = ON;’;
$set .=‘PRAGMA encoding = UTF-8;’;
file_put_contents($set, $database_name) ;
$result = $db->exec(“CREATE TABLE IF NOT EXISTS misc(
contacturl TEXT,
supporturl TEXT,
supporttext TEXT,
abouttext TEXT
)”);
$result = $db->exec(“INSERT INTO misc (contacturl,supporturl,supporttext,abouttext)
VALUES (‘http://example.com’,‘http://example.com/support/','Help Desk’,‘About Us’)”);
$db->close();
}
$db = new SQLite3($database_name);
$result = $db->query(‘SELECT * FROM misc’);
while ($row = $result->fetchArray()) {
foreach($row as $k => $v){
echo <pre>.$k ." = ". $v.</pre>;
}
}
$db->close();

Then to echo url do like follow

$db = new SQLite3($database_name);
$result = $db->query(‘SELECT * FROM misc’);
while ($row = $result->fetchArray()) {
$contacturl = $row[‘contacturl’];
$supporturl = $row[‘supporturl’];
}
$db->close();
echo $contacturl;
echo $supporturl;

1 Like

Hello,

Is it possible to do the same replacement with image, button color, background color and more like we can do it with caption’s text on buttons ?

Thank-you !

One solution, for icon image change on button :

procedure PImage(text: String);
begin
SetUiProp(“Ribbon1BHome”, “ImageIndex”, text);
end;

Then :

echo exo_runhescriptcom(‘UserMain.PImage|0’,‘’);

If you change 0 for 1 see the effect when testing your app.

Now, what i am trying to do is to replace a TImage (in toolbar) with one locate in Data’s folder, is it possible ?

Example :

procedure PLogo(text: String);
begin
SetUiProp(“Ribbon1Logo”, “Picture”, text);
end;

Then:

$img = ‘src image path>’;
echo exo_runhescriptcom(‘LangMain.PLogo|$img’,‘’);

It is not replacing the picture that way !

These are very good tips @Gilmichel, thank you! Helping me grasp scripting little better: )

Now if I could just make a button URL changeable and target the users default browser…

1 Like

This you should be able to create it when you setup action for your button.
First create an hescript procedure, and then configure your button action using hescript to choose the one you just created:

Hescript:

procedure LoadURL;
begin
ExecuteHTMLScript(“loadurl()”, “JavaScript”);
end;

In your principal .php page add the following

<?php
$url = “your url”;
?>

Then add this javascript:

<script>
function loadurl() {
window.location=“heexternal://<?php echo $url; ?>”
}
</script>

Brilliant @Gilmichel ! I will give this a try later and let you know. Appreciate you sharing the knowledge.

@Gilmichel Could not wait and had to try adding url to toolbar button…

Cannot get past the error PHP Error: PHP Parse error: syntax error, unexpected ‘heexternal’ (T_STRING)

Script is in footer so not sure why of error like above. Will have to wait until later to test further, got to go to church: )

EDIT: Above issue was due to copy and paste from forum, strange characters caused error.

But not working, error in dev console says loadurl is not defined.

It’s not possible to replace image with SetUiProp but we’ll offer a way in next update.

1 Like

Try to move it to header of your HTML page

1 Like

I had tried that (sorry should have mentioned) and still get loadurl is not defined.

Currently have the $url = "http://google.com"; at very top of page and script in header but no go.

Can you show how do you write the javascript function concerned ?

Also, try to copy paste, before to use it in your script, in notepad the code I have showed you and then, in notepad, replace the double quote if necessary. Then copy the code from notepad and paste it in your script.
And don’t forget to use https and not http for your url !

Thanks for response @Gilmichel

I have added the code as you provided:

Added Hescript:

    procedure LoadURL;
    begin
    ExecuteHTMLScript("loadurl()", "JavaScript");
    end;

At the very top of my page (before everything else):

    <?php
    $url = "http://google.com";
    ?>

In my header:

    
    function loadurl() {
    window.location="heexternal://<?php echo $url; ?>"
    }

Had to remove the scrip tags as forum now forbids and shows 403 error popup, but the opening and closing tags are in place.

Not sure how https for URL would help to solve the undefined loadurl() issue, but tried it to be sure and no change. Still get the loadurl() undefined error when clicking the toolbar button.

EDIT UPDATE: As usual, my problem your code works fine… Somehow the function loadurl() in script got converted to function loadUrl(). Guessing plugin for my notepad++ auto assumed I want the capital U. Sorry for the hassle and thank you very much @Gilmichel !

Javascript function must be set between two folowing tags :
<script>

</script>

Yes, I got that. Think you missed:

@gdgsupport Is it a security risk to allow script tags wrapped in the preformatted feature? Only way to prevent foreign characters best I can tell.

Anyway, got it working as described above. Use notepad++ and one of the plugins converted function loadUrl() to function loadUrl() (notice the capital U). All good and appreciate your help much.

1 Like