Okay
I have a question on this subject that's been bothering me a bit. Please forgive me for the long example, but I'd like to know if there's a better way to write this inline as I'm working with a great graphics, HTML guy and I'd like my code to be as easy as possible for him to work with.
A lot of my code involves using loops and conditional statements to decide what and how much HTML to echo to the browser.
code:
<?php
include("$DOCUMENT_ROOT/includes/admin/headers/header_admin.inc.php");
?>
</HEAD>
<BODY bgcolor=#cc6600 background=/images/admin/adminbg.gif>
<table cellpadding=10 cellspacing=0 border=0 width=100% height=100%>
<tr>
<td bgcolor=#ff9900 align=center valign=middle><a href="javascript:window.close()"><img src="/images/admin/logoff.gif" width="101" height="20" border="0"></a>
</td>
<td bgcolor=#000066 align=right height=50><a name=top><img src="/images/admin/pcs.gif" width="132" height="50" border="0"></a></td>
</tr>
<tr>
<td bgcolor=#000099 width=150 valign=top>
<?php
if(!isset($doit))
{
//content area
$display .= "<td bgcolor=ffffff valign=top>\n";
$display .= "<h1>Team Photo Gallery Delete</h1>\n";
$display .= "<form action=\"$PHP_SELF\" method=\"POST\">\n";
//start thumbnail display table
$display .= "<table cellpadding=6 cellspacing=2 border=0>\n<tr>\n";
$display .= "<td align=\"left\"><p><b>Photo</b></p></td>\n<td align=\"left\"><p><b>Select</b></p></td>\n";
//get current directory of this file
$curdir = $file_name;
$parent_dir = "$DOCUMENT_ROOT/gallery/$curdir/"; //starting directory
$photo_array = array();
if($file = @opendir($parent_dir))
{
while(($entry = readdir($file)) !== false)
{
if($entry != '.' && $entry != '..' && !eregi("\.html$",$entry) && !eregi("\.php$",$entry) && !eregi("\.pcgi$",$entry) && !@is_dir($parent_dir.$entry))
{
array_push($photo_array, $entry);
}
}
}
natcasesort($photo_array);
foreach($photo_array as $photo)
{
if($i % $thumbs_per_row != 0)
{
if(is_file($parent_dir."thumbnails/t_".$photo))
{
$path_to_pic = $parent_dir.$photo;
$size = getimagesize($parent_dir."thumbnails/t_".$photo);
$display .= "<td bgcolor=orange><img src=\"/gallery/$curdir/thumbnails/t_$photo\" $size[3] border=2></td>\n";
$display .= "<td bgcolor=orange valign=\"bottom\"><input type=\"checkbox\" name=\"photo[]\" value=\"$path_to_pic\"></td>\n";
$i++;
}
}
else
{
if(is_file($parent_dir."thumbnails/t_".$photo))
{
$path_to_pic = $parent_dir.$photo;
$size = getimagesize($parent_dir."thumbnails/t_".$photo);
$display .= "</tr>\n<tr>\n<td bgcolor=orange><img src=\"/gallery/$curdir/thumbnails/t_$photo\" $size[3] border=2></td>\n";
$display .= "<td bgcolor=orange valign=\"bottom\"><input type=\"checkbox\" name=\"photo[]\" value=\"$path_to_pic\"></td>\n";
$i = $i + 2;
}
}
}
if($i % $thumbs_per_row != 0)
{
$display .= "<input type=\"hidden\" name=\"doit\" value=1>\n</tr>\n";
$display .= "<tr>\n<td bgcolor=orange align=left><input type=\"submit\" name=\"submit\" value=\" Delete Photos \"></td>\n";
$display .= "</tr>\n</table>\n</form>\n</td>\n";
}
else
{
$display .= "<input type=\"hidden\" name=\"doit\" value=1>\n</tr>";
$display .= "<tr>\n<td bgcolor=orange align=left colspan=2><input type=\"submit\" name=\"submit\" value=\" Delete Photos \"></td>\n";
$display .= "</tr>\n</table>\n</form>\n</td>\n";
}
}
elseif(isset($doit))
{
$display = "<td bgcolor=ffffff>\n<table cellpadding=0 cellspacing=0 border=0 width=100% height=100%>\n<tr>\n<td valign=\"top\"><p>";
foreach($HTTP_POST_VARS['photo'] as $a)
{
unlink($a);
$b = preg_replace("/\/$file_name\//", "/$file_name/thumbnails/t_", "$a");
if(is_file($b))
{
unlink($b);
}
preg_match("/\/$file_name\/(.*\..*)$/", $a, $match);
$cur_file = $match[1];
$display .= "$cur_file has been deleted.<br>";
}
$display .= "</td>\n</tr>\n";
$display .= "</table>\n</td>\n";
}
include("$DOCUMENT_ROOT/includes/admin/admin_menu.inc.php");
echo $display;
include("$DOCUMENT_ROOT/includes/admin/footer.inc.php");
?>
Not to mention the fact that I'd love not to have to escape all the double quotes in my HTML that I'm echoing.
Thanks
-Butcher-