Completed
Pull Request — master (#1)
by
unknown
03:00
created

add_breeder.php ➔ check()   B

Complexity

Conditions 5
Paths 16

Size

Total Lines 21
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 25
nc 16
nop 0
dl 0
loc 21
rs 8.7624
c 0
b 0
f 0
1
<?php
2
// -------------------------------------------------------------------------
3
4
require_once dirname(dirname(__DIR__)) . '/mainfile.php';
5
6
$moduleDirName = basename(__DIR__);
7
xoops_loadLanguage('main', $moduleDirName);
8
xoops_load('XoopsRequest');
9
// Include any common code for this module.
10
require_once XOOPS_ROOT_PATH . "/modules/{$moduleDirName}/include/common.php";
11
12
//check for access
13 View Code Duplication
if (!$xoopsUser instanceof XoopsUser) {
0 ignored issues
show
Bug introduced by
The class XoopsUser does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

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...
14
    redirect_header('index.php', 3, _NOPERM . '<br />' . _MA_PEDIGREE_REGIST);
15
}
16
17
$xoopsOption['template_main'] = 'pedigree_adddog.tpl';
18
include XOOPS_ROOT_PATH . '/header.php';
19
20
//@todo - move language string to language file
21
$xoopsTpl->assign('page_title', 'Pedigree database - Add owner/breeder');
22
23
global $xoopsTpl, $xoopsUser, $xoopsDB;
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...
24
25
$f = XoopsRequest::getCmd('f', '', 'POST');
26
if ('check' === $f) {
27
    //check security token here
28
    if (!$GLOBALS['xoopsSecurity']->check()) {
29
        redirect_header($_SERVER['PHP_SELF'], 3, implode('<br>', $GLOBALS['xoopsSecurity']->getErrors()));
30
    }
31
32
    $achternaam = XoopsRequest::getString('achternaam', '', 'POST');
33
    $voornaam   = XoopsRequest::getString('voornaam', '', 'POST');
34
    $email      = XoopsRequest::getEmail('email', '', 'POST');
35
    $website    = XoopsRequest::getUrl('website', '', 'POST');
36
    $user       = XoopsRequest::getString('user', '', 'POST');
37
38
    //insert into owner
39
    //$query = 'INSERT INTO ' . $GLOBALS['xoopsDB']->prefix('pedigree_owner') . " VALUES ('','" . $voornaam . "','" . $achternaam . "','','','','','','" . $email . "','" . $website . "','" . $user . "')";
0 ignored issues
show
Unused Code Comprehensibility introduced by
36% 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
    $query = 'INSERT INTO ' . $GLOBALS['xoopsDB']->prefix('pedigree_owner') . " VALUES ('','" . $GLOBALS['xoopsDB']->escape($voornaam) . "','" . $GLOBALS['xoopsDB']->escape($achternaam) . "','','','','','','" . $GLOBALS['xoopsDB']->escape($email) . "','" . $GLOBALS['xoopsDB']->escape($website) . "','" . $GLOBALS['xoopsDB']->escape($user) . "')";
41
42
    $GLOBALS['xoopsDB']->query($query);
43
    //@todo - move language string to language file
44
    redirect_header('index.php', 1, 'The data has been stored.');
45
}
46
47
//check for access
48
$xoopsModule = XoopsModule::getByDirname('pedigree');
49
50
//create form
51
include XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
52
$form = new XoopsThemeForm(_MA_PEDIGREE_ADD_OWNER, 'breedername', 'add_breeder.php?f=check', 'POST');
53
$form->addElement(new XoopsFormHiddenToken($name = 'XOOPS_TOKEN_REQUEST', $timeout = 360));
54
$form->addElement(new XoopsFormHidden('user', $xoopsUser->getVar('uid')));
55
//lastname
56
$form->addElement(new XoopsFormText('<b>' . _MA_PEDIGREE_FLD_OWN_LNAME . '</b>', 'achternaam', $size = 50, $maxsize = 255, $value = ''));
57
58
//firstname
59
$form->addElement(new XoopsFormText('<b>' . _MA_PEDIGREE_FLD_OWN_FNAME . '</b>', 'voornaam', $size = 50, $maxsize = 255, $value = ''));
60
61
//email
62
$form->addElement(new XoopsFormText('<b>' . _MA_PEDIGREE_FLD_OWN_EMAIL . '</b>', 'email', $size = 50, $maxsize = 255, $value = ''));
63
64
//website
65
$form->addElement(new XoopsFormText('<b>' . _MA_PEDIGREE_FLD_OWN_WEB . '</b>', 'website', $size = 50, $maxsize = 255, $value = ''));
66
$form->addElement(new XoopsFormLabel(_MA_PEDIGREE_EXPLAIN, _MA_PEDIGREE_FLD_OWN_WEB_EX));
67
68
//submit button
69
$form->addElement(new XoopsFormButton('', 'button_id', _MA_PEDIGREE_ADD_OWNER, 'submit'));
70
71
//add data (form) to smarty template
72
$xoopsTpl->assign('form', $form->render());
73
74
//footer
75
include XOOPS_ROOT_PATH . '/footer.php';
76