profile.php 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851
  1. <?php // $Id: profile.php 19225 2009-03-24 01:31:26Z cvargas1 $
  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. $form->addRule('picture', get_lang('OnlyImagesAllowed'), 'mimetype', array('image/gif', 'image/jpeg', 'image/png','image/pjpeg'));
  219. }
  220. // LANGUAGE
  221. $form->addElement('select_language', 'language', get_lang('Language'));
  222. if (api_get_setting('profile', 'language') !== 'true')
  223. $form->freeze('language');
  224. // EXTENDED PROFILE this make the page very slow!
  225. if (api_get_setting('extended_profile') == 'true') {
  226. if ($_GET['type']=='extended') {
  227. //$form->addElement('html', '<a href="#" onclick="javascript:show_extend();"> show_extend_profile</a>');
  228. $form->addElement('static', null, '<em>'.get_lang('OptionalTextFields').'</em>');
  229. // MY COMPETENCES
  230. $form->add_html_editor('competences', get_lang('MyCompetences'), false);
  231. // MY DIPLOMAS
  232. $form->add_html_editor('diplomas', get_lang('MyDiplomas'), false);
  233. // WHAT I AM ABLE TO TEACH
  234. $form->add_html_editor('teach', get_lang('MyTeach'), false);
  235. // MY PRODUCTIONS
  236. $form->addElement('file', 'production', get_lang('MyProductions'));
  237. if ($production_list = UserManager::build_production_list($_user['user_id'],'',true)) {
  238. $form->addElement('static', 'productions_list', null, $production_list);
  239. }
  240. // MY PERSONAL OPEN AREA
  241. $form->add_html_editor('openarea', get_lang('MyPersonalOpenArea'), false);
  242. $form->applyFilter(array('competences', 'diplomas', 'teach', 'openarea'), 'stripslashes');
  243. $form->applyFilter(array('competences', 'diplomas', 'teach'), 'trim'); // openarea is untrimmed for maximum openness
  244. }
  245. }
  246. // PASSWORD
  247. if (is_profile_editable() && api_get_setting('profile', 'password') == 'true') {
  248. $form->addElement('password', 'password0', get_lang('Pass'), array('size' => 40));
  249. $form->addElement('static', null, null, '<em>'.get_lang('Enter2passToChange').'</em>');
  250. $form->addElement('password', 'password1', get_lang('NewPass'), array('size' => 40));
  251. $form->addElement('password', 'password2', get_lang('Confirmation'), array('size' => 40));
  252. // user must enter identical password twice so we can prevent some user errors
  253. $form->addRule(array('password1', 'password2'), get_lang('PassTwo'), 'compare');
  254. if (CHECK_PASS_EASY_TO_FIND)
  255. $form->addRule('password1', get_lang('PassTooEasy').': '.api_generate_password(), 'callback', 'api_check_password');
  256. }
  257. // EXTRA FIELDS
  258. $extra = UserManager::get_extra_fields(0,50,5,'ASC');
  259. $extra_data = UserManager::get_extra_user_data(api_get_user_id(),true);
  260. foreach($extra as $id => $field_details) {
  261. if($field_details[6] == 0) {
  262. continue;
  263. }
  264. switch($field_details[2]) {
  265. case USER_FIELD_TYPE_TEXT:
  266. $form->addElement('text', 'extra_'.$field_details[1], $field_details[3], array('size' => 40));
  267. $form->applyFilter('extra_'.$field_details[1], 'stripslashes');
  268. $form->applyFilter('extra_'.$field_details[1], 'trim');
  269. if ($field_details[7] == 0) $form->freeze('extra_'.$field_details[1]);
  270. break;
  271. case USER_FIELD_TYPE_TEXTAREA:
  272. $form->add_html_editor('extra_'.$field_details[1], $field_details[3], false);
  273. //$form->addElement('textarea', 'extra_'.$field_details[1], $field_details[3], array('size' => 80));
  274. $form->applyFilter('extra_'.$field_details[1], 'stripslashes');
  275. $form->applyFilter('extra_'.$field_details[1], 'trim');
  276. if ($field_details[7] == 0) $form->freeze('extra_'.$field_details[1]);
  277. break;
  278. case USER_FIELD_TYPE_RADIO:
  279. $group = array();
  280. foreach($field_details[9] as $option_id => $option_details) {
  281. $options[$option_details[1]] = $option_details[2];
  282. $group[] =& HTML_QuickForm::createElement('radio', 'extra_'.$field_details[1], $option_details[1],$option_details[2].'<br />',$option_details[1]);
  283. }
  284. $form->addGroup($group, 'extra_'.$field_details[1], $field_details[3], '');
  285. if ($field_details[7] == 0) $form->freeze('extra_'.$field_details[1]);
  286. break;
  287. case USER_FIELD_TYPE_SELECT:
  288. $options = array();
  289. foreach($field_details[9] as $option_id => $option_details) {
  290. $options[$option_details[1]] = $option_details[2];
  291. }
  292. $form->addElement('select','extra_'.$field_details[1],$field_details[3],$options,'');
  293. if ($field_details[7] == 0) $form->freeze('extra_'.$field_details[1]);
  294. break;
  295. case USER_FIELD_TYPE_SELECT_MULTIPLE:
  296. $options = array();
  297. foreach($field_details[9] as $option_id => $option_details) {
  298. $options[$option_details[1]] = $option_details[2];
  299. }
  300. $form->addElement('select','extra_'.$field_details[1],$field_details[3],$options,array('multiple' => 'multiple'));
  301. if ($field_details[7] == 0) $form->freeze('extra_'.$field_details[1]);
  302. break;
  303. case USER_FIELD_TYPE_DATE:
  304. $form->addElement('datepickerdate', 'extra_'.$field_details[1],$field_details[3], array('form_name'=>'profile'));
  305. $form->_elements[$form->_elementIndex['extra_'.$field_details[1]]]->setLocalOption('minYear',1900);
  306. if ($field_details[7] == 0) $form->freeze('extra_'.$field_details[1]);
  307. $form->applyFilter('theme', 'trim');
  308. $defaults['extra_'.$field_details[1]] = date('Y-m-d 12:00:00');
  309. $form -> setDefaults($defaults);
  310. break;
  311. case USER_FIELD_TYPE_DATETIME:
  312. $form->addElement('datepicker', 'extra_'.$field_details[1],$field_details[3], array('form_name'=>'profile'));
  313. $form->_elements[$form->_elementIndex['extra_'.$field_details[1]]]->setLocalOption('minYear',1900);
  314. if ($field_details[7] == 0) $form->freeze('extra_'.$field_details[1]);
  315. $form->applyFilter('theme', 'trim');
  316. $defaults['extra_'.$field_details[1]] = date('Y-m-d 12:00:00');
  317. $form -> setDefaults($defaults);
  318. break;
  319. case USER_FIELD_TYPE_DOUBLE_SELECT:
  320. foreach ($field_details[9] as $key=>$element) {
  321. if ($element[2][0] == '*') {
  322. $values['*'][$element[0]] = str_replace('*','',$element[2]);
  323. } else {
  324. $values[0][$element[0]] = $element[2];
  325. }
  326. }
  327. $group='';
  328. $group[] =& HTML_QuickForm::createElement('select', 'extra_'.$field_details[1],'',$values[0],'');
  329. $group[] =& HTML_QuickForm::createElement('select', 'extra_'.$field_details[1].'*','',$values['*'],'');
  330. $form->addGroup($group, 'extra_'.$field_details[1], $field_details[3], '&nbsp;');
  331. if ($field_details[7] == 0) $form->freeze('extra_'.$field_details[1]);
  332. // recoding the selected values for double : if the user has selected certain values, we have to assign them to the correct select form
  333. if (key_exists('extra_'.$field_details[1], $extra_data))
  334. {
  335. // exploding all the selected values (of both select forms)
  336. $selected_values = explode(';',$extra_data['extra_'.$field_details[1]]);
  337. $extra_data['extra_'.$field_details[1]] =array();
  338. // looping through the selected values and assigning the selected values to either the first or second select form
  339. foreach ($selected_values as $key=>$selected_value)
  340. {
  341. if (key_exists($selected_value,$values[0]))
  342. {
  343. $extra_data['extra_'.$field_details[1]]['extra_'.$field_details[1]] = $selected_value;
  344. }
  345. else
  346. {
  347. $extra_data['extra_'.$field_details[1]]['extra_'.$field_details[1].'*'] = $selected_value;
  348. }
  349. }
  350. }
  351. break;
  352. case USER_FIELD_TYPE_DIVIDER:
  353. $form->addElement('static',$field_details[1], '<br /><strong>'.$field_details[3].'</strong>');
  354. break;
  355. }
  356. }
  357. if (api_get_setting('profile', 'apikeys') == 'true') {
  358. $form->addElement('html','<div id="div_api_key">');
  359. $form->addElement('text', 'api_key_generate', get_lang('MyApiKey'), array('size' => 40,'id' => 'id_api_key_generate'));
  360. $form->addElement('html','</div>');
  361. $form->addElement('button', 'generate_api_key', get_lang('GenerateApiKey'),array('id' => 'id_generate_api_key','onclick' => 'generate_open_id_form()'));//generate_open_id_form()
  362. }
  363. // SUBMIT
  364. if (is_profile_editable()) {
  365. $form->addElement('style_submit_button', 'apply_change', get_lang('SaveSettings'), 'class="save"');
  366. } else {
  367. $form->freeze();
  368. }
  369. $user_data = array_merge($user_data,$extra_data);
  370. $form->setDefaults($user_data);
  371. /*
  372. ==============================================================================
  373. FUNCTIONS
  374. ==============================================================================
  375. */
  376. /*
  377. -----------------------------------------------------------
  378. LOGIC FUNCTIONS
  379. -----------------------------------------------------------
  380. */
  381. /**
  382. * Can a user edit his/her profile?
  383. *
  384. * @return boolean Editability of the profile
  385. */
  386. function is_profile_editable()
  387. {
  388. return $GLOBALS['profileIsEditable'];
  389. }
  390. /*
  391. -----------------------------------------------------------
  392. USER IMAGE FUNCTIONS
  393. -----------------------------------------------------------
  394. */
  395. /**
  396. * Upload a submitted user image.
  397. *
  398. * @param $user_id User id
  399. * @return The filename of the new picture or FALSE if the upload has failed
  400. */
  401. function upload_user_image($user_id)
  402. {
  403. /* Originally added by Miguel (miguel@cesga.es) - 2003-11-04
  404. * Code Refactoring by Hugues Peeters (hugues.peeters@claroline.net) - 2003-11-24
  405. * Moved inside a function and refactored by Thomas Corthals - 2005-11-04
  406. */
  407. $image_path = UserManager::get_user_picture_path_by_id($user_id,'system',true);
  408. $image_repository = $image_path['dir'];
  409. $existing_image = $image_path['file'];
  410. $file_extension = explode('.', $_FILES['picture']['name']);
  411. $file_extension = strtolower($file_extension[count($file_extension) - 1]);
  412. if (!file_exists($image_repository)) {
  413. mkpath($image_repository);
  414. }
  415. if ($existing_image != '') {
  416. if (KEEP_THE_NAME_WHEN_CHANGE_IMAGE) {
  417. $picture_filename = $existing_image;
  418. $old_picture_filename = 'saved_'.date('Y_m_d_H_i_s').'_'.uniqid('').'_'.$existing_image;
  419. } else {
  420. $old_picture_filename = $existing_image;
  421. $picture_filename = (PREFIX_IMAGE_FILENAME_WITH_UID ? 'u'.$user_id.'_' : '').uniqid('').'.'.$file_extension;
  422. }
  423. if (KEEP_THE_OLD_IMAGE_AFTER_CHANGE) {
  424. @rename($image_repository.$existing_image, $image_repository.$old_picture_filename);
  425. } else {
  426. @unlink($image_repository.$existing_image);
  427. }
  428. } else {
  429. $picture_filename = (PREFIX_IMAGE_FILENAME_WITH_UID ? $user_id.'_' : '').uniqid('').'.'.$file_extension;
  430. }
  431. // get the picture and resize it 200x200 only if the picture is bigger than 200px (width)
  432. $temp = new image($_FILES['picture']['tmp_name']);
  433. $picture_infos=getimagesize($_FILES['picture']['tmp_name']);
  434. $max_size_for_picture = 200; // in pixels
  435. if ($picture_infos[0]>$max_size_for_picture) {
  436. $thumbwidth = $max_size_for_picture;
  437. if (empty($thumbwidth) or $thumbwidth==0) {
  438. $thumbwidth=$max_size_for_picture;
  439. }
  440. $new_height = round(($thumbwidth/$picture_infos[0])*$picture_infos[1]);
  441. $temp->resize($thumbwidth,$new_height,0);
  442. }
  443. $type=$picture_infos[2];
  444. // original picture
  445. $big_temp = new image($_FILES['picture']['tmp_name']);
  446. switch (!empty($type)) {
  447. case 2 : $temp->send_image('JPG',$image_repository.$picture_filename);
  448. $big_temp->send_image('JPG',$image_repository.'big_'.$picture_filename);
  449. break;
  450. case 3 : $temp->send_image('PNG',$image_repository.$picture_filename);
  451. $big_temp->send_image('JPG',$image_repository.'big_'.$picture_filename);
  452. break;
  453. case 1 : $temp->send_image('GIF',$image_repository.$picture_filename);
  454. $big_temp->send_image('JPG',$image_repository.'big_'.$picture_filename);
  455. break;
  456. }
  457. return $picture_filename;
  458. }
  459. /**
  460. * Remove an existing user image.
  461. *
  462. * @param $user_id User id
  463. */
  464. function remove_user_image($user_id)
  465. {
  466. $image_path = UserManager::get_user_picture_path_by_id($user_id,'system');
  467. $image_repository = $image_path['dir'];
  468. $image = $image_path['file'];
  469. if ($image != '')
  470. {
  471. if (KEEP_THE_OLD_IMAGE_AFTER_CHANGE)
  472. {
  473. @rename($image_repository.$image, $image_repository.'deleted_'.date('Y_m_d_H_i_s').'_'.$image);
  474. }
  475. else
  476. {
  477. @unlink($image_repository.$image);
  478. }
  479. }
  480. }
  481. /*
  482. -----------------------------------------------------------
  483. PRODUCTIONS FUNCTIONS
  484. -----------------------------------------------------------
  485. */
  486. /**
  487. * Upload a submitted user production.
  488. *
  489. * @param $user_id User id
  490. * @return The filename of the new production or FALSE if the upload has failed
  491. */
  492. function upload_user_production($user_id)
  493. {
  494. $image_path = UserManager::get_user_picture_path_by_id($user_id,'system',true);
  495. $production_repository = $image_path['dir'].$user_id.'/';
  496. if (!file_exists($production_repository))
  497. {
  498. mkpath($production_repository);
  499. }
  500. $filename = replace_dangerous_char($_FILES['production']['name']);
  501. $filename = disable_dangerous_file($filename);
  502. if(filter_extension($filename))
  503. {
  504. if (@move_uploaded_file($_FILES['production']['tmp_name'], $production_repository.$filename))
  505. {
  506. return $filename;
  507. }
  508. }
  509. return false; // this should be returned if anything went wrong with the upload
  510. }
  511. /**
  512. * Write old password to change a new password.
  513. * @param int User id
  514. * @param char password
  515. * @return bool true o false
  516. */
  517. function check_user_password($password){
  518. global $_user;
  519. $user_id = $_user['user_id'];
  520. if ( $user_id != strval(intval($user_id)) || empty($password) ) { return false; }
  521. $table_user = Database :: get_main_table(TABLE_MAIN_USER);
  522. $password = api_get_encrypted_password($password);
  523. $sql_password="SELECT * FROM $table_user WHERE user_id='".$user_id."' AND password='".$password."'";
  524. $result=api_sql_query($sql_password, __FILE__, __LINE__);
  525. if (Database::num_rows($result)==0) {
  526. return false;
  527. } else {
  528. return true;
  529. }
  530. }
  531. /*
  532. ==============================================================================
  533. MAIN CODE
  534. ==============================================================================
  535. */
  536. $filtered_extension = false;
  537. $update_success = false;
  538. $upload_picture_success = false;
  539. $upload_production_success = false;
  540. if (!empty($_SESSION['profile_update']))
  541. {
  542. $update_success = ($_SESSION['profile_update'] == 'success');
  543. unset($_SESSION['profile_update']);
  544. }
  545. if (!empty($_SESSION['image_uploaded']))
  546. {
  547. $upload_picture_success = ($_SESSION['image_uploaded'] == 'success');
  548. unset($_SESSION['image_uploaded']);
  549. }
  550. if (!empty($_SESSION['production_uploaded']))
  551. {
  552. $upload_production_success = ($_SESSION['production_uploaded'] == 'success');
  553. unset($_SESSION['production_uploaded']);
  554. } elseif (isset($_POST['remove_production'])) {
  555. foreach (array_keys($_POST['remove_production']) as $production)
  556. {
  557. UserManager::remove_user_production($_user['user_id'], urldecode($production));
  558. }
  559. if ($production_list = UserManager::build_production_list($_user['user_id'], true,true))
  560. $form->insertElementBefore($form->createElement('static', null, null, $production_list), 'productions_list');
  561. $form->removeElement('productions_list');
  562. $file_deleted = true;
  563. } elseif ($form->validate()) {
  564. $wrong_current_password = false;
  565. $user_data = $form->exportValues();
  566. //
  567. // set password if a new one was provided
  568. if(!empty($user_data['password0'])){
  569. $val=check_user_password($user_data['password0']);
  570. if ($val==true){
  571. if (!empty($user_data['password1']))
  572. $password = $user_data['password1'];
  573. } else {
  574. $wrong_current_password = true;
  575. }
  576. }
  577. if (empty($user_data['password0']) && !empty($user_data['password1'])) {
  578. $wrong_current_password = true;
  579. }
  580. // upload picture if a new one is provided
  581. if ($_FILES['picture']['size'])
  582. {
  583. if ($new_picture = upload_user_image($_user['user_id']))
  584. {
  585. $user_data['picture_uri'] = $new_picture;
  586. $_SESSION['image_uploaded'] = 'success';
  587. }
  588. }
  589. // remove existing picture if asked
  590. elseif (!empty($user_data['remove_picture']))
  591. {
  592. remove_user_image($_user['user_id']);
  593. $user_data['picture_uri'] = '';
  594. }
  595. // upload production if a new one is provided
  596. if ($_FILES['production']['size'])
  597. {
  598. $res = upload_user_production($_user['user_id']);
  599. if(!$res)
  600. {
  601. //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
  602. $filtered_extension = true;
  603. }
  604. else
  605. {
  606. $_SESSION['production_uploaded'] = 'success';
  607. }
  608. }
  609. // remove values that shouldn't go in the database
  610. unset($user_data['password0'],$user_data['password1'], $user_data['password2'], $user_data['MAX_FILE_SIZE'],
  611. $user_data['remove_picture'], $user_data['apply_change']);
  612. // Following RFC2396 (http://www.faqs.org/rfcs/rfc2396.html), a URI uses ':' as a reserved character
  613. // we can thus ensure the URL doesn't contain any scheme name by searching for ':' in the string
  614. $my_user_openid=isset($user_data['openid']) ? $user_data['openid'] : '';
  615. if(!preg_match('/^[^:]*:\/\/.*$/',$my_user_openid))
  616. { //ensure there is at least a http:// scheme in the URI provided
  617. $user_data['openid'] = 'http://'.$my_user_openid;
  618. }
  619. $extras = array();
  620. // build SQL query
  621. $sql = "UPDATE $table_user SET";
  622. unset($user_data['api_key_generate']);
  623. foreach($user_data as $key => $value)
  624. {
  625. if(substr($key,0,6)=='extra_') //an extra field
  626. {
  627. $extras[substr($key,6)] = $value;
  628. }
  629. else
  630. {
  631. $sql .= " $key = '".Database::escape_string($value)."',";
  632. }
  633. }
  634. if (isset($password))
  635. {
  636. $password = api_get_encrypted_password($password);
  637. $sql .= " password = '".Database::escape_string($password)."'";
  638. }
  639. else // remove trailing , from the query we have so far
  640. {
  641. $sql = rtrim($sql, ',');
  642. }
  643. $sql .= " WHERE user_id = '".$_user['user_id']."'";
  644. api_sql_query($sql, __FILE__, __LINE__);
  645. //update the extra fields
  646. foreach($extras as $key=>$value)
  647. {
  648. $myres = UserManager::update_extra_field_value($_user['user_id'],$key,$value);
  649. }
  650. // re-init the system to take new settings into account
  651. $uidReset = true;
  652. include (api_get_path(INCLUDE_PATH).'local.inc.php');
  653. $_SESSION['profile_update'] = 'success';
  654. 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':''));
  655. exit;
  656. }
  657. if (isset($_GET['show'])) {
  658. if ((api_get_setting('allow_social_tool')=='true' && api_get_setting('allow_message_tool')=='true') ||(api_get_setting('allow_social_tool')=='true')) {
  659. $interbreadcrumb[]= array (
  660. 'url' => '#',
  661. 'name' => get_lang('SocialNetwork')
  662. );
  663. } elseif ((api_get_setting('allow_social_tool')=='false' && api_get_setting('allow_message_tool')=='true')) {
  664. $interbreadcrumb[]= array (
  665. 'url' => '#',
  666. 'name' => get_lang('MessageTool')
  667. );
  668. }
  669. }
  670. /*
  671. ==============================================================================
  672. MAIN DISPLAY SECTION
  673. ==============================================================================
  674. */
  675. Display :: display_header('');
  676. if (api_get_setting('extended_profile') == 'true') {
  677. echo '<div class="actions">';
  678. if (isset($_GET['show'])) {
  679. $show='&amp;show='.Security::remove_XSS($_GET['show']);
  680. } else {
  681. $show='';
  682. }
  683. if (isset($_GET['type']) && $_GET['type']=='extended') {
  684. echo '<a href="profile.php?type=reduced'.$show.'">'.Display::return_icon('edit.gif',get_lang('EditNormalProfile')).'&nbsp;'.get_lang('EditNormalProfile').'</a>';
  685. } else {
  686. echo '<a href="profile.php?type=extended'.$show.'">'.Display::return_icon('edit.gif',get_lang('EditExtendProfile')).'&nbsp;'.get_lang('EditExtendProfile').'</a>';
  687. }
  688. if (api_get_setting('allow_social_tool')=='true' && api_get_setting('allow_message_tool')=='true') {
  689. echo '<a href="../social/profile.php">'.Display::return_icon('edit.gif').'&nbsp;'.mb_convert_encoding(get_lang('ViewSharedProfile'),'UTF-8',$charset).'</a>';
  690. }
  691. echo '</div>';
  692. }
  693. if (!empty($file_deleted)) {
  694. Display :: display_confirmation_message(get_lang('FileDeleted'),false);
  695. } elseif (!empty($update_success)) {
  696. $message=get_lang('ProfileReg');
  697. if ($upload_picture_success == true) {
  698. $message.='<br /> '.get_lang('PictureUploaded');
  699. }
  700. if ($upload_production_success == true) {
  701. $message.='<br />'.get_lang('ProductionUploaded');
  702. }
  703. Display :: display_confirmation_message($message,false);
  704. }
  705. if(!empty($warning_msg))
  706. {
  707. Display :: display_warning_message($warning_msg,false);
  708. }
  709. //User picture size is calculated from SYSTEM path
  710. $image_syspath = UserManager::get_user_picture_path_by_id(api_get_user_id(),'system',false,true);
  711. $image_syspath['dir'].$image_syspath['file'];
  712. $image_size = getimagesize($image_syspath['dir'].$image_syspath['file']);
  713. //Web path
  714. $image_path = UserManager::get_user_picture_path_by_id(api_get_user_id(),'web',false,true);
  715. $image_dir = $image_path['dir'];
  716. $image = $image_path['file'];
  717. $image_file = $image_dir.$image;
  718. $img_attributes = 'src="'.$image_file.'?rand='.time().'" '
  719. .'alt="'.$user_data['lastname'].' '.$user_data['firstname'].'" '
  720. .'style="float:'.($text_dir == 'rtl' ? 'left' : 'right').'; margin-top:0px;padding:5px;" ';
  721. if ($image_size[0] > 300) {
  722. //limit display width to 300px
  723. $img_attributes .= 'width="300" ';
  724. }
  725. // get the path,width and height from original picture
  726. $big_image = $image_dir.'big_'.$image;
  727. $big_image_size = @getimagesize($big_image);
  728. $big_image_width= $big_image_size[0];
  729. $big_image_height= $big_image_size[1];
  730. $url_big_image = $big_image.'?rnd='.time();
  731. echo '<div id="image-message-container" style="float:right;padding:5px;width:250px;" >';
  732. if ($image=='unknown.jpg') {
  733. echo '<img '.$img_attributes.' />';
  734. } else {
  735. echo '<input type="image" '.$img_attributes.' onclick="return show_image(\''.$url_big_image.'\',\''.$big_image_width.'\',\''.$big_image_height.'\');"/>';
  736. }
  737. if (api_get_setting('allow_message_tool')=='true') {
  738. include (api_get_path(LIBRARY_PATH).'message.lib.php');
  739. $number_of_new_messages = MessageManager::get_new_messages();
  740. $number_of_outbox_message=MessageManager::get_number_of_messages_sent();
  741. $cant_out_box=' ('.$number_of_outbox_message.')';
  742. $cant_msg = ' ('.$number_of_new_messages.')';
  743. $number_of_new_messages_of_friend=UserFriend::get_message_number_invitation_by_user_id(api_get_user_id());
  744. //echo '<div class="message-view" style="display:none;">'.get_lang('ViewMessages').'</div>';
  745. echo '<div class="message-content">
  746. <h2 class="message-title">'.get_lang('Messages').'</h2>
  747. <p>
  748. <a href="../social/index.php#remote-tab-2" class="message-body">'.get_lang('Inbox').$cant_msg.' </a><br />
  749. <a href="../social/index.php#remote-tab-3" class="message-body">'.get_lang('Outbox').$cant_out_box.'</a><br />
  750. </p>';
  751. /* if (api_get_setting('allow_social_tool')=='true') {
  752. if ($number_of_new_messages_of_friend>0) {
  753. echo '<div class="message-content-internal">';
  754. 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>';
  755. echo '</div><br/>';
  756. }
  757. }*/
  758. echo '<img src="../img/delete.gif" alt="'.get_lang('Close').'" title="'.get_lang('Close').'" class="message-delete" />';
  759. if ($number_of_new_messages_of_friend>0) {
  760. echo '<br/>';
  761. }
  762. echo '</div>';
  763. }
  764. echo '</div>';
  765. $form->display();
  766. Display :: display_footer();
  767. ?>