profile.php 28 KB

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