diff options
Diffstat (limited to 'modules/comment/comment.module')
-rw-r--r-- | modules/comment/comment.module | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/modules/comment/comment.module b/modules/comment/comment.module new file mode 100644 index 000000000..d7de2460a --- /dev/null +++ b/modules/comment/comment.module @@ -0,0 +1,96 @@ +<? + +$module = array("admin" => "comment_admin"); + +function comment_edit($id) { + $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); + + $output .= "<FORM ACTION=\"admin.php?mod=comment&op=save&id=$id\" METHOD=\"post\">\n"; + + $output .= "<P>\n"; + $output .= " <B>Author:</B><BR>\n"; + $output .= " ". format_username($comment->userid, 1) ."\n"; + $output .= "</P>\n"; + + $output .= "<P>\n"; + $output .= " <B>Subject:</B><BR>\n"; + $output .= " <INPUT TYPE=\"text\" NAME=\"subject\" SIZE=\"50\" VALUE=\"". check_output(check_field($comment->subject)) ."\"><BR>\n"; + $output .= "</P>\n"; + + $output .= "<P>\n"; + $output .= "<B>Comment:</B><BR>\n"; + $output .= " <TEXTAREA WRAP=\"virtual\" COLS=\"50\" ROWS=\"10\" NAME=\"comment\">". check_output($comment->comment) ."</TEXTAREA><BR>\n"; + $output .= "</P>\n"; + + $output .= "<P>\n"; + $output .= " <INPUT TYPE=\"submit\" NAME=\"op\" VALUE=\"Save comment\">\n"; + $output .= "</P>\n"; + $output .= "</FORM>\n"; + + print $output; +} + +function comment_save($id, $subject, $comment) { + db_query("UPDATE comments SET subject = '". check_input($subject) ."', comment = '". check_input($comment) ."' WHERE cid = $id"); + watchdog("message", "modified comment `$subject'."); +} + +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"); + + // Display comments: + $output .= "<TABLE BORDER=\"1\" CELLPADDING=\"3\" CELLSPACING=\"0\">\n"; + $output .= " <TR>\n"; + $output .= " <TH ALIGN=\"right\" COLSPAN=\"5\">\n"; + $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)) { + $output .= " <TR><TD><A HREF=\"discussion.php?id=$comment->sid&cid=$comment->cid&pid=$comment->pid#$comment->cid\">". check_output($comment->subject) ."</A></TD><TD>". format_username($comment->userid, 1) ."</TD><TD ALIGN=\"center\"><A HREF=\"admin.php?mod=comment&op=edit&id=$comment->cid\">edit</A></TD></TR>\n"; + } + + $output .= "</TABLE>\n"; + + print $output; +} + +function comment_admin() { + global $op, $id, $subject, $comment, $order; + + switch ($op) { + case "edit": + comment_edit($id); + break; + case "Save comment": + comment_save($id, $subject, $comment); + comment_edit($id); + break; + case "Update": + comment_display($order); + break; + default: + comment_display(); + } +} + +?>
\ No newline at end of file |