Index: openacs-4/packages/assessment/www/asm-admin/toggle-publish.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/assessment/www/asm-admin/toggle-publish.tcl,v diff -u -r1.1 -r1.1.2.1 --- openacs-4/packages/assessment/www/asm-admin/toggle-publish.tcl 28 Nov 2006 18:17:53 -0000 1.1 +++ openacs-4/packages/assessment/www/asm-admin/toggle-publish.tcl 23 Mar 2007 16:35:56 -0000 1.1.2.1 @@ -9,6 +9,21 @@ -object_id $assessment_id \ -privilege "admin" -db_dml toggle_publish "" +# find current publish_status +set publish_status [db_string get_publish_status ""] +if { $publish_status ne "live" } { + set publish_status "" +} -ad_returnredirect [export_vars -base one-a {assessment_id}] \ No newline at end of file +# returns list of empty sections +set empty_sections [db_list count_questions ""] + +if { ($empty_sections eq "") || ($publish_status eq "live") } { + # if no empty sections, or if we're un-publishing, then proceed + db_dml toggle_publish "" + set message "" +} else { + set message "Publish failed. Following section(s) have no questions: ${empty_sections}" +} + +ad_returnredirect -message $message [export_vars -base one-a {assessment_id}] Index: openacs-4/packages/assessment/www/asm-admin/toggle-publish.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/assessment/www/asm-admin/toggle-publish.xql,v diff -u -r1.1 -r1.1.2.1 --- openacs-4/packages/assessment/www/asm-admin/toggle-publish.xql 28 Nov 2006 18:17:53 -0000 1.1 +++ openacs-4/packages/assessment/www/asm-admin/toggle-publish.xql 23 Mar 2007 16:35:56 -0000 1.1.2.1 @@ -1,6 +1,26 @@ + + + select publish_status from cr_items where item_id=:assessment_id + + + + + + -- group sections with item_counts, then select those sections with 0 items + select title + from (select asm.section_id, count(ism.as_item_id) as count, cr.title + from cr_items i, cr_revisions cr, as_assessment_section_map asm left join as_item_section_map ism using (section_id) + where i.item_id=:assessment_id + and asm.assessment_id=i.latest_revision + and cr.revision_id = asm.section_id + group by asm.section_id, cr.title) item_counts + where count = 0 + + + update cr_items set publish_status = (case when publish_status is null or publish_status <> 'live' then 'live' else null end) where item_id=:assessment_id