-- return 'yes' if I am allowed to dial *60 to bypass callforward settings
CREATE or REPLACE FUNCTION allow_bypass_forward(integer,varchar) RETURNS varchar AS '
   DECLARE
       allow varchar;
       bypassable varchar;
       uid ALIAS for $1;
       ext ALIAS for $2;
   BEGIN

       select into allow contact.allow_bypass_forward
       from   contact where id = uid;

       select into bypassable phoneline.bypassable_forward
       from   phoneline
       where  phoneline.extension = ext and phoneline.status <> ''deleted'';

       IF  allow = ''no'' THEN
       --  RAISE NOTICE ''not allowed to bypass other peoples callforward settings'';
           return ''no'';
       END IF;

       return bypassable;
   END;
' LANGUAGE plpgsql;

