-- return 'yes' if I am allowed to enter the conference box as administrator
-- get user id, conference extension
CREATE or REPLACE FUNCTION confadmin(integer,varchar) RETURNS varchar AS '
   DECLARE
       uid ALIAS for $1;
       ext ALIAS for $2;
       allow varchar;

   BEGIN
       select into allow ''yes''
       from   conference, phoneline, contact_department
       where  phoneline.extension = ext and
              conference.phoneline = phoneline.id and
              conference.department = contact_department.department and
              contact_department.contact = uid;

       IF  allow = ''yes'' THEN
           return ''yes'';
       END IF;

       return ''no'';
   END;
' LANGUAGE plpgsql;

