chamilo /
chamilo-lms
| 1 | <?php |
||
| 2 | /* For licensing terms, see /license.txt */ |
||
| 3 | |||
| 4 | use Chamilo\CoreBundle\Entity\User; |
||
| 5 | use Chamilo\CoreBundle\Entity\UserAuthSource; |
||
| 6 | use Chamilo\CoreBundle\Enums\ActionIcon; |
||
| 7 | use Chamilo\CoreBundle\Enums\ToolIcon; |
||
| 8 | use Chamilo\CoreBundle\Event\AbstractEvent; |
||
| 9 | use Chamilo\CoreBundle\Event\Events; |
||
| 10 | use Chamilo\CoreBundle\Event\UserUpdatedEvent; |
||
| 11 | use Chamilo\CoreBundle\Framework\Container; |
||
| 12 | use ChamiloSession as Session; |
||
| 13 | |||
| 14 | /** |
||
| 15 | * This file displays the user's profile, |
||
| 16 | * optionally it allows users to modify their profile as well. |
||
| 17 | * |
||
| 18 | * See inc/conf/profile.conf.php to modify settings |
||
| 19 | */ |
||
| 20 | $cidReset = true; |
||
| 21 | require_once __DIR__.'/../inc/global.inc.php'; |
||
| 22 | |||
| 23 | $this_section = SECTION_MYPROFILE; |
||
| 24 | $allowSocialTool = 'true' == api_get_setting('allow_social_tool'); |
||
| 25 | if ($allowSocialTool) { |
||
| 26 | $this_section = SECTION_SOCIAL; |
||
| 27 | } |
||
| 28 | |||
| 29 | $logInfo = [ |
||
| 30 | 'tool' => 'profile', |
||
| 31 | 'action' => $this_section, |
||
| 32 | ]; |
||
| 33 | Event::registerLog($logInfo); |
||
|
0 ignored issues
–
show
|
|||
| 34 | |||
| 35 | $profileList = (array) api_get_setting('profile'); |
||
| 36 | |||
| 37 | $_user = api_get_user_info(); |
||
| 38 | $_SESSION['this_section'] = $this_section; |
||
| 39 | |||
| 40 | if (!(isset($_user['user_id']) && $_user['user_id']) || api_is_anonymous($_user['user_id'], true)) { |
||
| 41 | api_not_allowed(true); |
||
| 42 | } |
||
| 43 | |||
| 44 | $htmlHeadXtra[] = api_get_password_checker_js('#username', '#password1'); |
||
| 45 | //$htmlHeadXtra[] = api_get_css_asset('cropper/dist/cropper.min.css'); |
||
| 46 | //$htmlHeadXtra[] = api_get_asset('cropper/dist/cropper.min.js'); |
||
| 47 | $htmlHeadXtra[] = '<script> |
||
| 48 | $(function() { |
||
| 49 | $("#id_generate_api_key").on("click", function (e) { |
||
| 50 | e.preventDefault(); |
||
| 51 | |||
| 52 | $.ajax({ |
||
| 53 | contentType: "application/x-www-form-urlencoded", |
||
| 54 | type: "POST", |
||
| 55 | url: "'.api_get_path(WEB_AJAX_PATH).'user_manager.ajax.php?a=generate_api_key", |
||
| 56 | data: "num_key_id="+"", |
||
| 57 | success: function(datos) { |
||
| 58 | $("#div_api_key").html(datos); |
||
| 59 | } |
||
| 60 | }); |
||
| 61 | }); |
||
| 62 | |||
| 63 | }); |
||
| 64 | |||
| 65 | function confirmation(name) { |
||
| 66 | if (confirm("'.get_lang('Are you sure to delete').' " + name + " ?")) { |
||
| 67 | document.forms["profile"].submit(); |
||
| 68 | } else { |
||
| 69 | return false; |
||
| 70 | } |
||
| 71 | } |
||
| 72 | function show_image(image,width,height) { |
||
| 73 | width = parseInt(width) + 20; |
||
| 74 | height = parseInt(height) + 20; |
||
| 75 | window_x = window.open(image,\'windowX\',\'width=\'+ width + \', height=\'+ height + \'\'); |
||
| 76 | } |
||
| 77 | </script>'; |
||
| 78 | |||
| 79 | $jquery_ready_content = ''; |
||
| 80 | if ('true' === api_get_setting('allow_message_tool')) { |
||
| 81 | $jquery_ready_content = <<<EOF |
||
| 82 | $(".message-content .message-delete").click(function(){ |
||
| 83 | $(this).parents(".message-content").animate({ opacity: "hide" }, "slow"); |
||
| 84 | $(".message-view").animate({ opacity: "show" }, "slow"); |
||
| 85 | }); |
||
| 86 | EOF; |
||
| 87 | } |
||
| 88 | |||
| 89 | $tool_name = get_lang('View my e-portfolio'); |
||
| 90 | $table_user = Database::get_main_table(TABLE_MAIN_USER); |
||
| 91 | |||
| 92 | /* |
||
| 93 | * Get initial values for all fields. |
||
| 94 | */ |
||
| 95 | $user_data = api_get_user_info( |
||
| 96 | api_get_user_id(), |
||
| 97 | false, |
||
| 98 | false, |
||
| 99 | false, |
||
| 100 | false, |
||
| 101 | true, |
||
| 102 | true |
||
| 103 | ); |
||
| 104 | $array_list_key = UserManager::get_api_keys(api_get_user_id()); |
||
| 105 | $id_temp_key = UserManager::get_api_key_id(api_get_user_id(), 'default'); |
||
| 106 | $value_array = []; |
||
| 107 | if (isset($array_list_key[$id_temp_key])) { |
||
| 108 | $value_array = $array_list_key[$id_temp_key]; |
||
| 109 | } |
||
| 110 | $user_data['api_key_generate'] = $value_array; |
||
| 111 | |||
| 112 | if (false !== $user_data) { |
||
| 113 | if ('true' == api_get_setting('login_is_email')) { |
||
| 114 | $user_data['username'] = $user_data['email']; |
||
| 115 | } |
||
| 116 | if (is_null($user_data['language'])) { |
||
| 117 | $user_data['language'] = api_get_setting('platformLanguage'); |
||
| 118 | } |
||
| 119 | } |
||
| 120 | |||
| 121 | $form = new FormValidator('profile'); |
||
| 122 | |||
| 123 | if (api_is_western_name_order()) { |
||
| 124 | // FIRST NAME and LAST NAME |
||
| 125 | $form->addElement('text', 'firstname', get_lang('First name'), ['size' => 40]); |
||
| 126 | $form->addElement('text', 'lastname', get_lang('Last name'), ['size' => 40]); |
||
| 127 | } else { |
||
| 128 | // LAST NAME and FIRST NAME |
||
| 129 | $form->addElement('text', 'lastname', get_lang('Last name'), ['size' => 40]); |
||
| 130 | $form->addElement('text', 'firstname', get_lang('First name'), ['size' => 40]); |
||
| 131 | } |
||
| 132 | if (!in_array('name', $profileList)) { |
||
| 133 | $form->freeze(['lastname', 'firstname']); |
||
| 134 | } |
||
| 135 | $form->applyFilter(['lastname', 'firstname'], 'stripslashes'); |
||
| 136 | $form->applyFilter(['lastname', 'firstname'], 'trim'); |
||
| 137 | $form->applyFilter(['lastname', 'firstname'], 'html_filter'); |
||
| 138 | $form->addRule('lastname', get_lang('Required field'), 'required'); |
||
| 139 | $form->addRule('firstname', get_lang('Required field'), 'required'); |
||
| 140 | |||
| 141 | // USERNAME |
||
| 142 | $form->addElement( |
||
| 143 | 'text', |
||
| 144 | 'username', |
||
| 145 | get_lang('Username'), |
||
| 146 | [ |
||
| 147 | 'id' => 'username', |
||
| 148 | 'maxlength' => User::USERNAME_MAX_LENGTH, |
||
| 149 | 'size' => User::USERNAME_MAX_LENGTH, |
||
| 150 | ] |
||
| 151 | ); |
||
| 152 | if (!in_array('login', $profileList) || 'true' == api_get_setting('login_is_email')) { |
||
| 153 | $form->freeze('username'); |
||
| 154 | } |
||
| 155 | $form->applyFilter('username', 'stripslashes'); |
||
| 156 | $form->applyFilter('username', 'trim'); |
||
| 157 | $form->addRule('username', get_lang('Required field'), 'required'); |
||
| 158 | $form->addRule('username', get_lang('Your login can only contain letters, numbers and _.-'), 'username'); |
||
| 159 | $form->addRule('username', get_lang('This login is already in use'), 'username_available', $user_data['username']); |
||
| 160 | |||
| 161 | $form->addElement('text', 'official_code', get_lang('Code'), ['size' => 40]); |
||
| 162 | if (!in_array('officialcode', $profileList)) { |
||
| 163 | $form->freeze('official_code'); |
||
| 164 | } |
||
| 165 | $form->applyFilter('official_code', 'stripslashes'); |
||
| 166 | $form->applyFilter('official_code', 'trim'); |
||
| 167 | $form->applyFilter('official_code', 'html_filter'); |
||
| 168 | if ('true' === api_get_setting('registration', 'officialcode') && |
||
| 169 | in_array('officialcode', $profileList) |
||
| 170 | ) { |
||
| 171 | $form->addRule('official_code', get_lang('Required field'), 'required'); |
||
| 172 | } |
||
| 173 | |||
| 174 | |||
| 175 | $form->addElement('email', 'email', get_lang('E-mail'), ['size' => 40]); |
||
| 176 | if (!in_array('email', $profileList)) { |
||
| 177 | $form->freeze('email'); |
||
| 178 | } |
||
| 179 | |||
| 180 | if ('true' == api_get_setting('registration', 'email') && in_array('email', $profileList) |
||
| 181 | ) { |
||
| 182 | $form->applyFilter('email', 'stripslashes'); |
||
| 183 | $form->applyFilter('email', 'trim'); |
||
| 184 | $form->addRule('email', get_lang('Required field'), 'required'); |
||
| 185 | $form->addEmailRule('email'); |
||
| 186 | } |
||
| 187 | |||
| 188 | // PHONE |
||
| 189 | $form->addElement('text', 'phone', get_lang('Phone'), ['size' => 20]); |
||
| 190 | if (!in_array('phone', $profileList)) { |
||
| 191 | $form->freeze('phone'); |
||
| 192 | } |
||
| 193 | $form->applyFilter('phone', 'stripslashes'); |
||
| 194 | $form->applyFilter('phone', 'trim'); |
||
| 195 | $form->applyFilter('phone', 'html_filter'); |
||
| 196 | |||
| 197 | // PICTURE |
||
| 198 | if (in_array('picture', $profileList)) { |
||
| 199 | $form->addFile( |
||
| 200 | 'picture', |
||
| 201 | [ |
||
| 202 | '' != $user_data['picture_uri'] ? get_lang('Update Image') : get_lang('Add image'), |
||
| 203 | get_lang('Only PNG, JPG or GIF images allowed'), |
||
| 204 | ], |
||
| 205 | [ |
||
| 206 | 'id' => 'picture', |
||
| 207 | 'class' => 'picture-form', |
||
| 208 | 'crop_image' => true, |
||
| 209 | 'crop_ratio' => '1 / 1', |
||
| 210 | 'accept' => 'image/*', |
||
| 211 | ] |
||
| 212 | ); |
||
| 213 | |||
| 214 | $form->addProgress(); |
||
| 215 | if (!empty($user_data['picture_uri'])) { |
||
| 216 | $form->addElement('checkbox', 'remove_picture', null, get_lang('Remove picture')); |
||
| 217 | } |
||
| 218 | $allowed_picture_types = api_get_supported_image_extensions(false); |
||
| 219 | $form->addRule( |
||
| 220 | 'picture', |
||
| 221 | get_lang('Only PNG, JPG or GIF images allowed').' ('.implode(', ', $allowed_picture_types).')', |
||
| 222 | 'filetype', |
||
| 223 | $allowed_picture_types |
||
| 224 | ); |
||
| 225 | } |
||
| 226 | |||
| 227 | // LANGUAGE |
||
| 228 | $form->addSelectLanguage('language', get_lang('Language')); |
||
| 229 | if (!in_array('language', $profileList)) { |
||
| 230 | $form->freeze('language'); |
||
| 231 | } |
||
| 232 | |||
| 233 | // THEME |
||
| 234 | if ('true' === api_get_setting('user_selected_theme')) { |
||
| 235 | $form->addSelectTheme('theme', get_lang('Graphical theme')); |
||
| 236 | if (!in_array('theme', $profileList)) { |
||
| 237 | $form->freeze('theme'); |
||
| 238 | } |
||
| 239 | $form->applyFilter('theme', 'trim'); |
||
| 240 | } |
||
| 241 | |||
| 242 | // EXTENDED PROFILE this make the page very slow! |
||
| 243 | if ('true' === api_get_setting('extended_profile')) { |
||
| 244 | $width_extended_profile = 500; |
||
| 245 | // MY COMPETENCES |
||
| 246 | $form->addHtmlEditor( |
||
| 247 | 'competences', |
||
| 248 | get_lang('My competences'), |
||
| 249 | false, |
||
| 250 | false, |
||
| 251 | [ |
||
| 252 | 'ToolbarSet' => 'Profile', |
||
| 253 | 'Width' => $width_extended_profile, |
||
| 254 | 'Height' => '130', |
||
| 255 | ] |
||
| 256 | ); |
||
| 257 | // MY DIPLOMAS |
||
| 258 | $form->addHtmlEditor( |
||
| 259 | 'diplomas', |
||
| 260 | get_lang('My diplomas'), |
||
| 261 | false, |
||
| 262 | false, |
||
| 263 | [ |
||
| 264 | 'ToolbarSet' => 'Profile', |
||
| 265 | 'Width' => $width_extended_profile, |
||
| 266 | 'Height' => '130', |
||
| 267 | ] |
||
| 268 | ); |
||
| 269 | // WHAT I AM ABLE TO TEACH |
||
| 270 | $form->addHtmlEditor( |
||
| 271 | 'teach', |
||
| 272 | get_lang('What I can teach'), |
||
| 273 | false, |
||
| 274 | false, |
||
| 275 | [ |
||
| 276 | 'ToolbarSet' => 'Profile', |
||
| 277 | 'Width' => $width_extended_profile, |
||
| 278 | 'Height' => '130', |
||
| 279 | ] |
||
| 280 | ); |
||
| 281 | |||
| 282 | // MY PRODUCTIONS |
||
| 283 | /* |
||
| 284 | $form->addElement('file', 'production', get_lang('My productions')); |
||
| 285 | if ($production_list = UserManager::build_production_list(api_get_user_id(), '', true)) { |
||
| 286 | $form->addElement('static', 'productions_list', null, $production_list); |
||
| 287 | } |
||
| 288 | */ |
||
| 289 | // MY PERSONAL OPEN AREA |
||
| 290 | $form->addHtmlEditor( |
||
| 291 | 'openarea', |
||
| 292 | get_lang('My personal open area'), |
||
| 293 | false, |
||
| 294 | false, |
||
| 295 | [ |
||
| 296 | 'ToolbarSet' => 'Profile', |
||
| 297 | 'Width' => $width_extended_profile, |
||
| 298 | 'Height' => '350', |
||
| 299 | ] |
||
| 300 | ); |
||
| 301 | // openarea is untrimmed for maximum openness |
||
| 302 | $form->applyFilter(['competences', 'diplomas', 'teach', 'openarea'], 'stripslashes'); |
||
| 303 | $form->applyFilter(['competences', 'diplomas', 'teach'], 'trim'); |
||
| 304 | } |
||
| 305 | |||
| 306 | // PASSWORD, if auth_source is platform |
||
| 307 | if (in_array(UserAuthSource::PLATFORM, $user_data['auth_sources']) && |
||
| 308 | in_array('password', $profileList) |
||
| 309 | ) { |
||
| 310 | $form->addElement('password', 'password0', [get_lang('Pass'), get_lang('To change your password, enter your current password in the field above and your new password in both fields below. To maintain the current password, leave the three fields empty.')], ['size' => 40]); |
||
| 311 | $form->addElement('password', 'password1', get_lang('New password'), ['id' => 'password1', 'size' => 40]); |
||
| 312 | |||
| 313 | $form->addElement('password', 'password2', get_lang('Confirm password'), ['size' => 40]); |
||
| 314 | // user must enter identical password twice so we can prevent some user errors |
||
| 315 | $form->addRule(['password1', 'password2'], get_lang('You have typed two different passwords'), 'compare'); |
||
| 316 | $form->addPasswordRule('password1'); |
||
| 317 | } |
||
| 318 | |||
| 319 | $extraField = new ExtraField('user'); |
||
| 320 | $return = $extraField->addElements( |
||
| 321 | $form, |
||
| 322 | api_get_user_id() |
||
| 323 | ); |
||
| 324 | |||
| 325 | $jquery_ready_content = $return['jquery_ready_content']; |
||
| 326 | |||
| 327 | // the $jquery_ready_content variable collects all functions that |
||
| 328 | // will be load in the $(document).ready javascript function |
||
| 329 | $htmlHeadXtra[] = '<script> |
||
| 330 | $(function() { |
||
| 331 | '.$jquery_ready_content.' |
||
| 332 | }); |
||
| 333 | </script>'; |
||
| 334 | |||
| 335 | if (in_array('apikeys', $profileList)) { |
||
| 336 | $form->addElement('html', '<div id="div_api_key">'); |
||
| 337 | $form->addElement( |
||
| 338 | 'text', |
||
| 339 | 'api_key_generate', |
||
| 340 | get_lang('My API key'), |
||
| 341 | ['size' => 40, 'id' => 'id_api_key_generate'] |
||
| 342 | ); |
||
| 343 | $form->addElement('html', '</div>'); |
||
| 344 | $form->addButton( |
||
| 345 | 'generate_api_key', |
||
| 346 | get_lang('Generate API key'), |
||
| 347 | 'cogs', |
||
| 348 | 'default', |
||
| 349 | 'default', |
||
| 350 | null, |
||
| 351 | ['id' => 'id_generate_api_key'] |
||
| 352 | ); |
||
| 353 | } |
||
| 354 | // SUBMIT |
||
| 355 | $form->addButtonUpdate(get_lang('Save settings'), 'apply_change'); |
||
| 356 | |||
| 357 | // Student cannot modified their user conditions |
||
| 358 | $extraConditions = api_get_setting('profile.show_conditions_to_user', true); |
||
| 359 | if ($extraConditions && isset($extraConditions['conditions'])) { |
||
| 360 | $extraConditions = $extraConditions['conditions']; |
||
| 361 | foreach ($extraConditions as $condition) { |
||
| 362 | $element = $form->getElement('extra_'.$condition['variable']); |
||
| 363 | if ($element) { |
||
| 364 | $element->freeze(); |
||
| 365 | } |
||
| 366 | } |
||
| 367 | } |
||
| 368 | |||
| 369 | $form->setDefaults($user_data); |
||
| 370 | |||
| 371 | $filtered_extension = false; |
||
| 372 | |||
| 373 | if ($form->validate()) { |
||
| 374 | Container::getEventDispatcher()->dispatch( |
||
| 375 | new UserUpdatedEvent([], AbstractEvent::TYPE_PRE), |
||
| 376 | Events::USER_UPDATED |
||
| 377 | ); |
||
| 378 | |||
| 379 | $wrong_current_password = false; |
||
| 380 | $user_data = $form->getSubmitValues(1); |
||
| 381 | $user_data['item_id'] = api_get_user_id(); |
||
| 382 | $user = api_get_user_entity(api_get_user_id()); |
||
| 383 | |||
| 384 | // set password if a new one was provided |
||
| 385 | $validPassword = false; |
||
| 386 | $passwordWasChecked = false; |
||
| 387 | |||
| 388 | if ($user && |
||
|
0 ignored issues
–
show
|
|||
| 389 | (!empty($user_data['password0']) && |
||
| 390 | !empty($user_data['password1'])) || |
||
| 391 | (!empty($user_data['password0']) && |
||
| 392 | in_array('email', $profileList) |
||
| 393 | ) |
||
| 394 | ) { |
||
| 395 | $passwordWasChecked = true; |
||
| 396 | $validPassword = UserManager::isPasswordValid( |
||
| 397 | $user, |
||
| 398 | $user_data['password0'], |
||
| 399 | ); |
||
| 400 | |||
| 401 | if ($validPassword) { |
||
| 402 | $password = $user_data['password1']; |
||
| 403 | } else { |
||
| 404 | Display::addFlash( |
||
| 405 | Display:: return_message( |
||
| 406 | get_lang('The current password is incorrect'), |
||
| 407 | 'warning', |
||
| 408 | false |
||
| 409 | ) |
||
| 410 | ); |
||
| 411 | } |
||
| 412 | } |
||
| 413 | |||
| 414 | $allow_users_to_change_email_with_no_password = true; |
||
| 415 | if (isset($user_data['auth_sources']) && in_array(UserAuthSource::PLATFORM, $user_data['auth_sources']) && |
||
| 416 | 'false' === api_get_setting('allow_users_to_change_email_with_no_password') |
||
| 417 | ) { |
||
| 418 | $allow_users_to_change_email_with_no_password = false; |
||
| 419 | } |
||
| 420 | |||
| 421 | // If user sending the email to be changed (input available and not frozen ) |
||
| 422 | if (in_array('email', $profileList)) { |
||
| 423 | $userFromEmail = api_get_user_info_from_email($user_data['email']); |
||
| 424 | if ($allow_users_to_change_email_with_no_password) { |
||
| 425 | if (!empty($userFromEmail)) { |
||
| 426 | $changeemail = $user_data['email']; |
||
| 427 | } |
||
| 428 | } else { |
||
| 429 | // Normal behaviour |
||
| 430 | if (!empty($userFromEmail) && $validPassword) { |
||
| 431 | $changeemail = $user_data['email']; |
||
| 432 | } |
||
| 433 | |||
| 434 | if (!empty($userFromEmail) && empty($user_data['password0'])) { |
||
| 435 | Display::addFlash( |
||
| 436 | Display:: return_message( |
||
| 437 | get_lang('In order to change your e-mail address, you are required to confirm your password'), |
||
| 438 | 'error', |
||
| 439 | false |
||
| 440 | ) |
||
| 441 | ); |
||
| 442 | } |
||
| 443 | } |
||
| 444 | } |
||
| 445 | |||
| 446 | // Upload picture if a new one is provided |
||
| 447 | if (isset($_FILES['picture']) && $_FILES['picture']['size']) { |
||
| 448 | $new_picture = UserManager::update_user_picture( |
||
| 449 | api_get_user_id(), |
||
| 450 | $_FILES['picture']['name'], |
||
| 451 | $_FILES['picture']['tmp_name'], |
||
| 452 | $user_data['picture_crop_result'] |
||
| 453 | ); |
||
| 454 | |||
| 455 | if ($new_picture) { |
||
|
0 ignored issues
–
show
|
|||
| 456 | $user_data['picture_uri'] = $new_picture; |
||
| 457 | |||
| 458 | Display::addFlash( |
||
| 459 | Display:: return_message( |
||
| 460 | get_lang('Your picture has been uploaded'), |
||
| 461 | 'normal', |
||
| 462 | false |
||
| 463 | ) |
||
| 464 | ); |
||
| 465 | } |
||
| 466 | } elseif (!empty($user_data['remove_picture'])) { |
||
| 467 | // remove existing picture if asked |
||
| 468 | UserManager::deleteUserPicture(api_get_user_id()); |
||
| 469 | $user_data['picture_uri'] = ''; |
||
| 470 | } |
||
| 471 | |||
| 472 | // Remove production. |
||
| 473 | /* |
||
| 474 | if (isset($user_data['remove_production']) && |
||
| 475 | is_array($user_data['remove_production']) |
||
| 476 | ) { |
||
| 477 | foreach (array_keys($user_data['remove_production']) as $production) { |
||
| 478 | UserManager::remove_user_production(api_get_user_id(), urldecode($production)); |
||
| 479 | } |
||
| 480 | if ($production_list = UserManager::build_production_list(api_get_user_id(), true, true)) { |
||
| 481 | $form->insertElementBefore( |
||
| 482 | $form->createElement('static', null, null, $production_list), |
||
| 483 | 'productions_list' |
||
| 484 | ); |
||
| 485 | } |
||
| 486 | $form->removeElement('productions_list'); |
||
| 487 | Display::addFlash( |
||
| 488 | Display:: return_message(get_lang('File deleted'), 'normal', false) |
||
| 489 | ); |
||
| 490 | } |
||
| 491 | */ |
||
| 492 | // upload production if a new one is provided |
||
| 493 | /*if (isset($_FILES['production']) && $_FILES['production']['size']) { |
||
| 494 | $res = upload_user_production(api_get_user_id()); |
||
| 495 | if (!$res) { |
||
| 496 | //it's a bit excessive to assume the extension is the reason why |
||
| 497 | // upload_user_production() returned false, but it's true in most cases |
||
| 498 | $filtered_extension = true; |
||
| 499 | } else { |
||
| 500 | Display::addFlash( |
||
| 501 | Display:: return_message( |
||
| 502 | get_lang('Your production file has been uploaded'), |
||
| 503 | 'normal', |
||
| 504 | false |
||
| 505 | ) |
||
| 506 | ); |
||
| 507 | } |
||
| 508 | }*/ |
||
| 509 | |||
| 510 | // remove values that shouldn't go in the database |
||
| 511 | unset( |
||
| 512 | $user_data['password0'], |
||
| 513 | $user_data['password1'], |
||
| 514 | $user_data['password2'], |
||
| 515 | $user_data['MAX_FILE_SIZE'], |
||
| 516 | $user_data['remove_picture'], |
||
| 517 | $user_data['apply_change'], |
||
| 518 | $user_data['email'] |
||
| 519 | ); |
||
| 520 | |||
| 521 | // Following RFC2396 (http://www.faqs.org/rfcs/rfc2396.html), a URI uses ':' as a reserved character |
||
| 522 | // we can thus ensure the URL doesn't contain any scheme name by searching for ':' in the string |
||
| 523 | $my_user_openid = isset($user_data['openid']) ? $user_data['openid'] : ''; |
||
| 524 | if (!preg_match('/^[^:]*:\/\/.*$/', $my_user_openid)) { |
||
| 525 | //ensure there is at least a http:// scheme in the URI provided |
||
| 526 | $user_data['openid'] = 'http://'.$my_user_openid; |
||
| 527 | } |
||
| 528 | $extras = []; |
||
| 529 | |||
| 530 | //Checking the user language |
||
| 531 | $languages = array_keys(api_get_languages()); |
||
| 532 | if (!in_array($user_data['language'], $languages)) { |
||
| 533 | $user_data['language'] = api_get_setting('platformLanguage'); |
||
| 534 | } |
||
| 535 | $_SESSION['_user']['language'] = $user_data['language']; |
||
| 536 | |||
| 537 | //Only update values that are request by the "profile" setting |
||
| 538 | //Adding missing variables |
||
| 539 | |||
| 540 | $available_values_to_modify = []; |
||
| 541 | foreach ($profileList as $key) { |
||
| 542 | switch ($key) { |
||
| 543 | case 'language': |
||
| 544 | $available_values_to_modify[] = 'language'; |
||
| 545 | $available_values_to_modify[] = 'locale'; |
||
| 546 | $user_data['locale'] = $user_data['language']; |
||
| 547 | break; |
||
| 548 | case 'login': |
||
| 549 | $available_values_to_modify[] = 'username'; |
||
| 550 | break; |
||
| 551 | case 'name': |
||
| 552 | $available_values_to_modify[] = 'firstname'; |
||
| 553 | $available_values_to_modify[] = 'lastname'; |
||
| 554 | break; |
||
| 555 | case 'picture': |
||
| 556 | $available_values_to_modify[] = 'picture_uri'; |
||
| 557 | break; |
||
| 558 | default: |
||
| 559 | $available_values_to_modify[] = $key; |
||
| 560 | break; |
||
| 561 | } |
||
| 562 | } |
||
| 563 | |||
| 564 | //Fixing missing variables |
||
| 565 | $available_values_to_modify = array_merge( |
||
| 566 | $available_values_to_modify, |
||
| 567 | ['competences', 'diplomas', 'openarea', 'teach', 'openid', 'address'] |
||
| 568 | ); |
||
| 569 | |||
| 570 | // build SQL query |
||
| 571 | $sql = "UPDATE $table_user SET"; |
||
| 572 | unset($user_data['api_key_generate']); |
||
| 573 | |||
| 574 | foreach ($user_data as $key => $value) { |
||
| 575 | if ('extra_' === substr($key, 0, 6)) { //an extra field |
||
| 576 | continue; |
||
| 577 | } elseif (false !== strpos($key, 'remove_extra_')) { |
||
| 578 | } else { |
||
| 579 | if (in_array($key, $available_values_to_modify)) { |
||
| 580 | $sql .= " $key = '".Database::escape_string($value)."',"; |
||
| 581 | } |
||
| 582 | } |
||
| 583 | } |
||
| 584 | |||
| 585 | $changePassword = false; |
||
| 586 | // Change email |
||
| 587 | if ($allow_users_to_change_email_with_no_password) { |
||
| 588 | if (isset($changeemail) && in_array('email', $available_values_to_modify)) { |
||
| 589 | $sql .= " email = '".Database::escape_string($changeemail)."' "; |
||
| 590 | } |
||
| 591 | if (isset($password) && in_array('password', $available_values_to_modify)) { |
||
| 592 | $changePassword = true; |
||
| 593 | } |
||
| 594 | } else { |
||
| 595 | if (isset($changeemail) && !isset($password) && in_array('email', $available_values_to_modify)) { |
||
| 596 | $sql .= " email = '".Database::escape_string($changeemail)."'"; |
||
| 597 | } else { |
||
| 598 | if (isset($password) && in_array('password', $available_values_to_modify)) { |
||
| 599 | if (isset($changeemail) && in_array('email', $available_values_to_modify)) { |
||
| 600 | $sql .= " email = '".Database::escape_string($changeemail)."' "; |
||
| 601 | } |
||
| 602 | $changePassword = true; |
||
| 603 | } |
||
| 604 | } |
||
| 605 | } |
||
| 606 | |||
| 607 | $sql = rtrim($sql, ','); |
||
| 608 | if ($changePassword && !empty($password)) { |
||
| 609 | UserManager::updatePassword(api_get_user_id(), $password); |
||
| 610 | } |
||
| 611 | |||
| 612 | if (!in_array('officialcode', $profileList) && |
||
| 613 | isset($user_data['official_code']) |
||
| 614 | ) { |
||
| 615 | $sql .= ", official_code = '".Database::escape_string($user_data['official_code'])."'"; |
||
| 616 | } |
||
| 617 | |||
| 618 | $sql .= " WHERE id = '".api_get_user_id()."'"; |
||
| 619 | Database::query($sql); |
||
| 620 | |||
| 621 | if (isset($user_data['language']) && !empty($user_data['language'])) { |
||
| 622 | // _locale_user is set in the UserLocaleListener during login |
||
| 623 | Session::write('_locale_user', $user_data['language']); |
||
| 624 | } |
||
| 625 | |||
| 626 | if (false == $passwordWasChecked) { |
||
|
0 ignored issues
–
show
|
|||
| 627 | Display::addFlash( |
||
| 628 | Display:: return_message(get_lang('Your new profile has been saved'), 'normal', false) |
||
| 629 | ); |
||
| 630 | } else { |
||
| 631 | if ($validPassword) { |
||
| 632 | Display::addFlash( |
||
| 633 | Display:: return_message(get_lang('Your new profile has been saved'), 'normal', false) |
||
| 634 | ); |
||
| 635 | } |
||
| 636 | } |
||
| 637 | |||
| 638 | $extraField = new ExtraFieldValue('user'); |
||
| 639 | $extraField->saveFieldValues($user_data); |
||
| 640 | |||
| 641 | $userInfo = api_get_user_info( |
||
| 642 | api_get_user_id(), |
||
| 643 | false, |
||
| 644 | false, |
||
| 645 | false, |
||
| 646 | false, |
||
| 647 | true, |
||
| 648 | true |
||
| 649 | ); |
||
| 650 | Session::write('_user', $userInfo); |
||
| 651 | |||
| 652 | Container::getEventDispatcher()->dispatch( |
||
| 653 | new UserUpdatedEvent( |
||
| 654 | ['user' => api_get_user_entity()], |
||
| 655 | AbstractEvent::TYPE_POST |
||
| 656 | ), |
||
| 657 | Events::USER_UPDATED |
||
| 658 | ); |
||
| 659 | |||
| 660 | /*if ($hook) { |
||
| 661 | Database::getManager()->clear(User::class); // Avoid cache issue (user entity is used before) |
||
| 662 | $user = api_get_user_entity(api_get_user_id()); // Get updated user info for hook event |
||
| 663 | $hook->setEventData(['user' => $user]); |
||
| 664 | $hook->notifyUpdateUser(HOOK_EVENT_TYPE_POST); |
||
| 665 | }*/ |
||
| 666 | |||
| 667 | Session::erase('system_timezone'); |
||
| 668 | |||
| 669 | $url = api_get_self(); |
||
| 670 | header("Location: $url"); |
||
| 671 | exit; |
||
| 672 | } |
||
| 673 | |||
| 674 | $actions = ''; |
||
| 675 | if ($allowSocialTool) { |
||
| 676 | if ('true' === api_get_setting('extended_profile')) { |
||
| 677 | if ('true' === api_get_setting('allow_message_tool')) { |
||
| 678 | $actions .= '<a href="'.api_get_path(WEB_PATH).'main/social/profile.php">'. |
||
| 679 | Display::getMdiIcon(ToolIcon::SHARED_PROFILE, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('View shared profile')).'</a>'; |
||
| 680 | $actions .= '<a href="'.api_get_path(WEB_PATH).'main/messages/inbox.php">'. |
||
| 681 | Display::getMdiIcon(ToolIcon::MESSAGE, 'ch-tool-icon', null, ICON_SIZE_SMALL, get_lang('Messages')).'</a>'; |
||
| 682 | } |
||
| 683 | $show = isset($_GET['show']) ? '&show='.(int) $_GET['show'] : ''; |
||
| 684 | |||
| 685 | if (isset($_GET['type']) && 'extended' === $_GET['type']) { |
||
| 686 | $actions .= '<a href="profile.php?type=reduced'.$show.'">'. |
||
| 687 | Display::getMdiIcon(ActionIcon::EDIT, 'ch-tool-icon', null, ICON_SIZE_TINY, get_lang('Edit normal profile')).'</a>'; |
||
| 688 | } else { |
||
| 689 | $actions .= '<a href="profile.php?type=extended'.$show.'">'. |
||
| 690 | Display::getMdiIcon(ActionIcon::EDIT, 'ch-tool-icon', null, ICON_SIZE_TINY, get_lang('Edit extended profile')).'</a>'; |
||
| 691 | } |
||
| 692 | } |
||
| 693 | } |
||
| 694 | |||
| 695 | $show_delete_account_button = 'true' === api_get_setting('platform_unsubscribe_allowed') ? true : false; |
||
| 696 | |||
| 697 | $tpl = new Template(get_lang('Profile')); |
||
| 698 | |||
| 699 | if ($actions) { |
||
| 700 | $tpl->assign( |
||
| 701 | 'actions', |
||
| 702 | Display::toolbarAction('toolbar', [$actions]) |
||
| 703 | ); |
||
| 704 | } |
||
| 705 | |||
| 706 | SocialManager::setSocialUserBlock($tpl, api_get_user_id(), 'messages'); |
||
| 707 | $tabs = SocialManager::getHomeProfileTabs('profile'); |
||
| 708 | |||
| 709 | if ($allowSocialTool) { |
||
| 710 | SocialManager::setSocialUserBlock($tpl, api_get_user_id(), 'home'); |
||
| 711 | $tpl->assign('social_right_content', $form->returnForm()); |
||
| 712 | $social_layout = $tpl->get_template('social/edit_profile.html.twig'); |
||
| 713 | $tpl->display($social_layout); |
||
| 714 | } else { |
||
| 715 | $bigImage = UserManager::getUserPicture(api_get_user_id(), USER_IMAGE_SIZE_BIG); |
||
| 716 | $normalImage = UserManager::getUserPicture(api_get_user_id(), USER_IMAGE_SIZE_ORIGINAL); |
||
| 717 | |||
| 718 | $imageToShow = '<div id="image-message-container">'; |
||
| 719 | $imageToShow .= '<a class="expand-image float-right" href="'.$bigImage.'" /><img src="'.$normalImage.'"></a>'; |
||
| 720 | $imageToShow .= '</div>'; |
||
| 721 | |||
| 722 | $content = $imageToShow.$form->returnForm(); |
||
| 723 | |||
| 724 | $tpl->assign('content', $content); |
||
| 725 | $tpl->display_one_col_template(); |
||
| 726 | } |
||
| 727 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.