コード例 #1
0
ファイル: borrow.php プロジェクト: nickburton/web-prog-assign
function getBooks()
{
	$fp = fopen("books.txt","r"); 
	rewind($fp);
	
	$searched = $_GET['type'];
	$_SESSION['search'] = $_GET['search'];
	$borrow = $_POST['borrow'];

	if(isset($borrow))
	{
		$cfp = fopen("bookcopy.txt","w"); 
		
		while(!feof($fp))
		{
			$line = fgets($fp);
			$element = split("\|", $line);

			if(strcmp($element[0], $_SESSION['book']) == 0)
			{
				$element[7] = "On Loan";
				$element[9] = $_SESSION['uname'];
				$element[10] = date("d-m-y",mktime(0,0,0,date("m"),date("d")+14,date("y")));
				
				echoLine($element);
				
				$write_values = implode("|",$element);
				fwrite($cfp, $write_values);
			}
			else
			{
				fwrite($cfp,$line);
			}
		}
		fclose($fp);
		fclose($cfp);

		$bookFile = "books.txt";
		$copyFile = "bookcopy.txt";
		$fp = fopen($bookFile, "w+");		
		$cfp = fopen($copyFile, "r");		
		$file_contents = fread($cfp, filesize($copyFile));
		fwrite($fp, $file_contents);
		fclose($cfp);
		
		rewind($fp);		
		fclose($fp);
	}
	else if(isset($searched))
	{
		if($_SESSION['search'] != '')
		{
			$searchType = $_GET['type'];
			
			$titles = array("title","author","category","year","pages","notes","ISBN","status","keywords");
				
			for($counter=0;$counter<count($titles);$counter++)
			{
				if($searchType == $titles[$counter])
				{
					$arrayNum = $counter;
				}
			} 
			
			while(!feof($fp))
			{
				$line = fgets($fp);
				$element = split("\|", $line);
									
				if(stristr($element[$arrayNum],$_SESSION['search']) == TRUE)
				{
					echoLine($element);
					
					if(strcmp($element[$arrayNum],$_SESSION['search']) == 0)
					{
						if(trim($element[7]) != "On Loan")
						{
							borrow_button();
						}
						$_SESSION['book'] = $element[$arrayNum];
					}
				}
			}
		}
	}	
}
コード例 #2
0
function getBooks()
{
	$fp = fopen("books.txt","r"); 
	rewind($fp);
	
	$searched = $_GET['type'];
	$_SESSION['search'] = $_GET['search'];

	if(isset($searched))
	{
		if($_SESSION['search'] != '')
		{
			$searchType = $_GET['type'];
			
			$titles = array("title","author","category","year","pages","notes","ISBN","status","keywords");
				
			for($counter=0;$counter<count($titles);$counter++)
			{
				if($searchType == $titles[$counter])
				{
					$arrayNum = $counter;
				}
			} 
			
			while(!feof($fp))
			{
				$line = fgets($fp);
				$element = split("\|", $line);
									
				if(stristr($element[$arrayNum],$_SESSION['search']) == TRUE)
				{
					echoLine($element);
					if(strcmp($element[$arrayNum],$_SESSION['search']) == 0)
					{
						borrow_button();
					}
				}
			}
		}
	}
	else
	{	
		showBooks($fp);
	}	
}