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

Documentation generated by phpDocumentor 1.3.0RC3