sub PrepareString{ # creates $addstring, $id for AddStringToDatabase # We are going to use a new data type for the keywords. Since # this is not really relevant to the other db entries we'll use # data type 9, to leave some space for improvements # the database. takes $call{'parameters'}, makes $addstring $count = $hash{'0'}; $count = ($count +1); $hash{'0'} = $count; $id = $count; # cat all these variables into addstring, seperated by | $addstring = $id . "|" . "9" . "|" . # datatype "Admin" . "|" . "None" . "|"; # Discussion: # We are storing a set of keyword values to a specific # keyword. We may want to parse this subset later so we'll # put in each keyword set like this x=y:x=z: # $call{'values[$values 1 - x]'} $i = 1; while ($i <= $call{'values'}){ $val = ("values" . $i); $addstring = $addstring . "$call{'keyword'}=$call{$val}:"; $i++; } $i = '0'; # to finish our string, another | and the question text $addstring = $addstring . "|" . "None"; } sub AddStringToDatabase{ # assumes db is open and ready to accept data # adds addstring to the database. add string is an # assembled entry to the database it will be added at $id $hash{$id} = $addstring; } sub CheckFields { @required = { namefirst, namelast, contactemail, administratorlogin, administratorpassword, databasepretty, databasename }; foreach $field (@required){ if (!($call{$field})){ $error = "Required Field: $call($field)"; } } } sub CheckDatabaseName{ if ($call{databasename}){ if ($call{databasename} =~ m/ /){ $error = "short database name must be one word!"; } } } sub CreateDatabase{ tie %hash, DB_File, '/tmp/newdb.dbm' # open database, to be accessed or print "Can't open $newdatabase: $!\n"; # through %HASH # temporarily populate db $hash{1} = $call{'administratorlogin'}; system ("chmod o+w /tmp/newdb.dbm"); system ("mv /tmp/newdb.dbm $databasedir$call{databasename}.dbm"); print "Pre-Log error: $!"; open (LOG, ">>$logdata") || print "Can't open $logdata: $!"; print "Initalizing Database: $hash{1}: $!"; print LOG "Initalizing Database: $hash{1}: $!\n"; close (LOG); untie %hash; # close the database } sub AddBasicInfo{ $dbmlocation = $databasedir . $call{databasename} . ".dbm"; tie %hash, DB_File, $dbmlocation # open database, to be accessed or print "Can't open $dbmlocation: $!\n"; # through %HASH $hash{'0'} = '10'; # put string in database $hash{'1'} = $call{'administratorlogin'}; $hash{'4'} = $call{'password'}; $hash{'3'} = 'false'; # for future implements $hash{'5'} = ( $call{'namefirst'} . "&" . $call{'namelast'} . "&" . $call{'contactemail'} ); $hash{'6'} = $call{'databasepretty'}; $hash{'7'} = $call{'databasename'}; untie %hash; open LOG, '>>$logdata' || print "Can't open $logdata: $!"; print LOG "Initalizing Database Variables: $dbmlocation\n"; print "Initalizing Database Variables: $dbmlocation\n"; close LOG; } sub openDBhash{ # need to implement lock routines here tie %hash, DB_File, $dbmfile # open database, to be accessed or print "Can't open $dbmfile: $!\n"; # through %HASH } sub closeDBhash{ untie %hash; # close the database } 1;