<?php
/*
// OPDS basic gestion (only add entities and relations, not modify)
// Version: 0.1
// Pierre FAUQUE, <pierre@fauque.net>
// Script: 2014, Script->Class: 2019, Gestion: may 2020
// Encoding: UTF-8
// Text editor: GNU/Linux Debian Vi
// File: init.php (v0.1)
// Role: initialisation script for a page (connection to the database, menu, etc.)
*/
// --- Table names. Can be changed here, not in the script
define("TB_AUT", "opds_Authors"); // Table of authors of documents
define("TB_CAT", "opds_Categories"); // Table of categories of documents
define("TB_CFG", "opds_Config"); // Table of configuration
define("TB_DOCS", "opds_Documents"); // Table of available documents
define("TB_KW", "opds_Keywords"); // Table of keywords
define("TB_PUB", "opds_PublishedIn"); // Table of published documents in ebook
define("TB_CLAS", "opds_References"); // Table of classifications of documents
define("TB_SCAT", "opds_SCategories"); // Table of subcategories
define("TB_TYP", "opds_Types"); // Table of types of ebooks
define("TB_WRIT", "opds_Write"); // Table of identified creation (who writes what ?)
// ---------- For connection to the database
// define("DBTYPE", "pgsql");
// define("PORT", "port=5432");
define("DBTYPE", "mysql"); // Type of database
define("PORT", "port=3306"); // Port of the database server
define("SERVER", "host=000.000.00.00"); // IP number or FQDN
define("BASE", "dbname=opds"); // Database name
define("USER", "login"); // Database user
define("PASS", "password"); // Database access password
define("DSN", DBTYPE.":".PORT.";".SERVER.";".BASE);
try {
// Connection to the server
$cnx = new PDO(
DSN, USER, PASS,
array (
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_OBJ,
PDO::ATTR_TIMEOUT => 2
)
);
}
catch(PDOException $e) {
echo showError($e->getCode())."\n";
die();
}
$colm = 200; // Width of the column menu
$_lines = 10; // Number of lines in a list in the end of a page under the input form.
// Get the configuration
$request = "SELECT * FROM ".TB_CFG.";";
$result = $cnx->query($request);
while($c = $result->fetch()) { ${$c->key} = $c->value; }
// Display the error message
function showError($err) {
switch($err) {
case 0 : return "Database driver not installed"; break;
case 1044 : return "Database not reachable"; break;
case 1045 : return "Unidentified user"; break;
case 2002 : return "Connection refused"; break;
case 2003 : return "DB Server not reachable"; break;
case 23000 : return "Not added. Already in the database"; break;
default : return "Unknown error ($e)"; break;
}
}
// Write the menu
function menu() {
$hf=fopen("menu.txt","r");
while($line=trim(chop(fgets($hf,128)))) {
$char0 = $line[0];
switch($char0) {
case ';' : break; // Comment
case '#' : break; // Comment
case '-' : echo "<hr size='1' noshade>\n"; break; // Line
case '<' : echo $line."\n"; break; // Title
case '@' : $fn = substr($line,1); // Functions
switch($fn) {
case 'LDdocs': echo LDdocs(); break;
}
break;
default : $tm = explode(";",$line); // Item of menu
echo "<div class=\"m\"><a href=\"".$tm[1]."\">".$tm[0]."</a></div>\n";
break;
}
}
fclose($hf);
echo "<br/>";
// Last update of the page
$sna = explode("/",$_SERVER["PHP_SELF"]); // Script Name Array
$me = $sna[count($sna)-1];
$stat = stat($me);
echo "<div class=\"upd\">";
echo "Last page update :<br/>".date("r",$stat["mtime"]);
echo "</div>";
}
// logo: i.jpg (information)
// $hf = fopen("i.jpg", "r");
// $c = fread($hf,2048);
// fclose($hf);
// echo chunk_split(base64_encode($c)); // Copy/Paste...
$info = "data:image/jpg;base64,/9j/4AAQSkZJRgABAQEASABIAAD/2wBDAAUDBAQEAwUEB
AQFBQUGBwwIBwcHBw8LCwkMEQ8SEhEPERETFhwXExQaFRERGCEYGh0dHx8fExciJCIeJBweHx7/2
wBDAQUFBQcGBw4ICA4eFBEUHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eH
h4eHh4eHh4eHh7/wAARCAAUABQDASIAAhEBAxEB/8QAFwABAQEBAAAAAAAAAAAAAAAAAAYHCP/EA
CoQAAEDAwMDAwQDAAAAAAAAAAECAwQFBhEABxITIWEUMUEIFSJxUXKC/8QAFwEAAwEAAAAAAAAAA
AAAAAAAAwUGB//EACIRAAEDBAICAwAAAAAAAAAAAAIBAwQAETFhFCESgVFxsf/aAAwDAQACEQMRA
D8Au9yNx6jc15zbWpFQehU6M4qOj07hQuW4DxOVDvxzkADsR3PiQ3Bq1ds+r0Z2i0qq2pIbigOrX
LUsTVpIyspJII/YOc+NQ970uZQ72qlLkhaZLEtYH8rBVlKh/YEEfvV79TtQR9us1I5FxqkpbXkey
8IyD51aA00wTQCieJIv5nd91nxuvyBecJVQxVPXeNW17rdNntz6feNltVKpvxoVQZdVGlNlXFKnE
gHknPwQoHwcj401hOxO2lZuSyV1dMn0bL0xzpBZI6iQlIKh45BQ/wAnTU9Ijx0dJEK3eKqo0mUTI
qoX6z81uW7W3luXbCNUntyItTgtlbE6G703k8e4BOCCM9xkZHwRrH9rttqRdtbfZuOq12pRoiuoI
703KHCDj8u2fk+xB000aKRcclvjGqBNAeUKWznf3XTECHFgQmYUKO3HjMIDbTTaeKUJAwAAPYaaa
aUZp2nVf//Z";
?>
|