Merge branch 'master' of /home/jmf/repos/koha-rm-root.git/
authorChris Cormack <crc@liblime.com>
Tue, 7 Aug 2007 20:43:42 +0000 (15:43 -0500)
committerChris Cormack <crc@liblime.com>
Tue, 7 Aug 2007 20:43:42 +0000 (15:43 -0500)
C4/Auth.pm
C4/Branch.pm
koha-tmpl/intranet-tmpl/prog/en/auth.tmpl

index da70939..3ffbb3e 100644 (file)
@@ -114,6 +114,7 @@ C4::Auth - Authenticates Koha users
 
 sub get_template_and_user {
     my $in       = shift;
+       warn "GET Template";
     my $template =
       gettemplate( $in->{'template_name'}, $in->{'type'}, $in->{'query'} );
     my ( $user, $cookie, $sessionID, $flags ) = checkauth(
@@ -216,8 +217,7 @@ sub get_template_and_user {
     }
     if ( $in->{'type'} eq "intranet" ) {
         $template->param(
-            intranetcolorstylesheet =>
-              C4::Context->preference("intranetcolorstylesheet"),
+            intranetcolorstylesheet => C4::Context->preference("intranetcolorstylesheet"),
             intranetstylesheet => C4::Context->preference("intranetstylesheet"),
             IntranetNav        => C4::Context->preference("IntranetNav"),
             intranetuserjs     => C4::Context->preference("intranetuserjs"),
@@ -383,7 +383,7 @@ sub checkauth {
     # state variables
     my $loggedin = 0;
     my %info;
-    my ( $userid, $cookie, $sessionID, $flags, $envcookie );
+    my ( $userid, $cookie, $sessionID, $flags );
     my $logout = $query->param('logout.x');
     if ( $userid = $ENV{'REMOTE_USER'} ) {
 
@@ -545,10 +545,14 @@ sub checkauth {
 #  new op dev :
 # launch a sequence to check if we have a ip for the branch, if we have one we replace the branchcode of the userenv by the branch bound in the ip.
                 my $ip       = $ENV{'REMOTE_ADDR'};
+                               # if they specify at login, use that
+                               if ($query->param('branch')) {
+                               $branchcode  = $query->param('branch');
+                               $branchname = GetBranchName($branchcode);
+                               }
                 my $branches = GetBranches();
                 my @branchesloop;
                 foreach my $br ( keys %$branches ) {
-
                     #          now we work with the treatment of ip
                     my $domain = $branches->{$br}->{'branchip'};
                     if ( $domain && $ip =~ /^$domain/ ) {
@@ -587,7 +591,17 @@ sub checkauth {
                 $session->param('ip',$session->remote_addr());
                                $session->param('lasttime',time());
                        }
+                       if ($session){
+               C4::Context::set_userenv(
+                $session->param('number'),       $session->param('id'),
+                $session->param('cardnumber'),   $session->param('firstname'),
+                $session->param('surname'),      $session->param('branch'),
+                $session->param('branchname'),   $session->param('flags'),
+                $session->param('emailaddress'), $session->param('branchprinter')
+               );
+               }               
         }
+
         else {
             if ($userid) {
                 $info{'invalid_username_or_password'} = 1;
@@ -617,8 +631,16 @@ sub checkauth {
         my $value = $query->param($name);
         push @inputs, { name => $name, value => $value };
     }
+    # get the branchloop, which we need for authetication
+       use C4::Branch;
+    my $branches = GetBranches();
+    my @branch_loop;
+    for my $branch_hash (keys %$branches) {
+                push @branch_loop, {branchcode => "$branch_hash", branchname => $branches->{$branch_hash}->{'branchname'}, };
+    }
 
     my $template = gettemplate( $template_name, $type, $query );
+    $template->param(branchloop => \@branch_loop,);
     $template->param(
         INPUTS               => \@inputs,
         suggestion           => C4::Context->preference("suggestion"),
index 4a540be..79d4d54 100644 (file)
@@ -91,8 +91,7 @@ foreach my $thisbranch (keys %$branches) {
 =cut
 
 sub GetBranches {
-
-    my $onlymine=@_;
+    my ($onlymine)=@_;
     # returns a reference to a hash of references to ALL branches...
     my %branches;
     my $dbh = C4::Context->dbh;
index b91d737..69c6c4b 100644 (file)
 <p>
 <label>Password:<br />
 <input type="password" name="password" id="password" class="input" value="" size="20" tabindex="20" /></label>
-</p>    
+</p> 
+<p>
+<label for="branch">Library:</label>
+<select name="branch" id="branch" class="input">
+<!-- TMPL_LOOP NAME="branchloop" -->
+<option value="<!-- TMPL_VAR NAME='branchcode' -->"><!-- TMPL_VAR NAME='branchname' --></option>
+<!-- /TMPL_LOOP -->
+</select>
+</p>
 <p class="submit"><input type="submit" value="Login &raquo;" /></p>
 </form>
-
 <!-- /TMPL_IF -->
 
 <script type="text/javascript">