sub reg_reviewer
{
    my $sock = shift( @_ );
    my $R_name = shift( @_ );
    my $R_login = shift( @_ );
    my $R_affiliation = shift( @_ );
    my $R_country = shift( @_ );
    my $R_email = shift( @_ );
    my $R_address = shift( @_ );
    my $R_phone = shift( @_ );
    my $R_fax = shift( @_ );
    my $R_url = shift( @_ );
    my $R_category = shift( @_ );
    my $R_keywords = shift( @_ );

    my $R_id_sth = $sock->prepare( "select id ".
				  "from reviewer where login='$R_login'" )
	|| die( "ERROR: ".$sock->errstr );
    $R_id_sth->execute() || die( "ERROR: ".$sock->errstr );

    if( !$R_id_sth->rows() )
    {
	$R_id_sth->finish();
	my $R_id = get_sequence( $sock, 'reviewer' );

	my $R_code_sth = $sock->prepare( "SELECT id FROM reviewer WHERE code=?" );
	my $R_code = 0;
	while( !$R_code )
	{
	    $R_code = int( rand( 1000 ) );
	    $R_code_sth->execute( int( $R_code ) ) 
		|| CgiDie( "ERROR: ".$sock->errstr );
	    $R_code = 0 if( $R_code_sth->rows() );
	}

	my $insert_sth = $sock->prepare( "INSERT INTO reviewer (id, code, ".
					"name, login, ".
					"affiliation, address, country, ".
					"email, phone, fax, url, ".
					"category, keywords ) ".
					"VALUES (".
					$R_id.", ".
					$R_code.", ".
					"'".tomsql( $R_name )."', ".
					"'$R_login', ".
					"'".tomsql( $R_affiliation )."', ".
					"'".tomsql( $R_address )."', ".
					"'".tomsql( $R_country )."', ".
					"'$R_email', ".
					"'".tomsql( $R_phone )."', ".
					"'".tomsql( $R_fax )."', ".
					"'".tomsql( $R_url )."', ".
					( $R_category ? 
					  "'$R_category'" : 'NULL' ).", ".
					"'".tomsql( $R_keywords )."' ) " );
	$insert_sth->execute() || CgiDie( "ERROR: ".$sock->errstr );
    }
    else
    {
	my $R_id = ( $R_id_sth->fetchrow() )[0];
	my $update_sth = $sock->prepare( "update reviewer set ".
					"name='".tomsql( $R_name )."', ".
					"affiliation='".tomsql( $R_affiliation )."', ".
					"address='".tomsql( $R_address )."', ".
					"country='".tomsql( $R_country )."', ".
					"email='$R_email', ".
					"phone='".tomsql( $R_phone )."', ".
					"fax='".tomsql( $R_fax )."', ".
					"url='".tomsql( $R_url )."', ".
					"category=".
					 ( $R_category ? 
					   "'$R_category'" : 'NULL' ).", ".
					 "keywords='".tomsql( $R_keywords )."' ".
					"where id=$R_id " );
	$update_sth->execute() || CgiDie( "ERROR: ".$sock->errstr );
    }
}

1;
