Passed
Push — master ( f62223...75b16c )
by Michael
02:33
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 http://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 XoopsModules\Extcal;
21
22
require_once dirname(dirname(__DIR__)) . '/mainfile.php';
23
24
/** @var Extcal\Helper $helper */
25
$helper = Extcal\Helper::getInstance();
26
$GLOBALS['xoopsOption']['template_main'] = 'extcal_post.tpl';
27
28
require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
0 ignored issues
show
The constant XOOPS_ROOT_PATH was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
29
//require_once __DIR__   . '/class/form/extcalform.php';
30
//require_once __DIR__   . '/class/perm.php';
31
32
require_once __DIR__ . '/class/Utility.php';
33
require_once __DIR__ . '/include/constantes.php';
34
35
$permHandler = Extcal\Perm::getHandler();
36
$xoopsUser   = $xoopsUser ?: null;
37
38
if (!$permHandler->isAllowed($xoopsUser, 'extcal_cat_submit', \Xmf\Request::getInt('cat_id', 0, 'POST'))) {
0 ignored issues
show
The type Xmf\Request was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
39
    redirect_header('index.php', 3);
40
}
41
42
// Getting eXtCal object's handler
43
/** @var Extcal\EventHandler $eventHandler */
44
$eventHandler = Extcal\Helper::getInstance()->getHandler(_EXTCAL_CLN_EVENT);
45
46
if (\Xmf\Request::hasVar('form_preview', 'POST')) {
47
    require_once XOOPS_ROOT_PATH . '/header.php';
48
49
    // Title of the page
50
    $xoopsTpl->assign('xoops_pagetitle', _MI_EXTCAL_SUBMIT_EVENT);
51
52
    $data = [
53
        'event_title'        => $_POST['event_title'],
54
        'cat_id'             => \Xmf\Request::getInt('cat_id', 0, 'POST'),
55
        'event_desc'         => $_POST['event_desc'],
56
        'event_nbmember'     => \Xmf\Request::getInt('event_nbmember', 0, 'POST'),
57
        'event_contact'      => $_POST['event_contact'],
58
        'event_url'          => $_POST['event_url'],
59
        'event_email'        => $_POST['event_email'],
60
        'event_address'      => $_POST['event_address'],
61
        'event_approved'     => 1,
62
        'event_start'        => $_POST['event_start'],
63
        'have_end'           => $_POST['have_end'],
64
        'event_end'          => $_POST['event_end'],
65
        'dohtml'             => (int)$helper->getConfig('allow_html'),
66
        'event_price'        => $_POST['event_price'],
67
        'event_organisateur' => $_POST['event_organisateur'],
68
        'event_icone'        => $_POST['event_icone'],
69
    ];
70
71
    if (\Xmf\Request::hasVar('event_id', 'POST')) {
72
        $data['event_id'] = \Xmf\Request::getInt('event_id', 0, 'POST');
73
    }
74
75
    // Creating tempory event object to apply Object data filtering
76
    $event = $eventHandler->createEventForPreview($data);
77
    $event = $eventHandler->objectToArray($event, ['cat_id'], 'p');
78
79
    // Adding formated date for start and end event
80
    $eventHandler->formatEventDate($event, $helper->getConfig('event_date_event'));
81
82
    // Assigning event to the template
83
    $xoopsTpl->assign('event', $event);
84
85
    //     $lang = array(
86
    //         '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
87
    //     );
88
    //     // Assigning language data to the template
89
    //     $xoopsTpl->assign('lang', $lang);
90
91
    $event['cat_id']   = \Xmf\Request::getInt('cat_id', 0, 'POST');
92
    $event['have_end'] = $_POST['have_end'];
93
94
    // Display the submit form
95
    /** @var Extcal\Form\ThemeForm $form */
96
    $form     = $eventHandler->getEventForm('user', 'preview', $event);
97
    $formBody = $form->render();
98
    $xoopsTpl->assign('preview', true);
99
    $xoopsTpl->assign('formBody', $formBody);
100
101
    require_once XOOPS_ROOT_PATH . '/footer.php';
102
} elseif (\Xmf\Request::hasVar('form_submit', 'POST')) {
103
    if (!isset($_POST['rrule_weekly_interval'])) {
104
        $_POST['rrule_weekly_interval'] = 0;
105
    }
106
    // Extcal\Utility::echoArray($_POST, '',true);
107
    // exit;
108
    // $ts = print_r($_POST,true);
109
    // echo "<pre>{$ts}</pre>";
110
    // If the date format is wrong
111
    //    if (
112
    //        !preg_match(_EXTCAL_MOTIF_DATE, $_POST['event_start']['date'])
113
    //            || !preg_match(_EXTCAL_MOTIF_DATE, $_POST['event_end']['date'])
114
    //    ) {
115
    //        redirect_header(
116
    //            'index.php', 3, _MD_EXTCAL_WRONG_DATE_FORMAT . "<br>"
117
    //            . implode('<br>', $GLOBALS['xoopsSecurity']->getErrors())
118
    //        );
119
    //        exit;
120
    //    }
121
    ///////////////////////////////////////////////////////////////////////////////
122
    Extcal\Utility::loadImg($_REQUEST, $event_picture1, $event_picture2);
123
    ///////////////////////////////////////////////////////////////////////////////
124
125
//    require_once __DIR__ . '/class/perm.php';
126
127
    /** @var Extcal\FileHandler $fileHandler */
128
    $fileHandler = Extcal\Helper::getInstance()->getHandler(_EXTCAL_CLN_FILE);
129
    $permHandler = Extcal\Perm::getHandler();
130
    $approve     = $permHandler->isAllowed($xoopsUser, 'extcal_cat_autoapprove', \Xmf\Request::getInt('cat_id', 0, 'POST'));
131
132
    $data = [
133
        'event_title'         => $_POST['event_title'],
134
        'cat_id'              => $_POST['cat_id'],
135
        'event_desc'          => $_POST['event_desc'],
136
        'event_nbmember'      => $_POST['event_nbmember'],
137
        'event_organisateur'  => $_POST['event_organisateur'],
138
        'event_contact'       => $_POST['event_contact'],
139
        'event_url'           => $_POST['event_url'],
140
        'event_email'         => $_POST['event_email'],
141
        'event_address'       => $_POST['event_address'],
142
        'event_approved'      => (false === $approve) ? 0 : 1,
143
        'event_start'         => $_POST['event_start'],
144
        'have_end'            => $_POST['have_end'],
145
        'event_end'           => $_POST['event_end'],
146
        'event_picture1'      => @$event_picture1,
147
        'event_picture2'      => @$event_picture2,
148
        'event_price'         => @$_POST['event_price'],
149
        'event_location' => $_POST['event_location'],
150
        'dohtml'              => $helper->getConfig('allow_html'),
151
        'event_icone'         => $_POST['event_icone'],
152
153
    ];
154
155
    if (\Xmf\Request::hasVar('event_id', 'POST')) {
156
        $eventHandler->modifyEvent(\Xmf\Request::getInt('event_id', 0, 'POST'), $data);
157
        $fileHandler->updateEventFile(\Xmf\Request::getInt('event_id', 0, 'POST'));
158
        $fileHandler->createFile(\Xmf\Request::getInt('event_id', 0, 'POST'));
159
160
        redirect_header('event.php?event=' . $_POST['event_id'], 3, _MD_EXTCAL_EVENT_UPDATED, false);
161
    } else {
162
        $data['event_submitter']  = $xoopsUser ? $xoopsUser->getVar('uid') : 0;
163
        $data['event_submitdate'] = time();
164
165
        $eventHandler->createEvent($data);
166
        $fileHandler->createFile($eventHandler->getInsertId());
167
168
        $notifyEvent = 'new_event';
169
        if (!$approve) {
170
            $notifyEvent = 'new_event_pending';
171
        }
172
173
        /** @var \XoopsNotificationHandler $notificationHandler */
174
        $notificationHandler = xoops_getHandler('notification');
175
        $notificationHandler->triggerEvent('global', 0, $notifyEvent, ['EVENT_TITLE' => $_POST['event_title']]);
176
        if (1 == $approve) {
177
            //            $catHandler = xoops_getModuleHandler(_EXTCAL_CLS_CAT, _EXTCAL_MODULE);
178
            $catHandler = Extcal\Helper::getInstance()->getHandler(_EXTCAL_CLN_CAT);
179
            $cat        = $catHandler->getCat(\Xmf\Request::getInt('cat_id', 0, 'POST'), $xoopsUser, 'all');
180
            $notificationHandler->triggerEvent('cat', \Xmf\Request::getInt('cat_id', 0, 'POST'), 'new_event_cat', [
181
                'EVENT_TITLE' => $_POST['event_title'],
182
                'CAT_NAME'    => $cat->getVar('cat_name'),
183
            ]);
184
        }
185
    }
186
187
    if ($approve) {
188
        redirect_header(_EXTCAL_FILE_CALMONTH, 3, _MD_EXTCAL_EVENT_CREATED, false);
189
    } else {
190
        redirect_header(_EXTCAL_FILE_CALMONTH, 3, _MD_EXTCAL_EVENT_PENDING, false);
191
    }
192
}
193