CMS  Version 3.9
subscription_dialog.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 
39 Fakoli::using("forum");
40 
41 $topic_id = checkNumeric($_GET["topic_id"]);
42 $forum_id = checkNumeric($_GET["forum_id"]);
43 $forum_subscription_id = checkNumeric($_GET["forum_subscription_id"]);
44 
45 if(!$user)
46 {
47  Fakoli::end("You must be logged in to change your forum subscription preferences.");
48 }
49 
50 if(!$forum_id)
51 {
52  Fakoli::end("Unable to update subscription - unknown forum");
53 }
54 
56 
58 
59 $pk = $user->getPrimaryKey();
60 $forumSubscriptions = Query::create(ForumSubscription, "WHERE user_id=:user_id AND forum_id=:forum_id")
61  ->bind(":user_id", $user->$pk, ":forum_id", $forum_id)
62  ->execute();
63 
65 if(count($forumSubscriptions))
66 {
67  foreach($forumSubscriptions as $fs)
68  {
69  if($fs->topic_id > 0)
70  {
71  $topicSubscriptions[] = $fs;
72  }
73  }
74 }
75 
77 {
79 }
80 else
81 {
82  $pk = $user->getPrimaryKey();
83  $forumSubscription->user_id = $user->$pk;
85  if($topic_id)
86  {
87  $forumSubscription->topic_id = $topic_id;
88  }
90 }
91 
92 if($topic_id)
93 {
94  // on save complete - determine if we are setting a topic subscription
95  $forumSubscription->set("topics_page", true);
96 }
97 
99 $helper = new ForumSubscriptionHelper($forum, $topic);
100 
101 $form = new AutoForm($forumSubscription, "POST", "/action/forum/subscription_dialog?forum_id=$forum_id&topic_id=$topic_id&forum_subscription_id={$form->data->forum_subscription_id}");
102 $form->ajaxSubmit("function(result) {forumSubscriptionMgr.subscriptionDialogResult(result);}", "function() {document.id('{$form->id}_error').set('text','Failed to communicate with server'); }");
103 
104 $form->hide("user_id", "forum_id", "topic_id");
105 $typeSelect = new RadioButtonFieldRenderer($form, "subscription_type", "", $helper->formatSubscriptionOptions());
106 $typeSelect->hideLabel = true;
107 
108 $form->button("Cancel", "forumSubscriptionMgr.closeDialog()", null, true);
109 $form->customSaveHandler = array($helper, saveForumSubscription);
110 $form->labelCSS = "forum_subscription_label";
111 
112 if ($method == "POST")
113 {
114  if ($form->save())
115  {
116  Fakoli::end("OK");
117  }
118  else
119  {
120  Fakoli::end($form->msg);
121  }
122 }
123 
124 echo $form->writeScript();
125 
126 echo $helper->drawHeaderText();
127 $form->drawForm();
128 ?>
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
Definition: forum.inc:42
global $user
$method
Pull out a simple reference to the request method.
Definition: core.inc:1573
const subscription_daily_digest
$forumSubscription
$forum_subscription_id
if(! $user) if(! $forum_id) $forum
$forumSubscriptions
if($topic_id) $topic
$topicSubscriptions