Index: openacs-4/packages/dotlrn/sql/postgresql/privacy-package-create.sql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/dotlrn/sql/postgresql/privacy-package-create.sql,v
diff -u -r1.2 -r1.3
--- openacs-4/packages/dotlrn/sql/postgresql/privacy-package-create.sql	20 Apr 2004 21:13:17 -0000	1.2
+++ openacs-4/packages/dotlrn/sql/postgresql/privacy-package-create.sql	1 Nov 2013 21:08:29 -0000	1.3
@@ -9,115 +9,145 @@
 -- provides extra checking to a simple view query, since Guest status is not
 -- yet used uniformly across OACS.
 --
-create or replace function dotlrn_privacy__guest_p (integer)
-returns char as '
-declare
-  v_user_id alias for $1;
+
+
+--
+-- procedure dotlrn_privacy__guest_p/1
+--
+CREATE OR REPLACE FUNCTION dotlrn_privacy__guest_p(
+   p_user_id integer
+) RETURNS char AS $$
+DECLARE
   v_count integer;
   v_guest_p char(1);
-begin
-  select count(*) into v_count from dotlrn_guest_status where user_id = v_user_id;
+BEGIN
+  select count(*) into v_count from dotlrn_guest_status where user_id = p_user_id;
   if v_count > 1 then
-    raise EXCEPTION ''-20000: Guest status is multiply defined for user %'', v_user_id;
+    raise EXCEPTION '-20000: Guest status is multiply defined for user %', p_user_id;
   end if;
   if v_count = 0 then
-    raise EXCEPTION ''-20000: Guest status is not defined for user %'', v_user_id;
+    raise EXCEPTION '-20000: Guest status is not defined for user %', p_user_id;
   end if;
-  select guest_p into v_guest_p from dotlrn_guest_status where user_id = v_user_id;
+  select guest_p into v_guest_p from dotlrn_guest_status where user_id = p_user_id;
   return v_guest_p;
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
 
-create or replace function dotlrn_privacy__set_user_non_guest (integer)
-returns integer as '
-declare
-  v_user_id alias for $1;
+
+
+--
+-- procedure dotlrn_privacy__set_user_non_guest/1
+--
+CREATE OR REPLACE FUNCTION dotlrn_privacy__set_user_non_guest(
+   p_user_id integer
+) RETURNS integer AS $$
+DECLARE
   v_rel_id integer;
   cur record;
-begin
+BEGIN
   for cur in
     select r.rel_id 
       from acs_rels r, 
            membership_rels m 
       where m.rel_id = r.rel_id 
-        and (r.rel_type = ''dotlrn_guest_rel''
-             or r.rel_type = ''dotlrn_non_guest_rel'')
-        and r.object_id_one = acs__magic_object_id(''registered_users'')
-        and r.object_id_two = v_user_id
+        and (r.rel_type = 'dotlrn_guest_rel'
+             or r.rel_type = 'dotlrn_non_guest_rel')
+        and r.object_id_one = acs__magic_object_id('registered_users')
+        and r.object_id_two = p_user_id
   loop 
     perform membership_rel__delete(cur.rel_id);
   end loop;
   v_rel_id := membership_rel__new(
     null,
-    ''dotlrn_non_guest_rel'',
-    acs__magic_object_id(''registered_users''),
-    v_user_id,
-    ''approved'',
+    'dotlrn_non_guest_rel',
+    acs__magic_object_id('registered_users'),
+    p_user_id,
+    'approved',
     null,
     null
   );
 
   return 0;
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
 
-create or replace function dotlrn_privacy__set_user_guest (integer)
-returns integer as '
-declare
-  v_user_id alias for $1;
+
+
+--
+-- procedure dotlrn_privacy__set_user_guest/1
+--
+CREATE OR REPLACE FUNCTION dotlrn_privacy__set_user_guest(
+   p_user_id integer
+) RETURNS integer AS $$
+DECLARE
   v_rel_id integer;
   cur record;
-begin
+BEGIN
   for cur in
     select r.rel_id 
       from acs_rels r, 
            membership_rels m 
       where m.rel_id = r.rel_id 
-        and (r.rel_type = ''dotlrn_guest_rel''
-             or r.rel_type = ''dotlrn_non_guest_rel'')
-        and r.object_id_one = acs__magic_object_id(''registered_users'')
-        and r.object_id_two = v_user_id
+        and (r.rel_type = 'dotlrn_guest_rel'
+             or r.rel_type = 'dotlrn_non_guest_rel')
+        and r.object_id_one = acs__magic_object_id('registered_users')
+        and r.object_id_two = p_user_id
   loop 
     perform membership_rel__delete(cur.rel_id);
   end loop;
   v_rel_id := membership_rel__new(
     null,
-    ''dotlrn_guest_rel'',
-    acs__magic_object_id(''registered_users''),
-    v_user_id,
-    ''approved'',
+    'dotlrn_guest_rel',
+    acs__magic_object_id('registered_users'),
+    p_user_id,
+    'approved',
     null,
     null
   );
 
   return 0;
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
 
-create or replace function dotlrn_privacy__grant_rd_prv_dt_to_rel (integer,varchar)
-returns integer as '
-declare
-  v_object_id alias for $1;
-  v_rel_type alias for $2;
+
+
+--
+-- procedure dotlrn_privacy__grant_rd_prv_dt_to_rel/2
+--
+CREATE OR REPLACE FUNCTION dotlrn_privacy__grant_rd_prv_dt_to_rel(
+   v_object_id integer,
+   v_rel_type varchar
+) RETURNS integer AS $$
+DECLARE
   v_segment_id integer;
-begin
+BEGIN
   select segment_id into v_segment_id
   from rel_segments
-  where group_id = acs__magic_object_id(''registered_users'')
+  where group_id = acs__magic_object_id('registered_users')
     and rel_type = v_rel_type;
-  perform acs_permission__grant_permission(v_object_id,v_segment_id,''read_private_data'');
+  perform acs_permission__grant_permission(v_object_id,v_segment_id,'read_private_data');
   return 0;
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
 
-create or replace function dotlrn_privacy__revoke_rd_prv_dt_from_rel (integer,varchar)
-returns integer as '
-declare
-  v_object_id alias for $1;
-  v_rel_type alias for $2;
+
+
+--
+-- procedure dotlrn_privacy__revoke_rd_prv_dt_from_rel/2
+--
+CREATE OR REPLACE FUNCTION dotlrn_privacy__revoke_rd_prv_dt_from_rel(
+   v_object_id integer,
+   v_rel_type varchar
+) RETURNS integer AS $$
+DECLARE
   v_segment_id integer;
-begin
+BEGIN
   select segment_id into v_segment_id
   from rel_segments
-  where group_id = acs__magic_object_id(''registered_users'')
+  where group_id = acs__magic_object_id('registered_users')
     and rel_type = v_rel_type;
-  perform acs_permission__revoke_permission(v_object_id,v_segment_id,''read_private_data'');
+  perform acs_permission__revoke_permission(v_object_id,v_segment_id,'read_private_data');
   return 0;
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
 
