Init actions and db
This commit is contained in:
parent
acd9b72097
commit
1acce6509c
|
@ -7,3 +7,11 @@ epub-loader is a utility ressource for ebooks.
|
||||||
- CalibreDbLoader class allows create Calibre databases and add ebooks
|
- CalibreDbLoader class allows create Calibre databases and add ebooks
|
||||||
- BookExport class allows to export ebooks metadata in csv files
|
- BookExport class allows to export ebooks metadata in csv files
|
||||||
- The app directory contains samples and allows to run actions
|
- The app directory contains samples and allows to run actions
|
||||||
|
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
## -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
- If a first-time install, copy app/config.php.example to app/config.php
|
||||||
|
- Edit config.php to match your config
|
||||||
|
- Open the app directory url
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
* @author Didier Corbière <didier.corbiere@opale-concept.com>
|
* @author Didier Corbière <didier.corbiere@opale-concept.com>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
foreach ($gConfig['databases'] as $dbConfig) {
|
|
||||||
// Init csv file
|
// Init csv file
|
||||||
$fileName = $dbConfig['db_path'] . DIRECTORY_SEPARATOR . basename($dbConfig['db_path']) . '_metadata.csv';
|
$fileName = $dbConfig['db_path'] . DIRECTORY_SEPARATOR . basename($dbConfig['db_path']) . '_metadata.csv';
|
||||||
try {
|
try {
|
||||||
|
@ -25,6 +24,5 @@ foreach ($gConfig['databases'] as $dbConfig) {
|
||||||
catch (Exception $e) {
|
catch (Exception $e) {
|
||||||
$gErrorArray[$fileName] = $e->getMessage();
|
$gErrorArray[$fileName] = $e->getMessage();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
* @author Didier Corbière <didier.corbiere@opale-concept.com>
|
* @author Didier Corbière <didier.corbiere@opale-concept.com>
|
||||||
*/
|
*/
|
||||||
|
|
||||||
foreach ($gConfig['databases'] as $dbConfig) {
|
|
||||||
// Init database file
|
// Init database file
|
||||||
$fileName = $dbConfig['db_path'] . DIRECTORY_SEPARATOR . 'metadata.db';
|
$fileName = $dbConfig['db_path'] . DIRECTORY_SEPARATOR . 'metadata.db';
|
||||||
try {
|
try {
|
||||||
|
@ -24,6 +23,5 @@ foreach ($gConfig['databases'] as $dbConfig) {
|
||||||
catch (Exception $e) {
|
catch (Exception $e) {
|
||||||
$gErrorArray[$fileName] = $e->getMessage();
|
$gErrorArray[$fileName] = $e->getMessage();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
|
@ -42,4 +42,4 @@ $gConfig['databases'][] = array('name' => 'La Bibliothèque électronique du Qu
|
||||||
*/
|
*/
|
||||||
$gConfig['actions'] = array();
|
$gConfig['actions'] = array();
|
||||||
$gConfig['actions']['cvs_export'] = 'Cvs export';
|
$gConfig['actions']['cvs_export'] = 'Cvs export';
|
||||||
$gConfig['actions']['db_load'] = 'Calibre database load';
|
$gConfig['actions']['db_load'] = 'Create database';
|
||||||
|
|
|
@ -14,11 +14,11 @@ header('Content-type: text/html; charset=utf-8');
|
||||||
body {
|
body {
|
||||||
font-family: "Times New Roman", Times, serif;
|
font-family: "Times New Roman", Times, serif;
|
||||||
background-color: #ffffff;
|
background-color: #ffffff;
|
||||||
color: #2F4769;
|
color: #333333;
|
||||||
margin: 20px;
|
margin: 20px;
|
||||||
}
|
}
|
||||||
a {
|
a {
|
||||||
color: #CC9966;
|
color: #096DD1;
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
}
|
}
|
||||||
a:hover {
|
a:hover {
|
||||||
|
@ -70,7 +70,7 @@ header('Content-type: text/html; charset=utf-8');
|
||||||
.footer {
|
.footer {
|
||||||
border-top: solid #2F4769 1px;
|
border-top: solid #2F4769 1px;
|
||||||
margin-top: 15px;
|
margin-top: 15px;
|
||||||
padding-top: 5px;
|
padding-top: 10px;
|
||||||
font-size: 80%;
|
font-size: 80%;
|
||||||
font-style: italic;
|
font-style: italic;
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,9 +22,31 @@ define('DEF_AppAdminMail', 'didier.corbiere@opale-concept.com');
|
||||||
// Include files
|
// Include files
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'config.php');
|
// Include config file
|
||||||
require_once($gConfig['cops_directory'] . '/resources/epub-loader/CalibreDbLoader.class.php');
|
$fileName = __DIR__ . DIRECTORY_SEPARATOR . 'config.php';
|
||||||
require_once($gConfig['cops_directory'] . '/resources/epub-loader/BookExport.class.php');
|
if (!file_exists($fileName)) {
|
||||||
|
die ('Missing configuration file: ' . $fileName);
|
||||||
|
}
|
||||||
|
require_once($fileName);
|
||||||
|
|
||||||
|
// Check Cops directory
|
||||||
|
if (!is_dir($gConfig['cops_directory'])) {
|
||||||
|
die ('Incorrect Cops directory: ' . $gConfig['cops_directory']);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Include Calibre database loader class
|
||||||
|
$fileName = $gConfig['cops_directory'] . '/resources/epub-loader/CalibreDbLoader.class.php';
|
||||||
|
if (!file_exists($fileName)) {
|
||||||
|
die ('Incorrect include file: ' . $gConfig['cops_directory']);
|
||||||
|
}
|
||||||
|
require_once($fileName);
|
||||||
|
|
||||||
|
// Include book export class
|
||||||
|
$fileName = $gConfig['cops_directory'] . '/resources/epub-loader/BookExport.class.php';
|
||||||
|
if (!file_exists($fileName)) {
|
||||||
|
die ('Incorrect include file: ' . $gConfig['cops_directory']);
|
||||||
|
}
|
||||||
|
require_once($fileName);
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
// Start application
|
// Start application
|
||||||
|
@ -33,24 +55,70 @@ require_once($gConfig['cops_directory'] . '/resources/epub-loader/BookExport.cla
|
||||||
// Global vars
|
// Global vars
|
||||||
$gErrorArray = array();
|
$gErrorArray = array();
|
||||||
|
|
||||||
// Get the action to execute
|
// Get the url parameters
|
||||||
$action = isset($_GET['action']) ? $_GET['action'] : null;
|
$action = isset($_GET['action']) ? $_GET['action'] : null;
|
||||||
|
$dbNum = isset($_GET['dbnum']) ? (int)$_GET['dbnum'] : null;
|
||||||
|
|
||||||
|
// Include html header
|
||||||
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'header.php');
|
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'header.php');
|
||||||
if (isset($action)) {
|
|
||||||
$phpFile = sprintf('%s%saction_%s.php', realpath(dirname(__FILE__)), DIRECTORY_SEPARATOR, $action);
|
// Html content
|
||||||
require_once($phpFile);
|
if (isset($action) && isset($dbNum)) {
|
||||||
|
if (!isset($gConfig['databases'][$dbNum])) {
|
||||||
|
die ('Incorrect database num: ' . $dbNum);
|
||||||
|
}
|
||||||
|
$dbConfig = $gConfig['databases'][$dbNum];
|
||||||
|
$fileName = sprintf('%s%saction_%s.php', __DIR__, DIRECTORY_SEPARATOR, $action);
|
||||||
|
if (!file_exists($fileName)) {
|
||||||
|
die ('Incorrect action file: ' . $fileName);
|
||||||
|
}
|
||||||
|
require_once($fileName);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
if (!isset($action)) {
|
||||||
// Display the available actions
|
// Display the available actions
|
||||||
echo ' <ul>' . "\n";
|
$str = '';
|
||||||
|
$str .= '<div><b>' . 'Select action' . '</b></div>' . "\n";
|
||||||
|
$str .= ' <ul>' . "\n";
|
||||||
foreach ($gConfig['actions'] as $action => $actionInfo) {
|
foreach ($gConfig['actions'] as $action => $actionInfo) {
|
||||||
echo ' <li>' . "\n";
|
$str .= ' <li>' . "\n";
|
||||||
echo ' <a href="./index.php?action=' . $action . '">' . $actionInfo . '</a>' . "\n";
|
$str .= ' <a href="./index.php?action=' . $action . '">' . $actionInfo . '</a>' . "\n";
|
||||||
echo ' </li>' . "\n";
|
$str .= ' </li>' . "\n";
|
||||||
}
|
}
|
||||||
echo ' </ul>' . "\n";
|
$str .= ' </ul>' . "\n";
|
||||||
|
echo $str;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
// Display databases
|
||||||
|
$str = '';
|
||||||
|
$str .= '<table width="100%">' . "\n";
|
||||||
|
$str .= '<tr>' . "\n";
|
||||||
|
$str .= '<th>' . 'Db num' . '</th>' . "\n";
|
||||||
|
$str .= '<th>' . 'Db name' . '</th>' . "\n";
|
||||||
|
$str .= '<th>' . 'Action' . '</th>' . "\n";
|
||||||
|
$str .= '<th>' . 'Db Path' . '</th>' . "\n";
|
||||||
|
$str .= '<th>' . 'Epub path' . '</th>' . "\n";
|
||||||
|
$str .= '<th>' . 'Nb Files' . '</th>' . "\n";
|
||||||
|
$str .= '</tr>' . "\n";
|
||||||
|
$actionTitle = $gConfig['actions'][$action];
|
||||||
|
foreach ($gConfig['databases'] as $dbNum => $dbConfig) {
|
||||||
|
$fileList = glob($dbConfig['epub_path'] . DIRECTORY_SEPARATOR . '*.epub');
|
||||||
|
$str .= '<tr>' . "\n";
|
||||||
|
$str .= '<td>' . $dbNum . '</td>' . "\n";
|
||||||
|
$str .= '<td>' . $dbConfig['name'] . '</td>' . "\n";
|
||||||
|
$str .= '<td>' . '<a href="./index.php?action=' . $action . '&dbnum=' . $dbNum . '">' . $actionTitle . '</a>' . '</td>' . "\n";
|
||||||
|
$str .= '<td>' . $dbConfig['db_path'] . '</td>' . "\n";
|
||||||
|
$str .= '<td>' . $dbConfig['epub_path'] . '</td>' . "\n";
|
||||||
|
$str .= '<td>' . count($fileList) . '</td>' . "\n";
|
||||||
|
$str .= '</tr>' . "\n";
|
||||||
|
$numWork++;
|
||||||
|
}
|
||||||
|
$str .= '</table>' . "\n";
|
||||||
|
echo $str;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Include html footer
|
||||||
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'footer.php');
|
require_once(__DIR__ . DIRECTORY_SEPARATOR . 'footer.php');
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
|
Loading…
Reference in a new issue