my $stmtCat = "SELECT * FROM CAT ORDER BY rowid;";
+$dbs = $db->prepare( $stmtCat );
+$rv = $dbs->execute() or die or die "<p>Error->"& $DBI::errstri &"</p>";
+
###############
&processSubmit;
###############
#
-$dbs = $db->prepare( $stmtCat );
-$rv = $dbs->execute() or die or die "<p>Error->"& $DBI::errstri &"</p>";
-
my $cats = '<table id="ec" class="tbl" name="cats" border="0">
<tr class="r0"><td colspan="4"><b>* CATEGORIES CONFIGURATION *</b></td></tr>
<tr class="r1"><th>ID</th><th>Category</th><th>Description</th><td></td></tr>
';
-my %hshCats;
while(my @row = $dbs->fetchrow_array()) {
- $cats = $cats. '<tr class="r0"><td>'.$row[0].'</td>
- <td><input name="cat'.$row[0].'" type="text" value="'.$row[1].'" size="12"></td>
- <td><input name="descr'.$row[0].'" type="text" value="'.$row[2].'" size="64"></td><td></td></tr>';
- $hshCats{$row[0]} = $row[1];
+
+ if($row[0]>0){
+ $cats = $cats.
+ '<tr class="r0"><td>'.$row[0].'</td>
+ <td><input name="nm'.$row[0].'" type="text" value="'.$row[1].'" size="12"></td>
+ <td><input name="ds'.$row[0].'" type="text" value="'.$row[2].'" size="64"></td>
+ <td></td></tr>';
+ }
}
<td></td>
</tr>
<tr class="r1">
- <td colspan="2"><input type="button" value="Add New Category" onclick="return submitNewCategory()"/></td>
+ <td colspan="2"><input type="submit" value="Add New Category" onclick="return submitNewCategory()"/></td>
<td colspan="2"><input type="submit" value="Change"/></td>
</tr>
<tr class="r1">
- <td colspan="4"><font color="red">WARNING!</font> 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 <b>Unspecified</b> You Can't Change!<br/>If changing here things? Make a backup! (copy existing db, small file)</td>
-</table><input type="hidden" name="cats_change" value="1"/></form><br/>);
+ <td colspan="4"><font color="red">WARNING!</font>
+ 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 <b>Unspecified</b> You can't CHANGE!<br/>If changing here things? Make a backup! (copy existing db file)</td>
+</table><input type="hidden" name="cchg" value="1"/></form><br/>);
#
#
print "<center>";
print "\n<div>\n" . $frm ."\n</div>\n<br/>";
- print '</br><div><a href="main.cgi">Back to Main Log (Be wise)</a></div>';
+ print '</br><div><a href="main.cgi">Back to Main Log</a></div>';
print "</center>";
### 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 "<center><div><p>
+ <font color=red>Client Error</font>: ID->".$caid." or -> Category->".$canm.
+ " is already assigned, these must be unique!</p></div></center>";
+ }
+}
+
+ #Re-select
+ $dbs = $db->prepare( $stmtCat );
+ $rv = $dbs->execute() or die or die "<p>Error->"& $DBI::errstri &"</p>";
+
+}
+catch{
+ print "<center><div><p>".
+ "<font color=red><b>SERVER ERROR</b></font>:".$_. "</p></div></center>";
+
+}
+
+}
+
sub checkCreateTablesAndSettings{
$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]}
}
}
catch{
- print "ERROR:".$_;
-}
-
-}
-sub processSubmit {
-if ($q->param("cats_change")=="1"){
-
+ print "<font color=red><b>SERVER ERROR</b></font>:".$_;
}
-<< '*/';
-
- 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('<b>Insert is in the past!</b>');
- #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:".$_;
-}
-
-*/
-
-}