// disable memory and time limits, necessary for some administration tasks
 ini_set('memory_limit', '-1');
 if (!intval(ini_get('safe_mode'))) {
     set_time_limit(0);
 }
 echo "<pre>\n";
 $start_time = time();
 switch ($action) {
     case 'import':
         $files = $_POST['files'];
         if (isset($files)) {
             foreach ($files as $file) {
                 echo "Importing " . htmlspecialchars($file, ENT_NOQUOTES) . "\n";
                 ob_flush();
                 flush();
                 $catalog->import_book($admin_directory . "/" . $file);
             }
         }
         break;
     case 'upload':
         $file = $_FILES['file']['tmp_name'];
         if (isset($file) and is_uploaded_file($file)) {
             echo "Importing " . htmlspecialchars($_FILES["file"]["name"], ENT_NOQUOTES) . "\n";
             ob_flush();
             flush();
             $catalog->import_book($file);
         }
         break;
     case 'index':
         $book_ids = $_POST['books'];
         if (isset($book_ids)) {
<?php

if (php_sapi_name() != 'cli') {
    die("You're not using CLI PHP");
}
require_once 'inc/config.inc.php';
require_once 'lib/book_catalog.lib.php';
$catalog = new BookCatalog();
for ($i = 1; $i < $argc; ++$i) {
    $filename = $argv[$i];
    echo "Importing '{$filename}'...";
    $start_time = time();
    $catalog->import_book($filename);
    $finish_time = time();
    $ellapsed_time = $finish_time - $start_time;
    echo " ({$ellapsed_time} sec)\n";
}