editor.php
2.22 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
<?php
/**
* Created by PhpStorm.
* User: aleksandarhristov
* Date: 12.02.15
* Time: 11:27
*/
//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');
//get the selected option for what the user wants to edit (page or section)
$to_edit = $_POST['select_option'];
$smarty->assign("to_edit", $to_edit);
//if the user wants to edit a page
if($to_edit == "page")
{
//if theres no title value display the failure template with the error message
if(empty($_POST['page_to_edit']))
{
$smarty->assign("error", "Something went wrong. Please try to fill the form again.");
$smarty->display("tpl/failure.tpl");
}
//else if there is a value for the title of the page the user wants to edit
else
{
//assign the old text, page_id, old title etc. and display the editor template
$page_to_edit = $_POST['page_to_edit'];
$smarty->assign("old_title", $page_to_edit);
$old_text = $db->querySingle("SELECT text FROM pages WHERE title='$page_to_edit'");
$smarty->assign("old_text", $old_text);
$smarty->assign("page_id", "");
$smarty->display("tpl/editor.tpl");
}
}
//else if the user wants to edit a section
else if($to_edit == "section")
{
//if theres no title value display the failure template with the error message
if(empty($_POST['section_to_edit']))
{
$smarty->assign("error", "Something went wrong. Please try to fill the form again.");
$smarty->display("tpl/failure.tpl");
}
//else if there is a value for the title of the section the user wants to edit
else
{
//assign the old text, page_id, old title etc. and display the editor template
$old_title = $_POST['section_to_edit'];
$old_title = explode(": ", $old_title);
$section_to_edit = $old_title[1];
$page_to_edit = $old_title[0];
$page_id = $db->querySingle("SELECT id FROM pages WHERE title = '$page_to_edit'");
$smarty->assign("old_title", urlencode($section_to_edit));
$smarty->assign("page_id", $page_id);
$old_text = $db->querySingle("SELECT text FROM sections WHERE title='$section_to_edit' AND page_id='$page_id'");
$smarty->assign("old_text", $old_text);
$smarty->display("tpl/editor.tpl");
}
}
?>