#!/usr/bin/php -q
<?php

require_once('forum_upload.ini');
require_once('script_functions.ini');

// -------------------------------------------------------------------------
// defaults and definitions
//

$progname = basename($argv[0]);

$stdin = fopen("php://stdin", "w");
$stderr = fopen("php://stderr", "w");

// -------------------------------------------------------------------------
// functions
//

function error_clean_up() {

	global $stderr;
	global $progname;

	fwrite($stderr, "$progname: bailing out\n");

	return;

} // end error_clean_up()

// -------------------------------------------------------------------------
// command line stuff
//

if ($argc == 1) {
?>

usage: <?php echo $progname; ?> <posted by external name> <user ID>

Changes and external user to a registered user.

<?php
	exit(1);
}

if ($argc < 3) {
	command_line_error("too few arguments");
	exit(1);
}

if ($argc > 3) {
	command_line_error("too many arguments");
	exit(1);
}

$external_name = $argv[1];

if (!check_int($argv[2])) {
	command_line_error("bad user ID \"" . $argv[2] . "\"");
	exit(1);
}

$user_id = intval($argv[2]);

// -------------------------------------------------------------------------
// get information about the upload
//

forum_init();

$n_updated = activate_user($external_name, $user_id);

print "$n_updated messages updated\n";

// -------------------------------------------------------------------------
// clean up and exit
//

forum_close();

exit(0);

?>
