<?php

	include_once("common.php");
	
	head("New Annotator");
	
	if ($annotator_registered[$_POST["NEW_ANNOTATOR"]]) {
		print "An annotator with the name \"".$_POST["NEW_ANNOTATOR"]."\" already exists, please try again.";
	}
	else if  (!ereg("^[A-Za-z0-9]", $_POST['NEW_ANNOTATOR'])) {
		print("Invalid characters in username, please try again using only numbers and letters.");
	}
	else if (! $_POST["NEW_PWD"]) {
		print "No password entered, please go back.";
	}
	else {
		$email = $_POST["EMAIL"];
		if ($email == "") { $email = "none"; }
		$conflict = "";
		if($_POST["CONFLICT"]) {
			$conflict = join(" ",$_POST["CONFLICT"]);
		}
		if ($conflict == "") { $conflict = "none"; }
		
		$languages = array();
		while (list($key, $value) = each($_POST)) {
			if (preg_match("/LANGUAGE_(.+)/",$key,$reg)) {
				$languages[] = $reg[1];
			}
		}
		if (sizeof($languages) == 0) {
			print "No languages selected, please go back.";
		} else {
			$lang_string = join(" ",$languages);
			$f = fopen(get_annotators_file(),"a");
			fputs($f,strip_tags($_POST["NEW_ANNOTATOR"])." ||| ".md5(strip_tags($_POST["NEW_PWD"]))." ||| $email ||| $conflict ||| $lang_string \n");
			fclose($f);
			?>
			Name and password registered. <A HREF="index.php">Please login</A>.
			<?php
		}
	}
	
	tail();

?>
