Passed
Push — master ( d8c963...320458 )
by Michael
04:43
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\{Helper,
22
    EventHandler,
23
    Form,
24
    Utility,
25
    FileHandler,
26
    Perm
27
};
28
29
$GLOBALS['xoopsOption']['template_main'] = 'extcal_post.tpl';
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
38
require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
39
//require_once __DIR__   . '/class/form/extcalform.php';
40
//require_once __DIR__   . '/class/perm.php';
41
42
require_once __DIR__ . '/class/Utility.php';
43
require_once __DIR__ . '/include/constantes.php';
44
45
$permHandler = Perm::getHandler();
46
$xoopsUser   = $xoopsUser ?: null;
47
48
if (!$permHandler->isAllowed($xoopsUser, 'extcal_cat_submit', Request::getInt('cat_id', 0, 'POST'))) {
49
    redirect_header('index.php', 3);
50
}
51
52
// Getting eXtCal object's handler
53
/** @var EventHandler $eventHandler */
54
$eventHandler = Helper::getInstance()->getHandler(_EXTCAL_CLN_EVENT);
55
56
if (Request::hasVar('form_preview', 'POST')) {
57
    require_once XOOPS_ROOT_PATH . '/header.php';
58
59
    // Title of the page
60
    $xoopsTpl->assign('xoops_pagetitle', _MI_EXTCAL_SUBMIT_EVENT);
61
62
    $data = [
63
        'event_title'        => $_POST['event_title'],
64
        'cat_id'             => Request::getInt('cat_id', 0, 'POST'),
65
        'event_desc'         => $_POST['event_desc'],
66
        'event_nbmember'     => Request::getInt('event_nbmember', 0, 'POST'),
67
        'event_contact'      => $_POST['event_contact'],
68
        'event_url'          => $_POST['event_url'],
69
        'event_email'        => $_POST['event_email'],
70
        'event_address'      => $_POST['event_address'],
71
        'event_approved'     => 1,
72
        'event_start'        => $_POST['event_start'],
73
        'have_end'           => $_POST['have_end'],
74
        'event_end'          => $_POST['event_end'],
75
        'dohtml'             => (int)$helper->getConfig('allow_html'),
76
        'event_price'        => $_POST['event_price'],
77
        'event_organisateur' => $_POST['event_organisateur'],
78
        'event_icone'        => $_POST['event_icone'],
79
    ];
80
81
    if (Request::hasVar('event_id', 'POST')) {
82
        $data['event_id'] = Request::getInt('event_id', 0, 'POST');
83
    }
84
85
    // Creating tempory event object to apply Object data filtering
86
    $event = $eventHandler->createEventForPreview($data);
87
    $event = $eventHandler->objectToArray($event, ['cat_id'], 'p');
88
89
    // Adding formated date for start and end event
90
    $eventHandler->formatEventDate($event, $helper->getConfig('event_date_event'));
91
92
    // Assigning event to the template
93
    $xoopsTpl->assign('event', $event);
94
95
    //     $lang = array(
96
    //         '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
97
    //     );
98
    //     // Assigning language data to the template
99
    //     $xoopsTpl->assign('lang', $lang);
100
101
    $event['cat_id']   = Request::getInt('cat_id', 0, 'POST');
102
    $event['have_end'] = $_POST['have_end'];
103
104
    // Display the submit form
105
    /** @var Form\ThemeForm $form */
106
    $form     = $eventHandler->getEventForm('user', 'preview', $event);
107
    $formBody = $form->render();
108
    $xoopsTpl->assign('preview', true);
109
    $xoopsTpl->assign('formBody', $formBody);
110
111
    require_once XOOPS_ROOT_PATH . '/footer.php';
112
} elseif (Request::hasVar('form_submit', 'POST')) {
113
    if (!isset($_POST['rrule_weekly_interval'])) {
114
        $_POST['rrule_weekly_interval'] = 0;
115
    }
116
    // Utility::echoArray($_POST, '',true);
117
    // exit;
118
    // $ts = print_r($_POST,true);
119
    // echo "<pre>{$ts}</pre>";
120
    // If the date format is wrong
121
    //    if (
122
    //        !preg_match(_EXTCAL_MOTIF_DATE, $_POST['event_start']['date'])
123
    //            || !preg_match(_EXTCAL_MOTIF_DATE, $_POST['event_end']['date'])
124
    //    ) {
125
    //        redirect_header(
126
    //            'index.php', 3, _MD_EXTCAL_WRONG_DATE_FORMAT . "<br>"
127
    //            . implode('<br>', $GLOBALS['xoopsSecurity']->getErrors())
128
    //        );
129
    //        exit;
130
    //    }
131
    ///////////////////////////////////////////////////////////////////////////////
132
    Utility::loadImg($_REQUEST, $event_picture1, $event_picture2);
133
    ///////////////////////////////////////////////////////////////////////////////
134
135
    //    require_once __DIR__ . '/class/perm.php';
136
137
    /** @var FileHandler $fileHandler */
138
    $fileHandler = Helper::getInstance()->getHandler(_EXTCAL_CLN_FILE);
139
    $permHandler = Perm::getHandler();
140
    $approve     = $permHandler->isAllowed($xoopsUser, 'extcal_cat_autoapprove', Request::getInt('cat_id', 0, 'POST'));
141
142
    $data = [
143
        'event_title'        => $_POST['event_title'],
144
        'cat_id'             => $_POST['cat_id'],
145
        'event_desc'         => $_POST['event_desc'],
146
        'event_nbmember'     => $_POST['event_nbmember'],
147
        'event_organisateur' => $_POST['event_organisateur'],
148
        'event_contact'      => $_POST['event_contact'],
149
        'event_url'          => $_POST['event_url'],
150
        'event_email'        => $_POST['event_email'],
151
        'event_address'      => $_POST['event_address'],
152
        'event_approved'     => (false === $approve) ? 0 : 1,
153
        'event_start'        => $_POST['event_start'],
154
        'have_end'           => $_POST['have_end'],
155
        'event_end'          => $_POST['event_end'],
156
        'event_picture1'     => @$event_picture1,
157
        'event_picture2'     => @$event_picture2,
158
        'event_price'        => @$_POST['event_price'],
159
        'event_location'     => $_POST['event_location'],
160
        'dohtml'             => $helper->getConfig('allow_html'),
161
        'event_icone'        => $_POST['event_icone'],
162
    ];
163
164
    if (Request::hasVar('event_id', 'POST')) {
165
        $eventHandler->modifyEvent(Request::getInt('event_id', 0, 'POST'), $data);
166
        $fileHandler->updateEventFile(Request::getInt('event_id', 0, 'POST'));
167
        $fileHandler->createFile(Request::getInt('event_id', 0, 'POST'));
168
169
        redirect_header('event.php?event=' . $_POST['event_id'], 3, _MD_EXTCAL_EVENT_UPDATED, false);
170
    } else {
171
        $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

171
        $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...
172
        $data['event_submitdate'] = time();
173
174
        $eventHandler->createEvent($data);
175
        $fileHandler->createFile($eventHandler->getInsertId());
176
177
        $notifyEvent = 'new_event';
178
        if (!$approve) {
179
            $notifyEvent = 'new_event_pending';
180
        }
181
182
        /** @var \XoopsNotificationHandler $notificationHandler */
183
        $notificationHandler = xoops_getHandler('notification');
184
        $notificationHandler->triggerEvent('global', 0, $notifyEvent, ['EVENT_TITLE' => $_POST['event_title']]);
185
        if (1 == $approve) {
186
            //            $categoryHandler = xoops_getModuleHandler(_EXTCAL_CLS_CAT, _EXTCAL_MODULE);
187
            $categoryHandler = Helper::getInstance()->getHandler(_EXTCAL_CLN_CAT);
188
            $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

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