CMS  Version 3.9
comment_form.inc
Go to the documentation of this file.
1 <?php
2 /*
3  * Allow user to edit a comment.
4  *
5  * To do - Delete the comment_id in the xref table.
6  */
7 
8 Fakoli::using("comment", "settings", "email", "captcha");
9 Fakoli::usingFeature("auto_form");
10 
11 $comment_id = checkNumeric($_GET["comment_id"]);
12 $xref_class = ConnectionManager::escape($_GET["xref_class"]);
13 $key_name = ConnectionManager::escape($_GET["key_name"]);
14 $key_value = checkNumeric($_GET["key_value"]);
15 $xref_component = ConnectionManager::escape($_GET["xref_component"]);
16 global $user;
17 
19 
20 $comment = new Comment();
21 
22 if ($comment_id)
23 {
24  $comment->load($comment_id);
25  $newPost = false;
26  $returnFn = "editCommentFormResult";
27 }
28 else
29 {
30  $comment->user_id = ($user) ? $user->get($user->primary_key) : 0;
31  $comment->date_posted = today();
32  $newPost = true;
33  $returnFn = "commentFormResult";
34 }
35 
36 $form = new AutoForm($comment, "POST", "/action/comment/comment_form?comment_id=$comment_id&xref_class=$xref_class&key_name=$key_name&key_value=$key_value&xref_component=$xref_component", "EditComment_form");
37 $form->alias("title", "Subject");
38 $form->ajaxSubmit("function(result) {new Comment().{$returnFn}(result);}", "function() {document.id('{$form->id}_error').set('text','Failed to communicate with server'); }");
39 $form->required("description");
40 
41 // To do - make it configurable whether to include title?
42 //$form->hide("title");
43 if (!$comment_id)
44 {
45  $form->alias("author", "Your Name");
46 }
47 
48 $posted = new DateTimeFieldRenderer($form);
49 $posted->template = "m/d/Y";
50 $form->override("date_posted", "Date Posted", $posted);
51 $form->readOnly("date_posted");
52 
53 if(!$comment_id)
54 {
55  $form->onSaveComplete = saveNewComment;
56  $form->data->set("xref_class", $xref_class);
57  $form->data->set("key_name", $key_name);
58  $form->data->set("key_value", $key_value);
59 }
60 
61 if($comment->user_id)
62 {
63  $mgr = new UserManager();
64  $userClass = $mgr->getUserClass();
65  $userSelect = new RelatedItemSelectFieldRenderer($form, "user_id", "Author", $userClass, "WHERE user_id={$comment->user_id}", "{first_name} {last_name}", "user_id");
66  $form->readOnly("user_id");
67  $form->hide("author");
68 }
69 else
70 {
71  $form->hide("user_id");
72  $form->readOnly("author");
73 }
74 
75 $captchaMode = Settings::getValue("comment", "use_captcha");
76 if (!$comment_id && ($captchaMode == "Always" || ($captchaMode == "Anonymous Only" && !$user)))
77 {
78  $captchaMgr = new CaptchaManager();
79  $captchaMgr->addCaptchaToForm($form);
80 }
81 
82 $form->allowDelete = true;
83 
84 if($method == "POST")
85 {
86  //echo "<pre>"; print_r($_POST); echo "</pre>";
87  if($form->save())
88  {
89  $confirmationMessage = $form->data->get("confirmation_message");
90 
91  Fakoli::end("OK|$confirmationMessage");
92  }
93  else
94  {
95  Fakoli::end($form->msg);
96  }
97 }
98 
99 echo $form->writeScript();
100 
101 $form->drawForm();
102 
104 {
106 }
Provides a central management class for event handlers and common functionality for the captcha compo...
static onSaveNewComment($form)
Called by comment_form handler to save xref and send email for new comments.
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
static end($message="")
Use this method to terminate execution of a script instead of using the php keywords exit() or die().
Definition: core.inc:1149
static getValue($component, $name)
Retrieve the value of the specified Setting.
Definition: settings.inc:104
Provides the interface to the user model for the application.
global $user
$captchaMode
$form
saveNewComment($form)
$xref_class
$comment
$newPost
$key_value
$comment_id
$xref_component
$key_name
$returnFn
if(! $comment_id) $posted
$method
Pull out a simple reference to the request method.
Definition: core.inc:1573