On 13 May, 23:43, cwdjrxyz <spamtr...@cwdjr.infowrote:
On May 13, 2:24 pm, JRough <jlro...@yahoo.comwrote:
I got lost on formatting the nested if/else's on the bottom of the
file right up the last else/if there seems to be a stray bracket. I'm
trying to line up the brackets so I can read it. Is it okay to split
a long line setting a variable on two lines at the equals sign? That
is so you can read it in google groups.
<?
//Send payement advices
$TPL_auction_id = $auction_id;
$user_id=$userrec["id"];
if(!$sessionVars["SELL_action"]) {
include "header.php";}
if($FEE>0) {
if($SETTINGS["invoicing"] == 'y') {
if(!$sessionVars["SELL_action"]=="edit") {
include phpa_include("template_menu_php.html");
include phpa_include("template_sell_result_php.html");
} else {
$auction_url =
$SETTINGS["siteurl"] . "item.php?mode=1&id=".$auction_id;
if($sessionVars["SELL_action"]=="edit") {
unset($_SESSION["sessionVars"]);
unset($_SESSION["RELISTEDAUCTION"]);
if(isset($_SESSION['backtolist']))
header("Location: ".$_SESSION['backtolist']."?PAGE=
".$_SESSION['backtolist_page']);
else
header("Location: yourauctions.php?PAGE=
".$_SESSION['backtolist_page']);
exit;
}
if($sessionVars["SELL_action"]=="reopen") {
unset($_SESSION["sessionVars"]);
unset($_SESSION["RELISTEDAUCTION"]);
header("Location: yourauctions_c.php?PAGE=
".$_SESSION['backtolist_page']);
exit;
}}
} elseif($SETTINGS["feetype"] == "prepay") {
if(!$sessionVars["SELL_action"]) {
//include "header.php";}
include "lib/auctionsetup_payment.php";} else {
if($sessionVars["SELL_action"]) {
include "header.php";
include phpa_include("template_menu_php.html");}
?>
The first thing I think of when something with this much logic comes
up is a switch statement. Of course sometimes it is not suited at all
or only for some of the logic. However, when you can use switch, the
code is much more orderly and easy to modify. You may have already
considered switch and found problems in using it, so excuse me for
bringing up the subject if that is the case. I do not have time just
now to consider the details of your code and test them. The php switch
is nearly the same as a Javascript switch in the formal code structure.
A PHP switch statement only really works on the value(s) of a single
expression - the code above relies on multiple experssions. I'd agree
that the code above is rather messy and difficult to maintain.
Certainly end brackets of nested blocks should be commented to
reference the start point. It already looks as if it needs fixed:
if(!$sessionVars["SELL_action"]=="edit") {
....
} else {
...
if($sessionVars["SELL_action"]=="edit") {
There's other ways to make the code clearer though:
You could break it down into seperate functions.
The indentiy of include files is alerady encapsulated in a function
(presumably for path rewriting) you could push the logic for determing
which include files to use further down the call tree.
You could bundle the different scenarios under single level if ...
elseif ...else statements
e.g.
//Send payement advices
$TPL_auction_id = $auction_id;
$user_id=$userrec["id"];
if ((!$sessionVars["SELL_action"]) || ($FEE<=0) {
include "header.php";
}
if (($FEE>0) && (($SETTINGS["invoicing"] == 'y') && (!
$sessionVars["SELL_action"]=="edit")) {
include phpa_include("template_menu_php.html");
include phpa_include("template_sell_result_php.html");
}
if (($FEE>0) && (($SETTINGS["invoicing"] == 'y') && (!
$sessionVars["SELL_action"]!="edit")) {
$auction_url = $SETTINGS["siteurl"] . "item.php?mode=1&id=".
$auction_id;
}
....
Another problem with the code is that it seems to rely on inline
(main) code within include functions - which can introduce lots of
unexpected side-effects and create vulnerabilities. As a general rule
I don't have any inline code other than defines in include files. If
you use OO then you can use the autlolader to selectively load
libraries.
Another thing I note is that you use include throughout where require
might_once might be more appropriate.
Sorry OP, but the length of your lines is the least of your worries.
You should start by reading up on Karnaugh maps and boolean algebra.
C.