Completed
Push — master ( bb1ebf...0d7d1b )
by Michael
02:07
created

request.php (12 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
2
3
/**
4
 * Module: SmartFAQ
5
 * Author: The SmartFactory <www.smartfactory.ca>
6
 * Licence: GNU
7
 */
8
9
require_once __DIR__ . '/header.php';
10
require_once XOOPS_ROOT_PATH . '/header.php';
11
12
global $xoopsUser, $xoopsConfig, $xoopsModuleConfig, $xoopsModule;
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...
13
14
// Creating the category handler object
15
$categoryHandler = sf_gethandler('category');
16
17
// Creating the FAQ handler object
18
$faqHandler = sf_gethandler('faq');
19
20
// Get the total number of categories
21
$totalCategories = count($categoryHandler->getCategories());
22
23
if ($totalCategories == 0) {
24
    redirect_header('index.php', 1, _AM_SF_NOCOLEXISTS);
25
}
26
27
// Find if the user is admin of the module
28
$isAdmin = sf_userIsAdmin();
29
// If the user is not admin AND we don't allow user submission, exit
30 View Code Duplication
if (!($isAdmin
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...
31
      || (isset($xoopsModuleConfig['allowrequest'])
32
          && $xoopsModuleConfig['allowrequest'] == 1
33
          && (is_object($xoopsUser) || (isset($xoopsModuleConfig['anonpost']) && $xoopsModuleConfig['anonpost'] == 1))))) {
34
    redirect_header('index.php', 1, _NOPERM);
35
}
36
37
$op = '';
38
39
if (isset($_GET['op'])) {
40
    $op = $_GET['op'];
41
}
42
if (isset($_POST['op'])) {
43
    $op = $_POST['op'];
44
}
45
46
switch ($op) {
47
    case 'post':
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...
48
49
        global $xoopsUser, $xoopsConfig, $xoopsModule, $xoopsModuleConfig, $xoopsDB;
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...
50
51
        $newFaqObj = $faqHandler->create();
52
53 View Code Duplication
        if (!$xoopsUser) {
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...
54
            if ($xoopsModuleConfig['anonpost'] == 1) {
55
                $uid = 0;
56
            } else {
57
                redirect_header('index.php', 3, _NOPERM);
58
            }
59
        } else {
60
            $uid = $xoopsUser->uid();
0 ignored issues
show
The method uid cannot be called on $xoopsUser (of type integer|double|string|array|boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
61
        }
62
63
        // Putting the values about the FAQ in the FAQ object
64
        $newFaqObj->setVar('categoryid', $_POST['categoryid']);
65
        $newFaqObj->setVar('uid', $uid);
66
        $newFaqObj->setVar('question', $_POST['question']);
67
        $notifypub = isset($_POST['notifypub']) ? $_POST['notifypub'] : 0;
68
        $newFaqObj->setVar('notifypub', $notifypub);
69
70
        // Setting the status of the FAQ
71
        if ($xoopsModuleConfig['autoapprove_request'] == 1) {
72
            $newFaqObj->setVar('status', _SF_STATUS_OPENED);
73
        } else {
74
            $newFaqObj->setVar('status', _SF_STATUS_ASKED);
75
        }
76
77
        // Storing the FAQ object in the database
78
        if (!$newFaqObj->store()) {
79
            redirect_header('javascript:history.go(-1)', 3, _MD_SF_REQUEST_ERROR . sf_formatErrors($newFaqObj->getErrors()));
80
        }
81
82
        // Get the cateopry object related to that FAQ
83
        // If autoapprove_requested
84
        if ($xoopsModuleConfig['autoapprove_request'] == 1) {
85
            // We do not not subscribe user to notification on publish since we publish it right away
86
87
            // Send notifications
88
            $newFaqObj->sendNotifications(array(_SF_NOT_QUESTION_PUBLISHED));
89
90
            $redirect_msg = _MD_SF_REQUEST_RECEIVED_AND_PUBLISHED;
91 View Code Duplication
        } else {
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...
92
            // Subscribe the user to On Published notification, if requested
93
            if ($notifypub == 1) {
94
                require_once XOOPS_ROOT_PATH . '/include/notification_constants.php';
95
                $notificationHandler = xoops_getHandler('notification');
96
                $notificationHandler->subscribe('question', $newFaqObj->faqid(), 'approved', XOOPS_NOTIFICATION_MODE_SENDONCETHENDELETE);
97
            }
98
            // Send notifications
99
            $newFaqObj->sendNotifications(array(_SF_NOT_QUESTION_SUBMITTED));
100
101
            $redirect_msg = _MD_SF_REQUEST_RECEIVED_NEED_APPROVAL;
102
        }
103
104
        //redirect_header("javascript:history.go(-2)", 3, $redirect_msg);
0 ignored issues
show
Unused Code Comprehensibility introduced by
73% 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...
105
        redirect_header('index.php', 2, $redirect_msg);
106
        break;
107
108
    case 'form':
109
    default:
0 ignored issues
show
The default body in a switch statement must start on the line following the statement.

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

switch ($expr) {
    default:
        doSomething(); //right
        break;
}


switch ($expr) {
    default:

        doSomething(); //wrong
        break;
}

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

Loading history...
110
111
        global $xoopsUser, $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...
112
113
        $GLOBALS['xoopsOption']['template_main'] = 'smartfaq_submit.tpl';
114
        require_once XOOPS_ROOT_PATH . '/header.php';
115
        require_once __DIR__ . '/footer.php';
116
117
        $name = $xoopsUser ? ucwords($xoopsUser->getVar('uname')) : 'Anonymous';
0 ignored issues
show
The method getVar cannot be called on $xoopsUser (of type integer|double|string|array|boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
118
119
        $moduleName =& $myts->displayTarea($xoopsModule->getVar('name'));
120
        $xoopsTpl->assign('whereInSection', $moduleName);
121
        $xoopsTpl->assign('lang_submit', _MD_SF_REQUEST);
122
123
        $xoopsTpl->assign('lang_intro_title', _MD_SF_REQUEST);
124
        $xoopsTpl->assign('lang_intro_text', _MD_SF_GOODDAY . "<b>$name</b>, " . $myts->displayTarea($xoopsModuleConfig['requestintromsg']));
125
126
        require_once __DIR__ . '/include/request.inc.php';
127
128
        $name = $xoopsUser ? ucwords($xoopsUser->getVar('uname')) : 'Anonymous';
0 ignored issues
show
The method getVar cannot be called on $xoopsUser (of type integer|double|string|array|boolean).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
129
130
        $sectionname = $myts->htmlSpecialChars($xoopsModule->getVar('name'));
131
132
        require_once __DIR__ . '/include/request.inc.php';
133
134
        require_once XOOPS_ROOT_PATH . '/footer.php';
135
136
        break;
137
}
138