offer.php ➔ editoffer()   B
last analyzed

Complexity

Conditions 4
Paths 8

Size

Total Lines 39
Code Lines 29

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 29
nc 8
nop 3
dl 0
loc 39
rs 8.5806
c 0
b 0
f 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 12 and the first side effect is on line 52.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
/**
3
 *
4
 * Module: SmartCourse
5
 * Author: The SmartFactory <www.smartfactory.ca>
6
 * Licence: GNU
7
 * @param bool   $showmenu
8
 * @param int    $offerid
9
 * @param string $fct
10
 */
11
12
function editoffer($showmenu = false, $offerid = 0, $fct = '')
13
{
14
    global $smartPartnerOfferHandler, $smartPartnerCategoryHandler, $smartPartnerPartnerHandler;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
15
16
    $offerObj = $smartPartnerOfferHandler->get($offerid);
17
18
    if ($offerObj->isNew()) {
19
        $breadcrumb            = _AM_SPARTNER_OFFERS . ' > ' . _AM_SPARTNER_CREATINGNEW;
0 ignored issues
show
Unused Code introduced by
$breadcrumb 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...
20
        $title                 = _AM_SPARTNER_OFFER_CREATE;
21
        $info                  = _AM_SPARTNER_OFFER_CREATE_INFO;
22
        $collaps_name          = 'offercreate';
23
        $form_name             = _AM_SPARTNER_OFFER_CREATE;
24
        $submit_button_caption = null;
25
        $offerObj->setVar('date_sub', time());
26
    } else {
27
        $breadcrumb            = _AM_SPARTNER_OFFERS . ' > ' . _AM_SPARTNER_EDITING;
0 ignored issues
show
Unused Code introduced by
$breadcrumb 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...
28
        $title                 = _AM_SPARTNER_OFFER_EDIT;
29
        $info                  = _AM_SPARTNER_OFFER_EDIT_INFO;
30
        $collaps_name          = 'offeredit';
31
        $form_name             = _AM_SPARTNER_OFFER_EDIT;
32
        $submit_button_caption = null;
33
    }
34
    $partnerObj = $smartPartnerPartnerHandler->get($offerObj->getVar('partnerid', 'e'));
0 ignored issues
show
Unused Code introduced by
$partnerObj 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...
35
    $offerObj->hideFieldFromForm('date_sub');
36
    $menuTab = 3;
0 ignored issues
show
Unused Code introduced by
$menuTab 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...
37
38
    if ($showmenu) {
0 ignored issues
show
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...
39
        //smart_adminMenu($menuTab, $breadcrumb);
0 ignored issues
show
Unused Code Comprehensibility introduced by
75% 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...
40
    }
41
    echo "<br>\n";
42
    smart_collapsableBar($collaps_name, $title, $info);
43
44
    $sform = $offerObj->getForm($form_name, 'addoffer', false, $submit_button_caption);
45
    if ($fct === 'app') {
46
        $sform->addElement(new XoopsFormHidden('fct', 'app'));
47
    }
48
    $sform->display();
49
    smart_close_collapsable($collaps_name);
50
}
51
52
include_once __DIR__ . '/admin_header.php';
53
54
$op = '';
55
if (isset($_GET['op'])) {
56
    $op = $_GET['op'];
57
}
58
if (isset($_POST['op'])) {
59
    $op = $_POST['op'];
60
}
61
62
switch ($op) {
63
    case 'mod':
64
        $offerid = isset($_GET['offerid']) ? (int)$_GET['offerid'] : 0;
65
        $fct     = isset($_GET['fct']) ? $_GET['fct'] : '';
66
        smart_xoops_cp_header();
67
68
        editoffer(true, $offerid, $fct);
69
        break;
70
71
    case 'addoffer':
72
        include_once XOOPS_ROOT_PATH . '/modules/smartobject/class/smartobjectcontroller.php';
73
74
        $controller = new SmartObjectController($smartPartnerOfferHandler);
75
        $offerObj   = $controller->storeSmartObject();
76
        $fct        = isset($_POST['fct']) ? $_POST['fct'] : '';
77
78
        if ($offerObj->hasError()) {
79
            redirect_header($smart_previous_page, 3, _CO_SOBJECT_SAVE_ERROR . $offerObj->getHtmlErrors());
80
        } else {
81
            $partnerObj = $smartPartnerPartnerHandler->get($offerObj->getVar('partnerid', 'e'));
82
            $partnerObj->setUpdated();
83
            if ($_POST['offerid'] == '') {
84
                $offerObj->sendNotifications(array(_SPARTNER_NOT_OFFER_NEW));
85
            }
86
87
            redirect_header(smart_get_page_before_form(), 3, _CO_SOBJECT_SAVE_SUCCESS);
88
        }
89
        exit;
90
        break;
91
92
    case 'del':
93
        include_once XOOPS_ROOT_PATH . '/modules/smartobject/class/smartobjectcontroller.php';
94
        $controller = new SmartObjectController($smartPartnerOfferHandler);
95
        $controller->handleObjectDeletion();
96
        break;
97
98
    case 'default':
99
    default:
100
        include_once(XOOPS_ROOT_PATH . '/modules/smartobject/include/functions.php');
101
        smart_xoops_cp_header();
102
103
        //add navigation icon
104
        $indexAdmin = new ModuleAdmin();
105
        echo $indexAdmin->addNavigation(basename(__FILE__));
106
107
        //add button for creating a new offer
108
        $indexAdmin->addItemButton(_AM_SPARTNER_OFFER_CREATE, 'offer.php?op=mod', 'add', '');
109
        echo $indexAdmin->renderButton('left', '');
110
111
        //smart_adminMenu(3, _AM_SPARTNER_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...
112
113
        //        echo "<br>\n";
114
        //        echo "<form><div style=\"margin-bottom: 12px;\">";
0 ignored issues
show
Unused Code Comprehensibility introduced by
43% 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...
115
        //        echo "<input type='button' name='button' onclick=\"location='offer.php?op=mod'\" value='" . _AM_SPARTNER_OFFER_CREATE . "'>&nbsp;&nbsp;";
116
        //        echo "</div></form>";
117
118
        smart_collapsableBar('createdoffers', _AM_SPARTNER_OFFERS, _AM_SPARTNER_OFFERS_DSC);
119
120
        include_once XOOPS_ROOT_PATH . '/modules/smartobject/class/smartobjecttable.php';
121
        $objectTable = new SmartObjectTable($smartPartnerOfferHandler);
122
        $objectTable->addFilter('partnerid', 'getPartnerList');
123
        $objectTable->addFilter('status', 'getStatusList');
124
        $objectTable->addColumn(new SmartObjectColumn('title', 'left'));
125
        $objectTable->addColumn(new SmartObjectColumn('partnerid', 'center', 100));
126
        $objectTable->addColumn(new SmartObjectColumn('status', 'center', 100));
127
        $objectTable->render();
128
129
        echo '<br>';
130
        smart_close_collapsable('createdoffers');
131
        echo '<br>';
132
133
        break;
134
}
135
136
//smart_modFooter();
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% 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...
137
//xoops_cp_footer();
138
include_once __DIR__ . '/admin_footer.php';
139