Commit bc27f77e by Aleksandar Hristov

Fixed bugs, better output

1 parent 278c06e2
......@@ -56,27 +56,38 @@ else
//if the user chose to create a new page
if($to_add == 'page')
{
//insert the new page in the database
$query = $db->exec("INSERT INTO pages (title) VALUES ('$title')");
$checkIfExists = return_page_id($title);
//if something went wrong, show the failure template with the error message
if(!$query)
if($checkIfExists!=0)
{
$smarty->assign("error", $db->lastErrorMsg());
$smarty->assign("error", "The page already exists!");
$smarty->display('tpl/failure.tpl');
}
//else if everything went fine, show the success template
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($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']))
{
$smarty->assign("error", "There has to be a page in the wiki first!");
......@@ -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
$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
$query = $db->exec("INSERT INTO sections (page_id, title) VALUES ('$page_id', '$title')");
......@@ -103,6 +114,9 @@ else
//else if everything went fine show the success template
else
{
$strPageSection = return_page_title($page_id).": ".$title;
$smarty->assign("section_title", $strPageSection);
$smarty->assign("action", "create");
$smarty->display('tpl/success.tpl');
}
}
......
......@@ -105,11 +105,11 @@ function page_sections($page)
}
//function that returns section id
function return_section_id($section_title)
function return_section_id($section_title, $page_id)
{
global $db;
$query = $db->query("SELECT * FROM sections");
$query = $db->query("SELECT * FROM sections WHERE page_id = '$page_id'");
$i=0;
while ($row=$query->fetchArray())
......@@ -184,6 +184,16 @@ function return_page_title($page_id)
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)
{
global $db;
......
......@@ -22,10 +22,6 @@ class MyDB extends SQLite3
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)');
if(!$query) echo $db->lastErrorMsg();
......
......@@ -38,16 +38,30 @@ html
/* Dark blue button */
.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
{
background:#44c3dc !important;
color:white;
background: #005281 !important;
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
{
padding:10px;
......
......@@ -13,7 +13,7 @@
<div id="container2">
<h1 id="container2-header">Error!</h1>
</div>
<div class="alert alert-danger" role="alert">{$_SERVER['HTTP_REFERER']} {$error}</div>
<div class="alert alert-danger" role="alert">{$error}</div>
</div>
</div>
{include file="tpl/footer.tpl"}
\ No newline at end of file
......@@ -15,15 +15,31 @@
</div>
<div class="alert alert-success" role="alert">The action was performed successfully!
{if (isset($action) AND $action=="edit")}
<br/><br/>
<a href="edit.php" class="btn dark-blue">New edit</a>
{if isset($section_id)}
<a href="index.php?{$page_id}#{$section_id}" class="btn dark-blue">Go to last edited</a>
{else}
<a href="index.php?{$page_id}" class="btn dark-blue">Go to last edited</a>
{if (isset($action) AND $action=="edit")}
<br/><br/>
<a href="edit.php" class="btn dark-blue">New edit</a>
{if isset($section_id)}
<a href="index.php?{$page_id}#{$section_id}" class="btn dark-blue" target="_blank">Go to last edited</a>
{else}
<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}
</div>
</div>
{include file="tpl/footer.tpl"}
\ 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!