]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-18644 Bugs found by syntax checker, merged from MOODLE_19_STABLE
authormudrd8mz <mudrd8mz>
Mon, 23 Mar 2009 09:53:02 +0000 (09:53 +0000)
committermudrd8mz <mudrd8mz>
Mon, 23 Mar 2009 09:53:02 +0000 (09:53 +0000)
auth/cas/CAS/client.php
lib/adodb/perf/perf-mysql.inc.php
lib/magpie/rss_parse.inc
login/index.php
mod/lesson/reformat.php
mod/resource/type/file/resource.class.php
mod/resource/type/ims/deploy.php
mod/resource/type/ims/repository_deploy.php
mod/resource/type/repository/resource.class.php
mod/scorm/datamodels/sequencinglib.php

index a793e127800b29eab9825a150426cd1a0e524181..ca846daa68b942a3aa620b68d93a9cafdcdfc08e 100644 (file)
@@ -79,12 +79,12 @@ class CASClient
   function printHTMLHeader($title)
     {
       $this->HTMLFilterOutput(str_replace('__TITLE__',
-                                         $title,
-                                         (empty($this->_output_header)
-                                          ? '<html><head><title>__TITLE__</title></head><body><h1>__TITLE__</h1>'
-                                          : $this->_output_header)
-                                         )
-                             );
+                      $title,
+                      (empty($this->_output_header)
+                       ? '<html><head><title>__TITLE__</title></head><body><h1>__TITLE__</h1>'
+                       : $this->_output_header)
+                      )
+                  );
     }
 
   /**
@@ -107,8 +107,8 @@ class CASClient
   function printHTMLFooter()
     {
       $this->HTMLFilterOutput(empty($this->_output_footer)
-                             ?('<hr><address>phpCAS __PHPCAS_VERSION__ '.$this->getString(CAS_STR_USING_SERVER).' <a href="__SERVER_BASE_URL__">__SERVER_BASE_URL__</a> (CAS __CAS_VERSION__)</a></address></body></html>')
-                             :$this->_output_footer);
+                  ?('<hr><address>phpCAS __PHPCAS_VERSION__ '.$this->getString(CAS_STR_USING_SERVER).' <a href="__SERVER_BASE_URL__">__SERVER_BASE_URL__</a> (CAS __CAS_VERSION__)</a></address></body></html>')
+                  :$this->_output_footer);
     }
 
   /**
@@ -165,7 +165,7 @@ class CASClient
   function getLang()
     {
       if ( empty($this->_lang) )
-       $this->setLang(PHPCAS_LANG_DEFAULT);
+    $this->setLang(PHPCAS_LANG_DEFAULT);
       return $this->_lang;
     }
 
@@ -195,7 +195,7 @@ class CASClient
       $this->getLang();
       
       if ( !isset($this->_strings[$str]) ) {
-       trigger_error('string `'.$str.'\' not defined for language `'.$this->getLang().'\'',E_USER_ERROR);
+    trigger_error('string `'.$str.'\' not defined for language `'.$this->getLang().'\'',E_USER_ERROR);
       }
       return $this->_strings[$str];
     }
@@ -215,7 +215,7 @@ class CASClient
       include_once(dirname(__FILE__).'/languages/'.$lang.'.php');
 
       if ( !is_array($this->_strings) ) {
-       trigger_error('language `'.$lang.'\' is not implemented',E_USER_ERROR);
+    trigger_error('language `'.$lang.'\' is not implemented',E_USER_ERROR);
       }
       $this->_lang = $lang;
     }
@@ -254,11 +254,11 @@ class CASClient
    * @private
    */
   var $_server = array(
-                      'version' => -1,
-                      'hostname' => 'none',
-                      'port' => -1,
-                      'uri' => 'none'
-                      );
+               'version' => -1,
+               'hostname' => 'none',
+               'port' => -1,
+               'uri' => 'none'
+               );
   
   /**
    * This method is used to retrieve the version of the CAS server.
@@ -303,11 +303,11 @@ class CASClient
     { 
       // the URL is build only when needed
       if ( empty($this->_server['base_url']) ) {
-       $this->_server['base_url'] = 'https://'
-         .$this->getServerHostname()
-         .':'
-         .$this->getServerPort()
-         .$this->getServerURI();
+    $this->_server['base_url'] = 'https://'
+      .$this->getServerHostname()
+      .':'
+      .$this->getServerPort()
+      .$this->getServerURI();
       }
       return $this->_server['base_url']; 
     }
@@ -355,14 +355,14 @@ class CASClient
     { 
       // the URL is build only when needed
       if ( empty($this->_server['service_validate_url']) ) {
-       switch ($this->getServerVersion()) {
-       case CAS_VERSION_1_0:
-         $this->_server['service_validate_url'] = $this->getServerBaseURL().'validate';
-         break;
-       case CAS_VERSION_2_0:
-         $this->_server['service_validate_url'] = $this->getServerBaseURL().'serviceValidate';
-         break;
-       }
+    switch ($this->getServerVersion()) {
+    case CAS_VERSION_1_0:
+      $this->_server['service_validate_url'] = $this->getServerBaseURL().'validate';
+      break;
+    case CAS_VERSION_2_0:
+      $this->_server['service_validate_url'] = $this->getServerBaseURL().'serviceValidate';
+      break;
+    }
       }
 //      return $this->_server['service_validate_url'].'?service='.preg_replace('/&/','%26',$this->getURL()); 
       return $this->_server['service_validate_url'].'?service='.urlencode($this->getURL()); 
@@ -377,14 +377,14 @@ class CASClient
     { 
       // the URL is build only when needed
       if ( empty($this->_server['proxy_validate_url']) ) {
-       switch ($this->getServerVersion()) {
-       case CAS_VERSION_1_0:
-         $this->_server['proxy_validate_url'] = '';
-         break;
-       case CAS_VERSION_2_0:
-         $this->_server['proxy_validate_url'] = $this->getServerBaseURL().'proxyValidate';
-         break;
-       }
+    switch ($this->getServerVersion()) {
+    case CAS_VERSION_1_0:
+      $this->_server['proxy_validate_url'] = '';
+      break;
+    case CAS_VERSION_2_0:
+      $this->_server['proxy_validate_url'] = $this->getServerBaseURL().'proxyValidate';
+      break;
+    }
       }
 //      return $this->_server['proxy_validate_url'].'?service='.preg_replace('/&/','%26',$this->getURL()); 
       return $this->_server['proxy_validate_url'].'?service='.urlencode($this->getURL()); 
@@ -399,14 +399,14 @@ class CASClient
     { 
       // the URL is build only when needed
       if ( empty($this->_server['proxy_url']) ) {
-       switch ($this->getServerVersion()) {
-       case CAS_VERSION_1_0:
-         $this->_server['proxy_url'] = '';
-         break;
-       case CAS_VERSION_2_0:
-         $this->_server['proxy_url'] = $this->getServerBaseURL().'proxy';
-         break;
-       }
+    switch ($this->getServerVersion()) {
+    case CAS_VERSION_1_0:
+      $this->_server['proxy_url'] = '';
+      break;
+    case CAS_VERSION_2_0:
+      $this->_server['proxy_url'] = $this->getServerBaseURL().'proxy';
+      break;
+    }
       }
       return $this->_server['proxy_url']; 
     }
@@ -420,7 +420,7 @@ class CASClient
     { 
       // the URL is build only when needed
       if ( empty($this->_server['logout_url']) ) {
-       $this->_server['logout_url'] = $this->getServerBaseURL().'logout';
+    $this->_server['logout_url'] = $this->getServerBaseURL().'logout';
       }
       return $this->_server['logout_url']; 
     }
@@ -469,12 +469,12 @@ class CASClient
     * @public
     */
   function CASClient(
-       $server_version,
-       $proxy,
-       $server_hostname,
-       $server_port,
-       $server_uri,
-       $start_session = true) {
+    $server_version,
+    $proxy,
+    $server_hostname,
+    $server_port,
+    $server_uri,
+    $start_session = true) {
 
     phpCAS::traceBegin();
 
@@ -561,7 +561,7 @@ class CASClient
           } 
           break;
         }
-       }
+    }
     phpCAS::traceEnd();
   }
 
@@ -609,7 +609,7 @@ class CASClient
   function getUser()
     {
       if ( empty($this->_user) ) {
-       phpCAS::error('this method should be used only after '.__CLASS__.'::forceAuthentication() or '.__CLASS__.'::isAuthenticated()');
+    phpCAS::error('this method should be used only after '.__CLASS__.'::forceAuthentication() or '.__CLASS__.'::isAuthenticated()');
       }
       return $this->_user;
     }
@@ -626,15 +626,15 @@ class CASClient
 
       if ( $this->isAuthenticated() ) {
         // the user is authenticated, nothing to be done.
-           phpCAS::trace('no need to authenticate');
-           $res = TRUE;
+        phpCAS::trace('no need to authenticate');
+        $res = TRUE;
 
       } else {
-           // the user is not authenticated, redirect to the CAS server
+        // the user is not authenticated, redirect to the CAS server
         unset($_SESSION['phpCAS']['auth_checked']);
-           $this->redirectToCas(FALSE/* no gateway */);        
-           // never reached
-           $res = FALSE;
+        $this->redirectToCas(FALSE/* no gateway */);    
+        // never reached
+        $res = FALSE;
       }
       phpCAS::traceEnd($res);
       return $res;
@@ -657,7 +657,7 @@ class CASClient
    */
   function setCacheTimesForAuthRequest($n)
     {
-      $this->_cache_times_for_auth_recheck = n;
+      $this->_cache_times_for_auth_recheck = $n;
     }
 
   /**
@@ -670,17 +670,17 @@ class CASClient
       phpCAS::traceBegin();
 
       if ( $this->isAuthenticated() ) {
-           phpCAS::trace('user is authenticated');
-           $res = TRUE;
+        phpCAS::trace('user is authenticated');
+        $res = TRUE;
       } else if (isset($_SESSION['phpCAS']['auth_checked'])) {
         // the previous request has redirected the client to the CAS server with gateway=true
         unset($_SESSION['phpCAS']['auth_checked']);
         $res = FALSE;
       } else {
 //        $_SESSION['phpCAS']['auth_checked'] = true;
-//         $this->redirectToCas(TRUE/* gateway */);    
-//         // never reached
-//         $res = FALSE;
+//      $this->redirectToCas(TRUE/* gateway */);    
+//      // never reached
+//      $res = FALSE;
         // avoid a check against CAS on every request
         if (! isset($_SESSION['phpCAS']['unauth_count']) )
            $_SESSION['phpCAS']['unauth_count'] = -2; // uninitialized
@@ -692,22 +692,22 @@ class CASClient
            
            if ($this->_cache_times_for_auth_recheck != -1)
            {
-                         $_SESSION['phpCAS']['unauth_count']++;
-                 phpCAS::trace('user is not authenticated (cached for '.$_SESSION['phpCAS']['unauth_count'].' times of '.$this->_cache_times_for_auth_recheck.')');
+              $_SESSION['phpCAS']['unauth_count']++;
+              phpCAS::trace('user is not authenticated (cached for '.$_SESSION['phpCAS']['unauth_count'].' times of '.$this->_cache_times_for_auth_recheck.')');
            }
            else
            {
-                 phpCAS::trace('user is not authenticated (cached for until login pressed)');
+              phpCAS::trace('user is not authenticated (cached for until login pressed)');
            }
         }
         else
         {
-               $_SESSION['phpCAS']['unauth_count'] = 0;
+            $_SESSION['phpCAS']['unauth_count'] = 0;
             $_SESSION['phpCAS']['auth_checked'] = true;
             phpCAS::trace('user is not authenticated (cache reset)');
-           $this->redirectToCas(TRUE/* gateway */);    
-           // never reached
-           $res = FALSE;
+            $this->redirectToCas(TRUE/* gateway */);    
+            // never reached
+            $res = FALSE;
         }
       }
       phpCAS::traceEnd($res);
@@ -729,46 +729,46 @@ class CASClient
       $validate_url = '';
 
       if ( $this->wasPreviouslyAuthenticated() ) {
-                // the user has already (previously during the session) been 
-                // authenticated, nothing to be done.
-       phpCAS::trace('user was already authenticated, no need to look for tickets');
-       $res = TRUE;
+         // the user has already (previously during the session) been 
+         // authenticated, nothing to be done.
+        phpCAS::trace('user was already authenticated, no need to look for tickets');
+        $res = TRUE;
       } 
-         elseif ( $this->hasST() ) {
-       // if a Service Ticket was given, validate it
-       phpCAS::trace('ST `'.$this->getST().'\' is present');
-       $this->validateST($validate_url,$text_response,$tree_response); // if it fails, it halts
-       phpCAS::trace('ST `'.$this->getST().'\' was validated');
-       if ( $this->isProxy() ) {
-                  $this->validatePGT($validate_url,$text_response,$tree_response); // idem
-                  phpCAS::trace('PGT `'.$this->getPGT().'\' was validated');
-                  $_SESSION['phpCAS']['pgt'] = $this->getPGT();
-               }
-               $_SESSION['phpCAS']['user'] = $this->getUser();
-               $res = TRUE;
-       }
-       elseif ( $this->hasPT() ) {
-               // if a Proxy Ticket was given, validate it
-               phpCAS::trace('PT `'.$this->getPT().'\' is present');
-               $this->validatePT($validate_url,$text_response,$tree_response); // note: if it fails, it halts
-               phpCAS::trace('PT `'.$this->getPT().'\' was validated');
-
-               if ( $this->isProxy() ) {
-
-                  $this->validatePGT($validate_url,$text_response,$tree_response); // idem
-                  phpCAS::trace('PGT `'.$this->getPGT().'\' was validated');
-                  $_SESSION['phpCAS']['pgt'] = $this->getPGT();
-               }
-       $_SESSION['phpCAS']['user'] = $this->getUser();
-               $res = TRUE;
-       
-       else {
-       // no ticket given, not authenticated
-       phpCAS::trace('no ticket found');
-       }
-
-       phpCAS::traceEnd($res);
-       return $res;
+      elseif ( $this->hasST() ) {
+        // if a Service Ticket was given, validate it
+        phpCAS::trace('ST `'.$this->getST().'\' is present');
+        $this->validateST($validate_url,$text_response,$tree_response); // if it fails, it halts
+        phpCAS::trace('ST `'.$this->getST().'\' was validated');
+        if ( $this->isProxy() ) {
+           $this->validatePGT($validate_url,$text_response,$tree_response); // idem
+           phpCAS::trace('PGT `'.$this->getPGT().'\' was validated');
+           $_SESSION['phpCAS']['pgt'] = $this->getPGT();
+        }
+        $_SESSION['phpCAS']['user'] = $this->getUser();
+        $res = TRUE;
+    }
+    elseif ( $this->hasPT() ) {
+        // if a Proxy Ticket was given, validate it
+        phpCAS::trace('PT `'.$this->getPT().'\' is present');
+        $this->validatePT($validate_url,$text_response,$tree_response); // note: if it fails, it halts
+        phpCAS::trace('PT `'.$this->getPT().'\' was validated');
+
+        if ( $this->isProxy() ) {
+
+           $this->validatePGT($validate_url,$text_response,$tree_response); // idem
+           phpCAS::trace('PGT `'.$this->getPGT().'\' was validated');
+           $_SESSION['phpCAS']['pgt'] = $this->getPGT();
+        }
+        $_SESSION['phpCAS']['user'] = $this->getUser();
+        $res = TRUE;
+    } 
+    else {
+        // no ticket given, not authenticated
+        phpCAS::trace('no ticket found');
+    }
+
+    phpCAS::traceEnd($res);
+    return $res;
   }
   
   /**
@@ -797,46 +797,46 @@ class CASClient
 
       if ( $this->isCallbackMode() ) {
 
-       $this->callback();
+    $this->callback();
       }
 
       $auth = FALSE;
 
       if ( $this->isProxy() ) {
-       // CAS proxy: username and PGT must be present
-       if ( $this->isSessionAuthenticated() && !empty($_SESSION['phpCAS']['pgt']) ) {
-         // authentication already done
-         $this->setUser($_SESSION['phpCAS']['user']);
-         $this->setPGT($_SESSION['phpCAS']['pgt']);
-         phpCAS::trace('user = `'.$_SESSION['phpCAS']['user'].'\', PGT = `'.$_SESSION['phpCAS']['pgt'].'\''); 
-         $auth = TRUE;
-       } elseif ( $this->isSessionAuthenticated() && empty($_SESSION['phpCAS']['pgt']) ) {
-         // these two variables should be empty or not empty at the same time
-         phpCAS::trace('username found (`'.$_SESSION['phpCAS']['user'].'\') but PGT is empty');
-         // unset all tickets to enforce authentication
-         unset($_SESSION['phpCAS']);
-         $this->setST('');
-         $this->setPT('');
-       } elseif ( !$this->isSessionAuthenticated() && !empty($_SESSION['phpCAS']['pgt']) ) {
-         // these two variables should be empty or not empty at the same time
-         phpCAS::trace('PGT found (`'.$_SESSION['phpCAS']['pgt'].'\') but username is empty'); 
-         // unset all tickets to enforce authentication
-         unset($_SESSION['phpCAS']);
-         $this->setST('');
-         $this->setPT('');
-       } else {
-         phpCAS::trace('neither user not PGT found'); 
-       }
+    // CAS proxy: username and PGT must be present
+    if ( $this->isSessionAuthenticated() && !empty($_SESSION['phpCAS']['pgt']) ) {
+      // authentication already done
+      $this->setUser($_SESSION['phpCAS']['user']);
+      $this->setPGT($_SESSION['phpCAS']['pgt']);
+      phpCAS::trace('user = `'.$_SESSION['phpCAS']['user'].'\', PGT = `'.$_SESSION['phpCAS']['pgt'].'\''); 
+      $auth = TRUE;
+    } elseif ( $this->isSessionAuthenticated() && empty($_SESSION['phpCAS']['pgt']) ) {
+      // these two variables should be empty or not empty at the same time
+      phpCAS::trace('username found (`'.$_SESSION['phpCAS']['user'].'\') but PGT is empty');
+      // unset all tickets to enforce authentication
+      unset($_SESSION['phpCAS']);
+      $this->setST('');
+      $this->setPT('');
+    } elseif ( !$this->isSessionAuthenticated() && !empty($_SESSION['phpCAS']['pgt']) ) {
+      // these two variables should be empty or not empty at the same time
+      phpCAS::trace('PGT found (`'.$_SESSION['phpCAS']['pgt'].'\') but username is empty'); 
+      // unset all tickets to enforce authentication
+      unset($_SESSION['phpCAS']);
+      $this->setST('');
+      $this->setPT('');
+    } else {
+      phpCAS::trace('neither user not PGT found'); 
+    }
       } else {
-       // `simple' CAS client (not a proxy): username must be present
-       if ( $this->isSessionAuthenticated() ) {
-         // authentication already done
-         $this->setUser($_SESSION['phpCAS']['user']);
-         phpCAS::trace('user = `'.$_SESSION['phpCAS']['user'].'\''); 
-         $auth = TRUE;
-       } else {
-         phpCAS::trace('no user found');
-       }
+    // `simple' CAS client (not a proxy): username must be present
+    if ( $this->isSessionAuthenticated() ) {
+      // authentication already done
+      $this->setUser($_SESSION['phpCAS']['user']);
+      phpCAS::trace('user = `'.$_SESSION['phpCAS']['user'].'\''); 
+      $auth = TRUE;
+    } else {
+      phpCAS::trace('no user found');
+    }
       }
       
       phpCAS::traceEnd($auth);
@@ -964,102 +964,102 @@ class CASClient
       // build the URL to validate the ticket
       $validate_url = $this->getServerServiceValidateURL().'&ticket='.$this->getST();
       if ( $this->isProxy() ) {
-                // pass the callback url for CAS proxies
-                $validate_url .= '&pgtUrl='.$this->getCallbackURL();
+         // pass the callback url for CAS proxies
+         $validate_url .= '&pgtUrl='.$this->getCallbackURL();
       }
 
       // open and read the URL
       if ( !$this->readURL($validate_url,''/*cookies*/,$headers,$text_response,$err_msg) ) {
-       phpCAS::trace('could not open URL \''.$validate_url.'\' to validate ('.$err_msg.')');
-       $this->authError('ST not validated',
-                        $validate_url,
-                        TRUE/*$no_response*/);
+    phpCAS::trace('could not open URL \''.$validate_url.'\' to validate ('.$err_msg.')');
+    $this->authError('ST not validated',
+             $validate_url,
+             TRUE/*$no_response*/);
       }
 
       // analyze the result depending on the version
       switch ($this->getServerVersion()) {
       case CAS_VERSION_1_0:
-       if (preg_match('/^no\n/',$text_response)) {
-         phpCAS::trace('ST has not been validated');
-         $this->authError('ST not validated',
-                      $validate_url,
-                      FALSE/*$no_response*/,
-                      FALSE/*$bad_response*/,
-                      $text_response);
-       }
-       if (!preg_match('/^yes\n/',$text_response)) {
-         phpCAS::trace('ill-formed response');
-         $this->authError('ST not validated',
-                      $validate_url,
-                      FALSE/*$no_response*/,
-                      TRUE/*$bad_response*/,
-                      $text_response);
-       }
-       // ST has been validated, extract the user name
-       $arr = preg_split('/\n/',$text_response);
-       $this->setUser(trim($arr[1]));
-       break;
+    if (preg_match('/^no\n/',$text_response)) {
+      phpCAS::trace('ST has not been validated');
+      $this->authError('ST not validated',
+               $validate_url,
+               FALSE/*$no_response*/,
+               FALSE/*$bad_response*/,
+               $text_response);
+    }
+    if (!preg_match('/^yes\n/',$text_response)) {
+      phpCAS::trace('ill-formed response');
+      $this->authError('ST not validated',
+               $validate_url,
+               FALSE/*$no_response*/,
+               TRUE/*$bad_response*/,
+               $text_response);
+    }
+    // ST has been validated, extract the user name
+    $arr = preg_split('/\n/',$text_response);
+    $this->setUser(trim($arr[1]));
+    break;
       case CAS_VERSION_2_0:
-       // read the response of the CAS server into a DOM object
-       if ( !($dom = domxml_open_mem($text_response))) {
-         phpCAS::trace('domxml_open_mem() failed');
-         $this->authError('ST not validated',
-                      $validate_url,
-                      FALSE/*$no_response*/,
-                      TRUE/*$bad_response*/,
-                      $text_response);
-       }
-       // read the root node of the XML tree
-       if ( !($tree_response = $dom->document_element()) ) {
-         phpCAS::trace('document_element() failed');
-         $this->authError('ST not validated',
-                      $validate_url,
-                      FALSE/*$no_response*/,
-                      TRUE/*$bad_response*/,
-                      $text_response);
-       }
-       // insure that tag name is 'serviceResponse'
-       if ( $tree_response->node_name() != 'serviceResponse' ) {
-         phpCAS::trace('bad XML root node (should be `serviceResponse\' instead of `'.$tree_response->node_name().'\'');
-         $this->authError('ST not validated',
-                      $validate_url,
-                      FALSE/*$no_response*/,
-                      TRUE/*$bad_response*/,
-                      $text_response);
-       }
-       if ( sizeof($success_elements = $tree_response->get_elements_by_tagname("authenticationSuccess")) != 0) {
-         // authentication succeded, extract the user name
-         if ( sizeof($user_elements = $success_elements[0]->get_elements_by_tagname("user")) == 0) {
-           phpCAS::trace('<authenticationSuccess> found, but no <user>');
-           $this->authError('ST not validated',
-                        $validate_url,
-                        FALSE/*$no_response*/,
-                        TRUE/*$bad_response*/,
-                        $text_response);
-         }
-         $user = trim($user_elements[0]->get_content());
-         phpCAS::trace('user = `'.$user);
-         $this->setUser($user);
-         
-       } else if ( sizeof($failure_elements = $tree_response->get_elements_by_tagname("authenticationFailure")) != 0) {
-         phpCAS::trace('<authenticationFailure> found');
-         // authentication failed, extract the error code and message
-         $this->authError('ST not validated',
-                      $validate_url,
-                      FALSE/*$no_response*/,
-                      FALSE/*$bad_response*/,
-                      $text_response,
-                      $failure_elements[0]->get_attribute('code')/*$err_code*/,
-                      trim($failure_elements[0]->get_content())/*$err_msg*/);
-       } else {
-         phpCAS::trace('neither <authenticationSuccess> nor <authenticationFailure> found');
-         $this->authError('ST not validated',
-                      $validate_url,
-                      FALSE/*$no_response*/,
-                      TRUE/*$bad_response*/,
-                      $text_response);
-       }
-       break;
+    // read the response of the CAS server into a DOM object
+    if ( !($dom = domxml_open_mem($text_response))) {
+      phpCAS::trace('domxml_open_mem() failed');
+      $this->authError('ST not validated',
+               $validate_url,
+               FALSE/*$no_response*/,
+               TRUE/*$bad_response*/,
+               $text_response);
+    }
+    // read the root node of the XML tree
+    if ( !($tree_response = $dom->document_element()) ) {
+      phpCAS::trace('document_element() failed');
+      $this->authError('ST not validated',
+               $validate_url,
+               FALSE/*$no_response*/,
+               TRUE/*$bad_response*/,
+               $text_response);
+    }
+    // insure that tag name is 'serviceResponse'
+    if ( $tree_response->node_name() != 'serviceResponse' ) {
+      phpCAS::trace('bad XML root node (should be `serviceResponse\' instead of `'.$tree_response->node_name().'\'');
+      $this->authError('ST not validated',
+               $validate_url,
+               FALSE/*$no_response*/,
+               TRUE/*$bad_response*/,
+               $text_response);
+    }
+    if ( sizeof($success_elements = $tree_response->get_elements_by_tagname("authenticationSuccess")) != 0) {
+      // authentication succeded, extract the user name
+      if ( sizeof($user_elements = $success_elements[0]->get_elements_by_tagname("user")) == 0) {
+        phpCAS::trace('<authenticationSuccess> found, but no <user>');
+        $this->authError('ST not validated',
+             $validate_url,
+             FALSE/*$no_response*/,
+             TRUE/*$bad_response*/,
+             $text_response);
+      }
+      $user = trim($user_elements[0]->get_content());
+      phpCAS::trace('user = `'.$user);
+      $this->setUser($user);
+      
+    } else if ( sizeof($failure_elements = $tree_response->get_elements_by_tagname("authenticationFailure")) != 0) {
+      phpCAS::trace('<authenticationFailure> found');
+      // authentication failed, extract the error code and message
+      $this->authError('ST not validated',
+               $validate_url,
+               FALSE/*$no_response*/,
+               FALSE/*$bad_response*/,
+               $text_response,
+               $failure_elements[0]->get_attribute('code')/*$err_code*/,
+               trim($failure_elements[0]->get_content())/*$err_msg*/);
+    } else {
+      phpCAS::trace('neither <authenticationSuccess> nor <authenticationFailure> found');
+      $this->authError('ST not validated',
+               $validate_url,
+               FALSE/*$no_response*/,
+               TRUE/*$bad_response*/,
+               $text_response);
+    }
+    break;
       }
       
       // at this step, ST has been validated and $this->_user has been set,
@@ -1218,11 +1218,11 @@ class CASClient
       // the URL is built when needed only
       if ( empty($this->_callback_url) ) {
         $final_uri = '';
-           // remove the ticket if present in the URL
-           $final_uri = 'https://';
-           /* replaced by Julien Marchal - v0.4.6
-            * $this->uri .= $_SERVER['SERVER_NAME'];
-            */
+        // remove the ticket if present in the URL
+        $final_uri = 'https://';
+        /* replaced by Julien Marchal - v0.4.6
+         * $this->uri .= $_SERVER['SERVER_NAME'];
+         */
         if(empty($_SERVER['HTTP_X_FORWARDED_SERVER'])){
           /* replaced by teedog - v0.4.12
            * $final_uri .= $_SERVER['SERVER_NAME'];
@@ -1235,15 +1235,15 @@ class CASClient
         } else {
           $final_uri .= $_SERVER['HTTP_X_FORWARDED_SERVER'];
         }
-           if ( ($this->isHttps() && $_SERVER['SERVER_PORT']!=443)
-              || (!$this->isHttps() && $_SERVER['SERVER_PORT']!=80) ) {
-             $final_uri .= ':';
-             $final_uri .= $_SERVER['SERVER_PORT'];
-           }
-           $request_uri = $_SERVER['REQUEST_URI'];
-           $request_uri = preg_replace('/\?.*$/','',$request_uri);
-           $final_uri .= $request_uri;
-           $this->setCallbackURL($final_uri);
+        if ( ($this->isHttps() && $_SERVER['SERVER_PORT']!=443)
+           || (!$this->isHttps() && $_SERVER['SERVER_PORT']!=80) ) {
+          $final_uri .= ':';
+          $final_uri .= $_SERVER['SERVER_PORT'];
+        }
+        $request_uri = $_SERVER['REQUEST_URI'];
+        $request_uri = preg_replace('/\?.*$/','',$request_uri);
+        $final_uri .= $request_uri;
+        $this->setCallbackURL($final_uri);
       }
       return $this->_callback_url;
     }
@@ -1309,7 +1309,7 @@ class CASClient
     {
       // if no SetPGTStorageXxx() has been used, default to file
       if ( !is_object($this->_pgt_storage) ) {
-       $this->setPGTStorageFile();
+    $this->setPGTStorageFile();
       }
 
       // initializes the storage
@@ -1361,11 +1361,11 @@ class CASClient
    * @public
    */
   function setPGTStorageFile($format='',
-                            $path='')
+                 $path='')
     {
       // check that the storage has not already been set
       if ( is_object($this->_pgt_storage) ) {
-       phpCAS::error('PGT storage already defined');
+    phpCAS::error('PGT storage already defined');
       }
 
       // create the storage object
@@ -1390,16 +1390,16 @@ class CASClient
    * @public
    */
   function setPGTStorageDB($user,
-                          $password,
-                          $database_type,
-                          $hostname,
-                          $port,
-                          $database,
-                          $table)
+               $password,
+               $database_type,
+               $hostname,
+               $port,
+               $database,
+               $table)
     {
       // check that the storage has not already been set
       if ( is_object($this->_pgt_storage) ) {
-       phpCAS::error('PGT storage already defined');
+    phpCAS::error('PGT storage already defined');
       }
 
       // warn the user that he should use file storage...
@@ -1429,30 +1429,30 @@ class CASClient
     {
       phpCAS::traceBegin();
       if ( sizeof($arr = $tree_response->get_elements_by_tagname("proxyGrantingTicket")) == 0) {
-       phpCAS::trace('<proxyGrantingTicket> not found');
-       // authentication succeded, but no PGT Iou was transmitted
-       $this->authError('Ticket validated but no PGT Iou transmitted',
-                    $validate_url,
-                    FALSE/*$no_response*/,
-                    FALSE/*$bad_response*/,
-                    $text_response);
+    phpCAS::trace('<proxyGrantingTicket> not found');
+    // authentication succeded, but no PGT Iou was transmitted
+    $this->authError('Ticket validated but no PGT Iou transmitted',
+             $validate_url,
+             FALSE/*$no_response*/,
+             FALSE/*$bad_response*/,
+             $text_response);
       } else {
-       // PGT Iou transmitted, extract it
-       $pgt_iou = trim($arr[0]->get_content());
-       $pgt = $this->loadPGT($pgt_iou);
-       if ( $pgt == FALSE ) {
+    // PGT Iou transmitted, extract it
+    $pgt_iou = trim($arr[0]->get_content());
+    $pgt = $this->loadPGT($pgt_iou);
+    if ( $pgt == FALSE ) {
 
-         phpCAS::trace('could not load PGT');
+      phpCAS::trace('could not load PGT');
 
-         $this->authError('PGT Iou was transmitted but PGT could not be retrieved',
-                      $validate_url,
-                      FALSE/*$no_response*/,
-                      FALSE/*$bad_response*/,
-                      $text_response);
+      $this->authError('PGT Iou was transmitted but PGT could not be retrieved',
+               $validate_url,
+               FALSE/*$no_response*/,
+               FALSE/*$bad_response*/,
+               $text_response);
 
 
-       }
-       $this->setPGT($pgt);
+    }
+    $this->setPGT($pgt);
       }
       phpCAS::traceEnd(TRUE);
       return TRUE;
@@ -1489,71 +1489,71 @@ class CASClient
 
       // open and read the URL
       if ( !$this->readURL($cas_url,''/*cookies*/,$headers,$cas_response,$err_msg) ) {
-       phpCAS::trace('could not open URL \''.$cas_url.'\' to validate ('.$err_msg.')');
-       $err_code = PHPCAS_SERVICE_PT_NO_SERVER_RESPONSE;
-       $err_msg = 'could not retrieve PT (no response from the CAS server)';
-       phpCAS::traceEnd(FALSE);
-       return FALSE;
+    phpCAS::trace('could not open URL \''.$cas_url.'\' to validate ('.$err_msg.')');
+    $err_code = PHPCAS_SERVICE_PT_NO_SERVER_RESPONSE;
+    $err_msg = 'could not retrieve PT (no response from the CAS server)';
+    phpCAS::traceEnd(FALSE);
+    return FALSE;
       }
 
       $bad_response = FALSE;
 
       if ( !$bad_response ) {
-       // read the response of the CAS server into a DOM object
-       if ( !($dom = @domxml_open_mem($cas_response))) {
-         phpCAS::trace('domxml_open_mem() failed');
-         // read failed
-         $bad_response = TRUE;
-       
+    // read the response of the CAS server into a DOM object
+    if ( !($dom = @domxml_open_mem($cas_response))) {
+      phpCAS::trace('domxml_open_mem() failed');
+      // read failed
+      $bad_response = TRUE;
+    } 
       }
 
       if ( !$bad_response ) {
-       // read the root node of the XML tree
-       if ( !($root = $dom->document_element()) ) {
-         phpCAS::trace('document_element() failed');
-         // read failed
-         $bad_response = TRUE;
-       
+    // read the root node of the XML tree
+    if ( !($root = $dom->document_element()) ) {
+      phpCAS::trace('document_element() failed');
+      // read failed
+      $bad_response = TRUE;
+    } 
       }
 
       if ( !$bad_response ) {
-       // insure that tag name is 'serviceResponse'
-       if ( $root->node_name() != 'serviceResponse' ) {
-         phpCAS::trace('node_name() failed');
-         // bad root node
-         $bad_response = TRUE;
-       
+    // insure that tag name is 'serviceResponse'
+    if ( $root->node_name() != 'serviceResponse' ) {
+      phpCAS::trace('node_name() failed');
+      // bad root node
+      $bad_response = TRUE;
+    } 
       }
 
       if ( !$bad_response ) {
-       // look for a proxySuccess tag
-       if ( sizeof($arr = $root->get_elements_by_tagname("proxySuccess")) != 0) {
-         // authentication succeded, look for a proxyTicket tag
-         if ( sizeof($arr = $root->get_elements_by_tagname("proxyTicket")) != 0) {
-           $err_code = PHPCAS_SERVICE_OK;
-           $err_msg = '';
+    // look for a proxySuccess tag
+    if ( sizeof($arr = $root->get_elements_by_tagname("proxySuccess")) != 0) {
+      // authentication succeded, look for a proxyTicket tag
+      if ( sizeof($arr = $root->get_elements_by_tagname("proxyTicket")) != 0) {
+        $err_code = PHPCAS_SERVICE_OK;
+        $err_msg = '';
         phpCAS::trace('original PT: '.trim($arr[0]->get_content()));
         $pt = trim($arr[0]->get_content());
-           phpCAS::traceEnd($pt);
-           return $pt;
-         } else {
-           phpCAS::trace('<proxySuccess> was found, but not <proxyTicket>');
-         }
-       
-       // look for a proxyFailure tag
-       else if ( sizeof($arr = $root->get_elements_by_tagname("proxyFailure")) != 0) {
-         // authentication failed, extract the error
-         $err_code = PHPCAS_SERVICE_PT_FAILURE;
-         $err_msg = 'PT retrieving failed (code=`'
-           .$arr[0]->get_attribute('code')
-           .'\', message=`'
-           .trim($arr[0]->get_content())
-           .'\')';
-         phpCAS::traceEnd(FALSE);
-         return FALSE;
-       } else {
-         phpCAS::trace('neither <proxySuccess> nor <proxyFailure> found');
-       }
+        phpCAS::traceEnd($pt);
+        return $pt;
+      } else {
+        phpCAS::trace('<proxySuccess> was found, but not <proxyTicket>');
+      }
+    } 
+    // look for a proxyFailure tag
+    else if ( sizeof($arr = $root->get_elements_by_tagname("proxyFailure")) != 0) {
+      // authentication failed, extract the error
+      $err_code = PHPCAS_SERVICE_PT_FAILURE;
+      $err_msg = 'PT retrieving failed (code=`'
+        .$arr[0]->get_attribute('code')
+        .'\', message=`'
+        .trim($arr[0]->get_content())
+        .'\')';
+      phpCAS::traceEnd(FALSE);
+      return FALSE;
+    } else {
+      phpCAS::trace('neither <proxySuccess> nor <proxyFailure> found');
+    }
       }
 
       // at this step, we are sure that the response of the CAS server was ill-formed
@@ -1594,11 +1594,11 @@ class CASClient
 
       // initialize the CURL session
       $ch = curl_init($url);
-       
-         // verify the the server's certificate corresponds to its name
-         curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1);
-         // but do not verify the certificate itself
-         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
+    
+      // verify the the server's certificate corresponds to its name
+      curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1);
+      // but do not verify the certificate itself
+      curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
 
       // return the CURL output into a variable
       curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
@@ -1606,45 +1606,45 @@ class CASClient
       curl_setopt($ch, CURLOPT_HEADER, 1);
       // add cookies headers
       if ( is_array($cookies) ) {
-       curl_setopt($ch,CURLOPT_COOKIE,implode(';',$cookies));
+    curl_setopt($ch,CURLOPT_COOKIE,implode(';',$cookies));
       }
       // perform the query
       $buf = curl_exec ($ch);
       if ( $buf === FALSE ) {
-       phpCAS::trace('cur_exec() failed');
-       $err_msg = 'CURL error #'.curl_errno($ch).': '.curl_error($ch);
-       // close the CURL session
-       curl_close ($ch);
-       $res = FALSE;
+    phpCAS::trace('cur_exec() failed');
+    $err_msg = 'CURL error #'.curl_errno($ch).': '.curl_error($ch);
+    // close the CURL session
+    curl_close ($ch);
+    $res = FALSE;
       } else {
-       // close the CURL session
-       curl_close ($ch);
-       
-       // find the end of the headers
-       // note: strpos($str,"\n\r\n\r") does not work (?)
-       $pos = FALSE;
-       for ($i=0; $i<strlen($buf); $i++) {
-         if ( $buf[$i] == chr(13) ) 
-           if ( $buf[$i+1] == chr(10) ) 
-             if ( $buf[$i+2] == chr(13) ) 
-               if ( $buf[$i+3] == chr(10) ) {
-                 // header found
-                 $pos = $i;
-                 break;
-               }
-       }
-       
-       if ( $pos === FALSE ) {
-         // end of header not found
-         $err_msg = 'no header found';
-         phpCAS::trace($err_msg);
-         $res = FALSE;
-       } else { 
-         // extract headers into an array
-         $headers = preg_split ("/[\n\r]+/",substr($buf,0,$pos));        
-         // extract body into a string
-         $body = substr($buf,$pos+4);
-       }
+    // close the CURL session
+    curl_close ($ch);
+    
+    // find the end of the headers
+    // note: strpos($str,"\n\r\n\r") does not work (?)
+    $pos = FALSE;
+    for ($i=0; $i<strlen($buf); $i++) {
+      if ( $buf[$i] == chr(13) ) 
+        if ( $buf[$i+1] == chr(10) ) 
+          if ( $buf[$i+2] == chr(13) ) 
+        if ( $buf[$i+3] == chr(10) ) {
+          // header found
+          $pos = $i;
+          break;
+        }
+    }
+    
+    if ( $pos === FALSE ) {
+      // end of header not found
+      $err_msg = 'no header found';
+      phpCAS::trace($err_msg);
+      $res = FALSE;
+    } else { 
+      // extract headers into an array
+      $headers = preg_split ("/[\n\r]+/",substr($buf,0,$pos));    
+      // extract body into a string
+      $body = substr($buf,$pos+4);
+    }
       }
 
       phpCAS::traceEnd($res);
@@ -1676,52 +1676,52 @@ class CASClient
       
       // test if PT was retrieved correctly
       if ( !$pt ) {
-       // note: $err_code and $err_msg are filled by CASClient::retrievePT()
-       phpCAS::trace('PT was not retrieved correctly');
-       $res = FALSE;
+    // note: $err_code and $err_msg are filled by CASClient::retrievePT()
+    phpCAS::trace('PT was not retrieved correctly');
+    $res = FALSE;
       } else {
-       // add cookies if necessary
-       if ( is_array($_SESSION['phpCAS']['services'][$url]['cookies']) ) {
-         foreach ( $_SESSION['phpCAS']['services'][$url]['cookies'] as $name => $val ) { 
-           $cookies[] = $name.'='.$val;
-         }
-       }
-       
-       // build the URL including the PT
-       if ( strstr($url,'?') === FALSE ) {
-         $service_url = $url.'?ticket='.$pt;
-       } else {
-         $service_url = $url.'&ticket='.$pt;
-       }
-       
-       phpCAS::trace('reading URL`'.$service_url.'\'');
-       if ( !$this->readURL($service_url,$cookies,$headers,$output,$err_msg) ) {
-         phpCAS::trace('could not read URL`'.$service_url.'\'');
-         $err_code = PHPCAS_SERVICE_NOT_AVAILABLE;
-         // give an error message
-         $output = sprintf($this->getString(CAS_STR_SERVICE_UNAVAILABLE),
-                           $service_url,
-                           $err_msg);
-         $res = FALSE;
-       } else {
-         // URL has been fetched, extract the cookies
-         phpCAS::trace('URL`'.$service_url.'\' has been read, storing cookies:');
-         foreach ( $headers as $header ) {
-           // test if the header is a cookie
-           if ( preg_match('/^Set-Cookie:/',$header) ) {
-             // the header is a cookie, remove the beginning
-             $header_val = preg_replace('/^Set-Cookie: */','',$header);
-             // extract interesting information
-             $name_val = strtok($header_val,'; ');
-             // extract the name and the value of the cookie
-             $cookie_name = strtok($name_val,'=');
-             $cookie_val = strtok('=');
-             // store the cookie 
-             $_SESSION['phpCAS']['services'][$url]['cookies'][$cookie_name] = $cookie_val;
-             phpCAS::trace($cookie_name.' -> '.$cookie_val);
-           }
-         }
-       }
+    // add cookies if necessary
+    if ( is_array($_SESSION['phpCAS']['services'][$url]['cookies']) ) {
+      foreach ( $_SESSION['phpCAS']['services'][$url]['cookies'] as $name => $val ) { 
+        $cookies[] = $name.'='.$val;
+      }
+    }
+    
+    // build the URL including the PT
+    if ( strstr($url,'?') === FALSE ) {
+      $service_url = $url.'?ticket='.$pt;
+    } else {
+      $service_url = $url.'&ticket='.$pt;
+    }
+    
+    phpCAS::trace('reading URL`'.$service_url.'\'');
+    if ( !$this->readURL($service_url,$cookies,$headers,$output,$err_msg) ) {
+      phpCAS::trace('could not read URL`'.$service_url.'\'');
+      $err_code = PHPCAS_SERVICE_NOT_AVAILABLE;
+      // give an error message
+      $output = sprintf($this->getString(CAS_STR_SERVICE_UNAVAILABLE),
+                $service_url,
+                $err_msg);
+      $res = FALSE;
+    } else {
+      // URL has been fetched, extract the cookies
+      phpCAS::trace('URL`'.$service_url.'\' has been read, storing cookies:');
+      foreach ( $headers as $header ) {
+        // test if the header is a cookie
+        if ( preg_match('/^Set-Cookie:/',$header) ) {
+          // the header is a cookie, remove the beginning
+          $header_val = preg_replace('/^Set-Cookie: */','',$header);
+          // extract interesting information
+          $name_val = strtok($header_val,'; ');
+          // extract the name and the value of the cookie
+          $cookie_name = strtok($name_val,'=');
+          $cookie_val = strtok('=');
+          // store the cookie 
+          $_SESSION['phpCAS']['services'][$url]['cookies'][$cookie_name] = $cookie_val;
+          phpCAS::trace($cookie_name.' -> '.$cookie_val);
+        }
+      }
+    }
       }
 
       phpCAS::traceEnd($res);
@@ -1756,23 +1756,23 @@ class CASClient
       
       // test if PT was retrieved correctly
       if ( !$pt ) {
-       // note: $err_code and $err_msg are filled by CASClient::retrievePT()
-       phpCAS::trace('PT was not retrieved correctly');
+    // note: $err_code and $err_msg are filled by CASClient::retrievePT()
+    phpCAS::trace('PT was not retrieved correctly');
       } else {
-       phpCAS::trace('opening IMAP URL `'.$url.'\'...');
-       $stream = @imap_open($url,$this->getUser(),$pt,$flags);
-       if ( !$stream ) {
-         phpCAS::trace('could not open URL');
-         $err_code = PHPCAS_SERVICE_NOT_AVAILABLE;
-         // give an error message
-         $err_msg = sprintf($this->getString(CAS_STR_SERVICE_UNAVAILABLE),
-                            $service_url,
-                            var_export(imap_errors(),TRUE));
-         $pt = FALSE;
-         $stream = FALSE;
-       } else {
-         phpCAS::trace('ok');
-       }
+    phpCAS::trace('opening IMAP URL `'.$url.'\'...');
+    $stream = @imap_open($url,$this->getUser(),$pt,$flags);
+    if ( !$stream ) {
+      phpCAS::trace('could not open URL');
+      $err_code = PHPCAS_SERVICE_NOT_AVAILABLE;
+      // give an error message
+      $err_msg = sprintf($this->getString(CAS_STR_SERVICE_UNAVAILABLE),
+                 $service_url,
+                 var_export(imap_errors(),TRUE));
+      $pt = FALSE;
+      $stream = FALSE;
+    } else {
+      phpCAS::trace('ok');
+    }
       }
 
       phpCAS::traceEnd($stream);
@@ -1855,71 +1855,71 @@ class CASClient
 
       if ( $this->isProxy() ) {
       // pass the callback url for CAS proxies
-       $validate_url .= '&pgtUrl='.$this->getCallbackURL();
+    $validate_url .= '&pgtUrl='.$this->getCallbackURL();
       }
 
       // open and read the URL
       if ( !$this->readURL($validate_url,''/*cookies*/,$headers,$text_response,$err_msg) ) {
-       phpCAS::trace('could not open URL \''.$validate_url.'\' to validate ('.$err_msg.')');
-       $this->authError('PT not validated',
-                        $validate_url,
-                        TRUE/*$no_response*/);
+    phpCAS::trace('could not open URL \''.$validate_url.'\' to validate ('.$err_msg.')');
+    $this->authError('PT not validated',
+             $validate_url,
+             TRUE/*$no_response*/);
       }
 
       // read the response of the CAS server into a DOM object
       if ( !($dom = domxml_open_mem($text_response))) {
-       // read failed
-       $this->authError('PT not validated',
-                    $validate_url,
-                    FALSE/*$no_response*/,
-                    TRUE/*$bad_response*/,
-                    $text_response);
+    // read failed
+    $this->authError('PT not validated',
+             $validate_url,
+             FALSE/*$no_response*/,
+             TRUE/*$bad_response*/,
+             $text_response);
       }
       // read the root node of the XML tree
       if ( !($tree_response = $dom->document_element()) ) {
-       // read failed
-       $this->authError('PT not validated',
-                    $validate_url,
-                    FALSE/*$no_response*/,
-                    TRUE/*$bad_response*/,
-                    $text_response);
+    // read failed
+    $this->authError('PT not validated',
+             $validate_url,
+             FALSE/*$no_response*/,
+             TRUE/*$bad_response*/,
+             $text_response);
       }
       // insure that tag name is 'serviceResponse'
       if ( $tree_response->node_name() != 'serviceResponse' ) {
-       // bad root node
-       $this->authError('PT not validated',
-                    $validate_url,
-                    FALSE/*$no_response*/,
-                    TRUE/*$bad_response*/,
-                    $text_response);
+    // bad root node
+    $this->authError('PT not validated',
+             $validate_url,
+             FALSE/*$no_response*/,
+             TRUE/*$bad_response*/,
+             $text_response);
       }
       if ( sizeof($arr = $tree_response->get_elements_by_tagname("authenticationSuccess")) != 0) {
-       // authentication succeded, extract the user name
-       if ( sizeof($arr = $tree_response->get_elements_by_tagname("user")) == 0) {
-         // no user specified => error
-         $this->authError('PT not validated',
-                      $validate_url,
-                      FALSE/*$no_response*/,
-                      TRUE/*$bad_response*/,
-                      $text_response);
-       }
-       $this->setUser(trim($arr[0]->get_content()));
-       
+    // authentication succeded, extract the user name
+    if ( sizeof($arr = $tree_response->get_elements_by_tagname("user")) == 0) {
+      // no user specified => error
+      $this->authError('PT not validated',
+               $validate_url,
+               FALSE/*$no_response*/,
+               TRUE/*$bad_response*/,
+               $text_response);
+    }
+    $this->setUser(trim($arr[0]->get_content()));
+    
       } else if ( sizeof($arr = $tree_response->get_elements_by_tagname("authenticationFailure")) != 0) {
-       // authentication succeded, extract the error code and message
-       $this->authError('PT not validated',
-                    $validate_url,
-                    FALSE/*$no_response*/,
-                    FALSE/*$bad_response*/,
-                    $text_response,
-                    $arr[0]->get_attribute('code')/*$err_code*/,
-                    trim($arr[0]->get_content())/*$err_msg*/);
+    // authentication succeded, extract the error code and message
+    $this->authError('PT not validated',
+             $validate_url,
+             FALSE/*$no_response*/,
+             FALSE/*$bad_response*/,
+             $text_response,
+             $arr[0]->get_attribute('code')/*$err_code*/,
+             trim($arr[0]->get_content())/*$err_msg*/);
       } else {
-       $this->authError('PT not validated',
-                    $validate_url,     
-                    FALSE/*$no_response*/,
-                    TRUE/*$bad_response*/,
-                    $text_response);
+    $this->authError('PT not validated',
+             $validate_url, 
+             FALSE/*$no_response*/,
+             TRUE/*$bad_response*/,
+             $text_response);
       }
       
       // at this step, PT has been validated and $this->_user has been set,
@@ -1966,13 +1966,13 @@ class CASClient
       phpCAS::traceBegin();
       // the URL is built when needed only
       if ( empty($this->_url) ) {
-           $final_uri = '';
-           // remove the ticket if present in the URL
-           $final_uri = ($this->isHttps()) ? 'https' : 'http';
-           $final_uri .= '://';
-           /* replaced by Julien Marchal - v0.4.6
-            * $this->_url .= $_SERVER['SERVER_NAME'];
-            */
+        $final_uri = '';
+        // remove the ticket if present in the URL
+        $final_uri = ($this->isHttps()) ? 'https' : 'http';
+        $final_uri .= '://';
+        /* replaced by Julien Marchal - v0.4.6
+         * $this->_url .= $_SERVER['SERVER_NAME'];
+         */
         if(empty($_SERVER['HTTP_X_FORWARDED_SERVER'])){
           /* replaced by teedog - v0.4.12
            * $this->_url .= $_SERVER['SERVER_NAME'];
@@ -1987,23 +1987,23 @@ class CASClient
         }
       $final_uri .= $server_name;
       if (!strpos($server_name, ':')) {
-           if ( ($this->isHttps() && $_SERVER['SERVER_PORT']!=443)
-              || (!$this->isHttps() && $_SERVER['SERVER_PORT']!=80) ) {
-             $final_uri .= ':';
-             $final_uri .= $_SERVER['SERVER_PORT'];
-           }
+        if ( ($this->isHttps() && $_SERVER['SERVER_PORT']!=443)
+           || (!$this->isHttps() && $_SERVER['SERVER_PORT']!=80) ) {
+          $final_uri .= ':';
+          $final_uri .= $_SERVER['SERVER_PORT'];
+        }
       }
 
-         $final_uri .= strtok($_SERVER['REQUEST_URI'],"?");
-         $cgi_params = '?'.strtok("?");
-         // remove the ticket if present in the CGI parameters
-         $cgi_params = preg_replace('/&ticket=[^&]*/','',$cgi_params);
-         $cgi_params = preg_replace('/\?ticket=[^&;]*/','?',$cgi_params);
-         $cgi_params = preg_replace('/\?%26/','?',$cgi_params);
-         $cgi_params = preg_replace('/\?&/','?',$cgi_params);
-         $cgi_params = preg_replace('/\?$/','',$cgi_params);
-         $final_uri .= $cgi_params;
-         $this->setURL($final_uri);
+      $final_uri .= strtok($_SERVER['REQUEST_URI'],"?");
+      $cgi_params = '?'.strtok("?");
+      // remove the ticket if present in the CGI parameters
+      $cgi_params = preg_replace('/&ticket=[^&]*/','',$cgi_params);
+      $cgi_params = preg_replace('/\?ticket=[^&;]*/','?',$cgi_params);
+      $cgi_params = preg_replace('/\?%26/','?',$cgi_params);
+      $cgi_params = preg_replace('/\?&/','?',$cgi_params);
+      $cgi_params = preg_replace('/\?$/','',$cgi_params);
+      $final_uri .= $cgi_params;
+      $this->setURL($final_uri);
     }
     phpCAS::traceEnd($this->_url);
     return $this->_url;
@@ -2048,24 +2048,24 @@ class CASClient
       phpCAS::trace('CAS URL: '.$cas_url);
       phpCAS::trace('Authentication failure: '.$failure);
       if ( $no_response ) {
-       phpCAS::trace('Reason: no response from the CAS server');
+    phpCAS::trace('Reason: no response from the CAS server');
       } else {
-       if ( $bad_response ) {
-           phpCAS::trace('Reason: bad response from the CAS server');
-       } else {
-         switch ($this->getServerVersion()) {
-         case CAS_VERSION_1_0:
-           phpCAS::trace('Reason: CAS error');
-           break;
-         case CAS_VERSION_2_0:
-           if ( empty($err_code) )
-             phpCAS::trace('Reason: no CAS error');
-           else
-             phpCAS::trace('Reason: ['.$err_code.'] CAS error: '.$err_msg);
-           break;
-         }
-       }
-       phpCAS::trace('CAS response: '.$cas_response);
+    if ( $bad_response ) {
+        phpCAS::trace('Reason: bad response from the CAS server');
+    } else {
+      switch ($this->getServerVersion()) {
+      case CAS_VERSION_1_0:
+        phpCAS::trace('Reason: CAS error');
+        break;
+      case CAS_VERSION_2_0:
+        if ( empty($err_code) )
+          phpCAS::trace('Reason: no CAS error');
+        else
+          phpCAS::trace('Reason: ['.$err_code.'] CAS error: '.$err_msg);
+        break;
+      }
+    }
+    phpCAS::trace('CAS response: '.$cas_response);
       }
       $this->printHTMLFooter();
       phpCAS::traceExit();
index 9f35e1cf76ceb7c51cc1764e6cf3eb4e9271f9ed..ad79da6570349d68c2d1649d59a0873d17f729a1 100644 (file)
@@ -16,271 +16,270 @@ V5.04a 25 Mar 2008   (c) 2000-2008 John Lim (jlim#natsoft.com.my). All rights re
 if (!defined('ADODB_DIR')) die();
 
 class perf_mysql extends adodb_perf{
-       
-       var $tablesSQL = 'show table status';
-       
-       var $createTableSQL = "CREATE TABLE adodb_logsql (
-                 created datetime NOT NULL,
-                 sql0 varchar(250) NOT NULL,
-                 sql1 text NOT NULL,
-                 params text NOT NULL,
-                 tracer text NOT NULL,
-                 timer decimal(16,6) NOT NULL
-               )";
-               
-       var $settings = array(
-       'Ratios',
-               'MyISAM cache hit ratio' => array('RATIO',
-                       '=GetKeyHitRatio',
-                       '=WarnCacheRatio'),
-               'InnoDB cache hit ratio' => array('RATIO',
-                       '=GetInnoDBHitRatio',
-                       '=WarnCacheRatio'),
-               'data cache hit ratio' => array('HIDE', # only if called
-                       '=FindDBHitRatio',
-                       '=WarnCacheRatio'),
-               'sql cache hit ratio' => array('RATIO',
-                       '=GetQHitRatio',
-                       ''),
-       'IO',
-               'data reads' => array('IO',
-                       '=GetReads',
-                       'Number of selects (Key_reads is not accurate)'),
-               'data writes' => array('IO',
-                       '=GetWrites',
-                       'Number of inserts/updates/deletes * coef (Key_writes is not accurate)'),
-               
-       'Data Cache',
-               'MyISAM data cache size' => array('DATAC',
-                       array("show variables", 'key_buffer_size'),
-                       '' ),
-               'BDB data cache size' => array('DATAC',
-                       array("show variables", 'bdb_cache_size'),
-                       '' ),
-               'InnoDB data cache size' => array('DATAC',
-                       array("show variables", 'innodb_buffer_pool_size'),
-                       '' ),
-       'Memory Usage',
-               'read buffer size' => array('CACHE',
-                       array("show variables", 'read_buffer_size'),
-                       '(per session)'),
-               'sort buffer size' => array('CACHE',
-                       array("show variables", 'sort_buffer_size'),
-                       'Size of sort buffer (per session)' ),
-               'table cache' => array('CACHE',
-                       array("show variables", 'table_cache'),
-                       'Number of tables to keep open'),
-       'Connections',  
-               'current connections' => array('SESS',
-                       array('show status','Threads_connected'),
-                       ''),
-               'max connections' => array( 'SESS',
-                       array("show variables",'max_connections'),
-                       ''),
-       
-               false
-       );
-       
-       function perf_mysql(&$conn)
-       {
-               $this->conn = $conn;
-       }
-       
-       function Explain($sql,$partial=false)
-       {
-               
-               if (strtoupper(substr(trim($sql),0,6)) !== 'SELECT') return '<p>Unable to EXPLAIN non-select statement</p>';
-               $save = $this->conn->LogSQL(false);
-               if ($partial) {
-                       $sqlq = $this->conn->qstr($sql.'%');
-                       $arr = $this->conn->GetArray("select distinct sql1 from adodb_logsql where sql1 like $sqlq");
-                       if ($arr) {
-                               foreach($arr as $row) {
-                                       $sql = reset($row);
-                                       if (crc32($sql) == $partial) break;
-                               }
-                       }
-               }
-               $sql = str_replace('?',"''",$sql);
-               
-               if ($partial) {
-                       $sqlq = $this->conn->qstr($sql.'%');
-                       $sql = $this->conn->GetOne("select sql1 from adodb_logsql where sql1 like $sqlq");
-               }
-               
-               $s = '<p><b>Explain</b>: '.htmlspecialchars($sql).'</p>';
-               $rs = $this->conn->Execute('EXPLAIN '.$sql);
-               $s .= rs2html($rs,false,false,false,false);
-               $this->conn->LogSQL($save);
-               $s .= $this->Tracer($sql);
-               return $s;
-       }
-       
-       function Tables()
-       {
-               if (!$this->tablesSQL) return false;
-               
-               $rs = $this->conn->Execute($this->tablesSQL);
-               if (!$rs) return false;
-               
-               $html = rs2html($rs,false,false,false,false);
-               return $html;
-       }
-       
-       function GetReads()
-       {
-       global $ADODB_FETCH_MODE;
-               $save = $ADODB_FETCH_MODE;
-               $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
-               if ($this->conn->fetchMode !== false) $savem = $this->conn->SetFetchMode(false);
-               
-               $rs = $this->conn->Execute('show status');
-               
-               if (isset($savem)) $this->conn->SetFetchMode($savem);
-               $ADODB_FETCH_MODE = $save;
-               
-               if (!$rs) return 0;
-               $val = 0;
-               while (!$rs->EOF) {
-                       switch($rs->fields[0]) {
-                       case 'Com_select': 
-                               $val = $rs->fields[1];
-                               $rs->Close();
-                               return $val;
-                       }
-                       $rs->MoveNext();
-               } 
-               
-               $rs->Close();
-               
-               return $val;
-       }
-       
-       function GetWrites()
-       {
-       global $ADODB_FETCH_MODE;
-               $save = $ADODB_FETCH_MODE;
-               $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
-               if ($this->conn->fetchMode !== false) $savem = $this->conn->SetFetchMode(false);
-               
-               $rs = $this->conn->Execute('show status');
-               
-               if (isset($savem)) $this->conn->SetFetchMode($savem);
-               $ADODB_FETCH_MODE = $save;
-               
-               if (!$rs) return 0;
-               $val = 0.0;
-               while (!$rs->EOF) {
-                       switch($rs->fields[0]) {
-                       case 'Com_insert': 
-                               $val += $rs->fields[1]; break;
-                       case 'Com_delete': 
-                               $val += $rs->fields[1]; break;
-                       case 'Com_update': 
-                               $val += $rs->fields[1]/2;
-                               $rs->Close();
-                               return $val;
-                       }
-                       $rs->MoveNext();
-               } 
-               
-               $rs->Close();
-               
-               return $val;
-       }
-       
-       function FindDBHitRatio()
-       {
-               // first find out type of table
-               //$this->conn->debug=1;
-               
-               global $ADODB_FETCH_MODE;
-               $save = $ADODB_FETCH_MODE;
-               $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
-               if ($this->conn->fetchMode !== false) $savem = $this->conn->SetFetchMode(false);
-               
-               $rs = $this->conn->Execute('show table status');
-               
-               if (isset($savem)) $this->conn->SetFetchMode($savem);
-               $ADODB_FETCH_MODE = $save;
-               
-               if (!$rs) return '';
-               $type = strtoupper($rs->fields[1]);
-               $rs->Close();
-               switch($type){
-               case 'MYISAM':
-               case 'ISAM':
-                       return $this->DBParameter('MyISAM cache hit ratio').' (MyISAM)';
-               case 'INNODB':
-                       return $this->DBParameter('InnoDB cache hit ratio').' (InnoDB)';
-               default:
-                       return $type.' not supported';
-               }
-               
-       }
-       
-       function GetQHitRatio()
-       {
-               //Total number of queries = Qcache_inserts + Qcache_hits + Qcache_not_cached
-               $hits = $this->_DBParameter(array("show status","Qcache_hits"));
-               $total = $this->_DBParameter(array("show status","Qcache_inserts"));
-               $total += $this->_DBParameter(array("show status","Qcache_not_cached"));
-               
-               $total += $hits;
-               if ($total) return round(($hits*100)/$total,2);
-               return 0;
-       }
-       
-       /*
-               Use session variable to store Hit percentage, because MySQL
-               does not remember last value of SHOW INNODB STATUS hit ratio
-               
-               # 1st query to SHOW INNODB STATUS
-               0.00 reads/s, 0.00 creates/s, 0.00 writes/s
-               Buffer pool hit rate 1000 / 1000
-               
-               # 2nd query to SHOW INNODB STATUS
-               0.00 reads/s, 0.00 creates/s, 0.00 writes/s
-               No buffer pool activity since the last printout
-       */
-       function GetInnoDBHitRatio()
-       {
-       global $ADODB_FETCH_MODE;
-       
-               $save = $ADODB_FETCH_MODE;
-               $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
-               if ($this->conn->fetchMode !== false) $savem = $this->conn->SetFetchMode(false);
-               
-               $rs = $this->conn->Execute('show innodb status');
-               
-               if (isset($savem)) $this->conn->SetFetchMode($savem);
-               $ADODB_FETCH_MODE = $save;
-               
-               if (!$rs || $rs->EOF) return 0;
-               $stat = $rs->fields[0];
-               $rs->Close();
-               $at = strpos($stat,'Buffer pool hit rate');
-               $stat = substr($stat,$at,200);
-               if (preg_match('!Buffer pool hit rate\s*([0-9]*) / ([0-9]*)!',$stat,$arr)) {
-                       $val = 100*$arr[1]/$arr[2];
-                       $_SESSION['INNODB_HIT_PCT'] = $val;
-                       return round($val,2);
-               } else {
-                       if (isset($_SESSION['INNODB_HIT_PCT'])) return $_SESSION['INNODB_HIT_PCT'];
-                       return 0;
-               }
-               return 0;
-       }
-       
-       function GetKeyHitRatio()
-       {
-               $hits = $this->_DBParameter(array("show status","Key_read_requests"));
-               $reqs = $this->_DBParameter(array("show status","Key_reads"));
-               if ($reqs == 0) return 0;
-               
-               return round(($hits/($reqs+$hits))*100,2);
-       }
-       
+    
+    var $tablesSQL = 'show table status';
+    
+    var $createTableSQL = "CREATE TABLE adodb_logsql (
+          created datetime NOT NULL,
+          sql0 varchar(250) NOT NULL,
+          sql1 text NOT NULL,
+          params text NOT NULL,
+          tracer text NOT NULL,
+          timer decimal(16,6) NOT NULL
+        )";
+        
+    var $settings = array(
+    'Ratios',
+        'MyISAM cache hit ratio' => array('RATIO',
+            '=GetKeyHitRatio',
+            '=WarnCacheRatio'),
+        'InnoDB cache hit ratio' => array('RATIO',
+            '=GetInnoDBHitRatio',
+            '=WarnCacheRatio'),
+        'data cache hit ratio' => array('HIDE', # only if called
+            '=FindDBHitRatio',
+            '=WarnCacheRatio'),
+        'sql cache hit ratio' => array('RATIO',
+            '=GetQHitRatio',
+            ''),
+    'IO',
+        'data reads' => array('IO',
+            '=GetReads',
+            'Number of selects (Key_reads is not accurate)'),
+        'data writes' => array('IO',
+            '=GetWrites',
+            'Number of inserts/updates/deletes * coef (Key_writes is not accurate)'),
+        
+    'Data Cache',
+        'MyISAM data cache size' => array('DATAC',
+            array("show variables", 'key_buffer_size'),
+            '' ),
+        'BDB data cache size' => array('DATAC',
+            array("show variables", 'bdb_cache_size'),
+            '' ),
+        'InnoDB data cache size' => array('DATAC',
+            array("show variables", 'innodb_buffer_pool_size'),
+            '' ),
+    'Memory Usage',
+        'read buffer size' => array('CACHE',
+            array("show variables", 'read_buffer_size'),
+            '(per session)'),
+        'sort buffer size' => array('CACHE',
+            array("show variables", 'sort_buffer_size'),
+            'Size of sort buffer (per session)' ),
+        'table cache' => array('CACHE',
+            array("show variables", 'table_cache'),
+            'Number of tables to keep open'),
+    'Connections',  
+        'current connections' => array('SESS',
+            array('show status','Threads_connected'),
+            ''),
+        'max connections' => array( 'SESS',
+            array("show variables",'max_connections'),
+            ''),
+    
+        false
+    );
+    
+    function perf_mysql(&$conn)
+    {
+        $this->conn = $conn;
+    }
+    
+    function Explain($sql,$partial=false)
+    {
+        
+        if (strtoupper(substr(trim($sql),0,6)) !== 'SELECT') return '<p>Unable to EXPLAIN non-select statement</p>';
+        $save = $this->conn->LogSQL(false);
+        if ($partial) {
+            $sqlq = $this->conn->qstr($sql.'%');
+            $arr = $this->conn->GetArray("select distinct sql1 from adodb_logsql where sql1 like $sqlq");
+            if ($arr) {
+                foreach($arr as $row) {
+                    $sql = reset($row);
+                    if (crc32($sql) == $partial) break;
+                }
+            }
+        }
+        $sql = str_replace('?',"''",$sql);
+        
+        if ($partial) {
+            $sqlq = $this->conn->qstr($sql.'%');
+            $sql = $this->conn->GetOne("select sql1 from adodb_logsql where sql1 like $sqlq");
+        }
+        
+        $s = '<p><b>Explain</b>: '.htmlspecialchars($sql).'</p>';
+        $rs = $this->conn->Execute('EXPLAIN '.$sql);
+        $s .= rs2html($rs,false,false,false,false);
+        $this->conn->LogSQL($save);
+        $s .= $this->Tracer($sql);
+        return $s;
+    }
+    
+    function Tables()
+    {
+        if (!$this->tablesSQL) return false;
+        
+        $rs = $this->conn->Execute($this->tablesSQL);
+        if (!$rs) return false;
+        
+        $html = rs2html($rs,false,false,false,false);
+        return $html;
+    }
+    
+    function GetReads()
+    {
+    global $ADODB_FETCH_MODE;
+        $save = $ADODB_FETCH_MODE;
+        $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
+        if ($this->conn->fetchMode !== false) $savem = $this->conn->SetFetchMode(false);
+        
+        $rs = $this->conn->Execute('show status');
+        
+        if (isset($savem)) $this->conn->SetFetchMode($savem);
+        $ADODB_FETCH_MODE = $save;
+        
+        if (!$rs) return 0;
+        $val = 0;
+        while (!$rs->EOF) {
+            switch($rs->fields[0]) {
+            case 'Com_select': 
+                $val = $rs->fields[1];
+                $rs->Close();
+                return $val;
+            }
+            $rs->MoveNext();
+        } 
+        
+        $rs->Close();
+        
+        return $val;
+    }
+    
+    function GetWrites()
+    {
+    global $ADODB_FETCH_MODE;
+        $save = $ADODB_FETCH_MODE;
+        $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
+        if ($this->conn->fetchMode !== false) $savem = $this->conn->SetFetchMode(false);
+        
+        $rs = $this->conn->Execute('show status');
+        
+        if (isset($savem)) $this->conn->SetFetchMode($savem);
+        $ADODB_FETCH_MODE = $save;
+        
+        if (!$rs) return 0;
+        $val = 0.0;
+        while (!$rs->EOF) {
+            switch($rs->fields[0]) {
+            case 'Com_insert': 
+                $val += $rs->fields[1]; break;
+            case 'Com_delete': 
+                $val += $rs->fields[1]; break;
+            case 'Com_update': 
+                $val += $rs->fields[1]/2;
+                $rs->Close();
+                return $val;
+            }
+            $rs->MoveNext();
+        } 
+        
+        $rs->Close();
+        
+        return $val;
+    }
+    
+    function FindDBHitRatio()
+    {
+        // first find out type of table
+        //$this->conn->debug=1;
+        
+        global $ADODB_FETCH_MODE;
+        $save = $ADODB_FETCH_MODE;
+        $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
+        if ($this->conn->fetchMode !== false) $savem = $this->conn->SetFetchMode(false);
+        
+        $rs = $this->conn->Execute('show table status');
+        
+        if (isset($savem)) $this->conn->SetFetchMode($savem);
+        $ADODB_FETCH_MODE = $save;
+        
+        if (!$rs) return '';
+        $type = strtoupper($rs->fields[1]);
+        $rs->Close();
+        switch($type){
+        case 'MYISAM':
+        case 'ISAM':
+            return $this->DBParameter('MyISAM cache hit ratio').' (MyISAM)';
+        case 'INNODB':
+            return $this->DBParameter('InnoDB cache hit ratio').' (InnoDB)';
+        default:
+            return $type.' not supported';
+        }
+        
+    }
+    
+    function GetQHitRatio()
+    {
+        //Total number of queries = Qcache_inserts + Qcache_hits + Qcache_not_cached
+        $hits = $this->_DBParameter(array("show status","Qcache_hits"));
+        $total = $this->_DBParameter(array("show status","Qcache_inserts"));
+        $total += $this->_DBParameter(array("show status","Qcache_not_cached"));
+        
+        $total += $hits;
+        if ($total) return round(($hits*100)/$total,2);
+        return 0;
+    }
+    
+    /*
+        Use session variable to store Hit percentage, because MySQL
+        does not remember last value of SHOW INNODB STATUS hit ratio
+        
+        # 1st query to SHOW INNODB STATUS
+        0.00 reads/s, 0.00 creates/s, 0.00 writes/s
+        Buffer pool hit rate 1000 / 1000
+        
+        # 2nd query to SHOW INNODB STATUS
+        0.00 reads/s, 0.00 creates/s, 0.00 writes/s
+        No buffer pool activity since the last printout
+    */
+    function GetInnoDBHitRatio()
+    {
+    global $ADODB_FETCH_MODE;
+    
+        $save = $ADODB_FETCH_MODE;
+        $ADODB_FETCH_MODE = ADODB_FETCH_NUM;
+        if ($this->conn->fetchMode !== false) $savem = $this->conn->SetFetchMode(false);
+        
+        $rs = $this->conn->Execute('show innodb status');
+        
+        if (isset($savem)) $this->conn->SetFetchMode($savem);
+        $ADODB_FETCH_MODE = $save;
+        
+        if (!$rs || $rs->EOF) return 0;
+        $stat = $rs->fields[0];
+        $rs->Close();
+        $at = strpos($stat,'Buffer pool hit rate');
+        $stat = substr($stat,$at,200);
+        if (preg_match('!Buffer pool hit rate\s*([0-9]*) / ([0-9]*)!',$stat,$arr)) {
+            $val = 100*$arr[1]/$arr[2];
+            $_SESSION['INNODB_HIT_PCT'] = $val;
+            return round($val,2);
+        } else {
+            if (isset($_SESSION['INNODB_HIT_PCT'])) return $_SESSION['INNODB_HIT_PCT'];
+            return 0;
+        }
+    }
+    
+    function GetKeyHitRatio()
+    {
+        $hits = $this->_DBParameter(array("show status","Key_read_requests"));
+        $reqs = $this->_DBParameter(array("show status","Key_reads"));
+        if ($reqs == 0) return 0;
+        
+        return round(($hits/($reqs+$hits))*100,2);
+    }
+    
     // start hack 
     var $optimizeTableLow = 'CHECK TABLE %s FAST QUICK';
     var $optimizeTableHigh = 'OPTIMIZE TABLE %s';
@@ -312,4 +311,4 @@ class perf_mysql extends adodb_perf{
      }
     // end hack 
 }
-?>
\ No newline at end of file
+?>
index 56d420f097566e455083a39418aa6ed2ecddab01..65aebef5be6a49b48af92a5924a73354e9c40ca8 100644 (file)
@@ -587,18 +587,18 @@ function map_attrs($k, $v) {
 // courtesy, Ryan Currie, ryan@digibliss.com
 
 if (!function_exists('array_change_key_case')) {
-       define("CASE_UPPER",1);
-       define("CASE_LOWER",0);
+    define("CASE_UPPER",1);
+    define("CASE_LOWER",0);
 
 
-       function array_change_key_case($array,$case=CASE_LOWER) {
-       if ($case=CASE_LOWER) $cmd=strtolower;
-       elseif ($case=CASE_UPPER) $cmd=strtoupper;
+    function array_change_key_case($array,$case=CASE_LOWER) {
+       if ($case == CASE_LOWER) $cmd=strtolower;
+       elseif ($case == CASE_UPPER) $cmd=strtoupper;
        foreach($array as $key=>$value) {
                $output[$cmd($key)]=$value;
        }
        return $output;
-       }
+    }
 
 }
 
index dcb3a65af71adc0e49307bc1bdff956f433c05c8..b4c1b81d51548892d3a7765889eb1538d77a8dc3 100644 (file)
@@ -67,7 +67,7 @@
         // Handles the case of another Moodle site linking into a page on this site
         //TODO: move weblink into own auth plugin
         include($CFG->dirroot.'/login/weblinkauth.php');
-        if (function_exists(weblink_auth)) {
+        if (function_exists('weblink_auth')) {
             $user = weblink_auth($SESSION->wantsurl);
         }
         if ($user) {
index 7068d02260f76515b7e0e2596a2cc8c263f8a678..e13bc76207858b7270d53f0a5c3dccf364181622 100644 (file)
@@ -108,7 +108,7 @@ function importmodifiedaikenstyle($filename) {
             // make entry followed by '.'
             $line[1]='.';
         }
-        elseif ( ($responses AND $answer_found) OR (count(outlines)<=1) ) {
+        elseif ( ($responses AND $answer_found) OR (count($outlines)<=1) ) {
         // we have found responses and an answer and the current line is not an answer
             switch ($line[0]) {
                 case 1:
index e63abaad939c63bdc7e9b4528de980213f3ca965..af0fa10b68e129f1c6c19c71d1c7983f765b4412 100644 (file)
@@ -736,7 +736,7 @@ class resource_file extends resource_base {
 
         if (!empty($this->resource->reference) && file_exists($CFG->dirroot ."/mod/resource/type/file/externserverfile.php")) {
             include $CFG->dirroot ."/mod/resource/type/file/externserverfile.php";
-            if (function_exists(extern_server_file)) {
+            if (function_exists('extern_server_file')) {
                 return extern_server_file($this->resource->reference);
             }
         }
index 631d628040bad4947261ad9e9258aac11addf511..af7eda5b82f89255861faa89978a538ee975dd08 100644 (file)
                 $moresubmanifests = ims_extract_submanifests($submanifest['#']);
             /// Add them to results array
                 if (!empty($moresubmanifests)) {
-                    $submanifest_object->childs = moresubmanifests;
+                    $submanifest_object->childs = $moresubmanifests;
                 }
             /// Add submanifest object to results array
                 $submanifests[] = $submanifest_object;
index 4aae690db32468b21738a29964a5b046074de091..a206699866a3cab84e289429dd1691e3846d24b4 100644 (file)
                 $moresubmanifests = ims_extract_submanifests($submanifest['#']);
             /// Add them to results array
                 if (!empty($moresubmanifests)) {
-                    $submanifest_object->childs = moresubmanifests;
+                    $submanifest_object->childs = $moresubmanifests;
                 }
             /// Add submanifest object to results array
                 $submanifests[] = $submanifest_object;
index 8fb2e4f90871db47bc883e2570288e0a313e34e4..dc665510af871e0ab0ae96b63b17c6fec079d855 100644 (file)
@@ -498,7 +498,7 @@ function set_encrypted_parameter() {
 
     if (!empty($this->resource->reference) && file_exists($CFG->dirroot ."/mod/resource/type/file/externserverfile.php")) {
         include $CFG->dirroot ."/mod/resource/type/file/externserverfile.php";
-        if (function_exists(extern_server_file)) {
+        if (function_exists('extern_server_file')) {
             return extern_server_file($this->resource->reference);
         }
     }
index 4eee118373f68068359a2608a4f9cc1a63b104cc..a06cddb0d7b3ff15a7c838507c08bec7fc654ef2 100755 (executable)
@@ -13,13 +13,13 @@ function scorm_seq_overall ($scoid,$userid,$request,$attempt) {
         }
         if ($seq->sequencing != null) {
             $seq = scorm_seq_sequencing($scoid,$userid,$seq);
-                       if($seq->sequencing == 'exit'){//return the control to the LTS
-                               return 'true';
-                       }
+            if($seq->sequencing == 'exit'){//return the control to the LTS
+                return 'true';
+            }
         }
         if ($seq->delivery != null) {
             $seq = scorm_sequencing_delivery($scoid,$userid,$seq);
-                       $seq = scorm_content_delivery_environment ($seq,$userid);
+            $seq = scorm_content_delivery_environment ($seq,$userid);
         }
     }
     if ($seq->exception != null) {
@@ -35,24 +35,24 @@ function scorm_seq_navigation ($scoid,$userid,$request,$attempt=0) {
     /// Sequencing structure
     $seq = new stdClass();
     $seq->currentactivity = scorm_get_sco($scoid);
-       $seq->traversaldir = null;
-       $seq->nextactivity = null;
-       $seq->deliveryvalid = null;
-       $seq->attempt = $attempt;
-       
-       $seq->identifiedactivity = null;
-       $seq->delivery = null;
-       $seq->deliverable = false;
+    $seq->traversaldir = null;
+    $seq->nextactivity = null;
+    $seq->deliveryvalid = null;
+    $seq->attempt = $attempt;
+    
+    $seq->identifiedactivity = null;
+    $seq->delivery = null;
+    $seq->deliverable = false;
     $seq->active = scorm_seq_is('active',$scoid,$userid);
     $seq->suspended = scorm_seq_is('suspended',$scoid,$userid);
     $seq->navigation = null;
     $seq->termination = null;
     $seq->sequencing = null;
     $seq->target = null;
-       $seq->endsession = null;
+    $seq->endsession = null;
     $seq->exception = null;
-       $seq->reachable = true;
-       $seq->prevact = true;
+    $seq->reachable = true;
+    $seq->prevact = true;
 
     switch ($request) {
         case 'start_':
@@ -81,10 +81,10 @@ function scorm_seq_navigation ($scoid,$userid,$request,$attempt=0) {
                 $sco = $seq->currentactivity;
                 if ($sco->parent != '/') {
                     if ($parentsco = scorm_get_parent($sco)) {
-                                               
-                                                if (isset($parentsco->flow) && ($parentsco->flow == true)) {//I think it's parentsco
+                        
+                         if (isset($parentsco->flow) && ($parentsco->flow == true)) {//I think it's parentsco
                             // Current activity is active !
-                                                       if (scorm_seq_is('active',$sco->id,$userid)) {
+                            if (scorm_seq_is('active',$sco->id,$userid)) {
                                 if ($request == 'continue_') {
                                     $seq->navigation = true;
                                     $seq->termination = 'exit';
@@ -98,7 +98,7 @@ function scorm_seq_navigation ($scoid,$userid,$request,$attempt=0) {
                                         $seq->exception = 'NB.2.1-5'; /// Violates control mode
                                     }
                                 }
-                                                       }
+                            }
                         }
 
                     }
@@ -235,7 +235,7 @@ function scorm_seq_termination ($seq,$userid) {
             }
             /// Terminate Descendent Attempts Process
 
-                       
+            
             if ($ancestors = scorm_get_ancestors($sco)) { 
                 foreach ($ancestors as $ancestor) {
                     scorm_seq_end_attempt($ancestor,$userid,$seq);
@@ -245,7 +245,7 @@ function scorm_seq_termination ($seq,$userid) {
 
             $seq->active = scorm_seq_is('active',$seq->currentactivity->id,$userid);
             $seq->termination = true;
-                       $seq->sequencing = exit;
+            $seq->sequencing = exit;
         break;
         case 'suspendall':
             if (($seq->active) || ($seq->suspended)) {
@@ -391,7 +391,7 @@ function scorm_seq_exit_action_rules($seq,$userid) {
         /// Terminate Descendent Attempts Process
         if ($commons) { 
             foreach ($commons as $ancestor) {
-                               
+                
                 scorm_seq_end_attempt($ancestor,$userid,$seq->attempt);
                 $seq->currentactivity = $ancestor;
             }
@@ -427,65 +427,65 @@ function scorm_seq_post_cond_rules($seq,$userid) {
 function scorm_seq_rules_check ($sco, $action){
     global $DB;
 
-       $act = null;
-       if($rules = $DB->get_records('scorm_seq_ruleconds', array('scoid'=>$sco->id,'action'=>$action))) {
-               foreach ($rules as $rule){
-                       if($act = scorm_seq_rule_check($sco,$rule)){
-                               return $act;
-                       }
-               }
-       }
-       return $act;
+    $act = null;
+    if($rules = $DB->get_records('scorm_seq_ruleconds', array('scoid'=>$sco->id,'action'=>$action))) {
+        foreach ($rules as $rule){
+            if($act = scorm_seq_rule_check($sco,$rule)){
+                return $act;
+            }
+        }
+    }
+    return $act;
 
 }
 
 function scorm_seq_rule_check ($sco, $rule){
     global $DB;
 
-       $bag = Array();
-       $cond = '';
-       $ruleconds = $DB->get_records('scorm_seq_rulecond', array('scoid'=>$sco->id,'ruleconditionsid'=>$rule->id));
-       foreach ($ruleconds as $rulecond){
-                if ($rulecond->operator = 'not') {
-                    if ($rulecond->cond != 'unknown' ){
-                               $rulecond->cond = 'not'.$rulecond;
-                        }
-                }
-                $bag [$rule->id] = $rulecond->cond;
+    $bag = Array();
+    $cond = '';
+    $ruleconds = $DB->get_records('scorm_seq_rulecond', array('scoid'=>$sco->id,'ruleconditionsid'=>$rule->id));
+    foreach ($ruleconds as $rulecond){
+         if ($rulecond->operator = 'not') {
+             if ($rulecond->cond != 'unknown' ){
+                $rulecond->cond = 'not'.$rulecond;
+             }
+         }
+         $bag [$rule->id] = $rulecond->cond;
     
-       }
-       if (empty($bag)){
-               $cond = 'unknown';
-               return $cond;
-       }
-
-       $size= sizeof($bag);
-       $i=0;
-
-       if ($rule->conditioncombination = 'all'){
-               foreach ($bag as $con){
-                           $cond = $cond.' and '.$con;
-                       
-               }
-       }
-       else{
-               foreach ($bag as $con){
-                       $cond = $cond.' or '.$con;
-               }
-       }
-       return $cond;
+    }
+    if (empty($bag)){
+        $cond = 'unknown';
+        return $cond;
+    }
+
+    $size= sizeof($bag);
+    $i=0;
+
+    if ($rule->conditioncombination = 'all'){
+        foreach ($bag as $con){
+                $cond = $cond.' and '.$con;
+            
+        }
+    }
+    else{
+        foreach ($bag as $con){
+            $cond = $cond.' or '.$con;
+        }
+    }
+    return $cond;
 }
 
 
 function scorm_seq_overall_rollup($sco,$userid){//Carlos
 
-        if ($ancestors = scorm_get_ancestors($sco)) { 
+     if ($ancestors = scorm_get_ancestors($sco)) { 
             foreach ($ancestors as $ancestor) {
-                               if(!scorm_is_leaf($ancestor)){
-                                       scorm_seq_measure_rollup($sco,$userid);
-                               }
-                               scorm_seq_objective_rollup($sco,$userid);
-                               scorm_seq_activity_progress_rollup($sco,$userid);
+                if(!scorm_is_leaf($ancestor)){
+                    scorm_seq_measure_rollup($sco,$userid);
+                }
+                scorm_seq_objective_rollup($sco,$userid);
+                scorm_seq_activity_progress_rollup($sco,$userid);
 
             }
 
@@ -496,127 +496,127 @@ function scorm_seq_overall_rollup($sco,$userid){//Carlos
 
 function scorm_seq_measure_rollup($sco,$userid){
 
-       $totalmeasure = 0; //Check if there is something similar in the database
-       $valid = false;//Same as in the last line
-       $countedmeasures = 0;//Same too
-       $targetobjective = null;
-       $readable = true;//to check if status and measure weight are readable
-       $objectives = $DB->get_records('scorm_seq_objective', array('scoid'=>$sco->id));
+    $totalmeasure = 0; //Check if there is something similar in the database
+    $valid = false;//Same as in the last line
+    $countedmeasures = 0;//Same too
+    $targetobjective = null;
+    $readable = true;//to check if status and measure weight are readable
+    $objectives = $DB->get_records('scorm_seq_objective', array('scoid'=>$sco->id));
 
     foreach ($objectives as $objective){
 
-               if ($objective->primaryobj == true){//Objective contributes to rollup I'm using primaryobj field, but not 
-                   $targetobjective = $objective;
-                       break;
-               }
+        if ($objective->primaryobj == true){//Objective contributes to rollup I'm using primaryobj field, but not 
+            $targetobjective = $objective;
+            break;
+        }
 
-       }
+    }
 
-       if ($targetobjective != null){
-               $children = scorm_get_children($sco);
+    if ($targetobjective != null){
+        $children = scorm_get_children($sco);
         foreach ($children as $child){
-                   $child = scorm_get_sco ($child);
-                       if (!isset($child->tracked) || ($child->tracked == 1)){
-       
-                           $rolledupobjective = null;// we set the rolled up activity to undefined
-                               $objectives = $DB->get_records('scorm_seq_objective', array('scoid'=>$child->id));
+            $child = scorm_get_sco ($child);
+            if (!isset($child->tracked) || ($child->tracked == 1)){
+    
+                $rolledupobjective = null;// we set the rolled up activity to undefined
+                $objectives = $DB->get_records('scorm_seq_objective', array('scoid'=>$child->id));
                 foreach ($objectives as $objective){
-                           if ($objective->primaryobj == true){//Objective contributes to rollup I'm using primaryobj field, but not 
-                               $rolledupobjective = $objective;
-                                   break;
-                           }
-                   }
-                               if ($rolledupobjective != null){
+                    if ($objective->primaryobj == true){//Objective contributes to rollup I'm using primaryobj field, but not 
+                        $rolledupobjective = $objective;
+                        break;
+                    }
+                }
+                if ($rolledupobjective != null){
                     $child = scorm_get_sco($child->id);
-                               
-                                       $countedmeasures = $countedmeasures + ($child->measureweight);
-                                       if (!scorm_seq_is('objectivemeasurestatus',$sco->id,$userid)) {
-                                               $normalizedmeasure = $DB->get_record('scorm_scoes_track', array('scoid'=>$child->id,'userid'=>$userid,'element'=>'objectivenormalizedmeasure'));
-                                               $totalmeasure = $totalmeasure + (($normalizedmeasure->value) * ($child->measureweight));
-                                               $valid = true;
-                                       }
-
-                                       
+                
+                    $countedmeasures = $countedmeasures + ($child->measureweight);
+                    if (!scorm_seq_is('objectivemeasurestatus',$sco->id,$userid)) {
+                        $normalizedmeasure = $DB->get_record('scorm_scoes_track', array('scoid'=>$child->id,'userid'=>$userid,'element'=>'objectivenormalizedmeasure'));
+                        $totalmeasure = $totalmeasure + (($normalizedmeasure->value) * ($child->measureweight));
+                        $valid = true;
+                    }
+
+                    
                     
-                               }
-                   }
-               }
-
-                                                
-               if(!$valid){
-
-                       scorm_seq_set('objectivemeasurestatus',$sco->id,$userid,false);
-
-               }
-               else{
-                       if($countedmeasures>0){
-                               scorm_seq_set('objectivemeasurestatus',$sco->id,$userid);
-                               $val=$totalmeasure/$countedmeasures;
-                               scorm_seq_set('objectivenormalizedmeasure',$sco->id,$userid,$val);
-                       
-                       }
-                       else{
-                               scorm_seq_set('objectivemeasurestatus',$sco->id,$userid,false);
-                               
-                       }
-               }
-
-       }
-       
+                }
+            }
+        }
+
+                         
+        if(!$valid){
+
+            scorm_seq_set('objectivemeasurestatus',$sco->id,$userid,false);
+
+        }
+        else{
+            if($countedmeasures>0){
+                scorm_seq_set('objectivemeasurestatus',$sco->id,$userid);
+                $val=$totalmeasure/$countedmeasures;
+                scorm_seq_set('objectivenormalizedmeasure',$sco->id,$userid,$val);
+                
+            }
+            else{
+                scorm_seq_set('objectivemeasurestatus',$sco->id,$userid,false);
+                
+            }
+        }
+
+    }
+    
 }
 
 function scorm_seq_objective_rollup($sco,$userid){
     global $DB;
-       
+    
     scorm_seq_objective_rollup_measure($sco,$userid);
     scorm_seq_objective_rollup_rules($sco,$userid);
     scorm_seq_objective_rollup_default($sco,$userid);
 
 /*
-       if($targetobjective->satisfiedbymeasure){
-               scorm_seq_objective_rollup_measure($sco,$userid);
-       }
-       else{
-               if ((scorm_seq_rollup_rule_check($sco,$userid,'incomplete'))|| (scorm_seq_rollup_rule_check($sco,$userid,'completed'))){
-                       scorm_seq_objective_rollup_rules($sco,$userid);
-               }
-               else{
+    if($targetobjective->satisfiedbymeasure){
+        scorm_seq_objective_rollup_measure($sco,$userid);
+    }
+    else{
+        if ((scorm_seq_rollup_rule_check($sco,$userid,'incomplete'))|| (scorm_seq_rollup_rule_check($sco,$userid,'completed'))){
+            scorm_seq_objective_rollup_rules($sco,$userid);
+        }
+        else{
 
             $rolluprules = $DB->get_record('scorm_seq_rolluprule', array('scoid'=>$sco->id,'userid'=>$userid));
             foreach($rolluprules as $rolluprule){
                 $rollupruleconds = $DB->get_records('scorm_seq_rolluprulecond', array('rollupruleid'=>$rolluprule->id));
-                           foreach($rollupruleconds as $rolluprulecond){
+                foreach($rollupruleconds as $rolluprulecond){
                  
                     switch ($rolluprulecond->cond!='satisfied' && $rolluprulecond->cond!='completed' && $rolluprulecond->cond!='attempted'){
-                                                       
-                                                  scorm_seq_set('objectivesatisfiedstatus',$sco->id,$userid, false);
+                            
+                           scorm_seq_set('objectivesatisfiedstatus',$sco->id,$userid, false);
 
-                                       break;
-                               }
-                           }
+                        break;
+                    }
+                }
 
-       
-               }
-       }
-*/     
+    
+        }
+    }
+*/  
 }
 
 function scorm_seq_objective_rollup_measure($sco,$userid){
     global $DB;
 
-       $targetobjective = null;
-       
+    $targetobjective = null;
+    
 
-       $objectives = $DB->get_records('scorm_seq_objective', array('scoid'=>$sco->id));
+    $objectives = $DB->get_records('scorm_seq_objective', array('scoid'=>$sco->id));
     foreach ($objectives as $objective){
-           if ($objective->primaryobj == true){
-                   $targetobjective = $objective;
-                       break;
-               }
-       }
-       if ($targetobjective != null){
+        if ($objective->primaryobj == true){
+            $targetobjective = $objective;
+            break;
+        }
+    }
+    if ($targetobjective != null){
 
-               if($targetobjective->satisfiedbymeasure){
+        if($targetobjective->satisfiedbymeasure){
 
             
             if (!scorm_seq_is('objectiveprogressstatus',$sco->id,$userid)) {
@@ -625,454 +625,454 @@ function scorm_seq_objective_rollup_measure($sco,$userid){
                                 
             }
 
-                       else{
-                               if (scorm_seq_is('active',$sco->id,$userid)) {
-                                   $isactive = true;
-                               }
-                               else{
-                                       $isactive = false;
-                               }
-
-                               $normalizedmeasure = $DB->get_record('scorm_scoes_track', array('scoid'=>$sco->id,'userid'=>$userid,'element'=>'objectivenormalizedmeasure'));
-
-                               $sco = scorm_get_sco ($sco->id);
-
-                               if (!$isactive || ($isactive && (!isset($sco->measuresatisfactionifactive) || $sco->measuresatisfactionifactive == true))){
-                                   if($normalizedmeasure->value >= $targetobjective->minnormalizedmeasure){
-                                           scorm_seq_set('objectiveprogressstatus',$sco->id,$userid);
-                                           scorm_seq_set('objectivesatisfiedstatus',$sco->id,$userid);
-                                       }
-                                       else{
-                                           scorm_seq_set('objectiveprogressstatus',$sco->id,$userid);
-                                           scorm_seq_set('objectivesatisfiedstatus',$sco->id,$userid,false);
-                               }
-                           }
-                               else{
-
-                                       scorm_seq_set('objectiveprogressstatus',$sco->id,$userid,false);
-                               
-                           }
-                       }
-               }
-       }
+            else{
+                if (scorm_seq_is('active',$sco->id,$userid)) {
+                    $isactive = true;
+                }
+                else{
+                    $isactive = false;
+                }
+
+                $normalizedmeasure = $DB->get_record('scorm_scoes_track', array('scoid'=>$sco->id,'userid'=>$userid,'element'=>'objectivenormalizedmeasure'));
+
+                $sco = scorm_get_sco ($sco->id);
+
+                if (!$isactive || ($isactive && (!isset($sco->measuresatisfactionifactive) || $sco->measuresatisfactionifactive == true))){
+                    if($normalizedmeasure->value >= $targetobjective->minnormalizedmeasure){
+                        scorm_seq_set('objectiveprogressstatus',$sco->id,$userid);
+                        scorm_seq_set('objectivesatisfiedstatus',$sco->id,$userid);
+                    }
+                    else{
+                        scorm_seq_set('objectiveprogressstatus',$sco->id,$userid);
+                        scorm_seq_set('objectivesatisfiedstatus',$sco->id,$userid,false);
+                    }
+                }
+                else{
+
+                    scorm_seq_set('objectiveprogressstatus',$sco->id,$userid,false);
+                
+                }
+            }
+        }
+    }
 
 }
 
 function scorm_seq_objective_rollup_default($sco,$userid){
     global $DB;
 
-       if (!(scorm_seq_rollup_rule_check($sco,$userid,'incomplete')) && !(scorm_seq_rollup_rule_check($sco,$userid,'completed'))){
-               
+    if (!(scorm_seq_rollup_rule_check($sco,$userid,'incomplete')) && !(scorm_seq_rollup_rule_check($sco,$userid,'completed'))){
+        
             $rolluprules = $DB->get_record('scorm_seq_rolluprule', array('scoid'=>$sco->id,'userid'=>$userid));
             foreach($rolluprules as $rolluprule){
                 $rollupruleconds = $DB->get_records('scorm_seq_rolluprulecond', array('rollupruleid'=>$rolluprule->id));
-                           foreach($rollupruleconds as $rolluprulecond){
+                foreach($rollupruleconds as $rolluprulecond){
                  
                     if ($rolluprulecond->cond!='satisfied' && $rolluprulecond->cond!='completed' && $rolluprulecond->cond!='attempted'){
-                                                       
-                                                  scorm_seq_set('objectivesatisfiedstatus',$sco->id,$userid, false);
+                            
+                           scorm_seq_set('objectivesatisfiedstatus',$sco->id,$userid, false);
 
-                                       break;
-                               }
-                           }
+                        break;
+                    }
+                }
 
-       
+    
             }
-       }
-       
+    }
+    
 }
 
 
 function scorm_seq_objective_rollup_rules($sco,$userid){
     global $DB;
 
-       $targetobjective = null;
+    $targetobjective = null;
 
-       $objectives = $DB->get_records('scorm_seq_objective', array('scoid'=>$sco->id));
+    $objectives = $DB->get_records('scorm_seq_objective', array('scoid'=>$sco->id));
     foreach ($objectives as $objective){
-           if ($objective->primaryobj == true){//Objective contributes to rollup I'm using primaryobj field, but not 
-                   $targetobjective = $objective;
-                       break;
-               }
-       }
-       if ($targetobjective != null){
+        if ($objective->primaryobj == true){//Objective contributes to rollup I'm using primaryobj field, but not 
+            $targetobjective = $objective;
+            break;
+        }
+    }
+    if ($targetobjective != null){
 
         
 
-               if(scorm_seq_rollup_rule_check($sco,$userid,'notsatisfied')){//with not satisfied rollup for the activity
+        if(scorm_seq_rollup_rule_check($sco,$userid,'notsatisfied')){//with not satisfied rollup for the activity
 
-                  
-                       scorm_seq_set('objectiveprogressstatus',$sco->id,$userid);
-               scorm_seq_set('objectivesatisfiedstatus',$sco->id,$userid,false);
-               }
-               if(scorm_seq_rollup_rule_check($sco,$userid,'satisfied')){//with satisfied rollup for the activity
-                       scorm_seq_set('objectiveprogressstatus',$sco->id,$userid);
-               scorm_seq_set('objectivesatisfiedstatus',$sco->id,$userid);
-               }
+           
+            scorm_seq_set('objectiveprogressstatus',$sco->id,$userid);
+            scorm_seq_set('objectivesatisfiedstatus',$sco->id,$userid,false);
+        }
+        if(scorm_seq_rollup_rule_check($sco,$userid,'satisfied')){//with satisfied rollup for the activity
+            scorm_seq_set('objectiveprogressstatus',$sco->id,$userid);
+            scorm_seq_set('objectivesatisfiedstatus',$sco->id,$userid);
+        }
 
-       }
+    }
 
 }
 
 function scorm_seq_activity_progress_rollup ($sco, $userid){
 
-       if(scorm_seq_rollup_rule_check($sco,$userid,'incomplete')){
-               //incomplete rollup action
-               scorm_seq_set('attemptcompletionstatus',$sco->id,$userid,false,$seq->attempt);
-               scorm_seq_set('attemptprogressstatus',$sco->id,$userid,true,$seq->attempt);
+    if(scorm_seq_rollup_rule_check($sco,$userid,'incomplete')){
+        //incomplete rollup action
+        scorm_seq_set('attemptcompletionstatus',$sco->id,$userid,false,$seq->attempt);
+        scorm_seq_set('attemptprogressstatus',$sco->id,$userid,true,$seq->attempt);
 
-       }
+    }
     if(scorm_seq_rollup_rule_check($sco,$userid,'completed')){
-               //incomplete rollup action
-               scorm_seq_set('attemptcompletionstatus',$sco->id,true,$userid);
-               scorm_seq_set('attemptprogressstatus',$sco->id,true,$userid);
-       }
+        //incomplete rollup action
+        scorm_seq_set('attemptcompletionstatus',$sco->id,true,$userid);
+        scorm_seq_set('attemptprogressstatus',$sco->id,true,$userid);
+    }
 
 }
 
 function scorm_seq_rollup_rule_check ($sco,$userid,$action){
     global $DB;
 
-        if($rolluprules = $DB->get_record('scorm_seq_rolluprule', array('scoid'=>$sco->id,'userid'=>$userid,'action'=>$action))) {
+     if($rolluprules = $DB->get_record('scorm_seq_rolluprule', array('scoid'=>$sco->id,'userid'=>$userid,'action'=>$action))) {
 
         $childrenbag = Array ();
-               $children = scorm_get_children ($sco);
+        $children = scorm_get_children ($sco);
 
-               foreach($rolluprules as $rolluprule){
+        foreach($rolluprules as $rolluprule){
 
-                       foreach ($children as $child){
+            foreach ($children as $child){
 
-                               /*$tracked = $DB->get_records('scorm_scoes_track', array('scoid'=>$child->id,'userid'=>$userid));
-                           if($tracked && $tracked->attemp != 0){*/
-                                $child = scorm_get_sco ($child);
-                       if (!isset($child->tracked) || ($child->tracked == 1)){
+                /*$tracked = $DB->get_records('scorm_scoes_track', array('scoid'=>$child->id,'userid'=>$userid));
+                if($tracked && $tracked->attemp != 0){*/
+                 $child = scorm_get_sco ($child);
+            if (!isset($child->tracked) || ($child->tracked == 1)){
 
-                                       if(scorm_seq_check_child ($child,$action,$userid)){
+                    if(scorm_seq_check_child ($child,$action,$userid)){
 
                         $rollupruleconds = $DB->get_records('scorm_seq_rolluprulecond', array('rollupruleid'=>$rolluprule->id));
-                                               $evaluate = scorm_seq_evaluate_rollupcond($child,$rolluprule->conditioncombination,$rollupruleconds,$userid);
-                                               if ($evaluate=='unknown'){
-                                                       array_push($childrenbag,'unknown');
-                                               }
-                                               else{
-                                                       if($evaluate == true){
-                                                               array_push($childrenbag,true);
-                                                       }
-                                                       else{
-                                                               array_push($childrenbag,false);
-                                                       }
-                                               }
-                                       }
-                               }
-                               
-                       }
-                       $change = false;
-
-                       switch ($rolluprule->childactivityset){
-
-                               case 'all':
-                                       if((array_search(false,$childrenbag)===false)&&(array_search('unknown',$childrenbag)===false)){//I think I can use this condition instead equivalent to OR
-                                           $change = true;
-                                   }
-                               break;
-
-                               case 'any':
-                                       if(array_search(true,$childrenbag)!==false){//I think I can use this condition instead equivalent to OR
-                                           $change = true;
-                                   }
-                               break;
-
-                               case 'none':
-                                       if((array_search(true,$childrenbag)===false)&&(array_search('unknown',$childrenbag)===false)){//I think I can use this condition instead equivalent to OR
-                                           $change = true;
-                                   }
-                               break;
-
-                               case 'atleastcount':
-                                       foreach ($childrenbag as $itm){//I think I can use this condition instead equivalent to OR
-                                       $cont = 0;
-                                       if($itm === true){
-                                                       $cont++;
-                                               }
-                                               if($cont >= $roullprule->minimumcount){
-                                               $change = true;
-                                       }
-                                   }
-                               break;
-
-                               case 'atleastcount':
-                                       foreach ($childrenbag as $itm){//I think I can use this condition instead equivalent to OR
-                                       $cont = 0;
-                                       if($itm === true){
-                                                       $cont++;
-                                               }
-                                               if($cont >= $roullprule->minimumcount){
-                                               $change = true;
-                                       }
-                                   }
-                               break;
-
-                               case 'atleastpercent':
-                                       foreach ($childrenbag as $itm){//I think I can use this condition instead equivalent to OR
-                                       $cont = 0;
-                                       if($itm === true){
-                                                       $cont++;
-                                               }
-                                               if(($cont/sizeof($childrenbag)) >= $roullprule->minimumcount){
-                                               $change = true;
-                                       }
-                                   }
-                               break;
-                       }
-                       if ($change==true){
-                               return true;
-                       }
-               }
-        }
-        return false;
+                        $evaluate = scorm_seq_evaluate_rollupcond($child,$rolluprule->conditioncombination,$rollupruleconds,$userid);
+                        if ($evaluate=='unknown'){
+                            array_push($childrenbag,'unknown');
+                        }
+                        else{
+                            if($evaluate == true){
+                                array_push($childrenbag,true);
+                            }
+                            else{
+                                array_push($childrenbag,false);
+                            }
+                        }
+                    }
+                }
+                
+            }
+            $change = false;
+
+            switch ($rolluprule->childactivityset){
+
+                case 'all':
+                    if((array_search(false,$childrenbag)===false)&&(array_search('unknown',$childrenbag)===false)){//I think I can use this condition instead equivalent to OR
+                        $change = true;
+                    }
+                break;
+
+                case 'any':
+                    if(array_search(true,$childrenbag)!==false){//I think I can use this condition instead equivalent to OR
+                        $change = true;
+                    }
+                break;
+
+                case 'none':
+                    if((array_search(true,$childrenbag)===false)&&(array_search('unknown',$childrenbag)===false)){//I think I can use this condition instead equivalent to OR
+                        $change = true;
+                    }
+                break;
+
+                case 'atleastcount':
+                    foreach ($childrenbag as $itm){//I think I can use this condition instead equivalent to OR
+                        $cont = 0;
+                        if($itm === true){
+                            $cont++;
+                        }
+                        if($cont >= $roullprule->minimumcount){
+                            $change = true;
+                        }
+                    }
+                break;
+
+                case 'atleastcount':
+                    foreach ($childrenbag as $itm){//I think I can use this condition instead equivalent to OR
+                        $cont = 0;
+                        if($itm === true){
+                            $cont++;
+                        }
+                        if($cont >= $roullprule->minimumcount){
+                            $change = true;
+                        }
+                    }
+                break;
+
+                case 'atleastpercent':
+                    foreach ($childrenbag as $itm){//I think I can use this condition instead equivalent to OR
+                        $cont = 0;
+                        if($itm === true){
+                            $cont++;
+                        }
+                        if(($cont/sizeof($childrenbag)) >= $roullprule->minimumcount){
+                            $change = true;
+                        }
+                    }
+                break;
+            }
+            if ($change==true){
+                return true;
+            }
+        }
+     }
+     return false;
 }
 
 
 function scorm_seq_evaluate_rollupcond($sco,$conditioncombination,$rollupruleconds,$userid){
-       $bag = Array();
+    $bag = Array();
     $con = "";
-       $val = false;
-       $unk = false;
+    $val = false;
+    $unk = false;
     foreach($rollupruleconds as $rolluprulecond){
 
-               $condit = scorm_evaluate_cond($rolluprulecond,$sco,$userid);
-
-               if($rule->operator=='not'){// If operator is not, negate the condition
-                       if ($rule->cond != 'unknown'){            
-                               if ($condit){
-                                       $condit = false;
-                               }
-                               else{
-                                       $condit = true;
-                               }
-                       }
-                       else{
-                               $condit = 'unknown';
-                   }
-                       array_push($childrenbag,$condit);
-               }
-
-       }
-       if (empty($bag)){
-               return 'unknown';
-       }
-       else{
-               $i = 0;
-               foreach ($bag as $b){
-
-                        if ($rolluprule->conditioncombination == 'all'){
-
-                                $val = true;
-                                if($b == 'unknown'){
-                                        $unk = true;
-                                }
-                                if($b === false){
-                                        return false;
-                                }
-                        }
-
-                        else{
+        $condit = scorm_evaluate_cond($rolluprulecond,$sco,$userid);
+
+        if($rule->operator=='not'){// If operator is not, negate the condition
+            if ($rule->cond != 'unknown'){            
+                if ($condit){
+                    $condit = false;
+                }
+                else{
+                    $condit = true;
+                }
+            }
+            else{
+                $condit = 'unknown';
+            }
+            array_push($childrenbag,$condit);
+        }
+
+    }
+    if (empty($bag)){
+        return 'unknown';
+    }
+    else{
+        $i = 0;
+        foreach ($bag as $b){
+
+             if ($rolluprule->conditioncombination == 'all'){
+
+                 $val = true;
+                 if($b == 'unknown'){
+                     $unk = true;
+                 }
+                 if($b === false){
+                     return false;
+                 }
+             }
+
+             else{
 
                 $val = false;
-                                
-                               if($b == 'unknown'){
-                                        $unk = true;
-                               }
-                               if($b === true){
-                                       return true;
-                               }
-                        }
-
-
-               }
-       }
-       if ($unk){
-               return 'unknown';
-       }
-       return $val;
+                 
+                if($b == 'unknown'){
+                     $unk = true;
+                }
+                if($b === true){
+                    return true;
+                }
+             }
+
+
+        }
+    }
+    if ($unk){
+        return 'unknown';
+    }
+    return $val;
 
 }
 
 function scorm_evaluate_condition ($rolluprulecond,$sco,$userid){
     global $DB;
-       
-               $res = false;
+    
+            $res = false;
 
             switch ($rolluprulecond->cond){
-                               
-                               case 'satisfied':
-                                        if($r=$DB->get_record('scorm_scoes_track', array('scoid'=>$sco->id,'userid'=>$userid,'element'=>'objectivesatisfiedstatus'))) {
-                                               if($r->value == true){
-                                               if ($r=$DB->get_record('scorm_scoes_track', array('scoid'=>$sco->id,'userid'=>$userid,'element'=>'objectiveprogressstatus'))) {
-                                                       if($r->value == true){
-                                                      $res= true;
-                                                       }
-                                           }
-                                               }
-                                   }
-                               break;
-
-                               case 'objectiveStatusKnown':
+                
+                case 'satisfied':
+                     if($r=$DB->get_record('scorm_scoes_track', array('scoid'=>$sco->id,'userid'=>$userid,'element'=>'objectivesatisfiedstatus'))) {
+                        if($r->value == true){
+                            if ($r=$DB->get_record('scorm_scoes_track', array('scoid'=>$sco->id,'userid'=>$userid,'element'=>'objectiveprogressstatus'))) {
+                                if($r->value == true){
+                                   $res= true;
+                                }
+                            }
+                        }
+                    }
+                break;
+
+                case 'objectiveStatusKnown':
                     if ($r=$DB->get_record('scorm_scoes_track', array('scoid'=>$sco->id,'userid'=>$userid,'element'=>'objectiveprogressstatus'))) {
-                                               if($r->value == true){
-                                               $res= true;
-                                               }
-                                   }
-                               break;
-
-                               case 'objectiveMeasureKnown':
-                                       if ($r = $DB->get_record('scorm_scoes_track', array('scoid'=>$sco->id,'userid'=>$userid,'element'=>'objectivemeasurestatus'))) {
-                                           if($r->value == true){
-                                                       $res = true;
-                                               }
-       
-                                   }
-
-                               break;
-
-                               case 'completed':
-                                       if ($r = $DB->get_record('scorm_scoes_track', array('scoid'=>$sco->id,'userid'=>$userid,'element'=>'attemptcompletionstatus'))) {
-                                           if($r->value){
-                                                       if ($r = $DB->get_record('scorm_scoes_track', array('scoid'=>$sco->id,'userid'=>$userid,'element'=>'attemptprogressstatus'))) {
-                                                  if($r->value){
-                                                             $res = true;
-                                                      }
-       
-                                           }
-                                               }
-       
-                                   }
-                               break;
-
-                               case 'attempted':
-                                       if ($r = $DB->get_record('scorm_scoes_track', array('scoid'=>$sco->id,'userid'=>$userid,'element'=>'activityprogressstatus'))) {
-                                           if($r->value){
-                                                       if ($r = $DB->get_record('scorm_scoes_track', array('scoid'=>$sco->id,'userid'=>$userid,'element'=>'activityattemptcount'))) {
-                                                   if($r->value > 0){
-                                                               $res = true;
-                                                       }
-       
-                                           }
-                                               }
-       
-                                   }
-                               break;
-                               
-
-                               case 'attemptLimitExceeded':
-                                       if ($r = $DB->get_record('scorm_scoes_track', array('scoid'=>$sco->id,'userid'=>$userid,'element'=>'activityprogressstatus'))) {
-                                           if($r->value){
-                                                       if ($r = $DB->get_record('scorm_scoes_track', array('scoid'=>$sco->id,'userid'=>$userid,'element'=>'limitconditionattemptlimitcontrol'))) {
-                                                   if($r->value){
-                                                              if ($r = $DB->get_record('scorm_scoes_track', array('scoid'=>$sco->id,'userid'=>$userid,'element'=>'activityattemptcount')) && $r2 = $DB->get_record('scorm_scoes_track', array('scoid'=>$sco->id,'userid'=>$userid,'element'=>'limitconditionattemptlimit')) ){
-                                                          if($r->value >= $r2->value){
-                                                                      $res = true;
-                                                              }
-       
-                                                  }
-                                       
-                                                       }
-       
-                                           }
-                                       
-                                               }
-       
-                                   }
-                                       
-                               break;
-
-                               case 'activityProgressKnown':
-
-                                       if ($r = $DB->get_record('scorm_scoes_track', array('scoid'=>$sco->id,'userid'=>$userid,'element'=>'activityprogressstatus'))) {
-                                           if($r->value){
-                                               if ($r = $DB->get_record('scorm_scoes_track', array('scoid'=>$sco->id,'userid'=>$userid,'element'=>'attemptprogressstatus'))) {
-                                                   if($r->value){
-                                                               $res = true;
-                                                       }
-       
-                                           }
-                                       
-                                               }
-       
-                                   }
-                                       
-                               break;
-                       }
-                       return $res;
+                        if($r->value == true){
+                            $res= true;
+                        }
+                    }
+                break;
+
+                case 'objectiveMeasureKnown':
+                    if ($r = $DB->get_record('scorm_scoes_track', array('scoid'=>$sco->id,'userid'=>$userid,'element'=>'objectivemeasurestatus'))) {
+                        if($r->value == true){
+                            $res = true;
+                        }
+    
+                    }
+
+                break;
+
+                case 'completed':
+                    if ($r = $DB->get_record('scorm_scoes_track', array('scoid'=>$sco->id,'userid'=>$userid,'element'=>'attemptcompletionstatus'))) {
+                        if($r->value){
+                            if ($r = $DB->get_record('scorm_scoes_track', array('scoid'=>$sco->id,'userid'=>$userid,'element'=>'attemptprogressstatus'))) {
+                               if($r->value){
+                                  $res = true;
+                               }
+    
+                            }
+                        }
+    
+                    }
+                break;
+
+                case 'attempted':
+                    if ($r = $DB->get_record('scorm_scoes_track', array('scoid'=>$sco->id,'userid'=>$userid,'element'=>'activityprogressstatus'))) {
+                        if($r->value){
+                            if ($r = $DB->get_record('scorm_scoes_track', array('scoid'=>$sco->id,'userid'=>$userid,'element'=>'activityattemptcount'))) {
+                                if($r->value > 0){
+                                    $res = true;
+                                }
+    
+                            }
+                        }
+    
+                    }
+                break;
+                
+
+                case 'attemptLimitExceeded':
+                    if ($r = $DB->get_record('scorm_scoes_track', array('scoid'=>$sco->id,'userid'=>$userid,'element'=>'activityprogressstatus'))) {
+                        if($r->value){
+                            if ($r = $DB->get_record('scorm_scoes_track', array('scoid'=>$sco->id,'userid'=>$userid,'element'=>'limitconditionattemptlimitcontrol'))) {
+                                if($r->value){
+                                   if ($r = $DB->get_record('scorm_scoes_track', array('scoid'=>$sco->id,'userid'=>$userid,'element'=>'activityattemptcount')) && $r2 = $DB->get_record('scorm_scoes_track', array('scoid'=>$sco->id,'userid'=>$userid,'element'=>'limitconditionattemptlimit')) ){
+                                       if($r->value >= $r2->value){
+                                           $res = true;
+                                       }
+    
+                                   }
+                    
+                                }
+    
+                            }
+                    
+                        }
+    
+                    }
+                    
+                break;
+
+                case 'activityProgressKnown':
+
+                    if ($r = $DB->get_record('scorm_scoes_track', array('scoid'=>$sco->id,'userid'=>$userid,'element'=>'activityprogressstatus'))) {
+                        if($r->value){
+                            if ($r = $DB->get_record('scorm_scoes_track', array('scoid'=>$sco->id,'userid'=>$userid,'element'=>'attemptprogressstatus'))) {
+                                if($r->value){
+                                    $res = true;
+                                }
+    
+                            }
+                    
+                        }
+    
+                    }
+                    
+                break;
+            }
+            return $res;
 
 }
 
 function scorm_seq_check_child ($sco, $action, $userid){
     global $DB;
 
-       $included = false;
-       $sco=scorm_get_sco($sco->id);
-       $r = $DB->get_record('scorm_scoes_track', array('scoid'=>$sco->id,'userid'=>$userid,'element'=>'activityattemptcount'));
-       if ($action == 'satisfied' || $action == 'notsatisfied'){
-         if (!$sco->rollupobjectivesatisfied){
-               $included = true;
-               if (($action == 'satisfied' && $sco->requiredforsatisfied == 'ifnotsuspended') || ($action == 'notsatisfied' && $sco->requiredfornotsatisfied == 'ifnotsuspended')){
-                       
-                       if (!scorm_seq_is('activityprogressstatus',$sco->id,$userid) || ((($r->value)>0)&& !scorm_seq_is('suspended',$sco->id,$userid))){
-                               $included = false;
-                       }
-
-               }
-               else{
-                       if (($action == 'satisfied' && $sco->requiredforsatisfied == 'ifattempted') || ($action == 'notsatisfied' && $sco->requiredfornotsatisfied == 'ifattempted')){
-                           if (!scorm_seq_is('activityprogressstatus',$sco->id,$userid) || (($r->value) == 0)){
-                                   $included = false;
-                           }
+    $included = false;
+    $sco=scorm_get_sco($sco->id);
+    $r = $DB->get_record('scorm_scoes_track', array('scoid'=>$sco->id,'userid'=>$userid,'element'=>'activityattemptcount'));
+    if ($action == 'satisfied' || $action == 'notsatisfied'){
+      if (!$sco->rollupobjectivesatisfied){
+        $included = true;
+        if (($action == 'satisfied' && $sco->requiredforsatisfied == 'ifnotsuspended') || ($action == 'notsatisfied' && $sco->requiredfornotsatisfied == 'ifnotsuspended')){
+            
+            if (!scorm_seq_is('activityprogressstatus',$sco->id,$userid) || ((($r->value)>0)&& !scorm_seq_is('suspended',$sco->id,$userid))){
+                $included = false;
+            }
+
+        }
+        else{
+            if (($action == 'satisfied' && $sco->requiredforsatisfied == 'ifattempted') || ($action == 'notsatisfied' && $sco->requiredfornotsatisfied == 'ifattempted')){
+                if (!scorm_seq_is('activityprogressstatus',$sco->id,$userid) || (($r->value) == 0)){
+                    $included = false;
+                }
+            }
+            else{
+                if (($action == 'satisfied' && $sco->requiredforsatisfied == 'ifnotskipped') || ($action == 'notsatisfied' && $sco->requiredfornotsatisfied == 'ifnotskipped')){
+                    $rulch = scorm_seq_rules_check($sco, 'skip');
+                    if ($rulch != null){
+                        $included = false;
+                    }
+                }
             }
-                       else{
-                               if (($action == 'satisfied' && $sco->requiredforsatisfied == 'ifnotskipped') || ($action == 'notsatisfied' && $sco->requiredfornotsatisfied == 'ifnotskipped')){
-                                       $rulch = scorm_seq_rules_check($sco, 'skip');
-                                       if ($rulch != null){
-                                               $included = false;
-                                       }
-                           }
-                       }
-               }
+        }
       }
-       }
+    }
     if ($action == 'completed' || $action == 'incomplete'){
-               if (!$sco->rollupprogresscompletion){
-                   $included = true;
+        if (!$sco->rollupprogresscompletion){
+            $included = true;
 
             if (($action == 'completed' && $sco->requiredforcompleted == 'ifnotsuspended') || ($action == 'incomplete' && $sco->requiredforincomplete == 'ifnotsuspended')){
 
-                           if (!scorm_seq_is('activityprogressstatus',$sco->id,$userid) || ( (($r->value)>0)&& !scorm_seq_is('suspended',$sco->id,$userid))){
-                                   $included = false;
-                           }
-
-                   }
-                       else{
-                               
-                               if (($action == 'completed' && $sco->requiredforcompleted == 'ifattempted') || ($action == 'incomplete' && $sco->requiredforincomplete == 'ifattempted')){
-                               if (!scorm_seq_is('activityprogressstatus',$sco->id,$userid) || (($r->value)==0)){
-                                       $included = false;
-                               }
-
-                       }
-                               else{
-                                       if (($action == 'completed' && $sco->requiredforsatisfied == 'ifnotskipped') || ($action == 'incomplete' && $sco->requiredfornotsatisfied == 'ifnotskipped')){
-                                           $rulch = scorm_seq_rules_check($sco, 'skip');
-                                           if ($rulch != null){
-                                                   $included = false;
-                                           }
-                               }
-                               }
-
-
-                       }
-
-               }
-       }
+                if (!scorm_seq_is('activityprogressstatus',$sco->id,$userid) || ( (($r->value)>0)&& !scorm_seq_is('suspended',$sco->id,$userid))){
+                    $included = false;
+                }
+
+            }
+            else{
+                
+                if (($action == 'completed' && $sco->requiredforcompleted == 'ifattempted') || ($action == 'incomplete' && $sco->requiredforincomplete == 'ifattempted')){
+                    if (!scorm_seq_is('activityprogressstatus',$sco->id,$userid) || (($r->value)==0)){
+                        $included = false;
+                    }
+
+                }
+                else{
+                    if (($action == 'completed' && $sco->requiredforsatisfied == 'ifnotskipped') || ($action == 'incomplete' && $sco->requiredfornotsatisfied == 'ifnotskipped')){
+                        $rulch = scorm_seq_rules_check($sco, 'skip');
+                        if ($rulch != null){
+                            $included = false;
+                        }
+                    }
+                }
+
+
+            }
+
+        }
+    }
     return $included;
 
 
@@ -1083,23 +1083,23 @@ function scorm_seq_sequencing ($scoid,$userid,$seq) {
 
         case 'start':
         //TODO: undefined $sco!
-                        $seq = scorm_seq_start_sequencing($sco,$userid,$seq); //We'll see the parameters we have to send, this should update delivery and end
-                       $seq->sequencing = true;
+             $seq = scorm_seq_start_sequencing($sco,$userid,$seq); //We'll see the parameters we have to send, this should update delivery and end
+            $seq->sequencing = true;
            
-                       
-                   break;
-                       
+            
+            break;
+            
         case 'resumeall':
-                       $seq = scorm_seq_resume_sequencing($sco,$userid,$seq); //We'll see the parameters we have to send, this should update delivery and end
-                       $seq->sequencing = true;
-                       
-                   
+            $seq = scorm_seq_resume_sequencing($sco,$userid,$seq); //We'll see the parameters we have to send, this should update delivery and end
+            $seq->sequencing = true;
+            
+            
           
             break;
 
         case 'exit':
-                        $seq = scorm_seq_exit_sequencing($sco,$userid,$seq); //We'll see the parameters we have to send, this should update delivery and end
-                       $seq->sequencing = true;
+             $seq = scorm_seq_exit_sequencing($sco,$userid,$seq); //We'll see the parameters we have to send, this should update delivery and end
+            $seq->sequencing = true;
 
            
           
@@ -1108,32 +1108,32 @@ function scorm_seq_sequencing ($scoid,$userid,$seq) {
         case 'retry':
             $seq = scorm_seq_retry_sequencing($sco,$userid,$seq); //We'll see the parameters we have to send, this should update delivery and end
             $seq->sequencing = true;
-                       
+            
           
             break;
 
-               case 'previous':
-                       $seq = scorm_seq_previous_sequencing($sco,$userid,$seq);// We'll see the parameters we have to send, this should update delivery and end
-                       $seq->sequencing = true;
+        case 'previous':
+            $seq = scorm_seq_previous_sequencing($sco,$userid,$seq);// We'll see the parameters we have to send, this should update delivery and end
+            $seq->sequencing = true;
 
          
             break;
 
-               case 'choice':
-                       $seq = scorm_seq_choice_sequencing($sco,$userid,$seq);// We'll see the parameters we have to send, this should update delivery and end
+        case 'choice':
+            $seq = scorm_seq_choice_sequencing($sco,$userid,$seq);// We'll see the parameters we have to send, this should update delivery and end
              $seq->sequencing = true; 
-                        
+             
       
-                   break;
+            break;
 
     }
 
-       if ($seq->exception != null){
-               $seq->sequencing = false;
-               return $seq;
-       }
-       
-       $seq->sequencing= true;
+    if ($seq->exception != null){
+        $seq->sequencing = false;
+        return $seq;
+    }
+    
+    $seq->sequencing= true;
     return $seq;
 }
 
@@ -1141,383 +1141,383 @@ function scorm_seq_sequencing ($scoid,$userid,$seq) {
 function scorm_seq_start_sequencing($scoid,$userid,$seq){
     global $DB;
 
-       if (!empty($seq->currentactivity)) {
-               $seq->delivery = null;
-               $seq->exception = 'SB.2.5-1';
-               return $seq;
-       }
-       $sco = $DB->get_record('scorm_scoes', array('scoid'=>$scoid,'userid'=>$userid));
-       if (($sco->parent == '/') && scorm_is_leaf($sco)) {//if the activity is the root and is leaf
-               $seq->delivery = $sco;
-       }
-       else{
-               $ancestors = scorm_get_ancestors($sco);
-               $ancestorsroot = array_reverse($ancestors);
-               $res = scorm_seq_flow($ancestorsroot[0],'forward',$seq,true,$userid);
-               if($res){
-                       return $res;
-               }
-               else{
-                       //return end and exception
-               }
-       }
+    if (!empty($seq->currentactivity)) {
+        $seq->delivery = null;
+        $seq->exception = 'SB.2.5-1';
+        return $seq;
+    }
+    $sco = $DB->get_record('scorm_scoes', array('scoid'=>$scoid,'userid'=>$userid));
+    if (($sco->parent == '/') && scorm_is_leaf($sco)) {//if the activity is the root and is leaf
+        $seq->delivery = $sco;
+    }
+    else{
+        $ancestors = scorm_get_ancestors($sco);
+        $ancestorsroot = array_reverse($ancestors);
+        $res = scorm_seq_flow($ancestorsroot[0],'forward',$seq,true,$userid);
+        if($res){
+            return $res;
+        }
+        else{
+            //return end and exception
+        }
+    }
 }
 
 function scorm_seq_resume_all_sequencing($scoid,$userid,$seq){
     global $DB;
 
-       if (!empty($seq->currentactivity)){
-               $seq->delivery = null;
-               $seq->exception = 'SB.2.6-1';
-               return $seq;
-       }
-       $track = $DB->get_record('scorm_scoes_track', array('scoid'=>$scoid,'userid'=>$userid,'element'=>'suspendedactivity'));
+    if (!empty($seq->currentactivity)){
+        $seq->delivery = null;
+        $seq->exception = 'SB.2.6-1';
+        return $seq;
+    }
+    $track = $DB->get_record('scorm_scoes_track', array('scoid'=>$scoid,'userid'=>$userid,'element'=>'suspendedactivity'));
     if (!$track) {
-               $seq->delivery = null;
-           $seq->exception = 'SB.2.6-2';
-           return $seq;
-       }
-       $seq->delivery = $DB->get_record('scorm_scoes', array('scoid'=>$scoid,'userid'=>$userid));//we assign the sco to the delivery
-       
+        $seq->delivery = null;
+        $seq->exception = 'SB.2.6-2';
+        return $seq;
+    }
+    $seq->delivery = $DB->get_record('scorm_scoes', array('scoid'=>$scoid,'userid'=>$userid));//we assign the sco to the delivery
+    
 }
 
 function scorm_seq_continue_sequencing($scoid,$userid,$seq){
-       if (empty($seq->currentactivity)) {
-               $seq->delivery = null;
-               $seq->exception = 'SB.2.7-1';
-               return $seq;
-       }
-       $currentact= $seq->currentactivity;
-       if ($currentact->parent != '/') {//if the activity is the root and is leaf
-           $parent = scorm_get_parent ($currentact);
-
-                if (!isset($parent->flow) || ($parent->flow == false)) {
-                       $seq->delivery = null;
-               $seq->exception = 'SB.2.7-2';
-               return $seq;
-               }
-
-               $res = scorm_seq_flow($currentact,'forward',$seq,false,$userid);
-               if($res){
-                       return $res;
-               }
-               else{
-                       //return end and exception
-               }
-
-       }
-}
-
-function scorm_seq_previous_sequencing($scoid,$userid,$seq){
-       if (empty($seq->currentactivity)) {
-               $seq->delivery = null;
-               $seq->exception = 'SB.2.8-1';
-               return $seq;
-       }
-       
-       $currentact= $seq->currentactivity;
-       if ($currentact->parent != '/') {//if the activity is the root and is leaf
-           $parent = scorm_get_parent ($activity); // TODO: undefined!!
-               if (!isset($parent->flow) || ($parent->flow == false)) {
-                       $seq->delivery = null;
-               $seq->exception = 'SB.2.8-2';
-               return $seq;
-               }
-
-               $res = scorm_seq_flow($currentact,'backward',$seq,false,$userid);
-               if($res){
-                       return $res;
-               }
-               else{
-                       //return end and exception
-               }
-
-       }
+    if (empty($seq->currentactivity)) {
+        $seq->delivery = null;
+        $seq->exception = 'SB.2.7-1';
+        return $seq;
+    }
+    $currentact= $seq->currentactivity;
+    if ($currentact->parent != '/') {//if the activity is the root and is leaf
+        $parent = scorm_get_parent ($currentact);
+
+         if (!isset($parent->flow) || ($parent->flow == false)) {
+            $seq->delivery = null;
+            $seq->exception = 'SB.2.7-2';
+            return $seq;
+        }
+
+        $res = scorm_seq_flow($currentact,'forward',$seq,false,$userid);
+        if($res){
+            return $res;
+        }
+        else{
+            //return end and exception
+        }
+
+    }
+}
+
+function scorm_seq_previous_sequencing($scoid,$userid,$seq){
+    if (empty($seq->currentactivity)) {
+        $seq->delivery = null;
+        $seq->exception = 'SB.2.8-1';
+        return $seq;
+    }
+    
+    $currentact= $seq->currentactivity;
+    if ($currentact->parent != '/') {//if the activity is the root and is leaf
+        $parent = scorm_get_parent ($activity); // TODO: undefined!!
+        if (!isset($parent->flow) || ($parent->flow == false)) {
+            $seq->delivery = null;
+            $seq->exception = 'SB.2.8-2';
+            return $seq;
+        }
+
+        $res = scorm_seq_flow($currentact,'backward',$seq,false,$userid);
+        if($res){
+            return $res;
+        }
+        else{
+            //return end and exception
+        }
+
+    }
 
 }
 
 function scorm_seq_exit_sequencing($scoid,$userid,$seq){
-       if (empty($seq->currentactivity)) {
-               $seq->delivery = null;
-               $seq->exception = 'SB.2.11-1';
-               return $seq;
-       }
-
-        if ($seq->active){
-                $seq->endsession = false;
-                $seq->exception = 'SB.2.11-2';
-                return $seq;
-        }
-        $currentact= $seq->currentactivity;
-        if ($currentact->parent == '/'){
-                $seq->endsession = true;
-                return $seq;
-        }
-               
-       $seq->endsession = false;
-       return $seq;
+    if (empty($seq->currentactivity)) {
+        $seq->delivery = null;
+        $seq->exception = 'SB.2.11-1';
+        return $seq;
+    }
+
+     if ($seq->active){
+         $seq->endsession = false;
+         $seq->exception = 'SB.2.11-2';
+         return $seq;
+     }
+     $currentact= $seq->currentactivity;
+     if ($currentact->parent == '/'){
+         $seq->endsession = true;
+         return $seq;
+     }
+        
+    $seq->endsession = false;
+    return $seq;
 }
 
 
 function scorm_seq_retry_sequencing($scoid,$userid,$seq){
-       if (empty($seq->currentactivity)) {
-               $seq->delivery = null;
-               $seq->exception = 'SB.2.10-1';
-               return $seq;
-       }
-       if ($seq->active || $seq->suspended){
-               $seq->delivery = null;
-               $seq->exception = 'SB.2.10-2';
-               return $seq;
-       }
-       
-       if (!scorm_is_leaf($seq->currentactivity)){
-           $res = scorm_seq_flow($seq->currentactivity,'forward',$seq,true,$userid);
-               if($res != null){
-                       return $res;
-                       //return deliver
-               }
-               else{
-                       $seq->delivery = null;
-                   $seq->exception = 'SB.2.10-3';
-                   return $seq;
-               }
-       }
-       else{
-               $seq->delivery = $seq->currentactivity;
-               return $seq;
-       }
+    if (empty($seq->currentactivity)) {
+        $seq->delivery = null;
+        $seq->exception = 'SB.2.10-1';
+        return $seq;
+    }
+    if ($seq->active || $seq->suspended){
+        $seq->delivery = null;
+        $seq->exception = 'SB.2.10-2';
+        return $seq;
+    }
+    
+    if (!scorm_is_leaf($seq->currentactivity)){
+        $res = scorm_seq_flow($seq->currentactivity,'forward',$seq,true,$userid);
+        if($res != null){
+            return $res;
+            //return deliver
+        }
+        else{
+            $seq->delivery = null;
+            $seq->exception = 'SB.2.10-3';
+            return $seq;
+        }
+    }
+    else{
+        $seq->delivery = $seq->currentactivity;
+        return $seq;
+    }
 
 }
 
 function scorm_seq_flow ($candidate,$direction,$seq,$childrenflag,$userid){
-       //$PREVDIRECTION NOT DEFINED YET
-
-       $activity=$candidate;
-       $deliverable=false;
-       $previdirection = null;
-       $seq = scorm_seq_flow_tree_traversal ($activity,$direction,$childrenflag,$prevdirection,$seq,$userid); // TODO: undefined
-       if($seq->identifiedactivity == null){//if identifies
-               $seq->identifiedactivity = $candidate;
-               $seq->deliverable = false;
-               return $seq;
-       }
-       else{
-               $activity = $seq->identifiedactivity;
-               $seq = scorm_seq_flow_activity_traversal($activity,$userid,$direction,$childrenflag,$prevdirection,$seq,$userid);//
-               return $seq;
-
-       }
+    //$PREVDIRECTION NOT DEFINED YET
+
+    $activity=$candidate;
+    $deliverable=false;
+    $previdirection = null;
+    $seq = scorm_seq_flow_tree_traversal ($activity,$direction,$childrenflag,$prevdirection,$seq,$userid); // TODO: undefined
+    if($seq->identifiedactivity == null){//if identifies
+        $seq->identifiedactivity = $candidate;
+        $seq->deliverable = false;
+        return $seq;
+    }
+    else{
+        $activity = $seq->identifiedactivity;
+        $seq = scorm_seq_flow_activity_traversal($activity,$userid,$direction,$childrenflag,$prevdirection,$seq,$userid);//
+        return $seq;
+
+    }
 }
 
 function scorm_seq_flow_activity_traversal ($activity, $userid, $direction, $childrenflag, $prevdirection, $seq,$userid){//returns the next activity on the tree, traversal direction, control returned to the LTS, (may) exception
     $activity = scorm_get_sco ($activity);
     $parent = scorm_get_parent ($activity);
    if (!isset($parent->flow) || ($parent->flow == false)) {
-               $seq->deliverable = false;
-           $seq->exception = 'SB.2.2-1';
-               $seq->nextactivity = $activity;
-           return $seq;
-       }
+        $seq->deliverable = false;
+        $seq->exception = 'SB.2.2-1';
+        $seq->nextactivity = $activity;
+        return $seq;
+    }
      
     $rulch = scorm_seq_rules_check($sco, 'skipped'); // TODO: undefined
-       if ($rulch != null){
-           $seq = scorm_seq_flow_tree_traversal ($activity, $direction, false, $prevdirection, $seq,$userid);//endsession and exception
-               if ($seq->identifiedactivity == null){
-                       $seq->deliverable = false;
-                       $seq->nextactivity = $activity;
-                       return $seq;
-               }
-               else{
-                       
-                       if ($prevdirection = 'backward' && $seq->traversaldir == 'backward'){
-                               $seq = scorm_seq_flow_tree_traversal ($activity,$direction,false,null,$seq,$userid);
-                               $seq = scorm_seq_flow_activity($seq->identifiedactivity, $userid, $direction, $childrenflag, $prevdirection, $seq,$userid);
-                       }
-                       else{
-                               $seq = scorm_seq_flow_tree_traversal ($activity,$direction,false,null,$seq,$userid);
-                               $seq = scorm_seq_flow_activity($seq->identifiedactivity, $userid, $direction, $childrenflag, $prevdirection, $seq,$userid);
-                       }
-                       return $seq;
-               }
-       }
-
-       $ch=scorm_check_activity ($activity,$userid);
-
-       if ($ch){
-
-               $seq->deliverable = false;
-           $seq->exception = 'SB.2.2-2';
-               $seq->nextactivity = $activity;
-           return $seq;
-
-       }
-
-       if (!scorm_is_leaf($activity)){
-
-               $seq = scorm_seq_flow_tree_traversal ($activity,$direction,true,null,$seq,$userid);
-
-               if ($seq->identifiedactivity == null){
-                       $seq->deliverable = false;
-                       $seq->nextactivity = $activity;
-                       return $seq;
-               }
-
-               else{
-                   if($direction == 'backward' && $seq->traversaldir == 'forward'){
-                               $seq = scorm_seq_flow_activity($seq->identifiedactivity, $userid, 'forward', $childrenflag, 'backward', $seq,$userid);
-                       }
-                       else{
-                               scorm_seq_flow_activity($seq->identifiedactivity, $userid, $direction, $childrenflag, null, $seq,$userid);
-                       }
-                       return $seq;
-               }
-
-       }
+    if ($rulch != null){
+        $seq = scorm_seq_flow_tree_traversal ($activity, $direction, false, $prevdirection, $seq,$userid);//endsession and exception
+        if ($seq->identifiedactivity == null){
+            $seq->deliverable = false;
+            $seq->nextactivity = $activity;
+            return $seq;
+        }
+        else{
+            
+            if ($prevdirection = 'backward' && $seq->traversaldir == 'backward'){
+                $seq = scorm_seq_flow_tree_traversal ($activity,$direction,false,null,$seq,$userid);
+                $seq = scorm_seq_flow_activity($seq->identifiedactivity, $userid, $direction, $childrenflag, $prevdirection, $seq,$userid);
+            }
+            else{
+                $seq = scorm_seq_flow_tree_traversal ($activity,$direction,false,null,$seq,$userid);
+                $seq = scorm_seq_flow_activity($seq->identifiedactivity, $userid, $direction, $childrenflag, $prevdirection, $seq,$userid);
+            }
+            return $seq;
+        }
+    }
+
+    $ch=scorm_check_activity ($activity,$userid);
+
+    if ($ch){
+
+        $seq->deliverable = false;
+        $seq->exception = 'SB.2.2-2';
+        $seq->nextactivity = $activity;
+        return $seq;
+
+    }
+
+    if (!scorm_is_leaf($activity)){
+
+        $seq = scorm_seq_flow_tree_traversal ($activity,$direction,true,null,$seq,$userid);
+
+        if ($seq->identifiedactivity == null){
+            $seq->deliverable = false;
+            $seq->nextactivity = $activity;
+            return $seq;
+        }
+
+        else{
+            if($direction == 'backward' && $seq->traversaldir == 'forward'){
+                $seq = scorm_seq_flow_activity($seq->identifiedactivity, $userid, 'forward', $childrenflag, 'backward', $seq,$userid);
+            }
+            else{
+                scorm_seq_flow_activity($seq->identifiedactivity, $userid, $direction, $childrenflag, null, $seq,$userid);
+            }
+            return $seq;
+        }
+
+    }
 
     $seq->deliverable = true;
-       $seq->nextactivity = $activity;
+    $seq->nextactivity = $activity;
     return $seq;
 
 }
 function scorm_seq_flow_tree_traversal ($activity,$direction,$childrenflag,$prevdirection,$seq,$userid){
 
-       $revdirection = false;
-       $parent = scorm_get_parent ($activity);
-       $children = scorm_get_available_children ($parent);
-       $siz = sizeof ($children);
+    $revdirection = false;
+    $parent = scorm_get_parent ($activity);
+    $children = scorm_get_available_children ($parent);
+    $siz = sizeof ($children);
 
     if (($prevdirection != null && $prevdirection == 'backward') && ($children[$siz-1]->id == $activity->id)){
-               $direction = 'backward';
-               $children[0] = $activity;
-               $revdirection = true;
-       }
-
-       if($direction = 'forward'){
-               $ancestors = scorm_get_ancestors($activity);
-               $ancestorsroot = array_reverse($ancestors);
-               $preorder = scorm_get_preorder ($ancestorsroot);
-               $siz= sizeof ($preorder);
-               if (($activity->id == $preorder[$siz-1]->id) || (($activity->parent == '/') && !($childrenflag))){
-                       scorm_seq_terminate_descent($ancestorsroot,$userid);
-                       $seq->endsession = true;
-                       $seq->nextactivity = null;
-                       return $seq;
-               }
-               if (scorm_is_leaf ($activity) || !$childrenflag){
-                       if ($children[$siz-1]->id == $activity->id){
-       
-                               $seq = scorm_seq_flow_tree_traversal ($parent, $direction, false, null, $seq,$userid);
-                               // I think it's not necessary to do a return in here
-                       }
-                       else{
-                               $parent = scorm_get_parent($activity);
-                               $children = scorm_get_available_children($parent);
-                               $seq->traversaldir = $direction;
-                               $sib = scorm_get_siblings($activity);
-                               $pos = array_search($sib, $activity);
-                               if ($pos !== false) {
-                                   if ($pos != sizeof ($sib)){
-                                       $seq->nextactivity = $sib [$pos+1];
-                                               return $seq;
-                                   }
-                                   else{
-                                           $ch = scorm_get_children($sib[0]);
-                                           $seq->nextactivity = $ch[0];
-                                               return $seq;
-                                   }
-                               }
-                   }
-               }
-               else{
-                       if (!empty ($children)){
-                               $seq->traversaldir = $direction;
+        $direction = 'backward';
+        $children[0] = $activity;
+        $revdirection = true;
+    }
+
+    if($direction = 'forward'){
+        $ancestors = scorm_get_ancestors($activity);
+        $ancestorsroot = array_reverse($ancestors);
+        $preorder = scorm_get_preorder ($ancestorsroot);
+        $siz= sizeof ($preorder);
+        if (($activity->id == $preorder[$siz-1]->id) || (($activity->parent == '/') && !($childrenflag))){
+            scorm_seq_terminate_descent($ancestorsroot,$userid);
+            $seq->endsession = true;
+            $seq->nextactivity = null;
+            return $seq;
+        }
+        if (scorm_is_leaf ($activity) || !$childrenflag){
+            if ($children[$siz-1]->id == $activity->id){
+    
+                $seq = scorm_seq_flow_tree_traversal ($parent, $direction, false, null, $seq,$userid);
+                // I think it's not necessary to do a return in here
+            }
+            else{
+                $parent = scorm_get_parent($activity);
+                $children = scorm_get_available_children($parent);
+                $seq->traversaldir = $direction;
+                $sib = scorm_get_siblings($activity);
+                $pos = array_search($sib, $activity);
+                if ($pos !== false) {
+                    if ($pos != sizeof ($sib)){
+                        $seq->nextactivity = $sib [$pos+1];
+                        return $seq;
+                    }
+                    else{
+                        $ch = scorm_get_children($sib[0]);
+                        $seq->nextactivity = $ch[0];
+                        return $seq;
+                    }
+                }
+            }
+        }
+        else{
+            if (!empty ($children)){
+                $seq->traversaldir = $direction;
                 $seq->nextactivity = $children[0];
-                               return $seq;
-                       }
-                       else{
-                               $seq->traversaldir = null;
+                return $seq;
+            }
+            else{
+                $seq->traversaldir = null;
                 $seq->nextactivity = $children[0];
-                               $seq->exception = 'SB.2.1-2';
-                               return $seq;
-                       }
-               }
-               
-       }
-       if($direction = 'backward'){
-               
-                if ($activity->parent == '/'){
-                       $seq->traversaldir = null;
+                $seq->exception = 'SB.2.1-2';
+                return $seq;
+            }
+        }
+        
+    }
+    if($direction = 'backward'){
+        
+         if ($activity->parent == '/'){
+            $seq->traversaldir = null;
             $seq->nextactivity = null;
-                       $seq->exception = 'SB.2.1-3';
-                       return $seq;
-                }
-                if (scorm_is_leaf ($activity) || !$childrenflag){
-                        if (!$revdirection){
-                                if (isset($parent->forwardonly) && ($parent->forwardonly == true)) {
-                                        $seq->traversaldir = null;
+            $seq->exception = 'SB.2.1-3';
+            return $seq;
+         }
+         if (scorm_is_leaf ($activity) || !$childrenflag){
+             if (!$revdirection){
+                 if (isset($parent->forwardonly) && ($parent->forwardonly == true)) {
+                     $seq->traversaldir = null;
                      $seq->nextactivity = null;
-                                $seq->exception = 'SB.2.1-4';
-                                        return $seq;
-                                }
-                        }
-                        if ($children[0]->id == $activity->id){
-                               $seq = scorm_seq_flow_tree_traversal ($parent, 'backward', false, null, $seq);
-                               return $seq;
-                        }
-                        else{
-                               $ancestors = scorm_get_ancestors($activity);
-                       $ancestorsroot = array_reverse ($ancestors);
-                               $preorder = scorm_get_preorder ($ancestorsroot);
-                               $pos = array_search($preorder, $children[$siz]);
-                               $preord = array_slice($preorder, 0, $pos-1);
-                               $revpreorder = array_reverse($preord);
-                               $position = array_search($revpreorder, $activity);
-                               $seq->nextactivity = $revpreorder[$pos+1];
-                               $seq->traversaldir = $direction;
-                               return $seq;
-                        }
-                }
-                else{
-                        if (!empty($children)){
-                                $activity = scorm_get_sco($activity->id);
-                                if (isset($parent->flow) && ($parent->flow == true)) {
-                                        $children = scorm_get_children ($activity);
-                                        $seq->traversaldir = 'forward';
+                     $seq->exception = 'SB.2.1-4';
+                     return $seq;
+                 }
+             }
+             if ($children[0]->id == $activity->id){
+                $seq = scorm_seq_flow_tree_traversal ($parent, 'backward', false, null, $seq);
+                return $seq;
+             }
+             else{
+                $ancestors = scorm_get_ancestors($activity);
+                $ancestorsroot = array_reverse ($ancestors);
+                $preorder = scorm_get_preorder ($ancestorsroot);
+                $pos = array_search($preorder, $children[$siz]);
+                $preord = array_slice($preorder, 0, $pos-1);
+                $revpreorder = array_reverse($preord);
+                $position = array_search($revpreorder, $activity);
+                $seq->nextactivity = $revpreorder[$pos+1];
+                $seq->traversaldir = $direction;
+                return $seq;
+             }
+         }
+         else{
+             if (!empty($children)){
+                 $activity = scorm_get_sco($activity->id);
+                 if (isset($parent->flow) && ($parent->flow == true)) {
+                     $children = scorm_get_children ($activity);
+                     $seq->traversaldir = 'forward';
                      $seq->nextactivity = $children[0];
-                                        return $seq;
-                                
-                                }
-                                else{
-                                        $children = scorm_get_children ($activity);
-                                        $seq->traversaldir = 'backward';
+                     return $seq;
+                     
+                 }
+                 else{
+                     $children = scorm_get_children ($activity);
+                     $seq->traversaldir = 'backward';
                      $seq->nextactivity = $children[sizeof($children)-1];
-                                        return $seq;
-                                }
+                     return $seq;
+                 }
 
-                        }
-                        else{
-                                
-                                        $seq->traversaldir = null;
+             }
+             else{
+                 
+                     $seq->traversaldir = null;
                      $seq->nextactivity = null;
-                                        $seq->exception = 'SB.2.1-2';
-                                        return $seq;
-                        }
-                }
+                     $seq->exception = 'SB.2.1-2';
+                     return $seq;
+             }
+         }
 
-       }
+    }
 
 
 }
 function scorm_check_activity ($activity,$userid){
-       $act = scorm_seq_rules_check($activity,'disabled');
-       if ($act != null){
-               return true;
-       }
+    $act = scorm_seq_rules_check($activity,'disabled');
+    if ($act != null){
+        return true;
+    }
     if(scorm_limit_cond_check ($activity,$userid)){
-               return true;
-       }
-       return false;
+        return true;
+    }
+    return false;
 
 
 }
@@ -1526,69 +1526,69 @@ function scorm_limit_cond_check ($activity,$userid){
     global $DB;
 
     if (isset($activity->tracked) && ($activity->tracked == 0)){
-               
-               return false;
-       }
-
-       if (scorm_seq_is('active',$activity->id,$userid) || scorm_seq_is('suspended',$activity->id,$userid)){
-               return false;
-       }
-
-    if (!isset($activity->limitcontrol) || ($activity->limitcontrol == 1)){    
-               $r = $DB->get_record('scorm_scoes_track', array('scoid'=>$activity->id,'userid'=>$userid,'element'=>'activityattemptcount'));
-               if (scorm_seq_is('activityprogressstatus',$activity->id,$userid) && ($r->value >=$activity->limitattempt)){
-                       return true;
-               }
-       }
-
-        if (!isset($activity->limitabsdurcontrol) || ($activity->limitabsdurcontrol == 1)){    
-               $r = $DB->get_record('scorm_scoes_track', array('scoid'=>$activity->id,'userid'=>$userid,'element'=>'activityabsoluteduration'));
-               if (scorm_seq_is('activityprogressstatus',$activity->id,$userid) && ($r->value >=$activity->limitabsduration)){
-                       return true;
-               }
-       }
-
-       if (!isset($activity->limitexpdurcontrol) || ($activity->limitexpdurcontrol == 1)){     
-               $r = $DB->get_record('scorm_scoes_track', array('scoid'=>$activity->id,'userid'=>$userid,'element'=>'activityexperiencedduration'));
-               if (scorm_seq_is('activityprogressstatus',$activity->id,$userid) && ($r->value >=$activity->limitexpduration)){
-                       return true;
-               }
-       }
+        
+        return false;
+    }
+
+    if (scorm_seq_is('active',$activity->id,$userid) || scorm_seq_is('suspended',$activity->id,$userid)){
+        return false;
+    }
+
+    if (!isset($activity->limitcontrol) || ($activity->limitcontrol == 1)){ 
+        $r = $DB->get_record('scorm_scoes_track', array('scoid'=>$activity->id,'userid'=>$userid,'element'=>'activityattemptcount'));
+        if (scorm_seq_is('activityprogressstatus',$activity->id,$userid) && ($r->value >=$activity->limitattempt)){
+            return true;
+        }
+    }
+
+     if (!isset($activity->limitabsdurcontrol) || ($activity->limitabsdurcontrol == 1)){    
+        $r = $DB->get_record('scorm_scoes_track', array('scoid'=>$activity->id,'userid'=>$userid,'element'=>'activityabsoluteduration'));
+        if (scorm_seq_is('activityprogressstatus',$activity->id,$userid) && ($r->value >=$activity->limitabsduration)){
+            return true;
+        }
+    }
+
+    if (!isset($activity->limitexpdurcontrol) || ($activity->limitexpdurcontrol == 1)){ 
+        $r = $DB->get_record('scorm_scoes_track', array('scoid'=>$activity->id,'userid'=>$userid,'element'=>'activityexperiencedduration'));
+        if (scorm_seq_is('activityprogressstatus',$activity->id,$userid) && ($r->value >=$activity->limitexpduration)){
+            return true;
+        }
+    }
     
-        if (!isset($activity->limitattabsdurcontrol) || ($activity->limitattabsdurcontrol == 1)){      
-               $r = $DB->get_record('scorm_scoes_track', array('scoid'=>$activity->id,'userid'=>$userid,'element'=>'attemptabsoluteduration'));
-               if (scorm_seq_is('activityprogressstatus',$activity->id,$userid) && ($r->value >=$activity->limitattabsduration)){
-                       return true;
-               }
-       }
-
-       if (!isset($activity->limitattexpdurcontrol) || ($activity->limitattexpdurcontrol == 1)){       
-               $r = $DB->get_record('scorm_scoes_track', array('scoid'=>$activity->id,'userid'=>$userid,'element'=>'attemptexperiencedduration'));
-               if (scorm_seq_is('activityprogressstatus',$activity->id,$userid) && ($r->value >=$activity->limitattexpduration)){
-                       return true;
-               }
-       }
-
-       if (!isset($activity->limitbegincontrol) || ($activity->limitbegincontrol == 1)){       
-               $r = $DB->get_record('scorm_scoes_track', array('scoid'=>$activity->id,'userid'=>$userid,'element'=>'begintime'));
-               if (time()>=$activity->limitbegintime){
-                       return true;
-               }
-       }
-
-       if (!isset($activity->limitbegincontrol) || ($activity->limitbegincontrol == 1)){       
-               if (time()<$activity->limitbegintime){
-                       return true;
-               }
-       }
-
-       if (!isset($activity->limitendcontrol) || ($activity->limitendcontrol == 1)){   
-
-               if (time()>$activity->limitendtime){
-                       return true;
-               }
-       }
-       return false;
+     if (!isset($activity->limitattabsdurcontrol) || ($activity->limitattabsdurcontrol == 1)){  
+        $r = $DB->get_record('scorm_scoes_track', array('scoid'=>$activity->id,'userid'=>$userid,'element'=>'attemptabsoluteduration'));
+        if (scorm_seq_is('activityprogressstatus',$activity->id,$userid) && ($r->value >=$activity->limitattabsduration)){
+            return true;
+        }
+    }
+
+    if (!isset($activity->limitattexpdurcontrol) || ($activity->limitattexpdurcontrol == 1)){   
+        $r = $DB->get_record('scorm_scoes_track', array('scoid'=>$activity->id,'userid'=>$userid,'element'=>'attemptexperiencedduration'));
+        if (scorm_seq_is('activityprogressstatus',$activity->id,$userid) && ($r->value >=$activity->limitattexpduration)){
+            return true;
+        }
+    }
+
+    if (!isset($activity->limitbegincontrol) || ($activity->limitbegincontrol == 1)){   
+        $r = $DB->get_record('scorm_scoes_track', array('scoid'=>$activity->id,'userid'=>$userid,'element'=>'begintime'));
+        if (time()>=$activity->limitbegintime){
+            return true;
+        }
+    }
+
+    if (!isset($activity->limitbegincontrol) || ($activity->limitbegincontrol == 1)){   
+        if (time()<$activity->limitbegintime){
+            return true;
+        }
+    }
+
+    if (!isset($activity->limitendcontrol) || ($activity->limitendcontrol == 1)){   
+
+        if (time()>$activity->limitendtime){
+            return true;
+        }
+    }
+    return false;
 
 
 }
@@ -1596,361 +1596,361 @@ function scorm_limit_cond_check ($activity,$userid){
 
 function scorm_seq_choice_sequencing($sco,$userid,$seq){
 
-       $avchildren = Array ();
-       $comancestor = null;
-       $traverse = null;
+    $avchildren = Array ();
+    $comancestor = null;
+    $traverse = null;
 
-       if ($sco == null){
-               $seq->delivery = null;
-               $seq->exception = 'SB.2.9-1';
-               return $seq;
-       }
+    if ($sco == null){
+        $seq->delivery = null;
+        $seq->exception = 'SB.2.9-1';
+        return $seq;
+    }
 
     $ancestors = scorm_get_ancestors($sco);
     $arrpath = array_reverse($ancestors);
-       array_push ($arrpath,$sco);//path from the root to the target
+    array_push ($arrpath,$sco);//path from the root to the target
 
-       foreach ($arrpath as $activity){
+    foreach ($arrpath as $activity){
 
         if ($activity->parent != '/') {
-                       $avchildren = scorm_get_available_children (scorm_get_parent($activity));
-                       $position = array_search($avchildren, $activity);
+            $avchildren = scorm_get_available_children (scorm_get_parent($activity));
+            $position = array_search($avchildren, $activity);
             if ($position !== false){
-                               $seq->delivery = null;
-                       $seq->exception = 'SB.2.9-2';
-                       return $seq;
-                       }
-               }
+                $seq->delivery = null;
+                $seq->exception = 'SB.2.9-2';
+                return $seq;
+            }
+        }
 
-               if (scorm_seq_rules_check($activity,'hidefromchoice' != null)){
+        if (scorm_seq_rules_check($activity,'hidefromchoice' != null)){
 
-                       $seq->delivery = null;
-                   $seq->exception = 'SB.2.9-3';
-                   return $seq;
+            $seq->delivery = null;
+            $seq->exception = 'SB.2.9-3';
+            return $seq;
 
-               }
+        }
 
-       }
+    }
 
-       if ($sco->parent != '/') {
-               $parent = scorm_sco_get_parent ($sco);
-               if ( isset($parent->choice) && ($parent->choice == false)){
-                       $seq->delivery = null;
-                   $seq->exception = 'SB.2.9-4';
-                   return $seq;
-               }
-       }
+    if ($sco->parent != '/') {
+        $parent = scorm_sco_get_parent ($sco);
+        if ( isset($parent->choice) && ($parent->choice == false)){
+            $seq->delivery = null;
+            $seq->exception = 'SB.2.9-4';
+            return $seq;
+        }
+    }
 
-       if ($seq->currentactivity != null){
+    if ($seq->currentactivity != null){
         $commonpos = scorm_find_common_ancestor($ancestors,$seq->currentactivity);
-               $comancestor = $arrpath [$commonpos];
-       }
-       else{
-               $comancestor = $arrpath [0];
-       }
+        $comancestor = $arrpath [$commonpos];
+    }
+    else{
+        $comancestor = $arrpath [0];
+    }
 
-       if($seq->currentactivity === $sco) {
+    if($seq->currentactivity === $sco) {
         break;
-       }
+    }
 
-       $sib = scorm_get_siblings($seq->currentactivity);
-       $pos = array_search($sib, $sco);
+    $sib = scorm_get_siblings($seq->currentactivity);
+    $pos = array_search($sib, $sco);
 
-       if (pos !== false){
+    if ($pos !== false){
 
-               $siblings = array_slice($sib, 0, $pos-1);
+        $siblings = array_slice($sib, 0, $pos-1);
 
-               if (empty($siblings)){
+        if (empty($siblings)){
 
-                       $seq->delivery = null;
-                   $seq->exception = 'SB.2.9-5';
-                   return $seq;
+            $seq->delivery = null;
+            $seq->exception = 'SB.2.9-5';
+            return $seq;
 
-               }
+        }
         
-               $children = scorm_get_children (scorm_get_parent ($sco));
-               $pos1 = array_search($children, $sco);
-               $pos2 = array_search($seq->currentactivity, $sco);
-               if ($pos1>$pos2){
-                       $traverse = 'forward';
-               }
-               else{
-                       $traverse = 'backward';
-               }
-
-               foreach ($siblings as $sibling){
-                       $seq = scorm_seq_choice_activity_traversal($sibling,$userid,$seq,$traverse);
-                   if(!$seq->reachable){
-                           $seq->delivery = null;
-                           return $seq;
-                   }
-               }
-               break;
-
-       }
+        $children = scorm_get_children (scorm_get_parent ($sco));
+        $pos1 = array_search($children, $sco);
+        $pos2 = array_search($seq->currentactivity, $sco);
+        if ($pos1>$pos2){
+            $traverse = 'forward';
+        }
+        else{
+            $traverse = 'backward';
+        }
+
+        foreach ($siblings as $sibling){
+            $seq = scorm_seq_choice_activity_traversal($sibling,$userid,$seq,$traverse);
+            if(!$seq->reachable){
+                $seq->delivery = null;
+                return $seq;
+            }
+        }
+        break;
+
+    }
 
     if($seq->currentactivity == null || $seq->currentactivity == $comancestor){
-               $commonpos = scorm_find_common_ancestor($ancestors,$seq->currentactivity);
-               $comtarget = array_slice($ancestors, 1,$commonpos-1);//path from the common ancestor to the target activity
-               $comtarget = array_reverse($comtarget);
-
-               if (empty($comtarget)){
-                       $seq->delivery = null;
-                   $seq->exception = 'SB.2.9-5';
-                   return $seq;
-               }
-               foreach ($comtarget as $act){
-                       $seq = scorm_seq_choice_activity_traversal($act,$userid,$seq,'forward');
-                   if(!$seq->reachable){
-                           $seq->delivery = null;
-                           return $seq;
-                   }
+        $commonpos = scorm_find_common_ancestor($ancestors,$seq->currentactivity);
+        $comtarget = array_slice($ancestors, 1,$commonpos-1);//path from the common ancestor to the target activity
+        $comtarget = array_reverse($comtarget);
+
+        if (empty($comtarget)){
+            $seq->delivery = null;
+            $seq->exception = 'SB.2.9-5';
+            return $seq;
+        }
+        foreach ($comtarget as $act){
+            $seq = scorm_seq_choice_activity_traversal($act,$userid,$seq,'forward');
+            if(!$seq->reachable){
+                $seq->delivery = null;
+                return $seq;
+            }
             $act = scorm_get_sco ($acti->id);
-                       if(scorm_seq_is('active',$act->id,$userid) && ($act->id != $comancestor->id && $act->preventactivation)){//adlseq:can i write it like another property for the $seq object?
-                               $seq->delivery = null;
-                       $seq->exception = 'SB.2.9-6';
-                       return $seq;
-                       }
-               }
-               break;
+            if(scorm_seq_is('active',$act->id,$userid) && ($act->id != $comancestor->id && $act->preventactivation)){//adlseq:can i write it like another property for the $seq object?
+                $seq->delivery = null;
+                $seq->exception = 'SB.2.9-6';
+                return $seq;
+            }
+        }
+        break;
 
-       }
+    }
 
-       if ($comancestor->id == $sco->id){
+    if ($comancestor->id == $sco->id){
 
         $ancestorscurrent = scorm_get_ancestors($seq->currentactivity);
-               $possco = array_search ($ancestorscurrent, $sco);
-               $curtarget = array_slice($ancestorscurrent,0,$possco);//path from the current activity to the target
-
-               if (empty($curtarget)){
-                       $seq->delivery = null;
-                   $seq->exception = 'SB.2.9-5';
-                   return $seq;
-               }
+        $possco = array_search ($ancestorscurrent, $sco);
+        $curtarget = array_slice($ancestorscurrent,0,$possco);//path from the current activity to the target
+
+        if (empty($curtarget)){
+            $seq->delivery = null;
+            $seq->exception = 'SB.2.9-5';
+            return $seq;
+        }
         $i=0;
-               foreach ($curtarget as $activ){
-                       $i++;
-                       if ($i != sizeof($curtarget)){
-                               if ( isset($activ->choiceexit) && ($activ->choiceexit == false)){
-                                       $seq->delivery = null;
-                           $seq->exception = 'SB.2.9-7';
-                           return $seq;
-                               }
-                       }
-               }
-               break;
-       }
-
-       if (array_search ($ancestors, $comancestor)!== false){
-               $ancestorscurrent = scorm_get_ancestors($seq->currentactivity);
-               $commonpos = scorm_find_common_ancestor($ancestors,$sco);
-               $curcommon = array_slice($ancestorscurrent,0,$commonpos-1);
-               if(empty($curcommon)){
-                       $seq->delivery = null;
-                   $seq->exception = 'SB.2.9-5';
-                   return $seq;
-               }
-
-               $constrained = null;
-               foreach ($curcommon as $acti){
-                       $acti = scorm_get_sco($acti->id);
-                       if ( isset($acti->choiceexit) && ($acti->choiceexit == false)){
-                                       $seq->delivery = null;
-                           $seq->exception = 'SB.2.9-7';
-                           return $seq;
-                       }
-                       if ($constrained == null){
-                               if($acti->constrainchoice == true){
-                                       $constrained = $acti;
-                               }
-                       }
-               }
-               if ($constrained != null){
+        foreach ($curtarget as $activ){
+            $i++;
+            if ($i != sizeof($curtarget)){
+                if ( isset($activ->choiceexit) && ($activ->choiceexit == false)){
+                    $seq->delivery = null;
+                    $seq->exception = 'SB.2.9-7';
+                    return $seq;
+                }
+            }
+        }
+        break;
+    }
+
+    if (array_search ($ancestors, $comancestor)!== false){
+        $ancestorscurrent = scorm_get_ancestors($seq->currentactivity);
+        $commonpos = scorm_find_common_ancestor($ancestors,$sco);
+        $curcommon = array_slice($ancestorscurrent,0,$commonpos-1);
+        if(empty($curcommon)){
+            $seq->delivery = null;
+            $seq->exception = 'SB.2.9-5';
+            return $seq;
+        }
+
+        $constrained = null;
+        foreach ($curcommon as $acti){
+            $acti = scorm_get_sco($acti->id);
+            if ( isset($acti->choiceexit) && ($acti->choiceexit == false)){
+                    $seq->delivery = null;
+                    $seq->exception = 'SB.2.9-7';
+                    return $seq;
+            }
+            if ($constrained == null){
+                if($acti->constrainchoice == true){
+                    $constrained = $acti;
+                }
+            }
+        }
+        if ($constrained != null){
             $fwdir = scorm_get_preorder($constrained);
 
-                   if(array_search ($fwdir, $sco)!== false){
-                               $traverse = 'forward';
-                       }
-                       else{
-                               $traverse = 'backward';
-                       }
-                       $seq = scorm_seq_choice_flow ($constrained, $traverse, $seq);
-                       $actconsider = $seq->identifiedactivity;
-                       $avdescendents = Array();
-                       $avdescendents= scorm_get_available_descendents ($actconsider);
-                       if (array_search ($avdescendents, $sco) !== false && $sco->id != $actconsider->id && $constrained->id != $sco->id ){
-                               $seq->delivery = null;
-                       $seq->exception = 'SB.2.9-8';
-                       return $seq;
-                       }
+            if(array_search ($fwdir, $sco)!== false){
+                $traverse = 'forward';
+            }
+            else{
+                $traverse = 'backward';
+            }
+            $seq = scorm_seq_choice_flow ($constrained, $traverse, $seq);
+            $actconsider = $seq->identifiedactivity;
+            $avdescendents = Array();
+            $avdescendents= scorm_get_available_descendents ($actconsider);
+            if (array_search ($avdescendents, $sco) !== false && $sco->id != $actconsider->id && $constrained->id != $sco->id ){
+                $seq->delivery = null;
+                $seq->exception = 'SB.2.9-8';
+                return $seq;
+            }
 
 //CONTINUE 11.5.5
-               }
+        }
 
-               $commonpos = scorm_find_common_ancestor($ancestors,$seq->currentactivity);
-               $comtarget = array_slice($ancestors, 1,$commonpos-1);//path from the common ancestor to the target activity
-               $comtarget = array_reverse($comtarget);
+        $commonpos = scorm_find_common_ancestor($ancestors,$seq->currentactivity);
+        $comtarget = array_slice($ancestors, 1,$commonpos-1);//path from the common ancestor to the target activity
+        $comtarget = array_reverse($comtarget);
 
-               if (empty($comtarget)){
-                       $seq->delivery = null;
-                   $seq->exception = 'SB.2.9-5';
-                   return $seq;
-               }
+        if (empty($comtarget)){
+            $seq->delivery = null;
+            $seq->exception = 'SB.2.9-5';
+            return $seq;
+        }
 
-               $fwdir = scorm_get_preorder($seq->currentactivity);
+        $fwdir = scorm_get_preorder($seq->currentactivity);
 
-               if(array_search ($fwdir, $sco)!== false){
+        if(array_search ($fwdir, $sco)!== false){
 
-                   foreach ($comtarget as $act){
-                           $seq = scorm_seq_choice_activity_traversal($act,$userid,$seq,'forward');
-                       if(!$seq->reachable){
-                               $seq->delivery = null;
-                               return $seq;
-                       }
+            foreach ($comtarget as $act){
+                $seq = scorm_seq_choice_activity_traversal($act,$userid,$seq,'forward');
+                if(!$seq->reachable){
+                    $seq->delivery = null;
+                    return $seq;
+                }
                 $act = scorm_get_sco($act->id);
-                           if(scorm_seq_is('active',$act->id,$userid) && ($act->id != $comancestor->id && ($act->preventactivation == true))){
-                                   $seq->delivery = null;
-                           $seq->exception = 'SB.2.9-6';
-                           return $seq;
-                           }
-                   }
-
-               }
-               else{
-                       foreach ($comtarget as $act){
-                               $act = scorm_get_sco($act->id);
-                           if(scorm_seq_is('active',$act->id,$userid) && ($act->id != $comancestor->id && ($act->preventactivation==true))){
-                                   $seq->delivery = null;
-                           $seq->exception = 'SB.2.9-6';
-                           return $seq;
-                           }
-                   }
-               }
-           break;      
-       }
-
-       if(scorm_is_leaf ($sco)){
-               $seq->delivery = $sco;
-               $seq->exception = 'SB.2.9-6';
-               return $seq;
-       }
+                if(scorm_seq_is('active',$act->id,$userid) && ($act->id != $comancestor->id && ($act->preventactivation == true))){
+                    $seq->delivery = null;
+                    $seq->exception = 'SB.2.9-6';
+                    return $seq;
+                }
+            }
+
+        }
+        else{
+            foreach ($comtarget as $act){
+                $act = scorm_get_sco($act->id);
+                if(scorm_seq_is('active',$act->id,$userid) && ($act->id != $comancestor->id && ($act->preventactivation==true))){
+                    $seq->delivery = null;
+                    $seq->exception = 'SB.2.9-6';
+                    return $seq;
+                }
+            }
+        }
+        break;  
+    }
+
+    if(scorm_is_leaf ($sco)){
+        $seq->delivery = $sco;
+        $seq->exception = 'SB.2.9-6';
+        return $seq;
+    }
 
     $seq = scorm_seq_flow ($sco,'forward',$seq,true,$userid);
     if ($seq->deliverable == false){
-               scorm_terminate_descendent_attempts($comancestor,$userid,$seq);
-               scorm_seq_end_attempt($comancestor,$userid,$seq->attempt);
-               $seq->currentactivity = $sco;
-               $seq->delivery = null;
-               $seq->exception = 'SB.2.9-9';
-               return $seq;
-
-       }
-       else{
-               return $seq;
-       }
+        scorm_terminate_descendent_attempts($comancestor,$userid,$seq);
+        scorm_seq_end_attempt($comancestor,$userid,$seq->attempt);
+        $seq->currentactivity = $sco;
+        $seq->delivery = null;
+        $seq->exception = 'SB.2.9-9';
+        return $seq;
+
+    }
+    else{
+        return $seq;
+    }
   
 }
 
 function scorm_seq_choice_flow ($constrained, $traverse, $seq){
-       $seq = scorm_seq_choice_flow_tree ($constrained, $traverse, $seq);
-       if ($seq->identifiedactivity == null){
+    $seq = scorm_seq_choice_flow_tree ($constrained, $traverse, $seq);
+    if ($seq->identifiedactivity == null){
         $seq->identifiedactivity = $constrained;
-               return $seq;
-       }
-       else{
-               return $seq;
-       }
+        return $seq;
+    }
+    else{
+        return $seq;
+    }
 }
 
 function scorm_seq_choice_flow_tree ($constrained, $traverse, $seq){
-       $islast = false;
-       $parent = scorm_get_parent ($constrained);
-       if ($traverse== 'forward'){
-               $preord = scorm_get_preorder ($constrained);
-               if (sizeof($preorder) == 0 || (sizeof($preorder) == 0 && $preorder[0]->id = $constrained->id)){ // TODO: undefined
-                       $islast = true;//the function is the last activity available
-               }
-               if ($constrained->parent == '/' || $islast){
-                       $seq->nextactivity = null;
-                       return $seq;
-               }
-               $avchildren = scorm_get_available_children ($parent);//available children
-               if ($avchildren [sizeof($avchildren)-1]->id == $constrained->id){
-                       $seq = scorm_seq_choice_flow_tree ($parent, 'forward', $seq);
-                       return $seq;
-               }
-               else{
-                       $i=0;
-                       while(i < sizeof($avchildren)){
-                               if ($avchildren [i]->id == $constrained->id){
-                                       $seq->nextactivity = $avchildren [i+1];
-                                       return $seq;
-                               }
-                               else{
-                                       $i++;
-                               }
-                       }
-               }
-
-       }
-
-       if ($traverse== 'backward'){
-               if($constrained->parent == '/' ){
-                       $seq->nextactivity = null;
-                       return $seq;
-               }
-
-               $avchildren = scorm_get_available_children ($parent);//available children
-               if ($avchildren [0]->id == $constrained->id){
-                       $seq = scorm_seq_choice_flow_tree ($parent, 'backward', $seq);
-                       return $seq;
-               }
-               else{
-                       $i=sizeof($avchildren)-1;
-                       while($i >=0){
-                               if ($avchildren [i]->id == $constrained->id){
-                                       $seq->nextactivity = $avchildren [i-1];
-                                       return $seq;
-                               }
-                               else{
-                                       $i--;
-                               }
-                       }
-               }
-       }
+    $islast = false;
+    $parent = scorm_get_parent ($constrained);
+    if ($traverse== 'forward'){
+        $preord = scorm_get_preorder ($constrained);
+        if (sizeof($preorder) == 0 || (sizeof($preorder) == 0 && $preorder[0]->id = $constrained->id)){ // TODO: undefined
+            $islast = true;//the function is the last activity available
+        }
+        if ($constrained->parent == '/' || $islast){
+            $seq->nextactivity = null;
+            return $seq;
+        }
+        $avchildren = scorm_get_available_children ($parent);//available children
+        if ($avchildren [sizeof($avchildren)-1]->id == $constrained->id){
+            $seq = scorm_seq_choice_flow_tree ($parent, 'forward', $seq);
+            return $seq;
+        }
+        else{
+            $i=0;
+            while($i < sizeof($avchildren)){
+                if ($avchildren [$i]->id == $constrained->id){
+                    $seq->nextactivity = $avchildren [$i+1];
+                    return $seq;
+                }
+                else{
+                    $i++;
+                }
+            }
+        }
+
+    }
+
+    if ($traverse== 'backward'){
+        if($constrained->parent == '/' ){
+            $seq->nextactivity = null;
+            return $seq;
+        }
+
+        $avchildren = scorm_get_available_children ($parent);//available children
+        if ($avchildren [0]->id == $constrained->id){
+            $seq = scorm_seq_choice_flow_tree ($parent, 'backward', $seq);
+            return $seq;
+        }
+        else{
+            $i=sizeof($avchildren)-1;
+            while($i >=0){
+                if ($avchildren [$i]->id == $constrained->id){
+                    $seq->nextactivity = $avchildren [$i-1];
+                    return $seq;
+                }
+                else{
+                    $i--;
+                }
+            }
+        }
+    }
 }
 function scorm_seq_choice_activity_traversal($activity,$userid,$seq,$direction){
 
-       if($direction == 'forward'){
-
-               $act = scorm_seq_rules_check($activity,'stopforwardtraversal');
-
-               if($act != null){
-                       $seq->reachable = false;
-                       $seq->exception = 'SB.2.4-1';
-                   return $seq;
-               }
-               $seq->reachable = false;
-               return $seq;
-       }
-
-       if($direction == 'backward'){
-               $parentsco = scorm_get_parent($activity);
-               if($parentsco!= null){
-                        if (isset($parentsco->forwardonly) && ($parentsco->forwardonly == true)){
-                                $seq->reachable = false;
-                            $seq->exception = 'SB.2.4-2';
-                        return $seq;
-                        }
-                        else{
-                           $seq->reachable = false;
-                           $seq->exception = 'SB.2.4-3';
-                       return $seq;
-                    }
-               }
-       }
-       $seq->reachable = true;
-       return $seq;
+    if($direction == 'forward'){
+
+        $act = scorm_seq_rules_check($activity,'stopforwardtraversal');
+
+        if($act != null){
+            $seq->reachable = false;
+            $seq->exception = 'SB.2.4-1';
+            return $seq;
+        }
+        $seq->reachable = false;
+        return $seq;
+    }
+
+    if($direction == 'backward'){
+        $parentsco = scorm_get_parent($activity);
+        if($parentsco!= null){
+             if (isset($parentsco->forwardonly) && ($parentsco->forwardonly == true)){
+                 $seq->reachable = false;
+                 $seq->exception = 'SB.2.4-2';
+                 return $seq;
+             }
+             else{
+                $seq->reachable = false;
+                $seq->exception = 'SB.2.4-3';
+                return $seq;
+             }
+        }
+    }
+    $seq->reachable = true;
+    return $seq;
 
 }
 
@@ -1958,417 +1958,417 @@ function scorm_seq_choice_activity_traversal($activity,$userid,$seq,$direction){
 
 function scorm_sequencing_delivery($scoid,$userid,$seq){
 
-       if(!scorm_is_leaf ($seq->delivery)){
-               $seq->deliveryvalid = false;
-               $seq->exception = 'DB.1.1-1';
-               return $seq;
-       }
-       $ancestors = scorm_get_ancestors($seq->delivery);
+    if(!scorm_is_leaf ($seq->delivery)){
+        $seq->deliveryvalid = false;
+        $seq->exception = 'DB.1.1-1';
+        return $seq;
+    }
+    $ancestors = scorm_get_ancestors($seq->delivery);
     $arrpath = array_reverse($ancestors);
-       array_push ($arrpath,$seq->delivery);//path from the root to the target
+    array_push ($arrpath,$seq->delivery);//path from the root to the target
 
-       if (empty($arrpath)){
-               $seq->deliveryvalid = false;
-               $seq->exception = 'DB.1.1-2';
-               return $seq;
-       }
+    if (empty($arrpath)){
+        $seq->deliveryvalid = false;
+        $seq->exception = 'DB.1.1-2';
+        return $seq;
+    }
 
-       foreach ($arrpath as $activity){
-           if(scorm_check_activity ($activity,$userid)){
-                   $seq->deliveryvalid = false;
-               $seq->exception = 'DB.1.1-3';
-               return $seq;
-           }
-       }
+    foreach ($arrpath as $activity){
+        if(scorm_check_activity ($activity,$userid)){
+            $seq->deliveryvalid = false;
+            $seq->exception = 'DB.1.1-3';
+            return $seq;
+        }
+    }
 
-       $seq->deliveryvalid = true;
-       return $seq;
+    $seq->deliveryvalid = true;
+    return $seq;
 
 }
 
 function scorm_content_delivery_environment ($seq,$userid){
     global $DB;
 
-       $act = $seq->currentactivity;
-       if(scorm_seq_is('active',$act->id,$userid)){
-               $seq->exception = 'DB.2-1';
-           return $seq;
-       }
-       $track = $DB->get_record('scorm_scoes_track', array('scoid'=>$act->id,'userid'=>$userid,'element'=>'suspendedactivity'));
-       if ($track != null){
-               $seq = scorm_clear_suspended_activity($seq->delivery, $seq);
-
-       }
-       $seq = scorm_terminate_descendent_attempts ($seq->delivery,$userid,$seq);
-       $ancestors = scorm_get_ancestors($seq->delivery);
+    $act = $seq->currentactivity;
+    if(scorm_seq_is('active',$act->id,$userid)){
+        $seq->exception = 'DB.2-1';
+        return $seq;
+    }
+    $track = $DB->get_record('scorm_scoes_track', array('scoid'=>$act->id,'userid'=>$userid,'element'=>'suspendedactivity'));
+    if ($track != null){
+        $seq = scorm_clear_suspended_activity($seq->delivery, $seq);
+
+    }
+    $seq = scorm_terminate_descendent_attempts ($seq->delivery,$userid,$seq);
+    $ancestors = scorm_get_ancestors($seq->delivery);
     $arrpath = array_reverse($ancestors);
-       array_push ($arrpath,$seq->delivery);
-       foreach ($arrpath as $activity){
-               if(!scorm_seq_is('active',$activity->id,$userid)){
-                       if(!isset($activity->tracked) || ($activity->tracked == 1)){
-                               if(!scorm_seq_is('suspended',$activity->id,$userid)){
-                                       $r = $DB->get_record('scorm_scoes_track', array('scoid'=>$activity->id,'userid'=>$userid,'element'=>'activityattemptcount'));
-                                       $r->value = ($r->value)+1;
-                                       $DB->update_record ('scorm_scoes_track',$r);
-                                       if ($r->value == 1){
-                                               scorm_seq_set('activityprogressstatus', $activity->id, $userid, 'true');
-                                       }
-                                       scorm_insert_track($userid, $activity->scorm, $activity->id, 0, 'objectiveprogressstatus', 'false');
-                                       scorm_insert_track($userid, $activity->scorm, $activity->id, 0, 'objectivesatisfiedstatus', 'false');
-                                       scorm_insert_track($userid, $activity->scorm, $activity->id, 0, 'objectivemeasurestatus', 'false');
-                                       scorm_insert_track($userid, $activity->scorm, $activity->id, 0, 'objectivenormalizedmeasure', 0.0);
-
-                                       scorm_insert_track($userid, $activity->scorm, $activity->id, 0, 'attemptprogressstatus', 'false');
-                                       scorm_insert_track($userid, $activity->scorm, $activity->id, 0, 'attemptcompletionstatus', 'false');
-                                       scorm_insert_track($userid, $activity->scorm, $activity->id, 0, 'attemptabsoluteduration', 0.0);
-                                       scorm_insert_track($userid, $activity->scorm, $activity->id, 0, 'attemptexperiencedduration', 0.0);
-                                       scorm_insert_track($userid, $activity->scorm, $activity->id, 0, 'attemptcompletionamount', 0.0);
-                               }
-                       }
+    array_push ($arrpath,$seq->delivery);
+    foreach ($arrpath as $activity){
+        if(!scorm_seq_is('active',$activity->id,$userid)){
+            if(!isset($activity->tracked) || ($activity->tracked == 1)){
+                if(!scorm_seq_is('suspended',$activity->id,$userid)){
+                    $r = $DB->get_record('scorm_scoes_track', array('scoid'=>$activity->id,'userid'=>$userid,'element'=>'activityattemptcount'));
+                    $r->value = ($r->value)+1;
+                    $DB->update_record ('scorm_scoes_track',$r);
+                    if ($r->value == 1){
+                        scorm_seq_set('activityprogressstatus', $activity->id, $userid, 'true');
+                    }
+                    scorm_insert_track($userid, $activity->scorm, $activity->id, 0, 'objectiveprogressstatus', 'false');
+                    scorm_insert_track($userid, $activity->scorm, $activity->id, 0, 'objectivesatisfiedstatus', 'false');
+                    scorm_insert_track($userid, $activity->scorm, $activity->id, 0, 'objectivemeasurestatus', 'false');
+                    scorm_insert_track($userid, $activity->scorm, $activity->id, 0, 'objectivenormalizedmeasure', 0.0);
+
+                    scorm_insert_track($userid, $activity->scorm, $activity->id, 0, 'attemptprogressstatus', 'false');
+                    scorm_insert_track($userid, $activity->scorm, $activity->id, 0, 'attemptcompletionstatus', 'false');
+                    scorm_insert_track($userid, $activity->scorm, $activity->id, 0, 'attemptabsoluteduration', 0.0);
+                    scorm_insert_track($userid, $activity->scorm, $activity->id, 0, 'attemptexperiencedduration', 0.0);
+                    scorm_insert_track($userid, $activity->scorm, $activity->id, 0, 'attemptcompletionamount', 0.0);
+                }
+            }
             scorm_seq_set('active', $activity->id, $userid, 'true');
-               }
-       }
-       $seq->delivery = $seq->currentactivity;
-       scorm_seq_set('suspendedactivity', $activity->id, $userid, 'false');
+        }
+    }
+    $seq->delivery = $seq->currentactivity;
+    scorm_seq_set('suspendedactivity', $activity->id, $userid, 'false');
 
-       //ONCE THE DELIVERY BEGINS (How should I check that?)
+    //ONCE THE DELIVERY BEGINS (How should I check that?)
 
     if(isset($activity->tracked) || ($activity->tracked == 0)){
-               //How should I track the info and what should I do to not record the information for the activity during delivery? 
-               $atabsdur = $DB->get_record('scorm_scoes_track', array('scoid'=>$activity->id,'userid'=>$userid,'element'=>'attemptabsoluteduration'));
-               $atexpdur = $DB->get_record('scorm_scoes_track', array('scoid'=>$activity->id,'userid'=>$userid,'element'=>'attemptexperiencedduration'));
-       }
-       return $seq;
+        //How should I track the info and what should I do to not record the information for the activity during delivery? 
+        $atabsdur = $DB->get_record('scorm_scoes_track', array('scoid'=>$activity->id,'userid'=>$userid,'element'=>'attemptabsoluteduration'));
+        $atexpdur = $DB->get_record('scorm_scoes_track', array('scoid'=>$activity->id,'userid'=>$userid,'element'=>'attemptexperiencedduration'));
+    }
+    return $seq;
 
  
 }
 function scorm_clear_suspended_activity($act,$seq){
     global $DB;
-       $currentact= $seq->currentactivity;
-       $track = $DB->get_record('scorm_scoes_track', array('scoid'=>$currentact->id,'userid'=>$userid,'element'=>'suspendedactivity')); // TODO: undefined
-       if ($track != null){
-               $ancestors = scorm_get_ancestors($act);
+    $currentact= $seq->currentactivity;
+    $track = $DB->get_record('scorm_scoes_track', array('scoid'=>$currentact->id,'userid'=>$userid,'element'=>'suspendedactivity')); // TODO: undefined
+    if ($track != null){
+        $ancestors = scorm_get_ancestors($act);
         $commonpos = scorm_find_common_ancestor($ancestors,$currentact);
         if ($commonpos !== false) {
             if ($activitypath = array_slice($ancestors,0,$commonpos)) {
-                               if (!empty ($activitypath)){
+                if (!empty ($activitypath)){
 
                     foreach ($activitypath as $activity) {
-                                           if (scorm_is_leaf($activity)){
-                                                       scorm_seq_set('suspended',$activity->id,$userid,false);
-                                               }
-                                               else{
-                                                       $children = scorm_get_children($activity);
-                                                       $bool= false; 
-                                                       foreach ($children as $child){
-                                                               if(scorm_seq_is('suspended',$child->id,$userid)){
-                                                                       $bool= true;
-                                                               }
-                                                       }
+                        if (scorm_is_leaf($activity)){
+                            scorm_seq_set('suspended',$activity->id,$userid,false);
+                        }
+                        else{
+                            $children = scorm_get_children($activity);
+                            $bool= false; 
+                            foreach ($children as $child){
+                                if(scorm_seq_is('suspended',$child->id,$userid)){
+                                    $bool= true;
+                                }
+                            }
                              if(!$bool){
-                                                           scorm_seq_set('suspended',$activity->id,$userid,false);
-                                                        }
-                                               }
-                                   }
-                               }
-                       }
-               }
-               scorm_seq_set('suspendedactivity',$act->id,$userid,false);
-
-       }
+                                scorm_seq_set('suspended',$activity->id,$userid,false);
+                             }
+                        }
+                    }
+                }
+            }
+        }
+        scorm_seq_set('suspendedactivity',$act->id,$userid,false);
+
+    }
 }
 
 function scorm_select_children_process($scoid,$userid){
     global $DB;
 
-       $sco = scorm_get_sco($scoid);
+    $sco = scorm_get_sco($scoid);
     if (!scorm_is_leaf($sco)){
-               if(!scorm_seq_is('suspended',$scoid,$userid) && !scorm_seq_is('active',$scoid,$userid)){
-                       $r = $DB->get_record('scorm_scoes_track', array('scoid'=>$scoid,'userid'=>$userid,'element'=>'selectiontiming'));
+        if(!scorm_seq_is('suspended',$scoid,$userid) && !scorm_seq_is('active',$scoid,$userid)){
+            $r = $DB->get_record('scorm_scoes_track', array('scoid'=>$scoid,'userid'=>$userid,'element'=>'selectiontiming'));
 
              switch($r->value) {
 
                 case 'oneachnewattempt':
-                               case 'never':
+                case 'never':
                 break;
              
                 case 'once':
                     if(!scorm_seq_is('activityprogressstatus',$scoid,$userid)){
-                                           if(scorm_seq_is('selectioncountsstatus',$scoid,$userid)){
-                                               $childlist = '';
-                                                       $res = $DB->get_record('scorm_scoes_track', array('scoid'=>$scoid,'userid'=>$userid,'element'=>'selectioncount'));
-                                                       $i = ($res->value)-1;
-                                                       $children = scorm_get_children ($sco);
-
-                                                       while (i>=0){
-                                                               $pos = array_rand($children);
-                                                               array_push($childlist,$children [$pos]);
-                                                               array_splice($children,$pos,1);
-                                                               $i--;
-                                                       }
-                                                       sort ($childlist);
-                                                       $clist = serialize ($childlist);
-                                                       scorm_seq_set('availablechildren', $scoid, $userid, false);
-                                                       scorm_seq_set('availablechildren', $scoid, $userid, $clist);
-
-
-                                       }
-                                   }
+                        if(scorm_seq_is('selectioncountsstatus',$scoid,$userid)){
+                            $childlist = '';
+                            $res = $DB->get_record('scorm_scoes_track', array('scoid'=>$scoid,'userid'=>$userid,'element'=>'selectioncount'));
+                            $i = ($res->value)-1;
+                            $children = scorm_get_children ($sco);
+
+                            while ($i>=0){
+                                $pos = array_rand($children);
+                                array_push($childlist,$children [$pos]);
+                                array_splice($children,$pos,1);
+                                $i--;
+                            }
+                            sort ($childlist);
+                            $clist = serialize ($childlist);
+                            scorm_seq_set('availablechildren', $scoid, $userid, false);
+                            scorm_seq_set('availablechildren', $scoid, $userid, $clist);
+
+
+                        }
+                    }
                 break;
                
             }
 
-               }
-       }
+        }
+    }
 }
 
 function scorm_randomize_children_process($scoid,$userid){
     global $DB;
 
-       $sco = scorm_get_sco($scoid);
+    $sco = scorm_get_sco($scoid);
     if (!scorm_is_leaf($sco)){
-               if(!scorm_seq_is('suspended',$scoid,$userid) && !scorm_seq_is('active',$scoid,$userid)){
-                       $r = $DB->get_record('scorm_scoes_track', array('scoid'=>$scoid,'userid'=>$userid,'element'=>'randomizationtiming'));
+        if(!scorm_seq_is('suspended',$scoid,$userid) && !scorm_seq_is('active',$scoid,$userid)){
+            $r = $DB->get_record('scorm_scoes_track', array('scoid'=>$scoid,'userid'=>$userid,'element'=>'randomizationtiming'));
 
              switch($r->value) {
 
                 
-                               case 'never':
+                case 'never':
                 break;
              
                 case 'oneachnewattempt':
                 case 'once':
                     if(!scorm_seq_is('activityprogressstatus',$scoid,$userid)){
-                                           if(scorm_seq_is('randomizechildren',$scoid,$userid)){
-                                               $childlist = array();
-                                                       $res = scorm_get_available_children($sco);
-                                                       $i = sizeof($res)-1;
-                                                       $children = $res->value;
-
-                                                       while (i>=0){
-                                                               $pos = array_rand($children);
-                                                               array_push($childlist,$children [$pos]);
-                                                               array_splice($children,$pos,1);
-                                                               $i--;
-                                                       }
-                                                       
-                                                       $clist = serialize ($childlist);
-                                                       scorm_seq_set('availablechildren', $scoid, $userid, false);
-                                                       scorm_seq_set('availablechildren', $scoid, $userid, $clist);
-
-
-                                       }
-                                   }
+                        if(scorm_seq_is('randomizechildren',$scoid,$userid)){
+                            $childlist = array();
+                            $res = scorm_get_available_children($sco);
+                            $i = sizeof($res)-1;
+                            $children = $res->value;
+
+                            while ($i>=0){
+                                $pos = array_rand($children);
+                                array_push($childlist,$children [$pos]);
+                                array_splice($children,$pos,1);
+                                $i--;
+                            }
+                            
+                            $clist = serialize ($childlist);
+                            scorm_seq_set('availablechildren', $scoid, $userid, false);
+                            scorm_seq_set('availablechildren', $scoid, $userid, $clist);
+
+
+                        }
+                    }
                 break;
-                        
+             
+               
                
-                          
             }
 
-               }
-       }
+        }
+    }
 }
 
 function scorm_terminate_descendent_attempts ($activity,$userid,$seq){
-       $ancestors = scorm_get_ancestors($seq->currentactivity);
+    $ancestors = scorm_get_ancestors($seq->currentactivity);
     $commonpos = scorm_find_common_ancestor($ancestors,$activity);
         if ($commonpos !== false) {
             if ($activitypath = array_slice($ancestors,1,$commonpos-2)) {
-                               if (!empty ($activitypath)){
+                if (!empty ($activitypath)){
 
                     foreach ($activitypath as $sco) {
-                                               scorm_seq_end_attempt($sco,$userid,$seq->attempt);
-                                          
-                                   }
-                               }
-                       }
-               
+                        scorm_seq_end_attempt($sco,$userid,$seq->attempt);
+                       
+                    }
+                }
+            }
+        } 
 }
 
 function scorm_sequencing_exception($seq){
     if($seq->exception != null){
-               switch($seq->exception){
+        switch($seq->exception){
 
-                       case 'NB.2.1-1':
+            case 'NB.2.1-1':
                 notify("Sequencing session has already begun");
             break;
             case 'NB.2.1-2':
                 notify("Sequencing session has not begun");
             break;
-                       case 'NB.2.1-3':
+            case 'NB.2.1-3':
                 notify("Suspended activity is not defined");
             break;
-                       case 'NB.2.1-4':
+            case 'NB.2.1-4':
                 notify("Flow Sequencing Control Model Violation");
             break;
-                       case 'NB.2.1-5':
+            case 'NB.2.1-5':
                 notify("Flow or Forward only Sequencing Control Model Violation");
             break;
-                       case 'NB.2.1-6':
+            case 'NB.2.1-6':
                 notify("No activity is previous to the root");
             break;
-                       case 'NB.2.1-7':
+            case 'NB.2.1-7':
                 notify("Unsupported Navigation Request");
             break;
-                       case 'NB.2.1-8':
+            case 'NB.2.1-8':
                 notify("Choice Exit Sequencing Control Model Violation");
             break;
-                       case 'NB.2.1-9':
+            case 'NB.2.1-9':
                 notify("No activities to consider");
             break;
-                       case 'NB.2.1-10':
+            case 'NB.2.1-10':
                 notify("Choice Sequencing Control Model Violation");
             break;
-                       case 'NB.2.1-11':
+            case 'NB.2.1-11':
                 notify("Target Activity does not exist");
             break;
-                       case 'NB.2.1-12':
+            case 'NB.2.1-12':
                 notify("Current Activity already terminated");
             break;
-                       case 'NB.2.1-13':
+            case 'NB.2.1-13':
                 notify("Undefined Navigation Request");
             break;
 
-                       case 'TB.2.3-1':
+            case 'TB.2.3-1':
                 notify("Current Activity already terminated");
             break;
-                       case 'TB.2.3-2':
+            case 'TB.2.3-2':
                 notify("Current Activity already terminated");
             break;
-                       case 'TB.2.3-4':
+            case 'TB.2.3-4':
                 notify("Current Activity already terminated");
             break;
-                       case 'TB.2.3-5':
+            case 'TB.2.3-5':
                 notify("Nothing to suspend; No active activities");
             break;
-                       case 'TB.2.3-6':
+            case 'TB.2.3-6':
                 notify("Nothing to abandon; No active activities");
             break;
 
-                       case 'SB.2.1-1':
+            case 'SB.2.1-1':
                 notify("Last activity in the tree");
             break;
             case 'SB.2.1-2':
                 notify("Cluster has no available children");
             break;
-                       case 'SB.2.1-3':
+            case 'SB.2.1-3':
                 notify("No activity is previous to the root");
             break;
-                       case 'SB.2.1-4':
+            case 'SB.2.1-4':
                 notify("Forward Only Sequencing Control Model Violation");
             break;
 
-                       case 'SB.2.2-1':
+            case 'SB.2.2-1':
                 notify("Flow Sequencing Control Model Violation");
             break;
-                       case 'SB.2.2-2':
+            case 'SB.2.2-2':
                 notify("Activity unavailable");
             break;
 
-                       case 'SB.2.3-1':
+            case 'SB.2.3-1':
                 notify("Forward Traversal Blocked");
             break;
             case 'SB.2.3-2':
                 notify("Forward Only Sequencing Control Model Violation");
             break;
-                       case 'SB.2.3-3':
+            case 'SB.2.3-3':
                 notify("No activity is previous to the root");
             break;
 
-                       case 'SB.2.5-1':
+            case 'SB.2.5-1':
                 notify("Sequencing session has already begun");
             break;
 
-                       case 'SB.2.6-1':
+            case 'SB.2.6-1':
                 notify("Sequencing session has already begun");
             break;
-                       case 'SB.2.6-2':
+            case 'SB.2.6-2':
                 notify("No Suspended activity is defined");
             break;
 
             case 'SB.2.7-1':
                 notify("Sequencing session has not begun");
             break;
-                       case 'SB.2.7-2':
+            case 'SB.2.7-2':
                 notify("Flow Sequencing Control Model Violation");
             break;
 
-                       case 'SB.2.8-1':
+            case 'SB.2.8-1':
                 notify("Sequencing session has not begun");
             break;
-                       case 'SB.2.8-2':
+            case 'SB.2.8-2':
                 notify("Flow Sequencing Control Model Violation");
             break;
 
-                       case 'SB.2.9-1':
+            case 'SB.2.9-1':
                 notify("No target for Choice");
             break;
-                       case 'SB.2.9-2':
+            case 'SB.2.9-2':
                 notify("Target Activity does not exist or is unavailable");
             break;
-                       case 'SB.2.9-3':
+            case 'SB.2.9-3':
                 notify("Target Activity hidden from choice");
             break;
-                       case 'SB.2.9-4':
+            case 'SB.2.9-4':
                 notify("Choice Sequencing Control Model Violation");
             break;
-                       case 'SB.2.9-5':
+            case 'SB.2.9-5':
                 notify("No activities to consider");
             break;
-                       case 'SB.2.9-6':
+            case 'SB.2.9-6':
                 notify("Unable to activate target; target is not a child of the Current Activity");
             break;
-                       case 'SB.2.9-7':
+            case 'SB.2.9-7':
                 notify("Choice Exit Sequencing Control Model Violation");
             break;
-                       case 'SB.2.9-8':
+            case 'SB.2.9-8':
                 notify("Unable to choose target activity - constrained choice");
             break;
-                       case 'SB.2.9-9':
+            case 'SB.2.9-9':
                 notify("Choice Request Prevented by Flow-only Activity");
             break;
 
-                       case 'SB.2.10-1':
+            case 'SB.2.10-1':
                 notify("Sequencing session has not begun");
             break;
-                       case 'SB.2.10-2':
+            case 'SB.2.10-2':
                 notify("Current Activity is active or suspended");
             break;
-                       case 'SB.2.10-3':
+            case 'SB.2.10-3':
                 notify("Flow Sequencing Control Model Violation");
             break;
             
             case 'SB.2.11-1':
                 notify("Sequencing session has not begun");
             break;
-                       case 'SB.2.11-2':
+            case 'SB.2.11-2':
                 notify("Current Activity has not been terminated");
             break;
 
-                       case 'SB.2.12-2':
+            case 'SB.2.12-2':
                 notify("Undefined Sequencing Request");
             break;
 
-                       case 'DB.1.1-1':
+            case 'DB.1.1-1':
                 notify("Cannot deliver a non-leaf activity");
             break;
-                       case 'DB.1.1-2':
+            case 'DB.1.1-2':
                 notify("Nothing to deliver");
             break;
-                       case 'DB.1.1-3':
+            case 'DB.1.1-3':
                 notify("Activity unavailable");
             break;
 
-                       case 'DB.2-1':
+            case 'DB.2-1':
                 notify("Identified activity is already active");
             break;
-                                        
-               }
+                     
+        }
                
-       }
+    }
 }
 
 
 
 
-?>
\ No newline at end of file
+?>