');
+# 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('
'.&Apache::loncommon::end_data_table_row());
+ $shown++;
+ if (!($env{'form.show'} eq &mt('all')
+ || $shown<=$env{'form.show'})) { last; }
+ }
+ $r->print(&Apache::loncommon::end_data_table());
+}
+
+sub update_paste_buffer {
+ my ($coursenum,$coursedom) = @_;
+
+ return if (!defined($env{'form.markcopy'}));
+ return if (!defined($env{'form.copyfolder'}));
+ return if ($env{'form.markcopy'} < 0);
+
+ my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
+ $env{'form.copyfolder'});
+
+ return if ($fatal);
+
+# Mark for copying
+ my ($title,$url)=split(':',$LONCAPA::map::resources[$LONCAPA::map::order[$env{'form.markcopy'}]]);
+ if (&is_supplemental_title($title)) {
+ ($title) = &parse_supplemental_title($title);
+ }
+ &Apache::lonnet::appenv('docs.markedcopy_title' => $title,
+ 'docs.markedcopy_url' => $url);
+ delete($env{'form.markcopy'});
+}
+
+sub print_paste_buffer {
+ my ($r,$container) = @_;
+ return if (!defined($env{'docs.markedcopy_url'}));
+
+ $r->print(<');
+}
+
+sub editor {
+ my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$which)=@_;
my $errtext='';
my $fatal=0;
- ($errtext,$fatal)=
- &mapread($coursenum,$coursedom,$folder.'.sequence');
- if ($#Apache::lonratedt::order<1) {
- $Apache::lonratedt::order[0]=1;
- $Apache::lonratedt::resources[1]='';
+ my $container='sequence';
+ if ($env{'form.pagepath'}) {
+ $container='page';
+ }
+ ($errtext,$fatal) = &mapread($coursenum,$coursedom,$folder.'.'.$container);
+ 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)=&breadcrumbs($folder);
+ $r->print($breadcrumbtrail);
if ($fatal) {
- $r->print('
'.$errtext.'
');
+ $r->print('
'.$errtext.'
');
} else {
# ------------------------------------------------------------ Process commands
+
# ---------------- if they are for this folder and user allowed to make changes
- if (($allowed) && ($ENV{'form.folder'} eq $folder)) {
-# upload a file, if present
- if (($ENV{'form.uploaddoc.filename'}) &&
- ($ENV{'form.cmd'}=~/^upload_(\w+)/)) {
- if ($folder=~/^$1/) {
-# this is for a course, not a user, so set coursedoc flag
-# probably the only place in the system where this should be "1"
- my $url=&Apache::lonnet::userfileupload('uploaddoc',1);
- my $ext='false';
- if ($url=~/^http\:\/\//) { $ext='true'; }
- $url=~s/\:/\:/g;
- my $comment=$ENV{'form.comment'};
- $comment=~s/\\<\;/g;
- $comment=~s/\>/\>\;/g;
- $comment=~s/\:/\:/g;
- if ($folder=~/^supplemental/) {
- $comment=time.'___&&&___'.$ENV{'user.name'}.'___&&&___'.
- $ENV{'user.domain'}.'___&&&___'.$comment;
- }
- my $newidx=$#Apache::lonratedt::resources+1;
- $Apache::lonratedt::resources[$newidx]=
- $comment.':'.$url.':'.$ext.':normal:res';
- $Apache::lonratedt::order[$#Apache::lonratedt::order+1]=
- $newidx;
- &storemap($coursenum,$coursedom,$folder.'.sequence');
- }
- }
- if ($ENV{'form.cmd'}) {
- my ($cmd,$idx)=split(/\_/,$ENV{'form.cmd'});
+ if (($allowed) && ($env{'form.folder'} eq $folder)) {
+# set parameters and change order
+ &snapshotbefore();
+ if ($env{'form.changeparms'}) {
+ my $idx=$env{'form.setparms'};
+# set parameters
+ if ($env{'form.changeparms'} eq 'randompick') {
+ if ($env{'form.randpick_'.$idx}) {
+ &LONCAPA::map::storeparameter($idx,'parameter_randompick',$env{'form.randpick_'.$idx},'int_pos');
+ &remember_parms($idx,'randompick','set',$env{'form.randpick_'.$idx});
+ } else {
+ &LONCAPA::map::delparameter($idx,'parameter_randompick');
+ &remember_parms($idx,'randompick','del');
+ }
+ }
+ if ($env{'form.changeparms'} eq 'hiddenresource') {
+ if ($env{'form.hidprs_'.$idx}) {
+ &LONCAPA::map::storeparameter($idx,'parameter_hiddenresource','yes','string_yesno');
+ &remember_parms($idx,'hiddenresource','set',$env{'form.hidprs_'.$idx});
+ } else {
+ &LONCAPA::map::delparameter($idx,'parameter_hiddenresource');
+ &remember_parms($idx,'hiddenresource','del');
+ }
+ }
+ if ($env{'form.changeparms'} eq 'encrypturl') {
+ if ($env{'form.encprs_'.$idx}) {
+ &LONCAPA::map::storeparameter($idx,'parameter_encrypturl','yes','string_yesno');
+ &remember_parms($idx,'encrypturl','set',$env{'form.encprs_'.$idx});
+ } else {
+ &LONCAPA::map::delparameter($idx,'parameter_encrypturl');
+ &remember_parms($idx,'encrypturl','del');
+ }
+ }
+# store the changed version
+ ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
+ if ($fatal) {
+ $r->print('
'.$errtext.'
');
+ return;
+ }
+ }
+
+ if ($env{'form.newpos'}) {
+# change order
+ 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]=$LONCAPA::map::order[$i];
+ }
+ for ($i=$currentpos;$i<$newpos;$i++) {
+ $neworder[$i]=$LONCAPA::map::order[$i+1];
+ }
+ $neworder[$newpos]=$LONCAPA::map::order[$currentpos];
+ for ($i=$newpos+1;$i<=$#LONCAPA::map::order;$i++) {
+ $neworder[$i]=$LONCAPA::map::order[$i];
+ }
+ } else {
+# moving stuff down
+ for ($i=0;$i<$newpos;$i++) {
+ $neworder[$i]=$LONCAPA::map::order[$i];
+ }
+ $neworder[$newpos]=$LONCAPA::map::order[$currentpos];
+ for ($i=$newpos+1;$i<$currentpos+1;$i++) {
+ $neworder[$i]=$LONCAPA::map::order[$i-1];
+ }
+ for ($i=$currentpos+1;$i<=$#LONCAPA::map::order;$i++) {
+ $neworder[$i]=$LONCAPA::map::order[$i];
+ }
+ }
+ @LONCAPA::map::order=@neworder;
+# store the changed version
+ ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
+ if ($fatal) {
+ $r->print('
'.$errtext.'
');
+ return;
+ }
+ }
+
+ if ($env{'form.pastemarked'}) {
+# paste resource to end of list
+ my $url=$env{'docs.markedcopy_url'};
+ my $title=$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;
+ }
+ $title = &LONCAPA::map::qtunescape($title);
+ my $ext='false';
+ if ($url=~/^http\:\/\//) { $ext='true'; }
+ $url = &LONCAPA::map::qtunescape($url);
+# Now insert the URL at the bottom
+ my $newidx=&LONCAPA::map::getresidx($url);
+ $LONCAPA::map::resources[$newidx]=
+ $title.':'.$url.':'.$ext.':normal:res';
+ $LONCAPA::map::order[1+$#LONCAPA::map::order]=$newidx;
+# Store the result
+ ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
+ if ($fatal) {
+ $r->print('
'.$errtext.'
');
+ return;
+ }
+
+ }
+ $r->print($upload_output);
+ if ($env{'form.cmd'}) {
+ my ($cmd,$idx)=split(/\_/,$env{'form.cmd'});
if ($cmd eq 'del') {
- for (my $i=$idx;$i<$#Apache::lonratedt::order;$i++) {
- $Apache::lonratedt::order[$i]=
- $Apache::lonratedt::order[$i+1];
+ my (undef,$url)=split(':',$LONCAPA::map::resources[$LONCAPA::map::order[$idx]]);
+ 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]);
+ }
+ for (my $i=$idx;$i<$#LONCAPA::map::order;$i++) {
+ $LONCAPA::map::order[$i] = $LONCAPA::map::order[$i+1];
+ }
+ $#LONCAPA::map::order--;
+ } elsif ($cmd eq 'cut') {
+ my (undef,$url)=split(':',$LONCAPA::map::resources[$LONCAPA::map::order[$idx]]);
+ &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
+ for (my $i=$idx;$i<$#LONCAPA::map::order;$i++) {
+ $LONCAPA::map::order[$i] = $LONCAPA::map::order[$i+1];
}
- $#Apache::lonratedt::order--;
+ $#LONCAPA::map::order--;
} elsif ($cmd eq 'up') {
- if (($idx) && (defined($Apache::lonratedt::order[$idx-1]))) {
- my $i=$Apache::lonratedt::order[$idx-1];
- $Apache::lonratedt::order[$idx-1]=
- $Apache::lonratedt::order[$idx];
- $Apache::lonratedt::order[$idx]=$i;
+ if (($idx) && (defined($LONCAPA::map::order[$idx-1]))) {
+ my $i=$LONCAPA::map::order[$idx-1];
+ $LONCAPA::map::order[$idx-1] = $LONCAPA::map::order[$idx];
+ $LONCAPA::map::order[$idx] = $i;
}
} elsif ($cmd eq 'down') {
- if (defined($Apache::lonratedt::order[$idx+1])) {
- my $i=$Apache::lonratedt::order[$idx+1];
- $Apache::lonratedt::order[$idx+1]=
- $Apache::lonratedt::order[$idx];
- $Apache::lonratedt::order[$idx]=$i;
+ if (defined($LONCAPA::map::order[$idx+1])) {
+ my $i=$LONCAPA::map::order[$idx+1];
+ $LONCAPA::map::order[$idx+1] = $LONCAPA::map::order[$idx];
+ $LONCAPA::map::order[$idx] = $i;
}
} elsif ($cmd eq 'rename') {
+ my $ratstr = $LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
my ($rtitle,@rrest)=split(/\:/,
- $Apache::lonratedt::resources[
- $Apache::lonratedt::order[$idx]]);
- my $comment=
- &HTML::Entities::decode($ENV{'form.title'});
- $comment=~s/\\<\;/g;
- $comment=~s/\>/\>\;/g;
- $comment=~s/\:/\:/g;
- $Apache::lonratedt::resources[
- $Apache::lonratedt::order[$idx]]=
- $comment.':'.join(':',@rrest);
-
+ $LONCAPA::map::resources[$LONCAPA::map::order[$idx]]);
+ my $comment=$env{'form.title'};
+ $comment = &LONCAPA::map::qtunescape($comment);
+ if ($comment=~/\S/) {
+ $LONCAPA::map::resources[$LONCAPA::map::order[$idx]]=
+ $comment.':'.join(':',@rrest);
+ }
+# Devalidate title cache
+ my $renamed_url=&LONCAPA::map::qtescape($rrest[0]);
+ &Apache::lonnet::devalidate_title_cache($renamed_url);
}
# Store the changed version
- &storemap($coursenum,$coursedom,$folder.'.sequence');
+ ($errtext,$fatal)=&storemap($coursenum,$coursedom,
+ $folder.'.'.$container);
+ if ($fatal) {
+ $r->print('
'.$errtext.'
');
+ return;
+ }
}
# Group import/search
- if ($ENV{'form.importdetail'}) {
- foreach (split(/\&/,$ENV{'form.importdetail'})) {
- if (defined($_)) {
- my ($name,$url)=split(/\=/,$_);
- $name=&Apache::lonnet::unescape($name);
- $url=&Apache::lonnet::unescape($url);
- if ($url) {
- my $idx=$#Apache::lonratedt::resources+1;
- $Apache::lonratedt::order
- [$#Apache::lonratedt::order+1]=$idx;
- my $ext='false';
- if ($url=~/^http\:\/\//) { $ext='true'; }
- $url=~s/\:/\:/g;
- $name=~s/\:/\:/g;
- $Apache::lonratedt::resources[$idx]=
- $name.':'.$url.':'.$ext.':normal:res';
- }
- }
- }
+ if ($env{'form.importdetail'}) {
+ my @imports;
+# &Apache::lonnet::logthis("imp detail ".$env{'form.importdetail'});
+ foreach (split(/\&/,$env{'form.importdetail'})) {
+ if (defined($_)) {
+ my ($name,$url)=split(/\=/,$_);
+ $name=&unescape($name);
+ $url=&unescape($url);
+ push @imports, $name, $url;
+ }
+ }
# Store the changed version
- &storemap($coursenum,$coursedom,$folder.'.sequence');
+ ($errtext,$fatal)=&group_import($coursenum, $coursedom, $folder,
+ $container,'londocs',@imports);
+ if ($fatal) {
+ $r->print('
'.$errtext.'
');
+ return;
+ }
}
# Loading a complete map
- if (($ENV{'form.importmap'}) && ($ENV{'form.loadmap'})) {
- foreach
-(&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$ENV{'form.importmap'}))) {
- my $idx=$#Apache::lonratedt::resources;
- $idx++;
- $Apache::lonratedt::resources[$idx]=$_;
- $Apache::lonratedt::order
- [$#Apache::lonratedt::order+1]=$idx;
- }
-
+ if ($env{'form.loadmap'}) {
+ if ($env{'form.importmap'}=~/\w/) {
+ foreach (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
+ my ($title,$url,$ext,$type)=split(/\:/,$_);
+ my $idx=&LONCAPA::map::getresidx($url);
+ $LONCAPA::map::resources[$idx]=$_;
+ $LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx;
+ }
# Store the changed version
- &storemap($coursenum,$coursedom,$folder.'.sequence');
+ ($errtext,$fatal)=&storemap($coursenum,$coursedom,
+ $folder.'.'.$container);
+ if ($fatal) {
+ $r->print('
'.$errtext.'
');
+ return;
+ }
+ } 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)) {
+ $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.').'
\n");
+ $r->print(''.&mt('Return to DOCS').'');
+}
+
+
+#
+# -------------------------------------------------------------- Verify Content
+#
+sub verifycontent {
+ my ($r) = @_;
+ my $type = &Apache::loncommon::course_type();
my $loaderror=&Apache::lonnet::overloaderror($r);
if ($loaderror) { return $loaderror; }
-
- $r->print('Verify Content'.
- &Apache::loncommon::bodytag('Verify Course Documents'));
+ $r->print(&Apache::loncommon::start_page('Verify '.$type.' Documents'));
+ $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$type.' Documents'));
$hashtied=0;
undef %alreadyseen;
%alreadyseen=();
&tiehash();
foreach (keys %hash) {
- if (($_=~/^src\_(.+)$/) && (!$alreadyseen{$hash{$_}})) {
+ if ($hash{$_}=~/\.(page|sequence)$/) {
+ if (($_=~/^src_/) && ($alreadyseen{&unescape($hash{$_})})) {
+ $r->print(''.
+ &mt('The following sequence or page is included more than once in your '.$type.': ').
+ &unescape($hash{$_}).' '.
+ &mt('Note that grading records for problems included in this sequence or folder will overlap.'));
+ }
+ }
+ if (($_=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$_})})) {
&checkonthis($r,$hash{$_},0,$hash{'title_'.$1});
}
}
&untiehash();
- $r->print('
Done.
');
- } elsif ($ENV{'form.versions'}) {
- $r->print('Check Versions'.
- &Apache::loncommon::bodytag('Check Course Document Versions'));
- $hashtied=0;
- &tiehash();
- my %changes=&Apache::lonnet::dump
- ('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;
- }
- my $seltext='during the last '.$ENV{'form.timerange'}.' seconds';
- my $startsel='';
- my $monthsel='';
- my $weeksel='';
- my $daysel='';
- if ($ENV{'form.timerange'}==-1) {
- $seltext='since start of course';
- $startsel='selected';
- $ENV{'form.timerange'}=time;
- }
- my $starttime=time-$ENV{'form.timerange'};
- if ($ENV{'form.timerange'}==2592000) {
- $seltext='during the last month ('.localtime($starttime).')';
- $monthsel='selected';
- } elsif ($ENV{'form.timerange'}==604800) {
- $seltext='during the last week ('.localtime($starttime).')';
- $weeksel='selected';
- } elsif ($ENV{'form.timerange'}==86400) {
- $seltext='since yesterday ('.localtime($starttime).')';
- $daysel='selected';
- }
-
- $r->print(<print('
'.&mt('Done').'.
'.''.
+ &mt('Return to DOCS').'');
+}
+
+
+# -------------------------------------------------------------- Check Versions
+
+sub devalidateversioncache {
+ my $src=shift;
+ &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
+ &Apache::lonnet::clutter($src));
+}
+
+sub checkversions {
+ my ($r) = @_;
+ my $type = &Apache::loncommon::course_type();
+ $r->print(&Apache::loncommon::start_page("Check $type Document Versions"));
+ $r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $type Document Versions"));
+ my $header='';
+ my $startsel='';
+ my $monthsel='';
+ my $weeksel='';
+ my $daysel='';
+ my $allsel='';
+ my %changes=();
+ my $starttime=0;
+ my $haschanged=0;
+ my %setversions=&Apache::lonnet::dump('resourceversions',
+ $env{'course.'.$env{'request.course.id'}.'.domain'},
+ $env{'course.'.$env{'request.course.id'}.'.num'});
+
+ $hashtied=0;
+ &tiehash();
+ my %newsetversions=();
+ if ($env{'form.setmostrecent'}) {
+ $haschanged=1;
+ foreach (keys %hash) {
+ if ($_=~/^ids\_(\/res\/.+)$/) {
+ $newsetversions{$1}='mostrecent';
+ &devalidateversioncache($1);
+ }
+ }
+ } elsif ($env{'form.setcurrent'}) {
+ $haschanged=1;
+ foreach (keys %hash) {
+ if ($_=~/^ids\_(\/res\/.+)$/) {
+ my $getvers=&Apache::lonnet::getversion($1);
+ if ($getvers>0) {
+ $newsetversions{$1}=$getvers;
+ &devalidateversioncache($1);
+ }
+ }
+ }
+ } elsif ($env{'form.setversions'}) {
+ $haschanged=1;
+ foreach (keys %env) {
+ if ($_=~/^form\.set_version_(.+)$/) {
+ my $src=$1;
+ if (($env{$_}) && ($env{$_} ne $setversions{$src})) {
+ $newsetversions{$src}=$env{$_};
+ &devalidateversioncache($src);
+ }
+ }
+ }
+ }
+ if ($haschanged) {
+ if (&Apache::lonnet::put('resourceversions',\%newsetversions,
+ $env{'course.'.$env{'request.course.id'}.'.domain'},
+ $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
+ $r->print('
'.&mt('Your Version Settings have been Saved').'
');
+ } else {
+ $r->print('
'.&mt('An Error Occured while Attempting to Save your Version Settings').'
');
+ }
+ &mark_hash_old();
+ }
+ &changewarning($r,'');
+ if ($env{'form.timerange'} eq 'all') {
+# show all documents
+ $header=&mt('All Documents in '.$type);
+ $allsel=1;
+ foreach (keys %hash) {
+ if ($_=~/^ids\_(\/res\/.+)$/) {
+ my $src=$1;
+ $changes{$src}=1;
+ }
+ }
+ } else {
+# show documents which changed
+ %changes=&Apache::lonnet::dump
+ ('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;
+ }
+ my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
+ .&mt('seconds');
+ if ($env{'form.timerange'}==-1) {
+ $seltext='since start of course';
+ $startsel='selected';
+ $env{'form.timerange'}=time;
+ }
+ $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) {
+ $seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
+ $weeksel='selected';
+ } elsif ($env{'form.timerange'}==86400) {
+ $seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
+ $daysel='selected';
+ }
+ $header=&mt('Content changed').' '.$seltext;
+ } else {
+ $header=&mt('No content modifications yet.');
+ }
+ }
+ %setversions=&Apache::lonnet::dump('resourceversions',
+ $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 '.$type,
+ 'lm' => 'Version changes since last Month',
+ 'lw' => 'Version changes since last Week',
+ 'sy' => 'Version changes since Yesterday',
+ 'al' => 'All Resources (possibly large output)',
+ 'sd' => 'Display',
+ 'fi' => 'File',
+ 'md' => 'Modification Date',
+ 'mr' => 'Most recently published Version',
+ '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');
+ $r->print(<
+
+
+
-
-
-
Content changed $seltext
-
-
-
File
Modification Date
-
Version
Differences
+
+
$header
+
+
ENDHEADERS
- foreach (keys %changes) {
- if ($changes{$_}>$starttime) {
- my ($root,$extension)=($_=~/^(.*)\.(\w+)$/);
- my $currentversion=&Apache::lonnet::getversion($_);
- my $linkurl=&Apache::lonnet::clutter($_);
- $r->print(
- '
');
+ my $lastold=1;
+ for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
+ my $url=$root.'.'.$prevvers.'.'.$extension;
+ if (&Apache::lonnet::metadata($url,'lastrevisiondate')<
+ $starttime) {
+ $lastold=$prevvers;
+ }
+ }
+ #
+ # Code to figure out how many version entries should go in
+ # each of the four columns
+ my $entries_per_col = 0;
+ my $num_entries = ($currentversion-$lastold);
+ if ($num_entries % 4 == 0) {
+ $entries_per_col = $num_entries/4;
+ } else {
+ $entries_per_col = $num_entries/4 + 1;
+ }
+ my $entries_count = 0;
+ $r->print('
');
+
+ &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,$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=>&Apache::loncommon::course_type()." Documents",
+ 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
+sub handler {
+ my $r = shift;
+ &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','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');
+ $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
+ 'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
+ $help{'Simple Problem'} = &Apache::loncommon::help_open_topic(
+ 'Option_Response_Simple');
+ $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
+ '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');
+
+# 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 ($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 ($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 $buttons='';
my $showdoc=0;
+ my $containertag;
+ my $uploadtag;
&Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
- ['folder','foldername']);
+ ['folderpath','pagepath',
+ 'pagesymb']);
+ 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;
+ $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('srm',$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');
-}
-
-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 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();');
-}
+ $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL') . "/");
-function changename(folder,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.folder.value=folder;
- this.document.forms.renameform.submit();
- }
-}
-
-function removeres(folder,index,oldtitle) {
- if ((oldtitle=='NO RESOURCE') || (confirm('Remove "'+oldtitle+'"?'))) {
- this.document.forms.renameform.cmd.value='del_'+index;
- this.document.forms.renameform.folder.value=folder;
- this.document.forms.renameform.submit();
+ if ($allowed) {
+ $script .= &editing_js($udom,$uname);
}
-}
-
-
-ENDNEWSCRIPT
- }
# -------------------------------------------------------------------- Body tag
- $r->print(''.
- &Apache::loncommon::bodytag('Course Documents','',$events).
- $buttons);
- 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.
+ $upload_result = &process_file_upload(\$upload_output,$coursenum,
+ $coursedom,\%allfiles,
+ \%codebase,$1);
+ 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 '.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',
+ 'abou' => 'About User',
+ 'imsf' => 'Import IMS package',
+ 'file' => 'File',
+ 'title' => 'Title',
+ 'comment' => 'Comment',
+ 'parse' => 'If HTML file, upload embedded images/multimedia files'
+ );
+# -----------------------------------------------------------------------------
if ($allowed) {
- $r->print(&Apache::loncommon::help_open_topic('Docs_Adding_Course_Doc',
- 'Editing the Table of Contents for your Course'));
+ &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'};
+ if (!$folderpath) {
+ if ($env{'form.folder'} eq '' ||
+ $env{'form.folder'} eq 'supplemental') {
+ $folderpath='default&'.
+ &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 '.$type)));
}
# --------------------------------------------------------- Standard documents
$r->print('
');
if (($standard) && ($allowed) && (!$forcesupplement)) {
- $r->print('
Main Course Documents'.
- ($allowed?' '.$help{'Main_Course_Documents'}:'').'