profile.php 30 KB

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