Completed
Push — master ( 0424ea...923121 )
by Michael
03:57
created

admin/upgrade.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/*
3
-------------------------------------------------------------------------
4
                     ADSLIGHT 2 : Module for Xoops
5
6
        Redesigned and ameliorate By Luc Bizet user at www.frxoops.org
7
        Started with the Classifieds module and made MANY changes
8
        Website : http://www.luc-bizet.fr
9
        Contact : [email protected]
10
-------------------------------------------------------------------------
11
             Original credits below Version History
12
##########################################################################
13
#                    Classified Module for Xoops                         #
14
#  By John Mordo user jlm69 at www.xoops.org and www.jlmzone.com         #
15
#      Started with the MyAds module and made MANY changes               #
16
##########################################################################
17
 Original Author: Pascal Le Boustouller
18
 Author Website : [email protected]
19
 Licence Type   : GPL
20
-------------------------------------------------------------------------
21
*/
22
23
$moduleDirName = basename(dirname(__DIR__));
24
$admin_lang    = '_AM_' . strtoupper($moduleDirName);
25
26
include_once dirname(dirname(dirname(__DIR__))) . '/include/cp_header.php';
27
xoops_cp_header();
28
include_once XOOPS_ROOT_PATH . '/modules/adslight/include/functions.php';
29
30
if (is_object($xoopsUser) && $xoopsUser->isAdmin($xoopsModule->mid())) {
31
    $errors = 0;
32
33 View Code Duplication
    if (!jlm_ads_TableExists($xoopsDB->prefix('adslight_pictures'))) {
1 ignored issue
show
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...
34
        $sql = 'CREATE TABLE ' . $xoopsDB->prefix('adslight_pictures') . " (
35
              cod_img int(11) NOT NULL auto_increment,
36
              title varchar(255) NOT NULL default '',
37
              date_added int(10)NOT NULL default '0',
38
              date_modified int(10) NOT NULL default '0',
39
              lid int(11) NOT NULL default '0',
40
              uid_owner varchar(50) NOT NULL default '',
41
              url varchar(50) NOT NULL default '',
42
              PRIMARY KEY  (cod_img),
43
              KEY storyid (storyid)
44
            ) TYPE=MyISAM;";
45
        if (!$xoopsDB->queryF($sql)) {
46
            echo '<br>' . constant($admin_lang . '_UPGRADEFAILED') . ' ' . constant($admin_lang . '_UPGRADEFAILED1');
47
            ++$errors;
48
        }
49
    }
50
51
    // 3) Create the adslight_replies table if it does NOT exist
52 View Code Duplication
    if (!jlm_ads_TableExists($xoopsDB->prefix('adslight_replies'))) {
1 ignored issue
show
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...
53
        $sql3 = 'CREATE TABLE ' . $xoopsDB->prefix('adslight_replies') . " (
54
      r_lid int(11) NOT NULL auto_increment,
55
      lid int(5) unsigned NOT NULL default '0',
56
      title varchar(50) NOT NULL default '',
57
      date int(10) NOT NULL default '0',
58
      submitter varchar(60) NOT NULL default '',
59
      message text NOT NULL default '',
60
      tele varchar(20) NOT NULL default '0',
61
      email varchar(100) NOT NULL default '',
62
      r_usid int(11) NOT NULL default '0',
63
      PRIMARY KEY  (r_lid)
64
    ) TYPE=MyISAM;";
65
66
        if (!$xoopsDB->queryF($sql3)) {
67
            echo '<br>' . constant($admin_lang . '_UPGRADEFAILED') . ' ' . constant($admin_lang . '_UPGRADEFAILED1');
68
            ++$errors;
69
        }
70
    }
71
72
    //  Add the new fields to the categories table
73
    if (!jlm_ads_FieldExists('cat_desc', $xoopsDB->prefix('adslight_categories'))) {
74
        jlm_ads_AddField("cat_desc text DEFAULT '' AFTER title", $xoopsDB->prefix('adslight_categories'));
75
    }
76
77
    //  Add the new fields to the categories table
78
    if (!jlm_ads_FieldExists('cat_keywords', $xoopsDB->prefix('adslight_categories'))) {
79
        jlm_ads_AddField("cat_keywords text DEFAULT '' AFTER title", $xoopsDB->prefix('adslight_categories'));
80
    }
81
82
    //  Add the new fields to the categories table
83
    if (!jlm_ads_FieldExists('cat_moderate', $xoopsDB->prefix('adslight_categories'))) {
84
        jlm_ads_AddField("cat_moderate int(5) DEFAULT '0' AFTER affprice", $xoopsDB->prefix('adslight_categories'));
85
    }
86
87
    //  Add the new fields to the categories table
88
    if (!jlm_ads_FieldExists('moderate_subcat', $xoopsDB->prefix('adslight_categories'))) {
89
        jlm_ads_AddField("moderate_subcat int(5) DEFAULT '0' AFTER cat_moderate", $xoopsDB->prefix('adslight_categories'));
90
    }
91
92
    //  Add the new fields to the listing table
93
    if (!jlm_ads_FieldExists('status', $xoopsDB->prefix('adslight_listing'))) {
94
        jlm_ads_AddField("status INT(3) DEFAULT '0' NOT NULL AFTER title", $xoopsDB->prefix('adslight_listing'));
95
    }
96
    //  Add the new fields to the listing table
97
    if (!jlm_ads_FieldExists('remind', $xoopsDB->prefix('adslight_listing'))) {
98
        jlm_ads_AddField("remind INT(11) DEFAULT '0' NOT NULL AFTER comments", $xoopsDB->prefix('adslight_listing'));
99
    }
100
101
    // At the end, if there was errors, show them or redirect user to the module's upgrade page
102
    if ($errors) {
103
        echo '<H1>' . constant($admin_lang . '_UPGRADEFAILED') . '</H1>';
104
        echo '<br>' . constant($admin_lang . '_UPGRADEFAILED0');
105
    } else {
106
        echo '' .
107
             constant($admin_lang . '_UPDATECOMPLETE') .
108
             " - <a href='" .
109
             XOOPS_URL .
110
             "/modules/system/admin.php?fct=modulesadmin&op=update&module=$moduleDirName'>" .
111
             constant($admin_lang . '_UPDATEMODULE') .
112
             '</a>';
113
    }
114
} else {
115
    printf("<h2>%s</h2>\n", constant($admin_lang . '_UPGR_ACCESS_ERROR'));
116
}
117
xoops_cp_footer();
118