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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
|
<?php
include("config.php"); include("auth.php"); include("lib.php");
//#########################################################################################################################// // B R O W S E T O P I C //#########################################################################################################################//
function browtopic() { global $itemperpage, $start, $tablewidth, $admheadercolor, $admrowcolor1, $admrowcolor2; $index_url = "admin.php?action=browtopic"; if (!isset($start) OR ($start == "")) $start = 0 ;
$query_jumlah = mysql_query("SELECT count(*) FROM mtalk_topic"); $data_jumlah = mysql_fetch_row($query_jumlah); $all_record = $data_jumlah[0]; $query = mysql_query("SELECT * FROM mtalk_topic ORDER BY topic_time DESC LIMIT $start, $itemperpage"); $this_page= @mysql_num_rows($query) or die("No records found!");
echo"<table width=\"$tablewidth\" border=\"0\" style=\" margin: 10px 0;\"> <tr><td align=\"center\">"; echo "<b>Browse Topics "; $paging = generate_pagination($index_url, $all_record, $itemperpage, $start); echo $paging . "</td></tr></table>"; echo "</b> <form method=\"get\" action=\"admin.php\"> <input type=\"hidden\" name=\"action\" value=\"deltopic\"> <input type=\"hidden\" name=\"start\" value=\"$start\">";
echo " <table width=\"$tablewidth\" border=\"0\" cellspacing=\"1\" cellpadding=\"5\" bgcolor=\"#d0d0d0\"> <tr bgcolor=\"$admheadercolor\"> <td align=\"center\" width=\"30\"> </td> <td width=\"100\" class=\"normal\"><font color=\"#FFFFFF\"><b>Poster</b></font></td> <td width=\"\" class=\"normal\"><font color=\"#FFFFFF\"><b>Topics Title</b></font></td> <td align=\"center\" width=\"30\" class=\"normal\"><font color=\"#FFFFFF\"><b>Views</b></font></td> <td align=\"center\" width=\"30\" class=\"normal\"><font color=\"#FFFFFF\"><b>Replies</b></font></td> <td align=\"center\" width=\"30\" class=\"normal\"><font color=\"#FFFFFF\"><b>show</b></font></td> <td width=\"30\"> </td></tr>\n";
if ($this_page < $itemperpage) $looping = $this_page; else $looping = $itemperpage;
for ($i=1; $i<=$looping; $i++) { $counter = $end - $i; $data = mysql_fetch_row($query) or die("No topic found!"); $nomor = $counter + 1; if ((($i+1) % 2) == 0) $kolor = $admrowcolor1; else $kolor = $admrowcolor2; $tgl = substr($data[4],0,10); echo "<tr bgcolor=\"$kolor\">"; echo "<td align=\"center\"><input type=\"checkbox\" name=\"check[]\" value=\"$data[0]\"></td>"; echo "<td valign=\"top\" class=\"normal\">$tgl<br>"; $hasil_user = mysql_query("SELECT * FROM mtalk_post WHERE topic_id=$data[0] ORDER BY post_time ASC"); $data_user = mysql_fetch_row($hasil_user);// or die("No posting found!"); $user = $data_user[2]; $user_mail = $data_user[4]; $user_web = $data_user[5];
echo "by <b>$user</b><br>"; if (!$user_mail == "") echo "<a href=\"mailto:$user_mail\"><img src=\"images/sym_email.gif\" border=\"0\"></a> "; if ($user_web <> "" AND $user_web <> "http://") echo "<a href=\"$user_web\" target=\"_blank\"><img src=\"images/sym_www.gif\" border=\"0\"></a>"; echo "</td>";
echo "<td class=\"normal\"><a href=\"admin.php?action=browpost&id=$data[0]\"><strong>".$data[2]."</strong></a><br>"; $hasil_post = mysql_query("SELECT * FROM mtalk_post WHERE topic_id=$data[0] ORDER BY post_time ASC"); $data_post = mysql_fetch_row($hasil_post);// or die("No records found!"); $hasil_text = mysql_query("SELECT post_id, SUBSTRING_INDEX(post_text,' ',20) FROM mtalk_postext WHERE post_id=$data_post[0]"); $data_text = mysql_fetch_row($hasil_text);// or die("No records found!"); $kontet = smile($data_text[1]); $kontet = auto_url($kontet); echo "$kontet ...</td>"; $showing=($data[7]) ? "<img src='images/ico_check.png'>": " "; echo "<td align=\"center\" class=\"normal\">$data[5]</td> <td align=\"center\" class=\"normal\">$data[6]</td> <td align=\"center\" class=\"normal\">$showing</td> <td align=\"center\" class=\"normal\"><a href=\"admin.php?action=edittopic&id=$data[0]&start=$start\">edit</a></td></tr>"; }
echo " </table> <br> <table width=\"$tablewidth\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"> <tr> <td> <input type=\"submit\" value=\"Delete Checked Record\"> </td> <td align=\"right\" valign=\"top\"> total topics : <font color=\"#ff0000\">$all_record</font> </td> </tr> </table> </form> "; }
//#########################################################################################################################// // B R O W S E P O S T I N G //#########################################################################################################################//
function browpost() { global $itemperpage, $start, $tablewidth, $admheadercolor, $admrowcolor1, $admrowcolor2, $id; if (!isset($start) OR ($start == "")) $start = 0 ; $hasil_topic = mysql_query("SELECT * FROM mtalk_topic WHERE topic_id=$id"); $data_topic = mysql_fetch_row($hasil_topic);// or die("No topic found!"); $index_url = "admin.php?action=browpost&id=$id"; $query_jumlah = mysql_query("SELECT count(*) FROM mtalk_post WHERE topic_id=$id"); $data_jumlah = mysql_fetch_row($query_jumlah); $all_record = $data_jumlah[0];
$query = mysql_query("SELECT * FROM mtalk_post WHERE topic_id=$id ORDER BY post_time LIMIT $start, $itemperpage"); $this_page = mysql_num_rows($query);// or die("No post records found!");
echo " <form method=\"get\" action=\"admin.php\"> <input type=\"hidden\" name=\"action\" value=\"delpost\"> <input type=\"hidden\" name=\"id\" value=\"$id\"> <input type=\"hidden\" name=\"start\" value=\"$start\">"; echo"<table width=\"$tablewidth\" border=\"0\" cellspacing=\"1\" cellpadding=\"2\"> <tr><td class=\"normal\" align=\"center\">"; $paging = generate_pagination($index_url, $all_record, $itemperpage, $start); echo "<a href=\"admin.php\">Goto Admin Home</a>"; if (!empty($paging)) echo " | "; echo $paging; echo "</td></tr></table>";
echo " <img height=\"5\" src=\"images/space.gif\" width=\"$tablewidth\"><br> <table width=\"$tablewidth\" border=\"0\" cellspacing=\"1\" cellpadding=\"5\" bgcolor=\"white\"> <tr bgcolor=\"$admheadercolor\"> <td align=\"center\" width=\"5%\"> </td> <td width=\"20%\" class=\"normal\"><b><font color=\"#FFFFFF\">Posted</font></b></td> <td width=\"65%\" class=\"normal\"><b><font color=\"#FFFFFF\">$data_topic[2]</font></b></td> <td width=\"10%\"> </td> </tr>\n";
if ($this_page < $itemperpage) $looping = $this_page; else $looping = $itemperpage;
for ($i=1; $i<=$looping; $i++) { $data = mysql_fetch_row($query);// or die("No records found!");
if ((($i+1) % 2) == 0) $kolor = $admrowcolor1; else $kolor = $admrowcolor2; $tgl = substr($data[4],0,10);
echo "<tr bgcolor=\"$kolor\">"; if ($i <> 1) echo "<td align=\"center\"><input type=\"checkbox\" name=\"check[]\" value=\"$data[0]\"></td>"; else echo "<td></td>"; echo "<td valign=\"top\" class=\"normal\">$tgl<br>";
$user = $data[2]; $user_mail = $data[4]; $user_web = $data[5];
echo "by <b>$user</b><br>"; if (!$user_mail == "") echo "<a href=\"mailto:$user_mail\"><img src=\"images/sym_email.gif\" border=\"0\"></a> "; if ($user_web <> "" AND $user_web <> "http://") echo "<a href=\"$user_web\" target=\"_blank\"><img src=\"images/sym_www.gif\" border=\"0\"></a>"; echo "</td>"; echo "<td class=\"normal\">";
$hasil_text = mysql_query("SELECT * FROM mtalk_postext WHERE post_id=$data[0]"); $data_text = mysql_fetch_row($hasil_text);// or die("No records found!"); $kontet = smile($data_text[1]); $kontet = auto_url($kontet); echo "$kontet</td>"; echo "<td align=\"center\" class=\"normal\"><a href=\"admin.php?action=editpost&topicid=$id&id=$data[0]&start=$start\">edit</a></td></tr>"; }
echo " </table> <br> <table width=\"$tablewidth\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"> <tr> <td> <input type=\"submit\" value=\"Delete Checked Record\"> </td> <td align=\"right\" valign=\"top\"> total posting : <font color=\"#ff0000\">$all_record</font> </td> </tr> </table> </form> "; }
//#########################################################################################################################// // E D I T T O P I C //#########################################################################################################################//
function edittopic() { global $start, $id;
$query = mysql_query("SELECT * FROM mtalk_topic WHERE topic_id=$id"); $data = mysql_fetch_row($query); $S = ($data[8]==1) ? "checked='checked'": ""; echo " <center><form method=\"get\" action=\"admin.php\"> <input type=\"hidden\" name=\"action\" value=\"doedittopic\"> <input type=\"hidden\" name=\"id\" value=\"$id\"> <input type=\"hidden\" name=\"start\" value=\"$start\"> <table width=\"400\" border=\"0\" cellspacing=\"0\" cellpadding=\"5\"> <tr bgcolor=\"#f0f0f0\"> <td>Id</td> <td>$data[0]</td> </tr> <tr> <td>Date</td> <td>$data[4]</td> </tr> <tr bgcolor=\"#f0f0f0\"> <td>Views</td> <td>$data[5]</td> </tr> <tr> <td>Replies</td> <td>$data[6]</td> </tr> <tr bgcolor=\"#f0f0f0\"> <td>Poster</td> <td><input type=\"text\" name=\"poster\" size=\"30\" value=\"$data[3]\"></td> </tr> <tr> <td>Title</td> <td><textarea name=\"title\" rows=\"12\" cols=\"50\">$data[2]</textarea></td> </tr> <tr> <td>Show</td> <td><input type=\"checkbox\" name=\"showing\" value=\"1\" $S></td> </tr> <tr> <td> </td> <td><input type=\"submit\" value=\"Update Data\"> <div style='margin:20px 0px'><a href=\"admin.php?action=browtopic&start=$start\">Back Browsing Topics</a></div></td> </tr> </table> </form><p> </p>"; }
//#########################################################################################################################// // D O E D I T T O P I C //#########################################################################################################################//
function doedittopic() { global $id, $poster, $title, $start, $showing;
if (trim($poster)=="" OR trim($title)=="") { erro("Some fields may still blank!"); } $S=(isset($_POST['showing'])) ? "1" : 0; $query = mysql_query("UPDATE mtalk_topic SET topic_poster='$poster', topic_title='$title', showing=$S WHERE topic_id=$id");
if (mysql_affected_rows() <> 0) { echo "<span class=\"error\">Topic has been ppdated! </span>"; } else { echo "<span class=\"error\">Update failed due to some reason</span>"; }
$urut = mysql_query("SELECT * FROM mtalk_post WHERE topic_id = $id ORDER BY post_time ASC"); $data_temp = mysql_fetch_row($urut); $id_temp = $data_temp[0]; $update_name = mysql_query("UPDATE mtalk_post SET poster='$poster' WHERE post_id=$id_temp");
echo "<div style='margin:20px 0px'><span class=\"normal\"><br><br><a href=\"admin.php?start=$start\">Back Browsing Topic</a></span></div>";
}
//#########################################################################################################################// // E D I T P O S T //#########################################################################################################################//
function editpost() { global $topicid, $start, $id;
$topic = mysql_query("SELECT * FROM mtalk_topic WHERE topic_id=$topicid"); $data_topic = mysql_fetch_row($topic);
$query = mysql_query("SELECT * FROM mtalk_post WHERE post_id=$id"); $data = mysql_fetch_row($query);
$get_post_text = mysql_query("SELECT * FROM mtalk_postext WHERE post_id=$id"); $data_post_text = mysql_fetch_row($get_post_text);
echo " <center><form method=\"post\" action=\"admin.php\"> <input type=\"hidden\" name=\"action\" value=\"doeditpost\"> <input type=\"hidden\" name=\"id\" value=\"$id\"> <input type=\"hidden\" name=\"topicid\" value=\"$topicid\"> <input type=\"hidden\" name=\"start\" value=\"$start\"> <table width=\"400\" border=\"0\" cellspacing=\"0\" cellpadding=\"5\"> <tr> <td>Topic</td> <td><font color=\"blue\"><b>$data_topic[2]</b></font></td> </tr> <tr bgcolor=\"#f0f0f0\"> <td>Id</td> <td>$data[0]</td> </tr> <tr> <td>Date</td> <td>$data[3]</td> </tr> <tr bgcolor=\"#f0f0f0\"> <td>Poster</td> <td><input type=\"text\" size=\"35\" name=\"poster\" value=\"$data[2]\"></td> </tr> <tr> <td>Email</td> <td><input type=\"text\" size=\"35\" name=\"email\" value=\"$data[4]\"></td> </tr> <tr bgcolor=\"#f0f0f0\"> <td>Web</td> <td><input type=\"text\" size=\"35\" name=\"web\" value=\"$data[5]\"></td> </tr> <tr> <td>Post text</td> <td><textarea name=\"postext\" rows=\"10\" cols=\"35\">$data_post_text[1]</textarea></td> </tr> <tr> <td> </td> <td><input type=\"submit\" value=\"Update Data\"></td> </tr> </table> </form> <div style='margin:20px 0px'><span class=\"normal\"><a href=\"admin.php?action=browpost&id=$topicid&start=$start\">Back Browsing Posting</a></span><br><br><br></div> <hr noshade size=\"1\"></center>"; }
//#########################################################################################################################// // D O E D I T P O S T //#########################################################################################################################//
function doeditpost() { global $topicid, $poster, $email, $web, $postext, $start, $id;
if (trim($poster)=="" or trim($postext)=="") { erro("Some fields may still blank!"); }
if (trim($web)=="http://") $web = ""; if ($email) check_email($email);
$query_post_string = "UPDATE mtalk_post SET poster='$poster', email='$email', web='$web' WHERE post_id=$id"; $post_string = mysql_query($query_post_string); if (mysql_affected_rows() <> 0) $edit1 = 1; else $edit1 = 0;
$query_postext_string = "UPDATE mtalk_postext SET post_text='$postext' WHERE post_id=$id"; $postext_string = mysql_query($query_postext_string); if (mysql_affected_rows() <> 0) $edit2 = 1; else $edit2 = 0;
/*if (($edit1 == 1) AND ($edit2 == 1)) { echo "<span class=\"error\">Update Success! Both tables affected.</span><br>"; } elseif (($edit1 == 1) OR ($edit2 == 1)) { echo "<font face=\"$default_font\" size=2>Update Success! Only 1 table affected!</font>"; } else { echo "<font face=\"$default_font\" size=2>No Records Affected!</font>"; } */
echo "<span class=\"error\">Update action succeed</span>";
$check_topic = mysql_query("SELECT * FROM mtalk_post WHERE topic_id=$topicid ORDER BY post_time ASC"); $data_check = mysql_fetch_row($check_topic); $id_check = $data_check[0]; if ($id_check == $id) { $update_poster_query = "UPDATE mtalk_topic SET topic_poster='$poster' WHERE topic_id=$topicid"; $update_poster = mysql_query($update_poster_query); }
echo "<div style='margin:20px 0px'><span class=\"normal\"><a href=\"admin.php?action=browpost&id=$topicid&start=$start\">Back Browsing Posting</a></span><br><br><br></div>";
}
//#########################################################################################################################// // D E L E T E T O P I C //#########################################################################################################################//
function deltopic() { global $id, $check, $start; $posting_deleted = 0; $deleted = 0; for ($i=0; $i<=count($check); $i++) { if ($check[$i] <> "" ) { $hapus = @mysql_query("DELETE FROM mtalk_topic WHERE topic_id=$check[$i]"); if (mysql_affected_rows() <> 0) { $deleted++; echo "<font color=red>Topic with id: <b>$check[$i]</b> deleted!</font><br>"; $pilih_post = mysql_query("SELECT post_id FROM mtalk_post WHERE topic_id=$check[$i]"); if (@mysql_num_rows($pilih_post) <> 0) { while ($data = mysql_fetch_row($pilih_post)) { $hapus1 = mysql_query("DELETE FROM mtalk_postext WHERE post_id=$data[0]"); if(mysql_affected_rows() <> 0) { $posting_deleted++; echo "Posting with id: <b>$data[0]</b> also deleted!<br>"; } } $hapus2 = mysql_query("DELETE FROM mtalk_post WHERE topic_id=$check[$i]"); } } } }
if ($deleted == 0) echo "<br><br><span class=\"error\">No topic deleted!</span>"; else echo "<br><br><span class=\"error\">Total <font color=blue><b>$deleted</b></font> topics deleted!</span>"; if ($posting_deleted == 0) echo "<br><span class=\"error\">No posting deleted!</span>"; else echo "<br><span class=\"error\">Total <font color=blue><b>$posting_deleted</b></font> posting also deleted!</span>";
echo "<div style='margin:20px 0px'><span class=\"normal\"><a href=\"admin.php?start=$start\">back browsing topic</a></span><br><br></font></div>"; }
//#########################################################################################################################// // D E L E T E P O S T //#########################################################################################################################//
function delpost() { global $id, $check, $start;
$posting_deleted = 0; for ($i=0; $i<=count($check); $i++) { if ($check[$i] <> "" ) { $hapus = @mysql_query("DELETE FROM mtalk_post WHERE post_id=$check[$i]"); $hapus1 = @mysql_query("DELETE FROM mtalk_postext WHERE post_id=$check[$i]"); if (mysql_affected_rows() <> 0) { $posting_deleted++; echo "<span class=\"normal\">Posting with id: <b>$check[$i]</b> deleted!</span><br>"; $kurangin = mysql_query("UPDATE mtalk_topic SET topic_replies=topic_replies - 1 WHERE topic_id=$id"); $reply = mysql_query("SELECT topic_replies FROM mtalk_topic WHERE topic_id=$id"); $reply_data = mysql_fetch_row($reply); if ($reply_data[0] < 0) { $delete_topic = mysql_query("DELETE FROM mtalk_topic WHERE topic_id=$id"); } } } }
$check_last = mysql_query("SELECT topic_last_post_id FROM mtalk_topic WHERE topic_id=$id"); $data = @mysql_fetch_row($check_last) or die("The topic is not exist or have been deleted!"); $check_post = mysql_query("SELECT post_id FROM mtalk_post WHERE topic_id=$id ORDER BY post_time DESC"); $data = @mysql_fetch_row($check_post) or die("No posting in this topic"); $update_las = mysql_query("UPDATE mtalk_topic SET topic_last_post_id = $data[0] WHERE topic_id = $id");
if ($posting_deleted == 0) echo "<br><span class=\"error\">No Posting deleted!</span>"; else echo "<br><span class=\"error\">total <font color=blue><b>$posting_deleted</b></font> posting deleted!</span>"; echo "<div style='margin:20px 0px'><span class=\"normal\"><a href=\"admin.php?action=browpost&id=$id&start=$start\">back browsing posting</a></span></div>";
}
//#########################################################################################################################// // M A I N P R O G R A M //#########################################################################################################################//
include("wb_header.php");
switch ($action) {
case "": browtopic(); break;
case "browtopic": browtopic(); break;
case "edittopic": edittopic(); break;
case "doedittopic": doedittopic(); break;
case "deltopic": deltopic(); break;
case "browpost": browpost(); break;
case "editpost": editpost(); break;
case "doeditpost": doeditpost(); break;
case "delpost": delpost($id); break;
}
include("wp_footer.php");
mysql_close();
|