mambax7 /
smartfaq
| 1 | <?php |
||
| 2 | |||
| 3 | /** |
||
| 4 | * Module: SmartFAQ |
||
| 5 | * Author: The SmartFactory <www.smartfactory.ca> |
||
| 6 | * Licence: GNU |
||
| 7 | */ |
||
| 8 | |||
| 9 | use XoopsModules\Smartfaq; |
||
| 10 | use XoopsModules\Smartfaq\Constants; |
||
| 11 | |||
| 12 | /** @var Smartfaq\Helper $helper */ |
||
| 13 | $helper = Smartfaq\Helper::getInstance(); |
||
| 14 | |||
| 15 | require_once __DIR__ . '/admin_header.php'; |
||
| 16 | |||
| 17 | $op = ''; |
||
| 18 | |||
| 19 | // Getting the operation we are doing |
||
| 20 | if (isset($_GET['op'])) { |
||
| 21 | $op = $_GET['op']; |
||
| 22 | } |
||
| 23 | if (isset($_POST['op'])) { |
||
| 24 | $op = $_POST['op']; |
||
| 25 | } |
||
| 26 | |||
| 27 | // Creating the answer handler object |
||
| 28 | /** @var \XoopsModules\Smartfaq\AnswerHandler $answerHandler */ |
||
| 29 | $answerHandler = \XoopsModules\Smartfaq\Helper::getInstance()->getHandler('Answer'); |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @param string $faqid |
||
| 33 | */ |
||
| 34 | function editfaq($faqid = '') |
||
| 35 | { |
||
| 36 | global $answerHandler, $xoopsUser, $xoopsUser, $xoopsConfig, $xoopsDB, $modify, $xoopsModule, $XOOPS_URL, $myts, $pathIcon16, $smartModuleConfig; |
||
| 37 | /** @var Smartfaq\Helper $helper */ |
||
| 38 | $helper = Smartfaq\Helper::getInstance(); |
||
|
0 ignored issues
–
show
Unused Code
introduced
by
Loading history...
|
|||
| 39 | |||
| 40 | require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php'; |
||
| 41 | |||
| 42 | // Creating the FAQ object |
||
| 43 | $faqObj = new Smartfaq\Faq($faqid); |
||
| 44 | |||
| 45 | // Creating the category object |
||
| 46 | $categoryObj = $faqObj->category(); |
||
| 47 | |||
| 48 | if ($faqObj->notLoaded()) { |
||
| 49 | redirect_header('index.php', 1, _AM_SF_NOFAQSELECTED); |
||
| 50 | } |
||
| 51 | |||
| 52 | switch ($faqObj->status()) { |
||
| 53 | |||
| 54 | case Constants::SF_STATUS_ANSWERED: |
||
| 55 | $breadcrumb_action1 = _AM_SF_SUBMITTED; |
||
| 56 | $breadcrumb_action2 = _AM_SF_APPROVING; |
||
| 57 | $collapsableBar_title = _AM_SF_SUBMITTED_TITLE; |
||
| 58 | $collapsableBar_info = _AM_SF_SUBMITTED_INFO; |
||
| 59 | $button_caption = _AM_SF_APPROVE; |
||
| 60 | $an_status = Constants::SF_AN_STATUS_PROPOSED; |
||
| 61 | break; |
||
| 62 | |||
| 63 | } |
||
| 64 | |||
| 65 | $module_id = $xoopsModule->getVar('mid'); |
||
| 66 | $gpermHandler = xoops_getHandler('groupperm'); |
||
| 67 | $groups = $xoopsUser ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS; |
||
| 68 | |||
| 69 | if (!Smartfaq\Utility::userIsAdmin() |
||
| 70 | && (!$gpermHandler->checkRight('category_admin', $faqObj->categoryid(), $groups, $module_id))) { |
||
| 71 | redirect_header('javascript:history.go(-1)', 1, _NOPERM); |
||
| 72 | } |
||
| 73 | // Retreiving the official answer |
||
| 74 | $official_answer = $faqObj->answer(); |
||
| 75 | |||
| 76 | Smartfaq\Utility::collapsableBar('bottomtable', 'bottomtableicon'); |
||
| 77 | echo "<img id='bottomtableicon' src=" . XOOPS_URL . '/modules/' . $xoopsModule->dirname() . "/assets/images/icon/close12.gif alt=''></a> " . _AM_SF_SUBMITTED_ANSWER . '</h3>'; |
||
| 78 | echo "<div id='bottomtable'>"; |
||
| 79 | echo '<span style="color: #567; margin: 3px 0 12px 0; font-size: small; display: block; ">' . _AM_SF_SUBMITTED_ANSWER_INFO . '</span>'; |
||
| 80 | |||
| 81 | $proposed_answers = $answerHandler->getAllAnswers($faqid, Constants::SF_AN_STATUS_PROPOSED); |
||
| 82 | |||
| 83 | if (0 == count($proposed_answers)) { |
||
| 84 | redirect_header('index.php', 1, _AM_SF_NOANSWERS); |
||
| 85 | } |
||
| 86 | |||
| 87 | echo "<table width='100%' cellspacing=1 cellpadding=3 border=0 class = outer> |
||
| 88 | <tr> |
||
| 89 | <td class='head' width='100px'>" . _AM_SF_CATEGORY . "</td> |
||
| 90 | <td class='even'>" . $categoryObj->name() . "</td> |
||
| 91 | </tr> |
||
| 92 | <tr> |
||
| 93 | <td class='head' width='100px'>" . _AM_SF_QUESTION . "</td> |
||
| 94 | <td class='even'>" . $faqObj->question() . '</td> |
||
| 95 | </tr>'; |
||
| 96 | if ($official_answer) { |
||
|
0 ignored issues
–
show
|
|||
| 97 | echo " |
||
| 98 | <tr> |
||
| 99 | <td class='head' width='100px'>" . _AM_SF_ANSWER_OFFICIAL . "</td> |
||
| 100 | <td class='even'>" . $official_answer->answer() . '</td> |
||
| 101 | </tr>'; |
||
| 102 | } |
||
| 103 | echo "</table><br>\n"; |
||
| 104 | |||
| 105 | echo "<table width='100%' cellspacing=1 cellpadding=3 border=0 class = outer>"; |
||
| 106 | echo '<tr>'; |
||
| 107 | echo "<th width='40' class='bg3' align='center'><b>" . _AM_SF_ARTID . '</b></td>'; |
||
| 108 | echo "<th class='bg3' class='bg3' align='center'><b>" . _AM_SF_ANSWER . '</b></td>'; |
||
| 109 | |||
| 110 | echo "<th width='90' class='bg3' align='center'><b>" . _AM_SF_ANSWERED . '</b></td>'; |
||
| 111 | |||
| 112 | echo "<th width='180' class='bg3' align='center'><b>" . _AM_SF_CREATED . '</b></td>'; |
||
| 113 | echo "<th width='120' class='bg3' align='center'><b>" . _AM_SF_ACTION . '</b></td>'; |
||
| 114 | echo '</tr>'; |
||
| 115 | |||
| 116 | $merge = ''; |
||
| 117 | $modify = ''; |
||
| 118 | $approve = ''; |
||
| 119 | foreach ($proposed_answers as $proposed_answer) { |
||
| 120 | if (Constants::SF_STATUS_NEW_ANSWER == $faqObj->status()) { |
||
| 121 | $merge = "<a href='faq.php?op=merge&faqid=" |
||
| 122 | . $faqObj->faqid() |
||
| 123 | . '&answerid=' |
||
| 124 | . $proposed_answer->answerid() |
||
| 125 | . "'><img src='" |
||
| 126 | . XOOPS_URL |
||
| 127 | . '/modules/' |
||
| 128 | . $xoopsModule->dirname() |
||
| 129 | . "/assets/images/icon/merge.gif' title='" |
||
| 130 | . _AM_SF_FAQ_MERGE |
||
| 131 | . "' alt='" |
||
| 132 | . _AM_SF_FAQ_MERGE |
||
| 133 | . "'></a> "; |
||
| 134 | $approve = "<a href='answer.php?op=selectanswer&faqid=" . $faqid . '&answerid=' . $proposed_answer->answerid() . "'><img src='" . $pathIcon16 . '/on.png' . "' title='" . _AM_SF_FAQ_APPROVE_NEW_ANSWER . "' alt='" . _AM_SF_APPROVESUB . "'></a>"; |
||
| 135 | } |
||
| 136 | $modify = "<a href='faq.php?op=mod&faqid=" . $faqObj->faqid() . '&answerid=' . $proposed_answer->answerid() . "'><img src='" . $pathIcon16 . '/edit.png' . "' title='" . _AM_SF_FAQ_REVIEW . "' alt='" . _AM_SF_FAQ_REVIEW . "'></a> "; |
||
| 137 | $delete = "<a href='answer.php?op=del&faqid=" . $faqObj->faqid() . '&answerid=' . $proposed_answer->answerid() . "'><img src='" . $pathIcon16 . '/delete.png' . "' title='" . _AM_SF_DELETESUBM . "' alt='" . _AM_SF_DELETESUBM . "'></a>"; |
||
| 138 | echo '<tr>'; |
||
| 139 | echo "<td class='head' align='center'>" . $proposed_answer->answerid() . '</td>'; |
||
| 140 | echo "<td class='even' align='left'>" . $proposed_answer->answer() . '</td>'; |
||
| 141 | |||
| 142 | //show name of the answer submitter |
||
| 143 | $submitter = Smartfaq\Utility::getLinkedUnameFromId($proposed_answer->uid(), $smartModuleConfig['userealname']); |
||
| 144 | echo "<td class='even' align='center'>" . $submitter . '</td>'; |
||
| 145 | |||
| 146 | echo "<td class='even' align='center'>" . $proposed_answer->datesub() . '</td>'; |
||
| 147 | echo "<td class='even' align='center'> $merge $modify $approve $delete </td>"; |
||
| 148 | echo '</tr>'; |
||
| 149 | } |
||
| 150 | |||
| 151 | echo "</table>\n<br>"; |
||
| 152 | } |
||
| 153 | |||
| 154 | /* -- Available operations -- */ |
||
| 155 | switch ($op) { |
||
| 156 | case 'mod': |
||
| 157 | xoops_cp_header(); |
||
| 158 | require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php'; |
||
| 159 | 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 1. Pass all data via parametersfunction myFunction($a, $b) {
// Do something
}
2. Create a class that maintains your stateclass MyClass {
private $a;
private $b;
public function __construct($a, $b) {
$this->a = $a;
$this->b = $b;
}
public function myFunction() {
// Do something
}
}
Loading history...
|
|||
| 160 | $faqid = \Xmf\Request::getInt('faqid', 0, 'GET'); |
||
|
0 ignored issues
–
show
The type
Xmf\Request was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 161 | editfaq($faqid); |
||
| 162 | break; |
||
| 163 | |||
| 164 | case 'selectanswer': |
||
| 165 | global $xoopsUser, $_GET; |
||
|
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 1. Pass all data via parametersfunction myFunction($a, $b) {
// Do something
}
2. Create a class that maintains your stateclass MyClass {
private $a;
private $b;
public function __construct($a, $b) {
$this->a = $a;
$this->b = $b;
}
public function myFunction() {
// Do something
}
}
Loading history...
|
|||
| 166 | |||
| 167 | $faqid = \Xmf\Request::getInt('faqid', 0, 'GET'); |
||
| 168 | $answerid = \Xmf\Request::getInt('answerid', 0, 'GET'); |
||
| 169 | |||
| 170 | // Creating the FAQ object |
||
| 171 | $faqObj = new Smartfaq\Faq($faqid); |
||
| 172 | |||
| 173 | if ($faqObj->notLoaded()) { |
||
| 174 | redirect_header('index.php', 1, _AM_SF_NOFAQSELECTED); |
||
| 175 | } |
||
| 176 | |||
| 177 | // Creating the answer object |
||
| 178 | $answerObj = new Smartfaq\Answer($answerid); |
||
| 179 | |||
| 180 | if ($answerObj->notLoaded()) { |
||
| 181 | redirect_header('index.php', 1, _AM_SF_NOFAQSELECTED); |
||
| 182 | } |
||
| 183 | |||
| 184 | $answerObj->setVar('status', Constants::SF_AN_STATUS_APPROVED); |
||
| 185 | |||
| 186 | $notifToDo_answer = null; |
||
| 187 | $notifToDo_faq = null; |
||
| 188 | |||
| 189 | switch ($faqObj->status()) { |
||
| 190 | // This was an Open Question that became a Submitted FAQ |
||
| 191 | case Constants::SF_STATUS_ANSWERED: |
||
| 192 | if (1 == $helper->getConfig('autoapprove_submitted_faq')) { |
||
| 193 | // We automatically approve Submitted Q&A |
||
| 194 | $redirect_msg = _AM_SF_ANSWER_APPROVED_PUBLISHED; |
||
| 195 | $faqObj->setVar('status', Constants::SF_STATUS_PUBLISHED); |
||
| 196 | $answerObj->setVar('status', Constants::SF_AN_STATUS_APPROVED); |
||
| 197 | $notifToDo_faq = [Constants::SF_NOT_FAQ_PUBLISHED]; |
||
| 198 | } else { |
||
| 199 | // Submitted Q&A need approbation |
||
| 200 | $redirect_msg = _AM_SF_ANSWER_APPROVED_NEED_APPROVED; |
||
| 201 | $faqObj->setVar('status', Constants::SF_STATUS_SUBMITTED); |
||
| 202 | $answerObj->setVar('status', Constants::SF_AN_STATUS_APPROVED); |
||
| 203 | $notifToDo_faq = [Constants::SF_NOT_FAQ_SUBMITTED]; |
||
| 204 | } |
||
| 205 | break; |
||
| 206 | |||
| 207 | // This is a published FAQ for which a user submitted a new answer and we just accepeted one |
||
| 208 | case Constants::SF_STATUS_NEW_ANSWER: |
||
| 209 | $redirect_msg = _AM_SF_FAQ_NEW_ANSWER_PUBLISHED; |
||
| 210 | $faqObj->setVar('status', Constants::SF_STATUS_PUBLISHED); |
||
| 211 | $answerObj->setVar('status', Constants::SF_AN_STATUS_APPROVED); |
||
| 212 | $notifToDo_answer = [Constants::SF_NOT_ANSWER_APPROVED]; |
||
| 213 | break; |
||
| 214 | } |
||
| 215 | |||
| 216 | // Storing the FAQ object in the database |
||
| 217 | if (!$faqObj->store()) { |
||
| 218 | redirect_header('javascript:history.go(-1)', 2, _AM_SF_ERROR_FAQ_NOT_SAVED); |
||
| 219 | } |
||
| 220 | |||
| 221 | // Storing the answer object in the database |
||
| 222 | if (!$answerObj->store()) { |
||
| 223 | redirect_header('javascript:history.go(-1)', 2, _AM_SF_ERROR_ANSWER_NOT_SAVED); |
||
| 224 | } |
||
| 225 | |||
| 226 | // Send FAQ notifications |
||
| 227 | if (!empty($notifToDo_faq)) { |
||
| 228 | $faqObj->sendNotifications($notifToDo_faq); |
||
| 229 | } |
||
| 230 | |||
| 231 | // Send answer notifications |
||
| 232 | if (!empty($notifToDo_answer)) { |
||
| 233 | $answerObj->sendNotifications($notifToDo_answer); |
||
| 234 | } |
||
| 235 | |||
| 236 | redirect_header('index.php', 2, $redirect_msg); |
||
| 237 | break; |
||
| 238 | |||
| 239 | case 'del': |
||
| 240 | global $xoopsUser, $xoopsUser, $xoopsConfig, $xoopsDB; |
||
| 241 | |||
| 242 | $faqid = \Xmf\Request::getInt('faqid', 0, 'POST'); |
||
| 243 | $faqid = \Xmf\Request::getInt('faqid', $faqid, 'GET'); |
||
| 244 | $answerid = \Xmf\Request::getInt('answerid', 0, 'POST'); |
||
| 245 | $answerid = \Xmf\Request::getInt('answerid', $answerid, 'GET'); |
||
| 246 | $confirm = \Xmf\Request::getInt('confirm', 0, 'POST'); |
||
| 247 | $faqObj = new Smartfaq\Faq($faqid); |
||
| 248 | $answerObj = new Smartfaq\Answer($answerid); |
||
| 249 | if ($confirm) { |
||
| 250 | $answerObj->setVar('status', Constants::SF_AN_STATUS_REJECTED); |
||
| 251 | $answerObj->store(); |
||
| 252 | |||
| 253 | switch ($faqObj->status()) { |
||
| 254 | // Open Question for which we are rejecting an answer |
||
| 255 | case Constants::SF_STATUS_ANSWERED: |
||
| 256 | $redirect_page = 'index.php'; |
||
| 257 | $redirect_msg = _AM_SF_ANSWER_REJECTED_OPEN_QUESTION; |
||
| 258 | $faqObj->setVar('status', Constants::SF_STATUS_OPENED); |
||
| 259 | break; |
||
| 260 | |||
| 261 | case Constants::SF_STATUS_NEW_ANSWER: |
||
| 262 | $proposed_answers = $answerHandler->getAllAnswers($faqid, Constants::SF_AN_STATUS_PROPOSED); |
||
| 263 | if (count($proposed_answers) > 0) { |
||
| 264 | // This question has other proposed answer |
||
| 265 | $redirect_page = 'answer.php?op=mod&faqid=' . $faqid; |
||
| 266 | $redirect_msg = _AM_SF_ANSWER_REJECTED; |
||
| 267 | } else { |
||
| 268 | // The question has no other proposed answer |
||
| 269 | $redirect_page = 'index.php'; |
||
| 270 | $redirect_msg = _AM_SF_ANSWER_REJECTED; |
||
| 271 | $faqObj->setVar('status', Constants::SF_STATUS_PUBLISHED); |
||
| 272 | } |
||
| 273 | break; |
||
| 274 | } |
||
| 275 | $faqObj->store(); |
||
| 276 | redirect_header($redirect_page, 3, $redirect_msg); |
||
| 277 | } else { |
||
| 278 | xoops_cp_header(); |
||
| 279 | xoops_confirm(['op' => 'del', 'answerid' => $answerid, 'confirm' => 1, 'faqid' => $faqid], 'answer.php', _AM_SF_DELETETHISANSWER, _AM_SF_DELETE); |
||
| 280 | xoops_cp_footer(); |
||
| 281 | } |
||
| 282 | exit(); |
||
| 283 | break; |
||
| 284 | |||
| 285 | case 'default': |
||
| 286 | default: |
||
| 287 | xoops_cp_header(); |
||
| 288 | |||
| 289 | require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php'; |
||
| 290 | global $xoopsUser, $xoopsUser, $xoopsConfig, $xoopsDB, $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 1. Pass all data via parametersfunction myFunction($a, $b) {
// Do something
}
2. Create a class that maintains your stateclass MyClass {
private $a;
private $b;
public function __construct($a, $b) {
$this->a = $a;
$this->b = $b;
}
public function myFunction() {
// Do something
}
}
Loading history...
|
|||
| 291 | /** @var Smartfaq\Helper $helper */ |
||
| 292 | $helper = Smartfaq\Helper::getInstance(); |
||
| 293 | |||
| 294 | editfaq(); |
||
| 295 | break; |
||
| 296 | } |
||
| 297 | |||
| 298 | require_once __DIR__ . '/admin_footer.php'; |
||
| 299 |