');
+# Before
+ for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
+ my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
+ my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
+ if ($oldname ne $newname) {
+ $r->print(&LONCAPA::map::qtescape($oldname));
+ }
+ }
+ $r->print('
');
+ for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
+ if ($docslog{$id}{'logentry'}{'before_order_res_'.$idx}) {
+ $r->print('
');
+}
+
+sub do_paste_from_buffer {
+ my ($coursenum,$coursedom,$folder) = @_;
+
+ return 0 if (!$env{'form.pastemarked'});
+
+# paste resource to end of list
+ my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url'});
+ my $title=&LONCAPA::map::qtescape($env{'docs.markedcopy_title'});
+# Maps need to be copied first
+ if (($url=~/\.(page|sequence)$/) && ($url=~/^\/uploaded\//)) {
+ $title=&mt('Copy of').' '.$title;
+ my $newid=$$.time;
+ $url=~/^(.+)\.(\w+)$/;
+ my $newurl=$1.$newid.'.'.$2;
+ my $storefn=$newurl;
+ $storefn=~s{^/\w+/$match_domain/$match_username/}{};
+ &Apache::lonclonecourse::writefile($env{'request.course.id'},$storefn,
+ &Apache::lonnet::getfile($url));
+ $url = $newurl;
+ }
+# published maps can only exists once, so remove it from paste buffer when done
+ if (($url=~/\.(page|sequence)$/) && ($url=~m {^/res/})) {
+ &Apache::lonnet::delenv('docs\\.markedcopy');
+ }
+ if ($url=~ m{/smppg$}) {
+ my $db_name = &Apache::lonsimplepage::get_db_name($url);
+ if ($db_name =~ /^smppage_/) {
+ #simple pages, need to copy the db contents to a new one.
+ my %contents=&Apache::lonnet::dump($db_name,$coursedom,$coursenum);
+ my $now = time();
+ $db_name =~ s{_\d*$ }{_$now}x;
+ my $result=&Apache::lonnet::put($db_name,\%contents,
+ $coursedom,$coursenum);
+ $url =~ s{/(\d*)/smppg$ }{/$now/smppg}x;
+ $title=&mt('Copy of').' '.$title;
+ }
}
- if ($fatal) {
- $r->print('
'.$errtext.'
');
+ $title = &LONCAPA::map::qtunescape($title);
+ my $ext='false';
+ if ($url=~m{^http(|s)://}) { $ext='true'; }
+ $url = &LONCAPA::map::qtunescape($url);
+# Now insert the URL at the bottom
+ my $newidx = &LONCAPA::map::getresidx($url);
+ if ($env{'docs.markedcopy_supplemental'}) {
+ if ($folder =~ /^supplemental/) {
+ $title = $env{'docs.markedcopy_supplemental'};
+ } else {
+ (undef,undef,$title) =
+ &parse_supplemental_title($env{'docs.markedcopy_supplemental'});
+ }
} else {
+ if ($folder=~/^supplemental/) {
+ $title=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
+ $env{'user.domain'}.'___&&&___'.$title;
+ }
+ }
+
+ $LONCAPA::map::resources[$newidx]= $title.':'.$url.':'.$ext.':normal:res';
+ push(@LONCAPA::map::order, $newidx);
+# Store the result
+}
+
+my %parameter_type = ( 'randompick' => 'int_pos',
+ 'hiddenresource' => 'string_yesno',
+ 'encrypturl' => 'string_yesno',
+ 'randomorder' => 'string_yesno',);
+my $valid_parameters_re = join('|',keys(%parameter_type));
+# set parameters
+sub update_parameter {
+
+ return 0 if ($env{'form.changeparms'} !~ /^($valid_parameters_re)$/);
+
+ my $which = $env{'form.changeparms'};
+ my $idx = $env{'form.setparms'};
+ if ($env{'form.'.$which.'_'.$idx}) {
+ my $value = ($which eq 'randompick') ? $env{'form.'.$which.'_'.$idx}
+ : 'yes';
+ &LONCAPA::map::storeparameter($idx, 'parameter_'.$which, $value,
+ $parameter_type{$which});
+ &remember_parms($idx,$which,'set',$value);
+ } else {
+ &LONCAPA::map::delparameter($idx,'parameter_'.$which);
+
+ &remember_parms($idx,$which,'del');
+ }
+ return 1;
+}
+
+
+sub handle_edit_cmd {
+ my ($coursenum,$coursedom) =@_;
+
+ my ($cmd,$idx)=split('_',$env{'form.cmd'});
+
+ my $ratstr = $LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
+ my ($title, $url, @rrest) = split(':', $ratstr);
+
+ if ($cmd eq 'del') {
+ if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
+ ($url!~/\.(page|sequence|problem|exam|quiz|assess|survey|form|library|task)$/)) {
+ &Apache::lonnet::removeuploadedurl($url);
+ } else {
+ &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
+ }
+ splice(@LONCAPA::map::order, $idx, 1);
+
+ } elsif ($cmd eq 'cut') {
+ &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
+ splice(@LONCAPA::map::order, $idx, 1);
+
+ } elsif ($cmd eq 'up'
+ && ($idx) && (defined($LONCAPA::map::order[$idx-1]))) {
+ @LONCAPA::map::order[$idx-1,$idx] = @LONCAPA::map::order[$idx,$idx-1];
+
+ } elsif ($cmd eq 'down'
+ && defined($LONCAPA::map::order[$idx+1])) {
+ @LONCAPA::map::order[$idx+1,$idx] = @LONCAPA::map::order[$idx,$idx+1];
+
+ } elsif ($cmd eq 'rename') {
+
+ my $comment = &LONCAPA::map::qtunescape($env{'form.title'});
+ if ($comment=~/\S/) {
+ $LONCAPA::map::resources[$LONCAPA::map::order[$idx]]=
+ $comment.':'.join(':', $url, @rrest);
+ }
+# Devalidate title cache
+ my $renamed_url=&LONCAPA::map::qtescape($url);
+ &Apache::lonnet::devalidate_title_cache($renamed_url);
+ } else {
+ return 0;
+ }
+ return 1;
+}
+
+sub editor {
+ my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$type)=@_;
+
+ my $container= ($env{'form.pagepath'}) ? 'page'
+ : 'sequence';
+
+ my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
+ $folder.'.'.$container);
+ return $errtext if ($fatal);
+
+ if ($#LONCAPA::map::order<1) {
+ my $idx=&LONCAPA::map::getresidx();
+ if ($idx<=0) { $idx=1; }
+ $LONCAPA::map::order[0]=$idx;
+ $LONCAPA::map::resources[$idx]='';
+ }
+
+ my ($breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,$is_random_order)=
+ &breadcrumbs($folder,$allowed,$type);
+ $r->print($breadcrumbtrail);
+
# ------------------------------------------------------------ Process commands
# ---------------- if they are for this folder and user allowed to make changes
- if (($allowed) && ($ENV{'form.folder'} eq $folder)) {
+ if (($allowed) && ($env{'form.folder'} eq $folder)) {
# set parameters and change order
- if (defined($ENV{'form.setparms'})) {
- my $idx=$ENV{'form.setparms'};
-# set parameters
- if ($ENV{'form.randpick_'.$idx}) {
- &Apache::lonratedt::storeparameter($idx,'parameter_randompick',$ENV{'form.randpick_'.$idx},'int_pos');
- } else {
- &Apache::lonratedt::delparameter($idx,'parameter_randompick');
- }
- if ($ENV{'form.hidprs_'.$idx}) {
- &Apache::lonratedt::storeparameter($idx,'parameter_hiddenresource','yes','string_yesno');
- } else {
- &Apache::lonratedt::delparameter($idx,'parameter_hiddenresource');
- }
- if ($ENV{'form.encprs_'.$idx}) {
- &Apache::lonratedt::storeparameter($idx,'parameter_encrypturl','yes','string_yesno');
- } else {
- &Apache::lonratedt::delparameter($idx,'parameter_encrypturl');
- }
+ &snapshotbefore();
+
+ if (&update_parameter()) {
+ ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
+ return $errtext if ($fatal);
+ }
- if ($ENV{'form.newpos'}) {
+ if ($env{'form.newpos'} && $env{'form.currentpos'}) {
# change order
+ my $res = splice(@LONCAPA::map::order,$env{'form.currentpos'}-1,1);
+ splice(@LONCAPA::map::order,$env{'form.newpos'}-1,0,$res);
- my $newpos=$ENV{'form.newpos'}-1;
- my $currentpos=$ENV{'form.currentpos'}-1;
- my $i;
- my @neworder=();
- if ($newpos>$currentpos) {
-# moving stuff up
- for ($i=0;$i<$currentpos;$i++) {
- $neworder[$i]=$Apache::lonratedt::order[$i];
- }
- for ($i=$currentpos;$i<$newpos;$i++) {
- $neworder[$i]=$Apache::lonratedt::order[$i+1];
- }
- $neworder[$newpos]=$Apache::lonratedt::order[$currentpos];
- for ($i=$newpos+1;$i<=$#Apache::lonratedt::order;$i++) {
- $neworder[$i]=$Apache::lonratedt::order[$i];
- }
- } else {
-# moving stuff down
- for ($i=0;$i<$newpos;$i++) {
- $neworder[$i]=$Apache::lonratedt::order[$i];
- }
- $neworder[$newpos]=$Apache::lonratedt::order[$currentpos];
- for ($i=$newpos+1;$i<$currentpos+1;$i++) {
- $neworder[$i]=$Apache::lonratedt::order[$i-1];
- }
- for ($i=$currentpos+1;$i<=$#Apache::lonratedt::order;$i++) {
- $neworder[$i]=$Apache::lonratedt::order[$i];
- }
- }
- @Apache::lonratedt::order=@neworder;
- }
-# store the changed version
+ ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
+ return $errtext if ($fatal);
+ }
+
+ if ($env{'form.pastemarked'}) {
+ &do_paste_from_buffer($coursenum,$coursedom,$folder);
+ ($errtext,$fatal) = &storemap($coursenum,$coursedom,$folder.'.'.$container);
+ return $errtext if ($fatal);
+ }
- ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.sequence');
- if ($fatal) {
- $r->print('
'.$errtext.'
');
- return;
+ $r->print($upload_output);
+
+ if (&handle_edit_cmd()) {
+ ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
+ return $errtext if ($fatal);
+ }
+# Group import/search
+ if ($env{'form.importdetail'}) {
+ my @imports;
+ foreach (split(/\&/,$env{'form.importdetail'})) {
+ if (defined($_)) {
+ my ($name,$url,$residx)=
+ map {&unescape($_)} split(/\=/,$_);
+ push(@imports, [$name, $url, $residx]);
+ }
+ }
+ ($errtext,$fatal)=&group_import($coursenum, $coursedom, $folder,
+ $container,'londocs',@imports);
+ return $errtext if ($fatal);
+ }
+# Loading a complete map
+ if ($env{'form.loadmap'}) {
+ if ($env{'form.importmap'}=~/\w/) {
+ foreach my $res (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
+ my ($title,$url,$ext,$type)=split(/\:/,$res);
+ my $idx=&LONCAPA::map::getresidx($url);
+ $LONCAPA::map::resources[$idx]=$res;
+ $LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx;
}
+ ($errtext,$fatal)=&storemap($coursenum,$coursedom,
+ $folder.'.'.$container);
+ return $errtext if ($fatal);
+ } else {
+ $r->print('
'.&mt('No map selected.').'
');
}
+ }
+ &log_differences($plain);
+ }
+# ---------------------------------------------------------------- End commands
+# ---------------------------------------------------------------- Print screen
+ my $idx=0;
+ my $shown=0;
+ if (($ishidden) || ($isencrypted) || ($randompick>=0) || ($is_random_order)) {
+ $r->print('
'.&mt('Caution: this folder is set to randomly pick a subset of resources. Adding or removing resources from this folder will change the set of resources that the students see, resulting in spurious or missing credit for completed problems, not limited to ones you modify. Do not modify the contents of this folder if it is in active student use.').'
');
+ }
+ if ($is_random_order) {
+ $r->print('
'.&mt('Caution: this folder is set to randomly order its contents. Adding or removing resources from this folder will change the order of resources shown.').'
'.&mt('An Error Occured while Attempting to Store your Version Settings').'
');
+ $r->print('
'.&mt('An Error Occured while Attempting to Save your Version Settings').'
');
}
- &changewarning($r,'');
+ &mark_hash_old();
}
- if ($ENV{'form.timerange'} eq 'all') {
+ &changewarning($r,'');
+ if ($env{'form.timerange'} eq 'all') {
# show all documents
- $header=&mt('All Documents in Course');
+ $header=&mt('All Documents in '.$type);
$allsel=1;
foreach (keys %hash) {
if ($_=~/^ids\_(\/res\/.+)$/) {
@@ -834,28 +2199,28 @@ sub checkversions {
} else {
# show documents which changed
%changes=&Apache::lonnet::dump
- ('versionupdate',$ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
- $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
+ ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
+ $env{'course.'.$env{'request.course.id'}.'.num'});
my $firstkey=(keys %changes)[0];
unless ($firstkey=~/^error\:/) {
- unless ($ENV{'form.timerange'}) {
- $ENV{'form.timerange'}=604800;
+ unless ($env{'form.timerange'}) {
+ $env{'form.timerange'}=604800;
}
- my $seltext=&mt('during the last').' '.$ENV{'form.timerange'}.' '
+ my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
.&mt('seconds');
- if ($ENV{'form.timerange'}==-1) {
+ if ($env{'form.timerange'}==-1) {
$seltext='since start of course';
$startsel='selected';
- $ENV{'form.timerange'}=time;
+ $env{'form.timerange'}=time;
}
- $starttime=time-$ENV{'form.timerange'};
- if ($ENV{'form.timerange'}==2592000) {
+ $starttime=time-$env{'form.timerange'};
+ if ($env{'form.timerange'}==2592000) {
$seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
$monthsel='selected';
- } elsif ($ENV{'form.timerange'}==604800) {
+ } elsif ($env{'form.timerange'}==604800) {
$seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
$weeksel='selected';
- } elsif ($ENV{'form.timerange'}==86400) {
+ } elsif ($env{'form.timerange'}==86400) {
$seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
$daysel='selected';
}
@@ -865,10 +2230,10 @@ sub checkversions {
}
}
%setversions=&Apache::lonnet::dump('resourceversions',
- $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
- $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
+ $env{'course.'.$env{'request.course.id'}.'.domain'},
+ $env{'course.'.$env{'request.course.id'}.'.num'});
my %lt=&Apache::lonlocal::texthash
- ('st' => 'Version changes since start of Course',
+ ('st' => 'Version changes since start of '.$type,
'lm' => 'Version changes since last Month',
'lw' => 'Version changes since last Week',
'sy' => 'Version changes since Yesterday',
@@ -877,9 +2242,9 @@ sub checkversions {
'fi' => 'File',
'md' => 'Modification Date',
'mr' => 'Most recently published Version',
- 've' => 'Version used in Course',
- 'vu' => 'Set Version to be used in Course',
-'sv' => 'Set Versions to be used in Course according to Selections below',
+ 've' => 'Version used in '.$type,
+ 'vu' => 'Set Version to be used in '.$type,
+'sv' => 'Set Versions to be used in '.$type.' according to Selections below',
'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
'di' => 'Differences');
@@ -923,10 +2288,10 @@ ENDHEADERS
'lastrevisiondate')
).
''.
- '
Most Recent: '.
+ '
Most Recent: '.
''.$currentversion.''.
- '
'.
- '
In Course: '.
+ '
'.
+ '
In '.$type.': '.
'');
# Used in course
my $usedversion=$hash{'version_'.$linkurl};
@@ -935,15 +2300,17 @@ ENDHEADERS
} else {
$r->print($currentversion);
}
- $r->print('
');
my $lastold=1;
for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
my $url=$root.'.'.$prevvers.'.'.$extension;
@@ -967,7 +2334,7 @@ ENDHEADERS
my $cols_output = 1;
for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
my $url=$root.'.'.$prevvers.'.'.$extension;
- $r->print(''.&mt('Version').' '.$prevvers.' ('.
&Apache::lonlocal::locallocaltime(
&Apache::lonnet::metadata($url,
@@ -980,7 +2347,7 @@ ENDHEADERS
'&versionone='.$prevvers.
'">'.&mt('Diffs').'');
}
- $r->print(' ');
+ $r->print(' ');
if (++$entries_count % $entries_per_col == 0) {
$r->print('');
if ($cols_output != 4) {
@@ -1001,19 +2368,71 @@ ENDHEADERS
&untiehash();
}
+sub mark_hash_old {
+ my $retie_hash=0;
+ if ($hashtied) {
+ $retie_hash=1;
+ &untiehash();
+ }
+ &tiehash('write');
+ $hash{'old'}=1;
+ &untiehash();
+ if ($retie_hash) { &tiehash(); }
+}
+
+sub is_hash_old {
+ my $untie_hash=0;
+ if (!$hashtied) {
+ $untie_hash=1;
+ &tiehash();
+ }
+ my $return=$hash{'old'};
+ if ($untie_hash) { &untiehash(); }
+ return $return;
+}
+
sub changewarning {
- my ($r,$postexec)=@_;
- $r->print(
-''.
-'');
+ my ($r,$postexec,$message,$url)=@_;
+ if (!&is_hash_old()) { return; }
+ my $pathvar='folderpath';
+ my $path=&escape($env{'form.folderpath'});
+ if (!defined($url)) {
+ if (defined($env{'form.pagepath'})) {
+ $pathvar='pagepath';
+ $path=&escape($env{'form.pagepath'});
+ $path.='&pagesymb='.&escape($env{'form.pagesymb'});
+ }
+ $url='/adm/coursedocs?'.$pathvar.'='.$path;
+ }
+ my $course_type = &Apache::loncommon::course_type();
+ if (!defined($message)) {
+ $message='Changes will become active for your current session after [_1], or the next time you log in.';
+ }
+ $r->print("\n\n".
+''."\n".
+''."\n\n");
+}
+
+# =========================================== Breadcrumbs for special functions
+
+sub init_breadcrumbs {
+ my ($form,$text)=@_;
+ &Apache::lonhtmlcommon::clear_breadcrumbs();
+ &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs",
+ text=>"Edit ".&Apache::loncommon::course_type(),
+ faq=>273,
+ bug=>'Instructor Interface',
+ help => 'Docs_Adding_Course_Doc'});
+ &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?".$form.'=1',
+ text=>$text,
+ faq=>273,
+ bug=>'Instructor Interface'});
}
# ================================================================ Main Handler
@@ -1022,16 +2441,17 @@ sub handler {
&Apache::loncommon::content_type($r,'text/html');
$r->send_http_header;
return OK if $r->header_only;
+ my $type = &Apache::loncommon::course_type();
# --------------------------------------------- Initialize help topics for this
- foreach ('Adding_Course_Doc','Main_Course_Documents',
- 'Adding_External_Resource','Navigate_Content',
- 'Adding_Folders','Docs_Overview', 'Load_Map',
- 'Supplemental', 'Score_Upload_Form',
- 'Importing_LON-CAPA_Resource','Uploading_From_Harddrive',
- 'Check_Resource_Versions','Verify_Content') {
- $help{$_}=&Apache::loncommon::help_open_topic('Docs_'.$_);
- }
+ foreach ('Adding_Course_Doc','Main_Course_Documents',
+ 'Adding_External_Resource','Navigate_Content',
+ 'Adding_Folders','Docs_Overview', 'Load_Map',
+ 'Supplemental','Score_Upload_Form','Adding_Pages',
+ 'Importing_LON-CAPA_Resource','Uploading_From_Harddrive',
+ 'Check_Resource_Versions','Verify_Content') {
+ $help{$_}=&Apache::loncommon::help_open_topic('Docs_'.$_);
+ }
# Composite help files
$help{'Syllabus'} = &Apache::loncommon::help_open_topic(
'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
@@ -1043,510 +2463,880 @@ sub handler {
'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
$help{'My Personal Info'} = &Apache::loncommon::help_open_topic(
'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
+ $help{'Group Files'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
$help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
-
- if ($ENV{'form.verify'}) {
+
+# does this user have privileges to modify docs
+ my $allowed=&Apache::lonnet::allowed('mdc',$env{'request.course.id'});
+ if ($allowed && $env{'form.verify'}) {
+ &init_breadcrumbs('verify','Verify Content');
&verifycontent($r);
- } elsif ($ENV{'form.versions'}) {
+ } elsif ($allowed && $env{'form.listsymbs'}) {
+ &init_breadcrumbs('listsymbs','List Symbs');
+ &list_symbs($r);
+ } elsif ($allowed && $env{'form.docslog'}) {
+ &init_breadcrumbs('docslog','Show Log');
+ &docs_change_log($r);
+ } elsif ($allowed && $env{'form.versions'}) {
+ &init_breadcrumbs('versions','Check/Set Resource Versions');
&checkversions($r);
- } elsif ($ENV{'form.dumpcourse'}) {
+ } elsif ($allowed && $env{'form.dumpcourse'}) {
+ &init_breadcrumbs('dumpcourse','Dump '.&Apache::loncommon::course_type().' DOCS to Construction Space');
&dumpcourse($r);
+ } elsif ($allowed && $env{'form.exportcourse'}) {
+ &init_breadcrumbs('exportcourse','Export '.&Apache::loncommon::course_type().' to IMS');
+ &exportcourse($r);
} else {
# is this a standard course?
- my $standard=($ENV{'request.course.uri'}=~/^\/uploaded\//);
- my $forcestandard;
+ my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
+ my $forcestandard = 0;
my $forcesupplement;
my $script='';
- my $allowed;
- my $events='';
my $showdoc=0;
+ my $containertag;
+ my $uploadtag;
&Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
- ['folderpath']);
- if ($ENV{'form.folderpath'}) {
- my (@folderpath)=split('&',$ENV{'form.folderpath'});
- $ENV{'form.foldername'}=&Apache::lonnet::unescape(pop(@folderpath));
- $ENV{'form.folder'}=pop(@folderpath);
- }
+ ['folderpath','pagepath',
+ 'pagesymb']);
+# No folderpath, no pagepath, see if we have something stored
+ if ((!$env{'form.folderpath'}) && (!$env{'form.pagepath'})) {
+ &Apache::loncommon::restore_course_settings('docs_folderpath',
+ {'folderpath' => 'scalar'});
+ }
+ if (!$env{'form.folderpath'}) {
+ &Apache::loncommon::restore_course_settings('docs_folderpath',
+ {'pagepath' => 'scalar'});
+ }
+ if ($env{'form.pagepath'}) {
+ $env{'form.folderpath'}='';
+ }
+ if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
+ $env{'form.folderpath'} = 'supplemental&'.
+ &escape(&mt('Supplemental '.$type.' Documents')).'&'.
+ $env{'form.folderpath'};
+ }
+ &Apache::loncommon::store_course_settings('docs_folderpath',
+ {'pagepath' => 'scalar',
+ 'folderpath' => 'scalar'});
+ if ($env{'form.folderpath'}) {
+ my (@folderpath)=split('&',$env{'form.folderpath'});
+ $env{'form.foldername'}=&unescape(pop(@folderpath));
+ $env{'form.folder'}=pop(@folderpath);
+ }
+ if ($env{'form.pagepath'}) {
+ my (@pagepath)=split('&',$env{'form.pagepath'});
+ $env{'form.pagename'}=&unescape(pop(@pagepath));
+ $env{'form.folder'}=pop(@pagepath);
+ $containertag = ''.
+ '';
+ $uploadtag = ''.
+ '';
+ }
if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
$showdoc='/'.$1;
}
unless ($showdoc) { # got called from remote
- $forcestandard=($ENV{'form.folder'}=~/^default_/);
- $forcesupplement=($ENV{'form.folder'}=~/^supplemental_/);
+ if (($env{'form.folder'}=~/^(?:group|default)_/) ||
+ ($env{'form.folder'} =~ m:^\d+/(pages|sequences)/:)) {
+ $forcestandard = 1;
+ }
+ $forcesupplement=($env{'form.folder'}=~/^supplemental_/);
-# does this user have privileges to post, etc?
- $allowed=&Apache::lonnet::allowed('mdc',$ENV{'request.course.id'});
if ($allowed) {
&Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
$script=&Apache::lonratedt::editscript('simple');
}
} else { # got called in sequence from course
$allowed=0;
- $script=''.&Apache::lonmenu::registerurl(1,undef).'
-ENDDOCUMENT
- if ($allowed) {
- $r->print(<
-function makenewfolder(targetform,folderseq) {
- var foldername=prompt('Name of New Folder','New Folder');
- if (foldername) {
- targetform.importdetail.value=foldername+"="+folderseq;
- targetform.submit();
- }
-}
-
-function makenewext(targetname) {
- this.document.forms.extimport.useform.value=targetname;
- window.open('/adm/rat/extpickframe.html');
-}
+ $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL') . "/");
-function makeexamupload() {
- var title=prompt('Listed Title for the Uploaded Score');
- if (title) {
- this.document.forms.newexamupload.importdetail.value=
- title+'=/res/lib/templates/examupload.problem';
- this.document.forms.newexamupload.submit();
- }
-}
-
-function makesmppage() {
- var title=prompt('Listed Title for the Page');
- if (title) {
- this.document.forms.newsmppg.importdetail.value=
- title+'=/adm/$udom/$uname/$now/smppg';
- this.document.forms.newsmppg.submit();
- }
-}
-
-function makesmpproblem() {
- var title=prompt('Listed Title for the Problem');
- if (title) {
- this.document.forms.newsmpproblem.importdetail.value=
- title+'=/res/lib/templates/simpleproblem.problem';
- this.document.forms.newsmpproblem.submit();
- }
-}
-
-function makebulboard() {
- var title=prompt('Listed Title for the Bulletin Board');
- if (title) {
- this.document.forms.newbul.importdetail.value=
- title+'=/adm/$udom/$uname/$now/bulletinboard';
- this.document.forms.newbul.submit();
- }
-}
-
-function makeabout() {
- var user=prompt("Enter user\@domain for User's 'About Me' Page");
- if (user) {
- var comp=new Array();
- comp=user.split('\@');
- if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
- if ((comp[0]) && (comp[1])) {
- this.document.forms.newaboutsomeone.importdetail.value=
- 'About '+user+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
- this.document.forms.newaboutsomeone.submit();
- }
- }
- }
-}
-
-function makeims() {
- var caller = document.forms.ims.folder.value
- var newlocation = "/adm/imsimportdocs?folder="+caller+"&phase=one"
- newWindow = window.open("","IMSimport","HEIGHT=700,WIDTH=750,scrollbars=yes")
- newWindow.location.href = newlocation
-}
-
-
-function finishpick() {
- var title=this.document.forms.extimport.title.value;
- var url=this.document.forms.extimport.url.value;
- var form=this.document.forms.extimport.useform.value;
- eval
- ('this.document.forms.'+form+'.importdetail.value="'+title+'='+url+
- '";this.document.forms.'+form+'.submit();');
-}
-
-function changename(folderpath,index,oldtitle) {
- var title=prompt('New Title',oldtitle);
- if (title) {
- 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 removeres(folderpath,index,oldtitle) {
- if (confirm('Remove "'+oldtitle+'"?')) {
- this.document.forms.renameform.cmd.value='del_'+index;
- this.document.forms.renameform.folderpath.value=folderpath;
- this.document.forms.renameform.submit();
+ if ($allowed) {
+ $script .= &editing_js($udom,$uname);
}
-}
-
-
-
-ENDNEWSCRIPT
- }
# -------------------------------------------------------------------- Body tag
- $r->print(''.
- &Apache::loncommon::bodytag('Course Documents','',$events,
- '','',$showdoc).
- &Apache::loncommon::help_open_faq(273).
- &Apache::loncommon::help_open_bug('RAT'));
- unless ($showdoc) {
+ $script = '';
+ $r->print(&Apache::loncommon::start_page("$type Documents", $script,
+ {'force_register' => $showdoc,}).
+ &Apache::loncommon::help_open_menu('','',273,'RAT'));
+
+ my %allfiles = ();
+ my %codebase = ();
+ my ($upload_result,$upload_output);
+ if ($allowed) {
+ if (($env{'form.uploaddoc.filename'}) &&
+ ($env{'form.cmd'}=~/^upload_(\w+)/)) {
+# Process file upload - phase one - upload and parse primary file.
+ undef($hadchanges);
+ $upload_result = &process_file_upload(\$upload_output,$coursenum,
+ $coursedom,\%allfiles,
+ \%codebase,$1);
+ if ($hadchanges) {
+ &mark_hash_old();
+ }
+ if ($upload_result eq 'phasetwo') {
+ $r->print($upload_output);
+ }
+ } elsif ($env{'form.phasetwo'}) {
+ my %newname = ();
+ my %origname = ();
+ my %attribs = ();
+ my $updateflag = 0;
+ my $residx = $env{'form.newidx'};
+ my $primary_url = &unescape($env{'form.primaryurl'});
+# Process file upload - phase two - gather secondary files.
+ for (my $i=0; $i<$env{'form.phasetwo'}; $i++) {
+ if ($env{'form.embedded_item_'.$i.'.filename'}) {
+ my $javacodebase;
+ $newname{$i} = &process_secondary_uploads(\$upload_output,$coursedom,$coursenum,'embedded_item_',$i,$residx);
+ $origname{$i} = &unescape($env{'form.embedded_orig_'.$i});
+ if (exists($env{'form.embedded_codebase_'.$i})) {
+ $javacodebase = &unescape($env{'form.embedded_codebase_'.$i});
+ $origname{$i} =~ s#^\Q$javacodebase\E/##;
+ }
+ my @attributes = ();
+ if ($env{'form.embedded_attrib_'.$i} =~ /:/) {
+ @attributes = split/:/,$env{'form.embedded_attrib_'.$i};
+ } else {
+ @attributes = ($env{'form.embedded_attrib_'.$i});
+ }
+ foreach (@attributes) {
+ push(@{$attribs{$i}},&unescape($_));
+ }
+ if ($javacodebase) {
+ $codebase{$i} = $javacodebase;
+ $codebase{$i} =~ s#/$##;
+ $updateflag = 1;
+ }
+ }
+ unless ($newname{$i} eq $origname{$i}) {
+ $updateflag = 1;
+ }
+ }
+# Process file upload - phase three - modify primary file
+ if ($updateflag) {
+ my ($content,$rtncode);
+ my $updateflag = 0;
+ my $getstatus = &Apache::lonnet::getuploaded('GET',$primary_url,$coursedom,$coursenum,\$content,\$rtncode);
+ if ($getstatus eq 'ok') {
+ foreach my $item (keys %newname) {
+ if ($newname{$item} ne $origname{$item}) {
+ my $attrib_regexp = '';
+ if (@{$attribs{$item}} > 1) {
+ $attrib_regexp = join('|',@{$attribs{$item}});
+ } else {
+ $attrib_regexp = $attribs{$item}[0];
+ }
+ if ($content =~ m#($attrib_regexp\s*=\s*['"]?)\Q$origname{$item}\E(['"]?)#) {
+ }
+ $content =~ s#($attrib_regexp\s*=\s*['"]?)\Q$origname{$item}\E(['"]?)#$1$newname{$item}$2#gi;
+ }
+ if (exists($codebase{$item})) {
+ $content =~ s/(codebase\s*=\s*["']?)\Q$codebase{$item}\E(["']?)/$1.$2/i; #' stupid emacs
+ }
+ }
+# Save edited file.
+ my $saveresult;
+ my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
+ my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
+ my $url = &Apache::lonnet::store_edited_file($primary_url,$content,$docudom,$docuname,\$saveresult);
+ } else {
+ &Apache::lonnet::logthis('retrieval of uploaded file - '.$primary_url.' - for editing, failed: '.$getstatus);
+ }
+ }
+ }
+ }
+
+ unless ($showdoc || $upload_result eq 'phasetwo') {
# -----------------------------------------------------------------------------
my %lt=&Apache::lonlocal::texthash(
- 'uplm' => 'Upload a new main course document',
- 'upls' => 'Upload a new supplemental course document',
- 'impp' => 'Import a published document',
+ 'uplm' => 'Upload a new main '.lc($type).' document',
+ 'upls' => 'Upload a new supplemental '.lc($type).' document',
+ 'impp' => 'Import a document',
+ 'pubd' => 'Published documents',
+ 'copm' => 'All documents out of a published map into this folder',
'spec' => 'Special documents',
'upld' => 'Upload Document',
'srch' => 'Search',
'impo' => 'Import',
+ 'book' => 'Import Bookmarks',
'selm' => 'Select Map',
'load' => 'Load Map',
+ 'reco' => 'Recover Deleted Resources',
'newf' => 'New Folder',
+ 'newp' => 'New Composite Page',
'extr' => 'External Resource',
'syll' => 'Syllabus',
'navc' => 'Navigate Contents',
'sipa' => 'Simple Page',
'sipr' => 'Simple Problem',
+ 'drbx' => 'Drop Box',
'scuf' => 'Score Upload Form',
'bull' => 'Bulletin Board',
'mypi' => 'My Personal Info',
+ 'grpo' => 'Group Files',
+ 'rost' => 'Course Roster',
'abou' => 'About User',
'imsf' => 'Import IMS package',
'file' => 'File',
'title' => 'Title',
- 'comment' => 'Comment'
+ 'comment' => 'Comment',
+ 'parse' => 'If HTML file, upload embedded images/multimedia files'
);
# -----------------------------------------------------------------------------
if ($allowed) {
+ &update_paste_buffer($coursenum,$coursedom);
my $dumpbut=&dumpbutton();
+ my $exportbut=&exportbutton();
my %lt=&Apache::lonlocal::texthash(
'vc' => 'Verify Content',
'cv' => 'Check/Set Resource Versions',
+ 'ls' => 'List Symbs',
+ 'sl' => 'Show Log'
);
- my $folderpath=$ENV{'form.folderpath'};
+ my $folderpath=$env{'form.folderpath'};
if (!$folderpath) {
- if ($ENV{'form.folder'} eq '' ||
- $ENV{'form.folder'} eq 'supplemental') {
+ if ($env{'form.folder'} eq '' ||
+ $env{'form.folder'} eq 'supplemental') {
$folderpath='default&'.
- &Apache::lonnet::escape(&mt('Main Course Documents'));
+ &escape(&mt('Main '.$type.' Documents'));
}
}
+ unless ($env{'form.pagepath'}) {
+ $containertag = '';
+ $uploadtag = '';
+ }
+
$r->print(<
-
-
-
+
+
+
+
+ $containertag
+
ENDCOURSEVERIFY
$r->print(&Apache::loncommon::help_open_topic('Docs_Adding_Course_Doc',
- &mt('Editing the Table of Contents for your Course')));
+ &mt('Editing the Table of Contents for your '.$type)));
}
# --------------------------------------------------------- Standard documents
- $r->print('