anchor.diff:  
   
   %% @doc Check if the current user/browser did the survey
  +%% @private
   did_survey(SurveyId, Context) ->
       case z_acl:user(Context) of
           undefined ->
  
positive.code: survey_stats(SurveyId, Context) ->
      Rows = z_db:q("
                  select question, name, value, count(*) 
                  from survey_answer 
                  where survey_id = $1 and value is not null
                  group by question, name, value 
                  order by question, name, value", [SurveyId], Context),
      group_questions(Rows, []).
      
      group_questions([], Acc) ->
          lists:reverse(Acc);
      group_questions([{Question,_,_,_}|_] = Answers, Acc) ->
          {Qs,Answers1} = lists:splitwith(fun({Q,_,_,_}) -> Q == Question end, Answers),
          NVs = case Qs of
              [{_, Name, Value, Count}|QsTail] -> group_values(Name, [{Value, Count}], QsTail, []);
              [] -> []
          end,
          group_questions(Answers1, [{Question,NVs}|Acc]).
          
      group_values(Name, Values, [], Acc) ->
          [{Name, Values}|Acc];
      group_values(Name, Values, [{_,Name,V,C}|Rs], Acc) ->
          group_values(Name, [{V,C}|Values], Rs, Acc);
      group_values(Name, Values, [{_,N,V,C}|Rs], Acc) ->
          group_values(N, [{V,C}], Rs, [{Name,Values}|Acc]).
  
  
  survey_results_sorted(SurveyId, SortColumn, Context) ->
      [Headers|Data] = survey_results(SurveyId, Context),
      case string:str(Headers, [list_to_binary(SortColumn)]) of
  
negative.code:                 Rows).
  
  
  %% @doc Delete a survey result for a user or persistent id.
  delete_result(SurveyId, UserId, PersistentId, Context) ->
      {Clause, Args} = case z_utils:is_empty(UserId) of
                           true -> {"persistent = $1", [PersistentId]};
  