4 use CXGN
::DB
::Connection
;
8 use CXGN
::People
::Forum
;
9 use CXGN
::Page
::FormattingHelpers
qw(page_title_html blue_section_html);
15 posts.pl - a web script that displays posts for a given topic.
20 topic_id - the id of the topic to be displayed. Required. Omitting it will display an error message.
21 post_text - if a post text is being supplied, the post_text is added to the topic.
22 post_parent_id - the id of the post that is the parent of this post. Currently not used in this interface.
24 Note: people have to be logged in to add posts. Users can browse posts without being logged in.
28 Lukas Mueller (lam87@cornell.edu)
34 my $page = CXGN
::Page
->new( "SGN Forum Main", "Lukas");
36 my $dbh = CXGN
::DB
::Connection
->new();
37 my $sp_person_id = CXGN
::Login
->new($dbh)->has_session();
39 my ($topic_id, $post_text, $post_parent_id) = $page -> get_encoded_arguments
("topic_id", "post_text", "post_parent_id");
43 $person = CXGN
::People
::Person
->new($dbh, $sp_person_id);
44 $sp_person_id = $person -> get_sp_person_id
();
47 # do some sanity checking
51 print "<p>No topic was specified. Please go back and try another topic.\n</p>";
56 # get some information about the topic
58 my $topic = CXGN
::People
::Forum
::Topic
->new($dbh, $topic_id);
59 if ($topic->get_topic_name() eq "") {
61 print "<p>The topic you are refering to does not exist or no longer exists. Please <a href=\"topics.pl\">go back</a> and try again!<br /><br />\n";
65 my $topic_start_person_id = $topic -> get_person_id
();
66 my $topic_start_person = CXGN
::People
::Person
->new($dbh, $topic_start_person_id);
68 # generate the post list
70 my $s = posts_list
($dbh, $sp_person_id, $topic_id, $page);
76 print page_title_html
("SOL Forum Topic: ".$topic->get_topic_name()."\n");
77 my $topic_started_by = "<br />This topic was started by <b><a href=\"/solpeople/personal-info.pl?sp_person_id=".
78 ($topic_start_person->get_sp_person_id)."\">".
79 ($topic_start_person->get_first_name()." ".$topic_start_person->get_last_name())."</a></b>.\n";
81 my $topic_name = $topic->get_topic_name();
82 my $topic_description = $topic->get_topic_description();
83 my $forum_toolbar = forum_toolbar
($topic_id, $sp_person_id);
84 if (!$topic_description) { $topic_description = "(topic description not available)"; }
87 print qq { <div
class="indentedcontent">$forum_toolbar</div
>\n };
88 print qq { <center
><table width
="710" cellpadding
="5" class="topicbox"><tr
><td
><b
>$topic_name</b><br /><br
/>$topic_description<br />$topic_started_by</td></tr
></table
> };
89 #print blue_section_html("Topic Description", $topic_description." ".$topic_started_by);
92 print qq { </center
>\n };
93 print "<div class=\"indentedcontent\">$forum_toolbar</div>\n";
99 my ($dbh,$sp_person_id,$topic_id,$page) = @_;
100 my $topic = CXGN
::People
::Forum
::Topic
-> new
($dbh, $topic_id);
101 my $user = CXGN
::People
::Person
->new($dbh, $sp_person_id);
103 my @posts = $topic -> get_all_posts
($topic_id);
106 $s .= qq { <table cellpadding
="5" cellspacing
="0" width
="720" border
="0" > };
109 $s .= "<tr><td>No user comments. <br /></td></tr>\n";
112 foreach my $p (@posts) {
113 my $post_subject = $p->get_subject();
114 my $post_person_id = $p -> get_person_id
();
115 my $post_person = CXGN
::People
::Person
-> new
($dbh, $post_person_id);
116 my $post_sp_person_id = $post_person -> get_sp_person_id
();
117 my $post_name = $post_person->get_first_name()." ".$post_person->get_last_name();
118 my $user_type = $post_person->get_user_type();
119 if($user_type and $user_type ne 'user')
121 $user_type=" ($user_type)";
127 my $post_text = $p -> get_post_text
();
128 my $post_date = $p -> get_formatted_post_time
();
129 my $remove_link = " ";
131 my $refering_url = $page->{request
}->uri()."?".$page->{request
}->args();
132 my $encoded_url = URI
::Escape
::uri_escape
($refering_url);
133 if (($sp_person_id && ($post_person_id == $sp_person_id)) || $user->get_user_type() eq "curator") {
134 $remove_link = "<a href=\"forum_post_delete.pl?post_id=".($p->get_forum_post_id())."&refering_page=$encoded_url\">Delete</a>\n";
137 $s .= qq { <tr
><td
><div
class="topicbox"><table cellspacing
="0" cellpadding
="5" border
="0" width
="100%"><tr
><td
>Posted by
<b
><a href
="/solpeople/personal-info.pl?sp_person_id=$post_sp_person_id">$post_name</a>$user_type</b
> on
$post_date </td><td class="right">$remove_link </td
></tr></table
></div
> };
138 $s .= qq { <table cellpadding
="5" width
="100%" class="topicdescbox"><tr
><td
>$post_text</td></tr
></table
> };
145 my $topic_id = shift;
146 my $topic = Topic
-> new
($topic_id);
148 my @posts = $topic -> get_all_posts
($topic_id);
150 my $previous_parent_id = -1;
151 my $previous_id = -1;
153 my $indent_size = 20;
158 return "Currently there are no posts under this topic. Please use the Add Posting link to add a post. Please note that you have to be logged in to post. [<a href=\"login.pl\">Login</a>]<br /><br />";
161 my $s = "<table border=\"0\" cellpadding=\"2\" cellspacing=\"2\">";
163 foreach my $p (@posts) {
164 my $subject = $p->get_subject();
165 if (!$subject) { $subject = "[No subject]"; }
166 my $post_text = $p->get_post_text();
168 my $person_id = $p->get_person_id();
169 my $post_time = $p->get_post_time();
170 my $parent_id = $p->get_parent_post_id();
171 my $forum_post_id = $p -> get_forum_post_id
();
173 my $person = CXGN
::People
::Person
->new($person_id);
174 my $name = $person->get_first_name()." ".$person->get_last_name();
176 #$indent = $p->get_post_level() * $indent_size;
178 for ( my $i=0; $i<@parent_ids; $i++) {
179 if ($parent_id == $parent_ids[$i]) {
181 $parent_ids[$i+1]=$forum_post_id;
187 push @parent_ids, $parent_id;
188 $indent = @parent_ids;
191 $post_time =~ s/(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/$2\-$3\-$1 $4\:$5\:$6/;
192 my $indent_pixels = $indent * $indent_size;
193 my $indent_chars = "";
194 for (my $i=0; $i<$indent; $i++) {
195 $indent_chars .="→";
198 my $respond_link = "Respond";
200 $respond_link = "<a href=\"add_post.pl?parent_post_id=$forum_post_id&topic_id=$topic_id\">Respond</a>";
202 #my $post_level = $p -> get_post_level();
203 $s .= "<tr><td colspan=\"4\" class=\"bgcolorselected\">From: <b>$name</b> </td><td colspan=3 class=\"bgcolorselected\" align=\"right\">Posted: $post_time</td></tr>\n";
204 $s .= "<tr><td><table cellpadding=\"5\"><tr><td width=\"$indent_pixels\">$indent_chars</td><td><b>$subject</b></td></tr></table></td><td colspan=\"4\" wrap=\"wrap\">$post_text</td></tr>";
205 $s .="<tr><td colspan=\"7\" align=\"right\">$respond_link</td></tr>";
206 $s .= "<tr><td><img src=\"/img/dot_clear.png\" height=\"2\" /></td><td colspan=\"5\"><img src=\"/img/dot_clear.png\" height=\"2\" /></td></tr>";
208 $s.="</table>\n<br /><br />";
215 my $person_id = shift; # not used... always display link, will go to login page if not logged in
216 my $s = "<a href=\"topics.pl\">View topics list</a> | \n";
218 $s .= "<a href=\"add_post.pl?topic_id=$topic_id\">Add post</a>";