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

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

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