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

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

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