mambax7 /
smartfaq
| 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 = \Xmf\Request::getCmd('op', ''); |
||||||
| 31 | |||||||
| 32 | // Where shall we start? |
||||||
| 33 | $startfaq = \Xmf\Request::getInt('startfaq', 0, 'GET'); |
||||||
| 34 | |||||||
| 35 | /** |
||||||
| 36 | * @param bool $showmenu |
||||||
| 37 | * @param int $faqid |
||||||
| 38 | * @param int $answerid |
||||||
| 39 | * @param bool $merge |
||||||
| 40 | */ |
||||||
| 41 | function editfaq($showmenu = false, $faqid = -1, $answerid = -1, $merge = false) |
||||||
| 42 | { |
||||||
| 43 | global $answerHandler, $faqHandler, $categoryHandler, $xoopsUser, $xoopsUser, $xoopsConfig, $xoopsDB, $modify, $xoopsModule, $XOOPS_URL, $myts; |
||||||
| 44 | /** @var Smartfaq\Helper $helper */ |
||||||
| 45 | $helper = Smartfaq\Helper::getInstance(); |
||||||
| 46 | |||||||
| 47 | require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php'; |
||||||
| 48 | // If there is a parameter, and the id exists, retrieve data: we're editing a faq |
||||||
| 49 | if (-1 != $faqid) { |
||||||
| 50 | // Creating the FAQ object |
||||||
| 51 | $faqObj = new Smartfaq\Faq($faqid); |
||||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||||
| 52 | |||||||
| 53 | if ($faqObj->notLoaded()) { |
||||||
| 54 | redirect_header('faq.php', 1, _AM_SF_NOFAQSELECTED); |
||||||
| 55 | } |
||||||
| 56 | |||||||
| 57 | if (-1 == $answerid) { |
||||||
| 58 | // Creating the object for the official answer |
||||||
| 59 | $answerObj = $faqObj->answer(); |
||||||
| 60 | if (!$answerObj) { |
||||||
|
0 ignored issues
–
show
|
|||||||
| 61 | $answerObj = $answerHandler->create(); |
||||||
| 62 | } |
||||||
| 63 | } else { |
||||||
| 64 | $answerObj = new Smartfaq\Answer($answerid); |
||||||
|
0 ignored issues
–
show
It seems like
$answerid can also be of type integer; however, parameter $id of XoopsModules\Smartfaq\Answer::__construct() does only seem to accept null, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 65 | $originalAnswerObj = $faqObj->answer(); |
||||||
| 66 | } |
||||||
| 67 | |||||||
| 68 | switch ($faqObj->status()) { |
||||||
| 69 | case Constants::SF_STATUS_ASKED: |
||||||
| 70 | $breadcrumb_action1 = _AM_SF_ASKED; |
||||||
| 71 | $breadcrumb_action2 = _AM_SF_APPROVING; |
||||||
| 72 | $collapsableBar_title = _AM_SF_ASKED_TITLE; |
||||||
| 73 | $collapsableBar_info = _AM_SF_ASKED_TITLE_INFO; |
||||||
| 74 | $button_caption = _AM_SF_PUBLISHED; |
||||||
| 75 | $an_status = Constants::SF_AN_STATUS_APPROVED; |
||||||
| 76 | $answerObj->setVar('uid', $xoopsUser->getVar('uid')); |
||||||
| 77 | break; |
||||||
| 78 | case Constants::SF_STATUS_ANSWERED: |
||||||
| 79 | $breadcrumb_action1 = _AM_SF_ANSWERED; |
||||||
| 80 | $breadcrumb_action2 = _AM_SF_APPROVING; |
||||||
| 81 | $collapsableBar_title = _AM_SF_ANSWERED_TITLE; |
||||||
| 82 | $collapsableBar_info = _AM_SF_ANSWERED_TITLE_INFO; |
||||||
| 83 | $button_caption = _AM_SF_APPROVE; |
||||||
| 84 | $an_status = Constants::SF_AN_STATUS_PROPOSED; |
||||||
| 85 | break; |
||||||
| 86 | case Constants::SF_STATUS_SUBMITTED: |
||||||
| 87 | $breadcrumb_action1 = _AM_SF_SUBMITTED; |
||||||
| 88 | $breadcrumb_action2 = _AM_SF_APPROVING; |
||||||
| 89 | $collapsableBar_title = _AM_SF_SUBMITTED_TITLE; |
||||||
| 90 | $collapsableBar_info = _AM_SF_SUBMITTED_INFO; |
||||||
| 91 | $button_caption = _AM_SF_APPROVE; |
||||||
| 92 | $an_status = Constants::SF_AN_STATUS_PROPOSED; |
||||||
| 93 | break; |
||||||
| 94 | case Constants::SF_STATUS_PUBLISHED: |
||||||
| 95 | $breadcrumb_action1 = _AM_SF_PUBLISHED; |
||||||
| 96 | $breadcrumb_action2 = _AM_SF_EDITING; |
||||||
| 97 | $collapsableBar_title = _AM_SF_PUBLISHEDEDITING; |
||||||
| 98 | $collapsableBar_info = _AM_SF_PUBLISHEDEDITING_INFO; |
||||||
| 99 | $button_caption = _AM_SF_MODIFY; |
||||||
| 100 | $an_status = Constants::SF_AN_STATUS_APPROVED; |
||||||
| 101 | break; |
||||||
| 102 | case Constants::SF_STATUS_OFFLINE: |
||||||
| 103 | $breadcrumb_action1 = _AM_SF_OFFLINE; |
||||||
| 104 | $breadcrumb_action2 = _AM_SF_EDITING; |
||||||
| 105 | $collapsableBar_title = _AM_SF_OFFLINEEDITING; |
||||||
| 106 | $collapsableBar_info = _AM_SF_OFFLINEEDITING_INFO; |
||||||
| 107 | $button_caption = _AM_SF_MODIFY; |
||||||
| 108 | $an_status = Constants::SF_AN_STATUS_APPROVED; |
||||||
| 109 | break; |
||||||
| 110 | case Constants::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 = Constants::SF_AN_STATUS_NOTSET; |
||||||
| 117 | $answerObj->setVar('uid', $xoopsUser->getVar('uid')); |
||||||
| 118 | break; |
||||||
| 119 | case Constants::SF_STATUS_NEW_ANSWER: |
||||||
| 120 | $breadcrumb_action1 = _AM_SF_PUBLISHED; |
||||||
| 121 | $breadcrumb_action2 = _AM_SF_EDITING; |
||||||
| 122 | $collapsableBar_title = _AM_SF_NEW_ANSWER_EDITING; |
||||||
| 123 | $collapsableBar_info = _AM_SF_NEW_ANSWER_EDITING_INFO; |
||||||
| 124 | $button_caption = _AM_SF_PUBLISH; |
||||||
| 125 | $an_status = Constants::SF_AN_STATUS_NOTSET; |
||||||
| 126 | break; |
||||||
| 127 | case 'default': |
||||||
| 128 | default: |
||||||
| 129 | break; |
||||||
| 130 | } |
||||||
| 131 | |||||||
| 132 | /* if (!$answerObj) { |
||||||
| 133 | redirect_header("faq.php", 2, _AM_SF_ANSWERNOTFOUND); |
||||||
| 134 | } */ |
||||||
| 135 | |||||||
| 136 | // Creating the category of this FAQ |
||||||
| 137 | $categoryObj = $faqObj->category(); |
||||||
| 138 | |||||||
| 139 | echo "<br>\n"; |
||||||
| 140 | Smartfaq\Utility::collapsableBar('bottomtable', 'bottomtableicon'); |
||||||
| 141 | echo "<img id='bottomtableicon' src=" . XOOPS_URL . '/modules/' . $xoopsModule->dirname() . "/assets/images/icon/close12.gif alt=''></a> " . $collapsableBar_title . '</h3>'; |
||||||
| 142 | echo "<div id='bottomtable'>"; |
||||||
| 143 | echo '<span style="color: #567; margin: 3px 0 12px 0; font-size: small; display: block; ">' . $collapsableBar_info . '</span>'; |
||||||
| 144 | } else { |
||||||
| 145 | // there's no parameter, so we're adding a faq |
||||||
| 146 | $faqObj = $faqHandler->create(); |
||||||
| 147 | $faqObj->setVar('uid', $xoopsUser->getVar('uid')); |
||||||
| 148 | $categoryObj = $categoryHandler->create(); |
||||||
| 149 | $answerObj = $answerHandler->create(); |
||||||
| 150 | $answerObj->setVar('uid', $xoopsUser->getVar('uid')); |
||||||
| 151 | |||||||
| 152 | $breadcrumb_action1 = _AM_SF_SMARTFAQS; |
||||||
| 153 | $breadcrumb_action2 = _AM_SF_CREATINGNEW; |
||||||
| 154 | $button_caption = _AM_SF_CREATE; |
||||||
| 155 | |||||||
| 156 | Smartfaq\Utility::collapsableBar('bottomtable', 'bottomtableicon'); |
||||||
| 157 | echo "<img id='bottomtableicon' src=" . XOOPS_URL . '/modules/' . $xoopsModule->dirname() . "/assets/images/icon/close12.gif alt=''></a> " . _AM_SF_CREATESMARTFAQ . '</h3>'; |
||||||
| 158 | echo "<div id='bottomtable'>"; |
||||||
| 159 | } |
||||||
| 160 | $sform = new \XoopsThemeForm(_AM_SF_SMARTFAQ, 'op', xoops_getenv('PHP_SELF'), 'post', true); |
||||||
| 161 | $sform->setExtra('enctype="multipart/form-data"'); |
||||||
| 162 | |||||||
| 163 | // faq requester |
||||||
| 164 | $sform->addElement(new \XoopsFormLabel(_AM_SF_REQUESTED_BY, Smartfaq\Utility::getLinkedUnameFromId($faqObj->uid(), $helper->getConfig('userealname')))); |
||||||
| 165 | |||||||
| 166 | // faq answered by |
||||||
| 167 | $sform->addElement(new \XoopsFormLabel(_AM_SF_ANSWERED_BY, Smartfaq\Utility::getLinkedUnameFromId($answerObj->uid(), $helper->getConfig('userealname')))); |
||||||
| 168 | |||||||
| 169 | // CATEGORY |
||||||
| 170 | /* |
||||||
| 171 | * Get information for pulldown menu using XoopsTree. |
||||||
| 172 | * First var is the database table |
||||||
| 173 | * Second var is the unique field ID for the categories |
||||||
| 174 | * Last one is not set as we do not have sub menus in Smartfaq |
||||||
| 175 | */ |
||||||
| 176 | |||||||
| 177 | $mytree = new Smartfaq\Tree($xoopsDB->prefix('smartfaq_categories'), 'categoryid', 'parentid'); |
||||||
| 178 | ob_start(); |
||||||
| 179 | $mytree->makeMySelBox('name', 'weight', $categoryObj->categoryid()); |
||||||
| 180 | $sform->addElement(new \XoopsFormLabel(_AM_SF_CATEGORY_FAQ, ob_get_clean())); |
||||||
| 181 | |||||||
| 182 | // faq QUESTION |
||||||
| 183 | $sform->addElement(new \XoopsFormTextArea(_AM_SF_QUESTION, 'question', $faqObj->question(0, 'e'), 7, 60)); |
||||||
| 184 | |||||||
| 185 | // ANSWER |
||||||
| 186 | if ($merge) { |
||||||
| 187 | $theanswer = $originalAnswerObj->answer('e') . "\n\n" . sprintf(_AM_SF_NEW_CONTRIBUTION, Smartfaq\Utility::getLinkedUnameFromId($answerObj->uid(), $helper->getConfig('userealname')), $answerObj->datesub(), $answerObj->answer('e')); |
||||||
| 188 | } else { |
||||||
| 189 | $theanswer = $answerObj->answer('e'); |
||||||
| 190 | } |
||||||
| 191 | |||||||
| 192 | //$sform->addElement(new \XoopsFormDhtmlTextArea(_AM_SF_ANSWER_FAQ, 'answer', $theanswer, 15, 60), true); |
||||||
| 193 | |||||||
| 194 | $editorTray = new \XoopsFormElementTray(_AM_SF_ANSWER_FAQ, '<br>'); |
||||||
| 195 | if (class_exists('XoopsFormEditor')) { |
||||||
| 196 | $options['name'] = 'answer'; |
||||||
| 197 | $options['value'] = $theanswer; |
||||||
| 198 | $options['rows'] = 5; |
||||||
| 199 | $options['cols'] = '100%'; |
||||||
| 200 | $options['width'] = '100%'; |
||||||
| 201 | $options['height'] = '200px'; |
||||||
| 202 | $answerEditor = new \XoopsFormEditor('', $helper->getConfig('form_editorOptions'), $options, $nohtml = false, $onfailure = 'textarea'); |
||||||
| 203 | $editorTray->addElement($answerEditor, true); |
||||||
| 204 | } else { |
||||||
| 205 | $answerEditor = new \XoopsFormDhtmlTextArea(_AM_SF_ANSWER_FAQ, 'answer', $theanswer, '100%', '100%'); |
||||||
|
0 ignored issues
–
show
'100%' of type string is incompatible with the type integer expected by parameter $cols of XoopsFormDhtmlTextArea::__construct().
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
'100%' of type string is incompatible with the type integer expected by parameter $rows of XoopsFormDhtmlTextArea::__construct().
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 206 | $editorTray->addElement($answerEditor, true); |
||||||
| 207 | } |
||||||
| 208 | |||||||
| 209 | $sform->addElement($editorTray); |
||||||
| 210 | |||||||
| 211 | // HOW DO I |
||||||
| 212 | $sform->addElement(new \XoopsFormText(_AM_SF_HOWDOI_FAQ, 'howdoi', 50, 255, $faqObj->howdoi('e')), false); |
||||||
| 213 | |||||||
| 214 | // DIDUNO |
||||||
| 215 | $sform->addElement(new \XoopsFormTextArea(_AM_SF_DIDUNO_FAQ, 'diduno', $faqObj->diduno('e'), 3, 60)); |
||||||
| 216 | |||||||
| 217 | // CONTEXT MODULE LINK |
||||||
| 218 | // Retreive the list of module currently installed. The key value is the dirname |
||||||
| 219 | /** @var \XoopsModuleHandler $moduleHandler */ |
||||||
| 220 | $moduleHandler = xoops_getHandler('module'); |
||||||
| 221 | $modules_array = $moduleHandler->getList(null, true); |
||||||
| 222 | $modulelink_select_array = ['url' => _AM_SF_SPECIFIC_URL_SELECT]; |
||||||
| 223 | $modulelink_select_array = array_merge($modules_array, $modulelink_select_array); |
||||||
| 224 | $modulelink_select_array = array_merge(['None' => _AM_SF_NONE, 'All' => _AM_SF_ALL], $modulelink_select_array); |
||||||
| 225 | |||||||
| 226 | $modulelink_select = new \XoopsFormSelect('', 'modulelink', $faqObj->modulelink()); |
||||||
| 227 | $modulelink_select->addOptionArray($modulelink_select_array); |
||||||
| 228 | $modulelink_tray = new \XoopsFormElementTray(_AM_SF_CONTEXTMODULELINK_FAQ, ' '); |
||||||
| 229 | $modulelink_tray->addElement($modulelink_select); |
||||||
| 230 | $sform->addElement($modulelink_tray); |
||||||
| 231 | |||||||
| 232 | // SPECIFICURL |
||||||
| 233 | $sform->addElement(new \XoopsFormText(_AM_SF_SPECIFIC_URL, 'contextpage', 50, 60, $faqObj->contextpage()), false); |
||||||
| 234 | |||||||
| 235 | // EXACT URL? |
||||||
| 236 | $excaturl_radio = new \XoopsFormRadioYN(_AM_SF_EXACTURL, 'exacturl', $faqObj->exacturl(), ' ' . _AM_SF_YES . '', ' ' . _AM_SF_NO . ''); |
||||||
| 237 | $sform->addElement($excaturl_radio); |
||||||
| 238 | // WEIGHT |
||||||
| 239 | $sform->addElement(new \XoopsFormText(_AM_SF_WEIGHT, 'weight', 5, 5, $faqObj->weight()), true); |
||||||
| 240 | |||||||
| 241 | // COMMENTS |
||||||
| 242 | // Code to allow comments |
||||||
| 243 | $addcomments_radio = new \XoopsFormRadioYN(_AM_SF_ALLOWCOMMENTS, 'cancomment', $faqObj->cancomment(), ' ' . _AM_SF_YES . '', ' ' . _AM_SF_NO . ''); |
||||||
| 244 | $sform->addElement($addcomments_radio); |
||||||
| 245 | |||||||
| 246 | // PER ITEM PERMISSIONS |
||||||
| 247 | $memberHandler = xoops_getHandler('member'); |
||||||
| 248 | $group_list = $memberHandler->getGroupList(); |
||||||
|
0 ignored issues
–
show
The method
getGroupList() does not exist on XoopsObjectHandler. It seems like you code against a sub-type of XoopsObjectHandler such as XoopsPersistableObjectHandler.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 249 | $groups_checkbox = new \XoopsFormCheckBox(_AM_SF_PERMISSIONS_FAQ, 'groups[]', $faqObj->getGroups_read()); |
||||||
| 250 | foreach ($group_list as $group_id => $group_name) { |
||||||
| 251 | if (XOOPS_GROUP_ADMIN != $group_id) { |
||||||
| 252 | $groups_checkbox->addOption($group_id, $group_name); |
||||||
| 253 | } |
||||||
| 254 | } |
||||||
| 255 | $sform->addElement($groups_checkbox); |
||||||
| 256 | |||||||
| 257 | $partial_view = new \XoopsFormRadioYN(_AM_SF_PARTIALVIEW, 'partialview', $faqObj->partialview(), ' ' . _AM_SF_YES . '', ' ' . _AM_SF_NO . ''); |
||||||
| 258 | $sform->addElement($partial_view); |
||||||
| 259 | |||||||
| 260 | // VARIOUS OPTIONS |
||||||
| 261 | $options_tray = new \XoopsFormElementTray(_AM_SF_OPTIONS, '<br>'); |
||||||
| 262 | |||||||
| 263 | $html_checkbox = new \XoopsFormCheckBox('', 'html', $faqObj->html()); |
||||||
| 264 | $html_checkbox->addOption(1, _AM_SF_DOHTML); |
||||||
| 265 | $options_tray->addElement($html_checkbox); |
||||||
| 266 | |||||||
| 267 | $smiley_checkbox = new \XoopsFormCheckBox('', 'smiley', $faqObj->smiley()); |
||||||
| 268 | $smiley_checkbox->addOption(1, _AM_SF_DOSMILEY); |
||||||
| 269 | $options_tray->addElement($smiley_checkbox); |
||||||
| 270 | |||||||
| 271 | $xcodes_checkbox = new \XoopsFormCheckBox('', 'xcodes', $faqObj->xcodes()); |
||||||
| 272 | $xcodes_checkbox->addOption(1, _AM_SF_DOXCODE); |
||||||
| 273 | $options_tray->addElement($xcodes_checkbox); |
||||||
| 274 | |||||||
| 275 | $sform->addElement($options_tray); |
||||||
| 276 | |||||||
| 277 | // OFFLINE |
||||||
| 278 | if (Constants::SF_STATUS_OFFLINE == $faqObj->status()) { |
||||||
| 279 | // Back OnLine |
||||||
| 280 | $offline_radio = new \XoopsFormRadioYN(_AM_SF_OFFLINE_FIELD, 'offline', 1, ' ' . _AM_SF_YES . '', ' ' . _AM_SF_NO . ''); |
||||||
| 281 | $sform->addElement($offline_radio); |
||||||
| 282 | } |
||||||
| 283 | |||||||
| 284 | // faq ID |
||||||
| 285 | $sform->addElement(new \XoopsFormHidden('faqid', $faqObj->faqid())); |
||||||
| 286 | |||||||
| 287 | // requester id |
||||||
| 288 | $sform->addElement(new \XoopsFormHidden('requester_uid', $faqObj->uid())); |
||||||
| 289 | |||||||
| 290 | // answerer id |
||||||
| 291 | $sform->addElement(new \XoopsFormHidden('answerer_uid', $answerObj->uid())); |
||||||
| 292 | |||||||
| 293 | // ANSWER ID |
||||||
| 294 | $sform->addElement(new \XoopsFormHidden('answerid', $answerObj->answerid())); |
||||||
| 295 | |||||||
| 296 | $buttonTray = new \XoopsFormElementTray('', ''); |
||||||
| 297 | $hidden = new \XoopsFormHidden('op', 'addfaq'); |
||||||
| 298 | $buttonTray->addElement($hidden); |
||||||
| 299 | |||||||
| 300 | $sform->addElement(new \XoopsFormHidden('status', $faqObj->status())); |
||||||
| 301 | |||||||
| 302 | // Setting the FAQ Status |
||||||
| 303 | /* $status_select = new \XoopsFormSelect('', 'status', $status); |
||||||
| 304 | $status_select->addOptionArray(Smartfaq\Utility::getStatusArray()); |
||||||
| 305 | $status_tray = new \XoopsFormElementTray(_AM_SF_STATUS_EXP , ' '); |
||||||
| 306 | $status_tray->addElement($status_select); |
||||||
| 307 | $sform->addElement($status_tray); |
||||||
| 308 | */ |
||||||
| 309 | if (!$faqid) { |
||||||
| 310 | // there's no faqid? Then it's a new faq |
||||||
| 311 | // $buttonTray -> addElement( new \XoopsFormButton( '', 'mod', _AM_SF_CREATE, 'submit' ) ); |
||||||
| 312 | $butt_create = new \XoopsFormButton('', '', _AM_SF_CREATE, 'submit'); |
||||||
| 313 | $butt_create->setExtra('onclick="this.form.elements.op.value=\'addfaq\'"'); |
||||||
| 314 | $buttonTray->addElement($butt_create); |
||||||
| 315 | |||||||
| 316 | $butt_clear = new \XoopsFormButton('', '', _AM_SF_CLEAR, 'reset'); |
||||||
| 317 | $buttonTray->addElement($butt_clear); |
||||||
| 318 | |||||||
| 319 | $butt_cancel = new \XoopsFormButton('', '', _AM_SF_CANCEL, 'button'); |
||||||
| 320 | $butt_cancel->setExtra('onclick="history.go(-1)"'); |
||||||
| 321 | $buttonTray->addElement($butt_cancel); |
||||||
| 322 | } else { |
||||||
| 323 | // else, we're editing an existing faq |
||||||
| 324 | // $buttonTray -> addElement( new \XoopsFormButton( '', 'mod', _AM_SF_MODIFY, 'submit' ) ); |
||||||
| 325 | $butt_create = new \XoopsFormButton('', '', $button_caption, 'submit'); |
||||||
| 326 | $butt_create->setExtra('onclick="this.form.elements.op.value=\'addfaq\'"'); |
||||||
| 327 | $buttonTray->addElement($butt_create); |
||||||
| 328 | |||||||
| 329 | $butt_cancel = new \XoopsFormButton('', '', _AM_SF_CANCEL, 'button'); |
||||||
| 330 | $butt_cancel->setExtra('onclick="history.go(-1)"'); |
||||||
| 331 | $buttonTray->addElement($butt_cancel); |
||||||
| 332 | } |
||||||
| 333 | |||||||
| 334 | $sform->addElement($buttonTray); |
||||||
| 335 | $sform->display(); |
||||||
| 336 | echo '</div>'; |
||||||
| 337 | unset($hidden); |
||||||
| 338 | } |
||||||
| 339 | |||||||
| 340 | /* -- Available operations -- */ |
||||||
| 341 | switch ($op) { |
||||||
| 342 | case 'merge': |
||||||
| 343 | |||||||
| 344 | $faqid = isset($_GET['faqid']) ? $_GET['faqid'] : -1; |
||||||
| 345 | $answerid = isset($_GET['answerid']) ? $_GET['answerid'] : -1; |
||||||
| 346 | if (-1 == $faqid) { |
||||||
| 347 | $totalcategories = $categoryHandler->getCategoriesCount(-1); |
||||||
| 348 | if (0 == $totalcategories) { |
||||||
| 349 | redirect_header('category.php?op=mod', 3, _AM_SF_NEED_CATEGORY_FAQ); |
||||||
| 350 | } |
||||||
| 351 | } |
||||||
| 352 | |||||||
| 353 | xoops_cp_header(); |
||||||
| 354 | require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php'; |
||||||
| 355 | |||||||
| 356 | editfaq(true, $faqid, $answerid, true); |
||||||
| 357 | break; |
||||||
| 358 | case 'mod': |
||||||
| 359 | |||||||
| 360 | global $xoopsUser, $xoopsUser, $xoopsConfig, $xoopsDB, $xoopsModule, $modify, $myts; |
||||||
| 361 | $faqid = isset($_GET['faqid']) ? $_GET['faqid'] : -1; |
||||||
| 362 | $answerid = isset($_GET['answerid']) ? $_GET['answerid'] : -1; |
||||||
| 363 | if (-1 == $faqid) { |
||||||
| 364 | $totalcategories = $categoryHandler->getCategoriesCount(-1); |
||||||
| 365 | if (0 == $totalcategories) { |
||||||
| 366 | redirect_header('category.php?op=mod', 3, _AM_SF_NEED_CATEGORY_FAQ); |
||||||
| 367 | } |
||||||
| 368 | } |
||||||
| 369 | |||||||
| 370 | $adminObject = \Xmf\Module\Admin::getInstance(); |
||||||
| 371 | xoops_cp_header(); |
||||||
| 372 | |||||||
| 373 | $adminObject->displayNavigation(basename(__FILE__)); |
||||||
| 374 | require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php'; |
||||||
| 375 | |||||||
| 376 | editfaq(true, $faqid, $answerid); |
||||||
| 377 | break; |
||||||
| 378 | case 'addfaq': |
||||||
| 379 | global $xoopsUser; |
||||||
| 380 | |||||||
| 381 | $faqid = Request::getInt('faqid', -1, 'POST'); |
||||||
| 382 | $requesterUid = Request::getInt('requester_uid', 0, 'POST'); |
||||||
| 383 | $answererUid = Request::getInt('answerer_uid', 0, 'POST'); |
||||||
| 384 | |||||||
| 385 | // Creating the FAQ and answer objects |
||||||
| 386 | if (-1 != $faqid) { |
||||||
| 387 | $faqObj = new Smartfaq\Faq($faqid); |
||||||
| 388 | $answerObj = $faqObj->answer(); |
||||||
| 389 | // If the FAQ does not have an answer, then it's an answered opened question |
||||||
| 390 | if (!$answerObj) { |
||||||
|
0 ignored issues
–
show
|
|||||||
| 391 | echo 'error in faq.php...200412111827'; |
||||||
| 392 | } |
||||||
| 393 | } else { |
||||||
| 394 | $faqObj = $faqHandler->create(); |
||||||
| 395 | $answerObj = $answerHandler->create(); |
||||||
| 396 | } |
||||||
| 397 | |||||||
| 398 | // Putting the values in the FAQ object |
||||||
| 399 | // if (\Xmf\Request::hasVar('groups', 'POST')) { |
||||||
| 400 | // $faqObj->setGroups_read($_POST['groups']); |
||||||
| 401 | // } else { |
||||||
| 402 | // $faqObj->setGroups_read(); |
||||||
| 403 | // } |
||||||
| 404 | |||||||
| 405 | if (Request::hasVar('groups', 'POST')) { |
||||||
| 406 | $faqObj->setGroups_read(Request::getArray('groups', [], 'POST')); |
||||||
| 407 | } else { |
||||||
| 408 | $faqObj->setGroups_read(); |
||||||
| 409 | } |
||||||
| 410 | |||||||
| 411 | $faqObj->setVar('categoryid', Request::getInt('categoryid', 0, 'POST')); |
||||||
| 412 | $faqObj->setVar('question', Request::getString('question', '', 'POST')); |
||||||
| 413 | $faqObj->setVar('howdoi', Request::getString('howdoi', '', 'POST')); |
||||||
| 414 | $faqObj->setVar('diduno', Request::getString('diduno', '', 'POST')); |
||||||
| 415 | |||||||
| 416 | $faqObj->setVar('status', Request::getInt('status', Constants::SF_STATUS_ASKED, 'POST')); |
||||||
| 417 | |||||||
| 418 | // If this SmartFAQ is offline and the user set this option to No |
||||||
| 419 | $offline = Request::getInt('offline', 1, 'POST'); |
||||||
| 420 | if ((0 == $offline) && (Constants::SF_STATUS_OFFLINE == $faqObj->status())) { |
||||||
| 421 | $faqObj->setVar('status', Constants::SF_STATUS_PUBLISHED); |
||||||
| 422 | } |
||||||
| 423 | $faqObj->setVar('weight', Request::getInt('weight', $faqObj->weight(), 'POST')); |
||||||
| 424 | $faqObj->setVar('html', Request::getInt('html', 0, 'POST')); |
||||||
| 425 | $faqObj->setVar('smiley', Request::getInt('smiley', 0, 'POST')); |
||||||
| 426 | $faqObj->setVar('xcodes', Request::getInt('xcodes', 0, 'POST')); |
||||||
| 427 | $faqObj->setVar('cancomment', Request::getInt('cancomment', 0, 'POST')); |
||||||
| 428 | $faqObj->setVar('modulelink', Request::getString('modulelink', '', 'POST')); |
||||||
| 429 | $faqObj->setVar('contextpage', Request::getString('contextpage', '', 'POST')); |
||||||
| 430 | $faqObj->setVar('exacturl', Request::getString('exacturl', '', 'POST')); |
||||||
| 431 | $faqObj->setVar('partialview', Request::getInt('partialview', 0, 'POST')); |
||||||
| 432 | $faqObj->setVar('uid', $requesterUid); |
||||||
| 433 | |||||||
| 434 | switch ($faqObj->status()) { |
||||||
| 435 | case Constants::SF_STATUS_ASKED: |
||||||
| 436 | $redirect_msg = _AM_SF_ASKED_APPROVE_SUCCESS; |
||||||
| 437 | $error_msg = _AM_SF_ARTNOTUPDATED; |
||||||
| 438 | // Setting the new status |
||||||
| 439 | $status = Constants::SF_STATUS_PUBLISHED; |
||||||
| 440 | $an_status = Constants::SF_AN_STATUS_APPROVED; |
||||||
| 441 | $notifToDo = [Constants::SF_NOT_FAQ_PUBLISHED]; |
||||||
| 442 | break; |
||||||
| 443 | case Constants::SF_STATUS_ANSWERED: |
||||||
| 444 | $redirect_msg = _AM_SF_ANSWERED_APPROVE_SUCCESS; |
||||||
| 445 | $error_msg = _AM_SF_ARTNOTUPDATED; |
||||||
| 446 | // Setting the new status |
||||||
| 447 | $status = Constants::SF_STATUS_PUBLISHED; |
||||||
| 448 | $an_status = Constants::SF_AN_STATUS_APPROVED; |
||||||
| 449 | $notifToDo = [Constants::SF_NOT_FAQ_PUBLISHED]; |
||||||
| 450 | break; |
||||||
| 451 | case Constants::SF_STATUS_SUBMITTED: |
||||||
| 452 | $redirect_msg = _AM_SF_SUBMITTED_APPROVE_SUCCESS; |
||||||
| 453 | $error_msg = _AM_SF_ARTNOTUPDATED; |
||||||
| 454 | // Setting the new status |
||||||
| 455 | $status = Constants::SF_STATUS_PUBLISHED; |
||||||
| 456 | $an_status = Constants::SF_AN_STATUS_APPROVED; |
||||||
| 457 | $notifToDo = [Constants::SF_NOT_FAQ_PUBLISHED]; |
||||||
| 458 | break; |
||||||
| 459 | case Constants::SF_STATUS_PUBLISHED: |
||||||
| 460 | $redirect_msg = _AM_SF_PUBLISHED_MOD_SUCCESS; |
||||||
| 461 | $error_msg = _AM_SF_ARTNOTUPDATED; |
||||||
| 462 | // Setting the new status |
||||||
| 463 | $status = Constants::SF_STATUS_PUBLISHED; |
||||||
| 464 | $an_status = Constants::SF_AN_STATUS_APPROVED; |
||||||
| 465 | break; |
||||||
| 466 | case Constants::SF_STATUS_OPENED: |
||||||
| 467 | $redirect_msg = _AM_SF_OPENED_ANSWERING_SUCCESS; |
||||||
| 468 | $error_msg = _AM_SF_ARTNOTUPDATED; |
||||||
| 469 | // Setting the new status |
||||||
| 470 | $status = Constants::SF_STATUS_PUBLISHED; |
||||||
| 471 | $an_status = Constants::SF_AN_STATUS_APPROVED; |
||||||
| 472 | $notifToDo = [Constants::SF_NOT_FAQ_PUBLISHED]; |
||||||
| 473 | break; |
||||||
| 474 | case Constants::SF_STATUS_NEW_ANSWER: |
||||||
| 475 | $redirect_msg = _AM_SF_FAQ_NEW_ANSWER_PUBLISHED; |
||||||
| 476 | $error_msg = _AM_SF_ARTNOTUPDATED; |
||||||
| 477 | // Setting the new status |
||||||
| 478 | $status = Constants::SF_STATUS_PUBLISHED; |
||||||
| 479 | $an_status = Constants::SF_AN_STATUS_APPROVED; |
||||||
| 480 | //$notifToDo = array(Constants::SF_NOT_FAQ_PUBLISHED); |
||||||
| 481 | break; |
||||||
| 482 | case Constants::SF_STATUS_OFFLINE: |
||||||
| 483 | break; |
||||||
| 484 | case 'default': |
||||||
| 485 | default: |
||||||
| 486 | $redirect_msg = _AM_SF_SUBMITTED_APPROVE_SUCCESS; |
||||||
| 487 | $error_msg = _AM_SF_ARTNOTCREATED; |
||||||
| 488 | // Setting the new status |
||||||
| 489 | $status = Constants::SF_STATUS_PUBLISHED; |
||||||
| 490 | $an_status = Constants::SF_AN_STATUS_APPROVED; |
||||||
| 491 | $notifToDo = [Constants::SF_NOT_FAQ_PUBLISHED]; |
||||||
| 492 | break; |
||||||
| 493 | } |
||||||
| 494 | $faqObj->setVar('status', $status); |
||||||
| 495 | |||||||
| 496 | // Puting the info in the answer object |
||||||
| 497 | $answerObj->setVar('answer', $_POST['answer']); |
||||||
| 498 | $answerObj->setVar('status', $an_status); |
||||||
| 499 | $answerObj->setVar('uid', $answererUid); |
||||||
| 500 | |||||||
| 501 | // Storing the FAQ |
||||||
| 502 | if (!$faqObj->store()) { |
||||||
| 503 | redirect_header('<script>javascript:history.go(-1)</script>', 3, $error_msg . Smartfaq\Utility::formatErrors($faqObj->getErrors())); |
||||||
| 504 | } |
||||||
| 505 | |||||||
| 506 | // Storing the answer |
||||||
| 507 | $answerObj->setVar('faqid', $faqObj->faqid()); |
||||||
| 508 | if (!$answerObj->store()) { |
||||||
| 509 | redirect_header('<script>javascript:history.go(-1)</script>', 3, $error_msg . Smartfaq\Utility::formatErrors($answerObj->getErrors())); |
||||||
| 510 | } |
||||||
| 511 | |||||||
| 512 | // Send notifications |
||||||
| 513 | if (!empty($notifToDo)) { |
||||||
| 514 | $faqObj->sendNotifications($notifToDo); |
||||||
| 515 | } |
||||||
| 516 | |||||||
| 517 | redirect_header('faq.php', 2, $redirect_msg); |
||||||
| 518 | break; |
||||||
| 519 | case 'del': |
||||||
| 520 | global $xoopsUser, $xoopsUser, $xoopsConfig, $xoopsDB, $_GET; |
||||||
| 521 | |||||||
| 522 | $module_id = $xoopsModule->getVar('mid'); |
||||||
| 523 | $grouppermHandler = xoops_getHandler('groupperm'); |
||||||
| 524 | |||||||
| 525 | $faqid = Request::getInt('faqid', 0, 'POST'); |
||||||
| 526 | $faqid = Request::getInt('faqid', $faqid, 'GET'); |
||||||
| 527 | |||||||
| 528 | $faqObj = new Smartfaq\Faq($faqid); |
||||||
| 529 | |||||||
| 530 | $confirm = Request::getInt('confirm', 0, 'POST'); |
||||||
| 531 | $question = Request::getString('question', '', 'POST'); |
||||||
| 532 | |||||||
| 533 | if ($confirm) { |
||||||
| 534 | if (!$faqHandler->delete($faqObj)) { |
||||||
| 535 | redirect_header('faq.php', 2, _AM_SF_FAQ_DELETE_ERROR . Smartfaq\Utility::formatErrors($faqObj->getErrors())); |
||||||
| 536 | } |
||||||
| 537 | |||||||
| 538 | redirect_header('faq.php', 2, sprintf(_AM_SF_ARTISDELETED, $faqObj->question())); |
||||||
| 539 | } else { |
||||||
| 540 | // no confirm: show deletion condition |
||||||
| 541 | $faqid = Request::getInt('faqid', 0, 'POST'); |
||||||
| 542 | xoops_cp_header(); |
||||||
| 543 | xoops_confirm([ |
||||||
| 544 | 'op' => 'del', |
||||||
| 545 | 'faqid' => $faqObj->faqid(), |
||||||
| 546 | 'confirm' => 1, |
||||||
| 547 | 'name' => $faqObj->question(), |
||||||
| 548 | ], 'faq.php', _AM_SF_DELETETHISARTICLE . " <br>'" . $faqObj->question() . "'. <br> <br>", _AM_SF_DELETE); |
||||||
| 549 | xoops_cp_footer(); |
||||||
| 550 | } |
||||||
| 551 | |||||||
| 552 | exit(); |
||||||
| 553 | break; |
||||||
| 554 | case 'default': |
||||||
| 555 | default: |
||||||
| 556 | $adminObject = \Xmf\Module\Admin::getInstance(); |
||||||
| 557 | xoops_cp_header(); |
||||||
| 558 | |||||||
| 559 | $adminObject->displayNavigation(basename(__FILE__)); |
||||||
| 560 | |||||||
| 561 | require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php'; |
||||||
| 562 | require_once XOOPS_ROOT_PATH . '/class/pagenav.php'; |
||||||
| 563 | |||||||
| 564 | require_once XOOPS_ROOT_PATH . '/modules/smartfaq/include/displayfaqs.php'; |
||||||
| 565 | |||||||
| 566 | $totalcategories = $categoryHandler->getCategoriesCount(-1); |
||||||
| 567 | if ($totalcategories > 0) { |
||||||
| 568 | editfaq(); |
||||||
| 569 | } |
||||||
| 570 | |||||||
| 571 | break; |
||||||
| 572 | } |
||||||
| 573 | |||||||
| 574 | require_once __DIR__ . '/admin_footer.php'; |
||||||
| 575 |