PHP Classes

File: gestion/add_type.php

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

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

if(
$_POST["submit"]) {
   
$type = strtoupper($_POST["type"]);
   
$format = $_POST["format"];
   
$request = "INSERT INTO ".TB_TYP." (type,format) VALUES ('$type','$format');";
    try {
       
$result = $cnx->exec($request);
        if(
$result) { $report = "Type added."; }
    } catch(
Exception $e) {
       
$report = showError($e->getCode());
    }
}
?><!DOCTYPE html>
<html>

<head>
<meta charset="utf-8">
<title>Add type of 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_type = ascii;
ca_format = ascii + digits + "-_+.";

function verif() {

    var msg;

    var type = document.addtype.type.value;
    var format = document.addtype.format.value;

        // Need Type of ebook
    if(!type) {
        alert("Missing type of ebook");
        document.addtype.type.focus();
        return false;
    }
    msg = isValidText(type,ca_type,3,15);
    if(msg != "OK") {
        alert("Type of ebook:\n"+msg);
        document.addtype.type.focus();
        return false;
    }

        // Need MIME format
        if(!format) {
                alert("Missing MIME format");
                document.addtype.format.focus();
                return false;
        }
        msg = isValidText(format,ca_format,3,20);
        if(msg != "OK") {
                alert("MIME format:\n"+msg);
                document.addtype.format.focus();
                return false;
        }

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

<body>
<form method="post" name="addtype" 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 type of document</h1>
<p><?php echo $report; ?></p>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
  <td class="label">Type</td>
  <td class="value">
    <input type="text" name="type" size="15" tabindex="1" class="need"> &nbsp;
    <a class="info" href="#"><img src="<?php echo $info; ?>" border="0" style="vertical-align:top">
    <span style="width:13em">Type of ebook :<br/>Examples: EPUB, MOBI, etc.</span></a>
  </td>
</tr><tr>
  <td class="label">MIME format</td>
  <td class="value">
    <input type="text" name="format" size="20" tabindex="2" class="need"> &nbsp;
    <a class="info" href="#"><img src="<?php echo $info; ?>" border="0" style="vertical-align:top">
    <span style="width:13em">MIME format of ebook :<br/>- epub+zip<br/>- x-mobipocket-ebook<br/>- pdf</br/>- etc.</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 type,format FROM ".TB_TYP." ORDER BY type,format;";
$result = $cnx->query($request);
if(
$result->rowCount()>0) {
        echo
"<div class=\"list\">";
        echo
"<div class=\"ltitle\">List of existing types :</div>";
        echo
"<select name=\"types\" multiple size=\"$_lines\" class=\"liste\">";
        while(
$r=$result->fetch()) {
                echo
"<option class=\"active\">$r->type / $r->format</option>";
        }
    echo
"</select>";
    echo
"</div>";
}
?>
<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
</td>
</tr>
</table>
</form>
<p>&nbsp;</p>
<p>&nbsp;</p>
</body>
</html>