catalog admin

master
Gutenberg back end service account 2020-08-28 12:21:11 -04:00
parent c10f1344a6
commit 138070ad67
158 changed files with 14598 additions and 0 deletions

76
catalog/admin/#user.php# Normal file
View File

@ -0,0 +1,76 @@
<?php
set_include_path(get_include_path() . PATH_SEPARATOR . "/public/vhost/g/gutenberg/dev/private/lib/php");
include_once ("pgcat.phh");
authenticate ("createuser");
getstr ("mode");
$caption = ucfirst ($mode) . " User";
pageheader ($caption);
include_once ("sqlform.phh");
$db = $config->db ();
$db->logger = new logger ();
$f = new SQLForm ();
getint ("fk_users");
getstr ("filter");
if (ismode ("delete")) {
$f->SubCaption ("You are about to delete this user.");
$f->SubCaption ("Press the '$caption' button to continue or " .
"hit the back button on your browser to dismiss.");
} else {
$f->Text ("user", "user", "User", SQLCHAR, 80, 240, true);
$f->Text ("login", "login", "Login", SQLCHAR, 80, 240, true);
$f->TextArea ("note", "note", "Note", SQLCHAR, 4, 80, false);
$f->LoadData ("select * from users where pk = $fk_users");
}
$f->Hidden ("fk_users");
$f->Hidden ("filter");
if (isupdatemode ("add")) {
if ($f->Check ()) {
$sql = $f->mkInsert ($db->GetFormatter ());
if ($db->Exec ("insert into users " . $sql)) {
msg ("User added !");
} else {
error_msg ("Could not add user!");
}
}
}
if (isupdatemode ("edit")) {
if ($f->Check ()) {
$sql = $f->mkUpdate ($db->GetFormatter ());
if ($db->Exec ("update users set " . $sql . "where pk = $fk_users")) {
msg ("User modified !");
} else {
error_msg ("Could not modify user !");
}
}
}
if (isupdatemode ("delete")) {
$db->Exec ("delete from mn_users_permissions where fk_users = $fk_users");
if ($db->Exec ("delete from users where pk = $fk_users")) {
msg ("User deleted !");
} else {
error_msg ("Could not delete user !");
}
}
if (isupdate ()) {
if (!isupdatemode ("delete")) {
p ("<a href=\"user?mode=edit&filter=$filter&fk_users=$fk_users\">Back to User</a>");
}
} else {
$f->Output ($caption, $caption);
}
p ("<a href=\"users_list?filter=$filter\">Back to User List</a>");
pagefooter ();
?>

1
catalog/admin/.#user.php Symbolic link
View File

@ -0,0 +1 @@
gutenbackend@login2.ibiblio.org.27895:1596734584

View File

@ -0,0 +1,3 @@
<Files *>
DirectoryIndex index.php
</Files>

5
catalog/admin/a.php Normal file
View File

@ -0,0 +1,5 @@
<?php
print "hello, world\n";
?>

66
catalog/admin/alias.php Normal file
View File

@ -0,0 +1,66 @@
<?php
set_include_path(get_include_path() . PATH_SEPARATOR . "/public/vhost/g/gutenberg/dev/private/lib/php");
include_once ("pgcat.phh");
include_once ("sqlform.phh");
authenticate ();
$db = $config->db ();
$db->logger = new logger ();
getstr ("mode");
getint ("fk_aliases");
getint ("fk_authors");
$caption = ucfirst ($mode);
$f = new SQLForm ();
if (ismode ("add")) {
$f->SQLInject ("fk_authors", "fk_authors", SQLINT);
}
$f->Text ("alias", "alias", "Alias", SQLCHAR, 80, 240, true);
$f->KeySelect ("alias_heading", "alias_heading", "Heading", SQLINT, 10, 2, false);
$f->last->PushOptions ($titles_heading);
$f->last->ToolTip ("Should this alias generate a user-visible heading?");
$f->LoadData ("select * from aliases where pk = $fk_aliases");
$f->Hidden ("fk_aliases");
$f->Hidden ("fk_authors");
if (ismode ("delete")) {
$f->SubCaption ("You are about to delete this alias. " .
"Press the '$caption' button to continue or " .
"hit the back button on your browser to dismiss.");
}
if (isupdatemode ("add")) {
if ($f->Check ()) {
$sql = $f->mkInsert ($db->GetFormatter ());
$retcode = $db->Exec ("insert into aliases " . $sql);
}
}
if (isupdatemode ("edit")) {
if ($f->Check ()) {
$sql = $f->mkUpdate ($db->GetFormatter ());
$retcode = $db->Exec ("update aliases set " . $sql . "where pk = $fk_aliases");
}
}
if (isupdatemode ("delete")) {
$retcode = $db->Exec ("delete from aliases where pk = $fk_aliases");
}
if (isupdate ()) {
$msg = confirmation_msg ($retcode, $mode, "alias");
header ("Location: author?mode=edit&fk_authors=$fk_authors&$msg");
return;
}
pageheader ("$caption Author Alias");
$f->Output ($caption, $caption);
pagefooter ();
?>

65
catalog/admin/alias.php~ Normal file
View File

@ -0,0 +1,65 @@
<?php
include_once ("pgcat.phh");
include_once ("sqlform.phh");
authenticate ();
$db = $config->db ();
$db->logger = new logger ();
getstr ("mode");
getint ("fk_aliases");
getint ("fk_authors");
$caption = ucfirst ($mode);
$f = new SQLForm ();
if (ismode ("add")) {
$f->SQLInject ("fk_authors", "fk_authors", SQLINT);
}
$f->Text ("alias", "alias", "Alias", SQLCHAR, 80, 240, true);
$f->KeySelect ("alias_heading", "alias_heading", "Heading", SQLINT, 10, 2, false);
$f->last->PushOptions ($titles_heading);
$f->last->ToolTip ("Should this alias generate a user-visible heading?");
$f->LoadData ("select * from aliases where pk = $fk_aliases");
$f->Hidden ("fk_aliases");
$f->Hidden ("fk_authors");
if (ismode ("delete")) {
$f->SubCaption ("You are about to delete this alias. " .
"Press the '$caption' button to continue or " .
"hit the back button on your browser to dismiss.");
}
if (isupdatemode ("add")) {
if ($f->Check ()) {
$sql = $f->mkInsert ($db->GetFormatter ());
$retcode = $db->Exec ("insert into aliases " . $sql);
}
}
if (isupdatemode ("edit")) {
if ($f->Check ()) {
$sql = $f->mkUpdate ($db->GetFormatter ());
$retcode = $db->Exec ("update aliases set " . $sql . "where pk = $fk_aliases");
}
}
if (isupdatemode ("delete")) {
$retcode = $db->Exec ("delete from aliases where pk = $fk_aliases");
}
if (isupdate ()) {
$msg = confirmation_msg ($retcode, $mode, "alias");
header ("Location: author?mode=edit&fk_authors=$fk_authors&$msg");
return;
}
pageheader ("$caption Author Alias");
$f->Output ($caption, $caption);
pagefooter ();
?>

View File

@ -0,0 +1,82 @@
<?php
set_include_path(get_include_path() . PATH_SEPARATOR . "/public/vhost/g/gutenberg/dev/private/lib/php");
include_once ("pgcat.phh");
include_once ("sqlform.phh");
authenticate ();
$db = $config->db ();
$db->logger = new logger ();
getstr ("mode");
getint ("pk");
getint ("fk_books");
$caption = ucfirst ($mode);
$f = new SQLForm ();
if (ismode ("add")) {
$f->SQLInject ("fk_books", "fk_books", SQLINT);
}
$f->KeySelect ("fk_attriblist", "fk_attriblist", "Attribute", SQLINT, 40, 40, true);
$f->last->LoadSQL ("select pk as key, name as caption from attriblist where type = 'unc' order by name");
$f->last->DefValue (500);
$f->last->ToolTip ("Select an attribute.");
$f->TextArea ("text", "text", "Value", SQLCHAR, 5, 80, true);
$f->ToolTip ("Enter the value for the selected attribute.");
$f->Text ("nonfiling", "nonfiling", "Nonfiling Chars", SQLINT, 2, 2, false);
$f->DefValue (0);
$f->ToolTip ("No. of nonfiling characters. eg. 'The Idiot' => 4");
$f->Text ("indicators", "indicators", "MARC indicators", SQLCHAR, 2, 2, false);
$f->ToolTip ("MARC indicators (2 digits). See MARC Spec for details. If you are unsure leave blank.");
$f->KeySelect ("fk_langs", "fk_langs", "Language", SQLCHAR, 40, 40, true);
$f->last->PushOption (null, "undefined");
$f->last->LoadSQL ("select pk as key, lang as caption from langs order by lang");
$f->last->DefValue ("en");
$f->last->ToolTip ("Which language is this attribute in?");
$f->LoadData ("select * from attributes where pk = $pk");
$f->Hidden ("pk");
$f->Hidden ("fk_books");
if (ismode ("delete")) {
$f->SubCaption ("You are about to delete this attribute. " .
"Press the '$caption' button to continue or " .
"hit the back button on your browser to dismiss.");
}
if (isupdatemode ("add")) {
if ($f->Check ()) {
$sql = $f->mkInsert ($db->GetFormatter ());
$retcode = $db->Exec ("insert into attributes " . $sql);
}
}
if (isupdatemode ("edit")) {
if ($f->Check ()) {
$sql = $f->mkUpdate ($db->GetFormatter ());
$retcode = $db->Exec ("update attributes set " . $sql . "where pk = $pk");
}
}
if (isupdatemode ("delete")) {
$retcode = $db->Exec ("delete from attributes where pk = $pk");
}
if (isupdate ()) {
$msg = confirmation_msg ($retcode, $mode, "attribute");
header ("Location: book?mode=edit&fk_books=$fk_books&$msg");
return;
}
pageheader ("$caption Attribute");
p ("<a href=\"http://www.loc.gov/marc/umb/um07to10.html\">A Summary of Commonly Used MARC 21 Fields</a>");
$f->Output ($caption, $caption);
pagefooter ();
?>

View File

@ -0,0 +1,81 @@
<?php
include_once ("pgcat.phh");
include_once ("sqlform.phh");
authenticate ();
$db = $config->db ();
$db->logger = new logger ();
getstr ("mode");
getint ("pk");
getint ("fk_books");
$caption = ucfirst ($mode);
$f = new SQLForm ();
if (ismode ("add")) {
$f->SQLInject ("fk_books", "fk_books", SQLINT);
}
$f->KeySelect ("fk_attriblist", "fk_attriblist", "Attribute", SQLINT, 40, 40, true);
$f->last->LoadSQL ("select pk as key, name as caption from attriblist where type = 'unc' order by name");
$f->last->DefValue (500);
$f->last->ToolTip ("Select an attribute.");
$f->TextArea ("text", "text", "Value", SQLCHAR, 5, 80, true);
$f->ToolTip ("Enter the value for the selected attribute.");
$f->Text ("nonfiling", "nonfiling", "Nonfiling Chars", SQLINT, 2, 2, false);
$f->DefValue (0);
$f->ToolTip ("No. of nonfiling characters. eg. 'The Idiot' => 4");
$f->Text ("indicators", "indicators", "MARC indicators", SQLCHAR, 2, 2, false);
$f->ToolTip ("MARC indicators (2 digits). See MARC Spec for details. If you are unsure leave blank.");
$f->KeySelect ("fk_langs", "fk_langs", "Language", SQLCHAR, 40, 40, true);
$f->last->PushOption (null, "undefined");
$f->last->LoadSQL ("select pk as key, lang as caption from langs order by lang");
$f->last->DefValue ("en");
$f->last->ToolTip ("Which language is this attribute in?");
$f->LoadData ("select * from attributes where pk = $pk");
$f->Hidden ("pk");
$f->Hidden ("fk_books");
if (ismode ("delete")) {
$f->SubCaption ("You are about to delete this attribute. " .
"Press the '$caption' button to continue or " .
"hit the back button on your browser to dismiss.");
}
if (isupdatemode ("add")) {
if ($f->Check ()) {
$sql = $f->mkInsert ($db->GetFormatter ());
$retcode = $db->Exec ("insert into attributes " . $sql);
}
}
if (isupdatemode ("edit")) {
if ($f->Check ()) {
$sql = $f->mkUpdate ($db->GetFormatter ());
$retcode = $db->Exec ("update attributes set " . $sql . "where pk = $pk");
}
}
if (isupdatemode ("delete")) {
$retcode = $db->Exec ("delete from attributes where pk = $pk");
}
if (isupdate ()) {
$msg = confirmation_msg ($retcode, $mode, "attribute");
header ("Location: book?mode=edit&fk_books=$fk_books&$msg");
return;
}
pageheader ("$caption Attribute");
p ("<a href=\"http://www.loc.gov/marc/umb/um07to10.html\">A Summary of Commonly Used MARC 21 Fields</a>");
$f->Output ($caption, $caption);
pagefooter ();
?>

View File

@ -0,0 +1,39 @@
<?php
set_include_path(get_include_path() . PATH_SEPARATOR . "/public/vhost/g/gutenberg/dev/private/lib/php");
include_once ("pgcat.phh");
authenticate ();
getint("attribute");
$db = $config->db ();
$db->logger = new logger ();
$db->Exec("select name from attriblist where pk = $attribute");
$marcfield = $db->Get("name");
if (!$marcfield) {
pageheader("Usage of ... field");
echo("<b>Error: Unrecognized MARC attribute \"$attribute\" given.</b>");
pagefooter();
return;
}
pageheader ("Usage of $marcfield field");
$db->Exec("select fk_books, text from attributes " .
"where fk_attriblist = $attribute");
if ($db->Get("fk_books")) {
echo("<table>\n".
"<caption>Uses</caption>" .
"<tr><th>Etext#</th><th>Text of MARC field</th></tr>");
do {
$etext=$db->Get("fk_books");
echo("<tr><td><a href=\"/etext/${etext}e\">${etext}</a></td><td>" .
$db->Get("text") . "</td></tr>\n");
} while ($db->NextRow());
echo ("</table>");
} else {
echo("MARC field $attribute is unused.");
}
pagefooter();
?>

View File

@ -0,0 +1,38 @@
<?php
include_once ("pgcat.phh");
authenticate ();
getint("attribute");
$db = $config->db ();
$db->logger = new logger ();
$db->Exec("select name from attriblist where pk = $attribute");
$marcfield = $db->Get("name");
if (!$marcfield) {
pageheader("Usage of ... field");
echo("<b>Error: Unrecognized MARC attribute \"$attribute\" given.</b>");
pagefooter();
return;
}
pageheader ("Usage of $marcfield field");
$db->Exec("select fk_books, text from attributes " .
"where fk_attriblist = $attribute");
if ($db->Get("fk_books")) {
echo("<table>\n".
"<caption>Uses</caption>" .
"<tr><th>Etext#</th><th>Text of MARC field</th></tr>");
do {
$etext=$db->Get("fk_books");
echo("<tr><td><a href=\"/etext/${etext}e\">${etext}</a></td><td>" .
$db->Get("text") . "</td></tr>\n");
} while ($db->NextRow());
echo ("</table>");
} else {
echo("MARC field $attribute is unused.");
}
pagefooter();
?>

View File

@ -0,0 +1,42 @@
<?php
set_include_path(get_include_path() . PATH_SEPARATOR . "/public/vhost/g/gutenberg/dev/private/lib/php");
include_once ("pgcat.phh");
authenticate ();
pageheader ("Statistics on MARC field usage");
$db = $config->db ();
$db->logger = new logger ();
$marc_fields = array();
$db->Exec("select pk, name from attriblist order by pk");
do {
$marc_fields[] = array($db->Get("pk"), $db->Get("name"));
} while ($db->NextRow());
echo <<< EOT
<p>This is a list of all the MARC field/attribute/tag/code names currently
present in the cataloging system. As you can see, we do not actually use
MARC attributes for Author, Language, Subject or LoCC (they are stored
& modified elsewhere), but the system does know about them. This should
probably be fixed. -- Jan 2008</p>
<p>Click on the attribute name to get a list of all the uses of it in the system,
along with links to edit them.</p>
EOT;
echo("<table>\n".
"<caption># of times each MARC field is used in the PG catalog.</caption>" .
"<tr><th>MARC field</th><th># of entries</th></tr>");
for ($i = 0 ; $i < count($marc_fields); $i++) {
$db->Exec("select count(*) as cnt from attributes where fk_attriblist = " .
$marc_fields[$i][0]);
echo("<tr><td><a href=\"attribute_list?attribute=" . $marc_fields[$i][0] . "\">" .
$marc_fields[$i][1] . "</a></td><td>" . $db->Get("cnt") .
"</td></tr>\n");
}
echo ("</table>");
pagefooter();
?>

View File

@ -0,0 +1,41 @@
<?php
include_once ("pgcat.phh");
authenticate ();
pageheader ("Statistics on MARC field usage");
$db = $config->db ();
$db->logger = new logger ();
$marc_fields = array();
$db->Exec("select pk, name from attriblist order by pk");
do {
$marc_fields[] = array($db->Get("pk"), $db->Get("name"));
} while ($db->NextRow());
echo <<< EOT
<p>This is a list of all the MARC field/attribute/tag/code names currently
present in the cataloging system. As you can see, we do not actually use
MARC attributes for Author, Language, Subject or LoCC (they are stored
& modified elsewhere), but the system does know about them. This should
probably be fixed. -- Jan 2008</p>
<p>Click on the attribute name to get a list of all the uses of it in the system,
along with links to edit them.</p>
EOT;
echo("<table>\n".
"<caption># of times each MARC field is used in the PG catalog.</caption>" .
"<tr><th>MARC field</th><th># of entries</th></tr>");
for ($i = 0 ; $i < count($marc_fields); $i++) {
$db->Exec("select count(*) as cnt from attributes where fk_attriblist = " .
$marc_fields[$i][0]);
echo("<tr><td><a href=\"attribute_list?attribute=" . $marc_fields[$i][0] . "\">" .
$marc_fields[$i][1] . "</a></td><td>" . $db->Get("cnt") .
"</td></tr>\n");
}
echo ("</table>");
pagefooter();
?>

182
catalog/admin/author.php Normal file
View File

@ -0,0 +1,182 @@
<?php
set_include_path(get_include_path() . PATH_SEPARATOR . "/public/vhost/g/gutenberg/dev/private/lib/php");
include_once ("pgcat.phh");
authenticate ();
getstr ("mode");
$caption = ucfirst ($mode) . " Author";
pageheader ($caption);
getstr ("msg");
getstr ("errormsg");
if (!empty ($msg)) msg ($msg);
if (!empty ($errormsg)) error_msg ($msg);
include_once ("sqlform.phh");
class ListAliasesTable extends ListTable {
function __construct () {
global $fk_authors;
$prefix = "<a href=\"alias?fk_authors=$fk_authors&mode";
$this->AddColumn ("$prefix=edit&fk_aliases=#pk#\">Edit</a>",
"$prefix=add\">Add</a>", "narrow");
$this->AddColumn ("$prefix=delete&fk_aliases=#pk#\">Delete</a>", "", "narrow");
$this->AddSimpleColumn ("alias", "Alias");
$this->AddSimpleColumn ("c_alias_heading", "Heading", "narrow");
$this->AddSubCaption
("Less prominent names and pseudonyms the author is also known under, " .
"ASCII-fied versions, variant orthographies, common mis-spellings (Gutenburg).");
}
}
class ListAuthorUrlsTable extends ListTable {
function __construct () {
global $fk_authors;
$prefix = "<a href=\"author_url?fk_authors=$fk_authors&mode";
$this->AddColumn ("$prefix=edit&fk_author_urls=#pk#\">Edit</a>",
"$prefix=add\">Add</a>", "narrow");
$this->AddColumn ("$prefix=delete&fk_author_urls=#pk#\">Delete</a>", "", "narrow");
$this->AddSimpleColumn ("description", "Description");
$this->AddSimpleColumn ("url", "URL");
$this->AddSubCaption ("Interesting sites about the author.");
}
}
class ListBooksTable extends ListTable {
function __construct () {
$this->AddColumn ("<a href=\"book?mode=edit&fk_books=#fk_books#\">#fk_books#</a>",
"Etext Nr.", "narrow right");
$this->AddSimpleColumn ("title", "Title");
$this->AddSimpleColumn ("lang", "Language", "narrow");
$this->AddSimpleColumn ("role", "Role", "narrow");
$this->AddSubCaption ("Books linked to author.");
}
}
$db = $config->db ();
$db->logger = new logger ();
$f = new SQLForm ();
getint ("fk_authors");
if (ismode ("delete")) {
$db->Exec ("select count (*) as cnt from mn_books_authors where fk_authors = $fk_authors");
$cnt = $db->get ("cnt");
if ($cnt > 0) {
error_msg ("There are still $cnt books related to this author. " .
"You must delete them first.");
}
$db->Exec ("select author from authors where pk = $fk_authors");
$author = $db->get("author");
$f->SubCaption ("You are about to delete author: $author.");
$f->SubCaption ("Press the '$caption' button to continue or " .
"hit the back button on your browser to dismiss.");
} else {
print "<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><h1>editing</h1>\n";
$f->SubCaption ("The best-known name or pseudonym and other data.");
$f->Text ("author", "author", "Name", SQLCHAR, 80, 240, true);
$f->ToolTip ("Enter the name or pseudonym the author is best known under. " .
"Put lesser known names or pseudonyms in aliases. " .
"Use full unicode here and put an ASCII-fied version in aliases." .
"(eg. Brontë, Charlotte)");
$f->Text ("born_floor", "born_floor", "Born (earliest)", SQLINT, 12, 12, false);
$f->ToolTip ("Year the author was born (earliest estimate). Leave empty if unknown. ".
"(eg. 1803, -250)");
$f->Text ("born_ceil", "born_ceil", "Born (latest)", SQLINT, 12, 12, false);
$f->ToolTip ("Year the author was born (latest estimate). Leave empty if unknown. ".
"(eg. 1803, -250)");
$f->Text ("died_floor", "died_floor", "Died (earliest)", SQLINT, 12, 12, false);
$f->ToolTip ("Year the author died (earliest estimate). Leave empty if unknown. ".
"(eg. 1803, -250)");
$f->Text ("died_ceil", "died_ceil", "Died (latest)", SQLINT, 12, 12, false);
$f->ToolTip ("Year the author died (latest estimate). Leave empty if unknown. ".
"(eg. 1803, -250)");
$f->TextArea ("note", "note", "Note", SQLCHAR, 4, 80, false);
$f->ToolTip ("Any note relevant to the cataloging people.");
$f->LoadData ("select * from authors where pk = $fk_authors");
}
$f->Hidden ("fk_authors");
if (isupdatemode ("add")) {
if ($f->Check ()) {
$sql = $f->mkInsert ($db->GetFormatter ());
if ($db->Exec ("insert into authors " . $sql)) {
msg ("Author added !");
} else {
error_msg ("Could not add Author!");
}
}
}
if (isupdatemode ("edit")) {
if ($f->Check ()) {
$sql = $f->mkUpdate ($db->GetFormatter ());
if ($db->Exec ("update authors set " . $sql . "where pk = $fk_authors")) {
msg ("Author modified !");
} else {
error_msg ("Could not modify author !");
}
}
}
if (isupdatemode ("delete")) {
$db->Exec ("delete from aliases where fk_authors = $fk_authors");
$db->Exec ("delete from author_urls where fk_authors = $fk_authors");
if ($db->Exec ("delete from authors where pk = $fk_authors")) {
msg ("Author deleted !");
$fk_authors = null;
} else {
error_msg ("Could not delete author !");
}
}
if (isupdate ()) {
if ($fk_authors)
p ("<a href=\"author?mode=edit&amp;fk_authors=$fk_authors\">" .
"Back to Author</a>");
} else {
$f->Output ($caption, $caption);
if (ismode ("edit")) {
$db->exec ("select * from authors where pk = $fk_authors");
if ($db->FirstRow ()) {
$author_from = $db->Get ("author", SQLCHAR);
p ("<a href=\"authors_list?author_from=$author_from&amp;" .
"fk_authors_from=$fk_authors\">Transfer&nbsp;Books</a>");
}
p("<a href=\"author?mode=delete&fk_authors=$fk_authors\">" .
"Delete Author</a>");
$db->exec ("select * from aliases where fk_authors = $fk_authors;");
$db->calcfields ["c_alias_heading"] = new CalcFieldAliasHeading ();
$table = new ListAliasesTable ();
$table->PrintTable ($db, "Aliases");
$db->exec ("select * from author_urls where fk_authors = $fk_authors;");
$table = new ListAuthorUrlsTable ();
$table->PrintTable ($db, "URLs");
$db->exec ("select * from v_books where fk_authors = $fk_authors order by title;");
$table = new ListBooksTable ();
$table->PrintTable ($db, "Books");
}
}
pagefooter ();
// Local Variables:
// mode:php
// coding:utf-8-unix
// fill-column: 75
// End:
?>

181
catalog/admin/author.php~ Normal file
View File

@ -0,0 +1,181 @@
<?php
include_once ("pgcat.phh");
authenticate ();
getstr ("mode");
$caption = ucfirst ($mode) . " Author";
pageheader ($caption);
getstr ("msg");
getstr ("errormsg");
if (!empty ($msg)) msg ($msg);
if (!empty ($errormsg)) error_msg ($msg);
include_once ("sqlform.phh");
class ListAliasesTable extends ListTable {
function __construct () {
global $fk_authors;
$prefix = "<a href=\"alias?fk_authors=$fk_authors&mode";
$this->AddColumn ("$prefix=edit&fk_aliases=#pk#\">Edit</a>",
"$prefix=add\">Add</a>", "narrow");
$this->AddColumn ("$prefix=delete&fk_aliases=#pk#\">Delete</a>", "", "narrow");
$this->AddSimpleColumn ("alias", "Alias");
$this->AddSimpleColumn ("c_alias_heading", "Heading", "narrow");
$this->AddSubCaption
("Less prominent names and pseudonyms the author is also known under, " .
"ASCII-fied versions, variant orthographies, common mis-spellings (Gutenburg).");
}
}
class ListAuthorUrlsTable extends ListTable {
function __construct () {
global $fk_authors;
$prefix = "<a href=\"author_url?fk_authors=$fk_authors&mode";
$this->AddColumn ("$prefix=edit&fk_author_urls=#pk#\">Edit</a>",
"$prefix=add\">Add</a>", "narrow");
$this->AddColumn ("$prefix=delete&fk_author_urls=#pk#\">Delete</a>", "", "narrow");
$this->AddSimpleColumn ("description", "Description");
$this->AddSimpleColumn ("url", "URL");
$this->AddSubCaption ("Interesting sites about the author.");
}
}
class ListBooksTable extends ListTable {
function __construct () {
$this->AddColumn ("<a href=\"book?mode=edit&fk_books=#fk_books#\">#fk_books#</a>",
"Etext Nr.", "narrow right");
$this->AddSimpleColumn ("title", "Title");
$this->AddSimpleColumn ("lang", "Language", "narrow");
$this->AddSimpleColumn ("role", "Role", "narrow");
$this->AddSubCaption ("Books linked to author.");
}
}
$db = $config->db ();
$db->logger = new logger ();
$f = new SQLForm ();
getint ("fk_authors");
if (ismode ("delete")) {
$db->Exec ("select count (*) as cnt from mn_books_authors where fk_authors = $fk_authors");
$cnt = $db->get ("cnt");
if ($cnt > 0) {
error_msg ("There are still $cnt books related to this author. " .
"You must delete them first.");
}
$db->Exec ("select author from authors where pk = $fk_authors");
$author = $db->get("author");
$f->SubCaption ("You are about to delete author: $author.");
$f->SubCaption ("Press the '$caption' button to continue or " .
"hit the back button on your browser to dismiss.");
} else {
print "<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><h1>editing</h1>\n";
$f->SubCaption ("The best-known name or pseudonym and other data.");
$f->Text ("author", "author", "Name", SQLCHAR, 80, 240, true);
$f->ToolTip ("Enter the name or pseudonym the author is best known under. " .
"Put lesser known names or pseudonyms in aliases. " .
"Use full unicode here and put an ASCII-fied version in aliases." .
"(eg. Brontë, Charlotte)");
$f->Text ("born_floor", "born_floor", "Born (earliest)", SQLINT, 12, 12, false);
$f->ToolTip ("Year the author was born (earliest estimate). Leave empty if unknown. ".
"(eg. 1803, -250)");
$f->Text ("born_ceil", "born_ceil", "Born (latest)", SQLINT, 12, 12, false);
$f->ToolTip ("Year the author was born (latest estimate). Leave empty if unknown. ".
"(eg. 1803, -250)");
$f->Text ("died_floor", "died_floor", "Died (earliest)", SQLINT, 12, 12, false);
$f->ToolTip ("Year the author died (earliest estimate). Leave empty if unknown. ".
"(eg. 1803, -250)");
$f->Text ("died_ceil", "died_ceil", "Died (latest)", SQLINT, 12, 12, false);
$f->ToolTip ("Year the author died (latest estimate). Leave empty if unknown. ".
"(eg. 1803, -250)");
$f->TextArea ("note", "note", "Note", SQLCHAR, 4, 80, false);
$f->ToolTip ("Any note relevant to the cataloging people.");
$f->LoadData ("select * from authors where pk = $fk_authors");
}
$f->Hidden ("fk_authors");
if (isupdatemode ("add")) {
if ($f->Check ()) {
$sql = $f->mkInsert ($db->GetFormatter ());
if ($db->Exec ("insert into authors " . $sql)) {
msg ("Author added !");
} else {
error_msg ("Could not add Author!");
}
}
}
if (isupdatemode ("edit")) {
if ($f->Check ()) {
$sql = $f->mkUpdate ($db->GetFormatter ());
if ($db->Exec ("update authors set " . $sql . "where pk = $fk_authors")) {
msg ("Author modified !");
} else {
error_msg ("Could not modify author !");
}
}
}
if (isupdatemode ("delete")) {
$db->Exec ("delete from aliases where fk_authors = $fk_authors");
$db->Exec ("delete from author_urls where fk_authors = $fk_authors");
if ($db->Exec ("delete from authors where pk = $fk_authors")) {
msg ("Author deleted !");
$fk_authors = null;
} else {
error_msg ("Could not delete author !");
}
}
if (isupdate ()) {
if ($fk_authors)
p ("<a href=\"author?mode=edit&amp;fk_authors=$fk_authors\">" .
"Back to Author</a>");
} else {
$f->Output ($caption, $caption);
if (ismode ("edit")) {
$db->exec ("select * from authors where pk = $fk_authors");
if ($db->FirstRow ()) {
$author_from = $db->Get ("author", SQLCHAR);
p ("<a href=\"authors_list?author_from=$author_from&amp;" .
"fk_authors_from=$fk_authors\">Transfer&nbsp;Books</a>");
}
p("<a href=\"author?mode=delete&fk_authors=$fk_authors\">" .
"Delete Author</a>");
$db->exec ("select * from aliases where fk_authors = $fk_authors;");
$db->calcfields ["c_alias_heading"] = new CalcFieldAliasHeading ();
$table = new ListAliasesTable ();
$table->PrintTable ($db, "Aliases");
$db->exec ("select * from author_urls where fk_authors = $fk_authors;");
$table = new ListAuthorUrlsTable ();
$table->PrintTable ($db, "URLs");
$db->exec ("select * from v_books where fk_authors = $fk_authors order by title;");
$table = new ListBooksTable ();
$table->PrintTable ($db, "Books");
}
}
pagefooter ();
// Local Variables:
// mode:php
// coding:utf-8-unix
// fill-column: 75
// End:
?>

View File

@ -0,0 +1,72 @@
<?php
set_include_path(get_include_path() . PATH_SEPARATOR . "/public/vhost/g/gutenberg/dev/private/lib/php");
include_once ("pgcat.phh");
authenticate ();
getstr ("mode");
$caption = ucfirst ($mode) . " Author URL";
pageheader ($caption);
include_once ("sqlform.phh");
$db = $config->db ();
$db->logger = new logger ();
$f = new SQLForm ();
getint ("fk_author_urls");
if (ismode ("delete")) {
$f->SubCaption ("You are about to delete this URL.");
$f->SubCaption ("Press the '$caption' button to continue or " .
"hit the back button on your browser to dismiss.");
} else {
if (ismode ("add")) {
$f->SQLInject ("fk_authors", "fk_authors", SQLINT);
}
$f->Text ("description", "description", "Description", SQLCHAR, 80, 240, true);
$f->Text ("url", "url", "URL", SQLCHAR, 80, 240, true);
$f->LoadData ("select * from author_urls where pk = $fk_author_urls");
}
$f->Hidden ("fk_author_urls");
$f->Hidden ("fk_authors");
if (isupdatemode ("add")) {
if ($f->Check ()) {
$sql = $f->mkInsert ($db->GetFormatter ());
if ($db->Exec ("insert into author_urls " . $sql)) {
msg ("Author URL added !");
} else {
error_msg ("Could not add author URL!");
}
}
}
if (isupdatemode ("edit")) {
if ($f->Check ()) {
$sql = $f->mkUpdate ($db->GetFormatter ());
if ($db->Exec ("update author_urls set " . $sql . "where pk = $fk_author_urls")) {
msg ("Author URL modified !");
} else {
error_msg ("Could not modify author URL !");
}
}
}
if (isupdatemode ("delete")) {
if ($db->Exec ("delete from author_urls where pk = $fk_author_urls")) {
msg ("Author URL deleted !");
} else {
error_msg ("Could not delete author URL !");
}
}
if (isupdate ()) {
getint ("fk_authors");
echo ("<p><a href=\"author?mode=edit&fk_authors=$fk_authors\">Back to Author</a></p>\n\n");
} else {
$f->Output ($caption, $caption);
}
pagefooter ();
?>

View File

@ -0,0 +1,71 @@
<?php
include_once ("pgcat.phh");
authenticate ();
getstr ("mode");
$caption = ucfirst ($mode) . " Author URL";
pageheader ($caption);
include_once ("sqlform.phh");
$db = $config->db ();
$db->logger = new logger ();
$f = new SQLForm ();
getint ("fk_author_urls");
if (ismode ("delete")) {
$f->SubCaption ("You are about to delete this URL.");
$f->SubCaption ("Press the '$caption' button to continue or " .
"hit the back button on your browser to dismiss.");
} else {
if (ismode ("add")) {
$f->SQLInject ("fk_authors", "fk_authors", SQLINT);
}
$f->Text ("description", "description", "Description", SQLCHAR, 80, 240, true);
$f->Text ("url", "url", "URL", SQLCHAR, 80, 240, true);
$f->LoadData ("select * from author_urls where pk = $fk_author_urls");
}
$f->Hidden ("fk_author_urls");
$f->Hidden ("fk_authors");
if (isupdatemode ("add")) {
if ($f->Check ()) {
$sql = $f->mkInsert ($db->GetFormatter ());
if ($db->Exec ("insert into author_urls " . $sql)) {
msg ("Author URL added !");
} else {
error_msg ("Could not add author URL!");
}
}
}
if (isupdatemode ("edit")) {
if ($f->Check ()) {
$sql = $f->mkUpdate ($db->GetFormatter ());
if ($db->Exec ("update author_urls set " . $sql . "where pk = $fk_author_urls")) {
msg ("Author URL modified !");
} else {
error_msg ("Could not modify author URL !");
}
}
}
if (isupdatemode ("delete")) {
if ($db->Exec ("delete from author_urls where pk = $fk_author_urls")) {
msg ("Author URL deleted !");
} else {
error_msg ("Could not delete author URL !");
}
}
if (isupdate ()) {
getint ("fk_authors");
echo ("<p><a href=\"author?mode=edit&fk_authors=$fk_authors\">Back to Author</a></p>\n\n");
} else {
$f->Output ($caption, $caption);
}
pagefooter ();
?>

View File

@ -0,0 +1,74 @@
<?php
set_include_path(get_include_path() . PATH_SEPARATOR . "/public/vhost/g/gutenberg/dev/private/lib/php");
include_once ("pgcat.phh");
authenticate ();
getstr ("filter");
getstr ("author_from");
getint ("fk_authors_from");
if ($fk_authors_from) {
pageheader ($caption = "Transfer Books $filter");
p ("Transferring all books from $author_from to:");
} else {
pageheader ($caption = "Authors $filter");
}
class ListAuthorsTable extends ListTable {
function __construct () {
global $fk_authors_from, $author_from, $filter;
$this->AddColumn ("<a href=\"author?mode=edit&fk_authors=#pk#\">Edit</a>",
"<a href=\"author?mode=add\">Add</a>", "narrow");
$this->AddColumn ("<a href=\"author?mode=delete&fk_authors=#pk#\">Delete</a>",
"", "narrow");
if ($fk_authors_from) {
$this->AddColumn ("<a href=\"authors_transfer?author_from=$author_from&amp;author_to=#author#&amp;" .
"fk_authors_from=$fk_authors_from&amp;fk_authors_to=#pk#\">Transfer&nbsp;To</a>",
"", "narrow");
$this->TitleColumn ("Transfer all books linked to $author_from to this one.");
} else {
$this->AddColumn ("<a href=\"authors_list?author_from=#author#&amp;" .
"fk_authors_from=#pk#&amp;filter=$filter\">Transfer&nbsp;From</a>",
"", "narrow");
$this->TitleColumn ("Transfer all books linked to this author to a different one.");
}
$this->AddSimpleColumn ("author", "Name");
$this->AddSimpleColumn ("cnt_books", "No. of Books", "narrow right");
$this->AddSimpleColumn ("born_floor", "Born", "narrow right");
$this->AddSimpleColumn ("died_floor", "Died", "narrow right");
}
}
$db = $config->db ();
echo ("
<p>Please enter the first few characters of the authors name (at least one).
Search is case-insensitive.
Use * as wildcard. (eg. Moli*re)
To see everything just enter *.</p>
");
form_open ();
echo (" <input type=\"text\" name=\"filter\" value=\"$filter\"/>\n");
form_hidden ("fk_authors_from", $fk_authors_from);
form_hidden ("author_from", $author_from);
form_submit ("Search");
form_close ();
if ($filter != "") {
$sql_filter = str_replace ('*', '%', $filter);
$sql_filter = $db->f ("$sql_filter%", SQLCHAR);
$db->exec ("select *, (select count (*) from mn_books_authors where fk_authors = authors.pk) as cnt_books from authors where " .
"(author ilike $sql_filter or authors.pk in " .
"(select fk_authors from aliases where alias ilike $sql_filter)) " .
"order by author");
$table = new ListAuthorsTable ();
$table->PrintTable ($db, $caption, "pgdbfiles");
}
pagefooter ();
?>

View File

@ -0,0 +1,73 @@
<?php
include_once ("pgcat.phh");
authenticate ();
getstr ("filter");
getstr ("author_from");
getint ("fk_authors_from");
if ($fk_authors_from) {
pageheader ($caption = "Transfer Books $filter");
p ("Transferring all books from $author_from to:");
} else {
pageheader ($caption = "Authors $filter");
}
class ListAuthorsTable extends ListTable {
function __construct () {
global $fk_authors_from, $author_from, $filter;
$this->AddColumn ("<a href=\"author?mode=edit&fk_authors=#pk#\">Edit</a>",
"<a href=\"author?mode=add\">Add</a>", "narrow");
$this->AddColumn ("<a href=\"author?mode=delete&fk_authors=#pk#\">Delete</a>",
"", "narrow");
if ($fk_authors_from) {
$this->AddColumn ("<a href=\"authors_transfer?author_from=$author_from&amp;author_to=#author#&amp;" .
"fk_authors_from=$fk_authors_from&amp;fk_authors_to=#pk#\">Transfer&nbsp;To</a>",
"", "narrow");
$this->TitleColumn ("Transfer all books linked to $author_from to this one.");
} else {
$this->AddColumn ("<a href=\"authors_list?author_from=#author#&amp;" .
"fk_authors_from=#pk#&amp;filter=$filter\">Transfer&nbsp;From</a>",
"", "narrow");
$this->TitleColumn ("Transfer all books linked to this author to a different one.");
}
$this->AddSimpleColumn ("author", "Name");
$this->AddSimpleColumn ("cnt_books", "No. of Books", "narrow right");
$this->AddSimpleColumn ("born_floor", "Born", "narrow right");
$this->AddSimpleColumn ("died_floor", "Died", "narrow right");
}
}
$db = $config->db ();
echo ("
<p>Please enter the first few characters of the authors name (at least one).
Search is case-insensitive.
Use * as wildcard. (eg. Moli*re)
To see everything just enter *.</p>
");
form_open ();
echo (" <input type=\"text\" name=\"filter\" value=\"$filter\"/>\n");
form_hidden ("fk_authors_from", $fk_authors_from);
form_hidden ("author_from", $author_from);
form_submit ("Search");
form_close ();
if ($filter != "") {
$sql_filter = str_replace ('*', '%', $filter);
$sql_filter = $db->f ("$sql_filter%", SQLCHAR);
$db->exec ("select *, (select count (*) from mn_books_authors where fk_authors = authors.pk) as cnt_books from authors where " .
"(author ilike $sql_filter or authors.pk in " .
"(select fk_authors from aliases where alias ilike $sql_filter)) " .
"order by author");
$table = new ListAuthorsTable ();
$table->PrintTable ($db, $caption, "pgdbfiles");
}
pagefooter ();
?>

View File

@ -0,0 +1,75 @@
<?php
set_include_path(get_include_path() . PATH_SEPARATOR . "/public/vhost/g/gutenberg/dev/private/lib/php");
include_once ("pgcat.phh");
authenticate ();
getstr ("author_from");
getstr ("author_to");
$caption = "Transfer All Books From $author_from To $author_to";
pageheader ($caption);
include_once ("sqlform.phh");
$db = $config->db ();
$db->logger = new logger ();
$f = new SQLForm ();
getint ("fk_authors_from");
getint ("fk_authors_to");
if (!$fk_authors_from) error_msg ("No From Author");
if (!$fk_authors_to) error_msg ("No To Author");
// don't test for author equality, transferring to the same author
// can be useful to batch-change the role.
// if ($fk_authors_to == $fk_authors_from) error_msg ("But that is the same author!");
if (!isupdate ()) {
$db->Exec ("select count (*) as cnt from mn_books_authors where fk_authors = $fk_authors_from");
$cnt = $db->get ("cnt");
$f->SQLSelect ("fk_roles", "fk_roles", "Author Role", SQLCHAR, 40, 40, true,
"select 'same' as value, 'Same Role' as caption union " .
"select pk as value, role as caption from roles order by caption");
$f->SetFieldData ("fk_roles", "same");
$f->SubCaption ("You are about to transfer $cnt books from $author_from to $author_to.");
$f->SubCaption ("Press the '$caption' button to continue or " .
"hit the back button on your browser to dismiss.");
}
$f->Hidden ("fk_authors_from");
$f->Hidden ("fk_authors_to");
$f->Hidden ("author_from");
$f->Hidden ("author_to");
if (isupdate ()) {
getstr ("fk_roles");
if ($fk_roles == "same") {
$sql = "update mn_books_authors set fk_authors = $fk_authors_to " .
"where fk_authors = $fk_authors_from";
} else {
$sql_fk_roles = $db->f ($fk_roles, SQLCHAR);
$sql = "update mn_books_authors set fk_authors = $fk_authors_to, fk_roles = $sql_fk_roles " .
"where fk_authors = $fk_authors_from";
}
if ($db->exec ($sql)) {
msg ("Books transferred !");
} else {
error_msg ("Could not transfer books !");
}
p ("<a href=\"author?mode=delete&fk_authors=$fk_authors_from\">Delete From Author ($author_from)</a>");
p ("<a href=\"author?mode=edit&fk_authors=$fk_authors_to\">Back to To Author ($author_to)</a>");
} else {
$f->Output ($caption, $caption);
}
pagefooter ();
// Local Variables:
// mode:php
// coding:utf-8-unix
// fill-column: 75
// End:
?>

View File

@ -0,0 +1,74 @@
<?php
include_once ("pgcat.phh");
authenticate ();
getstr ("author_from");
getstr ("author_to");
$caption = "Transfer All Books From $author_from To $author_to";
pageheader ($caption);
include_once ("sqlform.phh");
$db = $config->db ();
$db->logger = new logger ();
$f = new SQLForm ();
getint ("fk_authors_from");
getint ("fk_authors_to");
if (!$fk_authors_from) error_msg ("No From Author");
if (!$fk_authors_to) error_msg ("No To Author");
// don't test for author equality, transferring to the same author
// can be useful to batch-change the role.
// if ($fk_authors_to == $fk_authors_from) error_msg ("But that is the same author!");
if (!isupdate ()) {
$db->Exec ("select count (*) as cnt from mn_books_authors where fk_authors = $fk_authors_from");
$cnt = $db->get ("cnt");
$f->SQLSelect ("fk_roles", "fk_roles", "Author Role", SQLCHAR, 40, 40, true,
"select 'same' as value, 'Same Role' as caption union " .
"select pk as value, role as caption from roles order by caption");
$f->SetFieldData ("fk_roles", "same");
$f->SubCaption ("You are about to transfer $cnt books from $author_from to $author_to.");
$f->SubCaption ("Press the '$caption' button to continue or " .
"hit the back button on your browser to dismiss.");
}
$f->Hidden ("fk_authors_from");
$f->Hidden ("fk_authors_to");
$f->Hidden ("author_from");
$f->Hidden ("author_to");
if (isupdate ()) {
getstr ("fk_roles");
if ($fk_roles == "same") {
$sql = "update mn_books_authors set fk_authors = $fk_authors_to " .
"where fk_authors = $fk_authors_from";
} else {
$sql_fk_roles = $db->f ($fk_roles, SQLCHAR);
$sql = "update mn_books_authors set fk_authors = $fk_authors_to, fk_roles = $sql_fk_roles " .
"where fk_authors = $fk_authors_from";
}
if ($db->exec ($sql)) {
msg ("Books transferred !");
} else {
error_msg ("Could not transfer books !");
}
p ("<a href=\"author?mode=delete&fk_authors=$fk_authors_from\">Delete From Author ($author_from)</a>");
p ("<a href=\"author?mode=edit&fk_authors=$fk_authors_to\">Back to To Author ($author_to)</a>");
} else {
$f->Output ($caption, $caption);
}
pagefooter ();
// Local Variables:
// mode:php
// coding:utf-8-unix
// fill-column: 75
// End:
?>

View File

@ -0,0 +1,78 @@
<?php
set_include_path(get_include_path() . PATH_SEPARATOR . "/public/vhost/g/gutenberg/dev/private/lib/php");
include_once ("pgcat.phh");
$cli = php_sapi_name () == "cli";
if (!$cli) {
exit ();
}
$fk_books = intval ($argv[1]);
if (!$fk_books) {
exit ();
}
function output ($db, $caption) {
if ($db->FirstRow ()) {
do {
$v = $db->get ("value", SQLCHAR);
echo ("$caption: $v\n");
} while ($db->NextRow ());
}
}
$db = $config->db ();
$db->exec ("select * from books where pk = $fk_books");
if (!$db->FirstRow ()) {
exit ();
}
$release_date = $db->get ("release_date", SQLDATE);
$copyrighted = $db->get ("copyrighted", SQLINT);
echo ("Etext-Nr: $fk_books\n");
echo ("Release-Date: " . date ("M d, Y\n", $release_date));
echo ("Copyrighted: $copyrighted\n");
$db->exec ("select author, role from v_books_authors " .
"where fk_books = $fk_books");
if ($db->FirstRow ()) {
do {
$author = $db->get ("author", SQLCHAR);
$role = $db->get ("role", SQLCHAR);
echo ("$role: $author\n");
} while ($db->NextRow ());
}
$db->exec ("select title as value from titles where title_order = 1 and fk_books = $fk_books");
output ($db, "Title");
$db->exec ("select title as value from titles where title_order = 2 and fk_books = $fk_books");
output ($db, "Alternate Title");
$db->exec ("select title as value from titles where title_order = 3 and fk_books = $fk_books");
output ($db, "Contents");
$db->exec ("select note as value from notes where fk_books = $fk_books");
output ($db, "Note");
$db->exec ("select lang as value from langs, mn_books_langs " .
"where langs.pk = fk_langs and fk_books = $fk_books");
output ($db, "Language");
$db->exec ("select pk as value from loccs, mn_books_loccs " .
"where loccs.pk = fk_loccs and fk_books = $fk_books");
output ($db, "Locc");
$db->exec ("select subject as value from subjects, mn_books_subjects " .
"where subjects.pk = fk_subjects and fk_books = $fk_books");
output ($db, "Subject");
$db->exec ("select category as value from categories, mn_books_categories " .
"where categories.pk = fk_categories and fk_books = $fk_books");
output ($db, "Category");
echo ("----------\n");
?>

View File

@ -0,0 +1,77 @@
<?php
include_once ("pgcat.phh");
$cli = php_sapi_name () == "cli";
if (!$cli) {
exit ();
}
$fk_books = intval ($argv[1]);
if (!$fk_books) {
exit ();
}
function output ($db, $caption) {
if ($db->FirstRow ()) {
do {
$v = $db->get ("value", SQLCHAR);
echo ("$caption: $v\n");
} while ($db->NextRow ());
}
}
$db = $config->db ();
$db->exec ("select * from books where pk = $fk_books");
if (!$db->FirstRow ()) {
exit ();
}
$release_date = $db->get ("release_date", SQLDATE);
$copyrighted = $db->get ("copyrighted", SQLINT);
echo ("Etext-Nr: $fk_books\n");
echo ("Release-Date: " . date ("M d, Y\n", $release_date));
echo ("Copyrighted: $copyrighted\n");
$db->exec ("select author, role from v_books_authors " .
"where fk_books = $fk_books");
if ($db->FirstRow ()) {
do {
$author = $db->get ("author", SQLCHAR);
$role = $db->get ("role", SQLCHAR);
echo ("$role: $author\n");
} while ($db->NextRow ());
}
$db->exec ("select title as value from titles where title_order = 1 and fk_books = $fk_books");
output ($db, "Title");
$db->exec ("select title as value from titles where title_order = 2 and fk_books = $fk_books");
output ($db, "Alternate Title");
$db->exec ("select title as value from titles where title_order = 3 and fk_books = $fk_books");
output ($db, "Contents");
$db->exec ("select note as value from notes where fk_books = $fk_books");
output ($db, "Note");
$db->exec ("select lang as value from langs, mn_books_langs " .
"where langs.pk = fk_langs and fk_books = $fk_books");
output ($db, "Language");
$db->exec ("select pk as value from loccs, mn_books_loccs " .
"where loccs.pk = fk_loccs and fk_books = $fk_books");
output ($db, "Locc");
$db->exec ("select subject as value from subjects, mn_books_subjects " .
"where subjects.pk = fk_subjects and fk_books = $fk_books");
output ($db, "Subject");
$db->exec ("select category as value from categories, mn_books_categories " .
"where categories.pk = fk_categories and fk_books = $fk_books");
output ($db, "Category");
echo ("----------\n");
?>

336
catalog/admin/book.php Normal file
View File

@ -0,0 +1,336 @@
<?php
set_include_path(get_include_path() . PATH_SEPARATOR . "/public/vhost/g/gutenberg/dev/private/lib/php");
include_once ("pgcat.phh");
authenticate ();
getstr ("mode");
$caption = ucfirst ($mode) . " Book";
pageheader ($caption);
getstr ("msg");
getstr ("errormsg");
if (!empty ($msg)) msg ($msg);
if (!empty ($errormsg)) error_msg ($msg);
include_once ("sqlform.phh");
class ListAttributesTable extends ListTable {
function __construct () {
global $fk_books;
$prefix = "<a href=\"attribute?fk_books=$fk_books&amp;mode";
$this->AddColumn ("$prefix=edit&amp;pk=#pk#\">Edit</a>",
"$prefix=add\">Add</a>", "narrow");
$this->AddColumn ("$prefix=delete&amp;pk=#pk#\">Delete</a>", "", "narrow");
$this->AddSimpleColumn ("name", "MARC Tag");
$this->AddSimpleColumn ("indicators", "MARC Indicators", "narrow");
$this->AddSimpleColumn ("nonfiling", "Nonfiling Chars", "narrow");
$this->AddSimpleColumn ("text", "Text");
}
}
class ListMarcFieldsTable extends ListTable {
function __construct () {
global $fk_books, $fk_marcauthrecs;
$prefix = "<a href=\"mn_books_marcauthrecs?fk_books=$fk_books&amp;mode";
$this->AddColumn ("$prefix=delete&amp;fk_marcauthrecs=#fk_marcauthrecs#&amp;fk_marctags=#fk_marctags#\">Unlink</a>",
"", "narrow");
// $this->AddColumn ("$prefix=edit&amp;fk_marcauthrecs=#fk_marcauthrecs#&amp;fk_marctags=#fk_marctags#\">Edit&nbsp;Link</a>", "", "narrow");
$this->AddSimpleColumn ("name", "MARC Tag");
// $this->AddSimpleColumn ("indicators", "MARC Indicators", "narrow");
// $this->AddSimpleColumn ("nonfiling", "Nonfiling Chars", "narrow");
$this->AddSimpleColumn ("text", "Text");
}
}
class ListAuthorsTable extends ListTable {
function __construct () {
global $fk_books;
$prefix = "<a href=\"mn_books_authors?fk_books=$fk_books&amp;mode";
$this->AddColumn ("$prefix=delete&amp;fk_authors=#pk#&amp;fk_roles=#fk_roles#\">Unlink</a>",
"<a href=\"mn_books_authors_list?fk_books=$fk_books&amp;mode=add\">Link</a>",
"narrow");
$this->AddColumn ("$prefix=edit&amp;fk_authors=#pk#&amp;fk_roles=#fk_roles#\">Edit&nbsp;Link</a>",
"", "narrow");
$this->AddColumn ("<a href=\"author?mode=edit&amp;fk_authors=#pk#\">#author#</a>", "Author");
$this->AddSimpleColumn ("role", "Role", "narrow");
$this->AddSimpleColumn ("c_heading", "Heading", "narrow");
$this->AddSimpleColumn ("born_floor", "Born", "narrow right");
$this->AddSimpleColumn ("died_floor", "Died", "narrow right");
$this->AddSubCaption ("All authors for this work.");
}
}
class ListReviewsTable extends ListTable {
function __construct () {
global $fk_books;
$this->AddSubCaption ("All reviews for this work.");
$prefix = "<a href=\"review?fk_books=$fk_books&amp;mode";
$this->AddColumn ("$prefix=edit&amp;fk_reviews=#pk#\">Edit</a>",
"$prefix=add\">Add</a>", "narrow");
$this->AddColumn ("$prefix=delete&amp;fk_reviews=#pk#\">Delete</a>", "", "narrow");
$this->AddSimpleColumn ("name", "Reviewer");
$this->AddSimpleColumn ("review", "Review");
}
}
class ListCategoriesTable extends ListTable {
function __construct () {
global $fk_books;
$prefix = "<a href=\"mn_books_categories?fk_books=$fk_books&amp;mode";
$this->AddColumn ("$prefix=delete&amp;fk_categories=#pk#\">Unlink</a>",
"$prefix=add\">Link</a>", "narrow");
$this->AddSimpleColumn ("category", "Category");
$this->AddSubCaption ("All categories for this work.");
}
}
class ListSubjectsTable extends ListTable {
function __construct () {
global $fk_books;
$prefix = "<a href=\"mn_books_subjects?fk_books=$fk_books&amp;mode";
$this->AddColumn ("$prefix=delete&amp;fk_subjects=#pk#\">Unlink</a>",
"$prefix=add\">Link</a>", "narrow");
$this->AddColumn ("<a href=\"subject?fk_subjects=#pk#&amp;" .
"mode=edit\">#subject#</a>", "Subject");
//Make the subject name's clickable links to the edit & list of books page
$this->AddColumn ("#pk#", "#", "narrow");
//List the Internal Code #.
$this->AddSubCaption ("All subjects for this work.");
}
}
class ListLangsTable extends ListTable {
function __construct () {
global $fk_books;
$prefix = "<a href=\"mn_books_langs?fk_books=$fk_books&amp;mode";
$this->AddColumn ("$prefix=delete&amp;fk_langs=#pk#\">Unlink</a>",
"$prefix=add\">Link</a>", "narrow");
$this->AddSimpleColumn ("lang", "Language");
$this->AddSubCaption ("Languages of all major sections in this work.");
}
}
class ListLoccsTable extends ListTable {
function __construct () {
global $fk_books;
$prefix = "<a href=\"mn_books_loccs?fk_books=$fk_books&amp;mode";
$this->AddColumn ("$prefix=delete&amp;fk_loccs=#pk#\">Unlink</a>",
"$prefix=add\">Link</a>", "narrow");
$this->AddSimpleColumn("pk", "Code");
$this->AddSimpleColumn ("locc", "LoC class");
$this->AddSubCaption ("All LoC Classes this work falls into.");
}
}
$db = $config->db ();
$db->logger = new logger ();
$f = new SQLForm ();
getint ("fk_books");
if (ismode ("delete")) {
$f->SubCaption ("You are about to delete this book.");
$f->SubCaption ("Press the '$caption' button to continue or hit " .
"the back button on your browser to dismiss.");
} else {
$f->Text ("pk", "pk", "EText Nr.", SQLINT, 20, 5, true);
$f->ToolTip ("Enter the ebook number.");
$f->Text ("release_date", "release_date", "Release Date", SQLCHAR, 20, 20, false);
$f->ToolTip ("Enter the official release date.");
$f->CheckBox ("copyrighted", "copyrighted", "Copyrighted", SQLINT);
$f->ToolTip ("Check if book is copyrighted.");
$f->CheckBox ("updatemode", "updatemode", "Manual Update", SQLINT);
$f->ToolTip ("Check if book is manually updated.");
$f->LoadData ("select * from books where pk = $fk_books");
}
$f->Hidden ("fk_books");
if (isupdatemode ("add")) {
if ($f->Check ()) {
$sql = $f->mkInsert ($db->GetFormatter ());
if ($db->Exec ("insert into books " . $sql)) {
msg ("Book added !");
} else {
error_msg ("Could not add Book!");
}
}
}
if (isupdatemode ("edit")) {
if ($f->Check ()) {
$sql = $f->mkUpdate ($db->GetFormatter ());
// set manually updated mode
if ($db->Exec ("update books set " . $sql . "where pk = $fk_books")) {
msg ("Book modified !");
} else {
error_msg ("Could not modify book !");
}
}
}
if (isupdatemode ("delete")) {
$db->exec ("delete from files where fk_books = $fk_books");
$db->exec ("delete from attributes where fk_books = $fk_books");
$db->exec ("delete from reviews.reviews where fk_books = $fk_books");
$db->Exec ("delete from mn_books_authors where fk_books = $fk_books");
$db->Exec ("delete from mn_books_langs where fk_books = $fk_books");
$db->Exec ("delete from mn_books_loccs where fk_books = $fk_books");
$db->Exec ("delete from mn_books_subjects where fk_books = $fk_books");
$db->Exec ("delete from mn_books_categories where fk_books = $fk_books");
if ($db->Exec ("delete from books where pk = $fk_books")) {
msg ("Book deleted !");
} else {
error_msg ("Could not delete book !");
}
}
if (isupdate ()) {
getint ("fk_books");
echo (" <p><a href=\"book?mode=edit&amp;fk_books=$fk_books\">Back to Book</a></p>\n\n");
} else {
$f->Output ($caption, $caption);
if (ismode ("edit")) {
p ("<a href=\"files?fk_books=$fk_books\">Goto Edit Files Page</a> &mdash; " .
"<a href=\"$config->etext/${fk_books}#bibrec\">Goto Bibrec Page</a> &mdash; " .
"<a href=\"$config->etext/${fk_books}#download\">Goto Bibrec Download Page</a>");
$db->exec ("select gutindex from books where pk = $fk_books");
if ($db->FirstRow ()) {
$gutindex = $db->get ("gutindex", SQLCHAR);
if (!empty ($gutindex)) {
echo ("<pre class=\"boxed\">$gutindex</pre>\n");
}
}
// Authors for book
$db->exec ("select authors.pk as pk, author, heading, born_floor, died_floor, " .
"fk_roles, role " .
"from authors, mn_books_authors, roles " .
"where authors.pk = mn_books_authors.fk_authors " .
"and mn_books_authors.fk_roles = roles.pk " .
"and mn_books_authors.fk_books = $fk_books " .
"order by author;");
$db->calcfields ["c_heading"] = new CalcFieldHeading ();
$table = new ListAuthorsTable ();
$table->PrintTable ($db, "Authors", "pgdbdata");
p ("<a href=\"http://www.loc.gov/marc/umb/um07to10.html\">A Summary of Commonly Used MARC 21 Fields</a>");
// Uncontrolled Fields for book
$db->exec ("select attributes.*, attriblist.name from attributes, attriblist " .
"where attributes.fk_books = $fk_books and " .
"attributes.fk_attriblist = attriblist.pk " .
"order by attriblist.name;");
$table = new ListAttributesTable ();
$table->PrintTable ($db, "Uncontrolled MARC 21 Fields", "pgdbdata");
// Controlled Fields for book
// $db->exec ("select marcfields.text, marctags.name, mn_books_marcauthrecs.* " .
// "from mn_books_marcauthrecs, marcfields, marctags " .
// "where mn_books_marcauthrecs.fk_books = $fk_books " .
// "and marcfields.fk_marcauthrecs = mn_books_marcauthrecs.fk_marcauthrecs " .
// "and marctags.pk = mn_books_marcauthrecs.fk_marctags " .
// "and marcfields.fk_marctags like 'A1%' order by marctags.name, marcfields.text;");
// $table = new ListMarcFieldsTable ();
// $table->PrintTable ($db, "Controlled MARC 21 Fields", "pgdbdata");
// $f2 = new SQLForm ("mn_books_marcauthrecs", "get");
// $f2->KeySelect ("fk_marctags", "fk_marctags", "Tag to Link", SQLCHAR, 40, 40, true);
// $f2->last->LoadSQL ("select pk as key, name as caption from marctags where pk like 'B%' and type IS NOT NULL and not exists (select * from mn_books_marcauthrecs as mnm, marctags as mt where mnm.fk_books = $fk_books and mnm.fk_marctags = mt.pk and mt.excludes = marctags.excludes) order by name");
// $f2->last->DefValue ("B100");
// $f2->last->ToolTip ("Select a Bibliographic MARC Tag.");
// $f2->Hidden ("fk_books");
// $f2->Hidden ("mode", "add");
// $f2->Hidden ("step", "first");
// $f2->Output ("Link Controlled Field", "Link Controlled Field");
// Categories for book
$db->exec ("select * from categories, mn_books_categories " .
"where categories.pk = mn_books_categories.fk_categories " .
"and mn_books_categories.fk_books =$fk_books " .
"order by category;");
$table = new ListCategoriesTable ();
$table->PrintTable ($db, "Categories", "pgdbdata");
// Subjects for book
$db->exec ("select * from subjects, mn_books_subjects " .
"where subjects.pk = mn_books_subjects.fk_subjects " .
"and mn_books_subjects.fk_books =$fk_books " .
"order by subject;");
$table = new ListSubjectsTable ();
$table->PrintTable ($db, "Subjects", "pgdbdata");
form_open ("mn_books_subjects");
form_hidden ("mode", "add");
form_hidden ("step", "update");
form_hidden ("fk_books", $fk_books);
echo ("Quick link subject: <input type=\"text\" name=\"fk_subjects\" size=\"5\"> Use internal subject #!\n");
form_submit ("Link Subject");
echo ("(See \"#\" column above.)");
form_close ();
// Languages for book
$db->exec ("select langs.pk as pk, lang from langs, mn_books_langs " .
"where mn_books_langs.fk_langs = langs.pk " .
"and fk_books = $fk_books order by lang;");
$table = new ListLangsTable ();
$table->PrintTable ($db, "Languages", "pgdbdata");
form_open ("mn_books_langs");
form_hidden ("mode", "add");
form_hidden ("step", "update");
form_hidden ("fk_books", $fk_books);
echo ("Quick link language: <input type=\"text\" name=\"fk_langs\" size=\"3\"> Use 2-letter code!\n");
form_submit ("Link Language");
form_close ();
// LoCCs for book
$db->exec ("select loccs.pk as pk, locc from loccs, mn_books_loccs " .
"where mn_books_loccs.fk_loccs = loccs.pk " .
"and fk_books = $fk_books order by locc;");
$table = new ListLoccsTable ();
$table->PrintTable ($db, "LoC Classes", "pgdbdata");
form_open ("mn_books_loccs");
form_hidden ("mode", "add");
form_hidden ("step", "update");
form_hidden ("fk_books", $fk_books);
echo ("Quick link LoC class: <input type=\"text\" name=\"fk_loccs\" size=\"5\"> Use code!\n");
form_submit ("Link LoC Class");
form_close ();
// Reviews for book
$db->exec ("select reviews.reviews.*, reviews.reviewers.name from reviews.reviews, reviews.reviewers where fk_books = $fk_books and reviews.reviewers.pk = reviews.reviews.fk_reviewers;");
$table = new ListReviewsTable ();
$table->PrintTable ($db, "Reviews", "pgdbdata");
}
}
pagefooter ();
// Local Variables:
// mode:php
// coding:utf-8-unix
// fill-column: 75
// End:
?>

335
catalog/admin/book.php~ Normal file
View File

@ -0,0 +1,335 @@
<?php
include_once ("pgcat.phh");
authenticate ();
getstr ("mode");
$caption = ucfirst ($mode) . " Book";
pageheader ($caption);
getstr ("msg");
getstr ("errormsg");
if (!empty ($msg)) msg ($msg);
if (!empty ($errormsg)) error_msg ($msg);
include_once ("sqlform.phh");
class ListAttributesTable extends ListTable {
function __construct () {
global $fk_books;
$prefix = "<a href=\"attribute?fk_books=$fk_books&amp;mode";
$this->AddColumn ("$prefix=edit&amp;pk=#pk#\">Edit</a>",
"$prefix=add\">Add</a>", "narrow");
$this->AddColumn ("$prefix=delete&amp;pk=#pk#\">Delete</a>", "", "narrow");
$this->AddSimpleColumn ("name", "MARC Tag");
$this->AddSimpleColumn ("indicators", "MARC Indicators", "narrow");
$this->AddSimpleColumn ("nonfiling", "Nonfiling Chars", "narrow");
$this->AddSimpleColumn ("text", "Text");
}
}
class ListMarcFieldsTable extends ListTable {
function __construct () {
global $fk_books, $fk_marcauthrecs;
$prefix = "<a href=\"mn_books_marcauthrecs?fk_books=$fk_books&amp;mode";
$this->AddColumn ("$prefix=delete&amp;fk_marcauthrecs=#fk_marcauthrecs#&amp;fk_marctags=#fk_marctags#\">Unlink</a>",
"", "narrow");
// $this->AddColumn ("$prefix=edit&amp;fk_marcauthrecs=#fk_marcauthrecs#&amp;fk_marctags=#fk_marctags#\">Edit&nbsp;Link</a>", "", "narrow");
$this->AddSimpleColumn ("name", "MARC Tag");
// $this->AddSimpleColumn ("indicators", "MARC Indicators", "narrow");
// $this->AddSimpleColumn ("nonfiling", "Nonfiling Chars", "narrow");
$this->AddSimpleColumn ("text", "Text");
}
}
class ListAuthorsTable extends ListTable {
function __construct () {
global $fk_books;
$prefix = "<a href=\"mn_books_authors?fk_books=$fk_books&amp;mode";
$this->AddColumn ("$prefix=delete&amp;fk_authors=#pk#&amp;fk_roles=#fk_roles#\">Unlink</a>",
"<a href=\"mn_books_authors_list?fk_books=$fk_books&amp;mode=add\">Link</a>",
"narrow");
$this->AddColumn ("$prefix=edit&amp;fk_authors=#pk#&amp;fk_roles=#fk_roles#\">Edit&nbsp;Link</a>",
"", "narrow");
$this->AddColumn ("<a href=\"author?mode=edit&amp;fk_authors=#pk#\">#author#</a>", "Author");
$this->AddSimpleColumn ("role", "Role", "narrow");
$this->AddSimpleColumn ("c_heading", "Heading", "narrow");
$this->AddSimpleColumn ("born_floor", "Born", "narrow right");
$this->AddSimpleColumn ("died_floor", "Died", "narrow right");
$this->AddSubCaption ("All authors for this work.");
}
}
class ListReviewsTable extends ListTable {
function __construct () {
global $fk_books;
$this->AddSubCaption ("All reviews for this work.");
$prefix = "<a href=\"review?fk_books=$fk_books&amp;mode";
$this->AddColumn ("$prefix=edit&amp;fk_reviews=#pk#\">Edit</a>",
"$prefix=add\">Add</a>", "narrow");
$this->AddColumn ("$prefix=delete&amp;fk_reviews=#pk#\">Delete</a>", "", "narrow");
$this->AddSimpleColumn ("name", "Reviewer");
$this->AddSimpleColumn ("review", "Review");
}
}
class ListCategoriesTable extends ListTable {
function __construct () {
global $fk_books;
$prefix = "<a href=\"mn_books_categories?fk_books=$fk_books&amp;mode";
$this->AddColumn ("$prefix=delete&amp;fk_categories=#pk#\">Unlink</a>",
"$prefix=add\">Link</a>", "narrow");
$this->AddSimpleColumn ("category", "Category");
$this->AddSubCaption ("All categories for this work.");
}
}
class ListSubjectsTable extends ListTable {
function __construct () {
global $fk_books;
$prefix = "<a href=\"mn_books_subjects?fk_books=$fk_books&amp;mode";
$this->AddColumn ("$prefix=delete&amp;fk_subjects=#pk#\">Unlink</a>",
"$prefix=add\">Link</a>", "narrow");
$this->AddColumn ("<a href=\"subject?fk_subjects=#pk#&amp;" .
"mode=edit\">#subject#</a>", "Subject");
//Make the subject name's clickable links to the edit & list of books page
$this->AddColumn ("#pk#", "#", "narrow");
//List the Internal Code #.
$this->AddSubCaption ("All subjects for this work.");
}
}
class ListLangsTable extends ListTable {
function __construct () {
global $fk_books;
$prefix = "<a href=\"mn_books_langs?fk_books=$fk_books&amp;mode";
$this->AddColumn ("$prefix=delete&amp;fk_langs=#pk#\">Unlink</a>",
"$prefix=add\">Link</a>", "narrow");
$this->AddSimpleColumn ("lang", "Language");
$this->AddSubCaption ("Languages of all major sections in this work.");
}
}
class ListLoccsTable extends ListTable {
function __construct () {
global $fk_books;
$prefix = "<a href=\"mn_books_loccs?fk_books=$fk_books&amp;mode";
$this->AddColumn ("$prefix=delete&amp;fk_loccs=#pk#\">Unlink</a>",
"$prefix=add\">Link</a>", "narrow");
$this->AddSimpleColumn("pk", "Code");
$this->AddSimpleColumn ("locc", "LoC class");
$this->AddSubCaption ("All LoC Classes this work falls into.");
}
}
$db = $config->db ();
$db->logger = new logger ();
$f = new SQLForm ();
getint ("fk_books");
if (ismode ("delete")) {
$f->SubCaption ("You are about to delete this book.");
$f->SubCaption ("Press the '$caption' button to continue or hit " .
"the back button on your browser to dismiss.");
} else {
$f->Text ("pk", "pk", "EText Nr.", SQLINT, 20, 5, true);
$f->ToolTip ("Enter the ebook number.");
$f->Text ("release_date", "release_date", "Release Date", SQLCHAR, 20, 20, false);
$f->ToolTip ("Enter the official release date.");
$f->CheckBox ("copyrighted", "copyrighted", "Copyrighted", SQLINT);
$f->ToolTip ("Check if book is copyrighted.");
$f->CheckBox ("updatemode", "updatemode", "Manual Update", SQLINT);
$f->ToolTip ("Check if book is manually updated.");
$f->LoadData ("select * from books where pk = $fk_books");
}
$f->Hidden ("fk_books");
if (isupdatemode ("add")) {
if ($f->Check ()) {
$sql = $f->mkInsert ($db->GetFormatter ());
if ($db->Exec ("insert into books " . $sql)) {
msg ("Book added !");
} else {
error_msg ("Could not add Book!");
}
}
}
if (isupdatemode ("edit")) {
if ($f->Check ()) {
$sql = $f->mkUpdate ($db->GetFormatter ());
// set manually updated mode
if ($db->Exec ("update books set " . $sql . "where pk = $fk_books")) {
msg ("Book modified !");
} else {
error_msg ("Could not modify book !");
}
}
}
if (isupdatemode ("delete")) {
$db->exec ("delete from files where fk_books = $fk_books");
$db->exec ("delete from attributes where fk_books = $fk_books");
$db->exec ("delete from reviews.reviews where fk_books = $fk_books");
$db->Exec ("delete from mn_books_authors where fk_books = $fk_books");
$db->Exec ("delete from mn_books_langs where fk_books = $fk_books");
$db->Exec ("delete from mn_books_loccs where fk_books = $fk_books");
$db->Exec ("delete from mn_books_subjects where fk_books = $fk_books");
$db->Exec ("delete from mn_books_categories where fk_books = $fk_books");
if ($db->Exec ("delete from books where pk = $fk_books")) {
msg ("Book deleted !");
} else {
error_msg ("Could not delete book !");
}
}
if (isupdate ()) {
getint ("fk_books");
echo (" <p><a href=\"book?mode=edit&amp;fk_books=$fk_books\">Back to Book</a></p>\n\n");
} else {
$f->Output ($caption, $caption);
if (ismode ("edit")) {
p ("<a href=\"files?fk_books=$fk_books\">Goto Edit Files Page</a> &mdash; " .
"<a href=\"$config->etext/${fk_books}#bibrec\">Goto Bibrec Page</a> &mdash; " .
"<a href=\"$config->etext/${fk_books}#download\">Goto Bibrec Download Page</a>");
$db->exec ("select gutindex from books where pk = $fk_books");
if ($db->FirstRow ()) {
$gutindex = $db->get ("gutindex", SQLCHAR);
if (!empty ($gutindex)) {
echo ("<pre class=\"boxed\">$gutindex</pre>\n");
}
}
// Authors for book
$db->exec ("select authors.pk as pk, author, heading, born_floor, died_floor, " .
"fk_roles, role " .
"from authors, mn_books_authors, roles " .
"where authors.pk = mn_books_authors.fk_authors " .
"and mn_books_authors.fk_roles = roles.pk " .
"and mn_books_authors.fk_books = $fk_books " .
"order by author;");
$db->calcfields ["c_heading"] = new CalcFieldHeading ();
$table = new ListAuthorsTable ();
$table->PrintTable ($db, "Authors", "pgdbdata");
p ("<a href=\"http://www.loc.gov/marc/umb/um07to10.html\">A Summary of Commonly Used MARC 21 Fields</a>");
// Uncontrolled Fields for book
$db->exec ("select attributes.*, attriblist.name from attributes, attriblist " .
"where attributes.fk_books = $fk_books and " .
"attributes.fk_attriblist = attriblist.pk " .
"order by attriblist.name;");
$table = new ListAttributesTable ();
$table->PrintTable ($db, "Uncontrolled MARC 21 Fields", "pgdbdata");
// Controlled Fields for book
// $db->exec ("select marcfields.text, marctags.name, mn_books_marcauthrecs.* " .
// "from mn_books_marcauthrecs, marcfields, marctags " .
// "where mn_books_marcauthrecs.fk_books = $fk_books " .
// "and marcfields.fk_marcauthrecs = mn_books_marcauthrecs.fk_marcauthrecs " .
// "and marctags.pk = mn_books_marcauthrecs.fk_marctags " .
// "and marcfields.fk_marctags like 'A1%' order by marctags.name, marcfields.text;");
// $table = new ListMarcFieldsTable ();
// $table->PrintTable ($db, "Controlled MARC 21 Fields", "pgdbdata");
// $f2 = new SQLForm ("mn_books_marcauthrecs", "get");
// $f2->KeySelect ("fk_marctags", "fk_marctags", "Tag to Link", SQLCHAR, 40, 40, true);
// $f2->last->LoadSQL ("select pk as key, name as caption from marctags where pk like 'B%' and type IS NOT NULL and not exists (select * from mn_books_marcauthrecs as mnm, marctags as mt where mnm.fk_books = $fk_books and mnm.fk_marctags = mt.pk and mt.excludes = marctags.excludes) order by name");
// $f2->last->DefValue ("B100");
// $f2->last->ToolTip ("Select a Bibliographic MARC Tag.");
// $f2->Hidden ("fk_books");
// $f2->Hidden ("mode", "add");
// $f2->Hidden ("step", "first");
// $f2->Output ("Link Controlled Field", "Link Controlled Field");
// Categories for book
$db->exec ("select * from categories, mn_books_categories " .
"where categories.pk = mn_books_categories.fk_categories " .
"and mn_books_categories.fk_books =$fk_books " .
"order by category;");
$table = new ListCategoriesTable ();
$table->PrintTable ($db, "Categories", "pgdbdata");
// Subjects for book
$db->exec ("select * from subjects, mn_books_subjects " .
"where subjects.pk = mn_books_subjects.fk_subjects " .
"and mn_books_subjects.fk_books =$fk_books " .
"order by subject;");
$table = new ListSubjectsTable ();
$table->PrintTable ($db, "Subjects", "pgdbdata");
form_open ("mn_books_subjects");
form_hidden ("mode", "add");
form_hidden ("step", "update");
form_hidden ("fk_books", $fk_books);
echo ("Quick link subject: <input type=\"text\" name=\"fk_subjects\" size=\"5\"> Use internal subject #!\n");
form_submit ("Link Subject");
echo ("(See \"#\" column above.)");
form_close ();
// Languages for book
$db->exec ("select langs.pk as pk, lang from langs, mn_books_langs " .
"where mn_books_langs.fk_langs = langs.pk " .
"and fk_books = $fk_books order by lang;");
$table = new ListLangsTable ();
$table->PrintTable ($db, "Languages", "pgdbdata");
form_open ("mn_books_langs");
form_hidden ("mode", "add");
form_hidden ("step", "update");
form_hidden ("fk_books", $fk_books);
echo ("Quick link language: <input type=\"text\" name=\"fk_langs\" size=\"3\"> Use 2-letter code!\n");
form_submit ("Link Language");
form_close ();
// LoCCs for book
$db->exec ("select loccs.pk as pk, locc from loccs, mn_books_loccs " .
"where mn_books_loccs.fk_loccs = loccs.pk " .
"and fk_books = $fk_books order by locc;");
$table = new ListLoccsTable ();
$table->PrintTable ($db, "LoC Classes", "pgdbdata");
form_open ("mn_books_loccs");
form_hidden ("mode", "add");
form_hidden ("step", "update");
form_hidden ("fk_books", $fk_books);
echo ("Quick link LoC class: <input type=\"text\" name=\"fk_loccs\" size=\"5\"> Use code!\n");
form_submit ("Link LoC Class");
form_close ();
// Reviews for book
$db->exec ("select reviews.reviews.*, reviews.reviewers.name from reviews.reviews, reviews.reviewers where fk_books = $fk_books and reviews.reviewers.pk = reviews.reviews.fk_reviewers;");
$table = new ListReviewsTable ();
$table->PrintTable ($db, "Reviews", "pgdbdata");
}
}
pagefooter ();
// Local Variables:
// mode:php
// coding:utf-8-unix
// fill-column: 75
// End:
?>

View File

@ -0,0 +1,47 @@
<?php
set_include_path(get_include_path() . PATH_SEPARATOR . "/public/vhost/g/gutenberg/dev/private/lib/php");
include_once ("pgcat.phh");
authenticate ();
pageheader ("Books");
echo ("<h2>Search a book</h2>\n");
form_open ("books_list");
?>
<table class="dialog" cellspacing=\"2\" cellpadding=\"4\" width=\"100%\">
<colgroup><col width=\"1%\"/></colgroup>
<tr class="oddrow">
<th><label for="author" accesskey="a">Author:</label></th>
<td><input type="text" id="author" name="author"
title="Enter author name in the format: 'Brontë, Emily'." style="width: 30em"/></td>
</tr>
<tr class="evenrow">
<th><label for="title" accesskey="t">Title:</label></th>
<td><input type="text" id="title" name="title"
title="Enter title of work." style="width: 30em"/></td>
</tr>
<tr class="oddrow">
<th><label for="nr" accesskey="t">EText&nbsp;Nr.:</label></th>
<td><input type="text" id="nr" name="nr"
title="Enter EText Nr. of work." style="width: 10em"/></td>
</tr>
<tr class="evenrow">
<th></th>
<td><input type="submit" id="submit" accesskey="s" value="Search"
title="Start search"/>
<input type="reset" id="reset" accesskey="r" value="Reset"
title="Reset form"/></td>
</tr>
</table>
<?php
form_close ();
echo ("<h2><a href=\"book?mode=add\">Add a book</a></h2>\n");
pagefooter ();
?>

View File

@ -0,0 +1,45 @@
<?php
include_once ("pgcat.phh");
authenticate ();
pageheader ("Books");
echo ("<h2>Search a book</h2>\n");
form_open ("books_list");
?>
<table class="dialog" cellspacing=\"2\" cellpadding=\"4\" width=\"100%\">
<colgroup><col width=\"1%\"/></colgroup>
<tr class="oddrow">
<th><label for="author" accesskey="a">Author:</label></th>
<td><input type="text" id="author" name="author"
title="Enter author name in the format: 'Brontë, Emily'." style="width: 30em"/></td>
</tr>
<tr class="evenrow">
<th><label for="title" accesskey="t">Title:</label></th>
<td><input type="text" id="title" name="title"
title="Enter title of work." style="width: 30em"/></td>
</tr>
<tr class="oddrow">
<th><label for="nr" accesskey="t">EText&nbsp;Nr.:</label></th>
<td><input type="text" id="nr" name="nr"
title="Enter EText Nr. of work." style="width: 10em"/></td>
</tr>
<tr class="evenrow">
<th></th>
<td><input type="submit" id="submit" accesskey="s" value="Search"
title="Start search"/>
<input type="reset" id="reset" accesskey="r" value="Reset"
title="Reset form"/></td>
</tr>
</table>
<?php
form_close ();
echo ("<h2><a href=\"book?mode=add\">Add a book</a></h2>\n");
pagefooter ();
?>

View File

@ -0,0 +1,56 @@
<?php
set_include_path(get_include_path() . PATH_SEPARATOR . "/public/vhost/g/gutenberg/dev/private/lib/php");
include_once ("pgcat.phh");
authenticate ();
getstr ("author");
getstr ("title");
getint ("nr");
pageheader ($caption = "Books");
class ListBooksTable extends ListTable {
function __construct () {
$this->AddColumn ("<a href=\"book?mode=edit&fk_books=#fk_books#\">Edit</a>",
"<a href=\"book?mode=add\">Add</a>", "left", "1%");
$this->AddColumn ("<a href=\"book?mode=delete&fk_books=#fk_books#\">Delete</a>",
"", "left", "1%");
$this->AddSimpleColumn ("fk_books", "Nr.", "right", "1%");
$this->AddSimpleColumn ("author", "Author");
$this->AddSimpleColumn ("title", "Title");
}
}
$db = $config->db ();
$f = $db->GetFormatter ();
if (isset ($author)) {
$author = $f->f ("$author%", SQLCHAR);
$author = "and author ilike $author ";
}
if (isset ($title)) {
$title = $f->f ("%$title%", SQLCHAR);
$title = "and title ilike $title ";
}
if (isset ($nr)) {
$nr = $f->f ($nr, SQLINT);
$nr = "and fk_books = $nr ";
}
$where = substr ($author . $title . $nr, 4);
if (strlen ($where)) {
$where = "where $where";
$db->exec ("select * from v_books $where order by author, title");
$table = new ListBooksTable ();
$table->PrintTable ($db, $caption);
} else {
msg ("Please enter at least one search argument.");
}
pagefooter ();
?>

View File

@ -0,0 +1,55 @@
<?php
include_once ("pgcat.phh");
authenticate ();
getstr ("author");
getstr ("title");
getint ("nr");
pageheader ($caption = "Books");
class ListBooksTable extends ListTable {
function __construct () {
$this->AddColumn ("<a href=\"book?mode=edit&fk_books=#fk_books#\">Edit</a>",
"<a href=\"book?mode=add\">Add</a>", "left", "1%");
$this->AddColumn ("<a href=\"book?mode=delete&fk_books=#fk_books#\">Delete</a>",
"", "left", "1%");
$this->AddSimpleColumn ("fk_books", "Nr.", "right", "1%");
$this->AddSimpleColumn ("author", "Author");
$this->AddSimpleColumn ("title", "Title");
}
}
$db = $config->db ();
$f = $db->GetFormatter ();
if (isset ($author)) {
$author = $f->f ("$author%", SQLCHAR);
$author = "and author ilike $author ";
}
if (isset ($title)) {
$title = $f->f ("%$title%", SQLCHAR);
$title = "and title ilike $title ";
}
if (isset ($nr)) {
$nr = $f->f ($nr, SQLINT);
$nr = "and fk_books = $nr ";
}
$where = substr ($author . $title . $nr, 4);
if (strlen ($where)) {
$where = "where $where";
$db->exec ("select * from v_books $where order by author, title");
$table = new ListBooksTable ();
$table->PrintTable ($db, $caption);
} else {
msg ("Please enter at least one search argument.");
}
pagefooter ();
?>

17
catalog/admin/cat.php Normal file
View File

@ -0,0 +1,17 @@
<?php
ob_start("ob_gzhandler");
set_include_path(get_include_path() . PATH_SEPARATOR . "/public/vhost/g/gutenberg/dev/private/lib/php");
include ("pgcat.phh");
authenticate ();
getstr ("file");
header ("Content-Type: text/plain");
echo ("File: $file\n\n");
readfile ($file);
?>

16
catalog/admin/cat.php~ Normal file
View File

@ -0,0 +1,16 @@
<?php
ob_start("ob_gzhandler");
include ("pgcat.phh");
authenticate ();
getstr ("file");
header ("Content-Type: text/plain");
echo ("File: $file\n\n");
readfile ($file);
?>

View File

@ -0,0 +1,642 @@
<?php
set_include_path(get_include_path() . PATH_SEPARATOR . "/public/vhost/g/gutenberg/dev/private/lib/php");
include_once ("pgcat.phh");
$cli = php_sapi_name () == "cli";
if (!$cli) {
exit ();
}
include_once ("sqlform.phh");
echo ("after sqlform ...\n"); flush ();
$db = $config->db ();
echo ("after db () ...\n"); flush ();
$db->logger = new logger ();
echo ("Initializing ...\n"); flush ();
$db->Exec ("select pk, lang from langs");
if ($db->FirstRow ()) {
do {
$languages[$db->Get ("lang", SQLCHAR)] = $db->Get ("pk", SQLCHAR);
} while ($db->NextRow ());
}
$db->exec ("select pk, filetype from filetypes");
if ($db->FirstRow ()) {
do {
$filetypes[$db->Get ("pk", SQLCHAR)] = $db->Get ("filetype", SQLCHAR);
} while ($db->NextRow ());
}
$db->exec ("select pk, compression from compressions");
if ($db->FirstRow ()) {
do {
$compressions[$db->Get ("pk", SQLCHAR)] = $db->Get ("compression", SQLCHAR);
} while ($db->NextRow ());
}
$db->exec ("select pk from encodings");
if ($db->FirstRow ()) {
do {
$encodings[$db->Get ("pk", SQLCHAR)] = 1;
} while ($db->NextRow ());
}
$db->exec ("select pk, role from roles");
if ($db->FirstRow ()) {
do {
$roles[$db->Get ("role", SQLCHAR)] = $db->get ("pk", SQLCHAR);
} while ($db->NextRow ());
}
$importfilename = $argv[1];
if (empty ($importfilename))
$importfilename = $config->catalogupdatelog;
echo ("Processing $importfilename ...\n"); flush ();
$old_etext_number = -1;
function guess_filetype ($filename) {
// guesses filetype, encoding from filename only
//
// needs following hashes:
// usually loaded from the same tables in the database
// $filetypes: 'txt' => 'Plain text'
// $encodings: 'us-ascii'
global $filetypes, $encodings;
$extension_aliases = array (
'htm' => 'html',
'tif' => 'tiff',
'jpeg' => 'jpg',
'midi' => 'mid'
);
$ft = $enc = null;
$base = $ext = "";
$base_after_hyphen = "";
if (preg_match ("/^(.*)\.(.*)$/", $filename, $matches)) {
$base = strtolower ($matches[1]);
$ext = strtolower ($matches[2]);
}
$post10k = preg_match ("/^\d{5}(-|$)/", $base);
if (preg_match ("/-(.*)$/", $base, $matches))
$base_after_hyphen = $matches[1];
// guess filetype from file extension
if (isset ($extension_aliases[$ext])) {
$ext = $extension_aliases[$ext];
}
if (isset ($filetypes[$ext])) {
$ft = $ext;
}
if (preg_match ("/[-_]index\.html?$/i", $filename)) {
$ft = "index";
}
if (preg_match ("/readme\.txt$/i", $filename)) {
$ft = "readme";
}
if (preg_match ("/license\.txt$/i", $filename)) {
$ft = "license";
}
if (preg_match ("/page-images/i", $filename)) {
$ft = "pageimages";
}
// guess encoding from file name
if ($ext == "txt") {
if ($post10k) {
switch ($base_after_hyphen) {
case "" : $enc = "us-ascii"; break;
case "8" : $enc = "iso-8859-1"; break;
case "0" : $enc = "utf-8"; break;
case "5" : $enc = "big5"; break;
}
} else {
$enc = "us-ascii";
if (preg_match ("/^8\w.+\d\da?$/", $base))
$enc = "iso-8859-1";
if (preg_match ("/^8\w.+\d\du$/", $base))
$enc = "utf-8";
}
}
return array ($ft, $enc);
}
function fix_encoding ($encoding) {
global $encodings;
$encoding_aliases = array (
'ascii' => 'us-ascii',
'usascii' => 'us-ascii',
'iso88591' => 'iso-8859-1',
'latin1' => 'iso-8859-1',
'iso88592' => 'iso-8859-2',
'latin2' => 'iso-8859-2',
'iso88593' => 'iso-8859-3',
'latin3' => 'iso-8859-3',
'iso88594' => 'iso-8859-4',
'latin4' => 'iso-8859-4',
'iso88595' => 'iso-8859-5',
'cyrillic' => 'iso-8859-5',
'iso88596' => 'iso-8859-6',
'arabic' => 'iso-8859-6',
'iso88597' => 'iso-8859-7',
'greek' => 'iso-8859-7',
'iso88598' => 'iso-8859-8',
'hebrew' => 'iso-8859-8',
'iso88599' => 'iso-8859-9',
'latin5' => 'iso-8859-9',
'iso885910' => 'iso-8859-10',
'latin6' => 'iso-8859-10',
'iso885913' => 'iso-8859-13',
'iso885914' => 'iso-8859-14',
'latin8' => 'iso-8859-14',
'iso885915' => 'iso-8859-15',
'latin9' => 'iso-8859-15',
'iso885916' => 'iso-8859-16',
'latin10' => 'iso-8859-16',
'utf7' => 'utf-7',
'utf8' => 'utf-8',
'win1250' => 'windows-1250',
'win1251' => 'windows-1251',
'win1252' => 'windows-1252',
'win1253' => 'windows-1253',
'koi8r' => 'koi8-r'
);
$pat[] = "/[- _=<]/"; $rep[] = "";
$pat[] = "/^unicode/"; $rep[] = "";
$pat[] = "/^windowscodepage/"; $rep[] = "win";
$pat[] = "/^windows/"; $rep[] = "win";
$pat[] = "/^codepage/"; $rep[] = "win";
$pat[] = "/^cp/"; $rep[] = "win";
$pat[] = "/^isolatin/"; $rep[] = "latin";
$encoding = strtolower ($encoding);
$encoding = preg_replace ($pat, $rep, $encoding);
if (isset ($encodings[$encoding])) {
return $encoding;
}
if (isset ($encoding_aliases[$encoding])) {
return $encoding_aliases[$encoding];
}
if (strpos ($encoding, "iso88591")) {
$encoding = "iso-8859-1";
} elseif (strpos ($encoding, "utf8")) {
$encoding = "utf-8";
} else {
$encoding = null;
// print ("#$nr: unknown encoding $enc\n");
}
return $encoding;
}
function encode_language ($l) {
global $languages;
$l = ucfirst ($l);
if (isset ($languages[$l])) {
return $languages[$l];
}
return null;
}
function decode_author ($whole) {
global $roles;
$parts = preg_split ("/ *, */", $whole);
$names = array ();
$name = "";
$born = null;
$died = null;
$role = "aut";
foreach ($parts as $part) {
if (empty ($part))
continue;
if (preg_match ("/^(\d+\??)-(\d*\??)$/", $part, $matches)) {
$born = "$matches[1]";
$died = "$matches[2]";
continue;
}
if (preg_match ("/^-(\d+)$/", $part, $matches)) {
$died = "$matches[1]";
continue;
}
if (isset ($roles[$part])) {
$role = $roles[$part];
continue;
}
array_push ($names, $part);
}
return array (join (", ", $names), $born, $died, $role);
}
function insert_author ($author, $born, $died) {
global $db;
if (empty ($author))
return null;
$sql_author = $db->f ($author, SQLCHAR);
$sql_born = $db->f ($born, SQLINT);
$sql_died = $db->f ($died, SQLINT);
$sql_author_like = $db->f ("$author%", SQLCHAR);
$pk = 0;
$db->exec ("select pk from authors where author ilike $sql_author_like order by pk");
if ($db->FirstRow ()) {
$pk = $db->Get ("pk", SQLINT);
} else {
// try aliases
$db->exec ("select fk_authors from aliases where alias ilike $sql_author_like order by fk_authors");
if ($db->FirstRow ()) {
$pk = $db->Get ("fk_authors", SQLINT);
}
}
if ($pk == 0) {
$db->exec ("insert into authors (author, born_floor, died_floor, born_ceil, died_ceil) " .
"values ($sql_author, $sql_born, $sql_died, $sql_born, $sql_died)");
$db->exec ("select pk from authors where author = $sql_author");
$pk = $db->Get ("pk", SQLINT);
echo ("Added author '$author' to database. !!!!\n");
}
return $pk;
}
function insert_title ($etext_number, $title, $marc = 245) {
global $db, $titles;
if (empty ($title))
return;
$nonfilings = array ('The ', 'A ', 'An ',
'Der ', 'Die ', 'Das ', 'Eine ', 'Ein ',
'La ', 'Le ', 'Les ', 'L\'',
'El ');
$nonfiling = 0;
foreach ($nonfilings as $key => $value) {
if (preg_match ("/^$value/", $title)) {
$nonfiling = strlen ($value);
}
}
$title = preg_replace ("/--/", "\xE2\x80\x94", $title);
$title = preg_replace ("/ *_ */", "\n", $title);
$sql_title = $db->f ($title, SQLCHAR);
$sql_etext_number = $db->f ($etext_number, SQLINT);
$sql_marc = $db->f ($marc, SQLINT);
$sql_nonfiling = $db->f ($nonfiling, SQLINT);
$db->exec ("select pk from attributes where fk_books = $sql_etext_number and text = $sql_title");
if (!$db->FirstRow ()) {
$db->exec ("insert into attributes (fk_books, text, nonfiling, fk_attriblist) " .
"values ($sql_etext_number, $sql_title, $sql_nonfiling, $sql_marc)");
echo ("Added title '$title' to book $etext_number\n");
}
}
function capture ($tok, $e) {
$matches = array ();
if (preg_match ("/^$tok: (.*)$/im", $e, $matches))
return $matches[1];
return null;
}
function process_section ($e) {
global $db, $filetypes, $compressions, $encodings, $roles, $old_etext_number;
$etext_number = $pk_author = null;
$cnt_authors = $updatemode = 0;
$got_title = 0;
// try to read etext_number from inputfile
$etext_number = capture ("Etext-Nr", $e);
if (empty ($etext_number)) {
// no etext_number ?
// try to compute etext_number from directory
$directory = capture ("directory", $e);
if (preg_match ("/^(?:\d\/)+(\d{2,5})/", $directory, $matches)) {
$etext_number = intval ($matches[1]);
// double-check this
$dir = etext2dir ($etext_number);
if (strncmp ("$directory/", $dir, strlen ($dir)))
$etext_number = null;
} elseif (preg_match ("/^([1-9])$/", $directory, $matches)) {
$etext_number = intval ($matches[1]);
}
}
if ($etext_number != $old_etext_number) {
echo ("----------\n\n");
$old_etext_number = $etext_number;
}
// insert file into files table
if ($filename = capture ("filename", $e)) {
$matches = array ();
$directory = capture ("directory", $e);
$mtime = capture ("mtime", $e);
$size = capture ("size", $e);
$edition = capture ("edition", $e);
$filetype = capture ("filetype", $e);
$obsoleted = capture ("obsoleted", $e);
$encoding = fix_encoding (capture ("encoding", $e));
$zipmember = capture ("Zipmemberfilename", $e);
/*
$md5hash = @pack ("H*", capture ("md5.hex", $e));
$sha1hash = @pack ("H*", capture ("sha1.hex", $e));
$kzhash = @pack ("H*", capture ("kzhash.hex", $e));
$ed2khash = @pack ("H*", capture ("ed2khash.hex", $e));
$tigertreehash = @pack ("H*", capture ("tigertree.hex", $e));
*/
$md5hash = capture ("md5.hex", $e);
$sha1hash = capture ("sha1.hex", $e);
$kzhash = capture ("kzhash.hex", $e);
$ed2khash = capture ("ed2khash.hex", $e);
$tigertreehash = capture ("tigertree.hex", $e);
// filetype and encoding
list ($fk_filetypes, $fk_encodings) =
guess_filetype (empty ($zipmember) ? $filename : $zipmember);
// the encoding is better taken from the file, if present
if (isset ($encodings[$encoding])) {
$fk_encodings = $encoding;
}
// the filetype is better taken from the file, if present (not used for now)
// if (!empty ($filetype) && isset ($filetypes[$filetype])) {
// $fk_filetypes = $filetype;
// }
// compression
$fk_compressions = 'none';
if (preg_match ("/^(.*)\.(.*)$/", $filename, $matches)) {
if (isset ($compressions[strtolower ($matches[2])])) {
$fk_compressions = strtolower ($matches[2]);
}
}
// obsoleted
if (preg_match ("/\/old(\/|$)/", $directory)) {
$obsoleted = 1;
}
$diskstatus = 0;
// hide image files
if (strpos ($directory, "/$etext_number-")) {
if (in_array ($fk_filetypes, array ("jpg", "png", "gif", "svg", "css", "xsl")))
$diskstatus = 1;
if (preg_match ("/\/images(\/|$)/", $directory))
$diskstatus = 1;
if (preg_match ("/-h\/files(\/|$)/", $directory))
$diskstatus = 1;
}
$sql_diskstatus = $db->f ($diskstatus, SQLINT);
$sql_fk_filetypes = $db->f ($fk_filetypes, SQLCHAR);
$sql_fk_compressions = $db->f ($fk_compressions, SQLCHAR);
$sql_fk_encodings = $db->f ($fk_encodings, SQLCHAR);
$sql_mtime = $db->f ($mtime, SQLDATE);
$sql_size = $db->f ($size, SQLINT);
$sql_edition = $db->f ($edition, SQLINT);
$sql_obsoleted = $db->f ($obsoleted, SQLINT);
$sql_etext_number = $db->f ($etext_number, SQLINT);
$sql_filename = $db->f ("$directory/$filename", SQLCHAR);
$sql_md5hash = $db->f ($md5hash, SQLBYTE);
$sql_sha1hash = $db->f ($sha1hash, SQLBYTE);
$sql_kzhash = $db->f ($kzhash, SQLBYTE);
$sql_ed2khash = $db->f ($ed2khash, SQLBYTE);
$sql_tigertreehash = $db->f ($tigertreehash, SQLBYTE);
$fields =
(empty ($etext_number) ? "" : "fk_books = $sql_etext_number, ") .
(empty ($fk_filetypes) ? "" : "fk_filetypes = $sql_fk_filetypes, ") .
(empty ($fk_encodings) ? "" : "fk_encodings = $sql_fk_encodings, ") .
(empty ($fk_compressions) ? "" : "fk_compressions = $sql_fk_compressions, ") .
(empty ($md5hash) ? "" : "md5hash = $sql_md5hash, ") .
(empty ($sha1hash) ? "" : "sha1hash = $sql_sha1hash, ") .
(empty ($kzhash) ? "" : "kzhash = $sql_kzhash, ") .
(empty ($ed2khash) ? "" : "ed2khash = $sql_ed2khash, ") .
(empty ($tigertreehash) ? "" : "tigertreehash = $sql_tigertreehash, ") .
(empty ($edition) ? "" : "edition = $sql_edition, ") .
(empty ($obsoleted) ? "" : "obsoleted = $sql_obsoleted, ") .
(empty ($size) ? "" : "filesize = $sql_size, ") .
(empty ($mtime) ? "" : "filemtime = $sql_mtime, ") .
"diskstatus = $sql_diskstatus";
// $fields = rtrim ($fields, ", ");
$db->BeginTrans ();
$db->exec ("select pk from files where filename = $sql_filename");
$newfile = !$db->FirstRow ();
if ($newfile) {
$db->exec ("insert into files (filename, diskstatus) values ($sql_filename, 0);");
}
$db->exec ("update files set $fields where filename = $sql_filename");
$db->Commit ();
echo (($newfile ? "Added" : "Updated") . " file $directory/$filename " .
"($sql_etext_number $sql_fk_filetypes $sql_fk_compressions $sql_fk_encodings $sql_diskstatus $sql_obsoleted)\n");
}
// maybe insert book into books table
if (!empty ($etext_number)) {
$db->BeginTrans ();
$sql_etext_number = $db->f ($etext_number, SQLINT);
$db->exec ("select * from books where pk = $sql_etext_number");
if ($db->FirstRow ()) {
$updatemode = $db->get ("updatemode", SQLINT); // 0 = auto, 1 = manual
} else {
$db->exec ("insert into books (pk) values ($sql_etext_number)");
echo ("Inserted book $etext_number into database\n");
}
if ($updatemode == 0) {
if ($fk_encodings != "utf-8") {
iconv_set_encoding ("internal_encoding", "UTF-8");
$converted = iconv (strtoupper ($fk_encodings), "UTF-8", $e);
if ($converted !== FALSE) {
$e = $converted;
}
}
$lines = preg_split ("/\n/", $e);
foreach ($lines as $line) {
if (empty ($line)) continue;
if (!preg_match ("/^(.*?):\s+(.*)$/", $line, $matches))
continue;
list ($dummy, $key, $value) = $matches; // preg_split ("/:\s+/", $line); //FIXME
if (empty ($value)) continue;
if (isset ($roles[$key])) {
list ($author, $born, $died, $role) = decode_author ($value);
$pk_author = insert_author ($author, $born, $died);
if ($key != "Author") {
$role = $roles[$key];
}
if ($pk_author) {
$sql_fk_authors = $db->f ($pk_author, SQLINT);
$sql_fk_roles = $db->f ($role, SQLCHAR);
$db->exec ("select * from mn_books_authors " .
"where fk_books = $sql_etext_number and fk_authors = $sql_fk_authors " .
"and fk_roles = $sql_fk_roles");
if (!$db->FirstRow ()) {
$db->exec ("insert into mn_books_authors (fk_books, fk_authors, fk_roles) " .
"values ($sql_etext_number, $sql_fk_authors, $sql_fk_roles)");
echo ("Added author '$author' role $role to book $etext_number\n");
}
}
$cnt_authors++;
continue;
}
if ($key == "Title") {
insert_title ($etext_number, $value, 245);
$got_title = 1;
continue;
}
if ($key == "Alternate Title") {
insert_title ($etext_number, $value, 246);
continue;
}
if ($key == "Contents") {
insert_title ($etext_number, $value, 505);
continue;
}
if ($key == "Language") {
$lang = encode_language ($value);
if (!empty ($lang)) {
$sql_lang = $db->f ($lang, SQLCHAR);
$db->exec ("select * from mn_books_langs " .
"where fk_books = $sql_etext_number and fk_langs = $sql_lang");
if (!$db->FirstRow ()) {
$db->exec ("insert into mn_books_langs (fk_books, fk_langs) " .
"values ($sql_etext_number, $sql_lang)");
}
}
continue;
}
if ($key == "Locc") {
$sql_locc = $db->f (strtoupper ($value), SQLCHAR);
$db->exec ("select * from mn_books_loccs " .
"where fk_books = $sql_etext_number and fk_loccs = $sql_locc");
if (!$db->FirstRow ()) {
$db->exec ("insert into mn_books_loccs (fk_books, fk_loccs) " .
"values ($sql_etext_number, $sql_locc)");
}
continue;
}
if ($key == "Subject") {
$sql_subject = $db->f ($value, SQLCHAR);
$db->exec ("select pk from subjects where subject = $sql_subject");
if (!$db->FirstRow ()) {
$db->exec ("insert into subjects (subject) values ($sql_subject)");
$db->exec ("select pk from subjects where subject = $sql_subject");
}
$pk_subjects = $db->Get ("pk", SQLINT);
$sql_fk_subjects = $db->f ($pk_subjects, SQLINT);
$db->exec ("select * from mn_books_subjects " .
"where fk_books = $sql_etext_number and fk_subjects = $sql_fk_subjects");
if (!$db->FirstRow ()) {
$db->exec ("insert into mn_books_subjects (fk_books, fk_subjects) " .
"values ($sql_etext_number, $sql_fk_subjects)");
}
continue;
}
if ($key == "Note") {
$sql_note = $db->f ($value, SQLCHAR);
$db->exec ("select * from attributes " .
"where fk_books = $sql_etext_number and text = $sql_note");
if (!$db->FirstRow ()) {
$db->exec ("insert into attributes (fk_books, fk_attriblist, text) values ($sql_etext_number, 500, $sql_note)");
}
continue;
}
if ($key == "Copyright") {
$sql_copyrighted = $db->f ($value, SQLINT);
$db->exec ("update books set copyrighted = $sql_copyrighted where pk = $sql_etext_number");
continue;
}
if ($key == "Category") {
$sql_category = $db->f ($value, SQLCHAR);
$db->exec ("select pk from categories where category = $sql_category");
if ($db->FirstRow ()) {
$fk_categories = $db->get ("pk", SQLINT);
$sql_fk_categories = $db->f ($fk_categories, SQLINT);
$db->exec ("select * from mn_books_categories " .
"where fk_books = $sql_etext_number and fk_categories = $sql_fk_categories");
if (!$db->FirstRow ()) {
$db->exec ("insert into mn_books_categories (fk_books, fk_categories) " .
"values ($sql_etext_number, $fk_categories)");
}
}
continue;
}
if ($key == "Release-Date") {
if (strpos ($value, ',') === false) {
$vale = "1 $value";
}
$release_date = strtotime ("$value");
$sql_release_date = $db->f ($release_date, SQLDATE);
$db->exec ("update books set release_date = $sql_release_date where pk = $sql_etext_number");
continue;
}
}
// hack! makefiles.pl sorts filenames so that 8-bit ones come first
// this way we prefer titles etc. from 8-bit files over html and 7-bit files
if ($got_title) {
$db->exec ("update books set updatemode = 1 where pk = $sql_etext_number");
}
$db->Commit ();
}
}
}
register_shutdown_function ('rollback_transaction');
set_time_limit (0);
$buffer = "";
if ($hd = fopen ($importfilename, "r")) {
while (!feof ($hd)) {
$line = fgets ($hd);
if (preg_match ("/^---*[\r\n]*$/", $line)) {
process_section ($buffer);
$buffer = "";
echo ("\n"); flush ();
} else {
$buffer .= $line;
}
}
process_section ($buffer);
fclose ($hd);
}
?>

View File

@ -0,0 +1,641 @@
<?php
include_once ("pgcat.phh");
$cli = php_sapi_name () == "cli";
if (!$cli) {
exit ();
}
include_once ("sqlform.phh");
echo ("after sqlform ...\n"); flush ();
$db = $config->db ();
echo ("after db () ...\n"); flush ();
$db->logger = new logger ();
echo ("Initializing ...\n"); flush ();
$db->Exec ("select pk, lang from langs");
if ($db->FirstRow ()) {
do {
$languages[$db->Get ("lang", SQLCHAR)] = $db->Get ("pk", SQLCHAR);
} while ($db->NextRow ());
}
$db->exec ("select pk, filetype from filetypes");
if ($db->FirstRow ()) {
do {
$filetypes[$db->Get ("pk", SQLCHAR)] = $db->Get ("filetype", SQLCHAR);
} while ($db->NextRow ());
}
$db->exec ("select pk, compression from compressions");
if ($db->FirstRow ()) {
do {
$compressions[$db->Get ("pk", SQLCHAR)] = $db->Get ("compression", SQLCHAR);
} while ($db->NextRow ());
}
$db->exec ("select pk from encodings");
if ($db->FirstRow ()) {
do {
$encodings[$db->Get ("pk", SQLCHAR)] = 1;
} while ($db->NextRow ());
}
$db->exec ("select pk, role from roles");
if ($db->FirstRow ()) {
do {
$roles[$db->Get ("role", SQLCHAR)] = $db->get ("pk", SQLCHAR);
} while ($db->NextRow ());
}
$importfilename = $argv[1];
if (empty ($importfilename))
$importfilename = $config->catalogupdatelog;
echo ("Processing $importfilename ...\n"); flush ();
$old_etext_number = -1;
function guess_filetype ($filename) {
// guesses filetype, encoding from filename only
//
// needs following hashes:
// usually loaded from the same tables in the database
// $filetypes: 'txt' => 'Plain text'
// $encodings: 'us-ascii'
global $filetypes, $encodings;
$extension_aliases = array (
'htm' => 'html',
'tif' => 'tiff',
'jpeg' => 'jpg',
'midi' => 'mid'
);
$ft = $enc = null;
$base = $ext = "";
$base_after_hyphen = "";
if (preg_match ("/^(.*)\.(.*)$/", $filename, $matches)) {
$base = strtolower ($matches[1]);
$ext = strtolower ($matches[2]);
}
$post10k = preg_match ("/^\d{5}(-|$)/", $base);
if (preg_match ("/-(.*)$/", $base, $matches))
$base_after_hyphen = $matches[1];
// guess filetype from file extension
if (isset ($extension_aliases[$ext])) {
$ext = $extension_aliases[$ext];
}
if (isset ($filetypes[$ext])) {
$ft = $ext;
}
if (preg_match ("/[-_]index\.html?$/i", $filename)) {
$ft = "index";
}
if (preg_match ("/readme\.txt$/i", $filename)) {
$ft = "readme";
}
if (preg_match ("/license\.txt$/i", $filename)) {
$ft = "license";
}
if (preg_match ("/page-images/i", $filename)) {
$ft = "pageimages";
}
// guess encoding from file name
if ($ext == "txt") {
if ($post10k) {
switch ($base_after_hyphen) {
case "" : $enc = "us-ascii"; break;
case "8" : $enc = "iso-8859-1"; break;
case "0" : $enc = "utf-8"; break;
case "5" : $enc = "big5"; break;
}
} else {
$enc = "us-ascii";
if (preg_match ("/^8\w.+\d\da?$/", $base))
$enc = "iso-8859-1";
if (preg_match ("/^8\w.+\d\du$/", $base))
$enc = "utf-8";
}
}
return array ($ft, $enc);
}
function fix_encoding ($encoding) {
global $encodings;
$encoding_aliases = array (
'ascii' => 'us-ascii',
'usascii' => 'us-ascii',
'iso88591' => 'iso-8859-1',
'latin1' => 'iso-8859-1',
'iso88592' => 'iso-8859-2',
'latin2' => 'iso-8859-2',
'iso88593' => 'iso-8859-3',
'latin3' => 'iso-8859-3',
'iso88594' => 'iso-8859-4',
'latin4' => 'iso-8859-4',
'iso88595' => 'iso-8859-5',
'cyrillic' => 'iso-8859-5',
'iso88596' => 'iso-8859-6',
'arabic' => 'iso-8859-6',
'iso88597' => 'iso-8859-7',
'greek' => 'iso-8859-7',
'iso88598' => 'iso-8859-8',
'hebrew' => 'iso-8859-8',
'iso88599' => 'iso-8859-9',
'latin5' => 'iso-8859-9',
'iso885910' => 'iso-8859-10',
'latin6' => 'iso-8859-10',
'iso885913' => 'iso-8859-13',
'iso885914' => 'iso-8859-14',
'latin8' => 'iso-8859-14',
'iso885915' => 'iso-8859-15',
'latin9' => 'iso-8859-15',
'iso885916' => 'iso-8859-16',
'latin10' => 'iso-8859-16',
'utf7' => 'utf-7',
'utf8' => 'utf-8',
'win1250' => 'windows-1250',
'win1251' => 'windows-1251',
'win1252' => 'windows-1252',
'win1253' => 'windows-1253',
'koi8r' => 'koi8-r'
);
$pat[] = "/[- _=<]/"; $rep[] = "";
$pat[] = "/^unicode/"; $rep[] = "";
$pat[] = "/^windowscodepage/"; $rep[] = "win";
$pat[] = "/^windows/"; $rep[] = "win";
$pat[] = "/^codepage/"; $rep[] = "win";
$pat[] = "/^cp/"; $rep[] = "win";
$pat[] = "/^isolatin/"; $rep[] = "latin";
$encoding = strtolower ($encoding);
$encoding = preg_replace ($pat, $rep, $encoding);
if (isset ($encodings[$encoding])) {
return $encoding;
}
if (isset ($encoding_aliases[$encoding])) {
return $encoding_aliases[$encoding];
}
if (strpos ($encoding, "iso88591")) {
$encoding = "iso-8859-1";
} elseif (strpos ($encoding, "utf8")) {
$encoding = "utf-8";
} else {
$encoding = null;
// print ("#$nr: unknown encoding $enc\n");
}
return $encoding;
}
function encode_language ($l) {
global $languages;
$l = ucfirst ($l);
if (isset ($languages[$l])) {
return $languages[$l];
}
return null;
}
function decode_author ($whole) {
global $roles;
$parts = preg_split ("/ *, */", $whole);
$names = array ();
$name = "";
$born = null;
$died = null;
$role = "aut";
foreach ($parts as $part) {
if (empty ($part))
continue;
if (preg_match ("/^(\d+\??)-(\d*\??)$/", $part, $matches)) {
$born = "$matches[1]";
$died = "$matches[2]";
continue;
}
if (preg_match ("/^-(\d+)$/", $part, $matches)) {
$died = "$matches[1]";
continue;
}
if (isset ($roles[$part])) {
$role = $roles[$part];
continue;
}
array_push ($names, $part);
}
return array (join (", ", $names), $born, $died, $role);
}
function insert_author ($author, $born, $died) {
global $db;
if (empty ($author))
return null;
$sql_author = $db->f ($author, SQLCHAR);
$sql_born = $db->f ($born, SQLINT);
$sql_died = $db->f ($died, SQLINT);
$sql_author_like = $db->f ("$author%", SQLCHAR);
$pk = 0;
$db->exec ("select pk from authors where author ilike $sql_author_like order by pk");
if ($db->FirstRow ()) {
$pk = $db->Get ("pk", SQLINT);
} else {
// try aliases
$db->exec ("select fk_authors from aliases where alias ilike $sql_author_like order by fk_authors");
if ($db->FirstRow ()) {
$pk = $db->Get ("fk_authors", SQLINT);
}
}
if ($pk == 0) {
$db->exec ("insert into authors (author, born_floor, died_floor, born_ceil, died_ceil) " .
"values ($sql_author, $sql_born, $sql_died, $sql_born, $sql_died)");
$db->exec ("select pk from authors where author = $sql_author");
$pk = $db->Get ("pk", SQLINT);
echo ("Added author '$author' to database. !!!!\n");
}
return $pk;
}
function insert_title ($etext_number, $title, $marc = 245) {
global $db, $titles;
if (empty ($title))
return;
$nonfilings = array ('The ', 'A ', 'An ',
'Der ', 'Die ', 'Das ', 'Eine ', 'Ein ',
'La ', 'Le ', 'Les ', 'L\'',
'El ');
$nonfiling = 0;
foreach ($nonfilings as $key => $value) {
if (preg_match ("/^$value/", $title)) {
$nonfiling = strlen ($value);
}
}
$title = preg_replace ("/--/", "\xE2\x80\x94", $title);
$title = preg_replace ("/ *_ */", "\n", $title);
$sql_title = $db->f ($title, SQLCHAR);
$sql_etext_number = $db->f ($etext_number, SQLINT);
$sql_marc = $db->f ($marc, SQLINT);
$sql_nonfiling = $db->f ($nonfiling, SQLINT);
$db->exec ("select pk from attributes where fk_books = $sql_etext_number and text = $sql_title");
if (!$db->FirstRow ()) {
$db->exec ("insert into attributes (fk_books, text, nonfiling, fk_attriblist) " .
"values ($sql_etext_number, $sql_title, $sql_nonfiling, $sql_marc)");
echo ("Added title '$title' to book $etext_number\n");
}
}
function capture ($tok, $e) {
$matches = array ();
if (preg_match ("/^$tok: (.*)$/im", $e, $matches))
return $matches[1];
return null;
}
function process_section ($e) {
global $db, $filetypes, $compressions, $encodings, $roles, $old_etext_number;
$etext_number = $pk_author = null;
$cnt_authors = $updatemode = 0;
$got_title = 0;
// try to read etext_number from inputfile
$etext_number = capture ("Etext-Nr", $e);
if (empty ($etext_number)) {
// no etext_number ?
// try to compute etext_number from directory
$directory = capture ("directory", $e);
if (preg_match ("/^(?:\d\/)+(\d{2,5})/", $directory, $matches)) {
$etext_number = intval ($matches[1]);
// double-check this
$dir = etext2dir ($etext_number);
if (strncmp ("$directory/", $dir, strlen ($dir)))
$etext_number = null;
} elseif (preg_match ("/^([1-9])$/", $directory, $matches)) {
$etext_number = intval ($matches[1]);
}
}
if ($etext_number != $old_etext_number) {
echo ("----------\n\n");
$old_etext_number = $etext_number;
}
// insert file into files table
if ($filename = capture ("filename", $e)) {
$matches = array ();
$directory = capture ("directory", $e);
$mtime = capture ("mtime", $e);
$size = capture ("size", $e);
$edition = capture ("edition", $e);
$filetype = capture ("filetype", $e);
$obsoleted = capture ("obsoleted", $e);
$encoding = fix_encoding (capture ("encoding", $e));
$zipmember = capture ("Zipmemberfilename", $e);
/*
$md5hash = @pack ("H*", capture ("md5.hex", $e));
$sha1hash = @pack ("H*", capture ("sha1.hex", $e));
$kzhash = @pack ("H*", capture ("kzhash.hex", $e));
$ed2khash = @pack ("H*", capture ("ed2khash.hex", $e));
$tigertreehash = @pack ("H*", capture ("tigertree.hex", $e));
*/
$md5hash = capture ("md5.hex", $e);
$sha1hash = capture ("sha1.hex", $e);
$kzhash = capture ("kzhash.hex", $e);
$ed2khash = capture ("ed2khash.hex", $e);
$tigertreehash = capture ("tigertree.hex", $e);
// filetype and encoding
list ($fk_filetypes, $fk_encodings) =
guess_filetype (empty ($zipmember) ? $filename : $zipmember);
// the encoding is better taken from the file, if present
if (isset ($encodings[$encoding])) {
$fk_encodings = $encoding;
}
// the filetype is better taken from the file, if present (not used for now)
// if (!empty ($filetype) && isset ($filetypes[$filetype])) {
// $fk_filetypes = $filetype;
// }
// compression
$fk_compressions = 'none';
if (preg_match ("/^(.*)\.(.*)$/", $filename, $matches)) {
if (isset ($compressions[strtolower ($matches[2])])) {
$fk_compressions = strtolower ($matches[2]);
}
}
// obsoleted
if (preg_match ("/\/old(\/|$)/", $directory)) {
$obsoleted = 1;
}
$diskstatus = 0;
// hide image files
if (strpos ($directory, "/$etext_number-")) {
if (in_array ($fk_filetypes, array ("jpg", "png", "gif", "svg", "css", "xsl")))
$diskstatus = 1;
if (preg_match ("/\/images(\/|$)/", $directory))
$diskstatus = 1;
if (preg_match ("/-h\/files(\/|$)/", $directory))
$diskstatus = 1;
}
$sql_diskstatus = $db->f ($diskstatus, SQLINT);
$sql_fk_filetypes = $db->f ($fk_filetypes, SQLCHAR);
$sql_fk_compressions = $db->f ($fk_compressions, SQLCHAR);
$sql_fk_encodings = $db->f ($fk_encodings, SQLCHAR);
$sql_mtime = $db->f ($mtime, SQLDATE);
$sql_size = $db->f ($size, SQLINT);
$sql_edition = $db->f ($edition, SQLINT);
$sql_obsoleted = $db->f ($obsoleted, SQLINT);
$sql_etext_number = $db->f ($etext_number, SQLINT);
$sql_filename = $db->f ("$directory/$filename", SQLCHAR);
$sql_md5hash = $db->f ($md5hash, SQLBYTE);
$sql_sha1hash = $db->f ($sha1hash, SQLBYTE);
$sql_kzhash = $db->f ($kzhash, SQLBYTE);
$sql_ed2khash = $db->f ($ed2khash, SQLBYTE);
$sql_tigertreehash = $db->f ($tigertreehash, SQLBYTE);
$fields =
(empty ($etext_number) ? "" : "fk_books = $sql_etext_number, ") .
(empty ($fk_filetypes) ? "" : "fk_filetypes = $sql_fk_filetypes, ") .
(empty ($fk_encodings) ? "" : "fk_encodings = $sql_fk_encodings, ") .
(empty ($fk_compressions) ? "" : "fk_compressions = $sql_fk_compressions, ") .
(empty ($md5hash) ? "" : "md5hash = $sql_md5hash, ") .
(empty ($sha1hash) ? "" : "sha1hash = $sql_sha1hash, ") .
(empty ($kzhash) ? "" : "kzhash = $sql_kzhash, ") .
(empty ($ed2khash) ? "" : "ed2khash = $sql_ed2khash, ") .
(empty ($tigertreehash) ? "" : "tigertreehash = $sql_tigertreehash, ") .
(empty ($edition) ? "" : "edition = $sql_edition, ") .
(empty ($obsoleted) ? "" : "obsoleted = $sql_obsoleted, ") .
(empty ($size) ? "" : "filesize = $sql_size, ") .
(empty ($mtime) ? "" : "filemtime = $sql_mtime, ") .
"diskstatus = $sql_diskstatus";
// $fields = rtrim ($fields, ", ");
$db->BeginTrans ();
$db->exec ("select pk from files where filename = $sql_filename");
$newfile = !$db->FirstRow ();
if ($newfile) {
$db->exec ("insert into files (filename, diskstatus) values ($sql_filename, 0);");
}
$db->exec ("update files set $fields where filename = $sql_filename");
$db->Commit ();
echo (($newfile ? "Added" : "Updated") . " file $directory/$filename " .
"($sql_etext_number $sql_fk_filetypes $sql_fk_compressions $sql_fk_encodings $sql_diskstatus $sql_obsoleted)\n");
}
// maybe insert book into books table
if (!empty ($etext_number)) {
$db->BeginTrans ();
$sql_etext_number = $db->f ($etext_number, SQLINT);
$db->exec ("select * from books where pk = $sql_etext_number");
if ($db->FirstRow ()) {
$updatemode = $db->get ("updatemode", SQLINT); // 0 = auto, 1 = manual
} else {
$db->exec ("insert into books (pk) values ($sql_etext_number)");
echo ("Inserted book $etext_number into database\n");
}
if ($updatemode == 0) {
if ($fk_encodings != "utf-8") {
iconv_set_encoding ("internal_encoding", "UTF-8");
$converted = iconv (strtoupper ($fk_encodings), "UTF-8", $e);
if ($converted !== FALSE) {
$e = $converted;
}
}
$lines = preg_split ("/\n/", $e);
foreach ($lines as $line) {
if (empty ($line)) continue;
if (!preg_match ("/^(.*?):\s+(.*)$/", $line, $matches))
continue;
list ($dummy, $key, $value) = $matches; // preg_split ("/:\s+/", $line); //FIXME
if (empty ($value)) continue;
if (isset ($roles[$key])) {
list ($author, $born, $died, $role) = decode_author ($value);
$pk_author = insert_author ($author, $born, $died);
if ($key != "Author") {
$role = $roles[$key];
}
if ($pk_author) {
$sql_fk_authors = $db->f ($pk_author, SQLINT);
$sql_fk_roles = $db->f ($role, SQLCHAR);
$db->exec ("select * from mn_books_authors " .
"where fk_books = $sql_etext_number and fk_authors = $sql_fk_authors " .
"and fk_roles = $sql_fk_roles");
if (!$db->FirstRow ()) {
$db->exec ("insert into mn_books_authors (fk_books, fk_authors, fk_roles) " .
"values ($sql_etext_number, $sql_fk_authors, $sql_fk_roles)");
echo ("Added author '$author' role $role to book $etext_number\n");
}
}
$cnt_authors++;
continue;
}
if ($key == "Title") {
insert_title ($etext_number, $value, 245);
$got_title = 1;
continue;
}
if ($key == "Alternate Title") {
insert_title ($etext_number, $value, 246);
continue;
}
if ($key == "Contents") {
insert_title ($etext_number, $value, 505);
continue;
}
if ($key == "Language") {
$lang = encode_language ($value);
if (!empty ($lang)) {
$sql_lang = $db->f ($lang, SQLCHAR);
$db->exec ("select * from mn_books_langs " .
"where fk_books = $sql_etext_number and fk_langs = $sql_lang");
if (!$db->FirstRow ()) {
$db->exec ("insert into mn_books_langs (fk_books, fk_langs) " .
"values ($sql_etext_number, $sql_lang)");
}
}
continue;
}
if ($key == "Locc") {
$sql_locc = $db->f (strtoupper ($value), SQLCHAR);
$db->exec ("select * from mn_books_loccs " .
"where fk_books = $sql_etext_number and fk_loccs = $sql_locc");
if (!$db->FirstRow ()) {
$db->exec ("insert into mn_books_loccs (fk_books, fk_loccs) " .
"values ($sql_etext_number, $sql_locc)");
}
continue;
}
if ($key == "Subject") {
$sql_subject = $db->f ($value, SQLCHAR);
$db->exec ("select pk from subjects where subject = $sql_subject");
if (!$db->FirstRow ()) {
$db->exec ("insert into subjects (subject) values ($sql_subject)");
$db->exec ("select pk from subjects where subject = $sql_subject");
}
$pk_subjects = $db->Get ("pk", SQLINT);
$sql_fk_subjects = $db->f ($pk_subjects, SQLINT);
$db->exec ("select * from mn_books_subjects " .
"where fk_books = $sql_etext_number and fk_subjects = $sql_fk_subjects");
if (!$db->FirstRow ()) {
$db->exec ("insert into mn_books_subjects (fk_books, fk_subjects) " .
"values ($sql_etext_number, $sql_fk_subjects)");
}
continue;
}
if ($key == "Note") {
$sql_note = $db->f ($value, SQLCHAR);
$db->exec ("select * from attributes " .
"where fk_books = $sql_etext_number and text = $sql_note");
if (!$db->FirstRow ()) {
$db->exec ("insert into attributes (fk_books, fk_attriblist, text) values ($sql_etext_number, 500, $sql_note)");
}
continue;
}
if ($key == "Copyright") {
$sql_copyrighted = $db->f ($value, SQLINT);
$db->exec ("update books set copyrighted = $sql_copyrighted where pk = $sql_etext_number");
continue;
}
if ($key == "Category") {
$sql_category = $db->f ($value, SQLCHAR);
$db->exec ("select pk from categories where category = $sql_category");
if ($db->FirstRow ()) {
$fk_categories = $db->get ("pk", SQLINT);
$sql_fk_categories = $db->f ($fk_categories, SQLINT);
$db->exec ("select * from mn_books_categories " .
"where fk_books = $sql_etext_number and fk_categories = $sql_fk_categories");
if (!$db->FirstRow ()) {
$db->exec ("insert into mn_books_categories (fk_books, fk_categories) " .
"values ($sql_etext_number, $fk_categories)");
}
}
continue;
}
if ($key == "Release-Date") {
if (strpos ($value, ',') === false) {
$vale = "1 $value";
}
$release_date = strtotime ("$value");
$sql_release_date = $db->f ($release_date, SQLDATE);
$db->exec ("update books set release_date = $sql_release_date where pk = $sql_etext_number");
continue;
}
}
// hack! makefiles.pl sorts filenames so that 8-bit ones come first
// this way we prefer titles etc. from 8-bit files over html and 7-bit files
if ($got_title) {
$db->exec ("update books set updatemode = 1 where pk = $sql_etext_number");
}
$db->Commit ();
}
}
}
register_shutdown_function ('rollback_transaction');
set_time_limit (0);
$buffer = "";
if ($hd = fopen ($importfilename, "r")) {
while (!feof ($hd)) {
$line = fgets ($hd);
if (preg_match ("/^---*[\r\n]*$/", $line)) {
process_section ($buffer);
$buffer = "";
echo ("\n"); flush ();
} else {
$buffer .= $line;
}
}
process_section ($buffer);
fclose ($hd);
}
?>

View File

@ -0,0 +1,44 @@
<?php
set_include_path(get_include_path() . PATH_SEPARATOR . "/public/vhost/g/gutenberg/dev/private/lib/php");
include_once ("pgcat.phh");
authenticate ();
getstr ("filter");
pageheader ($caption = "Categories $filter");
class ListCategoriesTable extends ListTable {
function __construct () {
global $filter;
$prefix = "<a href=\"category?filter=$filter&mode";
$this->AddColumn ("$prefix=edit&fk_categories=#pk#\">Edit</a>",
"$prefix=add\">Add</a>", "left", "1%");
$this->AddColumn ("$prefix=delete&fk_categories=#pk#\">Delete</a>",
"", "left", "1%");
$this->AddSimpleColumn ("category", "Category");
}
}
$db = $config->db ();
p ("Please enter the first few characters of the category (at least one).
Search is case-sensitive.
Use * as wildcard. (eg. *human)
To see everything just enter *.");
form_open ();
echo (" <input type=\"text\" name=\"filter\" value=\"$filter\"/>&nbsp;\n");
form_submit ("Search");
form_close ();
if ($filter != "") {
$filt = preg_replace ('/\*/', '%', $filter);
$db->exec ("select * from categories where category ilike '$filt%' order by category;");
$table = new ListCategoriesTable ();
$table->PrintTable ($db, $caption);
}
pagefooter ();
?>

View File

@ -0,0 +1,43 @@
<?php
include_once ("pgcat.phh");
authenticate ();
getstr ("filter");
pageheader ($caption = "Categories $filter");
class ListCategoriesTable extends ListTable {
function __construct () {
global $filter;
$prefix = "<a href=\"category?filter=$filter&mode";
$this->AddColumn ("$prefix=edit&fk_categories=#pk#\">Edit</a>",
"$prefix=add\">Add</a>", "left", "1%");
$this->AddColumn ("$prefix=delete&fk_categories=#pk#\">Delete</a>",
"", "left", "1%");
$this->AddSimpleColumn ("category", "Category");
}
}
$db = $config->db ();
p ("Please enter the first few characters of the category (at least one).
Search is case-sensitive.
Use * as wildcard. (eg. *human)
To see everything just enter *.");
form_open ();
echo (" <input type=\"text\" name=\"filter\" value=\"$filter\"/>&nbsp;\n");
form_submit ("Search");
form_close ();
if ($filter != "") {
$filt = preg_replace ('/\*/', '%', $filter);
$db->exec ("select * from categories where category ilike '$filt%' order by category;");
$table = new ListCategoriesTable ();
$table->PrintTable ($db, $caption);
}
pagefooter ();
?>

View File

@ -0,0 +1,92 @@
<?php
set_include_path(get_include_path() . PATH_SEPARATOR . "/public/vhost/g/gutenberg/dev/private/lib/php");
include_once ("pgcat.phh");
authenticate ();
getstr ("mode");
$caption = ucfirst ($mode) . " Category";
pageheader ($caption);
include_once ("sqlform.phh");
class ListBooksTable extends MoreTable {
function __construct () {
$this->AddColumn ("<a href=\"book?mode=edit&fk_books=#pk#\">#pk#</a>",
"Etext Nr.", "right", "1*");
$this->AddSimpleColumn ("author", "Author");
$this->AddSimpleColumn ("title", "Title");
$this->limit = 25;
$this->relay = array ("fk_categories", "mode", "filter");
}
}
$db = $config->db ();
$db->logger = new logger ();
$f = new SQLForm ();
getint ("fk_categories");
getstr ("filter");
if (ismode ("delete")) {
$db->Exec ("select count (*) as cnt from mn_books_categories " .
"where fk_categories = $fk_categories");
$cnt = $db->get ("cnt");
if ($cnt > 0) {
$f->SubCaption ("Warning: There are $cnt books related to this category. ");
}
$f->SubCaption ("You are about to delete this category.");
$f->SubCaption ("Press the '$caption' button to continue or " .
"hit the back button on your browser to dismiss.");
} else {
$f->Text ("category", "category", "Category", SQLCHAR, 80, 240, true);
$f->LoadData ("select * from categories where pk = $fk_categories");
}
$f->Hidden ("fk_categories");
$f->Hidden ("filter");
if (isupdatemode ("add")) {
if ($f->Check ()) {
$sql = $f->mkInsert ($db->GetFormatter ());
if ($db->Exec ("insert into categories " . $sql)) {
msg ("Category added !");
} else {
error_msg ("Could not add category!");
}
}
}
if (isupdatemode ("edit")) {
if ($f->Check ()) {
$sql = $f->mkUpdate ($db->GetFormatter ());
if ($db->Exec ("update categories set " . $sql . "where pk = $fk_categories")) {
msg ("Category modified !");
} else {
error_msg ("Could not modify category !");
}
}
}
if (isupdatemode ("delete")) {
$db->Exec ("delete from mn_books_categories where fk_categories = $fk_categories");
if ($db->Exec ("delete from categories where pk = $fk_categories")) {
msg ("Category deleted !");
} else {
error_msg ("Could not delete category !");
}
}
if (isupdate ()) {
if (!isupdatemode ("delete")) {
echo (" <p><a href=\"category?mode=edit&filter=$filter&fk_categories=$fk_categories\">" .
"Back to Category</a></p>\n\n");
}
} else {
$f->Output ($caption, $caption);
}
echo (" <p><a href=\"categories_list?filter=$filter\">" .
"Back to Category List</a></p>\n\n");
pagefooter ();
?>

View File

@ -0,0 +1,91 @@
<?php
include_once ("pgcat.phh");
authenticate ();
getstr ("mode");
$caption = ucfirst ($mode) . " Category";
pageheader ($caption);
include_once ("sqlform.phh");
class ListBooksTable extends MoreTable {
function __construct () {
$this->AddColumn ("<a href=\"book?mode=edit&fk_books=#pk#\">#pk#</a>",
"Etext Nr.", "right", "1*");
$this->AddSimpleColumn ("author", "Author");
$this->AddSimpleColumn ("title", "Title");
$this->limit = 25;
$this->relay = array ("fk_categories", "mode", "filter");
}
}
$db = $config->db ();
$db->logger = new logger ();
$f = new SQLForm ();
getint ("fk_categories");
getstr ("filter");
if (ismode ("delete")) {
$db->Exec ("select count (*) as cnt from mn_books_categories " .
"where fk_categories = $fk_categories");
$cnt = $db->get ("cnt");
if ($cnt > 0) {
$f->SubCaption ("Warning: There are $cnt books related to this category. ");
}
$f->SubCaption ("You are about to delete this category.");
$f->SubCaption ("Press the '$caption' button to continue or " .
"hit the back button on your browser to dismiss.");
} else {
$f->Text ("category", "category", "Category", SQLCHAR, 80, 240, true);
$f->LoadData ("select * from categories where pk = $fk_categories");
}
$f->Hidden ("fk_categories");
$f->Hidden ("filter");
if (isupdatemode ("add")) {
if ($f->Check ()) {
$sql = $f->mkInsert ($db->GetFormatter ());
if ($db->Exec ("insert into categories " . $sql)) {
msg ("Category added !");
} else {
error_msg ("Could not add category!");
}
}
}
if (isupdatemode ("edit")) {
if ($f->Check ()) {
$sql = $f->mkUpdate ($db->GetFormatter ());
if ($db->Exec ("update categories set " . $sql . "where pk = $fk_categories")) {
msg ("Category modified !");
} else {
error_msg ("Could not modify category !");
}
}
}
if (isupdatemode ("delete")) {
$db->Exec ("delete from mn_books_categories where fk_categories = $fk_categories");
if ($db->Exec ("delete from categories where pk = $fk_categories")) {
msg ("Category deleted !");
} else {
error_msg ("Could not delete category !");
}
}
if (isupdate ()) {
if (!isupdatemode ("delete")) {
echo (" <p><a href=\"category?mode=edit&filter=$filter&fk_categories=$fk_categories\">" .
"Back to Category</a></p>\n\n");
}
} else {
$f->Output ($caption, $caption);
}
echo (" <p><a href=\"categories_list?filter=$filter\">" .
"Back to Category List</a></p>\n\n");
pagefooter ();
?>

View File

@ -0,0 +1,96 @@
<?php
set_include_path(get_include_path() . PATH_SEPARATOR . "/public/vhost/g/gutenberg/dev/private/lib/php");
include_once ("pgcat.phh");
authenticate ();
$db = $config->db ();
getstr ("file");
getint ("samples", 10);
pageheader ("Encoding Guesses for $file");
$root = "/public/ftp/pub/docs/books/gutenberg/";
$path = realpath ("$root$file");
if (!preg_match ("|^$root|", $path) || (!$hd = fopen ($path, "r"))) {
// serve only files below root
header("HTTP/1.0 404 Not Found");
echo ("I see no such file here\n");
exit;
}
// get some words with funny characters
$data = file_get_contents ($path);
preg_match_all ("/\b.{0,20}[\x80-\xFF].{0,20}\b/s", $data, $matches);
$found_samples = count ($matches[0]);
if ($found_samples == 0) {
echo ("<p>No non-ascii characters found.</p>");
pagefooter ();
exit ();
}
$more_samples = $samples > 0 && $found_samples > $samples;
$words = join ("\n", $samples ? array_slice ($matches[0], 0, $samples) : $matches[0]);
// convert those words to all known encodings
$encodings = array ();
$db->exec ("select pk from encodings order by pk");
if ($db->FirstRow ()) {
do {
$encodings[] = $db->Get ("pk");
} while ($db->NextRow ());
}
$me = $_SERVER['PATH_INFO'] . htmlspecialchars ("?file=$file");
if ($more_samples) {
$caption = "Samples (first $samples of $found_samples found) <a href='$me&amp;samples=0'>show all</a>";
} else {
$caption = "Samples (all $found_samples found)";
if ($found_samples > 10)
$caption .= " <a href='$me&amp;samples=10'>show only first 10</a>";
}
echo ("<table><tr><th>Encoding</th><th>$caption</th></tr>\n");
function hex ($c) {
return sprintf ('\x%2X', ord ($c));
}
$sample = htmlspecialchars (@preg_replace ("/[\x80-\xFF]/e", 'hex ($0)', $words));
$sample = preg_replace ("/\n/", "<br/>", $sample);
echo ("<tr><th>hex-escaped</th><td>$sample</td></tr>\n");
mb_regex_encoding ("UTF-8");
mb_ereg_search_init ("[\x80-\x9F]");
foreach ($encodings as $enc) {
$wordslen = strlen ($words);
$sample = @iconv ($enc, "UTF-8", $words);
if ($sample) {
if (!mb_ereg ("[\200-\237]", $sample)) {
if (iconv_strlen ($sample, 'UTF-8') == $wordslen) {
$sample = preg_replace ("/\n/", "<br/>", htmlspecialchars ($sample));
echo ("<tr><th>$enc</th><td>$sample</td></tr>\n");
}
}
}
}
echo ("</table>");
pagefooter ();
// Local Variables:
// mode:php
// coding:utf-8-unix
// fill-column: 75
// End:
?>

View File

@ -0,0 +1,95 @@
<?php
include_once ("pgcat.phh");
authenticate ();
$db = $config->db ();
getstr ("file");
getint ("samples", 10);
pageheader ("Encoding Guesses for $file");
$root = "/public/ftp/pub/docs/books/gutenberg/";
$path = realpath ("$root$file");
if (!preg_match ("|^$root|", $path) || (!$hd = fopen ($path, "r"))) {
// serve only files below root
header("HTTP/1.0 404 Not Found");
echo ("I see no such file here\n");
exit;
}
// get some words with funny characters
$data = file_get_contents ($path);
preg_match_all ("/\b.{0,20}[\x80-\xFF].{0,20}\b/s", $data, $matches);
$found_samples = count ($matches[0]);
if ($found_samples == 0) {
echo ("<p>No non-ascii characters found.</p>");
pagefooter ();
exit ();
}
$more_samples = $samples > 0 && $found_samples > $samples;
$words = join ("\n", $samples ? array_slice ($matches[0], 0, $samples) : $matches[0]);
// convert those words to all known encodings
$encodings = array ();
$db->exec ("select pk from encodings order by pk");
if ($db->FirstRow ()) {
do {
$encodings[] = $db->Get ("pk");
} while ($db->NextRow ());
}
$me = $_SERVER['PATH_INFO'] . htmlspecialchars ("?file=$file");
if ($more_samples) {
$caption = "Samples (first $samples of $found_samples found) <a href='$me&amp;samples=0'>show all</a>";
} else {
$caption = "Samples (all $found_samples found)";
if ($found_samples > 10)
$caption .= " <a href='$me&amp;samples=10'>show only first 10</a>";
}
echo ("<table><tr><th>Encoding</th><th>$caption</th></tr>\n");
function hex ($c) {
return sprintf ('\x%2X', ord ($c));
}
$sample = htmlspecialchars (@preg_replace ("/[\x80-\xFF]/e", 'hex ($0)', $words));
$sample = preg_replace ("/\n/", "<br/>", $sample);
echo ("<tr><th>hex-escaped</th><td>$sample</td></tr>\n");
mb_regex_encoding ("UTF-8");
mb_ereg_search_init ("[\x80-\x9F]");
foreach ($encodings as $enc) {
$wordslen = strlen ($words);
$sample = @iconv ($enc, "UTF-8", $words);
if ($sample) {
if (!mb_ereg ("[\200-\237]", $sample)) {
if (iconv_strlen ($sample, 'UTF-8') == $wordslen) {
$sample = preg_replace ("/\n/", "<br/>", htmlspecialchars ($sample));
echo ("<tr><th>$enc</th><td>$sample</td></tr>\n");
}
}
}
}
echo ("</table>");
pagefooter ();
// Local Variables:
// mode:php
// coding:utf-8-unix
// fill-column: 75
// End:
?>

View File

@ -0,0 +1,84 @@
<?php
$cli = php_sapi_name () == "cli";
if (!$cli) exit ();
set_include_path(get_include_path() . PATH_SEPARATOR . "/public/vhost/g/gutenberg/dev/private/lib/php");
include_once ("pgcat.phh");
$db = $config->db ();
$cnt = 0;
$db->exec ("select author, url from authors, author_urls where authors.pk = author_urls.fk_authors order by url");
if ($db->FirstRow ()) {
do {
$url = $db->get ("url", SQLCHAR);
$author = $db->get ("author", SQLCHAR);
sleep (1);
if (!preg_match ("!^http://(.*?)(/.*)$!", $url, $matches)) {
echo ("$author\nNot a http url: $url\n");
$cnt++;
continue;
}
$host = $matches[1];
$path = $matches[2];
$sock = @fsockopen ($host, 80, $errno, $errstr, 120);
if (!$sock) {
echo ("$author\nHost $host unreachable! $errstr ($errno)\n");
$cnt++;
continue;
}
$request = "HEAD $path HTTP/1.0\r\nHost: $host\r\n\r\n";
// echo ($request);
fwrite ($sock, $request);
$headers = "";
while ($str = trim (fgets ($sock, 4096)))
$headers .= "$str\n";
fclose ($sock);
if (!preg_match ("!^HTTP/\d\.\d\s+(\d+)!", $headers, $matches)) {
echo ("$author\nGot bogus response from $host!\n\n($headers)\n\n");
$cnt++;
continue;
}
$code = intval ($matches[1]);
if ($code == 200) {
continue;
}
if ($code >= 300 && $code < 400) {
echo ("$author\n$url Redirected $code");
if (preg_match ("!^Location:\s+(.*)$!im", $headers, $matches)) {
$location = $matches[1];
echo (" to $location");
}
echo ("\n");
continue;
}
echo ("$author\n$url Error $code!\n");
$cnt++;
} while ($db->NextRow ());
}
if ($cnt) {
echo ("$cnt urls failed!!\n");
return 1;
}
return 0;
?>

View File

@ -0,0 +1,83 @@
<?php
$cli = php_sapi_name () == "cli";
if (!$cli) exit ();
include_once ("pgcat.phh");
$db = $config->db ();
$cnt = 0;
$db->exec ("select author, url from authors, author_urls where authors.pk = author_urls.fk_authors order by url");
if ($db->FirstRow ()) {
do {
$url = $db->get ("url", SQLCHAR);
$author = $db->get ("author", SQLCHAR);
sleep (1);
if (!preg_match ("!^http://(.*?)(/.*)$!", $url, $matches)) {
echo ("$author\nNot a http url: $url\n");
$cnt++;
continue;
}
$host = $matches[1];
$path = $matches[2];
$sock = @fsockopen ($host, 80, $errno, $errstr, 120);
if (!$sock) {
echo ("$author\nHost $host unreachable! $errstr ($errno)\n");
$cnt++;
continue;
}
$request = "HEAD $path HTTP/1.0\r\nHost: $host\r\n\r\n";
// echo ($request);
fwrite ($sock, $request);
$headers = "";
while ($str = trim (fgets ($sock, 4096)))
$headers .= "$str\n";
fclose ($sock);
if (!preg_match ("!^HTTP/\d\.\d\s+(\d+)!", $headers, $matches)) {
echo ("$author\nGot bogus response from $host!\n\n($headers)\n\n");
$cnt++;
continue;
}
$code = intval ($matches[1]);
if ($code == 200) {
continue;
}
if ($code >= 300 && $code < 400) {
echo ("$author\n$url Redirected $code");
if (preg_match ("!^Location:\s+(.*)$!im", $headers, $matches)) {
$location = $matches[1];
echo (" to $location");
}
echo ("\n");
continue;
}
echo ("$author\n$url Error $code!\n");
$cnt++;
} while ($db->NextRow ());
}
if ($cnt) {
echo ("$cnt urls failed!!\n");
return 1;
}
return 0;
?>

View File

@ -0,0 +1,44 @@
<?php
set_include_path(get_include_path() . PATH_SEPARATOR . "/public/vhost/g/gutenberg/dev/private/lib/php");
include_once ("pgcat.phh");
$cli = php_sapi_name () == "cli";
if (!$cli) {
exit ();
}
include_once ("sqlform.phh");
set_time_limit (0);
$db = $config->db ();
$db->exec ("select * from files where fk_filetypes = 'html' and fk_compressions = 'none' order by filename");
if ($db->FirstRow ()) {
do {
$filename = $db->get ("filename", SQLCHAR);
echo ("Checking $filename ...");
$url = "http://$config->domain/dirs/$filename";
$output = `/public/vhost/g/gutenberg/private/local/bin/checklink -q -s --broken $url`;
if (preg_match ("/broken links/i", $output)) {
echo (" ERRORS!\n$output\n");
$validator = "http://validator.w3.org/checklink?uri=" . urlencode ($url) . "&amp;hide_type=all&amp;depth=&amp;check=Check";
mail ("marcello@perathoner.de", "Broken links in $filename",
"Validator url:\n\n$validator\n\nValidator output was:\n$output",
"From: linkchecker@gutenberg.org\r\n" .
"Reply-To: webmaster@gutenberg.org\r\n");
} else {
echo (" OK\n");
}
} while ($db->NextRow ());
}
?>

View File

@ -0,0 +1,43 @@
<?php
include_once ("pgcat.phh");
$cli = php_sapi_name () == "cli";
if (!$cli) {
exit ();
}
include_once ("sqlform.phh");
set_time_limit (0);
$db = $config->db ();
$db->exec ("select * from files where fk_filetypes = 'html' and fk_compressions = 'none' order by filename");
if ($db->FirstRow ()) {
do {
$filename = $db->get ("filename", SQLCHAR);
echo ("Checking $filename ...");
$url = "http://$config->domain/dirs/$filename";
$output = `/public/vhost/g/gutenberg/private/local/bin/checklink -q -s --broken $url`;
if (preg_match ("/broken links/i", $output)) {
echo (" ERRORS!\n$output\n");
$validator = "http://validator.w3.org/checklink?uri=" . urlencode ($url) . "&amp;hide_type=all&amp;depth=&amp;check=Check";
mail ("marcello@perathoner.de", "Broken links in $filename",
"Validator url:\n\n$validator\n\nValidator output was:\n$output",
"From: linkchecker@gutenberg.org\r\n" .
"Reply-To: webmaster@gutenberg.org\r\n");
} else {
echo (" OK\n");
}
} while ($db->NextRow ());
}
?>

View File

@ -0,0 +1,19 @@
<?php
echo ('<p>start ...</p>');
flush ();
/*
for ($i = 0; $i < 31000; $i++) {
chmod ("/public/vhost/g/gutenberg/html/cache/bibrec/$i", 0777);
if (($i % 100) == 0) {
echo ("<p>$i</p>");
flush ();
}
}
*/
echo (`chmod -R 777 /public/vhost/g/gutenberg/html/cache/wiki/*`);
echo ('<p>done</p>');
?>

13
catalog/admin/cp.php Normal file
View File

@ -0,0 +1,13 @@
<?php
set_include_path(get_include_path() . PATH_SEPARATOR . "/public/vhost/g/gutenberg/dev/private/lib/php");
include ("pgcat.phh");
authenticate ();
getstr ("file");
header ("Content-Type: application/octet-stream");
readfile ($file);
?>

12
catalog/admin/cp.php~ Normal file
View File

@ -0,0 +1,12 @@
<?php
include ("pgcat.phh");
authenticate ();
getstr ("file");
header ("Content-Type: application/octet-stream");
readfile ($file);
?>

View File

@ -0,0 +1,115 @@
<?php
// For each (non-removed) file in the 'files' table,
// check that it still exists in the filesystem.
// If not, mark it as removed (diskstatus = 5).
set_include_path(get_include_path() . PATH_SEPARATOR . "/public/vhost/g/gutenberg/dev/private/lib/php");
include_once ("pgcat.phh");
$cli = php_sapi_name () == "cli";
if (!$cli) {
exit ();
}
include_once ("sqlform.phh");
$db = $config->db ();
$db->logger = new logger ();
echo ("Initializing ...\n");
register_shutdown_function ('rollback_transaction');
set_time_limit (0);
$cnt = 0;
$db->Exec ("select filename from files where diskstatus != 5 order by filename");
if ($db->FirstRow ()) {
do {
$files[$db->Get ("filename", SQLCHAR)] = 0;
$cnt++;
} while ($db->NextRow ());
}
echo ("$cnt files in database.\n");
echo ("Stat-ing files ...\n");
$cnt = 0;
$gonecnt = 0;
foreach ($files as $filename => $value) {
if ($filename[0] == '/') {
if (@stat ($filename) === FALSE) {
$gone[$filename] = 1;
$gonecnt++;
echo ("Gone: $filename\n");
}
} elseif (preg_match ('/^(cache|masters)\//', $filename)) {
if (@stat ("$config->documentroot/$filename") === FALSE) {
$gone[$filename] = 1;
$gonecnt++;
echo ("Gone: $config->documentroot//$filename\n");
}
} else {
if (@stat ("$config->filesroot/$filename") === FALSE) {
$gone[$filename] = 1;
$gonecnt++;
echo ("Gone: $config->filesroot//$filename\n");
}
}
$cnt++;
if (($cnt % 100000) == 0) {
echo ("Stat: $cnt gone: $gonecnt\n");
}
if ($gonecnt > 10000) {
echo ("Gone over 10.000 files!\nDeleted nothing. Check for errors.");
die ();
}
}
$files = null;
echo ("Gone: $gonecnt files\n");
// stat everything again, maybe nfs is flaky today
for ($i = 0; $i < 10; $i++) {
if (!$gonecnt)
break;
echo ("Waiting ...\n");
sleep (600);
echo ("Re-stat-ing: $gonecnt files\n");
clearstatcache ();
foreach ($gone as $filename => $value) {
if ($value == 1) {
if (preg_match ('/^cache\//', $filename)) {
if (@stat ("$config->documentroot/$filename") !== FALSE) {
$gone[$filename] = 0;
$gonecnt--;
}
} else {
if (@stat ("$config->filesroot/$filename") !== FALSE) {
$gone[$filename] = 0;
$gonecnt--;
}
}
}
}
}
if ($gonecnt) {
echo ("Deleting: $gonecnt files ...\n");
foreach ($gone as $filename => $value) {
if ($value == 1) {
echo ("Marking as deleted: $filename\n");
$esc_filename = addslashes($filename);
$db->exec ("update files set diskstatus = 5 where filename = '$esc_filename'");
$infofile = "$config->privateroot/fileinfo/$filename.info";
@unlink ($infofile);
}
}
}
echo ("Done.\n");
?>

View File

@ -0,0 +1,114 @@
<?php
// For each (non-removed) file in the 'files' table,
// check that it still exists in the filesystem.
// If not, mark it as removed (diskstatus = 5).
include_once ("pgcat.phh");
$cli = php_sapi_name () == "cli";
if (!$cli) {
exit ();
}
include_once ("sqlform.phh");
$db = $config->db ();
$db->logger = new logger ();
echo ("Initializing ...\n");
register_shutdown_function ('rollback_transaction');
set_time_limit (0);
$cnt = 0;
$db->Exec ("select filename from files where diskstatus != 5 order by filename");
if ($db->FirstRow ()) {
do {
$files[$db->Get ("filename", SQLCHAR)] = 0;
$cnt++;
} while ($db->NextRow ());
}
echo ("$cnt files in database.\n");
echo ("Stat-ing files ...\n");
$cnt = 0;
$gonecnt = 0;
foreach ($files as $filename => $value) {
if ($filename[0] == '/') {
if (@stat ($filename) === FALSE) {
$gone[$filename] = 1;
$gonecnt++;
echo ("Gone: $filename\n");
}
} elseif (preg_match ('/^(cache|masters)\//', $filename)) {
if (@stat ("$config->documentroot/$filename") === FALSE) {
$gone[$filename] = 1;
$gonecnt++;
echo ("Gone: $config->documentroot//$filename\n");
}
} else {
if (@stat ("$config->filesroot/$filename") === FALSE) {
$gone[$filename] = 1;
$gonecnt++;
echo ("Gone: $config->filesroot//$filename\n");
}
}
$cnt++;
if (($cnt % 100000) == 0) {
echo ("Stat: $cnt gone: $gonecnt\n");
}
if ($gonecnt > 10000) {
echo ("Gone over 10.000 files!\nDeleted nothing. Check for errors.");
die ();
}
}
$files = null;
echo ("Gone: $gonecnt files\n");
// stat everything again, maybe nfs is flaky today
for ($i = 0; $i < 10; $i++) {
if (!$gonecnt)
break;
echo ("Waiting ...\n");
sleep (600);
echo ("Re-stat-ing: $gonecnt files\n");
clearstatcache ();
foreach ($gone as $filename => $value) {
if ($value == 1) {
if (preg_match ('/^cache\//', $filename)) {
if (@stat ("$config->documentroot/$filename") !== FALSE) {
$gone[$filename] = 0;
$gonecnt--;
}
} else {
if (@stat ("$config->filesroot/$filename") !== FALSE) {
$gone[$filename] = 0;
$gonecnt--;
}
}
}
}
}
if ($gonecnt) {
echo ("Deleting: $gonecnt files ...\n");
foreach ($gone as $filename => $value) {
if ($value == 1) {
echo ("Marking as deleted: $filename\n");
$esc_filename = addslashes($filename);
$db->exec ("update files set diskstatus = 5 where filename = '$esc_filename'");
$infofile = "$config->privateroot/fileinfo/$filename.info";
@unlink ($infofile);
}
}
}
echo ("Done.\n");
?>

View File

@ -0,0 +1,27 @@
<?php
set_include_path(get_include_path() . PATH_SEPARATOR . "/public/vhost/g/gutenberg/dev/private/lib/php");
include_once ("pgcat.phh");
authenticate ();
$db = $config->db ();
$db->logger = new logger ();
pageheader("Books with duplicate MARC fields");
class DuplAttribTable extends ListTable {
function __construct () {
$this->AddColumn("<a href=\"dupl_attribs" .
"?fk_attriblist=#code#&cnt=#cnt#\">" .
"#name#</a>", "MARC Field");
$this->AddColumn("#cnt#", "# of fields per book");
$this->AddColumn("#count#", "# of books");
}
}
p("Click on the MARC Fields to see a list of the actual duplicates.");
$db->Exec("select name, code, cnt, count(cnt) from (select fk_attriblist as code, count(fk_attriblist) as cnt from attributes group by fk_books, fk_attriblist having count(fk_attriblist)>1) as foo join attriblist on code=attriblist.pk group by attriblist.pk, attriblist.name, code, cnt order by code");
$table = new DuplAttribTable();
$table->PrintTable($db, "Duplicate MARC Fields");
pagefooter();

View File

@ -0,0 +1,26 @@
<?php
include_once ("pgcat.phh");
authenticate ();
$db = $config->db ();
$db->logger = new logger ();
pageheader("Books with duplicate MARC fields");
class DuplAttribTable extends ListTable {
function __construct () {
$this->AddColumn("<a href=\"dupl_attribs" .
"?fk_attriblist=#code#&cnt=#cnt#\">" .
"#name#</a>", "MARC Field");
$this->AddColumn("#cnt#", "# of fields per book");
$this->AddColumn("#count#", "# of books");
}
}
p("Click on the MARC Fields to see a list of the actual duplicates.");
$db->Exec("select name, code, cnt, count(cnt) from (select fk_attriblist as code, count(fk_attriblist) as cnt from attributes group by fk_books, fk_attriblist having count(fk_attriblist)>1) as foo join attriblist on code=attriblist.pk group by attriblist.pk, attriblist.name, code, cnt order by code");
$table = new DuplAttribTable();
$table->PrintTable($db, "Duplicate MARC Fields");
pagefooter();

View File

@ -0,0 +1,34 @@
<?php
set_include_path(get_include_path() . PATH_SEPARATOR . "/public/vhost/g/gutenberg/dev/private/lib/php");
include_once ("pgcat.phh");
authenticate ();
$db = $config->db ();
$db->logger = new logger ();
getint("fk_attriblist");
getint("cnt");
$db->Exec("select name from attriblist where pk=$fk_attriblist");
$attr_name = $db->Get("name");
pageheader("Books with $cnt of the '$attr_name' field");
class DuplAttribDetailTable extends ListTable {
function __construct () {
$this->AddColumn("<a href=\"book?mode=edit&fk_books=#fk_books#\">" .
"#fk_books#</a>", "Etext #");
$this->AddColumn("#text#", "Text of field");
}
}
$table= new DuplAttribDetailTable();
$db->Exec ("select fk_books, text from attributes where fk_attriblist=$fk_attriblist and fk_books in (select fk_books from attributes where fk_attriblist=$fk_attriblist group by fk_books, fk_attriblist having count(fk_attriblist)=$cnt) order by fk_books");
$table->PrintTable($db, "");
/* TODO: Convert $cnt to words, i.e. "five" not "5" */
p("<a href=\"dupl_attrib_list\">Return to list</a>");
pagefooter();

View File

@ -0,0 +1,33 @@
<?php
include_once ("pgcat.phh");
authenticate ();
$db = $config->db ();
$db->logger = new logger ();
getint("fk_attriblist");
getint("cnt");
$db->Exec("select name from attriblist where pk=$fk_attriblist");
$attr_name = $db->Get("name");
pageheader("Books with $cnt of the '$attr_name' field");
class DuplAttribDetailTable extends ListTable {
function __construct () {
$this->AddColumn("<a href=\"book?mode=edit&fk_books=#fk_books#\">" .
"#fk_books#</a>", "Etext #");
$this->AddColumn("#text#", "Text of field");
}
}
$table= new DuplAttribDetailTable();
$db->Exec ("select fk_books, text from attributes where fk_attriblist=$fk_attriblist and fk_books in (select fk_books from attributes where fk_attriblist=$fk_attriblist group by fk_books, fk_attriblist having count(fk_attriblist)=$cnt) order by fk_books");
$table->PrintTable($db, "");
/* TODO: Convert $cnt to words, i.e. "five" not "5" */
p("<a href=\"dupl_attrib_list\">Return to list</a>");
pagefooter();

View File

@ -0,0 +1,32 @@
<?php
set_include_path(get_include_path() . PATH_SEPARATOR . "/public/vhost/g/gutenberg/dev/private/lib/php");
include_once ("pgcat.phh");
authenticate ();
$db = $config->db ();
$db->logger = new logger ();
class AuthorsBirthDeathDeletionTable extends ListTable {
function __construct () {
$this->AddColumn("<a href=\"author?mode=delete&fk_authors=#pk#\">" .
"Delete</a>", "", "narrow");
$this->AddColumn("<a href=\"author?mode=edit&fk_authors=#pk#\">" .
"#author#</a>", "Author");
$this->AddSimpleColumn("born_floor", "Birth");
$this->AddSimpleColumn("died_floor", "Death");
}
}
pageheader("Authors with no books");
$table = new AuthorsBirthDeathDeletionTable ();
$db->Exec("select distinct pk, author, born_floor, died_floor " .
"from authors left join mn_books_authors " .
"on fk_authors=authors.pk where fk_books is null " .
"order by author, pk");
$table->PrintTable($db, "Authors with no books linked");
pagefooter();

View File

@ -0,0 +1,31 @@
<?php
include_once ("pgcat.phh");
authenticate ();
$db = $config->db ();
$db->logger = new logger ();
class AuthorsBirthDeathDeletionTable extends ListTable {
function __construct () {
$this->AddColumn("<a href=\"author?mode=delete&fk_authors=#pk#\">" .
"Delete</a>", "", "narrow");
$this->AddColumn("<a href=\"author?mode=edit&fk_authors=#pk#\">" .
"#author#</a>", "Author");
$this->AddSimpleColumn("born_floor", "Birth");
$this->AddSimpleColumn("died_floor", "Death");
}
}
pageheader("Authors with no books");
$table = new AuthorsBirthDeathDeletionTable ();
$db->Exec("select distinct pk, author, born_floor, died_floor " .
"from authors left join mn_books_authors " .
"on fk_authors=authors.pk where fk_books is null " .
"order by author, pk");
$table->PrintTable($db, "Authors with no books linked");
pagefooter();

71
catalog/admin/file.php Normal file
View File

@ -0,0 +1,71 @@
<?php
set_include_path(get_include_path() . PATH_SEPARATOR . "/public/vhost/g/gutenberg/dev/private/lib/php");
include_once ("pgcat.phh");
authenticate ();
getstr ("mode");
$caption = ucfirst ($mode) . " File Entry";
pageheader ($caption);
include_once ("sqlform.phh");
$db = $config->db ();
$db->logger = new logger ();
$f = new SQLForm ();
getint ("fk_files");
getint ("fk_books");
if (ismode ("delete")) {
$f->SubCaption ("You are about to delete this file.");
$f->SubCaption ("Press the '$caption' button to continue or " .
"hit the back button on your browser to dismiss.");
} else {
if (ismode ("add")) {
$f->SQLInject ("fk_books", "fk_books", SQLINT);
}
$f->Text ("filename", "filename", "Filename", SQLCHAR, 80, 240, true);
$f->Text ("fk_books", "fk_books", "Etext-Nr.", SQLINT, 20, 80, false);
$f->Text ("edition", "edition", "Edition", SQLINT, 20, 80, false);
$f->Text ("filemtime", "filemtime", "File&nbsp;Modification&nbsp;Time", SQLDATE, 20, 20, false);
$f->CheckBox ("obsoleted", "obsoleted", "Obsoleted", SQLINT);
$f->SQLSelect ("fk_filetypes", "fk_filetypes", "File Type", SQLCHAR, 40, 80, true,
"select pk as value, filetype as caption from filetypes order by filetype");
$f->SQLSelect ("fk_compressions", "fk_compressions", "Compression", SQLCHAR, 40, 80, true,
"select pk as value, compression as caption from compressions order by compression");
$f->SQLSelect ("fk_encodings", "fk_encodings", "Encoding", SQLCHAR, 40, 80, false,
"select null as value, 'unknown' as caption union " .
"select pk as value, pk as caption from encodings order by caption");
$f->Text ("filesize", "filesize", "File Size", SQLINT, 20, 80, false);
$f->TextArea ("note", "note", "Note", SQLCHAR, 4, 80, false);
$f->LoadData ("select * from files where pk = $fk_files");
}
$f->Hidden ("fk_files");
$f->Hidden ("fk_books");
$f->Hidden ("filemask");
if (isupdatemode ("edit")) {
if ($f->Check ()) {
$sql = $f->mkUpdate ($db->GetFormatter ());
if ($db->Exec ("update files set " . $sql . "where pk = $fk_files")) {
msg ("File modified !");
} else {
error_msg ("Could not modify file !");
}
}
}
if (isupdate ()) {
getint ("fk_books");
getstr ("filemask");
echo ("<p><a href=\"files?fk_books=$fk_books&amp;filemask=$filemask\">Back to Book Files</a></p>\n\n");
} else {
$f->Output ($caption, $caption);
}
pagefooter ();
?>

70
catalog/admin/file.php~ Normal file
View File

@ -0,0 +1,70 @@
<?php
include_once ("pgcat.phh");
authenticate ();
getstr ("mode");
$caption = ucfirst ($mode) . " File Entry";
pageheader ($caption);
include_once ("sqlform.phh");
$db = $config->db ();
$db->logger = new logger ();
$f = new SQLForm ();
getint ("fk_files");
getint ("fk_books");
if (ismode ("delete")) {
$f->SubCaption ("You are about to delete this file.");
$f->SubCaption ("Press the '$caption' button to continue or " .
"hit the back button on your browser to dismiss.");
} else {
if (ismode ("add")) {
$f->SQLInject ("fk_books", "fk_books", SQLINT);
}
$f->Text ("filename", "filename", "Filename", SQLCHAR, 80, 240, true);
$f->Text ("fk_books", "fk_books", "Etext-Nr.", SQLINT, 20, 80, false);
$f->Text ("edition", "edition", "Edition", SQLINT, 20, 80, false);
$f->Text ("filemtime", "filemtime", "File&nbsp;Modification&nbsp;Time", SQLDATE, 20, 20, false);
$f->CheckBox ("obsoleted", "obsoleted", "Obsoleted", SQLINT);
$f->SQLSelect ("fk_filetypes", "fk_filetypes", "File Type", SQLCHAR, 40, 80, true,
"select pk as value, filetype as caption from filetypes order by filetype");
$f->SQLSelect ("fk_compressions", "fk_compressions", "Compression", SQLCHAR, 40, 80, true,
"select pk as value, compression as caption from compressions order by compression");
$f->SQLSelect ("fk_encodings", "fk_encodings", "Encoding", SQLCHAR, 40, 80, false,
"select null as value, 'unknown' as caption union " .
"select pk as value, pk as caption from encodings order by caption");
$f->Text ("filesize", "filesize", "File Size", SQLINT, 20, 80, false);
$f->TextArea ("note", "note", "Note", SQLCHAR, 4, 80, false);
$f->LoadData ("select * from files where pk = $fk_files");
}
$f->Hidden ("fk_files");
$f->Hidden ("fk_books");
$f->Hidden ("filemask");
if (isupdatemode ("edit")) {
if ($f->Check ()) {
$sql = $f->mkUpdate ($db->GetFormatter ());
if ($db->Exec ("update files set " . $sql . "where pk = $fk_files")) {
msg ("File modified !");
} else {
error_msg ("Could not modify file !");
}
}
}
if (isupdate ()) {
getint ("fk_books");
getstr ("filemask");
echo ("<p><a href=\"files?fk_books=$fk_books&amp;filemask=$filemask\">Back to Book Files</a></p>\n\n");
} else {
$f->Output ($caption, $caption);
}
pagefooter ();
?>

206
catalog/admin/files.php Normal file
View File

@ -0,0 +1,206 @@
<?php
set_include_path(get_include_path() . PATH_SEPARATOR . "/public/vhost/g/gutenberg/dev/private/lib/php");
include_once ("pgcat.phh");
authenticate ();
$db = $config->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 ("<a href=\"book?mode=edit&amp;fk_books=$fk_books\">Goto Edit Book Page</a> &mdash; " .
"<a href=\"$config->etext/${fk_books}\">Goto Bibrec Page</a>");
function mk_options ($name, $options, $option) {
$ret = "";
foreach ($options as $value => $opt) {
$selected = ($opt == $option) ? " selected=\"selected\"" : "";
$ret .= "<option value=\"$value\"$selected>$opt</option>\n";
}
return "<select name=\"${name}[]\">\n" . $ret . "</select>\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 "<td><a href=\"zipdir?file=$filename\" target=\"newwin\">Dir</a></td>";
return "<td><a href=\"head?file=$filename&amp;lines=500\" target=\"newwin\">Head</a></td>";
}
}
class CharsetColumn extends dbtSimpleColumn {
function __construct () {
parent::__construct (null, "", "narrow");
}
function Data ($db) {
$filename = $db->get ("filename");
if (preg_match ("/\.zip$/i", $filename))
return "<td></td>";
return "<td><a href=\"charset_guesser?file=$filename\" target=\"newwin\">Guess</a></td>";
}
}
class SizeColumn extends dbtSimpleColumn {
function __construct () {
parent::__construct (null, "Size", "pgdbfilessize");
}
function Header () {
return "<th class=\"pgdbfilessize\">Size</th>";
}
function Data ($db) {
return "<td class=\"pgdbfilessize\">" . human_readable_size ($db->get ("filesize")) . "</td>";
}
}
class FiletypeColumn extends dbtSimpleColumn {
function __construct () {
parent::__construct (null, "File&nbsp;Type", "pgdbfilesfiletype");
}
function Data ($db) {
global $filetypes;
return "<td>" . mk_options ("fk_filetypes", $filetypes, $db->get ("filetype")) . "</td>";
}
}
class CompressionColumn extends dbtSimpleColumn {
function __construct () {
parent::__construct (null, "Compression", "pgdbfilescompression");
}
function Data ($db) {
global $compressions;
return "<td>" . mk_options ("fk_compressions", $compressions, $db->get ("compression")) . "</td>";
}
}
class EncodingColumn extends dbtSimpleColumn {
function __construct () {
parent::__construct (null, "Encoding", "pgdbfilesencoding");
}
function Data ($db) {
global $encodings;
return "<td>" . mk_options ("fk_encodings", $encodings, $db->get ("fk_encodings")) . "</td>";
}
}
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 "<td><input type=\"checkbox\" name=\"obsoleteds[]\" value=\"$pk\"$obs /></td>";
}
}
form_open_get ();
echo ("Enter Perl RegExp: <input type=\"text\" name=\"filemask\" value=\"$filemask\" /> eg. /12345/");
form_relay ("fk_books");
form_submit ("Reload");
form_close ();
// Files for book
$prefix = "<a href=\"file?fk_books=$fk_books&mode";
$t = new ListTable ();
$t->AddColumn ("<input type=\"checkbox\" name=\"pks_update[]\" value=\"#pk#\" />", "", "narrow");
$t->AddColumn ("$prefix=edit&fk_files=#pk#\">Edit</a>", "", "narrow");
$t->AddColumnObject (new HeadColumn ());
$t->AddColumn ("<a href=\"mailto:errata2010@pglaf.org?subject=Bug in ebook $fk_books file #filename#\">Bug</a>", "", "narrow");
$t->AddColumn ("<a href=\"$config->downloadbase/#filename#\">#filename#</a>" .
"<input type=\"hidden\" name=\"filenames[]\" value=\"#filename#\" />",
"Filename");
$t->AddColumn ("<input type=\"text\" size=\"5\" name=\"fk_books_a[]\" value=\"#fk_books#\" />" .
"<input type=\"hidden\" name=\"pks[]\" value=\"#pk#\" />", "EBook");
$t->AddColumn ("<input type=\"text\" size=\"2\" name=\"editions[]\" value=\"#edition#\"/>", "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:
?>

205
catalog/admin/files.php~ Normal file
View File

@ -0,0 +1,205 @@
<?php
include_once ("pgcat.phh");
authenticate ();
$db = $config->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 ("<a href=\"book?mode=edit&amp;fk_books=$fk_books\">Goto Edit Book Page</a> &mdash; " .
"<a href=\"$config->etext/${fk_books}\">Goto Bibrec Page</a>");
function mk_options ($name, $options, $option) {
$ret = "";
foreach ($options as $value => $opt) {
$selected = ($opt == $option) ? " selected=\"selected\"" : "";
$ret .= "<option value=\"$value\"$selected>$opt</option>\n";
}
return "<select name=\"${name}[]\">\n" . $ret . "</select>\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 "<td><a href=\"zipdir?file=$filename\" target=\"newwin\">Dir</a></td>";
return "<td><a href=\"head?file=$filename&amp;lines=500\" target=\"newwin\">Head</a></td>";
}
}
class CharsetColumn extends dbtSimpleColumn {
function __construct () {
parent::__construct (null, "", "narrow");
}
function Data ($db) {
$filename = $db->get ("filename");
if (preg_match ("/\.zip$/i", $filename))
return "<td></td>";
return "<td><a href=\"charset_guesser?file=$filename\" target=\"newwin\">Guess</a></td>";
}
}
class SizeColumn extends dbtSimpleColumn {
function __construct () {
parent::__construct (null, "Size", "pgdbfilessize");
}
function Header () {
return "<th class=\"pgdbfilessize\">Size</th>";
}
function Data ($db) {
return "<td class=\"pgdbfilessize\">" . human_readable_size ($db->get ("filesize")) . "</td>";
}
}
class FiletypeColumn extends dbtSimpleColumn {
function __construct () {
parent::__construct (null, "File&nbsp;Type", "pgdbfilesfiletype");
}
function Data ($db) {
global $filetypes;
return "<td>" . mk_options ("fk_filetypes", $filetypes, $db->get ("filetype")) . "</td>";
}
}
class CompressionColumn extends dbtSimpleColumn {
function __construct () {
parent::__construct (null, "Compression", "pgdbfilescompression");
}
function Data ($db) {
global $compressions;
return "<td>" . mk_options ("fk_compressions", $compressions, $db->get ("compression")) . "</td>";
}
}
class EncodingColumn extends dbtSimpleColumn {
function __construct () {
parent::__construct (null, "Encoding", "pgdbfilesencoding");
}
function Data ($db) {
global $encodings;
return "<td>" . mk_options ("fk_encodings", $encodings, $db->get ("fk_encodings")) . "</td>";
}
}
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 "<td><input type=\"checkbox\" name=\"obsoleteds[]\" value=\"$pk\"$obs /></td>";
}
}
form_open_get ();
echo ("Enter Perl RegExp: <input type=\"text\" name=\"filemask\" value=\"$filemask\" /> eg. /12345/");
form_relay ("fk_books");
form_submit ("Reload");
form_close ();
// Files for book
$prefix = "<a href=\"file?fk_books=$fk_books&mode";
$t = new ListTable ();
$t->AddColumn ("<input type=\"checkbox\" name=\"pks_update[]\" value=\"#pk#\" />", "", "narrow");
$t->AddColumn ("$prefix=edit&fk_files=#pk#\">Edit</a>", "", "narrow");
$t->AddColumnObject (new HeadColumn ());
$t->AddColumn ("<a href=\"mailto:errata2010@pglaf.org?subject=Bug in ebook $fk_books file #filename#\">Bug</a>", "", "narrow");
$t->AddColumn ("<a href=\"$config->downloadbase/#filename#\">#filename#</a>" .
"<input type=\"hidden\" name=\"filenames[]\" value=\"#filename#\" />",
"Filename");
$t->AddColumn ("<input type=\"text\" size=\"5\" name=\"fk_books_a[]\" value=\"#fk_books#\" />" .
"<input type=\"hidden\" name=\"pks[]\" value=\"#pk#\" />", "EBook");
$t->AddColumn ("<input type=\"text\" size=\"2\" name=\"editions[]\" value=\"#edition#\"/>", "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:
?>

71
catalog/admin/files2.php Normal file
View File

@ -0,0 +1,71 @@
<?php
set_include_path(get_include_path() . PATH_SEPARATOR . "/public/vhost/g/gutenberg/dev/private/lib/php");
include_once ("pgcat.phh");
authenticate ();
pageheader ("Batch Update File Entries");
$db = $config->db ();
$db->logger = new logger ();
getint ("fk_files");
getint ("fk_books");
getstr ("filemask");
getarray ("pks_update");
getarray ("pks");
getarray ("fk_books_a");
getarray ("filenames");
getarray ("editions");
getarray ("obsoleteds");
getarray ("fk_filetypes");
getarray ("fk_compressions");
getarray ("fk_encodings");
foreach ($pks as $pk) {
$fk_book = array_shift ($fk_books_a);
$filename = array_shift ($filenames);
$edition = array_shift ($editions);
$fk_filetype = array_shift ($fk_filetypes);
$fk_compression = array_shift ($fk_compressions);
$fk_encoding = array_shift ($fk_encodings);
// p ("file: $pk $filename $fk_book $fk_filetype $fk_compression $fk_encoding");
if (!in_array ($pk, $pks_update))
continue;
$sql_pk = $db->f ($pk, SQLINT);
$sql_fk_books = $db->f ($fk_book, SQLINT);
$sql_edition = $db->f ($edition, SQLINT);
$sql_obsoleted = $db->f ($obsoleted, SQLINT);
$sql_fk_filetypes = $db->f ($fk_filetype, SQLCHAR);
$sql_fk_compressions = $db->f ($fk_compression, SQLCHAR);
$sql_fk_encodings = $db->f ($fk_encoding, SQLCHAR);
$sql_obsoleted = in_array ($pk, $obsoleteds) ? 1 : 0;
$sql = "update files set " .
"fk_books = $sql_fk_books, " .
"edition = $sql_edition, " .
"obsoleted = $sql_obsoleted, " .
"fk_filetypes = $sql_fk_filetypes, " .
"fk_compressions = $sql_fk_compressions, " .
"fk_encodings = $sql_fk_encodings " .
"where pk = $sql_pk";
// p ($sql);
if ($db->exec ($sql)) {
msg ("File $filename updated !");
} else {
error_msg ("Could not update file $filename !");
}
}
p ("<a href=\"files?fk_books=$fk_books&amp;filemask=$filemask\">Back to Book Files</a>");
pagefooter ();
?>

70
catalog/admin/files2.php~ Normal file
View File

@ -0,0 +1,70 @@
<?php
include_once ("pgcat.phh");
authenticate ();
pageheader ("Batch Update File Entries");
$db = $config->db ();
$db->logger = new logger ();
getint ("fk_files");
getint ("fk_books");
getstr ("filemask");
getarray ("pks_update");
getarray ("pks");
getarray ("fk_books_a");
getarray ("filenames");
getarray ("editions");
getarray ("obsoleteds");
getarray ("fk_filetypes");
getarray ("fk_compressions");
getarray ("fk_encodings");
foreach ($pks as $pk) {
$fk_book = array_shift ($fk_books_a);
$filename = array_shift ($filenames);
$edition = array_shift ($editions);
$fk_filetype = array_shift ($fk_filetypes);
$fk_compression = array_shift ($fk_compressions);
$fk_encoding = array_shift ($fk_encodings);
// p ("file: $pk $filename $fk_book $fk_filetype $fk_compression $fk_encoding");
if (!in_array ($pk, $pks_update))
continue;
$sql_pk = $db->f ($pk, SQLINT);
$sql_fk_books = $db->f ($fk_book, SQLINT);
$sql_edition = $db->f ($edition, SQLINT);
$sql_obsoleted = $db->f ($obsoleted, SQLINT);
$sql_fk_filetypes = $db->f ($fk_filetype, SQLCHAR);
$sql_fk_compressions = $db->f ($fk_compression, SQLCHAR);
$sql_fk_encodings = $db->f ($fk_encoding, SQLCHAR);
$sql_obsoleted = in_array ($pk, $obsoleteds) ? 1 : 0;
$sql = "update files set " .
"fk_books = $sql_fk_books, " .
"edition = $sql_edition, " .
"obsoleted = $sql_obsoleted, " .
"fk_filetypes = $sql_fk_filetypes, " .
"fk_compressions = $sql_fk_compressions, " .
"fk_encodings = $sql_fk_encodings " .
"where pk = $sql_pk";
// p ($sql);
if ($db->exec ($sql)) {
msg ("File $filename updated !");
} else {
error_msg ("Could not update file $filename !");
}
}
p ("<a href=\"files?fk_books=$fk_books&amp;filemask=$filemask\">Back to Book Files</a>");
pagefooter ();
?>

View File

@ -0,0 +1,35 @@
<?php
// delete fileinfos of removed files
set_include_path(get_include_path() . PATH_SEPARATOR . "/public/vhost/g/gutenberg/dev/private/lib/php");
include_once ("pgcat.phh");
$cli = php_sapi_name () == "cli";
if (!$cli) {
exit ();
}
include_once ("sqlform.phh");
$db = $config->db ();
set_time_limit (0);
$cnt = 0;
$db->Exec ("select filename from files where diskstatus = 5 order by filename");
if ($db->FirstRow ()) {
do {
$filename = $db->Get ("filename", SQLCHAR);
$infofile = "$config->privateroot/fileinfo/$filename.info";
echo ("unlinking $infofile\n");
if (unlink ($infofile))
$cnt++;
} while ($db->NextRow ());
}
echo ("unlinked $cnt files.\n");
echo ("Done.\n");
?>

View File

@ -0,0 +1,34 @@
<?php
// delete fileinfos of removed files
include_once ("pgcat.phh");
$cli = php_sapi_name () == "cli";
if (!$cli) {
exit ();
}
include_once ("sqlform.phh");
$db = $config->db ();
set_time_limit (0);
$cnt = 0;
$db->Exec ("select filename from files where diskstatus = 5 order by filename");
if ($db->FirstRow ()) {
do {
$filename = $db->Get ("filename", SQLCHAR);
$infofile = "$config->privateroot/fileinfo/$filename.info";
echo ("unlinking $infofile\n");
if (unlink ($infofile))
$cnt++;
} while ($db->NextRow ());
}
echo ("unlinked $cnt files.\n");
echo ("Done.\n");
?>

View File

@ -0,0 +1,32 @@
<?php
$cli = php_sapi_name () == "cli";
if (!$cli) exit ();
set_include_path(get_include_path() . PATH_SEPARATOR . "/public/vhost/g/gutenberg/dev/private/lib/php");
include_once ("pgcat.phh");
$db = $config->db ();
$db2 = $config->db ();
$db->exec ("select * from attributes where fk_attriblist = 505 and text ~ '^Contents:' order by text");
if ($db->FirstRow ()) {
do {
$title = $db->get ("text", SQLCHAR);
$orig = $title;
$pk = $db->get ("pk", SQLINT);
$nonfiling = "";
$title = preg_replace ("/^Contents: /", "", $title);
if ($title != $orig) {
$sql_title = $db-> f ($title, SQLCHAR);
echo ("update attributes set text = $sql_title where pk = $pk\n");
$db2->exec ("update attributes set text = $sql_title where pk = $pk");
}
} while ($db->NextRow ());
}
?>

View File

@ -0,0 +1,31 @@
<?php
$cli = php_sapi_name () == "cli";
if (!$cli) exit ();
include_once ("pgcat.phh");
$db = $config->db ();
$db2 = $config->db ();
$db->exec ("select * from attributes where fk_attriblist = 505 and text ~ '^Contents:' order by text");
if ($db->FirstRow ()) {
do {
$title = $db->get ("text", SQLCHAR);
$orig = $title;
$pk = $db->get ("pk", SQLINT);
$nonfiling = "";
$title = preg_replace ("/^Contents: /", "", $title);
if ($title != $orig) {
$sql_title = $db-> f ($title, SQLCHAR);
echo ("update attributes set text = $sql_title where pk = $pk\n");
$db2->exec ("update attributes set text = $sql_title where pk = $pk");
}
} while ($db->NextRow ());
}
?>

View File

@ -0,0 +1,95 @@
<?php
$cli = php_sapi_name () == "cli";
if (!$cli) exit ();
set_include_path(get_include_path() . PATH_SEPARATOR . "/public/vhost/g/gutenberg/dev/private/lib/php");
include_once ("pgcat.phh");
$db = $config->db ();
$db2 = $config->db ();
$trans = get_html_translation_table (HTML_ENTITIES);
$trans = array_flip ($trans);
array_walk ($trans, create_function ('&$v,$k', '$v = utf8_encode ($v);'));
$trans['&mdash;'] = chr (0xe2) . chr (0x80) . chr (0x94);
$trans['&ndash;'] = chr (0xe2) . chr (0x80) . chr (0x93);
$cnt = 0;
$db->exec ("select * from titles order by title");
if ($db->FirstRow ()) {
do {
$title = $db->get ("title", SQLCHAR);
$orig = $title;
$pk = $db->get ("pk", SQLINT);
$title = strtr ($title, $trans);
if ($title != $orig) {
$sql_title = $db-> f ($title, SQLCHAR);
echo ("update titles set title = $sql_title where pk = $pk\n");
$db2->exec ("update titles set title = $sql_title where pk = $pk");
$cnt++;
}
} while ($db->NextRow ());
}
echo ("$cnt title changes\n");
$cnt = 0;
$db->exec ("select * from authors order by author");
if ($db->FirstRow ()) {
do {
$author = $db->get ("author", SQLCHAR);
$orig = $author;
$pk = $db->get ("pk", SQLINT);
$author = strtr ($author, $trans);
if ($author != $orig) {
$sql_author = $db-> f ($author, SQLCHAR);
echo ("update authors set author = $sql_author where pk = $pk\n");
$db2->exec ("update authors set author = $sql_author where pk = $pk");
$cnt++;
}
} while ($db->NextRow ());
}
echo ("$cnt author changes\n");
$cnt = 0;
$db->exec ("select * from aliases order by alias");
if ($db->FirstRow ()) {
do {
$alias = $db->get ("alias", SQLCHAR);
$orig = $alias;
$pk = $db->get ("pk", SQLINT);
$alias = strtr ($alias, $trans);
if ($alias != $orig) {
$sql_alias = $db-> f ($alias, SQLCHAR);
echo ("update aliases set alias = $sql_alias where pk = $pk\n");
$db2->exec ("update aliases set alias = $sql_alias where pk = $pk");
$cnt++;
}
} while ($db->NextRow ());
}
echo ("$cnt alias changes\n");
?>

View File

@ -0,0 +1,94 @@
<?php
$cli = php_sapi_name () == "cli";
if (!$cli) exit ();
include_once ("pgcat.phh");
$db = $config->db ();
$db2 = $config->db ();
$trans = get_html_translation_table (HTML_ENTITIES);
$trans = array_flip ($trans);
array_walk ($trans, create_function ('&$v,$k', '$v = utf8_encode ($v);'));
$trans['&mdash;'] = chr (0xe2) . chr (0x80) . chr (0x94);
$trans['&ndash;'] = chr (0xe2) . chr (0x80) . chr (0x93);
$cnt = 0;
$db->exec ("select * from titles order by title");
if ($db->FirstRow ()) {
do {
$title = $db->get ("title", SQLCHAR);
$orig = $title;
$pk = $db->get ("pk", SQLINT);
$title = strtr ($title, $trans);
if ($title != $orig) {
$sql_title = $db-> f ($title, SQLCHAR);
echo ("update titles set title = $sql_title where pk = $pk\n");
$db2->exec ("update titles set title = $sql_title where pk = $pk");
$cnt++;
}
} while ($db->NextRow ());
}
echo ("$cnt title changes\n");
$cnt = 0;
$db->exec ("select * from authors order by author");
if ($db->FirstRow ()) {
do {
$author = $db->get ("author", SQLCHAR);
$orig = $author;
$pk = $db->get ("pk", SQLINT);
$author = strtr ($author, $trans);
if ($author != $orig) {
$sql_author = $db-> f ($author, SQLCHAR);
echo ("update authors set author = $sql_author where pk = $pk\n");
$db2->exec ("update authors set author = $sql_author where pk = $pk");
$cnt++;
}
} while ($db->NextRow ());
}
echo ("$cnt author changes\n");
$cnt = 0;
$db->exec ("select * from aliases order by alias");
if ($db->FirstRow ()) {
do {
$alias = $db->get ("alias", SQLCHAR);
$orig = $alias;
$pk = $db->get ("pk", SQLINT);
$alias = strtr ($alias, $trans);
if ($alias != $orig) {
$sql_alias = $db-> f ($alias, SQLCHAR);
echo ("update aliases set alias = $sql_alias where pk = $pk\n");
$db2->exec ("update aliases set alias = $sql_alias where pk = $pk");
$cnt++;
}
} while ($db->NextRow ());
}
echo ("$cnt alias changes\n");
?>

View File

@ -0,0 +1,42 @@
<?php
set_include_path(get_include_path() . PATH_SEPARATOR . "/public/vhost/g/gutenberg/dev/private/lib/php");
include_once ("pgcat.phh");
$cli = php_sapi_name () == "cli";
if (!$cli) {
exit ();
}
$db = $config->db ();
$db2 = $config->db ();
function getno ($filename) {
$etext_number = null;
if (preg_match ("/^(?:\d\/)+(\d{2,5})/", $filename, $matches)) {
$etext_number = intval ($matches[1]);
// double-check this
$dir = etext2dir ($etext_number);
if (strncmp ("$filename/", $dir, strlen ($dir)))
$etext_number = null;
} elseif (preg_match ("/^([1-9])$/", $filename, $matches)) {
$etext_number = intval ($matches[1]);
}
return $etext_number;
}
$db->exec ("select pk, filename from files where fk_books is null and diskstatus != 2");
if ($db->FirstRow ()) {
do {
$pk = $db->get ("pk", SQLINT);
$filename = $db->get ("filename", SQLCHAR);
$no = getno ($filename);
if (!empty ($no)) {
echo ("$no $filename\n");
$db2->exec ("update files set fk_books = $no where pk = $pk");
}
} while ($db->Nextrow ());
}
?>

View File

@ -0,0 +1,41 @@
<?php
include_once ("pgcat.phh");
$cli = php_sapi_name () == "cli";
if (!$cli) {
exit ();
}
$db = $config->db ();
$db2 = $config->db ();
function getno ($filename) {
$etext_number = null;
if (preg_match ("/^(?:\d\/)+(\d{2,5})/", $filename, $matches)) {
$etext_number = intval ($matches[1]);
// double-check this
$dir = etext2dir ($etext_number);
if (strncmp ("$filename/", $dir, strlen ($dir)))
$etext_number = null;
} elseif (preg_match ("/^([1-9])$/", $filename, $matches)) {
$etext_number = intval ($matches[1]);
}
return $etext_number;
}
$db->exec ("select pk, filename from files where fk_books is null and diskstatus != 2");
if ($db->FirstRow ()) {
do {
$pk = $db->get ("pk", SQLINT);
$filename = $db->get ("filename", SQLCHAR);
$no = getno ($filename);
if (!empty ($no)) {
echo ("$no $filename\n");
$db2->exec ("update files set fk_books = $no where pk = $pk");
}
} while ($db->Nextrow ());
}
?>

View File

@ -0,0 +1,61 @@
<?php
$cli = php_sapi_name () == "cli";
if (!$cli) exit ();
set_include_path(get_include_path() . PATH_SEPARATOR . "/public/vhost/g/gutenberg/dev/private/lib/php");
include_once ("pgcat.phh");
$db = $config->db ();
$db2 = $config->db ();
$articles = array ("The", "A", "An", "La", "Le", "Der", "Die", "Das");
$prepositions = array ("The", "A", "An", "In", "From", "To", "On", "Of", "Out", "For",
"Into", "At", "About", "And", "Or", "But", "With", "Under", "Over", "As");
foreach ($prepositions as $s) {
$search[] = " $s ";
$replace[] = strtolower (" $s ");
}
$search[] = "--";
$replace[] = "&mdash;";
$search[] = "Vol.";
$replace[] = "Volume";
$search[] = "vol.";
$replace[] = "Volume";
$db->exec ("select * from titles order by title");
if ($db->FirstRow ()) {
do {
$title = $db->get ("title", SQLCHAR);
$orig = $title;
$pk = $db->get ("pk", SQLINT);
$nonfiling = "";
if (preg_match ("/Reserved:/i", $title))
continue;
foreach ($articles as $article) {
if (preg_match ("/, $article\$/", $title)) {
$title = preg_replace ("/, $article\$/", "", $title);
$title = "$article $title";
$nonfiling = ", nonfiling = " . strlen ("$article ");
break;
}
}
$title = str_replace ($search, $replace, $title);
if ($title != $orig) {
$sql_title = $db-> f ($title, SQLCHAR);
echo ("update titles set title = $sql_title$nonfiling where pk = $pk\n");
$db2->exec ("update titles set title = $sql_title$nonfiling where pk = $pk");
}
} while ($db->NextRow ());
}
?>

View File

@ -0,0 +1,60 @@
<?php
$cli = php_sapi_name () == "cli";
if (!$cli) exit ();
include_once ("pgcat.phh");
$db = $config->db ();
$db2 = $config->db ();
$articles = array ("The", "A", "An", "La", "Le", "Der", "Die", "Das");
$prepositions = array ("The", "A", "An", "In", "From", "To", "On", "Of", "Out", "For",
"Into", "At", "About", "And", "Or", "But", "With", "Under", "Over", "As");
foreach ($prepositions as $s) {
$search[] = " $s ";
$replace[] = strtolower (" $s ");
}
$search[] = "--";
$replace[] = "&mdash;";
$search[] = "Vol.";
$replace[] = "Volume";
$search[] = "vol.";
$replace[] = "Volume";
$db->exec ("select * from titles order by title");
if ($db->FirstRow ()) {
do {
$title = $db->get ("title", SQLCHAR);
$orig = $title;
$pk = $db->get ("pk", SQLINT);
$nonfiling = "";
if (preg_match ("/Reserved:/i", $title))
continue;
foreach ($articles as $article) {
if (preg_match ("/, $article\$/", $title)) {
$title = preg_replace ("/, $article\$/", "", $title);
$title = "$article $title";
$nonfiling = ", nonfiling = " . strlen ("$article ");
break;
}
}
$title = str_replace ($search, $replace, $title);
if ($title != $orig) {
$sql_title = $db-> f ($title, SQLCHAR);
echo ("update titles set title = $sql_title$nonfiling where pk = $pk\n");
$db2->exec ("update titles set title = $sql_title$nonfiling where pk = $pk");
}
} while ($db->NextRow ());
}
?>

51
catalog/admin/fixurls.php Normal file
View File

@ -0,0 +1,51 @@
<?php
$cli = php_sapi_name () == "cli";
if (!$cli) exit ();
set_include_path(get_include_path() . PATH_SEPARATOR . "/public/vhost/g/gutenberg/dev/private/lib/php");
include_once ("pgcat.phh");
$db = $config->db ();
$db2 = $config->db ();
$cnt = 0;
$db->exec ("select * from author_urls order by url");
if ($db->FirstRow ()) {
do {
$url = $db->get ("url", SQLCHAR);
$orig = $url;
$pk = $db->get ("pk", SQLINT);
$url = rawurldecode ($url);
if ($url == $orig) {
continue;
}
// echo ("$orig\n");
if (utf8_encode (utf8_decode ($url)) != $url) {
// not an utf-8 string
if (($url = iconv ("ISO-8859-1", "UTF-8", $url)) === FALSE) {
// nor an iso-8859-1 one ???
// punt on this one
continue;
}
}
// echo ("$url\n");
if ($url != $orig) {
$sql_url = $db-> f ($url, SQLCHAR);
echo ("update author_urls set url = $sql_url where pk = $pk\n");
$db2->exec ("update author_urls set url = $sql_url where pk = $pk;");
$cnt++;
}
} while ($db->NextRow ());
}
echo ("$cnt url changes\n");
?>

View File

@ -0,0 +1,50 @@
<?php
$cli = php_sapi_name () == "cli";
if (!$cli) exit ();
include_once ("pgcat.phh");
$db = $config->db ();
$db2 = $config->db ();
$cnt = 0;
$db->exec ("select * from author_urls order by url");
if ($db->FirstRow ()) {
do {
$url = $db->get ("url", SQLCHAR);
$orig = $url;
$pk = $db->get ("pk", SQLINT);
$url = rawurldecode ($url);
if ($url == $orig) {
continue;
}
// echo ("$orig\n");
if (utf8_encode (utf8_decode ($url)) != $url) {
// not an utf-8 string
if (($url = iconv ("ISO-8859-1", "UTF-8", $url)) === FALSE) {
// nor an iso-8859-1 one ???
// punt on this one
continue;
}
}
// echo ("$url\n");
if ($url != $orig) {
$sql_url = $db-> f ($url, SQLCHAR);
echo ("update author_urls set url = $sql_url where pk = $pk\n");
$db2->exec ("update author_urls set url = $sql_url where pk = $pk;");
$cnt++;
}
} while ($db->NextRow ());
}
echo ("$cnt url changes\n");
?>

View File

@ -0,0 +1,82 @@
<?php
$cli = php_sapi_name () == "cli";
if (!$cli) exit ();
set_include_path(get_include_path() . PATH_SEPARATOR . "/public/vhost/g/gutenberg/dev/private/lib/php");
include ("pgcat.phh");
$gutindex = "$config->documentroot/dirs/GUTINDEX.ALL.iso-8859-1.txt";
$fp = fopen ($gutindex, "r");
if (!$fp) {
die ("cannot open $gutindex");
}
$db = $config->db ();
$pks = array ();
$gutindex = array ();
$db->exec ("select * from books");
if ($db->FirstRow ()) {
do {
$pk = $db->get ("pk", SQLINT);
$pks[$pk] = 1;
} while ($db->NextRow ());
}
$mode = 0;
$pk = 0;
$buffer = "";
while (!feof ($fp)) {
$line = fgets ($fp);
$tline = trim ($line);
switch ($mode) {
case 0:
if (preg_match ("/^~ ~ ~ ~/", $tline, $matches)) {
$mode = 1;
}
break;
case 1:
if ($tline == "<==End of GUTINDEX.ALL==>") {
$mode = 0;
break;
}
// fall thru
case 2:
if (preg_match ("/(\d+)[-BC]?$/", $tline, $matches)) {
if (!preg_match ("/GUTINDEX/", $tline)) {
$gutindex[$pk] = $buffer;
$buffer = utf8_encode ($line);
$mode = 2;
$pk = intval ($matches [1]);
break;
}
}
if (empty ($tline) || preg_match ("/\*$/", $tline)) {
$gutindex[$pk] = $buffer;
$buffer = "";
$mode = 1;
$pk = 0;
break;
}
$buffer .= utf8_encode ($line);
break;
}
}
fclose ($fp);
foreach ($gutindex as $pk => $book) {
if (isset ($pks[$pk])) {
$sql_book = $db->f ($book, SQLCHAR);
$db->exec ("update books set gutindex = $sql_book where pk = $pk");
$db->exec ("commit");
// echo ("Updated #$pk\n");
}
}
?>

View File

@ -0,0 +1,81 @@
<?php
$cli = php_sapi_name () == "cli";
if (!$cli) exit ();
include ("pgcat.phh");
$gutindex = "$config->documentroot/dirs/GUTINDEX.ALL.iso-8859-1.txt";
$fp = fopen ($gutindex, "r");
if (!$fp) {
die ("cannot open $gutindex");
}
$db = $config->db ();
$pks = array ();
$gutindex = array ();
$db->exec ("select * from books");
if ($db->FirstRow ()) {
do {
$pk = $db->get ("pk", SQLINT);
$pks[$pk] = 1;
} while ($db->NextRow ());
}
$mode = 0;
$pk = 0;
$buffer = "";
while (!feof ($fp)) {
$line = fgets ($fp);
$tline = trim ($line);
switch ($mode) {
case 0:
if (preg_match ("/^~ ~ ~ ~/", $tline, $matches)) {
$mode = 1;
}
break;
case 1:
if ($tline == "<==End of GUTINDEX.ALL==>") {
$mode = 0;
break;
}
// fall thru
case 2:
if (preg_match ("/(\d+)[-BC]?$/", $tline, $matches)) {
if (!preg_match ("/GUTINDEX/", $tline)) {
$gutindex[$pk] = $buffer;
$buffer = utf8_encode ($line);
$mode = 2;
$pk = intval ($matches [1]);
break;
}
}
if (empty ($tline) || preg_match ("/\*$/", $tline)) {
$gutindex[$pk] = $buffer;
$buffer = "";
$mode = 1;
$pk = 0;
break;
}
$buffer .= utf8_encode ($line);
break;
}
}
fclose ($fp);
foreach ($gutindex as $pk => $book) {
if (isset ($pks[$pk])) {
$sql_book = $db->f ($book, SQLCHAR);
$db->exec ("update books set gutindex = $sql_book where pk = $pk");
$db->exec ("commit");
// echo ("Updated #$pk\n");
}
}
?>

29
catalog/admin/head.php Normal file
View File

@ -0,0 +1,29 @@
<?php
set_include_path(get_include_path() . PATH_SEPARATOR . "/public/vhost/g/gutenberg/dev/private/lib/php");
include_once ("pgcat.phh");
authenticate ();
$root = "/public/ftp/pub/docs/books/gutenberg/";
$file = realpath ($root . $_REQUEST['file']);
$lines = intval ($_REQUEST['lines']);
if (!preg_match ("|^$root|", $file) || (!$hd = fopen ($file, "r"))) {
// serve only files below root
header("HTTP/1.0 404 Not Found");
echo ("I see no such file here\n");
exit;
}
header ("Content-Type: text/plain");
while ((!feof ($hd)) && ($lines > 0)) {
$buffer = fgets ($hd, 4096);
echo ($buffer);
--$lines;
}
fclose ($hd);
?>

27
catalog/admin/head.php~ Normal file
View File

@ -0,0 +1,27 @@
<?php
include_once ("pgcat.phh");
authenticate ();
$root = "/public/ftp/pub/docs/books/gutenberg/";
$file = realpath ($root . $_REQUEST['file']);
$lines = intval ($_REQUEST['lines']);
if (!preg_match ("|^$root|", $file) || (!$hd = fopen ($file, "r"))) {
// serve only files below root
header("HTTP/1.0 404 Not Found");
echo ("I see no such file here\n");
exit;
}
header ("Content-Type: text/plain");
while ((!feof ($hd)) && ($lines > 0)) {
$buffer = fgets ($hd, 4096);
echo ($buffer);
--$lines;
}
fclose ($hd);
?>

139
catalog/admin/index.php Normal file
View File

@ -0,0 +1,139 @@
<?php
set_include_path(get_include_path() . PATH_SEPARATOR . "/public/vhost/g/gutenberg/dev/private/lib/php");
include_once ("pgcat.phh");
authenticate ();
pageheader ("Administration Index");
?>
<h2>Read This First</h2>
<h3>Entities and relations</h3>
<p>In this catalog you will find 2 different recurring concepts:</p>
<ul>
<li>the entity</li>
<li>the relation (or link).</li>
</ul>
<p>Don't confuse database link (relation) with HTML-link (underlined
text to click.)</p>
<p>Book, Author, Subject, Language and LoC Class are entities.</p>
<p>Book-Author, Book-Subject, Book-Language and Book-LoC Class are
relations.</p>
<p>You can <strong>add</strong>, <strong>edit</strong> and
<strong>delete</strong> entities. Add an author, add a book. You can
create and remove links between existing entities (<strong>link</strong>
and <strong>unlink</strong> entities). Link an author to a book.
Remember: to link you have to create the entities first. Of course, if
you find that the entity already exists in the catalog, you should not
create it again.</p>
<p>The advantage of the entity and link concept is that you have to enter data
only once. Every author exists only once in the database. You have to enter
the date of birth and of death only once. You have to enter the pseudonyms
and different orthografies of the name only once. If you find an error, you
have to fix it only once.</p>
<p>To add a new book:</p>
<ol>
<li>Search for the author. If you don't find her, add her.</li>
<li>Enter the book data.</li>
<li>Link the author to the book.</li>
</ol>
<h3>HTML-Links and Buttons</h3>
<p>Clicking on a HTML-link will never alter any data.</p>
<p>Clicking on a button with: add, edit, delete, link or unlink in the
caption will alter data. (There are some other buttons though that don't
alter data.) </p>
<h2>Starting points</h2>
<h3>Reports / Statistics</h3>
<h4><a href="attribute_stats">MARC Attribute usage</a></h4>
<p>List all the MARC attributes/tags/codes currently in the system,
and how many records use them; and see the usage.</p>
<h4><a href="subj_locc_by_etext">Books lacking a Subject and/or a LoCC</a></h4>
<p>List all the books which do not have any Subjects and/or LoCCs attached to them,
sorted by Etext#, i.e. least recent first.</p>
<h4><a href="stats">Statistics</a></h4>
<p> Various statistics, mainly focused on authors.</p>
<h4><a href="empty_authors.php">Authors with no books</a></h4>
<p>A list of author entries that have no books attached to them, which usually means
they should be deleted.</p>
<h4><a href="dupl_attrib_list">Duplicate MARC attributes</a></h4>
<p>MARC attributes whose values are not unique.</p>
<h3>User Tasks</h3>
<h4><a href="authors_list">Authors</a></h4>
<p>Manage authors, author aliases and interesting URLs for author.</p>
<h4><a href="books_form">Books</a></h4>
<p>Manage books, book-titles, book-authors, book-subjects, book-languages
and book-LoC classes.</p>
<h4><a href="titles">Batch-Edit Titles</a></h4>
<p>Select a batch of titles by regular expression and
edit them all in one place.</p>
<h4><a href="subjects_list">Subjects</a></h4>
<p>Manage subjects.</p>
<h4><a href="categories_list">Categories</a></h4>
<p>Manage categories.</p>
<h4><a href="loccs_list">LoC Classes</a></h4>
<p>Manage LoC Classes.</p>
<h4><a href="langs_list">Languages</a></h4>
<p>Manage Languages. You will seldom need this, as most languages are
already entered.</p>
<h4><a href="password">Change Password</a></h4>
<p>Change your password. You'll probably have to login again.</p>
<h3>Administrator Tasks</h3>
<p>Requires Administrator rights.</p>
<h4><a href="users_list">Users</a></h4>
<p>Manage users. Add, remove, reset password etc.</p>
<h4><a href="mirrors_list">Mirrors</a></h4>
<p>Manage mirrors.</p>
<?php
pagefooter ();
?>

137
catalog/admin/index.php~ Normal file
View File

@ -0,0 +1,137 @@
<?php
include_once ("pgcat.phh");
authenticate ();
pageheader ("Administration Index");
?>
<h2>Read This First</h2>
<h3>Entities and relations</h3>
<p>In this catalog you will find 2 different recurring concepts:</p>
<ul>
<li>the entity</li>
<li>the relation (or link).</li>
</ul>
<p>Don't confuse database link (relation) with HTML-link (underlined
text to click.)</p>
<p>Book, Author, Subject, Language and LoC Class are entities.</p>
<p>Book-Author, Book-Subject, Book-Language and Book-LoC Class are
relations.</p>
<p>You can <strong>add</strong>, <strong>edit</strong> and
<strong>delete</strong> entities. Add an author, add a book. You can
create and remove links between existing entities (<strong>link</strong>
and <strong>unlink</strong> entities). Link an author to a book.
Remember: to link you have to create the entities first. Of course, if
you find that the entity already exists in the catalog, you should not
create it again.</p>
<p>The advantage of the entity and link concept is that you have to enter data
only once. Every author exists only once in the database. You have to enter
the date of birth and of death only once. You have to enter the pseudonyms
and different orthografies of the name only once. If you find an error, you
have to fix it only once.</p>
<p>To add a new book:</p>
<ol>
<li>Search for the author. If you don't find her, add her.</li>
<li>Enter the book data.</li>
<li>Link the author to the book.</li>
</ol>
<h3>HTML-Links and Buttons</h3>
<p>Clicking on a HTML-link will never alter any data.</p>
<p>Clicking on a button with: add, edit, delete, link or unlink in the
caption will alter data. (There are some other buttons though that don't
alter data.) </p>
<h2>Starting points</h2>
<h3>Reports / Statistics</h3>
<h4><a href="attribute_stats">MARC Attribute usage</a></h4>
<p>List all the MARC attributes/tags/codes currently in the system,
and how many records use them; and see the usage.</p>
<h4><a href="subj_locc_by_etext">Books lacking a Subject and/or a LoCC</a></h4>
<p>List all the books which do not have any Subjects and/or LoCCs attached to them,
sorted by Etext#, i.e. least recent first.</p>
<h4><a href="stats">Statistics</a></h4>
<p> Various statistics, mainly focused on authors.</p>
<h4><a href="empty_authors.php">Authors with no books</a></h4>
<p>A list of author entries that have no books attached to them, which usually means
they should be deleted.</p>
<h4><a href="dupl_attrib_list">Duplicate MARC attributes</a></h4>
<p>MARC attributes whose values are not unique.</p>
<h3>User Tasks</h3>
<h4><a href="authors_list">Authors</a></h4>
<p>Manage authors, author aliases and interesting URLs for author.</p>
<h4><a href="books_form">Books</a></h4>
<p>Manage books, book-titles, book-authors, book-subjects, book-languages
and book-LoC classes.</p>
<h4><a href="titles">Batch-Edit Titles</a></h4>
<p>Select a batch of titles by regular expression and
edit them all in one place.</p>
<h4><a href="subjects_list">Subjects</a></h4>
<p>Manage subjects.</p>
<h4><a href="categories_list">Categories</a></h4>
<p>Manage categories.</p>
<h4><a href="loccs_list">LoC Classes</a></h4>
<p>Manage LoC Classes.</p>
<h4><a href="langs_list">Languages</a></h4>
<p>Manage Languages. You will seldom need this, as most languages are
already entered.</p>
<h4><a href="password">Change Password</a></h4>
<p>Change your password. You'll probably have to login again.</p>
<h3>Administrator Tasks</h3>
<p>Requires Administrator rights.</p>
<h4><a href="users_list">Users</a></h4>
<p>Manage users. Add, remove, reset password etc.</p>
<h4><a href="mirrors_list">Mirrors</a></h4>
<p>Manage mirrors.</p>
<?php
pagefooter ();
?>

View File

@ -0,0 +1,128 @@
<?php
set_include_path(get_include_path() . PATH_SEPARATOR . "/public/vhost/g/gutenberg/dev/private/lib/php");
include_once ("pgcat.phh");
authenticate ();
pageheader ($caption = "IP Activity Monitor");
p ("My IP: {$_SERVER['REMOTE_ADDR']}");
p ("Collecting data ...");
flush ();
for ($i = 0; $i < 60; $i++) {
$ip = mmcache_get ("pglastip");
$ips[$ip]++;
sleep (1);
}
foreach ($ips as $ip => $cnt) {
p ("$ip => $cnt");
}
/*
function fixnetwork ($ip) {
if (($pos = strpos ($ip, "/")) !== false) {
$ip = substr ($ip, 0, $pos);
$ip = long2ip (ip2long ($ip) + 1);
}
return $ip;
}
class CalcFieldHost {
function f ($db) {
return @gethostbyaddr (fixnetwork ($db->get ("ip", SQLCHAR)));
}
}
class CalcFieldRBL {
function __construct ($list) {
$this->list = $list;
}
function f ($db) {
$ip = fixnetwork ($db->get ("ip", SQLCHAR));
$reverse_ip = join (".", array_reverse (explode (".", $ip)));
$host = gethostbyname ("$reverse_ip.$this->list");
// return $host; // debug
return strncmp ($host, "127.", 4) ? "" : "Yes";
}
}
class RobotHitTable extends ListTable {
function __construct () {
$this->AddSimpleColumn ("date", "Date");
$this->AddSimpleColumn ("ip", "IP");
$this->AddSimpleColumn ("c_host", "Host");
$this->AddSimpleColumn ("hits", "Hits");
$this->AddSimpleColumn ("restricted", "Restricted");
$this->AddSimpleColumn ("c_isdialup", "Dialup");
$this->AddSimpleColumn ("c_spam", "Spam");
$this->AddSimpleColumn ("c_spews", "SPEWS");
}
}
class RobotJailTable extends ListTable {
function __construct () {
$this->AddSimpleColumn ("firstseen", "First Sighted");
$this->AddSimpleColumn ("lastseen", "Last Seen");
$this->AddSimpleColumn ("ip", "IP");
$this->AddSimpleColumn ("c_host", "Host");
$this->AddSimpleColumn ("hits", "Hits");
$this->AddSimpleColumn ("restricted", "Restricted");
$this->AddSimpleColumn ("charge", "Charge");
$this->AddSimpleColumn ("c_isdialup", "Dialup");
$this->AddSimpleColumn ("c_spam", "Spam");
$this->AddSimpleColumn ("c_spews", "SPEWS");
$this->AddSimpleColumn ("ua", "User-Agent");
}
}
$db = $config->db ();
$db->exec ("select * from robots.stat");
$lastcron = $db->get ("lastcron", SQLCHAR);
p ("Last Cron Run: $lastcron");
// Jailed
$db->exec ("
select * from robots.jail order by firstseen;
");
$db->calcfields ["c_host"] = new CalcFieldHost ();
$db->calcfields ["c_isdialup"] = new CalcFieldRBL ("dul.dnsbl.sorbs.net");
$db->calcfields ["c_spam"] = new CalcFieldRBL ("spam.dnsbl.sorbs.net");
$db->calcfields ["c_spews"] = new CalcFieldRBL ("l2.spews.dnsbl.sorbs.net");
$table = new RobotJailTable ();
$table->PrintTable ($db, "Currently Jailed Robots");
flush ();
// Recent
$db->exec ("
select date, ip, hits, restricted from robots.hit_totals
union
select current_date, ip, count (ip), sum (restricted) from robots.hits
group by ip having count (ip) > 1000
order by date desc, ip;
");
$db->calcfields ["c_host"] = new CalcFieldHost ();
$db->calcfields ["c_isdialup"] = new CalcFieldRBL ("dul.dnsbl.sorbs.net");
$db->calcfields ["c_spam"] = new CalcFieldRBL ("spam.dnsbl.sorbs.net");
$db->calcfields ["c_spews"] = new CalcFieldRBL ("l2.spews.dnsbl.sorbs.net");
$table = new RobotHitTable ();
$table->PrintTable ($db, "Recently Active Robots");
flush ();
*/
pagefooter ();
?>

View File

@ -0,0 +1,127 @@
<?php
include_once ("pgcat.phh");
authenticate ();
pageheader ($caption = "IP Activity Monitor");
p ("My IP: {$_SERVER['REMOTE_ADDR']}");
p ("Collecting data ...");
flush ();
for ($i = 0; $i < 60; $i++) {
$ip = mmcache_get ("pglastip");
$ips[$ip]++;
sleep (1);
}
foreach ($ips as $ip => $cnt) {
p ("$ip => $cnt");
}
/*
function fixnetwork ($ip) {
if (($pos = strpos ($ip, "/")) !== false) {
$ip = substr ($ip, 0, $pos);
$ip = long2ip (ip2long ($ip) + 1);
}
return $ip;
}
class CalcFieldHost {
function f ($db) {
return @gethostbyaddr (fixnetwork ($db->get ("ip", SQLCHAR)));
}
}
class CalcFieldRBL {
function __construct ($list) {
$this->list = $list;
}
function f ($db) {
$ip = fixnetwork ($db->get ("ip", SQLCHAR));
$reverse_ip = join (".", array_reverse (explode (".", $ip)));
$host = gethostbyname ("$reverse_ip.$this->list");
// return $host; // debug
return strncmp ($host, "127.", 4) ? "" : "Yes";
}
}
class RobotHitTable extends ListTable {
function __construct () {
$this->AddSimpleColumn ("date", "Date");
$this->AddSimpleColumn ("ip", "IP");
$this->AddSimpleColumn ("c_host", "Host");
$this->AddSimpleColumn ("hits", "Hits");
$this->AddSimpleColumn ("restricted", "Restricted");
$this->AddSimpleColumn ("c_isdialup", "Dialup");
$this->AddSimpleColumn ("c_spam", "Spam");
$this->AddSimpleColumn ("c_spews", "SPEWS");
}
}
class RobotJailTable extends ListTable {
function __construct () {
$this->AddSimpleColumn ("firstseen", "First Sighted");
$this->AddSimpleColumn ("lastseen", "Last Seen");
$this->AddSimpleColumn ("ip", "IP");
$this->AddSimpleColumn ("c_host", "Host");
$this->AddSimpleColumn ("hits", "Hits");
$this->AddSimpleColumn ("restricted", "Restricted");
$this->AddSimpleColumn ("charge", "Charge");
$this->AddSimpleColumn ("c_isdialup", "Dialup");
$this->AddSimpleColumn ("c_spam", "Spam");
$this->AddSimpleColumn ("c_spews", "SPEWS");
$this->AddSimpleColumn ("ua", "User-Agent");
}
}
$db = $config->db ();
$db->exec ("select * from robots.stat");
$lastcron = $db->get ("lastcron", SQLCHAR);
p ("Last Cron Run: $lastcron");
// Jailed
$db->exec ("
select * from robots.jail order by firstseen;
");
$db->calcfields ["c_host"] = new CalcFieldHost ();
$db->calcfields ["c_isdialup"] = new CalcFieldRBL ("dul.dnsbl.sorbs.net");
$db->calcfields ["c_spam"] = new CalcFieldRBL ("spam.dnsbl.sorbs.net");
$db->calcfields ["c_spews"] = new CalcFieldRBL ("l2.spews.dnsbl.sorbs.net");
$table = new RobotJailTable ();
$table->PrintTable ($db, "Currently Jailed Robots");
flush ();
// Recent
$db->exec ("
select date, ip, hits, restricted from robots.hit_totals
union
select current_date, ip, count (ip), sum (restricted) from robots.hits
group by ip having count (ip) > 1000
order by date desc, ip;
");
$db->calcfields ["c_host"] = new CalcFieldHost ();
$db->calcfields ["c_isdialup"] = new CalcFieldRBL ("dul.dnsbl.sorbs.net");
$db->calcfields ["c_spam"] = new CalcFieldRBL ("spam.dnsbl.sorbs.net");
$db->calcfields ["c_spews"] = new CalcFieldRBL ("l2.spews.dnsbl.sorbs.net");
$table = new RobotHitTable ();
$table->PrintTable ($db, "Recently Active Robots");
flush ();
*/
pagefooter ();
?>

106
catalog/admin/lang.php Normal file
View File

@ -0,0 +1,106 @@
<?php
set_include_path(get_include_path() . PATH_SEPARATOR . "/public/vhost/g/gutenberg/dev/private/lib/php");
include_once ("pgcat.phh");
authenticate ();
getstr ("mode");
$caption = ucfirst ($mode) . " Language";
pageheader ($caption);
include_once ("sqlform.phh");
class ListBooksTable extends MoreTable {
function __construct () {
$this->AddColumn ("<a href=\"book?mode=edit&fk_books=#pk#\">#pk#</a>",
"Etext&nbsp;Nr.", "right", "1*");
$this->AddSimpleColumn ("author", "Author");
$this->AddSimpleColumn ("title", "Title");
$this->limit = 25;
$this->relay = array ("fk_langs", "mode", "filter");
}
}
$db = $config->db ();
$db->logger = new logger ();
$f = new SQLForm ();
getstr ("fk_langs");
getstr ("filter");
if (ismode ("delete")) {
$db->Exec ("select count (*) as cnt from mn_books_langs " .
"where fk_langs = '$fk_langs'");
$cnt = $db->get ("cnt");
if ($cnt > 0) {
$f->SubCaption ("Warning: There are $cnt books related to this language. ");
}
$f->SubCaption ("You are about to delete this language.");
$f->SubCaption ("Press the '$caption' button to continue or " .
"hit the back button on your browser to dismiss.");
} else {
$f->Text ("fk_langs", "pk", "Id", SQLCHAR, 10, 10, true);
$f->Text ("lang", "lang", "Language", SQLCHAR, 80, 240, true);
$f->LoadData ("select * from langs where pk = '$fk_langs'");
}
$f->Hidden ("fk_langs");
$f->Hidden ("filter");
if (isupdatemode ("add")) {
if ($f->Check ()) {
$sql = $f->mkInsert ($db->GetFormatter ());
if ($db->Exec ("insert into langs " . $sql)) {
msg ("Language added !");
} else {
error_msg ("Could not add language!");
}
}
}
if (isupdatemode ("edit")) {
if ($f->Check ()) {
$sql = $f->mkUpdate ($db->GetFormatter ());
if ($db->Exec ("update langs set " . $sql . "where pk = '$fk_langs'")) {
msg ("Language modified !");
} else {
error_msg ("Could not modify language !");
}
}
}
if (isupdatemode ("delete")) {
$db->Exec ("delete from mn_books_langs where fk_langs = '$fk_langs'");
if ($db->Exec ("delete from langs where pk = '$fk_langs'")) {
msg ("Language deleted !");
} else {
error_msg ("Could not delete language !");
}
}
if (isupdate ()) {
if (!isupdatemode ("delete")) {
echo (" <p><a href=\"lang?mode=edit&filter=$filter&fk_langs=$fk_langs\">" .
"Back to Lang</a></p>\n\n");
}
} else {
$f->Output ($caption, $caption);
if (ismode ("edit")) {
$table = new ListBooksTable ();
$db->exec ("select books.pk as pk, title, author " .
"from books, mn_books_langs, titles, mn_books_authors, authors " .
"where books.pk = mn_books_langs.fk_books " .
"and books.pk = mn_books_authors.fk_books " .
"and authors.pk = mn_books_authors.fk_authors " .
"and books.pk = titles.fk_books " .
"and mn_books_langs.fk_langs = '$fk_langs' order by author, title " .
$table->MkOffset ());
$table->PrintTable ($db, "Books for Language");
}
}
echo (" <p><a href=\"langs_list?filter=$filter\">" .
"Back to Language List</a></p>\n\n");
pagefooter ();
?>

105
catalog/admin/lang.php~ Normal file
View File

@ -0,0 +1,105 @@
<?php
include_once ("pgcat.phh");
authenticate ();
getstr ("mode");
$caption = ucfirst ($mode) . " Language";
pageheader ($caption);
include_once ("sqlform.phh");
class ListBooksTable extends MoreTable {
function __construct () {
$this->AddColumn ("<a href=\"book?mode=edit&fk_books=#pk#\">#pk#</a>",
"Etext&nbsp;Nr.", "right", "1*");
$this->AddSimpleColumn ("author", "Author");
$this->AddSimpleColumn ("title", "Title");
$this->limit = 25;
$this->relay = array ("fk_langs", "mode", "filter");
}
}
$db = $config->db ();
$db->logger = new logger ();
$f = new SQLForm ();
getstr ("fk_langs");
getstr ("filter");
if (ismode ("delete")) {
$db->Exec ("select count (*) as cnt from mn_books_langs " .
"where fk_langs = '$fk_langs'");
$cnt = $db->get ("cnt");
if ($cnt > 0) {
$f->SubCaption ("Warning: There are $cnt books related to this language. ");
}
$f->SubCaption ("You are about to delete this language.");
$f->SubCaption ("Press the '$caption' button to continue or " .
"hit the back button on your browser to dismiss.");
} else {
$f->Text ("fk_langs", "pk", "Id", SQLCHAR, 10, 10, true);
$f->Text ("lang", "lang", "Language", SQLCHAR, 80, 240, true);
$f->LoadData ("select * from langs where pk = '$fk_langs'");
}
$f->Hidden ("fk_langs");
$f->Hidden ("filter");
if (isupdatemode ("add")) {
if ($f->Check ()) {
$sql = $f->mkInsert ($db->GetFormatter ());
if ($db->Exec ("insert into langs " . $sql)) {
msg ("Language added !");
} else {
error_msg ("Could not add language!");
}
}
}
if (isupdatemode ("edit")) {
if ($f->Check ()) {
$sql = $f->mkUpdate ($db->GetFormatter ());
if ($db->Exec ("update langs set " . $sql . "where pk = '$fk_langs'")) {
msg ("Language modified !");
} else {
error_msg ("Could not modify language !");
}
}
}
if (isupdatemode ("delete")) {
$db->Exec ("delete from mn_books_langs where fk_langs = '$fk_langs'");
if ($db->Exec ("delete from langs where pk = '$fk_langs'")) {
msg ("Language deleted !");
} else {
error_msg ("Could not delete language !");
}
}
if (isupdate ()) {
if (!isupdatemode ("delete")) {
echo (" <p><a href=\"lang?mode=edit&filter=$filter&fk_langs=$fk_langs\">" .
"Back to Lang</a></p>\n\n");
}
} else {
$f->Output ($caption, $caption);
if (ismode ("edit")) {
$table = new ListBooksTable ();
$db->exec ("select books.pk as pk, title, author " .
"from books, mn_books_langs, titles, mn_books_authors, authors " .
"where books.pk = mn_books_langs.fk_books " .
"and books.pk = mn_books_authors.fk_books " .
"and authors.pk = mn_books_authors.fk_authors " .
"and books.pk = titles.fk_books " .
"and mn_books_langs.fk_langs = '$fk_langs' order by author, title " .
$table->MkOffset ());
$table->PrintTable ($db, "Books for Language");
}
}
echo (" <p><a href=\"langs_list?filter=$filter\">" .
"Back to Language List</a></p>\n\n");
pagefooter ();
?>

View File

@ -0,0 +1,48 @@
<?php
set_include_path(get_include_path() . PATH_SEPARATOR . "/public/vhost/g/gutenberg/dev/private/lib/php");
include_once ("pgcat.phh");
authenticate ();
getstr ("filter");
pageheader ($caption = "Languages $filter");
class ListLangsTable extends ListTable {
function __construct () {
global $filter;
$prefix = "<a href=\"lang?filter=$filter&mode";
$this->AddColumn ("$prefix=edit&fk_langs=#pk#\">Edit</a>",
"$prefix=add\">Add</a>", "left", "1%");
$this->AddColumn ("$prefix=delete&fk_langs=#pk#\">Delete</a>",
"", "left", "1%");
$this->AddSimpleColumn ("pk", "Id", "left", "1%");
$this->AddSimpleColumn ("lang", "Language");
$this->AddSimpleColumn ("cnt", "# of books");
}
}
$db = $config->db ();
echo ("
<p>Please enter the first few characters of the language (at least one).
Search is case-sensitive.
Use * as wildcard. (eg. *ish)
To see everything just enter *.</p>
");
form_open ();
echo (" <input type=\"text\" name=\"filter\" value=\"$filter\"/>\n");
form_submit ("Search");
form_close ();
if ($filter != "") {
$filt = preg_replace ('/\*/', '%', $filter);
$db->exec ("select pk, lang, (select count(fk_books) from mn_books_langs where fk_langs=pk) as cnt from langs where lang like '$filt%' order by cnt, lang;");
$table = new ListLangsTable ();
$table->PrintTable ($db, $caption);
}
pagefooter ();
?>

View File

@ -0,0 +1,47 @@
<?php
include_once ("pgcat.phh");
authenticate ();
getstr ("filter");
pageheader ($caption = "Languages $filter");
class ListLangsTable extends ListTable {
function __construct () {
global $filter;
$prefix = "<a href=\"lang?filter=$filter&mode";
$this->AddColumn ("$prefix=edit&fk_langs=#pk#\">Edit</a>",
"$prefix=add\">Add</a>", "left", "1%");
$this->AddColumn ("$prefix=delete&fk_langs=#pk#\">Delete</a>",
"", "left", "1%");
$this->AddSimpleColumn ("pk", "Id", "left", "1%");
$this->AddSimpleColumn ("lang", "Language");
$this->AddSimpleColumn ("cnt", "# of books");
}
}
$db = $config->db ();
echo ("
<p>Please enter the first few characters of the language (at least one).
Search is case-sensitive.
Use * as wildcard. (eg. *ish)
To see everything just enter *.</p>
");
form_open ();
echo (" <input type=\"text\" name=\"filter\" value=\"$filter\"/>\n");
form_submit ("Search");
form_close ();
if ($filter != "") {
$filt = preg_replace ('/\*/', '%', $filter);
$db->exec ("select pk, lang, (select count(fk_books) from mn_books_langs where fk_langs=pk) as cnt from langs where lang like '$filt%' order by cnt, lang;");
$table = new ListLangsTable ();
$table->PrintTable ($db, $caption);
}
pagefooter ();
?>

105
catalog/admin/locc.php Normal file
View File

@ -0,0 +1,105 @@
<?php
set_include_path(get_include_path() . PATH_SEPARATOR . "/public/vhost/g/gutenberg/dev/private/lib/php");
include_once ("pgcat.phh");
authenticate ();
getstr ("mode");
$caption = ucfirst ($mode) . " LoC Class";
pageheader ($caption);
include_once ("sqlform.phh");
class ListBooksTable extends MoreTable {
function __construct () {
$this->AddColumn ("<a href=\"book?mode=edit&fk_books=#pk#\">#pk#</a>",
"Etext&nbsp;Nr.", "right", "1*");
$this->AddSimpleColumn ("title", "Title");
$this->limit = 25;
$this->relay = array ("fk_loccs", "mode", "filter");
}
}
$db = $config->db ();
$db->logger = new logger ();
$f = new SQLForm ();
getstr ("fk_loccs");
getstr ("filter");
if (ismode ("delete")) {
$db->Exec ("select count (*) as cnt from mn_books_loccs " .
"where fk_loccs = '$fk_loccs'");
$cnt = $db->get ("cnt");
if ($cnt > 0) {
$f->SubCaption ("Warning: There are $cnt books related to this LoC class. ");
}
$f->SubCaption ("You are about to delete this LoC class.");
$f->SubCaption ("Press the '$caption' button to continue or " .
"hit the back button on your browser to dismiss.");
} else {
$f->Text ("fk_loccs", "pk", "Id", SQLCHAR, 10, 10, true);
$f->Text ("locc", "locc", "LoC Class", SQLCHAR, 80, 240, true);
$f->LoadData ("select * from loccs where pk = '$fk_loccs'");
}
$f->Hidden ("fk_loccs");
$f->Hidden ("filter");
if (isupdatemode ("add")) {
if ($f->Check ()) {
$sql = $f->mkInsert ($db->GetFormatter ());
if ($db->Exec ("insert into loccs " . $sql)) {
msg ("LoC class added !");
} else {
error_msg ("Could not add LoC class!");
}
}
}
if (isupdatemode ("edit")) {
if ($f->Check ()) {
$sql = $f->mkUpdate ($db->GetFormatter ());
if ($db->Exec ("update loccs set " . $sql . "where pk = '$fk_loccs'")) {
msg ("LoC class modified !");
} else {
error_msg ("Could not modify LoC class !");
}
}
}
if (isupdatemode ("delete")) {
$db->Exec ("delete from mn_books_loccs where fk_loccs = '$fk_loccs'");
if ($db->Exec ("delete from loccs where pk = '$fk_loccs'")) {
msg ("LoC class deleted !");
} else {
error_msg ("Could not delete LoC class !");
}
}
if (isupdate ()) {
if (!isupdatemode ("delete")) {
echo (" <p><a href=\"locc?mode=edit&filter=$filter&fk_loccs=$fk_loccs\">" .
"Back to Locc</a></p>\n\n");
}
} else {
$f->Output ($caption, $caption);
if (ismode ("edit")) {
$table = new ListBooksTable ();
$db->exec ("select books.pk as pk, title, author " .
"from books, mn_books_loccs, titles, mn_books_authors, authors " .
"where books.pk = mn_books_loccs.fk_books " .
"and books.pk = mn_books_authors.fk_books " .
"and authors.pk = mn_books_authors.fk_authors " .
"and books.pk = titles.fk_books " .
"and mn_books_loccs.fk_loccs = '$fk_loccs' order by author, title " .
$table->MkOffset ());
$table->PrintTable ($db, "Books for LoC Class");
}
}
echo (" <p><a href=\"loccs_list?filter=$filter\">" .
"Back to LoC Class List</a></p>\n\n");
pagefooter ();
?>

104
catalog/admin/locc.php~ Normal file
View File

@ -0,0 +1,104 @@
<?php
include_once ("pgcat.phh");
authenticate ();
getstr ("mode");
$caption = ucfirst ($mode) . " LoC Class";
pageheader ($caption);
include_once ("sqlform.phh");
class ListBooksTable extends MoreTable {
function __construct () {
$this->AddColumn ("<a href=\"book?mode=edit&fk_books=#pk#\">#pk#</a>",
"Etext&nbsp;Nr.", "right", "1*");
$this->AddSimpleColumn ("title", "Title");
$this->limit = 25;
$this->relay = array ("fk_loccs", "mode", "filter");
}
}
$db = $config->db ();
$db->logger = new logger ();
$f = new SQLForm ();
getstr ("fk_loccs");
getstr ("filter");
if (ismode ("delete")) {
$db->Exec ("select count (*) as cnt from mn_books_loccs " .
"where fk_loccs = '$fk_loccs'");
$cnt = $db->get ("cnt");
if ($cnt > 0) {
$f->SubCaption ("Warning: There are $cnt books related to this LoC class. ");
}
$f->SubCaption ("You are about to delete this LoC class.");
$f->SubCaption ("Press the '$caption' button to continue or " .
"hit the back button on your browser to dismiss.");
} else {
$f->Text ("fk_loccs", "pk", "Id", SQLCHAR, 10, 10, true);
$f->Text ("locc", "locc", "LoC Class", SQLCHAR, 80, 240, true);
$f->LoadData ("select * from loccs where pk = '$fk_loccs'");
}
$f->Hidden ("fk_loccs");
$f->Hidden ("filter");
if (isupdatemode ("add")) {
if ($f->Check ()) {
$sql = $f->mkInsert ($db->GetFormatter ());
if ($db->Exec ("insert into loccs " . $sql)) {
msg ("LoC class added !");
} else {
error_msg ("Could not add LoC class!");
}
}
}
if (isupdatemode ("edit")) {
if ($f->Check ()) {
$sql = $f->mkUpdate ($db->GetFormatter ());
if ($db->Exec ("update loccs set " . $sql . "where pk = '$fk_loccs'")) {
msg ("LoC class modified !");
} else {
error_msg ("Could not modify LoC class !");
}
}
}
if (isupdatemode ("delete")) {
$db->Exec ("delete from mn_books_loccs where fk_loccs = '$fk_loccs'");
if ($db->Exec ("delete from loccs where pk = '$fk_loccs'")) {
msg ("LoC class deleted !");
} else {
error_msg ("Could not delete LoC class !");
}
}
if (isupdate ()) {
if (!isupdatemode ("delete")) {
echo (" <p><a href=\"locc?mode=edit&filter=$filter&fk_loccs=$fk_loccs\">" .
"Back to Locc</a></p>\n\n");
}
} else {
$f->Output ($caption, $caption);
if (ismode ("edit")) {
$table = new ListBooksTable ();
$db->exec ("select books.pk as pk, title, author " .
"from books, mn_books_loccs, titles, mn_books_authors, authors " .
"where books.pk = mn_books_loccs.fk_books " .
"and books.pk = mn_books_authors.fk_books " .
"and authors.pk = mn_books_authors.fk_authors " .
"and books.pk = titles.fk_books " .
"and mn_books_loccs.fk_loccs = '$fk_loccs' order by author, title " .
$table->MkOffset ());
$table->PrintTable ($db, "Books for LoC Class");
}
}
echo (" <p><a href=\"loccs_list?filter=$filter\">" .
"Back to LoC Class List</a></p>\n\n");
pagefooter ();
?>

View File

@ -0,0 +1,47 @@
<?php
set_include_path(get_include_path() . PATH_SEPARATOR . "/public/vhost/g/gutenberg/dev/private/lib/php");
include_once ("pgcat.phh");
authenticate ();
getstr ("filter");
pageheader ($caption = "LoC classes $filter");
class ListLoccsTable extends ListTable {
function __construct () {
global $filter;
$prefix = "<a href=\"locc?filter=$filter&mode";
$this->AddColumn ("$prefix=edit&fk_loccs=#pk#\">Edit</a>",
"$prefix=add\">Add</a>", "left", "1%");
$this->AddColumn ("$prefix=delete&fk_loccs=#pk#\">Delete</a>",
"", "left", "1%");
$this->AddSimpleColumn ("pk", "Id", "left", "1%");
$this->AddSimpleColumn ("locc", "LoC Class");
}
}
$db = $config->db ();
echo ("
<p>Please enter the first few characters of the LoC Class (at least one).
Search is case-sensitive.
Use * as wildcard. (eg. *United*)
To see everything just enter *.</p>
");
form_open ();
echo (" <input type=\"text\" name=\"filter\" value=\"$filter\"/>\n");
form_submit ("Search");
form_close ();
if ($filter != "") {
$filt = preg_replace ('/\*/', '%', $filter);
$db->exec ("select * from loccs where locc like '$filt%' order by locc;");
$table = new ListLoccsTable ();
$table->PrintTable ($db, $caption);
}
pagefooter ();
?>

View File

@ -0,0 +1,46 @@
<?php
include_once ("pgcat.phh");
authenticate ();
getstr ("filter");
pageheader ($caption = "LoC classes $filter");
class ListLoccsTable extends ListTable {
function __construct () {
global $filter;
$prefix = "<a href=\"locc?filter=$filter&mode";
$this->AddColumn ("$prefix=edit&fk_loccs=#pk#\">Edit</a>",
"$prefix=add\">Add</a>", "left", "1%");
$this->AddColumn ("$prefix=delete&fk_loccs=#pk#\">Delete</a>",
"", "left", "1%");
$this->AddSimpleColumn ("pk", "Id", "left", "1%");
$this->AddSimpleColumn ("locc", "LoC Class");
}
}
$db = $config->db ();
echo ("
<p>Please enter the first few characters of the LoC Class (at least one).
Search is case-sensitive.
Use * as wildcard. (eg. *United*)
To see everything just enter *.</p>
");
form_open ();
echo (" <input type=\"text\" name=\"filter\" value=\"$filter\"/>\n");
form_submit ("Search");
form_close ();
if ($filter != "") {
$filt = preg_replace ('/\*/', '%', $filter);
$db->exec ("select * from loccs where locc like '$filt%' order by locc;");
$table = new ListLoccsTable ();
$table->PrintTable ($db, $caption);
}
pagefooter ();
?>

17
catalog/admin/ls.php Normal file
View File

@ -0,0 +1,17 @@
<?php
ob_start("ob_gzhandler");
set_include_path(get_include_path() . PATH_SEPARATOR . "/public/vhost/g/gutenberg/dev/private/lib/php");
include ("pgcat.phh");
authenticate ();
getstr ("file");
header ("Content-Type: text/plain");
echo ("File: $file\n\n");
system ("ls -al $file");
?>

16
catalog/admin/ls.php~ Normal file
View File

@ -0,0 +1,16 @@
<?php
ob_start("ob_gzhandler");
include ("pgcat.phh");
authenticate ();
getstr ("file");
header ("Content-Type: text/plain");
echo ("File: $file\n\n");
system ("ls -al $file");
?>

View File

@ -0,0 +1,618 @@
<?php
// todo:
// subject pages
$cli = php_sapi_name () == "cli";
if (!$cli) exit ();
set_include_path(get_include_path() . PATH_SEPARATOR . "/public/vhost/g/gutenberg/dev/private/lib/php");
include_once ("pgcat.phh");
$lang_thres = 50;
setlocale (LC_ALL, 'en_US.utf8');
$config->page_encoding = "UTF-8";
function _navbar ($what, $dir) {
global $config;
$nav = " <p>$what:\n";
foreach ($config->browse_pages as $caption => $regexp) {
$href = strtolower ($caption);
$nav .= " <a href=\"/$dir/$href\">$caption</a>&nbsp;\n";
}
$nav .= " </p>\n";
return $nav;
}
function _navbarrecent ($what, $dir) {
global $spans;
$nav .= " <p>$what:\n";
foreach ($spans as $href => $caption) {
$nav .= " <a href=\"/$dir/last$href\">$caption</a>&nbsp;\n";
}
$nav .= " </p>\n";
return $nav;
}
function _navbarlangs ($what, $where, $dir) {
global $db;
$nav = " <p>$what:\n";
$db->Exec ("select pk, lang, cnt from langs join (select fk_langs, count (fk_langs) as cnt from mn_books_langs group by fk_langs having count (fk_langs) $where) as sums on pk = fk_langs order by lang;");
if ($db->FirstRow ()) {
do {
$pk = strtolower ($db->Get ("pk", SQLCHAR));
$lang = $db->Get ("lang", SQLCHAR);
$cnt = $db->Get ("cnt", SQLINT);
$nav .= " <a href=\"/$dir/$pk\" title=\"$lang ($cnt)\">$lang</a>&nbsp;\n";
} while ($db->NextRow ());
}
$nav .= " </p>\n";
return $nav;
}
function _navbarloccs ($what, $dir) {
global $db;
$nav = " <p>$what:\n";
$db->Exec ("select pk, locc, cnt from loccs join (select fk_loccs, count (fk_loccs) as cnt from mn_books_loccs group by fk_loccs) as sums on pk = fk_loccs order by fk_loccs;");
if ($db->FirstRow ()) {
do {
$pk = strtolower ($db->Get ("pk", SQLCHAR));
$pku = strtoupper ($pk);
$locc = $db->Get ("locc", SQLCHAR);
$cnt = $db->Get ("cnt", SQLINT);
$nav .= " <a href=\"/$dir/$pk\" title=\"$locc ($cnt)\">$pku</a>&nbsp;\n";
} while ($db->NextRow ());
}
$nav .= " </p>\n";
return $nav;
}
function _navbarcategories ($what, $dir) {
global $db;
$nav = " <p>$what:\n";
$db->Exec ("select pk, category, cnt from categories join (select fk_categories, count (fk_categories) as cnt from mn_books_categories group by fk_categories) as sums on pk = fk_categories order by category;");
if ($db->FirstRow ()) {
do {
$pk = $db->Get ("pk", SQLINT);
$category = $db->Get ("category", SQLCHAR);
$cnt = $db->Get ("cnt", SQLINT);
$nav .= " <a href=\"/$dir/$pk\" title=\"$category ($cnt)\">$category</a>&nbsp;\n";
} while ($db->NextRow ());
}
$nav .= " </p>\n";
return $nav;
}
function navbar () {
global $dir_authors, $dir_titles, $dir_langs, $dir_loccs, $dir_categories, $dir_recent, $lang_thres;
$nav = "<div class=\"pgdbnavbar\">\n";
$nav .= _navbar ("Authors", $dir_authors);
$nav .= _navbar ("Titles", $dir_titles);
$nav .= _navbarlangs ("Languages with more than $lang_thres books", "> $lang_thres", $dir_langs);
$nav .= _navbarlangs ("Languages with up to $lang_thres books", "<= $lang_thres", $dir_langs);
// $nav .= _navbarloccs ("LoC Class", $dir_loccs);
$nav .= _navbarcategories ("Special Categories", $dir_categories);
$nav .= _navbarrecent ("Recent", $dir_recent);
$nav .= "</div>\n\n";
return $nav;
}
function pagefooterfile ($file) {
global $page;
$page->footer ();
$output = ob_get_contents ();
ob_clean ();
$hd = fopen ($file, "w");
if ($hd) {
fwrite ($hd, $output);
fclose ($hd);
}
$hd = gzopen ("$file.gzip", "w9");
if ($hd) {
gzwrite ($hd, $output);
gzclose ($hd);
}
}
function LoadTitles () {
global $db, $authors;
foreach ($authors as $fk_authors => $dummy) {
$authors[$fk_authors]['titles'] = array ();
// echo ("$fk_authors\n");
}
if ($db->FirstRow ()) {
do {
$o = array ();
$fk_authors = $db->get ("fk_authors", SQLINT);
if (empty ($fk_authors))
$fk_authors = 0;
// echo ("fk_authors: $fk_authors\n");
$o['title'] = str_replace ("\n", "<br$config->endtag>",
strip_marc_subfields (htmlspecialchars ($db->get ("title", SQLCHAR))));
$o['lang'] = $db->get ("lang", SQLCHAR);
$o['etext'] = $db->get ("fk_books", SQLINT);
$o['is_audio'] = $db->get ("is_audio", SQLBOOL);
$o['role'] = $db->get ("role", SQLCHAR);
array_push ($authors[$fk_authors]['titles'], $o);
} while ($db->NextRow ());
}
}
function pklist ($aa) {
// make a list of all authors with titles
$pklist = array ();
foreach ($aa as $fk_authors => $o) {
if (count ($o['titles'])) {
$pklist[] = $fk_authors;
}
}
return $pklist;
}
function FormatAliases ($pklist, $mode = 0, $regex = "") {
global $db, $lines, $authors;
if (count ($pklist) == 0)
return;
$list = join (",", $pklist);
$db->exec ("select fk_authors, alias from aliases " .
"where aliases.alias_heading = 1 and fk_authors in ($list)");
if ($db->FirstRow ()) {
do {
$fk_authors = $db->get ("fk_authors", SQLINT);
$alias = $db->get ("alias", SQLCHAR);
$author = $authors[$fk_authors]['author'];
if ($mode == 1) {
if (!preg_match ("/$regex/i", $alias))
continue;
// the by-author pages need a different url
$href = find_browse_page ($author) . "#a$fk_authors";
} else {
$href = "#a$fk_authors";
}
$html_alias = htmlspecialchars ($alias);
$html_author = htmlspecialchars ($author);
$lines[$alias] = "<h2>$html_alias</h2>\n<p>See: <a href=\"$href\">$html_author</a></p>\n\n";
// echo ("$alias\n");
} while ($db->NextRow ());
}
}
function FormatAuthors ($mode = 0) {
global $db, $lines, $dir_etext, $authors;
foreach ($authors as $fk_authors => $o) {
if (count ($o['titles'])) {
$html_author = htmlspecialchars ($o['author']);
if ($mode == 1 || $fk_authors == 0) {
$line = "<h2><a name=\"a$fk_authors\">$html_author</a> <a href=\"#a$fk_authors\" title=\"Link to this author\">¶</a></h2>\n";
} else {
$href = "/browse/authors/" . find_browse_page ($o['author']) . "#a$fk_authors";
$line = "<h2><a name=\"a$fk_authors\"></a><a href=\"$href\">$html_author</a></h2>\n";
}
$line .= "<ul>\n";
if ($mode == 1) {
// by-author page
if (isset ($o['aliases'])) {
foreach ($o['aliases'] as $alias) {
$line .= " <li class=\"pgdbalias\">$alias</li>\n";
}
}
if (isset ($o['urls'])) {
foreach ($o['urls'] as $description => $url) {
$line .= " <li class=\"pgdbxlink\"><a href=\"$url\">$description</a></li>\n";
}
}
}
// output list of titles
foreach ($o['titles'] as $t) {
$role = (empty ($t['role']) || $t['role'] == "Creator") ? "" : " (as {$t['role']})";
$cls = $t['is_audio'] ? " class=\"pgdbaudio\"" : " class=\"pgdbetext\"";
$line .= " <li$cls><a href=\"/$dir_etext/{$t['etext']}\">{$t['title']}</a> ({$t['lang']})$role</li>\n";
}
$line .= "</ul>\n\n";
$lines[$o['author']] = $line;
// echo ("{$o['author']}\n");
}
}
}
$dir = "browse";
$dir_authors = "$dir/authors";
$dir_titles = "$dir/titles";
$dir_langs = "$dir/languages";
$dir_loccs = "$dir/loccs";
$dir_subjects = "$dir/subjects";
$dir_categories = "$dir/categories";
$dir_recent = "$dir/recent";
$dir_feeds = "cache/epub/feeds";
$dir_etext = "ebooks";
$base_url = "http://$config->domain";
@mkdir ("$config->documentroot/$dir", 0755);
@mkdir ("$config->documentroot/$dir_authors", 0755);
@mkdir ("$config->documentroot/$dir_titles", 0755);
@mkdir ("$config->documentroot/$dir_langs", 0755);
@mkdir ("$config->documentroot/$dir_loccs", 0755);
@mkdir ("$config->documentroot/$dir_subjects", 0755);
@mkdir ("$config->documentroot/$dir_categories", 0755);
@mkdir ("$config->documentroot/$dir_recent", 0755);
@mkdir ("$config->documentroot/$dir_feeds", 0755);
$spans[1] = 'last 24 hours';
$spans[7] = 'last 7 days';
$spans[30] = 'last 30 days';
$db = $config->db ();
$db2 = $config->db ();
$authors = array ();
////////////////////////////////////////////////////////////////////////
// load authors
$authors[0]['author'] = "No Author Listed";
$db->exec ("select * from authors");
if ($db->FirstRow ()) {
do {
$fk_authors = $db->get ("pk", SQLINT);
$authors[$fk_authors]['author'] = FormatAuthorDate ($db);
} while ($db->NextRow ());
}
$db->exec ("select * from aliases where alias_heading = 1 order by alias");
if ($db->FirstRow ()) {
do {
$fk_authors = $db->get ("fk_authors", SQLINT);
$alias = htmlspecialchars ($db->get ("alias", SQLCHAR));
$authors[$fk_authors]['aliases'][] = $alias;
} while ($db->NextRow ());
}
$db->exec ("select * from author_urls order by description");
if ($db->FirstRow ()) {
do {
$fk_authors = $db->get ("fk_authors", SQLINT);
$description = htmlspecialchars ($db->get ("description", SQLCHAR));
$url = htmlspecialchars ($db->get ("url", SQLCHAR));
$authors[$fk_authors]['urls'][$description] = $url;
} while ($db->NextRow ());
}
// echo ("$config->documentroot/$dir/navbar.html\n");
if ($hd = fopen ("$config->documentroot/$dir/navbar.html", "w")) {
fputs ($hd, navbar ());
fclose ($hd);
}
////////////////////////////////////////////////////////////////////////////////
$db->exec ("create temporary table tmp_books as select * from v_books");
////////////////////////////////////////////////////////////////////////////////
// by-author
// Postgres 7.3.3 at ibiblio doesn't dig multicolumn functional indexes
$db->exec ("create index tmp_ix_books_authors on tmp_books (lower (author))");
foreach ($config->browse_pages as $caption => $regexp) {
// titles for each author
$db->exec ("select * from tmp_books where author ~* '^$regexp' " .
"order by author, filing, lang");
LoadTitles ();
$lines = array ();
FormatAuthors (1);
$pklist = array ();
$db->exec ("select fk_authors from aliases where alias ~* '^$regexp'");
if ($db->FirstRow ()) {
do {
$pklist[] = $db->get ("fk_authors", SQLINT);
} while ($db->NextRow ());
}
FormatAliases ($pklist, 1, "^$regexp");
uksort ($lines, 'strcoll');
$fn = strtolower ($caption);
pageheader ("Browse By Author: $caption");
echo (navbar ());
echo ("<div class=\"pgdbbyauthor\">\n\n");
foreach ($lines as $line) {
echo ($line);
}
echo ("</div>\n\n");
pagefooterfile ("$config->documentroot/$dir_authors/$fn.html.utf8");
}
////////////////////////////////////////////////////////////////////////////////
// by-lang
$db->exec ("create index tmp_ix_books_langs on tmp_books (lang)");
$db->exec ("select pk, lang from langs where pk in (select fk_langs from mn_books_langs)");
if ($db->FirstRow ()) {
do {
$langs[$db->get ("lang", SQLCHAR)] = $db->get ("pk", SQLCHAR);
} while ($db->NextRow ());
}
foreach ($langs as $lang => $id) {
$caption = $lang;
$fn = $id;
if ($id == 'en') {
pageheader ("Browse By Language: $caption");
echo (navbar ());
echo ("<p>There are too many english books to list them in one page. " .
"Please use the Browse-By-Author pages instead.</p>\n\n");
pagefooterfile ("$config->documentroot/$dir_langs/$fn.html.utf8");
continue;
}
$db->exec ("select * from tmp_books where fk_books in
(select fk_books from mn_books_langs where fk_langs = '$id'
and tmp_books.fk_books = mn_books_langs.fk_books)
order by lang, author, filing");
LoadTitles ();
$lines = array ();
FormatAuthors ();
FormatAliases (pklist ($authors));
uksort ($lines, 'strcoll');
pageheader ("Browse By Language: $caption");
echo (navbar ());
echo ("<div class=\"pgdbbylanguage\">\n\n");
foreach ($lines as $line) {
echo ($line);
}
echo ("</div>\n\n");
pagefooterfile ("$config->documentroot/$dir_langs/$fn.html.utf8");
}
////////////////////////////////////////////////////////////////////////////////
// by-locc
$db->exec ("select pk, locc from loccs where pk in (select fk_loccs from mn_books_loccs)");
if ($db->FirstRow ()) {
do {
$loccs[$db->get ("locc", SQLCHAR)] = $db->get ("pk", SQLCHAR);
} while ($db->NextRow ());
}
foreach ($loccs as $locc => $fk_loccs) {
$caption = $locc;
$fn = strtolower ($fk_loccs);
// titles for each author
// $db->exec ("select * from tmp_books where fk_loccs = '$fk_loccs' " .
// "order by fk_loccs, author, filing");
$db->exec ("select * from tmp_books where fk_books in
(select fk_books from mn_books_loccs where fk_loccs = '$fk_loccs'
and tmp_books.fk_books = mn_books_loccs.fk_books)
order by author, filing");
LoadTitles ();
$lines = array ();
FormatAuthors ();
FormatAliases (pklist ($authors));
uksort ($lines, 'strcoll');
pageheader ("Browse By Library of Congress Class: $caption");
echo (navbar ());
echo ("<div class=\"pgdbbylocc\">\n\n");
foreach ($lines as $line) {
echo ($line);
}
echo ("</div>\n\n");
pagefooterfile ("$config->documentroot/$dir_loccs/$fn.html.utf8");
}
////////////////////////////////////////////////////////////////////////////////
// by-category
$db->exec ("select pk, category from categories");
if ($db->FirstRow ()) {
do {
$categories[$db->get ("category", SQLCHAR)] = $db->get ("pk", SQLINT);
} while ($db->NextRow ());
}
foreach ($categories as $category => $id) {
$caption = $category;
$fn = $id;
if ($id == 0) {
pageheader ("Browse By Category: $caption");
echo (navbar ());
echo ("<p>There are too many books in this category too list them in one page. " .
"Please use the Browse-By-Author pages instead.</p>\n\n");
pagefooterfile ("$config->documentroot/$dir_langs/$fn.html.utf8");
continue;
}
$db->exec ("select * from tmp_books where fk_books in
(select fk_books from mn_books_categories where fk_categories = $id
and tmp_books.fk_books = mn_books_categories.fk_books)
order by author, filing");
LoadTitles ();
$lines = array ();
FormatAuthors ();
FormatAliases (pklist ($authors));
uksort ($lines, 'strcoll');
pageheader ("Browse By Category: $caption");
echo (navbar ());
echo ("<div class=\"pgdbbycategory\">\n\n");
foreach ($lines as $line) {
echo ($line);
}
echo ("</div>\n\n");
pagefooterfile ("$config->documentroot/$dir_categories/$fn.html.utf8");
}
////////////////////////////////////////////////////////////////////////////////
// by-title
$db->exec ("create index tmp_ix_books_titles on tmp_books (lower (filing))");
foreach ($config->browse_pages as $caption => $regexp) {
$fn = strtolower ($caption);
pageheader ("Browse By Title: $caption");
echo (navbar ());
echo ("<div class=\"pgdbbytitle\">\n\n");
// titles
$db->exec ("select * from tmp_books where lower (filing) ~ '^$regexp' order by lower (filing), author, lang");
if ($db->FirstRow ()) {
do {
$etext = $db->get ("fk_books", SQLINT);
$fk_authors = $db->get ("fk_authors", SQLINT);
$title = str_replace ("\n", "<br$config->endtag>", $db->get ("title", SQLCHAR));
$author = $db->get ("author", SQLCHAR);
$lang = $db->get ("lang", SQLCHAR);
$is_audio = $db->get ("is_audio", SQLBOOL);
// echo ("$title\n");
$icon = $is_audio ? " <img class=\"pgdbflag\" src=\"/pics/stock_volume-16.png\" alt=\"Audio Book\" title=\"Audio Book\"$config->endtag>" : "";
echo ("<h2><a href=\"/$dir_etext/$etext\">$title</a> ($lang)$icon</h2>\n");
$href = "/$dir_authors/" . find_browse_page ($author) . "#a$fk_authors";
echo ("<p>by <a href=\"$href\">$author</a></p>\n\n");
} while ($db->NextRow ());
}
echo ("</div>\n\n");
pagefooterfile ("$config->documentroot/$dir_titles/$fn.html.utf8");
}
////////////////////////////////////////////////////////////////////////////////
// recent books
$db->exec ("create index tmp_ix_books_fk_books on tmp_books (fk_books)");
$rssbuffer = "";
$books_output = array ();
// clear titles
foreach ($authors as $fk_authors => $dummy) {
$authors[$fk_authors]['titles'] = array ();
}
foreach ($spans as $span => $caption) {
$recents = array ();
$cutoff = date ("Y-m-d", time () - $span * 86400);
$db->exec ("select distinct fk_books from files " .
"where fk_books is not null and diskstatus = 0 and filename !~ '^cache' and filemtime >= '$cutoff 00:00:00'");
if ($db->FirstRow ()) {
do {
$recents[] = $db->get ("fk_books", SQLINT);
} while ($db->NextRow ());
}
$lines = array ();
if (count ($recents)) {
$recent = join (", ", $recents);
// titles for each author
$db->exec ("select * from tmp_books where fk_books in ($recent) order by author, filing, lang");
LoadTitles ();
FormatAuthors ();
FormatAliases (pklist ($authors));
uksort ($lines, 'strcoll');
}
$config->htmlheaderlinks[] = "<link rel=\"alternate\" type=\"application/rss+xml\" title=\"RSS-Feed of Project Gutenberg Recently Posted or Updated EBooks\" href=\"http://www.gutenberg.org/$dir_feeds/today.rss\">";
pageheader ("Books Posted or Updated Since: $cutoff");
echo (navbar ());
echo ("<div class=\"pgdbrecent\">\n\n");
if (!count ($recents)) {
echo ("<p>No books posted.</p>\n\n");
}
foreach ($lines as $line) {
echo ($line);
}
if ($span == 1) {
// build rss
foreach ($authors as $author => $o) {
if (count ($o['titles'])) {
// output list of titles
foreach ($o['titles'] as $t) {
// avoid duplicates in rss
if (!isset ($books_output[$t['etext']])) {
$books_output[$t['etext']] = 1;
$friendlytitle = htmlspecialchars (friendlytitle ($t['etext'], 100));
$rssbuffer .= " <item>\n";
$rssbuffer .= " <title>$friendlytitle</title>\n";
$rssbuffer .= " <link>$base_url/$dir_etext/{$t['etext']}</link>\n";
$rssbuffer .= " <description>Language: {$t['lang']}</description>\n";
$rssbuffer .= " </item>\n\n";
}
}
}
}
}
echo ("</div>\n\n");
pagefooterfile ("$config->documentroot/$dir_recent/last$span.html.utf8");
$config->htmlheaderlinks = array ();
}
// write rss feed
if ($hd = fopen ($file = "$config->documentroot/$dir_feeds/today.rss", "w")) {
$pubdate = date ("r");
fputs ($hd, <<<EOF
<?xml version="1.0" encoding="utf-8" ?>
<rss version="0.91">
<channel>
<title>Project Gutenberg Recently Posted or Updated EBooks</title>
<link>$base_url</link>
<description>
EBooks posted or updated today on Project Gutenberg.
This feed is regenerated every night.
</description>
<language>en-us</language>
<webMaster>webmaster@gutenberg.org (Marcello Perathoner)</webMaster>
<pubDate>$pubdate</pubDate>
<lastBuildDate>$pubdate</lastBuildDate>
EOF
);
fputs ($hd, $rssbuffer);
fputs ($hd, " </channel>\n</rss>\n");
fclose ($hd);
}
?>

View File

@ -0,0 +1,617 @@
<?php
// todo:
// subject pages
$cli = php_sapi_name () == "cli";
if (!$cli) exit ();
include_once ("pgcat.phh");
$lang_thres = 50;
setlocale (LC_ALL, 'en_US.utf8');
$config->page_encoding = "UTF-8";
function _navbar ($what, $dir) {
global $config;
$nav = " <p>$what:\n";
foreach ($config->browse_pages as $caption => $regexp) {
$href = strtolower ($caption);
$nav .= " <a href=\"/$dir/$href\">$caption</a>&nbsp;\n";
}
$nav .= " </p>\n";
return $nav;
}
function _navbarrecent ($what, $dir) {
global $spans;
$nav .= " <p>$what:\n";
foreach ($spans as $href => $caption) {
$nav .= " <a href=\"/$dir/last$href\">$caption</a>&nbsp;\n";
}
$nav .= " </p>\n";
return $nav;
}
function _navbarlangs ($what, $where, $dir) {
global $db;
$nav = " <p>$what:\n";
$db->Exec ("select pk, lang, cnt from langs join (select fk_langs, count (fk_langs) as cnt from mn_books_langs group by fk_langs having count (fk_langs) $where) as sums on pk = fk_langs order by lang;");
if ($db->FirstRow ()) {
do {
$pk = strtolower ($db->Get ("pk", SQLCHAR));
$lang = $db->Get ("lang", SQLCHAR);
$cnt = $db->Get ("cnt", SQLINT);
$nav .= " <a href=\"/$dir/$pk\" title=\"$lang ($cnt)\">$lang</a>&nbsp;\n";
} while ($db->NextRow ());
}
$nav .= " </p>\n";
return $nav;
}
function _navbarloccs ($what, $dir) {
global $db;
$nav = " <p>$what:\n";
$db->Exec ("select pk, locc, cnt from loccs join (select fk_loccs, count (fk_loccs) as cnt from mn_books_loccs group by fk_loccs) as sums on pk = fk_loccs order by fk_loccs;");
if ($db->FirstRow ()) {
do {
$pk = strtolower ($db->Get ("pk", SQLCHAR));
$pku = strtoupper ($pk);
$locc = $db->Get ("locc", SQLCHAR);
$cnt = $db->Get ("cnt", SQLINT);
$nav .= " <a href=\"/$dir/$pk\" title=\"$locc ($cnt)\">$pku</a>&nbsp;\n";
} while ($db->NextRow ());
}
$nav .= " </p>\n";
return $nav;
}
function _navbarcategories ($what, $dir) {
global $db;
$nav = " <p>$what:\n";
$db->Exec ("select pk, category, cnt from categories join (select fk_categories, count (fk_categories) as cnt from mn_books_categories group by fk_categories) as sums on pk = fk_categories order by category;");
if ($db->FirstRow ()) {
do {
$pk = $db->Get ("pk", SQLINT);
$category = $db->Get ("category", SQLCHAR);
$cnt = $db->Get ("cnt", SQLINT);
$nav .= " <a href=\"/$dir/$pk\" title=\"$category ($cnt)\">$category</a>&nbsp;\n";
} while ($db->NextRow ());
}
$nav .= " </p>\n";
return $nav;
}
function navbar () {
global $dir_authors, $dir_titles, $dir_langs, $dir_loccs, $dir_categories, $dir_recent, $lang_thres;
$nav = "<div class=\"pgdbnavbar\">\n";
$nav .= _navbar ("Authors", $dir_authors);
$nav .= _navbar ("Titles", $dir_titles);
$nav .= _navbarlangs ("Languages with more than $lang_thres books", "> $lang_thres", $dir_langs);
$nav .= _navbarlangs ("Languages with up to $lang_thres books", "<= $lang_thres", $dir_langs);
// $nav .= _navbarloccs ("LoC Class", $dir_loccs);
$nav .= _navbarcategories ("Special Categories", $dir_categories);
$nav .= _navbarrecent ("Recent", $dir_recent);
$nav .= "</div>\n\n";
return $nav;
}
function pagefooterfile ($file) {
global $page;
$page->footer ();
$output = ob_get_contents ();
ob_clean ();
$hd = fopen ($file, "w");
if ($hd) {
fwrite ($hd, $output);
fclose ($hd);
}
$hd = gzopen ("$file.gzip", "w9");
if ($hd) {
gzwrite ($hd, $output);
gzclose ($hd);
}
}
function LoadTitles () {
global $db, $authors;
foreach ($authors as $fk_authors => $dummy) {
$authors[$fk_authors]['titles'] = array ();
// echo ("$fk_authors\n");
}
if ($db->FirstRow ()) {
do {
$o = array ();
$fk_authors = $db->get ("fk_authors", SQLINT);
if (empty ($fk_authors))
$fk_authors = 0;
// echo ("fk_authors: $fk_authors\n");
$o['title'] = str_replace ("\n", "<br$config->endtag>",
strip_marc_subfields (htmlspecialchars ($db->get ("title", SQLCHAR))));
$o['lang'] = $db->get ("lang", SQLCHAR);
$o['etext'] = $db->get ("fk_books", SQLINT);
$o['is_audio'] = $db->get ("is_audio", SQLBOOL);
$o['role'] = $db->get ("role", SQLCHAR);
array_push ($authors[$fk_authors]['titles'], $o);
} while ($db->NextRow ());
}
}
function pklist ($aa) {
// make a list of all authors with titles
$pklist = array ();
foreach ($aa as $fk_authors => $o) {
if (count ($o['titles'])) {
$pklist[] = $fk_authors;
}
}
return $pklist;
}
function FormatAliases ($pklist, $mode = 0, $regex = "") {
global $db, $lines, $authors;
if (count ($pklist) == 0)
return;
$list = join (",", $pklist);
$db->exec ("select fk_authors, alias from aliases " .
"where aliases.alias_heading = 1 and fk_authors in ($list)");
if ($db->FirstRow ()) {
do {
$fk_authors = $db->get ("fk_authors", SQLINT);
$alias = $db->get ("alias", SQLCHAR);
$author = $authors[$fk_authors]['author'];
if ($mode == 1) {
if (!preg_match ("/$regex/i", $alias))
continue;
// the by-author pages need a different url
$href = find_browse_page ($author) . "#a$fk_authors";
} else {
$href = "#a$fk_authors";
}
$html_alias = htmlspecialchars ($alias);
$html_author = htmlspecialchars ($author);
$lines[$alias] = "<h2>$html_alias</h2>\n<p>See: <a href=\"$href\">$html_author</a></p>\n\n";
// echo ("$alias\n");
} while ($db->NextRow ());
}
}
function FormatAuthors ($mode = 0) {
global $db, $lines, $dir_etext, $authors;
foreach ($authors as $fk_authors => $o) {
if (count ($o['titles'])) {
$html_author = htmlspecialchars ($o['author']);
if ($mode == 1 || $fk_authors == 0) {
$line = "<h2><a name=\"a$fk_authors\">$html_author</a> <a href=\"#a$fk_authors\" title=\"Link to this author\">¶</a></h2>\n";
} else {
$href = "/browse/authors/" . find_browse_page ($o['author']) . "#a$fk_authors";
$line = "<h2><a name=\"a$fk_authors\"></a><a href=\"$href\">$html_author</a></h2>\n";
}
$line .= "<ul>\n";
if ($mode == 1) {
// by-author page
if (isset ($o['aliases'])) {
foreach ($o['aliases'] as $alias) {
$line .= " <li class=\"pgdbalias\">$alias</li>\n";
}
}
if (isset ($o['urls'])) {
foreach ($o['urls'] as $description => $url) {
$line .= " <li class=\"pgdbxlink\"><a href=\"$url\">$description</a></li>\n";
}
}
}
// output list of titles
foreach ($o['titles'] as $t) {
$role = (empty ($t['role']) || $t['role'] == "Creator") ? "" : " (as {$t['role']})";
$cls = $t['is_audio'] ? " class=\"pgdbaudio\"" : " class=\"pgdbetext\"";
$line .= " <li$cls><a href=\"/$dir_etext/{$t['etext']}\">{$t['title']}</a> ({$t['lang']})$role</li>\n";
}
$line .= "</ul>\n\n";
$lines[$o['author']] = $line;
// echo ("{$o['author']}\n");
}
}
}
$dir = "browse";
$dir_authors = "$dir/authors";
$dir_titles = "$dir/titles";
$dir_langs = "$dir/languages";
$dir_loccs = "$dir/loccs";
$dir_subjects = "$dir/subjects";
$dir_categories = "$dir/categories";
$dir_recent = "$dir/recent";
$dir_feeds = "cache/epub/feeds";
$dir_etext = "ebooks";
$base_url = "http://$config->domain";
@mkdir ("$config->documentroot/$dir", 0755);
@mkdir ("$config->documentroot/$dir_authors", 0755);
@mkdir ("$config->documentroot/$dir_titles", 0755);
@mkdir ("$config->documentroot/$dir_langs", 0755);
@mkdir ("$config->documentroot/$dir_loccs", 0755);
@mkdir ("$config->documentroot/$dir_subjects", 0755);
@mkdir ("$config->documentroot/$dir_categories", 0755);
@mkdir ("$config->documentroot/$dir_recent", 0755);
@mkdir ("$config->documentroot/$dir_feeds", 0755);
$spans[1] = 'last 24 hours';
$spans[7] = 'last 7 days';
$spans[30] = 'last 30 days';
$db = $config->db ();
$db2 = $config->db ();
$authors = array ();
////////////////////////////////////////////////////////////////////////
// load authors
$authors[0]['author'] = "No Author Listed";
$db->exec ("select * from authors");
if ($db->FirstRow ()) {
do {
$fk_authors = $db->get ("pk", SQLINT);
$authors[$fk_authors]['author'] = FormatAuthorDate ($db);
} while ($db->NextRow ());
}
$db->exec ("select * from aliases where alias_heading = 1 order by alias");
if ($db->FirstRow ()) {
do {
$fk_authors = $db->get ("fk_authors", SQLINT);
$alias = htmlspecialchars ($db->get ("alias", SQLCHAR));
$authors[$fk_authors]['aliases'][] = $alias;
} while ($db->NextRow ());
}
$db->exec ("select * from author_urls order by description");
if ($db->FirstRow ()) {
do {
$fk_authors = $db->get ("fk_authors", SQLINT);
$description = htmlspecialchars ($db->get ("description", SQLCHAR));
$url = htmlspecialchars ($db->get ("url", SQLCHAR));
$authors[$fk_authors]['urls'][$description] = $url;
} while ($db->NextRow ());
}
// echo ("$config->documentroot/$dir/navbar.html\n");
if ($hd = fopen ("$config->documentroot/$dir/navbar.html", "w")) {
fputs ($hd, navbar ());
fclose ($hd);
}
////////////////////////////////////////////////////////////////////////////////
$db->exec ("create temporary table tmp_books as select * from v_books");
////////////////////////////////////////////////////////////////////////////////
// by-author
// Postgres 7.3.3 at ibiblio doesn't dig multicolumn functional indexes
$db->exec ("create index tmp_ix_books_authors on tmp_books (lower (author))");
foreach ($config->browse_pages as $caption => $regexp) {
// titles for each author
$db->exec ("select * from tmp_books where author ~* '^$regexp' " .
"order by author, filing, lang");
LoadTitles ();
$lines = array ();
FormatAuthors (1);
$pklist = array ();
$db->exec ("select fk_authors from aliases where alias ~* '^$regexp'");
if ($db->FirstRow ()) {
do {
$pklist[] = $db->get ("fk_authors", SQLINT);
} while ($db->NextRow ());
}
FormatAliases ($pklist, 1, "^$regexp");
uksort ($lines, 'strcoll');
$fn = strtolower ($caption);
pageheader ("Browse By Author: $caption");
echo (navbar ());
echo ("<div class=\"pgdbbyauthor\">\n\n");
foreach ($lines as $line) {
echo ($line);
}
echo ("</div>\n\n");
pagefooterfile ("$config->documentroot/$dir_authors/$fn.html.utf8");
}
////////////////////////////////////////////////////////////////////////////////
// by-lang
$db->exec ("create index tmp_ix_books_langs on tmp_books (lang)");
$db->exec ("select pk, lang from langs where pk in (select fk_langs from mn_books_langs)");
if ($db->FirstRow ()) {
do {
$langs[$db->get ("lang", SQLCHAR)] = $db->get ("pk", SQLCHAR);
} while ($db->NextRow ());
}
foreach ($langs as $lang => $id) {
$caption = $lang;
$fn = $id;
if ($id == 'en') {
pageheader ("Browse By Language: $caption");
echo (navbar ());
echo ("<p>There are too many english books to list them in one page. " .
"Please use the Browse-By-Author pages instead.</p>\n\n");
pagefooterfile ("$config->documentroot/$dir_langs/$fn.html.utf8");
continue;
}
$db->exec ("select * from tmp_books where fk_books in
(select fk_books from mn_books_langs where fk_langs = '$id'
and tmp_books.fk_books = mn_books_langs.fk_books)
order by lang, author, filing");
LoadTitles ();
$lines = array ();
FormatAuthors ();
FormatAliases (pklist ($authors));
uksort ($lines, 'strcoll');
pageheader ("Browse By Language: $caption");
echo (navbar ());
echo ("<div class=\"pgdbbylanguage\">\n\n");
foreach ($lines as $line) {
echo ($line);
}
echo ("</div>\n\n");
pagefooterfile ("$config->documentroot/$dir_langs/$fn.html.utf8");
}
////////////////////////////////////////////////////////////////////////////////
// by-locc
$db->exec ("select pk, locc from loccs where pk in (select fk_loccs from mn_books_loccs)");
if ($db->FirstRow ()) {
do {
$loccs[$db->get ("locc", SQLCHAR)] = $db->get ("pk", SQLCHAR);
} while ($db->NextRow ());
}
foreach ($loccs as $locc => $fk_loccs) {
$caption = $locc;
$fn = strtolower ($fk_loccs);
// titles for each author
// $db->exec ("select * from tmp_books where fk_loccs = '$fk_loccs' " .
// "order by fk_loccs, author, filing");
$db->exec ("select * from tmp_books where fk_books in
(select fk_books from mn_books_loccs where fk_loccs = '$fk_loccs'
and tmp_books.fk_books = mn_books_loccs.fk_books)
order by author, filing");
LoadTitles ();
$lines = array ();
FormatAuthors ();
FormatAliases (pklist ($authors));
uksort ($lines, 'strcoll');
pageheader ("Browse By Library of Congress Class: $caption");
echo (navbar ());
echo ("<div class=\"pgdbbylocc\">\n\n");
foreach ($lines as $line) {
echo ($line);
}
echo ("</div>\n\n");
pagefooterfile ("$config->documentroot/$dir_loccs/$fn.html.utf8");
}
////////////////////////////////////////////////////////////////////////////////
// by-category
$db->exec ("select pk, category from categories");
if ($db->FirstRow ()) {
do {
$categories[$db->get ("category", SQLCHAR)] = $db->get ("pk", SQLINT);
} while ($db->NextRow ());
}
foreach ($categories as $category => $id) {
$caption = $category;
$fn = $id;
if ($id == 0) {
pageheader ("Browse By Category: $caption");
echo (navbar ());
echo ("<p>There are too many books in this category too list them in one page. " .
"Please use the Browse-By-Author pages instead.</p>\n\n");
pagefooterfile ("$config->documentroot/$dir_langs/$fn.html.utf8");
continue;
}
$db->exec ("select * from tmp_books where fk_books in
(select fk_books from mn_books_categories where fk_categories = $id
and tmp_books.fk_books = mn_books_categories.fk_books)
order by author, filing");
LoadTitles ();
$lines = array ();
FormatAuthors ();
FormatAliases (pklist ($authors));
uksort ($lines, 'strcoll');
pageheader ("Browse By Category: $caption");
echo (navbar ());
echo ("<div class=\"pgdbbycategory\">\n\n");
foreach ($lines as $line) {
echo ($line);
}
echo ("</div>\n\n");
pagefooterfile ("$config->documentroot/$dir_categories/$fn.html.utf8");
}
////////////////////////////////////////////////////////////////////////////////
// by-title
$db->exec ("create index tmp_ix_books_titles on tmp_books (lower (filing))");
foreach ($config->browse_pages as $caption => $regexp) {
$fn = strtolower ($caption);
pageheader ("Browse By Title: $caption");
echo (navbar ());
echo ("<div class=\"pgdbbytitle\">\n\n");
// titles
$db->exec ("select * from tmp_books where lower (filing) ~ '^$regexp' order by lower (filing), author, lang");
if ($db->FirstRow ()) {
do {
$etext = $db->get ("fk_books", SQLINT);
$fk_authors = $db->get ("fk_authors", SQLINT);
$title = str_replace ("\n", "<br$config->endtag>", $db->get ("title", SQLCHAR));
$author = $db->get ("author", SQLCHAR);
$lang = $db->get ("lang", SQLCHAR);
$is_audio = $db->get ("is_audio", SQLBOOL);
// echo ("$title\n");
$icon = $is_audio ? " <img class=\"pgdbflag\" src=\"/pics/stock_volume-16.png\" alt=\"Audio Book\" title=\"Audio Book\"$config->endtag>" : "";
echo ("<h2><a href=\"/$dir_etext/$etext\">$title</a> ($lang)$icon</h2>\n");
$href = "/$dir_authors/" . find_browse_page ($author) . "#a$fk_authors";
echo ("<p>by <a href=\"$href\">$author</a></p>\n\n");
} while ($db->NextRow ());
}
echo ("</div>\n\n");
pagefooterfile ("$config->documentroot/$dir_titles/$fn.html.utf8");
}
////////////////////////////////////////////////////////////////////////////////
// recent books
$db->exec ("create index tmp_ix_books_fk_books on tmp_books (fk_books)");
$rssbuffer = "";
$books_output = array ();
// clear titles
foreach ($authors as $fk_authors => $dummy) {
$authors[$fk_authors]['titles'] = array ();
}
foreach ($spans as $span => $caption) {
$recents = array ();
$cutoff = date ("Y-m-d", time () - $span * 86400);
$db->exec ("select distinct fk_books from files " .
"where fk_books is not null and diskstatus = 0 and filename !~ '^cache' and filemtime >= '$cutoff 00:00:00'");
if ($db->FirstRow ()) {
do {
$recents[] = $db->get ("fk_books", SQLINT);
} while ($db->NextRow ());
}
$lines = array ();
if (count ($recents)) {
$recent = join (", ", $recents);
// titles for each author
$db->exec ("select * from tmp_books where fk_books in ($recent) order by author, filing, lang");
LoadTitles ();
FormatAuthors ();
FormatAliases (pklist ($authors));
uksort ($lines, 'strcoll');
}
$config->htmlheaderlinks[] = "<link rel=\"alternate\" type=\"application/rss+xml\" title=\"RSS-Feed of Project Gutenberg Recently Posted or Updated EBooks\" href=\"http://www.gutenberg.org/$dir_feeds/today.rss\">";
pageheader ("Books Posted or Updated Since: $cutoff");
echo (navbar ());
echo ("<div class=\"pgdbrecent\">\n\n");
if (!count ($recents)) {
echo ("<p>No books posted.</p>\n\n");
}
foreach ($lines as $line) {
echo ($line);
}
if ($span == 1) {
// build rss
foreach ($authors as $author => $o) {
if (count ($o['titles'])) {
// output list of titles
foreach ($o['titles'] as $t) {
// avoid duplicates in rss
if (!isset ($books_output[$t['etext']])) {
$books_output[$t['etext']] = 1;
$friendlytitle = htmlspecialchars (friendlytitle ($t['etext'], 100));
$rssbuffer .= " <item>\n";
$rssbuffer .= " <title>$friendlytitle</title>\n";
$rssbuffer .= " <link>$base_url/$dir_etext/{$t['etext']}</link>\n";
$rssbuffer .= " <description>Language: {$t['lang']}</description>\n";
$rssbuffer .= " </item>\n\n";
}
}
}
}
}
echo ("</div>\n\n");
pagefooterfile ("$config->documentroot/$dir_recent/last$span.html.utf8");
$config->htmlheaderlinks = array ();
}
// write rss feed
if ($hd = fopen ($file = "$config->documentroot/$dir_feeds/today.rss", "w")) {
$pubdate = date ("r");
fputs ($hd, <<<EOF
<?xml version="1.0" encoding="utf-8" ?>
<rss version="0.91">
<channel>
<title>Project Gutenberg Recently Posted or Updated EBooks</title>
<link>$base_url</link>
<description>
EBooks posted or updated today on Project Gutenberg.
This feed is regenerated every night.
</description>
<language>en-us</language>
<webMaster>webmaster@gutenberg.org (Marcello Perathoner)</webMaster>
<pubDate>$pubdate</pubDate>
<lastBuildDate>$pubdate</lastBuildDate>
EOF
);
fputs ($hd, $rssbuffer);
fputs ($hd, " </channel>\n</rss>\n");
fclose ($hd);
}
?>

384
catalog/admin/make-rdf.php Normal file
View File

@ -0,0 +1,384 @@
<?php
$cli = php_sapi_name () == "cli";
if (!$cli) exit ();
set_include_path(get_include_path() . PATH_SEPARATOR . "/public/vhost/g/gutenberg/dev/private/lib/php");
include ("pgcat.phh");
function _log ($s) {
// fwrite (STDERR, "$s\n");
}
function lout (&$book, $name, $tag) {
$s = "";
if (isset ($book[$name])) {
$a = $book[$name];
if (is_array ($a)) {
if (count ($a) > 1) {
$s .= " <$tag>\n <rdf:Bag>\n";
foreach ($a as $val) {
$s .= " <rdf:li rdf:parseType=\"Literal\">$val</rdf:li>\n";
}
$s .= " </rdf:Bag>\n </$tag>\n";
} else {
$val = $a[0];
$s .= " <$tag rdf:parseType=\"Literal\">$val</$tag>\n";
}
} else {
$val = $a;
$s .= " <$tag rdf:parseType=\"Literal\">$val</$tag>\n";
}
}
return $s;
}
function qout (&$book, $name, $tag, $tag2) {
if (!isset ($book[$name])) {
return "";
}
$a = $book[$name];
if (is_array ($a)) {
if (count ($a) > 1) {
$s = " <$tag>\n <rdf:Bag>\n";
foreach ($a as $val) {
$s .= " <rdf:li><$tag2><rdf:value>$val</rdf:value></$tag2></rdf:li>\n";
}
$s .= " </rdf:Bag>\n </$tag>\n";
return $s;
} else {
$val = $a[0];
return " <$tag><$tag2><rdf:value>$val</rdf:value></$tag2></$tag>\n";
}
}
$val = $a;
return " <$tag><$tag2><rdf:value>$val</rdf:value></$tag2></$tag>\n";
}
_log ("Initializing ...");
$db = $config->db ();
_log (" Connected to Database ...");
$base_url = "http://www.gutenberg.org";
$file_base = "$base_url";
$now = date ("Y-m-d");
$books = array ();
_log (" Done\n");
_log ("Loading data from database ...");
_log (" Books");
$db->exec ("select * from books");
if ($db->FirstRow ()) {
do {
$pk = $db->get ("pk", SQLINT);
if ($reldate = $db->get ("release_date", SQLDATE)) {
$books[$pk]['release_date'] = date ("Y-m-d", $reldate);
$books[$pk]['downloads'] = $db->get ("downloads", SQLINT);
}
if ($db->get ("copyrighted", SQLINT)) {
$books[$pk]['copyrighted'] = 1;
}
} while ($db->NextRow ());
}
_log (" Authors");
$db->exec ("select * from v_books_authors order by fk_books");
if ($db->FirstRow ()) {
do {
$fk_books = $db->get ("fk_books", SQLINT);
$role = $db->get ("role", SQLCHAR);
if ($role == "Creator" || $role == "Author") {
$val = htmlspecialchars (FormatAuthorDate ($db));
$books[$fk_books]['creators'][] = $val;
} else {
$val = htmlspecialchars (FormatAuthorDateRole ($db));
$books[$fk_books]['contributors'][] = $val;
}
} while ($db->NextRow ());
}
_log (" FriendlyTitles");
foreach ($books as $fk_books => $dummy) {
$books[$fk_books]['friendlytitle'][] = htmlspecialchars (friendlytitle ($fk_books));
}
/* _log (" Titles");
$db->exec ("select * from titles");
if ($db->FirstRow ()) {
do {
$fk_books = $db->get ("fk_books", SQLINT);
$title = htmlspecialchars ($db->get ("title", SQLCHAR));
// $title = preg_replace ("/\s*\n/", "<br />", $title);
switch ($db->get ("title_order", SQLINT)) {
case 1:
$books[$fk_books]['240'][] = $title; break;
case 2:
case 4:
case 5:
$books[$fk_books]['246'][] = $title; break;
case 3:
$books[$fk_books]['505'][] = $title; break;
}
} while ($db->NextRow ());
} */
_log (" Attributes");
$db->exec ("select * from attributes");
if ($db->FirstRow ()) {
do {
$fk_books = $db->get ("fk_books", SQLINT);
$fk_attriblist = (string) $db->get ("fk_attriblist", SQLINT);
$text = htmlspecialchars ($db->get ("text", SQLCHAR));
$books[$fk_books][$fk_attriblist][] = $text;
} while ($db->NextRow ());
}
_log (" Categories");
$db->exec ("select * from mn_books_categories, categories where fk_categories = pk");
if ($db->FirstRow ()) {
do {
$fk_books = $db->get ("fk_books", SQLINT);
$books[$fk_books]['categories'][] = $db->get ("category", SQLCHAR);
} while ($db->NextRow ());
} else {
$books[$fk_books]['categories'][] = 'eBook';
}
_log (" Languages");
$db->exec ("select * from mn_books_langs");
if ($db->FirstRow ()) {
do {
$fk_books = $db->get ("fk_books", SQLINT);
$books[$fk_books]['languages'][] = $db->get ("fk_langs", SQLCHAR);
} while ($db->NextRow ());
}
_log (" Subjects");
$db->exec ("select * from mn_books_subjects, subjects where fk_subjects = pk");
if ($db->FirstRow ()) {
do {
$fk_books = $db->get ("fk_books", SQLINT);
$subject = htmlspecialchars ($db->get ("subject", SQLCHAR));
$books[$fk_books]['subjects'][] = $subject;
} while ($db->NextRow ());
}
_log (" LoCC");
$db->exec ("select * from mn_books_loccs");
if ($db->FirstRow ()) {
do {
$fk_books = $db->get ("fk_books", SQLINT);
$books[$fk_books]['loccs'][] = $db->get ("fk_loccs", SQLCHAR);
} while ($db->NextRow ());
}
_log (" Done\n");
$fp = fopen ("php://stdout", "w");
$s = <<< EOF
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE rdf:RDF [
<!ENTITY pg "Project Gutenberg">
<!ENTITY lic "$base_url/license">
<!ENTITY f "$file_base/">
]>
<!--
The Project Gutenberg Catalog in RDF/XML Format
Copyright (C) 2004-present by
Project Gutenberg Literary Archive Foundation
4557 Melan Drive S.
Fairbanks AK 99712
U.S.A.
LICENSE TERMS
This file ("work") is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License (GPL)
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This work is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
Please become familiar with the GNU GPL before using this file.
You can get a full copy of the GNU General Public License online at:
http://www.gnu.org/licenses/gpl.html
The GNU General Public License is explained in human language at:
http://creativecommons.org/licenses/GPL/2.0/
If you are uncertain about the terms of the license or whether your
intended use is legitimate, please email gbnewby@pglaf.org for
clarification.
Thank you for your interest in Project Gutenberg. For more
information about Project Gutenberg and its goals, visit
the Official Project Gutenberg Web site at
http://www.gutenberg.org
-->
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:dcterms="http://purl.org/dc/terms/"
xmlns:dcmitype="http://purl.org/dc/dcmitype/"
xmlns:cc="http://web.resource.org/cc/"
xmlns:pgterms="$base_url/rdfterms/"
xml:base="$base_url/feeds/catalog.rdf">
<cc:Work rdf:about="">
<cc:license rdf:resource="http://creativecommons.org/licenses/GPL/2.0/" />
</cc:Work>
<cc:License rdf:about="http://creativecommons.org/licenses/GPL/2.0/">
<cc:permits rdf:resource="http://web.resource.org/cc/Reproduction" />
<cc:permits rdf:resource="http://web.resource.org/cc/Distribution" />
<cc:requires rdf:resource="http://web.resource.org/cc/Notice" />
<cc:permits rdf:resource="http://web.resource.org/cc/DerivativeWorks" />
<cc:requires rdf:resource="http://web.resource.org/cc/ShareAlike" />
<cc:requires rdf:resource="http://web.resource.org/cc/SourceCode" />
</cc:License>
<rdf:Description rdf:about="">
<dc:created><dcterms:W3CDTF><rdf:value>$now</rdf:value></dcterms:W3CDTF></dc:created>
</rdf:Description>
EOF;
fputs ($fp, $s);
// debug
// $books = array_slice ($books, 0, 500);
reset ($books);
while (list ($fk_books, $book) = each ($books)) {
$s = "<pgterms:etext rdf:ID=\"etext$fk_books\">\n";
$s .= " <dc:publisher>&pg;</dc:publisher>\n";
$s .= lout ($book, '240', 'dc:title');
$s .= lout ($book, '245', 'dc:title');
$s .= lout ($book, '246', 'dc:alternative');
$s .= lout ($book, '500', 'dc:description');
$s .= lout ($book, '505', 'dc:tableOfContents');
$s .= lout ($book, 'creators', 'dc:creator');
$s .= lout ($book, 'contributors', 'dc:contributor');
$s .= lout ($book, 'friendlytitle', 'pgterms:friendlytitle');
$s .= qout ($book, 'languages', 'dc:language', 'dcterms:ISO639-2');
$s .= qout ($book, 'subjects', 'dc:subject', 'dcterms:LCSH');
$s .= qout ($book, 'loccs', 'dc:subject', 'dcterms:LCC');
$s .= qout ($book, 'release_date', 'dc:created', 'dcterms:W3CDTF');
$s .= qout ($book, 'downloads', 'pgterms:downloads', 'xsd:nonNegativeInteger');
$s .= qout ($book, 'categories', 'dc:type', 'pgterms:category');
if (isset ($book['copyrighted'])) {
$s .= " <dc:rights>Copyrighted work. See license inside work.</dc:rights>\n";
} else {
$s .= " <dc:rights rdf:resource=\"&lic;\" />\n";
}
$s .= "</pgterms:etext>\n\n";
fputs ($fp, $s);
}
$books = null;
// files
$db->exec ("select fk_books, mediatype, filetype, fk_filetypes, fk_compressions, fk_encodings, " .
"edition, filename, filesize, filemtime " .
"from files " .
"left join filetypes on files.fk_filetypes = filetypes.pk " .
"where fk_books is not null and obsoleted = 0 and diskstatus = 0 " .
"order by fk_books, filename;");
if ($db->FirstRow ()) {
do {
$fk_books = $db->get ("fk_books", SQLINT);
$filename = $db->get ("filename", SQLCHAR);
$filesize = $db->get ("filesize", SQLINT);
$filetype = $db->get ("filetype", SQLCHAR);
$fk_filetypes = $db->get ("fk_filetypes", SQLCHAR);
$filemtime = $db->get ("filemtime", SQLDATE);
$mediatype = $db->get ("mediatype", SQLCHAR);
$fk_encodings = $db->get ("fk_encodings", SQLCHAR);
$fk_compressions = $db->get ("fk_compressions", SQLCHAR);
if (!strncmp ($filename, "cache/", 6)) {
$filename = "&f;$filename";
} else {
$filename = "&f;dirs/$filename";
}
$mtime = date ("Y-m-d", $filemtime);
if (!empty ($fk_encodings) && !strncmp ($mediatype, "text/", 5)) {
$mediatype .= "; charset=\"$fk_encodings\"";
}
if (empty ($mediatype)) {
$mediatype = "application/octet-stream";
if (!empty ($fk_filetypes)) {
$mediatype .= "; type=\"$filetype ($fk_filetypes)\"";
}
}
$compression = "";
if ($fk_compressions == "zip") {
$compression = "\n <dc:format><dcterms:IMT><rdf:value>application/zip</rdf:value></dcterms:IMT></dc:format>";
}
$s = "
<pgterms:file rdf:about=\"$filename\">
<dc:format><dcterms:IMT><rdf:value>$mediatype</rdf:value></dcterms:IMT></dc:format>$compression
<dcterms:extent>$filesize</dcterms:extent>
<dcterms:modified><dcterms:W3CDTF><rdf:value>$mtime</rdf:value></dcterms:W3CDTF></dcterms:modified>
<dcterms:isFormatOf rdf:resource=\"#etext$fk_books\" />
</pgterms:file>
";
fputs ($fp, $s);
} while ($db->NextRow ());
}
fputs ($fp, "\n</rdf:RDF>\n");
fclose ($fp);
_log (" Done!\n");
?>

383
catalog/admin/make-rdf.php~ Normal file
View File

@ -0,0 +1,383 @@
<?php
$cli = php_sapi_name () == "cli";
if (!$cli) exit ();
include ("pgcat.phh");
function _log ($s) {
// fwrite (STDERR, "$s\n");
}
function lout (&$book, $name, $tag) {
$s = "";
if (isset ($book[$name])) {
$a = $book[$name];
if (is_array ($a)) {
if (count ($a) > 1) {
$s .= " <$tag>\n <rdf:Bag>\n";
foreach ($a as $val) {
$s .= " <rdf:li rdf:parseType=\"Literal\">$val</rdf:li>\n";
}
$s .= " </rdf:Bag>\n </$tag>\n";
} else {
$val = $a[0];
$s .= " <$tag rdf:parseType=\"Literal\">$val</$tag>\n";
}
} else {
$val = $a;
$s .= " <$tag rdf:parseType=\"Literal\">$val</$tag>\n";
}
}
return $s;
}
function qout (&$book, $name, $tag, $tag2) {
if (!isset ($book[$name])) {
return "";
}
$a = $book[$name];
if (is_array ($a)) {
if (count ($a) > 1) {
$s = " <$tag>\n <rdf:Bag>\n";
foreach ($a as $val) {
$s .= " <rdf:li><$tag2><rdf:value>$val</rdf:value></$tag2></rdf:li>\n";
}
$s .= " </rdf:Bag>\n </$tag>\n";
return $s;
} else {
$val = $a[0];
return " <$tag><$tag2><rdf:value>$val</rdf:value></$tag2></$tag>\n";
}
}
$val = $a;
return " <$tag><$tag2><rdf:value>$val</rdf:value></$tag2></$tag>\n";
}
_log ("Initializing ...");
$db = $config->db ();
_log (" Connected to Database ...");
$base_url = "http://www.gutenberg.org";
$file_base = "$base_url";
$now = date ("Y-m-d");
$books = array ();
_log (" Done\n");
_log ("Loading data from database ...");
_log (" Books");
$db->exec ("select * from books");
if ($db->FirstRow ()) {
do {
$pk = $db->get ("pk", SQLINT);
if ($reldate = $db->get ("release_date", SQLDATE)) {
$books[$pk]['release_date'] = date ("Y-m-d", $reldate);
$books[$pk]['downloads'] = $db->get ("downloads", SQLINT);
}
if ($db->get ("copyrighted", SQLINT)) {
$books[$pk]['copyrighted'] = 1;
}
} while ($db->NextRow ());
}
_log (" Authors");
$db->exec ("select * from v_books_authors order by fk_books");
if ($db->FirstRow ()) {
do {
$fk_books = $db->get ("fk_books", SQLINT);
$role = $db->get ("role", SQLCHAR);
if ($role == "Creator" || $role == "Author") {
$val = htmlspecialchars (FormatAuthorDate ($db));
$books[$fk_books]['creators'][] = $val;
} else {
$val = htmlspecialchars (FormatAuthorDateRole ($db));
$books[$fk_books]['contributors'][] = $val;
}
} while ($db->NextRow ());
}
_log (" FriendlyTitles");
foreach ($books as $fk_books => $dummy) {
$books[$fk_books]['friendlytitle'][] = htmlspecialchars (friendlytitle ($fk_books));
}
/* _log (" Titles");
$db->exec ("select * from titles");
if ($db->FirstRow ()) {
do {
$fk_books = $db->get ("fk_books", SQLINT);
$title = htmlspecialchars ($db->get ("title", SQLCHAR));
// $title = preg_replace ("/\s*\n/", "<br />", $title);
switch ($db->get ("title_order", SQLINT)) {
case 1:
$books[$fk_books]['240'][] = $title; break;
case 2:
case 4:
case 5:
$books[$fk_books]['246'][] = $title; break;
case 3:
$books[$fk_books]['505'][] = $title; break;
}
} while ($db->NextRow ());
} */
_log (" Attributes");
$db->exec ("select * from attributes");
if ($db->FirstRow ()) {
do {
$fk_books = $db->get ("fk_books", SQLINT);
$fk_attriblist = (string) $db->get ("fk_attriblist", SQLINT);
$text = htmlspecialchars ($db->get ("text", SQLCHAR));
$books[$fk_books][$fk_attriblist][] = $text;
} while ($db->NextRow ());
}
_log (" Categories");
$db->exec ("select * from mn_books_categories, categories where fk_categories = pk");
if ($db->FirstRow ()) {
do {
$fk_books = $db->get ("fk_books", SQLINT);
$books[$fk_books]['categories'][] = $db->get ("category", SQLCHAR);
} while ($db->NextRow ());
} else {
$books[$fk_books]['categories'][] = 'eBook';
}
_log (" Languages");
$db->exec ("select * from mn_books_langs");
if ($db->FirstRow ()) {
do {
$fk_books = $db->get ("fk_books", SQLINT);
$books[$fk_books]['languages'][] = $db->get ("fk_langs", SQLCHAR);
} while ($db->NextRow ());
}
_log (" Subjects");
$db->exec ("select * from mn_books_subjects, subjects where fk_subjects = pk");
if ($db->FirstRow ()) {
do {
$fk_books = $db->get ("fk_books", SQLINT);
$subject = htmlspecialchars ($db->get ("subject", SQLCHAR));
$books[$fk_books]['subjects'][] = $subject;
} while ($db->NextRow ());
}
_log (" LoCC");
$db->exec ("select * from mn_books_loccs");
if ($db->FirstRow ()) {
do {
$fk_books = $db->get ("fk_books", SQLINT);
$books[$fk_books]['loccs'][] = $db->get ("fk_loccs", SQLCHAR);
} while ($db->NextRow ());
}
_log (" Done\n");
$fp = fopen ("php://stdout", "w");
$s = <<< EOF
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE rdf:RDF [
<!ENTITY pg "Project Gutenberg">
<!ENTITY lic "$base_url/license">
<!ENTITY f "$file_base/">
]>
<!--
The Project Gutenberg Catalog in RDF/XML Format
Copyright (C) 2004-present by
Project Gutenberg Literary Archive Foundation
4557 Melan Drive S.
Fairbanks AK 99712
U.S.A.
LICENSE TERMS
This file ("work") is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License (GPL)
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This work is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
Please become familiar with the GNU GPL before using this file.
You can get a full copy of the GNU General Public License online at:
http://www.gnu.org/licenses/gpl.html
The GNU General Public License is explained in human language at:
http://creativecommons.org/licenses/GPL/2.0/
If you are uncertain about the terms of the license or whether your
intended use is legitimate, please email gbnewby@pglaf.org for
clarification.
Thank you for your interest in Project Gutenberg. For more
information about Project Gutenberg and its goals, visit
the Official Project Gutenberg Web site at
http://www.gutenberg.org
-->
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:dcterms="http://purl.org/dc/terms/"
xmlns:dcmitype="http://purl.org/dc/dcmitype/"
xmlns:cc="http://web.resource.org/cc/"
xmlns:pgterms="$base_url/rdfterms/"
xml:base="$base_url/feeds/catalog.rdf">
<cc:Work rdf:about="">
<cc:license rdf:resource="http://creativecommons.org/licenses/GPL/2.0/" />
</cc:Work>
<cc:License rdf:about="http://creativecommons.org/licenses/GPL/2.0/">
<cc:permits rdf:resource="http://web.resource.org/cc/Reproduction" />
<cc:permits rdf:resource="http://web.resource.org/cc/Distribution" />
<cc:requires rdf:resource="http://web.resource.org/cc/Notice" />
<cc:permits rdf:resource="http://web.resource.org/cc/DerivativeWorks" />
<cc:requires rdf:resource="http://web.resource.org/cc/ShareAlike" />
<cc:requires rdf:resource="http://web.resource.org/cc/SourceCode" />
</cc:License>
<rdf:Description rdf:about="">
<dc:created><dcterms:W3CDTF><rdf:value>$now</rdf:value></dcterms:W3CDTF></dc:created>
</rdf:Description>
EOF;
fputs ($fp, $s);
// debug
// $books = array_slice ($books, 0, 500);
reset ($books);
while (list ($fk_books, $book) = each ($books)) {
$s = "<pgterms:etext rdf:ID=\"etext$fk_books\">\n";
$s .= " <dc:publisher>&pg;</dc:publisher>\n";
$s .= lout ($book, '240', 'dc:title');
$s .= lout ($book, '245', 'dc:title');
$s .= lout ($book, '246', 'dc:alternative');
$s .= lout ($book, '500', 'dc:description');
$s .= lout ($book, '505', 'dc:tableOfContents');
$s .= lout ($book, 'creators', 'dc:creator');
$s .= lout ($book, 'contributors', 'dc:contributor');
$s .= lout ($book, 'friendlytitle', 'pgterms:friendlytitle');
$s .= qout ($book, 'languages', 'dc:language', 'dcterms:ISO639-2');
$s .= qout ($book, 'subjects', 'dc:subject', 'dcterms:LCSH');
$s .= qout ($book, 'loccs', 'dc:subject', 'dcterms:LCC');
$s .= qout ($book, 'release_date', 'dc:created', 'dcterms:W3CDTF');
$s .= qout ($book, 'downloads', 'pgterms:downloads', 'xsd:nonNegativeInteger');
$s .= qout ($book, 'categories', 'dc:type', 'pgterms:category');
if (isset ($book['copyrighted'])) {
$s .= " <dc:rights>Copyrighted work. See license inside work.</dc:rights>\n";
} else {
$s .= " <dc:rights rdf:resource=\"&lic;\" />\n";
}
$s .= "</pgterms:etext>\n\n";
fputs ($fp, $s);
}
$books = null;
// files
$db->exec ("select fk_books, mediatype, filetype, fk_filetypes, fk_compressions, fk_encodings, " .
"edition, filename, filesize, filemtime " .
"from files " .
"left join filetypes on files.fk_filetypes = filetypes.pk " .
"where fk_books is not null and obsoleted = 0 and diskstatus = 0 " .
"order by fk_books, filename;");
if ($db->FirstRow ()) {
do {
$fk_books = $db->get ("fk_books", SQLINT);
$filename = $db->get ("filename", SQLCHAR);
$filesize = $db->get ("filesize", SQLINT);
$filetype = $db->get ("filetype", SQLCHAR);
$fk_filetypes = $db->get ("fk_filetypes", SQLCHAR);
$filemtime = $db->get ("filemtime", SQLDATE);
$mediatype = $db->get ("mediatype", SQLCHAR);
$fk_encodings = $db->get ("fk_encodings", SQLCHAR);
$fk_compressions = $db->get ("fk_compressions", SQLCHAR);
if (!strncmp ($filename, "cache/", 6)) {
$filename = "&f;$filename";
} else {
$filename = "&f;dirs/$filename";
}
$mtime = date ("Y-m-d", $filemtime);
if (!empty ($fk_encodings) && !strncmp ($mediatype, "text/", 5)) {
$mediatype .= "; charset=\"$fk_encodings\"";
}
if (empty ($mediatype)) {
$mediatype = "application/octet-stream";
if (!empty ($fk_filetypes)) {
$mediatype .= "; type=\"$filetype ($fk_filetypes)\"";
}
}
$compression = "";
if ($fk_compressions == "zip") {
$compression = "\n <dc:format><dcterms:IMT><rdf:value>application/zip</rdf:value></dcterms:IMT></dc:format>";
}
$s = "
<pgterms:file rdf:about=\"$filename\">
<dc:format><dcterms:IMT><rdf:value>$mediatype</rdf:value></dcterms:IMT></dc:format>$compression
<dcterms:extent>$filesize</dcterms:extent>
<dcterms:modified><dcterms:W3CDTF><rdf:value>$mtime</rdf:value></dcterms:W3CDTF></dcterms:modified>
<dcterms:isFormatOf rdf:resource=\"#etext$fk_books\" />
</pgterms:file>
";
fputs ($fp, $s);
} while ($db->NextRow ());
}
fputs ($fp, "\n</rdf:RDF>\n");
fclose ($fp);
_log (" Done!\n");
?>

View File

@ -0,0 +1,263 @@
<?php
$cli = php_sapi_name () == "cli";
if (!$cli) exit ();
set_include_path(get_include_path() . PATH_SEPARATOR . "/public/vhost/g/gutenberg/dev/private/lib/php");
include ("pgcat.phh");
function mk_header ($title) {
global $config;
return "<?php
include (\"pgbrowse.phh\");
\$config->page_encoding = \"UTF-8\";
pageheader (\"$title\");
?>\n\n";
}
$dir = "browse";
$dir_scores = "$dir/scores";
@mkdir ("$config->documentroot/$dir", 0755);
@mkdir ("$config->documentroot/$dir_scores", 0755);
$db = $config->db ();
$db2 = $config->db ();
////////////////////////////////////////////////////////////////////////////////
// top scores
// disqualified because they are mp3 files and have "House" in title
// its amazing how many kids try to download these
// moreover "Usher" seems to be a rap artist
$disqualifiedbooks = "0, 6550, 6557, 9280, 9695, 9714";
// unknown, anonymous and various
$disqualifiedauthors = "49, 116, 216";
function downloads ($where = "") {
global $db2, $config, $disqualifiedbooks;
$s = "";
$db2->exec ("
SELECT SUM (downloads) AS downloads
FROM dl
WHERE $where");
if ($db2->FirstRow ()) {
return $db2->get ("downloads", SQLINT);
}
return 0;
}
function topbooks ($num, $where = "") {
global $db2, $config, $disqualifiedbooks;
$s = "";
$db2->exec ("
SELECT fk_books, SUM (downloads) AS downloads
FROM dl
WHERE $where
GROUP BY fk_books
ORDER BY downloads DESC LIMIT $num");
$s .= "<ol>\n";
if ($db2->FirstRow ()) {
do {
$fk_books = $db2->get ("fk_books", SQLINT);
$downloads = $db2->get ("downloads", SQLINT);
$friendlytitle = friendlytitle ($fk_books, 100);
$s .= "<li><a href=\"$config->etext/$fk_books\">$friendlytitle ($downloads)</a></li>\n";
} while ($db2->NextRow ());
}
$s .= "</ol>\n";
return $s;
}
function topauthors ($num, $where = "") {
global $db2, $config, $disqualifiedbooks, $disqualifiedauthors;
$s = "";
$db2->exec ("
SELECT author, fk_authors, SUM (dl.downloads) as downloads
FROM authors, mn_books_authors, dl
WHERE $where
AND authors.pk = mn_books_authors.fk_authors
AND mn_books_authors.fk_books = dl.fk_books
AND fk_authors NOT IN ($disqualifiedauthors)
GROUP BY author, fk_authors
ORDER BY downloads DESC LIMIT $num");
$s .= "<ol>\n";
if ($db2->FirstRow ()) {
do {
$author = $db2->get ("author", SQLCHAR);
$fk_authors = $db2->get ("fk_authors", SQLINT);
$downloads = $db2->get ("downloads", SQLINT);
$href = find_browse_page ($author) . "#a$fk_authors";
$s .= ("<li><a href=\"/browse/authors/$href\">$author ($downloads)</a></li>\n");
} while ($db2->NextRow ());
}
$s .= "</ol>\n";
return $s;
}
/////////////////////////////////////////////////////////////////////////////////////
// start main
echo ("creating temp table ...");
$db2->exec ("CREATE TEMP TABLE dl AS
SELECT scores.book_downloads.fk_books, scores.book_downloads.date,
scores.book_downloads.downloads, fk_langs
FROM scores.book_downloads, mn_books_langs
WHERE scores.book_downloads.fk_books = mn_books_langs.fk_books
AND scores.book_downloads.fk_books NOT IN ($disqualifiedbooks)");
echo (" done.\n");
$langs = array ();
$langs[] = array ("", 100); // Top 100 all languages
$langs[] = array ("", 1000); // Top 1000 all languages
$db2->exec ("select fk_langs, count (fk_langs) as cnt from mn_books_langs group by fk_langs order by cnt desc;");
if ($db2->FirstRow ()) {
do {
$fk_langs = $db2->get ("fk_langs", SQLCHAR);
$langs[] = array ($fk_langs, 100); // Top 100 this language
} while ($db2->NextRow ());
}
echo (" done.\n");
$db2->exec ("select max (date) as latest, min (date) as earliest from scores.book_downloads");
$latest = date ("Y-m-d", $db2->get ("latest", SQLDATE));
$earliest = date ("Y-m-d", $db2->get ("earliest", SQLDATE));
// start output
foreach ($langs as $l) {
$lang = $l[0];
$num = $l[1];
$filesuffix = "";
$titlesuffix = "$num";
$langwhere = "";
if ($num != 100) {
$filesuffix .= "$num";
}
if (!empty ($lang)) {
$filesuffix .= "-$lang";
$titlesuffix .= " ($lang)";
$langwhere = "fk_langs = '$lang' AND ";
}
if ($hd = fopen ($file = "$config->documentroot/$dir_scores/top$filesuffix.php", "w")) {
echo ("writing $file ... downloads ...\n");
$d1 = downloads ("$langwhere date >= current_date - interval '1 days'");
$d7 = downloads ("$langwhere date >= current_date - interval '7 days'");
$d30 = downloads ("$langwhere date >= current_date - interval '30 days'");
fputs ($hd, mk_header ("Top $titlesuffix"));
$s = <<< EOF
<p>To determine the ranking we count the times each file gets downloaded.
Both HTTP and FTP transfers are counted.
Only transfers from ibiblio.org are counted as we have no access to our mirrors log files.
Multiple downloads from the same IP address on the same day count as one download.
IP addresses that download more than 100 files a day are considered
robots and are not considered.
Books made out of multiple files like most audio books are counted
if any file is downloaded.</p>
<table>
<caption>Downloaded Books</caption>
<tr><th>$latest</th><td class="right">$d1</td></tr>
<tr><th>last 7 days</th><td class="right">$d7</td></tr>
<tr><th>last 30 days</th><td class="right">$d30</td></tr>
</table>
<a href="pretty-pictures">Pretty Pictures</a>
EOF;
fputs ($hd, $s);
$links = "<p>
<a href=\"#books-last1\">Top $num EBooks yesterday</a> &mdash;
<a href=\"#authors-last1\">Top $num Authors yesterday</a> &mdash;
<a href=\"#books-last7\">Top $num EBooks last 7 days</a> &mdash;
<a href=\"#authors-last7\">Top $num Authors last 7 days</a> &mdash;
<a href=\"#books-last30\">Top $num EBooks last 30 days</a> &mdash;
<a href=\"#authors-last30\">Top $num Authors last 30 days</a>
</p>
";
// Yesterday
echo (" yesterday ... books ...");
fputs ($hd, $links);
fputs ($hd, "<h2 id=\"books-last1\">Top $num EBooks yesterday</h2>\n\n");
fputs ($hd, topbooks ($num, "$langwhere date >= current_date - interval '1 days'"));
echo (" authors ...");
fputs ($hd, $links);
fputs ($hd, "<h2 id=\"authors-last1\">Top $num Authors yesterday</h2>\n\n");
fputs ($hd, topauthors ($num, "$langwhere date >= current_date - interval '1 days'"));
// Last 7 days
echo (" last 7 days ... books ...");
fputs ($hd, $links);
fputs ($hd, "<h2 id=\"books-last7\">Top $num EBooks last 7 days</h2>\n\n");
fputs ($hd, topbooks ($num, "$langwhere date >= current_date - interval '7 days'"));
echo (" authors ...");
fputs ($hd, $links);
fputs ($hd, "<h2 id=\"authors-last7\">Top $num Authors last 7 days</h2>\n\n");
fputs ($hd, topauthors ($num, "$langwhere date >= current_date - interval '7 days'"));
// Last 30 days
echo (" last 30 days ... books ...");
fputs ($hd, $links);
fputs ($hd, "<h2 id=\"books-last30\">Top $num EBooks last 30 days</h2>\n\n");
fputs ($hd, topbooks ($num, "$langwhere date >= current_date - interval '30 days'"));
echo (" authors ...");
fputs ($hd, $links);
fputs ($hd, "<h2 id=\"authors-last30\">Top $num Authors last 30 days</h2>\n\n");
fputs ($hd, topauthors ($num, "$langwhere date >= current_date - interval '30 days'"));
fputs ($hd, $links);
fputs ($hd, "<?php pagefooter (); ?>\n");
fclose ($hd);
echo (" done.\n");
}
}
?>

View File

@ -0,0 +1,262 @@
<?php
$cli = php_sapi_name () == "cli";
if (!$cli) exit ();
include ("pgcat.phh");
function mk_header ($title) {
global $config;
return "<?php
include (\"pgbrowse.phh\");
\$config->page_encoding = \"UTF-8\";
pageheader (\"$title\");
?>\n\n";
}
$dir = "browse";
$dir_scores = "$dir/scores";
@mkdir ("$config->documentroot/$dir", 0755);
@mkdir ("$config->documentroot/$dir_scores", 0755);
$db = $config->db ();
$db2 = $config->db ();
////////////////////////////////////////////////////////////////////////////////
// top scores
// disqualified because they are mp3 files and have "House" in title
// its amazing how many kids try to download these
// moreover "Usher" seems to be a rap artist
$disqualifiedbooks = "0, 6550, 6557, 9280, 9695, 9714";
// unknown, anonymous and various
$disqualifiedauthors = "49, 116, 216";
function downloads ($where = "") {
global $db2, $config, $disqualifiedbooks;
$s = "";
$db2->exec ("
SELECT SUM (downloads) AS downloads
FROM dl
WHERE $where");
if ($db2->FirstRow ()) {
return $db2->get ("downloads", SQLINT);
}
return 0;
}
function topbooks ($num, $where = "") {
global $db2, $config, $disqualifiedbooks;
$s = "";
$db2->exec ("
SELECT fk_books, SUM (downloads) AS downloads
FROM dl
WHERE $where
GROUP BY fk_books
ORDER BY downloads DESC LIMIT $num");
$s .= "<ol>\n";
if ($db2->FirstRow ()) {
do {
$fk_books = $db2->get ("fk_books", SQLINT);
$downloads = $db2->get ("downloads", SQLINT);
$friendlytitle = friendlytitle ($fk_books, 100);
$s .= "<li><a href=\"$config->etext/$fk_books\">$friendlytitle ($downloads)</a></li>\n";
} while ($db2->NextRow ());
}
$s .= "</ol>\n";
return $s;
}
function topauthors ($num, $where = "") {
global $db2, $config, $disqualifiedbooks, $disqualifiedauthors;
$s = "";
$db2->exec ("
SELECT author, fk_authors, SUM (dl.downloads) as downloads
FROM authors, mn_books_authors, dl
WHERE $where
AND authors.pk = mn_books_authors.fk_authors
AND mn_books_authors.fk_books = dl.fk_books
AND fk_authors NOT IN ($disqualifiedauthors)
GROUP BY author, fk_authors
ORDER BY downloads DESC LIMIT $num");
$s .= "<ol>\n";
if ($db2->FirstRow ()) {
do {
$author = $db2->get ("author", SQLCHAR);
$fk_authors = $db2->get ("fk_authors", SQLINT);
$downloads = $db2->get ("downloads", SQLINT);
$href = find_browse_page ($author) . "#a$fk_authors";
$s .= ("<li><a href=\"/browse/authors/$href\">$author ($downloads)</a></li>\n");
} while ($db2->NextRow ());
}
$s .= "</ol>\n";
return $s;
}
/////////////////////////////////////////////////////////////////////////////////////
// start main
echo ("creating temp table ...");
$db2->exec ("CREATE TEMP TABLE dl AS
SELECT scores.book_downloads.fk_books, scores.book_downloads.date,
scores.book_downloads.downloads, fk_langs
FROM scores.book_downloads, mn_books_langs
WHERE scores.book_downloads.fk_books = mn_books_langs.fk_books
AND scores.book_downloads.fk_books NOT IN ($disqualifiedbooks)");
echo (" done.\n");
$langs = array ();
$langs[] = array ("", 100); // Top 100 all languages
$langs[] = array ("", 1000); // Top 1000 all languages
$db2->exec ("select fk_langs, count (fk_langs) as cnt from mn_books_langs group by fk_langs order by cnt desc;");
if ($db2->FirstRow ()) {
do {
$fk_langs = $db2->get ("fk_langs", SQLCHAR);
$langs[] = array ($fk_langs, 100); // Top 100 this language
} while ($db2->NextRow ());
}
echo (" done.\n");
$db2->exec ("select max (date) as latest, min (date) as earliest from scores.book_downloads");
$latest = date ("Y-m-d", $db2->get ("latest", SQLDATE));
$earliest = date ("Y-m-d", $db2->get ("earliest", SQLDATE));
// start output
foreach ($langs as $l) {
$lang = $l[0];
$num = $l[1];
$filesuffix = "";
$titlesuffix = "$num";
$langwhere = "";
if ($num != 100) {
$filesuffix .= "$num";
}
if (!empty ($lang)) {
$filesuffix .= "-$lang";
$titlesuffix .= " ($lang)";
$langwhere = "fk_langs = '$lang' AND ";
}
if ($hd = fopen ($file = "$config->documentroot/$dir_scores/top$filesuffix.php", "w")) {
echo ("writing $file ... downloads ...\n");
$d1 = downloads ("$langwhere date >= current_date - interval '1 days'");
$d7 = downloads ("$langwhere date >= current_date - interval '7 days'");
$d30 = downloads ("$langwhere date >= current_date - interval '30 days'");
fputs ($hd, mk_header ("Top $titlesuffix"));
$s = <<< EOF
<p>To determine the ranking we count the times each file gets downloaded.
Both HTTP and FTP transfers are counted.
Only transfers from ibiblio.org are counted as we have no access to our mirrors log files.
Multiple downloads from the same IP address on the same day count as one download.
IP addresses that download more than 100 files a day are considered
robots and are not considered.
Books made out of multiple files like most audio books are counted
if any file is downloaded.</p>
<table>
<caption>Downloaded Books</caption>
<tr><th>$latest</th><td class="right">$d1</td></tr>
<tr><th>last 7 days</th><td class="right">$d7</td></tr>
<tr><th>last 30 days</th><td class="right">$d30</td></tr>
</table>
<a href="pretty-pictures">Pretty Pictures</a>
EOF;
fputs ($hd, $s);
$links = "<p>
<a href=\"#books-last1\">Top $num EBooks yesterday</a> &mdash;
<a href=\"#authors-last1\">Top $num Authors yesterday</a> &mdash;
<a href=\"#books-last7\">Top $num EBooks last 7 days</a> &mdash;
<a href=\"#authors-last7\">Top $num Authors last 7 days</a> &mdash;
<a href=\"#books-last30\">Top $num EBooks last 30 days</a> &mdash;
<a href=\"#authors-last30\">Top $num Authors last 30 days</a>
</p>
";
// Yesterday
echo (" yesterday ... books ...");
fputs ($hd, $links);
fputs ($hd, "<h2 id=\"books-last1\">Top $num EBooks yesterday</h2>\n\n");
fputs ($hd, topbooks ($num, "$langwhere date >= current_date - interval '1 days'"));
echo (" authors ...");
fputs ($hd, $links);
fputs ($hd, "<h2 id=\"authors-last1\">Top $num Authors yesterday</h2>\n\n");
fputs ($hd, topauthors ($num, "$langwhere date >= current_date - interval '1 days'"));
// Last 7 days
echo (" last 7 days ... books ...");
fputs ($hd, $links);
fputs ($hd, "<h2 id=\"books-last7\">Top $num EBooks last 7 days</h2>\n\n");
fputs ($hd, topbooks ($num, "$langwhere date >= current_date - interval '7 days'"));
echo (" authors ...");
fputs ($hd, $links);
fputs ($hd, "<h2 id=\"authors-last7\">Top $num Authors last 7 days</h2>\n\n");
fputs ($hd, topauthors ($num, "$langwhere date >= current_date - interval '7 days'"));
// Last 30 days
echo (" last 30 days ... books ...");
fputs ($hd, $links);
fputs ($hd, "<h2 id=\"books-last30\">Top $num EBooks last 30 days</h2>\n\n");
fputs ($hd, topbooks ($num, "$langwhere date >= current_date - interval '30 days'"));
echo (" authors ...");
fputs ($hd, $links);
fputs ($hd, "<h2 id=\"authors-last30\">Top $num Authors last 30 days</h2>\n\n");
fputs ($hd, topauthors ($num, "$langwhere date >= current_date - interval '30 days'"));
fputs ($hd, $links);
fputs ($hd, "<?php pagefooter (); ?>\n");
fclose ($hd);
echo (" done.\n");
}
}
?>

77
catalog/admin/mirror.php Normal file
View File

@ -0,0 +1,77 @@
<?php
set_include_path(get_include_path() . PATH_SEPARATOR . "/public/vhost/g/gutenberg/dev/private/lib/php");
include_once ("pgcat.phh");
authenticate ("mirror");
getstr ("mode");
$caption = ucfirst ($mode) . " Mirror";
pageheader ($caption);
include_once ("sqlform.phh");
$db = $config->db ();
$db->logger = new logger ();
$f = new SQLForm ();
getstr ("fk_mirrors");
if (ismode ("delete")) {
$f->SubCaption ("You are about to delete this mirror.");
$f->SubCaption ("Press the '$caption' button to continue or " .
"hit the back button on your browser to dismiss.");
} else {
$f->Text ("continent", "continent", "Continent", SQLCHAR, 80, 80, false);
$f->Text ("nation", "nation", "Nation", SQLCHAR, 80, 80, false);
$f->Text ("location", "location", "Location", SQLCHAR, 80, 80, false);
$f->Text ("provider", "provider", "Provider", SQLCHAR, 80, 240, true);
$f->Text ("url", "url", "URL", SQLCHAR, 80, 240, true);
$f->TextArea ("note", "note", "Note", SQLCHAR, 4, 80, false);
$f->LoadData ("select * from mirrors where pk = '$fk_mirrors'");
}
$f->Hidden ("fk_mirrors");
if (isupdatemode ("add")) {
if ($f->Check ()) {
$sql = $f->mkInsert ($db->GetFormatter ());
if ($db->Exec ("insert into mirrors " . $sql)) {
msg ("Mirror added !");
} else {
error_msg ("Could not add mirror!");
}
}
}
if (isupdatemode ("edit")) {
if ($f->Check ()) {
$sql = $f->mkUpdate ($db->GetFormatter ());
if ($db->Exec ("update mirrors set " . $sql . "where pk = '$fk_mirrors'")) {
msg ("Mirror modified !");
} else {
error_msg ("Could not modify mirror !");
}
}
}
if (isupdatemode ("delete")) {
if ($db->Exec ("delete from mirrors where pk = '$fk_mirrors'")) {
msg ("Mirror deleted !");
} else {
error_msg ("Could not delete mirror !");
}
}
if (isupdate ()) {
if (!isupdatemode ("delete")) {
p ("<a href=\"mirror?mode=edit&fk_mirrors=$fk_mirrors\">" .
"Back to Mirror</a>");
}
} else {
$f->Output ($caption, $caption);
}
p ("<a href=\"mirrors_list\">Back to Mirror List</a>");
pagefooter ();
?>

76
catalog/admin/mirror.php~ Normal file
View File

@ -0,0 +1,76 @@
<?php
include_once ("pgcat.phh");
authenticate ("mirror");
getstr ("mode");
$caption = ucfirst ($mode) . " Mirror";
pageheader ($caption);
include_once ("sqlform.phh");
$db = $config->db ();
$db->logger = new logger ();
$f = new SQLForm ();
getstr ("fk_mirrors");
if (ismode ("delete")) {
$f->SubCaption ("You are about to delete this mirror.");
$f->SubCaption ("Press the '$caption' button to continue or " .
"hit the back button on your browser to dismiss.");
} else {
$f->Text ("continent", "continent", "Continent", SQLCHAR, 80, 80, false);
$f->Text ("nation", "nation", "Nation", SQLCHAR, 80, 80, false);
$f->Text ("location", "location", "Location", SQLCHAR, 80, 80, false);
$f->Text ("provider", "provider", "Provider", SQLCHAR, 80, 240, true);
$f->Text ("url", "url", "URL", SQLCHAR, 80, 240, true);
$f->TextArea ("note", "note", "Note", SQLCHAR, 4, 80, false);
$f->LoadData ("select * from mirrors where pk = '$fk_mirrors'");
}
$f->Hidden ("fk_mirrors");
if (isupdatemode ("add")) {
if ($f->Check ()) {
$sql = $f->mkInsert ($db->GetFormatter ());
if ($db->Exec ("insert into mirrors " . $sql)) {
msg ("Mirror added !");
} else {
error_msg ("Could not add mirror!");
}
}
}
if (isupdatemode ("edit")) {
if ($f->Check ()) {
$sql = $f->mkUpdate ($db->GetFormatter ());
if ($db->Exec ("update mirrors set " . $sql . "where pk = '$fk_mirrors'")) {
msg ("Mirror modified !");
} else {
error_msg ("Could not modify mirror !");
}
}
}
if (isupdatemode ("delete")) {
if ($db->Exec ("delete from mirrors where pk = '$fk_mirrors'")) {
msg ("Mirror deleted !");
} else {
error_msg ("Could not delete mirror !");
}
}
if (isupdate ()) {
if (!isupdatemode ("delete")) {
p ("<a href=\"mirror?mode=edit&fk_mirrors=$fk_mirrors\">" .
"Back to Mirror</a>");
}
} else {
$f->Output ($caption, $caption);
}
p ("<a href=\"mirrors_list\">Back to Mirror List</a>");
pagefooter ();
?>

View File

@ -0,0 +1,33 @@
<?php
set_include_path(get_include_path() . PATH_SEPARATOR . "/public/vhost/g/gutenberg/dev/private/lib/php");
include_once ("pgcat.phh");
authenticate ("mirror");
pageheader ($caption = "Mirrors");
class ListMirrorsTable extends ListTable {
function __construct () {
$prefix = "<a href=\"mirror?mode";
$this->AddColumn ("$prefix=edit&fk_mirrors=#pk#\">Edit</a>",
"$prefix=add\">Add</a>", "narrow");
$this->AddColumn ("$prefix=delete&fk_mirrors=#pk#\">Delete</a>", "", "narrow");
// $this->AddSimpleColumn ("continent", "Continent");
$this->AddSimpleColumn ("nation", "Nation");
$this->AddSimpleColumn ("location", "Location");
$this->AddSimpleColumn ("provider", "Provider");
$this->AddSimpleColumn ("url", "URL");
$this->AddSimpleColumn ("note", "Note");
}
}
$db = $config->db ();
$db->exec ("select * from mirrors order by nation, location, provider;");
$table = new ListMirrorsTable ();
$table->PrintTable ($db, $caption);
pagefooter ();
?>

View File

@ -0,0 +1,32 @@
<?php
include_once ("pgcat.phh");
authenticate ("mirror");
pageheader ($caption = "Mirrors");
class ListMirrorsTable extends ListTable {
function __construct () {
$prefix = "<a href=\"mirror?mode";
$this->AddColumn ("$prefix=edit&fk_mirrors=#pk#\">Edit</a>",
"$prefix=add\">Add</a>", "narrow");
$this->AddColumn ("$prefix=delete&fk_mirrors=#pk#\">Delete</a>", "", "narrow");
// $this->AddSimpleColumn ("continent", "Continent");
$this->AddSimpleColumn ("nation", "Nation");
$this->AddSimpleColumn ("location", "Location");
$this->AddSimpleColumn ("provider", "Provider");
$this->AddSimpleColumn ("url", "URL");
$this->AddSimpleColumn ("note", "Note");
}
}
$db = $config->db ();
$db->exec ("select * from mirrors order by nation, location, provider;");
$table = new ListMirrorsTable ();
$table->PrintTable ($db, $caption);
pagefooter ();
?>

View File

@ -0,0 +1,80 @@
<?php
set_include_path(get_include_path() . PATH_SEPARATOR . "/public/vhost/g/gutenberg/dev/private/lib/php");
include_once ("pgcat.phh");
include_once ("sqlform.phh");
include_once ("mn_relation.phh");
$db = $config->db ();
$db->logger = new logger ();
getint ("fk_books");
getint ("fk_authors");
getstr ("fk_roles");
getint ("heading");
$sql_fk_roles = $db->f ($fk_roles, SQLCHAR);
$caption = MNCaption ("Author", "Book");
$f->KeySelect ("fk_roles", "fk_roles", "Author Role", SQLCHAR, 40, 40, true);
$f->last->LoadSQL ("select pk as key, role as caption from roles order by role");
$f->last->DefValue ("cr");
$f->last->ToolTip ("In which role did this author contribute to the book?");
$f->KeySelect ("heading", "heading", "Heading", SQLINT, 10, 2, true);
$f->last->PushOptions ($titles_heading);
$f->last->DefValue (1);
$f->last->ToolTip ("Should this author generate a user-visible heading?");
$f->LoadData ("select * from mn_books_authors " .
"where fk_books = $fk_books and fk_authors = $fk_authors and fk_roles = $sql_fk_roles");
if (ismode ("delete")) {
$f->SubCaption ("You are about to unlink this book author. " .
"Press the '$caption' button to continue or " .
"hit the back button on your browser to dismiss.");
}
$f->Hidden ("fk_books");
$f->Hidden ("fk_authors");
if (isupdatemode ("add")) {
if ($f->Check ()) {
if ($db->Exec ("insert into mn_books_authors (fk_books, fk_authors, fk_roles, heading) " .
"values ($fk_books, $fk_authors, $sql_fk_roles, $heading)")) {
$msg = "msg=Book author linked !";
} else {
$msg = "errormsg=Could not link book author !";
}
}
}
if (isupdatemode ("edit")) {
if ($f->Check ()) {
if ($db->Exec ("update mn_books_authors " .
"set fk_roles = $sql_fk_roles, heading = $heading " .
"where fk_books = $fk_books and fk_authors = $fk_authors")) {
$msg = "msg=Author link modified !";
} else {
$msg = "errormsg=Could not modify author link !";
}
}
}
if (isupdatemode ("delete")) {
if ($db->Exec ("delete from mn_books_authors " .
"where fk_books = $fk_books and fk_authors = $fk_authors and fk_roles = $sql_fk_roles")) {
$msg = "msg=Book author unlinked !";
} else {
$msg = "errormsg=Could not unlink book author !";
}
}
if (isupdate ()) {
header ("Location: book?mode=edit&fk_books=$fk_books&$msg");
return;
}
pageheader ($caption);
$f->Output ($caption, $caption);
pagefooter ();
?>

Some files were not shown because too many files have changed in this diff Show More