--- loncom/interface/londocs.pm 2013/12/18 23:03:43 1.572 +++ loncom/interface/londocs.pm 2016/11/23 16:42:25 1.613 @@ -1,7 +1,7 @@ # The LearningOnline Network # Documents # -# $Id: londocs.pm,v 1.572 2013/12/18 23:03:43 raeburn Exp $ +# $Id: londocs.pm,v 1.613 2016/11/23 16:42:25 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -43,9 +43,13 @@ use Apache::lonnavdisplay(); use Apache::lonextresedit(); use Apache::lontemplate(); use Apache::lonsimplepage(); +use Apache::lonhomework(); +use Apache::lonpublisher(); use HTML::Entities; use HTML::TokeParser; use GDBM_File; +use File::MMagic; +use File::Copy; use Apache::lonlocal; use Cwd; use LONCAPA qw(:DEFAULT :match); @@ -301,14 +305,14 @@ ENDJS if ($contents{content}) { $content .= '
-

Content

'. +

'.&mt('Content').'

'. $contents{content}.'
'; } if ($contents{webreferences}) { $content .= '
-

Web References

'. +

'.&mt('Web References').'

'. $contents{webreferences}.'
'; } @@ -585,7 +589,7 @@ sub recurse_html { } sub group_import { - my ($coursenum, $coursedom, $folder, $container, $caller, @files) = @_; + my ($coursenum, $coursedom, $folder, $container, $caller, $ltitoolsref, @files) = @_; my ($donechk,$allmaps,%hierarchy,%titles,%addedmaps,%removefrommap, %removeparam,$importuploaded,$fixuperrors); $allmaps = {}; @@ -614,6 +618,89 @@ sub group_import { } } if ($url) { + if ($url =~ m{^(/adm/$coursedom/$coursenum/(\d+)/exttool)s?\:?(.*)$}) { + $url = $1; + my $marker = $2; + my $info = $3; + my ($toolid,%toolhash,%toolsettings); + my @toolinfo = split(/:/,$info); + if ($residx) { + %toolsettings=&Apache::lonnet::dump('exttool_'.$marker,$coursedom,$coursenum); + $toolid = $toolsettings{'id'}; + } else { + $toolid = shift(@toolinfo); + } + $toolid =~ s/\D//g; + ($toolhash{'target'},$toolhash{'width'},$toolhash{'height'}, + $toolhash{'crslabel'},$toolhash{'crstitle'}) = @toolinfo; + $toolhash{'crslabel'} = &unescape($toolhash{'crslabel'}); + $toolhash{'crstitle'} = &unescape($toolhash{'crstitle'}); + if (ref($ltitoolsref) eq 'HASH') { + my @deleted; + if (ref($ltitoolsref->{$toolid}) eq 'HASH') { + if ($ltitoolsref->{$toolid}->{'url'} =~ m{^https://}) { + $url =~ s/exttool$/exttools/; + } + $toolhash{'id'} = $toolid; + if (($toolhash{'target'} eq 'iframe') || ($toolhash{'target'} eq 'window')) { + if ($toolhash{'target'} eq 'window') { + foreach my $item ('width','height') { + $toolhash{$item} =~ s/^\s+//; + $toolhash{$item} =~ s/\s+$//; + } + } + } elsif ($residx) { + $toolhash{'target'} = $toolsettings{'target'}; + if ($toolhash{'target'} eq 'window') { + $toolhash{'width'} = $toolsettings{'width'}; + $toolhash{'height'} = $toolsettings{'height'}; + } + } elsif (ref($ltitoolsref->{$toolid}->{'display'}) eq 'HASH') { + $toolhash{'target'} = $ltitoolsref->{$toolid}->{'display'}->{'target'}; + if ($toolhash{'target'} eq 'window') { + $toolhash{'width'} = $ltitoolsref->{$toolid}->{'display'}->{'width'}; + $toolhash{'height'} = $ltitoolsref->{$toolid}->{'display'}->{'height'}; + } + } + if ($toolhash{'target'} eq 'iframe') { + delete($toolhash{'width'}); + delete($toolhash{'height'}); + if ($residx) { + if ($toolsettings{'width'}) { + push(@deleted,'width'); + } + if ($toolsettings{'height'}) { + push(@deleted,'height'); + } + } + } + if (ref($ltitoolsref->{$toolid}->{'crsconf'}) eq 'HASH') { + foreach my $item ('label','title') { + if ($ltitoolsref->{$toolid}->{'crsconf'}->{$item}) { + $toolhash{'crs'.$item} =~ s/^\s+//; + $toolhash{'crs'.$item} =~ s/\s+$//; + if ($toolhash{'crs'.$item} eq '') { + delete($toolhash{'crs'.$item}); + } + } else { + delete($toolhash{'crs'.$item}); + } + if (($residx) && (exists($toolsettings{'crs'.$item}))) { + unless (exists($toolhash{'crs'.$item})) { + push(@deleted,'crs'.$item); + } + } + } + } + my $putres = &Apache::lonnet::put('exttool_'.$marker,\%toolhash,$coursedom,$coursenum); + if ($putres eq 'ok') { + if (@deleted) { + &Apache::lonnet::del('exttool_'.$marker,\@deleted,$coursedom,$coursenum); + } + } + } + } + } if (($caller eq 'londocs') && ($folder =~ /^default/)) { if (($url =~ /\.(page|sequence)$/) && (!$donechk)) { @@ -651,7 +738,7 @@ sub group_import { } else { $fname =~ s/\W/_/g; } - if (length($fname > 15)) { + if (length($fname) > 15) { $fname = substr($fname,0,14); } my $initialtext = &mt('Replace with your own content.'); @@ -790,12 +877,13 @@ sub log_docs { } sub docs_change_log { - my ($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath)=@_; + my ($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath,$canedit)=@_; my $supplementalflag=($env{'form.folderpath'}=~/^supplemental/); my $js = ''."\n"; + .''."\n" + .''."\n"; # Breadcrumbs &Apache::lonhtmlcommon::clear_breadcrumbs(); @@ -4698,34 +5227,52 @@ sub handler { $r->print(&Apache::loncommon::start_page("$crstype documents",undef, {'force_register' => $showdoc,})); } elsif ($toolsflag) { + my ($breadtext,$breadtitle); + $breadtext = "$crstype Contents"; + if ($canedit) { + $breadtitle = 'Editing '.$crstype.' Contents'; + } else { + $breadtext .= ' (View-only mode)'; + $breadtitle = 'Viewing '.$crstype.' Contents'; + } &Apache::lonhtmlcommon::add_breadcrumb({ - href=>"/adm/coursedocs",text=>"$crstype Contents"}); + href=>"/adm/coursedocs",text=>$breadtext}); $r->print(&Apache::loncommon::start_page("$crstype Contents", $script) .&Apache::loncommon::help_open_menu('','',273,'RAT') .&Apache::lonhtmlcommon::breadcrumbs( - 'Editing Course Contents') + $breadtitle) ); } elsif ($r->uri eq '/adm/supplemental') { my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype); $r->print(&Apache::loncommon::start_page("Supplemental $crstype Content",undef, {'bread_crumbs' => $brcrum,})); } else { + my ($breadtext,$breadtitle,$helpitem); + $breadtext = "$crstype Contents"; + if ($canedit) { + $breadtitle = 'Editing '.$crstype.' Contents'; + $helpitem = 'Docs_Adding_Course_Doc'; + } else { + $breadtext .= ' (View-only mode)'; + $breadtitle = 'Viewing '.$crstype.' Contents'; + $helpitem = 'Docs_Viewing_Course_Doc'; + } &Apache::lonhtmlcommon::add_breadcrumb({ - href=>"/adm/coursedocs",text=>"$crstype Contents"}); + href=>"/adm/coursedocs",text=>$breadtext}); $r->print(&Apache::loncommon::start_page("$crstype Contents", $script, {'add_entries' => $addentries} ) .&Apache::loncommon::help_open_menu('','',273,'RAT') .&Apache::lonhtmlcommon::breadcrumbs( - 'Editing '.$crstype.' Contents', - 'Docs_Adding_Course_Doc') + $breadtitle, + $helpitem) ); } my %allfiles = (); my %codebase = (); my ($upload_result,$upload_output,$uploadphase); - if ($allowed) { + if ($canedit) { if (($env{'form.uploaddoc.filename'}) && ($env{'form.cmd'}=~/^upload_(\w+)/)) { my $context = $1; @@ -4777,7 +5324,7 @@ sub handler { if ($allowed && $toolsflag) { $r->print(&startContentScreen('tools')); - $r->print(&generate_admin_menu($crstype)); + $r->print(&generate_admin_menu($crstype,$canedit)); $r->print(&endContentScreen()); } elsif ((!$showdoc) && (!$uploadphase)) { # ----------------------------------------------------------------------------- @@ -4789,6 +5336,9 @@ sub handler { 'impo' => 'Import', 'lnks' => 'Import from Stored Links', 'impm' => 'Import from Assembled Map', + 'imcr' => 'Import from Course Resources', + 'extr' => 'External Resource', + 'extt' => 'External Tool', 'selm' => 'Select Map', 'load' => 'Load Map', 'newf' => 'New Folder', @@ -4798,6 +5348,9 @@ sub handler { 'sipa' => 'Simple Course Page', 'sipr' => 'Simple Problem', 'webp' => 'Blank Web Page (editable)', + 'stpr' => 'Standard Problem', + 'news' => 'New sub-directory', + 'crpr' => 'Create Problem', 'drbx' => 'Drop Box', 'scuf' => 'External Scores (handgrade, upload, clicker)', 'bull' => 'Discussion Board', @@ -4811,13 +5364,64 @@ sub handler { 'se' => 'Select', 'file' => 'File', 'title' => 'Title', + 'addp' => 'Add Placeholder to course?', + 'uste' => 'Use Template?', + 'fnam' => 'File Name:', + 'loca' => 'Location:', + 'dire' => 'Directory:', + 'cate' => 'Category:', + 'tmpl' => 'Template:', 'comment' => 'Comment', 'parse' => 'Upload embedded images/multimedia files if HTML file', - ); + 'bb5' => 'Blackboard 5', + 'bb6' => 'Blackboard 6', + 'angel5' => 'ANGEL 5.5', + 'webctce4' => 'WebCT 4 Campus Edition', + 'yes' => 'Yes', + 'no' => 'No', + 'er' => 'Editing rights unavailable for your current role', + ); # ----------------------------------------------------------------------------- + + # Calculate free quota space for a user or course. A javascript function checks + # file size to determine if upload should be allowed. + my $quotatype = 'unofficial'; + if ($crstype eq 'Community') { + $quotatype = 'community'; + } elsif ($crstype eq 'Placement') { + $quotatype = 'placement'; + } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.coursecode'}) { + $quotatype = 'official'; + } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.textbook'}) { + $quotatype = 'textbook'; + } + my $disk_quota = &Apache::loncommon::get_user_quota($coursenum,$coursedom, + 'course',$quotatype); # expressed in MB + my $current_disk_usage = 0; + foreach my $subdir ('docs','supplemental') { + $current_disk_usage += &Apache::lonnet::diskusage($coursedom,$coursenum, + "userfiles/$subdir",1); # expressed in kB + } + my $free_space = 1024 * ((1024 * $disk_quota) - $current_disk_usage); + my $usage = $current_disk_usage/1024; # in MB + my $quota = $disk_quota; + my $percent; + if ($disk_quota == 0) { + $percent = 100.0; + } else { + $percent = 100*($current_disk_usage/$disk_quota); + } + $usage = sprintf("%.2f",$usage); + $quota = sprintf("%.2f",$quota); + $percent = sprintf("%.0f",$percent); + my $quotainfo = '

'.&mt('Currently using [_1] of the [_2] available.', + $percent.'%',$quota.' MB').'

'; + my $fileupload=(< - + + FIUP my $checkbox=(< --> CHBO my $imsfolder = $env{'form.folder'}; @@ -4842,17 +5446,17 @@ CHBO

$lt{'cms'}:  - - - - - + + + +

- + IMSFORM @@ -4864,10 +5468,10 @@ IMSFORM FUFORM + my $mapimportjs; + if ($canedit) { + $mapimportjs = "javascript:openbrowser('mapimportform','importmap','sequence,page','');"; + } else { + $mapimportjs = "javascript:alert('".&js_escape($lt{'er'})."');"; + } my $importpubform=(< $lt{'impm'}$help{'Load_Map'} @@ -4890,23 +5500,63 @@ FUFORM $lt{'copm'}
-  $lt{'selm'}
- + onfocus="this.blur();$mapimportjs" $disabled /> +  $lt{'selm'}
+ SEDFFORM + my $importcrsresform; + my ($numdirs,$pickfile) = + &Apache::loncommon::import_crsauthor_form('crsresimportform','coursepath','coursefile', + "resize_scrollbox('contentscroll','1','0');", + undef,'res'); + if ($pickfile) { + $importcrsresform=(< + $lt{'imcr'}$help{'Course_Resources'} +
+ +
+CRSFORM + } + + my $fromstoredjs; + if ($canedit) { + $fromstoredjs = 'open_StoredLinks_Import()'; + } else { + $fromstoredjs = "alert('".&js_escape($lt{'er'})."')"; + } + my @importpubforma = ( { ''.$lt{srch}.'' => $pathitem."$lt{'srch'}" }, { ''.$lt{impo}.'' => "$lt{'impo'}$help{'Importing_LON-CAPA_Resource'}" }, - { ''.$lt{lnks}.'' => "$lt{'lnks'}" }, - { ''.$lt{impm}.'' => $importpubform } - ); + { ''.$lt{lnks}.'' => ''.$lt{'lnks'}.'' }, + { ''.$lt{impm}.'' => $importpubform }, + ); + if ($pickfile) { + push(@importpubforma,{ ''.$lt{imcr}.'' => $importcrsresform}); + } $importpubform = &create_form_ul(&create_list_elements(@importpubforma)); my $extresourcesform = &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem, - $help{'Adding_External_Resource'}); + $help{'Adding_External_Resource'}, + undef,undef,undef,undef,undef,undef,$disabled); + my $exttoolform = + &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem, + $help{'Adding_External_Tool'},undef, + undef,'tool',$coursedom,$coursenum, + \%ltitools,$disabled); if ($allowed) { my $folder = $env{'form.folder'}; if ($folder eq '') { @@ -4979,7 +5629,7 @@ HIDDENFORM $pathitem - $lt{'navc'} + $lt{'navc'} $help{'Navigate_Content'} NNFORM @@ -5040,7 +5690,7 @@ NBFORM $pathitem - $lt{'mypi'} + $lt{'mypi'} $help{'My Personal Information Page'} NAMFORM @@ -5060,7 +5710,7 @@ NASOFORM $pathitem - $lt{'rost'} + $lt{'rost'} $help{'Course_Roster'} NROSTFORM @@ -5084,7 +5734,224 @@ NROSTFORM $help{'Web_Page'} NWEBFORM - + + my @ids=&Apache::lonnet::current_machine_ids(); + my %select_menus; + my $numauthor = 0; + my $numcrsdirs = 0; + my $toppath = "/priv/$env{'user.domain'}/$env{'user.name'}"; + if ($env{'user.author'}) { + $numauthor ++; + $select_menus{'author'}->{'text'} = &Apache::lonnet::plaintext('au'); + if (grep(/^\Q$env{'user.home'}\E$/,@ids)) { + my $is_home = 1; + my %subdirs; + &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs); + $select_menus{'author'}->{'default'} = '/'; + $select_menus{'author'}->{'select2'}->{'/'} = '/'; + my @ordered = ('/'); + foreach my $relpath (sort { lc($a) cmp lc($b) } (keys(%subdirs))) { + $select_menus{'author'}->{'select2'}->{$relpath} = $relpath; + push(@ordered,$relpath); + } + $select_menus{'author'}->{'order'} = \@ordered; + } else { + $select_menus{'author'}->{'select2'}->{'switch'} = &mt('Switch server required'); + $select_menus{'author'}->{'default'} = 'switch'; + $select_menus{'author'}->{'order'} = ['switch']; + } + } + my %roleshash = &Apache::lonnet::get_my_roles($env{'user.name'},$env{'user.domain'},'userroles', + ['active'],['ca','aa']); + my $crshome = $env{'course.'.$env{'request.course.id'}.'.home'}; + my %by_roletype; + if (keys(%roleshash)) { + foreach my $entry (keys(%roleshash)) { + my ($auname,$audom,$roletype) = split(/:/,$entry); + my $key = $entry; + $key =~ s/:/___/g; + $by_roletype{$roletype}{$auname.'___'.$audom} = 1; + $select_menus{$key}->{'text'} = &Apache::lonnet::plaintext($roletype)." ($audom/$auname)"; + my $rolehome = &Apache::lonnet::homeserver($auname,$audom); + if (grep(/^\Q$rolehome\E$/,@ids)) { + my $is_home = 1; + my (%subdirs,@ordered); + my $toppath="/priv/$audom/$auname"; + &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs); + $select_menus{$key}->{'default'} = '/'; + $select_menus{$key}->{'select2'}->{'/'} = '/'; + my @ordered = ('/'); + foreach my $relpath (sort { lc($a) cmp lc($b) } (keys(%subdirs))) { + $select_menus{$key}->{'select2'}->{$relpath} = $relpath; + push(@ordered,$relpath); + } + $select_menus{$key}->{'order'} = \@ordered; + } else { + $select_menus{$key}->{'select2'}->{'switch'} = &mt('Switch server required'); + $select_menus{$key}->{'default'} = 'switch'; + $select_menus{$key}->{'order'} = ['switch']; + } + $numauthor ++; + } + } + my ($pickdir,$showtitle);; + if ($numauthor) { + my @order; + my $defrole; + if ($env{'user.author'}) { + push(@order,'author'); + $defrole = 'author'; + } + if (keys(%by_roletype)) { + foreach my $possrole ('ca','aa') { + if (ref($by_roletype{$possrole}) eq 'HASH') { + foreach my $author (sort { lc($a) cmp lc($b) } (keys(%{$by_roletype{$possrole}}))) { + unless ($defrole) { + $defrole = $author; + } + push(@order,$author.'___'.$possrole); + } + } + } + } + $select_menus{'course'}->{'text'} = &mt('Course Resource'); + if (grep(/^\Q$crshome\E$/,@ids)) { + my $is_home = 1; + my %subdirs; + my $toppath="/priv/$coursedom/$coursenum"; + &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs); + $numcrsdirs = keys(%subdirs); + $select_menus{'course'}->{'default'} = '/'; + $select_menus{'course'}->{'select2'}->{'/'} = '/'; + my @ordered = ('/'); + foreach my $relpath (sort { lc($a) cmp lc($b) } (keys(%subdirs))) { + $select_menus{'course'}->{'select2'}->{$relpath} = $relpath; + push(@ordered,$relpath); + } + $select_menus{'course'}->{'order'} = \@ordered; + } else { + $select_menus{'course'}->{'select2'}->{'switch'} = &mt('Switch server required'); + $select_menus{'course'}->{'default'} = 'switch'; + $select_menus{'course'}->{'order'} = ['switch']; + } + push(@order,'course'); + $pickdir = $lt{'loca'}. + &Apache::loncommon::linked_select_forms('courseresform','
'.$lt{'dire'}, + $defrole,'authorrole','authorpath', + \%select_menus,\@order,'toggleCrsResTitle();', + '','priv').'
'; + $showtitle = 'none'; + } else { + my $is_home; + $showtitle = 'inline'; + if (grep(/^\Q$crshome\E$/,@ids)) { + $is_home = 1; + $pickdir .= ''; + my $toppath="/priv/$coursedom/$coursenum'}"; + my %subdirs; + &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$toppath,'',\%subdirs); + $numcrsdirs = keys(%subdirs); + if ($numcrsdirs) { + $pickdir .= &mt('Directory: ').''; + } else { + $pickdir .= ''."\n"; + } + } + } + + my %seltemplate_menus; + my @files = &Apache::lonhomework::get_template_list('problem'); + my @noexamplelink = ('blank.problem','blank.library','script.library'); + my $currentcategory = ''; + my @ordered = (''); + my %templatehelp; + my $defcategory = ''; + my @catorder = ($defcategory); + $seltemplate_menus{$defcategory}->{'order'} = ['']; + $seltemplate_menus{$defcategory}->{'text'} = ''; + foreach my $file (@files) { + if (ref($file) eq 'ARRAY') { + my ($path,$title,$category,$help) = @{$file}; + next if ($title !~ /\S/); + if (&js_escape($category) ne $currentcategory) { + $currentcategory = &js_escape($category); + push(@catorder,&js_escape($currentcategory)); + $seltemplate_menus{$currentcategory}->{'text'} = $category; + $seltemplate_menus{$currentcategory}->{'default'} = ''; + $seltemplate_menus{$currentcategory}->{'select2'}->{''} = ''; + push(@{$seltemplate_menus{$currentcategory}->{'order'}},''); + } + if ($path) { + $seltemplate_menus{$currentcategory}->{'select2'}->{&js_escape($path)} = $title; + push(@{$seltemplate_menus{$currentcategory}->{'order'}},&js_escape($path)); + if ($help) { + $templatehelp{$path} = $help; + } + } + } + } + + my $templates = $lt{'cate'}.' '. + &Apache::loncommon::linked_select_forms('courseresform','
'.$lt{'tmpl'}.' ', + $defcategory,'tempcategory','template', + \%seltemplate_menus,\@catorder, + "resize_scrollbox('contentscroll','1','0');", + "toggleExampleText();",'template').'
'; + my $templatepreview = ''. + ''.&mt('Example').''; + my $crsresform=(< + $lt{'stpr'}$help{'Course_Resource'} +
+ +
+ +RESFORM my $specialdocumentsform; my @specialdocumentsforma; @@ -5123,7 +5990,7 @@ NFFORM $pathitem - $lt{'syll'} + $lt{'syll'} $help{'Syllabus'} @@ -5135,14 +6002,14 @@ NSYLFORM $pathitem - $lt{'grpo'} + $lt{'grpo'} $help{'Group Portfolio'} NGFFORM @specialdocumentsforma=( {''.$lt{newp}.''=>$newpageform}, - {''.$lt{syll}.''=>$newsylform}, - {''.$lt{navc}.''=>$newnavform}, + {''.$lt{syll}.''=>$newsylform}, + {''.$lt{navc}.''=>$newnavform}, {''.$lt{sipa}.''=>$newsmppageform}, {''.$lt{webp}.''=>$newwebpageform}, ); @@ -5152,6 +6019,11 @@ NGFFORM my @importdoc = ( {''.$lt{extr}.''=>$extresourcesform} ); + if (keys(%ltitools)) { + push(@importdoc, + {''.$lt{extt}.''=>$exttoolform}, + ); + } unless ($container eq 'page') { push(@importdoc, {''.$lt{imsf}.''=>$imspform} @@ -5166,7 +6038,7 @@ NGFFORM {''.$lt{sipr}.''=>$newsmpproblemform}, {''.$lt{drbx}.''=>$newdropboxform}, {''.$lt{scuf}.''=>$newexuploadform}, - + {''.$lt{stpr}.''=>$crsresform}, ); $gradingform = &create_form_ul(&create_list_elements(@gradingforma)); @@ -5174,8 +6046,8 @@ NGFFORM {''.$lt{bull}.''=>$newbulform}, {''.$lt{mypi}.''=>$newaboutmeform}, {''.$lt{abou}.''=>$newaboutsomeoneform}, - {''.$lt{rost}.''=>$newrosterform}, - {''.$lt{grpo}.''=>$newgroupfileform}, + {''.$lt{rost}.''=>$newrosterform}, + {''.$lt{grpo}.''=>$newgroupfileform}, ); $communityform = &create_form_ul(&create_list_elements(@communityforma)); @@ -5193,7 +6065,7 @@ unless ($container eq 'page') { $hadchanges=0; unless (($supplementalflag || $toolsflag)) { my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype, - $supplementalflag,\%orderhash,$iconpath,$pathitem); + $supplementalflag,\%orderhash,$iconpath,$pathitem,\%ltitools,$canedit); if ($error) { $r->print('

'.$error.'

'); } @@ -5258,7 +6130,15 @@ SNFFORM my $supextform = &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem, - $help{'Adding_External_Resource'}); + $help{'Adding_External_Resource'}, + undef,undef,undef,undef,undef,undef, + $disabled); + + my $supexttoolform = + &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem, + $help{'Adding_External_Tool'}, + undef,undef,'tool',$coursedom, + $coursenum,\%ltitools,$disabled); my $supnewsylform=(< @@ -5266,7 +6146,7 @@ SNFFORM $pathitem - $lt{'syll'} + $lt{'syll'} $help{'Syllabus'} SNSFORM @@ -5277,7 +6157,7 @@ SNSFORM $pathitem - $lt{'mypi'} + $lt{'mypi'} $help{'My Personal Information Page'} SNAMFORM @@ -5304,19 +6184,25 @@ SWEBFORM my @specialdocs = ( - {''.$lt{syll}.'' + {''.$lt{syll}.'' =>$supnewsylform}, - {''.$lt{mypi}.'' + {''.$lt{mypi}.'' =>$supnewaboutmeform}, {''.$lt{webp}.''=>$supwebpageform}, ); my @supimportdoc = ( {''.$lt{extr}.'' - =>$supextform}, - {''.$lt{upl}.'' + =>$supextform}); + if (keys(%ltitools)) { + push(@supimportdoc, + {''.$lt{extt}.'' + =>$supexttoolform}); + } + push(@supimportdoc, + {''.$lt{upl}.'' =>$supupdocform}, - ); + ); $supupdocform = &create_form_ul(&create_list_elements(@supimportdoc)); my %suporderhash = ( @@ -5326,7 +6212,7 @@ my %suporderhash = ( ); if ($supplementalflag) { my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype, - $supplementalflag,\%suporderhash,$iconpath,$pathitem); + $supplementalflag,\%suporderhash,$iconpath,$pathitem,\%ltitools,$canedit); if ($error) { $r->print('

'.$error.'

'); } else { @@ -5346,7 +6232,7 @@ my %suporderhash = ( } } elsif ($supplementalflag) { my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype, - $supplementalflag,'',$iconpath,$pathitem); + $supplementalflag,'',$iconpath,$pathitem,$canedit); if ($error) { $r->print('

'.$error.'

'); } @@ -5373,7 +6259,9 @@ my %suporderhash = ( &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).''); } } - $r->print(&Apache::loncommon::end_page()); + unless ($noendpage) { + $r->print(&Apache::loncommon::end_page()); + } return OK; } @@ -5420,7 +6308,7 @@ sub decompression_info { my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'}; my $container='sequence'; my ($pathitem,$hiddenelem); - my @hiddens = ('newidx','comment','position','folderpath'); + my @hiddens = ('newidx','comment','position','folderpath','archiveurl'); if ($env{'form.folderpath'} =~ /\:1$/) { $container='page'; } @@ -5428,7 +6316,7 @@ sub decompression_info { foreach my $item (@hiddens) { if ($env{'form.'.$item}) { $hiddenelem .= ''."\n"; + &HTML::Entities::encode($env{'form.'.$item},'<>&"').'" />'."\n"; } } return ($destination,$dir_root,$londocroot,$docudom,$docuname,$container, @@ -5485,25 +6373,34 @@ sub remove_archive { } else { $delwarning = &mt('An error occurred retrieving the contents of the current folder.'); } - $delwarning .= &mt('As a result the archive file has not been removed.'); + $delwarning .= ' '.&mt('As a result the archive file has not been removed.'); } else { my $currcmd = $env{'form.cmd'}; my $position = $env{'form.position'}; + my $archiveidx = $position; if ($position > 0) { - $env{'form.cmd'} = 'remove_'.$position; - my ($title,$url,@rrest) = - split(/:/,$LONCAPA::map::resources[$LONCAPA::map::order[$position]]); - if (&handle_edit_cmd($docuname,$docudom)) { - ($errtext,$fatal) = &storemap($docuname,$docudom,$map,1); - if ($fatal) { - if ($container eq 'page') { - $delwarning = &mt('An error occurred updating the contents of the current page.'); + if (($env{'form.autoextract_camtasia'}) && (scalar(@LONCAPA::map::order) == 2)) { + $archiveidx = $position-1; + } + $env{'form.cmd'} = 'remove_'.$archiveidx; + my ($title,$url,@rrest) = + split(/:/,$LONCAPA::map::resources[$LONCAPA::map::order[$archiveidx]]); + if ($url eq $env{'form.archiveurl'}) { + if (&handle_edit_cmd($docuname,$docudom)) { + ($errtext,$fatal) = &storemap($docuname,$docudom,$map,1); + if ($fatal) { + if ($container eq 'page') { + $delwarning = &mt('An error occurred updating the contents of the current page.'); + } else { + $delwarning = &mt('An error occurred updating the contents of the current folder.'); + } } else { - $delwarning = &mt('An error occurred updating the contents of the current folder.'); + $delresult = &mt('Archive file removed.'); } - } else { - $delresult = &mt('Archive file removed.'); } + } else { + $delwarning .= &mt('Archive file had unexpected item number in folder.'). + ' '.&mt('As a result the archive file has not been removed.'); } } $env{'form.cmd'} = $currcmd; @@ -5522,7 +6419,7 @@ sub remove_archive { } sub generate_admin_menu { - my ($crstype) = @_; + my ($crstype,$canedit) = @_; my $lc_crstype = lc($crstype); my ($home,$other,%outhash)=&authorhosts(); my %lt= ( # do not translate here @@ -5580,7 +6477,9 @@ sub generate_admin_menu { linktitle => "List the unique identifier used for each resource instance in your $lc_crstype" }, ] - }, + }); + if ($canedit) { + push(@menu, { categorytitle=>'Export', items =>[ { linktext => $lt{'imse'}, @@ -5599,6 +6498,7 @@ sub generate_admin_menu { }, ] }); + } return '
'."\n". ''."\n". &Apache::lonhtmlcommon::generate_menu(@menu)."\n". @@ -5607,15 +6507,16 @@ sub generate_admin_menu { sub generate_edit_table { my ($tid,$orderhash_ref,$to_show,$iconpath,$jumpto,$readfile, - $need_save,$copyfolder) = @_; + $need_save,$copyfolder,$canedit) = @_; return unless(ref($orderhash_ref) eq 'HASH'); my %orderhash = %{$orderhash_ref}; - my $form; - my $activetab; - my $active; + my ($form, $activetab, $active, $disabled); if (($env{'form.active'} ne '') && ($env{'form.active'} ne '00')) { $activetab = $env{'form.active'}; } + unless ($canedit) { + $disabled = ' disabled="disabled"'; + } my $backicon = $iconpath.'clickhere.gif'; my $backtext = &mt('Exit Editor'); $form = '
'. @@ -5679,7 +6580,7 @@ sub generate_edit_table { - +
END @@ -5705,8 +6606,8 @@ END } sub editing_js { - my ($udom,$uname,$supplementalflag) = @_; - my %lt = &Apache::lonlocal::texthash( + my ($udom,$uname,$supplementalflag,$coursedom,$coursenum,$posslti,$londocroot,$canedit) = @_; + my %js_lt = &Apache::lonlocal::texthash( p_mnf => 'Name of New Folder', t_mnf => 'New Folder', p_mnp => 'Name of New Page', @@ -5716,23 +6617,26 @@ sub editing_js { p_msb => 'Title for the Problem', p_mdb => 'Title for the Drop Box', p_mbb => 'Title for the Discussion Board', - p_mwp => 'Title for Web Page', + p_mwp => 'Title for Web Page', + p_mnr => 'Title for the Resource', p_mab => "Enter user:domain for User's Personal Information Page", p_mab2 => 'Personal Information Page of ', p_mab_alrt1 => 'Not a valid user:domain', p_mab_alrt2 => 'Please enter both user and domain in the format user:domain', p_chn => 'New Title', p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!', - p_rmr2a => 'Remove[_99]', - p_rmr2b => '?[_99]', - p_rmr3a => 'Remove those [_2]', - p_rmr3b => 'items?[_2]', + p_rmr2a => 'Remove', + p_rmr2b => '?', + p_rmr3a => 'Remove those', + p_rmr3b => 'items?', + p_rmr4 => 'WARNING: Removing a resource uploaded to a course cannot be undone via "Undo Delete".', + p_rmr5 => 'Push "Cancel" and then use "Cut" instead if you might need to undo this change.', p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!', p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.', - p_ctr2a => 'Cut[_98]', - p_ctr2b => '?[_98]', - p_ctr3a => 'Cut those[_2]', - p_ctr3b => 'items?[_2]', + p_ctr2a => 'Cut', + p_ctr2b => '?', + p_ctr3a => 'Cut those', + p_ctr3b => 'items?', rpck => 'Enter number to pick (e.g., 3)', imsfile => 'You must choose an IMS package for import', imscms => 'You must select which Course Management System was the source of the IMS package', @@ -5743,8 +6647,12 @@ sub editing_js { noor => 'No actions selected or changes to settings specified.', noch => 'No changes to settings specified.', noac => 'No actions selected.', + nofi => 'No file selected', + tinc => 'Title in course', + sunm => 'Sub-directory name', + edri => 'Editing rights unavailable for your current role', ); - + &js_escape(\%js_lt); my $crstype = &Apache::loncommon::course_type(); my $docs_folderpath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'},'<>&"'); my $main_container_page; @@ -5764,8 +6672,20 @@ sub editing_js { my ($map,$id,$res)=&Apache::lonnet::decode_symb($caller); $res = &Apache::lonnet::clutter($res); if (&Apache::lonnet::is_on_map($res)) { - $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($res),'<>&"').'?symb='. + my ($url,$anchor); + if ($res =~ /^([^#]+)#([^#]+)$/) { + $url = $1; + $anchor = $2; + if (($caller =~ m{^([^#]+)\Q#$anchor\E$})) { + $caller = $1.&escape('#').$anchor; + } + } + $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($url),'<>&"').'?symb='. &HTML::Entities::encode($caller,'<>&"'); + if ($anchor ne '') { + $backtourl .= '#'.&HTML::Entities::encode($anchor,'<>&"'); + } + $backtourl = &Apache::loncommon::escape_single($backtourl); } else { $backtourl = '/adm/navmaps'; } @@ -5779,16 +6699,24 @@ sub editing_js { } my $fieldsets = "'ext','doc'"; + if ($posslti) { + $fieldsets .= ",'tool'"; + } unless ($main_container_page) { $fieldsets .=",'ims'"; } if ($supplementalflag) { $fieldsets = "'suppext','suppdoc'"; + if ($posslti) { + $fieldsets .= ",'supptool'"; + } } - - return < 0) { + document.courseresform.authorrole.selectedIndex = 0; + select1priv_changed(); + document.courseresform.authorpath.selectedIndex = 0; + document.courseresform.newresourceadd.selectedIndex = 0; + toggleNewInCourse(document.courseresform); + if (document.getElementById('newresource')) { + document.getElementById('newresource').style.display = 'none'; + } + } else { + if (numcrsdirs) { + document.courseresform.authorpath.selectedIndex = 0; + } + } + if (document.courseresform.newresusetemp.length) { + document.courseresform.newresusetemp[0].checked = true; + toggleWithTemplate(document.courseresform); + } + document.courseresform.newresourcename.value = ''; + } + } + if (document.courseresform.newsubdir.length) { + for (var j=0; j 1) { + select1res_changed(); + } + } + } + document.getElementById('importcrsresform').style.display=disp; + resize_scrollbox('contentscroll','1','0'); + } + return; +} + function makeims(imsform) { if ((imsform.uploaddoc.value == '') || (!imsform.uploaddoc.value)) { - alert("$lt{'imsfile'}"); + alert("$js_lt{'imsfile'}"); return; } if (imsform.source.selectedIndex == 0) { - alert("$lt{'imscms'}"); + alert("$js_lt{'imscms'}"); return; } newWindow = window.open('', 'IMSimport',"HEIGHT=700,WIDTH=750,scrollbars=yes"); imsform.submit(); } -function changename(folderpath,index,oldtitle) { -var title=prompt('$lt{"p_chn"}',oldtitle); -if (title) { -this.document.forms.renameform.markcopy.value=''; -this.document.forms.renameform.title.value=title; -this.document.forms.renameform.cmd.value='rename_'+index; -this.document.forms.renameform.folderpath.value=folderpath; -this.document.forms.renameform.submit(); -} -} - function updatePick(targetform,index,caller) { var pickitem; var picknumitem; @@ -5951,7 +7146,7 @@ function updatePick(targetform,index,cal picknumtext = document.getElementById('randompicknum_'+index); } if (pickitem.checked) { - var picknum=prompt('$lt{"rpck"}',picknumitem.value); + var picknum=prompt('$js_lt{"rpck"}',picknumitem.value); if (picknum == '' || picknum == null) { if (caller == 'check') { pickitem.checked=false; @@ -6101,7 +7296,12 @@ function propagateState(form,param) { return; } -function checkForSubmit(targetform,param,context,idx,folderpath,index,oldtitle,skip_confirm,container,folder) { +function checkForSubmit(targetform,param,context,idx,folderpath,index,oldtitle,skip_confirm,container,folder,confirm_removal) { + var canedit = '$canedit'; + if (canedit == '') { + alert("$js_lt{'edri'}"); + return; + } var dosettings; var doaction; var control = document.togglemultsettings; @@ -6139,14 +7339,28 @@ function checkForSubmit(targetform,param targetform.markcopy.value=idx+':'+param; targetform.copyfolder.value=folder+'.'+container; if (param == 'remove') { - if (skip_confirm || confirm('$lt{"p_rmr1"}\\n\\n$lt{"p_rmr2a"} "'+oldtitle+'" $lt{"p_rmr2b"}')) { + var doremove = 0; + if (skip_confirm) { + if (confirm_removal) { + if (confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'"$js_lt{"p_rmr2b"}')) { + doremove = 1; + } + } else { + doremove = 1; + } + } else { + if (confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr2a"} "'+oldtitle+'" $js_lt{"p_rmr2b"}')) { + doremove = 1; + } + } + if (doremove) { targetform.markcopy.value=''; targetform.copyfolder.value=''; targetform.submit(); } } if (param == 'cut') { - if (skip_confirm || confirm('$lt{"p_ctr1a"}\\n$lt{"p_ctr1b"}\\n\\n$lt{"p_ctr2a"} "'+oldtitle+'" $lt{"p_ctr2b"}')) { + if (skip_confirm || confirm('$js_lt{"p_ctr1a"}\\n$js_lt{"p_ctr1b"}\\n\\n$js_lt{"p_ctr2a"} "'+oldtitle+'" $js_lt{"p_ctr2b"}')) { targetform.submit(); return; } @@ -6260,6 +7474,8 @@ function showPage(current, pageId, nav, activeTab = ''; toggleUpload(); toggleMap(); + toggleCrsRes(); + toggleImportCrsres(); resize_scrollbox('contentscroll','1','0'); return; } else { @@ -6270,6 +7486,8 @@ function showPage(current, pageId, nav, activeTab = pageId; toggleUpload(); toggleMap(); + toggleCrsRes(); + toggleImportCrsres(); if (nav == 'mainnav') { var storedpath = "$docs_folderpath"; var storedpage = "$main_container_page"; @@ -6325,7 +7543,7 @@ function togglePick(caller,value) { } document.getElementById('multi'+caller).style.display=disp; if (value == 1) { - document.getElementById('more'+caller).innerHTML = '  $lt{'more'}'; + document.getElementById('more'+caller).innerHTML = '  $js_lt{'more'}'; } else { document.getElementById('more'+caller).innerHTML = ''; } @@ -6351,10 +7569,10 @@ function togglePick(caller,value) { function toggleCheckUncheck(caller,more) { if (more == 1) { - document.getElementById('more'+caller).innerHTML = '  $lt{'less'}'; + document.getElementById('more'+caller).innerHTML = '  $js_lt{'less'}'; document.getElementById('allfields'+caller).style.display='block'; } else { - document.getElementById('more'+caller).innerHTML = '  $lt{'more'}'; + document.getElementById('more'+caller).innerHTML = '  $js_lt{'more'}'; document.getElementById('allfields'+caller).style.display='none'; } resize_scrollbox('contentscroll','1','1'); @@ -6396,6 +7614,7 @@ function checkSubmits() { var doactions = multiActions(); var cutwarnings = 0; var remwarnings = 0; + var removalinfo = 0; if (doactions == 1) { var remidxlist = document.cumulativeactions.allremoveidx.value; if ((remidxlist != '') && (remidxlist != null)) { @@ -6410,6 +7629,11 @@ function checkSubmits() { remwarnings ++; } } + if (document.getElementById('confirm_removal_'+remidxs[i])) { + if (document.getElementById('confirm_removal_'+remidxs[i]).value == 1) { + removalinfo ++; + } + } } } } @@ -6508,14 +7732,19 @@ function checkSubmits() { } if (doactions == 1) { if (numchanges > 0) { - if ((cutwarnings > 0) || (remwarnings > 0)) { + if ((cutwarnings > 0) || (remwarnings > 0) || (removalinfo > 0)) { if (remwarnings > 0) { - if (!confirm('$lt{"p_rmr1"}\\n\\n$lt{"p_rmr3a"} '+remwarnings+' $lt{"p_rmr3b"}')) { + if (!confirm('$js_lt{"p_rmr1"}\\n\\n$js_lt{"p_rmr3a"} '+remwarnings+' $js_lt{"p_rmr3b"}')) { + return false; + } + } + if (removalinfo > 0) { + if (!confirm('$js_lt{"p_rmr4"}\\n$js_lt{"p_rmr5"}\\n\\n$js_lt{"p_rmr3a"} '+removalinfo+' $js_lt{"p_rmr3b"}')) { return false; } } if (cutwarnings > 0) { - if (!confirm('$lt{"p_ctr1a"}\\n$lt{"p_ctr1b"}\\n\\n$lt{"p_ctr3a"} '+cutwarnings+' $lt{"p_ctr3b"}')) { + if (!confirm('$js_lt{"p_ctr1a"}\\n$js_lt{"p_ctr1b"}\\n\\n$js_lt{"p_ctr3a"} '+cutwarnings+' $js_lt{"p_ctr3b"}')) { return false; } } @@ -6531,12 +7760,12 @@ function checkSubmits() { } } if ((dosettings == 1) && (doactions == 1)) { - alert("$lt{'noor'}"); + alert("$js_lt{'noor'}"); } else { if (dosettings == 1) { - alert("$lt{'noch'}"); + alert("$js_lt{'noch'}"); } else { - alert("$lt{'noac'}"); + alert("$js_lt{'noac'}"); } } return false; @@ -6622,7 +7851,34 @@ function setBoxes(value) { return; } -ENDNEWSCRIPT +function validImportCrsRes() { + var path = document.crsresimportform.coursepath.options[document.crsresimportform.coursepath.selectedIndex].value; + var fname = document.crsresimportform.coursefile.options[document.crsresimportform.coursefile.selectedIndex].value; + if ((fname == '') || (fname == null)) { + alert("$js_lt{'nofi'}"); + return false; + } + var url = '/res/$coursedom/$coursenum/'; + if (path && path != '/') { + url += path+'/'; + } + if (fname != '') { + url += fname; + } + var title = document.crsresimportform.crsrestitle.value; + document.crsresimportform.importdetail.value=escape(title)+'='+escape(url); + return true; +} + +function validateNewRes(caller) { + if (caller == 'single') { + var role = document.courseresform.authorrole.options[document.courseresform.authorrole.selectedIndex].value; + var authorpath = document.courseresform.authorpath.options[document.courseresform.authorpath.selectedIndex].value; + var resname = document.courseresform.newresourcename.value; + } +} + +ENDSCRIPT } sub history_tab_js { @@ -6651,13 +7907,19 @@ ENDINJECT sub dump_switchserver_js { my @hosts = @_; - my %lt = &Apache::lonlocal::texthash( - dump => 'Copying Content to Authoring Space requires switching server.', + my %js_lt = &Apache::lonlocal::texthash( + dump => 'Copying content to Authoring Space requires switching server.', + swit => 'Switch server?', + ); + my %html_js_lt = &Apache::lonlocal::texthash( swit => 'Switch server?', duco => 'Copying Content to Authoring Space', yone => 'You need to switch to a server housing an Authoring Space for which you are author or co-author.', chos => 'Choose server', ); + &js_escape(\%js_lt); + &html_escape(\%html_js_lt); + &js_escape(\%html_js_lt); my $role = $env{'request.role'}; my $js = <<"ENDSWJS";