[LON-CAPA-cvs] cvs: loncom(bz6209) /interface lonsyllabus.pm
faziophi
faziophi@source.lon-capa.org
Mon, 15 Feb 2010 16:05:32 -0000
faziophi Mon Feb 15 16:05:32 2010 EDT
Modified files: (Branch: bz6209)
/loncom/interface lonsyllabus.pm
Log:
Work-in-progress commit for bug 6209.
--> Adds capability to delete fields from display for lonsyllabus.
--> Allows basic field title renaming capability.
Index: loncom/interface/lonsyllabus.pm
diff -u loncom/interface/lonsyllabus.pm:1.106.2.1 loncom/interface/lonsyllabus.pm:1.106.2.2
--- loncom/interface/lonsyllabus.pm:1.106.2.1 Mon Feb 15 05:31:00 2010
+++ loncom/interface/lonsyllabus.pm Mon Feb 15 16:05:32 2010
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Syllabus
#
-# $Id: lonsyllabus.pm,v 1.106.2.1 2010/02/15 05:31:00 faziophi Exp $
+# $Id: lonsyllabus.pm,v 1.106.2.2 2010/02/15 16:05:32 faziophi Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -62,7 +62,7 @@
my (undef,undef,$cdom,$cnum)=split(/\//,$r->uri);
# ------------------------------------------------------------ Get query string
&Apache::loncommon::get_unprocessed_cgi
- ($ENV{'QUERY_STRING'},['delete', 'field', 'forcestudent','register','forceedit','forceflush','wrapperdisplay']);
+ ($ENV{'QUERY_STRING'},['delete', 'rename', 'field', 'forcestudent','register','forceedit','forceflush','wrapperdisplay']);
# ----------------------------------------------------- Is this even a course?
my $homeserver=&Apache::lonnet::homeserver($cnum,$cdom);
if ($homeserver eq 'no_host') {
@@ -189,12 +189,15 @@
&Apache::lonnet::del('syllabus', ['properties.v2_converted'], $cdom, $cnum);
delete $syllabus{'data.old_new_map'};
&Apache::lonnet::del('syllabus', ['data.old_new_map'], $cdom, $cnum);
+ delete $syllabus{'data.deleted_fields'};
+ &Apache::lonnet::del('syllabus', ['data.deleted_fields'], $cdom, $cnum);
%syllabus=&Apache::lonnet::dump('syllabus',$cdom,$cnum); # load db
$r->print("Flushed syllabus DB file.<br />");
$r->print("Syllabus conflict: ".$syllabus{'properties.v2_conflict'}."<br />");
}
$r->print("Existing fields: ".$syllabus{'data.fields'}."<br />");
$r->print("Old-new map: ".$syllabus{'data.old_new_map'}."<br />");
+ $r->print("Deleted fields: ".$syllabus{'data.deleted_fields'}."<br />");
if (!exists($syllabus{'data.fields'})) {
# convert existing 2.x data to new DB fields
# which become new primary data source for document
@@ -241,7 +244,54 @@
#do not delete if file in v2 conversion mode
if (exists($data{'data.field.'.$field}) &&
!exists($data{'properties.v2_converted'})) {
- $r->print("Field can be deleted.<br />");
+ $r->print("Field '$field' can be deleted.<br />");
+ # linearly parse "data.fields" and remove it
+ for (my $i = 0; $i < length(@fields); $i++) {
+ if ($fields[$i] eq $field) {
+ splice(@fields, $i, 1);
+ $r->print("Removed entry $i from 'data.fields'<br />");
+ }
+ }
+ # if "data.deleted" does not exist, create it
+ my @deleted;
+ if (!exists($data{'data.deleted_fields'})) {
+ @deleted = [];
+ } else {
+ @deleted = @{thaw($data{'data.deleted_fields'})};
+ }
+ # only if deleted does not exist in 'data.deleted', push it
+ my $push = 1;
+ for (my $i = 0; $i < length(@deleted); $i++) {
+ if ($deleted[$i] eq $field) {
+ $push = 0;
+ last;
+ }
+ }
+ unless (!$push) {
+ push(@deleted, $field);
+ }
+ $data{'data.fields'} = freeze(\@fields);
+ $data{'data.deleted_fields'} = freeze(\@deleted);
+
+ &Apache::lonnet::put('syllabus',\%data,$cdom,$cnum);
+ }
+ }
+ if (($allowed) && ($env{'form.rename'})) {
+ my $field = $env{'form.rename'};
+ my $new_title = "Hello, World!";
+ chomp($field);
+ $field=~s/[^0-9_]//g;
+ #check if the field exists
+ #do not delete if file in v2 conversion mode
+ if (exists($data{'data.field.'.$field}) &&
+ !exists($data{'properties.v2_converted'})) {
+ #sanitize HTML content
+ $r->print("Rename -- field found.<br />");
+ my %db_entry = %{thaw($data{'data.field.'.$field})};
+ $new_title = &Apache::lonfeedback::clear_out_html($new_title, 1);
+ $db_entry{title} = $new_title;
+ $data{'data.field.'.$field} = freeze(\%db_entry);
+ &Apache::lonnet::put('syllabus',\%data,$cdom,$cnum);
}
}
if (($allowed) && ($env{'form.storesyl'})) {
@@ -253,8 +303,7 @@
if (exists($data{'data.field.'.$syl_field})) {
$r->print("Creating/updated field ".$syl_field."<br />");
%field_hash = exists($data{'data.field.'.$syl_field}) ?
- %{thaw($data{'data.field.'.$syl_field})} :
- ();
+ %{thaw($data{'data.field.'.$syl_field})} : ();
$type = exists($field_hash{type}) ? $field_hash{type} : TYPE_TEXT_HTML;
chomp($field);
$field=~s/\s+$//s;
@@ -590,7 +639,8 @@
$key, $default_rich_text);
&Apache::lontemplate::print_saveall_template($r);
if (!exists($data{'properties.v2_converted'})) {
- $r->print("<a href='?delete=$key&forceedit=1'>Delete</a>");
+ $r->print("<a href='?delete=$key&forceedit=1'>Delete</a> ");
+ $r->print("<a href='?rename=$key&forceedit=1'>Rename to \"Hello, World!\"</a>");
}
$r->print("</div>");
}