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