index.php
1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?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");