Location: PHPKode > scripts > Impleo Music Collection Script > impleo/admin/detail-types.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');

$tpl = new ImpleoTemplate("detail-types.tpl");
$factory = Factory::getInstance();

$arrAttributes = $factory->getDetailInfo();

if (isset($_POST['update']))
{
	$required = 0;
	$show = 0;
	if (isset($_POST['editrequired']))
		$required = 1;
	if (isset($_POST['editshow']))
		$show = 1;
		
	$upd = $factory->updateDetailType($_POST['id'], $_POST['editname'], $required, $show);
	$arrAttributes = $factory->getDetailInfo();
}

$edit = -1;
for ($i = 0; $i < count($arrAttributes); $i++)
{
	$upVar = "moveup_" . $i;
	$downVar = "movedown_" . $i;
	$deleteVar = "delete_" . $i;
	$editVar = "edit_" . $i;
	if (isset($_POST[$upVar]))
	{
		$factory->moveDetailTypeUp($i);
		$arrAttributes = $factory->getDetailInfo();
	}
	if (isset($_POST[$downVar]))
	{
		$factory->moveDetailTypeDown($i);
		$arrAttributes = $factory->getDetailInfo();
	}
	if (isset($_POST[$deleteVar]))
	{
		$factory->deleteDetailType($arrAttributes[$i]['name']);
		$arrAttributes = $factory->getDetailInfo();
	}
	if (isset($_POST[$editVar]))
	{
		$edit = $i;
	}
}
$tpl->assign('edit', $edit);

$addPosted = false;
if (isset($_POST['add']))
{
	$addPosted = true;
	$errorMsg = "";
	$hasError = true;
	if (!empty($_POST['name']))
	{
			$required = 0;
			$show = 0;
			if (isset($_POST['required']))
				$required = 1;
			if (isset($_POST['showintable']))
				$show = 1;

			$ins = $factory->insertDetailType($_POST['name'], $required, $show);
			if ($ins == "ok")
			{
				$hasError = false;
				$arrAttributes = $factory->getDetailInfo();
			}
			else
				$errorMsg = $ins;
	}
	else
		$errorMsg = "Name of detail type must be specified.";
	
	$tpl->assign('hasError', $hasError);
	$tpl->assign('errorMsg', $errorMsg);
}

$tpl->assign('addPosted', $addPosted);
$tpl->assign('attributes', $arrAttributes);

$tpl->displayTemplate();

?>
Return current item: Impleo Music Collection Script