Passed
Push — master ( b847d6...d6d54c )
by Michael
09:34 queued 05:00
created

pedigree_config_post()   A

Complexity

Conditions 5
Paths 12

Size

Total Lines 31
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 23
c 0
b 0
f 0
nc 12
nop 0
dl 0
loc 31
rs 9.2408
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 52 and the first side effect is on line 36.

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
//    pedigree
4
//        Copyright 2004, James Cotton
5
//         http://www.dobermannvereniging.nl
6
//    Template
7
//        Copyright 2004 Thomas Hill
8
//        <a href="http://www.worldware.com">worldware.com</a>
9
// -------------------------------------------------------------------------
10
// ------------------------------------------------------------------------- //
11
//  This program is free software; you can redistribute it and/or modify     //
12
//  it under the terms of the GNU General Public License as published by     //
13
//  the Free Software Foundation; either version 2 of the License, or        //
14
//  (at your option) any later version.                                      //
15
//                                                                           //
16
//  You may not change or alter any portion of this comment or credits       //
17
//  of supporting developers from this source code or any supporting         //
18
//  source code which is considered copyrighted (c) material of the          //
19
//  original comment or credit authors.                                      //
20
//                                                                           //
21
//  This program is distributed in the hope that it will be useful,          //
22
//  but WITHOUT ANY WARRANTY; without even the implied warranty of           //
23
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            //
24
//  GNU General Public License for more details.                             //
25
//                                                                           //
26
//  You should have received a copy of the GNU General Public License        //
27
//  along with this program; if not, write to the Free Software              //
28
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA //
29
// ------------------------------------------------------------------------- //
30
31
use Xmf\Request;
32
use XoopsModules\Pedigree;
33
34
//To be deleted?
35
36
require_once  dirname(dirname(dirname(__DIR__))) . '/include/cp_header.php';
37
//require_once(XOOPS_ROOT_PATH . "/modules/" . $xoopsModule->dirname() . "/include/pedigree_includes.php");
0 ignored issues
show
Unused Code Comprehensibility introduced by
49% 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...
38
//require_once dirname(__DIR__) . "/include/pedigree_includes.php";
39
40
xoops_loadLanguage('modinfo', basename(dirname(dirname(__DIR__))));
41
require_once $GLOBALS['xoops']->path('modules/pedigree/admin/menu.php');
42
43
// Get HTTP post/get parameters.
44
//import_request_variables("gp", "param_");
45
extract($_GET, EXTR_PREFIX_ALL, 'param');
46
extract($_POST, EXTR_PREFIX_ALL, 'param');
47
48
$op = Request::getCmd('op', 'main');
49
//
50
// Writes out the form to get all config parameters.
51
//
52
function pedigree_config_form()
53
{
54
    $config_fields = pedigree_get_config_fields();
0 ignored issues
show
Bug introduced by
The function pedigree_get_config_fields 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

54
    $config_fields = /** @scrutinizer ignore-call */ pedigree_get_config_fields();
Loading history...
55
    $values        = pedigree_get_config();
0 ignored issues
show
Bug introduced by
The function pedigree_get_config 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

55
    $values        = /** @scrutinizer ignore-call */ pedigree_get_config();
Loading history...
56
    print "
57
    <form action='config.php' method='POST' enctype='application/x-www-form-urlencoded'>\n
58
    <table border='1' cellpadding='0' cellspacing='0' width='100%'>\n
59
        <tr><th>" . _AM_PEDIGREE_CTITLE . "</th></tr>\n
60
        <tr>\n
61
        <td class='bg2'>\n
62
            <table width='100%' border='0' cellpadding='4' cellspacing='1'>\n";
63
64
    foreach ($config_fields as $field => $prompt) {
65
        if ('config_id' === $field) {
66
            continue;
67
        }
68
        $pname = 'param_' . $field;
0 ignored issues
show
Unused Code introduced by
The assignment to $pname is dead and can be removed.
Loading history...
69
        print "
70
                <tr nowrap='nowrap'>\n
71
                <td class ='head'>{$prompt}</td>\n
72
                <td class='even aligntop'>\n
73
                    <input type='text' name='{$field}' size='32' maxlength='32' value ='{$values[$field]}'>\n
74
                </td></tr>\n
75
                </tr>\n";
76
    }
77
    print "
78
                <td class='head'>&nbsp;</td>\n
79
                <td class='even'>\n
80
                    <input type='hidden' name='op' value='config'>\n
81
                    <input type='hidden' name='window' value='config'>\n
82
                    <input type='submit' value='" . _AM_PEDIGREE_BUT_GO . "'>\n
83
                </td></tr>\n
84
            </table>\n
85
        </td></tr>\n
86
    </table>\n
87
    </form>\n";
88
}
89
90
/**
91
 *
92
 * @todo: create pedigree_admin_hmenu - it doesn't exist
93
 *
94
 * Displays the main admin interface
95
 *
96
 */
97
function pedigree_config_main()
98
{
99
    //xoops_cp_header();
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...
100
    $p_title = _AM_PEDIGREE_CONFIGURE;
101
    print "<h4 style='text-align:left;'>$p_title</h4>";
102
    pedigree_admin_hmenu();
0 ignored issues
show
Bug introduced by
The function pedigree_admin_hmenu 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

102
    /** @scrutinizer ignore-call */ 
103
    pedigree_admin_hmenu();
Loading history...
103
    pedigree_config_form();
104
    xoops_cp_footer();
105
    exit();
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
106
}
107
108
/**
109
 *
110
 * @todo: create pedigree_get_config_fields() method, it doesn't exist anywhere
111
 *
112
 * Processes the configuration update request, by
113
 * getting the HTTP parameters, and putting them into the database.
114
 */
115
function pedigree_config_post()
116
{
117
    $config_fields = pedigree_get_config_fields();
0 ignored issues
show
Bug introduced by
The function pedigree_get_config_fields 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

117
    $config_fields = /** @scrutinizer ignore-call */ pedigree_get_config_fields();
Loading history...
118
    foreach ($config_fields as $field => $prompt) {
119
        $param = 'param_' . $field;
0 ignored issues
show
Unused Code introduced by
The assignment to $param is dead and can be removed.
Loading history...
120
        global $$param;
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...
121
    }
122
    $param_config_id = 1;
123
    $sql             = 'REPLACE INTO ' . $GLOBALS['xoopsDB']->prefix('pedigree_fields') . ' (' . pedigree_to_string($config_fields) . ') VALUES (';
0 ignored issues
show
Bug introduced by
The function pedigree_to_string 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

123
    $sql             = 'REPLACE INTO ' . $GLOBALS['xoopsDB']->prefix('pedigree_fields') . ' (' . /** @scrutinizer ignore-call */ pedigree_to_string($config_fields) . ') VALUES (';
Loading history...
124
125
    $first = true;
126
    foreach ($config_fields as $field => $prompt) {
127
        $param = 'param_' . $field;
128
        if (!$first) {
129
            $sql .= ', ';
130
        }
131
        // Handle a 'feature' of PHP that adds backslashes to HTTP parameters.
132
        $param_value = $$param;
133
        $sql         .= "'" . $GLOBALS['xoopsDB']->escape($param_value) . "'";
134
        $first       = false;
135
    }
136
    $sql .= ' )';
137
    if (!$GLOBALS['xoopsDB']->query($sql)) {
138
        $error = $GLOBALS['xoopsDB']->error();
139
        xoops_cp_header();
140
        pedigree_show_sql_error(_AM_PEDIGREE_ERR_ADD_FAILED, $error, $sql);
0 ignored issues
show
Bug introduced by
The function pedigree_show_sql_error 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

140
        /** @scrutinizer ignore-call */ 
141
        pedigree_show_sql_error(_AM_PEDIGREE_ERR_ADD_FAILED, $error, $sql);
Loading history...
141
        xoops_cp_footer();
142
    } else {
143
        redirect_header('config.php', 1, _AM_PEDIGREE_OK_DB);
144
    }
145
    exit();
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
146
}
147
148
switch ($op) {
149
    case 'main':
150
        pedigree_config_main();
151
        break;
152
    case 'config':
153
        pedigree_config_post();
154
        break;
155
    default:
156
        //xoops_cp_header();
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...
157
        /* @todo: move hard coded language string to language file */
158
        print "<h1>Unknown method requested ('{$op}')</h1>";
159
        xoops_cp_footer();
160
}
161