--
-- static_page__new/4
--
create or replace function static_page__new(
  integer,
  character varying,
  character varying,
  integer
) returns int4 as $$

	declare
                p_folder_id             alias for $1;
                p_filename              alias for $2;
                p_title                 alias for $3;
		p_mtime			alias for $4;
               
	        v_static_page_id	static_pages.static_page_id%TYPE;	       
                v_item_id	        static_pages.static_page_id%TYPE;

        begin
		return static_page__new (
			   NULL,	       -- static_page_id
			   p_folder_id,	       -- folder_id
			   p_filename,	       -- filename
			   p_title,	       -- title
			   NULL,	       -- content
			   't',	       -- show_comments_p
			   now(),	       -- creation_date
			   NULL,	       -- creation_user
			   NULL,	       -- creation_ip
			   NULL,	       -- conext_id
			   p_mtime	       -- mtime
			   );
	       
end;$$ language plpgsql;


--
-- static_page__new/5
--
create or replace function static_page__new(
  integer,
  character varying,
  character varying,
  integer,
  character varying
) returns int4 as $$

	declare
                p_folder_id             alias for $1;
                p_filename              alias for $2;
                p_title                 alias for $3;
		p_mtime			alias for $4;
		p_mime_type		alias for $5;
               
	        v_static_page_id	static_pages.static_page_id%TYPE;	       
                v_item_id	        static_pages.static_page_id%TYPE;

        begin
		return static_page__new (
			   NULL,	       -- static_page_id
			   p_folder_id,	       -- folder_id
			   p_filename,	       -- filename
			   p_title,	       -- title
			   NULL,	       -- content
			   't',	       -- show_comments_p
			   now(),	       -- creation_date
			   NULL,	       -- creation_user
			   NULL,	       -- creation_ip
			   NULL,	       -- conext_id
			   p_mtime	       -- mtime
			   ,p_mime_type	       -- mime_type
			   );
	       
end;$$ language plpgsql;


--
-- static_page__new/11
--
create or replace function static_page__new(
  integer,
  integer,
  character varying,
  character varying,
  text,
  boolean,
  timestamp with time zone,
  integer,
  character varying,
  integer,
  integer
) returns int4 as $$

	declare
                p_static_page_id        alias for $1;
                p_folder_id             alias for $2;
                p_filename              alias for $3;
                p_title                 alias for $4;
                p_content               alias for $5;
                p_show_comments_p       alias for $6;
                p_creation_date         alias for $7;
                p_creation_user         alias for $8;
                p_creation_ip           alias for $9;
                p_context_id            alias for $10;
		p_mtime			alias for $11;

                v_item_id	        static_pages.static_page_id%TYPE;
                v_permission_row        RECORD;
		v_revision_id		integer;
		v_is_live		boolean default 't';
		v_mime_type		cr_revisions.mime_type%TYPE default 'text/html';
		v_storage_type		cr_items.storage_type%TYPE default 'file';
        begin
                -- Create content item; this also makes the content revision.
                -- One might be tempted to set the content_type to static_page,
                -- But this would confuse site-wide-search, which expects to
                -- see a content_type of content_revision.
		
                v_item_id := content_item__new(
                        p_static_page_id,               -- item_id
			p_filename,                     -- name		
			p_folder_id,                    -- parent_id
                        p_title,                        -- title
                        p_creation_date,                -- creation_date
                        p_creation_user,                -- creation_user
                        p_context_id,                   -- context_id
                        p_creation_ip,                  -- creation_ip
                        v_is_live,                          -- is_live
                        v_mime_type,                  -- mime_type
			p_content,                       -- text
			v_storage_type,			 -- storage_type
			FALSE,				 -- security_inherit_p
			'STATIC_PAGES',		-- storage_area_key
			'content_item',		 -- item subtype
			'static_page'			 -- content_type
                );


                -- We want to be able to have non-commentable folders below
                -- commentable folders.  We can't do this if we leave security
                -- inheritance enabled.
                --
-- uses overloaded content_item__new and acs_object__new to set
-- security_inherit_p to 'f' DaveB
--                update acs_objects set security_inherit_p = 'f'
--                        where object_id = v_item_id;

                -- Copy permissions from the parent:
                for v_permission_row in 
                        select grantee_id,privilege from acs_permissions
                                where object_id = p_folder_id
                 loop
                        perform acs_permission__grant_permission(
                                v_item_id,                      -- object_id
                                v_permission_row.grantee_id,    -- grantee_id
                                v_permission_row.privilege      -- privilege
                        );
                end loop;

                -- Insert row into static_pages:
                insert into static_pages
                        (static_page_id, filename, folder_id, show_comments_p, mtime)
                values (
                        v_item_id,
                        p_filename,
                        p_folder_id,
                        p_show_comments_p,
			p_mtime
                );

                return v_item_id;
end;$$ language plpgsql;


--
-- static_page__new/12
--
create or replace function static_page__new(
  integer,
  integer,
  character varying,
  character varying,
  text,
  boolean,
  timestamp with time zone,
  integer,
  character varying,
  integer,
  integer,
  character varying
) returns int4 as $$

	declare
                p_static_page_id        alias for $1;
                p_folder_id             alias for $2;
                p_filename              alias for $3;
                p_title                 alias for $4;
                p_content               alias for $5;
                p_show_comments_p       alias for $6;
                p_creation_date         alias for $7;
                p_creation_user         alias for $8;
                p_creation_ip           alias for $9;
                p_context_id            alias for $10;
		p_mtime			alias for $11;
		p_mime_type		alias for $12;

                v_item_id	        static_pages.static_page_id%TYPE;
                v_permission_row        RECORD;
		v_revision_id		integer;
		v_is_live		boolean default 't';
		v_storage_type		cr_items.storage_type%TYPE default 'file';
        begin
                -- Create content item; this also makes the content revision.
                -- One might be tempted to set the content_type to static_page,
                -- But this would confuse site-wide-search, which expects to
                -- see a content_type of content_revision.
		
                v_item_id := content_item__new(
                        p_static_page_id,               -- item_id
			p_filename,                     -- name		
			p_folder_id,                    -- parent_id
                        p_title,                        -- title
                        p_creation_date,                -- creation_date
                        p_creation_user,                -- creation_user
                        p_context_id,                   -- context_id
                        p_creation_ip,                  -- creation_ip
                        v_is_live,                          -- is_live
                        p_mime_type,			-- mime_type
			p_content,                       -- text
			v_storage_type,			 -- storage_type
			FALSE,				 -- security_inherit_p
			'STATIC_PAGES',		-- storage_area_key
			'content_item',		 -- item subtype
			'static_page'			 -- content_type
                );


                -- We want to be able to have non-commentable folders below
                -- commentable folders.  We can't do this if we leave security
                -- inheritance enabled.
                --
-- uses overloaded content_item__new and acs_object__new to set
-- security_inherit_p to 'f' DaveB
--                update acs_objects set security_inherit_p = 'f'
--                        where object_id = v_item_id;

                -- Copy permissions from the parent:
                for v_permission_row in 
                        select grantee_id,privilege from acs_permissions
                                where object_id = p_folder_id
                 loop
                        perform acs_permission__grant_permission(
                                v_item_id,                      -- object_id
                                v_permission_row.grantee_id,    -- grantee_id
                                v_permission_row.privilege      -- privilege
                        );
                end loop;

                -- Insert row into static_pages:
                insert into static_pages
                        (static_page_id, filename, folder_id, show_comments_p, mtime)
                values (
                        v_item_id,
                        p_filename,
                        p_folder_id,
                        p_show_comments_p,
			p_mtime
                );

                return v_item_id;
end;$$ language plpgsql;