registerFunction('search_sessions'); // setting the section (for the tabs) $this_section = SECTION_PLATFORM_ADMIN; // Access restrictions api_protect_admin_script(true); // setting breadcrumbs $interbreadcrumb[] = array('url' => 'index.php', 'name' => get_lang('PlatformAdmin')); $interbreadcrumb[] = array('url' => 'user_list.php', 'name' => get_lang('UserList')); // Database Table Definitions $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION); $tbl_session_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_USER); $tbl_session_rel_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION); // Initializing variables $user_id = isset($_GET['user']) ? intval($_GET['user']) : null; $user_info = api_get_user_info($user_id); $user_anonymous = api_get_anonymous_id(); $current_user_id = api_get_user_id(); $ajax_search = false; // Setting the name of the tool if (UserManager::is_admin($user_id)) { $tool_name = get_lang('AssignSessionsToPlatformAdministrator'); } else if ($user_info['status'] == SESSIONADMIN) { $tool_name = get_lang('AssignSessionsToSessionsAdministrator'); } else { $tool_name = get_lang('AssignSessionsToHumanResourcesManager'); } $add_type = 'multiple'; if (isset($_GET['add_type']) && $_GET['add_type']!='') { $add_type = Security::remove_XSS($_REQUEST['add_type']); } if (!api_is_platform_admin() && !api_is_session_admin()) { api_not_allowed(true); } function search_sessions($needle, $type) { global $user_id; $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION); $tbl_session_rel_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION); $xajax_response = new xajaxResponse(); $return = ''; if (!empty($needle) && !empty($type)) { $needle = Database::escape_string($needle); $assigned_sessions_to_hrm = SessionManager::get_sessions_followed_by_drh($user_id); $assigned_sessions_id = array_keys($assigned_sessions_to_hrm); $without_assigned_sessions = ''; if (count($assigned_sessions_id) > 0) { $without_assigned_sessions = " AND s.id NOT IN(".implode(',', $assigned_sessions_id).")"; } if (api_is_multiple_url_enabled()) { $sql = " SELECT s.id, s.name FROM $tbl_session s LEFT JOIN $tbl_session_rel_access_url a ON (s.id = a.session_id) WHERE s.name LIKE '$needle%' $without_assigned_sessions AND access_url_id = ".api_get_current_access_url_id(); } else { $sql = "SELECT s.id, s.name FROM $tbl_session s WHERE s.name LIKE '$needle%' $without_assigned_sessions "; } $rs = Database::query($sql); $return .= ''; $xajax_response->addAssign('ajax_list_sessions_multiple','innerHTML',api_utf8_encode($return)); } return $xajax_response; } $xajax->processRequests(); $htmlHeadXtra[] = $xajax->getJavascript('../inc/lib/xajax/'); $htmlHeadXtra[] = ' '; $formSent=0; $firstLetterSession = isset($_POST['firstLetterSession']) ? $_POST['firstLetterSession'] : null; $errorMsg = ''; $UserList = array(); if (isset($_POST['formSent']) && intval($_POST['formSent']) == 1) { $sessions_list = $_POST['SessionsList']; $userInfo = api_get_user_info($user_id); $affected_rows = SessionManager::subscribeSessionsToDrh( $userInfo, $sessions_list ); if ($affected_rows) { Display::addFlash( Display::return_message(get_lang('AssignedSessionsHaveBeenUpdatedSuccessfully')) ); } } // display header Display::display_header($tool_name); // Actions if ($user_info['status'] != SESSIONADMIN) { $actionsLeft = '' . Display::return_icon('add-user.png', get_lang('AssignUsers'), null, ICON_SIZE_MEDIUM ) . ''; $actionsLeft .= '' . Display::return_icon('course-add.png', get_lang('AssignCourses'), null, ICON_SIZE_MEDIUM) . ''; } echo Display::toolbarAction('toolbar-dashboard', array($actionsLeft)); echo Display::page_header( sprintf(get_lang('AssignSessionsToX'), api_get_person_name($user_info['firstname'], $user_info['lastname'])), null, 'h3' ); $assigned_sessions_to_hrm = SessionManager::get_sessions_followed_by_drh($user_id); $assigned_sessions_id = array_keys($assigned_sessions_to_hrm); $without_assigned_sessions = ''; if (count($assigned_sessions_id) > 0) { $without_assigned_sessions = " AND s.id NOT IN (".implode(',',$assigned_sessions_id).") "; } $needle = '%'; if (!empty($firstLetterSession)) { $needle = Database::escape_string($firstLetterSession.'%'); } if (api_is_multiple_url_enabled()) { $sql = "SELECT s.id, s.name FROM $tbl_session s LEFT JOIN $tbl_session_rel_access_url a ON (s.id = a.session_id) WHERE s.name LIKE '$needle%' $without_assigned_sessions AND access_url_id = ".api_get_current_access_url_id()." ORDER BY s.name"; } else { $sql = "SELECT s.id, s.name FROM $tbl_session s WHERE s.name LIKE '$needle%' $without_assigned_sessions ORDER BY s.name"; } $result = Database::query($sql); ?>