profile.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799
  1. <?php // $Id: profile.php 18203 2009-02-03 18:02:16Z ndieschburg $
  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. // name of the language file that needs to be included
  17. $language_file = array('registration','messages');
  18. $cidReset = true;
  19. require ('../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. api_block_anonymous_users();
  24. $htmlHeadXtra[] = '<script type="text/javascript">
  25. function confirmation(name)
  26. {
  27. if (confirm("'.get_lang('AreYouSureToDelete').' " + name + " ?"))
  28. {return true;}
  29. else
  30. {return false;}
  31. }
  32. function show_image(image,width,height) {
  33. width = parseInt(width) + 20;
  34. height = parseInt(height) + 20;
  35. window_x = window.open(image,\'windowX\',\'width=\'+ width + \', height=\'+ height + \'\');
  36. }
  37. </script>';
  38. if (api_get_setting('allow_message_tool')=='true') {
  39. $htmlHeadXtra[] = '<script src="../inc/lib/javascript/jquery.js" type="text/javascript" language="javascript"></script>'; //jQuery
  40. $htmlHeadXtra[] ='<script type="text/javascript">
  41. $(document).ready(function(){
  42. $(".message-content .message-delete").click(function(){
  43. $(this).parents(".message-content").animate({ opacity: "hide" }, "slow");
  44. $(".message-view").animate({ opacity: "show" }, "slow");
  45. });
  46. //$("message-content-internal").load("../messages/index.php");
  47. //$("message-content-internal").show();
  48. });
  49. </script>';
  50. }
  51. if (!empty ($_GET['coursePath']))
  52. {
  53. $course_url = api_get_path(WEB_COURSE_PATH).htmlentities(strip_tags($_GET['coursePath'])).'/index.php';
  54. $interbreadcrumb[] = array ('url' => $course_url, 'name' => Security::remove_XSS($_GET['courseCode']));
  55. }
  56. $warning_msg = '';
  57. if(!empty($_GET['fe']))
  58. {
  59. $warning_msg .= get_lang('UplUnableToSaveFileFilteredExtension');
  60. $_GET['fe'] = null;
  61. }
  62. /*
  63. -----------------------------------------------------------
  64. Configuration file
  65. -----------------------------------------------------------
  66. */
  67. require_once (api_get_path(CONFIGURATION_PATH).'profile.conf.php');
  68. /*
  69. -----------------------------------------------------------
  70. Libraries
  71. -----------------------------------------------------------
  72. */
  73. include_once (api_get_path(LIBRARY_PATH).'fileManage.lib.php');
  74. include_once (api_get_path(LIBRARY_PATH).'fileUpload.lib.php');
  75. include_once (api_get_path(LIBRARY_PATH).'image.lib.php');
  76. require_once (api_get_path(LIBRARY_PATH).'usermanager.lib.php');
  77. if (is_profile_editable())
  78. $tool_name = get_lang('ModifProfile');
  79. else
  80. $tool_name = get_lang('ViewProfile');
  81. $table_user = Database :: get_main_table(TABLE_MAIN_USER);
  82. /*
  83. -----------------------------------------------------------
  84. Form
  85. -----------------------------------------------------------
  86. */
  87. /*
  88. * Get initial values for all fields.
  89. */
  90. $user_data = UserManager::get_user_info_by_id(api_get_user_id());
  91. if ($user_data !== false)
  92. {
  93. if (is_null($user_data['language']))
  94. $user_data['language'] = api_get_setting('platformLanguage');
  95. }
  96. $user_image = UserManager::get_user_picture_path_by_id(api_get_user_id(),'none');
  97. $fck_attribute['Height'] = "150";
  98. $fck_attribute['Width'] = "100%";
  99. $fck_attribute['ToolbarSet'] = "Profil";
  100. /*
  101. * Initialize the form.
  102. */
  103. $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;')));
  104. /* Make sure this is the first submit on the form, even though it is hidden!
  105. * Otherwise, if a user has productions and presses ENTER to submit, he will
  106. * attempt to delete the first production in the list. */
  107. //if (is_profile_editable())
  108. // $form->addElement('style_submit_button', null, get_lang('SaveSettings'), 'class="save"', array('style' => 'visibility:hidden;'));
  109. // SUBMIT (visible)
  110. /*if (is_profile_editable())
  111. {
  112. $form->addElement('style_submit_button', 'apply_change', get_lang('SaveSettings'), 'class="save"');
  113. }
  114. else
  115. {
  116. $form->freeze();
  117. }*/
  118. //THEME
  119. if (is_profile_editable() && api_get_setting('user_selected_theme') == 'true')
  120. {
  121. $form->addElement('select_theme', get_lang('Theme'),'theme');
  122. if (api_get_setting('profile', 'theme') !== 'true')
  123. $form->freeze('theme');
  124. $form->applyFilter('theme', 'trim');
  125. //if (api_get_setting('registration', 'openid') == 'true')
  126. // $form->addRule('openid', get_lang('ThisFieldIsRequired'), 'required');
  127. }
  128. // LAST NAME and FIRST NAME
  129. $form->addElement('text', 'lastname', get_lang('LastName'), array('size' => 40));
  130. $form->addElement('text', 'firstname', get_lang('FirstName'), array('size' => 40));
  131. if (api_get_setting('profile', 'name') !== 'true')
  132. $form->freeze(array('lastname', 'firstname'));
  133. $form->applyFilter(array('lastname', 'firstname'), 'stripslashes');
  134. $form->applyFilter(array('lastname', 'firstname'), 'trim');
  135. $form->addRule('lastname' , get_lang('ThisFieldIsRequired'), 'required');
  136. $form->addRule('firstname', get_lang('ThisFieldIsRequired'), 'required');
  137. // USERNAME
  138. $form->addElement('text', 'username', get_lang('UserName'), array('size' => 40));
  139. if (api_get_setting('profile', 'login') !== 'true')
  140. $form->freeze('username');
  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. {
  149. $form->addElement('text', 'official_code', get_lang('OfficialCode'), array('size' => 40));
  150. if (api_get_setting('profile', 'officialcode') !== 'true')
  151. $form->freeze('official_code');
  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. // EMAIL
  158. $form->addElement('text', 'email', get_lang('Email'), array('size' => 40));
  159. if (api_get_setting('profile', 'email') !== 'true')
  160. $form->freeze('email');
  161. $form->applyFilter('email', 'stripslashes');
  162. $form->applyFilter('email', 'trim');
  163. if (api_get_setting('registration', 'email') == 'true')
  164. $form->addRule('email', get_lang('ThisFieldIsRequired'), 'required');
  165. $form->addRule('email', get_lang('EmailWrong'), 'email');
  166. // OPENID URL
  167. if(is_profile_editable() && api_get_setting('openid_authentication')=='true')
  168. {
  169. $form->addElement('text', 'openid', get_lang('OpenIDURL'), array('size' => 40));
  170. if (api_get_setting('profile', 'openid') !== 'true')
  171. $form->freeze('openid');
  172. $form->applyFilter('openid', 'trim');
  173. //if (api_get_setting('registration', 'openid') == 'true')
  174. // $form->addRule('openid', get_lang('ThisFieldIsRequired'), 'required');
  175. }
  176. // PHONE
  177. $form->addElement('text', 'phone', get_lang('phone'), array('size' => 20));
  178. if (api_get_setting('profile', 'phone') !== 'true')
  179. $form->freeze('phone');
  180. $form->applyFilter('phone', 'stripslashes');
  181. $form->applyFilter('phone', 'trim');
  182. /*if (api_get_setting('registration', 'phone') == 'true')
  183. $form->addRule('phone', get_lang('ThisFieldIsRequired'), 'required');
  184. $form->addRule('phone', get_lang('EmailWrong'), 'email');*/
  185. // PICTURE
  186. if (is_profile_editable() && api_get_setting('profile', 'picture') == 'true')
  187. {
  188. $form->addElement('file', 'picture', ($user_image != '' ? get_lang('UpdateImage') : get_lang('AddImage')));
  189. $form->add_progress_bar();
  190. if( strlen($user_data['picture_uri']) > 0)
  191. {
  192. $form->addElement('checkbox', 'remove_picture', null, get_lang('DelImage'));
  193. }
  194. $form->addRule('picture', get_lang('OnlyImagesAllowed'), 'mimetype', array('image/gif', 'image/jpeg', 'image/png','image/pjpeg'));
  195. }
  196. // LANGUAGE
  197. $form->addElement('select_language', 'language', get_lang('Language'));
  198. if (api_get_setting('profile', 'language') !== 'true')
  199. $form->freeze('language');
  200. // EXTENDED PROFILE
  201. if (api_get_setting('extended_profile') == 'true')
  202. {
  203. $form->addElement('static', null, '<em>'.get_lang('OptionalTextFields').'</em>');
  204. // MY COMPETENCES
  205. $form->add_html_editor('competences', get_lang('MyCompetences'), false);
  206. // MY DIPLOMAS
  207. $form->add_html_editor('diplomas', get_lang('MyDiplomas'), false);
  208. // WHAT I AM ABLE TO TEACH
  209. $form->add_html_editor('teach', get_lang('MyTeach'), false);
  210. // MY PRODUCTIONS
  211. $form->addElement('file', 'production', get_lang('MyProductions'));
  212. if ($production_list = UserManager::build_production_list($_user['user_id'],'',true))
  213. {
  214. $form->addElement('static', 'productions_list', null, $production_list);
  215. }
  216. // MY PERSONAL OPEN AREA
  217. $form->add_html_editor('openarea', get_lang('MyPersonalOpenArea'), false);
  218. $form->applyFilter(array('competences', 'diplomas', 'teach', 'openarea'), 'stripslashes');
  219. $form->applyFilter(array('competences', 'diplomas', 'teach'), 'trim'); // openarea is untrimmed for maximum openness
  220. }
  221. // PASSWORD
  222. if (is_profile_editable() && api_get_setting('profile', 'password') == 'true')
  223. {
  224. $form->addElement('static', null, null, '<em>'.get_lang('Enter2passToChange').'</em>');
  225. $form->addElement('password', 'password1', get_lang('Pass'), array('size' => 40));
  226. $form->addElement('password', 'password2', get_lang('Confirmation'), array('size' => 40));
  227. // user must enter identical password twice so we can prevent some user errors
  228. $form->addRule(array('password1', 'password2'), get_lang('PassTwo'), 'compare');
  229. if (CHECK_PASS_EASY_TO_FIND)
  230. $form->addRule('password1', get_lang('PassTooEasy').': '.api_generate_password(), 'callback', 'api_check_password');
  231. }
  232. // EXTRA FIELDS
  233. $extra = UserManager::get_extra_fields(0,50,5,'ASC');
  234. $extra_data = UserManager::get_extra_user_data(api_get_user_id(),true);
  235. foreach($extra as $id => $field_details)
  236. {
  237. if($field_details[6] == 0)
  238. {
  239. continue;
  240. }
  241. switch($field_details[2])
  242. {
  243. case USER_FIELD_TYPE_TEXT:
  244. $form->addElement('text', 'extra_'.$field_details[1], $field_details[3], array('size' => 40));
  245. $form->applyFilter('extra_'.$field_details[1], 'stripslashes');
  246. $form->applyFilter('extra_'.$field_details[1], 'trim');
  247. if ($field_details[7] == 0) $form->freeze('extra_'.$field_details[1]);
  248. break;
  249. case USER_FIELD_TYPE_TEXTAREA:
  250. $form->add_html_editor('extra_'.$field_details[1], $field_details[3], false);
  251. //$form->addElement('textarea', 'extra_'.$field_details[1], $field_details[3], array('size' => 80));
  252. $form->applyFilter('extra_'.$field_details[1], 'stripslashes');
  253. $form->applyFilter('extra_'.$field_details[1], 'trim');
  254. if ($field_details[7] == 0) $form->freeze('extra_'.$field_details[1]);
  255. break;
  256. case USER_FIELD_TYPE_RADIO:
  257. $group = array();
  258. foreach($field_details[8] as $option_id => $option_details)
  259. {
  260. $options[$option_details[1]] = $option_details[2];
  261. $group[] =& HTML_QuickForm::createElement('radio', 'extra_'.$field_details[1], $option_details[1],$option_details[2].'<br />',$option_details[1]);
  262. }
  263. $form->addGroup($group, 'extra_'.$field_details[1], $field_details[3], '');
  264. if ($field_details[7] == 0) $form->freeze('extra_'.$field_details[1]);
  265. break;
  266. case USER_FIELD_TYPE_SELECT:
  267. $options = array();
  268. foreach($field_details[8] as $option_id => $option_details)
  269. {
  270. $options[$option_details[1]] = $option_details[2];
  271. }
  272. $form->addElement('select','extra_'.$field_details[1],$field_details[3],$options,'');
  273. if ($field_details[7] == 0) $form->freeze('extra_'.$field_details[1]);
  274. break;
  275. case USER_FIELD_TYPE_SELECT_MULTIPLE:
  276. $options = array();
  277. foreach($field_details[8] as $option_id => $option_details)
  278. {
  279. $options[$option_details[1]] = $option_details[2];
  280. }
  281. $form->addElement('select','extra_'.$field_details[1],$field_details[3],$options,array('multiple' => 'multiple'));
  282. if ($field_details[7] == 0) $form->freeze('extra_'.$field_details[1]);
  283. break;
  284. case USER_FIELD_TYPE_DATE:
  285. $form->addElement('datepickerdate', 'extra_'.$field_details[1],$field_details[3], array('form_name'=>'profile'));
  286. $form->_elements[$form->_elementIndex['extra_'.$field_details[1]]]->setLocalOption('minYear',1900);
  287. if ($field_details[7] == 0) $form->freeze('extra_'.$field_details[1]);
  288. $form->applyFilter('theme', 'trim');
  289. $defaults['extra_'.$field_details[1]] = date('Y-m-d 12:00:00');
  290. $form -> setDefaults($defaults);
  291. break;
  292. case USER_FIELD_TYPE_DATETIME:
  293. $form->addElement('datepicker', 'extra_'.$field_details[1],$field_details[3], array('form_name'=>'profile'));
  294. $form->_elements[$form->_elementIndex['extra_'.$field_details[1]]]->setLocalOption('minYear',1900);
  295. if ($field_details[7] == 0) $form->freeze('extra_'.$field_details[1]);
  296. $form->applyFilter('theme', 'trim');
  297. $defaults['extra_'.$field_details[1]] = date('Y-m-d 12:00:00');
  298. $form -> setDefaults($defaults);
  299. break;
  300. case USER_FIELD_TYPE_DOUBLE_SELECT:
  301. foreach ($field_details[8] as $key=>$element)
  302. {
  303. if ($element[2][0] == '*')
  304. {
  305. $values['*'][$element[0]] = str_replace('*','',$element[2]);
  306. }
  307. else
  308. {
  309. $values[0][$element[0]] = $element[2];
  310. }
  311. }
  312. $group='';
  313. $group[] =& HTML_QuickForm::createElement('select', 'extra_'.$field_details[1],'',$values[0],'');
  314. $group[] =& HTML_QuickForm::createElement('select', 'extra_'.$field_details[1].'*','',$values['*'],'');
  315. $form->addGroup($group, 'extra_'.$field_details[1], $field_details[3], '&nbsp;');
  316. if ($field_details[7] == 0) $form->freeze('extra_'.$field_details[1]);
  317. // recoding the selected values for double : if the user has selected certain values, we have to assign them to the correct select form
  318. if (key_exists('extra_'.$field_details[1], $extra_data))
  319. {
  320. // exploding all the selected values (of both select forms)
  321. $selected_values = explode(';',$extra_data['extra_'.$field_details[1]]);
  322. $extra_data['extra_'.$field_details[1]] =array();
  323. // looping through the selected values and assigning the selected values to either the first or second select form
  324. foreach ($selected_values as $key=>$selected_value)
  325. {
  326. if (key_exists($selected_value,$values[0]))
  327. {
  328. $extra_data['extra_'.$field_details[1]]['extra_'.$field_details[1]] = $selected_value;
  329. }
  330. else
  331. {
  332. $extra_data['extra_'.$field_details[1]]['extra_'.$field_details[1].'*'] = $selected_value;
  333. }
  334. }
  335. }
  336. break;
  337. case USER_FIELD_TYPE_DIVIDER:
  338. $form->addElement('static',$field_details[1], '<br /><strong>'.$field_details[3].'</strong>');
  339. break;
  340. }
  341. }
  342. // SUBMIT
  343. if (is_profile_editable())
  344. {
  345. $form->addElement('style_submit_button', 'apply_change', get_lang('SaveSettings'), 'class="save"');
  346. }
  347. else
  348. {
  349. $form->freeze();
  350. }
  351. $user_data = array_merge($user_data,$extra_data);
  352. $form->setDefaults($user_data);
  353. /*
  354. ==============================================================================
  355. FUNCTIONS
  356. ==============================================================================
  357. */
  358. /*
  359. -----------------------------------------------------------
  360. LOGIC FUNCTIONS
  361. -----------------------------------------------------------
  362. */
  363. /**
  364. * Can a user edit his/her profile?
  365. *
  366. * @return boolean Editability of the profile
  367. */
  368. function is_profile_editable()
  369. {
  370. return $GLOBALS['profileIsEditable'];
  371. }
  372. /*
  373. -----------------------------------------------------------
  374. USER IMAGE FUNCTIONS
  375. -----------------------------------------------------------
  376. */
  377. /**
  378. * Upload a submitted user image.
  379. *
  380. * @param $user_id User id
  381. * @return The filename of the new picture or FALSE if the upload has failed
  382. */
  383. function upload_user_image($user_id)
  384. {
  385. /* Originally added by Miguel (miguel@cesga.es) - 2003-11-04
  386. * Code Refactoring by Hugues Peeters (hugues.peeters@claroline.net) - 2003-11-24
  387. * Moved inside a function and refactored by Thomas Corthals - 2005-11-04
  388. */
  389. $image_path = UserManager::get_user_picture_path_by_id($user_id,'system',true);
  390. $image_repository = $image_path['dir'];
  391. $existing_image = $image_path['file'];
  392. $file_extension = explode('.', $_FILES['picture']['name']);
  393. $file_extension = strtolower($file_extension[count($file_extension) - 1]);
  394. if (!file_exists($image_repository)) {
  395. mkpath($image_repository);
  396. }
  397. if ($existing_image != '') {
  398. if (KEEP_THE_NAME_WHEN_CHANGE_IMAGE) {
  399. $picture_filename = $existing_image;
  400. $old_picture_filename = 'saved_'.date('Y_m_d_H_i_s').'_'.uniqid('').'_'.$existing_image;
  401. } else {
  402. $old_picture_filename = $existing_image;
  403. $picture_filename = (PREFIX_IMAGE_FILENAME_WITH_UID ? 'u'.$user_id.'_' : '').uniqid('').'.'.$file_extension;
  404. }
  405. if (KEEP_THE_OLD_IMAGE_AFTER_CHANGE) {
  406. @rename($image_repository.$existing_image, $image_repository.$old_picture_filename);
  407. } else {
  408. @unlink($image_repository.$existing_image);
  409. }
  410. } else {
  411. $picture_filename = (PREFIX_IMAGE_FILENAME_WITH_UID ? $user_id.'_' : '').uniqid('').'.'.$file_extension;
  412. }
  413. // get the picture and resize it 200x200
  414. $temp = new image($_FILES['picture']['tmp_name']);
  415. $picture_infos=getimagesize($_FILES['picture']['tmp_name']);
  416. $thumbwidth = 200;
  417. if (empty($thumbwidth) or $thumbwidth==0) {
  418. $thumbwidth=200;
  419. }
  420. $new_height = round(($thumbwidth/$picture_infos[0])*$picture_infos[1]);
  421. $temp->resize($thumbwidth,$new_height,0);
  422. $type=$picture_infos[2];
  423. // original picture
  424. $big_temp = new image($_FILES['picture']['tmp_name']);
  425. switch (!empty($type)) {
  426. case 2 : $temp->send_image('JPG',$image_repository.$picture_filename);
  427. $big_temp->send_image('JPG',$image_repository.'big_'.$picture_filename);
  428. break;
  429. case 3 : $temp->send_image('PNG',$image_repository.$picture_filename);
  430. $big_temp->send_image('JPG',$image_repository.'big_'.$picture_filename);
  431. break;
  432. case 1 : $temp->send_image('GIF',$image_repository.$picture_filename);
  433. $big_temp->send_image('JPG',$image_repository.'big_'.$picture_filename);
  434. break;
  435. }
  436. return $picture_filename;
  437. }
  438. /**
  439. * Remove an existing user image.
  440. *
  441. * @param $user_id User id
  442. */
  443. function remove_user_image($user_id)
  444. {
  445. $image_path = UserManager::get_user_picture_path_by_id($user_id,'system');
  446. $image_repository = $image_path['dir'];
  447. $image = $image_path['file'];
  448. if ($image != '')
  449. {
  450. if (KEEP_THE_OLD_IMAGE_AFTER_CHANGE)
  451. {
  452. @rename($image_repository.$image, $image_repository.'deleted_'.date('Y_m_d_H_i_s').'_'.$image);
  453. }
  454. else
  455. {
  456. @unlink($image_repository.$image);
  457. }
  458. }
  459. }
  460. /*
  461. -----------------------------------------------------------
  462. PRODUCTIONS FUNCTIONS
  463. -----------------------------------------------------------
  464. */
  465. /**
  466. * Upload a submitted user production.
  467. *
  468. * @param $user_id User id
  469. * @return The filename of the new production or FALSE if the upload has failed
  470. */
  471. function upload_user_production($user_id)
  472. {
  473. $image_path = UserManager::get_user_picture_path_by_id($user_id,'system',true);
  474. $production_repository = $image_path['dir'].$user_id.'/';
  475. if (!file_exists($production_repository))
  476. {
  477. mkpath($production_repository);
  478. }
  479. $filename = replace_dangerous_char($_FILES['production']['name']);
  480. $filename = disable_dangerous_file($filename);
  481. if(filter_extension($filename))
  482. {
  483. if (@move_uploaded_file($_FILES['production']['tmp_name'], $production_repository.$filename))
  484. {
  485. return $filename;
  486. }
  487. }
  488. return false; // this should be returned if anything went wrong with the upload
  489. }
  490. /*
  491. ==============================================================================
  492. MAIN CODE
  493. ==============================================================================
  494. */
  495. $filtered_extension = false;
  496. $update_success = false;
  497. $upload_picture_success = false;
  498. $upload_production_success = false;
  499. if (!empty($_SESSION['profile_update']))
  500. {
  501. $update_success = ($_SESSION['profile_update'] == 'success');
  502. unset($_SESSION['profile_update']);
  503. }
  504. if (!empty($_SESSION['image_uploaded']))
  505. {
  506. $upload_picture_success = ($_SESSION['image_uploaded'] == 'success');
  507. unset($_SESSION['image_uploaded']);
  508. }
  509. if (!empty($_SESSION['production_uploaded']))
  510. {
  511. $upload_production_success = ($_SESSION['production_uploaded'] == 'success');
  512. unset($_SESSION['production_uploaded']);
  513. }
  514. elseif (isset($_POST['remove_production']))
  515. {
  516. foreach (array_keys($_POST['remove_production']) as $production)
  517. {
  518. UserManager::remove_user_production($_user['user_id'], urldecode($production));
  519. }
  520. if ($production_list = UserManager::build_production_list($_user['user_id'], true,true))
  521. $form->insertElementBefore($form->createElement('static', null, null, $production_list), 'productions_list');
  522. $form->removeElement('productions_list');
  523. $file_deleted = true;
  524. }
  525. elseif ($form->validate())
  526. {
  527. $user_data = $form->exportValues();
  528. // set password if a new one was provided
  529. if (!empty($user_data['password1']))
  530. $password = $user_data['password1'];
  531. // upload picture if a new one is provided
  532. if ($_FILES['picture']['size'])
  533. {
  534. if ($new_picture = upload_user_image($_user['user_id']))
  535. {
  536. $user_data['picture_uri'] = $new_picture;
  537. $_SESSION['image_uploaded'] = 'success';
  538. }
  539. }
  540. // remove existing picture if asked
  541. elseif (!empty($user_data['remove_picture']))
  542. {
  543. remove_user_image($_user['user_id']);
  544. $user_data['picture_uri'] = '';
  545. }
  546. // upload production if a new one is provided
  547. if ($_FILES['production']['size'])
  548. {
  549. $res = upload_user_production($_user['user_id']);
  550. if(!$res)
  551. {
  552. //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
  553. $filtered_extension = true;
  554. }
  555. else
  556. {
  557. $_SESSION['production_uploaded'] = 'success';
  558. }
  559. }
  560. // remove values that shouldn't go in the database
  561. unset($user_data['password1'], $user_data['password2'], $user_data['MAX_FILE_SIZE'],
  562. $user_data['remove_picture'], $user_data['apply_change']);
  563. // Following RFC2396 (http://www.faqs.org/rfcs/rfc2396.html), a URI uses ':' as a reserved character
  564. // we can thus ensure the URL doesn't contain any scheme name by searching for ':' in the string
  565. $my_user_openid=isset($user_data['openid']) ? $user_data['openid'] : '';
  566. if(!preg_match('/^[^:]*:\/\/.*$/',$my_user_openid))
  567. { //ensure there is at least a http:// scheme in the URI provided
  568. $user_data['openid'] = 'http://'.$my_user_openid;
  569. }
  570. $extras = array();
  571. // build SQL query
  572. $sql = "UPDATE $table_user SET";
  573. foreach($user_data as $key => $value)
  574. {
  575. if(substr($key,0,6)=='extra_') //an extra field
  576. {
  577. $extras[substr($key,6)] = $value;
  578. }
  579. else
  580. {
  581. $sql .= " $key = '".Database::escape_string($value)."',";
  582. }
  583. }
  584. if (isset($password))
  585. {
  586. if ($userPasswordCrypted)
  587. {
  588. $sql .= " password = MD5('".Database::escape_string($password)."')";
  589. }
  590. else
  591. {
  592. $sql .= " password = '".Database::escape_string($password)."'";
  593. }
  594. }
  595. else // remove trailing , from the query we have so far
  596. {
  597. $sql = rtrim($sql, ',');
  598. }
  599. $sql .= " WHERE user_id = '".$_user['user_id']."'";
  600. api_sql_query($sql, __FILE__, __LINE__);
  601. //update the extra fields
  602. foreach($extras as $key=>$value)
  603. {
  604. $myres = UserManager::update_extra_field_value($_user['user_id'],$key,$value);
  605. }
  606. // re-init the system to take new settings into account
  607. $uidReset = true;
  608. include (api_get_path(INCLUDE_PATH).'local.inc.php');
  609. $_SESSION['profile_update'] = 'success';
  610. header("Location: ".api_get_self()."?{$_SERVER['QUERY_STRING']}".($filtered_extension && strstr($_SERVER['QUERY_STRING'],'&fe=1')===false?'&fe=1':''));
  611. exit;
  612. }
  613. /*
  614. ==============================================================================
  615. MAIN DISPLAY SECTION
  616. ==============================================================================
  617. */
  618. Display :: display_header(get_lang('ModifyProfile'));
  619. if (!empty($file_deleted))
  620. {
  621. Display :: display_confirmation_message(get_lang('FileDeleted'),false);
  622. }
  623. elseif (!empty($update_success))
  624. {
  625. $message=get_lang('ProfileReg');
  626. if ($upload_picture_success == true)
  627. {
  628. $message.='<br /> '.get_lang('PictureUploaded');
  629. }
  630. if ($upload_production_success == true)
  631. {
  632. $message.='<br />'.get_lang('ProductionUploaded');
  633. }
  634. Display :: display_confirmation_message($message,false);
  635. }
  636. if(!empty($warning_msg))
  637. {
  638. Display :: display_warning_message($warning_msg,false);
  639. }
  640. //User picture size is calculated from SYSTEM path
  641. $image_syspath = UserManager::get_user_picture_path_by_id($userid,'system',false,true);
  642. $image_size = getimagesize($image_syspath['dir'].$image_syspath['file']);
  643. //Web path
  644. $image_path = UserManager::get_user_picture_path_by_id($_user['user_id'],'web',false,true);
  645. $image_dir = $image_path['dir'];
  646. $image = $image_path['file'];
  647. $image_file = $image_dir.$image;
  648. $img_attributes = 'src="'.$image_file.'?rand='.time().'" '
  649. .'alt="'.$user_data['lastname'].' '.$user_data['firstname'].'" '
  650. .'style="float:'.($text_dir == 'rtl' ? 'left' : 'right').'; padding:5px;" ';
  651. if ($image_size[0] > 300) {
  652. //limit display width to 300px
  653. $img_attributes .= 'width="300" ';
  654. }
  655. // get the path,width and height from original picture
  656. $big_image = $image_dir.'big_'.$image;
  657. $big_image_size = @getimagesize($big_image);
  658. $big_image_width= $big_image_size[0];
  659. $big_image_height= $big_image_size[1];
  660. $url_big_image = $big_image.'?rnd='.time();
  661. if ($image=='unknown.jpg') {
  662. echo '<img '.$img_attributes.' />';
  663. } else {
  664. echo '<input type="image" '.$img_attributes.' onclick="return show_image(\''.$url_big_image.'\',\''.$big_image_width.'\',\''.$big_image_height.'\');"/>';
  665. }
  666. if (api_get_setting('allow_message_tool')=='true') {
  667. include (api_get_path(LIBRARY_PATH).'message.lib.php');
  668. $number_of_new_messages = get_new_messages();
  669. $cant_msg = ' ('.$number_of_new_messages.')';
  670. if($number_of_new_messages==0) {
  671. $cant_msg= '';
  672. }
  673. //$number_of_new_messages=2;
  674. //echo '<div class="message-view" style="display:none;">'.get_lang('ViewMessages').'</div>';
  675. echo '<div class="message-content">
  676. <h2 class="message-title">'.get_lang('Message').'</h2>
  677. <p>
  678. <a href="../messages/inbox.php" class="message-body">'.get_lang('Inbox').$cant_msg.' </a><br />
  679. <a href="../messages/new_message.php" class="message-body">'.get_lang('Compose').'</a><br />' .
  680. '</p>';
  681. /*
  682. if ($number_of_new_messages>0) {
  683. echo '<div class="message-content-internal">';
  684. echo Display::return_icon('message_new.png',get_lang('NewMessage'));
  685. echo '<a href="inbox.php" style="color:#000000" >'.get_lang('YouHaveNewMessage').'</a>';
  686. echo '&nbsp;</div><br/>';
  687. }
  688. */
  689. echo '<img src="../img/delete.gif" alt="'.get_lang('Close').'" title="'.get_lang('Close').'" class="message-delete" />';
  690. if ($count_message>0) {
  691. echo '<br/>';
  692. }
  693. echo '</div>';
  694. }
  695. $form->display();
  696. Display :: display_footer();
  697. ?>