showCountdown()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 49
Code Lines 37

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 1 Features 1
Metric Value
cc 4
eloc 37
c 4
b 1
f 1
nc 4
nop 1
dl 0
loc 49
rs 9.328
1
<?php
2
3
declare(strict_types=1);
4
5
use XoopsModules\Countdown;
6
use XoopsModules\Countdown\Helper;
7
use XoopsModules\Countdown\Constants;
8
9
include_once XOOPS_ROOT_PATH . '/modules/countdown/include/common.php';
10
11
function showCountdown($options)
12
{
13
    /** @var Helper $helper */
14
    if (!class_exists(Helper::class)) {
15
        return false;
16
    }
17
18
    $helper = Helper::getInstance();
19
    $helper->loadLanguage('main');
20
21
    $myts = \MyTextSanitizer::getInstance();
0 ignored issues
show
Unused Code introduced by
The assignment to $myts is dead and can be removed.
Loading history...
22
23
    $block             = [];
24
    $block['event_id'] = $options[0];
25
    $selected_id       = $block['event_id'];
26
27
    $sql    = "SELECT * FROM " . $GLOBALS['xoopsDB']->prefix("countdown_events") . " WHERE event_id=$selected_id";
28
    $result = $GLOBALS['xoopsDB']->query($sql);
29
30
    while ($row = $GLOBALS['xoopsDB']->fetchArray($result)) {
31
        $block['id']           = $row['event_id'];
32
        $block['uid']          = $row['event_uid'];
33
        $block['submitter']    = \XoopsUser::getUnameFromId($row['event_uid']);
34
        $block['name']         = $row['event_name'];
35
        $block['description']  = $row['event_description'];
36
        $block['categoryid']   = $row['event_categoryid'];
37
        $categoryid            = $row['event_categoryid'];
38
        $categoryHandler       = $helper->getHandler('category');
39
        $categoryObj           = $categoryHandler->get($categoryid);
40
        $block['categoryname'] = $categoryObj->getVar('category_title');
41
        $categoryname          = $categoryObj->getVar('category_title');
42
        $block['logo']         = $row['event_logo'];
43
        $block['date']         = date(_DATESTRING, strtotime($row['event_date']));
44
        $block['dateiso']      = $row['event_date'];
45
        $block['usertime']     = formatTimeStamp(time(), 'mysql');
46
        $block['date_created'] = formatTimestamp($row['date_created']);
47
        $date_created          = formatTimestamp($row['date_created']);
48
        $block['date_updated'] = formatTimestamp($row['date_updated']);
49
        $date_updated          = formatTimestamp($row['date_updated']);
50
51
        if ($date_created == $date_updated) {
52
            $block['info'] = sprintf(_MB_COUNTDOWN_POSTEDBY, \XoopsUser::getUnameFromId($row['event_uid']), formatTimestamp($row['date_created'], 'M d Y'), $categoryname);
0 ignored issues
show
Bug introduced by
It seems like $categoryname can also be of type array and array; however, parameter $values of sprintf() does only seem to accept double|integer|string, maybe add an additional type check? ( Ignorable by Annotation )

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

52
            $block['info'] = sprintf(_MB_COUNTDOWN_POSTEDBY, \XoopsUser::getUnameFromId($row['event_uid']), formatTimestamp($row['date_created'], 'M d Y'), /** @scrutinizer ignore-type */ $categoryname);
Loading history...
53
        } else {
54
            $block['info'] = sprintf(_MB_COUNTDOWN_POSTEDBY, \XoopsUser::getUnameFromId($row['event_uid']), formatTimestamp($row['date_updated'], 'M d Y'), $categoryname);
55
        }
56
    }
57
    $block['displayinfo']      = $options[1];
58
    $block['displayeventlogo'] = $options[2];
59
    return $block;
60
}
61
62
function editCountdown($options)
63
{
64
    $form = _MB_COUNTDOWN_EVENTTODISPLAY . '&nbsp;';;
65
    $form .= "<input type='hidden' name='options[0]' value='" . $options[0] . "'>&nbsp;";
66
    $form .= "<select name='options[0]'>";
67
    $form .= "<option>" . _MB_COUNTDOWN_EVENTTODISPLAY . "</option>";
68
69
    $sql       = "SELECT c.category_title,c.category_id,e.event_id,e.event_name,event_categoryid FROM " . $GLOBALS['xoopsDB']->prefix("countdown_events") . " AS e JOIN " . $GLOBALS['xoopsDB']->prefix("countdown_categories") . " AS c WHERE category_id=event_categoryid";
70
    $result    = $GLOBALS['xoopsDB']->query($sql);
71
    $totaldata = $GLOBALS['xoopsDB']->getRowsNum($result);
72
    if ($totaldata > 0) {
73
        while ($myrow = $GLOBALS['xoopsDB']->fetchArray($result)) {
74
            $event[$myrow['category_title']][] = $myrow;
75
        }
76
        foreach ($event as $key => $values) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $event does not seem to be defined for all execution paths leading up to this point.
Loading history...
77
            $form .= '<optgroup label="' . $key . '">';
78
            foreach ($values as $value) {
79
                if ($options[0] == $value['event_id']) {
80
                    $form .= '<option value="' . $options[0] . '" selected>' . $value['event_name'] . '</option>';
81
                } else {
82
                    $form .= '<option value="' . $value['event_id'] . '">' . $value['event_name'] . '</option>';
83
                }
84
            }
85
            $form .= "</optgroup>";
86
        }
87
    } else {
88
    }
89
    $form .= "</select><br>";
90
91
    $form .= _MB_COUNTDOWN_DISPLAYEVENTDESCRIPTION . '&nbsp;';
92
    if (1 == $options[1]) {
93
        $chk = " checked";
94
    }
95
    $form .= "<input type='radio' name='options[1]' value='1'" . $chk . ' >&nbsp;' . _YES . '';
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $chk does not seem to be defined for all execution paths leading up to this point.
Loading history...
96
    $chk  = '';
97
    if (0 == $options[1]) {
98
        $chk = " checked";
99
    }
100
    $form .= "&nbsp;<input type='radio' name='options[1]' value='0'" . $chk . ' >' . _NO . '<br>';
101
102
    $form .= _MB_COUNTDOWN_DISPLAYEVENTLOGO . '&nbsp;';
103
    if (1 == $options[2]) {
104
        $chk = " checked";
105
    }
106
    $form .= "<input type='radio' name='options[2]' value='1'" . $chk . ' >&nbsp;' . _YES . '';
107
    $chk  = '';
108
    if (0 == $options[2]) {
109
        $chk = " checked";
110
    }
111
    $form .= "&nbsp;<input type='radio' name='options[2]' value='0'" . $chk . ' >' . _NO . '<br>';
112
113
    $form .= _MB_COUNTDOWN_DISPLAYINFO . '&nbsp;';
114
    if (1 == $options[3]) {
115
        $chk = " checked";
116
    }
117
    $form .= "<input type='radio' name='options[3]' value='1'" . $chk . ' >&nbsp;' . _YES . '';
118
    $chk  = '';
119
    if (0 == $options[3]) {
120
        $chk = " checked";
121
    }
122
    $form .= "&nbsp;<input type='radio' name='options[3]' value='0'" . $chk . ' >' . _NO . '<br>';
123
    return $form;
124
}
125
126
?>
0 ignored issues
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...
127