--- loncom/interface/londocs.pm 2007/07/03 00:17:42 1.283
+++ loncom/interface/londocs.pm 2009/01/28 11:51:22 1.326
@@ -1,3243 +1,3679 @@
-# The LearningOnline Network
-# Documents
-#
-# $Id: londocs.pm,v 1.283 2007/07/03 00:17:42 albertel Exp $
-#
-# Copyright Michigan State University Board of Trustees
-#
-# This file is part of the LearningOnline Network with CAPA (LON-CAPA).
-#
-# LON-CAPA is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
-#
-# LON-CAPA is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with LON-CAPA; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-#
-# /home/httpd/html/adm/gpl.txt
-#
-# http://www.lon-capa.org/
-#
-
-package Apache::londocs;
-
-use strict;
-use Apache::Constants qw(:common :http);
-use Apache::imsexport;
-use Apache::lonnet;
-use Apache::loncommon;
-use LONCAPA::map();
-use Apache::lonratedt();
-use Apache::lonxml;
-use Apache::lonclonecourse;
-use Apache::lonnavmaps;
-use HTML::Entities;
-use GDBM_File;
-use Apache::lonlocal;
-use Cwd;
-use LONCAPA qw(:DEFAULT :match);
-
-my $iconpath;
-
-my %hash;
-
-my $hashtied;
-my %alreadyseen=();
-
-my $hadchanges;
-
-# Available help topics
-
-my %help=();
-
-# Mapread read maps into LONCAPA::map:: global arrays
-# @order and @resources, determines status
-# sets @order - pointer to resources in right order
-# sets @resources - array with the resources with correct idx
-#
-
-sub mapread {
- my ($coursenum,$coursedom,$map)=@_;
- return
- &LONCAPA::map::mapread('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
- $map);
-}
-
-sub storemap {
- my ($coursenum,$coursedom,$map)=@_;
- my ($outtext,$errtext)=
- &LONCAPA::map::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
- $map,1);
- if ($errtext) { return ($errtext,2); }
-
- $hadchanges=1;
- return ($errtext,0);
-}
-
-# ----------------------------------------- Return hash with valid author names
-
-sub authorhosts {
- my %outhash=();
- my $home=0;
- my $other=0;
- foreach (keys %env) {
- if ($_=~/^user\.role\.(au|ca)\.(.+)$/) {
- my $role=$1;
- my $realm=$2;
- my ($start,$end)=split(/\./,$env{$_});
- if (($start) && ($start>time)) { next; }
- if (($end) && (time>$end)) { next; }
- my $ca; my $cd;
- if ($1 eq 'au') {
- $ca=$env{'user.name'};
- $cd=$env{'user.domain'};
- } else {
- ($cd,$ca)=($realm=~/^\/($match_domain)\/($match_username)$/);
- }
- my $allowed=0;
- my $myhome=&Apache::lonnet::homeserver($ca,$cd);
- my @ids=&Apache::lonnet::current_machine_ids();
- foreach my $id (@ids) { if ($id eq $myhome) { $allowed=1; } }
- if ($allowed) {
- $home++;
- $outhash{'home_'.$ca.'@'.$cd}=1;
- } else {
- $outhash{'otherhome_'.$ca.'@'.$cd}=$myhome;
- $other++;
- }
- }
- }
- return ($home,$other,%outhash);
-}
-# ------------------------------------------------------ Generate "dump" button
-
-sub dumpbutton {
- my ($home,$other,%outhash)=&authorhosts();
- my $type = &Apache::loncommon::course_type();
- if ($home+$other==0) { return ''; }
- if ($home) {
- return '
');
-# 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;
- 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.'
');
- } else {
-# ------------------------------------------------------------ Process commands
-
-# ---------------- if they are for this folder and user allowed to make changes
- 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') {
- 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];
- }
- $#LONCAPA::map::order--;
- } elsif ($cmd eq 'up') {
- 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($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(/\:/,
- $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
- ($errtext,$fatal)=&storemap($coursenum,$coursedom,
- $folder.'.'.$container);
- if ($fatal) {
- $r->print('
'.$errtext.'
');
- return;
- }
- }
-# Group import/search
- 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
- ($errtext,$fatal)=&group_import($coursenum, $coursedom, $folder,
- $container,'londocs',@imports);
- if ($fatal) {
- $r->print('
'.$errtext.'
');
- return;
- }
- }
-# Loading a complete map
- 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
- ($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(&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 ($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('
'.&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(<
-
-
-
-
-
-
$header
-
-
-ENDHEADERS
- foreach (sort keys %changes) {
- if ($changes{$_}>$starttime) {
- my ($root,$extension)=($_=~/^(.*)\.(\w+)$/);
- my $currentversion=&Apache::lonnet::getversion($_);
- if ($currentversion<0) {
- $currentversion=&mt('Could not be determined.');
- }
- 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 = 0;
- my $forcesupplement;
- my $script='';
- my $showdoc=0;
- my $containertag;
- my $uploadtag;
- &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
- ['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;
- }
- unless ($showdoc) { # got called from remote
- if (($env{'form.folder'}=~/^(?:group|default)_/) ||
- ($env{'form.folder'} =~ m:^\d+/(pages|sequences)/:)) {
- $forcestandard = 1;
- }
- $forcesupplement=($env{'form.folder'}=~/^supplemental_/);
-
- 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;
- }
-
-# get course data
- my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
- my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
-
-# get personal data
- my $uname=$env{'user.name'};
- my $udom=$env{'user.domain'};
- my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));
-
-# graphics settings
-
- $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL') . "/");
-
- if ($allowed) {
- $script .= &editing_js($udom,$uname);
- }
-# -------------------------------------------------------------------- Body tag
- $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) {
- &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('
');
+# 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('
'.&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('Unable to retrieve information about course contents').
+ '
');
+ &Apache::lonnet::logthis('Symb list failed - could not create navmap object in '.lc($type).':'.$env{'request.course.id'});
+ } else {
+ $r->print("
\n");
+ }
+ $r->print(''.&mt('Return to DOCS').'');
+}
+
+
+sub verifycontent {
+ my ($r) = @_;
+ my $type = &Apache::loncommon::course_type();
+ my $loaderror=&Apache::lonnet::overloaderror($r);
+ if ($loaderror) { return $loaderror; }
+ $r->print(&Apache::loncommon::start_page('Verify '.$type.' Documents'));
+ $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$type.' Documents'));
+ $hashtied=0;
+ undef %alreadyseen;
+ %alreadyseen=();
+ &tiehash();
+ foreach my $key (keys(%hash)) {
+ if ($hash{$key}=~/\.(page|sequence)$/) {
+ if (($key=~/^src_/) && ($alreadyseen{&unescape($hash{$key})})) {
+ $r->print(''.
+ &mt('The following sequence or page is included more than once in your '.$type.': ').
+ &unescape($hash{$key}).' '.
+ &mt('Note that grading records for problems included in this sequence or folder will overlap.'));
+ }
+ }
+ if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) {
+ &checkonthis($r,$hash{$key},0,$hash{'title_'.$1});
+ }
+ }
+ &untiehash();
+ $r->print('
'.&mt('Done').'.
'.''.
+ &mt('Return to DOCS').'');
+}
+
+
+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 my $key (keys(%hash)) {
+ if ($key=~/^ids\_(\/res\/.+)$/) {
+ $newsetversions{$1}='mostrecent';
+ &devalidateversioncache($1);
+ }
+ }
+ } elsif ($env{'form.setcurrent'}) {
+ $haschanged=1;
+ foreach my $key (keys(%hash)) {
+ if ($key=~/^ids\_(\/res\/.+)$/) {
+ my $getvers=&Apache::lonnet::getversion($1);
+ if ($getvers>0) {
+ $newsetversions{$1}=$getvers;
+ &devalidateversioncache($1);
+ }
+ }
+ }
+ } elsif ($env{'form.setversions'}) {
+ $haschanged=1;
+ foreach my $key (keys(%env)) {
+ if ($key=~/^form\.set_version_(.+)$/) {
+ my $src=$1;
+ if (($env{$key}) && ($env{$key} ne $setversions{$src})) {
+ $newsetversions{$src}=$env{$key};
+ &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 my $key (keys(%hash)) {
+ if ($key=~/^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(<
+
+
+
+
+
+
$header
+
+
+ENDHEADERS
+ foreach my $key (sort(keys(%changes))) {
+ if ($changes{$key}>$starttime) {
+ my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
+ my $currentversion=&Apache::lonnet::getversion($key);
+ if ($currentversion<0) {
+ $currentversion=&mt('Could not be determined.');
+ }
+ my $linkurl=&Apache::lonnet::clutter($key);
+ $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('
+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('