diff --git a/Code_Igniter/application/controllers/webform.php b/Code_Igniter/application/controllers/webform.php index 51a66c3c..811f8aaf 100644 --- a/Code_Igniter/application/controllers/webform.php +++ b/Code_Igniter/application/controllers/webform.php @@ -25,7 +25,7 @@ function __construct() parent::__construct(); $this->load->helper(array('subdomain','url', 'form')); $this->load->model('Survey_model','',TRUE); - $this->load->library('encrypt'); + $this->load->library(array('encrypt', 'meta')); $sub = get_subdomain(); $suf = $this->Survey_model->ONLINE_SUBDOMAIN_SUFFIX; $this->subdomain = ($this->Survey_model->has_offline_launch_enabled()) @@ -39,7 +39,7 @@ function __construct() $this->xsl_version_prev = (isset($form_props['xsl_version'])) ? $form_props['xsl_version'] : NULL; } $this->iframe = ( $this->input->get('iframe', TRUE) == 'true' ); - + if ($this->config->item('auth_support')) { $this->load->add_package_path(APPPATH.'third_party/form_auth'); } @@ -48,6 +48,7 @@ function __construct() $this->load->add_package_path(APPPATH.'third_party/account'); } $this->load->library('account'); + log_message('debug', 'Webform Controller Initialized'); } @@ -295,6 +296,9 @@ private function _get_form() $this->credentials = $this->form_auth->get_credentials($s); $this->Form_model->setup($this->server_url, $this->form_id, $this->credentials, $this->form_hash_prev, $this->xsl_version_prev, $this->media_hash_prev); + $uid = ($this->credentials) ? $this->credentials['username'] : NULL; + $this->meta->setMeta($uid); + if($this->Form_model->requires_auth()) { log_message('debug', "AUTHENTICATION REQUIRED"); $form = new stdClass(); diff --git a/Code_Igniter/application/libraries/Meta.php b/Code_Igniter/application/libraries/Meta.php new file mode 100644 index 00000000..71c5c927 --- /dev/null +++ b/Code_Igniter/application/libraries/Meta.php @@ -0,0 +1,72 @@ +CI =& get_instance(); + $this->CI->load->helper('url'); + $this->domain = $this->get_domain(); + log_message('debug', 'Meta library initialized'); + } + + public function setMeta($username = NULL) { + + log_message('debug', 'setting meta with username:'.$username); + if ($username && !$this->getCookie('uid')) { + $this->setCookie( 'uid', $this->domain.':'.$username); + } + + if (!$this->getCookie('deviceid')) { + $this->setCookie('deviceid', $this->domain.':'.$this->generate_deviceid(), TRUE); + } + + } + + private function setCookie($name, $value, $expire_as_late_as_possible = FALSE ) + { + if (empty($name) || empty($value)) { + return; + } + $cookie = array( + 'name' => $this->cookie_prefix . $name, + 'value' => $value, + 'expire' => ($expire_as_late_as_possible) ? 10 * 365 * 24 * 60 * 60 : 7 * 24 * 60 *60, + 'domain' => $this->CI->config->item('cookie_domain'), + 'path' => $this->CI->config->item('cookie_path'), + 'prefix' => $this->CI->config->item('cookie_prefix'), + 'secure' => $this->CI->config->item('cookie_secure') + ); + $this->CI->input->set_cookie($cookie); + } + + private function getCookie($name) + { + return $this->CI->input->cookie($this->cookie_prefix . $name, TRUE); + } + + private function generate_deviceid() + { + $this->CI->load->helper('string'); + return random_string('alnum', 16); + } + + private function get_domain() + { + $base_url = base_url(); + return substr( $base_url, strpos($base_url, '://') + 3 ); + } +} + +/* End of file Meta.php */