Source for file forum-defs.php

Documentation is available at forum-defs.php

  1. <?php
  2. /*######################################################################*/
  3. /* CATALYST Php Source Code */
  4. /* Copyright (C) 2002 Paul Waite */
  5. /* */
  6. /* -------------------------------------------------------------------- */
  7. /* This program is free software; you can redistribute it and/or modify */
  8. /* it under the terms of the GNU General Public License as published by */
  9. /* the Free Software Foundation; either version 2 of the License, or */
  10. /* (at your option) any later version. */
  11. /* */
  12. /* This program is distributed in the hope that it will be useful, */
  13. /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
  14. /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
  15. /* GNU General Public License for more details. */
  16. /* */
  17. /* You should have received a copy of the GNU General Public License */
  18. /* along with this program; if not, write to: */
  19. /* The Free Software Foundation, Inc., 59 Temple Place, Suite 330, */
  20. /* Boston, MA 02111-1307 USA */
  21. /* -------------------------------------------------------------------- */
  22. /* */
  23. /* Module: forum */
  24. /* Filename: forum-defs.php */
  25. /* Author: Mark Kessell */
  26. /* Description: Definitions for content forums, threads and messages */
  27. /* management in webpages. */
  28. /* */
  29. /*######################################################################*/
  30. /** @package forums */// DEFINITIONS
  31.  
  32. /** A new forum thread */
  33. ("NEW_THREAD", "NT");
  34.  
  35. /** A brand new forum */
  36. ("NEW_FORUM", "NF");
  37.  
  38. /** A new forum thread message */
  39. ("NEW_MSG", "NM");
  40.  
  41. // ----------------------------------------------------------------------
  42. /**
  43. * The forum class.
  44. * @package forums
  45. */
  46. class forum extends HTMLObject {
  47. var $forum_id;
  48. var $forum_name;
  49. var $forum_desc;
  50. var $enabled = true;
  51. var $private = false;
  52. var $moderator; // = array();
  53. var $posts;
  54. var $last_author;
  55. var $date_last_author;
  56. var $threadlast_author;
  57. var $new_topic;
  58.  
  59. // forum title
  60. var $forum_title = "Default Axyl Forums";
  61. var $error_msg;
  62.  
  63. var $forum_threads = array();
  64. var $forum_members = array(); // only if forum is a private forum.
  65.  
  66.  
  67. function forum ($forum_id=NEW_FORUM) {
  68. // Forum constructor.
  69. debugbr("FORUM CONSTRUCTOR.");
  70. $forum_id = trim($forum_id);
  71. $this->forum_id = $forum_id;
  72. if ( $this->forum_id != NEW_FORUM && is_numeric($this->forum_id)) {
  73. $this->get_forum();
  74. }
  75.  
  76. // run the POSTprocess function
  77. $this->POSTprocess();
  78. } // forum
  79.  
  80.  
  81. function set_forum_greeting($title) {
  82. // sets the forums title. not to be confused with the forum_name
  83. if ( trim($title) != "" )
  84. $this->forum_title = $title;
  85. } // set_forum_pagetitle
  86.  
  87.  
  88. function get_forum () {
  89. // Gets the forum record, and it's associated parent messages (threads).
  90. $q = "select * from ax_forum where forum_id=$this->forum_id";
  91. $qQ = new dbrecords($q);
  92.  
  93. if ( $qQ->hasdata ) {
  94. // load forum details
  95. $this->forum_name = $qQ->field("forum_name");
  96. $this->forum_desc = $qQ->field("forum_desc");
  97. $this->enabled = $qQ->istrue("enabled");
  98. $this->private = $qQ->istrue("private");
  99. debugbr("moderators: ".$qQ->field("moderator"));
  100. $this->moderator = $qQ->field("moderator");
  101. /*if ( substr_count($this->moderator, ',') == 0 && trim($this->moderator) != "" ) {
  102. $this->moderator[] = $qQ->field("moderator");
  103. } else {
  104. $this->moderator[] = explode(',',$qQ->field("moderator"));
  105. }*/
  106. $this->get_threads();
  107.  
  108. // get forum members if it's a private forum
  109. if ($this->private) {
  110. $m = "select user_id from ax_forum_member where forum_id=$this->forum_id";
  111. $mM = new dbrecords($m);
  112.  
  113. if ( $mM->hasdata ) {
  114. do {
  115. $this->forum_members[$mM->fields("user_id")] = $mM->fields("user_id");
  116. } while ( $mM->get_next() );
  117. }
  118. } // load members for private forum
  119. } else {
  120. $this->forum_id = '';
  121. }
  122. } // get_forum
  123.  
  124.  
  125. function save_forum() {
  126. // save forum details to database.
  127. global $mode;
  128.  
  129. if ( $this->forum_id == NEW_FORUM ) {
  130. // is an insert
  131. $query = new dbinsert("ax_forum");
  132. $fid = get_next_sequencevalue("seq_forum_id", "ax_forum", "forum_id");
  133. $query->set("forum_id", $fid);
  134. } else {
  135. // is an update
  136. $query = new dbupdate("ax_forum");
  137. $query->where("forum_id=$this->forum_id");
  138. }
  139.  
  140. $query->set("forum_name", $this->forum_name);
  141. $query->set("forum_desc", $this->forum_desc);
  142. $query->set("enabled", $this->enabled);
  143. $query->set("private", $this->private);
  144. //$query->set("moderator", implode(',',$this->moderator));
  145. $query->set("moderator", $this->moderator);
  146.  
  147. if ( $query->execute() ) {
  148. $this->error_msg = "Forum Record SAVED.";
  149. unset($mode);
  150. unset($forum_id);
  151. if ( $this->forum_id == NEW_FORUM ) {
  152. $this->forum_id = $fid;
  153. }
  154. }
  155. } // save_forum
  156.  
  157.  
  158. function add_member($user_id) {
  159. // add a member to a private forum.
  160. if ($this->private) {
  161.  
  162. } else {
  163. // this is a public board.
  164. // raise error and display
  165. $this->error_msg = "This is a PUBLIC forum. No need to add members to it, as all members have access to it.";
  166. }
  167. } // add_member
  168.  
  169.  
  170. function new_topic () {
  171. // start a new thread in this forum
  172. debugbr("forum_id within new_topic function: $this->forum_id");
  173. $this->new_topic = new forum_thread(NEW_THREAD, $this->forum_id);
  174. } // new_topic
  175.  
  176.  
  177. function get_threads() {
  178. // get the parent msgs for this forum
  179. debugbr("AQUIRING THREADS! FORUM_ID=$this->forum_id");
  180. if ( $this->forum_id != NEW_FORUM ) {
  181. debugbr("GETTING THREAD HEADERS!!!");
  182. $q = "select msg_id from ax_forum_msg where forum_id=$this->forum_id and ";
  183. $q .= "parent_thread_id is null order by sticky desc, last_modified desc";
  184. $qQ = new dbrecords($q);
  185.  
  186. if ( $qQ->hasdata ) {
  187. do {
  188. $this->forum_threads[$qQ->field("msg_id")] = new forum_thread($qQ->field("msg_id"), $this->forum_id);
  189. $this->forum_threads[$qQ->field("msg_id")]->set_moderator($this->moderator);
  190. } while ( $qQ->get_next() );
  191. }
  192. }
  193.  
  194. debugbr("the count of threads in this forum: ".count($this->forum_threads));
  195. } // get_threads
  196.  
  197.  
  198. /** disable the forum from showing */
  199.  
  200. function disable_forum () {
  201. $this->enabled =false;
  202. } // disable_forum
  203.  
  204.  
  205. /** enable the forum so it's visible again */
  206.  
  207. function enable_forum() {
  208. $this->enabled = true;
  209. } // enable_forum
  210.  
  211.  
  212. function delete_forum() {
  213. // deletes the forum
  214. // delete disabled forums only, or does it not matter?
  215. } // delete_forum
  216.  
  217.  
  218. function html () {
  219. // display the html required for the page.
  220. global $RESPONSE, $mode, $forum_id, $thread_id;
  221. global $SaveForum_x, $BackForum_x, $CancelForum_x, $locked, $sticky;
  222. global $SaveThread_x, $BackThread_x, $CancelThread_x;
  223. global $SaveMsg_x, $BackMsg_x, $CancelMsg_x, $hide, $msg_id, $thread_id;
  224.  
  225. $s = "";
  226.  
  227. debugbr("and the current mode is: $mode");
  228.  
  229. if ( isset($BackForum_x) || isset($CancelForum_x) ) {
  230. $mode = '';
  231. }
  232.  
  233. if ( isset($BackThread_x) || isset($CancelThread_x) ) {
  234. $mode = 'view';
  235. }
  236.  
  237. if ( isset($BackMsg_x) || isset($CancelMsg_x) ) {
  238. $mode = 'viewthread';
  239. }
  240.  
  241. $T = new table ("forum_html");
  242. $T->setwidth("100%");
  243. $T->setborder(0);
  244. $T->setpadding(4,1);
  245. $T->setalign("center");
  246.  
  247. switch ($mode) {
  248. case "new":
  249. case "edit":
  250. // create and edit forums
  251. if ( $RESPONSE->ismemberof_group_in("Admin,Editor") ) {
  252. $T->tr();
  253. $T->td("Create/Edit Forum Details", "forumheadings" );
  254. $T->td_colspan(2);
  255. $T->tr();
  256. $T->td("<hr>");
  257. $T->td_colspan(2);
  258.  
  259. if ( trim($this->error_msg) != "" ) {
  260. $T->tr();
  261. $T->td("<font color=\"red\">$this->error_msg</font>");
  262. $T->td_colspan(2);
  263. $T->tr();
  264. $T->td("<hr>");
  265. $T->td_colspan(2);
  266. }
  267.  
  268. if ( $this->forum_id != NEW_FORUM ) {
  269. $fidlabel = new form_labelfield("fid", $this->forum_id);
  270. $fidlabel->setclass("axfmlbl");
  271. $T->tr();
  272. $T->td("Forum Id: ", "forumlabels");
  273. $T->td_width("20%");
  274. $T->td_alignment("right");
  275. $T->td($fidlabel->render());
  276. }
  277.  
  278. // Forum Name text field
  279. $forumname = new form_textfield("forum_name", "", $this->forum_name);
  280. $forumname->setstyle("width: 250");
  281. $forumname->setclass("axtxtbox");
  282. $T->tr();
  283. $T->td("Forum Name: ", "forumlabels");
  284. $T->td_width("20%");
  285. $T->td_alignment("right");
  286. $T->td($forumname->render());
  287.  
  288. // Forum Description
  289. $forumdesc = new form_memofield("forum_desc", "", $this->forum_desc);
  290. $forumdesc->setstyle("width: 250");
  291. $forumdesc->setclass("axmemo");
  292. $T->tr();
  293. $T->td("Forum Desc: ", "forumlabels");
  294. $T->td_width("20%");
  295. $T->td_alignment("right", "top");
  296. $T->td($forumdesc->render());
  297.  
  298. // Enabled
  299. $forumenabled = new form_checkbox("enabled");
  300. if ($this->enabled) {
  301. $forumenabled->check();
  302. } else {
  303. $forumenabled->uncheck();
  304. }
  305. $T->tr();
  306. $T->td("Enabled: ", "forumlabels");
  307. $T->td_width("20%");
  308. $T->td_alignment("right");
  309. $T->td($forumenabled->render(), "axchkbox");
  310.  
  311. debugbr("moderators: $this->moderators");
  312. debugbr("is array? ".is_array($this->moderators));
  313. debugbr("count of array: ".count($this->moderators));
  314. //debugbr("list of moderators: ".implode(', ', $this->moderators));
  315.  
  316. // Moderator
  317. $fm = "select u.user_id from ax_user u";
  318. if ( !$RESPONSE->ismemberof_group_in("Admin,Editor") ) {
  319. $tmp = ", ax_user_group ug where u.user_id=ug.user_id and ug.group_id=2";
  320. }
  321. if ( trim($tmp) != "" ) $fm .= " $tmp and u.user_id != 'guest' order by lower(u.user_id)";
  322. else $fm .= " where u.user_id != 'guest' order by lower(u.user_id)";
  323. $FM = new dbrecords($fm);
  324. $forummoderator = new form_combofield("moderator", "", $this->moderator, EDITABLE, "", 1, SINGLESELECT);
  325. $forummoderator->setstyle("width: 250");
  326. $forummoderator->setclass("axlistbox");
  327. $forummoderator->add_querydata($FM, "user_id", "user_id");
  328. $T->tr();
  329. $T->td("Moderator(s): ", "forumlabels");
  330. $T->td_width("20%");
  331. $T->td_alignment("right", "top");
  332. $T->td($forummoderator->render());
  333.  
  334. // POST button
  335. $pb = new form_imagebutton("SaveForum", "SaveForum", "", "lib/_save.gif", "", 57, 15);
  336. $cb = new form_imagebutton("CancelForum", "CancelForum", "", "lib/_cancel.gif", "", 57, 15);
  337. $T->tr();
  338. $T->td("&nbsp;");
  339. $T->td($cb->render() . " " . $pb->render());
  340. $T->td_alignment("left");
  341.  
  342. $fidh = new form_hiddenfield("forum_id", $this->forum_id);
  343. $mh = new form_hiddenfield("mode", $mode);
  344. $T->tr();
  345. $T->td($fidh->render().$mh->render());
  346. $T->td_colspan(2);
  347.  
  348. $F = new form("Create/Edit Forum");
  349. $F->set_fieldwidth_pct(100);
  350. $F->add($T);
  351. $s = $F->render();
  352. } else {
  353. $T->tr();
  354. $T->td("Only site Admins and Editors can create/delete or edit forums.");
  355. $s = $T->render();
  356. }
  357.  
  358. break;
  359. case "edmsg":
  360. // admins/editors and moderators can edit any message within a given forum
  361. if ( $RESPONSE->ismemberof_group_in("Admin,Editor") || $RESPONSE->userid == trim($this->moderator) ) {
  362. debugbr("<font color=\"red\">EDIT MESSAGE SECTION 1</font>");
  363. $F = new form("EditMsg");
  364. $F->set_fieldwidth_pct(100);
  365. $F->add($this->forum_threads[$thread_id]);
  366. $s = $F->render();
  367. }
  368. break;
  369. case "delthd":
  370. // allows an admin / editor to delete a particular message
  371. if ( $RESPONSE->ismemberof_group_in("Admin,Editor") || $RESPONSE->userid == trim($this->moderator) ) {
  372. debugbr("DELETING THREAD #$msg_id");
  373. if ( dbcommand("delete from ax_forum_msg where msg_id=$thread_id or parent_thread_id=$thread_id") ) {
  374. unset($this->forum_threads);
  375. $this->get_threads();
  376. }
  377. }
  378. case "view":
  379. // display the threads within the selected forum
  380. // get the thread.
  381. $thd = $this->forum_threads[$thread_id];
  382.  
  383. debugbr("<font color=\"red\">is thread an object: ".is_object($thd)."</font>");
  384. if ( trim($this->forum_id) != "" /*&& is_object($thd)*/ ) {
  385. // check the locked thread situation
  386. if ( ($RESPONSE->ismemberof_group_in("Admin,Editor") || $RESPONSE->userid == trim($this->moderator))
  387. && (trim($locked) == 1 || trim($locked) == 0) ) {
  388. switch ($locked) {
  389. case "1":
  390. debugbr("<font color=\"red\">LOCKING THREAD</font>");
  391. $thd->lock_thread();
  392. break;
  393. case "0":
  394. debugbr("<font color=\"red\">UNLOCKING THREAD</font>");
  395. $thd->unlock_thread();
  396. break;
  397. }
  398. unset($this->forum_threads);
  399. $this->get_threads();
  400. }
  401.  
  402. // check if a thread has been made sticky or not
  403. if ( ($RESPONSE->ismemberof_group_in("Admin,Editor") || $RESPONSE->userid == trim($this->moderator))
  404. && (trim($sticky) == 1 || trim($sticky) == 0) ) {
  405. switch ($sticky) {
  406. case "1":
  407. debugbr("<font color=\"red\">STICKY THREAD</font>");
  408. $thd->stick_thread();
  409. break;
  410. case "0":
  411. debugbr("<font color=\"red\">UNSTICKY THREAD</font>");
  412. $thd->unstick_thread();
  413. break;
  414. }
  415. unset($this->forum_threads);
  416. $this->get_threads();
  417. }
  418.  
  419. // display the forum threads.
  420. debugbr("IS THIS FORUM ENABLED? $this->enabled");
  421. debugbr("IS THIS FORUM name? $this->forum_name");
  422. $T->tr();
  423. $fl = "<a href=\"?mode=\" class=\"forumlink\">Forum List</a>";
  424. $T->td("$fl >> <b>$this->forum_name</b>");
  425. if ( !$RESPONSE->ismemberof_group("guest") && $this->enabled ) {
  426. $T->td("<a href=\"$RESPONSE->requested?mode=newthread&forum_id=$this->forum_id\" class=\"forumlink\">[New Topic]</a>");
  427. $T->td_colspan(3);
  428. $T->td_alignment("right");
  429. } else {
  430. $T->td_colspan(4);
  431. }
  432. $T->tr();
  433. $T->td("Topic", "threadtitle");
  434. $T->td_alignment("center");
  435. $T->td_width("70%");
  436. $T->td("Replies", "threadtitle");
  437. $T->td_alignment("center");
  438. $T->td_width("5%");
  439. $T->td("Author", "threadtitle");
  440. $T->td_alignment("center");
  441. $T->td_width("20%");
  442. $T->td("Views", "threadtitle");
  443. $T->td_alignment("center");
  444. $T->td_width("5%");
  445. /*$T->tr();
  446. $T->td("&nbsp;");
  447. $T->td_colspan(4);*/
  448.  
  449. // display the thread header messages
  450. if ( count($this->forum_threads) > 0 ) {
  451. // display the threads
  452. foreach ($this->forum_threads as $thread) {
  453. //debugbr("<font color=\"red\">THREAD LOCKED: $thread->locked</font>");
  454. if ( trim($thread->subject) == "" ) $thread->subject = "(no thread topic)";
  455. debugbr("<font color=\"red\">MODERATOR: $thread->moderator</font>");
  456. debugbr("<font color=\"red\">$RESPONSE->userid ==== $thread->moderator</font>");
  457.  
  458. if ($thread->enabled) {
  459. if ($thread->locked && !$thread->sticky) {
  460. //debugbr("<font color=\"red\">THREAD LOCKED AND ENABLED</font>");
  461. $tname = "<a href=\"$RESPONSE->requested?forum_id=$this->forum_id&thread_id=$thread->thread_id&mode=viewthread\" class=\"locked\">$thread->subject</a>";
  462. } elseif (!$thread->locked && $thread->sticky) {
  463. //debugbr("<font color=\"red\">THREAD STICKY AND ENABLED</font>");
  464. $tname = "STICKY: <a href=\"$RESPONSE->requested?forum_id=$this->forum_id&thread_id=$thread->thread_id&mode=viewthread\">".strtoupper($thread->subject)."</a>";
  465. } elseif ($thread->locked && $thread->sticky) {
  466. //debugbr("<font color=\"red\">THREAD LOCKED AND STICKY AND ENABLED</font>");
  467. $tname = "STICKY: <a href=\"$RESPONSE->requested?forum_id=$this->forum_id&thread_id=$thread->thread_id&mode=viewthread\" class=\"locked\">".strtoupper($thread->subject)."</a>";
  468. } else {
  469. //debugbr("<font color=\"red\">THREAD UNLOCKED AND NOT STICKY AND ENABLED</font>");
  470. $tname = "<a href=\"$RESPONSE->requested?forum_id=$this->forum_id&thread_id=$thread->thread_id&mode=viewthread\" class=\"forumlink\">$thread->subject</a>";
  471. }
  472. } else {
  473. $tname = "<a href=\"$RESPONSE->requested?forum_id=$this->forum_id&thread_id=$thread->thread_id&mode=viewthread\"><font color=\"red\"><i>$thread->subject</i></font></a>";
  474. }
  475.  
  476. if ( $RESPONSE->ismemberof_group_in("Admin,Editor") || $RESPONSE->userid == trim($thread->moderator) ) {
  477. if ($this->enabled) {
  478. if (!$thread->locked) {
  479. //debugbr("<font color=\"red\">THREAD UNLOCKED</font>");
  480. $tname .= "<br>";
  481. $tname .= "<a href=\"$RESPONSE->requested?forum_id=$this->forum_id&thread_id=$thread->thread_id&mode=view&locked=1\" class=\"forumlinkother\">";
  482. $tname .= "[LOCK]</a>";
  483. } else {
  484. //debugbr("<font color=\"red\">THREAD LOCKED</font>");
  485. $tname .= "<br>";
  486. $tname .= "<a href=\"$RESPONSE->requested?forum_id=$this->forum_id&thread_id=$thread->thread_id&mode=view&locked=0\" class=\"forumlinkother\">";
  487. $tname .= "[UNLOCK]</a>";
  488. }
  489.  
  490. if (!$thread->sticky) {
  491. //debugbr("<font color=\"red\">THREAD NOT STICKY</font>");
  492. $tname .= "<a href=\"$RESPONSE->requested?forum_id=$this->forum_id&thread_id=$thread->thread_id&mode=view&sticky=1\" class=\"forumlinkother\">";
  493. $tname .= "[STICK]</a>";
  494. } else {
  495. //debugbr("<font color=\"red\">THREAD STICKY</font>");
  496. $tname .= "<a href=\"$RESPONSE->requested?forum_id=$this->forum_id&thread_id=$thread->thread_id&mode=view&sticky=0\" class=\"forumlinkother\">";
  497. $tname .= "[UNSTICK]</a>";
  498. }
  499. }
  500. }
  501.  
  502.  
  503. $T->tr();
  504. $T->td("$tname");
  505. $T->td_width("70%");
  506. $T->td_alignment("left");
  507. $T->td($thread->replies);
  508. $T->td_width("5%");
  509. $T->td_alignment("center");
  510. $T->td($thread->author);
  511. $T->td_width("20%");
  512. $T->td_alignment("center");
  513. $T->td($thread->views);
  514. $T->td_width("5%");
  515. $T->td_alignment("center");
  516. $T->tr();
  517. $T->td("<hr>");
  518. $T->td_colspan(4);
  519. } // foreach
  520. } // if count(array) > 0
  521. } else {
  522. if ( trim($this->forum_id) == "" ) {
  523. $T->tr();
  524. $T->td("That Forum Id does not exist within the database");
  525. }
  526.  
  527. /*if ( !is_object($thd) ) {
  528. $T->tr();
  529. $T->td("That Thread does not exist within the selected Forum");
  530. }*/
  531. }
  532.  
  533. $s = $T->render();
  534. break;
  535. case "newthread":
  536. // start a new thread
  537. if ( !$RESPONSE->ismemberof_group("guest") ) {
  538. $this->new_topic();
  539. $F = new form("NewTopic");
  540. $F->set_fieldwidth_pct(100);
  541. $F->add($this->new_topic);
  542. $s = $F->render();
  543. } else {
  544. $T->tr();
  545. $T->td("You must be logged in in order to post a forum thread.");
  546. $s = $T->render();
  547. }
  548. break;
  549. case "reply":
  550. // reply to a thread message
  551. if ( !$RESPONSE->ismemberof_group("guest") ) {
  552. $thread = $this->forum_threads[$thread_id];
  553. if ($thread->enabled && !$thread->locked) {
  554. $F = new form("NewMsg");
  555. $F->set_fieldwidth_pct(100);
  556. $F->add($thread);
  557. $s = $F->render();
  558. } else {
  559. $T->tr();
  560. $T->td("This either LOCKED or DISABLED, and as a result, cannot by replied to.");
  561. $s = $T->render();
  562. }
  563. } else {
  564. $T->tr();
  565. $T->td("You must be logged in in order to post to a forum thread.");
  566. $s = $T->render();
  567. }
  568. break;
  569. case "delmsg":
  570. // allows an admin / editor to delete a particular message
  571. // dbcommand("delete from ax_forum_msg where msg_id=$msg_id and parent_thread_id=$msg_id");
  572. if ( $RESPONSE->ismemberof_group_in("Admin,Editor") || $RESPONSE->userid == trim($this->moderator) ) {
  573. debugbr("DELETING MESSAGE #$msg_id");
  574. dbcommand("delete from ax_forum_msg where msg_id=$msg_id");
  575. }
  576. case "viewthread":
  577. // view the messages within the thread
  578. if ( $this->forum_threads[$thread_id] ) {
  579. $thread = $this->forum_threads[$thread_id];
  580. debugbr("thread object: $thread");
  581. if ( !isset($BackMsg_x) && !isset($CancelMsg_x) && !isset($SaveThread_x) && !isset($SaveMsg_x) && trim($mode) != "edmsg" ) {
  582. $thread->inc_thread_views();
  583. }
  584.  
  585. $s = $thread->render();
  586. } else {
  587. $T->tr();
  588. $T->td("That Thread Id does not exist within the database.");
  589. $s = $T->render();
  590. }
  591.  
  592. break;
  593. case "hidden":
  594. // enable or disable the forum so only admins and editors can browse them
  595. if ( $RESPONSE->ismemberof_group_in("Admin,Editor") ) {
  596. if ( trim($hide) == 't' ) {
  597. $this->enable_forum();
  598. } else {
  599. $this->disable_forum();
  600. }
  601. $this->save_forum();
  602. if ( trim($hide) != "" ) {
  603. // enable or disable all threads & messages within this forum as required.
  604. debugbr("ENABLING/DISABLING FORUM THREADS AND MESSAGES");
  605. $query = new dbupdate("ax_forum_msg");
  606. $query->where("forum_id=$this->forum_id");
  607. $query->set("enabled", $this->enabled);
  608. $query->execute();
  609. }
  610. }
  611. //break;
  612. default:
  613. // display the forums that already exist.
  614. // and are not disabled
  615. debugbr("this is the default mode. displaying the forums list");
  616. $q = "select * from ax_forum";
  617. if ( !$RESPONSE->ismemberof_group_in("Admin,Editor") ) {
  618. $q .= " where enabled=TRUE";
  619. }
  620. $qQ = new dbrecords($q);
  621.  
  622. $T->tr();
  623. $T->td("&nbsp;");
  624. $T->td_colspan(3);
  625. $T->tr();
  626. $T->td($this->forum_title, "forumgreetingdisp");
  627. $T->td_colspan(4);
  628. $T->td_alignment("left");
  629. $T->tr();
  630. $T->td("Forum Name", "forumtitle" );
  631. if ( $RESPONSE->ismemberof_group_in("Admin,Editor") ) {
  632. $T->td("<a href=\"$RESPONSE->requested?forum_id=".NEW_FORUM."&mode=new\" class=\"forumlinkwhite\">[NEW FORUM]</a>", "forumtitle" );
  633. } else {
  634. $T->td("&nbsp;", "forumtitle");
  635. }
  636. $T->td_colspan(3);
  637. $T->td_alignment("center");
  638.  
  639. $T->tr();
  640. $T->td("<hr>");
  641. $T->td_colspan(4);
  642.  
  643. if ( $qQ->hasdata ) {
  644. do {
  645. if (!$qQ->istrue("enabled")) {
  646. $fname = "<a href=\"$RESPONSE->requested?forum_id=".$qQ->field("forum_id")."&mode=view\" class=\"disabled\">".strtoupper($qQ->field("forum_name"))."</a>";
  647. } else {
  648. $fname = "<a href=\"$RESPONSE->requested?forum_id=".$qQ->field("forum_id")."&mode=view\" class=\"forumlink\">".strtoupper($qQ->field("forum_name"))."</a>";
  649. }
  650. $T->tr();
  651. $T->td("$fname");
  652. $T->td_width("80%");
  653. if ( $RESPONSE->ismemberof_group_in("Admin,Editor") ) {
  654. $T->td("<a href=\"$RESPONSE->requested?forum_id=".$qQ->field("forum_id")."&mode=edit\" class=\"forumlink\">[EDIT]</a>");
  655. $T->td_width("10%");
  656. $T->td("&nbsp;");
  657. if (!$qQ->istrue("enabled")) {
  658. $T->td("<a href=\"$RESPONSE->requested?forum_id=".$qQ->field("forum_id")."&mode=hidden&hide=t\" class=\"forumlink\">[ENABLE]</a>");
  659. } else {
  660. $T->td("<a href=\"$RESPONSE->requested?forum_id=".$qQ->field("forum_id")."&mode=hidden&hide=f\" class=\"forumlink\">[DISABLE]</a>");
  661. }
  662. $T->td_width("10%");
  663. } else {
  664. $T->td_colspan(4);
  665. }
  666. //if ( $RESPONSE->ismemberof_group_in("Admin,Editor") ) {
  667. $T->tr();
  668. $T->td("<hr>");
  669. $T->td_colspan(4);
  670. //}
  671. } while ( $qQ->get_next() );
  672. }
  673.  
  674. $s = $T->render();
  675. break;
  676. }
  677.  
  678.  
  679. return $s;
  680. } // html
  681.  
  682.  
  683. function POSTprocess() {
  684. // this function takes care of the new messages that come in.
  685. global $forum_desc, $forum_name, $enabled, $private, $moderator;
  686. global $forum_members, $RESPONSE, $SaveForum, $SaveForum_x;
  687. global $SaveThread, $SaveThread_x, $SaveMsg, $SaveMsg_x;
  688. global $msg_subject, $msg_text, $date_posted, $author, $mode;
  689. global $msg_id, $thread_id;
  690.  
  691. debugbr("POST PROCESS!!!");
  692.  
  693. if ( isset($SaveForum_x) ) {
  694. // saving new and modified forum details
  695. if ( trim($forum_name) != "" ) {
  696. debugbr("SAVING FORUM!!!");
  697. $this->forum_name = trim($forum_name);
  698. $this->forum_desc = trim($forum_desc);
  699. $this->enabled = isset($enabled);
  700. $this->private = isset($private);
  701. $this->moderator = $moderator;
  702.  
  703. $this->save_forum();
  704. $mode = '';
  705. } else {
  706. debugbr("NOT SAVING FORUM!!!");
  707. if (trim($forum_name) == "") {
  708. debugbr("FORUM NAME IS BLANK!");
  709. $this->error_msg .= "Forum must have a NAME.";
  710. }
  711. }
  712. } else
  713. if ( isset($SaveThread_x) ) {
  714. // saving new thread post
  715. if ( trim($msg_subject) != "" ) {
  716. debugbr("SAVING THREAD!!!");
  717. $this->new_topic();
  718. $this->new_topic->subject = trim($msg_subject);
  719. $this->new_topic->text = trim($msg_text);
  720. $this->new_topic->author = trim($author);
  721. $this->new_topic->date_posted = trim($date_posted);
  722. $this->new_topic->save_thread();
  723. $this->get_threads();
  724. $mode = 'viewthread';
  725. } else {
  726. debugbr("NOT SAVING THREAD!!!");
  727. if (trim($msg_subject) == "") {
  728. debugbr("THREAD'S SUBJECT IS BLANK!");
  729. $this->new_topic->newmsg->error_msg .= "Thread must have a SUBJECT.";
  730. }
  731.  
  732. }
  733. } else
  734. if ( isset($SaveMsg_x) ) {
  735. debugbr("SAVING THE MESSAGE REPLY!!! OR MSG EDIT");
  736. if ( trim($msg_subject) != "" ) {
  737. debugbr("SAVING MSG!!!");
  738. debugbr("msg_id = $msg_id and thread_id = $thread_id");
  739. debugbr("subject: $msg_subject, text: $msg_text");
  740. $thread = $this->forum_threads[$thread_id];
  741.  
  742. if ( trim($mode) != "edmsg" ) {
  743. $thread->new_msg();
  744. $thread->newmsg->msg_subject = trim($msg_subject);
  745. $thread->newmsg->msg_text = trim($msg_text);
  746. $thread->newmsg->author = trim($author);
  747. $thread->newmsg->date_posted = trim($date_posted);
  748. if ( $thread->newmsg->save_msg() ) {
  749. $thread->modify_replies();
  750. }
  751. } else {
  752. $thread->render();
  753. $thread->get_thread_header();
  754. $thread->get_thread();
  755. }
  756. $mode = 'viewthread';
  757. } else {
  758. debugbr("NOT SAVING THREAD!!!");
  759. if (trim($msg_subject) == "") {
  760. debugbr("MSG'S SUBJECT IS BLANK!");
  761. $thread->error_msg .= "Message must have a SUBJECT.";
  762. }
  763.  
  764. }
  765. // reset the mode so it doesn't stay at the enter msg screen.
  766. //$mode = "viewthread";
  767. //$this->render();
  768. }
  769. } // POSTprocess
  770.  
  771. } // class forum
  772. // ----------------------------------------------------------------------
  773.  
  774. /**
  775. * The forum thread class.
  776. * @package forums
  777. */
  778. class forum_thread extends forum {
  779. var $locked = false;
  780. var $sticky = false;
  781. var $views = 0;
  782. var $subject;
  783. var $enabled = true;
  784. var $text;
  785. var $author;
  786. var $thread_id;
  787. var $replies = 0;
  788. var $date_posted;
  789. var $forum_id;
  790. var $thread_msgs = array();
  791. var $newmsg;
  792. var $forum_moderator;
  793.  
  794. function forum_thread ($thread_id=NEW_THREAD, $forum_id) {
  795. // main forum_thread contructor
  796.  
  797. if ( isset($forum_id) ) {
  798. $this->thread_id = trim($thread_id);
  799. $this->forum_id = trim($forum_id);
  800. }
  801. debugbr("thread_id within the thread object: $this->thread_id");
  802. if ( $this->thread_id != NEW_THREAD && is_numeric($this->thread_id) ) {
  803. debugbr("getting the thread head message");
  804. $this->get_thread_header();
  805. }
  806.  
  807. if ( $this->thread_id == NEW_THREAD ) {
  808. $this->newmsg = new thread_msg(NEW_MSG, $this->thread_id);
  809. }
  810. } // forum_thread constructor
  811.  
  812.  
  813. function get_thread_header() {
  814. // get the message for the thread header for a particular forum
  815. $q = "select *, to_char(last_modified, 'DD/MM/YYYY HH:MI am') as date_posted ";
  816. $q .= "from ax_forum_msg where msg_id=$this->thread_id and forum_id=$this->forum_id";
  817. $qQ = new dbrecords($q);
  818.  
  819. if ( $qQ->hasdata ) {
  820. $this->subject = trim($qQ->field("msg_subject"));
  821. $this->text = trim($qQ->field("msg_text"));
  822. $this->author = trim($qQ->field("msg_author"));
  823. $this->date_posted = trim($qQ->field("date_posted"));
  824. $this->views = $qQ->field("views");
  825. $this->locked = $qQ->istrue("locked");
  826. $this->sticky = $qQ->istrue("sticky");
  827. $this->enabled = $qQ->istrue("enabled");
  828. $this->replies = $qQ->field("replies");
  829.  
  830. if ( trim($qQ->field("replies")) != "" ) $this->replies = $qQ->field("replies");
  831. }
  832. } // get_thread_header
  833.  
  834.  
  835. function set_moderator($mod="") {
  836. // sets the moderator for this thread
  837. $this->moderator = trim($mod);
  838. } // set_moderator
  839.  
  840.  
  841. function save_thread() {
  842. // save the thread information.
  843. // remember, it's just a message that has no parent message.
  844. global $mode, $thread_id;
  845.  
  846. debugbr("the forum_id = $this->forum_id");
  847.  
  848. if ( trim($this->thread_id) == NEW_THREAD ) {
  849. // then it's an insert
  850. $query = new dbinsert("ax_forum_msg");
  851. $tid = get_next_sequencevalue("seq_msg_id", "ax_forum_msg", "msg_id");
  852. $query->set("msg_id", $tid);
  853. $query->set("last_modified", 'now()');
  854. } else {
  855. // else it's an update
  856. $query = new dbupdate("ax_forum_msg");
  857. $query->where("msg_id=$this->thread_id");
  858. }
  859.  
  860. $query->set("msg_subject", $this->subject);
  861. $query->set("msg_text", $this->text);
  862. $query->set("msg_author", $this->author);
  863. $query->set("views", $this->views);
  864. $query->set("forum_id", $this->forum_id);
  865. $query->set("replies", $this->replies);
  866. $query->set("sticky", $this->sticky);
  867. $query->set("locked", $this->locked);
  868.  
  869. if ( $query->execute() ) {
  870. if ( $this->thread_id == NEW_THREAD ) {
  871. $this->thread_id = $tid;
  872. $thread_id = $tid;
  873. }
  874.  
  875. }
  876.  
  877. } // save_thread
  878.  
  879.  
  880. function lock_thread() {
  881. // lock the selected thread object
  882. $this->locked = true;
  883. $tup = new dbupdate("ax_forum_msg");
  884. $tup->set("locked", $this->locked);
  885. $tup->where("msg_id=$this->thread_id");
  886. $tup->execute();
  887. } // lock_thread
  888.  
  889.  
  890. function unlock_thread() {
  891. // unlock the selected thread object
  892. $this->locked = false;
  893. $tup = new dbupdate("ax_forum_msg");
  894. $tup->set("locked", $this->locked);
  895. $tup->where("msg_id=$this->thread_id");
  896. $tup->execute();
  897. } // unlock_thread
  898.  
  899.  
  900. function stick_thread() {
  901. // stick the selected thread object
  902. $this->sticky = true;
  903. $tup = new dbupdate("ax_forum_msg");
  904. $tup->set("sticky", $this->sticky);
  905. $tup->where("msg_id=$this->thread_id");
  906. $tup->execute();
  907. } // stick_thread
  908.  
  909.  
  910. function unstick_thread() {
  911. // unstick the selected thread object
  912. $this->sticky = false;
  913. $tup = new dbupdate("ax_forum_msg");
  914. $tup->set("sticky", $this->sticky);
  915. $tup->where("msg_id=$this->thread_id");
  916. $tup->execute();
  917. } // unstick_thread
  918.  
  919.  
  920. function inc_thread_views() {
  921. // this function writed to the views field in the thread message
  922. debugbr("<font color=\"red\">UPDATING THE VIEWS</font>");
  923. $this->views = $this->views + 1;
  924. $tup = new dbupdate("ax_forum_msg");
  925. $tup->set("views", $this->views);
  926. $tup->where("msg_id=$this->thread_id");
  927. $tup->execute();
  928. } // inc_thread_views
  929.  
  930.  
  931. function modify_replies() {
  932. // adjusts the threads replies field
  933. debugbr("<font color=\"red\">UPDATING THE REPLIES</font>");
  934. $this->replies = $this->replies + 1;
  935. $tup = new dbupdate("ax_forum_msg");
  936. $tup->set("replies", $this->replies);
  937. $tup->where("msg_id=$this->thread_id");
  938. $tup->execute();
  939. } // modify_replies
  940.  
  941.  
  942. function get_thread() {
  943. // Get the thread msgs.
  944. if ( $this->thread_id != NEW_THREAD ) {
  945. $q = "select msg_id from ax_forum_msg where forum_id=$this->forum_id and parent_thread_id=$this->thread_id";
  946. $q .= " order by last_modified asc";
  947. $qQ = new dbrecords($q);
  948. if ( $qQ->hasdata ) {
  949. do {
  950. $this->thread_msgs[$qQ->field("msg_id")] = new thread_msg($qQ->field("msg_id"), $this->thread_id);
  951. } while ( $qQ->get_next() );
  952. }
  953. // increment the "views" field in the thread record.
  954. //$this->inc_thread_views();
  955. }
  956. debugbr("the count of msgs in this thread: ".count($this->thread_msgs));
  957. } // get_thread
  958.  
  959.  
  960. function new_msg() {
  961. // creates a new message object
  962. $this->newmsg = new thread_msg(NEW_MSG, $this->thread_id);
  963. } // new_msg
  964.  
  965.  
  966. function html() {
  967. // display the message form here
  968. global $mode, $RESPONSE, $forum_id, $msg_id, $SaveMsg_x;
  969. global $msg_subject, $msg_text;
  970.  
  971. $s = "";
  972. if ( $this->thread_id == NEW_THREAD ) {
  973. $s = $this->newmsg->new_msg();
  974. } else {
  975. switch ($mode) {
  976. case "reply":
  977. $this->new_msg();
  978. $s = $this->newmsg->new_msg();
  979. break;
  980. case "edmsg":
  981. // edit a message. admin and editor function only.
  982. debugbr("EDITING THE MESSAGE");
  983. $emsg = new thread_msg($msg_id, $this->thread_id);
  984. if ( !isset($SaveMsg_x) ) {
  985. $s = $emsg->edit_msg();
  986. } else {
  987. $emsg->msg_subject = trim($msg_subject);
  988. $emsg->msg_text = trim($msg_text);
  989. $emsg->save_msg();
  990. }
  991. break;
  992. default:
  993. $this->get_thread();
  994. $this->get_thread_header();
  995. $T = new table("ForumThread");
  996. $T->setpadding(4,1);
  997. $T->setborder(0);
  998. $T->setwidth("80%");
  999. $T->setalign("center");
  1000.  
  1001. // thread header
  1002. $T->tr();
  1003. $tl = "<a href=\"$RESPONSE->requested?mode=view&forum_id=$forum_id\" class=\"forumlink\">Thread List</a>";
  1004. $fl = "<a href=\"$RESPONSE->requested?mode=\" class=\"forumlink\">Forum List</a>";
  1005. if ($this->locked) {
  1006. $T->td("$fl >> $tl >> <b>$this->subject (This thread has been LOCKED)</b>");
  1007. } else {
  1008. $T->td("$fl >> $tl >> <b>$this->subject</b>");
  1009. }
  1010. $T->td_colspan(2);
  1011. $T->tr();
  1012. $T->td("&nbsp;");
  1013. $T->td_colspan(2);
  1014. // display the thread header message
  1015. // subject
  1016. $T->tr();
  1017. $T->td("<b>$this->subject</b>", "forumtitle" );
  1018. $T->td_contentcss("font-size:10pt");
  1019. $T->td_alignment("left");
  1020. $T->td_colspan(2);
  1021.  
  1022. // message info and controls
  1023. if ($this->enabled && !$this->locked) {
  1024. $quote = "<a href=\"$RESPONSE->requested?mode=reply&forum_id=$this->forum_id&thread_id=$this->thread_id&quote=$this->thread_id\" class=\"forumlinkother\">[REPLY]</a>";
  1025. } else {
  1026. $quote = "&nbsp;";
  1027. }
  1028. if ( $RESPONSE->ismemberof_group_in("Admin,Editor") || $RESPONSE->userid == trim($this->moderator) ) {
  1029. $dthd = "<a href=\"$RESPONSE->requested?mode=delthd&msg_id=$this->thread_id&forum_id=$this->forum_id&thread_id=$this->thread_id\" class=\"forumlinkother\">[DELETE]</a>";
  1030. $ethd = "<a href=\"$RESPONSE->requested?mode=edmsg&msg_id=$this->thread_id&forum_id=$this->forum_id&thread_id=$this->thread_id\" class=\"forumlinkother\">[EDIT]</a>";
  1031. }
  1032. $T->tr();
  1033. $T->td("Thread last updated on $this->date_posted", "forummsginfo" );
  1034. if ( !$RESPONSE->ismemberof_group("guest") ) {
  1035. $T->td($quote."&nbsp;".$dthd."&nbsp;".$ethd);
  1036. $T->td_width("20%");
  1037. }
  1038.  
  1039. // message body
  1040. $T->tr();
  1041. $T->td(str_replace("\n", "<br>", $this->text));
  1042. $T->td_alignment("left", "top");
  1043. $T->td_colspan(2);
  1044.  
  1045. // the replies
  1046. if ( count($this->thread_msgs) > 0 ) {
  1047. $T->tr();
  1048. $T->td("<hr>");
  1049. $T->td_colspan(2);
  1050. $temp = "";
  1051. foreach ( $this->thread_msgs as $msg ) {
  1052. // display the thread header message
  1053. // subject
  1054. debugbr("subject: $msg->msg_subject, text: $msg->msg_text");
  1055. if ( trim($temp) != "" ) {
  1056. $T->tr();
  1057. $T->td("<hr>");
  1058. $T->td_colspan(2);
  1059. }
  1060. $T->tr();
  1061. $T->td("<b>$msg->msg_subject</b>");
  1062. $T->td_contentcss("font-size:10pt");
  1063. $T->td_alignment("left");
  1064. $T->td_colspan(2);
  1065.  
  1066. // message info and controls
  1067. if ($this->enabled && !$this->locked) {
  1068. $quote = "<a href=\"$RESPONSE->requested?mode=reply&forum_id=$msg->forum_id&thread_id=$msg->thread_id&quote=$msg->msg_id\" class=\"forumlinkother\">[REPLY]</a>";
  1069. } else {
  1070. $quote = "&nbsp;";
  1071. }
  1072. if ( $RESPONSE->ismemberof_group_in("Admin,Editor") || $RESPONSE->userid == trim($this->moderator)) {
  1073. $dmsg = "<a href=\"$RESPONSE->requested?mode=delmsg&msg_id=$msg->msg_id&forum_id=$msg->forum_id&thread_id=$msg->thread_id\" class=\"forumlinkother\">[DELETE]</a>";
  1074. $ethd = "<a href=\"$RESPONSE->requested?mode=edmsg&msg_id=$msg->msg_id&forum_id=$msg->forum_id&thread_id=$msg->thread_id\" class=\"forumlinkother\">[EDIT]</a>";
  1075. }
  1076. $T->tr();
  1077. $T->td("Posted by $msg->author on $msg->date_posted", "forumlinkother" );
  1078. if ( !$RESPONSE->ismemberof_group("guest") ) {
  1079. $T->td($quote."&nbsp;".$dmsg."&nbsp;".$ethd);
  1080. $T->td_width("20%");
  1081. }
  1082.  
  1083. // message body
  1084. $T->tr();
  1085. $T->td(str_replace("\n", "<br>", $msg->msg_text));
  1086. $T->td_alignment("left", "top");
  1087. $T->td_colspan(2);
  1088.  
  1089. $temp = "fish";
  1090. }
  1091. }
  1092. $s = $T->render();
  1093. } // switch ($mode)
  1094.  
  1095. }
  1096.  
  1097. return $s;
  1098. } // html
  1099.  
  1100. } // class forum_thread
  1101. // ----------------------------------------------------------------------
  1102.  
  1103. /**
  1104. * The thread message class.
  1105. * @package forums
  1106. */
  1107. class thread_msg extends forum_thread {
  1108. var $locked = false;
  1109. var $sticky = false;
  1110. var $msg_id;
  1111. var $thread_id;
  1112. var $msg_subject;
  1113. var $msg_text;
  1114. var $author;
  1115. var $date_posted;
  1116. var $enabled = true;
  1117. var $ParentMsg;
  1118. var $forum_id;
  1119. var $error_msg;
  1120.  
  1121. function thread_msg ($msg_id=NEW_MSG, $thread_id) {
  1122. // Msg Constructor
  1123.  
  1124. debugbr("message_id: $msg_id and thread_id: $thread_id");
  1125. if ( isset($thread_id) ) {
  1126. $this->thread_id = trim($thread_id);
  1127. $this->msg_id = trim($msg_id);
  1128. }
  1129.  
  1130. if ( isset($forum_id) ) $this->forum_id = $forum_id;
  1131.  
  1132. if ( $this->msg_id != NEW_MSG && is_numeric($msg_id) ) {
  1133. $this->get_msg();
  1134. }
  1135. } // thread_msg
  1136.  
  1137.  
  1138. function get_msg() {
  1139. // get the message object
  1140. debugbr("getting the message to EDIT");
  1141. $q = "select *, to_char(last_modified, 'DD/MM/YYYY HH:MI am') as date_posted ";
  1142. $q .= "from ax_forum_msg where msg_id=$this->msg_id";
  1143. $qQ = new dbrecords($q);
  1144.  
  1145. if ( $qQ->hasdata ) {
  1146. // get msg and place info in appropriate var.
  1147. $this->msg_subject = trim($qQ->field("msg_subject"));
  1148. $this->msg_text = trim($qQ->field("msg_text"));
  1149. $this->enabled = $qQ->istrue("enabled");
  1150. $this->author = trim($qQ->field("msg_author"));
  1151. $this->date_posted = $qQ->field("date_posted");
  1152. $this->ParentMsg = trim($qQ->field("parent_thread_id"));
  1153. $this->forum_id = trim($qQ->field("forum_id"));
  1154. }
  1155. } // get_msg
  1156.  
  1157.  
  1158. function update_trlm() {
  1159. // this function updates the thread last_modified field,
  1160. // and the replies field.
  1161. // as well as the last_author, threadlast_author and datelast_author
  1162. // fields in the forum record.
  1163. $q1 = "select * from ax_forum where forum_id=$this->forum_id";
  1164. $Q1 = new dbrecords($q1);
  1165.  
  1166. $q2 = "select * from ax_forum_msg where msg_id=$this->thread_id";
  1167. $Q2 = new dbrecords($q2);
  1168. } // update_trlm
  1169.  
  1170.  
  1171. function save_msg() {
  1172. // save the message.
  1173. global $mode, $forum_id, $msg_id;
  1174.  
  1175. debugbr("message id: $msg_id");
  1176. if ( trim($this->msg_id) == NEW_MSG ) {
  1177. // then it's an insert
  1178. $query = new dbinsert("ax_forum_msg");
  1179. $mid = get_next_sequencevalue("seq_msg_id", "ax_forum_msg", "msg_id");
  1180. $query->set("msg_id", $mid);
  1181. $query->set("parent_thread_id", $this->thread_id);
  1182. $query->set("msg_author", $this->author);
  1183. $query->set("last_modified", $this->date_posted);
  1184. $query->set("forum_id", trim($forum_id));
  1185. $query->set("enabled", $this->enabled);
  1186. $query->set("sticky", $this->sticky);
  1187. $query->set("locked", $this->locked);
  1188. } else {
  1189. // else it's an update
  1190. $query = new dbupdate("ax_forum_msg");
  1191. $query->where("msg_id=$this->msg_id");
  1192. }
  1193.  
  1194. $query->set("msg_subject", strip_tags($this->msg_subject), "<br>");
  1195. $query->set("msg_text", strip_tags($this->msg_text), "<br>");
  1196.  
  1197. if ( $query->execute() ) {
  1198. $mode = "viewthread";
  1199.  
  1200. // this is to update the thread last_modified field after the new message has been saved.
  1201. // this is only modified when a new msg is saved into the thread. nothing else.
  1202. // this is so threads can be sorted by the one with th emost recent post.
  1203. if ( $this->msg_id == NEW_MSG && $this->thread_id != NEW_THREAD ) {
  1204. $q = new dbupdate("ax_forum_msg");
  1205. $q->where("msg_id=$this->thread_id");
  1206.  
  1207. $q->set("last_modified", "now()");
  1208. $q->execute();
  1209. }
  1210.  
  1211. // set the msg id
  1212. $this->msg_id = $mid;
  1213. return TRUE;
  1214. } else { return FALSE; }
  1215. } // save_msg
  1216.  
  1217.  
  1218. function display_msg() {
  1219. // return the html for this particular msg
  1220. global $RESPONSE;
  1221.  
  1222. $s = "";
  1223.  
  1224. $T = new table("MessageTable".$this->msg_id);
  1225. $T->setpadding(4,1);
  1226. $T->setwidth("80%");
  1227. $T->setborder(1);
  1228. $T->tr();
  1229. $T->td("<center>".strtoupper($this->msg_subject)."</center>");
  1230. $T->td_colspan(3);
  1231. $T->tr();
  1232. $T->td("&nbsp;");
  1233. $T->td_width("25%");
  1234. $T->td("Posted on $this->date_posted By $this->author.");
  1235. $T->td("&nbsp;");
  1236. $T->td_width("25%");
  1237. $T->tr();
  1238. $T->td($this->msg_text);
  1239. $T->td_colspan(3);
  1240.  
  1241. $s = $T->render();
  1242.  
  1243. return $s;
  1244. } // display_msg
  1245.  
  1246.  
  1247. function new_msg() {
  1248. // displays the form objects for entering in a new message.
  1249. global $RESPONSE, $forum_id, $mode;
  1250. global $msg_subject, $msg_text;
  1251. global $quote;
  1252.  
  1253. if ( trim($msg_subject) != "" ) $this->msg_subject = trim($msg_subject);
  1254. if ( trim($msg_text) != "" ) $this->msg_text = trim($msg_text);
  1255.  
  1256. // set the non-entered fields for a message
  1257. $this->author = $RESPONSE->userid;
  1258. $this->date_posted = date("d/m/Y h:i a");
  1259. if ( trim($this->thread_id) != NEW_THREAD ) {
  1260. $this->ParentMsg = $this->thread_id;
  1261. }
  1262.  
  1263. $s = "";
  1264.  
  1265. if ( trim($mode) == "reply") {
  1266. $q = "select msg_subject, msg_text, msg_author, to_char(last_modified, 'DD/MM/YYYY HH:MI am') as date_posted ";
  1267. $q .= "from ax_forum_msg where msg_id=$quote";
  1268. $Q = new dbrecords($q);
  1269.  
  1270. if ( $Q->hasdata ) {
  1271. $oldsub = $Q->field("msg_subject");
  1272. $this->msg_subject = "RE: ".$Q->field("msg_subject");
  1273. $oldtxt = $Q->field("msg_text");
  1274.  
  1275. $this->msg_text = ">----------\nPosted by ".$Q->field("msg_author")." on ". $Q->field("date_posted").":";
  1276. $this->msg_text .= "\n\n".$Q->field("msg_text")."\n>----------\n\n";
  1277. }
  1278. }
  1279.  
  1280. // form objects.
  1281. $ms = new form_textfield("msg_subject", "", $this->msg_subject);
  1282. $ms->setstyle("width: 300");
  1283. $ms->setclass("axtxtbox");
  1284. $mt = new form_memofield("msg_text", "", $this->msg_text, EDITABLE, "", STD_WIDTH, 20);
  1285. $mt->setstyle("width: 300");
  1286. $mt->setclass("axmemo");
  1287.  
  1288. $T = new table("MessageTable".$this->msg_id);
  1289. $T->setpadding(4,1);
  1290. $T->setwidth("80%");
  1291. $T->setborder(0);
  1292. $T->setalign("center");
  1293.  
  1294. if ( trim($this->thread_id) != NEW_THREAD ) {
  1295. $T->tr();
  1296. $T->td("Subject:&nbsp;");
  1297. $T->td_alignment("right");
  1298. $T->td_width("25%");
  1299. $T->td("$oldsub");
  1300. $T->tr();
  1301. $T->td("Text:&nbsp;");
  1302. $T->td_alignment("right", "top");
  1303. $T->td_width("25%");
  1304. $T->td(str_replace("\n", "<br>", $oldtxt));
  1305. $T->tr();
  1306. $T->td("<hr>");
  1307. $T->td_colspan(2);
  1308.  
  1309. $pb = new form_imagebutton("SaveMsg", "Save Msg", "", "lib/_save.gif", "", 57, 15);
  1310. $cb = new form_imagebutton("CancelMsg", "Cancel", "", "lib/_cancel.gif", "", 57, 15);
  1311. //$bb = new form_imagebutton("BackMsg", "Back To Msgs", "", "lib/_back.gif", "", 42, 15);
  1312. } else {
  1313. $T->tr();
  1314. $T->td("&nbsp;");
  1315. $T->td("NEW THREAD", "forumheadings");
  1316. /*$T->td_contentcss("font-size:12pt;
  1317. color: #FF6600;
  1318. font-weight: bold;");*/
  1319. $pb = new form_imagebutton("SaveThread", "Save Thread", "", "lib/_save.gif", "", 57, 15);
  1320. $cb = new form_imagebutton("CancelThread", "Cancel", "", "lib/_cancel.gif", "", 57, 15);
  1321. //$bb = new form_imagebutton("BackThread", "Back To Threads", "", "lib/_back.gif", "", 42, 15);
  1322. }
  1323.  
  1324. debugbr("error message: $this->error_msg");
  1325. if ( trim($this->error_msg) != "" ) {
  1326. $T->tr();
  1327. $T->td($this->error_msg, "formerror");
  1328. //$T->td_contentcss("font-size:9pt");
  1329. $T->td_colspan(2);
  1330. $T->tr();
  1331. $T->td("<hr>");
  1332. $T->td_colspan(2);
  1333. }
  1334.  
  1335. $T->tr();
  1336. $T->td("&nbsp;");
  1337. $T->td("Posted by $this->author on $this->date_posted");
  1338. //$T->td_contentcss("font-size:9pt");
  1339. $T->tr();
  1340. $T->td("Subject:&nbsp;");
  1341. /*$T->td_contentcss("font-size:9pt;
  1342. color: #FF6600;");*/
  1343. $T->td_width("25%");
  1344. $T->td_alignment("right");
  1345. $T->td($ms->render());
  1346. $T->tr();
  1347. $T->td("Text:&nbsp;");
  1348. /*$T->td_contentcss("font-size:9pt;
  1349. color: #FF6600;");*/
  1350. $T->td_width("25%");
  1351. $T->td_alignment("right", "top");
  1352. $T->td($mt->render());
  1353.  
  1354. // POST button
  1355. $T->tr();
  1356. $T->td(/*$bb->render() . " " .*/ $cb->render() . " " . $pb->render());
  1357. $T->td_colspan(2);
  1358. $T->td_alignment("center");
  1359.  
  1360. $fidh = new form_hiddenfield("forum_id", $forum_id);
  1361. $tidh = new form_hiddenfield("thread_id", $this->thread_id);
  1362. $midh = new form_hiddenfield("msg_id", $this->msg_id);
  1363. $ah = new form_hiddenfield("author", $this->author);
  1364. $dph = new form_hiddenfield("date_posted", $this->date_posted);
  1365. $pidh = new form_hiddenfield("ParentMsg", $this->ParentMsg);
  1366. $mh = new form_hiddenfield("mode", $mode);
  1367. $T->tr();
  1368. $T->td($fidh->render().$mh->render().$tidh->render().$midh->render().$ah->render().$dph->render().$pidh->render());
  1369. $T->td_colspan(2);
  1370.  
  1371. $s = $T->render();
  1372.  
  1373. return $s;
  1374. } // new_msg
  1375.  
  1376.  
  1377. function edit_msg() {
  1378. // displays the form objects for editing a message.
  1379. global $RESPONSE, $forum_id, $mode;
  1380. global $quote;
  1381.  
  1382. // set the non-entered fields for a message
  1383.  
  1384. debugbr("===================================================");
  1385. debugbr("message id: $this->msg_id");
  1386. debugbr("thread id: $this->thread_id");
  1387. debugbr("message subject: $this->msg_subject");
  1388. debugbr("message text: $this->msg_text");
  1389. debugbr("author: $this->author");
  1390. debugbr("date posted: $this->date_posted");
  1391. debugbr("enabled: $this->enabled");
  1392. debugbr("parent message id: $this->ParentMsg");
  1393. debugbr("forum id: $this->forum_id");
  1394. debugbr("===================================================");
  1395.  
  1396. $s = "";
  1397.  
  1398. // form objects.
  1399. $ms = new form_textfield("msg_subject", "", $this->msg_subject);
  1400. $ms->setstyle("width: 300");
  1401. $ms->setclass("axtxtbox");
  1402. $mt = new form_memofield("msg_text", "", $this->msg_text, EDITABLE, "", STD_WIDTH, 20);
  1403. $mt->setstyle("width: 300");
  1404. $mt->setclass("axmemo");
  1405.  
  1406. $T = new table("MessageTable".$this->msg_id);
  1407. $T->setpadding(4,1);
  1408. $T->setwidth("80%");
  1409. $T->setborder(0);
  1410. $T->setalign("center");
  1411.  
  1412. $T->tr();
  1413. $T->td("&nbsp;");
  1414. $T->td("EDIT MESSAGE / THREAD", "forumheadings");
  1415. /*$T->td_contentcss("font-size:12pt;
  1416. color: #FF6600;
  1417. font-weight: bold;");*/
  1418. $pb = new form_imagebutton("SaveMsg", "Save Msg", "", "lib/_save.gif", "", 57, 15);
  1419. $cb = new form_imagebutton("CancelMsg", "Cancel", "", "lib/_cancel.gif", "", 57, 15);
  1420.  
  1421. debugbr("error message: $this->error_msg");
  1422. if ( trim($this->error_msg) != "" ) {
  1423. $T->tr();
  1424. $T->td("<font color=\"red\">$this->error_msg</font>");
  1425. //$T->td_contentcss("font-size:9pt");
  1426. $T->td_colspan(2);
  1427. $T->tr();
  1428. $T->td("<hr>");
  1429. $T->td_colspan(2);
  1430. }
  1431.  
  1432. $T->tr();
  1433. $T->td("&nbsp;");
  1434. $T->td("Posted by $this->author on $this->date_posted");
  1435. //$T->td_contentcss("font-size:9pt");
  1436. $T->tr();
  1437. $T->td("Subject:&nbsp;");
  1438. /*$T->td_contentcss("font-size:9pt;
  1439. color: #FF6600;");*/
  1440. $T->td_width("25%");
  1441. $T->td_alignment("right");
  1442. $T->td($ms->render());
  1443. $T->tr();
  1444. $T->td("Text:&nbsp;");
  1445. /*$T->td_contentcss("font-size:9pt;
  1446. color: #FF6600;");*/
  1447. $T->td_width("25%");
  1448. $T->td_alignment("right", "top");
  1449. $T->td($mt->render());
  1450.  
  1451. // POST button
  1452. $T->tr();
  1453. $T->td($cb->render() . " " . $pb->render());
  1454. $T->td_colspan(2);
  1455. $T->td_alignment("center");
  1456.  
  1457. $fidh = new form_hiddenfield("forum_id", $forum_id);
  1458. $tidh = new form_hiddenfield("thread_id", $this->thread_id);
  1459. $midh = new form_hiddenfield("msg_id", $this->msg_id);
  1460. $ah = new form_hiddenfield("author", $this->author);
  1461. $dph = new form_hiddenfield("date_posted", $this->date_posted);
  1462. $pidh = new form_hiddenfield("ParentMsg", $this->ParentMsg);
  1463. $mh = new form_hiddenfield("mode", $mode);
  1464. $T->tr();
  1465. $T->td($fidh->render().$mh->render().$tidh->render().$midh->render().$ah->render().$dph->render().$pidh->render());
  1466. $T->td_colspan(2);
  1467.  
  1468. $s = $T->render();
  1469.  
  1470. return $s;
  1471. } // edit_msg
  1472.  
  1473. } // class thread_msg
  1474. // ----------------------------------------------------------------------
  1475.  
  1476. ?>

Documentation generated by phpDocumentor 1.3.0RC3