Completed
Push — master ( c39b68...a1acf8 )
by Michael
03:03
created

import.php ➔ Import_wfdownloads()   C

Complexity

Conditions 11
Paths 152

Size

Total Lines 66
Code Lines 47

Duplication

Lines 13
Ratio 19.7 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 11
eloc 47
c 3
b 0
f 0
nc 152
nop 2
dl 13
loc 66
rs 5.5371

How to fix   Long Method    Complexity   

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
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 31 and the first side effect is on line 17.

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
 * TDMDownload
4
 *
5
 * You may not change or alter any portion of this comment or credits
6
 * of supporting developers from this source code or any supporting source code
7
 * which is considered copyrighted (c) material of the original comment or credit authors.
8
 * This program is distributed in the hope that it will be useful,
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
 *
12
 * @copyright   Gregory Mage (Aka Mage)
13
 * @license     GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
14
 * @author      Gregory Mage (Aka Mage)
15
 */
16
17
include 'admin_header.php';
18
xoops_cp_header();
19
if (TDMDownloads_checkModuleAdmin()) {
20
    $import_admin = new ModuleAdmin();
21
    echo $import_admin->addNavigation('import.php');
22
}
23
//Action dans switch
24
if (isset($_REQUEST['op'])) {
25
    $op = $_REQUEST['op'];
26
} else {
27
    $op = 'index';
28
}
29
30
// import depuis mydownloads
31
function Import_mydownloads($path='', $imgurl='')
0 ignored issues
show
Coding Style introduced by
Import_mydownloads uses the super-global variable $_POST which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
32
{
33
    $ok =  isset($_POST['ok']) ? intval($_POST['ok']) : 0;
34
    global $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...
35
    if ($ok == 1) {
36
        //Vider les tables
37
        $query = $xoopsDB->queryF("truncate table ".$xoopsDB->prefix("tdmdownloads_broken"));
0 ignored issues
show
Unused Code introduced by
$query 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...
38
        $query = $xoopsDB->queryF("truncate table ".$xoopsDB->prefix("tdmdownloads_cat"));
0 ignored issues
show
Unused Code introduced by
$query 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...
39
        $query = $xoopsDB->queryF("truncate table ".$xoopsDB->prefix("tdmdownloads_downloads"));
0 ignored issues
show
Unused Code introduced by
$query 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...
40
        $query = $xoopsDB->queryF("truncate table ".$xoopsDB->prefix("tdmdownloads_fielddata"));
0 ignored issues
show
Unused Code introduced by
$query 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...
41
        $query = $xoopsDB->queryF("truncate table ".$xoopsDB->prefix("tdmdownloads_modfielddata"));
0 ignored issues
show
Unused Code introduced by
$query 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...
42
        $query = $xoopsDB->queryF("truncate table ".$xoopsDB->prefix("tdmdownloads_votedata"));
0 ignored issues
show
Unused Code introduced by
$query 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...
43
        //Inserer les donn�es des cat�gories
44
        $query_topic = $xoopsDB->query("SELECT cid, pid, title, imgurl FROM ".$xoopsDB->prefix("mydownloads_cat"));
45
        while ($donnees = $xoopsDB->fetchArray($query_topic)) {
46
            if ($donnees['imgurl'] == "") {
47
                $img = "blank.gif";
48
            } else {
49
                $img = substr_replace($donnees['imgurl'],'',0,strlen($imgurl));
50
                @copy($path . $img, XOOPS_ROOT_PATH . "/uploads/TDMDownloads/images/cats/" . $img);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
51
            }
52
53
            $title = $donnees['title'];
54
            $insert = $xoopsDB->queryF("INSERT INTO ".$xoopsDB->prefix("tdmdownloads_cat")." (cat_cid, cat_pid, cat_title, cat_imgurl, cat_description_main, cat_weight ) VALUES ('".$donnees['cid']."', '".$donnees['pid']."', '".$title."', '".$img."', '', '0')");
55 View Code Duplication
            if (!$insert) {
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...
56
                echo "<font color='red'>" . _AM_TDMDOWNLOADS_IMPORT_ERROR_DATA .": </font> " . $donnees['title'] . "<br>";
57
            }
58
            echo sprintf(_AM_TDMDOWNLOADS_IMPORT_CAT_IMP . '<br/>', $donnees['title']);
59
        }
60
        echo '<br/>';
61
62
        //Inserer les donnees des t�l�chargemnts
63
        $query_links = $xoopsDB->query("SELECT lid, cid, title, url, homepage, version, size, platform, logourl, submitter, status, date, hits, rating, votes, comments FROM ".$xoopsDB->prefix("mydownloads_downloads"));
64
        while ($donnees = $xoopsDB->fetchArray($query_links)) {
65
            //On recupere la description
66
            $requete = $xoopsDB->queryF("SELECT description FROM ".$xoopsDB->prefix("mydownloads_text")." WHERE lid = '".$donnees['lid']."'");
67
            list ($description) = $xoopsDB -> fetchRow($requete);
68
            $insert = $xoopsDB->queryF("INSERT INTO ".$xoopsDB->prefix("tdmdownloads_downloads")." (
69
            lid, cid, title, url, homepage, version, size, platform, description, logourl, submitter, status, date, hits, rating, votes, comments, top) VALUES
70
            ('".$donnees['lid']."', '".$donnees['cid']."', '".$donnees['title']."', '".$donnees['url']."', '".$donnees['homepage']."', '".$donnees['version']."', '".$donnees['size']."', '".$donnees['platform']."', '".$description."',  '".$donnees['logourl']."', '".$donnees['submitter']."', '".$donnees['status']."', '".$donnees['date']."', '".$donnees['hits']."', '".$donnees['rating']."', '".$donnees['votes']."', '0', '0' )");
71 View Code Duplication
            if (!$insert) {
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...
72
                echo "<font color='red'>" . _AM_TDMDOWNLOADS_IMPORT_ERROR_DATA .": </font> " . $donnees['title'] . "<br>";
73
            }
74
            echo sprintf(_AM_TDMDOWNLOADS_IMPORT_DOWNLOADS_IMP . '<br/>', $donnees['title']);
75
            @copy($path . $donnees['logourl'], XOOPS_ROOT_PATH . "/uploads/TDMDownloads/images/shots/" . $donnees['logourl']);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
76
        }
77
        echo '<br/>';
78
        //Inserer les donnees des votes
79
        $query_vote = $xoopsDB->query("SELECT ratingid, lid, ratinguser, rating, ratinghostname, ratingtimestamp FROM ".$xoopsDB->prefix("mydownloads_votedata"));
80 View Code Duplication
        while ($donnees = $xoopsDB->fetchArray($query_vote)) {
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...
81
            $insert = $xoopsDB->queryF("INSERT INTO ".$xoopsDB->prefix("tdmdownloads_votedata")." (ratingid, lid, ratinguser, rating, ratinghostname, ratingtimestamp ) VALUES ('".$donnees['ratingid']."', '".$donnees['lid']."', '".$donnees['ratinguser']."', '".$donnees['rating']."', '".$donnees['ratinghostname']."', '". $donnees['ratingtimestamp']."')");
82
            if (!$insert) {
83
                echo "<font color='red'>" . _AM_TDMDOWNLOADS_IMPORT_ERROR_DATA .": </font> " . $donnees['ratingid'] . "<br>";
84
            }
85
            echo sprintf(_AM_TDMDOWNLOADS_IMPORT_VOTE_IMP . '<br/>', $donnees['ratingid']);
86
        }
87
        echo "<br><br>";
88
        echo "<div class='errorMsg'>";
89
        echo _AM_TDMDOWNLOADS_IMPORT_OK;
90
        echo "</div>";
91
    } else {
92
        xoops_confirm(array('op' => 'import_mydownloads', 'ok' => 1, 'path' => $path, 'imgurl' => $imgurl), 'import.php', _AM_TDMDOWNLOADS_IMPORT_CONF_MYDOWNLOADS . '<br>');
93
    }
94
}
95
96
// import depuis WF-Downloads
97
function Import_wfdownloads($shots='', $catimg='')
0 ignored issues
show
Coding Style introduced by
Import_wfdownloads uses the super-global variable $_POST which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
98
{
99
    $ok =  isset($_POST['ok']) ? intval($_POST['ok']) : 0;
100
    global $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...
101
    if ($ok == 1) {
102
        //Vider les tables
103
        $query = $xoopsDB->queryF("truncate table ".$xoopsDB->prefix("tdmdownloads_broken"));
0 ignored issues
show
Unused Code introduced by
$query 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...
104
        $query = $xoopsDB->queryF("truncate table ".$xoopsDB->prefix("tdmdownloads_cat"));
0 ignored issues
show
Unused Code introduced by
$query 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...
105
        $query = $xoopsDB->queryF("truncate table ".$xoopsDB->prefix("tdmdownloads_downloads"));
0 ignored issues
show
Unused Code introduced by
$query 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...
106
        $query = $xoopsDB->queryF("truncate table ".$xoopsDB->prefix("tdmdownloads_fielddata"));
0 ignored issues
show
Unused Code introduced by
$query 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...
107
        $query = $xoopsDB->queryF("truncate table ".$xoopsDB->prefix("tdmdownloads_modfielddata"));
0 ignored issues
show
Unused Code introduced by
$query 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...
108
        $query = $xoopsDB->queryF("truncate table ".$xoopsDB->prefix("tdmdownloads_votedata"));
0 ignored issues
show
Unused Code introduced by
$query 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...
109
        //Inserer les donn�es des cat�gories
110
        $query_topic = $xoopsDB->query("SELECT cid, pid, title, imgurl, description, total, summary, spotlighttop, spotlighthis, dohtml, dosmiley, doxcode, doimage, dobr, weight, formulize_fid FROM ".$xoopsDB->prefix("wfdownloads_cat"));
111
        while ($donnees = $xoopsDB->fetchArray($query_topic)) {
112
            if ($donnees['imgurl'] == "") {
113
                $img = "blank.gif";
114
            } else {
115
                $img = $donnees['imgurl'];
116
                @copy($catimg . $img, XOOPS_ROOT_PATH . "/uploads/TDMDownloads/images/cats/" . $img);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
117
            }
118
            $insert = $xoopsDB->queryF("INSERT INTO ".$xoopsDB->prefix("tdmdownloads_cat")." (cat_cid, cat_pid, cat_title, cat_imgurl, cat_description_main, cat_weight ) VALUES ('".$donnees['cid']."', '".$donnees['pid']."', '".$donnees['title']."', '".$img."', '".addcslashes($donnees['description'],"'")."', '".$donnees['weight']."')");
119 View Code Duplication
            if (!$insert) {
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...
120
                echo "<font color='red'>" . _AM_TDMDOWNLOADS_IMPORT_ERROR_DATA .": </font> " . $donnees['title'] . "<br>";
121
            }
122
            echo sprintf(_AM_TDMDOWNLOADS_IMPORT_CAT_IMP . '<br/>', $donnees['title']);
123
        }
124
        echo '<br/>';
125
126
        //Inserer les donnees des t�l�chargemnts
127
        $query_links = $xoopsDB->query("SELECT lid, cid, title, url, filename, filetype, homepage, version, size, platform, screenshot, screenshot2, screenshot3, screenshot4, submitter, publisher, status, date, hits, rating, votes, comments, license, mirror, price, paypalemail, features, requirements, homepagetitle, forumid, limitations, versiontypes, dhistory, published, expired, updated, offline, summary, description, ipaddress, notifypub, formulize_idreq  FROM ".$xoopsDB->prefix("wfdownloads_downloads"));
128
        while ($donnees = $xoopsDB->fetchArray($query_links)) {
129
            if ($donnees['url']=='') {
130
                $newurl = XOOPS_URL . '/uploads/' . $donnees['filename'];
131
            } else {
132
                $newurl = $donnees['url'];
133
            }
134
            $insert = $xoopsDB->queryF("INSERT INTO ".$xoopsDB->prefix("tdmdownloads_downloads")." (
135
            lid, cid, title, url, homepage, version, size, platform, description, logourl, submitter, status, date, hits, rating, votes, comments, top) VALUES
136
            ('".$donnees['lid']."', '".$donnees['cid']."', '".$donnees['title']."', '".$newurl."', '".$donnees['homepage']."', '".$donnees['version']."', '".$donnees['size']."', '".$donnees['platform']."', '".addcslashes($donnees['description'],"'")."',  '".$donnees['screenshot']."', '".$donnees['submitter']."', '".$donnees['status']."', '".$donnees['date']."', '".$donnees['hits']."', '".$donnees['rating']."', '".$donnees['votes']."', '0', '0' )");
137
138 View Code Duplication
            if (!$insert) {
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...
139
                echo "<font color='red'>" . _AM_TDMDOWNLOADS_IMPORT_ERROR_DATA .": </font> " . $donnees['title'] . "<br>";
140
            }
141
            echo sprintf(_AM_TDMDOWNLOADS_IMPORT_DOWNLOADS_IMP . '<br/>', $donnees['title']);
142
            @copy($shots . $donnees['screenshot'], XOOPS_ROOT_PATH . "/uploads/TDMDownloads/images/shots/" . $donnees['screenshot']);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
143
        }
144
        echo '<br/>';
145
146
        //Inserer les donnees des votes
147
        $query_vote = $xoopsDB->query("SELECT ratingid, lid, ratinguser, rating, ratinghostname, ratingtimestamp FROM ".$xoopsDB->prefix("wfdownloads_votedata"));
148 View Code Duplication
        while ($donnees = $xoopsDB->fetchArray($query_vote)) {
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...
149
            $insert = $xoopsDB->queryF("INSERT INTO ".$xoopsDB->prefix("tdmdownloads_votedata")." (ratingid, lid, ratinguser, rating, ratinghostname, ratingtimestamp ) VALUES ('".$donnees['ratingid']."', '".$donnees['lid']."', '".$donnees['ratinguser']."', '".$donnees['rating']."', '".$donnees['ratinghostname']."', '". $donnees['ratingtimestamp']."')");
150
            if (!$insert) {
151
                echo "<font color='red'>" . _AM_TDMDOWNLOADS_IMPORT_ERROR_DATA .": </font> " . $donnees['ratingid'] . "<br>";
152
            }
153
            echo sprintf(_AM_TDMDOWNLOADS_IMPORT_VOTE_IMP . '<br/>', $donnees['ratingid']);
154
        }
155
        echo "<br><br>";
156
        echo "<div class='errorMsg'>";
157
        echo _AM_TDMDOWNLOADS_IMPORT_OK;
158
        echo "</div>";
159
    } else {
160
        xoops_confirm(array('op' => 'import_wfdownloads', 'ok' => 1, 'shots' => $shots, 'catimg' => $catimg), 'import.php', _AM_TDMDOWNLOADS_IMPORT_CONF_WFDOWNLOADS . '<br>');
161
    }
162
}
163
164
switch ($op) {
165
    case "index":
166
        default:
167
        echo "<br><br>";
168
        echo "<div class='errorMsg'>";
169
        echo _AM_TDMDOWNLOADS_IMPORT_WARNING;
170
        echo "</div>";
171
        echo "<br><br>";
172
        if (TDMDownloads_checkModuleAdmin()) {
173
            $a_admin = new ModuleAdmin();
174
            $a_admin->addItemButton(_AM_TDMDOWNLOADS_IMPORT_MYDOWNLOADS, 'import.php?op=form_mydownloads', 'add');
175
            $a_admin->addItemButton(_AM_TDMDOWNLOADS_IMPORT_WFDOWNLOADS, 'import.php?op=form_wfdownloads', 'add');
176
            echo $a_admin->renderButton("center");
177
        }
178
    break;
179
180
    // import Mydownloads
181
    case "import_mydownloads":
182
        if ($_REQUEST['path'] == '' || $_REQUEST['imgurl'] == '') {
183
            redirect_header('import.php?op=form_mydownloads', 3, _AM_TDMDOWNLOADS_IMPORT_ERREUR);
184
        } else {
185
            Import_mydownloads($_REQUEST['path'],$_REQUEST['imgurl']);
186
        }
187
    break;
188
189 View Code Duplication
    case "form_mydownloads":
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...
190
        echo "<br><br>";
191
        echo "<fieldset><legend style='font-weight: bold; color: #900;'>" . _AM_TDMDOWNLOADS_IMPORT_NUMBER . "</legend>";
192
        global $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...
193
        $query = $xoopsDB->query("SELECT COUNT(lid) as count FROM ".$xoopsDB->prefix("mydownloads_downloads"));
194
        list( $count_downloads ) = $xoopsDB->fetchRow( $query ) ;
195
        if ($count_downloads < 1) {
196
            echo _AM_TDMDOWNLOADS_IMPORT_DONT_DOWNLOADS . "<br />";
197
        } else {
198
            echo sprintf(_AM_TDMDOWNLOADS_IMPORT_NB_DOWNLOADS, $count_downloads);
199
        }
200
        $query = $xoopsDB->query("SELECT COUNT(cid) as count FROM ".$xoopsDB->prefix("mydownloads_cat"));
201
        list( $count_topic ) = $xoopsDB->fetchRow( $query ) ;
202
        if ($count_topic < 1) {
203
            echo ""._AM_TDMDOWNLOADS_IMPORT_DONT_TOPIC."<br>";
204
        } else {
205
            echo sprintf('<br/>' . _AM_TDMDOWNLOADS_IMPORT_NB_CAT, $count_topic);
206
        }
207
        echo "</fieldset>";
208
        echo "<br><br>";
209
        echo "<table width='100%' border='0'>
210
                <form action='import.php?op=import_mydownloads' method=POST>
211
                <tr>
212
                    <td  class='even'>" . _AM_TDMDOWNLOADS_IMPORT_MYDOWNLOADS_PATH . "</td>
213
                    <td  class='odd'><input type='text' name='path' id='import_data' size='100' value='" . XOOPS_ROOT_PATH . "/modules/mydownloads/images/shots/' /></td>
214
                </tr>
215
                <tr>
216
                    <td  class='even'>" . _AM_TDMDOWNLOADS_IMPORT_MYDOWNLOADS_URL . "</td>
217
                    <td  class='odd'><input type='text' name='imgurl' id='import_data' size='100' value='" . XOOPS_URL . "/modules/mydownloads/images/shots/' /></td>
218
                </tr>
219
                <tr>
220
                    <td  class='even'>" . _AM_TDMDOWNLOADS_IMPORT_DOWNLOADS . "</td>
221
                    <td  class='odd'><input type='submit' name='button' id='import_data' value='" . _AM_TDMDOWNLOADS_IMPORT1 . "'></td>
222
                </tr>
223
                </form>
224
            </table>";
225
    break;
226
227
    // import WF-Downloads
228
    case "import_wfdownloads":
229
        if ($_REQUEST['shots'] == '' || $_REQUEST['catimg'] == '') {
230
            redirect_header('import.php?op=form_wfdownloads', 3, _AM_TDMDOWNLOADS_IMPORT_ERREUR);
231
        } else {
232
            Import_wfdownloads($_REQUEST['shots'],$_REQUEST['catimg']);
233
        }
234
    break;
235
236 View Code Duplication
    case "form_wfdownloads":
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...
237
        echo "<br><br>";
238
        echo "<fieldset><legend style='font-weight: bold; color: #900;'>" . _AM_TDMDOWNLOADS_IMPORT_NUMBER . "</legend>";
239
        global $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...
240
        $query = $xoopsDB->query("SELECT COUNT(lid) as count FROM ".$xoopsDB->prefix("wfdownloads_downloads"));
241
        list( $count_downloads ) = $xoopsDB->fetchRow( $query ) ;
242
        if ($count_downloads < 1) {
243
            echo _AM_TDMDOWNLOADS_IMPORT_DONT_DOWNLOADS . "<br />";
244
        } else {
245
            echo sprintf(_AM_TDMDOWNLOADS_IMPORT_NB_DOWNLOADS, $count_downloads);
246
        }
247
        $query = $xoopsDB->query("SELECT COUNT(cid) as count FROM ".$xoopsDB->prefix("wfdownloads_cat"));
248
        list( $count_topic ) = $xoopsDB->fetchRow( $query ) ;
249
        if ($count_topic < 1) {
250
            echo ""._AM_TDMDOWNLOADS_IMPORT_DONT_TOPIC."<br>";
251
        } else {
252
            echo sprintf('<br/>' . _AM_TDMDOWNLOADS_IMPORT_NB_CAT, $count_topic);
253
        }
254
        echo "</fieldset>";
255
        echo "<br><br>";
256
        echo "<table width='100%' border='0'>
257
                <form action='import.php?op=import_wfdownloads' method=POST>
258
                <tr>
259
                    <td  class='even'>" . _AM_TDMDOWNLOADS_IMPORT_WFDOWNLOADS_SHOTS . "</td>
260
                    <td  class='odd'><input type='text' name='shots' id='import_data' size='100' value='" . XOOPS_ROOT_PATH . "/modules/wfdownloads/images/screenshots/' /></td>
261
                </tr>
262
                <tr>
263
                    <td  class='even'>" . _AM_TDMDOWNLOADS_IMPORT_WFDOWNLOADS_CATIMG . "</td>
264
                    <td  class='odd'><input type='text' name='catimg' id='import_data' size='100' value='" . XOOPS_ROOT_PATH . "/modules/wfdownloads/images/category/' /></td>
265
                </tr>
266
                <tr>
267
                    <td  class='even'>" . _AM_TDMDOWNLOADS_IMPORT_DOWNLOADS . "</td>
268
                    <td  class='odd'><input type='submit' name='button' id='import_data' value='" . _AM_TDMDOWNLOADS_IMPORT1 . "'></td>
269
                </tr>
270
                </form>
271
            </table>";
272
    break;
273
}
274
275
xoops_cp_footer();
276