Gossamer Forum
Home : Products : DBMan : Customization :

Updating many cfg files at once.

Quote Reply
Updating many cfg files at once.
I have 7 cfg files, in each of the 7, under the "%db_select_fields" i have one called "Userid", it list all of the sale reps. Is there a way to make this read from a text file so that when i need to update the list i can edit the text file and the 7 cfg files will read from that file? this way i'm only updating one file.

Thanks,
Ed
Quote Reply
Re: [knue] Updating many cfg files at once. In reply to
easier way to do this:

In your .cfg file, create a new variable to hold the fieldnames that will be created from the external databases.

code:
$db_external_select_fields = 'Userid';

In db.cgi, create a subroutine: code:

sub build_external_select_field {
#------------------------------------
my ($column, $value) = @_;
my ($output,$external_db,$found,$field,@selectfields);
foreach $col (@db_cols) {
if ($column eq $col) {
$found = 1;
last;
}
}
if (!$found) {
return "error building select field: no fields specified!";
}
$output = qq|<SELECT NAME="$column">|;
$external_db=$db_script_path . '/' . lc($column) . '.db';
open (DB, "<$external_db") or &cgierr("unable to open $column.db. Reason: $!");
if ($db_use_flock) { flock(DB, 1); }
LINE: while (<DB> ) {
next if /^#/;
next if /^\s*$/;
$line = $_;
chomp ($line);
push (@selectfields, $line);
}
close DB;
foreach $field (sort @selectfields) {
($value =~ $field) ?
($output .= "<OPTION SELECTED>$field") :
($output .= "<OPTION>$field");
}
$output .= "</SELECT>";
return $output;
}

In html_build_record_form, after the line that starts with

if ($db_select_fields{$field}) {...

add code:

elsif ($db_external_select_fields =~ $field) {
$output .= "<TR><TD><$font>$field:</font></TD><TD" . &build_external_select_field($field, $rec{$field}) . "</TD></TR>";
}

As always, should you or any of your IM force be caught or captured-- Oh, wrong context.
As always, this is untested, except for sytax errors.



i copied above from an old post and edited it a little. ;you would take Userid out of the &db_select_fields in all the config files and use the following instead.

$db_external_select_fields = 'Userid';

then you would have a database that contained all the Userid's.

i suggest you use a common .pass file that already exists instead of a new file. if you use pass file you will need to make a few changes to the code above. if you need help with that, get it started and let me know!
Quote Reply
Re: [delicia] Updating many cfg files at once. In reply to
see http://redundantcartridge.com/cgi-bin/dbman/dbfaq.cgi?db=dbmanfaq

search for external
Quote Reply
Re: [delicia] Updating many cfg files at once. In reply to
Thanks delicia, ill start on this tonight and let you know the out come.

Ed-
Quote Reply
Re: [knue] Updating many cfg files at once. In reply to
reminder/hint: if you can use a password file, the delimiter is probably a colon : instead of pipe | so you may not want to use split_decode sub.
Quote Reply
Re: [delicia] Updating many cfg files at once. In reply to
I think i'm a little confused, where do i tell it the name of the file?
Quote Reply
Re: [knue] Updating many cfg files at once. In reply to
or is it called Userid?
Quote Reply
Re: [knue] Updating many cfg files at once. In reply to
in sub build_external_select_field, change the following line:

$external_db=$db_script_path . '/' . lc($column) . '.db';

to

$external_db= whatever the name of the password file is

note: i'm assuming that all of the people you want included in the list are in a common password file somewhere. if you're having to manually add people to each password file in several different folders, i would suggest changing all the cfg files to reference the same pass file. then sub build_external_select_field can just reference that one file which can easily be maintained by whoever has admin permission in the databases. for this application you're using a pass file as if it were a db file; it works because it's a plain text file, though the passwords are encrypted.
Quote Reply
Re: [delicia] Updating many cfg files at once. In reply to
here's some code from original sub admin_display that will help you:

# Now let's load the list of users.
open (PASS, "<$auth_pw_file") or &cgierr ("unable to open: $auth_pw_file.\nReason: $!");
if ($db_use_flock) { flock(PASS, 1); }
@lines = <PASS>;
close PASS;

# If we are inquiring, let's look for the specified user.
my (@data, $user_list, $perm, $password);

$user_list = qq~<select name="username"><option> </option>~;
LINE: foreach $line (@lines) {
$line =~ /^#/ and next LINE;
$line =~ /^\s*$/ and next LINE;
chomp $line;
@data = split (/:/, $line);

$data[0] is your userid

if you can get all the db's to use common pw file, you can even use filename $auth_pw_file as above.

Last edited by:

delicia: Dec 1, 2015, 5:39 PM
Quote Reply
Re: [delicia] Updating many cfg files at once. In reply to
yes, they all use the same password file.
Quote Reply
Re: [knue] Updating many cfg files at once. In reply to
EDIT: copy and paste got me in trouble. take out the line about user-list. i've removed it below

great! so basically change the following in sub build_external_select field
from
$external_db=$db_script_path . '/' . lc($column) . '.db';
open (DB, "<$external_db") or &cgierr("unable to open $column.db. Reason: $!");
if ($db_use_flock) { flock(DB, 1); }
LINE: while (<DB> ) {
next if /^#/;
next if /^\s*$/;
$line = $_;
chomp ($line);
push (@selectfields, $line);
}


to

open (PASS, "<$auth_pw_file") or &cgierr ("unable to open: $auth_pw_file.\nReason: $!");
if ($db_use_flock) { flock(PASS, 1); }
@lines = <PASS>;
close PASS;

# If we are inquiring, let's look for the specified user.
my (@data);

LINE: foreach $line (@lines) {
$line =~ /^#/ and next LINE;
$line =~ /^\s*$/ and next LINE;
chomp $line;
@data = split (/:/, $line);
push (@selectfields, $data[0]);
}

since i'm just working on excerpt, i may be missing a bracket somewhere...

Last edited by:

delicia: Dec 1, 2015, 6:02 PM
Quote Reply
Re: [delicia] Updating many cfg files at once. In reply to
Ok so far no syntax errorsSmile, but in my html file i get and error telling me "error building select field: no select fields specified in config for field 'Userid'! i did not change or removed the call for the drop down. because i did not know what to put in its place.
Quote Reply
Re: [knue] Updating many cfg files at once. In reply to
sounds like your html is still calling sub build_select_field

change:

print &build_select_field ("Userid", "$rec{'Userid'}");

to

print &build_external_select_field ("Userid", "$rec{'Userid'}");

either remove the part of sub build_external_select_field that checks to be sure Userid (field or column) is defined in cfg
or be sure it is defined in cfg in $external_select_field (or whatever the variable is; see my first reply)

Quote Reply
Re: [delicia] Updating many cfg files at once. In reply to
see private message.
Quote Reply
Re: [delicia] Updating many cfg files at once. In reply to
Just a quick reply, just made the change and it's working, i have not tried everything out yet but at first look it's working. i'll make the change to the rest of the files and let you know what happens.Smile

thanks
Ed-
Quote Reply
Re: [knue] Updating many cfg files at once. In reply to
Delicia, made the changes to all of the db, cfg, html files, everything is working the way it should except for the Modify Multiple rec.
The "Userid" dose not save it go's blank. Here are the changes that I made.

In the DB.cgi under:
sub build_html_mult_record_form {

I added this just after the "if" statement:

elsif ($db_external_select_fields =~ $field) { $output .= "<TR><TD><$font>$field:</font></TD><TD" . &build_external_select_field($field, $rec{$field}) . "</TD></TR>"; }

In the html.pl under:

sub html_record_form_mult {

I changed this:

print &build_external_select_field ("Userid", "$rec{'Userid'}");

to this:

print &build_external_select_field ("Userid", "$rec{'Userid'}","Userid-$rec{$db_key}");

Any ideals?

Ed

I also sent you a PM.
Quote Reply
Re: [delicia] Updating many cfg files at once. In reply to
 
Quote Reply
Re: [knue] Updating many cfg files at once. In reply to
at beginning of sub build_external_select_field change:

my ($column, $value) = @_;
my (@fields, $ouptut);

to

my ($column, $value, $name) = @_;
my (@fields, $ouptut);
$name || ($name = $column);

then further down in sub change:

$output = qq|<SELECT NAME="$column"><OPTION>---|;
foreach $field (@fields) {
$field eq $value ?
($output .= "<OPTION SELECTED>$field\n") :
($output .= "<OPTION>$field");

to

$output = qq|<SELECT NAME="$name"><OPTION>---|;
foreach $field (@fields) {
$field eq $value ?
($output .= "<OPTION SELECTED>$field\n") :
($output .= "<OPTION>$field");


i think this will take care of it.
Quote Reply
Re: [delicia] Updating many cfg files at once. In reply to
My layout was a little different, but i think this what you wanted me to do.


my ($column, $value, $name) = @_;
my ($output,$external_db,$found,$field,@selectfields);
$name || ($name = $column);
foreach $col (@db_cols) {
if ($column eq $col) {
$found = 1;
last;
}
}
if (!$found) {
return "error building select field: no fields specified!";
}
$output = qq|<SELECT NAME="$name">|;
open (PASS, "<$auth_pw_file") or &cgierr ("unable to open: $auth_pw_file.\nReason: $!");
if ($db_use_flock) { flock(PASS, 1); }
@lines = <PASS>;
close PASS;

This seems to work.

Thank you! again!!
Ed-
Quote Reply
Re: [knue] Updating many cfg files at once. In reply to
looks good, especially if it's working!