Running cmd/bat files via custom links

austega

Member
I need some guidance particularly re applying a custom link using a calc element in a list display. Here is what I am trying to achieve:

  1. The fabrik_erd_records list contains more than a thousand records of electronic genealogical resources of three types (there is a non-displayed id_linktype element in the list for the three different types):
    1. Resources on local server (html or pdf) - accessed by appropriate URL
    2. Resources (websites) elsewhere on the internet - accessed by appropriate URL
    3. Installed Windows applications hosted on local IIS server - accessed by running appropriate cmd or bat file for example <javascript LaunchApp ('C:/TSapplications/Scripts/diggerbty.cmd');>
  2. The public to be able to click on the displayed ___resource element and be taken to the appropriate resource via the appropriate URL or script contained in the non-displayed ___link calc element (which is constructed as a conditional concatenation of text strings and non-displayed ___path and ___url elements in the list - the constructed string format varies conditionally on the id_linktype value).
  3. The administrator only to also be able to click on a details link (not visible to public) and to be able to edit/delete the full record.
To try to achieve this I have:
  1. Set the List | Access to Special for all but the View list which is Public
  2. Set the ___resource element | List View Settings | List settings | Custom Link to {fabrik_erd_records___link}, with Show in List and Link to details set to Yes, and other options on that tab set to No.
The residual problems:
  1. While the above seems to work for Resources of the first two types (see above), for resources of the third type it produces a link such as http://localhost/index.php/javascript%20LaunchApp%20('C:/TSapplications/Scripts/diggerbty.cmd');
    when the value of ___link for that record was "
    javascript LaunchApp ('C:/TSapplications/Scripts/diggerbty.cmd');" Where does the http://localhost/index.php/ prefix come from and how can I prevent it? It seems to be assuming it should treat the value as a relative link.
  2. I am not sure if javascript LaunchApp ('C:/TSapplications/Scripts/diggerbty.cmd');will achieve what is intended but it is in line with what was done on the previous version (not using Fabrik) that we are trying to replicate. In any case we want the element link in the Fabrik list display to trigger a cmd or bat file located on the server.
  3. The view and edit and delete icons are shown for each row when an admin user displays the list. However if the admin user edits a record?s ___path variable the ___link calc element is not recalculated but rather shows as a null value. How do I ensure this calc element recalculation is triggered on an edit of the underlying elements? At present the calc element has Calc on Save set to Yes.
This development site is not accessible on the internet. I can attach screen shots as required.
 
At present the calc element has Calc on Save set to Yes.
Why did you set this (default is NO)? If you are setting "Only calc on Save"=yes it's only calculating on record save and in list view the element is not calculated "on the fly" but reading the value of the DB.
So you have to re-edit and save every single existing record to put the value into the DB to get the correct one in list view.
 
Thanks troester. I now have no idea how but I came to the conclusion that Calc on Save was the more general alternative. Reading the tooltip reference notes now it is obvious I should have this set to No, which I now do. Just to be frustrating I am no longer seeing any of the rows as linking to this path variable. Probably something obvious but I have not yet been able to find the source of the new problem. Will look into this again when I am fresher.

Did you have any thoughts on my first two residual problems?
 
I am bound to be missing something obvious but I have bashed my head a couple of time around so need to ask...

My "description" element custom link to a calc element {fabrik_erd_records___link2} (which contains absolute urls) is no longer appearing as a link on the site front end list display of the description element - the data displays without any link (and the same non-link behavior occurs without any custom detail link code). It was appearing as a link before I edited the calc element and I am not sure what I have done to kill it. Is there any list of "missing link" trouble shooting steps I can check?

I think I have checked the published status and the permissions (public).

Also a friendly bump about my first residual question in my first post...
 
Did you set "link to details" in element's list view settings?

Not sure about your javascript stuff:
A HTML link has to be HTLM-encoded and if it's no absolute link (http...) it's thought to be relative, so this is the expected behaviour.
Is this procedure you want to call (C:/...) on the server or on every local user PC?
On the server you can link to a php file calling the procedure with e.g. execute.
 
Hi troester, I think I have the link to details set to yes in the element's list view settings - I have attached screen shots (hoping you can see I am missing something obvious) of:
1. The front end list display
2. The backend elements list
3. The List View settings of the description element, and
4. The Calc settings of the link element (that the description element is meant to link to).

Yes the scripts I want to call are on all the local clients attached to the LAN server. The server php execute option sounds worth my while exploring - thanks for that.
 

Attachments

  • DescriptionElementListSettings.PNG
    DescriptionElementListSettings.PNG
    30.1 KB · Views: 368
  • Elements.PNG
    Elements.PNG
    49.6 KB · Views: 387
  • FrontendListDisplay.PNG
    FrontendListDisplay.PNG
    64.5 KB · Views: 357
  • LinkElementCalcSettings.PNG
    LinkElementCalcSettings.PNG
    34 KB · Views: 361
Back again. I have edited the thread title to focus on the remaining problem of using custom links on a displayed element to launch applications resident on the IIS server into which the twenty or so user thin clients are logged.
  1. At present there are a range of cmd/bat files that are stored in C:\TSapplications\Scripts folder on the server into which the user clients are logged. I have attached a couple of screenshot examples of these cmd/bat files.
  2. The old database Joomla 1 application ran these cmd/bat files by applying the following type of link to the relevant description entries in a table display of the various resources available: <a href="javascript:LaunchApp ('C:/TSapplications/Scripts/acdbNZ.cmd');">...</a>
  3. I am trying to use Fabrik's custom detail link on the relevant element to achieve this but find that the "javascript:" is lost and that the remainder is appended to the domain name - ie is treated as a relative link.
  4. There is a mixture of resource types in the displayed list (not all are applications) and many are successfully achieved by placing simple URLs into the custom link. So I have been achieving this variation by resource record by maintaining the appropriate custom link content in a non-displayed element and then using the placeholder for this non-displayed element as the custom link for the displayed description element. (So the custom link content placeholder includes both http:// and javascript:LaunchApp type rows...)
  5. I think my questions are as follows:
    A. Is it possible to avoid any custom link that doesn't start with an http:// from being treated as a relative link?
    B. Is it possible to have part of the custom link content not evaluated but passed through for browser activation?
    C. Is it possible to include PHP code in the custom link field? I am thinking of possibly using the PHP exec command...
  6. There may be better ways of achieving the end goal - please suggest any!
 

Attachments

  • A245cd1c.PNG
    A245cd1c.PNG
    4.4 KB · Views: 339
  • acdbA3.PNG
    acdbA3.PNG
    5.4 KB · Views: 347
You can try to create the link directly in you calc element (and display the calc in list view instead of your element with custom link)
return '<a href="'. your-link .'">text</a>';
(I hope I've got the correct " and ', no guarantee).
 
Thanks for that.

I think my underlying problem would still exist with that approach, being that I want the custom link (or other method) to be able to handle both URL links (absolute and relative) appropriate to many records and also whatever script command is needed to have the user's browser launch an application via a cmd/bat file for records that refer to applications. Am I missing something here?

Reading between the lines of your reply (possibly incorrectly!), I gather the custom link field can include PHP code. Is this right?

If so, can I put my conditionality (dependent on record type which is stored in another element in the table) inside this field with it returning different types of results depending on the record type?

And for the cmd/bat files, could I use the PHP exec command as part of custom link code to determine what is returned/done when the link is clicked.

Finally is there a limit on the amount of code that can be placed in a custom link field?
 
No, the custom link field can't include php.

The possibilities of a custom link in element setting are limited: you are defining only a URL, Fabrik/Joomla are creating the complete link (so you can't e.g. set a target etc).
In a calc element you can return whatever you want.
That's why you should try to create the complete link (including the <a tag) in your calc element
Code:
if ...
return '<a href="http://....');">...</a>';
if...
return '<a href="javascript:LaunchApp ('C:/TSapplications/Scripts/acdbNZ.cmd');">...</a>';
...
(It's only an example, you have to escape the ' or split the string. Not sure if this "javascript:" is working at all but you said it did in other places; is it working if you put it in your browser manually?).

Then set the calc element to show in list view, remove the custom link from your other element (and set it to list view=no).

If you want to call a php file your link must be e.g. your-relative-or-absolute-URL/images/yourphpfile.php
 
Hi

I think you might want to consider using the PHP list plugin. This would add an additional button to each of your list's rows. Clicking on this button will first trigger some JS and then optionally trigger some PHP.

First of all you should update from github as I had to fix a couple of things in the plugin to get it working for your scenario.

If you haven't done so install and publish the PHP list plugin, then edit your list and add the plugin.

You should then fill in the options as follows:

JS code:

Code:
// rows is an array of objects representing the selected table rows.
// You might need to add the _raw prefix to the full element name, depending on the field type (e.g. if its a dropdown).
var linkTypeId = parseInt(rows[0].fabrik_erd_records___id_linktype, 10);
var path = rows[0].fabrik_erd_records___path;

switch (linkTypeId) {
  case 2:
   LaunchApp (path);
    break;
  default:
    window.location.href = path;
    break;
}
 
  // Return false to stop the php code from running
  return false;
 
Thank you both. Will work on these and report back.
---
This is an update from 5 Feb as I do not seem to be able to write a new post due to an issue with your subscription system.

I have tried implementing Rob's suggested approach, updating from github, installing/publishing PHP List Plugin, and added this plugin to the latest iteration of our list (changes due to client changes to underlying data and wanting cascading dropdowns on some of the filtering data necessitating separate lists for this data).

In terms of the issue raised in this forum message I am at this point:

1. There is no apparent action on clicking the PHP button - no change of page, no error msg, though the button appears to click.

2. A google share link to an image of the PHP List Plugin configuration page is here - there are minor changes from your suggested code to suit the different list and element names. (The warning next to the Switch line suggests an If statement should have been used.) I also tested that the text string in the path variable did actually open the appropriate pdf when placed in the browser URL field - this was for a linktype_id =2 record (the most common).

3. A google share link to an image of the IE browser Development Tools Debugger screen is here - I have no experience here but it suggests to me that there is some barrier preventing the opening of the new window.

4. The html for the relevant part of the page is
HTML:
181 <th class="heading fabrik_ordercell fabrik_actions" >
182            <div class="btn-group"><a href="#" data-list="2_com_fabrik_2" class="btn php-0 listplugin" title="PHP"><i class="icon-play " ></i> <span class="hidden">PHP</span></a></div>    </th>
- which implies to me that the link data is not getting through to the page. A google share link to an image of the DOM Explorer screen is here.

5. Doing some searching on this issue I tried without success
A. using window.location.replace(path); in lieu of window.location.href = path;
B. adding return = "false"; immediately after the window.location.href = path;

6. For perspective, a google share link to an image of the front end list display is here.


Thanks in advance - David
 
Bump - please sir it has been six days since my post update - which was due to my not being able to post when the subscription system fouled my expiry date... :(
 
Apologies. For some reason, editing a post doesn't seem to "bump" it, and I tend to work on the "last 3 days" search for answering posts.

The only way we can help further with this would be to access you site. It's just pretty much impossible to debug a customization like this just from descriptions and images.

-- hugh
 
OK, will see if I can get you a remote connection credential. Do I send this sort of info via a "conversation" via clicking on your profile photo and then "Start a conversation"? If I do so in this case, should the conversation be with troester, rob or yourself or a combination of the above?
 
I can send you access credentials to the two servers via TeamViewer. To whom should I send them and what is the best way to send these securely?
 
Put the site details in your My Sites list (link on your "postbit", the stuff to the left of any of your posts). Then the three of us can see them (we are the only three people with access to that information).

I can't promise we can do this as part of a Standard sub, unless it's a one liner. This is the kind of customization which Pro is intended to cover. But I'll take a look.

-- hugh
 
Hi Hugh,

The development site and the live site are not accessible on the internet (by client design), but only through a remote desktop connection. The client IT bod set up a Team Viewer access to the two servers as per my Conversation message to you and Rob/Troester last Friday (8.41am Sydney time). I think that is the only way for you to access the development site, and I don't think I can provide the required information for the MySites forms. Did you receive that conversation message? Do you need me to repost it?

I am happy to upgrade to the Professional Support level for a month if that solves the issue.

David
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top