profile.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * This file displays the user's profile,
  5. * optionally it allows users to modify their profile as well.
  6. *
  7. * See inc/conf/profile.conf.php to modify settings
  8. *
  9. * @package chamilo.auth
  10. */
  11. use Chamilo\UserBundle\Entity\User;
  12. use ChamiloSession as Session;
  13. $cidReset = true;
  14. require_once '../inc/global.inc.php';
  15. if (api_get_setting('allow_social_tool') == 'true') {
  16. $this_section = SECTION_SOCIAL;
  17. } else {
  18. $this_section = SECTION_MYPROFILE;
  19. }
  20. //$htmlHeadXtra[] = api_get_password_checker_js('#username', '#password1');
  21. $_SESSION['this_section'] = $this_section;
  22. if (!(isset($_user['user_id']) && $_user['user_id']) || api_is_anonymous($_user['user_id'], true)) {
  23. api_not_allowed(true);
  24. }
  25. $htmlHeadXtra[] = api_get_password_checker_js('#username', '#password1');
  26. $htmlHeadXtra[] = '<script>
  27. function confirmation(name) {
  28. if (confirm("'.get_lang('AreYouSureToDelete', '').' " + name + " ?")) {
  29. document.forms["profile"].submit();
  30. } else {
  31. return false;
  32. }
  33. }
  34. function show_image(image,width,height) {
  35. width = parseInt(width) + 20;
  36. height = parseInt(height) + 20;
  37. window_x = window.open(image,\'windowX\',\'width=\'+ width + \', height=\'+ height + \'\');
  38. }
  39. function generate_open_id_form() {
  40. $.ajax({
  41. contentType: "application/x-www-form-urlencoded",
  42. beforeSend: function(objeto) {
  43. /*$("#div_api_key").html("Loading...");*/ },
  44. type: "POST",
  45. url: "'.api_get_path(WEB_AJAX_PATH).'user_manager.ajax.php?a=generate_api_key",
  46. data: "num_key_id="+"",
  47. success: function(datos) {
  48. $("#div_api_key").html(datos);
  49. }
  50. });
  51. }
  52. function hide_icon_edit(element_html) {
  53. ident="#edit_image";
  54. $(ident).hide();
  55. }
  56. function show_icon_edit(element_html) {
  57. ident="#edit_image";
  58. $(ident).show();
  59. }
  60. </script>';
  61. $warning_msg = '';
  62. if (!empty($_GET['fe'])) {
  63. $warning_msg .= get_lang('UplUnableToSaveFileFilteredExtension');
  64. $_GET['fe'] = null;
  65. }
  66. $jquery_ready_content = '';
  67. if (api_get_setting('allow_message_tool') == 'true') {
  68. $jquery_ready_content = <<<EOF
  69. $(".message-content .message-delete").click(function(){
  70. $(this).parents(".message-content").animate({ opacity: "hide" }, "slow");
  71. $(".message-view").animate({ opacity: "show" }, "slow");
  72. });
  73. EOF;
  74. }
  75. $tool_name = is_profile_editable() ? get_lang('ModifProfile') : get_lang('ViewProfile');
  76. $table_user = Database :: get_main_table(TABLE_MAIN_USER);
  77. /*
  78. * Get initial values for all fields.
  79. */
  80. $user_data = api_get_user_info(api_get_user_id());
  81. $array_list_key = UserManager::get_api_keys(api_get_user_id());
  82. $id_temp_key = UserManager::get_api_key_id(api_get_user_id(), 'dokeos');
  83. $value_array = $array_list_key[$id_temp_key];
  84. $user_data['api_key_generate'] = $value_array;
  85. if ($user_data !== false) {
  86. if (api_get_setting('login_is_email') == 'true') {
  87. $user_data['username'] = $user_data['email'];
  88. }
  89. if (is_null($user_data['language'])) {
  90. $user_data['language'] = api_get_setting('platformLanguage');
  91. }
  92. }
  93. /*
  94. * Initialize the form.
  95. */
  96. $form = new FormValidator(
  97. 'profile',
  98. 'post',
  99. api_get_self()."?".str_replace('&fe=1', '', Security::remove_XSS($_SERVER['QUERY_STRING'])),
  100. null
  101. );
  102. if (api_is_western_name_order()) {
  103. // FIRST NAME and LAST NAME
  104. $form->addElement('text', 'firstname', get_lang('FirstName'), array('size' => 40));
  105. $form->addElement('text', 'lastname', get_lang('LastName'), array('size' => 40));
  106. } else {
  107. // LAST NAME and FIRST NAME
  108. $form->addElement('text', 'lastname', get_lang('LastName'), array('size' => 40));
  109. $form->addElement('text', 'firstname', get_lang('FirstName'), array('size' => 40));
  110. }
  111. if (api_get_setting('profile', 'name') !== 'true') {
  112. $form->freeze(array('lastname', 'firstname'));
  113. }
  114. $form->applyFilter(array('lastname', 'firstname'), 'stripslashes');
  115. $form->applyFilter(array('lastname', 'firstname'), 'trim');
  116. $form->applyFilter(array('lastname', 'firstname'), 'html_filter');
  117. $form->addRule('lastname' , get_lang('ThisFieldIsRequired'), 'required');
  118. $form->addRule('firstname', get_lang('ThisFieldIsRequired'), 'required');
  119. // USERNAME
  120. $form->addElement(
  121. 'text',
  122. 'username',
  123. get_lang('UserName'),
  124. array(
  125. 'id' => 'username',
  126. 'maxlength' => USERNAME_MAX_LENGTH,
  127. 'size' => USERNAME_MAX_LENGTH,
  128. )
  129. );
  130. if (api_get_setting('profile', 'login') !== 'true' || api_get_setting('login_is_email') == 'true') {
  131. $form->freeze('username');
  132. }
  133. $form->applyFilter('username', 'stripslashes');
  134. $form->applyFilter('username', 'trim');
  135. $form->addRule('username', get_lang('ThisFieldIsRequired'), 'required');
  136. $form->addRule('username', get_lang('UsernameWrong'), 'username');
  137. $form->addRule('username', get_lang('UserTaken'), 'username_available', $user_data['username']);
  138. // OFFICIAL CODE
  139. if (CONFVAL_ASK_FOR_OFFICIAL_CODE) {
  140. $form->addElement('text', 'official_code', get_lang('OfficialCode'), array('size' => 40));
  141. if (api_get_setting('profile', 'officialcode') !== 'true') {
  142. $form->freeze('official_code');
  143. }
  144. $form->applyFilter('official_code', 'stripslashes');
  145. $form->applyFilter('official_code', 'trim');
  146. $form->applyFilter('official_code', 'html_filter');
  147. if (api_get_setting('registration', 'officialcode') == 'true' && api_get_setting('profile', 'officialcode') == 'true') {
  148. $form->addRule('official_code', get_lang('ThisFieldIsRequired'), 'required');
  149. }
  150. }
  151. // EMAIL
  152. $form->addElement('email', 'email', get_lang('Email'), array('size' => 40));
  153. if (api_get_setting('profile', 'email') !== 'true') {
  154. $form->freeze('email');
  155. }
  156. if (api_get_setting('registration', 'email') == 'true' && api_get_setting('profile', 'email') == 'true') {
  157. $form->applyFilter('email', 'stripslashes');
  158. $form->applyFilter('email', 'trim');
  159. $form->addRule('email', get_lang('ThisFieldIsRequired'), 'required');
  160. $form->addRule('email', get_lang('EmailWrong'), 'email');
  161. }
  162. // OPENID URL
  163. if (is_profile_editable() && api_get_setting('openid_authentication') == 'true') {
  164. $form->addElement('text', 'openid', get_lang('OpenIDURL'), array('size' => 40));
  165. if (api_get_setting('profile', 'openid') !== 'true') {
  166. $form->freeze('openid');
  167. }
  168. $form->applyFilter('openid', 'trim');
  169. }
  170. // PHONE
  171. $form->addElement('text', 'phone', get_lang('Phone'), array('size' => 20));
  172. if (api_get_setting('profile', 'phone') !== 'true') {
  173. $form->freeze('phone');
  174. }
  175. $form->applyFilter('phone', 'stripslashes');
  176. $form->applyFilter('phone', 'trim');
  177. $form->applyFilter('phone', 'html_filter');
  178. // PICTURE
  179. if (is_profile_editable() && api_get_setting('profile', 'picture') == 'true') {
  180. $form->addElement(
  181. 'file',
  182. 'picture',
  183. ($user_data['picture_uri'] != '' ? get_lang('UpdateImage') : get_lang(
  184. 'AddImage'
  185. )),
  186. array('class' => 'picture-form')
  187. );
  188. $form->add_progress_bar();
  189. if (!empty($user_data['picture_uri'])) {
  190. $form->addElement('checkbox', 'remove_picture', null, get_lang('DelImage'));
  191. }
  192. $allowed_picture_types = api_get_supported_image_extensions();
  193. $form->addRule(
  194. 'picture',
  195. get_lang('OnlyImagesAllowed').' ('.implode(', ', $allowed_picture_types).')',
  196. 'filetype',
  197. $allowed_picture_types
  198. );
  199. }
  200. // LANGUAGE
  201. $form->addElement('select_language', 'language', get_lang('Language'));
  202. if (api_get_setting('profile', 'language') !== 'true') {
  203. $form->freeze('language');
  204. }
  205. //THEME
  206. if (is_profile_editable() && api_get_setting('user_selected_theme') == 'true') {
  207. $form->addElement('SelectTheme', 'theme', get_lang('Theme'));
  208. if (api_get_setting('profile', 'theme') !== 'true') {
  209. $form->freeze('theme');
  210. }
  211. $form->applyFilter('theme', 'trim');
  212. }
  213. // EXTENDED PROFILE this make the page very slow!
  214. if (api_get_setting('extended_profile') == 'true') {
  215. $width_extended_profile = 500;
  216. // MY COMPETENCES
  217. $form->addHtmlEditor(
  218. 'competences',
  219. get_lang('MyCompetences'),
  220. false,
  221. false,
  222. array(
  223. 'ToolbarSet' => 'Profile',
  224. 'Width' => $width_extended_profile,
  225. 'Height' => '130',
  226. )
  227. );
  228. // MY DIPLOMAS
  229. $form->addHtmlEditor(
  230. 'diplomas',
  231. get_lang('MyDiplomas'),
  232. false,
  233. false,
  234. array(
  235. 'ToolbarSet' => 'Profile',
  236. 'Width' => $width_extended_profile,
  237. 'Height' => '130',
  238. )
  239. );
  240. // WHAT I AM ABLE TO TEACH
  241. $form->addHtmlEditor(
  242. 'teach',
  243. get_lang('MyTeach'),
  244. false,
  245. false,
  246. array(
  247. 'ToolbarSet' => 'Profile',
  248. 'Width' => $width_extended_profile,
  249. 'Height' => '130',
  250. )
  251. );
  252. // MY PRODUCTIONS
  253. $form->addElement('file', 'production', get_lang('MyProductions'));
  254. if ($production_list = UserManager::build_production_list(api_get_user_id(), '', true)) {
  255. $form->addElement('static', 'productions_list', null, $production_list);
  256. }
  257. // MY PERSONAL OPEN AREA
  258. $form->addHtmlEditor(
  259. 'openarea',
  260. get_lang('MyPersonalOpenArea'),
  261. false,
  262. false,
  263. array(
  264. 'ToolbarSet' => 'Profile',
  265. 'Width' => $width_extended_profile,
  266. 'Height' => '350',
  267. )
  268. );
  269. // openarea is untrimmed for maximum openness
  270. $form->applyFilter(array('competences', 'diplomas', 'teach', 'openarea'), 'stripslashes');
  271. $form->applyFilter(array('competences', 'diplomas', 'teach'), 'trim');
  272. }
  273. // PASSWORD, if auth_source is platform
  274. if (is_platform_authentication() &&
  275. is_profile_editable() &&
  276. api_get_setting('profile', 'password') == 'true'
  277. ) {
  278. $form->addElement('password', 'password0', array(get_lang('Pass'), get_lang('Enter2passToChange')), array('size' => 40));
  279. $form->addElement('password', 'password1', get_lang('NewPass'), array('id'=> 'password1', 'size' => 40));
  280. $checkPass = api_get_setting('allow_strength_pass_checker');
  281. if ($checkPass == 'true') {
  282. $form->addElement('label', null, '<div id="password_progress"></div>');
  283. }
  284. $form->addElement('password', 'password2', get_lang('Confirmation'), array('size' => 40));
  285. // user must enter identical password twice so we can prevent some user errors
  286. $form->addRule(array('password1', 'password2'), get_lang('PassTwo'), 'compare');
  287. if (CHECK_PASS_EASY_TO_FIND) {
  288. $form->addRule('password1', get_lang('CurrentPasswordEmptyOrIncorrect'), 'callback', 'api_check_password');
  289. }
  290. }
  291. $extraField = new ExtraField('user');
  292. $return = $extraField->addElements($form, api_get_user_id());
  293. $jquery_ready_content = $return['jquery_ready_content'];
  294. // the $jquery_ready_content variable collects all functions that
  295. // will be load in the $(document).ready javascript function
  296. $htmlHeadXtra[] ='<script>
  297. $(document).ready(function(){
  298. '.$jquery_ready_content.'
  299. });
  300. </script>';
  301. if (api_get_setting('profile', 'apikeys') == 'true') {
  302. $form->addElement('html', '<div id="div_api_key">');
  303. $form->addElement(
  304. 'text',
  305. 'api_key_generate',
  306. get_lang('MyApiKey'),
  307. array('size' => 40, 'id' => 'id_api_key_generate')
  308. );
  309. $form->addElement('html', '</div>');
  310. $form->addElement(
  311. 'button',
  312. 'generate_api_key',
  313. get_lang('GenerateApiKey'),
  314. array(
  315. 'id' => 'id_generate_api_key',
  316. 'onclick' => 'generate_open_id_form(); return false;',
  317. )
  318. ); //generate_open_id_form()
  319. }
  320. // SUBMIT
  321. if (is_profile_editable()) {
  322. $form->addButtonUpdate(get_lang('SaveSettings'), 'apply_change');
  323. } else {
  324. $form->freeze();
  325. }
  326. $form->setDefaults($user_data);
  327. /**
  328. * Is user auth_source is platform ?
  329. *
  330. * @return boolean if auth_source is platform
  331. */
  332. function is_platform_authentication() {
  333. $tab_user_info = api_get_user_info();
  334. return $tab_user_info['auth_source'] == PLATFORM_AUTH_SOURCE;
  335. }
  336. /**
  337. * Can a user edit his/her profile?
  338. *
  339. * @return boolean Editability of the profile
  340. */
  341. function is_profile_editable() {
  342. return $GLOBALS['profileIsEditable'];
  343. }
  344. /*
  345. PRODUCTIONS FUNCTIONS
  346. */
  347. /**
  348. * Upload a submitted user production.
  349. *
  350. * @param $user_id User id
  351. * @return The filename of the new production or FALSE if the upload has failed
  352. */
  353. function upload_user_production($user_id)
  354. {
  355. $production_repository = UserManager::getUserPathById($user_id, 'system');
  356. if (!file_exists($production_repository)) {
  357. @mkdir($production_repository, api_get_permissions_for_new_directories(), true);
  358. }
  359. $filename = api_replace_dangerous_char($_FILES['production']['name']);
  360. $filename = disable_dangerous_file($filename);
  361. if (filter_extension($filename)) {
  362. if (@move_uploaded_file($_FILES['production']['tmp_name'], $production_repository.$filename)) {
  363. return $filename;
  364. }
  365. }
  366. return false; // this should be returned if anything went wrong with the upload
  367. }
  368. /**
  369. * Check current user's current password
  370. * @param char email
  371. * @return bool true o false
  372. * @uses Gets user ID from global variable
  373. */
  374. function check_user_email($email) {
  375. $user_id = api_get_user_id();
  376. if ($user_id != strval(intval($user_id)) || empty($email)) {
  377. return false;
  378. }
  379. $table_user = Database :: get_main_table(TABLE_MAIN_USER);
  380. $email = Database::escape_string($email);
  381. $sql = "SELECT * FROM $table_user
  382. WHERE user_id='".$user_id."' AND email='".$email."'";
  383. $result = Database::query($sql);
  384. return Database::num_rows($result) != 0;
  385. }
  386. $filtered_extension = false;
  387. if ($form->validate()) {
  388. $wrong_current_password = false;
  389. $user_data = $form->getSubmitValues(1);
  390. $user = UserManager::getRepository()->find(api_get_user_id());
  391. // set password if a new one was provided
  392. $validPassword = false;
  393. $passwordWasChecked = false;
  394. if ($user &&
  395. !empty($user_data['password0']) &&
  396. !empty($user_data['password1'])
  397. ) {
  398. $passwordWasChecked = true;
  399. $validPassword = UserManager::isPasswordValid(
  400. $user_data['password0'],
  401. $user
  402. );
  403. if ($validPassword) {
  404. $password = $user_data['password1'];
  405. } else {
  406. Display::addFlash(
  407. Display:: return_message(
  408. get_lang('CurrentPasswordEmptyOrIncorrect'),
  409. 'warning',
  410. false
  411. )
  412. );
  413. }
  414. }
  415. $allow_users_to_change_email_with_no_password = true;
  416. if (is_platform_authentication() &&
  417. api_get_setting('allow_users_to_change_email_with_no_password') == 'false'
  418. ) {
  419. $allow_users_to_change_email_with_no_password = false;
  420. }
  421. // If user sending the email to be changed (input available and not frozen )
  422. if (api_get_setting('profile', 'email') == 'true') {
  423. if ($allow_users_to_change_email_with_no_password) {
  424. if (!check_user_email($user_data['email'])) {
  425. $changeemail = $user_data['email'];
  426. }
  427. } else {
  428. // Normal behaviour
  429. if (!check_user_email($user_data['email']) && $validPassword) {
  430. $changeemail = $user_data['email'];
  431. }
  432. if (!check_user_email($user_data['email']) &&
  433. empty($user_data['password0'])
  434. ){
  435. Display::addFlash(
  436. Display:: return_message(
  437. get_lang('ToChangeYourEmailMustTypeYourPassword'),
  438. 'error',
  439. false
  440. )
  441. );
  442. }
  443. }
  444. }
  445. // Upload picture if a new one is provided
  446. if ($_FILES['picture']['size']) {
  447. $new_picture = UserManager::update_user_picture(
  448. api_get_user_id(),
  449. $_FILES['picture']['name'],
  450. $_FILES['picture']['tmp_name']
  451. );
  452. if ($new_picture) {
  453. $user_data['picture_uri'] = $new_picture;
  454. Display::addFlash(
  455. Display:: return_message(
  456. get_lang('PictureUploaded'),
  457. 'normal',
  458. false
  459. )
  460. );
  461. }
  462. } elseif (!empty($user_data['remove_picture'])) {
  463. // remove existing picture if asked
  464. UserManager::delete_user_picture(api_get_user_id());
  465. $user_data['picture_uri'] = '';
  466. }
  467. // Remove production.
  468. if (isset($user_data['remove_production']) &&
  469. is_array($user_data['remove_production'])
  470. ) {
  471. foreach (array_keys($user_data['remove_production']) as $production) {
  472. UserManager::remove_user_production(api_get_user_id(), urldecode($production));
  473. }
  474. if ($production_list = UserManager::build_production_list(api_get_user_id(), true, true)) {
  475. $form->insertElementBefore(
  476. $form->createElement('static', null, null, $production_list),
  477. 'productions_list'
  478. );
  479. }
  480. $form->removeElement('productions_list');
  481. Display::addFlash(
  482. Display:: return_message(get_lang('FileDeleted'), 'normal', false)
  483. );
  484. }
  485. // upload production if a new one is provided
  486. if (isset($_FILES['production']) && $_FILES['production']['size']) {
  487. $res = upload_user_production(api_get_user_id());
  488. if (!$res) {
  489. //it's a bit excessive to assume the extension is the reason why
  490. // upload_user_production() returned false, but it's true in most cases
  491. $filtered_extension = true;
  492. } else {
  493. Display::addFlash(
  494. Display:: return_message(
  495. get_lang('ProductionUploaded'),
  496. 'normal',
  497. false
  498. )
  499. );
  500. }
  501. }
  502. // remove values that shouldn't go in the database
  503. unset(
  504. $user_data['password0'],
  505. $user_data['password1'],
  506. $user_data['password2'],
  507. $user_data['MAX_FILE_SIZE'],
  508. $user_data['remove_picture'],
  509. $user_data['apply_change'],
  510. $user_data['email']
  511. );
  512. // Following RFC2396 (http://www.faqs.org/rfcs/rfc2396.html), a URI uses ':' as a reserved character
  513. // we can thus ensure the URL doesn't contain any scheme name by searching for ':' in the string
  514. $my_user_openid = isset($user_data['openid']) ? $user_data['openid'] : '';
  515. if (!preg_match('/^[^:]*:\/\/.*$/', $my_user_openid)) {
  516. //ensure there is at least a http:// scheme in the URI provided
  517. $user_data['openid'] = 'http://'.$my_user_openid;
  518. }
  519. $extras = array();
  520. //Checking the user language
  521. $languages = api_get_languages();
  522. if (!in_array($user_data['language'], $languages['folder'])) {
  523. $user_data['language'] = api_get_setting('platformLanguage');
  524. }
  525. $_SESSION['_user']['language'] = $user_data['language'];
  526. //Only update values that are request by the "profile" setting
  527. $profile_list = api_get_setting('profile');
  528. //Adding missing variables
  529. $available_values_to_modify = array();
  530. foreach ($profile_list as $key => $status) {
  531. if ($status == 'true') {
  532. switch($key) {
  533. case 'login':
  534. $available_values_to_modify[] = 'username';
  535. break;
  536. case 'name':
  537. $available_values_to_modify[] = 'firstname';
  538. $available_values_to_modify[] = 'lastname';
  539. break;
  540. case 'picture':
  541. $available_values_to_modify[] = 'picture_uri';
  542. break;
  543. default:
  544. $available_values_to_modify[] = $key;
  545. break;
  546. }
  547. }
  548. }
  549. //Fixing missing variables
  550. $available_values_to_modify = array_merge(
  551. $available_values_to_modify,
  552. array('competences', 'diplomas', 'openarea', 'teach', 'openid')
  553. );
  554. // build SQL query
  555. $sql = "UPDATE $table_user SET";
  556. unset($user_data['api_key_generate']);
  557. foreach ($user_data as $key => $value) {
  558. if (substr($key, 0, 6) == 'extra_') { //an extra field
  559. continue;
  560. } elseif (strpos($key, 'remove_extra_') !== false) {
  561. } else {
  562. if (in_array($key, $available_values_to_modify)) {
  563. $sql .= " $key = '".Database::escape_string($value)."',";
  564. }
  565. }
  566. }
  567. $changePassword = false;
  568. // Change email
  569. if ($allow_users_to_change_email_with_no_password) {
  570. if (isset($changeemail) && in_array('email', $available_values_to_modify)) {
  571. $sql .= " email = '".Database::escape_string($changeemail)."' ";
  572. }
  573. if (isset($password) && in_array('password', $available_values_to_modify)) {
  574. $changePassword = true;
  575. /*$password = api_get_encrypted_password($password);
  576. $sql .= " password = '".Database::escape_string($password)."'";*/
  577. } else {
  578. // remove trailing , from the query we have so far
  579. //$sql = rtrim($sql, ',');
  580. }
  581. } else {
  582. if (isset($changeemail) && !isset($password) && in_array('email', $available_values_to_modify)) {
  583. $sql .= " email = '".Database::escape_string($changeemail)."'";
  584. } else {
  585. if (isset($password) && in_array('password', $available_values_to_modify)) {
  586. if (isset($changeemail) && in_array('email', $available_values_to_modify)) {
  587. $sql .= " email = '".Database::escape_string($changeemail)."' ";
  588. }
  589. $changePassword = true;
  590. /*$password = api_get_encrypted_password($password);
  591. $sql .= " password = '".Database::escape_string($password)."'";*/
  592. } else {
  593. // remove trailing , from the query we have so far
  594. //$sql = rtrim($sql, ',');
  595. }
  596. }
  597. }
  598. $sql = rtrim($sql, ',');
  599. if ($changePassword && !empty($password)) {
  600. UserManager::updatePassword(api_get_user_id(), $password);
  601. }
  602. if (api_get_setting('profile', 'officialcode') == 'true' &&
  603. isset($user_data['official_code'])
  604. ) {
  605. $sql .= ", official_code = '".Database::escape_string($user_data['official_code'])."'";
  606. }
  607. $sql .= " WHERE user_id = '".api_get_user_id()."'";
  608. Database::query($sql);
  609. if ($passwordWasChecked == false) {
  610. Display::addFlash(
  611. Display:: return_message(get_lang('ProfileReg'), 'normal', false)
  612. );
  613. } else {
  614. if ($validPassword) {
  615. Display::addFlash(
  616. Display:: return_message(get_lang('ProfileReg'), 'normal', false)
  617. );
  618. }
  619. }
  620. $extraField = new ExtraFieldValue('user');
  621. $extraField->saveFieldValues($user_data);
  622. $userInfo = api_get_user_info();
  623. Session::write('_user', $userInfo);
  624. // re-init the system to take new settings into account
  625. //$_SESSION['_user']['uidReset'] = true;
  626. //$_SESSION['noredirection'] = true;
  627. $url = api_get_self();
  628. header("Location: ".$url);
  629. exit;
  630. }
  631. // the header
  632. $actions = null;
  633. if (api_get_setting('allow_social_tool') != 'true') {
  634. if (api_get_setting('extended_profile') == 'true') {
  635. $actions .= '<div class="actions">';
  636. if (api_get_setting('allow_social_tool') == 'true' &&
  637. api_get_setting('allow_message_tool') == 'true'
  638. ) {
  639. $actions .= '<a href="'.api_get_path(WEB_PATH).'main/social/profile.php">'.
  640. Display::return_icon('shared_profile.png', get_lang('ViewSharedProfile')).'</a>';
  641. }
  642. if (api_get_setting('allow_message_tool') == 'true') {
  643. $actions .= '<a href="'.api_get_path(WEB_PATH).'main/messages/inbox.php">'.
  644. Display::return_icon('inbox.png', get_lang('Messages')).'</a>';
  645. }
  646. $show = isset($_GET['show']) ? '&amp;show='.Security::remove_XSS($_GET['show']) : '';
  647. if (isset($_GET['type']) && $_GET['type'] == 'extended') {
  648. $actions .= '<a href="profile.php?type=reduced'.$show.'">'.
  649. Display::return_icon('edit.png', get_lang('EditNormalProfile'),'',16).'</a>';
  650. } else {
  651. $actions .= '<a href="profile.php?type=extended'.$show.'">'.
  652. Display::return_icon('edit.png', get_lang('EditExtendProfile'),'',16).'</a>';
  653. }
  654. $actions .= '</div>';
  655. }
  656. }
  657. $show_delete_account_button = api_get_setting('platform_unsubscribe_allowed') == 'true' ? true : false;
  658. $tpl = new Template(get_lang('ModifyProfile'));
  659. $tpl->assign('actions', $actions);
  660. SocialManager::setSocialUserBlock($tpl, $user_id, 'messages');
  661. if (api_get_setting('allow_social_tool') == 'true') {
  662. SocialManager::setSocialUserBlock($tpl, api_get_user_id(), 'home');
  663. $menu = SocialManager::show_social_menu(
  664. 'home',
  665. null,
  666. api_get_user_id(),
  667. false,
  668. $show_delete_account_button
  669. );
  670. $tpl->assign('social_menu_block', $menu);
  671. $tpl->assign('social_right_content', $form->returnForm());
  672. $social_layout = $tpl->get_template('social/edit_profile.tpl');
  673. $tpl->display($social_layout);
  674. } else {
  675. $bigImage = UserManager::getUserPicture(api_get_user_id(), USER_IMAGE_SIZE_BIG);
  676. $normalImage = UserManager::getUserPicture(api_get_user_id(), USER_IMAGE_SIZE_ORIGINAL);
  677. $imageToShow = '<div id="image-message-container">';
  678. $imageToShow .= '<a class="expand-image" href="'.$bigImage.'" /><img src="'.$normalImage.'"></a>';
  679. $imageToShow .= '</div>';
  680. $content = $imageToShow.$form->returnForm();
  681. $tpl->assign('content', $content);
  682. $tpl->display_one_col_template();
  683. }