--- loncom/interface/lonsyllabus.pm 2013/05/15 17:31:52 1.124 +++ loncom/interface/lonsyllabus.pm 2013/08/26 23:38:07 1.129 @@ -1,7 +1,7 @@ # The LearningOnline Network # Syllabus # -# $Id: lonsyllabus.pm,v 1.124 2013/05/15 17:31:52 raeburn Exp $ +# $Id: lonsyllabus.pm,v 1.129 2013/08/26 23:38:07 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -71,6 +71,7 @@ sub handler { } # ------------------------------------- There is such a course, get environment my %courseenv=&Apache::lonnet::dump('environment',$cdom,$cnum); + my $crstype = &Apache::loncommon::course_type(); # ------------------------------------------------------------ Print the screen @@ -117,24 +118,26 @@ sub handler { } unless ($allowed && $forceedit) { my $file=&Apache::lonnet::filelocation("",$item); - if ($file =~ /\.(sty|css|js|txt|tex|html?)$/) { - my $filetype; - if ($file =~ /\.(sty|css|js|txt|tex)$/) { - $filetype=$1; - } else { - $filetype='html'; - } - my $result = ''; + if ($file =~ /\.(tex|x?html?)$/) { + my $filetype = $1; my $filecontents=&Apache::lonnet::getfile($file); if ($filecontents eq -1) { $r->print(&mt('Syllabus file unavailable')); - } elsif ($filetype eq 'html') { + } elsif ($filetype eq 'tex') { + my $result = &Apache::lontexconvert::converted(\$filecontents, + $env{'form.texengine'}); + my %args; + &get_breadcrumbs($cdom,$cnum,$crstype,\%args); + $r->print(&Apache::loncommon::start_page("Syllabus",undef,\%args). + $result. + &Apache::loncommon::end_page()); + } else { my %mystyle; &Apache::structuretags::reset_problem_globals(); my $oldfile = $env{'request.filename'}; $env{'request.filename'} = $item; - $result = &Apache::lonxml::xmlparse($r,'web',$filecontents, - '',%mystyle); + my $result = &Apache::lonxml::xmlparse($r,'web',$filecontents, + '',%mystyle); &Apache::structuretags::reset_problem_globals(); &Apache::lonhomework::finished_parsing(); $env{'request.filename'} = $oldfile; @@ -153,7 +156,6 @@ sub handler { } } - my $crstype = &Apache::loncommon::course_type(); # ------------------------------ The buck stops here: internal syllabus display # --------------------------------------------------------- The syllabus fields @@ -330,18 +332,18 @@ sub handler { } &Apache::lontemplate::print_start_template($r,&mt('Personnel'),'LC_Box', 'box_000_showpeople',$display); - $r->print(&get_personnel($r,$target,$cdom,$cnum,$allowed)); + $r->print(&get_personnel($r,$target,$cdom,$cnum,$allowed,$crstype,\%syllabus)); &Apache::lontemplate::print_end_template($r); } else { unless ($hidepersonnel) { &Apache::lontemplate::print_start_template($r,&mt('Personnel'),'LC_Box'); - $r->print(&get_personnel($r,$target,$cdom,$cnum,$allowed)); + $r->print(&get_personnel($r,$target,$cdom,$cnum,$allowed,$crstype,\%syllabus)); &Apache::lontemplate::print_end_template($r); } } } else { unless ($hidepersonnel) { - $r->print(&get_personnel($r,$target,$cdom,$cnum,$allowed)); + $r->print(&get_personnel($r,$target,$cdom,$cnum,$allowed,$crstype,%syllabus)); } } # -------------------------------------------------------------- Announcements? @@ -404,10 +406,6 @@ sub handler { } # ---------------------------------------------------------------- Get syllabus if (($syllabus{'uploaded.lastmodified'}) || ($allowed)) { - if ($allowed) { - $r->print('
'); - } - my $url_include_handler = sub { my ($r, $field, $message, $group, $data_ref, $fields_ref, $target, $allowed, $display) = @_; my %data = %{$data_ref}; @@ -454,7 +452,7 @@ sub handler { $target, $allowed, Apache::lontemplate->RICH_TEXT_DETECT_HTML, \%custom_hash, undef,\%displayfields,\%noshow); if ($allowed) { - $r->print('
'. + $r->print(''. &Apache::lonhtmlcommon::htmlareaselectactive()); } } else { @@ -664,7 +662,26 @@ ENDSCRIPT {href=>$r->uri, text=>"Course syllabus"}); $args->{'bread_crumbs'} = $brcrum; - } elsif ($env{'form.folderpath'} =~ /^supplemental/) { + } else { + &get_breadcrumbs($cdom,$cnum,$crstype,$args); + } + if ($allowed) { + my %loaditem = ( + onload => 'setTemplateBoxes();', + ); + $args->{'add_entries'} = \%loaditem; + } + my $start_page = + &Apache::loncommon::start_page("Syllabus", $rss_link.$js,$args); + if ($start_page) { + $r->print($start_page); + } +} + +sub get_breadcrumbs{ + my ($cdom,$cnum,$crstype,$args) = @_; + return unless (ref($args) eq 'HASH'); + if ($env{'form.folderpath'} =~ /^supplemental/) { my $title = $env{'form.title'}; if ($title eq '') { $title = &mt('Syllabus'); @@ -685,17 +702,7 @@ ENDSCRIPT ]; } } - if ($allowed) { - my %loaditem = ( - onload => 'setTemplateBoxes();', - ); - $args->{'add_entries'} = \%loaditem; - } - my $start_page = - &Apache::loncommon::start_page("Syllabus", $rss_link.$js,$args); - if ($start_page) { - $r->print($start_page); - } + return; } sub chooser { @@ -817,8 +824,16 @@ sub syllabus_file_info { my $absurl = $protocol.'://'.&Apache::lonnet::hostname($lonhost).$item; my ($filename) = ($item =~ m{([^/]+)$}); my $file=&Apache::lonnet::filelocation("",$item); - my $depbutton; - if ($file =~ /\.html?$/) { + my ($depbutton,$filetype,$editable); + if ($file =~ /\.(xhtml|xml|tex|html|htm)$/) { + $filetype=$1; + } + if ($filetype) { + unless ($filetype eq 'tex') { + $filetype='html'; + } + } + if ($filetype eq 'html') { my $filecontents=&Apache::lonnet::getfile($file); unless ($filecontents eq -1) { my $mm = new File::MMagic; @@ -833,12 +848,13 @@ sub syllabus_file_info { \%codebase, {'context' => 'rewrites', 'ignore_remote_references' => 1,}); - $depbutton = (' ' x 3). - &editfile_button($item,$context). - &editbutton_js(); + $editable = 1; } } } + $depbutton = (' ' x 3). + &editfile_button($item,$context,$editable). + &editbutton_js(); return ($absurl,$filename,$depbutton); } @@ -920,49 +936,121 @@ sub fields_check_uncheck { } sub get_personnel { - my ($r,$target,$cdom,$cnum,$allowed) = @_; + my ($r,$target,$cdom,$cnum,$allowed,$crstype,$syllabus) = @_; + my (%hiddenroles,%hiddenusers); + if (ref($syllabus) eq 'HASH') { + if (ref($syllabus->{'personnel'}) eq 'HASH') { + if ($syllabus->{'personnel'}{'hiderole'}) { + map { $hiddenroles{$_} = 1; } split(/,/,$syllabus->{'personnel'}{'hiderole'}); + } + if ($syllabus->{'personnel'}{'hideuser'}) { + map { $hiddenusers{$_} = 1; } split(/,/,$syllabus->{'personnel'}{'hideuser'}); + } + } + } my $output; - my %coursepersonnel=&Apache::lonnet::get_course_adv_roles($cdom.'/'.$cnum); + my %coursepersonnel=&Apache::lonnet::get_course_adv_roles($cdom.'/'.$cnum,1); if ($target ne 'tex') { - $r->print(&Apache::lonhtmlcommon::start_pick_box()); + if ($allowed) { + $r->print(&Apache::loncommon::start_data_table(). + &Apache::loncommon::start_data_table_header_row(). + ''.&mt('Role hidden?').''.&mt('Role').''. + ''.&mt('Personnel (hidden if checked)').''. + &Apache::loncommon::end_data_table_header_row()); + } else { + $r->print(&Apache::lonhtmlcommon::start_pick_box()); + } } else { $r->print('\begin{tabular}{|p{0.45\textwidth}|p{0.45\textwidth}|}\hline'); } my @personnel=sort(keys(%coursepersonnel)); my $lastpers=$personnel[$#personnel]; foreach my $element (@personnel) { + unless ($allowed) { + next if ($hiddenroles{$element}) + } + my ($role,$sec); + if ($element =~ /:/) { + ($role,$sec) = split(/:/,$element); + } else { + $role = $element; + } + my $roletext = &Apache::lonnet::plaintext($role,$crstype); + if ($sec) { + $roletext .=' ('.&Apache::lonlocal::mt('Section [_1]',$sec).')'; + } if ($target ne 'tex') { - $r->print(&Apache::lonhtmlcommon::row_title($element)); + if ($allowed) { + my $checked; + if ($hiddenroles{$element}) { + $checked = ' checked="checked"'; + } + $r->print(&Apache::loncommon::start_data_table_row(). + ''. + ''. + ''.$roletext.''); + } else { + $r->print(&Apache::lonhtmlcommon::row_title($roletext)); + } } else { - $r->print(' '.&Apache::lonxml::xmlparse($r,'tex',$element).' & '); + $r->print(' '.&Apache::lonxml::xmlparse($r,'tex',$roletext).' & '); } my @coursepersonlist; foreach my $user (split(/\,/,$coursepersonnel{$element})) { my ($puname,$pudom)=split(/\:/,$user); if ($target ne 'tex') { my $courseperson = &Apache::loncommon::plainname($puname,$pudom); - if (($env{'user.name'} eq '') || ($env{'user.name'} eq 'public') || - ($env{'user.domain'} eq '') || ($env{'user.domain'} eq 'public')) { - push(@coursepersonlist,$courseperson); + my $checked; + if ($hiddenusers{$element.'&'.$puname.':'.$pudom}) { + $checked = ' checked="checked"'; + } + if ($allowed) { + my $item = ''.(' 'x2).' '; + push(@coursepersonlist,$item); + } else { - push(@coursepersonlist,&Apache::loncommon::aboutmewrapper($courseperson, - $puname,$pudom)); + next if ($hiddenusers{$element.'&'.$puname.':'.$pudom}); + if (($env{'user.name'} eq '') || ($env{'user.name'} eq 'public') || + ($env{'user.domain'} eq '') || ($env{'user.domain'} eq 'public')) { + push(@coursepersonlist,$courseperson); + } else { + push(@coursepersonlist,&Apache::loncommon::aboutmewrapper($courseperson, + $puname,$pudom)); + } } } else { push(@coursepersonlist,&Apache::loncommon::plainname($puname, $pudom).' '); } } - $r->print(join(", ",@coursepersonlist)); + if ($allowed) { + $r->print(join('',@coursepersonlist)); + } else { + $r->print(join(', ',@coursepersonlist)); + } if ($target ne 'tex') { - my $lastclose=$element eq $lastpers?1:0; - $r->print(&Apache::lonhtmlcommon::row_closure($lastclose)); + if ($allowed) { + $r->print(''.&Apache::loncommon::end_data_table_row()); + } else { + my $lastclose=$element eq $lastpers?1:0; + $r->print(&Apache::lonhtmlcommon::row_closure($lastclose)); + } } else { $r->print('\\\\ \hline'); } } if ($target ne 'tex') { - $r->print(&Apache::lonhtmlcommon::end_pick_box()); + if ($allowed) { + $r->print(&Apache::loncommon::end_data_table()); + } else { + $r->print(&Apache::lonhtmlcommon::end_pick_box()); + } } else { $r->print('\end{tabular}\\\\'); } @@ -975,10 +1063,10 @@ sub save_changes { unless ((ref($syllabus) eq 'HASH') && (ref($syllabusfields) eq 'HASH')) { return ($earlyout,$uploaded,$external,$minimal,$output); } - if ($env{'form.deleteuploaded'}) { + if (($env{'form.deleteuploaded_file'}) || ($env{'form.deleteuploaded_minimal'})) { my %storehash; if (($env{'form.choice'} eq 'file') && - ($env{'form.deleteuploaded'} eq 'file') && ($uploaded =~ /\w/)) { + ($env{'form.deleteuploaded_file'}) && ($uploaded =~ /\w/)) { &Apache::lonnet::delenv('course.'.$env{'request.course.id'}.'.uploadedsyllabus'); &Apache::lonnet::delenv('course.'.$env{'request.course.id'}.'.externalsyllabus'); $storehash{'uploadedsyllabus'} = ''; @@ -987,7 +1075,7 @@ sub save_changes { undef($uploaded); undef($external); } elsif (($env{'form.choice'} eq 'minimal') && - ($env{'form.deleteuploaded'} eq 'minimal') && ($minimal =~ /\w/)) { + ($env{'form.deleteuploaded_minimal'}) && ($minimal =~ /\w/)) { &Apache::lonnet::delenv('course.'.$env{'request.course.id'}.'.externalsyllabus'); &Apache::lonnet::delenv('course.'.$env{'request.course.id'}.'.minimalsyllabus'); $storehash{'externalsyllabus'} = ''; @@ -1010,6 +1098,33 @@ sub save_changes { my ($prefix) = split(/_/,$field); $syllabus->{'uploaded.fields'} .= $prefix.','; } + if ($field eq '000_showpeople') { + my @hideusers = &Apache::loncommon::get_env_multiple('form.hideuser'); + my @hideroles = &Apache::loncommon::get_env_multiple('form.hiderole'); + my %coursepersonnel=&Apache::lonnet::get_course_adv_roles($cdom.'/'.$cnum,1); + my %personnel; + foreach my $key (keys(%coursepersonnel)) { + map { $personnel{$key}{$_} = 1; } split(/,/,$coursepersonnel{$key}); + } + %{$syllabus->{'personnel'}} = (); + $syllabus->{'personnel'}{'hideuser'} = ''; + $syllabus->{'personnel'}{'hiderole'} = ''; + foreach my $role (@hideroles) { + if (exists($personnel{$role})) { + $syllabus->{'personnel'}{'hiderole'} .= $role.','; + } + } + foreach my $item (@hideusers) { + my ($role,$user) = split(/\&/,$item); + if (ref($personnel{$role}) eq 'HASH') { + if ($personnel{$role}{$user}) { + $syllabus->{'personnel'}{'hideuser'} .= $item.','; + } + } + } + $syllabus->{'personnel'}{'hideuser'} =~ s/,$//; + $syllabus->{'personnel'}{'hiderole'} =~ s/,$//; + } } $syllabus->{'uploaded.fields'} =~ s/,$//; } @@ -1232,7 +1347,7 @@ END sub update_syllabus_env { my ($cdom,$cnum,$courseenv,$saved,$uploaded,$minimal,$external) = @_; - return unless(ref($courseenv) eq 'HASH'); + return ($uploaded,$minimal,$external) unless(ref($courseenv) eq 'HASH'); my $now = time; my (@envkeys,%storehash); if ($saved eq 'template') { @@ -1307,7 +1422,7 @@ sub home_http_host { if ($home ne 'no_host') { my $protocol = $Apache::lonnet::protocol{$home}; $protocol = 'http' if ($protocol ne 'https'); - return $protocol.'//'.$home; + return $protocol.'://'.$home; } return; } @@ -1397,18 +1512,28 @@ sub return_to_editor { } sub editfile_button { - my ($url,$context) = @_; + my ($url,$context,$editable) = @_; my $edittext=&mt('Edit'); my $deltext=&mt('Delete'); - return <<"END"; - -     - - -END + my $output; + if ($editable) { + $output = ' + +    '; + } + $output .= ' + + + '; + return $output; } sub editbutton_js { + my %lt = &Apache::lonlocal::texthash( + min => 'Are you sure you want to delete the contents of the syllabus template?', + file => 'Are you sure you want to delete the uploaded syllabus file?', + noundo => 'This action cannot be reversed.' + ); return < //