<?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: rel_authdoc.php (v0.1)
// Role: Add a relation (an author writes a document)
*/
require("init.php");
require("lib_lddocs.php");
$report = " ";
function LDdoc() {
global $cnx;
$ld = "<select name=\"iddoc\" tabindex=\"1\" class=\"need\"><option value=\"null\">--Document ?</option>";
$request = "SELECT iddoc,title,issued FROM ".TB_DOCS." ORDER BY title;";
$result = $cnx->query($request);
if($result->rowCount()==0) { return $ld."</select>"; }
while($r=$result->fetch()) {
if($r->issued) { $issued = " ($r->issued)"; }
$ld .= "<option value=\"$r->iddoc\">$r->title$issued</option>";
}
return $ld."</select>";
}
function LDaut() {
global $cnx;
$ld = "<select name=\"idaut\" tabindex=\"2\" class=\"need\"><option value=\"null\">--Author ?</option>";
$request = "SELECT idaut,lname,fname FROM ".TB_AUT." ORDER by lname,fname;";
$result = $cnx->query($request);
if($result->rowCount()==0) { return $ld."</select>"; }
while($r=$result->fetch()) {
$ld .= "<option value=\"$r->idaut\">".trim("$r->lname $r->fname")."</option>";
}
return $ld."</select>";
}
if($_POST["submit"]) {
$iddoc = $_POST["iddoc"];
$idaut = $_POST["idaut"];
$request = "INSERT INTO ".TB_WRIT." VALUES ($iddoc,$idaut);";
try {
$result = $cnx->exec($request);
if($result) {
$request = "SELECT lname,fname,title,issued "
. "FROM ".TB_DOCS.",".TB_AUT.",".TB_WRIT." "
. "WHERE ".TB_DOCS.".iddoc=".TB_WRIT.".iddoc "
. "AND ".TB_AUT.".idaut=".TB_WRIT.".idaut "
. "AND ".TB_DOCS.".iddoc=$iddoc;";
$result = $cnx->query($request);
$r=$result->fetch();
if($r->issued) { $issued = " in $r->issued"; }
$report = "$r->title has been written by ".trim ("$r->fname $r->lname").$issued;
}
} catch(Exception $e) {
$report = showError($e->getCode());
}
}
?><!DOCTYPE html>
<html>
<head>
<title>Author writes a document</title>
<meta charset="utf-8">
<link rel="stylesheet" href="opds.css" type="text/css" />
<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
// iddoc, idaut : selection tested, not the value (because of value of a select input)
function verif() {
var iddoc = document.autdoc.iddoc.options[document.autdoc.iddoc.selectedIndex].value;
var idaut = document.autdoc.idaut.options[document.autdoc.idaut.selectedIndex].value;
if(iddoc == 'null') {
alert("Missing document");
document.autdoc.iddoc.focus();
return false;
}
if(idaut == 'null') {
alert("Who wrote this document ?");
document.autdoc.idaut.focus();
return false;
}
return true;
}
</script>
</head>
<body>
<form method="post" name="autdoc" 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: Author writes document</h1>
<p class="report"><?php echo $report; ?></p>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td class="label">Document</td>
<td class="value">
<?php echo LDdoc(); ?>
<a class="info" href="#"><img src="<?php echo $info; ?>" border="0" style="vertical-align:top">
<span style="width:10em">Select the document.</span></a>
</td>
</tr><tr>
<td class="label">Author</td>
<td class="value">
<?php echo LDaut(); ?>
<a class="info" href="#"><img src="<?php echo $info; ?>" border="0" style="vertical-align:top">
<span style="width:15em">Select the author of this document.</span></a>
</td>
</tr><tr>
<td class="label"></td>
<td class="value"><input type="submit" name="submit" tabindex="3" value="Save"></td>
</tr>
</table>
<p> </p>
<?php
$request = "SELECT title,fname,lname "
. "FROM ".TB_DOCS.",".TB_AUT.",".TB_WRIT." "
. "WHERE ".TB_WRIT.".iddoc=".TB_DOCS.".iddoc "
. "AND ".TB_WRIT.".idaut=".TB_AUT.".idaut "
. "ORDER BY fname,lname,title;";
$result = $cnx->query($request);
if($result->rowCount()>0) {
echo "<div class=\"list\">";
echo "<div class=\"ltitle\">List of author's books :</div>";
echo "<select name=\"types\" multiple size=\"$_lines\" class=\"liste\">";
while($r=$result->fetch()) {
echo "<option class=\"active\">".trim($r->fname." ".$r->lname)." : $r->title</option>";
}
echo "</select>";
echo "</div>";
}
?>
<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
</td>
</tr>
</table>
</form>
<p> </p>
<p> </p>
</body>
</html>
|