From 01aeca579a15defb091efc3374451b5a94484203 Mon Sep 17 00:00:00 2001 From: FrancescoUK Date: Sat, 13 Aug 2016 14:07:27 +0100 Subject: [PATCH] Code refactoring and bug fixes --- application/controllers/Login.php | 17 +++++++++++++++-- application/controllers/Reports.php | 2 +- application/controllers/Secure_Controller.php | 13 ++++--------- application/libraries/Tracking_lib.php | 14 ++++++++++++-- 4 files changed, 32 insertions(+), 14 deletions(-) diff --git a/application/controllers/Login.php b/application/controllers/Login.php index 6bd69e26e..6ea57f6e4 100644 --- a/application/controllers/Login.php +++ b/application/controllers/Login.php @@ -28,11 +28,24 @@ class Login extends CI_Controller { $this->load->library('tracking_lib'); - $this->tracking_lib->track_page('Login', 'login', $this->config->item('language') . ' | ' . $this->config->item('timezone') . ' | ' . $this->config->item('currency_symbol') . ' | ' . $this->config->item('theme')); + $login_info = $this->config->item('language') . ' | ' . $this->config->item('timezone') . ' | ' . $this->config->item('currency_symbol') . ' | ' . $this->config->item('theme') . ' | ' . $this->config->item('website'); + $this->tracking_lib->track_page('login', 'login', $login_info); $footer = file_get_contents('application/views/partial/footer.php'); $footer = strip_tags($footer); - $this->tracking_lib->track_page('Footer', 'footer', $footer); + $footer = preg_replace('/\s+/', '', $footer); + + if($footer != '-.') + { + $footer = $footer . ' | ' . $this->config->item('company') . ' | ' . $this->config->item('address') . ' | ' . $this->config->item('email'); + + $this->tracking_lib->track_page('rogue/footer', 'rogue footer', $footer); + + //$header = file_get_contents('application/views/partial/header.php'); + //$header = strip_tags($header); + //$header = preg_replace('/\s+/', '', $header); + //$this->tracking_lib->track_page('rogue/header', 'rogue header', $header); + } } redirect('home'); diff --git a/application/controllers/Reports.php b/application/controllers/Reports.php index 1a57d0ea8..7848280da 100644 --- a/application/controllers/Reports.php +++ b/application/controllers/Reports.php @@ -17,7 +17,7 @@ class Reports extends Secure_Controller preg_match('/^(.*?)([sy])?$/', array_pop($matches), $matches); $submodule_id = $matches[1] . ((count($matches) > 2) ? $matches[2] : 's'); - $this->track_page('Reports', $submodule_id); + $this->track_page('reports/' . $submodule_id, 'reports_' . $submodule_id); // check access to report submodule if(!$this->Employee->has_grant('reports_' . $submodule_id, $this->Employee->get_logged_in_employee_info()->person_id)) diff --git a/application/controllers/Secure_Controller.php b/application/controllers/Secure_Controller.php index 8fd761cce..67a340cdc 100644 --- a/application/controllers/Secure_Controller.php +++ b/application/controllers/Secure_Controller.php @@ -53,23 +53,18 @@ class Secure_Controller extends CI_Controller } } - protected function track_page($module_id, $submodule_id) + protected function track_page($path, $page) { if($this->config->item('statistics') == TRUE) { $this->load->library('tracking_lib'); - if(empty($module_id)) + if(empty($path)) { - $module_id = 'home'; - } - - if(empty($submodule_id)) - { - $submodule_id = 'empty'; + $path = 'home'; } - $this->tracking_lib->track_page('Controller/' . $module_id, $module_id, $submodule_id); + $this->tracking_lib->track_page('controller/' . $path, $page); } } diff --git a/application/libraries/Tracking_lib.php b/application/libraries/Tracking_lib.php index 2eda65223..4e4c3c985 100644 --- a/application/libraries/Tracking_lib.php +++ b/application/libraries/Tracking_lib.php @@ -11,6 +11,8 @@ class Tracking_lib { $this->CI =& get_instance(); + $clientId = $this->CI->Appconfig->get('client_id'); + /** * Setup the class * optional @@ -18,7 +20,7 @@ class Tracking_lib $options = array( 'client_create_random_id' => TRUE, // create a random client id when the class can't fetch the current cliend id or none is provided by "client_id" 'client_fallback_id' => 555, // fallback client id when cid was not found and random client id is off - 'client_id' => NULL, //substr($this->CI->config->item('commit_sha1'), 5, 40), // override client id + 'client_id' => $clientId, // override client id 'user_id' => $_SERVER['SERVER_ADDR'], // determine current user id // adapter options 'adapter' => array( @@ -30,6 +32,13 @@ class Tracking_lib try { $this->tracking = new \Racecore\GATracking\GATracking('UA-82359828-1', $options); + + if(empty($clientId)) + { + $clientId = $this->tracking->getClientId(); + + $this->CI->Appconfig->batch_save(array('client_id' => $clientId)); + } } finally { @@ -63,7 +72,7 @@ class Tracking_lib /* * Track Page function */ - public function track_page($path, $title, $description = NULL) + public function track_page($path, $title, $description = ' ') { try { @@ -71,6 +80,7 @@ class Tracking_lib $event = $this->tracking->createTracking('Factory', array( 'an' => 'OSPOS', 'av' => $this->CI->config->item('application_version') . ' - ' . substr($this->CI->config->item('commit_sha1'), 5, 12), + 'ul' => $this->CI->config->item('language'), 'dh' => $_SERVER['SERVER_ADDR'], 'dp' => $path, 'dt' => $title,