PHP Classes

File: gestion/rel_pubdoc.php

Recommend this page to a friend!
  Classes of Pierre FAUQUE   OPDS PHP Ebook Publisher Class   gestion/rel_pubdoc.php   Download  
File: gestion/rel_pubdoc.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: 3 years ago
Size: 7,872 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_pubdoc.php (v0.1)
// Role: Add a relation (a document is published into a language and a format of ebook)
*/

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
LDtype() {
    global
$cnx;
   
$ld = "<select name=\"idtype\" tabindex=\"2\" class=\"need\"><option value=\"null\">--Type ?</option>";
   
$request = "SELECT * FROM ".TB_TYP." ORDER BY type,format;";
   
$result = $cnx->query($request);
    if(
$result->rowCount()==0) { return $ld."</select>"; }
        while(
$r=$result->fetch()) {
               
$ld .= "<option value=\"$r->idtype\">$r->type / $r->format</option>";
        }
        return
$ld."</select>";
}
if(
$_POST["submit"]) {
   
$iddoc= addslashes($_POST["iddoc"]);
   
$idtype = $_POST["idtype"];
   
$lang = $_POST["lang"];
   
$filename = addslashes($_POST["filename"]);
   
$thumb = $_POST["thumb"];
   
$descpe = addslashes($_POST["descpe"]);
   
$updpe = date("Y-m-d H:i:s");
   
$request = "INSERT INTO ".TB_PUB." VALUES ('$iddoc','$idtype','$lang','$filename','$thumb','$descpe','$updpe');";
    try {
       
$result = $cnx->exec($request);
        if(
$result) { $report = "This document has been added in the ebookstore."; }
    } catch(
Exception $e) {
       
$report = showError($e->getCode());
    }
}
?><!DOCTYPE html>
<html>

<head>
<meta charset="utf-8">
<title>Publish a document</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
// iddoc, idtype : selection tested, not the value (because of value of a select input)
ca_lang = ascii;
ca_filename = ascii + digits + "-_!.'";
ca_thumb = ascii + digits + "-_!.";
ca_descpe = letters + digits + ",.;:!? -+*/'_@=\n\"()[]$?#?";

function verif() {

    var msg;

    var iddoc = document.pubdoc.iddoc.options[document.pubdoc.iddoc.selectedIndex].value;
    var idtype = document.pubdoc.idtype.options[document.pubdoc.idtype.selectedIndex].value;
    var lang = document.pubdoc.lang.value;
    var filename = document.pubdoc.filename.value;
    var thumb = document.pubdoc.thumb.value;
    var descpe = document.pubdoc.descpe.value;

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

    if(idtype == "null") {
        alert("Missing type of document");
        document.pubdoc.idtype.focus();
        return false;
    }

    if(lang) {
        msg = isValidText(lang,ca_lang,2,2);
        if(msg != "OK") {
            alert("Language:\n"+msg);
            document.pubdoc.lang.focus();
            return false;
        }
    }

    if(!filename) {
        alert("Missing filename");
        document.pubdoc.filename.focus();
        return false;
    }
    msg = isValidText(filename,ca_filename,5,90);
    if(msg != "OK") {
        alert("Filename:\n"+msg);
        document.pubdoc.filename.focus();
        return false;
    }

    if(!thumb) {
        alert("Missing thumbnail");
        document.pubdoc.thumb.focus();
        return false;
    }
    msg = isValidText(thumb,ca_thumb,5,30);
    if(msg != "OK") {
        alert("Thumbnail:\n"+msg);
        document.pubdoc.thumb.focus();
        return false;
    }

    if(descpe) {
        msg = isValidText(descpe,ca_descpe,3,5000);
        if(msg != "OK") {
            alert("Publication description:\n"+msg);
            document.pubdoc.descpe.focus();
            return false;
        }
    }

    return true;
}

</script>
</head>

<body>
<form method="post" name="pubdoc" 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: Publish a 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(); ?> &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">Type of the document</td>
  <td class="value">
    <?php echo LDtype(); ?> &nbsp;
    <a class="info" href="#"><img src="<?php echo $info; ?>" border="0" style="vertical-align:top">
    <span style="width:15em">Select the Type of the document.</span></a>
  </td>
</tr><tr>
  <td class="label">Language</td>
  <td class="value">
    <input type="text" name="lang" size="5" tabindex="3" class="opt"> &nbsp;
    <a class="info" href="#"><img src="<?php echo $info; ?>" border="0" style="vertical-align:top">
    <span style="width:13em">Country. Use the two letters of the top level domain of the country. Ex.: br, en, fr, it, ...</span></a>
  </td>
</tr><tr>
  <td class="label">Filename</td>
  <td class="value">
    <input type="text" name="filename" size="60" tabindex="4" class="need"> &nbsp;
    <a class="info" href="#"><img src="<?php echo $info; ?>" border="0" style="vertical-align:top">
    <span style="width:13em">Filename of the ebook in the ebooks directory.</span></a>
  </td>
</tr><tr>
  <td class="label">Thumbnail</td>
  <td class="value">
    <input type="text" name="thumb" size="35" tabindex="5" class="need"> &nbsp;
    <a class="info" href="#"><img src="<?php echo $info; ?>" border="0" style="vertical-align:top">
    <span style="width:13em">Filename of the thumbnail (image of the ebook).<br/>*.jpg *.png *.gif<br/>Dim. : about 600 x 800 px</span></a>
  </td>
</tr><tr>
  <td class="label">Publication description</td>
  <td class="value">
    <textarea name="descpe" cols="60" rows="5" tabindex="6" class="opt"></textarea> &nbsp;
    <a class="info" href="#"><img src="<?php echo $info; ?>" border="0" style="vertical-align:top">
    <span style="top:-4em; width:13em">Description and summary of the publication.</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>&nbsp;</p>
<?php
$request
= "SELECT title,type "
        
. "FROM ".TB_DOCS.",".TB_TYP.",".TB_PUB." "
        
. "WHERE ".TB_PUB.".iddoc=".TB_DOCS.".iddoc "
        
. "AND ".TB_PUB.".idtype=".TB_TYP.".idtype "
        
. "ORDER BY title,type;";
$result = $cnx->query($request);
if(
$result->rowCount()>0) {
    echo
"<div class=\"list\">";
    echo
"<div class=\"ltitle\">List of published ebooks :</div>";
    echo
"<select name=\"types\" multiple size=\"$_lines\" class=\"liste\">";
    while(
$r=$result->fetch()) {
        echo
"<option class=\"active\">$r->title ($r->type)</option>";
    }
    echo
"</select>";
    echo
"</div>";
}
?>
<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
</td>
</tr>
</table>
</form>
<p>&nbsp;</p>
<p>&nbsp;</p>
</body>

</html>