BugFixing : viewlog.pl was broken (comma missing)
[koha_fer] / C4 / Auth.pm
old mode 100644 (file)
new mode 100755 (executable)
index 2d95edb..6d792ea
@@ -260,8 +260,7 @@ sub get_template_and_user {
         );
     }
     else {
-        warn "template type should be OPAC, here it is=[" . $in->{'type'} . "]"
-          unless ( $in->{'type'} eq 'opac' );
+               warn "template type should be OPAC, here it is=[" . $in->{'type'} . "]" unless ( $in->{'type'} eq 'opac' );
         my $LibraryNameTitle = C4::Context->preference("LibraryName");
         $LibraryNameTitle =~ s/<(?:\/?)(?:br|p)\s*(?:\/?)>/ /sgi;
         $LibraryNameTitle =~ s/<(?:[^<>'"]|'(?:[^']*)'|"(?:[^"]*)")*>//sg;
@@ -375,6 +374,22 @@ sub checkauth {
     my $timeout = C4::Context->preference('timeout');
     $timeout = 600 unless $timeout;
 
+
+    # If Version syspref is unavailable, it means Koha is beeing installed,
+    # and so we must redirect to OPAC maintenance page or to the WebInstaller
+    unless (C4::Context->preference('Version')) {
+      if ($type ne 'opac') {
+        warn "Install required, redirecting to Installer";
+        print $query->redirect("/cgi-bin/koha/installer/install.pl");
+      } 
+      else {
+        warn "OPAC Install required, redirecting to maintenance";
+        print $query->redirect("/cgi-bin/koha/maintenance.pl");
+      }
+      exit;
+    }
+
+
     # state variables
     my $loggedin = 0;
     my %info;
@@ -390,8 +405,15 @@ sub checkauth {
         $loggedin = 1;
     }
     elsif ( $sessionID = $query->cookie("CGISESSID")) {
-#         my $session = new CGI::Session("driver:MySQL", $sessionID, {Handle=>$dbh});
-        my $session = new CGI::Session("driver:File", $sessionID, {Directory=>'/tmp'});
+               my $storage_method = C4::Context->preference('SessionStorage');
+               my $session;
+               if ($storage_method eq 'mysql'){
+                   $session = new CGI::Session("driver:MySQL", $sessionID, {Handle=>$dbh});
+               }
+               else {
+                       # catch all defaults to tmp should work on all systems
+                       $session = new CGI::Session("driver:File", $sessionID, {Directory=>'/tmp'});                    
+               }
         C4::Context->_new_userenv($sessionID);
         if ($session){
             C4::Context::set_userenv(
@@ -401,8 +423,8 @@ sub checkauth {
                 $session->param('branchname'),   $session->param('flags'),
                 $session->param('emailaddress'), $session->param('branchprinter')
             );
-            warn       "".$session->param('cardnumber').",   ".$session->param('firstname').",
-                ".$session->param('surname').",      ".$session->param('branch');
+            warn       "".$session->param('cardnumber').",   ".$session->param('firstname').",
+                ".$session->param('surname').",      ".$session->param('branch');
         }
         my $ip;
         my $lasttime;
@@ -416,8 +438,9 @@ sub checkauth {
         if ($logout) {
 
             # voluntary logout the user
-#             $session->delete;
+
             $session->flush;      
+                       $session->delete();
             C4::Context->_unset_userenv($sessionID);
             $sessionID = undef;
             $userid    = undef;
@@ -471,12 +494,20 @@ sub checkauth {
         }
     }
     unless ($userid) {
-#         my $session = new CGI::Session("driver:MySQL", undef, {Handle=>$dbh});    
-        my $session = new CGI::Session("driver:File", undef, {Directory=>'/tmp'});    
+               my $storage_method = C4::Context->preference('SessionStorage');
+               my $session;
+               if ($storage_method eq 'mysql'){
+                   $session = new CGI::Session("driver:MySQL", $sessionID, {Handle=>$dbh});
+               }
+               else {
+                       # catch all defaults to tmp should work on all systems
+                       $session = new CGI::Session("driver:File", $sessionID, {Directory=>'/tmp'});                    
+               }
+
         my $sessionID;
-    if ($session) {
-      $sessionID = $session->id;
-      }
+               if ($session) {
+                       $sessionID = $session->id;
+               }
         $userid    = $query->param('userid');
         C4::Context->_new_userenv($sessionID);
         my $password = $query->param('password');
@@ -645,17 +676,6 @@ sub checkauth {
     # check that database and koha version are the same
     # there is no DB version, it's a fresh install,
     # go to web installer
-  warn "about to check version";
-    unless (C4::Context->preference('Version')){
-      if ($type ne 'opac'){
-        warn "Install required, redirecting to Installer";
-        print $query->redirect("/cgi-bin/koha/installer/install.pl");
-      } else {
-        warn "OPAC Install required, redirecting to maintenance";
-        print $query->redirect("/cgi-bin/koha/maintenance.pl");
-      }       
-      exit;
-    }
     # there is a DB version, compare it to the code version
     my $kohaversion=C4::Context::KOHAVERSION;
     # remove the 3 last . to have a Perl number