Commit b794d4e9 by Aleksandar Hristov

Changes

1 parent bc27f77e
...@@ -36,7 +36,7 @@ function get_pages_id() ...@@ -36,7 +36,7 @@ function get_pages_id()
$pages_id[$i]=$row[0]; $pages_id[$i]=$row[0];
$i++; $i++;
} }
return $pages_id; return !empty($pages_id) ? $pages_id : '';
} }
//function that returns all the sections in the database in an array in format "page: section" //function that returns all the sections in the database in an array in format "page: section"
...@@ -218,22 +218,22 @@ function main_page($return_this, $current_page) ...@@ -218,22 +218,22 @@ function main_page($return_this, $current_page)
switch($return_this) switch($return_this)
{ {
case "page_id": case "page_id":
return $page_id; return !empty($page_id) ? $page_id : '';
break; break;
case "page_title": case "page_title":
return $page_title; return !empty($page_title) ? $page_title : '';
break; break;
case "page_text": case "page_text":
return $page_text; return !empty($page_text) ? $page_text : '';
break; break;
case "section_id": case "section_id":
return $section_id; return !empty($section_id) ? $section_id : '';
break; break;
case "section_title": case "section_title":
return $section_title; return !empty($section_title) ? $section_title : '';
break; break;
case "section_text": case "section_text":
return $section_text; return !empty($section_text) ? $section_text : '';
break; break;
default: default:
echo "Error!"; echo "Error!";
......
...@@ -34,8 +34,236 @@ else ...@@ -34,8 +34,236 @@ else
$current_page=$current_page[1]; $current_page=$current_page[1];
} }
if(isset($_POST['editor_btn_submit']))
{
//get what we want to edit (page or section)
$to_edit = $_POST['to_edit'];
//if we want to edit a page
if($to_edit == "page")
{
//get the old title of the page (currently in the database) we want to edit
$page_to_edit = urldecode($_POST['old_title']);
//if theres no title value display the failure template with the error message
if(empty($page_to_edit))
{
$smarty->assign("error", "Something went wrong. Please try to fill the form again.");
}
//else if there is a value for the old (current) title
else
{
//find the id of this page by using the title
$id = $db->querySingle("SELECT id FROM pages WHERE title = '$page_to_edit'");
//get the new title submitted by the user
$title = $_POST['new_title'];
$title = str_replace("+", " ", $title);
//get the new text submitted by the user
$text = $db->escapeString($_POST['new_text']);
$plain_text = strip_tags($text);
//update the page in the database with the new title and text
$query = $db->exec("UPDATE pages SET title = '$title', text = '$text', plain_text='$plain_text' WHERE id = '$id'");
//if something went wrong show the failure template with the error message
if(!$query)
{
$smarty->assign("error", $db->lastErrorMsg());
}
}
}
//else if the user edited a section
else if($to_edit == "section")
{
//get the old (currently in the database) title of the section
$old_title = urldecode($_POST['old_title']);
//if it's empty display the failure template with the error message
if(empty($old_title))
{
$smarty->assign("error", "Something went wrong. Please try to fill the form again.");
$smarty->display("tpl/failure.tpl");
}
//else if it's not empty
else
{
//get the page_id and use it together with the old title to find the id of the section we want to edit
$section_to_edit = $old_title;
$page_id = $_POST['page_id'];
$id = $db->querySingle("SELECT id FROM sections WHERE page_id = '$page_id' AND title = '$section_to_edit'");
//get the new values for the text and title and update the row for this section in the database
$title = urldecode($_POST['new_title']);
$text = $db->escapeString($_POST['new_text']);
$plain_text = strip_tags($text);
$query = $db->exec("UPDATE sections SET title = '$title', text = '$text', plain_text='$plain_text' WHERE id = '$id'");
//if something went wrong show the failure template with the error message
if(!$query)
{
$smarty->assign("error", $db->lastErrorMsg());
}
}
}
}
if(isset($_POST['create_btn_submit']))
{
//get the values for what to add (page or section) and the title of what we add from the user input
$to_add = $_POST['select_option'];
$title = $_POST['title'];
//if there was no title entered
if (empty($title))
{
//display the failure template with the error message
$smarty->assign("error", "The title field has to have a value!");
}
//else if the user entered a title
else
{
//if the user chose to create a new page
if($to_add == 'page')
{
$checkIfExists = return_page_id($title);
if($checkIfExists!=0)
{
$smarty->assign("error", "The page already exists!");
}
else
{
//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());
}
else
{
$new_page_id = return_page_id($title);
header("Location: index.php?".$new_page_id);
}
}
}
//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 message
if(empty($_POST['page_to_add_section_to']))
{
$smarty->assign("error", "There has to be a page in the wiki first!");
}
//else if there's a page in the database and therefore the user chose it
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 = $_POST['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')");
//if something went wrong show the failure template with the error message
if(!$query)
{
$smarty->assign("error", $db->lastErrorMsg());
}
}
}
}
}
if(isset($_POST['remove_btn_submit']))
{
//get the user choice of what they want to remove/delete
$to_remove = $_POST['select_option'];
//if the user wants to remove a page
if ($to_remove == "page")
{
//if the variable with the page value is empty print an error and show the failure template
if (empty($_POST['page_to_remove']))
{
$smarty->assign("error", "Something went wrong. Please try to fill the form again.");
}
//else if the variable with the page value isn't empty
else
{
//get the title of the page to remove and find its id
$page_to_remove = $_POST['page_to_remove'];
$id = $db->querySingle("SELECT id FROM pages WHERE title = '$page_to_remove'");
//delete the page
$query=$db->exec("DELETE FROM pages WHERE id = '$id'");
//delete all its sections
$query=$db->exec("DELETE FROM sections WHERE page_id='$id'");
//if something went wrong show the failure template with the error message
if(!$query)
{
$smarty->assign("error", $db->lastErrorMsg());
}
}
}
//else if the user wants to remove a section
else if ($to_remove == "section")
{
//if the variable with the section title value is empty print an error and display the failure tempalte
if (empty($_POST['section_to_remove']))
{
$smarty->assign("error", "Something went wrong. Please try to fill the form again.");
}
//else if it's not empty
else
{
//get the title of the section we want to remove in format page: section
//explode the string to get the section title without the page and the page title so that we can find the page_id as well
$section_to_remove = $_POST['section_to_remove'];
$section_to_remove = explode(": ", $section_to_remove);
$page_of_section_to_remove = $section_to_remove[0];
$section_to_remove = $section_to_remove[1];
$page_id = $db->querySingle("SELECT id FROM pages WHERE title = '$page_of_section_to_remove'");
//find the id of this section and delete it from the database
$id = $db->querySingle("SELECT id FROM sections WHERE title = '$section_to_remove'");
$query=$db->exec("DELETE FROM sections WHERE id = '$id' AND page_id='$page_id'");
//if something went wrong show the failure template with the error message
if(!$query)
{
$smarty->assign("error", $db->lastErrorMsg());
}
}
}
}
//assign smarty variables and display the index.tpl //assign smarty variables and display the index.tpl
//assign values to the array needed to display all the pages found in the database; needed when creating a section
$smarty->assign("db_page_title", get_pages());
$smarty->assign("current_page", $current_page); $smarty->assign("current_page", $current_page);
//assign values to the array needed to display all the pages found in the database; needed when creating a section
$smarty->assign("page_section", get_sections());
$smarty->assign("page_id", main_page("page_id", $current_page)); $smarty->assign("page_id", main_page("page_id", $current_page));
$smarty->assign("page_title", main_page("page_title", $current_page)); $smarty->assign("page_title", main_page("page_title", $current_page));
$smarty->assign("page_text", main_page("page_text", $current_page)); $smarty->assign("page_text", main_page("page_text", $current_page));
......
...@@ -316,6 +316,11 @@ html ...@@ -316,6 +316,11 @@ html
border-bottom: 1px solid #E1E1E8; border-bottom: 1px solid #E1E1E8;
border-radius: 0 4px; border-radius: 0 4px;
} }
.margin-bottom-15
{
margin-bottom: 15px !important;
}
@media(min-width:1025px) { @media(min-width:1025px) {
#wrapper { #wrapper {
padding-left: 250px; padding-left: 250px;
......
...@@ -56,3 +56,14 @@ $("#menu-toggle").click(function(e) { ...@@ -56,3 +56,14 @@ $("#menu-toggle").click(function(e) {
}); });
$('#select_option_add').change(function(){
$('.methode_add').hide(0);
var val = $(this).val();
$('#' + val).show(0);
});
$('#select_option_remove').change(function(){
$('.methode_remove').hide(0);
var val = $(this).val() + "_remove";
$('#' + val).show(0);
});
<article> <article>
<h2 id="main-title">{$page_title}</h2><hr> <h2 id="main-title">{$page_title}
<div>{$page_text}</div> <button class="pull-right btn dark-blue" onclick="$('#edit_form_page_{$page_id}').toggle(0); $('#page_text_{$page_id}').toggle(0);"><i class="fa fa-pencil-square-o fa-lg"></i></button>
</h2>
<hr>
{if !empty($section_id) }
<div id="edit_form_page_{$page_id}" style="display:none; margin-bottom:20px; padding:0px;">
<form action="" method="post">
<div class="form-group form-inline" >
<input type="text" class="form-control" name="new_title" value="{urlencode($page_title)}">
<input type="hidden" name="to_edit" value="page">
<input type="hidden" name="old_title" value="{urlencode($page_title)}">
<input type="hidden" name="page_id" value={$page_id}>
<button type="submit" class="btn dark-blue" name="editor_btn_submit">Save changes</button>
</div>
<div class="text-center editable" id="editable">
<textarea name="new_text">{$page_text}</textarea>
</div>
</form>
</div>
<div id="page_text_{$page_id}">{$page_text}</div>
<div class="all-chapters"> <div class="all-chapters">
{section name=section loop=$section_id} {section name=section loop=$section_id}
<h3 id={$smarty.section.section.rownum}>{$smarty.section.section.rownum}. {$section_title[section]}</h3><hr> <h3 id={$smarty.section.section.rownum}>{$smarty.section.section.rownum}. {$section_title[section]}
<div class="margin-bottom-50px">{$section_text[section]}</div> <button class="pull-right btn dark-blue" onclick="$('#edit_form_section_{$smarty.section.section.rownum}').toggle(0); $('#section_text_{$smarty.section.section.rownum}').toggle(0);"><i class="fa fa-pencil-square-o fa-lg"></i></button>
</h3>
<hr>
<div id="edit_form_section_{$smarty.section.section.rownum}" class="margin-bottom-50px" style="display:none;">
<form action="" method="post">
<div class="form-group form-inline">
<input type="text" class="form-control" name="new_title" value="{urlencode($section_title[section])}">
<input type="hidden" name="to_edit" value="section">
<input type="hidden" name="old_title" value="{urlencode($section_title[section])}">
<input type="hidden" name="page_id" value={$page_id}>
<button type="submit" class="btn dark-blue" name="editor_btn_submit">Save changes</button>
</div>
<div class="text-center editable" id="editable">
<textarea name="new_text">{$section_text[section]}</textarea>
</div>
</form>
</div>
<div id="section_text_{$smarty.section.section.rownum}" class="margin-bottom-50px">{$section_text[section]}</div>
{/section} {/section}
</div> </div>
{/if}
</article> </article>
\ No newline at end of file \ No newline at end of file
...@@ -3,10 +3,7 @@ ...@@ -3,10 +3,7 @@
<!-- Update time JavaScript --> <!-- Update time JavaScript -->
<script src="static/js/main.js"></script> <script src="static/js/main.js"></script>
<script src="static/js/simple-clock.js"></script>
<script src="static/js/new_fields.js"></script>
<script type="text/javascript" src="static/select2/select2.js"></script> <script type="text/javascript" src="static/select2/select2.js"></script>
<script type="text/javascript" src="static/js/ZeroClipboard.min.js"></script>
<script type="text/javascript"> <script type="text/javascript">
$('select').select2(); $('select').select2();
......
...@@ -34,6 +34,60 @@ ...@@ -34,6 +34,60 @@
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script> <script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]--> <![endif]-->
<script type="text/javascript" src="static/tinymce/tinymce.min.js"></script>
<script type="text/javascript">
var viewportwidth;
// the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
if (typeof window.innerWidth != 'undefined')
{
viewportwidth = window.innerWidth
}
// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)
else if (typeof document.documentElement != 'undefined'
&& typeof document.documentElement.clientWidth !=
'undefined' && document.documentElement.clientWidth != 0)
{
viewportwidth = document.documentElement.clientWidth
}
// older versions of IE
else
{
viewportwidth = document.getElementsByTagName('body')[0].clientWidth
}
tinymce.init({
selector: "textarea",
height: 500,
browser_spellcheck : true,
plugin_preview_width : viewportwidth,
templates : [
{
title: "Sub-section title",
url: "tpl/tinymce_templates/sub-title.html",
description: "Enter the number in front (e.g. 2.7 Test) and add it in the id='' part of its source code."
},
{
title: "Sub-sub-section title",
url: "tpl/tinymce_templates/sub-sub-title.html",
description: "Enter the number in front (e.g. 2.7.7 Test) and add it in the id='' part of its source code."
}],
plugins: [
"advlist autolink lists link image charmap print preview hr anchor pagebreak",
"searchreplace wordcount visualblocks visualchars code",
"insertdatetime media nonbreaking save table contextmenu directionality",
"emoticons template paste textcolor colorpicker textpattern autosave"
],
toolbar1: "insertfile undo redo print preview | media link image emoticons | bold italic forecolor backcolor fontsizeselect | alignleft aligncenter alignright alignjustify outdent indent | bullist numlist | charmap searchreplace visualblocks visualchars template",
content_css : ["static/bootstrap/css/bootstrap.min.css","static/css/slimspots-wiki.css", "static/css/styles.css", "static/select2/select2.css", "static/select2/select2-bootstrap.css", "static/font-awesome/css/font-awesome.min.css"]
});
</script>
</head> </head>
<body> <body>
...@@ -5,8 +5,118 @@ ...@@ -5,8 +5,118 @@
{include file="tpl/menu_tray.tpl"} {include file="tpl/menu_tray.tpl"}
<div id="container2"> <div id="container2">
<h1 id="container2-header">Slimspots Wiki</h1> <h1 id="container2-header">Slimspots Wiki
<div class="btn-group pull-right" role="group" aria-label="...">
<button id="delete_page" type="button" class="btn btn-danger" onclick="$('#delete_form').toggle(0);"><i class="fa fa-times fa-lg"></i></button>
<button id="add_page" type="button" class="btn btn-success" onclick="$('#add_form').toggle(0);"><i class="fa fa-plus fa-lg"></i></button>
</div> </div>
</h1>
</div>
<div id="add_form" style="display:none; margin-bottom:20px; padding:0px;">
<form action="" method="post">
<div class="row">
<div class="col-lg-12">
<div class="panel panel-default">
<div class="panel-heading">Create</div>
<div class="panel-body">
<div class="form-group">
<label class="col-sm-4 control-label">Create a new:</label>
<div class="col-sm-8 margin-bottom-15">
<select id="select_option_add" class="form-control" name="select_option" data-tags="true" data-placeholder="Choose what you want to create">
<option value="page" selected>Page</option>
<option value="section">Section</option>
</select>
</div>
</div>
<div class="methode_remove display-none" id="section">
<div class="form-group">
<label class="col-sm-4 control-label">Page to add the section to:</label>
<div class="col-sm-8 margin-bottom-15">
<select class="form-control" name="page_to_add_section_to" id="page_to_add_section_to">
{foreach from=$db_page_title item=title}
<option value='{$title}'>{$title}</option>
{/foreach}
</select>
</div>
</div>
</div>
<div class="form-group">
<label class="col-sm-4 control-label">Title:</label>
<div class="col-sm-8 margin-bottom-15">
<input type="text" class="form-control" name="title" />
</div>
</div>
<div class="form-group">
<div class="col-sm-8 col-sm-offset-4">
<button class="btn dark-blue" type="submit" name="create_btn_submit">Submit</button>
</div>
</div>
</div>
</div>
</div>
</div>
</form>
</div>
<div id="delete_form" style="display:none; margin-bottom:20px; padding:0px;">
<form class="form-horizontal" method="post" action="">
<div class="panel panel-default">
<div class="panel-heading">Remove</div>
<div class="panel-body">
<div class="form-group">
<label class="col-sm-4 control-label">Remove:</label>
<div class="col-sm-8">
<select id="select_option_remove" class="form-control" name="select_option" data-tags="true" data-placeholder="Choose what you want to remove">
<option></option>
<option value="page">Page</option>
<option value="section">Section</option>
</select>
</div>
</div>
<div class="methode_remove display-none" id="page_remove">
<div class="form-group">
<label class="col-sm-4 control-label">Page to remove:</label>
<div class="col-sm-8">
<select class="form-control" name="page_to_remove" id="page_to_remove">
{foreach from=$db_page_title item=title}
<option value='{$title}'>{$title}</option>
{/foreach}
</select>
</div>
</div>
</div>
<div class="methode_remove display-none" id="section_remove">
<div class="form-group">
<label class="col-sm-4 control-label">Section to remove:</label>
<div class="col-sm-8">
<select class="form-control" name="section_to_remove" id="section_to_remove">
{foreach from=$page_section item=title}
<option value='{$title}'>{$title}</option>
{/foreach}
</select>
</div>
</div>
</div>
<div class="form-group">
<div class="col-sm-8 col-sm-offset-4">
<button class="btn dark-blue" type="submit" name="remove_btn_submit">Submit</button>
</div>
</div>
</div>
</div>
</form>
</div>
{if isset($error) }
<div class="alert alert-danger" role="alert">{$error}</div>
{/if}
{include file="tpl/content.tpl"} {include file="tpl/content.tpl"}
</div> </div>
<!-- /#page-content-wrapper --> <!-- /#page-content-wrapper -->
......
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
</li> </li>
{/section} {/section}
<li id="copyright">© 2015 slimspots.com</li> <li id="copyright">© 2016 slimspots.com</li>
</ul> </ul>
</div> </div>
<!-- /#sidebar-wrapper --> <!-- /#sidebar-wrapper -->
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!