PHP Classes

File: gestion/add_doc.php

Recommend this page to a friend!
  Classes of Pierre FAUQUE   OPDS PHP Ebook Publisher Class   gestion/add_doc.php   Download  
File: gestion/add_doc.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: 6,954 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: add_doc.php (v0.1)
// Role: To add documents
*/

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

function
LDactive() {
   
$ld = "<select name=\"active\" tabindex=\"5\" class=\"need\"><option value=\"null\">--Status ?</option>";
   
$ld .= "<option value=\"1\">Displayable</option><option value=\"0\">Hidden</option></select>";
    return
$ld;
}
function
LDsubcat() {
    global
$cnx;
   
$ld = "<select name=\"idscat\" tabindex=\"4\" class=\"need\"><option value=\"null\">--Category ?</option>";
   
$request = "SELECT idscat,scat,cat "
            
. "FROM ".TB_CAT.",".TB_SCAT." "
            
. "WHERE ".TB_SCAT.".idcat=".TB_CAT.".idcat "
            
. "ORDER by cat,scat;";
   
$result = $cnx->query($request);
        if(
$result->rowCount()==0) { return $ld."</select>"; }
        while(
$r=$result->fetch()) {
               
$ld .= "<option value=\"$r->idscat\">$r->cat / $r->scat</option>";
        }
        return
$ld."</select>";
}
if(
$_POST["submit"]) {
   
$title = addslashes($_POST["title"]);
   
$descd = addslashes($_POST["descd"]);
   
$issued = $_POST["issued"];
   
$idscat = $_POST["idscat"];
   
$active = $_POST["active"];
   
$updd = date("Y-m-d H:i:s");
   
$request = "INSERT INTO ".TB_DOCS." (title,descd,issued,idscat,active,updd) VALUES ('$title','$descd','$issued',$idscat,$active,'$updd');";
    try {
       
$result = $cnx->exec($request);
        if(
$result) { $report = "Document added"; }
    } catch(
Exception $e) {
           
$report = showError($e->getCode());
    }
}
?><!DOCTYPE html>
<html>

<head>
<meta charset="utf-8">
<title>Add 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
ca_title = letters + digits + "'- .(),$%?!:";
ca_descd = letters + digits + ",.;:!? -+*/'_@=\n\"()[]$?#?";
ca_issued = letters + digits + " .-/";
// idscat, active : selection tested, not the value (because of value of a select input)

function verif() {

    var msg;

    var title = document.adddoc.title.value;
    var descd = document.adddoc.descd.value;
    var issued = document.adddoc.issued.value;
    var idscat = document.adddoc.idscat.options[document.adddoc.idscat.options.selectedIndex].value;
    var active = document.adddoc.active.options[document.adddoc.active.options.selectedIndex].value;

    if(!title) {
        alert("Missing title");
        document.adddoc.title.focus();
        return false;
    }
    msg = isValidText(title,ca_title,1,60);
    if(msg != "OK") {
        alert("Title:\n"+msg);
        document.adddoc.title.focus();
        return false;
    }

    if(!descd) {
        alert("Missing description");
        document.adddoc.descd.focus();
        return false;
    }
    msg = isValidText(descd,ca_descd,5,5000);
    if(msg != "OK") {
        alert("Document description:\n"+msg);
        document.adddoc.descd.focus();
        return false;
    }

    if(issued) {
        msg = isValidText(issued,ca_issued,4,10);
        if(msg != "OK") {
            alert("Date of issue:\n"+msg);
            document.adddoc.issued.focus();
            return false;
        }
    }

    if(idscat == 'null') {
        alert("In which category you classify this ebook ?");
        document.adddoc.idscat.focus();
        return false;
    }

    if(active == 'null') {
        alert("Should this ebook be hidden or displayed ?");
        document.adddoc.active.focus();
        return false;
    }

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

<body>
<form method="post" name="adddoc" 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 document</h1>
<p class="report"><?php echo $report; ?></p>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
  <td class="label">Document title</td>
  <td class="value">
    <input type="text" name="title" size="55" tabindex="1" class="need"> &nbsp;
    <a class="info" href="#"><img src="<?php echo $info; ?>" border="0" style="vertical-align:top">
    <span style="width:10em">Title of the document</span></a>
  </td>
</tr><tr>
  <td class="label">Document description</td>
  <td class="value">
    <textarea name="descd" cols="60" rows="5" tabindex="2" class="need"></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 content of this document</span></a>
  </td>
</tr><tr>
  <td class="label">Date of issue</td>
  <td class="value">
    <input type="text" name="issued" size="10" tabindex="3" class="opt"> &nbsp;
    <a class="info" href="#"><img src="<?php echo $info; ?>" border="0" style="vertical-align:top">
    <span style="width:13em">Year/date of the document<br/>Written as text 10 chars max.<br/>Year only recommanded.</span></a>
  </td>
</tr><tr>
  <td class="label">Category of the document</td>
  <td class="value">
    <?php echo LDsubcat(); ?> &nbsp;
    <a class="info" href="#"><img src="<?php echo $info; ?>" border="0" style="vertical-align:top">
    <span style="width:17em">Select the category of the document</span></a>
  </td>
</tr><tr>
  <td class="label">Status of document</td>
  <td class="value">
    <?php echo LDactive(); ?> &nbsp;
    <a class="info" href="#"><img src="<?php echo $info; ?>" border="0" style="vertical-align:top">
    <span style="width:11em">Select if the document is displayable or hidden</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>&nbsp;</p>
<?php
$request
= "SELECT title,issued,active FROM ".TB_DOCS." ORDER BY title,issued;";
$result = $cnx->query($request);
if(
$result->rowCount()>0) {
        echo
"<div class=\"list\">";
        echo
"<div class=\"ltitle\">List of existing documents :</div>";
        echo
"<select name=\"categories\" multiple size=\"$_lines\" class=\"liste\">";
        while(
$r=$result->fetch()) {
        if(
$r->issued) { $issued = "($r->issued)"; } else { $issued = ""; }
                if(
$r->active) { $class="active"; } else { $class="inactive"; }
                echo
"<option class=\"$class\">$r->title $issued</option>";
        }
} echo
"</select>";
        echo
"</div>";
?>
<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
</td>
</tr>
</table>
</form>
<p>&nbsp;</p>
<p>&nbsp;</p>
</body>

</html>