Commit b9b138e7 by Aleksandar Hristov

Index.php init (this is where the database content is shown)

1 parent 3166099e
......@@ -66,4 +66,23 @@ function current_page()
return $current_page;
}
?>
\ No newline at end of file
//function that returns all the sections that belong to a specific page
function page_sections($page)
{
global $db;
$page_id = $db->querySingle("SELECT id FROM pages WHERE title='$page'");
$query = $db->query("SELECT * FROM sections WHERE page_id = '$page_id'");
$sections = array();
$i=0;
while ($row=$query->fetchArray())
{
$sections[$i] = $row[2];
$i++;
}
return $sections;
}
<?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("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->display("tpl/index.tpl");
<article>
<h2 id="main-title">{$page_title}</h2><hr>
<p>{$page_text}</p>
<div class="all-chapters">
{section name=section loop=$section_id}
<h3 id={$smarty.section.section.rownum}>{$smarty.section.section.rownum}. {$section_title[section]}</h3><hr>
<p class="margin-bottom-50px">{$section_text[section]}</p>
{/section}
</div>
</article>
\ No newline at end of file
......@@ -15,7 +15,7 @@
<script>
var ToC =
"<nav role='navigation' class='table-of-contents'>" +
"<b><?php echo $page_title; ?></b>" +
"<strong>{$page_title}</strong>" +
"<ul>";
var newLine, el, title, link;
......
{include file="tpl/header.tpl"}
<div id="wrapper">
{include file="tpl/user_sidebar_wrapper.tpl"}
{include file="tpl/menu_tray.tpl"}
<div id="container2">
<h1 id="container2-header">Slimspots Wiki</h1>
</div>
{include file="tpl/content.tpl"}
</div>
<!-- /#page-content-wrapper -->
</div>
<!-- /#wrapper -->
{include file="tpl/footer.tpl"}
\ No newline at end of file
<!----------------------------------------------------- Sidebar ---------------------------------------------------->
<div id="sidebar-wrapper">
<ul class="sidebar-nav">
<li class="sidebar-brand">
<a href="#">
<img src="static/gfx/logo.svg" class="img-responsive"/>
</a>
</li>
{section name=pages loop=$pages}
<li class="has-sub">
<a href="#">
{$pages[pages]}<i class="fa fa-chevron-right fa pull-right chevron-margin" id="valign-icon"></i>
<ul>
<!-- sections here -->
</ul>
</a>
</li>
{/section}
</ul>
</div>
<!-- /#sidebar-wrapper -->
\ No newline at end of file
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!