-
Notifications
You must be signed in to change notification settings - Fork 0
/
editBlog.php
219 lines (208 loc) · 10.9 KB
/
editBlog.php
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
<?php
require $_SERVER['DOCUMENT_ROOT'].'/scripts/dbConnector.php';
include $_SERVER['DOCUMENT_ROOT'].'/scripts/functions.php';
sec_session_start();
$admin = 0;
if(login_check($db) == true) {
$admin = 1;
if ($_SESSION['admin'] == 1) {
$clientView = 0;
} else {
$clientView = 1;
}
} else {
die('You do not have the rights to access this page');
}
if (isset($_GET['action'])) {
$action = $_GET['action'];
} else {
$action = 'new';
}
if (isset($_GET['id'])) {
$id = $_GET['id'];
}
$directoryName='';
$displayName='';
$objectTags='';
$currentContent='';
if ($action == 'update') {
$shortName = $_POST['shortName'];
$fullName = $_POST['fullName'];
$tags = $_POST['tags'];
$content = stripslashes($_POST['editor1']);
$description = stripslashes($_POST['editor2']);
$editUser = $_SESSION['username'];
$editTimeStamp = time();
$updateId = $_GET['id'];
$sql = 'UPDATE articles SET shortname = ?, fullname = ?, tags = ?, content = ?, description = ?, editUser = ?, editTimestamp = ? WHERE id = ?';
$stmt = $db->prepare($sql);
$stmt->bind_param('sssssssi', $shortName, $fullName, $tags, $content, $description, $editUser, $editTimeStamp, $updateId);
$stmt->execute();
$leave = 1;
$id = $_GET['id'];
} else if ($action == 'create') {
$shortName = $_POST['shortName'];
$fullName = $_POST['fullName'];
$tags = $_POST['tags'];
$content = stripslashes($_POST['editor1']);
$description = stripslashes($_POST['editor2']);
$editUser = $_SESSION['username'];
$editTimeStamp = time();
$usersql = 'INSERT INTO articles (shortName,fullName,tags,content, description, creationUser,creationtimeStamp) VALUES ( ? , ? , ? , ? , ? , ? , ? )';
$userps = $db->prepare($usersql);
$defaultRights = '000';
$userps->bind_param('sssssss', $shortName, $fullName, $tags, $content, $description, $editUser, $editTimeStamp);
$userps->execute();
$id = mysqli_insert_id($db);
}
if ($action == 'edit' || $action == 'update' || $action == 'create') {
$sql='SELECT * FROM articles WHERE id = ? LIMIT 1';
/* Prepare statement */
$stmt = $db->prepare($sql);
if($stmt === false) {
trigger_error('Wrong SQL: ' . $sql . ' Error: ' . $db->error, E_USER_ERROR);
}
/* Bind parameters. TYpes: s = string, i = integer, d = double, b = blob */
$stmt->bind_param('i',$id);
/* Execute statement */
$stmt->execute();
$stmt->bind_result($id, $shortName, $fullName, $tags, $content, $description, $creationUser, $timeStamp, $editUser, $editTimeStamp, $enabled);
while ($stmt->fetch()) {
$directoryName=$shortName;
$displayName=$fullName;
$objectTags=$tags;
$currentContent=$content;
}
$futureAction = 'update&id=' . $id;
} else if ($action == 'new') {
$futureAction = 'create';
}
if ($leave == 1) {
//echo "<script>window.location='".$page."';</script>";
}
?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=uTF-8" />
<meta content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0' name='viewport' />
<meta name="viewport" content="width=device-width" />
<meta http-equiv="X-UA-Compatible" content="IE=9; IE=8; IE=7; IE=EDGE" />
<title>New-Growth - Edit Blog</title>
<link rel="icon" href="/img/favicon.ico" type="image/x-icon" />
<link href="/css/default.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" type="text/css" href="/css/jquery.tagsinput.css" />
<link href='http://fonts.googleapis.com/css?family=Denk+One' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Open+Sans:400,700' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Titillium+Web:400,900' rel='stylesheet' type='text/css'>
<script type="text/javascript" src="/scripts/jquery.js"></script>
<script type="text/javascript" src="/scripts/arrange.js"></script>
<script src="/scripts/jquery.tagsinput.min.js"></script>
</head>
<body>
<header>
<div id='proceduralArea'>
<div id='leftSide' class='sideAreas'>
</div>
<div id='rightSide' class='sideAreas'>
</div>
</div>
<div id='overlay'>
<?php if ($admin==1) { ?>
<div id='adminPanel'>
<div id='userNameMachine'><?php echo $_SESSION['username']; ?></div>
<?php if ($clientView == 1) { ?><a class='adminStuff' href='/scripts/toggleAdmin.php'>Admin view</a><?php } else { ?><a class='adminStuff' href='/scripts/toggleAdmin.php'>User view</a><?php } ?>
<a class='adminStuff' href='/editBlog.php?action=new'>New Blog</a>
<a class='adminStuff' href='/editProject.php?action=new'>New Project</a>
<a class='adminStuff' href='/index.php?action=trigger'>Trigger Joker</a>
<a class='adminStuff' href='/scripts/logout.php'>Log out</a>
</div>
<?php } ?>
<div id='centrePiece'>
<div id='middleArea'>
</div>
<img src='/img/New-Growth_logo.png' alt='Logo' id='logo' />
<img src='/img/New-Growth_fae.png' alt='fae' id='fae' />
<img src='/img/New-Growth_jodie.png' alt='jodie' id='jodie' />
</div>
<div id='grass'> </div>
</div>
</header>
<div id='wrapper'>
<nav>
<a href='/index.php' class='navigationGroup homeNav'></a>
<a href='/projects.php' class='navigationGroup projectNav'></a>
<a href='/portfolios.php' class='navigationGroup portfolioNav'></a>
<a href='/contact.php' class='navigationGroup contactNav'></a>
</nav>
</div>
<div id='outterClear'>
<div id='clearMain' class='clearBox'>
<div id='contentArea' class='insetBox fullContent'>
<h1><?php if ($action == 'new') { ?>New<?php } else if ($action == 'edit') { ?>Edit<?php } ?> Blog</h1>
<table class='editTable'>
<form method="POST" action='editBlog.php?action=<?php echo $futureAction; ?>' id='editForm' name='editForm'>
<tr><td>Full name</td><td><input type='text' placeholder='The name of the blog as it appears on the page' name='fullName' id='fullName' value='<?php echo $displayName; ?>' /></td></tr>
<tr><td>Short directory name</td><td><input type='text' placeholder='The directory name (no spaces, no punctuation)' name='shortName' id='shortName' value='<?php echo $directoryName; ?>' /></td></tr>
<tr><td>Tags</td><td><input type='text' placeholder='Start tags with hash, seperate with a comma' name='tags' id='tags' value='<?php echo $objectTags; ?>' /></td></tr>
<tr><td>Description</td><td><textarea class="ckeditor" id="editor2" name="editor2"><?php echo $description; ?></textarea><br /></td></tr>
<tr><td>Content</td><td><textarea class="ckeditor" id="editor1" name="editor1"><?php echo $currentContent; ?></textarea><br /></td></tr>
</form>
<tr><td> </td><td> <form action="post_file.php" id="dropzone" class="dropzone"><div class="fallback"><input name="file" type="file" multiple /></div></form></td></tr>
<tr><td> </td><td><input type='submit' value='Submit' name='submitBtn' id='submitBtn' onclick="$('#editForm').submit();" /></td></tr>
</table>
</div>
</div>
</div>
<?php include 'footer.php'; ?>
<script src="/scripts/ckeditor/ckeditor.js"></script>
<script type="text/javascript" src="/scripts/dropzone.js"></script>
<script src="/scripts/jquery.filedrop.js"></script>
<script src="/scripts/script.js"></script>
<script>
if ($(window).width() > 900) {
parseAndFill('proceduralArea','leftSide','rightSide','middleArea');
} else {
$('#proceduralArea').css('background','url(../img/mobileBg.png) center bottom');
}
CKEDITOR.addStylesSet( 'my_styles', [
{ name : 'Left Quote' , element : 'div', attributes : { 'class' : 'leftQuote' } },
{ name : 'Right Quote' , element : 'div', attributes : { 'class' : 'rightQuote' } },
{ name : 'Centre Quote' , element : 'div', attributes : { 'class' : 'centerQuote' } }
]);
CKEDITOR.replace( 'editor1', {
toolbar: [
{ name: 'basicstyles', items: [ 'Bold', 'Italic', 'Underline', 'Strike', 'Subscript', 'Superscript', '-', 'RemoveFormat' ] },
{ name: 'formatting', items: ['Image', 'Format']},
{ name: 'clipboard', items: [ 'Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', '-', 'Undo', 'Redo' ] },
'/',
{ name: 'paragraph', items: ['NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', '-', 'Blockquote', 'CreateDiv', '-', 'JustifyLeft', 'JustifyCenter', 'JustifyRight',' JustifyBlock']},
{ name: 'links', items: ['Link', 'Unlink', 'Anchor']},
{ name: 'document', items: [ 'Source' ] },
{ name: 'tools', items: ['Maximize','ShowBlocks']},
],
} );
CKEDITOR.replace( 'editor2', {
toolbar: [
{ name: 'basicstyles', items: [ 'Bold', 'Italic', 'Underline', 'Strike', 'Subscript', 'Superscript', '-', 'RemoveFormat' ] },
{ name: 'formatting', items: ['Image', 'Format']},
{ name: 'clipboard', items: [ 'Cut', 'Copy', 'Paste', 'PasteText', 'PasteFromWord', '-', 'Undo', 'Redo' ] },
'/',
{ name: 'paragraph', items: ['NumberedList', 'BulletedList', '-', 'Outdent', 'Indent', '-', 'Blockquote', 'CreateDiv', '-', 'JustifyLeft', 'JustifyCenter', 'JustifyRight',' JustifyBlock']},
{ name: 'links', items: ['Link', 'Unlink', 'Anchor']},
{ name: 'document', items: [ 'Source' ] },
{ name: 'tools', items: ['Maximize','ShowBlocks']},
],
} );
//CKEDITOR.config.contentsCss = 'css/cmsCss.css';
var dropZoneTime = new Dropzone("#dropzone");
dropZoneTime.on("success", function(file) {
CKEDITOR.instances['editor1'].insertHtml('<img src="/uploads/' + file.name + '" alt="uploaded image" />');
});
$('#tags').tagsInput({
'height':'50px',
'width':'100%',
});
</script>
</body>
</html>