File: gestion/add_cat.php

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

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

function
LDactive() {
       
$ld = "<select name=\"active\" tabindex=\"3\" class=\"need\"><option value=\"null\">--Status ?</option>";
       
$ld .= "<option value=\"1\">Displayable</option><option value=\"0\">Hidden</option></select>";
        return
$ld;
}
if(
$_POST["submit"]) {
   
$cat = $_POST["cat"];
   
$descc = addslashes($_POST["descc"]);
   
$active = addslashes($_POST["active"]);
   
$updc = date("Y-m-d H:i:s");
   
$request = "INSERT INTO ".TB_CAT." (cat,descc,active,updc) values ('$cat','$descc',$active,'$updc');";
    try {
       
$result = $cnx->exec($request);
        if(
$result) { $report = "Category added."; }
    } catch(
Exception $e) {
       
$report = showError($e->getCode());
    }
}
?><!DOCTYPE html>
<html>

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

function verif() {

    var msg;

    var cat = document.addcat.cat.value;
    var descc = document.addcat.descc.value;
    var active = document.addcat.active.options[document.addcat.active.selectedIndex].value;

    if(!cat) {
        alert("Missing category");
        document.addcat.cat.focus();
        return false;
    }
    msg = isValidText(cat,ca_cat,3,30);
    if(msg != "OK") {
        alert("Category:\n" + msg);
        document.addcat.cat.focus();
        return false;
    }

    if(!descc) {
        alert("Missing description");
        document.addcat.descc.focus();
        return false;
    }
    msg = isValidText(descc,ca_descc,3,5000);
    if(msg != "OK") {
        alert("Category Description:\n" + msg);
        document.addcat.descc.focus();
        return false;
    }

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

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

<body>
<form method="post" name="addcat" 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 Category</h1>
<p class="report"><?php echo $report; ?></p>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
  <td class="label">Category</td>
  <td class="value">
    <input type="text" name="cat" size="30" tabindex="1" class="need"> &nbsp;
    <a class="info" href="#"><img src="<?php echo $info; ?>" border="0" style="vertical-align:top">
    <span style="width:8em">Category of book.<br/>Examples :<br/>- Literature<br/>- User guides<br/>- etc.</span></a>
  </td>
</tr><tr>
  <td class="label">Category description</td>
  <td class="value">
    <textarea name="descc" cols="50" rows="2" tabindex="2" class="need"></textarea> &nbsp;
    <a class="info" href="#"><img src="<?php echo $info; ?>" border="0" style="vertical-align:top">
    <span style="top:-1em; width:8em">Short description of the category</span></a>
  </td>
</tr><tr>
  <td class="label">Status of the category</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 category is displayable or hidden</span></a>
  </td>
</tr><tr>
  <td class="label"></td>
  <td class="value"><input type="submit" name="submit" tabindex="4" value="Save"></td>
</tr>
</table>
<p>&nbsp;</p>
<?php
$request
= "SELECT cat,active FROM ".TB_CAT." ORDER BY cat;";
$result = $cnx->query($request);
if(
$result->rowCount()>0) {
        echo
"<div class=\"list\">";
        echo
"<div class=\"ltitle\">List of existing categories :</div>";
        echo
"<select name=\"categories\" multiple size=\"$_lines\" class=\"liste\">";
        while(
$r=$result->fetch()) {
        if(
$r->active) { $class="active"; } else { $class="inactive"; }
                echo
"<option class=\"$class\">$r->cat</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.