<?php session_start(); ?>
<?php
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // Date in the past
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified
header("Cache-Control: no-store, no-cache, must-revalidate"); // HTTP/1.1
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache"); // HTTP/1.0
?>
<?php 
$nazwapliku="wyszukiwarkaen.php?wysz=1&jez=en";

$wysz=$_GET['wysz'];

if (!$jez || $jez=="en") include "db-en.php";
 ?>
<?php 
$displayRecs = 1000;
$recRange = 10;

// Get table name
$b_search = "";
if ($HTTP_GET_VARS["psearch"]!="")
{
    $dbwhere="";
}
?>
<?php 
// Get search criteria for basic search
$pSearch = @$HTTP_GET_VARS["psearch"];
$Rodzaj = $_GET["rodzaj"];
if ($pSearch != "")
	{
		$pSearch = (!get_magic_quotes_gpc()) ? addslashes($pSearch) : $pSearch;

		if ($Rodzaj == "Author")
  		{	
            	$b_search .= "nazwisko LIKE '".$pSearch."' OR ";
  		}
 

		else
		{
	   	$b_search .= "artykuly.tytul LIKE '".$pSearch."' OR ";
	        }	
} 

if (strlen($b_search) > 4)
{
	$b_search = substr($b_search, 0, strlen($b_search)-4);
	$b_search = "(".$b_search.")";
} 

?>
<?php 
   
//Build search criteria

  if ($b_search!="") 
  {
	$dbwhere .= $b_search; //basic search
}

//Save search criteria
if ($dbwhere != "")
{
    $HTTP_SESSION_VARS["dbwhere"] = $dbwhere;
	//reset start record counter
    $startRec = 1;
    $HTTP_SESSION_VARS["artykuly_REC"] = $startRec;
} 
else {     
	$dbwhere =@$HTTP_GET_VARS["dbwhere"];
    } 


//Get clear search cmd
$cmd = @$HTTP_GET_VARS["cmd"];
if (strtoupper($cmd)=="RESET")
{
	//reset search criteria
	 $dbwhere = "";
	 $HTTP_SESSION_VARS["dbwhere"] = $dbwhere;
} 
?>
<?php 
// Load Default Order
$DefaultOrder = "";
$DefaultOrderType = "";

// Check for an Order parameter
$OrderBy = @$HTTP_GET_VARS["order"];

if ($OrderBy != "")
{	
	// Check if an ASC/DESC toggle is required
	if ($HTTP_SESSION_VARS["artykuly_OB"] == $OrderBy)
	{	
		if ($HTTP_SESSION_VARS["artykuly_OT"] == "ASC")
		{		
			$HTTP_SESSION_VARS["artykuly_OT"] = "DESC";
		} else {
			$HTTP_SESSION_VARS["artykuly_OT"] = "ASC";
		} 
	} else {
		$HTTP_SESSION_VARS["artykuly_OT"] = "ASC";
	}
	$HTTP_SESSION_VARS["artykuly_OB"] = $OrderBy;
	$HTTP_SESSION_VARS["artykuly_REC"] = 1;
} else {	
	$OrderBy = @$HTTP_SESSION_VARS["artykuly_OB"];
	if ($OrderBy == "")
	{
		$OrderBy = $DefaultOrder;
		$HTTP_SESSION_VARS["artykuly_OB"] = $OrderBy;
		$HTTP_SESSION_VARS["artykuly_OT"] = $DefaultOrderType;
	}
} 

// Check for a START parameter
$startRec = @$HTTP_GET_VARS["start"];

if ($startRec != "")
{
	$HTTP_SESSION_VARS["artykuly_REC"] = $startRec;
} else {
	$startRec = @$HTTP_SESSION_VARS["artykuly_REC"];
	if ($startRec == "")
	{
		//reset start record counter
	  	$startRec = 1;
	  	$HTTP_SESSION_VARS["artykuly_REC"] = $startRec;
	}
} 

//Set the last record to display
$stopRec = $startRec + $displayRecs - 1;

// Open Connection to the database
$conn = mysql_connect(HOST, USER, PASS);
mysql_select_db(DB);

// Build Query
$strsql = "SELECT artykuly.*,artykulautor.*,autorzy.*, wydawnictwa.tytul as a, wydawnictwa.skrot, wydawnictwa.wydid FROM artykuly LEFT JOIN artykulautor USING (artid) LEFT JOIN autorzy USING (autorid) LEFT JOIN wydawnictwa ON artykuly.wydid=wydawnictwa.wydid";

if ($dbwhere != "")
{
	$strsql .= " WHERE ".$dbwhere;
  
} 
else
{
$strsql.= " WHERE NAZWISKO=''";
}
if ($OrderBy != "")
{
	$strsql .= " ORDER BY `".$OrderBy."` ".@$HTTP_SESSION_VARS["artykuly_OT"];
} 

$rs = mysql_query($strsql, $conn) or die(mysql_error());

$totalRecs = mysql_num_rows($rs);
?>
<META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=utf-8">
<body bgcolor=#CCFFFF leftmargin=0 topmargin=0 marginheight=0 marginwidth=0>
<div align="center" border=0>
 <center>
 <table border="0" width="900" height="1">
 <tr>
 <td border="0" width="900" height="1">
 <div align="center">
 <center>
 <table border="0" width="900" height="1" >
 <tr>
 <td width="150" height="1" bgcolor="#CCFFFF" bordercolor="#CCFFFF" align="left">
 <p align="center"><img border="0" src="rysunki/ICM.GIF" align="right" width="129" height="82"></td>
 <td width="700" height="1" colspan="2" bgcolor="#CCFFFF" bordercolor="#CCFFFF" align="center">
 <h1>&nbsp;</h1>
 </center>
 </center>
 <h3 align="center">&nbsp;&nbsp;&nbsp;&nbsp;<? echo $biblioteka ; ?></h3>
 <h1 align="center">&nbsp;&nbsp;&nbsp;&nbsp;<? echo $kolekcja; ?></h1>
 <center>
 <center>
 <p></p>
 </center></center></td>
 <td width="50" height="1" bgcolor="#CCFFFF" bordercolor="#CCFFFF" align="center"><a href="wyszukiwarkaen.php"><img border="2" src="rysunki/anglia.svg" width="50" height="25"></a></br></br><a href="wyszukiwarkapl.php"><img border="2" src="rysunki/polska.svg" align="top" width="50" height="25"></a></td>

 </tr>
  <tr>
 <td width="800" height="1" colspan="4" bgcolor="#CCFFFF" bordercolor="#CCFFFF">
  <hr color="#000080" size="5">
 <p>&nbsp;</td>
  </tr>


  </table>

<table width="100%" height="100%" border="0" cellspacing="0" cellpadding="10">
<tr align="center">
 <td colspan="2"><font size="-1"><strong></strong></font></td>
</tr>
	<tr>
		<!-- left column -->
<td width="20%" height="100%" valign="top">

<table width="100%" border="0" cellspacing="2" cellpadding="2">
<tr>
<td>
				
<div>
<table border="1">

<tr align="center">
<td><strong><font size="1"><? echo $znak; ?></font></strong></td>
<td><strong><font size="1"><? echo $opis; ?></font></strong></td>
</tr>
<tr>
<td align="center"><big >%</big></td>
<td><font size="1"><? echo $procent; ?></font></td>
</tr>
<tr>
<td align="center"><big>_</big></td>
<td><font size="1"><? echo $podkreslenie; ?></font></td>
</tr>
</table></div><br><br></td></tr>	
			</table>
		</td>
		<!-- right column -->
		<td width="80%" valign="top">

<p>&nbsp;

<form action="wyszukiwarkaen.php">
<table border="0" cellspacing="1" cellpadding="4">
	<tr>		
		<td colspan=3><b><? echo $szukaj ?> articles</b></font></td>
</tr>
<tr>
		<td colspan=3>
		<input type="Text" name="psearch" size=15>
    <SELECT NAME="rodzaj">
    <OPTION value="Title"> Title </Option>
    <OPTION SELECTED value="Author"> Author </Option>
    </SELECT> 

		<input type="Submit" name="Submit" value="<? echo $szukaj ?>">
		</td>
</tr>
<tr>
		<td><a href="wyszukiwarkaen.php?"><font size="-1"><? echo $wyczysc ?></font></a></td>
	<td>&nbsp;&nbsp;&nbsp;<a href="index.php?jez=en"><font size="-1"><? echo $powrot ?></a></td>
	<td>&nbsp;&nbsp;&nbsp;<a href="wyszukiwarka-ksen.php"><font size="-1"><? echo $szukaj ?> books</font></a></td>
	</tr>
</table>

<p>&nbsp;
</form>
</td>

</tr>

<tr vlign=top>
<td colspan="2">




<form>
<table width="1000" border="0" cellspacing="1" cellpadding="5" bgcolor="#CCCCCC" vlign=top>
<tr bgcolor="#0099CC">
<td>
<a href="wyszukiwarkaen.php?order=<?php echo urlencode("a"); ?>&jez=en"><font color="#FFFFFF"><font size="-1"><? echo $ewydawnictwo; ?>&nbsp;</font></font></a>
</td>
<td>
<a href="wyszukiwarkaen.php?order=<?php echo urlencode("TOM"); ?>&jez=en"><font color="#FFFFFF"><font size="-1"><? echo $etomy; ?>&nbsp;</font></font></a>
</td>
<td>
<a href="wyszukiwarkaen.php?order=<?php echo urlencode("NAZWISKO"); ?>&jez=en"><font color="#FFFFFF"><font size="-1"><? echo $enazwisko; ?>&nbsp;</font></font></a>
</td>
<td>
<a href="wyszukiwarkaen.php?order=<?php echo urlencode("TYTUL"); ?>&jez=en"><font color="#FFFFFF"><font size="-1"><? echo $etytul; ?>&nbsp;</font></font></a>
</td>

</tr>
<?php
$recCount = $startRec - 1;
@mysql_data_seek($rs, $recCount);
while (($row = mysql_fetch_assoc($rs)) && ($recCount < $stopRec))
{
	$recCount++;
	if (intval($recCount) >= intval($startRec))
    {
		//set row color
		$bgcolor="#FFFFFF";
?>
<?php 
		// Display alternate color for rows
		if ($recCount % 2 != 0)
		{
			$bgcolor = "#A5F5A5";
		} 
?>
<?php 
$x_ImieNazwisko = $row["NAZWISKO"]." ".mb_substr($row["IMIE"],0,1).".";
$x_LINK = $row["a"];
$x_TOM = $row["TOM"];

//wstawienie na poczatek zera w 1-9
   $p=$r="0";
   if ($row["TOM"]<10) $p.=$row["TOM"]; else $p=$row["TOM"];
   if ($row["LINK"]<10) $r.=$row["LINK"]; else $r=$row["LINK"];
   
 
?>
<tr bgcolor="<?php echo $bgcolor; ?>">
<td><font size="-1">
<?php echo '<a href="spis.php?wyd='.$row[WYDID].'&jez='.en.'">'.$x_LINK.'</a>&nbsp;'; ?>
</font></td>
<td><font size="-1">
<?php echo '<a href="tresc.php?wyd='.$row[WYDID].'&tom='.$x_TOM.'&jez='.en.'">'.$x_TOM.'</a>&nbsp;'; ?>&nbsp;
</font></td>
<td><font size="-1">
<?php echo $x_ImieNazwisko ?>&nbsp;
</font></td>
<td><font size="-1">
<?php 
 echo '<a href="http://matwbn.icm.edu.pl/ksiazki/'.$row[skrot].'/'.$row[skrot],$row[TOM].'/'.$row[skrot],$row[TOM],$row[ZESZYT],$row[LINK].'.pdf">',stripslashes($row[TYTUL]), '</a>';
?>

&nbsp;
</font></td>

</tr>
<?php
	}
}

mysql_free_result($rs);
mysql_close($conn);
?>
</table>
</form>
<?php 
if ($totalRecs > 0)
{
	// Find out if there should be Backward or Forward Buttons on the table.
	if ($startRec == 1)
	{
		 $isPrev = false;
	} else	{	
		$isPrev = true;
		$PrevStart = $startRec - $displayRecs;
		if ($PrevStart < 1)
		{
			$PrevStart = 1;
		}
?>
	<hr size="1" noshade>
	<strong><a href="wyszukiwarkaen.php?start=<?php echo $PrevStart; ?>&jez=en"><font size="-1">[&lt;&lt;&nbsp;<? echo $poprzednie; ?>]</font></a></strong>
<?php 
	}

	// Display Page numbers
    if ($isPrev||(!($totalRecs == 0)))
    {
      	if (!$isPrev)
      	{
?>
	<hr size="1" noshade>
<?php
		}

		$x = 1;
      	$y = 1;

      	$dx1 = intval(($startRec - 1)/($displayRecs*$recRange))*$displayRecs*$recRange + 1;
     	$dy1 = intval(($startRec - 1)/($displayRecs*$recRange))*$recRange + 1;
      	if (($dx1 + $displayRecs*$recRange - 1) > $totalRecs)
		{		
			$dx2 = intval($totalRecs/$displayRecs)*$displayRecs + 1;
			$dy2 = intval($totalRecs/$displayRecs) + 1;
		} else {
			$dx2 = $dx1 + $displayRecs*$recRange - 1;
		  	$dy2 = $dy1 + $recRange - 1;
		} 


		while ($x <= $totalRecs)
      	{
			if (($x >= $dx1)&&($x <= $dx2))
        	{
          		if (intval($startRec) == intval($x))
          		{
?>
	<strong><font size="-1"><?php echo $y; ?></font></strong>
<?php
				} else {
?>
	<strong><a href="wyszukiwarkaen.php?start=<?php echo $x; ?>&jez=en"><font size="-1"><?php echo $y; ?></font></a></strong>
<?php
				} 
         		$x = $x + $displayRecs;
          		$y = $y + 1;
        	} elseif (($x >= ($dx1 - $displayRecs*$recRange))&&($x <= ($dx2 + $displayRecs*$recRange)))
        	{

	          	if ($x + $recRange*$displayRecs < $totalRecs)
	          	{
?>
		<strong><a href="wyszukiwarkaen.php?start=<?php echo $x; ?>&jez=en"><font size="-1"><?php echo $y; ?>-<?php echo $y + $recRange - 1; ?></font></a></strong>
<?php
				} else {
		            $ny = intval(($totalRecs - 1)/$displayRecs) + 1;
					if ($ny == $y)
		            {
	?>
		<strong><a href="wyszukiwarkaen.php?start=<?php echo $x; ?>&jez=en"><font size="-1"><?php echo $y; ?></font></a></strong>
	<?php
					} else {
	?>
		<strong><a href="wyszukiwarkaen.php?start=<?php echo $x; ?>&jez=en"><font size="-1"><?php echo $y; ?>-<?php echo $ny; ?></font></a></strong>
	<?php
					} 
				}	
	          	$x = $x + $recRange*$displayRecs;
	          	$y = $y + $recRange;
	        } else {
	          	$x = $x + $recRange*$displayRecs;
	          	$y = $y + $recRange;
	        } 
		} 
	} 

	// Next link
    if ($totalRecs >= $startRec + $displayRecs)
    {
		$NextStart = $startRec + $displayRecs;
		$isMore = true;
 ?>
	<strong><a href="wyszukiwarkaen.php?start=<?php echo $NextStart; ?>&jez=en"><font size="-1">[<? echo $nastepne; ?>&nbsp;&gt;&gt;]</font></a></strong>
<?php
	} else {
		$isMore=false;
    }
 ?>
	<hr size="1" noshade>
<?php
	if ($stopRec > $recCount)
    {
    $stopRec = $recCount;
	}
 ?>
	<font size="-1"><?php echo $eartykuly; ?> <?php echo $startRec." ".$do." "; echo $stopRec; ?> <?php echo $z." ".$totalRecs; ?></font>
<?php
} else {
?>
<br><br>
<font size="-1"><? echo $braka; ?></font>
<br><br>
<?php
}
?>

			<p>&nbsp;</p>
		</td>
	</tr>
</table>
</body>
</html>
