CMS  Version 3.9
forum_message_form.inc
Go to the documentation of this file.
1 <?php
2 /**************************************************************
3 
4  Copyright (c) 2010 Sonjara, Inc
5 
6  Permission is hereby granted, free of charge, to any person
7  obtaining a copy of this software and associated documentation
8  files (the "Software"), to deal in the Software without
9  restriction, including without limitation the rights to use,
10  copy, modify, merge, publish, distribute, sublicense, and/or sell
11  copies of the Software, and to permit persons to whom the
12  Software is furnished to do so, subject to the following
13  conditions:
14 
15  The above copyright notice and this permission notice shall be
16  included in all copies or substantial portions of the Software.
17 
18  Except as contained in this notice, the name(s) of the above
19  copyright holders shall not be used in advertising or otherwise
20  to promote the sale, use or other dealings in this Software
21  without prior written authorization.
22 
23  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
25  OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
27  HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
28  WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
30  OTHER DEALINGS IN THE SOFTWARE.
31 
32 *****************************************************************/
33 
34 Fakoli::using("forum", "attachment", "user");
35 
36 Fakoli::usingFeature("auto_form");
37 
38 $forum_id = checkNumeric($_GET["forum_id"]);
39 $parent_id = checkNumeric($_GET["parent_id"]);
40 $message_id = checkNumeric($_GET["message_id"]);
41 
43 
44 if (!$forum) redirect("/index");
45 
46 $mgr = new UserManager();
47 
48 if ($message_id)
49 {
51  $message->filter = new ExclusionFilter("date_posted");
52 }
53 else
54 {
55  $message = new ForumMessage();
56  if ($parent_id)
57  {
59  $message->topic_id = $parent->topic_id;
60  $message->title = "Re: {$parent->title}";
61  $message->title = preg_replace("/^(Re:\s+)+/", "Re: ", $message->title);
62  $page->page_title = "Reply To: {$parent->title}";
63  $parentAuthor = $parent->Author();
64  $message->message = "<br/><div class='quote'><strong>{$parentAuthor->getFullName()} wrote on {$parent->date_posted}:</strong><br/>{$parent->message}</div><br/><br/>";
65  }
66  else
67  {
68  $page->page_title = "Create a Topic for {$forum->title}";
69 
70  }
71 
72  $_POST['author_id'] = $user->get($user->primary_key);
73  $_POST['forum_id'] = $forum_id;
74  $_POST['parent_id'] = $parent_id;
75 }
76 
77 
78 $form = new AutoForm($message);
79 $form->button("Cancel", "forum_details?forum_id=$forum_id");
80 
81 $form->hide("parent_id", "topic_id", "author_id", "forum_id", "date_posted", "deleted");
82 $form->onSaveComplete = emailSubscribers;
83 
85 
86 if ($method == "POST")
87 {
88  $_POST['date_posted'] = now();
89 
90  if ($message_id)
91  {
92  // Editing the message - add an edit notification to the end of the message
93  $_POST["message"] .= "<p><em>Edited by {$user->first_name} {$user->last_name} on ".now()."</em></p>";
94  }
95 
96  if ($form->save())
97  {
98  if (!$parent_id && !$message_id)
99  {
100  // Creating a new topic
101  $topic = new ForumTopic();
102  $topic->forum_id = $forum_id;
103  $topic->message_id = $form->data->message_id;
104  $topic->date_created = $form->data->date_posted;
105  $topic->save();
106 
107  $form->data->filter = new InclusionFilter("message_id", "topic_id");
108  $form->data->topic_id = $topic->topic_id;
109  $form->data->save();
110 
111  redirect("forum_details?forum_id={$forum_id}");
112  }
113  else
114  {
115  redirect("forum_topic?forum_id={$forum_id}&topic_id={$message->topic_id}");
116  }
117  }
118 }
119 
120 $script .= $form->writeScript();
121 
122 $form->drawForm();
123 
125 {
126  $message = $form->data;
127  trace("emailSubscribers:: message id {$message->message_id}", 3);
129 }
130 ?>
$page
Definition: help.inc:39
$parent
Definition: templates.inc:42
static usingFeature()
Uses the specified framework feature(s).
Definition: core.inc:388
static using()
Import the datamodels, views and manifest for the specified component(s).
Definition: core.inc:116
Definition: forum.inc:42
Provides the interface to the user model for the application.
global $user
$method
Pull out a simple reference to the request method.
Definition: core.inc:1573
$_POST['author_id']
$attachmentHandler
emailSubscribers($form)
if($method=="POST") $script
static sendInstantNotifications($message)
$message
Definition: mail_to.inc:49
$topic
Definition: topic_form.inc:42