Merge pull request #2830 from solgenomics/topic/fix_confirm_trait_property_deletion
[sgn.git] / cgi-bin / forum / topics.pl
blobdb1150acdeee806f0951683691bbe62d8bbc554a
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 if ($name) { $login_string = qq { <div class="row"><div class="panel panel-primary"><div class="panel-body"><div class="row"><div class="col-sm-10">You are logged in as <b>$name</b>.</div><div class="col-sm-2"><button class="btn btn-primary" onclick='location.href="add_topic.pl?action=new";'>Add topic</button>.</div></div></div></div></div> }; }
54 else { $login_string="<div class=\"row\"><div class=\"panel panel-primary\"><div class=\"panel-body\"><div class=\"row\"><div class=\"col-sm-10\"><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></div><div class=\"col-sm-2\"><button class=\"btn btn-primary\" onclick='location.href=\"/user/login?goto_url=/forum/topics.pl\";'>Login</button></div></div></div></div></div>"; }
56 print $login_string;
58 my $s = "";
59 $s = topics_list($dbh, $name, $user);
60 print $s;
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 <div class="row">
106 <div class="panel panel-default">
107 <div class="panel-heading">
108 <div class="row">
109 <div class="col-sm-6">
110 <a href="posts.pl?topic_id=$topic_id"><b>$topic_name</b></a>
111 </div>
112 <div class="col-sm-2">
113 Started by:<br/><b><a href="/solpeople/personal-info.pl?sp_person_id=$submitter_id">$submitter_name</a></b>
114 </div>
115 <div class="col-sm-2">
116 <a href="posts.pl?topic_id=$topic_id"><b>$post_count</b> Posts</a>
117 </div>
118 <div class="col-sm-2">
119 $most_recent_post_date
120 <br/>
121 $append
122 </div>
123 </div>
124 </div>
125 <div class="panel-body">
126 $display_topic_desc
128 </div>
129 </div>
130 </div>
135 return $s;