Passed
Push — master ( 9231af...82d95a )
by Michael
03:31
created
Labels
Severity
1
<?php
2
/*
3
 * You may not change or alter any portion of this comment or credits
4
 * of supporting developers from this source code or any supporting source code
5
 * which is considered copyrighted (c) material of the original comment or credit authors.
6
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
 */
11
12
/**
13
 * @copyright    {@link https://xoops.org/ XOOPS Project}
14
 * @license      {@link https://www.gnu.org/licenses/gpl-2.0.html GNU GPL 2 or later}
15
 * @package      extcal
16
 * @since
17
 * @author       XOOPS Development Team,
18
 */
19
20
use Xmf\Request;
21
use XoopsModules\Extcal\{
22
    Helper,
23
    EventHandler,
24
    Form,
25
    Utility,
26
    FileHandler,
27
    Perm
28
};
29
30
require_once __DIR__ . '/header.php';
31
32
global $xoopsUser, $xoopsTpl;
33
34
/** @var Time $timeHandler */
35
/** @var Helper $helper */
36
$helper                                  = Helper::getInstance();
37
$GLOBALS['xoopsOption']['template_main'] = 'extcal_post.tpl';
38
39
require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
40
//require_once __DIR__   . '/class/form/extcalform.php';
41
//require_once __DIR__   . '/class/perm.php';
42
43
require_once __DIR__ . '/class/Utility.php';
44
require_once __DIR__ . '/include/constantes.php';
45
46
$permHandler = Perm::getHandler();
47
$xoopsUser   = $xoopsUser ?: null;
48
49
if (!$permHandler->isAllowed($xoopsUser, 'extcal_cat_submit', Request::getInt('cat_id', 0, 'POST'))) {
50
    redirect_header('index.php', 3);
51
}
52
53
// Getting eXtCal object's handler
54
/** @var EventHandler $eventHandler */
55
$eventHandler = Helper::getInstance()->getHandler(_EXTCAL_CLN_EVENT);
56
57
if (Request::hasVar('form_preview', 'POST')) {
58
    require_once XOOPS_ROOT_PATH . '/header.php';
59
60
    // Title of the page
61
    $xoopsTpl->assign('xoops_pagetitle', _MI_EXTCAL_SUBMIT_EVENT);
62
63
    $data = [
64
        'event_title'        => $_POST['event_title'],
65
        'cat_id'             => Request::getInt('cat_id', 0, 'POST'),
66
        'event_desc'         => $_POST['event_desc'],
67
        'event_nbmember'     => Request::getInt('event_nbmember', 0, 'POST'),
68
        'event_contact'      => $_POST['event_contact'],
69
        'event_url'          => $_POST['event_url'],
70
        'event_email'        => $_POST['event_email'],
71
        'event_address'      => $_POST['event_address'],
72
        'event_approved'     => 1,
73
        'event_start'        => $_POST['event_start'],
74
        'have_end'           => $_POST['have_end'],
75
        'event_end'          => $_POST['event_end'],
76
        'dohtml'             => (int)$helper->getConfig('allow_html'),
77
        'event_price'        => $_POST['event_price'],
78
        'event_organisateur' => $_POST['event_organisateur'],
79
        'event_icone'        => $_POST['event_icone'],
80
    ];
81
82
    if (Request::hasVar('event_id', 'POST')) {
83
        $data['event_id'] = Request::getInt('event_id', 0, 'POST');
84
    }
85
86
    // Creating tempory event object to apply Object data filtering
87
    $event = $eventHandler->createEventForPreview($data);
88
    $event = $eventHandler->objectToArray($event, ['cat_id'], 'p');
89
90
    // Adding formated date for start and end event
91
    $eventHandler->formatEventDate($event, $helper->getConfig('event_date_event'));
92
93
    // Assigning event to the template
94
    $xoopsTpl->assign('event', $event);
95
96
    //     $lang = array(
97
    //         'start' => _MD_EXTCAL_START, 'end' => _MD_EXTCAL_END, 'contact_info' => _MD_EXTCAL_CONTACT_INFO, 'email' => _MD_EXTCAL_EMAIL, 'url' => _MD_EXTCAL_URL, 'whos_going' => _MD_EXTCAL_WHOS_GOING, 'whosnot_going' => _MD_EXTCAL_WHOSNOT_GOING
98
    //     );
99
    //     // Assigning language data to the template
100
    //     $xoopsTpl->assign('lang', $lang);
101
102
    $event['cat_id']   = Request::getInt('cat_id', 0, 'POST');
103
    $event['have_end'] = $_POST['have_end'];
104
105
    // Display the submit form
106
    /** @var Form\ThemeForm $form */
107
    $form     = $eventHandler->getEventForm('user', 'preview', $event);
108
    $formBody = $form->render();
109
    $xoopsTpl->assign('preview', true);
110
    $xoopsTpl->assign('formBody', $formBody);
111
112
    require_once XOOPS_ROOT_PATH . '/footer.php';
113
} elseif (Request::hasVar('form_submit', 'POST')) {
114
    if (!isset($_POST['rrule_weekly_interval'])) {
115
        $_POST['rrule_weekly_interval'] = 0;
116
    }
117
    // Utility::echoArray($_POST, '',true);
118
    // exit;
119
    // $ts = print_r($_POST,true);
120
    // echo "<pre>{$ts}</pre>";
121
    // If the date format is wrong
122
    //    if (
123
    //        !preg_match(_EXTCAL_MOTIF_DATE, $_POST['event_start']['date'])
124
    //            || !preg_match(_EXTCAL_MOTIF_DATE, $_POST['event_end']['date'])
125
    //    ) {
126
    //        redirect_header(
127
    //            'index.php', 3, _MD_EXTCAL_WRONG_DATE_FORMAT . "<br>"
128
    //            . implode('<br>', $GLOBALS['xoopsSecurity']->getErrors())
129
    //        );
130
    //        exit;
131
    //    }
132
    ///////////////////////////////////////////////////////////////////////////////
133
    Utility::loadImg($_REQUEST, $event_picture1, $event_picture2);
134
    ///////////////////////////////////////////////////////////////////////////////
135
136
    //    require_once __DIR__ . '/class/perm.php';
137
138
    /** @var FileHandler $fileHandler */
139
    $fileHandler = Helper::getInstance()->getHandler(_EXTCAL_CLN_FILE);
140
    $permHandler = Perm::getHandler();
141
    $approve     = $permHandler->isAllowed($xoopsUser, 'extcal_cat_autoapprove', Request::getInt('cat_id', 0, 'POST'));
142
143
    $data = [
144
        'event_title'        => $_POST['event_title'],
145
        'cat_id'             => $_POST['cat_id'],
146
        'event_desc'         => $_POST['event_desc'],
147
        'event_nbmember'     => $_POST['event_nbmember'],
148
        'event_organisateur' => $_POST['event_organisateur'],
149
        'event_contact'      => $_POST['event_contact'],
150
        'event_url'          => $_POST['event_url'],
151
        'event_email'        => $_POST['event_email'],
152
        'event_address'      => $_POST['event_address'],
153
        'event_approved'     => (false === $approve) ? 0 : 1,
154
        'event_start'        => $_POST['event_start'],
155
        'have_end'           => $_POST['have_end'],
156
        'event_end'          => $_POST['event_end'],
157
        'event_picture1'     => @$event_picture1,
158
        'event_picture2'     => @$event_picture2,
159
        'event_price'        => @$_POST['event_price'],
160
        'event_location'     => $_POST['event_location'],
161
        'dohtml'             => $helper->getConfig('allow_html'),
162
        'event_icone'        => $_POST['event_icone'],
163
    ];
164
165
    if (Request::hasVar('event_id', 'POST')) {
166
        $eventHandler->modifyEvent(Request::getInt('event_id', 0, 'POST'), $data);
167
        $fileHandler->updateEventFile(Request::getInt('event_id', 0, 'POST'));
168
        $fileHandler->createFile(Request::getInt('event_id', 0, 'POST'));
169
170
        redirect_header('event.php?event=' . $_POST['event_id'], 3, _MD_EXTCAL_EVENT_UPDATED, false);
171
    } else {
172
        $data['event_submitter']  = $xoopsUser ? $xoopsUser->getVar('uid') : 0;
0 ignored issues
show
The method getVar() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

172
        $data['event_submitter']  = $xoopsUser ? $xoopsUser->/** @scrutinizer ignore-call */ getVar('uid') : 0;

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
173
        $data['event_submitdate'] = time();
174
175
        $eventHandler->createEvent($data);
176
        $fileHandler->createFile($eventHandler->getInsertId());
177
178
        $notifyEvent = 'new_event';
179
        if (!$approve) {
180
            $notifyEvent = 'new_event_pending';
181
        }
182
183
        /** @var \XoopsNotificationHandler $notificationHandler */
184
        $notificationHandler = xoops_getHandler('notification');
185
        $notificationHandler->triggerEvent('global', 0, $notifyEvent, ['EVENT_TITLE' => $_POST['event_title']]);
186
        if (1 == $approve) {
187
            //            $categoryHandler = xoops_getModuleHandler(_EXTCAL_CLS_CAT, _EXTCAL_MODULE);
188
            $categoryHandler = Helper::getInstance()->getHandler(_EXTCAL_CLN_CAT);
189
            $cat        = $categoryHandler->getCat(Request::getInt('cat_id', 0, 'POST'), $xoopsUser, 'all');
0 ignored issues
show
The method getCat() 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 ignore-call  annotation

189
            /** @scrutinizer ignore-call */ 
190
            $cat        = $categoryHandler->getCat(Request::getInt('cat_id', 0, 'POST'), $xoopsUser, 'all');
Loading history...
190
            $notificationHandler->triggerEvent(
191
                'cat',
192
                Request::getInt('cat_id', 0, 'POST'),
193
                'new_event_cat',
194
                [
195
                    'EVENT_TITLE' => $_POST['event_title'],
196
                    'CAT_NAME'    => $cat->getVar('cat_name'),
197
                ]
198
            );
199
        }
200
    }
201
202
    if ($approve) {
203
        redirect_header(_EXTCAL_FILE_CALMONTH, 3, _MD_EXTCAL_EVENT_CREATED, false);
204
    } else {
205
        redirect_header(_EXTCAL_FILE_CALMONTH, 3, _MD_EXTCAL_EVENT_PENDING, false);
206
    }
207
}
208