00001 <?php
00002 if(!defined('__PRAGYAN_CMS'))
00003 {
00004 header($_SERVER['SERVER_PROTOCOL'].' 403 Forbidden');
00005 echo "<h1>403 Forbidden<h1><h4>You are not authorized to access the page.</h4>";
00006 echo '<hr/>'.$_SERVER['SERVER_SIGNATURE'];
00007 exit(1);
00008 }
00009
00016
00017
00018
00019
00020
00021
00022
00023 class forum implements module {
00024 private $userId;
00025 private $moduleComponentId;
00026 private $action;
00027
00028 public function getHtml($gotuid, $gotmoduleComponentId, $gotaction) {
00029 $this->userId = $gotuid;
00030 $this->moduleComponentId = $gotmoduleComponentId;
00031 $this->action = $gotaction;
00032
00033 if ($gotaction == 'view')
00034 return $this->actionView();
00035 if ($gotaction == 'post')
00036 return $this->actionPost();
00037 if ($gotaction == 'moderate')
00038 return $this->actionModerate();
00039 if ($gotaction == 'forumsettings')
00040 return $this->actionForumsettings();
00041
00042 }
00043
00054 public function getTotalPosts($userID) {
00055 $q1 = "SELECT * FROM `forum_threads` WHERE `forum_thread_user_id`=$userID AND `page_modulecomponentid`='$this->moduleComponentId'";
00056 $res1 = mysql_query($q1);
00057 $posts = mysql_num_rows($res1);
00058 $q2 = "SELECT * FROM `forum_posts` WHERE `forum_post_user_id`=$userID AND `page_modulecomponentid`='$this->moduleComponentId'";
00059 $res2 = mysql_query($q2);
00060 $posts += mysql_num_rows($res2);
00061 return $posts;
00062 }
00063
00064 public function getLastLogin($userId) {
00065 $query = "SELECT `user_lastlogin` FROM `" . MYSQL_DATABASE_PREFIX . "users` WHERE `user_id` = $userId";
00066 $result = mysql_query($query);
00067 $row = mysql_fetch_row($result);
00068 return $row[0];
00069 }
00075 function getRegDateFromUserID($userID) {
00076 if ($userID == 0)
00077 return 0;
00078 $query = 'SELECT `user_regdate` FROM `' . MYSQL_DATABASE_PREFIX . "users` WHERE `user_id` = '$userID'";
00079 $result = mysql_query($query);
00080 $row = mysql_fetch_row($result);
00081 return $row[0];
00082 }
00083 public function actionForumsettings(){
00084 $table_name = "forum_threads";
00085 $table1_name = "forum_posts";
00086 $table2_name = "forum_module";
00087 $forumHtml ='';
00088 if(isset($_POST['mod_permi']))
00089 {
00090 if($_POST['forum_desc'])
00091 {
00092 $forum_description = addslashes(htmlspecialchars($_POST['forum_desc']));
00093 if($_POST['del_post'] == "allow")
00094 $del_post=1;
00095 else
00096 $del_post=0;
00097 if($_POST['like_post'] == "allow")
00098 $like_post=1;
00099 else
00100 $like_post=0;
00101 }
00102 else
00103 {
00104 $forum_description = "";
00105 }
00106 if($_POST['mod_permi']=="public")
00107 {
00108 $access_level = 0;
00109 $approve = 1;
00110 $q1 = "UPDATE `$table_name` SET `forum_post_approve`='$approve' WHERE `page_modulecomponentid`='$this->moduleComponentId'";
00111 $res1 = mysql_query($q1);
00112 $q2 = "UPDATE `$table1_name` SET `forum_post_approve`='$approve' WHERE `page_modulecomponentid`='$this->moduleComponentId'";
00113 $res2 = mysql_query($q2);
00114 }
00115 else
00116 {$access_level = 1;}
00117 $pageId=getPageIdFromModuleComponentId("forum",$this->moduleComponentId);
00118 $q = "UPDATE `$table2_name` SET `forum_moderated`='$access_level', " .
00119 "`forum_description`='$forum_description',`allow_delete_posts`='$del_post',`allow_like_posts`='$like_post' WHERE `page_modulecomponentid`='$this->moduleComponentId' LIMIT 1";
00120 $res = mysql_query($q) or displayerror(mysql_error() . "Update failed L:113");
00121 displayinfo("Forum settings updated successfully!");
00122 }
00123 $query = "SELECT * FROM `$table2_name` WHERE `page_modulecomponentid`='$this->moduleComponentId' LIMIT 1";
00124 $result = mysql_query($query);
00125 $rows = mysql_fetch_array($result);
00126 $forum_description = stripslashes($rows['forum_description']);
00127 $forum_moderated = $rows['forum_moderated'];
00128 $allow_delete_posts = $rows['allow_delete_posts'];
00129 $allow_like_posts = $rows['allow_like_posts'];
00130 $moderatedselected = "";
00131 $publicselected = "";
00132 $allowselected = "";
00133 $dontallowselected = "";
00134 $lallowselected = "";
00135 $ldontallowselected = "";
00136
00137 if($forum_moderated==1) $moderatedselected = 'selected="selected"';
00138 else $publicselected = 'selected="selected"';
00139 if($allow_delete_posts==1) $allowselected = 'selected="selected"';
00140 else $dontallowselected = 'selected="selected"';
00141 if($allow_like_posts==1) $lallowselected = 'selected="selected"';
00142 else $ldontallowselected = 'selected="selected"';
00143 global $ICONS;
00144 $forumHtml .=<<<PRE
00145 <fieldset>
00146 <legend>{$ICONS['Forum Settings']['small']}Forum Settings</legend>
00147 <form method="post" name="forum_access" action="./+forumsettings">
00148 <table><tr><td>
00149 Choose Forum Access Level </td><td><select name="mod_permi" style="width:100px;">
00150 <option value="moderated" $moderatedselected >Moderated</option>
00151 <option value="public" $publicselected >Public</option>
00152 </select></td>
00153 </tr>
00154 <tr><td>
00155 Allow users to Delete their posts </td><td><select name="del_post" style="width:100px;">
00156 <option value="allow" $allowselected >Allow</option>
00157 <option value="dontallow" $dontallowselected >Don't Allow</option>
00158 </select></td>
00159 </tr>
00160 <tr><td>
00161 Allow users to Like posts </td><td><select name="like_post" style="width:100px;">
00162 <option value="allow" $lallowselected >Allow</option>
00163 <option value="dontallow" $ldontallowselected >Don't Allow</option>
00164 </select></td>
00165 </tr>
00166 <tr><td>
00167 Enter New Forum Description </td><td><textarea name="forum_desc" cols="50" rows="5" class="textbox" >$forum_description</textarea></td>
00168 </tr></table>
00169 <input type="submit" value="submit">
00170 </form>
00171 </fieldset>
00172 PRE;
00173 return $forumHtml;
00174 }
00175
00176 public function actionModerate() {
00177 global $urlRequestRoot, $moduleFolder, $cmsFolder,$templateFolder,$sourceFolder;
00178 $temp = $urlRequestRoot . "/" . $cmsFolder . "/" . $moduleFolder . "/forum/images";
00179 require_once ("$sourceFolder/$moduleFolder/forum/bbeditor.php");
00180 require_once ("$sourceFolder/$moduleFolder/forum/bbparser.php");
00181 $js=$urlRequestRoot."/".$cmsFolder."/".$moduleFolder."/forum/images/jscript.js";
00182 $userId = $this->userId;
00183 $table_name = "forum_threads";
00184 $table1_name = "forum_posts";
00185 $table2_name = "forum_module";
00186 $templatesImageFolder = "$urlRequestRoot/$cmsFolder/$templateFolder/".TEMPLATE;
00187 if(isset($_GET['subaction'])){
00188 if ($_GET['subaction'] == "approve" || $_GET['subaction'] == "disapprove") {
00189 if ($_GET['subaction'] == "approve")
00190 $approval = 1;
00191 else
00192 $approval = 0;
00193 if (!isset ($_GET['post_id'])) {
00194 $thread_id = escape($_GET['thread_id']);
00195 $query = "UPDATE `$table_name` SET `forum_post_approve`=$approval WHERE `forum_thread_id`=$thread_id AND `page_modulecomponentid`='$this->moduleComponentId' LIMIT 1";
00196 $result = mysql_query($query);
00197 } else {
00198 $thread_id = escape($_GET['forum_id']);
00199 $post_id = escape($_GET['post_id']);
00200 $query = "UPDATE `$table1_name` SET `forum_post_approve`=$approval WHERE `forum_thread_id`=$thread_id AND `forum_post_id`=$post_id AND `page_modulecomponentid`='$this->moduleComponentId' LIMIT 1";
00201 $result = mysql_query($query);
00202 }
00203 if (!$result)
00204 displayerror("Could not perform the desired action(approve/disapprove)!");
00205 }
00206 if ($_GET['subaction'] == "delete") {
00207 if (!isset ($_GET['post_id'])) {
00208 $thread_id = escape($_GET['thread_id']);
00209 $query = "DELETE FROM `$table_name` WHERE `forum_thread_id`=$thread_id AND `page_modulecomponentid`='$this->moduleComponentId' LIMIT 1";
00210 $result = mysql_query($query);
00211 $query1 = "DELETE FROM `forum_posts` WHERE `forum_thread_id`=$thread_id AND `page_modulecomponentid`='$this->moduleComponentId'";
00212 $result1 = mysql_query($query1);
00213 $query2 = "DELETE FROM `forum_like` WHERE `forum_thread_id`=$thread_id AND `page_modulecomponentid`='$this->moduleComponentId'";
00214 $result2 = mysql_query($query2);
00215 if (!$result)
00216 displayerror("Could not perform the delete operation!");
00217 else
00218 displayinfo("Successfully deleted the Thread!");
00219 }
00220 else {
00221 $thread_id = escape($_GET['forum_id']);
00222 $post_id = escape($_GET['post_id']);
00223 $query1 = "DELETE FROM `forum_posts` WHERE `forum_thread_id`=$thread_id AND `forum_post_id`=$post_id AND `page_modulecomponentid`='$this->moduleComponentId' LIMIT 1";
00224 $result1 = mysql_query($query1);
00225 $query1 = "DELETE FROM `forum_like` WHERE `forum_thread_id`=$thread_id AND `forum_post_id`=$post_id AND `page_modulecomponentid`='$this->moduleComponentId' LIMIT 1";
00226 $result1 = mysql_query($query1);
00227 if (!$result1)
00228 displayerror("Could not perform the delete operation!");
00229 else
00230 displayinfo("Successfully deleted the Post!");
00231 }
00232 }
00233 }
00234 if (!isset ($_GET['forum_id'])) {
00235 $query = "SELECT * FROM `$table_name` WHERE `page_modulecomponentid`='" . $this->moduleComponentId . "" .
00236 "' AND `forum_thread_category`='general' ORDER BY `forum_thread_lastpost_date` DESC";
00237 $result = mysql_query($query);
00238 $query1 = "SELECT * FROM `$table_name` WHERE `page_modulecomponentid`='" . $this->moduleComponentId . "" .
00239 "' AND `forum_thread_category`='sticky' ORDER BY `forum_thread_datetime` DESC";
00240 $result1 = mysql_query($query1);
00241 $num_rows = mysql_num_rows($result);
00242 $num_rows1 = mysql_num_rows($result1);
00243 global $ICONS;
00244 if ($result) {
00245
00246 $action = "+post&subaction=create_thread";
00247 $moderate =<<<PRE
00248 <link rel="stylesheet" href="$temp/styles.css" type="text/css" />
00249 <fieldset><legend>{$ICONS['Forum Moderate']['small']}Moderate Forum</legend>
00250 <p align="left"><a href="$action" style="color:#0F5B96"><img title="New Thread" src="$temp/newthread.gif" /></a></p>
00251 <table width="100%" id="forum" align="center" cellpadding="3" cellspacing="1">
00252 <tr>
00253 <td class="forumTableHeader" colspan="4"><strong>Subject</strong><br /></td>
00254 <td class="forumTableHeader"><strong>Views</strong></td>
00255 <td class="forumTableHeader"><strong>Replies</strong></td>
00256 <td class="forumTableHeader"><strong>Last Post</strong></td>
00257 </tr>
00258 <tr>
00259 PRE;
00260 if ($result1 && $num_rows1 > 0) {
00261 for ($i = 1; $i <= $num_rows1; $i++) {
00262 $rows = mysql_fetch_array($result1);
00263 $query2 = "SELECT `forum_post_id` FROM `$table1_name` WHERE `forum_thread_id`='" . $rows['forum_thread_id'] . "' AND `forum_post_approve`='1' AND `page_modulecomponentid`='$this->moduleComponentId'";
00264 $result2 = mysql_query($query2);
00265 $reply_count = mysql_num_rows($result2);
00266 $topic = ucfirst(parseubb(parsesmileys(htmlspecialchars($rows['forum_thread_topic']))));
00267 $name = ucfirst(getUserName($rows['forum_thread_user_id']));
00268 $last_post_author = ucfirst(getUserName($rows['forum_thread_last_post_userid']));
00269 if ($rows['forum_post_approve'] == 0)
00270 {
00271 $text = "Approve";
00272 $img = "like.gif";
00273 }
00274 else
00275 {
00276 $text = "Disapprove";
00277 $img = "unlike.gif";
00278 }
00279 $subaction = strtolower($text);
00280 $moderate .=<<<PRE
00281 <tr>
00282 <td class="forumThreadRow" width="3%"><a href="+moderate&subaction=delete&thread_id=$rows[forum_thread_id]">
00283 <img src="$temp/delete1.gif" /></a></td>
00284 <td class="forumThreadRow" width="3%"><a href="+moderate&subaction=$subaction&thread_id=$rows[forum_thread_id]">
00285 <img src="$temp/$img" /></a></td>
00286 <td class="forumThreadRow" width="3%"><img src="$temp/sticky.gif" /></td>
00287 <td class="forumThreadRow" width="41%"><a href="+moderate&forum_id=$rows[forum_thread_id]"> $topic </a><br /><small>by <b> $name </a></b>
00288 on $rows[forum_thread_datetime] </small></td>
00289 <td class="forumThreadRow" width="10%"> $rows[forum_thread_viewcount] </td>
00290 <td class="forumThreadRow" width="10%"> $reply_count </td>
00291 <td class="forumThreadRow" width="30%"><small>by <b> $last_post_author </a></b> on $rows[forum_thread_lastpost_date] </small></td>
00292 </tr>
00293 PRE;
00294
00295 }
00296 }
00297 if ($num_rows < 1)
00298 $moderate .= "<tr><td colspan=\"5\" class='forumTableRow'><strong>No Post</strong></td></tr>";
00299 for ($i = 1; $i <= $num_rows; $i++) {
00300 $rows = mysql_fetch_array($result);
00301 if($userId>0 && ($_SESSION['last_to_last_login_datetime']<$rows['forum_thread_lastpost_date']))
00302 $img_src = "thread_new.gif";
00303 else
00304 $img_src = "thread_hot.gif";
00305
00306 $query1 = "SELECT `forum_post_id` FROM `$table1_name` WHERE `forum_thread_id`='" . $rows['forum_thread_id'] . "' AND `forum_post_approve`='1'";
00307 $result1 = mysql_query($query1);
00308 $reply_count = mysql_num_rows($result1);
00309 $topic = ucfirst(parseubb(parsesmileys($rows['forum_thread_topic'])));
00310 $name = ucfirst(getUserName($rows['forum_thread_user_id']));
00311 $last_post_author = ucfirst(getUserName($rows['forum_thread_last_post_userid']));
00312 if ($rows['forum_post_approve'] == 0)
00313 {
00314 $text = "Approve";
00315 $img = "like.gif";
00316 }
00317 else
00318 {
00319 $text = "Disapprove";
00320 $img = "unlike.gif";
00321 }
00322 $subaction = strtolower($text);
00323 $moderate .=<<<PRE
00324 <tr>
00325 <td class="forumThreadRow" width="3%"><a href="+moderate&subaction=delete&thread_id=$rows[forum_thread_id]"><img src="$temp/delete1.gif" />
00326 </a></td>
00327 <td class="forumThreadRow" width="3%"><a href="+moderate&subaction=$subaction&thread_id=$rows[forum_thread_id]"><img src="$temp/$img" />
00328 </a></td>
00329 <td class="forumThreadRow" width="3%"><img src="$temp/$img_src" /></td>
00330 <td class="forumThreadRow" width="41%"><a href="+moderate&forum_id=$rows[forum_thread_id]"> $topic </a><br /><small>by <b> $name </a></b>
00331 on $rows[forum_thread_datetime] </small></td>
00332 <td class="forumThreadRow" width="10%"> $rows[forum_thread_viewcount] </td>
00333 <td class="forumThreadRow" width="10%"> $reply_count </td>
00334 <td class="forumThreadRow" width="30%"><small>by <b> $last_post_author </a></b> on $rows[forum_thread_lastpost_date] </small></td>
00335 </tr>
00336 PRE;
00337 }
00338 $moderate .= '</table><br />
00339 <p align="left"><img alt="" src="' . $temp . '/like.gif" align=left> - To Approve Threads.<br /><br />' .
00340 '<img alt="" src="' . $temp . '/unlike.gif" align=left> - To Disapprove Threads.<br /><br />' .
00341 '<img alt="" src="' . $temp . '/sticky.gif" align=left> - Sticky Threads.<br /><br />' .
00342 '<img alt="" src="' . $temp . '/thread_new.gif" align=left>' .
00343 ' - Topic with new posts since last visit.<br /><br />' .
00344 '<img alt="" src="' . $temp . '/thread_hot.gif" align=left>' .
00345 ' - Topic with no new posts since last visit. </p><hr /></fieldset>';
00346 }
00347 return $moderate;
00348 } else {
00349 $q = "SELECT * FROM `forum_module` WHERE `page_modulecomponentid`=$this->moduleComponentId LIMIT 1";
00350 $r = mysql_query($q) or displayerror(mysql_error() . "Moderate failed L:343");
00351 $r = mysql_fetch_array($r);
00352 $forum_id = escape($_GET['forum_id']);
00353 $sql = "SELECT * FROM `$table_name` WHERE `forum_thread_id`=$forum_id AND `page_modulecomponentid`='$this->moduleComponentId' LIMIT 1";
00354 $result1 = mysql_query($sql);
00355 $rows = mysql_fetch_array($result1);
00356 $forum_topic = ucfirst(parseubb(parsesmileys($rows['forum_thread_topic'])));
00357 $forum_detail = parseubb(parsesmileys($rows['forum_detail']));
00358 $name = ucfirst(getUserName($rows['forum_thread_user_id']));
00359 $posts = $this->getTotalPosts($rows['forum_thread_user_id']);
00360 $reg_date = $this->getRegDateFromUserID($rows['forum_thread_user_id']);
00361 $count='0';
00362 if ($rows['forum_post_approve'] == 0)
00363 {
00364 $text = "Approve";
00365 $img = "like.gif";
00366 }
00367 else
00368 {
00369 $text = "Disapprove";
00370 $img = "unlike.gif";
00371 }
00372 $subaction = strtolower($text);
00373 $postpart =<<<PRE
00374 <link rel="stylesheet" href="$temp/styles.css" type="text/css" />
00375 <p align="left"><a href="+post&subaction=post_reply&thread_id=$forum_id"><img title="Reply" src="$temp/reply.gif" /></a>
00376 <a href="+post&subaction=create_thread"><img title="New Thread" src="$temp/newthread.gif" /></a><a href="+view"><img title="Go Back to Forum" src="$temp/go_back.gif" /></a>
00377 <table id="forum" width="100%" cellpadding="3" cellspacing="1" bordercolor="1" >
00378 <tr>
00379 <td class="forumThreadRow" rowspan="2"><a href="+moderate&subaction=delete&thread_id=$rows[forum_thread_id]">
00380 <img src="$temp/delete1.gif" /></a></td>
00381 <td class="forumThreadRow" rowspan="2"><a href="+moderate&subaction=$subaction&thread_id=$rows[forum_thread_id]">
00382 <img src="$temp/$img" /></a></td>
00383 <td class="forumThreadRow"><strong>$forum_topic</strong><br /><img src="$temp/post_icon.gif" />
00384 <small">by $name on $rows[forum_thread_datetime] </small></td>
00385 <td class="forumThreadRow" rowspan="2"><strong>$name <br />
00386 PRE;
00387 if ($userId > 0 && $name != "Anonymous") {
00388 if ($rows['forum_thread_user_id'] == $userId)
00389 $lastLogin = $_SESSION['last_to_last_login_datetime'];
00390 else
00391 $lastLogin = $this->getLastLogin($rows['forum_thread_user_id']);
00392 $moderator=getPermissions($rows['forum_thread_user_id'], getPageIdFromModuleComponentId("forum",$this->moduleComponentId), "moderate");
00393 if($moderator)$postpart .= "Moderator";else
00394 $postpart .= "Member";
00395 $content = 'content'.$count;
00396 $text = 'text'.$count;
00397 $postpart .= <<<PRE
00398 </strong><br /><br />
00399 <script type="text/javascript" languauge="javascript" src="$js"></script>
00400 <a id="$text" href="javascript:toggle('$content','$text');" >Show Details</a><br />
00401 <div id="$content" style="display: none;"><small>Posts: $posts <br />Joined: $reg_date <br />Last Visit:
00402 $lastLogin </small></div>
00403 PRE;
00404 }
00405 $postpart .=<<<PRE
00406 </td>
00407 </tr>
00408 <tr>
00409 <td class="forumThreadRow"><br /> $forum_detail </td>
00410 </tr><tr><td class="blank" colspan="2"></td></tr>
00411 PRE;
00412
00413 $sql2 = "SELECT * FROM `$table1_name` WHERE `forum_thread_id`=$forum_id AND `page_modulecomponentid`='$this->moduleComponentId' ORDER BY forum_post_id ASC";
00414 $result2 = mysql_query($sql2);
00415 while ($rows = mysql_fetch_array($result2)) {
00416 $count = $count + 1;
00417 $post_title = ucfirst(parseubb(parsesmileys($rows['forum_post_title'])));
00418 $post_content = (parseubb(parsesmileys($rows['forum_post_content'])));
00419 $name = ucfirst(getUserName($rows['forum_post_user_id']));
00420 $posts = $this->getTotalPosts($rows['forum_post_user_id']);
00421 $reg_date = $this->getRegDateFromUserID($rows['forum_post_user_id']);
00422 if ($rows['forum_post_approve'] == 0)
00423 {
00424 $text = "Approve";
00425 $img = "like.gif";
00426 }
00427 else
00428 {
00429 $text = "Disapprove";
00430 $img = "unlike.gif";
00431 }
00432 $subaction = strtolower($text);
00433 $postpart .=<<<PRE
00434
00435 <td class="forumThreadRow" rowspan="2" width="3%">
00436 <a href="+moderate&subaction=delete&forum_id=$rows[forum_thread_id]&post_id=$rows[forum_post_id]"><img src="$temp/delete1.gif" /></a></td>
00437 <td class="forumThreadRow" rowspan="2" width="3%">
00438 <a href="+moderate&subaction=$subaction&forum_id=$rows[forum_thread_id]&post_id=$rows[forum_post_id]"><img src="$temp/$img" /></a></td>
00439 <td class="forumThreadRow"><strong>Re:- $post_title </strong><br /><img src="$temp/post_icon.gif" />
00440 <small">by $name on $rows[forum_post_datetime] <small>
00441 PRE;
00442 if($r['allow_like_posts'] == 1){
00443 $likequery = "SELECT * from `forum_like` WHERE `forum_thread_id`=$rows[forum_thread_id] AND `forum_post_id`=".$rows['forum_post_id']." AND `like_status`='1' AND `page_modulecomponentid`='$this->moduleComponentId' ";
00444 $likeres = mysql_query($likequery) or displayerror(mysql_error() . "Moderate failed L:438");;
00445 $likeres = mysql_num_rows($likeres);
00446 $dlikequery = "SELECT * from `forum_like` WHERE `forum_thread_id`=$rows[forum_thread_id] AND `forum_post_id`=".$rows['forum_post_id']." AND `like_status`='0' AND `page_modulecomponentid`='$this->moduleComponentId' ";
00447 $dlikeres = mysql_query($dlikequery) or displayerror(mysql_error() . "Moderate failed L:441");
00448 $dlikeres = mysql_num_rows($dlikeres);
00449 $postpart .= '<br /><small> ' . $likeres . ' people like this post</small>    ';
00450 $postpart .= '<small> ' . $dlikeres . ' people dislike this post</small><br />';
00451 }
00452 $postpart .= '</td><td class="forumThreadRow" rowspan="2" width="20%"><strong>$name<br />';
00453
00454 if ($userId > 0 && $name != "Anonymous") {
00455 if ($rows['forum_post_user_id'] == $userId)
00456 $lastLogin = $_SESSION['last_to_last_login_datetime'];
00457 else
00458 $lastLogin = $this->getLastLogin($rows['forum_post_user_id']);
00459 $moderator=getPermissions($rows['forum_post_user_id'], getPageIdFromModuleComponentId("forum",$this->moduleComponentId), "moderate");
00460 if($moderator)$postpart .= "Moderator";else
00461 $postpart .= "Member";
00462 $content = 'content'.$count;
00463 $text = 'text'.$count;
00464 $postpart .= <<<PRE
00465 </strong><br /><br />
00466 <script type="text/javascript" languauge="javascript" src="$js"></script>
00467 <a id="$text" href="javascript:toggle('$content','$text');" >Show Details</a><br />
00468 <div id="$content" style="display: none;"><small>Posts: $posts <br />Joined: $reg_date <br />Last Visit:
00469 $lastLogin </small></div>
00470 PRE;
00471 }
00472 $postpart .=<<<PRE
00473 </td>
00474 </tr>
00475 <tr>
00476 <td class="forumThreadRow"><br />$post_content</td>
00477 </tr><tr><td class="blank" colspan="2"></td></tr>
00478 PRE;
00479 }
00480 $postpart .='</table>';
00481 $query3 = "SELECT `forum_thread_viewcount` FROM `$table_name` WHERE forum_thread_id='$forum_id' AND `page_modulecomponentid`='$this->moduleComponentId' ";
00482 $result3 = mysql_query($query3);
00483 $rows = mysql_fetch_array($result3);
00484 $view = $rows['forum_thread_viewcount'];
00485
00486 $addview = $view +1;
00487 $query5 = "UPDATE `$table_name` SET `forum_thread_viewcount`='$addview' WHERE forum_thread_id='$forum_id' AND `page_modulecomponentid`='$this->moduleComponentId' LIMIT 1";
00488 $result5 = mysql_query($query5);
00489 $postpart .= '<br>
00490 <p align="left"><a href="+post&subaction=post_reply&thread_id='.$forum_id.'"><img title="Reply" src="'.$temp.'/reply.gif" />' .
00491 '</a> <a href="+post&subaction=create_thread"><img title="New Thread" src="'.$temp.'/newthread.gif" /></a></p>';
00492 return $postpart;
00493 }
00494 }
00495 public function actionPost() {
00496 $userId = $this->userId;
00497 $i = 0;
00498 $action = '';
00499 foreach ($_GET as $var => $val) {
00500 if ($i == 1)
00501 $action .= "&" . $var . "=" . $val;
00502 if ($val == 'post') {
00503 $action .= "+" . $val;
00504 $i = 1;
00505 }
00506 }
00507 $table_name = "forum_threads";
00508 $table1_name = "forum_posts";
00509 $table2_name = "forum_module";
00510 if(isset($_GET['subaction']))
00511 $subaction = escape($_GET['subaction']);
00512 global $urlRequestRoot, $moduleFolder, $cmsFolder,$templateFolder,$sourceFolder;
00513 $temp = $urlRequestRoot . "/" . $cmsFolder . "/" . $moduleFolder . "/forum/images";
00514 require_once ("$sourceFolder/$moduleFolder/forum/bbeditor.php");
00515 require_once ("$sourceFolder/$moduleFolder/forum/bbparser.php");
00516 $q = "SELECT * FROM `$table2_name` WHERE `page_modulecomponentid`=$this->moduleComponentId LIMIT 1";
00517 $res = mysql_query($q);
00518 $rows = mysql_fetch_array($res);
00519 $access_level = $rows['forum_moderated'];
00520 if ($access_level) {
00521 $approve = 0;
00522 $access = "moderated";
00523 } else {
00524 $approve = 1;
00525 $access = "public";
00526 }
00527 $moderator=getPermissions($this->userId, getPageIdFromModuleComponentId("forum",$this->moduleComponentId), "moderate");
00528 if($moderator) {
00529 $approve = 1;
00530 }
00531 if (isset ($_POST['post'])) {
00532 if (($subaction == "create_thread") ||( $subaction == "")) {
00533
00534 if (!$_POST['subject'] || !$_POST['message']) {
00535 $editor = bbeditor();
00536 return "You did not fill all the fields!" . $editor;
00537 } else {
00538 $datetime = date("Y-m-d H:i:s");
00539 $message = $_POST['message'];
00540 $subject = addslashes(htmlspecialchars($_POST['subject']));
00541 $message = addslashes(htmlspecialchars(parsenewline(nl2br($message))));
00542 if (isset ($_POST['sticky'])&&($moderator))
00543 $category = "sticky";
00544 else
00545 $category = "general";
00546 $query="SELECT MAX(`forum_thread_id`) AS MAX FROM `forum_threads`";
00547 $result=mysql_query($query);
00548 $row1 = mysql_fetch_assoc($result);
00549 $threadid = $row1['MAX'] + 1;
00550
00551 $sql = "INSERT INTO `$table_name`(`forum_thread_id` ,`page_modulecomponentid` ,`forum_thread_category` ,`forum_access_status` ," .
00552 "`forum_thread_topic` ,`forum_detail` ,`forum_thread_user_id` ,`forum_thread_datetime` ,`forum_post_approve` ," .
00553 "`forum_thread_viewcount` ,`forum_thread_last_post_userid` ,`forum_thread_lastpost_date`)" .
00554 " VALUES('$threadid', '$this->moduleComponentId', '$category', '$access', '$subject', '$message'," .
00555 " '$userId', '$datetime', '$approve', '1','$userId', '$datetime')";
00556 $result = mysql_query($sql) or displayerror(mysql_error() . "Create New Thread failed L:550");
00557 if ($result) {
00558 $sql1 = "SELECT * FROM `$table2_name` WHERE `page_modulecomponentid`=$this->moduleComponentId LIMIT 1";
00559 $result1 = mysql_query($sql1);
00560 $rows1 = mysql_fetch_array($result1);
00561 $total_thread_count = $rows['total_thread_count'];
00562
00563 $net_thread_count = $total_thread_count +1;
00564 $sql2 = "UPDATE `$table2_name` SET `total_thread_count`='$net_thread_count', `last_post_userid`='$userId'," .
00565 " `last_post_datetime`='$datetime' WHERE `page_modulecomponentid`=$this->moduleComponentId LIMIT 1";
00566 $result2 = mysql_query($sql2);
00567 if(($access=="moderated")&& (!$moderator))
00568 displayinfo("You have successfully created a new thread.It will be published after getting the moderator's approval." .
00569 "<br />");
00570 else
00571 displayinfo("You have successfully created a new thread.<br />");
00572 } else {
00573 displayerror("Sorry! Your thread could not be created now. Please try again later!");
00574 }
00575 return $this->actionView();
00576 }
00577 } else
00578 if ($subaction == "post_reply") {
00579 if (!$_POST['subject'] || !$_POST['message']) {
00580 $editor = bbeditor();
00581 return "You did not fill all the fields!" . $editor;
00582 } else {
00583 $forum_id = escape($_GET['thread_id']);
00584 $datetime = date("Y-m-d H:i:s");
00585 $message = $_POST['message'];
00586 $subject = addslashes(htmlspecialchars($_POST['subject']));
00587 $message = addslashes(htmlspecialchars(parsenewline(nl2br($message))));
00588 $sql7 = "SELECT MAX(`forum_post_id`) AS Maxpost_id FROM `$table1_name` WHERE `forum_thread_id` = '$forum_id'";
00589 $res = mysql_query($sql7);
00590 $rows = mysql_fetch_array($res);
00591
00592 if ($rows) {
00593 $Max_id = $rows['Maxpost_id'] + 1;
00594 } else {
00595 $Max_id = 1;
00596 }
00597 $sql = "INSERT INTO `$table1_name`( `page_modulecomponentid` , `forum_thread_id` , `forum_post_id` , `forum_post_user_id` , `forum_post_title` , " .
00598 "`forum_post_content` , `forum_post_datetime` , `forum_post_approve` ) VALUES( '$this->moduleComponentId','$forum_id', '$Max_id'," .
00599 " '$userId', '$subject', '$message', '$datetime', '$approve')";
00600 $result = mysql_query($sql) or displayerror(mysql_error() . "Post failed L:594");
00601 if ($result) {
00602 $sql1 = "SELECT * FROM `$table_name` WHERE `page_modulecomponentid`=$this->moduleComponentId AND `forum_thread_id`=$forum_id" .
00603 " LIMIT 1";
00604 $result1 = mysql_query($sql1);
00605 $rows1 = mysql_fetch_array($result1);
00606 $sql2 = "UPDATE `$table_name` SET `forum_thread_last_post_userid`='$userId', " .
00607 "`forum_thread_lastpost_date`='$datetime' " .
00608 "WHERE `page_modulecomponentid`=$this->moduleComponentId AND `forum_thread_id`='$forum_id' LIMIT 1";
00609 $result2 = mysql_query($sql2);
00610 $sql3 = "SELECT * FROM `$table2_name` WHERE `page_modulecomponentid`=$this->moduleComponentId LIMIT 1";
00611 $result3 = mysql_query($sql3);
00612 $rows3 = mysql_fetch_array($result3);
00613 $sql4 = "UPDATE `$table2_name` SET `last_post_userid`='$userId', " .
00614 "`last_post_datetime`='$datetime' WHERE `page_modulecomponentid`=$this->moduleComponentId LIMIT 1";
00615 $result4 = mysql_query($sql4);
00616 if(($rows1['forum_access_status']=="moderated")&& (!$moderator))
00617 displayinfo("You have successfully posted your reply.It will be published after getting the moderator's approval." .
00618 "<br />");
00619 else
00620 displayinfo("You have successfully posted your reply!");
00621 } else {
00622 displayerror("Sorry! Your reply could not be posted now. Please try again later!");
00623 }
00624 {
00625 $forumHtml = '';
00626 $thread_id = $forum_id;
00627 $sql = "SELECT * FROM `$table_name` WHERE `forum_thread_id`=$thread_id AND `page_modulecomponentid`='$this->moduleComponentId' LIMIT 1";
00628 $result1 = mysql_query($sql);
00629 $rows = mysql_fetch_array($result1);
00630 $threadUserId = $rows['forum_thread_user_id'];
00631 $forum_topic = parseubb(parsesmileys($rows['forum_thread_topic']));
00632 $forum_detail = parseubb(parsesmileys($rows['forum_detail']));
00633 $name = getUserName($rows['forum_thread_user_id']);
00634 $posts = $this->getTotalPosts($rows['forum_thread_user_id']);
00635 $reg_date = $this->getRegDateFromUserID($rows['forum_thread_user_id']);
00636 $forumHtml = $this->forumHtml($rows,'threadHead');
00637 if ($rows['forum_post_approve'] == 1)
00638 $forumHtml .= $this->forumHtml($rows,'threadMain');
00639 $sql2 = "SELECT * FROM `$table1_name` WHERE `forum_thread_id`=$thread_id AND `forum_post_approve` = 1 AND `page_modulecomponentid`='$this->moduleComponentId' ORDER BY `forum_post_id` ASC";
00640 $result2 = mysql_query($sql2);
00641 while ($rows = mysql_fetch_array($result2))
00642 $forumHtml .= $this->forumHtml($rows,'threadMain',1);
00643 $sql3 = "SELECT `forum_thread_viewcount` FROM `$table_name` WHERE `forum_thread_id`='$thread_id' AND `page_modulecomponentid`='$this->moduleComponentId'";
00644 $result3 = mysql_query($sql3);
00645 $rows = mysql_fetch_array($result3);
00646 $view = $rows['forum_thread_viewcount'];
00647
00648 $addview = $view +1;
00649 $sql5 = "UPDATE `$table_name` SET `forum_thread_viewcount`='$addview' WHERE forum_thread_id='$thread_id' AND `page_modulecomponentid`='$this->moduleComponentId' LIMIT 1";
00650 $result5 = mysql_query($sql5);
00651 $forumHtml .= '</table> ';
00652 return $forumHtml;
00653 }
00654 }
00655 }
00656 } else
00657 if (isset ($_POST['preview'])) {
00658
00659 $message = escape($_POST['message']);
00660 $subject = addslashes(htmlspecialchars($_POST['subject']));
00661 $text = $message;
00662 $message = nl2br($message);
00663 $message = parseubb(parsesmileys(addslashes(htmlspecialchars(parsenewline($message)))));
00664 $editor = bbeditor($action, $subject, $text);
00665 return "<b>Subject :</b> " . $subject . "<br><b>Message :</b><br> " . $message . $editor;
00666 } else
00667 if (isset ($_GET['thread_id'])) {
00668 $editor = bbeditor($action);
00669 return $editor;
00670 } else {
00671 $editor = bbeditor($action);
00672 return $editor;
00673 }
00674 }
00675 public function actionView() {
00676 $userId = $this->userId;
00677 global $urlRequestRoot, $moduleFolder, $cmsFolder,$templateFolder,$sourceFolder;
00678 $templatesImageFolder = "$urlRequestRoot/$cmsFolder/$templateFolder/".TEMPLATE;
00679 $temp = $urlRequestRoot . "/" . $cmsFolder . "/" . $moduleFolder . "/forum/images";
00680 $table_name = "forum_threads";
00681 $table1_name = "forum_posts";
00682 $forumHtml = <<<PRE
00683 <link rel="stylesheet" href="$temp/styles.css" type="text/css" />
00684 PRE;
00685 $forum_lastVisit = $this->forumLastVisit();
00686 $moderator=getPermissions($this->userId, getPageIdFromModuleComponentId("forum",$this->moduleComponentId), "moderate");
00687
00688 $table_visit = "forum_visits";
00689 $query_checkvisit = "SELECT * from `$table_visit` WHERE `user_id`=$userId AND `page_modulecomponentid`=$this->moduleComponentId";
00690 $result_checkvisit = mysql_query($query_checkvisit);
00691 $check_visits = mysql_fetch_array($result_checkvisit);
00692 if(mysql_num_rows($result_checkvisit)<1) {
00693 $forum_lastviewed = date("Y-m-d H:i:s");
00694 }
00695 else {
00696 $forum_lastviewed = $check_visits['last_visit'];
00697 }
00698
00699 $time_visit = date("Y-m-d H:i:s");
00700 $query_visit = "SELECT * FROM `$table_visit` WHERE `user_id`=$userId AND `page_modulecomponentid`=$this->moduleComponentId";
00701 $result_visit = mysql_query($query_visit);
00702 $num_rows_visit = mysql_num_rows($result_visit);
00703 if($num_rows_visit<1) {
00704 $query_setvisit = "INSERT INTO `$table_visit`(`page_modulecomponentid`,`user_id`,`last_visit`) VALUES($this->moduleComponentId,$userId,'$time_visit')";
00705 }
00706 else {
00707 $query_setvisit = "UPDATE `$table_visit` SET `last_visit`='$time_visit' WHERE `user_id`=$userId AND `page_modulecomponentid`=$this->moduleComponentId";
00708 }
00709 mysql_query($query_setvisit);
00710
00711 require_once ("$sourceFolder/$moduleFolder/forum/bbeditor.php");
00712 require_once ("$sourceFolder/$moduleFolder/forum/bbparser.php");
00713 if (!isset ($_GET['thread_id'])) {
00714 if ((isset($_GET['subaction']))&&($_GET['subaction'] == "delete_thread")) {
00715 $thread_id = escape($_GET['forum_id']);
00716 $query = "DELETE FROM `$table_name` WHERE `forum_thread_id`=$thread_id AND `page_modulecomponentid`='$this->moduleComponentId' LIMIT 1";
00717 $res = mysql_query($query);
00718 $query1 = "DELETE FROM `$table1_name` WHERE `forum_thread_id`=$thread_id AND `page_modulecomponentid`='$this->moduleComponentId'";
00719 $res1 = mysql_query($query1);
00720 if (!res || !res1)
00721 displayerror("Could not perform the delete operation on the selected thread!");
00722 }
00723 if($userId>0 )
00724 {
00725 $new_mt='0';
00726 $new_mp='0';
00727 $new_p='0';
00728 $new_t='0';
00729 if($moderator)
00730 {
00731 $qum_0 = "SELECT * FROM `$table_name` WHERE `page_modulecomponentid`=" . $this->moduleComponentId ." AND `forum_post_approve` = 0";
00732 $resm_0 = mysql_query($qum_0);
00733 $numm_0 = mysql_num_rows($resm_0);
00734 for ($j = 1; $j <= $numm_0; $j++) {
00735 $rows = mysql_fetch_array($resm_0,MYSQL_ASSOC);
00736 if($forum_lastVisit<$rows['forum_thread_datetime'])
00737 $new_mt = $new_mt + '1';
00738 }
00739 $qum_1 = "SELECT * FROM `$table1_name` WHERE `page_modulecomponentid`=" . $this->moduleComponentId ." AND `forum_post_approve` = 0";
00740 $resm_1 = mysql_query($qum_1);
00741 $numm_1 = mysql_num_rows($resm_1);
00742 for ($j = 1; $j <= $numm_1; $j++) {
00743 $rows = mysql_fetch_array($resm_1,MYSQL_ASSOC);
00744 if($forum_lastVisit<$rows['forum_post_datetime'])
00745 $new_mp = $new_mp + '1';
00746 }
00747 if($new_mt){
00748 $show_t = $new_mt. " new threads to be moderated since your last visit";
00749 displayinfo($show_t);}
00750 if($new_mp) {
00751 $show_p = $new_mp. " new posts to be moderated since your last visit";
00752 displayinfo($show_p);}
00753 }
00754 $qu_0 = "SELECT * FROM `$table_name` WHERE `page_modulecomponentid`=" . $this->moduleComponentId ." AND `forum_post_approve` = 1 AND `forum_thread_user_id` !=". $this->userId;
00755 $res_0 = mysql_query($qu_0);
00756 $num_0 = mysql_num_rows($res_0);
00757 for ($j = 1; $j <= $num_0; $j++) {
00758 $rows = mysql_fetch_array($res_0,MYSQL_ASSOC);
00759 if($forum_lastVisit<$rows['forum_thread_datetime'])
00760 $new_t = $new_t + '1';
00761 }
00762 $qu_1 = "SELECT * FROM `$table1_name` WHERE `page_modulecomponentid`=" . $this->moduleComponentId ." AND `forum_post_approve` = 1 AND `forum_post_user_id` !=". $this->userId;
00763 $res_1 = mysql_query($qu_1) or die(mysql_error());
00764 $num_1 = mysql_num_rows($res_1);
00765 for ($j = 1; $j <= $num_1; $j++) {
00766 $rows = mysql_fetch_array($res_1,MYSQL_ASSOC);
00767 if($forum_lastVisit<$rows['forum_post_datetime'])
00768 $new_p = $new_p + '1';
00769 }
00770 if($new_t && $new_t!=$new_mt){
00771 $show_t = $new_t. " new threads since your last visit";
00772 displayinfo($show_t);}
00773 if($new_p && $new_p!=$new_mp) {
00774 $show_p = $new_p. " new posts since your last visit";
00775 displayinfo($show_p);}
00776 }
00777 $query_d = "SELECT `forum_description` FROM `forum_module` WHERE `page_modulecomponentid`='" . $this->moduleComponentId ."' LIMIT 1";
00778 $result_d = mysql_query($query_d) or die(mysql_error());
00779 $result_d = mysql_fetch_array($result_d);
00780 $query = "SELECT * FROM `$table_name` WHERE `page_modulecomponentid`='" . $this->moduleComponentId . "' AND " .
00781 "`forum_thread_category`='general' ORDER BY `forum_thread_lastpost_date` DESC";
00782 $result = mysql_query($query) or displayerror(mysql_error() . "View of General Threads failed L:776");
00783 $query1 = "SELECT * FROM `$table_name` WHERE `page_modulecomponentid`='" . $this->moduleComponentId . "' AND " .
00784 "`forum_thread_category`='sticky' ORDER BY `forum_thread_datetime` DESC";
00785 $result1 = mysql_query($query1)or displayerror(mysql_error() . "View of sticjy Threads failed L:779");
00786 $num_rows1 = mysql_num_rows($result1);
00787 if ($result) {
00788 $action = "+post&subaction=create_thread";
00789 $num_rows = mysql_num_rows($result);
00790 $forum_header =<<<PRE
00791 <p align="left"><a href="$action"><img title="New Thread" src="$temp/newthread.gif" /></a></p>
00792 <div style="text-align:center;"><b>" $result_d[0] "</b></div>
00793 <table width="100%" border="1" align="center" cellpadding="4" cellspacing="2" id="forum">
00794 <tr class="TableHeader">
00795 <td class="forumTableHeader" colspan="2"><strong>TOPICS</strong><br /></td>
00796 <td class="forumTableHeader"> <strong>VIEWS</strong></td>
00797 <td class="forumTableHeader"><strong>REPLIES</strong></td>
00798 <td class="forumTableHeader"><strong>LAST POST</strong></td>
00799 </tr>
00800 PRE;
00801 $forumHtml .= $forum_header;
00802 if ($result1 && $num_rows1 > 0) {
00803 for ($j = 1; $j <= $num_rows1; $j++) {
00804 $rows = mysql_fetch_array($result1,MYSQL_ASSOC);
00805 $query2 = "SELECT `forum_post_id` FROM `$table1_name` WHERE `forum_thread_id`='" . $rows['forum_thread_id'] . "' AND `forum_post_approve`='1' AND `page_modulecomponentid`='$this->moduleComponentId'";
00806 $result2 = mysql_query($query2);
00807 $reply_count = mysql_num_rows($result2);
00808 $topic = parseubb(parsesmileys(stripslashes($rows['forum_thread_topic'])));
00809 $name = getUserName($rows['forum_thread_user_id']);
00810 $last_post_author = getUserName($rows['forum_thread_last_post_userid']);
00811 if ($rows['forum_post_approve'] == 1) {
00812 $forumHtml .= $this->forumHtml($rows,'threadRow');
00813 }
00814 }
00815 }
00816 if ($num_rows < 1)
00817 $forum_header .= "<tr><td colspan=\"5\" class='forumTableRow'><strong>No Post</strong></td></tr>";
00818 for ($i = 1; $i <= $num_rows; $i++) {
00819 $rows = mysql_fetch_array($result);
00820 $query1 = "SELECT `forum_post_id` FROM `$table1_name` WHERE `forum_thread_id`='" . $rows['forum_thread_id'] . "' AND `forum_post_approve`='1' AND `page_modulecomponentid`='$this->moduleComponentId'";
00821 $result1 = mysql_query($query1);
00822 $reply_count = mysql_num_rows($result1);
00823 $topic = parseubb(parsesmileys($rows['forum_thread_topic']));
00824 $name = getUserName($rows['forum_thread_user_id']);
00825 $last_post_author = getUserName($rows['forum_thread_last_post_userid']);
00826 if ($rows['forum_post_approve'] == 1) {
00827 $forumHtml .= $this->forumHtml($rows,'threadRow');
00828 }
00829 }
00830 $forumHtml .= '<tr></tr></table><br />';
00831 }
00832 }
00833 else {
00834 $thread_id = escape($_GET['thread_id']);
00835 if(isset($_GET['subaction'])){
00836 if ($_GET['subaction'] == "delete_post") {
00837 $post_id = escape($_GET['post_id']);
00838 $query = "DELETE FROM `$table1_name` WHERE `forum_thread_id`=$thread_id AND `forum_post_id`=$post_id AND `page_modulecomponentid`='$this->moduleComponentId' LIMIT 1";
00839 $res = mysql_query($query);
00840 if ( !$res )
00841 displayerror("Could not perform the delete operation on the selected post!");
00842 $query = "DELETE FROM `forum_like` WHERE `forum_thread_id`=$thread_id AND `forum_post_id`=$post_id AND `page_modulecomponentid`='$this->moduleComponentId'";
00843 $res = mysql_query($query);
00844 }
00845 if ($_GET['subaction'] == "like_post") {
00846 $post_id = escape($_GET['post_id']);
00847 $query = "SELECT * FROM `forum_like` WHERE `forum_thread_id`=$thread_id AND `forum_post_id`=$post_id AND `page_modulecomponentid`='$this->moduleComponentId' ";
00848 $res = mysql_query($query);
00849 if(mysql_num_rows($res)==0) {
00850 $query = "INSERT INTO`forum_like` (`page_modulecomponentid`,`forum_thread_id`,`forum_post_id`,`forum_like_user_id`,`like_status`) VALUES ($this->moduleComponentId,$thread_id,$post_id,$userId,'1')";
00851 $res = mysql_query($query);
00852 if ( !$res )
00853 displayerror("Could not perform the like operation on the selected post!");
00854 }
00855 }
00856 if ($_GET['subaction'] == "dislike_post") {
00857 $post_id = escape($_GET['post_id']);
00858 $query = "SELECT * FROM `forum_like` WHERE `forum_thread_id`=$thread_id AND `forum_post_id`=$post_id AND `page_modulecomponentid`='$this->moduleComponentId' ";
00859 $res = mysql_query($query);
00860 if(mysql_num_rows($res)==0) {
00861 $query = "INSERT INTO`forum_like` (`page_modulecomponentid`,`forum_thread_id`,`forum_post_id`,`forum_like_user_id`,`like_status`) VALUES ($this->moduleComponentId,$thread_id,$post_id,$userId,'0')";
00862 $res = mysql_query($query);
00863 if ( !$res )
00864 displayerror("Could not perform the dislike operation on the selected post!");
00865 }
00866 }
00867 }
00868 $sql = "SELECT * FROM `$table_name` WHERE `forum_thread_id`=$thread_id AND `page_modulecomponentid`='$this->moduleComponentId' LIMIT 1";
00869 $result1 = mysql_query($sql);
00870 $rows = mysql_fetch_array($result1);
00871 $threadUserId = $rows['forum_thread_user_id'];
00872 $forum_topic = parseubb(parsesmileys($rows['forum_thread_topic']));
00873 $forum_detail = parseubb(parsesmileys($rows['forum_detail']));
00874 $name = getUserName($rows['forum_thread_user_id']);
00875 $posts = $this->getTotalPosts($rows['forum_thread_user_id']);
00876 $reg_date = $this->getRegDateFromUserID($rows['forum_thread_user_id']);
00877 $forumHtml = $this->forumHtml($rows,'threadHead');
00878 $count=0;
00879 if ($rows['forum_post_approve'] == 1)
00880 $forumHtml .= $this->forumHtml($rows,'threadMain',0,0);
00881 $sql2 = "SELECT * FROM `$table1_name` WHERE `forum_thread_id`=$thread_id AND `forum_post_approve` = 1 AND `page_modulecomponentid`='$this->moduleComponentId' ORDER BY `forum_post_id` ASC";
00882 $result2 = mysql_query($sql2);
00883 while ($rows1 = mysql_fetch_array($result2)) {
00884 $count = $count + 1;
00885 $forumHtml .= $this->forumHtml($rows1,'threadMain',1,$count);
00886 }
00887 $sql3 = "SELECT `forum_thread_viewcount` FROM `$table_name` WHERE `forum_thread_id`='$thread_id' AND `page_modulecomponentid`='$this->moduleComponentId'";
00888 $result3 = mysql_query($sql3);
00889 $rows2 = mysql_fetch_array($result3);
00890 $view = $rows2['forum_thread_viewcount'];
00891
00892 $addview = $view +1;
00893 $sql5 = "UPDATE `$table_name` SET `forum_thread_viewcount`='$addview' WHERE forum_thread_id='$thread_id' AND `page_modulecomponentid`='$this->moduleComponentId' LIMIT 1";
00894 $result5 = mysql_query($sql5);
00895 $forumHtml .= '</table><br />';
00896 if($rows['forum_thread_category']!='sticky'){
00897 $forumHtml .= '<p align="left"><a href="+post&subaction=post_reply&thread_id='.$thread_id.'"><img alt="Reply" title="Reply" src="'.$temp.'/reply.gif" /></a></p>';
00898 }
00899 }
00900 $forumHtml .= '<p align="left"><img alt="Sticky" title="Sticky" src="' . $temp . '/sticky.gif" align=left> - Sticky Threads.<br /><br />' .
00901 '<img alt="New Posts" title="New Posts" src="' . $temp . '/thread_new.gif" align=left> - Topic with new posts since last visit.' .
00902 '<br /><br /><img alt="No new posts" title="No new Posts" src="' . $temp . '/thread_hot.gif" align=left>' .
00903 ' - Topic with no new posts since last visit. </p>';
00904 return $forumHtml;
00905 }
00906 private function forumHtml($data, $type='thread', $post=0,$count=0) {
00907 global $urlRequestRoot, $moduleFolder, $cmsFolder,$templateFolder,$sourceFolder,$userId;
00908 require_once ("$sourceFolder/$moduleFolder/forum/bbeditor.php");
00909 require_once ("$sourceFolder/$moduleFolder/forum/bbparser.php");
00910 $js=$urlRequestRoot."/".$cmsFolder."/".$moduleFolder."/forum/images/jscript.js";
00911 $table_name = "forum_threads";
00912 $table1_name = "forum_posts";
00913 $templatesImageFolder = "$urlRequestRoot/$cmsFolder/$templateFolder/".TEMPLATE;
00914 $temp = $urlRequestRoot . "/" . $cmsFolder . "/" . $moduleFolder . "/forum/images";
00915 if(isset($_GET['thread_id']))
00916 $thread_id = escape($_GET['thread_id']);
00917 $forumHtml = '';
00918 $forum_threads = '';
00919 $rows = $data;
00920 $action = "+post&subaction=create_thread";
00921 $forum_lastVisit = $this->forumLastVisit();
00922 if($type == 'threadRow')
00923 {
00924 if($userId>0 && ($forum_lastVisit<$rows['forum_thread_lastpost_date']))
00925 {
00926 $img_src = "thread_new.gif";
00927 }
00928 else
00929 {
00930 $img_src = "thread_hot.gif";
00931 }
00932 $topic = ucfirst((parseubb(parsesmileys($rows['forum_thread_topic']))));
00933 $name = ucfirst(getUserName($rows['forum_thread_user_id']));
00934 $last_post_author = ucfirst(getUserName($rows['forum_thread_last_post_userid']));
00935 if($rows['forum_thread_category']=='sticky') {
00936 $img_src = 'sticky.gif';
00937 }
00938 $query1 = "SELECT `forum_post_id` FROM `$table1_name` WHERE `forum_thread_id`='" . $rows['forum_thread_id'] . "' AND `forum_post_approve`='1' AND `page_modulecomponentid`='$this->moduleComponentId' ";
00939 $result1 = mysql_query($query1);
00940 $reply_count = mysql_num_rows($result1);
00941 $forum_threads .=<<<PRE1
00942 <tr class="forumThreadRow">
00943 <td class="forumThreadRow forumTableIcon" width="3%"><img src="$temp/$img_src" /></td>
00944 <td class="forumThreadRow" width="51%"><a class="threadRow" href="+view&thread_id=$rows[forum_thread_id]"> $topic </a><br /><small>by <b> $name </b>
00945 on $rows[forum_thread_datetime] </small></td>
00946 <td class="forumThreadRow" width="8%" style="text-align:center;"> $rows[forum_thread_viewcount] </td>
00947 <td class="forumThreadRow" width="8%" style="text-align:center;"> $reply_count </td>
00948 <td class="forumThreadRow" width="30%"><small>by <b> $last_post_author </a></b> on $rows[forum_thread_lastpost_date] </small></td>
00949 </tr>
00950 PRE1;
00951 $forumHtml .= $forum_threads;
00952 }
00953 if($type == 'threadHead'){
00954 $thread_Header = '<p align="left">';
00955 if($rows['forum_thread_category']!='sticky') {
00956 $thread_Header .= '<a href="+post&subaction=post_reply&thread_id='.$thread_id.'"><img alt="Reply" title="Reply" src="'.$temp.'/reply.gif" /></a>  ';
00957 }
00958 $thread_Header .=<<<PRE
00959 <link rel="stylesheet" href="$temp/styles.css" type="text/css" />
00960  <a href="+post&subaction=create_thread"><img title="New Thread" src="$temp/newthread.gif" /></a> <a
00961 href="+view"> <img title="Go Back to Forum" src="$temp/go_back.gif" /></a>
00962 <table width="100%" cellpadding="4" cellspacing="2" id="forum" >
00963 PRE;
00964 $forumHtml = $thread_Header;
00965 }
00966 if($type == 'threadMain') {
00967 $q = "SELECT * FROM `forum_module` WHERE `page_modulecomponentid`=$this->moduleComponentId LIMIT 1";
00968 $r = mysql_query($q) or displayerror(mysql_error() . "View of Thread failed L:962");
00969 $r = mysql_fetch_array($r);
00970 if($post == 0){
00971 $topic = censor_words(ucfirst(parseubb(parsesmileys($rows['forum_thread_topic']))));
00972 $name = ucfirst(getUserName($rows['forum_thread_user_id']));
00973 $last_post_author = ucfirst(getUserName($rows['forum_thread_last_post_userid']));
00974 $threadUserId = $rows['forum_thread_user_id'];
00975 $detail = censor_words(parseubb(parsesmileys($rows['forum_detail'])));
00976 $posts = $this->getTotalPosts($rows['forum_thread_user_id']);
00977 $reg_date = $this->getRegDateFromUserID($rows['forum_thread_user_id']);
00978 $postTime = $rows['forum_thread_datetime'];
00979 }
00980 if($post == 1){
00981 $postUserId = $rows['forum_post_user_id'];
00982 $topic = censor_words(ucfirst(parseubb(parsesmileys($rows['forum_post_title']))));
00983 $detail = censor_words(parseubb(parsesmileys($rows['forum_post_content'])));
00984 $name = ucfirst(getUserName($rows['forum_post_user_id']));
00985 $posts = $this->getTotalPosts($rows['forum_post_user_id']);
00986 $reg_date = $this->getRegDateFromUserID($rows['forum_post_user_id']);
00987 $postTime = $rows['forum_post_datetime'];
00988 $threadUserId = $postUserId;
00989 }
00990 $datetime = date("Y-m-d H:i:s")-$postTime;
00991 $threadHtml = '<tr class="ThreadHeadRow" cellspacing="10">
00992 <td class="forumThreadRow"><strong> ' . $topic . ' </strong><br />' .
00993 '<img src="' . $temp . '/post_icon.gif" /><small>   by ' . $name . ' </a>' .
00994 ' on ' . $postTime . ' </small>';
00995 if($post == 1)
00996 if($r['allow_like_posts'] == 1){
00997 $likequery = "SELECT * from `forum_like` WHERE `forum_thread_id`=$thread_id AND `forum_post_id`=".$rows['forum_post_id']." AND `like_status`='1' AND `page_modulecomponentid`='$this->moduleComponentId' ";
00998 $likeres = mysql_query($likequery);
00999 $likeres = mysql_num_rows($likeres);
01000 $dlikequery = "SELECT * from `forum_like` WHERE `forum_thread_id`=$thread_id AND `forum_post_id`=".$rows['forum_post_id']." AND `like_status`='0' AND `page_modulecomponentid`='$this->moduleComponentId' ";
01001 $dlikeres = mysql_query($dlikequery);
01002 $dlikeres = mysql_num_rows($dlikeres);
01003 $threadHtml .= '<br /><small> ' . $likeres . ' people like this post</small>    ';
01004 $threadHtml .= '<small> ' . $dlikeres . ' people dislike this post</small><br />';
01005 }
01006 $threadHtml .='</td>
01007 <td class="forumThreadRow" width="25%" rowspan="2"><strong> ' . $name . ' </a><br />';
01008 if ($threadUserId > 0) {
01009 if ($threadUserId == $userId)
01010 $lastLogin = $_SESSION['last_to_last_login_datetime'];
01011 else
01012 $lastLogin = $this->getLastLogin($threadUserId);
01013 $moderator=getPermissions($threadUserId, getPageIdFromModuleComponentId("forum",$this->moduleComponentId), "moderate");
01014 if($moderator)$threadHtml .= "Moderator";else
01015 $threadHtml .= "Member";
01016 $content = 'content'.$count;
01017 $text = 'text'.$count;
01018 $threadHtml .= <<<PRE
01019 </strong><br /><br />
01020 <script type="text/javascript" languauge="javascript" src="$js"></script>
01021 <a id="$text" href="javascript:toggle('$content','$text');" >Show Details</a><br />
01022 <div id="$content" style="display: none;"><small>Posts: $posts <br />Joined: $reg_date <br />Last Visit:
01023 $lastLogin </small></div>
01024 PRE;
01025 if($post==1 && $userId>0 && ( ($r['allow_delete_posts'] == 1) ||($r['allow_like_posts']==1))) {
01026
01027 if($r['allow_delete_posts'] == 1){
01028 if ($post==1 && $userId > 0 && $userId == $rows['forum_post_user_id'])
01029
01030 {
01031 $threadHtml .= '<br /><a href="+view&subaction=delete_post&thread_id=' . $thread_id . '&post_id=' . $rows['forum_post_id'] . '">' .
01032 '<img src="'.$temp.'/delete1.gif"></a></span>';
01033 }
01034 }
01035 if($r['allow_like_posts'] == 1) {
01036 if ($userId > 0 && $post == 1)
01037 {
01038 $postId=$rows['forum_post_id'];
01039 $qu = " SELECT * FROM `forum_like` WHERE `forum_like_user_id` = $userId AND`forum_thread_id` = $thread_id AND `forum_post_id` = $postId AND `page_modulecomponentid`=$this->moduleComponentId AND `like_status`='1'";
01040 $re = mysql_query($qu) ;
01041 $qu1 = " SELECT * FROM `forum_like` WHERE `forum_like_user_id` = $userId AND`forum_thread_id` = $thread_id AND `forum_post_id` = $postId AND `page_modulecomponentid`=$this->moduleComponentId AND `like_status`='0'";
01042 $re1 = mysql_query($qu1);
01043 if(mysql_num_rows($re)==0 && mysql_num_rows($re1)==0)
01044 {
01045 $threadHtml .= ' <a href="+view&subaction=like_post&thread_id=' . $thread_id . '&post_id=' . $rows['forum_post_id'] . '">' .
01046 ' <img title="Like this post" src="'.$temp.'/like.gif"></a></span>';
01047 $threadHtml .= ' <a href="+view&subaction=dislike_post&thread_id=' . $thread_id . '&post_id=' . $rows['forum_post_id'] . '">' .
01048 ' <img title="Dislike this post" src="'.$temp.'/unlike.gif"></a></span>';
01049 }
01050 else {
01051 if(mysql_num_rows($re)>0)
01052 $threadHtml .= '<br /> You Like this post';
01053 else
01054 $threadHtml .= '<br /> You Dislike this post';
01055 }
01056 }
01057 }
01058
01059 }
01060 }
01061 $threadHtml .=<<<PRE
01062 </td>
01063 </tr>
01064 <tr>
01065 <td class="forumThreadRow"> <br />$detail </td>
01066 </tr>
01067 PRE;
01068 $threadHtml .= '<tr><td class="blank" colspan="2"></td></tr>';
01069
01070
01071 $forumHtml .= $threadHtml;
01072 }
01073
01074 return $forumHtml;
01075 }
01076
01077 private function forumLastVisit() {
01078 global $userId;
01079
01080 if(!isset($_SESSION['forum_lastVisit'])){
01081 $table_visit = "forum_visits";
01082 $query_checkvisit = "SELECT * from `$table_visit` WHERE `user_id`=$userId AND `page_modulecomponentid`=$this->moduleComponentId";
01083 $result_checkvisit = mysql_query($query_checkvisit);
01084 $check_visits = mysql_fetch_array($result_checkvisit);
01085 if(mysql_num_rows($result_checkvisit)<1) {
01086 $forum_lastViewed = date("Y-m-d H:i:s");
01087 }
01088 else {
01089 $forum_lastViewed = $check_visits['last_visit'];
01090 }
01091 $_SESSION['forum_lastVisit'] = $forum_lastViewed ;
01092
01093 $time_visit = date("Y-m-d H:i:s");
01094 $query_visit = "SELECT * FROM `$table_visit` WHERE `user_id`=$userId AND `page_modulecomponentid`=$this->moduleComponentId";
01095 $result_visit = mysql_query($query_visit);
01096 $num_rows_visit = mysql_num_rows($result_visit);
01097 if($num_rows_visit<1) {
01098 $query_setvisit = "INSERT INTO `$table_visit`(`page_modulecomponentid`,`user_id`,`last_visit`) VALUES($this->moduleComponentId,$userId,'$time_visit')";
01099 }
01100 else {
01101 $query_setvisit = "UPDATE `$table_visit` SET `last_visit`='$time_visit' WHERE `user_id`=$userId AND `page_modulecomponentid`=$this->moduleComponentId";
01102 }
01103 mysql_query($query_setvisit);
01104 }
01105 else {
01106 $forum_lastViewed = $_SESSION['forum_lastVisit'];
01107 }
01108 return $forum_lastViewed;
01109
01110 }
01111 public function createModule($compId) {
01112 $query = "INSERT INTO `forum_module` (`page_modulecomponentid`,`forum_description`,`last_post_userid` )VALUES ('$compId','Forum Description Here!!!','1')";
01113 $result = mysql_query($query) or die(mysql_error() . " forum.lib L:1112");
01114 }
01115
01116 public function deleteModule($moduleComponentId) {
01117 return true;
01118 }
01119
01120 public function copyModule($moduleComponentId,$newId) {
01121 return true;
01122 }
01123 }
01124