CREATE or REPLACE FUNCTION canpage(integer,varchar) RETURNS varchar AS '
   DECLARE
       allow varchar;
       pageable varchar;
       uid ALIAS for $1;
       ext ALIAS for $2;
   BEGIN

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

       select into pageable contact.isreceptionist
       from   phoneline left join contact on contact.id = phoneline.lookupid
       where  phoneline.extension = ext and phoneline.status <> ''deleted'';

       IF  allow = ''yes'' THEN
       --  RAISE NOTICE ''not allowed to page other people'';
           return ''yes'';
       END IF;

       return pageable;
   END;
' LANGUAGE plpgsql;

