/
mod_articles.php
711 lines (554 loc) · 24.3 KB
/
mod_articles.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
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
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
<?
include_once("mod_logging.php");
function module_enter_article(){
echo "<!-- start enter article -->";
if(isset($_REQUEST['edit']))
$edit = $_REQUEST['edit'];
else
$edit = "";
if(isset($_REQUEST['preview']))
$preview = $_REQUEST['preview'];
else
$preview = "";
if(!isset($_SESSION['user_may_post']) && !isset($_SESSION['valid_admin'])){
echo "Du har ikke tillatelse til å legge inn artikler.";
return;
}
if($edit){
echo '<table class="default_table"><tr><td colspan=2><div class="default_header">Rediger artikkelen</div></td></tr>';
$query = "SELECT * FROM articles WHERE articleid = " . $_REQUEST['articleid'] . ";";
$row = searchDB($query);
if(!$row || ($_SESSION['valid_user'] != $row['author_username'] && !isset($_SESSION['valid_admin'])) ){
echo "<tr><td colspan=2>Fant ikke artikkelen, eller du har ikke tilgang til å redigere den.</td></tr></table>";
return;
}else{
form_article();
}
}else{
echo '<table class="default_table"><tr><td colspan=2><div class="default_header">Legg inn en artikkel</div></td></tr>';
form_article();
//do_article_form();
}
echo "<br/><br/>";
do_cancel_article_form();
}
// Wipe out everything stored in session about article
function module_cancel_article(){
if(isset($_REQUEST["cancelarticle"])){
unset_form_article();
echo "Alle data midlertidig lagret i forbindelse med oppretting/redigering av artikkel er fjernet.";
}
}
/* View article */
function m_va(){
// Calls new view article function, rest of code should be dumped
va();
return;
global $anyone_comments;
if(isset($_REQUEST['c']))
$skip_chars = $_REQUEST['c'];
else
$skip_chars = 0;
echo "<!-- start view article -->";
global $article_author;
$articleid = $_REQUEST['articleid'];
echo '<div class="articles"><table><tr><td class="articlescell">';
if(!$articleid){
echo "Ingen artikkel er valgt.";
}else{
$query = "SELECT * FROM articles WHERE articleid =" . $articleid . " AND is_deleted IS NULL AND (is_draft IS NULL OR is_draft=0);";
$result = DB_get_table($query);
$num_results = DB_rows_affected($query);
if($num_results == 0){
echo "Fant ikke ønsket artikkel.";
}else{
increment_view_count($articleid);
$row = DB_next_row($result);
echo '<div class="header2">' . stripslashes($row['title']) . '</div>';
echo '<div class="metatext">' . $article_author;
echo '<span class="author">: ';
if(isset($row['author_username'])){
echo '<a href="index.php?m_c=mvp&username=';
echo $row['author_username'] . '">' . stripslashes($row['author']) . '</a>';
}else{
echo stripslashes($row['author']);
}
echo '</span>';
echo ', postet <span class="date">' . make_date($row['date_posted']) . '</span><span class="time"> ' . make_time($row['time_posted']) . '</span></div>';
echo '<div class="textbody">';
$body = stripslashes(nl2br($row['body']));
/* If reader continues an article read partly on front page, we
* insert anchor tag that the browser can skip to
*/
if($skip_chars == 0)
echo $body;
else{
echo substr($body,0,$skip_chars);
echo '<a name="continue"></a>';
echo substr($body, $skip_chars, strlen($body)-$skip_chars);
}
echo '</div>';
$edit_ok = false;
// hvis admin
if (isset($_SESSION['valid_admin'])) {
if ($_SESSION['valid_admin']) {
$edit_ok = true;
}
}
// hvis valid user, og forfatter av den.
if (isset($_SESSION['valid_user']) && isset($row['author_username'])) {
if(($row['author_username'] == $_SESSION['valid_user'])){
$edit_ok = true;
}
}
if ($edit_ok) {
echo '<div class="editarticle">';
echo '<a href="index.php?articleid=' . $row['articleid'] . '&m_c=module_delete_article">Slett</a> ';
echo '<a href="index.php?articleid=' . $row['articleid'] . '&m_c=module_enter_article&edit=1">Rediger</a>';
echo '</div>';
}
$comments_query = "SELECT * FROM articles WHERE comment_to=" . $articleid . " AND is_deleted IS NULL ORDER BY date_posted, time_posted ASC;";
$comments_results = DB_get_table($comments_query);
$num_comments = DB_rows_affected($comments_results);
if($num_comments != 0){
echo '</td></tr><tr><td class="header4"><a name="comments">Kommentarer</a></tr></td>';
display_comments_rows($comments_results);
}else{
echo '</td></tr>';
}
// End DIV articles
echo '</table></div>';
if($anyone_comments || isset($_SESSION["valid_user"])){
echo '<div class="default_header"><a name="commentform">Legg til en kommentar</a></div>';
do_comment_form();
}
else{
echo '<div class="default_text">Du må være en <a href="index.php?m_c=module_register_form&page_title=Register<+new+user">registrert bruker</a>';
echo " og <span id='loginlink''><a href=\"javascript:showDiv('loginform', 'errorandlogout')\">logget inn</a> for å kunne kommentere.</span></div>";
}
}
}
}
function display_comments_rows ($result) {
$num_results = DB_rows_affected($result);
global $unknown_author;
for ($i=$num_results; $i > 0; $i--)
{
$row = DB_next_row($result);
if($i == 1)
echo '<a name="lastcomment"></a>';
echo "<tr ><td class=\"commentscell\"><div class=\"commentsheader\">" . stripslashes($row['title']) . "</div>";
if(strlen($row['author_username']) > 1)
echo "<div class=\"commentmetatext\">Av: <span class=\"commentauthor\">" . "<a href=\"index.php?m_c=mvp&username=" . $row['author_username'] . "\" >" . stripslashes($row['author']) . "</a></span>";
else
echo "<div class=\"commentmetatext\">Av: <span class=\"commentauthor\">" . stripslashes($row['author']) . "</span>";
echo ", postet <span class=\"commentdate\">" . make_date($row['date_posted']) . "</span> <span class=\"commenttime\">" . make_time($row['time_posted']) . "</span>";
// You may delete if you are admin OR if you are a logged in user AND this is your comment AND your comment is the last one
$delete_ok = false;
// hvis admin
if (isset($_SESSION['valid_admin'])) {
if ($_SESSION['valid_admin']) {
$delete_ok = true;
}
}
// hvis bruker, og det finnes et author_username.
if (isset($_SESSION['valid_user']) && isset($row['author_username'])) {
// hvis samme, og siste post.
if (($row['author_username'] == $_SESSION['valid_user']) && ($i == 1)){
$delete_ok = true;
}
}
if ($delete_ok) {
echo '<span class="delcomment"> <a href="index.php?articleid=' . $row['articleid'] . '&m_c=module_delete_article">(slett kommentar)</a></span>';
}
echo "</div><div class=\"textbody_comment\">" . stripslashes(nl2br($row['body'])) . "</div>";
echo "</td></tr>";
}
}
function module_add_article(){
global $flashformid;
echo "\n<!-- start add article -->";
$all_ok = true; // Error checking
// create short variable names
$edit = $_REQUEST['editarticle']; // Is this an edit operation?
// User has confirmed a previewed article, get values from session
if(isset($_REQUEST['previewconfirmed'])){
$author = $_SESSION['author'];
$title = $_SESSION['title'];
$intro = $_SESSION['intro'];
$body = $_SESSION['body'];
$priority = $_SESSION['priority'];
$date_posted = $_SESSION['date_posted'];
$time_posted = $_SESSION['time_posted'];
$comment_to = $_SESSION['comment_to'];
$articleid = $_SESSION['articleid'];
$category = $_SESSION['category'];
$is_draft = $_SESSION['is_draft'];
}else{
$author = $_POST['author'];
$title = $_POST['title'];
$intro = $_POST['intro'];
$body = $_POST['body'];
$priority = $_POST['priority'];
$date_posted = $_POST['year'] . "-" . $_POST['month'] . "-" . $_POST['day'];
$time_posted = $_POST['hours'] . ":" . $_POST['minutes'];
$comment_to = $_POST['comment_to'];
$articleid = $_POST['articleid'];
$category = $_REQUEST['category'];
$category = 0;
$is_draft = $_POST['is_draft'];
$article_form_id = $_REQUEST['article_form_id'];
}
// Replace form-given time with real time if this is a comment
if($comment_to > 0 ){
$date_posted = date("Y") . "-" . date("m") . "-" . date("d");
$time_posted = date("H") . ":" . date("i");
}else{
}
// Can occur if someone posts after session is deleted. Return whatever
// contents is sent to us.
global $anyone_comments;
if(!$anyone_comments && !is_logged_in()){
echo "Du må være innlogget for å kunne kommentere; dersom du ikke gjør noe på nettstedet i løpet av omtrent 25 minutter blir du logget ut. Teksten du forsøkte å poste følger under. " .
"Merk den og bruk CTRL+C for å kopiere den og CTRL+V for å lime den inn i et tekstfelt når du har logget inn igjen.<br/><br/>";
echo $body;
return;
}
// Reject if this isn't a comment and user has no posting rights
if($comment_to < 1 && !is_logged_in()){
echo "Du har ikke tillatelse til å legge inn artikler.";
echo "Antakelig ser du dette fordi du ikke har gjort noe på nettstedet de siste 20 minuttene, slik at du har blitt automatisk utlogget. Teksten du forsøkte å poste følger under. Merk den og bruk CTRL+C for å lage en kopi og CTRL+V til å lime den inn i et tekstfelt når du har logget inn igjen.<br/>";
echo $body;
return;
}
/* If the unique form ID doesn't match with the current session counter, we do _nothing */
/* since this is most likely the result of the user tumbling back and forth.
* If the session has timed out (because the user has been writing too long, hopefully)
* we still accept the new post (i.e. NEW_SESSION is TRUE).
*/
/*
global $NEW_SESSION;
if($NEW_SESSION == TRUE)
echo "1";
else
echo "0";
*/
if((isset($article_form_id) && ($flashformid != $article_form_id)) || ($NEW_SESSION == TRUE)){
echo "Kommentar innsendt tidligere, eller du har logget ut. Du prøvde å poste dette: <br/>";
echo $body;
}else{
$preview = $_REQUEST['preview'];
$_SESSION['editarticle'] = "true";
save_form_article();
if(!($_SESSION['valid_user'] || $comment_to && article_exists($comment_to))){
echo "Du må være en registrert bruker for å kunne legge inn artikler.";
}else{
if($_SESSION['valid_user']){
$author_username = $_SESSION['valid_user'];
}else{
$author_username = '';
}
if (!$author || !$body || !$date_posted || !$time_posted)
{
$all_ok = false; $error_msg .= "Forfatter, tidspunkt og tekst må fylles inn.";
}
if (!$comment_to && !$title){
$all_ok = false; $error_msg .= " Tittel må være med!";
}
if(!(is_valid_alphanum($author) && is_valid_alphanum($title))){
$all_ok = false; $error_msg .= "Systemutvikleren gnir sitt fjes i grusen og beklager på det dypeste at forfatterfelt og tittelfelt nå inneholder et eller annet spesialtegn som ikke er godkjent. Ta vennligst kontakt snarest slik at deres personlige programmeringskonsulent kan rette opp denne pinlige feilen.";
}
$title = addslashes(strip_tags($title));
$author = addslashes(strip_tags($author));
$date_posted = addslashes(strip_tags($date_posted));
$time_posted = addslashes(strip_tags($time_posted));
$body = addslashes(strip_tags($body, "<a> <img> <br> <i> <b> <div>"));
$category = addslashes(strip_tags($category));
if($is_draft == "ON"){
$is_draft = 1; $log_description .= "savedraft,";
}else{
$is_draft = 'NULL';
}
if(!$comment_to > 0)
$comment_to = 'NULL';
else
$log_description .= "comment,";
// Inserting into DB
if($edit){
$log_description .= "editarticle,";
$query = "UPDATE articles SET title=\"$title\", author=\"$author\", intro=\"$intro\", body=\"$body\", date_posted=\"$date_posted\", time_posted=\"$time_posted\", comment_to=$comment_to, priority=\"$priority\", picture_url=\"$picture_url\", category=\"$category\", is_draft=$is_draft WHERE articleid=" . $articleid .";";
}else{
$log_description .= "newarticle,";
$query = "INSERT INTO articles (title, author, author_username, body, date_posted, time_posted, comment_to, is_draft, view_count) VALUES(\"$title\", \"$author\", \"$author_username\", \"$body\", \"$date_posted\", \"$time_posted\", $comment_to,$is_draft,0);";
}
if($all_ok == true){
if(isset($preview)){
echo "<div class=\"header2\">" . stripslashes($_REQUEST['title']) . "</div>";
echo "<div class=\"metatext\"><span class=\"author\">Av: " . $_REQUEST['author'];
if(isset($_SESSION['valid_user'])){
echo " (" . $_SESSION['valid_user'] . ").</span>";
}else{
echo " (" . $unknown_author . ").</span>";
}
echo "<span class=\"time\">Lagt opp: " . date_nor_sql($date_posted) . ", " . $time_posted . "</span></div>";
echo "<div class=\"textbody\">" . stripslashes(nl2br($_REQUEST['body'])) . "</div>";
form_start_post();
form_submit("previewconfirmed", "Lagre artikkel");
if(isset($edit))
form_hidden("editarticle", "editarticle");
form_hidden("m_c", "module_add_article");
form_end();
form_start_post();
if(isset($edit))
form_hidden("edit", "edit");
form_hidden("articleid", $articleid);
form_submit("backtoedit", "Rediger artikkel");
form_hidden("m_c", "module_enter_article");
form_end();
echo "<br/><br/>";
do_cancel_article_form();
}else{
$result = DB_insert($query);
if($result > 0){
global $logtype; global $eventdesc;
if($edit){
if($comment_to > 0)
write_log_entry($articleid, $logtype['comment'], $log_description);
else
write_log_entry($articleid, $logtype['article'], $log_description);
}else{
if($comment_to > 0)
write_log_entry(mysql_insert_id(), $logtype['comment'], $log_description);
else
write_log_entry(mysql_insert_id(), $logtype['article'], $log_description);
}
$_SESSION['flashformid'] = $flashformid+1;
if($comment_to != 'NULL'){
echo "Kommentar lagt til! Godt sagt, forhåpentligvis. Husk Vær Varsom-plakaten.<br/>";
form_start_get();
form_submit("submit", "Gå tilbake til artikkelen");
form_hidden("m_c", "m_va");
form_hidden("articleid", $comment_to);
form_end();
unset_form_article();
}else if($edit){
echo "Redigering fullført. Håper det ble bedre.";
if($is_draft != 'NULL')
echo " Denne artikkelen er lagret og er tilgjengelig fra din profilside. " .
"Den blir ikke lagt ut på forsiden eller gjort tilgjengelig gjennom artikkelsøk.";
unset_form_article();
}else{
echo "Ny artikkel lagt inn! Husk: Sist gang noen sjekket, var det bare 1 av 10 lesere som gadd å kommentere. ;)";
if($is_draft != 'NULL')
echo "Denne artikkelen er lagret og er tilgjengelig fra din profilside. " .
"Den blir ikke lagt ut på forsiden eller gjort tilgjengelig gjennom artikkelsøk.";
unset_form_article();
}
}else{
echo $query;
echo ("Artikkel ikke lagt opp, databaseproblem.");
}
}
}else{
echo $error_msg;
}
}
}
}
function module_articles_frontpage(){
echo "<!-- start articles frontpage -->";
global $article_author;
global $no_articles_text; global $jokes, $layout, $chars_showing_articles, $chars_showing_first_article;
$query = "select * from articles WHERE is_deleted IS NULL AND comment_to IS NULL AND is_draft IS NULL ORDER BY date_posted DESC, time_posted DESC LIMIT 8";
$result = DB_get_table($query);
?>
<!-- start articles frontpage -->
<?
if($layout == "newspaper")
echo '<table class="frontpage_table_2columns">';
else
echo '<table class="frontpage_table">';
if(!$result || DB_rows_affected($result) < 1){
// hvis noe er feil, vis en vits.
echo '<tr>';
echo '<td colspan="2" class=\"articles_frontpage\">';
echo $no_articles_text . ' Vi presenterer i stedet en vits.<br/><br/>';
echo $jokes[array_rand($jokes, 1)];
echo '</td>';
echo '</tr>';
}else{
$num_results = DB_rows_affected();
// øverste artikkel, spenner over begge kolonnene.
echo "<tr>";
echo '<td colspan="2" class="articles_frontpage">';
$row = DB_next_row($result);
echo '<div class="header2 articletitlefront"><a href="index.php?m_c=m_va&articleid=' . $row['articleid'] . '">' . stripslashes($row['title']) . '</a></div>';
echo '<div class="metatext">' . $article_author;
echo '<span class="author">: ';
if(isset($row['author_username'])){
echo '<a href="index.php?m_c=mvp&username=';
echo $row['author_username'] . '">' . stripslashes($row['author']) . '</a>';
}else{
echo stripslashes($row['author']);
}
echo '</span>';
echo ', postet <span class="date">' . make_date($row['date_posted']) . ' </span><span class="time">' . make_time($row['time_posted']) . '</span></div>';
echo '<div class="textbody">';
if(strlen($row['body']) < $chars_showing_first_article*2){
echo stripslashes(nl2br($row['body']));
}else{
echo closeUnclosedTags ( stripslashes( substr(nl2br($row['body']),0,$chars_showing_first_article) ) ) ;
echo " ...";
$chars_left = strlen($row['body']) - $chars_showing_first_article;
}
echo '</div>';
$number_of_comments = number_of_comments($row['articleid']);
echo '<div class="showarticlelink">';
if(strlen($row['body']) < $chars_showing_first_article*2){
echo '<a href="index.php?m_c=m_va&articleid=' . $row['articleid'] . '">Vis artikkelside</a> ';
}else{
echo '<a href="index.php?c='. $chars_showing_first_article . '&m_c=m_va&articleid=' . $row['articleid'] . '#continue">Les hele artikkelen <span class="notice">(' . $chars_left . ' flere tegn)</span></a> ';
}
// Give link to comments if any, else link to the commenting form
if($number_of_comments > 0)
echo '<a href="index.php?m_c=m_va&articleid=' . $row['articleid'] . '#comments">Les kommentarer (' . $number_of_comments . ')</a> ';
else{
global $anyone_comments;
if($anyone_comments || isset($_SESSION['valid_user']))
echo '<a href="index.php?m_c=m_va&articleid=' . $row['articleid'] . '#commentform">Skriv kommentar</a> ';
else
echo "<span id='loginlink'><a href=\"javascript:showDiv('loginform', 'errorandlogout')\">Logg inn og kommenter</a></span>";
}
echo '</div>';
echo '</td>';
echo '</tr>';
// resten av artiklene
if($layout == "newspaper")
$chars_showing_first_article = $chars_showing_first_article / 4;
for ($i=1; $i < $num_results; $i++){
// sjekker layout og hvilken 'side' man er på, siden man kan velge mellom 1 eller 2 kolonner.
if((!($i % 2 == 0)) || $layout == "weblog"){
echo "<tr>";
if($layout == "weblog")
echo '<td colspan="2" class="articles_frontpage">';
else
echo '<td class="articles_frontpage_2column">';
}else{
if($layout == "weblog")
echo '<td colspan="2" class="articles_frontpage">';
else
echo '<td class="articles_frontpage_2column">';
}
$row = DB_next_row($result);
echo '<div class="header2 articletitlefront"><a href="index.php?m_c=m_va&articleid=' . $row['articleid'] . '">' . stripslashes($row['title']) . '</a></div>';
echo '<div class="metatext">' . $article_author;
echo '<span class="author">: ';
if(isset($row['author_username'])){
echo '<a href="index.php?m_c=mvp&username=';
echo $row['author_username'] . '">' . stripslashes($row['author']) . '</a>';
}else{
echo stripslashes($row['author']);
}
echo '</span>';
echo ', postet <span class="date">' . make_date($row['date_posted']) . ' </span><span class="time">' . make_time($row['time_posted']) . '</span></div>';
echo '<div class="textbody">';
if(strlen($row['body']) < $chars_showing_first_article*2){
echo stripslashes(nl2br($row['body']));
}else{
echo stripslashes(substr(nl2br($row['body']),0,$chars_showing_first_article));
echo " ..."; $chars_left = strlen($row['body']) - $chars_showing_first_article;
}
echo '</div>';
$number_of_comments = number_of_comments($row['articleid']);
echo "<div class=\"showarticlelink\">";
if(strlen($row['body']) < $chars_showing_first_article*2){
echo '<a href="index.php?m_c=m_va&articleid=' . $row['articleid'] . '">Vis artikkelside</a> ';
}else{
echo '<a href="index.php?c='. $chars_showing_first_article . '&m_c=m_va&articleid=' . $row['articleid'] . '#continue">Les hele artikkelen <span class="notice">(' . $chars_left . ' flere tegn)</span></a> ';
}
if($number_of_comments > 0)
echo '<a href="index.php?m_c=m_va&articleid=' . $row['articleid'] . '#comments">Les kommentarer (' . $number_of_comments . ')</a> ';
else
echo '<a href="index.php?m_c=m_va&articleid=' . $row['articleid'] . '#commentform">Skriv kommentar</a> ';
echo '</div>';
echo '</td>';
if ((!($i % 2 != 0)) || $layout == "weblog"){
echo "</tr>";
}
} // slutt for-løkke
// helt til slutt, hvis antall artikler på forsiden er et partall,
// og dette ikke er weblog (en artikkel pr rad)
// vil vi bare ha en artikkel på slutten, og må huske å avslutte raden.
if (($num_results % 2 == 0) && $layout <> "weblog"){
echo "</tr>";
}
}
echo "</table>";
}
function module_delete_article(){
echo "<!-- start delete article -->";
if (!$_SESSION['valid_user']){
echo "Du må være innlogget for å få tilgang til denne siden.";
}else{
$reallydelete = $_REQUEST['reallydelete'];
$articleid = $_REQUEST['articleid'];
// TODO: this smells like shit..
if($reallydelete){
$query = "select * from articles where articleid=$articleid";
$result = DB_get_table($query);
$num_results = DB_rows_affected($result);
if($num_results == 1){
//$deletequery = "DELETE FROM articles WHERE articleid = $articleid;";
$deletequery = "UPDATE articles SET is_deleted = 1 WHERE articleid = $articleid;";
$deleteresult = DB_update($deletequery);
global $logtype; global $eventdesc;
write_log_entry($articleid, $logtype['article'], "deletearticle,");
echo "<h3>Følgende artikkel er nå slettet fra databasen</h3>";
$row = DB_next_row($result);
echo '<p><strong>'.($i+1).'. Title: ';
echo htmlspecialchars(stripslashes($row['title']));
echo '</strong><br />Author: ';
echo stripslashes($row['author']);
echo '<br />Date: ';
echo stripslashes($row['date']);
echo '<br />Article ID: ';
echo stripslashes($row['articleid']);
echo '<br />Article priority: ';
echo stripslashes($row['priority']);
echo '<br />Text:<br/> ';
echo stripslashes($row['body']);
echo '</p>';
}
else {
echo "<h3>Artikkelen fins ikke i databasen.</h3>";
}
}else{
$query = "select * from articles where articleid=$articleid";
$row = searchDB($query);
// lov til � slette?
$ok = false;
if (isset($_SESSION['valid_user'])) {
if ($_SESSION['valid_user'] == $row['author_username']) {
$ok = true;
}
}
if (isset($_SESSION['valid_admin'])) {
if ($_SESSION['valid_admin']) {
$ok = true;
}
}
if ($ok) {
echo "Vil du virkelig slette " . stripslashes($row['title']) . "?";
form_start_post();
form_hidden("m_c", "module_delete_article");
form_hidden("articleid", $articleid);
form_hidden("reallydelete", "yes");
form_submit("submit", "Ja, slett artikkelen.");
form_end();
} else {
echo "Du må være forfatteren av denne teksten for å kunne slette den.";
}
}
}
}
?>