summaryrefslogtreecommitdiff
path: root/modules/comment/comment.module
blob: 9af8d04e8c50bc2fb00faa790d48e39b1e05635f (plain)
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
<?php

function comment_find($keys) {
  global $user;
  $find = array();
  $result = db_query("SELECT c.*, u.userid FROM comments c LEFT JOIN users u ON c.author = u.id WHERE c.subject LIKE '%$keys%' OR c.comment LIKE '%$keys%' ORDER BY c.timestamp DESC LIMIT 20");
  while ($comment = db_fetch_object($result)) {
    array_push($find, array("title" => check_output($comment->subject), "link" => (user_access($user, "comment") ? "admin.php?mod=comment&op=edit&id=$comment->cid" : "node.php?id=$comment->lid&cid=$comment->cid"), "user" => $comment->userid, "date" => $comment->timestamp));
  }
  return $find;
}

function comment_edit($id) {
  global $REQUEST_URI;

  $result = db_query("SELECT c.*, u.userid FROM comments c LEFT JOIN users u ON c.author = u.id WHERE c.cid = '$id'");
  $comment = db_fetch_object($result);

  $form .= form_item(t("Author"), format_username($comment->userid));
  $form .= form_textfield(t("Subject"), "subject", $comment->subject, 50, 128);
  $form .= form_textarea(t("Comment"), "comment", $comment->comment, 50, 10);
  $form .= form_submit(t("Submit"));

  return form($REQUEST_URI, $form);
}

function comment_save($id, $edit) {
  db_query("UPDATE comments SET subject = '". check_input($edit[subject]) ."', comment = '". check_input($edit[comment]) ."' WHERE cid = '$id'");
  watchdog("message", "comment: modified '$edit[subject]'");
}

function comment_overview() {
  $result = db_query("SELECT c.*, u.userid FROM comments c LEFT JOIN users u ON u.id = c.author ORDER BY timestamp DESC LIMIT 50");

  $output .= "<TABLE BORDER=\"1\" CELLPADDING=\"2\" CELLSPACING=\"2\">\n";
  $output .= " <TR><TH>subject</TH><TH>author</TH><TH>date</TH><TH COLSPAN=\"2\">operations</TH></TR>\n";
  while ($comment = db_fetch_object($result)) {
    $output .= " <TR><TD><A HREF=\"node.php?id=$comment->lid&cid=$comment->cid&pid=$comment->pid#$comment->cid\">". check_output($comment->subject) ."</A></TD><TD>". format_username($comment->userid) ."</TD><TD>". format_date($comment->timestamp, "small") ."</TD><TD><A HREF=\"admin.php?mod=comment&op=edit&id=$comment->cid\">edit comment</A></TD><TD><A HREF=\"admin.php?mod=comment&op=delete&id=$comment->cid\">delete comment</A></TD></TR>\n";
  }
  $output .= "</TABLE>\n";

  return $output;
}

function comment_admin() {
  global $op, $id, $edit, $mod, $keys, $order;

  print "<SMALL><A HREF=\"admin.php?mod=comment\">overview</A> | <A HREF=\"admin.php?mod=comment&op=search\">search comment</A></SMALL><HR>\n";

  switch ($op) {
    case "edit":
      print comment_edit($id);
      break;
    case "search":
      print search_form($keys);
      print search_data($keys, $mod);
      break;
    case t("Submit"):
      print status(comment_save(check_input($id), $edit));
      print comment_overview();
      break;
    default:
      print comment_overview();
  }
}

?>