1
|
|
|
<?php |
|
|
|
|
2
|
|
|
// ------------------------------------------------------------------------- |
3
|
|
|
// pedigree |
4
|
|
|
// Copyright 2004, James Cotton |
5
|
|
|
// http://www.dobermannvereniging.nl |
6
|
|
|
// Template |
7
|
|
|
// Copyright 2004 Thomas Hill |
8
|
|
|
// <a href="http://www.worldware.com">worldware.com</a> |
9
|
|
|
// ------------------------------------------------------------------------- |
10
|
|
|
// ------------------------------------------------------------------------- // |
11
|
|
|
// This program is free software; you can redistribute it and/or modify // |
12
|
|
|
// it under the terms of the GNU General Public License as published by // |
13
|
|
|
// the Free Software Foundation; either version 2 of the License, or // |
14
|
|
|
// (at your option) any later version. // |
15
|
|
|
// // |
16
|
|
|
// You may not change or alter any portion of this comment or credits // |
17
|
|
|
// of supporting developers from this source code or any supporting // |
18
|
|
|
// source code which is considered copyrighted (c) material of the // |
19
|
|
|
// original comment or credit authors. // |
20
|
|
|
// // |
21
|
|
|
// This program is distributed in the hope that it will be useful, // |
22
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of // |
23
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // |
24
|
|
|
// GNU General Public License for more details. // |
25
|
|
|
// // |
26
|
|
|
// You should have received a copy of the GNU General Public License // |
27
|
|
|
// along with this program; if not, write to the Free Software // |
28
|
|
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // |
29
|
|
|
// ------------------------------------------------------------------------- // |
30
|
|
|
|
31
|
|
|
use Xmf\Request; |
32
|
|
|
use XoopsModules\Pedigree; |
33
|
|
|
|
34
|
|
|
//To be deleted? |
35
|
|
|
|
36
|
|
|
require_once dirname(dirname(dirname(__DIR__))) . '/include/cp_header.php'; |
37
|
|
|
//require_once(XOOPS_ROOT_PATH . "/modules/" . $xoopsModule->dirname() . "/include/pedigree_includes.php"); |
|
|
|
|
38
|
|
|
//require_once dirname(__DIR__) . "/include/pedigree_includes.php"; |
39
|
|
|
|
40
|
|
|
xoops_loadLanguage('modinfo', basename(dirname(dirname(__DIR__)))); |
41
|
|
|
require_once $GLOBALS['xoops']->path('modules/pedigree/admin/menu.php'); |
42
|
|
|
|
43
|
|
|
// Get HTTP post/get parameters. |
44
|
|
|
//import_request_variables("gp", "param_"); |
45
|
|
|
extract($_GET, EXTR_PREFIX_ALL, 'param'); |
46
|
|
|
extract($_POST, EXTR_PREFIX_ALL, 'param'); |
47
|
|
|
|
48
|
|
|
$op = Request::getCmd('op', 'main'); |
49
|
|
|
// |
50
|
|
|
// Writes out the form to get all config parameters. |
51
|
|
|
// |
52
|
|
|
function pedigree_config_form() |
53
|
|
|
{ |
54
|
|
|
$config_fields = pedigree_get_config_fields(); |
|
|
|
|
55
|
|
|
$values = pedigree_get_config(); |
|
|
|
|
56
|
|
|
print " |
57
|
|
|
<form action='config.php' method='POST' enctype='application/x-www-form-urlencoded'>\n |
58
|
|
|
<table border='1' cellpadding='0' cellspacing='0' width='100%'>\n |
59
|
|
|
<tr><th>" . _AM_PEDIGREE_CTITLE . "</th></tr>\n |
60
|
|
|
<tr>\n |
61
|
|
|
<td class='bg2'>\n |
62
|
|
|
<table width='100%' border='0' cellpadding='4' cellspacing='1'>\n"; |
63
|
|
|
|
64
|
|
|
foreach ($config_fields as $field => $prompt) { |
65
|
|
|
if ('config_id' === $field) { |
66
|
|
|
continue; |
67
|
|
|
} |
68
|
|
|
$pname = 'param_' . $field; |
|
|
|
|
69
|
|
|
print " |
70
|
|
|
<tr nowrap='nowrap'>\n |
71
|
|
|
<td class ='head'>{$prompt}</td>\n |
72
|
|
|
<td class='even aligntop'>\n |
73
|
|
|
<input type='text' name='{$field}' size='32' maxlength='32' value ='{$values[$field]}'>\n |
74
|
|
|
</td></tr>\n |
75
|
|
|
</tr>\n"; |
76
|
|
|
} |
77
|
|
|
print " |
78
|
|
|
<td class='head'> </td>\n |
79
|
|
|
<td class='even'>\n |
80
|
|
|
<input type='hidden' name='op' value='config'>\n |
81
|
|
|
<input type='hidden' name='window' value='config'>\n |
82
|
|
|
<input type='submit' value='" . _AM_PEDIGREE_BUT_GO . "'>\n |
83
|
|
|
</td></tr>\n |
84
|
|
|
</table>\n |
85
|
|
|
</td></tr>\n |
86
|
|
|
</table>\n |
87
|
|
|
</form>\n"; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* |
92
|
|
|
* @todo: create pedigree_admin_hmenu - it doesn't exist |
93
|
|
|
* |
94
|
|
|
* Displays the main admin interface |
95
|
|
|
* |
96
|
|
|
*/ |
97
|
|
|
function pedigree_config_main() |
98
|
|
|
{ |
99
|
|
|
//xoops_cp_header(); |
|
|
|
|
100
|
|
|
$p_title = _AM_PEDIGREE_CONFIGURE; |
101
|
|
|
print "<h4 style='text-align:left;'>$p_title</h4>"; |
102
|
|
|
pedigree_admin_hmenu(); |
|
|
|
|
103
|
|
|
pedigree_config_form(); |
104
|
|
|
xoops_cp_footer(); |
105
|
|
|
exit(); |
|
|
|
|
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* |
110
|
|
|
* @todo: create pedigree_get_config_fields() method, it doesn't exist anywhere |
111
|
|
|
* |
112
|
|
|
* Processes the configuration update request, by |
113
|
|
|
* getting the HTTP parameters, and putting them into the database. |
114
|
|
|
*/ |
115
|
|
|
function pedigree_config_post() |
116
|
|
|
{ |
117
|
|
|
$config_fields = pedigree_get_config_fields(); |
|
|
|
|
118
|
|
|
foreach ($config_fields as $field => $prompt) { |
119
|
|
|
$param = 'param_' . $field; |
|
|
|
|
120
|
|
|
global $$param; |
|
|
|
|
121
|
|
|
} |
122
|
|
|
$param_config_id = 1; |
123
|
|
|
$sql = 'REPLACE INTO ' . $GLOBALS['xoopsDB']->prefix('pedigree_fields') . ' (' . pedigree_to_string($config_fields) . ') VALUES ('; |
|
|
|
|
124
|
|
|
|
125
|
|
|
$first = true; |
126
|
|
|
foreach ($config_fields as $field => $prompt) { |
127
|
|
|
$param = 'param_' . $field; |
128
|
|
|
if (!$first) { |
129
|
|
|
$sql .= ', '; |
130
|
|
|
} |
131
|
|
|
// Handle a 'feature' of PHP that adds backslashes to HTTP parameters. |
132
|
|
|
$param_value = $$param; |
133
|
|
|
$sql .= "'" . $GLOBALS['xoopsDB']->escape($param_value) . "'"; |
134
|
|
|
$first = false; |
135
|
|
|
} |
136
|
|
|
$sql .= ' )'; |
137
|
|
|
if (!$GLOBALS['xoopsDB']->query($sql)) { |
138
|
|
|
$error = $GLOBALS['xoopsDB']->error(); |
139
|
|
|
xoops_cp_header(); |
140
|
|
|
pedigree_show_sql_error(_AM_PEDIGREE_ERR_ADD_FAILED, $error, $sql); |
|
|
|
|
141
|
|
|
xoops_cp_footer(); |
142
|
|
|
} else { |
143
|
|
|
redirect_header('config.php', 1, _AM_PEDIGREE_OK_DB); |
144
|
|
|
} |
145
|
|
|
exit(); |
|
|
|
|
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
switch ($op) { |
149
|
|
|
case 'main': |
150
|
|
|
pedigree_config_main(); |
151
|
|
|
break; |
152
|
|
|
case 'config': |
153
|
|
|
pedigree_config_post(); |
154
|
|
|
break; |
155
|
|
|
default: |
156
|
|
|
//xoops_cp_header(); |
|
|
|
|
157
|
|
|
/* @todo: move hard coded language string to language file */ |
158
|
|
|
print "<h1>Unknown method requested ('{$op}')</h1>"; |
159
|
|
|
xoops_cp_footer(); |
160
|
|
|
} |
161
|
|
|
|
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.