Links

Table Views can display information from the database, but can also display other information like links to external pages, and these links can be built using values from the data base as well.

For this feature, no option type is required,

In the table View page add a column for your link. For example an external PDF, in this case 200 is a with of 200px

 

array_push($td_titles, "200-PDF");

 

Then we need to create an array with the following values, some of them are optional.
"type" is required, this tells that we are going to add a link, when the link is saved in the database we use the value
"col" to specify the database column name where the link is saved
"text" and "title" are optional and both use a database column name to fetch a value from.

FETCH URLS FROM THE DATABASE

$tdvalue = array(
'type'=>'link',
'plainText'=> true, //optional, default: false, determines if the innerhtml of the link and the title attribute is fixed or comes from the database, if false text and title must be database columns
'text'=>'PDF_NAME',  //optional (default: OPEN LINK), leave emtpy if no text is required (required when plainText is false and must be a database column)
'title'=>'PDF_NAME',  //optional (default: is text if any), leave emtpy if no title is required (required when plainText is false and must be a database column)
'col'=>'URL', //the column of the database where the URL comes from (see 'format' bellow for more options)
'class'=>'pdfLink',   //optional, class name selector
'toURL'=> true, //true by default, this will clean and encode any characters that are not compatible with URLs
'attributes'=>'datat-var="value"',  //optional, can be any attribute(s) with value(s)
'target'=> '_blank', //optional, _blank by default
'nl2br'=> false, //optional, false by default
'icon'=>'<i class="far fa-external-link"></i>', //optional, default: <i class="far fa-external-link"></i>
'privilege'=> 4 //optional, 4 will show the field only to High and Admin privileges, default is 1
);

array_push($td_fields,$tdvalue);

 

 

USE A SPECIFIC FORMAT WITH WILDCARDS AND ADD MULTIPLE URL VALUES.

If the link is not saved in the database and we need to create our own URL with values from the database, then we use "format" instead of "col", and we put between "%" the column names from the database that we need to use in the URL, in the following example we use %IID% and %CLID%

 

$reservation = array(
'type'=>'link',
'format'=>'/ajax/invoice_page.php?&IID=%IID%&CLID=%CLID%',
'plainText'=> false,
'text'=>'RESNUM',
'title'=>'OPEN RESERVATION',
'toURL'=>false,
'nl2br'=> false,
'target'=> '_blank',
'icon'=>'<i class="far fa-external-link"></i>',
'privilege'=> 1
);

array_push($td_fields,$tdvalue);


LINKS TO OTHER KAS SECTIONS USING getPath() AND WILDCARDS

 

$tdvalue = array(
'type'=>'link',
'format'=>getPath('BILLING','CLIENTS','EDIT CLIENT','FUSCKDEW','%CLID%'),
'class'=>'localLink',
'text'=>'CLIENT_NAME',
'icon'=>'<i class="far fa-external-link"></i>'
);

array_push($td_fields,$tdvalue);

 

 

ENCRYPT DATA IN URL

In certain occasions it is important to encrypt our data so the information in the URL is not revealed, like IDs or accounts information, In such cases we can determine which columns using our wildcards %COL% will be encrypted, these need to be specified inside an array using the option encrypt

 

$reservation = array(
'type'=>'link',
'format'=>'/ajax/invoice_page.php?&IID=%IID%&CLID=%CLID%',
'plainText'=> false,
'text'=>'INVD',
'title'=>'OPEN INVOICE',
'toURL'=>false,
'nl2br'=> false,
'target'=> '_blank',
'icon'=>'<i class="far fa-external-link"></i>',
'privilege'=> 1,
'encrypt'=> array('IID','CLID'...) //used when format values are encrypted
);

array_push($td_fields,$tdvalue);

 

You can be creative and encrypt multiple values at once, for instance you can concatenate serval values from you DB query, and encrypt them all together, if you will only encrypt one value 'encrypt' can be a srtring.

 

$reservation = array(
'type'=>'link',
'format'=>'/ajax/invoice_page.php?&token=%token%',
'plainText'=> false,
'text'=>'INVD',
'title'=>'OPEN INVOICE',
'toURL'=>false,
'nl2br'=> false,
'target'=> '_blank',
'icon'=>'<i class="far fa-external-link"></i>',
'privilege'=> 1,
'encrypt'=> 'token' //used when format values are encrypted
);

array_push($td_fields,$tdvalue);

$query = "SELECT INVD, ....., CONCAT(IID, CLID, RESID) AS token from $dbtable %%WHERE%%;

 

 

SHOW MULTIPLE LINKS IN ONE SINGLE COLUMN

This one might be rarely used, but if you need to generate multiple dynamic links in the same column, you need to generate directly from a MySQL a comma separated value that will be assigned to 'text', if 'text' contains 3 values, then 3 links will be shown, one per line, and then inside format, you can add multiple wildcards, but if any the wildcards contains a comma separated value with the same number of values as the one assigned to text, each link will then receive the unique value of the wildcard. as for those who only have one value will be shared with all the links.

In this example we only use one wildcard with multiple values and one text also with multiple values, where 3 social media links are shown.

$tdvalue = array(
'type'=>'link',
'format'=>'social_urls',
'text'=>'socialmedia',
'title'=>'',  //leave empty if you don't want a title
'attributes'=>'target="_blank"'
);

array_push($td_fields,$tdvalue);

$query = "SELECT 
INVD, ....., 
CONCAT(FB_PAGE,',',INSTA_PAGE,',',LINKEDIN_PAGE) AS socialmedia,
CONCAT(FB_URL,',',INSTA_URL,',',LINKEDIN_URL) as social_urls
from $dbtable %%WHERE%%;

 

Here we combine multiple value wildcards with a single value wildcards, and multiple text values. RID will always be the same but supplier_ids will always be different

 

$tdvalue = array(
'type'=>'link',
'format'=>'/ajax/suppliers.php?&RID=%RID%&SID=%supplier_ids%',
'toURL'=>'false',
'text'=>'suppliers'
);

array_push($td_fields,$tdvalue);

$query = "SELECT 
INVD, ....., 
(SELECT GROUP_CONCAT(DISTINCT SUPPLIERS.SID) from SUPPLIERS where SUPPLIERS.RID=$dbtable.RID) as supplier_ids
(SELECT GROUP_CONCAT(DISTINCT SUPPLIERS.NAME) from SUPPLIERS where SUPPLIERS.RID=$dbtable.RID) as suppliers​
from $dbtable %%WHERE%%;

 

 

SHORT FORMATS (DEPRECATED)

These formats have many limitations and are deprecated:

 

//BASIC
array_push($td_fields,"link:/ajax/reservation_preview.php?CLID=%CLID%&INV=%INVID%:Open Invoice");

 

This array is transformed into:

 

$suppliers = array(
   'type'=>'link',
   'plainText'=> true,
   'format'=>'/ajax/reservation_preview.php?CLID=%CLID%&INV=%INVID%',
   'text'=>'Open Invoice',
   'toURL'=>false,
   'title'=>'Open Invoicer'
);

 

 

//ADVANCED
array_push($td_fields,"link:/ajax/reservation_preview.php?CLID=%CLID%&INV=%%INVID%%:open Invoice:INVOICE_NO:true");

 

This array is transformed into:

 

$suppliers = array(
   'type'=>'link',
   'plainText'=> false,
   'format'=>'/ajax/reservation_preview.php?CLID=%CLID%&INV=%INVID%',
   'text'=>'INVOICE_NO',
   'toURL'=> true,
   'title'=>'Open Invoice'
);