Sommario
Nelle pagine che seguono viene descritta una base di dati utilizzata per mantenere un elenco delle apparecchiatutre di calcolo in uso presso l'Osservatorio di Arcetri. L'applicazione è basata su mSQL (un motore di database che implementa un sottoinsieme del linguaggio SQL) e su FORMS che accedono a procedure di tipo CGI su un server Web. Mediante tali interfaccie è possibile effettuare ricerche sul database nonché modificare ed introdurre nuove informazioni.
Quest'ultima parte è protetta da un meccanismo di username/password.
L'intero sistema consiste di un insieme di varie tecniche e strumenti per la realizzazione di servizi basati sul Web e può essere interessante come esempio per l'implementazione di altre applicazioni dello stesso tipo.
L'uso di strumenti basati sul protocollo HTTP per la realizzazione di applicazioni di tipo client/server sta avendo un successo crescente tanto da stimolare la creazione di un nuovo termine (intranet) quando le applicazioni siano destinate al supporto di servizi interni di una organizzazione.
Uno dei principali motivi di tale successo deriva dal fatto che gli sforzi di implementazione possono essere concentrati sulle funzioni da realizzare mentre tutta la parte di interfaccia viene realizzata mediante browser già disponibili per l'accesso a servizi Internet.
Oltre a ciò le applicazioni realizzate in tal modo sono intrinsecamente orientate all'uso in rete e possono essere utilizzate da clienti di tipo diverso, purché supportino l'accesso alla rete con protocollo HTTP.
Nelle pagine che seguono viene descritta una semplice applicazione che consente di creare e mantenere un archivio delle apparecchiature di calcolo dell'Osservatorio di Arcetri e del Dipartimento di Astronomia e Scienza dello Spazio, il cui interesse deriva principalmente dal fatto che sulla stessa falsariga possono essere realizzate altre applicazioni di tipo organizzativo o amministrativo.
L'applicazione realizzata consiste essenzialmente nella definizione delle interfaccie di utente delle varie funzioni che sono necessarie per realizzare un tipico sistema di database: ricerca di records e, per utenti autorizzati, inserimento, modifica e cancellazione di records.
Il "motore" usato come supporto al database è mSQL (di cui viene
data una breve descrizione sotto) e le interfaccie sono realizzate con
procedure di tipo CGI
scritte in Lite, il linguaggio di
svilupppo nativo per applicazioni mSQL.
Traducendo direttamente dalla documentazione originale:
mSQL è un mini-SQL, ovvero un motore di database "leggero" sviluppato da David J. Hughes <bambi@hughes.com.au> presso la Bond University, Australia. Esso è stato progettato in modo da consentire un accesso veloce a dati memorizzati richiedendo limitate risorse di memoria. Come è implicito nel nome mSQL utilizza un sottoinsieme di SQLcome linguaggio di interrogazione. Sebbene supporti solo un sottoinsieme del linguaggio, tutte le funzioni supportate sono in accordo con la specifica standard ANSI di SQL.
Ulteriori informazioni possono essere reperite presso la relativa "Home page":
http://www.Hughes.com.au.
Presso l'Osservatorio è inoltre disponibile on-line il manuale completo di mSQL:
http://www.arcetri.astro.it/CC/mSQLman.
Il cuore di mSQL è costituito da un processo (msql2d) attivo sulla macchina server che effettua le operazioni sul database costituito da un insieme di files residenti su un disco accessibile a tale processo.
msql2d riceve richieste di operazione, in linguaggio SQL, tramite collegamenti di rete e li esegue.
Il sistema è dotato di alcuni programmi accessori quali:
Il sistema comprende inoltre librerie per vari linguaggi mediante le quali è possibile ``personalizzare'' le modalità di accesso al database, nonché un linguaggio specifico detto lite sempre per lo stesso scopo.
Lite è un linguaggio assai simile al perl, anche se molto più limitato, ma che ha rispetto a quest'ultimo il vantaggio di essere essai più ``leggero'' e di essere particolarmente progettato per la realizzazione di interfaccie di tipo CGI a funzioni mSQL.
Il sistema comprende infatti una applicazione (w3-msql) che viene attivata come applicazione di tipo CGI sul server HTTP, con la specifica di un file che può contenere sia normale codice HTML, che viene mostrato come tale, sia codice lite che viene eseguito.
Tutte le funzioni descritte nel seguito sono state realizzate mediante questa tecnica.
Il database Inventario consiste in alcune ``tabelle'' gestite dal server mSQL. La struttura del database (ovvero le tabelle che lo costituiscono) è mostrata sotto, nel formato di uscita del programma relshow:
Database = Inventario
+---------------------+
| Table |
+---------------------+
| AuthList |
| Ditte |
| Enti |
| Tipi |
| Oggetti |
| Obsoleti |
+---------------------+
Il database comprende una tabella principale (Oggetti) ed alcune ausiliarie, più in dettaglio:
Le tabelle devono essere inizialmente create utilizando l'apposito comando del programma di gestione msqladmin, le altre operazioni vengono effettuate utilizzando comandi SQL.
Le operazioni di accesso al database sono divise in due gruppi: un gruppo, accessibile a tutti gli utenti, che consentono la consultazione dei dati ed un gruppo, riservato ad utenti autorizzati, per l'introduzione dei dati e la modifica di quelli esistenti. Questo secondo gruppo è protetto mediante un meccanismo di controllo di password descritto nel seguito.
[IMAGE ]
Figure 1: Struttura generale delle procedure
L'intero sistema è costituito da procedure operanti sotto il controllo del programma w3-msql sopra descritto. Nei prossimi paragrafi vengono descritte in dettaglio le operazioni definite e le singole procedure che le implementano.
La struttura complessiva del sistema è mostrata in figura 1. index.html costituisce la pagina principale di accesso a tutte le procedure. Al suo interno quattro links consentono l'attivazione delle pagine successive: Inventario.html, per la ricerca di dati; showrel.html per visualizzare la struttura del database; oldinv.html, per accedere ai dati degli apparecchi eliminati dall'inventario principale; privindex.html, la procedura che effettua il controllo dell'accesso ed attiva le operazioni di tipo privilegiato.
L'interfaccia per la ricerca e la visualizzazione di records ha la struttura mostrata in figura 2. Nella figura, e in quelle successive, vengono evidenziati i diversi FORM e pagine HTML utilizzate per l'accesso ai dati, nonché i link principali che consentono di passare da un documento HTML al successivo (eventuali link ausiliari, quali ad esempio quelli che consentono l'accesso a pagine di aiuto, non sono mostrati per chiarezza di esposizione).
[IMAGE ]
Figure 2: Interfaccia per consultazione dei dati
La procedura consta dei seguenti passi:
Nel
primo caso sono evidenziati alcuni dei campi principali contenuti nel
record e la ricerca avviene applicando la funzione AND sui campi
specificati ed ignorando le lettere maiuscole e minuscole
. Nel secondo caso viene presentato un solo
campo di testo nel quale introdurre la specififca di ricerca.
A seconda di quale dei due FORM viene attivato viene passato il controllo alla procedura successiva (simplesrc.html nel primo caso e fullsrc.html nel secondo)
Ancora più semplice è la struttura dell'interfaccia per la visualizzione della struttura del database. Questa infatti, come mostrato in figura 1, è costituita da un'unica procedura che visualizza la struttura delle tabelle principali che costituiscono il database.
Le pagine utilizzate per le operazioni di modifica al database hanno una struttura più complessa, innanzitutto allo scopo di implementare il sistema di controllo dell'accesso ed inoltre perchè vengono adottate varie misure per controllare il formato ed il tipo di dati introdotti dall'operatore. In tutti i casi in cui ciò è possibile, infatti, si è cercato di presentare all'operatore un menù di scelte, anziche un campo dove è possibile inserire caratteri arbitrariamente; ciò allo scopo di ``forzare'' una maggiore omogeneità dei dati contenuti nel database.
[IMAGE ]
Figure 3: Interfaccia per modifica dei records
Le operazioni di modifica sono di tre tipi:
La struttura generale della successione di passi utilizzati per implementare queste operazioni viene mostrata in figura 3; ciascuna operazione è descritta più in dettaglio nei paragrafi che seguono.
Poiché le operazioni di modifica devono essere effettuate solo da personale autorizzato, l'accesso a tali procedure è soggetto ad un preliminare controllo di accesso mediante una pagina specifica (priv/index.html). Tale pagina presenta un FORM che richiede password ed username ed attiva la procedura di controllo vera e propria che svolge essenzialmente due compiti essenziali:
Se i controlli sono positivi la procedura attiva il passo successivo trasmettendo il codice di autorizzazione che sarà verificato dall'ultimo passo, subito prima di effettuare la vera modifica del database.
L'operazione di introduzione di un nuovo record è costituita da quattro passi, come mostrato in figura 3.
La struttura della procedura di modifica di un record, come evidenziato in figura 3 è assai simile a quella relativa all'introduzione di un nuovo record. La principale differenza consiste nel fatto che il FORM per l'introduzione dei dati non è vuoto, ma viene inizializzato con i dati del record da modificare. Questo passo è preceduto da una operazione di ricerca in tutto analoga a quella descritta nel paragrafo 4.1.
I passi, in dettaglio, sono i seguenti:
Nel caso in cui sia stata scelta l'operazione MODIFICA, si procede con il passo successivo.
Allo scopo di mantenere una traccia storica delle apparecchiature l'eliminazione di un record non consiste nella semplice cancellazione dal database, ma piuttosto il record viene spostato in un archivio ausiliario. La struttura della procedura è mostrata in figura 3.
Al termine delle operazioni di modifica è necessario effettuare una uscita ordinata selezionando il link di termine delle operazioni.
Tale operazione, effettuata dalla procedura endmaint.html,
è necessaria allo scopo di cancellare il file di LOCK, che
altrimenti impedirebbe l'accesso ad altri utenti
.
Nell'implementazione delle procedure sopra descritte si è fatto largo uso di sottoprogrammi precompilati per varie delle funzioni elementari utilizzate. Il linguaggio lite consente infatti di includere in una procedura riferimenti ad altre procedure precompilate con due ordini di vantaggi: 1) maggiore efficienza dovuta alla assenza della fase di interpretazione del codice sorgente; 2) riservatezza del codice relativo alle procedure precompilate.
Nella libreria dblib sono state raccolte varie procedure per la manipolazione del database ed altre funzioni ausiliarie il cui uso è generico, ovvero che possono essere utilizzate per realizzare altre applicazioni dello stesso tipo di quella descritta in queste note.
La libreria invlib contiene invece moduli specifici di questa particolare applicazione (formati di stampa, headers, path di specific files, etc.).
Nelle seguenti appendici viene riportato il codice sorcente (HTML/lite) delle varie procedure, approssimativamente suddivise analogamente a come appaiono nel testo, nonchè delle due librerie di sottoprogrammi utilizzate.
<! THIS FILE IS GENERATED AUTOMATICALLY. DO NOT EDIT >
<! YOU MUST EDIT THE SOURCE FILE index.src INSTEAD >
<! file generated from config: cfgDbg on 25/1/98 12:14:25 >
<html>
<head><title>Inventario Apparecchi di calcolo (mSQL)</title></head>
<! /* L. Fini -- Jan 1988 */ >
<body>
<center>
<h3>Osservatorio di Arcetri<br>
Dipartimento di Astronomia e Scienza dello Spazio</h3>
<h1>Inventario Apparecchi di Calcolo</h1>
</center>
<!++ Inizio zona da includere >
<hr>
<blockquote>
<dl>
<dt><h2><a href=/cgi-bin/w3-msql/lfini/Inventario.html?DEBUG=1&DB=Inventario>Inventario corrente</a></h2>
<dd>
Accesso all'inventario corrente.
<dt><h2><a href=/cgi-bin/w3-msql/lfini/gen/showrel.html?DEBUG=1&DB=Inventario>Struttura</a> del database</h2>
<dd>
Mostra la struttura del database e delle tabelle.
</dl>
<hr>
<hr>
<h3> Le seguenti operazioni sono riservate al personale addetto</h3>
<dl>
<dt><h2><a href=/cgi-bin/w3-msql/lfini/priv/index.html?DEBUG=1&DB=Inventario>Modifiche</a></h2>
<dd>
Variazione di dati, inserimento nuove schede, eliminazione dall'inventario.
<dt><h2><a href=/cgi-bin/w3-msql/lfini/priv/oldinv.html?DEBUG=1&DB=Inventario&PRIV=1>Accesso</a> agli apparecchi disinventariati</h2>
<dd>
Ricerche sul database degli strumenti dismessi.
</dl>
</blockquote>
<!-- Fine zona da includere >
</body>
</html>
<html>
<head><title>Inventario Apparecchi di calcolo (mSQL)</title></head>
<body>
<!
load "../invlib.lib";
header(1,"<h1>Apparecchi Disinventariati</h1>");
$w3=w3path();
$Debug=(int)$DEBUG;
$tb = tbold();
if($Debug==1) {
echo("<pre>\n");
echo("DBG><b>Database: </b>$DB\n");
echo("DBG><b> Table: </b>$tb\n");
echo("DBG><b> w3path: </b>$w3\n");
echo("DBG><b> PRIV: </b>$PRIV\n");
echo("</pre>\n");
}
srcform($DB,$tb,"", "", "", $Debug);
>
</body>
</html>
<html>
<head><title>showrel.html - show database structure</title></head>
<body>
<!
load "../invlib.lib"; /* Osservatorio di Arcetri. Library management */
load "../dblib.lib"; /* This module shows the structure of the database */
/* L.Fini. Nov 1997 */
header(0,"<h1>Visualizzazione struttura del database</h1>");
$tipi[1]="int";
$tipi[2]="char";
$tipi[6]="text";
$tb = tbcurr();
$to = tbold();
$Debug=(int)$DEBUG;
if($Debug==1) {
$euid=geteuid();
echo("<pre>\n");
echo("DBG><b>Database: </b>$DB\n");
echo("DBG><b> Table: </b>$tb\n");
echo("DBG><b> EUID: </b>$euid\n");
echo("</pre>\n");
}
/* Get field list and build query */
$flds = fields($DB,$tb);
$nflds= # $flds;
echo("Il database delle apparecchiature di calcolo è costituito da una\n");
echo("tabella principale di nome <b>$tb</b> contenente le schede descrittive\n");
echo("delle apparecchiature in uso ed una secondaria di nome <b>$to</b> per\n");
echo("le apparecchiature dismesse.<p> Entrambe le tabella hanno la seguente\n");
echo("struttura:\n");
echo("<blockquote>\n");
echo("<table border=2>\n");
echo("<tr><th>Nome campo<th> Tipo <th>Lungh.</tr>\n");
$i=0;
while( $i < $nflds) {
$fdata=split($flds[$i],",");
$fname=$fdata[0];
$ftype=(int)$fdata[1];
$fleng=(int)$fdata[2];
if($ftype>0) {
$t=$tipi[$ftype];
if($t=="") {
$t=(char)$ftype;
}
echo("<tr><td> $fname <td> $t <td> $fleng</tr>\n");
}
$i = $i + 1;
}
>
</table>
</blockquote>
<hr>
Il database utilizza altre tabelle ausiliarie, descritte nel seguito:
<h3>Lista degli utenti autorizzati a modificare il database:</h3>
<blockquote>
<table border=2>
<tr><th>Username<th>Full name</tr>
<!
$sock=opendb($DB);
$q="select * from AuthList";
$ret= msqlQuery($sock, $q);
if ($ret < 0) {
echo("<h2>Errore da msqlQuery</h2>");
echo("<b>Query: </b> $q <br>");
echo("<b>ErrMsg: </b> $ERRMSG<p>\n");
msqlClose($sock);
exit(1);
}
$res=msqlStoreResult();
msqlClose($sock);
$loop=1;
while($loop>0) {
$row = msqlFetchRow($res);
if ( # $row == 0) {
$loop=0;
} else {
echo("<tr><td> $row[0] <td> $row[1] </tr>\n");
}
}
>
</table>
</blockquote>
<h2>Lista degli Enti proprietari</h2>
<blockquote>
<table border=2>
<tr><th> Ente <th></tr>
<!
$sock=opendb($DB);
$q="select * from Enti order by item";
$ret= msqlQuery($sock, $q);
if ($ret < 0) {
echo("<h2>Errore da msqlQuery</h2>");
echo("<b>Query: </b> $q <br>");
echo("<b>ErrMsg: </b> $ERRMSG<p>\n");
msqlClose($sock);
exit(1);
}
$res=msqlStoreResult();
msqlClose($sock);
$loop=1;
while($loop>0) {
$row = msqlFetchRow($res);
if ( # $row == 0) {
$loop=0;
} else {
echo("<tr><td> $row[0] </tr>\n");
}
}
>
</table>
</blockquote>
<h2>Lista delle Ditte</h2>
<blockquote>
<table border=2>
<tr><th> Ditta <th></tr>
<!
$sock=opendb($DB);
$q="select * from Ditte order by item";
$ret= msqlQuery($sock, $q);
if ($ret < 0) {
echo("<h2>Errore da msqlQuery</h2>");
echo("<b>Query: </b> $q <br>");
echo("<b>ErrMsg: </b> $ERRMSG<p>\n");
msqlClose($sock);
exit(1);
}
$res=msqlStoreResult();
msqlClose($sock);
$loop=1;
while($loop>0) {
$row = msqlFetchRow($res);
if ( # $row == 0) {
$loop=0;
} else {
echo("<tr><td> $row[0] </tr>\n");
}
}
>
</table>
</blockquote>
</body>
</html>
<html>
<head><title>Inventario Apparecchi di calcolo (mSQL)</title></head>
<body>
<!
load "invlib.lib"; /* Osservatorio di Arcetri. Inventory management */
/* this module displays a record search FORM */
/* L.Fini. Oct 1997 */
$Debug=(int)$DEBUG;
$db = dbcurr();
$tb = tbcurr();
header(0,"<h2>Ricerca schede</h2>");
srcform($db, $tb, "", "", "", $Debug);
>
</body>
</html>
<html>
<head><title>simplesrc.html - perform a search. Simplified syntax</title></head>
<!
load "../dblib.lib"; /* Osservatorio di Arcetri. Inventory management */
load "../invlib.lib"; /* This module performs a search on the database */
/* after building a valid mSQL search command based */
/* on a few of simple specifications. */
/* The search expression is the logical AND of case */
/* insensitive string matching in any point of the */
/* fields: author, title, borrower etc. */
/* L.Fini. Oct 1997 */
header(0,"<h2>Risultati Ricerca</h2>");
$w3=w3path();
$Debug=(int)$DEBUG;
if($Debug==1) {
echo("<pre>\n");
echo("DBG><b>Database: </b>$DB\n");
echo("DBG><b> Table: </b>$TB\n");
echo("DBG><b> w3path: </b>$w3\n");
echo("DBG><b> INIZIO: </b>$INIZIO\n");
echo("DBG><b> FORMAT: </b>$FORMAT\n");
echo("DBG><b> PRIV: </b>$PRIV\n");
echo("DBG><b> USER: </b>$USER\n");
echo("DBG><b> FULLN: </b>$FULLN\n");
echo("</pre>\n");
}
$q = "select " + fdlist(1) + " from " + $TB + " where " ;
$n=0;
if($INIZIO != "") {
$q = $q + "numero >= " + (char)$INIZIO;
$n=1;
$and = " AND ";
}
if($TIPO != "") {
$q = $q + $and + "tipo CLIKE '%" + $TIPO + "%'";
$n=1;
$and = " AND ";
}
if($ENTE != "") {
$q = $q + $and + "ente CLIKE '%" + $ENTE + "%'";
$n=1;
$and = " AND ";
}
if($COLLOC != "") {
$q = $q + $and + "collocazione = " + $COLLOC;
$n=1;
$and = " AND ";
}
if($RESP != "") {
$q = $q + $and + "responsabile CLIKE '%" + $RESP + "%'";
$n=1;
$and = " AND ";
}
if($MATR != "") {
$q = $q + $and + "matricola CLIKE '%" + $MATR + "%'";
$n=1;
$and = " AND ";
}
if($INV != "") {
$q = $q + $and + "inventario CLIKE '%" + $INV + "%'";
$n=1;
$and = " AND ";
}
if($MOD != "") {
$q = $q + $and + "modello CLIKE '%" + $MOD + "%'";
$n=1;
$and = " AND ";
}
if($n==0) {
echo("<h2>Non hai specificato una stringa di ricerca!</h2>");
exit(0);
}
$q = $q + " order by numero";
if((int)$LIMIT >0 ) {
$q = $q + " limit " + $LIMIT;
}
$res= searchq($DB,$q,$Debug);
$nr=msqlNumRows($res);
echo("<h3>Trovate $nr schede</h3><hr>\n");
shrthdr($DB,$TB,$FORMAT,$Debug); /* Stampa header per visualizzazione */
$totval=0;
$loop=1;
while($loop>0) {
$row = msqlFetchRow($res);
if ( # $row == 0) {
$loop=0;
} else {
$totval = $totval + viewshort($row,$FORMAT,$Debug);
}
}
shrtftr($PRIV,$USER,$FULLN,$FORMAT,$totval);
>
</body>
</html>
<html>
<head><title>fullsrc.html - perform a search. Full mSQL syntax</title></head>
<body>
<!
load "../dblib.lib"; /* Osservatorio di Arcetri. Inventory management */
load "../invlib.lib"; /* This module gets an msql search expression from */
/* a form and performs a search with the given */
/* espression. The output is formatted on a few */
/* lines and allows to select a record to be shown */
/* in full details. */
/* L.Fini. Nov 1997 */
header(0,"<h1>Risultati ricerca</h1>");
$w3 = w3path();
$Debug=(int)$DEBUG;
if($Debug==1) {
echo("<pre>\n");
echo("DBG><b>Database: </b>$DB\n");
echo("DBG><b> Table: </b>$TB\n");
echo("DBG><b> w3path: </b>$w3\n");
echo("DBG><b> FORMAT: </b>$FORMAT\n");
echo("DBG><b> PRIV: </b>$PRIV\n");
echo("DBG><b> USER: </b>$USER\n");
echo("DBG><b> FULLN: </b>$FULLN\n");
echo("</pre>\n");
}
if($SPEC == "") {
echo("<h2>Deve essere specificato un comando di ricerca</h2>\n");
echo("<h3>Vedi: <a href=$w3/help.html>aiuto</a></h3>\n");
exit(0);
}
$q = "select " + fdlist(1) + " from " + $TB + " where " + $SPEC;
$res= searchq($DB,$q, $Debug);
$nr=msqlNumRows($res);
echo("<h3>Trovate $nr schede</h3><hr>\n");
$loop=1;
$totval=0;
shrthdr($DB,$TB,$FORMAT,$Debug); /* Stampa header per visualizzazione */
while($loop>0) {
$row = msqlFetchRow($res);
if ( # $row == 0) {
$loop=0;
} else {
$totval = $totval + viewshort($row,$FORMAT,$Debug);
viewshort($row,$FORMAT,$Debug);
}
}
shrtftr($PRIV,$USER,$FULLN,$FORMAT,$totval);
>
</body>
</html>
<html>
<head><title>recdetail.html - Show a record in full detail</title></head>
<body>
<html>
<!
load "../dblib.lib"; /* Osservatorio di Arcetri. Library management */
load "../invlib.lib"; /* L.Fini. Oct 1997 */
/* This shows the full content of a record */
funct privmode(char $db,
char $Rowid,
char $Priv,
char $User,
char $Fulln,
char $Debug)
{
$w3=w3path();
echo("</pre><form action=$w3/priv/operations.html>\n");
echo("<b>Operazioni consentite</b>:<blockquote> \n");
echo("<input type=hidden name=DB value=$db>\n");
echo("<input type=hidden name=ROWID value=$Rowid>\n");
echo("<input type=hidden name=PRIV value=$Priv>\n");
echo("<input type=hidden name=USER value=$User>\n");
echo("<input type=hidden name=FULLN value=\"$Fulln\">\n");
echo("<input type=hidden name=DEBUG value=$Debug>\n");
echo("<input type=submit name=OPER value=MODIFICA> : ");
echo("Modifica informazioni nella scheda<br>\n");
echo("<input type=submit name=OPER value=ELIMINA> : ");
echo("Elimina apparecchiatura dall'Inventario<br>\n");
echo("<input type=submit name=OPER value=ANNULLA> : ");
echo("Annulla modifica e torna alla selezione funzioni<br>\n");
echo("</blockquote></form>\n");
}
header(0,"<h1>Dettaglio schede</h1>");
$Debug=(int)$DEBUG;
$rwtype = typeof($ROWID);
if($Debug==1) {
echo("<pre>\n");
echo("DBG><b> Rowid: </b>");
if($rwtype=="array") {
$i=0; $n = # $ROWID;
while($i<$n) {
echo("$ROWID[$i],");
$i++;
}
} else {
echo($ROWID);
}
echo("\n");
echo("DBG><b> PRIV: </b>$PRIV\n");
echo("DBG><b> USER: </b>$USER\n");
echo("DBG><b> FULLN: </b>$FULLN\n");
echo("</pre>\n");
}
if(# $ROWID == 0) {
printf("<h2>Nessuna scheda selezionata!</h2>\n");
exit(0);
}
$i=0; $n = # $ROWID;
if($rwtype=="array") {
while($i<$n) {
$row = viewrec($DB,$TB,(int)$ROWID[$i],$PRIV,$Debug);
if($PRIV != "") {
privmode($DB,$ROWID[$i],$PRIV,$USER,$FULLN,$DEBUG);
}
$i++;
}
} else {
$row = viewrec($DB,$TB,(int)$ROWID,$PRIV,$Debug);
if($PRIV != "") {
privmode($DB,$ROWID,$PRIV,$USER,$FULLN,$DEBUG);
}
}
>
</body>
</html>
<html>
<head><title>index.html - Access to privileged functions</title></head>
<body>
<!
load "../invlib.lib"; /* Osservatorio di Arcetri. Library management */
load "../dblib.lib"; /* L.Fini. Oct 1997 */
/* This module request username and password for */
/* user authentication */
header(1,"<h1>Accesso ad operazioni sul database</h1>");
$www=w3path();
$html=htmlpath();
$Debug=(int)$DEBUG;
if($Debug==1) {
echo("<pre>\n");
echo("DBG><b>Database: </b>$DB\n");
echo("DBG><b> w3path: </b>$www\n");
echo("DBG><b>htmlpath: </b>$html\n");
echo("</pre>\n");
}
echo("<h3>Per procedere occorre identificarsi con <i>username</i> e <i>password</i>:</h3>\n");
echo("<form action=./privindex.html method=post>\n");
echo("<input type=hidden name=DB value=$DB>\n");
echo("<blockquote><h4><pre>\n");
echo("Username: <input type=text name=id size=10><br>\n");
echo("Password: <input type=password name=id size=10> ");
echo("<input type=submit value=INVIO>");
if($Debug==1) {
echo("<input type=hidden name=DEBUG value=1>\n");
}
echo("</h4></blockquote>\n");
echo("</form>\n");
>
</body>
</html>
<html>
<head><title>privindex.html - Check user identification</title></head>
<body>
<!
load "../invlib.lib"; /* Osservatorio di Arcetri. Gestione inventario */
load "../dblib.lib"; /* L.Fini. Oct 1997 */
/* This module checks username and password and */
/* creates the lock file with authorization token */
/* Then displays a selection of allowed operations */
header(1,"<h1>Selezione operazione sul database</h1>");
$w3=w3path();
$Debug=(int)$DEBUG;
if($Debug==1) {
echo("<pre>\n");
echo("DBG><b>Database: </b>$DB\n");
echo("DBG><b> w3path: </b>$w3\n");
echo("DBG><b> PRIV: </b>$PRIV\n");
if($PRIV != "") {
echo("DBG> Iteration\n");
echo("DBG><b> USER: </b>$USER\n");
echo("DBG><b> FULLN: </b>$FULLN\n");
} else {
echo("DBG> First entry\n");
echo("DBG><b>Username: </b>$id[0]\n");
}
echo("</pre>\n");
}
if($PRIV=="") { /* here the first time it's called */
$User=$id[0];
$passw=$id[1];
$pwf=getpwnam($User);
if(# $pwf != 7) { Fail($DB,403); } /* cannot get user password */
$sign=strseg($pwf[1],0,1);
$cpw=crypt($passw,$sign);
if($cpw != $pwf[1]) { Fail($DB,104); } /* illegal password */
$cmd="select name from AuthList where username = '$User'";
$res=searchq($DB,$cmd,$Debug);
$row = msqlFetchRow($res);
if(# $row == 0) { Fail($DB,105); } /* User not in authorization */
/* list */
$Fulln=$row[0];
$file=w3userdir() + "/" + $DB + ".lock"; /* make filename */
if(test("f",$file) == 1) { /* Lock file exists. Get user name */
$fd=open($file,"<");
$usr=readln($fd);
$usr=chop($usr);
$fuln=readln($fd);
$fuln=chop($fuln);
$rtm=readln($fd);
$rtm=readln($fd);
$rtm=chop($rtm);
$tm = (int)$rtm;
$life=time() - $tm;
close($fd);
if($Debug==1) {
echo("<pre>\n");
echo("DBG> Lockfile --\n");
echo("DBG> User: $usr\n");
echo("DBG> Full Name: $fuln\n");
echo("DBG> Timelock: $rtm \n");
echo("DBG> Life: $life sec\n");
echo("</pre>");
}
if(# $rtm>0) {
if($usr != $User) { /* database in use by someone */
if($life > 1800) { /* But time expired */
unlink($file);
} else {
echo("<H3>Data base occupato da: $line</h3>\n");
echo("<H4>Riprova piu' tardi</h4>\n");
exit(0);
}
}
} else {
if(test("f",$file)==1) {
fatal("<H3>Internal locking error</h3>\n");
}
}
}
} else { /* Here when called after previous operation */
ChkPriv($DB,$PRIV,$USER,$FULLN);
$User=$USER;
$Fulln=$FULLN;
}
$Priv=resetlock($DB,$User,$Fulln);
$pargs=privargs($DB,$Priv,$User,$Fulln,$DEBUG);
echo("<blockquote>\n");
echo("<h3>\n");
echo("<ul>\n");
echo("<li> <a href=$w3/priv/updatedb.html?$pargs>Modifica/Cancellazione</a> di schede esistenti<p>\n");
echo("<li> <a href=$w3/priv/preselect.html?$pargs>Inserimento </a>di nuove schede<p>\n");
echo("<li> <a href=$w3/priv/modtables.html?$pargs>Modifica</a> tabelle ausiliarie<p>\n");
echo("<li> <a href=$w3/priv/endmaint.html?$pargs>Fine</a> procedure<p>\n");
echo("</ul>\n");
echo("</h3>\n");
echo("</blockquote>\n");
>
</body>
</html>
<html>
<head><title>preselect.html - Seleziona tipo record</title></head>
<body>
<!
load "../invlib.lib"; /* Osservatorio di Arcetri. Library management */
load "../dblib.lib"; /* L.Fini. Oct 1997 */
/* This module displays a FORM for device type */
/* selection. */
header(1,"<h1>Preselezione tipo apparecchio</h1>");
$w3=w3path();
$html=htmlpath();
$Debug=(int)$DEBUG;
if($Debug==1) {
echo("<pre>\n");
echo("DBG><b>Database: </b>$DB\n");
echo("DBG><b> w3path: </b>$w3\n");
echo("DBG><b>htmlpath: </b>$html\n");
echo("DBG><b> PRIV: </b>$PRIV\n");
echo("DBG><b> USER: </b>$USER\n");
echo("DBG><b> FULLN: </b>$FULLN\n");
echo("</pre>\n");
}
/* Get field list and build query */
echo("<form method=POST action=$w3/priv/insertdb.html>\n");
echo("<h3>Scegliere il tipo di Apparecchiatura e premere ");
echo("<input type=hidden name=DB value=$DB>\n");
echo("<input type=submit value=Invio>.</h3>\n");
echo("<input type=hidden name=PRIV value=$PRIV>\n");
echo("<input type=hidden name=USER value=$USER>\n");
echo("<input type=hidden name=FULLN value=\"$FULLN\">\n");
echo("<input type=hidden name=DEBUG value=$Debug>\n");
echo("<blockquote><b>\n");
selecttable($DB,"Tipi",10,"TIPO","",$Debug);
echo("</b></blockquote>\n");
echo("</form>");
>
</body>
</html>
<html>
<head><title>insertdb.html - Insert new records</title></head>
<body>
<!
load "../invlib.lib"; /* Osservatorio di Arcetri. Library management */
load "../dblib.lib"; /* L.Fini. Oct 1997 */
/* This module generates the data entry FORM. */
header(1,"<h1>Modulo inserimento dati</h1>");
$w3=w3path();
$html=htmlpath();
$tb=tbcurr();
$Debug=(int)$DEBUG;
if($Debug==1) {
echo("<pre>\n");
echo("DBG><b>Database: </b>$DB\n");
echo("DBG><b> w3path: </b>$w3\n");
echo("DBG><b>htmlpath: </b>$html\n");
echo("DBG><b> Tipo: </b>$TIPO\n");
echo("DBG><b> PRIV: </b>$PRIV\n");
echo("DBG><b> USER: </b>$USER\n");
echo("DBG><b> FULLN: </b>$FULLN\n");
echo("</pre>\n");
}
/* Get field list and build query */
$Num = getnext($DB,$tb,"numero", $Debug);
echo("<form method=POST action=$w3/priv/confinsert.html>\n");
echo("<input type=hidden name=DB value=$DB>\n");
echo("<h3>Inserire i dati richiesti e premere ");
echo("<input type=hidden name=PRIV value=$PRIV>\n");
echo("<input type=hidden name=USER value=$USER>\n");
echo("<input type=hidden name=FULLN value=\"$FULLN\">\n");
echo("<input type=hidden name=DEBUG value=$Debug>\n");
echo("<input type=submit value=Invio>.</h3>\n");
echo("<table>");
echo("<table>");
echo("<tr valign=center><td><b>Numero</b> ");
echo("<td><input type=hidden name=NUM value=$Num>$Num</tr>\n");
echo("<tr valign=center><td><b>Tipo</b> ");
echo("<td><input type=hidden name=TIPO value=\"$TIPO\">$TIPO</tr>\n");
echo("<tr valign=center><td><b>Costruttore </b> ");
echo("<td>");
selecttable($DB,"Ditte",5,"COST","",$Debug);
echo("</tr>\n");
echo("<tr valign=center><td><b>Venditore </b> ");
echo("<td>");
selecttable($DB,"Ditte",5,"VEND","",$Debug);
echo("</tr>\n");
echo("<tr valign=center><td><b>Modello</b> ");
echo("<td><input type=text size=40 name=MOD></tr>\n");
echo("<tr valign=center><td><b>Descrizione </b> ");
echo("<td><input type=text size=40 name=DESC></tr>\n");
echo("<tr valign=center><td><b>Matricola </b> ");
echo("<td><input type=text size=25 name=MATR></tr>\n");
echo("<tr valign=center><td><b>Valore </b> ");
echo("<td><input type=text size=10 name=VAL> (Lire)</tr>\n");
echo("<tr valign=center><td><b>Ente </b> ");
echo("<td>");
selecttable($DB,"Enti",1,"ENTE","Oss.Arcetri",$Debug);
echo("</tr>\n");
echo("<tr valign=center><td><b>N. Inventario </b> ");
echo("<td><input type=text size=15 name=INV></tr>\n");
echo("<tr valign=center><td><b>Collocazione </b> ");
echo("<td><input type=text size=4 name=COLL> (N. stanza come da ");
echo("<a href=$html/mappe/Mappe.html>mappe</a>))</tr>\n");
echo("<tr valign=center><td><b>Responsabile </b> ");
echo("<td><input type=text size=15 name=RESP></tr>\n");
$tm = time();
$yr=unixtime2year($tm);
$mo=unixtime2month($tm);
$dy=unixtime2day($tm);
echo("<tr valign=center><td><b>Data </b> ");
echo("<td><input type=text size=2 value=$dy name=DD> / ");
echo("<input type=text size=2 value=$mo name=MM> / ");
echo("<input type=text size=4 value=$yr name=YY></tr>\n");
echo("<tr valign=center><td><b>Nome di rete </b> ");
echo("<td><input type=text size=15 name=NRET></tr>\n");
echo("<tr valign=center><td><b>Principale </b> ");
echo("<td><input type=text size=15 name=PRIN></tr>\n");
echo("<tr valign=center><td><b>Commenti </b> ");
echo(" <td><textarea cols=60 rows=3 name=COMM></textarea></tr>\n");
echo("</table></form>\n");
>
</body>
</html>
<html>
<head><title>confinsert.html - Confirm insertion</title></head>
<body>
<!
load "../invlib.lib"; /* Osservatorio di Arcetri. Library management */
load "../dblib.lib"; /* This module ask for confirmation of record */
/* insertion */
/* L.Fini. Oct 1997 */
funct lacking(char $fname, int $c)
{
if($c<1) {
echo("<h2>Dati di ingresso incompleti</h2>\n");
echo("<h3>Mancano le seguenti informazioni obbligatorie:</h3><blockquote>\n");
}
echo("<h4>$fname</h4>\n");
}
header(1,"<h1>Conferma inserimento scheda</h1>");
$w3=w3path();
$html=htmlpath();
$tb = tbcurr();
$Debug=(int)$DEBUG;
if($Debug==1) {
echo("<pre>\n");
echo("DBG><b>Database: </b>$DB\n");
echo("DBG><b> Table: </b>$tb\n");
echo("DBG><b> w3path: </b>$w3\n");
echo("DBG><b>htmlpath: </b>$html\n");
echo("DBG><b> PRIV: </b>$PRIV\n");
echo("DBG><b> USER: </b>$USER\n");
echo("DBG><b> FULLN: </b>$FULLN\n");
echo("</pre>\n");
}
/* Get field list and build query */
$c=0;
if($TIPO == "") { lacking("Tipo",$c); $c=1; }
if($COST == "") { lacking("Costruttore",$c); $c=1; }
if($VEND == "") { lacking("Venditore",$c); $c=1; }
if($MOD == "") { lacking("Modello",$c); $c=1; }
if($VAL == "") { lacking("Valore",$c); $c=1; }
if($ENTE == "") { lacking("Ente",$c); $c=1; }
if(($DD == "")||($MM == "")||($YY == "")) { lacking("Data",$c); $c=1; }
if($COLL == "") { lacking("Collocazione",$c); $c=1; }
if($RESP == "") { lacking("Responsabile",$c); $c=1; }
$pargs=privargs($DB,$PRIV,$USER,$FULLN,$DEBUG);
if($c==1) {
echo("</blockquote><hr>\n");
echo("Puoi usare il bottone <b>Back</b> del browser per tornare alla pagina\n");
echo("precedente ed aggiungere le informazioni mancanti.\n");
exit(0);
}
echo("<b>Se non voui proseguire puoi \n");
echo("<a href=$w3/priv/privindex.html?$pargs>tornare</a> alla selezione delle operazioni<p>\n");
$q = "insert into " + $tb + " values (\n ";
$tm = time();
$yr=unixtime2year($tm);
$mo=unixtime2month($tm);
$dy=unixtime2day($tm);
$catdate=encdata($dy,$mo,$yr);
$q = $q + $NUM + ",\n ";
$q = $q + chrEncode($TIPO) + ",\n ";
$q = $q + chrEncode($COST) + ",\n ";
$q = $q + chrEncode($VEND) + ",\n ";
$q = $q + chrEncode($MOD) + ",\n ";
$q = $q + chrEncode($DESC) + ",\n ";
$q = $q + chrEncode($MATR) + ",\n ";
$q = $q + chrEncode($VAL) + ",\n ";
$q = $q + chrEncode($ENTE) + ",\n ";
$q = $q + chrEncode($INV) + ",\n ";
$q = $q + chrEncode($COLL) + ",\n ";
$q = $q + chrEncode($RESP) + ",\n ";
$q = $q + chrEncode((char)$catdate) + ",\n ";
$q = $q + chrEncode($NRET) + ",\n ";
$q = $q + chrEncode($PRIN) + ",\n ";
$q = $q + chrEncode($COMM) + ",\n ";
$q = $q + chrEncode($FULLN) + ",\n ";
$q = $q + chrEncode((char)$catdate) + "\n)\n";
$q = dblEncode($q);
echo("<h2>Query:</h2><blockquote><h3><pre>\n");
echo($q);
echo("</pre></h3></blockquote>\n");
echo("<form method=POST action=$w3/priv/doinsert.html>\n");
echo("<input type=hidden name=DB value=$DB>\n");
echo("<input type=HIDDEN name=DEBUG value=$Debug>\n");
echo("<input type=HIDDEN name=PRIV value=$PRIV>\n");
echo("<input type=HIDDEN name=USER value=$USER>\n");
echo("<input type=HIDDEN name=FULLN value=\"$FULLN\">\n");
echo("<input type=HIDDEN name=ROWID value=$ROWID>\n");
echo("<input type=HIDDEN name=QUERY value=\"$q\">\n");
echo("Per inserire il record premere:");
echo("<input type=SUBMIT value=CONFERMA>\n");
echo("</form>\n");
echo("<h3>Se non vuoi inserire il record ");
echo("<a href=$w3/priv/privindex.html?$pargs>torna</a> alla selezione funzioni.</h3>\n");
>
</body>
</html>
<html>
<head><title>doinsert.html - Actually insert a record</title></head>
<body>
<!
load "../invlib.lib"; /* Osservatorio di Arcetri. Inventory management */
load "../dblib.lib"; /* L.Fini. Oct 1997 */
/* This module performs an insertion into the */
/* database. */
/* Input variables: */
/* $QUERY: operation to perform (mSQL syntax) */
header(1,"<h1>Inserimento scheda</h1>");
$Debug=(int)$DEBUG;
$w3=w3path();
if($Debug==1) {
$uid=geteuid();
echo("<pre>\n");
echo("DBG><b>Database: </b>$DB\n");
echo("DBG><b> UID: </b>$uid\n");
echo("DBG><b> w3path: </b>$w3\n");
echo("DBG><b> QUERY: </b>$QUERY\n");
echo("DBG><b> PRIV: </b>$PRIV\n");
echo("DBG><b> USER: </b>$USER\n");
echo("DBG><b> FULLN: </b>$FULLN\n");
echo("</pre>\n");
}
ChkPriv($DB,$PRIV,$USER,$FULLN);
$ret=plaincmd($DB,$QUERY,$Debug);
if($ret>=0) {
echo("<h3>Nuovo record correttamente inserito</h3>\n");
} else {
echo("<h3>Il record NON è stato inserito !</h3>\n");
}
$pargs=privargs($DB,$PRIV,$USER,$FULLN,$DEBUG);
echo("<blockquote>\n");
echo("<h3>Torna alla pagina <a href=$w3/priv/privindex.html?$pargs>selezione funzioni</a></h3>\n");
echo("</blockquote>\n");
>
</body>
</html>
<html>
<head><title>operations.html - Perform operations on database</title></head>
<body>
<!
load "../invlib.lib"; /* Osservatorio di Arcetri. Library management */
load "../dblib.lib"; /* L.Fini. Oct 1997 */
/* This module gets operation request (MODIFY, or */
/* DELETE) and prepares the related query */
/************************************/
funct modify(char $db, /* Modify a record */
int $Rowid,
char $Priv,
char $User,
char $fulln,
int $Debug)
{
$w3=w3path();
$tb=tbcurr();
/* Get field list and build query */
$flds = fields($db,$tb);
$nflds= # $flds;
$i=0;
$nnflds=0;
$q = "select"; $s=" ";
while( $i < $nflds) {
$fdata=split($flds[$i],",");
if(($fdata[0] != "redazione")&&($fdata[0] != "data_red")) {
$fname[$i]=$fdata[0];
$ftype[$i]=(int)$fdata[1];
$fleng[$i]=(int)$fdata[2];
$q = $q + $s + $fdata[0];
$s=",";
$nnflds=$nnflds + 1;
}
$i=$i + 1;
}
$row = getrec($db,$tb,$Rowid,$Debug,$q);
$pargs=privargs($db,$Priv,$User,$fulln,(char)$Debug);
echo("<b>Per interrompere la modifica tornare alla pagina\n");
echo("<a href=$w3/priv/privindex.html?$pargs>");
echo(" selezione funzioni</a>.</b><hr>\n");
echo("<form method=POST action=$w3/priv/confupdate.html>\n");
echo("<b>Modificare i dati nei campi sottostanti e quindi premere ");
echo("<input type=submit value=Invio>.</b><p>\n");
echo("<input type=hidden name=DB value=$db>\n");
echo("<input type=hidden name=ROWID value=$Rowid>\n");
echo("<input type=hidden name=PRIV value=$Priv>\n");
echo("<input type=hidden name=USER value=$User>\n");
echo("<input type=hidden name=FULLN value=\"$fulln\">\n");
echo("<input type=hidden name=DEBUG value=$Debug>\n");
echo("<table>");
echo("<tr valign=center><td><b>_rowid:</b> ");
echo("<td>$Rowid<br>\n");
$i=0;
while( $i<$nnflds) {
if($ftype[$i] > 0) {
printf("<input type=hidden name=NAMES value=\"%s\">\n",$fname[$i]);
printf("<input type=hidden name=TYPES value=%d>\n",$ftype[$i]);
printf("<input type=hidden name=LENGS value=%d>\n",$fleng[$i]);
printf("<tr valign=center><td><b>%s:</b> ",$fname[$i]);
}
if($ftype[$i]==6) {
printf(" <td><textarea cols=60 rows=3 name=VALUES>$row[$i]</textarea><br>\n");
}
if($ftype[$i] == 1) {
if($fname[$i]=="numero"){
echo("<td> $row[$i]<input type=hidden name=VALUES value=\"$row[$i]\"><br>\n");
} else {
echo("<td><input type=text size=10 name=VALUES value=\"$row[$i]\"><br>\n");
}
}
if($ftype[$i] == 2) {
$sz=(int)$fleng[$i];
echo("<td><input type=text size=$sz name=VALUES value=\"$row[$i]\"<br>\n");
}
$i = $i + 1;
}
echo("</table></form>");
return(1);
}
/************************************/
funct delete(char $db, /* deletes a record (Actually moves */
int $Rowid, /* it into the "Obsolete" table) */
char $Priv,
char $User,
char $fulln,
int $Debug)
{
$w3=w3path();
$tb=tbcurr();
$tbold=tbold();
$row = getrec($db,$tb,$Rowid,$Debug,""); /* Get record */
$flds = fields($db,$tb); /* Get field list */
if(# $row<2) {
return(0);
}
$tm = time();
$yr=unixtime2year($tm);
$mo=unixtime2month($tm);
$dy=unixtime2day($tm);
$catdate=encdata($dy,$mo,$yr);
$d = "DELETE FROM " + $tb +
" WHERE _rowid=" + (char)$Rowid + "\n"; /* prepare delete query */
$s = " ";
$i=0;
$nflds= # $flds;
$q = "INSERT INTO " + $tbold + " VALUES\n(\n"; /* prepare insertion query */
while( $i < $nflds) {
$fdata=split($flds[$i],",");
$val=$row[$i];
if($fdata[0] == "redazione") {
$val=$fulln;
}
if($fdata[0] == "data_red") {
$val=(char)$catdate;
}
if($fdata[0] != "_rowid") {
if((int)$fdata[1]==1) {
$q = $q + $s + $val;
} else {
$q = $q + $s + chrEncode($val);
}
$s=",\n ";
}
$i=$i + 1;
}
$q = $q + "\n)\n";
$q = dblEncode($q);
$pargs=privargs($db,$Priv,$User,$fulln,(char)$Debug);
echo("<b>Per interrompere la cancellazione tornare alla pagina\n");
echo("<a href=$w3/priv/privindex.html?$pargs>");
echo(" selezione funzioni</a>.</b><hr>\n");
echo("<form method=POST action=$w3/priv/dodelete.html>\n");
echo("<b>Se vuoi eleminare la seguente scheda dall'inventario premi ");
echo("<input type=submit value=CONFERMA>.</b><p>\n");
echo("<input type=hidden name=DB value=$db>\n");
echo("<input type=hidden name=ROWID value=$Rowid>\n");
echo("<input type=hidden name=PRIV value=$Priv>\n");
echo("<input type=hidden name=USER value=$User>\n");
echo("<input type=hidden name=FULLN value=\"$fulln\">\n");
echo("<input type=hidden name=DEBUG value=$Debug>\n");
echo("<input type=hidden name=QUERY1 value=\"$d\">\n");
echo("<input type=hidden name=QUERY2 value=\"$q\">\n");
$row = printrec($row);
echo("</form>");
return(1);
}
$w3=w3path();
$Debug=(int)$DEBUG;
if($Debug==1) {
echo("<pre>\n");
echo("DBG><b> Database: </b>$DB\n");
echo("DBG><b> w3path: </b>$w3\n");
echo("DBG><b> Rowid: </b>$ROWID\n");
echo("DBG><b>Operation: </b>$OPER\n");
echo("DBG><b> PRIV: </b>$PRIV\n");
echo("DBG><b> USER: </b>$USER\n");
echo("DBG><b> FULLN: </b>$FULLN\n");
echo("</pre>\n");
}
$Rowid=(int)$ROWID;
if($ROWID == "") {
echo("<h2>Internal error: No record selected.!</h2>\n");
exit(0);
}
$stat=0;
if($OPER=="MODIFICA") {
header(1,"<h1>Modifica scheda</h1>");
$stat=modify($DB,$Rowid,$PRIV,$USER,$FULLN,$Debug);
}
if($OPER=="ELIMINA") {
header(1,"<h1>Elimina scheda</h1>");
$stat=delete($DB,$Rowid,$PRIV,$USER,$FULLN,$Debug);
}
if($OPER=="ANNULLA") {
header(1,"<h1>Operazione Annullata</h1>");
$pargs=privargs($DB,$PRIV,$USER,$FULLN,(char)$Debug);
echo("<h3>Torna alla pagina ");
echo("<a href=$w3/priv/privindex.html?$pargs>");
echo(" selezione funzioni</a>.</h3><hr>\n");
$stat=1;
}
if($stat != 1) {
header(1,"<h1>Richiesta illegale: $OPER</h1>");
}
>
</body>
</html>
<html>
<head><title>confupdate.html - Requires confirmation for modif. op.</title></head>
<body>
<!
load "../invlib.lib"; /* Osservatorio di Arcetri. Inventory management */
load "../dblib.lib"; /* L.Fini. Oct 1997 */
/* This module receives a modification requests, */
/* build the UPDATE SQL query and asks for confir- */
/* mation */
/* Input variables: */
/* $ROWID: _rowid of record to modify */
/* $NAMES: array of field names */
/* $TYPES: array of field types */
/* $LENGS: array of field lengths */
/* $VALUE: array of field values */
header(1,"<h1>Conferma aggiornameto scheda</h1>");
$w3=w3path();
$html=htmlpath();
$tb = tbcurr();
$Rowid=(int)$ROWID;
$Debug=(int)$DEBUG;
if($Debug==1) {
echo("<pre>\n");
echo("DBG><b>Database: </b>$DB\n");
echo("DBG><b> Table: </b>$tb\n");
echo("DBG><b> w3path: </b>$w3\n");
echo("DBG><b>htmlpath: </b>$html\n");
echo("DBG><b> Rowid: </b>$Rowid\n");
echo("DBG><b> PRIV: </b>$PRIV\n");
echo("DBG><b> USER: </b>$USER\n");
echo("DBG><b> FULLN: </b>$FULLN\n");
echo("</pre>\n");
}
if((char)$ROWID == "") {
printf("<h2>Internal error: No record selected.!</h2>\n");
exit(0);
}
$tm = time();
$yr=unixtime2year($tm);
$mo=unixtime2month($tm);
$dy=unixtime2day($tm);
$moddate=encdata($dy,$mo,$yr);
$nflds=# $NAMES;
$q = "update " + $tb + " set\n\n";
$s=" ";
$i=0;
while($i<$nflds) {
if((int)$TYPES[$i]==1) { /* Campo numerico */
$v=(int)$VALUES[$i];
$q=$q + $s + $NAMES[$i] + "=" + (char)$v;
} else { /* Campo alfanumerico */
$q=$q + $s + $NAMES[$i] + "=" + chrEncode($VALUES[$i]);
}
$i=$i + 1; $s = ",\n ";
}
$q = $q + $s + "redazione=" + chrEncode($FULLN) +
",\n data_red=" + chrEncode((char)$moddate) +
"\n\nwhere _rowid=" + $ROWID;
$q = dblEncode($q);
echo("<h2>Query:</h2><blockquote><h3><pre>\n");
echo($q);
echo("</pre></h3></blockquote>\n");
echo("<form method=POST action=$w3/priv/doupdate.html>\n");
echo("<input type=hidden name=DB value=$DB>\n");
echo("<input type=HIDDEN name=ROWID value=$ROWID>\n");
echo("<input type=HIDDEN name=PRIV value=$PRIV>\n");
echo("<input type=HIDDEN name=USER value=$USER>\n");
echo("<input type=HIDDEN name=FULLN value=\"$FULLN\">\n");
echo("<input type=HIDDEN name=DEBUG value=$Debug>\n");
echo("<input type=HIDDEN name=QUERY value=\"$q\">\n");
echo("Per confermare la modifica premere: ");
echo("<input type=SUBMIT value=CONFERMA>\n");
echo("</form>\n");
$pargs=privargs($DB,$PRIV,$USER,$FULLN,$DEBUG);
echo("<h3>Annulla modifica e ");
echo("<a href=$w3/priv/privindex.html?$pargs>torna</a> alla selezione funzioni</h3>\n");
>
</body>
</html>
<html>
<head><title>doupdate.html - Actually update a record</title></head>
<body>
<!
load "../invlib.lib"; /* Osservatorio di Arcetri. Inventory management */
load "../dblib.lib"; /* L.Fini. Oct 1997 */
/* This module performs an UPDATE operation on the */
/* database. */
/* Input variables: */
/* $QUERY: operation to perform (mSQL syntax) */
/* $ROWID: _rowid of the record (for double check) */
header(1,"<h1>Aggiornamento scheda</h1>");
$Debug=(int)$DEBUG;
$w3=w3path();
if($Debug==1) {
$uid=geteuid();
echo("<pre>\n");
echo("DBG><b>Database: </b>$DB\n");
echo("DBG><b> UID: </b>$uid\n");
echo("DBG><b> w3path: </b>$w3\n");
echo("DBG><b> ROWID: </b>$ROWID\n");
echo("DBG><b> QUERY: </b>$QUERY\n");
echo("DBG><b> PRIV: </b>$PRIV\n");
echo("DBG><b> USER: </b>$USER\n");
echo("DBG><b> FULLN: </b>$FULLN\n");
echo("</pre>\n");
}
ChkPriv($DB,$PRIV,$USER,$FULLN);
$ret=plaincmd($DB,$QUERY, $Debug);
if($ret>=0) {
echo("<h3>La scheda è stata aggiornata</h3>\n");
} else {
echo("<h3>L' operazione NON È STATA ESEGUITA</h3>\n");
}
$pargs=privargs($DB,$PRIV,$USER,$FULLN,$DEBUG);
echo("<blockquote>\n");
echo("<h3><a href=$w3/priv/privindex.html?$pargs>");
echo("Torna </a> alla selezione funzioni</h3>\n");
echo("</blockquote>\n");
>
</body>
</html>
<html>
<head><title>dodelete.html - Actually delete a record</title></head>
<body>
<!
load "../invlib.lib"; /* Osservatorio di Arcetri. Inventory management */
load "../dblib.lib"; /* L.Fini. Oct 1997 */
/* This module performs a delete query */
/* (The query is built elsewhere and is sent as an */
/* argument) */
/* Input variables: */
/* $QUERY: operation to perform (mSQL syntax) */
/* $ROWID: _rowid of the record (for double check) */
header(1,"<h1>Eliminazione scheda dall'inventario</h1>");
$Debug=(int)$DEBUG;
$w3=w3path();
if($Debug==1) {
$uid=geteuid();
echo("<pre>\n");
echo("DBG><b>Database: </b>$DB\n");
echo("DBG><b> UID: </b>$uid\n");
echo("DBG><b> w3path: </b>$w3\n");
echo("DBG><b> ROWID: </b>$ROWID\n");
echo("DBG><b> QUERY1: </b>$QUERY1\n");
echo("DBG><b> QUERY2: </b>$QUERY2\n");
echo("DBG><b> PRIV: </b>$PRIV\n");
echo("DBG><b> USER: </b>$USER\n");
echo("DBG><b> FULLN: </b>$FULLN\n");
echo("</pre>\n");
}
ChkPriv($DB,$PRIV,$USER,$FULLN);
$ret=plaincmd($DB,$QUERY1, $Debug);
if($ret<0) {
echo("<h3>Il record non è stato cancellato</h3>\n");
} else {
echo("<h3>Il record è stato cancellato</h3>\n");
$ret=plaincmd($DB,$QUERY2, $Debug);
if($ret<0) {
echo("<h3>Il record NON È STATO TRASFERITO !!</h3>\n");
} else {
echo("<h3>Il record è stato trasferito</h3>\n");
}
}
$pargs=privargs($DB,$PRIV,$USER,$FULLN,$DEBUG);
echo("<blockquote>\n");
echo("<h3>Torna alla pagina <a href=$w3/priv/privindex.html?$pargs>selezione funzioni</a></h3>\n");
echo("</blockquote>\n");
>
</body>
</html>
/* THIS FILE IS GENERATED AUTOMATICALLY. DO NOT EDIT */
/* YOU MUST EDIT THE SOURCE FILE invlib.src INSTEAD */
/* file generated from config: cfgDbg on 26/1/98 9:18:51 */
/* L. Fini -- Jan 1988 */
/******************************************/
funct w3path() /* Returns full file path as seen by */
/* w3-msql */
{
return("/cgi-bin/w3-msql/lfini");
}
/******************************************/
funct htmlpath() /* Returns file path as seen by the http */
{ /* server */
return("http://www.arcetri.astro.it/~lfini/nINV");
}
/******************************************/
funct w3userdir() /* Returns the path of the "w3user" own */
{ /* directory (to store the lockfile) */
return("/tmp");
}
/******************************************/
funct dbcurr() /* Returns the name of the database */
{ /* */
return("Inventario");
}
/******************************************/
funct tbold() /* Returns the name of the obsolete device*/
{ /* table */
return("Obsoleti");
}
/******************************************/
funct tbcurr() /* Returns the name of the current device */
{ /* table */
return("Oggetti");
}
/******************************************/
funct fdlist(int $sel) /* Returns a list of main table fields */
/* If: sel=(-1) doesn't include add-on */
/* fields */
/* If: sel=0 includes add-on fields */
/* If: sel=1 includes the _rowid field */
{
if($sel==(-1)) {
$r= "numero,tipo,costruttore,venditore,modello,descrizione,matricola,valore,ente,inventario,collocazione,responsabile,data,nome_di_rete,principale,commenti";
}
if($sel==0) {
$r= "numero,tipo,costruttore,venditore,modello,descrizione,matricola,valore,ente,inventario,collocazione,responsabile,data,nome_di_rete,principale,commenti" + "," + "redazione,data_red";
}
if($sel==1) {
$r= "_rowid," + "numero,tipo,costruttore,venditore,modello,descrizione,matricola,valore,ente,inventario,collocazione,responsabile,data,nome_di_rete,principale,commenti" + "," + "redazione,data_red";
}
return($r);
}
/******************************************/
funct fmtnorm() { /* Returns format string for short list 1 */
return("%-3s %-8s %-10s %-8s %-6s %-4s %4s %2d/%2d/%4d %-12s\n");
}
/******************************************/
funct fmtval() { /* Returns format string for short list 2 */
return("%-3s %-8s %-16s %-10s %5s %6d %-6s %2d/%4d %s\n");
}
/******************************************/
funct header(int $s, /* Prints out an HTML header with a sub- */
char $subtit) /* title. */
{ /* If s=1 also prints "privileged op" */
/* warning */
echo("<center>\n");
echo("<h3>Osservatorio di Arcetri<br>\n");
echo("Dipartimento di Astronomia e Scienza dello Spazio</h3>\n");
echo("<h2>Inventario Apparecchi di Calcolo</h2>\n");
echo($subtit);
if($s==1) {
echo("<h3>L'uso di queste procedure è riservato al personale autorizzato</h3>\n");
}
echo("</center><hr><br>\n");
}
/******************************************/
funct shrthdr(char $db, /* Prints out the header for short record */
char $tb, /* listing */
char $fmt,
int $Debug)
{
echo("<form method=post action=recdetail.html>\n");
echo("<input type=hidden name=DB value=$db>\n");
echo("<input type=hidden name=TB value=$tb>\n");
echo("<input type=HIDDEN name=DEBUG value=$Debug>\n");
if($fmt == "N") {
$hd1 = "<pre><b>" +
" Numero Costruttore Matrico. Ente Num. Colloc.\n";
$hd2 = " Tipo Modello Prop. Inv. Data Nome rete</b>\n";
}
if($fmt == "V") {
$hd1 = "<pre><b>" +
" Numero Costruttore Num. Valore Ente Nome\n";
$hd2 = " Tipo Modello Matricola Inv. x1000 Prop. Data di rete</b>\n";
}
echo($hd1);
echo($hd2);
}
/******************************************/
funct shrtftr(char $Priv, /* Prints out the footer for short record */
char $User, /* listing */
char $Fulln,
char $fmt,
int $totval)
{
if($fmt == "V") {
printf("\n<b>Valore totale (Lire x 1000) ......................... %6d\n",$totval);
}
echo("</pre>\n");
echo("<hr>\n");
echo("Per visualizzare i dati completi, seleziona uno o più record\n");
echo("e premi: <input type=submit value=INVIO>\n");
if($Priv != "") {
echo("<input type=HIDDEN name=PRIV value=$Priv>\n");
echo("<input type=HIDDEN name=USER value=$User>\n");
echo("<input type=HIDDEN name=FULLN value=\"$Fulln\">\n");
}
echo("</form>\n");
}
/******************************************/
funct viewshort(char $row, /* Prints out a single record in short */
char $FORMAT, /* format */
int $Debug) /* FORMAT may be one of "N" (normal form.)*/
{ /* or "V" (format with value) */
$w3=w3path();
printf("<input type=checkbox name=ROWID value=%d>%4d ",(int)$row[0],(int)$row[1]);
$data=dcdata($row[13]);
if(# $row[2]>3) { $row[2]=strseg($row[2],0,2); }
if(# $row[3]>8) { $row[3]=strseg($row[3],0,7); }
if($FORMAT=="N") {
$fmt=fmtnorm();
if(# $row[5]>10) { $row[5]=strseg($row[5],0,9); }
if(# $row[7]>8) { $row[7]=strseg($row[7],0,7); }
if(# $row[9]>6) { $row[9]=strseg($row[9],0,5); }
if(# $row[10]>4) { $row[10]=strseg($row[10],0,3); }
if(# $row[11]>4) { $row[11]=strseg($row[11],0,3); }
if(# $row[14]>12) { $row[14]=strseg($row[14],0,11); }
printf($fmt,$row[2], $row[3], $row[5],
$row[7],$row[9], $row[10],$row[11],
$data[0], $data[1], $data[2], $row[14]);
$val1000=0;
}
if($FORMAT=="V") {
$fmt=fmtval();
$val1000 = ((int)$row[8] + 500) / 1000;
if(# $row[5]>16) { $row[5]=strseg($row[5],0,15); }
if(# $row[7]>10) { $row[7]=strseg($row[7],0,9); }
if(# $row[6]>6) { $row[6]=strseg($row[6],0,5); }
if(# $row[9]>6) { $row[9]=strseg($row[9],0,5); }
if(# $row[10]>4) { $row[10]=strseg($row[10],0,3); }
printf($fmt,$row[2], /* tipo */
$row[3], $row[5], /* costruttore, modello */
$row[7], $row[10], /* matricola, inventario */
$val1000, $row[9], /* valore, ente */
$data[1], $data[2], /* data */
$row[14]); /* nome di rete */
}
return($val1000);
}
/******************************************/
funct viewrec(char $db, /* Prints out a record in full format */
char $tb, /* reads the record from the database */
int $Rowid,
char $Priv,
int $Debug)
{
$row = getrec($db,$tb,$Rowid,$Debug,"");
if(# $row > 0) {
printrec($row);
}
}
/******************************************/
funct printrec(char $row) /* Prints out a record in full format */
/* Record data are in array $row */
{
$html=htmlpath();
$data=dcdata($row[13]);
$rdat=dcdata($row[18]);
$i=0;
printf("<center><font size=+1>\n");
printf("<h2>Record N. %s</h2></center>\n",$row[1]);
printf("<pre>");
printf(" Tipo:<b> %s</b>\n",$row[2]);
printf(" Costruttore:<b> %s</b>\n",$row[3]);
printf(" Venditore:<b> %s</b>\n",$row[4]);
printf(" Modello:<b> %s</b>\n",$row[5]);
printf(" Descrizione:<b> %s</b>\n",$row[6]);
printf(" Matricola:<b> %s</b>\n",$row[7]);
printf(" Valore:<b> %s</b>\n",$row[8]);
printf("Ente Proprietario:<b> %s</b>\n",$row[9]);
printf(" Num. Inventario:<b> %s</b>\n",$row[10]);
printf(" Collocazione:<b> %s</b> ",$row[11]);
echo("(Vedi: <a href=$html/mappe/Mappe.html>mappe</a>)\n");
printf(" Responsabile:<b> %s</b>\n",$row[12]);
printf(" Data:<b> %2d/%2d/%4d</b>\n",$data[0],$data[1],$data[2]);
printf(" Nome_di_rete:<b> %s</b>\n",$row[14]);
printf(" Principale:<b> %s</b>\n",$row[15]);
printf(" Commenti:<b> %s</b>\n",$row[16]);
printf("Scheda redatta da:<b> %s (%2d/%2d/%4d)</b>\n",$row[17],$rdat[0],$rdat[1],$rdat[2]);
printf("<hr></pre>\n");
return(1);
}
/******************************************/
funct srcform(char $db, /* Prints out the FORM for record search */
char $tb, /* inventario */
char $Priv, /* */
char $User, /* */
char $Fulln, /* */
int $Debug) /* */
{
$w3=w3path();
if($Debug==1) {
echo("<pre>\n");
echo("DBG><b>Database: </b>$db\n");
echo("DBG><b> Table: </b>$tb\n");
echo("DBG><b> w3path: </b>$w3\n");
echo("DBG><b> PRIV: </b>$Priv\n");
echo("DBG><b> USER: </b>$User\n");
echo("DBG><b> FULLN: </b>$Fulln\n");
echo("</pre>\n");
}
echo("<form method=POST action=$w3/gen/simplesrc.html>\n");
echo("<h2>Ricerca Semplice \n");
echo(" \n");
echo(" <input type=submit value=trova></h2>\n");
echo("<input type=hidden name=DEBUG value=$Debug>\n");
echo("<input type=hidden name=DB value=$db>\n");
echo("<input type=hidden name=TB value=$tb>\n");
if($Priv != "") {
echo("<input type=hidden name=PRIV value=$Priv>\n");
echo("<input type=hidden name=USER value=$User>\n");
echo("<input type=hidden name=FULLN value=\"$Fulln\">\n");
}
echo("<pre>\n");
echo("<strong>dal Numero:</strong><input type=text size=5 value=1 name=INIZIO>");
echo(" <strong>Num.schede:</strong><input type=text size=5 value=30 name=LIMIT>");
echo(" <strong>Matricola:<input type=text size=10 name=MATR>\n");
echo(" <strong>Tipo:</strong><input type=text size=5 name=TIPO> ");
echo(" <strong>Ente:</strong><input type=text size=10 name=ENTE>");
echo(" <strong>Invent.:</strong><input type=text size=5 name=INV>\n");
echo(" <strong>Stanza:</strong><input type=text size=5 name=COLLOC>");
echo(" <strong>Respons.:</strong><input type=text size=10 name=RESP>");
echo(" <strong>Modello:</strong><input type=text size=10 name=MOD>\n\n");
echo("</pre>\n");
echo("Tipo di stampa: <input type=radio name=FORMAT checked value=N>Normale\n");
echo("<input type=radio name=FORMAT value=V>Con valore\n");
echo("</form>\n");
echo("<hr>\n<form method=POST action=$w3/gen/fullsrc.html>\n");
echo("<input type=hidden name=DEBUG value=$Debug>\n");
echo("<input type=hidden name=DB value=$db>\n");
echo("<input type=hidden name=TB value=$tb>\n");
echo("<h2>Ricerca completa</h2>\n");
echo("Specificare un comando di ricerca mSQL (<a href=$w3/gen/help.html>aiuto</a>).\n");
echo("Quindi premere <return>.\n");
echo("<input type=text size=80 name=SPEC><br>\n");
echo("Tipo di stampa: <input type=radio name=FORMAT checked value=N>Normale\n");
echo("<input type=radio name=FORMAT value=V>Con valore\n");
echo("</form>\n");
}
/* dblib.lite Vers. 1.0 -- L.Fini, Jan 1998 */
/* Utility functions for database manipulation */
/*********************************************/
funct chrEncode(char $str) /* Returns msqlencoded and quoted string */
{
$r= "'" + msqlEncode($str) + "'";
return($r);
}
/*********************************************/
funct dblEncode(char $str) /* converts '"' into " */
{
$spl = split($str,"\"");
$n=# $spl;
$i=0;
$q=""; $r="";
while($i<$n) {
$r = $r + $q + $spl[$i];
$i = $i + 1;
$q = """;
}
return($r);
}
/******************************************/
funct privargs(char $db, /* Builds arguments for a URL to call */
char $Priv, /* privindex.html with method GETS */
char $User,
char $Fulln,
char $Debug)
{
$prv=urlEncode($Priv);
$usr=urlEncode($User);
$fln=urlEncode($Fulln);
$dbn=urlEncode($db);
$str="DEBUG=" + $Debug + "&DB=" + $dbn;
if($Priv != "") {$str = $str + "&PRIV=" + $prv; }
if($User != "") {$str = $str + "&USER=" + $usr; }
if($Fulln != "") {$str = $str + "&FULLN=" + $fln; }
return($str);
}
/******************************************/
funct writechk(char $file, /* Writes the check file (lockfile) */
char $uname, /* Username */
char $fulln, /* Ful name of user */
char $priv, /* Authorization token */
int $tm) /* Time */
{
umask(077); /* make it readable by myself only */
$fd=open($file,">");
if($fd<0) {
echo("<H3>Cannot open file $file (Err: $ERRMSG)</h3>\n");
exit(0);
}
fprintf($fd,"%s\n",$uname);
fprintf($fd,"%s\n",$fulln);
fprintf($fd,"%s\n",$priv);
fprintf($fd,"%d\n",$tm);
close($fd);
}
/******************************************/
funct resetlock(char $db, /* Write a new lockfile */
char $uname,
char $fulln)
{
$file=w3userdir() + "/" + $db + ".lock"; /* Generate the filename */
$tm=time();
srandom($tm);
$rd=random();
$priv=crypt((char)$rd,"LF"); /* Generate authorization token */
writechk($file,$uname,$fulln,$priv,$tm); /* write Author. file */
return($priv);
}
/******************************************/
funct Fail(char $db, /* Return an error message and code */
int $code) /* when access to privileged functions is */
{ /* denied */
$w3=w3path();
echo("<h2>Accesso al database '$db' negato ! (codice:$code)</h2>\n");
echo("<blockquote><h3><a href=$w3/priv/index.html?DB=$db>Ritorna</a>");
echo(" al controllo di accesso</h3></blockquote>\n");
exit(0);
}
/******************************************/
funct ChkPriv(char $db, /* Check authorization code */
char $priv,
char $uname,
char $fulln)
{
$w3=w3path();
$file=w3userdir() + "/" + $db + ".lock"; /* Generate the filename */
if(test("f",$file) == 0) {
Fail($db,401); /* lock file doesn't exist */
}
$fd=open($file,"<");
if($fd<0) {
Fail($db,402); /* Cannot read from lock file */
}
$runame=readln($fd); $runame=chop($runame);
$rfulln=readln($fd); $rfulln=chop($rfulln);
$rpriv=readln($fd); $rpriv=chop($rpriv);
$rtm=readln($fd); $rtm=chop($rtm);
close($fd);
if(($priv != $rpriv)||($uname != $runame)) {
if($uname != $runame) {
echo("<h2>Database currently locked by: $fulln</h2>\n");
Fail($db,101); /* Database locked by other user */
} else {
unlink($file);
Fail($db,102); /* Authorization code check failed */
}
}
$tm = (int)$rtm;
$life=time() - $tm;
if($life > 1800) {
unlink($file);
echo("<h2>Time expired. Operation is canceled</h2>");
Fail($db,103); /* Time expired */
}
}
/******************************************/
/* Decode date from internal fmt (integer)*/
funct dcdata(char $dbdata) /* returns a three elemnt array: */
/* dd[0]=day */
/* dd[1]=month */
/* dd[2]=year */
{
$dd[0]=(int)strseg($dbdata,6,7);
$dd[1]=(int)strseg($dbdata,4,5);
$dd[2]=(int)strseg($dbdata,0,3);
return($dd);
}
/******************************************/
/* Encode date to internale fmt (integer) */
funct encdata(int $day, /* */
int $month,
int $year) /* $data = $year*10000+$month*100+$day */
{
$dt= $year * 10000;
$dt= $dt + ($month * 100);
$dt= $dt + $day;
return($dt);
}
/******************************************/
funct opendb(char $dbname) /* Opens the specified database for access*/
{
$sock=msqlConnect();
if($sock < 0) {
echo("<h2>msql2d non risponde</h2>");
exit(1);
}
if(msqlSelectDB($sock, $dbname) < 0) {
echo("<h2>Errore da msqlSelectDB($dbname): $ERRMSG<h2>\n");
msqlClose($sock);
exit(1);
}
return($sock);
}
/******************************************/
funct getrec(char $db, /* Gets record with specified _rowid */
char $tb, /* from a specified database and table */
int $Rowid,
int $Debug,
char $q ) /* if $q=="" the full query is built by */
/* this subprogram. */
/* if $q=="select row1,row2,...,rowN" */
/* this part is used in the */
/* query to select specified */
/* fields */
{
$sock=opendb($db);
if($q == "") {
$q = "select " + fdlist(1);
}
$q = $q + " from " + $tb + " where _rowid=" + (char)$Rowid;
if($Debug==1) {
printf("<p><pre><b>Query: </b>%s</pre><p><hr>\n",$q);
}
if (msqlQuery($sock, $q) < 0) {
echo("<h2>Errore da msqlQuery</h2>");
echo("<b>Query: </b> $q <br>");
echo("<b>ErrMsg: </b> $ERRMSG<p>\n");
msqlClose($sock);
exit(1);
}
$res=msqlStoreResult();
$row = msqlFetchRow($res);
msqlClose($sock);
if ( # $row == 0) {
echo("<h2>Errore Interno</h2>");
echo("Il record (_rowid: $Rowid) non esiste nel database!");
exit(1);
}
$i=1; /* This loop is to transform NULL fields into "" */
while($i<# $row) {
$row[$i]=(char)$row[$i];
$i=$i + 1;
}
return($row);
}
/******************************************/
funct searchq(char $db, /* Sends a search query */
char $cm,
int $Debug)
{
$sock=opendb($db);
if($Debug==1) {
echo("<pre>DBG>Entered searchq\n");
echo("DBG> <b>Database: </b> $db \n");
echo("DBG> <b> Query: </b> $cm \n</pre>\n");
}
$ret= msqlQuery($sock, $cm);
if ($ret < 0) {
echo("<h2>Errore da msqlQuery</h2>");
echo("<b>Query: </b> $cm <br>");
echo("<b>ErrMsg: </b> $ERRMSG<p>\n");
msqlClose($sock);
exit(1);
}
$ret=msqlStoreResult();
msqlClose($sock);
return($ret);
}
/******************************************/
funct plaincmd(char $db, /* Sends the specified SQL command */
char $cm, /* The db is openend end then closed */
int $Debug)
{
$sock=opendb($db);
if($Debug==1) {
echo("<pre>DBG>Entered plaincmd\n");
echo("DBG> <b>Database: </b> $db \n");
echo("DBG> <b> Query: </b> $cm \n</pre>\n");
}
$ret= msqlQuery($sock, $cm);
if ($ret < 0) {
echo("<h2>Errore da msqlQuery</h2>");
echo("<b>Query: </b> $cm <br>");
echo("<b>ErrMsg: </b> $ERRMSG<p>\n");
}
msqlClose($sock);
return($ret);
}
/******************************************/
funct docommand(char $db, /* Sends the specified SQL query appending*/
char $rowid, /* the proper "where" clause */
char $cmd,
int $Debug)
{
if($rowid == "") {
printf("<h2>Internal error: No record selected.!</h2>\n");
exit(0);
}
$q=$cmd + " where _rowid=" + $rowid;
$ret=plaincmd($db,$q,$Debug);
return($ret);
}
/******************************************/
funct selecttable(char $db, /* Prints out an HTML menu of type SELECT */
char $tbname, /* getting data from the specified table */
int $lng, /* Length of the menu field */
char $pname, /* name of the HTML argument */
char $slctd, /* name of a field to be "selected" */
int $Debug)
{
$q="select item from " + $tbname + " order by item";
$res=searchq($db,$q,$Debug);
$n = # $selected - 1;
$loop=1;
echo("<select name=$pname size=$lng>\n");
while($loop>0) {
$row = msqlFetchRow($res);
if ( # $row == 0) {
$loop=0;
} else {
$s="";
if($n>=0) {
if(strseg($row[0],0,$n) == $slctd) {
$s="selected";
}
}
echo("<option $s>$row[0]</option>\n");
}
}
echo("</select>\n");
}
/******************************************/
funct getnext(char $db, /* Get the next free record number */
char $tb,
char $fd, /* name of the field containing rec.numb. */
int $Dbg)
{
$q = "select " + $fd + " from " + $tb + " order by " + $fd + " desc limit 1";
$res=searchq($db,$q,$Dbg);
$row = msqlFetchRow($res);
$n = (int)$row[0] + 1;
return($n);
}
/******************************************/
funct fields(char $db, /* Analize structure of the given table */
char $tb) /* Returns array with elements containing:*/
{ /* */
/* "name,type,length" (comma separated) */
/* (type=0: _rowid) */
$sock=opendb($db);
$res=msqlInitFieldList ($sock,$tb);
$field = msqlListField($res);
$fld[0]="_rowid,0,0";
$i=1;
while( # $field > 0) {
if(($field[2]==1)||($field[2]==2)||($field[2]==6)) {
$ty = $field[2];
$fld[$i] = $field[0] + "," + (char)$ty + "," + (char)$field[3];
$i=$i + 1;
}
$field = msqlListField($res);
}
msqlClose($sock);
return($fld);
}
This document was generated using the LaTeX2HTML translator Version 96.1 (Feb 5, 1996) Copyright © 1993, 1994, 1995, 1996, Nikos Drakos, Computer Based Learning Unit, University of Leeds.
The command line arguments were:
latex2html -split 0 -external_images -html_version 3.1 techdetails.
The translation was initiated by Luca Fini on Thu Feb 26 16:40:20 MET 1998