![]() |
|---|
| [ Index ] |
Source Code Reference for V1.00 |
[Summary view] [Print] [Text view]
1 <?php /* $Id: view_messages.php 115 2008-03-21 17:20:33Z pedroix $ $URL: https://web2project.svn.sourceforge.net/svnroot/web2project/trunk/modules/forums/view_messages.php $ */ 2 if (!defined('W2P_BASE_DIR')) { 3 die('You should not access this file directly.'); 4 } 5 6 $AppUI->savePlace(); 7 $sort = w2PgetParam($_REQUEST, 'sort', 'asc'); 8 $viewtype = w2PgetParam($_REQUEST, 'viewtype', 'normal'); 9 $hideEmail = w2PgetConfig('hide_email_addresses', false); 10 11 $q = new DBQuery; 12 $q->addTable('forums'); 13 $q->addTable('forum_messages'); 14 $q->addQuery('forum_messages.*, contact_first_name, contact_last_name, contact_email, user_username, forum_moderated, visit_user'); 15 $q->addJoin('forum_visits', 'v', 'visit_user = ' . (int)$AppUI->user_id . ' AND visit_forum = ' . (int)$forum_id . ' AND visit_message = forum_messages.message_id'); 16 $q->addJoin('users', 'u', 'message_author = u.user_id', 'inner'); 17 $q->addJoin('contacts', 'con', 'contact_id = user_contact', 'inner'); 18 $q->addWhere('forum_id = message_forum AND (message_id = ' . (int)$message_id . ' OR message_parent = ' . (int)$message_id . ')'); 19 $q->addOrder('message_date ' . $sort); 20 21 $messages = $q->loadList(); 22 23 $crumbs = array(); 24 $crumbs['?m=forums'] = 'forums list'; 25 $crumbs['?m=forums&a=viewer&forum_id=' . $forum_id] = 'topics for this forum'; 26 $crumbs['?m=forums&a=view_pdf&forum_id=' . $forum_id . '&message_id=' . $message_id . '&sort=' . $sort . '&suppressHeaders=1'] = 'view PDF file'; 27 ?> 28 <script language="javascript"> 29 <?php 30 if ($viewtype != 'normal') { 31 ?> 32 function toggle(id) { 33 <?php 34 if ($viewtype == 'single') { 35 ?> 36 var elems = document.getElementsByTagName('div'); 37 for (var i=0, i_cmp=elems.length; i<i_cmp; i++) 38 if (elems[i].className == 'message') { 39 elems[i].style.display = 'none'; 40 } 41 document.getElementById(id).style.display = 'block'; 42 43 <?php 44 } else 45 if ($viewtype == 'short') { 46 ?> 47 vista = (document.getElementById(id).style.display == 'none') ? 'block' : 'none'; 48 document.getElementById(id).style.display = vista; 49 <?php 50 } 51 ?> 52 } 53 <?php 54 } 55 // security improvement: 56 // some javascript functions may not appear on client side in case of user not having write permissions 57 // else users would be able to arbitrarily run 'bad' functions 58 if ($canAuthor || $canEdit) { 59 ?> 60 function delIt(id) { 61 var form = document.messageForm; 62 if (confirm( '<?php echo $AppUI->_('forumsDelete'); ?>' )) { 63 form.del.value = 1; 64 form.message_id.value = id; 65 form.submit(); 66 } 67 } 68 <?php } ?> 69 </script> 70 <?php 71 $thispage = '?m=' . $m . '&a=viewer&forum_id=' . $forum_id . '&message_id=' . $message_id . '&sort=' . $sort; 72 // $thispage = $_PHP['self']; 73 74 ?> 75 <br /> 76 <?php 77 if (function_exists('styleRenderBoxTop')) { 78 echo styleRenderBoxTop(); 79 } 80 ?> 81 <form name="messageForm" method="POST" action="?m=forums&forum_id=<?php echo $forum_id; ?>"> 82 <input type="hidden" name="dosql" value="do_post_aed" /> 83 <input type="hidden" name="del" value="0" /> 84 <input type="hidden" name="message_id" value="0" /> 85 </form> 86 <table border="0" cellpadding="4" cellspacing="1" width="100%" class="std" align="center"> 87 88 <tr><td colspan="2"> 89 <table width="100%" cellspacing="1" cellpadding="2" border="0" align="center"> 90 <tr> 91 <td align="left" nowrap="nowrap"><?php echo breadCrumbs($crumbs); ?></td> 92 <td nowrap="nowrap"> 93 <form action="<?php echo $thispage; ?>" method="post"> 94 <?php echo $AppUI->_('View') ?>: 95 <input type="radio" name="viewtype" value="normal" <?php echo ($viewtype == 'normal') ? 'checked' : ''; ?> onclick="this.form.submit();" /><?php echo $AppUI->_('Normal') ?> 96 <input type="radio" name="viewtype" value="short" <?php echo ($viewtype == 'short') ? 'checked' : ''; ?> onclick="this.form.submit();" /><?php echo $AppUI->_('Collapsed') ?> 97 <input type="radio" name="viewtype" value="single" <?php echo ($viewtype == 'single') ? 'checked' : ''; ?> onclick="this.form.submit();" /><?php echo $AppUI->_('Single Message at a time') ?> 98 </form> 99 </td> 100 <td width="100%" align="right"> 101 <?php $sort = ($sort == 'asc') ? 'desc' : 'asc'; ?> 102 <input type="button" class="button" value="<?php echo $AppUI->_('Sort By Date') . ' (' . $AppUI->_($sort) . ')'; ?>" onclick="javascript:window.location='./index.php?m=forums&a=viewer&forum_id=<?php echo $forum_id; ?>&message_id=<?php echo $message_id; ?>&sort=<?php echo $sort; ?>'" /> 103 <?php if ($canAuthor) { ?> 104 <input type="button" class="button" value="<?php echo $AppUI->_('Post Reply'); ?>" onclick="javascript:window.location='./index.php?m=forums&a=viewer&forum_id=<?php echo $forum_id; ?>&message_parent=<?php echo $message_id; ?>&post_message=1';" /> 105 <input type="button" class="button" value="<?php echo $AppUI->_('New Topic'); ?>" onclick="javascript:window.location='./index.php?m=forums&a=viewer&forum_id=<?php echo $forum_id; ?>&message_id=0&post_message=1';" /> 106 <?php } ?> 107 </td> 108 </tr> 109 </table> 110 </td></tr> 111 112 <tr> 113 <?php 114 if ($viewtype != 'short') { 115 echo '<th nowrap>' . $AppUI->_('Author') . ':</th>'; 116 } 117 echo '<th width="' . (($viewtype == 'single') ? '60' : '100') . '%">' . $AppUI->_('Message') . ':</th>'; 118 ?> 119 </tr> 120 121 <?php 122 $x = false; 123 124 $date = new CDate(); 125 126 if ($viewtype == 'single') { 127 $s = ''; 128 $first = true; 129 } 130 131 $new_messages = array(); 132 133 foreach ($messages as $row) { 134 // Find the parent message - the topic. 135 if ($row['message_id'] == $message_id) 136 $topic = $row['message_title']; 137 138 $q = new DBQuery; 139 $q->addTable('forum_messages'); 140 $q->addTable('users'); 141 $q->addQuery('DISTINCT contact_email, contact_first_name, contact_last_name, user_username'); 142 $q->addJoin('contacts', 'con', 'contact_id = user_contact', 'inner'); 143 $q->addWhere('users.user_id = ' . (int)$row['message_editor']); 144 $editor = $q->loadList(); 145 146 $date = intval($row['message_date']) ? new CDate($row['message_date']) : null; 147 if ($viewtype != 'single') { 148 $s = ''; 149 } 150 $style = $x ? 'background-color:#eeeeee' : ''; 151 152 //!!! Different table building for the three different views 153 // To be cleaned up, and reuse common code at later stage. 154 if ($viewtype == 'normal') { 155 $s .= '<tr>'; 156 157 $s .= '<td valign="top" style="' . $style . '" nowrap="nowrap">'; 158 if (!$hideEmail) { 159 $s .= '<a href="mailto:' . $row['contact_email'] . '">'; 160 } 161 $s .= '<font size="2">' . $row['contact_first_name'] . ' ' . $row['contact_last_name'] . '</font>'; 162 if (!$hideEmail) { 163 $s .= '</a>'; 164 } 165 if (sizeof($editor) > 0) { 166 $s .= '<br/> <br/>' . $AppUI->_('last edited by'); 167 $s .= ':<br/>'; 168 if (!$hideEmail) { 169 $s .= '<a href="mailto:' . $editor[0]['contact_email'] . '">'; 170 } 171 $s .= '<font size="1">' . $editor[0]['contact_first_name'] . ' ' . $editor[0]['contact_last_name'] . '</font>'; 172 if (!$hideEmail) { 173 $s .= '</a>'; 174 } 175 } 176 if ($row['visit_user'] != $AppUI->user_id) { 177 $s .= '<br /> ' . w2PshowImage('images/icons/stock_new_small.png'); 178 $new_messages[] = $row['message_id']; 179 } 180 $s .= '</td>'; 181 $s .= '<td valign="top" style="' . $style . '">'; 182 $s .= '<font size="2"><strong>' . $row['message_title'] . '</strong><hr size=1>'; 183 $row['message_body'] = $bbparser->qparse($row['message_body']); 184 $s .= str_replace(chr(13), ' <br />', $row['message_body']); 185 $s .= '</font></td>'; 186 187 $s .= '</tr><tr>'; 188 189 $s .= '<td valign="top" style="' . $style . '" nowrap="nowrap">'; 190 $s .= '<img src="' . w2PfindImage('icons/posticon.gif', $m) . '" alt="date posted" border="0" width="14" height="11">' . $date->format($df . ' ' . $tf) . '</td>'; 191 $s .= '<td valign="top" align="right" style="' . $style . '">'; 192 193 //the following users are allowed to edit/delete a forum message: 1. the forum creator 2. a superuser with read-write access to 'all' 3. the message author 194 if ($canEdit || $AppUI->user_id == $row['forum_moderated'] || $AppUI->user_id == $row['message_author'] || $canAdminEdit) { 195 $s .= '<table cellspacing="0" cellpadding="0" border="0"><tr>'; 196 // edit message 197 $s .= '<td><a href="./index.php?m=forums&a=viewer&post_message=1&forum_id=' . $row['message_forum'] . '&message_parent=' . $row['message_parent'] . '&message_id=' . $row["message_id"] . '" title="' . $AppUI->_('Edit') . ' ' . $AppUI->_('Message') . '">'; 198 $s .= w2PshowImage('icons/stock_edit-16.png', '16', '16'); 199 $s .= '</td><td>'; 200 } 201 if ($canDelete || $AppUI->user_id == $row['forum_moderated'] || $AppUI->user_id == $row['message_author'] || $canAdminEdit) { 202 // delete message 203 $s .= '<a href="javascript:delIt(' . $row['message_id'] . ')" title="' . $AppUI->_('delete') . '">'; 204 $s .= w2PshowImage('icons/stock_delete-16.png', '16', '16'); 205 $s .= '</a>'; 206 $s .= '</td></tr></table>'; 207 208 } 209 $s .= '</td>'; 210 $s .= '</tr>'; 211 } else 212 if ($viewtype == 'short') { 213 $s .= "<tr>"; 214 215 $s .= '<td valign="top" style="' . $style . '" >'; 216 $s .= '<a href="mailto:' . $row['contact_email'] . '">'; 217 $s .= '<font size="2">' . $row['contact_first_name'] . ' ' . $row['contact_last_name'] . '</font></a>'; 218 $s .= ' (' . $date->format($df . ' ' . $tf) . ') '; 219 if (sizeof($editor) > 0) { 220 $s .= '<br/> <br/>' . $AppUI->_('last edited by'); 221 $s .= ':<br/><a href="mailto:' . $editor[0]['contact_email'] . '">'; 222 $s .= '<font size="1">' . $editor[0]['contact_first_name'] . ' ' . $editor[0]['contact_last_name'] . '</font></a>'; 223 } 224 $s .= '<a name="' . $row['message_id'] . '" href="javascript: void(0);" onclick="toggle(' . $row['message_id'] . ')">'; 225 $s .= '<span size="2"><strong>' . $row['message_title'] . '</strong></span></a>'; 226 $s .= '<div class="message" id="' . $row['message_id'] . '" style="display: none">'; 227 $row['message_body'] = $bbparser->qparse($row['message_body']); 228 $s .= str_replace(chr(13), " <br />", $row['message_body']); 229 $s .= '</div></td>'; 230 231 $s .= '</tr>'; 232 } else 233 if ($viewtype == 'single') { 234 $s .= '<tr>'; 235 236 $s .= '<td valign="top" style="' . $style . '">'; 237 $s .= $date->format($df . ' ' . $tf) . ' - '; 238 $s .= '<a href="mailto:' . $row['contact_email'] . '">'; 239 $s .= '<font size="2">' . $row['contact_first_name'] . ' ' . $row['contact_last_name'] . '</font></a>'; 240 $s .= '<br />'; 241 if (sizeof($editor) > 0) { 242 $s .= '<br/> <br/>' . $AppUI->_('last edited by'); 243 $s .= ':<br/><a href="mailto:' . $editor[0]['contact_email'] . '">'; 244 $s .= '<font size="1">' . $editor[0]['contact_first_name'] . ' ' . $editor[0]['contact_last_name'] . '</font></a>'; 245 } 246 $s .= '<a href="javascript: void(0);" onclick="toggle(' . $row['message_id'] . ')">'; 247 $s .= '<span size="2"><strong>' . $row['message_title'] . '</strong></span></a>'; 248 $side .= '<div class="message" id="' . $row['message_id'] . '" style="display: none">'; 249 $row['message_body'] = $bbparser->qparse($row['message_body']); 250 $side .= str_replace(chr(13), ' <br />', $row['message_body']); 251 $side .= '</div>'; 252 $s .= '</td>'; 253 if ($first) { 254 $s .= '<td rowspan="' . count($messages) . '" valign="top">'; 255 echo $s; 256 $s = ''; 257 $first = false; 258 } 259 $s .= '</tr>'; 260 } 261 262 if ($viewtype != 'single') { 263 echo $s; 264 } 265 $x = !$x; 266 267 } 268 if ($viewtype == 'single') { 269 echo $side . '</td>' . $s; 270 } 271 ?> 272 273 <tr><td colspan="2"> 274 <table border="0" cellpadding="2" cellspacing="1" width="100%"> 275 <tr> 276 <td align="left" nowrap="nowrap"><?php echo breadCrumbs($crumbs); ?></td> 277 <td width="100%" align="right"> 278 <input type="button" class="button" value="<?php echo $AppUI->_('Sort By Date') . ' (' . $AppUI->_($sort) . ')'; ?>" onclick="javascript:window.location='./index.php?m=forums&a=viewer&forum_id=<?php echo $forum_id; ?>&message_id=<?php echo $message_id; ?>&sort=<?php echo $sort; ?>'" /> 279 <?php if ($canAuthor) { ?> 280 <input type="button" class="button" value="<?php echo $AppUI->_('Post Reply'); ?>" onclick="javascript:window.location='./index.php?m=forums&a=viewer&forum_id=<?php echo $forum_id; ?>&message_parent=<?php echo $message_id; ?>&post_message=1';" /> 281 <input type="button" class="button" value="<?php echo $AppUI->_('New Topic'); ?>" onclick="javascript:window.location='./index.php?m=forums&a=viewer&forum_id=<?php echo $forum_id; ?>&message_id=0&post_message=1';" /> 282 <?php } ?> 283 </td> 284 </tr> 285 </table> 286 </td></tr> 287 </table> 288 <?php 289 // Now we need to update the forum visits with the new messages so they don't show again. 290 foreach ($new_messages as $msg_id) { 291 $q = new DBQuery; 292 $q->addTable('forum_visits'); 293 $q->addInsert('visit_user', $AppUI->user_id); 294 $q->addInsert('visit_forum', $forum_id); 295 $q->addInsert('visit_message', $msg_id); 296 $q->addInsert('visit_date', $date->getDate()); 297 $q->exec(); 298 $q->clear(); 299 } 300 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Fri Jan 9 03:00:02 2009 | Cross-referenced by PHPXref 0.7 |