<?PHP
/**************************************************************************
* SETUP INFORMATION - THIS IS CHANGABLE DURING INITIAL SETUP OF THE SITE!
***************************************************************************/

// Basic information about the owner of the system (used in many places) {
$owner_name = "Dan Jensen";
$owner_email = "admin@NOSPAMleinir.dk";
// Basic information about the owner of the system (used in many places) }

// This is where the setup files are to be put {
$setup_folder = "setup";
// This is where the setup files are to be put }

// If this is set to true, all users can delete themselves as user {
$let_users_delete_self = false;
// If this is set to true, all users can delete themselves as user }

// Set the default language
// Values are standard ISO two-letter language definitions
//
// For example:
// en = English
// dk = Danish
// de = German
// es = Spanish
$language = $_REQUEST['language'];
if ($language == "") $language = "dk";

/**************************************************************************
* SETUP INFORMATION ENDS HERE - NO USER SETUP BELLOW THIS POINT!
***************************************************************************/

// Script execution timer start {
$mtime = microtime();
$mtime = explode(" ",$mtime);
$mtime = $mtime[1] + $mtime[0];
$starttime = $mtime;
// Script execution timer start }

// Define variables determining where stuff goes... {
$password_file = "$setup_folder/password.txt";
$recent_file = "$setup_folder/recent_nodes.txt";
$node_folder = "$setup_folder/nodes";
$subject_folder = "$setup_folder/subjects";
$files_folder = "$setup_folder/files";
$userinfo_folder = "$setup_folder/userinfo";
// Define variables determining where stuff goes... }

//Setup folders must exist
/* This does not, for some reason, work on some servers... (Security issues I suppose...)
if (!file_exists($setup_folder)) mkdir($setup_folder,0777);
if (!file_exists($node_folder)) mkdir($node_folder,0777);
if (!file_exists($subject_folder)) mkdir($subject_folder,0777);
if (!file_exists($files_folder)) mkdir($files_folder,0777);
touch($recent_file);
*/

//The person who made the system
$creator_name = "Dan Jensen";
$creator_email = "admin@NOSPAMleinir.dk";

include ("node.class.php"); // Node functions
$nodectl = new Node; // Create a node control to work with

// A bunch of shared functions
include("shared.php");
// Get list of recently changed nodes
include ("recentchanges.php");
// Get list over theme names and folders
include ("theme_list.php");
// Authentication subsystem
include ("auth.php");
if ($_REQUEST["logout"] == true) unauth();
$usermanager = new Userman;
auth();

// Get the current node_id and get the data that goes with it {
$node_id = $_REQUEST["node_id"];
if(!$node_id){ //If we didn't get a node_id
	if($_REQUEST["node"]){ //if $node is present
		$node_id = getnode_id($setup_folder, $_REQUEST["node"]); //get $node_id by backtracing the $node
	} else {
		$node_id = 0;
	}
}
// Get the current node_id and get the data that goes with it }

// Internationalisation stuff
// Needs to be here (we need the node_id, and we don't have that before now)
include("i18n.php");

/*List of $node_ids
0 = Front page
1 = About the system, and who has made it
2 = Tag wall
3 = Site setup (links to editing nodes, subject menus, users, themes)
4 = User setup (make, delete users, change password)
5 = Manage nodes (delete, update $node-to-$node_id backwards lookup index (setup/node_backwards.txt))
6 = Edit node (include $edit_id (or an $edit_title for creating a new). Update recentchanges.php on exit (rotate_recent($new_id) function in recentchanges.php)
7 = Manage the subject menus
8 = Edit $subject_menu (include $subject_id)
9 = Theme management
10 = List of all nodes
11 = File management (downloads...)
12 = Gallery setup
	(folders with...
		gallery.txt
			containing "title;description"
		images/*.jpg/png/gif
		data/*.jpg/png/gif.txt
			containing description
		thumbs/*.jpg/png/gif (120px wide)
	)
*/

if ($node_id == 0) { include ("frontpage.php");
} else if ($node_id == 1) { include ("about.php");
} else if ($node_id == 2) { include ("tagwall.php");
} else if ($node_id == 3) { include ("setup.php");
} else if ($node_id == 4) { include ("usersetup.php");
} else if ($node_id == 5) { include ("nodesetup.php");
} else if ($node_id == 6) { include ("nodeedit.php");
} else if ($node_id == 7) { include ("subjectsetup.php");
} else if ($node_id == 8) { include ("subjectedit.php");
} else if ($node_id == 9) { $node_content = "Manage themes";
} else if ($node_id == 10) { include ("allnodes.php");
} else if ($node_id == 11) { include ("filesetup.php");
} else if ($node_id == 12) { include ("gallerysetup.php");
} else if ($node_id == -1) {
	$node_author = $owner_name;
	$node_author_email = $owner_email;
	$node_title = $node;
	$node_subject = 0;
	$node_content = parse_node_data($search_messages["notfound"], $language, $setup_folder);
	$node_date = date("F j, Y, g:i a");
} else if (is_array($node_id)) {//this means that the search for nodes returned more than one $node_id, and that it is now an array.
	$node_author = $owner_name;
	$node_author_email = $owner_email;
	$node_subject = 0;
	$node_date = date("F j, Y, g:i a");
	$node_title = $search_messages["foundnodes"];
	$commands["found_top"] = "<p>{$search_messages["foundnodes_message"]}</p>\n<ul>";
	$commands["found_bottom"] = "</ul>\n		<hr size=\"1\">\n		<p><a href=\"./index.php?node_id=6&edit_title=$node&amp;language=$language\">{$search_messages["foundnodes_create"]}</a>.</p>";
	$node_content = "{$commands["found_top"]}";
	//cycle through the list of found nodes and write the $node_title and a short bit of the $node_content
	foreach ($node_id as $key => $value) {
		foreach($value["title"] as $key2 => $value2) {
			$node_content = "$node_content
			<li><div><a href=\"./index.php?node_id={$node_id[$key]['id']}&amp;language={$node_id[$key]['language'][$key2]}\">{$node_id[$key]['title'][$key2]} ({$node_id[$key]['language'][$key2]})</a></div>";
		}
	}
	$node_content = "$node_content{$commands["found_bottom"]}";
} else if ($node_id > 99) { //Nodes
	$node_temp = $nodectl->fetchNodeData($node_id, $language, $node_folder);
	$node_author = $node_temp["author"];
	$node_author_email = $node_temp["email"];
	$node_subject = $node_temp["subject"];
	$node_date = $node_temp["date"];
	$node_title = $node_temp["title"];
	$node_content = $node_temp["content"];
	if (!strpos($node_content, "<") === true) { //only parse the node content if it isn't already html
		$node_content = parse_node_data($node_content);
	}
} else { //Something is broken, this should NEVER happen!
	$node_title = "THIS SHOULD NOT HAPPEN!!";
}

//Theming is the last thing to be done
include("theming.php");

// Script execution timer end {
$mtime = microtime();
$mtime = explode(" ",$mtime);
$mtime = $mtime[1] + $mtime[0];
$endtime = $mtime;
$totaltime = ($endtime - $starttime);
echo "<div style=\"text-align : center; font-size: 6px; color : #c0c0c0;\">This page was created in ".$totaltime." seconds</div>";
// Script execution timer end }
?>
