summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJon Doe <you@example.com>2013-03-19 17:38:07 -0400
committerJon Doe <you@example.com>2013-03-19 17:38:07 -0400
commit8179e55fe0df90b3316a88b4f85073c11b43388e (patch)
tree9f7e9ea1227778aa240adf113af2ec0916cbe2fa
parent022f4e34f25216d96c26556b44a4b588ac7f7e67 (diff)
downloadBiblioteka-8179e55fe0df90b3316a88b4f85073c11b43388e.tar.gz
Biblioteka-8179e55fe0df90b3316a88b4f85073c11b43388e.tar.bz2
Biblioteka-8179e55fe0df90b3316a88b4f85073c11b43388e.zip
Poprawion blad przy wyswietlaniu ksiazek,
Dodano informacje o dostepnosci ksiazki i mozliwosci wypozyczenia w postaci Tak/Nie zamiast 0/1
-rwxr-xr-xbin/add_book.pl44
-rwxr-xr-xbin/app.pl3
-rw-r--r--bin/ksiazki.dbbin3072 -> 3072 bytes
-rw-r--r--views/a.tt13
4 files changed, 57 insertions, 3 deletions
diff --git a/bin/add_book.pl b/bin/add_book.pl
index 13cf934..a7364db 100755
--- a/bin/add_book.pl
+++ b/bin/add_book.pl
@@ -9,7 +9,49 @@ use DBI;
my $dbfile = 'ksiazki.db';
my $dbh = DBI->connect("dbi:SQLite:dbname=$dbfile", "", "");
-my$sth=$dbh->prepare("select * from ksiazki where id=(select max(id) from ksiazki)");
+my $sth=$dbh->prepare("select * from ksiazki where id=(select max(id) from ksiazki)");
$sth->execute;
(my @dupa)=$sth->fetchall_arrayref;
my $max_id = ${$dupa[0]}[0][0];
+
+my $id=$max_id+1; #Nowe id tworzymy, biorac stare najwieksze i dodajac 1
+print 'Podaj isbn:';
+my $isbn = <STDIN>;
+chomp $isbn;
+print 'Podaj tytul:';
+my $title = <STDIN>;
+chomp $title;
+$title='\''.$title.'\'';
+print 'Podaj autora:';
+my $author = <STDIN>;
+chomp $author;
+$author = '\''.$author.'\'';
+print 'Podaj wlasciciela:';
+my $owner = <STDIN>;
+chomp $owner;
+$owner = '\''.$owner.'\'';
+print 'Czy ksiazke mozna pozyczac?:';
+my $can_borrow = <STDIN>;
+chomp $can_borrow;
+while (1)
+{
+ if ($can_borrow eq 'Tak')
+ {
+ $can_borrow = 1;
+ last;
+ }
+ elsif ($can_borrow eq 'Nie')
+ {
+ $can_borrow = 0;
+ last;
+ }
+ else
+ {
+ print 'Odpowiedz Tak lub Nie!';
+ $can_borrow = <STDIN>;
+ chomp $can_borrow;
+ }
+}
+$sth=$dbh->prepare("insert into ksiazki values($id,$isbn,$title,$author,$owner,1,$can_borrow)"); #Zakladamy, ze dodawana ksiazka jest na miejscu,
+#wiec zamiast sie o to pytac, wpisuje, ze jest.
+$sth->execute or die 'Blad przy pisaniu do bazy!';
diff --git a/bin/app.pl b/bin/app.pl
index 8a5045b..5b8d7be 100755
--- a/bin/app.pl
+++ b/bin/app.pl
@@ -5,7 +5,8 @@ use Dancer;
use DBI;
#Struktura bazy
-#id, int; isbn, int; tytul, string; autor, string; owner, string; state, bool (czy pozyczona, 0=dostepna, 1=wzieta); type, bool (mozna brac ze soba? 1=tak, 0=nie)
+#id, int; isbn, int; tytul, string; autor, string; owner, string;
+#state, bool (czy pozyczona, 1=dostepna, 0=wzieta); can_borrow, bool (mozna brac ze soba? 1=tak, 0=nie)
my $dbfile = 'ksiazki.db';
my $dbh = DBI->connect("dbi:SQLite:dbname=$dbfile", "", "");
diff --git a/bin/ksiazki.db b/bin/ksiazki.db
index ff6d6ee..f908194 100644
--- a/bin/ksiazki.db
+++ b/bin/ksiazki.db
Binary files differ
diff --git a/views/a.tt b/views/a.tt
index 781a145..6b45fac 100644
--- a/views/a.tt
+++ b/views/a.tt
@@ -6,11 +6,22 @@
<tr><td>id</td><td>isbn</td><td>tytul</td><td>autor</td><td>wlasiciciel</td><td>jest?</td><td>mozna brac?</td></tr>
<tr>
- % for (my $i=0;$i<$#tab;$i++)
+ % for (my $i=0;$i<$#tab+1;$i++)
% {
% for (my $ii=0;$ii<7;$ii++) #Jest 7 pol w kazdym rekordzie
% {
+ % if ($ii==5 || $ii==6)
+ % {
+ % if ($tab[$i][$ii]==1)
+ % {
+ % $tab[$i][$ii] = 'Tak';
+ % }
+ % else
+ % {
+ % $tab[$i][$ii] = 'Nie';
+ % }
+ % }
<td> <%= $tab[$i][$ii] %> </td>
% }
%= "\n"