<?php
require '../jaivejaive/jaive1NoRefresh.php';
require '../jaivejaive/ScholasticaColors.php';
$CollectionName="";
$CategoryName="";
$CategoryCode="";
$DeptName="";
$DeptCode="";
$BookName="";
$BookCode="";
$AuthorName="";
$PublisherName="";
$ISBNName="";
$ColOption="";
$dirOption="Books";
$Categorytype="";
$Departmenttype="";
$RegisterType="";
$CollectionName="";
$DeptName="";
$BookName="";
$AuthorName="";
$TitleName="";
$ISBNName="";
$gOption="";
$OptionType="";
$CategoryValue="";
$DeptValue="";
$BookValue="";
$CatName="";
$myCurrentSRC="";
$BookSpec="Specifications:";
$BookSummary="Summary:";
$zipCount=0;
$zipSavedFileName="";
$zipFlag="OFF";
$advanceFlag="OFF";
$eBookName="Title:";
$BookSummary="eDescription";
$AuthorName="";
$PublisherName="";
$eBookISBN="";
$erprice=0;
$elPrice=0;
$ebPrice=0;
$epPrice=0;
$SubBalance=0;
$requestFlag=0;
$currDate=date("Y-m-d");
$TransType="INFLOW";
$SubType="";
$SubStatus="";
$TableBG1="#f0f0ff";
$TableTXT1="#ffffff";
$ButtonBG2="#f0f0fa";
$ButtonTXT2="#000000";

//----------------------- Check Controls-------------
$ModuleName="eLibrary";
$CheckBlackList="";
$CheckWhiteList="";
$ModuleStatus="OFF";

	mysqli_select_db($connect,"$myjaiveDBname")  or die ('did not find db'.mysql_error());
	$resultSUB=mysqli_query($connect,"SELECT  * FROM buzzprofile WHERE ProfileCode='$uname'");
	while($rowT = mysqli_fetch_array ($resultSUB))
	{
	$CheckBlackList=$rowT["BlackList"];
	$CheckWhiteList=$rowT["WhiteList"];
	}
	if(strpos($CheckBlackList,$ModuleName)){$ModuleStatus="ON";}else{$ModuleStatus="OFF";}	
	if($CheckBlackList=="ALLOW"){$ModuleStatus="ON";}
	if($CheckBlackList=="DENY"){$ModuleStatus="OFF";}	
	if(!strpos($CheckWhiteList,$ModuleName)){$ModuleStatus="OFF";}	
	if($CheckWhiteList=="ALLOW"){$ModuleStatus="ON";}
	if($CheckWhiteList=="DENY"){$ModuleStatus="OFF";}		
	if($ModuleStatus=="OFF"){
	//========== Disabled for this relgious free app ======
	//$fpath1="$forms/index/index.php";
	//$action1="$ffname$fpath1";
	//$_SESSION['sModuleMessage']="You are not privillaged to view the $ModuleName page - CHECK YOUR SUBSCRIPTION ...Thanks";
	//header("Location: $action1", true. 303);
	//exit;
	//========== Disabled for this relgious free app ======	
	}
//-------------------------------------

$ffgot=1000;
for($ffg=0; $ffg< $ffgot; $ffg++)
{
$imagepath="eLibraryCategory".$ffg.".jpg";
	if(file_exists($imagepath))
	unlink($imagepath);
}

$ffgot=1000;
for($ffg=0; $ffg< $ffgot; $ffg++)
{
$imagepath="eLibraryDept".$ffg.".jpg";
	if(file_exists($imagepath))
	unlink($imagepath);
}
			
			$arRecentHistory[0]="Books.Arts.History.YoungObiansiandAbiribaWarDanceSongs.jpg";
			$arRecentHistory[1]="Books.Arts.History.TheAbiribaCivilizationearlydaystothe20thCenturyAD.jpg";
			$arRecentHistory[2]="Magazines.Events.ModernAfriqueMagazineEventsandStylesChapter2.jpg";
			$arRecentHistory[3]="Magazines.News.AtangAbiriba.Vol.1No.3ItuEye2010.jpg";
			$arRecentHistory[4]="";
			$ColCategory=array();
			$unColCategory=array();
 			$resultCategory[1]="";
 			$resultCategoryName[1]="";
 			$resultDept[1]="";
 			$resultDeptName[1]="";
 			$resultBook[1]="";
 			$resultBookName[1]="";
 			$arrayresultAuthor[1]="";
 			$arrayresultPublisher[1]="";
 			$arrayresultISBN[1]="";
			$resultDeptName[1]="";
			$resultDeptCount=0;
			$resultBookCount=0;
			$resultAuthorCount=0;
			$resultPublisherCount=0;
			$resultISBNCount=0;

			$resultAuthor="";
 			$resultPublisher="";
 			$resultISBN="";

if (isset($_SESSION['sCollectionName']))
$CollectionName=$_SESSION['sCollectionName'];

if (isset($_SESSION['sCategoryName']))
$CategoryName=$_SESSION['sCategoryName'];

if (isset($_SESSION['sDeptName']))
$DeptName=$_SESSION['sDeptName'];

if (isset($_SESSION['sBookName']))
$BookName=$_SESSION['sBookName'];

if (isset($_SESSION['sAuthorName']))
$AuthorName=$_SESSION['sAuthorName'];

if (isset($_SESSION['sPublisherName']))
$PublisherName=$_SESSION['sPublisherName'];

if (isset($_SESSION['sISBNName']))
$ISBNName=$_SESSION['sISBNName'];

if (isset($_SESSION['sColOption']))
$ColOption=$_SESSION['sColOption'];

if (isset($_SESSION['sdirOption']))
$dirOption=$_SESSION['sdirOption'];

if (isset($_SESSION['szipCount']))
$zipCount=$_SESSION['szipCount'];

if (isset($_SESSION['szipSavedFileName']))
$zipSavedFileName=$_SESSION['szipSavedFileName'];

//echo "  ColOption:".$ColOption;

if (isset($_REQUEST['Collection']))
{
//echo $_REQUEST['Collection'];
$requestFlag=1;
$theOption= $_REQUEST['Collection'];
$dirOptionpos= strpos($theOption, ",",0);
 if($dirOptionpos>0){
 $dirOption=substr($theOption, 0, $dirOptionpos);
 $ColOptionpos= strpos($theOption, ".", $dirOptionpos+4);
 $ColOption=substr($theOption,$dirOptionpos+1,$ColOptionpos-$dirOptionpos-1);
 }else{
 $dirOption=$theOption;
 $ColOption="";
 }
$ColOption=trim($ColOption);
$_SESSION['sColOption']=$ColOption;
$_SESSION['sdirOption']=$dirOption;
}
//echo "  ColOption1:".$ColOption;

if (isset($_SESSION['sOptionType']))
{
$OptionType=$_SESSION['sOptionType'];
$_SESSION['sOptionType']="";
	if($OptionType=="TeachYourselfMathematics")
	$theOption="Slides.Mathematics.Gateway-Mathematics, Department.Slides.Mathematics.Gateway-Mathematics";
	
	if($OptionType=="TeachYourselfPhysics")
	$theOption="Slides.Mathematics.Gateway-Mathematics, Department.Slides.Mathematics.Gateway-Mathematics";

	if($OptionType=="TeachYourselfChemistry")
	$theOption="Slides.Mathematics.Gateway-Mathematics, Department.Slides.Mathematics.Gateway-Mathematics";
	
	if($OptionType=="TeachYourselfProgramming")
	$theOption="Slides.Mathematics.Gateway-Mathematics, Department.Slides.Mathematics.Gateway-Mathematics";
	
	$dirOptionpos= strpos($theOption, ",",0);
 		if($dirOptionpos>0){
		 $dirOption=substr($theOption, 0, $dirOptionpos);
 		$ColOptionpos= strpos($theOption, ".", $dirOptionpos+4);
 		$ColOption=substr($theOption,$dirOptionpos+1,$ColOptionpos-$dirOptionpos-1);
 		}else{
 		$dirOption=$theOption;
 		$ColOption="";
 		}
	$ColOption=trim($ColOption);
	$_SESSION['sColOption']=$ColOption;
	$_SESSION['sdirOption']=$dirOption;
	
}

//echo "  ColOption2:".$ColOption;
//echo "  diroption:".$dirOption;
if (isset($_POST['GoBar']))
{
$gOption=$_POST['GoBar'];
$_SESSION['sgOption']=$gOption;
}


if (isset($_POST['CollectionName']))
{
$CollectionName=$_POST['CollectionName'];
$_SESSION['sCollectionName']=$CollectionName;
}



if(isset($_POST['CategoryName']))
{
$CategoryName= $_POST['CategoryName'];
$_SESSION['sCategoryName']=$CategoryName;
}

if(isset($_POST['CategoryCode']))
{
$CategoryCode= $_POST['CategoryCode'];
$_SESSION['sCategoryCode']=$CategoryCode;

	mysqli_select_db($connect,"$myjaiveDBname2") or die ('did not find db'.mysql_error());
	$result5=mysqli_query($connect,"SELECT*  FROM elibrary WHERE eCategoryCode='$CategoryCode'");
	while($row5 = mysqli_fetch_array($result5))
	{
 	$CategoryName=$row5["eCategoryName"];
	}

}


//echo "CategoryName:".$CategoryName;


if (isset($_POST['DeptName']))
{
$DeptName=$_POST['DeptName'];
$_SESSION['s']=$DeptName;
}


if (isset($_POST['DeptCode']))
{
$DeptCode=$_POST['DeptCode'];
$_SESSION['s']=$DeptCode;
	mysqli_select_db($connect,"$myjaiveDBname2") or die ('did not find db'.mysql_error());
	$result5=mysqli_query($connect,"SELECT*  FROM elibrary WHERE eDeptCode='$DeptCode'");
	while($row5 = mysqli_fetch_array($result5))
	{
 	$DeptName=$row5["eDeptName"];
	}


}

if (isset($_POST['BookName']))
{
$BookName=$_POST['BookName'];
$_SESSION['sBookName']=$BookName;
}

if (isset($_POST['BookCode']))
{
$BookCode=$_POST['BookCode'];
$_SESSION['sBookCode']=$BookCode;
	mysqli_select_db($connect,"$myjaiveDBname2") or die ('did not find db'.mysql_error());
	$result5=mysqli_query($connect,"SELECT*  FROM elibrary WHERE eBookCode='$BookCode'");
	while($row5 = mysqli_fetch_array($result5))
	{
 	$BookName=$row5["eBookName"];
	}

}


if (isset($_POST['AuthorName']))
{
$AuthorName=$_POST['AuthorName'];
$_SESSION['s']=$AuthorName;
}


if (isset($_POST['PublisherName']))
{
$PublisherName=$_POST['PublisherName'];
$_SESSION['sPublisherName']=$PublisherName;
}


if (isset($_POST['ISBNName']))
{
$ISBNName=$_POST['ISBNName'];
$_SESSION['sISBNName']=$ISBNName;
}

if (isset($_POST['Box1']))
{
$uname=$_POST['Box1'];
$_SESSION['sBox1']=$uname;
mysqli_select_db($connect,"$myjaiveDBname") or die ('did not find db'.mysql_error());
$qry = "UPDATE buzzprofile SET ActivePageP1='$uname' WHERE ProfileCode='$uname' ";
mysqli_query($connect, $qry) or die ('could not query: '.mysql_error());
//mysqli_close($connect);
}
else
{
$uname=$ap1;
}
if (isset($_POST['Box2']))
{
$nname=$_POST['Box2'];
$_SESSION['sBox2']=$nname;
mysqli_select_db($connect,"$myjaiveDBname") or die ('did not find db'.mysql_error());
$qry = "UPDATE buzzprofile SET ActivePageP2='$nname' WHERE ProfileCode='$uname' ";
mysqli_query($connect, $qry) or die ('could not query: '.mysql_error());
//mysqli_close($connect);
}
else
{
$nname=$ap2;
}

mysqli_select_db($connect,"$myjaiveDBname2") or die ('did not find db'.mysql_error());
$arHistory=mysqli_query($connect,"SELECT*  FROM erecent");
$recentcounter=4;
while($row5 = mysqli_fetch_array($arHistory))
{
$arRecentHistory[$recentcounter]=$row5["RecentName"];
$recentcounter++;
}
$aruniqueHistory=array_unique($arRecentHistory);
$arupsidedown=array_reverse($aruniqueHistory);
$myRecentHistory1=$arupsidedown[0];
$myRecentHistory2=$arupsidedown[1];
$myRecentHistory3=$arupsidedown[2];
$myRecentHistory4=$arupsidedown[3];

//print_r($arRecentHistory);
//print_r($myRecentHistory2=$arupsidedown[0]);
//print_r($myRecentHistory2=$arupsidedown[1]);
//print_r($myRecentHistory2=$arupsidedown[2]);
//print_r($myRecentHistory2=$arupsidedown[3]);

$boxCs = "";
$boxA = "";
$boxSt = "";
$boxSc = "";
$boxCs = "";
$boxTm = "";


mysqli_select_db($connect,"$myjaiveDBname") or die ('did not find db'.mysql_error());
$result1=mysqli_query($connect,"SELECT*  FROM buzzprofile WHERE ProfileCode='$uname'");
while($row1 = mysqli_fetch_array($result1))
{
$boxA = $row1["ProfileNumber"];
$boxSt = $row1["NickName"];
$boxSc = $row1["School"];
$boxCs = $row1["Class"];
$boxTm = $row1["Term"];
$RegisterType= $row1["RegisterType"];
}
$_SESSION['sBoxA']=$boxA;
$_SESSION['sBoxSc']=$boxSc;
$_SESSION['sBoxSt']=$boxSt;
$_SESSION['sBoxCs']=$boxCs;
$_SESSION['sBoxTm']=$boxTm;

if ($RegisterType=="EntranceRegistration")
{
$fpath="$forms/frmAdmission/index.php";
$action1="$ffname$fpath";
header("Location: $action1", true. 303);
exit;
}

if(!empty($requestFlag))
//======================= begin Subscription charges ====
{
		//get price
	mysqli_select_db($connect,"$myjaiveDBname2") or die ('did not find db'.mysql_error());
	$result5=mysqli_query($connect,"SELECT*  FROM elibrary");
	while($row5 = mysqli_fetch_array($result5))
	{
		$eFilePath=$row5["eFilePath"];
	//echo "   eFilePath:".$eFilePath;
		if($dirOption==$eFilePath)
		{
		$eBookName=$row5["eBookName"];
		$erprice=$row5["erPrice"];
		$elPrice=$row5["elPrice"];
		$ebPrice=$row5["ebPrice"];
		$epPrice=$row5["epPrice"];
		$ebPrice=$epPrice+($epPrice*.4);
	//echo "   BookSummary1:".$BookSummary;
		}			     				
	}

	//get Balance
	mysqli_select_db($connect,"$myjaiveDBname")  or die ('did not find db'.mysql_error());
	$resultSUB=mysqli_query($connect,"SELECT  * FROM buzzprofile WHERE ProfileCode='$uname'");
	while($rowT = mysqli_fetch_array ($resultSUB))
	{
	$SubBalance=$rowT["SubscriptionBalance"];
	$SubType=$rowT["SubscriptionType"];
	$SubStatus=$rowT["SubscriptionStatus"];
	}
	
	//get intance info
	$chargeEnable=1;
	mysqli_select_db($connect,"$myjaiveDBname")  or die ('did not find db'.mysql_error());
	$resultSUB=mysqli_query($connect,"SELECT  * FROM tblscholasticasubscriptionlog WHERE SubscriberCode='$uname'");
	while($rowT = mysqli_fetch_array ($resultSUB))
	{
		if($dirOption==$rowT["TransactionItem"] AND $currDate=$rowT["SubscriptionDate"])
		{
		$chargeEnable=0;
		}

	}
				
	if ($ColOption=="Subscription")
	{
	//========== Disabled for this relgious free app ======	    
	//$fpath="$forms/frmSubscription/DisplaySubscription.php";
	//$action1="$ffname$fpath";
	//header("Location: $action1", true. 303);
	//exit;
	//========== Disabled for this relgious free app ======	
	}

	if ($ColOption=="Read")
	{
	//Check Subscription confirm enough balance for the read proce	
	//deduct read price from account Subscription
	//then continue
	$DiffPrice=$SubBalance-$erprice;
	//echo "  DiffPrice:".$DiffPrice;
		//if(!empty($DiffPrice) OR !empty($chargeEnble))
		if(!empty($DiffPrice) OR empty($chargeEnble))		
		{
		//function to deduct read price from current subcription balance
			if(!empty($chargeEnable))
			{
			$qry = "UPDATE buzzprofile SET  SubscriptionBalance='$DiffPrice' WHERE ProfileCode='$uname' ";
			mysqli_query($connect,"$qry")  or die ('could not query Monthly: '.mysql_error());
			
			$qry = "INSERT INTO tblscholasticasubscriptionlog (SubscriberName, SubscriberCode, TransactionType, SubscriptionType, TransactionAmount, SubscriptionBalance, SubscriptionDate, SubscriptionStatus, TransactionItem) VALUES ('" . mysqli_real_escape_string($connect, $nname) . "', '" . mysqli_real_escape_string($connect, $uname) . "', '" . mysqli_real_escape_string($connect, $TransType) . "', '" . mysqli_real_escape_string($connect, $SubType) . "', '" . mysqli_real_escape_string($connect, $erprice) . "', '" . mysqli_real_escape_string($connect, $DiffPrice) . "', '" . mysqli_real_escape_string($connect, $currDate) . "', '" . mysqli_real_escape_string($connect, $SubStatus) . "', '" . mysqli_real_escape_string($connect, $dirOption) . "')";
			mysqli_query($connect,"$qry") ;
			}		
		$ColOption="Collection";	
		}
		else
		{
		// output Notification page and possibly  redirect uer to Subscription page
		$fpath="$forms/frmSubscription/DisplaySubscription.php";
		$action1="$ffname$fpath";
		header("Location: $action1", true. 303);
		exit;	
		}

	}

	if ($ColOption=="Loan")
	{
	//Check Subscription confirm enough balance for the read proce	
	//deduct read price from account Subscription
	//then continue
	//Goto Loan Page
	//$fpath="$forms/frmSubscription/DisplaySubscription.php";
	//$action1="$ffname$fpath";
	//header("Location: $action1", true. 303);
	//exit;
	$ColOption="Collection";
	}

	if ($ColOption=="SoftCopy")
	{
	//Check Subscription confirm enough balance for the read proce	
	//deduct read price from account Subscription
	//then continue
	//Goto SoftCopy DownLoad Page

	//header('Content-type: application/pdf');
	//header('Content-Disposition: attachment; filename="downloaded.pdf"');
	//readfile($path2eLibraryBooks."Books.Novels.Fiction.HisVenom.pdf");

	$file = $path2eLibraryBooks."Books.Novels.Fiction.HisVenom.pdf";

		if (file_exists($file)) {
		    header('Content-Description: File Transfer');
		    header('Content-Type: application/octet-stream');
		    header('Content-Disposition: attachment; filename='.basename($file));
		    header('Content-Transfer-Encoding: binary');
		    header('Expires: 0');
		    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
		    header('Pragma: public');
		    header('Content-Length: ' . filesize($file));
		    ob_clean();
		    flush();
		    readfile($file);
		    exit;
		}
	}

	if ($ColOption=="HardCopy")
	{
	//Check Subscription confirm enough balance for the read proce	
	//deduct read price from account Subscription
	//then continue
	//Goto HardCopy Purchase and delivery Page
	$fpath="$forms/frmSubscription/DisplaySubscription.php";
	$action1="$ffname$fpath";
	header("Location: $action1", true. 303);
	exit;
	}
}
//======================= end Subscription charges ====

if (isset($_SESSION['sBox1']))
$uname=$_SESSION['sBox1'];
if (isset($_SESSION['sBox2']))
$nname=$_SESSION['sBox2'];
$_SESSION['sBox1']=$uname;
$_SESSION['sBox2']=$nname;


if ($gOption=="Close")
{
$fpath="$forms/index/index.php";
$action1="$ffname$fpath";
header("Location: $action1", true. 303);
exit;
}


if ($gOption=="Add New")
{
$fpath="$forms/frmeLibrary/frmeLibraryUpload.php";
$action1="$ffname$fpath";
header("Location: $action1", true. 303);
exit;
}

if($dirOption=="Next")
{
$zipCount=$zipCount+1;
$ColOption="Collection";
$dirOption=$zipSavedFileName;	
}

if($dirOption=="Previous")
{
$zipCount=$zipCount-1;
	if($zipCount<1)
	{
		$zipCount=0;
	}
$ColOption="Collection";
$dirOption=$zipSavedFileName;	
}
//================ if file type i .zip etract the particular file ======================
//$zip = new ZipArchive;
//$res = $zip->open('test_im.zip');
//if ($res === TRUE) {
//    $zip->extractTo('/my/destination/dir/', array('pear_item.gif', 'testfromfile.php'));
//    $zip->close();
//    echo 'ok';
//} else {
//    echo 'failed';
//}
//====================================== end etract zip file ================================================
//echo "  zipCount:".$zipCount;
//echo "  colOption:".$ColOption;
//echo "  collection:".$CollectionName;

//echo "  zipSavedFileName:".$zipSavedFileName;
//echo "  dirOption:".$dirOption;

//====================================== Begin Menu Bar ==========================================		


$fpath="$forms/frmeLibrary/frmDisplayeLibraryPortraitSmall.php";
$action1="$ffname$fpath";

echo "<Form Name=\"frmeLibrary1\" method=\"post\" action=\"$action1\"  align=\"center\"  style=\"background-color: #000000; text-align:center; font-size: 16.0pt; font-family: 'Cooper Black',serif; color: #ffffff; font-weight: Bold;  border: 1px solid; padding: 5px 4px\">\n";

//echo "<div align=\"center\">";

//=========================================== END Collections================================================

//=========================================== Begin Header Library Graphics Bar================================================

echo "<table border=\"0\" width=\"1280\" cellpadding=\"6\"  id=\"table2\"  style=\"border-collapse: collapse;  \" > ";
	    echo "</tr>";

			
			//============================================== Begin main Library Display Window========================================================
			//echo "<td   height=\"600\" colspan=\"1\" rowspan=\"11\" align=\"left\" valign=\"top\" >";
			//echo "</td>";

			echo "<td  width=\"1280\" height=\"800\"  colspan=\"8\" rowspan=\"11\" align=\"center\" valign=\"top\"  style=\"border-collapse: collapse; color:$ButtonTXT2; background-color:#555555 \">";


					if ($dirOption=="Books" OR $dirOption=="Journals" OR $dirOption=="Magazines" OR $dirOption=="Videos" OR $dirOption=="Audios" OR $dirOption=="Photos" OR $dirOption=="Slides" OR $dirOption=="Documents")
					{
						$gOption="";

						//===========================Begin Books Journals Magazines Videos Audios Photos ==================================
										
							$totggt=0;

							$dir = $path2Root."/eLibraryImages/";
							$dirtmp = $path2Root."/eLibraryImages/";
				
							// Open a known directory, and proceed to read its contents and get total number of files
							if (is_dir($dirtmp)) {
							if ($dh = opendir($dirtmp)) {
							while (($file = readdir($dh)) !== false) {
							$totggt=$totggt+1;
							}
							closedir($dh);
							}
							}

							// check that it is part of the owners Shop or company and include it in the list
							$files1 = scandir($dir);
							$ggt=0;
							$caCount=0;
							for($ggt=0; $ggt< $totggt; $ggt++)
							{
							$Invoutput1=$files1[$ggt];
							$dirOptionLEN=strlen($dirOption);
							$gfth=substr("$Invoutput1",0,$dirOptionLEN);

			      					if("$gfth"=="$dirOption")
			      					{
								$dirOptionLEN=strlen($dirOption);
								$catPOS=strpos($Invoutput1, ".", $dirOptionLEN+1);
								$unColCategory[$ggt]=substr("$Invoutput1",0,$catPOS);
								$caCount=$caCount+1;
			      					}

							
							}
								$ColCategory=array_unique($unColCategory);
								$ffgot=count($ColCategory);
								$caPosINDEX=array_keys($ColCategory);
								//========================Show Categories=============================
									$ffgVal=0;
									for($ffg=0; $ffg< $ffgot; $ffg++)
									{
									$ffgVal=$caPosINDEX[$ffg];
									$CatName="Category.".$ColCategory[$ffgVal];
									//$action2="/$forms/frmeLearning/frmDisplayeLearning.php?Collection=$ColCategory[$ffgVal], $CatName";	
									$action2="/$forms/frmeLibrary/frmDisplayeLibraryPortraitSmall.php?Collection=$ColCategory[$ffgVal], $CatName";	
									echo "<a href=\"$action2\">";
									//$mysrc="eLibraryImages/eLibraryCategory.jpg";
									$mysrc="eLibraryCategory.jpg";

			// Create a blank image and add some text
			$im = imagecreatetruecolor(250, 50);
			$text_color = imagecolorallocate($im, 200, 200, 200);
			$background_color = imagecolorallocate($im, 200, 200, 200);
			imagestring($im,5, 5, 5, $ColCategory[$ffgVal], $text_color);
			//$imagepath=$mysrc;
			$imagepath="eLibraryCategory".$ffgVal.".jpg";
			//imagepng($im);
			imagejpeg($im, $imagepath);
			//imagedestroy($im);
			
//$im = imagegrabscreen();
imagejpeg($im, "$imagepath");
//imagedestroy($im);

									echo "<img border=\"0\"  src=$imagepath  width=\"200\"  height=\"50\" > ";
									echo "</a>&nbsp&nbsp\n";
									}

								//=====================================================



					}
					elseif ($ColOption=="Category")
					{
							$gOption="";

						//================================================
							$totggt=0;

							$dir = $path2Root."/eLibraryImages/";
							$dirtmp = $path2Root."/eLibraryImages/";
				
							// Open a known directory, and proceed to read its contents and get total number of files
							if (is_dir($dirtmp)) {
							if ($dh = opendir($dirtmp)) {
							while (($file = readdir($dh)) !== false) {
							$totggt=$totggt+1;
							//echo "filename: $file : filetype: " . filetype($dirtmp. $file) . "\n";
							}
							closedir($dh);
							}
							}
							//echo $totggt;

							// check that it is part of the owners Shop or company and include it in the list
							$files1 = scandir($dir);
							$ggt=0;
							//while($ggt<$totggt)
							$caCount=0;
							for($ggt=0; $ggt< $totggt; $ggt++)
							{
							$Invoutput1=$files1[$ggt];
							//$dirPOS=$dirOption.\".\";
							//$gfthPOS=strpos($Invoutput1, $dirPOS, 0);
							$dirOptionLEN=strlen($dirOption);
							$gfth=substr("$Invoutput1",0,$dirOptionLEN);
							//echo $gfth;

			      					if("$gfth"=="$dirOption")
			      					{
								$dirOptionLEN=strlen($dirOption);
								$catPOS=strpos($Invoutput1, ".", $dirOptionLEN+1);
								$unColCategory[$ggt]=substr("$Invoutput1",0,$catPOS);
								//$caPosINDEX[$caCount]=$ggt;
								//echo $caPosINDEX[$caCount];
								$caCount=$caCount+1;
			      					}

							
							}
								$ColCategory=array_unique($unColCategory);
								$ffgot=count($ColCategory);
								$caPosINDEX=array_keys($ColCategory);
								//========================Show Departments =============================
									$ffgVal=0;
									for($ffg=0; $ffg< $ffgot; $ffg++)
									{
									$ffgVal=$caPosINDEX[$ffg];
									$CatName="Department.".$ColCategory[$ffgVal];
									$action2="/$forms/frmeLibrary/frmDisplayeLibraryPortraitSmall.php?Collection=$ColCategory[$ffgVal], $CatName";	
									//$action2="/$forms/frmeLearning/frmDisplayeLearning.php?Collection=$ColCategory[$ffgVal], $CatName";	
									echo "<a href=\"$action2\">";
									$mysrc="eLibraryImages/eLibraryDept.jpg";


									$im = imagecreatetruecolor(200, 50);
									$text_color = imagecolorallocate($im, 200, 200, 200);
									imagestring($im,5, 5, 5, $ColCategory[$ffgVal], $text_color);
									$imagepath="eLibraryDept".$ffgVal.".jpg";
									imagejpeg($im, $imagepath);
						
									echo "<img border=\"0\"  src=$imagepath  width=\"200\"  height=\"50\" > ";
									//echo "<input type=\"text\" name=\"Departmenttype\" size=\"10\"  maxlenght=\"20\"  style=\"alignment: Center; background-color:#00c000\" Value=\"$ColCategory[$ffgVal]\" >";
									echo "</a>&nbsp&nbsp\n";
									}
			imagedestroy($im); //unlink($imagepath);
								//==============================================================================================

					}
					elseif ($ColOption=="Department")
					{
						$gOption="";
								//}
						//================================================
							$totggt=0;

							$dir = $path2Root."/eLibraryImages/";
							$dirtmp = $path2Root."/eLibraryImages/";
				
							// Open a known directory, and proceed to read its contents and get total number of files
							if (is_dir($dirtmp)) {
							if ($dh = opendir($dirtmp)) {
							while (($file = readdir($dh)) !== false) {
							$totggt=$totggt+1;
							//echo "filename: $file : filetype: " . filetype($dirtmp. $file) . "\n";
							}
							closedir($dh);
							}
							}
							//echo $totggt;

							// check that it is part of the owners Shop or company and include it in the list
							$files1 = scandir($dir);
							$ggt=0;
							//while($ggt<$totggt)
							$caCount=0;
							for($ggt=0; $ggt< $totggt; $ggt++)
							{
							$Invoutput1=$files1[$ggt];
							
							//$dirPOS=$dirOption.\".\";
							//$gfthPOS=strpos($Invoutput1, $dirPOS, 0);
							$dirOptionLEN=strlen($dirOption);
							$gfth=substr("$Invoutput1",0,$dirOptionLEN);
							//echo $gfth;

			      					if("$gfth"=="$dirOption")
			      					{
//Echo "  dirOptionk:".$dirOption;
//Echo "  Invoutput1:".$Invoutput1;
								$dirOptionLEN=strlen($dirOption);
								//$catPOS=strpos($Invoutput1, ".", $dirOptionLEN+1);
								$catPOS=strpos($Invoutput1, ".", $dirOptionLEN+1);
								$unColCategory[$ggt]=substr("$Invoutput1",0,strlen($Invoutput1)-4);
//Echo "  unColCategory[$ggt]:".$unColCategory[$ggt];
								//$caPosINDEX[$caCount]=$ggt;
								//echo $caPosINDEX[$caCount];
								$caCount=$caCount+1;
			      					}

							
							}
								$ColCategory=array_unique($unColCategory);
								$ffgot=count($ColCategory);
								$caPosINDEX=array_keys($ColCategory);
								//========================Show Books =============================
									$ffgVal=0;
									for($ffg=0; $ffg< $ffgot; $ffg++)
									{
									$ffgVal=$caPosINDEX[$ffg];
									//$CatName="Collection.".$ColCategory[$ffgVal]. ".jpg";
									$CatName="ShowBook.".$ColCategory[$ffgVal]. ".jpg";

									$mysrcName=$ColCategory[$ffgVal]. ".jpg";
									$action2="/$forms/frmeLibrary/frmDisplayeLibraryPortraitSmall.php?Collection=$mysrcName, $CatName";	
									//$action2="/$forms/frmeLearning/frmDisplayeLearning.php?Collection=$mysrcName, $CatName";	
									echo "<a href=\"$action2\">";
									$mysrc="eLibraryImages/$mysrcName";			
									echo "<img title=\"$ColCategory[$ffgVal]\" border=\"0\"  src=$ffname$mysrc  width=\"81\"  height=\"81\" > ";
									echo "</a>\n";
									//echo "<input type=\"text\" name=\"Booktype\" size=\"12\"  maxlenght=\"20\"  style=\"alignment: Center; background-color:#00c000\" Value=\"$CatName\">";
									//echo $mysrc;
									}

								//=====================================================

					}
		elseif ($ColOption=="Collection")
		{
			$ColOption="";
			$_SESSION['sColOption']="";

				$gfthPOS=0;
				$gfthType="";

				$gfthPOS=strpos($dirOption, ".", 0);
				$gfthType=substr("$dirOption",0,$gfthPOS);
     				$mybytes="";
			//========add to previous books menu=====
			$myCurrentSRC=$dirOption;
			//array_shift($arRecentHistory,$myCurrentSRC);
			//========================= update recent history================
  			mysqli_select_db($connect,"$myjaiveDBname2") or die ('did not find db'.mysql_error());
  			$qry = "INSERT INTO erecent (RecentName) VALUES ('" . mysqli_real_escape_string($connect, $myCurrentSRC) . "')";
			mysqli_query($connect, $qry) or die ('could not query: '.mysql_error());
			//===============================================================

			//=======================================
			//if($gfthType=="Books"){
     		//		$mybytes=str_replace(".jpg", ".pdf", "$dirOption");
			//}
			//elseif($gfthType=="Magazines"){
     		//		$mybytes=str_replace(".jpg", ".pdf", "$dirOption");
			//}
			//elseif($gfthType=="Journals"){
     		//		$mybytes=str_replace(".jpg", ".pdf", "$dirOption");
			//}
			//elseif($gfthType=="Audios"){
     		//		$mybytes=str_replace(".jpg", ".mp3", "$dirOption");
			//}
			//elseif($gfthType=="Videos"){
     		//		$mybytes=str_replace(".jpg", ".mpeg", "$dirOption");
			//}
			//elseif($gfthType=="Photos"){
     		//		$mybytes=str_replace(".jpg", ".jpg", "$dirOption");
			//}

			//elseif($gfthType=="Slides"){
     		//		$mybytes=str_replace(".jpg", ".jpg", "$dirOption");
			//}

								$dirOptionLEN=strlen($dirOption);
								$catPOS=strpos($dirOption, ".", $dirOptionLEN-5);
			     				$mybytes="";
			     				$mybytes=substr("$dirOption",0,$catPOS);
							$zipLEN=strlen($mybytes);		
			     				$zipPOS=strpos($mybytes, ".", $zipLEN-5);
			     				$myZipbytes=substr("$mybytes",0,$zipPOS);
			     				$zipExt=substr("$mybytes",$zipPOS);
			     				
			     				if($zipSavedFileName==$dirOption)
			     				{
			     					//contiue
			     				}else{
									$zipSavedFileName="";
									$zipCount=0;
									$_SESSION['szipSavedFileName']="";
									$_SESSION['szipCount']=0;
								}
//echo "  zipExt:".$zipExt;
			     				if($zipExt==".zip")
			     				{
									$zipFlag="ON";
									$zipSavedFileName=$dirOption;
							$_SESSION['szipSavedFileName']=$zipSavedFileName;
							$_SESSION['szipCount']=$zipCount;
								}else{
								$zipFlag="OFF";	
								}
			if ($gfthType=="Books" OR $gfthType=="Magazines" OR $gfthType=="Journals" OR $gfthType=="Videos" OR $gfthType=="Audios" OR $gfthType=="Photos" OR $gfthType=="Slides")
			{

						if ($gfthType=="Books")
						{
						$dirpdf= $path2Root."/eLibraryBooks/";
						$dirpdftemp= $path2Root."/eLibraryBooks/";
						$dirziptemp= $path2Root."/androidapps/frmeLibrary/";
						$bytes = $ffname."eLibraryBooks/".$mybytes;
							if($zipFlag=="ON")
							{
								$zip = new ZipArchive;
								if ($zip->open($path2Root."/eLibraryBooks/".$mybytes) === TRUE)
								{
								$zip->extractTo($dirziptemp,array($zip->getNameIndex($zipCount)));
								$zipbytes=$ffname."androidapps/frmeLibrary/".$zip->getNameIndex($zipCount);	
								echo "<embed src=$zipbytes  width=\"900\"  height=\"600\" >\n";

								//unlink($zipbytes); //unlink($imagepath);
				    				$zip->close();
								} else {
								    echo 'failed';
								}

								
							}else{
								echo "<embed src=$bytes  width=\"900\"  height=\"600\" >\n";								
							}

						}

						if ($gfthType=="Magazines")
						{
						$dirpdf= $path2Root."/eLibraryMagazines/";
						$dirpdftemp= $path2Root."/eLibraryMagazines/";
						$dirziptemp= $path2Root."/androidapps/frmeLibrary/";
						$bytes = $ffname."eLibraryMagazines/".$mybytes;
							if($zipFlag=="ON")
							{
								$zip = new ZipArchive;
								if ($zip->open($path2Root."/eLibraryMagazines/".$mybytes) === TRUE)
								{
								$zip->extractTo($dirziptemp,array($zip->getNameIndex($zipCount)));
								$zipbytes=$ffname."androidapps/frmeLibrary/".$zip->getNameIndex($zipCount);	
								echo "<embed src=$zipbytes  width=\"900\"  height=\"600\" >\n";

								//unlink($zipbytes); //unlink($imagepath);
				    				$zip->close();
								} else {
								    echo 'failed';
								}

								
							}else{
								echo "<embed src=$bytes  width=\"900\"  height=\"600\" >\n";								
							}

						}

						if ($gfthType=="Journals")
						{
						$dirpdf= $path2Root."/eLibraryJournals/";
						$dirpdftemp= $path2Root."/eLibraryJournals/";
						$dirziptemp= $path2Root."/androidapps/frmeLibrary/";
						$bytes = $ffname."eLibraryJournals/".$mybytes;
							if($zipFlag=="ON")
							{
								$zip = new ZipArchive;
								if ($zip->open($path2Root."/eLibraryJournals/".$mybytes) === TRUE)
								{
								$zip->extractTo($dirziptemp,array($zip->getNameIndex($zipCount)));
								$zipbytes=$ffname."androidapps/frmeLibrary/".$zip->getNameIndex($zipCount);	
								echo "<embed src=$zipbytes  width=\"900\"  height=\"600\" >\n";

								//unlink($zipbytes); //unlink($imagepath);
				    				$zip->close();
								} else {
								    echo 'failed';
								}

								
							}else{
								echo "<embed src=$bytes  width=\"900\"  height=\"600\" >\n";								
							}

						}

						if ($gfthType=="Videos")
						{
						$dirpdf= $path2Root."/eLibraryVideos/";
						$dirpdftemp= $path2Root."/eLibraryVideos/";
						$dirziptemp= $path2Root."/androidapps/frmeLibrary/";
						$bytes = $ffname."eLibraryVideos/".$mybytes;
							if($zipFlag=="ON")
							{
								$zip = new ZipArchive;
								if ($zip->open($path2Root."/eLibraryVideos/".$mybytes) === TRUE)
								{
								$zip->extractTo($dirziptemp,array($zip->getNameIndex($zipCount)));
								$zipbytes=$ffname."androidapps/frmeLibrary/".$zip->getNameIndex($zipCount);	
								echo "<embed src=$zipbytes  width=\"900\"  height=\"600\" >\n";

								//unlink($zipbytes); //unlink($imagepath);
				    				$zip->close();
								} else {
								    echo 'failed';
								}

								
							}else{
								echo "<embed src=$bytes  width=\"900\"  height=\"600\" >\n";								
							}

						}

						if ($gfthType=="Audios")
						{
						$dirpdf= $path2Root."/eLibraryAudios/";
						$dirpdftemp= $path2Root."/eLibraryAudios/";
						$dirziptemp= $path2Root."/androidapps/frmeLibrary/";
						$bytes = $ffname."eLibraryAudios/".$mybytes;
							if($zipFlag=="ON")
							{
								$zip = new ZipArchive;
								if ($zip->open($path2Root."/eLibraryAudios/".$mybytes) === TRUE)
								{
								$zip->extractTo($dirziptemp,array($zip->getNameIndex($zipCount)));
								$zipbytes=$ffname."androidapps/frmeLibrary/".$zip->getNameIndex($zipCount);	
								echo "<embed src=$zipbytes  width=\"900\"  height=\"600\" >\n";
								//echo "<img border=\"1\"  src=$zipbytes  width=\"600\"  height=\"600\" > ";
								//unlink($zipbytes); //unlink($imagepath);
				    				$zip->close();
								} else {
								    echo 'failed';
								}

								
							}else{
								echo "<embed src=$bytes  width=\"900\"  height=\"600\" >\n";								
								//echo "<img border=\"1\"  src=$zipbytes  width=\"600\"  height=\"600\" > ";
							}

						}

						if ($gfthType=="Photos")
						{
						$dirpdf= $path2Root."/eLibraryPhotos/";
						$dirpdftemp= $path2Root."/eLibraryPhotos/";
						$dirziptemp= $path2Root."/androidapps/frmeLibrary/";
						$bytes = $ffname."eLibraryPhotos/".$mybytes;
							if($zipFlag=="ON")
							{
								$zip = new ZipArchive;
								if ($zip->open($path2Root."/eLibraryPhotos/".$mybytes) === TRUE)
								{
								$zip->extractTo($dirziptemp,array($zip->getNameIndex($zipCount)));
								$zipbytes=$ffname."androidapps/frmeLibrary/".$zip->getNameIndex($zipCount);	
								//echo "<embed src=$zipbytes  width=\"900\"  height=\"600\" >\n";
								echo "<img border=\"1\"  src=$zipbytes  width=\"600\"  height=\"600\" > ";
								//unlink($zipbytes); //unlink($imagepath);
				    				$zip->close();
								} else {
								    echo 'failed';
								}

								
							}else{
								//echo "<embed src=$bytes  width=\"900\"  height=\"600\" >\n";								
								echo "<img border=\"1\"  src=$bytes  width=\"600\"  height=\"600\" > ";
							}

						}

						if ($gfthType=="Slides")
						{
						$dirpdf= $path2Root."/eLibrarySlides/";
						$dirpdftemp= $path2Root."/eLibrarySlides/";
						$dirziptemp= $path2Root."/androidapps/frmeLibrary/";
						$bytes = $ffname."eLibrarySlides/".$mybytes;
							if($zipFlag=="ON")
							{
								$zip = new ZipArchive;
								if ($zip->open($path2Root."/eLibrarySlides/".$mybytes) === TRUE)
								{
								$zip->extractTo($dirziptemp,array($zip->getNameIndex($zipCount)));
								$zipbytes=$ffname."androidapps/frmeLibrary/".$zip->getNameIndex($zipCount);	
								//echo "<embed src=$zipbytes  width=\"900\"  height=\"600\" >\n";
								echo "<img border=\"1\"  src=$zipbytes  width=\"700\"  height=\"900\" > ";
								//unlink($zipbytes); //unlink($imagepath);
				    				$zip->close();
								} else {
								    echo 'failed';
								}

								
							}else{
								//echo "<embed src=$bytes  width=\"900\"  height=\"600\" >\n";								
								echo "<img border=\"1\"  src=$bytes  width=\"600\"  height=\"600\" > ";
							}

						}

						if ($gfthType=="myDocuments")
						{
						$dirpdf= $path2Root."/eLibraryAudios/";
						$dirpdftemp= $path2Root."/eLibraryAudios/";
						$bytes = $ffname."eLibraryDocuments/".$mybytes;
 								echo "&nbsp<embed src=$bytes>\n";
						}



			}else{
			$mysrc="eLibraryImages/$dirOption";			
			//echo "<img border=\"0\"  src=$ffname$mysrc  width=\"400\"  height=\"600\" > ";
 			echo "&nbsp<embed src=$ffname$mysrc>\n";
			}
		}

//========================================== Begin Display Books =======================================================

		if ($gOption=="DisplayBook")
		{


			mysqli_select_db($connect,"$myjaiveDBname2") or die ('did not find db'.mysql_error());
			$result5=mysqli_query($connect,"SELECT*  FROM elibrary WHERE eFilePath='$dirOption'");
			while($row5 = mysqli_fetch_array($result5))
			{
			$eBookName=$row5["eBookName"];
 			$BookSummary=$row5["eDescription"];
			$erprice=$row5["erprice"];
			$elPrice=$row5["elPrice"];
			$ebPrice=$row5["ebPrice"];
			$epPrice=$row5["epPrice"];
			$AuthorName=$row5["eAuthorName"];
			$PublisherName=$row5["ePublisherName"];
			$eBookISBN=$row5["eBookISBN"];
			}


						echo "<table text=\"#ffffff\" border=\"0\" align=\"center\" cellpadding=\"6\"   id=\"table2\"  style=\"border-collapse: collapse; color:#000000; background-color:#ffffff\" > ";
						echo "<tr>";

						echo "<td   height=\"500\" width=\"500\" align=\"left\" valign=\"bottom\" >";

						echo "<button name=\"B12\"  style=\"width: 105; color:#000000; color:$ButtonTXT2; background-color:$ButtonBG2\" > Title</button>";
						echo "<br>$eBookName";
						//echo "<br><input type=\"text\"  value=\"$eBookName\"  name=\"eBookName\"  style=\"width: 100; background-color:#FFffff\" >";

						echo "<p>";
						echo "<button name=\"B12\"  style=\"width: 105; color:#000000; color:$ButtonTXT2; background-color:$ButtonBG2\" > Author</button>";
						echo "<br>$AuthorName";
						//echo "<br><input type=\"text\"  value=\"$AuthorName\"  name=\"AuthorName\"  style=\"width: 100; background-color:#FFffff\" >";

						echo "<p>";
						echo "<button name=\"B12\"  style=\"width: 105; color:#000000; color:$ButtonTXT2; background-color:$ButtonBG2\" > Publisher</button>";
						echo "<br>$PublisherName";
						//echo "<br><input type=\"text\"  value=\"$PublisherName\"  name=\"PublisherName\"  style=\"width: 100; background-color:#FFffff\" >";

						echo "<p>";
						echo "<button name=\"B12\"  style=\"width: 105; color:#000000; color:$ButtonTXT2; background-color:$ButtonBG2\" > ISBN</button>";
						echo "<br>$eBookISBN";
						//echo "<br><input type=\"text\"  value=\"$eBookISBN\"  name=\"eBookISBN\"  style=\"width: 100; background-color:#FFffff\" >";

						echo "<p>";
						echo "<button name=\"B12\"  style=\"width: 105; color:#000000; color:$ButtonTXT2; background-color:$ButtonBG2\" > Read Price</button>";
						echo "<br>$erprice";
						//echo "<br><input type=\"text\"  value=\"$erprice\"  name=\"erprice\"  style=\"width: 100; background-color:#FFffff\" >";

						echo "<p>";
						echo "<button name=\"B12\"  style=\"width: 105; color:#000000; color:$ButtonTXT2; background-color:$ButtonBG2\" > Loan Price</button>";
						echo "<br>$elPrice";
						//echo "<br><input type=\"text\"  value=\"$elPrice\"  name=\"elPrice\"  style=\"width: 100; background-color:#FFffff\" >";

						echo "<p>";
						echo "<button name=\"B12\"  style=\"width: 105; color:#000000; color:$ButtonTXT2; background-color:$ButtonBG2\" > Borrow Price</button>";
						echo "<br>$ebPrice";
						//echo "<br><input type=\"text\"  value=\"$ebPrice\"  name=\"ebPrice\"  style=\"width: 100; background-color:#FFffff\" >";

						echo "<p>";
						echo "<button name=\"B12\"  style=\"width: 105; color:#000000; color:$ButtonTXT2; background-color:$ButtonBG2\" > Purchase</button>";
						echo "<br>$epPrice";
						//echo "<br><input type=\"text\"  value=\"$epPrice\"  name=\"epPrice\"  style=\"width: 100; background-color:#FFffff\" >";
						//echo "<input type=\"submit\"  value=\"-> GoSearch\"  name=\"GoBar\"  style=\"width: 20; color:$ButtonTXT2; background-color:$ButtonBG2; height: 20\">";
					echo "</td>";



						echo "<td   height=\"500\" width=\"500\" align=\"left\" valign=\"bottom\" >";
						$mysrcName=$SearchBookDir;
						$CatName="Collection.".$SearchBookDir;
						$action2="/$forms/frmeLibrary/frmDisplayeLibraryPortraitSmall.php?Collection=$mysrcName, $CatName";	
						$myPath=$ffname."eLibraryImages/".$SearchBookDir;	
						echo "<a href=\"$action2\">";
						//echo "<img title=\"$SearchBookPath\" border=\"0\"  src=$SearchBookPath width=\"500\"  height=\"500\" > ";
						//echo "<img title=\"$SearchBookDir\" border=\"0\"  src=$ffname$SearchBookDir width=\"500\"  height=\"500\" > ";
 						echo "<img title=\"$dirOption\" border=\"0\"  src=$myPath width=\"500\"  height=\"500\" > ";
						//echo "&nbsp<embed src=$SearchBookPath>\n";
						echo "</a>\n";
					echo "</td>";


						echo "<td   height=\"500\" width=\"100\" align=\"left\" valign=\"bottom\" >";
						echo "&nbsp&nbsp&nbsp<textarea name=\"BookSummary\" style=\"width:200; height :500\">$BookSummary</textarea>";
					echo "</td>";
						echo "</tr>";
						echo "</table>";


		}

//=================================================== Begin Show Book =====================================================
	if ($ColOption=="ShowBook")
		{

			mysqli_select_db($connect,"$myjaiveDBname2") or die ('did not find db'.mysql_error());
			//$result5=mysqli_query($connect,"SELECT*  FROM elibrary WHERE eFilePath='$dirOption'");
			$result5=mysqli_query($connect,"SELECT*  FROM elibrary");
			while($row5 = mysqli_fetch_array($result5))
			{
				$eFilePath=$row5["eFilePath"];
		//echo "   eFilePath:".$eFilePath;
				if($dirOption==$eFilePath)
				{
				$eBookName=$row5["eBookName"];
	 			$BookSummary=$row5["eDescription"];
				$erprice=$row5["erPrice"];
				$elPrice=$row5["elPrice"];
				$ebPrice=$row5["ebPrice"];
				$epPrice=$row5["epPrice"];
				$AuthorName=$row5["eAuthorName"];
				$PublisherName=$row5["ePublisherName"];
				$eBookISBN=$row5["eBookISBN"];
				$ebPrice=$epPrice+($epPrice*.4);
		//echo "   BookSummary1:".$BookSummary;
				}			     				
			}

	//echo "   BookSummary2:".$BookSummary;			     				

						echo "<table text=\"#ffffff\" border=\"0\" align=\"center\" cellpadding=\"6\"   id=\"table2\"  style=\"border-collapse: collapse; color:#000000; background-color:#ffffff\" > ";
						echo "<tr>";
						echo "<td   height=\"500\" width=\"100\" align=\"left\" valign=\"bottom\" >";

						echo "<button name=\"B12\"  style=\"width: 105; color:#000000; color:$ButtonTXT2; background-color:$ButtonBG2\" > Title</button>";
						echo "<br>$eBookName";
						//echo "<br><input type=\"text\"  value=\"$eBookName\"  name=\"eBookName\"  style=\"width: 100; background-color:#FFffff\" >";

						echo "<p>";
						echo "<button name=\"B12\"  style=\"width: 105; color:#000000; color:$ButtonTXT2; background-color:$ButtonBG2\" > Author</button>";
						echo "<br>$AuthorName";
						//echo "<br><input type=\"text\"  value=\"$AuthorName\"  name=\"AuthorName\"  style=\"width: 100; background-color:#FFffff\" >";

						echo "<p>";
						echo "<button name=\"B12\"  style=\"width: 105; color:#000000; color:$ButtonTXT2; background-color:$ButtonBG2\" > Publisher</button>";
						echo "<br>$PublisherName";
						//echo "<br><input type=\"text\"  value=\"$PublisherName\"  name=\"PublisherName\"  style=\"width: 100; background-color:#FFffff\" >";

						echo "<p>";
						echo "<button name=\"B12\"  style=\"width: 105; color:#000000; color:$ButtonTXT2; background-color:$ButtonBG2\" > ISBN</button>";
						echo "<br>$eBookISBN";
						//echo "<br><input type=\"text\"  value=\"$eBookISBN\"  name=\"eBookISBN\"  style=\"width: 100; background-color:#FFffff\" >";

						echo "<p>";
						$mysrcName=$dirOption;
						$CatName="Read.".$dirOption;
						$action2="/$forms/frmeLibrary/frmDisplayeLibraryPortraitSmall.php?Collection=$mysrcName, $CatName";
						echo "<a href=\"$action2\"><input type=\"button\"  value=\"Read Price\" title=\"Go to Easy Subcription\" name=\"B12\"  style=\"width: 105; color:#000000; color:$ButtonTXT2; background-color:$ButtonBG2\" ></button></a>\n";
						//echo "<button name=\"B12\"  style=\"width: 105; color:#000000; color:$ButtonTXT2; background-color:$ButtonBG2\" > Read Price</button>";
						echo "<br>$erprice";
						//echo "<br><input type=\"text\"  value=\"$erprice\"  name=\"erprice\"  style=\"width: 100; background-color:#FFffff\" >";

						echo "<p>";
						$mysrcName=$dirOption;
						$CatName="Loan.".$dirOption;
						$action2="/$forms/frmeLibrary/frmDisplayeLibraryPortraitSmall.php?Collection=$mysrcName, $CatName";
						echo "<a href=\"$action2\"><input type=\"button\"  value=\"Loan Price\" title=\"Go to Easy Subcription\" name=\"B12\"  style=\"width: 105; color:#000000; color:$ButtonTXT2; background-color:$ButtonBG2\" ></button></a>\n";
						//echo "<button name=\"B12\"  style=\"width: 105; color:#000000; color:$ButtonTXT2; background-color:$ButtonBG2\" >Loan Price</button>";
						echo "<br>$elPrice";
						//echo "<br><input type=\"text\"  value=\"$elPrice\"  name=\"elPrice\"  style=\"width: 100; background-color:#FFffff\" >";

						echo "<p>";
						$mysrcName=$dirOption;
						$CatName="HardCopy.".$dirOption;
						$action2="/$forms/frmeLibrary/frmDisplayeLibraryPortraitSmall.php?Collection=$mysrcName, $CatName";
						echo "<a href=\"$action2\"><input type=\"button\"  value=\"Hard Copy\" title=\"Go to Easy Subcription\" name=\"B12\"  style=\"width: 105; color:#000000; color:$ButtonTXT2; background-color:$ButtonBG2\" ></button></a>\n";					
						//echo "<button name=\"B12\"  style=\"width: 105; color:#000000; color:$ButtonTXT2; background-color:$ButtonBG2\" > Hard Copy</button>";
						echo "<br>$ebPrice";
						//echo "<br><input type=\"text\"  value=\"$ebPrice\"  name=\"ebPrice\"  style=\"width: 100; background-color:#FFffff\" >";

						echo "<p>";
						$mysrcName=$dirOption;
						$CatName="SoftCopy.".$dirOption;
						$action2="/$forms/frmeLibrary/frmDisplayeLibraryPortraitSmall.php?Collection=$mysrcName, $CatName";
						//$myPath=$ffname."eLibraryImages/".$dirOption;	
						//echo "<a href=\"$action2\"><input type=\"button\"  value=\"Subcription Bal\" title=\"Go to Easy Subcription\" name=\"B12\"  style=\"width: 105; color:#000000; color:$ButtonTXT2; background-color:$ButtonBG2\" ></a>\n";
						echo "<a href=\"$action2\"><input type=\"button\"  value=\"Soft Copy\" title=\"Go to Easy Subcription\" name=\"B12\"  style=\"width: 105; color:#000000; color:$ButtonTXT2; background-color:$ButtonBG2\" ></button></a>\n";
						echo "<br>$epPrice";
						
						echo "<p>";
						$mysrcName=$dirOption;
						$CatName="Subscription.".$dirOption;
						$action2="/$forms/frmeLibrary/frmDisplayeLibraryPortraitSmall.php?Collection=$mysrcName, $CatName";
						//$myPath=$ffname."eLibraryImages/".$dirOption;	
						echo "<a href=\"$action2\"><input type=\"button\"  value=\"Subcription Bal\" title=\"Go to Easy Subcription\" name=\"B12\"  style=\"width: 105; color:#000000; color:$ButtonTXT2; background-color:$ButtonBG2\" ></a>\n";						
						echo "<br>$SubBalance";						
						//echo "<br><input type=\"text\"  value=\"$epPrice\"  name=\"epPrice\"  style=\"width: 100; background-color:#FFffff\" >";
						//echo "<input type=\"submit\"  value=\"-> GoSearch\"  name=\"GoBar\"  style=\"width: 20; color:$ButtonTXT2; background-color:$ButtonBG2; height: 20\">";
					echo "</td>";


					echo "<td   height=\"500\" width=\"100\" align=\"left\" valign=\"bottom\" >";
						$mysrcName=$dirOption;
						$CatName="Collection.".$dirOption;
						$action2="/$forms/frmeLibrary/frmDisplayeLibraryPortraitSmall.php?Collection=$mysrcName, $CatName";
						$myPath=$ffname."eLibraryImages/".$dirOption;	
						//echo "<a href=\"$action2\">";
						echo "<img title=\"$dirOption\" border=\"0\"  src=$myPath width=\"500\"  height=\"500\" > ";
						//echo "</a>\n";
					echo "</td>";

						echo "<td   height=\"500\" width=\"100\" align=\"left\" valign=\"bottom\" >";
						echo "&nbsp&nbsp&nbsp<textarea name=\"BookSummary\" style=\"width:200; height :500\">$BookSummary</textarea>";
					echo "</td>";
						echo "</tr>";
						echo "</table>";



		}

		if ($gOption=="-> GoSearch")
		{

		if(isset($_POST['SearchBook']))
			{
			$arSearchBook=array();
			$SearchBook= $_POST['SearchBook'];
			//$_SESSION['sCategoryCode']=$CategoryCode;
				$NumberOfBooks=0;
				$BooksCounted=0;

				$dotting=".";
				$bcount=0;
				mysqli_select_db($connect,"$myjaiveDBname2") or die ('did not find db'.mysql_error());
				$result5=mysqli_query($connect,"SELECT*  FROM elibrary");
				while($row5 = mysqli_fetch_array($result5))
				{
 				$NumberOfBooks=0;
				preg_match("/$SearchBook/i",$row5["eBookName"],$arMatch);
				$NumberOfBooks=count($arMatch);
					if($NumberOfBooks>=1){
					$arSearchBook[$bcount]=$row5["eCollectionName"].$dotting.$row5["eCategoryName"].$dotting.$row5["eDeptName"].$dotting.$row5["eBookName"].$row5["ePageExtCode"];
					$bcount++;
					}
				}
				//preg_match("/$SearchBook/i",$arSearchBook,$arMatch);
				//$arMatch=array_intersect($arSearchBook,$SearchBook);
				$BooksCounted=count($arSearchBook);

					if($BooksCounted>=1){
						for($ffg=0; $ffg<=$BooksCounted-1; $ffg++){
						$mysrcName=$arSearchBook[$ffg];
						$CatName="Collection.".$arSearchBook[$ffg];
						$action2="/$forms/frmeLibrary/frmDisplayeLibraryPortraitSmall.php?Collection=$mysrcName, $CatName";	
						echo "<a href=\"$action2\">";
						$mysrc=$arSearchBook[$ffg];
						$mysrc=preg_replace('/\s/','',$mysrc);
						$mysrc="eLibraryImages/$mysrc";
						echo "<img title=\"$mysrc\" border=\"0\"  src=$ffname$mysrc  width=\"100\"  height=\"100\" > ";
						echo "</a>\n";
						}
					}

			}


		}

			echo "</td>";
			echo "</tr>";
		    
			//echo "</td>";
			
		//	if($advanceFlag=="OFF")
		//	{
		//	echo "<td   width=\"5%\" > ";
		//	echo "<input type=\"submit\"  value=\"Close\"  name=\"GoBar\"  style=\"height: 40; width: 70;  color:$ButtonTXT2; background-color:$ButtonBG2\" >";
		//	echo "</td>";
		//	}



		    //echo "</tr>";		


	echo "</table>";
//============================================ End Main Library Display===============================================================
	
//echo "</div>";

//=========================================== Begin Footer Library Graphics Bar================================================

echo "</form>\n";
//echo "</center>";

?>