LP1207396 Patron self-registration web form
authorBill Erickson <berick@esilibrary.com>
Tue, 6 Aug 2013 18:31:41 +0000 (14:31 -0400)
committerBill Erickson <berick@esilibrary.com>
Tue, 6 Aug 2013 18:31:41 +0000 (14:31 -0400)
Signed-off-by: Bill Erickson <berick@esilibrary.com>
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGCatLoader/Register.pm
Open-ILS/src/templates/opac/register.tt2

index 613cca8..1b359a6 100644 (file)
@@ -16,6 +16,7 @@ sub load_patron_reg {
     my $cgi = $self->cgi;
     $ctx->{register} = {};
     $self->collect_register_validation_settings;
+    $self->collect_requestor_info;
 
     # in the home org unit selector, we only want to present 
     # org units to the patron which support self-registration.
@@ -88,6 +89,32 @@ sub load_patron_reg {
     return Apache2::Const::OK;
 }
 
+# if the pending account is requested by an existing user account,
+# load the existing user's data to pre-populate some fields.
+sub collect_requestor_info {
+    my $self = shift;
+    return unless $self->ctx->{user};
+
+    my $user = $self->editor->retrieve_actor_user([
+        $self->ctx->{user}->id,
+        {flesh => 1, flesh_fields => {
+            au => [qw/mailing_address billing_address/]}
+        }
+    ]);
+
+
+    my $vhash = $self->ctx->{register}{values} = {};
+    my $addr = $user->mailing_address || $user->billing_address;
+    $vhash->{stgu}{home_ou} = $user->home_ou;
+
+    if ($addr) {
+        $vhash->{stgma}{city} = $addr->city;
+        $vhash->{stgma}{county} = $addr->county;
+        $vhash->{stgma}{state} = $addr->state;
+        $vhash->{stgma}{post_code} = $addr->post_code;
+    }
+}
+
 # if the username is in use by an actor.usr OR a 
 # pending user treat it as taken and warn the user.
 sub test_requested_username {
index b565bb4..518420c 100644 (file)
@@ -92,7 +92,7 @@ register_fields = [
                     </td>
                     <td>[% INCLUDE build_org_selector 
                             name='stgu.home_ou' 
-                            value=ctx_org
+                            value=value || ctx_org
                             can_have_users_only=1
                             valid_org_list=ctx.register.valid_orgs
                         %]
@@ -116,6 +116,7 @@ FOR field_def IN register_fields;
     show = ctx.register.settings.$fclass.$fname.show;
     require = ctx.register.settings.$fclass.$fname.require;
     example = ctx.register.settings.$fclass.$fname.example;
+    value = ctx.register.values.$fclass.$fname;
 
     invalid_require = ctx.register.invalid.$fclass.$fname.require;
     invalid_regex = ctx.register.invalid.$fclass.$fname.regex;
@@ -130,7 +131,7 @@ FOR field_def IN register_fields;
         <input 
             type='text' 
             name='[% field_path %]'
-            value='[% CGI.param(field_path) | html %]'/>
+            value='[% value || CGI.param(field_path) | html %]'/>
         [% IF require %]
         <span class='patron-reg-invalid'>*</span>
         [% END %]
@@ -159,11 +160,9 @@ FOR field_def IN register_fields;
 [% END %]
 <!-- ====> shifting the code back to the right for context -->
                     <tr>
-                        <td>
+                        <td colspan='3'>
                             <a href="[% ctx.opac_root %]/home" 
                                 class="opac-button">[% l('Go Back') %]</a>
-                        </td>
-                        <td>
                             <input type="submit" 
                                 value="[% l('Submit Registration') %]" 
                                 class="opac-button" />