<?php
/**
* Setup page
*
* Handles saving of the various config options.
*
* @package Setup
* @author Andreas Gohr <hide@address.com>
* @author Andreas Götz <hide@address.com>
* @version $Id: setup.php,v 2.44 2008/04/20 17:31:20 andig2 Exp $
*/
require_once './core/session.php';
require_once './core/functions.php';
require_once './core/setup.core.php';
localnet_or_die();
permission_or_die(PERM_ADMIN);
/**
* Cache file maintenance AJAX function
*
* @author Andreas Goetz <hide@address.com>
*/
if ($ajax_cache)
{
list($total, $expired, $files) = analyzeCacheFolder('cache/imdb', !empty($cacheempty));
// add some delay for debugging
if ($config['debug'] && $_SERVER['SERVER_ADDR'] == '127.0.0.1') usleep(rand(200,1000)*1000);
header('X-JSON: '.json_encode(array(
'cachetotal' => round($total/(1024*1024), 2),
'cacheexpired' => round($expired/(1024*1024), 2),
'cacheexpiredpercent' => (0 == $total ? '0' : round($expired*100/$total, 0))
)));
exit;
}
/*
* Note:
*
* for administrators, the profile settings will override generic setup
*/
if ($quicksave)
{
// insert data
foreach ($SETUP_QUICK as $opt)
{
$SQL = 'REPLACE INTO '.TBL_CONFIG." (opt,value) VALUES ('$opt','".addslashes($$opt)."')";
runSQL($SQL);
}
// reload config
load_config(true);
}
// save data
elseif ($save)
{
$languageflags = @join('::', $languages);
$adultgenres = @join('::', $adultgenres);
// insert data
foreach ($SETUP_GLOBAL as $opt)
{
$SQL = 'REPLACE INTO '.TBL_CONFIG." (opt,value) VALUES ('$opt','".addslashes($$opt)."')";
runSQL($SQL);
}
// make sure default engine ist active
if (!empty($enginedefault))
{
$opt = 'engine'.$enginedefault;
$$opt = 1;
}
foreach ($config['engines'] as $engine => $meta)
{
$opt = 'engine'.$engine;
$config['engine'][$engine] = $$opt;
$SQL = 'REPLACE INTO '.TBL_CONFIG." (opt,value) VALUES ('$opt','".addslashes($$opt)."')";
runSQL($SQL);
}
// update session variables
update_session();
// remove user-specific config options
$user_id = get_current_user_id();
if (!empty($user_id))
{
$SQL = "DELETE FROM ".TBL_USERCONFIG." WHERE user_id = '".addslashes($user_id)."'";
runSQL($SQL);
}
// reload config
load_config(true);
/*
// clear compiled templates for new template
AG: should not be required
$smarty->clear_compiled_tpl(null, $config['cacheid']);
*/
}
// set default engine to imdb if not set
if (empty($config['enginedefault']))
{
$config['enginedefault'] = "imdb";
}
// check permissions again - they may have changed
if (!check_permission(PERM_ADMIN))
{
redirect('login.php');
}
// destroy cookies if required
if ($_COOKIE['VDBusername'] && !$config['multiuser'])
{
setcookie('VDBpassword', '', time()-7200);
setcookie('VDBusername', '', time()-7200);
setcookie('VDBuserid', '', time()-7200);
}
// cache maintenance
// moved to checkCache AJAX call
#list($total, $expired, $files) = analyzeCacheFolder('cache/imdb', !empty($cacheempty));
#if ($total)
#{
// delete from cache directory?
if ($cachecleanup || $cacheempty)
{
// need to count again for AJAX call
list($total, $expired, $files) = analyzeCacheFolder('cache/imdb', !empty($cacheempty));
foreach ($files as $file) unlink($file);
$total -= $expired;
$expired = 0;
// clear thumbnail cache
runSQL('DELETE FROM '.TBL_CACHE);
}
# $smarty->assign('total', round($total/(1024*1024), 2));
# $smarty->assign('expired', round($expired/(1024*1024), 2));
#}
// prepare options
$setup = setup_mkOptions(false);
// prepare templates
tpl_page('configview');
$smarty->assign('setup', $setup);
// display templates
tpl_display('setup.tpl');
?>