Passed
Push — master ( 4e30dc...deff52 )
by Michael
02:16
created
submit.php 1 patch
Switch Indentation   +134 added lines, -134 removed lines patch added patch discarded remove patch
@@ -52,153 +52,153 @@  discard block
 block discarded – undo
52 52
 }
53 53
 
54 54
 switch ($op) {
55
-    case 'preview':
55
+        case 'preview':
56 56
 
57
-        global $xoopsUser, $xoopsConfig, $xoopsModule, $xoopsModuleConfig, $xoopsDB;
57
+            global $xoopsUser, $xoopsConfig, $xoopsModule, $xoopsModuleConfig, $xoopsDB;
58 58
 
59
-        $faqObj      = $faqHandler->create();
60
-        $answerObj   = $answerHandler->create();
61
-        $categoryObj = $categoryHandler->get($_POST['categoryid']);
59
+            $faqObj      = $faqHandler->create();
60
+            $answerObj   = $answerHandler->create();
61
+            $categoryObj = $categoryHandler->get($_POST['categoryid']);
62 62
 
63
-        if (!$xoopsUser) {
64
-            if (1 == $xoopsModuleConfig['anonpost']) {
65
-                $uid = 0;
63
+            if (!$xoopsUser) {
64
+                if (1 == $xoopsModuleConfig['anonpost']) {
65
+                    $uid = 0;
66
+                } else {
67
+                    redirect_header('index.php', 3, _NOPERM);
68
+                }
66 69
             } else {
67
-                redirect_header('index.php', 3, _NOPERM);
70
+                $uid = $xoopsUser->uid();
68 71
             }
69
-        } else {
70
-            $uid = $xoopsUser->uid();
71
-        }
72 72
 
73
-        $notifypub = isset($_POST['notifypub']) ? $_POST['notifypub'] : 0;
73
+            $notifypub = isset($_POST['notifypub']) ? $_POST['notifypub'] : 0;
74 74
 
75
-        // Putting the values about the FAQ in the FAQ object
76
-        $faqObj->setVar('categoryid', $_POST['categoryid']);
77
-        $faqObj->setVar('uid', $uid);
78
-        $faqObj->setVar('question', $_POST['question']);
79
-        $faqObj->setVar('howdoi', $_POST['howdoi']);
80
-        $faqObj->setVar('diduno', $_POST['diduno']);
81
-        $faqObj->setVar('datesub', time());
75
+            // Putting the values about the FAQ in the FAQ object
76
+            $faqObj->setVar('categoryid', $_POST['categoryid']);
77
+            $faqObj->setVar('uid', $uid);
78
+            $faqObj->setVar('question', $_POST['question']);
79
+            $faqObj->setVar('howdoi', $_POST['howdoi']);
80
+            $faqObj->setVar('diduno', $_POST['diduno']);
81
+            $faqObj->setVar('datesub', time());
82 82
 
83
-        // Putting the values in the answer object
84
-        $answerObj->setVar('status', Constants::SF_AN_STATUS_APPROVED);
85
-        $answerObj->setVar('faqid', $faqObj->faqid());
86
-        $answerObj->setVar('answer', $_POST['answer']);
87
-        $answerObj->setVar('uid', $uid);
83
+            // Putting the values in the answer object
84
+            $answerObj->setVar('status', Constants::SF_AN_STATUS_APPROVED);
85
+            $answerObj->setVar('faqid', $faqObj->faqid());
86
+            $answerObj->setVar('answer', $_POST['answer']);
87
+            $answerObj->setVar('uid', $uid);
88 88
 
89
-        global $xoopsUser, $myts;
89
+            global $xoopsUser, $myts;
90 90
 
91
-        $GLOBALS['xoopsOption']['template_main'] = 'smartfaq_submit.tpl';
92
-        require_once XOOPS_ROOT_PATH . '/header.php';
93
-        require_once __DIR__ . '/footer.php';
91
+            $GLOBALS['xoopsOption']['template_main'] = 'smartfaq_submit.tpl';
92
+            require_once XOOPS_ROOT_PATH . '/header.php';
93
+            require_once __DIR__ . '/footer.php';
94 94
 
95
-        $name = $xoopsUser ? ucwords($xoopsUser->getVar('uname')) : 'Anonymous';
95
+            $name = $xoopsUser ? ucwords($xoopsUser->getVar('uname')) : 'Anonymous';
96 96
 
97
-        $moduleName          =& $myts->displayTarea($xoopsModule->getVar('name'));
98
-        $faq                 = $faqObj->toArray(null, $categoryObj, false);
99
-        $faq['categoryPath'] = $categoryObj->getCategoryPath(true);
100
-        $faq['answer']       = $answerObj->answer();
101
-        $faq['who_when']     = $faqObj->getWhoAndWhen();
97
+            $moduleName          =& $myts->displayTarea($xoopsModule->getVar('name'));
98
+            $faq                 = $faqObj->toArray(null, $categoryObj, false);
99
+            $faq['categoryPath'] = $categoryObj->getCategoryPath(true);
100
+            $faq['answer']       = $answerObj->answer();
101
+            $faq['who_when']     = $faqObj->getWhoAndWhen();
102 102
 
103
-        $faq['comments'] = -1;
104
-        $xoopsTpl->assign('faq', $faq);
105
-        $xoopsTpl->assign('op', 'preview');
106
-        $xoopsTpl->assign('whereInSection', $moduleName);
107
-        $xoopsTpl->assign('lang_submit', _MD_SF_SUB_SNEWNAME);
103
+            $faq['comments'] = -1;
104
+            $xoopsTpl->assign('faq', $faq);
105
+            $xoopsTpl->assign('op', 'preview');
106
+            $xoopsTpl->assign('whereInSection', $moduleName);
107
+            $xoopsTpl->assign('lang_submit', _MD_SF_SUB_SNEWNAME);
108 108
 
109
-        $xoopsTpl->assign('lang_intro_title', sprintf(_MD_SF_SUB_SNEWNAME, ucwords($xoopsModule->name())));
110
-        $xoopsTpl->assign('lang_intro_text', _MD_SF_GOODDAY . "<b>$name</b>, " . _MD_SF_SUB_INTRO);
109
+            $xoopsTpl->assign('lang_intro_title', sprintf(_MD_SF_SUB_SNEWNAME, ucwords($xoopsModule->name())));
110
+            $xoopsTpl->assign('lang_intro_text', _MD_SF_GOODDAY . "<b>$name</b>, " . _MD_SF_SUB_INTRO);
111 111
 
112
-        require_once __DIR__ . '/include/submit.inc.php';
112
+            require_once __DIR__ . '/include/submit.inc.php';
113 113
 
114
-        require_once XOOPS_ROOT_PATH . '/footer.php';
114
+            require_once XOOPS_ROOT_PATH . '/footer.php';
115 115
 
116
-        exit();
117
-        break;
116
+            exit();
117
+            break;
118 118
 
119
-    case 'post':
119
+        case 'post':
120 120
 
121
-        global $xoopsUser, $xoopsConfig, $xoopsModule, $xoopsModuleConfig, $xoopsDB;
121
+            global $xoopsUser, $xoopsConfig, $xoopsModule, $xoopsModuleConfig, $xoopsDB;
122 122
 
123
-        $newFaqObj    = $faqHandler->create();
124
-        $newAnswerObj = $answerHandler->create();
123
+            $newFaqObj    = $faqHandler->create();
124
+            $newAnswerObj = $answerHandler->create();
125 125
 
126
-        if (!$xoopsUser) {
127
-            if (1 == $xoopsModuleConfig['anonpost']) {
128
-                $uid = 0;
126
+            if (!$xoopsUser) {
127
+                if (1 == $xoopsModuleConfig['anonpost']) {
128
+                    $uid = 0;
129
+                } else {
130
+                    redirect_header('index.php', 3, _NOPERM);
131
+                }
129 132
             } else {
130
-                redirect_header('index.php', 3, _NOPERM);
133
+                $uid = $xoopsUser->uid();
131 134
             }
132
-        } else {
133
-            $uid = $xoopsUser->uid();
134
-        }
135
-
136
-        $notifypub = isset($_POST['notifypub']) ? $_POST['notifypub'] : 0;
137
-
138
-        // Putting the values about the FAQ in the FAQ object
139
-        $newFaqObj->setVar('categoryid', $_POST['categoryid']);
140
-        $newFaqObj->setVar('uid', $uid);
141
-        $newFaqObj->setVar('question', $_POST['question']);
142
-        $newFaqObj->setVar('howdoi', $_POST['howdoi']);
143
-        $newFaqObj->setVar('diduno', $_POST['diduno']);
144
-        $newFaqObj->setVar('notifypub', $notifypub);
145
-        //$newFaqObj->setVar('modulelink', $_POST['modulelink']);
146
-        //$newFaqObj->setVar('contextpage', $_POST['contextpage']);
147 135
 
148
-        // Setting the status of the FAQ
149
-
150
-        // if user is admin, FAQ are automatically published
151
-        $isAdmin = Smartfaq\Utility::userIsAdmin();
152
-        if ($isAdmin) {
153
-            $newFaqObj->setVar('status', Constants::SF_STATUS_PUBLISHED);
154
-        } elseif (1 == $xoopsModuleConfig['autoapprove_submitted_faq']) {
155
-            $newFaqObj->setVar('status', Constants::SF_STATUS_PUBLISHED);
156
-        } else {
157
-            $newFaqObj->setVar('status', Constants::SF_STATUS_SUBMITTED);
158
-        }
136
+            $notifypub = isset($_POST['notifypub']) ? $_POST['notifypub'] : 0;
137
+
138
+            // Putting the values about the FAQ in the FAQ object
139
+            $newFaqObj->setVar('categoryid', $_POST['categoryid']);
140
+            $newFaqObj->setVar('uid', $uid);
141
+            $newFaqObj->setVar('question', $_POST['question']);
142
+            $newFaqObj->setVar('howdoi', $_POST['howdoi']);
143
+            $newFaqObj->setVar('diduno', $_POST['diduno']);
144
+            $newFaqObj->setVar('notifypub', $notifypub);
145
+            //$newFaqObj->setVar('modulelink', $_POST['modulelink']);
146
+            //$newFaqObj->setVar('contextpage', $_POST['contextpage']);
147
+
148
+            // Setting the status of the FAQ
149
+
150
+            // if user is admin, FAQ are automatically published
151
+            $isAdmin = Smartfaq\Utility::userIsAdmin();
152
+            if ($isAdmin) {
153
+                $newFaqObj->setVar('status', Constants::SF_STATUS_PUBLISHED);
154
+            } elseif (1 == $xoopsModuleConfig['autoapprove_submitted_faq']) {
155
+                $newFaqObj->setVar('status', Constants::SF_STATUS_PUBLISHED);
156
+            } else {
157
+                $newFaqObj->setVar('status', Constants::SF_STATUS_SUBMITTED);
158
+            }
159 159
 
160
-        // Storing the FAQ object in the database
161
-        if (!$newFaqObj->store()) {
162
-            redirect_header('javascript:history.go(-1)', 2, _MD_SF_SUBMIT_ERROR);
163
-        }
160
+            // Storing the FAQ object in the database
161
+            if (!$newFaqObj->store()) {
162
+                redirect_header('javascript:history.go(-1)', 2, _MD_SF_SUBMIT_ERROR);
163
+            }
164 164
 
165
-        // Putting the values in the answer object
166
-        $newAnswerObj->setVar('status', Constants::SF_AN_STATUS_APPROVED);
167
-        $newAnswerObj->setVar('faqid', $newFaqObj->faqid());
168
-        $newAnswerObj->setVar('answer', $_POST['answer']);
169
-        $newAnswerObj->setVar('uid', $uid);
170
-
171
-        //====================================================================================
172
-        //TODO post Attachment
173
-        $attachments_tmp = [];
174
-        if (!empty($_POST['attachments_tmp'])) {
175
-            $attachments_tmp = unserialize(base64_decode($_POST['attachments_tmp']));
176
-            if (isset($_POST['delete_tmp']) && count($_POST['delete_tmp'])) {
177
-                foreach ($_POST['delete_tmp'] as $key) {
178
-                    unlink(XOOPS_ROOT_PATH . '/' . $xoopsModuleConfig['dir_attachments'] . '/' . $attachments_tmp[$key][0]);
179
-                    unset($attachments_tmp[$key]);
165
+            // Putting the values in the answer object
166
+            $newAnswerObj->setVar('status', Constants::SF_AN_STATUS_APPROVED);
167
+            $newAnswerObj->setVar('faqid', $newFaqObj->faqid());
168
+            $newAnswerObj->setVar('answer', $_POST['answer']);
169
+            $newAnswerObj->setVar('uid', $uid);
170
+
171
+            //====================================================================================
172
+            //TODO post Attachment
173
+            $attachments_tmp = [];
174
+            if (!empty($_POST['attachments_tmp'])) {
175
+                $attachments_tmp = unserialize(base64_decode($_POST['attachments_tmp']));
176
+                if (isset($_POST['delete_tmp']) && count($_POST['delete_tmp'])) {
177
+                    foreach ($_POST['delete_tmp'] as $key) {
178
+                        unlink(XOOPS_ROOT_PATH . '/' . $xoopsModuleConfig['dir_attachments'] . '/' . $attachments_tmp[$key][0]);
179
+                        unset($attachments_tmp[$key]);
180
+                    }
180 181
                 }
181 182
             }
182
-        }
183
-        if (count($attachments_tmp)) {
184
-            foreach ($attachments_tmp as $key => $attach) {
185
-                if (rename(XOOPS_CACHE_PATH . '/' . $attachments_tmp[$key][0], XOOPS_ROOT_PATH . '/' . $xoopsModuleConfig['dir_attachments'] . '/' . $attachments_tmp[$key][0])) {
186
-                    $post_obj->setAttachment($attach[0], $attach[1], $attach[2]);
183
+            if (count($attachments_tmp)) {
184
+                foreach ($attachments_tmp as $key => $attach) {
185
+                    if (rename(XOOPS_CACHE_PATH . '/' . $attachments_tmp[$key][0], XOOPS_ROOT_PATH . '/' . $xoopsModuleConfig['dir_attachments'] . '/' . $attachments_tmp[$key][0])) {
186
+                        $post_obj->setAttachment($attach[0], $attach[1], $attach[2]);
187
+                    }
187 188
                 }
188 189
             }
189
-        }
190
-        $error_upload = '';
190
+            $error_upload = '';
191 191
 
192
-        if (isset($_FILES['userfile']['name']) && '' != $_FILES['userfile']['name']
193
-            && $topicHandler->getPermission($forum_obj, $topic_status, 'attach')) {
194
-            require_once XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname', 'n') . '/class/uploader.php';
195
-            $maxfilesize = $forum_obj->getVar('attach_maxkb') * 1024;
196
-            $uploaddir   = XOOPS_CACHE_PATH;
192
+            if (isset($_FILES['userfile']['name']) && '' != $_FILES['userfile']['name']
193
+                && $topicHandler->getPermission($forum_obj, $topic_status, 'attach')) {
194
+                require_once XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname', 'n') . '/class/uploader.php';
195
+                $maxfilesize = $forum_obj->getVar('attach_maxkb') * 1024;
196
+                $uploaddir   = XOOPS_CACHE_PATH;
197 197
 
198
-            $uploader = new Smartfaq\Uploader($uploaddir, $newAnswerObj->getVar('attach_ext'), (int)$maxfilesize, (int)$xoopsModuleConfig['max_img_width'], (int)$xoopsModuleConfig['max_img_height']);
198
+                $uploader = new Smartfaq\Uploader($uploaddir, $newAnswerObj->getVar('attach_ext'), (int)$maxfilesize, (int)$xoopsModuleConfig['max_img_width'], (int)$xoopsModuleConfig['max_img_height']);
199 199
 
200
-            if ($_FILES['userfile']['error'] > 0) {
201
-                switch ($_FILES['userfile']['error']) {
200
+                if ($_FILES['userfile']['error'] > 0) {
201
+                    switch ($_FILES['userfile']['error']) {
202 202
                     case 1:
203 203
                         $error_message[] = _MD_NEWBB_MAXUPLOADFILEINI;
204 204
                         break;
@@ -208,7 +208,7 @@  discard block
 block discarded – undo
208 208
                     default:
209 209
                         $error_message[] = _MD_NEWBB_UPLOAD_ERRNODEF;
210 210
                         break;
211
-                }
211
+                    }
212 212
             } else {
213 213
                 $uploader->setCheckMediaTypeByExt();
214 214
 
@@ -271,30 +271,30 @@  discard block
 block discarded – undo
271 271
         redirect_header('index.php', 2, $redirect_msg);
272 272
         break;
273 273
 
274
-    case 'form':
275
-    default:
274
+        case 'form':
275
+        default:
276 276
 
277
-        global $xoopsUser, $myts;
277
+            global $xoopsUser, $myts;
278 278
 
279
-        $faqObj      = $faqHandler->create();
280
-        $answerObj   = $answerHandler->create();
281
-        $categoryObj = $categoryHandler->create();
279
+            $faqObj      = $faqHandler->create();
280
+            $answerObj   = $answerHandler->create();
281
+            $categoryObj = $categoryHandler->create();
282 282
 
283
-        $GLOBALS['xoopsOption']['template_main'] = 'smartfaq_submit.tpl';
284
-        require_once XOOPS_ROOT_PATH . '/header.php';
285
-        require_once __DIR__ . '/footer.php';
283
+            $GLOBALS['xoopsOption']['template_main'] = 'smartfaq_submit.tpl';
284
+            require_once XOOPS_ROOT_PATH . '/header.php';
285
+            require_once __DIR__ . '/footer.php';
286 286
 
287
-        $name       = $xoopsUser ? ucwords($xoopsUser->getVar('uname')) : 'Anonymous';
288
-        $notifypub  = 1;
289
-        $moduleName =& $myts->displayTarea($xoopsModule->getVar('name'));
290
-        $xoopsTpl->assign('whereInSection', $moduleName);
291
-        $xoopsTpl->assign('lang_submit', _MD_SF_SUB_SNEWNAME);
287
+            $name       = $xoopsUser ? ucwords($xoopsUser->getVar('uname')) : 'Anonymous';
288
+            $notifypub  = 1;
289
+            $moduleName =& $myts->displayTarea($xoopsModule->getVar('name'));
290
+            $xoopsTpl->assign('whereInSection', $moduleName);
291
+            $xoopsTpl->assign('lang_submit', _MD_SF_SUB_SNEWNAME);
292 292
 
293
-        $xoopsTpl->assign('lang_intro_title', sprintf(_MD_SF_SUB_SNEWNAME, ucwords($xoopsModule->name())));
294
-        $xoopsTpl->assign('lang_intro_text', _MD_SF_GOODDAY . "<b>$name</b>, " . _MD_SF_SUB_INTRO);
293
+            $xoopsTpl->assign('lang_intro_title', sprintf(_MD_SF_SUB_SNEWNAME, ucwords($xoopsModule->name())));
294
+            $xoopsTpl->assign('lang_intro_text', _MD_SF_GOODDAY . "<b>$name</b>, " . _MD_SF_SUB_INTRO);
295 295
 
296
-        require_once __DIR__ . '/include/submit.inc.php';
296
+            require_once __DIR__ . '/include/submit.inc.php';
297 297
 
298
-        require_once XOOPS_ROOT_PATH . '/footer.php';
299
-        break;
298
+            require_once XOOPS_ROOT_PATH . '/footer.php';
299
+            break;
300 300
 }
Please login to merge, or discard this patch.