+ // TODO: Security problem!
+ //$user_id = $this->input->post('user-id');
+ if ($this->input->post('username'))
+ $data['username'] = $this->input->post('username');
+ $data['email'] = $this->input->post('email');
+ $data['first_name'] = $this->input->post('first-name');
+ $data['last_name'] = $this->input->post('last-name');
+ $data['sex'] = intval($this->input->post('sex'));
+ $data['birth_date'] = $this->input->post('birth-date');
+ $data['country'] = $this->input->post('country');
+ $data['locality'] = $this->input->post('locality');
+ $data['ui_lang'] = $this->input->post('ui-lang');
+ $data['time_zone'] = $this->input->post('time-zone');
+
+ // Handle picture if one was uploaded.
+ if ($_FILES['picture']['tmp_name'])
+ {
+ $upload_data = $this->upload->data();
+ $this->load->library('image');
+ $this->image->load($upload_data['full_path']);
+ // Resize original to a maximum size.
+ if ($this->image->get_width() * $this->image->get_height()
+ > 640*480)
+ {
+ $this->image->save_thumbnail(
+ $upload_data['full_path'],
+ 640, 480, IMAGETYPE_AUTO);
+ }
+ // Create thumbnail.
+ $data['picture'] = $upload_data['file_name'];
+ $this->image->save_thumbnail($upload_data['file_path']
+ . $upload_data['file_name']. '-thumb.jpg', 120, 90);
+ }
+
+ // TODO: To much info as session data?
+ // Update session user data.
+ $this->_update_session_userdata($data);
+
+ // Edit account data
+ if ($user_id)
+ {
+ $password = $this->input->post('new-password');
+ if ($password)
+ $data['password'] = $password;
+
+ $this->users_model->set_userdata($user_id, $data);
+
+ // Redirect to last page before login.
+ header('Location: '. site_url(urldecode_segments($redirect)));
+ }
+ // Registration
+ else
+ {
+ $data['username'] = $this->input->post('username');
+ $data['password'] = $this->input->post('password');
+ $data['auth_src'] = 'internal';
+
+ $this->users_model->register($data);
+ $user_id = $this->users_model->get_userdata($data['username'],
+ "id");
+ $user_id = $user_id['id'];
+
+ // Redirect account activation page.
+ header('Location: '. site_url("user/activate/$user_id"));
+ }
+ }
+ }
+
+ public function account($redirect = '')
+ {
+ $this->register($redirect);
+ }
+
+ public function profile($username, $videos_offset = 0)
+ {
+ // TODO handle user not found
+
+ $user_id = $this->session->userdata('user_id');
+ if ($user_id)
+ {
+ if (intval($user_id) & USER_ROLE_ADMIN)
+ $allow_unactivated = TRUE;
+ else
+ $allow_unactivated = FALSE;
+ }
+ else
+ $allow_unactivated = FALSE;
+
+ $this->load->config('localization');
+ $this->load->helper('date');
+ $this->lang->load('date');
+
+ // **
+ // ** LOADING MODEL
+ // **
+ // Logged in user time zone
+ $time_zone = $this->session->userdata('time_zone');
+
+ // User data
+ $userdata = $this->users_model->get_userdata($username);
+ $userdata['roles'] = Users_model::roles_to_string($userdata['roles']);
+ $country_list = $this->config->item('country_list');
+ $userdata['country_name'] = $country_list[ $userdata['country'] ];
+ $userdata['last_login'] = human_gmt_to_human_local(
+ $userdata['last_login'], $time_zone);
+ $userdata['time_zone'] = $this->lang->line($userdata['time_zone']);
+
+ // User's videos
+ $this->load->model('videos_model');
+ $vs_data['videos'] = $this->videos_model->get_videos_summary(
+ NULL, $username, intval($videos_offset),
+ $this->config->item('videos_per_page'), 'hottest',
+ $allow_unactivated);
+
+ // Pagination
+ $this->load->library('pagination');
+ $pg_config['base_url'] = site_url("user/profile/$username/");
+ $pg_config['uri_segment'] = 4;
+ $pg_config['total_rows'] = $this->videos_model->get_videos_count(
+ NULL, $username, $allow_unactivated);
+ $pg_config['per_page'] = $this->config->item('videos_per_page');
+ $this->pagination->initialize($pg_config);
+ $vs_data['pagination'] = $this->pagination->create_links();
+ $vs_data['title'] = NULL;
+ $vs_data['category_name'] = ''; // TODO videos_summary with AJAX
+
+ $params = array(
+ 'title'=> $this->lang->line('user_appelation').' '.$username
+ .' – '
+ . $this->config->item('site_name'),
+ 'css'=> array('catalog.css')
+ //'metas' => array('description'=>'')
+ );
+ $this->load->library('html_head_params', $params);
+
+ // Current user profile tab
+ $tab = (! $videos_offset ? 0 : 1);
+
+ // **
+ // ** LOADING VIEWS
+ // **
+ $this->load->view('html_begin', $this->html_head_params);
+ $this->load->view('header', array());
+
+ $vs = $this->load->view('catalog/videos_summary_view', $vs_data, TRUE);
+
+ $main_params['content'] = $this->load->view('user/profile_view',
+ array('userdata'=> $userdata, 'videos_summary'=> $vs, 'tab'=>$tab),
+ TRUE);
+ $main_params['side'] = $this->load->view('side_default', NULL, TRUE);
+ $this->load->view('main', $main_params);
+
+ $this->load->view('footer');
+ $this->load->view('html_end');
+ }
+
+ public function activate($user_id, $method='', $activation_code='')
+ {
+ $user_id = intval($user_id);
+ $res_form_validation = FALSE;
+
+ if ($method == 'code')
+ {
+ if (! $activation_code)
+ $res_form_validation = $this->form_validation->run('activate');
+ // Activation code is provided in URL.
+ else
+ {
+ if ($this->_valid_activation_code($activation_code)
+ && $this->users_model->activate_account($user_id,
+ $activation_code))
+ {
+ $this->load->helper('message');
+ show_info_msg_page($this, sprintf(
+ $this->lang->line('user_msg_activated_account'),
+ site_url('user/login')));
+ return;
+ }
+ else
+ {
+ $this->load->helper('message');
+ show_error_msg_page($this,
+ $this->lang->line(
+ 'user_msg_wrong_activation_code'));
+ return;
+ }
+ }
+ }
+ else if ($method == 'resend')
+ {
+ $res_form_validation =
+ $this->form_validation->run('resend_activation');
+ }
+
+ $userdata = $this->users_model->get_userdata($user_id,
+ 'email, a.activation_code');
+ $email = $userdata['email'];
+ $activated_account = ($userdata['activation_code'] == NULL);
+
+ if ($activated_account)
+ {
+ $this->load->helper('message');
+ show_info_msg_page($this, sprintf(
+ $this->lang->line('user_msg_activated_account'),
+ site_url('user/login')));