--- /dev/null
+package ShareStuff::UI;
+use strict;
+use warnings;
+
+use Apache::Constants qw( :common );
+use Template qw( :template );
+use CGI;
+use OpenSRF::EX qw(:try);
+use OpenSRF::System;
+use OpenILS::Utils::CStoreEditor;
+
+
+# set the bootstrap config and template include directory when
+# this module is loaded
+my $bootstrap;
+my $ssl_off;
+
+sub import {
+ my $self = shift;
+ $bootstrap = shift;
+ $ssl_off = shift;
+}
+
+
+sub child_init {
+ OpenSRF::System->bootstrap_client( config_file => $bootstrap );
+ OpenILS::Utils::CStoreEditor::init();
+ return OK;
+}
+
+# we epxect a PerlSetVar of ss_templates pointing to the location of the TT files
+sub handler {
+ my %env = ();
+
+ $env{r} = shift;
+ $env{cgi} = new CGI;
+
+ $env{authtoken} = $cgi->cookie('ses') || $cgi->param('ses');
+ $env{user} = verify_login($env{authtoken});
+ $env{cstore} = new OpenILS::Utils::CStoreEditor;
+
+
+ $env{file} = $env{r}->path_info;
+ $env{file} =~ s[^/][];
+
+ $env{api} = 0;
+ if ($env{file} =~ /^api/) {
+ $env{file} =~ s[^api/][];
+ $env{api} = 1;
+ }
+
+ my $template = Template->new({
+ VARIABLES => \%env,
+ INCLUDE_PATH => $ss_templates,
+ OUTPUT => $env{r}, # direct output to Apache request
+ });
+
+ $evn{r}->content_type('text/html') if (!$env{api});
+ $evn{r}->content_type('text/json') if ($env{api});
+ $evn{r}->send_http_header;
+
+ $template->process($env{file}, $env) || return fail($env{r}, SERVER_ERROR, $template->error());
+
+ return OK;
+}
+
+sub fail {
+ my ($r, $status, $message) = @_;
+ $r->log_reason($message, $r->filename);
+ return $status;
+}
+
+# returns the user object if the session is valid, 0 otherwise
+sub verify_login {
+ my $auth_token = shift;
+ return undef unless $auth_token;
+
+ my $user = OpenSRF::AppSession
+ ->create("sharestuff.auth")
+ ->request( "sharestuff.auth.session.retrieve", $auth_token )
+ ->gather(1);
+
+ if (ref($user) eq 'HASH' && $user->{ilsevent} == 1001) {
+ return undef;
+ }
+
+ return $user if ref($user);
+ return undef;
+}
+
+1;
--- /dev/null
+[%
+
+WRAPPER base;
+
+pkg_id = cgi.param( 'pkg' );
+
+
+IF pkg_id
+ INCLUDE package_details
+ pkg = cstore.retrieve_depository_package( [ cgi.param( 'pkg' ), { flesh = 1, flesh_fields = { dp = ['systems'] } } ] )
+ systems = cstore.retrieve_all_depository_source_system();
+ELSE
+ FOREACH p IN cstore.search_depository_package( [ { author = user.id() }, { flesh = 1, flesh_fields = { dp = ['systems'] } } ] );
+ INCLUDE package_summary pkg = p;
+ %] <hr/> [%
+ END;
+END;
+
+END %]
+
--- /dev/null
+<!-- expects "pkg", "systems" -->
+
+[%
+
+sysnames = [];
+FOREACH s IN systems;
+ sysnames.push(s.name());
+END;
+
+
+%]
+
+<form id="p[% pkg.id() %]_form" method="POST">
+<table style="border-collapse:collaps; border-width:1px">
+ <tr>
+ <th>Title</th>
+ <td><input name="title" type="text" value="[% pkg.title() | html %]"/></td>
+ </tr>
+ <tr>
+ <th>Description</th>
+ <td><textarea name="description">[% pkg.description() | html %]</textarea></td>
+ </tr>
+ <tr>
+ <th>Version</th>
+ <td><input name="pkg_version" type="text" value="[% pkg.pkg_version() | html %]"/></td>
+ </tr>
+ <tr>
+ <th>Created</th>
+ <td><input name="created" type="text" value="[% pkg.created() | html %]"/></td>
+ </tr>
+ <tr>
+ <th>Systems</th>
+ <td>
+ [% FOREACH s IN sysnames.sort %]
+ <input
+ name="systems"
+ type="checkbox"
+ value="[% s.name() | html %]"
+ [% 'checked="checked"' IF pgk.systems().grep(s) %]
+ />[% s.name() | html %]>
+ <br/>
+ [% END %]
+ </td>
+ </tr>
+</table>
+<a href="javascript:document.forms['p[% pkg.id() %]_form'].submit()">Save</a><br/>
+<a href="javascript:history.back()">Back</a>
+</form>
+
+[% END %]
+
--- /dev/null
+<!-- expects "pkg" -->
+
+[%
+
+sysnames = [];
+FOREACH s IN pkg.systems();
+ sysnames.push(s.name());
+END;
+
+
+%]
+
+<table style="border-collapse:collaps; border-width:1px; width: 90%">
+ <tr>
+ <th>Title</th>
+ <td><a href="?pkg=[% pkg.id() %]">[% pkg.title() | html %]</a></td>
+ <th>Version</th>
+ <td>[% pkg.pkg_version() | html %]</td>
+ <th>Created</th>
+ <td>[% pkg.created() | html %]"/></td>
+ <th>Systems</th>
+ </tr>
+ <tr>
+ <th>Description</th>
+ <td colspan="5">[% pkg.description() | html %]</textarea></td>
+ <td>
+ [% FOREACH s IN sysnames.sort %]
+ [% s.name() | html %]<br/>
+ [% END %]
+ </td>
+ </tr>
+</table>
+
+[% END %]
+