...

View Full Version : if then make green, else, make red problems.



thesavior
01-01-2006, 03:54 AM
On this code:


<?php
$configname = "../includes/config.inc.php";
$configmod = substr(sprintf('%o', fileperms($configname)), -4);
echo "<table width=\"100%\" border=\"2\" cellspacing=\"0\" cellpadding=\"3\">";
echo "<tr>";
echo "<th scope=\"col\">File Name</th>";
echo "<th scope=\"col\">Needed Chmod</th>";
echo "<th scope=\"col\">Current Chmod</th>";
echo "</tr><tr>";
echo "<td>". $configname ."</td>";
echo "<td>0777</td>";
echo "<td>$configmod</td>";
echo "</tr><table>";
?>

i want it to change to be, check the file for permissions, it it doesn't have the right permissions, make the row with its information red, if it does, then make it green. Im not sure how to go about this, any ideas?

This is the page with the current code on it: http://www.lonelylizard.com/~eli/test/tms/install/install1.php

mlse
01-01-2006, 10:55 AM
Hi,

First, you need some CSS for your red and green states. Something like:



TR.badperms TD {
color:#CC0000;
}

TR.goodperms TD {
color:#00CC00;
}


It depends what you regard as "correct permissions", so:




$configname = "../includes/config.inc.php";
clearstatcache();
$configmod = substr(sprintf('%o', fileperms($configname)), -4);
$goodperms = //Whatever - NOTE: you need to put the permission you require in here or this code will be in error.
$trcss = (($configmod != $goodperms) ? "badperms" : "goodperms");

echo "<table width=\"100%\" border=\"2\" cellspacing=\"0\" cellpadding=\"3\">";
echo "<tr>";
echo "<th scope=\"col\">File Name</th>";
echo "<th scope=\"col\">Needed Chmod</th>";
echo "<th scope=\"col\">Current Chmod</th>";
echo "</tr><tr class=".$trcss.">";
echo "<td>". $configname ."</td>";
echo "<td>0777</td>";
echo "<td>$configmod</td>";
echo "</tr><table>";


That should work. If you want to perform other checks on permissions (i.e. checking for more than just one value), this link should give you some ideas: http://uk.php.net/manual/en/function.fileperms.php

Hope that helps!

Mike.

thesavior
01-01-2006, 07:22 PM
thanks for the speedy reply, but i have one more question.

Can you explain what this line does?


$trcss = (($configmod != $goodperms) ? "badperms" : "goodperms");

degsy
01-01-2006, 07:52 PM
That is using the ternary operator.

It is a short way of using an if/else statement.



if($configmod != $goodperms){ //if not equal to
$trcss = "badperms";
}
else{
$trcss = "goodperms");
}

thesavior
01-01-2006, 08:17 PM
ok, thanks.

mlse
01-04-2006, 10:40 AM
Yes indeed. Strictly speaking it's not good programming practice, but I use it because I'm a rebel :cool: Also I'm lazy :rolleyes:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum