profile.php 34 KB

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