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

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

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