6 use CGI::Carp qw(fatalsToBrowser);
17 # Copyright 2013 yukikaze, long.inus
18 # Licensed under the Apache License, Version 2.0 (the "License");
19 # you may not use this file except in compliance with the License.
20 # You may obtain a copy of the License at
22 # http://www.apache.org/licenses/LICENSE-2.0
24 # Unless required by applicable law or agreed to in writing, software
25 # distributed under the License is distributed on an "AS IS" BASIS,
26 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
27 # See the License for the specific language governing permissions and
28 # limitations under the License.
32 my $mode = $cgi->param('mode');
33 my $confdata = YAML::XS::LoadFile(
34 -e 'libre10.conf' ? 'libre10.conf' : '/etc/libre10.conf' );
35 my $temppath = "/tmp/libre10/tmp" . generate_unique_key();
36 my $dbh = DBI->connect( "dbi:SQLite:dbname=$confdata->{dburl}",
37 "", "", { RaiseError => 1, AutoCommit => 1 } );
38 my $pdflist = $dbh->selectall_hashref(
39 "SELECT id, path, page, title, part, genre, startpage, endpage, showpagediff, indexpage
43 mkdir '/tmp/libre10' unless ( -e '/tmp/libre10' );
45 print $cgi->header( -charset => 'utf-8' );
46 if ( $mode eq 'partpdf' ) {
47 my $pdfid = $cgi->param('pdfid');
48 my $pdftk = $cgi->param('pdftk');
51 $pdftk =~ s/[^0-9\-]//;
53 my $pdfpath = $pdflist->{$pdfid}->{path};
54 exit unless ( -e $pdfpath );
55 system "pdftk '$pdfpath' cat '$pdftk' output '$temppath.pdf'";
56 my $length = -s "$temp:q:path.pdf";
57 print "Content-Type: application/pdf\n";
58 print "Content-Length: $length\n";
60 print read_file("$temppath.pdf");
63 elsif ( $mode eq 'showpagediff' ) {
64 my $dnum = $cgi->int( param("diff") );
65 my $title = $cgi->param("title");
68 "UPDATE pdffile SET showpagediff = $dnum WHERE title_group=$title";
69 $dbs = $dbh->prepare($sqls);
79 qq {Partial PDF = ./pdfmanager.pl?mode=partpdf&pdfid=68fc6a6a1cdd79227d0f2fe2f03dd510&pdftk=765-765\n};
80 my $ary_ref = $dbh->selectall_arrayref(
81 "SELECT id, path, page, title, part, genre, startpage, endpage, showpagediff, indexpage
87 print qq {<th>id</th>\n};
88 print qq {<th>path</th>\n};
89 print qq {<th>page</th>\n};
90 print qq {<th>title</th>\n};
91 print qq {<th>part</th>\n};
92 print qq {<th>genre</th>\n};
93 print qq {<th>start</th>\n};
94 print qq {<th>end</th>\n};
96 #print qq {<th>showpagediff</th>\n};
97 #print qq {<th>indexpage</th>\n};
99 foreach my $line ( @{$ary_ref} ) {
102 qq {<td><a href="./htmlserver.pl?pdfpath=$line->{id}&pagenum=1">$line->{id}</a></td>\n};
103 print qq {<td>$line->{path}</td>\n};
104 print qq {<td>$line->{page}</td>\n};
105 print qq {<td>$line->{title}</td>\n};
106 print qq {<td>$line->{part}</td>\n};
107 print qq {<td>$line->{genre}</td>\n};
108 print qq {<td>$line->{startpage}</td>\n};
109 print qq {<td>$line->{endpage}</td>\n};
111 #print qq {<td>$line->{showpagediff}</td>\n};
112 #print qq {<td>$line->{indexpage}</td>\n};
115 print qq {</table>\n};
119 sub generate_unique_key {
121 my @str = ( 0 .. 9, 'A' .. 'Z', 'a' .. 'z' );
124 $ukey .= $str[ int( rand(@str) ) ];