profile.php 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858
  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. /* Init section */
  12. // Language files that should be included.
  13. $language_file = array('registration', 'messages', 'userInfo');
  14. $cidReset = true;
  15. require_once '../inc/global.inc.php';
  16. require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php';
  17. if (api_get_setting('allow_social_tool') == 'true') {
  18. $this_section = SECTION_SOCIAL;
  19. } else {
  20. $this_section = SECTION_MYPROFILE;
  21. }
  22. $_SESSION['this_section'] = $this_section;
  23. if (!(isset($_user['user_id']) && $_user['user_id']) || api_is_anonymous($_user['user_id'], true)) {
  24. api_not_allowed(true);
  25. }
  26. //jquery thickbox already called from main/inc/header.inc.php
  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 type="text/javascript">
  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. require_once api_get_path(LIBRARY_PATH).'usermanager.lib.php';
  89. require_once api_get_path(LIBRARY_PATH).'social.lib.php';
  90. $tool_name = is_profile_editable() ? get_lang('ModifProfile') : get_lang('ViewProfile');
  91. $table_user = Database :: get_main_table(TABLE_MAIN_USER);
  92. /* Form */
  93. /*
  94. * Get initial values for all fields.
  95. */
  96. $user_data = UserManager::get_user_info_by_id(api_get_user_id());
  97. $array_list_key = UserManager::get_api_keys(api_get_user_id());
  98. $id_temp_key = UserManager::get_api_key_id(api_get_user_id(), 'dokeos');
  99. $value_array = $array_list_key[$id_temp_key];
  100. $user_data['api_key_generate'] = $value_array;
  101. if ($user_data !== false) {
  102. if (is_null($user_data['language'])) {
  103. $user_data['language'] = api_get_setting('platformLanguage');
  104. }
  105. }
  106. /*
  107. * Initialize the form.
  108. */
  109. $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;')));
  110. /* Make sure this is the first submit on the form, even though it is hidden!
  111. * Otherwise, if a user has productions and presses ENTER to submit, he will
  112. * attempt to delete the first production in the list. */
  113. //if (is_profile_editable()) {
  114. // $form->addElement('style_submit_button', null, get_lang('SaveSettings'), 'class="save"', array('style' => 'visibility:hidden;'));
  115. //}
  116. // SUBMIT (visible)
  117. /*if (is_profile_editable()) {
  118. $form->addElement('style_submit_button', 'apply_change', get_lang('SaveSettings'), 'class="save"');
  119. } else {
  120. $form->freeze();
  121. }*/
  122. //THEME
  123. if (is_profile_editable() && api_get_setting('user_selected_theme') == 'true') {
  124. $form->addElement('select_theme', 'theme', get_lang('Theme'));
  125. if (api_get_setting('profile', 'theme') !== 'true')
  126. $form->freeze('theme');
  127. $form->applyFilter('theme', 'trim');
  128. }
  129. if (api_is_western_name_order()) {
  130. // FIRST NAME and LAST NAME
  131. $form->addElement('text', 'firstname', get_lang('FirstName'), array('size' => 40));
  132. $form->addElement('text', 'lastname', get_lang('LastName'), array('size' => 40));
  133. } else {
  134. // LAST NAME and FIRST NAME
  135. $form->addElement('text', 'lastname', get_lang('LastName'), array('size' => 40));
  136. $form->addElement('text', 'firstname', get_lang('FirstName'), array('size' => 40));
  137. }
  138. if (api_get_setting('profile', 'name') !== 'true') {
  139. $form->freeze(array('lastname', 'firstname'));
  140. }
  141. $form->applyFilter(array('lastname', 'firstname'), 'stripslashes');
  142. $form->applyFilter(array('lastname', 'firstname'), 'trim');
  143. $form->addRule('lastname' , get_lang('ThisFieldIsRequired'), 'required');
  144. $form->addRule('firstname', get_lang('ThisFieldIsRequired'), 'required');
  145. // USERNAME
  146. $form->addElement('text', 'username', get_lang('UserName'), array('maxlength' => USERNAME_MAX_LENGTH, 'size' => 40));
  147. if (api_get_setting('profile', 'login') !== 'true') {
  148. $form->freeze('username');
  149. }
  150. $form->applyFilter('username', 'stripslashes');
  151. $form->applyFilter('username', 'trim');
  152. $form->addRule('username', get_lang('ThisFieldIsRequired'), 'required');
  153. $form->addRule('username', get_lang('UsernameWrong'), 'username');
  154. $form->addRule('username', get_lang('UserTaken'), 'username_available', $user_data['username']);
  155. // OFFICIAL CODE
  156. if (CONFVAL_ASK_FOR_OFFICIAL_CODE) {
  157. $form->addElement('text', 'official_code', get_lang('OfficialCode'), array('size' => 40));
  158. if (api_get_setting('profile', 'officialcode') !== 'true') {
  159. $form->freeze('official_code');
  160. }
  161. $form->applyFilter('official_code', 'stripslashes');
  162. $form->applyFilter('official_code', 'trim');
  163. if (api_get_setting('registration', 'officialcode') == 'true' && api_get_setting('profile', 'officialcode') == 'true') {
  164. $form->addRule('official_code', get_lang('ThisFieldIsRequired'), 'required');
  165. }
  166. }
  167. // EMAIL
  168. $form->addElement('text', 'email', get_lang('Email'), array('size' => 40));
  169. if (api_get_setting('profile', 'email') !== 'true') {
  170. $form->freeze('email');
  171. }
  172. $form->applyFilter('email', 'stripslashes');
  173. $form->applyFilter('email', 'trim');
  174. if (api_get_setting('registration', 'email') == 'true') {
  175. $form->addRule('email', get_lang('ThisFieldIsRequired'), 'required');
  176. }
  177. $form->addRule('email', get_lang('EmailWrong'), 'email');
  178. // OPENID URL
  179. if (is_profile_editable() && api_get_setting('openid_authentication') == 'true') {
  180. $form->addElement('text', 'openid', get_lang('OpenIDURL'), array('size' => 40));
  181. if (api_get_setting('profile', 'openid') !== 'true') {
  182. $form->freeze('openid');
  183. }
  184. $form->applyFilter('openid', 'trim');
  185. //if (api_get_setting('registration', 'openid') == 'true') {
  186. // $form->addRule('openid', get_lang('ThisFieldIsRequired'), 'required');
  187. //}
  188. }
  189. // PHONE
  190. $form->addElement('text', 'phone', get_lang('phone'), array('size' => 20));
  191. if (api_get_setting('profile', 'phone') !== 'true') {
  192. $form->freeze('phone');
  193. }
  194. $form->applyFilter('phone', 'stripslashes');
  195. $form->applyFilter('phone', 'trim');
  196. /*if (api_get_setting('registration', 'phone') == 'true') {
  197. $form->addRule('phone', get_lang('ThisFieldIsRequired'), 'required');
  198. }
  199. $form->addRule('phone', get_lang('EmailWrong'), 'email');*/
  200. // PICTURE
  201. if (is_profile_editable() && api_get_setting('profile', 'picture') == 'true') {
  202. $form->addElement('file', 'picture', ($user_data['picture_uri'] != '' ? get_lang('UpdateImage') : get_lang('AddImage')));
  203. $form->add_progress_bar();
  204. if (!empty($user_data['picture_uri'])) {
  205. $form->addElement('checkbox', 'remove_picture', null, get_lang('DelImage'));
  206. }
  207. $allowed_picture_types = array ('jpg', 'jpeg', 'png', 'gif');
  208. $form->addRule('picture', get_lang('OnlyImagesAllowed').' ('.implode(',', $allowed_picture_types).')', 'filetype', $allowed_picture_types);
  209. }
  210. // LANGUAGE
  211. $form->addElement('select_language', 'language', get_lang('Language'));
  212. if (api_get_setting('profile', 'language') !== 'true') {
  213. $form->freeze('language');
  214. }
  215. // EXTENDED PROFILE this make the page very slow!
  216. if (api_get_setting('extended_profile') == 'true') {
  217. if (!isset($_GET['type']) || (isset($_GET['type']) && $_GET['type'] == 'extended')) {
  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' => '580', 'Height' => '130'));
  222. // MY DIPLOMAS
  223. $form->add_html_editor('diplomas', get_lang('MyDiplomas'), false, false, array('ToolbarSet' => 'Profile', 'Width' => '580', 'Height' => '130'));
  224. // WHAT I AM ABLE TO TEACH
  225. $form->add_html_editor('teach', get_lang('MyTeach'), false, false, array('ToolbarSet' => 'Profile', 'Width' => '580', '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' => '580', '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
  238. if (is_profile_editable() && api_get_setting('profile', 'password') == 'true') {
  239. $form->addElement('password', 'password0', get_lang('Pass'), array('size' => 40));
  240. $form->addElement('static', null, null, '<em>'.get_lang('Enter2passToChange').'</em>');
  241. $form->addElement('password', 'password1', get_lang('NewPass'), array('size' => 40));
  242. $form->addElement('password', 'password2', get_lang('Confirmation'), array('size' => 40));
  243. // user must enter identical password twice so we can prevent some user errors
  244. $form->addRule(array('password1', 'password2'), get_lang('PassTwo'), 'compare');
  245. if (CHECK_PASS_EASY_TO_FIND) {
  246. $form->addRule('password1', get_lang('PassTooEasy').': '.api_generate_password(), 'callback', 'api_check_password');
  247. }
  248. }
  249. // EXTRA FIELDS
  250. $extra = UserManager::get_extra_fields(0, 50, 5, 'ASC');
  251. $extra_data = UserManager::get_extra_user_data(api_get_user_id(), true);
  252. foreach ($extra as $id => $field_details) {
  253. if ($field_details[6] == 0) {
  254. continue;
  255. }
  256. switch ($field_details[2]) {
  257. case USER_FIELD_TYPE_TEXT:
  258. $form->addElement('text', 'extra_'.$field_details[1], $field_details[3], array('size' => 40));
  259. $form->applyFilter('extra_'.$field_details[1], 'stripslashes');
  260. $form->applyFilter('extra_'.$field_details[1], 'trim');
  261. if ($field_details[7] == 0) $form->freeze('extra_'.$field_details[1]);
  262. break;
  263. case USER_FIELD_TYPE_TEXTAREA:
  264. $form->add_html_editor('extra_'.$field_details[1], $field_details[3], false);
  265. //$form->addElement('textarea', 'extra_'.$field_details[1], $field_details[3], array('size' => 80));
  266. $form->applyFilter('extra_'.$field_details[1], 'stripslashes');
  267. $form->applyFilter('extra_'.$field_details[1], 'trim');
  268. if ($field_details[7] == 0) $form->freeze('extra_'.$field_details[1]);
  269. break;
  270. case USER_FIELD_TYPE_RADIO:
  271. $group = array();
  272. foreach ($field_details[9] as $option_id => $option_details) {
  273. $options[$option_details[1]] = $option_details[2];
  274. $group[] =& HTML_QuickForm::createElement('radio', 'extra_'.$field_details[1], $option_details[1], $option_details[2].'<br />', $option_details[1]);
  275. }
  276. $form->addGroup($group, 'extra_'.$field_details[1], $field_details[3], '');
  277. if ($field_details[7] == 0) $form->freeze('extra_'.$field_details[1]);
  278. break;
  279. case USER_FIELD_TYPE_SELECT:
  280. if (in_array($field_details[1], array('mail_notify_invitation', 'mail_notify_message', 'mail_notify_group_message'))) {
  281. $field_details[3] = get_lang($field_details[3]);
  282. }
  283. $options = array();
  284. foreach ($field_details[9] as $option_id => $option_details) {
  285. if (in_array($field_details[1], array('mail_notify_invitation', 'mail_notify_message', 'mail_notify_group_message'))) {
  286. $option_details[2] = get_lang($option_details[2]);
  287. }
  288. $options[$option_details[1]] = $option_details[2];
  289. }
  290. $form->addElement('select', 'extra_'.$field_details[1], $field_details[3], $options, '');
  291. if ($field_details[7] == 0) $form->freeze('extra_'.$field_details[1]);
  292. break;
  293. case USER_FIELD_TYPE_SELECT_MULTIPLE:
  294. $options = array();
  295. foreach ($field_details[9] as $option_id => $option_details) {
  296. $options[$option_details[1]] = $option_details[2];
  297. }
  298. $form->addElement('select', 'extra_'.$field_details[1], $field_details[3], $options, array('multiple' => 'multiple'));
  299. if ($field_details[7] == 0) $form->freeze('extra_'.$field_details[1]);
  300. break;
  301. case USER_FIELD_TYPE_DATE:
  302. $form->addElement('datepickerdate', 'extra_'.$field_details[1], $field_details[3], array('form_name' => 'profile'));
  303. $form->_elements[$form->_elementIndex['extra_'.$field_details[1]]]->setLocalOption('minYear', 1900);
  304. if ($field_details[7] == 0) $form->freeze('extra_'.$field_details[1]);
  305. $form->applyFilter('theme', 'trim');
  306. $defaults['extra_'.$field_details[1]] = date('Y-m-d 12:00:00');
  307. $form -> setDefaults($defaults);
  308. break;
  309. case USER_FIELD_TYPE_DATETIME:
  310. $form->addElement('datepicker', 'extra_'.$field_details[1],$field_details[3], array('form_name' => 'profile'));
  311. $form->_elements[$form->_elementIndex['extra_'.$field_details[1]]]->setLocalOption('minYear', 1900);
  312. if ($field_details[7] == 0) $form->freeze('extra_'.$field_details[1]);
  313. $form->applyFilter('theme', 'trim');
  314. $defaults['extra_'.$field_details[1]] = date('Y-m-d 12:00:00');
  315. $form -> setDefaults($defaults);
  316. break;
  317. case USER_FIELD_TYPE_DOUBLE_SELECT:
  318. foreach ($field_details[9] as $key => $element) {
  319. if ($element[2][0] == '*') {
  320. $values['*'][$element[0]] = str_replace('*', '', $element[2]);
  321. } else {
  322. $values[0][$element[0]] = $element[2];
  323. }
  324. }
  325. $group = '';
  326. $group[] =& HTML_QuickForm::createElement('select', 'extra_'.$field_details[1], '', $values[0], '');
  327. $group[] =& HTML_QuickForm::createElement('select', 'extra_'.$field_details[1].'*', '', $values['*'], '');
  328. $form->addGroup($group, 'extra_'.$field_details[1], $field_details[3], '&nbsp;');
  329. if ($field_details[7] == 0) $form->freeze('extra_'.$field_details[1]);
  330. // recoding the selected values for double : if the user has selected certain values, we have to assign them to the correct select form
  331. if (key_exists('extra_'.$field_details[1], $extra_data)) {
  332. // exploding all the selected values (of both select forms)
  333. $selected_values = explode(';', $extra_data['extra_'.$field_details[1]]);
  334. $extra_data['extra_'.$field_details[1]] = array();
  335. // looping through the selected values and assigning the selected values to either the first or second select form
  336. foreach ($selected_values as $key=>$selected_value) {
  337. if (key_exists($selected_value,$values[0])) {
  338. $extra_data['extra_'.$field_details[1]]['extra_'.$field_details[1]] = $selected_value;
  339. } else {
  340. $extra_data['extra_'.$field_details[1]]['extra_'.$field_details[1].'*'] = $selected_value;
  341. }
  342. }
  343. }
  344. break;
  345. case USER_FIELD_TYPE_DIVIDER:
  346. $form->addElement('static', $field_details[1], '<br /><strong>'.$field_details[3].'</strong>');
  347. break;
  348. case USER_FIELD_TYPE_TAG:
  349. //the magic should be here
  350. $user_tags = UserManager::get_user_tags(api_get_user_id(),$field_details[0]);
  351. $pre_html = '<div class="row">
  352. <div class="label">'.$field_details[3].'</div>
  353. <div class="formw">';
  354. $post = '</div></div>';
  355. $tag_list = '';
  356. if (is_array($user_tags) && count($user_tags)> 0) {
  357. foreach ($user_tags as $tag) {
  358. $tag_list .= '<option value="'.$tag['tag'].'" class="selected">'.$tag['tag'].'</option>';
  359. }
  360. }
  361. $multi_select = '<select id="extra_'.$field_details[1].'" name="extra_'.$field_details[1].'">
  362. '.$tag_list.'
  363. </select>';
  364. $form->addElement('html',$pre_html.$multi_select.$post );
  365. $url = api_get_path(WEB_AJAX_PATH).'user_manager.ajax.php';
  366. $complete_text = get_lang('StartToType');
  367. //if cache is set to true the jquery will be called 1 time
  368. $jquery_ready_content.= <<<EOF
  369. $("#extra_$field_details[1]").fcbkcomplete({
  370. json_url: "$url?a=search_tags&field_id=$field_details[0]",
  371. cache: false,
  372. filter_case: true,
  373. filter_hide: true,
  374. complete_text:"$complete_text",
  375. firstselected: true,
  376. //onremove: "testme",
  377. //onselect: "testme",
  378. filter_selected: true,
  379. newel: true
  380. });
  381. EOF;
  382. break;
  383. case USER_FIELD_TYPE_TIMEZONE:
  384. $form->addElement('select', 'extra_'.$field_details[1], $field_details[3], api_get_timezones(), '');
  385. if ($field_details[7] == 0) $form->freeze('extra_'.$field_details[1]);
  386. break;
  387. case USER_FIELD_TYPE_SOCIAL_PROFILE:
  388. // get the social network's favicon
  389. $icon_path = UserManager::get_favicon_from_url($extra_data['extra_'.$field_details[1]], $field_details[4]);
  390. // special hack for hi5
  391. $leftpad = '1.7'; $top = '0.4'; $domain = parse_url($icon_path, PHP_URL_HOST); if ($domain == 'www.hi5.com' or $domain == 'hi5.com') { $leftpad = '3'; $top = '0';}
  392. // print the input field
  393. $form->addElement('text', 'extra_'.$field_details[1], $field_details[3], array('size' => 60, 'style' => 'background-image: url(\''.$icon_path.'\'); background-repeat: no-repeat; background-position: 0.4em '.$top.'em; padding-left: '.$leftpad.'em; '));
  394. $form->applyFilter('extra_'.$field_details[1], 'stripslashes');
  395. $form->applyFilter('extra_'.$field_details[1], 'trim');
  396. if ($field_details[7] == 0) $form->freeze('extra_'.$field_details[1]);
  397. break;
  398. }
  399. }
  400. // the $jquery_ready_content variable collects all functions that will be load in the $(document).ready javascript function
  401. $htmlHeadXtra[] ='<script type="text/javascript">
  402. $(document).ready(function(){
  403. '.$jquery_ready_content.'
  404. });
  405. </script>';
  406. if (api_get_setting('profile', 'apikeys') == 'true') {
  407. $form->addElement('html', '<div id="div_api_key">');
  408. $form->addElement('text', 'api_key_generate', get_lang('MyApiKey'), array('size' => 40, 'id' => 'id_api_key_generate'));
  409. $form->addElement('html', '</div>');
  410. $form->addElement('button', 'generate_api_key', get_lang('GenerateApiKey'), array('id' => 'id_generate_api_key', 'onclick' => 'generate_open_id_form()')); //generate_open_id_form()
  411. }
  412. // SUBMIT
  413. if (is_profile_editable()) {
  414. $form->addElement('style_submit_button', 'apply_change', get_lang('SaveSettings'), 'class="save"');
  415. } else {
  416. $form->freeze();
  417. }
  418. $user_data = array_merge($user_data, $extra_data);
  419. $form->setDefaults($user_data);
  420. /* FUNCTIONS */
  421. /**
  422. * Can a user edit his/her profile?
  423. *
  424. * @return boolean Editability of the profile
  425. */
  426. function is_profile_editable() {
  427. return $GLOBALS['profileIsEditable'];
  428. }
  429. /*
  430. PRODUCTIONS FUNCTIONS
  431. */
  432. /**
  433. * Upload a submitted user production.
  434. *
  435. * @param $user_id User id
  436. * @return The filename of the new production or FALSE if the upload has failed
  437. */
  438. function upload_user_production($user_id) {
  439. $image_path = UserManager::get_user_picture_path_by_id($user_id, 'system', true);
  440. $production_repository = $image_path['dir'].$user_id.'/';
  441. if (!file_exists($production_repository)) {
  442. @mkdir($production_repository, api_get_permissions_for_new_directories(), true);
  443. }
  444. $filename = replace_dangerous_char($_FILES['production']['name']);
  445. $filename = disable_dangerous_file($filename);
  446. if (filter_extension($filename)) {
  447. if (@move_uploaded_file($_FILES['production']['tmp_name'], $production_repository.$filename)) {
  448. return $filename;
  449. }
  450. }
  451. return false; // this should be returned if anything went wrong with the upload
  452. }
  453. /**
  454. * Check current user's current password
  455. * @param char password
  456. * @return bool true o false
  457. * @uses Gets user ID from global variable
  458. */
  459. function check_user_password($password){
  460. global $_user;
  461. $user_id = api_get_user_id();
  462. if ($user_id != strval(intval($user_id)) || empty($password)) { return false; }
  463. $table_user = Database :: get_main_table(TABLE_MAIN_USER);
  464. $password = api_get_encrypted_password($password);
  465. $sql_password = "SELECT * FROM $table_user WHERE user_id='".$user_id."' AND password='".$password."'";
  466. $result = Database::query($sql_password);
  467. return Database::num_rows($result) != 0;
  468. }
  469. /**
  470. * Check current user's current password
  471. * @param char email
  472. * @return bool true o false
  473. * @uses Gets user ID from global variable
  474. */
  475. function check_user_email($email){
  476. global $_user;
  477. $user_id = api_get_user_id();
  478. if ($user_id != strval(intval($user_id)) || empty($email)) { return false; }
  479. $table_user = Database :: get_main_table(TABLE_MAIN_USER);
  480. $sql_password = "SELECT * FROM $table_user WHERE user_id='".$user_id."' AND email='".$email."'";
  481. $result = Database::query($sql_password);
  482. return Database::num_rows($result) != 0;
  483. }
  484. /* MAIN CODE */
  485. $filtered_extension = false;
  486. $update_success = false;
  487. $upload_picture_success = false;
  488. $upload_production_success = false;
  489. $msg_fail_changue_email = false;
  490. $msg_is_not_password = false;
  491. if (!empty($_SESSION['change_email'])) {
  492. $msg_fail_changue_email= ($_SESSION['change_email'] == 'success');
  493. unset($_SESSION['change_email']);
  494. } elseif (!empty($_SESSION['is_not_password'])) {
  495. $msg_is_not_password = ($_SESSION['is_not_password'] == 'success');
  496. unset($_SESSION['is_not_password']);
  497. } elseif (!empty($_SESSION['profile_update'])) {
  498. $update_success = ($_SESSION['profile_update'] == 'success');
  499. unset($_SESSION['profile_update']);
  500. } elseif (!empty($_SESSION['image_uploaded'])) {
  501. $upload_picture_success = ($_SESSION['image_uploaded'] == 'success');
  502. unset($_SESSION['image_uploaded']);
  503. } elseif (!empty($_SESSION['production_uploaded'])) {
  504. $upload_production_success = ($_SESSION['production_uploaded'] == 'success');
  505. unset($_SESSION['production_uploaded']);
  506. }
  507. if ($form->validate()) {
  508. $wrong_current_password = false;
  509. // $user_data = $form->exportValues();
  510. $user_data = $form->getSubmitValues();
  511. // set password if a new one was provided
  512. if (!empty($user_data['password0'])) {
  513. if (check_user_password($user_data['password0'])) {
  514. if (!empty($user_data['password1'])) {
  515. $password = $user_data['password1'];
  516. }
  517. } else {
  518. $wrong_current_password = true;
  519. $_SESSION['is_not_password'] = 'success';
  520. }
  521. }
  522. if (empty($user_data['password0']) && !empty($user_data['password1'])) {
  523. $wrong_current_password = true;
  524. $_SESSION['is_not_password'] = 'success';
  525. }
  526. if (!check_user_email($user_data['email']) && !empty($user_data['password0']) && !$wrong_current_password) {
  527. $changeemail = $user_data['email'];
  528. }
  529. if (!check_user_email($user_data['email']) && empty($user_data['password0'])){
  530. $_SESSION['change_email'] = 'success';
  531. }
  532. // Upload picture if a new one is provided
  533. if ($_FILES['picture']['size']) {
  534. if ($new_picture = UserManager::update_user_picture(api_get_user_id(), $_FILES['picture']['name'], $_FILES['picture']['tmp_name'])) {
  535. $user_data['picture_uri'] = $new_picture;
  536. $_SESSION['image_uploaded'] = 'success';
  537. }
  538. } elseif (!empty($user_data['remove_picture'])) {
  539. // remove existing picture if asked
  540. UserManager::delete_user_picture(api_get_user_id());
  541. $user_data['picture_uri'] = '';
  542. }
  543. //Remove production
  544. if (is_array($user_data['remove_production'])) {
  545. foreach (array_keys($user_data['remove_production']) as $production) {
  546. UserManager::remove_user_production(api_get_user_id(), urldecode($production));
  547. }
  548. if ($production_list = UserManager::build_production_list(api_get_user_id(), true, true)) {
  549. $form->insertElementBefore($form->createElement('static', null, null, $production_list), 'productions_list');
  550. }
  551. $form->removeElement('productions_list');
  552. $file_deleted = true;
  553. }
  554. // upload production if a new one is provided
  555. if ($_FILES['production']['size']) {
  556. $res = upload_user_production(api_get_user_id());
  557. if (!$res) {
  558. //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
  559. $filtered_extension = true;
  560. } else {
  561. $_SESSION['production_uploaded'] = 'success';
  562. }
  563. }
  564. // remove values that shouldn't go in the database
  565. unset($user_data['password0'],$user_data['password1'], $user_data['password2'], $user_data['MAX_FILE_SIZE'],
  566. $user_data['remove_picture'], $user_data['apply_change'],$user_data['email'] );
  567. // Following RFC2396 (http://www.faqs.org/rfcs/rfc2396.html), a URI uses ':' as a reserved character
  568. // we can thus ensure the URL doesn't contain any scheme name by searching for ':' in the string
  569. $my_user_openid = isset($user_data['openid']) ? $user_data['openid'] : '';
  570. if (!preg_match('/^[^:]*:\/\/.*$/', $my_user_openid)) {
  571. //ensure there is at least a http:// scheme in the URI provided
  572. $user_data['openid'] = 'http://'.$my_user_openid;
  573. }
  574. $extras = array();
  575. //Checking the user language
  576. $languages = api_get_languages();
  577. if (!in_array($user_data['language'], $languages['folder'])) {
  578. $user_data['language'] = api_get_setting('platformLanguage');
  579. }
  580. //Only update values that are request by the "profile" setting
  581. $profile_list = api_get_setting('profile');
  582. //Adding missing variables
  583. $available_values_to_modify = array();
  584. foreach($profile_list as $key => $status) {
  585. if ($status == 'true') {
  586. if ($key == 'name') {
  587. $available_values_to_modify[] = 'firstname';
  588. $available_values_to_modify[] = 'lastname';
  589. } elseif ($key == 'picture') {
  590. $available_values_to_modify[] = 'picture_uri';
  591. } else {
  592. $available_values_to_modify[] = $key;
  593. }
  594. }
  595. }
  596. //Fixing missing variables
  597. $available_values_to_modify = array_merge($available_values_to_modify, array('competences', 'diplomas', 'openarea', 'teach', 'openid'));
  598. // build SQL query
  599. $sql = "UPDATE $table_user SET";
  600. unset($user_data['api_key_generate']);
  601. foreach ($user_data as $key => $value) {
  602. if (substr($key, 0, 6) == 'extra_') { //an extra field
  603. $new_key = substr($key, 6);
  604. // format array date to 'Y-m-d' or date time to 'Y-m-d H:i:s'
  605. if (is_array($value) && isset($value['Y']) && isset($value['F']) && isset($value['d'])) {
  606. if (isset($value['H']) && isset($value['i'])) {
  607. // extra field date time
  608. $time = mktime($value['H'],$value['i'],0,$value['F'],$value['d'],$value['Y']);
  609. $extras[$new_key] = date('Y-m-d H:i:s',$time);
  610. } else {
  611. // extra field date
  612. $time = mktime(0,0,0,$value['F'],$value['d'],$value['Y']);
  613. $extras[$new_key] = date('Y-m-d',$time);
  614. }
  615. } else {
  616. $extras[$new_key] = $value;
  617. }
  618. } else {
  619. if (in_array($key, $available_values_to_modify)) {
  620. $sql .= " $key = '".Database::escape_string($value)."',";
  621. }
  622. }
  623. }
  624. //changue email
  625. if (isset($changeemail) && !isset($password) && in_array('email', $available_values_to_modify)) {
  626. $sql .= " email = '".Database::escape_string($changeemail)."' ";
  627. } elseif (isset($password) && isset($changeemail) && in_array('email', $available_values_to_modify) && in_array('password', $available_values_to_modify)) {
  628. $sql .= " email = '".Database::escape_string($changeemail)."', ";
  629. $password = api_get_encrypted_password($password);
  630. $sql .= " password = '".Database::escape_string($password)."'";
  631. } elseif (isset($password) && !isset($changeemail) && in_array('password', $available_values_to_modify)) {
  632. $password = api_get_encrypted_password($password);
  633. $sql .= " password = '".Database::escape_string($password)."'";
  634. } else {
  635. // remove trailing , from the query we have so far
  636. $sql = rtrim($sql, ',');
  637. }
  638. $sql .= " WHERE user_id = '".api_get_user_id()."'";
  639. Database::query($sql);
  640. // User tag process
  641. //1. Deleting all user tags
  642. $list_extra_field_type_tag = UserManager::get_all_extra_field_by_type(USER_FIELD_TYPE_TAG);
  643. if (is_array($list_extra_field_type_tag) && count($list_extra_field_type_tag)>0) {
  644. foreach ($list_extra_field_type_tag as $id) {
  645. UserManager::delete_user_tags(api_get_user_id(), $id);
  646. }
  647. }
  648. //2. Update the extra fields and user tags if available
  649. if (is_array($extras) && count($extras)> 0) {
  650. foreach ($extras as $key => $value) {
  651. //3. Tags are process in the UserManager::update_extra_field_value by the UserManager::process_tags function
  652. $myres = UserManager::update_extra_field_value(api_get_user_id(), $key, $value);
  653. }
  654. }
  655. // re-init the system to take new settings into account
  656. $uidReset = true;
  657. include api_get_path(INCLUDE_PATH).'local.inc.php';
  658. $_SESSION['profile_update'] = 'success';
  659. header("Location: ".api_get_self()."?{$_SERVER['QUERY_STRING']}".($filtered_extension && strpos($_SERVER['QUERY_STRING'], '&fe=1') === false ? '&fe=1' : ''));
  660. exit;
  661. }
  662. /* MAIN DISPLAY SECTION */
  663. // the header
  664. Display::display_header(get_lang('ModifyProfile'));
  665. if (api_get_setting('allow_social_tool') != 'true') {
  666. if (api_get_setting('extended_profile') == 'true') {
  667. echo '<div class="actions">';
  668. if (api_get_setting('allow_social_tool') == 'true' && api_get_setting('allow_message_tool') == 'true') {
  669. echo '<a href="'.api_get_path(WEB_PATH).'main/social/profile.php">'.Display::return_icon('shared_profile.png', get_lang('ViewSharedProfile')).'&nbsp;'.get_lang('ViewSharedProfile').'</a>';
  670. }
  671. if (api_get_setting('allow_message_tool') == 'true') {
  672. echo '<a href="'.api_get_path(WEB_PATH).'main/messages/inbox.php">'.Display::return_icon('inbox.png').' '.get_lang('Messages').'</a>';
  673. }
  674. $show = isset($_GET['show']) ? '&amp;show='.Security::remove_XSS($_GET['show']) : '';
  675. if (isset($_GET['type']) && $_GET['type'] == 'extended') {
  676. echo '<a href="profile.php?type=reduced'.$show.'">'.Display::return_icon('edit.png', get_lang('EditNormalProfile'),'',16).'&nbsp;'.get_lang('EditNormalProfile').'</a>';
  677. } else {
  678. echo '<a href="profile.php?type=extended'.$show.'">'.Display::return_icon('edit.png', get_lang('EditExtendProfile'),'',16).'&nbsp;'.get_lang('EditExtendProfile').'</a>';
  679. }
  680. echo '</div>';
  681. }
  682. }
  683. if (!empty($file_deleted)) {
  684. Display :: display_confirmation_message(get_lang('FileDeleted'), false);
  685. } elseif (!empty($update_success)) {
  686. $message = get_lang('ProfileReg');
  687. if ($upload_picture_success) {
  688. $message .= '<br /> '.get_lang('PictureUploaded');
  689. }
  690. if ($upload_production_success) {
  691. $message.='<br />'.get_lang('ProductionUploaded');
  692. }
  693. Display :: display_confirmation_message($message, false);
  694. }
  695. if (!empty($msg_fail_changue_email)){
  696. $errormail=get_lang('ToChangeYourEmailMustTypeYourPassword');
  697. Display :: display_error_message($errormail, false);
  698. }
  699. if (!empty($msg_is_not_password)){
  700. $warning_msg = get_lang('CurrentPasswordEmptyOrIncorrect');
  701. Display :: display_warning_message($warning_msg, false);
  702. }
  703. //User picture size is calculated from SYSTEM path
  704. $image_syspath = UserManager::get_user_picture_path_by_id(api_get_user_id(), 'system', false, true);
  705. $image_syspath['dir'].$image_syspath['file'];
  706. $image_size = api_getimagesize($image_syspath['dir'].$image_syspath['file']);
  707. //Web path
  708. $image_path = UserManager::get_user_picture_path_by_id(api_get_user_id(), 'web', false, true);
  709. $image_dir = $image_path['dir'];
  710. $image = $image_path['file'];
  711. $image_file = $image_dir.$image;
  712. $img_attributes = 'src="'.$image_file.'?rand='.time().'" '
  713. .'alt="'.api_get_person_name($user_data['firstname'], $user_data['lastname']).'" '
  714. .'style="float:'.($text_dir == 'rtl' ? 'left' : 'right').'; margin-top:0px;padding:5px;" ';
  715. if ($image_size['width'] > 300) {
  716. //limit display width to 300px
  717. $img_attributes .= 'width="300" ';
  718. }
  719. // get the path,width and height from original picture
  720. $big_image = $image_dir.'big_'.$image;
  721. $big_image_size = api_getimagesize($big_image);
  722. $big_image_width = $big_image_size['width'];
  723. $big_image_height = $big_image_size['height'];
  724. $url_big_image = $big_image.'?rnd='.time();
  725. if (api_get_setting('allow_social_tool') == 'true') {
  726. echo '<div id="social-content">';
  727. echo '<div id="social-content-left">';
  728. SocialManager::show_social_menu('home', null, $user_id, $show_full_profile);
  729. echo '</div>';
  730. echo '<div id="social-content-right">';
  731. echo '<table><tr><td>';
  732. //Useless link
  733. /*
  734. echo '<div id="social-content-online">';
  735. if (api_get_setting('extended_profile') == 'true') {
  736. $show = isset($_GET['show']) ? '&amp;show='.Security::remove_XSS($_GET['show']) : '';
  737. if (isset($_GET['type']) && $_GET['type'] == 'reduced') {
  738. echo '<a href="profile.php?type=extended '.$show.'"><span class="social-menu-text1">'.Display::return_icon('edit.png', get_lang('EditExtendProfile'),'',16).'&nbsp;'.get_lang('EditExtendProfile').'</span></a>';
  739. } else {
  740. echo '<a href="profile.php?type=reduced'.$show.'"><span class="social-menu-text1">'.Display::return_icon('edit.png', get_lang('EditNormalProfile'),'',16).'&nbsp;'.get_lang('EditNormalProfile').'</span></a>';
  741. }
  742. }
  743. echo '</div>';*/
  744. $form->display();
  745. echo '</td></tr></table>';
  746. echo '</div>';
  747. } else {
  748. // Style position:absolute has been removed for Opera-compatibility.
  749. //echo '<div id="image-message-container" style="float:right;display:inline;position:absolute;padding:3px;width:250px;" >';
  750. echo '<div id="image-message-container" style="float:right;display:inline;padding:3px;width:230px;" >';
  751. if ($image == 'unknown.jpg') {
  752. echo '<img '.$img_attributes.' />';
  753. } else {
  754. echo '<input type="image" '.$img_attributes.' onclick="javascript: return show_image(\''.$url_big_image.'\',\''.$big_image_width.'\',\''.$big_image_height.'\');"/>';
  755. }
  756. echo '</div>';
  757. $form->display();
  758. }
  759. Display :: display_footer();