profile.php 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859
  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: "../auth/generate_api_key.inc.php",
  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. }
  388. }
  389. // the $jquery_ready_content variable collects all functions that will be load in the $(document).ready javascript function
  390. $htmlHeadXtra[] ='<script type="text/javascript">
  391. $(document).ready(function(){
  392. '.$jquery_ready_content.'
  393. });
  394. </script>';
  395. if (api_get_setting('profile', 'apikeys') == 'true') {
  396. $form->addElement('html', '<div id="div_api_key">');
  397. $form->addElement('text', 'api_key_generate', get_lang('MyApiKey'), array('size' => 40, 'id' => 'id_api_key_generate'));
  398. $form->addElement('html', '</div>');
  399. $form->addElement('button', 'generate_api_key', get_lang('GenerateApiKey'), array('id' => 'id_generate_api_key', 'onclick' => 'generate_open_id_form()')); //generate_open_id_form()
  400. }
  401. // SUBMIT
  402. if (is_profile_editable()) {
  403. $form->addElement('style_submit_button', 'apply_change', get_lang('SaveSettings'), 'class="save"');
  404. } else {
  405. $form->freeze();
  406. }
  407. $user_data = array_merge($user_data, $extra_data);
  408. $form->setDefaults($user_data);
  409. /*
  410. ==============================================================================
  411. FUNCTIONS
  412. ==============================================================================
  413. */
  414. /*
  415. -----------------------------------------------------------
  416. LOGIC FUNCTIONS
  417. -----------------------------------------------------------
  418. */
  419. /**
  420. * Can a user edit his/her profile?
  421. *
  422. * @return boolean Editability of the profile
  423. */
  424. function is_profile_editable() {
  425. return $GLOBALS['profileIsEditable'];
  426. }
  427. /*
  428. -----------------------------------------------------------
  429. PRODUCTIONS FUNCTIONS
  430. -----------------------------------------------------------
  431. */
  432. /**
  433. * Upload a submitted user production.
  434. *
  435. * @param $user_id User id
  436. * @return The filename of the new production or FALSE if the upload has failed
  437. */
  438. function upload_user_production($user_id) {
  439. $image_path = UserManager::get_user_picture_path_by_id($user_id, 'system', true);
  440. $production_repository = $image_path['dir'].$user_id.'/';
  441. if (!file_exists($production_repository)) {
  442. $perm = api_get_setting('permissions_for_new_directories');
  443. $perm = octdec(!empty($perm) ? $perm : '0770');
  444. @mkdir($production_repository, $perm, 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, __FILE__, __LINE__);
  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, __FILE__, __LINE__);
  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. }
  501. elseif (!empty($_SESSION['is_not_password'])) {
  502. $msg_is_not_password = ($_SESSION['is_not_password'] == 'success');
  503. unset($_SESSION['is_not_password']);
  504. }
  505. elseif (!empty($_SESSION['profile_update'])) {
  506. $update_success = ($_SESSION['profile_update'] == 'success');
  507. unset($_SESSION['profile_update']);
  508. }
  509. elseif (!empty($_SESSION['image_uploaded'])) {
  510. $upload_picture_success = ($_SESSION['image_uploaded'] == 'success');
  511. unset($_SESSION['image_uploaded']);
  512. }
  513. elseif (!empty($_SESSION['production_uploaded'])) {
  514. $upload_production_success = ($_SESSION['production_uploaded'] == 'success');
  515. unset($_SESSION['production_uploaded']);
  516. }
  517. elseif (isset($_POST['remove_production'])) {
  518. foreach (array_keys($_POST['remove_production']) as $production) {
  519. UserManager::remove_user_production($_user['user_id'], urldecode($production));
  520. }
  521. if ($production_list = UserManager::build_production_list($_user['user_id'], true, true)) {
  522. $form->insertElementBefore($form->createElement('static', null, null, $production_list), 'productions_list');
  523. }
  524. $form->removeElement('productions_list');
  525. $file_deleted = true;
  526. } elseif ($form->validate()) {
  527. $wrong_current_password = false;
  528. // $user_data = $form->exportValues();
  529. $user_data = $form->getSubmitValues();
  530. // set password if a new one was provided
  531. if (!empty($user_data['password0'])) {
  532. if (check_user_password($user_data['password0'])) {
  533. if (!empty($user_data['password1'])) {
  534. $password = $user_data['password1'];
  535. }
  536. } else {
  537. $wrong_current_password = true;
  538. $_SESSION['is_not_password'] = 'success';
  539. }
  540. }
  541. if (empty($user_data['password0']) && !empty($user_data['password1'])) {
  542. $wrong_current_password = true;
  543. $_SESSION['is_not_password'] = 'success';
  544. }
  545. if (!check_user_email($user_data['email']) && !empty($user_data['password0']) && ($wrong_current_password==false)) {
  546. $changeemail = $user_data['email'];
  547. }
  548. if (!check_user_email($user_data['email']) && empty($user_data['password0'])){
  549. $_SESSION['change_email'] = 'success';
  550. }
  551. // upload picture if a new one is provided
  552. if ($_FILES['picture']['size']) {
  553. if ($new_picture = UserManager::update_user_picture($_user['user_id'], $_FILES['picture']['name'], $_FILES['picture']['tmp_name'])) {
  554. $user_data['picture_uri'] = $new_picture;
  555. $_SESSION['image_uploaded'] = 'success';
  556. }
  557. }
  558. // remove existing picture if asked
  559. elseif (!empty($user_data['remove_picture'])) {
  560. UserManager::delete_user_picture($_user['user_id']);
  561. $user_data['picture_uri'] = '';
  562. }
  563. // upload production if a new one is provided
  564. if ($_FILES['production']['size']) {
  565. $res = upload_user_production($_user['user_id']);
  566. if (!$res) {
  567. //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
  568. $filtered_extension = true;
  569. } else {
  570. $_SESSION['production_uploaded'] = 'success';
  571. }
  572. }
  573. // remove values that shouldn't go in the database
  574. unset($user_data['password0'],$user_data['password1'], $user_data['password2'], $user_data['MAX_FILE_SIZE'],
  575. $user_data['remove_picture'], $user_data['apply_change'],$user_data['email'] );
  576. // Following RFC2396 (http://www.faqs.org/rfcs/rfc2396.html), a URI uses ':' as a reserved character
  577. // we can thus ensure the URL doesn't contain any scheme name by searching for ':' in the string
  578. $my_user_openid = isset($user_data['openid']) ? $user_data['openid'] : '';
  579. if (!preg_match('/^[^:]*:\/\/.*$/', $my_user_openid)) {
  580. //ensure there is at least a http:// scheme in the URI provided
  581. $user_data['openid'] = 'http://'.$my_user_openid;
  582. }
  583. $extras = array();
  584. // build SQL query
  585. $sql = "UPDATE $table_user SET";
  586. unset($user_data['api_key_generate']);
  587. foreach ($user_data as $key => $value) {
  588. if (substr($key, 0, 6) == 'extra_') { //an extra field
  589. $new_key = substr($key, 6);
  590. // format array date to 'Y-m-d' or date time to 'Y-m-d H:i:s'
  591. if (is_array($value) && isset($value['Y']) && isset($value['F']) && isset($value['d'])) {
  592. if (isset($value['H']) && isset($value['i'])) {
  593. // extra field date time
  594. $time = mktime($value['H'],$value['i'],0,$value['F'],$value['d'],$value['Y']);
  595. $extras[$new_key] = date('Y-m-d H:i:s',$time);
  596. } else {
  597. // extra field date
  598. $time = mktime(0,0,0,$value['F'],$value['d'],$value['Y']);
  599. $extras[$new_key] = date('Y-m-d',$time);
  600. }
  601. } else {
  602. $extras[$new_key] = $value;
  603. }
  604. } else {
  605. $sql .= " $key = '".Database::escape_string($value)."',";
  606. }
  607. }
  608. //changue email
  609. if (isset($changeemail) && !isset($password) ) {
  610. $sql .= " email = '".Database::escape_string($changeemail)."' ";
  611. } elseif (isset($password) && isset($changeemail)) {
  612. $sql .= " email = '".Database::escape_string($changeemail)."', ";
  613. $password = api_get_encrypted_password($password);
  614. $sql .= " password = '".Database::escape_string($password)."'";
  615. } elseif (isset($password) && !isset($changeemail)) {
  616. $password = api_get_encrypted_password($password);
  617. $sql .= " password = '".Database::escape_string($password)."'";
  618. } else {
  619. // remove trailing , from the query we have so far
  620. $sql = rtrim($sql, ',');
  621. }
  622. $sql .= " WHERE user_id = '".$_user['user_id']."'";
  623. //var_dump($sql); exit();
  624. Database::query($sql, __FILE__, __LINE__);
  625. // User tag process
  626. //1. Deleting all user tags
  627. $list_extra_field_type_tag = UserManager::get_all_extra_field_by_type(USER_FIELD_TYPE_TAG);
  628. if (is_array($list_extra_field_type_tag) && count($list_extra_field_type_tag)>0) {
  629. foreach ($list_extra_field_type_tag as $id) {
  630. UserManager::delete_user_tags(api_get_user_id(), $id);
  631. }
  632. }
  633. //2. Update the extra fields and user tags if available
  634. if (is_array($extras) && count($extras)> 0) {
  635. foreach ($extras as $key => $value) {
  636. //3. Tags are process in the UserManager::update_extra_field_value by the UserManager::process_tags function
  637. $myres = UserManager::update_extra_field_value($_user['user_id'], $key, $value);
  638. }
  639. }
  640. // re-init the system to take new settings into account
  641. $uidReset = true;
  642. include api_get_path(INCLUDE_PATH).'local.inc.php';
  643. $_SESSION['profile_update'] = 'success';
  644. header("Location: ".api_get_self()."?{$_SERVER['QUERY_STRING']}".($filtered_extension && strpos($_SERVER['QUERY_STRING'], '&fe=1') === false ? '&fe=1' : ''));
  645. exit;
  646. }
  647. if (isset($_GET['show'])) {
  648. if ((api_get_setting('allow_social_tool') == 'true' && api_get_setting('allow_message_tool') == 'true') || (api_get_setting('allow_social_tool') == 'true')) {
  649. //$interbreadcrumb[] = array ('url' => 'javascript: void(0);', 'name' => get_lang('SocialNetwork'));
  650. } elseif ((api_get_setting('allow_social_tool') == 'false' && api_get_setting('allow_message_tool') == 'true')) {
  651. //$interbreadcrumb[] = array('url' => 'javascript: void(0);', 'name' => get_lang('MessageTool'));
  652. }
  653. }
  654. /*
  655. ==============================================================================
  656. MAIN DISPLAY SECTION
  657. ==============================================================================
  658. */
  659. // the header
  660. Display::display_header(get_lang('ModifyProfile'));
  661. if (api_get_setting('allow_social_tool') != 'true') {
  662. if (api_get_setting('extended_profile') == 'true') {
  663. echo '<div class="actions">';
  664. if (api_get_setting('allow_social_tool') == 'true' && api_get_setting('allow_message_tool') == 'true') {
  665. 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>';
  666. }
  667. if (api_get_setting('allow_message_tool') == 'true') {
  668. echo '<a href="'.api_get_path(WEB_PATH).'main/messages/inbox.php">'.Display::return_icon('inbox.png').' '.get_lang('Messages').'</a>';
  669. }
  670. $show = isset($_GET['show']) ? '&amp;show='.Security::remove_XSS($_GET['show']) : '';
  671. if (isset($_GET['type']) && $_GET['type'] == 'extended') {
  672. echo '<a href="profile.php?type=reduced'.$show.'">'.Display::return_icon('edit.gif', get_lang('EditNormalProfile')).'&nbsp;'.get_lang('EditNormalProfile').'</a>';
  673. } else {
  674. echo '<a href="profile.php?type=extended'.$show.'">'.Display::return_icon('edit.gif', get_lang('EditExtendProfile')).'&nbsp;'.get_lang('EditExtendProfile').'</a>';
  675. }
  676. echo '</div>';
  677. }
  678. }
  679. if (!empty($file_deleted)) {
  680. Display :: display_confirmation_message(get_lang('FileDeleted'), false);
  681. } elseif (!empty($update_success)) {
  682. $message = get_lang('ProfileReg');
  683. if ($upload_picture_success) {
  684. $message .= '<br /> '.get_lang('PictureUploaded');
  685. }
  686. if ($upload_production_success) {
  687. $message.='<br />'.get_lang('ProductionUploaded');
  688. }
  689. Display :: display_confirmation_message($message, false);
  690. }
  691. if (!empty($msg_fail_changue_email)){
  692. $errormail=get_lang('ToChangeYourEmailMustTypeYourPassword');
  693. Display :: display_error_message($errormail, false);
  694. }
  695. if (!empty($msg_is_not_password)){
  696. $warning_msg = get_lang('CurrentPasswordEmptyOrIncorrect');
  697. Display :: display_warning_message($warning_msg, false);
  698. }
  699. //User picture size is calculated from SYSTEM path
  700. $image_syspath = UserManager::get_user_picture_path_by_id(api_get_user_id(), 'system', false, true);
  701. $image_syspath['dir'].$image_syspath['file'];
  702. $image_size = @getimagesize($image_syspath['dir'].$image_syspath['file']);
  703. //Web path
  704. $image_path = UserManager::get_user_picture_path_by_id(api_get_user_id(), 'web', false, true);
  705. $image_dir = $image_path['dir'];
  706. $image = $image_path['file'];
  707. $image_file = $image_dir.$image;
  708. $img_attributes = 'src="'.$image_file.'?rand='.time().'" '
  709. .'alt="'.api_get_person_name($user_data['firstname'], $user_data['lastname']).'" '
  710. .'style="float:'.($text_dir == 'rtl' ? 'left' : 'right').'; margin-top:0px;padding:5px;" ';
  711. if ($image_size[0] > 300) {
  712. //limit display width to 300px
  713. $img_attributes .= 'width="300" ';
  714. }
  715. // get the path,width and height from original picture
  716. $big_image = $image_dir.'big_'.$image;
  717. $big_image_size = api_getimagesize($big_image);
  718. $big_image_width = $big_image_size[0];
  719. $big_image_height = $big_image_size[1];
  720. $url_big_image = $big_image.'?rnd='.time();
  721. if (api_get_setting('allow_social_tool') == 'true') {
  722. echo '<div id="social-content">';
  723. echo '<div id="social-content-left">';
  724. SocialManager::show_social_menu('home', null, $user_id, $show_full_profile);
  725. echo '</div>';
  726. echo '<div id="social-content-right">';
  727. echo '<div id="social-content-online">';
  728. if (api_get_setting('extended_profile') == 'true') {
  729. $show = isset($_GET['show']) ? '&amp;show='.Security::remove_XSS($_GET['show']) : '';
  730. if (isset($_GET['type']) && $_GET['type'] == 'extended') {
  731. 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>';
  732. } else {
  733. 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>';
  734. }
  735. }
  736. echo '</div>';
  737. $form->display();
  738. echo '</div>';
  739. echo '</div>';
  740. } else {
  741. // Style position:absolute has been removed for Opera-compatibility.
  742. //echo '<div id="image-message-container" style="float:right;display:inline;position:absolute;padding:3px;width:250px;" >';
  743. echo '<div id="image-message-container" style="float:right;display:inline;padding:3px;width:230px;" >';
  744. if ($image == 'unknown.jpg') {
  745. echo '<img '.$img_attributes.' />';
  746. } else {
  747. echo '<input type="image" '.$img_attributes.' onclick="javascript: return show_image(\''.$url_big_image.'\',\''.$big_image_width.'\',\''.$big_image_height.'\');"/>';
  748. }
  749. echo '</div>';
  750. $form->display();
  751. }
  752. Display :: display_footer();