Code cleanup.

This commit is contained in:
Nate Jones
2015-02-15 08:46:20 +00:00
parent 45637ba48a
commit 2b0396063a
27 changed files with 230 additions and 450 deletions

View File

@@ -179,183 +179,168 @@ require_once "resources/header.php";
$order_by = $_GET["order_by"];
$order = $_GET["order"];
echo "<div align='center'>";
echo "<table width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
$sql = "select * from v_menu_items ";
$sql .= "where menu_uuid = '".$menu_uuid."' ";
$sql .= "and menu_item_parent_uuid is null ";
if (strlen($order_by)> 0) {
$sql .= "order by $order_by $order ";
}
else {
$sql .= "order by menu_item_order asc ";
}
$prep_statement = $db->prepare(check_sql($sql));
$prep_statement->execute();
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
$result_count = count($result);
echo "<tr class='border'>\n";
echo " <td align=\"left\">\n";
$c = 0;
$row_style["0"] = "row_style0";
$row_style["1"] = "row_style0";
$sql = "select * from v_menu_items ";
$sql .= "where menu_uuid = '".$menu_uuid."' ";
$sql .= "and menu_item_parent_uuid is null ";
if (strlen($order_by)> 0) {
$sql .= "order by $order_by $order ";
echo "<table class='tr_hover' width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
if ($result_count == 0) {
//no results
echo "<tr><td>&nbsp;</td></tr>";
}
else {
echo "<tr>";
echo "<th align='left' nowrap>".$text['label-title']."</th>";
echo "<th align='left' nowrap>".$text['label-groups']."</th>";
echo "<th align='left'nowrap>".$text['label-category']."</th>";
echo "<th nowrap style='text-align: center;'>".$text['label-protected']."</th>";
echo "<th nowrap width='70' style='text-align: center;'>".$text['label-menu_order']."</th>";
echo "<td class='list_control_icons'>";
if (permission_exists('menu_add')) {
echo "<a href='menu_item_edit.php?id=".$menu_uuid."' alt='".$text['button-add']."'>$v_link_label_add</a>";
}
else {
$sql .= "order by menu_item_order asc ";
}
$prep_statement = $db->prepare(check_sql($sql));
$prep_statement->execute();
$result = $prep_statement->fetchAll(PDO::FETCH_NAMED);
$result_count = count($result);
echo "</td>\n";
echo "</tr>";
$c = 0;
$row_style["0"] = "row_style0";
$row_style["1"] = "row_style0";
foreach($result as $row) {
//set the db values as php variables
$menu_item_uuid = $row['menu_item_uuid'];
$menu_item_category = $row['menu_item_category'];
$menu_item_title = $row['menu_item_title'];
$menu_item_link = $row['menu_item_link'];
$menu_item_protected = $row['menu_item_protected'];
echo "<div align='left'>\n";
echo "<table class='tr_hover' width='100%' border='0' cellpadding='0' cellspacing='0'>\n";
if ($result_count == 0) {
//no results
echo "<tr><td>&nbsp;</td></tr>";
}
else {
echo "<tr>";
echo "<th align='left' nowrap>".$text['label-title']."</th>";
echo "<th align='left' nowrap>".$text['label-groups']."</th>";
echo "<th align='left'nowrap>".$text['label-category']."</th>";
echo "<th nowrap style='text-align: center;'>".$text['label-protected']."</th>";
echo "<th nowrap width='70' style='text-align: center;'>".$text['label-menu_order']."</th>";
echo "<td class='list_control_icons'>";
if (permission_exists('menu_add')) {
echo "<a href='menu_item_edit.php?id=".$menu_uuid."' alt='".$text['button-add']."'>$v_link_label_add</a>";
}
echo "</td>\n";
echo "</tr>";
foreach($result as $row) {
//set the db values as php variables
$menu_item_uuid = $row['menu_item_uuid'];
$menu_item_category = $row['menu_item_category'];
$menu_item_title = $row['menu_item_title'];
$menu_item_link = $row['menu_item_link'];
$menu_item_protected = $row['menu_item_protected'];
//get the groups that have been assigned to the menu
$sql = "select group_name from v_menu_item_groups ";
$sql .= "where menu_uuid = '$menu_uuid' ";
$sql .= "and menu_item_uuid = '$menu_item_uuid' ";
$sub_prep_statement = $db->prepare(check_sql($sql));
$sub_prep_statement->execute();
$sub_result = $sub_prep_statement->fetchAll(PDO::FETCH_NAMED);
$group_list = "";
$x = 0;
foreach ($sub_result as &$sub_row) {
if ($x == 0) {
$group_list = $sub_row["group_name"];
}
else {
$group_list .= ", ".$sub_row["group_name"];
}
$x++;
}
unset ($sub_prep_statement);
//add the type link based on the typd of the menu
switch ($menu_item_category) {
case "internal":
$menu_item_title = "<a href='".PROJECT_PATH . $menu_item_link."'>$menu_item_title</a>";
break;
case "external":
if (substr($menu_item_link, 0,1) == "/") {
$menu_item_link = PROJECT_PATH . $menu_item_link;
}
$menu_item_title = "<a href='$menu_item_link' target='_blank'>$menu_item_title</a>";
break;
case "email":
$menu_item_title = "<a href='mailto:$menu_item_link'>$menu_item_title</a>";
break;
}
//display the content of the list
$tr_link = (permission_exists('menu_edit')) ? "href='menu_item_edit.php?id=".$menu_uuid."&menu_item_uuid=".$row['menu_item_uuid']."&menu_uuid=".$menu_uuid."'" : null;
echo "<tr style='".$row_style[$c]."' ".$tr_link.">\n";
echo "<td valign='top' class='".$row_style[$c]."'>".$menu_item_title."&nbsp;</td>";
echo "<td valign='top' class='".$row_style[$c]."'>".$group_list."&nbsp;</td>";
//echo "<td valign='top' class='".$row_style[$c]."'>".$menu_item_link."&nbsp;</td>";
echo "<td valign='top' class='".$row_style[$c]."'>".$menu_item_category."&nbsp;</td>";
//echo "<td valign='top' class='".$row_style[$c]."'>".$row[menu_item_description]."</td>";
//echo "<td valign='top' class='".$row_style[$c]."'>".$row['menu_item_parent_uuid']."&nbsp;</td>";
//echo "<td valign='top' class='".$row_style[$c]."'>".$row['menu_item_order']."&nbsp;</td>";
if ($menu_item_protected == "true") {
echo "<td valign='top' class='".$row_style[$c]."' style='text-align: center;'><strong>".$text['label-true']."</strong> &nbsp;</td>";
//get the groups that have been assigned to the menu
$sql = "select group_name from v_menu_item_groups ";
$sql .= "where menu_uuid = '$menu_uuid' ";
$sql .= "and menu_item_uuid = '$menu_item_uuid' ";
$sub_prep_statement = $db->prepare(check_sql($sql));
$sub_prep_statement->execute();
$sub_result = $sub_prep_statement->fetchAll(PDO::FETCH_NAMED);
$group_list = "";
$x = 0;
foreach ($sub_result as &$sub_row) {
if ($x == 0) {
$group_list = $sub_row["group_name"];
}
else {
echo "<td valign='top' class='".$row_style[$c]."' style='text-align: center;'>".$text['label-false']." &nbsp;</td>";
$group_list .= ", ".$sub_row["group_name"];
}
$x++;
}
unset ($sub_prep_statement);
echo "<td valign='top' nowrap class='".$row_style[$c]."' style='text-align: center;'>";
echo " ".$row[menu_item_order]."&nbsp;";
echo "</td>";
//add the type link based on the typd of the menu
switch ($menu_item_category) {
case "internal":
$menu_item_title = "<a href='".PROJECT_PATH . $menu_item_link."'>$menu_item_title</a>";
break;
case "external":
if (substr($menu_item_link, 0,1) == "/") {
$menu_item_link = PROJECT_PATH . $menu_item_link;
}
$menu_item_title = "<a href='$menu_item_link' target='_blank'>$menu_item_title</a>";
break;
case "email":
$menu_item_title = "<a href='mailto:$menu_item_link'>$menu_item_title</a>";
break;
}
//echo "<td valign='top' align='center' nowrap class='".$row_style[$c]."'>";
//if (permission_exists('menu_edit')) {
// echo " <input type='button' class='btn' name='' onclick=\"window.location='menu_item_move_up.php?menu_uuid=".$menu_uuid."&menu_item_parent_uuid=".$row['menu_item_parent_uuid']."&menu_item_uuid=".$row['menu_item_uuid']."&menu_item_order=".$row['menu_item_order']."'\" value='<' title='".$row['menu_item_order'].". ".$text['button-move_up']."'>";
// echo " <input type='button' class='btn' name='' onclick=\"window.location='menu_item_move_down.php?menu_uuid=".$menu_uuid."&menu_item_parent_uuid=".$row['menu_item_parent_uuid']."&menu_item_uuid=".$row['menu_item_uuid']."&menu_item_order=".$row['menu_item_order']."'\" value='>' title='".$row['menu_item_order'].". ".$text['button-move_down']."'>";
//}
//echo "</td>";
//display the content of the list
$tr_link = (permission_exists('menu_edit')) ? "href='menu_item_edit.php?id=".$menu_uuid."&menu_item_uuid=".$row['menu_item_uuid']."&menu_uuid=".$menu_uuid."'" : null;
echo "<tr style='".$row_style[$c]."' ".$tr_link.">\n";
echo "<td valign='top' class='".$row_style[$c]."'>".$menu_item_title."&nbsp;</td>";
echo "<td valign='top' class='".$row_style[$c]."'>".$group_list."&nbsp;</td>";
//echo "<td valign='top' class='".$row_style[$c]."'>".$menu_item_link."&nbsp;</td>";
echo "<td valign='top' class='".$row_style[$c]."'>".$menu_item_category."&nbsp;</td>";
//echo "<td valign='top' class='".$row_style[$c]."'>".$row[menu_item_description]."</td>";
//echo "<td valign='top' class='".$row_style[$c]."'>".$row['menu_item_parent_uuid']."&nbsp;</td>";
//echo "<td valign='top' class='".$row_style[$c]."'>".$row['menu_item_order']."&nbsp;</td>";
echo " <td class='list_control_icons'>";
if (permission_exists('menu_edit')) {
echo "<a href='menu_item_edit.php?id=".$menu_uuid."&menu_item_uuid=".$row['menu_item_uuid']."&menu_uuid=".$menu_uuid."' alt='".$text['button-edit']."'>$v_link_label_edit</a>";
}
if (permission_exists('menu_delete')) {
echo "<a href='menu_item_delete.php?id=".$menu_uuid."&menu_item_uuid=".$row['menu_item_uuid']."&menu_uuid=".$menu_uuid."' onclick=\"return confirm('".$text['confirm-delete']."')\" alt='".$text['button-delete']."'>$v_link_label_delete</a>";
}
echo " </td>\n";
echo "</tr>";
if ($menu_item_protected == "true") {
echo "<td valign='top' class='".$row_style[$c]."' style='text-align: center;'><strong>".$text['label-true']."</strong> &nbsp;</td>";
}
else {
echo "<td valign='top' class='".$row_style[$c]."' style='text-align: center;'>".$text['label-false']." &nbsp;</td>";
}
//update the menu order
if ($row[menu_item_order] != $tmp_menu_item_order) {
$sql = "update v_menu_items set ";
$sql .= "menu_item_title = '".$row['menu_item_title']."', ";
$sql .= "menu_item_order = '".$tmp_menu_item_order."' ";
$sql .= "where menu_uuid = '".$menu_uuid."' ";
$sql .= "and menu_item_uuid = '".$row[menu_item_uuid]."' ";
//$db->exec(check_sql($sql));
}
$tmp_menu_item_order++;
echo "<td valign='top' nowrap class='".$row_style[$c]."' style='text-align: center;'>";
echo " ".$row[menu_item_order]."&nbsp;";
echo "</td>";
//check for sub menus
$menu_item_level = 0;
if (strlen($row['menu_item_uuid']) > 0) {
$c = build_db_child_menu_list($db, $menu_item_level, $row['menu_item_uuid'], $c);
}
//echo "<td valign='top' align='center' nowrap class='".$row_style[$c]."'>";
//if (permission_exists('menu_edit')) {
// echo " <input type='button' class='btn' name='' onclick=\"window.location='menu_item_move_up.php?menu_uuid=".$menu_uuid."&menu_item_parent_uuid=".$row['menu_item_parent_uuid']."&menu_item_uuid=".$row['menu_item_uuid']."&menu_item_order=".$row['menu_item_order']."'\" value='<' title='".$row['menu_item_order'].". ".$text['button-move_up']."'>";
// echo " <input type='button' class='btn' name='' onclick=\"window.location='menu_item_move_down.php?menu_uuid=".$menu_uuid."&menu_item_parent_uuid=".$row['menu_item_parent_uuid']."&menu_item_uuid=".$row['menu_item_uuid']."&menu_item_order=".$row['menu_item_order']."'\" value='>' title='".$row['menu_item_order'].". ".$text['button-move_down']."'>";
//}
//echo "</td>";
if ($c==0) { $c=1; } else { $c=0; }
} //end foreach
unset($sql, $result, $row_count);
echo " <td class='list_control_icons'>";
if (permission_exists('menu_edit')) {
echo "<a href='menu_item_edit.php?id=".$menu_uuid."&menu_item_uuid=".$row['menu_item_uuid']."&menu_uuid=".$menu_uuid."' alt='".$text['button-edit']."'>$v_link_label_edit</a>";
}
if (permission_exists('menu_delete')) {
echo "<a href='menu_item_delete.php?id=".$menu_uuid."&menu_item_uuid=".$row['menu_item_uuid']."&menu_uuid=".$menu_uuid."' onclick=\"return confirm('".$text['confirm-delete']."')\" alt='".$text['button-delete']."'>$v_link_label_delete</a>";
}
echo " </td>\n";
echo "</tr>";
} //end if results
//update the menu order
if ($row[menu_item_order] != $tmp_menu_item_order) {
$sql = "update v_menu_items set ";
$sql .= "menu_item_title = '".$row['menu_item_title']."', ";
$sql .= "menu_item_order = '".$tmp_menu_item_order."' ";
$sql .= "where menu_uuid = '".$menu_uuid."' ";
$sql .= "and menu_item_uuid = '".$row[menu_item_uuid]."' ";
//$db->exec(check_sql($sql));
}
$tmp_menu_item_order++;
echo "<tr>\n";
echo "<td colspan='6' align='left'>\n";
echo " <table border='0' width='100%' cellpadding='0' cellspacing='0'>\n";
echo " <tr>\n";
echo " <td width='33.3%' nowrap>&nbsp;</td>\n";
echo " <td width='33.3%' align='center' nowrap>&nbsp;</td>\n";
echo " <td width='33.3%' align='right'>\n";
if (permission_exists('menu_add') && $action == "update") {
echo " <a href='menu_item_edit.php?id=".$menu_uuid."' alt='".$text['button-add']."'>$v_link_label_add</a>\n";
}
echo " </td>\n";
echo " </tr>\n";
echo " </table>\n";
//check for sub menus
$menu_item_level = 0;
if (strlen($row['menu_item_uuid']) > 0) {
$c = build_db_child_menu_list($db, $menu_item_level, $row['menu_item_uuid'], $c);
}
echo "</td>\n";
echo "</tr>\n";
echo "</table>\n";
echo "</div>\n";
echo "<br><br>";
if ($c==0) { $c=1; } else { $c=0; }
} //end foreach
unset($sql, $result, $row_count);
echo " </td>\n";
echo "</tr>\n";
echo "</table>\n";
echo "</div>";
} //end if results
echo "<br><br>";
require_once "resources/footer.php";
echo "<tr>\n";
echo "<td colspan='6' align='left'>\n";
echo " <table border='0' width='100%' cellpadding='0' cellspacing='0'>\n";
echo " <tr>\n";
echo " <td width='33.3%' nowrap>&nbsp;</td>\n";
echo " <td width='33.3%' align='center' nowrap>&nbsp;</td>\n";
echo " <td width='33.3%' align='right'>\n";
if (permission_exists('menu_add') && $action == "update") {
echo " <a href='menu_item_edit.php?id=".$menu_uuid."' alt='".$text['button-add']."'>$v_link_label_add</a>\n";
}
echo " </td>\n";
echo " </tr>\n";
echo " </table>\n";
echo "</td>\n";
echo "</tr>\n";
echo "</table>\n";
echo "<br><br>";
require_once "resources/footer.php";
?>