fix problem with changing of the plot/accessions when no other selections have yet...
[sgn.git] / cgi-bin / forum / forum_post_delete.pl
blobe29062817bb88af341f0d45842385ea4b06ed34b
2 # deletes a forum post
4 # Lukas Mueller, April 6, 2005
7 use strict;
8 use CXGN::DB::Connection;
9 use CXGN::Page;
10 use CXGN::Login;
11 use CXGN::People::Forum;
12 use CXGN::People;
15 # create a page object
17 my $page = CXGN::Page -> new( "Delete Post", "Lukas");
18 my $dbh = CXGN::DB::Connection->new();
20 # check if there is a valid login going on
22 my $user_id = CXGN::Login->new($dbh)->verify_session();
24 # get the page arguments
26 =head2 Page Arguments
28 topic_id: The id of the topic the post to be deleted belongs to.
29 post_id: The id of the post to be deleted.
30 confirm: a boolean that will ask for confirmation before deleting.
31 refering page: The page that called this script, so that we can
32 provide a link back to that page. This will no always be equal to the REFERER that
33 one can obtain from the Apache object!
35 =cut
37 my ($post_id, $confirm, $refering_page, $topic_id) = $page -> get_arguments("post_id", "confirm", "refering_page", "topic_id");
39 my $sp_person_id = "";
41 my $post_person_id = undef;
42 my $post_text = undef;
43 my $post;
44 if ($post_id) {
46 $post = CXGN::People::Forum::Post -> new($dbh, $post_id);
47 my $user = CXGN::People::Person->new($dbh, $user_id);
49 $post_person_id = $post -> get_person_id();
51 $post_text = $post -> get_post_text();
53 my $post_person = CXGN::People::Person -> new($dbh, $post_person_id);
54 my $sp_person_id = $post_person -> get_sp_person_id();
55 my $post_person_last_name = $post_person -> get_last_name();
56 my $post_person_first_name = $post_person -> get_first_name();
58 if (!$post) {
59 $page->header();
60 print "<h4>No such post</h4>\n<br />
61 The post you are trying to delete does not exist.
62 It may have been deleted previously or never existed.
63 <br /><br /><br /><br />\n";
64 $page->footer();
67 elsif (($sp_person_id && ($user_id == $sp_person_id)) || $user->get_user_type() eq "curator") {
68 if (!$confirm) {
69 $page->header();
71 print <<HTML;
73 <h4>Confirm user comment delete</h4>
74 Comment \# $post_id from user <b>$post_person_first_name $post_person_last_name</b><br /><br />
75 Are you sure you want to delete this post? <br /><br />
77 <div class="boxbgcolor2">$post_text</div>
79 <br />
80 <form action="forum_post_delete.pl">
81 <input type="hidden" name="confirm" value="1" />
82 <input type="hidden" name="post_id" value="$post_id" />
83 <input type="hidden" name="refering_page" value="$refering_page" />
84 <input type="hidden" name="topic_id" value="$topic_id" />
85 <input type="submit" value="Delete" /><br /><br />
86 <a href="$refering_page">Go back</a>
87 </form>
89 HTML
92 $page->footer();
94 else {
95 my $rows = $post->delete();
97 if ($rows == 1) {
98 $page->header();
99 print "<h4>Your post has been deleted.</h4>\n<br /><br /><br />";
101 print "<a href=\"$refering_page\">Go back to user comments on the detail page.</a><br /><br />\n";
102 $page->footer();
104 else {
105 $page->header();
106 print "<h4>ERROR</h4><h4>An error occurred during deletion. The post_id supplied may be invalid.</h4>";
107 $page->footer();
113 else {
114 $page ->header();
115 print "<h4>POST CAN'T BE DELETED!</h4>\n";
116 print "<h4>Either this post_id does not exist anymore or you are not the owner of post $post_id. Only the posters can delete their own posts. Sorry!</h4>\n";
117 print "<br /><br /><a href=\"$refering_page\">Return to user comments.</a><br /><br />\n";
120 $page->footer();
124 else {
125 $page->header();
126 print "<h4>No post id was supplied. Nothing was deleted.</h4>\n";
127 $page->footer();