Map Status Text change to Image

Hadeszeus

New member
Messages
651
Points
0
Location
Philippines
Guys, I'm currently working on my CP using FLUX. I'm having problem changing the output text OFFLINE/ONLINE in MAP SERVER STATUS.

Here's the original code:

<table><?php foreach ($serverStatus as $privServerName => $gameServers): ?> <?php foreach ($gameServers as $serverName => $gameServer): ?> <tr> <th class="server"><?php echo htmlspecialchars($serverName) ?></th> <td class="status-login"><?php echo $this->serverUpDown($gameServer['loginServerUp'])?></td> <td class="status-char"><?php echo $this->serverUpDown($gameServer['charServerUp']) ?></td> <td class="status-map"><?php echo $this->serverUpDown($gameServer['mapServerUp']) ?></td> <td class="status-online"><?php echo $gameServer['playersOnline'] ?></td> </tr> <?php endforeach ?></table>

Here's my if statement to change the text to image (I used text to echo the return value for testing purposes only.) 

The problem is even if the server is Offline the status still display green text instead of red

<td class="status-login"><?php if($this->serverUpDown($gameServer['loginServerUp']) == "Offline") {echo "red";} else {echo "green";}?></td>

Any thoughts? Thanks!

 
Last edited by a moderator:
to change text to image, I think it would change the "red" to "<img src="off image url" title="off"/>" and "green" to "<img src="on image url" title="on"/>"

 
Please share how you solved your problem to mark it Solved thanks
default_wink.png


 
The reason why the IF statement didn't work, because serverUpDown fuction is using bool to pass the output OFFLINE/ONLINE.

Here's the orginal code: 

   /lib/Flux/Template.php

/** * Returns "up" or "down" in a span HTML element with either the class * .up or .down, based on the value of $bool. True returns up, false * returns down. * * @param bool $bool True/false value * @return string Up/down */ public function serverUpDown($bool) { $class = $bool ? 'up' : 'down'; return sprintf('<span class="%s">%s</span>', $class, $bool ? 'Online' : 'Offline'); }

So to make it work. 

Just create a new function for serverUpDown. 

Something like this

Code:
 // filename of an image that represent that the Server is Online  define('ONLINE_IMAGE', 'Online.png');  // filename of an image that represent that the Server is Offline  define('OFFLINE_IMAGE', 'Offline.png');  function serverUpDownImage($bool)  {      $imgDown = THEME_PATH.'images/'.OFFLINE_IMAGE;      $imgUp = THEME_PATH.'images/'.ONLINE_IMAGE;      $class = $bool?'up':'down';      return sprintf('<span class="%s">%s</span>', $class, $bool?'<img src="'.$imgUp.          '"/>':'<img src="'.$imgDown.'"/>');  }
 
Last edited by a moderator:
Back
Top