<?php

class ControllerExtensionModuleTrackingInputEvent extends Controller {

	public function eventModuleTAfter(&$route, &$data, &$output) {		
		$output .= "\n" . '<script type="text/javascript">$(\'#tracking-input-div\').data(\'d\', ' . $data['json'] . ');</script>' . "\n";
	}
	
	public function eventAddEditAffiliateAfter(&$route, &$args, &$output) {
		$customer_id = $args[0];
		$data = $args[1];		
		if(isset($data['tracking']) && !isset($data['tracking_input'])) $data['tracking_input'] = $data['tracking'];
		if($this->config->get('module_tracking_input_status') && $this->config->get('module_tracking_input_choose_code') && isset($data['tracking_input']) && preg_match("/^[\w\-]+$/", $data['tracking_input']) && strlen($data['tracking_input']) < 65) $this->db->query("UPDATE " . DB_PREFIX . "customer_affiliate SET `tracking` = '" . $this->db->escape($data['tracking_input']) . "' WHERE customer_id = '" . (int)$customer_id . "'");		
	}

}