summaryrefslogtreecommitdiff
path: root/includes/helper
diff options
context:
space:
mode:
Diffstat (limited to 'includes/helper')
-rw-r--r--includes/helper/graph_helper.php39
-rw-r--r--includes/helper/internationalization_helper.php14
-rw-r--r--includes/helper/session_helper.php4
3 files changed, 55 insertions, 2 deletions
diff --git a/includes/helper/graph_helper.php b/includes/helper/graph_helper.php
new file mode 100644
index 00000000..17473634
--- /dev/null
+++ b/includes/helper/graph_helper.php
@@ -0,0 +1,39 @@
+<?php
+
+/**
+ * Renders a bargraph
+ * @param string $key keyname of the x-axis
+ * @param array $row_names keynames for the data rows
+ * @param unknown $colors colors for the data rows
+ * @param unknown $data the data
+ */
+function bargraph($id, $key, $row_names, $colors, $data) {
+ $labels = [];
+ foreach ($data as $dataset)
+ $labels[] = $dataset[$key];
+
+ $datasets = [];
+ foreach ($row_names as $row_key => $name) {
+ $values = [];
+ foreach ($data as $dataset)
+ $values[] = $dataset[$row_key];
+ $datasets[] = [
+ 'label' => $name,
+ 'fillColor' => $colors[$row_key],
+ 'data' => $values
+ ];
+ }
+
+ return '<canvas id="' . $id . '" style="width: 100%; height: 300px;"></canvas>
+ <script type="text/javascript">
+ $(function(){
+ var ctx = $("#' . $id . '").get(0).getContext("2d");
+ var chart = new Chart(ctx).Bar(' . json_encode([
+ 'labels' => $labels,
+ 'datasets' => $datasets
+ ]) . ');
+ });
+ </script>';
+}
+
+?> \ No newline at end of file
diff --git a/includes/helper/internationalization_helper.php b/includes/helper/internationalization_helper.php
index 836bbc6a..a8fdd0f0 100644
--- a/includes/helper/internationalization_helper.php
+++ b/includes/helper/internationalization_helper.php
@@ -7,6 +7,20 @@ $locales = array(
$default_locale = 'en_US.UTF-8';
/**
+ * Return currently active locale
+ */
+function locale() {
+ return $_SESSION['locale'];
+}
+
+/**
+ * Returns two letter language code from currently active locale
+ */
+function locale_short() {
+ return substr(locale(), 0, 2);
+}
+
+/**
* Initializes gettext for internationalization and updates the sessions locale to use for translation.
*/
function gettext_init() {
diff --git a/includes/helper/session_helper.php b/includes/helper/session_helper.php
index 4063ff69..443701ee 100644
--- a/includes/helper/session_helper.php
+++ b/includes/helper/session_helper.php
@@ -9,7 +9,7 @@
*/
function session_lifetime($lifetime, $application_name) {
// Set session save path and name
- $session_save_path = rtrim(session_save_path(), '/') . '/' . $application_name;
+ $session_save_path = '/tmp/' . $application_name;
if (! file_exists($session_save_path))
mkdir($session_save_path);
if (file_exists($session_save_path))
@@ -22,7 +22,7 @@ function session_lifetime($lifetime, $application_name) {
ini_set('session.gc_divisor', 100);
// Cookie settings (lifetime)
- ini_set('session.cookie_secure', ! (preg_match("/^localhost/", $_SERVER["HTTP_HOST"]) || isset($_GET['debug'])));
+ ini_set('session.cookie_secure', ! (isset($_SERVER['HTTP_HOST']) && preg_match("/^localhost/", $_SERVER["HTTP_HOST"]) || isset($_GET['debug'])));
ini_set('session.use_only_cookies', true);
ini_set('session.cookie_lifetime', $lifetime * 60);
}