profile.php 33 KB

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