oops forgot these from working on the road
authorivan <ivan>
Fri, 5 Apr 2002 16:37:42 +0000 (16:37 +0000)
committerivan <ivan>
Fri, 5 Apr 2002 16:37:42 +0000 (16:37 +0000)
FS/t/part_export-infostreet.t [new file with mode: 0644]
FS/t/part_export-sqlradius.t [new file with mode: 0644]
eg/export_template.pm [new file with mode: 0644]
httemplate/search/sql.cgi [new file with mode: 0755]

diff --git a/FS/t/part_export-infostreet.t b/FS/t/part_export-infostreet.t
new file mode 100644 (file)
index 0000000..1b33418
--- /dev/null
@@ -0,0 +1,5 @@
+BEGIN { $| = 1; print "1..1\n" }
+END {print "not ok 1\n" unless $loaded;}
+use FS::part_export::infostreet;
+$loaded=1;
+print "ok 1\n";
diff --git a/FS/t/part_export-sqlradius.t b/FS/t/part_export-sqlradius.t
new file mode 100644 (file)
index 0000000..5fb23a5
--- /dev/null
@@ -0,0 +1,5 @@
+BEGIN { $| = 1; print "1..1\n" }
+END {print "not ok 1\n" unless $loaded;}
+use FS::part_export::sqlradius;
+$loaded=1;
+print "ok 1\n";
diff --git a/eg/export_template.pm b/eg/export_template.pm
new file mode 100644 (file)
index 0000000..11e1c3b
--- /dev/null
@@ -0,0 +1,47 @@
+package FS::part_export::myexport;
+
+use vars qw(@ISA);
+use FS::part_export;
+
+@ISA = qw(FS::part_export);
+
+sub rebless { shift; }
+
+sub _export_insert {
+  my($self, $svc_something) = (shift, shift);
+  $self->myexport_queue( $svc_acct->svcnum, 'insert',
+    $svc_something->username, $svc_something->password );
+}
+
+sub _export_replace {
+  my( $self, $new, $old ) = (shift, shift, shift);
+  #return "can't change username with myexport"
+  #  if $old->username ne $new->username;
+  #return '' unless $old->_password ne $new->_password;
+  $self->myexport_queue( $new->svcnum,
+    'replace', $new->username, $new->password );
+}
+
+sub _export_delete {
+  my( $self, $svc_something ) = (shift, shift);
+  $self->myexport_queue( $svc_acct->svcnum,
+    'delete', $svc_something->username );
+}
+
+#a good idea to queue anything that could fail or take any time
+sub myexport_queue {
+  my( $self, $svcnum, $method ) = (shift, shift, shift);
+  my $queue = new FS::queue {
+    'svcnum' => $svcnum,
+    'job'    => "FS::part_export::myexport::myexport_$method",
+  };
+  $queue->insert( @_ );
+}
+
+sub myexport_insert { #subroutine, not method
+}
+sub myexport_replace { #subroutine, not method
+}
+sub myexport_delete { #subroutine, not method
+}
+
diff --git a/httemplate/search/sql.cgi b/httemplate/search/sql.cgi
new file mode 100755 (executable)
index 0000000..b83ef03
--- /dev/null
@@ -0,0 +1,76 @@
+<%
+
+my $conf = new FS::Conf;
+my $maxrecords = $conf->config('maxsearchrecordsperpage');
+
+my $limit = '';
+$limit .= "LIMIT $maxrecords" if $maxrecords;
+
+my $offset = $cgi->param('offset') || 0;
+$limit .= " OFFSET $offset" if $offset;
+
+my $total;
+
+my $sql = $cgi->param('sql');
+$sql =~ s/^\s*SELECT//i;
+
+my $count_sql = $sql;
+$count_sql =~ s/^(.*)\s+FROM\s/COUNT(*) FROM /i;
+
+my $sth = dbh->prepare("SELECT $count_sql")
+  or eidiot dbh->errstr. " doing $count_sql\n";
+$sth->execute or eidiot "Error executing \"$count_sql\": ". $sth->errstr;
+
+$total = $sth->fetchrow_arrayref->[0];
+
+my $sth = dbh->prepare("SELECT $sql $limit")
+  or eidiot dbh->errstr. " doing $sql\n";
+$sth->execute or eidiot "Error executing \"$sql\": ". $sth->errstr;
+my $rows = $sth->fetchall_arrayref;
+
+%>
+<!-- mason kludge -->
+<%
+
+  #begin pager
+  my $pager = '';
+  if ( $total != scalar(@$rows) && $maxrecords ) {
+    unless ( $offset == 0 ) {
+      $cgi->param('offset', $offset - $maxrecords);
+      $pager .= '<A HREF="'. $cgi->self_url.
+                '"><B><FONT SIZE="+1">Previous</FONT></B></A> ';
+    }
+    my $poff;
+    my $page;
+    for ( $poff = 0; $poff < $total; $poff += $maxrecords ) {
+      $page++;
+      if ( $offset == $poff ) {
+        $pager .= qq!<FONT SIZE="+2">$page</FONT> !;
+      } else {
+        $cgi->param('offset', $poff);
+        $pager .= qq!<A HREF="!. $cgi->self_url. qq!">$page</A> !;
+      }
+    }
+    unless ( $offset + $maxrecords > $total ) {
+      $cgi->param('offset', $offset + $maxrecords);
+      $pager .= '<A HREF="'. $cgi->self_url.
+                '"><B><FONT SIZE="+1">Next</FONT></B></A> ';
+    }
+  }
+  #end pager
+
+  print header('Query Results', menubar('Main Menu'=>$p) ).
+        "$total total rows<BR><BR>$pager". table().
+        "<TR>";
+  print "<TH>$_</TH>" foreach @{$sth->{NAME}};
+  print "</TR>";
+
+  foreach $row ( @$rows ) {
+    print "<TR>";
+    print "<TD>$_</TD>" foreach @$row;
+    print "</TR>";
+  }
+
+  print "</TABLE>$pager</BODY></HTML>";
+
+%>