fix problem with changing of the plot/accessions when no other selections have yet...
[sgn.git] / cgi-bin / forum / topics.pl
blob3e913e246b721a86d4741ab62b72fb87f4ec885c
2 use strict;
3 use CXGN::DB::Connection;
4 use CXGN::Page;
5 use CXGN::People;
6 use CXGN::People::Person;
7 use CXGN::Login;
8 use CXGN::People::Forum;
9 use CXGN::Contact;
10 use CXGN::Page::FormattingHelpers qw /page_title_html blue_section_html/;
12 my $page = CXGN::Page->new("Forum Main", "Lukas");
14 my $dbh = CXGN::DB::Connection->new();
15 my $sp_person_id = CXGN::Login->new($dbh)->has_session();
17 my ($topic_name, $topic_description) = $page -> get_encoded_arguments("topic_name", "topic_description", "topic_id", "post_text", "post_parent_id");
19 # create a user object, representing the user who is logged in,
20 # or a dummy user object if not logged in.
22 my $user = undef;
24 my $name="";
25 if ($sp_person_id) {
26 $user = CXGN::People::Person->new($dbh, $sp_person_id);
27 $sp_person_id = $user -> get_sp_person_id();
28 $name = $user->get_first_name()." ".$user->get_last_name();
30 else { $user = CXGN::People::Person->new($dbh); }
32 if ($topic_name) {
33 my $sp_person_id = CXGN::Login->new($dbh)->verify_session();
35 my $topic = CXGN::People::Forum::Topic -> new($dbh);
36 $topic->set_topic_name($topic_name);
37 $topic->set_topic_description($topic_description);
38 $topic->set_person_id($sp_person_id);
39 $topic->store();
41 CXGN::Contact::email_us("New topic submitted: $topic_name","Description: $topic_description",'email');
47 $page -> header();
49 print page_title_html("Forum Topics");
51 my $login_string="";
53 my $s = "";
54 $s = topics_list($dbh, $name, $user);
55 print $s;
57 if ($name) { $login_string = qq { You are logged in as <b>$name</b>. <a href="add_topic.pl?action=new"><b>Add topic</b></a>.<br /><br /> }; }
58 else { $login_string="<b>Note:</b> <ul><li>You are not logged in.</li><li>You have to be logged in to add new topics and posts. </li><li>You don't need to be logged in for browsing.</li></ul><br /> [<a href=\"/solpeople/login.pl?goto_url=/forum/topics.pl\">Login</a>] <br /><br />\n"; }
60 print $login_string;
62 $page -> footer();
67 sub topics_list {
68 my $dbh = shift;
69 my $login = shift;
70 my $user = shift;
72 my @topics = CXGN::People::Forum::Topic::all_topics($dbh);
74 my $s = "";
76 foreach my $t (@topics) {
77 my $topic_name = $t->get_topic_name();
78 my $topic_description = $t->get_topic_description();
80 my $topic_id = $t -> get_forum_topic_id();
81 my $submitter = CXGN::People::Person->new($dbh, $t->get_person_id());
82 my $submitter_name = $submitter->get_first_name()." ".$submitter->get_last_name();
83 my $submitter_id = $submitter->get_sp_person_id();
84 my $post_count = $t -> get_post_count();
85 my $most_recent_post_date = $t -> get_most_recent_post_date();
86 my $topic_person_id = $t->get_person_id();
87 my $user_id = $user->get_sp_person_id();
88 my $append = "";
90 my $display_topic_desc = $t->format_post_text($topic_description);
91 if (
92 ($user_id && $topic_person_id == $user_id)
93 || $user->get_user_type() eq "curator"
94 ) {
95 $append = qq {
96 <a href="add_topic.pl?action=edit&amp;topic_id=$topic_id">edit</a> |
97 <a href="add_topic.pl?action=delete&amp;topic_id=$topic_id">delete</a>
101 else {
102 $append = "&nbsp;";
104 $s .= qq {
105 <table summary="" border="0" class="topicbox">
106 <tr>
107 <td width="250"><a href="posts.pl?topic_id=$topic_id"><b>$topic_name</b></a></td>
108 <td width="250">started by <b><a href="/solpeople/personal-info.pl?sp_person_id=$submitter_id">$submitter_name</a></b></td>
109 <td width="80" align="center"><a href="posts.pl?topic_id=$topic_id"><b>$post_count</b> posts</a></td>
110 <td align="right" width="140">$most_recent_post_date</td>
111 </tr>
112 </table>
113 <table summary="" border="0" class="topicdescbox">
114 <tr>
115 <td width="640">$display_topic_desc</td><td width="88" align="right">$append</td>
117 </tr>
118 </table>
119 <table summary=""><tr><td></td></tr></table>
123 return $s;