Thank you Vaaaska for letting me in on a few things to search for. I will do so and give it a go!
Here is the build_common.php code, it will take two separate posts:
<?php
session_start();
if ( $_SESSION['logged_in'] != "true" )
{
print "Log in as admin";
exit;
}
function show_page_row ( $title, $url, $description )
{
echo "<tr>\n";
echo "<td class=\"mnllinklist\"><a href=\"" . $url . "\" target=\"_blank\" class=\"mnllinklist\">" . $title . "</a><br>";
echo $description . "</td>\n";
echo "</tr>\n";
}
function create_links_page( $category, $sub_category, $show_progress )
{
global $db, $CONFIG_VAR;
global $cplinks_version;
$category_name = str_replace ( "_", " ", $category );
$sub_category_name = ucwords ( str_replace ( "_", " ", $sub_category ) );
$type = "link";
if ( $show_progress )
{
echo "creating page ..." . $category_name . " -> " . $sub_category_name;
}
ob_start();
$location = "sub";
$title = $CONFIG_VAR['website_name'] . " :: " . $category_name . " :: " . $sub_category_name;
$keywords = $sub_category_name;
$description = "These websites provide information about " . $category_name . " and " . $sub_category_name;
//This creates the page header
require ( "../templates/mnl_page_header.php" );
// This creates the start of the main body table
echo "<!-- Start of main body table -->\n\n";
echo "<table width=\"" . $CONFIG_VAR['body_width_value'] . "\" align=\"" . $CONFIG_VAR['main_body_align'] . "\" cellspacing=\"0\" border=\"0\" cellpadding=\"0\" bgcolor=\"#" . $CONFIG_VAR['main_body_colour'] . "\">\n";
echo "<tr>\n";
//This creates the left hand column
require ( "../templates/mnl_left_hand_column.php" );
// This creates the middle table
echo "<!-- Start of middle column -->\n\n";
echo "<td valign=\"top\">\n";
// This creates the breadcrumbs
echo "<table width=\"100%\" border=\"0\" cellpadding=\"3\" cellspacing=\"0\">\n";
echo "<tr>\n";
echo "<td class=\"mnlbreadcrumbs\"><a href=\"../index.html\">Home</a> >> <a href=\"index.html\">" . $category_name . " </a> >> " . $sub_category_name . "</td>\n";
echo "</tr>\n";
echo "</table>\n";
echo "<table width=\"100%\" border=\"0\" cellpadding=\"5\" cellspacing=\"0\">\n";
$query = "SELECT title,
url,
description
FROM mnl_links
WHERE category='$category'
AND sub_category='$sub_category'
AND approved='yes'
ORDER BY status, rec_timestamp DESC";
$result = $db->get_results ( $query );
if ( $db->num_rows == 0 )
{
echo "<tr>\n";
echo "<td class=\"tbody\">There are currently no links for " . $sub_category_name . ". To add a link select \"Submit A Link\" from the menu.</td>\n";
echo "</tr>\n";
}
else
{
foreach ( $result as $val )
{
show_page_row ( $val->title, $val->url, $val->description );
}
}
echo "</table>\n";
//This creates the search form
search_form ( "sub" );
//This creates the main menu along the bottom of the main column
navigation( "link", $category, $sub_category );
echo "</td>\n";
echo "<!-- End of the middle_column -->\n\n";
// This creates the right hand menu column
require ( "../templates/mnl_right_hand_column.php" );
// This ends the main body table
echo "</tr>\n";
echo "</table>\n";
//This creates the page footer
require ( "../templates/mnl_page_footer.php" );
$output = ob_get_contents();
ob_end_clean();
$fp = fopen ( "../" . strtolower ( $category ) . "/" . strtolower ( $sub_category ) . ".html", "wb");
fwrite ($fp, $output);
fclose ($fp);
if ( $show_progress )
{
echo "....done<br>";
}
}
function show_category_links ( $title, $url, $description )
{
echo "<tr>\n";
echo "<td class=\"mnllinklist\"><a href=\"" . $url . "\" target=\"_blank\" class=\"mnllinklist\">" . $title . "</a><br>";
echo $description;
echo "</td>\n";
echo "</tr>\n";
}
function create_directory ( $directory )
{
global $ftp_server_name, $ftp_user_name, $ftp_password;
$new_dir = strtolower ( $directory );
if ( $directory = "" )
{
return array('error' => true, 'error_msg' => "No value was assigned for the directory" );
}
$connection = ftp_connect( $ftp_server_name );
$username = $ftp_user_name;
$pass = $ftp_password;
$login_result = ftp_login($connection,$username,$pass);
// check to make sure you're connected:
if ( (! ( $login_result ) ) or ( !( $connection ) ) )
{
ftp_close ( $connection);
return array('error' => true, 'error_msg' => "Cannot log in to the FTP server" );
}
//find the current directory
$explode_path = explode ( "/", getcwd() );
$num_elements = count ( $explode_path );
$root_path = $explode_path[ $num_elements - 2];
//change to the cpLinks root directory
$i = 0;
while ( !ftp_chdir( $connection, $root_path ) AND $i <$num_elements )
{
$root_path = "";
for ( $j = $num_elements - 2; $j > $i; $j-- )
{
$root_path = "/" . $explode_path[$j] . $root_path;
}
$i++;
}
if ( ftp_mkdir( $connection, $new_dir ) )
{
$new_dir = "CHMOD 777 " . $new_dir;
ftp_site ( $connection, $new_dir );
ftp_close ( $connection );
print "Directory creation succeeded and permissons set... ";
}
else
{
print "The " . strtolower ( $new_dir ) . " directory already exists... ";
}
return array('error' => false, 'error_msg' => "" );
}
function show_category_row ( $cat, $category, $directory )
{
global $db;
$query = "SELECT Count(category ) As number_links
FROM `mnl_links`
WHERE sub_category='$directory'
AND category='$cat'
AND approved='yes'";
$results = $db->get_var ( $query );
echo "<tr>\n";
if ( $directory == "" )
{
echo "<td width=\"50%\"> </td>\n";
echo "<td width=\"50%\"> </td>\n";
}
else
{
echo "<td width=\"3%\"><img src=\"../images/triangle_bullet.gif\" alt=\"\"></td>\n";
echo "<td width=\"97%\" class=\"mnlcategorylist\"><a href=\"" . strtolower ( $directory ) . ".html\"><b>" . ucwords ( $category ) . "</b></a> (" . $results . ")</td>\n";
}
echo "</tr>\n";
}
function create_sub_category_page( $category, $show_progress )
{
global $db, $CONFIG_VAR;
global $cplinks_version;
$category_name = str_replace ( "_", " ", $category );
$type = "sub";
if ( $show_progress )
{
echo "building the " . $category . " directory......";
}
ob_start();
$location = "sub";
$title = $CONFIG_VAR['website_name'] . " :: " . $category_name;
$keywords = $category;
$description = "This is a list of subjects about " . $category_name;
//This creates the page header
require ( "../templates/mnl_page_header.php" );
// This creates the start of the main body table
echo "<!-- Start of main body table -->\n\n";
echo "<table width=\"" . $CONFIG_VAR['body_width_value'] . "\" align=\"" . $CONFIG_VAR['main_body_align'] . "\" cellspacing=\"0\" border=\"0\" cellpadding=\"0\" bgcolor=\"#" . $CONFIG_VAR['main_body_colour'] . "\">\n";
echo "<tr>\n";
//This creates the left hand column
require ( "../templates/mnl_left_hand_column.php" );
// This creates the middle table
echo "<!-- Start of middle column -->\n\n";
echo "<td valign=\"top\">\n";
// This creates the breadcrumbs
echo "<table width=\"100%\" border=\"0\" cellpadding=\"3\" cellspacing=\"0\">\n";
echo "<tr>\n";
echo "<td class=\"mnlbreadcrumbs\"><a href=\"../index.html\">Home</a> >> " . $category_name . "</td>\n";
echo "</tr>\n";
echo "</table>\n";
echo "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"1\">\n";
echo "<tr>\n";
echo "<td width=\"50%\" valign=\"top\">\n";
echo "<table width=\"100%\" border=\"0\" cellpadding=\"5\" cellspacing=\"0\">\n";
$query = "SELECT DISTINCT sub_category
FROM mnl_categories
WHERE category='$category'
AND approved='yes'";
$result = $db->get_results ( $query );
$num_rows = $db->num_rows;
$round = round ( $num_rows/2, 0 );
$count = 0;
foreach ( $result as $val )
{