<commit_before>
function update_profile_location() {
	
	var params = {};
	params.country = document.getElementById('edit_user_country').value;
	params.city = document.getElementById('edit_user_city').value;
	params.university = document.getElementById('edit_user_university').value;
	var url = createUrlFromObj(params);
	send_request_post(
		'api/users/update_location.php',
		url,
		function (obj) {
			if (obj.result == "ok")
				showModalDialog("Saved. <br><br>");
			else
				showModalDialog("Fail. <br>" + obj.error.message + "<br><br>");
		}
	);
}

function update_profile_style() {
	
	var params = {};
	params.style = document.getElementById('edit_style').value;
	var url = createUrlFromObj(params);
	send_request_post(
		'api/users/update_style.php',
		url,
		function (obj) {
			if (obj.result == "ok")
				showModalDialog("Saved. Please reload page!!!<br><br>");
			else
				showModalDialog("Fail. <br>" + obj.error.message + "<br><br>");
		}
	);
}

function resetUsersPage() {
	document.getElementById('user_page').value = 0;
}

function setUsersPage(val) {
	document.getElementById('user_page').value = val;
}

function changeUserLogo(userid) {
	var params = {};
	params.userid = userid;
	params.logo = document.getElementById('user_new_logo').value;
	send_request_post(
		'api/users/update_logo.php',
		createUrlFromObj(params),
		function (obj) {
			if (obj.result == "fail") {
				alert(obj.error.message);
				return;
			}
			document.getElementById('user_current_logo').src = obj.data.logo;
		}
	);
}

function changeUserNick(userid) {
	var params = {};
	if (userid != null) {
		params.userid = userid;
	}
	params.nick = document.getElementById('user_new_nick').value;
	send_request_post(
		'api/users/update_nick.php',
		createUrlFromObj(params),
		function (obj) {
			if (obj.result == "fail") {
				alert(obj.error.message);
				return;
			}
			document.getElementById('user_current_nick').innerHTML = obj.data.nick;
			if (userid == null) {
				document.getElementById('btn_user_info').innerHTML = obj.data.nick;
			}
		}
	);
}

// for admin
// TODO rename to update_user_password
function changeUserPassword(userid) {
	var params = {};
	params.userid = userid;
	params.password = document.getElementById('<PASSWORD>').value;
	params.email = document.getElementById('user_current_email').innerHTML;
	send_request_post(
		'api/users/update_password.php',
		createUrlFromObj(params),
		function (obj) {
			if (obj.result == "fail") {
				alert(obj.error.message);
				return;
			}
			document.getElementById('user_new_password').value = "";
			alert('updated');
		}
	);
}

// for user
function userpage_changeUserPassword() {
	var params = {};
	params.old_password = document.getElementById('userpage_old_password').value;
	params.new_password = document.getElementById('<PASSWORD>page_<PASSWORD>password').value;
	params.new_password_confirm = document.getElementById('userpage_new_password_confirm').value;
	send_request_post(
		'api/users/change_password.php',
		createUrlFromObj(params),
		function (obj) {
			if (obj.result == "fail") {
				showModalDialog(obj.error.message);
				return;
			}
			document.getElementById('userpage_old_password').value = "";
			document.getElementById('userpage_new_password').value = "";
			document.getElementById('userpage_new_password_confirm').value = "";
			showModalDialog('updated');
		}
	);
}

function changeUserStatus(userid) {
	var params = {};
	params.userid = userid;
	params.status = document.getElementById('user_new_status').value;
	send_request_post(
		'api/users/update_status.php',
		createUrlFromObj(params),
		function (obj) {
			if (obj.result == "fail") {
				alert(obj.error.message);
				return;
			}
			document.getElementById('user_current_status').innerHTML = obj.data.status;
		}
	);
}

function changeUserRole(userid) {
	var params = {};
	params.userid = userid;
	params.role = document.getElementById('user_new_role').value;
	send_request_post(
		'api/users/update_role.php',
		createUrlFromObj(params),
		function (obj) {
			if (obj.result == "fail") {
				alert(obj.error.message);
				return;
			}
			document.getElementById('user_current_role').innerHTML = obj.data.role;
		}
	);
}

function deleteUser(userid) {
	if (!confirm("Are you sure that wand remove user?"))
		return;

	var params = {};
	params.userid = userid;
	send_request_post(
		'api/users/delete.php',
		createUrlFromObj(params),
		function (obj) {
			if (obj.result == "fail") {
				alert(obj.error.message);
				return;
			}
			alert("removed! Cry baby cry...");
			closeModalDialog();
			updateUsers();
		}
	);
}

function showUserInfo(id) {
	showModalDialog('<div id="user_info"><center>Please wait...</div>');

	// user info
	fhq.api.users.profile(id).done(function (obj) {
			var ui = document.getElementById('user_info');
			
			
			var pt = new FHQParamTable();
			pt.row('Logo:', '<img id="user_current_logo" src="'+ obj.data.logo + '"/>');
			pt.row('ID:',  obj.data.userid);
			if (obj.access.edit == true) {
				pt.row('E-mail:', '<div id="user_current_email">' + obj.data.email + '</div>');
				pt.row('Role:', '<div id="user_current_role">' + obj.data.role + '</div>');
			}
			pt.row('Nick:', '<div id="user_current_nick">' + obj.data.nick + '</div>');
			if (obj.access.edit == true){
				pt.row('Status:', '<div id="user_current_status">' + obj.data.status + '</div>');
			}

			if (obj.access.edit) {
				if (!obj.currentUser) {
					pt.skip();

					pt.row('Change Logo:', '<input id="user_new_logo" type="text" value="' + obj.data.logo + '" > '
						+ fhqgui.btn('Save', 'changeUserLogo(' + obj.data.userid + ');'));

					pt.row('Change Nick:', '<input id="user_new_nick" type="text" value="' + obj.data.nick + '" > '
						+ fhqgui.btn('Save', 'changeUserNick(' + obj.data.userid + ');'));

					pt.row('Change Password:', '<input id="user_new_password" type="password" value="" > '
						+ fhqgui.btn('Save', 'changeUserPassword(' + obj.data.userid + ');'));

					pt.row('Change Status:', fhqgui.combobox('user_new_status', obj.data.status, fhq.getUserStatuses()) + ' '
						+ fhqgui.btn('Save', 'changeUserStatus(' + obj.data.userid + ');'));
					pt.row('Change Role:', fhqgui.combobox('user_new_role', obj.data.role, fhq.getUserRoles()) + ' '
						+ fhqgui.btn('Save', 'changeUserRole(' + obj.data.userid + ');'));
					pt.row('Remove User:', fhqgui.btn('Remove', 'deleteUser(' + obj.data.userid + ');'));
				}

				pt.skip();
				for (var k in obj.profile) {
					pt.row('Profile "' + k + '":', obj.profile[k]);
				}
			}
			pt.skip();
			for (var k in obj.games) {
				pt.row('Game "' + obj.games[k].title + '" (' + obj.games[k].type_game + '):', obj.games[k].score);
			}
			pt.skip();
			pt.row('', fhqgui.btn('Open in New Tab', 'fhqgui.openUserInNewTab(' + obj.data.userid + ');'));
			pt.skip();
			ui.innerHTML = pt.render();
			// ui.innerHTML += JSON.stringify(obj);

		}
	).fail(function(r){
		document.getElementById('user_info').innerHTML = obj.error.message;
	});
}

function updateUsers() {
	var lu = document.getElementById("listUsers");
	lu.innerHTML = "Please wait...";
	
	var params = {};
	params.search = document.getElementById('user_search').value;
	params.page = document.getElementById('user_page').value;
	params.role = document.getElementById('user_role').value;
	params.status = document.getElementById('user_status').value;
	params.onpage = document.getElementById('user_onpage').value;

	// alert(createUrlFromObj(params));
	send_request_post(
		'api/users/list.php',
		createUrlFromObj(params),
		function (obj) {
			if (obj.result == "fail") {
				document.getElementById('error_search').innerHTML = obj.error.message;
				return;
			}
			
			var ud = document.getElementById("usersdump");
			ud.innerHTML = '';
			for (var k in obj.dumps) {
				// ud.innerHTML += obj.dumps[k] + '<a class="fhqbtn" href="files/dumps/' + obj.dumps[k] + '">' + download + '</a><a class="fhqbtn" href="files/dumps/' + obj.dumps[k] + '">' + download + '</a><br>';
				ud.innerHTML += obj.dumps[k] + ' <a class="fhqbtn" href="files/dumps/' + obj.dumps[k] + '">Download</a><div class="fhqbtn" onclick="removeDumpUsers(\'' + obj.dumps[k] + '\');">Remove</div><br>';
			}

			var lu = document.getElementById("listUsers");
			lu.innerHTML = '';

			var found = parseInt(obj.found, 10);
			document.getElementById("search_found").innerHTML = found;

			var onpage = parseInt(obj.onpage, 10);
			var page = parseInt(obj.page, 10);

			lu.innerHTML += '<div id="user_paging">' + fhqgui.paginator(0,found, onpage, page, 'setUsersPage', 'updateUsers') + '</div>';
			
			
			var tbl = new FHQTable();<commit_msg>Small fix for users list<commit_after>
function update_profile_location() {
	
	var params = {};
	params.country = document.getElementById('edit_user_country').value;
	params.city = document.getElementById('edit_user_city').value;
	params.university = document.getElementById('edit_user_university').value;
	var url = createUrlFromObj(params);
	send_request_post(
		'api/users/update_location.php',
		url,
		function (obj) {
			if (obj.result == "ok")
				showModalDialog("Saved. <br><br>");
			else
				showModalDialog("Fail. <br>" + obj.error.message + "<br><br>");
		}
	);
}

function update_profile_style() {
	
	var params = {};
	params.style = document.getElementById('edit_style').value;
	var url = createUrlFromObj(params);
	send_request_post(
		'api/users/update_style.php',
		url,
		function (obj) {
			if (obj.result == "ok")
				showModalDialog("Saved. Please reload page!!!<br><br>");
			else
				showModalDialog("Fail. <br>" + obj.error.message + "<br><br>");
		}
	);
}

function resetUsersPage() {
	document.getElementById('user_page').value = 0;
}

function setUsersPage(val) {
	document.getElementById('user_page').value = val;
}

function changeUserLogo(userid) {
	var params = {};
	params.userid = userid;
	params.logo = document.getElementById('user_new_logo').value;
	send_request_post(
		'api/users/update_logo.php',
		createUrlFromObj(params),
		function (obj) {
			if (obj.result == "fail") {
				alert(obj.error.message);
				return;
			}
			document.getElementById('user_current_logo').src = obj.data.logo;
		}
	);
}

function changeUserNick(userid) {
	var params = {};
	if (userid != null) {
		params.userid = userid;
	}
	params.nick = document.getElementById('user_new_nick').value;
	send_request_post(
		'api/users/update_nick.php',
		createUrlFromObj(params),
		function (obj) {
			if (obj.result == "fail") {
				alert(obj.error.message);
				return;
			}
			document.getElementById('user_current_nick').innerHTML = obj.data.nick;
			if (userid == null) {
				document.getElementById('btn_user_info').innerHTML = obj.data.nick;
			}
		}
	);
}

// for admin
// TODO rename to update_user_password
function changeUserPassword(userid) {
	var params = {};
	params.userid = userid;
	params.password = document.getElementById('user_new_password').value;
	params.email = document.getElementById('user_current_email').innerHTML;
	send_request_post(
		'api/users/update_password.php',
		createUrlFromObj(params),
		function (obj) {
			if (obj.result == "fail") {
				alert(obj.error.message);
				return;
			}
			document.getElementById('user_new_password').value = "";
			alert('updated');
		}
	);
}

// for user
function userpage_changeUserPassword() {
	var params = {};
	params.old_password = document.getElementById('userpage_old_password').value;
	params.new_password = document.getElementById('userpage_new_password').value;
	params.new_password_confirm = document.getElementById('userpage_new_password_confirm').value;
	send_request_post(
		'api/users/change_password.php',
		createUrlFromObj(params),
		function (obj) {
			if (obj.result == "fail") {
				showModalDialog(obj.error.message);
				return;
			}
			document.getElementById('userpage_old_password').value = "";
			document.getElementById('userpage_new_password').value = "";
			document.getElementById('userpage_new_password_confirm').value = "";
			showModalDialog('updated');
		}
	);
}

function changeUserStatus(userid) {
	var params = {};
	params.userid = userid;
	params.status = document.getElementById('user_new_status').value;
	send_request_post(
		'api/users/update_status.php',
		createUrlFromObj(params),
		function (obj) {
			if (obj.result == "fail") {
				alert(obj.error.message);
				return;
			}
			document.getElementById('user_current_status').innerHTML = obj.data.status;
		}
	);
}

function changeUserRole(userid) {
	var params = {};
	params.userid = userid;
	params.role = document.getElementById('user_new_role').value;
	send_request_post(
		'api/users/update_role.php',
		createUrlFromObj(params),
		function (obj) {
			if (obj.result == "fail") {
				alert(obj.error.message);
				return;
			}
			document.getElementById('user_current_role').innerHTML = obj.data.role;
		}
	);
}

function deleteUser(userid) {
	if (!confirm("Are you sure that wand remove user?"))
		return;

	var params = {};
	params.userid = userid;
	send_request_post(
		'api/users/delete.php',
		createUrlFromObj(params),
		function (obj) {
			if (obj.result == "fail") {
				alert(obj.error.message);
				return;
			}
			alert("removed! Cry baby cry...");
			closeModalDialog();
			updateUsers();
		}
	);
}

function showUserInfo(id) {
	showModalDialog('<div id="user_info"><center>Please wait...</div>');

	// user info
	fhq.api.users.profile(id).done(function (obj) {
			var ui = document.getElementById('user_info');
			
			
			var pt = new FHQParamTable();
			pt.row('Logo:', '<img id="user_current_logo" src="'+ obj.data.logo + '"/>');
			pt.row('ID:',  obj.data.userid);
			if (obj.access.edit == true) {
				pt.row('E-mail:', '<div id="user_current_email">' + obj.data.email + '</div>');
				pt.row('Role:', '<div id="user_current_role">' + obj.data.role + '</div>');
			}
			pt.row('Nick:', '<div id="user_current_nick">' + obj.data.nick + '</div>');
			if (obj.access.edit == true){
				pt.row('Status:', '<div id="user_current_status">' + obj.data.status + '</div>');
			}

			if (obj.access.edit) {
				if (!obj.currentUser) {
					pt.skip();

					pt.row('Change Logo:', '<input id="user_new_logo" type="text" value="' + obj.data.logo + '" > '
						+ fhqgui.btn('Save', 'changeUserLogo(' + obj.data.userid + ');'));

					pt.row('Change Nick:', '<input id="user_new_nick" type="text" value="' + obj.data.nick + '" > '
						+ fhqgui.btn('Save', 'changeUserNick(' + obj.data.userid + ');'));

					pt.row('Change Password:', '<input id="user_new_password" type="password" value="" > '
						+ fhqgui.btn('Save', 'changeUserPassword(' + obj.data.userid + ');'));

					pt.row('Change Status:', fhqgui.combobox('user_new_status', obj.data.status, fhq.getUserStatuses()) + ' '
						+ fhqgui.btn('Save', 'changeUserStatus(' + obj.data.userid + ');'));
					pt.row('Change Role:', fhqgui.combobox('user_new_role', obj.data.role, fhq.getUserRoles()) + ' '
						+ fhqgui.btn('Save', 'changeUserRole(' + obj.data.userid + ');'));
					pt.row('Remove User:', fhqgui.btn('Remove', 'deleteUser(' + obj.data.userid + ');'));
				}

				pt.skip();
				for (var k in obj.profile) {
					pt.row('Profile "' + k + '":', obj.profile[k]);
				}
			}
			pt.skip();
			for (var k in obj.games) {
				pt.row('Game "' + obj.games[k].title + '" (' + obj.games[k].type_game + '):', obj.games[k].score);
			}
			pt.skip();
			pt.row('', fhqgui.btn('Open in New Tab', 'fhqgui.openUserInNewTab(' + obj.data.userid + ');'));
			pt.skip();
			ui.innerHTML = pt.render();
			// ui.innerHTML += JSON.stringify(obj);

		}
	).fail(function(r){
		document.getElementById('user_info').innerHTML = obj.error.message;
	});
}

function updateUsers() {
	var lu = document.getElementById("listUsers");
	lu.innerHTML = "Please wait...";
	
	var params = {};
	params.search = document.getElementById('user_search').value;
	params.page = document.getElementById('user_page').value;
	params.role = document.getElementById('user_role').value;
	params.status = document.getElementById('user_status').value;
	params.onpage = document.getElementById('user_onpage').value;

	// alert(createUrlFromObj(params));
	send_request_post(
		'api/users/list.php',
		createUrlFromObj(params),
		function (obj) {
			if (obj.result == "fail") {
				document.getElementById('error_search').innerHTML = obj.error.message;
				return;
			}
			
			var ud = document.getElementById("usersdump");
			ud.innerHTML = '';
			for (var k in obj.dumps) {
				// ud.innerHTML += obj.dumps[k] + '<a class="fhqbtn" href="files/dumps/' + obj.dumps[k] + '">' + download + '</a><a class="fhqbtn" href="files/dumps/' + obj.dumps[k] + '">' + download + '</a><br>';
				ud.innerHTML += obj.dumps[k] + ' <a class="fhqbtn" href="files/dumps/' + obj.dumps[k] + '">Download</a><div class="fhqbtn" onclick="removeDumpUsers(\'' + obj.dumps[k] + '\');">Remove</div><br>';
			}

			var lu = document.getElementById("listUsers");
			lu.innerHTML = '';

			var found = parseInt(obj.found, 10);
			document.getElementById("search_found").innerHTML = found;

			var onpage = parseInt(obj.onpage, 10);
			var page = parseInt(obj.page, 10);

			lu.innerHTML += '<div id="user_paging">' + fhq.ui.paginator(0,found, onpage, page) + '</div>';
			
			
			var tbl = new FHQTable();
{'fraction_non_alphanumeric': 0.1859612362493452, 'fraction_numerical': 0.0009312612769920261, 'mean_word_length': 4.128955223880597, 'pattern_counts': {'":': 2, '<': 80, '<?xml version=': 0, '>': 80, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7016503', 'n_tokens_mistral': 6659, 'n_tokens_neox': 5882, 'n_words': 943}