Completed
Branch master (1b2f30)
by Michael
06:29 queued 03:22
created

admin/faq.php (13 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 37 and the first side effect is on line 9.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
/**
4
 * Module: SmartFAQ
5
 * Author: The SmartFactory <www.smartfactory.ca>
6
 * Licence: GNU
7
 */
8
9
include_once __DIR__ . '/admin_header.php';
10
11
// Creating the faq handler object
12
$faqHandler = sf_gethandler('faq');
13
14
// Creating the category handler object
15
$categoryHandler = sf_gethandler('category');
16
17
// Creating the answer handler object
18
$answerHandler = sf_gethandler('answer');
19
20
$op = '';
21
if (isset($_GET['op'])) {
22
    $op = $_GET['op'];
23
}
24
if (isset($_POST['op'])) {
25
    $op = $_POST['op'];
26
}
27
28
// Where shall we start?
29
$startfaq = isset($_GET['startfaq']) ? (int)$_GET['startfaq'] : 0;
30
31
/**
32
 * @param bool $showmenu
33
 * @param int  $faqid
0 ignored issues
show
Should the type for parameter $faqid not be string?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
34
 * @param int  $answerid
35
 * @param bool $merge
36
 */
37
function editfaq($showmenu = false, $faqid = -1, $answerid = -1, $merge = false)
0 ignored issues
show
The function editfaq() has been defined more than once; this definition is ignored, only the first definition in admin/answer.php (L27-130) is considered.

This check looks for functions that have already been defined in other files.

Some Codebases, like WordPress, make a practice of defining functions multiple times. This may lead to problems with the detection of function parameters and types. If you really need to do this, you can mark the duplicate definition with the @ignore annotation.

/**
 * @ignore
 */
function getUser() {

}

function getUser($id, $realm) {

}

See also the PhpDoc documentation for @ignore.

Loading history...
38
{
39
    global $answerHandler, $faqHandler, $categoryHandler, $xoopsUser, $xoopsUser, $xoopsConfig, $xoopsDB, $modify, $xoopsModuleConfig, $xoopsModule, $XOOPS_URL, $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...
40
41
    include_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
42
    // If there is a parameter, and the id exists, retrieve data: we're editing a faq
43
    if ($faqid != -1) {
44
        // Creating the FAQ object
45
        $faqObj = new sfFaq($faqid);
46
47
        if ($faqObj->notLoaded()) {
48
            redirect_header('faq.php', 1, _AM_SF_NOFAQSELECTED);
49
        }
50
51
        if ($answerid == -1) {
52
            // Creating the object for the official answer
53
            $answerObj = $faqObj->answer();
54
            if (!$answerObj) {
55
                $answerObj = $answerHandler->create();
56
            }
57
        } else {
58
            $answerObj         = new sfAnswer($answerid);
59
            $originalAnswerObj = $faqObj->answer();
60
        }
61
62
        switch ($faqObj->status()) {
63
64
            case _SF_STATUS_ASKED:
65
                $breadcrumb_action1   = _AM_SF_ASKED;
66
                $breadcrumb_action2   = _AM_SF_APPROVING;
67
                $collapsableBar_title = _AM_SF_ASKED_TITLE;
68
                $collapsableBar_info  = _AM_SF_ASKED_TITLE_INFO;
69
                $button_caption       = _AM_SF_PUBLISHED;
70
                $an_status            = _SF_AN_STATUS_APPROVED;
71
                $answerObj->setVar('uid', $xoopsUser->getVar('uid'));
72
                break;
73
74
            case _SF_STATUS_ANSWERED:
75
                $breadcrumb_action1   = _AM_SF_ANSWERED;
76
                $breadcrumb_action2   = _AM_SF_APPROVING;
77
                $collapsableBar_title = _AM_SF_ANSWERED_TITLE;
78
                $collapsableBar_info  = _AM_SF_ANSWERED_TITLE_INFO;
79
                $button_caption       = _AM_SF_APPROVE;
80
                $an_status            = _SF_AN_STATUS_PROPOSED;
81
                break;
82
83 View Code Duplication
            case _SF_STATUS_SUBMITTED:
84
                $breadcrumb_action1   = _AM_SF_SUBMITTED;
85
                $breadcrumb_action2   = _AM_SF_APPROVING;
86
                $collapsableBar_title = _AM_SF_SUBMITTED_TITLE;
87
                $collapsableBar_info  = _AM_SF_SUBMITTED_INFO;
88
                $button_caption       = _AM_SF_APPROVE;
89
                $an_status            = _SF_AN_STATUS_PROPOSED;
90
                break;
91
92
            case _SF_STATUS_PUBLISHED:
93
                $breadcrumb_action1   = _AM_SF_PUBLISHED;
94
                $breadcrumb_action2   = _AM_SF_EDITING;
95
                $collapsableBar_title = _AM_SF_PUBLISHEDEDITING;
96
                $collapsableBar_info  = _AM_SF_PUBLISHEDEDITING_INFO;
97
                $button_caption       = _AM_SF_MODIFY;
98
                $an_status            = _SF_AN_STATUS_APPROVED;
99
                break;
100
101
            case _SF_STATUS_OFFLINE:
102
                $breadcrumb_action1   = _AM_SF_OFFLINE;
103
                $breadcrumb_action2   = _AM_SF_EDITING;
104
                $collapsableBar_title = _AM_SF_OFFLINEEDITING;
105
                $collapsableBar_info  = _AM_SF_OFFLINEEDITING_INFO;
106
                $button_caption       = _AM_SF_MODIFY;
107
                $an_status            = _SF_AN_STATUS_APPROVED;
108
                break;
109
110
            case _SF_STATUS_OPENED:
111
                $breadcrumb_action1   = _AM_SF_OPEN_QUESTIONS;
112
                $breadcrumb_action2   = _AM_SF_ANSWERING;
113
                $collapsableBar_title = _AM_SF_OPEN_QUESTION_ANSWERING;
114
                $collapsableBar_info  = _AM_SF_OPEN_QUESTION_ANSWERING_INFO;
115
                $button_caption       = _AM_SF_PUBLISH;
116
                $an_status            = _SF_AN_STATUS_NOTSET;
117
                $answerObj->setVar('uid', $xoopsUser->getVar('uid'));
118
                break;
119
120
            case _SF_STATUS_NEW_ANSWER:
121
                $breadcrumb_action1   = _AM_SF_PUBLISHED;
122
                $breadcrumb_action2   = _AM_SF_EDITING;
123
                $collapsableBar_title = _AM_SF_NEW_ANSWER_EDITING;
124
                $collapsableBar_info  = _AM_SF_NEW_ANSWER_EDITING_INFO;
125
                $button_caption       = _AM_SF_PUBLISH;
126
                $an_status            = _SF_AN_STATUS_NOTSET;
127
                break;
128
129
            case 'default':
130
            default:
131
                break;
132
        }
133
134
        /*      if (!$answerObj) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
61% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
135
                    redirect_header("faq.php", 2, _AM_SF_ANSWERNOTFOUND);
136
                }       */
137
138
        // Creating the category of this FAQ
139
        $categoryObj = $faqObj->category();
140
141
        echo "<br />\n";
142
        sf_collapsableBar('bottomtable', 'bottomtableicon');
143
        echo "<img id='bottomtableicon' src=" . XOOPS_URL . '/modules/' . $xoopsModule->dirname() . "/assets/images/icon/close12.gif alt='' /></a>&nbsp;" . $collapsableBar_title . '</h3>';
144
        echo "<div id='bottomtable'>";
145
        echo "<span style=\"color: #567; margin: 3px 0 12px 0; font-size: small; display: block; \">" . $collapsableBar_info . '</span>';
146
    } else {
147
        // there's no parameter, so we're adding a faq
148
        $faqObj =& $faqHandler->create();
149
        $faqObj->setVar('uid', $xoopsUser->getVar('uid'));
150
        $categoryObj = $categoryHandler->create();
151
        $answerObj   = $answerHandler->create();
152
        $answerObj->setVar('uid', $xoopsUser->getVar('uid'));
153
154
        $breadcrumb_action1 = _AM_SF_SMARTFAQS;
155
        $breadcrumb_action2 = _AM_SF_CREATINGNEW;
156
        $button_caption     = _AM_SF_CREATE;
157
158
        sf_collapsableBar('bottomtable', 'bottomtableicon');
159
        echo "<img id='bottomtableicon' src=" . XOOPS_URL . '/modules/' . $xoopsModule->dirname() . "/assets/images/icon/close12.gif alt='' /></a>&nbsp;" . _AM_SF_CREATESMARTFAQ . '</h3>';
160
        echo "<div id='bottomtable'>";
161
    }
162
    $sform = new XoopsThemeForm(_AM_SF_SMARTFAQ, 'op', xoops_getenv('PHP_SELF'));
163
    $sform->setExtra('enctype="multipart/form-data"');
164
165
    // faq requester
166
    $sform->addElement(new XoopsFormLabel(_AM_SF_REQUESTED_BY, sf_getLinkedUnameFromId($faqObj->uid(), $xoopsModuleConfig['userealname'])));
167
168
    // faq answered by
169
    $sform->addElement(new XoopsFormLabel(_AM_SF_ANSWERED_BY, sf_getLinkedUnameFromId($answerObj->uid(), $xoopsModuleConfig['userealname'])));
170
171
    // CATEGORY
172
    /*
173
    * Get information for pulldown menu using XoopsTree.
174
    * First var is the database table
175
    * Second var is the unique field ID for the categories
176
    * Last one is not set as we do not have sub menus in Smartfaq
177
    */
178
179
    $mytree = new XoopsTree($xoopsDB->prefix('smartfaq_categories'), 'categoryid', 'parentid');
180
    ob_start();
181
    $mytree->makeMySelBox('name', 'weight', $categoryObj->categoryid());
182
    $sform->addElement(new XoopsFormLabel(_AM_SF_CATEGORY_FAQ, ob_get_contents()));
183
    ob_end_clean();
184
185
    // faq QUESTION
186
    $sform->addElement(new XoopsFormTextArea(_AM_SF_QUESTION, 'question', $faqObj->question(0, 'e'), 7, 60));
187
188
    // ANSWER
189
    if ($merge) {
190
        $theanswer = $originalAnswerObj->answer('e') . "\n\n" . sprintf(_AM_SF_NEW_CONTRIBUTION, sf_getLinkedUnameFromId($answerObj->uid(), $xoopsModuleConfig['userealname']), $answerObj->datesub(), $answerObj->answer('e'));
191
    } else {
192
        $theanswer = $answerObj->answer('e');
193
    }
194
195
    //$sform->addElement(new XoopsFormDhtmlTextArea(_AM_SF_ANSWER_FAQ, 'answer', $theanswer, 15, 60), true);
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
196
197
    $editorTray = new XoopsFormElementTray(_AM_SF_ANSWER_FAQ, '<br />');
198 View Code Duplication
    if (class_exists('XoopsFormEditor')) {
199
        $options['name']   = 'answer';
200
        $options['value']  = $theanswer;
201
        $options['rows']   = 5;
202
        $options['cols']   = '100%';
203
        $options['width']  = '100%';
204
        $options['height'] = '200px';
205
        $answerEditor      = new XoopsFormEditor('', $xoopsModuleConfig['form_editorOptions'], $options, $nohtml = false, $onfailure = 'textarea');
206
        $editorTray->addElement($answerEditor, true);
207
    } else {
208
        $answerEditor = new XoopsFormDhtmlTextArea(_AM_SF_ANSWER_FAQ, 'answer', $theanswer, '100%', '100%');
209
        $editorTray->addElement($answerEditor, true);
210
    }
211
212
    $sform->addElement($editorTray);
213
214
    // HOW DO I
215
    $sform->addElement(new XoopsFormText(_AM_SF_HOWDOI_FAQ, 'howdoi', 50, 255, $faqObj->howdoi('e')), false);
216
217
    // DIDUNO
218
    $sform->addElement(new XoopsFormTextArea(_AM_SF_DIDUNO_FAQ, 'diduno', $faqObj->diduno('e'), 3, 60));
219
220
    // CONTEXT MODULE LINK
221
    // Retreive the list of module currently installed. The key value is the dirname
222
    $moduleHandler           = xoops_getHandler('module');
223
    $modules_array           = $moduleHandler->getList(null, true);
224
    $modulelink_select_array = array('url' => _AM_SF_SPECIFIC_URL_SELECT);
225
    $modulelink_select_array = array_merge($modules_array, $modulelink_select_array);
226
    $modulelink_select_array = array_merge(array('None' => _AM_SF_NONE, 'All' => _AM_SF_ALL), $modulelink_select_array);
227
228
    $modulelink_select = new XoopsFormSelect('', 'modulelink', $faqObj->modulelink());
229
    $modulelink_select->addOptionArray($modulelink_select_array);
230
    $modulelink_tray = new XoopsFormElementTray(_AM_SF_CONTEXTMODULELINK_FAQ, '&nbsp;');
231
    $modulelink_tray->addElement($modulelink_select);
232
    $sform->addElement($modulelink_tray);
233
234
    // SPECIFICURL
235
    $sform->addElement(new XoopsFormText(_AM_SF_SPECIFIC_URL, 'contextpage', 50, 60, $faqObj->contextpage()), false);
236
237
    // EXACT URL?
238
    $excaturl_radio = new XoopsFormRadioYN(_AM_SF_EXACTURL, 'exacturl', $faqObj->exacturl(), ' ' . _AM_SF_YES . '', ' ' . _AM_SF_NO . '');
239
    $sform->addElement($excaturl_radio);
240
    // WEIGHT
241
    $sform->addElement(new XoopsFormText(_AM_SF_WEIGHT, 'weight', 5, 5, $faqObj->weight()), true);
242
243
    // COMMENTS
244
    // Code to allow comments
245
    $addcomments_radio = new XoopsFormRadioYN(_AM_SF_ALLOWCOMMENTS, 'cancomment', $faqObj->cancomment(), ' ' . _AM_SF_YES . '', ' ' . _AM_SF_NO . '');
246
    $sform->addElement($addcomments_radio);
247
248
    // PER ITEM PERMISSIONS
249
    $memberHandler   = xoops_getHandler('member');
250
    $group_list      = $memberHandler->getGroupList();
251
    $groups_checkbox = new XoopsFormCheckBox(_AM_SF_PERMISSIONS_FAQ, 'groups[]', $faqObj->getGroups_read());
252
    foreach ($group_list as $group_id => $group_name) {
253
        if ($group_id != XOOPS_GROUP_ADMIN) {
254
            $groups_checkbox->addOption($group_id, $group_name);
255
        }
256
    }
257
    $sform->addElement($groups_checkbox);
258
259
    $partial_view = new XoopsFormRadioYN(_AM_SF_PARTIALVIEW, 'partialview', $faqObj->partialview(), ' ' . _AM_SF_YES . '', ' ' . _AM_SF_NO . '');
260
    $sform->addElement($partial_view);
261
262
    // VARIOUS OPTIONS
263
    $options_tray = new XoopsFormElementTray(_AM_SF_OPTIONS, '<br />');
264
265
    $html_checkbox = new XoopsFormCheckBox('', 'html', $faqObj->html());
266
    $html_checkbox->addOption(1, _AM_SF_DOHTML);
267
    $options_tray->addElement($html_checkbox);
268
269
    $smiley_checkbox = new XoopsFormCheckBox('', 'smiley', $faqObj->smiley());
270
    $smiley_checkbox->addOption(1, _AM_SF_DOSMILEY);
271
    $options_tray->addElement($smiley_checkbox);
272
273
    $xcodes_checkbox = new XoopsFormCheckBox('', 'xcodes', $faqObj->xcodes());
274
    $xcodes_checkbox->addOption(1, _AM_SF_DOXCODE);
275
    $options_tray->addElement($xcodes_checkbox);
276
277
    $sform->addElement($options_tray);
278
279
    // OFFLINE
280
    if ($faqObj->status() == _SF_STATUS_OFFLINE) {
281
        // Back OnLine
282
        $offline_radio = new XoopsFormRadioYN(_AM_SF_OFFLINE_FIELD, 'offline', 1, ' ' . _AM_SF_YES . '', ' ' . _AM_SF_NO . '');
283
        $sform->addElement($offline_radio);
284
    }
285
286
    // faq ID
287
    $sform->addElement(new XoopsFormHidden('faqid', $faqObj->faqid()));
288
289
    // requester id
290
    $sform->addElement(new XoopsFormHidden('requester_uid', $faqObj->uid()));
291
292
    // answerer id
293
    $sform->addElement(new XoopsFormHidden('answerer_uid', $answerObj->uid()));
294
295
    // ANSWER ID
296
    $sform->addElement(new XoopsFormHidden('answerid', $answerObj->answerid()));
297
298
    $button_tray = new XoopsFormElementTray('', '');
299
    $hidden      = new XoopsFormHidden('op', 'addfaq');
300
    $button_tray->addElement($hidden);
301
302
    $sform->addElement(new XoopsFormHidden('status', $faqObj->status()));
303
304
    // Setting the FAQ Status
305
    /*  $status_select = new XoopsFormSelect('', 'status', $status);
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
306
    $status_select->addOptionArray(sf_getStatusArray());
307
    $status_tray = new XoopsFormElementTray(_AM_SF_STATUS_EXP , '&nbsp;');
308
    $status_tray->addElement($status_select);
309
    $sform->addElement($status_tray);
310
    */
311 View Code Duplication
    if (!$faqid) {
312
        // there's no faqid? Then it's a new faq
313
        // $button_tray -> addElement( new XoopsFormButton( '', 'mod', _AM_SF_CREATE, 'submit' ) );
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
314
        $butt_create = new XoopsFormButton('', '', _AM_SF_CREATE, 'submit');
315
        $butt_create->setExtra('onclick="this.form.elements.op.value=\'addfaq\'"');
316
        $button_tray->addElement($butt_create);
317
318
        $butt_clear = new XoopsFormButton('', '', _AM_SF_CLEAR, 'reset');
319
        $button_tray->addElement($butt_clear);
320
321
        $butt_cancel = new XoopsFormButton('', '', _AM_SF_CANCEL, 'button');
322
        $butt_cancel->setExtra('onclick="history.go(-1)"');
323
        $button_tray->addElement($butt_cancel);
324
    } else {
325
        // else, we're editing an existing faq
326
        // $button_tray -> addElement( new XoopsFormButton( '', 'mod', _AM_SF_MODIFY, 'submit' ) );
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
327
        $butt_create = new XoopsFormButton('', '', $button_caption, 'submit');
328
        $butt_create->setExtra('onclick="this.form.elements.op.value=\'addfaq\'"');
329
        $button_tray->addElement($butt_create);
330
331
        $butt_cancel = new XoopsFormButton('', '', _AM_SF_CANCEL, 'button');
332
        $butt_cancel->setExtra('onclick="history.go(-1)"');
333
        $button_tray->addElement($butt_cancel);
334
    }
335
336
    $sform->addElement($button_tray);
337
    $sform->display();
338
    echo '</div>';
339
    unset($hidden);
340
}
341
342
/* -- Available operations -- */
343
switch ($op) {
344
    case 'merge':
0 ignored issues
show
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
345
346
        $faqid    = isset($_GET['faqid']) ? $_GET['faqid'] : -1;
347
        $answerid = isset($_GET['answerid']) ? $_GET['answerid'] : -1;
348 View Code Duplication
        if ($faqid == -1) {
349
            $totalcategories = $categoryHandler->getCategoriesCount(-1);
350
            if ($totalcategories == 0) {
351
                redirect_header('category.php?op=mod', 3, _AM_SF_NEED_CATEGORY_FAQ);
352
            }
353
        }
354
355
        xoops_cp_header();
356
        include_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
357
358
        editfaq(true, $faqid, $answerid, true);
359
        break;
360
361
    case 'mod':
0 ignored issues
show
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
362
363
        global $xoopsUser, $xoopsUser, $xoopsConfig, $xoopsDB, $xoopsModuleConfig, $xoopsModule, $modify, $myts;
364
        $faqid    = isset($_GET['faqid']) ? $_GET['faqid'] : -1;
365
        $answerid = isset($_GET['answerid']) ? $_GET['answerid'] : -1;
366 View Code Duplication
        if ($faqid == -1) {
367
            $totalcategories = $categoryHandler->getCategoriesCount(-1);
368
            if ($totalcategories == 0) {
369
                redirect_header('category.php?op=mod', 3, _AM_SF_NEED_CATEGORY_FAQ);
370
            }
371
        }
372
373
        $indexAdmin = new ModuleAdmin();
374
        xoops_cp_header();
375
376
        echo $indexAdmin->addNavigation(basename(__FILE__));
377
        include_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
378
379
        editfaq(true, $faqid, $answerid);
380
        break;
381
382
    case 'addfaq':
383
        global $xoopsUser;
384
385
        $faqid         = isset($_POST['faqid']) ? (int)$_POST['faqid'] : -1;
386
        $requester_uid = isset($_POST['requester_uid']) ? (int)$_POST['requester_uid'] : 0;
387
        $answerer_uid  = isset($_POST['answerer_uid']) ? (int)$_POST['answerer_uid'] : 0;
388
389
        // Creating the FAQ and answer objects
390
        if ($faqid != -1) {
391
            $faqObj    = new sfFaq($faqid);
392
            $answerObj = $faqObj->answer();
393
            // If the FAQ does not have an answer, then it's an answered opened question
394
            if (!$answerObj) {
395
                echo 'error in faq.php...200412111827';
396
            }
397
        } else {
398
            $faqObj    = $faqHandler->create();
399
            $answerObj = $answerHandler->create();
400
        }
401
402
        // Putting the values in the FAQ object
403
        if (isset($_POST['groups'])) {
404
            $faqObj->setGroups_read($_POST['groups']);
405
        } else {
406
            $faqObj->setGroups_read();
407
        }
408
        $faqObj->setVar('categoryid', isset($_POST['categoryid']) ? (int)$_POST['categoryid'] : 0);
409
        $faqObj->setVar('question', $_POST['question']);
410
        $faqObj->setVar('howdoi', $_POST['howdoi']);
411
        $faqObj->setVar('diduno', $_POST['diduno']);
412
413
        $faqObj->setVar('status', isset($_POST['status']) ? (int)$_POST['status'] : _SF_STATUS_ASKED);
414
415
        // If this SmartFAQ is offline and the user set this option to No
416
        $offline = isset($_POST['offline']) ? $_POST['offline'] : 1;
417
        if ((0 == $offline) && ($faqObj->status() == _SF_STATUS_OFFLINE)) {
418
            $faqObj->setVar('status', _SF_STATUS_PUBLISHED);
419
        }
420
        $faqObj->setVar('weight', isset($_POST['weight']) ? (int)$_POST['weight'] : $faqObj->weight());
421
        $faqObj->setVar('html', isset($_POST['html']) ? (int)$_POST['html'] : 0);
422
        $faqObj->setVar('smiley', isset($_POST['smiley']) ? (int)$_POST['smiley'] : 0);
423
        $faqObj->setVar('xcodes', isset($_POST['xcodes']) ? (int)$_POST['xcodes'] : 0);
424
        $faqObj->setVar('cancomment', isset($_POST['cancomment']) ? (int)$_POST['cancomment'] : 0);
425
        $faqObj->setVar('modulelink', $_POST['modulelink']);
426
        $faqObj->setVar('contextpage', $_POST['contextpage']);
427
        $faqObj->setVar('exacturl', $_POST['exacturl']);
428
        $faqObj->setVar('partialview', $_POST['partialview']);
429
        $faqObj->setVar('uid', $requester_uid);
430
431
        switch ($faqObj->status()) {
432
433
            case _SF_STATUS_ASKED:
434
                $redirect_msg = _AM_SF_ASKED_APPROVE_SUCCESS;
435
                $error_msg    = _AM_SF_ARTNOTUPDATED;
436
                // Setting the new status
437
                $status    = _SF_STATUS_PUBLISHED;
438
                $an_status = _SF_AN_STATUS_APPROVED;
439
                $notifToDo = array(_SF_NOT_FAQ_PUBLISHED);
440
                break;
441
442
            case _SF_STATUS_ANSWERED:
443
                $redirect_msg = _AM_SF_ANSWERED_APPROVE_SUCCESS;
444
                $error_msg    = _AM_SF_ARTNOTUPDATED;
445
                // Setting the new status
446
                $status    = _SF_STATUS_PUBLISHED;
447
                $an_status = _SF_AN_STATUS_APPROVED;
448
                $notifToDo = array(_SF_NOT_FAQ_PUBLISHED);
449
                break;
450
451 View Code Duplication
            case _SF_STATUS_SUBMITTED:
452
                $redirect_msg = _AM_SF_SUBMITTED_APPROVE_SUCCESS;
453
                $error_msg    = _AM_SF_ARTNOTUPDATED;
454
                // Setting the new status
455
                $status    = _SF_STATUS_PUBLISHED;
456
                $an_status = _SF_AN_STATUS_APPROVED;
457
                $notifToDo = array(_SF_NOT_FAQ_PUBLISHED);
458
                break;
459
460
            case _SF_STATUS_PUBLISHED:
461
                $redirect_msg = _AM_SF_PUBLISHED_MOD_SUCCESS;
462
                $error_msg    = _AM_SF_ARTNOTUPDATED;
463
                // Setting the new status
464
                $status    = _SF_STATUS_PUBLISHED;
465
                $an_status = _SF_AN_STATUS_APPROVED;
466
                break;
467
468
            case _SF_STATUS_OPENED:
469
                $redirect_msg = _AM_SF_OPENED_ANSWERING_SUCCESS;
470
                $error_msg    = _AM_SF_ARTNOTUPDATED;
471
                // Setting the new status
472
                $status    = _SF_STATUS_PUBLISHED;
473
                $an_status = _SF_AN_STATUS_APPROVED;
474
                $notifToDo = array(_SF_NOT_FAQ_PUBLISHED);
475
                break;
476
477
            case _SF_STATUS_NEW_ANSWER:
478
                $redirect_msg = _AM_SF_FAQ_NEW_ANSWER_PUBLISHED;
479
                $error_msg    = _AM_SF_ARTNOTUPDATED;
480
                // Setting the new status
481
                $status    = _SF_STATUS_PUBLISHED;
482
                $an_status = _SF_AN_STATUS_APPROVED;
483
                //$notifToDo = array(_SF_NOT_FAQ_PUBLISHED);
0 ignored issues
show
Unused Code Comprehensibility introduced by
56% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
484
                break;
485
486
            case _SF_STATUS_OFFLINE:
487
                break;
488
489
            case 'default':
490 View Code Duplication
            default :
491
                $redirect_msg = _AM_SF_SUBMITTED_APPROVE_SUCCESS;
492
                $error_msg    = _AM_SF_ARTNOTCREATED;
493
                // Setting the new status
494
                $status    = _SF_STATUS_PUBLISHED;
495
                $an_status = _SF_AN_STATUS_APPROVED;
496
                $notifToDo = array(_SF_NOT_FAQ_PUBLISHED);
497
                break;
498
        }
499
        $faqObj->setVar('status', $status);
500
501
        // Puting the info in the answer ibject
502
        $answerObj->setVar('answer', $_POST['answer']);
503
        $answerObj->setVar('status', $an_status);
504
        $answerObj->setVar('uid', $answerer_uid);
505
506
        // Storing the FAQ
507
        if (!$faqObj->store()) {
508
            redirect_header('javascript:history.go(-1)', 3, $error_msg . sf_formatErrors($faqObj->getErrors()));
509
        }
510
511
        // Storing the answer
512
        $answerObj->setVar('faqid', $faqObj->faqid());
513
        if (!$answerObj->store()) {
514
            redirect_header('javascript:history.go(-1)', 3, $error_msg . sf_formatErrors($answerObj->getErrors()));
515
        }
516
517
        // Send notifications
518
        if (!empty($notifToDo)) {
519
            $faqObj->sendNotifications($notifToDo);
520
        }
521
522
        redirect_header('faq.php', 2, $redirect_msg);
523
        break;
524
525 View Code Duplication
    case 'del':
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
526
        global $xoopsUser, $xoopsUser, $xoopsConfig, $xoopsDB, $_GET;
527
528
        $module_id    = $xoopsModule->getVar('mid');
529
        $gpermHandler = xoops_getHandler('groupperm');
530
531
        $faqid = isset($_POST['faqid']) ? (int)$_POST['faqid'] : 0;
532
        $faqid = isset($_GET['faqid']) ? (int)$_GET['faqid'] : $faqid;
533
534
        $faqObj = new sfFaq($faqid);
535
536
        $confirm  = isset($_POST['confirm']) ? $_POST['confirm'] : 0;
537
        $question = isset($_POST['question']) ? $_POST['question'] : '';
538
539
        if ($confirm) {
540
            if (!$faqHandler->delete($faqObj)) {
541
                redirect_header('faq.php', 2, _AM_SF_FAQ_DELETE_ERROR . sf_formatErrors($faqObj->getErrors()));
542
            }
543
544
            redirect_header('faq.php', 2, sprintf(_AM_SF_ARTISDELETED, $faqObj->question()));
545
        } else {
546
            // no confirm: show deletion condition
547
            $faqid = isset($_GET['faqid']) ? (int)$_GET['faqid'] : 0;
548
            xoops_cp_header();
549
            xoops_confirm(array('op' => 'del', 'faqid' => $faqObj->faqid(), 'confirm' => 1, 'name' => $faqObj->question()), 'faq.php', _AM_SF_DELETETHISARTICLE . " <br />'" . $faqObj->question() . "'. <br /> <br />", _AM_SF_DELETE);
550
            xoops_cp_footer();
551
        }
552
553
        exit();
554
        break;
555
556
    case 'default':
557
    default:
558
        $indexAdmin = new ModuleAdmin();
559
        xoops_cp_header();
560
561
        echo $indexAdmin->addNavigation(basename(__FILE__));
562
563
        include_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
564
        include_once XOOPS_ROOT_PATH . '/class/pagenav.php';
565
566
        include_once XOOPS_ROOT_PATH . '/modules/smartfaq/include/displayfaqs.php';
567
568
        $totalcategories = $categoryHandler->getCategoriesCount(-1);
569
        if ($totalcategories > 0) {
570
            editfaq();
571
        }
572
573
        break;
574
}
575
576
include_once __DIR__ . '/admin_footer.php';
577