<?php
session_start();
//------------------------------------------------------------------------------
// Includes
//------------------------------------------------------------------------------
include_once('../inc/config.php');
include_once('../inc/util.inc');
include_once('../inc/html_class.php');
include_once('../inc/validation_class.php');
mysql_connect($db_server, $db_username, $db_password);
mysql_select_db($db_database);
$validation = new Validation();
$html = new Html;
//------------------------------------------------------------------------------
// Setup Theme
//------------------------------------------------------------------------------
$THEME = array(
'site_name' => getSiteName(),
'path' => '../',
'page' => 'code',
'page_title' => _('Administration'),
'theme_path' => getTheme(),
'modules' => getAdminModules(),
);
//------------------------------------------------------------------------------
// Control Structure
//------------------------------------------------------------------------------
include $THEME['path'].$THEME['theme_path'].'adminheader.php';
if (!isLoggedInAdmin()) {
handleBadLogin();
return;
}
$message = '';
if (isset($_POST['submit'])) {
$message = displayUpdateRepoSubmit($_POST['repo']);
}
displayUpdateRepoForm($message);
include $THEME['path'].$THEME['theme_path'].'footer.php';
return;
//------------------------------------------------------------------------------
// Functions
//------------------------------------------------------------------------------
function handleBadLogin ()
{
echo '
<div class="error-alert">'._('You must login as an Administrator to view this page.').'</div>';
displayLogin('tracker.php');
}
function displayUpdateRepoSubmit ($repo)
{
global $validation;
$repo = $validation->cleanInput($repo);
$sql = "UPDATE `sam_configuration`
SET `repo` = '$repo'";
if (!mysql_query($sql)) {
logSqlError(__FILE__, __LINE__, mysql_error(), $sql);
return array('error', _('Cannot update repository.'));
}
return array('ok', _('SVN Repository updated.'));
}
function displayUpdateRepoForm ($message)
{
global $html, $validation;
$sql = "SELECT `repo` FROM `sam_configuration` LIMIT 1";
$result = mysql_query($sql);
if (!$result) {
$error = _('Could not get ticket type information.');
logSqlError($error, __FILE__, __LINE__, mysql_error(), $sql);
return array('error', $error);
}
$r = mysql_fetch_array($result);
// Show messages if any
if (is_array($message)) {
$html->displayMessage($message);
}
$repo = isset($r['repo']) ? $validation->cleanOutput($r['repo']) : '';
echo '
<fieldset>
<legend>'._('Source Code').'</legend>
<form method="post" action="code.php">
<p>
<label for="repo">'._('SVN Repository').'</label><br/>
<input type="text" class="txt" id="repo" name="repo" value="'.$repo.'"/>
</p>
<p>
<input class="sub1" type="submit" id="submit" name="submit" value="'._('Save').'"/>
</p>
</form>
</fieldset>';
}