profile.php 24 KB

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