comment.module 3.87 KB
Newer Older
Dries's avatar
 
Dries committed
1
<?php
Dries's avatar
 
Dries committed
2

Dries's avatar
 
Dries committed
3 4 5 6
$module = array("find" => "comment_find",
                "admin" => "comment_admin");

function comment_find($keys) {
Dries's avatar
 
Dries committed
7
  global $user;
Dries's avatar
 
Dries committed
8
  $find = array();
Dries's avatar
 
Dries committed
9
  $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");
Dries's avatar
 
Dries committed
10
  while ($comment = db_fetch_object($result)) {
Dries's avatar
 
Dries committed
11
    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));
Dries's avatar
 
Dries committed
12 13 14
  }
  return $find;
}
Dries's avatar
 
Dries committed
15 16

function comment_edit($id) {
Dries's avatar
 
Dries committed
17
  $result = db_query("SELECT c.*, u.userid FROM comments c LEFT JOIN users u ON c.author = u.id WHERE c.cid = '$id'");
Dries's avatar
 
Dries committed
18 19 20 21 22

  $comment = db_fetch_object($result);

  $output .= "<FORM ACTION=\"admin.php?mod=comment&op=save&id=$id\" METHOD=\"post\">\n";

23 24
  $output .= "<B>Author:</B><BR>\n";
  $output .= format_username($comment->userid) ."<P>\n";
Dries's avatar
 
Dries committed
25

26 27
  $output .= "<B>Subject:</B><BR>\n";
  $output .= "<INPUT TYPE=\"text\" NAME=\"subject\" SIZE=\"50\" VALUE=\"". check_textfield($comment->subject) ."\"><P>\n";
Dries's avatar
 
Dries committed
28 29

  $output .= "<B>Comment:</B><BR>\n";
30
  $output .= "<TEXTAREA WRAP=\"virtual\" COLS=\"50\" ROWS=\"10\" NAME=\"comment\">". check_textarea($comment->comment) ."</TEXTAREA><P>\n";
Dries's avatar
 
Dries committed
31

32
  $output .= "<INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"Save comment\">\n";
Dries's avatar
 
Dries committed
33
  $output .= "</FORM>\n";
Dries's avatar
 
Dries committed
34

Dries's avatar
 
Dries committed
35 36 37 38
  print $output;
}

function comment_save($id, $subject, $comment) {
Dries's avatar
 
Dries committed
39
  db_query("UPDATE comments SET subject = '$subject', comment = '$comment' WHERE cid = '$id'");
40
  watchdog("message", "comment: modified '$subject'");
Dries's avatar
 
Dries committed
41 42 43 44 45 46 47 48
}

function comment_display($order = "date") {
  // Initialize variables:
  $fields = array("author" => "author", "date" => "timestamp DESC", "subject" => "subject");

  // Perform SQL query:
  $result = db_query("SELECT c.*, u.userid FROM comments c LEFT JOIN users u ON u.id = c.author ORDER BY c.$fields[$order] LIMIT 50");
Dries's avatar
 
Dries committed
49

Dries's avatar
 
Dries committed
50
  // Display comments:
Dries's avatar
 
Dries committed
51
  $output .= "<TABLE BORDER=\"1\" CELLPADDING=\"2\" CELLSPACING=\"2\">\n";
Dries's avatar
 
Dries committed
52
  $output .= " <TR>\n";
Dries's avatar
 
Dries committed
53
  $output .= "  <TH ALIGN=\"right\" COLSPAN=\"3\">\n";
Dries's avatar
 
Dries committed
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
  $output .= "   <FORM ACTION=\"admin.php?mod=comment\" METHOD=\"post\">\n";
  $output .= "    <SELECT NAME=\"order\">\n";
  foreach ($fields as $key=>$value) {
    $output .= "     <OPTION VALUE=\"$key\"". ($key == $order ? " SELECTED" : "") .">Sort by $key</OPTION>\n";
  }
  $output .= "    </SELECT>\n";
  $output .= "    <INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"Update\">\n";
  $output .= "   </FORM>\n";
  $output .= "  </TH>\n";
  $output .= " </TR>\n";

  $output .= " <TR>\n";
  $output .= "  <TH>subject</TH>\n";
  $output .= "  <TH>author</TH>\n";
  $output .= "  <TH>operations</TH>\n";
  $output .= " </TR>\n";

  while ($comment = db_fetch_object($result)) {
Dries's avatar
 
Dries committed
72
    $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 ALIGN=\"center\"><A HREF=\"admin.php?mod=comment&op=edit&id=$comment->cid\">edit</A></TD></TR>\n";
Dries's avatar
 
Dries committed
73 74 75
  }

  $output .= "</TABLE>\n";
Dries's avatar
 
Dries committed
76

Dries's avatar
 
Dries committed
77 78 79 80
  print $output;
}

function comment_admin() {
Dries's avatar
 
Dries committed
81
  global $op, $id, $mod, $keys, $subject, $comment, $order;
Dries's avatar
 
Dries committed
82

Dries's avatar
 
Dries committed
83 84
  print "<SMALL><A HREF=\"admin.php?mod=comment\">overview</A> | <A HREF=\"admin.php?mod=comment&op=search\">search comment</A></SMALL><HR>\n";

Dries's avatar
 
Dries committed
85 86 87 88
  switch ($op) {
    case "edit":
      comment_edit($id);
      break;
Dries's avatar
 
Dries committed
89
    case "search":
Dries's avatar
 
Dries committed
90 91
      print search_form($keys);
      print search_data($keys, $mod);
Dries's avatar
 
Dries committed
92
      break;
Dries's avatar
 
Dries committed
93
    case "Save comment":
Dries's avatar
 
Dries committed
94
      comment_save(check_input($id), check_input($subject), check_input($comment));
95
      comment_display();
Dries's avatar
 
Dries committed
96 97
      break;
    case "Update":
Dries's avatar
 
Dries committed
98
      comment_display(check_input($order));
Dries's avatar
 
Dries committed
99 100 101 102 103 104 105
      break;
    default:
      comment_display();
  }
}

?>