Correct checking of omitted ID components.
[irspy-moved-to-github.git] / web / htdocs / details / edit.mc
index 96a2948..917c9f3 100644 (file)
@@ -1,16 +1,15 @@
-%# $Id: edit.mc,v 1.13 2006-11-16 11:53:33 mike Exp $
+%# $Id: edit.mc,v 1.17 2006-11-16 17:27:15 mike Exp $
 <%args>
 $id => undef
 </%args>
 <%perl>
 my $conn = new ZOOM::Connection("localhost:3313/IR-Explain---1", 0,
-                               user => "admin", password => "fruitbat");
+                               user => "admin", password => "fruitbat",
+                               elementSetName => "zeerex");
 my $rec = '<explain xmlns="http://explain.z3950.org/dtd/2.0/"/>';
 if (defined $id && $id ne "") {
-    $conn->option(elementSetName => "zeerex");
-    my $qid = $id;
-    $qid =~ s/"/\\"/g;
-    my $query = qq[rec.id="$qid"];
+    # Existing record
+    my $query = 'rec.id="' . cql_quote($id) . '"';
     my $rs = $conn->search(new ZOOM::Query::CQL($query));
     my $n = $rs->size();
     if ($n == 0) {
@@ -18,6 +17,20 @@ if (defined $id && $id ne "") {
     } else {
        $rec = $rs->record(0);
     }
+
+} else {
+    # New record
+    my $host = $r->param("host");
+    my $port = $r->param("port");
+    my $dbname = $r->param("dbname");
+    if (!defined $host || $host eq "" ||
+       !defined $port || $port eq "" ||
+       !defined $dbname || $dbname eq "") {
+       print qq[<p class="error">You must specify host, port and database name.</p>\n];
+       $r->param(update => 0);
+    }
+
+    my $query = cql_target($host, $port, $dbname);
 }
 
 my $xc = irspy_xpath_context($rec);
@@ -59,7 +72,7 @@ my @fields =
 
 my $nchanges = 0;
 my $update = $r->param("update");
-if (defined $update) {
+if ($update) {
     # Update record with submitted data
     my %fieldsByKey = map { ( $_->[0], $_) } @fields;
     my %data;
@@ -102,9 +115,9 @@ foreach my $ref (@fields) {
 %     }
      </select>
 % } elsif ($nlines) {
-     <textarea name="<% $name %>" rows="<% $nlines %>" cols="55"><% $data %></textarea>
+     <textarea name="<% $name %>" rows="<% $nlines %>" cols="51"><% $data %></textarea>
 % } else {
-     <input name="<% $name %>" type="text" size="60" value="<% $data %>">
+     <input name="<% $name %>" type="text" size="60" value="<% $data %>"/>
 % }
     </td>
    </tr>