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></p>
00377 <p align="right"><a href="+view"><img title="Go Back to Forum" src="$temp/go_back.gif" /></a>
00378 <table id="forum" width="100%" cellpadding="3" cellspacing="1" bordercolor="1" >
00379 <tr>
00380 <td class="forumThreadRow" rowspan="2"><a href="+moderate&subaction=delete&thread_id=$rows[forum_thread_id]">
00381 <img src="$temp/delete1.gif" /></a></td>
00382 <td class="forumThreadRow" rowspan="2"><a href="+moderate&subaction=$subaction&thread_id=$rows[forum_thread_id]">
00383 <img src="$temp/$img" /></a></td>
00384 <td class="forumThreadRow"><strong>$forum_topic</strong><br /><img src="$temp/post_icon.gif" />
00385 <small">by $name on $rows[forum_thread_datetime] </small></td>
00386 <td class="forumThreadRow" rowspan="2"><strong>$name <br />
00387 PRE;
00388 if ($userId > 0 && $name != "Anonymous") {
00389 if ($rows['forum_thread_user_id'] == $userId)
00390 $lastLogin = $_SESSION['last_to_last_login_datetime'];
00391 else
00392 $lastLogin = $this->getLastLogin($rows['forum_thread_user_id']);
00393 $moderator=getPermissions($rows['forum_thread_user_id'], getPageIdFromModuleComponentId("forum",$this->moduleComponentId), "moderate");
00394 if($moderator)$postpart .= "Moderator";else
00395 $postpart .= "Member";
00396 $content = 'content'.$count;
00397 $text = 'text'.$count;
00398 $postpart .= <<<PRE
00399 </strong><br /><br />
00400 <script type="text/javascript" languauge="javascript" src="$js"></script>
00401 <a class="threadRow" id="$text" href="javascript:toggle('$content','$text');" >Show Details</a><br />
00402 <div id="$content" style="display: none;"><small>Posts: $posts <br />Joined: $reg_date <br />Last Visit:
00403 $lastLogin </small></div>
00404 PRE;
00405 }
00406 $postpart .=<<<PRE
00407 </td>
00408 </tr>
00409 <tr>
00410 <td class="forumThreadRow"><br /> $forum_detail </td>
00411 </tr><tr><td class="blank" colspan="2"></td></tr>
00412 PRE;
00413
00414 $sql2 = "SELECT * FROM `$table1_name` WHERE `forum_thread_id`=$forum_id AND `page_modulecomponentid`='$this->moduleComponentId' ORDER BY forum_post_id ASC";
00415 $result2 = mysql_query($sql2);
00416 while ($rows = mysql_fetch_array($result2)) {
00417 $count = $count + '1';
00418 $post_title = ucfirst(parseubb(parsesmileys($rows['forum_post_title'])));
00419 $post_content = (parseubb(parsesmileys($rows['forum_post_content'])));
00420 $name = ucfirst(getUserName($rows['forum_post_user_id']));
00421 $posts = $this->getTotalPosts($rows['forum_post_user_id']);
00422 $reg_date = $this->getRegDateFromUserID($rows['forum_post_user_id']);
00423 if ($rows['forum_post_approve'] == 0)
00424 {
00425 $text = "Approve";
00426 $img = "like.gif";
00427 }
00428 else
00429 {
00430 $text = "Disapprove";
00431 $img = "unlike.gif";
00432 }
00433 $subaction = strtolower($text);
00434 $postpart .=<<<PRE
00435
00436 <td class="forumThreadRow" rowspan="2" width="3%">
00437 <a href="+moderate&subaction=delete&forum_id=$rows[forum_thread_id]&post_id=$rows[forum_post_id]"><img src="$temp/delete1.gif" /></a></td>
00438 <td class="forumThreadRow" rowspan="2" width="3%">
00439 <a href="+moderate&subaction=$subaction&forum_id=$rows[forum_thread_id]&post_id=$rows[forum_post_id]"><img src="$temp/$img" /></a></td>
00440 <td class="forumThreadRow"><strong>Re:- $post_title </strong><br /><img src="$temp/post_icon.gif" />
00441 <small">by $name on $rows[forum_post_datetime] <small>
00442 PRE;
00443 if($r['allow_like_posts'] == 1){
00444 $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' ";
00445 $likeres = mysql_query($likequery) or displayerror(mysql_error() . "Moderate failed L:438");;
00446 $likeres = mysql_num_rows($likeres);
00447 $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' ";
00448 $dlikeres = mysql_query($dlikequery) or displayerror(mysql_error() . "Moderate failed L:441");
00449 $dlikeres = mysql_num_rows($dlikeres);
00450 $postpart .= '<br /><small> ' . $likeres . ' people like this post</small>    ';
00451 $postpart .= '<small> ' . $dlikeres . ' people dislike this post</small><br />';
00452 }
00453 $postpart .= '</td><td class="forumThreadRow" rowspan="2" width="20%"><strong>$name<br />';
00454
00455 if ($userId > 0 && $name != "Anonymous") {
00456 if ($rows['forum_post_user_id'] == $userId)
00457 $lastLogin = $_SESSION['last_to_last_login_datetime'];
00458 else
00459 $lastLogin = $this->getLastLogin($rows['forum_post_user_id']);
00460 $moderator=getPermissions($rows['forum_post_user_id'], getPageIdFromModuleComponentId("forum",$this->moduleComponentId), "moderate");
00461 if($moderator)$postpart .= "Moderator";else
00462 $postpart .= "Member";
00463 $content = 'content'.$count;
00464 $text = 'text'.$count;
00465 $postpart .= <<<PRE
00466 </strong><br /><br />
00467 <script type="text/javascript" languauge="javascript" src="$js"></script>
00468 <a class="threadRow" id="$text" href="javascript:toggle('$content','$text');" >Show Details</a><br />
00469 <div id="$content" style="display: none;"><small>Posts: $posts <br />Joined: $reg_date <br />Last Visit:
00470 $lastLogin </small></div>
00471 PRE;
00472 }
00473 $postpart .=<<<PRE
00474 </td>
00475 </tr>
00476 <tr>
00477 <td class="forumThreadRow"><br />$post_content</td>
00478 </tr><tr><td class="blank" colspan="2"></td></tr>
00479 PRE;
00480 }
00481 $postpart .='</table>';
00482 $query3 = "SELECT `forum_thread_viewcount` FROM `$table_name` WHERE forum_thread_id='$forum_id' AND `page_modulecomponentid`='$this->moduleComponentId' ";
00483 $result3 = mysql_query($query3);
00484 $rows = mysql_fetch_array($result3);
00485 $view = $rows['forum_thread_viewcount'];
00486
00487 $addview = $view +1;
00488 $query5 = "UPDATE `$table_name` SET `forum_thread_viewcount`='$addview' WHERE forum_thread_id='$forum_id' AND `page_modulecomponentid`='$this->moduleComponentId' LIMIT 1";
00489 $result5 = mysql_query($query5);
00490 $postpart .= '<br>
00491 <p align="left"><a href="+post&subaction=post_reply&thread_id='.$forum_id.'"><img title="Reply" src="'.$temp.'/reply.gif" />' .
00492 '</a> <a href="+post&subaction=create_thread"><img title="New Thread" src="'.$temp.'/newthread.gif" /></a></p>';
00493 return $postpart;
00494 }
00495 }
00496 public function actionPost() {
00497 $userId = $this->userId;
00498 $i = 0;
00499 $action = '';
00500 foreach ($_GET as $var => $val) {
00501 if ($i == 1)
00502 $action .= "&" . $var . "=" . $val;
00503 if ($val == 'post') {
00504 $action .= "+" . $val;
00505 $i = 1;
00506 }
00507 }
00508 $table_name = "forum_threads";
00509 $table1_name = "forum_posts";
00510 $table2_name = "forum_module";
00511 if(isset($_GET['subaction']))
00512 $subaction = escape($_GET['subaction']);
00513 global $urlRequestRoot, $moduleFolder, $cmsFolder,$templateFolder,$sourceFolder;
00514 $temp = $urlRequestRoot . "/" . $cmsFolder . "/" . $moduleFolder . "/forum/images";
00515 require_once ("$sourceFolder/$moduleFolder/forum/bbeditor.php");
00516 require_once ("$sourceFolder/$moduleFolder/forum/bbparser.php");
00517 $q = "SELECT * FROM `$table2_name` WHERE `page_modulecomponentid`=$this->moduleComponentId LIMIT 1";
00518 $res = mysql_query($q);
00519 $rows = mysql_fetch_array($res);
00520 $access_level = $rows['forum_moderated'];
00521 if ($access_level) {
00522 $approve = 0;
00523 $access = "moderated";
00524 } else {
00525 $approve = 1;
00526 $access = "public";
00527 }
00528 $moderator=getPermissions($this->userId, getPageIdFromModuleComponentId("forum",$this->moduleComponentId), "moderate");
00529 if($moderator) {
00530 $approve = 1;
00531 }
00532 if (isset ($_POST['post'])) {
00533 if (($subaction == "create_thread") ||( $subaction == "")) {
00534
00535 if (!$_POST['subject'] || !$_POST['message']) {
00536 $editor = bbeditor();
00537 return "You did not fill all the fields!" . $editor;
00538 } else {
00539 $datetime = date("Y-m-d H:i:s");
00540 $message = $_POST['message'];
00541 $subject = addslashes(htmlspecialchars($_POST['subject']));
00542 $message = addslashes(htmlspecialchars(parsenewline(nl2br($message))));
00543 if (isset ($_POST['sticky'])&&($moderator))
00544 $category = "sticky";
00545 else
00546 $category = "general";
00547 $query="SELECT MAX(`forum_thread_id`) AS MAX FROM `forum_threads`";
00548 $result=mysql_query($query);
00549 $row1 = mysql_fetch_assoc($result);
00550 $threadid = $row1['MAX'] + 1;
00551
00552 $sql = "INSERT INTO `$table_name`(`forum_thread_id` ,`page_modulecomponentid` ,`forum_thread_category` ,`forum_access_status` ," .
00553 "`forum_thread_topic` ,`forum_detail` ,`forum_thread_user_id` ,`forum_thread_datetime` ,`forum_post_approve` ," .
00554 "`forum_thread_viewcount` ,`forum_thread_last_post_userid` ,`forum_thread_lastpost_date`)" .
00555 " VALUES('$threadid', '$this->moduleComponentId', '$category', '$access', '$subject', '$message'," .
00556 " '$userId', '$datetime', '$approve', '1','$userId', '$datetime')";
00557 $result = mysql_query($sql) or displayerror(mysql_error() . "Create New Thread failed L:550");
00558 if ($result) {
00559 $sql1 = "SELECT * FROM `$table2_name` WHERE `page_modulecomponentid`=$this->moduleComponentId LIMIT 1";
00560 $result1 = mysql_query($sql1);
00561 $rows1 = mysql_fetch_array($result1);
00562 $total_thread_count = $rows['total_thread_count'];
00563
00564 $net_thread_count = $total_thread_count +1;
00565 $sql2 = "UPDATE `$table2_name` SET `total_thread_count`='$net_thread_count', `last_post_userid`='$userId'," .
00566 " `last_post_datetime`='$datetime' WHERE `page_modulecomponentid`=$this->moduleComponentId LIMIT 1";
00567 $result2 = mysql_query($sql2);
00568 if(($access=="moderated")&& (!$moderator))
00569 displayinfo("You have successfully created a new thread.It will be published after getting the moderator's approval." .
00570 "<br />");
00571 else
00572 displayinfo("You have successfully created a new thread.<br />");
00573 } else {
00574 displayerror("Sorry! Your thread could not be created now. Please try again later!");
00575 }
00576 return $this->actionView();
00577 }
00578 } else
00579 if ($subaction == "post_reply") {
00580 if (!$_POST['subject'] || !$_POST['message']) {
00581 $editor = bbeditor();
00582 return "You did not fill all the fields!" . $editor;
00583 } else {
00584 $forum_id = escape($_GET['thread_id']);
00585 $datetime = date("Y-m-d H:i:s");
00586 $message = $_POST['message'];
00587 $subject = addslashes(htmlspecialchars($_POST['subject']));
00588 $message = addslashes(htmlspecialchars(parsenewline(nl2br($message))));
00589 $sql7 = "SELECT MAX(`forum_post_id`) AS Maxpost_id FROM `$table1_name` WHERE `forum_thread_id` = '$forum_id'";
00590 $res = mysql_query($sql7);
00591 $rows = mysql_fetch_array($res);
00592
00593 if ($rows) {
00594 $Max_id = $rows['Maxpost_id'] + 1;
00595 } else {
00596 $Max_id = 1;
00597 }
00598 $sql = "INSERT INTO `$table1_name`( `page_modulecomponentid` , `forum_thread_id` , `forum_post_id` , `forum_post_user_id` , `forum_post_title` , " .
00599 "`forum_post_content` , `forum_post_datetime` , `forum_post_approve` ) VALUES( '$this->moduleComponentId','$forum_id', '$Max_id'," .
00600 " '$userId', '$subject', '$message', '$datetime', '$approve')";
00601 $result = mysql_query($sql) or displayerror(mysql_error() . "Post failed L:594");
00602 if ($result) {
00603 $sql1 = "SELECT * FROM `$table_name` WHERE `page_modulecomponentid`=$this->moduleComponentId AND `forum_thread_id`=$forum_id" .
00604 " LIMIT 1";
00605 $result1 = mysql_query($sql1);
00606 $rows1 = mysql_fetch_array($result1);
00607 $sql2 = "UPDATE `$table_name` SET `forum_thread_last_post_userid`='$userId', " .
00608 "`forum_thread_lastpost_date`='$datetime' " .
00609 "WHERE `page_modulecomponentid`=$this->moduleComponentId AND `forum_thread_id`='$forum_id' LIMIT 1";
00610 $result2 = mysql_query($sql2);
00611 $sql3 = "SELECT * FROM `$table2_name` WHERE `page_modulecomponentid`=$this->moduleComponentId LIMIT 1";
00612 $result3 = mysql_query($sql3);
00613 $rows3 = mysql_fetch_array($result3);
00614 $sql4 = "UPDATE `$table2_name` SET `last_post_userid`='$userId', " .
00615 "`last_post_datetime`='$datetime' WHERE `page_modulecomponentid`=$this->moduleComponentId LIMIT 1";
00616 $result4 = mysql_query($sql4);
00617 if(($rows1['forum_access_status']=="moderated")&& (!$moderator))
00618 displayinfo("You have successfully posted your reply.It will be published after getting the moderator's approval." .
00619 "<br />");
00620 else
00621 displayinfo("You have successfully posted your reply!");
00622 } else {
00623 displayerror("Sorry! Your reply could not be posted now. Please try again later!");
00624 }
00625 {
00626 $forumHtml = '';
00627 $thread_id = $forum_id;
00628 $sql = "SELECT * FROM `$table_name` WHERE `forum_thread_id`=$thread_id AND `page_modulecomponentid`='$this->moduleComponentId' LIMIT 1";
00629 $result1 = mysql_query($sql);
00630 $rows = mysql_fetch_array($result1);
00631 $threadUserId = $rows['forum_thread_user_id'];
00632 $forum_topic = parseubb(parsesmileys($rows['forum_thread_topic']));
00633 $forum_detail = parseubb(parsesmileys($rows['forum_detail']));
00634 $name = getUserName($rows['forum_thread_user_id']);
00635 $posts = $this->getTotalPosts($rows['forum_thread_user_id']);
00636 $reg_date = $this->getRegDateFromUserID($rows['forum_thread_user_id']);
00637 $forumHtml = $this->forumHtml($rows,'threadHead');
00638 if ($rows['forum_post_approve'] == 1)
00639 $forumHtml .= $this->forumHtml($rows,'threadMain');
00640 $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";
00641 $result2 = mysql_query($sql2);
00642 while ($rows = mysql_fetch_array($result2))
00643 $forumHtml .= $this->forumHtml($rows,'threadMain',1);
00644 $sql3 = "SELECT `forum_thread_viewcount` FROM `$table_name` WHERE `forum_thread_id`='$thread_id' AND `page_modulecomponentid`='$this->moduleComponentId'";
00645 $result3 = mysql_query($sql3);
00646 $rows = mysql_fetch_array($result3);
00647 $view = $rows['forum_thread_viewcount'];
00648
00649 $addview = $view +1;
00650 $sql5 = "UPDATE `$table_name` SET `forum_thread_viewcount`='$addview' WHERE forum_thread_id='$thread_id' AND `page_modulecomponentid`='$this->moduleComponentId' LIMIT 1";
00651 $result5 = mysql_query($sql5);
00652 $forumHtml .= '</table> ';
00653 return $forumHtml;
00654 }
00655 }
00656 }
00657 } else
00658 if (isset ($_POST['preview'])) {
00659
00660 $message = escape($_POST['message']);
00661 $subject = addslashes(htmlspecialchars($_POST['subject']));
00662 $text = $message;
00663 $message = nl2br($message);
00664 $message = parseubb(parsesmileys(addslashes(htmlspecialchars(parsenewline($message)))));
00665 $editor = bbeditor($action, $subject, $text);
00666 return "<b>Subject :</b> " . $subject . "<br><b>Message :</b><br> " . $message . $editor;
00667 } else
00668 if (isset ($_GET['thread_id'])) {
00669 $editor = bbeditor($action);
00670 return $editor;
00671 } else {
00672 $editor = bbeditor($action);
00673 return $editor;
00674 }
00675 }
00676 public function actionView() {
00677 $userId = $this->userId;
00678 global $urlRequestRoot, $moduleFolder, $cmsFolder,$templateFolder,$sourceFolder;
00679 $templatesImageFolder = "$urlRequestRoot/$cmsFolder/$templateFolder/".TEMPLATE;
00680 $temp = $urlRequestRoot . "/" . $cmsFolder . "/" . $moduleFolder . "/forum/images";
00681 $table_name = "forum_threads";
00682 $table1_name = "forum_posts";
00683 $forumHtml = <<<PRE
00684 <link rel="stylesheet" href="$temp/styles.css" type="text/css" />
00685 PRE;
00686 $forum_lastVisit = $this->forumLastVisit();
00687 $moderator=getPermissions($this->userId, getPageIdFromModuleComponentId("forum",$this->moduleComponentId), "moderate");
00688
00689 $table_visit = "forum_visits";
00690 $query_checkvisit = "SELECT * from `$table_visit` WHERE `user_id`=$userId AND `page_modulecomponentid`=$this->moduleComponentId";
00691 $result_checkvisit = mysql_query($query_checkvisit);
00692 $check_visits = mysql_fetch_array($result_checkvisit);
00693 if(mysql_num_rows($result_checkvisit)<1) {
00694 $forum_lastviewed = date("Y-m-d H:i:s");
00695 }
00696 else {
00697 $forum_lastviewed = $check_visits['last_visit'];
00698 }
00699
00700 $time_visit = date("Y-m-d H:i:s");
00701 $query_visit = "SELECT * FROM `$table_visit` WHERE `user_id`=$userId AND `page_modulecomponentid`=$this->moduleComponentId";
00702 $result_visit = mysql_query($query_visit);
00703 $num_rows_visit = mysql_num_rows($result_visit);
00704 if($num_rows_visit<1) {
00705 $query_setvisit = "INSERT INTO `$table_visit`(`page_modulecomponentid`,`user_id`,`last_visit`) VALUES($this->moduleComponentId,$userId,'$time_visit')";
00706 }
00707 else {
00708 $query_setvisit = "UPDATE `$table_visit` SET `last_visit`='$time_visit' WHERE `user_id`=$userId AND `page_modulecomponentid`=$this->moduleComponentId";
00709 }
00710 mysql_query($query_setvisit);
00711
00712 require_once ("$sourceFolder/$moduleFolder/forum/bbeditor.php");
00713 require_once ("$sourceFolder/$moduleFolder/forum/bbparser.php");
00714 if (!isset ($_GET['thread_id'])) {
00715 if ((isset($_GET['subaction']))&&($_GET['subaction'] == "delete_thread")) {
00716 $thread_id = escape($_GET['forum_id']);
00717 $query = "DELETE FROM `$table_name` WHERE `forum_thread_id`=$thread_id AND `page_modulecomponentid`='$this->moduleComponentId' LIMIT 1";
00718 $res = mysql_query($query);
00719 $query1 = "DELETE FROM `$table1_name` WHERE `forum_thread_id`=$thread_id AND `page_modulecomponentid`='$this->moduleComponentId'";
00720 $res1 = mysql_query($query1);
00721 if (!res || !res1)
00722 displayerror("Could not perform the delete operation on the selected thread!");
00723 }
00724 if($userId>0 )
00725 {
00726 $new_mt='0';
00727 $new_mp='0';
00728 $new_p='0';
00729 $new_t='0';
00730 if($moderator)
00731 {
00732 $qum_0 = "SELECT * FROM `$table_name` WHERE `page_modulecomponentid`=" . $this->moduleComponentId ." AND `forum_post_approve` = 0";
00733 $resm_0 = mysql_query($qum_0);
00734 $numm_0 = mysql_num_rows($resm_0);
00735 for ($j = 1; $j <= $numm_0; $j++) {
00736 $rows = mysql_fetch_array($resm_0,MYSQL_ASSOC);
00737 if($forum_lastVisit<$rows['forum_thread_datetime'])
00738 $new_mt = $new_mt + '1';
00739 }
00740 $qum_1 = "SELECT * FROM `$table1_name` WHERE `page_modulecomponentid`=" . $this->moduleComponentId ." AND `forum_post_approve` = 0";
00741 $resm_1 = mysql_query($qum_1);
00742 $numm_1 = mysql_num_rows($resm_1);
00743 for ($j = 1; $j <= $numm_1; $j++) {
00744 $rows = mysql_fetch_array($resm_1,MYSQL_ASSOC);
00745 if($forum_lastVisit<$rows['forum_post_datetime'])
00746 $new_mp = $new_mp + '1';
00747 }
00748 if($new_mt){
00749 $show_t = $new_mt. " new threads to be moderated since your last visit";
00750 displayinfo($show_t);}
00751 if($new_mp) {
00752 $show_p = $new_mp. " new posts to be moderated since your last visit";
00753 displayinfo($show_p);}
00754 }
00755 $qu_0 = "SELECT * FROM `$table_name` WHERE `page_modulecomponentid`=" . $this->moduleComponentId ." AND `forum_post_approve` = 1 AND `forum_thread_user_id` !=". $this->userId;
00756 $res_0 = mysql_query($qu_0);
00757 $num_0 = mysql_num_rows($res_0);
00758 for ($j = 1; $j <= $num_0; $j++) {
00759 $rows = mysql_fetch_array($res_0,MYSQL_ASSOC);
00760 if($forum_lastVisit<$rows['forum_thread_datetime'])
00761 $new_t = $new_t + '1';
00762 }
00763 $qu_1 = "SELECT * FROM `$table1_name` WHERE `page_modulecomponentid`=" . $this->moduleComponentId ." AND `forum_post_approve` = 1 AND `forum_post_user_id` !=". $this->userId;
00764 $res_1 = mysql_query($qu_1) or die(mysql_error());
00765 $num_1 = mysql_num_rows($res_1);
00766 for ($j = 1; $j <= $num_1; $j++) {
00767 $rows = mysql_fetch_array($res_1,MYSQL_ASSOC);
00768 if($forum_lastVisit<$rows['forum_post_datetime'])
00769 $new_p = $new_p + '1';
00770 }
00771 if($new_t && $new_t!=$new_mt){
00772 $show_t = $new_t. " new threads since your last visit";
00773 displayinfo($show_t);}
00774 if($new_p && $new_p!=$new_mp) {
00775 $show_p = $new_p. " new posts since your last visit";
00776 displayinfo($show_p);}
00777 }
00778 $query_d = "SELECT `forum_description` FROM `forum_module` WHERE `page_modulecomponentid`='" . $this->moduleComponentId ."' LIMIT 1";
00779 $result_d = mysql_query($query_d) or die(mysql_error());
00780 $result_d = mysql_fetch_array($result_d);
00781 $query = "SELECT * FROM `$table_name` WHERE `page_modulecomponentid`='" . $this->moduleComponentId . "' AND " .
00782 "`forum_thread_category`='general' ORDER BY `forum_thread_lastpost_date` DESC";
00783 $result = mysql_query($query) or displayerror(mysql_error() . "View of General Threads failed L:776");
00784 $query1 = "SELECT * FROM `$table_name` WHERE `page_modulecomponentid`='" . $this->moduleComponentId . "' AND " .
00785 "`forum_thread_category`='sticky' ORDER BY `forum_thread_datetime` DESC";
00786 $result1 = mysql_query($query1)or displayerror(mysql_error() . "View of sticjy Threads failed L:779");
00787 $num_rows1 = mysql_num_rows($result1);
00788 if ($result) {
00789 $action = "+post&subaction=create_thread";
00790 $num_rows = mysql_num_rows($result);
00791 $forum_header =<<<PRE
00792 <p align="left"><a href="$action"><img title="New Thread" src="$temp/newthread.gif" /></a></p>
00793 <div style="text-align:center;"><b>" $result_d[0] "</b></div>
00794 <table width="100%" border="1" align="center" cellpadding="4" cellspacing="2" id="forum">
00795 <tr class="TableHeader">
00796 <td class="forumTableHeader" colspan="2"><strong>TOPICS</strong><br /></td>
00797 <td class="forumTableHeader"> <strong>VIEWS</strong></td>
00798 <td class="forumTableHeader"><strong>REPLIES</strong></td>
00799 <td class="forumTableHeader"><strong>LAST POST</strong></td>
00800 </tr>
00801 PRE;
00802 $forumHtml .= $forum_header;
00803 if ($result1 && $num_rows1 > 0) {
00804 for ($j = 1; $j <= $num_rows1; $j++) {
00805 $rows = mysql_fetch_array($result1,MYSQL_ASSOC);
00806 $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'";
00807 $result2 = mysql_query($query2);
00808 $reply_count = mysql_num_rows($result2);
00809 $topic = parseubb(parsesmileys(stripslashes($rows['forum_thread_topic'])));
00810 $name = getUserName($rows['forum_thread_user_id']);
00811 $last_post_author = getUserName($rows['forum_thread_last_post_userid']);
00812 if ($rows['forum_post_approve'] == 1) {
00813 $forumHtml .= $this->forumHtml($rows,'threadRow');
00814 }
00815 }
00816 }
00817 if ($num_rows < 1)
00818 $forum_header .= "<tr><td colspan=\"5\" class='forumTableRow'><strong>No Post</strong></td></tr>";
00819 for ($i = 1; $i <= $num_rows; $i++) {
00820 $rows = mysql_fetch_array($result);
00821 $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'";
00822 $result1 = mysql_query($query1);
00823 $reply_count = mysql_num_rows($result1);
00824 $topic = parseubb(parsesmileys($rows['forum_thread_topic']));
00825 $name = getUserName($rows['forum_thread_user_id']);
00826 $last_post_author = getUserName($rows['forum_thread_last_post_userid']);
00827 if ($rows['forum_post_approve'] == 1) {
00828 $forumHtml .= $this->forumHtml($rows,'threadRow');
00829 }
00830 }
00831 $forumHtml .= '<tr></tr></table><br />';
00832 }
00833 }
00834 else {
00835 $thread_id = escape($_GET['thread_id']);
00836 if(isset($_GET['subaction'])){
00837 if ($_GET['subaction'] == "delete_post") {
00838 $post_id = escape($_GET['post_id']);
00839 $query = "DELETE FROM `$table1_name` WHERE `forum_thread_id`=$thread_id AND `forum_post_id`=$post_id AND `page_modulecomponentid`='$this->moduleComponentId' LIMIT 1";
00840 $res = mysql_query($query);
00841 if ( !$res )
00842 displayerror("Could not perform the delete operation on the selected post!");
00843 $query = "DELETE FROM `forum_like` WHERE `forum_thread_id`=$thread_id AND `forum_post_id`=$post_id AND `page_modulecomponentid`='$this->moduleComponentId'";
00844 $res = mysql_query($query);
00845 }
00846 if ($_GET['subaction'] == "like_post") {
00847 $post_id = escape($_GET['post_id']);
00848 $query = "SELECT * FROM `forum_like` WHERE `forum_thread_id`=$thread_id AND `forum_post_id`=$post_id AND `page_modulecomponentid`='$this->moduleComponentId' ";
00849 $res = mysql_query($query);
00850 if(mysql_num_rows($res)==0) {
00851 $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')";
00852 $res = mysql_query($query);
00853 if ( !$res )
00854 displayerror("Could not perform the like operation on the selected post!");
00855 }
00856 }
00857 if ($_GET['subaction'] == "dislike_post") {
00858 $post_id = escape($_GET['post_id']);
00859 $query = "SELECT * FROM `forum_like` WHERE `forum_thread_id`=$thread_id AND `forum_post_id`=$post_id AND `page_modulecomponentid`='$this->moduleComponentId' ";
00860 $res = mysql_query($query);
00861 if(mysql_num_rows($res)==0) {
00862 $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')";
00863 $res = mysql_query($query);
00864 if ( !$res )
00865 displayerror("Could not perform the dislike operation on the selected post!");
00866 }
00867 }
00868 }
00869 $sql = "SELECT * FROM `$table_name` WHERE `forum_thread_id`=$thread_id AND `page_modulecomponentid`='$this->moduleComponentId' LIMIT 1";
00870 $result1 = mysql_query($sql);
00871 $rows = mysql_fetch_array($result1);
00872 $threadUserId = $rows['forum_thread_user_id'];
00873 $forum_topic = parseubb(parsesmileys($rows['forum_thread_topic']));
00874 $forum_detail = parseubb(parsesmileys($rows['forum_detail']));
00875 $name = getUserName($rows['forum_thread_user_id']);
00876 $posts = $this->getTotalPosts($rows['forum_thread_user_id']);
00877 $reg_date = $this->getRegDateFromUserID($rows['forum_thread_user_id']);
00878 $forumHtml = $this->forumHtml($rows,'threadHead');
00879 $count=0;
00880 if ($rows['forum_post_approve'] == 1)
00881 $forumHtml .= $this->forumHtml($rows,'threadMain',0,0);
00882 $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";
00883 $result2 = mysql_query($sql2);
00884 while ($rows1 = mysql_fetch_array($result2)) {
00885 $count = $count + 1;
00886 $forumHtml .= $this->forumHtml($rows1,'threadMain',1,$count);
00887 }
00888 $sql3 = "SELECT `forum_thread_viewcount` FROM `$table_name` WHERE `forum_thread_id`='$thread_id' AND `page_modulecomponentid`='$this->moduleComponentId'";
00889 $result3 = mysql_query($sql3);
00890 $rows2 = mysql_fetch_array($result3);
00891 $view = $rows2['forum_thread_viewcount'];
00892
00893 $addview = $view +1;
00894 $sql5 = "UPDATE `$table_name` SET `forum_thread_viewcount`='$addview' WHERE forum_thread_id='$thread_id' AND `page_modulecomponentid`='$this->moduleComponentId' LIMIT 1";
00895 $result5 = mysql_query($sql5);
00896 $forumHtml .= '</table><br />';
00897 if($rows['forum_thread_category']!='sticky'){
00898 $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>';
00899 }
00900 }
00901 $forumHtml .= '<p align="left"><img alt="Sticky" title="Sticky" src="' . $temp . '/sticky.gif" align=left> - Sticky Threads.<br /><br />' .
00902 '<img alt="New Posts" title="New Posts" src="' . $temp . '/thread_new.gif" align=left> - Topic with new posts since last visit.' .
00903 '<br /><br /><img alt="No new posts" title="No new Posts" src="' . $temp . '/thread_hot.gif" align=left>' .
00904 ' - Topic with no new posts since last visit. </p>';
00905 return $forumHtml;
00906 }
00907 private function forumHtml($data, $type='thread', $post=0,$count=0) {
00908 global $urlRequestRoot, $moduleFolder, $cmsFolder,$templateFolder,$sourceFolder,$userId;
00909 require_once ("$sourceFolder/$moduleFolder/forum/bbeditor.php");
00910 require_once ("$sourceFolder/$moduleFolder/forum/bbparser.php");
00911 $js=$urlRequestRoot."/".$cmsFolder."/".$moduleFolder."/forum/images/jscript.js";
00912 $table_name = "forum_threads";
00913 $table1_name = "forum_posts";
00914 $templatesImageFolder = "$urlRequestRoot/$cmsFolder/$templateFolder/".TEMPLATE;
00915 $temp = $urlRequestRoot . "/" . $cmsFolder . "/" . $moduleFolder . "/forum/images";
00916 if(isset($_GET['thread_id']))
00917 $thread_id = escape($_GET['thread_id']);
00918 $forumHtml = '';
00919 $forum_threads = '';
00920 $rows = $data;
00921 $action = "+post&subaction=create_thread";
00922 $forum_lastVisit = $this->forumLastVisit();
00923 if($type == 'threadRow')
00924 {
00925 if($userId>0 && ($forum_lastVisit<$rows['forum_thread_lastpost_date']))
00926 {
00927 $img_src = "thread_new.gif";
00928 }
00929 else
00930 {
00931 $img_src = "thread_hot.gif";
00932 }
00933 $topic = ucfirst((parseubb(parsesmileys($rows['forum_thread_topic']))));
00934 $name = ucfirst(getUserName($rows['forum_thread_user_id']));
00935 $last_post_author = ucfirst(getUserName($rows['forum_thread_last_post_userid']));
00936 if($rows['forum_thread_category']=='sticky') {
00937 $img_src = 'sticky.gif';
00938 }
00939 $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' ";
00940 $result1 = mysql_query($query1);
00941 $reply_count = mysql_num_rows($result1);
00942 $forum_threads .=<<<PRE1
00943 <tr class="forumThreadRow">
00944 <td class="forumThreadRow forumTableIcon" width="3%"><img src="$temp/$img_src" /></td>
00945 <td class="forumThreadRow" width="51%"><a class="threadRow" href="+view&thread_id=$rows[forum_thread_id]"> $topic </a><br /><small>by <b> $name </b>
00946 on $rows[forum_thread_datetime] </small></td>
00947 <td class="forumThreadRow" width="8%" style="text-align:center;"> $rows[forum_thread_viewcount] </td>
00948 <td class="forumThreadRow" width="8%" style="text-align:center;"> $reply_count </td>
00949 <td class="forumThreadRow" width="30%"><small>by <b> $last_post_author </a></b> on $rows[forum_thread_lastpost_date] </small></td>
00950 </tr>
00951 PRE1;
00952 $forumHtml .= $forum_threads;
00953 }
00954 if($type == 'threadHead'){
00955 $thread_Header = '<p align="left">';
00956 if($rows['forum_thread_category']!='sticky') {
00957 $thread_Header .= '<a href="+post&subaction=post_reply&thread_id='.$thread_id.'"><img alt="Reply" title="Reply" src="'.$temp.'/reply.gif" /></a>  ';
00958 }
00959 $thread_Header .=<<<PRE
00960 <link rel="stylesheet" href="$temp/styles.css" type="text/css" />
00961  <a href="+post&subaction=create_thread"><img title="New Thread" src="$temp/newthread.gif" /></a></p>
00962 <p align="right"><a href="+view"> <img title="Go Back to Forum" src="$temp/go_back.gif" /></a>
00963 <table width="100%" cellpadding="4" cellspacing="2" id="forum" >
00964 PRE;
00965 $forumHtml = $thread_Header;
00966 }
00967 if($type == 'threadMain') {
00968 $q = "SELECT * FROM `forum_module` WHERE `page_modulecomponentid`=$this->moduleComponentId LIMIT 1";
00969 $r = mysql_query($q) or displayerror(mysql_error() . "View of Thread failed L:962");
00970 $r = mysql_fetch_array($r);
00971 if($post == 0){
00972 $topic = censor_words(ucfirst(parseubb(parsesmileys($rows['forum_thread_topic']))));
00973 $name = ucfirst(getUserName($rows['forum_thread_user_id']));
00974 $last_post_author = ucfirst(getUserName($rows['forum_thread_last_post_userid']));
00975 $threadUserId = $rows['forum_thread_user_id'];
00976 $detail = censor_words(parseubb(parsesmileys($rows['forum_detail'])));
00977 $posts = $this->getTotalPosts($rows['forum_thread_user_id']);
00978 $reg_date = $this->getRegDateFromUserID($rows['forum_thread_user_id']);
00979 $postTime = $rows['forum_thread_datetime'];
00980 }
00981 if($post == 1){
00982 $postUserId = $rows['forum_post_user_id'];
00983 $topic = censor_words(ucfirst(parseubb(parsesmileys($rows['forum_post_title']))));
00984 $detail = censor_words(parseubb(parsesmileys($rows['forum_post_content'])));
00985 $name = ucfirst(getUserName($rows['forum_post_user_id']));
00986 $posts = $this->getTotalPosts($rows['forum_post_user_id']);
00987 $reg_date = $this->getRegDateFromUserID($rows['forum_post_user_id']);
00988 $postTime = $rows['forum_post_datetime'];
00989 $threadUserId = $postUserId;
00990 }
00991 $datetime = date("Y-m-d H:i:s")-$postTime;
00992 $threadHtml = '<tr class="ThreadHeadRow" cellspacing="10">
00993 <td class="forumThreadRow"><strong> ' . $topic . ' </strong><br />' .
00994 '<img src="' . $temp . '/post_icon.gif" /><small>   by ' . $name . ' </a>' .
00995 ' on ' . $postTime . ' </small>';
00996 if($post == 1)
00997 if($r['allow_like_posts'] == 1){
00998 $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' ";
00999 $likeres = mysql_query($likequery);
01000 $likeres = mysql_num_rows($likeres);
01001 $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' ";
01002 $dlikeres = mysql_query($dlikequery);
01003 $dlikeres = mysql_num_rows($dlikeres);
01004 $threadHtml .= '<br /><small> ' . $likeres . ' people like this post</small>    ';
01005 $threadHtml .= '<small> ' . $dlikeres . ' people dislike this post</small><br />';
01006 }
01007 $threadHtml .='</td>
01008 <td class="forumThreadRow" width="25%" rowspan="2"><strong> ' . $name . ' </a><br />';
01009 if ($threadUserId > 0) {
01010 if ($threadUserId == $userId)
01011 $lastLogin = $_SESSION['last_to_last_login_datetime'];
01012 else
01013 $lastLogin = $this->getLastLogin($threadUserId);
01014 $moderator=getPermissions($threadUserId, getPageIdFromModuleComponentId("forum",$this->moduleComponentId), "moderate");
01015 if($moderator)$threadHtml .= "Moderator";else
01016 $threadHtml .= "Member";
01017 $content = 'content'.$count;
01018 $text = 'text'.$count;
01019 $threadHtml .= <<<PRE
01020 </strong><br /><br />
01021 <script type="text/javascript" languauge="javascript" src="$js"></script>
01022 <a class="threadRow" id="$text" href="javascript:toggle('$content','$text');" >Show Details</a><br />
01023 <div id="$content" style="display: none;"><small>Posts: $posts <br />Joined: $reg_date <br />Last Visit:
01024 $lastLogin </small></div>
01025 PRE;
01026 if($post==1 && $userId>0 && ( ($r['allow_delete_posts'] == 1) ||($r['allow_like_posts']==1))) {
01027
01028 if($r['allow_delete_posts'] == 1){
01029 if ($post==1 && $userId > 0 && $userId == $rows['forum_post_user_id'])
01030
01031 {
01032 $threadHtml .= '<br /><a href="+view&subaction=delete_post&thread_id=' . $thread_id . '&post_id=' . $rows['forum_post_id'] . '">' .
01033 '<img src="'.$temp.'/delete1.gif"></a></span>';
01034 }
01035 }
01036 if($r['allow_like_posts'] == 1) {
01037 if ($userId > 0 && $post == 1)
01038 {
01039 $postId=$rows['forum_post_id'];
01040 $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'";
01041 $re = mysql_query($qu) ;
01042 $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'";
01043 $re1 = mysql_query($qu1);
01044 if(mysql_num_rows($re)==0 && mysql_num_rows($re1)==0)
01045 {
01046 $threadHtml .= ' <a href="+view&subaction=like_post&thread_id=' . $thread_id . '&post_id=' . $rows['forum_post_id'] . '">' .
01047 ' <img title="Like this post" src="'.$temp.'/like.gif"></a></span>';
01048 $threadHtml .= ' <a href="+view&subaction=dislike_post&thread_id=' . $thread_id . '&post_id=' . $rows['forum_post_id'] . '">' .
01049 ' <img title="Dislike this post" src="'.$temp.'/unlike.gif"></a></span>';
01050 }
01051 else {
01052 if(mysql_num_rows($re)>0)
01053 $threadHtml .= '<br /> You Like this post';
01054 else
01055 $threadHtml .= '<br /> You Dislike this post';
01056 }
01057 }
01058 }
01059
01060 }
01061 }
01062 $threadHtml .=<<<PRE
01063 </td>
01064 </tr>
01065 <tr>
01066 <td class="forumThreadRow"> <br />$detail </td>
01067 </tr>
01068 PRE;
01069 $threadHtml .= '<tr><td class="blank" colspan="2"></td></tr>';
01070
01071
01072 $forumHtml .= $threadHtml;
01073 }
01074
01075 return $forumHtml;
01076 }
01077
01078 private function forumLastVisit() {
01079 global $userId;
01080
01081 if(!isset($_SESSION['forum_lastVisit'])){
01082 $table_visit = "forum_visits";
01083 $query_checkvisit = "SELECT * from `$table_visit` WHERE `user_id`=$userId AND `page_modulecomponentid`=$this->moduleComponentId";
01084 $result_checkvisit = mysql_query($query_checkvisit);
01085 $check_visits = mysql_fetch_array($result_checkvisit);
01086 if(mysql_num_rows($result_checkvisit)<1) {
01087 $forum_lastViewed = date("Y-m-d H:i:s");
01088 }
01089 else {
01090 $forum_lastViewed = $check_visits['last_visit'];
01091 }
01092 $_SESSION['forum_lastVisit'] = $forum_lastViewed ;
01093
01094 $time_visit = date("Y-m-d H:i:s");
01095 $query_visit = "SELECT * FROM `$table_visit` WHERE `user_id`=$userId AND `page_modulecomponentid`=$this->moduleComponentId";
01096 $result_visit = mysql_query($query_visit);
01097 $num_rows_visit = mysql_num_rows($result_visit);
01098 if($num_rows_visit<1) {
01099 $query_setvisit = "INSERT INTO `$table_visit`(`page_modulecomponentid`,`user_id`,`last_visit`) VALUES($this->moduleComponentId,$userId,'$time_visit')";
01100 }
01101 else {
01102 $query_setvisit = "UPDATE `$table_visit` SET `last_visit`='$time_visit' WHERE `user_id`=$userId AND `page_modulecomponentid`=$this->moduleComponentId";
01103 }
01104 mysql_query($query_setvisit);
01105 }
01106 else {
01107 $forum_lastViewed = $_SESSION['forum_lastVisit'];
01108 }
01109 return $forum_lastViewed;
01110
01111 }
01112 public function createModule(& $moduleComponentId) {
01113
01114 $query = "SELECT MAX(page_modulecomponentid) as MAX FROM `forum_module` ";
01115 $result = mysql_query($query) or die(mysql_error() . " forum.lib L:1108");
01116 $row = mysql_fetch_assoc($result);
01117 $compId = $row['MAX'] + 1;
01118 $query = "INSERT INTO `forum_module` (`page_modulecomponentid`,`forum_description`,`last_post_userid` )VALUES ('$compId','Forum Description Here!!!','1')";
01119 $result = mysql_query($query) or die(mysql_error() . " forum.lib L:1112");
01120 if (mysql_affected_rows()) {
01121 $moduleComponentId = $compId;
01122 return true;
01123 } else
01124 return false;
01125
01126 }
01127
01128 public function deleteModule($moduleComponentId) {
01129 $query = "DELETE FROM `forum_posts` WHERE `page_modulecomponentid`=$moduleComponentId";
01130 $result = mysql_query($query);
01131 $query1 = "DELETE FROM `forum_threads` WHERE `page_modulecomponentid`=$moduleComponentId";
01132 $result1 = mysql_query($query1);
01133 $query2 = "DELETE FROM `forum_module` WHERE `page_modulecomponentid`=$moduleComponentId";
01134 $resul2 = mysql_query($query2);
01135 if ((mysql_affected_rows()) >= 1)
01136 return true;
01137 else
01138 return false;
01139 }
01140
01141 public function copyModule($moduleComponentId) {
01142 $query = "SELECT MAX(page_modulecomponentid) as MAX FROM `forum_module` ";
01143 $result = mysql_query($query) or displayerror(mysql_error() . "Copy for forum failed L:1136");
01144 $row = mysql_fetch_assoc($result);
01145 $compId = $row['MAX'] + 1;
01146
01147 $query = "SELECT * FROM `forum_module` WHERE `page_modulecomponentid`=$moduleComponentId";
01148 $result = mysql_query($query);
01149 $rows = mysql_num_rows($result);
01150 while($forummodule_content = mysql_fetch_assoc($result)){
01151 $forummodule_query="INSERT INTO `forum_module` (`page_modulecomponentid` ,`forum_description` ,`forum_moderated` ," .
01152 "`total_thread_count` ,`last_post_userid` ,`last_post_datetime` )" .
01153 " VALUES ($compId," .
01154 "'".mysql_escape_string($forummodule_content['forum_description'])."'," .
01155 " '".mysql_escape_string($forummodule_content['forum_moderated'])."'," .
01156 " '".mysql_escape_string($forummodule_content['total_thread_count'])."' , " .
01157
01158 " '".mysql_escape_string($forummodule_content['last_post_userid'])."', " .
01159 "'".mysql_escape_string($forummodule_content['last_post_datetime'])."')";
01160 mysql_query($forummodule_query) or displayerror(mysql_error()."Copy for forum failed L:1153");
01161 $rows -= mysql_affected_rows();
01162 }
01163 if($rows!=0)
01164 return false;
01165
01166 $query = "SELECT * FROM `forum_posts` WHERE `page_modulecomponentid`=$moduleComponentId";
01167 $result = mysql_query($query);
01168 $rows = mysql_num_rows($result);
01169
01170 while($forumanswer_content = mysql_fetch_assoc($result)){
01171 $forumanswer_query="INSERT INTO `forum_posts` (`page_modulecomponentid` ,`forum_thread_id` ,`forum_post_id` ,`forum_post_user_id` ,`forum_post_title` ," .
01172 "`forum_post_content` ,`forum_post_datetime` ,`forum_post_approve`) VALUES ($compId, '".mysql_escape_string($forumanswer_content['forum_thread_id'])."'," .
01173 " '".mysql_escape_string($forumanswer_content['forum_post_id'])."', '".mysql_escape_string($forumanswer_content['forum_post_user_id']).
01174 "', '".mysql_escape_string($forumanswer_content['forum_post_title'])."' , '".mysql_escape_string($forumanswer_content['forum_post_content'])."" .
01175 "' , '".mysql_escape_string($forumanswer_content['forum_post_datetime'])."', '".mysql_escape_string($forumanswer_content['forum_post_approve'])."')";
01176 mysql_query($forumanswer_query) or displayerror(mysql_error()."Copy for forum failed L:1169");
01177 $rows -= mysql_affected_rows();
01178 }
01179 if($rows!=0)
01180 return false;
01181
01182 $query = "SELECT * FROM `forum_threads` WHERE `page_modulecomponentid`=$moduleComponentId";
01183 $result = mysql_query($query);
01184 $rows = mysql_num_rows($result);
01185 while($forumquestion_content = mysql_fetch_assoc($result)){
01186 $forumquestion_query="INSERT INTO `forum_threads` (`page_modulecomponentid` ,`forum_thread_id` ,`forum_thread_category` ," .
01187 "`forum_access_status` ,`forum_thread_topic` ,`forum_detail` ,`forum_thread_user_id` ,`forum_thread_datetime` ,`forum_post_approve` ,`forum_thread_viewcount` ," .
01188 "`forum_thread_last_post_userid` ,`forum_thread_lastpost_date`) VALUES ($compId," .
01189 " '".mysql_escape_string($forumquestion_content['forum_thread_id'])."', " .
01190 "'".mysql_escape_string($forumquestion_content['forum_thread_category'])."'," .
01191 " '".mysql_escape_string($forumquestion_content['forum_access_status'])."'," .
01192 " '".mysql_escape_string($forumquestion_content['forum_thread_topic'])."' ," .
01193 " '".mysql_escape_string($forumquestion_content['forum_detail'])."' , " .
01194 "'".mysql_escape_string($forumquestion_content['forum_detail'])."', " .
01195 "'".mysql_escape_string($forumquestion_content['forum_thread_datetime'])."'," .
01196 " '".mysql_escape_string($forumquestion_content['forum_post_approve'])."', " .
01197 "'".mysql_escape_string($forumquestion_content['forum_thread_viewcount'])."'," .
01198
01199 " '".mysql_escape_string($forumquestion_content['forum_thread_last_post_userid'])."', " .
01200 "'".mysql_escape_string($forumquestion_content['forum_thread_lastpost_date'])."')";
01201 mysql_query($forumquestion_query) or displayerror(mysql_error()."Copy for forum failed L:1194");
01202 $rows -= mysql_affected_rows();
01203 }
01204 if($rows!=0)
01205 return false;
01206 return $compId;
01207 }
01208 }
01209