Commit bc27f77e by Aleksandar Hristov

Fixed bugs, better output

1 parent 278c06e2
...@@ -56,27 +56,38 @@ else ...@@ -56,27 +56,38 @@ else
//if the user chose to create a new page //if the user chose to create a new page
if($to_add == 'page') if($to_add == 'page')
{ {
//insert the new page in the database $checkIfExists = return_page_id($title);
$query = $db->exec("INSERT INTO pages (title) VALUES ('$title')");
//if something went wrong, show the failure template with the error message if($checkIfExists!=0)
if(!$query)
{ {
$smarty->assign("error", $db->lastErrorMsg()); $smarty->assign("error", "The page already exists!");
$smarty->display('tpl/failure.tpl'); $smarty->display('tpl/failure.tpl');
} }
//else if everything went fine, show the success template
else else
{ {
$smarty->display('tpl/success.tpl'); //insert the new page in the database
$query = $db->exec("INSERT INTO pages (title) VALUES ('$title')");
//if something went wrong, show the failure template with the error message
if(!$query)
{
$smarty->assign("error", $db->lastErrorMsg());
$smarty->display('tpl/failure.tpl');
}
//else if everything went fine, show the success template
else
{
$smarty->assign("page_title", $title);
$smarty->assign("action", "create");
$smarty->display('tpl/success.tpl');
}
} }
} }
//else if the user chose to create a new section //else if the user chose to create a new section
else if($to_add == 'section') else if($to_add == 'section')
{ {
//if the user didn't choose a page to add the section to (can only happen if there's no page in the database), show the failure template with the error emssage //if the user didn't choose a page to add the section to (can only happen if there's no page in the database), show the failure template with the error message
if(empty($_GET['page_to_add_section_to'])) if(empty($_GET['page_to_add_section_to']))
{ {
$smarty->assign("error", "There has to be a page in the wiki first!"); $smarty->assign("error", "There has to be a page in the wiki first!");
...@@ -88,7 +99,7 @@ else ...@@ -88,7 +99,7 @@ else
{ {
//get the value of this page to add the section to and perform a database query to find the id of this page, needed for the page_id field in the sections table //get the value of this page to add the section to and perform a database query to find the id of this page, needed for the page_id field in the sections table
$page_to_add_section_to = $_GET['page_to_add_section_to']; $page_to_add_section_to = $_GET['page_to_add_section_to'];
$page_id = $db->querySingle("SELECT id FROM pages WHERE title=='$page_to_add_section_to'"); $page_id = return_page_id($page_to_add_section_to);
//insert the new section in the database //insert the new section in the database
$query = $db->exec("INSERT INTO sections (page_id, title) VALUES ('$page_id', '$title')"); $query = $db->exec("INSERT INTO sections (page_id, title) VALUES ('$page_id', '$title')");
...@@ -103,6 +114,9 @@ else ...@@ -103,6 +114,9 @@ else
//else if everything went fine show the success template //else if everything went fine show the success template
else else
{ {
$strPageSection = return_page_title($page_id).": ".$title;
$smarty->assign("section_title", $strPageSection);
$smarty->assign("action", "create");
$smarty->display('tpl/success.tpl'); $smarty->display('tpl/success.tpl');
} }
} }
......
...@@ -105,11 +105,11 @@ function page_sections($page) ...@@ -105,11 +105,11 @@ function page_sections($page)
} }
//function that returns section id //function that returns section id
function return_section_id($section_title) function return_section_id($section_title, $page_id)
{ {
global $db; global $db;
$query = $db->query("SELECT * FROM sections"); $query = $db->query("SELECT * FROM sections WHERE page_id = '$page_id'");
$i=0; $i=0;
while ($row=$query->fetchArray()) while ($row=$query->fetchArray())
...@@ -184,6 +184,16 @@ function return_page_title($page_id) ...@@ -184,6 +184,16 @@ function return_page_title($page_id)
return $page_title; return $page_title;
} }
function return_section_title($section_id, $page_id)
{
global $db;
$section_title = $db->querySingle("SELECT title FROM sections WHERE id = '$section_id' AND page_id = '$page_id'");
return $section_title;
}
function main_page($return_this, $current_page) function main_page($return_this, $current_page)
{ {
global $db; global $db;
......
...@@ -22,10 +22,6 @@ class MyDB extends SQLite3 ...@@ -22,10 +22,6 @@ class MyDB extends SQLite3
if(!$db) echo $db->lastErrorMsg(); if(!$db) echo $db->lastErrorMsg();
$query = $db->exec('CREATE TABLE admin (username varchar(255), password VARCHAR (255))');
if(!$query) echo $db->lastErrorMsg();
$query = $db->exec('CREATE TABLE pages (id INTEGER PRIMARY KEY AUTOINCREMENT, title varchar(250) NULL, text TEXT NULL, plain_text TEXT NULL)'); $query = $db->exec('CREATE TABLE pages (id INTEGER PRIMARY KEY AUTOINCREMENT, title varchar(250) NULL, text TEXT NULL, plain_text TEXT NULL)');
if(!$query) echo $db->lastErrorMsg(); if(!$query) echo $db->lastErrorMsg();
......
...@@ -38,16 +38,30 @@ html ...@@ -38,16 +38,30 @@ html
/* Dark blue button */ /* Dark blue button */
.dark-blue .dark-blue
{ {
background: #0066a1;
color:white;
background:#0066a1;
color:#fff;
border: 1px solid transparent;
-webkit-box-shadow: 1px 2px 2px 0 rgba(4, 4, 4, 0.3);
-moz-box-shadow: 1px 2px 2px 0 rgba(4, 4, 4, 0.3);
box-shadow: 1px 2px 2px 0 rgba(4, 4, 4, 0.3);
-moz-border-radius: 2px;
-webkit-border-radius: 2px;
border-radius: 2px;
} }
.dark-blue:hover .dark-blue:hover
{ {
background:#44c3dc !important; background: #005281 !important;
color:white; color: #ffffff;
border: 1px solid rgba(4, 4, 4, 0.1);
-webkit-box-shadow: 1px 2px 2px 0 rgba(4, 4, 4, 0.3);
-moz-box-shadow: 1px 2px 2px 0 rgba(4, 4, 4, 0.3);
box-shadow: 1px 2px 2px 0 rgba(4, 4, 4, 0.3);
} }
#menu-tray #menu-tray
{ {
padding:10px; padding:10px;
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
<div id="container2"> <div id="container2">
<h1 id="container2-header">Error!</h1> <h1 id="container2-header">Error!</h1>
</div> </div>
<div class="alert alert-danger" role="alert">{$_SERVER['HTTP_REFERER']} {$error}</div> <div class="alert alert-danger" role="alert">{$error}</div>
</div> </div>
</div> </div>
{include file="tpl/footer.tpl"} {include file="tpl/footer.tpl"}
\ No newline at end of file \ No newline at end of file
...@@ -15,15 +15,31 @@ ...@@ -15,15 +15,31 @@
</div> </div>
<div class="alert alert-success" role="alert">The action was performed successfully! <div class="alert alert-success" role="alert">The action was performed successfully!
{if (isset($action) AND $action=="edit")} {if (isset($action) AND $action=="edit")}
<br/><br/> <br/><br/>
<a href="edit.php" class="btn dark-blue">New edit</a> <a href="edit.php" class="btn dark-blue">New edit</a>
{if isset($section_id)} {if isset($section_id)}
<a href="index.php?{$page_id}#{$section_id}" class="btn dark-blue">Go to last edited</a> <a href="index.php?{$page_id}#{$section_id}" class="btn dark-blue" target="_blank">Go to last edited</a>
{else} {else}
<a href="index.php?{$page_id}" class="btn dark-blue">Go to last edited</a> <a href="index.php?{$page_id}" class="btn dark-blue" target="_blank">Go to last edited</a>
{/if}
{elseif (isset($action) AND $action=="create")}
<br/><br/>
<a href="create.php" class="btn dark-blue">Create new</a><br/><br/>
<form method="post" action="editor.php">
{if isset($section_title)}
<input type="hidden" name="select_option" value="section">
<input type="hidden" name="section_to_edit" value="{$section_title}">
<button type="submit" class="btn dark-blue">Edit this section</button>
{else}
<input type="hidden" name="select_option" value="page">
<input type="hidden" name="page_to_edit" value="{$page_title}">
<button type="submit" class="btn dark-blue">Edit this page</button>
{/if}
</form>
{/if} {/if}
{/if}
</div> </div>
</div> </div>
{include file="tpl/footer.tpl"} {include file="tpl/footer.tpl"}
\ No newline at end of file \ 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!