index.php 1.3 KB
<?php
/**
 * Created by PhpStorm.
 * User: aleksandarhristov
 * Date: 02.02.15
 * Time: 09:53
 */

//include the smarty class and the global functions
require "libs/Smarty.class.php";
require "global_functions.php";

//initialize smarty
$smarty = new Smarty;

//connect to the database
$db = new SQLite3('wiki.db');


$url=$_SERVER['REQUEST_URI'];

if (strpos($url, '?') === false)
{
	$current_page=1;
}

else
{
	$current_page = explode ('?', $url);
	$current_page=$current_page[1];
}

$query=$db->query("SELECT * FROM pages WHERE id = '$current_page'");


while ($row=$query->fetchArray())
{
	$page_id=$row[0];
	$page_title=$row[1];
	$page_text=$row[2];

	$sections=$db->query("SELECT * FROM sections WHERE page_id = '$page_id'");
	$i=0;
	while ($row1=$sections->fetchArray())
	{
		$section_id[$i] = $row1[0];
		$section_title[$i] = $row1[2];
		$section_text[$i] = $row1[3];
		$i++;
	}
}




$smarty->assign("current_page", $current_page);
$smarty->assign("page_id", $page_id);
$smarty->assign("page_title", $page_title);
$smarty->assign("page_text", $page_text);
$smarty->assign("section_id", $section_id);
$smarty->assign("section_title", $section_title);
$smarty->assign("section_text", $section_text);

$smarty->assign("pages", get_pages());
$smarty->assign("pages_id", get_pages_id());
$smarty->display("tpl/index.tpl");