From 94f072fe15fbbc33afa7f4aebc10ab41e25ff834 Mon Sep 17 00:00:00 2001 From: Metabox Date: Thu, 18 Jul 2019 13:05:50 +1000 Subject: [PATCH] Qill work. --- htdocs/cgi-bin/main.cgi | 10 +- htdocs/cgi-bin/wsrc/main.cgi | 1035 ++++++++++++++++++++++++++++++++++ htdocs/cgi-bin/wsrc/main.css | 8 + htdocs/cgi-bin/wsrc/main.js | 56 +- 4 files changed, 1098 insertions(+), 11 deletions(-) create mode 100755 htdocs/cgi-bin/wsrc/main.cgi diff --git a/htdocs/cgi-bin/main.cgi b/htdocs/cgi-bin/main.cgi index 50c0b0a..c76f2d7 100755 --- a/htdocs/cgi-bin/main.cgi +++ b/htdocs/cgi-bin/main.cgi @@ -570,11 +570,11 @@ $cats  Ammount: - +   RTF Document -
  -
+
  +
@@ -982,8 +982,8 @@ sub quill { return qq{ -
-
+!; + + if ( $rs_prev && $rs_prev > 0 && $tbl_start > 0 && $rs_page > 0 ) { + + $tbl = $tbl . qq!!; + + } + else { + $tbl .= ''; + } + + $tbl .= +''; + + if ( $is_end_of_rs == 1 ) { + $tbl = $tbl . ''; + } + else { + + $tbl .= +qq!!; + + } + + $tbl = $tbl . ''; +} + +sub authenticate { + try { + + if ($AUTHORITY) { + return; + } + + my $st = $db->prepare( + "SELECT * FROM AUTH WHERE alias='$userid' and passw='$password';" + ); + $st->execute(); + if ( $st->fetchrow_array() ) { return; } + + #Check if passw has been wiped for reset? + $st = $db->prepare("SELECT * FROM AUTH WHERE alias='$userid';"); + $st->execute(); + my @w = $st->fetchrow_array(); + if ( @w && $w[1] == "" ) { + + #Wiped with -> UPDATE AUTH SET passw='' WHERE alias='$userid'; + $st = $db->prepare( + "UPDATE AUTH SET passw='$password' WHERE alias='$userid';"); + $st->execute(); + return; + } + + print $cgi->header( -expires => "+0s", -charset => "UTF-8" ); + print $cgi->start_html( + -title => "Personal Log Login", + -script => { -type => 'text/javascript', -src => 'wsrc/main.js' }, + -style => { -type => 'text/css', -src => 'wsrc/main.css' }, + ); + + print $cgi->center( + $cgi->div("Access Denied! alias:$userid pass:$password") ); + print $cgi->end_html; + + $db->disconnect(); + $session->flush(); + exit; + + } + catch { + print $cgi->header( -expires => "+0s", -charset => "UTF-8" ); + print $cgi->p( "ERROR:" . $_ ); + print $cgi->end_html; + exit; + } +} + +sub fetchAutocomplete { + try { + + while ( my @row = $st->fetchrow_array() ) { + my $log = $row[0]; + + #Decode escaped \\n + $log =~ s/\\n/\n/gs; + $log =~ s/''/'/g; + + #Replace link to empty string + my @words = split( /($re_a_tag)/si, $log ); + foreach my $ch_i (@words) { + next if $ch_i =~ /$re_a_tag/; + next if index( $ch_i, " -1; + $ch_i =~ s/https//gsi; + $ch_i =~ s/($RE{URI}{HTTP})//gsi; + } + $log = join( ' ', @words ); + @words = split( ' ', $log ); + foreach my $word (@words) { + + #remove all non alphanumerics + $word =~ s/[^a-zA-Z]//gs; + if ( length($word) > 2 ) { + $word = lc $word; + + #parse for already placed words, instead of using an hash. + my $idx = index( $autowords, $word, 0 ); + if ( $idx > 0 ) { + my $end = index( $autowords, '"', $idx ); + my $existing = substr( $autowords, $idx, $end - $idx ); + next if $word eq $existing; + } + + $autowords .= qq(,"$word"); + if ( $aw_cnt++ > $AUTO_WRD_LMT ) { + last; + } + } + } + + if ( $aw_cnt > $AUTO_WRD_LMT ) { + last; + } + } + + } + catch { + print "SERVER ERROR:" . $_; + } +} + +sub getConfiguration { + my $db = shift; + try { + $st = $db->prepare("SELECT * FROM CONFIG;"); + $st->execute(); + + while ( my @r = $st->fetchrow_array() ) { + + switch ( $r[1] ) { + case "REC_LIMIT" { $REC_LIMIT = $r[2] } + case "TIME_ZONE" { $TIME_ZONE = $r[2] } + case "PRC_WIDTH" { $PRC_WIDTH = $r[2] } + case "SESSN_EXPR" { $SESSN_EXPR = $r[2] } + case "DATE_UNI" { $DATE_UNI = $r[2] } + case "LANGUAGE" { $LANGUAGE = $r[2] } + case "IMG_W_H" { $IMG_W_H = $r[2] } + case "AUTO_WRD_LMT" { $AUTO_WRD_LMT = $r[2] } + else { + print "Unknow variable setting: " . $r[1] . " == " . $r[2]; + } + } + + } + } + catch { + print "SERVER ERROR:" . $_; + } +} + +sub camm { + my $amm = sprintf("%.2f", shift @_); + # Add one comma each time through the do-nothing loop + 1 while $amm =~ s/^(-?\d+)(\d\d\d)/$1,$2/; +return $amm; +} + +sub quill { +return qq{ + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+ +} +} \ No newline at end of file diff --git a/htdocs/cgi-bin/wsrc/main.css b/htdocs/cgi-bin/wsrc/main.css index ef8a08e..1824197 100644 --- a/htdocs/cgi-bin/wsrc/main.css +++ b/htdocs/cgi-bin/wsrc/main.css @@ -200,4 +200,12 @@ img { #editor-container { height: 480px; + border-top: 1px solid gray; + border-right: 1px solid gray; + background-color: #e6ffff; +} + +#toolbar-container { + background-color: #98e6e6; + margin-bottom: 3px; } \ No newline at end of file diff --git a/htdocs/cgi-bin/wsrc/main.js b/htdocs/cgi-bin/wsrc/main.js index d386481..229450e 100644 --- a/htdocs/cgi-bin/wsrc/main.js +++ b/htdocs/cgi-bin/wsrc/main.js @@ -7,6 +7,11 @@ var _MAP = new Map(); var MNU_SCROLLING = false; var SRCH_VISIBLE = true; +var QUILL; +var Delta; +var RTF_SET = false; +var CHANGE; + function loadedBody(toggle) { @@ -103,19 +108,21 @@ function loadedBody(toggle) { $('#ec').show(); - - var quill = new Quill('#editor-container', { + $("#RTF").prop("checked", false); + // $('#tbl_doc').toggle(); + // $('#toolbar-container').toggle(); + QUILL = new Quill('#editor-container', { modules: { formula: true, syntax: true, toolbar: '#toolbar-container' }, - placeholder: 'Compose an epic...', + placeholder: 'Enter your Document here...', theme: 'snow' }); - - $('#tbl_doc').toggle(); - // $('#toolbar-container').toggle(); + Delta = Quill.import('delta'); + CHANGE = new Delta(); + // toggleDocument(); } @@ -316,7 +323,44 @@ function viewAll() { return false; } +function toggleDocument() { + $('#tbl_doc').toggle(); + $('#toolbar-container').toggle(); + if (!RTF_SET) { + + CHANGE = new Delta(); + QUILL.on('text-change', function(delta) { + CHANGE = CHANGE.compose(delta); + }); + + setInterval(function() { + if (CHANGE.length() > 0) { + console.log('Saving changes', CHANGE); + /* + Send partial changes + $.post('/your-endpoint', { + partial: JSON.stringify(change) + }); + + Send entire document + $.post('/your-endpoint', { + doc: JSON.stringify(QUILL.getContents()) + }); + */ + CHANGE = new Delta(); + } + }, 10 * 1000); + RTF_SET = true; + } + + +} +function saveRTF() { + if (RTF_SET) { + $.post('json.pl?m=1', { doc: JSON.stringify(QUILL.getContents()) }); + } +} function toggleSearch() { $("html, body").animate({ scrollTop: 0 }, "slow"); -- 2.34.1