Passed
Push — master ( 2744eb...81ba93 )
by Michael
02:46
created

admin/faq.php (3 issues)

1
<?php
2
3
/**
4
 * Module: SmartFAQ
5
 * Author: The SmartFactory <www.smartfactory.ca>
6
 * Licence: GNU
7
 */
8
9
use Xmf\Request;
10
use XoopsModules\Smartfaq;
11
use XoopsModules\Smartfaq\Constants;
12
13
require_once __DIR__ . '/admin_header.php';
14
15
/** @var Smartfaq\Helper $helper */
16
$helper = Smartfaq\Helper::getInstance();
17
18
// Creating the faq handler object
19
/** @var \XoopsModules\Smartfaq\FaqHandler $faqHandler */
20
$faqHandler = \XoopsModules\Smartfaq\Helper::getInstance()->getHandler('Faq');
21
22
// Creating the category handler object
23
/** @var \XoopsModules\Smartfaq\CategoryHandler $categoryHandler */
24
$categoryHandler = \XoopsModules\Smartfaq\Helper::getInstance()->getHandler('Category');
25
26
// Creating the answer handler object
27
/** @var \XoopsModules\Smartfaq\AnswerHandler $answerHandler */
28
$answerHandler = \XoopsModules\Smartfaq\Helper::getInstance()->getHandler('Answer');
29
30
$op = '';
31
if (isset($_GET['op'])) {
32
    $op = $_GET['op'];
33
}
34
if (isset($_POST['op'])) {
35
    $op = $_POST['op'];
36
}
37
38
// Where shall we start?
39
$startfaq = \Xmf\Request::getInt('startfaq', 0, 'GET');
40
41
/**
42
 * @param bool $showmenu
43
 * @param int  $faqid
44
 * @param int  $answerid
45
 * @param bool $merge
46
 */
47
function editfaq($showmenu = false, $faqid = -1, $answerid = -1, $merge = false)
48
{
49
    global $answerHandler, $faqHandler, $categoryHandler, $xoopsUser, $xoopsUser, $xoopsConfig, $xoopsDB, $modify,  $xoopsModule, $XOOPS_URL, $myts;
50
    /** @var Smartfaq\Helper $helper */
51
    $helper = Smartfaq\Helper::getInstance();
52
53
    require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
54
    // If there is a parameter, and the id exists, retrieve data: we're editing a faq
55
    if (-1 != $faqid) {
56
        // Creating the FAQ object
57
        $faqObj = new Smartfaq\Faq($faqid);
58
59
        if ($faqObj->notLoaded()) {
60
            redirect_header('faq.php', 1, _AM_SF_NOFAQSELECTED);
61
        }
62
63
        if (-1 == $answerid) {
64
            // Creating the object for the official answer
65
            $answerObj = $faqObj->answer();
66
            if (!$answerObj) {
0 ignored issues
show
$answerObj is of type XoopsModules\Smartfaq\Answer, thus it always evaluated to true.
Loading history...
67
                $answerObj = $answerHandler->create();
68
            }
69
        } else {
70
            $answerObj         = new Smartfaq\Answer($answerid);
71
            $originalAnswerObj = $faqObj->answer();
72
        }
73
74
        switch ($faqObj->status()) {
75
76
            case Constants::SF_STATUS_ASKED:
77
                $breadcrumb_action1   = _AM_SF_ASKED;
78
                $breadcrumb_action2   = _AM_SF_APPROVING;
79
                $collapsableBar_title = _AM_SF_ASKED_TITLE;
80
                $collapsableBar_info  = _AM_SF_ASKED_TITLE_INFO;
81
                $button_caption       = _AM_SF_PUBLISHED;
82
                $an_status            = Constants::SF_AN_STATUS_APPROVED;
83
                $answerObj->setVar('uid', $xoopsUser->getVar('uid'));
84
                break;
85
86
            case Constants::SF_STATUS_ANSWERED:
87
                $breadcrumb_action1   = _AM_SF_ANSWERED;
88
                $breadcrumb_action2   = _AM_SF_APPROVING;
89
                $collapsableBar_title = _AM_SF_ANSWERED_TITLE;
90
                $collapsableBar_info  = _AM_SF_ANSWERED_TITLE_INFO;
91
                $button_caption       = _AM_SF_APPROVE;
92
                $an_status            = Constants::SF_AN_STATUS_PROPOSED;
93
                break;
94
95
            case Constants::SF_STATUS_SUBMITTED:
96
                $breadcrumb_action1   = _AM_SF_SUBMITTED;
97
                $breadcrumb_action2   = _AM_SF_APPROVING;
98
                $collapsableBar_title = _AM_SF_SUBMITTED_TITLE;
99
                $collapsableBar_info  = _AM_SF_SUBMITTED_INFO;
100
                $button_caption       = _AM_SF_APPROVE;
101
                $an_status            = Constants::SF_AN_STATUS_PROPOSED;
102
                break;
103
104
            case Constants::SF_STATUS_PUBLISHED:
105
                $breadcrumb_action1   = _AM_SF_PUBLISHED;
106
                $breadcrumb_action2   = _AM_SF_EDITING;
107
                $collapsableBar_title = _AM_SF_PUBLISHEDEDITING;
108
                $collapsableBar_info  = _AM_SF_PUBLISHEDEDITING_INFO;
109
                $button_caption       = _AM_SF_MODIFY;
110
                $an_status            = Constants::SF_AN_STATUS_APPROVED;
111
                break;
112
113
            case Constants::SF_STATUS_OFFLINE:
114
                $breadcrumb_action1   = _AM_SF_OFFLINE;
115
                $breadcrumb_action2   = _AM_SF_EDITING;
116
                $collapsableBar_title = _AM_SF_OFFLINEEDITING;
117
                $collapsableBar_info  = _AM_SF_OFFLINEEDITING_INFO;
118
                $button_caption       = _AM_SF_MODIFY;
119
                $an_status            = Constants::SF_AN_STATUS_APPROVED;
120
                break;
121
122
            case Constants::SF_STATUS_OPENED:
123
                $breadcrumb_action1   = _AM_SF_OPEN_QUESTIONS;
124
                $breadcrumb_action2   = _AM_SF_ANSWERING;
125
                $collapsableBar_title = _AM_SF_OPEN_QUESTION_ANSWERING;
126
                $collapsableBar_info  = _AM_SF_OPEN_QUESTION_ANSWERING_INFO;
127
                $button_caption       = _AM_SF_PUBLISH;
128
                $an_status            = Constants::SF_AN_STATUS_NOTSET;
129
                $answerObj->setVar('uid', $xoopsUser->getVar('uid'));
130
                break;
131
132
            case Constants::SF_STATUS_NEW_ANSWER:
133
                $breadcrumb_action1   = _AM_SF_PUBLISHED;
134
                $breadcrumb_action2   = _AM_SF_EDITING;
135
                $collapsableBar_title = _AM_SF_NEW_ANSWER_EDITING;
136
                $collapsableBar_info  = _AM_SF_NEW_ANSWER_EDITING_INFO;
137
                $button_caption       = _AM_SF_PUBLISH;
138
                $an_status            = Constants::SF_AN_STATUS_NOTSET;
139
                break;
140
141
            case 'default':
142
            default:
143
                break;
144
        }
145
146
        /*      if (!$answerObj) {
147
                    redirect_header("faq.php", 2, _AM_SF_ANSWERNOTFOUND);
148
                }       */
149
150
        // Creating the category of this FAQ
151
        $categoryObj = $faqObj->category();
152
153
        echo "<br>\n";
154
        Smartfaq\Utility::collapsableBar('bottomtable', 'bottomtableicon');
155
        echo "<img id='bottomtableicon' src=" . XOOPS_URL . '/modules/' . $xoopsModule->dirname() . "/assets/images/icon/close12.gif alt=''></a>&nbsp;" . $collapsableBar_title . '</h3>';
156
        echo "<div id='bottomtable'>";
157
        echo '<span style="color: #567; margin: 3px 0 12px 0; font-size: small; display: block; ">' . $collapsableBar_info . '</span>';
158
    } else {
159
        // there's no parameter, so we're adding a faq
160
        $faqObj = $faqHandler->create();
161
        $faqObj->setVar('uid', $xoopsUser->getVar('uid'));
162
        $categoryObj = $categoryHandler->create();
163
        $answerObj   = $answerHandler->create();
164
        $answerObj->setVar('uid', $xoopsUser->getVar('uid'));
165
166
        $breadcrumb_action1 = _AM_SF_SMARTFAQS;
167
        $breadcrumb_action2 = _AM_SF_CREATINGNEW;
168
        $button_caption     = _AM_SF_CREATE;
169
170
        Smartfaq\Utility::collapsableBar('bottomtable', 'bottomtableicon');
171
        echo "<img id='bottomtableicon' src=" . XOOPS_URL . '/modules/' . $xoopsModule->dirname() . "/assets/images/icon/close12.gif alt=''></a>&nbsp;" . _AM_SF_CREATESMARTFAQ . '</h3>';
172
        echo "<div id='bottomtable'>";
173
    }
174
    $sform = new \XoopsThemeForm(_AM_SF_SMARTFAQ, 'op', xoops_getenv('PHP_SELF'), 'post', true);
175
    $sform->setExtra('enctype="multipart/form-data"');
176
177
    // faq requester
178
    $sform->addElement(new \XoopsFormLabel(_AM_SF_REQUESTED_BY, Smartfaq\Utility::getLinkedUnameFromId($faqObj->uid(), $helper->getConfig('userealname'))));
179
180
    // faq answered by
181
    $sform->addElement(new \XoopsFormLabel(_AM_SF_ANSWERED_BY, Smartfaq\Utility::getLinkedUnameFromId($answerObj->uid(), $helper->getConfig('userealname'))));
182
183
    // CATEGORY
184
    /*
185
    * Get information for pulldown menu using XoopsTree.
186
    * First var is the database table
187
    * Second var is the unique field ID for the categories
188
    * Last one is not set as we do not have sub menus in Smartfaq
189
    */
190
191
    $mytree = new Smartfaq\Tree($xoopsDB->prefix('smartfaq_categories'), 'categoryid', 'parentid');
192
    ob_start();
193
    $mytree->makeMySelBox('name', 'weight', $categoryObj->categoryid());
194
    $sform->addElement(new \XoopsFormLabel(_AM_SF_CATEGORY_FAQ, ob_get_contents()));
195
    ob_end_clean();
196
197
    // faq QUESTION
198
    $sform->addElement(new \XoopsFormTextArea(_AM_SF_QUESTION, 'question', $faqObj->question(0, 'e'), 7, 60));
199
200
    // ANSWER
201
    if ($merge) {
202
        $theanswer = $originalAnswerObj->answer('e') . "\n\n" . sprintf(_AM_SF_NEW_CONTRIBUTION, Smartfaq\Utility::getLinkedUnameFromId($answerObj->uid(), $helper->getConfig('userealname')), $answerObj->datesub(), $answerObj->answer('e'));
203
    } else {
204
        $theanswer = $answerObj->answer('e');
205
    }
206
207
    //$sform->addElement(new \XoopsFormDhtmlTextArea(_AM_SF_ANSWER_FAQ, 'answer', $theanswer, 15, 60), true);
208
209
    $editorTray = new \XoopsFormElementTray(_AM_SF_ANSWER_FAQ, '<br>');
210
    if (class_exists('XoopsFormEditor')) {
211
        $options['name']   = 'answer';
212
        $options['value']  = $theanswer;
213
        $options['rows']   = 5;
214
        $options['cols']   = '100%';
215
        $options['width']  = '100%';
216
        $options['height'] = '200px';
217
        $answerEditor      = new \XoopsFormEditor('', $helper->getConfig('form_editorOptions'), $options, $nohtml = false, $onfailure = 'textarea');
218
        $editorTray->addElement($answerEditor, true);
219
    } else {
220
        $answerEditor = new \XoopsFormDhtmlTextArea(_AM_SF_ANSWER_FAQ, 'answer', $theanswer, '100%', '100%');
221
        $editorTray->addElement($answerEditor, true);
222
    }
223
224
    $sform->addElement($editorTray);
225
226
    // HOW DO I
227
    $sform->addElement(new \XoopsFormText(_AM_SF_HOWDOI_FAQ, 'howdoi', 50, 255, $faqObj->howdoi('e')), false);
228
229
    // DIDUNO
230
    $sform->addElement(new \XoopsFormTextArea(_AM_SF_DIDUNO_FAQ, 'diduno', $faqObj->diduno('e'), 3, 60));
231
232
    // CONTEXT MODULE LINK
233
    // Retreive the list of module currently installed. The key value is the dirname
234
    /** @var XoopsModuleHandler $moduleHandler */
235
    $moduleHandler           = xoops_getHandler('module');
236
    $modules_array           = $moduleHandler->getList(null, true);
237
    $modulelink_select_array = ['url' => _AM_SF_SPECIFIC_URL_SELECT];
238
    $modulelink_select_array = array_merge($modules_array, $modulelink_select_array);
239
    $modulelink_select_array = array_merge(['None' => _AM_SF_NONE, 'All' => _AM_SF_ALL], $modulelink_select_array);
240
241
    $modulelink_select = new \XoopsFormSelect('', 'modulelink', $faqObj->modulelink());
242
    $modulelink_select->addOptionArray($modulelink_select_array);
243
    $modulelink_tray = new \XoopsFormElementTray(_AM_SF_CONTEXTMODULELINK_FAQ, '&nbsp;');
244
    $modulelink_tray->addElement($modulelink_select);
245
    $sform->addElement($modulelink_tray);
246
247
    // SPECIFICURL
248
    $sform->addElement(new \XoopsFormText(_AM_SF_SPECIFIC_URL, 'contextpage', 50, 60, $faqObj->contextpage()), false);
249
250
    // EXACT URL?
251
    $excaturl_radio = new \XoopsFormRadioYN(_AM_SF_EXACTURL, 'exacturl', $faqObj->exacturl(), ' ' . _AM_SF_YES . '', ' ' . _AM_SF_NO . '');
252
    $sform->addElement($excaturl_radio);
253
    // WEIGHT
254
    $sform->addElement(new \XoopsFormText(_AM_SF_WEIGHT, 'weight', 5, 5, $faqObj->weight()), true);
255
256
    // COMMENTS
257
    // Code to allow comments
258
    $addcomments_radio = new \XoopsFormRadioYN(_AM_SF_ALLOWCOMMENTS, 'cancomment', $faqObj->cancomment(), ' ' . _AM_SF_YES . '', ' ' . _AM_SF_NO . '');
259
    $sform->addElement($addcomments_radio);
260
261
    // PER ITEM PERMISSIONS
262
    $memberHandler   = xoops_getHandler('member');
263
    $group_list      = $memberHandler->getGroupList();
264
    $groups_checkbox = new \XoopsFormCheckBox(_AM_SF_PERMISSIONS_FAQ, 'groups[]', $faqObj->getGroups_read());
265
    foreach ($group_list as $group_id => $group_name) {
266
        if (XOOPS_GROUP_ADMIN != $group_id) {
267
            $groups_checkbox->addOption($group_id, $group_name);
268
        }
269
    }
270
    $sform->addElement($groups_checkbox);
271
272
    $partial_view = new \XoopsFormRadioYN(_AM_SF_PARTIALVIEW, 'partialview', $faqObj->partialview(), ' ' . _AM_SF_YES . '', ' ' . _AM_SF_NO . '');
273
    $sform->addElement($partial_view);
274
275
    // VARIOUS OPTIONS
276
    $options_tray = new \XoopsFormElementTray(_AM_SF_OPTIONS, '<br>');
277
278
    $html_checkbox = new \XoopsFormCheckBox('', 'html', $faqObj->html());
279
    $html_checkbox->addOption(1, _AM_SF_DOHTML);
280
    $options_tray->addElement($html_checkbox);
281
282
    $smiley_checkbox = new \XoopsFormCheckBox('', 'smiley', $faqObj->smiley());
283
    $smiley_checkbox->addOption(1, _AM_SF_DOSMILEY);
284
    $options_tray->addElement($smiley_checkbox);
285
286
    $xcodes_checkbox = new \XoopsFormCheckBox('', 'xcodes', $faqObj->xcodes());
287
    $xcodes_checkbox->addOption(1, _AM_SF_DOXCODE);
288
    $options_tray->addElement($xcodes_checkbox);
289
290
    $sform->addElement($options_tray);
291
292
    // OFFLINE
293
    if (Constants::SF_STATUS_OFFLINE == $faqObj->status()) {
294
        // Back OnLine
295
        $offline_radio = new \XoopsFormRadioYN(_AM_SF_OFFLINE_FIELD, 'offline', 1, ' ' . _AM_SF_YES . '', ' ' . _AM_SF_NO . '');
296
        $sform->addElement($offline_radio);
297
    }
298
299
    // faq ID
300
    $sform->addElement(new \XoopsFormHidden('faqid', $faqObj->faqid()));
301
302
    // requester id
303
    $sform->addElement(new \XoopsFormHidden('requester_uid', $faqObj->uid()));
304
305
    // answerer id
306
    $sform->addElement(new \XoopsFormHidden('answerer_uid', $answerObj->uid()));
307
308
    // ANSWER ID
309
    $sform->addElement(new \XoopsFormHidden('answerid', $answerObj->answerid()));
310
311
    $button_tray = new \XoopsFormElementTray('', '');
312
    $hidden      = new \XoopsFormHidden('op', 'addfaq');
313
    $button_tray->addElement($hidden);
314
315
    $sform->addElement(new \XoopsFormHidden('status', $faqObj->status()));
316
317
    // Setting the FAQ Status
318
    /*  $status_select = new \XoopsFormSelect('', 'status', $status);
319
    $status_select->addOptionArray(Smartfaq\Utility::getStatusArray());
320
    $status_tray = new \XoopsFormElementTray(_AM_SF_STATUS_EXP , '&nbsp;');
321
    $status_tray->addElement($status_select);
322
    $sform->addElement($status_tray);
323
    */
324
    if (!$faqid) {
325
        // there's no faqid? Then it's a new faq
326
        // $button_tray -> addElement( new \XoopsFormButton( '', 'mod', _AM_SF_CREATE, 'submit' ) );
327
        $butt_create = new \XoopsFormButton('', '', _AM_SF_CREATE, 'submit');
328
        $butt_create->setExtra('onclick="this.form.elements.op.value=\'addfaq\'"');
329
        $button_tray->addElement($butt_create);
330
331
        $butt_clear = new \XoopsFormButton('', '', _AM_SF_CLEAR, 'reset');
332
        $button_tray->addElement($butt_clear);
333
334
        $butt_cancel = new \XoopsFormButton('', '', _AM_SF_CANCEL, 'button');
335
        $butt_cancel->setExtra('onclick="history.go(-1)"');
336
        $button_tray->addElement($butt_cancel);
337
    } else {
338
        // else, we're editing an existing faq
339
        // $button_tray -> addElement( new \XoopsFormButton( '', 'mod', _AM_SF_MODIFY, 'submit' ) );
340
        $butt_create = new \XoopsFormButton('', '', $button_caption, 'submit');
341
        $butt_create->setExtra('onclick="this.form.elements.op.value=\'addfaq\'"');
342
        $button_tray->addElement($butt_create);
343
344
        $butt_cancel = new \XoopsFormButton('', '', _AM_SF_CANCEL, 'button');
345
        $butt_cancel->setExtra('onclick="history.go(-1)"');
346
        $button_tray->addElement($butt_cancel);
347
    }
348
349
    $sform->addElement($button_tray);
350
    $sform->display();
351
    echo '</div>';
352
    unset($hidden);
353
}
354
355
/* -- Available operations -- */
356
switch ($op) {
357
    case 'merge':
358
359
        $faqid    = isset($_GET['faqid']) ? $_GET['faqid'] : -1;
360
        $answerid = isset($_GET['answerid']) ? $_GET['answerid'] : -1;
361
        if (-1 == $faqid) {
362
            $totalcategories = $categoryHandler->getCategoriesCount(-1);
363
            if (0 == $totalcategories) {
364
                redirect_header('category.php?op=mod', 3, _AM_SF_NEED_CATEGORY_FAQ);
365
            }
366
        }
367
368
        xoops_cp_header();
369
        require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
370
371
        editfaq(true, $faqid, $answerid, true);
372
        break;
373
374
    case 'mod':
375
376
        global $xoopsUser, $xoopsUser, $xoopsConfig, $xoopsDB, $xoopsModule, $modify, $myts;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
377
        $faqid    = isset($_GET['faqid']) ? $_GET['faqid'] : -1;
378
        $answerid = isset($_GET['answerid']) ? $_GET['answerid'] : -1;
379
        if (-1 == $faqid) {
380
            $totalcategories = $categoryHandler->getCategoriesCount(-1);
381
            if (0 == $totalcategories) {
382
                redirect_header('category.php?op=mod', 3, _AM_SF_NEED_CATEGORY_FAQ);
383
            }
384
        }
385
386
        $adminObject = \Xmf\Module\Admin::getInstance();
387
        xoops_cp_header();
388
389
        $adminObject->displayNavigation(basename(__FILE__));
390
        require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
391
392
        editfaq(true, $faqid, $answerid);
393
        break;
394
395
    case 'addfaq':
396
        global $xoopsUser;
397
398
        $faqid        = Request::getInt('faqid', -1, 'POST');
399
        $requesterUid = Request::getInt('requester_uid', 0, 'POST');
400
        $answererUid  = Request::getInt('answerer_uid', 0, 'POST');
401
402
        // Creating the FAQ and answer objects
403
        if (-1 != $faqid) {
404
            $faqObj    = new Smartfaq\Faq($faqid);
405
            $answerObj = $faqObj->answer();
406
            // If the FAQ does not have an answer, then it's an answered opened question
407
            if (!$answerObj) {
0 ignored issues
show
$answerObj is of type XoopsModules\Smartfaq\Answer, thus it always evaluated to true.
Loading history...
408
                echo 'error in faq.php...200412111827';
409
            }
410
        } else {
411
            $faqObj    = $faqHandler->create();
412
            $answerObj = $answerHandler->create();
413
        }
414
415
        // Putting the values in the FAQ object
416
        //        if (isset($_POST['groups'])) {
417
        //            $faqObj->setGroups_read($_POST['groups']);
418
        //        } else {
419
        //            $faqObj->setGroups_read();
420
        //        }
421
422
        if (Request::hasVar('groups', 'POST')) {
423
            $faqObj->setGroups_read(Request::getArray('groups', [], 'POST'));
424
        } else {
425
            $faqObj->setGroups_read();
426
        }
427
428
        $faqObj->setVar('categoryid', Request::getInt('categoryid', 0, 'POST'));
429
        $faqObj->setVar('question', Request::getString('question', '', 'POST'));
430
        $faqObj->setVar('howdoi', Request::getString('howdoi', '', 'POST'));
431
        $faqObj->setVar('diduno', Request::getString('diduno', '', 'POST'));
432
433
        $faqObj->setVar('status', Request::getInt('status', Constants::SF_STATUS_ASKED, 'POST'));
434
435
        // If this SmartFAQ is offline and the user set this option to No
436
        $offline = Request::getInt('offline', 1, 'POST');
437
        if ((0 == $offline) && (Constants::SF_STATUS_OFFLINE == $faqObj->status())) {
438
            $faqObj->setVar('status', Constants::SF_STATUS_PUBLISHED);
439
        }
440
        $faqObj->setVar('weight', Request::getInt('weight', $faqObj->weight(), 'POST'));
441
        $faqObj->setVar('html', Request::getInt('html', 0, 'POST'));
442
        $faqObj->setVar('smiley', Request::getInt('smiley', 0, 'POST'));
443
        $faqObj->setVar('xcodes', Request::getInt('xcodes', 0, 'POST'));
444
        $faqObj->setVar('cancomment', Request::getInt('cancomment', 0, 'POST'));
445
        $faqObj->setVar('modulelink', Request::getString('modulelink', '', 'POST'));
446
        $faqObj->setVar('contextpage', Request::getString('contextpage', '', 'POST'));
447
        $faqObj->setVar('exacturl', Request::getString('exacturl', '', 'POST'));
448
        $faqObj->setVar('partialview', Request::getInt('partialview', 0, 'POST'));
449
        $faqObj->setVar('uid', $requesterUid);
450
451
        switch ($faqObj->status()) {
452
453
            case Constants::SF_STATUS_ASKED:
454
                $redirect_msg = _AM_SF_ASKED_APPROVE_SUCCESS;
455
                $error_msg    = _AM_SF_ARTNOTUPDATED;
456
                // Setting the new status
457
                $status    = Constants::SF_STATUS_PUBLISHED;
458
                $an_status = Constants::SF_AN_STATUS_APPROVED;
459
                $notifToDo = [Constants::SF_NOT_FAQ_PUBLISHED];
460
                break;
461
462
            case Constants::SF_STATUS_ANSWERED:
463
                $redirect_msg = _AM_SF_ANSWERED_APPROVE_SUCCESS;
464
                $error_msg    = _AM_SF_ARTNOTUPDATED;
465
                // Setting the new status
466
                $status    = Constants::SF_STATUS_PUBLISHED;
467
                $an_status = Constants::SF_AN_STATUS_APPROVED;
468
                $notifToDo = [Constants::SF_NOT_FAQ_PUBLISHED];
469
                break;
470
471
            case Constants::SF_STATUS_SUBMITTED:
472
                $redirect_msg = _AM_SF_SUBMITTED_APPROVE_SUCCESS;
473
                $error_msg    = _AM_SF_ARTNOTUPDATED;
474
                // Setting the new status
475
                $status    = Constants::SF_STATUS_PUBLISHED;
476
                $an_status = Constants::SF_AN_STATUS_APPROVED;
477
                $notifToDo = [Constants::SF_NOT_FAQ_PUBLISHED];
478
                break;
479
480
            case Constants::SF_STATUS_PUBLISHED:
481
                $redirect_msg = _AM_SF_PUBLISHED_MOD_SUCCESS;
482
                $error_msg    = _AM_SF_ARTNOTUPDATED;
483
                // Setting the new status
484
                $status    = Constants::SF_STATUS_PUBLISHED;
485
                $an_status = Constants::SF_AN_STATUS_APPROVED;
486
                break;
487
488
            case Constants::SF_STATUS_OPENED:
489
                $redirect_msg = _AM_SF_OPENED_ANSWERING_SUCCESS;
490
                $error_msg    = _AM_SF_ARTNOTUPDATED;
491
                // Setting the new status
492
                $status    = Constants::SF_STATUS_PUBLISHED;
493
                $an_status = Constants::SF_AN_STATUS_APPROVED;
494
                $notifToDo = [Constants::SF_NOT_FAQ_PUBLISHED];
495
                break;
496
497
            case Constants::SF_STATUS_NEW_ANSWER:
498
                $redirect_msg = _AM_SF_FAQ_NEW_ANSWER_PUBLISHED;
499
                $error_msg    = _AM_SF_ARTNOTUPDATED;
500
                // Setting the new status
501
                $status    = Constants::SF_STATUS_PUBLISHED;
502
                $an_status = Constants::SF_AN_STATUS_APPROVED;
503
                //$notifToDo = array(Constants::SF_NOT_FAQ_PUBLISHED);
504
                break;
505
506
            case Constants::SF_STATUS_OFFLINE:
507
                break;
508
509
            case 'default':
510
            default:
511
                $redirect_msg = _AM_SF_SUBMITTED_APPROVE_SUCCESS;
512
                $error_msg    = _AM_SF_ARTNOTCREATED;
513
                // Setting the new status
514
                $status    = Constants::SF_STATUS_PUBLISHED;
515
                $an_status = Constants::SF_AN_STATUS_APPROVED;
516
                $notifToDo = [Constants::SF_NOT_FAQ_PUBLISHED];
517
                break;
518
        }
519
        $faqObj->setVar('status', $status);
520
521
        // Puting the info in the answer ibject
522
        $answerObj->setVar('answer', $_POST['answer']);
523
        $answerObj->setVar('status', $an_status);
524
        $answerObj->setVar('uid', $answererUid);
525
526
        // Storing the FAQ
527
        if (!$faqObj->store()) {
528
            redirect_header('javascript:history.go(-1)', 3, $error_msg . Smartfaq\Utility::formatErrors($faqObj->getErrors()));
529
        }
530
531
        // Storing the answer
532
        $answerObj->setVar('faqid', $faqObj->faqid());
533
        if (!$answerObj->store()) {
534
            redirect_header('javascript:history.go(-1)', 3, $error_msg . Smartfaq\Utility::formatErrors($answerObj->getErrors()));
535
        }
536
537
        // Send notifications
538
        if (!empty($notifToDo)) {
539
            $faqObj->sendNotifications($notifToDo);
540
        }
541
542
        redirect_header('faq.php', 2, $redirect_msg);
543
        break;
544
545
    case 'del':
546
        global $xoopsUser, $xoopsUser, $xoopsConfig, $xoopsDB, $_GET;
547
548
        $module_id    = $xoopsModule->getVar('mid');
549
        $gpermHandler = xoops_getHandler('groupperm');
550
551
        $faqid = Request::getInt('faqid', 0, 'POST');
552
        $faqid = Request::getInt('faqid', $faqid, 'GET');
553
554
        $faqObj = new Smartfaq\Faq($faqid);
555
556
        $confirm  = Request::getInt('confirm', 0, 'POST');
557
        $question = Request::getString('question', '', 'POST');
558
559
        if ($confirm) {
560
            if (!$faqHandler->delete($faqObj)) {
561
                redirect_header('faq.php', 2, _AM_SF_FAQ_DELETE_ERROR . Smartfaq\Utility::formatErrors($faqObj->getErrors()));
562
            }
563
564
            redirect_header('faq.php', 2, sprintf(_AM_SF_ARTISDELETED, $faqObj->question()));
565
        } else {
566
            // no confirm: show deletion condition
567
            $faqid =  Request::getInt('faqid', 0, 'POST');
568
            xoops_cp_header();
569
            xoops_confirm([
570
                              'op'      => 'del',
571
                              'faqid'   => $faqObj->faqid(),
572
                              'confirm' => 1,
573
                              'name'    => $faqObj->question()
574
                          ], 'faq.php', _AM_SF_DELETETHISARTICLE . " <br>'" . $faqObj->question() . "'. <br> <br>", _AM_SF_DELETE);
575
            xoops_cp_footer();
576
        }
577
578
        exit();
579
        break;
580
581
    case 'default':
582
    default:
583
        $adminObject = \Xmf\Module\Admin::getInstance();
584
        xoops_cp_header();
585
586
        $adminObject->displayNavigation(basename(__FILE__));
587
588
        require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
589
        require_once XOOPS_ROOT_PATH . '/class/pagenav.php';
590
591
        require_once XOOPS_ROOT_PATH . '/modules/smartfaq/include/displayfaqs.php';
592
593
        $totalcategories = $categoryHandler->getCategoriesCount(-1);
594
        if ($totalcategories > 0) {
595
            editfaq();
596
        }
597
598
        break;
599
}
600
601
require_once __DIR__ . '/admin_footer.php';
602