profile.php 30 KB

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