db (); getint ("fk_books"); getstr ("filemask"); pageheader ("Files for EBook #$fk_books"); p ("Careful! If you change the Ebook number you link the file to a different Ebook."); p ("Note: you cannot add files to the database. " . "That is done automagically by a nightly cron job."); p ("Goto Edit Book Page — " . "etext/${fk_books}\">Goto Bibrec Page"); function mk_options ($name, $options, $option) { $ret = ""; foreach ($options as $value => $opt) { $selected = ($opt == $option) ? " selected=\"selected\"" : ""; $ret .= "\n"; } return "\n"; } $filetypes[null] = "unknown"; $db->Exec ("select * from filetypes order by filetype"); if ($db->FirstRow ()) { do { $filetypes[$db->Get ("pk")] = $db->Get ("filetype"); } while ($db->NextRow ()); } $compressions[null] = "unknown"; $db->Exec ("select * from compressions order by compression"); if ($db->FirstRow ()) { do { $compressions[$db->Get ("pk")] = $db->Get ("compression"); } while ($db->NextRow ()); } $encodings[null] = "unknown"; $db->Exec ("select * from encodings order by pk"); if ($db->FirstRow ()) { do { $encodings[$db->Get ("pk")] = $db->Get ("pk"); } while ($db->NextRow ()); } class HeadColumn extends dbtSimpleColumn { function __construct () { parent::__construct (null, "", "narrow"); } function Data ($db) { $filename = $db->get ("filename"); if (preg_match ("/\.zip$/i", $filename)) return "Dir"; return "Head"; } } class CharsetColumn extends dbtSimpleColumn { function __construct () { parent::__construct (null, "", "narrow"); } function Data ($db) { $filename = $db->get ("filename"); if (preg_match ("/\.zip$/i", $filename)) return ""; return "Guess"; } } class SizeColumn extends dbtSimpleColumn { function __construct () { parent::__construct (null, "Size", "pgdbfilessize"); } function Header () { return "Size"; } function Data ($db) { return "" . human_readable_size ($db->get ("filesize")) . ""; } } class FiletypeColumn extends dbtSimpleColumn { function __construct () { parent::__construct (null, "File Type", "pgdbfilesfiletype"); } function Data ($db) { global $filetypes; return "" . mk_options ("fk_filetypes", $filetypes, $db->get ("filetype")) . ""; } } class CompressionColumn extends dbtSimpleColumn { function __construct () { parent::__construct (null, "Compression", "pgdbfilescompression"); } function Data ($db) { global $compressions; return "" . mk_options ("fk_compressions", $compressions, $db->get ("compression")) . ""; } } class EncodingColumn extends dbtSimpleColumn { function __construct () { parent::__construct (null, "Encoding", "pgdbfilesencoding"); } function Data ($db) { global $encodings; return "" . mk_options ("fk_encodings", $encodings, $db->get ("fk_encodings")) . ""; } } class ObsoletedColumn extends dbtSimpleColumn { function __construct () { parent::__construct (null, "Obs.", "pgdbfilesobsoleted"); } function Data ($db) { $obs = $db->get ("obsoleted", SQLINT) ? " checked=\"checked\"" : ""; $pk = $db->get ("pk", SQLINT); return ""; } } form_open_get (); echo ("Enter Perl RegExp: eg. /12345/"); form_relay ("fk_books"); form_submit ("Reload"); form_close (); // Files for book $prefix = "AddColumn ("", "", "narrow"); $t->AddColumn ("$prefix=edit&fk_files=#pk#\">Edit", "", "narrow"); $t->AddColumnObject (new HeadColumn ()); $t->AddColumn ("Bug", "", "narrow"); $t->AddColumn ("downloadbase/#filename#\">#filename#" . "", "Filename"); $t->AddColumn ("" . "", "EBook"); $t->AddColumn ("", "Edition"); $t->AddColumnObject (new ObsoletedColumn ()); $t->AddColumnObject (new FiletypeColumn ()); $t->AddColumnObject (new EncodingColumn ()); $t->AddColumnObject (new CharsetColumn ()); $t->AddColumnObject (new CompressionColumn ()); $t->AddColumnObject (new SizeColumn ()); ///////////////////////////////////////////////////////////////////////////////// // Generate list of candidate files // /*if (empty ($filemask)) { if ($fk_books > 10000) { $filemask = "/${fk_books}[.-]"; } else { $db->Exec ("select * from books where pk = $fk_books"); $filemask = $db->Get ("filemask"); if (!empty ($filemask)) { $filemask = preg_replace ("/\./", "\\.", $filemask); $filemask = preg_replace ("/x+/", ".*", $filemask); $filemask = preg_replace ("/^[?]/", "[78]", $filemask); } } }*/ $sql = "select files.pk as pk, fk_books, filename, edition, obsoleted, filetype, " . "compression, fk_encodings, filesize " . "from files left join filetypes on files.fk_filetypes = filetypes.pk " . "left join compressions on files.fk_compressions = compressions.pk " . "where " . (empty ($filemask) ? "" : "filename ~ '$filemask' or ") . "(fk_books = $fk_books and diskstatus = 0) " . "order by (fk_books = $fk_books) desc, obsoleted, " . "filetype, fk_encodings, compression, filename;"; $db->exec ($sql); form_open ("files2"); $t->limit = 100; $t->PrintTable ($db, "Files Linked to Book $fk_books or Matching RegExp: $filemask", "pgdbfiles"); form_relay ("fk_books"); form_relay ("filemask"); form_submit ("Update Checked File Entries"); form_close (); p ("To be implemented: functions for viewing bottom n lines from file, check for character encoding, diff files, look into zips. In my copious free time."); pagefooter (); // Local Variables: // mode:php // coding:utf-8-unix // fill-column: 75 // End: ?>