1 #!/local/bin/perl
2 ##############################################
3 # generic.cgi #
4 # Started by Steve Sowder on June 7, 2004 #
5 ##############################################
6
7 require "cgi-lib.pl";
8 &ReadParse(*input);
9
10 print &PrintHeader;
11
12 &loadconfig;
13 &verifyconfig;
14 &makebackup;
15
16
17 ## Global Field Names
18 # $KEYLENGTH - length of the numeic primary key
19 # $DATABASE - The filename of the database (no path info)
20 # $HOMEBASE - the name of this program with absolute path name
21 # $SYSTEMSIP - IP address of the systems user
22 # $SYSTEMSUSER- equal "Y" if true
23 # $USERIP - Ip address of the library user
24 # @FIELDS - Names of the fields in the database
25 # @DISPLAY - Nmaes to use for displaying the field names of the database
26 # @SECURITY - Security level for each field
27 # @DATATYPE - Datatype for each field
28 #
29
30
31 &verifysecurity;
32
33
34 $action = $input{'action'};
35 $field_count = @FIELDS;
36 $col_span = $field_count + 1;
37 $search_field = $input{'search_field'};
38 $search_for = $input{'search_for'};
39 @keys = $input{'key'};
40 $key_matches = @keys;
41
42
43 if($action =~ /add record/i){
44 # Add the record passed from the add record page
45 # $key = $keys[0];
46 #print "
add record routine\n";
47 &add_record;
48 $message="Record Added";
49 &print_message($message);
50 }
51 elsif($action =~ /add/i){
52 # Display the add record page
53 &print_add_screen;
54 }
55
56
57 elsif($action =~ /search/i)
58 {
59 # Search database and display the results
60 &search_database($search_for);
61 $count = @results;
62 if($count > 0)
63 {
64 $button_text = "Back to Database";
65 $caption = "Search Results";
66 &multiple_match;
67 }
68 else {&no_match; }
69 }
70
71 elsif($action =~ /modify record/i)
72 {
73 # Display the results of the search
74
75 &search_database($input{'key'});
76 $count = @results;
77 &no_match if($count < 1);
78 &print_modify_page;
79 }
80
81 elsif($action =~ /modify this record/i)
82 {
83 # Modify the record that was passed
84 $key=$keys[0];
85 &add_record;
86 $message="Record Modified";
87 &print_message($message);
88 }
89
90 elsif($action =~ /modify/i)
91 {
92 # Search and display results for modification
93 &search_database($search_for);
94 $count = @results;
95 if($count < 1) {&no_match }
96 elsif($count == 1) {&print_modify_page }
97 else
98 {
99 $caption="Modify Which Record?";
100 $button_text="Modify Record";
101 &multiple_match("RADIO","modify");
102 }
103 }
104
105
106 elsif($action =~ /delete record/i){
107 # Delete the record(s) that were passed
108 $key = $keys[0];
109 &delete_records;
110 $message="Record(s) Deleted";
111 &print_message($message);
112 }
113 elsif($action =~ /delete/i){
114 # Search and display results for modification
115 &search_database($search_for);
116 $count = @results;
117 &no_match if($count < 1);
118 $caption="Delete Which Record(s)?";
119 $button_text="Delete Record(s)";
120 &multiple_match("CHECKBOX","delete");
121
122 }
123 elsif($action =~ /update/i){
124 # update file
125 &update_database;
126 $message='File Updated';
127 &print_message($message);
128
129 }
130 elsif($action =~ /publish/i){
131 # update file
132 &update_database;
133 &publish;
134 $message='File Updated and Published';
135 &print_message($message);
136
137
138 }
139
140
141 else {&print_default}
142
143 ###########################################
144 sub add_record {
145 $key = $input{'key'}; # key 0
146
147 if (length($key) != $KEYLENGTH)
148 { &get_highest_key; $key = $nextkey; }
149 $record = $key;
150
151 $timestamp = time(); # key 1
152 $record .= "\^$timestamp";
153
154 for ($x = 2; $x <= $field_count; $x++) # remaining keys
155 {
156 $field = $input{"$FIELDS[$x]"};
157 $field = filter($field);
158 if ($DATACASE[$x] =~ /U/i) {$field = uc $field }
159 $record .= "\^$field";
160 }
161
162 open (DB, ">>$DATABASE") || die "Error opening database for add. $!\n";
163
164 flock DB, $EXCLUSIVE;
165 # seek DB, 0, 2;
166 print DB "$record\n";
167 flock DB, $UNLOCK;
168 close(DB);
169
170 } # End of add_record subroutine.
171 ###########################################
172 sub print_add_screen{
173 print<
180