anchor.diff:  		    ]
   	    end
       end.
  -    
  +
  +print_disabled(none, never) ->
  +    "disabled";
  +print_disabled({Forwards, 0, Localring}, always) ->
  +    "disabled";
  +print_disabled({Forwards, Timeout, Localring}, noanswer) when Timeout > 0 ->
  +    "disabled";
  +print_disabled(_, _) ->
  +    "".
  +
  +show_user_front(User, Numberlist) ->
  +    Printfunc = fun (Number) ->
  +			Forward = case database_forward:fetch(Number) of
  +				      {atomic, [F]} ->
  +					  F;
  +				      _ ->
  +					  none
  +				  end,
  +			[
  +			 "<h2>Vidarekoppling f&ouml;r ", Number, "</h2>\n",
  +			 "<h3>Nuvarande vidarekopplingsstatus</h3>\n",
  +			 "<table>",
  +			 "<tr>",
  +			 print_one_forward(Forward),
  +			 case Forward of
  +			     none ->
  +				 "";
  +			     _ ->
  +				 ["<td>",
  +				  "<form action=\"admin_www%3Ashow_user\" method=get>\n",
  +				  "<input type=\"hidden\" name=\"user\" value=\"",
  +				  User, "\">\n",
  +				  "<input type=\"hidden\" name=\"number\" value=\"",
  +				  Number, "\">\n",
  +				  "<input type=\"hidden\" name=\"type\" value=\"",
  +				  "change", "\">\n",
  +				  "<input type=\"submit\" value=\"&Auml;ndra\">\n",
  +				  "</form>\n",
  +				  "</td>"]
  +			 end,
  +			 "</tr>",
  +			 "</table>",
  +			 "<h3>&Auml;ndra vidarekopplingstyp</h3>",
  +			 "<table><tr><td>",
  +			 "<form action=\"admin_www%3Ashow_user\" method=get>\n",
  +			 "<input type=\"hidden\" name=\"user\" value=\"",
  +			 User, "\">\n",
  +			 "<input type=\"hidden\" name=\"number\" value=\"",
  +			 Number, "\">\n",
  +			 "<input type=\"hidden\" name=\"type\" value=\"",
  +			 "never", "\">\n",
  +			 "<input ",
  +			 print_disabled(Forward, never),
  +			 " type=\"submit\" value=\"Vidarekoppla aldrig\">\n",
  +			 "</form>\n",
  +			 "</td><td>",
  +			 "<form action=\"admin_www%3Ashow_user\" method=get>\n",
  +			 "<input type=\"hidden\" name=\"user\" value=\"",
  +			 User, "\">\n",
  +			 "<input type=\"hidden\" name=\"number\" value=\"",
  +			 Number, "\">\n",
  +			 "<input type=\"hidden\" name=\"type\" value=\"",
  +			 "always", "\">\n",
  +			 "<input ",
  +			 print_disabled(Forward, always),
  +			 " type=\"submit\" value=\"Vidarekoppla alltid\">\n",
  +			 "</form>\n",
  +			 "</td><td>",
  +			 "<form action=\"admin_www%3Ashow_user\" method=get>\n",
  +			 "<input type=\"hidden\" name=\"user\" value=\"",
  +			 User, "\">\n",
  +			 "<input type=\"hidden\" name=\"number\" value=\"",
  +			 Number, "\">\n",
  +			 "<input type=\"hidden\" name=\"type\" value=\"",
  +			 "noanswer", "\">\n",
  +			 "<input ",
  +			 print_disabled(Forward, noanswer),
  +			 " type=\"submit\" value=\"Vidarekoppla vid ej svar\">\n",
  +			 "</form>\n"
  +			 "</td></tr></table>"
  +			]
  +		end,
  +    [
  +     header(ok),
  +     "<h1>", username_to_cn(User), "(", User, ")", "</h1>\n",
  +     lists:map(Printfunc, Numberlist),
  +     indexurl_html()
  +    ].
  +
  +forward_to_typestring(none) ->
  +    "never";
  +forward_to_typestring({Forwards, 0, Localring}) ->
  +    "always";
  +forward_to_typestring({Forwards, _, Localring}) ->
  +    "noanswer".
  +
  +show_user_number(User, Number, "never") ->
  +    [
  +     header(ok),
  +     "<h1>", username_to_cn(User), "(", User, ")", "</h1>\n",
  +     "<h2>Byt vidarekopplingstyp f&ouml;r ", Number, "</h2>\n",
  +     "Byt till vidarekoppla aldrig<br>",
  +
  +     "<form action=\"admin_www%3Aset_forward\" method=post>\n",
  +     "<input type=\"hidden\" name=\"user\" value=\"",
  +     User, "\">\n",
  +     "<input type=\"hidden\" name=\"number\" value=\"",
  +     Number, "\">\n",
  +     "<input type=\"hidden\" name=\"type\" value=\"",
  +     "never", "\">\n",
  +     "<input type=\"submit\" value=\"OK\">\n",
  +     "</form>\n",
  +     "<form action=\"admin_www%3Ashow_user\" method=post>\n",
  +     "<input type=\"hidden\" name=\"user\" value=\"",
  +     User, "\">\n",
  +     "<input type=\"submit\" value=\"Avbryt\">\n",
  +     "</form>\n",
  +     indexurl_html()
  +    ];
  +
  +show_user_number(User, Number, InType) ->
  +    Forward = case database_forward:fetch(Number) of
  +		  {atomic, [F]} ->
  +		      F;
  +		  _ ->
  +		      none
  +	      end,
  +    {Forwards, Timeout, Localring} = case Forward of
  +					 none ->
  +					     {[""], 20, false};
  +					 _ ->
  +					     Forward
  +				     end,
  +    Type = case InType of
  +	       "change" ->
  +		   forward_to_typestring(Forward);
  +	       _ ->
  +		   InType
  +	   end,
  +    [
  +     header(ok),
  +     "<h1>", username_to_cn(User), "(", User, ")", "</h1>\n",
  +     case InType of
  +	 "change" ->
  +	     ["<h2>&Auml;ndra vidarekoppling f&ouml;r ", Number, "</h2>\n"];
  +	 _ ->
  +	     ["<h2>Byt vidarekopplingstyp f&ouml;r ", Number, "</h2>\n"]
  +     end,
  +
  +     "<form action=\"admin_www%3Aset_forward\" method=post>\n",
  +     "Vidarekoppla till ",
  +     "<input type=\"text\" name=\"forwardnumber\" value=\"",
  +     hd(Forwards),
  +     "\">",
  +     case Type of
  +	 "noanswer" ->
  +	     T = case InType of
  +		     "change" ->
  +			 integer_to_list(Timeout);
  +		     _ ->
  +			 "20"
  +		 end,
  +	     [
  +	      "<br>efter <input type=\"text\" name=\"timeout\" value=\"",
  +	      T,
  +	      "\"> sekunder"
  +	     ];
  +	 _ ->
  +	     ""
  +     end,
  +     "<br>\n",
  +     case Type of
  +	 "noanswer" ->
  +	     "Forts&auml;tt ring p&aring; min vanliga telefon ";
  +	 "always" ->
  +	     "Ring ocks&aring; p&aring; min vanliga telefon "
  +     end,
  +     "<input type=\"checkbox\" name=\"localring\"",
  +     case Localring of
  +	 true ->
  +	     "checked ";
  +	 _ ->
  +	     ""
  +     end,
  +     "value=\"true\"><br>\n",
  +     "<br>\n",
  +     "<input type=\"hidden\" name=\"user\" value=\"",
  +     User, "\">\n",
  +     "<input type=\"hidden\" name=\"number\" value=\"",
  +     Number, "\">\n",
  +     "<input type=\"hidden\" name=\"type\" value=\"",
  +     Type, "\">\n",
  +     "<input type=\"submit\" value=\"OK\">\n",
  +     "</form>\n",
  +     "<form action=\"admin_www%3Ashow_user\" method=post>\n",
  +     "<input type=\"hidden\" name=\"user\" value=\"",
  +     User, "\">\n",
  +     "<input type=\"submit\" value=\"Avbryt\">\n",
  +     "</form>\n",
  +     indexurl_html()
  +    ].
  +
  +httparg(Env, Input) ->
  +    case lists:keysearch(request_method, 1, Env) of
  +	{value, {_, "GET"}} ->
  +	    case lists:keysearch(query_string, 1, Env) of
  +		{value, {_, Query}} ->
  +		    sipheader:httparg(Query)
  +	    end;
  +	{value, {Key, "POST"}} ->
  +	    sipheader:httparg(Input)
  +    end.
  +
  +show_user(Env, Input) ->
  +    Args = httparg(Env, Input),
  +    {ok, User} = dict:find("user", Args),
  +
  +    case check_auth_user(Env, User) of
  +	{error, Message} ->
  +	    Message;
  +	{ok} ->
  +	    {Password, Flags, Classes} = get_pass(User),
  +	    Numberlist = get_numbers(User),
  +	    case dict:find("number", Args) of
  +		error ->
  +		    show_user_front(User, Numberlist);
  +		{ok, Number} ->
  +		    case lists:member(Number, Numberlist) of
  +			false ->
  +			    [header(ok),
  +			     "<h1>Not allowed to change number</h1>"
  +			    ];
  +			_ ->
  +			    {ok, Type} = dict:find("type", Args),
  +			    show_user_number(User, Number, Type)
  +		    end
  +	    end
  +    end.
  +
  +set_forward_type(Number, "never", _, _, _) ->
  +    database_forward:delete(Number);
  +set_forward_type(Number, "always", Forwards, _, Localring) ->
  +    database_forward:insert(Number, Forwards, 0, Localring);
  +set_forward_type(Number, "noanswer", Forwards, Timeout, Localring) ->
  +    database_forward:insert(Number, Forwards, Timeout, Localring).
  +
  +dict_find(Key, Dict, Default) ->
  +    case dict:find(Key, Dict) of
  +	{ok, Value} ->
  +	    Value;
  +	_ ->
  +	    Default
  +    end.
  +
  +set_forward(Env, Input) ->
  +    Args = httparg(Env, Input),
  +    {ok, User} = dict:find("user", Args),
  +    {ok, Number} = dict:find("number", Args),
  +    {ok, Type} = dict:find("type", Args),
  +
  +    case check_auth_user(Env, User) of
  +	{error, Message} ->
  +	    Message;
  +	{ok} ->
  +	    {Password, Flags, Classes} = get_pass(User),
  +	    
  +	    Numberlist = get_numbers(User),
  +	    
  +	    true = lists:member(Number, Numberlist),
  +	    
  +	    Forwards = [dict_find("forwardnumber", Args, "")],
  +	    TimeoutText = dict_find("timeout", Args, "20"),
  +	    Timeout = case util:isnumeric(TimeoutText) of
  +			  true ->
  +			      list_to_integer(TimeoutText);
  +			  _ ->
  +			      20
  +		      end,
  +	    Localring = list_to_atom(dict_find("localring", Args, "false")),
  +	    
  +	    set_forward_type(Number, Type, Forwards, Timeout, Localring),
  +	    header(redirect, showuserurl() ++ "?user=" ++ User)
  +    end.
  +
   set_admin(User, "true") ->
       {Password, Flags, Classes} = get_pass(User),
       case lists:member(admin, Flags) of
  
positive.code: 		    ]};
  	{value, {Key, Value}} ->
  	    case check_auth2(Value, Env, WantAdmin) of
  		true ->
  		    {ok};
  		false ->
  
negative.code:      end,
       "</td></tr>\n"].
  
  print_one_forward({Forwards, Timeout, Localring}) ->
      Printfunc = fun (Number) ->
  			[
  			 "<tr><td>",
  			 Number,
  			 "</td></tr>"
  			]
  		end,
      ["<td>",
       case Timeout of
  	 0 ->
  	     "Vidarekoppla alltid till ";
  	 _ ->
  	     ["Vidarekoppla efter ", integer_to_list(Timeout), " sekunder till "]
       end,
       "</td><td>",
       "<table>",
       lists:map(Printfunc, Forwards),
       "</table>",
       "</td><td>",
       case Localring of
  	 true ->
  	     "Ring ocks&aring; p&aring; den egna telefonen ";
  	 _ ->
  	     ""
       end,
       "</td>\n"
      ];
  print_one_forward(none) ->
      ["<td>",
       "Vidarekoppla aldrig"
       "</td>\n"
      ].
  
  print_phones([]) -> [];
  
  print_phones([{regexproute, Regexp, Flags, Class, Expire, Address} | List]) ->
  