<?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: add_auth.php (v0.1)
// Role: To add authors
*/
require("init.php");
require("lib_lddocs.php");
$report = " ";
function capitalize($fname) {
if(strpos($fname," ")) {
$tfn = explode(" ",$fname);
$nbfn = count($tfn); $fname = ucfirst($tfn[0]);
for($n=1; $n<$nbfn; $n++) { $fname .= " ".ucfirst($tfn[$n]); }
}
if(strpos($fname,"-")) {
$tfn = explode("-",$fname);
$nbfn = count($tfn); $fname = ucfirst($tfn[0]);
for($n=1; $n<$nbfn; $n++) { $fname .= "-".ucfirst($tfn[$n]); }
}
return ucfirst($fname);
}
if($_POST["submit"]) {
$lname = addslashes(strtoupper($_POST["lname"]));
$fname = addslashes(capitalize($_POST["fname"]));
$bdate = $_POST["bdate"];
$ddate = $_POST["ddate"];
$uri = $_POST["uri"];
if(!(strstr($uri,'http://') || strstr($uri,'https://'))) {
$uri = $CFG["rootsite"].$CFG["rootopds"]."/".$CFG["authdir"]."/$uri";
}
$bio = addslashes($_POST["bio"]);
$upda = date("Y-m-d H:i:s");
$request = "INSERT INTO ".TB_AUT." (lname,fname,bdate,ddate,uri,bio,upda) VALUES ('$lname','$fname','$bdate','$ddate','$uri','$bio','$upda');";
try {
$result = $cnx->exec($request);
if($result) { $report = "Author added"; }
} catch(Exception $e) {
$report = showError($e->getCode());
}
}
?><!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="opds.css" type="text/css" />
<title>Add author</title>
<script type="text/javascript" src="functions.js"></script>
<script language="javascript" type="text/javascript">
// Lists of the classic (c)haracters (a)uthorized (ca_ *) in the various input fields
ca_lname = letters + "- '";
ca_fname = letters + "- '";
ca_bdate = digits + "-";
ca_ddate = digits + "-";
ca_uri = ascii + digits + "_-:/.?=%+";
ca_bio = letters + digits + ",.;:!? -+*/'_@=\n\"()[]$?#?";
function verif() {
var msg;
var lname = document.addauth.lname.value;
var fname = document.addauth.fname.value;
var bdate = document.addauth.bdate.value;
var ddate = document.addauth.ddate.value;
var uri = document.addauth.uri.value;
var bio = document.addauth.bio.value;
// Need Last name
if(!lname) {
alert("Missing Last name");
document.addauth.lname.focus();
return false;
}
msg = isValidText(lname,ca_lname,3,30);
if(msg != "OK") {
alert("Last name:\n"+msg);
document.addauth.lname.focus();
return false;
}
document.addauth.lname.value = noaccent(lname); // No accent to capitalize.
// Verif first name if provided
if(fname) {
msg = isValidText(fname,ca_fname,3,30);
if(msg != "OK") {
alert("First name:\n"+msg);
document.addauth.fname.focus();
return false;
}
}
if(bdate) {
msg = isValidDate(bdate);
if(msg != "OK") {
alert("Birthdate:\n"+msg);
document.addauth.bdate.focus();
return false;
}
}
if(ddate) {
msg = isValidDate(ddate);
if(msg != "OK") {
alert("Deathdate:\n"+msg);
document.addauth.ddate.focus();
return false;
}
}
if(uri) {
msg = isValidText(uri,ca_uri,3,80);
if(msg != "OK") {
alert("URL of author:\n"+msg);
document.addauth.uri.focus();
return false;
}
}
if(bio) {
msg = isValidText(bio,ca_bio,3,5000);
if(msg != "OK") {
alert("Biography of author:\n"+msg);
document.addauth.bio.focus();
return false;
}
}
return true;
}
</script>
</head>
<body>
<form method="post" name="addauth" action="<?php echo $_SERVER["PHP_SELF"]; ?>" onsubmit="return verif();">
<table border="0" width="100%">
<tr>
<td class="cmen">
<?php menu(); ?></td>
<td class="cont">
<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<h1>OPDS: Add Author</h1>
<p class="report"><?php echo $report; ?></p>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td class="label">Last name</td>
<td class="value">
<input type="text" name="lname" size="30" tabindex="1" class="need">
<a class="info" href="#"><img src="<?php echo $info; ?>" border="0" style="vertical-align:top">
<span style="width:11em">Last name of an author<br/>No accents because it<br/>will be capitalized.</span></a>
</td>
</tr><tr>
<td class="label">First name</td>
<td class="value">
<input type="text" name="fname" size="30" tabindex="2" class="opt">
<a class="info" href="#"><img src="<?php echo $info; ?>" border="0" style="vertical-align:top">
<span style="width:11em">First name of an author</span></a>
</td>
</tr><tr>
<td class="label">Date of birth</td>
<td class="value">
<input type="text" name="bdate" size="10" tabindex="3" class="opt">
<a class="info" href="#"><img src="<?php echo $info; ?>" border="0" style="vertical-align:top">
<span style="width:11em">His/her birthdate</br/>Format = YYYY-MM-DD<br/>year = 0000 if unknown<br/>month = 00 if unknown<br/>day = 00 if unknown<br/>empty or 0000-00-00</span></a>
</td>
</tr><tr>
<td class="label">Date of death</td>
<td class="value">
<input type="text" name="ddate" size="10" tabindex="4" class="opt">
<a class="info" href="#"><img src="<?php echo $info; ?>" border="0" style="vertical-align:top">
<span style="width:11em">His/her deathdate</br/>Format = YYYY-MM-DD<br/>year = 0000 if unknown<br/>month = 00 if unknown<br/>day = 00 if unknown<br/>empty or 0000-00-00</span></a>
</td>
</tr><tr>
<td class="label">URL page</td>
<td class="value">
<input type="text" name="uri" size="45" tabindex="5" class="opt">
<a class="info" href="#"><img src="<?php echo $info; ?>" border="0" style="vertical-align:top">
<span style="width:22em">URL of his website or a webpage about him/her</span></a>
</td>
</tr><tr>
<td class="label">Brief biography</td>
<td class="value">
<textarea name="bio" cols="60" rows="5" tabindex="6" class="opt"></textarea>
<a class="info" href="#"><img src="<?php echo $info; ?>" border="0" style="vertical-align:top">
<span style="top:-4em; width:16em">A brief biography about this author</span></a>
</td>
</tr><tr>
<td class="label"></td>
<td class="value"><input type="submit" name="submit" tabindex="7" value="Save"></td>
</tr>
</table>
<p> </p>
<?php
$request = "SELECT lname,fname FROM ".TB_AUT." ORDER BY lname,fname;";
$result = $cnx->query($request);
if($result->rowCount()>0) {
echo "<div class=\"list\">";
echo "<div class=\"ltitle\">List of existing authors :</div>";
echo "<select name=\"authors\" multiple size=\"$_lines\" class=\"liste\">";
while($r=$result->fetch()) {
echo "<option class=\"active\">$r->lname $r->fname</option>";
}
} echo "</select>";
echo "</div>";
?>
<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
</td>
</tr>
</table>
</form>
<p> </p>
<p> </p>
</body>
</html>
|