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