Index: dotlrn_packages/lams2conf/www/tooladapter_dlfrum10.tcl =================================================================== RCS file: /usr/local/cvsroot/dotlrn_packages/lams2conf/www/tooladapter_dlfrum10.tcl,v diff -u -r1.1 -r1.2 --- dotlrn_packages/lams2conf/www/tooladapter_dlfrum10.tcl 6 Aug 2008 07:33:49 -0000 1.1 +++ dotlrn_packages/lams2conf/www/tooladapter_dlfrum10.tcl 12 Aug 2008 02:59:21 -0000 1.2 @@ -1,5 +1,4 @@ # packages/lams2conf/www/tooladapter_forum.tcl - ad_page_contract { Tool Adapter for Forum @@ -10,11 +9,13 @@ @cvs-id $Id$ } { method - extToolContentID + extToolContentID:optional ts un hs cs + upload_file:trim,optional + upload_file.tmpfile:optional,tmpfile } -properties { } -validate { } -errors { @@ -65,19 +66,35 @@ import { # gets the file from LAMS with the content of the forum + + if { ![empty_string_p $upload_file] && [file isfile ${upload_file.tmpfile}]} { + + # if the file exists and it's indeed a file, + # then import the instance using the content of the file, + # the course_id and user_id + + set new_extToolContentID [forum::lams::import_instance -file_path ${upload_file.tmpfile} -user_id $username -course_id $course_id] + + ns_log Debug "Import: newextToolContentID $new_extToolContentID " + ReturnHeaders "text/plain" + ns_write $new_extToolContentID + ad_script_abort + + } else { + + # error with the input, return a -1 to denote error. + ReturnHeaders "text/plain" + ns_write "-1" + ad_script_abort + } + } export { - # exports the content of the forum + # exports the content of the forum to a file - # gets the content of the forum - forum::get -forum_id $forum_id -array forum + forum::lams::export_instance -forum_id $extToolContentID - # exports the array to text - set export_forum_as_string [array get forum] - - # returns the text from the array - ns_returnfile 200 text/plain $export_forum_as_string ad_script_abort } Index: dotlrn_packages/packages/forums/tcl/forums-lams-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/dotlrn_packages/packages/forums/tcl/forums-lams-procs.tcl,v diff -u -r1.1 -r1.2 --- dotlrn_packages/packages/forums/tcl/forums-lams-procs.tcl 6 Aug 2008 07:34:35 -0000 1.1 +++ dotlrn_packages/packages/forums/tcl/forums-lams-procs.tcl 12 Aug 2008 03:07:21 -0000 1.2 @@ -87,3 +87,77 @@ } +ad_proc -public forum::lams::export_instance { + {-forum_id ""} +} { + Exports an instance of forum +} { + + # gets the content of the forum + forum::get -forum_id $forum_id -array forum + + # exports the array to text + set export_forum_as_string [array get forum] + + set tmp_folder [ns_tmpnam] + file mkdir $tmp_folder + set path_to_file [file join $tmp_folder forum_$forum_id] + + set filer [open $path_to_file w+] + + puts -nonewline $filer $export_forum_as_string + + close $filer + + # send the file back to the call + + ns_set put [ad_conn outputheaders] Content-Disposition "attachment;filename=\"forum_$forum_id.txt\"" + ns_set put [ad_conn outputheaders] Content-Type "text/txt" + ns_set put [ad_conn outputheaders] Content-Size "[file size $path_to_file]" + ns_returnfile 200 text/txt $path_to_file + + # clean up + file delete -force $path_to_file + ad_script_abort + +} + +ad_proc -public forum::lams::import_instance { + -file_path:required + -user_id + -course_id +} { + Import an instance of forum +} { + + # open file + + set filer [open $file_path r] + + set content [read $filer] + + ns_log Debug "Importing tool content: $content" + + array set forum $content + + close $filer + + set forum_name $forum(name) + set forum_charter $forum(charter) + set presentation_type $forum(presentation_type) + set posting_policy $forum(posting_policy) + set forum_package_id [forum::lams::get_package_instance -community_id $course_id] + + set new_forum_id [forum::new -name $forum_name \ + -charter $forum_charter \ + -presentation_type $presentation_type \ + -posting_policy $posting_policy \ + -package_id $forum_package_id \ + ] + + forum::lams::is_lams -forum_id $new_forum_id + + return $new_forum_id + +} +