%args> $glossmax => undef $placemax => undef $valsiword => undef $type => undef $valsiid => undef $langid => undef $definitiontxt => undef $notes => undef $jargon => undef $valsitxt => undef $langtag => undef $selmaho => undef $final => undef %oldargs => undef %args> <%shared> our $titlestr; our $notready = 0; %shared> <%method title> Adding definition: <% $titlestr %> %method> <%init> our($dbh,%session); use utils; use Unicode::String; use String::Approx 'amatch'; $r->content_type("text/html; charset=utf-8"); my $editbitsret; %init> <%perl> #print "
".Dumper(\%ARGS).""; #print "
v: $valsiid, $valsiword, $langid, $type.\n"; #print "
add: $glossadd, $glossmax, $placeadd, $placemax.\n"; # Either the user got here through addvalsi, in which case # valsiword will be set, or they got here through dict/dhandler, # and/or editdef.html, in which case valsiid will be set. my($langrealname); if( defined( $valsiid )) { my @initialresult = $dbh->selectrow_array("SELECT (SELECT word FROM valsi WHERE valsiid=?), realname, tag FROM languages WHERE langid=?", undef, $valsiid, $langid); ($valsiword,$langrealname,$langtag) = @initialresult; } elsif( defined( $valsiword )) { my @initialresult = $dbh->selectrow_array("SELECT realname, tag FROM languages WHERE langid=?", undef, $langid); ($langrealname,$langtag) = @initialresult; } else { $m->out("Sorry, couldn't find either the valsi ID you requested, or something else went wrong."); return; } %perl> <%doc> editbits does all the actual work, and returns 0 if more work is needed, 1 if we're readt to save, and undef on error. %doc> <%perl> $titlestr = sprintf('Adding definition for "%s" in language "%s"', $valsiword, $langrealname); if( ! $final ) { %perl> Adding definition for "<% $valsiword %>" in language "<% $langrealname %>"
".Dumper(\@nlwrets).""; my @glosskeywords = @{ $nlwrets[0] }; my @placekeywords = @{ $nlwrets[1] }; #print "
".Dumper(\@glosskeywords).""; #print "
".Dumper(\@placekeywords).""; # If the valsi hasn't been created yet if( ! defined( $valsiid )) { %perl>
Ok, I'm adding the word to the database.
<%perl> $dbh->do("INSERT INTO valsi (word, typeid, userid, time) VALUES (?, (SELECT typeid FROM valsitypes WHERE descriptor=?), ?, ?)", {}, $valsiword, $type, $session{'userid'}, time()) or $dbh->errstr; # Get the valsiid of the word we just created $valsiid = $dbh->selectrow_array("SELECT valsiid FROM valsi WHERE word=?", undef, $valsiword); } my @seqvalueresult = $dbh->selectrow_array("SELECT nextval('definitions_definitionid_seq')") or die $dbh->errstr; $dbh->do("INSERT INTO definitions ". "(definitionid, langid, valsiid, definitionNum, definition, selmaho, notes, jargon, userid, time) ". "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", undef, $seqvalueresult[0], $langid, $valsiid, $seqvalueresult[0], $definitiontxt, $selmaho, $notes, $jargon, $session{'userid'}, time()) or die $dbh->errstr; for(my $i=0; $i<=$#glosskeywords; $i++) { next unless (defined $glosskeywords[$i] && $glosskeywords[$i]->[0]); my @tmp = @{ $glosskeywords[$i] }; my $meaning = $tmp[1] ? $tmp[1] : undef; $dbh->do('INSERT INTO keywordmapping (definitionid, place, natlangwordid) '. 'VALUES (?, 0, (SELECT wordid FROM natlangwords '. 'WHERE langid=?::integer AND word=?::text AND '. '(meaning=?::text OR (?::text IS NULL AND meaning IS NULL))))', undef, $seqvalueresult[0], $langid, $tmp[0], $meaning, $meaning ) or die $dbh->errstr; } for(my $i=0; $i<=$#placekeywords; $i++) { next unless (defined $placekeywords[$i] && $placekeywords[$i]->[0]); my @tmp = @{ $placekeywords[$i] }; my $meaning = $tmp[1] ? $tmp[1] : undef; $dbh->do('INSERT INTO keywordmapping (definitionid, place, natlangwordid) '. 'VALUES (?, ?, (SELECT wordid FROM natlangwords '. 'WHERE langid=?::integer AND word=?::text AND '. '(meaning=?::text OR (?::text IS NULL AND meaning IS NULL))))', undef, $seqvalueresult[0], $i+1, $langid, $tmp[0], $meaning, $meaning ) or die $dbh->errstr; } $dbh->do("DELETE FROM definitionvotes WHERE valsiid=? and langid=? and userid=?", undef, $valsiid, $langid, $session{'userid'}) or die $dbh->errstr; $dbh->do("INSERT INTO definitionvotes (valsiid, langid, definitionid, value, userid, time) VALUES (?, ?, ?, (SELECT votesize FROM users WHERE userid=?), ?, ?)", undef, $valsiid, $langid, $seqvalueresult[0], $session{'userid'}, $session{'userid'}, time()) or die $dbh->errstr; # Deal with the voting $m->comp( 'votebits', %ARGS, definition => $seqvalueresult[0] ); $dbh->commit; # Get the current definition data my %newcontent = $m->comp( 'getdef', definitionid => $seqvalueresult[0]); # Send e-mail to various people $m->comp( 'mailbits', newcontent => \%newcontent, type => "added", typeUpper => "Added", valsiid => $valsiid, langid => $langid, valsiword => $valsitxt, ); # Update valsibestguesses my $jbovlastedir = $m->base_comp->attr('jbovlaste_dir'); system( "$jbovlastedir/bin/updatevbg $jbovlastedir $langid $valsiid $session{'userid'} $seqvalueresult[0] \&" ); %perl>If you're seeing this, it probably worked. Please go to the definition you added and check on things. A vote for you on the definition you just added has already been recorded.
<%perl> } %perl>