[go: up one dir, main page]

Menu

[r63]: / trunk / admin.php  Maximize  Restore  History

Download this file

234 lines (208 with data), 6.7 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
<?php
session_start();
//------------------------------------------------------------------------------
// Includes
//------------------------------------------------------------------------------
include_once('inc/config.php');
include_once('inc/util.inc');
include_once('inc/html_class.php');
mysql_connect($db_server, $db_username, $db_password);
mysql_select_db($db_database);
$html = new Html();
//------------------------------------------------------------------------------
// Setup Theme
//------------------------------------------------------------------------------
$THEME = array(
'site_name' => getSiteName(),
'path' => '',
'page' => 'admin',
'page_title' => _('Administration'),
'theme_path' => getTheme(),
'modules' => getAdminModules(),
);
if (isset($_GET['settings']) || isset($_POST['edit-general'])) {
$THEME['page'] = 'general';
}
//------------------------------------------------------------------------------
// Control Structure
//------------------------------------------------------------------------------
include $THEME['theme_path'].'adminheader.php';
if (!isLoggedInAdmin()) {
handleBadLogin();
return;
}
if (isset($_POST['edit-general'])) {
$message = displayEditSubmit();
displayEditForm($message);
} elseif (isset($_GET['settings'])) {
displayEditForm();
} else {
displayDashboard($THEME['modules'], $THEME['theme_path']);
}
include $THEME['theme_path'].'footer.php';
return;
//------------------------------------------------------------------------------
// Functions
//------------------------------------------------------------------------------
function handleBadLogin ()
{
echo '
<div class="error-alert">'._('You must logged in to view this page.').'</div>';
displayLogin();
include $THEME['theme_path'].'footer.php';
}
/**
* displayEditSubmit
*
* Updates general settings.
*
* @return array
*/
function displayEditSubmit ()
{
$update = '';
$sitename = trim($_POST['sitename']);
$contact = trim($_POST['contact']);
if (strlen($sitename) > 0) {
$sitename = stripMagicQuotes($sitename);
$sitename = escape_string($sitename);
$update .= "`sitename` = '$sitename', ";
}
if (strlen($contact) > 0) {
$contact = stripMagicQuotes($contact);
$contact = escape_string($contact);
$update .= "`contact` = '$contact', ";
}
$theme = escape_string($_POST['theme']);
$theme = basename($theme);
$sql = "UPDATE `sam_configuration`
SET $update `theme` = '$theme'";
if (!mysql_query($sql)) {
logSqlError(__FILE__, __LINE__, mysql_error(), $sql);
return array('error', _('Cannot update general settings.'));
}
// if theme changed, refresh page
if ($_POST['theme'] !== $_POST['prev-theme']) {
echo '<meta http-equiv="refresh" content="0"/>';
die();
}
return array('ok', _('General settings updated.'));
}
/**
* displayEditForm
*
* Displays the form for editing general settings.
*
* @param array $message
*
* @return void
*/
function displayEditForm ($message = '')
{
global $html;
$sql = "SELECT `sitename`, `contact`, `theme`
FROM `sam_configuration`
LIMIT 1";
$result = mysql_query($sql);
if (!$result) {
$error = _('Could not get general settings information.');
displaySqlError($error, __FILE__, __LINE__, mysql_error(), $sql);
return;
}
if (mysql_num_rows($result) < 1) {
echo '
<div class="error-alert">'._('Your site settings are corrupt or missing.').'</div>';
return;
}
$r = mysql_fetch_array($result);
// Theme
$themes = getDirectoryFileListing("themes/");
$params = array(
array(
'input' => 'text',
'id' => 'sitename',
'label' => _('Sitename'),
'value' => $r['sitename'],
),
array(
'input' => 'text',
'id' => 'contact',
'label' => _('Contact Email'),
'value' => $r['contact'],
),
array(
'input' => 'select',
'id' => 'theme',
'label' => _('Theme'),
'value' => $themes,
'selected' => $r['theme'],
),
array(
'input' => 'hidden',
'id' => 'prev-theme',
'value' => $r['theme'],
),
array(
'input' => 'submit',
'id' => 'edit-general',
'value' => _('Save'),
),
);
// Show errors if any
if (is_array($message)) {
echo '
<div class="'.$message[0].'-alert">
'.$message[1].'
</div>';
}
// Display Form
$html->displayForm('admin.php', _('General'), $params);
}
/**
* displayDashboard
*
* @param array $modules
* @param string $theme
*
* @return void
*/
function displayDashboard ($modules, $theme)
{
echo '
<div id="settings" class="clearfix">
<a class="settingsblock" href="admin.php?settings=general">
<img src="'.$theme.'images/required/general.png"/>
<i>'._('General').'</i>
<span>'._('Sitename, Email, and Theme').'</span>
<b>'._('Edit').'</b>
</a>
<a class="settingsblock" href="admin/widgets.php">
<img src="'.$theme.'images/required/widgets.png"/>
<i>'._('Widgets').'</i>
<span>'._('Design the frontpage layout').'</span>
<b>'._('Edit').'</b>
</a>
<a class="settingsblock" href="admin/modules.php">
<img src="'.$theme.'images/required/modules.png"/>
<i>'._('Modules').'</i>
<span>'._('Add or remove features').'</span>
<b>'._('Edit').'</b>
</a>
<a class="settingsblock" href="admin/users.php">
<img src="'.$theme.'images/required/users.png"/>
<i>'._('Users').'</i>
<span>'._('Configure user permissions').'</span>
<b>'._('Edit').'</b>
</a>';
foreach ($modules as $mod) {
echo '
<a class="settingsblock" href="admin/'.$mod.'.php">
<img src="'.$theme.'images/required/'.$mod.'.png"/>
<i>'.getModuleTypeName($mod).'</i>
<span>'.getModuleTypeDescription($mod).'</span>
<b>'._('Edit').'</b>
</a>';
}
echo '
</div>';
}