/
answer.php
238 lines (193 loc) · 7.55 KB
/
answer.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
<?php
/**
* $Id: answer.php,v 1.17 2006/09/29 18:49:10 malanciault Exp $
* Module: SmartFAQ
* Author: The SmartFactory <www.smartfactory.ca>
* Licence: GNU
*/
include_once("header.php");
global $xoopsUser, $xoopsConfig, $xoopsModuleConfig, $xoopsModule;
// If user is anonymous and we don't allow anonymous posting, exit; else, get the uid
if (!$xoopsUser && ($xoopsModuleConfig['anonpost'] != 1)) {
redirect_header("index.php", 3, _NOPERM);
exit();
}
$op = 'form';
// Getting the operation we are doing
if (isset($_GET['op'])) $op = $_GET['op'];
if (isset($_POST['op'])) $op = $_POST['op'];
// Getting the faqid
$faqid = isset($_GET['faqid'])? intval($_GET['faqid']) : 0;
$faqid = isset($_POST['faqid'])? intval($_POST['faqid']) : $faqid;
// If no FAQ is selected, exit
if ($faqid == 0) {
redirect_header("javascript:history.go(-1)", 1, _MD_SF_NOFAQSELECTED);
exit();
}
// Creating the FAQ handler object
$faq_handler =& sf_gethandler('faq');
// Creating the answer handler object
$answer_handler =& sf_gethandler('answer');
switch ($op) {
// The answer is posted
case 'post':
Global $faqObj, $xoopsUser, $xoopsConfig, $xoopsModule, $xoopsModuleConfig, $xoopsDB;
// If user is anonymous and we don't allow anonymous posting, exit; else, get the uid
if (!$xoopsUser) {
if ($xoopsModuleConfig['anonpost'] == 1) {
$uid = 0;
} else {
redirect_header("index.php", 3, _NOPERM);
exit();
}
} else {
$uid = $xoopsUser->uid();
}
// Creating the FAQ object for the selected FAQ
$faqObj = new sfFaq($faqid);
// If the selected FAQ was not found, exit
if ($faqObj->notLoaded()) {
redirect_header("javascript:history.go(-1)", 1, _MD_SF_NOFAQSELECTED);
exit();
}
// Get the category object related to that FAQ
$categoryObj =& $faqObj->category();
// Create the answer object
$newAnswerObj = $answer_handler->create();
// Putting the values in the answer object
$newAnswerObj->setVar('faqid', $faqObj->faqid());
$newAnswerObj->setVar('answer',$_POST['answer']);
$newAnswerObj->setVar('uid', $uid);
// Depending of the status of the FAQ, some values need to be set
$original_status = $faqObj->status();
switch ($original_status)
{
// This is an Open Question
case _SF_STATUS_OPENED :
if ( $xoopsModuleConfig['autoapprove_answer'] == 1) {
// We automatically approve submitted answer for Open Question, so the question become a Submitted Q&A
if ( $xoopsModuleConfig['autoapprove_submitted_faq'] == 1) {
// We automatically approve Submitted Q&A
$redirect_msg = _MD_SF_QNA_RECEIVED_AND_PUBLISHED;
$faqObj->setVar('status', _SF_STATUS_PUBLISHED);
$newAnswerObj->setVar('status', _SF_AN_STATUS_APPROVED);
$notifCase = 1;
} else {
// Submitted Q&A need approbation
$redirect_msg = _MD_SF_QNA_RECEIVED_NEED_APPROVAL;
$faqObj->setVar('status', _SF_STATUS_SUBMITTED);
$newAnswerObj->setVar('status', _SF_AN_STATUS_PROPOSED);
$notifCase = 2;
}
} else {
// Submitted answer need approbation
$redirect_msg = _MD_SF_OPEN_ANSWER_NEED_APPROBATION;
$faqObj->setVar('status', _SF_STATUS_ANSWERED);
$newAnswerObj->setVar('status', _SF_AN_STATUS_PROPOSED);
$notifCase = 3;
}
break;
// This is a published FAQ for which a user submitted a new answer
case _SF_STATUS_PUBLISHED :
case _SF_STATUS_NEW_ANSWER :
if ( $xoopsModuleConfig['autoapprove_answer_new'] == 1) {
// We automatically approve new submitted answer for already published FAQ
$redirect_msg = '4';
$faqObj->setVar('status', _SF_STATUS_SUBMITTED);
$newAnswerObj->setVar('status', _SF_AN_STATUS_APPROVED);
$notifCase = 4;
} else {
// New submitted answer need approbation
$redirect_msg = _MD_SF_FAQ_NEW_ANSWER_NEED_APPROBATION;
$faqObj->setVar('status', _SF_STATUS_NEW_ANSWER);
$newAnswerObj->setVar('status', _SF_AN_STATUS_PROPOSED);
$notifCase = 5;
}
break;
}
// Storing the FAQ object in the database
if ( !$faqObj->store() ) {
redirect_header("javascript:history.go(-1)", 3, _MD_SF_SUBMIT_ERROR . sf_formatErrors($faqObj->getErrors()));
exit();
}
// Storing the answer object in the database
if ( !$newAnswerObj->store() ) {
redirect_header("javascript:history.go(-1)", 3, _MD_SF_SUBMIT_ERROR . sf_formatErrors($newAnswerObj->getErrors()));
exit();
}
$notification_handler = &xoops_gethandler('notification');
switch ($notifCase)
{
case 1 :
// Question submitted, auto-approved; became Q&A, auto-approved
// We do not not subscribe user to notification on publish since we publish it right away
// Send notifications
$faqObj->sendNotifications(array(_SF_NOT_FAQ_PUBLISHED));
break;
case 2 :
// Answer for an open question submitted, auto-approved; became Q&A, need approbation
if (isset($_POST['notifypub']) && $_POST['notifypub'] == 1) {
include_once XOOPS_ROOT_PATH . '/include/notification_constants.php';
$notification_handler->subscribe('faq', $faqObj->faqid(), 'approved', XOOPS_NOTIFICATION_MODE_SENDONCETHENDELETE);
}
// Send notifications
$faqObj->sendNotifications(array(_SF_NOT_FAQ_SUBMITTED));
break;
case 3 :
// Answer submitted, needs approbation
if (isset($_POST['notifypub']) && $_POST['notifypub'] == 1) {
include_once XOOPS_ROOT_PATH . '/include/notification_constants.php';
$notification_handler->subscribe('question', $newAnswerObj->answerid(), 'approved', XOOPS_NOTIFICATION_MODE_SENDONCETHENDELETE);
}
// Send notifications
$faqObj->sendNotifications(array(_SF_NOT_QUESTION_SUBMITTED));
case 4 :
// New answer submitted for a published Q&A, auto-approved
// TODO...
break;
case 5 :
// New answer submitted for a published Q&A, need approbation
// Send notifications
if (isset($_POST['notifypub']) && $_POST['notifypub'] == 1) {
include_once XOOPS_ROOT_PATH . '/include/notification_constants.php';
$notification_handler->subscribe('faq', $newAnswerObj->answerid(), 'answer_approved', XOOPS_NOTIFICATION_MODE_SENDONCETHENDELETE);
}
$faqObj->sendNotifications(array(_SF_NOT_NEW_ANSWER_PROPOSED));
break;
}
redirect_header("javascript:history.go(-2)", 3, $redirect_msg);
exit;
break;
case 'form':
default:
global $xoopsUser, $xoopsModule, $HTTP_SERVER_VARS;
// Creating the FAQ object for the selected FAQ
$faqObj = new sfFaq($faqid);
// If the selected FAQ was not found, exit
if ($faqObj->notLoaded()) {
redirect_header("javascript:history.go(-1)", 1, _MD_SF_NOFAQSELECTED);
exit();
}
// Creating the category object that holds the selected FAQ
$categoryObj =& $faqObj->category();
// Creating the answer object
$answerObj =& $faqObj->answer();
// Check user permissions to access that category of the selected FAQ
if (faqAccessGranted($faqObj) < 0) {
redirect_header("javascript:history.go(-1)", 1, _NOPERM);
exit;
}
$xoopsOption['template_main'] = 'smartfaq_submit.html';
include_once(XOOPS_ROOT_PATH . "/header.php");
include_once("footer.php");
$name = ($xoopsUser)? (ucwords($xoopsUser->getVar("uname"))) : 'Anonymous';
$moduleName = $myts->displayTarea($xoopsModule->getVar('name'));
$xoopsTpl->assign('whereInSection', $moduleName);
$xoopsTpl->assign('lang_submit', _MD_SF_SUBMITANSWER);
$xoopsTpl->assign('lang_intro_title', sprintf(_MD_SF_SUBMITANSWERTO, ucwords($xoopsModule->name())));
$xoopsTpl->assign('lang_intro_text', _MD_SF_GOODDAY . "<b>$name</b>, " . _MD_SF_SUBMITANSWER_INTRO);
include_once 'include/answer.inc.php';
include_once XOOPS_ROOT_PATH . '/footer.php';
break;
}
?>