Setting Colour on font depending on their status!

The recommended method of customizing your AppGini-generated application is through hooks. But sometimes you might need to add functionality not accessible through hooks. You can discuss this here.
Post Reply
reg216uk
Posts: 22
Joined: 2013-09-26 18:45

Setting Colour on font depending on their status!

Post by reg216uk » 2013-09-27 21:18

Hello im not very skilled with php if im honest and was just wondering if anyone would be able to help.

I have designed a database for my work which basically controls logistic jobs....I wont go into too much detail.... what I require is that when I select the Status of each entry ("row") it changes the colour of the rows background or font colour....

So if the job status is listed as "Pending" the font or background of the row will be Red, if the status is set to "Booked" the font or background will be blue and finally if the status is set to "Loaded" itll be listed as green.

The jobs status is selected by a Drop Down Menu obviously....

Please can someone help....Im extremely new too php so any help would be greatful....I am also willing to pay a small amount of money for anyone to help me develop this system further.

AhmedBR
AppGini Super Hero
AppGini Super Hero
Posts: 327
Joined: 2013-09-19 10:23

Re: Setting Colour on font depending on their status!

Post by AhmedBR » 2013-09-27 23:04

If I understood what you want, it is almost exactly like this topic:
http://forums.appgini.com/phpbb/viewtopic.php?f=8&t=577

Have a nice day
AppGini 22.14 - xampp 3.3.0 - PHP 7.4.30 - Summary reports - Calendar - Mass update - Messages - AppGiniHelper

reg216uk
Posts: 22
Joined: 2013-09-26 18:45

Re: Setting Colour on font depending on their status!

Post by reg216uk » 2013-09-28 07:16

Ahhh yes I saw this....however I dont know where to put it...perhaps you could explain? Like I said im very new to php....

reg216uk
Posts: 22
Joined: 2013-09-26 18:45

Re: Setting Colour on font depending on their status!

Post by reg216uk » 2013-09-28 07:50

ok so i have kinda worked out that there is a hook file and that I need to edit the file named VIDA.php which is the customer ill be working with....I have edited the code tow hat I think is correct but I cannot seem to make it work....

The table is called VIDA and the field i want to edit is the "Status" would the fact im using a drop down menu instead of the radio button cause a problem?

Any help would be greatly appreciated thank you.

Code: Select all

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

	function VIDA_init(&$options, $memberInfo, &$args){
	// modify the status field of the table view query to display 'Due' invoices in bold red
		$oldArray=$options->QueryFieldsTV;
		$options->QueryFieldsTV='';
		foreach($oldArray as $field => $caption){
			if($field=='`VIDA`.`status`'){
				$options->QueryFieldsTV['IF(`VIDA`.`Status`=\'Pending\', \'<b style="color: red;">Pending</b>\', IF(`VIDA`.`Status`=\'Loaded\', \'<b style="color: green;">Loaded</b>\', `Vida`.`Status`))']=$caption;
			}else{
				$options->QueryFieldsTV[$field]=$caption;
			}
		}
		return TRUE;
	}

	function VIDA_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 VIDA_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 VIDA_before_insert(&$data, $memberInfo, &$args){

		return TRUE;
	}

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

		return TRUE;
	}

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

		return TRUE;
	}

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

		return TRUE;
	}

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

		return TRUE;
	}

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

	}

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

	}

	function VIDA_csv($query, $memberInfo, $args){

		return $query;
	}

reg216uk
Posts: 22
Joined: 2013-09-26 18:45

Re: Setting Colour on font depending on their status!

Post by reg216uk » 2013-09-28 08:07

ok so I managed to get it working sorry to be a pain haha :)

What I would like now is to add another section to the code that if status is "Booked" it changes the colour of the text to blue...everytime I try adding it i get errors...

Code: Select all

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

	function VIDA_init(&$options, $memberInfo, &$args){
	// modify the status field of the table view query to display 'Due' invoices in bold red
		$oldArray=$options->QueryFieldsTV;
		$options->QueryFieldsTV='';
		foreach($oldArray as $field => $caption){
			if($field=='`VIDA`.`Status`'){
				$options->QueryFieldsTV['IF(`VIDA`.`Status`=\'Pending\', \'<b style="color: red;">Pending</b>\', IF(`VIDA`.`Status`=\'Booked\', \'<b style="color: blue;">Booked</b>\', IF(`VIDA`.`Status`=\'Loaded\', \'<b style="color: green;">Loaded</b>\', `VIDA`.`Status`))']=$caption;
			}else{
				$options->QueryFieldsTV[$field]=$caption;
			}
		}
		return TRUE;
	}
This is the code im trying but it keeps giving me errors?

This is my last question....how do i get it to work....thank you :S

djb2002
Posts: 24
Joined: 2013-09-14 09:49

Re: Setting Colour on font depending on their status!

Post by djb2002 » 2013-09-28 16:13

I'm trying to do a similar thing too and not managing :(

Anyone got any ideas ?

reg216uk
Posts: 22
Joined: 2013-09-26 18:45

Re: Setting Colour on font depending on their status!

Post by reg216uk » 2013-09-29 08:31

djb2002 wrote:I'm trying to do a similar thing too and not managing :(

Anyone got any ideas ?

Hello djb2002....inside your hooks folder there will be your tables php file....my table is called VIDA so the file is called VIDA.php

Inside here is where the code has to go....

The following code has been tried and tested to work ... im just having problems trying to add another bit to the code so when i put the status to Booked it goes Blue...

Code: Select all

function VIDA_init(&$options, $memberInfo, &$args){
	// modify the status field of the table view query to display 'Due' invoices in bold red
		$oldArray=$options->QueryFieldsTV;
		$options->QueryFieldsTV='';
		foreach($oldArray as $field => $caption){
			if($field=='`VIDA`.`Status`'){
				$options->QueryFieldsTV['IF(`VIDA`.`Status`=\'Pending\', \'<b style="color: red;">Pending</b>\', IF(`VIDA`.`Status`=\'Loaded\', \'<b style="color: green;">Loaded</b>\', `VIDA`.`Status`))']=$caption;
			}else{
				$options->QueryFieldsTV[$field]=$caption;
			}
		}
		return TRUE;
Just ensure you change the Table name and the field name to match yours etc.

reg216uk
Posts: 22
Joined: 2013-09-26 18:45

Re: Setting Colour on font depending on their status!

Post by reg216uk » 2013-09-29 16:36

Code: Select all

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

   function VIDA_init(&$options, $memberInfo, &$args){
   // modify the status field of the table view query to display 'Due' invoices in bold red
      $oldArray=$options->QueryFieldsTV;
      $options->QueryFieldsTV='';
      foreach($oldArray as $field => $caption){
         if($field=='`VIDA`.`Status`'){
            $options->QueryFieldsTV['IF(`VIDA`.`Status`=\'Pending\', \'<b style="color: red;">Pending</b>\', IF(`VIDA`.`Status`=\'Booked\', \'<b style="color: blue;">Booked</b>\', IF(`VIDA`.`Status`=\'Loaded\', \'<b style="color: green;">Loaded</b>\', `VIDA`.`Status`))']=$caption;
         }else{
            $options->QueryFieldsTV[$field]=$caption;
         }
      }
      return TRUE;
   }
anyone know how I can added to the following code so that when field is = to Booked it shows Booked in blue font ....and bold....

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

Re: Setting Colour on font depending on their status!

Post by espo » 2013-10-09 12:19

Hello,

I tried to enter this code with the changes to my page.
If I insert only two values ​​(eg YES and NO - red and green) works.
But if I try to add an extra field with a more color (blue) I have this error:

Errore: 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 'as `stato`, `db`.`id` as 'db.id' from `db` limit 0,2000' at line 1

Someone can help me to solve?

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

Re: Setting Colour on font depending on their status!

Post by espo » 2013-10-09 12:29

Hello,

I solved it.
It was necessary to add one) in more than reported in the sample code.

... Loaded </ b> \ ', `` VIDA. `Status`)))'] = $ caption;

reg216uk
Posts: 22
Joined: 2013-09-26 18:45

Re: Setting Colour on font depending on their status!

Post by reg216uk » 2013-10-09 13:30

Could you include the full section of code for me?

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

Re: Setting Colour on font depending on their status!

Post by espo » 2013-10-10 09:17

This is :-)

function db_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=='`db`.`stato`'){
$options->QueryFieldsTV['IF(`db`.`stato`=\'si\', \'<b style="color: green;">SI</b>\', IF(`db`.`stato`=\'no\', \'<b style="color: red;">NO</b>\', IF(`db`.`stato`=\'forse\', \'<b style="color: blue;">FORSE</b>\', `db`.`stato`)))']=$caption;
}else{
$options->QueryFieldsTV[$field]=$caption;
}
}
return TRUE;
}

reg216uk
Posts: 22
Joined: 2013-09-26 18:45

Re: Setting Colour on font depending on their status!

Post by reg216uk » 2013-10-11 13:13

Thank you i have it working :D

Post Reply