Location: PHPKode > scripts > Impleo Music Collection Script > impleo/admin/settings.php
<?php
/* ----------------------------------------------------------------------------
 * "THE BEER-WARE LICENSE" (Revision 42):
 * <hide@address.com> wrote this file. As long as you retain this notice you
 * can do whatever you want with this stuff. If we meet some day, and you think
 * this stuff is worth it, you can buy me a beer in return Christoffer Kjeldgaard Petersen
 * ----------------------------------------------------------------------------
 */

session_start();

// Login control:
if (!$_SESSION['login'] == 1)
{
	header("Location: ./");
	exit;
}

header("content-type:text/html;charset=utf-8");

require_once(dirname(__FILE__) . '/../classes/ImpleoTemplate.class.php');
require_once(dirname(__FILE__) . '/../classes/Factory.class.php');
require_once(dirname(__FILE__) . '/../classes/XMLImportExport.class.php');

$tpl = new ImpleoTemplate("settings.tpl");
$factory = Factory::getInstance();

// Updating general settings:
$updatePosted = false;
if (isset($_POST['update']))
{
    $updatePosted = true;
    $hasError = true;
    
    if (!empty($_POST['name']))
    {
        if (is_numeric($_POST['records_per_page']))
        {
            if (is_numeric($_POST['image_width']))
            {
                $hasError = false;
                if ($_POST['link'])
                    $link = true;
                else
                    $link = false;
                    
                $factory->updateGeneralSettings($_POST['name'], $_POST['records_per_page'], $link, $_POST['image_width']);
            }
            else
                $errorMsg = "Image width must be numeric.";
        }
        else
            $errorMsg = "'Records per page' must be numeric.";
    }
    else
        $errorMsg = "Collection name must be specified.";

    $tpl->assign('hasError', $hasError);
    $tpl->assign('errorMsg', $errorMsg);
}

$arrPageLimitOptions = array(0, 10, 25, 50, 100, 150, 250, 500, 1000);

$tpl->assign('updatePosted', $updatePosted);
$tpl->assign('settings', $factory->getGeneralSettings());
$tpl->assign('pageLimitOptions', $arrPageLimitOptions);

// Export XML:
if ($_POST['xml'])
{
    header('Content-Type: text/xml');
    header('Content-Disposition: attachment; filename=music_collection.xml');

    $xmlExport = new XMLImportExport();
    echo $xmlExport->exportXML();

    exit;
}

// Import XML:
$importPosted = false;
if ($_POST['import'])
{
    $importPosted = true;
    $xmlImportHasError = true;

    if ($_FILES['xmlimport']['type'] == "text/xml")
    {
        $filename = $_FILES['xmlimport']['tmp_name'];
        $handle = fopen($filename, "r");
        $xmlContents = fread($handle, filesize($filename));
        fclose($handle);

        if ($_POST['popnu']) { $popnu = true; } else { $popnu = false; }

        $xmlImport = new XMLImportExport();
        $result = $xmlImport->importXML($xmlContents, $popnu);

        if (is_array($result))
        {
            $xmlImportHasError = false;
            $tpl->assign('xmlImportResult', $result);
        }
    }

    $tpl->assign('xmlImportHasError', $xmlImportHasError);
}
$tpl->assign('xmlImportPosted', $importPosted);

// Change password:
$changePosted = false;
if ($_POST['updatepassword'])
{
    $changePosted = true;

    $pass = $factory->changePassword($_SESSION['username'], $_POST['currentpassword'], $_POST['newpassword']);
    if ($pass === true)
        $changeError = false;
    else
        $changeError = true;

    $tpl->assign('changeMessage', $pass);
    $tpl->assign('changeError', $changeError);
}
$tpl->assign('changePosted', $changePosted);

$tpl->displayTemplate();
?>
Return current item: Impleo Music Collection Script