Annotation of loncom/interface/londocs.pm, revision 1.136

1.1       www         1: # The LearningOnline Network
1.2       www         2: # Documents
1.1       www         3: #
1.136   ! albertel    4: # $Id: londocs.pm,v 1.135 2004/07/08 19:58:29 albertel Exp $
1.1       www         5: #
1.3       www         6: # Copyright Michigan State University Board of Trustees
1.1       www         7: #
1.3       www         8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
1.1       www         9: #
1.3       www        10: # LON-CAPA is free software; you can redistribute it and/or modify
                     11: # it under the terms of the GNU General Public License as published by
                     12: # the Free Software Foundation; either version 2 of the License, or
                     13: # (at your option) any later version.
1.1       www        14: #
1.3       www        15: # LON-CAPA is distributed in the hope that it will be useful,
                     16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
                     17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     18: # GNU General Public License for more details.
                     19: #
                     20: # You should have received a copy of the GNU General Public License
                     21: # along with LON-CAPA; if not, write to the Free Software
                     22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
                     23: #
                     24: # /home/httpd/html/adm/gpl.txt
                     25: #
                     26: # http://www.lon-capa.org/
                     27: #
                     28: 
1.2       www        29: package Apache::londocs;
1.1       www        30: 
                     31: use strict;
1.28      www        32: use Apache::Constants qw(:common :http);
1.4       www        33: use Apache::lonnet;
                     34: use Apache::loncommon;
1.7       www        35: use Apache::lonratedt;
                     36: use Apache::lonratsrv;
1.15      www        37: use Apache::lonxml;
1.74      www        38: use Apache::loncreatecourse;
1.38      www        39: use HTML::Entities;
1.27      www        40: use GDBM_File;
1.81      www        41: use Apache::lonlocal;
1.7       www        42: 
1.8       www        43: my $iconpath;
1.7       www        44: 
1.27      www        45: my %hash;
                     46: 
                     47: my $hashtied;
1.29      www        48: my %alreadyseen=();
1.27      www        49: 
1.40      www        50: my $hadchanges;
                     51: 
1.47      www        52: # Available help topics
                     53: 
                     54: my %help=();
                     55: 
1.7       www        56: # Mapread read maps into lonratedt::global arrays 
1.10      www        57: # @order and @resources, determines status
1.7       www        58: # sets @order - pointer to resources in right order
                     59: # sets @resources - array with the resources with correct idx
                     60: #
                     61: 
                     62: sub mapread {
                     63:     my ($coursenum,$coursedom,$map)=@_;
                     64:     return
                     65:       &Apache::lonratedt::mapread('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
                     66:                                 $map);
                     67: }
                     68: 
                     69: sub storemap {
                     70:     my ($coursenum,$coursedom,$map)=@_;
1.104     albertel   71:     my ($outtext,$errtext)=
1.7       www        72:       &Apache::lonratedt::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
1.15      www        73:                                 $map,1);
1.104     albertel   74:     if ($errtext) { return ($errtext,2); }
                     75:     
                     76:     $hadchanges=1;
                     77:     return ($errtext,0);
1.7       www        78: }
                     79: 
1.74      www        80: # ----------------------------------------- Return hash with valid author names
                     81: 
                     82: sub authorhosts {
                     83:     my %outhash=();
                     84:     my $home=0;
                     85:     my $other=0;
                     86:     foreach (keys %ENV) {
                     87: 	if ($_=~/^user\.role\.(au|ca)\.(.+)$/) {
                     88: 	    my $role=$1;
                     89: 	    my $realm=$2;
                     90: 	    my ($start,$end)=split(/\./,$ENV{$_});
                     91: 	    if (($start) && ($start>time)) { next; }
                     92: 	    if (($end) && (time>$end)) { next; }
                     93: 	    my $ca; my $cd;
                     94: 	    if ($1 eq 'au') {
                     95: 		$ca=$ENV{'user.name'};
                     96: 		$cd=$ENV{'user.domain'};
                     97: 	    } else {
                     98: 		($cd,$ca)=($realm=~/^\/(\w+)\/(\w+)$/);
                     99: 	    }
1.107     albertel  100: 	    my $allowed=0;
                    101: 	    my $myhome=&Apache::lonnet::homeserver($ca,$cd);
                    102: 	    my @ids=&Apache::lonnet::current_machine_ids();
                    103: 	    foreach my $id (@ids) { if ($id eq $myhome) { $allowed=1; } }
                    104: 	    if ($allowed) {
1.74      www       105: 		$home++;
                    106: 		$outhash{'home_'.$ca.'@'.$cd}=1;
                    107: 	    } else {
1.107     albertel  108: 		$outhash{'otherhome_'.$ca.'@'.$cd}=$myhome;
1.74      www       109: 		$other++;
                    110: 	    }
                    111: 	}
                    112:     }
                    113:     return ($home,$other,%outhash);
                    114: }
                    115: # ------------------------------------------------------ Generate "dump" button
                    116: 
                    117: sub dumpbutton {
                    118:     my ($home,$other,%outhash)=&authorhosts();
                    119:     if ($home+$other==0) { return ''; }
                    120:     my $output='</td><td bgcolor="#DDDDCC">';
                    121:     if ($home) {
                    122: 	return '</td><td bgcolor="#DDDDCC">'.
1.81      www       123: 	    '<input type="submit" name="dumpcourse" value="'.
1.130     www       124: 	    &mt('Dump Course DOCS to Construction Space').'" />'.
                    125: 	    &Apache::loncommon::help_open_topic('Docs_Dump_Course_Docs');
1.74      www       126:     } else {
                    127: 	return'</td><td bgcolor="#DDDDCC">'.
1.81      www       128:      &mt('Dump Course DOCS to Construction Space: available on other servers');
1.74      www       129:     }
                    130: }
                    131: 
                    132: # -------------------------------------------------------- Actually dump course
                    133: 
                    134: sub dumpcourse {
1.75      www       135:     my $r=shift;
                    136:     $r->print('<html><head><title>Dump DOCS</title></head>'.
1.76      www       137:         &Apache::loncommon::bodytag('Dump Course DOCS to Construction Space').
                    138: 	      '<form name="dumpdoc" method="post">');
1.74      www       139:     my ($home,$other,%outhash)=&authorhosts();
1.75      www       140:     unless ($home) { return ''; }
1.76      www       141:     my $origcrsid=$ENV{'request.course.id'};
                    142:     my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
                    143:     if (($ENV{'form.authorspace'}) && ($ENV{'form.authorfolder'}=~/\w/)) {
                    144: # Do the dumping
1.75      www       145: 	unless ($outhash{'home_'.$ENV{'form.authorspace'}}) { return ''; }
                    146: 	my ($ca,$cd)=split(/\@/,$ENV{'form.authorspace'});
1.87      www       147: 	$r->print('<h3>'.&mt('Copying Files').'</h3>');
1.76      www       148: 	my $title=$ENV{'form.authorfolder'};
1.79      www       149: 	$title=~s/[^\w\/]+/\_/g;
                    150: 	my %replacehash=();
                    151: 	foreach (keys %ENV) {
                    152: 	    if ($_=~/^form\.namefor\_(.+)/) {
                    153: 		$replacehash{$1}=$ENV{$_};
                    154: 	    }
                    155: 	}
                    156: 	my $crs='/uploaded/'.$ENV{'request.course.id'}.'/';
                    157: 	$crs=~s/\_/\//g;
                    158: 	foreach (keys %replacehash) {
                    159: 	    my $newfilename=$title.'/'.$replacehash{$_};
1.132     www       160: 	    $newfilename=~s/[^\w\/\.\/]+/\_/g;
1.79      www       161: 	    my @dirs=split(/\//,$newfilename);
                    162: 	    my $path='/home/'.$ca.'/public_html';
                    163: 	    my $makepath=$path;
                    164: 	    my $fail=0;
                    165: 	    for (my $i=0;$i<$#dirs;$i++) {
                    166: 		$makepath.='/'.$dirs[$i];
                    167: 		unless (-e $makepath) { 
                    168: 		    unless(mkdir($makepath,0777)) { $fail=1; } 
                    169: 		}
                    170: 	    }
                    171: 	    $r->print('<br /><tt>'.$_.'</tt> => <tt>'.$newfilename.'</tt>: ');
                    172: 	    if (my $fh=Apache::File->new('>'.$path.'/'.$newfilename)) {
                    173: 		if ($_=~/\.(sequence|page|html|htm|xml|xhtml)$/) {
                    174: 		    print $fh &Apache::loncreatecourse::rewritefile(
                    175:          &Apache::loncreatecourse::readfile($ENV{'request.course.id'},$_),
                    176: 				     (%replacehash,$crs => '')
                    177: 								    );
                    178: 		} else {
                    179: 		    print $fh
                    180:          &Apache::loncreatecourse::readfile($ENV{'request.course.id'},$_);
                    181: 		       }
                    182: 		$fh->close();
                    183: 	    } else {
                    184: 		$fail=1;
                    185: 	    }
                    186: 	    if ($fail) {
                    187: 		$r->print('<font color="red">fail</font>');
                    188: 	    } else {
                    189: 		$r->print('<font color="green">ok</font>');
                    190: 	    }
                    191: 	}
1.76      www       192:     } else {
                    193: # Input form
                    194: 	unless ($home==1) {
                    195: 	    $r->print(
1.81      www       196: 		      '<h3>'.&mt('Select the Construction Space').'</h3><select name="authorspace">');
1.76      www       197: 	}
                    198: 	foreach (sort keys %outhash) {
                    199: 	    if ($_=~/^home_(.+)$/) {
                    200: 		if ($home==1) {
                    201: 		    $r->print(
                    202: 		  '<input type="hidden" name="authorspace" value="'.$1.'" />');
                    203: 		} else {
1.133     www       204: 		    $r->print('<option value="'.$1.'">'.$1.' - '.
                    205: 			      &Apache::loncommon::plainname(split(/\@/,$1)).'</option>');
1.76      www       206: 		}
                    207: 	    }
                    208: 	}
                    209: 	unless ($home==1) {
                    210: 	    $r->print('</select>');
                    211: 	}
                    212: 	my $title=$origcrsdata{'description'};
                    213: 	$title=~s/\s+/\_/gs;
                    214: 	$title=~s/\W//gs;
1.81      www       215: 	$r->print('<h3>'.&mt('Folder in Construction Space').'</h3><input type="text" size="50" name="authorfolder" value="'.$title.'" /><br />');
1.76      www       216: 	&tiehash();
1.81      www       217: 	$r->print('<h3>'.&mt('Filenames in Construction Space').'</h3><table border="2"><tr><th>'.&mt('Internal Filename').'</th><th>'.&mt('Title').'</th><th>'.&mt('Save as ...').'</th></tr>');
1.76      www       218: 	foreach (&Apache::loncreatecourse::crsdirlist($origcrsid,'userfiles')) {
1.78      www       219: 	    $r->print('<tr><td>'.$_.'</td>');
                    220: 	    my ($ext)=($_=~/\.(\w+)$/);
                    221: 	    my $title=$hash{'title_'.$hash{
                    222: 		'ids_/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'.$_}};
                    223: 	    $r->print('<td>'.($title?$title:'&nbsp;').'</td>');
                    224: 	    unless ($title) {
                    225: 		$title=$_;
                    226: 	    }
                    227: 	    $title=~s/\.(\w+)$//;
1.132     www       228: 	    $title=~s/[^\w\/]+/\_/gs;
1.78      www       229: 	    $title.='.'.$ext;
1.79      www       230: 	    $r->print("\n<td><input type='text' size='60' name='namefor_".$_."' value='".$title."' /></td></tr>\n");
1.76      www       231: 	}
1.78      www       232: 	$r->print("</table>\n");
1.76      www       233: 	&untiehash();
                    234: 	$r->print(
1.81      www       235:   '<p><input type="submit" name="dumpcourse" value="'.&mt('Dump Course DOCS').'" /></p></form>');
1.75      www       236:     }
1.74      www       237: }
1.76      www       238: 
1.74      www       239: 
1.73      bowersj2  240: # Imports the given (name, url) resources into the course
                    241: # coursenum, coursedom, and folder must precede the list
                    242: sub group_import {
                    243:     my $coursenum = shift;
                    244:     my $coursedom = shift;
                    245:     my $folder = shift;
                    246:     while (@_) {
                    247: 	my $name = shift;
                    248: 	my $url = shift;
                    249: 	if ($url) {
                    250: 	    my $idx = $#Apache::lonratedt::resources + 1;
                    251: 	    $Apache::lonratedt::order[$#Apache::lonratedt::order+1]=$idx;
                    252: 	    my $ext = 'false';
                    253: 	    if ($url=~/^http:\/\//) { $ext = 'true'; }
                    254: 	    $url =~ s/:/\&colon;/g;
                    255: 	    $name =~ s/:/\&colon;/g;
                    256: 	    $Apache::lonratedt::resources[$idx] = 
                    257: 		join ':', ($name, $url, $ext, 'normal', 'res');
                    258: 	}
                    259:     }
1.104     albertel  260:     return &storemap($coursenum, $coursedom, $folder.'.sequence');
1.73      bowersj2  261: }
                    262: 
1.114     albertel  263: sub breadcrumbs {
                    264:     my ($where)=@_;
                    265:     &Apache::lonhtmlcommon::clear_breadcrumbs();
1.116     albertel  266:     my (@folders)=split('&',$ENV{'form.folderpath'});
                    267:     my $folderpath;
                    268:     while (@folders) {
                    269: 	my $folder=shift(@folders);
                    270: 	my $foldername=shift(@folders);
                    271: 	if ($folderpath) {$folderpath.='&';}
                    272: 	$folderpath.=$folder.'&'.$foldername;
                    273: 	my $url='/adm/coursedocs?folderpath='.
                    274: 	    &Apache::lonnet::escape($folderpath);
1.114     albertel  275: 	    &Apache::lonhtmlcommon::add_breadcrumb(
                    276: 		      {'href'=>$url,
                    277: 		       'title'=>&Apache::lonnet::unescape($foldername),
1.117     albertel  278: 		       'text'=>'<font size="+1">'.
                    279: 			   &Apache::lonnet::unescape($foldername).'</font>'
                    280: 		       });
1.114     albertel  281: 		       
                    282: 						 
                    283:     }
1.116     albertel  284:     return &Apache::lonhtmlcommon::breadcrumbs(undef,undef,undef,undef,undef,0);
1.114     albertel  285: }
                    286: 
1.7       www       287: sub editor {
                    288:     my ($r,$coursenum,$coursedom,$folder,$allowed)=@_;
1.114     albertel  289: 
                    290:     $r->print(&breadcrumbs($folder));
1.10      www       291:     my $errtext='';
                    292:     my $fatal=0;
                    293:     ($errtext,$fatal)=
1.7       www       294:           &mapread($coursenum,$coursedom,$folder.'.sequence');
1.17      www       295:     if ($#Apache::lonratedt::order<1) {
                    296:        	$Apache::lonratedt::order[0]=1;
                    297:         $Apache::lonratedt::resources[1]='';
                    298:     }
1.7       www       299:     if ($fatal) {
                    300: 	   $r->print('<p><font color="red">'.$errtext.'</font></p>');
                    301:     } else {
                    302: # ------------------------------------------------------------ Process commands
1.121     www       303: 
1.16      www       304: # ---------------- if they are for this folder and user allowed to make changes
                    305: 	if (($allowed) && ($ENV{'form.folder'} eq $folder)) {
1.123     www       306: # set parameters and change order
1.121     www       307: 	    if (defined($ENV{'form.setparms'})) {
                    308: 		my $idx=$ENV{'form.setparms'};
1.123     www       309: # set parameters
1.121     www       310: 		if ($ENV{'form.randpick_'.$idx}) {
1.122     www       311: 		    &Apache::lonratedt::storeparameter($idx,'parameter_randompick',$ENV{'form.randpick_'.$idx},'int_pos');
1.121     www       312: 		} else {
1.122     www       313: 		    &Apache::lonratedt::delparameter($idx,'parameter_randompick');
1.121     www       314: 		}
                    315: 		if ($ENV{'form.hidprs_'.$idx}) {
1.122     www       316: 		    &Apache::lonratedt::storeparameter($idx,'parameter_hiddenresource','yes','string_yesno');
1.121     www       317: 		} else {
1.122     www       318: 		    &Apache::lonratedt::delparameter($idx,'parameter_hiddenresource');
1.121     www       319: 		}
                    320: 		if ($ENV{'form.encprs_'.$idx}) {
1.122     www       321: 		    &Apache::lonratedt::storeparameter($idx,'parameter_encrypturl','yes','string_yesno');
1.121     www       322: 		} else {
1.122     www       323: 		    &Apache::lonratedt::delparameter($idx,'parameter_encrypturl');
1.121     www       324: 		}
                    325: 
1.123     www       326: 		if ($ENV{'form.newpos'}) {
                    327: # change order
                    328: 
                    329: 		    my $newpos=$ENV{'form.newpos'}-1;
1.124     www       330: 		    my $currentpos=$ENV{'form.currentpos'}-1;
1.125     www       331: 		    my $i;
                    332: 		    my @neworder=();
                    333: 		    if ($newpos>$currentpos) {
                    334: # moving stuff up
                    335: 			for ($i=0;$i<$currentpos;$i++) {
                    336: 			    $neworder[$i]=$Apache::lonratedt::order[$i];
                    337: 			}
                    338: 			for ($i=$currentpos;$i<$newpos;$i++) {
                    339: 			    $neworder[$i]=$Apache::lonratedt::order[$i+1];
                    340: 			}
                    341:                         $neworder[$newpos]=$Apache::lonratedt::order[$currentpos];
                    342: 			for ($i=$newpos+1;$i<=$#Apache::lonratedt::order;$i++) {
                    343: 			    $neworder[$i]=$Apache::lonratedt::order[$i];
                    344: 			}
                    345: 		    } else {
                    346: # moving stuff down
                    347: 			for ($i=0;$i<$newpos;$i++) {
                    348: 			    $neworder[$i]=$Apache::lonratedt::order[$i];
                    349: 			}
                    350: 			$neworder[$newpos]=$Apache::lonratedt::order[$currentpos];
                    351: 			for ($i=$newpos+1;$i<$currentpos+1;$i++) {
                    352: 			    $neworder[$i]=$Apache::lonratedt::order[$i-1];
                    353: 			}
                    354: 			for ($i=$currentpos+1;$i<=$#Apache::lonratedt::order;$i++) {
                    355: 			    $neworder[$i]=$Apache::lonratedt::order[$i];
                    356: 			}
                    357: 		    }
                    358: 		    @Apache::lonratedt::order=@neworder;
1.124     www       359: 		}
                    360: # store the changed version
1.123     www       361: 
1.124     www       362: 		($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.sequence');
                    363: 		if ($fatal) {
                    364: 		    $r->print('<p><font color="red">'.$errtext.'</font></p>');
                    365: 		    return;
1.123     www       366: 		}
1.124     www       367: 		
                    368: 	    }
1.123     www       369: 
1.10      www       370: # upload a file, if present
                    371:            if (($ENV{'form.uploaddoc.filename'}) &&
                    372:                ($ENV{'form.cmd'}=~/^upload_(\w+)/)) {
1.112     raeburn   373: 	    if ( ($folder=~/^$1/) || ($1 eq 'default') ) {
1.10      www       374: # this is for a course, not a user, so set coursedoc flag
                    375: # probably the only place in the system where this should be "1"
1.126     albertel  376: 	      my $url=&Apache::lonnet::userfileupload('uploaddoc',1,'docs');
1.10      www       377:               my $ext='false';
                    378:               if ($url=~/^http\:\/\//) { $ext='true'; }
                    379:               $url=~s/\:/\&colon;/g;
                    380: 	      my $comment=$ENV{'form.comment'};
                    381:               $comment=~s/\</\&lt\;/g;
                    382:               $comment=~s/\>/\&gt\;/g;
                    383:               $comment=~s/\:/\&colon;/g;
1.17      www       384:               if ($folder=~/^supplemental/) {
                    385: 		  $comment=time.'___&&&___'.$ENV{'user.name'}.'___&&&___'.
                    386: 		      $ENV{'user.domain'}.'___&&&___'.$comment;
                    387:               }
1.10      www       388:               my $newidx=$#Apache::lonratedt::resources+1;
                    389:               $Apache::lonratedt::resources[$newidx]=
                    390:                   $comment.':'.$url.':'.$ext.':normal:res';
                    391:               $Apache::lonratedt::order[$#Apache::lonratedt::order+1]=
                    392:                                                               $newidx;       
1.104     albertel  393: 
                    394: 	      ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.sequence');
                    395: 	      if ($fatal) {
                    396: 		  $r->print('<p><font color="red">'.$errtext.'</font></p>');
                    397: 		  return;
                    398: 	      }
1.10      www       399: 	     }
                    400:             }
1.8       www       401: 	    if ($ENV{'form.cmd'}) {
1.10      www       402:                 my ($cmd,$idx)=split(/\_/,$ENV{'form.cmd'});
                    403:                 if ($cmd eq 'del') {
1.128     albertel  404: 		    my (undef,$url)=split(':',$Apache::lonratedt::resources[$Apache::lonratedt::order[$idx]]);
                    405: 		    if ($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) {
                    406: 			&Apache::lonnet::removeuploadedurl($url);
                    407: 		    }
1.10      www       408: 		    for (my $i=$idx;$i<$#Apache::lonratedt::order;$i++) {
                    409:                         $Apache::lonratedt::order[$i]=
                    410:                           $Apache::lonratedt::order[$i+1];
                    411:                     }
                    412:                     $#Apache::lonratedt::order--;
                    413:                 } elsif ($cmd eq 'up') {
1.38      www       414: 		  if (($idx) && (defined($Apache::lonratedt::order[$idx-1]))) {
1.10      www       415:                     my $i=$Apache::lonratedt::order[$idx-1];
                    416:                     $Apache::lonratedt::order[$idx-1]=
                    417: 			$Apache::lonratedt::order[$idx];
                    418:                     $Apache::lonratedt::order[$idx]=$i;
1.38      www       419: 		   }
1.10      www       420:                 } elsif ($cmd eq 'down') {
1.38      www       421: 		   if (defined($Apache::lonratedt::order[$idx+1])) {
1.10      www       422:                     my $i=$Apache::lonratedt::order[$idx+1];
                    423:                     $Apache::lonratedt::order[$idx+1]=
                    424: 			$Apache::lonratedt::order[$idx];
                    425:                     $Apache::lonratedt::order[$idx]=$i;
1.38      www       426: 		   }
1.36      www       427:                 } elsif ($cmd eq 'rename') {
                    428:                     my ($rtitle,@rrest)=split(/\:/,
                    429:                        $Apache::lonratedt::resources[
                    430: 				       $Apache::lonratedt::order[$idx]]);
1.38      www       431:                     my $comment=
                    432:                      &HTML::Entities::decode($ENV{'form.title'});
1.36      www       433:                     $comment=~s/\</\&lt\;/g;
                    434:                     $comment=~s/\>/\&gt\;/g;
                    435:                     $comment=~s/\:/\&colon;/g;
                    436:                     $Apache::lonratedt::resources[
                    437: 				       $Apache::lonratedt::order[$idx]]=
                    438:                              $comment.':'.join(':',@rrest);
                    439:                     
1.10      www       440:                 }
                    441: # Store the changed version
1.104     albertel  442: 		($errtext,$fatal)=&storemap($coursenum,$coursedom,
                    443: 					    $folder.'.sequence');
                    444: 		if ($fatal) {
                    445: 		    $r->print('<p><font color="red">'.$errtext.'</font></p>');
                    446: 		    return;
                    447: 		}
1.8       www       448:             }
1.11      www       449: # Group import/search
                    450: 	    if ($ENV{'form.importdetail'}) {
1.73      bowersj2  451: 		my @imports;
                    452: 		foreach (split(/\&/,$ENV{'form.importdetail'})) {
                    453: 		    if (defined($_)) {
                    454: 			my ($name,$url)=split(/\=/,$_);
                    455: 			$name=&Apache::lonnet::unescape($name);
                    456: 			$url=&Apache::lonnet::unescape($url);
                    457: 			push @imports, $name, $url;
                    458: 		    }
                    459: 		}
1.11      www       460: # Store the changed version
1.104     albertel  461: 		($errtext,$fatal)=group_import($coursenum, $coursedom, $folder,
                    462: 					       @imports);
                    463: 		if ($fatal) {
                    464: 		    $r->print('<p><font color="red">'.$errtext.'</font></p>');
                    465: 		    return;
                    466: 		}
1.11      www       467:             }
1.53      www       468: # Loading a complete map
                    469: 	   if (($ENV{'form.importmap'}) && ($ENV{'form.loadmap'})) {
1.104     albertel  470: 	       foreach (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$ENV{'form.importmap'}))) {
1.53      www       471:                    my $idx=$#Apache::lonratedt::resources;
                    472:                    $idx++;
                    473:                    $Apache::lonratedt::resources[$idx]=$_;
                    474:                    $Apache::lonratedt::order
1.104     albertel  475: 		       [$#Apache::lonratedt::order+1]=$idx;
                    476: 	       }
1.53      www       477: 
                    478: # Store the changed version
1.104     albertel  479: 	       ($errtext,$fatal)=&storemap($coursenum,$coursedom,
                    480: 					   $folder.'.sequence');
                    481: 	       if ($fatal) {
                    482: 		   $r->print('<p><font color="red">'.$errtext.'</font></p>');
                    483: 		   return;
                    484: 	       }
1.53      www       485:            }
1.16      www       486:        }
                    487: # ---------------------------------------------------------------- End commands
1.7       www       488: # ---------------------------------------------------------------- Print screen
1.10      www       489:         my $idx=0;
                    490:         $r->print('<table>');
                    491:         foreach (@Apache::lonratedt::order) {
                    492:            my ($name,$url)=split(/\:/,$Apache::lonratedt::resources[$_]);
                    493:            unless ($name) {  $name=(split(/\//,$url))[-1]; }
1.106     www       494:            unless ($name) { next; }
1.112     raeburn   495:            $r->print(&entryline($idx,$name,$url,$folder,$allowed,$_,$coursenum));
1.10      www       496:            $idx++;
                    497:         }
1.131     www       498: 	unless ($idx) {
                    499: 	    $r->print('<tr><td>'.&mt('Currently no documents.').'</td></tr>');
                    500: 	}
1.10      www       501:         $r->print('</table>');
1.7       www       502:     }
                    503: }
1.1       www       504: 
1.8       www       505: # --------------------------------------------------------------- An entry line
                    506: 
                    507: sub entryline {
1.112     raeburn   508:     my ($index,$title,$url,$folder,$allowed,$residx,$coursenum)=@_;
1.38      www       509:     $title=~s/\&colon\;/\:/g;
                    510:     $title=&HTML::Entities::encode(&HTML::Entities::decode(
1.109     albertel  511:      &Apache::lonnet::unescape($title)),'"<>&\'');
1.38      www       512:     my $renametitle=$title;
                    513:     my $foldertitle=$title;
1.122     www       514:     my $orderidx=$Apache::lonratedt::order[$index];
1.109     albertel  515:     if ($title=~ /^(\d+)___&amp;&amp;&amp;___(\w+)___&amp;&amp;&amp;___(\w+)___&amp;&amp;&amp;___(.*)$/	) { 
                    516: 	$foldertitle=&Apache::lontexconvert::msgtexconverted($4);
                    517: 	$renametitle=$4;
                    518: 	$title='<i>'.&Apache::lonlocal::locallocaltime($1).'</i> '.
                    519: 	    &Apache::loncommon::plainname($2,$3).': <br />'.
                    520: 	    $foldertitle;
                    521:     }
1.38      www       522:     $renametitle=~s/\&quot\;/\\\"/g;
1.8       www       523:     my $line='<tr>';
                    524: # Edit commands
1.120     www       525:     my $folderpath;
                    526:     if ($ENV{'form.folderpath'}) {
                    527: 	$folderpath=&Apache::lonnet::escape($ENV{'form.folderpath'});
                    528: 	# $htmlfoldername=&HTML::Entities::encode($ENV{'form.foldername'},'<>&"');
                    529:     }
1.109     albertel  530:     if ($allowed) {
1.123     www       531: 	my $incindex=$index+1;
                    532: 	my $selectbox='';
                    533: 	if ($folder!~/^supplemental/) {
                    534: 	    $selectbox=
1.124     www       535: 		'<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
1.123     www       536: 		'<select name="newpos" onChange="this.form.submit()">';
                    537: 	    for (my $i=1;$i<=$#Apache::lonratedt::order+1;$i++) {
                    538: 		if ($i==$incindex) {
                    539: 		    $selectbox.='<option value="" selected="1">('.$i.')</option>';
                    540: 		} else {
                    541: 		    $selectbox.='<option value="'.$i.'">'.$i.'</option>';
                    542: 		}
                    543: 	    }
                    544: 	    $selectbox.='</select>';
                    545: 	}
1.119     www       546: 	my %lt=&Apache::lonlocal::texthash(
                    547:                 'up' => 'Move Up',
1.109     albertel  548: 		'dw' => 'Move Down',
                    549: 		'rm' => 'Remove',
                    550: 		'rn' => 'Rename');
                    551: 	$line.=(<<END);
1.121     www       552: <form name="entry_$index" action="/adm/coursedocs" method="post">
                    553: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1.122     www       554: <input type="hidden" name="setparms" value="$orderidx" />
1.54      www       555: <td><table border='0' cellspacing='2' cellpadding='0'>
                    556: <tr><td bgcolor="#DDDDDD">
1.115     albertel  557: <a href='/adm/coursedocs?cmd=up_$index&folderpath=$folderpath'>
1.90      www       558: <img src="${iconpath}move_up.gif" alt='$lt{'up'}' border='0' /></a></td></tr>
1.54      www       559: <tr><td bgcolor="#DDDDDD">
1.115     albertel  560: <a href='/adm/coursedocs?cmd=down_$index&folderpath=$folderpath'>
1.90      www       561: <img src="${iconpath}move_down.gif" alt='$lt{'dw'}' border='0' /></a></td></tr>
1.123     www       562: </table></td>
                    563: <td>$selectbox
                    564: </td><td bgcolor="#DDDDDD">
1.115     albertel  565: <a href='javascript:removeres("$folderpath","$index","$renametitle");'>
1.90      www       566: <font size="-2" color="#990000">$lt{'rm'}</font></a>
1.115     albertel  567: <a href='javascript:changename("$folderpath","$index","$renametitle");'>
1.90      www       568: <font size="-2" color="#009900">$lt{'rn'}</font></a></td>
1.8       www       569: END
                    570:     }
1.16      www       571: # Figure out what kind of a resource this is
                    572:     my ($extension)=($url=~/\.(\w+)$/);
                    573:     my $uploaded=($url=~/^\/*uploaded\//);
1.97      albertel  574:     my $icon=&Apache::loncommon::icon($url);
1.17      www       575:     my $isfolder=0;
1.114     albertel  576:     my $folderarg;
1.16      www       577:     if ($uploaded) {
1.135     albertel  578: 	if ($extension eq 'sequence') {
                    579: 	    $icon=$iconpath.'/folder_closed.gif';
                    580: 	    $url=~/$coursenum\/([\/\w]+)\.sequence$/;
                    581: 	    $url='/adm/coursedocs?';
                    582: 	    $folderarg=$1;
                    583: 	    $isfolder=1;
                    584: 	} else {
                    585: 	    &Apache::lonnet::allowuploaded('/adm/coursedoc',$url);
                    586: 	}
1.16      www       587:     }
1.18      www       588:     $url=~s/^http\&colon\;\/\//\/adm\/wrapper\/ext\//;
1.113     albertel  589:     if ((!$isfolder) && ($residx) && ($folder!~/supplemental/)) {
                    590: 	my $symb=&Apache::lonnet::symbclean(
1.50      www       591:           &Apache::lonnet::declutter('uploaded/'.
                    592:            $ENV{'course.'.$ENV{'request.course.id'}.'.domain'}.'/'.
                    593:            $ENV{'course.'.$ENV{'request.course.id'}.'.num'}.'/'.$folder.
                    594:            '.sequence').
                    595:            '___'.$residx.'___'.
1.113     albertel  596: 	   &Apache::lonnet::declutter($url));
                    597: 	(undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
                    598: 	$url=&Apache::lonnet::clutter($url);
1.127     albertel  599: 	if ($url=~/^\/*uploaded\//) {
                    600: 	    $url=~/\.(\w+)$/;
                    601: 	    my $embstyle=&Apache::loncommon::fileembstyle($1);
                    602: 	    if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
                    603: 		$url='/adm/wrapper'.$url;
                    604: 	    } elsif ($embstyle eq 'ssi') {
                    605: 		#do nothing with these
                    606: 	    } elsif ($url!~/\.(sequence|page)$/) {
                    607: 		$url='/adm/coursedocs/showdoc'.$url;
                    608: 	    }
                    609: 	}
1.113     albertel  610: 	$url.=(($url=~/\?/)?'&':'?').'symb='.&Apache::lonnet::escape($symb);
1.50      www       611:     }
1.120     www       612:     my $parameterset='&nbsp;';
1.114     albertel  613:     if ($isfolder) {
                    614: 	my $foldername=&Apache::lonnet::escape($foldertitle);
                    615: 	my $folderpath=$ENV{'form.folderpath'};
                    616: 	if ($folderpath) { $folderpath.='&' };
                    617: 	$folderpath.=$folderarg.'&'.$foldername;
                    618: 	$url.='folderpath='.&Apache::lonnet::escape($folderpath);
1.120     www       619: 	$parameterset=&mt('Randomly Pick: ').
1.122     www       620: 	    '<input type="text" size="4" name="randpick_'.$orderidx.'" value="'.
                    621: 	    (&Apache::lonratedt::getparameter($orderidx,'parameter_randompick'))[0].'" />';
1.114     albertel  622:     }
1.113     albertel  623:     $line.='<td bgcolor="#FFFFBB"><a href="'.$url.'"><img src="'.$icon.
                    624: 	'" border="0"></a></td>'.
1.119     www       625:         "<td bgcolor='#FFFFBB'><a href='$url'>$title</a></td>";
1.120     www       626:     if (($allowed) && ($folder!~/^supplemental/)) {
                    627:  	my %lt=&Apache::lonlocal::texthash(
                    628:  			      'hd' => 'Hidden',
                    629:  			      'ec' => 'URL hidden',
                    630:  			      'sp' => 'Store Parameters');
1.122     www       631: 	my $enctext=
                    632: 	    ((&Apache::lonratedt::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i?' checked="1"':'');
                    633: 	my $hidtext=
                    634: 	    ((&Apache::lonratedt::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i?' checked="1"':'');
1.120     www       635: 	$line.=(<<ENDPARMS);
                    636: <td bgcolor="#BBBBFF"><font size='-2'>
1.122     www       637: <input type="checkbox" name="hidprs_$orderidx" $hidtext/> $lt{'hd'}</td>
1.120     www       638: <td bgcolor="#BBBBFF"><font size='-2'>
1.122     www       639: <input type="checkbox" name="encprs_$orderidx" $enctext/> $lt{'ec'}</td>
1.120     www       640: <td bgcolor="#BBBBFF"><font size="-2">$parameterset</font></td>
                    641: <td bgcolor="#BBBBFF"><font size='-2'>
1.121     www       642: <input type="submit" value="$lt{'sp'}" />
1.120     www       643: </font></td>
                    644: ENDPARMS
1.119     www       645:     }
1.120     www       646:     $line.="</form></tr>";
1.8       www       647:     return $line;
                    648: }
                    649: 
1.27      www       650: # ---------------------------------------------------------------- tie the hash
                    651: 
                    652: sub tiehash {
1.136   ! albertel  653:     my ($mode)=@_;
1.27      www       654:     $hashtied=0;
                    655:     if ($ENV{'request.course.fn'}) {
1.136   ! albertel  656: 	if ($mode eq 'write') {
        !           657: 	    if (tie(%hash,'GDBM_File',$ENV{'request.course.fn'}.".db",
        !           658: 		    &GDBM_WRCREAT(),0640)) {
        !           659:                 $hashtied=2;
        !           660: 	    }
        !           661: 	} else {
        !           662: 	    if (tie(%hash,'GDBM_File',$ENV{'request.course.fn'}.".db",
        !           663: 		    &GDBM_READER(),0640)) {
1.27      www       664:                 $hashtied=1;
1.136   ! albertel  665: 	    }
        !           666: 	}
1.27      www       667:     }    
                    668: }
                    669: 
                    670: sub untiehash {
                    671:     if ($hashtied) { untie %hash; }
                    672:     $hashtied=0;
                    673: }
                    674: 
1.29      www       675: # --------------------------------------------------------------- check on this
                    676: 
                    677: sub checkonthis {
                    678:     my ($r,$url,$level,$title)=@_;
                    679:     $alreadyseen{$url}=1;
                    680:     $r->rflush();
1.41      www       681:     if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
1.108     albertel  682:        $r->print("\n<br />");
1.29      www       683:        for (my $i=0;$i<=$level*5;$i++) {
                    684:            $r->print('&nbsp;');
                    685:        }
                    686:        $r->print('<a href="'.$url.'" target="cat">'.
                    687: 		 ($title?$title:$url).'</a> ');
                    688:        if ($url=~/^\/res\//) {
                    689: 	  my $result=&Apache::lonnet::repcopy(
                    690:                               &Apache::lonnet::filelocation('',$url));
                    691:           if ($result==OK) {
1.87      www       692:              $r->print('<font color="green">'.&mt('ok').'</font>');
1.29      www       693:              $r->rflush();
1.34      www       694:              &Apache::lonnet::countacc($url);
                    695:              $url=~/\.(\w+)$/;
                    696:              if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
                    697: 		 $r->print('<br />');
                    698:                  $r->rflush();
                    699:                  for (my $i=0;$i<=$level*5;$i++) {
                    700:                      $r->print('&nbsp;');
                    701:                  }
1.84      www       702:                  $r->print('- '.&mt('Rendering').': ');
1.69      albertel  703:                  my $oldpath=$ENV{'request.filename'};
                    704:                  $ENV{'request.filename'}=&Apache::lonnet::filelocation('',$url);
1.34      www       705:                  &Apache::lonxml::xmlparse($r,'web',
                    706:                    &Apache::lonnet::getfile(
1.35      albertel  707:                     &Apache::lonnet::filelocation('',$url)));
1.94      www       708: 		 undef($Apache::lonhomework::parsing_a_problem);
1.69      albertel  709: 		 $ENV{'request.filename'}=$oldpath;
1.34      www       710:                  if (($Apache::lonxml::errorcount) ||
                    711:                      ($Apache::lonxml::warningcount)) {
                    712: 		     if ($Apache::lonxml::errorcount) {
1.98      www       713:                         $r->print('<img src="/adm/lonMisc/bomb.gif" /><font color="red"><b>'.
1.87      www       714: 			  $Apache::lonxml::errorcount.' '.
                    715: 				  &mt('error(s)').'</b></font> ');
1.34      www       716:                      }
                    717: 		     if ($Apache::lonxml::warningcount) {
                    718:                         $r->print('<font color="blue">'.
1.84      www       719: 			  $Apache::lonxml::warningcount.' '.
                    720: 				  &mt('warning(s)').'</font>');
1.34      www       721:                      }
                    722:                  } else {
1.87      www       723:                      $r->print('<font color="green">'.&mt('ok').'</font>');
1.34      www       724:                  }
                    725:                  $r->rflush();
                    726:              }
1.29      www       727: 	     my $dependencies=
                    728:                 &Apache::lonnet::metadata($url,'dependencies');
                    729:              foreach (split(/\,/,$dependencies)) {
                    730: 		 if (($_=~/^\/res\//) && (!$alreadyseen{$_})) {
                    731:                     &checkonthis($r,$_,$level+1);
                    732:                  }
                    733:              }
                    734:           } elsif ($result==HTTP_SERVICE_UNAVAILABLE) {
1.84      www       735:              $r->print('<font color="red"><b>'.&mt('connection down').'</b></font>');
1.29      www       736:           } elsif ($result==HTTP_NOT_FOUND) {
1.100     www       737: 	      unless ($url=~/\$/) {
                    738: 		  $r->print('<font color="red"><b>'.&mt('not found').'</b></font>');
                    739: 	      } else {
                    740: 		  $r->print('<font color="yellow"><b>'.&mt('unable to verify variable URL').'</b></font>');
                    741: 	      }
1.29      www       742:           } else {
1.84      www       743:              $r->print('<font color="red"><b>'.&mt('access denied').'</b></font>');
1.29      www       744:           }
                    745:       }
                    746:    }
                    747: }
                    748: 
1.1       www       749: 
1.75      www       750: #
                    751: # -------------------------------------------------------------- Verify Content
                    752: # 
                    753: sub verifycontent {
                    754:    my $r=shift; 
1.26      www       755:    my $loaderror=&Apache::lonnet::overloaderror($r);
                    756:    if ($loaderror) { return $loaderror; }
                    757: 
                    758:    $r->print('<html><head><title>Verify Content</title></head>'.
                    759:               &Apache::loncommon::bodytag('Verify Course Documents'));
1.27      www       760:    $hashtied=0;
1.30      www       761:    undef %alreadyseen;
                    762:    %alreadyseen=();
1.27      www       763:    &tiehash();
                    764:    foreach (keys %hash) {
1.28      www       765:        if (($_=~/^src\_(.+)$/) && (!$alreadyseen{$hash{$_}})) {
1.29      www       766:            &checkonthis($r,$hash{$_},0,$hash{'title_'.$1});
1.27      www       767:        }
                    768:    }
                    769:    &untiehash();
1.108     albertel  770:    $r->print('<h1>'.&mt('Done').'.</h1>'.'<a href="/adm/coursedocs">'.
                    771: 	     &mt('Return to DOCS').'</a>');
1.75      www       772: }
                    773: 
                    774: # -------------------------------------------------------------- Check Versions
                    775: 
                    776: sub checkversions {
                    777:     my $r=shift;
1.89      www       778:     $r->print('<html><head><title>Check Versions</title></head>'.
1.26      www       779:               &Apache::loncommon::bodytag('Check Course Document Versions'));
1.89      www       780:     my $header='';
                    781:     my $startsel='';
                    782:     my $monthsel='';
                    783:     my $weeksel='';
                    784:     my $daysel='';
                    785:     my $allsel='';
                    786:     my %changes=();
                    787:     my $starttime=0;
1.91      www       788:     my $haschanged=0;
1.92      www       789:     my %setversions=&Apache::lonnet::dump('resourceversions',
                    790: 			  $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
                    791: 			  $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
                    792: 
                    793:     $hashtied=0;
                    794:     &tiehash();
                    795:     my %newsetversions=();
1.91      www       796:     if ($ENV{'form.setmostrecent'}) {
                    797: 	$haschanged=1;
1.92      www       798: 	foreach (keys %hash) {
                    799: 	    if ($_=~/^ids\_(\/res\/.+)$/) {
1.93      www       800: 		$newsetversions{$1}='mostrecent';
1.92      www       801: 	    }
                    802: 	}
1.91      www       803:     } elsif ($ENV{'form.setcurrent'}) {
                    804: 	$haschanged=1;
1.92      www       805: 	foreach (keys %hash) {
                    806: 	    if ($_=~/^ids\_(\/res\/.+)$/) {
1.93      www       807: 		my $getvers=&Apache::lonnet::getversion($1);
                    808: 		if ($getvers>0) {
                    809: 		    $newsetversions{$1}=$getvers;
                    810: 		}
1.92      www       811: 	    }
                    812: 	}
1.91      www       813:     } elsif ($ENV{'form.setversions'}) {
                    814: 	$haschanged=1;
1.92      www       815: 	foreach (keys %ENV) {
                    816: 	    if ($_=~/^form\.set_version_(.+)$/) {
                    817: 		my $src=$1;
                    818: 		if (($ENV{$_}) && ($ENV{$_} ne $setversions{$src})) {
                    819: 		    $newsetversions{$src}=$ENV{$_};
                    820: 		}
                    821: 	    }
                    822: 	}
1.91      www       823:     }
                    824:     if ($haschanged) {
1.92      www       825:         if (&Apache::lonnet::put('resourceversions',\%newsetversions,
                    826: 			  $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
                    827: 			  $ENV{'course.'.$ENV{'request.course.id'}.'.num'}) eq 'ok') {		
                    828: 	    $r->print('<h1>'.&mt('Your Version Settings have been Stored').'</h1>');
                    829: 	} else {
                    830: 	    $r->print('<h1><font color="red">'.&mt('An Error Occured while Attempting to Store your Version Settings').'</font></h1>');
                    831: 	}
1.136   ! albertel  832: 	&mark_hash_old();
1.91      www       833:     }
1.136   ! albertel  834:     &changewarning($r,'');
1.89      www       835:     if ($ENV{'form.timerange'} eq 'all') {
                    836: # show all documents
                    837: 	$header=&mt('All Documents in Course');
1.91      www       838: 	$allsel=1;
1.90      www       839: 	foreach (keys %hash) {
                    840: 	    if ($_=~/^ids\_(\/res\/.+)$/) {
                    841: 		my $src=$1;
                    842: 		$changes{$src}=1;
                    843: 	    }
                    844: 	}
1.89      www       845:     } else {
                    846: # show documents which changed
                    847: 	%changes=&Apache::lonnet::dump
                    848: 	 ('versionupdate',$ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
1.30      www       849:                      $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1.89      www       850: 	my $firstkey=(keys %changes)[0];
                    851: 	unless ($firstkey=~/^error\:/) {
                    852: 	    unless ($ENV{'form.timerange'}) {
                    853: 		$ENV{'form.timerange'}=604800;
                    854: 	    }
                    855: 	    my $seltext=&mt('during the last').' '.$ENV{'form.timerange'}.' '
                    856: 		.&mt('seconds');
                    857: 	    if ($ENV{'form.timerange'}==-1) {
                    858: 		$seltext='since start of course';
                    859: 		$startsel='selected';
                    860: 		$ENV{'form.timerange'}=time;
                    861: 	    }
                    862: 	    $starttime=time-$ENV{'form.timerange'};
                    863: 	    if ($ENV{'form.timerange'}==2592000) {
                    864: 		$seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
                    865: 		$monthsel='selected';
                    866: 	    } elsif ($ENV{'form.timerange'}==604800) {
                    867: 		$seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
                    868: 		$weeksel='selected';
                    869: 	    } elsif ($ENV{'form.timerange'}==86400) {
                    870: 		$seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
                    871: 		$daysel='selected';
                    872: 	    }
                    873: 	    $header=&mt('Content changed').' '.$seltext;
                    874: 	} else {
                    875: 	    $header=&mt('No content modifications yet.');
                    876: 	}
                    877:     }
1.92      www       878:     %setversions=&Apache::lonnet::dump('resourceversions',
                    879: 			  $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
                    880: 			  $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
1.89      www       881:     my %lt=&Apache::lonlocal::texthash
1.88      www       882: 	      ('st' => 'Version changes since start of Course',
                    883: 	       'lm' => 'Version changes since last Month',
                    884: 	       'lw' => 'Version changes since last Week',
                    885: 	       'sy' => 'Version changes since Yesterday',
1.91      www       886:                'al' => 'All Resources (possibly large output)',
1.88      www       887: 	       'sd' => 'Display',
1.84      www       888: 	       'fi' => 'File',
                    889: 	       'md' => 'Modification Date',
1.87      www       890:                'mr' => 'Most recently published Version',
                    891: 	       've' => 'Version used in Course',
1.91      www       892:                'vu' => 'Set Version to be used in Course',
                    893: 'sv' => 'Set Versions to be used in Course according to Selections below',
                    894: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
                    895: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
1.84      www       896: 	       'di' => 'Differences');
1.89      www       897:     $r->print(<<ENDHEADERS);
1.31      www       898: <form action="/adm/coursedocs" method="post">
1.91      www       899: <input type="hidden" name="versions" value="1" />
                    900: <input type="submit" name="setmostrecent" value="$lt{'sm'}" />
                    901: <input type="submit" name="setcurrent" value="$lt{'sc'}" /><hr />
1.31      www       902: <select name="timerange">
1.88      www       903: <option value='all' $allsel>$lt{'al'}</option>
1.84      www       904: <option value="-1" $startsel>$lt{'st'}</option>
                    905: <option value="2592000" $monthsel>$lt{'lm'}</option>
                    906: <option value="604800" $weeksel>$lt{'lw'}</option>
                    907: <option value="86400" $daysel>$lt{'sy'}</option>
1.31      www       908: </select>
1.91      www       909: <input type="submit" name="display" value="$lt{'sd'}" />
1.89      www       910: <h3>$header</h3>
1.91      www       911: <input type="submit" name="setversions" value="$lt{'sv'}" />
1.103     matthew   912: <table border="0">
1.31      www       913: ENDHEADERS
1.91      www       914:     foreach (sort keys %changes) {
1.89      www       915: 	if ($changes{$_}>$starttime) {
                    916: 	    my ($root,$extension)=($_=~/^(.*)\.(\w+)$/);
                    917: 	    my $currentversion=&Apache::lonnet::getversion($_);
1.93      www       918: 	    if ($currentversion<0) {
                    919: 		$currentversion=&mt('Could not be determined.');
                    920: 	    }
1.89      www       921: 	    my $linkurl=&Apache::lonnet::clutter($_);
                    922: 	    $r->print(
1.103     matthew   923: 		      '<tr><td colspan="5"><br /><br /><font size="+1"><b>'.
1.91      www       924: 		      &Apache::lonnet::gettitle($linkurl).
1.103     matthew   925:                       '</b></font></td></tr>'.
                    926:                       '<tr><td>&nbsp;&nbsp;&nbsp;</td>'.
                    927:                       '<td colspan="4">'.
                    928:                       '<a href="'.$linkurl.'" target="cat">'.$linkurl.
                    929: 		      '</a></td></tr>'.
                    930:                       '<tr><td></td>'.
                    931:                       '<td title="'.$lt{'md'}.'">'.
1.102     matthew   932: 		      &Apache::lonlocal::locallocaltime(
                    933:                            &Apache::lonnet::metadata($root.'.'.$extension,
                    934:                                                      'lastrevisiondate')
                    935:                                                         ).
1.103     matthew   936:                       '</td>'.
                    937:                       '<td title="'.$lt{'mr'}.'"><nobr>Most Recent: '.
                    938:                       '<font size="+1">'.$currentversion.'</font>'.
                    939:                       '</nobr></td>'.
                    940:                       '<td title="'.$lt{'ve'}.'"><nobr>In Course: '.
                    941:                       '<font size="+1">');
1.87      www       942: # Used in course
1.89      www       943: 	    my $usedversion=$hash{'version_'.$linkurl};
1.93      www       944: 	    if (($usedversion) && ($usedversion ne 'mostrecent')) {
1.89      www       945: 		$r->print($usedversion);
                    946: 	    } else {
                    947: 		$r->print($currentversion);
                    948: 	    }
1.103     matthew   949: 	    $r->print('</font></nobr></td><td title="'.$lt{'vu'}.'">'.
                    950:                       '<nobr>Use: ');
1.87      www       951: # Set version
1.92      www       952: 	    $r->print(&Apache::loncommon::select_form($setversions{$linkurl},
1.89      www       953: 						      'set_version_'.$linkurl,
1.136   ! albertel  954: 						      ('select_form_order' =>
        !           955: 						       ['',1..$currentversion,'mostrecent'],
        !           956: 						       '' => '',
1.93      www       957: 						       'mostrecent' => 'most recent',
1.89      www       958: 						       map {$_,$_} (1..$currentversion))));
1.103     matthew   959: 	    $r->print('</nobr></td></tr><tr><td></td>');
1.89      www       960: 	    my $lastold=1;
                    961: 	    for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
                    962: 		my $url=$root.'.'.$prevvers.'.'.$extension;
                    963: 		if (&Apache::lonnet::metadata($url,'lastrevisiondate')<
                    964: 		    $starttime) {
                    965: 		    $lastold=$prevvers;
                    966: 		}
                    967: 	    }
1.103     matthew   968:             # 
                    969:             # Code to figure out how many version entries should go in
                    970:             # each of the four columns
                    971:             my $entries_per_col = 0;
                    972:             my $num_entries = ($currentversion-$lastold);
                    973:             if ($num_entries % 4 == 0) {
                    974:                 $entries_per_col = $num_entries/4;
                    975:             } else {
                    976:                 $entries_per_col = $num_entries/4 + 1;
                    977:             }
                    978:             my $entries_count = 0;
                    979:             $r->print('<td valign="top"><font size="-2">'); 
                    980:             my $cols_output = 1;
1.32      www       981:             for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
1.89      www       982: 		my $url=$root.'.'.$prevvers.'.'.$extension;
1.103     matthew   983: 		$r->print('<nobr><a href="'.&Apache::lonnet::clutter($url).
1.91      www       984: 			  '">'.&mt('Version').' '.$prevvers.'</a> ('.
1.103     matthew   985: 			  &Apache::lonlocal::locallocaltime(
                    986:                                 &Apache::lonnet::metadata($url,
                    987:                                                           'lastrevisiondate')
                    988:                                                             ).
1.91      www       989: 			  ')');
1.89      www       990: 		if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
1.33      www       991:                     $r->print(' <a href="/adm/diff?filename='.
1.89      www       992: 			      &Apache::lonnet::clutter($root.'.'.$extension).
                    993: 			      '&versionone='.$prevvers.
                    994: 			      '">'.&mt('Diffs').'</a>');
                    995: 		}
1.103     matthew   996: 		$r->print('</nobr><br />');
                    997:                 if (++$entries_count % $entries_per_col == 0) {
                    998:                     $r->print('</font></td>');
                    999:                     if ($cols_output != 4) {
                   1000:                         $r->print('<td valign="top"><font size="-2">');
                   1001:                         $cols_output++;
                   1002:                     }
                   1003:                 }
1.89      www      1004: 	    }
1.103     matthew  1005:             while($cols_output++ < 4) {
                   1006:                 $r->print('</font></td><td><font>')
                   1007:             }
                   1008: 	    $r->print('</font></td></tr>'."\n");
1.89      www      1009: 	}
                   1010:     }
1.92      www      1011:     $r->print('</table></form>');
1.89      www      1012:     $r->print('<h1>'.&mt('Done').'.</h1>');
                   1013: 
                   1014:     &untiehash();
1.75      www      1015: }
                   1016: 
1.136   ! albertel 1017: sub mark_hash_old {
        !          1018:     my $retie_hash=0;
        !          1019:     if ($hashtied) {
        !          1020: 	$retie_hash=1;
        !          1021: 	&untiehash();
        !          1022:     }
        !          1023:     &tiehash('write');
        !          1024:     $hash{'old'}=1;
        !          1025:     &untiehash();
        !          1026:     if ($retie_hash) { &tiehash(); }
        !          1027: }
        !          1028: 
        !          1029: sub is_hash_old {
        !          1030:     my $untie_hash=0;
        !          1031:     if (!$hashtied) {
        !          1032: 	$untie_hash=1;
        !          1033: 	&tiehash();
        !          1034:     }
        !          1035:     my $return=$hash{'old'};
        !          1036:     if ($untie_hash) { &untiehash(); }
        !          1037:     return $return;
        !          1038: }
        !          1039: 
1.91      www      1040: sub changewarning {
                   1041:     my ($r,$postexec)=@_;
1.136   ! albertel 1042:     if (!&is_hash_old()) { return; }
1.91      www      1043:     $r->print(
                   1044: '<script>function reinit(tf) { tf.submit();'.$postexec.' }</script>'. 
                   1045: '<form method="post" action="/adm/roles" target="loncapaclient">'.
1.117     albertel 1046: '<input type="hidden" name="orgurl" value="/adm/coursedocs?folderpath='.
                   1047: &Apache::lonnet::escape($ENV{'form.folderpath'}).
                   1048: '" /><input type="hidden" name="selectrole" value="1" /><h3><font color="red">'.
1.91      www      1049: &mt('Changes will become active for your current session after').
                   1050: ' <input type="hidden" name="'.
                   1051: $ENV{'request.role'}.'" value="1" /><input type="button" value="'.
                   1052: &mt('re-initializing course').'" onClick="reinit(this.form)"/>'.&mt(', or the next time you log in.').
                   1053: $help{'Caching'}.'</font></h3></form>');
                   1054: }
                   1055: 
1.75      www      1056: # ================================================================ Main Handler
                   1057: sub handler {
                   1058:     my $r = shift;
1.82      www      1059:     &Apache::loncommon::content_type($r,'text/html');
1.75      www      1060:     $r->send_http_header;
                   1061:     return OK if $r->header_only;
                   1062: 
                   1063: # --------------------------------------------- Initialize help topics for this
                   1064:   foreach ('Adding_Course_Doc','Main_Course_Documents',
                   1065:            'Adding_External_Resource','Navigate_Content',
                   1066:            'Adding_Folders','Docs_Overview', 'Load_Map',
                   1067:            'Supplemental', 'Score_Upload_Form',
1.130     www      1068:            'Importing_LON-CAPA_Resource','Uploading_From_Harddrive',
                   1069: 	   'Check_Resource_Versions','Verify_Content') {
1.75      www      1070:       $help{$_}=&Apache::loncommon::help_open_topic('Docs_'.$_);
                   1071:   }
                   1072:     # Composite help files
                   1073:     $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
                   1074: 		    'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
                   1075:     $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
                   1076: 		    'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
1.86      albertel 1077:     $help{'Simple Problem'} = &Apache::loncommon::help_open_topic(
                   1078: 		    'Option_Response_Simple');
1.75      www      1079:     $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
                   1080: 		    'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
                   1081:     $help{'My Personal Info'} = &Apache::loncommon::help_open_topic(
                   1082: 		  'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
                   1083:     $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
                   1084:  
                   1085:   if ($ENV{'form.verify'}) {
                   1086:       &verifycontent($r);
                   1087:   } elsif ($ENV{'form.versions'}) {
                   1088:       &checkversions($r);
                   1089:   } elsif ($ENV{'form.dumpcourse'}) {
                   1090:       &dumpcourse($r);
1.26      www      1091:   } else {
1.7       www      1092: # is this a standard course?
                   1093: 
                   1094:     my $standard=($ENV{'request.course.uri'}=~/^\/uploaded\//);
1.15      www      1095:     my $forcestandard;
                   1096:     my $forcesupplement;
                   1097:     my $script='';
                   1098:     my $allowed;
                   1099:     my $events='';
1.19      www      1100:     my $showdoc=0;
1.15      www      1101:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.114     albertel 1102: 					    ['folderpath']);
                   1103:     if ($ENV{'form.folderpath'}) {
                   1104: 	my (@folderpath)=split('&',$ENV{'form.folderpath'});
                   1105: 	$ENV{'form.foldername'}=&Apache::lonnet::unescape(pop(@folderpath));
                   1106: 	$ENV{'form.folder'}=pop(@folderpath);
1.116     albertel 1107:     } 
1.21      www      1108:     if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
1.127     albertel 1109:        $showdoc='/'.$1;
1.21      www      1110:     }
                   1111:     unless ($showdoc) { # got called from remote
1.15      www      1112:        $forcestandard=($ENV{'form.folder'}=~/^default_/);
                   1113:        $forcesupplement=($ENV{'form.folder'}=~/^supplemental_/);
1.7       www      1114: 
1.4       www      1115: # does this user have privileges to post, etc?
1.77      www      1116:        $allowed=&Apache::lonnet::allowed('mdc',$ENV{'request.course.id'});
1.15      www      1117:        if ($allowed) { 
                   1118:          &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
                   1119:          $script=&Apache::lonratedt::editscript('simple'); 
                   1120:        }
                   1121:     } else { # got called in sequence from course
                   1122:        $allowed=0;
1.49      www      1123:        $script='</script>'.&Apache::lonmenu::registerurl(1,undef).'<script>';
                   1124:        $events='onLoad="'.&Apache::lonmenu::loadevents.
                   1125:            '" onUnload="'.&Apache::lonmenu::unloadevents.'"';
1.3       www      1126:     }
1.4       www      1127: 
                   1128: # get course data
                   1129:     my $coursenum=$ENV{'course.'.$ENV{'request.course.id'}.'.num'};
                   1130:     my $coursedom=$ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
                   1131: 
1.14      www      1132: # get personal data
                   1133:  
                   1134:     my $uname=$ENV{'user.name'};
                   1135:     my $udom=$ENV{'user.domain'};
                   1136:     my $plainname=&Apache::lonnet::escape(
                   1137:                      &Apache::loncommon::plainname($uname,$udom));
                   1138: 
1.8       www      1139: # graphics settings
1.4       www      1140: 
1.8       www      1141:     $iconpath = $r->dir_config('lonIconsURL') . "/";
                   1142: 
1.22      www      1143:     my $now=time;
1.64      www      1144: 
1.4       www      1145: # print screen
1.1       www      1146:     $r->print(<<ENDDOCUMENT);
                   1147: <html>
                   1148: <head>
                   1149: <title>The LearningOnline Network with CAPA</title>
1.16      www      1150: <script>
                   1151: $script
1.20      www      1152: </script>
1.19      www      1153: ENDDOCUMENT
                   1154:    if ($allowed) {
                   1155:     $r->print(<<ENDNEWSCRIPT);
1.20      www      1156: <script>
1.16      www      1157: function makenewfolder(targetform,folderseq) {
                   1158:     var foldername=prompt('Name of New Folder','New Folder');
                   1159:     if (foldername) {
                   1160: 	targetform.importdetail.value=foldername+"="+folderseq;
                   1161:         targetform.submit();
                   1162:     }
                   1163: }
                   1164: 
1.18      www      1165: function makenewext(targetname) {
                   1166:     this.document.forms.extimport.useform.value=targetname;
                   1167:     window.open('/adm/rat/extpickframe.html');
                   1168: }
                   1169: 
1.62      www      1170: function makeexamupload() {
                   1171:    var title=prompt('Listed Title for the Uploaded Score');
                   1172:    if (title) { 
                   1173:     this.document.forms.newexamupload.importdetail.value=
                   1174: 	title+'=/res/lib/templates/examupload.problem';
                   1175:     this.document.forms.newexamupload.submit();
                   1176:    }
                   1177: }
                   1178: 
1.22      www      1179: function makesmppage() {
1.38      www      1180:    var title=prompt('Listed Title for the Page');
                   1181:    if (title) { 
1.22      www      1182:     this.document.forms.newsmppg.importdetail.value=
                   1183: 	title+'=/adm/$udom/$uname/$now/smppg';
                   1184:     this.document.forms.newsmppg.submit();
1.38      www      1185:    }
1.22      www      1186: }
                   1187: 
1.55      www      1188: function makesmpproblem() {
                   1189:    var title=prompt('Listed Title for the Problem');
                   1190:    if (title) { 
                   1191:     this.document.forms.newsmpproblem.importdetail.value=
1.63      www      1192: 	title+'=/res/lib/templates/simpleproblem.problem';
1.55      www      1193:     this.document.forms.newsmpproblem.submit();
                   1194:    }
                   1195: }
                   1196: 
1.22      www      1197: function makebulboard() {
1.38      www      1198:    var title=prompt('Listed Title for the Bulletin Board');
                   1199:    if (title) {
1.22      www      1200:     this.document.forms.newbul.importdetail.value=
                   1201: 	title+'=/adm/$udom/$uname/$now/bulletinboard';
                   1202:     this.document.forms.newbul.submit();
1.38      www      1203:    }
1.22      www      1204: }
                   1205: 
1.101     www      1206: function makeabout() {
                   1207:    var user=prompt("Enter user\@domain for User's 'About Me' Page");
                   1208:    if (user) {
                   1209:        var comp=new Array();
                   1210:        comp=user.split('\@');
                   1211:        if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
                   1212: 	   if ((comp[0]) && (comp[1])) {
                   1213: 	       this.document.forms.newaboutsomeone.importdetail.value=
                   1214: 		   'About '+user+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
                   1215: 	       this.document.forms.newaboutsomeone.submit();
                   1216: 	   }
                   1217:        }
                   1218:    }
                   1219: }
                   1220: 
1.110     raeburn  1221: function makeims() {
                   1222:     var caller = document.forms.ims.folder.value
                   1223:     var newlocation = "/adm/imsimportdocs?folder="+caller+"&phase=one"
                   1224:     newWindow = window.open("","IMSimport","HEIGHT=700,WIDTH=750,scrollbars=yes")
                   1225:     newWindow.location.href = newlocation
                   1226: }
                   1227: 
                   1228: 
1.18      www      1229: function finishpick() {
                   1230:     var title=this.document.forms.extimport.title.value;
                   1231:     var url=this.document.forms.extimport.url.value;
                   1232:     var form=this.document.forms.extimport.useform.value;
                   1233:     eval
                   1234:      ('this.document.forms.'+form+'.importdetail.value="'+title+'='+url+
                   1235:     '";this.document.forms.'+form+'.submit();');
1.16      www      1236: }
1.36      www      1237: 
1.115     albertel 1238: function changename(folderpath,index,oldtitle) {
1.36      www      1239:     var title=prompt('New Title',oldtitle);
                   1240:     if (title) {
                   1241: 	this.document.forms.renameform.title.value=title;
                   1242: 	this.document.forms.renameform.cmd.value='rename_'+index;
1.115     albertel 1243: 	this.document.forms.renameform.folderpath.value=folderpath;
1.54      www      1244:         this.document.forms.renameform.submit();
                   1245:     }
                   1246: }
                   1247: 
1.115     albertel 1248: function removeres(folderpath,index,oldtitle) {
1.106     www      1249:     if (confirm('Remove "'+oldtitle+'"?')) {
1.54      www      1250: 	this.document.forms.renameform.cmd.value='del_'+index;
1.115     albertel 1251: 	this.document.forms.renameform.folderpath.value=folderpath;
1.36      www      1252:         this.document.forms.renameform.submit();
                   1253:     }
                   1254: }
1.121     www      1255: 
1.16      www      1256: </script>
1.42      www      1257: 
                   1258: ENDNEWSCRIPT
                   1259:   }
                   1260: # -------------------------------------------------------------------- Body tag
                   1261:   $r->print('</head>'.
1.72      www      1262:             &Apache::loncommon::bodytag('Course Documents','',$events,
1.99      www      1263: 					'','',$showdoc).
1.134     albertel 1264: 	    &Apache::loncommon::help_open_menu('','','','',273,'RAT'));
1.42      www      1265:   unless ($showdoc) {
1.81      www      1266: # -----------------------------------------------------------------------------
                   1267:        my %lt=&Apache::lonlocal::texthash(
                   1268:                 'uplm' => 'Upload a new main course document',
                   1269:                 'upls' => 'Upload a new supplemental course document',
                   1270:                 'impp' => 'Import a published document',
                   1271:                 'spec' => 'Special documents',
                   1272:                 'upld' => 'Upload Document',
                   1273:                 'srch' => 'Search',
                   1274:                 'impo' => 'Import',
                   1275:                 'selm' => 'Select Map',
                   1276:                 'load' => 'Load Map',
                   1277:                 'newf' => 'New Folder',
                   1278:                 'extr' => 'External Resource',
                   1279:                 'syll' => 'Syllabus',
                   1280:                 'navc' => 'Navigate Contents',
                   1281:                 'sipa' => 'Simple Page',
                   1282:                 'sipr' => 'Simple Problem',
                   1283:                 'scuf' => 'Score Upload Form',
                   1284:                 'bull' => 'Bulletin Board',
1.96      sakharuk 1285:                 'mypi' => 'My Personal Info',
1.101     www      1286: 		'abou' => 'About User',
1.110     raeburn  1287:                 'imsf' => 'Import IMS package',
1.96      sakharuk 1288:                 'file' =>  'File',
                   1289:                 'title' => 'Title',
                   1290:                 'comment' => 'Comment' 
1.81      www      1291: 					  );
                   1292: # -----------------------------------------------------------------------------
1.42      www      1293:     if ($allowed) {
1.74      www      1294:        my $dumpbut=&dumpbutton();
1.88      www      1295:        my %lt=&Apache::lonlocal::texthash(
                   1296: 					 'vc' => 'Verify Content',
                   1297: 					 'cv' => 'Check/Set Resource Versions',
                   1298: 					  );
1.118     albertel 1299: 
                   1300:        my $folderpath=$ENV{'form.folderpath'};
                   1301:        if (!$folderpath) {
                   1302: 	   if ($ENV{'form.folder'} eq '' ||
                   1303: 	       $ENV{'form.folder'} eq 'supplemental') {
                   1304: 	       $folderpath='default&'.
                   1305: 		   &Apache::lonnet::escape(&mt('Main Course Documents'));
                   1306: 	   }
                   1307:        }
1.42      www      1308:        $r->print(<<ENDCOURSEVERIFY);
1.36      www      1309: <form name="renameform" method="post" action="/adm/coursedocs">
                   1310: <input type="hidden" name="title" />
                   1311: <input type="hidden" name="cmd" />
1.115     albertel 1312: <input type="hidden" name="folderpath" />
1.36      www      1313: </form>
1.39      www      1314: <form name="simpleedit" method="post" action="/adm/coursedocs">
                   1315: <input type=hidden name="importdetail" value="">
1.118     albertel 1316: <input type="hidden" name="folderpath" value="$folderpath" />
1.39      www      1317: </form>
1.26      www      1318: <form action="/adm/coursedocs" method="post" name="courseverify">
1.74      www      1319: <table bgcolor="#AAAAAA" width="100%" cellspacing="4" cellpadding="4">
                   1320: <tr><td bgcolor="#DDDDCC">
1.130     www      1321: <input type="submit" name="verify" value="$lt{'vc'}" />$help{'Verify_Content'}
1.74      www      1322: </td><td bgcolor="#DDDDCC">
1.130     www      1323:     <input type="submit" name="versions" value="$lt{'cv'}" />$help{'Check_Resource_Versions'}
1.74      www      1324: $dumpbut
                   1325: </td></tr></table>
1.25      www      1326: </form>
                   1327: ENDCOURSEVERIFY
1.74      www      1328:        $r->print(&Apache::loncommon::help_open_topic('Docs_Adding_Course_Doc',
1.96      sakharuk 1329: 		     &mt('Editing the Table of Contents for your Course')));
1.25      www      1330:     }
1.17      www      1331: # --------------------------------------------------------- Standard documents
1.43      www      1332:     $r->print('<table border=2 cellspacing=4 cellpadding=4>');
1.7       www      1333:     if (($standard) && ($allowed) && (!$forcesupplement)) {
1.116     albertel 1334: 	$r->print('<tr><td bgcolor="#BBBBBB">');
                   1335: #  '<h2>'.&mt('Main Course Documents').
                   1336: #  ($allowed?' '.$help{'Main_Course_Documents'}:'').'</h2>');
1.7       www      1337:        my $folder=$ENV{'form.folder'};
1.117     albertel 1338:        if ($folder eq '' || $folder eq 'supplemental') {
1.112     raeburn  1339:            $folder='default';
1.116     albertel 1340: 	   $ENV{'form.folderpath'}='default&'.&Apache::lonnet::escape(&mt('Main Course Documents'));
1.112     raeburn  1341:        }
1.51      www      1342:        my $postexec='';
                   1343:        if ($folder eq 'default') {
                   1344: 	   $r->print('<script>this.window.name="loncapaclient";</script>');
                   1345:        } else {
1.117     albertel 1346:            #$postexec='self.close();';
1.51      www      1347:        }
1.40      www      1348:        $hadchanges=0;
1.7       www      1349:        &editor($r,$coursenum,$coursedom,$folder,$allowed);
1.40      www      1350:        if ($hadchanges) {
1.136   ! albertel 1351: 	   &mark_hash_old()
1.40      www      1352:        }
1.136   ! albertel 1353:        &changewarning($r,$postexec);
1.16      www      1354:        my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_'.time.
                   1355:                      '.sequence';
1.8       www      1356:        $r->print(<<ENDFORM);
1.43      www      1357: <table cellspacing=4 cellpadding=4><tr>
1.81      www      1358: <th bgcolor="#DDDDDD">$lt{'uplm'}</th>
                   1359: <th bgcolor="#DDDDDD">$lt{'impp'}</th>
                   1360: <th bgcolor="#DDDDDD">$lt{'spec'}</th>
1.11      www      1361: </tr>
1.16      www      1362: <tr><td bgcolor="#DDDDDD">
1.96      sakharuk 1363: $lt{'file'}:<br />
1.10      www      1364: <form action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.59      www      1365: <input type="file" name="uploaddoc" size="40">
1.8       www      1366: <br />
1.96      sakharuk 1367: $lt{'title'}:<br />
1.11      www      1368: <input type="text" size="50" name="comment">
1.115     albertel 1369: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1.10      www      1370: <input type="hidden" name="cmd" value="upload_default">
1.129     albertel 1371: <nobr>
1.81      www      1372: <input type="submit" value="$lt{'upld'}">
1.60      albertel 1373:  $help{'Uploading_From_Harddrive'}
1.58      albertel 1374: </nobr>
1.60      albertel 1375: </form>
1.11      www      1376: </td>
1.16      www      1377: <td bgcolor="#DDDDDD">
1.39      www      1378: <form action="/adm/coursedocs" method="post" name="simpleeditdefault">
1.115     albertel 1379: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
                   1380: <input type=button onClick="javascript:groupsearch()" value="$lt{'srch'}">
1.58      albertel 1381: <nobr>
1.115     albertel 1382: <input type=button onClick="javascript:groupimport();" value="$lt{'impo'}">
1.58      albertel 1383: $help{'Importing_LON-CAPA_Resource'}
                   1384: </nobr>
1.59      www      1385: <p>
                   1386: <hr />
1.68      bowersj2 1387: <input type="text" size="20" name="importmap"><br />
                   1388: <nobr><input type=button 
1.52      www      1389: onClick="javascript:openbrowser('simpleeditdefault','importmap','sequence,page','')"
1.81      www      1390: value="$lt{'selm'}"> <input type="submit" name="loadmap" value="$lt{'load'}">
1.68      bowersj2 1391: $help{'Load_Map'}</nobr>
1.59      www      1392: </p>
1.52      www      1393: </form>
1.16      www      1394: </td><td bgcolor="#DDDDDD">
1.11      www      1395: <form action="/adm/coursedocs" method="post" name="newfolder">
1.115     albertel 1396: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1.13      www      1397: <input type=hidden name="importdetail" value="">
1.58      albertel 1398: <nobr>
1.16      www      1399: <input name="newfolder" type="button"
                   1400: onClick="javascript:makenewfolder(this.form,'$folderseq');"
1.81      www      1401: value="$lt{'newf'}" />$help{'Adding_Folders'}
1.58      albertel 1402: </nobr>
1.11      www      1403: </form>
                   1404: <form action="/adm/coursedocs" method="post" name="newext">
1.115     albertel 1405: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1.13      www      1406: <input type=hidden name="importdetail" value="">
1.58      albertel 1407: <nobr>
1.18      www      1408: <input name="newext" type="button" onClick="javascript:makenewext('newext');"
1.81      www      1409: value="$lt{'extr'}" /> $help{'Adding_External_Resource'}
1.58      albertel 1410: </nobr>
1.11      www      1411: </form>
                   1412: <form action="/adm/coursedocs" method="post" name="newsyl">
1.115     albertel 1413: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1.14      www      1414: <input type=hidden name="importdetail" 
                   1415: value="Syllabus=/public/$coursedom/$coursenum/syllabus">
1.58      albertel 1416: <nobr>
1.81      www      1417: <input name="newsyl" type="submit" value="$lt{'syll'}" /> 
1.65      bowersj2 1418:  $help{'Syllabus'}
1.58      albertel 1419: </nobr>
                   1420: </form>
1.17      www      1421: <form action="/adm/coursedocs" method="post" name="newnav">
1.115     albertel 1422: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1.15      www      1423: <input type=hidden name="importdetail" 
                   1424: value="Navigate Content=/adm/navmaps">
1.58      albertel 1425: <nobr>
1.81      www      1426: <input name="newnav" type="submit" value="$lt{'navc'}" />
1.47      www      1427: $help{'Navigate_Content'}
1.58      albertel 1428: </nobr>
1.22      www      1429: </form>
                   1430: <form action="/adm/coursedocs" method="post" name="newsmppg">
1.115     albertel 1431: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1.22      www      1432: <input type=hidden name="importdetail" value="">
1.58      albertel 1433: <nobr>
1.81      www      1434: <input name="newsmppg" type="button" value="$lt{'sipa'}"
1.65      bowersj2 1435: onClick="javascript:makesmppage();" /> $help{'Simple Page'}
1.58      albertel 1436: </nobr>
1.55      www      1437: </form>
                   1438: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
1.115     albertel 1439: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1.55      www      1440: <input type=hidden name="importdetail" value="">
1.58      albertel 1441: <nobr>
1.81      www      1442: <input name="newsmpproblem" type="button" value="$lt{'sipr'}"
1.65      bowersj2 1443: onClick="javascript:makesmpproblem();" />$help{'Simple Problem'}
1.62      www      1444: </nobr>
                   1445: </form>
                   1446: <form action="/adm/coursedocs" method="post" name="newexamupload">
1.115     albertel 1447: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1.62      www      1448: <input type=hidden name="importdetail" value="">
                   1449: <nobr>
1.81      www      1450: <input name="newexamupload" type="button" value="$lt{'scuf'}"
1.62      www      1451: onClick="javascript:makeexamupload();" />
1.66      bowersj2 1452: $help{'Score_Upload_Form'}
1.58      albertel 1453: </nobr>
1.22      www      1454: </form>
                   1455: <form action="/adm/coursedocs" method="post" name="newbul">
1.115     albertel 1456: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1.22      www      1457: <input type=hidden name="importdetail" value="">
1.58      albertel 1458: <nobr>
1.81      www      1459: <input name="newbulletin" type="button" value="$lt{'bull'}"
1.22      www      1460: onClick="javascript:makebulboard();" />
1.65      bowersj2 1461: $help{'Bulletin Board'}
1.58      albertel 1462: </nobr>
                   1463: </form>
1.12      www      1464: <form action="/adm/coursedocs" method="post" name="newaboutme">
1.115     albertel 1465: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1.14      www      1466: <input type=hidden name="importdetail" 
                   1467: value="$plainname=/adm/$udom/$uname/aboutme">
1.58      albertel 1468: <nobr>
1.81      www      1469: <input name="newaboutme" type="submit" value="$lt{'mypi'}" />
1.65      bowersj2 1470: $help{'My Personal Info'}
1.101     www      1471: </nobr>
                   1472: </form>
                   1473: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
1.115     albertel 1474: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1.101     www      1475: <input type=hidden name="importdetail" value="">
                   1476: <nobr>
                   1477: <input name="newaboutsomeone" type="button" value="$lt{'abou'}" 
                   1478: onClick="javascript:makeabout();" />
1.110     raeburn  1479: </nobr>
                   1480: </form>
                   1481: <form action="/adm/imsimportdocs" method="post" name="ims">
1.118     albertel 1482: <input type="hidden" name="folder" value="$folder" />
1.110     raeburn  1483: <input name="imsimport" type="button" value="$lt{'imsf'}" onClick="javascript:makeims();" />
1.58      albertel 1484: </nobr>
                   1485: </form>
1.11      www      1486: </td></tr>
                   1487: </table>
1.8       www      1488: ENDFORM
1.24      www      1489:        $r->print('</td></tr>');
1.7       www      1490:     }
                   1491: # ----------------------------------------------------- Supplemental documents
                   1492:     if (!$forcestandard) {
1.116     albertel 1493:        $r->print('<tr><td bgcolor="#BBBBBB">');
                   1494: # '<h2>'.&mt('Supplemental Course Documents').
                   1495: #  ($allowed?' '.$help{'Supplemental'}:'').'</h2>');
1.7       www      1496:        my $folder=$ENV{'form.folder'};
1.117     albertel 1497:        unless ($folder=~/^supplemental/) {
1.116     albertel 1498: 	   $folder='supplemental';
1.117     albertel 1499:        }
                   1500:        if ($folder =~ /^supplemental$/ &&
                   1501: 	   $ENV{'form.folderpath'} =~ /^default\&/) {
                   1502: 	   $ENV{'form.folderpath'}='supplemental&'.
                   1503: 	       &Apache::lonnet::escape(&mt('Supplemental Course Documents'));
1.116     albertel 1504:        }
1.7       www      1505:        &editor($r,$coursenum,$coursedom,$folder,$allowed);
1.8       www      1506:        if ($allowed) {
1.17      www      1507:        my $folderseq=
                   1508:                   '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_'.time.
                   1509:                      '.sequence';
                   1510: 
1.8       www      1511:           $r->print(<<ENDSUPFORM);
1.43      www      1512: <table cellspacing=4 cellpadding=4><tr>
1.81      www      1513: <th bgcolor="#DDDDDD">$lt{'upls'}</th>
                   1514: <th bgcolor="#DDDDDD">$lt{'spec'}</th>
1.17      www      1515: </tr>
                   1516: <tr><td bgcolor="#DDDDDD">
1.10      www      1517: <form action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.59      www      1518: <input type="file" name="uploaddoc" size="40">
1.96      sakharuk 1519: <br />$lt{'comment'}:<br />
1.4       www      1520: <textarea cols=50 rows=4 name='comment'>
                   1521: </textarea>
1.115     albertel 1522: <br />
                   1523: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1.10      www      1524: <input type="hidden" name="cmd" value="upload_supplemental">
1.58      albertel 1525: <nobr>
1.81      www      1526: <input type="submit" value="$lt{'upld'}">
1.58      albertel 1527:  $help{'Uploading_From_Harddrive'}
                   1528: </nobr>
                   1529: </form>
1.17      www      1530: </td>
                   1531: <td bgcolor="#DDDDDD">
1.18      www      1532: <form action="/adm/coursedocs" method="post" name="supnewfolder">
1.115     albertel 1533: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1.17      www      1534: <input type=hidden name="importdetail" value="">
1.58      albertel 1535: <nobr>
1.17      www      1536: <input name="newfolder" type="button"
                   1537: onClick="javascript:makenewfolder(this.form,'$folderseq');"
1.81      www      1538: value="$lt{'newf'}" /> $help{'Adding_Folders'}
1.58      albertel 1539: </nobr>
1.17      www      1540: </form>
1.18      www      1541: <form action="/adm/coursedocs" method="post" name="supnewext">
1.115     albertel 1542: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1.17      www      1543: <input type=hidden name="importdetail" value="">
1.58      albertel 1544: <nobr>
1.18      www      1545: <input name="newext" type="button" 
                   1546: onClick="javascript:makenewext('supnewext');"
1.81      www      1547: value="$lt{'extr'}" /> $help{'Adding_External_Resource'}
1.58      albertel 1548: </nobr>
1.17      www      1549: </form>
1.18      www      1550: <form action="/adm/coursedocs" method="post" name="supnewsyl">
1.115     albertel 1551: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1.17      www      1552: <input type=hidden name="importdetail" 
                   1553: value="Syllabus=/public/$coursedom/$coursenum/syllabus">
1.58      albertel 1554: <nobr>
1.81      www      1555: <input name="newsyl" type="submit" value="$lt{'syll'}" />
1.65      bowersj2 1556: $help{'Syllabus'}
1.58      albertel 1557: </nobr>
                   1558: </form>
1.18      www      1559: <form action="/adm/coursedocs" method="post" name="subnewaboutme">
1.115     albertel 1560: <input type="hidden" name="folderpath" value="$ENV{'form.folderpath'}" />
1.17      www      1561: <input type=hidden name="importdetail" 
                   1562: value="$plainname=/adm/$udom/$uname/aboutme">
1.58      albertel 1563: <nobr>
1.81      www      1564: <input name="newaboutme" type="submit" value="$lt{'mypi'}" />
1.65      bowersj2 1565: $help{'My Personal Info'}
1.58      albertel 1566: </nobr>
                   1567: </form>
1.17      www      1568: </td></tr>
1.24      www      1569: </table></td></tr>
1.8       www      1570: ENDSUPFORM
                   1571:        }
1.7       www      1572:     }
1.18      www      1573:     if ($allowed) {
                   1574: 	$r->print('<form name="extimport"><input type="hidden" name="title"><input type="hidden" name="url"><input type="hidden" name="useform"></form>');
                   1575:     }
1.24      www      1576:     $r->print('</table>');
1.19      www      1577:   } else {
                   1578: # -------------------------------------------------------- This is showdoc mode
1.81      www      1579:       $r->print("<h1>".&mt('Uploaded Document').'</h1><p>'.
                   1580: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><p><table>".
                   1581:          &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table></p>');
1.19      www      1582:   }
1.26      www      1583:  }
1.95      www      1584:  $r->print('</body></html>');
1.26      www      1585:  return OK;
1.1       www      1586: } 
                   1587: 
                   1588: 1;
                   1589: __END__

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>