<?php
require('settings.php');
$db = mysql_connect($dbhost, $dbuser, $dbpass) || die("Zugriff auf Datenbank verweigert: ".mysql_info());
mysql_query("USE $dbname;") || die("Die Datenbank existiert nicht: ".mysql_info());
$sqlBuecher = 'SELECT * FROM Buecher LEFT JOIN Kategorien ON Buecher.Typ=Kategorien.Kat_ID';
if(!($_REQUEST['do'] === 'exp')) // Wenn exportiert werden soll, darf kein Output erfolgen
require('includes/header.inc');
if($_REQUEST['do'] === 'edit') editLabel();
elseif($_REQUEST['do'] === 'exp') exportLabels();
elseif($_REQUEST['do'] === 'del' && !empty($_REQUEST['id'])) {
mysql_query('DELETE FROM Buecher WHERE ID='.$_REQUEST['id'].';')
|| die('Datenbankfehler beim Löschen: '.mysql_error());
listLabels();
}
else listLabels();
function listLabels() // Erzeugt eine Liste der Labels
{
global $sqlBuecher; // Standard-Code für Tabelle Buecher
// Bücher sortieren
$orderby=$_REQUEST['orderby'];
if(empty($orderby)) $orderby = 'Autor';
// Auf bestimmte Anzahl Einträge limitieren
/* $start = $_REQUEST['start'];
$end = $_REQUEST['end'];
if(empty($start)) $start = 0;
if(empty($end)) $end = 30;
$tempend = $end-$start;*/
$neue_buecher = mysql_query($sqlBuecher.' WHERE Neu=1 ORDER BY '.$orderby.';');
//$buecher = mysql_query($sqlBuecher.' ORDER BY '.$orderby.' LIMIT '.$start.', '.$tempend.';');
$buecher = mysql_query($sqlBuecher.' ORDER BY '.$orderby.';');
// Style-Informationen: Wonach wurde sortiert?
if($orderby === 'Titel') $orderTitel = ' class="orderedby"';
elseif($orderby === 'Typ') $orderTyp = ' class="orderedby"';
else $orderAutor = ' class="orderedby"';
// Tabellen-Head anzeigen
echo '<h1>Schulbücherei</h1>'
. '<a href="edit.php?do=edit">'
. '<img src="images/label.gif" alt="Neues Label erstellen" /></a><br />'
. '<form method="POST" name="list">'
. '<input type="hidden" name="do" value="exp">'
. '<table class="list">'
. '<thead>'
. '<tr>'
. '<td> </td>'
. '<td'.$orderAutor.'><a href="edit.php?orderby=Autor">Autor</a></td>'
. '<td'.$orderTitel.'><a href="edit.php?orderby=Titel">Titel</a></td>'
. '<td'.$orderTyp.'><a href="edit.php?orderby=Typ">Medientyp</a></td>'
. '<td> </td>'
. '<td> </td>'
. '</tr>'
. '</thead>'
. '<tbody>';
$i = 0;
while($zeile = mysql_fetch_array($neue_buecher)){
echo '<tr class="row_new">'
. '<td><input type="checkbox" name="exp'.$i.'" value='.$zeile['ID'].' /></td>'
. '<td'.$orderAutor.'>'.$zeile['Autor'].'</td>'
. '<td'.$orderTitel.'>'.$zeile['Titel'].'</td>'
. '<td'.$orderTyp.'>'.$zeile['Kategorie'].'</td>'
. '<td><a href="edit.php?do=edit&id='.$zeile['ID'].'&action=edit">'
. '<img src="images/bearbeiten.gif" alt="Bearbeiten" /></a></td>'
. '<td><a href="edit.php?do=del&id='.$zeile['ID'].'">'
. '<img src="images/loeschen.gif" alt="Löschen" /></a></td>'
. '</tr>';
$i++;
}
$i = 0;
while($zeile = mysql_fetch_array($buecher)){
echo '<tr>'
. '<td><input type="checkbox" name="exp'.$i.'" value='.$zeile['ID'].' /></td>'
. '<td'.$orderAutor.'>'.$zeile['Autor'].'</td>'
. '<td'.$orderTitel.'>'.$zeile['Titel'].'</td>'
. '<td'.$orderTyp.'>'.$zeile['Kategorie'].'</td>'
. '<td><a href="edit.php?do=edit&id='.$zeile['ID'].'&action=edit">'
. '<img src="images/bearbeiten.gif" alt="Bearbeiten" /></a></td>'
. '<td><a href="edit.php?do=del&id='.$zeile['ID'].'">'
. '<img src="images/loeschen.gif" alt="Löschen" /></a></td>'
. '</tr>';
$i++;
}
echo '</tbody>'
. '</table>'
. '<table style="table-layout:fixed;" class="list-bot">'
. '<tr>'
. '<td style="width:25%"><a href="javascript:document.list.submit()">'
. '<img src="images/exportieren.gif" alt="Exportieren" /></a></td>'
. '<td style="width:25%"><a href="edit.php?do=exp&all=new">'
. '<img src="images/neue-exportieren.gif" alt="Neue Exportieren" /></a></td>'
. '<td style="width:25%"><a href="edit.php?do=exp&all=all">'
. '<img src="images/alle-exportieren.gif" alt="Alle Exportieren" /></a></td>'
. '<td style="width:25%"><a href="edit.php">'
. '<img src="images/aktualisieren.gif" alt="Ansicht aktualisieren" /></a></td>'
. '</table>'
. '</form>';
}
function editLabel() // Bearbeitet die Labels, wenn Label nicht existiert, wird es erstellt
{
global $sqlBuecher; // Standard-Code für Tabellen-Import: Buecher
if(!empty($_REQUEST['id'])) { // Wenn ID nicht leer ist => Bearbeitung gewünscht
if (!empty($_REQUEST['autor']) && !empty($_REQUEST['titel']) && !empty($_REQUEST['typ']))
{
mysql_query("UPDATE Buecher
SET Autor='".$_REQUEST['autor']."',Titel='".$_REQUEST['titel']."',Typ='".$_REQUEST['typ']."'
WHERE ID=".$_REQUEST['id'].";")||die('Fehler beim Ändern der Werte'.mysql_error());
listLabels();
}
else
{
$edit_buch = mysql_query($sqlBuecher." WHERE ID=".$_REQUEST['id'].";");
$zeile = mysql_fetch_array($edit_buch);
echoEdit('edit', $zeile['Autor'], $zeile['Titel'], $zeile['ID'], $zeile['Kategorie'], $zeile['Kat_ID']);
}
}
else { // Wenn ID leer ist => Erstellung gewünscht
if (!empty($_REQUEST['autor']) && !empty($_REQUEST['titel']) && !empty($_REQUEST['typ'])) {
mysql_query("INSERT INTO Buecher (Autor,Titel,Typ)
VALUES ('".$_REQUEST['autor']."', '".$_REQUEST['titel']."', '".$_REQUEST['typ']."');")
||die('Fehler beim Eintragen der Werte'.mysql_error());
echoEdit('create');
}
else {
echoEdit('create');
}
}
}
function echoEdit($action='create', $autor='', $titel='', $id='', $kategorie='', $Kat_ID) {
if($action === "edit")
echo '<h1>Bearbeiten: '.$autor.': '.$titel.' ('.$kategorie.')</h1>';
else
echo '<h1>Label erstellen</h1>';
echo '<form action="edit.php" method="POST" name="createLabel">';
if($action === "edit")
echo '<input type="hidden" name="id" value="'.$id.'">';
echo '<input type="hidden" name="do" value="edit">'
. '<table class="createLabel">'
. '<tr><td>Autor:</td><td><input type="text" name="autor" value="'.$autor.'"></td></tr>'
. '<tr><td>Titel:</td><td><input type="text" name="titel" value="'.$titel.'"></td></tr>'
. '<tr><td>Typ:</td>'
. '<td>'.kategories($Kat_ID).'</td>'
. '<tr><td><a href="javascript:document.createLabel.submit()">'
. '<img src="images/speichern.gif" alt="Speichern" /></a></td>'
. '<td><a href="edit.php?do=edit&id='.$id.'&action=delete">'
. '<img src="images/loeschen.gif" alt="Löschen" /></a></td></tr>'
. '</table>'
. '</form>';
}
function Kategories($Kat_ID) // Erzeugt eine Liste der mögl. Kategorien
{
$kategories = mysql_query('SELECT * FROM Kategorien');
$ret = '<select name="typ">';
while($zeile = mysql_fetch_array($kategories)) {
if($Kat_ID === $zeile['Kat_ID']) $sel="selected";
$ret .= '<option value="'.$zeile['Kat_ID'].'" '.$sel.'>'.$zeile['Kategorie'].'</option>';
$sel="";
}
$ret .= '</select>';
return $ret;
}
function exportLabels() // Exportiert die Labels nach PDF
{
global $sqlBuecher; // Standard-Code für Tabellen-Import: Buecher
//fpdf-code
require("fpdf/fpdf.php");
$pdf=new FPDF('P','pt','A4');
$pdf->SetMargins(0, 0, 0);
$pdf->AddPage();
$pdf->SetAutoPageBreak(true, 0);
$pdf->SetFont('Arial','',16);
// Zwischenspeicher
$issecond = false;
$autor = "";
$titel = "";
if($_REQUEST["all"] === "all")
$buecher = mysql_query($sqlBuecher);
elseif($_REQUEST["all"] === "new")
$buecher = mysql_query($sqlBuecher." WHERE Neu=1;");
if(!empty($_REQUEST["all"]))
mysql_query("UPDATE Buecher SET Neu=0;");
for ($i=0; $i<1000; $i++) { // HACK: Es sind max. 1000 Karten möglich!
if(empty($_REQUEST["exp$i"]) && empty($_REQUEST["all"]))
continue;
if(!empty($_REQUEST["exp$i"]))
$buecher = mysql_query($sqlBuecher." WHERE ID=".$_REQUEST["exp$i"].";");
$row = mysql_fetch_array($buecher);
if(empty($row['Autor'])&&empty($row['Titel'])&&empty($row['Typ']))
break;
if(empty($_REQUEST["all"]))
mysql_query("UPDATE Buecher SET Neu=0 WHERE ID=".$row['ID'].";");
// Anfang: Strings splitten
list ($a1, $a2, $a3, $a4, $a5, $a6, $a7, $a8, $a9, $a10) = split('[ ]', $titel, 10);
list ($b1, $b2, $b3, $b4, $b5, $b6, $b7, $b8, $b9, $b10) = split('[ ]', $row['Titel'], 10);
for($i=1; $i <= 10; $i++) {
if($i==1){$temp=$a1.' ';$tit1_teil1='';$tit1_teil2='';}
elseif($i==2)$temp=$a2.' ';
elseif($i==3)$temp=$a3.' ';
elseif($i==4)$temp=$a4.' ';
elseif($i==5)$temp=$a5.' ';
elseif($i==6)$temp=$a6.' ';
elseif($i==7)$temp=$a7.' ';
elseif($i==8)$temp=$a8.' ';
elseif($i==9)$temp=$a9.' ';
elseif($i==10)$temp=$a10.' ';
if(strlen($tit1_teil1.$temp) <= 35)
$tit1_teil1 .= $temp;
else
$tit1_teil2 .= $temp;
}
$tit1_teil2 = trim(substr(substr($tit1_teil1, 35, 70).$tit1_teil2, 0, 35));
$tit1_teil1 = trim(substr($tit1_teil1, 0, 35));
for($i=1; $i <= 10; $i++) {
if($i==1){$temp=$b1.' ';$tit2_teil1='';$tit2_teil2='';}
elseif($i==2)$temp=$b2.' ';
elseif($i==3)$temp=$b3.' ';
elseif($i==4)$temp=$b4.' ';
elseif($i==5)$temp=$b5.' ';
elseif($i==6)$temp=$b6.' ';
elseif($i==7)$temp=$b7.' ';
elseif($i==8)$temp=$b8.' ';
elseif($i==9)$temp=$b9.' ';
elseif($i==10)$temp=$b10.' ';
if(strlen($tit2_teil1.$temp) <= 35)
$tit2_teil1 .= $temp;
else
$tit2_teil2 .= $temp;
}
$tit2_teil2 = trim(substr(substr($tit2_teil1, 35, 70).$tit2_teil2, 0, 35));
$tit2_teil1 = trim(substr($tit2_teil1, 0, 35));
// Ende: Strings splitten
if(!$issecond) {
$autor = $row['Autor'];
$titel = $row['Titel'];
$typ = $row['Kategorie'];
$issecond = true;
}
else {
$pdf->SetFont('Arial','I',13);
$pdf->Cell(297.46,52.618125,'Eigentum der GGS Corneliusstrasse','LRT',0,'C');
$pdf->Cell(297.46,52.618125,'Eigentum der GGS Corneliusstrasse','LRT',1, 'C');
$pdf->SetFont('Arial','U',13);
$pdf->Cell(297.46,26.3090625,' Titel:','LR',0);
$pdf->Cell(297.46,26.3090625,' Titel:','LR',1);
$pdf->SetFont('Arial','',16);
$pdf->Cell(297.46,26.3090625,' '.$tit1_teil1,'LR',0);
$pdf->Cell(297.46,26.3090625,' '.$tit2_teil1,'LR',1);
$pdf->Cell(297.46,26.3090625,' '.$tit1_teil2,'LR',0);
$pdf->Cell(297.46,26.3090625,' '.$tit2_teil2,'LR',1);
$pdf->SetFont('Arial','U',13);
$pdf->Cell(297.46,26.3090625,' Autor:','LR',0);
$pdf->Cell(297.46,26.3090625,' Autor:','LR',1);
$pdf->SetFont('Arial','',16);
$pdf->Cell(297.46,26.3090625,' '.$autor,'LR',0);
$pdf->Cell(297.46,26.3090625,' '.$row['Autor'],'LR',1);
$pdf->SetFont('Arial','B',16);
$pdf->Cell(297.46,26.3090625,' '.$typ,'LRB',0,'C');
$pdf->Cell(297.46,26.3090625,' '.$row['Kategorie'],'LRB',1,'C');
$autor = "";
$titel = "";
$typ = "";
$issecond = false;
}
}
if(!empty($titel) || !empty($autor)) {
// Anfang: Strings splitten
list ($a1, $a2, $a3, $a4, $a5, $a6, $a7, $a8, $a9, $a10) = split('[ ]', $titel, 10);
for($i=1; $i <= 10; $i++) {
if($i==1){$temp=$a1.' ';$tit1_teil1='';$tit1_teil2='';}
elseif($i==2)$temp=$a2.' ';
elseif($i==3)$temp=$a3.' ';
elseif($i==4)$temp=$a4.' ';
elseif($i==5)$temp=$a5.' ';
elseif($i==6)$temp=$a6.' ';
elseif($i==7)$temp=$a7.' ';
elseif($i==8)$temp=$a8.' ';
elseif($i==9)$temp=$a9.' ';
elseif($i==10)$temp=$a10.' ';
if(strlen($tit1_teil1.$temp) <= 35)
$tit1_teil1 .= $temp;
else
$tit1_teil2 .= $temp;
}
$tit1_teil2 = trim(substr(substr($tit1_teil1, 35, 70).$tit1_teil2, 0, 35));
$tit1_teil1 = trim(substr($tit1_teil1, 0, 35));
// Ende: Strings splitten
$pdf->SetFont('Arial','I',13);
$pdf->Cell(297.46,52.618125,'Eigentum der GGS Corneliusstrasse','LRT',2, 'C');
$pdf->SetFont('Arial','U',13);
$pdf->Cell(297.46,26.3090625,' Titel:','LR',2);
$pdf->SetFont('Arial','',16);
$pdf->Cell(297.46,26.3090625,' '.$tit1_teil1,'LR',2);
$pdf->Cell(297.46,26.3090625,' '.$tit1_teil2,'LR',2);
$pdf->SetFont('Arial','U',13);
$pdf->Cell(297.46,26.3090625,' Autor:','LR',2);
$pdf->SetFont('Arial','',16);
$pdf->Cell(297.46,26.3090625,' '.$autor,'LR',2);
$pdf->SetFont('Arial','B',16);
$pdf->Cell(297.46,26.3090625,' '.$typ,'LRB',2,'C');
}
$pdf->Output("Export.pdf", "I");
}
if(!($_REQUEST['do'] === 'exp')) {
require('includes/edit_buttons.inc');
require('includes/overall_footer.inc');
}