Completed
Push — master ( b35b0f...acc097 )
by Greg
05:21
created

admin/domain-fields/index.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
 * /admin/domain-fields/index.php
4
 *
5
 * This file is part of DomainMOD, an open source domain and internet asset manager.
6
 * Copyright (c) 2010-2017 Greg Chetcuti <[email protected]>
7
 *
8
 * Project: http://domainmod.org   Author: http://chetcuti.com
9
 *
10
 * DomainMOD is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
11
 * License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later
12
 * version.
13
 *
14
 * DomainMOD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
15
 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU General Public License along with DomainMOD. If not, see
18
 * http://www.gnu.org/licenses/.
19
 *
20
 */
21
?>
22
<?php //@formatter:off
23
require_once('../../_includes/start-session.inc.php');
24
require_once('../../_includes/init.inc.php');
25
26
require_once(DIR_ROOT . '/classes/Autoloader.php');
27
spl_autoload_register('DomainMOD\Autoloader::classAutoloader');
28
29
$system = new DomainMOD\System();
30
$error = new DomainMOD\Error();
31
$layout = new DomainMOD\Layout();
32
$time = new DomainMOD\Time();
33
34
require_once(DIR_INC . '/head.inc.php');
35
require_once(DIR_INC . '/config.inc.php');
36
require_once(DIR_INC . '/software.inc.php');
37
require_once(DIR_INC . '/debug.inc.php');
38
require_once(DIR_INC . '/settings/admin-custom-domain-fields.inc.php');
39
require_once(DIR_INC . '/database.inc.php');
40
41
$system->authCheck();
42
$system->checkAdminUser($_SESSION['s_is_admin']);
43
44
$export_data = $_GET['export_data'];
45
46
$sql = "SELECT f.id, f.name, f.field_name, f.description, f.notes, f.creation_type_id, f.created_by, f.insert_time, f.update_time, t.name AS type
47
        FROM domain_fields AS f, custom_field_types AS t
48
        WHERE f.type_id = t.id
49
        ORDER BY f.name";
50
51 View Code Duplication
if ($export_data == '1') {
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...
52
53
    $result = mysqli_query($dbcon, $sql) or $error->outputSqlError($dbcon, '1', 'ERROR');
54
55
    $export = new DomainMOD\Export();
56
    $export_file = $export->openFile('custom_domain_field_list', strtotime($time->stamp()));
57
58
    $row_contents = array($page_title);
59
    $export->writeRow($export_file, $row_contents);
60
61
    $export->writeBlankRow($export_file);
62
63
    $row_contents = array(
64
        'Display Name',
65
        'DB Field',
66
        'Data Type',
67
        'Description',
68
        'Notes',
69
        'Creation Type',
70
        'Created By',
71
        'Inserted',
72
        'Updated'
73
    );
74
    $export->writeRow($export_file, $row_contents);
75
76
    if (mysqli_num_rows($result) > 0) {
77
78
        while ($row = mysqli_fetch_object($result)) {
79
80
            $creation_type = $system->getCreationType($row->creation_type_id);
81
82
            if ($row->created_by == '0') {
83
                $created_by = 'Unknown';
84
            } else {
85
                $user = new DomainMOD\User();
86
                $created_by = $user->getFullName($row->created_by);
87
            }
88
89
            $row_contents = array(
90
                $row->name,
91
                $row->field_name,
92
                $row->type,
93
                $row->description,
94
                $row->notes,
95
                $creation_type,
96
                $created_by,
97
                $time->toUserTimezone($row->insert_time),
98
                $time->toUserTimezone($row->update_time)
99
            );
100
101
            $export->writeRow($export_file, $row_contents);
102
103
        }
104
105
    }
106
107
    $export->closeFile($export_file);
108
109
}
110
?>
111
<?php require_once(DIR_INC . '/doctype.inc.php'); ?>
112
<html>
113
<head>
114
    <title><?php echo $system->pageTitle($page_title); ?></title>
115
    <?php require_once(DIR_INC . '/layout/head-tags.inc.php'); ?>
116
</head>
117
<body class="hold-transition skin-red sidebar-mini">
118
<?php require_once(DIR_INC . '/layout/header.inc.php'); ?>
119
Below is a list of all the Custom Domain Fields that have been added to <?php echo SOFTWARE_TITLE; ?>.<BR>
120
<BR>
121
Custom Domain Fields help extend the functionality of <?php echo SOFTWARE_TITLE; ?> by allowing the user to create
122
their own data fields. For example, if you wanted to keep track of which domains are currenty setup in Google Analytics,
123
you could create a new Google Analytics check box field and start tracking this information for each of your domains.
124
Combine custom fields with the ability to update them with the Bulk Updater, and the sky's the limit in regards to what
125
data you can easily track!<BR>
126
<BR>
127
And when you export your domain data, the information contained in your custom fields will automatically be included in
128
the exported data.<BR>
129
<BR><?php
130
131
$result = mysqli_query($dbcon, $sql) or $error->outputSqlError($dbcon, '1', 'ERROR');
132
133 View Code Duplication
if (mysqli_num_rows($result) > 0) { ?>
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...
134
135
    <a href="add.php"><?php echo $layout->showButton('button', 'Add Custom Field'); ?></a>
136
    <a href="index.php?export_data=1"><?php echo $layout->showButton('button', 'Export'); ?></a><BR><BR>
137
138
    <table id="<?php echo $slug; ?>" class="<?php echo $datatable_class; ?>">
139
        <thead>
140
        <tr>
141
            <th width="20px"></th>
142
            <th>Name</th>
143
            <th>DB Field</th>
144
            <th>Data Type</th>
145
            <th>Inserted</th>
146
            <th>Updated</th>
147
        </tr>
148
        </thead>
149
        <tbody><?php
150
151
        while ($row = mysqli_fetch_object($result)) { ?>
152
153
            <tr>
154
            <td></td>
155
            <td>
156
                <a href="edit.php?cdfid=<?php echo $row->id; ?>"><?php echo $row->name; ?></a>
157
            </td>
158
            <td>
159
                <a href="edit.php?cdfid=<?php echo $row->id; ?>"><?php echo $row->field_name; ?></a>
160
            </td>
161
            <td>
162
                <a href="edit.php?cdfid=<?php echo $row->id; ?>"><?php echo $row->type; ?></a>
163
            </td>
164
            <td>
165
                <a href="edit.php?cdfid=<?php echo $row->id; ?>"><?php echo $time->toUserTimezone($row->insert_time); ?></a>
166
            </td>
167
            <td><?php
168
169
                if ($row->update_time != '0000-00-00 00:00:00') {
170
171
                    $temp_update_time = $time->toUserTimezone($row->update_time);
172
173
                } else {
174
175
                    $temp_update_time = '-';
176
177
                } ?>
178
                <a href="edit.php?cdfid=<?php echo $row->id; ?>"><?php echo $temp_update_time; ?></a>
179
            </td>
180
            </tr><?php
181
182
        } ?>
183
184
        </tbody>
185
    </table><?php
186
187
} else { ?>
188
189
    It appears as though you haven't created any Custom Domain Fields yet. <a href="add.php">Click here</a> to add one.<?php
190
191
} ?>
192
<?php require_once(DIR_INC . '/layout/footer.inc.php'); //@formatter:on ?>
193
</body>
194
</html>
195