shop.balmet.com

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

profile.php (7215B)


      1 <?php
      2 class ControllerCommonProfile extends Controller {
      3 	private $error = array();
      4 
      5 	public function index() {
      6 		$this->load->language('common/profile');
      7 
      8 		$this->document->setTitle($this->language->get('heading_title'));
      9 
     10 		$this->load->model('user/user');
     11 
     12 		if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) {
     13 			$user_data = array_merge($this->request->post, array(
     14 				'user_group_id' => $this->user->getGroupId(),
     15 				'status'        => 1,
     16 			));
     17 			
     18 			$this->model_user_user->editUser($this->user->getId(), $user_data);
     19 
     20 			$this->session->data['success'] = $this->language->get('text_success');
     21 
     22 			$this->response->redirect($this->url->link('common/profile', 'user_token=' . $this->session->data['user_token'], true));
     23 		}
     24 
     25 		if (isset($this->session->data['success'])) {
     26 			$data['success'] = $this->session->data['success'];
     27 
     28 			unset($this->session->data['success']);
     29 		} else {
     30 			$data['success'] = '';
     31 		}
     32 
     33 		if (isset($this->error['warning'])) {
     34 			$data['error_warning'] = $this->error['warning'];
     35 		} else {
     36 			$data['error_warning'] = '';
     37 		}
     38 
     39 		if (isset($this->error['username'])) {
     40 			$data['error_username'] = $this->error['username'];
     41 		} else {
     42 			$data['error_username'] = '';
     43 		}
     44 
     45 		if (isset($this->error['password'])) {
     46 			$data['error_password'] = $this->error['password'];
     47 		} else {
     48 			$data['error_password'] = '';
     49 		}
     50 
     51 		if (isset($this->error['confirm'])) {
     52 			$data['error_confirm'] = $this->error['confirm'];
     53 		} else {
     54 			$data['error_confirm'] = '';
     55 		}
     56 
     57 		if (isset($this->error['firstname'])) {
     58 			$data['error_firstname'] = $this->error['firstname'];
     59 		} else {
     60 			$data['error_firstname'] = '';
     61 		}
     62 
     63 		if (isset($this->error['lastname'])) {
     64 			$data['error_lastname'] = $this->error['lastname'];
     65 		} else {
     66 			$data['error_lastname'] = '';
     67 		}
     68 
     69 		if (isset($this->error['email'])) {
     70 			$data['error_email'] = $this->error['email'];
     71 		} else {
     72 			$data['error_email'] = '';
     73 		}
     74 
     75 		$data['breadcrumbs'] = array();
     76 
     77 		$data['breadcrumbs'][] = array(
     78 			'text' => $this->language->get('text_home'),
     79 			'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true)
     80 		);
     81 
     82 		$data['breadcrumbs'][] = array(
     83 			'text' => $this->language->get('heading_title'),
     84 			'href' => $this->url->link('common/profile', 'user_token=' . $this->session->data['user_token'], true)
     85 		);
     86 
     87 		$data['action'] = $this->url->link('common/profile', 'user_token=' . $this->session->data['user_token'], true);
     88 
     89 		$data['cancel'] = $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true);
     90 
     91 		if ($this->request->server['REQUEST_METHOD'] != 'POST') {
     92 			$user_info = $this->model_user_user->getUser($this->user->getId());
     93 		}
     94 
     95 		if (isset($this->request->post['username'])) {
     96 			$data['username'] = $this->request->post['username'];
     97 		} elseif (!empty($user_info)) {
     98 			$data['username'] = $user_info['username'];
     99 		} else {
    100 			$data['username'] = '';
    101 		}
    102 
    103 		if (isset($this->request->post['password'])) {
    104 			$data['password'] = $this->request->post['password'];
    105 		} else {
    106 			$data['password'] = '';
    107 		}
    108 
    109 		if (isset($this->request->post['confirm'])) {
    110 			$data['confirm'] = $this->request->post['confirm'];
    111 		} else {
    112 			$data['confirm'] = '';
    113 		}
    114 
    115 		if (isset($this->request->post['firstname'])) {
    116 			$data['firstname'] = $this->request->post['firstname'];
    117 		} elseif (!empty($user_info)) {
    118 			$data['firstname'] = $user_info['firstname'];
    119 		} else {
    120 			$data['firstname'] = '';
    121 		}
    122 
    123 		if (isset($this->request->post['lastname'])) {
    124 			$data['lastname'] = $this->request->post['lastname'];
    125 		} elseif (!empty($user_info)) {
    126 			$data['lastname'] = $user_info['lastname'];
    127 		} else {
    128 			$data['lastname'] = '';
    129 		}
    130 
    131 		if (isset($this->request->post['email'])) {
    132 			$data['email'] = $this->request->post['email'];
    133 		} elseif (!empty($user_info)) {
    134 			$data['email'] = $user_info['email'];
    135 		} else {
    136 			$data['email'] = '';
    137 		}
    138 
    139 		if (isset($this->request->post['image'])) {
    140 			$data['image'] = $this->request->post['image'];
    141 		} elseif (!empty($user_info)) {
    142 			$data['image'] = $user_info['image'];
    143 		} else {
    144 			$data['image'] = '';
    145 		}
    146 
    147 		$this->load->model('tool/image');
    148 
    149 		if (isset($this->request->post['image']) && is_file(DIR_IMAGE . $this->request->post['image'])) {
    150 			$data['thumb'] = $this->model_tool_image->resize($this->request->post['image'], 100, 100);
    151 		} elseif (!empty($user_info) && $user_info['image'] && is_file(DIR_IMAGE . $user_info['image'])) {
    152 			$data['thumb'] = $this->model_tool_image->resize($user_info['image'], 100, 100);
    153 		} else {
    154 			$data['thumb'] = $this->model_tool_image->resize('no_image.png', 100, 100);
    155 		}
    156 		
    157 		$data['placeholder'] = $this->model_tool_image->resize('no_image.png', 100, 100);
    158 
    159 		$data['header'] = $this->load->controller('common/header');
    160 		$data['column_left'] = $this->load->controller('common/column_left');
    161 		$data['footer'] = $this->load->controller('common/footer');
    162 
    163 		$this->response->setOutput($this->load->view('common/profile', $data));
    164 	}
    165 
    166 	protected function validateForm() {
    167 		if (!$this->user->hasPermission('modify', 'common/profile')) {
    168 			$this->error['warning'] = $this->language->get('error_permission');
    169 		}
    170 
    171 		if ((utf8_strlen($this->request->post['username']) < 3) || (utf8_strlen($this->request->post['username']) > 20)) {
    172 			$this->error['username'] = $this->language->get('error_username');
    173 		}
    174 
    175 		$user_info = $this->model_user_user->getUserByUsername($this->request->post['username']);
    176 
    177 		if ($user_info && ($this->user->getId() != $user_info['user_id'])) {
    178 			$this->error['warning'] = $this->language->get('error_exists_username');
    179 		}
    180 
    181 		if ((utf8_strlen(trim($this->request->post['firstname'])) < 1) || (utf8_strlen(trim($this->request->post['firstname'])) > 32)) {
    182 			$this->error['firstname'] = $this->language->get('error_firstname');
    183 		}
    184 
    185 		if ((utf8_strlen(trim($this->request->post['lastname'])) < 1) || (utf8_strlen(trim($this->request->post['lastname'])) > 32)) {
    186 			$this->error['lastname'] = $this->language->get('error_lastname');
    187 		}
    188 
    189 		if ((utf8_strlen($this->request->post['email']) > 96) || !filter_var($this->request->post['email'], FILTER_VALIDATE_EMAIL)) {
    190 			$this->error['email'] = $this->language->get('error_email');
    191 		}
    192 
    193 		$user_info = $this->model_user_user->getUserByEmail($this->request->post['email']);
    194 
    195 		if ($user_info && ($this->user->getId() != $user_info['user_id'])) {
    196 			$this->error['warning'] = $this->language->get('error_exists_email');
    197 		}
    198 
    199 		if ($this->request->post['password']) {
    200 			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)) {
    201 				$this->error['password'] = $this->language->get('error_password');
    202 			}
    203 
    204 			if ($this->request->post['password'] != $this->request->post['confirm']) {
    205 				$this->error['confirm'] = $this->language->get('error_confirm');
    206 			}
    207 		}
    208 
    209 		return !$this->error;
    210 	}
    211 }