profile.php 31 KB

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