From: Metabox Date: Fri, 26 Apr 2019 08:57:00 +0000 (+1000) Subject: Added config file processing for system settings. X-Git-Url: https://lifelog.hopto.org/gitweb/?a=commitdiff_plain;h=bf8d6230af1a1406eef0178aa00e2c99a0535ceb;p=LifeLog.git Added config file processing for system settings. --- diff --git a/htdocs/cgi-bin/config.cgi b/htdocs/cgi-bin/config.cgi index 2f040d3..d97705b 100755 --- a/htdocs/cgi-bin/config.cgi +++ b/htdocs/cgi-bin/config.cgi @@ -21,9 +21,11 @@ use Text::CSV; #DEFAULT SETTINGS HERE! our $REC_LIMIT = 25; our $TIME_ZONE = 'Australia/Sydney'; +our $LANGUAGE = 'English'; our $PRC_WIDTH = '60'; our $LOG_PATH = '../../dbLifeLog/'; our $SESSN_EXPR = '+30m'; +our $DATE_UNI = '0'; our $RELEASE_VER = '1.3'; #END OF SETTINGS @@ -106,8 +108,6 @@ my $tbl = ').$tbl.qq( @@ -116,15 +116,15 @@ my $frm = qq( - - + +
   Log Configuration In -> $dbname 
WARNING! - Removing and changing categories is permanent!
Adding one must have unique ID.
- Blanking an category name will remove and seek change LOG
records to Unspecified (id 1)!
- Also ONLY the category Unspecified You can't REMOVE!
If changing here things? - Make a backup! (copy existing db file)
+ Removing or changing categories is permanent! Each category one must have an unique ID. + Blank a category name to remove it. LOG records will change to the Unspecified (id 1) category!
+ The category Unspecified, can't be removed! +

); @@ -143,13 +143,26 @@ while(my @row = $dbs->fetchrow_array()) { my $n = $row[1]; my $v = $row[2]; if($n eq "TIME_ZONE"){ - $n = ''.$n.''; - if($tz){ - $v = $tz; - } - $v = ''; - - }elsif($n ne "RELEASE_VER"){ + $n = ''.$n.''; + if($tz){ + $v = $tz; + } + $v = ''; + } + elsif($n eq "DATE_UNI"){ + my($l,$u)=("",""); + if($v == 0){ + $l = "SELECTED" + } + else{ + $u = "SELECTED" + } + $v = qq(); + } + elsif($n ne "RELEASE_VER"){ $v = ''; } $tbl = $tbl. @@ -171,15 +184,12 @@ my $frmVars = qq( #Page printout from here! # my $prc_hdr = $PRC_WIDTH-2; -print '
'; -print "
Log Configuration In -> $dbname
"; + print '
'; print "\n
\n" . $frm ."\n
\n"; print "\n
\n" . $frmVars."\n
\n"; print "\n
\nSTATUS:" .$status. "\n
\n"; print qq(
Back to Main Log


\n - - \n \n @@ -198,10 +208,11 @@ print "

CSV File Format


-
[Export Log to CSV]   +
\n
\n
+ [View the Categories in CSV Format]
\n +
); print '
'; @@ -314,27 +325,7 @@ catch{ } -sub getConfiguration{ - try{ - $dbs = $db->prepare("SELECT * FROM CONFIG;"); - $dbs->execute(); - while (my @r=$dbs->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]} - else {print "Unknow variable setting: ".$r[1]. " == ". $r[2]} - } - - } - } - catch{ - print "SERVER ERROR:".$_; - } -} sub changeSystemSettings{ try{ @@ -348,6 +339,8 @@ sub changeSystemSettings{ case "TIME_ZONE" {$TIME_ZONE=$var; updConfSetting($r[0],$var)} case "PRC_WIDTH" {$PRC_WIDTH=$var; updConfSetting($r[0],$var)} case "SESSN_EXPR"{$SESSN_EXPR=$var; updConfSetting($r[0],$var)} + case "DATE_UNI" {$DATE_UNI=$var; updConfSetting($r[0],$var)} + case "LANGUAGE" {$LANGUAGE=$var; updConfSetting($r[0],$var)} } } } @@ -370,8 +363,6 @@ sub updConfSetting{ } } - - sub exportLogToCSV{ try{ @@ -402,6 +393,7 @@ sub exportLogToCSV{ print "SERVER ERROR->exportLogToCSV:".$_; } } + sub exportCategoriesToCSV{ try{ @@ -529,3 +521,29 @@ sub updateLOGDB{ } } } + + +sub getConfiguration{ + try{ + $dbs = $db->prepare("SELECT * FROM CONFIG;"); + $dbs->execute(); + + while (my @r=$dbs->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]} + else {print "Unknow variable setting: ".$r[1]. " == ". $r[2]} + } + + } + } + catch{ + print "SERVER ERROR:".$_; + } + +} \ No newline at end of file diff --git a/htdocs/cgi-bin/login_ctr.cgi b/htdocs/cgi-bin/login_ctr.cgi index a78298c..8872887 100755 --- a/htdocs/cgi-bin/login_ctr.cgi +++ b/htdocs/cgi-bin/login_ctr.cgi @@ -16,13 +16,14 @@ use DateTime::Format::SQLite; use DateTime::Duration; use Text::CSV; - #DEFAULT SETTINGS HERE! our $REC_LIMIT = 25; our $TIME_ZONE = 'Australia/Sydney'; +our $LANGUAGE = 'English'; our $PRC_WIDTH = '60'; our $LOG_PATH = '../../dbLifeLog/'; our $SESSN_EXPR = '+30m'; +our $DATE_UNI = '0'; our $RELEASE_VER = '1.3'; #END OF SETTINGS @@ -181,24 +182,16 @@ try{ $st->execute(); if(!$st->fetchrow_array()) { my $stmt = qq( - CREATE TABLE CONFIG( - ID TINY PRIMARY KEY NOT NULL, - NAME VCHAR(16), - VALUE VCHAR(64) - ); + CREATE TABLE CONFIG( + ID TINY PRIMARY KEY NOT NULL, + NAME VCHAR(16), + VALUE VCHAR(64) + ); ); $rv = $db->do($stmt); - populateConfig($db); - - } - else{ - #TODO Check table and update existing table for subsequent releases with new settings. - $st = $db->prepare('SELECT * FROM CONFIG'); - $st->execute(); - if(!$st->fetchrow_array()) { - populateConfig($db); - } } + populateConfig($db); + } catch{ print $cgi->header; @@ -207,6 +200,51 @@ try{ exit; } } +sub populateConfig{ + + open(my $fh, '<', './main.cnf' ) or die "Can't open main.cnf: $!"; + my $db = shift; + my ($did,$name, $value); + + my $st = $db->prepare("SELECT count(*) FROM CONFIG;"); + $st->execute(); + my $cnt = $st->fetchrow_array(); + if($cnt != 0){ + return; + } +try{ + while (my $line = <$fh>) { + chomp $line; + my %hsh = $line =~ m[(\S+)\s*=\s*(\S+)]g; + for my $key (keys %hsh) { + my %nash = $key =~ m[(\S+)\s*\|\$\s*(\S+)]g; + + for my $id (keys %nash) { + $did = $id; + $name = $nash{$id}; + $value = $hsh{$key}; + my $st = $db->prepare("SELECT * FROM CONFIG WHERE NAME LIKE '$name';"); + $st->execute(); + if(!$st->fetchrow_array()){ + #TODO Check if script id is unique to database? If not script prevails to database entry. + #if user setting from previous release, must be migrated later. + $st = $db->prepare('INSERT INTO CONFIG VALUES (?,?,?)'); + $did = $id; + $st->execute($id, $name,$value); + } + } + } + } + + close $fh; + } catch{ + close $fh; + print $cgi->header; + print "SERVER ERROR [$did, $name,$value]:".$_; + print $cgi->end_html; + exit; + } +} sub selSQLTbl{ my $name = $_[0]; @@ -228,16 +266,6 @@ sub insertDefCats{ $st->finish(); } -sub populateConfig{ - my $db = shift; - my $st = $db->prepare('INSERT INTO CONFIG VALUES (?,?,?)'); - $st->execute(0,"RELEASE_VER",$RELEASE_VER); - $st->execute(1,"REC_LIMIT", $REC_LIMIT); - $st->execute(3,"TIME_ZONE", $TIME_ZONE); - $st->execute(5,"PRC_WIDTH", $PRC_WIDTH); - $st->execute(8,"SESSN_EXPR", $SESSN_EXPR); -} - sub removeOldSessions{ opendir(DIR, $LOG_PATH); diff --git a/htdocs/cgi-bin/main.cgi b/htdocs/cgi-bin/main.cgi index 70bd922..7600a8e 100755 --- a/htdocs/cgi-bin/main.cgi +++ b/htdocs/cgi-bin/main.cgi @@ -16,6 +16,7 @@ use DBI; use DateTime; use DateTime::Format::SQLite; use DateTime::Duration; +use Date::Language; use Date::Parse; use Time::localtime; use Regexp::Common qw /URI/; @@ -23,9 +24,11 @@ use Regexp::Common qw /URI/; #DEFAULT SETTINGS HERE! our $REC_LIMIT = 25; our $TIME_ZONE = 'Australia/Sydney'; +our $LANGUAGE = 'English'; our $PRC_WIDTH = '60'; our $LOG_PATH = '../../dbLifeLog/'; our $SESSN_EXPR = '+30m'; +our $DATE_UNI = '0'; our $RELEASE_VER = '1.3'; #END OF SETTINGS @@ -81,9 +84,10 @@ print $cgi->start_html(-title => "Personal Log", -BGCOLOR=>"#c8fff8", ); my $rv; my $st; +my $lang = Date::Language->new($LANGUAGE); my $today = DateTime->now; $today->set_time_zone( $TIME_ZONE ); - + my $stmtCat = "SELECT * FROM CAT;"; my $stmt = "SELECT rowid, ID_CAT, DATE, LOG, AMMOUNT FROM LOG ORDER BY rowid DESC, DATE DESC;"; @@ -107,7 +111,6 @@ my $c_sel = 1; $cats = $cats.''; - my $tbl = qq( @@ -117,7 +120,6 @@ my $tbl = qq(Category); - if($rs_keys){ my @keywords = split / /, $rs_keys; @@ -161,8 +163,6 @@ else{ # # Enable to see main query statement issued! #print $cgi->pre("### -> ".$stmt); - - my $tfId = 0; my $id = 0; my $tbl_start = index $stmt, "<="; @@ -285,15 +285,22 @@ while(my @row = $st->fetchrow_array()) { }elsif(1 == $row[1]){ $log = "$log"; } - my $dty=$dt->ymd; + + my ($dty, $dtf) = $dt->ymd; my $dth=$dt->hms; + if($DATE_UNI==1){ + $dtf = $dty; + } + else{ + $dtf= $lang->time2str("%d %b %Y", $dt->epoch); + } $tbl .= qq( - + - + - @@ -621,19 +628,26 @@ try { sub getConfiguration{ - my $st = $_[0]->prepare("SELECT * FROM CONFIG;"); - $st->execute(); + 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 "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]} else {print "Unknow variable setting: ".$r[1]. " == ". $r[2]} - } } -} + } + catch{ + print "SERVER ERROR:".$_; + } +} \ No newline at end of file diff --git a/htdocs/cgi-bin/main.cnf b/htdocs/cgi-bin/main.cnf new file mode 100644 index 0000000..a6dc3ef --- /dev/null +++ b/htdocs/cgi-bin/main.cnf @@ -0,0 +1,10 @@ + +00|$RELEASE_VER = 1.3 +01|$REC_LIMIT = 25 +03|$TIME_ZONE = Australia/Sydney +05|$PRC_WIDTH = 60; +08|$LOG_PATH = ../../dbLifeLog/ +10|$SESSN_EXPR = +30m +12|$DATE_UNI = 0 +14|$LANGUAGE = English + diff --git a/htdocs/cgi-bin/remove.cgi b/htdocs/cgi-bin/remove.cgi index c3e4cb8..8c6b3ca 100755 --- a/htdocs/cgi-bin/remove.cgi +++ b/htdocs/cgi-bin/remove.cgi @@ -105,7 +105,7 @@ sub DisplayDateDiffs{ '; $stm = 'SELECT DATE, LOG FROM LOG WHERE '; -my @prms = $cgi->param('chk'); + my @prms = $cgi->param('chk'); foreach (@prms){ $stm .= "rowid = '" . $_ ."'"; @@ -123,11 +123,10 @@ my @prms = $cgi->param('chk'); my $dt = DateTime::Format::SQLite->parse_datetime( $row[0] ); my $dif = dateDiff($dt_prev, $dt); $tbl .= ' - ". - ''; + ". + ''; $dt_prev = $dt; } - $tbl .= '
Edit
$dty$dtf $dth$log$log $amm $ct +
* DATE DIFFERENCES *
'. $dt->ymd . ''.$row[1]."
'.$dif. '
'.$row[1]."
'.$dif. '
'; print '
'.$tbl.'

Back to Main Log
'; diff --git a/htdocs/cgi-bin/wsrc/main.js b/htdocs/cgi-bin/wsrc/main.js index 9accd3a..7d7d29c 100644 --- a/htdocs/cgi-bin/wsrc/main.js +++ b/htdocs/cgi-bin/wsrc/main.js @@ -89,7 +89,7 @@ function edit(row) { } else { document.getElementById("el").value = ev_v.innerText; } - document.getElementById("ed").value = ed_v.innerText + " " + et_v.innerText; + document.getElementById("ed").value = ed_v.value + " " + et_v.innerText; document.getElementById("am").value = ea_v.innerText; //Change selected catergory for (var i = 0, j = ec.options.length; i < j; ++i) {