Annotation of loncom/interface/londocs.pm, revision 1.418
1.329 droeschl 1: # The LearningOnline Network
2: # Documents
3: #
1.418 ! raeburn 4: # $Id: londocs.pm,v 1.417 2010/01/30 13:06:43 droeschl Exp $
1.329 droeschl 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
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.
14: #
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:
29:
30:
31: package Apache::londocs;
32:
33: use strict;
34: use Apache::Constants qw(:common :http);
35: use Apache::imsexport;
36: use Apache::lonnet;
37: use Apache::loncommon;
1.383 tempelho 38: use Apache::lonhtmlcommon;
1.329 droeschl 39: use LONCAPA::map();
40: use Apache::lonratedt();
41: use Apache::lonxml;
42: use Apache::lonclonecourse;
43: use Apache::lonnavmaps;
44: use HTML::Entities;
45: use GDBM_File;
46: use Apache::lonlocal;
47: use Cwd;
48: use LONCAPA qw(:DEFAULT :match);
49:
50: my $iconpath;
51:
52: my %hash;
53:
54: my $hashtied;
55: my %alreadyseen=();
56:
57: my $hadchanges;
58:
59:
60: my %help=();
61:
62:
63: sub mapread {
64: my ($coursenum,$coursedom,$map)=@_;
65: return
66: &LONCAPA::map::mapread('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
67: $map);
68: }
69:
70: sub storemap {
71: my ($coursenum,$coursedom,$map)=@_;
72: my ($outtext,$errtext)=
73: &LONCAPA::map::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
74: $map,1);
75: if ($errtext) { return ($errtext,2); }
1.364 bisitz 76:
1.329 droeschl 77: $hadchanges=1;
78: return ($errtext,0);
79: }
80:
81:
82:
83: sub authorhosts {
84: my %outhash=();
85: my $home=0;
86: my $other=0;
87: foreach my $key (keys(%env)) {
88: if ($key=~/^user\.role\.(au|ca)\.(.+)$/) {
89: my $role=$1;
90: my $realm=$2;
91: my ($start,$end)=split(/\./,$env{$key});
92: if (($start) && ($start>time)) { next; }
93: if (($end) && (time>$end)) { next; }
94: my ($ca,$cd);
95: if ($1 eq 'au') {
96: $ca=$env{'user.name'};
97: $cd=$env{'user.domain'};
98: } else {
99: ($cd,$ca)=($realm=~/^\/($match_domain)\/($match_username)$/);
100: }
101: my $allowed=0;
102: my $myhome=&Apache::lonnet::homeserver($ca,$cd);
103: my @ids=&Apache::lonnet::current_machine_ids();
104: foreach my $id (@ids) { if ($id eq $myhome) { $allowed=1; } }
105: if ($allowed) {
106: $home++;
107: $outhash{'home_'.$ca.'@'.$cd}=1;
108: } else {
109: $outhash{'otherhome_'.$ca.'@'.$cd}=$myhome;
110: $other++;
111: }
112: }
113: }
114: return ($home,$other,%outhash);
115: }
116:
117:
118: sub dumpbutton {
119: my ($home,$other,%outhash)=&authorhosts();
1.408 raeburn 120: my $crstype = &Apache::loncommon::course_type();
1.329 droeschl 121: if ($home+$other==0) { return ''; }
122: if ($home) {
1.408 raeburn 123: my $link = "<a onclick='javascript:injectData(document.courseverify, \"dummy\", \"dumpcourse\", \"".&mt('Dump '.$crstype.' DOCS to Construction Space')."\")'>".&mt('Dump '.$crstype.' DOCS to Construction Space')."</a>";
1.383 tempelho 124: return $link.' '.
1.362 ehlerst 125: &Apache::loncommon::help_open_topic('Docs_Dump_Course_Docs').'<br />';
1.329 droeschl 126: } else {
1.417 droeschl 127: return &mt('Dump '.$crstype.
128: ' DOCS to Construction Space: available on other servers');
1.329 droeschl 129: }
130: }
131:
132: sub clean {
133: my ($title)=@_;
134: $title=~s/[^\w\/\!\$\%\^\*\-\_\=\+\;\:\,\\\|\`\~]+/\_/gs;
1.344 bisitz 135: return $title;
1.329 droeschl 136: }
137:
138:
139:
140: sub dumpcourse {
141: my ($r) = @_;
1.408 raeburn 142: my $crstype = &Apache::loncommon::course_type();
143: $r->print(&Apache::loncommon::start_page('Dump '.$crstype.' DOCS to Construction Space').
1.369 bisitz 144: '<form name="dumpdoc" action="" method="post">');
1.408 raeburn 145: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Dump '.$crstype.' DOCS to Construction Space'));
1.329 droeschl 146: my ($home,$other,%outhash)=&authorhosts();
147: unless ($home) { return ''; }
148: my $origcrsid=$env{'request.course.id'};
149: my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
150: if (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
151: # Do the dumping
152: unless ($outhash{'home_'.$env{'form.authorspace'}}) { return ''; }
153: my ($ca,$cd)=split(/\@/,$env{'form.authorspace'});
154: $r->print('<h3>'.&mt('Copying Files').'</h3>');
155: my $title=$env{'form.authorfolder'};
156: $title=&clean($title);
157: my %replacehash=();
158: foreach my $key (keys(%env)) {
159: if ($key=~/^form\.namefor\_(.+)/) {
160: $replacehash{$1}=$env{$key};
161: }
162: }
163: my $crs='/uploaded/'.$env{'request.course.id'}.'/';
164: $crs=~s/\_/\//g;
165: foreach my $item (keys(%replacehash)) {
166: my $newfilename=$title.'/'.$replacehash{$item};
167: $newfilename=~s/\.(\w+)$//;
168: my $ext=$1;
169: $newfilename=&clean($newfilename);
170: $newfilename.='.'.$ext;
171: my @dirs=split(/\//,$newfilename);
172: my $path='/home/'.$ca.'/public_html';
173: my $makepath=$path;
174: my $fail=0;
175: for (my $i=0;$i<$#dirs;$i++) {
176: $makepath.='/'.$dirs[$i];
1.344 bisitz 177: unless (-e $makepath) {
178: unless(mkdir($makepath,0777)) { $fail=1; }
1.329 droeschl 179: }
180: }
181: $r->print('<br /><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt>: ');
182: if (my $fh=Apache::File->new('>'.$path.'/'.$newfilename)) {
183: if ($item=~/\.(sequence|page|html|htm|xml|xhtml)$/) {
184: print $fh &Apache::lonclonecourse::rewritefile(
185: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
186: (%replacehash,$crs => '')
187: );
188: } else {
189: print $fh
190: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item);
191: }
192: $fh->close();
193: } else {
194: $fail=1;
195: }
196: if ($fail) {
197: $r->print('<span class="LC_error">'.&mt('fail').'</span>');
198: } else {
199: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
200: }
201: }
202: } else {
203: # Input form
204: unless ($home==1) {
205: $r->print(
206: '<h3>'.&mt('Select the Construction Space').'</h3><select name="authorspace">');
207: }
208: foreach my $key (sort(keys(%outhash))) {
209: if ($key=~/^home_(.+)$/) {
210: if ($home==1) {
211: $r->print(
212: '<input type="hidden" name="authorspace" value="'.$1.'" />');
213: } else {
214: $r->print('<option value="'.$1.'">'.$1.' - '.
215: &Apache::loncommon::plainname(split(/\@/,$1)).'</option>');
216: }
217: }
218: }
219: unless ($home==1) {
220: $r->print('</select>');
221: }
222: my $title=$origcrsdata{'description'};
223: $title=~s/[\/\s]+/\_/gs;
224: $title=&clean($title);
225: $r->print('<h3>'.&mt('Folder in Construction Space').'</h3>'
226: .'<input type="text" size="50" name="authorfolder" value="'.$title.'" /><br />');
227: &tiehash();
228: $r->print('<h3>'.&mt('Filenames in Construction Space').'</h3>'
229: .&Apache::loncommon::start_data_table()
230: .&Apache::loncommon::start_data_table_header_row()
231: .'<th>'.&mt('Internal Filename').'</th>'
232: .'<th>'.&mt('Title').'</th>'
233: .'<th>'.&mt('Save as ...').'</th>'
234: .&Apache::loncommon::end_data_table_header_row());
235: foreach my $file (&Apache::lonclonecourse::crsdirlist($origcrsid,'userfiles')) {
236: $r->print(&Apache::loncommon::start_data_table_row()
237: .'<td>'.$file.'</td>');
238: my ($ext)=($file=~/\.(\w+)$/);
239: my $title=$hash{'title_'.$hash{
240: 'ids_/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'.$file}};
241: $r->print('<td>'.($title?$title:' ').'</td>');
242: if (!$title) {
243: $title=$file;
244: } else {
245: $title=~s|/|_|g;
246: }
247: $title=~s/\.(\w+)$//;
248: $title=&clean($title);
249: $title.='.'.$ext;
250: $r->print("\n<td><input type='text' size='60' name='namefor_".$file."' value='".$title."' /></td>"
251: .&Apache::loncommon::end_data_table_row());
252: }
253: $r->print(&Apache::loncommon::end_data_table());
254: &untiehash();
255: $r->print(
1.408 raeburn 256: '<p><input type="submit" name="dumpcourse" value="'.&mt("Dump $crstype DOCS").'" /></p></form>');
1.329 droeschl 257: }
258: }
259:
260:
261:
262: sub exportbutton {
1.408 raeburn 263: my $crstype = &Apache::loncommon::course_type();
1.383 tempelho 264: return "<a onclick='javascript:injectData(document.courseverify, \"dummy\", \"exportcourse\", \"".&mt('IMS Export')."\")'>".&mt('IMS Export')."</a>".
1.362 ehlerst 265: &Apache::loncommon::help_open_topic('Docs_Export_Course_Docs').'<br />';
1.329 droeschl 266: }
267:
268:
269:
270: sub exportcourse {
271: my $r=shift;
1.408 raeburn 272: my $crstype = &Apache::loncommon::course_type();
1.329 droeschl 273: my %discussiontime = &Apache::lonnet::dump('discussiontimes',
274: $env{'course.'.$env{'request.course.id'}.'.domain'}, $env{'course.'.$env{'request.course.id'}.'.num'});
275: my $numdisc = keys(%discussiontime);
276: my $navmap = Apache::lonnavmaps::navmap->new();
277: if (!defined($navmap)) {
1.408 raeburn 278: $r->print(&Apache::loncommon::start_page('Export '.$crstype.' to IMS Package').
1.376 bisitz 279: '<h2>'.&mt('IMS Export Failed').'</h2>'.
1.408 raeburn 280: '<div class="LC_error">');
281: if ($crstype eq 'Community') {
282: $r->print(&mt('Unable to retrieve information about community contents'));
283: } else {
284: $r->print(&mt('Unable to retrieve information about course contents'));
285: }
286: $r->print('</div><a href="/adm/coursedocs">');
287: if ($crstype eq 'Community') {
288: $r->print(&mt('Return to Community Editor'));
289: } else {
290: $r->print(&mt('Return to Course Editor'));
291: }
292: $r->print('</a>');
293: &Apache::lonnet::logthis('IMS export failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
1.329 droeschl 294: return;
295: }
296: my $it=$navmap->getIterator(undef,undef,undef,1,undef,undef);
297: my $curRes;
298: my $outcome;
299:
300: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
301: ['finishexport']);
302: if ($env{'form.finishexport'}) {
303: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
304: ['archive','discussion']);
305:
306: my @exportitems = &Apache::loncommon::get_env_multiple('form.archive');
307: my @discussions = &Apache::loncommon::get_env_multiple('form.discussion');
308: if (@exportitems == 0 && @discussions == 0) {
1.377 bisitz 309: $outcome =
310: '<p class="LC_warning">'
311: .&mt('As you did not select any content items or discussions'
312: .' for export, an IMS package has not been created.')
313: .'</p>'
314: .'<p>'
315: .&mt('Please [_1]go back[_2] to select either content items'
316: .' or discussions for export.'
317: ,'<a href="javascript:history.go(-1)">'
318: ,'</a>')
319: .'</p>';
1.329 droeschl 320: } else {
321: my $now = time;
322: my %symbs;
323: my $manifestok = 0;
324: my $imsresources;
325: my $tempexport;
326: my $copyresult;
327: my $ims_manifest = &create_ims_store($now,\$manifestok,\$outcome,\$tempexport);
328: if ($manifestok) {
329: &build_package($now,$navmap,\@exportitems,\@discussions,\$outcome,$tempexport,\$copyresult,$ims_manifest);
330: close($ims_manifest);
331:
332: #Create zip file in prtspool
333: my $imszipfile = '/prtspool/'.
334: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
335: time.'_'.rand(1000000000).'.zip';
336: my $cwd = &Cwd::getcwd();
337: my $imszip = '/home/httpd/'.$imszipfile;
338: chdir $tempexport;
339: open(OUTPUT, "zip -r $imszip * 2> /dev/null |");
340: close(OUTPUT);
341: chdir $cwd;
1.415 raeburn 342: $outcome .= '<p>'
343: .&mt('[_1]Your IMS package[_2] is ready for download.'
344: ,'<a href="'.$imszipfile.'">','</a>')
345: .'</p>';
1.329 droeschl 346: if ($copyresult) {
1.369 bisitz 347: $outcome .= '<p class="LC_error">'
348: .&mt('The following errors occurred during export - [_1]'
349: ,$copyresult)
350: .'</p>';
1.329 droeschl 351: }
352: } else {
1.377 bisitz 353: $outcome = '<p class="LC_error">'
354: .&mt('Unfortunately you will not be able to retrieve'
1.415 raeburn 355: .' an IMS archive of your course at this time,'
1.377 bisitz 356: .' because there was a problem creating a'
357: .' manifest file.')
358: .'</p>'
359: .'<p><a href="javascript:history.go(-1)">'
360: .&mt('Go Back')
361: .'</a></p>';
1.329 droeschl 362: }
363: }
1.408 raeburn 364: $r->print(&Apache::loncommon::start_page('Export '.$crstype.' to IMS Package'));
1.377 bisitz 365: $r->print(&Apache::lonhtmlcommon::breadcrumbs('IMS Export'));
1.329 droeschl 366: $r->print($outcome);
367: $r->print(&Apache::loncommon::end_page());
368: } else {
1.413 raeburn 369: my $display='<form name="exportdoc" action="" method="post">'."\n".
370: '<p>'.
371: &mt('Choose which items you wish to export from your '.$crstype.'.').
372: '</p>'.
373: '<div class="LC_columnSection"><fieldset>'.
1.369 bisitz 374: '<legend>'.&mt('Content items').'</legend>'.
375: '<input type="button" value="'.&mt('check all').'" '.
1.329 droeschl 376: 'onclick="javascript:checkAll(document.exportdoc.archive)" />'.
1.369 bisitz 377: ' <input type="button" value="'.&mt('uncheck all').'"'.
1.414 raeburn 378: ' onclick="javascript:uncheckAll(document.exportdoc.archive)" /></fieldset>';
379: if ($numdisc > 0) {
380: $display .= '<fieldset>'.
381: '<legend>'.&mt('Discussion posts').'</legend>'.
382: '<input type="button" value="'.&mt('check all').'"'.
383: ' onclick="javascript:checkAll(document.exportdoc.discussion)" />'.
384: ' <input type="button" value="'.&mt('uncheck all').'"'.
385: ' onclick="javascript:uncheckAll(document.exportdoc.discussion)" />'.
386: '</fieldset>';
387: }
388: $display .= '</div>';
1.329 droeschl 389: my $curRes;
390: my $depth = 0;
391: my $count = 0;
392: my $boards = 0;
393: my $startcount = 5;
394: my %parent = ();
395: my %children = ();
396: my $lastcontainer = $startcount;
1.369 bisitz 397: $display .= &Apache::loncommon::start_data_table()
398: .&Apache::loncommon::start_data_table_header_row()
1.414 raeburn 399: .'<th>'.&mt('Export content item?').'</th>';
1.329 droeschl 400: if ($numdisc > 0) {
1.414 raeburn 401: $display .= '<th>'.&mt('Export discussion posts?').'</th>';
1.329 droeschl 402: }
1.414 raeburn 403: $display .= &Apache::loncommon::end_data_table_header_row();
1.329 droeschl 404: while ($curRes = $it->next()) {
405: if (ref($curRes)) {
406: $count ++;
407: }
408: if ($curRes == $it->BEGIN_MAP()) {
409: $depth++;
410: $parent{$depth} = $lastcontainer;
411: }
412: if ($curRes == $it->END_MAP()) {
413: $depth--;
414: $lastcontainer = $parent{$depth};
415: }
416: if (ref($curRes)) {
417: my $symb = $curRes->symb();
418: my $ressymb = $symb;
419: if ($ressymb =~ m|adm/($match_domain)/($match_username)/(\d+)/bulletinboard$|) {
420: unless ($ressymb =~ m|adm/wrapper/adm|) {
421: $ressymb = 'bulletin___'.$3.'___adm/wrapper/adm/'.$1.'/'.$2.'/'.$3.'/bulletinboard';
422: }
423: }
1.416 raeburn 424: my $currelem = $count+$boards+$startcount;
1.369 bisitz 425: $display .= &Apache::loncommon::start_data_table_row()
426: .'<td>'."\n"
427: .'<input type="checkbox" name="archive" value="'.$count.'" ';
1.329 droeschl 428: if (($curRes->is_sequence()) || ($curRes->is_page())) {
1.416 raeburn 429: $lastcontainer = $currelem;
430: $display .= 'onclick="javascript:propagateCheck('."'$currelem'".')"';
1.329 droeschl 431: }
432: $display .= ' />'."\n";
433: for (my $i=0; $i<$depth; $i++) {
1.416 raeburn 434: $display .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";
1.329 droeschl 435: }
436: if ($curRes->is_sequence()) {
1.365 bisitz 437: $display .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" /> '."\n";
1.329 droeschl 438: } elsif ($curRes->is_page()) {
1.365 bisitz 439: $display .= '<img src="/adm/lonIcons/navmap.page.open.gif" alt="" /> '."\n";
1.329 droeschl 440: }
441: $children{$parent{$depth}} .= $currelem.':';
1.369 bisitz 442: $display .= ' '.$curRes->title().'</td>'."\n";
443:
444: # Existing discussion posts?
1.329 droeschl 445: if ($discussiontime{$ressymb} > 0) {
446: $boards ++;
1.369 bisitz 447: $display .= '<td align="right">'
448: .'<input type="checkbox" name="discussion" value="'.$count.'" />'
449: .'</td>'."\n";
1.414 raeburn 450: } elsif ($numdisc > 0) {
1.369 bisitz 451: $display .= '<td> </td>'."\n";
1.329 droeschl 452: }
1.369 bisitz 453: $display .= &Apache::loncommon::end_data_table_row();
1.329 droeschl 454: }
455: }
1.369 bisitz 456: $display .= &Apache::loncommon::end_data_table();
1.329 droeschl 457: my $scripttag = qq|
1.369 bisitz 458: <script type="text/javascript">
459: // <![CDATA[
1.329 droeschl 460: function checkAll(field) {
461: if (field.length > 0) {
462: for (i = 0; i < field.length; i++) {
463: field[i].checked = true ;
464: }
465: } else {
466: field.checked = true
467: }
468: }
1.364 bisitz 469:
1.329 droeschl 470: function uncheckAll(field) {
471: if (field.length > 0) {
472: for (i = 0; i < field.length; i++) {
473: field[i].checked = false ;
474: }
475: } else {
476: field.checked = false ;
477: }
478: }
479:
480: function propagateCheck(item) {
481: if (document.exportdoc.elements[item].checked == true) {
482: containerCheck(item)
483: }
1.364 bisitz 484: }
1.329 droeschl 485:
486: function containerCheck(item) {
487: document.exportdoc.elements[item].checked = true
488: var numitems = $count + $boards + $startcount
489: var parents = new Array(numitems)
490: for (var i=$startcount; i<numitems; i++) {
491: parents[i] = new Array
492: }
493: |;
494:
495: foreach my $container (sort { $a <=> $b } (keys(%children))) {
496: my @contents = split(/:/,$children{$container});
497: for (my $i=0; $i<@contents; $i ++) {
498: $scripttag .= ' parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
499: }
500: }
501:
502: $scripttag .= qq|
503: if (parents[item].length > 0) {
504: for (var j=0; j<parents[item].length; j++) {
505: containerCheck(parents[item][j])
506: }
1.364 bisitz 507: }
1.329 droeschl 508: }
1.369 bisitz 509: // ]]>
1.329 droeschl 510: </script>
511: |;
1.408 raeburn 512: $r->print(&Apache::loncommon::start_page('Export '.$crstype.' to IMS Package',
1.329 droeschl 513: $scripttag));
1.377 bisitz 514: $r->print(&Apache::lonhtmlcommon::breadcrumbs('IMS Export'));
1.369 bisitz 515: $r->print($display.
1.361 bisitz 516: '<p><input type="hidden" name="finishexport" value="1" />'.
1.329 droeschl 517: '<input type="submit" name="exportcourse" value="'.
1.377 bisitz 518: &mt('Export').'" /></p></form>');
1.329 droeschl 519: }
520: }
521:
522: sub create_ims_store {
523: my ($now,$manifestok,$outcome,$tempexport) = @_;
524: $$tempexport = $Apache::lonnet::perlvar{'lonDaemons'}.'/tmp/ims_exports';
525: my $ims_manifest;
526: if (!-e $$tempexport) {
527: mkdir($$tempexport,0700);
528: }
529: $$tempexport .= '/'.$now;
530: if (!-e $$tempexport) {
531: mkdir($$tempexport,0700);
532: }
533: $$tempexport .= '/'.$env{'user.domain'}.'_'.$env{'user.name'};
534: if (!-e $$tempexport) {
535: mkdir($$tempexport,0700);
536: }
537: if (!-e "$$tempexport/resources") {
538: mkdir("$$tempexport/resources",0700);
539: }
540: # open manifest file
541: my $manifest = '/imsmanifest.xml';
542: my $manifestfilename = $$tempexport.$manifest;
543: if ($ims_manifest = Apache::File->new('>'.$manifestfilename)) {
544: $$manifestok=1;
545: print $ims_manifest
546: '<?xml version="1.0" encoding="UTF-8"?>'."\n".
547: '<manifest xmlns="http://www.imsglobal.org/xsd/imscp_v1p1"'.
548: ' xmlns:imsmd="http://www.imsglobal.org/xsd/imsmd_v1p2"'.
549: ' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"'.
550: ' identifier="MANIFEST-'.$env{'request.course.id'}.'-'.$now.'"'.
551: ' xsi:schemaLocation="http://www.imsglobal.org/xsd/imscp_v1p1imscp_v1p1.xsd'.
552: ' http://www.imsglobal.org/xsd/imsmd_v1p2 imsmd_v1p2p2.xsd">'."\n".
553: ' <metadata>
554: <schema></schema>
555: <imsmd:lom>
556: <imsmd:general>
557: <imsmd:identifier>'.$env{'request.course.id'}.'</imsmd:identifier>
558: <imsmd:title>
559: <imsmd:langstring xml:lang="en">'.$env{'course.'.$env{'request.course.id'}.'.description'}.'</imsmd:langstring>
560: </imsmd:title>
561: </imsmd:general>
562: </imsmd:lom>
563: </metadata>'."\n".
564: ' <organizations default="ORG-'.$env{'request.course.id'}.'-'.$now.'">'."\n".
565: ' <organization identifier="ORG-'.$env{'request.course.id'}.'-'.$now.'"'.
566: ' structure="hierarchical">'."\n".
567: ' <title>'.$env{'course.'.$env{'request.course.id'}.'.description'}.'</title>'
568: } else {
569: $$outcome .= 'An error occurred opening the IMS manifest file.<br />'
570: ;
571: }
572: return $ims_manifest;
573: }
574:
575: sub build_package {
576: my ($now,$navmap,$exportitems,$discussions,$outcome,$tempexport,$copyresult,$ims_manifest) = @_;
577: # first iterator to look for dependencies
578: my $it = $navmap->getIterator(undef,undef,undef,1,undef,undef);
579: my $curRes;
580: my $count = 0;
581: my $depth = 0;
582: my $lastcontainer = 0;
583: my %parent = ();
584: my @dependencies = ();
585: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
586: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
587: while ($curRes = $it->next()) {
588: if (ref($curRes)) {
589: $count ++;
590: }
591: if ($curRes == $it->BEGIN_MAP()) {
592: $depth++;
593: $parent{$depth} = $lastcontainer;
594: }
595: if ($curRes == $it->END_MAP()) {
596: $depth--;
597: $lastcontainer = $parent{$depth};
598: }
599: if (ref($curRes)) {
600: if ($curRes->is_sequence() || $curRes->is_page()) {
601: $lastcontainer = $count;
602: }
603: if (grep(/^$count$/,@$exportitems)) {
604: &get_dependencies($exportitems,\%parent,$depth,\@dependencies);
605: }
606: }
607: }
608: # second iterator to build manifest and store resources
609: $it = $navmap->getIterator(undef,undef,undef,1,undef,undef);
610: $depth = 0;
611: my $prevdepth;
612: $count = 0;
613: my $imsresources;
614: my $pkgdepth;
615: while ($curRes = $it->next()) {
616: if ($curRes == $it->BEGIN_MAP()) {
617: $prevdepth = $depth;
618: $depth++;
619: }
620: if ($curRes == $it->END_MAP()) {
621: $prevdepth = $depth;
622: $depth--;
623: }
624:
625: if (ref($curRes)) {
626: $count ++;
627: if ((grep(/^$count$/,@$exportitems)) || (grep(/^$count$/,@dependencies))) {
628: my $symb = $curRes->symb();
629: my $isvisible = 'true';
630: my $resourceref;
631: if ($curRes->randomout()) {
632: $isvisible = 'false';
633: }
634: unless ($curRes->is_sequence()) {
635: $resourceref = 'identifierref="RES-'.$env{'request.course.id'}.'-'.$count.'"';
636: }
637: my $step = $prevdepth - $depth;
638: if (($step >= 0) && ($count > 1)) {
639: while ($step >= 0) {
640: print $ims_manifest "\n".' </item>'."\n";
641: $step --;
642: }
643: }
644: $prevdepth = $depth;
645:
646: my $itementry =
647: '<item identifier="ITEM-'.$env{'request.course.id'}.'-'.$count.
648: '" isvisible="'.$isvisible.'" '.$resourceref.'>'.
649: '<title>'.$curRes->title().'</title>';
650: print $ims_manifest "\n".$itementry;
651:
652: unless ($curRes->is_sequence()) {
653: my $content_file;
654: my @hrefs = ();
655: &process_content($count,$curRes,$cdom,$cnum,$symb,\$content_file,\@hrefs,$copyresult,$tempexport);
656: if ($content_file) {
657: $imsresources .= "\n".
658: ' <resource identifier="RES-'.$env{'request.course.id'}.'-'.$count.
659: '" type="webcontent" href="'.$content_file.'">'."\n".
660: ' <file href="'.$content_file.'" />'."\n";
661: foreach my $item (@hrefs) {
662: $imsresources .=
663: ' <file href="'.$item.'" />'."\n";
664: }
665: if (grep(/^$count$/,@$discussions)) {
666: my $ressymb = $symb;
667: my $mode;
668: if ($ressymb =~ m|adm/($match_domain)/($match_username)/(\d+)/bulletinboard$|) {
669: unless ($ressymb =~ m|adm/wrapper/adm|) {
670: $ressymb = 'bulletin___'.$3.'___adm/wrapper/adm/'.$1.'/'.$2.'/'.$3.'/bulletinboard';
671: }
672: $mode = 'board';
673: }
674: my %extras = (
675: caller => 'imsexport',
676: tempexport => $tempexport.'/resources',
677: count => $count
678: );
679: my $discresult = &Apache::lonfeedback::list_discussion($mode,undef,$ressymb,\%extras);
680: }
681: $imsresources .= ' </resource>'."\n";
682: }
683: }
684: $pkgdepth = $depth;
685: }
686: }
687: }
688: while ($pkgdepth > 0) {
689: print $ims_manifest " </item>\n";
690: $pkgdepth --;
691: }
692: my $resource_text = qq|
693: </organization>
694: </organizations>
695: <resources>
696: $imsresources
697: </resources>
698: </manifest>
699: |;
700: print $ims_manifest $resource_text;
701: }
702:
703: sub get_dependencies {
704: my ($exportitems,$parent,$depth,$dependencies) = @_;
705: if ($depth > 1) {
706: if ((!grep(/^$$parent{$depth}$/,@$exportitems)) && (!grep(/^$$parent{$depth}$/,@$dependencies))) {
707: push(@{$dependencies},$$parent{$depth});
708: if ($depth > 2) {
709: &get_dependencies($exportitems,$parent,$depth-1,$dependencies);
710: }
711: }
712: }
713: }
714:
715: sub process_content {
716: my ($count,$curRes,$cdom,$cnum,$symb,$content_file,$href,$copyresult,$tempexport) = @_;
717: my $content_type;
718: my $message;
719: my @uploads = ();
720: if ($curRes->is_sequence()) {
721: $content_type = 'sequence';
722: } elsif ($curRes->is_page()) {
723: $content_type = 'page'; # need to handle individual items in pages.
724: } elsif ($symb =~ m-public/$cdom/$cnum/syllabus$-) {
725: $content_type = 'syllabus';
726: my $contents = &Apache::imsexport::templatedpage($content_type);
727: if ($contents) {
728: $$content_file = &store_template($contents,$tempexport,$count,$content_type);
729: }
730: } elsif ($symb =~ m-\.sequence___\d+___ext-) {
731: $content_type = 'external';
732: my $title = $curRes->title;
733: my $contents = &Apache::imsexport::external($symb,$title);
734: if ($contents) {
735: $$content_file = &store_template($contents,$tempexport,$count,$content_type);
736: }
737: } elsif ($symb =~ m-adm/navmaps$-) {
738: $content_type = 'navmap';
739: } elsif ($symb =~ m-adm/[^/]+/[^/]+/(\d+)/smppg$-) {
740: $content_type = 'simplepage';
741: my $contents = &Apache::imsexport::templatedpage($content_type,$1,$count,\@uploads);
742: if ($contents) {
743: $$content_file = &store_template($contents,$tempexport,$count,$content_type);
744: }
745: } elsif ($symb =~ m-lib/templates/simpleproblem\.problem$-) {
746: $content_type = 'simpleproblem';
747: my $contents = &Apache::imsexport::simpleproblem($symb);
748: if ($contents) {
749: $$content_file = &store_template($contents,$tempexport,$count,$content_type);
750: }
751: } elsif ($symb =~ m-lib/templates/examupload\.problem$-) {
752: $content_type = 'examupload';
753: } elsif ($symb =~ m-adm/($match_domain)/($match_username)/(\d+)/bulletinboard$-) {
754: $content_type = 'bulletinboard';
755: my $contents = &Apache::imsexport::templatedpage($content_type,$3,$count,\@uploads,$1,$2);
756: if ($contents) {
757: $$content_file = &store_template($contents,$tempexport,$count,$content_type);
758: }
759: } elsif ($symb =~ m-adm/([^/]+)/([^/]+)/aboutme$-) {
760: $content_type = 'aboutme';
761: my $contents = &Apache::imsexport::templatedpage($content_type,undef,$count,\@uploads,$1,$2);
762: if ($contents) {
763: $$content_file = &store_template($contents,$tempexport,$count,$content_type);
764: }
765: } elsif ($symb =~ m-\.(sequence|page)___\d+___uploaded/$cdom/$cnum/-) {
766: $$content_file = &replicate_content($cdom,$cnum,$tempexport,$symb,$count,\$message,$href,'uploaded');
767: } elsif ($symb =~ m-\.(sequence|page)___\d+___([^/]+)/([^/]+)-) {
768: my $canedit = 0;
769: if ($2 eq $env{'user.domain'} && $3 eq $env{'user.name'}) {
770: $canedit= 1;
771: }
772: # only include problem code where current user is author
773: if ($canedit) {
774: $$content_file = &replicate_content($cdom,$cnum,$tempexport,$symb,$count,\$message,$href,'resource');
775: } else {
776: $$content_file = &replicate_content($cdom,$cnum,$tempexport,$symb,$count,\$message,$href,'noedit');
777: }
778: } elsif ($symb =~ m-uploaded/$cdom/$cnum-) {
779: $$content_file = &replicate_content($cdom,$cnum,$tempexport,$symb,$count,\$message,$href,'uploaded');
780: }
781: if (@uploads > 0) {
782: foreach my $item (@uploads) {
783: my $uploadmsg = '';
784: &replicate_content($cdom,$cnum,$tempexport,$item,$count,\$uploadmsg,$href,'templateupload');
785: if ($uploadmsg) {
786: $$copyresult .= $uploadmsg."\n";
787: }
788: }
789: }
790: if ($message) {
791: $$copyresult .= $message."\n";
792: }
793: }
794:
795: sub replicate_content {
796: my ($cdom,$cnum,$tempexport,$symb,$count,$message,$href,$caller) = @_;
797: my ($map,$ind,$url);
798: if ($caller eq 'templateupload') {
799: $url = $symb;
800: $url =~ s#//#/#g;
1.344 bisitz 801: } else {
1.329 droeschl 802: ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb);
803: }
804: my $content;
805: my $filename;
806: my $repstatus;
807: my $content_name;
808: if ($url =~ m-/([^/]+)$-) {
809: $filename = $1;
810: if (!-e $tempexport.'/resources') {
811: mkdir($tempexport.'/resources',0700);
812: }
813: if (!-e $tempexport.'/resources/'.$count) {
814: mkdir($tempexport.'/resources/'.$count,0700);
815: }
816: my $destination = $tempexport.'/resources/'.$count.'/'.$filename;
817: my $copiedfile;
818: if ($copiedfile = Apache::File->new('>'.$destination)) {
819: my $content;
820: if ($caller eq 'resource') {
821: my $respath = $Apache::lonnet::perlvar{'lonDocRoot'}.'/res';
822: my $filepath = &Apache::lonnet::filelocation($respath,$url);
823: $content = &Apache::lonnet::getfile($filepath);
824: if ($content eq -1) {
825: $$message = 'Could not copy file '.$filename;
826: } else {
827: &extract_media($url,$cdom,$cnum,\$content,$count,$tempexport,$href,$message,'resource');
828: $repstatus = 'ok';
829: }
830: } elsif ($caller eq 'uploaded' || $caller eq 'templateupload') {
831: my $rtncode;
832: $repstatus = &Apache::lonnet::getuploaded('GET',$url,$cdom,$cnum,\$content,$rtncode);
833: if ($repstatus eq 'ok') {
834: if ($url =~ /\.html?$/i) {
835: &extract_media($url,$cdom,$cnum,\$content,$count,$tempexport,$href,$message,'uploaded');
836: }
837: } else {
838: $$message = 'Could not render '.$url.' server message - '.$rtncode."<br />\n";
839: }
840: } elsif ($caller eq 'noedit') {
1.344 bisitz 841: # Need to render the resource without the LON-CAPA Internal header and the Post discussion footer, and then set $content equal to this.
1.329 droeschl 842: $repstatus = 'ok';
1.344 bisitz 843: $content = 'Not the owner of this resource';
1.329 droeschl 844: }
845: if ($repstatus eq 'ok') {
846: print $copiedfile $content;
847: }
848: close($copiedfile);
849: } else {
850: $$message = 'Could not open destination file for '.$filename."<br />\n";
851: }
852: } else {
853: $$message = 'Could not determine name of file for '.$symb."<br />\n";
854: }
855: if ($repstatus eq 'ok') {
856: $content_name = 'resources/'.$count.'/'.$filename;
857: }
858: return $content_name;
859: }
860:
861: sub extract_media {
862: my ($url,$cdom,$cnum,$content,$count,$tempexport,$href,$message,$caller) = @_;
863: my ($dirpath,$container);
864: my %allfiles = ();
865: my %codebase = ();
866: if ($url =~ m-(.*/)([^/]+)$-) {
867: $dirpath = $1;
868: $container = $2;
869: } else {
870: $dirpath = $url;
871: $container = '';
872: }
873: &Apache::lonnet::extract_embedded_items(undef,\%allfiles,\%codebase,$content);
874: foreach my $embed_file (keys(%allfiles)) {
875: my $filename;
876: if ($embed_file =~ m#([^/]+)$#) {
877: $filename = $1;
878: } else {
879: $filename = $embed_file;
880: }
881: my $newname = 'res/'.$filename;
882: my ($rtncode,$embed_content,$repstatus);
883: my $embed_url;
884: if ($embed_file =~ m-^/-) {
885: $embed_url = $embed_file; # points to absolute path
886: } else {
887: if ($embed_file =~ m-https?://-) {
888: next; # points to url
889: } else {
890: $embed_url = $dirpath.$embed_file; # points to relative path
891: }
892: }
893: if ($caller eq 'resource') {
1.344 bisitz 894: my $respath = $Apache::lonnet::perlvar{'lonDocRoot'}.'/res';
895: my $embed_path = &Apache::lonnet::filelocation($respath,$embed_url);
1.329 droeschl 896: $embed_content = &Apache::lonnet::getfile($embed_path);
897: unless ($embed_content eq -1) {
898: $repstatus = 'ok';
899: }
900: } elsif ($caller eq 'uploaded') {
1.364 bisitz 901:
1.329 droeschl 902: $repstatus = &Apache::lonnet::getuploaded('GET',$embed_url,$cdom,$cnum,\$embed_content,$rtncode);
903: }
904: if ($repstatus eq 'ok') {
905: my $destination = $tempexport.'/resources/'.$count.'/res';
906: if (!-e "$destination") {
907: mkdir($destination,0755);
908: }
909: $destination .= '/'.$filename;
910: my $copiedfile;
911: if ($copiedfile = Apache::File->new('>'.$destination)) {
912: print $copiedfile $embed_content;
913: push(@{$href},'resources/'.$count.'/res/'.$filename);
914: my $attrib_regexp = '';
915: if (@{$allfiles{$embed_file}} > 1) {
916: $attrib_regexp = join('|',@{$allfiles{$embed_file}});
917: } else {
918: $attrib_regexp = $allfiles{$embed_file}[0];
919: }
920: $$content =~ s#($attrib_regexp\s*=\s*['"]?)\Q$embed_file\E(['"]?)#$1$newname$2#gi;
921: if ($caller eq 'resource' && $container =~ /\.(problem|library)$/) {
922: $$content =~ s#\Q$embed_file\E#$newname#gi;
923: }
924: }
925: } else {
926: $$message .= 'replication of embedded file - '.$embed_file.' in '.$url.' failed, reason -'.$rtncode."<br />\n";
927: }
928: }
929: return;
930: }
931:
932: sub store_template {
933: my ($contents,$tempexport,$count,$content_type) = @_;
934: if ($contents) {
935: if ($tempexport) {
936: if (!-e $tempexport.'/resources') {
937: mkdir($tempexport.'/resources',0700);
938: }
939: if (!-e $tempexport.'/resources/'.$count) {
940: mkdir($tempexport.'/resources/'.$count,0700);
941: }
942: my $destination = $tempexport.'/resources/'.$count.'/'.$content_type.'.xml';
943: my $storetemplate;
944: if ($storetemplate = Apache::File->new('>'.$destination)) {
945: print $storetemplate $contents;
946: close($storetemplate);
947: }
948: if ($content_type eq 'external') {
949: return 'resources/'.$count.'/'.$content_type.'.html';
950: } else {
951: return 'resources/'.$count.'/'.$content_type.'.xml';
952: }
953: }
954: }
955: }
956:
957:
958: sub group_import {
959: my ($coursenum, $coursedom, $folder, $container, $caller, @files) = @_;
960:
961: while (@files) {
962: my ($name, $url, $residx) = @{ shift(@files) };
1.344 bisitz 963: if (($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$})
1.329 droeschl 964: && ($caller eq 'londocs')
965: && (!&Apache::lonnet::stat_file($url))) {
1.364 bisitz 966:
1.329 droeschl 967: my $errtext = '';
968: my $fatal = 0;
969: my $newmapstr = '<map>'."\n".
970: '<resource id="1" src="" type="start"></resource>'."\n".
971: '<link from="1" to="2" index="1"></link>'."\n".
972: '<resource id="2" src="" type="finish"></resource>'."\n".
973: '</map>';
974: $env{'form.output'}=$newmapstr;
975: my $result=&Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
976: 'output',$1.$2);
977: if ($result != m|^/uploaded/|) {
978: $errtext.='Map not saved: A network error occurred when trying to save the new map. ';
979: $fatal = 2;
980: }
981: if ($fatal) {
982: return ($errtext,$fatal);
983: }
984: }
985: if ($url) {
1.344 bisitz 986: if (!$residx
1.329 droeschl 987: || defined($LONCAPA::map::zombies[$residx])) {
988: $residx = &LONCAPA::map::getresidx($url,$residx);
989: push(@LONCAPA::map::order, $residx);
990: }
991: my $ext = 'false';
992: if ($url=~m{^http://} || $url=~m{^https://}) { $ext = 'true'; }
993: $url = &LONCAPA::map::qtunescape($url);
994: $name = &LONCAPA::map::qtunescape($name);
1.344 bisitz 995: $LONCAPA::map::resources[$residx] =
1.329 droeschl 996: join(':', ($name, $url, $ext, 'normal', 'res'));
997: }
998: }
999: return &storemap($coursenum, $coursedom, $folder.'.'.$container);
1000: }
1001:
1002: sub breadcrumbs {
1.408 raeburn 1003: my ($allowed,$crstype)=@_;
1.329 droeschl 1004: &Apache::lonhtmlcommon::clear_breadcrumbs();
1005: my (@folders);
1006: if ($env{'form.pagepath'}) {
1007: @folders = split('&',$env{'form.pagepath'});
1008: } else {
1009: @folders=split('&',$env{'form.folderpath'});
1010: }
1011: my $folderpath;
1012: my $cpinfo='';
1013: my $plain='';
1014: my $randompick=-1;
1015: my $isencrypted=0;
1016: my $ishidden=0;
1017: my $is_random_order=0;
1.395 raeburn 1018: if (!$allowed) {
1019: my $description = $env{'course.'.$env{'request.course.id'}.'.description'};
1020: &Apache::lonhtmlcommon::add_breadcrumb(
1021: {'href' => '/adm/menu',
1022: 'title'=> 'Go to main menu',
1023: 'text' => $description,
1024: });
1025: $plain .= $description.' >';
1026: }
1.329 droeschl 1027: while (@folders) {
1028: my $folder=shift(@folders);
1029: my $foldername=shift(@folders);
1030: if ($folderpath) {$folderpath.='&';}
1031: $folderpath.=$folder.'&'.$foldername;
1032: my $url='/adm/coursedocs?folderpath='.
1033: &escape($folderpath);
1034: my $name=&unescape($foldername);
1.344 bisitz 1035: # randompick number, hidden, encrypted, random order, is appended with ":"s to the foldername
1.329 droeschl 1036: $name=~s/\:(\d*)\:(\w*)\:(\w*):(\d*)$//;
1.344 bisitz 1037: if ($1 ne '') {
1.329 droeschl 1038: $randompick=$1;
1039: } else {
1040: $randompick=-1;
1041: }
1042: if ($2) { $ishidden=1; }
1043: if ($3) { $isencrypted=1; }
1044: if ($4 ne '') { $is_random_order = 1; }
1045: if ($folder eq 'supplemental') {
1.408 raeburn 1046: $name = &mt('Supplemental '.$crstype.' Documents');
1.329 droeschl 1047: }
1048: &Apache::lonhtmlcommon::add_breadcrumb(
1049: {'href'=>$url.$cpinfo,
1050: 'title'=>$name,
1.367 droeschl 1051: 'text'=>$name,
1.329 droeschl 1052: 'no_mt'=>1,
1053: });
1054: $plain.=$name.' > ';
1055: }
1056: $plain=~s/\>\;\s*$//;
1057: return (&Apache::lonhtmlcommon::breadcrumbs(undef,undef,0,'nohelp',
1.379 bisitz 1058: undef, undef, 1 ),$randompick,$ishidden,$isencrypted,$plain,$is_random_order);
1.329 droeschl 1059: }
1060:
1061: sub log_docs {
1062: return &Apache::lonnet::instructor_log('docslog',@_);
1063: }
1064:
1065: {
1066: my @oldresources=();
1067: my @oldorder=();
1068: my $parmidx;
1069: my %parmaction=();
1070: my %parmvalue=();
1071: my $changedflag;
1072:
1073: sub snapshotbefore {
1074: @oldresources=@LONCAPA::map::resources;
1075: @oldorder=@LONCAPA::map::order;
1076: $parmidx=undef;
1077: %parmaction=();
1078: %parmvalue=();
1079: $changedflag=0;
1080: }
1081:
1082: sub remember_parms {
1083: my ($idx,$parameter,$action,$value)=@_;
1084: $parmidx=$idx;
1085: $parmaction{$parameter}=$action;
1086: $parmvalue{$parameter}=$value;
1087: $changedflag=1;
1088: }
1089:
1090: sub log_differences {
1091: my ($plain)=@_;
1092: my %storehash=('folder' => $plain,
1093: 'currentfolder' => $env{'form.folder'});
1094: if ($parmidx) {
1095: $storehash{'parameter_res'}=$oldresources[$parmidx];
1096: foreach my $parm (keys(%parmaction)) {
1097: $storehash{'parameter_action_'.$parm}=$parmaction{$parm};
1098: $storehash{'parameter_value_'.$parm}=$parmvalue{$parm};
1099: }
1100: }
1101: my $maxidx=$#oldresources;
1102: if ($#LONCAPA::map::resources>$#oldresources) {
1103: $maxidx=$#LONCAPA::map::resources;
1104: }
1105: for (my $idx=0; $idx<=$maxidx; $idx++) {
1106: if ($LONCAPA::map::resources[$idx] ne $oldresources[$idx]) {
1107: $storehash{'before_resources_'.$idx}=$oldresources[$idx];
1108: $storehash{'after_resources_'.$idx}=$LONCAPA::map::resources[$idx];
1109: $changedflag=1;
1110: }
1111: if ($LONCAPA::map::order[$idx] ne $oldorder[$idx]) {
1112: $storehash{'before_order_res_'.$idx}=$oldresources[$oldorder[$idx]];
1113: $storehash{'after_order_res_'.$idx}=$LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
1114: $changedflag=1;
1115: }
1116: }
1117: $storehash{'maxidx'}=$maxidx;
1118: if ($changedflag) { &log_docs(\%storehash); }
1119: }
1120: }
1121:
1122:
1123:
1124:
1125:
1126: sub docs_change_log {
1127: my ($r)=@_;
1128: my $folder=$env{'form.folder'};
1129: $r->print(&Apache::loncommon::start_page('Course Document Change Log'));
1130: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Course Document Change Log'));
1131: my %docslog=&Apache::lonnet::dump('nohist_docslog',
1132: $env{'course.'.$env{'request.course.id'}.'.domain'},
1133: $env{'course.'.$env{'request.course.id'}.'.num'});
1134:
1135: if ((keys(%docslog))[0]=~/^error\:/) { undef(%docslog); }
1136:
1137: $r->print('<form action="/adm/coursedocs" method="post" name="docslog">'.
1138: '<input type="hidden" name="docslog" value="1" />');
1139:
1140: my %saveable_parameters = ('show' => 'scalar',);
1141: &Apache::loncommon::store_course_settings('docs_log',
1142: \%saveable_parameters);
1143: &Apache::loncommon::restore_course_settings('docs_log',
1144: \%saveable_parameters);
1145: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1146: my %lt=('hiddenresource' => 'Resources hidden',
1147: 'encrypturl' => 'URL hidden',
1148: 'randompick' => 'Randomly pick',
1149: 'randomorder' => 'Randomly ordered',
1150: 'set' => 'set to',
1151: 'del' => 'deleted');
1152: $r->print(&Apache::loncommon::display_filter().
1153: '<input type="hidden" name="folder" value="'.$folder.'" />'.
1154: '<input type="submit" value="'.&mt('Display').'" /></form>');
1155: $r->print(&Apache::loncommon::start_data_table().&Apache::loncommon::start_data_table_header_row().
1156: '<th>'.&mt('Time').'</th><th>'.&mt('User').'</th><th>'.&mt('Folder').'</th><th>'.&mt('Before').'</th><th>'.
1157: &mt('After').'</th>'.
1158: &Apache::loncommon::end_data_table_header_row());
1159: my $shown=0;
1160: foreach my $id (sort { $docslog{$b}{'exe_time'}<=>$docslog{$a}{'exe_time'} } (keys(%docslog))) {
1161: if ($env{'form.displayfilter'} eq 'currentfolder') {
1162: if ($docslog{$id}{'logentry'}{'currentfolder'} ne $folder) { next; }
1163: }
1164: my @changes=keys(%{$docslog{$id}{'logentry'}});
1165: if ($env{'form.displayfilter'} eq 'containing') {
1166: my $wholeentry=$docslog{$id}{'exe_uname'}.':'.$docslog{$id}{'exe_udom'}.':'.
1167: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},$docslog{$id}{'exe_udom'});
1168: foreach my $key (@changes) {
1169: $wholeentry.=':'.$docslog{$id}{'logentry'}{$key};
1170: }
1.344 bisitz 1171: if ($wholeentry!~/\Q$env{'form.containingphrase'}\E/i) { next; }
1.329 droeschl 1172: }
1173: my $count = 0;
1174: my $time =
1175: &Apache::lonlocal::locallocaltime($docslog{$id}{'exe_time'});
1176: my $plainname =
1177: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},
1178: $docslog{$id}{'exe_udom'});
1179: my $about_me_link =
1180: &Apache::loncommon::aboutmewrapper($plainname,
1181: $docslog{$id}{'exe_uname'},
1182: $docslog{$id}{'exe_udom'});
1183: my $send_msg_link='';
1184: if ((($docslog{$id}{'exe_uname'} ne $env{'user.name'})
1185: || ($docslog{$id}{'exe_udom'} ne $env{'user.domain'}))) {
1186: $send_msg_link ='<br />'.
1187: &Apache::loncommon::messagewrapper(&mt('Send message'),
1188: $docslog{$id}{'exe_uname'},
1189: $docslog{$id}{'exe_udom'});
1190: }
1191: $r->print(&Apache::loncommon::start_data_table_row());
1192: $r->print('<td>'.$time.'</td>
1193: <td>'.$about_me_link.
1194: '<br /><tt>'.$docslog{$id}{'exe_uname'}.
1195: ':'.$docslog{$id}{'exe_udom'}.'</tt>'.
1196: $send_msg_link.'</td><td>'.
1197: $docslog{$id}{'logentry'}{'folder'}.'</td><td>');
1198: # Before
1199: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1200: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
1201: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
1202: if ($oldname ne $newname) {
1203: $r->print(&LONCAPA::map::qtescape($oldname));
1204: }
1205: }
1206: $r->print('<ul>');
1207: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1208: if ($docslog{$id}{'logentry'}{'before_order_res_'.$idx}) {
1209: $r->print('<li>'.&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'before_order_res_'.$idx}))[0]).'</li>');
1210: }
1211: }
1212: $r->print('</ul>');
1213: # After
1214: $r->print('</td><td>');
1215:
1216: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1217: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
1218: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
1219: if ($oldname ne '' && $oldname ne $newname) {
1220: $r->print(&LONCAPA::map::qtescape($newname));
1221: }
1.364 bisitz 1222: }
1.329 droeschl 1223: $r->print('<ul>');
1224: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
1225: if ($docslog{$id}{'logentry'}{'after_order_res_'.$idx}) {
1226: $r->print('<li>'.&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'after_order_res_'.$idx}))[0]).'</li>');
1227: }
1228: }
1229: $r->print('</ul>');
1230: if ($docslog{$id}{'logentry'}{'parameter_res'}) {
1231: $r->print(&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'parameter_res'}))[0]).':<ul>');
1232: foreach my $parameter ('randompick','hiddenresource','encrypturl','randomorder') {
1233: if ($docslog{$id}{'logentry'}{'parameter_action_'.$parameter}) {
1234: $r->print('<li>'.
1235: &mt($lt{$parameter}.' '.$lt{$docslog{$id}{'logentry'}{'parameter_action_'.$parameter}}.' [_1]',
1236: $docslog{$id}{'logentry'}{'parameter_value_'.$parameter})
1237: .'</li>');
1238: }
1239: }
1240: $r->print('</ul>');
1241: }
1242: # End
1243: $r->print('</td>'.&Apache::loncommon::end_data_table_row());
1244: $shown++;
1245: if (!($env{'form.show'} eq &mt('all')
1246: || $shown<=$env{'form.show'})) { last; }
1247: }
1248: $r->print(&Apache::loncommon::end_data_table());
1249: }
1250:
1251: sub update_paste_buffer {
1252: my ($coursenum,$coursedom) = @_;
1253:
1254: return if (!defined($env{'form.markcopy'}));
1255: return if (!defined($env{'form.copyfolder'}));
1256: return if ($env{'form.markcopy'} < 0);
1257:
1258: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
1259: $env{'form.copyfolder'});
1.364 bisitz 1260:
1.329 droeschl 1261: return if ($fatal);
1262:
1263: # Mark for copying
1264: my ($title,$url)=split(':',$LONCAPA::map::resources[$LONCAPA::map::order[$env{'form.markcopy'}]]);
1265: if (&is_supplemental_title($title)) {
1266: &Apache::lonnet::appenv({'docs.markedcopy_supplemental' => $title});
1267: ($title) = &parse_supplemental_title($title);
1268: } elsif ($env{'docs.markedcopy_supplemental'}) {
1.346 raeburn 1269: &Apache::lonnet::delenv('docs.markedcopy_supplemental');
1.329 droeschl 1270: }
1271: $url=~s{http(:|:)//https(:|:)//}{https$2//};
1272:
1273: &Apache::lonnet::appenv({'docs.markedcopy_title' => $title,
1274: 'docs.markedcopy_url' => $url});
1275: delete($env{'form.markcopy'});
1276: }
1277:
1278: sub print_paste_buffer {
1279: my ($r,$container) = @_;
1280: return if (!defined($env{'docs.markedcopy_url'}));
1281:
1.381 bisitz 1282: $r->print('<fieldset>'
1283: .'<legend>'.&mt('Clipboard').'</legend>'
1284: .'<form name="pasteform" action="/adm/coursedocs" method="post">'
1285: .'<input type="submit" name="pastemarked" value="'.&mt('Paste').'" /> '
1286: );
1.329 droeschl 1287:
1288: my $type;
1289: if ($env{'docs.markedcopy_url'} =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//} ) {
1290: $type = &mt('External Resource');
1291: $r->print($type.': '.
1292: &LONCAPA::map::qtescape($env{'docs.markedcopy_title'}).' ('.
1293: &LONCAPA::map::qtescape($env{'docs.markedcopy_url'}).')');
1294: } else {
1295: my $extension = (split(/\./,$env{'docs.markedcopy_url'}))[-1];
1296: my $icon = &Apache::loncommon::icon($extension);
1297: if ($extension eq 'sequence' &&
1298: $env{'docs.markedcopy_url'} =~ m{/default_\d+\.sequence$ }x) {
1299: $icon = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
1.380 bisitz 1300: $icon .= '/navmap.folder.closed.gif';
1.329 droeschl 1301: }
1302: $icon = '<img src="'.$icon.'" alt="" class="LC_icon" />';
1303: $r->print($icon.$type.': '. &parse_supplemental_title(&LONCAPA::map::qtescape($env{'docs.markedcopy_title'})));
1304: }
1305: if ($container eq 'page') {
1306: $r->print('
1307: <input type="hidden" name="pagepath" value="'.&HTML::Entities::encode($env{'form.pagepath'},'<>&"').'" />
1308: <input type="hidden" name="pagesymb" value="'.&HTML::Entities::encode($env{'form.pagesymb'},'<>&"').'" />
1309: ');
1310: } else {
1311: $r->print('
1312: <input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />
1313: ');
1314: }
1.381 bisitz 1315: $r->print('</form></fieldset>');
1.329 droeschl 1316: }
1317:
1318: sub do_paste_from_buffer {
1319: my ($coursenum,$coursedom,$folder) = @_;
1320:
1321: if (!$env{'form.pastemarked'}) {
1322: return;
1323: }
1324:
1325: # paste resource to end of list
1326: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url'});
1327: my $title=&LONCAPA::map::qtescape($env{'docs.markedcopy_title'});
1328: # Maps need to be copied first
1329: if (($url=~/\.(page|sequence)$/) && ($url=~/^\/uploaded\//)) {
1330: $title=&mt('Copy of').' '.$title;
1331: my $newid=$$.int(rand(100)).time;
1332: my ($oldid,$ext) = ($url=~/^(.+)\.(\w+)$/);
1333: if ($oldid =~ m{^(/uploaded/\Q$coursedom\E/\Q$coursenum\E/)(\D+)(\d+)$}) {
1334: my $path = $1;
1335: my $prefix = $2;
1336: my $ancestor = $3;
1337: if (length($ancestor) > 10) {
1338: $ancestor = substr($ancestor,-10,10);
1339: }
1340: $oldid = $path.$prefix.$ancestor;
1341: }
1342: my $counter = 0;
1343: my $newurl=$oldid.$newid.'.'.$ext;
1344: my $is_unique = &uniqueness_check($newurl);
1345: while (!$is_unique && $counter < 100) {
1346: $counter ++;
1347: $newid ++;
1348: $newurl = $oldid.$newid;
1349: $is_unique = &uniqueness_check($newurl);
1350: }
1351: if (!$is_unique) {
1352: if ($url=~/\.page$/) {
1353: return &mt('Paste failed: an error occurred creating a unique URL for the composite page');
1354: } else {
1355: return &mt('Paste failed: an error occurred creating a unique URL for the folder');
1356: }
1357: }
1358: my $storefn=$newurl;
1359: $storefn=~s{^/\w+/$match_domain/$match_username/}{};
1360: my $paste_map_result =
1361: &Apache::lonclonecourse::writefile($env{'request.course.id'},$storefn,
1362: &Apache::lonnet::getfile($url));
1363: if ($paste_map_result eq '/adm/notfound.html') {
1364: if ($url=~/\.page$/) {
1365: return &mt('Paste failed: an error occurred saving the composite page');
1366: } else {
1367: return &mt('Paste failed: an error occurred saving the folder');
1368: }
1369: }
1370: $url = $newurl;
1371: }
1372: # published maps can only exists once, so remove it from paste buffer when done
1373: if (($url=~/\.(page|sequence)$/) && ($url=~m {^/res/})) {
1.346 raeburn 1374: &Apache::lonnet::delenv('docs.markedcopy');
1.329 droeschl 1375: }
1376: if ($url=~ m{/smppg$}) {
1377: my $db_name = &Apache::lonsimplepage::get_db_name($url);
1378: if ($db_name =~ /^smppage_/) {
1379: #simple pages, need to copy the db contents to a new one.
1380: my %contents=&Apache::lonnet::dump($db_name,$coursedom,$coursenum);
1381: my $now = time();
1382: $db_name =~ s{_\d*$ }{_$now}x;
1383: my $result=&Apache::lonnet::put($db_name,\%contents,
1384: $coursedom,$coursenum);
1.344 bisitz 1385: $url =~ s{/(\d*)/smppg$ }{/$now/smppg}x;
1.329 droeschl 1386: $title=&mt('Copy of').' '.$title;
1387: }
1388: }
1389: $title = &LONCAPA::map::qtunescape($title);
1390: my $ext='false';
1391: if ($url=~m{^http(|s)://}) { $ext='true'; }
1392: $url = &LONCAPA::map::qtunescape($url);
1393: # Now insert the URL at the bottom
1394: my $newidx = &LONCAPA::map::getresidx($url);
1395: if ($env{'docs.markedcopy_supplemental'}) {
1396: if ($folder =~ /^supplemental/) {
1397: $title = $env{'docs.markedcopy_supplemental'};
1398: } else {
1.344 bisitz 1399: (undef,undef,$title) =
1.329 droeschl 1400: &parse_supplemental_title($env{'docs.markedcopy_supplemental'});
1401: }
1402: } else {
1403: if ($folder=~/^supplemental/) {
1404: $title=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
1405: $env{'user.domain'}.'___&&&___'.$title;
1406: }
1407: }
1408:
1409: $LONCAPA::map::resources[$newidx]= $title.':'.$url.':'.$ext.':normal:res';
1410: push(@LONCAPA::map::order, $newidx);
1411: return 'ok';
1412: # Store the result
1413: }
1414:
1415: sub uniqueness_check {
1416: my ($newurl) = @_;
1417: my $unique = 1;
1418: foreach my $res (@LONCAPA::map::order) {
1419: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
1420: $url=&LONCAPA::map::qtescape($url);
1421: if ($newurl eq $url) {
1422: $unique = 0;
1.344 bisitz 1423: last;
1.329 droeschl 1424: }
1425: }
1426: return $unique;
1427: }
1428:
1429: my %parameter_type = ( 'randompick' => 'int_pos',
1430: 'hiddenresource' => 'string_yesno',
1431: 'encrypturl' => 'string_yesno',
1432: 'randomorder' => 'string_yesno',);
1433: my $valid_parameters_re = join('|',keys(%parameter_type));
1434: # set parameters
1435: sub update_parameter {
1436:
1437: return 0 if ($env{'form.changeparms'} !~ /^($valid_parameters_re)$/);
1438:
1439: my $which = $env{'form.changeparms'};
1440: my $idx = $env{'form.setparms'};
1441: if ($env{'form.'.$which.'_'.$idx}) {
1442: my $value = ($which eq 'randompick') ? $env{'form.'.$which.'_'.$idx}
1443: : 'yes';
1444: &LONCAPA::map::storeparameter($idx, 'parameter_'.$which, $value,
1445: $parameter_type{$which});
1446: &remember_parms($idx,$which,'set',$value);
1447: } else {
1448: &LONCAPA::map::delparameter($idx,'parameter_'.$which);
1.364 bisitz 1449:
1.329 droeschl 1450: &remember_parms($idx,$which,'del');
1451: }
1452: return 1;
1453: }
1454:
1455:
1456: sub handle_edit_cmd {
1457: my ($coursenum,$coursedom) =@_;
1458:
1459: my ($cmd,$idx)=split('_',$env{'form.cmd'});
1460:
1461: my $ratstr = $LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
1462: my ($title, $url, @rrest) = split(':', $ratstr);
1463:
1464: if ($cmd eq 'del') {
1465: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
1466: ($url!~/\.(page|sequence|problem|exam|quiz|assess|survey|form|library|task)$/)) {
1467: &Apache::lonnet::removeuploadedurl($url);
1468: } else {
1469: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
1470: }
1471: splice(@LONCAPA::map::order, $idx, 1);
1472:
1473: } elsif ($cmd eq 'cut') {
1474: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
1475: splice(@LONCAPA::map::order, $idx, 1);
1476:
1.344 bisitz 1477: } elsif ($cmd eq 'up'
1.329 droeschl 1478: && ($idx) && (defined($LONCAPA::map::order[$idx-1]))) {
1479: @LONCAPA::map::order[$idx-1,$idx] = @LONCAPA::map::order[$idx,$idx-1];
1480:
1481: } elsif ($cmd eq 'down'
1482: && defined($LONCAPA::map::order[$idx+1])) {
1483: @LONCAPA::map::order[$idx+1,$idx] = @LONCAPA::map::order[$idx,$idx+1];
1484:
1485: } elsif ($cmd eq 'rename') {
1486:
1487: my $comment = &LONCAPA::map::qtunescape($env{'form.title'});
1488: if ($comment=~/\S/) {
1489: $LONCAPA::map::resources[$LONCAPA::map::order[$idx]]=
1490: $comment.':'.join(':', $url, @rrest);
1491: }
1492: # Devalidate title cache
1493: my $renamed_url=&LONCAPA::map::qtescape($url);
1494: &Apache::lonnet::devalidate_title_cache($renamed_url);
1495: } else {
1496: return 0;
1497: }
1498: return 1;
1499: }
1500:
1501: sub editor {
1.408 raeburn 1502: my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$crstype)=@_;
1.329 droeschl 1503: my $container= ($env{'form.pagepath'}) ? 'page'
1504: : 'sequence';
1505:
1506: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
1507: $folder.'.'.$container);
1508: return $errtext if ($fatal);
1509:
1510: if ($#LONCAPA::map::order<1) {
1511: my $idx=&LONCAPA::map::getresidx();
1512: if ($idx<=0) { $idx=1; }
1513: $LONCAPA::map::order[0]=$idx;
1514: $LONCAPA::map::resources[$idx]='';
1515: }
1.364 bisitz 1516:
1.395 raeburn 1517: my ($breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,$is_random_order);
1518: if ($allowed) {
1519: ($breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,$is_random_order) =
1.408 raeburn 1520: &breadcrumbs($allowed,$crstype);
1.395 raeburn 1521: $r->print($breadcrumbtrail);
1522: } else {
1523: $randompick = -1;
1524: }
1.364 bisitz 1525:
1.329 droeschl 1526: # ------------------------------------------------------------ Process commands
1527:
1528: # ---------------- if they are for this folder and user allowed to make changes
1529: if (($allowed) && ($env{'form.folder'} eq $folder)) {
1530: # set parameters and change order
1531: &snapshotbefore();
1532:
1533: if (&update_parameter()) {
1534: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
1535: return $errtext if ($fatal);
1536: }
1537:
1538: if ($env{'form.newpos'} && $env{'form.currentpos'}) {
1539: # change order
1540: my $res = splice(@LONCAPA::map::order,$env{'form.currentpos'}-1,1);
1541: splice(@LONCAPA::map::order,$env{'form.newpos'}-1,0,$res);
1542:
1543: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
1544: return $errtext if ($fatal);
1545: }
1.364 bisitz 1546:
1.329 droeschl 1547: if ($env{'form.pastemarked'}) {
1.344 bisitz 1548: my $paste_res =
1.329 droeschl 1549: &do_paste_from_buffer($coursenum,$coursedom,$folder);
1550: if ($paste_res eq 'ok') {
1551: ($errtext,$fatal) = &storemap($coursenum,$coursedom,$folder.'.'.$container);
1552: return $errtext if ($fatal);
1553: } elsif ($paste_res ne '') {
1554: $r->print('<p><span class="LC_error">'.$paste_res.'</span></p>');
1555: }
1556: }
1557:
1558: $r->print($upload_output);
1559:
1560: if (&handle_edit_cmd()) {
1561: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
1562: return $errtext if ($fatal);
1563: }
1564: # Group import/search
1565: if ($env{'form.importdetail'}) {
1566: my @imports;
1567: foreach my $item (split(/\&/,$env{'form.importdetail'})) {
1568: if (defined($item)) {
1569: my ($name,$url,$residx)=
1570: map {&unescape($_)} split(/\=/,$item);
1571: push(@imports, [$name, $url, $residx]);
1572: }
1573: }
1574: ($errtext,$fatal)=&group_import($coursenum, $coursedom, $folder,
1575: $container,'londocs',@imports);
1576: return $errtext if ($fatal);
1577: }
1578: # Loading a complete map
1579: if ($env{'form.loadmap'}) {
1580: if ($env{'form.importmap'}=~/\w/) {
1581: foreach my $res (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
1582: my ($title,$url,$ext,$type)=split(/\:/,$res);
1583: my $idx=&LONCAPA::map::getresidx($url);
1584: $LONCAPA::map::resources[$idx]=$res;
1585: $LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx;
1586: }
1587: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1588: $folder.'.'.$container);
1589: return $errtext if ($fatal);
1590: } else {
1591: $r->print('<p><span class="LC_error">'.&mt('No map selected.').'</span></p>');
1.364 bisitz 1592:
1.329 droeschl 1593: }
1594: }
1595: &log_differences($plain);
1596: }
1597: # ---------------------------------------------------------------- End commands
1598: # ---------------------------------------------------------------- Print screen
1599: my $idx=0;
1600: my $shown=0;
1601: if (($ishidden) || ($isencrypted) || ($randompick>=0) || ($is_random_order)) {
1.381 bisitz 1602: $r->print('<div class="LC_Box">'.
1603: '<p>'.&mt('Parameters:').
1604: '<ul>'.
1605: ($randompick>=0?'<li>'.&mt('randomly pick [quant,_1,resource]',$randompick).'</li>':'').
1.329 droeschl 1606: ($ishidden?'<li>'.&mt('contents hidden').'</li>':'').
1607: ($isencrypted?'<li>'.&mt('URLs hidden').'</li>':'').
1.381 bisitz 1608: ($is_random_order?'<li>'.&mt('random order').'</li>':'').
1.329 droeschl 1609: '</ul></p>');
1.381 bisitz 1610: if ($randompick>=0) {
1611: $r->print('<p class="LC_warning">'
1612: .&mt('Caution: this folder is set to randomly pick a subset'
1613: .' of resources. Adding or removing resources from this'
1614: .' folder will change the set of resources that the'
1615: .' students see, resulting in spurious or missing credit'
1616: .' for completed problems, not limited to ones you'
1617: .' modify. Do not modify the contents of this folder if'
1618: .' it is in active student use.')
1619: .'</p>'
1620: );
1621: }
1622: if ($is_random_order) {
1623: $r->print('<p class="LC_warning">'
1624: .&mt('Caution: this folder is set to randomly order its'
1625: .' contents. Adding or removing resources from this folder'
1626: .' will change the order of resources shown.')
1627: .'</p>'
1628: );
1629: }
1630: $r->print('</div>');
1.364 bisitz 1631: }
1.381 bisitz 1632:
1633: my $output;
1634: foreach my $res (@LONCAPA::map::order) {
1635: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
1636: $name=&LONCAPA::map::qtescape($name);
1637: $url=&LONCAPA::map::qtescape($url);
1638: unless ($name) { $name=(split(/\//,$url))[-1]; }
1639: unless ($name) { $idx++; next; }
1640: $output .= &entryline($idx,$name,$url,$folder,$allowed,$res,
1.408 raeburn 1641: $coursenum,$crstype);
1.381 bisitz 1642: $idx++;
1643: $shown++;
1.329 droeschl 1644: }
1.381 bisitz 1645: if ($shown) {
1.393 raeburn 1646: $r->print(&Apache::loncommon::start_data_table());
1647: if ($allowed) {
1648: $r->print(&Apache::loncommon::start_data_table_header_row()
1649: .'<th colspan="2">'.&mt('Move').'</th>'
1650: .'<th>'.&mt('Actions').'</th>'
1651: .'<th colspan="2">'.&mt('Document').'</th>');
1652: if ($folder !~ /^supplemental/) {
1653: $->print('<th colspan="4">'.&mt('Settings').'</th>');
1654: }
1655: $r->print(&Apache::loncommon::end_data_table_header_row());
1656: }
1657: $r->print($output
1658: .&Apache::loncommon::end_data_table()
1659: );
1660: } else {
1.381 bisitz 1661: $r->print('<p class="LC_info">'
1662: .&mt('Currently no documents.')
1663: .'</p>'
1664: );
1.329 droeschl 1665: }
1666: if ($allowed) {
1667: &print_paste_buffer($r,$container);
1668: }
1669: return;
1670: }
1671:
1672: sub process_file_upload {
1673: my ($upload_output,$coursenum,$coursedom,$allfiles,$codebase,$uploadcmd) = @_;
1674: # upload a file, if present
1675: my $parseaction;
1676: if ($env{'form.parserflag'}) {
1677: $parseaction = 'parse';
1678: }
1679: my $phase_status;
1680: my $folder=$env{'form.folder'};
1681: if ($folder eq '') {
1682: $folder='default';
1683: }
1684: if ( ($folder=~/^$uploadcmd/) || ($uploadcmd eq 'default') ) {
1685: my $errtext='';
1686: my $fatal=0;
1687: my $container='sequence';
1688: if ($env{'form.pagepath'}) {
1689: $container='page';
1690: }
1691: ($errtext,$fatal)=
1692: &mapread($coursenum,$coursedom,$folder.'.'.$container);
1693: if ($#LONCAPA::map::order<1) {
1694: $LONCAPA::map::order[0]=1;
1695: $LONCAPA::map::resources[1]='';
1696: }
1697: if ($fatal) {
1698: return 'failed';
1699: }
1700: my $destination = 'docs/';
1701: if ($folder =~ /^supplemental/) {
1702: $destination = 'supplemental/';
1703: }
1704: if (($folder eq 'default') || ($folder eq 'supplemental')) {
1705: $destination .= 'default/';
1706: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
1707: $destination .= $2.'/';
1708: }
1709: # this is for a course, not a user, so set coursedoc flag
1710: # probably the only place in the system where this should be "1"
1711: my $newidx=&LONCAPA::map::getresidx();
1712: $destination .= $newidx;
1713: my $url=&Apache::lonnet::userfileupload('uploaddoc',1,$destination,
1714: $parseaction,$allfiles,
1715: $codebase);
1716: my $ext='false';
1717: if ($url=~m{^http://}) { $ext='true'; }
1718: $url = &LONCAPA::map::qtunescape($url);
1719: my $comment=$env{'form.comment'};
1720: $comment = &LONCAPA::map::qtunescape($comment);
1721: if ($folder=~/^supplemental/) {
1722: $comment=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
1723: $env{'user.domain'}.'___&&&___'.$comment;
1724: }
1725:
1726: $LONCAPA::map::resources[$newidx]=
1727: $comment.':'.$url.':'.$ext.':normal:res';
1728: $LONCAPA::map::order[$#LONCAPA::map::order+1]= $newidx;
1729: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1730: $folder.'.'.$container);
1731: if ($fatal) {
1732: $$upload_output .= '<p><span class="LC_error">'.$errtext.'</span></p>';
1733: return 'failed';
1734: } else {
1735: if ($parseaction eq 'parse') {
1.384 raeburn 1736: my $total_embedded = scalar(keys(%{$allfiles}));
1.329 droeschl 1737: if ($total_embedded > 0) {
1738: my $num = 0;
1739: my $state = '
1740: <input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />
1741: <input type="hidden" name="cmd" value="upload_embedded" />
1742: <input type="hidden" name="newidx" value="'.$newidx.'" />
1743: <input type="hidden" name="primaryurl" value="'.&escape($url).'" />
1744: <input type="hidden" name="phasetwo" value="'.$total_embedded.'" />';
1745: $phase_status = 'phasetwo';
1746:
1.344 bisitz 1747: $$upload_output .=
1.329 droeschl 1748: 'This file contains embedded multimedia objects, which need to be uploaded to LON-CAPA.<br />'.
1749: &Apache::loncommon::ask_for_embedded_content(
1750: '/adm/coursedocs',$state,$allfiles,$codebase);
1751: } else {
1752: $$upload_output .= 'No embedded items identified<br />';
1753: }
1754: }
1755: }
1756: }
1757: return $phase_status;
1758: }
1759:
1760: sub process_secondary_uploads {
1761: my ($upload_output,$coursedom,$coursenum,$formname,$num,$newidx) = @_;
1762: my $folder=$env{'form.folder'};
1763: my $destination = 'docs/';
1764: if ($folder =~ /^supplemental/) {
1765: $destination = 'supplemental/';
1766: }
1767: if (($folder eq 'default') || ($folder eq 'supplemental')) {
1768: $destination .= 'default/';
1769: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
1770: $destination .= $2.'/';
1771: }
1772: $destination .= $newidx;
1773: my ($url,$filename);
1774: $url=&Apache::lonnet::userfileupload($formname.$num,1,$destination);
1775: ($filename) = ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/\Q$destination\E/(.+)$});
1776: return $filename;
1777: }
1778:
1779: sub is_supplemental_title {
1780: my ($title) = @_;
1781: return scalar($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/);
1782: }
1783:
1784: sub parse_supplemental_title {
1785: my ($title) = @_;
1786:
1787: my ($foldertitle,$renametitle);
1788: if ($title =~ /&&&/) {
1789: $title = &HTML::Entites::decode($title);
1790: }
1791: if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
1792: $renametitle=$4;
1793: my ($time,$uname,$udom) = ($1,$2,$3);
1794: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
1795: my $name = &Apache::loncommon::plainname($uname,$udom);
1796: $name = &HTML::Entities::encode($name,'"<>&\'');
1.418 ! raeburn 1797: $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
1.329 droeschl 1798: $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.
1799: $name.': <br />'.$foldertitle;
1800: }
1801: if (wantarray) {
1802: return ($title,$foldertitle,$renametitle);
1.364 bisitz 1803: }
1.329 droeschl 1804: return $title;
1805: }
1806:
1807: # --------------------------------------------------------------- An entry line
1808:
1809: sub entryline {
1.408 raeburn 1810: my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$crstype)=@_;
1.329 droeschl 1811: my ($foldertitle,$pagetitle,$renametitle);
1812: if (&is_supplemental_title($title)) {
1813: ($title,$foldertitle,$renametitle) = &parse_supplemental_title($title);
1814: $pagetitle = $foldertitle;
1815: } else {
1816: $title=&HTML::Entities::encode($title,'"<>&\'');
1817: $renametitle=$title;
1818: $foldertitle=$title;
1819: $pagetitle=$title;
1820: }
1821:
1822: my $orderidx=$LONCAPA::map::order[$index];
1.364 bisitz 1823:
1.329 droeschl 1824:
1825: $renametitle=~s/\\/\\\\/g;
1826: $renametitle=~s/\"\;/\\\"/g;
1827: $renametitle=~s/ /%20/g;
1.379 bisitz 1828: my $line=&Apache::loncommon::start_data_table_row();
1.329 droeschl 1829: my ($form_start,$form_end);
1830: # Edit commands
1831: my ($container, $type, $esc_path, $path, $symb);
1832: if ($env{'form.folderpath'}) {
1833: $type = 'folder';
1834: $container = 'sequence';
1835: $esc_path=&escape($env{'form.folderpath'});
1836: $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1837: # $htmlfoldername=&HTML::Entities::encode($env{'form.foldername'},'<>&"');
1838: }
1839: if ($env{'form.pagepath'}) {
1840: $type = $container = 'page';
1841: $esc_path=&escape($path = $env{'form.pagepath'});
1842: $path = &HTML::Entities::encode($env{'form.pagepath'},'<>&"');
1843: $symb=&escape($env{'form.pagesymb'});
1844: }
1845: my $cpinfo='';
1846: if ($allowed) {
1847: my $incindex=$index+1;
1848: my $selectbox='';
1849: if (($folder!~/^supplemental/) &&
1.344 bisitz 1850: ($#LONCAPA::map::order>0) &&
1.329 droeschl 1851: ((split(/\:/,
1.344 bisitz 1852: $LONCAPA::map::resources[$LONCAPA::map::order[0]]))[1]
1853: ne '') &&
1.329 droeschl 1854: ((split(/\:/,
1.344 bisitz 1855: $LONCAPA::map::resources[$LONCAPA::map::order[1]]))[1]
1.329 droeschl 1856: ne '')) {
1857: $selectbox=
1858: '<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
1.373 bisitz 1859: '<select name="newpos" onchange="this.form.submit()">';
1.329 droeschl 1860: for (my $i=1;$i<=$#LONCAPA::map::order+1;$i++) {
1861: if ($i==$incindex) {
1.358 bisitz 1862: $selectbox.='<option value="" selected="selected">('.$i.')</option>';
1.329 droeschl 1863: } else {
1864: $selectbox.='<option value="'.$i.'">'.$i.'</option>';
1865: }
1866: }
1867: $selectbox.='</select>';
1868: }
1869: my %lt=&Apache::lonlocal::texthash(
1870: 'up' => 'Move Up',
1871: 'dw' => 'Move Down',
1872: 'rm' => 'Remove',
1873: 'ct' => 'Cut',
1874: 'rn' => 'Rename',
1875: 'cp' => 'Copy');
1876: my $nocopy=0;
1877: my $nocut=0;
1878: if ($url=~/\.(page|sequence)$/) {
1879: if ($url =~ m{/res/}) {
1880: # no copy for published maps
1881: $nocopy = 1;
1882: } else {
1883: foreach my $item (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$url),1)) {
1884: my ($title,$url,$ext,$type)=split(/\:/,$item);
1885: if (($url=~/\.(page|sequence)/) && ($type ne 'zombie')) {
1886: $nocopy=1;
1887: last;
1888: }
1889: }
1890: }
1891: }
1.344 bisitz 1892: if ($url=~/^\/res\/lib\/templates\//) {
1893: $nocopy=1;
1.329 droeschl 1894: $nocut=1;
1895: }
1896: my $copylink=' ';
1897: my $cutlink=' ';
1.364 bisitz 1898:
1.329 droeschl 1899: my $skip_confirm = 0;
1900: if ( $folder =~ /^supplemental/
1901: || ($url =~ m{( /smppg$
1902: |/syllabus$
1903: |/aboutme$
1904: |/navmaps$
1905: |/bulletinboard$
1906: |\.html$
1907: |^/adm/wrapper/ext)}x)) {
1908: $skip_confirm = 1;
1909: }
1910:
1911: if (!$nocopy) {
1912: $copylink=(<<ENDCOPY);
1913: <a href='javascript:markcopy("$esc_path","$index","$renametitle","$container","$symb","$folder");' class="LC_docs_copy">$lt{'cp'}</a>
1914: ENDCOPY
1915: }
1916: if (!$nocut) {
1917: $cutlink=(<<ENDCUT);
1918: <a href='javascript:cutres("$esc_path","$index","$renametitle","$container","$symb","$folder",$skip_confirm);' class="LC_docs_cut">$lt{'ct'}</a>
1919: ENDCUT
1920: }
1921: $form_start = (<<END);
1922: <form action="/adm/coursedocs" method="post">
1923: <input type="hidden" name="${type}path" value="$path" />
1924: <input type="hidden" name="${type}symb" value="$symb" />
1925: <input type="hidden" name="setparms" value="$orderidx" />
1926: <input type="hidden" name="changeparms" value="0" />
1927: END
1928: $form_end = '</form>';
1929: $line.=(<<END);
1930: <td>
1.379 bisitz 1931: <div class="LC_docs_entry_move">
1932: <a href='/adm/coursedocs?cmd=up_$index&${type}path=$esc_path&${type}symb=$symb$cpinfo'>
1933: <img src="${iconpath}move_up.gif" alt='$lt{'up'}' class="LC_icon" />
1934: </a>
1935: </div>
1936: <div class="LC_docs_entry_move">
1937: <a href='/adm/coursedocs?cmd=down_$index&${type}path=$esc_path&${type}symb=$symb$cpinfo'>
1938: <img src="${iconpath}move_down.gif" alt='$lt{'dw'}' class="LC_icon" />
1939: </a>
1940: </div>
1.329 droeschl 1941: </td>
1942: <td>
1943: $form_start
1944: $selectbox
1945: $form_end
1946: </td>
1947: <td class="LC_docs_entry_commands">
1948: <a href='javascript:removeres("$esc_path","$index","$renametitle","$container","$symb",$skip_confirm);' class="LC_docs_remove">$lt{'rm'}</a>
1949: $cutlink
1950: <a href='javascript:changename("$esc_path","$index","$renametitle","$container","$symb");' class="LC_docs_rename">$lt{'rn'}</a>
1951: $copylink
1952: </td>
1953: END
1954:
1955: }
1956: # Figure out what kind of a resource this is
1957: my ($extension)=($url=~/\.(\w+)$/);
1958: my $uploaded=($url=~/^\/*uploaded\//);
1959: my $icon=&Apache::loncommon::icon($url);
1960: my $isfolder=0;
1961: my $ispage=0;
1962: my $folderarg;
1963: my $pagearg;
1964: my $pagefile;
1965: if ($uploaded) {
1966: if ($extension eq 'sequence') {
1.380 bisitz 1967: $icon=$iconpath.'/navmap.folder.closed.gif';
1.329 droeschl 1968: $url=~/\Q$coursenum\E\/([\/\w]+)\.sequence$/;
1969: $url='/adm/coursedocs?';
1970: $folderarg=$1;
1971: $isfolder=1;
1972: } elsif ($extension eq 'page') {
1973: $icon=$iconpath.'/page.gif';
1974: $url=~/\Q$coursenum\E\/([\/\w]+)\.page$/;
1975: $pagearg=$1;
1976: $url='/adm/coursedocs?';
1977: $ispage=1;
1978: } else {
1979: &Apache::lonnet::allowuploaded('/adm/coursedoc',$url);
1980: }
1981: }
1.364 bisitz 1982:
1.329 droeschl 1983: my $orig_url = $url;
1.340 raeburn 1984: $orig_url=~s{http(:|:)//https(:|:)//}{https$2//};
1.329 droeschl 1985: my $external = ($url=~s{^http(|s)(:|:)//}{/adm/wrapper/ext/});
1986: if ((!$isfolder) && ($residx) && ($folder!~/supplemental/) && (!$ispage)) {
1987: my $symb=&Apache::lonnet::symbclean(
1988: &Apache::lonnet::declutter('uploaded/'.
1989: $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
1990: $env{'course.'.$env{'request.course.id'}.'.num'}.'/'.$folder.
1991: '.sequence').
1992: '___'.$residx.'___'.
1993: &Apache::lonnet::declutter($url));
1994: (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
1995: $url=&Apache::lonnet::clutter($url);
1996: if ($url=~/^\/*uploaded\//) {
1997: $url=~/\.(\w+)$/;
1998: my $embstyle=&Apache::loncommon::fileembstyle($1);
1999: if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
2000: $url='/adm/wrapper'.$url;
2001: } elsif ($embstyle eq 'ssi') {
2002: #do nothing with these
2003: } elsif ($url!~/\.(sequence|page)$/) {
2004: $url='/adm/coursedocs/showdoc'.$url;
2005: }
1.344 bisitz 2006: } elsif ($url=~m|^/ext/|) {
1.329 droeschl 2007: $url='/adm/wrapper'.$url;
2008: $external = 1;
2009: }
2010: if (&Apache::lonnet::symbverify($symb,$url)) {
2011: $url.=(($url=~/\?/)?'&':'?').'symb='.&escape($symb);
2012: } else {
2013: $url='';
2014: }
2015: if ($container eq 'page') {
2016: my $symb=$env{'form.pagesymb'};
1.364 bisitz 2017:
1.329 droeschl 2018: $url=&Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
2019: $url.=(($url=~/\?/)?'&':'?').'symb='.&escape($symb);
2020: }
2021: }
2022: my ($parameterset,$rand_order_text) = (' ', ' ');
2023: if ($isfolder || $extension eq 'sequence') {
2024: my $foldername=&escape($foldertitle);
2025: my $folderpath=$env{'form.folderpath'};
2026: if ($folderpath) { $folderpath.='&' };
1.344 bisitz 2027: # Append randompick number, hidden, and encrypted with ":" to foldername,
1.329 droeschl 2028: # so it gets transferred between levels
2029: $folderpath.=$folderarg.'&'.$foldername.':'.(&LONCAPA::map::getparameter($orderidx,
2030: 'parameter_randompick'))[0]
2031: .':'.((&LONCAPA::map::getparameter($orderidx,
2032: 'parameter_hiddenresource'))[0]=~/^yes$/i)
2033: .':'.((&LONCAPA::map::getparameter($orderidx,
2034: 'parameter_encrypturl'))[0]=~/^yes$/i)
2035: .':'.((&LONCAPA::map::getparameter($orderidx,
2036: 'parameter_randomorder'))[0]=~/^yes$/i);
2037: $url.='folderpath='.&escape($folderpath).$cpinfo;
2038: $parameterset='<label>'.&mt('Randomly Pick: ').
1.373 bisitz 2039: '<input type="text" size="4" onchange="this.form.changeparms.value='."'randompick'".';this.form.submit()" name="randompick_'.$orderidx.'" value="'.
1.329 droeschl 2040: (&LONCAPA::map::getparameter($orderidx,
2041: 'parameter_randompick'))[0].
2042: '" />'.
2043: '<a href="javascript:void(0)">'.&mt('Save').'</a></label>';
2044: my $ro_set=
2045: ((&LONCAPA::map::getparameter($orderidx,'parameter_randomorder'))[0]=~/^yes$/i?' checked="checked"':'');
2046: $rand_order_text ='
1.369 bisitz 2047: <span class="LC_nobreak"><label><input type="checkbox" name="randomorder_'.$orderidx.'" onclick="this.form.changeparms.value=\'randomorder\';this.form.submit()" '.$ro_set.' /> '.&mt('Random Order').' </label></span>';
1.329 droeschl 2048: }
2049: if ($ispage) {
2050: my $pagename=&escape($pagetitle);
2051: my $pagepath;
2052: my $folderpath=$env{'form.folderpath'};
2053: if ($folderpath) { $pagepath = $folderpath.'&' };
2054: $pagepath.=$pagearg.'&'.$pagename;
2055: my $symb=$env{'form.pagesymb'};
2056: if (!$symb) {
2057: my $path='uploaded/'.
2058: $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
2059: $env{'course.'.$env{'request.course.id'}.'.num'}.'/';
2060: $symb=&Apache::lonnet::encode_symb($path.$folder.'.sequence',
2061: $residx,
2062: $path.$pagearg.'.page');
2063: }
2064: $url.='pagepath='.&escape($pagepath).
2065: '&pagesymb='.&escape($symb).$cpinfo;
2066: }
1.396 raeburn 2067: if (($external) && ($allowed)) {
1.329 droeschl 2068: my $form = ($folder =~ /^default/)? 'newext' : 'supnewext';
2069: $external = ' <a class="LC_docs_ext_edit" href="javascript:edittext(\''.$form.'\',\''.$residx.'\',\''.&escape($title).'\',\''.&escape($orig_url).'\');" >'.&mt('Edit').'</a>';
2070: } else {
2071: undef($external);
2072: }
1.408 raeburn 2073: my $reinit;
2074: if ($crstype eq 'Community') {
2075: $reinit = &mt('(re-initialize community to access)');
2076: } else {
2077: $reinit = &mt('(re-initialize course to access)');
2078: }
1.329 droeschl 2079: $line.='
1.379 bisitz 2080: <td>
1.329 droeschl 2081: '.($url?'<a href="'.$url.'">':'').'<img src="'.$icon.'" alt="" class="LC_icon" />'.($url?'</a>':'').'
2082: </td>
1.379 bisitz 2083: <td>
1.408 raeburn 2084: '.($url?"<a href=\"$url\">":'').$title.($url?'</a>':' <span class="LC_docs_reinit_warn">'.$reinit.'</span>').$external."
1.329 droeschl 2085: </td>";
2086: if (($allowed) && ($folder!~/^supplemental/)) {
2087: my %lt=&Apache::lonlocal::texthash(
2088: 'hd' => 'Hidden',
2089: 'ec' => 'URL hidden');
2090: my $enctext=
1.358 bisitz 2091: ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i?' checked="checked"':'');
1.329 droeschl 2092: my $hidtext=
1.358 bisitz 2093: ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i?' checked="checked"':'');
1.329 droeschl 2094: $line.=(<<ENDPARMS);
2095: <td class="LC_docs_entry_parameter">
2096: $form_start
1.369 bisitz 2097: <label><input type="checkbox" name="hiddenresource_$orderidx" onclick="this.form.changeparms.value='hiddenresource';this.form.submit()" $hidtext /> $lt{'hd'}</label>
1.329 droeschl 2098: $form_end
2099: </td>
2100: <td class="LC_docs_entry_parameter">
2101: $form_start
1.369 bisitz 2102: <label><input type="checkbox" name="encrypturl_$orderidx" onclick="this.form.changeparms.value='encrypturl';this.form.submit()" $enctext /> $lt{'ec'}</label>
1.329 droeschl 2103: $form_end
2104: </td>
2105: <td class="LC_docs_entry_parameter">$form_start $rand_order_text $form_end</td>
2106: <td class="LC_docs_entry_parameter">$form_start $parameterset $form_end</td>
2107: ENDPARMS
2108: }
1.379 bisitz 2109: $line.=&Apache::loncommon::end_data_table_row();
1.329 droeschl 2110: return $line;
2111: }
2112:
2113: =pod
2114:
2115: =item tiehash()
2116:
2117: tie the hash
2118:
2119: =cut
2120:
2121: sub tiehash {
2122: my ($mode)=@_;
2123: $hashtied=0;
2124: if ($env{'request.course.fn'}) {
2125: if ($mode eq 'write') {
2126: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
2127: &GDBM_WRCREAT(),0640)) {
2128: $hashtied=2;
2129: }
2130: } else {
2131: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
2132: &GDBM_READER(),0640)) {
2133: $hashtied=1;
2134: }
2135: }
1.364 bisitz 2136: }
1.329 droeschl 2137: }
2138:
2139: sub untiehash {
2140: if ($hashtied) { untie %hash; }
2141: $hashtied=0;
2142: return OK;
2143: }
2144:
2145:
2146:
2147:
2148: sub checkonthis {
2149: my ($r,$url,$level,$title)=@_;
2150: $url=&unescape($url);
2151: $alreadyseen{$url}=1;
2152: $r->rflush();
2153: if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
2154: $r->print("\n<br />");
2155: if ($level==0) {
2156: $r->print("<br />");
2157: }
2158: for (my $i=0;$i<=$level*5;$i++) {
2159: $r->print(' ');
2160: }
2161: $r->print('<a href="'.$url.'" target="cat">'.
2162: ($title?$title:$url).'</a> ');
2163: if ($url=~/^\/res\//) {
2164: my $result=&Apache::lonnet::repcopy(
2165: &Apache::lonnet::filelocation('',$url));
2166: if ($result eq 'ok') {
2167: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
2168: $r->rflush();
2169: &Apache::lonnet::countacc($url);
2170: $url=~/\.(\w+)$/;
2171: if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
2172: $r->print('<br />');
2173: $r->rflush();
2174: for (my $i=0;$i<=$level*5;$i++) {
2175: $r->print(' ');
2176: }
2177: $r->print('- '.&mt('Rendering:').' ');
2178: my ($errorcount,$warningcount)=split(/:/,
2179: &Apache::lonnet::ssi_body($url,
2180: ('grade_target'=>'web',
2181: 'return_only_error_and_warning_counts' => 1)));
2182: if (($errorcount) ||
2183: ($warningcount)) {
2184: if ($errorcount) {
1.369 bisitz 2185: $r->print('<img src="/adm/lonMisc/bomb.gif" alt="'.&mt('bomb').'" /><span class="LC_error">'.
1.329 droeschl 2186: &mt('[quant,_1,error]',$errorcount).'</span>');
2187: }
2188: if ($warningcount) {
2189: $r->print('<span class="LC_warning">'.
2190: &mt('[quant,_1,warning]',$warningcount).'</span>');
2191: }
2192: } else {
2193: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
2194: }
2195: $r->rflush();
2196: }
2197: my $dependencies=
2198: &Apache::lonnet::metadata($url,'dependencies');
2199: foreach my $dep (split(/\,/,$dependencies)) {
2200: if (($dep=~/^\/res\//) && (!$alreadyseen{$dep})) {
2201: &checkonthis($r,$dep,$level+1);
2202: }
2203: }
2204: } elsif ($result eq 'unavailable') {
2205: $r->print('<span class="LC_error">'.&mt('connection down').'</span>');
2206: } elsif ($result eq 'not_found') {
2207: unless ($url=~/\$/) {
2208: $r->print('<span class="LC_error">'.&mt('not found').'</b></span>');
2209: } else {
1.366 bisitz 2210: $r->print('<span class="LC_error">'.&mt('unable to verify variable URL').'</span>');
1.329 droeschl 2211: }
2212: } else {
2213: $r->print('<span class="LC_error">'.&mt('access denied').'</span>');
2214: }
2215: }
2216: }
2217: }
2218:
2219:
2220:
2221: =pod
2222:
2223: =item list_symbs()
2224:
2225: List Symbs
2226:
2227: =cut
2228:
2229: sub list_symbs {
2230: my ($r) = @_;
2231:
1.408 raeburn 2232: my $crstype = &Apache::loncommon::course_type();
1.329 droeschl 2233: $r->print(&Apache::loncommon::start_page('Symb List'));
2234: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Symb List'));
2235: my $navmap = Apache::lonnavmaps::navmap->new();
2236: if (!defined($navmap)) {
2237: $r->print('<h2>'.&mt('Retrieval of List Failed').'</h2>'.
2238: '<div class="LC_error">'.
2239: &mt('Unable to retrieve information about course contents').
2240: '</div>');
1.408 raeburn 2241: &Apache::lonnet::logthis('Symb list failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
1.329 droeschl 2242: } else {
2243: $r->print("<pre>\n");
2244: foreach my $res ($navmap->retrieveResources()) {
2245: $r->print($res->compTitle()."\t".$res->symb()."\n");
2246: }
2247: $r->print("\n</pre>\n");
2248: }
2249: $r->print('<a href="/adm/coursedocs">'.&mt('Return to DOCS').'</a>');
2250: }
2251:
2252:
2253: sub verifycontent {
2254: my ($r) = @_;
1.408 raeburn 2255: my $crstype = &Apache::loncommon::course_type();
1.329 droeschl 2256: my $loaderror=&Apache::lonnet::overloaderror($r);
2257: if ($loaderror) { return $loaderror; }
1.408 raeburn 2258: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Documents'));
2259: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Documents'));
1.329 droeschl 2260: $hashtied=0;
2261: undef %alreadyseen;
2262: %alreadyseen=();
2263: &tiehash();
2264: foreach my $key (keys(%hash)) {
2265: if ($hash{$key}=~/\.(page|sequence)$/) {
2266: if (($key=~/^src_/) && ($alreadyseen{&unescape($hash{$key})})) {
2267: $r->print('<hr /><span class="LC_error">'.
1.408 raeburn 2268: &mt('The following sequence or page is included more than once in your '.$crstype.': ').
1.329 droeschl 2269: &unescape($hash{$key}).'</span><br />'.
2270: &mt('Note that grading records for problems included in this sequence or folder will overlap.<hr />'));
2271: }
2272: }
2273: if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) {
2274: &checkonthis($r,$hash{$key},0,$hash{'title_'.$1});
2275: }
2276: }
2277: &untiehash();
2278: $r->print('<h1>'.&mt('Done').'.</h1>'.'<a href="/adm/coursedocs">'.
2279: &mt('Return to DOCS').'</a>');
2280: }
2281:
2282:
2283: sub devalidateversioncache {
2284: my $src=shift;
2285: &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
2286: &Apache::lonnet::clutter($src));
2287: }
2288:
2289: sub checkversions {
2290: my ($r) = @_;
1.408 raeburn 2291: my $crstype = &Apache::loncommon::course_type();
2292: $r->print(&Apache::loncommon::start_page("Check $crstype Document Versions"));
2293: $r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $crstype Document Versions"));
1.329 droeschl 2294: my $header='';
2295: my $startsel='';
2296: my $monthsel='';
2297: my $weeksel='';
2298: my $daysel='';
2299: my $allsel='';
2300: my %changes=();
2301: my $starttime=0;
2302: my $haschanged=0;
2303: my %setversions=&Apache::lonnet::dump('resourceversions',
2304: $env{'course.'.$env{'request.course.id'}.'.domain'},
2305: $env{'course.'.$env{'request.course.id'}.'.num'});
2306:
2307: $hashtied=0;
2308: &tiehash();
2309: my %newsetversions=();
2310: if ($env{'form.setmostrecent'}) {
2311: $haschanged=1;
2312: foreach my $key (keys(%hash)) {
2313: if ($key=~/^ids\_(\/res\/.+)$/) {
2314: $newsetversions{$1}='mostrecent';
2315: &devalidateversioncache($1);
2316: }
2317: }
2318: } elsif ($env{'form.setcurrent'}) {
2319: $haschanged=1;
2320: foreach my $key (keys(%hash)) {
2321: if ($key=~/^ids\_(\/res\/.+)$/) {
2322: my $getvers=&Apache::lonnet::getversion($1);
2323: if ($getvers>0) {
2324: $newsetversions{$1}=$getvers;
2325: &devalidateversioncache($1);
2326: }
2327: }
2328: }
2329: } elsif ($env{'form.setversions'}) {
2330: $haschanged=1;
2331: foreach my $key (keys(%env)) {
2332: if ($key=~/^form\.set_version_(.+)$/) {
2333: my $src=$1;
2334: if (($env{$key}) && ($env{$key} ne $setversions{$src})) {
2335: $newsetversions{$src}=$env{$key};
2336: &devalidateversioncache($src);
2337: }
2338: }
2339: }
2340: }
2341: if ($haschanged) {
2342: if (&Apache::lonnet::put('resourceversions',\%newsetversions,
2343: $env{'course.'.$env{'request.course.id'}.'.domain'},
1.344 bisitz 2344: $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
1.329 droeschl 2345: $r->print('<h1>'.&mt('Your Version Settings have been Saved').'</h1>');
2346: } else {
2347: $r->print('<h1><span class="LC_error">'.&mt('An Error Occured while Attempting to Save your Version Settings').'</span></h1>');
2348: }
2349: &mark_hash_old();
2350: }
2351: &changewarning($r,'');
2352: if ($env{'form.timerange'} eq 'all') {
2353: # show all documents
1.408 raeburn 2354: $header=&mt('All Documents in '.$crstype);
1.329 droeschl 2355: $allsel=1;
2356: foreach my $key (keys(%hash)) {
2357: if ($key=~/^ids\_(\/res\/.+)$/) {
2358: my $src=$1;
2359: $changes{$src}=1;
2360: }
2361: }
2362: } else {
2363: # show documents which changed
2364: %changes=&Apache::lonnet::dump
2365: ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
2366: $env{'course.'.$env{'request.course.id'}.'.num'});
2367: my $firstkey=(keys(%changes))[0];
2368: unless ($firstkey=~/^error\:/) {
2369: unless ($env{'form.timerange'}) {
2370: $env{'form.timerange'}=604800;
2371: }
2372: my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
2373: .&mt('seconds');
2374: if ($env{'form.timerange'}==-1) {
2375: $seltext='since start of course';
2376: $startsel='selected';
2377: $env{'form.timerange'}=time;
2378: }
2379: $starttime=time-$env{'form.timerange'};
2380: if ($env{'form.timerange'}==2592000) {
2381: $seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
2382: $monthsel='selected';
2383: } elsif ($env{'form.timerange'}==604800) {
2384: $seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
2385: $weeksel='selected';
2386: } elsif ($env{'form.timerange'}==86400) {
2387: $seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
2388: $daysel='selected';
2389: }
2390: $header=&mt('Content changed').' '.$seltext;
2391: } else {
2392: $header=&mt('No content modifications yet.');
2393: }
2394: }
2395: %setversions=&Apache::lonnet::dump('resourceversions',
2396: $env{'course.'.$env{'request.course.id'}.'.domain'},
2397: $env{'course.'.$env{'request.course.id'}.'.num'});
2398: my %lt=&Apache::lonlocal::texthash
1.408 raeburn 2399: ('st' => 'Version changes since start of '.$crstype,
1.329 droeschl 2400: 'lm' => 'Version changes since last Month',
2401: 'lw' => 'Version changes since last Week',
2402: 'sy' => 'Version changes since Yesterday',
2403: 'al' => 'All Resources (possibly large output)',
2404: 'sd' => 'Display',
2405: 'fi' => 'File',
2406: 'md' => 'Modification Date',
2407: 'mr' => 'Most recently published Version',
1.408 raeburn 2408: 've' => 'Version used in '.$crstype,
2409: 'vu' => 'Set Version to be used in '.$crstype,
2410: 'sv' => 'Set Versions to be used in '.$crstype.' according to Selections below',
1.329 droeschl 2411: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
2412: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
2413: 'di' => 'Differences');
2414: $r->print(<<ENDHEADERS);
2415: <form action="/adm/coursedocs" method="post">
2416: <input type="hidden" name="versions" value="1" />
2417: <input type="submit" name="setmostrecent" value="$lt{'sm'}" />
2418: <input type="submit" name="setcurrent" value="$lt{'sc'}" /><hr />
2419: <select name="timerange">
2420: <option value='all' $allsel>$lt{'al'}</option>
2421: <option value="-1" $startsel>$lt{'st'}</option>
2422: <option value="2592000" $monthsel>$lt{'lm'}</option>
2423: <option value="604800" $weeksel>$lt{'lw'}</option>
2424: <option value="86400" $daysel>$lt{'sy'}</option>
2425: </select>
2426: <input type="submit" name="display" value="$lt{'sd'}" />
2427: <h3>$header</h3>
2428: <input type="submit" name="setversions" value="$lt{'sv'}" />
2429: <table border="0">
2430: ENDHEADERS
2431: foreach my $key (sort(keys(%changes))) {
2432: if ($changes{$key}>$starttime) {
2433: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
2434: my $currentversion=&Apache::lonnet::getversion($key);
2435: if ($currentversion<0) {
2436: $currentversion=&mt('Could not be determined.');
2437: }
2438: my $linkurl=&Apache::lonnet::clutter($key);
2439: $r->print(
2440: '<tr><td colspan="5"><br /><br /><font size="+1"><b>'.
2441: &Apache::lonnet::gettitle($linkurl).
2442: '</b></font></td></tr>'.
2443: '<tr><td> </td>'.
2444: '<td colspan="4">'.
2445: '<a href="'.$linkurl.'" target="cat">'.$linkurl.
2446: '</a></td></tr>'.
2447: '<tr><td></td>'.
2448: '<td title="'.$lt{'md'}.'">'.
2449: &Apache::lonlocal::locallocaltime(
2450: &Apache::lonnet::metadata($root.'.'.$extension,
2451: 'lastrevisiondate')
2452: ).
2453: '</td>'.
2454: '<td title="'.$lt{'mr'}.'"><span class="LC_nobreak">Most Recent: '.
2455: '<font size="+1">'.$currentversion.'</font>'.
2456: '</span></td>'.
1.408 raeburn 2457: '<td title="'.$lt{'ve'}.'"><span class="LC_nobreak">In '.$crstype.': '.
1.329 droeschl 2458: '<font size="+1">');
2459: # Used in course
2460: my $usedversion=$hash{'version_'.$linkurl};
2461: if (($usedversion) && ($usedversion ne 'mostrecent')) {
2462: $r->print($usedversion);
2463: } else {
2464: $r->print($currentversion);
2465: }
2466: $r->print('</font></span></td><td title="'.$lt{'vu'}.'">'.
2467: '<span class="LC_nobreak">Use: ');
2468: # Set version
2469: $r->print(&Apache::loncommon::select_form($setversions{$linkurl},
2470: 'set_version_'.$linkurl,
2471: ('select_form_order' =>
2472: ['',1..$currentversion,'mostrecent'],
2473: '' => '',
1.411 bisitz 2474: 'mostrecent' => &mt('most recent'),
1.329 droeschl 2475: map {$_,$_} (1..$currentversion))));
2476: $r->print('</span></td></tr><tr><td></td>');
2477: my $lastold=1;
2478: for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
2479: my $url=$root.'.'.$prevvers.'.'.$extension;
2480: if (&Apache::lonnet::metadata($url,'lastrevisiondate')<
2481: $starttime) {
2482: $lastold=$prevvers;
2483: }
2484: }
1.364 bisitz 2485: #
1.329 droeschl 2486: # Code to figure out how many version entries should go in
2487: # each of the four columns
2488: my $entries_per_col = 0;
2489: my $num_entries = ($currentversion-$lastold);
2490: if ($num_entries % 4 == 0) {
2491: $entries_per_col = $num_entries/4;
2492: } else {
2493: $entries_per_col = $num_entries/4 + 1;
2494: }
2495: my $entries_count = 0;
1.344 bisitz 2496: $r->print('<td valign="top"><font size="-2">');
1.329 droeschl 2497: my $cols_output = 1;
2498: for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
2499: my $url=$root.'.'.$prevvers.'.'.$extension;
2500: $r->print('<span class="LC_nobreak"><a href="'.&Apache::lonnet::clutter($url).
2501: '">'.&mt('Version').' '.$prevvers.'</a> ('.
2502: &Apache::lonlocal::locallocaltime(
2503: &Apache::lonnet::metadata($url,
2504: 'lastrevisiondate')
2505: ).
2506: ')');
2507: if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
2508: $r->print(' <a href="/adm/diff?filename='.
2509: &Apache::lonnet::clutter($root.'.'.$extension).
2510: '&versionone='.$prevvers.
2511: '">'.&mt('Diffs').'</a>');
2512: }
2513: $r->print('</span><br />');
2514: if (++$entries_count % $entries_per_col == 0) {
2515: $r->print('</font></td>');
2516: if ($cols_output != 4) {
2517: $r->print('<td valign="top"><font size="-2">');
2518: $cols_output++;
2519: }
2520: }
2521: }
2522: while($cols_output++ < 4) {
2523: $r->print('</font></td><td><font>')
2524: }
2525: $r->print('</font></td></tr>'."\n");
2526: }
2527: }
2528: $r->print('</table></form>');
2529: $r->print('<h1>'.&mt('Done').'.</h1>');
2530:
2531: &untiehash();
2532: }
2533:
2534: sub mark_hash_old {
2535: my $retie_hash=0;
2536: if ($hashtied) {
2537: $retie_hash=1;
2538: &untiehash();
2539: }
2540: &tiehash('write');
2541: $hash{'old'}=1;
2542: &untiehash();
2543: if ($retie_hash) { &tiehash(); }
2544: }
2545:
2546: sub is_hash_old {
2547: my $untie_hash=0;
2548: if (!$hashtied) {
2549: $untie_hash=1;
2550: &tiehash();
2551: }
2552: my $return=$hash{'old'};
2553: if ($untie_hash) { &untiehash(); }
2554: return $return;
2555: }
2556:
2557: sub changewarning {
2558: my ($r,$postexec,$message,$url)=@_;
2559: if (!&is_hash_old()) { return; }
2560: my $pathvar='folderpath';
2561: my $path=&escape($env{'form.folderpath'});
2562: if (!defined($url)) {
2563: if (defined($env{'form.pagepath'})) {
2564: $pathvar='pagepath';
2565: $path=&escape($env{'form.pagepath'});
2566: $path.='&pagesymb='.&escape($env{'form.pagesymb'});
2567: }
2568: $url='/adm/coursedocs?'.$pathvar.'='.$path;
2569: }
2570: my $course_type = &Apache::loncommon::course_type();
2571: if (!defined($message)) {
2572: $message='Changes will become active for your current session after [_1], or the next time you log in.';
2573: }
2574: $r->print("\n\n".
1.372 bisitz 2575: '<script type="text/javascript">'."\n".
2576: '// <![CDATA['."\n".
2577: 'function reinit(tf) { tf.submit();'.$postexec.' }'."\n".
2578: '// ]]>'."\n".
1.369 bisitz 2579: '</script>'."\n".
1.375 tempelho 2580: '<form name="reinitform" method="post" action="/adm/roles" target="loncapaclient">'.
1.329 droeschl 2581: '<input type="hidden" name="orgurl" value="'.$url.
1.372 bisitz 2582: '" /><input type="hidden" name="selectrole" value="1" /><p class="LC_warning">'.
1.329 droeschl 2583: &mt($message,' <input type="hidden" name="'.
2584: $env{'request.role'}.'" value="1" /><input type="button" value="'.
1.369 bisitz 2585: &mt('re-initializing '.$course_type).'" onclick="reinit(this.form)" />').
1.372 bisitz 2586: $help{'Caching'}.'</p></form>'."\n\n");
1.329 droeschl 2587: }
2588:
2589:
2590: sub init_breadcrumbs {
2591: my ($form,$text)=@_;
2592: &Apache::lonhtmlcommon::clear_breadcrumbs();
2593: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs",
1.405 bisitz 2594: text=>&Apache::loncommon::course_type().' Editor',
1.329 droeschl 2595: faq=>273,
2596: bug=>'Instructor Interface',
2597: help => 'Docs_Adding_Course_Doc'});
2598: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?".$form.'=1',
2599: text=>$text,
2600: faq=>273,
2601: bug=>'Instructor Interface'});
2602: }
2603:
2604:
2605:
2606:
2607: sub handler {
2608: my $r = shift;
2609: &Apache::loncommon::content_type($r,'text/html');
2610: $r->send_http_header;
2611: return OK if $r->header_only;
1.408 raeburn 2612: my $crstype = &Apache::loncommon::course_type();
1.329 droeschl 2613:
2614:
2615: # --------------------------------------------- Initialize help topics for this
2616: foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',
2617: 'Adding_External_Resource','Navigate_Content',
2618: 'Adding_Folders','Docs_Overview', 'Load_Map',
2619: 'Supplemental','Score_Upload_Form','Adding_Pages',
2620: 'Importing_LON-CAPA_Resource','Uploading_From_Harddrive',
2621: 'Check_Resource_Versions','Verify_Content') {
2622: $help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
2623: }
2624: # Composite help files
2625: $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
2626: 'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
2627: $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
2628: 'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
2629: $help{'Simple Problem'} = &Apache::loncommon::help_open_topic(
2630: 'Option_Response_Simple');
2631: $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
2632: 'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
1.347 weissno 2633: $help{'My Personal Information Page'} = &Apache::loncommon::help_open_topic(
1.329 droeschl 2634: 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
1.353 weissno 2635: $help{'Group Portfolio'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
1.329 droeschl 2636: $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
2637:
2638: # does this user have privileges to modify docs
2639: my $allowed=&Apache::lonnet::allowed('mdc',$env{'request.course.id'});
2640: if ($allowed && $env{'form.verify'}) {
2641: &init_breadcrumbs('verify','Verify Content');
2642: &verifycontent($r);
2643: } elsif ($allowed && $env{'form.listsymbs'}) {
2644: &init_breadcrumbs('listsymbs','List Symbs');
2645: &list_symbs($r);
2646: } elsif ($allowed && $env{'form.docslog'}) {
2647: &init_breadcrumbs('docslog','Show Log');
2648: &docs_change_log($r);
2649: } elsif ($allowed && $env{'form.versions'}) {
2650: &init_breadcrumbs('versions','Check/Set Resource Versions');
2651: &checkversions($r);
2652: } elsif ($allowed && $env{'form.dumpcourse'}) {
2653: &init_breadcrumbs('dumpcourse','Dump '.&Apache::loncommon::course_type().' DOCS to Construction Space');
2654: &dumpcourse($r);
2655: } elsif ($allowed && $env{'form.exportcourse'}) {
1.377 bisitz 2656: &init_breadcrumbs('exportcourse','IMS Export');
1.329 droeschl 2657: &exportcourse($r);
2658: } else {
2659: # is this a standard course?
2660:
2661: my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
2662: my $forcestandard = 0;
2663: my $forcesupplement;
2664: my $script='';
2665: my $showdoc=0;
2666: my $containertag;
2667: my $uploadtag;
2668:
2669:
2670: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
2671: ['folderpath','pagepath',
2672: 'pagesymb']);
2673: # No folderpath, no pagepath, see if we have something stored
2674: if ((!$env{'form.folderpath'}) && (!$env{'form.pagepath'})) {
2675: &Apache::loncommon::restore_course_settings('docs_folderpath',
2676: {'folderpath' => 'scalar'});
2677: }
1.409 raeburn 2678: if (!$allowed) {
2679: unless($env{'form.folderpath'} =~ /^supplemental/) {
2680: $env{'form.folderpath'} = '';
2681: }
2682: }
2683: if (!$env{'form.folderpath'} && $allowed) {
1.329 droeschl 2684: &Apache::loncommon::restore_course_settings('docs_folderpath',
2685: {'pagepath' => 'scalar'});
2686: }
2687: if ($env{'form.pagepath'}) {
2688: $env{'form.folderpath'}='';
2689: }
2690: if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
2691: $env{'form.folderpath'} = 'supplemental&'.
1.408 raeburn 2692: &escape(&mt('Supplemental '.$crstype.' Documents')).'&'.
1.329 droeschl 2693: $env{'form.folderpath'};
2694: }
2695: &Apache::loncommon::store_course_settings('docs_folderpath',
2696: {'pagepath' => 'scalar',
2697: 'folderpath' => 'scalar'});
2698: if ($env{'form.folderpath'}) {
2699: my (@folderpath)=split('&',$env{'form.folderpath'});
2700: $env{'form.foldername'}=&unescape(pop(@folderpath));
2701: $env{'form.folder'}=pop(@folderpath);
2702: }
2703: if ($env{'form.pagepath'}) {
2704: my (@pagepath)=split('&',$env{'form.pagepath'});
2705: $env{'form.pagename'}=&unescape(pop(@pagepath));
2706: $env{'form.folder'}=pop(@pagepath);
2707: $containertag = '<input type="hidden" name="pagepath" value="" />'.
2708: '<input type="hidden" name="pagesymb" value="" />';
2709: $uploadtag = '<input type="hidden" name="pagepath" value="'.&HTML::Entities::encode($env{'form.pagepath'},'<>&"').'" />'.
2710: '<input type="hidden" name="pagesymb" value="'.&HTML::Entities::encode($env{'form.pagesymb'},'<>&"').'" />';
2711: }
2712: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
2713: $showdoc='/'.$1;
2714: }
1.402 raeburn 2715: if ($showdoc) { # got called in sequence from course
2716: $allowed=0;
2717: } else {
1.344 bisitz 2718: if (($env{'form.folder'}=~/^(?:group|default)_/) ||
1.329 droeschl 2719: ($env{'form.folder'} =~ m:^\d+/(pages|sequences)/:)) {
2720: $forcestandard = 1;
1.364 bisitz 2721: }
1.329 droeschl 2722: $forcesupplement=($env{'form.folder'}=~/^supplemental_/);
2723:
1.344 bisitz 2724: if ($allowed) {
1.329 droeschl 2725: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
1.344 bisitz 2726: $script=&Apache::lonratedt::editscript('simple');
1.329 droeschl 2727: }
2728: }
2729:
1.383 tempelho 2730: # subroutine to list form elements
2731: sub create_list_elements {
2732: my @formarr = @_;
2733: my $list = '';
2734: for my $button (@formarr){
2735: for my $picture(keys %$button) {
2736: #my $link = Apache::lonhtmlcommon::htmltag('a' ,$button->{$picture}, {href => "test"});
2737: $list .= Apache::lonhtmlcommon::htmltag('li', $picture.' '.$button->{$picture}, {class => 'LC_menubuttons_inline_text'});
2738: }
2739: }
2740: return $list;
2741: }
2742:
2743: # subroutine to create ul from list elements
2744: sub create_form_ul {
2745: my $list = shift;
2746: my $ul = Apache::lonhtmlcommon::htmltag('ul',$list, {class => 'LC_ListStyleNormal'});
2747: return $ul;
2748: }
2749:
1.329 droeschl 2750: # get course data
2751: my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
2752: my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
2753:
1.344 bisitz 2754: # get personal data
1.329 droeschl 2755: my $uname=$env{'user.name'};
2756: my $udom=$env{'user.domain'};
2757: my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));
2758:
2759: # graphics settings
2760:
2761: $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL') . "/");
2762:
2763: if ($allowed) {
2764: $script .= &editing_js($udom,$uname);
2765: }
2766: # -------------------------------------------------------------------- Body tag
1.369 bisitz 2767: $script = '<script type="text/javascript">'."\n"
1.372 bisitz 2768: .'// <![CDATA['."\n"
2769: .$script."\n"
2770: .'// ]]>'."\n"
2771: .'</script>'."\n";
1.385 bisitz 2772:
2773: # Breadcrumbs
2774: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.392 raeburn 2775: if ($allowed) {
2776: &Apache::lonhtmlcommon::add_breadcrumb({
1.408 raeburn 2777: href=>"/adm/coursedocs",text=>"$crstype Editor"});
1.392 raeburn 2778:
1.408 raeburn 2779: $r->print(&Apache::loncommon::start_page("$crstype Editor", $script,
1.392 raeburn 2780: {'force_register' => $showdoc,})
2781: .&Apache::loncommon::help_open_menu('','',273,'RAT')
2782: .&Apache::lonhtmlcommon::breadcrumbs(
1.408 raeburn 2783: 'Editing the Table of Contents for your '.$crstype,
1.392 raeburn 2784: 'Docs_Adding_Course_Doc')
2785: );
1.402 raeburn 2786: } elsif ($showdoc) {
1.408 raeburn 2787: $r->print(&Apache::loncommon::start_page("$crstype documents",undef,
1.402 raeburn 2788: {'force_register' => $showdoc,}));
1.392 raeburn 2789: } else {
1.395 raeburn 2790: my $folder=$env{'form.folder'};
2791: if ($folder eq '' || $folder eq 'supplemental') {
2792: $env{'form.folderpath'} = 'supplemental&'.
1.408 raeburn 2793: &escape(&mt('Supplemental '.$crstype.' Documents'));
1.395 raeburn 2794: }
1.408 raeburn 2795: my ($breadcrumbtrail) = &breadcrumbs($allowed,$crstype);
1.392 raeburn 2796: $r->print(&Apache::loncommon::start_page("Supplemental documents").
1.395 raeburn 2797: $breadcrumbtrail);
1.392 raeburn 2798: }
1.364 bisitz 2799:
1.329 droeschl 2800: my %allfiles = ();
2801: my %codebase = ();
2802: my ($upload_result,$upload_output);
2803: if ($allowed) {
2804: if (($env{'form.uploaddoc.filename'}) &&
2805: ($env{'form.cmd'}=~/^upload_(\w+)/)) {
1.344 bisitz 2806: # Process file upload - phase one - upload and parse primary file.
1.329 droeschl 2807: undef($hadchanges);
2808: $upload_result = &process_file_upload(\$upload_output,$coursenum,
2809: $coursedom,\%allfiles,
2810: \%codebase,$1);
2811: if ($hadchanges) {
2812: &mark_hash_old();
2813: }
2814: if ($upload_result eq 'phasetwo') {
2815: $r->print($upload_output);
2816: }
2817: } elsif ($env{'form.phasetwo'}) {
2818: my %newname = ();
2819: my %origname = ();
2820: my %attribs = ();
2821: my $updateflag = 0;
2822: my $residx = $env{'form.newidx'};
2823: my $primary_url = &unescape($env{'form.primaryurl'});
2824: # Process file upload - phase two - gather secondary files.
2825: for (my $i=0; $i<$env{'form.phasetwo'}; $i++) {
2826: if ($env{'form.embedded_item_'.$i.'.filename'}) {
2827: my $javacodebase;
2828: $newname{$i} = &process_secondary_uploads(\$upload_output,$coursedom,$coursenum,'embedded_item_',$i,$residx);
2829: $origname{$i} = &unescape($env{'form.embedded_orig_'.$i});
2830: if (exists($env{'form.embedded_codebase_'.$i})) {
1.344 bisitz 2831: $javacodebase = &unescape($env{'form.embedded_codebase_'.$i});
2832: $origname{$i} =~ s#^\Q$javacodebase\E/##;
1.329 droeschl 2833: }
2834: my @attributes = ();
2835: if ($env{'form.embedded_attrib_'.$i} =~ /:/) {
2836: @attributes = split(/:/,$env{'form.embedded_attrib_'.$i});
2837: } else {
2838: @attributes = ($env{'form.embedded_attrib_'.$i});
2839: }
2840: foreach my $attr (@attributes) {
2841: push(@{$attribs{$i}},&unescape($attr));
2842: }
2843: if ($javacodebase) {
2844: $codebase{$i} = $javacodebase;
2845: $codebase{$i} =~ s#/$##;
2846: $updateflag = 1;
2847: }
2848: }
2849: unless ($newname{$i} eq $origname{$i}) {
2850: $updateflag = 1;
2851: }
2852: }
2853: # Process file upload - phase three - modify primary file
2854: if ($updateflag) {
2855: my ($content,$rtncode);
2856: my $updateflag = 0;
2857: my $getstatus = &Apache::lonnet::getuploaded('GET',$primary_url,$coursedom,$coursenum,\$content,\$rtncode);
2858: if ($getstatus eq 'ok') {
2859: foreach my $item (keys(%newname)) {
2860: if ($newname{$item} ne $origname{$item}) {
2861: my $attrib_regexp = '';
2862: if (@{$attribs{$item}} > 1) {
2863: $attrib_regexp = join('|',@{$attribs{$item}});
2864: } else {
2865: $attrib_regexp = $attribs{$item}[0];
2866: }
2867: if ($content =~ m#($attrib_regexp\s*=\s*['"]?)\Q$origname{$item}\E(['"]?)#) {
1.364 bisitz 2868: }
1.344 bisitz 2869: $content =~ s#($attrib_regexp\s*=\s*['"]?)\Q$origname{$item}\E(['"]?)#$1$newname{$item}$2#gi;
1.329 droeschl 2870: }
2871: if (exists($codebase{$item})) {
2872: $content =~ s/(codebase\s*=\s*["']?)\Q$codebase{$item}\E(["']?)/$1.$2/i; #' stupid emacs
2873: }
2874: }
2875: # Save edited file.
2876: my $saveresult;
2877: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
2878: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
2879: my $url = &Apache::lonnet::store_edited_file($primary_url,$content,$docudom,$docuname,\$saveresult);
2880: } else {
1.344 bisitz 2881: &Apache::lonnet::logthis('retrieval of uploaded file - '.$primary_url.' - for editing, failed: '.$getstatus);
1.329 droeschl 2882: }
2883: }
2884: }
2885: }
2886:
2887: unless ($showdoc || $upload_result eq 'phasetwo') {
2888: # -----------------------------------------------------------------------------
2889: my %lt=&Apache::lonlocal::texthash(
1.408 raeburn 2890: 'uplm' => 'Upload a new main '.lc($crstype).' document',
2891: 'upls' => 'Upload a new supplemental '.lc($crstype).' document',
1.329 droeschl 2892: 'impp' => 'Import a document',
2893: 'copm' => 'All documents out of a published map into this folder',
1.417 droeschl 2894: 'upld' => 'Import Document',
1.329 droeschl 2895: 'srch' => 'Search',
2896: 'impo' => 'Import',
2897: 'book' => 'Import Bookmarks',
2898: 'selm' => 'Select Map',
2899: 'load' => 'Load Map',
2900: 'reco' => 'Recover Deleted Resources',
2901: 'newf' => 'New Folder',
2902: 'newp' => 'New Composite Page',
2903: 'extr' => 'External Resource',
2904: 'syll' => 'Syllabus',
2905: 'navc' => 'Navigate Contents',
1.343 biermanm 2906: 'sipa' => 'Simple Course Page',
1.329 droeschl 2907: 'sipr' => 'Simple Problem',
2908: 'drbx' => 'Drop Box',
2909: 'scuf' => 'Score Upload Form',
1.336 schafran 2910: 'bull' => 'Discussion Board',
1.347 weissno 2911: 'mypi' => 'My Personal Information Page',
1.353 weissno 2912: 'grpo' => 'Group Portfolio',
1.329 droeschl 2913: 'rost' => 'Course Roster',
1.348 weissno 2914: 'abou' => 'Personal Information Page for a User',
1.377 bisitz 2915: 'imsf' => 'IMS Import',
2916: 'imsl' => 'Import IMS package',
1.329 droeschl 2917: 'file' => 'File',
2918: 'title' => 'Title',
2919: 'comment' => 'Comment',
1.403 raeburn 2920: 'parse' => 'Upload embedded images/multimedia files if HTML file',
1.368 truskell 2921: 'nd' => 'Upload Document',
1.329 droeschl 2922: 'pm' => 'Published Map',
2923: 'sd' => 'Special Document',
2924: 'mo' => 'More Options',
2925: );
2926: # -----------------------------------------------------------------------------
2927: my $fileupload=(<<FIUP);
2928: $lt{'file'}:<br />
2929: <input type="file" name="uploaddoc" size="40" />
2930: FIUP
2931:
2932: my $checkbox=(<<CHBO);
2933: <!-- <label>$lt{'parse'}?
2934: <input type="checkbox" name="parserflag" />
2935: </label> -->
2936: <label>
2937: <input type="checkbox" name="parserflag" checked="checked" /> $lt{'parse'}
2938: </label>
2939: CHBO
2940:
1.394 droeschl 2941: my $fileuploada = "<input type='submit' value='".$lt{'upld'}."' /> $help{'Uploading_From_Harddrive'}";
1.329 droeschl 2942: my $fileuploadform=(<<FUFORM);
2943: <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.371 tempelho 2944: <input type="hidden" name="active" value="aa" />
1.329 droeschl 2945: $fileupload
2946: <br />
2947: $lt{'title'}:<br />
2948: <input type="text" size="50" name="comment" />
2949: $uploadtag
2950: <input type="hidden" name="cmd" value="upload_default" />
2951: <br />
2952: <span class="LC_nobreak">
2953: $checkbox
2954: </span>
1.383 tempelho 2955: FUFORM
1.394 droeschl 2956: #$list .= Apache::lonhtmlcommon::htmltag('li', $picture.' '.$button->{$picture}, {class => 'LC_menubuttons_inline_text'});
2957: #$fileuploadform .= create_form_ul(create_list_elements(@fileuploada));
2958: $fileuploadform .= create_form_ul(Apache::lonhtmlcommon::htmltag('li',$fileuploada,{class => 'LC_menubuttons_inline_text'}));
1.383 tempelho 2959: $fileuploadform .= (<<FUFORM);
1.329 droeschl 2960: </form>
2961: FUFORM
2962:
2963: my $simpleeditdefaultform=(<<SEDFFORM);
2964: <form action="/adm/coursedocs" method="post" name="simpleeditdefault">
1.371 tempelho 2965: <input type="hidden" name="active" value="bb" />
1.383 tempelho 2966: SEDFFORM
2967: my @simpleeditdefaultforma = (
1.417 droeschl 2968: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/src.png" alt="'.$lt{srch}.'" onclick="javascript:groupsearch()" />' => "$uploadtag<a onclick='javascript:groupsearch()'>$lt{'srch'}</a>" },
2969: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/res.png" alt="'.$lt{impo}.'" onclick="javascript:groupimport();"/>' => "<a onclick='javascript:groupimport();'>$lt{'impo'}</a>$help{'Importing_LON-CAPA_Resource'}" },
2970: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/vbkm.png" alt="'.$lt{book}.'" onclick="javascript:groupopen(0,1,1);" />' => "<a onclick='javascript:groupopen(0,1,1);'>$lt{'book'}</a>" },
1.383 tempelho 2971: );
2972: $simpleeditdefaultform .= create_form_ul(create_list_elements(@simpleeditdefaultforma));
2973: $simpleeditdefaultform .=(<<SEDFFORM);
1.329 droeschl 2974: <hr />
2975: <p>
2976: $lt{'copm'}<br />
2977: <input type="text" size="40" name="importmap" /><br />
1.344 bisitz 2978: <span class="LC_nobreak"><input type="button"
1.369 bisitz 2979: onclick="javascript:openbrowser('simpleeditdefault','importmap','sequence,page','')"
1.329 droeschl 2980: value="$lt{'selm'}" /> <input type="submit" name="loadmap" value="$lt{'load'}" />
2981: $help{'Load_Map'}</span>
2982: </p>
2983: </form>
2984: SEDFFORM
2985:
2986: my $extresourcesform=(<<ERFORM);
2987: <form action="/adm/coursedocs" method="post" name="newext">
2988: $uploadtag
2989: <input type="hidden" name="importdetail" value="" />
1.383 tempelho 2990: <a onclick="javascript:makenewext('newext');">$lt{'extr'}</a>$help{'Adding_External_Resource'}
1.329 droeschl 2991: </form>
2992: ERFORM
2993:
2994: if ($allowed) {
2995: &update_paste_buffer($coursenum,$coursedom);
2996: my %lt=&Apache::lonlocal::texthash(
2997: 'vc' => 'Verify Content',
2998: 'cv' => 'Check/Set Resource Versions',
2999: 'ls' => 'List Symbs',
3000: 'sl' => 'Show Log'
3001: );
3002:
3003: my $folderpath=$env{'form.folderpath'};
3004: if (!$folderpath) {
3005: if ($env{'form.folder'} eq '' ||
3006: $env{'form.folder'} eq 'supplemental') {
3007: $folderpath='default&'.
1.408 raeburn 3008: &escape(&mt('Main '.$crstype.' Documents'));
1.329 droeschl 3009: }
3010: }
3011: unless ($env{'form.pagepath'}) {
3012: $containertag = '<input type="hidden" name="folderpath" value="" />';
3013: $uploadtag = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
3014: }
1.337 ehlerst 3015: $r->print(<<HIDDENFORM);
3016: <form name="renameform" method="post" action="/adm/coursedocs">
3017: <input type="hidden" name="title" />
3018: <input type="hidden" name="cmd" />
3019: <input type="hidden" name="markcopy" />
3020: <input type="hidden" name="copyfolder" />
3021: $containertag
3022: </form>
3023: <form name="simpleedit" method="post" action="/adm/coursedocs">
3024: <input type="hidden" name="importdetail" value="" />
3025: $uploadtag
3026: </form>
3027: HIDDENFORM
1.329 droeschl 3028: }
1.335 ehlerst 3029: # --------------------------------------------------------- Main tab structure
1.395 raeburn 3030:
1.335 ehlerst 3031: my $activeClass = 1;
1.355 ehlerst 3032: my $active = '';
1.407 raeburn 3033: my %tabtitles = (
3034: main => {
3035: Course => &mt('Main Course Documents'),
3036: Community => &mt('Main Community Documents'),
3037: },
3038: supplemental => {
3039: Course => &mt('Supplemental Course Documents'),
3040: Community => &mt('Supplemental Community Documents'),
3041: },
3042: );
1.395 raeburn 3043: if ($allowed) {
3044: $r->print('<ul class="LC_TabContentBigger" id="mainnav">');
3045: if (($standard) && ($allowed) && (!$forcesupplement) && (($env{'form.folderpath'}=~/^default/) || $env{'form.folderpath'}eq"" || ($env{'form.pagepath'}))) {
3046: if($activeClass == 1){
3047: $active = 'class="active"';
3048: $activeClass = 0;
3049: }
3050: }
1.408 raeburn 3051: $r->print('<li '.$active.' onclick="javascript:showPage(this,\'mainCourseDocuments\',\'mainnav\',\'maincoursedoc\');"><a href="#"><b>'.$tabtitles{'main'}{$crstype}.'</b></a></li>');
1.395 raeburn 3052: $active = '';
3053: if (!$forcestandard || ($env{'form.folderpath'}=~/^supplemental/)) {
3054: if($activeClass == 1){
3055: $active = 'class="active"';
3056: }
1.335 ehlerst 3057: }
1.408 raeburn 3058: $r->print('<li '.$active.' onclick="javascript:showPage(this,\'supplCourseDocuments\',\'mainnav\',\'maincoursedoc\');"><a href="#"><b>'.$tabtitles{'supplemental'}{$crstype}.'</b></a></li>');
1.395 raeburn 3059: $r->print('</ul>');
3060: } else {
3061: $r->print('<br />');
1.335 ehlerst 3062: }
1.395 raeburn 3063: $r->print('<div class="LC_Box" style="clear:both;margin:0;">'
1.376 bisitz 3064: .'<div id="maincoursedoc" style="margin:0 0;padding:0 0;">');
1.329 droeschl 3065: # --------------------------------------------------------- Standard documents
1.356 tempelho 3066: my $savefolderpath;
1.395 raeburn 3067: $active = 'style="display: none;"';
1.335 ehlerst 3068: if($activeClass == 0){
3069: $active = 'style="display: block;"';
3070: }
1.393 raeburn 3071: if ($allowed) {
1.359 tempelho 3072: $r->print('<div class="LC_ContentBox" id="mainCourseDocuments" '.$active.'>');
1.329 droeschl 3073: my $folder=$env{'form.folder'};
1.356 tempelho 3074: if ($folder eq '' || $folder=~/^supplemental/) {
1.329 droeschl 3075: $folder='default';
1.356 tempelho 3076: $savefolderpath = $env{'form.folderpath'};
1.408 raeburn 3077: $env{'form.folderpath'}='default&'.&escape($tabtitles{'main'}{$crstype});
1.329 droeschl 3078: $uploadtag = '<input type="hidden" name="folderpath" value="'.
3079: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
3080: }
3081: my $postexec='';
3082: if ($folder eq 'default') {
1.372 bisitz 3083: $r->print('<script type="text/javascript">'."\n"
3084: .'// <![CDATA['."\n"
3085: .'this.window.name="loncapaclient";'."\n"
3086: .'// ]]>'."\n"
3087: .'</script>'."\n"
1.369 bisitz 3088: );
1.329 droeschl 3089: } else {
3090: #$postexec='self.close();';
3091: }
3092: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_'.time.
3093: '.sequence';
3094: my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_'.time.
3095: '.page';
3096: my $container='sequence';
3097: if ($env{'form.pagepath'}) {
3098: $container='page';
3099: }
3100: my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
3101:
3102:
3103:
3104: my $recoverform=(<<RFORM);
3105: <form action="/adm/groupsort" method="post" name="recover">
1.383 tempelho 3106: <a onclick="javascript:groupopen('$readfile',1,0)">$lt{'reco'}</a>
1.329 droeschl 3107: </form>
3108: RFORM
3109:
3110: my $imspform=(<<IMSPFORM);
3111: <form action="/adm/imsimportdocs" method="post" name="ims">
3112: <input type="hidden" name="folder" value="$folder" />
1.383 tempelho 3113: <a onclick="javascript:makeims();">$lt{'imsf'}</a>
1.329 droeschl 3114: </form>
3115: IMSPFORM
3116:
3117: my $newnavform=(<<NNFORM);
3118: <form action="/adm/coursedocs" method="post" name="newnav">
1.371 tempelho 3119: <input type="hidden" name="active" value="cc" />
1.329 droeschl 3120: $uploadtag
3121: <input type="hidden" name="importdetail"
3122: value="$lt{'navc'}=/adm/navmaps" />
1.383 tempelho 3123: <a onclick="document.newnav.submit()">$lt{'navc'}</a>
1.329 droeschl 3124: $help{'Navigate_Content'}
3125: </form>
3126: NNFORM
3127: my $newsmppageform=(<<NSPFORM);
3128: <form action="/adm/coursedocs" method="post" name="newsmppg">
1.371 tempelho 3129: <input type="hidden" name="active" value="cc" />
1.329 droeschl 3130: $uploadtag
3131: <input type="hidden" name="importdetail" value="" />
1.383 tempelho 3132: <a onclick="javascript:makesmppage();"> $lt{'sipa'}</a>
3133: $help{'Simple Page'}
1.329 droeschl 3134: </form>
3135: NSPFORM
3136:
3137: my $newsmpproblemform=(<<NSPROBFORM);
3138: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
1.371 tempelho 3139: <input type="hidden" name="active" value="cc" />
1.329 droeschl 3140: $uploadtag
3141: <input type="hidden" name="importdetail" value="" />
1.383 tempelho 3142: <a onclick="javascript:makesmpproblem();">$lt{'sipr'}</a>
3143: $help{'Simple Problem'}
1.329 droeschl 3144: </form>
3145:
3146: NSPROBFORM
3147:
3148: my $newdropboxform=(<<NDBFORM);
3149: <form action="/adm/coursedocs" method="post" name="newdropbox">
1.371 tempelho 3150: <input type="hidden" name="active" value="cc" />
1.344 bisitz 3151: $uploadtag
1.329 droeschl 3152: <input type="hidden" name="importdetail" value="" />
1.383 tempelho 3153: <a onclick="javascript:makedropbox();">$lt{'drbx'}</a>
1.344 bisitz 3154: </form>
1.329 droeschl 3155: NDBFORM
3156:
3157: my $newexuploadform=(<<NEXUFORM);
3158: <form action="/adm/coursedocs" method="post" name="newexamupload">
1.371 tempelho 3159: <input type="hidden" name="active" value="cc" />
1.329 droeschl 3160: $uploadtag
3161: <input type="hidden" name="importdetail" value="" />
1.383 tempelho 3162: <a onclick="javascript:makeexamupload();">$lt{'scuf'}</a>
1.329 droeschl 3163: $help{'Score_Upload_Form'}
3164: </form>
3165: NEXUFORM
3166:
3167: my $newbulform=(<<NBFORM);
3168: <form action="/adm/coursedocs" method="post" name="newbul">
1.371 tempelho 3169: <input type="hidden" name="active" value="cc" />
1.329 droeschl 3170: $uploadtag
3171: <input type="hidden" name="importdetail" value="" />
1.383 tempelho 3172: <a onclick="javascript:makebulboard();" >$lt{'bull'}</a>
1.329 droeschl 3173: $help{'Bulletin Board'}
3174: </form>
3175: NBFORM
3176:
3177: my $newaboutmeform=(<<NAMFORM);
3178: <form action="/adm/coursedocs" method="post" name="newaboutme">
1.371 tempelho 3179: <input type="hidden" name="active" value="cc" />
1.329 droeschl 3180: $uploadtag
3181: <input type="hidden" name="importdetail"
3182: value="$plainname=/adm/$udom/$uname/aboutme" />
1.383 tempelho 3183: <a onclick="document.newaboutme.submit()">$lt{'mypi'}</a>
1.347 weissno 3184: $help{'My Personal Information Page'}
1.329 droeschl 3185: </form>
3186: NAMFORM
3187:
3188: my $newaboutsomeoneform=(<<NASOFORM);
3189: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
1.371 tempelho 3190: <input type="hidden" name="active" value="cc" />
1.329 droeschl 3191: $uploadtag
3192: <input type="hidden" name="importdetail" value="" />
1.383 tempelho 3193: <a onclick="javascript:makeabout();">$lt{'abou'}</a>
1.329 droeschl 3194: </form>
3195: NASOFORM
3196:
3197:
3198: my $newrosterform=(<<NROSTFORM);
3199: <form action="/adm/coursedocs" method="post" name="newroster">
1.371 tempelho 3200: <input type="hidden" name="active" value="cc" />
1.329 droeschl 3201: $uploadtag
3202: <input type="hidden" name="importdetail"
3203: value="$lt{'rost'}=/adm/viewclasslist" />
1.383 tempelho 3204: <a onclick="document.newroster.submit()">$lt{'rost'}</a>
1.329 droeschl 3205: $help{'Course Roster'}
3206: </form>
3207: NROSTFORM
3208:
1.342 ehlerst 3209: my $specialdocumentsform;
1.383 tempelho 3210: my @specialdocumentsforma;
1.351 ehlerst 3211: my $newfolderform;
1.390 tempelho 3212: my $newfolderb;
1.342 ehlerst 3213:
1.329 droeschl 3214: unless ($env{'form.pagepath'}) {
3215: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.383 tempelho 3216:
1.329 droeschl 3217: my $newpageform=(<<NPFORM);
3218: <form action="/adm/coursedocs" method="post" name="newpage">
3219: <input type="hidden" name="folderpath" value="$path" />
3220: <input type="hidden" name="importdetail" value="" />
1.371 tempelho 3221: <input type="hidden" name="active" value="cc" />
1.383 tempelho 3222: <a onclick="javascript:makenewpage(document.newpage,'$pageseq');">$lt{'newp'}</a>
3223: $help{'Adding_Pages'}
1.329 droeschl 3224: </form>
3225: NPFORM
1.390 tempelho 3226:
3227:
1.351 ehlerst 3228: $newfolderform=(<<NFFORM);
1.329 droeschl 3229: <form action="/adm/coursedocs" method="post" name="newfolder">
3230: <input type="hidden" name="folderpath" value="$path" />
3231: <input type="hidden" name="importdetail" value="" />
1.371 tempelho 3232: <input type="hidden" name="active" value="aa" />
1.383 tempelho 3233: <a onclick="javascript:makenewfolder(document.newfolder,'$folderseq');">$lt{'newf'}</a>$help{'Adding_Folders'}
1.329 droeschl 3234: </form>
3235: NFFORM
3236:
3237: my $newsylform=(<<NSYLFORM);
3238: <form action="/adm/coursedocs" method="post" name="newsyl">
1.371 tempelho 3239: <input type="hidden" name="active" value="cc" />
1.329 droeschl 3240: $uploadtag
3241: <input type="hidden" name="importdetail"
3242: value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />
1.383 tempelho 3243: <a onclick="document.newsyl.submit()">$lt{'syll'}</a>
1.329 droeschl 3244: $help{'Syllabus'}
1.383 tempelho 3245:
1.329 droeschl 3246: </form>
3247: NSYLFORM
1.364 bisitz 3248:
1.329 droeschl 3249: my $newgroupfileform=(<<NGFFORM);
3250: <form action="/adm/coursedocs" method="post" name="newgroupfiles">
1.371 tempelho 3251: <input type="hidden" name="active" value="cc" />
1.329 droeschl 3252: $uploadtag
3253: <input type="hidden" name="importdetail"
3254: value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
1.383 tempelho 3255: <a onclick="document.newgroupfiles.submit()">$lt{'grpo'}</a>
1.353 weissno 3256: $help{'Group Portfolio'}
1.329 droeschl 3257: </form>
3258: NGFFORM
1.383 tempelho 3259: @specialdocumentsforma=(
1.417 droeschl 3260: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/page.png" alt="'.$lt{newp}.'" onclick="javascript:makenewpage(document.newpage,"'.$pageseq.'");" />'=>$newpageform},
3261: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="document.newsyl.submit()" />'=>$newsylform},
3262: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/groupportfolio.png" alt="'.$lt{grpo}.'" onclick="document.newgroupfiles.submit()" />'=>$newgroupfileform},
1.383 tempelho 3263: );
3264:
3265: }
1.417 droeschl 3266: push @specialdocumentsforma, ({'<img class="LC_noBorder LC_middle" src="/res/adm/pages/navigation.png" alt="'.$lt{navc}.'" onclick="document.newnav.submit()" />'=>$newnavform},
3267: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simple.png" alt="'.$lt{sipa}.'" onclick="javascript:makesmppage();" />'=>$newsmppageform},
3268: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{sipr}.'" onclick="javascript:makesmpproblem();" />'=>$newsmpproblemform},
3269: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/dropbox.png" alt="'.$lt{drbx}.'" onclick="javascript:makedropbox();" />'=>$newdropboxform},
3270: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/scoreupfrm.png" alt="'.$lt{scuf}.'" onclick="javascript:makeexamupload();" />'=>$newexuploadform},
3271: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/bchat.png" alt="'.$lt{bull}.'" onclick="javascript:makebulboard();" />'=>$newbulform},
3272: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makebulboard();" />'=>$newaboutmeform},
3273: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/aboutme.png" alt="'.$lt{abou}.'" onclick="javascript:makeabout();" />'=>$newaboutsomeoneform},
3274: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/chrt.png" alt="'.$lt{rost}.'" onclick="document.newroster.submit()" />'=>$newrosterform},);
1.383 tempelho 3275:
3276: $specialdocumentsform = create_form_ul(create_list_elements(@specialdocumentsforma));
1.329 droeschl 3277:
1.342 ehlerst 3278: if($env{'form.pagepath'}) {
1.383 tempelho 3279:
3280: @specialdocumentsforma=(
1.417 droeschl 3281: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.&mt('Simple Problem').'" onclick="javascript:makesmpproblem();" />'=>$newsmpproblemform},
3282: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/scoreupfrm.png" alt="'.&mt('Score Upload Form').'" onclick="javascript:makeexamupload();" />'=>$newexuploadform}
1.383 tempelho 3283: );
3284: $specialdocumentsform= create_form_ul(create_list_elements(@specialdocumentsforma));
1.342 ehlerst 3285: }
1.331 muellerd 3286:
1.383 tempelho 3287: my @tools = (
1.417 droeschl 3288: # {'<img class="LC_noBorder LC_middle" align="left" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" />'=>$extresourcesform},
3289: # {'<img class="LC_noBorder LC_middle" align="left" src="/res/adm/pages/ims.png" alt="'.$lt{imsf}.'" />'=>$imspform},
3290: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/recover.png" alt="'.$lt{reco}.'" onclick="javascript:groupopen(\''.$readfile.'\',1,0)" />'=>$recoverform},
1.383 tempelho 3291: );
3292:
1.417 droeschl 3293: my @importdoc = (
3294: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="javascript:makenewext(\'newext\');" />'=>$extresourcesform},
3295: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/ims.png" alt="'.$lt{imsf}.'" onclick="javascript:makeims();" />'=>$imspform},
3296: );
3297: $fileuploadform = create_form_ul(create_list_elements(@importdoc)) . '<hr/>' . $fileuploadform;
1.330 tempelho 3298: my %orderhash = (
1.390 tempelho 3299: '00' => ['Newfolder',$newfolderform],
1.417 droeschl 3300: 'aa' => ['Import Documents',$fileuploadform],
1.377 bisitz 3301: 'bb' => ['Published Resources',$simpleeditdefaultform],
1.363 ehlerst 3302: 'cc' => ['Special Documents',$specialdocumentsform],
1.383 tempelho 3303: 'dd' => ['Tools', create_form_ul(create_list_elements(@tools)).&generate_admin_options($containertag,$uploadtag,\%help,\%env)],
1.330 tempelho 3304: );
1.334 muellerd 3305: my $tid='1';
1.341 ehlerst 3306: $hadchanges=0;
1.408 raeburn 3307: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype);
1.335 ehlerst 3308: if ($error) {
3309: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
3310: }
1.341 ehlerst 3311: if ($hadchanges) {
3312: &mark_hash_old();
3313: }
3314:
3315: &changewarning($r,'');
1.406 raeburn 3316: $r->print(&generate_edit_table($tid,\%orderhash));
1.389 tempelho 3317:
1.335 ehlerst 3318: $r->print('</div>');
1.383 tempelho 3319: }
1.329 droeschl 3320: if ($env{'form.pagepath'}) {
3321: }
3322: # ----------------------------------------------------- Supplemental documents
1.395 raeburn 3323: $active = 'style="display: none;"';
1.335 ehlerst 3324: if($activeClass == 1){
3325: $active = 'style="display: block;"';
3326: }
1.373 bisitz 3327: $r->print('<div class="LC_ContentBox" id="supplCourseDocuments" '.$active.'>');
1.329 droeschl 3328: my $folder=$env{'form.folder'};
3329: unless ($folder=~/^supplemental/) {
3330: $folder='supplemental';
3331: }
3332: if ($folder =~ /^supplemental$/ &&
3333: (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
3334: $env{'form.folderpath'} = 'supplemental&'.
1.408 raeburn 3335: &escape(&mt('Supplemental '.$crstype.' Documents'));
1.393 raeburn 3336: } elsif ($allowed) {
1.356 tempelho 3337: $env{'form.folderpath'} = $savefolderpath;
1.329 droeschl 3338: }
1.362 ehlerst 3339: $env{'form.pagepath'} = '';
1.329 droeschl 3340: if ($allowed) {
3341: my $folderseq=
3342: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_'.time.
3343: '.sequence';
3344:
3345: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3346:
1.400 droeschl 3347: my $supupdocformbtn = "<input type='submit' value='".$lt{'upld'}."' />$help{'Uploading_From_Harddrive'}";
1.329 droeschl 3348: my $supupdocform=(<<SUPDOCFORM);
1.383 tempelho 3349: <form action="/adm/coursedocs" method="post" name="supuploaddocument" enctype="multipart/form-data">
1.371 tempelho 3350: <input type="hidden" name="active" value="ee" />
1.329 droeschl 3351: $fileupload
3352: <br />
3353: <br />
3354: <span class="LC_nobreak">
3355: $checkbox
3356: </span>
3357: <br /><br />
3358: $lt{'comment'}:<br />
1.383 tempelho 3359: <textarea cols="50" rows="4" name="comment"></textarea>
1.329 droeschl 3360: <br />
3361: <input type="hidden" name="folderpath" value="$path" />
3362: <input type="hidden" name="cmd" value="upload_supplemental" />
3363: SUPDOCFORM
1.400 droeschl 3364: $supupdocform .= create_form_ul(Apache::lonhtmlcommon::htmltag('li',$supupdocformbtn,{class => 'LC_menubuttons_inline_text'}))."</form>";
1.329 droeschl 3365:
3366: my $supnewfolderform=(<<SNFFORM);
3367: <form action="/adm/coursedocs" method="post" name="supnewfolder">
1.371 tempelho 3368: <input type="hidden" name="active" value="ee" />
1.329 droeschl 3369: <input type="hidden" name="folderpath" value="$path" />
3370: <input type="hidden" name="importdetail" value="" />
1.383 tempelho 3371: <a onclick="javascript:makenewfolder(document.supnewfolder,'$folderseq');">$lt{'newf'}</a>
3372: $help{'Adding_Folders'}
1.329 droeschl 3373: </form>
3374: SNFFORM
1.383 tempelho 3375:
1.329 droeschl 3376:
3377: my $supnewextform=(<<SNEFORM);
3378: <form action="/adm/coursedocs" method="post" name="supnewext">
1.371 tempelho 3379: <input type="hidden" name="active" value="ff" />
1.329 droeschl 3380: <input type="hidden" name="folderpath" value="$path" />
3381: <input type="hidden" name="importdetail" value="" />
1.383 tempelho 3382: <a onclick="javascript:makenewext('supnewext');">$lt{'extr'}</a> $help{'Adding_External_Resource'}
1.329 droeschl 3383: </form>
3384: SNEFORM
3385:
3386: my $supnewsylform=(<<SNSFORM);
3387: <form action="/adm/coursedocs" method="post" name="supnewsyl">
1.371 tempelho 3388: <input type="hidden" name="active" value="ff" />
1.329 droeschl 3389: <input type="hidden" name="folderpath" value="$path" />
3390: <input type="hidden" name="importdetail"
3391: value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
1.383 tempelho 3392: <a onclick="document.supnewsyl.submit()">$lt{'syll'}</a>
1.329 droeschl 3393: $help{'Syllabus'}
3394: </form>
3395: SNSFORM
3396:
3397: my $supnewaboutmeform=(<<SNAMFORM);
1.383 tempelho 3398: <form action="/adm/coursedocs" method="post" name="supnewaboutme">
1.371 tempelho 3399: <input type="hidden" name="active" value="ff" />
1.329 droeschl 3400: <input type="hidden" name="folderpath" value="$path" />
3401: <input type="hidden" name="importdetail"
3402: value="$plainname=/adm/$udom/$uname/aboutme" />
1.383 tempelho 3403: <a onclick="document.supnewaboutme.submit()">$lt{'mypi'}</a>
1.347 weissno 3404: $help{'My Personal Information Page'}
1.329 droeschl 3405: </form>
3406: SNAMFORM
3407:
1.333 muellerd 3408:
1.383 tempelho 3409: my @specialdocs = (
1.417 droeschl 3410: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="document.supnewsyl.submit()" />'
3411: =>$supnewsylform},
3412: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="document.supnewaboutme.submit()" />'
3413: =>$supnewaboutmeform},
1.383 tempelho 3414: );
1.417 droeschl 3415: my @supimportdoc = (
3416: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="javascript:makenewext(\'supnewext\');" />'
3417: =>$supnewextform},
3418: );
3419: $supupdocform = create_form_ul(create_list_elements(@supimportdoc)) . '<hr/>' . $supupdocform;
1.333 muellerd 3420: my %suporderhash = (
1.390 tempelho 3421: '00' => ['Supnewfolder', $supnewfolderform],
1.417 droeschl 3422: 'ee' => ['Import Documents',$supupdocform],
1.390 tempelho 3423: 'ff' => ['Special Documents',create_form_ul(create_list_elements(@specialdocs))]
1.333 muellerd 3424: );
1.334 muellerd 3425:
1.408 raeburn 3426: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype);
1.393 raeburn 3427: if ($error) {
3428: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
3429: }
3430: my $tid='2';
1.406 raeburn 3431: $r->print(&generate_edit_table($tid,\%suporderhash));
1.393 raeburn 3432: } else {
1.408 raeburn 3433: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype);
1.393 raeburn 3434: if ($error) {
3435: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.383 tempelho 3436: }
1.393 raeburn 3437: }
1.389 tempelho 3438:
3439:
1.335 ehlerst 3440: $r->print('</div>');
1.383 tempelho 3441: $r->print('</div></div>');
3442:
3443:
1.329 droeschl 3444: if ($allowed) {
3445: $r->print('
3446: <form method="post" name="extimport" action="/adm/coursedocs">
3447: <input type="hidden" name="title" />
3448: <input type="hidden" name="url" />
3449: <input type="hidden" name="useform" />
3450: <input type="hidden" name="residx" />
3451: </form>');
3452: }
3453: } else {
3454: unless ($upload_result eq 'phasetwo') {
3455: # -------------------------------------------------------- This is showdoc mode
3456: $r->print("<h1>".&mt('Uploaded Document').' - '.
3457: &Apache::lonnet::gettitle($r->uri).'</h1><p>'.
3458: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><table>".
3459: &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');
3460: }
3461: }
3462: }
3463: $r->print(&Apache::loncommon::end_page());
3464: return OK;
1.364 bisitz 3465: }
1.329 droeschl 3466:
3467: sub generate_admin_options {
1.337 ehlerst 3468: my ($containertag,$uploadtag,$help_ref,$env_ref) = @_;
3469: my %lt=&Apache::lonlocal::texthash(
3470: 'vc' => 'Verify Content',
3471: 'cv' => 'Check/Set Resource Versions',
3472: 'ls' => 'List Symbs',
1.412 wenzelju 3473: 'sl' => 'Show Log',
3474: 'imse' => 'IMS Export',
3475: 'dcd' => 'Dump Course DOCS to Construction Space: available on other servers'
1.337 ehlerst 3476: );
1.329 droeschl 3477: my %help = %{$help_ref};
3478: my %env = %{$env_ref};
3479: my $dumpbut=&dumpbutton();
3480: my $exportbut=&exportbutton();
1.383 tempelho 3481: my @list = (
1.417 droeschl 3482: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/verify.png" alt="'.$lt{vc}.'" onclick=\'javascript:injectData(document.courseverify, "dummy", "verify", "'.$lt{'vc'}.'")\' />'
3483: => "<a onclick='javascript:injectData(document.courseverify, \"dummy\", \"verify\", \"$lt{'vc'}\")'>$lt{'vc'}</a>$help{'Verify_Content'}"},
3484: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/resversion.png" alt="'.$lt{cv}.'" onclick=\'javascript:injectData(document.courseverify, "dummy", "versions", "'.$lt{'cv'}.'")\' />'
3485: =>"<a onclick='javascript:injectData(document.courseverify, \"dummy\", \"versions\", \"$lt{'cv'}\")'>$lt{'cv'}</a>$help{'Check_Resource_Versions'}"},
1.383 tempelho 3486: );
3487: if($dumpbut ne ''){
1.417 droeschl 3488: push @list, {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/dump.png" alt="'.$lt{dcd}.'" />'=>$dumpbut};
1.383 tempelho 3489: }
1.417 droeschl 3490: push @list, ({'<img class="LC_noBorder LC_middle" src="/res/adm/pages/imsexport.png" alt="'.$lt{imse}.'" onclick=\'javascript:injectData(document.courseverify, "dummy", "exportcourse", "'.&mt('IMS Export').'")\' />'
3491: =>$exportbut},
3492: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/symbs.png" alt="'.$lt{ls}.'" onclick=\'javascript:injectData(document.courseverify, "dummy", "listsymbs", "'.$lt{'ls'}.'")\' />'
3493: =>"<a onclick='javascript:injectData(document.courseverify, \"dummy\", \"listsymbs\", \"$lt{'ls'}\")'>$lt{'ls'}</a><input type='hidden' name='folder' value='$env{'form.folder'}' />"},
3494: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/log.png" alt="'.$lt{sl}.'" onclick=\'javascript:injectData(document.courseverify, "dummy", "docslog", "'.$lt{'sl'}.'")\' />'
3495: =>"<a onclick='javascript:injectData(document.courseverify, \"dummy\", \"docslog\", \"$lt{'sl'}\")'>$lt{'sl'}</a>"},
1.383 tempelho 3496: );
3497: return '<form action="/adm/coursedocs" method="post" name="courseverify"><input type="hidden" id="dummy" />'.create_form_ul(create_list_elements(@list)).'</form>';
1.330 tempelho 3498:
1.329 droeschl 3499: }
3500:
1.330 tempelho 3501:
1.329 droeschl 3502: sub generate_edit_table {
1.406 raeburn 3503: my ($tid,$orderhash_ref) = @_;
3504: return unless(ref($orderhash_ref) eq 'HASH');
1.342 ehlerst 3505: my %orderhash = %{$orderhash_ref};
1.344 bisitz 3506: my $form;
1.371 tempelho 3507: my $activetab;
3508: my $active;
3509: if($env{'form.active'} ne ''){
3510: $activetab = $env{'form.active'};
3511: }
1.417 droeschl 3512: $form = '<div class="LC_Box" style="margin-right:0">';
1.359 tempelho 3513: $form .= '<ul id="navigation'.$tid.'" class="LC_TabContent">';
1.329 droeschl 3514: foreach my $name (sort(keys(%orderhash))){
1.390 tempelho 3515: if($name ne '00'){
1.371 tempelho 3516: if($activetab eq '' || $activetab ne $name){
3517: $active = '';
3518: }elsif($activetab eq $name){
3519: $active = 'class="active"';
3520: }
1.374 tempelho 3521: $form .= '<li '.$active.' onclick="javascript:showPage(this, \''.$name.$tid.'\', \'navigation'.$tid.'\',\'content'.$tid.'\');">'.&mt(${$orderhash{$name}}[0]).'</li>';
1.390 tempelho 3522: } else {
3523: $form .= '<li '.$active.'>'.${$orderhash{$name}}[1].'</li>';
3524:
3525: }
1.329 droeschl 3526: }
1.339 ehlerst 3527: $form .= '</ul>';
1.398 bisitz 3528: $form .= '<div id="content'.$tid.'" style="padding: 0 0; margin: 0 0; clear: both;">';
1.363 ehlerst 3529: foreach my $field (keys(%orderhash)){
1.390 tempelho 3530: if($field ne '00'){
1.371 tempelho 3531: if($activetab eq '' || $activetab ne $field){
3532: $active = 'style="display: none;"';
3533: }elsif($activetab eq $field){
3534: $active = 'style="display:block;"';
3535: }
1.374 tempelho 3536: $form .= '<div id="'.$field.$tid.'"'
1.373 bisitz 3537: .' class="LC_ContentBox" '.$active.'>'.${$orderhash{$field}}[1]
3538: .'</div>';
1.363 ehlerst 3539: }
3540: }
1.330 tempelho 3541: $form .= '</div></div>';
1.364 bisitz 3542:
1.329 droeschl 3543: return $form;
3544: }
3545:
3546: sub editing_js {
3547: my ($udom,$uname) = @_;
3548: my $now = time();
3549: my %lt = &Apache::lonlocal::texthash(
3550: p_mnf => 'Name of New Folder',
3551: t_mnf => 'New Folder',
3552: p_mnp => 'Name of New Page',
3553: t_mnp => 'New Page',
3554: p_mxu => 'Title for the Uploaded Score',
1.349 biermanm 3555: p_msp => 'Name of Simple Course Page',
1.329 droeschl 3556: p_msb => 'Title for the Problem',
3557: p_mdb => 'Title for the Drop Box',
1.336 schafran 3558: p_mbb => 'Title for the Discussion Board',
1.348 weissno 3559: p_mab => "Enter user:domain for User's Personal Information Page",
1.352 bisitz 3560: p_mab2 => 'Personal Information Page of ',
1.329 droeschl 3561: p_mab_alrt1 => 'Not a valid user:domain',
3562: p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',
3563: p_chn => 'New Title',
3564: p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',
3565: p_rmr2a => 'Remove[_99]',
3566: p_rmr2b => '?[_99]',
3567: p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',
3568: p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',
3569: p_ctr2a => 'Cut[_98]',
3570: p_ctr2b => '?[_98]'
3571: );
3572:
3573: return <<ENDNEWSCRIPT;
3574: function makenewfolder(targetform,folderseq) {
3575: var foldername=prompt('$lt{"p_mnf"}','$lt{"t_mnf"}');
3576: if (foldername) {
3577: targetform.importdetail.value=escape(foldername)+"="+folderseq;
3578: targetform.submit();
3579: }
3580: }
3581:
3582: function makenewpage(targetform,folderseq) {
3583: var pagename=prompt('$lt{"p_mnp"}','$lt{"t_mnp"}');
3584: if (pagename) {
3585: targetform.importdetail.value=escape(pagename)+"="+folderseq;
3586: targetform.submit();
3587: }
3588: }
3589:
3590: function makenewext(targetname) {
3591: this.document.forms.extimport.useform.value=targetname;
3592: this.document.forms.extimport.title.value='';
3593: this.document.forms.extimport.url.value='';
3594: this.document.forms.extimport.residx.value='';
3595: window.open('/adm/rat/extpickframe.html');
3596: }
3597:
3598: function edittext(targetname,residx,title,url) {
3599: this.document.forms.extimport.useform.value=targetname;
3600: this.document.forms.extimport.residx.value=residx;
3601: this.document.forms.extimport.url.value=url;
3602: this.document.forms.extimport.title.value=title;
3603: window.open('/adm/rat/extpickframe.html');
3604: }
3605:
3606: function makeexamupload() {
3607: var title=prompt('$lt{"p_mxu"}');
1.344 bisitz 3608: if (title) {
1.329 droeschl 3609: this.document.forms.newexamupload.importdetail.value=
3610: escape(title)+'=/res/lib/templates/examupload.problem';
3611: this.document.forms.newexamupload.submit();
3612: }
3613: }
3614:
3615: function makesmppage() {
3616: var title=prompt('$lt{"p_msp"}');
1.344 bisitz 3617: if (title) {
1.329 droeschl 3618: this.document.forms.newsmppg.importdetail.value=
3619: escape(title)+'=/adm/$udom/$uname/$now/smppg';
3620: this.document.forms.newsmppg.submit();
3621: }
3622: }
3623:
3624: function makesmpproblem() {
3625: var title=prompt('$lt{"p_msb"}');
1.344 bisitz 3626: if (title) {
1.329 droeschl 3627: this.document.forms.newsmpproblem.importdetail.value=
3628: escape(title)+'=/res/lib/templates/simpleproblem.problem';
3629: this.document.forms.newsmpproblem.submit();
3630: }
3631: }
3632:
3633: function makedropbox() {
3634: var title=prompt('$lt{"p_mdb"}');
1.344 bisitz 3635: if (title) {
1.329 droeschl 3636: this.document.forms.newdropbox.importdetail.value=
3637: escape(title)+'=/res/lib/templates/DropBox.problem';
3638: this.document.forms.newdropbox.submit();
3639: }
3640: }
3641:
3642: function makebulboard() {
3643: var title=prompt('$lt{"p_mbb"}');
3644: if (title) {
3645: this.document.forms.newbul.importdetail.value=
3646: escape(title)+'=/adm/$udom/$uname/$now/bulletinboard';
3647: this.document.forms.newbul.submit();
3648: }
3649: }
3650:
3651: function makeabout() {
3652: var user=prompt("$lt{'p_mab'}");
3653: if (user) {
3654: var comp=new Array();
3655: comp=user.split(':');
3656: if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
3657: if ((comp[0]) && (comp[1])) {
3658: this.document.forms.newaboutsomeone.importdetail.value=
3659: '$lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
1.335 ehlerst 3660: this.document.forms.newaboutsomeone.submit();
3661: } else {
3662: alert("$lt{'p_mab_alrt1'}");
1.329 droeschl 3663: }
1.335 ehlerst 3664: } else {
3665: alert("$lt{'p_mab_alrt2'}");
3666: }
3667: }
1.329 droeschl 3668: }
3669:
3670: function makeims() {
1.335 ehlerst 3671: var caller = document.forms.ims.folder.value;
3672: var newlocation = "/adm/imsimportdocs?folder="+caller+"&phase=one";
3673: newWindow = window.open("","IMSimport","HEIGHT=700,WIDTH=750,scrollbars=yes");
3674: newWindow.location.href = newlocation;
1.329 droeschl 3675: }
3676:
3677:
3678: function finishpick() {
1.335 ehlerst 3679: var title=this.document.forms.extimport.title.value;
3680: var url=this.document.forms.extimport.url.value;
3681: var form=this.document.forms.extimport.useform.value;
3682: var residx=this.document.forms.extimport.residx.value;
3683: eval('this.document.forms.'+form+'.importdetail.value="'+title+'='+url+'='+residx+'";this.document.forms.'+form+'.submit();');
1.329 droeschl 3684: }
3685:
3686: function changename(folderpath,index,oldtitle,container,pagesymb) {
1.335 ehlerst 3687: var title=prompt('$lt{"p_chn"}',oldtitle);
3688: if (title) {
3689: this.document.forms.renameform.markcopy.value=-1;
3690: this.document.forms.renameform.title.value=title;
3691: this.document.forms.renameform.cmd.value='rename_'+index;
3692: if (container == 'sequence') {
3693: this.document.forms.renameform.folderpath.value=folderpath;
3694: }
3695: if (container == 'page') {
3696: this.document.forms.renameform.pagepath.value=folderpath;
3697: this.document.forms.renameform.pagesymb.value=pagesymb;
3698: }
3699: this.document.forms.renameform.submit();
3700: }
1.329 droeschl 3701: }
3702:
3703: function removeres(folderpath,index,oldtitle,container,pagesymb,skip_confirm) {
1.335 ehlerst 3704: if (skip_confirm || confirm('$lt{"p_rmr1"}\\n\\n$lt{"p_rmr2a"} "'+oldtitle+'" $lt{"p_rmr2b"}')) {
3705: this.document.forms.renameform.markcopy.value=-1;
3706: this.document.forms.renameform.cmd.value='del_'+index;
3707: if (container == 'sequence') {
3708: this.document.forms.renameform.folderpath.value=folderpath;
3709: }
3710: if (container == 'page') {
3711: this.document.forms.renameform.pagepath.value=folderpath;
3712: this.document.forms.renameform.pagesymb.value=pagesymb;
3713: }
3714: this.document.forms.renameform.submit();
3715: }
1.329 droeschl 3716: }
3717:
3718: function cutres(folderpath,index,oldtitle,container,pagesymb,folder,skip_confirm) {
1.335 ehlerst 3719: if (skip_confirm || confirm('$lt{"p_ctr1a"}\\n$lt{"p_ctr1b"}\\n\\n$lt{"p_ctr2a"} "'+oldtitle+'" $lt{"p_ctr2b"}')) {
3720: this.document.forms.renameform.cmd.value='cut_'+index;
3721: this.document.forms.renameform.markcopy.value=index;
3722: this.document.forms.renameform.copyfolder.value=folder+'.'+container;
3723: if (container == 'sequence') {
3724: this.document.forms.renameform.folderpath.value=folderpath;
3725: }
3726: if (container == 'page') {
3727: this.document.forms.renameform.pagepath.value=folderpath;
3728: this.document.forms.renameform.pagesymb.value=pagesymb;
3729: }
3730: this.document.forms.renameform.submit();
3731: }
1.329 droeschl 3732: }
3733:
3734: function markcopy(folderpath,index,oldtitle,container,pagesymb,folder) {
1.335 ehlerst 3735: this.document.forms.renameform.markcopy.value=index;
3736: this.document.forms.renameform.copyfolder.value=folder+'.'+container;
3737: if (container == 'sequence') {
3738: this.document.forms.renameform.folderpath.value=folderpath;
3739: }
3740: if (container == 'page') {
3741: this.document.forms.renameform.pagepath.value=folderpath;
3742: this.document.forms.renameform.pagesymb.value=pagesymb;
3743: }
3744: this.document.forms.renameform.submit();
1.329 droeschl 3745: }
3746:
1.334 muellerd 3747: function unselectInactive(nav) {
1.335 ehlerst 3748: currentNav = document.getElementById(nav);
3749: currentLis = currentNav.getElementsByTagName('LI');
3750: for (i = 0; i < currentLis.length; i++) {
1.374 tempelho 3751: if(currentLis[i].className == 'right active' || currentLis[i].className == 'right'){
3752: currentLis[i].className = 'right';
3753: }else{
3754: currentLis[i].className = 'i';
3755: }
1.335 ehlerst 3756: }
1.332 tempelho 3757: }
3758:
1.334 muellerd 3759: function hideAll(current, nav, data) {
1.335 ehlerst 3760: unselectInactive(nav);
1.374 tempelho 3761: if(current.className == 'right'){
3762: current.className = 'right active'
3763: }else{
3764: current.className = 'active';
3765: }
1.335 ehlerst 3766: currentData = document.getElementById(data);
3767: currentDivs = currentData.getElementsByTagName('DIV');
3768: for (i = 0; i < currentDivs.length; i++) {
3769: if(currentDivs[i].className == 'LC_ContentBox'){
1.333 muellerd 3770: currentDivs[i].style.display = 'none';
1.330 tempelho 3771: }
3772: }
1.335 ehlerst 3773: }
1.330 tempelho 3774:
1.374 tempelho 3775: function openTabs(pageId) {
3776: tabnav = document.getElementById(pageId).getElementsByTagName('UL');
1.383 tempelho 3777: if(tabnav.length > 2 ){
1.389 tempelho 3778: currentNav = document.getElementById(tabnav[1].id);
1.374 tempelho 3779: currentLis = currentNav.getElementsByTagName('LI');
3780: for(i = 0; i< currentLis.length; i++){
3781: if(currentLis[i].className == 'active') {
1.375 tempelho 3782: funcString = currentLis[i].onclick.toString();
3783: tab = funcString.split('"');
3784: currentData = document.getElementById(tab[1]);
3785: currentData.style.display = 'block';
1.374 tempelho 3786: }
3787: }
3788: }
3789: }
3790:
1.334 muellerd 3791: function showPage(current, pageId, nav, data) {
3792: hideAll(current, nav, data);
1.375 tempelho 3793: openTabs(pageId);
1.334 muellerd 3794: unselectInactive(nav);
1.330 tempelho 3795: current.className = 'active';
3796: currentData = document.getElementById(pageId);
3797: currentData.style.display = 'block';
3798: return false;
3799: }
1.329 droeschl 3800:
1.383 tempelho 3801: function injectData(current, hiddenField, name, value) {
3802: currentElement = document.getElementById(hiddenField);
3803: currentElement.name = name;
3804: currentElement.value = value;
3805: current.submit();
3806: }
3807:
1.329 droeschl 3808: ENDNEWSCRIPT
3809: }
3810: 1;
3811: __END__
3812:
3813:
3814: =head1 NAME
3815:
3816: Apache::londocs.pm
3817:
3818: =head1 SYNOPSIS
3819:
3820: This is part of the LearningOnline Network with CAPA project
3821: described at http://www.lon-capa.org.
3822:
3823: =head1 SUBROUTINES
3824:
3825: =over
3826:
3827: =item %help=()
3828:
3829: Available help topics
3830:
3831: =item mapread()
3832:
1.344 bisitz 3833: Mapread read maps into LONCAPA::map:: global arrays
1.329 droeschl 3834: @order and @resources, determines status
3835: sets @order - pointer to resources in right order
3836: sets @resources - array with the resources with correct idx
3837:
3838: =item authorhosts()
3839:
3840: Return hash with valid author names
3841:
3842: =item dumpbutton()
3843:
3844: Generate "dump" button
3845:
3846: =item clean()
3847:
3848: =item dumpcourse()
3849:
3850: Actually dump course
3851:
3852:
3853: =item exportbutton()
3854:
3855: Generate "export" button
3856:
3857: =item exportcourse()
3858:
3859: =item create_ims_store()
3860:
3861: =item build_package()
3862:
3863: =item get_dependencies()
3864:
3865: =item process_content()
3866:
3867: =item replicate_content()
3868:
3869: =item extract_media()
3870:
3871: =item store_template()
3872:
3873: =item group_import()
3874:
3875: Imports the given (name, url) resources into the course
3876: coursenum, coursedom, and folder must precede the list
3877:
3878: =item breadcrumbs()
3879:
3880: =item log_docs()
3881:
3882: =item docs_change_log()
3883:
3884: =item update_paste_buffer()
3885:
3886: =item print_paste_buffer()
3887:
3888: =item do_paste_from_buffer()
3889:
3890: =item update_parameter()
3891:
3892: =item handle_edit_cmd()
3893:
3894: =item editor()
3895:
3896: =item process_file_upload()
3897:
3898: =item process_secondary_uploads()
3899:
3900: =item is_supplemental_title()
3901:
3902: =item parse_supplemental_title()
3903:
3904: =item entryline()
3905:
3906: =item tiehash()
3907:
3908: =item untiehash()
3909:
3910: =item checkonthis()
3911:
3912: check on this
3913:
3914: =item verifycontent()
3915:
3916: Verify Content
3917:
3918: =item devalidateversioncache() & checkversions()
3919:
3920: Check Versions
3921:
3922: =item mark_hash_old()
3923:
3924: =item is_hash_old()
3925:
3926: =item changewarning()
3927:
3928: =item init_breadcrumbs()
3929:
3930: Breadcrumbs for special functions
3931:
3932: =back
3933:
3934: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>