Merge branch 'master' of ssh://git.indexdata.com:222/home/git/pub/irspy
[irspy-moved-to-github.git] / web / htdocs / details / upload.mc
1 <%args>
2 $filename => undef
3 </%args>
4 % if (!defined $filename) {
5    <p>
6     Please note that this form expects a
7     <a href="http://explain.z3950.org/"
8         >ZeeRex record</a>
9     only, not an entire
10     <a href="http://www.loc.gov/standards/sru/explain/"
11         >SRU explainResponse</a>.
12    <p>
13    <form method="post" action=""
14             enctype="multipart/form-data">
15     <p>
16      ZeeRex file to upload:
17      <input type="file" name="filename" size="50"/>
18      <br/>
19      <input type="submit" name="_submit" value="Submit"/>
20     </p>
21    </form>
22 % return;
23 % }
24 <%perl>
25
26 my $fin;
27
28 # Apache2.0 
29 if ($r->isa('Apache2::RequestRec')) {
30     require Apache2::Request;
31     require Apache2::Upload;
32     my $req = new Apache2::Request($r);
33     my $upload = $req->upload('filename');
34     $fin = $upload->fh();
35
36
37 # Apache 1.3
38 else {
39     $fin = $r->upload()->fh();
40 }
41
42 if (!defined $fin) {
43     $m->comp("/details/error.mc", msg => "Upload cancelled");
44     return;
45 }
46
47 my $xml = join("", <$fin>);
48 my $xc = irspy_xpath_context($xml);
49 my $id = irspy_record2identifier($xc);
50 my $db = ZOOM::IRSpy::connect_to_registry();
51 my $conn = new ZOOM::Connection($db, 0,
52                                 user => "admin", password => "fruitbat",
53                                 elementSetName => "zeerex");
54 ZOOM::IRSpy::_rewrite_zeerex_record($conn, $xc->getContextNode());
55 </%perl>
56      <p>
57       Upload OK.
58      </p>
59      <p>
60       Proceed to
61       <a href="<% xml_encode("/full.html?id=" . uri_escape_utf8($id))
62         %>">the new record</a>.
63      </p>