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

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

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