guildmaster/src_joomla_1.0/admin.guildmaster.php

105 lines
2.3 KiB
PHP

<?php
// no direct access
defined( '_VALID_MOS' ) or die( 'Restricted access' );
/*
* Make sure the user is authorized to view this page
*/
// ensure user has access to this function
if (!($acl->acl_check( 'administration', 'edit', 'users', $my->usertype, 'components', 'all' ))) {
mosRedirect( 'index2.php', _NOT_AUTH );
}
require_once( $mainframe->getPath( 'admin_html' ) );
require_once( $mainframe->getPath( 'class' ) );
switch ($task) {
case 'save' :
saveGuildmaster($option);
break;
case 'cancel' :
cancelGuildmaster();
break;
default :
showGuildmaster($option);
break;
}
/**
* List the records
* @param string The current GET/POST option
*/
function showGuildmaster($option) {
global $database, $mainframe;
$txt = array ();
$database->setQuery("SELECT * FROM #__guild_master_conf WHERE id=1");
$conf_rows = $database->loadObjectList();
$conf_row = $conf_rows[0];
// Conf options
if ($conf_row) {
foreach ($conf_row as $k => $v) {
$txt[] = "$k=$v";
}
}
// get params definitions
$params = new mosParameters( $txt, $mainframe->getPath( 'com_xml', $option ), 'component' );
HTML_guildmaster :: showSettings($option, $params);
}
/**
* Saves the record from an edit form submit
* @param string The current GET/POST option
*/
function saveGuildmaster($option) {
global $database;
$row = new GuildMasterConf($database);
$row->id=1;
$params = mosGetParam( $_POST, 'params', '' );
if (is_array($params)) {
$txt = array ();
foreach ($params as $k => $v) {
$txt[] = "$k=$v";
}
// For textareas
$total = count($txt);
for ($i = 0; $i < $total; $i++) {
if (strstr($txt[$i], "\n")) {
$txt[$i] = str_replace("\n", '<br />', $txt[$i]);
}
}
$_POST['params'] = implode( "\n", $txt );
}
if (!$row->bind($params)) {
echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
exit ();
}
if (!$row->check()) {
echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
exit ();
}
if (!$row->store()) {
echo "<script> alert('".$row->getError()."'); window.history.go(-1); </script>\n";
exit ();
}
$msg = 'Settings successfully Saved';
mosRedirect( 'index2.php?option='. $option, $msg );
}
/**
* Cancels editing and checks in the record
*/
function cancelGuildmaster() {
mosRedirect('index2.php');
}
?>