profile.php 35 KB

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