Revision 2801
Added by sgarg about 19 years ago
src/perl/register-dataset.cgi | ||
---|---|---|
87 | 87 |
$config->define("spatialRequired", { DEFAULT => 'true'} ); |
88 | 88 |
$config->define("contactEmailAddressRequired", { DEFAULT => 'false'} ); |
89 | 89 |
$config->define("publicReadable", { DEFAULT => 'true'} ); |
90 |
$config->define("adminIsOwner", { DEFAULT => 'false'} ); |
|
90 | 91 |
$config->define("moderators", { DEFAULT => ''} ); |
91 | 92 |
$config->define("mailhost"); |
92 | 93 |
$config->define("sender"); |
... | ... | |
103 | 104 |
$config->define("loginFormTemplate", { DEFAULT => 'crap.tmpl'} ); |
104 | 105 |
$config->define("confirmDataTemplate", { DEFAULT => 'crap.tmpl'} ); |
105 | 106 |
$config->define("deleteDataTemplate", { DEFAULT => 'crap.tmpl'} ); |
106 |
$config->define("modNotificationTemplate", { DEFAULT => 'crap.tmpl'} ); |
|
107 |
$config->define("modEmailNotificationTemplate", { DEFAULT => 'crap.tmpl'} ); |
|
108 |
$config->define("modResultTemplate", { DEFAULT => 'crap.tmpl'} ); |
|
107 | 109 |
$config->define("debug", { DEFAULT => '0'} ); |
108 | 110 |
$config->define("lat", { ARGCOUNT => ARGCOUNT_HASH} ); |
109 | 111 |
$config->define("lon", { ARGCOUNT => ARGCOUNT_HASH} ); |
110 | 112 |
|
113 |
|
|
111 | 114 |
if (! hasContent($FORM::cfg)) { |
112 | 115 |
$error = "Application misconfigured. Please contact the administrator."; |
113 | 116 |
push(@errorMessages, $error); |
... | ... | |
132 | 135 |
my $guideTemplate = $config->guideTemplate(); |
133 | 136 |
my $loginFormTemplate = $config->loginFormTemplate(); |
134 | 137 |
my $confirmDataTemplate = $config->confirmDataTemplate(); |
135 |
my $modNotificationTemplate = $config->modNotificationTemplate(); |
|
138 |
my $modEmailNotificationTemplate = $config->modEmailNotificationTemplate(); |
|
139 |
my $modResultTemplate = $config->modResultTemplate(); |
|
136 | 140 |
my $accesspubid = $config->accesspubid(); |
137 | 141 |
my $accesssysid = $config->accesssysid(); |
138 | 142 |
my $datasetpubid = $config->datasetpubid(); |
... | ... | |
151 | 155 |
my $spatialRequired = $config->spatialRequired(); |
152 | 156 |
my $contactEmailAddressRequired = $config->contactEmailAddressRequired(); |
153 | 157 |
my $publicReadable = $config->publicReadable(); |
158 |
my $adminIsDocOwner = $config->adminIsDocOwner(); |
|
154 | 159 |
my $moderators = $config->moderators(); |
155 | 160 |
my $mailhost = $config->mailhost(); |
156 | 161 |
my $sender = $config->sender(); |
... | ... | |
342 | 347 |
my $longMin2 = ""; |
343 | 348 |
my $longSec2 = ""; |
344 | 349 |
my $hemisphLong2 = ""; |
350 |
my $modUsername = ""; |
|
351 |
my $modPassword = ""; |
|
345 | 352 |
|
346 | 353 |
# validate the input form parameters |
347 | 354 |
my $invalidParams; |
... | ... | |
385 | 392 |
|
386 | 393 |
my $errorMessage = ""; |
387 | 394 |
my $response = $metacat->login($dname, $userPass); |
395 |
|
|
396 |
|
|
388 | 397 |
if (! $response) { |
389 | 398 |
push(@errorMessages, $metacat->getMessage()); |
390 | 399 |
push(@errorMessages, "Failed during login.\n"); |
... | ... | |
398 | 407 |
exit(0); |
399 | 408 |
} else { |
400 | 409 |
|
410 |
if($adminIsDocOwner == 'true'){ |
|
411 |
$response = $metacat->login($username, $password); |
|
412 |
if (! $response) { |
|
413 |
push(@errorMessages, $metacat->getMessage()); |
|
414 |
push(@errorMessages, "Failed during login for admin.\n"); |
|
415 |
$$templateVars{'status'} = 'login_failure'; |
|
416 |
$$templateVars{'errorMessages'} = \@errorMessages; |
|
417 |
$$templateVars{'docid'} = $docid; |
|
418 |
$$templateVars{'cfg'} = $FORM::cfg; |
|
419 |
$$templateVars{'function'} = "submitted"; |
|
420 |
$$templateVars{'section'} = "Submission Status"; |
|
421 |
$template->process( $responseTemplate, $templateVars); |
|
422 |
exit(0); |
|
423 |
} |
|
424 |
} |
|
425 |
|
|
401 | 426 |
debug( "Registry: A"); |
402 | 427 |
if ($FORM::docid eq "") { |
403 | 428 |
debug( "Registry: B1"); |
... | ... | |
788 | 813 |
push(@invalidParams, "Last name of data set contact is missing.") |
789 | 814 |
unless (hasContent($FORM::origNamelastContact) || |
790 | 815 |
$FORM::useOrigAddress); |
791 |
push(@invalidParams, "Email address of data set contact is missing.") |
|
792 |
unless (hasContent($FORM::origEmailContact) || $FORM::contactEmailAddressRequired ne 'true' ); |
|
816 |
if($FORM::contactEmailAddressRequired eq 'true'){ |
|
817 |
if($FORM::useOrigAddress){ |
|
818 |
push(@invalidParams, "Email address of data set owner is missing. This is required as it will be used as contact email address as specified by you.") |
|
819 |
unless (hasContent($FORM::origEmail)); |
|
820 |
} else { |
|
821 |
push(@invalidParams, "Email address of data set contact is missing.") |
|
822 |
unless (hasContent($FORM::origEmailContact)); |
|
823 |
} |
|
824 |
} |
|
793 | 825 |
push(@invalidParams, "Data medium is missing.") |
794 | 826 |
unless (hasContent($FORM::dataMedium) || $FORM::dataMedium =~ /elect/); |
795 | 827 |
push(@invalidParams, "Usage rights are missing.") |
... | ... | |
2521 | 2553 |
|
2522 | 2554 |
################################################################################ |
2523 | 2555 |
# |
2556 |
# function to check if the moderator is logged in - if yes, then username and |
|
2557 |
# password are set |
|
2558 |
# |
|
2559 |
################################################################################ |
|
2560 |
sub isModerator { |
|
2561 |
my $stage = shift; |
|
2562 |
|
|
2563 |
my $returnValue = 1; |
|
2564 |
|
|
2565 |
# Check if the session exists |
|
2566 |
my $session = CGI::Session->load(); |
|
2567 |
if ( $session->is_empty || $session->is_expired) { |
|
2568 |
# no session found ... send back to index.html page ... |
|
2569 |
processResultTemplate($stage, 'failure', "Moderator is not logged in.\n"); |
|
2570 |
$returnValue = -1; |
|
2571 |
} |
|
2572 |
|
|
2573 |
# check if logged in user is moderator |
|
2574 |
my $moderator = $session->param("moderator"); |
|
2575 |
if ( $moderator ne 'true') { |
|
2576 |
# no session found ... send back to index.html page ... |
|
2577 |
debug("Logged in user is not moderator"); |
|
2578 |
processResultTemplate($stage, 'failure', "Logged in user is not moderator.\n"); |
|
2579 |
$returnValue = -1; |
|
2580 |
} |
|
2581 |
|
|
2582 |
if($returnValue eq 1){ |
|
2583 |
$modUsername = $session->param("username"); |
|
2584 |
$modPassword = $session->param("password"); |
|
2585 |
} |
|
2586 |
|
|
2587 |
return $returnValue; |
|
2588 |
} |
|
2589 |
|
|
2590 |
################################################################################ |
|
2591 |
# |
|
2524 | 2592 |
# function to handle accept request for moderator |
2525 | 2593 |
# |
2526 | 2594 |
################################################################################ |
2527 | 2595 |
sub handleModAccept(){ |
2528 | 2596 |
|
2529 |
my $metacat; |
|
2597 |
my $errorMessage = ''; |
|
2598 |
my $metacat; |
|
2530 | 2599 |
$metacat = Metacat->new(); |
2531 | 2600 |
if ($metacat) { |
2532 | 2601 |
$metacat->set_options( metacatUrl => $metacatUrl ); |
2533 | 2602 |
} else { |
2534 | 2603 |
#die "failed during metacat creation\n"; |
2535 |
push(@errorMessages, "Failed during metacat creation.");
|
|
2604 |
$errorMessage = $errorMessage." Failed during metacat creation.";
|
|
2536 | 2605 |
} |
2537 | 2606 |
|
2538 | 2607 |
print "Content-type: text/html\n\n"; |
2539 | 2608 |
|
2540 |
# Check if the session exists |
|
2541 | 2609 |
debug("Stage is mod_accept"); |
2542 | 2610 |
|
2543 |
my $session = CGI::Session->load(); |
|
2544 |
if ( $session->is_empty || $session->is_expired) { |
|
2545 |
# no session found ... send back to index.html page ... |
|
2546 |
push(@errorMessages, "Failed during login.\n"); |
|
2547 |
processErrorTemplate('login_failure', 'loginform', 'Login Status'); |
|
2548 |
return; |
|
2549 |
} |
|
2550 |
|
|
2551 |
# check if logged in user is moderator |
|
2552 |
my $moderator = $session->param("moderator"); |
|
2553 |
if ( $moderator ne 'true') { |
|
2554 |
# no session found ... send back to index.html page ... |
|
2555 |
debug("Logged in user is not moderator"); |
|
2556 |
push(@errorMessages, "Logged in user is not moderator. Please login again as moderator\n"); |
|
2557 |
processErrorTemplate('login_failure', 'loginform', 'Login Status'); |
|
2558 |
return; |
|
2559 |
} |
|
2560 |
|
|
2561 |
# change the access rules |
|
2562 |
|
|
2611 |
my $isMod = isModerator("accept"); |
|
2612 |
if($isMod < 0){ |
|
2613 |
return; |
|
2614 |
} |
|
2615 |
# change the access rules |
|
2563 | 2616 |
## create the access block |
2564 | 2617 |
my $accessblock = ''; |
2565 | 2618 |
$accessblock .= "<access authSystem=\"knb\" order=\"denyFirst\">\n"; |
... | ... | |
2582 | 2635 |
$accessblock .= "</access>\n"; |
2583 | 2636 |
|
2584 | 2637 |
## read the document from |
2585 |
my $docFromMetacat = readDocumentFromMetacat(); |
|
2586 |
my ($emldoc, $temp) = split('<access authSystem=', $docFromMetacat); |
|
2638 |
my $parser = XML::LibXML->new(); |
|
2639 |
my $title = ''; |
|
2640 |
my $contactEmailAddress = ''; |
|
2641 |
my $contactName = ''; |
|
2642 |
# Log into metacat |
|
2643 |
my $response = $metacat->login($modUsername, $modPassword); |
|
2587 | 2644 |
|
2588 |
$emldoc .= $accessblock; |
|
2589 |
$emldoc .= "</dataset>\n</eml:eml>\n"; |
|
2645 |
if (! $response) { |
|
2646 |
# Could not login |
|
2647 |
$errorMessage = $errorMessage." Failed during moderator login."; |
|
2590 | 2648 |
|
2591 |
debug("Document created by handleModAccept is " . $emldoc); |
|
2649 |
} else { |
|
2650 |
# read the document and get the contact name and address |
|
2651 |
my $docid = $FORM::docid; |
|
2652 |
$response = $metacat->read($docid); |
|
2653 |
my $docFromMetacat = $response->content(); |
|
2654 |
my $xmldoc = $parser->parse_string($docFromMetacat); |
|
2592 | 2655 |
|
2593 |
# update the document |
|
2594 |
my $docid = $FORM::docid; |
|
2656 |
if ($xmldoc eq "" || $docFromMetacat=~ /<error/) { |
|
2657 |
# not able to parse |
|
2658 |
$errorMessage = $errorMessage." Error in reading the following docid:".$docid; |
|
2659 |
} else { |
|
2660 |
my ($emldoc, $temp) = split('<access authSystem=', $docFromMetacat); |
|
2661 |
$emldoc .= $accessblock; |
|
2662 |
$emldoc .= "</dataset>\n</eml:eml>\n"; |
|
2663 |
|
|
2664 |
#debug("Document created by handleModAccept is " . $emldoc); |
|
2665 |
# update the document |
|
2666 |
my $docid = $FORM::docid; |
|
2595 | 2667 |
|
2596 |
my $x; |
|
2597 |
my $y; |
|
2598 |
my $z; |
|
2668 |
my $x;
|
|
2669 |
my $y;
|
|
2670 |
my $z;
|
|
2599 | 2671 |
|
2600 |
($x, $y, $z) = split(/\./, $docid); |
|
2601 |
$z++; |
|
2602 |
$docid = "$x.$y.$z"; |
|
2672 |
($x, $y, $z) = split(/\./, $docid);
|
|
2673 |
$z++;
|
|
2674 |
$docid = "$x.$y.$z";
|
|
2603 | 2675 |
|
2604 |
$emldoc =~ s/packageId=\"docid\"/packageId=\"$docid\"/; |
|
2605 |
|
|
2606 |
my $response = $metacat->update($docid, $emldoc); |
|
2676 |
$emldoc =~ s/packageId=\"docid\"/packageId=\"$docid\"/; |
|
2677 |
$response = $metacat->update($docid, $emldoc); |
|
2607 | 2678 |
|
2608 |
if (! $response) { |
|
2609 |
debug("Error while updating in handleModAccept."); |
|
2679 |
if (! $response) { |
|
2680 |
debug("Error while updating in handleModAccept."); |
|
2681 |
#push(@errorMessages, $metacat->getMessage()); |
|
2682 |
$errorMessage = $errorMessage." Failed while updating the document with new access rules."; |
|
2683 |
} |
|
2610 | 2684 |
|
2611 |
push(@errorMessages, $metacat->getMessage());
|
|
2612 |
push(@errorMessages, "Failed while updating.\n");
|
|
2685 |
# get the contact email address from the
|
|
2686 |
$xmldoc = $parser->parse_string($emldoc);
|
|
2613 | 2687 |
|
2614 |
############ TODO: need for proper error message |
|
2615 |
} |
|
2616 |
|
|
2617 |
# get the contact email address from the |
|
2618 |
my $parser = XML::LibXML->new(); |
|
2619 |
my $xmldoc = $parser->parse_string($emldoc); |
|
2620 |
my $title = ''; |
|
2621 |
my $contactEmailAddress = ''; |
|
2622 |
my $contactName = ''; |
|
2623 |
|
|
2624 |
if ($xmldoc eq "" || $xmldoc=~ /<error/) { |
|
2625 |
# not able to parse |
|
2626 |
push(@errorMessages, "Error in reading the docid:".$docid."\n"); |
|
2627 |
} else { |
|
2628 |
my $findNodes = $xmldoc->findnodes('//dataset/contact'); |
|
2629 |
if($findNodes->size() > 0){ |
|
2630 |
# found contact email address |
|
2631 |
my $node = ''; |
|
2632 |
foreach $node ($findNodes->get_nodelist) { |
|
2633 |
$contactEmailAddress = findValue($node,'electronicMailAddress'); |
|
2634 |
my $surName = findValue($node,'individualName/surName'); |
|
2635 |
my $givenName = findValue($node,'individualName/givenName'); |
|
2636 |
my $organizationName = findValue($node,'organizaitionName'); |
|
2688 |
if ($xmldoc eq "" || $xmldoc=~ /<error/) { |
|
2689 |
# not able to parse |
|
2690 |
$errorMessage = $errorMessage." Error in reading the docid:".$docid; |
|
2691 |
} else { |
|
2692 |
my $findNodes = $xmldoc->findnodes('//dataset/contact'); |
|
2693 |
if($findNodes->size() > 0){ |
|
2694 |
# found contact email address |
|
2695 |
my $node = ''; |
|
2696 |
foreach $node ($findNodes->get_nodelist) { |
|
2697 |
$contactEmailAddress = findValue($node,'electronicMailAddress'); |
|
2698 |
my $surName = findValue($node,'individualName/surName'); |
|
2699 |
my $givenName = findValue($node,'individualName/givenName'); |
|
2700 |
my $organizationName = findValue($node,'organizaitionName'); |
|
2637 | 2701 |
|
2638 |
if($surName ne ''){ |
|
2639 |
$contactName = $givenName.' '.$surName; |
|
2640 |
} else { |
|
2641 |
$contactName = $organizationName; |
|
2702 |
if($surName ne ''){ |
|
2703 |
$contactName = $givenName.' '.$surName; |
|
2704 |
} else { |
|
2705 |
$contactName = $organizationName; |
|
2706 |
} |
|
2642 | 2707 |
} |
2708 |
} else { |
|
2709 |
$contactEmailAddress = ''; |
|
2643 | 2710 |
} |
2644 |
} else {
|
|
2645 |
$contactEmailAddress = '';
|
|
2646 |
}
|
|
2647 |
$findNodes = $xmldoc->findnodes('//dataset/title');
|
|
2648 |
if($findNodes->size() > 0){
|
|
2649 |
# found title
|
|
2650 |
my $node = '';
|
|
2651 |
foreach $node ($findNodes->get_nodelist) {
|
|
2652 |
$title = findValue($node,'../title');
|
|
2711 |
$findNodes = $xmldoc->findnodes('//dataset/title');
|
|
2712 |
if($findNodes->size() > 0){
|
|
2713 |
# found title
|
|
2714 |
my $node = '';
|
|
2715 |
foreach $node ($findNodes->get_nodelist) {
|
|
2716 |
$title = findValue($node,'../title');
|
|
2717 |
}
|
|
2718 |
} else {
|
|
2719 |
$title = '';
|
|
2653 | 2720 |
} |
2654 |
} else { |
|
2655 |
$title = ''; |
|
2656 |
} |
|
2657 |
} |
|
2658 |
|
|
2721 |
} |
|
2722 |
} |
|
2723 |
} |
|
2659 | 2724 |
# send notification to the user and the moderator |
2660 |
if (!scalar(@errorMessages)) { |
|
2661 |
# send notifications |
|
2662 |
mod_sendNotification($title, $contactEmailAddress, $contactName, 'Document '.$FORM::docid.' Accepted'); |
|
2663 |
|
|
2664 |
$$templateVars{'function'} = "deleted"; |
|
2665 |
$$templateVars{'section'} = "Deletion Status"; |
|
2666 |
$template->process( $responseTemplate, $templateVars); |
|
2725 |
if ($errorMessage eq '') { |
|
2726 |
# send notifications |
|
2727 |
mod_sendNotification($title, $contactEmailAddress, $contactName, 'Document '.$FORM::docid.' Accepted'); |
|
2728 |
processResultTemplate('accept', 'success', $errorMessage); |
|
2667 | 2729 |
} else { |
2668 |
############ TODO: need for proper error message |
|
2669 |
processErrorTemplate('failure', '', 'Unable to delete the document'); |
|
2670 |
} |
|
2730 |
processResultTemplate('accept', 'failure', $errorMessage); |
|
2731 |
} |
|
2671 | 2732 |
} |
2672 | 2733 |
|
2673 | 2734 |
################################################################################ |
... | ... | |
2677 | 2738 |
################################################################################ |
2678 | 2739 |
sub handleModDecline(){ |
2679 | 2740 |
|
2680 |
my $metacat; |
|
2741 |
my $errorMessage = ''; |
|
2742 |
my $metacat; |
|
2681 | 2743 |
$metacat = Metacat->new(); |
2682 | 2744 |
if ($metacat) { |
2683 | 2745 |
$metacat->set_options( metacatUrl => $metacatUrl ); |
2684 | 2746 |
} else { |
2685 | 2747 |
#die "failed during metacat creation\n"; |
2686 |
push(@errorMessages, "Failed during metacat creation.");
|
|
2748 |
$errorMessage = $errorMessage." Failed during metacat object creation.";
|
|
2687 | 2749 |
} |
2688 | 2750 |
|
2689 | 2751 |
print "Content-type: text/html\n\n"; |
2690 | 2752 |
|
2691 |
# Check if the session exists |
|
2692 | 2753 |
debug("Stage is mod_decline"); |
2693 | 2754 |
|
2694 |
my $session = CGI::Session->load(); |
|
2695 |
if ( $session->is_empty || $session->is_expired) { |
|
2696 |
# no session found ... send back to index.html page ... |
|
2697 |
push(@errorMessages, "Failed during login.\n"); |
|
2698 |
processErrorTemplate('login_failure', 'loginform', 'Login Status'); |
|
2699 |
return; |
|
2700 |
} |
|
2755 |
if(isModerator('decline')<0){ |
|
2756 |
return; |
|
2757 |
} |
|
2701 | 2758 |
|
2702 |
# check if logged in user is moderator |
|
2703 |
my $moderator = $session->param("moderator"); |
|
2704 |
if ( $moderator ne 'true') { |
|
2705 |
# no session found ... send back to index.html page ... |
|
2706 |
debug("Logged in user is not moderator"); |
|
2707 |
push(@errorMessages, "Logged in user is not moderator. Please login again as moderator\n"); |
|
2708 |
processErrorTemplate('login_failure', 'loginform', 'Login Status'); |
|
2709 |
return; |
|
2710 |
} |
|
2711 |
|
|
2712 |
# variables for contact information |
|
2713 |
my $contactEmailAddress; |
|
2714 |
my $contactName; |
|
2715 |
my $title; |
|
2759 |
# variables for contact information |
|
2760 |
my $contactEmailAddress; |
|
2761 |
my $contactName; |
|
2762 |
my $title; |
|
2716 | 2763 |
|
2717 |
# Log into metacat |
|
2718 |
my $username = $session->param("username"); |
|
2719 |
my $password = $session->param("password"); |
|
2720 |
my $response = $metacat->login($username, $password); |
|
2764 |
# Log into metacat |
|
2765 |
my $response = $metacat->login($modUsername, $modPassword); |
|
2721 | 2766 |
|
2722 |
if (! $response) { |
|
2723 |
# Could not login |
|
2724 |
push(@errorMessages, $metacat->getMessage()); |
|
2725 |
push(@errorMessages, "Failed during login.\n"); |
|
2726 |
|
|
2767 |
if (! $response) { |
|
2768 |
# Could not login |
|
2769 |
#push(@errorMessages, $metacat->getMessage()); |
|
2770 |
$errorMessage = $errorMessage." Failed during moderator login."; |
|
2727 | 2771 |
} else { |
2728 | 2772 |
# read the document and get the contact name and address |
2729 |
my $parser = XML::LibXML->new();
|
|
2773 |
my $parser = XML::LibXML->new(); |
|
2730 | 2774 |
my $docid = $FORM::docid; |
2731 | 2775 |
|
2732 |
$response = $metacat->read($docid);
|
|
2733 |
my $doc = $response->content();
|
|
2776 |
$response = $metacat->read($docid); |
|
2777 |
my $doc = $response->content(); |
|
2734 | 2778 |
my $xmldoc = $parser->parse_string($doc); |
2735 | 2779 |
|
2736 | 2780 |
if ($xmldoc eq "" || $doc=~ /<error/) { |
2737 | 2781 |
# not able to parse |
2738 |
push(@errorMessages, "Error in reading the docid:".$docid."\n"); |
|
2739 |
} else { |
|
2740 |
my $findNodes = $xmldoc->findnodes('//dataset/contact'); |
|
2741 |
if($findNodes->size() > 0){ |
|
2742 |
# found contact email address |
|
2743 |
my $node = ''; |
|
2744 |
foreach $node ($findNodes->get_nodelist) { |
|
2745 |
$contactEmailAddress = findValue($node,'electronicMailAddress'); |
|
2746 |
|
|
2747 |
my $surName = findValue($node,'individualName/surName'); |
|
2748 |
my $givenName = findValue($node,'individualName/givenName'); |
|
2749 |
my $organizationName = findValue($node,'organizaitionName'); |
|
2750 |
|
|
2751 |
if($surName ne ''){ |
|
2752 |
$contactName = $givenName.' '.$surName; |
|
2753 |
} else { |
|
2754 |
$contactName = $organizationName; |
|
2755 |
} |
|
2756 |
} |
|
2782 |
$errorMessage = $errorMessage." Error in reading the docid:".$docid; |
|
2783 |
} else { |
|
2784 |
my $findNodes = $xmldoc->findnodes('//dataset/contact'); |
|
2785 |
if($findNodes->size() > 0){ |
|
2786 |
# found contact email address |
|
2787 |
my $node = ''; |
|
2788 |
foreach $node ($findNodes->get_nodelist) { |
|
2789 |
$contactEmailAddress = findValue($node,'electronicMailAddress'); |
|
2790 |
my $surName = findValue($node,'individualName/surName'); |
|
2791 |
my $givenName = findValue($node,'individualName/givenName'); |
|
2792 |
my $organizationName = findValue($node,'organizaitionName'); |
|
2793 |
|
|
2794 |
if($surName ne ''){ |
|
2795 |
$contactName = $givenName.' '.$surName; |
|
2757 | 2796 |
} else { |
2758 |
$contactEmailAddress = '';
|
|
2797 |
$contactName = $organizationName;
|
|
2759 | 2798 |
} |
2760 |
$findNodes = $xmldoc->findnodes('//dataset/title'); |
|
2761 |
if($findNodes->size() > 0){ |
|
2762 |
# found title |
|
2763 |
my $node = ''; |
|
2764 |
foreach $node ($findNodes->get_nodelist) { |
|
2765 |
$title = findValue($node,'../title'); |
|
2766 |
} |
|
2767 |
} else { |
|
2768 |
$title = ''; |
|
2769 |
} |
|
2770 |
|
|
2771 | 2799 |
} |
2772 |
|
|
2773 |
$response = $metacat->delete($docid); |
|
2774 |
if (!$response) { |
|
2775 |
debug("Error while deleting document in handleModDecline."); |
|
2776 |
push(@errorMessages, $metacat->getMessage()); |
|
2777 |
push(@errorMessages, "Failed during deleting $docid. Please check if you are authorized to delete this document.\n"); |
|
2778 | 2800 |
} else { |
2779 |
debug("Document deleted by handleModDecline is " . $docid); |
|
2801 |
$contactEmailAddress = ''; |
|
2802 |
} |
|
2803 |
$findNodes = $xmldoc->findnodes('//dataset/title'); |
|
2804 |
if($findNodes->size() > 0){ |
|
2805 |
# found title |
|
2806 |
my $node = ''; |
|
2807 |
foreach $node ($findNodes->get_nodelist) { |
|
2808 |
$title = findValue($node,'../title'); |
|
2780 | 2809 |
} |
2810 |
} else { |
|
2811 |
$title = ''; |
|
2812 |
} |
|
2781 | 2813 |
} |
2782 | 2814 |
|
2783 |
if (!scalar(@errorMessages)) { |
|
2784 |
# send notifications |
|
2785 |
mod_sendNotification($title, $contactEmailAddress, $contactName, 'Document '.$FORM::docid.' Rejected'); |
|
2815 |
$response = $metacat->delete($docid); |
|
2816 |
if (!$response) { |
|
2817 |
debug("Error while deleting document in handleModDecline."); |
|
2818 |
#push(@errorMessages, $metacat->getMessage()); |
|
2819 |
$errorMessage = $errorMessage." Failed during deleting $docid. Please check if you are authorized to delete this document or if the document is not already deleted."; |
|
2820 |
} else { |
|
2821 |
debug("Document deleted by handleModDecline is " . $docid); |
|
2822 |
} |
|
2823 |
} |
|
2786 | 2824 |
|
2787 |
$$templateVars{'function'} = "deleted"; |
|
2788 |
$$templateVars{'section'} = "Deletion Status"; |
|
2789 |
$template->process( $responseTemplate, $templateVars); |
|
2825 |
if ($errorMessage eq '') { |
|
2826 |
# send notifications |
|
2827 |
mod_sendNotification($title, $contactEmailAddress, $contactName, 'Document '.$FORM::docid.' Rejected'); |
|
2828 |
processResultTemplate('decline', 'success', $errorMessage); |
|
2790 | 2829 |
} else { |
2791 |
############ TODO: need for proper error message |
|
2792 |
processErrorTemplate('failure', '', 'Unable to delete the document'); |
|
2793 |
} |
|
2830 |
processResultTemplate('decline', 'failure', $errorMessage); |
|
2831 |
} |
|
2794 | 2832 |
} |
2795 | 2833 |
|
2796 | 2834 |
################################################################################ |
... | ... | |
2799 | 2837 |
# |
2800 | 2838 |
################################################################################ |
2801 | 2839 |
sub handleModRevise(){ |
2802 |
|
|
2803 |
my $metacat;
|
|
2840 |
my $errorMessage = ''; |
|
2841 |
my $metacat;
|
|
2804 | 2842 |
$metacat = Metacat->new(); |
2805 | 2843 |
if ($metacat) { |
2806 | 2844 |
$metacat->set_options( metacatUrl => $metacatUrl ); |
2807 | 2845 |
} else { |
2808 | 2846 |
#die "failed during metacat creation\n"; |
2809 |
push(@errorMessages, "Failed during metacat creation.");
|
|
2847 |
$errorMessage = $errorMessage." Failed during metacat creation.";
|
|
2810 | 2848 |
} |
2811 | 2849 |
|
2812 | 2850 |
print "Content-type: text/html\n\n"; |
2813 | 2851 |
|
2814 |
# Check if the session exists |
|
2815 | 2852 |
debug("Stage is mod_revise"); |
2816 | 2853 |
|
2817 |
my $session = CGI::Session->load(); |
|
2818 |
if ( $session->is_empty || $session->is_expired) { |
|
2819 |
# no session found ... send back to index.html page ... |
|
2820 |
push(@errorMessages, "Failed during login.\n"); |
|
2821 |
processErrorTemplate('login_failure', 'loginform', 'Login Status'); |
|
2822 |
return; |
|
2823 |
} |
|
2854 |
if(isModerator('revise')<0){ |
|
2855 |
return; |
|
2856 |
} |
|
2857 |
|
|
2858 |
# variables for contact information |
|
2859 |
my $contactEmailAddress; |
|
2860 |
my $contactName; |
|
2861 |
my $title; |
|
2824 | 2862 |
|
2825 |
# check if logged in user is moderator |
|
2826 |
my $moderator = $session->param("moderator"); |
|
2827 |
if ( $moderator ne 'true') { |
|
2828 |
# no session found ... send back to index.html page ... |
|
2829 |
debug("Logged in user is not moderator"); |
|
2830 |
push(@errorMessages, "Logged in user is not moderator. Please login again as moderator\n"); |
|
2831 |
processErrorTemplate('login_failure', 'loginform', 'Login Status'); |
|
2832 |
return; |
|
2833 |
} |
|
2834 |
|
|
2835 |
# variables for contact information |
|
2836 |
my $contactEmailAddress; |
|
2837 |
my $contactName; |
|
2838 |
my $title; |
|
2839 |
|
|
2840 |
# Log into metacat |
|
2841 |
my $username = $session->param("username"); |
|
2842 |
my $password = $session->param("password"); |
|
2843 |
my $response = $metacat->login($username, $password); |
|
2863 |
# Log into metacat |
|
2864 |
my $response = $metacat->login($modUsername, $modPassword); |
|
2844 | 2865 |
|
2845 |
if (! $response) {
|
|
2866 |
if (! $response) {
|
|
2846 | 2867 |
# Could not login |
2847 |
push(@errorMessages, $metacat->getMessage()); |
|
2848 |
push(@errorMessages, "Failed during login.\n");
|
|
2868 |
#push(@errorMessages, $metacat->getMessage());
|
|
2869 |
$errorMessage = $errorMessage." Failed during moderator login.";
|
|
2849 | 2870 |
|
2850 | 2871 |
} else { |
2851 |
# read the document and get the contact name and address
|
|
2852 |
my $parser = XML::LibXML->new();
|
|
2872 |
# read the document and get the contact name and address |
|
2873 |
my $parser = XML::LibXML->new(); |
|
2853 | 2874 |
my $docid = $FORM::docid; |
2854 | 2875 |
|
2855 |
$response = $metacat->read($docid);
|
|
2856 |
my $doc = $response->content();
|
|
2876 |
$response = $metacat->read($docid); |
|
2877 |
my $doc = $response->content(); |
|
2857 | 2878 |
my $xmldoc = $parser->parse_string($doc); |
2858 | 2879 |
|
2859 | 2880 |
if ($xmldoc eq "" || $doc=~ /<error/) { |
2860 | 2881 |
# not able to parse |
2861 |
push(@errorMessages, "Error in reading the docid:".$docid."\n");
|
|
2882 |
$errorMessage = $errorMessage." Error in reading the docid:".$docid;
|
|
2862 | 2883 |
} else { |
2863 | 2884 |
my $findNodes = $xmldoc->findnodes('//dataset/contact'); |
2864 | 2885 |
if($findNodes->size() > 0){ |
... | ... | |
2893 | 2914 |
|
2894 | 2915 |
} |
2895 | 2916 |
} |
2896 |
|
|
2917 |
if ($errorMessage eq '') { |
|
2897 | 2918 |
# send notifications |
2898 | 2919 |
mod_sendNotification($title, $contactEmailAddress, $contactName, "Revise document: ".$FORM::docid); |
2899 |
|
|
2900 |
$$templateVars{'function'} = "deleted";
|
|
2901 |
$$templateVars{'section'} = "Deletion Status";
|
|
2902 |
$template->process( $responseTemplate, $templateVars);
|
|
2920 |
processResultTemplate('revise', 'success', $errorMessage); |
|
2921 |
} else {
|
|
2922 |
processResultTemplate('revise', 'failure', $errorMessage);
|
|
2923 |
}
|
|
2903 | 2924 |
} |
2904 | 2925 |
|
2905 | 2926 |
|
... | ... | |
2927 | 2948 |
|
2928 | 2949 |
$$templateVars{'recipient_status'} = 'moderator'; |
2929 | 2950 |
sendNotification($mailhost, $sender, $recipient, $subject, |
2930 |
$modNotificationTemplate, $templateVars); |
|
2951 |
$modEmailNotificationTemplate, $templateVars);
|
|
2931 | 2952 |
if($contactEmailAddress ne ''){ |
2932 | 2953 |
# send notification to contact email address specified in cfg |
2933 | 2954 |
$$templateVars{'recipient'} = $contactEmailAddress; |
2934 | 2955 |
$$templateVars{'recipient_status'} = 'user'; |
2935 | 2956 |
sendNotification($mailhost, $sender, $contactEmailAddress, |
2936 |
$subject, $modNotificationTemplate, $templateVars); |
|
2957 |
$subject, $modEmailNotificationTemplate, $templateVars);
|
|
2937 | 2958 |
} |
2938 | 2959 |
} |
2939 | 2960 |
|
... | ... | |
2946 | 2967 |
my $mailhost = shift; |
2947 | 2968 |
my $sender = shift; |
2948 | 2969 |
my $recipient = shift; |
2949 |
my $subject = shift;
|
|
2970 |
my $subject = shift;
|
|
2950 | 2971 |
my $templateForm = shift; |
2951 | 2972 |
my $templateVars = shift; |
2952 | 2973 |
|
2953 |
debug($mailhost); |
|
2954 |
debug($sender); |
|
2955 |
debug($recipient); |
|
2956 |
debug($subject); |
|
2957 |
|
|
2958 | 2974 |
my $smtp = Net::SMTP->new($mailhost); |
2959 | 2975 |
$smtp->mail($sender); |
2960 | 2976 |
$smtp->to($recipient); |
2961 | 2977 |
|
2962 |
$smtp->data;
|
|
2963 |
$smtp->datasend("From: $sender\n");
|
|
2964 |
$smtp->datasend("To: <$recipient>\n");
|
|
2965 |
$smtp->datasend("Subject: $subject\n");
|
|
2966 |
$smtp->datasend("\n");
|
|
2978 |
$smtp->data;
|
|
2979 |
$smtp->datasend("From: $sender\n");
|
|
2980 |
$smtp->datasend("To: <$recipient>\n");
|
|
2981 |
$smtp->datasend("Subject: $subject\n");
|
|
2982 |
$smtp->datasend("\n");
|
|
2967 | 2983 |
|
2968 | 2984 |
my $message; |
2969 |
$template->process($templateForm, $templateVars,\$message);
|
|
2985 |
$template->process($templateForm, $templateVars,\$message);
|
|
2970 | 2986 |
|
2971 | 2987 |
$smtp->datasend($message); |
2972 |
$smtp->dataend();
|
|
2988 |
$smtp->dataend();
|
|
2973 | 2989 |
$smtp->quit; |
2974 | 2990 |
} |
2975 | 2991 |
|
2976 |
sub processErrorTemplate(){ |
|
2977 |
my $status = shift; |
|
2978 |
my $function = shift; |
|
2979 |
my $section = shift; |
|
2980 |
|
|
2981 |
$$templateVars{'status'} = $status; |
|
2982 |
$$templateVars{'function'} = $function; |
|
2983 |
$$templateVars{'errorMessages'} = \@errorMessages; |
|
2984 |
$$templateVars{'cfg'} = $FORM::cfg; |
|
2985 |
$$templateVars{'section'} = $section; |
|
2986 |
$template->process( $responseTemplate, $templateVars); |
|
2992 |
################################################################################ |
|
2993 |
# |
|
2994 |
# sends back the result to the use |
|
2995 |
# |
|
2996 |
################################################################################ |
|
2997 |
sub processResultTemplate(){ |
|
2998 |
my $stage = shift; |
|
2999 |
my $result = shift; |
|
3000 |
my $message = shift; |
|
3001 |
|
|
3002 |
if($result eq 'success'){ |
|
3003 |
if($stage eq 'accept'){ |
|
3004 |
$message = "Dataset (docid:".$FORM::docid.") accepted "; |
|
3005 |
} elsif($stage eq 'decline'){ |
|
3006 |
$message = "Dataset (docid:".$FORM::docid.") declined "; |
|
3007 |
} else { |
|
3008 |
$message = "Revision requested for dataset (docid:".$FORM::docid.") "; |
|
3009 |
} |
|
3010 |
} else { |
|
3011 |
if($stage eq 'accept'){ |
|
3012 |
$message = "Failure in accepting docid: ".$FORM::docid." (".$message.")"; |
|
3013 |
} elsif($stage eq 'decline'){ |
|
3014 |
$message = "Failure in declining docid: ".$FORM::docid." (".$message.")"; |
|
3015 |
} else { |
|
3016 |
$message = "Failure in requesting revision of docid: ".$FORM::docid." (".$message.")"; |
|
3017 |
} |
|
3018 |
} |
|
3019 |
$$templateVars{'message'} = $message; |
|
3020 |
$template->process($modResultTemplate, $templateVars); |
|
2987 | 3021 |
} |
2988 | 3022 |
|
2989 | 3023 |
|
... | ... | |
3154 | 3188 |
if (hasContent($taxonRankArray->[$i]) && hasContent($taxonNameArray->[$i])) { |
3155 | 3189 |
debug("Registry processing keyword: trv = ".$taxonRankArray->[$i] |
3156 | 3190 |
." trn = ".$taxonNameArray->[$i]); |
3157 |
$$templateVars{"taxonRankName".$taxonCount} = normalizeCD($taxonNameArray->[$i]);
|
|
3158 |
$$templateVars{"taxonRankValue".$taxonCount} = normalizeCD($taxonRankArray->[$i]);
|
|
3191 |
$$templateVars{"taxonRankName".$taxonCount} = normalizeCD($taxonRankArray->[$i]);
|
|
3192 |
$$templateVars{"taxonRankValue".$taxonCount} = normalizeCD($taxonNameArray->[$i]);
|
|
3159 | 3193 |
$taxonCount++; |
3160 | 3194 |
} |
3161 | 3195 |
} |
Also available in: Unified diff
Following changes:
1. Fixed a bug in checking of contact email address field
2. Added functions to display the result of accept, reject and revise actions
3. Added variable to control if the document creator should be the skin admin
4. a common function to check if the present user is a moderator