Location: PHPKode > projects > ACSoc Comics Library Management System > odin-0.589/publs.php
<?php
	require_once "odincom.php";
	require_once "$ui_dir/uicom.inc";
	require_once "dbo/Item.php";
	require_once "dbo/ItemList.php";
	require_once "dbo/Series.php";
	require_once "dbo/SeriesList.php";
	require_once "dbo/User.php";
	require_once "$ui_dir/renderer.inc";
	require_once "$ui_dir/disppubls.inc";

	$script	="publs.php";
	odin_login();

	if ($_GET['action'] == "logout") {
		odin_logout();
		exit;
	}

	if ($_GET['nvr']) {
		$_SESSION['navbar']->register("root_publs");
	}
	
	if ($_POST['action'])
		$action = $_POST['action'];
	elseif ($_GET['action'])
		$action = $_GET['action'];
	elseif ($_GET['by'])
		$action = "query";
		
	switch($action) {
		case "query":
			$_SESSION['navbar']->register("root_publs");
			$renderObj = query_series();
			$previousQuery = $_GET['query'];
			$mainForm = "query";
			break;
		case "browse":
			$_SESSION['navbar']->register("root_publs");
			$renderObj = query_series(1);
			$mainForm = "query";
			break;
		case "vycr":
			check_patron_login();
			$renderObj = user_info();
			break;
		default:
			$s = $_GET['sid'];
			$v = $_GET['vid'];
			if ($v) {
				$renderObj = volume_info($v);
			}
			elseif ($s) {
				$renderObj = series_info($s);
			}
			else {
				$_SESSION['navbar']->register("root_publs");
				$mainForm = "query";
			}
	}

	print_header();
	$renderer = new Renderer;
	$renderer->is_admin = 0;
	if (!$deferRenderObj && $renderObj) {
		$renderer->render($renderObj);
		unset($renderObj);
	}
	switch ($mainForm) {
		case "query":
			main_menu($previousQuery);
			break;
		default:
			default_form();
	}	
	if ($renderObj) {
		$renderer->render($renderObj);
	}

	print_footer();
	exit;



//////////////////////////////////////////////////////////////////////////
function query_series($browse=0) {
	global $lang;

	if (!$browse && empty($_GET['query'])) return;
	
	$_SESSION['search'] = array();
	if ($_GET['by'] == "cn" || $_GET['by'] == "ct") {
		$list = new ItemList;
		$_SESSION['search']['class'] = "Item";
	} else {
		$list = new SeriesList;
		$_SESSION['search']['class'] = "Series";
	}
	$list->lim = $_GET['lim'];
	$list->page = $_GET['page'];
	$list->orderby = $_GET['ord'];
	$list->orderdesc = $_GET['odn'];
	if ($browse) $list->browse();
	else $list->search($_GET['by'], trim($_GET['query']));
	
	if (!$browse && $list->no_of_match==1) 
	{
		// if only one match, jump directly to info page
		if (is_a($list, "ItemList")) {
			redirect("{$GLOBALS['script']}?vid={$list->list[0]['id']}");
		}
		else {
			redirect("{$GLOBALS['script']}?sid={$list->list[0]['id']}");
		}
	}
	else if ($list->no_of_match>1) {
		$displaystr = "";
		if ($_GET['query']) $displaystr .= " '{$_GET['query']}'";
		if ($_GET['page']) $displaystr .= " pg. {$_GET['page']}";
		if ($browse && $_GET['status'] == '') {
			$_SESSION['navbar']->register("browse", url_strip_qs('luck'), $displaystr);
		}
		else {
			$_SESSION['navbar']->register("result", url_strip_qs('luck'), $displaystr);
			$_SESSION['navbar']->addaction("startover", "{$GLOBALS['script']}");
		}
		
		$_SESSION['search']['url'] = url_strip_qs('luck');
		$_SESSION['search']['page'] = $list->page;
		$_SESSION['search']['maxpage'] = ceil($list->no_of_match/$list->limit);
		$_SESSION['search']['ids'] = $list->ids;
		if (($x=$_GET['luck']) != '')
		{
			if ($x == -1) $x = count($list->ids)-1;
			if (is_a($list, "ItemList")) {
				redirect("{$GLOBALS['script']}?vid={$list->ids[$x]}&x=$x");
			}
			else {
				redirect("{$GLOBALS['script']}?sid={$list->ids[$x]}&x=$x");
			}
		}

		return $list;
	}
	else
	{
		myresult(1, $lang[60]);
	}
		
	return;
}

//////////////////////////////////////////////////////////////////////////
function volume_info($vid) {
	global $lang;

	$item = new Item();
	$item->id = $vid;
	if (!$item->loadFromDB()) return;
	$_SESSION['navbar']->register("seriesinfo", "keep", trim("$series->seriesno $series->title"));
	
	$ix = $_GET['x'];
	if (is_numeric($ix) && ($sr = $_SESSION['search']) && $sr['class'] == "Item") {
		if ($ix > 0) { 
			$prurl = url_replace_qs('x', $ix-1);
			$prurl = url_replace_qs('vid', $sr['ids'][$ix-1], $prurl);
		} else {
			if ($sr['page'] > 1) {
				$prurl = url_replace_qs('page', $sr['page']-1, $sr['url']);
				$prurl = url_replace_qs('luck', '-1', $prurl);
			} else {
				$prurl = '';
			}
		}
		if ($ix < count($sr['ids'])-1) { 
			$nxurl = url_replace_qs('x', $ix+1);
			$nxurl = url_replace_qs('vid', $sr['ids'][$ix+1], $nxurl);
		} else {
			if ($sr['page'] < $sr['maxpage']) {
				$nxurl = url_replace_qs('page', $sr['page']+1, $sr['url']);
				$nxurl = url_replace_qs('luck', '0', $nxurl);
			} else {
				$nxurl = '';
			}
		}
		$_SESSION['navbar']->addaction("prev", $prurl);
		$_SESSION['navbar']->addaction("returntoresult", $sr['url']);
		$_SESSION['navbar']->addaction("next", $nxurl);
		$_SESSION['navbar']->register("volumeinfo", "{$GLOBALS['script']}?vid={$item->id}&x=ix", $item->svolume);
	}
	else 
		$_SESSION['navbar']->register("volumeinfo", "{$GLOBALS['script']}?vid={$item->id}", $item->svolume);
		
	return $item;
}

//////////////////////////////////////////////////////////////////////////
function series_info($sid) {
	global $lang;

	$series = new Series();
	$series->id = $sid;
	if (!$series->loadFromDB()) return;
	$series->loadVolumes();
	
	$ix = $_GET['x'];
	if (is_numeric($ix) && ($sr = $_SESSION['search']) && $sr['class'] == "Series") {
		if ($ix > 0) { 
			$prurl = url_replace_qs('x', $ix-1);
			$prurl = url_replace_qs('sid', $sr['ids'][$ix-1], $prurl);
		} else {
			if ($sr['page'] > 1) {
				$prurl = url_replace_qs('page', $sr['page']-1, $sr['url']);
				$prurl = url_replace_qs('luck', '-1', $prurl);
			} else {
				$prurl = '';
			}
		}
		if ($ix < count($sr['ids'])-1) { 
			$nxurl = url_replace_qs('x', $ix+1);
			$nxurl = url_replace_qs('sid', $sr['ids'][$ix+1], $nxurl);
		} else {
			if ($sr['page'] < $sr['maxpage']) {
				$nxurl = url_replace_qs('page', $sr['page']+1, $sr['url']);
				$nxurl = url_replace_qs('luck', '0', $nxurl);
			} else {
				$nxurl = '';
			}
		}
		$_SESSION['navbar']->register("seriesinfo", "{$GLOBALS['script']}?sid=$sid&x=$ix", trim("$series->seriesno $series->title"));
		$_SESSION['navbar']->addaction("prev", $prurl);
		$_SESSION['navbar']->addaction("returntoresult", $sr['url']);
		$_SESSION['navbar']->addaction("next", $nxurl);
	}
	else 
		$_SESSION['navbar']->register("seriesinfo", "{$GLOBALS['script']}?sid=$sid", trim("$series->seriesno $series->title"));
	

	return $series;
	
}


//////////////////////////////////////////////////////////////////////////
function user_info() {
	global $lang;

	$class = new User();
	$class->id = $_SESSION['userinfo']['id'];
	if (!$class->loadFromDB()) return;
	$class->loadBorrowedBooks();
	$_SESSION['navbar']->register("vycr", "?action=vycr");
	return $class;
}



?>
Return current item: ACSoc Comics Library Management System