Passed
Push — master ( 81ba93...c6c854 )
by Michael
03:30
created

include/submit.inc.php (2 issues)

Labels
Severity
1
<?php
2
3
/**
4
 * Module: SmartFAQ
5
 * Author: The SmartFactory <www.smartfactory.ca>
6
 * Licence: GNU
7
 */
8
9
use XoopsModules\Smartfaq;
10
11
// defined('XOOPS_ROOT_PATH') || die('Restricted access');
12
13
global $_POST, $xoopsDB;
14
15
require_once XOOPS_ROOT_PATH . '/class/xoopstree.php';
16
require_once XOOPS_ROOT_PATH . '/class/xoopslists.php';
17
require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
18
//require_once __DIR__ . '/functions.php';
19
20
/** @var Smartfaq\Helper $helper */
21
$helper = Smartfaq\Helper::getInstance();
22
23
$mytree = new Smartfaq\Tree($xoopsDB->prefix('smartfaq_categories'), 'categoryid', 'parentid');
24
$form   = new \XoopsThemeForm(_MD_SF_SUB_SMNAME, 'form', xoops_getenv('PHP_SELF'), 'post', true);
25
26
// Category
27
ob_start();
28
$form->addElement(new \XoopsFormHidden('categoryid', ''));
29
$mytree->makeMySelBox('name', 'weight', $categoryObj->categoryid());
30
$category_label = new \XoopsFormLabel(_MD_SF_CATEGORY_FAQ, ob_get_contents());
31
$category_label->setDescription(_MD_SF_CATEGORY_FAQ_DSC);
32
$form->addElement($category_label);
33
ob_end_clean();
34
35
// FAQ QUESTION
36
$form->addElement(new \XoopsFormTextArea(_MD_SF_QUESTION, 'question', $faqObj->question(), 7, 60), true);
37
38
// ANSWER
39
//$answer_text = new \XoopsFormDhtmlTextArea(_MD_SF_ANSWER_FAQ, 'answer', $answerObj->answer(), 15, 60);
40
//$answer_text->setDescription(_MD_SF_ANSWER_FAQ_DSC);
41
//$form->addElement($answer_text, true);
42
43
$userIsAdmin = Smartfaq\Utility::userIsAdmin();
44
if ($userIsAdmin) {
45
    $tempEditor = $helper->getConfig('form_editorOptions');
46
} else {
47
    $tempEditor = $helper->getConfig('form_editorOptionsUser');
48
}
49
50
$editorTray = new \XoopsFormElementTray(_MD_SF_ANSWER_FAQ, '<br>');
51
if (class_exists('XoopsFormEditor')) {
52
    $options['name']   = 'answer';
53
    $options['value']  = $answerObj->answer();
54
    $options['rows']   = 5;
55
    $options['cols']   = '100%';
56
    $options['width']  = '100%';
57
    $options['height'] = '200px';
58
    $answerEditor      = new \XoopsFormEditor('', $tempEditor, $options, $nohtml = false, $onfailure = 'textarea');
59
    $editorTray->addElement($answerEditor);
60
} else {
61
    $answerEditor = new \XoopsFormDhtmlTextArea('', 'answer', $faqObj->question(), '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 ignore-type  annotation

61
    $answerEditor = new \XoopsFormDhtmlTextArea('', 'answer', $faqObj->question(), '100%', /** @scrutinizer ignore-type */ '100%');
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 ignore-type  annotation

61
    $answerEditor = new \XoopsFormDhtmlTextArea('', 'answer', $faqObj->question(), /** @scrutinizer ignore-type */ '100%', '100%');
Loading history...
62
    $answerEditor->setDescription(_MD_SF_ANSWER_FAQ_DSC);
63
    $editorTray->addElement($answerEditor);
64
}
65
66
$form->addElement($editorTray);
67
68
// HOW DO I
69
$howdoi_text = new \XoopsFormText(_MD_SF_HOWDOI_FAQ, 'howdoi', 50, 255, $faqObj->howdoi());
70
$howdoi_text->setDescription(_MD_SF_HOWDOI_FAQ_DSC);
71
$form->addElement($howdoi_text, false);
72
73
// DIDUNO
74
$diduno_text = new \XoopsFormTextArea(_MD_SF_DIDUNO_FAQ, 'diduno', $faqObj->diduno(), 3, 60);
75
$diduno_text->setDescription(_MD_SF_DIDUNO_FAQ_DSC);
76
$form->addElement($diduno_text);
77
78
//**************************************************
79
80
//if ($topicHandler->getPermission($forum_obj, $topic_status, 'attach')) {
81
$upload_tray = new \XoopsFormElementTray(_MD_SF_ATTACHMENT);
82
//    $upload_tray->addElement(new \XoopsFormFile('', 'userfile', ($forum_obj->getVar('attach_maxkb') * 1024)));
83
$upload_tray->addElement(new \XoopsFormFile('', 'userfile', $helper->getConfig('max_image_size') * 1024));
84
$upload_tray->addElement(new \XoopsFormButton('', 'contents_upload', _MD_SF_UPLOAD, 'submit'));
85
$upload_tray->addElement(new \XoopsFormLabel('<br><br>' . _MD_SF_MAX_FILESIZE . ':', $helper->getConfig('max_image_size') . 'Kb; '));
86
$extensions = trim(str_replace('|', ' ', $helper->getConfig('attach_ext')));
87
$extensions = (empty($extensions) || '*' === $extensions) ? _ALL : $extensions;
88
$upload_tray->addElement(new \XoopsFormLabel(_MD_SF_ALLOWED_EXTENSIONS . ':', $extensions));
89
$upload_tray->addElement(new \XoopsFormLabel('<br>' . sprintf(_MD_SF_MAXPIC, $helper->getConfig('max_img_height'), $helper->getConfig('max_img_width'))));
90
$form->addElement($upload_tray);
91
//}
92
93
if (!empty($attachments) && is_array($attachments) && count($attachments)) {
94
    $delete_attach_checkbox = new \XoopsFormCheckBox(_MD_SF_ATTACHED_FILES, 'delete_attach[]');
95
    foreach ($attachments as $key => $attachment) {
96
        $attach = ' ' . _DELETE . ' <a href=' . XOOPS_URL . '/' . $helper->getConfig('dir_attachments') . '/' . $attachment['name_saved'] . ' rel="external">' . $attachment['name_display'] . '</a><br>';
97
        $delete_attach_checkbox->addOption($key, $attach);
98
    }
99
    $form->addElement($delete_attach_checkbox);
100
    unset($delete_attach_checkbox);
101
}
102
103
if (!empty($attachments_tmp) && is_array($attachments_tmp) && count($attachments_tmp)) {
104
    $delete_attach_checkbox = new \XoopsFormCheckBox(_MD_REMOVE, 'delete_tmp[]');
105
    $url_prefix             = str_replace(XOOPS_ROOT_PATH, XOOPS_URL, XOOPS_CACHE_PATH);
106
    foreach ($attachments_tmp as $key => $attachment) {
107
        $attach = ' <a href="' . $url_prefix . '/' . $attachment[0] . '" rel="external">' . $attachment[1] . '</a><br>';
108
        $delete_attach_checkbox->addOption($key, $attach);
109
    }
110
    $form->addElement($delete_attach_checkbox);
111
    unset($delete_attach_checkbox);
112
    $attachments_tmp = base64_encode(serialize($attachments_tmp));
113
    $form->addElement(new \XoopsFormHidden('attachments_tmp', $attachments_tmp));
114
}
115
116
//************************************************
117
118
// CONTEXT MODULE LINK
119
// Retreive the list of module currently installed. The key value is the dirname
120
/*$moduleHandler = xoops_getHandler('module');
121
$modules_array = $moduleHandler->getList(null, true);
122
$modulelink_select_array = array("url" => _MD_SF_SPECIFIC_URL_SELECT);
123
$modulelink_select_array = array_merge($modules_array, $modulelink_select_array);
124
$modulelink_select_array = array_merge(array("None" => _MD_SF_NONE, "All" => _MD_SF_ALL), $modulelink_select_array);
125
126
$modulelink_select = new \XoopsFormSelect('', 'modulelink', '');
127
$modulelink_select->addOptionArray($modulelink_select_array);
128
$modulelink_tray = new \XoopsFormElementTray(_MD_SF_CONTEXTMODULELINK_FAQ , '&nbsp;');
129
$modulelink_tray->addElement($modulelink_select);
130
$form->addElement($modulelink_tray);
131
*/
132
// CONTEXTPAGE
133
//$form->addElement(new \XoopsFormText(_MD_SF_SPECIFIC_URL, 'contextpage', 50, 60, ''), false);
134
135
// EXACT URL?
136
/*$excaturl_radio = new \XoopsFormRadioYN(_MD_SF_EXACTURL, 'exacturl', 0, ' ' . _MD_SF_YES . '', ' ' . _MD_SF_NO . '');
137
$form->addElement($excaturl_radio);
138
*/
139
// NOTIFY ON PUBLISH
140
if (is_object($xoopsUser)) {
141
    $notify_checkbox = new \XoopsFormCheckBox('', 'notifypub', $notifypub);
142
    $notify_checkbox->addOption(1, _MD_SF_NOTIFY);
143
    $form->addElement($notify_checkbox);
144
}
145
146
$buttonTray = new \XoopsFormElementTray('', '');
147
148
$butt_create = new \XoopsFormButton('', 'post', _MD_SF_CREATE, 'submit');
149
$buttonTray->addElement($butt_create);
150
151
$butt_preview = new \XoopsFormButton('', 'preview', _MD_SF_PREVIEW, 'submit');
152
$buttonTray->addElement($butt_preview);
153
154
$form->addElement($buttonTray);
155
$form->assign($xoopsTpl);
156
157
unset($hidden, $hidden2);
158