From: wbudic Date: Wed, 16 Jan 2019 05:00:33 +0000 (+1100) Subject: New Config and login pages, under development. X-Git-Url: https://lifelog.hopto.org/gitweb/?a=commitdiff_plain;h=34f4963d6b9dd758dd8ef4575719341cd8d47a70;p=LifeLog.git New Config and login pages, under development. --- diff --git a/htdocs/cgi-bin/config.cgi b/htdocs/cgi-bin/config.cgi index 91038d6..1ebb2c4 100755 --- a/htdocs/cgi-bin/config.cgi +++ b/htdocs/cgi-bin/config.cgi @@ -50,25 +50,28 @@ print $q->start_html(-title => "Personal Log", my $stmtCat = "SELECT * FROM CAT ORDER BY rowid;"; +$dbs = $db->prepare( $stmtCat ); +$rv = $dbs->execute() or die or die "

Error->"& $DBI::errstri &"

"; + ############### &processSubmit; ############### # -$dbs = $db->prepare( $stmtCat ); -$rv = $dbs->execute() or die or die "

Error->"& $DBI::errstri &"

"; - my $cats = ' '; -my %hshCats; while(my @row = $dbs->fetchrow_array()) { - $cats = $cats. ' - - '; - $hshCats{$row[0]} = $row[1]; + + if($row[0]>0){ + $cats = $cats. + ' + + + '; + } } @@ -82,12 +85,14 @@ my $frm = qq( - + - -
* CATEGORIES CONFIGURATION *
IDCategoryDescription
'.$row[0].'
'.$row[0].'
WARNING! Removing and changing categories is permanent! Adding one must have unique ID. Blanking an category will seek and remove old records under it in the LOG! Also ONLY Category Unspecified You Can't Change!
If changing here things? Make a backup! (copy existing db, small file)

); + WARNING! + Removing and changing categories is permanent! Adding one must have unique ID. + Blanking an category will seek and change LOG records to Unspecified! Also ONLY the category Unspecified You can't CHANGE!
If changing here things? Make a backup! (copy existing db file) +
); # @@ -95,7 +100,7 @@ my $frm = qq( # print "
"; print "\n
\n" . $frm ."\n
\n
"; - print '
Back to Main Log (Be wise)
'; + print '
Back to Main Log
'; print "
"; @@ -105,6 +110,103 @@ exit; ### CGI END +sub processSubmit { + +my $change = $q->param("cchg"); +my $s; +my $d; + +try{ +if ($change == 1){ + + + while(my @row = $dbs->fetchrow_array()) { + + my $cid = $row[0]; + my $cnm = $row[1]; + my $cds = $row[2]; + + + my $pnm = $q->param('nm'.$cid); + my $pds = $q->param('ds'.$cid); + + if($cid!=1 && $pnm ne $cnm || $pds ne $cds){ + + if($pnm eq ""){ + + $s = "SELECT rowid, ID_CAT FROM LOG WHERE ID_CAT =".$cid.";"; + $d = $db->prepare($s); + $d->execute(); + + while(my @r = $d->fetchrow_array()) { + $s = "UPDATE LOG SET CAT_ID=1 WHERE rowid=".$r[0].";"; + $d = $db->prepare($s); + $d->execute(); + } + + #Delete + $s = "DELETE FROM CAT WHERE ID=".$cid.";"; + $d = $db->prepare($s); + $d->execute(); + + } + else{ + #Update + $s = "UPDATE CAT SET NAME='".$pnm."', DESCRIPTION='".$pds."' WHERE ID=".$cid.";"; + $d = $db->prepare($s); + $d->execute(); + } + + } + + } +} + +if($change > 1){ + + #UNDER DEVELOPMENT! + my $caid = $q->param('caid'); + my $canm = $q->param('canm'); + my $cade = $q->param('cade'); + my $valid = 1; + + while(my @row = $dbs->fetchrow_array()) { + + my $cid = $row[0]; + my $cnm = $row[1]; + my $cds = $row[2]; + + + if($cid==$caid || $cnm eq $canm){ + $valid = 0; + last; + } + } + + if($valid){ + $d = $db->prepare('INSERT INTO CAT VALUES (?,?,?)'); + $d->execute($caid,$canm, $cade); + } + else{ + print "

+ Client Error: ID->".$caid." or -> Category->".$canm. + " is already assigned, these must be unique!

"; + } +} + + #Re-select + $dbs = $db->prepare( $stmtCat ); + $rv = $dbs->execute() or die or die "

Error->"& $DBI::errstri &"

"; + +} +catch{ + print "

". + "SERVER ERROR:".$_. "

"; + +} + +} + sub checkCreateTablesAndSettings{ @@ -195,13 +297,13 @@ try{ $dbs = $db->prepare("SELECT * FROM CONFIG;"); $dbs->execute(); - while (my @row=$dbs->fetchrow_array()){ + while (my @r=$dbs->fetchrow_array()){ - switch ($row[1]) { + switch ($r[1]) { - case "REC_LIMIT" {$REC_LIMIT=$row[2]} - case "TIME_ZONE" {$TIME_ZONE=$row[2]} - else {print "Unknow variable setting: ".$row[1]. " == ". $row[2]} + case "REC_LIMIT" {$REC_LIMIT=$r[2]} + case "TIME_ZONE" {$TIME_ZONE=$r[2]} + else {print "Unknow variable setting: ".$r[1]. " == ". $r[2]} } @@ -209,103 +311,11 @@ try{ } catch{ - print "ERROR:".$_; -} - -} -sub processSubmit { -if ($q->param("cats_change")=="1"){ - + print "SERVER ERROR:".$_; } -<< '*/'; - - my $date = $q->param('date'); - my $log = $q->param('log'); - my $cat = $q->param('cat'); - my $amm = $q->param('am'); - - my $edit_mode = $q->param('submit_is_edit'); - my $view_mode = $q->param('submit_is_view'); - my $view_all = $q->param('rs_all'); - - -try{ - #Apostroph's need to be replaced with doubles and white space fixed for the SQL. - $log =~ s/(?<=\w) ?' ?(?=\w)/''/g; - - if($edit_mode && $edit_mode != "0"){ - #Update - - my $stm = "UPDATE LOG SET ID_CAT='".$cat."', DATE='". $date ."', - LOG='".$log."' WHERE rowid=".$edit_mode.";"; - my $db = $db->prepare($stm); - $db->execute(); - return; - } - if($view_all && $view_all=="1"){ - $REC_LIMIT = 0; - } - - if($view_mode && $view_mode == "1"){ - - if($rs_cur){ - $stmt = 'SELECT rowid, ID_CAT, DATE, LOG, AMMOUNT from LOG - where rowid <= "'.$rs_cur.'" ORDER BY DATE DESC, rowid DESC;'; - return; - } - } - - if($log && $date && $cat){ - - #check for double entry - # - my $db = $db->prepare( - "SELECT DATE,LOG FROM LOG where DATE='".$date."' AND LOG='".$log."';" - ); - - $db->execute(); - if(my @row = $db->fetchrow_array()){ - return; - } - - $db = $db->prepare('INSERT INTO LOG VALUES (?,?,?,?)'); - $db->execute( $cat, $date, $log, $amm); - # - # UNDER DEVELOPMENT! - # - # After Insert renumeration check - # - my $dt = DateTime::Format::SQLite->parse_datetime($date); - my $dtCur = DateTime->now(); - $dtCur->set_time_zone($TIME_ZONE); - $dtCur = $dtCur - DateTime::Duration->new( days => 1); - - if($dtCur> $dt){ - print $q->p('Insert is in the past!'); - #Renumerate directly (not proper SQL but faster); - $db = $db->prepare('select rowid from LOG ORDER BY DATE;'); - $db->execute(); - my @row = $db->fetchrow_array(); - my $cnt = 1; - while(my @row = $db->fetchrow_array()) { - - my $db_upd = $db->prepare("UPDATE LOG SET rowid=".$cnt. - " WHERE rowid='".$row[0]."';"); - $db_upd->execute(); - $cnt = $cnt + 1; - } - } - } } -catch{ - print "ERROR:".$_; -} - -*/ - -} diff --git a/htdocs/cgi-bin/login_ctr.cgi b/htdocs/cgi-bin/login_ctr.cgi new file mode 100755 index 0000000..8376406 --- /dev/null +++ b/htdocs/cgi-bin/login_ctr.cgi @@ -0,0 +1,63 @@ +#!/usr/bin/perl + +use strict; +use warnings; +use Try::Tiny; +use Switch; + +use CGI; +use CGI::Session; +use DBI; + +use DateTime; +use DateTime::Format::SQLite; +use DateTime::Duration; +use Text::CSV; + +my $driver = "SQLite"; +my $database = "../../dbLifeLog/data_config_test_log.db"; +my $dsn = "DBI:$driver:dbname=$database"; +my $userid = $ENV{'DB_USER'}; +my $password = $ENV{'DB_PASS'}; + + + +my $rv; +my $dbs; + + +my $q = CGI->new; + +print $q->header(-expires=>"+6os", -charset=>"UTF-8"); + +print $q->start_html(-title => "Personal Log", + -script=>{-type => 'text/javascript', -src => 'wsrc/main.js'}, + -style =>{-type => 'text/css', -src => 'wsrc/main.css'}, + ); +my $frm = qq( +
+ + + + + + + + + + +
LOGIN
Alias:
Password:
NOTICE!  If here the first time? Write down your alias and password, before proceeding. So you can comeback in the future to continue. Only you can know it. +
); + + +print "
"; + print "\n
\n" . $frm ."\n
\n
"; +print "
"; + + +print $q->end_html; +exit; + +### CGI END + + diff --git a/htdocs/cgi-bin/wsrc/main.js b/htdocs/cgi-bin/wsrc/main.js index 267f339..167e5ff 100644 --- a/htdocs/cgi-bin/wsrc/main.js +++ b/htdocs/cgi-bin/wsrc/main.js @@ -125,7 +125,6 @@ function resetView(){ function updateSelCategory(sel){ - var b = document.getElementById("btn_cat"); var cat = document.getElementById("idx_cat"); @@ -141,5 +140,8 @@ function viewByCategory(btn){ function submitNewCategory(){ - return false; + var frm = document.getElementById("frm_config"); + var cid = frm.caid; + frm.cchg.value = cid.value; + return true; }