Index: openacs-4/packages/acs-content-repository/sql/postgresql/content-folder.sql
===================================================================
RCS file: /usr/local/cvsroot/openacs-4/packages/acs-content-repository/sql/postgresql/content-folder.sql,v
diff -u -N -r1.50 -r1.51
--- openacs-4/packages/acs-content-repository/sql/postgresql/content-folder.sql	24 Oct 2008 13:50:14 -0000	1.50
+++ openacs-4/packages/acs-content-repository/sql/postgresql/content-folder.sql	7 Jul 2011 10:46:02 -0000	1.51
@@ -13,15 +13,24 @@
 -- create or replace package body content_folder
 
 
-create or replace function content_folder__new(varchar,varchar,varchar,integer,integer) 
-returns integer as '
-declare
-  new__name                   alias for $1;  
-  new__label                  alias for $2;  
-  new__description            alias for $3;  -- default null  
-  new__parent_id              alias for $4;  -- default null
-  new__package_id             alias for $5;  -- default null
-begin
+
+
+--
+-- procedure content_folder__new/5
+--
+CREATE OR REPLACE FUNCTION content_folder__new(
+   new__name varchar,
+   new__label varchar,
+   new__description varchar, -- default null
+   new__parent_id integer,   -- default null
+   new__package_id integer   -- default null
+
+) RETURNS integer AS $$
+--
+-- content_folder__new/5 maybe obsolete, when we define proper defaults for /11
+--
+DECLARE
+BEGIN
         return content_folder__new(new__name,
                                    new__label,
                                    new__description,
@@ -34,16 +43,26 @@
                                    new__package_id
                );
 
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
 
-create or replace function content_folder__new(varchar,varchar,varchar,integer) 
-returns integer as '
-declare
-  new__name                   alias for $1;  
-  new__label                  alias for $2;  
-  new__description            alias for $3;  -- default null  
-  new__parent_id              alias for $4;  -- default null
-begin
+
+
+--
+-- procedure content_folder__new/4
+--
+CREATE OR REPLACE FUNCTION content_folder__new(
+   new__name varchar,
+   new__label varchar,
+   new__description varchar, -- default null
+   new__parent_id integer    -- default null
+
+) RETURNS integer AS $$
+--
+-- content_folder__new/4 maybe obsolete, when we define proper defaults for /11
+--
+DECLARE
+BEGIN
         return content_folder__new(new__name,
                                    new__label,
                                    new__description,
@@ -53,26 +72,36 @@
                                    now(),
                                    null,
                                    null,
-                                   ''t'',
+                                   't',
                                    null
                );
 
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
 
 -- function new
-create or replace function content_folder__new (varchar,varchar,varchar,integer,integer,integer,timestamptz,integer,varchar)
-returns integer as '
-declare
-  new__name                   alias for $1;  
-  new__label                  alias for $2;  
-  new__description            alias for $3;  -- default null
-  new__parent_id              alias for $4;  -- default null
-  new__context_id             alias for $5;  -- default null
-  new__folder_id              alias for $6;  -- default null
-  new__creation_date          alias for $7;  -- default now()
-  new__creation_user          alias for $8;  -- default null
-  new__creation_ip            alias for $9;  -- default null
-begin
+
+
+--
+-- procedure content_folder__new/9
+--
+CREATE OR REPLACE FUNCTION content_folder__new(
+   new__name varchar,
+   new__label varchar,
+   new__description varchar,       -- default null
+   new__parent_id integer,         -- default null
+   new__context_id integer,        -- default null
+   new__folder_id integer,         -- default null
+   new__creation_date timestamptz, -- default now()
+   new__creation_user integer,     -- default null
+   new__creation_ip varchar        -- default null
+
+) RETURNS integer AS $$
+--
+-- content_folder__new/9 maybe obsolete, when we define proper defaults for /11
+--
+DECLARE
+BEGIN
         return content_folder__new(new__name,
                                    new__label,
                                    new__description,
@@ -82,30 +111,40 @@
                                    new__creation_date,
                                    new__creation_user,
                                    new__creation_ip,
-                                   ''t'',
+                                   't',
                                    null::integer
                );
 
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
 
 -- function new
-create or replace function content_folder__new (varchar,varchar,varchar,integer,integer,integer,timestamptz,integer,varchar,integer)
-returns integer as '
-declare
-  new__name                   alias for $1;  
-  new__label                  alias for $2;  
-  new__description            alias for $3;  -- default null
-  new__parent_id              alias for $4;  -- default null
-  new__context_id             alias for $5;  -- default null
-  new__folder_id              alias for $6;  -- default null
-  new__creation_date          alias for $7;  -- default now()
-  new__creation_user          alias for $8;  -- default null
-  new__creation_ip            alias for $9;  -- default null
-  new__package_id             alias for $10;  -- default null
+
+
+--
+-- procedure content_folder__new/10
+--
+CREATE OR REPLACE FUNCTION content_folder__new(
+   new__name varchar,
+   new__label varchar,
+   new__description varchar,       -- default null
+   new__parent_id integer,         -- default null
+   new__context_id integer,        -- default null
+   new__folder_id integer,         -- default null
+   new__creation_date timestamptz, -- default now()
+   new__creation_user integer,     -- default null
+   new__creation_ip varchar,       -- default null
+   new__package_id integer         -- default null
+
+) RETURNS integer AS $$
+--
+-- content_folder__new/10 maybe obsolete, when we define proper defaults for /11
+--
+DECLARE
   v_folder_id                 cr_folders.folder_id%TYPE;
   v_context_id                acs_objects.context_id%TYPE;
   v_package_id                acs_objects.package_id%TYPE;
-begin
+BEGIN
         return content_folder__new(new__name,
                                    new__label,
                                    new__description,
@@ -115,28 +154,38 @@
                                    new__creation_date,
                                    new__creation_user,
                                    new__creation_ip,
-                                   ''t'',
+                                   't',
                                    new__package_id
                );
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
 
-create or replace function content_folder__new (varchar,varchar,varchar,integer,integer,integer,timestamptz,integer,varchar,boolean)
-returns integer as '
-declare
-  new__name                   alias for $1;
-  new__label                  alias for $2;
-  new__description            alias for $3;  -- default null
-  new__parent_id              alias for $4;  -- default null
-  new__context_id             alias for $5;  -- default null
-  new__folder_id              alias for $6;  -- default null
-  new__creation_date          alias for $7;  -- default now()
-  new__creation_user          alias for $8;  -- default null
-  new__creation_ip            alias for $9;  -- default null
-  new__security_inherit_p     alias for $10;  -- default true
+
+
+--
+-- procedure content_folder__new/10
+--
+CREATE OR REPLACE FUNCTION content_folder__new(
+   new__name varchar,
+   new__label varchar,
+   new__description varchar,       -- default null
+   new__parent_id integer,         -- default null
+   new__context_id integer,        -- default null
+   new__folder_id integer,         -- default null
+   new__creation_date timestamptz, -- default now()
+   new__creation_user integer,     -- default null
+   new__creation_ip varchar,       -- default null
+   new__security_inherit_p boolean -- default true
+
+) RETURNS integer AS $$
+--
+-- content_folder__new/10 maybe obsolete, when we define proper defaults for /11
+--
+DECLARE
   v_package_id                acs_objects.package_id%TYPE;
   v_folder_id                 cr_folders.folder_id%TYPE;
   v_context_id                acs_objects.context_id%TYPE;
-begin
+BEGIN
 
         return content_folder__new (
                 new__name,
@@ -152,28 +201,39 @@
                 null
         );
 
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
 
 -- function new -- accepts security_inherit_p DaveB
-select define_function_args('content_folder__new','name,label,description,parent_id,context_id,folder_id,creation_date;now,creation_user,creation_ip,security_inherit_p;t,package_id');
 
-create or replace function content_folder__new (varchar,varchar,varchar,integer,integer,integer,timestamptz,integer,varchar, boolean,integer)
-returns integer as '
-declare
-  new__name                   alias for $1;  
-  new__label                  alias for $2;  
-  new__description            alias for $3;  -- default null
-  new__parent_id              alias for $4;  -- default null
-  new__context_id             alias for $5;  -- default null
-  new__folder_id              alias for $6;  -- default null
-  new__creation_date          alias for $7;  -- default now()
-  new__creation_user          alias for $8;  -- default null
-  new__creation_ip            alias for $9;  -- default null
-  new__security_inherit_p     alias for $10;  -- default true
-  new__package_id             alias for $11; -- default null
+-- old define_function_args('content_folder__new','name,label,description,parent_id,context_id,folder_id,creation_date;now,creation_user,creation_ip,security_inherit_p;t,package_id')
+-- new
+select define_function_args('content_folder__new','name,label,description;null,parent_id;null,context_id;null,folder_id;null,creation_date;now,creation_user;null,creation_ip;null,security_inherit_p;t,package_id;null');
+
+
+
+
+--
+-- procedure content_folder__new/11
+--
+CREATE OR REPLACE FUNCTION content_folder__new(
+   new__name varchar,
+   new__label varchar,
+   new__description varchar,        -- default null
+   new__parent_id integer,          -- default null
+   new__context_id integer,         -- default null
+   new__folder_id integer,          -- default null
+   new__creation_date timestamptz,  -- default now() -- default 'now'
+   new__creation_user integer,      -- default null
+   new__creation_ip varchar,        -- default null
+   new__security_inherit_p boolean, -- default true -- default 't'
+   new__package_id integer          -- default null
+
+) RETURNS integer AS $$
+DECLARE
   v_folder_id                 cr_folders.folder_id%TYPE;
   v_context_id                acs_objects.context_id%TYPE;
-begin
+BEGIN
 
   -- set the context_id
   if new__context_id is null then
@@ -185,9 +245,9 @@
   -- parent_id = security_context_root means that this is a mount point
   if new__parent_id != -4 and 
     content_folder__is_folder(new__parent_id) and
-    content_folder__is_registered(new__parent_id,''content_folder'',''f'') = ''f'' then
+    content_folder__is_registered(new__parent_id,'content_folder','f') = 'f' then
 
-    raise EXCEPTION ''-20000: This folder does not allow subfolders to be created'';
+    raise EXCEPTION '-20000: This folder does not allow subfolders to be created';
     return null;
 
   else
@@ -201,14 +261,14 @@
         new__creation_user, 
 	new__context_id,
 	new__creation_ip, 
-	''f'',
-	''text/plain'',
+	'f',
+	'text/plain',
 	null,
-	''text'',
+	'text',
 	new__security_inherit_p,
-	''CR_FILES'',
-	''content_folder'',
-        ''content_folder'',
+	'CR_FILES',
+	'content_folder',
+        'content_folder',
         new__package_id
     );
 
@@ -237,30 +297,40 @@
     end if;
 
     -- update the child flag on the parent
-    update cr_folders set has_child_folders = ''t''
+    update cr_folders set has_child_folders = 't'
       where folder_id = new__parent_id;
 
     return v_folder_id;
 
   end if;
 
   return v_folder_id; 
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
 
-create or replace function content_folder__new (varchar,varchar,varchar,integer,integer,integer,timestamptz,integer,varchar,boolean)
-returns integer as '
-declare
-  new__name                   alias for $1;  
-  new__label                  alias for $2;  
-  new__description            alias for $3;  -- default null
-  new__parent_id              alias for $4;  -- default null
-  new__context_id             alias for $5;  -- default null
-  new__folder_id              alias for $6;  -- default null
-  new__creation_date          alias for $7;  -- default now()
-  new__creation_user          alias for $8;  -- default null
-  new__creation_ip            alias for $9;  -- default null
-  new__security_inherit_p     alias for $10;  -- default true	
-begin
+
+
+--
+-- procedure content_folder__new/10
+--
+CREATE OR REPLACE FUNCTION content_folder__new(
+   new__name varchar,
+   new__label varchar,
+   new__description varchar,       -- default null
+   new__parent_id integer,         -- default null
+   new__context_id integer,        -- default null
+   new__folder_id integer,         -- default null
+   new__creation_date timestamptz, -- default now()
+   new__creation_user integer,     -- default null
+   new__creation_ip varchar,       -- default null
+   new__security_inherit_p boolean -- default true
+
+) RETURNS integer AS $$
+--
+-- content_folder__new/10 maybe obsolete, when we define proper defaults for /11
+--
+DECLARE
+BEGIN
         return content_folder__new(new__name,
                                    new__label,
                                    new__description,
@@ -274,29 +344,36 @@
                                    null::integer
                );
 
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
 
 -- procedure delete
 select define_function_args('content_folder__del','folder_id,cascade_p;f');
-create or replace function content_folder__del (integer, boolean)
-returns integer as '
-declare
-  delete__folder_id              alias for $1;  
-  p_cascade_p                    alias for $2; -- default ''f''
+
+
+--
+-- procedure content_folder__del/2
+--
+CREATE OR REPLACE FUNCTION content_folder__del(
+   delete__folder_id integer,
+   p_cascade_p boolean -- default 'f'
+
+) RETURNS integer AS $$
+DECLARE
   v_count                        integer;       
   v_child_row                    record;
   v_parent_id                    integer;  
   v_path                         varchar;     
   v_folder_sortkey               varbit;
-begin
+BEGIN
 
-  if p_cascade_p = ''f'' then
+  if p_cascade_p = 'f' then
     select count(*) into v_count from cr_items 
      where parent_id = delete__folder_id;
     -- check if the folder contains any items
     if v_count > 0 then
       v_path := content_item__get_path(delete__folder_id, null);
-      raise EXCEPTION ''-20000: Folder ID % (%) cannot be deleted because it is not empty.'', delete__folder_id, v_path;
+      raise EXCEPTION '-20000: Folder ID % (%) cannot be deleted because it is not empty.', delete__folder_id, v_path;
     end if;  
   else 
   -- delete children
@@ -320,95 +397,123 @@
 
   PERFORM content_folder__unregister_content_type(
       delete__folder_id,
-      ''content_revision'',
-      ''t'' 
+      'content_revision',
+      't' 
   );
 
   delete from cr_folder_type_map
     where folder_id = delete__folder_id;
 
   select parent_id into v_parent_id from cr_items 
     where item_id = delete__folder_id;
-  raise notice ''deleteing folder %'',delete__folder_id;
+  raise notice 'deleteing folder %',delete__folder_id;
   PERFORM content_item__delete(delete__folder_id);
 
   -- check if any folders are left in the parent
-  update cr_folders set has_child_folders = ''f'' 
+  update cr_folders set has_child_folders = 'f' 
     where folder_id = v_parent_id and not exists (
       select 1 from cr_items 
-        where parent_id = v_parent_id and content_type = ''content_folder'');
+        where parent_id = v_parent_id and content_type = 'content_folder');
 
   return 0; 
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
 
 select define_function_args('content_folder__delete','folder_id,cascade_p;f');
 
-create or replace function content_folder__delete (integer, boolean)
-returns integer as '
-declare
-  delete__folder_id              alias for $1;  
-  p_cascade_p                    alias for $2;  -- default ''f''
-begin
+
+
+--
+-- procedure content_folder__delete/2
+--
+CREATE OR REPLACE FUNCTION content_folder__delete(
+   delete__folder_id integer,
+   p_cascade_p boolean -- default 'f'
+
+) RETURNS integer AS $$
+DECLARE
+BEGIN
         PERFORM content_folder__del(delete__folder_id,p_cascade_p);
   return 0; 
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
 
 
-create or replace function content_folder__delete (integer)
-returns integer as '
-declare
-  delete__folder_id              alias for $1;  
+
+
+--
+-- procedure content_folder__delete/1
+--
+CREATE OR REPLACE FUNCTION content_folder__delete(
+   delete__folder_id integer
+) RETURNS integer AS $$
+--
+-- content_folder__delete/1 maybe obsolete, when we define proper defaults for /2
+--
+DECLARE
   v_count                        integer;       
   v_parent_id                    integer;  
   v_path                         varchar;     
-begin
+BEGIN
 	return content_folder__del(
 		delete__folder_id,
-		''f''
+		'f'
 		);
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
 
 
 -- procedure rename
-select define_function_args('content_folder__edit_name','folder_id,name,label,description');
-create or replace function content_folder__edit_name (integer,varchar,varchar,varchar)
-returns integer as '
-declare
-  edit_name__folder_id              alias for $1;  
-  edit_name__name                   alias for $2;  -- default null  
-  edit_name__label                  alias for $3;  -- default null
-  edit_name__description            alias for $4;  -- default null
+
+-- old define_function_args('content_folder__edit_name','folder_id,name,label,description')
+-- new
+select define_function_args('content_folder__edit_name','folder_id,name;null,label;null,description;null');
+
+
+
+--
+-- procedure content_folder__edit_name/4
+--
+CREATE OR REPLACE FUNCTION content_folder__edit_name(
+   edit_name__folder_id integer,
+   edit_name__name varchar,       -- default null
+   edit_name__label varchar,      -- default null
+   edit_name__description varchar -- default null
+
+) RETURNS integer AS $$
+DECLARE
   v_name_already_exists_p        integer;
-begin
+BEGIN
 
-  if edit_name__name is not null and edit_name__name != '''' then
+  if edit_name__name is not null and edit_name__name != '' then
     PERFORM content_item__edit_name(edit_name__folder_id, edit_name__name);
   end if;
 
-  if edit_name__label is not null and edit_name__label != '''' then
+  if edit_name__label is not null and edit_name__label != '' then
     update acs_objects
     set title = edit_name__label
     where object_id = edit_name__folder_id;
   end if;
 
-  if edit_name__label is not null and edit_name__label != '''' and 
-     edit_name__description is not null and edit_name__description != '''' then 
+  if edit_name__label is not null and edit_name__label != '' and 
+     edit_name__description is not null and edit_name__description != '' then 
 
     update cr_folders
       set label = edit_name__label,
       description = edit_name__description
       where folder_id = edit_name__folder_id;
 
-  else if(edit_name__label is not null and edit_name__label != '''') and 
-         (edit_name__description is null or edit_name__description = '''') then  
+  else if(edit_name__label is not null and edit_name__label != '') and 
+         (edit_name__description is null or edit_name__description = '') then  
     update cr_folders
       set label = edit_name__label
       where folder_id = edit_name__folder_id;
 
   end if; end if;
 
   return 0; 
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
 
 -- 1) make sure we are not moving the folder to an invalid location:
 --   a. destination folder exists
@@ -421,15 +526,21 @@
 -- procedure move
 select define_function_args('content_folder__move','folder_id,target_folder_id,name;null');
 
-create or replace function content_folder__move (integer,integer,varchar)
-returns integer as '
-declare
-  move__folder_id              alias for $1;  
-  move__target_folder_id       alias for $2;
-  move__name                   alias for $3; -- default null
+
+
+--
+-- procedure content_folder__move/3
+--
+CREATE OR REPLACE FUNCTION content_folder__move(
+   move__folder_id integer,
+   move__target_folder_id integer,
+   move__name varchar -- default null
+
+) RETURNS integer AS $$
+DECLARE
   v_source_folder_id           integer;       
   v_valid_folders_p            integer;
-begin
+BEGIN
 
   select 
     count(*)
@@ -443,24 +554,24 @@
     folder_id = move__folder_id;
 
   if v_valid_folders_p != 2 then
-    raise EXCEPTION ''-20000: content_folder.move - Not valid folder(s)'';
+    raise EXCEPTION '-20000: content_folder.move - Not valid folder(s)';
   end if;
 
   if move__folder_id = content_item__get_root_folder(null) or
     move__folder_id = content_template__get_root_folder() then
-    raise EXCEPTION ''-20000: content_folder.move - Cannot move root folder'';
+    raise EXCEPTION '-20000: content_folder.move - Cannot move root folder';
   end if;
   
   if move__target_folder_id = move__folder_id then
-    raise EXCEPTION ''-20000: content_folder.move - Cannot move a folder to itself'';
+    raise EXCEPTION '-20000: content_folder.move - Cannot move a folder to itself';
   end if;
 
-  if content_folder__is_sub_folder(move__folder_id, move__target_folder_id) = ''t'' then
-    raise EXCEPTION ''-20000: content_folder.move - Destination folder is subfolder'';
+  if content_folder__is_sub_folder(move__folder_id, move__target_folder_id) = 't' then
+    raise EXCEPTION '-20000: content_folder.move - Destination folder is subfolder';
   end if;
 
-  if content_folder__is_registered(move__target_folder_id,''content_folder'',''f'') != ''t'' then
-    raise EXCEPTION ''-20000: content_folder.move - Destination folder does not allow subfolders'';
+  if content_folder__is_registered(move__target_folder_id,'content_folder','f') != 't' then
+    raise EXCEPTION '-20000: content_folder.move - Destination folder does not allow subfolders';
   end if;
 
   select parent_id into v_source_folder_id from cr_items 
@@ -475,50 +586,68 @@
   -- update the has_child_folders flags
 
   -- update the source
-  update cr_folders set has_child_folders = ''f'' 
+  update cr_folders set has_child_folders = 'f' 
     where folder_id = v_source_folder_id and not exists (
       select 1 from cr_items 
         where parent_id = v_source_folder_id 
-          and content_type = ''content_folder'');
+          and content_type = 'content_folder');
 
   -- update the destination
-  update cr_folders set has_child_folders = ''t''
+  update cr_folders set has_child_folders = 't'
     where folder_id = move__target_folder_id;
 
   return 0; 
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
 
-create or replace function content_folder__move (integer,integer)
-returns integer as '
-declare
-  move__folder_id              alias for $1;  
-  move__target_folder_id       alias for $2;  
-begin
 
+
+--
+-- procedure content_folder__move/2
+--
+CREATE OR REPLACE FUNCTION content_folder__move(
+   move__folder_id integer,
+   move__target_folder_id integer
+) RETURNS integer AS $$
+--
+-- content_folder__move/2 maybe obsolete, when we define proper defaults for /3
+--
+DECLARE
+BEGIN
+
   perform content_folder__move (
                                 move__folder_id,
                                 move__target_folder_id,
                                 NULL
                                );
   return null;
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
 
 -- procedure copy
-create or replace function content_folder__copy (integer,integer,integer,varchar)
-returns integer as '
-declare
-  copy__folder_id              alias for $1;  
-  copy__target_folder_id       alias for $2;  
-  copy__creation_user          alias for $3;  
-  copy__creation_ip            alias for $4;  -- default null  
+
+
+-- added
+
+--
+-- procedure content_folder__copy/4
+--
+CREATE OR REPLACE FUNCTION content_folder__copy(
+   copy__folder_id integer,
+   copy__target_folder_id integer,
+   copy__creation_user integer,
+   copy__creation_ip varchar -- default null
+
+) RETURNS integer AS $$
+DECLARE
   v_valid_folders_p            integer;        
   v_current_folder_id          cr_folders.folder_id%TYPE;
   v_name                       cr_items.name%TYPE;
   v_label                      cr_folders.label%TYPE;
   v_description                cr_folders.description%TYPE;
   v_new_folder_id              cr_folders.folder_id%TYPE;
   v_folder_contents_val        record;
-begin
+BEGIN
 	v_new_folder_id := content_folder__copy (
 			copy__folder_id,
 			copy__target_folder_id,
@@ -527,28 +656,38 @@
 			NULL
 			);
 	return v_new_folder_id;
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
 
-create or replace function content_folder__copy (integer,integer,integer,varchar,varchar)
-returns integer as '
-declare
-  copy__folder_id              alias for $1;  
-  copy__target_folder_id       alias for $2;  
-  copy__creation_user          alias for $3;  
-  copy__creation_ip            alias for $4;  -- default null
-  copy__name                   alias for $5; -- default null
+
+
+-- added
+select define_function_args('content_folder__copy','folder_id,target_folder_id,creation_user,creation_ip;null,name;null');
+
+--
+-- procedure content_folder__copy/5
+--
+CREATE OR REPLACE FUNCTION content_folder__copy(
+   copy__folder_id integer,
+   copy__target_folder_id integer,
+   copy__creation_user integer,
+   copy__creation_ip varchar, -- default null
+   copy__name varchar         -- default null
+
+) RETURNS integer AS $$
+DECLARE
   v_valid_folders_p            integer;
   v_current_folder_id          cr_folders.folder_id%TYPE;
   v_name                       cr_items.name%TYPE;
   v_label                      cr_folders.label%TYPE;
   v_description                cr_folders.description%TYPE;
   v_new_folder_id              cr_folders.folder_id%TYPE;
   v_folder_contents_val        record;
-begin
+BEGIN
 
   if copy__folder_id = content_item__get_root_folder(null) 
      or copy__folder_id = content_template__get_root_folder() then
-     raise EXCEPTION ''-20000: content_folder.copy - Not allowed to copy root folder'';
+     raise EXCEPTION '-20000: content_folder.copy - Not allowed to copy root folder';
   end if;
 
   select 
@@ -563,19 +702,19 @@
     folder_id = copy__folder_id;
 
   if v_valid_folders_p != 2 then 
-    raise EXCEPTION ''-20000: content_folder.copy - Invalid folder(s)'';
+    raise EXCEPTION '-20000: content_folder.copy - Invalid folder(s)';
   end if;
 
   if copy__target_folder_id = copy__folder_id then 
-    raise EXCEPTION ''-20000: content_folder.copy - Cannot copy folder to itself'';
+    raise EXCEPTION '-20000: content_folder.copy - Cannot copy folder to itself';
   end if;
   
-  if content_folder__is_sub_folder(copy__folder_id, copy__target_folder_id) = ''t'' then
-    raise EXCEPTION ''-20000: content_folder.copy - Destination folder is subfolder'';
+  if content_folder__is_sub_folder(copy__folder_id, copy__target_folder_id) = 't' then
+    raise EXCEPTION '-20000: content_folder.copy - Destination folder is subfolder';
   end if;
 
-  if content_folder__is_registered(copy__target_folder_id,''content_folder'',''f'') != ''t'' then
-    raise EXCEPTION ''-20000: content_folder.copy - Destination folder does not allow subfolders'';
+  if content_folder__is_registered(copy__target_folder_id,'content_folder','f') != 't' then
+    raise EXCEPTION '-20000: content_folder.copy - Destination folder does not allow subfolders';
   end if;
 
   -- get the source folder info
@@ -593,7 +732,7 @@
   -- would be better to check if the copy__name alredy exists in the destination folder.
 
   if v_current_folder_id = copy__target_folder_id and (v_name = copy__name or copy__name is null) then
-    raise EXCEPTION ''-20000: content_folder.copy - Destination folder is parent folder and folder alredy exists'';
+    raise EXCEPTION '-20000: content_folder.copy - Destination folder is parent folder and folder alredy exists';
   end if;
 
       -- create the new folder
@@ -607,7 +746,7 @@
           now(),
 	  copy__creation_user,
 	  copy__creation_ip,
-          ''t'',
+          't',
           null
       );
 
@@ -645,39 +784,51 @@
       end loop;
 
   return 0; 
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
 
 
 -- function is_folder
 select define_function_args('content_folder__is_folder','item_id');
-create or replace function content_folder__is_folder (integer)
-returns boolean as '
-declare
-  item_id                alias for $1;  
-begin
 
+
+--
+-- procedure content_folder__is_folder/1
+--
+CREATE OR REPLACE FUNCTION content_folder__is_folder(
+   item_id integer
+) RETURNS boolean AS $$
+DECLARE
+BEGIN
+
   return count(*) > 0 from cr_folders
     where folder_id = item_id;
 
-end;' language 'plpgsql' stable;
+END;
+$$ LANGUAGE plpgsql stable;
 
 
 -- function is_sub_folder
 select define_function_args('content_folder__is_sub_folder','folder_id,target_folder_id');
-create or replace function content_folder__is_sub_folder (integer,integer)
-returns boolean as '
-declare
-  is_sub_folder__folder_id              alias for $1;  
-  is_sub_folder__target_folder_id       alias for $2;  
+
+
+--
+-- procedure content_folder__is_sub_folder/2
+--
+CREATE OR REPLACE FUNCTION content_folder__is_sub_folder(
+   is_sub_folder__folder_id integer,
+   is_sub_folder__target_folder_id integer
+) RETURNS boolean AS $$
+DECLARE
   v_parent_id                           integer default 0;       
-  v_sub_folder_p                        boolean default ''f'';           
+  v_sub_folder_p                        boolean default 'f';           
   v_rec                                 record;
-begin
+BEGIN
 
   if is_sub_folder__folder_id = content_item__get_root_folder(null) or
     is_sub_folder__folder_id = content_template__get_root_folder() then
 
-    v_sub_folder_p := ''t'';
+    v_sub_folder_p := 't';
   end if;
 
 --               select
@@ -702,22 +853,28 @@
   end LOOP;
 
   if v_parent_id != -4 then 
-    v_sub_folder_p := ''t'';
+    v_sub_folder_p := 't';
   end if;
 
   return v_sub_folder_p;
  
-end;' language 'plpgsql'; 
+END;
+$$ LANGUAGE plpgsql; 
 
 
 -- function is_empty
 select define_function_args('content_folder__is_empty','folder_id');
-create or replace function content_folder__is_empty (integer)
-returns boolean as '
-declare
-  is_empty__folder_id              alias for $1;  
+
+
+--
+-- procedure content_folder__is_empty/1
+--
+CREATE OR REPLACE FUNCTION content_folder__is_empty(
+   is_empty__folder_id integer
+) RETURNS boolean AS $$
+DECLARE
   v_return                         boolean;    
-begin
+BEGIN
 
   select
     count(*) = 0 into v_return
@@ -728,30 +885,37 @@
 
   return v_return;
  
-end;' language 'plpgsql' stable;
+END;
+$$ LANGUAGE plpgsql stable;
 
 
 -- procedure register_content_type
 select define_function_args('content_folder__register_content_type','folder_id,content_type,include_subtypes;f');
 
-create or replace function content_folder__register_content_type (integer,varchar,boolean)
-returns integer as '
-declare
-  register_content_type__folder_id              alias for $1;  
-  register_content_type__content_type           alias for $2;  
-  register_content_type__include_subtypes       alias for $3;  -- default ''f''
+
+
+--
+-- procedure content_folder__register_content_type/3
+--
+CREATE OR REPLACE FUNCTION content_folder__register_content_type(
+   register_content_type__folder_id integer,
+   register_content_type__content_type varchar,
+   register_content_type__include_subtypes boolean -- default 'f'
+
+) RETURNS integer AS $$
+DECLARE
   v_is_registered                               varchar;  
-begin
+BEGIN
 
-  if register_content_type__include_subtypes = ''f'' then
+  if register_content_type__include_subtypes = 'f' then
 
     v_is_registered := content_folder__is_registered(
         register_content_type__folder_id,
 	register_content_type__content_type, 
-	''f'' 
+	'f' 
     );
 
-    if v_is_registered = ''f'' then
+    if v_is_registered = 'f' then
 
         insert into cr_folder_type_map (
 	  folder_id, content_type
@@ -771,7 +935,7 @@
 --      from
 --        acs_object_types
 --      where
---        object_type <> ''acs_object''
+--        object_type <> 'acs_object'
 --      and
 --        not exists (select 1 from cr_folder_type_map
 --                    where folder_id = register_content_type__folder_id
@@ -785,7 +949,7 @@
       select register_content_type__folder_id as folder_id, 
         o.object_type as content_type
       from acs_object_types o, acs_object_types o2
-      where o.object_type <> ''acs_object''
+      where o.object_type <> 'acs_object'
         and not exists (select 1
                         from cr_folder_type_map
                         where folder_id = register_content_type__folder_id
@@ -795,20 +959,27 @@
   end if;
 
   return 0; 
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
 
 
 -- procedure unregister_content_type
 select define_function_args('content_folder__unregister_content_type','folder_id,content_type,include_subtypes;f');
-create or replace function content_folder__unregister_content_type (integer,varchar,boolean)
-returns integer as '
-declare
-  unregister_content_type__folder_id              alias for $1;  
-  unregister_content_type__content_type           alias for $2;  
-  unregister_content_type__include_subtypes       alias for $3; -- default ''f'' 
-begin
 
-  if unregister_content_type__include_subtypes = ''f'' then
+
+--
+-- procedure content_folder__unregister_content_type/3
+--
+CREATE OR REPLACE FUNCTION content_folder__unregister_content_type(
+   unregister_content_type__folder_id integer,
+   unregister_content_type__content_type varchar,
+   unregister_content_type__include_subtypes boolean -- default 'f'
+
+) RETURNS integer AS $$
+DECLARE
+BEGIN
+
+  if unregister_content_type__include_subtypes = 'f' then
     delete from cr_folder_type_map
       where folder_id = unregister_content_type__folder_id
       and content_type = unregister_content_type__content_type;
@@ -818,7 +989,7 @@
 --    where folder_id = unregister_content_type__folder_id
 --    and content_type in (select object_type
 --           from acs_object_types    
---	   where object_type <> ''acs_object''
+--	   where object_type <> 'acs_object'
 --	   connect by prior object_type = supertype
 --	   start with 
 --             object_type = unregister_content_type__content_type);
@@ -827,29 +998,36 @@
     where folder_id = unregister_content_type__folder_id
     and content_type in (select o.object_type
                            from acs_object_types o, acs_object_types o2
-	                  where o.object_type <> ''acs_object''
+	                  where o.object_type <> 'acs_object'
                             and o2.object_type = unregister_content_type__content_type
                             and o.tree_sortkey between o2.tree_sortkey and tree_right(o2.tree_sortkey));
 
   end if;
 
   return 0; 
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
 
 
 -- function is_registered
 select define_function_args('content_folder__is_registered','folder_id,content_type,include_subtypes;f');
-create or replace function content_folder__is_registered (integer,varchar,boolean)
-returns boolean as '
-declare
-  is_registered__folder_id              alias for $1;  
-  is_registered__content_type           alias for $2;  
-  is_registered__include_subtypes       alias for $3;  -- default ''f''  
+
+
+--
+-- procedure content_folder__is_registered/3
+--
+CREATE OR REPLACE FUNCTION content_folder__is_registered(
+   is_registered__folder_id integer,
+   is_registered__content_type varchar,
+   is_registered__include_subtypes boolean -- default 'f'
+
+) RETURNS boolean AS $$
+DECLARE
   v_is_registered                       integer;
   v_subtype_val                         record;
-begin
+BEGIN
 
-  if is_registered__include_subtypes = ''f'' or  is_registered__include_subtypes is null then
+  if is_registered__include_subtypes = 'f' or  is_registered__include_subtypes is null then
     select 
       count(1)
     into 
@@ -867,7 +1045,7 @@
 --                          from 
 --                            acs_object_types
 --                          where 
---                            object_type <> ''acs_object''
+--                            object_type <> 'acs_object'
 --                          connect by 
 --                            prior object_type = supertype
 --                          start with 
@@ -876,35 +1054,41 @@
     v_is_registered := 1;
     for v_subtype_val in select o.object_type
                          from acs_object_types o, acs_object_types o2
-                         where o.object_type <> ''acs_object''
+                         where o.object_type <> 'acs_object'
                            and o2.object_type = is_registered__content_type
                            and o.tree_sortkey between o2.tree_sortkey and tree_right(o2.tree_sortkey)
                          order by o.tree_sortkey
     LOOP
       if content_folder__is_registered(is_registered__folder_id,
-                       v_subtype_val.object_type, ''f'') = ''f'' then
+                       v_subtype_val.object_type, 'f') = 'f' then
         v_is_registered := 0;
       end if;
     end loop;
   end if;
 
   if v_is_registered = 0 then
-    return ''f'';
+    return 'f';
   else
-    return ''t'';
+    return 't';
   end if;
  
-end;' language 'plpgsql' stable;
+END;
+$$ LANGUAGE plpgsql stable;
 
 
 -- function get_label
 select define_function_args('content_folder__get_label','folder_id');
-create or replace function content_folder__get_label (integer)
-returns varchar as '
-declare
-  get_label__folder_id              alias for $1;  
+
+
+--
+-- procedure content_folder__get_label/1
+--
+CREATE OR REPLACE FUNCTION content_folder__get_label(
+   get_label__folder_id integer
+) RETURNS varchar AS $$
+DECLARE
   v_label                           cr_folders.label%TYPE;
-begin
+BEGIN
 
   select 
     label into v_label 
@@ -915,21 +1099,27 @@
 
   return v_label;
  
-end;' language 'plpgsql' stable strict;
+END;
+$$ LANGUAGE plpgsql stable strict;
 
 
 -- function get_index_page
 select define_function_args('content_folder__get_index_page','folder_id');
-create or replace function content_folder__get_index_page (integer)
-returns integer as '
-declare
-  get_index_page__folder_id              alias for $1;  
+
+
+--
+-- procedure content_folder__get_index_page/1
+--
+CREATE OR REPLACE FUNCTION content_folder__get_index_page(
+   get_index_page__folder_id integer
+) RETURNS integer AS $$
+DECLARE
   v_folder_id                            cr_folders.folder_id%TYPE;
   v_index_page_id                        cr_items.item_id%TYPE;
-begin
+BEGIN
 
   -- if the folder is a symlink, resolve it
-  if content_symlink__is_symlink(get_index_page__folder_id) = ''t'' then
+  if content_symlink__is_symlink(get_index_page__folder_id) = 't' then
     v_folder_id := content_symlink__resolve(get_index_page__folder_id);
   else
     v_folder_id := get_index_page__folder_id;
@@ -942,40 +1132,47 @@
   where
     parent_id = v_folder_id
   and
-    name = ''index''
+    name = 'index'
   and
     content_item__is_subclass(
       content_item__get_content_type(content_symlink__resolve(item_id)),
-    ''content_folder'') = ''f''
+    'content_folder') = 'f'
   and
     content_item__is_subclass(
       content_item__get_content_type(content_symlink__resolve(item_id)),
-    ''content_template'') = ''f'';
+    'content_template') = 'f';
 
   if NOT FOUND then 
      return null;
   end if;
 
   return v_index_page_id;
 
-end;' language 'plpgsql' stable strict;
+END;
+$$ LANGUAGE plpgsql stable strict;
 
 
 -- function is_root
 select define_function_args('content_folder__is_root','folder_id');
-create or replace function content_folder__is_root (integer)
-returns boolean as '
-declare
-  is_root__folder_id              alias for $1;  
+
+
+--
+-- procedure content_folder__is_root/1
+--
+CREATE OR REPLACE FUNCTION content_folder__is_root(
+   is_root__folder_id integer
+) RETURNS boolean AS $$
+DECLARE
   v_is_root                       boolean;       
-begin
+BEGIN
 
   select parent_id = -4 into v_is_root 
     from cr_items where item_id = is_root__folder_id;
 
   return v_is_root;
  
-end;' language 'plpgsql';
+END;
+$$ LANGUAGE plpgsql;
 
 
 
