profile.php 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828
  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. /**
  12. * Code
  13. */
  14. // Language files that should be included.
  15. $language_file = array('registration', 'messages', 'userInfo');
  16. $cidReset = true;
  17. //require_once '../inc/global.inc.php';
  18. if (api_is_profile_readable() == false) {
  19. api_not_allowed(true);
  20. }
  21. if (api_get_setting('allow_social_tool') == 'true') {
  22. $this_section = SECTION_SOCIAL;
  23. } else {
  24. $this_section = SECTION_MYPROFILE;
  25. }
  26. $htmlHeadXtra[] = api_get_password_checker_js('#username', '#password1');
  27. $_SESSION['this_section'] = $this_section;
  28. if (!(isset($_user['user_id']) && $_user['user_id']) || api_is_anonymous($_user['user_id'], true)) {
  29. api_not_allowed(true);
  30. }
  31. $htmlHeadXtra[] = '<script>
  32. function confirmation(name) {
  33. if (confirm("'.get_lang('AreYouSureToDelete', '').' " + name + " ?")) {
  34. document.forms["profile"].submit();
  35. } else {
  36. return false;
  37. }
  38. }
  39. function show_image(image,width,height) {
  40. width = parseInt(width) + 20;
  41. height = parseInt(height) + 20;
  42. window_x = window.open(image,\'windowX\',\'width=\'+ width + \', height=\'+ height + \'\');
  43. }
  44. function generate_open_id_form() {
  45. $.ajax({
  46. contentType: "application/x-www-form-urlencoded",
  47. type: "POST",
  48. url: "'.api_get_path(WEB_AJAX_PATH).'user_manager.ajax.php?a=generate_api_key",
  49. data: "num_key_id="+"",
  50. success: function(datos) {
  51. $("#div_api_key").html(datos);
  52. }
  53. });
  54. }
  55. function hide_icon_edit(element_html) {
  56. ident="#edit_image";
  57. $(ident).hide();
  58. }
  59. function show_icon_edit(element_html) {
  60. ident="#edit_image";
  61. $(ident).show();
  62. }
  63. </script>';
  64. if (!empty ($_GET['coursePath'])) {
  65. $course_url = api_get_path(WEB_COURSE_PATH).htmlentities(strip_tags($_GET['coursePath'])).'/index.php';
  66. $interbreadcrumb[] = array('url' => $course_url, 'name' => Security::remove_XSS($_GET['courseCode']));
  67. }
  68. $warning_msg = '';
  69. if (!empty($_GET['fe'])) {
  70. $warning_msg .= get_lang('UplUnableToSaveFileFilteredExtension');
  71. $_GET['fe'] = null;
  72. }
  73. $jquery_ready_content = '';
  74. if (api_get_setting('allow_message_tool') == 'true') {
  75. $jquery_ready_content = <<<EOF
  76. $(".message-content .message-delete").click(function(){
  77. $(this).parents(".message-content").animate({ opacity: "hide" }, "slow");
  78. $(".message-view").animate({ opacity: "show" }, "slow");
  79. });
  80. EOF;
  81. }
  82. // Libraries
  83. $tool_name = api_is_profile_editable() ? get_lang('ModifProfile') : get_lang('ViewProfile');
  84. $table_user = Database :: get_main_table(TABLE_MAIN_USER);
  85. /* Form */
  86. /*
  87. * Get initial values for all fields.
  88. */
  89. $user_data = UserManager::get_user_info_by_id(api_get_user_id());
  90. $array_list_key = UserManager::get_api_keys(api_get_user_id());
  91. $id_temp_key = UserManager::get_api_key_id(api_get_user_id(), 'dokeos');
  92. $value_array = $array_list_key[$id_temp_key];
  93. $user_data['api_key_generate'] = $value_array;
  94. if ($user_data !== false) {
  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', 'post', api_get_self()."?".str_replace(
  103. '&fe=1',
  104. '',
  105. $_SERVER['QUERY_STRING']
  106. ), null, array('style' => 'width: 70%; float: '.($text_dir == 'rtl' ? 'right;' : 'left;')));
  107. if (api_is_western_name_order()) {
  108. // FIRST NAME and LAST NAME
  109. $form->addElement('text', 'firstname', get_lang('FirstName'), array('size' => 40));
  110. $form->addElement('text', 'lastname', get_lang('LastName'), array('size' => 40));
  111. } else {
  112. // LAST NAME and FIRST NAME
  113. $form->addElement('text', 'lastname', get_lang('LastName'), array('size' => 40));
  114. $form->addElement('text', 'firstname', get_lang('FirstName'), array('size' => 40));
  115. }
  116. if (api_get_setting('profile', 'name') !== 'true') {
  117. $form->freeze(array('lastname', 'firstname'));
  118. }
  119. $form->applyFilter(array('lastname', 'firstname'), 'stripslashes');
  120. $form->applyFilter(array('lastname', 'firstname'), 'trim');
  121. $form->addRule('lastname', get_lang('ThisFieldIsRequired'), 'required');
  122. $form->addRule('firstname', get_lang('ThisFieldIsRequired'), 'required');
  123. // USERNAME
  124. $form->addElement(
  125. 'text',
  126. 'username',
  127. get_lang('UserName'),
  128. array('maxlength' => USERNAME_MAX_LENGTH, 'size' => USERNAME_MAX_LENGTH)
  129. );
  130. if (api_get_setting('profile', 'login') !== '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. if (api_get_setting('registration', 'officialcode') == 'true' && api_get_setting(
  147. 'profile',
  148. 'officialcode'
  149. ) == 'true'
  150. ) {
  151. $form->addRule('official_code', get_lang('ThisFieldIsRequired'), 'required');
  152. }
  153. }
  154. // EMAIL
  155. $form->addElement('email', 'email', get_lang('Email'), array('size' => 40));
  156. if (api_get_setting('profile', 'email') !== 'true') {
  157. $form->freeze('email');
  158. }
  159. if (api_get_setting('registration', 'email') == 'true' && api_get_setting('profile', 'email') == 'true') {
  160. $form->applyFilter('email', 'stripslashes');
  161. $form->applyFilter('email', 'trim');
  162. $form->addRule('email', get_lang('ThisFieldIsRequired'), 'required');
  163. $form->addRule('email', get_lang('EmailWrong'), 'email');
  164. }
  165. // OPENID URL
  166. if (api_is_profile_editable() && api_get_setting('openid_authentication') == 'true') {
  167. $form->addElement('text', 'openid', get_lang('OpenIDURL'), array('size' => 40));
  168. if (api_get_setting('profile', 'openid') !== 'true') {
  169. $form->freeze('openid');
  170. }
  171. $form->applyFilter('openid', 'trim');
  172. //if (api_get_setting('registration', 'openid') == 'true') {
  173. // $form->addRule('openid', get_lang('ThisFieldIsRequired'), 'required');
  174. //}
  175. }
  176. // PHONE
  177. $form->addElement('text', 'phone', get_lang('phone'), array('size' => 20));
  178. if (api_get_setting('profile', 'phone') !== 'true') {
  179. $form->freeze('phone');
  180. }
  181. $form->applyFilter('phone', 'stripslashes');
  182. $form->applyFilter('phone', 'trim');
  183. /*if (api_get_setting('registration', 'phone') == 'true') {
  184. $form->addRule('phone', get_lang('ThisFieldIsRequired'), 'required');
  185. }
  186. $form->addRule('phone', get_lang('EmailWrong'), 'email');*/
  187. // PICTURE
  188. if (api_is_profile_editable() && api_get_setting('profile', 'picture') == 'true') {
  189. $form->addElement(
  190. 'file',
  191. 'picture',
  192. ($user_data['picture_uri'] != '' ? get_lang('UpdateImage') : get_lang('AddImage'))
  193. );
  194. $form->add_progress_bar();
  195. if (!empty($user_data['picture_uri'])) {
  196. $form->addElement('checkbox', 'remove_picture', null, get_lang('DelImage'));
  197. }
  198. $allowed_picture_types = array('jpg', 'jpeg', 'png', 'gif');
  199. $form->addRule(
  200. 'picture',
  201. get_lang('OnlyImagesAllowed').' ('.implode(',', $allowed_picture_types).')',
  202. 'filetype',
  203. $allowed_picture_types
  204. );
  205. }
  206. // LANGUAGE
  207. $form->addElement('select_language', 'language', get_lang('Language'));
  208. if (api_get_setting('profile', 'language') !== 'true') {
  209. $form->freeze('language');
  210. }
  211. //THEME
  212. if (api_is_profile_editable() && api_get_setting('user_selected_theme') == 'true') {
  213. $form->addElement('select_theme', 'theme', get_lang('Theme'));
  214. if (api_get_setting('profile', 'theme') !== 'true') {
  215. $form->freeze('theme');
  216. }
  217. $form->applyFilter('theme', 'trim');
  218. }
  219. // EXTENDED PROFILE this make the page very slow!
  220. if (api_get_setting('extended_profile') == 'true') {
  221. if (!isset($_GET['type']) || (isset($_GET['type']) && $_GET['type'] == 'extended')) {
  222. $width_extended_profile = 500;
  223. //$form->addElement('html', '<a href="javascript: void(0);" onclick="javascript: show_extend();"> show_extend_profile</a>');
  224. //$form->addElement('static', null, '<em>'.get_lang('OptionalTextFields').'</em>');
  225. // MY COMPETENCES
  226. $form->add_html_editor(
  227. 'competences',
  228. get_lang('MyCompetences'),
  229. false,
  230. false,
  231. array('ToolbarSet' => 'Profile', 'Width' => $width_extended_profile, 'Height' => '130')
  232. );
  233. // MY DIPLOMAS
  234. $form->add_html_editor(
  235. 'diplomas',
  236. get_lang('MyDiplomas'),
  237. false,
  238. false,
  239. array('ToolbarSet' => 'Profile', 'Width' => $width_extended_profile, 'Height' => '130')
  240. );
  241. // WHAT I AM ABLE TO TEACH
  242. $form->add_html_editor(
  243. 'teach',
  244. get_lang('MyTeach'),
  245. false,
  246. false,
  247. array('ToolbarSet' => 'Profile', 'Width' => $width_extended_profile, 'Height' => '130')
  248. );
  249. // MY PRODUCTIONS
  250. $form->addElement('file', 'production', get_lang('MyProductions'));
  251. if ($production_list = UserManager::build_production_list(api_get_user_id(), '', true)) {
  252. $form->addElement('static', 'productions_list', null, $production_list);
  253. }
  254. // MY PERSONAL OPEN AREA
  255. $form->add_html_editor(
  256. 'openarea',
  257. get_lang('MyPersonalOpenArea'),
  258. false,
  259. false,
  260. array('ToolbarSet' => 'Profile', 'Width' => $width_extended_profile, 'Height' => '350')
  261. );
  262. $form->applyFilter(array('competences', 'diplomas', 'teach', 'openarea'), 'stripslashes');
  263. $form->applyFilter(
  264. array('competences', 'diplomas', 'teach'),
  265. 'trim'
  266. ); // openarea is untrimmed for maximum openness
  267. }
  268. }
  269. // PASSWORD, if auth_source is platform
  270. if (is_platform_authentication() && api_is_profile_editable() && api_get_setting('profile', 'password') == 'true') {
  271. $form->addElement(
  272. 'password',
  273. 'password0',
  274. array(get_lang('Pass'), get_lang('Enter2passToChange')),
  275. array('size' => 40)
  276. );
  277. $form->addElement('password', 'password1', get_lang('NewPass'), array('size' => 40));
  278. $form->addElement('password', 'password2', get_lang('Confirmation'), array('size' => 40));
  279. // user must enter identical password twice so we can prevent some user errors
  280. $form->addRule(array('password1', 'password2'), get_lang('PassTwo'), 'compare');
  281. if (CHECK_PASS_EASY_TO_FIND) {
  282. $form->addRule('password1', get_lang('CurrentPasswordEmptyOrIncorrect'), 'callback', 'api_check_password');
  283. }
  284. }
  285. // EXTRA FIELDS
  286. $extra_data = UserManager::get_extra_user_data(api_get_user_id(), true);
  287. $extraField = new ExtraField('user');
  288. $return_params = $extraField->set_extra_fields_in_form($form, $extra_data, 'profile', false, api_get_user_id());
  289. $jquery_ready_content = $return_params['jquery_ready_content'];
  290. // the $jquery_ready_content variable collects all functions that will be load in the $(document).ready javascript function
  291. $htmlHeadXtra[] = '<script>
  292. $(document).ready(function(){
  293. '.$jquery_ready_content.'
  294. });
  295. </script>';
  296. if (api_get_setting('profile', 'apikeys') == 'true') {
  297. $form->addElement('html', '<div id="div_api_key">');
  298. $form->addElement(
  299. 'text',
  300. 'api_key_generate',
  301. get_lang('MyApiKey'),
  302. array('size' => 40, 'id' => 'id_api_key_generate')
  303. );
  304. $form->addElement('html', '</div>');
  305. $form->addElement(
  306. 'button',
  307. 'generate_api_key',
  308. get_lang('GenerateApiKey'),
  309. array('id' => 'id_generate_api_key', 'onclick' => 'generate_open_id_form()')
  310. ); //generate_open_id_form()
  311. }
  312. // SUBMIT
  313. if (api_is_profile_editable()) {
  314. $form->addElement('style_submit_button', 'apply_change', get_lang('SaveSettings'), 'class="save"');
  315. } else {
  316. $form->freeze();
  317. }
  318. $user_data = array_merge($user_data, $extra_data);
  319. $form->setDefaults($user_data);
  320. /* FUNCTIONS */
  321. /**
  322. * Is user auth_source is platform ?
  323. *
  324. * @return boolean if auth_source is platform
  325. */
  326. function is_platform_authentication()
  327. {
  328. $tab_user_info = api_get_user_info();
  329. return $tab_user_info['auth_source'] == PLATFORM_AUTH_SOURCE;
  330. }
  331. /*
  332. PRODUCTIONS FUNCTIONS
  333. */
  334. /**
  335. * Upload a submitted user production.
  336. *
  337. * @param $user_id User id
  338. * @return The filename of the new production or FALSE if the upload has failed
  339. */
  340. function upload_user_production($user_id)
  341. {
  342. $image_path = UserManager::get_user_picture_path_by_id($user_id, 'system', true);
  343. $production_repository = $image_path['dir'].$user_id.'/';
  344. if (!file_exists($production_repository)) {
  345. @mkdir($production_repository, api_get_permissions_for_new_directories(), true);
  346. }
  347. $filename = api_replace_dangerous_char($_FILES['production']['name']);
  348. $filename = FileManager::disable_dangerous_file($filename);
  349. if (FileManager::filter_extension($filename)) {
  350. if (@move_uploaded_file($_FILES['production']['tmp_name'], $production_repository.$filename)) {
  351. return $filename;
  352. }
  353. }
  354. return false; // this should be returned if anything went wrong with the upload
  355. }
  356. /**
  357. * Check current user's current password
  358. * @param char password
  359. * @return bool true o false
  360. * @uses Gets user ID from global variable
  361. */
  362. function check_user_password($password)
  363. {
  364. global $_user;
  365. $user_id = api_get_user_id();
  366. if ($user_id != strval(intval($user_id)) || empty($password)) {
  367. return false;
  368. }
  369. $table_user = Database :: get_main_table(TABLE_MAIN_USER);
  370. $password = api_get_encrypted_password($password);
  371. $sql_password = "SELECT * FROM $table_user WHERE user_id='".$user_id."' AND password='".$password."'";
  372. $result = Database::query($sql_password);
  373. return Database::num_rows($result) != 0;
  374. }
  375. /**
  376. * Check current user's current password
  377. * @param char email
  378. * @return bool true o false
  379. * @uses Gets user ID from global variable
  380. */
  381. function check_user_email($email)
  382. {
  383. $user_id = api_get_user_id();
  384. if ($user_id != strval(intval($user_id)) || empty($email)) {
  385. return false;
  386. }
  387. $table_user = Database :: get_main_table(TABLE_MAIN_USER);
  388. $email = Database::escape_string($email);
  389. $sql_password = "SELECT * FROM $table_user WHERE user_id='".$user_id."' AND email='".$email."'";
  390. $result = Database::query($sql_password);
  391. return Database::num_rows($result) != 0;
  392. }
  393. /* MAIN CODE */
  394. $filtered_extension = false;
  395. $update_success = false;
  396. $upload_picture_success = false;
  397. $upload_production_success = false;
  398. $msg_fail_changue_email = false;
  399. $msg_is_not_password = false;
  400. if (is_platform_authentication()) {
  401. if (!empty($_SESSION['change_email'])) {
  402. $msg_fail_changue_email = ($_SESSION['change_email'] == 'success');
  403. unset($_SESSION['change_email']);
  404. } elseif (!empty($_SESSION['is_not_password'])) {
  405. $msg_is_not_password = ($_SESSION['is_not_password'] == 'success');
  406. unset($_SESSION['is_not_password']);
  407. } elseif (!empty($_SESSION['profile_update'])) {
  408. $update_success = ($_SESSION['profile_update'] == 'success');
  409. unset($_SESSION['profile_update']);
  410. } elseif (!empty($_SESSION['image_uploaded'])) {
  411. $upload_picture_success = ($_SESSION['image_uploaded'] == 'success');
  412. unset($_SESSION['image_uploaded']);
  413. } elseif (!empty($_SESSION['production_uploaded'])) {
  414. $upload_production_success = ($_SESSION['production_uploaded'] == 'success');
  415. unset($_SESSION['production_uploaded']);
  416. }
  417. }
  418. if ($form->validate()) {
  419. $wrong_current_password = false;
  420. // $user_data = $form->exportValues();
  421. $user_data = $form->getSubmitValues();
  422. // set password if a new one was provided
  423. if (!empty($user_data['password0'])) {
  424. if (check_user_password($user_data['password0'])) {
  425. if (!empty($user_data['password1'])) {
  426. $password = $user_data['password1'];
  427. }
  428. } else {
  429. $wrong_current_password = true;
  430. $_SESSION['is_not_password'] = 'success';
  431. }
  432. }
  433. if (empty($user_data['password0']) && !empty($user_data['password1'])) {
  434. $wrong_current_password = true;
  435. $_SESSION['is_not_password'] = 'success';
  436. }
  437. $allow_users_to_change_email_with_no_password = true;
  438. if (is_platform_authentication() && api_get_setting('allow_users_to_change_email_with_no_password') == 'false') {
  439. $allow_users_to_change_email_with_no_password = false;
  440. }
  441. //If user sending the email to be changed (input available and not frozen )
  442. if (api_get_setting('profile', 'email') == 'true') {
  443. if ($allow_users_to_change_email_with_no_password) {
  444. if (!check_user_email($user_data['email'])) {
  445. $changeemail = $user_data['email'];
  446. //$_SESSION['change_email'] = 'success';
  447. }
  448. } else {
  449. //Normal behaviour
  450. if (!check_user_email($user_data['email']) && !empty($user_data['password0']) && !$wrong_current_password) {
  451. $changeemail = $user_data['email'];
  452. }
  453. if (!check_user_email($user_data['email']) && empty($user_data['password0'])) {
  454. $_SESSION['change_email'] = 'success';
  455. }
  456. }
  457. }
  458. // Upload picture if a new one is provided
  459. if ($_FILES['picture']['size']) {
  460. if ($new_picture = UserManager::update_user_picture(
  461. api_get_user_id(),
  462. $_FILES['picture']['name'],
  463. $_FILES['picture']['tmp_name']
  464. )
  465. ) {
  466. $user_data['picture_uri'] = $new_picture;
  467. $_SESSION['image_uploaded'] = 'success';
  468. }
  469. } elseif (!empty($user_data['remove_picture'])) {
  470. // remove existing picture if asked
  471. UserManager::delete_user_picture(api_get_user_id());
  472. $user_data['picture_uri'] = '';
  473. }
  474. //Remove production
  475. if (is_array($user_data['remove_production'])) {
  476. foreach (array_keys($user_data['remove_production']) as $production) {
  477. UserManager::remove_user_production(api_get_user_id(), urldecode($production));
  478. }
  479. if ($production_list = UserManager::build_production_list(api_get_user_id(), true, true)) {
  480. $form->insertElementBefore(
  481. $form->createElement('static', null, null, $production_list),
  482. 'productions_list'
  483. );
  484. }
  485. $form->removeElement('productions_list');
  486. $file_deleted = true;
  487. }
  488. // upload production if a new one is provided
  489. if ($_FILES['production']['size']) {
  490. $res = upload_user_production(api_get_user_id());
  491. if (!$res) {
  492. //it's a bit excessive to assume the extension is the reason why upload_user_production() returned false, but it's true in most cases
  493. $filtered_extension = true;
  494. } else {
  495. $_SESSION['production_uploaded'] = 'success';
  496. }
  497. }
  498. // remove values that shouldn't go in the database
  499. unset($user_data['password0'], $user_data['password1'], $user_data['password2'], $user_data['MAX_FILE_SIZE'],
  500. $user_data['remove_picture'], $user_data['apply_change'], $user_data['email']);
  501. // Following RFC2396 (http://www.faqs.org/rfcs/rfc2396.html), a URI uses ':' as a reserved character
  502. // we can thus ensure the URL doesn't contain any scheme name by searching for ':' in the string
  503. $my_user_openid = isset($user_data['openid']) ? $user_data['openid'] : '';
  504. if (!preg_match('/^[^:]*:\/\/.*$/', $my_user_openid)) {
  505. //ensure there is at least a http:// scheme in the URI provided
  506. $user_data['openid'] = 'http://'.$my_user_openid;
  507. }
  508. $extras = array();
  509. //Checking the user language
  510. $languages = api_get_languages();
  511. if (!in_array($user_data['language'], $languages['folder'])) {
  512. $user_data['language'] = api_get_setting('platformLanguage');
  513. }
  514. //Only update values that are request by the "profile" setting
  515. $profile_list = api_get_setting('profile');
  516. //Adding missing variables
  517. $available_values_to_modify = array();
  518. foreach ($profile_list as $key => $status) {
  519. if ($status == 'true') {
  520. switch ($key) {
  521. case 'login':
  522. $available_values_to_modify[] = 'username';
  523. break;
  524. case 'name':
  525. $available_values_to_modify[] = 'firstname';
  526. $available_values_to_modify[] = 'lastname';
  527. break;
  528. case 'picture':
  529. $available_values_to_modify[] = 'picture_uri';
  530. break;
  531. default:
  532. $available_values_to_modify[] = $key;
  533. break;
  534. }
  535. }
  536. }
  537. //Fixing missing variables
  538. $available_values_to_modify = array_merge(
  539. $available_values_to_modify,
  540. array('competences', 'diplomas', 'openarea', 'teach', 'openid')
  541. );
  542. // build SQL query
  543. $sql = "UPDATE $table_user SET";
  544. unset($user_data['api_key_generate']);
  545. foreach ($user_data as $key => $value) {
  546. if (substr($key, 0, 6) == 'extra_') { //an extra field
  547. $new_key = substr($key, 6);
  548. // format array date to 'Y-m-d' or date time to 'Y-m-d H:i:s'
  549. if (is_array($value) && isset($value['Y']) && isset($value['F']) && isset($value['d'])) {
  550. if (isset($value['H']) && isset($value['i'])) {
  551. // extra field date time
  552. $time = mktime($value['H'], $value['i'], 0, $value['F'], $value['d'], $value['Y']);
  553. $extras[$new_key] = date('Y-m-d H:i:s', $time);
  554. } else {
  555. // extra field date
  556. $time = mktime(0, 0, 0, $value['F'], $value['d'], $value['Y']);
  557. $extras[$new_key] = date('Y-m-d', $time);
  558. }
  559. } else {
  560. $extras[$new_key] = $value;
  561. }
  562. } else {
  563. if (in_array($key, $available_values_to_modify)) {
  564. $sql .= " $key = '".Database::escape_string($value)."',";
  565. }
  566. }
  567. }
  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. $password = api_get_encrypted_password($password);
  575. $sql .= " password = '".Database::escape_string($password)."'";
  576. } else {
  577. // remove trailing , from the query we have so far
  578. $sql = rtrim($sql, ',');
  579. }
  580. } else {
  581. //normal behaviour
  582. if (empty($changeemail) && isset($password)) {
  583. $sql .= " email = y@u.com";
  584. }
  585. if (isset($changeemail) && !isset($password) && in_array('email', $available_values_to_modify)) {
  586. $sql .= " email = '".Database::escape_string($changeemail)."'";
  587. } elseif (isset($password) && isset($changeemail) && in_array('email', $available_values_to_modify) && in_array(
  588. 'password',
  589. $available_values_to_modify
  590. )
  591. ) {
  592. $sql .= " email = '".Database::escape_string($changeemail)."',";
  593. $password = api_get_encrypted_password($password);
  594. $sql .= " password = '".Database::escape_string($password)."'";
  595. } elseif (isset($password) && in_array('password', $available_values_to_modify)) {
  596. $password = api_get_encrypted_password($password);
  597. $sql .= " password = '".Database::escape_string($password)."'";
  598. } else {
  599. // remove trailing , from the query we have so far
  600. $sql = rtrim($sql, ',');
  601. }
  602. }
  603. if (api_get_setting('profile', 'officialcode') == 'true' && isset($user_data['official_code'])) {
  604. $sql .= ", official_code = '".Database::escape_string($user_data['official_code'])."'";
  605. }
  606. $sql .= " WHERE user_id = '".api_get_user_id()."'";
  607. Database::query($sql);
  608. // User tag process
  609. //1. Deleting all user tags
  610. $list_extra_field_type_tag = UserManager::get_all_extra_field_by_type(ExtraField::FIELD_TYPE_TAG);
  611. if (is_array($list_extra_field_type_tag) && count($list_extra_field_type_tag) > 0) {
  612. foreach ($list_extra_field_type_tag as $id) {
  613. UserManager::delete_user_tags(api_get_user_id(), $id);
  614. }
  615. }
  616. //2. Update the extra fields and user tags if available
  617. if (is_array($extras) && count($extras) > 0) {
  618. foreach ($extras as $key => $value) {
  619. //3. Tags are process in the UserManager::update_extra_field_value by the UserManager::process_tags function
  620. UserManager::update_extra_field_value(api_get_user_id(), $key, $value);
  621. }
  622. }
  623. // re-init the system to take new settings into account
  624. $_SESSION['_user']['uidReset'] = true;
  625. $_SESSION['noredirection'] = true;
  626. $_SESSION['profile_update'] = 'success';
  627. $url = api_get_self()."?{$_SERVER['QUERY_STRING']}".($filtered_extension && strpos(
  628. $_SERVER['QUERY_STRING'],
  629. '&fe=1'
  630. ) === false ? '&fe=1' : '');
  631. header("Location: ".$url);
  632. exit;
  633. }
  634. /* MAIN DISPLAY SECTION */
  635. // the header
  636. Display::display_header(get_lang('ModifyProfile'));
  637. if (api_get_setting('allow_social_tool') != 'true') {
  638. if (api_get_setting('extended_profile') == 'true') {
  639. echo '<div class="actions">';
  640. if (api_get_setting('allow_social_tool') == 'true' && api_get_setting('allow_message_tool') == 'true') {
  641. echo '<a href="'.api_get_path(WEB_PATH).'main/social/profile.php">'.Display::return_icon(
  642. 'shared_profile.png',
  643. get_lang('ViewSharedProfile')
  644. ).'</a>';
  645. }
  646. if (api_get_setting('allow_message_tool') == 'true') {
  647. echo '<a href="'.api_get_path(WEB_PATH).'main/messages/inbox.php">'.Display::return_icon(
  648. 'inbox.png',
  649. get_lang('Messages')
  650. ).'</a>';
  651. }
  652. $show = isset($_GET['show']) ? '&amp;show='.Security::remove_XSS($_GET['show']) : '';
  653. if (isset($_GET['type']) && $_GET['type'] == 'extended') {
  654. echo '<a href="profile.php?type=reduced'.$show.'">'.Display::return_icon(
  655. 'edit.png',
  656. get_lang('EditNormalProfile'),
  657. '',
  658. 16
  659. ).'</a>';
  660. } else {
  661. echo '<a href="profile.php?type=extended'.$show.'">'.Display::return_icon(
  662. 'edit.png',
  663. get_lang('EditExtendProfile'),
  664. '',
  665. 16
  666. ).'</a>';
  667. }
  668. echo '</div>';
  669. }
  670. }
  671. if (!empty($file_deleted)) {
  672. Display :: display_confirmation_message(get_lang('FileDeleted'), false);
  673. } elseif (!empty($update_success)) {
  674. $message = get_lang('ProfileReg');
  675. if ($upload_picture_success) {
  676. $message .= '<br /> '.get_lang('PictureUploaded');
  677. }
  678. if ($upload_production_success) {
  679. $message .= '<br />'.get_lang('ProductionUploaded');
  680. }
  681. Display :: display_confirmation_message($message, false);
  682. }
  683. if (!empty($msg_fail_changue_email)) {
  684. $errormail = get_lang('ToChangeYourEmailMustTypeYourPassword');
  685. Display :: display_error_message($errormail, false);
  686. }
  687. if (!empty($msg_is_not_password)) {
  688. $warning_msg = get_lang('CurrentPasswordEmptyOrIncorrect');
  689. Display :: display_warning_message($warning_msg, false);
  690. }
  691. //User picture size is calculated from SYSTEM path
  692. $image_syspath = UserManager::get_user_picture_path_by_id(api_get_user_id(), 'system', false, true);
  693. $image_syspath['dir'].$image_syspath['file'];
  694. //$image_size = api_getimagesize($image_syspath['dir'].$image_syspath['file']);
  695. //Web path
  696. $image_path = UserManager::get_user_picture_path_by_id(api_get_user_id(), 'web', false, true);
  697. $image_dir = $image_path['dir'];
  698. $image = $image_path['file'];
  699. $image_file = $image_dir.$image;
  700. $img_attributes = 'src="'.$image_file.'?rand='.time().'" '
  701. .'alt="'.api_get_person_name($user_data['firstname'], $user_data['lastname']).'" '
  702. .'style="float:'.($text_dir == 'rtl' ? 'left' : 'right').'; margin-top:0px;padding:5px;" ';
  703. /*
  704. if ($image_size['width'] > 300) {
  705. //limit display width to 300px
  706. $img_attributes .= 'width="300" ';
  707. }*/
  708. // get the path,width and height from original picture
  709. $big_image = $image_dir.'big_'.$image;
  710. $big_image_size = api_getimagesize($big_image);
  711. $big_image_width = $big_image_size['width'];
  712. $big_image_height = $big_image_size['height'];
  713. $url_big_image = $big_image.'?rnd='.time();
  714. $show_delete_account_button = api_get_setting('platform_unsubscribe_allowed') == 'true' ? true : false;
  715. if (api_get_setting('allow_social_tool') == 'true') {
  716. /*echo '<div class="row-fluid">';
  717. echo '<div class="span3">';
  718. echo SocialManager::show_social_menu('home', null, api_get_user_id(), false, $show_delete_account_button);
  719. echo '</div>';
  720. echo '<div class="span9">';
  721. $form->display();
  722. echo '</div>';*/
  723. } else {
  724. }
  725. // Style position:absolute has been removed for Opera-compatibility.
  726. //echo '<div id="image-message-container" style="float:right;display:inline;position:absolute;padding:3px;width:250px;" >';
  727. echo '<div id="image-message-container" style="float:right;display:inline;padding:3px;width:230px;" >';
  728. if ($image == 'unknown.jpg') {
  729. echo '<img '.$img_attributes.' />';
  730. } else {
  731. echo '<input type="image" '.$img_attributes.' onclick="javascript: return show_image(\''.$url_big_image.'\',\''.$big_image_width.'\',\''.$big_image_height.'\');"/>';
  732. }
  733. echo '</div>';
  734. $form->display();
  735. Display :: display_footer();