Annotation of loncom/interface/londocs.pm, revision 1.198
1.1 www 1: # The LearningOnline Network
1.2 www 2: # Documents
1.1 www 3: #
1.198 ! raeburn 4: # $Id: londocs.pm,v 1.197 2005/07/26 13:30:34 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') {
1.198 ! raeburn 785: $content_name = 'resources/'.$count.'/'.$filename;
1.157 raeburn 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) = @_;
1.198 ! raeburn 792: my ($dirpath,$container);
1.197 raeburn 793: my %allfiles = ();
794: my %codebase = ();
1.198 ! raeburn 795: if ($url =~ m-(.*/)([^/]+)$-) {
! 796: $dirpath = $1;
! 797: $container = $2;
! 798: } else {
! 799: $dirpath = $url;
! 800: $container = '';
! 801: }
1.197 raeburn 802: &Apache::lonnet::extract_embedded_items(undef,undef,\%allfiles,\%codebase,$content);
803: foreach my $embed_file (keys(%allfiles)) {
804: my $filename;
805: if ($embed_file =~ m#([^/]+)$#) {
806: $filename = $1;
807: } else {
808: $filename = $embed_file;
809: }
810: my $newname = 'res/'.$filename;
811: my ($rtncode,$embed_content,$repstatus);
812: my $embed_url;
813: if ($embed_file =~ m-^/-) {
814: $embed_url = $embed_file; # points to absolute path
815: } else {
816: if ($embed_file =~ m-https?://-) {
817: next; # points to url
818: } else {
1.198 ! raeburn 819: $embed_url = $dirpath.$embed_file; # points to relative path
1.197 raeburn 820: }
821: }
822: if ($caller eq 'resource') {
823: my $respath = $Apache::lonnet::perlvar{'lonDocRoot'}.'/res';
824: my $embed_path = &Apache::lonnet::filelocation($respath,$embed_url);
825: $embed_content = &Apache::lonnet::getfile($embed_path);
826: unless ($embed_content eq -1) {
827: $repstatus = 'ok';
828: }
829: } elsif ($caller eq 'uploaded') {
830:
831: $repstatus = &Apache::lonnet::getuploaded('GET',$embed_url,$cdom,$cnum,\$embed_content,$rtncode);
832: }
833: if ($repstatus eq 'ok') {
834: my $destination = $tempexport.'/resources/'.$count.'/res';
835: if (!-e "$destination") {
836: mkdir($destination,0755);
837: }
838: $destination .= '/'.$filename;
839: my $copiedfile;
840: if ($copiedfile = Apache::File->new('>'.$destination)) {
841: print $copiedfile $embed_content;
1.198 ! raeburn 842: push @{$href}, 'resources/'.$count.'/res/'.$filename;
1.197 raeburn 843: my $attrib_regexp = '';
844: if (@{$allfiles{$embed_file}} > 1) {
845: $attrib_regexp = join('|',@{$allfiles{$embed_file}});
846: } else {
847: $attrib_regexp = $allfiles{$embed_file}[0];
848: }
849: $$content =~ s#($attrib_regexp\s*=\s*['"]?)\Q$embed_file\E(['"]?)#$1$newname$2#gi;
1.198 ! raeburn 850: if ($caller eq 'resource' && $container =~ /\.(problem|library)$/) {
1.197 raeburn 851: $$content =~ s#\Q$embed_file\E#$newname#gi;
852: }
853: }
854: } else {
855: $$message .= 'replication of embedded file - '.$embed_file.' in '.$url.' failed, reason -'.$rtncode."<br />\n";
856: }
857: }
1.157 raeburn 858: return;
1.143 raeburn 859: }
1.74 www 860:
1.158 raeburn 861: sub store_template {
862: my ($contents,$tempexport,$count,$content_type) = @_;
863: if ($contents) {
1.159 raeburn 864: if ($tempexport) {
865: if (!-e $tempexport.'/resources') {
866: mkdir($tempexport.'/resources',0700);
867: }
868: if (!-e $tempexport.'/resources/'.$count) {
869: mkdir($tempexport.'/resources/'.$count,0700);
870: }
871: my $destination = $tempexport.'/resources/'.$count.'/'.$content_type.'.xml';
872: my $storetemplate;
873: if ($storetemplate = Apache::File->new('>'.$destination)) {
874: print $storetemplate $contents;
875: close($storetemplate);
876: }
877: if ($content_type eq 'external') {
1.198 ! raeburn 878: return 'resources/'.$count.'/'.$content_type.'.html';
1.159 raeburn 879: } else {
1.198 ! raeburn 880: return 'resources/'.$count.'/'.$content_type.'.xml';
1.159 raeburn 881: }
1.158 raeburn 882: }
883: }
884: }
885:
1.73 bowersj2 886: # Imports the given (name, url) resources into the course
887: # coursenum, coursedom, and folder must precede the list
888: sub group_import {
889: my $coursenum = shift;
890: my $coursedom = shift;
891: my $folder = shift;
1.142 raeburn 892: my $container = shift;
893: my $caller = shift;
1.73 bowersj2 894: while (@_) {
895: my $name = shift;
896: my $url = shift;
1.142 raeburn 897: if (($url =~ m#^/uploaded/$coursedom/$coursenum/(default_\d+\.)(page|sequence)$#) && ($caller eq 'londocs')) {
898: my $errtext = '';
899: my $fatal = 0;
900: my $newmapstr = '<map>'."\n".
901: '<resource id="1" src="" type="start"></resource>'."\n".
902: '<link from="1" to="2" index="1"></link>'."\n".
903: '<resource id="2" src="" type="finish"></resource>'."\n".
904: '</map>';
1.174 albertel 905: $env{'form.output'}=$newmapstr;
1.189 albertel 906: my $result=&Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
1.142 raeburn 907: 'output',$1.$2);
908: if ($result != m|^/uploaded/|) {
909: $errtext.='Map not saved: A network error occured when trying to save the new map. ';
910: $fatal = 2;
911: }
912: if ($fatal) {
913: return ($errtext,$fatal);
914: }
915: }
1.73 bowersj2 916: if ($url) {
1.178 www 917: my $idx = &Apache::lonratedt::getresidx($url);
1.73 bowersj2 918: $Apache::lonratedt::order[$#Apache::lonratedt::order+1]=$idx;
919: my $ext = 'false';
920: if ($url=~/^http:\/\//) { $ext = 'true'; }
921: $url =~ s/:/\:/g;
922: $name =~ s/:/\:/g;
923: $Apache::lonratedt::resources[$idx] =
924: join ':', ($name, $url, $ext, 'normal', 'res');
925: }
926: }
1.142 raeburn 927: return &storemap($coursenum, $coursedom, $folder.'.'.$container);
1.73 bowersj2 928: }
929:
1.114 albertel 930: sub breadcrumbs {
931: my ($where)=@_;
932: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.142 raeburn 933: my (@folders);
1.174 albertel 934: if ($env{'form.pagepath'}) {
935: @folders = split('&',$env{'form.pagepath'});
1.142 raeburn 936: } else {
1.174 albertel 937: @folders=split('&',$env{'form.folderpath'});
1.142 raeburn 938: }
1.116 albertel 939: my $folderpath;
1.168 www 940: my $cpinfo='';
1.174 albertel 941: if ($env{'form.markedcopy_url'}) {
942: &Apache::lonnet::logthis('Found '.$env{'form.markedcopy_url'});
1.168 www 943: $cpinfo='&markedcopy_url='.
1.174 albertel 944: &Apache::lonnet::escape($env{'form.markedcopy_url'}).
1.168 www 945: '&markedcopy_title='.
1.174 albertel 946: &Apache::lonnet::escape($env{'form.markedcopy_title'});
1.168 www 947: }
1.116 albertel 948: while (@folders) {
949: my $folder=shift(@folders);
950: my $foldername=shift(@folders);
951: if ($folderpath) {$folderpath.='&';}
952: $folderpath.=$folder.'&'.$foldername;
953: my $url='/adm/coursedocs?folderpath='.
954: &Apache::lonnet::escape($folderpath);
1.114 albertel 955: &Apache::lonhtmlcommon::add_breadcrumb(
1.168 www 956: {'href'=>$url.$cpinfo,
1.114 albertel 957: 'title'=>&Apache::lonnet::unescape($foldername),
1.117 albertel 958: 'text'=>'<font size="+1">'.
959: &Apache::lonnet::unescape($foldername).'</font>'
960: });
1.114 albertel 961:
962:
963: }
1.137 albertel 964: return &Apache::lonhtmlcommon::breadcrumbs(undef,undef,undef,undef,undef,
965: 0,'nohelp');
1.114 albertel 966: }
967:
1.7 www 968: sub editor {
1.188 raeburn 969: my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output)=@_;
1.10 www 970: my $errtext='';
971: my $fatal=0;
1.142 raeburn 972: my $container='sequence';
1.174 albertel 973: if ($env{'form.pagepath'}) {
1.142 raeburn 974: $container='page';
975: }
1.10 www 976: ($errtext,$fatal)=
1.142 raeburn 977: &mapread($coursenum,$coursedom,$folder.'.'.$container);
1.17 www 978: if ($#Apache::lonratedt::order<1) {
1.178 www 979: my $idx=&Apache::lonratedt::getresidx();
980: if ($idx<=0) { $idx=1; }
981: $Apache::lonratedt::order[0]=$idx;
982: $Apache::lonratedt::resources[$idx]='';
1.17 www 983: }
1.174 albertel 984: if (defined($env{'form.markcopy'})) {
1.168 www 985: # Mark for copying
1.174 albertel 986: my ($title,$url)=split(':',$Apache::lonratedt::resources[$Apache::lonratedt::order[$env{'form.markcopy'}]]);
987: $env{'form.markedcopy_title'}=$title;
988: $env{'form.markedcopy_url'}=$url;
1.168 www 989: }
990: $r->print(&breadcrumbs($folder));
1.7 www 991: if ($fatal) {
992: $r->print('<p><font color="red">'.$errtext.'</font></p>');
993: } else {
994: # ------------------------------------------------------------ Process commands
1.121 www 995:
1.16 www 996: # ---------------- if they are for this folder and user allowed to make changes
1.174 albertel 997: if (($allowed) && ($env{'form.folder'} eq $folder)) {
1.123 www 998: # set parameters and change order
1.174 albertel 999: if (defined($env{'form.setparms'})) {
1000: my $idx=$env{'form.setparms'};
1.123 www 1001: # set parameters
1.174 albertel 1002: if ($env{'form.randpick_'.$idx}) {
1003: &Apache::lonratedt::storeparameter($idx,'parameter_randompick',$env{'form.randpick_'.$idx},'int_pos');
1.121 www 1004: } else {
1.122 www 1005: &Apache::lonratedt::delparameter($idx,'parameter_randompick');
1.121 www 1006: }
1.174 albertel 1007: if ($env{'form.hidprs_'.$idx}) {
1.122 www 1008: &Apache::lonratedt::storeparameter($idx,'parameter_hiddenresource','yes','string_yesno');
1.121 www 1009: } else {
1.122 www 1010: &Apache::lonratedt::delparameter($idx,'parameter_hiddenresource');
1.121 www 1011: }
1.174 albertel 1012: if ($env{'form.encprs_'.$idx}) {
1.122 www 1013: &Apache::lonratedt::storeparameter($idx,'parameter_encrypturl','yes','string_yesno');
1.121 www 1014: } else {
1.122 www 1015: &Apache::lonratedt::delparameter($idx,'parameter_encrypturl');
1.121 www 1016: }
1017:
1.174 albertel 1018: if ($env{'form.newpos'}) {
1.123 www 1019: # change order
1020:
1.174 albertel 1021: my $newpos=$env{'form.newpos'}-1;
1022: my $currentpos=$env{'form.currentpos'}-1;
1.125 www 1023: my $i;
1024: my @neworder=();
1025: if ($newpos>$currentpos) {
1026: # moving stuff up
1027: for ($i=0;$i<$currentpos;$i++) {
1028: $neworder[$i]=$Apache::lonratedt::order[$i];
1029: }
1030: for ($i=$currentpos;$i<$newpos;$i++) {
1031: $neworder[$i]=$Apache::lonratedt::order[$i+1];
1032: }
1033: $neworder[$newpos]=$Apache::lonratedt::order[$currentpos];
1034: for ($i=$newpos+1;$i<=$#Apache::lonratedt::order;$i++) {
1035: $neworder[$i]=$Apache::lonratedt::order[$i];
1036: }
1037: } else {
1038: # moving stuff down
1039: for ($i=0;$i<$newpos;$i++) {
1040: $neworder[$i]=$Apache::lonratedt::order[$i];
1041: }
1042: $neworder[$newpos]=$Apache::lonratedt::order[$currentpos];
1043: for ($i=$newpos+1;$i<$currentpos+1;$i++) {
1044: $neworder[$i]=$Apache::lonratedt::order[$i-1];
1045: }
1046: for ($i=$currentpos+1;$i<=$#Apache::lonratedt::order;$i++) {
1047: $neworder[$i]=$Apache::lonratedt::order[$i];
1048: }
1049: }
1050: @Apache::lonratedt::order=@neworder;
1.124 www 1051: }
1052: # store the changed version
1.123 www 1053:
1.142 raeburn 1054: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
1.124 www 1055: if ($fatal) {
1056: $r->print('<p><font color="red">'.$errtext.'</font></p>');
1057: return;
1.123 www 1058: }
1.124 www 1059:
1060: }
1.174 albertel 1061: if ($env{'form.pastemarked'}) {
1.168 www 1062: # paste resource to end of list
1.174 albertel 1063: my $url=$env{'form.markedcopy_url'};
1064: my $title=$env{'form.markedcopy_title'};
1.168 www 1065: # Maps need to be copied first
1066: if (($url=~/\.(page|sequence)$/) || ($url=~/^\/uploaded\//)) {
1067: $title=&mt('Copy of').' '.$title;
1068: my $newid=$$.time;
1069: $url=~/^(.+)\.(\w+)$/;
1070: my $newurl=$1.$newid.'.'.$2;
1071: my $storefn=$newurl;
1072: $storefn=~s/^\/\w+\/\w+\/\w+\///;
1073: &Apache::loncreatecourse::writefile
1.174 albertel 1074: ($env{'request.course.id'},$storefn,
1.168 www 1075: &Apache::lonnet::getfile($url));
1076: $url=$newurl;
1077: }
1078: $title=~s/\</\<\;/g;
1079: $title=~s/\>/\>\;/g;
1080: $title=~s/\:/\:/g;
1081: my $ext='false';
1082: if ($url=~/^http\:\/\//) { $ext='true'; }
1083: $url=~s/\:/\:/g;
1084: # Now insert the URL at the bottom
1.179 www 1085: my $newidx=&Apache::lonratedt::getresidx($url);
1.168 www 1086: $Apache::lonratedt::resources[$newidx]=
1087: $title.':'.$url.':'.$ext.':normal:res';
1088: $Apache::lonratedt::order[1+$#Apache::lonratedt::order]=$newidx;
1089: # Store the result
1090: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
1091: if ($fatal) {
1092: $r->print('<p><font color="red">'.$errtext.'</font></p>');
1093: return;
1094: }
1.123 www 1095:
1.168 www 1096: }
1.188 raeburn 1097: $r->print($upload_output);
1.174 albertel 1098: if ($env{'form.cmd'}) {
1099: my ($cmd,$idx)=split(/\_/,$env{'form.cmd'});
1.10 www 1100: if ($cmd eq 'del') {
1.128 albertel 1101: my (undef,$url)=split(':',$Apache::lonratedt::resources[$Apache::lonratedt::order[$idx]]);
1.187 www 1102: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
1103: ($url!~/\.(page|sequence|problem|exam|quiz|assess|survey|form|library)$/)) {
1104: &Apache::lonnet::removeuploadedurl($url);
1105: } else {
1106: &Apache::lonratedt::makezombie($Apache::lonratedt::order[$idx]);
1.128 albertel 1107: }
1.10 www 1108: for (my $i=$idx;$i<$#Apache::lonratedt::order;$i++) {
1109: $Apache::lonratedt::order[$i]=
1110: $Apache::lonratedt::order[$i+1];
1111: }
1112: $#Apache::lonratedt::order--;
1.171 www 1113: } elsif ($cmd eq 'cut') {
1114: my (undef,$url)=split(':',$Apache::lonratedt::resources[$Apache::lonratedt::order[$idx]]);
1.179 www 1115: &Apache::lonratedt::makezombie($Apache::lonratedt::order[$idx]);
1.171 www 1116: for (my $i=$idx;$i<$#Apache::lonratedt::order;$i++) {
1117: $Apache::lonratedt::order[$i]=
1118: $Apache::lonratedt::order[$i+1];
1119: }
1120: $#Apache::lonratedt::order--;
1.10 www 1121: } elsif ($cmd eq 'up') {
1.38 www 1122: if (($idx) && (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.10 www 1128: } elsif ($cmd eq 'down') {
1.38 www 1129: if (defined($Apache::lonratedt::order[$idx+1])) {
1.10 www 1130: my $i=$Apache::lonratedt::order[$idx+1];
1131: $Apache::lonratedt::order[$idx+1]=
1132: $Apache::lonratedt::order[$idx];
1133: $Apache::lonratedt::order[$idx]=$i;
1.38 www 1134: }
1.36 www 1135: } elsif ($cmd eq 'rename') {
1.142 raeburn 1136: my $ratstr = $Apache::lonratedt::resources[$Apache::lonratedt::order[$idx]];
1.36 www 1137: my ($rtitle,@rrest)=split(/\:/,
1138: $Apache::lonratedt::resources[
1139: $Apache::lonratedt::order[$idx]]);
1.38 www 1140: my $comment=
1.174 albertel 1141: &HTML::Entities::decode($env{'form.title'});
1.36 www 1142: $comment=~s/\</\<\;/g;
1143: $comment=~s/\>/\>\;/g;
1144: $comment=~s/\:/\:/g;
1.144 albertel 1145: if ($comment=~/\S/) {
1146: $Apache::lonratedt::resources[
1.36 www 1147: $Apache::lonratedt::order[$idx]]=
1.144 albertel 1148: $comment.':'.join(':',@rrest);
1149: }
1.10 www 1150: }
1151: # Store the changed version
1.104 albertel 1152: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.142 raeburn 1153: $folder.'.'.$container);
1.104 albertel 1154: if ($fatal) {
1155: $r->print('<p><font color="red">'.$errtext.'</font></p>');
1156: return;
1157: }
1.8 www 1158: }
1.11 www 1159: # Group import/search
1.174 albertel 1160: if ($env{'form.importdetail'}) {
1.73 bowersj2 1161: my @imports;
1.174 albertel 1162: foreach (split(/\&/,$env{'form.importdetail'})) {
1.73 bowersj2 1163: if (defined($_)) {
1164: my ($name,$url)=split(/\=/,$_);
1165: $name=&Apache::lonnet::unescape($name);
1166: $url=&Apache::lonnet::unescape($url);
1167: push @imports, $name, $url;
1168: }
1169: }
1.11 www 1170: # Store the changed version
1.104 albertel 1171: ($errtext,$fatal)=group_import($coursenum, $coursedom, $folder,
1.142 raeburn 1172: $container,'londocs',@imports);
1.104 albertel 1173: if ($fatal) {
1174: $r->print('<p><font color="red">'.$errtext.'</font></p>');
1175: return;
1176: }
1.11 www 1177: }
1.53 www 1178: # Loading a complete map
1.174 albertel 1179: if (($env{'form.importmap'}) && ($env{'form.loadmap'})) {
1180: foreach (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
1.181 www 1181: my ($title,$url,$ext,$type)=split(/\:/,$_);
1182: my $idx=&Apache::lonratedt::getresidx($url);
1.53 www 1183: $Apache::lonratedt::resources[$idx]=$_;
1184: $Apache::lonratedt::order
1.104 albertel 1185: [$#Apache::lonratedt::order+1]=$idx;
1186: }
1.53 www 1187:
1188: # Store the changed version
1.104 albertel 1189: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.142 raeburn 1190: $folder.'.'.$container);
1.104 albertel 1191: if ($fatal) {
1192: $r->print('<p><font color="red">'.$errtext.'</font></p>');
1193: return;
1194: }
1.53 www 1195: }
1.16 www 1196: }
1197: # ---------------------------------------------------------------- End commands
1.7 www 1198: # ---------------------------------------------------------------- Print screen
1.10 www 1199: my $idx=0;
1.148 www 1200: my $shown=0;
1.10 www 1201: $r->print('<table>');
1202: foreach (@Apache::lonratedt::order) {
1203: my ($name,$url)=split(/\:/,$Apache::lonratedt::resources[$_]);
1204: unless ($name) { $name=(split(/\//,$url))[-1]; }
1.148 www 1205: unless ($name) { $idx++; next; }
1.112 raeburn 1206: $r->print(&entryline($idx,$name,$url,$folder,$allowed,$_,$coursenum));
1.10 www 1207: $idx++;
1.148 www 1208: $shown++;
1.10 www 1209: }
1.148 www 1210: unless ($shown) {
1.131 www 1211: $r->print('<tr><td>'.&mt('Currently no documents.').'</td></tr>');
1212: }
1.168 www 1213: $r->print("\n</table>\n");
1.174 albertel 1214: if ($env{'form.markedcopy_url'}) {
1.168 www 1215: $r->print(<<ENDPASTE);
1216: <p><form name="pasteform" action="/adm/coursedocs" method="post">
1.174 albertel 1217: <input type="hidden" name="markedcopy_url" value="$env{'form.markedcopy_url'}" />
1218: <input type="hidden" name="markedcopy_title" value="$env{'form.markedcopy_title'}" />
1.168 www 1219: ENDPASTE
1220: $r->print(
1221: '<input type="submit" name="pastemarked" value="'.&mt('Paste').
1222: '" /> '.&Apache::loncommon::filedescription(
1.174 albertel 1223: (split(/\./,$env{'form.markedcopy_url'}))[-1]).': '.
1224: $env{'form.markedcopy_title'});
1.168 www 1225: if ($container eq 'page') {
1226: $r->print(<<PAGEINFO);
1.174 albertel 1227: <input type="hidden" name="pagepath" value="$env{'form.pagepath'}" />
1228: <input type="hidden" name="pagesymb" value="$env{'form.pagesymb'}" />
1.168 www 1229: PAGEINFO
1230: } else {
1231: $r->print(<<FOLDERINFO);
1.174 albertel 1232: <input type="hidden" name="folderpath" value="$env{'form.folderpath'}" />
1.168 www 1233: FOLDERINFO
1234: }
1235: $r->print('</form></p>');
1236: }
1.7 www 1237: }
1238: }
1.1 www 1239:
1.188 raeburn 1240: sub process_file_upload {
1.194 raeburn 1241: my ($upload_output,$coursenum,$coursedom,$allfiles,$codebase,$uploadcmd) = @_;
1.188 raeburn 1242: # upload a file, if present
1243: my $parseaction;
1.190 albertel 1244: if ($env{'form.parserflag'}) {
1.188 raeburn 1245: $parseaction = 'parse';
1246: }
1247: my $phase_status;
1248: my $folder=$env{'form.folder'};
1.194 raeburn 1249: if ($folder eq '') {
1.188 raeburn 1250: $folder='default';
1251: }
1.194 raeburn 1252: if ( ($folder=~/^$uploadcmd/) || ($uploadcmd eq 'default') ) {
1.188 raeburn 1253: my $errtext='';
1254: my $fatal=0;
1255: my $container='sequence';
1256: if ($env{'form.pagepath'}) {
1257: $container='page';
1258: }
1259: ($errtext,$fatal)=
1260: &mapread($coursenum,$coursedom,$folder.'.'.$container);
1261: if ($#Apache::lonratedt::order<1) {
1262: $Apache::lonratedt::order[0]=1;
1263: $Apache::lonratedt::resources[1]='';
1264: }
1265: if ($fatal) {
1266: return 'failed';
1267: }
1268: my $destination = 'docs/';
1.194 raeburn 1269: if ($folder =~ /^supplemental/) {
1270: $destination = 'supplemental/';
1271: }
1272: if (($folder eq 'default') || ($folder eq 'supplemental')) {
1.188 raeburn 1273: $destination .= 'default/';
1.194 raeburn 1274: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
1275: $destination .= $2.'/';
1.188 raeburn 1276: }
1277: # this is for a course, not a user, so set coursedoc flag
1278: # probably the only place in the system where this should be "1"
1279: my $newidx=&Apache::lonratedt::getresidx();
1280: $destination .= $newidx;
1.190 albertel 1281: my $url=&Apache::lonnet::userfileupload('uploaddoc',1,$destination,
1282: $parseaction,$allfiles,
1283: $codebase);
1.188 raeburn 1284: my $ext='false';
1285: if ($url=~/^http\:\/\//) { $ext='true'; }
1286: $url=~s/\:/\:/g;
1287: my $comment=$env{'form.comment'};
1288: $comment=~s/\</\<\;/g;
1289: $comment=~s/\>/\>\;/g;
1290: $comment=~s/\:/\:/g;
1291: if ($folder=~/^supplemental/) {
1292: $comment=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
1293: $env{'user.domain'}.'___&&&___'.$comment;
1294: }
1295:
1296: $Apache::lonratedt::resources[$newidx]=
1297: $comment.':'.$url.':'.$ext.':normal:res';
1.190 albertel 1298: $Apache::lonratedt::order[$#Apache::lonratedt::order+1]= $newidx;
1299: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1300: $folder.'.'.$container);
1.188 raeburn 1301: if ($fatal) {
1302: $$upload_output .= '<p><font color="red">'.$errtext.'</font></p>';
1303: return 'failed';
1304: } else {
1305: if ($parseaction eq 'parse') {
1.190 albertel 1306: my $total_embedded = keys(%{$allfiles});
1.188 raeburn 1307: if ($total_embedded > 0) {
1308: my $num = 0;
1309: $$upload_output .= 'This file contains embedded multimedia objects, which need to be uploaded to LON-CAPA.<br />
1310: <form name="upload_embedded" action="/adm/coursedocs"
1311: method="post" enctype="multipart/form-data">
1312: <input type="hidden" name="folderpath" value="'.$env{'form.folderpath'}.'" /> <input type="hidden" name="cmd" value="upload_embedded" />
1313: <input type="hidden" name="newidx" value="'.$newidx.'" />
1314: <input type="hidden" name="primaryurl" value="'.&Apache::lonnet::escape($url).'" />
1315: <input type="hidden" name="phasetwo" value="'.$total_embedded.'" />';
1316: $$upload_output .= '<b>Upload embedded files</b>:<br />
1317: <table>';
1.190 albertel 1318: foreach my $embed_file (keys(%{$allfiles})) {
1.188 raeburn 1319: $$upload_output .= '<tr><td>'.$embed_file.
1.190 albertel 1320: '<input name="embedded_item_'.$num.'" type="file" />
1321: <input name="embedded_orig_'.$num.'" type="hidden" value="'.&Apache::lonnet::escape($embed_file).'" />';
1.188 raeburn 1322: my $attrib;
1323: if (@{$$allfiles{$embed_file}} > 1) {
1324: $attrib = join(':',@{$$allfiles{$embed_file}});
1325: } else {
1326: $attrib = $$allfiles{$embed_file}[0];
1327: }
1328: $$upload_output .=
1329: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.$attrib.'" />';
1330: if (exists($$codebase{$embed_file})) {
1331: $$upload_output .=
1332: '<input name="codebase_'.$num.'" type="hidden" value="'.&Apache::lonnet::escape($$codebase{$embed_file}).'" />';
1333: }
1334: $$upload_output .= '</td></tr>';
1335: $num ++;
1336: }
1337: $phase_status = 'phasetwo';
1338: $$upload_output .= '</table><br />
1339: <input type ="submit" value="Complete upload" />
1340: </form>';
1341: } else {
1342: $$upload_output .= 'No embedded items identified<br />';
1343: }
1344: }
1345: }
1346: }
1347: return $phase_status;
1348: }
1349:
1350: sub process_secondary_uploads {
1351: my ($upload_output,$coursedom,$coursenum,$formname,$num,$newidx) = @_;
1352: my $folder=$env{'form.folder'};
1353: my $destination = 'docs/';
1.195 raeburn 1354: if ($folder =~ /^supplemental/) {
1355: $destination = 'supplemental/';
1356: }
1357: if (($folder eq 'default') || ($folder eq 'supplemental')) {
1.188 raeburn 1358: $destination .= 'default/';
1.195 raeburn 1359: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
1.188 raeburn 1360: $destination .= $1.'/';
1361: }
1362: $destination .= $newidx;
1363: my ($url,$filename);
1364: $url=&Apache::lonnet::userfileupload($formname.$num,1,$destination);
1365: ($filename) = ($url =~ m-^/uploaded/$coursedom/$coursenum/$destination/(.+)$-);
1366: return $filename;
1367: }
1368:
1.8 www 1369: # --------------------------------------------------------------- An entry line
1370:
1371: sub entryline {
1.112 raeburn 1372: my ($index,$title,$url,$folder,$allowed,$residx,$coursenum)=@_;
1.38 www 1373: $title=~s/\&colon\;/\:/g;
1374: $title=&HTML::Entities::encode(&HTML::Entities::decode(
1.109 albertel 1375: &Apache::lonnet::unescape($title)),'"<>&\'');
1.38 www 1376: my $renametitle=$title;
1377: my $foldertitle=$title;
1.142 raeburn 1378: my $pagetitle=$title;
1.122 www 1379: my $orderidx=$Apache::lonratedt::order[$index];
1.109 albertel 1380: if ($title=~ /^(\d+)___&&&___(\w+)___&&&___(\w+)___&&&___(.*)$/ ) {
1381: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
1382: $renametitle=$4;
1383: $title='<i>'.&Apache::lonlocal::locallocaltime($1).'</i> '.
1384: &Apache::loncommon::plainname($2,$3).': <br />'.
1385: $foldertitle;
1386: }
1.38 www 1387: $renametitle=~s/\"\;/\\\"/g;
1.8 www 1388: my $line='<tr>';
1389: # Edit commands
1.142 raeburn 1390: my $container;
1.120 www 1391: my $folderpath;
1.174 albertel 1392: if ($env{'form.folderpath'}) {
1.142 raeburn 1393: $container = 'sequence';
1.174 albertel 1394: $folderpath=&Apache::lonnet::escape($env{'form.folderpath'});
1395: # $htmlfoldername=&HTML::Entities::encode($env{'form.foldername'},'<>&"');
1.120 www 1396: }
1.156 albertel 1397: my ($pagepath,$pagesymb);
1.174 albertel 1398: if ($env{'form.pagepath'}) {
1.142 raeburn 1399: $container = 'page';
1.174 albertel 1400: $pagepath=&Apache::lonnet::escape($env{'form.pagepath'});
1401: $pagesymb=&Apache::lonnet::escape($env{'form.pagesymb'});
1.142 raeburn 1402: }
1.168 www 1403: my $cpinfo='';
1.174 albertel 1404: if ($env{'form.markedcopy_url'}) {
1.168 www 1405: $cpinfo='&markedcopy_url='.
1.174 albertel 1406: &Apache::lonnet::escape($env{'form.markedcopy_url'}).
1.168 www 1407: '&markedcopy_title='.
1.174 albertel 1408: &Apache::lonnet::escape($env{'form.markedcopy_title'});
1.168 www 1409: }
1.109 albertel 1410: if ($allowed) {
1.123 www 1411: my $incindex=$index+1;
1412: my $selectbox='';
1.168 www 1413: if (($folder!~/^supplemental/) &&
1414: ($#Apache::lonratedt::order>0) &&
1415: ((split(/\:/,
1416: $Apache::lonratedt::resources[$Apache::lonratedt::order[0]]))[1]
1417: ne '') &&
1418: ((split(/\:/,
1419: $Apache::lonratedt::resources[$Apache::lonratedt::order[1]]))[1]
1420: ne '')) {
1.123 www 1421: $selectbox=
1.124 www 1422: '<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
1.123 www 1423: '<select name="newpos" onChange="this.form.submit()">';
1424: for (my $i=1;$i<=$#Apache::lonratedt::order+1;$i++) {
1425: if ($i==$incindex) {
1426: $selectbox.='<option value="" selected="1">('.$i.')</option>';
1427: } else {
1428: $selectbox.='<option value="'.$i.'">'.$i.'</option>';
1429: }
1430: }
1431: $selectbox.='</select>';
1432: }
1.119 www 1433: my %lt=&Apache::lonlocal::texthash(
1434: 'up' => 'Move Up',
1.109 albertel 1435: 'dw' => 'Move Down',
1436: 'rm' => 'Remove',
1.171 www 1437: 'ct' => 'Cut',
1.168 www 1438: 'rn' => 'Rename',
1439: 'cp' => 'Copy');
1.174 albertel 1440: if ($env{'form.pagepath'}) {
1.142 raeburn 1441: $line.=(<<END);
1442: <form name="entry_$index" action="/adm/coursedocs" method="post">
1.174 albertel 1443: <input type="hidden" name="pagepath" value="$env{'form.pagepath'}" />
1444: <input type="hidden" name="pagesymb" value="$env{'form.pagesymb'}" />
1445: <input type="hidden" name="markedcopy_url" value="$env{'form.markedcopy_url'}" />
1446: <input type="hidden" name="markedcopy_title" value="$env{'form.markedcopy_title'}" />
1.142 raeburn 1447: <input type="hidden" name="setparms" value="$orderidx" />
1448: <td><table border='0' cellspacing='2' cellpadding='0'>
1449: <tr><td bgcolor="#DDDDDD">
1.168 www 1450: <a href='/adm/coursedocs?cmd=up_$index&pagepath=$pagepath&pagesymb=$pagesymb$cpinfo'>
1.142 raeburn 1451: <img src="${iconpath}move_up.gif" alt='$lt{'up'}' border='0' /></a></td></tr>
1452: <tr><td bgcolor="#DDDDDD">
1.168 www 1453: <a href='/adm/coursedocs?cmd=down_$index&pagepath=$pagepath&pagesymb=$pagesymb$cpinfo'>
1.142 raeburn 1454: <img src="${iconpath}move_down.gif" alt='$lt{'dw'}' border='0' /></a></td></tr>
1455: </table></td>
1456: <td>$selectbox
1457: </td><td bgcolor="#DDDDDD">
1.156 albertel 1458: <a href='javascript:removeres("$pagepath","$index","$renametitle","page","$pagesymb");'>
1.142 raeburn 1459: <font size="-2" color="#990000">$lt{'rm'}</font></a>
1.171 www 1460: <a href='javascript:cutres("$pagepath","$index","$renametitle","page","$pagesymb");'>
1461: <font size="-2" color="#550044">$lt{'ct'}</font></a>
1.156 albertel 1462: <a href='javascript:changename("$pagepath","$index","$renametitle","page","$pagesymb");'>
1.168 www 1463: <font size="-2" color="#009900">$lt{'rn'}</font></a>
1464: <a href='javascript:markcopy("$pagepath","$index","$renametitle","page","$pagesymb");'>
1465: <font size="-2" color="#000099">$lt{'cp'}</font></a></td>
1.142 raeburn 1466: END
1467: } else {
1468: $line.=(<<END);
1.121 www 1469: <form name="entry_$index" action="/adm/coursedocs" method="post">
1.174 albertel 1470: <input type="hidden" name="folderpath" value="$env{'form.folderpath'}" />
1471: <input type="hidden" name="markedcopy_url" value="$env{'form.markedcopy_url'}" />
1472: <input type="hidden" name="markedcopy_title" value="$env{'form.markedcopy_title'}" />
1.122 www 1473: <input type="hidden" name="setparms" value="$orderidx" />
1.54 www 1474: <td><table border='0' cellspacing='2' cellpadding='0'>
1475: <tr><td bgcolor="#DDDDDD">
1.168 www 1476: <a href='/adm/coursedocs?cmd=up_$index&folderpath=$folderpath$cpinfo'>
1.90 www 1477: <img src="${iconpath}move_up.gif" alt='$lt{'up'}' border='0' /></a></td></tr>
1.54 www 1478: <tr><td bgcolor="#DDDDDD">
1.168 www 1479: <a href='/adm/coursedocs?cmd=down_$index&folderpath=$folderpath$cpinfo'>
1.90 www 1480: <img src="${iconpath}move_down.gif" alt='$lt{'dw'}' border='0' /></a></td></tr>
1.123 www 1481: </table></td>
1482: <td>$selectbox
1483: </td><td bgcolor="#DDDDDD">
1.142 raeburn 1484: <a href='javascript:removeres("$folderpath","$index","$renametitle","sequence");'>
1.90 www 1485: <font size="-2" color="#990000">$lt{'rm'}</font></a>
1.171 www 1486: <a href='javascript:cutres("$folderpath","$index","$renametitle","sequence");'>
1487: <font size="-2" color="#550044">$lt{'ct'}</font></a>
1.142 raeburn 1488: <a href='javascript:changename("$folderpath","$index","$renametitle","sequence");'>
1.168 www 1489: <font size="-2" color="#009900">$lt{'rn'}</font></a>
1490: <a href='javascript:markcopy("$folderpath","$index","$renametitle","sequence");'>
1491: <font size="-2" color="#000099">$lt{'cp'}</font></a></td>
1.8 www 1492: END
1.142 raeburn 1493: }
1.8 www 1494: }
1.16 www 1495: # Figure out what kind of a resource this is
1496: my ($extension)=($url=~/\.(\w+)$/);
1497: my $uploaded=($url=~/^\/*uploaded\//);
1.97 albertel 1498: my $icon=&Apache::loncommon::icon($url);
1.17 www 1499: my $isfolder=0;
1.142 raeburn 1500: my $ispage=0;
1.114 albertel 1501: my $folderarg;
1.142 raeburn 1502: my $pagearg;
1503: my $pagefile;
1.16 www 1504: if ($uploaded) {
1.135 albertel 1505: if ($extension eq 'sequence') {
1506: $icon=$iconpath.'/folder_closed.gif';
1507: $url=~/$coursenum\/([\/\w]+)\.sequence$/;
1508: $url='/adm/coursedocs?';
1509: $folderarg=$1;
1510: $isfolder=1;
1.142 raeburn 1511: } elsif ($extension eq 'page') {
1512: $icon=$iconpath.'/page.gif';
1513: $url=~/$coursenum\/([\/\w]+)\.page$/;
1514: $pagearg=$1;
1515: $url='/adm/coursedocs?';
1516: $ispage=1;
1.135 albertel 1517: } else {
1518: &Apache::lonnet::allowuploaded('/adm/coursedoc',$url);
1519: }
1.16 www 1520: }
1.18 www 1521: $url=~s/^http\&colon\;\/\//\/adm\/wrapper\/ext\//;
1.142 raeburn 1522: if ((!$isfolder) && ($residx) && ($folder!~/supplemental/) && (!$ispage)) {
1.113 albertel 1523: my $symb=&Apache::lonnet::symbclean(
1.50 www 1524: &Apache::lonnet::declutter('uploaded/'.
1.174 albertel 1525: $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
1526: $env{'course.'.$env{'request.course.id'}.'.num'}.'/'.$folder.
1.50 www 1527: '.sequence').
1528: '___'.$residx.'___'.
1.113 albertel 1529: &Apache::lonnet::declutter($url));
1530: (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
1531: $url=&Apache::lonnet::clutter($url);
1.127 albertel 1532: if ($url=~/^\/*uploaded\//) {
1533: $url=~/\.(\w+)$/;
1534: my $embstyle=&Apache::loncommon::fileembstyle($1);
1535: if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
1536: $url='/adm/wrapper'.$url;
1537: } elsif ($embstyle eq 'ssi') {
1538: #do nothing with these
1539: } elsif ($url!~/\.(sequence|page)$/) {
1540: $url='/adm/coursedocs/showdoc'.$url;
1541: }
1.145 albertel 1542: } elsif ($url=~m|^/ext/|) {
1543: $url='/adm/wrapper'.$url;
1.127 albertel 1544: }
1.152 albertel 1545: $url.=(($url=~/\?/)?'&':'?').'symb='.&Apache::lonnet::escape($symb);
1546: if ($container eq 'page') {
1.174 albertel 1547: my $symb=$env{'form.pagesymb'};
1.152 albertel 1548:
1549: $url=&Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
1.142 raeburn 1550: $url.=(($url=~/\?/)?'&':'?').'symb='.&Apache::lonnet::escape($symb);
1.152 albertel 1551: }
1.50 www 1552: }
1.120 www 1553: my $parameterset=' ';
1.114 albertel 1554: if ($isfolder) {
1555: my $foldername=&Apache::lonnet::escape($foldertitle);
1.174 albertel 1556: my $folderpath=$env{'form.folderpath'};
1.114 albertel 1557: if ($folderpath) { $folderpath.='&' };
1558: $folderpath.=$folderarg.'&'.$foldername;
1.168 www 1559: $url.='folderpath='.&Apache::lonnet::escape($folderpath).$cpinfo;
1.147 matthew 1560: $parameterset='<label>'.&mt('Randomly Pick: ').
1.165 www 1561: '<input type="text" size="4" onChange="this.form.submit()" name="randpick_'.$orderidx.'" value="'.
1.147 matthew 1562: (&Apache::lonratedt::getparameter($orderidx,
1563: 'parameter_randompick'))[0].
1.165 www 1564: '" />'.
1565: '<font size="-2"><a href="javascript:void(0)">'.&mt('Store').'</a></font></label>';
1.147 matthew 1566:
1.114 albertel 1567: }
1.142 raeburn 1568: if ($ispage) {
1569: my $pagename=&Apache::lonnet::escape($pagetitle);
1570: my $pagepath;
1.174 albertel 1571: my $folderpath=$env{'form.folderpath'};
1.142 raeburn 1572: if ($folderpath) { $pagepath = $folderpath.'&' };
1573: $pagepath.=$pagearg.'&'.$pagename;
1.174 albertel 1574: my $symb=$env{'form.pagesymb'};
1.152 albertel 1575: if (!$symb) {
1576: my $path='uploaded/'.
1.174 albertel 1577: $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
1578: $env{'course.'.$env{'request.course.id'}.'.num'}.'/';
1.152 albertel 1579: $symb=&Apache::lonnet::encode_symb($path.$folder.'.sequence',
1580: $residx,
1581: $path.$pagearg.'.page');
1582: }
1583: $url.='pagepath='.&Apache::lonnet::escape($pagepath).
1.168 www 1584: '&pagesymb='.&Apache::lonnet::escape($symb).$cpinfo;
1.142 raeburn 1585: }
1.113 albertel 1586: $line.='<td bgcolor="#FFFFBB"><a href="'.$url.'"><img src="'.$icon.
1587: '" border="0"></a></td>'.
1.119 www 1588: "<td bgcolor='#FFFFBB'><a href='$url'>$title</a></td>";
1.120 www 1589: if (($allowed) && ($folder!~/^supplemental/)) {
1590: my %lt=&Apache::lonlocal::texthash(
1591: 'hd' => 'Hidden',
1.165 www 1592: 'ec' => 'URL hidden');
1.122 www 1593: my $enctext=
1594: ((&Apache::lonratedt::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i?' checked="1"':'');
1595: my $hidtext=
1596: ((&Apache::lonratedt::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i?' checked="1"':'');
1.120 www 1597: $line.=(<<ENDPARMS);
1598: <td bgcolor="#BBBBFF"><font size='-2'>
1.165 www 1599: <nobr><label><input type="checkbox" name="hidprs_$orderidx" onClick="this.form.submit()" $hidtext /> $lt{'hd'}</label></nobr></td>
1.149 albertel 1600: <td bgcolor="#BBBBFF"><font size='-2'>
1.165 www 1601: <nobr><label><input type="checkbox" name="encprs_$orderidx" onClick="this.form.submit()" $enctext /> $lt{'ec'}</label></nobr></td>
1.120 www 1602: <td bgcolor="#BBBBFF"><font size="-2">$parameterset</font></td>
1603: ENDPARMS
1.119 www 1604: }
1.120 www 1605: $line.="</form></tr>";
1.8 www 1606: return $line;
1607: }
1608:
1.27 www 1609: # ---------------------------------------------------------------- tie the hash
1610:
1611: sub tiehash {
1.136 albertel 1612: my ($mode)=@_;
1.27 www 1613: $hashtied=0;
1.174 albertel 1614: if ($env{'request.course.fn'}) {
1.136 albertel 1615: if ($mode eq 'write') {
1.174 albertel 1616: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
1.136 albertel 1617: &GDBM_WRCREAT(),0640)) {
1618: $hashtied=2;
1619: }
1620: } else {
1.174 albertel 1621: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
1.136 albertel 1622: &GDBM_READER(),0640)) {
1.27 www 1623: $hashtied=1;
1.136 albertel 1624: }
1625: }
1.27 www 1626: }
1627: }
1628:
1629: sub untiehash {
1630: if ($hashtied) { untie %hash; }
1631: $hashtied=0;
1632: }
1633:
1.29 www 1634: # --------------------------------------------------------------- check on this
1635:
1636: sub checkonthis {
1637: my ($r,$url,$level,$title)=@_;
1.140 www 1638: $url=&Apache::lonnet::unescape($url);
1.29 www 1639: $alreadyseen{$url}=1;
1640: $r->rflush();
1.41 www 1641: if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
1.108 albertel 1642: $r->print("\n<br />");
1.29 www 1643: for (my $i=0;$i<=$level*5;$i++) {
1644: $r->print(' ');
1645: }
1646: $r->print('<a href="'.$url.'" target="cat">'.
1647: ($title?$title:$url).'</a> ');
1648: if ($url=~/^\/res\//) {
1649: my $result=&Apache::lonnet::repcopy(
1650: &Apache::lonnet::filelocation('',$url));
1.172 raeburn 1651: if ($result eq 'ok') {
1.87 www 1652: $r->print('<font color="green">'.&mt('ok').'</font>');
1.29 www 1653: $r->rflush();
1.34 www 1654: &Apache::lonnet::countacc($url);
1655: $url=~/\.(\w+)$/;
1656: if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
1657: $r->print('<br />');
1658: $r->rflush();
1659: for (my $i=0;$i<=$level*5;$i++) {
1660: $r->print(' ');
1661: }
1.84 www 1662: $r->print('- '.&mt('Rendering').': ');
1.170 www 1663: my ($errorcount,$warningcount)=split(/:/,
1664: &Apache::lonnet::ssi_body($url,
1.173 albertel 1665: ('grade_target'=>'web',
1666: 'return_only_error_and_warning_counts' => 1)));
1.170 www 1667: if (($errorcount) ||
1668: ($warningcount)) {
1669: if ($errorcount) {
1.98 www 1670: $r->print('<img src="/adm/lonMisc/bomb.gif" /><font color="red"><b>'.
1.170 www 1671: $errorcount.' '.
1.87 www 1672: &mt('error(s)').'</b></font> ');
1.34 www 1673: }
1.170 www 1674: if ($warningcount) {
1.34 www 1675: $r->print('<font color="blue">'.
1.170 www 1676: $warningcount.' '.
1.84 www 1677: &mt('warning(s)').'</font>');
1.34 www 1678: }
1679: } else {
1.87 www 1680: $r->print('<font color="green">'.&mt('ok').'</font>');
1.34 www 1681: }
1682: $r->rflush();
1683: }
1.29 www 1684: my $dependencies=
1685: &Apache::lonnet::metadata($url,'dependencies');
1686: foreach (split(/\,/,$dependencies)) {
1687: if (($_=~/^\/res\//) && (!$alreadyseen{$_})) {
1688: &checkonthis($r,$_,$level+1);
1689: }
1690: }
1.172 raeburn 1691: } elsif ($result eq 'unavailable') {
1.84 www 1692: $r->print('<font color="red"><b>'.&mt('connection down').'</b></font>');
1.172 raeburn 1693: } elsif ($result eq 'not_found') {
1.100 www 1694: unless ($url=~/\$/) {
1695: $r->print('<font color="red"><b>'.&mt('not found').'</b></font>');
1696: } else {
1697: $r->print('<font color="yellow"><b>'.&mt('unable to verify variable URL').'</b></font>');
1698: }
1.29 www 1699: } else {
1.84 www 1700: $r->print('<font color="red"><b>'.&mt('access denied').'</b></font>');
1.29 www 1701: }
1702: }
1703: }
1704: }
1705:
1.1 www 1706:
1.75 www 1707: #
1708: # -------------------------------------------------------------- Verify Content
1709: #
1710: sub verifycontent {
1711: my $r=shift;
1.26 www 1712: my $loaderror=&Apache::lonnet::overloaderror($r);
1713: if ($loaderror) { return $loaderror; }
1.167 albertel 1714: my $html=&Apache::lonxml::xmlbegin();
1715: $r->print($html.'<head><title>Verify Content</title></head>'.
1.26 www 1716: &Apache::loncommon::bodytag('Verify Course Documents'));
1.27 www 1717: $hashtied=0;
1.30 www 1718: undef %alreadyseen;
1719: %alreadyseen=();
1.27 www 1720: &tiehash();
1721: foreach (keys %hash) {
1.140 www 1722: if ($hash{$_}=~/\.(page|sequence)$/) {
1723: if (($_=~/^src_/) && ($alreadyseen{&Apache::lonnet::unescape($hash{$_})})) {
1724: $r->print('<hr /><font color="red">'.
1725: &mt('The following sequence or page is included more than once in your course: ').
1726: &Apache::lonnet::unescape($hash{$_}).'</font><br />'.
1727: &mt('Note that grading records for problems included in this sequence or folder will overlap.<hr />'));
1728: }
1729: }
1730: if (($_=~/^src\_(.+)$/) && (!$alreadyseen{&Apache::lonnet::unescape($hash{$_})})) {
1.29 www 1731: &checkonthis($r,$hash{$_},0,$hash{'title_'.$1});
1.27 www 1732: }
1733: }
1734: &untiehash();
1.108 albertel 1735: $r->print('<h1>'.&mt('Done').'.</h1>'.'<a href="/adm/coursedocs">'.
1736: &mt('Return to DOCS').'</a>');
1.75 www 1737: }
1738:
1.192 www 1739:
1.75 www 1740: # -------------------------------------------------------------- Check Versions
1741:
1.192 www 1742: sub devalidateversioncache {
1743: my $src=shift;
1744: &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
1745: &Apache::lonnet::clutter($src));
1746: }
1747:
1.75 www 1748: sub checkversions {
1749: my $r=shift;
1.167 albertel 1750: my $html=&Apache::lonxml::xmlbegin();
1751: $r->print($html.'<head><title>Check Versions</title></head>'.
1.26 www 1752: &Apache::loncommon::bodytag('Check Course Document Versions'));
1.89 www 1753: my $header='';
1754: my $startsel='';
1755: my $monthsel='';
1756: my $weeksel='';
1757: my $daysel='';
1758: my $allsel='';
1759: my %changes=();
1760: my $starttime=0;
1.91 www 1761: my $haschanged=0;
1.92 www 1762: my %setversions=&Apache::lonnet::dump('resourceversions',
1.174 albertel 1763: $env{'course.'.$env{'request.course.id'}.'.domain'},
1764: $env{'course.'.$env{'request.course.id'}.'.num'});
1.92 www 1765:
1766: $hashtied=0;
1767: &tiehash();
1768: my %newsetversions=();
1.174 albertel 1769: if ($env{'form.setmostrecent'}) {
1.91 www 1770: $haschanged=1;
1.92 www 1771: foreach (keys %hash) {
1772: if ($_=~/^ids\_(\/res\/.+)$/) {
1.93 www 1773: $newsetversions{$1}='mostrecent';
1.192 www 1774: &devalidateversioncache($1);
1.92 www 1775: }
1776: }
1.174 albertel 1777: } elsif ($env{'form.setcurrent'}) {
1.91 www 1778: $haschanged=1;
1.92 www 1779: foreach (keys %hash) {
1780: if ($_=~/^ids\_(\/res\/.+)$/) {
1.93 www 1781: my $getvers=&Apache::lonnet::getversion($1);
1782: if ($getvers>0) {
1783: $newsetversions{$1}=$getvers;
1.192 www 1784: &devalidateversioncache($1);
1.93 www 1785: }
1.92 www 1786: }
1787: }
1.174 albertel 1788: } elsif ($env{'form.setversions'}) {
1.91 www 1789: $haschanged=1;
1.174 albertel 1790: foreach (keys %env) {
1.92 www 1791: if ($_=~/^form\.set_version_(.+)$/) {
1792: my $src=$1;
1.174 albertel 1793: if (($env{$_}) && ($env{$_} ne $setversions{$src})) {
1794: $newsetversions{$src}=$env{$_};
1.192 www 1795: &devalidateversioncache($src);
1.92 www 1796: }
1797: }
1798: }
1.91 www 1799: }
1800: if ($haschanged) {
1.92 www 1801: if (&Apache::lonnet::put('resourceversions',\%newsetversions,
1.174 albertel 1802: $env{'course.'.$env{'request.course.id'}.'.domain'},
1803: $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
1.92 www 1804: $r->print('<h1>'.&mt('Your Version Settings have been Stored').'</h1>');
1805: } else {
1806: $r->print('<h1><font color="red">'.&mt('An Error Occured while Attempting to Store your Version Settings').'</font></h1>');
1807: }
1.136 albertel 1808: &mark_hash_old();
1.91 www 1809: }
1.136 albertel 1810: &changewarning($r,'');
1.174 albertel 1811: if ($env{'form.timerange'} eq 'all') {
1.89 www 1812: # show all documents
1813: $header=&mt('All Documents in Course');
1.91 www 1814: $allsel=1;
1.90 www 1815: foreach (keys %hash) {
1816: if ($_=~/^ids\_(\/res\/.+)$/) {
1817: my $src=$1;
1818: $changes{$src}=1;
1819: }
1820: }
1.89 www 1821: } else {
1822: # show documents which changed
1823: %changes=&Apache::lonnet::dump
1.174 albertel 1824: ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
1825: $env{'course.'.$env{'request.course.id'}.'.num'});
1.89 www 1826: my $firstkey=(keys %changes)[0];
1827: unless ($firstkey=~/^error\:/) {
1.174 albertel 1828: unless ($env{'form.timerange'}) {
1829: $env{'form.timerange'}=604800;
1.89 www 1830: }
1.174 albertel 1831: my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
1.89 www 1832: .&mt('seconds');
1.174 albertel 1833: if ($env{'form.timerange'}==-1) {
1.89 www 1834: $seltext='since start of course';
1835: $startsel='selected';
1.174 albertel 1836: $env{'form.timerange'}=time;
1.89 www 1837: }
1.174 albertel 1838: $starttime=time-$env{'form.timerange'};
1839: if ($env{'form.timerange'}==2592000) {
1.89 www 1840: $seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1841: $monthsel='selected';
1.174 albertel 1842: } elsif ($env{'form.timerange'}==604800) {
1.89 www 1843: $seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1844: $weeksel='selected';
1.174 albertel 1845: } elsif ($env{'form.timerange'}==86400) {
1.89 www 1846: $seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1847: $daysel='selected';
1848: }
1849: $header=&mt('Content changed').' '.$seltext;
1850: } else {
1851: $header=&mt('No content modifications yet.');
1852: }
1853: }
1.92 www 1854: %setversions=&Apache::lonnet::dump('resourceversions',
1.174 albertel 1855: $env{'course.'.$env{'request.course.id'}.'.domain'},
1856: $env{'course.'.$env{'request.course.id'}.'.num'});
1.89 www 1857: my %lt=&Apache::lonlocal::texthash
1.88 www 1858: ('st' => 'Version changes since start of Course',
1859: 'lm' => 'Version changes since last Month',
1860: 'lw' => 'Version changes since last Week',
1861: 'sy' => 'Version changes since Yesterday',
1.91 www 1862: 'al' => 'All Resources (possibly large output)',
1.88 www 1863: 'sd' => 'Display',
1.84 www 1864: 'fi' => 'File',
1865: 'md' => 'Modification Date',
1.87 www 1866: 'mr' => 'Most recently published Version',
1867: 've' => 'Version used in Course',
1.91 www 1868: 'vu' => 'Set Version to be used in Course',
1869: 'sv' => 'Set Versions to be used in Course according to Selections below',
1870: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
1871: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
1.84 www 1872: 'di' => 'Differences');
1.89 www 1873: $r->print(<<ENDHEADERS);
1.31 www 1874: <form action="/adm/coursedocs" method="post">
1.91 www 1875: <input type="hidden" name="versions" value="1" />
1876: <input type="submit" name="setmostrecent" value="$lt{'sm'}" />
1877: <input type="submit" name="setcurrent" value="$lt{'sc'}" /><hr />
1.31 www 1878: <select name="timerange">
1.88 www 1879: <option value='all' $allsel>$lt{'al'}</option>
1.84 www 1880: <option value="-1" $startsel>$lt{'st'}</option>
1881: <option value="2592000" $monthsel>$lt{'lm'}</option>
1882: <option value="604800" $weeksel>$lt{'lw'}</option>
1883: <option value="86400" $daysel>$lt{'sy'}</option>
1.31 www 1884: </select>
1.91 www 1885: <input type="submit" name="display" value="$lt{'sd'}" />
1.89 www 1886: <h3>$header</h3>
1.91 www 1887: <input type="submit" name="setversions" value="$lt{'sv'}" />
1.103 matthew 1888: <table border="0">
1.31 www 1889: ENDHEADERS
1.91 www 1890: foreach (sort keys %changes) {
1.89 www 1891: if ($changes{$_}>$starttime) {
1892: my ($root,$extension)=($_=~/^(.*)\.(\w+)$/);
1893: my $currentversion=&Apache::lonnet::getversion($_);
1.93 www 1894: if ($currentversion<0) {
1895: $currentversion=&mt('Could not be determined.');
1896: }
1.89 www 1897: my $linkurl=&Apache::lonnet::clutter($_);
1898: $r->print(
1.103 matthew 1899: '<tr><td colspan="5"><br /><br /><font size="+1"><b>'.
1.91 www 1900: &Apache::lonnet::gettitle($linkurl).
1.103 matthew 1901: '</b></font></td></tr>'.
1902: '<tr><td> </td>'.
1903: '<td colspan="4">'.
1904: '<a href="'.$linkurl.'" target="cat">'.$linkurl.
1905: '</a></td></tr>'.
1906: '<tr><td></td>'.
1907: '<td title="'.$lt{'md'}.'">'.
1.102 matthew 1908: &Apache::lonlocal::locallocaltime(
1909: &Apache::lonnet::metadata($root.'.'.$extension,
1910: 'lastrevisiondate')
1911: ).
1.103 matthew 1912: '</td>'.
1913: '<td title="'.$lt{'mr'}.'"><nobr>Most Recent: '.
1914: '<font size="+1">'.$currentversion.'</font>'.
1915: '</nobr></td>'.
1916: '<td title="'.$lt{'ve'}.'"><nobr>In Course: '.
1917: '<font size="+1">');
1.87 www 1918: # Used in course
1.89 www 1919: my $usedversion=$hash{'version_'.$linkurl};
1.93 www 1920: if (($usedversion) && ($usedversion ne 'mostrecent')) {
1.89 www 1921: $r->print($usedversion);
1922: } else {
1923: $r->print($currentversion);
1924: }
1.103 matthew 1925: $r->print('</font></nobr></td><td title="'.$lt{'vu'}.'">'.
1926: '<nobr>Use: ');
1.87 www 1927: # Set version
1.92 www 1928: $r->print(&Apache::loncommon::select_form($setversions{$linkurl},
1.89 www 1929: 'set_version_'.$linkurl,
1.136 albertel 1930: ('select_form_order' =>
1931: ['',1..$currentversion,'mostrecent'],
1932: '' => '',
1.93 www 1933: 'mostrecent' => 'most recent',
1.89 www 1934: map {$_,$_} (1..$currentversion))));
1.103 matthew 1935: $r->print('</nobr></td></tr><tr><td></td>');
1.89 www 1936: my $lastold=1;
1937: for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
1938: my $url=$root.'.'.$prevvers.'.'.$extension;
1939: if (&Apache::lonnet::metadata($url,'lastrevisiondate')<
1940: $starttime) {
1941: $lastold=$prevvers;
1942: }
1943: }
1.103 matthew 1944: #
1945: # Code to figure out how many version entries should go in
1946: # each of the four columns
1947: my $entries_per_col = 0;
1948: my $num_entries = ($currentversion-$lastold);
1949: if ($num_entries % 4 == 0) {
1950: $entries_per_col = $num_entries/4;
1951: } else {
1952: $entries_per_col = $num_entries/4 + 1;
1953: }
1954: my $entries_count = 0;
1955: $r->print('<td valign="top"><font size="-2">');
1956: my $cols_output = 1;
1.32 www 1957: for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
1.89 www 1958: my $url=$root.'.'.$prevvers.'.'.$extension;
1.103 matthew 1959: $r->print('<nobr><a href="'.&Apache::lonnet::clutter($url).
1.91 www 1960: '">'.&mt('Version').' '.$prevvers.'</a> ('.
1.103 matthew 1961: &Apache::lonlocal::locallocaltime(
1962: &Apache::lonnet::metadata($url,
1963: 'lastrevisiondate')
1964: ).
1.91 www 1965: ')');
1.89 www 1966: if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
1.33 www 1967: $r->print(' <a href="/adm/diff?filename='.
1.89 www 1968: &Apache::lonnet::clutter($root.'.'.$extension).
1969: '&versionone='.$prevvers.
1970: '">'.&mt('Diffs').'</a>');
1971: }
1.103 matthew 1972: $r->print('</nobr><br />');
1973: if (++$entries_count % $entries_per_col == 0) {
1974: $r->print('</font></td>');
1975: if ($cols_output != 4) {
1976: $r->print('<td valign="top"><font size="-2">');
1977: $cols_output++;
1978: }
1979: }
1.89 www 1980: }
1.103 matthew 1981: while($cols_output++ < 4) {
1982: $r->print('</font></td><td><font>')
1983: }
1984: $r->print('</font></td></tr>'."\n");
1.89 www 1985: }
1986: }
1.92 www 1987: $r->print('</table></form>');
1.89 www 1988: $r->print('<h1>'.&mt('Done').'.</h1>');
1989:
1990: &untiehash();
1.75 www 1991: }
1992:
1.136 albertel 1993: sub mark_hash_old {
1994: my $retie_hash=0;
1995: if ($hashtied) {
1996: $retie_hash=1;
1997: &untiehash();
1998: }
1999: &tiehash('write');
2000: $hash{'old'}=1;
2001: &untiehash();
2002: if ($retie_hash) { &tiehash(); }
2003: }
2004:
2005: sub is_hash_old {
2006: my $untie_hash=0;
2007: if (!$hashtied) {
2008: $untie_hash=1;
2009: &tiehash();
2010: }
2011: my $return=$hash{'old'};
2012: if ($untie_hash) { &untiehash(); }
2013: return $return;
2014: }
2015:
1.91 www 2016: sub changewarning {
1.177 albertel 2017: my ($r,$postexec,$message,$url)=@_;
1.136 albertel 2018: if (!&is_hash_old()) { return; }
1.150 albertel 2019: my $pathvar='folderpath';
1.174 albertel 2020: my $path=&Apache::lonnet::escape($env{'form.folderpath'});
1.177 albertel 2021: if (!defined($url)) {
2022: if (defined($env{'form.pagepath'})) {
2023: $pathvar='pagepath';
2024: $path=&Apache::lonnet::escape($env{'form.pagepath'});
1.193 albertel 2025: $path.='&pagesymb='.&Apache::lonnet::escape($env{'form.pagesymb'});
1.177 albertel 2026: }
2027: $url='/adm/coursedocs?'.$pathvar.'='.$path;
2028: }
2029: if (!defined($message)) {
2030: $message='Changes will become active for your current session after [_1], or the next time you log in.';
1.150 albertel 2031: }
1.185 www 2032: $r->print("\n\n".
2033: '<script>function reinit(tf) { tf.submit();'.$postexec.' }</script>'."\n".
2034: '<form name="reinitform" method="post" action="/adm/roles" target="loncapaclient">'.
1.177 albertel 2035: '<input type="hidden" name="orgurl" value="'.$url.
1.117 albertel 2036: '" /><input type="hidden" name="selectrole" value="1" /><h3><font color="red">'.
1.177 albertel 2037: &mt($message,' <input type="hidden" name="'.
2038: $env{'request.role'}.'" value="1" /><input type="button" value="'.
2039: &mt('re-initializing course').'" onClick="reinit(this.form)" />').
1.185 www 2040: $help{'Caching'}.'</font></h3></form>'."\n\n");
1.91 www 2041: }
2042:
1.75 www 2043: # ================================================================ Main Handler
2044: sub handler {
2045: my $r = shift;
1.82 www 2046: &Apache::loncommon::content_type($r,'text/html');
1.75 www 2047: $r->send_http_header;
2048: return OK if $r->header_only;
2049:
2050: # --------------------------------------------- Initialize help topics for this
2051: foreach ('Adding_Course_Doc','Main_Course_Documents',
2052: 'Adding_External_Resource','Navigate_Content',
2053: 'Adding_Folders','Docs_Overview', 'Load_Map',
1.142 raeburn 2054: 'Supplemental','Score_Upload_Form','Adding_Pages',
1.130 www 2055: 'Importing_LON-CAPA_Resource','Uploading_From_Harddrive',
2056: 'Check_Resource_Versions','Verify_Content') {
1.75 www 2057: $help{$_}=&Apache::loncommon::help_open_topic('Docs_'.$_);
2058: }
2059: # Composite help files
2060: $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
2061: 'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
2062: $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
2063: 'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
1.86 albertel 2064: $help{'Simple Problem'} = &Apache::loncommon::help_open_topic(
2065: 'Option_Response_Simple');
1.75 www 2066: $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
2067: 'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
2068: $help{'My Personal Info'} = &Apache::loncommon::help_open_topic(
2069: 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
2070: $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
1.142 raeburn 2071:
1.174 albertel 2072: if ($env{'form.verify'}) {
1.75 www 2073: &verifycontent($r);
1.174 albertel 2074: } elsif ($env{'form.versions'}) {
1.75 www 2075: &checkversions($r);
1.174 albertel 2076: } elsif ($env{'form.dumpcourse'}) {
1.75 www 2077: &dumpcourse($r);
1.174 albertel 2078: } elsif ($env{'form.exportcourse'}) {
1.138 raeburn 2079: &exportcourse($r);
1.26 www 2080: } else {
1.7 www 2081: # is this a standard course?
2082:
1.174 albertel 2083: my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
1.155 raeburn 2084: my $forcestandard = 0;
1.15 www 2085: my $forcesupplement;
2086: my $script='';
2087: my $allowed;
2088: my $events='';
1.19 www 2089: my $showdoc=0;
1.142 raeburn 2090: my $containertag;
2091: my $uploadtag;
1.15 www 2092: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.168 www 2093: ['folderpath','pagepath','pagesymb','markedcopy_url','markedcopy_title']);
1.174 albertel 2094: if ($env{'form.folderpath'}) {
2095: my (@folderpath)=split('&',$env{'form.folderpath'});
2096: $env{'form.foldername'}=&Apache::lonnet::unescape(pop(@folderpath));
2097: $env{'form.folder'}=pop(@folderpath);
2098: }
2099: if ($env{'form.pagepath'}) {
2100: my (@pagepath)=split('&',$env{'form.pagepath'});
2101: $env{'form.pagename'}=&Apache::lonnet::unescape(pop(@pagepath));
2102: $env{'form.folder'}=pop(@pagepath);
1.156 albertel 2103: $containertag = '<input type="hidden" name="pagepath" value="" />'.
2104: '<input type="hidden" name="pagesymb" value="" />';
1.174 albertel 2105: $uploadtag = '<input type="hidden" name="pagepath" value="'.$env{'form.pagepath'}.'" />'.
2106: '<input type="hidden" name="pagesymb" value="'.$env{'form.pagesymb'}.'" />';
1.142 raeburn 2107: }
1.21 www 2108: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
1.127 albertel 2109: $showdoc='/'.$1;
1.21 www 2110: }
2111: unless ($showdoc) { # got called from remote
1.174 albertel 2112: if (($env{'form.folder'}=~/^default_/) ||
2113: ($env{'form.folder'} =~ m#^\d+/(pages|sequences)/#)) {
1.155 raeburn 2114: $forcestandard = 1;
2115: }
1.174 albertel 2116: $forcesupplement=($env{'form.folder'}=~/^supplemental_/);
1.7 www 2117:
1.4 www 2118: # does this user have privileges to post, etc?
1.174 albertel 2119: $allowed=&Apache::lonnet::allowed('mdc',$env{'request.course.id'});
1.15 www 2120: if ($allowed) {
2121: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
2122: $script=&Apache::lonratedt::editscript('simple');
2123: }
2124: } else { # got called in sequence from course
2125: $allowed=0;
1.49 www 2126: $script='</script>'.&Apache::lonmenu::registerurl(1,undef).'<script>';
2127: $events='onLoad="'.&Apache::lonmenu::loadevents.
2128: '" onUnload="'.&Apache::lonmenu::unloadevents.'"';
1.3 www 2129: }
1.4 www 2130:
2131: # get course data
1.174 albertel 2132: my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
2133: my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.4 www 2134:
1.14 www 2135: # get personal data
2136:
1.174 albertel 2137: my $uname=$env{'user.name'};
2138: my $udom=$env{'user.domain'};
1.14 www 2139: my $plainname=&Apache::lonnet::escape(
2140: &Apache::loncommon::plainname($uname,$udom));
2141:
1.8 www 2142: # graphics settings
1.4 www 2143:
1.176 albertel 2144: $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL') . "/");
1.8 www 2145:
1.22 www 2146: my $now=time;
1.64 www 2147:
1.4 www 2148: # print screen
1.167 albertel 2149: my $html=&Apache::lonxml::xmlbegin();
1.1 www 2150: $r->print(<<ENDDOCUMENT);
1.167 albertel 2151: $html
1.1 www 2152: <head>
2153: <title>The LearningOnline Network with CAPA</title>
1.16 www 2154: <script>
2155: $script
1.20 www 2156: </script>
1.19 www 2157: ENDDOCUMENT
2158: if ($allowed) {
2159: $r->print(<<ENDNEWSCRIPT);
1.20 www 2160: <script>
1.16 www 2161: function makenewfolder(targetform,folderseq) {
2162: var foldername=prompt('Name of New Folder','New Folder');
2163: if (foldername) {
2164: targetform.importdetail.value=foldername+"="+folderseq;
2165: targetform.submit();
2166: }
2167: }
2168:
1.142 raeburn 2169: function makenewpage(targetform,folderseq) {
2170: var pagename=prompt('Name of New Page','New Page');
2171: if (pagename) {
2172: targetform.importdetail.value=pagename+"="+folderseq;
2173: targetform.submit();
2174: }
2175: }
2176:
1.18 www 2177: function makenewext(targetname) {
2178: this.document.forms.extimport.useform.value=targetname;
2179: window.open('/adm/rat/extpickframe.html');
2180: }
2181:
1.62 www 2182: function makeexamupload() {
2183: var title=prompt('Listed Title for the Uploaded Score');
2184: if (title) {
2185: this.document.forms.newexamupload.importdetail.value=
2186: title+'=/res/lib/templates/examupload.problem';
2187: this.document.forms.newexamupload.submit();
2188: }
2189: }
2190:
1.22 www 2191: function makesmppage() {
1.38 www 2192: var title=prompt('Listed Title for the Page');
2193: if (title) {
1.22 www 2194: this.document.forms.newsmppg.importdetail.value=
2195: title+'=/adm/$udom/$uname/$now/smppg';
2196: this.document.forms.newsmppg.submit();
1.38 www 2197: }
1.22 www 2198: }
2199:
1.55 www 2200: function makesmpproblem() {
2201: var title=prompt('Listed Title for the Problem');
2202: if (title) {
2203: this.document.forms.newsmpproblem.importdetail.value=
1.63 www 2204: title+'=/res/lib/templates/simpleproblem.problem';
1.55 www 2205: this.document.forms.newsmpproblem.submit();
2206: }
2207: }
2208:
1.22 www 2209: function makebulboard() {
1.38 www 2210: var title=prompt('Listed Title for the Bulletin Board');
2211: if (title) {
1.22 www 2212: this.document.forms.newbul.importdetail.value=
2213: title+'=/adm/$udom/$uname/$now/bulletinboard';
2214: this.document.forms.newbul.submit();
1.38 www 2215: }
1.22 www 2216: }
2217:
1.101 www 2218: function makeabout() {
2219: var user=prompt("Enter user\@domain for User's 'About Me' Page");
2220: if (user) {
2221: var comp=new Array();
2222: comp=user.split('\@');
2223: if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
2224: if ((comp[0]) && (comp[1])) {
2225: this.document.forms.newaboutsomeone.importdetail.value=
2226: 'About '+user+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
2227: this.document.forms.newaboutsomeone.submit();
1.165 www 2228: } else {
2229: alert("Not a valid user\@domain");
2230: }
2231: } else {
2232: alert("Please enter both user and domain in the format user\@domain");
1.101 www 2233: }
2234: }
2235: }
2236:
1.110 raeburn 2237: function makeims() {
1.165 www 2238: var caller = document.forms.ims.folder.value;
2239: var newlocation = "/adm/imsimportdocs?folder="+caller+"&phase=one";
2240: newWindow = window.open("","IMSimport","HEIGHT=700,WIDTH=750,scrollbars=yes");
2241: newWindow.location.href = newlocation;
1.110 raeburn 2242: }
2243:
2244:
1.18 www 2245: function finishpick() {
2246: var title=this.document.forms.extimport.title.value;
2247: var url=this.document.forms.extimport.url.value;
2248: var form=this.document.forms.extimport.useform.value;
2249: eval
2250: ('this.document.forms.'+form+'.importdetail.value="'+title+'='+url+
2251: '";this.document.forms.'+form+'.submit();');
1.16 www 2252: }
1.36 www 2253:
1.156 albertel 2254: function changename(folderpath,index,oldtitle,container,pagesymb) {
1.36 www 2255: var title=prompt('New Title',oldtitle);
2256: if (title) {
2257: this.document.forms.renameform.title.value=title;
2258: this.document.forms.renameform.cmd.value='rename_'+index;
1.142 raeburn 2259: if (container == 'sequence') {
2260: this.document.forms.renameform.folderpath.value=folderpath;
2261: }
2262: if (container == 'page') {
2263: this.document.forms.renameform.pagepath.value=folderpath;
1.156 albertel 2264: this.document.forms.renameform.pagesymb.value=pagesymb;
1.142 raeburn 2265: }
1.54 www 2266: this.document.forms.renameform.submit();
2267: }
2268: }
2269:
1.156 albertel 2270: function removeres(folderpath,index,oldtitle,container,pagesymb) {
1.171 www 2271: if (confirm('WARNING: Removing a resource makes associated grades and scores inaccessible!\\nRemove "'+oldtitle+'"?')) {
1.54 www 2272: this.document.forms.renameform.cmd.value='del_'+index;
1.142 raeburn 2273: if (container == 'sequence') {
2274: this.document.forms.renameform.folderpath.value=folderpath;
2275: }
2276: if (container == 'page') {
2277: this.document.forms.renameform.pagepath.value=folderpath;
1.156 albertel 2278: this.document.forms.renameform.pagesymb.value=pagesymb;
1.142 raeburn 2279: }
1.36 www 2280: this.document.forms.renameform.submit();
2281: }
2282: }
1.121 www 2283:
1.171 www 2284: function cutres(folderpath,index,oldtitle,container,pagesymb) {
1.186 www 2285: 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 2286: this.document.forms.renameform.cmd.value='cut_'+index;
2287: this.document.forms.renameform.markcopy.value=index;
2288: if (container == 'sequence') {
2289: this.document.forms.renameform.folderpath.value=folderpath;
2290: }
2291: if (container == 'page') {
2292: this.document.forms.renameform.pagepath.value=folderpath;
2293: this.document.forms.renameform.pagesymb.value=pagesymb;
2294: }
2295: this.document.forms.renameform.submit();
2296: }
2297: }
2298:
1.168 www 2299: function markcopy(folderpath,index,oldtitle,container,pagesymb) {
2300: this.document.forms.renameform.markcopy.value=index;
2301: if (container == 'sequence') {
2302: this.document.forms.renameform.folderpath.value=folderpath;
2303: }
2304: if (container == 'page') {
2305: this.document.forms.renameform.pagepath.value=folderpath;
2306: this.document.forms.renameform.pagesymb.value=pagesymb;
2307: }
2308: this.document.forms.renameform.submit();
2309: }
2310:
1.16 www 2311: </script>
1.42 www 2312:
2313: ENDNEWSCRIPT
2314: }
2315: # -------------------------------------------------------------------- Body tag
2316: $r->print('</head>'.
1.72 www 2317: &Apache::loncommon::bodytag('Course Documents','',$events,
1.99 www 2318: '','',$showdoc).
1.134 albertel 2319: &Apache::loncommon::help_open_menu('','','','',273,'RAT'));
1.188 raeburn 2320: my %allfiles = ();
2321: my %codebase = ();
2322: my ($upload_result,$upload_output);
2323: if ($allowed) {
2324: if (($env{'form.uploaddoc.filename'}) && ($env{'form.cmd'}=~/^upload_(\w+)/)) {
2325: # Process file upload - phase one - upload and parse primary file.
1.190 albertel 2326: $upload_result = &process_file_upload(\$upload_output,$coursenum,
2327: $coursedom,\%allfiles,
1.194 raeburn 2328: \%codebase,$1);
1.188 raeburn 2329: if ($upload_result eq 'phasetwo') {
2330: $r->print($upload_output);
2331: }
2332: } elsif ($env{'form.phasetwo'}) {
2333: my %newname = ();
2334: my %origname = ();
2335: my %attribs = ();
2336: my $updateflag = 0;
2337: my $residx = $env{'form.newidx'};
2338: my $primary_url = &Apache::lonnet::unescape($env{'form.primaryurl'});
2339: # Process file upload - phase two - gather secondary files.
2340: for (my $i=0; $i<$env{'form.phasetwo'}; $i++) {
2341: if ($env{'form.embedded_item_'.$i.'.filename'}) {
2342: my $javacodebase;
2343: $newname{$i} = &process_secondary_uploads(\$upload_output,$coursedom,$coursenum,'embedded_item_',$i,$residx);
2344: $origname{$i} = &Apache::lonnet::unescape($env{'form.embedded_orig_'.$i});
2345: if (exists($env{'form.embedded_codebase_'.$i})) {
2346: $javacodebase = &Apache::lonnet::unescape($env{'form.embedded_codebase_'.$i});
2347: $origname{$i} =~ s#^\Q$javacodebase\E/##;
2348: }
2349: my @attributes = ();
2350: if ($env{'form.embedded_attrib_'.$i} =~ /:/) {
2351: @attributes = split/:/,$env{'form.embedded_attrib_'.$i};
2352: } else {
2353: @attributes = ($env{'form.embedded_attrib_'.$i});
2354: }
2355: foreach (@attributes) {
2356: push(@{$attribs{$i}},&Apache::lonnet::unescape($_));
2357: }
2358: if ($javacodebase) {
2359: $codebase{$i} = $javacodebase;
2360: $codebase{$i} =~ s#/$##;
2361: $updateflag = 1;
2362: }
2363: }
2364: unless ($newname{$i} eq $origname{$i}) {
2365: $updateflag = 1;
2366: }
2367: }
2368: # Process file upload - phase three - modify primary file
2369: if ($updateflag) {
2370: my ($content,$rtncode);
2371: my $updateflag = 0;
2372: my $getstatus = &Apache::lonnet::getuploaded('GET',$primary_url,$coursedom,$coursenum,\$content,\$rtncode);
2373: if ($getstatus eq 'ok') {
2374: foreach my $item (keys %newname) {
2375: if ($newname{$item} ne $origname{$item}) {
2376: my $attrib_regexp = '';
2377: if (@{$attribs{$item}} > 1) {
2378: $attrib_regexp = join('|',@{$attribs{$item}});
2379: } else {
2380: $attrib_regexp = $attribs{$item}[0];
2381: }
2382: if ($content =~ m#($attrib_regexp\s*=\s*['"]?)\Q$origname{$item}\E(['"]?)#) {
2383: }
2384: $content =~ s#($attrib_regexp\s*=\s*['"]?)\Q$origname{$item}\E(['"]?)#$1$newname{$item}$2#gi;
2385: }
2386: if (exists($codebase{$item})) {
2387: $content =~ s/(codebase\s*=\s*["']?)\Q$codebase{$item}\E(["']?)/$1.$2/i;
2388: }
2389: }
2390: # Save edited file.
2391: my $saveresult;
2392: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
2393: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.191 raeburn 2394: my $url = &Apache::lonnet::store_edited_file($primary_url,$content,$docudom,$docuname,\$saveresult);
1.188 raeburn 2395: } else {
2396: &Apache::lonnet::logthis('retrieval of uploaded file - '.$primary_url.' - for editing, failed: '.$getstatus);
2397: }
2398: }
2399: }
2400: }
2401:
2402: unless ($showdoc || $upload_result eq 'phasetwo') {
1.81 www 2403: # -----------------------------------------------------------------------------
2404: my %lt=&Apache::lonlocal::texthash(
2405: 'uplm' => 'Upload a new main course document',
2406: 'upls' => 'Upload a new supplemental course document',
1.168 www 2407: 'impp' => 'Import a document',
2408: 'pubd' => 'Published documents',
1.181 www 2409: 'copm' => 'All documents out of a published map into this folder',
1.81 www 2410: 'spec' => 'Special documents',
2411: 'upld' => 'Upload Document',
2412: 'srch' => 'Search',
2413: 'impo' => 'Import',
2414: 'selm' => 'Select Map',
2415: 'load' => 'Load Map',
1.186 www 2416: 'reco' => 'Recover Deleted Resources',
1.81 www 2417: 'newf' => 'New Folder',
1.142 raeburn 2418: 'newp' => 'New Composite Page',
1.81 www 2419: 'extr' => 'External Resource',
2420: 'syll' => 'Syllabus',
2421: 'navc' => 'Navigate Contents',
2422: 'sipa' => 'Simple Page',
2423: 'sipr' => 'Simple Problem',
2424: 'scuf' => 'Score Upload Form',
2425: 'bull' => 'Bulletin Board',
1.96 sakharuk 2426: 'mypi' => 'My Personal Info',
1.101 www 2427: 'abou' => 'About User',
1.110 raeburn 2428: 'imsf' => 'Import IMS package',
1.96 sakharuk 2429: 'file' => 'File',
2430: 'title' => 'Title',
1.188 raeburn 2431: 'comment' => 'Comment',
2432: 'parse' => 'If HTML file, upload embedded images/multimedia files'
1.81 www 2433: );
2434: # -----------------------------------------------------------------------------
1.42 www 2435: if ($allowed) {
1.74 www 2436: my $dumpbut=&dumpbutton();
1.138 raeburn 2437: my $exportbut=&exportbutton();
1.88 www 2438: my %lt=&Apache::lonlocal::texthash(
2439: 'vc' => 'Verify Content',
2440: 'cv' => 'Check/Set Resource Versions',
2441: );
1.118 albertel 2442:
1.174 albertel 2443: my $folderpath=$env{'form.folderpath'};
1.118 albertel 2444: if (!$folderpath) {
1.174 albertel 2445: if ($env{'form.folder'} eq '' ||
2446: $env{'form.folder'} eq 'supplemental') {
1.118 albertel 2447: $folderpath='default&'.
2448: &Apache::lonnet::escape(&mt('Main Course Documents'));
2449: }
2450: }
1.174 albertel 2451: unless ($env{'form.pagepath'}) {
1.142 raeburn 2452: $containertag = '<input type="hidden" name="folderpath" value="" />';
2453: $uploadtag = '<input type="hidden" name="folderpath" value="'.$folderpath.'" />';
2454: }
2455:
1.42 www 2456: $r->print(<<ENDCOURSEVERIFY);
1.36 www 2457: <form name="renameform" method="post" action="/adm/coursedocs">
2458: <input type="hidden" name="title" />
2459: <input type="hidden" name="cmd" />
1.168 www 2460: <input type="hidden" name="markcopy" />
1.142 raeburn 2461: $containertag
1.36 www 2462: </form>
1.39 www 2463: <form name="simpleedit" method="post" action="/adm/coursedocs">
2464: <input type=hidden name="importdetail" value="">
1.142 raeburn 2465: $uploadtag
1.39 www 2466: </form>
1.26 www 2467: <form action="/adm/coursedocs" method="post" name="courseverify">
1.74 www 2468: <table bgcolor="#AAAAAA" width="100%" cellspacing="4" cellpadding="4">
2469: <tr><td bgcolor="#DDDDCC">
1.130 www 2470: <input type="submit" name="verify" value="$lt{'vc'}" />$help{'Verify_Content'}
1.74 www 2471: </td><td bgcolor="#DDDDCC">
1.130 www 2472: <input type="submit" name="versions" value="$lt{'cv'}" />$help{'Check_Resource_Versions'}
1.74 www 2473: $dumpbut
1.138 raeburn 2474: $exportbut
1.74 www 2475: </td></tr></table>
1.25 www 2476: </form>
2477: ENDCOURSEVERIFY
1.74 www 2478: $r->print(&Apache::loncommon::help_open_topic('Docs_Adding_Course_Doc',
1.96 sakharuk 2479: &mt('Editing the Table of Contents for your Course')));
1.25 www 2480: }
1.17 www 2481: # --------------------------------------------------------- Standard documents
1.43 www 2482: $r->print('<table border=2 cellspacing=4 cellpadding=4>');
1.7 www 2483: if (($standard) && ($allowed) && (!$forcesupplement)) {
1.116 albertel 2484: $r->print('<tr><td bgcolor="#BBBBBB">');
2485: # '<h2>'.&mt('Main Course Documents').
2486: # ($allowed?' '.$help{'Main_Course_Documents'}:'').'</h2>');
1.174 albertel 2487: my $folder=$env{'form.folder'};
1.117 albertel 2488: if ($folder eq '' || $folder eq 'supplemental') {
1.112 raeburn 2489: $folder='default';
1.174 albertel 2490: $env{'form.folderpath'}='default&'.&Apache::lonnet::escape(&mt('Main Course Documents'));
1.112 raeburn 2491: }
1.51 www 2492: my $postexec='';
2493: if ($folder eq 'default') {
2494: $r->print('<script>this.window.name="loncapaclient";</script>');
2495: } else {
1.117 albertel 2496: #$postexec='self.close();';
1.51 www 2497: }
1.40 www 2498: $hadchanges=0;
1.188 raeburn 2499: &editor($r,$coursenum,$coursedom,$folder,$allowed,$upload_output);
1.40 www 2500: if ($hadchanges) {
1.136 albertel 2501: &mark_hash_old()
1.40 www 2502: }
1.136 albertel 2503: &changewarning($r,$postexec);
1.16 www 2504: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_'.time.
2505: '.sequence';
1.142 raeburn 2506: my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_'.time.
2507: '.page';
1.186 www 2508: my $container='sequence';
2509: if ($env{'form.pagepath'}) {
2510: $container='page';
2511: }
2512: my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
1.8 www 2513: $r->print(<<ENDFORM);
1.43 www 2514: <table cellspacing=4 cellpadding=4><tr>
1.81 www 2515: <th bgcolor="#DDDDDD">$lt{'uplm'}</th>
2516: <th bgcolor="#DDDDDD">$lt{'impp'}</th>
2517: <th bgcolor="#DDDDDD">$lt{'spec'}</th>
1.11 www 2518: </tr>
1.16 www 2519: <tr><td bgcolor="#DDDDDD">
1.96 sakharuk 2520: $lt{'file'}:<br />
1.182 albertel 2521: <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.59 www 2522: <input type="file" name="uploaddoc" size="40">
1.8 www 2523: <br />
1.96 sakharuk 2524: $lt{'title'}:<br />
1.11 www 2525: <input type="text" size="50" name="comment">
1.142 raeburn 2526: $uploadtag
1.10 www 2527: <input type="hidden" name="cmd" value="upload_default">
1.188 raeburn 2528: <br />
2529: <nobr>
1.190 albertel 2530: <label>$lt{'parse'}?
1.188 raeburn 2531: <input type="checkbox" name="parserflag" />
1.190 albertel 2532: </label>
1.188 raeburn 2533: </nobr>
2534: <br />
2535: <br />
1.129 albertel 2536: <nobr>
1.81 www 2537: <input type="submit" value="$lt{'upld'}">
1.60 albertel 2538: $help{'Uploading_From_Harddrive'}
1.58 albertel 2539: </nobr>
1.60 albertel 2540: </form>
1.11 www 2541: </td>
1.16 www 2542: <td bgcolor="#DDDDDD">
1.39 www 2543: <form action="/adm/coursedocs" method="post" name="simpleeditdefault">
1.168 www 2544: $lt{'pubd'}<br />
1.142 raeburn 2545: $uploadtag
1.115 albertel 2546: <input type=button onClick="javascript:groupsearch()" value="$lt{'srch'}">
1.58 albertel 2547: <nobr>
1.115 albertel 2548: <input type=button onClick="javascript:groupimport();" value="$lt{'impo'}">
1.58 albertel 2549: $help{'Importing_LON-CAPA_Resource'}
2550: </nobr>
1.59 www 2551: <p>
2552: <hr />
1.181 www 2553: $lt{'copm'}<br />
2554: <input type="text" size="40" name="importmap"><br />
1.68 bowersj2 2555: <nobr><input type=button
1.52 www 2556: onClick="javascript:openbrowser('simpleeditdefault','importmap','sequence,page','')"
1.81 www 2557: value="$lt{'selm'}"> <input type="submit" name="loadmap" value="$lt{'load'}">
1.68 bowersj2 2558: $help{'Load_Map'}</nobr>
1.59 www 2559: </p>
1.52 www 2560: </form>
1.186 www 2561: <hr />
2562: <form action="/adm/groupsort" method="post" name="recover">
2563: <input type="button" name="recovermap" onClick="javascript:groupopen('$readfile',1)" value="$lt{'reco'}" />
2564: </form>
1.142 raeburn 2565: ENDFORM
1.174 albertel 2566: unless ($env{'form.pagepath'}) {
1.168 www 2567: $r->print(<<ENDFORM);
2568: <hr />
2569: <form action="/adm/coursedocs" method="post" name="newext">
2570: $uploadtag
2571: <input type=hidden name="importdetail" value="">
2572: <nobr>
2573: <input name="newext" type="button" onClick="javascript:makenewext('newext');"
2574: value="$lt{'extr'}" /> $help{'Adding_External_Resource'}
2575: </nobr>
2576: </form>
2577: <form action="/adm/imsimportdocs" method="post" name="ims">
2578: <input type="hidden" name="folder" value="$folder" />
2579: <input name="imsimport" type="button" value="$lt{'imsf'}" onClick="javascript:makeims();" />
2580: </nobr>
2581: </form>
2582: ENDFORM
2583: }
2584: $r->print('</td><td bgcolor="#DDDDDD">');
1.174 albertel 2585: unless ($env{'form.pagepath'}) {
1.142 raeburn 2586: $r->print(<<ENDFORM);
1.11 www 2587: <form action="/adm/coursedocs" method="post" name="newfolder">
1.174 albertel 2588: <input type="hidden" name="folderpath" value="$env{'form.folderpath'}" />
1.13 www 2589: <input type=hidden name="importdetail" value="">
1.58 albertel 2590: <nobr>
1.16 www 2591: <input name="newfolder" type="button"
2592: onClick="javascript:makenewfolder(this.form,'$folderseq');"
1.81 www 2593: value="$lt{'newf'}" />$help{'Adding_Folders'}
1.58 albertel 2594: </nobr>
1.11 www 2595: </form>
1.142 raeburn 2596: <form action="/adm/coursedocs" method="post" name="newpage">
1.174 albertel 2597: <input type="hidden" name="folderpath" value="$env{'form.folderpath'}" />
1.142 raeburn 2598: <input type=hidden name="importdetail" value="">
2599: <nobr>
2600: <input name="newpage" type="button"
2601: onClick="javascript:makenewpage(this.form,'$pageseq');"
2602: value="$lt{'newp'}" />$help{'Adding_Pages'}
2603: </nobr>
2604: </form>
1.11 www 2605: <form action="/adm/coursedocs" method="post" name="newsyl">
1.142 raeburn 2606: $uploadtag
1.14 www 2607: <input type=hidden name="importdetail"
2608: value="Syllabus=/public/$coursedom/$coursenum/syllabus">
1.58 albertel 2609: <nobr>
1.81 www 2610: <input name="newsyl" type="submit" value="$lt{'syll'}" />
1.65 bowersj2 2611: $help{'Syllabus'}
1.58 albertel 2612: </nobr>
2613: </form>
1.17 www 2614: <form action="/adm/coursedocs" method="post" name="newnav">
1.142 raeburn 2615: $uploadtag
1.15 www 2616: <input type=hidden name="importdetail"
2617: value="Navigate Content=/adm/navmaps">
1.58 albertel 2618: <nobr>
1.81 www 2619: <input name="newnav" type="submit" value="$lt{'navc'}" />
1.47 www 2620: $help{'Navigate_Content'}
1.58 albertel 2621: </nobr>
1.22 www 2622: </form>
2623: <form action="/adm/coursedocs" method="post" name="newsmppg">
1.142 raeburn 2624: $uploadtag
1.22 www 2625: <input type=hidden name="importdetail" value="">
1.58 albertel 2626: <nobr>
1.81 www 2627: <input name="newsmppg" type="button" value="$lt{'sipa'}"
1.65 bowersj2 2628: onClick="javascript:makesmppage();" /> $help{'Simple Page'}
1.58 albertel 2629: </nobr>
1.55 www 2630: </form>
2631: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
1.142 raeburn 2632: $uploadtag
1.55 www 2633: <input type=hidden name="importdetail" value="">
1.58 albertel 2634: <nobr>
1.81 www 2635: <input name="newsmpproblem" type="button" value="$lt{'sipr'}"
1.65 bowersj2 2636: onClick="javascript:makesmpproblem();" />$help{'Simple Problem'}
1.62 www 2637: </nobr>
2638: </form>
2639: <form action="/adm/coursedocs" method="post" name="newexamupload">
1.142 raeburn 2640: $uploadtag
1.62 www 2641: <input type=hidden name="importdetail" value="">
2642: <nobr>
1.81 www 2643: <input name="newexamupload" type="button" value="$lt{'scuf'}"
1.62 www 2644: onClick="javascript:makeexamupload();" />
1.66 bowersj2 2645: $help{'Score_Upload_Form'}
1.58 albertel 2646: </nobr>
1.22 www 2647: </form>
2648: <form action="/adm/coursedocs" method="post" name="newbul">
1.142 raeburn 2649: $uploadtag
1.22 www 2650: <input type=hidden name="importdetail" value="">
1.58 albertel 2651: <nobr>
1.81 www 2652: <input name="newbulletin" type="button" value="$lt{'bull'}"
1.22 www 2653: onClick="javascript:makebulboard();" />
1.65 bowersj2 2654: $help{'Bulletin Board'}
1.58 albertel 2655: </nobr>
2656: </form>
1.12 www 2657: <form action="/adm/coursedocs" method="post" name="newaboutme">
1.142 raeburn 2658: $uploadtag
1.14 www 2659: <input type=hidden name="importdetail"
2660: value="$plainname=/adm/$udom/$uname/aboutme">
1.58 albertel 2661: <nobr>
1.81 www 2662: <input name="newaboutme" type="submit" value="$lt{'mypi'}" />
1.65 bowersj2 2663: $help{'My Personal Info'}
1.101 www 2664: </nobr>
2665: </form>
2666: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
1.142 raeburn 2667: $uploadtag
1.101 www 2668: <input type=hidden name="importdetail" value="">
2669: <nobr>
2670: <input name="newaboutsomeone" type="button" value="$lt{'abou'}"
2671: onClick="javascript:makeabout();" />
1.110 raeburn 2672: </nobr>
1.182 albertel 2673: </form>
1.142 raeburn 2674: ENDFORM
2675: }
1.174 albertel 2676: if ($env{'form.pagepath'}) {
1.142 raeburn 2677: $r->print(<<ENDBLOCK);
2678: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
2679: $uploadtag
2680: <input type=hidden name="importdetail" value="">
2681: <nobr>
2682: <input name="newsmpproblem" type="button" value="$lt{'sipr'}"
2683: onClick="javascript:makesmpproblem();" />$help{'Simple Problem'}
2684: </nobr>
2685: </form>
2686: <form action="/adm/coursedocs" method="post" name="newexamupload">
2687: $uploadtag
2688: <input type=hidden name="importdetail" value="">
2689: <nobr>
2690: <input name="newexamupload" type="button" value="$lt{'scuf'}"
2691: onClick="javascript:makeexamupload();" />
2692: $help{'Score_Upload_Form'}
2693: </nobr>
1.182 albertel 2694: </form>
1.142 raeburn 2695: ENDBLOCK
2696: }
2697: $r->print('</td></tr>'."\n".
2698: '</table>');
1.24 www 2699: $r->print('</td></tr>');
1.7 www 2700: }
2701: # ----------------------------------------------------- Supplemental documents
2702: if (!$forcestandard) {
1.116 albertel 2703: $r->print('<tr><td bgcolor="#BBBBBB">');
2704: # '<h2>'.&mt('Supplemental Course Documents').
2705: # ($allowed?' '.$help{'Supplemental'}:'').'</h2>');
1.174 albertel 2706: my $folder=$env{'form.folder'};
1.117 albertel 2707: unless ($folder=~/^supplemental/) {
1.116 albertel 2708: $folder='supplemental';
1.117 albertel 2709: }
2710: if ($folder =~ /^supplemental$/ &&
1.174 albertel 2711: $env{'form.folderpath'} =~ /^default\&/) {
2712: $env{'form.folderpath'}='supplemental&'.
1.117 albertel 2713: &Apache::lonnet::escape(&mt('Supplemental Course Documents'));
1.116 albertel 2714: }
1.7 www 2715: &editor($r,$coursenum,$coursedom,$folder,$allowed);
1.8 www 2716: if ($allowed) {
1.17 www 2717: my $folderseq=
2718: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_'.time.
2719: '.sequence';
2720:
1.8 www 2721: $r->print(<<ENDSUPFORM);
1.43 www 2722: <table cellspacing=4 cellpadding=4><tr>
1.81 www 2723: <th bgcolor="#DDDDDD">$lt{'upls'}</th>
2724: <th bgcolor="#DDDDDD">$lt{'spec'}</th>
1.17 www 2725: </tr>
2726: <tr><td bgcolor="#DDDDDD">
1.10 www 2727: <form action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.59 www 2728: <input type="file" name="uploaddoc" size="40">
1.196 raeburn 2729: <br />
2730: <br />
2731: <nobr>
2732: <label>$lt{'parse'}?
2733: <input type="checkbox" name="parserflag" />
2734: </label>
2735: </nobr>
2736: <br /><br />
2737: $lt{'comment'}:<br />
1.4 www 2738: <textarea cols=50 rows=4 name='comment'>
2739: </textarea>
1.115 albertel 2740: <br />
1.174 albertel 2741: <input type="hidden" name="folderpath" value="$env{'form.folderpath'}" />
1.10 www 2742: <input type="hidden" name="cmd" value="upload_supplemental">
1.58 albertel 2743: <nobr>
1.81 www 2744: <input type="submit" value="$lt{'upld'}">
1.58 albertel 2745: $help{'Uploading_From_Harddrive'}
2746: </nobr>
2747: </form>
1.17 www 2748: </td>
2749: <td bgcolor="#DDDDDD">
1.18 www 2750: <form action="/adm/coursedocs" method="post" name="supnewfolder">
1.174 albertel 2751: <input type="hidden" name="folderpath" value="$env{'form.folderpath'}" />
1.17 www 2752: <input type=hidden name="importdetail" value="">
1.58 albertel 2753: <nobr>
1.17 www 2754: <input name="newfolder" type="button"
2755: onClick="javascript:makenewfolder(this.form,'$folderseq');"
1.81 www 2756: value="$lt{'newf'}" /> $help{'Adding_Folders'}
1.58 albertel 2757: </nobr>
1.17 www 2758: </form>
1.18 www 2759: <form action="/adm/coursedocs" method="post" name="supnewext">
1.174 albertel 2760: <input type="hidden" name="folderpath" value="$env{'form.folderpath'}" />
1.17 www 2761: <input type=hidden name="importdetail" value="">
1.58 albertel 2762: <nobr>
1.18 www 2763: <input name="newext" type="button"
2764: onClick="javascript:makenewext('supnewext');"
1.81 www 2765: value="$lt{'extr'}" /> $help{'Adding_External_Resource'}
1.58 albertel 2766: </nobr>
1.17 www 2767: </form>
1.18 www 2768: <form action="/adm/coursedocs" method="post" name="supnewsyl">
1.174 albertel 2769: <input type="hidden" name="folderpath" value="$env{'form.folderpath'}" />
1.17 www 2770: <input type=hidden name="importdetail"
2771: value="Syllabus=/public/$coursedom/$coursenum/syllabus">
1.58 albertel 2772: <nobr>
1.81 www 2773: <input name="newsyl" type="submit" value="$lt{'syll'}" />
1.65 bowersj2 2774: $help{'Syllabus'}
1.58 albertel 2775: </nobr>
2776: </form>
1.18 www 2777: <form action="/adm/coursedocs" method="post" name="subnewaboutme">
1.174 albertel 2778: <input type="hidden" name="folderpath" value="$env{'form.folderpath'}" />
1.17 www 2779: <input type=hidden name="importdetail"
2780: value="$plainname=/adm/$udom/$uname/aboutme">
1.58 albertel 2781: <nobr>
1.81 www 2782: <input name="newaboutme" type="submit" value="$lt{'mypi'}" />
1.65 bowersj2 2783: $help{'My Personal Info'}
1.58 albertel 2784: </nobr>
2785: </form>
1.17 www 2786: </td></tr>
1.24 www 2787: </table></td></tr>
1.8 www 2788: ENDSUPFORM
2789: }
1.7 www 2790: }
1.18 www 2791: if ($allowed) {
1.182 albertel 2792: $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 2793: }
1.24 www 2794: $r->print('</table>');
1.19 www 2795: } else {
1.188 raeburn 2796: unless ($upload_result eq 'phasetwo') {
1.19 www 2797: # -------------------------------------------------------- This is showdoc mode
1.188 raeburn 2798: $r->print("<h1>".&mt('Uploaded Document').' - '.
1.141 albertel 2799: &Apache::lonnet::gettitle($r->uri).'</h1><p>'.
1.81 www 2800: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><p><table>".
1.188 raeburn 2801: &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table></p>');
2802: }
1.19 www 2803: }
1.26 www 2804: }
1.95 www 2805: $r->print('</body></html>');
1.26 www 2806: return OK;
1.1 www 2807: }
2808:
2809: 1;
2810: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>