-
Notifications
You must be signed in to change notification settings - Fork 0
/
approve.php
201 lines (186 loc) · 6.12 KB
/
approve.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
<?php
function banish(){
header("Location: 404.php");
die();
}
// trespasser
if (session_status() == PHP_SESSION_NONE) {
session_start();
}
if(!(isset($_SESSION['create'])) || !(isset($_SESSION['approve']))){
if(!(isset($_GET['user'])) || !(isset($_GET['id'])) || !(isset($_GET['action']))){
banish();
}
// shortcuts
$short_id = $_GET['id'];
$short_action = $_GET['action'];
$short_user = $_GET['user'];
$brand = $_GET['brand'];
if($short_user != "hawwa")
banish();
// remove s after debugging
if(!($short_action == "a" || $short_action == "p" || $short_action == "s"))
banish();
// '/[1-9]\d{9}/'
//if(!(preg_match('#[0-9]{9}#', $short_id)))
if(!(is_numeric($short_id)) || !(is_numeric($brand)))
banish();
// brand 1 or 0
if(in_array($brand, array(1,0)))
$_SESSION['brand'] = $_GET['brand'];
else
banish();
// mark session if shortcut used
// validate post id
$range = $short_id / 100000000;
($range <= 1.00000001) ? banish() : (($range > 2) ? banish() : $_SESSION['shortcut'] = true);
//}
}
$brand = $_SESSION['brand'];
$brand = ($brand == 1)? "grt" : "ultra";
$init = file_get_contents("static/blogs/$brand/log.json");
$log = json_decode($init, true);
// company indication
$bg = ($brand== "grt") ? "dist" : "n2";
?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Approve a blog | Almassarat</title>
<meta name="description" content="Approve a blog | Almassarat" />
<!-- Load Headers-->
<?php include_once "headers.php"; ?>
<style>
.dashboard{
position: relative;
overflow: auto;
}
</style>
</head>
<body class='scroll1 page-gallery'>
<center>
<?php /* dyanamically added button */
define('admin', TRUE);
include_once "nav.php";
?>
<!-- front section -->
<div><img id="banner" class="img-fluid w-100" src="img/banners/<?php echo $bg; ?>.jpg" /></div>
<!-- intro text -->
<div class="my-5 text-center" id="intro">
<div class="container">
<h1 class="display-4 text-theme">Approve a Blog</h1>
<p class="adapt-3 lead">
Review blogs for approval. Click on review to view a sample and proofreading. Click on approve to publish the blog to normal users. Click on purge to delete the blog.
</p>
</div>
</div>
<div class="container my-5 dashboard">
<table class="table table-border table-striped table-hover text-center">
<thead>
<th>Blog ID</th>
<th colspan='4'>Actions</th>
</thead>
<tbody>
<tr>
<td>TEMP-100000001</td>
<td><a href="<?php echo $brand; ?>-feed.php?article=-100000001" target="_blank" class="btn btn-info">Review</a></td>
<td><input type="submit" class="btn btn-success" value="Approve" disabled></td>
<td><a href="static/blogs/<?php echo $brand; ?>/100000001.json" class="btn btn-primary" download>Download</a></td>
<td><a href="#" class="btn btn-danger disabled">Purge</a></td>
</tr>
<?php
$disabled = "";
$disabled = (isset($_SESSION['shortcut'])) ? "disabled" : "";
for($i = 1; $i < $log['pending_total']; $i++){
$id = $log['pending'][$i];
echo "
<tr>
<td>TEMP-$id</td>
<td><a href='$brand-feed.php?article=-$id' target='_blank' class='btn btn-info'>Review</a></td>
<td><button onclick='aprv($id)' class='btn btn-success' $disabled>Approve</button></form></td>
<td><a href='static/blogs/$brand/$id.json' class='btn btn-primary' download>Download</a></td>
<td><button onclick='purge($id)' class='btn btn-danger' $disabled>Purge</button></td>
</tr>
";
}
?>
</tbody>
</table>
</div>
<div class="my-5">
<hr>
<p class='lead'><a href='create.php' id='cr8'>Create Blog.</a></p><hr>
<p class="lead"><a href='dashboard.php' id='dash'>Manage Dashboard.</a></p><hr>
</div>
<!-- Footer -->
<?php include_once "footer.php"; ?>
<script>
// approve
function aprv(id){
data = "id="+id;
$.ajax({
type: "POST",
url: "approve_blog.php",
data: data,
cache: false,
success: function(result){
if(!result){
alert("Fatal Error occurred");
console.log("Fatal Error occurred");
}
if(result == "ok"){
alert("Blog approved successfully!");
console.log("Blog "+ id + " approved successfully!");
}
else{
alert(result);
console.log(result);
}
}
});
//location.reload();
}
// purge
function purge(id){
data = "id="+id;
$.ajax({
type: "POST",
url: "delete_blog.php",
data: data,
cache: false,
success: function(result){
if(!result)
alert("Fatal Error occurred");
if(result == "ok"){
alert("Blog deleted successfully!");
console.log("Blog "+ id + " deleted successfully!");
}
else
alert(result);
}
});
//location.reload();
}
</script>
<?php
// trigger action is shortcut is used
if(isset($_SESSION['shortcut'])){
// approve the post
if($short_action == "a"){
echo "<script>aprv($short_id)</script>";
}
// purge the post
if($short_action == "p"){
echo "<script>purge($short_id)</script>";
}
// display page
if($short_action == "s"){
echo "<script>console.log('debug');</script>";
}
//unset($_SESSION['shortcut']);
}
?>
</center>
<script defer src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.bundle.min.js"></script>
</body>
</html>