16 # Licensed under the Apache License,
20 # Copyright 2013 yukikaze
21 # Licensed under the Apache License, Version 2.0 (the "License");
22 # you may not use this file except in compliance with the License.
23 # You may obtain a copy of the License at
25 # http://www.apache.org/licenses/LICENSE-2.0
27 # Unless required by applicable law or agreed to in writing, software
28 # distributed under the License is distributed on an "AS IS" BASIS,
29 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
30 # See the License for the specific language governing permissions and
31 # limitations under the License.
35 if ( -e "libre10.conf" ) {
36 $confpath = "libre10.conf";
39 $confpath = "/etc/libre10.conf";
41 $confdata = YAML::XS::LoadFile($confpath);
43 $mode = decode( 'utf-8', $cgi->param('mode') );
44 $pagenum = int( $cgi->param('pagenum') );
45 $title_row = $cgi->param('title');
46 $title_row = uri_unescape($title_row);
47 $title_group = decode( 'utf-8', $title_row );
48 $title_uri = uri_escape($title_row);
49 $html_mode = $cgi->param('htmlmode');
51 $height = $cgi->param("height");
52 $width = $cgi->param("width");
53 $dbpath = $confdata->{dburl};
56 DBI->connect( "dbi:SQLite:dbname=$dbpath", "", "",
57 { RaiseError => 1, AutoCommit => 1 } );
61 "SELECT id,title,part,startpage,endpage FROM pdffile WHERE title_id = '$title_group' ORDER BY part DESC LIMIT 1";
62 $dbs = $dbi->prepare($sql);
64 $dbh = $dbs->fetchrow_hashref;
65 $multi_maxpage = $dbh->{'endpage'};
68 "SELECT id,startpage FROM pdffile WHERE title_id = '$title_group' AND startpage < $pagenum AND endpage > $pagenum";
69 $dbs2 = $dbi->prepare($sql2);
71 $dbh2 = $dbs2->fetchrow_hashref;
72 $single_pagenum = $pagenum - $dbh2->{'startpage'};
73 $pdfpath = $dbh2->{'id'};
75 "htmlserver.pl?title=$title_uri&mode=$mode&width=$width&height=$height&pagenum=";
76 $bpage = $pagenum - 1;
78 "htmlserver.pl?title=$title_uri&mode=$mode&width=$width&height=$height&pagenum=$bpage";
79 $npage = $pagenum + 1;
81 "htmlserver.pl?title=$title_uri&mode=$mode&width=$width&height=$height&pagenum=$npage";
84 $height = $cgi->param("height");
85 $width = $cgi->param("width");
87 "jpegserver.pl?pdfpath=\"$pdfpath\"&pagenum=$single_pagenum&mode=$mode&height=$height&width=$width";
88 if ( $html_mode eq '' ) {
90 HTML::Template->new( filename => './template/mobile_viewjpeg.tmpl' );
91 $template->param( blink => $blink );
92 $template->param( nlink => $nlink );
93 $template->param( jpegpath => $jpeglink );
94 $template->param( jumplink => $jumplink );
95 $template->param( nowpage => $pagenum );
96 $template->param( maxpage => $multi_maxpage );
97 print $cgi->header( -charset => 'utf-8' ), $template->output;