shop.balmet.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

register.php (14338B)


      1 <?php
      2 class ControllerAffiliateRegister extends Controller {
      3 	private $error = array();
      4 
      5 	public function index() {
      6 		if ($this->customer->isLogged()) {
      7 			$this->response->redirect($this->url->link('account/account', '', true));
      8 		}
      9 
     10 		$this->load->language('affiliate/register');
     11 
     12 		$this->document->setTitle($this->language->get('heading_title'));
     13 		
     14 		$this->document->addScript('catalog/view/javascript/jquery/datetimepicker/moment/moment.min.js');
     15 		$this->document->addScript('catalog/view/javascript/jquery/datetimepicker/moment/moment-with-locales.min.js');
     16 		$this->document->addScript('catalog/view/javascript/jquery/datetimepicker/bootstrap-datetimepicker.min.js');
     17 		$this->document->addStyle('catalog/view/javascript/jquery/datetimepicker/bootstrap-datetimepicker.min.css');
     18 
     19 		$this->load->model('account/customer');
     20 
     21 		if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
     22 			$customer_id = $this->model_account_customer->addCustomer($this->request->post);
     23 
     24 			$this->model_account_customer->addAffiliate($customer_id, $this->request->post);
     25 
     26 			// Clear any previous login attempts in not registered.
     27 			$this->model_account_customer->deleteLoginAttempts($this->request->post['email']);
     28 
     29 			$this->customer->login($this->request->post['email'], $this->request->post['password']);
     30 
     31 			$this->response->redirect($this->url->link('affiliate/success'));
     32 		}
     33 
     34 		$data['breadcrumbs'] = array();
     35 
     36 		$data['breadcrumbs'][] = array(
     37 			'text' => $this->language->get('text_home'),
     38 			'href' => $this->url->link('common/home')
     39 		);
     40 
     41 		$data['breadcrumbs'][] = array(
     42 			'text' => $this->language->get('text_account'),
     43 			'href' => $this->url->link('account/account', '', true)
     44 		);
     45 
     46 		$data['breadcrumbs'][] = array(
     47 			'text' => $this->language->get('text_register'),
     48 			'href' => $this->url->link('affiliate/register', '', true)
     49 		);
     50 
     51 		$data['text_account_already'] = sprintf($this->language->get('text_account_already'), $this->url->link('affiliate/login', '', true));
     52 
     53 		if (isset($this->error['warning'])) {
     54 			$data['error_warning'] = $this->error['warning'];
     55 		} else {
     56 			$data['error_warning'] = '';
     57 		}
     58 
     59 		if (isset($this->error['firstname'])) {
     60 			$data['error_firstname'] = $this->error['firstname'];
     61 		} else {
     62 			$data['error_firstname'] = '';
     63 		}
     64 
     65 		if (isset($this->error['lastname'])) {
     66 			$data['error_lastname'] = $this->error['lastname'];
     67 		} else {
     68 			$data['error_lastname'] = '';
     69 		}
     70 
     71 		if (isset($this->error['email'])) {
     72 			$data['error_email'] = $this->error['email'];
     73 		} else {
     74 			$data['error_email'] = '';
     75 		}
     76 
     77 		if (isset($this->error['telephone'])) {
     78 			$data['error_telephone'] = $this->error['telephone'];
     79 		} else {
     80 			$data['error_telephone'] = '';
     81 		}
     82 
     83 		if (isset($this->error['password'])) {
     84 			$data['error_password'] = $this->error['password'];
     85 		} else {
     86 			$data['error_password'] = '';
     87 		}
     88 
     89 		if (isset($this->error['confirm'])) {
     90 			$data['error_confirm'] = $this->error['confirm'];
     91 		} else {
     92 			$data['error_confirm'] = '';
     93 		}
     94 		
     95 		if (isset($this->error['custom_field'])) {
     96 			$data['error_custom_field'] = $this->error['custom_field'];
     97 		} else {
     98 			$data['error_custom_field'] = array();
     99 		}
    100 		
    101 		if (isset($this->error['cheque'])) {
    102 			$data['error_cheque'] = $this->error['cheque'];
    103 		} else {
    104 			$data['error_cheque'] = '';
    105 		}
    106 
    107 		if (isset($this->error['paypal'])) {
    108 			$data['error_paypal'] = $this->error['paypal'];
    109 		} else {
    110 			$data['error_paypal'] = '';
    111 		}
    112 
    113 		if (isset($this->error['bank_account_name'])) {
    114 			$data['error_bank_account_name'] = $this->error['bank_account_name'];
    115 		} else {
    116 			$data['error_bank_account_name'] = '';
    117 		}
    118 
    119 		if (isset($this->error['bank_account_number'])) {
    120 			$data['error_bank_account_number'] = $this->error['bank_account_number'];
    121 		} else {
    122 			$data['error_bank_account_number'] = '';
    123 		}
    124 				
    125 		$data['action'] = $this->url->link('affiliate/register', '', true);
    126 
    127 		$data['customer_groups'] = array();
    128 
    129 		if (is_array($this->config->get('config_customer_group_display'))) {
    130 			$this->load->model('account/customer_group');
    131 
    132 			$customer_groups = $this->model_account_customer_group->getCustomerGroups();
    133 
    134 			foreach ($customer_groups as $customer_group) {
    135 				if (in_array($customer_group['customer_group_id'], $this->config->get('config_customer_group_display'))) {
    136 					$data['customer_groups'][] = $customer_group;
    137 				}
    138 			}
    139 		}
    140 
    141 		if (isset($this->request->post['customer_group_id'])) {
    142 			$data['customer_group_id'] = $this->request->post['customer_group_id'];
    143 		} else {
    144 			$data['customer_group_id'] = $this->config->get('config_affiliate_group_id');
    145 		}
    146 		
    147 		if (isset($this->request->post['firstname'])) {
    148 			$data['firstname'] = $this->request->post['firstname'];
    149 		} else {
    150 			$data['firstname'] = '';
    151 		}
    152 
    153 		if (isset($this->request->post['lastname'])) {
    154 			$data['lastname'] = $this->request->post['lastname'];
    155 		} else {
    156 			$data['lastname'] = '';
    157 		}
    158 
    159 		if (isset($this->request->post['email'])) {
    160 			$data['email'] = $this->request->post['email'];
    161 		} else {
    162 			$data['email'] = '';
    163 		}
    164 
    165 		if (isset($this->request->post['telephone'])) {
    166 			$data['telephone'] = $this->request->post['telephone'];
    167 		} else {
    168 			$data['telephone'] = '';
    169 		}
    170 
    171 		if (isset($this->request->post['company'])) {
    172 			$data['company'] = $this->request->post['company'];
    173 		} else {
    174 			$data['company'] = '';
    175 		}
    176 
    177 		// Custom Fields
    178 		$this->load->model('account/custom_field');
    179 
    180 		$data['custom_fields'] = $this->model_account_custom_field->getCustomFields();
    181 
    182 		if (isset($this->request->post['custom_field'])) {
    183 			if (isset($this->request->post['custom_field']['account'])) {
    184 				$account_custom_field = $this->request->post['custom_field']['account'];
    185 			} else {
    186 				$account_custom_field = array();
    187 			}
    188 			
    189 			if (isset($this->request->post['custom_field']['affiliate'])) {
    190 				$affiliate_custom_field = $this->request->post['custom_field']['affiliate'];
    191 			} else {
    192 				$affiliate_custom_field = array();
    193 			}
    194 			
    195 			$data['register_custom_field'] = $account_custom_field + $affiliate_custom_field;
    196 		} else {
    197 			$data['register_custom_field'] = array();
    198 		}
    199 
    200 		if (isset($this->request->post['website'])) {
    201 			$data['website'] = $this->request->post['website'];
    202 		} else {
    203 			$data['website'] = '';
    204 		}
    205 		
    206 		if (isset($this->request->post['tax'])) {
    207 			$data['tax'] = $this->request->post['tax'];
    208 		} else {
    209 			$data['tax'] = '';
    210 		}
    211 
    212 		if (isset($this->request->post['payment'])) {
    213 			$data['payment'] = $this->request->post['payment'];
    214 		} else {
    215 			$data['payment'] = 'cheque';
    216 		}
    217 
    218 		if (isset($this->request->post['cheque'])) {
    219 			$data['cheque'] = $this->request->post['cheque'];
    220 		} else {
    221 			$data['cheque'] = '';
    222 		}
    223 
    224 		if (isset($this->request->post['paypal'])) {
    225 			$data['paypal'] = $this->request->post['paypal'];
    226 		} else {
    227 			$data['paypal'] = '';
    228 		}
    229 
    230 		if (isset($this->request->post['bank_name'])) {
    231 			$data['bank_name'] = $this->request->post['bank_name'];
    232 		} else {
    233 			$data['bank_name'] = '';
    234 		}
    235 
    236 		if (isset($this->request->post['bank_branch_number'])) {
    237 			$data['bank_branch_number'] = $this->request->post['bank_branch_number'];
    238 		} else {
    239 			$data['bank_branch_number'] = '';
    240 		}
    241 
    242 		if (isset($this->request->post['bank_swift_code'])) {
    243 			$data['bank_swift_code'] = $this->request->post['bank_swift_code'];
    244 		} else {
    245 			$data['bank_swift_code'] = '';
    246 		}
    247 
    248 		if (isset($this->request->post['bank_account_name'])) {
    249 			$data['bank_account_name'] = $this->request->post['bank_account_name'];
    250 		} else {
    251 			$data['bank_account_name'] = '';
    252 		}
    253 
    254 		if (isset($this->request->post['bank_account_number'])) {
    255 			$data['bank_account_number'] = $this->request->post['bank_account_number'];
    256 		} else {
    257 			$data['bank_account_number'] = '';
    258 		}
    259 
    260 		if (isset($this->request->post['password'])) {
    261 			$data['password'] = $this->request->post['password'];
    262 		} else {
    263 			$data['password'] = '';
    264 		}
    265 
    266 		if (isset($this->request->post['confirm'])) {
    267 			$data['confirm'] = $this->request->post['confirm'];
    268 		} else {
    269 			$data['confirm'] = '';
    270 		}
    271 
    272 		// Captcha
    273 		if ($this->config->get('captcha_' . $this->config->get('config_captcha') . '_status') && in_array('register', (array)$this->config->get('config_captcha_page'))) {
    274 			$data['captcha'] = $this->load->controller('extension/captcha/' . $this->config->get('config_captcha'), $this->error);
    275 		} else {
    276 			$data['captcha'] = '';
    277 		}
    278 
    279 		if ($this->config->get('config_affiliate_id')) {
    280 			$this->load->model('catalog/information');
    281 
    282 			$information_info = $this->model_catalog_information->getInformation($this->config->get('config_affiliate_id'));
    283 
    284 			if ($information_info) {
    285 				$data['text_agree'] = sprintf($this->language->get('text_agree'), $this->url->link('information/information/agree', 'information_id=' . $this->config->get('config_affiliate_id'), true), $information_info['title'], $information_info['title']);
    286 			} else {
    287 				$data['text_agree'] = '';
    288 			}
    289 		} else {
    290 			$data['text_agree'] = '';
    291 		}
    292 
    293 		if (isset($this->request->post['agree'])) {
    294 			$data['agree'] = $this->request->post['agree'];
    295 		} else {
    296 			$data['agree'] = false;
    297 		}
    298 
    299 		$data['column_left'] = $this->load->controller('common/column_left');
    300 		$data['column_right'] = $this->load->controller('common/column_right');
    301 		$data['content_top'] = $this->load->controller('common/content_top');
    302 		$data['content_bottom'] = $this->load->controller('common/content_bottom');
    303 		$data['footer'] = $this->load->controller('common/footer');
    304 		$data['header'] = $this->load->controller('common/header');
    305 
    306 		$this->response->setOutput($this->load->view('affiliate/register', $data));
    307 	}
    308 
    309 	protected function validate() {
    310 		if ((utf8_strlen(trim($this->request->post['firstname'])) < 1) || (utf8_strlen(trim($this->request->post['firstname'])) > 32)) {
    311 			$this->error['firstname'] = $this->language->get('error_firstname');
    312 		}
    313 
    314 		if ((utf8_strlen(trim($this->request->post['lastname'])) < 1) || (utf8_strlen(trim($this->request->post['lastname'])) > 32)) {
    315 			$this->error['lastname'] = $this->language->get('error_lastname');
    316 		}
    317 
    318 		if ((utf8_strlen($this->request->post['email']) > 96) || !filter_var($this->request->post['email'], FILTER_VALIDATE_EMAIL)) {
    319 			$this->error['email'] = $this->language->get('error_email');
    320 		}
    321 
    322 		if ($this->model_account_customer->getTotalCustomersByEmail($this->request->post['email'])) {
    323 			$this->error['warning'] = $this->language->get('error_exists');
    324 		}
    325 
    326 		if ((utf8_strlen($this->request->post['telephone']) < 3) || (utf8_strlen($this->request->post['telephone']) > 32)) {
    327 			$this->error['telephone'] = $this->language->get('error_telephone');
    328 		}
    329 
    330 		// Customer Group
    331 		if (isset($this->request->post['customer_group_id']) && is_array($this->config->get('config_customer_group_display')) && in_array($this->request->post['customer_group_id'], $this->config->get('config_customer_group_display'))) {
    332 			$customer_group_id = $this->request->post['customer_group_id'];
    333 		} else {
    334 			$customer_group_id = $this->config->get('config_affiliate_group_id');
    335 		}
    336 
    337 		// Custom field validation
    338 		$this->load->model('account/custom_field');
    339 
    340 		$custom_fields = $this->model_account_custom_field->getCustomFields($customer_group_id);
    341 		
    342 		foreach ($custom_fields as $custom_field) {
    343             if ($custom_field['required'] && empty($this->request->post['custom_field'][$custom_field['location']][$custom_field['custom_field_id']])) {
    344 				$this->error['custom_field'][$custom_field['custom_field_id']] = sprintf($this->language->get('error_custom_field'), $custom_field['name']);
    345 			} elseif (($custom_field['type'] == 'text') && !empty($custom_field['validation']) && !filter_var($this->request->post['custom_field'][$custom_field['location']][$custom_field['custom_field_id']], FILTER_VALIDATE_REGEXP, array('options' => array('regexp' => $custom_field['validation'])))) {
    346             	$this->error['custom_field'][$custom_field['custom_field_id']] = sprintf($this->language->get('error_custom_field'), $custom_field['name']);
    347             }
    348 		}
    349 
    350 		if ((utf8_strlen(html_entity_decode($this->request->post['password'], ENT_QUOTES, 'UTF-8')) < 4) || (utf8_strlen(html_entity_decode($this->request->post['password'], ENT_QUOTES, 'UTF-8')) > 40)) {
    351 			$this->error['password'] = $this->language->get('error_password');
    352 		}
    353 
    354 		if ($this->request->post['confirm'] != $this->request->post['password']) {
    355 			$this->error['confirm'] = $this->language->get('error_confirm');
    356 		}
    357 		
    358 		if (($this->request->post['payment'] == 'cheque') && !$this->request->post['cheque']) {
    359 			$this->error['cheque'] = $this->language->get('error_cheque');
    360 		} elseif (($this->request->post['payment'] == 'paypal') && ((utf8_strlen($this->request->post['paypal']) > 96) || !filter_var($this->request->post['paypal'], FILTER_VALIDATE_EMAIL))) {
    361 			$this->error['paypal'] = $this->language->get('error_paypal');
    362 		} elseif ($this->request->post['payment'] == 'bank') {
    363 			if (!$this->request->post['bank_account_name']) {
    364 				$this->error['bank_account_name'] = $this->language->get('error_bank_account_name');
    365 			}
    366 	
    367 			if (!$this->request->post['bank_account_number']) {
    368 				$this->error['bank_account_number'] = $this->language->get('error_bank_account_number');
    369 			}
    370 		}
    371 			
    372 		// Captcha
    373 		if ($this->config->get('captcha_' . $this->config->get('config_captcha') . '_status') && in_array('register', (array)$this->config->get('config_captcha_page'))) {
    374 			$captcha = $this->load->controller('extension/captcha/' . $this->config->get('config_captcha') . '/validate');
    375 
    376 			if ($captcha) {
    377 				$this->error['captcha'] = $captcha;
    378 			}
    379 		}
    380 
    381 		if ($this->config->get('config_affiliate_id')) {
    382 			$this->load->model('catalog/information');
    383 
    384 			$information_info = $this->model_catalog_information->getInformation($this->config->get('config_affiliate_id'));
    385 
    386 			if ($information_info && !isset($this->request->post['agree'])) {
    387 				$this->error['warning'] = sprintf($this->language->get('error_agree'), $information_info['title']);
    388 			}
    389 		}
    390 
    391 		return !$this->error;
    392 	}
    393 }