$line"; } close(SGML); $sgml .= "
#! /usr/bin/perl $workpath = "/tmp"; use CGI qw(:standard); use Pg; $query = new CGI; $dbmain = "ldp"; @row; # Read parameters $doc_id = param('doc_id'); $conn=Pg::connectdb("dbname=$dbmain"); die $conn->errorMessage unless PGRES_CONNECTION_OK eq $conn->status; $username = $query->remote_user(); $result=$conn->exec("SELECT username, admin, maintainer_id FROM username WHERE username='$username'"); @row = $result->fetchrow; if ($username ne $row[0]) { print $query->redirect("../newaccount.html"); exit; } else { if (($row[1] ne 't') and ($row[2] != $doc_id)) { print $query->redirect("../wrongpermission.html"); exit; } } $save = param('Save'); $preview = param('Preview'); $docbook = param('DocBook'); $wiki = param('wiki'); while ($wiki =~ /\'/) { $wiki =~ s/\'/a1s2d3f4/; } while ($wiki =~ /a1s2d3f4/) { $wiki =~ s/a1s2d3f4/\'\'/; } $notes = param('notes'); while ($notes =~ /\'/) { $notes =~ s/\'/a1s2d3f4/; } while ($notes =~ /a1s2d3f4/) { $notes =~ s/a1s2d3f4/\'\'/; } $revision = param('revision'); $username = $query->remote_user(); if ($save) { #find out how many prior revisions there were $result = $conn->exec("SELECT count(*) FROM document_wiki WHERE doc_id = $doc_id"); die $conn->errorMessage unless PGRES_TUPLES_OK eq $result->resultStatus; @row = $result->fetchrow; $revisions = $row[0]; if ($revisions >= $revision ) { &printheader; print "
Edit conflict!\n"; print "
You were editing version $revisions, but trying to save to version $revision\n"; print end_html; } else { $revision = $revisions + 1; $sql = "INSERT INTO document_wiki(doc_id, revision, date_entered, wiki, notes, username) VALUES ($doc_id, $revision, now(), '$wiki', '$notes', '$username')"; $result=$conn->exec($sql); print $query->redirect("document_edit.pl?doc_id=$doc_id"); } exit; } #load document meta-data $result = $conn->exec("SELECT title, filename FROM document WHERE doc_id = $doc_id"); die $conn->errorMessage unless PGRES_TUPLES_OK eq $result->resultStatus; @row = $result->fetchrow; $title = $row[0]; $title =~ s/\s+$//; $filename = $row[1]; #find out how many prior revisions there were $result = $conn->exec("SELECT count(*) FROM document_wiki WHERE doc_id = $doc_id"); die $conn->errorMessage unless PGRES_TUPLES_OK eq $result->resultStatus; @row = $result->fetchrow; $revisions = $row[0]; #if we're not previewing, load data from database and determine version unless ($preview or $docbook) { $result = $conn->exec("SELECT wiki FROM document_wiki WHERE doc_id = $doc_id ORDER BY revision DESC LIMIT 1, 0"); die $conn->errorMessage unless PGRES_TUPLES_OK eq $result->resultStatus; @row = $result->fetchrow; $revision = $revisions + 1; $wiki = $row[0]; $wiki =~ s/\s+$//; &printheader; print "
\n"; print end_html; } if ($preview or $docbook) { $txtfile = "$workpath/foo.txt"; $sgmlfile = $txtfile; $sgmlfile =~ s/\.txt/\.sgml/; $htmlfile = $txtfile; $htmlfile =~ s/\.txt/\.html/; open(TXT, "> $txtfile"); print TXT $wiki; close(TXT); $cmd = "/usr/lib/cgi-bin/gldp.org/txt2db.pl -o $sgmlfile $txtfile"; system($cmd); $sgml = '' . "\n"; $sgml .= "\n"; while ($sgml =~ /\) { $sgml =~ s/\</; } while ($sgml =~ /\>/) { $sgml =~ s/\>/>/; } print $sgml; print "\n"; print "