profile.php 33 KB

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