Completed
Push — master ( d9c1b5...d598f1 )
by Michael
20s queued 11s
created

APCal   F

Complexity

Total Complexity 793

Size/Duplication

Total Lines 5776
Duplicated Lines 10.58 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
dl 611
loc 5776
rs 0.8
c 0
b 0
f 0
wmc 793
lcom 1
cbo 3

65 Methods

Rating   Name   Duplication   Size   Complexity  
F __construct() 0 76 19
F make_cal_link() 6 56 32
B make_event_link() 0 23 7
A urlencode() 0 6 1
B makeShort() 0 82 1
A read_locale() 0 6 2
B set_date() 0 35 7
A daytype_to_colors() 0 18 5
A get_daytype() 0 27 5
B get_date_schedule() 10 73 6
B get_coming_schedule() 10 88 8
D get_flags_date_has_events() 22 92 15
D get_mini_calendar_html() 39 164 15
B get_yearly() 0 70 4
B get_monthly() 7 82 4
A get_weekly() 52 52 2
A get_daily() 52 52 2
F get_calendar_information() 21 116 15
F get_monthly_html() 0 267 37
F get_weekly_html() 76 305 48
F get_daily_html() 48 177 23
B savepictures() 0 35 6
F get_schedule_view_html() 13 494 74
F get_schedule_edit_html() 5 644 59
F update_schedule() 28 217 44
B delete_schedule() 6 34 10
A delete_schedule_one() 3 14 3
A delete_regonline() 0 41 1
A redirect() 0 26 4
A get_tz_for_display() 0 4 3
A get_tz_options() 0 46 3
A get_timezone_desc() 0 16 3
C get_categories_selform() 0 55 10
A parse_posted_date() 0 28 5
A get_vtimezones_str() 0 31 3
C get_sql_set() 11 61 13
A get_long_ymdn() 0 9 1
A get_middle_md() 0 7 1
A get_middle_dhi() 11 11 3
A get_middle_hi() 10 10 3
A get_options_for_hour() 0 11 4
A get_options_for_min() 0 10 3
B get_coming_time_description() 0 32 8
F get_todays_time_description() 29 64 15
C get_time_desc_for_a_day() 34 54 12
A get_formtextdateselect() 0 4 1
A get_embed_css() 0 9 2
A get_submitter_info() 0 4 1
B get_where_about_categories() 0 31 6
A get_where_about_class() 0 24 5
A mb_convert_kana() 9 9 3
A textarea_sanitizer_for_show() 0 4 1
A text_sanitizer_for_show() 0 4 1
A textarea_sanitizer_for_edit() 0 4 1
A text_sanitizer_for_edit() 0 4 1
A textarea_sanitizer_for_export_ics() 0 4 1
A output_ics_confirm() 0 31 2
F output_ics() 10 189 25
B import_ics_via_fopen() 10 42 9
A import_ics_via_upload() 10 28 5
B update_record_after_import() 0 31 6
F rrule_to_human_language() 12 99 24
F rrule_to_form() 13 234 28
F rrule_from_post() 0 108 24
F rrule_extract() 54 452 98

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like APCal often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use APCal, and based on these observations, apply Extract Interface, too.

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 http://xoops.org/ XOOPS Project}
14
 * @license     {@link http://www.fsf.org/copyleft/gpl.html GNU public license}
15
 * @package
16
 * @since
17
 * @author       XOOPS Development Team,
18
 * @author       GIJ=CHECKMATE (PEAK Corp. http://www.peak.ne.jp/)
19
 * @author       Antiques Promotion (http://www.antiquespromotion.ca)
20
 */
21
22
if (!class_exists('APCal')) {
23
    define('APCAL_EVENT_TABLE', 'apcal_event');
24
    define('APCAL_CAT_TABLE', 'apcal_cat');
25
//    require_once __DIR__ . '/../../../include/cp_header.php';
26
    require_once XOOPS_ROOT_PATH . '/modules/apcal/include/ro_contacthandler.php'; // added by goffy convert name(s) in field contact in a links to member account
27
    require_once XOOPS_ROOT_PATH . '/modules/apcal/class/thumb.php';
28
29
    /**
30
     * Class APCal
31
     */
32
    class APCal
33
    {
34
        // SKELTON (they will be defined in language files)
35
        public $holidays           = array();
36
        public $date_short_names   = array();
37
        public $date_long_names    = array();
38
        public $week_numbers       = array();
39
        public $week_short_names   = array();
40
        public $week_middle_names  = array();
41
        public $week_long_names    = array();
42
        public $month_short_names  = array();
43
        public $month_middle_names = array();
44
        public $month_long_names   = array();
45
        public $byday2langday_w    = array();
46
        public $byday2langday_m    = array();
47
48
        // LOCALES
49
        public $locale        = '';            // locale for APCal original
50
        public $locale4system = '';    // locale for UNIX systems (deprecated)
51
52
        // COLORS/STYLES  public
53
        public $holiday_color     = '#CC0000';
54
        public $holiday_bgcolor   = '#FFEEEE';
55
        public $sunday_color      = '#CC0000';
56
        public $sunday_bgcolor    = '#FFEEEE';
57
        public $saturday_color    = '#0000FF';
58
        public $saturday_bgcolor  = '#EEF7FF';
59
        public $weekday_color     = '#000099';
60
        public $weekday_bgcolor   = '#FFFFFF';
61
        public $targetday_bgcolor = '#CCFF99';
62
        public $calhead_color     = '#009900';
63
        public $calhead_bgcolor   = '#CCFFCC';
64
        public $frame_css         = '#000000';
65
        public $allcats_color     = '#5555AA';
66
        public $event_color       = '#000000';
67
        public $event_bgcolor     = '#EEEEEE';
68
69
        // GOOGLE MAPS
70
        public $gmlat    = 0;
71
        public $gmlng    = 0;
72
        public $gmzoom   = 12;
73
        public $gmheight = 350;
74
        public $gmPoints = array();
75
76
        // PICTURES
77
        public $picWidth   = 150;
78
        public $picHeight  = 150;
79
        public $nbPictures = 5;
80
81
        public $showPicMonthly = 1;
82
        public $showPicWeekly  = 1;
83
        public $showPicDaily   = 1;
84
        public $showPicList    = 1;
85
86
        public $widerDays = array('Saturday', 'Sunday');
87
88
        public $useurlrewrite     = 0;
89
        public $enablecalmap      = 1;
90
        public $enableeventmap    = 1;
91
        public $enablesharing     = 1;
92
        public $eventNavEnabled   = 1;
93
        public $displayCatTitle   = 1;
94
        public $enablesocial      = false;
95
        public $enabletellafriend = false;
96
        public $enableprint       = false;
97
98
        public $default_view = 'Monthly';
99
100
        // TIMEZONES
101
        public $server_TZ       = 9;            // Server's  Timezone Offset (hour)
102
        public $user_TZ         = 9;                // User's Timezone Offset (hour)
103
        public $use_server_TZ   = false;    // if 'caldate' is generated in Server's time
104
        public $displayTimezone = 0;
105
106
        // AUTHORITIES
107
        public $insertable = true;        // can insert a new event
108
        public $editable   = true;            // can update an event he posted
109
        public $superedit  = false;            // can update all event
110
        public $deletable  = true;            // can delete an event he posted
111
        public $user_id    = -1;                // User's ID
112
        public $isadmin    = false;            // Is admin or not
113
114
        // ANOTHER public properties
115
        public $conn;                    // MySQL�Ȥ���³�ϥ�ɥ� (ͽ������򤹤�����å�)
116
        public $table                = 'apcal_event';        // table name for events
117
        public $cat_table            = 'apcal_cat';        // table name for categories
118
        public $pic_table            = 'apcal_pictures';        // table name for pictures
119
        public $plugin_table         = 'apcal_plugin';    // table name for plugins
120
        public $base_url             = '';
121
        public $base_path            = '';
122
        public $images_url           = '/include/apcal/images';    // ���Υե������ spacer.gif, arrow*.gif ����֤��Ƥ���
123
        public $images_path          = 'include/apcal/images';
124
        public $jscalendar           = 'jscalendar'; // DHTML Date/Time Selector
125
        public $jscalendar_lang_file = 'calendar-jp.js'; // language file of the jscalh
126
        public $can_output_ics       = true;    // ics�ե�������Ϥ���Ĥ��뤫�ɤ���
127
        public $ics_new_cal          = true;
128
        public $connection           = 'http';        // http �� https ��
129
        public $max_rrule_extract    = 100;    // rrule ��Ÿ���ξ�¿�(COUNT)
130
        public $week_start           = 0;            // ��������� 0������ 1������
131
        public $week_numbering       = 0;        // ���ο����� 0�ʤ��� 1�ʤ�ǯ���̻�
132
        public $day_start            = 0;            // ���դζ���������ñ�̡�
133
        public $use24                = true;                // 24�������ʤ�true��12�������ʤ�false
134
        public $now_cid              = 0;                // ���ƥ������
135
        public $categories           = array();        // ����������ǽ�ʥ��ƥ��ꥪ�֥�������Ϣ������
136
        public $canbemain_cats       = array();
137
        public $groups               = array();            // PRIVATE���������ǽ�ʥ��롼�פ�Ϣ������
138
        public $nameoruname          = 'name';        // ��ƼԤ�ɽ���ʥ?����̾���ϥ�ɥ�̾����
139
        public $proxysettings        = '';        // Proxy setting
140
        public $last_summary         = '';        // ���������̾�򻲾Ȥ��뤿��Υץ�ѥƥ�
141
        public $plugins_path_monthly = 'plugins/monthly';
142
        public $plugins_path_weekly  = 'plugins/weekly';
143
        public $plugins_path_daily   = 'plugins/daily';
144
145
        // private members
146
        public $year;
147
        public $month;
148
        public $date;
149
        public $day;            // 0:Sunday ... 6:Saturday
150
        public $daytype;        // 0:weekdays 1:saturday 2:sunday 3:holiday
151
        public $caldate;        // everytime 'Y-n-j' formatted
152
        public $unixtime;
153
        public $long_event_legends = array();
154
        public $language           = 'japanese';
155
156
        // ����դ������ѥ���
157
        public $original_id;    // $_GET['event_id']�����ľ��˻��Ȳ�ǽ
158
159
        // added by goffy: vars for online registration
160
        public $table_ro_members = '_apcal_ro_members'; // table for eventmembers
161
        public $table_ro_events  = '_apcal_ro_events';  // table for events, where online registration is possible (max registration, email notify in case off add/remove eventmembers
162
        public $table_ro_notify  = '_apcal_ro_notify';  // table for persons, which should be informed about registrations by email
163
        public $redirecturl      = '';                  // variable für redirect
164
        public $registered       = 0;                   // var whether user is already regristrated for this event or not
165
        public $regonline        = 0;                   // var, whether online registration is activated or not
166
        public $roimage          = 0;                   // var for image to mark events with online registration
167
        public $eventmembers     = '';                  // first var for show additional info
168
        public $eventmembersall  = '';                  // second var for show additional info
169
        public $enableregistration = 1;
170
        var $enablecontact = 0;                         // use contacthandler
171
        var $ro_showtip = 0;                            // show tip for online registration
172
        var $ro_mail_sender = "[email protected]";    // e-mail of sender for notify registered person
173
        var $ro_mail_sendername = "Calendar of APCal";  // name of sender for notify registered person
174
        var $ro_mail_signature = "Your Team of APCal";  // signature for notify registered person
175
        var $ro_showlist = 0;                           // show list of registered persons
176
        // var $ro_superedit = 0;                          // user can edit/delete registration of other persons
177
        // var $ro_image_available = "";                   // path to image showing availability of the event
178
        // var $ro_use_waiting_list = "";                  // a waiting list will be used for an event
179
        // var $ro_need_confirm = "";                      // each online registration must be confirm by event owner
180
        var $ro_extrainfo1 = '';                 // define extrainfo1
181
        var $ro_extrainfo2 = '';                 // define extrainfo2
182
        var $ro_extrainfo3 = '';                 // define extrainfo3
183
        var $ro_extrainfo4 = '';                 // define extrainfo4
184
        var $ro_extrainfo5 = '';                 // define extrainfo5
185
        var $ro_extrainfo1_obl = 0;              // define whether extrainfo1 is obligatory or on voluntary base
186
        var $ro_extrainfo2_obl = 0;              // define whether extrainfo1 is obligatory or on voluntary base
187
        var $ro_extrainfo3_obl = 0;              // define whether extrainfo1 is obligatory or on voluntary base
188
        var $ro_extrainfo4_obl = 0;              // define whether extrainfo1 is obligatory or on voluntary base
189
        var $ro_extrainfo5_obl = 0;              // define whether extrainfo1 is obligatory or on voluntary base
190
        // end goffy
191
192
        /*******************************************************************/
193
        /*        CONSTRUCTOR etc.                                         */
194
        /*******************************************************************/
195
196
        // Constructor
197
        /**
198
         * APCal constructor.
199
         * @param string $target_date
200
         * @param string $language
201
         * @param bool   $reload
202
         */
203
        public function __construct($target_date = '', $language = 'japanese', $reload = false)
204
        {
205
            // ���դΥ��å�
206
            if ($target_date) {
207
                $this->set_date($target_date);
208
            } elseif (isset($_GET['caldate'])) {
209
                $this->set_date($_GET['caldate']);
210
            } elseif (isset($_POST['apcal_jumpcaldate']) && isset($_POST['apcal_year'])) {
211
                if (empty($_POST['apcal_month'])) {
212
                    // ǯ�Τߤ�POST���줿���
213
                    $month = 1;
214
                    $date  = 1;
215
                } elseif (empty($_POST['apcal_date'])) {
216
                    // ǯ���POST���줿���
217
                    $month = (int)$_POST['apcal_month'];
218
                    $date  = 1;
219
                } else {
220
                    // ǯ�����POST���줿���
221
                    $month = (int)$_POST['apcal_month'];
222
                    $date  = (int)$_POST['apcal_date'];
223
                }
224
                $year = (int)$_POST['apcal_year'];
225
                $this->set_date("$year-$month-$date");
226
                $caldate_posted = true;
227
            } else {
228
                $this->set_date(date('Y-n-j'));
229
                $this->use_server_TZ = true;
230
            }
231
232
            // SSL��̵ͭ��$_SERVER['HTTPS'] �ˤ�Ƚ��
233
            if (defined('XOOPS_URL')) {
234
                $this->connection = substr(XOOPS_URL, 0, 8) === 'https://' ? 'https' : 'http';
235
            } elseif (!empty($_SERVER['HTTPS'])) {
236
                $this->connection = 'https';
237
            } else {
238
                $this->connection = 'http';
239
            }
240
241
            // ���ƥ��꡼����μ���
242
            $this->now_cid = !empty($_GET['cid']) ? (int)$_GET['cid'] : 0;
243
244
            // POST�ǥХ�Х�����դ��������줿��硢���꤬����Х�?�ɤ�Ԥ�
245
            if (!empty($caldate_posted) && $reload && !headers_sent()) {
246
                $reload_str       = "Location: $this->connection://{$_SERVER['HTTP_HOST']}{$_SERVER['PHP_SELF']}?caldate=$this->caldate&{$_SERVER['QUERY_STRING']}";
247
                $needed_post_vars = array('op', 'order', 'cid', 'num', 'txt');
248
                foreach ($needed_post_vars as $post) {
249
                    if (isset($_POST[$post])) {
250
                        $reload_str .= "&$post=" . urlencode($_POST[$post]);
251
                    }
252
                }
253
                $reload_str4header = strtr($reload_str, "\r\n\0", '   ');
254
                header($reload_str4header);
255
                exit;
256
            }
257
258
            // APCal.php �ե������¸�ߤ���ǥ��쥯�ȥ�ΰ�ľ��١����Ȥ���
259
            $this->base_path = dirname(__DIR__);
260
261
            // ����ե�������ɤ߹���
262
            if (file_exists("$this->base_path/language/$language/apcal_vars.phtml")) {
263
                include "$this->base_path/language/$language/apcal_vars.phtml";
264
                require_once "$this->base_path/language/$language/apcal_constants.php";
265
                $this->language             = $language;
266
                $this->jscalendar_lang_file = _APCAL_JS_CALENDAR;
267
            } elseif (file_exists("$this->base_path/language/english/apcal_vars.phtml")) {
268
                include "$this->base_path/language/english/apcal_vars.phtml";
269
                require_once "$this->base_path/language/english/apcal_constants.php";
270
                $this->language             = 'english';
271
                $this->jscalendar_lang_file = 'calendar-en.js';
272
            }
273
274
            // �?����ե�������ɹ�
275
            if (!empty($this->locale)) {
276
                $this->read_locale();
277
            }
278
        }
279
280
        /**
281
         * @param  string $get_target
282
         * @param  string $smode
283
         * @param  int    $cid
284
         * @param  string $caldate
285
         * @return string
286
         */
287
        public function make_cal_link($get_target = '', $smode = 'Monthly', $cid = 0, $caldate = '')
288
        {
289
            global $xoopsModule;
290
291
            if ($cid < 0) {
292
                $cid = $this->now_cid;
293
            }
294
            if ($caldate === '') {
295
                $caldate = $this->caldate;
296
            }
297
            if ($smode === '') {
298
                $smode = $this->default_view;
299
            }
300
301
            $isAllCat      = $cid == 0;
302
            $isDefaultView = $smode == $this->default_view;
303
            $isToday       = date('Y-n-j') == $caldate;
304
305
            if ($this->conn) {
306
                $cat = $GLOBALS['xoopsDB']->query("SELECT cat_shorttitle FROM $this->cat_table WHERE cid=$cid LIMIT 0,1");
307
            } else {
308
                $cat = false;
309
            }
310
311
            if ($cat && $GLOBALS['xoopsDB']->getRowsNum($cat)) {
312
                $cat = $GLOBALS['xoopsDB']->fetchObject($cat);
313
                $cat = urlencode(urlencode($cat->cat_shorttitle));
314
            } else {
315
                $cat = isset($xoopsModule)
316
                       && !empty($xoopsModule) ? urlencode(urlencode($xoopsModule->getVar('name'))) : 0;
317
            }
318
319
            if ($this->useurlrewrite) {
320
                if (!$isAllCat && !$isDefaultView && !$isToday) {
321
                    $link = XOOPS_URL . "/modules/apcal/$cat-$smode-$caldate";
322 View Code Duplication
                } elseif (!$isAllCat && !$isDefaultView && $isToday) {
0 ignored issues
show
Duplication introduced by
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...
323
                    $link = XOOPS_URL . "/modules/apcal/$cat-$smode";
324
                } elseif (!$isAllCat && $isDefaultView && !$isToday) {
325
                    $link = XOOPS_URL . "/modules/apcal/$cat-$caldate";
326
                } elseif (!$isAllCat && $isDefaultView && $isToday) {
327
                    $link = XOOPS_URL . "/modules/apcal/$cat";
328 View Code Duplication
                } elseif ($isAllCat && !$isDefaultView && !$isToday) {
0 ignored issues
show
Duplication introduced by
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...
329
                    $link = XOOPS_URL . "/modules/apcal/$smode-$caldate";
330
                } elseif ($isAllCat && !$isDefaultView && $isToday) {
331
                    $link = XOOPS_URL . "/modules/apcal/$smode";
332
                } elseif ($isAllCat && $isDefaultView && !$isToday) {
333
                    $link = XOOPS_URL . "/modules/apcal/$caldate";
334
                } else {
335
                    $link = XOOPS_URL . '/modules/apcal/';
336
                }
337
338
                return $link;
339
            } else {
340
                return ($get_target === '' ? XOOPS_URL . '/modules/apcal/' : $get_target) . "?cid=$cid&smode=$smode&caldate=$caldate";
341
            }
342
        }
343
344
        /**
345
         * @param         $event_id
346
         * @param  string $get_target
347
         * @param  string $caldate
348
         * @return string
349
         */
350
        public function make_event_link($event_id, $get_target = '', $caldate = '')
351
        {
352
            if ($caldate === '') {
353
                $caldate = $this->caldate;
354
            }
355
356
            $event = $GLOBALS['xoopsDB']->query("SELECT shortsummary, start FROM $this->table WHERE id=$event_id LIMIT 0,1");
357
358
            if ($event && $GLOBALS['xoopsDB']->getRowsNum($event)) {
359
                $event = $GLOBALS['xoopsDB']->fetchObject($event);
360
                $date  = date('j-n-Y', $event->start);
361
                $event = urlencode(urlencode($event->shortsummary));
362
            } else {
363
                $event = $event_id;
364
                $date  = $caldate !== '' ? date('j-n-Y', strtotime($caldate)) : date('j-n-Y');
365
            }
366
367
            if ($this->useurlrewrite) {
368
                return XOOPS_URL . "/modules/apcal/$event-$date";
369
            } else {
370
                return ($get_target === '' ? XOOPS_URL . '/modules/apcal/' : $get_target) . "?event_id=$event_id&action=View&caldate=$caldate";
371
            }
372
        }
373
374
        /**
375
         * @param $str
376
         * @return mixed
377
         */
378
        public function urlencode($str)
379
        {
380
            $str = urlencode($str);
381
382
            return str_replace(array('%26', '3D'), array('&', '='), $str);
383
        }
384
385
        /**
386
         * @param $str
387
         * @return mixed
388
         */
389
        public function makeShort($str)
390
        {
391
            $replacements = array(
392
                'Ä' => 'Ae',
393
                'Ü' => 'Ue',
394
                'Ö' => 'Oe',
395
                'ä' => 'ae',
396
                'ö' => 'oe',
397
                'ü' => 'ue',
398
                'ß' => 'sz',
399
                'Å ' => 'S',
400
                'Å¡' => 's',
401
                'Ž' => 'Z',
402
                'ž' => 'z',
403
                'À' => 'A',
404
                '�' => 'A',
405
                'Â' => 'A',
406
                'Ã' => 'A',
407
                'Ä' => 'A',
408
                'Ã…' => 'A',
409
                'Æ' => 'A',
410
                'Ç' => 'C',
411
                'È' => 'E',
412
                'É' => 'E',
413
                'Ê' => 'E',
414
                'Ë' => 'E',
415
                'Ì' => 'I',
416
                '�' => 'I',
417
                'ÃŽ' => 'I',
418
                '�' => 'I',
419
                'Ñ' => 'N',
420
                'Ã’' => 'O',
421
                'Ó' => 'O',
422
                'Ô' => 'O',
423
                'Õ' => 'O',
424
                'Ö' => 'O',
425
                'Ø' => 'O',
426
                'Ù' => 'U',
427
                'Ú' => 'U',
428
                'Û' => 'U',
429
                'Ü' => 'U',
430
                '�' => 'Y',
431
                'Þ' => 'B',
432
                'ß' => 'Ss',
433
                'à' => 'a',
434
                'á' => 'a',
435
                'â' => 'a',
436
                'ã' => 'a',
437
                'ä' => 'a',
438
                'Ã¥' => 'a',
439
                'æ' => 'a',
440
                'ç' => 'c',
441
                'è' => 'e',
442
                'é' => 'e',
443
                'ê' => 'e',
444
                'ë' => 'e',
445
                'ì' => 'i',
446
                'í' => 'i',
447
                'î' => 'i',
448
                'ï' => 'i',
449
                'ð' => 'o',
450
                'ñ' => 'n',
451
                'ò' => 'o',
452
                'ó' => 'o',
453
                'ô' => 'o',
454
                'õ' => 'o',
455
                'ö' => 'o',
456
                'ø' => 'o',
457
                'ù' => 'u',
458
                'ú' => 'u',
459
                'û' => 'u',
460
                'ý' => 'y',
461
                'ý' => 'y',
462
                'þ' => 'b',
463
                'ÿ' => 'y'
464
            );
465
466
            $str = utf8_encode(strtr($str, $replacements));
467
            $str = strip_tags($str);
468
469
            return str_replace(array(' ', '-', '/', "\\", "'", '"', "\r", "\n", '&', '?', '!', '%', ',', '.'), '', $str);
470
        }
471
472
        // APCal���ѥ?����ե�������ɤ߹���
473
        public function read_locale()
474
        {
475
            if (file_exists("$this->base_path/locales/{$this->locale}.php")) {
476
                include "$this->base_path/locales/{$this->locale}.php";
477
            }
478
        }
479
480
        // year,month,day,caldate,unixtime �򥻥åȤ���
481
482
        /**
483
         * @param $setdate
484
         */
485
        public function set_date($setdate)
486
        {
487
            if (!(preg_match("/^([0-9][0-9]+)[-.\/]?([0-1]?[0-9])[-.\/]?([0-3]?[0-9])$/", $setdate, $regs)
488
                  && checkdate($regs[2], $regs[3], $regs[1]))
489
            ) {
490
                preg_match('/^([0-9]{4})-([0-9]{2})-([0-9]{2})$/', date('Y-m-d'), $regs);
491
                $this->use_server_TZ = true;
492
            }
493
            $this->year     = $year = (int)$regs[1];
494
            $this->month    = $month = (int)$regs[2];
495
            $this->date     = $date = (int)$regs[3];
496
            $this->caldate  = "$year-$month-$date";
497
            $this->unixtime = mktime(0, 0, 0, $month, $date, $year);
498
499
            // ��������ե����פΥ��å�
500
            // �ĥ��顼�θ�
501
            if ($month <= 2) {
502
                $year--;
503
                $month += 12;
504
            }
505
            $day = ($year + floor($year / 4) - floor($year / 100) + floor($year / 400) + floor(2.6 * $month + 1.6) + $date) % 7;
506
507
            $this->day = $day;
508
            if ($day == 0) {
509
                $this->daytype = 2;
510
            } elseif ($day == 6) {
511
                $this->daytype = 1;
512
            } else {
513
                $this->daytype = 0;
514
            }
515
516
            if (isset($this->holidays[$this->caldate])) {
517
                $this->daytype = 3;
518
            }
519
        }
520
521
        // �������μ��फ���طʿ���ʸ�������
522
523
        /**
524
         * @param $daytype
525
         * @return array
526
         */
527
        public function daytype_to_colors($daytype)
528
        {
529
            switch ($daytype) {
530
                case 3:
531
                    //  Holiday
532
                    return array($this->holiday_bgcolor, $this->holiday_color);
533
                case 2:
534
                    //  Sunday
535
                    return array($this->sunday_bgcolor, $this->sunday_color);
536
                case 1:
537
                    //  Saturday
538
                    return array($this->saturday_bgcolor, $this->saturday_color);
539
                case 0:
540
                default:
541
                    // Weekday
542
                    return array($this->weekday_bgcolor, $this->weekday_color);
543
            }
544
        }
545
546
        // SQL���������դ��顢�������μ������륯�饹�ؿ�
547
548
        /**
549
         * @param $date
550
         * @return int
551
         */
552
        public function get_daytype($date)
553
        {
554
            preg_match("/^([0-9][0-9]+)[-.\/]?([0-1]?[0-9])[-.\/]?([0-3]?[0-9])$/", $date, $regs);
555
            $year  = (int)$regs[1];
556
            $month = (int)$regs[2];
557
            $date  = (int)$regs[3];
558
559
            // �����3
560
            if (isset($this->holidays["$year-$month-$date"])) {
561
                return 3;
562
            }
563
564
            // �ĥ��顼�θ�
565
            if ($month <= 2) {
566
                $year--;
567
                $month += 12;
568
            }
569
            $day = ($year + floor($year / 4) - floor($year / 100) + floor($year / 400) + floor(2.6 * $month + 1.6) + $date) % 7;
570
571
            if ($day == 0) {
572
                return 2;
573
            } elseif ($day == 6) {
574
                return 1;
575
            } else {
576
                return 0;
577
            }
578
        }
579
580
        /*******************************************************************/
581
        /*        �֥�å���ɽ���ؿ�                                       */
582
        /*******************************************************************/
583
584
        // $this->caldate���ͽ�� ���֤�
585
        /**
586
         * @param  string $get_target
587
         * @return string
588
         */
589
        public function get_date_schedule($get_target = '')
590
        {
591
            // if( $get_target == '' ) $get_target = $_SERVER['SCRIPT_NAME'] ;
592
593
            $ret = '';
594
595
            // ������׻����Ĥġ�WHERE��δ�֤˴ؤ���������
596
            $tzoffset = ($this->user_TZ - $this->server_TZ) * 3600;
597
            if ($tzoffset == 0) {
598
                // �������ʤ���� ��MySQL����٤򤫤������ʤ����ᡢ�����Ǿ��ʬ�����Ȥ�)
599
                $whr_term = "start<'" . ($this->unixtime + 86400) . "' AND end>'$this->unixtime'";
600
            } else {
601
                // ������������ϡ�allday�ˤ�äƾ��ʬ��
602
                $whr_term = "( allday AND start<='$this->unixtime' AND end>'$this->unixtime') || ( ! allday AND start<'" . ($this->unixtime + 86400 - $tzoffset) . "' AND end>'" . ($this->unixtime
603
                                                                                                                                                                                    - $tzoffset) . "')";
604
            }
605
606
            // ���ƥ��꡼��Ϣ��WHERE������
607
            $whr_categories = $this->get_where_about_categories();
608
609
            // CLASS��Ϣ��WHERE������
610
            $whr_class = $this->get_where_about_class();
611
612
            // ����Υ������塼�����
613
            $yrs      = $GLOBALS['xoopsDB']->query("SELECT start,end,summary,id,allday FROM $this->table WHERE admission>0 AND ($whr_term) AND ($whr_categories) AND ($whr_class) ORDER BY start,end");
614
            $num_rows = $GLOBALS['xoopsDB']->getRowsNum($yrs);
615
616
            if ($num_rows == 0) {
617
                $ret .= _APCAL_MB_NOEVENT . "\n";
618
            } else {
619
                while ($event = $GLOBALS['xoopsDB']->fetchObject($yrs)) {
620
                    $summary = $this->text_sanitizer_for_show($event->summary);
621
622
                    if ($event->allday) {
623
                        // ����٥��
624
                        $ret .= "
625
           <table border='0' cellpadding='0' cellspacing='0' width='100%'>
626
             <tr>
627
               <td><img border='0' src='$this->images_url/dot_allday.gif' /> &nbsp; </td>
628
               <td><span style='font-size: x-small; '><a href='$get_target?cid=$this->now_cid&amp;smode=Daily&amp;action=View&amp;event_id=$event->id&amp;caldate=$this->caldate' class='calsummary_allday'>$summary</a></span></td>
629
             </tr>
630
           </table>\n";
631
                    } else {
632
                        // �̾磻�٥��
633
                        $event->start += $tzoffset;
634
                        $event->end   += $tzoffset;
635
                        $ret          .= "
636
           <dl>
637
             <dt>
638
               <span style='font-size: x-small; '>" . $this->get_todays_time_description($event->start, $event->end, $this->caldate, false, true) . "</span>
639
             </dt>
640
             <dd>
641
               <span style='font-size: x-small; '><a href='$get_target?cid=$this->now_cid&amp;smode=Daily&amp;action=View&amp;event_id=$event->id&amp;caldate=$this->caldate' class='calsummary'>$summary</a></span>
642
             </dd>
643
           </dl>\n";
644
                    }
645
                }
646
            }
647
648
            // ͽ����ɲáʱ�ɮ���������
649 View Code Duplication
            if ($this->insertable) {
0 ignored issues
show
Duplication introduced by
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...
650
                $ret .= "
651
           <dl>
652
             <dt>
653
               &nbsp; <span style='font-size: x-small; '><a href='$get_target?smode=Daily&amp;action=Edit&amp;caldate=$this->caldate'><img src='$this->images_url/addevent.gif' border='0' width='14' height='12' />"
654
                        . _APCAL_MB_ADDEVENT
655
                        . "</a></span>
656
             </dt>
657
           </dl>\n";
658
            }
659
660
            return $ret;
661
        }
662
663
        // $this->caldate�ʹߤ�ͽ�� ����� $num ���֤�
664
665
        /**
666
         * @param  string $get_target
667
         * @param  int    $num
668
         * @return string
669
         */
670
        public function get_coming_schedule($get_target = '', $num = 5)
671
        {
672
            // if( $get_target == '' ) $get_target = $_SERVER['SCRIPT_NAME'] ;
673
674
            $ret = '';
675
676
            // ������׻����Ĥġ�WHERE��δ�֤˴ؤ���������
677
            $tzoffset = ($this->user_TZ - $this->server_TZ) * 3600;
678
            if ($tzoffset == 0) {
679
                // �������ʤ���� ��MySQL����٤򤫤������ʤ����ᡢ�����Ǿ��ʬ�����Ȥ�)
680
                $whr_term = "end>'$this->unixtime'";
681
            } else {
682
                // ������������ϡ�allday�ˤ�äƾ��ʬ��
683
                $whr_term = "(allday AND end>'$this->unixtime') || ( ! allday AND end>'" . ($this->unixtime - $tzoffset) . "')";
684
            }
685
686
            // ���ƥ��꡼��Ϣ��WHERE������
687
            $whr_categories = $this->get_where_about_categories();
688
689
            // CLASS��Ϣ��WHERE������
690
            $whr_class = $this->get_where_about_class();
691
692
            // ����ʹߤΥ������塼�����
693
            $yrs      = $GLOBALS['xoopsDB']->query("SELECT start,end,summary,id,allday FROM $this->table WHERE admission>0 AND ($whr_term) AND ($whr_categories) AND ($whr_class) ORDER BY start");
694
            $num_rows = $GLOBALS['xoopsDB']->getRowsNum($yrs);
695
696
            if ($num_rows == 0) {
697
                $ret .= _APCAL_MB_NOEVENT . "\n";
698
            } else {
699
                for ($i = 0; $i < $num; ++$i) {
700
                    $event = $GLOBALS['xoopsDB']->fetchObject($yrs);
701
                    if ($event === false) {
702
                        break;
703
                    }
704
                    $summary = $this->text_sanitizer_for_show($event->summary);
705
706
                    if ($event->allday) {
707
                        // ����٥��
708
                        $ret .= "
709
           <dl>
710
             <dt>
711
               <span style='font-size: x-small; '><img border='0' src='$this->images_url/dot_allday.gif' /> " . $this->get_middle_md($event->start) . "</span>
712
             </dt>
713
             <dd>
714
               <span style='font-size: x-small; '><a href='$get_target?cid=$this->now_cid&amp;smode=Daily&amp;action=View&amp;event_id=$event->id&amp;caldate=$this->caldate' class='calsummary_allday'>$summary</a></span>
715
             </dd>
716
           </dl>\n";
717
                    } else {
718
                        // �̾磻�٥��
719
                        $event->start += $tzoffset;
720
                        $event->end   += $tzoffset;
721
                        $ret          .= "
722
           <dl>
723
             <dt>
724
               <span style='font-size: x-small; '>" . $this->get_coming_time_description($event->start, $this->unixtime) . "</span>
725
             </dt>
726
             <dd>
727
               <span style='font-size: x-small; '><a href='$get_target?cid=$this->now_cid&amp;smode=Daily&amp;action=View&amp;event_id=$event->id&amp;caldate=$this->caldate' class='calsummary'>$summary</a></span>
728
             </dd>
729
           </dl>\n";
730
                    }
731
                }
732
            }
733
734
            // �Ĥ�����ɽ��
735
            if ($num_rows > $num) {
736
                $ret .= "
737
           <table border='0' cellspacing='0' cellpadding='0' width='100%'>
738
            <tr>
739
             <td align='right'><small>" . _APCAL_MB_RESTEVENT_PRE . ($num_rows - $num) . _APCAL_MB_RESTEVENT_SUF . "</small></td>
740
            </tr>
741
           </table>\n";
742
            }
743
744
            // ͽ����ɲáʱ�ɮ���������
745 View Code Duplication
            if ($this->insertable) {
0 ignored issues
show
Duplication introduced by
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...
746
                $ret .= "
747
           <dl>
748
             <dt>
749
               &nbsp; <span style='font-size: x-small; '><a href='$get_target?smode=Daily&amp;action=Edit&amp;caldate=$this->caldate'><img src='$this->images_url/addevent.gif' border='0' width='14' height='12' />"
750
                        . _APCAL_MB_ADDEVENT
751
                        . "</a></span>
752
             </dt>
753
           </dl>\n";
754
            }
755
756
            return $ret;
757
        }
758
759
        // �ߥ˥��������ѥ��٥�ȼ����ؿ�
760
761
        /**
762
         * @param         $range_start_s
763
         * @param         $range_end_s
764
         * @param  string $mode
765
         * @return mixed
766
         */
767
        public function get_flags_date_has_events($range_start_s, $range_end_s, $mode = '')
768
        {
769
            // ���餫����������������Ƥ���
770
            /* for ($time = $start ; $time < $end ; $time += 86400) {
771
        $ret[ date( 'j' , $time ) ] = 0 ;
772
    } */
773
            for ($i = 0; $i <= 31; ++$i) {
774
                $ret[$i] = 0;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$ret was never initialized. Although not strictly required by PHP, it is generally a good practice to add $ret = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
775
            }
776
777
            // add margin -86400 and +86400
778
            $range_start_s -= 86400;
779
            $range_end_s   += 86400;
780
781
            // �����׻�
782
            $tzoffset_s2u = (int)(($this->user_TZ - $this->server_TZ) * 3600);
783
            //$gmtoffset = (int)( $this->server_TZ * 3600 ) ;
784
785
            // ���ƥ��꡼��Ϣ��WHERE������
786
            $whr_categories = $this->get_where_about_categories();
787
788
            // CLASS��Ϣ��WHERE������
789
            $whr_class = $this->get_where_about_class();
790
791
            /*  $yrs = mysqli_query( "SELECT start,end,allday FROM $this->table WHERE admission > 0 AND start < ".($end + 86400)." AND end > ".($start - 86400)." AND ($whr_categories) AND ($whr_class)" , $this->conn ) ;
792
    while ( $event = $xoopsDB->fetchObject( $yrs ) ) {
793
        $time = $event->start > $start ? $event->start : $start ;
794
        if (! $event->allday) {
795
            $time += $tzoffset ;
796
            $event->end += $tzoffset ;
797
        }
798
        $time -= ( $time + $gmtoffset ) % 86400 ;
799
        while ($time < $end && $time < $event->end) {
800
            $ret[ date( 'j' , $time ) ] = 1 ;
801
            $time += 86400 ;
802
        }
803
    }*/
804
805
            // ����٥�Ȱʳ��ν���
806
            $result = $GLOBALS['xoopsDB']->query("SELECT summary,id,start,location,contact,gmlat,gmlong FROM $this->table WHERE admission > 0 AND start >= $range_start_s AND start < $range_end_s AND ($whr_categories) AND ($whr_class) AND allday <= 0");
807
            while (list($title, $id, $server_time, $location, $contact, $gmlat, $gmlong) = $GLOBALS['xoopsDB']->fetchRow($result)) {
808 View Code Duplication
                if ($mode === 'NO_YEAR' && ($gmlat > 0 || $gmlong > 0)) {
0 ignored issues
show
Duplication introduced by
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...
809
                    $this->gmPoints[] = array(
810
                        'summary'   => $title,
811
                        'gmlat'     => $gmlat,
812
                        'gmlong'    => $gmlong,
813
                        'location'  => $location,
814
                        'contact'   => $contact,
815
                        'startDate' => date('j', $server_time),
816
                        'event_id'  => $id
817
                    );
818
                }
819
                $user_time = $server_time + $tzoffset_s2u;
820
                if (date('n', $user_time) != $this->month) {
821
                    continue;
822
                }
823
                $ret[date('j', $user_time)] = 1;
0 ignored issues
show
Bug introduced by
The variable $ret does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
824
            }
825
826
            // ����٥�����Ѥν���
827
            $result = $GLOBALS['xoopsDB']->query("SELECT summary,id,start,end,location,contact,gmlat,gmlong FROM $this->table WHERE admission > 0 AND start >= $range_start_s AND start < $range_end_s AND ($whr_categories) AND ($whr_class) AND allday > 0");
828
829
            while (list($title, $id, $start_s, $end_s, $location, $contact, $gmlat, $gmlong) = $GLOBALS['xoopsDB']->fetchRow($result)) {
830
                if ($start_s < $range_start_s) {
831
                    $start_s = $range_start_s;
832
                }
833
                if ($end_s > $range_end_s) {
834
                    $end_s = $range_end_s;
835
                }
836
837
                while ($start_s < $end_s) {
838
                    $user_time = $start_s + $tzoffset_s2u;
839
                    if (date('n', $user_time) == $this->month) {
840 View Code Duplication
                        if ($mode === 'NO_YEAR' && ($gmlat > 0 || $gmlong > 0)) {
0 ignored issues
show
Duplication introduced by
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...
841
                            $this->gmPoints[] = array(
842
                                'summary'   => $title,
843
                                'gmlat'     => $gmlat,
844
                                'gmlong'    => $gmlong,
845
                                'location'  => $location,
846
                                'contact'   => $contact,
847
                                'startDate' => date('j', $user_time),
848
                                'event_id'  => $id
849
                            );
850
                        }
851
                        $ret[date('j', $user_time)] = 1;
852
                    }
853
                    $start_s += 86400;
854
                }
855
            }
856
857
            return $ret;
858
        }
859
860
        // �ߥ˥�������ɽ����ʸ������֤�
861
862
        /**
863
         * @param  string $get_target
864
         * @param  string $query_string
865
         * @param  string $mode
866
         * @return string
867
         */
868
        public function get_mini_calendar_html($get_target = '', $query_string = '', $mode = '')
869
        {
870
            // �¹Ի��ַ�¬��������
871
            // list( $usec , $sec ) = explode( " " , microtime() ) ;
872
            // $apcalstarttime = $sec + $usec ;
873
874
            // $PHP_SELF = $_SERVER['SCRIPT_NAME'] ;
875
            // if( $get_target == '' ) $get_target = $PHP_SELF ;
876
877
            require_once "$this->base_path/include/patTemplate.php";
878
            $tmpl = new PatTemplate();
879
            $tmpl->setBasedir("$this->images_path");
880
881
            // ɽ���⡼�ɤ˱����ơ��ƥ�ץ졼�ȥե�����򿶤�ʬ��
882
            switch ($mode) {
883
                case 'NO_YEAR':
884
                    // ǯ��ɽ����
885
                    $tmpl->readTemplatesFromFile('minical_for_yearly.tmpl.html');
886
                    $target_highlight_flag = false;
887
                    break;
888
                case 'NO_NAVIGATE':
889
                    // ��֤β���������
890
                    $tmpl->readTemplatesFromFile('minical_for_monthly.tmpl.html');
891
                    $target_highlight_flag = false;
892
                    break;
893
                default:
894
                    // �̾�Υߥ˥��������֥�å���
895
                    $tmpl->readTemplatesFromFile('minical.tmpl.html');
896
                    $target_highlight_flag = true;
897
                    break;
898
            }
899
900
            // ����γ���٥�Ȥ��äƤ��뤫�ɤ��������
901
            $event_dates = $this->get_flags_date_has_events(mktime(0, 0, 0, $this->month, 1, $this->year), mktime(0, 0, 0, $this->month + 1, 1, $this->year), $mode);
902
903
            // ����Ϸ��������Ϸ��Ȥ���
904
            $prev_month = date('Y-n-j', mktime(0, 0, 0, $this->month, 0, $this->year));
905
            $next_month = date('Y-n-j', mktime(0, 0, 0, $this->month + 1, 1, $this->year));
906
907
            // $tmpl->addVar( "WholeBoard" , "PHP_SELF" , '' ) ;
908
            $tmpl->addVar('WholeBoard', 'DAY_URL', substr($this->make_cal_link($get_target, 'Monthly', $this->now_cid, ' '), 0, -1));
909
            $tmpl->addVar('WholeBoard', 'GET_TARGET', $get_target);
910
            $tmpl->addVar('WholeBoard', 'QUERY_STRING', $query_string);
911
912
            $tmpl->addVar('WholeBoard', 'MB_PREV_MONTH', _APCAL_MB_PREV_MONTH);
913
            $tmpl->addVar('WholeBoard', 'MB_NEXT_MONTH', _APCAL_MB_NEXT_MONTH);
914
            $tmpl->addVar('WholeBoard', 'MB_LINKTODAY', _APCAL_MB_LINKTODAY);
915
916
            $tmpl->addVar('WholeBoard', 'SKINPATH', $this->images_url);
917
            $tmpl->addVar('WholeBoard', 'FRAME_CSS', $this->frame_css);
918
            //  $tmpl->addVar( "WholeBoard" , "YEAR" , $this->year ) ;
919
            //  $tmpl->addVar( "WholeBoard" , "MONTH" , $this->month ) ;
920
            $tmpl->addVar('WholeBoard', 'MONTH_NAME', $this->month_middle_names[$this->month]);
921
            $tmpl->addVar('WholeBoard', 'YEAR_MONTH_TITLE', sprintf(_APCAL_FMT_YEAR_MONTH, $this->year, $this->month_middle_names[$this->month]));
922
            $tmpl->addVar('WholeBoard', 'PREV_MONTH', $prev_month);
923
            $tmpl->addVar('WholeBoard', 'NEXT_MONTH', $next_month);
924
925
            $tmpl->addVar('WholeBoard', 'CALHEAD_BGCOLOR', $this->calhead_bgcolor);
926
            $tmpl->addVar('WholeBoard', 'CALHEAD_COLOR', $this->calhead_color);
927
928
            $first_date = getdate(mktime(0, 0, 0, $this->month, 1, $this->year));
929
            $date       = (-$first_date['wday'] + $this->week_start - 7) % 7;
930
            $wday_end   = 7 + $this->week_start;
931
932
            // ����̾�롼��
933
            $rows = array();
934 View Code Duplication
            for ($wday = $this->week_start; $wday < $wday_end; ++$wday) {
0 ignored issues
show
Duplication introduced by
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...
935
                if ($wday % 7 == 0) {
936
                    //  Sunday
937
                    $bgcolor = $this->sunday_bgcolor;
938
                    $color   = $this->sunday_color;
939
                } elseif ($wday == 6) {
940
                    //  Saturday
941
                    $bgcolor = $this->saturday_bgcolor;
942
                    $color   = $this->saturday_color;
943
                } else {
944
                    // Weekday
945
                    $bgcolor = $this->weekday_bgcolor;
946
                    $color   = $this->weekday_color;
947
                }
948
949
                // �ƥ�ץ졼��������ؤΥǡ������å�
950
                array_push($rows, array(
951
                    'BGCOLOR' => $bgcolor,
952
                    'COLOR'   => $color,
953
                    'DAYNAME' => $this->week_short_names[$wday % 7]
954
                ));
955
            }
956
957
            // �ƥ�ץ졼�Ȥ˥ǡ�����������
958
            $tmpl->addRows('DayNameLoop', $rows);
959
            $tmpl->parseTemplate('DayNameLoop', 'w');
960
961
            // �� (row) �롼��
962
            for ($week = 0; $week < 6; ++$week) {
963
                $rows = array();
964
965
                // �� (col) �롼��
966
                for ($wday = $this->week_start; $wday < $wday_end; ++$wday) {
967
                    ++$date;
968
                    if (!checkdate($this->month, $date, $this->year)) {
969
                        // ����ϰϳ�
970
                        array_push($rows, array(
971
                            'GET_TARGET'   => $get_target,
972
                            'QUERY_STRING' => $query_string,
973
                            'SKINPATH'     => $this->images_url,
974
                            'DATE'         => date('j', mktime(0, 0, 0, $this->month, $date, $this->year)),
975
                            'DATE_TYPE'    => 0
976
                        ));
977
                        continue;
978
                    }
979
980
                    $link = "$this->year-$this->month-$date";
981
982
                    // ����פˤ�����迧����ʬ��
983 View Code Duplication
                    if (isset($this->holidays[$link])) {
0 ignored issues
show
Duplication introduced by
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...
984
                        //  Holiday
985
                        $bgcolor = $this->holiday_bgcolor;
986
                        $color   = $this->holiday_color;
987
                    } elseif ($wday % 7 == 0) {
988
                        //  Sunday
989
                        $bgcolor = $this->sunday_bgcolor;
990
                        $color   = $this->sunday_color;
991
                    } elseif ($wday == 6) {
992
                        //  Saturday
993
                        $bgcolor = $this->saturday_bgcolor;
994
                        $color   = $this->saturday_color;
995
                    } else {
996
                        // Weekday
997
                        $bgcolor = $this->weekday_bgcolor;
998
                        $color   = $this->weekday_color;
999
                    }
1000
1001
                    // ��������طʿ��ϥ��饤�Ƚ���
1002
                    if ($date == $this->date && $target_highlight_flag) {
1003
                        $bgcolor = $this->targetday_bgcolor;
1004
                    }
1005
1006
                    // �ƥ�ץ졼��������ؤΥǡ������å�
1007
                    array_push($rows, array(
1008
                        'GET_TARGET'   => $get_target,
1009
                        'QUERY_STRING' => $query_string,
1010
                        'DAY_URL'      => substr($this->make_cal_link($get_target, ($mode === 'NO_YEAR' ? 'Daily' : 'Monthly'), $this->now_cid, ' '), 0, -1),
1011
1012
                        'BGCOLOR'   => $bgcolor,
1013
                        'COLOR'     => $color,
1014
                        'LINK'      => $link,
1015
                        'DATE'      => $date,
1016
                        'DATE_TYPE' => $event_dates[$date] + 1
1017
                    ));
1018
                }
1019
                // �ƥ�ץ졼�Ȥ˥ǡ�����������
1020
                $tmpl->addRows('DailyLoop', $rows);
1021
                $tmpl->parseTemplate('DailyLoop', 'w');
1022
                $tmpl->parseTemplate('WeekLoop', 'a');
1023
            }
1024
1025
            $ret = $tmpl->getParsedTemplate();
1026
1027
            // �¹Ի��ֵ�Ͽ
1028
            // list( $usec , $sec ) = explode( " " , microtime() ) ;
1029
            // error_log( "MiniCalendar " . ( $sec + $usec - $apcalstarttime ) . "sec." , 0 ) ;
1030
            return $ret;
1031
        }
1032
1033
        /*******************************************************************/
1034
        /*        �ᥤ����ɽ���ؿ�                                         */
1035
        /*******************************************************************/
1036
1037
        // ǯ�֥����������Τ�ɽ����patTemplate����)
1038
        /**
1039
         * @param  string $get_target
1040
         * @param  string $query_string
1041
         * @param  bool   $for_print
1042
         * @return string
1043
         */
1044
        public function get_yearly($get_target = '', $query_string = '', $for_print = false)
1045
        {
1046
            // $PHP_SELF = $_SERVER['SCRIPT_NAME'] ;
1047
            // if( $get_target == '' ) $get_target = $PHP_SELF ;
1048
1049
            require_once "$this->base_path/include/patTemplate.php";
1050
            $tmpl = new PatTemplate();
1051
            $tmpl->readTemplatesFromFile("$this->images_path/yearly.tmpl.html");
1052
1053
            // setting skin folder
1054
            $tmpl->addVar('WholeBoard', 'SKINPATH', $this->images_url);
1055
1056
            // Static parameter for the request
1057
            $tmpl->addVar('WholeBoard', 'GET_TARGET', $get_target);
1058
            $tmpl->addVar('WholeBoard', 'QUERY_STRING', $query_string);
1059
            $tmpl->addVar('WholeBoard', 'PRINT_LINK', "$this->base_url/print.php?cid=$this->now_cid&amp;smode=Yearly&amp;caldate=$this->caldate");
1060
            $tmpl->addVar('WholeBoard', 'LANG_PRINT', _APCAL_BTN_PRINT);
1061
            if ($for_print) {
1062
                $tmpl->addVar('WholeBoard', 'PRINT_ATTRIB', "width='0' height='0'");
1063
            }
1064
1065
            $jumpScript = "<script type='text/javascript'>\n";
1066
            $jumpScript .= "function submitCat(cid, smode, caldate)\n";
1067
            $jumpScript .= "{\n";
1068
            if ($this->useurlrewrite) {
1069
                $jumpScript .= "document.selectDate.action = '" . XOOPS_URL . "/' + cid + '/' + smode + '/' + caldate;\n";
1070
                $jumpScript .= "document.selectDate.method = 'POST';\n";
1071
            }
1072
            $jumpScript .= "return true;\n";
1073
            $jumpScript .= "}\n";
1074
            $jumpScript .= "</script>\n";
1075
1076
            $prevYear = date('Y-n-j', mktime(0, 0, 0, $this->month, $this->date, $this->year - 1));
1077
            $nextYear = date('Y-n-j', mktime(0, 0, 0, $this->month, $this->date, $this->year + 1));
1078
            $tmpl->addVar('WholeBoard', 'JUMPLINK', $this->make_cal_link($get_target, 'Yearly', $this->now_cid, date('Y-n-j')));
1079
            $tmpl->addVar('WholeBoard', 'TODAYLINK', $this->make_cal_link($get_target, 'Yearly', $this->now_cid, date('Y-n-j')));
1080
            $tmpl->addVar('WholeBoard', 'PREVIOUSYEARLINK', $this->make_cal_link($get_target, 'Yearly', $this->now_cid, $prevYear));
1081
            $tmpl->addVar('WholeBoard', 'NEXTYEARLINK', $this->make_cal_link($get_target, 'Yearly', $this->now_cid, $nextYear));
1082
            $tmpl->addVar('WholeBoard', 'MONTHLYVIEW', $this->make_cal_link($get_target, 'Monthly', $this->now_cid, $this->caldate));
1083
            $tmpl->addVar('WholeBoard', 'WEEKLYVIEW', $this->make_cal_link($get_target, 'Weekly', $this->now_cid, $this->caldate));
1084
            $tmpl->addVar('WholeBoard', 'DAILYVIEW', $this->make_cal_link($get_target, 'Daily', $this->now_cid, $this->caldate));
1085
            $tmpl->addVar('WholeBoard', 'LISTVIEW', $this->make_cal_link($get_target, 'List', $this->now_cid, $this->caldate));
1086
1087
            // ���ƥ��꡼����ܥå���
1088
            $tmpl->addVar('WholeBoard', 'CATEGORIES_SELFORM', $this->get_categories_selform($get_target));
1089
            $tmpl->addVar('WholeBoard', 'CID', $this->now_cid);
1090
1091
            // Variables required in header part etc.
1092
            $tmpl->addVars('WholeBoard', $this->get_calendar_information('Y'));
1093
1094
            $tmpl->addVar('WholeBoard', 'LANG_JUMP', _APCAL_BTN_JUMP);
1095
1096
            // �Ʒ�Υߥ˥�������
1097
            // $this->caldate �ΥХå����å�
1098
            $backuped_caldate = $this->caldate;
1099
1100
            // 12����ʬ�Υߥ˥������������롼��
1101
            for ($m = 1; $m <= 12; ++$m) {
1102
                $this->set_date(date('Y-n-j', mktime(0, 0, 0, $m, 1, $this->year)));
1103
                $tmpl->addVar('WholeBoard', "MINICAL$m", $this->get_mini_calendar_html($get_target, $query_string, 'NO_YEAR'));
1104
            }
1105
1106
            // $this->caldate �Υꥹ�ȥ�
1107
            $this->set_date($backuped_caldate);
1108
1109
            // content generated from PatTemplate
1110
            $ret = $tmpl->getParsedTemplate('WholeBoard');
1111
1112
            return $ret;
1113
        }
1114
1115
        // ��֥����������Τ�ɽ����patTemplate����)
1116
1117
        /**
1118
         * @param  string $get_target
1119
         * @param  string $query_string
1120
         * @param  bool   $for_print
1121
         * @return string
1122
         */
1123
        public function get_monthly($get_target = '', $query_string = '', $for_print = false)
1124
        {
1125
            // $PHP_SELF = $_SERVER['SCRIPT_NAME'] ;
1126
            // if( $get_target == '' ) $get_target = $PHP_SELF ;
1127
1128
            if (isset($_POST['startDate'])) {
1129
                $date          = explode('-', $_POST['startDate']);
1130
                $this->year    = $date[0];
1131
                $this->month   = $date[1];
1132
                $this->day     = $date[2];
1133
                $this->caldate = $_POST['startDate'];
1134
            }
1135
1136
            require_once "$this->base_path/include/patTemplate.php";
1137
            $tmpl = new PatTemplate();
1138
            $tmpl->readTemplatesFromFile("$this->images_path/monthly.tmpl.html");
1139
1140
            // setting skin folder
1141
            $tmpl->addVar('WholeBoard', 'SKINPATH', $this->images_url);
1142
1143
            // Static parameter for the request
1144
            $tmpl->addVar('WholeBoard', 'GET_TARGET', $get_target);
1145
            $tmpl->addVar('WholeBoard', 'QUERY_STRING', $query_string);
1146
            $tmpl->addVar('WholeBoard', 'YEAR_MONTH_TITLE', sprintf(_APCAL_FMT_YEAR_MONTH, $this->year, $this->month_middle_names[$this->month]));
1147
            $tmpl->addVar('WholeBoard', 'PRINT_LINK', "$this->base_url/print.php?cid=$this->now_cid&amp;smode=Monthly&amp;caldate=$this->caldate");
1148
            $tmpl->addVar('WholeBoard', 'LANG_PRINT', _APCAL_BTN_PRINT);
1149
            if ($for_print) {
1150
                $tmpl->addVar('WholeBoard', 'PRINT_ATTRIB', "width='0' height='0'");
1151
            }
1152
1153
            $prevYear  = date('Y-n-j', mktime(0, 0, 0, $this->month, $this->date, $this->year - 1));
1154
            $nextYear  = date('Y-n-j', mktime(0, 0, 0, $this->month, $this->date, $this->year + 1));
1155
            $prevMonth = date('Y-n-j', mktime(0, 0, 0, $this->month, 0, $this->year));
1156
            $nextMonth = date('Y-n-j', mktime(0, 0, 0, $this->month + 1, 1, $this->year));
1157
            $tmpl->addVar('WholeBoard', 'TODAYLINK', $this->make_cal_link($get_target, 'Monthly', $this->now_cid, date('Y-n-j')));
1158
            $tmpl->addVar('WholeBoard', 'PREVIOUSYEARLINK', $this->make_cal_link($get_target, 'Monthly', $this->now_cid, $prevYear));
1159
            $tmpl->addVar('WholeBoard', 'PREVIOUSMONTHLINK', $this->make_cal_link($get_target, 'Monthly', $this->now_cid, $prevMonth));
1160
            $tmpl->addVar('WholeBoard', 'NEXTYEARLINK', $this->make_cal_link($get_target, 'Monthly', $this->now_cid, $nextYear));
1161
            $tmpl->addVar('WholeBoard', 'NEXTMONTHLINK', $this->make_cal_link($get_target, 'Monthly', $this->now_cid, $nextMonth));
1162
            $tmpl->addVar('WholeBoard', 'YEARLYVIEW', $this->make_cal_link($get_target, 'Yearly', $this->now_cid, $this->caldate));
1163
            $tmpl->addVar('WholeBoard', 'WEEKLYVIEW', $this->make_cal_link($get_target, 'Weekly', $this->now_cid, $this->caldate));
1164
            $tmpl->addVar('WholeBoard', 'DAILYVIEW', $this->make_cal_link($get_target, 'Daily', $this->now_cid, $this->caldate));
1165
            $tmpl->addVar('WholeBoard', 'LISTVIEW', $this->make_cal_link($get_target, 'List', $this->now_cid, $this->caldate));
1166
1167
            // ���ƥ��꡼����ܥå���
1168
            $tmpl->addVar('WholeBoard', 'CATEGORIES_SELFORM', $this->get_categories_selform($get_target));
1169
            $tmpl->addVar('WholeBoard', 'CID', $this->now_cid);
1170
1171
            // Variables required in header part etc.
1172
            $tmpl->addVars('WholeBoard', $this->get_calendar_information('M'));
1173
1174
            $tmpl->addVar('WholeBoard', 'LANG_JUMP', _APCAL_BTN_JUMP);
1175
1176
            // BODY of the calendar
1177
            $tmpl->addVar('WholeBoard', 'CALENDAR_BODY', $this->get_monthly_html($get_target, $query_string, $for_print));
1178
1179
            // legends of long events
1180 View Code Duplication
            foreach ($this->long_event_legends as $bit => $legend) {
0 ignored issues
show
Duplication introduced by
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...
1181
                $tmpl->addVar('LongEventLegends', 'BIT_MASK', 1 << ($bit - 1));
1182
                $tmpl->addVar('LongEventLegends', 'LEGEND_ALT', _APCAL_MB_ALLDAY_EVENT . " $bit");
1183
                $tmpl->addVar('LongEventLegends', 'LEGEND', $legend);
1184
                $tmpl->addVar('LongEventLegends', 'SKINPATH', $this->images_url);
1185
                $tmpl->parseTemplate('LongEventLegends', 'a');
1186
            }
1187
1188
            // �����Υߥ˥�������
1189
            // $this->caldate �ΥХå����å�
1190
            $backuped_caldate = $this->caldate;
1191
            // �����������դ򥻥åȤ�������Υߥ˥��������򥻥å�
1192
            $this->set_date(date('Y-n-j', mktime(0, 0, 0, $this->month, 0, $this->year)));
1193
            $tmpl->addVar('WholeBoard', 'PREV_MINICAL', $this->get_mini_calendar_html($get_target, $query_string, 'NO_NAVIGATE'));
1194
            // ���Ϥ����դ򥻥åȤ����ߥ˥���������ɽ��
1195
            $this->set_date(date('Y-n-j', mktime(0, 0, 0, $this->month + 2, 1, $this->year)));
1196
            $tmpl->addVar('WholeBoard', 'NEXT_MINICAL', $this->get_mini_calendar_html($get_target, $query_string, 'NO_NAVIGATE'));
1197
            // $this->caldate �Υꥹ�ȥ�
1198
            $this->set_date($backuped_caldate);
1199
1200
            // content generated from PatTemplate
1201
            $ret = $tmpl->getParsedTemplate('WholeBoard');
1202
1203
            return $ret;
1204
        }
1205
1206
        // ���֥����������Τ�ɽ����patTemplate����)
1207
1208
        /**
1209
         * @param  string $get_target
1210
         * @param  string $query_string
1211
         * @param  bool   $for_print
1212
         * @return string
1213
         */
1214 View Code Duplication
        public function get_weekly($get_target = '', $query_string = '', $for_print = false)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
1215
        {
1216
            // $PHP_SELF = $_SERVER['SCRIPT_NAME'] ;
1217
            // if( $get_target == '' ) $get_target = $PHP_SELF ;
1218
1219
            require_once "$this->base_path/include/patTemplate.php";
1220
            $tmpl = new PatTemplate();
1221
            $tmpl->readTemplatesFromFile("$this->images_path/weekly.tmpl.html");
1222
1223
            // setting skin folder
1224
            $tmpl->addVar('WholeBoard', 'SKINPATH', $this->images_url);
1225
1226
            // Static parameter for the request
1227
            $tmpl->addVar('WholeBoard', 'GET_TARGET', $get_target);
1228
            $tmpl->addVar('WholeBoard', 'QUERY_STRING', $query_string);
1229
            $tmpl->addVar('WholeBoard', 'PRINT_LINK', "$this->base_url/print.php?cid=$this->now_cid&amp;smode=Weekly&amp;caldate=$this->caldate");
1230
            $tmpl->addVar('WholeBoard', 'LANG_PRINT', _APCAL_BTN_PRINT);
1231
            if ($for_print) {
1232
                $tmpl->addVar('WholeBoard', 'PRINT_ATTRIB', "width='0' height='0'");
1233
            }
1234
1235
            $prevMonth = date('Y-n-j', mktime(0, 0, 0, $this->month, 0, $this->year));
1236
            $nextMonth = date('Y-n-j', mktime(0, 0, 0, $this->month + 1, 1, $this->year));
1237
            $prevWeek  = date('Y-n-j', mktime(0, 0, 0, $this->month, $this->date - 7, $this->year));
1238
            $nextWeek  = date('Y-n-j', mktime(0, 0, 0, $this->month, $this->date + 7, $this->year));
1239
            $tmpl->addVar('WholeBoard', 'TODAYLINK', $this->make_cal_link($get_target, 'Weekly', $this->now_cid, date('Y-n-j')));
1240
            $tmpl->addVar('WholeBoard', 'PREVIOUSMONTHLINK', $this->make_cal_link($get_target, 'Weekly', $this->now_cid, $prevMonth));
1241
            $tmpl->addVar('WholeBoard', 'PREVIOUSWEEKLINK', $this->make_cal_link($get_target, 'Weekly', $this->now_cid, $prevWeek));
1242
            $tmpl->addVar('WholeBoard', 'NEXTWEEKLINK', $this->make_cal_link($get_target, 'Weekly', $this->now_cid, $nextWeek));
1243
            $tmpl->addVar('WholeBoard', 'NEXTMONTHLINK', $this->make_cal_link($get_target, 'Weekly', $this->now_cid, $nextMonth));
1244
            $tmpl->addVar('WholeBoard', 'YEARLYVIEW', $this->make_cal_link($get_target, 'Yearly', $this->now_cid, $this->caldate));
1245
            $tmpl->addVar('WholeBoard', 'MONTHLYVIEW', $this->make_cal_link($get_target, 'Monthly', $this->now_cid, $this->caldate));
1246
            $tmpl->addVar('WholeBoard', 'DAILYVIEW', $this->make_cal_link($get_target, 'Daily', $this->now_cid, $this->caldate));
1247
            $tmpl->addVar('WholeBoard', 'LISTVIEW', $this->make_cal_link($get_target, 'List', $this->now_cid, $this->caldate));
1248
1249
            // ���ƥ��꡼����ܥå���
1250
            $tmpl->addVar('WholeBoard', 'CATEGORIES_SELFORM', $this->get_categories_selform($get_target));
1251
            $tmpl->addVar('WholeBoard', 'CID', $this->now_cid);
1252
1253
            // Variables required in header part etc.
1254
            $tmpl->addVars('WholeBoard', $this->get_calendar_information('W'));
1255
1256
            $tmpl->addVar('WholeBoard', 'LANG_JUMP', _APCAL_BTN_JUMP);
1257
1258
            // BODY of the calendar
1259
            $tmpl->addVar('WholeBoard', 'CALENDAR_BODY', $this->get_weekly_html($get_target, $query_string));
0 ignored issues
show
Unused Code introduced by
The call to APCal::get_weekly_html() has too many arguments starting with $query_string.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
1260
1261
            // content generated from PatTemplate
1262
            $ret = $tmpl->getParsedTemplate('WholeBoard');
1263
1264
            return $ret;
1265
        }
1266
1267
        // ������������Τ�ɽ����patTemplate����)
1268
1269
        /**
1270
         * @param  string $get_target
1271
         * @param  string $query_string
1272
         * @param  bool   $for_print
1273
         * @return string
1274
         */
1275 View Code Duplication
        public function get_daily($get_target = '', $query_string = '', $for_print = false)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
1276
        {
1277
            // $PHP_SELF = $_SERVER['SCRIPT_NAME'] ;
1278
            // if( $get_target == '' ) $get_target = $PHP_SELF ;
1279
1280
            require_once "$this->base_path/include/patTemplate.php";
1281
            $tmpl = new PatTemplate();
1282
            $tmpl->readTemplatesFromFile("$this->images_path/daily.tmpl.html");
1283
1284
            // setting skin folder
1285
            $tmpl->addVar('WholeBoard', 'SKINPATH', $this->images_url);
1286
1287
            // Static parameter for the request
1288
            $tmpl->addVar('WholeBoard', 'GET_TARGET', $get_target);
1289
            $tmpl->addVar('WholeBoard', 'QUERY_STRING', $query_string);
1290
            $tmpl->addVar('WholeBoard', 'PRINT_LINK', "$this->base_url/print.php?cid=$this->now_cid&amp;smode=Daily&amp;caldate=$this->caldate");
1291
            $tmpl->addVar('WholeBoard', 'LANG_PRINT', _APCAL_BTN_PRINT);
1292
            if ($for_print) {
1293
                $tmpl->addVar('WholeBoard', 'PRINT_ATTRIB', "width='0' height='0'");
1294
            }
1295
1296
            $prevMonth = date('Y-n-j', mktime(0, 0, 0, $this->month, 0, $this->year));
1297
            $nextMonth = date('Y-n-j', mktime(0, 0, 0, $this->month + 1, 1, $this->year));
1298
            $prevDay   = date('Y-n-j', mktime(0, 0, 0, $this->month, $this->date - 1, $this->year));
1299
            $nextDay   = date('Y-n-j', mktime(0, 0, 0, $this->month, $this->date + 1, $this->year));
1300
            $tmpl->addVar('WholeBoard', 'TODAYLINK', $this->make_cal_link($get_target, 'Daily', $this->now_cid, date('Y-n-j')));
1301
            $tmpl->addVar('WholeBoard', 'PREVIOUSMONTHLINK', $this->make_cal_link($get_target, 'Daily', $this->now_cid, $prevMonth));
1302
            $tmpl->addVar('WholeBoard', 'PREVIOUSDAYLINK', $this->make_cal_link($get_target, 'Daily', $this->now_cid, $prevDay));
1303
            $tmpl->addVar('WholeBoard', 'NEXTDAYLINK', $this->make_cal_link($get_target, 'Daily', $this->now_cid, $nextDay));
1304
            $tmpl->addVar('WholeBoard', 'NEXTMONTHLINK', $this->make_cal_link($get_target, 'Daily', $this->now_cid, $nextMonth));
1305
            $tmpl->addVar('WholeBoard', 'YEARLYVIEW', $this->make_cal_link($get_target, 'Yearly', $this->now_cid, $this->caldate));
1306
            $tmpl->addVar('WholeBoard', 'MONTHLYVIEW', $this->make_cal_link($get_target, 'Monthly', $this->now_cid, $this->caldate));
1307
            $tmpl->addVar('WholeBoard', 'WEEKLYVIEW', $this->make_cal_link($get_target, 'Weekly', $this->now_cid, $this->caldate));
1308
            $tmpl->addVar('WholeBoard', 'LISTVIEW', $this->make_cal_link($get_target, 'List', $this->now_cid, $this->caldate));
1309
1310
            // ���ƥ��꡼����ܥå���
1311
            $tmpl->addVar('WholeBoard', 'CATEGORIES_SELFORM', $this->get_categories_selform($get_target));
1312
            $tmpl->addVar('WholeBoard', 'CID', $this->now_cid);
1313
1314
            // Variables required in header part etc.
1315
            $tmpl->addVars('WholeBoard', $this->get_calendar_information('D'));
1316
1317
            $tmpl->addVar('WholeBoard', 'LANG_JUMP', _APCAL_BTN_JUMP);
1318
1319
            // BODY of the calendar
1320
            $tmpl->addVar('WholeBoard', 'CALENDAR_BODY', $this->get_daily_html($get_target, $query_string));
0 ignored issues
show
Unused Code introduced by
The call to APCal::get_daily_html() has too many arguments starting with $query_string.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
1321
1322
            // content generated from PatTemplate
1323
            $ret = $tmpl->getParsedTemplate('WholeBoard');
1324
1325
            return $ret;
1326
        }
1327
1328
        // ���������Υإå������ɬ�פʾ����Ϣ��������֤��ʷ�֡����֡������̡�
1329
1330
        /**
1331
         * @param  string $mode
1332
         * @return array
1333
         */
1334
        public function get_calendar_information($mode = 'M')
1335
        {
1336
            $ret = array();
1337
1338
            // ���ܾ���
1339
            $ret['TODAY']      = date('Y-n-j');        // GIJ TODO �׼�ľ���ʻȤ�ʤ�����
1340
            $ret['CALDATE']    = $this->caldate;
1341
            $ret['DISP_YEAR']  = sprintf(_APCAL_FMT_YEAR, $this->year);
1342
            $ret['DISP_MONTH'] = $this->month_middle_names[$this->month];
1343
            $ret['DISP_DATE']  = $this->date_long_names[$this->date];
1344
            $ret['DISP_DAY']   = "({$this->week_middle_names[ $this->day ]})";
1345
            list($bgcolor, $color) = $this->daytype_to_colors($this->daytype);
0 ignored issues
show
Unused Code introduced by
The assignment to $bgcolor is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
1346
            $ret['DISP_DAY_COLOR'] = $color;
1347
            $ret['COPYRIGHT']      = _MD_APCAL_COPYRIGHT;
1348
1349
            // �إå������Υ��顼
1350
            $ret['CALHEAD_BGCOLOR'] = $this->calhead_bgcolor;
1351
            $ret['CALHEAD_COLOR']   = $this->calhead_color;
1352
1353
            // ���������alt(title)
1354
            $ret['ICON_LIST']    = _APCAL_ICON_LIST;
1355
            $ret['ICON_DAILY']   = _APCAL_ICON_DAILY;
1356
            $ret['ICON_WEEKLY']  = _APCAL_ICON_WEEKLY;
1357
            $ret['ICON_MONTHLY'] = _APCAL_ICON_MONTHLY;
1358
            $ret['ICON_YEARLY']  = _APCAL_ICON_YEARLY;
1359
1360
            // ��å������֥�å�
1361
            $ret['MB_PREV_YEAR']  = _APCAL_MB_PREV_YEAR;
1362
            $ret['MB_NEXT_YEAR']  = _APCAL_MB_NEXT_YEAR;
1363
            $ret['MB_PREV_MONTH'] = _APCAL_MB_PREV_MONTH;
1364
            $ret['MB_NEXT_MONTH'] = _APCAL_MB_NEXT_MONTH;
1365
            $ret['MB_PREV_WEEK']  = _APCAL_MB_PREV_WEEK;
1366
            $ret['MB_NEXT_WEEK']  = _APCAL_MB_NEXT_WEEK;
1367
            $ret['MB_PREV_DATE']  = _APCAL_MB_PREV_DATE;
1368
            $ret['MB_NEXT_DATE']  = _APCAL_MB_NEXT_DATE;
1369
            $ret['MB_LINKTODAY']  = _APCAL_MB_LINKTODAY;
1370
1371
            // �����ؤΥ��
1372
            $ret['PREV_YEAR']  = date('Y-n-j', mktime(0, 0, 0, $this->month, $this->date, $this->year - 1));
1373
            $ret['NEXT_YEAR']  = date('Y-n-j', mktime(0, 0, 0, $this->month, $this->date, $this->year + 1));
1374
            $ret['PREV_MONTH'] = date('Y-n-j', mktime(0, 0, 0, $this->month, 0, $this->year));
1375
            $ret['NEXT_MONTH'] = date('Y-n-j', mktime(0, 0, 0, $this->month + 1, 1, $this->year));
1376
            $ret['PREV_WEEK']  = date('Y-n-j', mktime(0, 0, 0, $this->month, $this->date - 7, $this->year));
1377
            $ret['NEXT_WEEK']  = date('Y-n-j', mktime(0, 0, 0, $this->month, $this->date + 7, $this->year));
1378
            $ret['PREV_DATE']  = date('Y-n-j', mktime(0, 0, 0, $this->month, $this->date - 1, $this->year));
1379
            $ret['NEXT_DATE']  = date('Y-n-j', mktime(0, 0, 0, $this->month, $this->date + 1, $this->year));
1380
1381
            // ���ե������ѥե�����γƥ���ȥ?��
1382
            // ǯ�������ν����
1383
            if (empty($_POST['apcal_year'])) {
1384
                $year = $this->year;
1385
            } else {
1386
                $year = (int)$_POST['apcal_year'];
1387
            }
1388
            if (empty($_POST['apcal_month'])) {
1389
                $month = $this->month;
1390
            } else {
1391
                $month = (int)$_POST['apcal_month'];
1392
            }
1393
            if (empty($_POST['apcal_date'])) {
1394
                $date = $this->date;
1395
            } else {
1396
                $date = (int)$_POST['apcal_date'];
1397
            }
1398
1399
            // ǯ�������(2001��2020 �Ȥ���)
1400
            $year_options = '';
1401 View Code Duplication
            for ($y = 2001; $y <= 2020; ++$y) {
0 ignored issues
show
Duplication introduced by
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...
1402
                if ($y == $year) {
1403
                    $year_options .= "\t\t\t<option value='$y' selected>" . sprintf(strip_tags(_APCAL_FMT_YEAR), $y) . "</option>\n";
1404
                } else {
1405
                    $year_options .= "\t\t\t<option value='$y'>" . sprintf(strip_tags(_APCAL_FMT_YEAR), $y) . "</option>\n";
1406
                }
1407
            }
1408
            $ret['YEAR_OPTIONS'] = $year_options;
1409
1410
            // ��������
1411
            $month_options = '';
1412 View Code Duplication
            for ($m = 1; $m <= 12; ++$m) {
0 ignored issues
show
Duplication introduced by
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...
1413
                if ($m == $month) {
1414
                    $month_options .= "\t\t\t<option value='$m' selected>{$this->month_short_names[$m]}</option>\n";
1415
                } else {
1416
                    $month_options .= "\t\t\t<option value='$m'>{$this->month_short_names[$m]}</option>\n";
1417
                }
1418
            }
1419
            $ret['MONTH_OPTIONS'] = $month_options;
1420
1421
            // ��������
1422
            if ($mode === 'W' || $mode === 'D') {
1423
                $date_options = '';
1424 View Code Duplication
                for ($d = 1; $d <= 31; ++$d) {
0 ignored issues
show
Duplication introduced by
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...
1425
                    if ($d == $date) {
1426
                        $date_options .= "\t\t\t<option value='$d' selected>{$this->date_short_names[$d]}</option>\n";
1427
                    } else {
1428
                        $date_options .= "\t\t\t<option value='$d'>{$this->date_short_names[$d]}</option>\n";
1429
                    }
1430
                }
1431
1432
                $ret['YMD_SELECTS'] = sprintf(_APCAL_FMT_YMD, "<select name='apcal_year'>{$ret['YEAR_OPTIONS']}</select> &nbsp; ",
1433
                                              "<select name='apcal_month'>{$ret['MONTH_OPTIONS']}</select> &nbsp; ", "<select name='apcal_date'>$date_options</select> &nbsp; ");
1434
                if ($this->week_numbering) {
1435
                    if ($this->day == 0 && !$this->week_start) {
1436
                        $weekno = date('W', $this->unixtime + 86400);
1437
                    } else {
1438
                        $weekno = date('W', $this->unixtime);
1439
                    }
1440
                    $ret['YMW_TITLE'] = sprintf(_APCAL_FMT_YW, $this->year, $weekno);
1441
                } else {
1442
                    $week_number      = floor(($this->date - ($this->day - $this->week_start + 7) % 7 + 12) / 7);
1443
                    $ret['YMW_TITLE'] = sprintf(_APCAL_FMT_YMW, $this->year, $this->month_middle_names[$this->month], $this->week_numbers[$week_number]);
1444
                }
1445
                $ret['YMD_TITLE'] = sprintf(_APCAL_FMT_YMD, $this->year, $this->month_middle_names[$this->month], $this->date_long_names[$date]);
1446
            }
1447
1448
            return $ret;
1449
        }
1450
1451
        /**
1452
         * @param  string $get_target
1453
         * @param  string $query_string
1454
         * @param  bool   $for_print
1455
         * @return mixed|string|
1456
         */
1457
        public function get_monthly_html($get_target = '', $query_string = '', $for_print = false)
0 ignored issues
show
Unused Code introduced by
The parameter $query_string is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1458
        {
1459
            $tpl = new XoopsTpl();
1460
1461
            // Set days width
1462
            $this->widerDays = unserialize($this->widerDays);
1463
            $total           = 0;
1464
            $widths          = array(
1465
                'Monday'    => 1,
1466
                'Tuesday'   => 1,
1467
                'Wednesday' => 1,
1468
                'Thursday'  => 1,
1469
                'Friday'    => 1,
1470
                'Saturday'  => 1,
1471
                'Sunday'    => 1
1472
            );
1473
            foreach ($this->widerDays as $day) {
1474
                $widths[$day] = 1.5;
1475
            }
1476
            foreach ($widths as $width) {
1477
                $total += $width;
1478
            }
1479
            foreach ($widths as $day => $width) {
1480
                $widths[$day] = (100 * $width / $total) . '%';
1481
            }
1482
1483
            // Where clause - Start / End
1484
            $mtop_unixtime = mktime(0, 0, 0, $this->month, 1, $this->year);
1485
            $mtop_weekno   = date('W', $mtop_unixtime);
1486
            if ($mtop_weekno >= 52) {
1487
                $mtop_weekno = 1;
1488
            }
1489
            $first_date     = getdate($mtop_unixtime);
1490
            $date           = (-$first_date['wday'] + $this->week_start - 7) % 7;
1491
            $wday_end       = 7 + $this->week_start;
1492
            $last_date      = date('t', $this->unixtime);
1493
            $mlast_unixtime = mktime(0, 0, 0, $this->month + 1, 1, $this->year);
1494
1495
            $tzoffset = (int)(($this->user_TZ - $this->server_TZ) * 3600);
1496
            if ($tzoffset == 0) {
1497
                $whr_term = "start<='$mlast_unixtime' AND end>'$mtop_unixtime'";
1498
            } else {
1499
                $whr_term = "(allday AND start<='"
1500
                            . ($mlast_unixtime - $tzoffset)
1501
                            . "' AND end>'"
1502
                            . ($mtop_unixtime - $tzoffset)
1503
                            . "') || (!allday AND start<='"
1504
                            . ($mlast_unixtime - $tzoffset)
1505
                            . "' AND end>'"
1506
                            . ($mtop_unixtime - $tzoffset)
1507
                            . "')";
1508
            }
1509
1510
            // Where clause - Categories
1511
            $whr_categories = $this->get_where_about_categories();
1512
1513
            // Where clause - Class
1514
            $whr_class = $this->get_where_about_class();
1515
1516
            // WHERE clause - Admittance
1517
            $whr_admit = $this->isadmin ? '' : 'AND admission=1';
1518
1519
            // ???
1520
            $rs             = $GLOBALS['xoopsDB']->query("SELECT DISTINCT unique_id FROM $this->table WHERE ($whr_term) AND ($whr_categories) AND ($whr_class) AND (allday & 2) LIMIT 4");
1521
            $long_event_ids = array();
1522
            $bit            = 1;
1523
            while ($event = $GLOBALS['xoopsDB']->fetchObject($rs)) {
1524
                $long_event_ids[$bit] = $event->unique_id;
1525
                ++$bit;
1526
            }
1527
1528
            $cats_color['00000'] = $this->allcats_color;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$cats_color was never initialized. Although not strictly required by PHP, it is generally a good practice to add $cats_color = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
1529
            foreach ($this->canbemain_cats as $i => $cat) {
1530
                $cats_color[$cat->cid]          = $cat->color;
1531
                $this->canbemain_cats[$i]->link = $this->make_cal_link($get_target, 'Monthly', $cat->cid, $this->caldate);
1532
            }
1533
1534
            // Get all events in the month in the category with the class
1535
            $yrs         = $GLOBALS['xoopsDB']->query("SELECT id,start,end,summary,location,contact,id,allday,admission,uid,unique_id,mainCategory,categories,gmlat,gmlong,extkey0 FROM $this->table WHERE ({$whr_term}) AND ({$whr_categories}) AND ({$whr_class}) {$whr_admit} ORDER BY start");
1536
            $numrows_yrs = $GLOBALS['xoopsDB']->getRowsNum($yrs);
1537
            $events      = array();
1538
            $eventsids   = array();
1539
            $slots       = 0;
1540
            if ($numrows_yrs) {
1541
                $lastDay = date('t', mktime(0, 0, 0, $this->month, 1, $this->year));
1542
1543
                while ($event = $GLOBALS['xoopsDB']->fetchObject($yrs)) {
1544
                    $event->start += $tzoffset;
1545
                    $event->end   += $tzoffset;
1546
1547
                    $startDay = date('j', $event->start);
1548
                    $endDay   = date('j', $event->end);
1549
                    $endHour  = date('H:i:s', $event->end);
1550
1551
                    $startDay = $event->start < mktime(0, 0, 0, $this->month, 1, $this->year) ? 1 : $startDay;
1552
                    //$endDay = $endDay != $startDay && $endHour == '00:00:00' ? $endDay - 1 : $endDay;
1553
                    $endDay   = $event->end > mktime(0, 0, 0, $this->month, $lastDay, $this->year) ? $lastDay : $endDay;
1554
                    $week_end = $this->week_start + 6;
1555
1556
                    // Get picture
1557
                    $pic = $GLOBALS['xoopsDB']->fetchObject($GLOBALS['xoopsDB']->query("SELECT picture FROM {$this->pic_table} WHERE event_id={$event->id} AND main_pic=1 LIMIT 0,1"));
1558
1559
                    if ($event->admission) {
1560
                        // Put markers on map
1561
                        if ($event->gmlat > 0 || $event->gmlong > 0) {
1562
                            $this->gmPoints[$event->id] = array(
1563
                                'summary'   => $event->summary,
1564
                                'gmlat'     => $event->gmlat,
1565
                                'gmlong'    => $event->gmlong,
1566
                                'location'  => $event->location,
1567
                                'contact'   => $event->contact,
1568
                                'startDate' => $startDay,
1569
                                'event_id'  => $event->id
1570
                            );
1571
                            if ($endDay != $startDay && $endHour !== '00:00:00') {
1572
                                $nbDays = date('j', $event->end) - $startDay;
1573
                                for ($i = 1; $i <= $nbDays; ++$i) {
1574
                                    $this->gmPoints[$event->id . ($startDay + $i)] = array(
1575
                                        'summary'   => $event->summary,
1576
                                        'gmlat'     => $event->gmlat,
1577
                                        'gmlong'    => $event->gmlong,
1578
                                        'location'  => $event->location,
1579
                                        'contact'   => $event->contact,
1580
                                        'startDate' => $startDay + $i,
1581
                                        'event_id'  => $event->id
1582
                                    );
1583
                                }
1584
                            }
1585
                        }
1586
1587
                        // Categories
1588
                        $categories = explode(',', $event->categories);
0 ignored issues
show
Unused Code introduced by
$categories is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
1589
                        //$e['cat'] = $this->text_sanitizer_for_show($this->categories[(int)($categories[0])]->cat_title);
1590
                        // Summary
1591
                        $event->summary = $this->text_sanitizer_for_show($event->summary);
1592
                        $summary        = /*mb_strcut(*/
1593
                            $event->summary/*, 0, 44)*/
1594
                        ;
1595
                        /*if($summary != $event->summary) $summary .= "..";*/
1596
                        // Event ID
1597
                        $event_id = $event->id;
1598
                        //$e['week'] = date('W', $event->start) - date('W', mktime(0, 0, 0, $this->month, 1, $this->year));
1599
                        // Events array
1600
                        $events[$event_id]['summary'] = $summary;
1601
                        $events[$event_id]['extkey0'] = (int)$event->extkey0; //added by goffy
1602
                    } elseif ($this->isadmin || ($this->user_id > 0 && $this->user_id == $event->uid)) {
1603
                        $event_id                     = $event->id;
1604
                        $events[$event_id]['summary'] = sprintf(_APCAL_NTC_NUMBEROFNEEDADMIT, '');
1605
                    }
1606
                    $events[$event_id]['link']     = $this->make_event_link($event->id, $get_target);
0 ignored issues
show
Bug introduced by
The variable $event_id does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
1607
                    $events[$event_id]['location'] = $this->text_sanitizer_for_show($event->location);
1608
                    $events[$event_id]['start']    = $this->get_middle_md($event->start /*+ $tzoffset*/) . ' ' . ($event->allday < 1 ? $this->get_middle_hi($event->start /*+ $tzoffset*/) : '');
1609
                    $events[$event_id]['end']      = /*($event->allday != 1 ? */
1610
                        $this->get_middle_md($event->end /*+ $tzoffset*/) /*: $this->get_middle_md($event->end - 3600))*/ . ' ' . ($event->allday
1611
                                                                                                                                   < 1 ? $this->get_middle_hi($event->end/* + $tzoffset*/) : '');
1612
                    $events[$event_id]['cat']      = ($event->mainCategory
1613
                                                      && array_key_exists($event->mainCategory, $cats_color)) ? $event->mainCategory : '00000';
1614
                    $events[$event_id]['duration'] = $endDay - $startDay + 1;
1615
                    $events[$event_id]['picture']  = $pic && $this->showPicMonthly ? XOOPS_UPLOAD_URL . "/apcal/{$pic->picture}" : '';
1616
1617
                    // Find the best slot for the event
1618
                    $i  = 0;
1619
                    $ok = false;
1620
                    while (!$ok) {
1621
                        $ok = true;
1622
                        for ($d = $startDay; $d <= $endDay; ++$d) {
1623
                            if (isset($eventsids[$d][$i])) {
1624
                                $ok = false;
1625
                            }
1626
                        }
1627
                        if (!$ok) {
1628
                            ++$i;
1629
                        }
1630
                    }
1631
1632
                    // Assign event to day
1633
                    for ($d = $startDay; $d <= $endDay; ++$d) {
1634
                        $wday = date('w', mktime(0, 0, 0, $this->month, $d, $this->year));
1635
1636
                        if ($d == $startDay) {
1637
                            $wday_left         = $week_end == 7 && $wday == 0 ? 0 : $week_end - $wday;
1638
                            $duration          = min($events[$event_id]['duration'], $wday_left + 1);
1639
                            $eventsids[$d][$i] = array('id' => $event_id, 'first' => 1, 'duration' => $duration);
1640
                        } elseif ($wday == $this->week_start) {
1641
                            $duration          = min($endDay - $d + 1, 7);
1642
                            $eventsids[$d][$i] = array('id' => $event_id, 'first' => 1, 'duration' => $duration);
1643
                        } else {
1644
                            $eventsids[$d][$i] = array('id' => $event_id, 'first' => 0);
1645
                        }
1646
1647
                        $slots = max($slots, count($eventsids[$d]));
1648
                    }
1649
                }
1650
            }
1651
            $roimage = XOOPS_URL . '/modules/apcal/assets/images/regonline/regonline.png'; // added by goffy: general comments for online registration
1652
1653
            // Header
1654
            $tpl->assign('images_url', $this->images_url);
1655
            $tpl->assign('widths', $widths);
1656
            $tpl->assign('week_start', $this->week_start);
1657
            $tpl->assign('week_middle_names', $this->week_middle_names);
1658
1659
            // Colors
1660
            $tpl->assign('colors', array(
1661
                $this->sunday_color,
1662
                $this->weekday_color,
1663
                $this->weekday_color,
1664
                $this->weekday_color,
1665
                $this->weekday_color,
1666
                $this->weekday_color,
1667
                $this->saturday_color,
1668
                $this->sunday_color
1669
            ));
1670
            $tpl->assign('bgcolors', array(
1671
                $this->sunday_bgcolor,
1672
                $this->weekday_bgcolor,
1673
                $this->weekday_bgcolor,
1674
                $this->weekday_bgcolor,
1675
                $this->weekday_bgcolor,
1676
                $this->weekday_bgcolor,
1677
                $this->saturday_bgcolor,
1678
                $this->sunday_bgcolor
1679
            ));
1680
            $tpl->assign('frame_css', $this->frame_css);
1681
            $tpl->assign('holiday_color', $this->holiday_color);
1682
            $tpl->assign('holiday_bgcolor', $this->holiday_bgcolor);
1683
            $tpl->assign('targetday_bgcolor', $this->targetday_bgcolor);
1684
            $tpl->assign('event_color', $this->event_color);
1685
            $tpl->assign('event_bgcolor', $this->event_bgcolor);
1686
1687
            $tpl->assign('categories', $this->canbemain_cats);
1688
            $tpl->assign('cats_color', $cats_color);
1689
1690
            // Loops
1691
            $tpl->assign('week_start', $this->week_start);
1692
            $tpl->assign('week_end', $wday_end);
1693
            $tpl->assign('day', $date);
1694
            $tpl->assign('last_day', $last_date);
1695
            $tpl->assign('week_numbering', $this->week_numbering);
1696
            $tpl->assign('weekno', $mtop_weekno);
1697
            $tpl->assign('selectedday', (int)$this->date);
1698
            $tpl->assign('holidays', $this->holidays);
1699
1700
            // Days
1701
            $tpl->assign('insertable', $this->insertable);
1702
            $tpl->assign('days', array('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'));
1703
1704
            // Links
1705
            $tpl->assign('cid', $this->now_cid);
1706
            $tpl->assign('year', $this->year);
1707
            $tpl->assign('month', $this->month);
1708
            $tpl->assign('cal_date', $this->caldate);
1709
1710
            // Events
1711
            $tpl->assign('slots', $slots);
1712
            $tpl->assign('events', $events);
1713
            $tpl->assign('e', $eventsids);
1714
1715
            $tpl->assign('for_print', $for_print);
1716
1717
            $tpl->assign('cal', $this);
1718
1719
            //added by goffy: registration online
1720
            $tpl->assign('ro_image', $roimage);
1721
1722
            return $tpl->fetch(XOOPS_ROOT_PATH . '/modules/apcal/templates/apcal_monthly.tpl');
1723
        }
1724
1725
        // HTML output for weekly view
1726
1727
        /**
1728
         * @param  string $get_target
1729
         * @return string
1730
         */
1731
        public function get_weekly_html($get_target = '')
1732
        {
1733
            $roimage = XOOPS_URL . '/modules/apcal/assets/images/regonline/regonline.png'; // added by goffy: image for online registration
1734
            $ret     = "
1735
     <table border='0' cellspacing='0' cellpadding='0' width='100%' style='border-collapse:collapse;margin:0px;'>
1736
     <tr>
1737
       <td><img src='$this->images_url/spacer.gif' alt='' width='10' height='10' /></td>
1738
       <td><img src='$this->images_url/spacer.gif' alt='' width='80' height='10' /></td>
1739
       <td><img src='$this->images_url/spacer.gif' alt='' width='80' height='10' /></td>
1740
       <td><img src='$this->images_url/spacer.gif' alt='' width='80' height='10' /></td>
1741
       <td><img src='$this->images_url/spacer.gif' alt='' width='80' height='10' /></td>
1742
       <td><img src='$this->images_url/spacer.gif' alt='' width='80' height='10' /></td>
1743
       <td><img src='$this->images_url/spacer.gif' alt='' width='80' height='10' /></td>
1744
       <td><img src='$this->images_url/spacer.gif' alt='' width='80' height='10' /></td>
1745
     </tr>\n";
1746
1747
            $wtop_date      = $this->date - ($this->day - $this->week_start + 7) % 7;
1748
            $wtop_unixtime  = mktime(0, 0, 0, $this->month, $wtop_date, $this->year);
1749
            $wlast_unixtime = mktime(0, 0, 0, $this->month, $wtop_date + 7, $this->year);
1750
1751
            // get the result of plugins
1752
            $plugin_returns = array();
1753
            if (strtolower(get_class($this)) === 'apcal_xoops') {
1754
                $db       = XoopsDatabaseFactory::getDatabaseConnection();
1755
                $myts     = MyTextSanitizer::getInstance();
1756
                $now      = time();
1757
                $just1gif = 0;
1758
1759
                $tzoffset_s2u = (int)(($this->user_TZ - $this->server_TZ) * 3600);
1760
                $plugins      = $this->get_plugins('weekly');
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class APCal as the method get_plugins() does only exist in the following sub-classes of APCal: APCal_xoops. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
1761
                foreach ($plugins as $plugin) {
1762
                    $include_ret = @include $this->base_path . '/' . $this->plugins_path_weekly . '/' . $plugin['file'];
1763
                    if ($include_ret === false) {
1764
                        // weekly emulator by monthly plugin
1765
                        $wtop_month   = date('n', $wtop_unixtime);
1766
                        $wlast_month  = date('n', $wlast_unixtime - 86400);
1767
                        $year_backup  = $this->year;
1768
                        $month_backup = $this->month;
1769
                        if ($wtop_month == $wlast_month) {
1770
                            @include $this->base_path . '/' . $this->plugins_path_monthly . '/' . $plugin['file'];
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
1771
                        } else {
1772
                            $plugin_returns_backup = $plugin_returns;
1773
                            $this->year            = date('Y', $wtop_unixtime);
1774
                            $this->month           = $wtop_month;
1775
                            @include $this->base_path . '/' . $this->plugins_path_monthly . '/' . $plugin['file'];
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
1776 View Code Duplication
                            for ($d = 1; $d < 21; ++$d) {
0 ignored issues
show
Duplication introduced by
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...
1777
                                $plugin_returns[$d] = @$plugin_returns_backup[$d];
1778
                            }
1779
                            $plugin_returns_backup = $plugin_returns;
1780
                            $this->year            = date('Y', $wlast_unixtime);
1781
                            $this->month           = $wlast_month;
1782
                            @include $this->base_path . '/' . $this->plugins_path_monthly . '/' . $plugin['file'];
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
1783 View Code Duplication
                            for ($d = 8; $d < 32; ++$d) {
0 ignored issues
show
Duplication introduced by
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...
1784
                                $plugin_returns[$d] = @$plugin_returns_backup[$d];
1785
                            }
1786
                            $this->year  = $year_backup;
1787
                            $this->month = $month_backup;
1788
                        }
1789
                    }
1790
                }
1791
            }
1792
1793
            $tzoffset = (int)(($this->user_TZ - $this->server_TZ) * 3600);
1794
            if ($tzoffset == 0) {
1795
                $whr_term = "start<='$wlast_unixtime' AND end>'$wtop_unixtime'";
1796
            } else {
1797
                $whr_term = "(allday AND start<='$wlast_unixtime' AND end>'$wtop_unixtime') || ( ! allday AND start<='"
1798
                            . ($wlast_unixtime - $tzoffset)
1799
                            . "' AND end>'"
1800
                            . ($wtop_unixtime - $tzoffset)
1801
                            . "')";
1802
            }
1803
1804
            $whr_categories = $this->get_where_about_categories();
1805
            $whr_class      = $this->get_where_about_class();
1806
1807
            $ars         = $GLOBALS['xoopsDB']->query("SELECT * FROM $this->table WHERE admission>0 AND ($whr_term) AND ($whr_categories) AND ($whr_class) ORDER BY start");
1808
            $numrows_ars = $GLOBALS['xoopsDB']->getRowsNum($ars);
1809
            $wrs         = $GLOBALS['xoopsDB']->query("SELECT * FROM $this->table WHERE admission=0 AND ($whr_term) AND ($whr_categories) AND ($whr_class) ORDER BY start");
1810
            $numrows_wrs = $GLOBALS['xoopsDB']->getRowsNum($wrs);
1811
1812
            $now_date = $wtop_date;
1813
            $wday_end = 7 + $this->week_start;
1814
            for ($wday = $this->week_start; $wday < $wday_end; ++$wday, ++$now_date) {
1815
                $now_unixtime      = mktime(0, 0, 0, $this->month, $now_date, $this->year);
1816
                $toptime_of_day    = $now_unixtime + $this->day_start - $tzoffset;
1817
                $bottomtime_of_day = $toptime_of_day + 86400;
1818
                $link              = date('Y-n-j', $now_unixtime);
1819
                $date              = date('j', $now_unixtime);
1820
                $disp              = $this->get_middle_md($now_unixtime);
1821
                $disp              .= "<br>({$this->week_middle_names[$wday]})";
1822
                $date_part_append  = '';
1823
                $event_str         = "
1824
                <table cellpadding='0' cellspacing='2' style='margin:0px;'>
1825
                  <tr>
1826
                    <td><img src='$this->images_url/spacer.gif' alt='' border='0' width='120' height='4' /></td>
1827
                    <td><img src='$this->images_url/spacer.gif' alt='' border='0' width='360' height='4' /></td>
1828
                  </tr>
1829
        \n";
1830
1831
                if ($numrows_ars > 0) {
1832
                    mysqli_data_seek($ars, 0);
1833
                }
1834
                while ($event = $GLOBALS['xoopsDB']->fetchObject($ars)) {
1835
                    if ($event->allday & 4) {
1836
                        $event->end += 86400;
1837
                    }
1838 View Code Duplication
                    if ($event->gmlat > 0 || $event->gmlong > 0) {
0 ignored issues
show
Duplication introduced by
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...
1839
                        $this->gmPoints[] = array(
1840
                            'summary'   => $event->summary,
1841
                            'gmlat'     => $event->gmlat,
1842
                            'gmlong'    => $event->gmlong,
1843
                            'location'  => $event->location,
1844
                            'contact'   => $event->contact,
1845
                            'startDate' => date('j', $event->start + $tzoffset),
1846
                            'event_id'  => $event->id
1847
                        );
1848
                    }
1849
1850 View Code Duplication
                    if ($event->allday) {
0 ignored issues
show
Duplication introduced by
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...
1851
                        if ($event->start + $tzoffset >= $now_unixtime + 86400
1852
                            || $event->end + $tzoffset <= $now_unixtime
1853
                        ) {
1854
                            continue;
1855
                        }
1856
                    } else {
1857
                        if ($event->start + $tzoffset >= $bottomtime_of_day
1858
                            || $event->start + $tzoffset != $toptime_of_day
1859
                               && $event->end + $tzoffset <= $toptime_of_day
1860
                        ) {
1861
                            continue;
1862
                        }
1863
1864
                        $event->is_start_date = $event->start + $tzoffset >= $toptime_of_day;
1865
                        $event->is_end_date   = $event->end + $tzoffset <= $bottomtime_of_day;
1866
                    }
1867
1868
                    $summary = $this->text_sanitizer_for_show($event->summary);
1869
1870
                    // Get picture
1871
                    $pic     = $GLOBALS['xoopsDB']->fetchObject($GLOBALS['xoopsDB']->query("SELECT picture FROM {$this->pic_table} WHERE event_id={$event->id} AND main_pic=1 LIMIT 0,1"));
1872
                    $picture = $pic && $this->showPicWeekly ? "<img src='" . XOOPS_UPLOAD_URL . "/apcal/{$pic->picture}' alt='{$summary}' height='50' style='vertical-align: middle;' />" : '';
1873
1874
                    if ($event->allday) {
1875
                        if ($event->allday & 4) {
1876
                            $date_part_append .= "<span style='font-size: x-small; '><a href='{$this->make_event_link($event->id, $get_target)}' class='cal_summary_specialday'><font color='$this->holiday_color'>$summary</a></span>";
1877 View Code Duplication
                            if ($event->extkey0 == 1) {
0 ignored issues
show
Duplication introduced by
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...
1878
                                $event_str .= "&nbsp;&nbsp;<img src='{$roimage}' height='15px' alt='" . _APCAL_RO_ONLINE_POSS . "' title='" . _APCAL_RO_ONLINE_POSS . "' />";
1879
                            } // added by goffy: mark this event, that online registration is active
1880
                            $event_str .= "</a></font><br>\n";
1881
                            continue;
1882
                        } else {
1883
                            $time_part     = "             <img border='0' src='$this->images_url/dot_allday.gif' />";
1884
                            $summary_class = 'calsummary_allday';
1885
                        }
1886 View Code Duplication
                    } else {
0 ignored issues
show
Duplication introduced by
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...
1887
                        $time_part     = $this->get_time_desc_for_a_day($event, $tzoffset, $bottomtime_of_day - $this->day_start, true, true);
1888
                        $summary_class = 'calsummary';
1889
                    }
1890
1891
                    $event_str .= "
1892
                  <tr>
1893
                    <td valign='top' align='center'>
1894
                      <pre style='margin:0px;'><span style='font-size: x-small; '>$time_part</span></pre>
1895
                    </td>
1896
                    <td valign='top'>
1897
                      $picture
1898
                      <span style='font-size: x-small; '><a href='{$this->make_event_link($event->id, $get_target)}' class='$summary_class'>$summary</a></span>";
1899 View Code Duplication
                    if ($event->extkey0 == 1) {
0 ignored issues
show
Duplication introduced by
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...
1900
                        $event_str .= "&nbsp;&nbsp;<img src='{$roimage}' height='15px' alt='" . _APCAL_RO_ONLINE_POSS . "' title='" . _APCAL_RO_ONLINE_POSS . "' />";
1901
                    } // added by goffy: mark this event, that online registration is active
1902
                    $event_str .= "
1903
                    </td>
1904
                  </tr>
1905
            \n";
1906
                }
1907
1908
                if ($this->isadmin || $this->user_id > 0) {
1909
                    if ($numrows_wrs > 0) {
1910
                        mysqli_data_seek($wrs, 0);
1911
                    }
1912
                    while ($event = $GLOBALS['xoopsDB']->fetchObject($wrs)) {
1913 View Code Duplication
                        if ($event->allday) {
0 ignored issues
show
Duplication introduced by
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...
1914
                            if ($event->start + $tzoffset >= $now_unixtime + 86400
1915
                                || $event->end + $tzoffset <= $now_unixtime
1916
                            ) {
1917
                                continue;
1918
                            }
1919
                        } else {
1920
                            if ($event->start + $tzoffset >= $bottomtime_of_day
1921
                                || $event->start + $tzoffset != $toptime_of_day
1922
                                   && $event->end + $tzoffset <= $toptime_of_day
1923
                            ) {
1924
                                continue;
1925
                            }
1926
                            $event->is_start_date = $event->start + $tzoffset >= $toptime_of_day;
1927
                            $event->is_end_date   = $event->end + $tzoffset <= $bottomtime_of_day;
1928
                        }
1929
1930
                        $summary = $this->text_sanitizer_for_show($event->summary);
1931
1932
                        // Get picture
1933
                        $pic     = $GLOBALS['xoopsDB']->fetchObject($GLOBALS['xoopsDB']->query("SELECT picture FROM {$this->pic_table} WHERE event_id={$event->id} AND main_pic=1 LIMIT 0,1"));
1934
                        $picture = $pic && $this->showPicWeekly ? "<img src='" . XOOPS_UPLOAD_URL . "/apcal/{$pic->picture}' alt='{$summary}' height='50' style='vertical-align: middle;' />" : '';
1935
1936
                        if ($event->allday) {
1937
                            $time_part     = "             <img border='0' src='$this->images_url/dot_notadmit.gif' />";
1938
                            $summary_class = 'calsummary_allday';
1939 View Code Duplication
                        } else {
0 ignored issues
show
Duplication introduced by
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...
1940
                            $time_part     = $this->get_time_desc_for_a_day($event, $tzoffset, $bottomtime_of_day - $this->day_start, true, false);
1941
                            $summary_class = 'calsummary';
1942
                        }
1943
1944
                        $event_str .= "
1945
                      <tr>
1946
                        <td valign='top' align='center'>
1947
                          <pre style='margin:0px;'><span style='font-size: x-small; '>$time_part</span></pre>
1948
                        </td>
1949
                        <td valign='top'>
1950
                          $picture
1951
                          <span style='font-size: x-small; '><a href='{$this->make_event_link($event->id, $get_target)}' class='$summary_class'><font color='#00FF00'>$summary("
1952
                                      . _APCAL_MB_EVENT_NEEDADMIT
1953
                                      . ')</a></span>';
1954 View Code Duplication
                        if ($event->extkey0 == 1) {
0 ignored issues
show
Duplication introduced by
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...
1955
                            $event_str .= "&nbsp;&nbsp;<img src='{$roimage}' height='15px' alt='" . _APCAL_RO_ONLINE_POSS . "' title='" . _APCAL_RO_ONLINE_POSS . "' />";
1956
                        } // added by goffy: mark this event, that online registration is active
1957
                        $event_str .= "
1958
                        </td>
1959
                      </tr>
1960
                \n";
1961
                    }
1962
                }
1963
1964
                // drawing the result of plugins
1965
                if (!empty($plugin_returns[$date])) {
1966 View Code Duplication
                    foreach ($plugin_returns[$date] as $item) {
0 ignored issues
show
Duplication introduced by
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...
1967
                        $event_str .= "
1968
                  <tr>
1969
                    <td></td>
1970
                    <td valign='top'>
1971
                      <span style='font-size: x-small; '><a href='{$item['link']}' class='$summary_class'><img src='$this->images_url/{$item['dotgif']}' alt='{$item['title']}>' />{$item['title']}</a></span>
0 ignored issues
show
Bug introduced by
The variable $summary_class does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
1972
                    </td>
1973
                  </tr>\n";
1974
                    }
1975
                }
1976
1977
                if ($this->insertable) {
1978
                    $event_str .= "
1979
                  <tr>
1980
                    <td valign='bottom' colspan='2'>
1981
                      &nbsp; <span style='font-size: x-small; '><a href='$get_target?cid=$this->now_cid&amp;smode=Weekly&amp;action=Edit&amp;caldate=$link'><img src='$this->images_url/addevent.gif' border='0' width='14' height='12' />"
1982
                                  . _APCAL_MB_ADDEVENT
1983
                                  . "</a></span>
1984
                    </td>
1985
                  </tr>
1986
        \n";
1987
                }
1988
1989
                $event_str .= "\t\t\t\t</table>\n";
1990
1991
                if (isset($this->holidays[$link])) {
1992
                    //  Holiday
1993
                    $bgcolor = $this->holiday_bgcolor;
1994
                    $color   = $this->holiday_color;
1995
                    if ($this->holidays[$link] != 1) {
1996
                        $date_part_append .= "<span color='$this->holiday_color'>{$this->holidays[ $link ]}</span>\n";
1997
                    }
1998
                } elseif ($wday % 7 == 0) {
1999
                    //  Sunday
2000
                    $bgcolor = $this->sunday_bgcolor;
2001
                    $color   = $this->sunday_color;
2002
                } elseif ($wday == 6) {
2003
                    //  Saturday
2004
                    $bgcolor = $this->saturday_bgcolor;
2005
                    $color   = $this->saturday_color;
2006
                } else {
2007
                    // Weekday
2008
                    $bgcolor = $this->weekday_bgcolor;
2009
                    $color   = $this->weekday_color;
2010
                }
2011
2012
                // ��������طʿ��ϥ��饤�Ƚ���
2013
                if ($link == $this->caldate) {
2014
                    $body_bgcolor = $this->targetday_bgcolor;
2015
                } else {
2016
                    $body_bgcolor = $bgcolor;
2017
                }
2018
2019
                $ret .= "
2020
     <tr>
2021
       <td><img src='$this->images_url/spacer.gif' alt='' width='10' height='80' /></td>
2022
       <td bgcolor='$bgcolor' align='center' valign='middle' style='vertical-align:middle;text-align:center;$this->frame_css background-color:$bgcolor;'>
2023
         <a href='{$this->make_cal_link($get_target, 'Daily', $this->now_cid, $link)}' class='calbody'><font size='3' color='$color'><b><span class='calbody'>$disp</span></b></font></a><br>
2024
         $date_part_append
2025
       </td>
2026
       <td valign='top' colspan='6' bgcolor='$body_bgcolor' style='$this->frame_css background-color:$body_bgcolor'>
2027
         $event_str
2028
       </td>
2029
     </tr>\n";
2030
            }
2031
2032
            $ret .= "\t </table>\n";
2033
2034
            return $ret;
2035
        }
2036
2037
        // Get the html for the daily view
2038
2039
        /**
2040
         * @param  string $get_target
2041
         * @return string
2042
         */
2043
        public function get_daily_html($get_target = '')
2044
        {
2045
            $roimage = XOOPS_URL . '/modules/apcal/assets/images/regonline/regonline.png'; // added by goffy: image for online registration
2046
            // get the result of plugins
2047
            $plugin_returns = array();
2048
            if (strtolower(get_class($this)) === 'apcal_xoops') {
2049
                $db       = XoopsDatabaseFactory::getDatabaseConnection();
2050
                $myts     = MyTextSanitizer::getInstance();
2051
                $now      = time();
2052
                $just1gif = 0;
2053
2054
                $tzoffset_s2u = (int)(($this->user_TZ - $this->server_TZ) * 3600);
2055
                $plugins      = $this->get_plugins('daily');
0 ignored issues
show
Bug introduced by
It seems like you code against a specific sub-type and not the parent class APCal as the method get_plugins() does only exist in the following sub-classes of APCal: APCal_xoops. Maybe you want to instanceof check for one of these explicitly?

Let’s take a look at an example:

abstract class User
{
    /** @return string */
    abstract public function getPassword();
}

class MyUser extends User
{
    public function getPassword()
    {
        // return something
    }

    public function getDisplayName()
    {
        // return some name.
    }
}

class AuthSystem
{
    public function authenticate(User $user)
    {
        $this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
        // do something.
    }
}

In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different sub-classes of User which does not have a getDisplayName() method, the code will break.

Available Fixes

  1. Change the type-hint for the parameter:

    class AuthSystem
    {
        public function authenticate(MyUser $user) { /* ... */ }
    }
    
  2. Add an additional type-check:

    class AuthSystem
    {
        public function authenticate(User $user)
        {
            if ($user instanceof MyUser) {
                $this->logger->info(/** ... */);
            }
    
            // or alternatively
            if ( ! $user instanceof MyUser) {
                throw new \LogicException(
                    '$user must be an instance of MyUser, '
                   .'other instances are not supported.'
                );
            }
    
        }
    }
    
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types inside the if block in such a case.
  1. Add the method to the parent class:

    abstract class User
    {
        /** @return string */
        abstract public function getPassword();
    
        /** @return string */
        abstract public function getDisplayName();
    }
    
Loading history...
2056
                foreach ($plugins as $plugin) {
2057
                    $include_ret = @include $this->base_path . '/' . $this->plugins_path_daily . '/' . $plugin['file'];
2058
                    if ($include_ret === false) {
2059
                        // daily emulator by monthly plugin
2060
                        @include $this->base_path . '/' . $this->plugins_path_monthly . '/' . $plugin['file'];
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
2061
                    }
2062
                }
2063
            }
2064
2065
            list($bgcolor, $color) = $this->daytype_to_colors($this->daytype);
0 ignored issues
show
Unused Code introduced by
The assignment to $color is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
2066
2067
            $ret = "
2068
    <table border='0' cellspacing='0' cellpadding='0' width='100%' style='margin:0px;'>
2069
     <tr>
2070
     <td width='100%' class='calframe'>
2071
     <table border='0' cellspacing='0' cellpadding='0' width='100%' style='margin:0px;'>
2072
     <tr>
2073
       <td colspan='8'><img src='$this->images_url/spacer.gif' alt='' width='570' height='10' /></td>
2074
     </tr>
2075
     <tr>
2076
       <td><img src='$this->images_url/spacer.gif' alt='' width='10' height='350' /></td>
2077
       <td colospan='7' valign='top' bgcolor='$bgcolor' style='$this->frame_css;background-color:$bgcolor'>
2078
         <table border='0' cellpadding='0' cellspacing='0' style='margin:0px;'>
2079
           <tr>
2080
             <td><img src='$this->images_url/spacer.gif' alt='' width='120' height='10' /></td>
2081
             <td><img src='$this->images_url/spacer.gif' alt='' width='440' height='10' /></td>
2082
           </tr>
2083
    \n";
2084
2085
            // WHERE Clause - Date
2086
            $tzoffset          = (int)(($this->user_TZ - $this->server_TZ) * 3600);
2087
            $toptime_of_day    = $this->unixtime + $this->day_start - $tzoffset;
2088
            $bottomtime_of_day = $toptime_of_day + 86400;
2089
            $whr_term          = "(allday AND start<='$this->unixtime' AND end>'$this->unixtime') || ( ! allday AND start<'$bottomtime_of_day' AND (start='$toptime_of_day' OR end>'$toptime_of_day'))";
2090
2091
            // WHERE Clause - Categories
2092
            $whr_categories = $this->get_where_about_categories();
2093
2094
            // WHERE Clause - Class
2095
            $whr_class = $this->get_where_about_class();
2096
2097
            // MySQL Query
2098
            $yrs      = $GLOBALS['xoopsDB']->query("SELECT *,(start>='$toptime_of_day') AS is_start_date,(end<='$bottomtime_of_day') AS is_end_date FROM $this->table WHERE admission>0 AND ($whr_term) AND ($whr_categories) AND ($whr_class) ORDER BY start,end");
2099
            $num_rows = $GLOBALS['xoopsDB']->getRowsNum($yrs);
2100
2101
            if ($num_rows == 0) {
2102
                $ret .= '<tr><td></td><td>' . _APCAL_MB_NOEVENT . "</td></tr>\n";
2103
            } else {
2104
                while ($event = $GLOBALS['xoopsDB']->fetchObject($yrs)) {
2105
                    // Get picture
2106
                    $pic     = $GLOBALS['xoopsDB']->fetchObject($GLOBALS['xoopsDB']->query("SELECT picture FROM {$this->pic_table} WHERE event_id={$event->id} AND main_pic=1 LIMIT 0,1"));
2107
                    $picture = $pic && $this->showPicDaily ? "<img src='" . XOOPS_UPLOAD_URL . "/apcal/{$pic->picture}' alt='{$summary}' height='50' style='vertical-align: middle;' />" : '';
0 ignored issues
show
Bug introduced by
The variable $summary does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
2108
2109
                    // Google map
2110 View Code Duplication
                    if ($event->gmlat > 0 || $event->gmlong > 0) {
0 ignored issues
show
Duplication introduced by
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...
2111
                        $this->gmPoints[] = array(
2112
                            'summary'   => $event->summary,
2113
                            'gmlat'     => $event->gmlat,
2114
                            'gmlong'    => $event->gmlong,
2115
                            'location'  => $event->location,
2116
                            'contact'   => $event->contact,
2117
                            'startDate' => date('j', $event->start),
2118
                            'event_id'  => $event->id
2119
                        );
2120
                    }
2121
2122 View Code Duplication
                    if ($event->allday) {
0 ignored issues
show
Duplication introduced by
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...
2123
                        $time_part = "             <img border='0' src='$this->images_url/dot_allday.gif' />";
2124
                    } else {
2125
                        $time_part = $this->get_time_desc_for_a_day($event, $tzoffset, $bottomtime_of_day - $this->day_start, true, true);
2126
                    }
2127
2128
                    $description   = $this->textarea_sanitizer_for_show($event->description);
2129
                    $summary       = $this->text_sanitizer_for_show($event->summary);
2130
                    $summary_class = $event->allday ? 'calsummary_allday' : 'calsummary';
2131
2132
                    $ret .= "
2133
           <tr>
2134
             <td valign='middle' align='center'>
2135
               <pre style='margin:0px;'><font size='3'>$time_part</font></pre>
2136
             </td>
2137
             <td valign='middle'>
2138
               <a href='{$this->make_event_link($event->id, $get_target)}'>{$picture}</a>
2139
               <font size='3'><a href='{$this->make_event_link($event->id, $get_target)}' class='$summary_class'>$summary</a></font>";
2140 View Code Duplication
                    if ($event->extkey0 == 1) {
0 ignored issues
show
Duplication introduced by
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...
2141
                        $ret .= "&nbsp;&nbsp;<img src='{$roimage}' height='15px' alt='" . _APCAL_RO_ONLINE_POSS . "' title='" . _APCAL_RO_ONLINE_POSS . "'>";
2142
                    }    // added by goffy: mark this event, that online registration is active
2143
                    $ret .= "<br>
2144
               <span style='font-size: x-small; '>$description</span><br>
2145
               &nbsp;
2146
             </td>
2147
           </tr>\n";
2148
                }
2149
            }
2150
2151
            if ($this->isadmin || $this->user_id > 0) {
2152
                $whr_uid = $this->isadmin ? '1' : "uid=$this->user_id ";
2153
                $yrs     = $GLOBALS['xoopsDB']->query("SELECT start,end,summary,id,allday,admission,uid,description,(start>='$toptime_of_day') AS is_start_date,(end<='$bottomtime_of_day') AS is_end_date FROM $this->table WHERE admission=0 AND $whr_uid AND ($whr_term) AND ($whr_categories) AND ($whr_class) ORDER BY start,end");
2154
2155
                while ($event = $GLOBALS['xoopsDB']->fetchObject($yrs)) {
2156 View Code Duplication
                    if ($event->allday) {
0 ignored issues
show
Duplication introduced by
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...
2157
                        $time_part = "             <img border='0' src='$this->images_url/dot_notadmit.gif' />";
2158
                    } else {
2159
                        $time_part = $this->get_time_desc_for_a_day($event, $tzoffset, $bottomtime_of_day - $this->day_start, true, false);
2160
                    }
2161
2162
                    $summary = $this->text_sanitizer_for_show($event->summary);
2163
2164
                    $summary_class = $event->allday ? 'calsummary_allday' : 'calsummary';
2165
2166
                    $ret .= "
2167
           <tr>
2168
             <td valign='top' align='center'>
2169
               <pre style='margin:0px;'><font size='3'>$time_part</font></pre>
2170
             </td>
2171
             <td vlalign='top'>
2172
               <font size='3'><a href='{$this->make_event_link($event->id, $get_target)}' class='$summary_class'><font color='#00FF00'>{$summary}</a></font>";
2173 View Code Duplication
                    if ($event->extkey0 == 1) {
0 ignored issues
show
Duplication introduced by
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...
2174
                        $ret .= "&nbsp;&nbsp;<img src='{$roimage}' height='15px' alt='" . _APCAL_RO_ONLINE_POSS . "' title='" . _APCAL_RO_ONLINE_POSS . "'>";
2175
                    }    // added by goffy: mark this event, that online registration is active
2176
                    $ret .= ' (' . _APCAL_MB_EVENT_NEEDADMIT . ")
2177
             </td>
2178
           </tr>\n";
2179
                }
2180
            }
2181
2182
            // drawing the result of plugins
2183
            if (!empty($plugin_returns[$this->date])) {
2184 View Code Duplication
                foreach ($plugin_returns[$this->date] as $item) {
0 ignored issues
show
Duplication introduced by
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...
2185
                    $ret .= "
2186
           <tr>
2187
             <td></td>
2188
             <td valign='top'>
2189
               <font size='3'><a href='{$item['link']}' class='$summary_class'><img src='$this->images_url/{$item['dotgif']}' alt='{$item['title']}>' />{$item['title']}</a></font><br>
0 ignored issues
show
Bug introduced by
The variable $summary_class does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
2190
               <span style='font-size: x-small; '>{$item['description']}</span><br>
2191
               &nbsp;
2192
             </td>
2193
           </tr>\n";
2194
                }
2195
            }
2196
2197
            // ͽ����ɲáʱ�ɮ���������
2198 View Code Duplication
            if ($this->insertable) {
0 ignored issues
show
Duplication introduced by
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...
2199
                $ret .= "
2200
           <tr>
2201
             <td valign='bottom' colspan='2'>
2202
               &nbsp; <span style='font-size: x-small; '><a href='$get_target?cid=$this->now_cid&amp;smode=Daily&amp;action=Edit&amp;caldate=$this->caldate'><img src='$this->images_url/addevent.gif' border='0' width='14' height='12' />"
2203
                        . _APCAL_MB_ADDEVENT
2204
                        . "</a></span>
2205
             </td>
2206
           </tr>\n";
2207
            }
2208
2209
            $ret .= "
2210
         </table>
2211
       </td>
2212
     </tr>
2213
     </table>
2214
     </td>
2215
     </tr>
2216
    </table>\n";
2217
2218
            return $ret;
2219
        }
2220
2221
        /*******************************************************************/
2222
        /*        �ᥤ���� �ʸ��̥ǡ�������  */
2223
        /*******************************************************************/
2224
2225
        /**
2226
         * @param $event_id
2227
         */
2228
        public function savepictures($event_id)
2229
        {
2230
            xoops_load('xoopsmediauploader');
2231
            $uploader = new XoopsMediaUploader(XOOPS_UPLOAD_PATH . '/apcal', array(
2232
                'image/gif',
2233
                'image/jpeg',
2234
                'image/pjpeg',
2235
                'image/x-png',
2236
                'image/png',
2237
                'image/bmp'
2238
            ), $_POST['MAX_FILE_SIZE'], 4048, 4048);
2239
            $uploader->setPrefix('APCal');
2240
            $err = array();
2241
            foreach ($_POST['files'] as $i => $file) {
2242
                $main_pic = $file === 'picture0' ? 1 : 0;
2243
                if ($uploader->fetchMedia($file)) {
2244
                    if (!$uploader->upload()) {
2245
                        $err[] = $uploader->getErrors();
2246
                    } else {
2247
                        $filename = $uploader->getSavedFileName();
2248
                        $result   = $GLOBALS['xoopsDB']->query("INSERT INTO {$this->pic_table}(event_id, picture, main_pic) VALUES ({$event_id}, '{$filename}', {$main_pic})");
2249
                        if (!$result) {
2250
                            $err[] = sprintf(_FAILSAVEIMG, $i);
2251
                        } else {
2252
                            Thumb::save($filename, $this->picWidth, $this->picHeight);
2253
                        }
2254
                    }
2255
                } else {
2256
                    $err[] = sprintf(_FAILFETCHIMG, $i);
2257
                    $err   = array_merge($err, $uploader->getErrors(false));
2258
                }
2259
            }
2260
2261
            //FOR DEBUG: var_dump($err);
2262
        }
2263
2264
        // Show an event
2265
2266
        /**
2267
         * @param  bool $for_print
2268
         * @return string
0 ignored issues
show
Documentation introduced by
Should the return type not be null|string?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
2269
         */
2270
        public function get_schedule_view_html($for_print = false)
2271
        {
2272
            global $xoopsTpl;
2273
2274
            $smode     = empty($_GET['smode']) ? 'Monthly' : preg_replace('/[^a-zA-Z0-9_-]/', '', $_GET['smode']);
2275
            $editable  = $this->editable;
2276
            $superedit = $this->superedit;
2277
            $deletable = $this->deletable;
2278
2279
            $whr_categories = $this->get_where_about_categories();
2280
2281
            // CLASS
2282
            $whr_class = $this->get_where_about_class();
2283
2284
            if (empty($_GET['event_id'])) {
2285
                die(_APCAL_ERR_INVALID_EVENT_ID);
2286
            }
2287
            $this->original_id = $event_id = (int)$_GET['event_id'];
2288
            $yrs               = $GLOBALS['xoopsDB']->query("SELECT *,UNIX_TIMESTAMP(dtstamp) AS udtstamp FROM $this->table WHERE id='$event_id' AND ($whr_categories) AND ($whr_class)");
2289
            if ($GLOBALS['xoopsDB']->getRowsNum($yrs) < 1) {
2290
                die(_APCAL_ERR_INVALID_EVENT_ID);
2291
            }
2292
            $event = $GLOBALS['xoopsDB']->fetchObject($yrs);
2293
2294
            // rrule
2295
            if (trim($event->rrule) !== '') {
2296
                if ($event->rrule_pid != $event->id) {
2297
                    $event->id = $event->rrule_pid;
2298
                    $yrs       = $GLOBALS['xoopsDB']->query("SELECT id,start,start_date FROM $this->table WHERE id='$event->rrule_pid' AND ($whr_categories) AND ($whr_class)");
2299
                    if ($GLOBALS['xoopsDB']->getRowsNum($yrs) >= 1) {
2300
                        $event->id           = $event->rrule_pid;
2301
                        $parent_event        = $GLOBALS['xoopsDB']->fetchObject($yrs);
2302
                        $this->original_id   = $parent_event->id;
2303
                        $is_extracted_record = true;
2304
                    } else {
2305
                        $parent_event = $event;
2306
                    }
2307
                }
2308
                $rrule = $this->rrule_to_human_language($event->rrule);
2309
            } else {
2310
                $rrule = '';
2311
            }
2312
2313
            // submitter of event
2314
            if ($event->uid != $this->user_id) {
2315
                $editable  = false;
2316
                $deletable = false;
2317
            }
2318
            // user is admin or has right to edit/delete all events
2319
            if ($this->isadmin || $superedit) {
2320
                $editable  = true;
2321
                $deletable = true;
2322
            }
2323
2324
            // editable
2325
            if (!$event->admission && !$editable) {
2326
                die(_APCAL_ERR_NOPERM_TO_SHOW);
2327
            }
2328
2329
            if ($editable && !$for_print) {
2330
                $edit_button = "
2331
            <form class='apcalForm' method='get' action='" . XOOPS_URL . "/modules/apcal/index.php' style='margin:0px;'>
2332
                <input type='hidden' name='smode' value='$smode' />
2333
                <input type='hidden' name='action' value='Edit' />
2334
                <input type='hidden' name='event_id' value='$event->id' />
2335
                <input type='hidden' name='caldate' value='{$_GET['date']}' />
2336
                <input type='submit' value='" . _APCAL_BTN_EDITEVENT . "' />
2337
            </form>\n";
2338
            } else {
2339
                $edit_button = '';
2340
            }
2341
2342
            if ($deletable && !$for_print) {
2343
                $delete_button = "
2344
            <form class='apcalForm' method='post' action='"
2345
                                 . XOOPS_URL
2346
                                 . "/modules/apcal/index.php' id='MainForm' name='MainForm' style='margin:0px;'>
2347
                <input type='hidden' name='smode' value='$smode' />
2348
                <input type='hidden' name='last_smode' value='$smode' />
2349
                <input type='hidden' name='event_id' value='$event->id' />
2350
                <input type='hidden' name='subevent_id' value='$event_id' />
2351
                <input type='hidden' name='caldate' value='$this->caldate' />
2352
                <input type='hidden' name='last_caldate' value='{$_GET['date']}' />
2353
                <input type='submit' name='delete' value='"
2354
                                 . _APCAL_BTN_DELETE
2355
                                 . "' onclick='return confirm(\""
2356
                                 . _APCAL_CNFM_DELETE_YN
2357
                                 . "\")' />
2358
                "
2359
                                 . (!empty($is_extracted_record) ? "<input type='submit' name='delete_one' value='"
2360
                                                                   . _APCAL_BTN_DELETE_ONE
2361
                                                                   . "' onclick='return confirm(\""
2362
                                                                   . _APCAL_CNFM_DELETE_YN
2363
                                                                   . "\")' />" : '')
2364
                                 . '
2365
                '
2366
                                 . $GLOBALS['xoopsGTicket']->getTicketHtml(__LINE__)
2367
                                 . "
2368
            </form>\n";
2369
            } else {
2370
                $delete_button = '';
2371
            }
2372
2373
            // iCalendar
2374
            if ($this->can_output_ics && !$for_print) {
2375
                $php_self4disp     = strtr(@$_SERVER['PHP_SELF'], '<>\'"', '    ');
2376
                $ics_output_button = "
2377
            <a href='http://{$_SERVER['HTTP_HOST']}$php_self4disp?fmt=single&amp;event_id=$event->id&amp;output_ics=1' target='_blank'><img border='0' src='$this->images_url/output_ics_win.gif' alt='"
2378
                                     . _APCAL_BTN_OUTPUTICS_WIN
2379
                                     . "' title='"
2380
                                     . _APCAL_BTN_OUTPUTICS_WIN
2381
                                     . "' /></a>
2382
            <a href='webcal://{$_SERVER['HTTP_HOST']}$php_self4disp?fmt=single&amp;event_id=$event->id&amp;output_ics=1' target='_blank'><img border='0' src='$this->images_url/output_ics_mac.gif' alt='"
2383
                                     . _APCAL_BTN_OUTPUTICS_MAC
2384
                                     . "' title='"
2385
                                     . _APCAL_BTN_OUTPUTICS_MAC
2386
                                     . "' /></a>\n";
2387
            } else {
2388
                $ics_output_button = '';
2389
            }
2390
2391
            if ($event->allday) {
2392
                $tzoffset = (int)(($this->user_TZ - $this->server_TZ) * 3600);
2393
                //$event->end -= 300 ;
2394
                $start_time_str = /*"("._APCAL_MB_ALLDAY_EVENT.")"*/
2395
                    '';
2396
                $end_time_str   = '';
2397
            } else {
2398
                $tzoffset       = (int)(($this->user_TZ - $this->server_TZ) * 3600);
2399
                $disp_user_tz   = $this->get_tz_for_display($this->user_TZ);
2400
                $start_time_str = $this->get_middle_hi($event->start + $tzoffset) . " $disp_user_tz";
2401
                $end_time_str   = $this->get_middle_hi($event->end + $tzoffset) . " $disp_user_tz";
2402
                if ($this->user_TZ != $event->event_tz) {
2403
                    $tzoffset_s2e   = (int)(($event->event_tz - $this->server_TZ) * 3600);
2404
                    $disp_event_tz  = $this->get_tz_for_display($event->event_tz);
2405
                    $start_time_str .= ' &nbsp; &nbsp; <small>' . $this->get_middle_dhi($event->start + $tzoffset_s2e) . " $disp_event_tz</small>";
2406
                    $end_time_str   .= ' &nbsp; &nbsp; <small>' . $this->get_middle_dhi($event->end + $tzoffset_s2e) . " $disp_event_tz</small>";
2407
                }
2408
            }
2409
2410
            $start_date_str = $this->get_long_ymdn($event->start + $tzoffset);
2411
            $end_date_str   = $this->get_long_ymdn($event->end + $tzoffset);
2412
2413
            $start_datetime_str = "$start_date_str&nbsp;$start_time_str";
2414
            $end_datetime_str   = "$end_date_str&nbsp;$end_time_str";
2415
2416
            if (trim($event->rrule) !== '') {
2417
                if (isset($parent_event) && $parent_event != $event) {
2418
                    if (isset($parent_event->start_date)) {
2419
                        $parent_date_str = $parent_event->start_date; // GIJ TODO
2420
                    } else {
2421
                        $parent_date_str = $this->get_long_ymdn($parent_event->start + $tzoffset);
2422
                    }
2423
                    $rrule .= "<br><a href='?action=View&amp;event_id=$parent_event->id' target='_blank'>" . _APCAL_MB_LINK_TO_RRULE1ST . " $parent_date_str</a>";
2424
                } else {
2425
                    $rrule .= '<br> ' . _APCAL_MB_RRULE1ST;
2426
                }
2427
            }
2428
2429
            $cat_titles4show = '';
2430
            $cids            = explode(',', $event->categories);
2431
            foreach ($cids as $cid) {
2432
                $cid = (int)$cid;
2433
                if (isset($this->categories[$cid])) {
2434
                    $cat_titles4show .= "<a href='{$this->make_cal_link('', '', $cid, date('Y-n-j', $event->start))}'>" . $this->text_sanitizer_for_show($this->categories[$cid]->cat_title) . '</a>, ';
2435
                }
2436
            }
2437
            if ($cat_titles4show !== '') {
2438
                $cat_titles4show = substr($cat_titles4show, 0, -2);
2439
            }
2440
2441
            $submitter_info = $this->get_submitter_info($event->uid);
2442
2443
            if ($event->class === 'PRIVATE') {
2444
                $groupid = (int)$event->groupid;
2445
                if ($groupid == 0) {
2446
                    $group = _APCAL_OPT_PRIVATEMYSELF;
2447
                } elseif (isset($this->groups[$groupid])) {
2448
                    $group = sprintf(_APCAL_OPT_PRIVATEGROUP, $this->groups[$groupid]);
2449
                } else {
2450
                    $group = _APCAL_OPT_PRIVATEINVALID;
2451
                }
2452
                $class_status = _APCAL_MB_PRIVATE . sprintf(_APCAL_MB_PRIVATETARGET, $group);
2453
            } else {
2454
                $class_status = _APCAL_MB_PUBLIC;
2455
            }
2456
2457
            $admission_status = $event->admission ? _APCAL_MB_EVENT_ADMITTED : _APCAL_MB_EVENT_NEEDADMIT;
2458
            $last_modified    = $this->get_long_ymdn($event->udtstamp - (int)(($this->user_TZ - $this->server_TZ) * 3600));
2459
            $description      = $this->textarea_sanitizer_for_show($event->description);
2460
            $summary          = $this->text_sanitizer_for_show($event->summary);
2461
            $location         = $this->text_sanitizer_for_show($event->location);
2462
            $contact          = $this->text_sanitizer_for_show($event->contact);
2463
            $contact          = convertmycontacts($contact); // added one line by goffy: converting the contact name(s) into a link to member account this is not necessary for online registration
2464
            $email            = $this->text_sanitizer_for_show($event->email);
2465
            $url              = $this->text_sanitizer_for_show($event->url);
2466
            $url              = $url !== '' && substr($url, 0, 4) !== 'http' ? 'http://' . $url : $url;
2467
            $otherHour        = explode('-', $event->otherHours);
2468
            if ($otherHour[0] !== '') {
2469
                //$event->end += 300 ;
2470
                $h          = array(
2471
                    0,
2472
                    date('H', $event->start + $tzoffset),
2473
                    date('i', $event->start + $tzoffset),
2474
                    date('H', $event->end + $tzoffset),
2475
                    date('i', $event->end + $tzoffset)
2476
                );
2477
                $d          = $this->get_long_ymdn($event->start + ($h[0] * 3600 * 24) + $tzoffset);
2478
                $otherHours = '<br>' . $d . '&nbsp;&nbsp;&nbsp;&nbsp;' . sprintf('%02d', $h[1]) . ':' . sprintf('%02d', $h[2]) . ' - ' . sprintf('%02d', $h[3]) . ':' . sprintf('%02d', $h[4]);
2479
                foreach ($otherHour as $day) {
2480
                    $h          = explode(':', $day);
2481
                    $d          = $this->get_long_ymdn($event->start + ($h[0] * 3600 * 24) + $tzoffset);
2482
                    $otherHours .= '<br>' . $d . '&nbsp;&nbsp;&nbsp;&nbsp;' . sprintf('%02d', $h[1]) . ':' . sprintf('%02d', $h[2]) . ' - ' . sprintf('%02d', $h[3]) . ':' . sprintf('%02d', $h[4]);
2483
                }
2484
            }
2485
2486
            $this->last_summary = $summary;
2487
2488
            /********************************************************************/
2489
            /* added by goffy: code for online registration                     */
2490
            /********************************************************************/
2491
            $this->regonline = (int)$event->extkey0;
2492
            $registered      = 0;
2493
            if ($this->regonline == 1) {
2494
                $result_ro  = $GLOBALS['xoopsDB']->query('SELECT ' . XOOPS_DB_PREFIX . $this->table_ro_events . '.roe_number
2495
                FROM ' . XOOPS_DB_PREFIX . $this->table_ro_events . '
2496
                WHERE (((roe_eventid)=' . $event->id . '))');
2497
                $row        = $GLOBALS['xoopsDB']->fetchRow($result_ro);
2498
                $itemstotal = $row[0];
2499
                if ($itemstotal == 0) {
2500
                    //$eventmembersall = "No limit for online registration";
2501
                } else {
2502
                    $eventmembersall = _APCAL_RO_QUANTITY2 . ': ' . $itemstotal . '<br>';
2503
                }
2504
2505
                $result_ro  = $GLOBALS['xoopsDB']->query('SELECT Count(rom_id) AS countevents
2506
                FROM ' . XOOPS_DB_PREFIX . $this->table_ro_members . '
2507
                WHERE (((rom_eventid)=' . $event->id . '))');
2508
                $row        = $GLOBALS['xoopsDB']->fetchRow($result_ro);
2509
                $itemstotal = $row[0];
2510
                if ($itemstotal == 0) {
2511
                    $eventmembersall .= _APCAL_RO_NOMEMBERS;
0 ignored issues
show
Bug introduced by
The variable $eventmembersall does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
2512
                    $eventmembers    = '';
2513
                } else {
2514
                    $eventmembersall .= _APCAL_RO_ONLINE . ': ' . $itemstotal;
2515
                    if (!$this->user_id == 0 && $editable) {
2516
                        $eventmembers .= '<br>' . _APCAL_RO_UNAME . ':';
0 ignored issues
show
Bug introduced by
The variable $eventmembers seems only to be defined at a later point. Did you maybe move this code here without moving the variable definition?

This error can happen if you refactor code and forget to move the variable initialization.

Let’s take a look at a simple example:

function someFunction() {
    $x = 5;
    echo $x;
}

The above code is perfectly fine. Now imagine that we re-order the statements:

function someFunction() {
    echo $x;
    $x = 5;
}

In that case, $x would be read before it is initialized. This was a very basic example, however the principle is the same for the found issue.

Loading history...
2517
                    } else {
2518
                        $eventmembers = '';
2519
                    }
2520
                }
2521
2522
                if (!$this->user_id == 0) {
2523
                    if ($editable) {
2524
                        $result_ro = $GLOBALS['xoopsDB']->query('SELECT '
2525
                            . XOOPS_DB_PREFIX
2526
                            . '_users.uname,
2527
                    '
2528
                            . XOOPS_DB_PREFIX
2529
                            . '_users.uid, count(rom_id) as counter
2530
                    FROM '
2531
                            . XOOPS_DB_PREFIX
2532
                            . $this->table_ro_members
2533
                            . ' INNER JOIN '
2534
                            . XOOPS_DB_PREFIX
2535
                            . '_users ON '
2536
                            . XOOPS_DB_PREFIX
2537
                            . $this->table_ro_members
2538
                            . '.rom_submitter = '
2539
                            . XOOPS_DB_PREFIX
2540
                            . '_users.uid
2541
                    WHERE ((('
2542
                            . XOOPS_DB_PREFIX
2543
                            . $this->table_ro_members
2544
                            . '.rom_eventid)='
2545
                            . $event->id
2546
                            . ')) GROUP BY 1,2');
2547
                        $num_rows = $GLOBALS['xoopsDB']->getRowsNum($result_ro);
0 ignored issues
show
Unused Code introduced by
$num_rows is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
2548
                        $baseurl = XOOPS_URL;
0 ignored issues
show
Unused Code introduced by
$baseurl is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
2549
2550
                        while ($row = $GLOBALS['xoopsDB']->fetchRow($result_ro)) {
2551
                            $uname = $row[0];
2552
                            $uid = $row[1];
2553
                            $counter = $row[2];
2554
                            $eventmembers = (substr($eventmembers, strlen($eventmembers) - 1, 1) === ':') ? $eventmembers .= ' ' : $eventmembers .= ', ';
2555
                            $eventmembers .= "<a href='" . XOOPS_URL . '/userinfo.php?uid=' . $uid . "' title=" . $uname . '>' . $uname . '</a>';
2556
2557
                            if ($this->user_id == $uid) {
2558
                                $registered = 1;
2559
                            }
2560
                            if ($counter > 1) {
2561
                                $eventmembers .= ' (' . $counter . ')';
2562
                            }
2563
                        }
2564
                    }
2565
2566 View Code Duplication
                    if (!empty($_SERVER['HTTPS'])) {
0 ignored issues
show
Duplication introduced by
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...
2567
                        $this->redirecturl = 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
2568
                    } else {
2569
                        $this->redirecturl = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
2570
                    }
2571
                    
2572
                    $eventmembers_only = '';
2573
                    $eventmembers_form = '';
2574
                    if ($editable && !$for_print) {
2575
                        $eventmembers_form = "
2576
                            <form class='apcalForm' method='post' id='RegOnlineForm' action='ro_regonlinehandler.php' name='roformmembers1' style='margin:0px;'>
2577
                                <input type='hidden' name='eventid' value='$event->id' />
2578
                                <input type='hidden' name='uid' value='$this->user_id' />
2579
                                <input type='hidden' name='eventurl' value='$this->redirecturl' />
2580
                                <input type='hidden' name='summary' value='$summary' />
2581
                                <input type='hidden' name='date' value='$start_date_str' />
2582
                                <input type='hidden' name='eventdate' value='$event->start' />
2583
                                <input type='hidden' name='location' value='$location' />
2584
                                <div style='float:right;'>";
2585
                        if ($registered == 1) {
2586
                            $eventmembers_form .= "<input type='submit' name='form_add' value='" . _APCAL_RO_BTN_ADDMORE . "' />";
2587
                        } else {
2588
                            $eventmembers_form .= "<input type='submit' name='form_add' value='" . _APCAL_RO_BTN_ADD . "' />&nbsp;";
2589
                        }
2590
                        if ($editable && !$for_print && $itemstotal > 0) {
2591
                            $eventmembers_form .= "<input type='submit' name='list' value='" . _APCAL_RO_BTN_LISTMEMBERS . "' />";
2592
                        }
2593
                        $eventmembers_form .= "</div></form>\n";
2594
                    }
2595
                } else {
2596
                    $eventmembers_only = '<p>' . _APCAL_RO_ONLY_MEMBERS . '</p>';
2597
                    $eventmembers_only .= "<a class='btn btn-primary' href='" . XOOPS_URL . "/modules/profile/user.php?xoops_redirect=" . XOOPS_URL . "/modules/apcal/?event_id=$event->id&action=View' title=''>Einloggen</a>";
2598
                    $eventmembers_only .= "<br>Sie sind noch nicht als User registriert? Dann bitte zuerst <a class='btn btn-info cal-btn' href='" . XOOPS_URL . "/modules/profile/register.php' title=''>Registrieren</a>";
2599
2600
                }
2601
2602
                $eventmembertable = "
2603
        <tr>
2604
            <td class='head'>" . _APCAL_RO_ONLINE . "</td>
2605
            <td class='even'>
2606
                <div style='float:left; margin: 2px;'>$eventmembersall$eventmembers";
2607
                if ('' !== $eventmembers_only) {
2608
                    $eventmembertable .= $eventmembers_only;
2609
                }
2610
                $eventmembertable .= "</div>
2611
                <div style='float:left; margin: 2px;'>$eventmembers_form</div>
0 ignored issues
show
Bug introduced by
The variable $eventmembers_form does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
2612
            </td>
2613
        </tr>";
2614
            } else {
2615
                $eventmembertable = "
2616
        <tr>
2617
            <td class='head'>" . _APCAL_RO_ONLINE . "</td>
2618
            <td class='even'>
2619
                <div style='float:left; margin: 2px;'>" . _APCAL_RO_ONLINE_NO . '</div>
2620
            </td>
2621
        </tr>';
2622
            }
2623
            /*******************************************************************/
2624
            /* end added by goffy:                                             */
2625
            /*******************************************************************/
2626
2627
            $pictures = '';
2628
            $pics     = $GLOBALS['xoopsDB']->query("SELECT picture FROM {$this->pic_table} WHERE event_id={$event_id} ORDER BY main_pic DESC, id ASC LIMIT 0,{$this->nbPictures}");
2629
            while ($pic = $GLOBALS['xoopsDB']->fetchObject($pics)) {
2630
                if (!Thumb::exists($pic->picture)) {
2631
                    Thumb::save($pic->picture, $this->picWidth, $this->picHeight);
2632
                }
2633
                $pictures .= '<div style="padding: 10px 0;">
2634
                <a href="' . XOOPS_UPLOAD_URL . '/apcal/' . $pic->picture . '" class="highslide" onclick="return hs.expand(this)">
2635
                    <img src="' . XOOPS_UPLOAD_URL . '/apcal/thumbs/' . $pic->picture . '" alt="Image" />
2636
                </a>
2637
             </div>';
2638
            }
2639
2640
            if ($xoopsTpl) {
2641
                $prevEvent = $GLOBALS['xoopsDB']->query("SELECT id,start FROM $this->table WHERE id<{$event->id} AND start={$event->start} ORDER BY id DESC LIMIT 0,1");
2642
                $prevEvent = $GLOBALS['xoopsDB']->fetchObject($prevEvent);
2643 View Code Duplication
                if (!$prevEvent) {
0 ignored issues
show
Duplication introduced by
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...
2644
                    $prevEvent = $GLOBALS['xoopsDB']->query("SELECT id,start FROM $this->table WHERE start<{$event->start} ORDER BY start DESC LIMIT 0,1");
2645
                    $prevEvent = $GLOBALS['xoopsDB']->fetchObject($prevEvent);
2646
                }
2647
                $prevEvent = $prevEvent ? $this->make_event_link($prevEvent->id) : false;
2648
                $xoopsTpl->assign('prevEvent', $prevEvent);
2649
2650
                $nextEvent = $GLOBALS['xoopsDB']->query("SELECT id,start FROM $this->table WHERE id>{$event->id} AND start={$event->start} ORDER BY id ASC LIMIT 0,1");
2651
                $nextEvent = $GLOBALS['xoopsDB']->fetchObject($nextEvent);
2652 View Code Duplication
                if (!$nextEvent) {
0 ignored issues
show
Duplication introduced by
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...
2653
                    $nextEvent = $GLOBALS['xoopsDB']->query("SELECT id,start FROM $this->table WHERE start>{$event->start} ORDER BY start ASC LIMIT 0,1");
2654
                    $nextEvent = $GLOBALS['xoopsDB']->fetchObject($nextEvent);
2655
                }
2656
                $nextEvent = $nextEvent ? $this->make_event_link($nextEvent->id) : false;
2657
                $xoopsTpl->assign('nextEvent', $nextEvent);
2658
2659
                $xoopsTpl->assign('title', $summary);
2660
                $xoopsTpl->assign('location', $location);
2661
                $xoopsTpl->assign('contact', $contact);
2662
                $xoopsTpl->assign('email', $email);
2663
                $xoopsTpl->assign('url', $url);
2664
                $xoopsTpl->assign('startdate', date('Y-n-j', $event->start));
2665
                $xoopsTpl->assign('calLink', $this->make_cal_link('', '', 0, date('Y-n-j', $event->start)));
2666
                $xoopsTpl->assign('GMLat', $event->gmlat);
2667
                $xoopsTpl->assign('GMLong', $event->gmlong);
2668
                $xoopsTpl->assign('GMZoom', $event->gmzoom);
2669
                $xoopsTpl->assign('GMheight', $this->gmheight . 'px');
2670
                $xoopsTpl->assign('eventNavEnabled', $this->eventNavEnabled);
2671
                $xoopsTpl->assign('picsWidth', $pictures !== '' ? ($this->picWidth + 10) . 'px' : 0);
2672
                $xoopsTpl->assign('picsMargin', $pictures !== '' ? ($this->picWidth + 20) . 'px' : 0);
2673
                $xoopsTpl->assign('pictures', $pictures);
2674
                $xoopsTpl->assign('showPrint', $this->enableprint);
2675
            }
2676
2677
            $ret = "
2678
    <table border='0' cellpadding='0' cellspacing='2'>";
2679
            $ret .= ($summary !== '') ? "
2680
    <tr>
2681
        <td class='head'>" . _APCAL_TH_SUMMARY . "</td>
2682
        <td class='even'>$summary</td>
2683
    </tr>" : '';
2684
            $ret .= "
2685
    <tr>
2686
        <td class='head'>" . _APCAL_TH_STARTDATETIME . "</td>
2687
        <td class='even'>$start_datetime_str</td>
2688
    </tr>
2689
    <tr>
2690
        <td class='head'>" . _APCAL_TH_ENDDATETIME . "</td>
2691
        <td class='even'>$end_datetime_str</td>
2692
        </tr>";
2693
            $ret .= ($location !== '') ? "
2694
    <tr>
2695
        <td class='head'>" . _APCAL_TH_LOCATION . "</td>
2696
        <td class='even'>$location</td>
2697
    </tr>" : '';
2698
            $ret .= ($contact !== '') ? "
2699
    <tr>
2700
        <td class='head'>" . _APCAL_TH_CONTACT . "</td>
2701
        <td class='even'>$contact</td>
2702
    </tr>" : '';
2703
            $ret .= ($email !== '') ? "
2704
    <tr>
2705
        <td class='head'>" . _APCAL_TH_EMAIL . "</td>
2706
        <td class='even'><a href='mailto:$email'>$email</a></td>
2707
    </tr>" : '';
2708
            $ret .= ($url !== '') ? "
2709
    <tr>
2710
        <td class='head'>" . _APCAL_TH_URL . "</td>
2711
        <td class='even'><a href='$url' target='_blank'>$url</a></td>
2712
    </tr>" : '';
2713
            $ret .= ($description !== '' || $otherHours !== '') ? "
0 ignored issues
show
Bug introduced by
The variable $otherHours does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
2714
    <tr>
2715
        <td class='head'>" . _APCAL_TH_DESCRIPTION . "</td>
2716
        <td class='even'>$description<br>$otherHours</td>
2717
    </tr>" : '';
2718
            $ret .= ($cat_titles4show !== '') ? "
2719
    <tr>
2720
        <td class='head'>" . _APCAL_TH_CATEGORIES . "</td>
2721
        <td class='even'>$cat_titles4show</td>
2722
    </tr>" : '';
2723
            $ret .= ($this->superedit ? "
2724
    <tr>
2725
        <td class='head'>" . _APCAL_TH_SUBMITTER . "</td>
2726
        <td class='even'>$submitter_info</td>
2727
    </tr>
2728
    <tr>
2729
        <td class='head'>" . _APCAL_TH_CLASS . "</td>
2730
        <td class='even'>$class_status</td>
2731
    </tr>
2732
    <tr>
2733
        <td class='head'>" . _APCAL_TH_RRULE . "</td>
2734
        <td class='even'>$rrule</td>
2735
    </tr>
2736
    <tr>
2737
        <td class='head'>" . _APCAL_TH_ADMISSIONSTATUS . "</td>
2738
        <td class='even'>$admission_status</td>
2739
    </tr>
2740
    " : '') . "
2741
    <tr>
2742
        <td class='head'>" . _APCAL_TH_LASTMODIFIED . "</td>
2743
        <td class='even'>$last_modified</td>
2744
    </tr>" . ($this->enableregistration ? $eventmembertable : '') // goffy
2745
                    . "<tr>
2746
        <td></td>
2747
        <td align='center'>
2748
            <div style='float:left; margin: 2px;'>$edit_button</div>
2749
            <div style='float:left; margin: 2px;'>$delete_button</div>
2750
            <div style='float:left; margin: 2px;'>$ics_output_button</div>
2751
        </td>
2752
    </tr>
2753
    <tr>
2754
        <td><img src='$this->images_url/spacer.gif' alt='' width='150' height='4' /></td>       <td width='100%'></td>
2755
    </tr>
2756
    <tr>
2757
        <td width='100%' align='right' colspan='2'>" . _MD_APCAL_COPYRIGHT . "</td>
2758
    </tr>
2759
    </table>
2760
    \n";
2761
2762
            return $ret;
2763
        }
2764
2765
        // Edit an event form
2766
2767
        /**
2768
         * @return string
0 ignored issues
show
Documentation introduced by
Should the return type not be null|string?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
2769
         */
2770
        public function get_schedule_edit_html()
2771
        {
2772
            $editable  = $this->editable;
2773
            $superedit = $this->superedit;
2774
            $deletable = $this->deletable;
2775
            $smode     = empty($_GET['smode']) ? 'Monthly' : preg_replace('/[^a-zA-Z0-9_-]/', '', $_GET['smode']);
2776
2777
            if (!empty($_GET['event_id'])) {
2778
                if (!$this->editable) {
2779
                    die('Not allowed');
2780
                }
2781
2782
                $event_id = (int)$_GET['event_id'];
2783
                $yrs      = $GLOBALS['xoopsDB']->query("SELECT * FROM $this->table WHERE id='$event_id'");
2784
                if ($GLOBALS['xoopsDB']->getRowsNum($yrs) < 1) {
2785
                    die(_APCAL_ERR_INVALID_EVENT_ID);
2786
                }
2787
                $event = $GLOBALS['xoopsDB']->fetchObject($yrs);
2788
2789
                // submitter of event
2790
                if ($event->uid != $this->user_id) {
2791
                    $editable  = false;
2792
                    $deletable = false;
2793
                }
2794
                // user is admin or has right to edit/delete all events
2795
                if ($this->isadmin || $superedit) {
2796
                    $editable  = true;
2797
                    $deletable = true;
2798
                }
2799
2800
                $description  = $this->textarea_sanitizer_for_edit($event->description);
2801
                $summary      = $this->text_sanitizer_for_edit($event->summary);
2802
                $location     = $this->text_sanitizer_for_edit($event->location);
2803
                $gmlat        = $event->gmlat != 0 ? $event->gmlat : 0;
2804
                $gmlong       = $event->gmlong != 0 ? $event->gmlong : 0;
2805
                $gmzoom       = $event->gmzoom > 0 ? $event->gmzoom : 0;
2806
                $contact      = $this->text_sanitizer_for_edit($event->contact);
2807
                $email        = $this->text_sanitizer_for_edit($event->email);
2808
                $url          = $this->text_sanitizer_for_edit($event->url);
2809
                $categories   = $event->categories;
2810
                $mainCategory = $event->mainCategory;
2811
                if ($event->class === 'PRIVATE') {
2812
                    $class_private           = 'checked';
2813
                    $class_public            = '';
2814
                    $select_private_disabled = '';
2815
                } else {
2816
                    $class_private           = '';
2817
                    $class_public            = 'checked';
2818
                    $select_private_disabled = "disabled='disabled'";
2819
                }
2820
                $groupid          = $event->groupid;
2821
                $rrule            = $event->rrule;
2822
                $admission_status = $event->admission ? _APCAL_MB_EVENT_ADMITTED : _APCAL_MB_EVENT_NEEDADMIT;
2823
                $update_button    = $editable ? "<input name='update' type='submit' value='" . _APCAL_BTN_SUBMITCHANGES . "' />" : '';
2824
                $insert_button    = "<input name='saveas' type='submit' value='" . _APCAL_BTN_SAVEAS . "' onclick='return confirm(\"" . _APCAL_CNFM_SAVEAS_YN . "\")' />";
2825
                $delete_button    = $deletable ? "<input name='delete' type='submit' value='" . _APCAL_BTN_DELETE . "' onclick='return confirm(\"" . _APCAL_CNFM_DELETE_YN . "\")' />" : '';
2826
                $tz_options       = $this->get_tz_options($event->event_tz);
2827
                $poster_tz        = $event->poster_tz;
2828
2829
                // added by goffy for online registration
2830 View Code Duplication
                if (!empty($_SERVER['HTTPS'])) {
0 ignored issues
show
Duplication introduced by
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...
2831
                    $this->redirecturl = 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
2832
                } else {
2833
                    $this->redirecturl = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
2834
                }
2835
2836
                $regonline_label = _APCAL_RO_ENABLE_ONLINE;
0 ignored issues
show
Unused Code introduced by
$regonline_label is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
2837
                $regonline_state = ($event->extkey0 == 1) ? _APCAL_RO_ONLINE_YES : _APCAL_RO_ONLINE_NO;
2838
2839
                $regonline_state .= "
2840
        <form class='apcalForm' method='post' id='RegOnlineForm' action='ro_regonlinehandler.php' name='roformactivate1' style='margin:0px;'>
2841
            <input type='hidden' name='eventid' value='$event->id' />
2842
            <input type='hidden' name='uid' value='$this->user_id' />
2843
            <input type='hidden' name='eventurl' value='$this->redirecturl' />
2844
            <input type='hidden' name='title' value='$event->summary' />
2845
            <input type='hidden' name='eventdate' value='$event->start' />
2846
            <input type='hidden' name='location' value='$event->location' />
2847
            <div align='left'>";
2848
                if ($event->extkey0 == 1) {
2849
                    $regonline_state .= "
2850
                <input type='submit' name='form_activate' value='" . _APCAL_RO_BTN_RO_EDIT . "' />
2851
                <input type='submit' name='deactivate_x' value='" . _APCAL_RO_BTN_RO_DEACTIVATE . "' />";
2852
                } else {
2853
                    $regonline_state .= "<input type='submit' name='form_activate' value='" . _APCAL_RO_BTN_RO_ACTIVATE . "' />";
2854
                }
2855
                $regonline_state .= '</div>
2856
        </form>';
2857
2858
                $ro_form_edit = "<table>
2859
            <tr>
2860
                <td class='odd' colspan='2'></td>
2861
            </tr>
2862
            <tr>
2863
                <td class='head'>" . _APCAL_RO_ENABLE_ONLINE . "</td>
2864
                <td class='even'>" . $regonline_state . '</td>
2865
            </tr></table>';
2866
                $ro_form_new  = '';
2867
                // end added by goffy
2868
2869
                //$tmpEnd = date('H:i', $event->end) == '00:00' ? $event->end - 300 : $event->end;
2870
                $diff = date('j', $event->end) - date('j', $event->start);
2871
                if ($event->otherHours !== '' /*&& $event->allday <= 0*/) {
2872
                    $diffhours_checkbox = 'checked';
2873
                    $otherHours         = explode('-', $event->otherHours);
2874
                    foreach ($otherHours as $h) {
2875
                        $h          = explode(':', $h);
2876
                        $startHours .= "<span name='StartSpan'>" . _APCAL_DAY . '&nbsp;' . ($h[0] + 1);
0 ignored issues
show
Bug introduced by
The variable $startHours does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
2877
                        $startHours .= "<select name='StartH[]'>" . $this->get_options_for_hour($h[1]) . '</select>';
2878
                        $startHours .= "<select name='StartM[]'>" . $this->get_options_for_min($h[2]) . '</select></span>';
2879
                        $endHours   .= "<span name='EndSpan'>" . _APCAL_DAY . '&nbsp;' . ($h[0] + 1);
0 ignored issues
show
Bug introduced by
The variable $endHours does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
2880
                        $endHours   .= "<select name='EndH[]'>" . $this->get_options_for_hour($h[3]) . '</select>';
2881
                        $endHours   .= "<select name='EndM[]'>" . $this->get_options_for_min($h[4]) . '</select></span>';
2882
                    }
2883
                } elseif ($diff > 0 /*&& $event->allday == 0*/) {
2884
                    //$samehours_checkbox = "checked";
2885
                    for ($i = 0; $i < $diff; ++$i) {
2886
                        $startHours .= '<span>' . _APCAL_DAY . '&nbsp;' . ($i + 2);
2887
                        $startHours .= "<select name='StartH[]' disabled>" . $this->get_options_for_hour(9) . '</select>';
2888
                        $startHours .= "<select name='StartM[]' disabled>" . $this->get_options_for_min(0) . '</select></span>';
2889
                        $endHours   .= '<span>' . _APCAL_DAY . '&nbsp;' . ($i + 2);
2890
                        $endHours   .= "<select name='EndH[]' disabled>" . $this->get_options_for_hour(17) . '</select>';
2891
                        $endHours   .= "<select name='EndM[]' disabled>" . $this->get_options_for_min(0) . '</select></span>';
2892
                    }
2893
                }
2894
2895
                if ($event->allday) {
2896
                    $select_timezone_disabled = "disabled='disabled'";
2897
                    $tzoffset_s2e             = (int)(($event->event_tz - $this->server_TZ) * 3600);
2898
                    $event->start             += $tzoffset_s2e;
2899
                    $event->end               += $tzoffset_s2e;
2900
                    $allday_checkbox          = 'checked';
2901
                    $allday_select            = $event->allday == 5 ? "disabled='disabled'" : '';
2902
                    $allday_bit1              = ($event->allday & 2) ? 'checked' : '';
0 ignored issues
show
Unused Code introduced by
$allday_bit1 is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
2903
                    $allday_bit2              = ($event->allday & 4) ? 'checked' : '';
0 ignored issues
show
Unused Code introduced by
$allday_bit2 is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
2904
                    $allday_bit3              = ($event->allday & 8) ? 'checked' : '';
0 ignored issues
show
Unused Code introduced by
$allday_bit3 is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
2905
                    $allday_bit4              = ($event->allday & 16) ? 'checked' : '';
0 ignored issues
show
Unused Code introduced by
$allday_bit4 is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
2906
                    if (isset($event->start_date)) {
2907
                        $start_ymd = $start_long_ymdn = $event->start_date;
2908
                    } else {
2909
                        $start_ymd       = date('Y-m-d', $event->start);
2910
                        $start_long_ymdn = $this->get_long_ymdn($event->start);
2911
                    }
2912
                    $start_hour = date('H', $event->start);
2913
                    $start_min  = date('i', $event->start);
2914
                    if (isset($event->end_date)) {
2915
                        $end_ymd = $end_long_ymdn = $event->end_date;
2916
                    } else {
2917
                        $end_ymd       = date('Y-m-d', $event->end);
2918
                        $end_long_ymdn = $this->get_long_ymdn($event->end);
2919
                    }
2920
                    $end_hour = date('H', $event->end);
2921
                    $end_min  = date('i', $event->end);
2922
                } else {
2923
                    $select_timezone_disabled = '';
2924
                    $tzoffset_s2e             = (int)(($event->event_tz - $this->server_TZ) * 3600);
2925
                    $event->start             += $tzoffset_s2e;
2926
                    $event->end               += $tzoffset_s2e;
2927
                    $allday_checkbox          = '';
2928
                    if (!isset($samehours_checkbox) && !isset($samehours_checkbox)) {
0 ignored issues
show
Bug introduced by
The variable $samehours_checkbox seems only to be defined at a later point. As such the call to isset() seems to always evaluate to false.

This check marks calls to isset(...) or empty(...) that are found before the variable itself is defined. These will always have the same result.

This is likely the result of code being shifted around. Consider removing these calls.

Loading history...
2929
                        $samehours_checkbox = 'checked';
2930
                    }
2931
                    $allday_select   = '';
2932
                    $allday_bit1     = $allday_bit2 = $allday_bit3 = $allday_bit4 = '';
0 ignored issues
show
Unused Code introduced by
$allday_bit4 is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
Unused Code introduced by
$allday_bit3 is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
Unused Code introduced by
$allday_bit2 is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
Unused Code introduced by
$allday_bit1 is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
2933
                    $start_ymd       = date('Y-m-d', $event->start);
2934
                    $start_long_ymdn = $this->get_long_ymdn($event->start);
2935
                    $start_hour      = date('H', $event->start);
2936
                    $start_min       = date('i', $event->start);
2937
                    $end_ymd         = date('Y-m-d', $event->end);
2938
                    $end_long_ymdn   = $this->get_long_ymdn($event->end);
2939
                    $end_hour        = date('H', $event->end);
2940
                    $end_min         = date('i', $event->end);
2941
                }
2942
            } else {
2943
                if (!$this->insertable) {
2944
                    die('Not allowed');
2945
                }
2946
2947
                $event_id = 0;
2948
2949
                $editable                 = true;
2950
                $summary                  = '';
2951
                $select_timezone_disabled = '';
2952
                $location                 = '';
2953
                $gmlat                    = 0;
2954
                $gmlong                   = 0;
2955
                $gmzoom                   = 0;
2956
                $contact                  = '';
2957
                $email                    = '';
2958
                $url                      = '';
2959
                $class_private            = '';
2960
                $class_public             = 'checked';
2961
                $select_private_disabled  = "disabled='disabled'";
2962
                $groupid                  = 0;
2963
                $rrule                    = '';
2964
                $description              = '';
2965
                $categories               = $this->now_cid > 0 ? sprintf('%05d,', $this->now_cid) : '';
2966
                $mainCategory             = $this->now_cid > 0 ? sprintf('%05d,', $this->now_cid) : 0;
2967
                $start_ymd                = $end_ymd = $this->caldate;
2968
                $start_long_ymdn          = $end_long_ymdn = $this->get_long_ymdn($this->unixtime);
2969
                $start_hour               = 9;
2970
                $start_min                = 0;
2971
                $end_hour                 = 17;
2972
                $end_min                  = 0;
2973
                $admission_status         = _APCAL_MB_EVENT_NOTREGISTER;
2974
                $update_button            = '';
2975
                $insert_button            = "<input name='insert' type='submit' value='" . _APCAL_BTN_NEWINSERTED . "' />";
2976
                $delete_button            = '';
2977
                $allday_checkbox          = $allday_select = '';
2978
                $allday_bit1              = $allday_bit2 = $allday_bit3 = $allday_bit4 = '';
0 ignored issues
show
Unused Code introduced by
$allday_bit4 is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
Unused Code introduced by
$allday_bit3 is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
Unused Code introduced by
$allday_bit2 is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
Unused Code introduced by
$allday_bit1 is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
2979
                $tz_options               = $this->get_tz_options($this->user_TZ);
2980
                $poster_tz                = $this->user_TZ;
2981
2982
                // added by goffy for online registration
2983
                $regonline_label = _APCAL_RO_ONLINE2;
0 ignored issues
show
Unused Code introduced by
$regonline_label is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
2984
                $regonline_state = _APCAL_RO_ONLINE_NO;
0 ignored issues
show
Unused Code introduced by
$regonline_state is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
2985
                $ro_form_edit    = '';
2986
                $ro_form_new     = "
2987
            <tr>
2988
                <td class='head'>" . _APCAL_RO_ONLINE2 . "</td>
2989
                <td class='even'>
2990
                    <input type='radio' name='ro_activate' value='yes' > " . _APCAL_RO_ONLINE_ACTIVATE . "<br>
2991
                    <input type='radio' name='ro_activate' value='no' checked> " . _APCAL_RO_ONLINE_DEACTIVATE . '
2992
                </td>
2993
            </tr>';
2994
                // end goffy
2995
            }
2996
2997
            // Start Date
2998
            $textbox_start_date = $this->get_formtextdateselect('StartDate', $start_ymd, $start_long_ymdn);
0 ignored issues
show
Unused Code introduced by
The call to APCal::get_formtextdateselect() has too many arguments starting with $start_long_ymdn.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
2999
3000
            // Start Hour
3001
            $select_start_hour = "<select name='StartHour' $allday_select>\n";
3002
            $select_start_hour .= $this->get_options_for_hour($start_hour);
3003
            $select_start_hour .= '</select>';
3004
3005
            // Start Minutes
3006
            $select_start_min = "<select name='StartMin' $allday_select>\n";
3007
            for ($m = 0; $m < 60; $m += 5) {
3008
                if ($m == $start_min) {
3009
                    $select_start_min .= "<option value='$m' selected>" . sprintf('%02d', $m) . "</option>\n";
3010
                } else {
3011
                    $select_start_min .= "<option value='$m'>" . sprintf('%02d', $m) . "</option>\n";
3012
                }
3013
            }
3014
            $select_start_min .= '</select>';
3015
3016
            // End Date
3017
            $textbox_end_date = $this->get_formtextdateselect('EndDate', $end_ymd, $end_long_ymdn);
0 ignored issues
show
Unused Code introduced by
The call to APCal::get_formtextdateselect() has too many arguments starting with $end_long_ymdn.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
3018
3019
            // End Hour
3020
            $select_end_hour = "<select name='EndHour' $allday_select>\n";
3021
            $select_end_hour .= $this->get_options_for_hour($end_hour);
3022
            $select_end_hour .= '</select>';
3023
3024
            // End Minutes
3025
            $select_end_min = "<select name='EndMin' $allday_select>\n";
3026
            for ($m = 0; $m < 60; $m += 5) {
3027
                if ($m == $end_min) {
3028
                    $select_end_min .= "<option value='$m' selected>" . sprintf('%02d', $m) . "</option>\n";
3029
                } else {
3030
                    $select_end_min .= "<option value='$m'>" . sprintf('%02d', $m) . "</option>\n";
3031
                }
3032
            }
3033
            $select_end_min .= '</select>';
3034
3035
            // Checkbox for selecting Categories
3036
            $category_checkboxes = '';
3037
            foreach ($this->categories as $cid => $cat) {
3038
                $cid4sql        = sprintf('%05d,', $cid);
3039
                $cat_title4show = $this->text_sanitizer_for_show($cat->cat_title);
3040
                if ($cat->cat_depth < 2) {
3041
                    $category_checkboxes .= "<div style='float:left; margin:2px;'>\n";
3042
                }
3043
                $category_checkboxes .= str_repeat('-', $cat->cat_depth - 1)
3044
                                        . "<input type='checkbox' name='cids[]' value='$cid' "
3045
                                        . (strstr($categories, $cid4sql) ? 'checked' : '')
3046
                                        . " />$cat_title4show<br>\n";
3047
            }
3048
            $category_checkboxes = substr(str_replace('<div', '</div><div', $category_checkboxes), 6) . "</div>\n";
3049
3050
            // Select for selecting main category
3051
            $category_select = "<select name='mainCategory'>\n";
3052
            $category_select .= "<option  value='0' " . ($mainCategory == 0 ? 'selected' : '') . ' />' . _APCAL_NONE . "</option>\n";
3053
            foreach ($this->canbemain_cats as $cid => $cat) {
3054
                $cat_title4show  = $this->text_sanitizer_for_show($cat->cat_title);
3055
                $category_select .= "<option  value='$cid' " . ($mainCategory == $cid ? 'selected' : '') . ' />' . str_repeat('&nbsp;&nbsp;', $cat->cat_depth - 1) . " $cat_title4show</option>\n";
3056
            }
3057
            $category_select .= "</select>\n";
3058
3059
            // target for "class = PRIVATE"
3060
            $select_private = "<select name='groupid' $select_private_disabled>\n<option value='0'>" . _APCAL_OPT_PRIVATEMYSELF . "</option>\n";
3061
            foreach ($this->groups as $sys_gid => $gname) {
3062
                $option_desc = sprintf(_APCAL_OPT_PRIVATEGROUP, $gname);
3063
                if ($sys_gid == $groupid) {
3064
                    $select_private .= "<option value='$sys_gid' selected>$option_desc</option>\n";
3065
                } else {
3066
                    $select_private .= "<option value='$sys_gid'>$option_desc</option>\n";
3067
                }
3068
            }
3069
            $select_private .= '</select>';
3070
3071
            if (defined('XOOPS_ROOT_PATH')) {
3072
                require_once XOOPS_ROOT_PATH . '/include/xoopscodes.php';
3073
                ob_start();
3074
                $GLOBALS['description_text'] = $description;
3075
                xoopsCodeTarea('description_text', 50, 6);
3076
                $description_textarea = ob_get_contents();
3077
                ob_end_clean();
3078
            } else {
3079
                $description_textarea = "<textarea name='description' cols='50' rows='6' wrap='soft'>$description</textarea>";
3080
            }
3081
3082
            // MAIN PICTURE
3083
            $picture = $event_id > 0 ? $GLOBALS['xoopsDB']->query("SELECT id, picture FROM {$this->pic_table} WHERE event_id={$event_id} AND main_pic=1 LIMIT 0,1") : false;
3084
            if ($GLOBALS['xoopsDB']->getRowsNum($picture)) {
3085
                $picture = $GLOBALS['xoopsDB']->fetchObject($picture);
3086
                $mainPic = '<div id=mainPicture>
3087
                <a href="' . XOOPS_UPLOAD_URL . '/apcal/' . $picture->picture . '">
3088
                    <img src="' . XOOPS_URL . '/modules/apcal/thumbs/phpThumb.php?src=' . XOOPS_UPLOAD_PATH . '/apcal/' . $picture->picture . '&h=120&w=120" alt="" />
3089
                 </a>
3090
                 <a href="javascript:deletePic(\'' . XOOPS_URL . '\', ' . $picture->id . ', ' . $event_id . ', 1, ' . $this->nbPictures . ');" title="Delete picture">
3091
                     <img src="' . XOOPS_URL . '/modules/apcal/assets/images/delete.png" border="0" alt="Delete picture" />
3092
                 </a>
3093
             </div>';
3094
            } else {
3095
                $mainPic = '<input type="hidden" name="MAX_FILE_SIZE" value="5000000" />
3096
            <input type="file" name="picture0" id="picture0" />
3097
            <input type="hidden" name="files[]" id="files[]" value="picture0">';
3098
            }
3099
3100
            // OTHER PICTURES
3101
            $nbPictures   = $event_id
3102
                            > 0 ? $GLOBALS['xoopsDB']->fetchObject($GLOBALS['xoopsDB']->query("SELECT COUNT(id) AS count FROM {$this->pic_table} WHERE event_id={$event_id} AND main_pic=0"))->count : 0;
3103
            $picturesList = '';
3104
            if ($nbPictures > 0) {
3105
                $pictures = $GLOBALS['xoopsDB']->query("SELECT id, picture FROM {$this->pic_table} WHERE event_id={$event_id} AND main_pic=0 ORDER BY id ASC");
3106
                while ($pic = $GLOBALS['xoopsDB']->fetchObject($pictures)) {
3107
                    $picturesList .= '<span id="pic' . $pic->id . '">
3108
                    <a href="' . XOOPS_UPLOAD_URL . '/apcal/' . $pic->picture . '">
3109
                        <img src="' . XOOPS_URL . '/modules/apcal/thumbs/phpThumb.php?src=' . XOOPS_UPLOAD_PATH . '/apcal/' . $pic->picture . '&h=120&w=120" alt="" />
3110
                     </a>
3111
                     <a href="javascript:deletePic(\'' . XOOPS_URL . '\', ' . $pic->id . ', ' . $event_id . ', 0, ' . $this->nbPictures . ');" title="Delete the picture">
3112
                         <img src="' . XOOPS_URL . '/modules/apcal/assets/images/delete.png" border="0" alt="Delete the picture" />
3113
                     </a>
3114
                 </span>';
3115
                }
3116
            }
3117
            $pictures = '<div id="picList">';
3118
            $maxInput = $this->nbPictures - $nbPictures;
3119
            for ($i = 1; $i < $maxInput; ++$i) {
3120
                $pictures .= '<input type="hidden" name="MAX_FILE_SIZE" value="5000000" />
3121
            <input type="file" name="picture' . $i . '" id="picture' . $i . '" />
3122
            <input type="hidden" name="files[]" id="files[]" value="picture' . $i . '">
3123
            <br>';
3124
            }
3125
            $pictures .= '</div>';
3126
3127
            // FORM DISPLAY
3128
            $caldate = explode('-', $_GET['caldate']);
3129
            $caldate = strlen($caldate[0]) > 2 ? $caldate[0] . '-' . $caldate[1] . '-' . $caldate[2] : $caldate[2] . '-' . $caldate[1] . '-' . $caldate[0];
3130
            $ret     = '
3131
<h2>'
3132
                       . _APCAL_MB_TITLE_EVENTINFO
3133
                       . ' <small>-'
3134
                       . _APCAL_MB_SUBTITLE_EVENTEDIT
3135
                       . "-</small></h2>
3136
<form class='apcalForm' action='{$this->make_cal_link('', $smode, 0, $caldate)}' method='post' id='MainForm' name='MainForm' enctype='multipart/form-data'>
3137
    "
3138
                       . $GLOBALS['xoopsGTicket']->getTicketHtml(__LINE__)
3139
                       . "
3140
    <input type='hidden' name='caldate' value='{$caldate}' />
3141
    <input type='hidden' name='event_id' value='$event_id' />
3142
    <input type='hidden' name='last_smode' value='$smode' />
3143
    <input type='hidden' name='last_caldate' value='$this->caldate' />
3144
    <input type='hidden' name='poster_tz' value='$poster_tz' />
3145
    <input type='hidden' name='gmlatitude' value='$this->gmlat' />
3146
    <input type='hidden' name='gmlongitude' value='$this->gmlng' />
3147
    <input type='hidden' name='gmzoomlevel' value='$this->gmzoom' />
3148
    <table border='0' cellpadding='0' cellspacing='2'>
3149
    <tr>
3150
        <td class='head'>"
3151
                       . _APCAL_TH_SUMMARY
3152
                       . "</td>
3153
        <td class='even'><input type='text' name='summary' size='60' maxlength='250' value='$summary' /></td>
3154
    </tr>"
3155
                       . ($this->displayTimezone ? "<tr>
3156
        <td class='head'>" . _APCAL_TH_TIMEZONE . "</td>
3157
        <td class='even'><select name='event_tz' $select_timezone_disabled>$tz_options</select></td>
3158
    </tr>" : '')
3159
                       . "<tr>
3160
        <td class='head'>"
3161
                       . _APCAL_TH_STARTDATETIME
3162
                       . "</td>
3163
        <td class='even'>
3164
            $textbox_start_date &nbsp;
3165
            {$select_start_hour} {$select_start_min}"
3166
                       . _APCAL_MB_MINUTE_SUF
3167
                       . "</select>
3168
            <span id='start_datetime'>$startHours</span>
3169
        </td>
3170
    </tr>
3171
    <tr>
3172
        <td class='head'>"
3173
                       . _APCAL_TH_ENDDATETIME
3174
                       . "</td>
3175
        <td class='even'>
3176
            $textbox_end_date &nbsp;
3177
            {$select_end_hour} {$select_end_min}"
3178
                       . _APCAL_MB_MINUTE_SUF
3179
                       . "
3180
            <span id='end_datetime'>$endHours</span>
3181
        </td>
3182
    </tr>
3183
    <tr>
3184
        <td class='head'>"
3185
                       . _APCAL_TH_ALLDAYOPTIONS
3186
                       . "</td>
3187
        <td class='even'>
3188
            <input type='radio' name='allday_bits[]' value='2' {$allday_checkbox} onClick='document.MainForm.StartHour.disabled=document.MainForm.StartMin.disabled=document.MainForm.EndHour.disabled=document.MainForm.EndMin.disabled=true;enableSelects(true);' />"
3189
                       . _APCAL_MB_ALLDAY_EVENT
3190
                       . " &nbsp;
3191
            <input type='radio' name='allday_bits[]' value='0' {$samehours_checkbox} onClick='document.MainForm.StartHour.disabled=document.MainForm.StartMin.disabled=document.MainForm.EndHour.disabled=document.MainForm.EndMin.disabled=false;enableSelects(true);' />"
0 ignored issues
show
Bug introduced by
The variable $samehours_checkbox does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
3192
                       . _APCAL_SAMEHOURS
3193
                       . " &nbsp;
3194
            <input type='radio' name='allday_bits[]' value='8' {$diffhours_checkbox} onClick='document.MainForm.StartHour.disabled=document.MainForm.StartMin.disabled=document.MainForm.EndHour.disabled=document.MainForm.EndMin.disabled=false;enableSelects(false);' />"
0 ignored issues
show
Bug introduced by
The variable $diffhours_checkbox does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
3195
                       . _APCAL_DIFFERENTHOURS
3196
                       . "
3197
        </td>
3198
    </tr>
3199
    <tr>
3200
        <td class='head'>"
3201
                       . _APCAL_TH_LOCATION
3202
                       . "</td>
3203
        <td class='even'><input type='text' id='location' name='location' size='40' maxlength='250' value='$location' /></td>
3204
    </tr>
3205
        <tr>
3206
        <td class='head'></td>
3207
        <td class='even' valign='top'>
3208
                    <a href='' onclick=\"window.open('"
3209
                       . XOOPS_URL
3210
                       . "/modules/apcal/getCoords.php', '_blank', 'height=450,width=550,modal=yes,alwaysRaised=yes');return false;\">
3211
                        <img src='"
3212
                       . XOOPS_URL
3213
                       . "/modules/apcal/assets/images/gmap.png' />"
3214
                       . _APCAL_TH_GETCOORDS
3215
                       . "</a>
3216
                </td>
3217
    </tr>
3218
        <tr>
3219
        <td class='head'>"
3220
                       . _APCAL_TH_LATITUDE
3221
                       . "</td>
3222
        <td class='even'><input type='text' name='gmlat' size='40' maxlength='250' value='$gmlat' /></td>
3223
    </tr>
3224
        <tr>
3225
        <td class='head'>"
3226
                       . _APCAL_TH_LONGITUDE
3227
                       . "</td>
3228
        <td class='even'><input type='text' name='gmlong' size='40' maxlength='250' value='$gmlong' /></td>
3229
    </tr>
3230
        <tr>
3231
        <td class='head'>"
3232
                       . _APCAL_TH_ZOOM
3233
                       . "</td>
3234
        <td class='even'><input type='text' name='gmzoom' size='40' maxlength='250' value='$gmzoom' /></td>
3235
    </tr>
3236
    <tr>
3237
        <td class='head'>"
3238
                       . _APCAL_TH_CONTACT
3239
                       . "</td>
3240
        <td class='even'><input type='text' name='contact' size='50' maxlength='250' value='$contact' /></td>
3241
    </tr>
3242
    <tr>
3243
        <td class='head'>"
3244
                       . _APCAL_TH_EMAIL
3245
                       . "</td>
3246
        <td class='even'><input type='text' name='email' size='50' maxlength='250' value='$email' /></td>
3247
    </tr>
3248
    <tr>
3249
        <td class='head'>"
3250
                       . _APCAL_TH_URL
3251
                       . "</td>
3252
        <td class='even'><input type='text' name='url' size='50' maxlength='250' value='$url' /></td>
3253
    </tr>
3254
    <tr>
3255
        <td class='head'>"
3256
                       . _APCAL_TH_DESCRIPTION
3257
                       . "</td>
3258
        <td class='even'>$description_textarea</td>
3259
    </tr>
3260
    <tr>
3261
        <td class='head'>"
3262
                       . _APCAL_MAINPICTURE
3263
                       . "</td>
3264
        <td class='even'>$mainPic</td>
3265
    </tr>
3266
    <tr>
3267
        <td class='head'>"
3268
                       . _APCAL_PICTURES
3269
                       . "</td>
3270
        <td class='even'>$pictures<br>$picturesList</td>
3271
    </tr>
3272
    <tr>
3273
        <td class='head'>"
3274
                       . _APCAL_TH_MAINCATEGORY
3275
                       . "</td>
3276
        <td class='even'>$category_select</td>
3277
    </tr>
3278
    <tr>
3279
        <td class='head'>"
3280
                       . _APCAL_TH_CATEGORIES
3281
                       . "</td>
3282
        <td class='even'>$category_checkboxes</td>
3283
    </tr>
3284
    <tr>
3285
        <td class='head'>"
3286
                       . _APCAL_TH_CLASS
3287
                       . "</td>
3288
        <td class='even'><input type='radio' name='class' value='PUBLIC' $class_public onClick='document.MainForm.groupid.disabled=true' />"
3289
                       . _APCAL_MB_PUBLIC
3290
                       . " &nbsp;  &nbsp; <input type='radio' name='class' value='PRIVATE' $class_private onClick='document.MainForm.groupid.disabled=false' />"
3291
                       . _APCAL_MB_PRIVATE
3292
                       . sprintf(_APCAL_MB_PRIVATETARGET, $select_private)
3293
                       . "</td>
3294
    </tr>
3295
    <tr>
3296
        <td class='head'>"
3297
                       . _APCAL_TH_RRULE
3298
                       . "</td>
3299
        <td class='even'>"
3300
                       . $this->rrule_to_form($rrule, $end_ymd)
3301
                       . "</td>
3302
    </tr>
3303
    <tr>
3304
        <td class='head'>"
3305
                       . _APCAL_TH_ADMISSIONSTATUS
3306
                       . "</td>
3307
        <td class='even'>$admission_status</td>
3308
    </tr>\n";
3309
3310
            if ($this->enableregistration) {
3311
                $ret .= $ro_form_new;
3312
            } //added one line by goffy
3313
3314
            if ($editable) {
3315
                $ret .= "
3316
    <tr>
3317
        <td style='text-align:center' colspan='2'>
3318
            <input name='reset' type='reset' value='" . _APCAL_BTN_RESET . "' />
3319
            $update_button
3320
            $insert_button
3321
            $delete_button
3322
        </td>
3323
    </tr>\n";
3324
            }
3325
3326
            $ret .= "
3327
    <tr>
3328
        <td><img src='$this->images_url/spacer.gif' alt='' width='150' height='4' /></td>       <td width='100%'></td>
3329
    </tr>
3330
    </table>
3331
</form>
3332
\n";
3333
3334
            if ($this->enableregistration) {
3335
                $ret .= $ro_form_edit;
3336
            } // splitted and added one line by goffy
3337
            $ret .= "<table>
3338
        <tr><td><img src='$this->images_url/spacer.gif' alt='' height='4' /></td></tr>
3339
        <tr><td width='100%' align='right'>" . _MD_APCAL_COPYRIGHT . '</td></tr>
3340
    </table>';
3341
3342
            $ret .= "
3343
<script type='text/javascript'>
3344
    function addHours()
3345
    {
3346
        var startDate = document.MainForm.StartDate.value.split('-');
3347
        var endDate = document.MainForm.EndDate.value.split('-');
3348
        startDate = new Date(startDate[0], startDate[1]-1, startDate[2]).getTime();
3349
        endDate = new Date(endDate[0], endDate[1]-1, endDate[2]).getTime();
3350
        var diff = (endDate - startDate) / 3600000 / 24;
3351
        var diffBefore = document.getElementsByName('StartH[]').length;
3352
        var start = document.getElementById('start_datetime');
3353
        var end = document.getElementById('end_datetime');
3354
        var maxDays = 30;
3355
3356
        if (diffBefore < diff) {
3357
            for (var i=diffBefore; i<diff&&i<=maxDays; i++) {
3358
                var startNode = document.createElement('span');
3359
                var endNode = document.createElement('span');
3360
3361
                startNode.innerHTML += \"" . _APCAL_DAY . "&nbsp;\"+(i+2);
3362
                startNode.innerHTML += \"<select name='StartH[]' disabled>" . str_replace("\n", '', $this->get_options_for_hour($start_hour)) . "</select>\";
3363
                startNode.innerHTML += \"<select name='StartM[]' disabled>" . str_replace("\n", '', $this->get_options_for_min($start_min)) . '</select>";
3364
                endNode.innerHTML += "' . _APCAL_DAY . "&nbsp;\"+(i+2);
3365
                endNode.innerHTML += \"<select name='EndH[]' disabled>" . str_replace("\n", '', $this->get_options_for_hour($end_hour)) . "</select>\";
3366
                endNode.innerHTML += \"<select name='EndM[]' disabled>" . str_replace("\n", '', $this->get_options_for_min($end_min)) . "</select>\";
3367
3368
                start.appendChild(startNode);
3369
                end.appendChild(endNode);
3370
            }
3371
        } elseif (diff >= 0 && diff<=maxDays) {
3372
            var StartSpan = document.getElementById('start_datetime').getElementsByTagName('span');
3373
            var EndSpan = document.getElementById('end_datetime').getElementsByTagName('span');
3374
            for (var i=diffBefore-1; i>=diff; i--) {
3375
                StartSpan[i].outerHTML = '';
3376
                EndSpan[i].outerHTML = '';
3377
            }
3378
        }
3379
        enableSelects(!document.getElementsByName('allday_bits[]')[2].checked);
3380
    }
3381
3382
    function enableSelects(disabled)
3383
    {
3384
        var StartH = document.getElementsByName('StartH[]');
3385
        var StartM = document.getElementsByName('StartM[]');
3386
        var EndH = document.getElementsByName('EndH[]');
3387
        var EndM = document.getElementsByName('EndM[]');
3388
        var nbItems = StartH.length;
3389
3390
        for (var i=0; i<nbItems; i++) {
3391
            StartH[i].disabled = disabled;
3392
            StartM[i].disabled = disabled;
3393
            EndH[i].disabled = disabled;
3394
            EndM[i].disabled = disabled;
3395
        }
3396
    }
3397
3398
    function checkChange()
3399
    {
3400
        var newStart = document.MainForm.StartDate.value;
3401
        var newEnd = document.MainForm.EndDate.value;
3402
        if (oldStart != newStart || oldEnd != newEnd) {addHours();}
3403
        oldStart = newStart;
3404
        oldEnd = newEnd;
3405
    }
3406
    var oldStart = document.MainForm.StartDate.value;
3407
    var oldEnd = document.MainForm.EndDate.value;
3408
    setInterval(checkChange, 750);
3409
</script>\n
3410
";
3411
3412
            return $ret;
3413
        }
3414
3415
        // Save an event
3416
3417
        /**
3418
         * @param string $set_sql_append
3419
         * @param string $whr_sql_append
3420
         * @param null   $notify_callback
3421
         */
3422
        public function update_schedule($set_sql_append = '', $whr_sql_append = '', $notify_callback = null)
3423
        {
3424
            if ($_POST['summary'] === '') {
3425
                $_POST['summary'] = _APCAL_MB_NOSUBJECT;
3426
            }
3427
3428
            list($start, $start_date, $use_default) = $this->parse_posted_date($this->mb_convert_kana($_POST['StartDate'], 'a'), $this->unixtime);
0 ignored issues
show
Unused Code introduced by
The assignment to $use_default is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
3429
            list($end, $end_date, $use_default) = $this->parse_posted_date($this->mb_convert_kana($_POST['EndDate'], 'a'), $this->unixtime);
0 ignored issues
show
Unused Code introduced by
The assignment to $use_default is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
3430
3431
            $allday = 1;
3432
            if (isset($_POST['allday_bits'])) {
3433
                $bits = $_POST['allday_bits'];
3434
                if (is_array($bits)) {
3435
                    foreach ($bits as $bit) {
3436
                        if ($bit > 0 && $bit < 8) {
3437
                            $allday += pow(2, (int)$bit);
3438
                        }
3439
                    }
3440
                }
3441
            }
3442
3443
            $tzoffset_e2s = (int)(($this->server_TZ - $_POST['event_tz']) * 3600);
3444
            if ($start_date || $end_date) {
3445
                if ($start_date) {
3446
                    $date_append = ", start_date='$start_date'";
3447
                } else {
3448
                    $date_append = ', start_date=null';
3449
                }
3450
                if ($end_date) {
3451
                    $date_append .= ", end_date='$end_date'";
3452
                } else {
3453
                    $date_append .= ', end_date=null';
3454
                    $end         += 86400;
3455
                }
3456
                $set_sql_date = "start='$start', end='$end', allday='$allday' $date_append";
3457
                $allday_flag  = true;
3458
            } elseif ($_POST['allday_bits'][0] > 0) {
3459
                $start += $_POST['StartHour'] * 3600 + $_POST['StartMin'] * 60 + $tzoffset_e2s;
3460
                $end   += $_POST['EndHour'] * 3600 + $_POST['EndMin'] * 60 + $tzoffset_e2s;
3461
                if ($start > $end) {
3462
                    list($start, $end) = array($end, $start);
3463
                } elseif ($start == $end) {
3464
                    $start += 60;
3465
                    $end   += (23 * 3600) + (59 * 60);
3466
                }
3467
                //$end += 86400 ;
3468
                $set_sql_date = "start='$start', end='$end', allday='$allday', start_date=null, end_date=null";
3469
                $allday_flag  = true;
3470
            } else {
3471
                if (!isset($_POST['event_tz'])) {
3472
                    $_POST['event_tz'] = $this->user_TZ;
3473
                }
3474
                $tzoffset_e2s = (int)(($this->server_TZ - $_POST['event_tz']) * 3600);
3475
                //$tzoffset_e2s = (int)( date( 'Z' , $start ) - $_POST['event_tz'] * 3600 ) ;
3476
3477
                $start += $_POST['StartHour'] * 3600 + $_POST['StartMin'] * 60 + $tzoffset_e2s;
3478
                $end   += $_POST['EndHour'] * 3600 + $_POST['EndMin'] * 60 + $tzoffset_e2s;
3479
                if ($start > $end) {
3480
                    list($start, $end) = array($end, $start);
3481
                }
3482
                $set_sql_date = "start='$start', end='$end', allday=0, start_date=null, end_date=null";
3483
                $allday_flag  = false;
3484
            }
3485
3486
            $otherHours = '';
3487
            if (isset($_POST['allday_bits'][0]) && $_POST['allday_bits'][0] == '8') {
3488
                $otherHours = array();
3489
                foreach ($_POST['StartH'] as $i => $startH) {
3490
                    $otherHours[] = ($i + 1) . ':' . $startH . ':' . $_POST['StartM'][$i] . ':' . $_POST['EndH'][$i] . ':' . $_POST['EndM'][$i];
3491
                }
3492
                $otherHours = implode('-', $otherHours);
3493
            }
3494
3495
            $set_sql_date .= ",server_tz='$this->server_TZ'";
3496
3497
            if (!isset($_POST['description']) && isset($_POST['description_text'])) {
3498
                $_POST['description'] = $_POST['description_text'];
3499
            }
3500
3501
            $_POST['categories'] = '';
3502
            $cids                = is_array(@$_POST['cids']) ? $_POST['cids'] : array();
3503
            if (!in_array($_POST['mainCategory'], $cids)) {
3504
                $cids[] = $_POST['mainCategory'];
3505
            }
3506
            foreach ($cids as $cid) {
3507
                $cid = (int)$cid;
3508
                while (isset($this->categories[$cid])) {
3509
                    $cid4sql = sprintf('%05d,', $cid);
3510
                    if (stristr($_POST['categories'], $cid4sql) === false) {
3511
                        $_POST['categories'] .= sprintf('%05d,', $cid);
3512
                    }
3513
                    $cid = (int)$this->categories[$cid]->pid;
3514
                }
3515
            }
3516
3517
            // RRULE
3518
            $rrule = $this->rrule_from_post($start, $allday_flag);
3519
3520
            $cols = array(
3521
                'summary'     => '255:J:1',
3522
                'location'    => '255:J:0',
3523
                'contact'     => '255:J:0',
3524
                'email'       => '255:J:0',
3525
                'url'         => '255:J:0',
3526
                'description' => 'A:J:0',
3527
                'categories'  => '255:E:0',
3528
                'class'       => '255:E:0',
3529
                'groupid'     => 'I:N:0',
3530
                'poster_tz'   => 'F:N:0',
3531
                'event_tz'    => 'F:N:0'
3532
            );
3533
3534
            $set_str = $this->get_sql_set($cols) . ", $set_sql_date $set_sql_append";
3535
            $set_str .= ",shortsummary='" . $this->makeShort(utf8_decode($_POST['summary'])) . "'";
3536
            $set_str .= ",mainCategory='" . $_POST['mainCategory'] . "'";
3537
            $set_str .= ",otherHours='" . $otherHours . "'";
3538
3539
            // Check update or insert
3540
            $event_id = (int)$_POST['event_id'];
3541
            if ($event_id > 0) {
3542
                $rs = $GLOBALS['xoopsDB']->query("SELECT rrule_pid FROM $this->table WHERE id='$event_id' $whr_sql_append");
3543
                if (!($event = $GLOBALS['xoopsDB']->fetchObject($rs))) {
3544
                    die('Record Not Exists.');
3545
                }
3546 View Code Duplication
                if ($event->rrule_pid > 0) {
0 ignored issues
show
Duplication introduced by
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...
3547
                    if (!$GLOBALS['xoopsDB']->query("DELETE FROM $this->table WHERE rrule_pid='$event->rrule_pid' AND id<>'$event_id'")) {
3548
                        echo $GLOBALS['xoopsDB']->error();
3549
                    }
3550
                }
3551
3552
                // UPDATE
3553
                if ($rrule !== '') {
3554
                    $set_str .= ', rrule_pid=id';
3555
                }
3556
                $sql = "UPDATE $this->table SET $set_str , rrule='$rrule' , sequence=sequence+1, gmlat='{$_POST['gmlat']}', gmlong='{$_POST['gmlong']}', gmzoom='{$_POST['gmzoom']}' WHERE id='$event_id' $whr_sql_append";
3557
                if (!$GLOBALS['xoopsDB']->query($sql)) {
3558
                    echo $GLOBALS['xoopsDB']->error();
3559
                }
3560
3561
                // RRULE
3562
                if ($rrule !== '') {
3563
                    $this->rrule_extract($event_id);
3564
                }
3565
3566
                // ���٤Ƥ򹹿��塢���������դΥ����������?��
3567
                $last_smode = preg_replace('/[^a-zA-Z0-9_-]/', '', @$_POST['last_smode']);
0 ignored issues
show
Unused Code introduced by
$last_smode is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
3568
                //$last_caldate = preg_replace( '/[^a-zA-Z0-9_-]/' , '' , @$_POST['last_caldate'] ) ;
3569
                $new_caldate = $start_date ?: date('Y-n-j', $start);
0 ignored issues
show
Unused Code introduced by
$new_caldate is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
3570
                //$this->redirect( "smode=$last_smode&caldate=$new_caldate" ) ;
3571 View Code Duplication
                if (isset($_POST['saveas'])) {
0 ignored issues
show
Duplication introduced by
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...
3572
                    $result = $GLOBALS['xoopsDB']->query("SELECT * FROM {$this->pic_table} WHERE event_id={$_POST['event_oldid']}");
3573
                    while ($pic = $GLOBALS['xoopsDB']->fetchObject($result)) {
3574
                        $GLOBALS['xoopsDB']->query("INSERT INTO {$this->pic_table}(event_id, picture, main_pic) VALUES ({$event_id}, '{$pic->picture}', {$pic->main_pic})");
3575
                    }
3576
                    $this->savepictures($event_id);
3577
                } else {
3578
                    $this->savepictures($event_id);
3579
                }
3580
            } else {
3581
                $sql = "INSERT INTO $this->table SET $set_str , rrule='$rrule' , sequence=0, gmlat='{$_POST['gmlat']}', gmlong='{$_POST['gmlong']}', gmzoom='{$_POST['gmzoom']}'";
3582
                if (!$GLOBALS['xoopsDB']->query($sql)) {
3583
                    echo $GLOBALS['xoopsDB']->error();
3584
                }
3585
                // unique_id,rrule_pid
3586
                $event_id  = $GLOBALS['xoopsDB']->getInsertId($this->conn);
3587
                $unique_id = 'apcal060-' . md5("{$_SERVER['HTTP_HOST']}{$_SERVER['PHP_SELF']}$event_id");
3588
                $rrule_pid = $rrule ? $event_id : 0;
3589
                $GLOBALS['xoopsDB']->query("UPDATE $this->table SET unique_id='$unique_id',rrule_pid='$rrule_pid' WHERE id='$event_id'");
3590
3591
                // RRULE
3592
                if ($rrule !== '') {
3593
                    $this->rrule_extract($event_id);
3594
                }
3595
3596
                if (isset($notify_callback)) {
3597
                    $this->$notify_callback($event_id);
3598
                }
3599
3600
                $last_smode   = preg_replace('/[^a-zA-Z0-9_-]/', '', @$_POST['last_smode']);
3601
                $last_caldate = preg_replace('/[^a-zA-Z0-9_-]/', '', @$_POST['last_caldate']);
3602
                //$this->redirect( "smode=$last_smode&caldate=$last_caldate" ) ;
3603
3604
                // Save pictures
3605 View Code Duplication
                if (isset($_POST['saveas'])) {
0 ignored issues
show
Duplication introduced by
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...
3606
                    $result = $GLOBALS['xoopsDB']->query("SELECT * FROM {$this->pic_table} WHERE event_id={$_POST['event_oldid']}");
3607
                    while ($pic = $GLOBALS['xoopsDB']->fetchObject($result)) {
3608
                        $GLOBALS['xoopsDB']->query("INSERT INTO {$this->pic_table}(event_id, picture, main_pic) VALUES ({$event_id}, '{$pic->picture}', {$pic->main_pic})");
3609
                    }
3610
                    $this->savepictures($event_id);
3611
                } else {
3612
                    $this->savepictures($event_id);
3613
                }
3614
3615
                // added by goffy for registration online automatically redirect to form for set up parameters for online registration, if online registration is selected
3616
                $ro_redirect = $_POST['ro_activate'];
3617
                if ($ro_redirect === 'yes') {
3618 View Code Duplication
                    if (!empty($_SERVER['HTTPS'])) {
0 ignored issues
show
Duplication introduced by
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...
3619
                        $this->redirecturl = 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
3620
                    } else {
3621
                        $this->redirecturl = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
3622
                    }
3623
3624
                    $call_ro = 'ro_regonlinehandler.php?op=show_form_activate';
3625
                    $call_ro .= "&uid=$uid";
0 ignored issues
show
Bug introduced by
The variable $uid does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
3626
                    $call_ro .= "&eventid=$event_id";
3627
                    $call_ro .= '&title=' . $_POST['summary'];
3628
                    $call_ro .= "&eventdate=$start";//.$_POST[ 'StartDate' ]." ".$_POST[ 'StartHour' ].":".$_POST[ 'StartMin' ];
3629
                    $call_ro .= '&eventurl=' . $this->redirecturl;
3630
                    $call_ro .= "&smode=$last_smode";
3631
                    $call_ro .= "&caldate=$last_caldate";
3632
                    redirect_header($call_ro, 3, _APCAL_RO_SUCCESS_NEW_EVENT . '<br>' . _APCAL_RO_REDIRECT);
3633
                } else {
3634
                    redirect_header($this->redirecturl . "?smode=$last_smode&caldate=$last_caldate", 3, _APCAL_RO_SUCCESS_NEW_EVENT);
3635
                }
3636
                // end goffy
3637
            }
3638
        }
3639
3640
        // Delete an event
3641
3642
        /**
3643
         * @param string $whr_sql_append
3644
         * @param null   $eval_after
3645
         */
3646
        public function delete_schedule($whr_sql_append = '', $eval_after = null)
3647
        {
3648
            if (!empty($_POST['event_id'])) {
3649
                $event_id = (int)$_POST['event_id'];
3650
3651
                $this->delete_regonline($event_id); // added one line by goffy
3652
                $rs = $GLOBALS['xoopsDB']->query("SELECT rrule_pid FROM $this->table WHERE id='$event_id' $whr_sql_append");
3653
                if (!($event = $GLOBALS['xoopsDB']->fetchObject($rs))) {
3654
                    die('Record Not Exists.');
3655
                }
3656
                if ($event->rrule_pid > 0) {
3657 View Code Duplication
                    if (!$GLOBALS['xoopsDB']->query("DELETE FROM $this->table WHERE rrule_pid='$event->rrule_pid' $whr_sql_append")) {
0 ignored issues
show
Duplication introduced by
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...
3658
                        echo $GLOBALS['xoopsDB']->error();
3659
                    }
3660
                    // ����������ɲý����eval�Ǽ����� (XOOPS�Ǥϡ������Ȥκ���
3661
                    if ($GLOBALS['xoopsDB']->getAffectedRows() > 0 && isset($eval_after)) {
3662
                        $id = $event->rrule_pid;
0 ignored issues
show
Unused Code introduced by
$id is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
3663
                        eval($eval_after);
3664
                    }
3665
                } else {
3666 View Code Duplication
                    if (!$GLOBALS['xoopsDB']->query("DELETE FROM $this->table WHERE id='$event_id' $whr_sql_append")) {
0 ignored issues
show
Duplication introduced by
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...
3667
                        echo $GLOBALS['xoopsDB']->error();
3668
                    }
3669
                    // ����������ɲý����eval�Ǽ����� (XOOPS�Ǥϡ������Ȥκ���
3670
                    if ($GLOBALS['xoopsDB']->getAffectedRows() == 1 && isset($eval_after)) {
3671
                        $id = $event_id;
0 ignored issues
show
Unused Code introduced by
$id is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
3672
                        eval($eval_after);
3673
                    }
3674
                }
3675
            }
3676
            $last_smode   = preg_replace('/[^a-zA-Z0-9_-]/', '', @$_POST['last_smode']);
3677
            $last_caldate = preg_replace('/[^a-zA-Z0-9_-]/', '', @$_POST['last_caldate']);
3678
            $this->redirect("smode=$last_smode&caldate=$last_caldate");
3679
        }
3680
3681
        // �������塼��ΰ�����RRULE�λҶ��쥳���ɡ�
3682
3683
        /**
3684
         * @param string $whr_sql_append
3685
         */
3686
        public function delete_schedule_one($whr_sql_append = '')
3687
        {
3688
            if (!empty($_POST['subevent_id'])) {
3689
                $event_id = (int)$_POST['subevent_id'];
3690
                $this->delete_regonline($event_id); // added one line by goffy
3691
3692 View Code Duplication
                if (!$GLOBALS['xoopsDB']->query("DELETE FROM $this->table WHERE id='$event_id' AND rrule_pid <> id $whr_sql_append")) {
0 ignored issues
show
Duplication introduced by
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...
3693
                    echo $GLOBALS['xoopsDB']->error();
3694
                }
3695
            }
3696
            $last_smode   = preg_replace('/[^a-zA-Z0-9_-]/', '', @$_POST['last_smode']);
3697
            $last_caldate = preg_replace('/[^a-zA-Z0-9_-]/', '', @$_POST['last_caldate']);
3698
            $this->redirect("smode=$last_smode&caldate=$last_caldate");
3699
        }
3700
3701
        //added function by goffy
3702
3703
        /**
3704
         * @param $event_id
3705
         */
3706
        public function delete_regonline($event_id)
3707
        {
3708
            //delete data from table apcal_ro_members
3709
            $sql = 'DELETE '
3710
                   . XOOPS_DB_PREFIX
3711
                   . $this->table_ro_members
3712
                   . '.* FROM '
3713
                   . XOOPS_DB_PREFIX
3714
                   . $this->table_ro_members
3715
                   . ' WHERE (('
3716
                   . XOOPS_DB_PREFIX
3717
                   . $this->table_ro_members
3718
                   . ".rom_eventid)=$event_id)";
3719
            $res = $GLOBALS['xoopsDB']->query($sql);
0 ignored issues
show
Unused Code introduced by
$res is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
3720
3721
            //delete data from table apcal_ro_notify
3722
            $sql = 'DELETE '
3723
                   . XOOPS_DB_PREFIX
3724
                   . $this->table_ro_notify
3725
                   . '.* FROM '
3726
                   . XOOPS_DB_PREFIX
3727
                   . $this->table_ro_notify
3728
                   . ' WHERE (('
3729
                   . XOOPS_DB_PREFIX
3730
                   . $this->table_ro_notify
3731
                   . ".ron_eventid)=$event_id)";
3732
            $res = $GLOBALS['xoopsDB']->query($sql);
0 ignored issues
show
Unused Code introduced by
$res is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
3733
3734
            //delete data from table apcal_ro_events
3735
            $sql = 'DELETE '
3736
                   . XOOPS_DB_PREFIX
3737
                   . $this->table_ro_events
3738
                   . '.* FROM '
3739
                   . XOOPS_DB_PREFIX
3740
                   . $this->table_ro_events
3741
                   . ' WHERE (('
3742
                   . XOOPS_DB_PREFIX
3743
                   . $this->table_ro_events
3744
                   . ".roe_eventid)=$event_id)";
3745
            $res = $GLOBALS['xoopsDB']->query($sql);
0 ignored issues
show
Unused Code introduced by
$res is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
3746
        }
3747
3748
        /**
3749
         * @param $query
3750
         */
3751
        public function redirect($query)
3752
        {
3753
            // character white list and black list against 'javascript'
3754
            if (!preg_match('/^[a-z0-9=&_-]*$/i', $query) || stristr($query, 'javascript')) {
3755
                header(strtr("Location: $this->connection://{$_SERVER['HTTP_HOST']}{$_SERVER['PHP_SELF']}", "\r\n\0", '   '));
3756
                exit;
3757
            }
3758
3759
            if (headers_sent()) {
3760
                echo "
3761
            <html>
3762
            <head>
3763
            <title>redirection</title>
3764
            <meta http-equiv='Refresh' content='0; url=?$query' />
3765
            </head>
3766
            <body>
3767
            <p>
3768
                <a href='?$query'>push here if not redirected</a>
3769
            </p>
3770
            </body>
3771
            </html>";
3772
            } else {
3773
                header(strtr("Location: $this->connection://{$_SERVER['HTTP_HOST']}{$_SERVER['PHP_SELF']}?$query", "\r\n\0", '   '));
3774
            }
3775
            exit;
3776
        }
3777
3778
        // -12.0��12.0�ޤǤ��ͤ�����ơ�(GMT+HH:MM) �Ȥ���ʸ������֤�
3779
3780
        /**
3781
         * @param $offset
3782
         * @return string
3783
         */
3784
        public function get_tz_for_display($offset)
3785
        {
3786
            return $this->displayTimezone ? '(GMT' . ($offset >= 0 ? '+' : '-') . sprintf('%02d:%02d', abs($offset), abs($offset) * 60 % 60) . ')' : '';
3787
        }
3788
3789
        // -12.0��12.0�ޤǤ�Timzone SELECT�ܥå�����Optionʸ������֤�
3790
3791
        /**
3792
         * @param  int $selected
3793
         * @return string
3794
         */
3795
        public function get_tz_options($selected = 0)
3796
        {
3797
            $tzs = array(
3798
                '-12',
3799
                '-11',
3800
                '-10',
3801
                '-9',
3802
                '-8',
3803
                '-7',
3804
                '-6',
3805
                '-5',
3806
                '-4',
3807
                '-3.5',
3808
                '-3',
3809
                '-2',
3810
                '-1',
3811
                '0',
3812
                '1',
3813
                '2',
3814
                '3',
3815
                '3.5',
3816
                '4',
3817
                '4.5',
3818
                '5',
3819
                '5.5',
3820
                '6',
3821
                '7',
3822
                '8',
3823
                '9',
3824
                '9.5',
3825
                '10',
3826
                '11',
3827
                '12'
3828
            );
3829
3830
            $ret = '';
3831
            foreach ($tzs as $tz) {
3832
                if ($tz == $selected) {
3833
                    $ret .= "\t<option value='$tz' selected>" . $this->get_tz_for_display($tz) . "</option>\n";
3834
                } else {
3835
                    $ret .= "\t<option value='$tz'>" . $this->get_tz_for_display($tz) . "</option>\n";
3836
                }
3837
            }
3838
3839
            return $ret;
3840
        }
3841
3842
        // -12.0��12.0�ޤǤ��ͤ�����ơ�array(TZOFFSET,TZID)���֤�
3843
3844
        /**
3845
         * @param $tz
3846
         * @return array
3847
         */
3848
        public function get_timezone_desc($tz)
3849
        {
3850
            if ($tz == 0) {
3851
                $tzoffset = '+0000';
3852
                $tzid     = 'GMT';
3853
            } elseif ($tz > 0) {
3854
                $tzoffset = sprintf('+%02d%02d', $tz, $tz * 60 % 60);
3855
                $tzid     = 'Etc/GMT-' . sprintf('%d', $tz);
3856
            } else {
3857
                $tz       = abs($tz);
3858
                $tzoffset = sprintf('-%02d%02d', $tz, $tz * 60 % 60);
3859
                $tzid     = 'Etc/GMT+' . sprintf('%d', $tz);
3860
            }
3861
3862
            return array($tzoffset, $tzid);
3863
        }
3864
3865
        // ���ƥ��꡼����ʸ��ܥå�����ե����ऴ�Ⱥ�������
3866
3867
        /**
3868
         * @param  string $get_target
3869
         * @param  null   $smode
3870
         * @return string
3871
         */
3872
        public function get_categories_selform($get_target = '', $smode = null)
3873
        {
3874
            global $xoopsModule;
3875
3876
            if (empty($this->categories)) {
3877
                return '';
3878
            }
3879
3880
            if (empty($smode)) {
3881
                $smode = isset($_GET['smode']) ? $_GET['smode'] : 'Monthly';
3882
            }
3883
            $smode = preg_replace('/[^a-zA-Z0-9_-]/', '', $smode);
3884
3885
            $op = empty($_GET['op']) ? '' : preg_replace('/[^a-zA-Z0-9_-]/', '', $_GET['op']);
3886
3887
            $ret = "<script type='text/javascript'>\n";
3888
            $ret .= "function submitCat(cid, smode, caldate)\n";
3889
            $ret .= "{\n";
3890
            if ($this->useurlrewrite) {
3891
                $ret .= "var defaultView = '" . $this->default_view . "';\n";
3892
                $ret .= "var today = '" . date('Y-n-j') . "';\n";
3893
3894
                $ret .= "if (cid != 'All' && smode != defaultView && caldate != today) {document.catSel.action = '" . XOOPS_URL . "/modules/apcal/' + cid + '-' + smode + '-' + caldate;}\n";
3895
                $ret .= "else if (cid != 'All' && smode != defaultView && caldate == today) {document.catSel.action = '" . XOOPS_URL . "/modules/apcal/' + cid + '-' + smode;}\n";
3896
                $ret .= "else if (cid != 'All' && smode == defaultView && caldate != today) {document.catSel.action = '" . XOOPS_URL . "/modules/apcal/' + cid + '-' + caldate;}\n";
3897
                $ret .= "else if (cid == 'All' && smode != defaultView && caldate != today) {document.catSel.action = '" . XOOPS_URL . "/modules/apcal/' + smode + '-' + caldate;}\n";
3898
                $ret .= "else if (cid == 'All' && smode != defaultView && caldate == today) {document.catSel.action = '" . XOOPS_URL . "/modules/apcal/' + smode;}\n";
3899
                $ret .= "else if (cid == 'All' && smode == defaultView && caldate != today) {document.catSel.action = '" . XOOPS_URL . "/modules/apcal/' + caldate;}\n";
3900
                $ret .= "else if (cid != 'All' && smode == defaultView && caldate == today) {document.catSel.action = '" . XOOPS_URL . "/modules/apcal/' + cid;}\n";
3901
                $ret .= "else {document.catSel.action = '" . XOOPS_URL . "/modules/apcal/';}\n";
3902
3903
                //$ret .= "document.catSel.action = '".XOOPS_URL."/' + cid + '/' + smode + '/' + caldate;\n";
3904
                $ret .= "document.catSel.method = 'POST';\n";
3905
            }
3906
            $ret .= "document.catSel.submit();\n";
3907
            $ret .= "}\n";
3908
            $ret .= "</script>\n";
3909
            $ret .= "<form class='apcalForm' action='$get_target' name='catSel' method='GET' style='margin:0px;'>\n";
3910
            $ret .= "<input type='hidden' name='caldate' value='$this->caldate' />\n";
3911
            $ret .= "<input type='hidden' name='smode' value='$smode' />\n";
3912
            $ret .= "<input type='hidden' name='op' value='$op' />\n";
3913
            $ret .= "<select name='cid' onchange='submitCat(document.catSel.cid.value, document.catSel.smode.value, document.catSel.caldate.value);'>\n";
3914
            $ret .= $this->useurlrewrite ? "\t<option value='All'>" . _APCAL_MB_SHOWALLCAT . "</option>\n" : "\t<option value='0'>" . _APCAL_MB_SHOWALLCAT . "</option>\n";
3915
            foreach ($this->categories as $cid => $cat) {
3916
                $selected       = $this->now_cid == $cid ? 'selected' : '';
3917
                $depth_desc     = str_repeat('-', (int)$cat->cat_depth);
3918
                $cat_title4show = $this->text_sanitizer_for_show($cat->cat_title);
3919
                $ret            .= $this->useurlrewrite ? "\t<option value='"
3920
                                                          . urlencode(urlencode($cat->cat_shorttitle))
3921
                                                          . "' $selected>$depth_desc $cat_title4show</option>\n" : "\t<option value='$cid' $selected>$depth_desc $cat_title4show</option>\n";
3922
            }
3923
            $ret .= "</select>\n</form>\n";
3924
3925
            return $ret;
3926
        }
3927
3928
        // ǯ����Υƥ����ȥܥå������Ϥ�����ơ�UnixTimestamp���֤�
3929
3930
        /**
3931
         * @param $date_desc
3932
         * @param $default_unixtime
3933
         * @return array
3934
         */
3935
        public function parse_posted_date($date_desc, $default_unixtime)
3936
        {
3937
            if (!preg_match('#^([0-9][0-9]+)[-./]?([0-1]?[0-9])[-./]?([0-3]?[0-9])$#', $date_desc, $regs)) {
3938
                $unixtime    = $default_unixtime;
3939
                $use_default = true;
3940
                $iso_date    = '';
3941
            } elseif ($regs[1] >= 2038) {
3942
                // 2038ǯ�ʹߤξ�� 2038/1/1 �˥��å�
3943
                $unixtime    = mktime(0, 0, 0, 1, 1, 2038);
3944
                $use_default = false;
3945
                $iso_date    = "{$regs[1]}-{$regs[2]}-{$regs[3]}";
3946
            } elseif ($regs[1] <= 1970) {
3947
                // 1970ǯ�����ξ�� 1970/12/31�˥��å�
3948
                $unixtime    = mktime(0, 0, 0, 12, 31, 1970);
3949
                $use_default = false;
3950
                $iso_date    = "{$regs[1]}-{$regs[2]}-{$regs[3]}";
3951
            } elseif (!checkdate($regs[2], $regs[3], $regs[1])) {
3952
                $unixtime    = $default_unixtime;
3953
                $use_default = true;
3954
                $iso_date    = '';
3955
            } else {
3956
                $unixtime    = mktime(0, 0, 0, $regs[2], $regs[3], $regs[1]);
3957
                $use_default = false;
3958
                $iso_date    = '';
3959
            }
3960
3961
            return array($unixtime, $iso_date, $use_default);
3962
        }
3963
3964
        // timezone���������ơ�RFC2445��VTIMEZONE��ʸ������֤�
3965
3966
        /**
3967
         * @param $timezones
3968
         * @return string
3969
         */
3970
        public function get_vtimezones_str($timezones)
3971
        {
3972
            if (empty($timezones)) {
3973
                return "BEGIN:VTIMEZONE\r
3974
TZID:GMT\r
3975
BEGIN:STANDARD\r
3976
DTSTART:19390101T000000\r
3977
TZOFFSETFROM:+0000\r
3978
TZOFFSETTO:+0000\r
3979
TZNAME:GMT\r
3980
END:STANDARD\r
3981
END:VTIMEZONE\r\n";
3982
            } else {
3983
                $ret = '';
3984
                foreach ($timezones as $tz => $dummy) {
3985
                    list($for_tzoffset, $for_tzid) = $this->get_timezone_desc($tz);
3986
3987
                    $ret .= "BEGIN:VTIMEZONE\r
3988
TZID:$for_tzid\r
3989
BEGIN:STANDARD\r
3990
DTSTART:19390101T000000\r
3991
TZOFFSETFROM:$for_tzoffset\r
3992
TZOFFSETTO:$for_tzoffset\r
3993
TZNAME:$for_tzid\r
3994
END:STANDARD\r
3995
END:VTIMEZONE\r\n";
3996
                }
3997
3998
                return $ret;
3999
            }
4000
        }
4001
4002
        // Ϣ����������˼�ꡢ$_POST����INSERT,UPDATE�Ѥ�SETʸ���������륯�饹�ؿ�
4003
4004
        /**
4005
         * @param $cols
4006
         * @return string
0 ignored issues
show
Documentation introduced by
Should the return type not be null|string?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
4007
         */
4008
        public function get_sql_set($cols)
4009
        {
4010
            $ret = '';
4011
4012
            foreach ($cols as $col => $types) {
4013
                list($field, $lang, $essential) = explode(':', $types);
4014
4015
                // ̤����ʤ�''�ȸ��ʤ�
4016
                if (!isset($_POST[$col])) {
4017
                    $data = '';
4018
                } elseif (get_magic_quotes_gpc()) {
4019
                    $data = stripslashes($_POST[$col]);
4020
                } else {
4021
                    $data = $_POST[$col];
4022
                }
4023
4024
                // ɬ�ܥե�����ɤΥ����å�
4025
                if ($essential && $data === '') {
4026
                    die(sprintf(_APCAL_ERR_LACKINDISPITEM, $col));
4027
                }
4028
4029
                // ���졦����ʤɤ��̤ˤ�����
4030 View Code Duplication
                switch ($lang) {
0 ignored issues
show
Duplication introduced by
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...
4031
                    case 'N':    // ���� (����� , ����)
4032
                        $data = (int)str_replace(',', '', $data);
4033
                        break;
4034
                    case 'J':    // ���ܸ�ƥ����� (Ⱦ�ѥ��ʢ����Ѥ���)
4035
                        $data = $this->mb_convert_kana($data, 'KV');
4036
                        break;
4037
                    case 'E':    // Ⱦ�ѱѿ���Τ�
4038
                        $data = $this->mb_convert_kana($data, 'as');
4039
                        break;
4040
                }
4041
4042
                // �ե�����ɤη��ˤ�����
4043
                switch ($field) {
4044
                    case 'A':    // textarea
4045
                        $ret .= "$col='" . addslashes($data) . "',";
4046
                        break;
4047
                    case 'I':    // integer
4048
                        $data = (int)$data;
4049
                        $ret  .= "$col='$data',";
4050
                        break;
4051
                    case 'F':    // float
4052
                        $data = (float)$data;
4053
                        $ret  .= "$col='$data',";
4054
                        break;
4055
                    default:    // varchar(�ǥե����)�Ͽ��ͤˤ��ʸ�������
4056
                        if ($field < 1) {
4057
                            $field = 255;
4058
                        }
4059
                        $data = mb_strcut($data, 0, $field);
4060
                        $ret  .= "$col='" . addslashes($data) . "',";
4061
                }
4062
            }
4063
4064
            // �Ǹ�� , ����
4065
            $ret = substr($ret, 0, -1);
4066
4067
            return $ret;
4068
        }
4069
4070
        // unixtimestamp���顢���ߤθ����ɽ�����줿Ĺ��ɽ���� YMDN ������
4071
4072
        /**
4073
         * @param $time
4074
         * @return string
4075
         */
4076
        public function get_long_ymdn($time)
4077
        {
4078
            return sprintf(_APCAL_FMT_YMDN, // format
4079
                           date('Y', $time), // Y
4080
                           $this->month_long_names[date('n', $time)], // M
4081
                           $this->date_long_names[date('j', $time)], // D
4082
                           $this->week_long_names[date('w', $time)] // N
4083
            );
4084
        }
4085
4086
        // unixtimestamp���顢���ߤθ����ɽ�����줿ɸ��Ĺɽ���� MD ������
4087
4088
        /**
4089
         * @param $time
4090
         * @return string
4091
         */
4092
        public function get_middle_md($time)
4093
        {
4094
            return sprintf(_APCAL_FMT_MD, // format
4095
                           $this->month_middle_names[date('n', $time)], // M
4096
                           $this->date_short_names[date('j', $time)] // D
4097
            );
4098
        }
4099
4100
        // unixtimestamp���顢���ߤθ����ɽ�����줿 DHI ������
4101
4102
        /**
4103
         * @param         $time
4104
         * @param  bool   $is_over24
4105
         * @return string
4106
         */
4107 View Code Duplication
        public function get_middle_dhi($time, $is_over24 = false)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
4108
        {
4109
            $hour_offset = $is_over24 ? 24 : 0;
4110
4111
            $hour4disp = $this->use24 ? $this->hour_names_24[date('G', $time) + $hour_offset] : $this->hour_names_12[date('G', $time) + $hour_offset];
0 ignored issues
show
Bug introduced by
The property hour_names_24 does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
Bug introduced by
The property hour_names_12 does not seem to exist. Did you mean hour_names_24?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
4112
4113
            return sprintf(_APCAL_FMT_DHI, $this->date_short_names[date('j', $time)], // D
4114
                           $hour4disp, // H
4115
                           date(_APCAL_DTFMT_MINUTE, $time) // I
4116
            );
4117
        }
4118
4119
        // unixtimestamp���顢���ߤθ����ɽ�����줿 HI ������
4120
4121
        /**
4122
         * @param         $time
4123
         * @param  bool   $is_over24
4124
         * @return string
4125
         */
4126 View Code Duplication
        public function get_middle_hi($time, $is_over24 = false)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
4127
        {
4128
            $hour_offset = $is_over24 ? 24 : 0;
4129
4130
            $hour4disp = $this->use24 ? $this->hour_names_24[date('G', $time) + $hour_offset] : $this->hour_names_12[date('G', $time) + $hour_offset];
0 ignored issues
show
Bug introduced by
The property hour_names_12 does not seem to exist. Did you mean hour_names_24?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
4131
4132
            return sprintf(_APCAL_FMT_HI, $hour4disp, // H
4133
                           date(_APCAL_DTFMT_MINUTE, $time) // I
4134
            );
4135
        }
4136
4137
        // Make <option>s for selecting "HOUR" (default_hour must be 0-23)
4138
4139
        /**
4140
         * @param  int $default_hour
4141
         * @return string
4142
         */
4143
        public function get_options_for_hour($default_hour = 0)
4144
        {
4145
            $ret = '';
4146
            for ($h = 0; $h < 24; ++$h) {
4147
                $ret .= $h == $default_hour ? "<option value='$h' selected>" : "<option value='$h'>";
4148
                $ret .= $this->use24 ? $this->hour_names_24[$h] : $this->hour_names_12[$h];
0 ignored issues
show
Bug introduced by
The property hour_names_12 does not seem to exist. Did you mean hour_names_24?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
4149
                $ret .= "</option>\n";
4150
            }
4151
4152
            return $ret;
4153
        }
4154
4155
        // Make <option>s for selecting "MIN" (default_min must be 0-60 by 5)
4156
4157
        /**
4158
         * @param  int $default_min
4159
         * @return string
4160
         */
4161
        public function get_options_for_min($default_min = 0)
4162
        {
4163
            $ret = '';
4164
            for ($m = 0; $m < 60; $m += 5) {
4165
                $ret .= $m == $default_min ? "<option value='$m' selected>" : "<option value='$m'>";
4166
                $ret .= sprintf('%02d', $m) . '</option>';
4167
            }
4168
4169
            return $ret;
4170
        }
4171
4172
        // unixtimestamp���顢�������(timestamp����)�ʹߤ�ͽ�������ʸ���������
4173
4174
        /**
4175
         * @param         $start
4176
         * @param         $now
4177
         * @param  bool   $admission
4178
         * @return string
4179
         */
4180
        public function get_coming_time_description($start, $now, $admission = true)
4181
        {
4182
            // ��ǧ��̵ͭ�ˤ�äƥɥå�GIF���ؤ���
4183
            if ($admission) {
4184
                $dot = '';
4185
            } else {
4186
                $dot = "<img border='0' src='$this->images_url/dot_notadmit.gif' />";
4187
            }
4188
4189
            if ($start >= $now && $start - $now < 86400) {
4190
                // 24���ְ���Υ��٥��
4191
                if (!$dot) {
4192
                    $dot = "<img border='0' src='$this->images_url/dot_today.gif' />";
4193
                }
4194
                $ret = "$dot <b>" . $this->get_middle_hi($start) . '</b>' . _APCAL_MB_TIMESEPARATOR;
4195
            } elseif ($start < $now) {
4196
                // ���Ǥ˳��Ϥ��줿���٥��
4197
                if (!$dot) {
4198
                    $dot = "<img border='0' src='$this->images_url/dot_started.gif' />";
4199
                }
4200
                $ret = "$dot " . _APCAL_MB_CONTINUING;
4201
            } else {
4202
                // ����ʹߤ˳��Ϥˤʤ륤�٥��
4203
                if (!$dot) {
4204
                    $dot = "<img border='0' src='$this->images_url/dot_future.gif' />";
4205
                }
4206
                //      $ret = "$dot " . date( "n/j H:i" , $start ) . _APCAL_MB_TIMESEPARATOR ;
4207
                $ret = "$dot " . $this->get_middle_md($start) . ' ' . $this->get_middle_hi($start) . _APCAL_MB_TIMESEPARATOR;
4208
            }
4209
4210
            return $ret;
4211
        }
4212
4213
        // ���Ĥ�unixtimestamp���顢������(Y-n-j����)��ͽ����֤�ʸ���������ʴ�˥��ߡ�
4214
4215
        /**
4216
         * @param         $start
4217
         * @param         $end
4218
         * @param         $ynj
4219
         * @param  bool   $justify
4220
         * @param  bool   $admission
4221
         * @param  null   $is_start_date
4222
         * @param  null   $is_end_date
4223
         * @param  null   $border_for_2400
4224
         * @return string
4225
         */
4226
        public function get_todays_time_description(
4227
            $start,
4228
            $end,
4229
            $ynj,
4230
            $justify = true,
4231
            $admission = true,
4232
            $is_start_date = null,
4233
            $is_end_date = null,
4234
            $border_for_2400 = null
4235
        ) {
4236
            if (!isset($is_start_date)) {
4237
                $is_start_date = (date('Y-n-j', $start) == $ynj);
4238
            }
4239
            if (!isset($is_end_date)) {
4240
                $is_end_date = (date('Y-n-j', $end) == $ynj);
4241
            }
4242
            if (!isset($border_for_2400)) {
4243
                $this->unixtime - (int)(($this->user_TZ - $this->server_TZ) * 3600) + 86400;
4244
            }
4245
4246
            // $day_start ���꤬������Ρ�24:00�ʹߤν���
4247
            if ($is_start_date && $start > $border_for_2400) {
4248
                $start_desc = $this->get_middle_hi($start, true);
4249
            } else {
4250
                $start_desc = $this->get_middle_hi($start);
4251
            }
4252
4253 View Code Duplication
            if ($is_end_date && $end > $border_for_2400) {
0 ignored issues
show
Duplication introduced by
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...
4254
                $end_desc = $this->get_middle_hi($end, true);
4255
            } else {
4256
                $end_desc = $this->get_middle_hi($end);
4257
            }
4258
4259
            $stuffing = $justify ? '     ' : '';
4260
4261
            // ͽ����ֻ����̵ͭ����ǧ��̵ͭ�ˤ�äƥɥå�GIF���ؤ���
4262 View Code Duplication
            if ($admission) {
0 ignored issues
show
Duplication introduced by
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...
4263
                if ($is_start_date) {
4264
                    $dot = "<img border='0' src='$this->images_url/dot_startday.gif' />";
4265
                } elseif ($is_end_date) {
4266
                    $dot = "<img border='0' src='$this->images_url/dot_endday.gif' />";
4267
                } else {
4268
                    $dot = "<img border='0' src='$this->images_url/dot_interimday.gif' />";
4269
                }
4270
            } else {
4271
                $dot = "<img border='0' src='$this->images_url/dot_notadmit.gif' />";
4272
            }
4273
4274 View Code Duplication
            if ($is_start_date) {
0 ignored issues
show
Duplication introduced by
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...
4275
                if ($is_end_date) {
4276
                    $ret = "$dot {$start_desc}" . _APCAL_MB_TIMESEPARATOR . "{$end_desc}";
4277
                } else {
4278
                    $ret = "$dot {$start_desc}" . _APCAL_MB_TIMESEPARATOR . "{$stuffing}";
4279
                }
4280
            } else {
4281
                if ($is_end_date) {
4282
                    $ret = "$dot {$stuffing}" . _APCAL_MB_TIMESEPARATOR . "{$end_desc}";
4283
                } else {
4284
                    $ret = "$dot " . _APCAL_MB_CONTINUING;
4285
                }
4286
            }
4287
4288
            return $ret;
4289
        }
4290
4291
        // $event�������̤��顢�������ͽ����֤�ʸ�����������̾磻�٥�ȤΤߡ�
4292
4293
        /**
4294
         * @param         $event
4295
         * @param         $tzoffset
4296
         * @param         $border_for_2400
4297
         * @param  bool   $justify
4298
         * @param  bool   $admission
4299
         * @return string
4300
         */
4301
        public function get_time_desc_for_a_day(
4302
            $event,
4303
            $tzoffset,
4304
            $border_for_2400,
4305
            $justify = true,
4306
            $admission = true
4307
        ) {
4308
            $start = $event->start + $tzoffset;
4309
            $end   = $event->end + $tzoffset;
4310
4311
            // $day_start ���꤬������Ρ�24:00�ʹߤν���
4312 View Code Duplication
            if ($event->is_start_date && $event->start >= $border_for_2400) {
0 ignored issues
show
Duplication introduced by
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...
4313
                $start_desc = $this->get_middle_hi($start, true);
4314
            } else {
4315
                $start_desc = $this->get_middle_hi($start);
4316
            }
4317
4318 View Code Duplication
            if ($event->is_end_date && $event->end >= $border_for_2400) {
0 ignored issues
show
Duplication introduced by
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...
4319
                $end_desc = $this->get_middle_hi($end, true);
4320
            } else {
4321
                $end_desc = $this->get_middle_hi($end);
4322
            }
4323
4324
            $stuffing = $justify ? '     ' : '';
4325
4326
            // ͽ����ֻ����̵ͭ����ǧ��̵ͭ�ˤ�äƥɥå�GIF���ؤ���
4327 View Code Duplication
            if ($admission) {
0 ignored issues
show
Duplication introduced by
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...
4328
                if ($event->is_start_date) {
4329
                    $dot = "<img border='0' src='$this->images_url/dot_startday.gif' />";
4330
                } elseif ($event->is_end_date) {
4331
                    $dot = "<img border='0' src='$this->images_url/dot_endday.gif' />";
4332
                } else {
4333
                    $dot = "<img border='0' src='$this->images_url/dot_interimday.gif' />";
4334
                }
4335
            } else {
4336
                $dot = "<img border='0' src='$this->images_url/dot_notadmit.gif' />";
4337
            }
4338
4339 View Code Duplication
            if ($event->is_start_date) {
0 ignored issues
show
Duplication introduced by
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...
4340
                if ($event->is_end_date) {
4341
                    $ret = "$dot {$start_desc}" . _APCAL_MB_TIMESEPARATOR . "{$end_desc}";
4342
                } else {
4343
                    $ret = "$dot {$start_desc}" . _APCAL_MB_TIMESEPARATOR . "{$stuffing}";
4344
                }
4345
            } else {
4346
                if ($event->is_end_date) {
4347
                    $ret = "$dot {$stuffing}" . _APCAL_MB_TIMESEPARATOR . "{$end_desc}";
4348
                } else {
4349
                    $ret = "$dot " . _APCAL_MB_CONTINUING;
4350
                }
4351
            }
4352
4353
            return $ret;
4354
        }
4355
4356
        // �������ϥܥå����δؿ� (JavaScript�����Ϥ���ݤ�Override�о�)
4357
4358
        /**
4359
         * @param $name
4360
         * @param $value
4361
         * @return string
4362
         */
4363
        public function get_formtextdateselect($name, $value)
4364
        {
4365
            return "<input type='text' name='$name' size='12' value='$value' style='ime-mode:disabled' />";
4366
        }
4367
4368
        // $this->images_url���ˤ���style.css���ɤ߹��ߡ����˥��������ư��Ϥ�
4369
4370
        /**
4371
         * @return string
4372
         */
4373
        public function get_embed_css()
4374
        {
4375
            $css_filename = "$this->images_path/style.css";
4376
            if (!is_readable($css_filename)) {
4377
                return '';
4378
            } else {
4379
                return strip_tags(implode('', file($css_filename)));
4380
            }
4381
        }
4382
4383
        // ��ƼԤ�ɽ��ʸ������֤� (Override�о�)
4384
4385
        /**
4386
         * @param $uid
4387
         * @return string
4388
         */
4389
        public function get_submitter_info($uid)
4390
        {
4391
            return '';
4392
        }
4393
4394
        // ���ƥ���ط���WHERE�Ѿ�������
4395
4396
        /**
4397
         * @return string
4398
         */
4399
        public function get_where_about_categories()
4400
        {
4401
            if ($this->isadmin) {
4402
                if (empty($this->now_cid)) {
4403
                    // �����Ԥ�����Ԥ�$cid���꤬�ʤ���о��True
4404
                    return '1';
4405
                } else {
4406
                    // �����Ԥ�����Ԥ�$cid���꤬����С���������LIKE����
4407
                    return "categories LIKE '%" . sprintf('%05d,', $this->now_cid) . "%'";
4408
                }
4409
            } else {
4410
                if (empty($this->now_cid)) {
4411
                    // �����Ԥ�����԰ʳ���$cid���꤬�ʤ���С�CAT2GROUP�ˤ������
4412
                    $limit_from_perm = "categories='' OR ";
4413
                    foreach ($this->categories as $cid => $cat) {
4414
                        $limit_from_perm .= "categories LIKE '%" . sprintf('%05d,', $cid) . "%' OR ";
4415
                    }
4416
                    $limit_from_perm = substr($limit_from_perm, 0, -3);
4417
4418
                    return $limit_from_perm;
4419
                } else {
4420
                    // �����Ԥ�����԰ʳ���$cid���꤬����С����¥����å�����$cid����
4421
                    if (isset($this->categories[$this->now_cid])) {
4422
                        return "categories LIKE '%" . sprintf('%05d,', $this->now_cid) . "%'";
4423
                    } else {
4424
                        // ���ꤵ�줿cid�����¤ˤʤ�
4425
                        return '0';
4426
                    }
4427
                }
4428
            }
4429
        }
4430
4431
        // CLASS(�����)�ط���WHERE�Ѿ�������
4432
4433
        /**
4434
         * @return string
4435
         */
4436
        public function get_where_about_class()
4437
        {
4438
            if ($this->isadmin) {
4439
                // �����Ԥ�����Ԥʤ���True
4440
                return '1';
4441
            } elseif ($this->user_id <= 0) {
4442
                // �����Ԥ������Ȥʤ��(PUBLIC)�쥳���ɤΤ�
4443
                return "class='PUBLIC'";
4444
            } else {
4445
                // �̾�桼���ʤ顢PUBLIC�쥳���ɤ����桼��ID�����פ���쥳���ɡ��ޤ��ϡ���°���Ƥ��륰�롼��ID�Τ����ΰ�Ĥ��쥳���ɤΥ��롼��ID�Ȱ��פ���쥳����
4446
                $ids = ' ';
4447
                foreach ($this->groups as $id => $name) {
4448
                    $ids .= "$id,";
4449
                }
4450
                $ids = substr($ids, 0, -1);
4451
                if ((int)$ids == 0) {
4452
                    $group_section = '';
4453
                } else {
4454
                    $group_section = "OR groupid IN ($ids)";
4455
                }
4456
4457
                return "(class='PUBLIC' OR uid=$this->user_id $group_section)";
4458
            }
4459
        }
4460
4461
        // mb_convert_kana���
4462
4463
        /**
4464
         * @param $str
4465
         * @param $option
4466
         * @return string
4467
         */
4468 View Code Duplication
        public function mb_convert_kana($str, $option)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
4469
        {
4470
            // convert_kana �ν���ϡ����ܸ�ǤΤ߹Ԥ�
4471
            if ($this->language !== 'japanese' || !function_exists('mb_convert_kana')) {
4472
                return $str;
4473
            } else {
4474
                return mb_convert_kana($str, $option);
4475
            }
4476
        }
4477
4478
        /*******************************************************************/
4479
        /*   ���˥�������Ϣ�δؿ� (���֥��饹������������Override�о�)   */
4480
        /*******************************************************************/
4481
4482
        /**
4483
         * @param $data
4484
         * @return string
4485
         */
4486
        public function textarea_sanitizer_for_show($data)
4487
        {
4488
            return nl2br(htmlspecialchars($data, ENT_QUOTES));
4489
        }
4490
4491
        /**
4492
         * @param $data
4493
         * @return string
4494
         */
4495
        public function text_sanitizer_for_show($data)
4496
        {
4497
            return htmlspecialchars($data, ENT_QUOTES);
4498
        }
4499
4500
        /**
4501
         * @param $data
4502
         * @return string
4503
         */
4504
        public function textarea_sanitizer_for_edit($data)
4505
        {
4506
            return htmlspecialchars($data, ENT_QUOTES);
4507
        }
4508
4509
        /**
4510
         * @param $data
4511
         * @return string
4512
         */
4513
        public function text_sanitizer_for_edit($data)
4514
        {
4515
            return htmlspecialchars($data, ENT_QUOTES);
4516
        }
4517
4518
        /**
4519
         * @param $data
4520
         * @return mixed
4521
         */
4522
        public function textarea_sanitizer_for_export_ics($data)
4523
        {
4524
            return $data;
4525
        }
4526
4527
        /*******************************************************************/
4528
        /*        iCalendar ����ؿ�                                       */
4529
        /*******************************************************************/
4530
4531
        // iCalendar�����ǤΥХå����ϥץ�åȥե����������ѥե�������֤�
4532
        // $_POST['ids']�ǻ���
4533
        /**
4534
         * @param         $post_target
4535
         * @param  string $target
4536
         * @return string
4537
         */
4538
        public function output_ics_confirm($post_target, $target = '_self')
4539
        {
4540
            // POST�Ǽ�����ä�id�����event_ids����Ȥ���POST����
4541
            $hiddens = '';
4542
            foreach ($_POST['ids'] as $id) {
4543
                $id      = (int)$id;
4544
                $hiddens .= "<input type='hidden' name='event_ids[]' value='$id' />\n";
4545
            }
4546
            // webcal�������
4547
            $webcal_url = str_replace('http://', 'webcal://', $post_target);
4548
4549
            // ��ǧ�ե�������֤�
4550
            return "
4551
    <div style='text-align:center;width:100%;'>&nbsp;<br><b>" . _APCAL_MB_ICALSELECTPLATFORM . "</b><br>&nbsp;</div>
4552
    <table border='0' cellpadding='5' cellspacing='2' width='100%'>
4553
    <tr>
4554
    <td align='right' width='50%'>
4555
    <form class='apcalForm' action='$post_target?output_ics=1' method='post' target='$target'>
4556
        $hiddens
4557
        <input type='submit' name='do_output' value='" . _APCAL_BTN_OUTPUTICS_WIN . "' />
4558
    </form>
4559
    </td>
4560
    <td align='left' width='50%'>
4561
    <form class='apcalForm' action='$webcal_url?output_ics=1' method='post' target='$target'>
4562
        $hiddens
4563
        <input type='submit' name='do_output' value='" . _APCAL_BTN_OUTPUTICS_MAC . "' />
4564
    </form>
4565
    </td>
4566
    </tr>
4567
    </table><br><br>\n";
4568
        }
4569
4570
        // iCalendar�����Ǥν��� (mbstringɬ��)
4571
        // ���Ϥ����Τߤξ���$_GET['event_id']������ξ���$_POST['event_ids']
4572
        public function output_ics()
4573
        {
4574
            // $event_id �����ꤵ��Ƥ��ʤ���н�λ
4575
            if (empty($_GET['event_id']) && empty($_POST['event_ids'])) {
4576
                die(_APCAL_ERR_INVALID_EVENT_ID);
4577
            }
4578
4579
            // iCalendar���ϵ��Ĥ��ʤ���н�λ
4580
            if (!$this->can_output_ics) {
4581
                die(_APCAL_ERR_NOPERM_TO_OUTPUTICS);
4582
            }
4583
            if (isset($_GET['event_id'])) {
4584
                // $_GET[ 'event_id' ] �ˤ��������λ���ξ��
4585
                $event_id  = (int)$_GET['event_id'];
4586
                $event_ids = array($event_id);
4587
                //                $rs        = $xoopsDB->query("SELECT summary AS udtstmp FROM $this->table WHERE id='$event_id'");
4588
                $rs = $GLOBALS['xoopsDB']->query("SELECT summary AS udtstmp FROM $this->table WHERE id='$event_id'");
4589
4590
                if ($GLOBALS['xoopsDB']->getRowsNum($rs) < 1) {
4591
                    die(_APCAL_ERR_INVALID_EVENT_ID);
4592
                }
4593
                //                $summary = mysql_result($rs, 0, 0);
4594
                $summary   = 0;
4595
                $resultRow = $GLOBALS['xoopsDB']->fetchRow($rs);
4596
                if (false !== $resultRow && isset($resultRow[$field])) {
0 ignored issues
show
Bug introduced by
The variable $field seems to never exist, and therefore isset should always return false. Did you maybe rename this variable?

This check looks for calls to isset(...) or empty() on variables that are yet undefined. These calls will always produce the same result and can be removed.

This is most likely caused by the renaming of a variable or the removal of a function/method parameter.

Loading history...
4597
                    $summary = $resultRow[0];
4598
                }
4599
                //                $rs = $xoopsDB->query("SELECT * FROM $cal->table WHERE WHERE id='$event_id'");
4600
4601
                // ��̾ �� X-WR-CALNAME �Ȥ���
4602
                $x_wr_calname = $summary;
4603
                // �ե�����̾�˻Ȥ��ʤ�������ʸ��Ϻ��
4604
                if (function_exists('mb_ereg_replace')) {
4605
                    $summary = mb_ereg_replace('[<>|"?*,:;\\/]', '', $summary);
4606
                } else {
4607
                    $summary = preg_replace('/[<>|"?*,:;\\/]/', '', $summary);
4608
                }
4609
                // �ػ�ʸ����ä���̾.ics ��ե�����̾�Ȥ��� (��SJIS�Ѵ�)
4610
                $output_filename = mb_convert_encoding($summary, 'ASCII') . '.ics';
4611
                $output_filename = str_replace(' ', '', $output_filename);
4612
            } elseif (is_array($_POST['event_ids'])) {
4613
                // $_POST[ 'event_ids' ] �ˤ������ˤ�����ξ��
4614
                $event_ids = array_unique($_POST['event_ids']);
4615
                // events-�������(GMT) �� X-WR-CALNAME �Ȥ���
4616
                $x_wr_calname = 'events-' . gmdate('Ymd\THis\Z');
4617
                // events-�������.ics ��ե�����̾�Ȥ���
4618
                $output_filename = $x_wr_calname . '.ics';
4619
            } else {
4620
                die(_APCAL_ERR_INVALID_EVENT_ID);
4621
            }
4622
4623
            // HTTP header
4624
            header('Pragma: public');
4625
            header('Expires: 0');
4626
            header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
4627
            header('Cache-Control: private', false);
4628
            header('Content-Type: text/calendar');
4629
            header("Content-Disposition: attachment; filename=\"{$output_filename}\";");
4630
4631
            // iCalendar�إå�
4632
            $ical_header = "BEGIN:VCALENDAR\r
4633
CALSCALE:GREGORIAN\r
4634
X-WR-TIMEZONE;VALUE=TEXT:GMT\r
4635
PRODID:ANTIQUES PROMOTION - APCal -\r";
4636
            $ical_header .= $this->ics_new_cal ? "X-WR-CALNAME;VALUE=TEXT:$x_wr_calname\r" : '';
4637
            $ical_header .= "VERSION:2.0\r
4638
METHOD:PUBLISH\r\n";
4639
4640
            // ���ƥ��꡼��Ϣ��WHERE������
4641
            $whr_categories = $this->get_where_about_categories();
4642
4643
            // CLASS��Ϣ��WHERE������
4644
            $whr_class = $this->get_where_about_class();
4645
4646
            // ���٥����Υ롼��
4647
            $vevents_str = '';
4648
            $timezones   = array();
4649
            foreach ($event_ids as $event_id) {
4650
                $event_id = (int)$event_id;
4651
                $sql      = "SELECT *,UNIX_TIMESTAMP(dtstamp) AS udtstmp,DATE_ADD(end_date,INTERVAL 1 DAY) AS end_date_offseted FROM $this->table WHERE id='$event_id' AND ($whr_categories) AND ($whr_class)";
4652
                if (!$rs = $GLOBALS['xoopsDB']->query($sql)) {
4653
                    echo $GLOBALS['xoopsDB']->error();
4654
                }
4655
                $event = $GLOBALS['xoopsDB']->fetchObject($rs);
4656
                if (!$event) {
4657
                    continue;
4658
                }
4659
4660
                if (isset($event->start_date)) {
4661
                    // 1970������2038ǯ�ʹߤ����դ��������ü������٥��
4662
                    $dtstart = str_replace('-', '', $event->start_date);
4663 View Code Duplication
                    if (isset($event->end_date_offseted)) {
0 ignored issues
show
Duplication introduced by
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...
4664
                        $dtend = str_replace('-', '', $event->end_date_offseted);
4665
                    } else {
4666
                        $dtend = date('Ymd', $event->end);
4667
                    }
4668
                    $dtstart_opt = $dtend_opt = ';VALUE=DATE';
4669
                } elseif ($event->allday) {
4670
                    // ����٥�ȡʻ�������ʤ���
4671
                    $dtstart = date('Ymd', $event->start);
4672 View Code Duplication
                    if (isset($event->end_date_offseted)) {
0 ignored issues
show
Duplication introduced by
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...
4673
                        $dtend = str_replace('-', '', $event->end_date_offseted);
4674
                    } else {
4675
                        $dtend = date('Ymd', $event->end);
4676
                    }
4677
                    // ���ϤȽ�λ��Ʊ��ξ��ϡ���λ������ˤ��餹
4678
                    if ($dtstart == $dtend) {
4679
                        $dtend = date('Ymd', $event->end + 86400);
4680
                    }
4681
                    $dtstart_opt = $dtend_opt = ';VALUE=DATE';
4682
                } else {
4683
                    if ($event->rrule) {
4684
                        // �̾磻�٥�Ȥ�RRULE������С����٥��TZ�ǽ���
4685
                        $tzoffset = (int)(($this->server_TZ - $event->event_tz) * 3600);
4686
                        list(, $tzid) = $this->get_timezone_desc($event->event_tz);
4687
                        $dtstart     = date('Ymd\THis', $event->start - $tzoffset);
4688
                        $dtend       = date('Ymd\THis', $event->end - $tzoffset);
4689
                        $dtstart_opt = $dtend_opt = ";TZID=$tzid";
4690
                        // ����ˡ�����VTIMEZONE�����
4691
                        $timezones[$event->event_tz] = 1;
4692
                    } else {
4693
                        // �̾磻�٥�Ȥ�RRULE��̵����С������Фλ��������������GMTɽ��
4694
                        $tzoffset    = $this->server_TZ * 3600;
4695
                        $dtstart     = date('Ymd\THis\Z', $event->start - $tzoffset);
4696
                        $dtend       = date('Ymd\THis\Z', $event->end - $tzoffset);
4697
                        $dtstart_opt = $dtend_opt = '';
4698
                    }
4699
                }
4700
4701
                // DTSTAMP�Ͼ��GMT
4702
                $dtstamp = date('Ymd\THis\Z', $event->udtstmp - $this->server_TZ * 3600);
4703
4704
                // DESCRIPTION�� folding , \r��� ����� \n -> \\n �Ѵ�, ���˥�����
4705
                // (folding ̤����) TODO
4706
                $description = str_replace("\r", '', $event->description);
4707
                $description = str_replace("\n", '\n', $description);
4708
                $description = $this->textarea_sanitizer_for_export_ics($description);
4709
4710
                // ���ƥ��꡼��ɽ��
4711
                $categories = '';
4712
                $cids       = explode(',', $event->categories);
4713
                foreach ($cids as $cid) {
4714
                    $cid = (int)$cid;
4715
                    if (isset($this->categories[$cid])) {
4716
                        $categories .= $this->categories[$cid]->cat_title . ',';
4717
                    }
4718
                }
4719
                if ($categories !== '') {
4720
                    $categories = substr($categories, 0, -1);
4721
                }
4722
4723
                // RRULE�Ԥϡ�RRULE����Ȥ��������������
4724
                $rrule_line = $event->rrule ? "RRULE:{$event->rrule}\r\n" : '';
4725
4726
                // ���٥�ȥǡ����ν���
4727
                $vevents_str .= "BEGIN:VEVENT\r
4728
DTSTART{$dtstart_opt}:{$dtstart}\r
4729
DTEND{$dtend_opt}:{$dtend}\r
4730
LOCATION:{$event->location}\r
4731
TRANSP:OPAQUE\r
4732
SEQUENCE:{$event->sequence}\r
4733
UID:{$event->unique_id}\r
4734
DTSTAMP:{$dtstamp}\r
4735
CATEGORIES:{$categories}\r
4736
DESCRIPTION:{$description}\r
4737
SUMMARY:{$event->summary}\r
4738
{$rrule_line}PRIORITY:{$event->priority}\r
4739
CLASS:{$event->class}\r
4740
END:VEVENT\r\n";
4741
            }
4742
4743
            // VTIMEZONE
4744
            $vtimezones_str = $this->get_vtimezones_str($timezones);
4745
4746
            // iCalendar�եå�
4747
            $ical_footer = "END:VCALENDAR\r\n";
4748
4749
            $ical_data = "$ical_header$vtimezones_str$vevents_str$ical_footer";
4750
4751
            // mbstring ��������Τߡ�UTF-8 �ؤ��Ѵ�
4752
            if (extension_loaded('mbstring')) {
4753
                mb_http_output('pass');
4754
                $ical_data = mb_convert_encoding($ical_data, 'UTF-8');
4755
            }
4756
4757
            echo $ical_data;
4758
4759
            exit;
4760
        }
4761
4762
        /**
4763
         * @param         $uri
4764
         * @param  bool   $force_http
4765
         * @param  string $user_uri
4766
         * @return string
4767
         */
4768
        public function import_ics_via_fopen($uri, $force_http = true, $user_uri = '')
4769
        {
4770
            if (strlen($uri) < 5) {
4771
                return '-1:';
4772
            }
4773
            $user_uri = empty($user_uri) ? '' : $uri;
4774
            // webcal://* �� connection̤����⡢���٤� http://* �����
4775
            $uri = str_replace('webcal://', 'http://', $uri);
4776
4777
            if ($force_http) {
4778
                //                if (substr($uri, 0, 7) !== 'http://') {
4779
                if (0 !== strpos($uri, 'http://')) {
4780
                    $uri = 'http://' . $uri;
4781
                }
4782
            }
4783
4784
            // iCal parser �ˤ�����
4785
            require_once "$this->base_path/class/iCal_parser.php";
4786
            $ical           = new iCal_parser();
4787
            $ical->language = $this->language;
4788
            $ical->timezone = ($this->server_TZ >= 0 ? '+' : '-') . sprintf('%02d%02d', abs($this->server_TZ), abs($this->server_TZ) * 60 % 60);
4789
            list($ret_code, $message, $filename) = explode(':', $ical->parse($uri, $user_uri), 3);
4790
            if ($ret_code != 0) {
4791
                // �ѡ������Ԥʤ�-1�ȥ��顼��å��������֤�
4792
                return "-1: $message : $filename";
4793
            }
4794
            $setsqls = $ical->output_setsqls();
4795
4796
            $count = 0;
4797 View Code Duplication
            foreach ($setsqls as $setsql) {
0 ignored issues
show
Duplication introduced by
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...
4798
                $sql = "INSERT INTO $this->table SET $setsql,admission=1,uid=$this->user_id,poster_tz='$this->user_TZ',server_tz='$this->server_TZ'";
4799
4800
                if (!$GLOBALS['xoopsDB']->query($sql)) {
4801
                    die($GLOBALS['xoopsDB']->error());
4802
                }
4803
                $this->update_record_after_import($GLOBALS['xoopsDB']->getInsertId($this->conn));
4804
4805
                ++$count;
4806
            }
4807
4808
            return "$count: $message:";
4809
        }
4810
4811
        /**
4812
         * @param $userfile
4813
         * @return string
4814
         */
4815
        public function import_ics_via_upload($userfile)
4816
        {
4817
            // ics�ե�����򥯥饤����ȥޥ��󤫤饢�åץ?�ɤ����ɹ���
4818
            require_once "$this->base_path/class/iCal_parser.php";
4819
            $ical           = new iCal_parser();
4820
            $ical->language = $this->language;
4821
            $ical->timezone = ($this->server_TZ >= 0 ? '+' : '-') . sprintf('%02d%02d', abs($this->server_TZ), abs($this->server_TZ) * 60 % 60);
4822
            list($ret_code, $message, $filename) = explode(':', $ical->parse($_FILES[$userfile]['tmp_name'], $_FILES[$userfile]['name']), 3);
4823
            if ($ret_code != 0) {
4824
                // �ѡ������Ԥʤ�-1�ȥ��顼��å��������֤�
4825
                return "-1: $message : $filename";
4826
            }
4827
            $setsqls = $ical->output_setsqls();
4828
4829
            $count = 0;
4830 View Code Duplication
            foreach ($setsqls as $setsql) {
0 ignored issues
show
Duplication introduced by
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...
4831
                $sql = "INSERT INTO $this->table SET $setsql,admission=1,uid=$this->user_id,poster_tz='$this->user_TZ',server_tz='$this->server_TZ'";
4832
4833
                if (!$GLOBALS['xoopsDB']->query($sql)) {
4834
                    die($GLOBALS['xoopsDB']->error());
4835
                }
4836
                $this->update_record_after_import($GLOBALS['xoopsDB']->getInsertId($this->conn));
4837
4838
                ++$count;
4839
            }
4840
4841
            return "$count: $message :";
4842
        }
4843
4844
        // ���쥳���ɤ��ɤ߹��߸�˹Ԥ����� ��rrule��Ÿ����categories��cid���ʤɡ�
4845
4846
        /**
4847
         * @param $event_id
4848
         */
4849
        public function update_record_after_import($event_id)
4850
        {
4851
            $rs    = $GLOBALS['xoopsDB']->query("SELECT categories,rrule FROM $this->table WHERE id='$event_id'");
4852
            $event = $GLOBALS['xoopsDB']->fetchObject($rs);
4853
4854
            // categories �� cid�� ( '\,' -> ',' ��Outlook�к�)
4855
            $event->categories = str_replace('\,', ',', $event->categories);
4856
            $cat_names         = explode(',', $event->categories);
4857
            for ($i = 0, $iMax = count($cat_names); $i < $iMax; ++$i) {
4858
                $cat_names[$i] = trim($cat_names[$i]);
4859
            }
4860
            $categories = '';
4861
            foreach ($this->categories as $cid => $cat) {
4862
                if (in_array($cat->cat_title, $cat_names)) {
4863
                    $categories .= sprintf('%05d,', $cid);
4864
                }
4865
            }
4866
4867
            // rrule_pid ���
4868
            $rrule_pid = $event->rrule ? $event_id : 0;
4869
4870
            // �쥳���ɹ���
4871
            $GLOBALS['xoopsDB']->query("UPDATE $this->table SET categories='$categories',rrule_pid='$rrule_pid' WHERE id='$event_id'");
4872
4873
            // RRULE���顢�ҥ쥳���ɤ�Ÿ��
4874
            if ($event->rrule !== '') {
4875
                $this->rrule_extract($event_id);
4876
            }
4877
4878
            // GIJ TODO category �μ�ư��Ͽ class,groupid �ν���
4879
        }
4880
4881
        /*******************************************************************/
4882
        /*        RRULE ����ؿ�                                           */
4883
        /*******************************************************************/
4884
4885
        // rrule����������������륯�饹�ؿ�
4886
        /**
4887
         * @param $rrule
4888
         * @return string
4889
         */
4890
        public function rrule_to_human_language($rrule)
4891
        {
4892
            $rrule = trim($rrule);
4893
            if ($rrule === '') {
4894
                return '';
4895
            }
4896
4897
            // rrule �γ����Ǥ��ѿ���Ÿ��
4898
            $rrule = strtoupper($rrule);
4899
            $rules = explode(';', $rrule);
4900 View Code Duplication
            foreach ($rules as $rule) {
0 ignored issues
show
Duplication introduced by
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...
4901
                list($key, $val) = explode('=', $rule, 2);
4902
                $key  = trim($key);
4903
                $$key = trim($val);
4904
            }
4905
4906
            if (empty($FREQ)) {
0 ignored issues
show
Bug introduced by
The variable $FREQ seems only to be defined at a later point. As such the call to empty() seems to always evaluate to true.

This check marks calls to isset(...) or empty(...) that are found before the variable itself is defined. These will always have the same result.

This is likely the result of code being shifted around. Consider removing these calls.

Loading history...
4907
                $FREQ = 'DAILY';
4908
            }
4909
            if (empty($INTERVAL) || $INTERVAL <= 0) {
0 ignored issues
show
Bug introduced by
The variable $INTERVAL seems only to be defined at a later point. As such the call to empty() seems to always evaluate to true.

This check marks calls to isset(...) or empty(...) that are found before the variable itself is defined. These will always have the same result.

This is likely the result of code being shifted around. Consider removing these calls.

Loading history...
4910
                $INTERVAL = 1;
4911
            }
4912
4913
            // ���پ�����
4914
            $ret_freq = '';
4915
            $ret_day  = '';
4916
            switch ($FREQ) {
4917
                case 'DAILY':
4918
                    if ($INTERVAL == 1) {
4919
                        $ret_freq = _APCAL_RR_EVERYDAY;
4920
                    } else {
4921
                        $ret_freq = sprintf(_APCAL_RR_PERDAY, $INTERVAL);
4922
                    }
4923
                    break;
4924
                case 'WEEKLY':
4925
                    if (empty($BYDAY)) {
0 ignored issues
show
Bug introduced by
The variable $BYDAY seems to never exist, and therefore empty should always return true. Did you maybe rename this variable?

This check looks for calls to isset(...) or empty() on variables that are yet undefined. These calls will always produce the same result and can be removed.

This is most likely caused by the renaming of a variable or the removal of a function/method parameter.

Loading history...
4926
                        break;
4927
                    }    // BYDAY ɬ��
4928
                    $ret_day = strtr($BYDAY, $this->byday2langday_w);
4929
                    if ($INTERVAL == 1) {
4930
                        $ret_freq = _APCAL_RR_EVERYWEEK;
4931
                    } else {
4932
                        $ret_freq = sprintf(_APCAL_RR_PERWEEK, $INTERVAL);
4933
                    }
4934
                    break;
4935
                case 'MONTHLY':
4936
                    if (isset($BYMONTHDAY)) {
0 ignored issues
show
Bug introduced by
The variable $BYMONTHDAY seems to never exist, and therefore isset should always return false. Did you maybe rename this variable?

This check looks for calls to isset(...) or empty() on variables that are yet undefined. These calls will always produce the same result and can be removed.

This is most likely caused by the renaming of a variable or the removal of a function/method parameter.

Loading history...
4937
                        $ret_day   = '';
4938
                        $monthdays = explode(',', $BYMONTHDAY);
4939
                        foreach ($monthdays as $monthday) {
4940
                            $ret_day .= $this->date_long_names[$monthday] . ',';
4941
                        }
4942
                        $ret_day = substr($ret_day, 0, -1);
4943
                    } elseif (isset($BYDAY)) {
4944
                        $ret_day = strtr($BYDAY, $this->byday2langday_m);
4945
                    } else {
4946
                        break;        // BYDAY �ޤ��� BYMONTHDAY ɬ��
4947
                    }
4948
                    if ($INTERVAL == 1) {
4949
                        $ret_freq = _APCAL_RR_EVERYMONTH;
4950
                    } else {
4951
                        $ret_freq = sprintf(_APCAL_RR_PERMONTH, $INTERVAL);
4952
                    }
4953
                    break;
4954
                case 'YEARLY':
4955
                    $ret_day = '';
4956
                    if (!empty($BYMONTH)) {
0 ignored issues
show
Bug introduced by
The variable $BYMONTH seems to never exist, and therefore empty should always return true. Did you maybe rename this variable?

This check looks for calls to isset(...) or empty() on variables that are yet undefined. These calls will always produce the same result and can be removed.

This is most likely caused by the renaming of a variable or the removal of a function/method parameter.

Loading history...
4957
                        $months = explode(',', $BYMONTH);
4958
                        foreach ($months as $month) {
4959
                            $ret_day .= $this->month_long_names[$month] . ',';
4960
                        }
4961
                        $ret_day = substr($ret_day, 0, -1);
4962
                    }
4963
                    if (isset($BYDAY)) {
4964
                        $ret_day .= ' ' . strtr($BYDAY, $this->byday2langday_m);
4965
                    }
4966
                    if ($INTERVAL == 1) {
4967
                        $ret_freq = _APCAL_RR_EVERYYEAR;
4968
                    } else {
4969
                        $ret_freq = sprintf(_APCAL_RR_PERYEAR, $INTERVAL);
4970
                    }
4971
                    break;
4972
            }
4973
4974
            // �������
4975
            $ret_terminator = '';
4976
            // UNTIL �� COUNT ��ξ������ COUNT ͥ��
4977
            if (isset($COUNT) && $COUNT > 0) {
0 ignored issues
show
Bug introduced by
The variable $COUNT seems to never exist, and therefore isset should always return false. Did you maybe rename this variable?

This check looks for calls to isset(...) or empty() on variables that are yet undefined. These calls will always produce the same result and can be removed.

This is most likely caused by the renaming of a variable or the removal of a function/method parameter.

Loading history...
4978
                $ret_terminator = sprintf(_APCAL_RR_COUNT, $COUNT);
4979 View Code Duplication
            } elseif (isset($UNTIL)) {
0 ignored issues
show
Bug introduced by
The variable $UNTIL seems to never exist, and therefore isset should always return false. Did you maybe rename this variable?

This check looks for calls to isset(...) or empty() on variables that are yet undefined. These calls will always produce the same result and can be removed.

This is most likely caused by the renaming of a variable or the removal of a function/method parameter.

Loading history...
Duplication introduced by
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...
4980
                // UNTIL �ϡ�������Ǥ����̵���Ǹ��ʤ�
4981
                $year           = substr($UNTIL, 0, 4);
4982
                $month          = substr($UNTIL, 4, 2);
4983
                $date           = substr($UNTIL, 6, 2);
4984
                $ret_terminator = sprintf(_APCAL_RR_UNTIL, "$year-$month-$date");
4985
            }
4986
4987
            return "$ret_freq $ret_day $ret_terminator";
4988
        }
4989
4990
        // rrule���Խ��ѥե������Ÿ�����륯�饹�ؿ�
4991
4992
        /**
4993
         * @param $rrule
4994
         * @param $until_init
4995
         * @return string
4996
         */
4997
        public function rrule_to_form($rrule, $until_init)
4998
        {
4999
            // �ƽ���ͤ�����
5000
            $norrule_checked       = '';
0 ignored issues
show
Unused Code introduced by
$norrule_checked is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
5001
            $daily_checked         = '';
5002
            $weekly_checked        = '';
5003
            $monthly_checked       = '';
5004
            $yearly_checked        = '';
5005
            $norrule_checked       = '';
5006
            $noterm_checked        = '';
5007
            $count_checked         = '';
5008
            $until_checked         = '';
5009
            $daily_interval_init   = 1;
5010
            $weekly_interval_init  = 1;
5011
            $monthly_interval_init = 1;
5012
            $yearly_interval_init  = 1;
5013
            $count_init            = 1;
5014
            $wdays_checked         = array(
5015
                'SU' => '',
5016
                'MO' => '',
5017
                'TU' => '',
5018
                'WE' => '',
5019
                'TH' => '',
5020
                'FR' => '',
5021
                'SA' => ''
5022
            );
5023
            $byday_m_init          = '';
5024
            $bymonthday_init       = '';
5025
            $bymonths_checked      = array(1 => '', '', '', '', '', '', '', '', '', '', '', '');
5026
5027
            if (trim($rrule) === '') {
5028
                $norrule_checked = 'checked';
5029
            } else {
5030
5031
                // rrule �γ����Ǥ��ѿ���Ÿ��
5032
                $rrule = strtoupper($rrule);
5033
                $rules = explode(';', $rrule);
5034 View Code Duplication
                foreach ($rules as $rule) {
0 ignored issues
show
Duplication introduced by
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...
5035
                    list($key, $val) = explode('=', $rule, 2);
5036
                    $key  = trim($key);
5037
                    $$key = trim($val);
5038
                }
5039
5040
                if (empty($FREQ)) {
0 ignored issues
show
Bug introduced by
The variable $FREQ seems only to be defined at a later point. As such the call to empty() seems to always evaluate to true.

This check marks calls to isset(...) or empty(...) that are found before the variable itself is defined. These will always have the same result.

This is likely the result of code being shifted around. Consider removing these calls.

Loading history...
5041
                    $FREQ = 'DAILY';
5042
                }
5043
                if (empty($INTERVAL) || $INTERVAL <= 0) {
0 ignored issues
show
Bug introduced by
The variable $INTERVAL seems only to be defined at a later point. As such the call to empty() seems to always evaluate to true.

This check marks calls to isset(...) or empty(...) that are found before the variable itself is defined. These will always have the same result.

This is likely the result of code being shifted around. Consider removing these calls.

Loading history...
5044
                    $INTERVAL = 1;
5045
                }
5046
5047
                // ���پ�����
5048
                switch ($FREQ) {
5049
                    case 'DAILY':
5050
                        $daily_interval_init = $INTERVAL;
5051
                        $daily_checked       = 'checked';
5052
                        break;
5053
                    case 'WEEKLY':
5054
                        if (empty($BYDAY)) {
0 ignored issues
show
Bug introduced by
The variable $BYDAY seems to never exist, and therefore empty should always return true. Did you maybe rename this variable?

This check looks for calls to isset(...) or empty() on variables that are yet undefined. These calls will always produce the same result and can be removed.

This is most likely caused by the renaming of a variable or the removal of a function/method parameter.

Loading history...
5055
                            break;
5056
                        }    // BYDAY ɬ��
5057
                        $weekly_interval_init = $INTERVAL;
5058
                        $weekly_checked       = 'checked';
5059
                        $wdays                = explode(',', $BYDAY, 7);
5060
                        foreach ($wdays as $wday) {
5061
                            if (isset($wdays_checked[$wday])) {
5062
                                $wdays_checked[$wday] = 'checked';
5063
                            }
5064
                        }
5065
                        break;
5066
                    case 'MONTHLY':
5067
                        if (isset($BYDAY)) {
5068
                            $byday_m_init = $BYDAY;
5069
                        } elseif (isset($BYMONTHDAY)) {
0 ignored issues
show
Bug introduced by
The variable $BYMONTHDAY does not exist. Did you mean $bymonthday_init?

This check looks for variables that are accessed but have not been defined. It raises an issue if it finds another variable that has a similar name.

The variable may have been renamed without also renaming all references.

Loading history...
5070
                            $bymonthday_init = $BYMONTHDAY;
5071
                        } else {
5072
                            break;    // BYDAY �ޤ��� BYMONTHDAY ɬ��
5073
                        }
5074
                        $monthly_interval_init = $INTERVAL;
5075
                        $monthly_checked       = 'checked';
5076
                        break;
5077
                    case 'YEARLY':
5078
                        if (empty($BYMONTH)) {
0 ignored issues
show
Bug introduced by
The variable $BYMONTH seems only to be defined at a later point. As such the call to empty() seems to always evaluate to true.

This check marks calls to isset(...) or empty(...) that are found before the variable itself is defined. These will always have the same result.

This is likely the result of code being shifted around. Consider removing these calls.

Loading history...
5079
                            $BYMONTH = '';
5080
                        }
5081
                        if (isset($BYDAY)) {
5082
                            $byday_m_init = $BYDAY;
5083
                        }
5084
                        $yearly_interval_init = $INTERVAL;
5085
                        $yearly_checked       = 'checked';
5086
                        $months               = explode(',', $BYMONTH, 12);
5087
                        foreach ($months as $month) {
5088
                            $month = (int)$month;
5089
                            if ($month > 0 && $month <= 12) {
5090
                                $bymonths_checked[$month] = 'checked';
5091
                            }
5092
                        }
5093
                        break;
5094
                }
5095
5096
                // �������
5097
                // UNTIL �� COUNT ��ξ������ COUNT ͥ��
5098
                if (isset($COUNT) && $COUNT > 0) {
0 ignored issues
show
Bug introduced by
The variable $COUNT seems to never exist, and therefore isset should always return false. Did you maybe rename this variable?

This check looks for calls to isset(...) or empty() on variables that are yet undefined. These calls will always produce the same result and can be removed.

This is most likely caused by the renaming of a variable or the removal of a function/method parameter.

Loading history...
5099
                    $count_init    = $COUNT;
5100
                    $count_checked = 'checked';
5101 View Code Duplication
                } elseif (isset($UNTIL)) {
0 ignored issues
show
Bug introduced by
The variable $UNTIL seems to never exist, and therefore isset should always return false. Did you maybe rename this variable?

This check looks for calls to isset(...) or empty() on variables that are yet undefined. These calls will always produce the same result and can be removed.

This is most likely caused by the renaming of a variable or the removal of a function/method parameter.

Loading history...
Duplication introduced by
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...
5102
                    // UNTIL �ϡ�����ǡ����Ǥ����̵���Ǹ��ʤ�
5103
                    $year          = substr($UNTIL, 0, 4);
5104
                    $month         = substr($UNTIL, 4, 2);
5105
                    $date          = substr($UNTIL, 6, 2);
5106
                    $until_init    = "$year-$month-$date";
5107
                    $until_checked = 'checked';
5108
                } else {
5109
                    // ξ�ԤȤ���꤬�ʤ���С���λ���ʤ�
5110
                    $noterm_checked = 'checked';
5111
                }
5112
            }
5113
5114
            // UNTIL ����ꤹ�뤿��Υܥå���
5115
            $textbox_until = $this->get_formtextdateselect('rrule_until', $until_init);
5116
5117
            // ������������å��ܥå�����Ÿ��
5118
            $wdays_checkbox = '';
5119
            foreach ($this->byday2langday_w as $key => $val) {
5120
                $wdays_checkbox .= "<input type='checkbox' name='rrule_weekly_bydays[]' value='$key' {$wdays_checked[$key]} />$val &nbsp; \n";
5121
            }
5122
5123
            // ����������å��ܥå�����Ÿ��
5124
            $bymonth_checkbox = "<table border='0' cellpadding='2'><tr>\n";
5125
            foreach ($bymonths_checked as $key => $val) {
5126
                $bymonth_checkbox .= "<td><input type='checkbox' name='rrule_bymonths[]' value='$key' $val />{$this->month_short_names[$key]}</td>\n";
5127
                if ($key == 6) {
5128
                    $bymonth_checkbox .= "</tr>\n<tr>\n";
5129
                }
5130
            }
5131
            $bymonth_checkbox .= "</tr></table>\n";
5132
5133
            // ��N��������OPTION��Ÿ��
5134
            $byday_m_options = '';
5135
            foreach ($this->byday2langday_m as $key => $val) {
5136
                if ($byday_m_init == $key) {
5137
                    $byday_m_options .= "<option value='$key' selected>$val</option>\n";
5138
                } else {
5139
                    $byday_m_options .= "<option value='$key'>$val</option>\n";
5140
                }
5141
            }
5142
5143
            return "
5144
            <input type='radio' name='rrule_freq' value='none' $norrule_checked />"
5145
                   . _APCAL_RR_R_NORRULE
5146
                   . "<br>
5147
            <br>
5148
            <fieldset>
5149
                <legend class='blockTitle'>"
5150
                   . _APCAL_RR_R_YESRRULE
5151
                   . "</legend>
5152
                <fieldset>
5153
                    <legend class='blockTitle'><input type='radio' name='rrule_freq' value='daily' $daily_checked />"
5154
                   . _APCAL_RR_FREQDAILY
5155
                   . '</legend>
5156
                    '
5157
                   . _APCAL_RR_FREQDAILY_PRE
5158
                   . " <input type='text' size='2' name='rrule_daily_interval' value='$daily_interval_init' /> "
5159
                   . _APCAL_RR_FREQDAILY_SUF
5160
                   . "
5161
                </fieldset>
5162
                <br>
5163
                <fieldset>
5164
                    <legend class='blockTitle'><input type='radio' name='rrule_freq' value='weekly' $weekly_checked />"
5165
                   . _APCAL_RR_FREQWEEKLY
5166
                   . '</legend>
5167
                    '
5168
                   . _APCAL_RR_FREQWEEKLY_PRE
5169
                   . "<input type='text' size='2' name='rrule_weekly_interval' value='$weekly_interval_init' /> "
5170
                   . _APCAL_RR_FREQWEEKLY_SUF
5171
                   . " <br>
5172
                    $wdays_checkbox
5173
                </fieldset>
5174
                <br>
5175
                <fieldset>
5176
                    <legend class='blockTitle'><input type='radio' name='rrule_freq' value='monthly' $monthly_checked />"
5177
                   . _APCAL_RR_FREQMONTHLY
5178
                   . '</legend>
5179
                    '
5180
                   . _APCAL_RR_FREQMONTHLY_PRE
5181
                   . "<input type='text' size='2' name='rrule_monthly_interval' value='$monthly_interval_init' /> "
5182
                   . _APCAL_RR_FREQMONTHLY_SUF
5183
                   . " &nbsp;
5184
                    <select name='rrule_monthly_byday'>
5185
                        <option value=''>"
5186
                   . _APCAL_RR_S_NOTSELECTED
5187
                   . "</option>
5188
                        $byday_m_options
5189
                    </select> &nbsp; "
5190
                   . _APCAL_RR_OR
5191
                   . " &nbsp;
5192
                    <input type='text' size='10' name='rrule_bymonthday' value='$bymonthday_init' />"
5193
                   . _APCAL_NTC_MONTHLYBYMONTHDAY
5194
                   . "
5195
                </fieldset>
5196
                <br>
5197
                <fieldset>
5198
                    <legend class='blockTitle'><input type='radio' name='rrule_freq' value='yearly' $yearly_checked />"
5199
                   . _APCAL_RR_FREQYEARLY
5200
                   . '</legend>
5201
                    '
5202
                   . _APCAL_RR_FREQYEARLY_PRE
5203
                   . "<input type='text' size='2' name='rrule_yearly_interval' value='$yearly_interval_init' /> "
5204
                   . _APCAL_RR_FREQYEARLY_SUF
5205
                   . " <br>
5206
                    $bymonth_checkbox <br>
5207
                    <select name='rrule_yearly_byday'>
5208
                        <option value=''>"
5209
                   . _APCAL_RR_S_SAMEASBDATE
5210
                   . "</option>
5211
                        $byday_m_options
5212
                    </select>
5213
                </fieldset>
5214
                <br>
5215
                <input type='radio' name='rrule_terminator' value='noterm' $noterm_checked onClick='document.MainForm.rrule_until.disabled=true;document.MainForm.rrule_count.disabled=true;' />"
5216
                   . _APCAL_RR_R_NOCOUNTUNTIL
5217
                   . ' &nbsp; '
5218
                   . sprintf(_APCAL_NTC_EXTRACTLIMIT, $this->max_rrule_extract)
5219
                   . "  <br>
5220
                <input type='radio' name='rrule_terminator' value='count' $count_checked onClick='document.MainForm.rrule_until.disabled=true;document.MainForm.rrule_count.disabled=false;' />"
5221
                   . _APCAL_RR_R_USECOUNT_PRE
5222
                   . " <input type='text' size='3' name='rrule_count' value='$count_init' /> "
5223
                   . _APCAL_RR_R_USECOUNT_SUF
5224
                   . "<br>
5225
                <input type='radio' name='rrule_terminator' value='until' $until_checked onClick='document.MainForm.rrule_until.disabled=false;document.MainForm.rrule_count.disabled=true;' />"
5226
                   . _APCAL_RR_R_USEUNTIL
5227
                   . " $textbox_until
5228
            </fieldset>
5229
  \n";
5230
        }
5231
5232
        // POST���줿rrule��Ϣ�������ͤ�RRULEʸ������Ȥ߾夲�륯�饹�ؿ�
5233
5234
        /**
5235
         * @param $start
5236
         * @param $allday_flag
5237
         * @return string
0 ignored issues
show
Documentation introduced by
Should the return type not be string|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
5238
         */
5239
        public function rrule_from_post($start, $allday_flag)
5240
        {
5241
            // �����֤�̵���ʤ顢̵���Ƕ�ʸ������֤�
5242
            if ($_POST['rrule_freq'] === 'none') {
5243
                return '';
5244
            }
5245
5246
            // ���پ��
5247
            switch (strtoupper($_POST['rrule_freq'])) {
5248
                case 'DAILY':
5249
                    $ret_freq = 'FREQ=DAILY;INTERVAL=' . abs((int)$_POST['rrule_daily_interval']);
5250
                    break;
5251
                case 'WEEKLY':
5252
                    $ret_freq = 'FREQ=WEEKLY;INTERVAL=' . abs((int)$_POST['rrule_weekly_interval']);
5253
                    if (empty($_POST['rrule_weekly_bydays'])) {
5254
                        // ����λ��꤬��Ĥ�ʤ���С��������Ʊ������ˤ���
5255
                        $bydays = array_keys($this->byday2langday_w);
5256
                        $byday  = $bydays[date('w', $start)];
5257
                    } else {
5258
                        $byday = '';
5259
                        foreach ($_POST['rrule_weekly_bydays'] as $wday) {
5260
                            if (preg_match('/[^\w]+/', $wday)) {
5261
                                die('Some injection was tried');
5262
                            }
5263
                            $byday .= substr($wday, 0, 2) . ',';
5264
                        }
5265
                        $byday = substr($byday, 0, -1);
5266
                    }
5267
                    $ret_freq .= ";BYDAY=$byday";
5268
                    break;
5269
                case 'MONTHLY':
5270
                    $ret_freq = 'FREQ=MONTHLY;INTERVAL=' . abs((int)$_POST['rrule_monthly_interval']);
5271
                    if ($_POST['rrule_monthly_byday'] !== '') {
5272
                        // ��N����ˤ�����
5273
                        $byday = substr(trim($_POST['rrule_monthly_byday']), 0, 4);
5274
                        if (preg_match('/[^\w-]+/', $byday)) {
5275
                            die('Some injection was tried');
5276
                        }
5277
                        $ret_freq .= ";BYDAY=$byday";
5278
                    } elseif ($_POST['rrule_bymonthday'] !== '') {
5279
                        // ���դˤ�����
5280
                        $bymonthday = preg_replace('/[^0-9,]+/', '', $_POST['rrule_bymonthday']);
5281
                        $ret_freq   .= ";BYMONTHDAY=$bymonthday";
5282
                    } else {
5283
                        // ��N��������դλ��꤬�ʤ���С��������Ʊ�����դȤ���
5284
                        $ret_freq .= ';BYMONTHDAY=' . date('j', $start);
5285
                    }
5286
                    break;
5287
                case 'YEARLY':
5288
                    $ret_freq = 'FREQ=YEARLY;INTERVAL=' . abs((int)$_POST['rrule_yearly_interval']);
5289
                    if (empty($_POST['rrule_bymonths'])) {
5290
                        // ��λ��꤬��Ĥ�ʤ���С��������Ʊ����ˤ���
5291
                        $bymonth = date('n', $start);
5292
                    } else {
5293
                        $bymonth = '';
5294
                        foreach ($_POST['rrule_bymonths'] as $month) {
5295
                            $bymonth .= (int)$month . ',';
5296
                        }
5297
                        $bymonth = substr($bymonth, 0, -1);
5298
                    }
5299
                    if ($_POST['rrule_yearly_byday'] !== '') {
5300
                        // ��N����ˤ�����
5301
                        $byday = substr(trim($_POST['rrule_yearly_byday']), 0, 4);
5302
                        if (preg_match('/[^\w-]+/', $byday)) {
5303
                            die('Some injection was tried');
5304
                        }
5305
                        $ret_freq .= ";BYDAY=$byday";
5306
                    }
5307
                    $ret_freq .= ";BYMONTH=$bymonth";
5308
                    break;
5309
                default:
5310
                    return '';
5311
            }
5312
5313
            // ����
5314
            if (empty($_POST['rrule_terminator'])) {
5315
                $_POST['rrule_terminator'] = '';
5316
            }
5317
            switch (strtoupper($_POST['rrule_terminator'])) {
5318
                case 'COUNT':
5319
                    $ret_term = ';COUNT=' . abs((int)$_POST['rrule_count']);
5320
                    break;
5321
                case 'UNTIL':
5322
                    // UNTIL��Unixtime��
5323
                    list($until, $until_date, $use_default) = $this->parse_posted_date($this->mb_convert_kana($_POST['rrule_until'], 'a'), $this->unixtime);
0 ignored issues
show
Unused Code introduced by
The assignment to $use_default is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
5324
                    // 1970������2038ǯ�ʹߤʤ顢UNTIL̵��
5325
                    if ($until_date) {
5326
                        $ret_term = '';
5327
                    } else {
5328
                        if (!$allday_flag) {
5329
                            // ����٥�ȤǤʤ����Ʊ���23:59:59��λ����ȸ��ʤ��ơ� UTC �ػ����׻�����
5330
                            $event_tz = isset($_POST['event_tz']) ? $_POST['event_tz'] : $this->user_TZ;
5331
                            $until    = $until - (int)($event_tz * 3600) + 86400 - 1;
5332
                        }
5333
                        $ret_term = ';UNTIL=' . date('Ymd\THis\Z', $until);
5334
                    }
5335
                    break;
5336
                case 'NOTERM':
5337
                default:
5338
                    $ret_term = '';
5339
                    break;
5340
            }
5341
5342
            // WKST�ϡ���ư�������
5343
            $ret_wkst = $this->week_start ? ';WKST=MO' : ';WKST=SU';
5344
5345
            return $ret_freq . $ret_term . $ret_wkst;
5346
        }
5347
5348
        // �Ϥ��줿event_id����(��)�Ȥ��ơ�RRULE��Ÿ�����ƥǡ����١�����ȿ��
5349
5350
        /**
5351
         * @param $event_id
5352
         */
5353
        public function rrule_extract($event_id)
5354
        {
5355
            $yrs = $GLOBALS['xoopsDB']->query("SELECT *,TO_DAYS(end_date)-TO_DAYS(start_date) AS date_diff FROM $this->table WHERE id='$event_id'");
5356
            if ($GLOBALS['xoopsDB']->getRowsNum($yrs) < 1) {
5357
                return;
5358
            }
5359
            $event = $GLOBALS['xoopsDB']->fetchObject($yrs);
5360
5361
            if ($event->rrule === '') {
5362
                return;
5363
            }
5364
5365
            // rrule �γ����Ǥ��ѿ���Ÿ��
5366
            $rrule = strtoupper($event->rrule);
5367
            $rules = explode(';', $rrule);
5368 View Code Duplication
            foreach ($rules as $rule) {
0 ignored issues
show
Duplication introduced by
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...
5369
                list($key, $val) = explode('=', $rule, 2);
5370
                $key  = trim($key);
5371
                $$key = trim($val);
5372
            }
5373
5374
            // �����ˤ�äơ�RRULE�����ջ��꤬�ɤ��֤�����뤫�η׻�
5375
            if ($event->allday) {
5376
                $tzoffset_date = 0;
5377
            } else {
5378
                // ���٥�ȼ��Ȥ�TZ��Ÿ������
5379
                $tzoffset_s2e  = (int)(($event->event_tz - $this->server_TZ) * 3600);
5380
                $tzoffset_date = date('z', $event->start + $tzoffset_s2e) - date('z', $event->start);
5381
                if ($tzoffset_date > 1) {
5382
                    $tzoffset_date = -1;
5383
                } elseif ($tzoffset_date < -1) {
5384
                    $tzoffset_date = 1;
5385
                }
5386
            }
5387
5388
            if (empty($FREQ)) {
0 ignored issues
show
Bug introduced by
The variable $FREQ seems only to be defined at a later point. As such the call to empty() seems to always evaluate to true.

This check marks calls to isset(...) or empty(...) that are found before the variable itself is defined. These will always have the same result.

This is likely the result of code being shifted around. Consider removing these calls.

Loading history...
5389
                $FREQ = 'DAILY';
5390
            }
5391
            if (empty($INTERVAL) || $INTERVAL <= 0) {
0 ignored issues
show
Bug introduced by
The variable $INTERVAL seems only to be defined at a later point. As such the call to empty() seems to always evaluate to true.

This check marks calls to isset(...) or empty(...) that are found before the variable itself is defined. These will always have the same result.

This is likely the result of code being shifted around. Consider removing these calls.

Loading history...
5392
                $INTERVAL = 1;
5393
            }
5394
5395
            // �١����Ȥʤ�SQLʸ
5396
            $base_sql = "INSERT INTO $this->table SET uid='$event->uid',groupid='$event->groupid',shortsummary='"
5397
                        . $this->makeShort(utf8_decode(addslashes($event->summary)))
5398
                        . "',summary='"
5399
                        . addslashes($event->summary)
5400
                        . "',location='"
5401
                        . addslashes($event->location)
5402
                        . "',gmlat='{$event->gmlat}',gmlong='{$event->gmlong}',gmzoom='{$event->gmzoom}',organizer='"
5403
                        . addslashes($event->organizer)
5404
                        . "',sequence='$event->sequence',contact='"
5405
                        . addslashes($event->contact)
5406
                        . "',email='"
5407
                        . addslashes($event->email)
5408
                        . "',url='"
5409
                        . addslashes($event->url)
5410
                        . "',tzid='$event->tzid',description='"
5411
                        . addslashes($event->description)
5412
                        . "',dtstamp='$event->dtstamp',mainCategory='{$event->mainCategory}',categories='"
5413
                        . addslashes($event->categories)
5414
                        . "',transp='$event->transp',priority='$event->priority',admission='$event->admission',class='$event->class',rrule='"
5415
                        . addslashes($event->rrule)
5416
                        . "',unique_id='$event->unique_id',allday='$event->allday',start_date=null,end_date=null,cid='$event->cid',event_tz='$event->event_tz',server_tz='$event->server_tz',poster_tz='$event->poster_tz',extkey0='$event->extkey0',extkey1='$event->extkey1',rrule_pid='$event_id'";
5417
5418
            // �������
5419
            // �������
5420
            $count = $this->max_rrule_extract;
5421
            if (isset($COUNT) && $COUNT > 0 && $COUNT < $count) {
0 ignored issues
show
Bug introduced by
The variable $COUNT seems to never exist, and therefore isset should always return false. Did you maybe rename this variable?

This check looks for calls to isset(...) or empty() on variables that are yet undefined. These calls will always produce the same result and can be removed.

This is most likely caused by the renaming of a variable or the removal of a function/method parameter.

Loading history...
5422
                $count = $COUNT;
5423
            }
5424
            // Ÿ����λ��
5425
            if (isset($UNTIL)) {
0 ignored issues
show
Bug introduced by
The variable $UNTIL seems to never exist, and therefore isset should always return false. Did you maybe rename this variable?

This check looks for calls to isset(...) or empty() on variables that are yet undefined. These calls will always produce the same result and can be removed.

This is most likely caused by the renaming of a variable or the removal of a function/method parameter.

Loading history...
5426
                // UNTIL �ϡ�������Ǥ����̵���Ǹ��ʤ�
5427
                $year  = substr($UNTIL, 0, 4);
5428
                $month = substr($UNTIL, 4, 2);
5429
                $date  = substr($UNTIL, 6, 2);
5430
                if (!checkdate($month, $date, $year)) {
5431
                    $until = 0x7FFFFFFF;
5432
                } else {
5433
                    $until = gmmktime(23, 59, 59, $month, $date, $year);
5434
                    if (!$event->allday) {
5435
                        // �����л��֤ȥ��٥�Ȼ��֤����դ��ۤʤ���ˤ�UNTIL�⤺�餹
5436
                        $until -= (int)($tzoffset_date * 86400);
5437
                        // UTC -> server_TZ �λ����׻��ϹԤ�ʤ�
5438
                        // $until -= (int)( $this->server_TZ * 3600 ) ;
5439
                    }
5440
                }
5441
            } else {
5442
                $until = 0x7FFFFFFF;
5443
            }
5444
5445
            // WKST
5446
            if (empty($WKST)) {
0 ignored issues
show
Bug introduced by
The variable $WKST seems only to be defined at a later point. As such the call to empty() seems to always evaluate to true.

This check marks calls to isset(...) or empty(...) that are found before the variable itself is defined. These will always have the same result.

This is likely the result of code being shifted around. Consider removing these calls.

Loading history...
5447
                $WKST = 'MO';
5448
            }
5449
5450
            // UnixTimestamp�ϰϳ��ν���
5451
            if (isset($event->start_date)) {
5452
                // ���Ϥ佪λ��2038ǯ�ʹߤʤ�Ÿ�����ʤ�
5453
                if (date('Y', $event->start) >= 2038) {
5454
                    return;
5455
                }
5456
                if (date('Y', $event->end) >= 2038) {
5457
                    return;
5458
                }
5459
5460
                // 1971ǯ��Ʊ��Ʊ���Ÿ���١�����start�Ȥ���
5461
                $event->start = mktime(0, 0, 0, substr($event->start_date, 5, 2), substr($event->start_date, 8, 2), 1970 + 1);
5462
5463
                // end��1970�����ʤ顢����Ȥä�ȿ�ǡ������Ǥʤ����ϤȤꤢ�������� TODO
5464
                if (isset($event->end_date)) {
5465
                    $event->end = $event->start + ($event->date_diff + 1) * 86400;
5466
                }
5467
            }
5468
5469
            // ���پ�����
5470
            $sqls = array();
5471
            switch ($FREQ) {
5472
                case 'DAILY':
5473
                    $gmstart = $event->start + date('Z', $event->start);
5474
                    $gmend   = $event->end + date('Z', $event->end);
5475
                    for ($c = 1; $c < $count; ++$c) {
5476
                        $gmstart += $INTERVAL * 86400;
5477
                        $gmend   += $INTERVAL * 86400;
5478
                        if ($gmstart > $until) {
5479
                            break;
5480
                        }
5481
                        $sqls[] = $base_sql . ",start=UNIX_TIMESTAMP('" . gmdate('Y-m-d H:i:s', $gmstart) . "'),end=UNIX_TIMESTAMP('" . gmdate('Y-m-d H:i:s', $gmend) . "')";
5482
                    }
5483
                    break;
5484
5485
                case 'WEEKLY':
5486
                    $gmstart     = $event->start + date('Z', $event->start);
5487
                    $gmstartbase = $gmstart;
5488
                    $gmend       = $event->end + date('Z', $event->end);
5489
                    $duration    = $gmend - $gmstart;
5490
                    $wtop_date   = gmdate('j', $gmstart) - gmdate('w', $gmstart);
5491
                    if ($WKST !== 'SU') {
5492
                        $wtop_date = $wtop_date == 7 ? 1 : $wtop_date + 1;
5493
                    }
5494
                    $secondofday = $gmstart % 86400;
5495
                    $month       = gmdate('m', $gmstart);
5496
                    $year        = gmdate('Y', $gmstart);
5497
                    $week_top    = gmmktime(0, 0, 0, $month, $wtop_date, $year);
5498
                    $c           = 1;
5499
                    // ���Ͳ���������κ���
5500
                    $temp_dates = explode(',', $BYDAY);
0 ignored issues
show
Bug introduced by
The variable $BYDAY does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
5501
                    $wdays      = array_keys($this->byday2langday_w);
5502
                    if ($WKST !== 'SU') {
5503
                        // rotate wdays for creating array starting with Monday
5504
                        $sun_date = array_shift($wdays);
5505
                        array_push($wdays, $sun_date);
5506
                    }
5507
                    $dates = array();
5508
                    foreach ($temp_dates as $date) {
5509
                        // measure for bug of PHP<4.2.0
5510
                        if (in_array($date, $wdays)) {
5511
                            $dates[] = array_search($date, $wdays);
5512
                        }
5513
                    }
5514
                    sort($dates);
5515
                    $dates = array_unique($dates);
5516
                    if (!count($dates)) {
5517
                        return;
5518
                    }
5519
                    while (1) {
5520
                        foreach ($dates as $date) {
5521
                            // �����л��֤ȥ��٥�Ȼ��֤�����ۤʤ���ν����ɲ�
5522
                            $gmstart = $week_top + ($date - $tzoffset_date) * 86400 + $secondofday;
5523
                            if ($gmstart <= $gmstartbase) {
5524
                                continue;
5525
                            }
5526
                            $gmend = $gmstart + $duration;
5527
                            if ($gmstart > $until) {
5528
                                break 2;
5529
                            }
5530
                            if (++$c > $count) {
5531
                                break 2;
5532
                            }
5533
                            $sqls[] = $base_sql . ",start=UNIX_TIMESTAMP('" . gmdate('Y-m-d H:i:s', $gmstart) . "'),end=UNIX_TIMESTAMP('" . gmdate('Y-m-d H:i:s', $gmend) . "')";
5534
                        }
5535
                        $week_top += $INTERVAL * 86400 * 7;
5536
                    }
5537
                    break;
5538
5539
                case 'MONTHLY':
5540
                    $gmstart     = $event->start + date('Z', $event->start);
5541
                    $gmstartbase = $gmstart;
5542
                    $gmend       = $event->end + date('Z', $event->end);
5543
                    $duration    = $gmend - $gmstart;
5544
                    $secondofday = $gmstart % 86400;
5545
                    $month       = gmdate('m', $gmstart);
5546
                    $year        = gmdate('Y', $gmstart);
5547
                    $c           = 1;
5548
                    if (isset($BYDAY) && preg_match('/^(-1|[1-4])(SU|MO|TU|WE|TH|FR|SA)/', $BYDAY, $regs)) {
5549
                        // ��N�������(BYDAY)�ξ���ʣ���Բġ�
5550
                        // ��Ū�������ֹ�����
5551
                        $wdays     = array_keys($this->byday2langday_w);
5552
                        $wday      = array_search($regs[2], $wdays);
5553
                        $first_ymw = gmdate('Ym', $gmstart) . (int)((gmdate('j', $gmstart) - 1) / 7);
0 ignored issues
show
Unused Code introduced by
$first_ymw is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
5554
                        if ($regs[1] == -1) {
5555
                            // �ǽ�������ξ��Υ롼��
5556
                            $monthday_bottom = gmmktime(0, 0, 0, $month, 0, $year);
5557 View Code Duplication
                            while (1) {
0 ignored issues
show
Duplication introduced by
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...
5558
                                for ($i = 0; $i < $INTERVAL; ++$i) {
5559
                                    $monthday_bottom += gmdate('t', $monthday_bottom + 86400) * 86400;
5560
                                }
5561
                                // �ǽ���������Ĵ�٤�
5562
                                $last_monthdays_wday = gmdate('w', $monthday_bottom);
5563
                                $date_back           = $wday - $last_monthdays_wday;
5564
                                if ($date_back > 0) {
5565
                                    $date_back -= 7;
5566
                                }
5567
                                // �����л��֤ȥ��٥�Ȼ��֤�����ۤʤ���ν����ɲ�
5568
                                $gmstart = $monthday_bottom + ($date_back - $tzoffset_date) * 86400 + $secondofday;
5569
                                if ($gmstart <= $gmstartbase) {
5570
                                    continue;
5571
                                }
5572
                                $gmend = $gmstart + $duration;
5573
                                if ($gmstart > $until) {
5574
                                    break;
5575
                                }
5576
                                if (++$c > $count) {
5577
                                    break;
5578
                                }
5579
                                $sqls[] = $base_sql . ",start=UNIX_TIMESTAMP('" . gmdate('Y-m-d H:i:s', $gmstart) . "'),end=UNIX_TIMESTAMP('" . gmdate('Y-m-d H:i:s', $gmend) . "')";
5580
                            }
5581
                        } else {
5582
                            // ��N������ξ��Υ롼��
5583
                            $monthday_top       = gmmktime(0, 0, 0, $month, 1, $year);
5584
                            $week_number_offset = ($regs[1] - 1) * 7 * 86400;
5585
                            while (1) {
5586
                                for ($i = 0; $i < $INTERVAL; ++$i) {
5587
                                    $monthday_top += gmdate('t', $monthday_top) * 86400;
5588
                                }
5589
                                // ��N������������Ĵ�٤�
5590
                                $week_numbers_top_wday = gmdate('w', $monthday_top + $week_number_offset);
5591
                                $date_ahead            = $wday - $week_numbers_top_wday;
5592
                                if ($date_ahead < 0) {
5593
                                    $date_ahead += 7;
5594
                                }
5595
                                // �����л��֤ȥ��٥�Ȼ��֤�����ۤʤ���ν����ɲ�
5596
                                $gmstart = $monthday_top + $week_number_offset + ($date_ahead - $tzoffset_date) * 86400 + $secondofday;
5597
                                if ($gmstart <= $gmstartbase) {
5598
                                    continue;
5599
                                }
5600
                                $gmend = $gmstart + $duration;
5601
                                if ($gmstart > $until) {
5602
                                    break;
5603
                                }
5604
                                if (++$c > $count) {
5605
                                    break;
5606
                                }
5607
                                $sqls[] = $base_sql . ",start=UNIX_TIMESTAMP('" . gmdate('Y-m-d H:i:s', $gmstart) . "'),end=UNIX_TIMESTAMP('" . gmdate('Y-m-d H:i:s', $gmend) . "')";
5608
                            }
5609
                        }
5610
                    } elseif (isset($BYMONTHDAY)) {
0 ignored issues
show
Bug introduced by
The variable $BYMONTHDAY seems to never exist, and therefore isset should always return false. Did you maybe rename this variable?

This check looks for calls to isset(...) or empty() on variables that are yet undefined. These calls will always produce the same result and can be removed.

This is most likely caused by the renaming of a variable or the removal of a function/method parameter.

Loading history...
5611
                        // ���ջ���(BYMONTHDAY)�ξ���ʣ���ġ�
5612
                        $monthday_top = gmmktime(0, 0, 0, $month, 1, $year);
5613
                        // BYMONTHDAY ��������ơ�$dates����ˤ���
5614
                        $temp_dates = explode(',', $BYMONTHDAY);
5615
                        $dates      = array();
5616
                        foreach ($temp_dates as $date) {
5617
                            if ($date > 0 && $date <= 31) {
5618
                                $dates[] = (int)$date;
5619
                            }
5620
                        }
5621
                        sort($dates);
5622
                        $dates = array_unique($dates);
5623
                        if (!count($dates)) {
5624
                            return;
5625
                        }
5626 View Code Duplication
                        while (1) {
0 ignored issues
show
Duplication introduced by
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...
5627
                            $months_day = gmdate('t', $monthday_top);
5628
                            foreach ($dates as $date) {
5629
                                // ��κǽ���ե?�����å�
5630
                                if ($date > $months_day) {
5631
                                    $date = $months_day;
5632
                                }
5633
                                // �����л��֤ȥ��٥�Ȼ��֤����դ��ۤʤ���ν����ɲ�
5634
                                $gmstart = $monthday_top + ($date - 1 - $tzoffset_date) * 86400 + $secondofday;
5635
                                if ($gmstart <= $gmstartbase) {
5636
                                    continue;
5637
                                }
5638
                                $gmend = $gmstart + $duration;
5639
                                if ($gmstart > $until) {
5640
                                    break 2;
5641
                                }
5642
                                if (++$c > $count) {
5643
                                    break 2;
5644
                                }
5645
                                $sqls[] = $base_sql . ",start=UNIX_TIMESTAMP('" . gmdate('Y-m-d H:i:s', $gmstart) . "'),end=UNIX_TIMESTAMP('" . gmdate('Y-m-d H:i:s', $gmend) . "')";
5646
                            }
5647
                            for ($i = 0; $i < $INTERVAL; ++$i) {
5648
                                $monthday_top += gmdate('t', $monthday_top) * 86400;
5649
                            }
5650
                        }
5651
                    } else {
5652
                        // ͭ���$BYDAY��$BYMONTHDAY��̵����С������֤�����ʤ�
5653
                        return;
5654
                    }
5655
                    break;
5656
5657
                case 'YEARLY':
5658
                    $gmstart     = $event->start + date('Z', $event->start);
5659
                    $gmstartbase = $gmstart;
5660
                    $gmend       = $event->end + date('Z', $event->end);
5661
                    $duration    = $gmend - $gmstart;
5662
                    $secondofday = $gmstart % 86400;
5663
                    $gmmonth     = gmdate('n', $gmstart);
5664
5665
                    // empty BYMONTH
5666
                    if (empty($BYMONTH)) {
0 ignored issues
show
Bug introduced by
The variable $BYMONTH seems only to be defined at a later point. As such the call to empty() seems to always evaluate to true.

This check marks calls to isset(...) or empty(...) that are found before the variable itself is defined. These will always have the same result.

This is likely the result of code being shifted around. Consider removing these calls.

Loading history...
5667
                        $BYMONTH = $gmmonth;
5668
                    }
5669
5670
                    // BYMONTH ��������ơ�$months����ˤ����BYMONTH��ʣ���ġ�
5671
                    $temp_months = explode(',', $BYMONTH);
5672
                    $months      = array();
5673
                    foreach ($temp_months as $month) {
5674
                        if ($month > 0 && $month <= 12) {
5675
                            $months[] = (int)$month;
5676
                        }
5677
                    }
5678
                    sort($months);
5679
                    $months = array_unique($months);
5680
                    if (!count($months)) {
5681
                        return;
5682
                    }
5683
5684
                    if (isset($BYDAY) && preg_match('/^(-1|[1-4])(SU|MO|TU|WE|TH|FR|SA)/', $BYDAY, $regs)) {
5685
                        // ��N�������ξ���ʣ���Բġ�
5686
                        // ��Ū�������ֹ�����
5687
                        $wdays    = array_keys($this->byday2langday_w);
5688
                        $wday     = array_search($regs[2], $wdays);
5689
                        $first_ym = gmdate('Ym', $gmstart);
5690
                        $year     = gmdate('Y', $gmstart);
5691
                        $c        = 1;
5692
                        if ($regs[1] == -1) {
5693
                            // �ǽ�������ξ��Υ롼��
5694
                            while (1) {
5695
                                foreach ($months as $month) {
5696
                                    // �ǽ���������Ĵ�٤�
5697
                                    $last_monthdays_wday = gmdate('w', gmmktime(0, 0, 0, $month + 1, 0, $year));
5698
                                    $date_back           = $wday - $last_monthdays_wday;
5699
                                    if ($date_back > 0) {
5700
                                        $date_back -= 7;
5701
                                    }
5702
                                    $gmstart = gmmktime(0, 0, 0, $month + 1, $date_back - $tzoffset_date, $year) + $secondofday;
5703
                                    // ����Ʊ����������ɤ��������å�
5704
                                    if (gmdate('Ym', $gmstart) <= $first_ym) {
5705
                                        continue;
5706
                                    }
5707
                                    $gmend = $gmstart + $duration;
5708
                                    if ($gmstart > $until) {
5709
                                        break 2;
5710
                                    }
5711
                                    if (++$c > $count) {
5712
                                        break 2;
5713
                                    }
5714
                                    $sqls[] = $base_sql . ",start=UNIX_TIMESTAMP('" . gmdate('Y-m-d H:i:s', $gmstart) . "'),end=UNIX_TIMESTAMP('" . gmdate('Y-m-d H:i:s', $gmend) . "')";
5715
                                }
5716
                                $year += $INTERVAL;
5717
                                if ($year >= 2038) {
5718
                                    break;
5719
                                }
5720
                            }
5721
                        } else {
5722
                            // ��N������ξ��Υ롼��
5723
                            $week_numbers_top_date = 1 + ($regs[1] - 1) * 7;
5724
                            while (1) {
5725
                                foreach ($months as $month) {
5726
                                    // ��N������������Ĵ�٤�
5727
                                    $week_numbers_top_wday = gmdate('w', gmmktime(0, 0, 0, $month, $week_numbers_top_date, $year));
5728
                                    $date_ahead            = $wday - $week_numbers_top_wday;
5729
                                    if ($date_ahead < 0) {
5730
                                        $date_ahead += 7;
5731
                                    }
5732
                                    $gmstart = gmmktime(0, 0, 0, $month, $week_numbers_top_date + $date_ahead - $tzoffset_date, $year) + $secondofday;
5733
                                    // ����Ʊ����������ɤ��������å�
5734
                                    if (gmdate('Ym', $gmstart) <= $first_ym) {
5735
                                        continue;
5736
                                    }
5737
                                    $gmend = $gmstart + $duration;
5738
                                    if ($gmstart > $until) {
5739
                                        break 2;
5740
                                    }
5741
                                    if (++$c > $count) {
5742
                                        break 2;
5743
                                    }
5744
                                    $sqls[] = $base_sql . ",start=UNIX_TIMESTAMP('" . gmdate('Y-m-d H:i:s', $gmstart) . "'),end=UNIX_TIMESTAMP('" . gmdate('Y-m-d H:i:s', $gmend) . "')";
5745
                                }
5746
                                $year += $INTERVAL;
5747
                                if ($year >= 2038) {
5748
                                    break;
5749
                                }
5750
                            }
5751
                        }
5752
                    } else {
5753
                        // ���ջ���ξ��Υ롼�ס�ʣ���Բġ�
5754
                        $first_date = gmdate('j', $gmstart);
5755
                        $year       = gmdate('Y', $gmstart);
5756
                        $c          = 1;
5757
                        while (1) {
5758
                            foreach ($months as $month) {
5759
                                $date = $first_date;
5760
                                // ��κǽ���ե?�����å�
5761
                                while (!checkdate($month, $date, $year) && $date > 0) {
5762
                                    $date--;
5763
                                }
5764
                                // $date �� gmdate('j') �������Ƥ��뤿�ᡢ$tzoffset_date �ν��������
5765
                                $gmstart = gmmktime(0, 0, 0, $month, $date, $year) + $secondofday;
5766
                                if ($gmstart <= $gmstartbase) {
5767
                                    continue;
5768
                                }
5769
                                $gmend = $gmstart + $duration;
5770
                                if ($gmstart > $until) {
5771
                                    break 2;
5772
                                }
5773
                                if (++$c > $count) {
5774
                                    break 2;
5775
                                }
5776
                                $sqls[] = $base_sql . ",start=UNIX_TIMESTAMP('" . gmdate('Y-m-d H:i:s', $gmstart) . "'),end=UNIX_TIMESTAMP('" . gmdate('Y-m-d H:i:s', $gmend) . "')";
5777
                            }
5778
                            $year += $INTERVAL;
5779
                            if ($year >= 2038) {
5780
                                break;
5781
                            }
5782
                        }
5783
                    }
5784
                    break;
5785
5786
                default:
5787
                    return;
5788
            }
5789
5790
            // echo "<pre>" ; var_dump( $sqls ) ; echo "</pre>" ; exit ;
5791
            foreach ($sqls as $sql) {
5792
                $GLOBALS['xoopsDB']->query($sql);
5793
            }
5794
5795
            $result = $GLOBALS['xoopsDB']->query("SELECT id FROM {$this->table} WHERE rrule_pid={$event_id}");
5796
            $pics   = $GLOBALS['xoopsDB']->query("SELECT * FROM {$this->pic_table} WHERE event_id={$event_id}");
5797
            while ($event = $GLOBALS['xoopsDB']->fetchObject($result)) {
5798
                $GLOBALS['xoopsDB']->query("DELETE FROM {$this->pic_table} WHERE event_id={$event->id}");
5799
                mysqli_data_seek($pics, 0);
5800
                while ($pic = $GLOBALS['xoopsDB']->fetchObject($pics)) {
5801
                    $GLOBALS['xoopsDB']->query("INSERT INTO {$this->pic_table} SET event_id='{$event->id}', picture='{$pic->picture}', main_pic='{$pic->main_pic}'");
5802
                }
5803
            }
5804
        }
5805
5806
        // The End of Class
5807
    }
5808
}
5809