Completed
Push — master ( c1777d...d193e2 )
by Michael
13:22
created

submit.php (5 issues)

Upgrade to new PHP Analysis Engine

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
 * Module: Lexikon - glossary module
5
 * Version: v 1.00
6
 * Release Date: 8 May 2004
7
 * Author: hsalazar
8
 * Licence: GNU
9
 */
10
11
include __DIR__ . '/header.php';
12
$GLOBALS['xoopsOption']['template_main'] = 'lx_submit.tpl';
13
include XOOPS_ROOT_PATH . '/header.php';
14
15
include_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
16
17
global $xoTheme, $xoopsUser, $xoopsConfig, $xoopsModuleConfig, $xoopsModule;
18
19
$result = $xoopsDB->query('SELECT * FROM ' . $xoopsDB->prefix('lxcategories') . '');
20 View Code Duplication
if ($xoopsDB->getRowsNum($result) == '0' && $xoopsModuleConfig['multicats'] == '1') {
0 ignored issues
show
This code seems to be duplicated across your project.

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.

Loading history...
21
    redirect_header('index.php', 1, _AM_LEXIKON_NOCOLEXISTS);
22
}
23
24
/*if ( !is_object( $xoopsUser ) && $xoopsModuleConfig['anonpost'] == 0 ) {
25
    redirect_header( "index.php", 1, _NOPERM );
26
27
}
28
if ( is_object( $xoopsUser ) && $xoopsModuleConfig['allowsubmit'] == 0 ) {
29
    redirect_header( "index.php", 1, _NOPERM );
30
31
}*/
32
33
$op = 'form';
34
35
if (isset($_POST['post'])) {
36
    $op = trim('post');
37
} elseif (isset($_POST['edit'])) {
38
    $op = trim('edit');
39
}
40
41
//$suggest = isset($_GET['suggest']) ? $_GET['suggest'] : (isset($_POST['suggest']) ? $_POST['suggest'] : '');
42
$suggest = isset($_GET['suggest']) ? (int)((int)$_GET['suggest']) : 0;
43
44
if ($suggest > 0) {
45
    $terminosql = $xoopsDB->query('SELECT term FROM ' . $xoopsDB->prefix('lxentries') . ' WHERE datesub < ' . time() . " AND datesub > 0 AND request = '1' AND entryID = '" . $suggest . "'");
46
    list($termino) = $xoopsDB->fetchRow($terminosql);
47
} else {
48
    $termino = '';
49
}
50
//--- Permissions ---
51
$gpermHandler = xoops_getHandler('groupperm');
52
$groups       = is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS;
53
$module_id    = $xoopsModule->getVar('mid');
54
$perm_itemid  = isset($_POST['categoryID']) ? (int)$_POST['categoryID'] : 0;
55
if (!$gpermHandler->checkRight('lexikon_submit', $perm_itemid, $groups, $module_id)) {
56
    redirect_header('javascript:history.go(-1)', 3, _MD_LEXIKON_MUSTREGFIRST);
57
}
58
$totalcats    = $gpermHandler->getItemIds('lexikon_submit', $groups, $module_id);
59
$permitsubmit = count($totalcats);
60
if ($permitsubmit == 0 && $xoopsModuleConfig['multicats'] == '1') {
61
    redirect_header('index.php', 3, _NOPERM);
62
}
63
switch ($op) {
64
    case 'post':
65
        //--- Captcha
66
        if ($xoopsModuleConfig['captcha'] != 0) {
67
            xoops_load('XoopsCaptcha');
68
            if (@include_once XOOPS_ROOT_PATH . '/class/captcha/xoopscaptcha.php') {
69
                $xoopsCaptcha = XoopsCaptcha::getInstance();
70
                //if (! $xoopsCaptcha->verify($_POST["skipmember"]) ) {
71
                if (!$xoopsCaptcha->verify()) {
72
                    echo $xoopsCaptcha->getMessage();
73
                    redirect_header('javascript:history.go(-1)', 2, _CAPTCHA_INVALID_CODE);
74
                }
75
                //}
76
            }
77
        }
78
        //-------
79
80
        global $xoTheme, $xoopsUser, $xoopsModule, $xoopsModuleConfig;
81
        include_once XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->getVar('dirname') . '/class/Utility.php';
82
        $myts = MyTextSanitizer:: getInstance();
83
        //permissions
84
        $gpermHandler = xoops_getHandler('groupperm');
85
        $groups       = is_object($xoopsUser) ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS;
86
        $module_id    = $xoopsModule->getVar('mid');
87
        $perm_itemid  = isset($_POST['categoryID']) ? (int)$_POST['categoryID'] : 0;
88
89
        $html = 1;
90
        if ($xoopsUser) {
91
            $uid = $xoopsUser->getVar('uid');
92
            if ($xoopsUser->isAdmin($xoopsModule->mid())) {
93
                $html = empty($html) ? 0 : 1;
94
            }
95
        } else {
96
            if (!is_object($xoopsUser)
97
                && $gpermHandler->checkRight('lexikon_submit', $perm_itemid, $groups, $module_id)
98
            ) {
99
                $uid = 0;
100
            } else {
101
                redirect_header('index.php', 3, _NOPERM);
102
            }
103
        }
104
105
        $block  = isset($block) ? (int)$block : 1;
106
        $smiley = isset($smiley) ? (int)$smiley : 1;
107
        $xcodes = isset($xcodes) ? (int)$xcodes : 1;
108
        $breaks = isset($breaks) ? (int)$breaks : 1;
109
        //$notifypub = isset( $notifypub ) ? (int)( $notifypub ) : 0;
110
        //$notifypub = (isset($_POST['notifypub'])) ? (int)($_POST['notifypub']) : '';
111
        $notifypub = !empty($_POST['notifypub']) ? 1 : 0;
112
113
        if ($xoopsModuleConfig['multicats'] == 1) {
114
            $categoryID = (int)$_POST['categoryID'];
115
        } else {
116
            $categoryID = 1;
117
        }
118
        //$term = $myts->htmlspecialchars($_POST['term']);
119
        //$init = substr($term, 0, 1);
120
        //$definition = $myts -> addSlashes( $_POST['definition'] );
121
        //$ref = $myts -> addSlashes( $_POST['ref'] );
122
        //$term = $myts->htmlSpecialChars($myts->censorString($_POST['term'] ));
123
        $term       = $myts->addSlashes($myts->censorString($_POST['term']));
124
        $definition = $myts->addSlashes($myts->censorString($_POST['definition']));
125
        $ref        = $myts->addSlashes($myts->censorString($_POST['ref']));
126
        $url        = $myts->addSlashes($_POST['url']);
127
        if (empty($url)) {
128
            $url = '';
129
        }
130
        // this is for terms with umlaut or accented initials
131
        $term4sql = LexikonUtility::sanitizeFieldName($myts->htmlspecialchars($_POST['term']));
132
        $init     = substr($term4sql, 0, 1);
133
        $init     = preg_match('/[a-zA-Z]/', $init) ? strtoupper($init) : '#';
134
135
        $datesub = time();
136
137
        $submit      = 1;
138
        $offline     = 1;
139
        $request     = 0;
140
        $block       = 1;
141
        $autoapprove = 0;
142
143
        /*if ($xoopsModuleConfig['autoapprove'] == 1) {
144
            $submit = 0;
145
            $offline = 0;
146
        }*/
147
        if ($gpermHandler->checkRight('lexikon_approve', $perm_itemid, $groups, $module_id)) {
148
            $submit      = 0;
149
            $offline     = 0;
150
            $autoapprove = 1;
151
        }
152
        // verify that the term not exists
153 View Code Duplication
        if (LexikonUtility::isTermPresent($term, $xoopsDB->prefix('lxentries'))) {
0 ignored issues
show
This code seems to be duplicated across your project.

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.

Loading history...
154
            redirect_header('javascript:history.go(-1)', 2, _MD_LEXIKON_ITEMEXISTS . '<br>' . $term);
155
        }
156
        $result = $xoopsDB->query('INSERT INTO '
157
                                  . $xoopsDB->prefix('lxentries')
158
                                  . " (entryID, categoryID, term, init, definition, ref, url, uid, submit, datesub, html, smiley, xcodes, breaks, block, offline, notifypub ) VALUES ('', '$categoryID', '$term', '$init', '$definition', '$ref', '$url', '$uid', '$submit', '$datesub', '$html', '$smiley', '$xcodes', '$breaks','$block', '$offline', '$notifypub')");
159
        $newid  = $xoopsDB->getInsertId();
160
        // Increment author's posts count
161
        //if ($xoopsModuleConfig['autoapprove'] == 1) {
162
        //if (is_object($xoopsUser) && empty($entryID)) {
163 View Code Duplication
        if (is_object($xoopsUser) && empty($entryID) && $autoapprove) {
164
            $memberHandler = xoops_getHandler('member');
165
            $submitter     = $memberHandler->getUser($uid);
166
            if (is_object($submitter)) {
167
                $submitter->setVar('posts', $submitter->getVar('posts') + 1);
168
                $res = $memberHandler->insertUser($submitter, true);
169
                unset($submitter);
170
            }
171
        }
172
        //}
173
        // trigger Notification
174
        if (!empty($xoopsModuleConfig['notification_enabled'])) {
175
            global $xoopsModule;
176
            if ($newid == 0) {
177
                $newid = $xoopsDB->getInsertId();
178
            }
179
            $notificationHandler   = xoops_getHandler('notification');
180
            $tags                  = array();
181
            $shortdefinition       = $myts->htmlSpecialChars(xoops_substr(strip_tags($definition), 0, 45));
182
            $tags['ITEM_NAME']     = $term;
183
            $tags['ITEM_BODY']     = $shortdefinition;
184
            $tags['DATESUB']       = formatTimestamp($datesub, 'd M Y');
185
            $tags['ITEM_URL']      = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/admin/entry.php?op=mod&entryID=' . $newid;
186
            $sql                   = 'SELECT name FROM ' . $xoopsDB->prefix('lxcategories') . ' WHERE categoryID=' . $categoryID;
187
            $result                = $xoopsDB->query($sql);
188
            $row                   = $xoopsDB->fetchArray($result);
189
            $tags['CATEGORY_NAME'] = $row['name'];
190
            $tags['CATEGORY_URL']  = XOOPS_URL . '/modules/' . $xoopsModule->getVar('dirname') . '/category.php?categoryID=' . $categoryID;
191
            if ($xoopsModuleConfig['autoapprove'] == 1) {
192
                $notificationHandler->triggerEvent('category', $categoryID, 'new_post', $tags);
193
                $notificationHandler->triggerEvent('global', 0, 'new_post', $tags);
194
                //sample: $notificationHandler->triggerEvent($category, $item_id, $events, $tags, $user_list=array(), $module_id=null, $omit_user_id=null)
195
            } else {
196
                $notificationHandler->triggerEvent('global', 0, 'term_submit', $tags);
197
                $notificationHandler->triggerEvent('category', 0, 'term_submit', $tags);
198
                if ($notifypub) {
199
                    include_once XOOPS_ROOT_PATH . '/include/notification_constants.php';
200
                    $notificationHandler->subscribe('term', $newid, 'approve', XOOPS_NOTIFICATION_MODE_SENDONCETHENDELETE);
201
                }
202
            }
203
        }
204
        if ($result) {
205
            if (!is_object($xoopsUser)) {
206
                $username = _MD_LEXIKON_GUEST;
207
                $usermail = '';
208 View Code Duplication
            } else {
0 ignored issues
show
This code seems to be duplicated across your project.

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.

Loading history...
209
                $username = $xoopsUser->getVar('uname', 'E');
210
                $result   = $xoopsDB->query('select email from ' . $xoopsDB->prefix('users') . " WHERE uname='$username'");
211
                list($usermail) = $xoopsDB->fetchRow($result);
212
            }
213
214
            if ($xoopsModuleConfig['mailtoadmin'] == 1) {
215
                $adminMessage = sprintf(_MD_LEXIKON_WHOSUBMITTED, $username);
216
                $adminMessage .= '<b>' . $term . "</b>\n";
217
                $adminMessage .= '' . _MD_LEXIKON_EMAILLEFT . " $usermail\n";
218
                $adminMessage .= "\n";
219
                if ($notifypub == '1') {
220
                    $adminMessage .= _MD_LEXIKON_NOTIFYONPUB;
221
                }
222
                $adminMessage .= "\n" . $_SERVER['HTTP_USER_AGENT'] . "\n";
223
                $subject      = $xoopsConfig['sitename'] . ' - ' . _MD_LEXIKON_DEFINITIONSUB;
224
                $xoopsMailer  =& xoops_getMailer();
225
                $xoopsMailer->useMail();
226
                $xoopsMailer->multimailer->isHTML(true);
227
                $xoopsMailer->setToEmails($xoopsConfig['adminmail']);
228
                $xoopsMailer->setFromEmail($usermail);
229
                $xoopsMailer->setFromName($xoopsConfig['sitename']);
230
                $xoopsMailer->setSubject($subject);
231
                $xoopsMailer->setBody($adminMessage);
232
                $xoopsMailer->send();
233
                $messagesent = sprintf(_MD_LEXIKON_MESSAGESENT, $xoopsConfig['sitename']) . '<br>' . _MD_LEXIKON_THANKS1 . '';
234
            }
235
236
            //if ($xoopsModuleConfig['autoapprove'] == 1) {
237
            if ($autoapprove == 1) {
238
                redirect_header('index.php', 2, _MD_LEXIKON_RECEIVEDANDAPPROVED);
239 View Code Duplication
            } else {
0 ignored issues
show
This code seems to be duplicated across your project.

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.

Loading history...
240
                //send received mail
241
                //if (LexikonUtility::getModuleOption('mailtosender') && $usermail) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
63% 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.

Loading history...
242
                if ($xoopsModuleConfig['mailtosender'] == 1 && $usermail) {
243
                    $conf_subject = _MD_LEXIKON_THANKS3;
244
                    $userMessage  = sprintf(_MD_LEXIKON_GOODDAY2, $username);
245
                    $userMessage  .= "\n\n";
246
                    $userMessage  .= sprintf(_MD_LEXIKON_THANKYOU3, $xoopsConfig['sitename']);
247
                    $userMessage  .= "\n";
248
                    $userMessage  .= sprintf(_MD_LEXIKON_SUBMISSIONSENT, $xoopsConfig['sitename']);
249
                    $userMessage  .= "\n";
250
                    $userMessage  .= "--------------\n";
251
                    $userMessage  .= '' . $xoopsConfig['sitename'] . ' ' . _MD_LEXIKON_WEBMASTER . "\n";
252
                    $userMessage  .= '' . $xoopsConfig['adminmail'] . '';
253
254
                    $xoopsMailer =& xoops_getMailer();
255
                    $xoopsMailer->useMail();
256
                    $xoopsMailer->multimailer->isHTML(true);
257
                    $xoopsMailer->setToEmails($usermail);
258
                    $xoopsMailer->setFromEmail($xoopsConfig['adminmail']);
259
                    $xoopsMailer->setFromName($xoopsConfig['sitename']);
260
                    $xoopsMailer->setSubject($conf_subject);
261
                    $xoopsMailer->setBody($userMessage);
262
                    $xoopsMailer->send();
263
                    $messagesent = _MD_LEXIKON_RECEIVED . '<br>' . _MD_LEXIKON_THANKS1 . '';
264
                    $messagesent .= sprintf(_MD_LEXIKON_SENTCONFIRMMAIL, $usermail);
265
                } else {
266
                    $messagesent = sprintf(_MD_LEXIKON_RECEIVED) . '<br>' . _MD_LEXIKON_THANKS1 . '';
267
                }
268
                redirect_header('index.php', 2, $messagesent);
269
            }
270
        } else {
271
            redirect_header('submit.php', 2, _MD_LEXIKON_ERRORSAVINGDB);
272
        }
273
        exit();
274
        break;
275
276
    case 'form':
277
    default:
278
        global $xoopsUser, $_SERVER;
279
        include_once XOOPS_ROOT_PATH . '/modules/' . $xoopsModule->dirname() . '/class/Utility.php';// to create pagetitle
280
        $myts = MyTextSanitizer:: getInstance();
281
        if (!is_object($xoopsUser)) {
282
            $name = _MD_LEXIKON_GUEST;
283
        } else {
284
            $name = ucfirst($xoopsUser->getVar('uname'));
285
        }
286
287
        $xoopsTpl->assign('send_def_to', sprintf(_MD_LEXIKON_SUB_SNEWNAME, ucfirst($xoopsModule->name())));
288
        $xoopsTpl->assign('send_def_g', sprintf(_MD_LEXIKON_SUB_SNEWNAME, ucfirst($xoopsModule->name())));
289
        $xoopsTpl->assign('lx_user_name', $name);
290
291
        $block      = 1;
292
        $html       = 1;
293
        $smiley     = 1;
294
        $xcodes     = 1;
295
        $breaks     = 1;
296
        $categoryID = 0;
297
        $notifypub  = 1;
298
        $term       = $termino;
299
        $definition = '';
300
        $ref        = '';
301
        $url        = '';
302
303
        include_once __DIR__ . '/include/storyform.inc.php';
304
305
        $xoopsTpl->assign('modulename', $xoopsModule->dirname());
306
307
        $sform->assign($xoopsTpl);
308
309
        $xoopsTpl->assign('lang_modulename', $xoopsModule->name());
310
        $xoopsTpl->assign('lang_moduledirname', $xoopsModule->getVar('dirname'));
311
        $xoopsTpl->assign('xoops_pagetitle', $myts->htmlSpecialChars($xoopsModule->name()) . ' - ' . _MD_LEXIKON_SUBMITART);
312
        $xoopsTpl->assign('xoops_module_header', '<link rel="stylesheet" type="text/css" href="assets/css/style.css" />');
313
        // Meta data
314
        $meta_description = _MD_LEXIKON_SUBMITART . ' - ' . $myts->htmlSpecialChars($xoopsModule->name());
315
        if (isset($xoTheme) && is_object($xoTheme)) {
316
            $xoTheme->addMeta('meta', 'description', $meta_description);
317
        } else {
318
            $xoopsTpl->assign('xoops_meta_description', $meta_description);
319
        }
320
321
        include XOOPS_ROOT_PATH . '/footer.php';
322
        break;
323
}
324