Small fix in session.inc and extension of reference incrementation algorithm
authorJanusz Dobrowolski <janusz@frontaccounting.eu>
Wed, 6 Jan 2010 07:31:51 +0000 (07:31 +0000)
committerJanusz Dobrowolski <janusz@frontaccounting.eu>
Wed, 6 Jan 2010 07:31:51 +0000 (07:31 +0000)
CHANGELOG.txt
includes/references.inc
includes/session.inc

index ee1ccf72e7707564998b8789a627fe978873a214..de25f853df21967e6fdcfebfca1f40c7c9c6195a 100644 (file)
@@ -19,6 +19,12 @@ Legend:
 ! -> Note
 $ -> Affected files
 
+06-Jan-2010 Janusz Dobrowolski
+# Check on existence of locale.inc added to avoid blank pages when the file is broken.
+$ /includes/session.inc
+! Changed reference incrementation algorithm to preserve both number prefix and postfix.
+$ /includes/references.inc
+
 04-Jan-2010 Joe Hunt
 ! Making the stretch parameter = 1 on default print pdf all over
   Improved layout on documents.
index 6487404b299546ff98f77cd89110b562b7042609..420e960e805d0169280c8d8dafd73dcd25656398 100644 (file)
@@ -64,16 +64,19 @@ class references
        function increment($reference) 
        {
                // New method done by Pete. So f.i. WA036 will increment to WA037 and so on.
-               // If $reference is trailed by digits, and digits only,
-        // extract them and add 1, then put the alpha prefix back on
+               // If $reference contains at least one group of digits,
+        // extract first didgits group and add 1, then put all together.
         // NB. preg_match returns 1 if the regex matches completely 
         // also $result[0] holds entire string, 1 the first captured, 2 the 2nd etc.
-        if (preg_match('/^(.*?)(\d+)$/', $reference, $result) == 1) 
+        //
+        if (preg_match('/^(\D*?)(\d+)(.*)/', $reference, $result) == 1) 
         {
-            $dig_count = strlen($result[2]); // How many digits? eg. 0003 = 4
-            $fmt = '%0' . $dig_count . 'd'; // Make a format string - leading zeroes
-            $nextval =  $result[1] . sprintf($fmt, intval($result[2] + 1)); // Add one on, and put prefix back on
-            return $nextval;
+                       list($all, $prefix, $number, $postfix) = $result;
+                       $dig_count = strlen($number); // How many digits? eg. 0003 = 4
+                       $fmt = '%0' . $dig_count . 'd'; // Make a format string - leading zeroes
+                       $nextval =  sprintf($fmt, intval($number + 1)); // Add one on, and put prefix back on
+
+                       return $prefix.$nextval.$postfix;
         }
         else 
             return $reference;
index ba703dee0e8432e5dbd442cfcfd78b2e66db3be8..8929ff2e4341e83a777b7e75ebd4fb7d76e8789c 100644 (file)
@@ -176,8 +176,9 @@ if (!isset($_SESSION['language']))
 $_SESSION['language']->set_language($_SESSION['language']->code);
 
 // include $Hooks object if locale file exists
-if(@include_once($path_to_root . "/lang/".$_SESSION['language']->code."/locale.inc")) 
+if (file_exists($path_to_root . "/lang/".$_SESSION['language']->code."/locale.inc"))
 {
+       include_once($path_to_root . "/lang/".$_SESSION['language']->code."/locale.inc");
        $Hooks = new Hooks();
 }