CMS  Version 3.9
topic_view.inc
Go to the documentation of this file.
1 <?php
7 /**************************************************************
8 
9  Copyright (c) 2010 Sonjara, Inc
10 
11  Permission is hereby granted, free of charge, to any person
12  obtaining a copy of this software and associated documentation
13  files (the "Software"), to deal in the Software without
14  restriction, including without limitation the rights to use,
15  copy, modify, merge, publish, distribute, sublicense, and/or sell
16  copies of the Software, and to permit persons to whom the
17  Software is furnished to do so, subject to the following
18  conditions:
19 
20  The above copyright notice and this permission notice shall be
21  included in all copies or substantial portions of the Software.
22 
23  Except as contained in this notice, the name(s) of the above
24  copyright holders shall not be used in advertising or otherwise
25  to promote the sale, use or other dealings in this Software
26  without prior written authorization.
27 
28  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
30  OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
32  HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
33  WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
34  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
35  OTHER DEALINGS IN THE SOFTWARE.
36 
37 *****************************************************************/
38 
40 {
41  var $forum;
42  var $topic;
44 
45  function ForumTopicView($topic, $id = "topic_view")
46  {
47  $this->topic = $topic;
48  $this->forum = $topic->Forum();
49  $this->messages = $this->topic->Messages("WHERE deleted=0 ORDER BY date_posted");
50 
51  $this->subscriptionView = new ForumSubscriptionHelper($this->forum, $this->topic);
52  }
53 
54  function writeScript()
55  {
56  return $this->subscriptionView->writeScript();
57  }
58 
59  function drawView()
60  {
61  global $user; // User Credentials from session
62 
63  $first = true;
64  $alt = false;
65 
66  $this->subscriptionView->drawLink();
67 
68  if (count($this->messages) > 0)
69  {
70  foreach($this->messages as $message)
71  {
72  $author = $message->Author();
73 
74  $userProfile = ForumManager::formatUserProfile($author);
75  $class = $alt ? "message alt" : "message"
76 ?>
77  <a name="message<?echo $message->message_id?>"></a>
78  <div id="message<?echo $message->message_id?>" class="<?echo $class?>">
79  <div class="title">
80 <?
81  if ($first && $user)
82  {
83 ?>
84  <button class="button" onclick="go('forum_message_form?forum_id=<?echo $this->topic->forum_id?>&topic_id=<? echo $this->topic->topic_id ?>&parent_id=<?echo $this->topic->message_id?>')"> Reply to this topic </button>
85 <?
86  }
87 ?>
88  <strong><?echo $message->title?></strong><br/>
89  <span class="small">Posted by <?echo $userProfile?> at <?echo $message->date_posted?></span>
90  </div>
91  <div class="message_content">
92  <?echo $message->message?>
93  </div>
94  <?
95  $attachments = $message->Attachments();
96  $userMgr = new UserManager();
97  $cl = $userMgr->getUserClass();
98  $u = new $cl;
99  $pk = $u->getPrimaryKey();
100 
101  if (count($attachments) > 0)
102  {
103  echo "<h4 style='margin-bottom: 4px'>Attachments</h4>";
104 
105  foreach($attachments as $attachment)
106  {
107  $icon = DocumentHandler::getDocIcon($attachment->filename);
108 
109  echo $this->formatAttachment($icon, $attachment);
110 
111  if ($author && $user && ($author->get($pk) == $user->get($pk)) || checkRole("admin,data"))
112  {
113 ?>
114 &nbsp;&nbsp;<a style="font-size: 10px" href="/action/forum/attachment_delete?forum_id=<?echo $this->topic->forum_id?>&message_id=<?echo $message->message_id?>&attachment_id=<?echo $attachment->attachment_id?>" onclick="return confirm('Are you sure you want to delete <?echo $attachment->filename?>?');">Delete this attachment</a>
115 <?
116  }
117 ?>
118  <br/>
119 <?
120  }
121  }
122 
123  $controls = array();
124  if ($user && $author->get($pk) == $user->get($pk) || checkRole("admin,data,moderator"))
125  {
126  $controls[] = "<a href=\"forum_message_form?forum_id={$this->topic->forum_id}&topic_id={$this->topic->topic_id}&message_id={$message->message_id}\">Edit</a>";
127  }
128 
129  if ($user && $author->get($pk) == $user->get($pk) || checkRole("admin,data,moderator"))
130  {
131  $controls[] = "<a href=\"/action/forum/message_delete?forum_id={$this->topic->forum_id}&topic_id={$this->topic->topic_id}&message_id={$message->message_id}\" onclick=\"return confirm('Are you sure you want to delete this message?');\">Delete</a>";
132  }
133 
134  if ($user)
135  {
136  $controls[] = "<a href=\"forum_message_form?forum_id={$this->topic->forum_id}&topic_id={$this->topic->topic_id}&parent_id={$message->message_id}\">Reply</a>";
137  }
138 
139 ?>
140  <div class="message_controls"><? echo implode("&nbsp;|&nbsp;", $controls);?></div>
141  </div>
142 <?
143  $first = false;
144  $alt = !$alt;
145  }
146 
147  $this->topic->updateExplicit("SET views=views+1");
148  }
149  else
150  {
151 ?>
152  <p><em>No messages have been posted for this topic.</em></p>
153 <?
154  }
155  }
156 
158  {
159  global $config;
160  $dir = $config["uploaddir"];
161 
162  $link = "<img src=\"{$icon}\" alt=\"Icon\" style=\"display:inline-block;vertical-align:middle\"/>&nbsp;";
163  $link .= "<a href='/action/attachment/download?attachment_id={$attachment->attachment_id}'>{$attachment->filename}
164  </a>&nbsp;({$attachment->file_size})\n";
165 
166  return $link;
167  }
168 }?>
& nbsp
Definition: index.inc:49
$helpTree style
Definition: tree.inc:46
$dir
Definition: delete.inc:44
if(! $attachment_id) $attachment
Definition: delete.inc:42
$icon
Definition: upload.inc:92
static formatUserProfile($u)
ForumTopicView($topic, $id="topic_view")
Definition: topic_view.inc:45
formatAttachment($icon, $attachment)
Definition: topic_view.inc:157
Provides the interface to the user model for the application.
global $user
$forumRequest to
global $config
Definition: import.inc:4
$message
Definition: mail_to.inc:49