*/
// resetting the course id
$cidReset = true;
require_once __DIR__.'/../inc/global.inc.php';
$xajax = new xajax();
$xajax->registerFunction(['search_users', 'AccessUrlEditUsersToUrl', 'search_users']);
// setting the section (for the tabs)
$this_section = SECTION_PLATFORM_ADMIN;
// Access restrictions
api_protect_global_admin_script();
if (!api_get_multiple_access_url()) {
header('Location: index.php');
exit;
}
// Database Table Definitions
$tbl_user = Database::get_main_table(TABLE_MAIN_USER);
// setting breadcrumbs
$tool_name = get_lang('EditUsersToURL');
$interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('PlatformAdmin')];
$interbreadcrumb[] = ['url' => 'access_urls.php', 'name' => get_lang('MultipleAccessURLs')];
$add_type = 'multiple';
if (isset($_REQUEST['add_type']) && $_REQUEST['add_type'] != '') {
$add_type = Security::remove_XSS($_REQUEST['add_type']);
}
$access_url_id = 1;
if (isset($_REQUEST['access_url_id']) && $_REQUEST['access_url_id'] != '') {
$access_url_id = Security::remove_XSS($_REQUEST['access_url_id']);
}
$xajax->processRequests();
$htmlHeadXtra[] = $xajax->getJavascript('../inc/lib/xajax/');
$htmlHeadXtra[] = '';
$errorMsg = '';
$message = '';
$userGroup = new UserGroup();
$allUserGroup = $userGroup->get_all_group_tags();
$checkList = [];
$join = '';
$where = '';
if (isset($_POST['form_sent'])) {
$form_sent = $_POST['form_sent'];
$UserList = ($_POST['sessionUsersList'] ?? []);
if (!is_array($UserList)) {
$UserList = [];
}
if ($form_sent == 0) {
$tblUsergroupRelUser = Database::get_main_table(TABLE_USERGROUP_REL_USER);
if (isset($_POST['no_any_class'])) {
$where = "AND u.id NOT IN(SELECT g.user_id FROM $tblUsergroupRelUser g)";
} else {
foreach ($allUserGroup as $userGroup) {
if (isset($_POST[$userGroup['id']])) {
$checkList[] = $userGroup['id'];
$where .= $userGroup['id'].',';
}
}
if (count($checkList) > 0) {
$join = "INNER JOIN $tblUsergroupRelUser g ON u.user_id = g.user_id";
$where = trim($where, ',');
$where = "AND g.usergroup_id IN($where)";
}
}
}
if ($form_sent == 1) {
if ($access_url_id == 0) {
Display::addFlash(Display::return_message(get_lang('SelectURL')));
header('Location: access_url_edit_users_to_url.php');
exit;
} elseif (is_array($UserList)) {
$result = UrlManager::update_urls_rel_user($UserList, $access_url_id);
$url_info = UrlManager::get_url_data_from_id($access_url_id);
if (!empty($result)) {
$message .= 'URL: '.$url_info['url'].'
';
}
if (!empty($result['users_added'])) {
$message .= '