<?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_kw.php (v0.1)
// Role: To add keywords
*/
require("init.php");
require("lib_lddocs.php");
$report = " ";
if($_POST["submit"]) {
$kw = $_POST["keyword"];
$sizekw = count($kw);
for($n=0; $n<$sizekw; $n++) {
if($kw[$n]) { $requests[] = "INSERT INTO ".TB_KW." (keyword) VALUES ('".strtolower($kw[$n])."');"; }
}
$nbreq = count($requests);
$plural = "";
if($nbreq>1) { $plural = "s"; }
for($n=0; $n<$nbreq; $n++) { $result = $cnx->exec($requests[$n]); }
if($result) { $report = "Keyword$plural added."; } else { $report = "No keyword$plural added."; }
}
?><!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Add keywords</title>
<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
ca_kw = letters + digits + "-_ '";
function verif() {
var n,kw,msg,nbkw;
let keywords = document.getElementsByName("keyword[]");
nbkw = 0;
for(n=0; n<keywords.length; n++) {
kw = keywords[n].value;
if(kw) {
nbkw++;
msg = isValidText(kw,ca_kw,2,30);
if(msg != "OK") {
alert(kw + ":\n" + msg);
keywords[n].focus();
return false;
}
}
}
if(nbkw == 0) {
alert("At least one keyword");
keywords[0].focus();
return false;
}
return true;
}
</script>
</head>
<body>
<form method="post" name="addkw" action="<?php $_SERVER["PHP_SELF"]; ?>" onsubmit="return verif();">
<table border="0" width="100%">
<tr>
<td class="cmen">
<?php menu(); ?></td>
<td class="cont">
<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<h1>OPDS: Add keywords</h1>
<p class="report"><?php echo $report; ?></p>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td class="label">Keyword</td>
<td class="value">
<input type="text" name="keyword[]" size="25" tabindex="1"i class="need">
<a class="info" href="#"><img src="<?php echo $info; ?>" border="0" style="vertical-align:top">
<span style="width:9em">Keyword for search</span></a>
</td>
</tr><tr>
<td class="label">Keyword</td>
<td class="value">
<input type="text" name="keyword[]" size="25" tabindex="2" class="opt">
<a class="info" href="#"><img src="<?php echo $info; ?>" border="0" style="vertical-align:top">
<span style="width:9em">Keyword for search</span></a>
</td>
</tr><tr>
<td class="label">Keyword</td>
<td class="value">
<input type="text" name="keyword[]" size="25" tabindex="3" class="opt">
<a class="info" href="#"><img src="<?php echo $info; ?>" border="0" style="vertical-align:top">
<span style="width:9em">Keyword for search</span></a>
</td>
</tr><tr>
<td class="label">Keyword</td>
<td class="value">
<input type="text" name="keyword[]" size="25" tabindex="4" class="opt">
<a class="info" href="#"><img src="<?php echo $info; ?>" border="0" style="vertical-align:top">
<span style="width:9em">Keyword for search</span></a>
</td>
</tr><tr>
<td class="label">Keyword</td>
<td class="value">
<input type="text" name="keyword[]" size="25" tabindex="5" class="opt">
<a class="info" href="#"><img src="<?php echo $info; ?>" border="0" style="vertical-align:top">
<span style="width:9em">Keyword for search</span></a>
</td>
</tr><tr>
<td class="label"></td>
<td class="value"><input type="submit" name="submit" tabindex="6" value="Save"></td>
</tr>
</table>
<p> </p>
<?php
$request = "SELECT keyword FROM ".TB_KW." ORDER BY keyword;";
$result = $cnx->query($request);
if($result->rowCount()>0) {
echo "<div class=\"list\">";
echo "<div class=\"ltitle\">List of existing keywords :</div>";
echo "<select name=\"types\" multiple size=\"$_lines\" class=\"liste\">";
while($r=$result->fetch()) {
echo "<option class=\"active\">$r->keyword</option>";
}
echo "</select>";
echo "</div>";
}
?>
<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
</td>
</tr>
</table>
</form>
<p> </p>
<p> </p>
</body>
</html>
|