OSDN Git Service

show 2pages in desktop mode.
[libre10/libre10.git] / pdfmanager.pl
index 335fa11..183d0e6 100755 (executable)
@@ -1,6 +1,6 @@
 #!/usr/bin/perl
 use utf8;
-use strict;
+#use strict;
 use warnings;
 use CGI;
 use CGI::Carp qw(fatalsToBrowser);
@@ -10,7 +10,7 @@ use Data::Dumper;
 use Encode 'decode';
 use File::Slurp;
 use YAML::XS;
-
+use URI::Escape;
 #
 #   Libre10
 #
@@ -36,7 +36,7 @@ my $temppath = "/tmp/libre10/tmp" . generate_unique_key();
 my $dbh      = DBI->connect( "dbi:SQLite:dbname=$confdata->{dburl}",
        "", "", { RaiseError => 1, AutoCommit => 1 } );
 my $pdflist = $dbh->selectall_hashref(
-"SELECT id, path, page, title, part, genre, startpage, endpage, showpagediff, indexpage
+"SELECT id, path, page, title, title_id, part, genre, startpage, endpage, showpagediff, indexpage
        FROM pdffile"
        , 'id'
 );
@@ -61,15 +61,39 @@ if ( $mode eq 'partpdf' ) {
        exit;
 }
 elsif ( $mode eq 'showpagediff' ) {
-       my $dnum  = $cgi->int( param("diff") );
-       my $title = $cgi->param("title");
+       my $dnum  = int($cgi->param("diff") );
+       my $title = decode('utf-8',uri_unescape($cgi->param("title")));
        if ( $dnum > 0 ) {
                my $sqls =
-                 "UPDATE pdffile SET showpagediff = $dnum WHERE title_group=$title";
+                 "UPDATE pdffile SET showpagediff = $dnum WHERE title_id=\"$title\"";
+               print $sqls;
                $dbs = $dbh->prepare($sqls);
                $dbs->execute();
        }
 }
+elsif ( $mode eq 'genre') {
+       my $genre  = $cgi->param("genre");
+    my $title = decode('utf-8',uri_unescape($cgi->param("title")));
+       $lgenre = length $genre;
+    if ( $lgenre > 0 ) {
+        my $sqls =
+          "UPDATE pdffile SET genre = \"$genre\" WHERE title_id=\"$title\"";
+        print $sqls;
+        $dbs = $dbh->prepare($sqls);
+        $dbs->execute();
+    }
+}
+elsif ( $mode eq 'index') {
+    my $index  = int($cgi->param("index"));
+    my $title = decode('utf-8',uri_unescape($cgi->param("title")));
+    if ( $index > 0 ) {
+        my $sqls =
+          "UPDATE pdffile SET indexpage = \"$index\" WHERE title_id=\"$title\"";
+        print $sqls;
+        $dbs = $dbh->prepare($sqls);
+        $dbs->execute();
+    }
+}
 else {
        list_all_pdf();
 }
@@ -78,7 +102,7 @@ sub list_all_pdf {
        print
 qq {Partial PDF = ./pdfmanager.pl?mode=partpdf&pdfid=68fc6a6a1cdd79227d0f2fe2f03dd510&pdftk=765-765\n};
        my $ary_ref = $dbh->selectall_arrayref(
-"SELECT id, path, page, title, part, genre, startpage, endpage, showpagediff, indexpage
+"SELECT id, path, page, title_id, title, part, genre, startpage, endpage, showpagediff, indexpage
                FROM pdffile"
                , { Slice => {} }
        );
@@ -87,13 +111,14 @@ qq {Partial PDF = ./pdfmanager.pl?mode=partpdf&pdfid=68fc6a6a1cdd79227d0f2fe2f03
        print qq {<th>id</th>\n};
        print qq {<th>path</th>\n};
        print qq {<th>page</th>\n};
+       print qq {<th>title_id</th>\n};
        print qq {<th>title</th>\n};
        print qq {<th>part</th>\n};
        print qq {<th>genre</th>\n};
        print qq {<th>start</th>\n};
        print qq {<th>end</th>\n};
 
-       #print qq {<th>showpagediff</th>\n};
+       print qq {<th>showpagediff</th>\n};
        #print qq {<th>indexpage</th>\n};
        print qq {</tr>\n};
        foreach my $line ( @{$ary_ref} ) {
@@ -102,13 +127,14 @@ qq {Partial PDF = ./pdfmanager.pl?mode=partpdf&pdfid=68fc6a6a1cdd79227d0f2fe2f03
 qq {<td><a href="./htmlserver.pl?pdfpath=$line->{id}&amp;pagenum=1">$line->{id}</a></td>\n};
                print qq {<td>$line->{path}</td>\n};
                print qq {<td>$line->{page}</td>\n};
+               print qq {<td>$line->{title_id}</td>\n};
                print qq {<td>$line->{title}</td>\n};
                print qq {<td>$line->{part}</td>\n};
                print qq {<td>$line->{genre}</td>\n};
                print qq {<td>$line->{startpage}</td>\n};
                print qq {<td>$line->{endpage}</td>\n};
 
-               #print qq {<td>$line->{showpagediff}</td>\n};
+               print qq {<td>$line->{showpagediff}</td>\n};
                #print qq {<td>$line->{indexpage}</td>\n};
                print qq {</tr>\n};
        }