]> lifelog.hopto.org Git - LifeLog.git/commitdiff
JSON, RTF dev and various fixes, stage 1.
authorMetabox <redacted>
Fri, 2 Aug 2019 21:04:38 +0000 (07:04 +1000)
committerMetabox <redacted>
Fri, 2 Aug 2019 21:04:38 +0000 (07:04 +1000)
dbLifeLog/main.cnf
htdocs/cgi-bin/json.cgi
htdocs/cgi-bin/login_ctr.cgi
htdocs/cgi-bin/main.cgi
htdocs/cgi-bin/wsrc/main.js

index 0894b0c54fd3124dba9aceaec659dcdf2312e187..6bd1047c7546d845ac8294fe341ba35ccdb6e068 100644 (file)
@@ -18,6 +18,7 @@ Credential format:<<AUTO_LOGIN <{alias}/{password}> , must be enabled option.
 22|$AUTO_LOGIN  = 0`Autologin option, that expires only if login out. Enter Credentials in main.cnf.
 24|$FRAME_SIZE  = 0`Youtube frame size settings, 0 - Large, 1 - Medium, 2- Small.
 26|$RTF_SIZE    = 2`RTF Document height, 0 - Large, 1 - Medium, 2- Small.
+28|$THEME       = Standard`Theme to applay, Standard, Sun, Moon, Earth.
 <<CAT<3>
 01|Unspecified `For quick uncategorised entries.
 03|File System `Operating file system short log.
index 7c77d4f868a6f3e0a348f59629b3ce362863b86b..b33b87be5ae40aef62c9cbd659323ce15bfe5561 100755 (executable)
@@ -15,12 +15,16 @@ use DBI;
 
 use DateTime;
 use DateTime::Format::SQLite;
+use DateTime::Format::Strptime;
 use DateTime::Duration;
 use Date::Language;
 use Date::Parse;
 use Time::localtime;
 use Regexp::Common qw /URI/;
 use JSON;
+use IO::Compress::Gzip qw(gzip $GzipError);
+use Compress::Zlib;
+
 
 #DEFAULT SETTINGS HERE!
 our $REC_LIMIT    = 25;
@@ -41,26 +45,26 @@ my $cgi = CGI->new;
 my $session =
   new CGI::Session( "driver:File", $cgi, { Directory => $LOG_PATH } );
 my $sid      = $session->id();
-my $dbname   = "";#$session->param('database');
+my $dbname   = $session->param('database');
 my $userid   = $session->param('alias');
 my $password = $session->param('passw');
 my $action   = $cgi->param('action');
 my $lid      = $cgi->param('id');
 my $doc      = $cgi->param('doc');
+my $error    = "";
 
 if ($AUTHORITY) {
     $userid = $password = $AUTHORITY;
     $dbname = 'data_' . $userid . '_log.db';
 }
 elsif ( !$userid || !$dbname ) {
-   print $cgi->redirect("login_ctr.cgi?CGISESSID=$sid");
-   exit;
+   print $cgi->redirect("login_ctr.cgi?CGISESSID=$sid");
+   exit;
 }
 
 my $database = '../../dbLifeLog/' . $dbname;
 my $dsn      = "DBI:SQLite:dbname=$database";
-my $db;
-#$db      = DBI->connect( $dsn, $userid, $password, { RaiseError => 1 } );
+my $db = DBI->connect( $dsn, $userid, $password, { RaiseError => 1 } );
 
 ### Authenticate session to alias password
 #&authenticate;
@@ -70,19 +74,24 @@ my $lang  = Date::Language->new($LANGUAGE);
 my $today = DateTime->now;
 $today->set_time_zone($TIME_ZONE);
 
+my $strp = DateTime::Format::Strptime->new(
+    pattern   => '%F %T',
+    locale    => 'en_AU',
+    time_zone => $TIME_ZONE,
+    on_error  => 'croak',
+);
 
+my ($response, $json) = 'Feature Under Development!';
 
 ###############
-#&processSubmit;
+&processSubmit;
 ###############
-my $json = JSON->new->utf8->space_after->pretty->allow_blessed->encode
-     ({date => DateTime::Format::SQLite->format_datetime($today), 
-       response_origin => "LifeLog.".$RELEASE_VER,
-       response => "Feature Under Development!",
-       alias => $userid,
-       log_id => $lid,
-       received => $doc
-    });
+if($action eq 'load' && !$error){    
+      $json = $response;    
+}
+else{
+   &defaultJSON;
+}
 
 
 print $cgi->header( -expires => "+0s", -charset => "UTF-8" );
@@ -93,14 +102,54 @@ undef($session);
 exit;
 
 
+sub defaultJSON{
+     $json = JSON->new->utf8->space_after->pretty->allow_blessed->encode
+     ({date => $strp->format_datetime($today), 
+       response_origin => "LifeLog.".$RELEASE_VER,
+       response => $response,
+       alias => $userid,
+       log_id => $lid,
+       database=>$database, action => $action, error=>$error
+       #received => $doc       
+   });   
+}
+
 sub processSubmit {
 
      # my $date = $cgi->param('date');
-    
+     my $st;
+  
       try {
+        if($action eq 'store'){
+    
+           my $zip = compress($doc,Z_BEST_COMPRESSION);
+           $st = $db->prepare("SELECT LID FROM NOTES WHERE LID = '$lid';"); 
+           $st -> execute();
+           if($st->fetchrow_array() eq undef) {
+               $st = $db->prepare("INSERT INTO NOTES(LID, DOC) VALUES (?, ?);");               
+               $st->execute($lid, $zip);
+               $response = "Stored Document (id:$lid)!";
+           }
+           else{
+               $st = $db->prepare("UPDATE NOTES SET DOC = ? WHERE LID = '$lid';");
+               $st->execute($zip);
+               $response = "Updated Document (id:$lid)!";
+           }
+
+        }
+        elsif($action eq 'load'){
+           $st = $db->prepare("SELECT DOC FROM NOTES WHERE LID = '$lid';"); 
+           $st -> execute();
+           $doc = ($st->fetchrow_array())[0];
+           $response = uncompress($doc);
+        }
+        else{
+            $error = "Your action ($action) sux's a lot!";
+        }
+
       }
       catch {
-          print "ERROR:" . $_;
+          $error = ":LID[$lid]-> ".$_;
     }
 }
 
index 65fb99b8fe78dfbebe9add977b6201760e454db5..b93920e46e327afc2ab51b5c57cf6b5f6a839079 100755 (executable)
@@ -251,40 +251,34 @@ try{
        $st = $db->prepare(selSQLTbl('NOTES'));
        $st->execute();
        if(!$st->fetchrow_array()) {
-my $stmt = qq(
-                                                                               CREATE VIRTUAL TABLE NOTES USING fts4(
-                                                                                               ID INT PRIMARY KEY NOT NULL,
-                                                                                               ID_LOG INT,
-                                                                                               AUTHOR,
-                                                                                               CONTENT TEXT NOT NULL,
-                                                                                               compress=zip, uncompress=unzip
-                                                                               );
-); 
+               my $stmt = qq(
+                       CREATE TABLE NOTES (LID PRIMARY KEY NOT NULL, DOC TEXT);
+               ); 
                $rv = $db->do($stmt);
                if($rv < 0){print "<p>Error->"& $DBI::errstri &"</p>"};
-               $st = $db->prepare("SELECT * FROM AUTH WHERE alias='$alias' AND passw='$passw';");
-               $st->execute();
-               if(!$st->fetchrow_array()) {
-           $st = $db->prepare('INSERT INTO AUTH VALUES (?,?)');
-           $st->execute($alias, $passw);
-               }
        }
 
+       $st = $db->prepare("SELECT * FROM AUTH WHERE alias='$alias' AND passw='$passw';");
+       $st->execute();
+       if(!$st->fetchrow_array()) {
+               $st = $db->prepare('INSERT INTO AUTH VALUES (?,?)');
+               $st->execute($alias, $passw);
+       }
  
        $st = $db->prepare(selSQLTbl('CONFIG'));
        $st->execute();
-  if(!$st->fetchrow_array()) {
+    if(!$st->fetchrow_array()) {
                #v.1.3 -> v.1.4
                #alter table CONFIG add DESCRIPTION VCHAR(128);
 
     my $stmt = qq(
-                                                                               CREATE TABLE CONFIG(
-                                                                                               ID TINY PRIMARY KEY NOT NULL,
-                                                                                               NAME VCHAR(16),
-                                                                                               VALUE VCHAR(28),
-                                                                                               DESCRIPTION VCHAR(128)
-                                                                               );
-                                                                               CREATE INDEX idx_config_name ON CONFIG (NAME);
+                                       CREATE TABLE CONFIG(
+                                                       ID TINY PRIMARY KEY NOT NULL,
+                                                       NAME VCHAR(16),
+                                                       VALUE VCHAR(28),
+                                                       DESCRIPTION VCHAR(128)
+                                       );
+                                       CREATE INDEX idx_config_name ON CONFIG (NAME);
                );
                $rv = $db->do($stmt);
                $st->finish();
index 93331d7b214c4ee9af72c280b16ce14d6eeff7f3..e27ac2b30774f7cd8bb74b9556f797c723905304 100755 (executable)
@@ -35,7 +35,8 @@ our $AUTHORITY    = '';
 our $IMG_W_H      = '210x120';
 our $AUTO_WRD_LMT = 1000;
 our $FRAME_SIZE   = 0;
-our $RTF_SIZE   = 0;
+our $RTF_SIZE     = 0;
+our $THEME        = 'Standard';
 #END OF SETTINGS
 
 my $cgi = CGI->new;
@@ -104,13 +105,18 @@ else {    #defaults
       $imgh = 120;
 }
 
+my $bgcol = '#c8fff8';
+if($THEME eq 'Sun'){
+   $bgcol =  '#D4AF37';
+}
+
 print $cgi->header(
       -expires => "0s",
       -charset => "UTF-8"
   );
 print $cgi->start_html(
       -title   => "Personal Log",
-      -BGCOLOR => "#c8fff8",
+      -BGCOLOR => $bgcol,
       -onload  => "loadedBody('" . $toggle . "');",
       -style   => [
           { -type => 'text/css', -src => 'wsrc/main.css' },
index 0f8846fa1be20f48fdb0ebf95b634d04fae4a591..e66abd66528b7a1b9a1284c520fd55150d180797 100644 (file)
@@ -226,7 +226,7 @@ function validLog(log) {
 
 function setNow() {
 
-    var date = $("#frm_entry").date;
+    var date = document.getElementById("frm_entry").date;
     var dt = new Date();
     var mm = fix0(dt.getMonth() + 1);
     var dd = fix0(dt.getDate());
@@ -519,11 +519,13 @@ function saveRTF(id, action) {
     // alert(JSON.stringify(QUILL.getContents()));
     //Disabled on new log entry. Save and edit, obtains id. For now. @2019-07-20
     //if (id > 0) {
-    $.post('json.cgi?action=' + action + '&id=' + id, { doc: JSON.stringify(QUILL.getContents()) }, saveRTFResult);
+    $.post('json.cgi', {action:action, id:id, doc: JSON.stringify(QUILL.getContents()) }, saveRTFResult);
     //}
 }
 
 function saveRTFResult(result) {
-    alert("Result->" + result);
-    console.log(result);
+    //alert("Result->" + result);
+    console.log("Result->" + result);
+    var obj = JSON.parse(result);
+    alert(obj.response);
 }
\ No newline at end of file