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

Documentation generated by phpDocumentor 1.3.0RC3