Setting Colour on font depending on their status!

Discussions related to customizing hooks. Hooks are documented at http://bigprof.com/appgini/help/advanced-topics/hooks/
espo
Veteran Member
Posts: 98
Joined: 2013-03-01 12:55

Setting Colour on font depending on their status!

Post by espo » 2021-12-24 13:11

Hi everyone,

i am trying to enter this code to get a different color for each state.
It doesn't work, it clears my table data leaving the page blank.
Using AppGini 5.94


}function slot_init(&$options, $memberInfo, &$args){
// modify the status field of the table view query to display 'no' invoices in bold red
$oldArray=$options->QueryFieldsTV;
$options->QueryFieldsTV='';
foreach($oldArray as $field => $caption){
if($field=='`slot`.`slot_mag`'){
$options->QueryFieldsTV['IF(`slot`.`slot_mag`=\'betting da lavorare\', \'<b style="color: green;">BETTING DA LAVORARE</b>\', IF(`slot`.`slot_mag`=\'ATS da lavorare\', \'<b style="color: red;">ATS da lavorare</b>\', IF(`slot`.`slot_mag`=\'saci vlt da lavorare\', \'<b style="color: blue;">SACI VLT da lavorare</b>\', `slot`.`slot_mag`)))']=$caption;
}else{
$options->QueryFieldsTV[$field]=$caption;
}
}
return TRUE;


Could anyone help me to solve the problem?

Many thanks in advance.

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: Setting Colour on font depending on their status!

Post by pbottcher » 2021-12-24 14:57

Hi,

not sure what happens, but maybe your first } in front of the function is not correct.

Also you may try:

Code: Select all

function slot_init(&$options, $memberInfo, &$args){
// modify the status field of the table view query to display 'no' invoices in bold red
	$ar=array_flip($options->QueryFieldsTV);
	$ar['slot_mag']="CASE 
			WHEN `slot`.`slot_mag`='betting da lavorare' then '<b style=\"color: green;\">BETTING DA LAVORARE</b>' 
			WHEN `slot`.`slot_mag`='ATS da lavorare' then '<b style=\"color: red;\">ATS da lavorare</b>'
			WHEN `slot`.`slot_mag`='saci vlt da lavorare' then '<b style=\"color: blue;\">SACI VLT da lavorare</b>'
			ELSE `slot`.`slot_mag`
			END";
	$options->QueryFieldsTV=array_flip($ar);
}
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

espo
Veteran Member
Posts: 98
Joined: 2013-03-01 12:55

Re: Setting Colour on font depending on their status!

Post by espo » 2021-12-27 07:51

Thank you so much for your answer.
I tried to insert your code, but if I insert the return true at the end it gives me this error:
Parse error: syntax error, unexpected '}', expecting end of file in /membri/logisticmag/slot/hooks/SLOT.php on line 16

I have to remove RETURN TRUE} ?
Should I enter { in another area of ​​the code ?

Thank you so much for your help.

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: Setting Colour on font depending on their status!

Post by pbottcher » 2021-12-27 09:11

Hi,

well in this function I do not see any wrong bracket. Can you post your SLOT.php.
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

espo
Veteran Member
Posts: 98
Joined: 2013-03-01 12:55

Re: Setting Colour on font depending on their status!

Post by espo » 2021-12-27 10:13

This is mine.
Thanks so much.

Code: Select all

<?php
	// For help on using hooks, please refer to https://bigprof.com/appgini/help/working-with-generated-web-database-application/hooks

	function slot_init(&$options, $memberInfo, &$args){
// modify the status field of the table view query to display 'no' invoices in bold red
	$ar=array_flip($options->QueryFieldsTV);
	$ar['slot_mag']="CASE 
			WHEN `slot`.`slot_mag`='betting da lavorare' then '<b style=\"color: green;\">BETTING da lavorare</b>' 
			WHEN `slot`.`slot_mag`='ATS da lavorare' then '<b style=\"color: red;\">ATS da lavorare</b>'/						
			WHEN `slot`.`slot_mag`='saci vlt da lavorare' then '<b style=\"color: blue;\">SACI VLT da lavorare</b>'
			ELSE `slot`.`slot_mag`
			END";
	$options->QueryFieldsTV=array_flip($ar);
}

//	return TRUE;
//}

	function SLOT_header($contentType, $memberInfo, &$args) {
		$header='';

		switch($contentType) {
			case 'tableview':
				$header='';
				break;

			case 'detailview':
				$header='';
				break;

			case 'tableview+detailview':
				$header='';
				break;

			case 'print-tableview':
				$header='';
				break;

			case 'print-detailview':
				$header='';
				break;

			case 'filters':
				$header='';
				break;
		}

		return $header;
	}

	function SLOT_footer($contentType, $memberInfo, &$args) {
		$footer='';

		switch($contentType) {
			case 'tableview':
				$footer='';
				break;

			case 'detailview':
				$footer='';
				break;

			case 'tableview+detailview':
				$footer='';
				break;

			case 'print-tableview':
				$footer='';
				break;

			case 'print-detailview':
				$footer='';
				break;

			case 'filters':
				$footer='';
				break;
		}

		return $footer;
	}

	function SLOT_before_insert(&$data, $memberInfo, &$args) {

		return TRUE;
	}

	function SLOT_after_insert($data, $memberInfo, &$args) {

		return TRUE;
	}

	function SLOT_before_update(&$data, $memberInfo, &$args) {

		return TRUE;
	}

	function SLOT_after_update($data, $memberInfo, &$args) {

		return TRUE;
	}

	function SLOT_before_delete($selectedID, &$skipChecks, $memberInfo, &$args) {

		return TRUE;
	}

	function SLOT_after_delete($selectedID, $memberInfo, &$args) {

	}

	function SLOT_dv($selectedID, $memberInfo, &$html, &$args) {

	}

	function SLOT_csv($query, $memberInfo, &$args) {

		return $query;
	}
	function SLOT_batch_actions(&$args) {

		return [];
	}
	

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: Setting Colour on font depending on their status!

Post by pbottcher » 2021-12-27 10:47

You just need to remove the } before the return.

Code: Select all

	function slot_init(&$options, $memberInfo, &$args){
// modify the status field of the table view query to display 'no' invoices in bold red
	$ar=array_flip($options->QueryFieldsTV);
	$ar['slot_mag']="CASE 
			WHEN `slot`.`slot_mag`='betting da lavorare' then '<b style=\"color: green;\">BETTING da lavorare</b>' 
			WHEN `slot`.`slot_mag`='ATS da lavorare' then '<b style=\"color: red;\">ATS da lavorare</b>'/						
			WHEN `slot`.`slot_mag`='saci vlt da lavorare' then '<b style=\"color: blue;\">SACI VLT da lavorare</b>'
			ELSE `slot`.`slot_mag`
			END";
	$options->QueryFieldsTV=array_flip($ar);

	return TRUE;
}
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

espo
Veteran Member
Posts: 98
Joined: 2013-03-01 12:55

Re: Setting Colour on font depending on their status!

Post by espo » 2021-12-27 11:36

Ok, now it shows the items on the screen without errors, but they don't have the color.

Thanks for your patience.

espo
Veteran Member
Posts: 98
Joined: 2013-03-01 12:55

Re: Setting Colour on font depending on their status!

Post by espo » 2021-12-27 13:02

espo wrote:
2021-12-27 11:36
Ok, now it shows the items on the screen without errors, but they don't have the color.

Thanks for your patience.
Sorry but update.
I entered the code you sent me and this is the error:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHEN `slot`.`slot_mag`='saci vlt da lavorare' then '<b style="color: blue;">SACI' at line 4

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: Setting Colour on font depending on their status!

Post by pbottcher » 2021-12-27 14:06

Hi,

sorry there is a trailing /, please try

Code: Select all

	function slot_init(&$options, $memberInfo, &$args){
// modify the status field of the table view query to display 'no' invoices in bold red
	$ar=array_flip($options->QueryFieldsTV);
	$ar['slot_mag']="CASE 
			WHEN `slot`.`slot_mag`='betting da lavorare' then '<b style=\"color: green;\">BETTING da lavorare</b>' 
			WHEN `slot`.`slot_mag`='ATS da lavorare' then '<b style=\"color: red;\">ATS da lavorare</b>'					
			WHEN `slot`.`slot_mag`='saci vlt da lavorare' then '<b style=\"color: blue;\">SACI VLT da lavorare</b>'
			ELSE `slot`.`slot_mag`
			END";
	$options->QueryFieldsTV=array_flip($ar);

	return TRUE;
}
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

espo
Veteran Member
Posts: 98
Joined: 2013-03-01 12:55

Re: Setting Colour on font depending on their status!

Post by espo » 2021-12-30 07:20

Hi and thanks for your help.
I entered the code by removing the "/".

Now I have this error:

Code: Select all

Unknown column 'slot.slot_mag' in 'field list'

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: Setting Colour on font depending on their status!

Post by pbottcher » 2021-12-30 09:46

Hi,

well then you need to check what fields are with your table, as I do not know your setup.
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1807
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: Setting Colour on font depending on their status!

Post by jsetzer » 2021-12-30 10:36

Many times debugging helps us, finding our own errors: You should dump out contents of fields.

I recommend...

Code: Select all

var_dump($options->QueryFieldsTV);
exit;
...before applying any changes on the $options array and check the array keys.
$ar['slot_mag']="CASE WHEN ... END";
I doubt the array key equals slot_mag. Without knowing your model, I guess the key equals `slot`.`slot_mag`, instead.

If I remember right, the array should contain the desired output value as key and the fieldname as value, not vice versa. For example...

Code: Select all

$options->QueryFieldsTV["'Test'"] = 'COLUMN_NAME';
This would output ...
Test
... in every cell of COLUMN_NAME column.

You may have switched key and value.

espo
Veteran Member
Posts: 98
Joined: 2013-03-01 12:55

Re: Setting Colour on font depending on their status!

Post by espo » 2022-01-03 11:48

Happy New Year everyone and thanks for the replies.
Unfortunately I'm not very experienced and I try to explain my problem better.
I have always used the code I am attaching to change the state color in a field.
This code has always worked.
After updating APPGINI to version 5.97 the code no longer works and leaves me blank and non-editable fields.
The image is in the inserted link.
How can I solve this problem?

Code: Select all

function TEST_init(&$options, $memberInfo, &$args) {
   // modify the status field of the table view query to display 'no' invoices in bold red
     $oldArray=$options->QueryFieldsTV;
     $options->QueryFieldsTV='';
      foreach($oldArray as $field => $caption){
       if($field=='`TEST`.`stato`'){
           $options->QueryFieldsTV['IF(`TEST`.`stato`=\'BIANCO\', \'<b style="color: red;">BIANCO</b>\', 
									IF(`TEST`.`stato`=\'ROSSO\', \'<b style="color: green;">ROSSO</b>\', 
									IF(`TEST`.`stato`=\'VERDE\', \'<b style="color: #FF8243;">VERDE</b>\', 
									`TEST`.`stato`)))']=$caption;
        }else{
           $options->QueryFieldsTV[$field]=$caption;
        }
      }  
		return TRUE;
	}
https://ibb.co/6FdVLRp

My DB only has three fields

ID
FIRST NAME
STATE

Thank you very much!

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1807
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: Setting Colour on font depending on their status!

Post by jsetzer » 2022-01-03 11:58

Please post the result of var_dump(). This should help you (and us, who try to help you) finding the mistake.

See my recommendation above.
Last edited by jsetzer on 2022-01-03 12:02, edited 1 time in total.
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1807
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: Setting Colour on font depending on their status!

Post by jsetzer » 2022-01-03 12:01

Additionally, there has been a change in AG recently for avoiding XSS attacks by injecting custom CSS. You should inspect the elements in you browser dev-tools and check if AppGini has removed style attributes as a security feature.
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

espo
Veteran Member
Posts: 98
Joined: 2013-03-01 12:55

Re: Setting Colour on font depending on their status!

Post by espo » 2022-01-04 09:47

Sorry for my little knowledge ... but could you tell me where to insert

Code: Select all

var_dump ($ options-> QueryFieldsTV);
exit;
Thanks so much for your help

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1807
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: Setting Colour on font depending on their status!

Post by jsetzer » 2022-01-04 10:05

You were talking about _init-function in TEST.php. So, exaxtky that is the place.

Assuming your table name equals TEST:

File: hooks/TEST.php

Code: Select all

function TEST_init(&$options, $memberInfo, &$args) {
  var_dump($options->QueryFieldsTV);
  exit;
}
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1807
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: Setting Colour on font depending on their status!

Post by jsetzer » 2022-01-04 10:12

espo wrote:
2022-01-04 09:47

Code: Select all

var_dump ($ options-> QueryFieldsTV);
exit;
And please don't put any extra spaces.

In your code, extra spaces after $ and after -> which have to be removed.
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

espo
Veteran Member
Posts: 98
Joined: 2013-03-01 12:55

Re: Setting Colour on font depending on their status!

Post by espo » 2022-01-04 10:53

Thanks again for the help.

Code: Select all

function TEST_init(&$options, $memberInfo, &$args) {
   // modify the status field of the table view query to display 'no' invoices in bold red
    var_dump($options->QueryFieldsTV);
  exit;

     $oldArray=$options->QueryFieldsTV;
     $options->QueryFieldsTV='';
      foreach($oldArray as $field => $caption){
       if($field=='`TEST`.`stato`'){
          $options->QueryFieldsTV['IF(`TEST`.`stato`=\'BIANCO\', \'<b style="color: red;">BIANCO</b>\',
									IF(`TEST`.`stato`=\'ROSSO\', \'<b style="color: green;">ROSSO</b>\', 
									IF(`TEST`.`stato`=\'VERDE\', \'<b style="color: #FF8243;">VERDE</b>\', 
									`TEST`.`stato`)))']=$caption;
      }else{
           $options->QueryFieldsTV[$field]=$caption;
        }
      }  
		return TRUE;
	}
I insert the code and the result of the page ../view.php

array(3) { ["`TEST`.`id`"]=> string(2) "id" ["`TEST`.`NOME`"]=> string(4) "NOME" ["`TEST`.`STATO`"]=> string(5) "STATO" }

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1807
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: Setting Colour on font depending on their status!

Post by jsetzer » 2022-01-04 13:36

(1) As mentioned before, AppGini removes custom style attributes for avoiding XSS attacks. Even if you get your syntax right in PHP init-hook, the css-style will be removed.

(2) Also, as mentioned before, check the final HTML code in your browser's dev-tools. After customizing the TV column in init-hook and after AppGini has removed CSS styles for security reasons you will end up with sometihng like this:

Code: Select all

<span xss="removed">Test</span>
(3) Anyway, custom CSS-styling in TV seems to be important for a few users. I consider writing a blog post on this topic. Stay tuned.
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1807
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: Setting Colour on font depending on their status!

Post by jsetzer » 2022-01-04 14:51

If someone is interested in customizing TV columns, I have just published Part 1 of a series of tutorials in my Blog:

:arrow: https://appgini.bizzworxx.de/appgini/tv ... nge-value/

If you are interested, just have a look. There are screenshots and complete source codes inside. I am going to continue writing blog articles about customizing TV the next hours if I find enough time. And I will also adress the XSS-security problems and show solutions.
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: Setting Colour on font depending on their status!

Post by pbottcher » 2022-01-04 15:12

Hi,

you check

if($field=='`TEST`.`stato`'){

but in your datadump there is ["`TEST`.`STATO`"]=> string(5) "STATO"

So maybe the issue is related to the case-sensitivity.
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1807
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: Setting Colour on font depending on their status!

Post by jsetzer » 2022-01-04 15:35

+1 @pböttcher

That's exactly the reason why I recommend (and prefer by myself) dumping out the exact keys and values. I see it quite often that programmers assume some prerequisites but do not check them.
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

espo
Veteran Member
Posts: 98
Joined: 2013-03-01 12:55

Re: Setting Colour on font depending on their status!

Post by espo » 2022-01-05 10:02

Hello,

I also checked by entering capital words, but it doesn't work anyway.
I believe it is an XSS security issue at this point.
Stay tuned for updates ...

Thanks a lot to everyone.

User avatar
jsetzer
AppGini Super Hero
AppGini Super Hero
Posts: 1807
Joined: 2018-07-06 06:03
Location: Kiel, Germany
Contact:

Re: Setting Colour on font depending on their status!

Post by jsetzer » 2022-01-06 10:25

To see if your style has been removed or not, you can simply inspect the cell value in your browser's development tools:

chrome_T36pq9yG0I.png
chrome_T36pq9yG0I.png (49.17 KiB) Viewed 6181 times

If you can see xss="removed" there, well, your style has been removed for security reasons.

See also: Part 3 of my Blog series about customizing Table View cell values here:
https://appgini.bizzworxx.de/appgini/tv ... css-style/
Kind regards,
<js />

My AppGini Blog:
https://appgini.bizzworxx.de/blog

You can help us helping you:
Please always put code fragments inside [code]...[/code] blocks for better readability

AppGini 24.10 Revision 1579 + all AppGini Helper tools

Post Reply