File: gestion/rel_dockw.php

Recommend this page to a friend!
  Classes of Pierre FAUQUE  >  OPDS PHP Ebook Publisher Class  >  gestion/rel_dockw.php  >  Download  
File: gestion/rel_dockw.php
Role: Application script
Content type: text/plain
Description: Script of application
Class: OPDS PHP Ebook Publisher Class
Publish and distribute ebooks for download
Author: By
Last change:
Date: 4 months ago
Size: 5,199 bytes
 

Contents

Class file image Download
<?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_dockw.php (v0.1)
// Role: Add a relation (a document has keywords)
*/

require("init.php");
require(
"lib_lddocs.php");
$report = "&nbsp;";

function
LDdoc($idsel="") {
        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->iddoc==$idsel) { $sel = " selected"; } else { $sel = ""; }
                if(
$r->issued) { $issued = " ($r->issued)"; }
               
$ld .= "<option value=\"$r->iddoc\"$sel>$r->title$issued</option>";
        }
        return
$ld."</select>";
}
function
LDkw() {
    global
$cnx,$_lines;
   
$ld = "<select name=\"kw[]\" tabindex=\"2\" multiple size=\"".($_lines+5)."\" class=\"need\">";
   
$request = "SELECT * FROM ".TB_KW." ORDER BY keyword;";
   
$result = $cnx->query($request);
    if(
$result->rowCount()==0) { return $ld."</select>"; }
        while(
$r=$result->fetch()) {
                  
$ld .= "<option value=\"$r->idkw\">$r->keyword</option>";
        }
        return
$ld."</select>";
}
if(
$_POST["submit"]) {
   
$iddoc = $_POST["iddoc"];
   
$kws = $_POST["kw"];
   
$nbkw = count($kws);
    if(
$nbkw == 0) {
       
$report = "No keyword added for this document."; }
    else {
        if(
$nbkw>1) { $plural = "s"; }
        for(
$n=0; $n<$nbkw; $n++) {
           
$requests[] = "INSERT INTO ".TB_CLAS." VALUES ('$iddoc','".$kws[$n]."');";
        }
        for(
$n=0; $n<$nbkw; $n++) {
           
$result = $cnx->exec($requests[$n]);
        }
        if(
$result) { $report = "Keyword$plural added for this document."; }
        else {
$report = "No keyword added for this document."; }
       
$iddoc = 0;
    }
}
?><!DOCTYPE html>
<html>

<head>
<meta charset="utf-8">
<title>Document has 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

function verif() {

    var n, choix;
    var iddoc = document.dockw.iddoc.value;
    let idkws = document.getElementsByName("kw[]");

    if(iddoc == "null") {
        alert("Missing document");
        document.dockw.iddoc.focus();
        return false;
    }

    choix = 0;
    for(n=0; n<idkws.length; n++) {
        if(idkws[n].value) { choix++; }
    }
    if(!choix) {
        alert("At least one keyword for this document");
        return false;
    }

    return true;
}
</script>
</head>

<body>
<form method="post" name="dockw" 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: Document has keywords</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($iddoc); ?> &nbsp;
    <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">Keywords</td>
  <td class="value">
    <?php echo LDkw(); ?> &nbsp;
    <a class="info" href="#"><img src="<?php echo $info; ?>" border="0" style="vertical-align:top">
    <span style="top:-12em; width:15em">Ctrl-Clic on each keyword to select several for 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>&nbsp;</p>
<?php
$request
= "SELECT title,keyword "
        
. "FROM ".TB_DOCS.",".TB_KW.",".TB_CLAS." "
        
. "WHERE ".TB_CLAS.".iddoc=".TB_DOCS.".iddoc "
        
. "AND ".TB_CLAS.".idkw=".TB_KW.".idkw "
        
. "ORDER BY title,keyword;";
$result = $cnx->query($request);
if(
$result->rowCount()>0) {
    echo
"<div class=\"list\">";
    echo
"<div class=\"ltitle\">List of books's keywords :</div>";
    echo
"<select name=\"types\" multiple size=\"$_lines\" class=\"liste\">";
   
$r = $result->fetch();
   
$title = $r->title;
   
$kws = $r->keyword;
    while(
$r=$result->fetch()) {
        if(
$r->title == $title) {
           
$kws .= ", $r->keyword"; }
        else {
            echo
"<option class=\"active\">$title : $kws</option>";
           
$title = $r->title;
           
$kws = $r->keyword;
        }
    }
    echo
"<option class=\"active\">$title : $kws</option>";
    echo
"</select>";
    echo
"</div>";
}
?>
<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
</td>
</tr>
</table>
</form>
<p>&nbsp;</p>
<p>&nbsp;</p>
</body>

</html>


For more information send a message to info at phpclasses dot org.