<?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>';
}