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 | * $Id: request.php,v 1.14 2005/08/15 16:51:58 fx2024 Exp $ |
||
5 | * Module: SmartFAQ |
||
6 | * Author: The SmartFactory <www.smartfactory.ca> |
||
7 | * Licence: GNU |
||
8 | */ |
||
9 | |||
10 | include_once __DIR__ . '/header.php'; |
||
11 | include_once(XOOPS_ROOT_PATH . "/header.php"); |
||
12 | |||
13 | Global $xoopsUser, $xoopsConfig, $xoopsModuleConfig, $xoopsModule; |
||
14 | |||
15 | // Creating the category handler object |
||
16 | $category_handler =& sf_gethandler('category'); |
||
17 | |||
18 | // Creating the FAQ handler object |
||
19 | $faq_handler =& sf_gethandler('faq'); |
||
20 | |||
21 | // Get the total number of categories |
||
22 | $totalCategories = count($category_handler->getCategories()); |
||
23 | |||
24 | if ($totalCategories == 0) { |
||
25 | redirect_header("index.php", 1, _AM_SF_NOCOLEXISTS); |
||
26 | exit(); |
||
27 | } |
||
28 | |||
29 | // Find if the user is admin of the module |
||
30 | $isAdmin = sf_userIsAdmin(); |
||
31 | // If the user is not admin AND we don't allow user submission, exit |
||
32 | View Code Duplication | if (!($isAdmin || (isset($xoopsModuleConfig['allowrequest']) && $xoopsModuleConfig['allowrequest'] == 1 && (is_object($xoopsUser) || (isset($xoopsModuleConfig['anonpost']) && $xoopsModuleConfig['anonpost'] == 1))))) { |
|
33 | redirect_header("index.php", 1, _NOPERM); |
||
34 | exit(); |
||
35 | } |
||
36 | |||
37 | $op = ''; |
||
38 | |||
39 | if (isset($_GET['op'])) $op = $_GET['op']; |
||
40 | if (isset($_POST['op'])) $op = $_POST['op']; |
||
41 | |||
42 | switch ($op) { |
||
43 | case 'post': |
||
44 | |||
45 | Global $xoopsUser, $xoopsConfig, $xoopsModule, $xoopsModuleConfig, $xoopsDB; |
||
46 | |||
47 | $newFaqObj = $faq_handler->create(); |
||
48 | |||
49 | View Code Duplication | if (!$xoopsUser) { |
|
50 | if ($xoopsModuleConfig['anonpost'] == 1) { |
||
51 | $uid = 0; |
||
52 | } else { |
||
53 | redirect_header("index.php", 3, _NOPERM); |
||
54 | exit(); |
||
55 | } |
||
56 | } else { |
||
57 | $uid = $xoopsUser->uid(); |
||
58 | } |
||
59 | |||
60 | // Putting the values about the FAQ in the FAQ object |
||
61 | $newFaqObj->setVar('categoryid', $_POST['categoryid']); |
||
62 | $newFaqObj->setVar('uid', $uid); |
||
63 | $newFaqObj->setVar('question', $_POST['question']); |
||
64 | $notifypub = (isset($_POST['notifypub']))? $_POST['notifypub'] : 0; |
||
65 | $newFaqObj->setVar('notifypub', $notifypub); |
||
66 | |||
67 | // Setting the status of the FAQ |
||
68 | if ($xoopsModuleConfig['autoapprove_request'] == 1) { |
||
69 | $newFaqObj->setVar('status', _SF_STATUS_OPENED); |
||
70 | } else { |
||
71 | $newFaqObj->setVar('status', _SF_STATUS_ASKED); |
||
72 | } |
||
73 | |||
74 | // Storing the FAQ object in the database |
||
75 | View Code Duplication | if ( !$newFaqObj->store() ) { |
|
0 ignored issues
–
show
|
|||
76 | redirect_header("javascript:history.go(-1)", 3, _MD_SF_REQUEST_ERROR . sf_formatErrors($newFaqObj->getErrors())); |
||
77 | exit(); |
||
78 | } |
||
79 | |||
80 | // Get the cateopry object related to that FAQ |
||
81 | // If autoapprove_requested |
||
82 | if ($xoopsModuleConfig['autoapprove_request'] == 1) { |
||
83 | // We do not not subscribe user to notification on publish since we publish it right away |
||
84 | |||
85 | // Send notifications |
||
86 | $newFaqObj->sendNotifications(array(_SF_NOT_QUESTION_PUBLISHED)); |
||
87 | |||
88 | $redirect_msg = _MD_SF_REQUEST_RECEIVED_AND_PUBLISHED; |
||
89 | View Code Duplication | } else { |
|
90 | // Subscribe the user to On Published notification, if requested |
||
91 | if ($notifypub == 1) { |
||
92 | include_once XOOPS_ROOT_PATH . '/include/notification_constants.php'; |
||
93 | $notification_handler = &xoops_gethandler('notification'); |
||
94 | $notification_handler->subscribe('question', $newFaqObj->faqid(), 'approved', XOOPS_NOTIFICATION_MODE_SENDONCETHENDELETE); |
||
95 | } |
||
96 | // Send notifications |
||
97 | $newFaqObj->sendNotifications(array(_SF_NOT_QUESTION_SUBMITTED)); |
||
98 | |||
99 | $redirect_msg = _MD_SF_REQUEST_RECEIVED_NEED_APPROVAL; |
||
100 | } |
||
101 | |||
102 | //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. ![]() |
|||
103 | redirect_header("index.php", 2, $redirect_msg); |
||
104 | |||
105 | exit(); |
||
106 | break; |
||
107 | |||
108 | case 'form': |
||
109 | default: |
||
110 | |||
111 | global $xoopsUser, $myts; |
||
112 | |||
113 | $xoopsOption['template_main'] = 'smartfaq_submit.tpl'; |
||
114 | include_once(XOOPS_ROOT_PATH . "/header.php"); |
||
115 | include_once __DIR__ . '/footer.php'; |
||
116 | |||
117 | $name = ($xoopsUser)? (ucwords($xoopsUser->getVar("uname"))) : 'Anonymous'; |
||
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 | include_once 'include/request.inc.php'; |
||
127 | |||
128 | $name = ($xoopsUser)? (ucwords($xoopsUser->getVar("uname"))) : 'Anonymous'; |
||
0 ignored issues
–
show
|
|||
129 | |||
130 | $sectionname = $myts->htmlSpecialChars($xoopsModule->getVar('name')); |
||
131 | |||
132 | include_once 'include/request.inc.php'; |
||
133 | |||
134 | include_once XOOPS_ROOT_PATH . '/footer.php'; |
||
135 | |||
136 | break; |
||
137 | } |
||
138 |
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.