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

1.1       www         1: # The LearningOnline Network
1.2       www         2: # Documents
1.1       www         3: #
1.232   ! www         4: # $Id: londocs.pm,v 1.231 2006/06/08 16:00:54 www 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.158     raeburn    33: use Apache::imsexport;
1.4       www        34: use Apache::lonnet;
                     35: use Apache::loncommon;
1.7       www        36: use Apache::lonratedt;
                     37: use Apache::lonratsrv;
1.15      www        38: use Apache::lonxml;
1.74      www        39: use Apache::loncreatecourse;
1.138     raeburn    40: use Apache::lonnavmaps;
1.38      www        41: use HTML::Entities;
1.27      www        42: use GDBM_File;
1.81      www        43: use Apache::lonlocal;
1.143     raeburn    44: use Cwd;
1.228     www        45: use lib '/home/httpd/lib/perl/';
                     46: use LONCAPA;
1.7       www        47: 
1.8       www        48: my $iconpath;
1.7       www        49: 
1.27      www        50: my %hash;
                     51: 
                     52: my $hashtied;
1.29      www        53: my %alreadyseen=();
1.27      www        54: 
1.40      www        55: my $hadchanges;
                     56: 
1.47      www        57: # Available help topics
                     58: 
                     59: my %help=();
                     60: 
1.7       www        61: # Mapread read maps into lonratedt::global arrays 
1.10      www        62: # @order and @resources, determines status
1.7       www        63: # sets @order - pointer to resources in right order
                     64: # sets @resources - array with the resources with correct idx
                     65: #
                     66: 
                     67: sub mapread {
                     68:     my ($coursenum,$coursedom,$map)=@_;
                     69:     return
                     70:       &Apache::lonratedt::mapread('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
                     71:                                 $map);
                     72: }
                     73: 
                     74: sub storemap {
                     75:     my ($coursenum,$coursedom,$map)=@_;
1.104     albertel   76:     my ($outtext,$errtext)=
1.7       www        77:       &Apache::lonratedt::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
1.15      www        78:                                 $map,1);
1.104     albertel   79:     if ($errtext) { return ($errtext,2); }
                     80:     
                     81:     $hadchanges=1;
                     82:     return ($errtext,0);
1.7       www        83: }
                     84: 
1.74      www        85: # ----------------------------------------- Return hash with valid author names
                     86: 
                     87: sub authorhosts {
                     88:     my %outhash=();
                     89:     my $home=0;
                     90:     my $other=0;
1.174     albertel   91:     foreach (keys %env) {
1.74      www        92: 	if ($_=~/^user\.role\.(au|ca)\.(.+)$/) {
                     93: 	    my $role=$1;
                     94: 	    my $realm=$2;
1.174     albertel   95: 	    my ($start,$end)=split(/\./,$env{$_});
1.74      www        96: 	    if (($start) && ($start>time)) { next; }
                     97: 	    if (($end) && (time>$end)) { next; }
                     98: 	    my $ca; my $cd;
                     99: 	    if ($1 eq 'au') {
1.174     albertel  100: 		$ca=$env{'user.name'};
                    101: 		$cd=$env{'user.domain'};
1.74      www       102: 	    } else {
                    103: 		($cd,$ca)=($realm=~/^\/(\w+)\/(\w+)$/);
                    104: 	    }
1.107     albertel  105: 	    my $allowed=0;
                    106: 	    my $myhome=&Apache::lonnet::homeserver($ca,$cd);
                    107: 	    my @ids=&Apache::lonnet::current_machine_ids();
                    108: 	    foreach my $id (@ids) { if ($id eq $myhome) { $allowed=1; } }
                    109: 	    if ($allowed) {
1.74      www       110: 		$home++;
                    111: 		$outhash{'home_'.$ca.'@'.$cd}=1;
                    112: 	    } else {
1.107     albertel  113: 		$outhash{'otherhome_'.$ca.'@'.$cd}=$myhome;
1.74      www       114: 		$other++;
                    115: 	    }
                    116: 	}
                    117:     }
                    118:     return ($home,$other,%outhash);
                    119: }
                    120: # ------------------------------------------------------ Generate "dump" button
                    121: 
                    122: sub dumpbutton {
                    123:     my ($home,$other,%outhash)=&authorhosts();
1.230     albertel  124:     my $type = &Apache::loncommon::course_type();
1.74      www       125:     if ($home+$other==0) { return ''; }
                    126:     my $output='</td><td bgcolor="#DDDDCC">';
                    127:     if ($home) {
                    128: 	return '</td><td bgcolor="#DDDDCC">'.
1.81      www       129: 	    '<input type="submit" name="dumpcourse" value="'.
1.230     albertel  130: 	    &mt('Dump '.$type.' DOCS to Construction Space').'" />'.
1.130     www       131: 	    &Apache::loncommon::help_open_topic('Docs_Dump_Course_Docs');
1.74      www       132:     } else {
                    133: 	return'</td><td bgcolor="#DDDDCC">'.
1.230     albertel  134:      &mt('Dump '.$type.
                    135: 	 ' DOCS to Construction Space: available on other servers');
1.74      www       136:     }
                    137: }
                    138: 
1.164     albertel  139: sub clean {
                    140:     my ($title)=@_;
                    141:     $title=~s/[^\w\/\!\$\%\^\*\-\_\=\+\;\:\,\\\|\`\~]+/\_/gs;
                    142:     return $title;	
                    143: }
1.74      www       144: # -------------------------------------------------------- Actually dump course
                    145: 
                    146: sub dumpcourse {
1.224     albertel  147:     my ($r) = @_;
1.230     albertel  148:     my $type = &Apache::loncommon::course_type();
                    149:     $r->print(&Apache::loncommon::start_page('Dump '.$type.' DOCS to Construction Space').
                    150: 	      '<form name="dumpdoc" method="post">');
1.74      www       151:     my ($home,$other,%outhash)=&authorhosts();
1.75      www       152:     unless ($home) { return ''; }
1.174     albertel  153:     my $origcrsid=$env{'request.course.id'};
1.76      www       154:     my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
1.174     albertel  155:     if (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
1.76      www       156: # Do the dumping
1.174     albertel  157: 	unless ($outhash{'home_'.$env{'form.authorspace'}}) { return ''; }
                    158: 	my ($ca,$cd)=split(/\@/,$env{'form.authorspace'});
1.87      www       159: 	$r->print('<h3>'.&mt('Copying Files').'</h3>');
1.174     albertel  160: 	my $title=$env{'form.authorfolder'};
1.164     albertel  161: 	$title=&clean($title);
1.79      www       162: 	my %replacehash=();
1.174     albertel  163: 	foreach (keys %env) {
1.79      www       164: 	    if ($_=~/^form\.namefor\_(.+)/) {
1.174     albertel  165: 		$replacehash{$1}=$env{$_};
1.79      www       166: 	    }
                    167: 	}
1.174     albertel  168: 	my $crs='/uploaded/'.$env{'request.course.id'}.'/';
1.79      www       169: 	$crs=~s/\_/\//g;
                    170: 	foreach (keys %replacehash) {
                    171: 	    my $newfilename=$title.'/'.$replacehash{$_};
1.205     albertel  172: 	    $newfilename=~s/\.(\w+)$//;
                    173: 	    my $ext=$1;
1.164     albertel  174: 	    $newfilename=&clean($newfilename);
1.205     albertel  175: 	    $newfilename.='.'.$ext;
1.79      www       176: 	    my @dirs=split(/\//,$newfilename);
                    177: 	    my $path='/home/'.$ca.'/public_html';
                    178: 	    my $makepath=$path;
                    179: 	    my $fail=0;
                    180: 	    for (my $i=0;$i<$#dirs;$i++) {
                    181: 		$makepath.='/'.$dirs[$i];
                    182: 		unless (-e $makepath) { 
                    183: 		    unless(mkdir($makepath,0777)) { $fail=1; } 
                    184: 		}
                    185: 	    }
                    186: 	    $r->print('<br /><tt>'.$_.'</tt> => <tt>'.$newfilename.'</tt>: ');
                    187: 	    if (my $fh=Apache::File->new('>'.$path.'/'.$newfilename)) {
                    188: 		if ($_=~/\.(sequence|page|html|htm|xml|xhtml)$/) {
                    189: 		    print $fh &Apache::loncreatecourse::rewritefile(
1.174     albertel  190:          &Apache::loncreatecourse::readfile($env{'request.course.id'},$_),
1.79      www       191: 				     (%replacehash,$crs => '')
                    192: 								    );
                    193: 		} else {
                    194: 		    print $fh
1.174     albertel  195:          &Apache::loncreatecourse::readfile($env{'request.course.id'},$_);
1.79      www       196: 		       }
                    197: 		$fh->close();
                    198: 	    } else {
                    199: 		$fail=1;
                    200: 	    }
                    201: 	    if ($fail) {
                    202: 		$r->print('<font color="red">fail</font>');
                    203: 	    } else {
                    204: 		$r->print('<font color="green">ok</font>');
                    205: 	    }
                    206: 	}
1.76      www       207:     } else {
                    208: # Input form
                    209: 	unless ($home==1) {
                    210: 	    $r->print(
1.81      www       211: 		      '<h3>'.&mt('Select the Construction Space').'</h3><select name="authorspace">');
1.76      www       212: 	}
                    213: 	foreach (sort keys %outhash) {
                    214: 	    if ($_=~/^home_(.+)$/) {
                    215: 		if ($home==1) {
                    216: 		    $r->print(
                    217: 		  '<input type="hidden" name="authorspace" value="'.$1.'" />');
                    218: 		} else {
1.133     www       219: 		    $r->print('<option value="'.$1.'">'.$1.' - '.
                    220: 			      &Apache::loncommon::plainname(split(/\@/,$1)).'</option>');
1.76      www       221: 		}
                    222: 	    }
                    223: 	}
                    224: 	unless ($home==1) {
                    225: 	    $r->print('</select>');
                    226: 	}
                    227: 	my $title=$origcrsdata{'description'};
1.227     albertel  228: 	$title=~s/[\/\s]+/\_/gs;
1.164     albertel  229: 	$title=&clean($title);
1.81      www       230: 	$r->print('<h3>'.&mt('Folder in Construction Space').'</h3><input type="text" size="50" name="authorfolder" value="'.$title.'" /><br />');
1.76      www       231: 	&tiehash();
1.81      www       232: 	$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       233: 	foreach (&Apache::loncreatecourse::crsdirlist($origcrsid,'userfiles')) {
1.78      www       234: 	    $r->print('<tr><td>'.$_.'</td>');
                    235: 	    my ($ext)=($_=~/\.(\w+)$/);
                    236: 	    my $title=$hash{'title_'.$hash{
                    237: 		'ids_/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'.$_}};
1.163     albertel  238: 	    $title=~s/&colon;/:/g;
1.78      www       239: 	    $r->print('<td>'.($title?$title:'&nbsp;').'</td>');
                    240: 	    unless ($title) {
                    241: 		$title=$_;
                    242: 	    }
                    243: 	    $title=~s/\.(\w+)$//;
1.164     albertel  244: 	    $title=&clean($title);
1.78      www       245: 	    $title.='.'.$ext;
1.79      www       246: 	    $r->print("\n<td><input type='text' size='60' name='namefor_".$_."' value='".$title."' /></td></tr>\n");
1.76      www       247: 	}
1.78      www       248: 	$r->print("</table>\n");
1.76      www       249: 	&untiehash();
                    250: 	$r->print(
1.229     raeburn   251:   '<p><input type="submit" name="dumpcourse" value="'.&mt('Dump [_1] DOCS',$type).'" /></p></form>');
1.75      www       252:     }
1.74      www       253: }
1.76      www       254: 
1.138     raeburn   255: # ------------------------------------------------------ Generate "export" button
                    256: 
                    257: sub exportbutton {
1.230     albertel  258:     my $type = &Apache::loncommon::course_type();
1.138     raeburn   259:     return '</td><td bgcolor="#DDDDCC">'.
                    260:             '<input type="submit" name="exportcourse" value="'.
1.230     albertel  261:             &mt('Export '.$type.' to IMS').'" />'.
1.203     raeburn   262:     &Apache::loncommon::help_open_topic('Docs_Export_Course_Docs');
1.138     raeburn   263: }
                    264: 
                    265: sub exportcourse {
                    266:     my $r=shift;
1.230     albertel  267:     my $type = &Apache::loncommon::course_type();
1.138     raeburn   268:     my %discussiontime = &Apache::lonnet::dump('discussiontimes',
1.174     albertel  269:                                                $env{'course.'.$env{'request.course.id'}.'.domain'}, $env{'course.'.$env{'request.course.id'}.'.num'});
1.138     raeburn   270:     my $numdisc = keys %discussiontime;
                    271:     my $navmap = Apache::lonnavmaps::navmap->new();
                    272:     my $it=$navmap->getIterator(undef,undef,undef,1,undef,undef);
                    273:     my $curRes;
1.143     raeburn   274:     my $outcome;
1.138     raeburn   275: 
                    276:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
                    277:                                             ['finishexport']);
1.174     albertel  278:     if ($env{'form.finishexport'}) {
1.138     raeburn   279:         &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
                    280:                                             ['archive','discussion']);
                    281: 
1.175     albertel  282:         my @exportitems = &Apache::loncommon::get_env_multiple('form.archive');
                    283:         my @discussions = &Apache::loncommon::get_env_multiple('form.discussion');
1.143     raeburn   284:         if (@exportitems == 0 && @discussions == 0) {
                    285:             $outcome = '<br />As you did not select any content items or discussions for export, an IMS package has not been created.  Please <a href="javascript:history.go(-1)">go back</a> to select either content items or discussions for export';
                    286:         } else {
                    287:             my $now = time;
                    288:             my %symbs;
                    289:             my $manifestok = 0;
                    290:             my $imsresources;
                    291:             my $tempexport;
                    292:             my $copyresult;
                    293:             my $ims_manifest = &create_ims_store($now,\$manifestok,\$outcome,\$tempexport);
                    294:             if ($manifestok) {
1.157     raeburn   295:                 &build_package($now,$navmap,\@exportitems,\@discussions,\$outcome,$tempexport,\$copyresult,$ims_manifest);
1.143     raeburn   296:                 close($ims_manifest);
                    297: 
                    298: #Create zip file in prtspool
                    299:                 my $imszipfile = '/prtspool/'.
1.174     albertel  300:                 $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.143     raeburn   301:                    time.'_'.rand(1000000000).'.zip';
                    302:                 my $cwd = &Cwd::getcwd();
                    303:                 my $imszip = '/home/httpd/'.$imszipfile;
                    304:                 chdir $tempexport;
                    305:                 open(OUTPUT, "zip -r $imszip *  2> /dev/null |");
                    306:                 close(OUTPUT);
                    307:                 chdir $cwd;
1.230     albertel  308:                 $outcome .= &mt('Download the zip file from <a href="[_1]">IMS '.lc($type).' archive</a><br />',$imszipfile,);
1.143     raeburn   309:                 if ($copyresult) {
                    310:                     $outcome .= 'The following errors occurred during export - '.$copyresult;
1.138     raeburn   311:                 }
1.143     raeburn   312:             } else {
                    313:                 $outcome = '<br />Unfortunately you will not be able to retrieve an IMS archive of this posts at this time, because there was a problem creating a manifest file.<br />';
1.138     raeburn   314:             }
                    315:         }
1.229     raeburn   316:         $r->print(&Apache::loncommon::start_page('Export '.lc($type).' to IMS content package'));
1.143     raeburn   317:         $r->print($outcome);
1.224     albertel  318:         $r->print(&Apache::loncommon::end_page());
1.138     raeburn   319:     } else {
                    320:         my $display;
                    321:         $display = '<form name="exportdoc" method="post">'."\n";
1.230     albertel  322:         $display .= &mt('Choose which items you wish to export from your '.$type.'.<br /><br />');
1.138     raeburn   323:         $display .= '<table border="0" cellspacing="0" cellpadding="3">'.
                    324:                     '<tr><td><fieldset><legend>&nbsp;<b>Content items</b></legend>'.
                    325:                     '<input type="button" value="check all" '.
                    326:                     'onclick="javascript:checkAll(document.exportdoc.archive)" />'.
                    327:                     '&nbsp;&nbsp;<input type="button" value="uncheck all"'.
                    328:                     ' onclick="javascript:uncheckAll(document.exportdoc.archive)" /></fieldset></td>'.
                    329:                     '<td>&nbsp;</td><td>&nbsp;</td>'.
                    330:                     '<td align="right"><fieldset><legend>&nbsp;<b>Discussion posts'.
                    331:                     '</b></legend><input type="button" value="check all"'.
                    332:                     ' onclick="javascript:checkAll(document.exportdoc.discussion)" />'.
                    333:                     '&nbsp;&nbsp;<input type="button" value="uncheck all"'.
                    334:                     ' onclick="javascript:uncheckAll(document.exportdoc.discussion)" /></fieldset></td>'.
                    335:                     '</tr></table>';
                    336:         my $curRes;
                    337:         my $depth = 0;
                    338:         my $count = 0;
                    339:         my $boards = 0;
                    340:         my $startcount = 5;
                    341:         my %parent = ();
                    342:         my %children = ();
                    343:         my $lastcontainer = $startcount;
                    344:         my @bgcolors = ('#F6F6F6','#FFFFFF');
                    345:         $display .= '<table cellspacing="0"><tr>'.
                    346:             '<td><b>Export content item?<br /></b></td><td>&nbsp;</td><td align="right">'."\n";
                    347:         if ($numdisc > 0) {
                    348:             $display.='<b>Export&nbsp;discussion posts?</b>'."\n";
                    349:         }
                    350:         $display.='&nbsp;</td></tr>';
                    351:         while ($curRes = $it->next()) {
                    352:             if (ref($curRes)) {
                    353:                 $count ++;
                    354:             }
                    355:             if ($curRes == $it->BEGIN_MAP()) {
                    356:                 $depth++;
                    357:                 $parent{$depth} = $lastcontainer;
                    358:             }
                    359:             if ($curRes == $it->END_MAP()) {
                    360:                 $depth--;
                    361:                 $lastcontainer = $parent{$depth};
                    362:             }
                    363:             if (ref($curRes)) {
                    364:                 my $symb = $curRes->symb();
1.158     raeburn   365:                 my $ressymb = $symb;
                    366:                 if ($ressymb =~ m|adm/(\w+)/(\w+)/(\d+)/bulletinboard$|) {
                    367:                     unless ($ressymb =~ m|adm/wrapper/adm|) {
                    368:                         $ressymb = 'bulletin___'.$3.'___adm/wrapper/adm/'.$1.'/'.$2.'/'.$3.'/bulletinboard';
                    369:                     }
                    370:                 }
1.138     raeburn   371:                 my $color = $count%2;
                    372:                 $display .='<tr bgcolor='.$bgcolors[$color].'><td>'."\n".
                    373:                     '<input type="checkbox" name="archive" value="'.$count.'" ';
                    374:                 if (($curRes->is_sequence()) || ($curRes->is_page())) {
                    375:                     my $checkitem = $count + $boards + $startcount;
                    376:                     $display .= 'onClick="javascript:propagateCheck('."'$checkitem'".')"';
                    377:                 }
                    378:                 $display .= ' />'."\n";
                    379:                 for (my $i=0; $i<$depth; $i++) {
                    380:                     $display .= '<img src="/adm/lonIcons/whitespace1.gif" width="25" height="1" alt="" border="0" /><img src="/adm/lonIcons/whitespace1.gif" width="25" height="1" alt="" border="0" />'."\n";
                    381:                 }
                    382:                 if ($curRes->is_sequence()) {
                    383:                     $display .= '<img src="/adm/lonIcons/navmap.folder.open.gif">&nbsp;'."\n";
                    384:                     $lastcontainer = $count + $startcount + $boards;
                    385:                 } elsif ($curRes->is_page()) {
                    386:                     $display .= '<img src="/adm/lonIcons/navmap.page.open.gif">&nbsp;'."\n";
                    387:                     $lastcontainer = $count + $startcount + $boards;
                    388:                 }
                    389:                 my $currelem = $count+$boards+$startcount;
                    390:                 $children{$parent{$depth}} .= $currelem.':';
                    391:                 $display .= '&nbsp;'.$curRes->title().'</td>';
1.158     raeburn   392:                 if ($discussiontime{$ressymb} > 0) {
1.138     raeburn   393:                     $boards ++;
                    394:                     $currelem = $count+$boards+$startcount;
                    395:                     $display .= '<td>&nbsp;</td><td align="right"><input type="checkbox" name="discussion" value="'.$count.'" />&nbsp;</td>'."\n";
                    396:                 } else {
                    397:                     $display .= '<td colspan="2">&nbsp;</td>'."\n";
                    398:                 }
                    399:             }
                    400:         }
                    401:         my $scripttag = qq|
                    402: <script>
                    403: 
                    404: function checkAll(field) {
1.158     raeburn   405:     if (field.length > 0) {
                    406:         for (i = 0; i < field.length; i++) {
                    407:             field[i].checked = true ;
                    408:         }
                    409:     } else {
                    410:         field.checked = true
                    411:     }
1.138     raeburn   412: }
1.158     raeburn   413:                                                                                 
1.138     raeburn   414: function uncheckAll(field) {
1.158     raeburn   415:     if (field.length > 0) {
                    416:         for (i = 0; i < field.length; i++) {
                    417:             field[i].checked = false ;
                    418:         }
                    419:     } else {
                    420:         field.checked = false ;
                    421:     }
1.138     raeburn   422: }
                    423: 
                    424: function propagateCheck(item) {
                    425:     if (document.exportdoc.elements[item].checked == true) {
                    426:         containerCheck(item)
                    427:     }
                    428: } 
                    429: 
                    430: function containerCheck(item) {
                    431:     document.exportdoc.elements[item].checked = true
                    432:     var numitems = $count + $boards + $startcount
                    433:     var parents = new Array(numitems)
                    434:     for (var i=$startcount; i<numitems; i++) {
                    435:         parents[i] = new Array
                    436:     }
                    437:         |;
                    438: 
                    439:         foreach my $container (sort { $a <=> $b } keys %children) {
                    440:             my @contents = split/:/,$children{$container};
                    441:             for (my $i=0; $i<@contents; $i ++) {
                    442:                 $scripttag .= '    parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
                    443:             }
                    444:         }
                    445: 
                    446:         $scripttag .= qq|
                    447:     if (parents[item].length > 0) {
                    448:         for (var j=0; j<parents[item].length; j++) {
                    449:             containerCheck(parents[item][j])
                    450:         }
                    451:      }   
                    452: }
                    453: 
                    454: </script>
                    455:         |;
1.229     raeburn   456: 	$r->print(&Apache::loncommon::start_page('Export '.lc($type).' to IMS content package',
1.224     albertel  457: 						 $scripttag));
                    458: 	$r->print($display.'</table>'.
1.138     raeburn   459:                   '<p><input type="hidden" name="finishexport" value="1">'.
                    460:                   '<input type="submit" name="exportcourse" value="'.
1.230     albertel  461:                   &mt('Export '.$type.' DOCS').'" /></p></form>'.
1.224     albertel  462: 		  &Apache::loncommon::end_page());
1.138     raeburn   463:     }
                    464: }
                    465: 
1.143     raeburn   466: sub create_ims_store {
                    467:     my ($now,$manifestok,$outcome,$tempexport) = @_;
                    468:     $$tempexport = $Apache::lonnet::perlvar{'lonDaemons'}.'/tmp/ims_exports';
                    469:     my $ims_manifest;
                    470:     if (!-e $$tempexport) {
                    471:         mkdir($$tempexport,0700);
                    472:     }
                    473:     $$tempexport .= '/'.$now;
                    474:     if (!-e $$tempexport) {
                    475:         mkdir($$tempexport,0700);
                    476:     }
1.174     albertel  477:     $$tempexport .= '/'.$env{'user.domain'}.'_'.$env{'user.name'};
1.143     raeburn   478:     if (!-e $$tempexport) {
                    479:         mkdir($$tempexport,0700);
                    480:     }
1.159     raeburn   481:     if (!-e "$$tempexport/resources") {
                    482:         mkdir("$$tempexport/resources",0700);
                    483:     }
1.143     raeburn   484: # open manifest file
                    485:     my $manifest = '/imsmanifest.xml';
                    486:     my $manifestfilename = $$tempexport.$manifest;
                    487:     if ($ims_manifest = Apache::File->new('>'.$manifestfilename)) {
                    488:         $$manifestok=1;
                    489:         print $ims_manifest
                    490: '<?xml version="1.0" encoding="UTF-8"?>'."\n".
                    491: '<manifest xmlns="http://www.imsglobal.org/xsd/imscp_v1p1"'.
                    492: ' xmlns:imsmd="http://www.imsglobal.org/xsd/imsmd_v1p2"'.
                    493: ' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"'.
1.174     albertel  494: ' identifier="MANIFEST-'.$env{'request.course.id'}.'-'.$now.'"'.
1.143     raeburn   495: '  xsi:schemaLocation="http://www.imsglobal.org/xsd/imscp_v1p1imscp_v1p1.xsd'.
                    496: '  http://www.imsglobal.org/xsd/imsmd_v1p2 imsmd_v1p2p2.xsd">'."\n".
1.199     raeburn   497: '  <metadata>
                    498:     <schema></schema>
                    499:     <imsmd:lom>
                    500:       <imsmd:general>
                    501:         <imsmd:identifier>'.$env{'request.course.id'}.'</imsmd:identifier>
                    502:         <imsmd:title>
                    503:           <imsmd:langstring xml:lang="en">'.$env{'course.'.$env{'request.course.id'}.'.description'}.'</imsmd:langstring>
                    504:         </imsmd:title>
                    505:       </imsmd:general>
                    506:     </imsmd:lom>
                    507:   </metadata>'."\n".
1.174     albertel  508: '  <organizations default="ORG-'.$env{'request.course.id'}.'-'.$now.'">'."\n".
                    509: '    <organization identifier="ORG-'.$env{'request.course.id'}.'-'.$now.'"'.
1.143     raeburn   510: ' structure="hierarchical">'."\n".
1.199     raeburn   511: '      <title>'.$env{'course.'.$env{'request.course.id'}.'.description'}.'</title>'
1.143     raeburn   512:     } else {
                    513:         $$outcome .= 'An error occurred opening the IMS manifest file.<br />'
                    514: ;
                    515:     }
                    516:     return $ims_manifest;
                    517: }
                    518: 
                    519: sub build_package {
                    520:     my ($now,$navmap,$exportitems,$discussions,$outcome,$tempexport,$copyresult,$ims_manifest) = @_;
                    521: # first iterator to look for dependencies
                    522:     my $it = $navmap->getIterator(undef,undef,undef,1,undef,undef);
                    523:     my $curRes;
                    524:     my $count = 0;
                    525:     my $depth = 0;
                    526:     my $lastcontainer = 0;
                    527:     my %parent = ();
                    528:     my @dependencies = ();
1.174     albertel  529:     my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
                    530:     my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1.143     raeburn   531:     while ($curRes = $it->next()) {
                    532:         if (ref($curRes)) {
                    533:             $count ++;
                    534:         }
                    535:         if ($curRes == $it->BEGIN_MAP()) {
                    536:             $depth++;
                    537:             $parent{$depth} = $lastcontainer;
                    538:         }
                    539:         if ($curRes == $it->END_MAP()) {
                    540:             $depth--;
                    541:             $lastcontainer = $parent{$depth};
                    542:         }
                    543:         if (ref($curRes)) {
                    544:             if ($curRes->is_sequence() || $curRes->is_page()) {
                    545:                 $lastcontainer = $count;
                    546:             }
                    547:             if (grep/^$count$/,@$exportitems) {
                    548:                 &get_dependencies($exportitems,\%parent,$depth,\@dependencies);
                    549:             }
                    550:         }
                    551:     }
                    552: # second iterator to build manifest and store resources
                    553:     $it = $navmap->getIterator(undef,undef,undef,1,undef,undef);
                    554:     $depth = 0;
                    555:     my $prevdepth;
                    556:     $count = 0;
                    557:     my $imsresources;
                    558:     my $pkgdepth;
1.157     raeburn   559:     while ($curRes = $it->next()) {
                    560:         if ($curRes == $it->BEGIN_MAP()) {
                    561:             $prevdepth = $depth;
                    562:             $depth++;
                    563:         }
                    564:         if ($curRes == $it->END_MAP()) {
1.143     raeburn   565:             $prevdepth = $depth;
1.157     raeburn   566:             $depth--;
                    567:         }
                    568: 
                    569:         if (ref($curRes)) {
                    570:             $count ++;
                    571:             if ((grep/^$count$/,@$exportitems) || (grep/^$count$/,@dependencies)) {
                    572:                 my $symb = $curRes->symb();
                    573:                 my $isvisible = 'true';
                    574:                 my $resourceref;
                    575:                 if ($curRes->randomout()) {
                    576:                     $isvisible = 'false';
                    577:                 }
                    578:                 unless ($curRes->is_sequence()) {
1.174     albertel  579:                     $resourceref = 'identifierref="RES-'.$env{'request.course.id'}.'-'.$count.'"';
1.157     raeburn   580:                 }
1.199     raeburn   581:                 my $step = $prevdepth - $depth;
                    582:                 if (($step >= 0) && ($count > 1)) {
                    583:                     while ($step >= 0) {
                    584:                         print $ims_manifest "\n".'  </item>'."\n";
                    585:                         $step --;
                    586:                     }
1.157     raeburn   587:                 }
                    588:                 $prevdepth = $depth;
1.143     raeburn   589: 
1.157     raeburn   590:                 my $itementry =
1.174     albertel  591:               '<item identifier="ITEM-'.$env{'request.course.id'}.'-'.$count.
1.143     raeburn   592:               '" isvisible="'.$isvisible.'" '.$resourceref.'>'.
                    593:               '<title>'.$curRes->title().'</title>';
1.157     raeburn   594:                 print $ims_manifest "\n".$itementry;
1.143     raeburn   595: 
1.157     raeburn   596:                 unless ($curRes->is_sequence()) {
                    597:                     my $content_file;
                    598:                     my @hrefs = ();
                    599:                     &process_content($count,$curRes,$cdom,$cnum,$symb,\$content_file,\@hrefs,$copyresult,$tempexport);
                    600:                     if ($content_file) {
                    601:                         $imsresources .= "\n".
1.174     albertel  602:                      '   <resource identifier="RES-'.$env{'request.course.id'}.'-'.$count.
1.143     raeburn   603:                      '" type="webcontent" href="'.$content_file.'">'."\n".
                    604:                      '       <file href="'.$content_file.'" />'."\n";
1.157     raeburn   605:                         foreach (@hrefs) {
                    606:                             $imsresources .=
1.143     raeburn   607:                      '        <file href="'.$_.'" />'."\n";
1.157     raeburn   608:                         }
1.158     raeburn   609:                         if (grep/^$count$/,@$discussions) {
                    610:                             my $ressymb = $symb;
                    611:                             my $mode;
                    612:                             if ($ressymb =~ m|adm/(\w+)/(\w+)/(\d+)/bulletinboard$|) {
                    613:                                 unless ($ressymb =~ m|adm/wrapper/adm|) {
                    614:                                     $ressymb = 'bulletin___'.$3.'___adm/wrapper/adm/'.$1.'/'.$2.'/'.$3.'/bulletinboard';
                    615:                                 }
                    616:                                 $mode = 'board';
                    617:                             }
                    618:                             my %extras = (
                    619:                                           caller => 'imsexport',
1.159     raeburn   620:                                           tempexport => $tempexport.'/resources',
1.158     raeburn   621:                                           count => $count
                    622:                                          );
                    623:                             my $discresult = &Apache::lonfeedback::list_discussion($mode,undef,$ressymb,\%extras);
                    624:                         }
1.157     raeburn   625:                         $imsresources .= '    </resource>'."\n";
1.143     raeburn   626:                     }
                    627:                 }
1.157     raeburn   628:                 $pkgdepth = $depth;
1.143     raeburn   629:             }
                    630:         }
                    631:     }
1.157     raeburn   632:     while ($pkgdepth > 0) {
1.143     raeburn   633:         print $ims_manifest "    </item>\n";
                    634:         $pkgdepth --;
                    635:     }
                    636:     my $resource_text = qq|
                    637:     </organization>
                    638:   </organizations>
                    639:   <resources>
                    640:     $imsresources
                    641:   </resources>
                    642: </manifest>
                    643:     |;
                    644:     print $ims_manifest $resource_text;
                    645: }
                    646: 
                    647: sub get_dependencies {
                    648:     my ($exportitems,$parent,$depth,$dependencies) = @_;
                    649:     if ($depth > 1) {
1.157     raeburn   650:         if ((!grep/^$$parent{$depth}$/,@$exportitems) && (!grep/^$$parent{$depth}$/,@$dependencies)) {
1.143     raeburn   651:             push @$dependencies, $$parent{$depth};
                    652:             if ($depth > 2) {
                    653:                 &get_dependencies($exportitems,$parent,$depth-1,$dependencies);
                    654:             }
                    655:         }
                    656:     }
                    657: }
                    658: 
                    659: sub process_content {
                    660:     my ($count,$curRes,$cdom,$cnum,$symb,$content_file,$href,$copyresult,$tempexport) = @_;
                    661:     my $content_type;
                    662:     my $message;
1.158     raeburn   663:     my @uploads = ();
1.157     raeburn   664:     if ($curRes->is_sequence()) {
                    665:         $content_type = 'sequence';
                    666:     } elsif ($curRes->is_page()) {
                    667:         $content_type = 'page'; # need to handle individual items in pages.
1.143     raeburn   668:     } elsif ($symb =~ m-public/$cdom/$cnum/syllabus$-) {
                    669:         $content_type = 'syllabus';
1.158     raeburn   670:         my $contents = &Apache::imsexport::templatedpage($content_type);
                    671:         if ($contents) {
                    672:             $$content_file = &store_template($contents,$tempexport,$count,$content_type);
                    673:         }
1.157     raeburn   674:     } elsif ($symb =~ m-\.sequence___\d+___ext-) {
1.143     raeburn   675:         $content_type = 'external';
1.158     raeburn   676:         my $title = $curRes->title;
                    677:         my $contents =  &Apache::imsexport::external($symb,$title);
                    678:         if ($contents) {
                    679:             $$content_file = &store_template($contents,$tempexport,$count,$content_type);
                    680:         }
1.143     raeburn   681:     } elsif ($symb =~ m-adm/navmaps$-) {
                    682:         $content_type =  'navmap';
1.158     raeburn   683:     } elsif ($symb =~ m-adm/[^/]+/[^/]+/(\d+)/smppg$-) {
1.143     raeburn   684:         $content_type = 'simplepage';
1.158     raeburn   685:         my $contents = &Apache::imsexport::templatedpage($content_type,$1,$count,\@uploads);
                    686:         if ($contents) {
                    687:             $$content_file = &store_template($contents,$tempexport,$count,$content_type);
                    688:         }
                    689:     } elsif ($symb =~ m-lib/templates/simpleproblem\.problem$-) {
1.143     raeburn   690:         $content_type = 'simpleproblem';
1.158     raeburn   691:         my $contents =  &Apache::imsexport::simpleproblem($symb);
                    692:         if ($contents) {
                    693:             $$content_file = &store_template($contents,$tempexport,$count,$content_type);
                    694:         }
1.188     raeburn   695:     } elsif ($symb =~ m-lib/templates/examupload\.problem$-) {
1.158     raeburn   696:         $content_type = 'examupload';
                    697:     } elsif ($symb =~ m-adm/(\w+)/(\w+)/(\d+)/bulletinboard$-) {
1.143     raeburn   698:         $content_type = 'bulletinboard';
1.158     raeburn   699:         my $contents =  &Apache::imsexport::templatedpage($content_type,$3,$count,\@uploads,$1,$2);
                    700:         if ($contents) {
                    701:             $$content_file = &store_template($contents,$tempexport,$count,$content_type);
                    702:         }
                    703:     } elsif ($symb =~ m-adm/([^/]+)/([^/]+)/aboutme$-) {
1.143     raeburn   704:         $content_type = 'aboutme';
1.158     raeburn   705:         my $contents =  &Apache::imsexport::templatedpage($content_type,undef,$count,\@uploads,$1,$2);
                    706:         if ($contents) {
                    707:             $$content_file = &store_template($contents,$tempexport,$count,$content_type);
                    708:         }
1.157     raeburn   709:     } elsif ($symb =~ m-\.(sequence|page)___\d+___uploaded/$cdom/$cnum/-) {
                    710:         $$content_file = &replicate_content($cdom,$cnum,$tempexport,$symb,$count,\$message,$href,'uploaded');
1.162     raeburn   711:     } elsif ($symb =~ m-\.(sequence|page)___\d+___([^/]+)/([^/]+)-) {
1.143     raeburn   712:         my $canedit = 0;
1.174     albertel  713:         if ($2 eq $env{'user.domain'} && $3 eq $env{'user.name'})  {
1.143     raeburn   714:             $canedit= 1;
                    715:         }
1.200     raeburn   716: # only include problem code where current user is author
1.143     raeburn   717:         if ($canedit) {
1.157     raeburn   718:             $$content_file = &replicate_content($cdom,$cnum,$tempexport,$symb,$count,\$message,$href,'resource');
1.143     raeburn   719:         } else {
1.157     raeburn   720:             $$content_file = &replicate_content($cdom,$cnum,$tempexport,$symb,$count,\$message,$href,'noedit');
1.143     raeburn   721:         }
1.162     raeburn   722:     } elsif ($symb =~ m-uploaded/$cdom/$cnum-) {
                    723:         $$content_file = &replicate_content($cdom,$cnum,$tempexport,$symb,$count,\$message,$href,'uploaded');
1.143     raeburn   724:     }
1.158     raeburn   725:     if (@uploads > 0) {
                    726:         foreach my $item (@uploads) {
                    727:             my $uploadmsg = '';
1.159     raeburn   728:             &replicate_content($cdom,$cnum,$tempexport,$item,$count,\$uploadmsg,$href,'templateupload');
1.158     raeburn   729:             if ($uploadmsg) {
                    730:                 $$copyresult .= $uploadmsg."\n";
                    731:             }
                    732:         }
                    733:     }
1.157     raeburn   734:     if ($message) {
                    735:         $$copyresult .= $message."\n";
                    736:     }
1.143     raeburn   737: }
                    738: 
                    739: sub replicate_content {
1.157     raeburn   740:     my ($cdom,$cnum,$tempexport,$symb,$count,$message,$href,$caller) = @_;
1.159     raeburn   741:     my ($map,$ind,$url);
                    742:     if ($caller eq 'templateupload') {
                    743:         $url = $symb;
                    744:         $url =~ s#//#/#g;
                    745:     } else { 
                    746:         ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
                    747:     }
1.143     raeburn   748:     my $content;
                    749:     my $filename;
                    750:     my $repstatus;
1.157     raeburn   751:     my $content_name;
                    752:     if ($url =~ m-/([^/]+)$-) {
1.143     raeburn   753:         $filename = $1;
                    754:         if (!-e $tempexport.'/resources') {
                    755:             mkdir($tempexport.'/resources',0700);
                    756:         }
1.157     raeburn   757:         if (!-e $tempexport.'/resources/'.$count) {
1.143     raeburn   758:             mkdir($tempexport.'/resources/'.$count,0700);
                    759:         }
1.157     raeburn   760:         my $destination = $tempexport.'/resources/'.$count.'/'.$filename;
1.143     raeburn   761:         my $copiedfile;
                    762:         if ($copiedfile = Apache::File->new('>'.$destination)) {
                    763:             my $content;
1.157     raeburn   764:             if ($caller eq 'resource') {
1.197     raeburn   765:                 my $respath =  $Apache::lonnet::perlvar{'lonDocRoot'}.'/res';
                    766:                 my $filepath = &Apache::lonnet::filelocation($respath,$url);
                    767:                 $content = &Apache::lonnet::getfile($filepath);
1.143     raeburn   768:                 if ($content eq -1) {
                    769:                     $$message = 'Could not copy file '.$filename;
                    770:                 } else {
1.197     raeburn   771:                     &extract_media($url,$cdom,$cnum,\$content,$count,$tempexport,$href,$message,'resource');
1.143     raeburn   772:                     $repstatus = 'ok';
                    773:                 }
1.162     raeburn   774:             } elsif ($caller eq 'uploaded' || $caller eq 'templateupload') {
1.143     raeburn   775:                 my $rtncode;
1.157     raeburn   776:                 $repstatus = &Apache::lonnet::getuploaded('GET',$url,$cdom,$cnum,\$content,$rtncode);
                    777:                 if ($repstatus eq 'ok') {
                    778:                     if ($url =~ /\.html?$/i) {
1.197     raeburn   779:                         &extract_media($url,$cdom,$cnum,\$content,$count,$tempexport,$href,$message,'uploaded');
1.157     raeburn   780:                     }
                    781:                 } else {
1.197     raeburn   782:                     $$message = 'Could not render '.$url.' server message - '.$rtncode."<br />\n";
1.143     raeburn   783:                 }
1.162     raeburn   784:             } elsif ($caller eq 'noedit') {
                    785: # Need to render the resource without the LON-CAPA Internal header and the Post discussion footer, and then set $content equal to this. 
                    786:                 $repstatus = 'ok';
                    787:                 $content = 'Not the owner of this resource'; 
1.143     raeburn   788:             }
                    789:             if ($repstatus eq 'ok') {
                    790:                 print $copiedfile $content;
                    791:             }
                    792:             close($copiedfile);
                    793:         } else {
1.197     raeburn   794:             $$message = 'Could not open destination file for '.$filename."<br />\n";
1.143     raeburn   795:         }
                    796:     } else {
1.197     raeburn   797:         $$message = 'Could not determine name of file for '.$symb."<br />\n";
1.143     raeburn   798:     }
1.157     raeburn   799:     if ($repstatus eq 'ok') {
1.198     raeburn   800:         $content_name = 'resources/'.$count.'/'.$filename;
1.157     raeburn   801:     }
                    802:     return $content_name;
                    803: }
                    804: 
                    805: sub extract_media {
1.197     raeburn   806:     my ($url,$cdom,$cnum,$content,$count,$tempexport,$href,$message,$caller) = @_;
1.198     raeburn   807:     my ($dirpath,$container);
1.197     raeburn   808:     my %allfiles = ();
                    809:     my %codebase = ();
1.198     raeburn   810:     if ($url =~ m-(.*/)([^/]+)$-) {
                    811:         $dirpath = $1;
                    812:         $container = $2;
                    813:     } else {
                    814:         $dirpath = $url;
                    815:         $container = '';
                    816:     }
1.197     raeburn   817:     &Apache::lonnet::extract_embedded_items(undef,undef,\%allfiles,\%codebase,$content);
                    818:     foreach my $embed_file (keys(%allfiles)) {
                    819:         my $filename;
                    820:         if ($embed_file =~ m#([^/]+)$#) {
                    821:             $filename = $1;
                    822:         } else {
                    823:             $filename = $embed_file;
                    824:         }
                    825:         my $newname = 'res/'.$filename;
                    826:         my ($rtncode,$embed_content,$repstatus);
                    827:         my $embed_url;
                    828:         if ($embed_file =~ m-^/-) {
                    829:             $embed_url = $embed_file;           # points to absolute path
                    830:         } else {
                    831:             if ($embed_file =~ m-https?://-) {
                    832:                 next;                           # points to url
                    833:             } else {
1.198     raeburn   834:                 $embed_url = $dirpath.$embed_file;  # points to relative path
1.197     raeburn   835:             }
                    836:         }
                    837:         if ($caller eq 'resource') {
                    838:             my $respath =  $Apache::lonnet::perlvar{'lonDocRoot'}.'/res';  
                    839:             my $embed_path = &Apache::lonnet::filelocation($respath,$embed_url); 
                    840:             $embed_content = &Apache::lonnet::getfile($embed_path);
                    841:             unless ($embed_content eq -1) {
                    842:                 $repstatus = 'ok';
                    843:             }
                    844:         } elsif ($caller eq 'uploaded') {
                    845:             
                    846:             $repstatus = &Apache::lonnet::getuploaded('GET',$embed_url,$cdom,$cnum,\$embed_content,$rtncode);
                    847:         }
                    848:         if ($repstatus eq 'ok') {
                    849:             my $destination = $tempexport.'/resources/'.$count.'/res';
                    850:             if (!-e "$destination") {
                    851:                 mkdir($destination,0755);
                    852:             }
                    853:             $destination .= '/'.$filename;
                    854:             my $copiedfile;
                    855:             if ($copiedfile = Apache::File->new('>'.$destination)) {
                    856:                 print $copiedfile $embed_content;
1.198     raeburn   857:                 push @{$href}, 'resources/'.$count.'/res/'.$filename;
1.197     raeburn   858:                 my $attrib_regexp = '';
                    859:                 if (@{$allfiles{$embed_file}} > 1) {
                    860:                     $attrib_regexp = join('|',@{$allfiles{$embed_file}});
                    861:                 } else {
                    862:                     $attrib_regexp = $allfiles{$embed_file}[0];
                    863:                 }
                    864:                 $$content =~ s#($attrib_regexp\s*=\s*['"]?)\Q$embed_file\E(['"]?)#$1$newname$2#gi;
1.198     raeburn   865:                 if ($caller eq 'resource' && $container =~ /\.(problem|library)$/) {
1.197     raeburn   866:                     $$content =~ s#\Q$embed_file\E#$newname#gi;
                    867:                 }
                    868:             }
                    869:         } else {
                    870:             $$message .= 'replication of embedded file - '.$embed_file.' in '.$url.' failed, reason -'.$rtncode."<br />\n";
                    871:         }
                    872:     }
1.157     raeburn   873:     return;
1.143     raeburn   874: }
1.74      www       875: 
1.158     raeburn   876: sub store_template {
                    877:     my ($contents,$tempexport,$count,$content_type) = @_;
                    878:     if ($contents) {
1.159     raeburn   879:         if ($tempexport) {
                    880:             if (!-e $tempexport.'/resources') {
                    881:                 mkdir($tempexport.'/resources',0700);
                    882:             }
                    883:             if (!-e $tempexport.'/resources/'.$count) {
                    884:                 mkdir($tempexport.'/resources/'.$count,0700);
                    885:             }
                    886:             my $destination = $tempexport.'/resources/'.$count.'/'.$content_type.'.xml';
                    887:             my $storetemplate;
                    888:             if ($storetemplate = Apache::File->new('>'.$destination)) {
                    889:                 print $storetemplate $contents;
                    890:                 close($storetemplate);
                    891:             }
                    892:             if ($content_type eq 'external') {
1.198     raeburn   893:                 return 'resources/'.$count.'/'.$content_type.'.html';
1.159     raeburn   894:             } else {
1.198     raeburn   895:                 return 'resources/'.$count.'/'.$content_type.'.xml';
1.159     raeburn   896:             }
1.158     raeburn   897:         }
                    898:     }
                    899: }
                    900: 
1.73      bowersj2  901: # Imports the given (name, url) resources into the course
                    902: # coursenum, coursedom, and folder must precede the list
                    903: sub group_import {
                    904:     my $coursenum = shift;
                    905:     my $coursedom = shift;
                    906:     my $folder = shift;
1.142     raeburn   907:     my $container = shift;
                    908:     my $caller = shift;
1.73      bowersj2  909:     while (@_) {
                    910: 	my $name = shift;
                    911: 	my $url = shift;
1.142     raeburn   912:         if (($url =~ m#^/uploaded/$coursedom/$coursenum/(default_\d+\.)(page|sequence)$#) && ($caller eq 'londocs')) {
                    913:             my $errtext = '';
                    914:             my $fatal = 0;
                    915:             my $newmapstr = '<map>'."\n".
                    916:                             '<resource id="1" src="" type="start"></resource>'."\n".
                    917:                             '<link from="1" to="2" index="1"></link>'."\n".
                    918:                             '<resource id="2" src="" type="finish"></resource>'."\n".
                    919:                             '</map>';
1.174     albertel  920:             $env{'form.output'}=$newmapstr;
1.189     albertel  921:             my $result=&Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
1.142     raeburn   922:                                                 'output',$1.$2);
                    923:             if ($result != m|^/uploaded/|) {
                    924:                 $errtext.='Map not saved: A network error occured when trying to save the new map. ';
                    925:                 $fatal = 2;
                    926:             }
                    927:             if ($fatal) {
                    928:                 return ($errtext,$fatal);
                    929:             }
                    930:         }
1.73      bowersj2  931: 	if ($url) {
1.178     www       932: 	    my $idx = &Apache::lonratedt::getresidx($url);
1.73      bowersj2  933: 	    $Apache::lonratedt::order[$#Apache::lonratedt::order+1]=$idx;
                    934: 	    my $ext = 'false';
                    935: 	    if ($url=~/^http:\/\//) { $ext = 'true'; }
                    936: 	    $url =~ s/:/\&colon;/g;
                    937: 	    $name =~ s/:/\&colon;/g;
                    938: 	    $Apache::lonratedt::resources[$idx] = 
                    939: 		join ':', ($name, $url, $ext, 'normal', 'res');
                    940: 	}
                    941:     }
1.142     raeburn   942:     return &storemap($coursenum, $coursedom, $folder.'.'.$container);
1.73      bowersj2  943: }
                    944: 
1.114     albertel  945: sub breadcrumbs {
                    946:     my ($where)=@_;
                    947:     &Apache::lonhtmlcommon::clear_breadcrumbs();
1.142     raeburn   948:     my (@folders);
1.174     albertel  949:     if ($env{'form.pagepath'}) {
                    950:         @folders = split('&',$env{'form.pagepath'});
1.142     raeburn   951:     } else {
1.174     albertel  952:         @folders=split('&',$env{'form.folderpath'});
1.142     raeburn   953:     }
1.116     albertel  954:     my $folderpath;
1.168     www       955:     my $cpinfo='';
1.174     albertel  956:     if ($env{'form.markedcopy_url'}) {
1.168     www       957:        $cpinfo='&markedcopy_url='.
1.228     www       958:                &escape($env{'form.markedcopy_url'}).
1.168     www       959:                '&markedcopy_title='.
1.228     www       960:                &escape($env{'form.markedcopy_title'});
1.168     www       961:     }
1.116     albertel  962:     while (@folders) {
                    963: 	my $folder=shift(@folders);
                    964: 	my $foldername=shift(@folders);
                    965: 	if ($folderpath) {$folderpath.='&';}
                    966: 	$folderpath.=$folder.'&'.$foldername;
                    967: 	my $url='/adm/coursedocs?folderpath='.
1.228     www       968: 	    &escape($folderpath);
1.114     albertel  969: 	    &Apache::lonhtmlcommon::add_breadcrumb(
1.168     www       970: 		      {'href'=>$url.$cpinfo,
1.228     www       971: 		       'title'=>&unescape($foldername),
1.117     albertel  972: 		       'text'=>'<font size="+1">'.
1.228     www       973: 			   &unescape($foldername).'</font>'
1.117     albertel  974: 		       });
1.114     albertel  975: 		       
                    976: 						 
                    977:     }
1.226     albertel  978:     return &Apache::lonhtmlcommon::breadcrumbs(undef,undef,0,'nohelp');
1.114     albertel  979: }
                    980: 
1.7       www       981: sub editor {
1.188     raeburn   982:     my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output)=@_;
1.10      www       983:     my $errtext='';
                    984:     my $fatal=0;
1.142     raeburn   985:     my $container='sequence';
1.174     albertel  986:     if ($env{'form.pagepath'}) {
1.142     raeburn   987:         $container='page';
                    988:     }
1.10      www       989:     ($errtext,$fatal)=
1.142     raeburn   990:               &mapread($coursenum,$coursedom,$folder.'.'.$container);
1.17      www       991:     if ($#Apache::lonratedt::order<1) {
1.178     www       992: 	my $idx=&Apache::lonratedt::getresidx();
                    993: 	if ($idx<=0) { $idx=1; }
                    994:        	$Apache::lonratedt::order[0]=$idx;
                    995:         $Apache::lonratedt::resources[$idx]='';
1.17      www       996:     }
1.174     albertel  997:     if (defined($env{'form.markcopy'})) {
1.168     www       998: # Mark for copying
1.174     albertel  999: 	my ($title,$url)=split(':',$Apache::lonratedt::resources[$Apache::lonratedt::order[$env{'form.markcopy'}]]);
                   1000: 	$env{'form.markedcopy_title'}=$title;
                   1001: 	$env{'form.markedcopy_url'}=$url;
1.168     www      1002:     }
                   1003:     $r->print(&breadcrumbs($folder));
1.7       www      1004:     if ($fatal) {
                   1005: 	   $r->print('<p><font color="red">'.$errtext.'</font></p>');
                   1006:     } else {
                   1007: # ------------------------------------------------------------ Process commands
1.121     www      1008: 
1.16      www      1009: # ---------------- if they are for this folder and user allowed to make changes
1.174     albertel 1010: 	if (($allowed) && ($env{'form.folder'} eq $folder)) {
1.123     www      1011: # set parameters and change order
1.174     albertel 1012: 	    if (defined($env{'form.setparms'})) {
                   1013: 		my $idx=$env{'form.setparms'};
1.123     www      1014: # set parameters
1.174     albertel 1015: 		if ($env{'form.randpick_'.$idx}) {
                   1016: 		    &Apache::lonratedt::storeparameter($idx,'parameter_randompick',$env{'form.randpick_'.$idx},'int_pos');
1.121     www      1017: 		} else {
1.122     www      1018: 		    &Apache::lonratedt::delparameter($idx,'parameter_randompick');
1.121     www      1019: 		}
1.174     albertel 1020: 		if ($env{'form.hidprs_'.$idx}) {
1.122     www      1021: 		    &Apache::lonratedt::storeparameter($idx,'parameter_hiddenresource','yes','string_yesno');
1.121     www      1022: 		} else {
1.122     www      1023: 		    &Apache::lonratedt::delparameter($idx,'parameter_hiddenresource');
1.121     www      1024: 		}
1.174     albertel 1025: 		if ($env{'form.encprs_'.$idx}) {
1.122     www      1026: 		    &Apache::lonratedt::storeparameter($idx,'parameter_encrypturl','yes','string_yesno');
1.121     www      1027: 		} else {
1.122     www      1028: 		    &Apache::lonratedt::delparameter($idx,'parameter_encrypturl');
1.121     www      1029: 		}
                   1030: 
1.174     albertel 1031: 		if ($env{'form.newpos'}) {
1.123     www      1032: # change order
                   1033: 
1.174     albertel 1034: 		    my $newpos=$env{'form.newpos'}-1;
                   1035: 		    my $currentpos=$env{'form.currentpos'}-1;
1.125     www      1036: 		    my $i;
                   1037: 		    my @neworder=();
                   1038: 		    if ($newpos>$currentpos) {
                   1039: # moving stuff up
                   1040: 			for ($i=0;$i<$currentpos;$i++) {
                   1041: 			    $neworder[$i]=$Apache::lonratedt::order[$i];
                   1042: 			}
                   1043: 			for ($i=$currentpos;$i<$newpos;$i++) {
                   1044: 			    $neworder[$i]=$Apache::lonratedt::order[$i+1];
                   1045: 			}
                   1046:                         $neworder[$newpos]=$Apache::lonratedt::order[$currentpos];
                   1047: 			for ($i=$newpos+1;$i<=$#Apache::lonratedt::order;$i++) {
                   1048: 			    $neworder[$i]=$Apache::lonratedt::order[$i];
                   1049: 			}
                   1050: 		    } else {
                   1051: # moving stuff down
                   1052: 			for ($i=0;$i<$newpos;$i++) {
                   1053: 			    $neworder[$i]=$Apache::lonratedt::order[$i];
                   1054: 			}
                   1055: 			$neworder[$newpos]=$Apache::lonratedt::order[$currentpos];
                   1056: 			for ($i=$newpos+1;$i<$currentpos+1;$i++) {
                   1057: 			    $neworder[$i]=$Apache::lonratedt::order[$i-1];
                   1058: 			}
                   1059: 			for ($i=$currentpos+1;$i<=$#Apache::lonratedt::order;$i++) {
                   1060: 			    $neworder[$i]=$Apache::lonratedt::order[$i];
                   1061: 			}
                   1062: 		    }
                   1063: 		    @Apache::lonratedt::order=@neworder;
1.124     www      1064: 		}
                   1065: # store the changed version
1.123     www      1066: 
1.142     raeburn  1067: 		($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
1.124     www      1068: 		if ($fatal) {
                   1069: 		    $r->print('<p><font color="red">'.$errtext.'</font></p>');
                   1070: 		    return;
1.123     www      1071: 		}
1.124     www      1072: 		
                   1073: 	    }
1.174     albertel 1074: 	    if ($env{'form.pastemarked'}) {
1.168     www      1075: # paste resource to end of list
1.174     albertel 1076:                 my $url=$env{'form.markedcopy_url'};
                   1077: 		my $title=$env{'form.markedcopy_title'};
1.168     www      1078: # Maps need to be copied first
                   1079: 		if (($url=~/\.(page|sequence)$/) || ($url=~/^\/uploaded\//)) {
                   1080: 		    $title=&mt('Copy of').' '.$title;
                   1081:                     my $newid=$$.time;
                   1082: 		    $url=~/^(.+)\.(\w+)$/;
                   1083: 		    my $newurl=$1.$newid.'.'.$2;
                   1084: 		    my $storefn=$newurl;
                   1085:                     $storefn=~s/^\/\w+\/\w+\/\w+\///;
                   1086: 		    &Apache::loncreatecourse::writefile
1.174     albertel 1087: 			($env{'request.course.id'},$storefn,
1.168     www      1088: 			 &Apache::lonnet::getfile($url));
                   1089: 		    $url=$newurl;
                   1090: 		}
                   1091: 		$title=~s/\</\&lt\;/g;
                   1092: 		$title=~s/\>/\&gt\;/g;
                   1093: 		$title=~s/\:/\&colon;/g;
                   1094: 		my $ext='false';
                   1095: 		if ($url=~/^http\:\/\//) { $ext='true'; }
                   1096: 		$url=~s/\:/\&colon;/g;
                   1097: # Now insert the URL at the bottom
1.179     www      1098:                 my $newidx=&Apache::lonratedt::getresidx($url);
1.168     www      1099: 		$Apache::lonratedt::resources[$newidx]=
                   1100: 		    $title.':'.$url.':'.$ext.':normal:res';
                   1101: 		$Apache::lonratedt::order[1+$#Apache::lonratedt::order]=$newidx;
                   1102: # Store the result
                   1103: 		($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
                   1104: 		if ($fatal) {
                   1105: 		    $r->print('<p><font color="red">'.$errtext.'</font></p>');
                   1106: 		    return;
                   1107: 		}
1.123     www      1108: 
1.168     www      1109: 	    }
1.188     raeburn  1110:             $r->print($upload_output);
1.174     albertel 1111: 	    if ($env{'form.cmd'}) {
                   1112:                 my ($cmd,$idx)=split(/\_/,$env{'form.cmd'});
1.10      www      1113:                 if ($cmd eq 'del') {
1.128     albertel 1114: 		    my (undef,$url)=split(':',$Apache::lonratedt::resources[$Apache::lonratedt::order[$idx]]);
1.187     www      1115: 		    if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
1.206     albertel 1116: 			($url!~/\.(page|sequence|problem|exam|quiz|assess|survey|form|library|task)$/)) {
1.187     www      1117: 			&Apache::lonnet::removeuploadedurl($url);
                   1118: 		    } else {
                   1119: 			&Apache::lonratedt::makezombie($Apache::lonratedt::order[$idx]);
1.128     albertel 1120: 		    }
1.10      www      1121: 		    for (my $i=$idx;$i<$#Apache::lonratedt::order;$i++) {
                   1122:                         $Apache::lonratedt::order[$i]=
                   1123:                           $Apache::lonratedt::order[$i+1];
                   1124:                     }
                   1125:                     $#Apache::lonratedt::order--;
1.171     www      1126:                 } elsif ($cmd eq 'cut') {
                   1127: 		    my (undef,$url)=split(':',$Apache::lonratedt::resources[$Apache::lonratedt::order[$idx]]);
1.179     www      1128: 		    &Apache::lonratedt::makezombie($Apache::lonratedt::order[$idx]);
1.171     www      1129: 		    for (my $i=$idx;$i<$#Apache::lonratedt::order;$i++) {
                   1130:                         $Apache::lonratedt::order[$i]=
                   1131:                           $Apache::lonratedt::order[$i+1];
                   1132:                     }
                   1133:                     $#Apache::lonratedt::order--;
1.10      www      1134:                 } elsif ($cmd eq 'up') {
1.38      www      1135: 		  if (($idx) && (defined($Apache::lonratedt::order[$idx-1]))) {
1.10      www      1136:                     my $i=$Apache::lonratedt::order[$idx-1];
                   1137:                     $Apache::lonratedt::order[$idx-1]=
                   1138: 			$Apache::lonratedt::order[$idx];
                   1139:                     $Apache::lonratedt::order[$idx]=$i;
1.38      www      1140: 		   }
1.10      www      1141:                 } elsif ($cmd eq 'down') {
1.38      www      1142: 		   if (defined($Apache::lonratedt::order[$idx+1])) {
1.10      www      1143:                     my $i=$Apache::lonratedt::order[$idx+1];
                   1144:                     $Apache::lonratedt::order[$idx+1]=
                   1145: 			$Apache::lonratedt::order[$idx];
                   1146:                     $Apache::lonratedt::order[$idx]=$i;
1.38      www      1147: 		   }
1.36      www      1148:                 } elsif ($cmd eq 'rename') {
1.142     raeburn  1149:                     my $ratstr = $Apache::lonratedt::resources[$Apache::lonratedt::order[$idx]];
1.36      www      1150:                     my ($rtitle,@rrest)=split(/\:/,
                   1151:                        $Apache::lonratedt::resources[
                   1152: 				       $Apache::lonratedt::order[$idx]]);
1.38      www      1153:                     my $comment=
1.174     albertel 1154:                      &HTML::Entities::decode($env{'form.title'});
1.36      www      1155:                     $comment=~s/\</\&lt\;/g;
                   1156:                     $comment=~s/\>/\&gt\;/g;
                   1157:                     $comment=~s/\:/\&colon;/g;
1.144     albertel 1158: 		    if ($comment=~/\S/) {
                   1159: 			$Apache::lonratedt::resources[
1.36      www      1160: 				       $Apache::lonratedt::order[$idx]]=
1.144     albertel 1161: 				            $comment.':'.join(':',@rrest);
                   1162: 		    }
1.10      www      1163:                 }
                   1164: # Store the changed version
1.104     albertel 1165: 		($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.142     raeburn  1166: 					    $folder.'.'.$container);
1.104     albertel 1167: 		if ($fatal) {
                   1168: 		    $r->print('<p><font color="red">'.$errtext.'</font></p>');
                   1169: 		    return;
                   1170: 		}
1.8       www      1171:             }
1.11      www      1172: # Group import/search
1.174     albertel 1173: 	    if ($env{'form.importdetail'}) {
1.73      bowersj2 1174: 		my @imports;
1.174     albertel 1175: 		foreach (split(/\&/,$env{'form.importdetail'})) {
1.73      bowersj2 1176: 		    if (defined($_)) {
                   1177: 			my ($name,$url)=split(/\=/,$_);
1.228     www      1178: 			$name=&unescape($name);
                   1179: 			$url=&unescape($url);
1.73      bowersj2 1180: 			push @imports, $name, $url;
                   1181: 		    }
                   1182: 		}
1.11      www      1183: # Store the changed version
1.104     albertel 1184: 		($errtext,$fatal)=group_import($coursenum, $coursedom, $folder,
1.142     raeburn  1185: 					       $container,'londocs',@imports);
1.104     albertel 1186: 		if ($fatal) {
                   1187: 		    $r->print('<p><font color="red">'.$errtext.'</font></p>');
                   1188: 		    return;
                   1189: 		}
1.11      www      1190:             }
1.53      www      1191: # Loading a complete map
1.223     www      1192: 	   if ($env{'form.loadmap'}) {
                   1193:                if ($env{'form.importmap'}=~/\w/) {
                   1194: 	          foreach (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
                   1195: 		      my ($title,$url,$ext,$type)=split(/\:/,$_);
                   1196:                       my $idx=&Apache::lonratedt::getresidx($url);
                   1197:                       $Apache::lonratedt::resources[$idx]=$_;
                   1198:                       $Apache::lonratedt::order
                   1199: 		          [$#Apache::lonratedt::order+1]=$idx;
                   1200: 	          }
1.53      www      1201: # Store the changed version
1.223     www      1202:   	          ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.142     raeburn  1203: 					   $folder.'.'.$container);
1.223     www      1204: 	          if ($fatal) {
                   1205: 		      $r->print('<p><font color="red">'.$errtext.'</font></p>');
                   1206: 		      return;
                   1207: 	          }
                   1208:                } else {
                   1209:                    $r->print('<p><font color="red">'.&mt('No map selected.').'</font></p>');
                   1210:                }
1.53      www      1211:            }
1.16      www      1212:        }
                   1213: # ---------------------------------------------------------------- End commands
1.7       www      1214: # ---------------------------------------------------------------- Print screen
1.10      www      1215:         my $idx=0;
1.148     www      1216: 	my $shown=0;
1.10      www      1217:         $r->print('<table>');
                   1218:         foreach (@Apache::lonratedt::order) {
                   1219:            my ($name,$url)=split(/\:/,$Apache::lonratedt::resources[$_]);
1.207     albertel 1220: 	   $name=&Apache::lonratsrv::qtescape($name);
                   1221: 	   $url=&Apache::lonratsrv::qtescape($url);
1.10      www      1222:            unless ($name) {  $name=(split(/\//,$url))[-1]; }
1.148     www      1223:            unless ($name) { $idx++; next; }
1.112     raeburn  1224:            $r->print(&entryline($idx,$name,$url,$folder,$allowed,$_,$coursenum));
1.10      www      1225:            $idx++;
1.148     www      1226: 	   $shown++;
1.10      www      1227:         }
1.148     www      1228: 	unless ($shown) {
1.131     www      1229: 	    $r->print('<tr><td>'.&mt('Currently no documents.').'</td></tr>');
                   1230: 	}
1.168     www      1231:         $r->print("\n</table>\n");
1.174     albertel 1232: 	if ($env{'form.markedcopy_url'}) {
1.168     www      1233: 	    $r->print(<<ENDPASTE);
                   1234: <p><form name="pasteform" action="/adm/coursedocs" method="post">
1.174     albertel 1235: <input type="hidden" name="markedcopy_url" value="$env{'form.markedcopy_url'}" />
                   1236: <input type="hidden" name="markedcopy_title" value="$env{'form.markedcopy_title'}" />
1.168     www      1237: ENDPASTE
                   1238:             $r->print(
                   1239: 	   '<input type="submit" name="pastemarked" value="'.&mt('Paste').
                   1240: 		      '" /> '.&Apache::loncommon::filedescription(
1.174     albertel 1241: 		(split(/\./,$env{'form.markedcopy_url'}))[-1]).': '.
                   1242: 		      $env{'form.markedcopy_title'});
1.168     www      1243:             if ($container eq 'page') {
                   1244: 		$r->print(<<PAGEINFO);
1.174     albertel 1245: <input type="hidden" name="pagepath" value="$env{'form.pagepath'}" />
                   1246: <input type="hidden" name="pagesymb" value="$env{'form.pagesymb'}" />
1.168     www      1247: PAGEINFO
                   1248:             } else {
                   1249: 		$r->print(<<FOLDERINFO);
1.174     albertel 1250: <input type="hidden" name="folderpath" value="$env{'form.folderpath'}" />
1.168     www      1251: FOLDERINFO
                   1252: 	    }
                   1253: 	    $r->print('</form></p>');
                   1254: 	}
1.7       www      1255:     }
                   1256: }
1.1       www      1257: 
1.188     raeburn  1258: sub process_file_upload {
1.194     raeburn  1259:     my ($upload_output,$coursenum,$coursedom,$allfiles,$codebase,$uploadcmd) = @_;
1.188     raeburn  1260: # upload a file, if present
                   1261:     my $parseaction;
1.190     albertel 1262:    if ($env{'form.parserflag'}) {
1.188     raeburn  1263:         $parseaction = 'parse';
                   1264:     }
                   1265:     my $phase_status;
                   1266:     my $folder=$env{'form.folder'};
1.194     raeburn  1267:     if ($folder eq '') {
1.188     raeburn  1268:         $folder='default';
                   1269:     }
1.194     raeburn  1270:     if ( ($folder=~/^$uploadcmd/) || ($uploadcmd eq 'default') ) {
1.188     raeburn  1271:         my $errtext='';
                   1272:         my $fatal=0;
                   1273:         my $container='sequence';
                   1274:         if ($env{'form.pagepath'}) {
                   1275:             $container='page';
                   1276:         }
                   1277:         ($errtext,$fatal)=
                   1278:               &mapread($coursenum,$coursedom,$folder.'.'.$container);
                   1279:         if ($#Apache::lonratedt::order<1) {
                   1280:             $Apache::lonratedt::order[0]=1;
                   1281:             $Apache::lonratedt::resources[1]='';
                   1282:         }
                   1283:         if ($fatal) {
                   1284:             return 'failed';
                   1285:         }
                   1286:         my $destination = 'docs/';
1.194     raeburn  1287:         if ($folder =~ /^supplemental/) {
                   1288:             $destination = 'supplemental/';
                   1289:         }
                   1290:         if (($folder eq 'default') || ($folder eq 'supplemental')) {
1.188     raeburn  1291:             $destination .= 'default/';
1.194     raeburn  1292:         } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
                   1293:             $destination .=  $2.'/';
1.188     raeburn  1294:         }
                   1295: # this is for a course, not a user, so set coursedoc flag
                   1296: # probably the only place in the system where this should be "1"
                   1297:         my $newidx=&Apache::lonratedt::getresidx();
                   1298:         $destination .= $newidx;
1.190     albertel 1299:         my $url=&Apache::lonnet::userfileupload('uploaddoc',1,$destination,
                   1300: 						$parseaction,$allfiles,
                   1301: 						$codebase);
1.188     raeburn  1302:         my $ext='false';
                   1303:         if ($url=~/^http\:\/\//) { $ext='true'; }
                   1304:         $url=~s/\:/\&colon;/g;
                   1305:         my $comment=$env{'form.comment'};
                   1306:         $comment=~s/\</\&lt\;/g;
                   1307:         $comment=~s/\>/\&gt\;/g;
                   1308:         $comment=~s/\:/\&colon;/g;
                   1309:         if ($folder=~/^supplemental/) {
                   1310:               $comment=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
                   1311:                   $env{'user.domain'}.'___&&&___'.$comment;
                   1312:         }
                   1313: 
                   1314:         $Apache::lonratedt::resources[$newidx]=
                   1315:                   $comment.':'.$url.':'.$ext.':normal:res';
1.190     albertel 1316:         $Apache::lonratedt::order[$#Apache::lonratedt::order+1]= $newidx;
                   1317:         ($errtext,$fatal)=&storemap($coursenum,$coursedom,
                   1318: 				    $folder.'.'.$container);
1.188     raeburn  1319:         if ($fatal) {
                   1320:             $$upload_output .= '<p><font color="red">'.$errtext.'</font></p>';
                   1321:             return 'failed';
                   1322:         } else {
                   1323:             if ($parseaction eq 'parse') {
1.190     albertel 1324:                 my $total_embedded = keys(%{$allfiles});
1.188     raeburn  1325:                 if ($total_embedded > 0) {
                   1326:                     my $num = 0;
                   1327:                     $$upload_output .= 'This file contains embedded multimedia objects, which need to be uploaded to LON-CAPA.<br />
                   1328:    <form name="upload_embedded" action="/adm/coursedocs"
                   1329:                   method="post" enctype="multipart/form-data">
                   1330:    <input type="hidden" name="folderpath" value="'.$env{'form.folderpath'}.'" />   <input type="hidden" name="cmd" value="upload_embedded" />
                   1331:    <input type="hidden" name="newidx" value="'.$newidx.'" />
1.228     www      1332:    <input type="hidden" name="primaryurl" value="'.&escape($url).'" />
1.188     raeburn  1333:    <input type="hidden" name="phasetwo" value="'.$total_embedded.'" />';
                   1334:                     $$upload_output .= '<b>Upload embedded files</b>:<br />
                   1335:    <table>';
1.190     albertel 1336:                     foreach my $embed_file (keys(%{$allfiles})) {
1.188     raeburn  1337:                         $$upload_output .= '<tr><td>'.$embed_file.
1.190     albertel 1338:           '<input name="embedded_item_'.$num.'" type="file" />
1.228     www      1339:            <input name="embedded_orig_'.$num.'" type="hidden" value="'.&escape($embed_file).'" />';
1.188     raeburn  1340:                         my $attrib;
                   1341:                         if (@{$$allfiles{$embed_file}} > 1) {
                   1342:                             $attrib = join(':',@{$$allfiles{$embed_file}});
                   1343:                         } else {
                   1344:                             $attrib = $$allfiles{$embed_file}[0];
                   1345:                         }
                   1346:                         $$upload_output .=
                   1347:            '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.$attrib.'" />';
                   1348:                         if (exists($$codebase{$embed_file})) {
                   1349:                             $$upload_output .= 
1.228     www      1350:           '<input name="codebase_'.$num.'" type="hidden" value="'.&escape($$codebase{$embed_file}).'" />';
1.188     raeburn  1351:                         }
                   1352:                         $$upload_output .= '</td></tr>';
                   1353:                         $num ++;
                   1354:                     }
                   1355:                     $phase_status = 'phasetwo';
                   1356:                     $$upload_output .= '</table><br />
                   1357:    <input type ="submit" value="Complete upload" />
                   1358:    </form>';
                   1359:                 } else {
                   1360:                     $$upload_output .= 'No embedded items identified<br />';
                   1361:                 }
                   1362:             }
                   1363:         }
                   1364:     }
                   1365:     return $phase_status;
                   1366: }
                   1367: 
                   1368: sub process_secondary_uploads {
                   1369:     my ($upload_output,$coursedom,$coursenum,$formname,$num,$newidx) = @_;
                   1370:     my $folder=$env{'form.folder'};
                   1371:     my $destination = 'docs/';
1.195     raeburn  1372:     if ($folder =~ /^supplemental/) {
                   1373:         $destination = 'supplemental/';
                   1374:     }
                   1375:     if (($folder eq 'default') || ($folder eq 'supplemental')) {
1.188     raeburn  1376:         $destination .= 'default/';
1.195     raeburn  1377:     } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
1.217     raeburn  1378:         $destination .=  $2.'/';
1.188     raeburn  1379:     }
                   1380:     $destination .= $newidx;
                   1381:     my ($url,$filename);
                   1382:     $url=&Apache::lonnet::userfileupload($formname.$num,1,$destination);
                   1383:     ($filename) = ($url =~ m-^/uploaded/$coursedom/$coursenum/$destination/(.+)$-);
                   1384:     return $filename;
                   1385: }
                   1386: 
1.8       www      1387: # --------------------------------------------------------------- An entry line
                   1388: 
                   1389: sub entryline {
1.112     raeburn  1390:     my ($index,$title,$url,$folder,$allowed,$residx,$coursenum)=@_;
1.38      www      1391:     $title=~s/\&colon\;/\:/g;
                   1392:     $title=&HTML::Entities::encode(&HTML::Entities::decode(
1.228     www      1393:      &unescape($title)),'"<>&\'');
1.38      www      1394:     my $renametitle=$title;
                   1395:     my $foldertitle=$title;
1.142     raeburn  1396:     my $pagetitle=$title;
1.122     www      1397:     my $orderidx=$Apache::lonratedt::order[$index];
1.109     albertel 1398:     if ($title=~ /^(\d+)___&amp;&amp;&amp;___(\w+)___&amp;&amp;&amp;___(\w+)___&amp;&amp;&amp;___(.*)$/	) { 
                   1399: 	$foldertitle=&Apache::lontexconvert::msgtexconverted($4);
                   1400: 	$renametitle=$4;
                   1401: 	$title='<i>'.&Apache::lonlocal::locallocaltime($1).'</i> '.
                   1402: 	    &Apache::loncommon::plainname($2,$3).': <br />'.
                   1403: 	    $foldertitle;
                   1404:     }
1.222     albertel 1405:     $renametitle=~s/\\/\\\\/g;
1.38      www      1406:     $renametitle=~s/\&quot\;/\\\"/g;
1.8       www      1407:     my $line='<tr>';
                   1408: # Edit commands
1.142     raeburn  1409:     my $container;
1.120     www      1410:     my $folderpath;
1.174     albertel 1411:     if ($env{'form.folderpath'}) {
1.142     raeburn  1412:         $container = 'sequence';
1.228     www      1413: 	$folderpath=&escape($env{'form.folderpath'});
1.174     albertel 1414: 	# $htmlfoldername=&HTML::Entities::encode($env{'form.foldername'},'<>&"');
1.120     www      1415:     }
1.156     albertel 1416:     my ($pagepath,$pagesymb);
1.174     albertel 1417:     if ($env{'form.pagepath'}) {
1.142     raeburn  1418:         $container = 'page';
1.228     www      1419:         $pagepath=&escape($env{'form.pagepath'});
                   1420:         $pagesymb=&escape($env{'form.pagesymb'});
1.142     raeburn  1421:     }
1.168     www      1422:     my $cpinfo='';
1.174     albertel 1423:     if ($env{'form.markedcopy_url'}) {
1.168     www      1424:        $cpinfo='&markedcopy_url='.
1.228     www      1425:                &escape($env{'form.markedcopy_url'}).
1.168     www      1426:                '&markedcopy_title='.
1.228     www      1427:                &escape($env{'form.markedcopy_title'});
1.168     www      1428:     }
1.109     albertel 1429:     if ($allowed) {
1.123     www      1430: 	my $incindex=$index+1;
                   1431: 	my $selectbox='';
1.168     www      1432: 	if (($folder!~/^supplemental/) &&
                   1433: 	    ($#Apache::lonratedt::order>0) && 
                   1434: 	    ((split(/\:/,
                   1435: 	     $Apache::lonratedt::resources[$Apache::lonratedt::order[0]]))[1] 
                   1436: 	     ne '') && 
                   1437: 	    ((split(/\:/,
                   1438: 	     $Apache::lonratedt::resources[$Apache::lonratedt::order[1]]))[1] 
                   1439: 	     ne '')) {
1.123     www      1440: 	    $selectbox=
1.124     www      1441: 		'<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
1.123     www      1442: 		'<select name="newpos" onChange="this.form.submit()">';
                   1443: 	    for (my $i=1;$i<=$#Apache::lonratedt::order+1;$i++) {
                   1444: 		if ($i==$incindex) {
                   1445: 		    $selectbox.='<option value="" selected="1">('.$i.')</option>';
                   1446: 		} else {
                   1447: 		    $selectbox.='<option value="'.$i.'">'.$i.'</option>';
                   1448: 		}
                   1449: 	    }
                   1450: 	    $selectbox.='</select>';
                   1451: 	}
1.119     www      1452: 	my %lt=&Apache::lonlocal::texthash(
                   1453:                 'up' => 'Move Up',
1.109     albertel 1454: 		'dw' => 'Move Down',
                   1455: 		'rm' => 'Remove',
1.171     www      1456:                 'ct' => 'Cut',
1.168     www      1457: 		'rn' => 'Rename',
                   1458: 		'cp' => 'Copy');
1.211     www      1459: 	my $nocopy=0;
                   1460:         if ($url=~/\.(page|sequence)$/) {
                   1461: 	    foreach (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$url))) {
                   1462: 		my ($title,$url,$ext,$type)=split(/\:/,$_);
                   1463: 		if (($url=~/\.(page|sequence)/) && ($type ne 'zombie')) {
                   1464: 		    $nocopy=1;
                   1465: 		    last;
                   1466: 		}
                   1467: 	    }
                   1468: 	}
                   1469:         my $copylink='&nbsp;';
1.174     albertel 1470:         if ($env{'form.pagepath'}) {
1.211     www      1471:            unless ($nocopy) {
                   1472:                $copylink=(<<ENDCOPY);
                   1473: <a href='javascript:markcopy("$pagepath","$index","$renametitle","page","$pagesymb");'>
                   1474: <font size="-2" color="#000099">$lt{'cp'}</font></a></td>
                   1475: ENDCOPY
                   1476:             }
1.142     raeburn  1477:             $line.=(<<END);
                   1478: <form name="entry_$index" action="/adm/coursedocs" method="post">
1.174     albertel 1479: <input type="hidden" name="pagepath" value="$env{'form.pagepath'}" />
                   1480: <input type="hidden" name="pagesymb" value="$env{'form.pagesymb'}" />
                   1481: <input type="hidden" name="markedcopy_url" value="$env{'form.markedcopy_url'}" />
                   1482: <input type="hidden" name="markedcopy_title" value="$env{'form.markedcopy_title'}" />
1.142     raeburn  1483: <input type="hidden" name="setparms" value="$orderidx" />
                   1484: <td><table border='0' cellspacing='2' cellpadding='0'>
                   1485: <tr><td bgcolor="#DDDDDD">
1.168     www      1486: <a href='/adm/coursedocs?cmd=up_$index&pagepath=$pagepath&pagesymb=$pagesymb$cpinfo'>
1.142     raeburn  1487: <img src="${iconpath}move_up.gif" alt='$lt{'up'}' border='0' /></a></td></tr>
                   1488: <tr><td bgcolor="#DDDDDD">
1.168     www      1489: <a href='/adm/coursedocs?cmd=down_$index&pagepath=$pagepath&pagesymb=$pagesymb$cpinfo'>
1.142     raeburn  1490: <img src="${iconpath}move_down.gif" alt='$lt{'dw'}' border='0' /></a></td></tr>
                   1491: </table></td>
                   1492: <td>$selectbox
                   1493: </td><td bgcolor="#DDDDDD">
1.156     albertel 1494: <a href='javascript:removeres("$pagepath","$index","$renametitle","page","$pagesymb");'>
1.142     raeburn  1495: <font size="-2" color="#990000">$lt{'rm'}</font></a>
1.171     www      1496: <a href='javascript:cutres("$pagepath","$index","$renametitle","page","$pagesymb");'>
                   1497: <font size="-2" color="#550044">$lt{'ct'}</font></a>
1.213     albertel 1498: <a href='javascript:changename("$pagepath","$index","$renametitle","page","$pagesymb");'>
1.168     www      1499: <font size="-2" color="#009900">$lt{'rn'}</font></a>
1.211     www      1500: $copylink
1.142     raeburn  1501: END
                   1502:         } else {
1.211     www      1503:            unless ($nocopy) {
                   1504:                $copylink=(<<ENDCOPY);
                   1505: <a href='javascript:markcopy("$folderpath","$index","$renametitle","sequence");'>
                   1506: <font size="-2" color="#000099">$lt{'cp'}</font></a></td>
                   1507: ENDCOPY
                   1508:             }
1.142     raeburn  1509:             $line.=(<<END); 
1.121     www      1510: <form name="entry_$index" action="/adm/coursedocs" method="post">
1.174     albertel 1511: <input type="hidden" name="folderpath" value="$env{'form.folderpath'}" />
                   1512: <input type="hidden" name="markedcopy_url" value="$env{'form.markedcopy_url'}" />
                   1513: <input type="hidden" name="markedcopy_title" value="$env{'form.markedcopy_title'}" />
1.122     www      1514: <input type="hidden" name="setparms" value="$orderidx" />
1.54      www      1515: <td><table border='0' cellspacing='2' cellpadding='0'>
                   1516: <tr><td bgcolor="#DDDDDD">
1.168     www      1517: <a href='/adm/coursedocs?cmd=up_$index&folderpath=$folderpath$cpinfo'>
1.90      www      1518: <img src="${iconpath}move_up.gif" alt='$lt{'up'}' border='0' /></a></td></tr>
1.54      www      1519: <tr><td bgcolor="#DDDDDD">
1.168     www      1520: <a href='/adm/coursedocs?cmd=down_$index&folderpath=$folderpath$cpinfo'>
1.90      www      1521: <img src="${iconpath}move_down.gif" alt='$lt{'dw'}' border='0' /></a></td></tr>
1.123     www      1522: </table></td>
                   1523: <td>$selectbox
                   1524: </td><td bgcolor="#DDDDDD">
1.142     raeburn  1525: <a href='javascript:removeres("$folderpath","$index","$renametitle","sequence");'>
1.90      www      1526: <font size="-2" color="#990000">$lt{'rm'}</font></a>
1.171     www      1527: <a href='javascript:cutres("$folderpath","$index","$renametitle","sequence");'>
                   1528: <font size="-2" color="#550044">$lt{'ct'}</font></a>
1.142     raeburn  1529: <a href='javascript:changename("$folderpath","$index","$renametitle","sequence");'>
1.168     www      1530: <font size="-2" color="#009900">$lt{'rn'}</font></a>
1.211     www      1531: $copylink
1.8       www      1532: END
1.142     raeburn  1533:         }
1.8       www      1534:     }
1.16      www      1535: # Figure out what kind of a resource this is
                   1536:     my ($extension)=($url=~/\.(\w+)$/);
                   1537:     my $uploaded=($url=~/^\/*uploaded\//);
1.97      albertel 1538:     my $icon=&Apache::loncommon::icon($url);
1.17      www      1539:     my $isfolder=0;
1.142     raeburn  1540:     my $ispage=0;
1.114     albertel 1541:     my $folderarg;
1.142     raeburn  1542:     my $pagearg;
                   1543:     my $pagefile;
1.16      www      1544:     if ($uploaded) {
1.135     albertel 1545: 	if ($extension eq 'sequence') {
                   1546: 	    $icon=$iconpath.'/folder_closed.gif';
                   1547: 	    $url=~/$coursenum\/([\/\w]+)\.sequence$/;
                   1548: 	    $url='/adm/coursedocs?';
                   1549: 	    $folderarg=$1;
                   1550: 	    $isfolder=1;
1.142     raeburn  1551:         } elsif ($extension eq 'page') {
                   1552:             $icon=$iconpath.'/page.gif';
                   1553:             $url=~/$coursenum\/([\/\w]+)\.page$/;
                   1554:             $pagearg=$1;
                   1555:             $url='/adm/coursedocs?';
                   1556:             $ispage=1;
1.135     albertel 1557: 	} else {
                   1558: 	    &Apache::lonnet::allowuploaded('/adm/coursedoc',$url);
                   1559: 	}
1.16      www      1560:     }
1.215     albertel 1561:     $url=~s-^http(\&colon\;|:)//-/adm/wrapper/ext/-;
1.142     raeburn  1562:     if ((!$isfolder) && ($residx) && ($folder!~/supplemental/) && (!$ispage)) {
1.113     albertel 1563: 	my $symb=&Apache::lonnet::symbclean(
1.50      www      1564:           &Apache::lonnet::declutter('uploaded/'.
1.174     albertel 1565:            $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
                   1566:            $env{'course.'.$env{'request.course.id'}.'.num'}.'/'.$folder.
1.50      www      1567:            '.sequence').
                   1568:            '___'.$residx.'___'.
1.113     albertel 1569: 	   &Apache::lonnet::declutter($url));
                   1570: 	(undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
                   1571: 	$url=&Apache::lonnet::clutter($url);
1.127     albertel 1572: 	if ($url=~/^\/*uploaded\//) {
                   1573: 	    $url=~/\.(\w+)$/;
                   1574: 	    my $embstyle=&Apache::loncommon::fileembstyle($1);
                   1575: 	    if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
                   1576: 		$url='/adm/wrapper'.$url;
                   1577: 	    } elsif ($embstyle eq 'ssi') {
                   1578: 		#do nothing with these
                   1579: 	    } elsif ($url!~/\.(sequence|page)$/) {
                   1580: 		$url='/adm/coursedocs/showdoc'.$url;
                   1581: 	    }
1.145     albertel 1582: 	} elsif ($url=~m|^/ext/|) { 
                   1583: 	    $url='/adm/wrapper'.$url;
1.127     albertel 1584: 	}
1.228     www      1585: 	$url.=(($url=~/\?/)?'&':'?').'symb='.&escape($symb);
1.152     albertel 1586: 	if ($container eq 'page') {
1.174     albertel 1587: 	    my $symb=$env{'form.pagesymb'};
1.152     albertel 1588: 	    	    
                   1589: 	    $url=&Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
1.228     www      1590: 	    $url.=(($url=~/\?/)?'&':'?').'symb='.&escape($symb);
1.152     albertel 1591: 	}
1.50      www      1592:     }
1.120     www      1593:     my $parameterset='&nbsp;';
1.216     albertel 1594:     if ($isfolder || $extension eq 'sequence') {
1.228     www      1595: 	my $foldername=&escape($foldertitle);
1.174     albertel 1596: 	my $folderpath=$env{'form.folderpath'};
1.114     albertel 1597: 	if ($folderpath) { $folderpath.='&' };
                   1598: 	$folderpath.=$folderarg.'&'.$foldername;
1.228     www      1599: 	$url.='folderpath='.&escape($folderpath).$cpinfo;
1.147     matthew  1600: 	$parameterset='<label>'.&mt('Randomly Pick: ').
1.165     www      1601: 	    '<input type="text" size="4" onChange="this.form.submit()" name="randpick_'.$orderidx.'" value="'.
1.147     matthew  1602: 	    (&Apache::lonratedt::getparameter($orderidx,
                   1603:                                               'parameter_randompick'))[0].
1.165     www      1604:                                               '" />'.
                   1605: '<font size="-2"><a href="javascript:void(0)">'.&mt('Store').'</a></font></label>';
1.147     matthew  1606:        
1.114     albertel 1607:     }
1.142     raeburn  1608:     if ($ispage) {
1.228     www      1609:         my $pagename=&escape($pagetitle);
1.142     raeburn  1610:         my $pagepath;
1.174     albertel 1611:         my $folderpath=$env{'form.folderpath'};
1.142     raeburn  1612:         if ($folderpath) { $pagepath = $folderpath.'&' };
                   1613:         $pagepath.=$pagearg.'&'.$pagename;
1.174     albertel 1614: 	my $symb=$env{'form.pagesymb'};
1.152     albertel 1615: 	if (!$symb) {
                   1616: 	    my $path='uploaded/'.
1.174     albertel 1617: 		$env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
                   1618: 		$env{'course.'.$env{'request.course.id'}.'.num'}.'/';
1.152     albertel 1619: 	    $symb=&Apache::lonnet::encode_symb($path.$folder.'.sequence',
                   1620: 					       $residx,
                   1621: 					       $path.$pagearg.'.page');
                   1622: 	}
1.228     www      1623: 	$url.='pagepath='.&escape($pagepath).
                   1624: 	    '&pagesymb='.&escape($symb).$cpinfo;
1.142     raeburn  1625:     }
1.113     albertel 1626:     $line.='<td bgcolor="#FFFFBB"><a href="'.$url.'"><img src="'.$icon.
                   1627: 	'" border="0"></a></td>'.
1.212     foxr     1628:         "<td bgcolor='#FFFFBB'><a href=\"$url\">$title</a></td>";
1.120     www      1629:     if (($allowed) && ($folder!~/^supplemental/)) {
                   1630:  	my %lt=&Apache::lonlocal::texthash(
                   1631:  			      'hd' => 'Hidden',
1.165     www      1632:  			      'ec' => 'URL hidden');
1.122     www      1633: 	my $enctext=
                   1634: 	    ((&Apache::lonratedt::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i?' checked="1"':'');
                   1635: 	my $hidtext=
                   1636: 	    ((&Apache::lonratedt::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i?' checked="1"':'');
1.120     www      1637: 	$line.=(<<ENDPARMS);
                   1638: <td bgcolor="#BBBBFF"><font size='-2'>
1.165     www      1639: <nobr><label><input type="checkbox" name="hidprs_$orderidx" onClick="this.form.submit()" $hidtext /> $lt{'hd'}</label></nobr></td>
1.149     albertel 1640: <td bgcolor="#BBBBFF"><font size='-2'>
1.165     www      1641: <nobr><label><input type="checkbox" name="encprs_$orderidx" onClick="this.form.submit()" $enctext /> $lt{'ec'}</label></nobr></td>
1.120     www      1642: <td bgcolor="#BBBBFF"><font size="-2">$parameterset</font></td>
                   1643: ENDPARMS
1.119     www      1644:     }
1.120     www      1645:     $line.="</form></tr>";
1.8       www      1646:     return $line;
                   1647: }
                   1648: 
1.27      www      1649: # ---------------------------------------------------------------- tie the hash
                   1650: 
                   1651: sub tiehash {
1.136     albertel 1652:     my ($mode)=@_;
1.27      www      1653:     $hashtied=0;
1.174     albertel 1654:     if ($env{'request.course.fn'}) {
1.136     albertel 1655: 	if ($mode eq 'write') {
1.174     albertel 1656: 	    if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
1.136     albertel 1657: 		    &GDBM_WRCREAT(),0640)) {
                   1658:                 $hashtied=2;
                   1659: 	    }
                   1660: 	} else {
1.174     albertel 1661: 	    if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
1.136     albertel 1662: 		    &GDBM_READER(),0640)) {
1.27      www      1663:                 $hashtied=1;
1.136     albertel 1664: 	    }
                   1665: 	}
1.27      www      1666:     }    
                   1667: }
                   1668: 
                   1669: sub untiehash {
                   1670:     if ($hashtied) { untie %hash; }
                   1671:     $hashtied=0;
1.221     albertel 1672:     return OK;
1.27      www      1673: }
                   1674: 
1.29      www      1675: # --------------------------------------------------------------- check on this
                   1676: 
                   1677: sub checkonthis {
                   1678:     my ($r,$url,$level,$title)=@_;
1.228     www      1679:     $url=&unescape($url);
1.29      www      1680:     $alreadyseen{$url}=1;
                   1681:     $r->rflush();
1.41      www      1682:     if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
1.108     albertel 1683:        $r->print("\n<br />");
1.29      www      1684:        for (my $i=0;$i<=$level*5;$i++) {
                   1685:            $r->print('&nbsp;');
                   1686:        }
                   1687:        $r->print('<a href="'.$url.'" target="cat">'.
                   1688: 		 ($title?$title:$url).'</a> ');
                   1689:        if ($url=~/^\/res\//) {
                   1690: 	  my $result=&Apache::lonnet::repcopy(
                   1691:                               &Apache::lonnet::filelocation('',$url));
1.172     raeburn  1692:           if ($result eq 'ok') {
1.87      www      1693:              $r->print('<font color="green">'.&mt('ok').'</font>');
1.29      www      1694:              $r->rflush();
1.34      www      1695:              &Apache::lonnet::countacc($url);
                   1696:              $url=~/\.(\w+)$/;
                   1697:              if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
                   1698: 		 $r->print('<br />');
                   1699:                  $r->rflush();
                   1700:                  for (my $i=0;$i<=$level*5;$i++) {
                   1701:                      $r->print('&nbsp;');
                   1702:                  }
1.84      www      1703:                  $r->print('- '.&mt('Rendering').': ');
1.170     www      1704: 		 my ($errorcount,$warningcount)=split(/:/,
                   1705: 	       &Apache::lonnet::ssi_body($url,
1.173     albertel 1706: 			       ('grade_target'=>'web',
                   1707: 				'return_only_error_and_warning_counts' => 1)));
1.170     www      1708:                  if (($errorcount) ||
                   1709:                      ($warningcount)) {
                   1710: 		     if ($errorcount) {
1.98      www      1711:                         $r->print('<img src="/adm/lonMisc/bomb.gif" /><font color="red"><b>'.
1.170     www      1712: 			  $errorcount.' '.
1.87      www      1713: 				  &mt('error(s)').'</b></font> ');
1.34      www      1714:                      }
1.170     www      1715: 		     if ($warningcount) {
1.34      www      1716:                         $r->print('<font color="blue">'.
1.170     www      1717: 			  $warningcount.' '.
1.84      www      1718: 				  &mt('warning(s)').'</font>');
1.34      www      1719:                      }
                   1720:                  } else {
1.87      www      1721:                      $r->print('<font color="green">'.&mt('ok').'</font>');
1.34      www      1722:                  }
                   1723:                  $r->rflush();
                   1724:              }
1.29      www      1725: 	     my $dependencies=
                   1726:                 &Apache::lonnet::metadata($url,'dependencies');
                   1727:              foreach (split(/\,/,$dependencies)) {
                   1728: 		 if (($_=~/^\/res\//) && (!$alreadyseen{$_})) {
                   1729:                     &checkonthis($r,$_,$level+1);
                   1730:                  }
                   1731:              }
1.172     raeburn  1732:           } elsif ($result eq 'unavailable') {
1.84      www      1733:              $r->print('<font color="red"><b>'.&mt('connection down').'</b></font>');
1.172     raeburn  1734:           } elsif ($result eq 'not_found') {
1.100     www      1735: 	      unless ($url=~/\$/) {
                   1736: 		  $r->print('<font color="red"><b>'.&mt('not found').'</b></font>');
                   1737: 	      } else {
                   1738: 		  $r->print('<font color="yellow"><b>'.&mt('unable to verify variable URL').'</b></font>');
                   1739: 	      }
1.29      www      1740:           } else {
1.84      www      1741:              $r->print('<font color="red"><b>'.&mt('access denied').'</b></font>');
1.29      www      1742:           }
                   1743:       }
                   1744:    }
                   1745: }
                   1746: 
1.1       www      1747: 
1.75      www      1748: #
1.208     albertel 1749: # ----------------------------------------------------------------- List Symbs
                   1750: # 
                   1751: sub list_symbs {
1.224     albertel 1752:     my ($r) = @_;
                   1753: 
                   1754:     $r->print(&Apache::loncommon::start_page('Symb List'));
                   1755:     my $navmap = Apache::lonnavmaps::navmap->new();
                   1756:     $r->print("<pre>\n");
                   1757:     foreach my $res ($navmap->retrieveResources()) {
                   1758: 	$r->print($res->compTitle()."\t".$res->symb()."\n");
                   1759:     }
                   1760:     $r->print("\n</pre>\n");
                   1761:     $r->print('<a href="/adm/coursedocs">'.&mt('Return to DOCS').'</a>');
1.208     albertel 1762: }
                   1763: 
                   1764: 
                   1765: #
1.75      www      1766: # -------------------------------------------------------------- Verify Content
                   1767: # 
                   1768: sub verifycontent {
1.224     albertel 1769:     my ($r) = @_;
1.230     albertel 1770:     my $type = &Apache::loncommon::course_type();
1.26      www      1771:    my $loaderror=&Apache::lonnet::overloaderror($r);
                   1772:    if ($loaderror) { return $loaderror; }
1.229     raeburn  1773:    $r->print(&Apache::loncommon::start_page('Verify '.$type.' Documents'));
1.27      www      1774:    $hashtied=0;
1.30      www      1775:    undef %alreadyseen;
                   1776:    %alreadyseen=();
1.27      www      1777:    &tiehash();
                   1778:    foreach (keys %hash) {
1.140     www      1779:        if ($hash{$_}=~/\.(page|sequence)$/) {
1.228     www      1780: 	   if (($_=~/^src_/) && ($alreadyseen{&unescape($hash{$_})})) {
1.140     www      1781: 	       $r->print('<hr /><font color="red">'.
1.230     albertel 1782: 			 &mt('The following sequence or page is included more than once in your '.$type.': ').
1.228     www      1783: 			 &unescape($hash{$_}).'</font><br />'.
1.140     www      1784: 			 &mt('Note that grading records for problems included in this sequence or folder will overlap.<hr />'));
                   1785: 	   }
                   1786:        }
1.228     www      1787:        if (($_=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$_})})) {
1.29      www      1788:            &checkonthis($r,$hash{$_},0,$hash{'title_'.$1});
1.27      www      1789:        }
                   1790:    }
                   1791:    &untiehash();
1.108     albertel 1792:    $r->print('<h1>'.&mt('Done').'.</h1>'.'<a href="/adm/coursedocs">'.
                   1793: 	     &mt('Return to DOCS').'</a>');
1.75      www      1794: }
                   1795: 
1.192     www      1796: 
1.75      www      1797: # -------------------------------------------------------------- Check Versions
                   1798: 
1.192     www      1799: sub devalidateversioncache {
                   1800:     my $src=shift;
                   1801:     &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
                   1802: 					  &Apache::lonnet::clutter($src));
                   1803: }
                   1804: 
1.75      www      1805: sub checkversions {
1.224     albertel 1806:     my ($r) = @_;
1.230     albertel 1807:     my $type = &Apache::loncommon::course_type();
1.229     raeburn  1808:     $r->print(&Apache::loncommon::start_page("Check $type Document Versions"));
1.89      www      1809:     my $header='';
                   1810:     my $startsel='';
                   1811:     my $monthsel='';
                   1812:     my $weeksel='';
                   1813:     my $daysel='';
                   1814:     my $allsel='';
                   1815:     my %changes=();
                   1816:     my $starttime=0;
1.91      www      1817:     my $haschanged=0;
1.92      www      1818:     my %setversions=&Apache::lonnet::dump('resourceversions',
1.174     albertel 1819: 			  $env{'course.'.$env{'request.course.id'}.'.domain'},
                   1820: 			  $env{'course.'.$env{'request.course.id'}.'.num'});
1.92      www      1821: 
                   1822:     $hashtied=0;
                   1823:     &tiehash();
                   1824:     my %newsetversions=();
1.174     albertel 1825:     if ($env{'form.setmostrecent'}) {
1.91      www      1826: 	$haschanged=1;
1.92      www      1827: 	foreach (keys %hash) {
                   1828: 	    if ($_=~/^ids\_(\/res\/.+)$/) {
1.93      www      1829: 		$newsetversions{$1}='mostrecent';
1.192     www      1830:                 &devalidateversioncache($1);
1.92      www      1831: 	    }
                   1832: 	}
1.174     albertel 1833:     } elsif ($env{'form.setcurrent'}) {
1.91      www      1834: 	$haschanged=1;
1.92      www      1835: 	foreach (keys %hash) {
                   1836: 	    if ($_=~/^ids\_(\/res\/.+)$/) {
1.93      www      1837: 		my $getvers=&Apache::lonnet::getversion($1);
                   1838: 		if ($getvers>0) {
                   1839: 		    $newsetversions{$1}=$getvers;
1.192     www      1840: 		    &devalidateversioncache($1);
1.93      www      1841: 		}
1.92      www      1842: 	    }
                   1843: 	}
1.174     albertel 1844:     } elsif ($env{'form.setversions'}) {
1.91      www      1845: 	$haschanged=1;
1.174     albertel 1846: 	foreach (keys %env) {
1.92      www      1847: 	    if ($_=~/^form\.set_version_(.+)$/) {
                   1848: 		my $src=$1;
1.174     albertel 1849: 		if (($env{$_}) && ($env{$_} ne $setversions{$src})) {
                   1850: 		    $newsetversions{$src}=$env{$_};
1.192     www      1851: 		    &devalidateversioncache($src);
1.92      www      1852: 		}
                   1853: 	    }
                   1854: 	}
1.91      www      1855:     }
                   1856:     if ($haschanged) {
1.92      www      1857:         if (&Apache::lonnet::put('resourceversions',\%newsetversions,
1.174     albertel 1858: 			  $env{'course.'.$env{'request.course.id'}.'.domain'},
                   1859: 			  $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {		
1.92      www      1860: 	    $r->print('<h1>'.&mt('Your Version Settings have been Stored').'</h1>');
                   1861: 	} else {
                   1862: 	    $r->print('<h1><font color="red">'.&mt('An Error Occured while Attempting to Store your Version Settings').'</font></h1>');
                   1863: 	}
1.136     albertel 1864: 	&mark_hash_old();
1.91      www      1865:     }
1.136     albertel 1866:     &changewarning($r,'');
1.174     albertel 1867:     if ($env{'form.timerange'} eq 'all') {
1.89      www      1868: # show all documents
1.230     albertel 1869: 	$header=&mt('All Documents in '.$type);
1.91      www      1870: 	$allsel=1;
1.90      www      1871: 	foreach (keys %hash) {
                   1872: 	    if ($_=~/^ids\_(\/res\/.+)$/) {
                   1873: 		my $src=$1;
                   1874: 		$changes{$src}=1;
                   1875: 	    }
                   1876: 	}
1.89      www      1877:     } else {
                   1878: # show documents which changed
                   1879: 	%changes=&Apache::lonnet::dump
1.174     albertel 1880: 	 ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
                   1881:                      $env{'course.'.$env{'request.course.id'}.'.num'});
1.89      www      1882: 	my $firstkey=(keys %changes)[0];
                   1883: 	unless ($firstkey=~/^error\:/) {
1.174     albertel 1884: 	    unless ($env{'form.timerange'}) {
                   1885: 		$env{'form.timerange'}=604800;
1.89      www      1886: 	    }
1.174     albertel 1887: 	    my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
1.89      www      1888: 		.&mt('seconds');
1.174     albertel 1889: 	    if ($env{'form.timerange'}==-1) {
1.89      www      1890: 		$seltext='since start of course';
                   1891: 		$startsel='selected';
1.174     albertel 1892: 		$env{'form.timerange'}=time;
1.89      www      1893: 	    }
1.174     albertel 1894: 	    $starttime=time-$env{'form.timerange'};
                   1895: 	    if ($env{'form.timerange'}==2592000) {
1.89      www      1896: 		$seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
                   1897: 		$monthsel='selected';
1.174     albertel 1898: 	    } elsif ($env{'form.timerange'}==604800) {
1.89      www      1899: 		$seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
                   1900: 		$weeksel='selected';
1.174     albertel 1901: 	    } elsif ($env{'form.timerange'}==86400) {
1.89      www      1902: 		$seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
                   1903: 		$daysel='selected';
                   1904: 	    }
                   1905: 	    $header=&mt('Content changed').' '.$seltext;
                   1906: 	} else {
                   1907: 	    $header=&mt('No content modifications yet.');
                   1908: 	}
                   1909:     }
1.92      www      1910:     %setversions=&Apache::lonnet::dump('resourceversions',
1.174     albertel 1911: 			  $env{'course.'.$env{'request.course.id'}.'.domain'},
                   1912: 			  $env{'course.'.$env{'request.course.id'}.'.num'});
1.89      www      1913:     my %lt=&Apache::lonlocal::texthash
1.229     raeburn  1914: 	      ('st' => 'Version changes since start of '.$type,
1.88      www      1915: 	       'lm' => 'Version changes since last Month',
                   1916: 	       'lw' => 'Version changes since last Week',
                   1917: 	       'sy' => 'Version changes since Yesterday',
1.91      www      1918:                'al' => 'All Resources (possibly large output)',
1.88      www      1919: 	       'sd' => 'Display',
1.84      www      1920: 	       'fi' => 'File',
                   1921: 	       'md' => 'Modification Date',
1.87      www      1922:                'mr' => 'Most recently published Version',
1.229     raeburn  1923: 	       've' => 'Version used in '.$type,
                   1924:                'vu' => 'Set Version to be used in '.$type,
                   1925: 'sv' => 'Set Versions to be used in '.$type.' according to Selections below',
1.91      www      1926: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
                   1927: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
1.84      www      1928: 	       'di' => 'Differences');
1.89      www      1929:     $r->print(<<ENDHEADERS);
1.31      www      1930: <form action="/adm/coursedocs" method="post">
1.91      www      1931: <input type="hidden" name="versions" value="1" />
                   1932: <input type="submit" name="setmostrecent" value="$lt{'sm'}" />
                   1933: <input type="submit" name="setcurrent" value="$lt{'sc'}" /><hr />
1.31      www      1934: <select name="timerange">
1.88      www      1935: <option value='all' $allsel>$lt{'al'}</option>
1.84      www      1936: <option value="-1" $startsel>$lt{'st'}</option>
                   1937: <option value="2592000" $monthsel>$lt{'lm'}</option>
                   1938: <option value="604800" $weeksel>$lt{'lw'}</option>
                   1939: <option value="86400" $daysel>$lt{'sy'}</option>
1.31      www      1940: </select>
1.91      www      1941: <input type="submit" name="display" value="$lt{'sd'}" />
1.89      www      1942: <h3>$header</h3>
1.91      www      1943: <input type="submit" name="setversions" value="$lt{'sv'}" />
1.103     matthew  1944: <table border="0">
1.31      www      1945: ENDHEADERS
1.91      www      1946:     foreach (sort keys %changes) {
1.89      www      1947: 	if ($changes{$_}>$starttime) {
                   1948: 	    my ($root,$extension)=($_=~/^(.*)\.(\w+)$/);
                   1949: 	    my $currentversion=&Apache::lonnet::getversion($_);
1.93      www      1950: 	    if ($currentversion<0) {
                   1951: 		$currentversion=&mt('Could not be determined.');
                   1952: 	    }
1.89      www      1953: 	    my $linkurl=&Apache::lonnet::clutter($_);
                   1954: 	    $r->print(
1.103     matthew  1955: 		      '<tr><td colspan="5"><br /><br /><font size="+1"><b>'.
1.91      www      1956: 		      &Apache::lonnet::gettitle($linkurl).
1.103     matthew  1957:                       '</b></font></td></tr>'.
                   1958:                       '<tr><td>&nbsp;&nbsp;&nbsp;</td>'.
                   1959:                       '<td colspan="4">'.
                   1960:                       '<a href="'.$linkurl.'" target="cat">'.$linkurl.
                   1961: 		      '</a></td></tr>'.
                   1962:                       '<tr><td></td>'.
                   1963:                       '<td title="'.$lt{'md'}.'">'.
1.102     matthew  1964: 		      &Apache::lonlocal::locallocaltime(
                   1965:                            &Apache::lonnet::metadata($root.'.'.$extension,
                   1966:                                                      'lastrevisiondate')
                   1967:                                                         ).
1.103     matthew  1968:                       '</td>'.
                   1969:                       '<td title="'.$lt{'mr'}.'"><nobr>Most Recent: '.
                   1970:                       '<font size="+1">'.$currentversion.'</font>'.
                   1971:                       '</nobr></td>'.
1.229     raeburn  1972:                       '<td title="'.$lt{'ve'}.'"><nobr>In '.$type.': '.
1.103     matthew  1973:                       '<font size="+1">');
1.87      www      1974: # Used in course
1.89      www      1975: 	    my $usedversion=$hash{'version_'.$linkurl};
1.93      www      1976: 	    if (($usedversion) && ($usedversion ne 'mostrecent')) {
1.89      www      1977: 		$r->print($usedversion);
                   1978: 	    } else {
                   1979: 		$r->print($currentversion);
                   1980: 	    }
1.103     matthew  1981: 	    $r->print('</font></nobr></td><td title="'.$lt{'vu'}.'">'.
                   1982:                       '<nobr>Use: ');
1.87      www      1983: # Set version
1.92      www      1984: 	    $r->print(&Apache::loncommon::select_form($setversions{$linkurl},
1.89      www      1985: 						      'set_version_'.$linkurl,
1.136     albertel 1986: 						      ('select_form_order' =>
                   1987: 						       ['',1..$currentversion,'mostrecent'],
                   1988: 						       '' => '',
1.93      www      1989: 						       'mostrecent' => 'most recent',
1.89      www      1990: 						       map {$_,$_} (1..$currentversion))));
1.103     matthew  1991: 	    $r->print('</nobr></td></tr><tr><td></td>');
1.89      www      1992: 	    my $lastold=1;
                   1993: 	    for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
                   1994: 		my $url=$root.'.'.$prevvers.'.'.$extension;
                   1995: 		if (&Apache::lonnet::metadata($url,'lastrevisiondate')<
                   1996: 		    $starttime) {
                   1997: 		    $lastold=$prevvers;
                   1998: 		}
                   1999: 	    }
1.103     matthew  2000:             # 
                   2001:             # Code to figure out how many version entries should go in
                   2002:             # each of the four columns
                   2003:             my $entries_per_col = 0;
                   2004:             my $num_entries = ($currentversion-$lastold);
                   2005:             if ($num_entries % 4 == 0) {
                   2006:                 $entries_per_col = $num_entries/4;
                   2007:             } else {
                   2008:                 $entries_per_col = $num_entries/4 + 1;
                   2009:             }
                   2010:             my $entries_count = 0;
                   2011:             $r->print('<td valign="top"><font size="-2">'); 
                   2012:             my $cols_output = 1;
1.32      www      2013:             for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
1.89      www      2014: 		my $url=$root.'.'.$prevvers.'.'.$extension;
1.103     matthew  2015: 		$r->print('<nobr><a href="'.&Apache::lonnet::clutter($url).
1.91      www      2016: 			  '">'.&mt('Version').' '.$prevvers.'</a> ('.
1.103     matthew  2017: 			  &Apache::lonlocal::locallocaltime(
                   2018:                                 &Apache::lonnet::metadata($url,
                   2019:                                                           'lastrevisiondate')
                   2020:                                                             ).
1.91      www      2021: 			  ')');
1.89      www      2022: 		if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
1.33      www      2023:                     $r->print(' <a href="/adm/diff?filename='.
1.89      www      2024: 			      &Apache::lonnet::clutter($root.'.'.$extension).
                   2025: 			      '&versionone='.$prevvers.
                   2026: 			      '">'.&mt('Diffs').'</a>');
                   2027: 		}
1.103     matthew  2028: 		$r->print('</nobr><br />');
                   2029:                 if (++$entries_count % $entries_per_col == 0) {
                   2030:                     $r->print('</font></td>');
                   2031:                     if ($cols_output != 4) {
                   2032:                         $r->print('<td valign="top"><font size="-2">');
                   2033:                         $cols_output++;
                   2034:                     }
                   2035:                 }
1.89      www      2036: 	    }
1.103     matthew  2037:             while($cols_output++ < 4) {
                   2038:                 $r->print('</font></td><td><font>')
                   2039:             }
                   2040: 	    $r->print('</font></td></tr>'."\n");
1.89      www      2041: 	}
                   2042:     }
1.92      www      2043:     $r->print('</table></form>');
1.89      www      2044:     $r->print('<h1>'.&mt('Done').'.</h1>');
                   2045: 
                   2046:     &untiehash();
1.75      www      2047: }
                   2048: 
1.136     albertel 2049: sub mark_hash_old {
                   2050:     my $retie_hash=0;
                   2051:     if ($hashtied) {
                   2052: 	$retie_hash=1;
                   2053: 	&untiehash();
                   2054:     }
                   2055:     &tiehash('write');
                   2056:     $hash{'old'}=1;
                   2057:     &untiehash();
                   2058:     if ($retie_hash) { &tiehash(); }
                   2059: }
                   2060: 
                   2061: sub is_hash_old {
                   2062:     my $untie_hash=0;
                   2063:     if (!$hashtied) {
                   2064: 	$untie_hash=1;
                   2065: 	&tiehash();
                   2066:     }
                   2067:     my $return=$hash{'old'};
                   2068:     if ($untie_hash) { &untiehash(); }
                   2069:     return $return;
                   2070: }
                   2071: 
1.91      www      2072: sub changewarning {
1.177     albertel 2073:     my ($r,$postexec,$message,$url)=@_;
1.136     albertel 2074:     if (!&is_hash_old()) { return; }
1.150     albertel 2075:     my $pathvar='folderpath';
1.228     www      2076:     my $path=&escape($env{'form.folderpath'});
1.177     albertel 2077:     if (!defined($url)) {
                   2078: 	if (defined($env{'form.pagepath'})) {
                   2079: 	    $pathvar='pagepath';
1.228     www      2080: 	    $path=&escape($env{'form.pagepath'});
                   2081: 	    $path.='&amp;pagesymb='.&escape($env{'form.pagesymb'});
1.177     albertel 2082: 	}
                   2083: 	$url='/adm/coursedocs?'.$pathvar.'='.$path;
                   2084:     }
1.230     albertel 2085:     my $course_type = &Apache::loncommon::course_type();
1.177     albertel 2086:     if (!defined($message)) {
                   2087: 	$message='Changes will become active for your current session after [_1], or the next time you log in.';
1.150     albertel 2088:     }
1.185     www      2089:     $r->print("\n\n".
                   2090: '<script>function reinit(tf) { tf.submit();'.$postexec.' }</script>'."\n". 
                   2091: '<form name="reinitform" method="post" action="/adm/roles" target="loncapaclient">'.
1.177     albertel 2092: '<input type="hidden" name="orgurl" value="'.$url.
1.117     albertel 2093: '" /><input type="hidden" name="selectrole" value="1" /><h3><font color="red">'.
1.177     albertel 2094: &mt($message,' <input type="hidden" name="'.
                   2095:     $env{'request.role'}.'" value="1" /><input type="button" value="'.
1.230     albertel 2096:     &mt('re-initializing '.$course_type).'" onClick="reinit(this.form)" />').
1.185     www      2097: $help{'Caching'}.'</font></h3></form>'."\n\n");
1.91      www      2098: }
                   2099: 
1.75      www      2100: # ================================================================ Main Handler
                   2101: sub handler {
                   2102:     my $r = shift;
1.82      www      2103:     &Apache::loncommon::content_type($r,'text/html');
1.75      www      2104:     $r->send_http_header;
                   2105:     return OK if $r->header_only;
1.230     albertel 2106:     my $type = &Apache::loncommon::course_type();
1.75      www      2107: 
                   2108: # --------------------------------------------- Initialize help topics for this
1.209     albertel 2109:     foreach ('Adding_Course_Doc','Main_Course_Documents',
                   2110: 	     'Adding_External_Resource','Navigate_Content',
                   2111: 	     'Adding_Folders','Docs_Overview', 'Load_Map',
                   2112: 	     'Supplemental','Score_Upload_Form','Adding_Pages',
                   2113: 	     'Importing_LON-CAPA_Resource','Uploading_From_Harddrive',
                   2114: 	     'Check_Resource_Versions','Verify_Content') {
                   2115: 	$help{$_}=&Apache::loncommon::help_open_topic('Docs_'.$_);
                   2116:     }
1.75      www      2117:     # Composite help files
                   2118:     $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
                   2119: 		    'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
                   2120:     $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
                   2121: 		    'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
1.86      albertel 2122:     $help{'Simple Problem'} = &Apache::loncommon::help_open_topic(
                   2123: 		    'Option_Response_Simple');
1.75      www      2124:     $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
                   2125: 		    'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
                   2126:     $help{'My Personal Info'} = &Apache::loncommon::help_open_topic(
                   2127: 		  'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
                   2128:     $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
1.142     raeburn  2129: 
1.209     albertel 2130: # does this user have privileges to modify docs
                   2131:     my $allowed=&Apache::lonnet::allowed('mdc',$env{'request.course.id'});
                   2132: 
                   2133:   if ($allowed && $env{'form.verify'}) {
1.75      www      2134:       &verifycontent($r);
1.209     albertel 2135:   } elsif ($allowed && $env{'form.listsymbs'}) {
1.208     albertel 2136:       &list_symbs($r);
1.209     albertel 2137:   } elsif ($allowed && $env{'form.versions'}) {
1.75      www      2138:       &checkversions($r);
1.209     albertel 2139:   } elsif ($allowed && $env{'form.dumpcourse'}) {
1.75      www      2140:       &dumpcourse($r);
1.209     albertel 2141:   } elsif ($allowed && $env{'form.exportcourse'}) {
1.138     raeburn  2142:       &exportcourse($r);
1.26      www      2143:   } else {
1.7       www      2144: # is this a standard course?
                   2145: 
1.174     albertel 2146:     my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
1.155     raeburn  2147:     my $forcestandard = 0;
1.15      www      2148:     my $forcesupplement;
                   2149:     my $script='';
1.19      www      2150:     my $showdoc=0;
1.142     raeburn  2151:     my $containertag;
                   2152:     my $uploadtag;
1.15      www      2153:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.224     albertel 2154: 					    ['folderpath','pagepath',
                   2155: 					     'pagesymb','markedcopy_url',
                   2156: 					     'markedcopy_title']);
1.174     albertel 2157:     if ($env{'form.folderpath'}) {
                   2158: 	my (@folderpath)=split('&',$env{'form.folderpath'});
1.228     www      2159: 	$env{'form.foldername'}=&unescape(pop(@folderpath));
1.174     albertel 2160: 	$env{'form.folder'}=pop(@folderpath);
                   2161:     }
                   2162:     if ($env{'form.pagepath'}) {
                   2163:         my (@pagepath)=split('&',$env{'form.pagepath'});
1.228     www      2164:         $env{'form.pagename'}=&unescape(pop(@pagepath));
1.174     albertel 2165:         $env{'form.folder'}=pop(@pagepath);
1.156     albertel 2166:         $containertag = '<input type="hidden" name="pagepath" value="" />'.
                   2167: 	    '<input type="hidden" name="pagesymb" value="" />';
1.174     albertel 2168:         $uploadtag = '<input type="hidden" name="pagepath" value="'.$env{'form.pagepath'}.'" />'.
                   2169: 	    '<input type="hidden" name="pagesymb" value="'.$env{'form.pagesymb'}.'" />';
1.142     raeburn  2170:     }
1.21      www      2171:     if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
1.127     albertel 2172:        $showdoc='/'.$1;
1.21      www      2173:     }
                   2174:     unless ($showdoc) { # got called from remote
1.174     albertel 2175:        if (($env{'form.folder'}=~/^default_/) || 
1.209     albertel 2176:           ($env{'form.folder'} =~ m:^\d+/(pages|sequences)/:)) {
1.155     raeburn  2177:            $forcestandard = 1;
                   2178:        } 
1.174     albertel 2179:        $forcesupplement=($env{'form.folder'}=~/^supplemental_/);
1.7       www      2180: 
1.15      www      2181:        if ($allowed) { 
                   2182:          &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
                   2183:          $script=&Apache::lonratedt::editscript('simple'); 
                   2184:        }
                   2185:     } else { # got called in sequence from course
                   2186:        $allowed=0;
1.3       www      2187:     }
1.4       www      2188: 
                   2189: # get course data
1.174     albertel 2190:     my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
                   2191:     my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.4       www      2192: 
1.225     albertel 2193: # get personal data 
1.174     albertel 2194:     my $uname=$env{'user.name'};
                   2195:     my $udom=$env{'user.domain'};
1.228     www      2196:     my $plainname=&escape(
1.14      www      2197:                      &Apache::loncommon::plainname($uname,$udom));
                   2198: 
1.8       www      2199: # graphics settings
1.4       www      2200: 
1.176     albertel 2201:     $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL') . "/");
1.8       www      2202: 
1.224     albertel 2203:     if ($allowed) {
                   2204: 	$script .= &editing_js($udom,$uname);
1.171     www      2205:     }
1.42      www      2206: # -------------------------------------------------------------------- Body tag
1.224     albertel 2207:     $script = '<script type="text/javascript">'."\n".$script."\n".'</script>';
1.229     raeburn  2208:     $r->print(&Apache::loncommon::start_page("$type Documents", $script,
1.225     albertel 2209: 					     {'force_register' => $showdoc,}).
1.224     albertel 2210: 	      &Apache::loncommon::help_open_menu('','','','',273,'RAT'));
                   2211:   
1.188     raeburn  2212:   my %allfiles = ();
                   2213:   my %codebase = ();
                   2214:   my ($upload_result,$upload_output);
                   2215:   if ($allowed) {
                   2216:       if (($env{'form.uploaddoc.filename'}) &&                                               ($env{'form.cmd'}=~/^upload_(\w+)/)) {
                   2217: # Process file upload - phase one - upload and parse primary file.  
1.190     albertel 2218:           $upload_result = &process_file_upload(\$upload_output,$coursenum,
                   2219: 						$coursedom,\%allfiles,
1.194     raeburn  2220: 						\%codebase,$1);
1.188     raeburn  2221:           if ($upload_result eq 'phasetwo') {
                   2222:               $r->print($upload_output);
                   2223:           }
                   2224:       } elsif ($env{'form.phasetwo'}) {
                   2225:           my %newname = ();
                   2226:           my %origname = ();
                   2227:           my %attribs = ();
                   2228:           my $updateflag = 0;
                   2229:           my $residx = $env{'form.newidx'};
1.228     www      2230:           my $primary_url = &unescape($env{'form.primaryurl'});
1.188     raeburn  2231: # Process file upload - phase two - gather secondary files.
                   2232:           for (my $i=0; $i<$env{'form.phasetwo'}; $i++) {
                   2233:               if ($env{'form.embedded_item_'.$i.'.filename'}) {
                   2234:                   my $javacodebase;
                   2235:                   $newname{$i} = &process_secondary_uploads(\$upload_output,$coursedom,$coursenum,'embedded_item_',$i,$residx);
1.228     www      2236:                   $origname{$i} = &unescape($env{'form.embedded_orig_'.$i});
1.188     raeburn  2237:                   if (exists($env{'form.embedded_codebase_'.$i})) {
1.228     www      2238:                       $javacodebase =  &unescape($env{'form.embedded_codebase_'.$i});  
1.188     raeburn  2239:                       $origname{$i} =~ s#^\Q$javacodebase\E/##; 
                   2240:                   }
                   2241:                   my @attributes = ();
                   2242:                   if ($env{'form.embedded_attrib_'.$i} =~ /:/) {
                   2243:                       @attributes = split/:/,$env{'form.embedded_attrib_'.$i};
                   2244:                   } else {
                   2245:                       @attributes = ($env{'form.embedded_attrib_'.$i});
                   2246:                   }
                   2247:                   foreach (@attributes) {
1.228     www      2248:                       push(@{$attribs{$i}},&unescape($_));
1.188     raeburn  2249:                   }
                   2250:                   if ($javacodebase) {
                   2251:                       $codebase{$i} = $javacodebase;
                   2252:                       $codebase{$i} =~ s#/$##;
                   2253:                       $updateflag = 1;
                   2254:                   }
                   2255:               }
                   2256:               unless ($newname{$i} eq $origname{$i}) {
                   2257:                   $updateflag = 1;
                   2258:               }
                   2259:           }
                   2260: # Process file upload - phase three - modify primary file
                   2261:           if ($updateflag) {
                   2262:               my ($content,$rtncode);
                   2263:               my $updateflag = 0;
                   2264:               my $getstatus = &Apache::lonnet::getuploaded('GET',$primary_url,$coursedom,$coursenum,\$content,\$rtncode);
                   2265:               if ($getstatus eq 'ok') {
                   2266:                   foreach my $item (keys %newname) {
                   2267:                       if ($newname{$item} ne $origname{$item}) {
                   2268:                           my $attrib_regexp = '';
                   2269:                           if (@{$attribs{$item}} > 1) {
                   2270:                               $attrib_regexp = join('|',@{$attribs{$item}});
                   2271:                           } else {
                   2272:                               $attrib_regexp = $attribs{$item}[0];
                   2273:                           }
                   2274:                           if ($content =~ m#($attrib_regexp\s*=\s*['"]?)\Q$origname{$item}\E(['"]?)#) {
                   2275:                           } 
                   2276:                           $content =~ s#($attrib_regexp\s*=\s*['"]?)\Q$origname{$item}\E(['"]?)#$1$newname{$item}$2#gi; 
                   2277:                       }
                   2278:                       if (exists($codebase{$item})) {
1.224     albertel 2279:                           $content =~ s/(codebase\s*=\s*["']?)\Q$codebase{$item}\E(["']?)/$1.$2/i; #' stupid emacs
1.188     raeburn  2280:                       }
                   2281:                   }
                   2282: # Save edited file.
                   2283:                   my $saveresult;
                   2284:                   my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
                   2285:                   my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.191     raeburn  2286:                   my $url = &Apache::lonnet::store_edited_file($primary_url,$content,$docudom,$docuname,\$saveresult);
1.188     raeburn  2287:               } else {
                   2288:                   &Apache::lonnet::logthis('retrieval of uploaded file - '.$primary_url.' - for editing, failed: '.$getstatus); 
                   2289:               }
                   2290:           }
                   2291:       }
                   2292:   }
                   2293: 
                   2294:   unless ($showdoc ||  $upload_result eq 'phasetwo') {
1.81      www      2295: # -----------------------------------------------------------------------------
                   2296:        my %lt=&Apache::lonlocal::texthash(
1.229     raeburn  2297:                 'uplm' => 'Upload a new main '.lc($type).' document',
                   2298:                 'upls' => 'Upload a new supplemental '.lc($type).' document',
1.168     www      2299:                 'impp' => 'Import a document',
                   2300:                 'pubd' => 'Published documents',
1.181     www      2301: 		'copm' => 'All documents out of a published map into this folder',
1.81      www      2302:                 'spec' => 'Special documents',
                   2303:                 'upld' => 'Upload Document',
                   2304:                 'srch' => 'Search',
                   2305:                 'impo' => 'Import',
1.232   ! www      2306: 		'book' => 'Import Bookmarks',
1.81      www      2307:                 'selm' => 'Select Map',
                   2308:                 'load' => 'Load Map',
1.186     www      2309:                 'reco' => 'Recover Deleted Resources',
1.81      www      2310:                 'newf' => 'New Folder',
1.142     raeburn  2311:                 'newp' => 'New Composite Page',
1.81      www      2312:                 'extr' => 'External Resource',
                   2313:                 'syll' => 'Syllabus',
                   2314:                 'navc' => 'Navigate Contents',
                   2315:                 'sipa' => 'Simple Page',
                   2316:                 'sipr' => 'Simple Problem',
1.219     www      2317:                 'drbx' => 'Drop Box',
1.81      www      2318:                 'scuf' => 'Score Upload Form',
                   2319:                 'bull' => 'Bulletin Board',
1.96      sakharuk 2320:                 'mypi' => 'My Personal Info',
1.101     www      2321: 		'abou' => 'About User',
1.110     raeburn  2322:                 'imsf' => 'Import IMS package',
1.96      sakharuk 2323:                 'file' =>  'File',
                   2324:                 'title' => 'Title',
1.188     raeburn  2325:                 'comment' => 'Comment',
                   2326:                 'parse' => 'If HTML file, upload embedded images/multimedia files'
1.81      www      2327: 					  );
                   2328: # -----------------------------------------------------------------------------
1.42      www      2329:     if ($allowed) {
1.74      www      2330:        my $dumpbut=&dumpbutton();
1.138     raeburn  2331:        my $exportbut=&exportbutton();
1.88      www      2332:        my %lt=&Apache::lonlocal::texthash(
                   2333: 					 'vc' => 'Verify Content',
                   2334: 					 'cv' => 'Check/Set Resource Versions',
1.208     albertel 2335: 					 'ls' => 'List Symbs',
1.88      www      2336: 					  );
1.118     albertel 2337: 
1.174     albertel 2338:        my $folderpath=$env{'form.folderpath'};
1.118     albertel 2339:        if (!$folderpath) {
1.174     albertel 2340: 	   if ($env{'form.folder'} eq '' ||
                   2341: 	       $env{'form.folder'} eq 'supplemental') {
1.118     albertel 2342: 	       $folderpath='default&'.
1.230     albertel 2343: 		   &escape(&mt('Main '.$type.' Documents'));
1.118     albertel 2344: 	   }
                   2345:        }
1.174     albertel 2346:        unless ($env{'form.pagepath'}) {
1.142     raeburn  2347:            $containertag = '<input type="hidden" name="folderpath" value="" />';
                   2348:            $uploadtag = '<input type="hidden" name="folderpath" value="'.$folderpath.'" />';
                   2349:        }
                   2350: 
1.42      www      2351:        $r->print(<<ENDCOURSEVERIFY);
1.36      www      2352: <form name="renameform" method="post" action="/adm/coursedocs">
                   2353: <input type="hidden" name="title" />
                   2354: <input type="hidden" name="cmd" />
1.168     www      2355: <input type="hidden" name="markcopy" />
1.142     raeburn  2356: $containertag
1.36      www      2357: </form>
1.39      www      2358: <form name="simpleedit" method="post" action="/adm/coursedocs">
                   2359: <input type=hidden name="importdetail" value="">
1.142     raeburn  2360: $uploadtag
1.39      www      2361: </form>
1.26      www      2362: <form action="/adm/coursedocs" method="post" name="courseverify">
1.74      www      2363: <table bgcolor="#AAAAAA" width="100%" cellspacing="4" cellpadding="4">
                   2364: <tr><td bgcolor="#DDDDCC">
1.130     www      2365: <input type="submit" name="verify" value="$lt{'vc'}" />$help{'Verify_Content'}
1.74      www      2366: </td><td bgcolor="#DDDDCC">
1.130     www      2367:     <input type="submit" name="versions" value="$lt{'cv'}" />$help{'Check_Resource_Versions'}
1.74      www      2368: $dumpbut
1.138     raeburn  2369: $exportbut
1.218     albertel 2370: </td><td bgcolor="#DDDDCC">
1.208     albertel 2371:     <input type="submit" name="listsymbs" value="$lt{'ls'}" />
1.218     albertel 2372: </td></tr></table>
1.25      www      2373: </form>
                   2374: ENDCOURSEVERIFY
1.74      www      2375:        $r->print(&Apache::loncommon::help_open_topic('Docs_Adding_Course_Doc',
1.230     albertel 2376: 		     &mt('Editing the Table of Contents for your '.$type)));
1.25      www      2377:     }
1.17      www      2378: # --------------------------------------------------------- Standard documents
1.43      www      2379:     $r->print('<table border=2 cellspacing=4 cellpadding=4>');
1.7       www      2380:     if (($standard) && ($allowed) && (!$forcesupplement)) {
1.116     albertel 2381: 	$r->print('<tr><td bgcolor="#BBBBBB">');
                   2382: #  '<h2>'.&mt('Main Course Documents').
                   2383: #  ($allowed?' '.$help{'Main_Course_Documents'}:'').'</h2>');
1.174     albertel 2384:        my $folder=$env{'form.folder'};
1.117     albertel 2385:        if ($folder eq '' || $folder eq 'supplemental') {
1.112     raeburn  2386:            $folder='default';
1.230     albertel 2387: 	   $env{'form.folderpath'}='default&'.&escape(&mt('Main '.$type.' Documents'));
1.112     raeburn  2388:        }
1.51      www      2389:        my $postexec='';
                   2390:        if ($folder eq 'default') {
                   2391: 	   $r->print('<script>this.window.name="loncapaclient";</script>');
                   2392:        } else {
1.117     albertel 2393:            #$postexec='self.close();';
1.51      www      2394:        }
1.40      www      2395:        $hadchanges=0;
1.188     raeburn  2396:        &editor($r,$coursenum,$coursedom,$folder,$allowed,$upload_output);
1.40      www      2397:        if ($hadchanges) {
1.136     albertel 2398: 	   &mark_hash_old()
1.40      www      2399:        }
1.136     albertel 2400:        &changewarning($r,$postexec);
1.16      www      2401:        my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_'.time.
                   2402:                      '.sequence';
1.142     raeburn  2403:        my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_'.time.
                   2404:                      '.page';
1.186     www      2405: 	my $container='sequence';
                   2406: 	if ($env{'form.pagepath'}) {
                   2407: 	    $container='page';
                   2408: 	}
                   2409: 	my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
1.8       www      2410:        $r->print(<<ENDFORM);
1.43      www      2411: <table cellspacing=4 cellpadding=4><tr>
1.81      www      2412: <th bgcolor="#DDDDDD">$lt{'uplm'}</th>
                   2413: <th bgcolor="#DDDDDD">$lt{'impp'}</th>
                   2414: <th bgcolor="#DDDDDD">$lt{'spec'}</th>
1.11      www      2415: </tr>
1.16      www      2416: <tr><td bgcolor="#DDDDDD">
1.96      sakharuk 2417: $lt{'file'}:<br />
1.182     albertel 2418: <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.59      www      2419: <input type="file" name="uploaddoc" size="40">
1.8       www      2420: <br />
1.96      sakharuk 2421: $lt{'title'}:<br />
1.11      www      2422: <input type="text" size="50" name="comment">
1.142     raeburn  2423: $uploadtag
1.10      www      2424: <input type="hidden" name="cmd" value="upload_default">
1.188     raeburn  2425: <br />
                   2426: <nobr>
1.190     albertel 2427: <label>$lt{'parse'}?
1.188     raeburn  2428: <input type="checkbox" name="parserflag" />
1.190     albertel 2429: </label>
1.188     raeburn  2430: </nobr>
                   2431: <br />
                   2432: <br />
1.129     albertel 2433: <nobr>
1.81      www      2434: <input type="submit" value="$lt{'upld'}">
1.60      albertel 2435:  $help{'Uploading_From_Harddrive'}
1.58      albertel 2436: </nobr>
1.60      albertel 2437: </form>
1.11      www      2438: </td>
1.16      www      2439: <td bgcolor="#DDDDDD">
1.39      www      2440: <form action="/adm/coursedocs" method="post" name="simpleeditdefault">
1.168     www      2441: $lt{'pubd'}<br />
1.142     raeburn  2442: $uploadtag
1.232   ! www      2443: <input type=button onClick="javascript:groupsearch()" value="$lt{'srch'}" />
        !          2444: <br />
1.58      albertel 2445: <nobr>
1.232   ! www      2446: <input type=button onClick="javascript:groupimport();" value="$lt{'impo'}" />
1.58      albertel 2447: $help{'Importing_LON-CAPA_Resource'}
                   2448: </nobr>
1.232   ! www      2449: <br />
        !          2450: <input type=button onClick="javascript:groupopen(0,1,1);" value="$lt{'book'}" />
1.59      www      2451: <p>
                   2452: <hr />
1.181     www      2453: $lt{'copm'}<br />
                   2454: <input type="text" size="40" name="importmap"><br />
1.68      bowersj2 2455: <nobr><input type=button 
1.52      www      2456: onClick="javascript:openbrowser('simpleeditdefault','importmap','sequence,page','')"
1.81      www      2457: value="$lt{'selm'}"> <input type="submit" name="loadmap" value="$lt{'load'}">
1.68      bowersj2 2458: $help{'Load_Map'}</nobr>
1.59      www      2459: </p>
1.52      www      2460: </form>
1.186     www      2461: <hr />
                   2462: <form action="/adm/groupsort" method="post" name="recover">
1.232   ! www      2463: <input type="button" name="recovermap" onClick="javascript:groupopen('$readfile',1,0)" value="$lt{'reco'}" />
1.186     www      2464: </form>
1.142     raeburn  2465: ENDFORM
1.174     albertel 2466:        unless ($env{'form.pagepath'}) {
1.168     www      2467: 	   $r->print(<<ENDFORM);
                   2468: <hr />
                   2469: <form action="/adm/coursedocs" method="post" name="newext">
                   2470: $uploadtag
                   2471: <input type=hidden name="importdetail" value="">
                   2472: <nobr>
                   2473: <input name="newext" type="button" onClick="javascript:makenewext('newext');"
                   2474: value="$lt{'extr'}" /> $help{'Adding_External_Resource'}
                   2475: </nobr>
                   2476: </form>
1.214     www      2477: <br /><form action="/adm/imsimportdocs" method="post" name="ims">
1.168     www      2478: <input type="hidden" name="folder" value="$folder" />
                   2479: <input name="imsimport" type="button" value="$lt{'imsf'}" onClick="javascript:makeims();" />
                   2480: </nobr>
                   2481: </form>
                   2482: ENDFORM
                   2483:        }
                   2484:        $r->print('</td><td bgcolor="#DDDDDD">');
1.174     albertel 2485:        unless ($env{'form.pagepath'}) {
1.142     raeburn  2486:            $r->print(<<ENDFORM);
1.214     www      2487: <br /><form action="/adm/coursedocs" method="post" name="newfolder">
1.174     albertel 2488: <input type="hidden" name="folderpath" value="$env{'form.folderpath'}" />
1.13      www      2489: <input type=hidden name="importdetail" value="">
1.58      albertel 2490: <nobr>
1.16      www      2491: <input name="newfolder" type="button"
                   2492: onClick="javascript:makenewfolder(this.form,'$folderseq');"
1.81      www      2493: value="$lt{'newf'}" />$help{'Adding_Folders'}
1.58      albertel 2494: </nobr>
1.11      www      2495: </form>
1.214     www      2496: <br /><form action="/adm/coursedocs" method="post" name="newpage">
1.174     albertel 2497: <input type="hidden" name="folderpath" value="$env{'form.folderpath'}" />
1.142     raeburn  2498: <input type=hidden name="importdetail" value="">
                   2499: <nobr>
                   2500: <input name="newpage" type="button"
                   2501: onClick="javascript:makenewpage(this.form,'$pageseq');"
                   2502: value="$lt{'newp'}" />$help{'Adding_Pages'}
                   2503: </nobr>
                   2504: </form>
1.214     www      2505: <br /><form action="/adm/coursedocs" method="post" name="newsyl">
1.142     raeburn  2506: $uploadtag
1.14      www      2507: <input type=hidden name="importdetail" 
                   2508: value="Syllabus=/public/$coursedom/$coursenum/syllabus">
1.58      albertel 2509: <nobr>
1.81      www      2510: <input name="newsyl" type="submit" value="$lt{'syll'}" /> 
1.65      bowersj2 2511:  $help{'Syllabus'}
1.58      albertel 2512: </nobr>
                   2513: </form>
1.214     www      2514: <br /><form action="/adm/coursedocs" method="post" name="newnav">
1.142     raeburn  2515: $uploadtag
1.15      www      2516: <input type=hidden name="importdetail" 
                   2517: value="Navigate Content=/adm/navmaps">
1.58      albertel 2518: <nobr>
1.81      www      2519: <input name="newnav" type="submit" value="$lt{'navc'}" />
1.47      www      2520: $help{'Navigate_Content'}
1.58      albertel 2521: </nobr>
1.22      www      2522: </form>
1.214     www      2523: <br /><form action="/adm/coursedocs" method="post" name="newsmppg">
1.142     raeburn  2524: $uploadtag
1.22      www      2525: <input type=hidden name="importdetail" value="">
1.58      albertel 2526: <nobr>
1.81      www      2527: <input name="newsmppg" type="button" value="$lt{'sipa'}"
1.65      bowersj2 2528: onClick="javascript:makesmppage();" /> $help{'Simple Page'}
1.58      albertel 2529: </nobr>
1.55      www      2530: </form>
1.214     www      2531: <br /><form action="/adm/coursedocs" method="post" name="newsmpproblem">
1.142     raeburn  2532: $uploadtag
1.55      www      2533: <input type=hidden name="importdetail" value="">
1.58      albertel 2534: <nobr>
1.81      www      2535: <input name="newsmpproblem" type="button" value="$lt{'sipr'}"
1.65      bowersj2 2536: onClick="javascript:makesmpproblem();" />$help{'Simple Problem'}
1.62      www      2537: </nobr>
                   2538: </form>
1.219     www      2539: <br /><form action="/adm/coursedocs" method="post" name="newdropbox">
                   2540: $uploadtag      
                   2541: <input type=hidden name="importdetail" value="">
                   2542: <nobr>          
                   2543: <input name="newdropbox" type="button" value="$lt{'drbx'}"
                   2544: onClick="javascript:makedropbox();" />
                   2545: </nobr>         
                   2546: </form> 
1.214     www      2547: <br /><form action="/adm/coursedocs" method="post" name="newexamupload">
1.142     raeburn  2548: $uploadtag
1.62      www      2549: <input type=hidden name="importdetail" value="">
                   2550: <nobr>
1.81      www      2551: <input name="newexamupload" type="button" value="$lt{'scuf'}"
1.62      www      2552: onClick="javascript:makeexamupload();" />
1.66      bowersj2 2553: $help{'Score_Upload_Form'}
1.58      albertel 2554: </nobr>
1.22      www      2555: </form>
1.214     www      2556: <br /><form action="/adm/coursedocs" method="post" name="newbul">
1.142     raeburn  2557: $uploadtag
1.22      www      2558: <input type=hidden name="importdetail" value="">
1.58      albertel 2559: <nobr>
1.81      www      2560: <input name="newbulletin" type="button" value="$lt{'bull'}"
1.22      www      2561: onClick="javascript:makebulboard();" />
1.65      bowersj2 2562: $help{'Bulletin Board'}
1.58      albertel 2563: </nobr>
                   2564: </form>
1.214     www      2565: <br /><form action="/adm/coursedocs" method="post" name="newaboutme">
1.142     raeburn  2566: $uploadtag
1.14      www      2567: <input type=hidden name="importdetail" 
                   2568: value="$plainname=/adm/$udom/$uname/aboutme">
1.58      albertel 2569: <nobr>
1.81      www      2570: <input name="newaboutme" type="submit" value="$lt{'mypi'}" />
1.65      bowersj2 2571: $help{'My Personal Info'}
1.101     www      2572: </nobr>
                   2573: </form>
1.214     www      2574: <br /><form action="/adm/coursedocs" method="post" name="newaboutsomeone">
1.142     raeburn  2575: $uploadtag
1.101     www      2576: <input type=hidden name="importdetail" value="">
                   2577: <nobr>
                   2578: <input name="newaboutsomeone" type="button" value="$lt{'abou'}" 
                   2579: onClick="javascript:makeabout();" />
1.110     raeburn  2580: </nobr>
1.182     albertel 2581: </form>
1.142     raeburn  2582: ENDFORM
                   2583:        }
1.174     albertel 2584:        if ($env{'form.pagepath'}) {
1.142     raeburn  2585:            $r->print(<<ENDBLOCK);
                   2586: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
                   2587: $uploadtag
                   2588: <input type=hidden name="importdetail" value="">
                   2589: <nobr>
                   2590: <input name="newsmpproblem" type="button" value="$lt{'sipr'}"
                   2591: onClick="javascript:makesmpproblem();" />$help{'Simple Problem'}
                   2592: </nobr>
                   2593: </form>
1.214     www      2594: <br /><form action="/adm/coursedocs" method="post" name="newexamupload">
1.142     raeburn  2595: $uploadtag
                   2596: <input type=hidden name="importdetail" value="">
                   2597: <nobr>
                   2598: <input name="newexamupload" type="button" value="$lt{'scuf'}"
                   2599: onClick="javascript:makeexamupload();" />
                   2600: $help{'Score_Upload_Form'}
                   2601: </nobr>
1.182     albertel 2602: </form>
1.142     raeburn  2603: ENDBLOCK
                   2604:        }
                   2605:        $r->print('</td></tr>'."\n".
                   2606: '</table>');
1.24      www      2607:        $r->print('</td></tr>');
1.7       www      2608:     }
                   2609: # ----------------------------------------------------- Supplemental documents
                   2610:     if (!$forcestandard) {
1.116     albertel 2611:        $r->print('<tr><td bgcolor="#BBBBBB">');
                   2612: # '<h2>'.&mt('Supplemental Course Documents').
                   2613: #  ($allowed?' '.$help{'Supplemental'}:'').'</h2>');
1.174     albertel 2614:        my $folder=$env{'form.folder'};
1.117     albertel 2615:        unless ($folder=~/^supplemental/) {
1.116     albertel 2616: 	   $folder='supplemental';
1.117     albertel 2617:        }
                   2618:        if ($folder =~ /^supplemental$/ &&
1.174     albertel 2619: 	   $env{'form.folderpath'} =~ /^default\&/) {
                   2620: 	   $env{'form.folderpath'}='supplemental&'.
1.230     albertel 2621: 	       &escape(&mt('Supplemental '.$type.' Documents'));
1.116     albertel 2622:        }
1.7       www      2623:        &editor($r,$coursenum,$coursedom,$folder,$allowed);
1.8       www      2624:        if ($allowed) {
1.17      www      2625:        my $folderseq=
                   2626:                   '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_'.time.
                   2627:                      '.sequence';
                   2628: 
1.8       www      2629:           $r->print(<<ENDSUPFORM);
1.43      www      2630: <table cellspacing=4 cellpadding=4><tr>
1.81      www      2631: <th bgcolor="#DDDDDD">$lt{'upls'}</th>
                   2632: <th bgcolor="#DDDDDD">$lt{'spec'}</th>
1.17      www      2633: </tr>
                   2634: <tr><td bgcolor="#DDDDDD">
1.10      www      2635: <form action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.59      www      2636: <input type="file" name="uploaddoc" size="40">
1.196     raeburn  2637: <br />
                   2638: <br />
                   2639: <nobr>
                   2640: <label>$lt{'parse'}?
                   2641: <input type="checkbox" name="parserflag" />
                   2642: </label>
                   2643: </nobr>
                   2644: <br /><br />
                   2645: $lt{'comment'}:<br />
1.4       www      2646: <textarea cols=50 rows=4 name='comment'>
                   2647: </textarea>
1.115     albertel 2648: <br />
1.174     albertel 2649: <input type="hidden" name="folderpath" value="$env{'form.folderpath'}" />
1.10      www      2650: <input type="hidden" name="cmd" value="upload_supplemental">
1.58      albertel 2651: <nobr>
1.81      www      2652: <input type="submit" value="$lt{'upld'}">
1.58      albertel 2653:  $help{'Uploading_From_Harddrive'}
                   2654: </nobr>
                   2655: </form>
1.17      www      2656: </td>
                   2657: <td bgcolor="#DDDDDD">
1.18      www      2658: <form action="/adm/coursedocs" method="post" name="supnewfolder">
1.174     albertel 2659: <input type="hidden" name="folderpath" value="$env{'form.folderpath'}" />
1.17      www      2660: <input type=hidden name="importdetail" value="">
1.58      albertel 2661: <nobr>
1.17      www      2662: <input name="newfolder" type="button"
                   2663: onClick="javascript:makenewfolder(this.form,'$folderseq');"
1.81      www      2664: value="$lt{'newf'}" /> $help{'Adding_Folders'}
1.58      albertel 2665: </nobr>
1.17      www      2666: </form>
1.214     www      2667: <br /><form action="/adm/coursedocs" method="post" name="supnewext">
1.174     albertel 2668: <input type="hidden" name="folderpath" value="$env{'form.folderpath'}" />
1.17      www      2669: <input type=hidden name="importdetail" value="">
1.58      albertel 2670: <nobr>
1.18      www      2671: <input name="newext" type="button" 
                   2672: onClick="javascript:makenewext('supnewext');"
1.81      www      2673: value="$lt{'extr'}" /> $help{'Adding_External_Resource'}
1.58      albertel 2674: </nobr>
1.17      www      2675: </form>
1.214     www      2676: <br /><form action="/adm/coursedocs" method="post" name="supnewsyl">
1.174     albertel 2677: <input type="hidden" name="folderpath" value="$env{'form.folderpath'}" />
1.17      www      2678: <input type=hidden name="importdetail" 
                   2679: value="Syllabus=/public/$coursedom/$coursenum/syllabus">
1.58      albertel 2680: <nobr>
1.81      www      2681: <input name="newsyl" type="submit" value="$lt{'syll'}" />
1.65      bowersj2 2682: $help{'Syllabus'}
1.58      albertel 2683: </nobr>
                   2684: </form>
1.214     www      2685: <br /><form action="/adm/coursedocs" method="post" name="subnewaboutme">
1.174     albertel 2686: <input type="hidden" name="folderpath" value="$env{'form.folderpath'}" />
1.17      www      2687: <input type=hidden name="importdetail" 
                   2688: value="$plainname=/adm/$udom/$uname/aboutme">
1.58      albertel 2689: <nobr>
1.81      www      2690: <input name="newaboutme" type="submit" value="$lt{'mypi'}" />
1.65      bowersj2 2691: $help{'My Personal Info'}
1.58      albertel 2692: </nobr>
                   2693: </form>
1.17      www      2694: </td></tr>
1.24      www      2695: </table></td></tr>
1.8       www      2696: ENDSUPFORM
                   2697:        }
1.7       www      2698:     }
1.18      www      2699:     if ($allowed) {
1.182     albertel 2700: 	$r->print('<form method="POST" name="extimport" action="/adm/coursedocs"><input type="hidden" name="title" /><input type="hidden" name="url" /><input type="hidden" name="useform" /></form>');
1.18      www      2701:     }
1.24      www      2702:     $r->print('</table>');
1.19      www      2703:   } else {
1.188     raeburn  2704:       unless ($upload_result eq 'phasetwo') {
1.19      www      2705: # -------------------------------------------------------- This is showdoc mode
1.188     raeburn  2706:           $r->print("<h1>".&mt('Uploaded Document').' - '.
1.141     albertel 2707: 		&Apache::lonnet::gettitle($r->uri).'</h1><p>'.
1.81      www      2708: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><p><table>".
1.188     raeburn  2709:           &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table></p>');
                   2710:       }
1.19      www      2711:   }
1.26      www      2712:  }
1.224     albertel 2713:  $r->print(&Apache::loncommon::end_page());
1.26      www      2714:  return OK;
1.1       www      2715: } 
                   2716: 
1.224     albertel 2717: 
                   2718: sub editing_js {
                   2719:     my ($udom,$uname) = @_;
                   2720:     my $now = time();
                   2721: 
                   2722:     return <<ENDNEWSCRIPT;
                   2723: function makenewfolder(targetform,folderseq) {
                   2724:     var foldername=prompt('Name of New Folder','New Folder');
                   2725:     if (foldername) {
                   2726:        targetform.importdetail.value=foldername+"="+folderseq;
                   2727:         targetform.submit();
                   2728:     }
                   2729: }
                   2730: 
                   2731: function makenewpage(targetform,folderseq) {
                   2732:     var pagename=prompt('Name of New Page','New Page');
                   2733:     if (pagename) {
                   2734:         targetform.importdetail.value=pagename+"="+folderseq;
                   2735:         targetform.submit();
                   2736:     }
                   2737: }
                   2738: 
                   2739: function makenewext(targetname) {
                   2740:     this.document.forms.extimport.useform.value=targetname;
                   2741:     window.open('/adm/rat/extpickframe.html');
                   2742: }
                   2743: 
                   2744: function makeexamupload() {
                   2745:    var title=prompt('Listed Title for the Uploaded Score');
                   2746:    if (title) { 
                   2747:     this.document.forms.newexamupload.importdetail.value=
                   2748: 	title+'=/res/lib/templates/examupload.problem';
                   2749:     this.document.forms.newexamupload.submit();
                   2750:    }
                   2751: }
                   2752: 
                   2753: function makesmppage() {
                   2754:    var title=prompt('Listed Title for the Page');
                   2755:    if (title) { 
                   2756:     this.document.forms.newsmppg.importdetail.value=
                   2757: 	title+'=/adm/$udom/$uname/$now/smppg';
                   2758:     this.document.forms.newsmppg.submit();
                   2759:    }
                   2760: }
                   2761: 
                   2762: function makesmpproblem() {
                   2763:    var title=prompt('Listed Title for the Problem');
                   2764:    if (title) { 
                   2765:     this.document.forms.newsmpproblem.importdetail.value=
                   2766: 	title+'=/res/lib/templates/simpleproblem.problem';
                   2767:     this.document.forms.newsmpproblem.submit();
                   2768:    }
                   2769: }
                   2770: 
                   2771: function makedropbox() {
                   2772:    var title=prompt('Listed Title for the Drop Box');
                   2773:    if (title) { 
                   2774:     this.document.forms.newdropbox.importdetail.value=
                   2775:         title+'=/res/lib/templates/DropBox.problem';
                   2776:     this.document.forms.newdropbox.submit();
                   2777:    }
                   2778: }
                   2779: 
                   2780: function makebulboard() {
                   2781:    var title=prompt('Listed Title for the Bulletin Board');
                   2782:    if (title) {
                   2783:     this.document.forms.newbul.importdetail.value=
                   2784: 	title+'=/adm/$udom/$uname/$now/bulletinboard';
                   2785:     this.document.forms.newbul.submit();
                   2786:    }
                   2787: }
                   2788: 
                   2789: function makeabout() {
                   2790:    var user=prompt("Enter user\@domain for User's 'About Me' Page");
                   2791:    if (user) {
                   2792:        var comp=new Array();
                   2793:        comp=user.split('\@');
                   2794:        if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
                   2795: 	   if ((comp[0]) && (comp[1])) {
                   2796: 	       this.document.forms.newaboutsomeone.importdetail.value=
                   2797: 		   'About '+user+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
                   2798: 	       this.document.forms.newaboutsomeone.submit();
                   2799: 	   } else {
                   2800:                alert("Not a valid user\@domain");
                   2801:            }
                   2802:        } else {
                   2803:            alert("Please enter both user and domain in the format user\@domain"); 
                   2804:        }
                   2805:    }
                   2806: }
                   2807: 
                   2808: function makeims() {
                   2809:     var caller = document.forms.ims.folder.value;
                   2810:     var newlocation = "/adm/imsimportdocs?folder="+caller+"&phase=one";
                   2811:     newWindow = window.open("","IMSimport","HEIGHT=700,WIDTH=750,scrollbars=yes");
                   2812:     newWindow.location.href = newlocation;
                   2813: }
                   2814: 
                   2815: 
                   2816: function finishpick() {
                   2817:     var title=this.document.forms.extimport.title.value;
                   2818:     var url=this.document.forms.extimport.url.value;
                   2819:     var form=this.document.forms.extimport.useform.value;
                   2820:     eval
                   2821:      ('this.document.forms.'+form+'.importdetail.value="'+title+'='+url+
                   2822:     '";this.document.forms.'+form+'.submit();');
                   2823: }
                   2824: 
                   2825: function changename(folderpath,index,oldtitle,container,pagesymb) {
                   2826:     var title=prompt('New Title',oldtitle);
                   2827:     if (title) {
                   2828: 	this.document.forms.renameform.title.value=title;
                   2829: 	this.document.forms.renameform.cmd.value='rename_'+index;
                   2830:         if (container == 'sequence') {
                   2831: 	    this.document.forms.renameform.folderpath.value=folderpath;
                   2832:         }
                   2833:         if (container == 'page') {
                   2834:             this.document.forms.renameform.pagepath.value=folderpath;
                   2835:             this.document.forms.renameform.pagesymb.value=pagesymb;
                   2836:         }
                   2837:         this.document.forms.renameform.submit();
                   2838:     }
                   2839: }
                   2840: 
                   2841: function removeres(folderpath,index,oldtitle,container,pagesymb) {
                   2842:     if (confirm('WARNING: Removing a resource makes associated grades and scores inaccessible!\\nRemove "'+oldtitle+'"?')) {
                   2843: 	this.document.forms.renameform.cmd.value='del_'+index;
                   2844:         if (container == 'sequence') {
                   2845:             this.document.forms.renameform.folderpath.value=folderpath;
                   2846:         }
                   2847:         if (container == 'page') {
                   2848:             this.document.forms.renameform.pagepath.value=folderpath;
                   2849:             this.document.forms.renameform.pagesymb.value=pagesymb;
                   2850:         }
                   2851:         this.document.forms.renameform.submit();
                   2852:     }
                   2853: }
                   2854: 
                   2855: function cutres(folderpath,index,oldtitle,container,pagesymb) {
                   2856:     if (confirm('WARNING: Cutting a resource makes associated grades and scores inaccessible!\\nGrades remain inaccessible if resource is pasted into another folder.\\nCut "'+oldtitle+'"?')) {
                   2857: 	this.document.forms.renameform.cmd.value='cut_'+index;
                   2858: 	this.document.forms.renameform.markcopy.value=index;
                   2859:         if (container == 'sequence') {
                   2860:             this.document.forms.renameform.folderpath.value=folderpath;
                   2861:         }
                   2862:         if (container == 'page') {
                   2863:             this.document.forms.renameform.pagepath.value=folderpath;
                   2864:             this.document.forms.renameform.pagesymb.value=pagesymb;
                   2865:         }
                   2866:         this.document.forms.renameform.submit();
                   2867:     }
                   2868: }
                   2869: 
                   2870: function markcopy(folderpath,index,oldtitle,container,pagesymb) {
                   2871:     this.document.forms.renameform.markcopy.value=index;
                   2872:     if (container == 'sequence') {
                   2873: 	this.document.forms.renameform.folderpath.value=folderpath;
                   2874:     }
                   2875:     if (container == 'page') {
                   2876: 	this.document.forms.renameform.pagepath.value=folderpath;
                   2877: 	this.document.forms.renameform.pagesymb.value=pagesymb;
                   2878:     }
                   2879:     this.document.forms.renameform.submit();
                   2880: }
                   2881: 
                   2882: ENDNEWSCRIPT
                   2883: }
1.1       www      2884: 1;
                   2885: __END__

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