Some more work in progress on attachments.
[timetracker.git] / WEB-INF / lib / common.lib.php
index f483b3d..e09a943 100644 (file)
@@ -165,7 +165,7 @@ function check_extension($ext)
 // isTrue is a helper function to return correct false for older config.php values defined as a string 'false'.
 function isTrue($val)
 {
-  return ($val === true);
+  return (defined($val) && constant($val) === true);
 }
 
 // ttValidString is used to check user input to validate a string.
@@ -406,3 +406,14 @@ function ttDateToUserFormat($date)
   $o_date = new DateAndTime(DB_DATEFORMAT, $date);
   return $o_date->toString($user->date_format);
 }
+
+// ttRandomString generates a random alphanumeric string.
+function ttRandomString($length = 32) {
+  $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
+  $charactersLength = strlen($characters);
+  $randomString = '';
+  for ($i = 0; $i < $length; $i++) {
+    $randomString .= $characters[rand(0, $charactersLength - 1)];
+  }
+  return $randomString;
+}