Ok, here it is.
Record-view counter, bugfixed.
First, in your default.cfg add:
$db_file_count = $db_script_path . "/brojac.db";
$db_counter_field = 1;
In your default.cgi change :
------------------
open (ID, ">$db_id_file_name") or &cgierr("error in get_defaults. unable to open id file: $db_id_file_name.\nReason: $!");
if ($db_use_flock) {
flock(ID, 2) or &cgierr("unable to get exclusive lock on $db_id_file_name.\nReason: $!");
}
print ID $in{$db_key}; # update counter.
close ID; # automatically removes file lock
}
&auth_logging("added record: $in{$db_key}") if ($auth_logging);
&html_add_success;
---------------------------------
to:
---------------------
open (ID, ">$db_id_file_name") or &cgierr("error in get_defaults. unable to open id file: $db_id_file_name.\nReason: $!");
if ($db_use_flock) {
flock(ID, 2) or &cgierr("unable to get exclusive lock on $db_id_file_name.\nReason: $!");
}
print ID $in{$db_key}; # update counter.
close ID; # automatically removes file lock
}
# flag
open (CO, ">>$db_file_count") or &cgierr("error in get_defaults. unable to open id file: $db_file_count.\nReason: $!");
if ($db_use_flock) {
flock(CO, 2) or &cgierr("unable to get exclusive lock on $db_file_count.\nReason: $!");
}
print CO $in{$db_key}.$db_delim."1"; # update counter.
close CO; # automatically removes file lock
&auth_logging("added record: $in{$db_key}") if ($auth_logging);
&html_add_success;
--------------------------------
Then, in html.pl (html_record or html_record_long) after
----------------
my (%rec) = @_; # Load any defaults to put in the VALUE field.
($db_auto_generate and print &build_html_record(%rec) and return);
$rec{$db_key} =~ s/<.?B>//g;
my $font_color = 'Font face="Verdana, Arial, Helvetica" Size=2 Color=#33ff33';
my $font = 'Font face="Verdana, Arial, Helvetica" Size=2 Color=#CCFFCC';
-------------------
add:
--------------
my $broj = '0';
open (CO, "<$db_file_count")
or &cgierr("error in modify_records. unable to open db file: $db_file_count.\nReason: $!");
if ($db_use_flock) { flock(CO, 1); }
@lines = <CO>; # Slurp the database into @lines..
close CO;
LINE: foreach $line (@lines) {
if ($line =~ /^$/) { next LINE; }
if ($line =~ /^#/) { $output .= $line; next LINE; }
chomp ($line);
@data = &split_decode($line);
if ($data[$db_key_pos] eq $rec{$db_key}) {
$broj = $data[$db_counter_field];
}
}
and at the end of the same sub (html_record or html_reocrd_long) add:
---------------------
open (DB, "<$db_file_count")
or &cgierr("error in modify_records. unable to open db file: $db_file_count.\nReason: $!");
if ($db_use_flock) { flock(DB, 1); }
@lines = <DB>; # Slurp the database into @lines..
close DB;
LINE: foreach $line (@lines) {
if ($line =~ /^$/) { next LINE; }
if ($line =~ /^#/) { $output .= $line; next LINE; }
chomp ($line);
@data = &split_decode($line);
if ($data[$db_key_pos] eq $rec{$db_key}) {
++$data[$db_counter_field];
$output .= join($db_delim, @data) . "\n";
}
else {
$output .= $line . "\n";
}
}
open (DB, ">$db_file_count")
or &cgierr("error in modify_records. unable to open db file: $db_file_count.\nReason: $!");
if ($db_use_flock) {
flock(DB, 2) or &cgierr("unable to get exclusive lock on $db_file_count.\nReason: $!");
}
print DB $output;
close DB;
---------------------
Make empty file called brojac.db (or anything you specified in default.cfg) and that's it.
Maybe it's a kind messy and probably it could be done much better, but this works just fine.
Record-view counter, bugfixed.
First, in your default.cfg add:
$db_file_count = $db_script_path . "/brojac.db";
$db_counter_field = 1;
In your default.cgi change :
------------------
open (ID, ">$db_id_file_name") or &cgierr("error in get_defaults. unable to open id file: $db_id_file_name.\nReason: $!");
if ($db_use_flock) {
flock(ID, 2) or &cgierr("unable to get exclusive lock on $db_id_file_name.\nReason: $!");
}
print ID $in{$db_key}; # update counter.
close ID; # automatically removes file lock
}
&auth_logging("added record: $in{$db_key}") if ($auth_logging);
&html_add_success;
---------------------------------
to:
---------------------
open (ID, ">$db_id_file_name") or &cgierr("error in get_defaults. unable to open id file: $db_id_file_name.\nReason: $!");
if ($db_use_flock) {
flock(ID, 2) or &cgierr("unable to get exclusive lock on $db_id_file_name.\nReason: $!");
}
print ID $in{$db_key}; # update counter.
close ID; # automatically removes file lock
}
# flag
open (CO, ">>$db_file_count") or &cgierr("error in get_defaults. unable to open id file: $db_file_count.\nReason: $!");
if ($db_use_flock) {
flock(CO, 2) or &cgierr("unable to get exclusive lock on $db_file_count.\nReason: $!");
}
print CO $in{$db_key}.$db_delim."1"; # update counter.
close CO; # automatically removes file lock
&auth_logging("added record: $in{$db_key}") if ($auth_logging);
&html_add_success;
--------------------------------
Then, in html.pl (html_record or html_record_long) after
----------------
my (%rec) = @_; # Load any defaults to put in the VALUE field.
($db_auto_generate and print &build_html_record(%rec) and return);
$rec{$db_key} =~ s/<.?B>//g;
my $font_color = 'Font face="Verdana, Arial, Helvetica" Size=2 Color=#33ff33';
my $font = 'Font face="Verdana, Arial, Helvetica" Size=2 Color=#CCFFCC';
-------------------
add:
--------------
my $broj = '0';
open (CO, "<$db_file_count")
or &cgierr("error in modify_records. unable to open db file: $db_file_count.\nReason: $!");
if ($db_use_flock) { flock(CO, 1); }
@lines = <CO>; # Slurp the database into @lines..
close CO;
LINE: foreach $line (@lines) {
if ($line =~ /^$/) { next LINE; }
if ($line =~ /^#/) { $output .= $line; next LINE; }
chomp ($line);
@data = &split_decode($line);
if ($data[$db_key_pos] eq $rec{$db_key}) {
$broj = $data[$db_counter_field];
}
}
and at the end of the same sub (html_record or html_reocrd_long) add:
---------------------
open (DB, "<$db_file_count")
or &cgierr("error in modify_records. unable to open db file: $db_file_count.\nReason: $!");
if ($db_use_flock) { flock(DB, 1); }
@lines = <DB>; # Slurp the database into @lines..
close DB;
LINE: foreach $line (@lines) {
if ($line =~ /^$/) { next LINE; }
if ($line =~ /^#/) { $output .= $line; next LINE; }
chomp ($line);
@data = &split_decode($line);
if ($data[$db_key_pos] eq $rec{$db_key}) {
++$data[$db_counter_field];
$output .= join($db_delim, @data) . "\n";
}
else {
$output .= $line . "\n";
}
}
open (DB, ">$db_file_count")
or &cgierr("error in modify_records. unable to open db file: $db_file_count.\nReason: $!");
if ($db_use_flock) {
flock(DB, 2) or &cgierr("unable to get exclusive lock on $db_file_count.\nReason: $!");
}
print DB $output;
close DB;
---------------------
Make empty file called brojac.db (or anything you specified in default.cfg) and that's it.
Maybe it's a kind messy and probably it could be done much better, but this works just fine.