<commit_before><?
	# $Id: watch-list-maintenance.php,v 1.1.2.19 2002-12-18 17:55:24 dan Exp $
	#
	# Copyright (c) 1998-2001 DVL Software Limited
	#

	require_once($_SERVER['DOCUMENT_ROOT'] . '/include/common.php');
	require_once($_SERVER['DOCUMENT_ROOT'] . '/include/freshports.php');
	require_once($_SERVER['DOCUMENT_ROOT'] . '/include/databaselogin.php');
	require_once($_SERVER['DOCUMENT_ROOT'] . '/include/getvalues.php');
	require_once($_SERVER['DOCUMENT_ROOT'] . '/include/watch-lists.php');

$visitor = $_COOKIE['visitor'];

unset($add_name);
unset($rename_name);

$ValidCharacters = 'a-z, A-Z, and 0-9';

$WatchListNameMessage = 'Watch list names must contain only A..Z, a..z, or 0..9.';

// if we don't know who they are, we'll make sure they login first
if (!$visitor) {
        header('Location: login.php?origin=' . $_SERVER['PHP_SELF']);  /* Redirect browser to PHP web site */
        exit;  /* Make sure that code below does not get executed when we redirect. */
}

	require_once($_SERVER['DOCUMENT_ROOT'] . '/../classes/watch_lists.php');
	require_once($_SERVER['DOCUMENT_ROOT'] . '/../classes/user.php');

	freshports_Start('Watch list maintenance',
					'freshports - new ports, applications',
					'FreeBSD, index, applications, ports');
					
#phpinfo();
$Debug = 0;

$ConfirmationNeeded{'delete'}     = 1;
$ConfirmationNeeded{'delete_all'} = 1;
$ConfirmationNeeded{'empty'}      = 1;
$ConfirmationNeeded{'empty_all'}  = 1;

$UserClickedOn = '';
$ErrorMessage  = '';

if ($_POST['delete']) {
	$UserClickedOn = 'delete';
}

if ($_POST['delete_all']) {
	$UserClickedOn = 'delete_all';
}

if ($_POST['empty']) {
	$UserClickedOn = 'empty';
}

if ($_POST['empty_all']) {
	$UserClickedOn = 'empty_all';
}

if ($_POST['add']) {
	$UserClickedOn = 'add';
}

if ($_POST['rename']) {
	$UserClickedOn = 'rename';
}

if ($_POST['set_default']) {
	$UserClickedOn = 'set_default';
}

if ($_POST['set_options']) {
	$UserClickedOn = 'set_options';
}

#
# Error checking
#
if ($UserClickedOn) {
	if ($ConfirmationNeeded{$UserClickedOn}) {
		if ($_POST['confirm'] != $_POST[$UserClickedOn]) {
			$ErrorMessage = 'You did not supply the confirmation text';
		}
	}

	if ($ErrorMessage == '') {
		switch ($UserClickedOn) {
			case 'add':
				if (AddSlashes($_POST['add_name']) == '') {
					$ErrorMessage = 'When creating a new list, you must supply a name.';
				}
				if (preg_match("/[^a-zA-Z0-9]/", $_POST['add_name'])) {
					$ErrorMessage = $WatchListNameMessage;
					$add_name     = $_POST['add_name'];
				}
				break;

			case 'rename':
				if (AddSlashes($_POST['rename_name']) == '') {
					$ErrorMessage = 'When renaming an existing list, you must supply a name.';
				}
				if (preg_match("/[^a-zA-Z0-9]/", $_POST['rename_name'])) {
					$ErrorMessage = $WatchListNameMessage;
					$rename_name  = $_POST['rename_name'];
				}
				break;
		}
	}
	
}

if ($UserClickedOn != '' && $ErrorMessage == '') {
	if ($Debug) echo "you clicked on = '$UserClickedOn'<br>";
	if ($Debug) echo "your confirmation text = '" . AddSlashes($_POST['confirm']) . "'<br>";

	# all went well, so let us do what they told us to do
	switch ($UserClickedOn) {
		case 'add':
			$WatchList = new WatchList($db);
			$NewWatchListID = $WatchList->Create($User->id, AddSlashes($_POST['add_name']));
			if ($Debug) echo 'I just created \'' . AddSlashes($_POST['add_name']) . '\' with ID = \'' . $NewWatchListID . '\'';
			break;

		case 'rename':
			# check valid new name
			# check only one watch list supplied
			if (count($_POST['wlid']) == 1) {
				list($key, $WatchListIDToRename) = each($_POST['wlid']);
				$WatchList = new WatchList($db);
				$NewName = $WatchList->Rename($User->id, $WatchListIDToRename, $_POST['rename_name']);
				if ($Debug) echo 'I have renamed your list to \'' . AddSlashes($_POST['rename_name']) . '\'';
			} else {
				$ErrorMessage = 'Select exactly one watch list to be renamed.  I can\'t handle zero or more than one.';
			}
			break;

		case 'delete_all':
		case 'delete':
			pg_query($db, 'BEGIN');
			$WatchList = new WatchList($db);
			while (list($key, $WatchListIDToDelete) = each($_POST['wlid'])) {
				if ($Debug) echo "\$key='$key' \$WatchListIDToDelete='$WatchListIDToDelete'<br>";
				$DeletedWatchListID = $WatchList->Delete($User->id, AddSlashes($WatchListIDToDelete));
				if ($DeletedWatchListID != $WatchListIDToDelete) {
					die("Failed to deleted '$WatchListIDToDelete' (return value '$DeletedWatchListID')" . pg_last_error());
				}
				if ($Debug) echo 'I have deleted watch list id = ' . $WatchListIDToDelete . '<br>';
			}
			pg_query($db, 'COMMIT');
			
			break;

		case 'empty':
		case 'empty_all':
			pg_query($db, 'BEGIN');
			$WatchList = new WatchList($db);
			while (list($key, $WatchListIDToEmpty) = each($_POST['wlid'])) {
				if ($Debug) echo "\$key='$key' \$WatchListIDToEmpty='$WatchListIDToEmpty'<br>";
				$EmptydWatchListID = $WatchList->EmptyTheList($User->id, AddSlashes($WatchListIDToEmpty));<commit_msg>Correctly delete all the lists when asked to do so.<commit_after><?
	# $Id: watch-list-maintenance.php,v 1.1.2.20 2003-01-04 17:11:44 dan Exp $
	#
	# Copyright (c) 1998-2001 DVL Software Limited
	#

	require_once($_SERVER['DOCUMENT_ROOT'] . '/include/common.php');
	require_once($_SERVER['DOCUMENT_ROOT'] . '/include/freshports.php');
	require_once($_SERVER['DOCUMENT_ROOT'] . '/include/databaselogin.php');
	require_once($_SERVER['DOCUMENT_ROOT'] . '/include/getvalues.php');
	require_once($_SERVER['DOCUMENT_ROOT'] . '/include/watch-lists.php');

$visitor = $_COOKIE['visitor'];

unset($add_name);
unset($rename_name);

$ValidCharacters = 'a-z, A-Z, and 0-9';

$WatchListNameMessage = 'Watch list names must contain only A..Z, a..z, or 0..9.';

// if we don't know who they are, we'll make sure they login first
if (!$visitor) {
        header('Location: login.php?origin=' . $_SERVER['PHP_SELF']);  /* Redirect browser to PHP web site */
        exit;  /* Make sure that code below does not get executed when we redirect. */
}

	require_once($_SERVER['DOCUMENT_ROOT'] . '/../classes/watch_lists.php');
	require_once($_SERVER['DOCUMENT_ROOT'] . '/../classes/user.php');

	freshports_Start('Watch list maintenance',
					'freshports - new ports, applications',
					'FreeBSD, index, applications, ports');
					
#phpinfo();
$Debug = 0;

$ConfirmationNeeded{'delete'}     = 1;
$ConfirmationNeeded{'delete_all'} = 1;
$ConfirmationNeeded{'empty'}      = 1;
$ConfirmationNeeded{'empty_all'}  = 1;

$UserClickedOn = '';
$ErrorMessage  = '';

if ($_POST['delete']) {
	$UserClickedOn = 'delete';
}

if ($_POST['delete_all']) {
	$UserClickedOn = 'delete_all';
}

if ($_POST['empty']) {
	$UserClickedOn = 'empty';
}

if ($_POST['empty_all']) {
	$UserClickedOn = 'empty_all';
}

if ($_POST['add']) {
	$UserClickedOn = 'add';
}

if ($_POST['rename']) {
	$UserClickedOn = 'rename';
}

if ($_POST['set_default']) {
	$UserClickedOn = 'set_default';
}

if ($_POST['set_options']) {
	$UserClickedOn = 'set_options';
}

#
# Error checking
#
if ($UserClickedOn) {
	if ($ConfirmationNeeded{$UserClickedOn}) {
		if ($_POST['confirm'] != $_POST[$UserClickedOn]) {
			$ErrorMessage = 'You did not supply the confirmation text';
		}
	}

	if ($ErrorMessage == '') {
		switch ($UserClickedOn) {
			case 'add':
				if (AddSlashes($_POST['add_name']) == '') {
					$ErrorMessage = 'When creating a new list, you must supply a name.';
				}
				if (preg_match("/[^a-zA-Z0-9]/", $_POST['add_name'])) {
					$ErrorMessage = $WatchListNameMessage;
					$add_name     = $_POST['add_name'];
				}
				break;

			case 'rename':
				if (AddSlashes($_POST['rename_name']) == '') {
					$ErrorMessage = 'When renaming an existing list, you must supply a name.';
				}
				if (preg_match("/[^a-zA-Z0-9]/", $_POST['rename_name'])) {
					$ErrorMessage = $WatchListNameMessage;
					$rename_name  = $_POST['rename_name'];
				}
				break;
		}
	}
	
}

if ($UserClickedOn != '' && $ErrorMessage == '') {
	if ($Debug) echo "you clicked on = '$UserClickedOn'<br>";
	if ($Debug) echo "your confirmation text = '" . AddSlashes($_POST['confirm']) . "'<br>";

	# all went well, so let us do what they told us to do
	switch ($UserClickedOn) {
		case 'add':
			$WatchList = new WatchList($db);
			$NewWatchListID = $WatchList->Create($User->id, AddSlashes($_POST['add_name']));
			if ($Debug) echo 'I just created \'' . AddSlashes($_POST['add_name']) . '\' with ID = \'' . $NewWatchListID . '\'';
			break;

		case 'rename':
			# check valid new name
			# check only one watch list supplied
			if (count($_POST['wlid']) == 1) {
				list($key, $WatchListIDToRename) = each($_POST['wlid']);
				$WatchList = new WatchList($db);
				$NewName = $WatchList->Rename($User->id, $WatchListIDToRename, $_POST['rename_name']);
				if ($Debug) echo 'I have renamed your list to \'' . AddSlashes($_POST['rename_name']) . '\'';
			} else {
				$ErrorMessage = 'Select exactly one watch list to be renamed.  I can\'t handle zero or more than one.';
			}
			break;

		case 'delete':
			pg_query($db, 'BEGIN');
			$WatchList = new WatchList($db);
			while (list($key, $WatchListIDToDelete) = each($_POST['wlid'])) {
				if ($Debug) echo "\$key='$key' \$WatchListIDToDelete='$WatchListIDToDelete'<br>";
				$DeletedWatchListID = $WatchList->Delete($User->id, AddSlashes($WatchListIDToDelete));
				if ($DeletedWatchListID != $WatchListIDToDelete) {
					die("Failed to deleted '$WatchListIDToDelete' (return value '$DeletedWatchListID')" . pg_last_error());
				}
				if ($Debug) echo 'I have deleted watch list id = ' . $WatchListIDToDelete . '<br>';
			}
			pg_query($db, 'COMMIT');
			break;
			
		case 'delete_all':
			pg_query($db, 'BEGIN');
			$WatchLists = new WatchLists($db);
			if ($WatchLists->DeleteAllLists($User->id) == 1) {
				pg_query($db, 'COMMIT');
			} else {
				pg_query($db, 'ROLLBACK');
			}
			break;

		case 'empty':
		case 'empty_all':
			pg_query($db, 'BEGIN');
			$WatchList = new WatchList($db);
			while (list($key, $WatchListIDToEmpty) = each($_POST['wlid'])) {
				if ($Debug) echo "\$key='$key' \$WatchListIDToEmpty='$WatchListIDToEmpty'<br>";
				$EmptydWatchListID = $WatchList->EmptyTheList($User->id, AddSlashes($WatchListIDToEmpty));
{'fraction_non_alphanumeric': 0.18971282454760033, 'fraction_numerical': 0.008162863886703384, 'mean_word_length': 4.159309994926433, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4224567', 'n_tokens_mistral': 4001, 'n_tokens_neox': 3579, 'n_words': 784}