mjordn12,
No, you do not need to edit the get_default sub in db_utils.pl since it will handle the defaults automatically.
The default for a field is handled by the record definition in links.def in the variable %db_def which looks like this:
Quote:
%db_def = (
ID => [0, 'numer', 5, 8, 1, '', ''],
Title => [1, 'alpha', 40, 75, 1, '', ''],
URL => [2, 'alpha', 40, 75, 1, 'http://', '^http|news|mailto|ftp'],
Date => [3, 'date', 15, 15, 1, \&get_date, ''],
Category => [4, 'alpha', 0, 150, 1, '', ''],
Description => [5, 'alpha', '40x3', 500, 0, '', ''],
'Contact Name' => [6, 'alpha', 40, 75, 1, '', ''],
'Contact Email' => [7, 'alpha', 40, 75, 1, '', '.+@.+\..+'],
Hits => [8, 'numer', 10, 10, 1, '0', '\d+'],
isNew => [9, 'alpha', 0, 5, 0, 'No', ''],
isPopular => [10, 'alpha', 0, 5, 0, 'No', ''],
Rating => [11, 'numer', 10, 10, 1, 0, '^[\d\.]+$'],
Votes => [12, 'numer', 10, 10, 1, 0, '^\d+$'],
ReceiveMail => [13, 'alpha', 10, 10, 1, 'Yes', 'No|Yes']
);
The column on the left of the => is the field name. On the right side of the =>, inside the brackets from left to right, you have the field number, sort type, length of the input window in a form (used in the forms created in the admin screen), maximum length of the field itself, whether it should not be null (1 = cannot be null, 0 = can be null), the default value for the field if any, and a perl regexp that describes the default form of the field (if any).
You might also take a look at the %add_system_fields and %db_select_fields in links.def.
Once you have your new field defined, you need a way to add it to all the records already in links.db. What I do is use the upgrade.pl script that comes with the beta. I modify it to match what I want to add. For example, I added a date field to my database that was to keep track of the date a resource was originally added (v2.0 changes the other date anytime a record is modified by a user -- but not the admin). I changed:
Quote:
while (<DB> ) {
chomp;
s/NULL//g;
print DBOUT "$_|0|0|Yes\n";
}
to read:
Quote:
LINE: while (<DB> ) {
/^#/ and next LINE; # Skip comment Lines.
/^\s*$/ and next LINE; # Skip blank lines.
chomp; # Remove trailing new line.
@rec = &split_decode($_);
$rec[$db_dateadded] = $rec[$db_modified];
print DBOUT &join_encode(&array_to_hash(0, @rec));
}
I put this script in my admin/data directory, chmod it to 755, and then ran it. It updated my links.db just fine, but stored it as links2.db so that I could check it before renaming it to links.db.
Once you have done all that, you can modify the forms used in add/modify to include <input> tags for the new fields.
I hope this helps.
------------------
Bob Connors
bobsie@orphanage.com www.orphanage.com/goodstuff/ [This message has been edited by Bobsie (edited February 19, 1999).]