package main;
use strict;
use warnings;
-use Try::Tiny;
+use Try::Tiny;
use CGI;
use CGI::Session '-ip_match';
use DBI;
our $LOG_PATH = '../../dbLifeLog/';
our $SESSN_EXPR = '+30m';
our $DATE_UNI = '0';
-our $RELEASE_VER = '1.5';
+our $RELEASE_VER = '1.6';
our $AUTHORITY = '';
our $IMG_W_H = '210x120';
our $AUTO_WRD_LMT= 200;
if(&processSubmit==0){
&getTheme;
- print $cgi->header(-expires=>"0s", -charset=>"UTF-8", -cookie=>$cookie);
- print $cgi->start_html(-title => "Personal Log Login", -BGCOLOR=>"$BGCOL",
- -script=>{-type => 'text/javascript', -src => 'wsrc/main.js'},
- -style =>{-type => 'text/css', -src => "wsrc/$TH_CSS"},
- );
+ print $cgi->header(-expires=>"0s", -charset=>"UTF-8", -cookie=>$cookie);
+ print $cgi->start_html(
+ -title => "Personal Log Login",
+ -BGCOLOR => "$BGCOL",
+ -script => { -type => 'text/javascript', -src => 'wsrc/main.js' },
+ -style => { -type => 'text/css', -src => "wsrc/$TH_CSS" },
+);
- $frm = qq(
+
+$frm = qq(
<form id="frm_login" action="login_ctr.cgi" method="post"><table border="0" width="$PRC_WIDTH%">
<tr class="r0">
<td colspan="3"><center>LOGIN</center></td>
</tr>
<tr class="r1">
<td colspan="3" style="border-left:1px solid black; border-right:1px solid black;"><font color="red">NOTICE!</font>
- Alias will create a new database if it doesn't exist. Note down your password.
+ Alias will create a new database if it doesn't exist. Note down your password.
<input type="hidden" name="CGISESSID" value="$sid"/>
<input type="hidden" name="login" value="1"/></td></tr>
<tr class="r0"><td colspan="2"></td><td><input type="submit" value="Login"/></td></tr>
</table></form>);
- print qq(<br><br><div id=rz>
+print qq(<br><br><div id=rz>
<center>
<h2>Welcome to Life Log</h2><div>$frm</div><br/>
<a href="https://github.com/wbudic/LifeLog" target="_blank">Get latest version of this application here!</a><br>
</center><div>);
- print $cgi->end_html;
+ print $cgi->end_html;
+
}
else{
try{
if($alias&&$passw){
-
+
$passw = uc crypt $passw, hex $cipher_key;
&checkCreateTables;
$session->param('alias', $alias);
$session->param('passw', $passw);
- $session->param('database', 'data_'.$alias.'_log.db');
+ $session->param('database', 'data_'.$alias.'_log.db');
$session->flush();
- print $cgi->header(-expires=>"0s", -charset=>"UTF-8", -cookie=>$cookie, -location=>"main.cgi");
+ print $cgi->header(-expires=>"0s", -charset=>"UTF-8", -cookie=>$cookie, -location=>"main.cgi");
return 1;
}
else{
}
return 0;
}
- catch{
+ catch{
print $cgi->header;
print "<font color=red><b>SERVER ERROR</b></font> dump ->". $session->dump();
print $cgi->end_html;
try{
#We don't need to slurp as it is expected setting in header.
my @cre;
- open(my $fh, '<', $LOG_PATH.'main.cnf' ) or die "Can't open main.cnf: $!";
+ open(my $fh, '<', $LOG_PATH.'main.cnf' ) or die "Can't open main.cnf: $!";
while (my $line = <$fh>) {
chomp $line;
if(rindex ($line, "<<AUTO_LOGIN<", 0)==0){
}
}
close $fh;
- if(@cre &&scalar(@cre)>1){
+ if(@cre &&scalar(@cre)>1){
my $database = $LOG_PATH.'data_'.$cre[0].'_log.db';
my $dsn= "DBI:SQLite:dbname=$database";
- my $db = DBI->connect($dsn, $cre[0], $cre[1], { RaiseError => 1 })
+ my $db = DBI->connect($dsn, $cre[0], $cre[1], { RaiseError => 1 })
or die "<p>Error->"& $DBI::errstri &"</p>";
- #check if enabled.
+ #check if enabled.
my $st = $db->prepare("SELECT VALUE FROM CONFIG WHERE NAME='AUTO_LOGIN';");
$st->execute();
my @set = $st->fetchrow_array();
if(@set && $set[0]=="1"){
$alias = $cre[0];
- $passw = $cre[1];
+ $passw = $cre[1];
}
$db->disconnect();
}
}
- catch{
+ catch{
print $cgi->header;
print "<font color=red><b>SERVER ERROR</b></font>:".$_;
print $cgi->end_html;
$today->set_time_zone( $TIME_ZONE );
my $database = $LOG_PATH.'data_'.$alias.'_log.db';
my $dsn= "DBI:SQLite:dbname=$database";
- my $db = DBI->connect($dsn, $alias, $passw, { RaiseError => 1 })
+ my $db = DBI->connect($dsn, $alias, $passw, { RaiseError => 1 })
or die "<p>Error->"& $DBI::errstri &"</p>";
my $rv;
my $st = $db->prepare(selSQLTbl('LOG'));
CREATE TABLE LOG (
ID_CAT TINY NOT NULL,
DATE DATETIME NOT NULL,
- LOG VCHAR(128) NOT NULL,
+ LOG VCHAR(128) NOT NULL,
AMOUNT INTEGER DEFAULT 0,
AFLAG TINY DEFAULT 0,
RTF BOOL DEFAULT 0
);
$rv = $db->do($stmt);
if($rv < 0){print "<p>Error->"& $DBI::errstri &"</p>";}
-
+
$st = $db->prepare('INSERT INTO LOG VALUES (?,?,?,?,?,?)');
$st->execute( 3, $today, "DB Created!",0,0,0);
}
DESCRIPTION VCHAR(64)
);
CREATE INDEX idx_cat_name ON CAT (NAME);
- );
+ );
$rv = $db->do($stmt);
- $changed = 1;
+ $changed = 1;
}
#Have cats been wiped out?
$st = $db->prepare('SELECT count(ID) FROM CAT;');
if(!$st->fetchrow_array()) {
#
# @TODO
- # AUTH Action Flags
+ # AUTH Action Flags
# 00|DEFAULT`No action idle use.|
# 02|CONF_UPD`Configuration file update with db.
# 03|EMAIL`Issue email.|
# 06|DESTRUCT`Self destruct, remove alias and all data.
- # 08|CHNG_PASS`Change password.
- # 10|CHNG_ALIAS`Change alias.
-
+ # 08|CHNG_PASS`Change password.
+ # 10|CHNG_ALIAS`Change alias.
+
my $stmt = qq(
CREATE TABLE AUTH(
alias varchar(20) PRIMARY KEY,
passw TEXT,
email varchar(44),
- action TINY
+ action TINY
) WITHOUT ROWID;
CREATE INDEX idx_auth_name_passw ON AUTH (ALIAS, PASSW);
- );
+ );
$rv = $db->do($stmt);
if(!$st->fetchrow_array()) {
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('INSERT INTO AUTH VALUES (?,?,?,?);');
$st->execute($alias, $passw,"",0);
}
-
+
$st = $db->prepare(selSQLTbl('CONFIG'));
$st->execute();
if(!$st->fetchrow_array()) {
$st = $db->prepare('SELECT count(ID) FROM CONFIG;');
$st->execute();
$changed = 1 if($st->fetchrow_array()==0);
-
+
}
#
&populate($db) if $changed;
#
$db->disconnect();
}
- catch{
+ catch{
print $cgi->header;
print "<font color=red><b>SERVER ERROR</b></font>:".$_;
print $cgi->end_html;
}
sub populate {
-
+
my $db = shift;
my ($did,$name, $value, $desc);
my $inData = 0;
read $fh, my $content, -s $fh;
@lines = split '\n', $content;
close $fh;
-#TODO Check if script id is unique to database? If not script prevails to database entry.
+#TODO Check if script id is unique to database? If not script prevails to database entry.
#So, if user settings from a previous release, must be migrated later.
try{
-
+
my $insConfig = $db->prepare('INSERT INTO CONFIG VALUES (?,?,?,?)');
my $insCat = $db->prepare('INSERT INTO CAT VALUES (?,?,?)');
$db->begin_work();
foreach my $line (@lines) {
-
+
last if ($line =~ /<MIG<>/);
my @tick = split("`",$line);
$err .= "Invalid, spec'd entry -> $line\n";
}elsif($table_type==1){
my @pair = $tick[0] =~ m[(\S+)\s*\|\s*(\S+)]g;
- if ( scalar(@pair)==2 ) {
+ if ( scalar(@pair)==2 ) {
my $st = $db->prepare("SELECT rowid FROM CONFIG WHERE NAME LIKE '$pair[1]';");
$st->execute();
$inData = 1;
}
}elsif($table_type==2){
#TODO Do we really want this?
- }
+ }
}elsif($inData && length($line)>0){
if(scalar(@tick)==1){
$err .= "Corrupt Entry, no description supplied -> $line\n";
}
- else{
+ else{
$err .= "Corrupt Entry -> $line\n";
}
}
- }
+ }
die "Configuration script $LOG_PATH/main.cnf [$fh] contains errors." if $err;
$db->commit();
- } catch{
+ } catch{
print $cgi->header;
print "<font color=red><b>SERVER ERROR!</b></font><br> ".$_."<br><pre>$err</pre>";
print $cgi->end_html;
$session->delete();
$session->flush();
print $cgi->header(-expires=>"0s", -charset=>"UTF-8", -cookie=>$cookie);
- print $cgi->start_html(-title => "Personal Log Login", -BGCOLOR=>"black",
+ print $cgi->start_html(-title => "Personal Log Login", -BGCOLOR=>"black",
-style =>{-type => 'text/css', -src => 'wsrc/main.css'},
- );
-
+ );
+
print qq(<font color="white"><center><h2>You have properly loged out of the Life Log Application!</h2>
<br>
<form action="login_ctr.cgi"><input type="submit" value="No, no, NO! Log me In Again."/></form><br>
</br>
- <iframe width="60%" height="600px" src="https://www.youtube.com/embed/qTFojoffE78?autoplay=1"
- frameborder="0"
+ <iframe width="60%" height="600px" src="https://www.youtube.com/embed/qTFojoffE78?autoplay=1"
+ frameborder="0"
allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen>
</iframe>
</center></font>
- );
+ );
print $cgi->end_html;
exit;
}
+
+
### CGI END
else if(data.item.value == 0 && (evv == 35||evv==32)){sel = 1; }
if(sel){
ec.val(sel);
- ec.selectmenu("refresh");
+ // ec.selectmenu("refresh");
}
}
}});
function edit(row) {
var ed_v = $("#y" + row); //date
- var et_v = $("#t" + row); //time
+ var et_v = $("#t" + row); //time
var ea_v = $("#a" + row); //amount
- var tag = $("#g" + row); //orig. tagged log text.
- var log = $("#v" + row); //log
- var rtf = $("#r" + row); //RTF doc
+ var tag = $("#g" + row); //orig. tagged log text.
+ var log = $("#v" + row); //log
+ var rtf = $("#r" + row); //RTF doc
+ var amf = $("#f" + row); //Amount type.
var isRTF = (rtf.val()>0?true:false);
if(!isRTF){
$('#rtf_doc').hide();
if (tag.length) {
$("#el").val(decodeToHTMLText(tag.val()));
- } else {
+ } else {
$("#el").val(decodeToText(log.text()));
- }
-
+ }
+
$("#ed").val(ed_v.val() + " " + et_v.html()); //Time field
var val = ea_v.html();
val = val.replace(/\,/g,"");
var ec_v = $("#c" + row).text();
$("#ec option:contains(" + ec_v + ")").prop('selected', true);
$("#submit_is_edit").val(row);
+
+
+ ec_v = amf.val();
+ $("#amf").focus();
+ $("#amf").val(ec_v);
+ $("#amf").selectmenu('refresh');
+
$("#el").focus();
return false;
var sum = 0;
for (var i = 0, n = chks.length; i < n; i++) {
if (chks[i].checked) {
- var par = chks[i].parentNode.parentNode.childNodes;
- for (var j = 0, nn = par.length; j < nn; j++) {
- var el = par[j];
- if (el.id && el.id.indexOf('a', 0) == 0) {
- sum = sum + Number(el.innerHTML);
- break;
- }
+ var id = chks[i].value;
+ var am = $("#a"+id).text();
+ var ty = $("#c"+id).text();
+ am = am.replace(/\,/g,"");//rem formatting
+ if(ty=='Expense'){
+ sum = sum - Number(am);
+ }
+ else{
+ sum = sum + Number(am);
}
}
}
-function editorBackground(reset){
+function editorBackground(reset){
var css = $("#editor-container").prop('style');
if(reset){
css.backgroundColor = DEF_BACKGROUND;