Completed
Push — master ( c8eead...62889a )
by Michael
04:13
created

admin/tools.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
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 120 and the first side effect is on line 4.

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
4
require_once dirname(dirname(dirname(__DIR__))) . '/mainfile.php';
5
/*
0 ignored issues
show
Unused Code Comprehensibility introduced by
43% 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...
6
if (file_exists(XOOPS_ROOT_PATH . "/modules/" . $xoopsModule->dirname() . "/language/" . $xoopsConfig['language'] . "/main.php")) {
7
    require_once XOOPS_ROOT_PATH . "/modules/" . $xoopsModule->dirname() . "/language/" . $xoopsConfig['language'] . "/main.php";
8
} else {
9
    include_once XOOPS_ROOT_PATH . "/modules/" . $xoopsModule->dirname() . "/language/english/main.php";
10
}
11
*/
12
xoops_loadLanguage('main', basename(dirname(dirname(__DIR__))));
13
14
// Include any common code for this module.
15
require_once dirname(__DIR__) . "/include/functions.php";
16
17
$xoopsOption['template_main'] = "pedigree_tools.tpl";
18
19
include XOOPS_ROOT_PATH . '/header.php';
20
$xoopsTpl->assign('page_title', "Pedigree database - Add owner/breeder");
21
22
//check for access
23
$xoopsModule =& XoopsModule::getByDirname("pedigree");
24
if (empty($xoopsUser)) {
25
    redirect_header("index.php", 3, _NOPERM . "<br />" . _MA_PEDIGREE_REGIST);
26
    exit();
27
}
28
29
//add JS routines
30
echo '<script language="JavaScript" src="picker.js"></script>';
31
32
//set form to be empty
33
$form = "";
34
35
//get module configuration
36
$module_handler =& xoops_gethandler('module');
37
$module         =& $module_handler->getByDirname("pedigree");
38
$config_handler =& xoops_gethandler('config');
39
$moduleConfig   =& $config_handler->getConfigsByCat(0, $module->getVar('mid'));
40
41
switch ($_GET['op']) {
42
    case "lang":
43
        lang();
44
        break;
45
    case "langsave":
46
        langsave();
47
        break;
48
    case "colours":
49
        colours();
50
        break;
51
    case "settings":
52
        settings();
53
        break;
54
    case "settingssave":
55
        settingssave();
56
        break;
57
    case "pro":
58
        pro();
59
        break;
60
    case "userfields":
61
        userfields();
62
        break;
63
    case "deleted":
64
        deleted();
65
        break;
66
    case "delperm":
67
        delperm($_GET['id']);
68
        break;
69
    case "delall":
70
        delall();
71
        break;
72
    case "restore":
73
        restore($_GET['id']);
74
        break;
75
    case "database":
76
        database();
77
        $db = true;
78
        break;
79
    case "dbanc":
80
        database_oa();
81
        $db = true;
82
        break;
83
    case "fltypar":
84
        database_fp();
85
        $db = true;
86
        break;
87
    case "credits":
88
        credits();
89
        break;
90
    default :
91
        index();
92
        break;
93
}
94
95
//create tools array
96
$tools[] = array('title' => "General settings", 'link' => "tools.php?op=settings", 'main' => "1");
97
if ($moduleConfig['proversion'] == '1') {
98
    $tools[] = array('title' => "Pro-version settings", 'link' => "tools.php?op=pro", 'main' => "1");
99
}
100
$tools[] = array('title' => "Language options", 'link' => "tools.php?op=lang", 'main' => "1");
101
$tools[] = array('title' => "Create user fields", 'link' => "tools.php?op=userfields", 'main' => "1");
102
$tools[] = array('title' => "Create colours", 'link' => "tools.php?op=colours", 'main' => "1");
103
$tools[] = array('title' => "Deleted pedigree's", 'link' => "tools.php?op=deleted", 'main' => "1");
104
$tools[] = array('title' => "Database tools", 'link' => "tools.php?op=database", 'main' => "1");
105
if (isset($db)) {
106
    //create database submenu
107
    $tools[] = array('title' => "Own ancestors", 'link' => "tools.php?op=dbanc", 'main' => "0");
108
    $tools[] = array('title' => "Incorrect gender", 'link' => "tools.php?op=fltypar", 'main' => "0");
109
    $tools[] = array('title' => "User Queries", 'link' => "tools.php?op=userq", 'main' => "0");
110
}
111
$tools[] = array('title' => "Credits", 'link' => "tools.php?op=credits", 'main' => "1");
112
$tools[] = array('title' => "Logout", 'link' => "../../user.php?op=logout", 'main' => "1");
113
//add data (form) to smarty template
114
115
$xoopsTpl->assign("tools", $tools);
116
117
//footer
118
include XOOPS_ROOT_PATH . "/footer.php";
119
120
function index()
121
{
122
    $form = "";
123
}
124
125
function colours()
126
{
127
    global $xoopsTpl;
128
    $form = "This will be the wizard to create and modify the website colourscheme.<hr>";
129
    $form .= '<FORM NAME="myForm" action=\'savecolors.php\' method=\'POST\'>';
130
    $form .= '<INPUT TYPE="text" id="ftxtcolor" name="ftxtcolor" value="#' . $femaleTextColour . '" size="11" maxlength="7">';
131
    $form .= '<a href="javascript:TCP.popup(document.forms[\'myForm\'].elements[\'ftxtcolor\'])">';
132
    $form .= '<img width="15" height="13" border="0" alt="Click Here to Pick up the color" src="img/sel.gif"></a>';
133
    $form .= '</form>';
134
    $xoopsTpl->assign("form", $form);
135
}
136
137
function userfields()
138
{
139
    global $xoopsTpl;
140
    $form = "This will be the wizard to create and modify the custom userfields.<hr>";
141
    $xoopsTpl->assign("form", $form);
142
}
143
144
function credits()
145
{
146
    global $xoopsTpl;
147
    $form
148
        = "Pedigree database module<br /><br /><li>Programming : James Cotton<br/><li>Design & Layout : Ton van der Hagen<br /><br />Technical support :<br /><li><a href=\"mailto:[email protected]\">[email protected]<br /><li><a href=\"http://www.animalpedigree.com\">www.animalpedigree.com</a><hr>";
149
    $xoopsTpl->assign("form", $form);
150
}
151
152
function database()
153
{
154
    global $xoopsTpl;
155
    $form = _MA_PEDIGREE_QUERY_EXPLAN;
156
    $xoopsTpl->assign("form", $form);
157
}
158
159 View Code Duplication
function database_oa()
160
{
161
    global $xoopsTpl, $xoopsDB;
162
    $form = _AM_PEDIGREE_DATABASE_CHECK_ANCESTORS;
163
    $sql  = "SELECT d.id AS d_id, d.naam AS d_naam
164
            FROM " . $xoopsDB->prefix("pedigree_tree") . " d
165
            LEFT JOIN " . $xoopsDB->prefix("pedigree_tree") . " m ON m.id = d.mother
166
            LEFT JOIN " . $xoopsDB->prefix("pedigree_tree") . " f ON f.id = d.father
167
            LEFT JOIN " . $xoopsDB->prefix("pedigree_tree") . " mm ON mm.id = m.mother
168
            LEFT JOIN " . $xoopsDB->prefix("pedigree_tree") . " mf ON mf.id = m.father
169
            LEFT JOIN " . $xoopsDB->prefix("pedigree_tree") . " fm ON fm.id = f.mother
170
            LEFT JOIN " . $xoopsDB->prefix("pedigree_tree") . " ff ON ff.id = f.father
171
            WHERE
172
            d.mother = d.id
173
            OR d.father = d.id
174
            OR m.mother = d.id
175
            OR m.father = d.id
176
            OR f.mother = d.id
177
            OR f.father = d.id
178
            OR mm.mother = d.id
179
            OR mm.father = d.id
180
            OR mf.mother = d.id
181
            OR mf.father = d.id
182
            OR fm.mother = d.id
183
            OR fm.father = d.id
184
            OR ff.mother = d.id
185
            OR ff.father = d.id
186
            ";
187
    $result = $xoopsDB->query($sql);
188
    while ($row = $xoopsDB->fetchArray($result)) {
189
        $form .= "<li><a href=\"pedigree.php?pedid=" . $row['d_id'] . "\">" . $row['d_naam'] . "</a> [own parent or grandparent]<br />";
190
    }
191
    $xoopsTpl->assign("form", $form);
192
}
193
194 View Code Duplication
function database_fp()
195
{
196
    global $xoopsTpl, $xoopsDB;
197
    $form = _AM_PEDIGREE_DATABASE_CHECK_GENDER;
198
    $sql  = "SELECT d.id AS d_id, d.naam AS d_naam, m.roft as m_roft
199
            FROM " . $xoopsDB->prefix("pedigree_tree") . " d
200
            LEFT JOIN " . $xoopsDB->prefix("pedigree_tree") . " m ON m.id = d.mother
201
            WHERE
202
            d.mother = m.id
203
            AND m.roft = '0' ";
204
    $result = $xoopsDB->query($sql);
205
    while ($row = $xoopsDB->fetchArray($result)) {
206
        $form .= "<li><a href=\"dog.php?id=" . $row['d_id'] . "\">" . $row['d_naam'] . "</a> [mother seems to be male]<br />";
207
    }
208
    $sql
209
            = "SELECT d.id AS d_id, d.naam AS d_naam, f.roft as f_roft
210
            FROM " . $xoopsDB->prefix("pedigree_tree") . " d
211
            LEFT JOIN " . $xoopsDB->prefix("pedigree_tree") . " f ON f.id = d.father
212
            WHERE
213
            d.father = f.id
214
            AND f.roft = '1' ";
215
    $result = $xoopsDB->query($sql);
216
    while ($row = $xoopsDB->fetchArray($result)) {
217
        $form .= "<li><a href=\"dog.php?id=" . $row['d_id'] . "\">" . $row['d_naam'] . "</a> [father seems to be female]<br />";
218
    }
219
    $xoopsTpl->assign("form", $form);
220
}
221
222
function pro()
223
{
224
    global $xoopsTpl;
225
    $form = "Pro version settings go here.<hr>";
226
    $xoopsTpl->assign("form", $form);
227
}
228
229 View Code Duplication
function deleted()
230
{
231
    global $xoopsTpl, $xoopsDB, $moduleConfig;
232
    $form
233
            = "Below the line are the animals which have been deleted from your database.<br /><br />By clicking on the name you can reinsert them into the database.<br />By clicking on the 'X' in front of the name you can permanently delete the animal.<hr>";
234
    $sql    = "SELECT ID, NAAM	FROM " . $xoopsDB->prefix("pedigree_trash");
235
    $result = $xoopsDB->query($sql);
236
    while ($row = $xoopsDB->fetchArray($result)) {
237
        $form .= "<a href=\"tools.php?op=delperm&id=" . $row['ID'] . "\"><img src=\"assets/images/delete.gif\" /></a>&nbsp;<a href=\"tools.php?op=restore&id=" . $row['ID'] . "\">" . $row['NAAM']
238
            . "</a><br />";
239
    }
240
    if ($xoopsDB->getRowsNum($result) > 0) {
241
        $form .= "<hr><a href=\"tools.php?op=delall\">Click here</a> to remove all these " . $moduleConfig['animalTypes'] . " permenantly ";
242
    }
243
    $xoopsTpl->assign("form", $form);
244
}
245
246
/**
247
 * @param $id
248
 */
249 View Code Duplication
function delperm($id)
250
{
251
    global $xoopsTpl, $xoopsDB;
252
    $sql = "DELETE FROM " . $xoopsDB->prefix("pedigree_trash") . " WHERE ID = " . $id;
253
    $xoopsDB->queryF($sql);
254
    deleted();
255
}
256
257 View Code Duplication
function delall()
258
{
259
    global $xoopsTpl, $xoopsDB;
260
    $sql = "DELETE FROM " . $xoopsDB->prefix("pedigree_trash");
261
    $xoopsDB->queryF($sql);
262
    deleted();
263
}
264
265
/**
266
 * @param $id
267
 */
268
function restore($id)
269
{
270
    global $xoopsTpl, $xoopsDB;
271
    $sql    = "SELECT * from " . $xoopsDB->prefix("pedigree_trash") . " WHERE ID = " . $id;
272
    $result = $xoopsDB->query($sql);
273 View Code Duplication
    while ($row = $xoopsDB->fetchArray($result)) {
274
275
        foreach ($row as $key => $values) {
276
            $queryvalues .= "'" . $values . "',";
277
        }
278
        $outgoing = substr_replace($queryvalues, "", -1);
279
        $query    = "INSERT INTO " . $xoopsDB->prefix("pedigree_tree") . " VALUES (" . $outgoing . ")";
280
        $xoopsDB->queryF($query);
281
        $delquery = "DELETE FROM " . $xoopsDB->prefix("pedigree_trash") . " WHERE ID = " . $id;
282
        $xoopsDB->queryF($delquery);
283
        $form .= "<li><a href=\"pedigree.php?pedid=" . $row['ID'] . "\">" . $row['NAAM'] . "</a> has been restored into the database.<hr>";
284
    }
285
    $xoopsTpl->assign("form", $form);
286
287
}
288
289
function settings()
290
{
291
    global $xoopsUser, $xoopsTpl, $moduleConfig;
292
    include XOOPS_ROOT_PATH . "/class/xoopsformloader.php";
293
    $form = new XoopsThemeForm('General settings', 'settings', 'tools.php?op=settingssave', 'POST', 1);
294
    $form->addElement(new XoopsFormHiddenToken($name = 'XOOPS_TOKEN_REQUEST', $timeout = 360));
295
    $select  = new XoopsFormSelect("<b>Number of results per page</b>", 'perpage', $value = $moduleConfig['perpage'], $size = 1, $multiple = false);
296
    $options = array('50' => 50, '100' => 100, '250' => 250, '500' => 500, '1000' => 1000, '2000' => 2000, '5000' => 5000, '10000' => 10000);
297
    foreach ($options as $key => $values) {
298
        $select->addOption($key, $name = $values, $disabled = false);
299
    }
300
    unset($options);
301
    $form->addElement($select);
302
    $form->addElement(
303
        new XoopsFormLabel(
304
            _MA_PEDIGREE_EXPLAIN,
305
            'This field is used to set the number of results a page will return from a search. If more results are returned extra pages will be created for easy browsing.<br />Set this number higher as your database grows and the number of pages increase.'
306
        )
307
    );
308
    $radio = new XoopsFormRadio("<b>Use owner/breeder fields</b>", 'ownerbreeder', $value = $moduleConfig['ownerbreeder']);
309
    $radio->addOption(1, $name = 'yes', $disabled = false);
310
    $radio->addOption(0, $name = 'no', $disabled = false);
311
    $form->addElement($radio);
312
    $form->addElement(
313
        new XoopsFormLabel(
314
            _MA_PEDIGREE_EXPLAIN,
315
            'Use this field to set if you would like to use the owner/breeder fields of the database.<br />As the name suggests the owner/breeder fields let you record and display information about the owner and or breeder.<br />The owner/breeder menu items will also be affected by this setting.'
316
        )
317
    );
318
    $radiobr = new XoopsFormRadio("<b>Show brother & sister field</b>", 'brothers', $value = $moduleConfig['brothers']);
319
    $radiobr->addOption(1, $name = 'yes', $disabled = false);
320
    $radiobr->addOption(0, $name = 'no', $disabled = false);
321
    $form->addElement($radiobr);
322
    $form->addElement(
323
        new XoopsFormLabel(
324
            _MA_PEDIGREE_EXPLAIN,
325
            'Use this field to set if you would like to use the add a ' . $moduleConfig['litter']
326
            . 'feature.<br />If your chosen animal only has one offspring at a time this feature will not be useful to you.'
327
        )
328
    );
329
    $radiolit = new XoopsFormRadio("<b>Use add a " . $moduleConfig['litter'] . " feature</b>", 'uselitter', $value = $moduleConfig['uselitter']);
330
    $radiolit->addOption(1, $name = 'yes', $disabled = false);
331
    $radiolit->addOption(0, $name = 'no', $disabled = false);
332
    $form->addElement($radiolit);
333
    $form->addElement(
334
        new XoopsFormLabel(
335
            _MA_PEDIGREE_EXPLAIN, 'Use this field to set if you would like to display the brothers & sisters field on the detailed ' . $moduleConfig['animalType'] . ' information page.'
336
        )
337
    );
338
    $radioch = new XoopsFormRadio("<b>Show " . $moduleConfig['children'] . " field</b>", 'pups', $value = $moduleConfig['pups']);
339
    $radioch->addOption(1, $name = 'yes', $disabled = false);
340
    $radioch->addOption(0, $name = 'no', $disabled = false);
341
    $form->addElement($radioch);
342
    $form->addElement(
343
        new XoopsFormLabel(
344
            _MA_PEDIGREE_EXPLAIN, 'Use this field to set if you would like to display the ' . $moduleConfig['children'] . ' field on the detailed ' . $moduleConfig['animalType'] . ' information page.'
345
        )
346
    );
347
    $form->addElement(new XoopsFormButton('', 'button_id', 'Submit', 'submit'));
348
    $xoopsTpl->assign("form", $form->render());
349
}
350
351
function settingssave()
352
{
353
    global $xoopsDB, $xoopsUser, $xoopsTpl;
354
    $form     = "";
355
    $settings = array('perpage', 'ownerbreeder', 'brothers', 'uselitter', 'pups');
356
    foreach ($_POST as $key => $values) {
357
        if (in_array($key, $settings)) {
358
            $query = "UPDATE " . $xoopsDB->prefix("config") . " SET conf_value = '" . $values . "' WHERE conf_name = '" . $key . "'";
359
            $xoopsDB->query($query);
360
        }
361
    }
362
    $form .= "Your settings have been saved.<hr>";
363
    $xoopsTpl->assign("form", $form);
364
}
365
366
function lang()
367
{
368
    global $xoopsUser, $xoopsTpl, $moduleConfig;
369
    include XOOPS_ROOT_PATH . "/class/xoopsformloader.php";
370
    $form = new XoopsThemeForm('Language options', 'language', 'tools.php?op=langsave', 'POST');
371
    $form->addElement(new XoopsFormHiddenToken($name = 'XOOPS_TOKEN_REQUEST', $timeout = 360));
372
    $form->addElement(new XoopsFormText("<b>type of animal</b>", 'animalType', $size = 50, $maxsize = 255, $value = $moduleConfig['animalType']));
373
    $form->addElement(
374
        new XoopsFormLabel(
375
            _MA_PEDIGREE_EXPLAIN,
376
            'Use this field to set the animal type which will be used in the application.<br /><i>example : </i>snake, pigeon, dog, owl<br /><br />The value should fit in the sentences below.<br />Please add optional information for this <b>'
377
            . $moduleConfig['animalType'] . '</b>.<br />Select the first letter of the <b>' . $moduleConfig['animalType'] . '</b>.'
378
        )
379
    );
380
    $form->addElement(new XoopsFormText("<b>type of animal</b>", 'animalTypes', $size = 50, $maxsize = 255, $value = $value = $moduleConfig['animalTypes']));
381
    $form->addElement(
382
        new XoopsFormLabel(
383
            _MA_PEDIGREE_EXPLAIN,
384
            'Use this field to set the animal type which will be used in the application.<br />This field is the plural of the previous field<br /><i>example : </i>snakes, pigeons, dogs, owls<br /><br />The value should fit in the sentence below.<br />No <b>'
385
            . $moduleConfig['animalTypes'] . '</b> meeting your query have been found.'
386
        )
387
    );
388
    $form->addElement(new XoopsFormText("<b>male</b>", 'male', $size = 50, $maxsize = 255, $value = $moduleConfig['male']));
389
    $form->addElement(new XoopsFormLabel(_MA_PEDIGREE_EXPLAIN, 'Use this field to set the name used for the male animal.<br /><i>example : </i>male, buck, sire etc.'));
390
    $form->addElement(new XoopsFormText("<b>female</b>", 'female', $size = 50, $maxsize = 255, $value = $moduleConfig['female']));
391
    $form->addElement(new XoopsFormLabel(_MA_PEDIGREE_EXPLAIN, 'Use this field to set the name used for the female animal.<br /><i>example : </i>female, vixen, dam etc.'));
392
    $form->addElement(new XoopsFormText("<b>children</b>", 'children', $size = 50, $maxsize = 255, $value = $moduleConfig['children']));
393
    $form->addElement(
394
        new XoopsFormLabel(
395
            _MA_PEDIGREE_EXPLAIN, 'Use this field to set the name used for children of this type of animal (' . $moduleConfig['animalTypes'] . ').<br /><i>example : </i>pups, cubs, kittens etc.'
396
        )
397
    );
398
    $form->addElement(new XoopsFormText("<b>mother</b>", 'mother', $size = 50, $maxsize = 255, $value = $moduleConfig['mother']));
399
    $form->addElement(
400
        new XoopsFormLabel(_MA_PEDIGREE_EXPLAIN, 'Use this field to set the name used for mother of this type of animal (' . $moduleConfig['animalTypes'] . ').<br /><i>example : </i>dam, mare etc.')
401
    );
402
    $form->addElement(new XoopsFormText("<b>father</b>", 'father', $size = 50, $maxsize = 255, $value = $moduleConfig['father']));
403
    $form->addElement(
404
        new XoopsFormLabel(
405
            _MA_PEDIGREE_EXPLAIN, 'Use this field to set the name used for father of this type of animal (' . $moduleConfig['animalTypes'] . ').<br /><i>example : </i>sire, stallion etc.'
406
        )
407
    );
408
    $form->addElement(new XoopsFormText("<b>litter</b>", 'litter', $size = 50, $maxsize = 255, $value = $moduleConfig['litter']));
409
    $form->addElement(new XoopsFormLabel(_MA_PEDIGREE_EXPLAIN, 'Use this field to set the name used for a collection of newborn animals.<br /><i>example : </i>litter, nest etc.'));
410
    $form->addElement(new XoopsFormTextArea("<b>Welcome text</b>", 'welcome', $value = $moduleConfig['welcome'], $rows = 15, $cols = 50));
411
412
    $form->addElement(
413
        new XoopsFormLabel(
414
            _MA_PEDIGREE_EXPLAIN,
415
            'Use this field to set the text you would like to display for the welcome page.<br /><br />You may use the follwing variables :<br />[animalType] = ' . $moduleConfig['animalType']
416
            . '<br />[animalTypes] =' . $moduleConfig['animalTypes'] . '<br />[numanimals] = number of animals in the database.'
417
        )
418
    );
419
    $form->addElement(new XoopsFormButton('', 'button_id', 'Submit', 'submit'));
420
    $xoopsTpl->assign("form", $form->render());
421
}
422
423 View Code Duplication
function langsave()
424
{
425
    global $xoopsDB, $xoopsUser, $xoopsTpl;
426
    $form     = "";
427
    $settings = array('animalType', 'animalTypes', 'male', 'female', 'children', 'mother', 'father', 'litter', 'welcome');
428
    foreach ($_POST as $key => $values) {
429
        if (in_array($key, $settings)) {
430
            $query = "UPDATE " . $xoopsDB->prefix("config") . " SET conf_value = '" . $values . "' WHERE conf_name = '" . $key . "'";
431
            $xoopsDB->query($query);
432
        }
433
    }
434
    $form .= "Your settings have been saved.<hr>";
435
    $xoopsTpl->assign("form", $form);
436
}
437