profile.php 32 KB

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