File: gestion/set_conf.php

Recommend this page to a friend!
  Classes of Pierre FAUQUE  >  OPDS PHP Ebook Publisher Class  >  gestion/set_conf.php  >  Download  
File: gestion/set_conf.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: 9,857 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: set_conf.php (v0.1)
// Role: Configuration, set the configuration (administrator's name, mail, directories, etc.)
*/

require("init.php");
require(
"lib_lddocs.php");
$report = "&nbsp;";
if(
$_POST["submit"]) {
   
$site = trim($_POST["rootsite"]);
   
$opds = trim($_POST["rootopds"]);
   
$favicon = trim($_POST["favicon"]);
    if(
$opds[0] != "/") { $opds = "/$opds"; }
    if(
$favicon[0] != "/") { $favicon = "/$favicon"; }
    if(
substr($site,-1) == "/") { $site = substr($site,0,-1); } else { $site = $site; }
   
$requests[] = "TRUNCATE ".TB_CFG.";";
   
$requests[] = "INSERT INTO ".TB_CFG." VALUES ('author','".$_POST["author"]."','mandatory');";
   
$requests[] = "INSERT INTO ".TB_CFG." VALUES ('rootsite','$site','mandatory');";
   
$requests[] = "INSERT INTO ".TB_CFG." VALUES ('rootopds','$opds','mandatory');";
   
$requests[] = "INSERT INTO ".TB_CFG." VALUES ('docsdir','".$_POST["docsdir"]."','mandatory');";
   
$requests[] = "INSERT INTO ".TB_CFG." VALUES ('imgdir','".$_POST["imgdir"]."','mandatory');";
   
$requests[] = "INSERT INTO ".TB_CFG." VALUES ('authdir','".$_POST["authdir"]."','mandatory');";
   
$requests[] = "INSERT INTO ".TB_CFG." VALUES ('email','".$_POST["email"]."','optionnal');";
   
$requests[] = "INSERT INTO ".TB_CFG." VALUES ('favicon','".$_POST["favicon"]."','optionnal');";
   
$nbreq = count($requests);
    for(
$n=0; $n<$nbreq; $n++) { $result = $cnx->exec($requests[$n]); }
    if(
$result) { $report = "Configuration stored."; }
}
?><!DOCTYPE html>
<html>

<head>
<meta charset="utf-8">
<title>Set configuration</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_author = letters + "' -";
ca_rootsite = ascii + digits + ":/_-.";
ca_rootopds = ascii + digits + "/_";
ca_docsdir = ascii + digits + "_";
ca_imgdir = ascii + digits + "_";
ca_authdir = ascii + digits + "_";
ca_email = ascii + digits + "@_-.+";
ca_favicon = ascii + digits + "/_.-";

function verif() {

    var msg;

    var author = document.setconf.author.value;
    var rootsite = document.setconf.rootsite.value;
    var rootopds = document.setconf.rootopds.value;
    var docsdir = document.setconf.docsdir.value;
    var imgdir = document.setconf.imgdir.value;
    var authdir = document.setconf.authdir.value;
    var email = document.setconf.email.value;
    var favicon = document.setconf.favicon.value;

    if(!author) {
        alert("Who is responsible of the publications ?\nExample: John DOE");
        document.setconf.author.focus();
        return false;
    }
    msg = isValidText(author,ca_author,3,30);
    if(msg != "OK") {
        alert("author:\n" + msg);
        document.setconf.author.focus();
        return false;
    }
       
    if(!rootsite) {
        alert("URL of the home site ?\nwithout the final /\nExample: http://www.yourwebsite.com");
        document.setconf.rootsite.focus();
        return false;
    }
    msg = isValidText(rootsite,ca_rootsite,13,50);
    if(msg != "OK") {
        alert("rootsite:\n" + msg);
        document.setconf.rootsite.focus();
        return false;
    }
    if(rootsite.substring(0,4) != "http") {
        alert("rootsite:\n" + "An URL begins by 'http'");
        document.setconf.rootsite.focus();
        return false;
    }
    if(!rootopds) {
        alert("Subdirectory for the OPDS system ?\nExample : /opds");
        document.setconf.rootopds.focus();
        return false;
    }
    msg = isValidText(rootopds,ca_rootopds,4,50);
    if(msg != "OK") {
        alert("rootopds:\n" + msg);
        document.setconf.rootopds.focus();
        return false;
    }

    if(!docsdir) {
        alert("In which directory ebooks are stored ?\nExample: ebooks");
        document.setconf.docsdir.focus();
        return false;
    }
    msg = isValidText(docsdir,ca_docsdir,2,50);
    if(msg != "OK") {
        alert("docsdir:\n" + msg);
        document.setconf.docsdir.focus();
        return false;
    }

    if(!imgdir) {
        alert("In which directoriy the thumbnails are stored ?\nExample: img");
        document.setconf.imgdir.focus();
        return false;
    }
    msg = isValidText(imgdir,ca_imgdir,2,50);
    if(msg != "OK") {
        alert("imgdir:\n" + msg);
        document.setconf.imgdir.focus();
        return false;
    }

    if(!authdir) {
        alert("In which directory the default author's page are ?\nExample: authors");
        document.setconf.authdir.focus();
        return false;
    }
    msg = isValidText(authdir,ca_authdir,2,50);
    if(msg != "OK") {
        alert("authdir:\n" + msg);
        document.setconf.authdir.focus();
        return false;
    }

    if(email) {
        msg = isValidText(email,ca_email,6,50);
        if(msg != "OK") {
            alert("email:\n" + msg);
            document.setconf.email.focus();
            return false;
        }
        if(!isEmail(email)) {
            alert("email:\nBad email format");
            document.setconf.email.focus();
            return false;
        }
    }

    if(favicon) {
        msg = isValidText(favicon,ca_favicon,5,50);
        if(msg != "OK") {
            alert("favicon:\n" + msg);
            document.setconf.favicon.focus();
            return false;
        }
    }

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

<body>
<form method="post" name="setconf" 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: Set configuration</h1>
<p class="report"><?php echo $report; ?></p>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
  <td class="h">key</td>
  <td class="h">value</td>
</tr><tr>
  <td class="label">author</td>
  <td class="value">
    <input type="text" name="author" 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:15em">Author of the OPDS system (you)<br/>Last name FIRST NAME</span></a>
  </td>
</tr><tr>
  <td class="label">rootsite</td>
  <td class="value">
    <input type="text" name="rootsite" size="30" tabindex="2" class="need"> &nbsp;
    <a class="info" href="#"><img src="<?php echo $info; ?>" border="0" style="vertical-align:top">
    <span style="width:10em">URL or your website<br/>without the final /</span></a>
  </td>
</tr><tr>
  <td class="label">rootopds</td>
  <td class="value">
    <input type="text" name="rootopds" size="10" value="/opds" tabindex="3" class="need"> &nbsp;
    <a class="info" href="#"><img src="<?php echo $info; ?>" border="0" style="vertical-align:top">
    <span style="width:15em">Directory of the OPDS service<br/>a sub-directory of your website.<br/>/opds recommanded</span></a>
  </td>
</tr><tr>
  <td class="label">docsdir</td>
  <td class="value">
    <input type="text" name="docsdir" size="10" value="ebooks" tabindex="4" class="need"> &nbsp;
    <a class="info" href="#"><img src="<?php echo $info; ?>" border="0" style="vertical-align:top">
    <span style="width:15em">Subdirectory of rootopds where<br/>your ebooks are stored.<br/>ebooks recommanded</span></a>
  </td>
</tr><tr>
  <td class="label">imgdir</td>
  <td class="value">
    <input type="text" name="imgdir" size="10" value="img" tabindex="5" class="need"> &nbsp;
    <a class="info" href="#"><img src="<?php echo $info; ?>" border="0" style="vertical-align:top">
    <span style="width:15em">Subdirectory of rootopds where<br/>the thumbnails images of your ebooks are stored.<br/>img recommanded</span></a>
  </td>
</tr><tr>
  <td class="label">authdir</td>
  <td class="value">
    <input type="text" name="authdir" size="10" value="authors" tabindex="6" class="need"> &nbsp;
    <a class="info" href="#"><img src="<?php echo $info; ?>" border="0" style="vertical-align:top">
    <span style="width:17em">Subdirectory of rootopds if you want<br/>make page about ebook's authors.<br/>authors recommanded.</span></a>
  </td>
</tr><tr>
  <td class="label">email</td>
  <td class="value">
    <input type="text" name="email" size="50" tabindex="7" class="opt"> &nbsp;
    <a class="info" href="#"><img src="<?php echo $info; ?>" border="0" style="vertical-align:top">
    <span style="width:13em">email of the author of the OPDS system (yours)<br/>Optionnal but recomanded.</span></a>
  </td>
</tr><tr>
  <td class="label">favicon</td>
  <td class="value">
    <input type="text" name="favicon" size="25" tabindex="8" class="opt"> &nbsp;
    <a class="info" href="#"><img src="<?php echo $info; ?>" border="0" style="vertical-align:top">
    <span style="width:15em">Name of your favicon.ico<br/>Optionnal<br/>The path of your favicon must starts from the root of your website<br/>/favicon.ico<br/>/img/favicon.ico</span></a>
  </td>
</tr><tr>
  <td class="label"></td>
  <td class="value"><input type="submit" name="submit" tabindex="9" value="Save"></td>
</tr>
</table>
<p>&nbsp;</p>
<?php
$request
= "SELECT * FROM ".TB_CFG.";";
$result = $cnx->query($request);
if(
$result->rowCount()>0) {
        echo
"<div class=\"list\">";
        echo
"<div class=\"ltitle\">Configuration OPDS :</div>";
        echo
"<select name=\"categories\" multiple size=\"$_lines\" class=\"liste\">";
        while(
$r=$result->fetch()) {
                echo
"<option class=\"active\">$r->key = $r->value ($r->statut)</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.