profile.php 28 KB

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