profile.php 30 KB

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