diff --git a/main/auth/profile.php b/main/auth/profile.php index e40e1844c5..e47a606210 100644 --- a/main/auth/profile.php +++ b/main/auth/profile.php @@ -720,10 +720,13 @@ $big_image_width = $big_image_size['width']; $big_image_height = $big_image_size['height']; $url_big_image = $big_image.'?rnd='.time(); +$show_delete_account_button = api_get_setting('platform_unsubscribe_allowed') == 'true' ? true : false; + if (api_get_setting('allow_social_tool') == 'true') { + echo '
'; echo '
'; - echo SocialManager::show_social_menu('home', null, api_get_user_id(), false); + echo SocialManager::show_social_menu('home', null, api_get_user_id(), false, $show_delete_account_button); echo '
'; echo '
'; $form->display(); diff --git a/main/auth/shibboleth/lib/shibboleth_session.class.php b/main/auth/shibboleth/lib/shibboleth_session.class.php index c41b542f76..480c40d2cc 100644 --- a/main/auth/shibboleth/lib/shibboleth_session.class.php +++ b/main/auth/shibboleth/lib/shibboleth_session.class.php @@ -38,9 +38,7 @@ class ShibbolethSession function logout() { $_SESSION['_user'] = array(); - - $logout_no_redirect = true; - online_logout(); + online_logout(null, false); } /** diff --git a/main/auth/unsubscribe_account.php b/main/auth/unsubscribe_account.php new file mode 100644 index 0000000000..1b6bd5ddb2 --- /dev/null +++ b/main/auth/unsubscribe_account.php @@ -0,0 +1,32 @@ +addElement('button', 'submit', get_lang('Unsubscribe'), array('onclick' => "javascript:if(!confirm('".addslashes(api_htmlentities(get_lang("UnsubscribeFromPlatformConfirm")))."')) return false;")); +$content = $form->return_form(); + +if ($form->validate()) { + $user_info = api_get_user_info(); + $result = UserManager::delete_user($user_info['user_id']); + if ($result) { + $message = Display::return_message(sprintf(get_lang('UnsubscribeFromPlatformSuccess', $user_info['username']))); + $content = null; + online_logout($user_info['user_id'], false); + api_not_allowed(true, $message); + } +} + +$tpl = new Template($tool_name); +$tpl->assign('actions', $actions); +$tpl->assign('message', $message); +$tpl->assign('content', $content); +$tpl->display_one_col_template(); diff --git a/main/inc/lib/online.inc.php b/main/inc/lib/online.inc.php index 834b087c33..0b77c9edd8 100644 --- a/main/inc/lib/online.inc.php +++ b/main/inc/lib/online.inc.php @@ -51,21 +51,24 @@ function LoginCheck($uid) { * @return void Directly redirects the user or leaves him where he is, but doesn't return anything * @author Fernando P. GarcĂ­a */ -function online_logout() { +function online_logout($user_id = null, $logout_redirect = false) { global $_configuration, $extAuthSource; - // variable initialisation - $query_string=''; - - if (!empty($_SESSION['user_language_choice'])) { - $query_string='?language='.$_SESSION['user_language_choice']; - } - + // Database table definition $tbl_track_login = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_LOGIN); - // selecting the last login of the user - $uid = intval($_GET['uid']); - $sql_last_connection="SELECT login_id, login_date FROM $tbl_track_login WHERE login_user_id='$uid' ORDER BY login_date DESC LIMIT 0,1"; + if (empty($user_id)) { + $user_id = intval($_GET['uid']); + } + + //Changing global chat status to offline + if (api_get_setting('allow_global_chat') == 'true') { + $chat = new Chat(); + $chat->set_user_status(0); + } + + // selecting the last login of the user + $sql_last_connection="SELECT login_id, login_date FROM $tbl_track_login WHERE login_user_id='$user_id' ORDER BY login_date DESC LIMIT 0,1"; $q_last_connection=Database::query($sql_last_connection); if (Database::num_rows($q_last_connection)>0) { $i_id_last_connection=Database::result($q_last_connection,0,"login_id"); @@ -76,14 +79,14 @@ function online_logout() { $s_sql_update_logout_date="UPDATE $tbl_track_login SET logout_date='".$current_date."' WHERE login_id='$i_id_last_connection'"; Database::query($s_sql_update_logout_date); } - LoginDelete($uid); //from inc/lib/online.inc.php - removes the "online" status + LoginDelete($user_id); //from inc/lib/online.inc.php - removes the "online" status //the following code enables the use of an external logout function. //example: define a $extAuthSource['ldap']['logout']="file.php" in configuration.php // then a function called ldap_logout() inside that file // (using *authent_name*_logout as the function name) and the following code // will find and execute it - $uinfo = api_get_user_info($uid); + $uinfo = api_get_user_info($user_id); if (($uinfo['auth_source'] != PLATFORM_AUTH_SOURCE) && is_array($extAuthSource)) { if (is_array($extAuthSource[$uinfo['auth_source']])) { $subarray = $extAuthSource[$uinfo['auth_source']]; @@ -96,12 +99,13 @@ function online_logout() { } } } + require_once api_get_path(SYS_PATH) . 'main/chat/chat_functions.lib.php'; - exit_of_chat($uid); - Session::destroy(); - global $logout_no_redirect; - if (!$logout_no_redirect) { - header("Location: index.php$query_string"); + exit_of_chat($user_id); + + Session::destroy(); + if ($logout_redirect) { + header("Location: index.php"); return; } } diff --git a/main/inc/lib/social.lib.php b/main/inc/lib/social.lib.php index 89d2d3164b..e4dd18d569 100644 --- a/main/inc/lib/social.lib.php +++ b/main/inc/lib/social.lib.php @@ -545,7 +545,7 @@ class SocialManager extends UserManager { * @param bool show profile or not (show or hide the user image/information) * */ - public static function show_social_menu($show = '', $group_id = 0, $user_id = 0, $show_full_profile = false) { + public static function show_social_menu($show = '', $group_id = 0, $user_id = 0, $show_full_profile = false, $show_delete_account_button = false) { if (empty($user_id)) { $user_id = api_get_user_id(); } @@ -603,22 +603,22 @@ class SocialManager extends UserManager { if (!in_array($show, array('shared_profile', 'groups', 'group_edit', 'member_list','waiting_list','invite_friends'))) { $html .= ''; } @@ -634,14 +634,14 @@ class SocialManager extends UserManager { // My own profile if ($show_full_profile && $user_id == intval(api_get_user_id())) { - $html .= '
  • '.Display::return_icon('home.png',get_lang('Home'),array('hspace'=>'6')).'
  • -
  • '.Display::return_icon('instant_message.png',get_lang('Messages'),array('hspace'=>'6')).'
  • '; - $html .= '
  • '.Display::return_icon('invitation.png',get_lang('Invitations'),array('hspace'=>'6')).''.get_lang('Invitations').$total_invitations.'
  • '; - $html .= '
  • '.Display::return_icon('my_shared_profile.png', get_lang('ViewMySharedProfile'), array('hspace'=>'6','style'=>'float:left')).'
  • -
  • '.Display::return_icon('friend.png',get_lang('Friends'),array('hspace'=>'6')).'
  • -
  • '.Display::return_icon('group_s.png', get_lang('SocialGroups'),array('hspace'=>'6')).'
  • '; - $html .= '
  • '.Display::return_icon('zoom.png',get_lang('Search'),array('hspace'=>'6')).''.get_lang('Search').'
  • '; - $html .= '
  • '.Display::return_icon('briefcase.png',get_lang('MyFiles'),array('hspace'=>'6'),16).''.get_lang('MyFiles').'
  • '; + $html .= '
  • '.Display::return_icon('home.png',get_lang('Home'),array()).'
  • +
  • '.Display::return_icon('instant_message.png',get_lang('Messages'),array()).'
  • '; + $html .= '
  • '.Display::return_icon('invitation.png',get_lang('Invitations'),array()).''.get_lang('Invitations').$total_invitations.'
  • '; + $html .= '
  • '.Display::return_icon('my_shared_profile.png', get_lang('ViewMySharedProfile'), array('style'=>'float:left')).'
  • +
  • '.Display::return_icon('friend.png',get_lang('Friends'),array()).'
  • +
  • '.Display::return_icon('group_s.png', get_lang('SocialGroups'),array()).'
  • '; + $html .= '
  • '.Display::return_icon('zoom.png',get_lang('Search'),array()).''.get_lang('Search').'
  • '; + $html .= '
  • '.Display::return_icon('briefcase.png',get_lang('MyFiles'),array(),16).''.get_lang('MyFiles').'
  • '; } // My friend profile @@ -718,7 +718,16 @@ class SocialManager extends UserManager { } } } + + if ($show_delete_account_button) { + $html .= ''; + } $html .= '
    '; + + return $html; } diff --git a/main/inc/lib/userportal.lib.php b/main/inc/lib/userportal.lib.php index 5e7a584dd0..3aaeaa676d 100644 --- a/main/inc/lib/userportal.lib.php +++ b/main/inc/lib/userportal.lib.php @@ -103,76 +103,16 @@ class IndexManager { } /** - * This function handles the logout and is called whenever there is a $_GET['logout'] - * - * @author Patrick Cool , Ghent University + * Alias for the online_logout() function */ function logout() { - global $_configuration, $extAuthSource; - - // Variable initialisation. - $query_string = ''; - - if (!empty($_SESSION['user_language_choice'])) { - $query_string = '?language='.$_SESSION['user_language_choice']; - } - - // Database table definition. - $tbl_track_login = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_LOGIN); - - // Selecting the last login of the user. - $uid = $this->user_id; - - //Changing global chat status to offline - if (api_get_setting('allow_global_chat') == 'true') { - $chat = new Chat(); - $chat->set_user_status(0); - } - - $sql_last_connection = "SELECT login_id, login_date FROM $tbl_track_login WHERE login_user_id='$uid' ORDER BY login_date DESC LIMIT 0,1"; - $q_last_connection = Database::query($sql_last_connection); - if (Database::num_rows($q_last_connection) > 0) { - $i_id_last_connection = Database::result($q_last_connection, 0, 'login_id'); - } - - if (!isset($_SESSION['login_as'])) { - $current_date = date('Y-m-d H:i:s', time()); - $s_sql_update_logout_date = "UPDATE $tbl_track_login SET logout_date='".$current_date."' WHERE login_id='$i_id_last_connection'"; - Database::query($s_sql_update_logout_date); - } - LoginDelete($uid); // From inc/lib/online.inc.php - removes the "online" status. - - // The following code enables the use of an external logout function. - // Example: define a $extAuthSource['ldap']['logout'] = 'file.php' in configuration.php. - // Then a function called ldap_logout() inside that file - // (using *authent_name*_logout as the function name) and the following code - // will find and execute it. - $uinfo = api_get_user_info($uid); - if (($uinfo['auth_source'] != PLATFORM_AUTH_SOURCE) && is_array($extAuthSource)) { - if (is_array($extAuthSource[$uinfo['auth_source']])) { - $subarray = $extAuthSource[$uinfo['auth_source']]; - if (!empty($subarray['logout']) && file_exists($subarray['logout'])) { - include_once $subarray['logout']; - $logout_function = $uinfo['auth_source'].'_logout'; - if (function_exists($logout_function)) { - $logout_function($uinfo); - } - } - } - } - exit_of_chat($uid); - Session::destroy(); - - - $query_string = $query_string ? "$query_string&loggedout=true" : '?loggedout=true'; - header("Location: index.php$query_string"); - exit(); + online_logout($this->user_id, true); } /** * This function checks if there are courses that are open to the world in the platform course categories (=faculties) * - * @param unknown_type $category + * @param string $category * @return boolean */ function category_has_open_courses($category) { diff --git a/main/inc/local.inc.php b/main/inc/local.inc.php index f0fa4d5651..2632e4bd97 100644 --- a/main/inc/local.inc.php +++ b/main/inc/local.inc.php @@ -470,13 +470,9 @@ if (!empty($_SESSION['_user']['user_id']) && ! ($login || $logout)) { $osso = new sso(); } if (isset($_SESSION['_user']['user_id'])) { - if ($logout) { - - // Prevent index.php to redirect - global $logout_no_redirect; - $logout_no_redirect = TRUE; + if ($logout) { // Make custom redirect after logout - online_logout(); + online_logout($_SESSION['_user']['user_id'], false); $osso->logout(); //redirects and exits } } elseif(!$logout) { diff --git a/main/template/default/layout/layout_2_col.tpl b/main/template/default/layout/layout_2_col.tpl index 6ee32f96ed..b4bcbbc8fc 100644 --- a/main/template/default/layout/layout_2_col.tpl +++ b/main/template/default/layout/layout_2_col.tpl @@ -15,7 +15,11 @@ {# ?? #} {% if home_page_block %}
    - {{ home_page_block}} +
    +
    + {{ home_page_block}} +
    +
    {% endif %} diff --git a/tests/main/inc/lib/online.inc.test.php b/tests/main/inc/lib/online.inc.test.php index 75422fd58b..439cf42b13 100755 --- a/tests/main/inc/lib/online.inc.test.php +++ b/tests/main/inc/lib/online.inc.test.php @@ -24,10 +24,8 @@ class TestOnline extends UnitTestCase { } function testonline_logout(){ - global $_configuration, $extAuthSource; - global $logout_no_redirect; - $logout_no_redirect = 'prueba'; - $res=online_logout(); + global $_configuration, $extAuthSource; + $res=online_logout(null, true); $this->assertTrue(is_null($res)); //var_dump($res); }