Location: PHPKode > projects > ACSoc Comics Library Management System > odin-0.589/circu.php
<?php 
	require_once "odincom.php";
	require_once "dbo/ItemList.php";
	require_once "dbo/User.php";
	require_once "dbo/UserList.php";
	require_once "$ui_dir/uicom.inc";
	require_once "$ui_dir/renderer.inc";
	require_once "$ui_dir/dispcircu.inc";

	$script	="circu.php";
	odin_staff_login();

	if ($_SESSION['userinfo']['allowselfcheckout']) {
		if (!$_SESSION['userinfo']['allowcheckout']) {
			// only allow self checkout.  so auto select myself;
			$mid = $_SESSION['userinfo']['id'];
			myresult(1, "You account only allow you to check out materials for yourself");
		}
	} else {
		if (!check_staff_permission("allowcheckout")) {
			// error message printed
			print_header();
			print_footer();
			//redirect($GLOBALS['script_staff']);
		}
	}

	// export selected variables
	foreach (array('action', 'mid', 'ids') as $load) {
		$$load = $_POST[$load] or $$load = $_GET[$load];
	}

	if ($mid && !$member) $member = load_member($mid);
	
	switch ($action) {
		case "confirm_checkout":
			print_header();  //temporary.  should defer all printing after switch block
			if (!confirm_checkout($member)) {
				$mainPage = 1;
			}
			break;
		case "confirm_checkin":
			print_header();  //temporary.  should defer all printing after switch block
			if (!confirm_checkin($member)) {
				$mainPage = 1;
			}
			break;
		case "checkout":
			if (checkout($mid)) {
				unset($itemList);
				$_SESSION['navbar']->unregister("items");
				$member = load_member($mid);
			}
			$mainPage = 1;
			break;
		case "checkin":
			if (checkin($mid)) {
				$member = load_member($mid);
			}
			$mainPage = 1;
			break;
		default:
			$mainPage = 1;
	}


	if ($_GET['qi'] || $_GET['vol']) $itemList = search_item();
	if ($_GET['qm']) {
		$memList = search_member();
		if ($memList->no_of_match > 1) {
			print_header();
			member_choose_form($memList->list);
			$mainPage = 0;
		} elseif ($memList->no_of_match == 1) {
			$mid = $memList->ids[0];
			$member = load_member($mid);
			$midtext = "$member->patronno $member->name";	
			$_SESSION['navbar']->register("userinfo", "{$GLOBALS['script']}?chmem=1&mid=$mid", $midtext);
		}
	}
	if ($_GET['chmem']) {
		$midtext = "$member->patronno $member->name";	
		$_SESSION['navbar']->register("userinfo", "{$GLOBALS['script']}?chmem=1&mid=$mid", $midtext);
	}		

	if ($mainPage) {
		if ($member) {
			if ($ids && !$itemList) $itemList = load_items($ids);
			print_header();
			print_circu_header();
			$renderer = new Renderer();
			$renderer->is_admin = check_staff_permission('writememberlist',0);
			$renderer->render($member, "brief");
			book_form($mid, $itemList);
		}
		else {
			$_SESSION['navbar']->register("root_circu");
			print_header();
			print_circu_header();
			member_form();
		}
	}
	
	odin_disconnect();
	print_footer();
	exit;


//////////////////////////////////////////////////////////////////////////
function load_member($mid) {
	if (!check_staff_permission("readmemberlist")) return;

	$class = new User();
	$class->id = $mid;
	if (!$class->loadFromDB()) return;	
	$class->loadBorrowedBooks();
	return $class;
}

function load_items($ids) {
	$itemList = new ItemList();
	$itemList->limit = $GLOBALS['conf']['cartlimit'];
	$itemList->search_by_ids($ids);
	return $itemList;
}


/////////////////////////////////////////////////////////////////////	
function search_member() {

	global $lang;
	if (!check_staff_permission("readmemberlist")) return;
	
	if ($_GET['by'] == "co") {
		$list = new ItemList;
		$list->limit = $GLOBALS['conf']['circu_chooseuserlimit'];
		$list->search_status = "_co";
		$list->search("cn", trim($_GET['qm']));
	} 
	else {	
		$list = new UserList;	
		$list->limit = $GLOBALS['conf']['circu_chooseuserlimit'];
		$list->search($_GET['by'], trim($_GET['qm']));
	}

	if ($list->no_of_match == 0)
	{
		myresult(0, $lang[60]);
		return;
	} 
	elseif ($list->no_of_match > 1 &&
		$list->no_of_match > $GLOBALS['conf']['circu_chooseuserlimit'])
	{
		myresult(0, "Result user exceed limit: ".$GLOBALS['conf']['circu_chooseuserlimit']);
		return;
	}
	
	if (is_a($list,"ItemList")) {
		//print_r($list);
		$newlist = new UserList;
		$newlist->no_of_match = 1;
		$newlist->ids = array($list->list[0]['borrower']);
		
		/*
		$newlist->ids = array();
		$newlist->list = array();
		foreach($list->list as $item) {
			$newlist->ids[] = $item['borrower'];
			$mem['patronno']	= $item['patronno'];
			$mem['id']			= $item['id'];
			$mem['name']		= $item['name'];
			$mem['namealt'] 	= $item['namealt'];
			$mem['screenname']	= $item['screenname'];
			$newlist->list[] = $mem;
		}*/

		$list = $newlist;
	}		
	
	return $list;
}


/////////////////////////////////////////////////////////////////////	
function search_item() {
	global $lang;
	
	if (!$_GET['qi'] && $_GET['scope'] != "refine") return;
	$itemList = new ItemList();
	$itemList->limit = $GLOBALS['conf']['cartlimit'];
	$itemList->search($_GET['by'], trim($_GET['qi']), trim($_GET['vol']), $_GET['scope'], $_GET['ids']);
	if ($itemList->no_of_match > $GLOBALS['conf']['cartlimit']) {
		myresult(0, "Shopping cart is full.  You may have to narrow down your result. (No. of results = $itemList->no_of_match)");
	}
	if ($itemList->ids) {
		if (!$_POST) $_SESSION['navbar']->register("items", "get");
	}
	if ($itemList->no_of_match == 0)
	{
		myresult(0, $lang[60]);
	}
	return $itemList;
}

/////////////////////////////////////////////////////////////////////	
function checkout($mid) {
	global $lang;
	
	if (!$mid) {
		myresult(0, "Please select a member.");
		return;
	}
		
	$itemList = new ItemList();
	$itemList->limit = $GLOBALS['conf']['cartlimit'];
	$itemList->search_by_ids($_POST['coids']);
	if ($itemList->checkout($mid)) {
		myresult (1, "Checkout Success");
		return 1;
	}
}


/////////////////////////////////////////////////////////////////////	
function checkin($mid) {
	global $lang;
	
	if (!$mid) {
		myresult(0, "Please select a member.");
		return;
	}
		
	$itemList = new ItemList();
	$itemList->limit = $GLOBALS['conf']['cartlimit'];
	$itemList->search_by_ids($_POST['rtids']);
	if ($itemList->checkin($mid)) {
		myresult (1, "Return Success");
		return 1;
	}
}

/////////////////////////////////////////////////////////////////////	
function confirm_checkout($member) {
	$itemList = new ItemList();
	$itemList->limit = $GLOBALS['conf']['cartlimit'];
	if(!(is_array($_POST['co']) && count($_POST['co']) > 0)) {
		myresult(0, "Please selet an item.");
		return;
	}
	$itemList->search_by_ids(join(" ",array_keys($_POST['co'])));
	$itemdata = $itemList->list;
	$ids = $itemList->ids;
	if (! $ids) {
		myresult(0, "Please select an item.");
		return;
	}
	confirm_checkout_form($ids, $itemdata, $member);
	return 1;
}

/////////////////////////////////////////////////////////////////////	
function confirm_checkin($member) {
	$itemList = new ItemList();
	$itemList->limit = $GLOBALS['conf']['cartlimit'];
	if(!(is_array($_POST['rt']) && count($_POST['rt']) > 0)) {
		myresult(0, "Please selet an item.");
		return;
	}
	$itemList->search_by_ids(join(" ",array_keys($_POST['rt'])));
	$itemdata = $itemList->list;
	$ids = $itemList->ids;
	if (! $ids) {
		myresult(0, "Please select an item.");
		return;
	}
	confirm_checkin_form($ids, $itemdata, $member);
	return 1;
}



?>

Return current item: ACSoc Comics Library Management System