--- loncom/interface/lonsyllabus.pm 2010/02/15 05:31:00 1.106.2.1 +++ loncom/interface/lonsyllabus.pm 2010/02/15 20:28:51 1.106.2.3 @@ -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.3 2010/02/15 20:28:51 faziophi Exp $ # # Copyright Michigan State University Board of Trustees # @@ -62,7 +62,7 @@ sub handler { 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') { @@ -147,6 +147,102 @@ function getIndexByName(item) { ENDSCRIPT } + $js .= <<'ENDSCRIPT'; + + + + +ENDSCRIPT my $start_page = &Apache::loncommon::start_page("Syllabus", $rss_link.$js, {'function' => undef, @@ -189,17 +285,20 @@ ENDSCRIPT &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.
"); $r->print("Syllabus conflict: ".$syllabus{'properties.v2_conflict'}."
"); } - $r->print("Existing fields: ".$syllabus{'data.fields'}."
"); - $r->print("Old-new map: ".$syllabus{'data.old_new_map'}."
"); + #$r->print("Existing fields: ".$syllabus{'data.fields'}."
"); + #$r->print("Old-new map: ".$syllabus{'data.old_new_map'}."
"); + #$r->print("Deleted fields: ".$syllabus{'data.deleted_fields'}."
"); if (!exists($syllabus{'data.fields'})) { # convert existing 2.x data to new DB fields # which become new primary data source for document %data = %{convert_from_v2($r, \%syllabus, \%syllabusfields, 0)}; - $r->print("New fields order: ".$data{'data.fields'}."
"); + #$r->print("New fields order: ".$data{'data.fields'}."
"); &Apache::lonnet::put('syllabus',\%data,$cdom,$cnum); } elsif ( !exists($syllabus{'properties.v2_converted'}) && exists($syllabus{'uploaded.lastmodified'}) && @@ -241,7 +340,54 @@ ENDSCRIPT #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.
"); + #$r->print("Field '$field' can be deleted.
"); + # 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'
"); + } + } + # 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.
"); + 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'})) { @@ -251,10 +397,9 @@ ENDSCRIPT my %field_hash; # only update a field if it already exists! if (exists($data{'data.field.'.$syl_field})) { - $r->print("Creating/updated field ".$syl_field."
"); + #$r->print("Creating/updated field ".$syl_field."
"); %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; @@ -310,9 +455,9 @@ ENDSCRIPT #2.x compatibility: write to old fields with new mapped fields my %old_new_map = %{thaw($data{'data.old_new_map'})}; foreach my $old_field (keys(%old_new_map)) { - $r->print("Looking for: ".$old_field." at ".$old_new_map{$old_field}."
"); + #$r->print("Looking for: ".$old_field." at ".$old_new_map{$old_field}."
"); if (exists($data{'data.field.'.$old_new_map{$old_field}})) { - $r->print("updating old field ".$old_field."
"); + #$r->print("updating old field ".$old_field."
"); my %new_field = %{thaw($data{'data.field.'.$old_new_map{$old_field}})}; $data{$old_field} = $new_field{content}; } @@ -465,17 +610,11 @@ ENDSCRIPT my $day = &Apache::lonannounce::showday(time,2, &Apache::lonannounce::readcalendar($cdom.'_'.$cnum)); if ($target ne 'tex') { - if ($allowed) { - &Apache::lontemplate::print_start_template($r,'RSS Feeds and Blogs','LC_Box'); - $r->print(&Apache::lonrss::advertisefeeds($cnum,$cdom,$forceedit)); - my $editurl= &Apache::lonnet::absolute_url().'/adm/'.$cdom.'/'.$cnum.'/_rss.html'; - $r->print( ''.&mt('New RSS Feed or Blog').''); - &Apache::lontemplate::print_end_template($r); - } elsif (&Apache::lonrss::advertisefeeds($cnum,$cdom) ne '') { - &Apache::lontemplate::print_start_template($r,'RSS Feeds and Blogs','LC_Box'); - $r->print(&Apache::lonrss::advertisefeeds($cnum,$cdom,$forceedit)); - &Apache::lontemplate::print_end_template($r); + if (($syllabus{'uploaded.lastmodified'}) || ($allowed)) { + $r->print("
"); + &print_field_sortable($r, \%data, $target, $allowed, Apache::lontemplate->RICH_TEXT_DETECT_HTML); } + $r->print("
\n"); } else { $r->print(&Apache::lonxml::xmlparse($r,'tex',$day)); @@ -484,7 +623,7 @@ ENDSCRIPT # ---------------------------------------------------------------- Get syllabus if (($syllabus{'uploaded.lastmodified'}) || ($allowed)) { if ($allowed) { - $r->print('
'. + $r->print(''. ''); } my @htmlids=(); @@ -535,6 +674,18 @@ ENDSCRIPT $r->print('
'. &Apache::lonhtmlcommon::htmlareaselectactive(@htmlids)); } + if ($target ne 'tex') {$r->print('

 

');} + if ($allowed) { + &Apache::lontemplate::print_start_template($r,'RSS Feeds and Blogs','LC_Box'); + $r->print(&Apache::lonrss::advertisefeeds($cnum,$cdom,$forceedit)); + my $editurl= &Apache::lonnet::absolute_url().'/adm/'.$cdom.'/'.$cnum.'/_rss.html'; + $r->print( ''.&mt('New RSS Feed or Blog').''); + &Apache::lontemplate::print_end_template($r); + } elsif (&Apache::lonrss::advertisefeeds($cnum,$cdom) ne '') { + &Apache::lontemplate::print_start_template($r,'RSS Feeds and Blogs','LC_Box'); + $r->print(&Apache::lonrss::advertisefeeds($cnum,$cdom,$forceedit)); + &Apache::lontemplate::print_end_template($r); + } } else { if ($target ne 'tex') {$r->print('

');} else {$r->print('\par ');} $r->print(&mt('No syllabus information provided.')); @@ -553,6 +704,25 @@ ENDSCRIPT return OK; } +sub print_field_sortable { + my ($r, $data_ref, $target, $allowed, $default_rich_text, $group) = @_; + my %data = %{$data_ref}; + my @fields = @{thaw($data{'data.fields'})}; + $r->print("

+ +
+\n"); + foreach my $key (@fields) { + my %field = %{thaw($data{'data.field.'.$key})}; + $r->print("
  • $field{title}
  • \n"); + } + $r->print(" +
    +
    + +
    \n"); +} + sub print_template_new_fields { my ($r, $data_ref, $target, $allowed, $default_rich_text, $custom_handlers_ref, $group) = @_; my @html_ids = (); @@ -582,7 +752,7 @@ sub print_template_new_fields { $message=&Apache::lontexconvert::msgtexconverted($message); if ($target ne 'tex') { #output of syllabusfields will be generated here. - &Apache::lontemplate::print_start_template($r,$title,'LC_Box'); + &Apache::lontemplate::print_start_template($r,$title,'LC_Box', 'box-'.$key); $r->print($message); if ($allowed) { $r->print("
    "); @@ -590,7 +760,8 @@ sub print_template_new_fields { $key, $default_rich_text); &Apache::lontemplate::print_saveall_template($r); if (!exists($data{'properties.v2_converted'})) { - $r->print("Delete"); + $r->print("Delete "); + $r->print("Rename to \"Hello, World!\""); } $r->print("
    "); }