Passed
Push — master ( 2ecc51...c1b656 )
by Michael
04:26 queued 02:02
created

listoffers()   C

Complexity

Conditions 8
Paths 16

Size

Total Lines 115
Code Lines 91

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 8
eloc 91
nc 16
nop 0
dl 0
loc 115
rs 5.2676
c 0
b 0
f 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/*
3
 * You may not change or alter any portion of this comment or credits
4
 * of supporting developers from this source code or any supporting source code
5
 * which is considered copyrighted (c) material of the original comment or credit authors.
6
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
 */
11
12
/**
13
 * @copyright    {@link https://xoops.org/ XOOPS Project}
14
 * @license      {@link http://www.gnu.org/licenses/gpl-2.0.html GNU GPL 2 or later}
15
 * @package      efqdirectory
16
 * @since
17
 * @author       Martijn Hertog (aka wtravel)
18
 * @author       XOOPS Development Team,
19
 */
20
21
require_once __DIR__ . '/admin_header.php';
22
//include __DIR__ . '/../../../include/cp_header.php';
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
23
24
include __DIR__ . '/../include/functions.php';
25
require_once XOOPS_ROOT_PATH . '/class/xoopstree.php';
0 ignored issues
show
Bug introduced by
The constant XOOPS_ROOT_PATH was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
26
require_once XOOPS_ROOT_PATH . '/class/xoopslists.php';
27
require_once XOOPS_ROOT_PATH . '/include/xoopscodes.php';
28
require_once XOOPS_ROOT_PATH . '/class/module.errorhandler.php';
29
require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
30
require_once __DIR__ . '/../class/class.subscription.php';
31
$myts                = MyTextSanitizer::getInstance();
0 ignored issues
show
Bug introduced by
The type MyTextSanitizer was not found. Maybe you did not declare it correctly or list all dependencies?

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

filter:
    dependency_paths: ["lib/*"]

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

Loading history...
32
$eh                  = new ErrorHandler;
0 ignored issues
show
Bug introduced by
The type ErrorHandler was not found. Maybe you did not declare it correctly or list all dependencies?

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

filter:
    dependency_paths: ["lib/*"]

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

Loading history...
33
$itemtypes           = new XoopsTree($xoopsDB->prefix($xoopsModule->getVar('dirname', 'n') . '_itemtypes'), 'typeid', '');
0 ignored issues
show
Bug introduced by
The type XoopsTree was not found. Maybe you did not declare it correctly or list all dependencies?

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

filter:
    dependency_paths: ["lib/*"]

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

Loading history...
34
$subscription        = new efqSubscription();
35
$subscriptionhandler = new efqSubscriptionHandler();
36
37
$moddir = $xoopsModule->getVar('dirname');
38
if (isset($_GET['typeid'])) {
39
    $get_typeid = (int)$_GET['typeid'];
40
} else {
41
    $get_typeid = '0';
42
    if (isset($_POST['typeid'])) {
43
        $post_typeid = (int)$_POST['typeid'];
44
    }
45
}
46
if (isset($_GET['offerid'])) {
47
    $get_offerid = (int)$_GET['offerid'];
48
} else {
49
    $get_offerid = 0;
50
}
51
52
$eh = new ErrorHandler; //ErrorHandler object
53
54 View Code Duplication
if (isset($_GET['op'])) {
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...
55
    $op = $_GET['op'];
56
} elseif (isset($_POST['op'])) {
57
    $op = $_POST['op'];
58
} else {
59
    $op = '';
60
}
61
62
//function to list subscription types
63
function listoffers()
64
{
65
    global $xoopsDB, $eh, $xoopsUser, $subscription, $subscriptionhandler, $itemtypes, $myts, $xoopsModule;
66
    xoops_cp_header();
0 ignored issues
show
Bug introduced by
The function xoops_cp_header was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

66
    /** @scrutinizer ignore-call */ xoops_cp_header();
Loading history...
67
    $adminObject = \Xmf\Module\Admin::getInstance();
0 ignored issues
show
Bug introduced by
The type Xmf\Module\Admin was not found. Maybe you did not declare it correctly or list all dependencies?

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

filter:
    dependency_paths: ["lib/*"]

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

Loading history...
68
    $adminObject->displayNavigation(basename(__FILE__));
69
    //adminmenu(4, _MD_MANAGE_SUBSCRIPTION_OFFERS);
0 ignored issues
show
Unused Code Comprehensibility introduced by
63% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
70
    echo '<br>';
71
72
    //list subscription offers
73
    $sql     = 'SELECT o.offerid, o.typeid, o.title, o.duration, o.count, o.price, o.activeyn, o.currency, o.descr, t.typename, t.typelevel FROM '
74
               . $xoopsDB->prefix($xoopsModule->getVar('dirname', 'n') . '_itemtypes')
75
               . ' t, '
76
               . $xoopsDB->prefix($xoopsModule->getVar('dirname', 'n') . '_subscr_offers')
77
               . ' o WHERE o.typeid=t.typeid';
78
    $result  = $xoopsDB->query($sql) or $eh->show('0013');
79
    $numrows = $xoopsDB->getRowsNum($result);
80
    if ($numrows > 0) {
81
        echo '<h4>' . _MD_SUBSCR_OFFERS . '</h4>';
82
        echo "<table width='100%' border='0' cellspacing='1' class='outer'>";
83
        echo '<tr><th>' . _MD_OFFER_TITLE . '</th><th>' . _MD_OFFER_DURATION . '</th><th>' . _MD_OFFER_COUNT . '</th><th>' . _MD_OFFER_PRICE . '</th><th>' . _MD_OFFER_CURRENCY . '</th><th>' . _MD_OFFER_ACTIVE . '</th></tr>';
84
        $duration_arr = $subscription->durationArray();
85
        while (list($offerid, $typeid, $title, $duration, $count, $price, $activeyn, $currency, $descr, $typename, $level) = $xoopsDB->fetchRow($result)) {
86
            $offertitle = $myts->htmlSpecialChars($title);
87
            if ($activeyn == '1') {
88
                $activeyn = _MD_YES;
89
            } else {
90
                $activeyn = _MD_NO;
91
            }
92
            //Show offers
93
            echo '<tr>';
94
            echo "<td class=\"even\"><a href=\"subscriptions.php?op=editoffer&amp;offerid=$offerid\">$offertitle</a></td>";
95
            echo "<td class=\"odd\">$duration_arr[$duration]</td>";
96
            echo "<td class=\"even\">$count</td>";
97
            echo "<td class=\"odd\">$price</td>";
98
            echo "<td class=\"even\">$currency</td>";
99
            echo "<td class=\"odd\">$activeyn</td>";
100
            echo '</tr>';
101
        }
102
        echo '</table>';
103
    } else {
104
        echo '' . _MD_NORESULTS . '<br><br>';
105
    }
106
    echo '<h4>' . _MD_ADD_SUBSCR_OFFER . '</h4>';
107
108
    echo "<table width='100%' border='0' cellspacing='1' class='outer'><tr><td>";
109
    $form = new XoopsThemeForm(_MD_ADD_OFFER_FORM, 'newofferform', 'subscriptions.php');
0 ignored issues
show
Bug introduced by
The type XoopsThemeForm was not found. Maybe you did not declare it correctly or list all dependencies?

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

filter:
    dependency_paths: ["lib/*"]

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

Loading history...
110
    $form->addElement(new XoopsFormText(_MD_OFFER_TITLE, 'title', 50, 100, ''), true);
0 ignored issues
show
Bug introduced by
The type XoopsFormText was not found. Maybe you did not declare it correctly or list all dependencies?

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

filter:
    dependency_paths: ["lib/*"]

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

Loading history...
111
112
    $itemtypes_arr   = $subscriptionhandler->itemTypesArray();
113
    $itemtype_select = new XoopsFormSelect(_MD_SUBSCR_ITEMTYPE, 'typeid');
0 ignored issues
show
Bug introduced by
The type XoopsFormSelect was not found. Maybe you did not declare it correctly or list all dependencies?

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

filter:
    dependency_paths: ["lib/*"]

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

Loading history...
114
    $itemtype_select->addOptionArray($itemtypes_arr);
115
    $form->addElement($itemtype_select);
116
117
    $duration_arr    = $subscription->durationArray();
118
    $duration_select = new XoopsFormSelect(_MD_OFFER_DURATION, 'duration');
119
    $duration_select->addOptionArray($duration_arr);
120
    $form->addElement($duration_select);
121
122
    $form->addElement(new XoopsFormText(_MD_OFFER_COUNT, 'count', 10, 50, ''), true);
123
    $form->addElement(new XoopsFormText(_MD_OFFER_PRICE, 'price', 20, 50, ''), true);
124
125
    $currency_arr    = $subscription->currencyArray();
126
    $currency_select = new XoopsFormSelect(_MD_OFFER_CURRENCY, 'currency');
127
    $currency_select->addOptionArray($currency_arr);
128
    $form->addElement($currency_select);
129
130
    $form_active = new XoopsFormCheckBox(_MD_OFFER_ACTIVEYN, 'activeyn', 0);
0 ignored issues
show
Bug introduced by
The type XoopsFormCheckBox was not found. Maybe you did not declare it correctly or list all dependencies?

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

filter:
    dependency_paths: ["lib/*"]

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

Loading history...
131
    $form_active->addOption(1, _MD_YESNO);
132
    $form->addElement($form_active, true);
133
    $form->addElement(new XoopsFormDhtmlTextArea(_MD_OFFER_DESCR, 'descr', '', 5, 50, ''));
0 ignored issues
show
Bug introduced by
The type XoopsFormDhtmlTextArea was not found. Maybe you did not declare it correctly or list all dependencies?

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

filter:
    dependency_paths: ["lib/*"]

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

Loading history...
134
    $form->addElement(new XoopsFormButton('', 'submit', _MD_SUBMIT, 'submit'));
0 ignored issues
show
Bug introduced by
The type XoopsFormButton was not found. Maybe you did not declare it correctly or list all dependencies?

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

filter:
    dependency_paths: ["lib/*"]

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

Loading history...
135
    $form->addElement(new XoopsFormHidden('op', 'addoffer'));
0 ignored issues
show
Bug introduced by
The type XoopsFormHidden was not found. Maybe you did not declare it correctly or list all dependencies?

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

filter:
    dependency_paths: ["lib/*"]

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

Loading history...
136
    $form->addElement(new XoopsFormHidden('uid', $xoopsUser->getVar('uid')));
137
    $form->display();
138
    echo '</td></tr></table>';
139
140
    //Show item types
141
    $sql     = 'SELECT typeid, typename, typelevel FROM ' . $xoopsDB->prefix($xoopsModule->getVar('dirname', 'n') . '_itemtypes') . '';
142
    $result  = $xoopsDB->query($sql) or $eh->show('0013');
143
    $numrows = $xoopsDB->getRowsNum($result);
144
    if ($numrows > 0) {
145
        echo '<h4>' . _MD_ITEMTYPES . '</h4>';
146
        echo "<table width='100%' border='0' cellspacing='1' class='outer'>";
147
        echo '<tr><th>' . _MD_ITEMTYPE_NAME . '</th><th>' . _MD_ITEMTYPE_LEVEL . '</th><th>' . _MD_ACTION . '</th></tr>';
148
        $duration_arr = $subscription->durationArray();
0 ignored issues
show
Unused Code introduced by
The assignment to $duration_arr is dead and can be removed.
Loading history...
149
        while (list($typeid, $typename, $level) = $xoopsDB->fetchRow($result)) {
150
            $typename = $myts->htmlSpecialChars($typename);
151
            $level    = $myts->htmlSpecialChars($level);
152
153
            //Show types
154
            echo '<tr>';
155
            echo "<td class=\"even\"><a href=\"subscriptions.php?op=edittype&typeid=$typeid\">$typename</strong></td>";
156
            echo "<td class=\"odd\">$level</td>";
157
            echo "<td class=\"odd\"><a href=\"subscriptions.php?op=deltype&typeid=$typeid\">" . _MD_DELETE . '</strong></td>';
158
            echo '</tr>';
159
        }
160
        echo '</table>';
161
    } else {
162
        echo '' . _MD_NORESULTS . '<br><br>';
163
    }
164
    echo '<h4>' . _MD_ADD_ITEMTYPE . '</h4>';
165
166
    //Add item type form
167
    echo "<table width='100%' border='0' cellspacing='1' class='outer'><tr><td>";
168
    $form = new XoopsThemeForm(_MD_ADD_ITEMTYPE_FORM, 'newitemtypeform', 'subscriptions.php');
169
    $form->addElement(new XoopsFormText(_MD_ITEMTYPE_NAME, 'typename', 50, 100, ''), true);
170
    $form->addElement(new XoopsFormText(_MD_ITEMTYPE_LEVEL, 'typelevel', 10, 50, ''), true);
171
172
    $form->addElement(new XoopsFormButton('', 'submit', _MD_SUBMIT, 'submit'));
173
    $form->addElement(new XoopsFormHidden('op', 'addtype'));
174
    $form->addElement(new XoopsFormHidden('uid', $xoopsUser->getVar('uid')));
175
    $form->display();
176
    echo '</td></tr></table>';
177
    xoops_cp_footer();
0 ignored issues
show
Bug introduced by
The function xoops_cp_footer was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

177
    /** @scrutinizer ignore-call */ xoops_cp_footer();
Loading history...
178
}
179
180
function edittype()
181
{
182
    global $xoopsDB, $eh, $myts, $get_typeid, $xoopsUser;
183
    if ($get_typeid == 0) {
184
        redirect_header(XOOPS_URL . "/modules/$moddir/admin/subscriptions.php", 2, _MD_INVALID_TYPEID);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $moddir seems to be never defined.
Loading history...
Bug introduced by
The function redirect_header was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

184
        /** @scrutinizer ignore-call */ redirect_header(XOOPS_URL . "/modules/$moddir/admin/subscriptions.php", 2, _MD_INVALID_TYPEID);
Loading history...
Bug introduced by
The constant XOOPS_URL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
185
        exit();
186
    }
187
    xoops_cp_header();
0 ignored issues
show
Bug introduced by
The function xoops_cp_header was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

187
    /** @scrutinizer ignore-call */ xoops_cp_header();
Loading history...
188
    $adminObject = \Xmf\Module\Admin::getInstance();
189
    $adminObject->displayNavigation(basename(__FILE__));
190
    //adminmenu(4, _MD_MANAGE_SUBSCRIPTION_OFFERS);
0 ignored issues
show
Unused Code Comprehensibility introduced by
63% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
191
    echo '<br>';
192
    $sql     = 'SELECT typeid, typename, typelevel FROM ' . $xoopsDB->prefix($xoopsModule->getVar('dirname', 'n') . '_itemtypes') . " WHERE typeid=$get_typeid";
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $xoopsModule seems to be never defined.
Loading history...
193
    $result  = $xoopsDB->query($sql) or $eh->show('0013');
194
    $numrows = $xoopsDB->getRowsNum($result);
195
    if ($numrows > 0) {
196
        //$duration_arr = $subscription->durationArray();
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
197
        while (list($typeid, $typename, $level) = $xoopsDB->fetchRow($result)) {
198
            echo "<table width='100%' border='0' cellspacing='1' class='outer'><tr><td>";
199
            $form = new XoopsThemeForm(_MD_EDIT_ITEMTYPE_FORM, 'edititemtypeform', 'subscriptions.php');
200
            $form->addElement(new XoopsFormText(_MD_ITEMTYPE_NAME, 'typename', 50, 100, $typename), true);
201
            $form->addElement(new XoopsFormText(_MD_ITEMTYPE_LEVEL, 'typelevel', 10, 50, $level), true);
202
            $form->addElement(new XoopsFormButton('', 'submit', _MD_SUBMIT, 'submit'));
203
            $form->addElement(new XoopsFormHidden('op', 'savetype'));
204
            $form->addElement(new XoopsFormHidden('typeid', "$get_typeid"));
205
            $form->addElement(new XoopsFormHidden('uid', $xoopsUser->getVar('uid')));
206
            $form->display();
207
            echo '</td></tr></table>';
208
        }
209
    } else {
210
        redirect_header(XOOPS_URL . "/modules/$moddir/admin/subscriptions.php", 2, _MD_INVALID_TYPEID);
211
        exit();
212
    }
213
    xoops_cp_footer();
0 ignored issues
show
Bug introduced by
The function xoops_cp_footer was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

213
    /** @scrutinizer ignore-call */ xoops_cp_footer();
Loading history...
214
}
215
216
function editoffer()
217
{
218
    global $xoopsDB, $eh, $xoopsUser, $subscription, $subscriptionhandler, $get_offerid, $itemtypes;
219
    if ($get_offerid == 0) {
220
        redirect_header(XOOPS_URL . "/modules/$moddir/admin/subscriptions.php", 2, _MD_INVALID_OFFERID);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $moddir seems to be never defined.
Loading history...
Bug introduced by
The function redirect_header was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

220
        /** @scrutinizer ignore-call */ redirect_header(XOOPS_URL . "/modules/$moddir/admin/subscriptions.php", 2, _MD_INVALID_OFFERID);
Loading history...
Bug introduced by
The constant XOOPS_URL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
221
        exit();
222
    }
223
    xoops_cp_header();
0 ignored issues
show
Bug introduced by
The function xoops_cp_header was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

223
    /** @scrutinizer ignore-call */ xoops_cp_header();
Loading history...
224
    $adminObject = \Xmf\Module\Admin::getInstance();
225
    $adminObject->displayNavigation(basename(__FILE__));
226
    //adminmenu(4, _MD_MANAGE_SUBSCRIPTION_OFFERS);
0 ignored issues
show
Unused Code Comprehensibility introduced by
63% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
227
    echo '<br>';
228
    $sql     = 'SELECT o.offerid, o.title, o.typeid, o.duration, o.count, o.price, o.activeyn, o.currency, o.descr, t.typename, t.typelevel FROM '
229
               . $xoopsDB->prefix($xoopsModule->getVar('dirname', 'n') . '_itemtypes')
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $xoopsModule seems to be never defined.
Loading history...
230
               . ' t, '
231
               . $xoopsDB->prefix($xoopsModule->getVar('dirname', 'n') . '_subscr_offers')
232
               . ' o WHERE o.typeid=t.typeid AND o.offerid='
233
               . $get_offerid
234
               . '';
235
    $result  = $xoopsDB->query($sql) or $eh->show('0013');
236
    $numrows = $xoopsDB->getRowsNum($result);
237
    if ($numrows > 0) {
238
        $duration_arr = $subscription->durationArray();
239
        while (list($offerid, $offertitle, $typeid, $duration, $count, $price, $activeyn, $currency, $descr, $typename, $level) = $xoopsDB->fetchRow($result)) {
240
            echo "<table width='100%' border='0' cellspacing='1' class='outer'><tr><td>";
241
            $form = new XoopsThemeForm(_MD_ADD_OFFER_FORM, 'newofferform', 'subscriptions.php');
242
            $form->addElement(new XoopsFormText(_MD_OFFER_TITLE, 'title', 50, 100, $offertitle), true);
243
244
            $itemtypes_arr   = $subscriptionhandler->itemTypesArray();
245
            $itemtype_select = new XoopsFormSelect(_MD_SUBSCR_ITEMTYPE, 'typeid', $typeid);
246
            $itemtype_select->addOptionArray($itemtypes_arr);
247
            $form->addElement($itemtype_select);
248
249
            //$duration_arr = $subscription->durationArray();
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
250
            $duration_select = new XoopsFormSelect(_MD_OFFER_DURATION, 'duration', $duration);
251
            $duration_select->addOptionArray($duration_arr);
252
            $form->addElement($duration_select);
253
254
            $form->addElement(new XoopsFormText(_MD_OFFER_COUNT, 'count', 10, 50, $count), true);
255
            $form->addElement(new XoopsFormText(_MD_OFFER_PRICE, 'price', 20, 50, $price), true);
256
257
            $currency_arr    = $subscription->currencyArray();
258
            $currency_select = new XoopsFormSelect(_MD_OFFER_CURRENCY, 'currency', $currency);
259
            $currency_select->addOptionArray($currency_arr);
260
            $form->addElement($currency_select);
261
262
            $form_active = new XoopsFormCheckBox(_MD_OFFER_ACTIVEYN, 'activeyn', $activeyn);
263
            $form_active->addOption(1, _MD_YESNO);
264
            $form->addElement($form_active, true);
265
            $form->addElement(new XoopsFormDhtmlTextArea(_MD_OFFER_DESCR, 'descr', $descr, 5, 50, ''));
266
            $form->addElement(new XoopsFormButton('', 'submit', _MD_SUBMIT, 'submit'));
267
            $form->addElement(new XoopsFormHidden('op', 'saveoffer'));
268
            $form->addElement(new XoopsFormHidden('offerid', "$get_offerid"));
269
            $form->addElement(new XoopsFormHidden('uid', $xoopsUser->getVar('uid')));
270
            $form->display();
271
            echo '</td></tr></table>';
272
        }
273
    } else {
274
        redirect_header(XOOPS_URL . "/modules/$moddir/admin/subscriptions.php", 2, _MD_INVALID_OFFERID);
275
        exit();
276
    }
277
    xoops_cp_footer();
0 ignored issues
show
Bug introduced by
The function xoops_cp_footer was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

277
    /** @scrutinizer ignore-call */ xoops_cp_footer();
Loading history...
278
}
279
280
//function to view one subscription type
281
function viewtype()
282
{
283
    global $xoopsDB, $eh, $get_typeid;
284
    if (isset($get_itemid)) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $get_itemid seems to never exist and therefore isset should always be false.
Loading history...
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
285
        //view type
286
    }
287
}
288
289
function addoffer()
290
{
291
    global $xoopsDB, $eh, $myts, $moddir;
292
    //Get POST variables;
293
    $post_title    = $myts->makeTboxData4Save($_POST['title']);
294
    $post_typeid   = (int)$_POST['typeid'];
295
    $post_duration = $myts->makeTboxData4Save($_POST['duration']);
296
    $post_currency = $myts->makeTboxData4Save($_POST['currency']);
297
    $post_count    = (int)$_POST['count'];
298
    $post_price    = $myts->makeTboxData4Save($_POST['price']);
299
    if (isset($activeyn)) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $activeyn does not exist. Did you maybe mean $post_activeyn?
Loading history...
300
        $post_activeyn = (int)$_POST['activeyn'];
301
    } else {
302
        $post_activeyn = 0;
303
    }
304 View Code Duplication
    if (isset($_POST['descr'])) {
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...
305
        $post_descr = $myts->makeTboxData4Save($_POST['descr']);
306
    } else {
307
        $post_descr = '';
308
    }
309
310
    $gen_offerid = $xoopsDB->genId($xoopsDB->prefix($xoopsModule->getVar('dirname', 'n') . '_subscr_offers') . '_offerid_seq');
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $xoopsModule seems to be never defined.
Loading history...
311
    $sql         = sprintf("INSERT INTO %s (offerid, title, typeid, duration, COUNT, price, activeyn, currency, descr) VALUES (%u, '%s', %u, %u, %u, '%s', %u, '%s', '%s')", $xoopsDB->prefix($xoopsModule->getVar('dirname', 'n') . '_subscr_offers'), $gen_offerid, $post_title, $post_typeid,
312
                           $post_duration, $post_count, $post_price, $post_activeyn, $post_currency, $post_descr);
313
    $xoopsDB->query($sql) or $eh->show('0013');
314
    $gen_offerid = $xoopsDB->getInsertId();
315
    redirect_header(XOOPS_URL . "/modules/$moddir/admin/subscriptions.php?offerid=" . $gen_offerid . '', 2, _MD_SAVED);
0 ignored issues
show
Bug introduced by
The constant XOOPS_URL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
Bug introduced by
The function redirect_header was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

315
    /** @scrutinizer ignore-call */ redirect_header(XOOPS_URL . "/modules/$moddir/admin/subscriptions.php?offerid=" . $gen_offerid . '', 2, _MD_SAVED);
Loading history...
316
    exit();
317
}
318
319
function saveoffer()
320
{
321
    global $xoopsDB, $eh, $myts, $moddir;
322
    //Get POST variables;
323
    $post_offerid  = (int)$_POST['offerid'];
324
    $post_title    = $myts->makeTboxData4Save($_POST['title']);
325
    $post_typeid   = (int)$_POST['typeid'];
326
    $post_duration = $myts->makeTboxData4Save($_POST['duration']);
327
    $post_currency = $myts->makeTboxData4Save($_POST['currency']);
328
    $post_count    = (int)$_POST['count'];
329
    $post_price    = $myts->makeTboxData4Save($_POST['price']);
330
    if (isset($_POST['activeyn'])) {
331
        $post_activeyn = (int)$_POST['activeyn'];
332
    } else {
333
        $post_activeyn = 0;
334
    }
335 View Code Duplication
    if (isset($_POST['descr'])) {
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...
336
        $post_descr = $myts->makeTboxData4Save($_POST['descr']);
337
    } else {
338
        $post_descr = '';
339
    }
340
341
    $gen_offerid = $xoopsDB->genId($xoopsDB->prefix($xoopsModule->getVar('dirname', 'n') . '_subscr_offers') . '_offerid_seq');
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $xoopsModule seems to be never defined.
Loading history...
Unused Code introduced by
The assignment to $gen_offerid is dead and can be removed.
Loading history...
342
    $sql         = 'UPDATE '
343
                   . $xoopsDB->prefix($xoopsModule->getVar('dirname', 'n') . '_subscr_offers')
344
                   . " SET title = '$post_title', typeid = '$post_typeid', duration = '$post_duration', count = '$post_count', price = '$post_price', activeyn = '$post_activeyn', currency = '$post_currency', descr = '$post_descr' WHERE offerid='$post_offerid'";
345
    $xoopsDB->query($sql) or $eh->show('0013');
346
    $gen_offerid = $xoopsDB->getInsertId();
347
    redirect_header(XOOPS_URL . "/modules/$moddir/admin/subscriptions.php?offerid=" . $post_offerid . '', 2, _MD_SAVED);
0 ignored issues
show
Bug introduced by
The function redirect_header was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

347
    /** @scrutinizer ignore-call */ redirect_header(XOOPS_URL . "/modules/$moddir/admin/subscriptions.php?offerid=" . $post_offerid . '', 2, _MD_SAVED);
Loading history...
Bug introduced by
The constant XOOPS_URL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
348
    exit();
349
}
350
351
function addtype()
352
    //function to save a new item type
353
{
354
    global $xoopsDB, $eh, $myts, $_POST, $moddir;
355
    $p_typename = $myts->makeTboxData4Save($_POST['typename']);
356
    $p_level    = $myts->makeTboxData4Save($_POST['typelevel']);
357
    $newid      = $xoopsDB->genId($xoopsDB->prefix($xoopsModule->getVar('dirname', 'n') . '_itemtypes') . '_typeid_seq');
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $xoopsModule seems to be never defined.
Loading history...
358
    $sql        = sprintf("INSERT INTO %s (typeid, typename, typelevel) VALUES (%u, '%s', '%s')", $xoopsDB->prefix($xoopsModule->getVar('dirname', 'n') . '_itemtypes'), $newid, $p_typename, $p_level);
359
    $xoopsDB->query($sql) or $eh->show('0013');
360
    redirect_header(XOOPS_URL . "/modules/$moddir/admin/subscriptions.php", 2, _MD_SAVED);
0 ignored issues
show
Bug introduced by
The function redirect_header was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

360
    /** @scrutinizer ignore-call */ redirect_header(XOOPS_URL . "/modules/$moddir/admin/subscriptions.php", 2, _MD_SAVED);
Loading history...
Bug introduced by
The constant XOOPS_URL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
361
    exit();
362
}
363
364
function deltype()
365
    //function to delete an item type
366
{
367
    global $xoopsDB, $eh, $moddir, $subscriptionhandler;
368 View Code Duplication
    if (isset($_GET['typeid'])) {
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...
369
        $g_typeid = (int)$_GET['typeid'];
370
    } else {
371
        redirect_header(XOOPS_URL . "/modules/$moddir/admin/subscriptions.php", 2, _MD_ERR_ITEMTYPE_DELETE);
0 ignored issues
show
Bug introduced by
The constant _MD_ERR_ITEMTYPE_DELETE was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
Bug introduced by
The constant XOOPS_URL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
Bug introduced by
The function redirect_header was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

371
        /** @scrutinizer ignore-call */ redirect_header(XOOPS_URL . "/modules/$moddir/admin/subscriptions.php", 2, _MD_ERR_ITEMTYPE_DELETE);
Loading history...
372
        exit();
373
    }
374
375
    if ($subscriptionhandler->countSubscriptionsForType($g_typeid) > 0) {
376
        redirect_header(XOOPS_URL . "/modules/$moddir/admin/subscriptions.php", 3, _MD_ERR_ITEMTYPE_LINKED_TO_LISTINGS);
0 ignored issues
show
Bug introduced by
The constant _MD_ERR_ITEMTYPE_LINKED_TO_LISTINGS was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
377
        exit();
378
    }
379
    $sql = sprintf('DELETE FROM %s WHERE typeid=%u', $xoopsDB->prefix($xoopsModule->getVar('dirname', 'n') . '_itemtypes'), $g_typeid);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $xoopsModule seems to be never defined.
Loading history...
380
    $xoopsDB->queryF($sql) or $eh->show('0013');
381
    redirect_header(XOOPS_URL . "/modules/$moddir/admin/subscriptions.php", 1, _MD_ITEMTYPE_DELETED);
0 ignored issues
show
Bug introduced by
The constant _MD_ITEMTYPE_DELETED was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
382
    exit();
383
}
384
385
//function to save an existing subscription type
386
function savetype()
387
{
388
    global $xoopsDB, $eh, $post_typeid, $myts, $moddir;
389
    $p_typename = $myts->makeTboxData4Save($_POST['typename']);
390
    $p_level    = (int)$_POST['typelevel'];
391
    $newid      = $xoopsDB->genId($xoopsDB->prefix($xoopsModule->getVar('dirname', 'n') . '_itemtypes') . '_typeid_seq');
0 ignored issues
show
Unused Code introduced by
The assignment to $newid is dead and can be removed.
Loading history...
Comprehensibility Best Practice introduced by
The variable $xoopsModule seems to be never defined.
Loading history...
392
    $sql        = 'UPDATE ' . $xoopsDB->prefix($xoopsModule->getVar('dirname', 'n') . '_itemtypes') . " SET typename='$p_typename', typelevel='$p_level' WHERE typeid='$post_typeid'";
393
    $xoopsDB->query($sql) or $eh->show('0013');
394
    redirect_header(XOOPS_URL . "/modules/$moddir/admin/subscriptions.php", 2, _MD_SAVED);
0 ignored issues
show
Bug introduced by
The function redirect_header was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

394
    /** @scrutinizer ignore-call */ redirect_header(XOOPS_URL . "/modules/$moddir/admin/subscriptions.php", 2, _MD_SAVED);
Loading history...
Bug introduced by
The constant XOOPS_URL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
395
    exit();
396
}
397
398
//function to delete an existing subscription type
0 ignored issues
show
Unused Code Comprehensibility introduced by
39% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
399
/*function deltype()
400
{
401
global $xoopsDB, $eh, $post_typeid;
402
}*/
403
404
switch ($op) {
405
    case 'delete':
406
        deltype();
407
        break;
408
    case 'save':
409
        savetype();
410
        break;
411
    case 'addtype':
412
        addtype();
413
        break;
414
    case 'edittype':
415
        edittype();
416
        break;
417
    case 'deltype':
418
        deltype();
419
        break;
420
    case 'savetype':
421
        savetype();
422
        break;
423
    case 'viewtype':
424
        viewtype();
425
        break;
426
    case 'addoffer':
427
        addoffer();
428
        break;
429
    case 'editoffer':
430
        editoffer();
431
        break;
432
    case 'saveoffer':
433
        saveoffer();
434
        break;
435
    default:
436
        listoffers();
437
        break;
438
}
439