Annotation of loncom/interface/londocs.pm, revision 1.537
1.329 droeschl 1: # The LearningOnline Network
2: # Documents
3: #
1.537 ! raeburn 4: # $Id: londocs.pm,v 1.536 2013/03/13 00:29:09 raeburn 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: package Apache::londocs;
30:
31: use strict;
32: use Apache::Constants qw(:common :http);
33: use Apache::imsexport;
34: use Apache::lonnet;
35: use Apache::loncommon;
1.383 tempelho 36: use Apache::lonhtmlcommon;
1.329 droeschl 37: use LONCAPA::map();
38: use Apache::lonratedt();
39: use Apache::lonxml;
40: use Apache::lonclonecourse;
41: use Apache::lonnavmaps;
1.472 raeburn 42: use Apache::lonnavdisplay();
1.510 raeburn 43: use Apache::lonextresedit();
1.329 droeschl 44: use HTML::Entities;
1.488 raeburn 45: use HTML::TokeParser;
1.329 droeschl 46: use GDBM_File;
47: use Apache::lonlocal;
48: use Cwd;
49: use LONCAPA qw(:DEFAULT :match);
50:
51: my $iconpath;
52:
53: my %hash;
54:
55: my $hashtied;
56: my %alreadyseen=();
57:
58: my $hadchanges;
59:
60:
61: my %help=();
62:
63:
64: sub mapread {
65: my ($coursenum,$coursedom,$map)=@_;
66: return
67: &LONCAPA::map::mapread('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
68: $map);
69: }
70:
71: sub storemap {
1.492 raeburn 72: my ($coursenum,$coursedom,$map,$contentchg)=@_;
73: my $report;
74: if (($contentchg) && ($map =~ /^default/)) {
75: $report = 1;
76: }
1.329 droeschl 77: my ($outtext,$errtext)=
78: &LONCAPA::map::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
1.492 raeburn 79: $map,1,$report);
1.329 droeschl 80: if ($errtext) { return ($errtext,2); }
1.364 bisitz 81:
1.329 droeschl 82: $hadchanges=1;
83: return ($errtext,0);
84: }
85:
86:
87:
88: sub authorhosts {
89: my %outhash=();
90: my $home=0;
91: my $other=0;
92: foreach my $key (keys(%env)) {
93: if ($key=~/^user\.role\.(au|ca)\.(.+)$/) {
94: my $role=$1;
95: my $realm=$2;
96: my ($start,$end)=split(/\./,$env{$key});
97: if (($start) && ($start>time)) { next; }
98: if (($end) && (time>$end)) { next; }
99: my ($ca,$cd);
100: if ($1 eq 'au') {
101: $ca=$env{'user.name'};
102: $cd=$env{'user.domain'};
103: } else {
104: ($cd,$ca)=($realm=~/^\/($match_domain)\/($match_username)$/);
105: }
106: my $allowed=0;
107: my $myhome=&Apache::lonnet::homeserver($ca,$cd);
108: my @ids=&Apache::lonnet::current_machine_ids();
1.484 raeburn 109: foreach my $id (@ids) {
110: if ($id eq $myhome) {
111: $allowed=1;
112: last;
113: }
114: }
1.329 droeschl 115: if ($allowed) {
116: $home++;
1.484 raeburn 117: $outhash{'home_'.$ca.':'.$cd}=1;
1.329 droeschl 118: } else {
1.484 raeburn 119: $outhash{'otherhome_'.$ca.':'.$cd}=$myhome;
1.329 droeschl 120: $other++;
121: }
122: }
123: }
124: return ($home,$other,%outhash);
125: }
126:
127:
128: sub clean {
129: my ($title)=@_;
130: $title=~s/[^\w\/\!\$\%\^\*\-\_\=\+\;\:\,\\\|\`\~]+/\_/gs;
1.344 bisitz 131: return $title;
1.329 droeschl 132: }
133:
134:
135:
136: sub dumpcourse {
137: my ($r) = @_;
1.408 raeburn 138: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 139: $r->print(&Apache::loncommon::start_page('Dump '.$crstype.' Content to Authoring Space')."\n".
140: &Apache::lonhtmlcommon::breadcrumbs('Dump '.$crstype.' Content to Authoring Space')."\n");
141: $r->print(&startContentScreen('tools'));
1.329 droeschl 142: my ($home,$other,%outhash)=&authorhosts();
1.484 raeburn 143: unless ($home) {
144: $r->print(&endContentScreen());
145: return '';
146: }
1.329 droeschl 147: my $origcrsid=$env{'request.course.id'};
148: my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
149: if (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
150: # Do the dumping
1.484 raeburn 151: unless ($outhash{'home_'.$env{'form.authorspace'}}) {
152: $r->print(&endContentScreen());
153: return '';
154: }
1.531 raeburn 155: my ($ca,$cd)=split(/\:/,$env{'form.authorspace'});
1.329 droeschl 156: $r->print('<h3>'.&mt('Copying Files').'</h3>');
157: my $title=$env{'form.authorfolder'};
158: $title=&clean($title);
159: my %replacehash=();
160: foreach my $key (keys(%env)) {
161: if ($key=~/^form\.namefor\_(.+)/) {
162: $replacehash{$1}=$env{$key};
163: }
164: }
165: my $crs='/uploaded/'.$env{'request.course.id'}.'/';
166: $crs=~s/\_/\//g;
167: foreach my $item (keys(%replacehash)) {
168: my $newfilename=$title.'/'.$replacehash{$item};
169: $newfilename=~s/\.(\w+)$//;
170: my $ext=$1;
171: $newfilename=&clean($newfilename);
172: $newfilename.='.'.$ext;
173: my @dirs=split(/\//,$newfilename);
1.462 raeburn 174: my $path=$r->dir_config('lonDocRoot')."/priv/$cd/$ca";
1.329 droeschl 175: my $makepath=$path;
176: my $fail=0;
177: for (my $i=0;$i<$#dirs;$i++) {
178: $makepath.='/'.$dirs[$i];
1.344 bisitz 179: unless (-e $makepath) {
180: unless(mkdir($makepath,0777)) { $fail=1; }
1.329 droeschl 181: }
182: }
183: $r->print('<br /><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt>: ');
184: if (my $fh=Apache::File->new('>'.$path.'/'.$newfilename)) {
185: if ($item=~/\.(sequence|page|html|htm|xml|xhtml)$/) {
186: print $fh &Apache::lonclonecourse::rewritefile(
187: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
188: (%replacehash,$crs => '')
189: );
190: } else {
191: print $fh
192: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item);
193: }
194: $fh->close();
195: } else {
196: $fail=1;
197: }
198: if ($fail) {
199: $r->print('<span class="LC_error">'.&mt('fail').'</span>');
200: } else {
201: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
202: }
203: }
204: } else {
1.484 raeburn 205: $r->print(&mt('Searching ...').'<br />');
206: $r->rflush();
1.329 droeschl 207: # Input form
1.484 raeburn 208: $r->print('<form name="dumpdoc" action="" method="post">'."\n");
1.329 droeschl 209: unless ($home==1) {
1.484 raeburn 210: $r->print('<div class="LC_left_float">'.
211: '<fieldset><legend>'.
212: &mt('Select the Authoring Space').
213: '</legend><select name="authorspace">');
1.329 droeschl 214: }
215: foreach my $key (sort(keys(%outhash))) {
216: if ($key=~/^home_(.+)$/) {
217: if ($home==1) {
218: $r->print(
219: '<input type="hidden" name="authorspace" value="'.$1.'" />');
220: } else {
221: $r->print('<option value="'.$1.'">'.$1.' - '.
1.484 raeburn 222: &Apache::loncommon::plainname(split(/\:/,$1)).'</option>');
1.329 droeschl 223: }
224: }
225: }
226: unless ($home==1) {
1.484 raeburn 227: $r->print('</select></fieldset></div>'."\n");
1.329 droeschl 228: }
229: my $title=$origcrsdata{'description'};
230: $title=~s/[\/\s]+/\_/gs;
231: $title=&clean($title);
1.484 raeburn 232: $r->print('<div class="LC_left_float">'.
233: '<fieldset><legend>'.&mt('Folder in Authoring Space').'</legend>'.
234: '<input type="text" size="50" name="authorfolder" value="'.
235: $title.'" />'.
236: '</fieldset></div><br clear="all" />'."\n");
1.329 droeschl 237: &tiehash();
1.484 raeburn 238: $r->print('<h4>'.&mt('Filenames in Authoring Space').'</h4>'
1.329 droeschl 239: .&Apache::loncommon::start_data_table()
240: .&Apache::loncommon::start_data_table_header_row()
241: .'<th>'.&mt('Internal Filename').'</th>'
242: .'<th>'.&mt('Title').'</th>'
243: .'<th>'.&mt('Save as ...').'</th>'
244: .&Apache::loncommon::end_data_table_header_row());
245: foreach my $file (&Apache::lonclonecourse::crsdirlist($origcrsid,'userfiles')) {
246: $r->print(&Apache::loncommon::start_data_table_row()
247: .'<td>'.$file.'</td>');
248: my ($ext)=($file=~/\.(\w+)$/);
249: my $title=$hash{'title_'.$hash{
250: 'ids_/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'.$file}};
251: $r->print('<td>'.($title?$title:' ').'</td>');
252: if (!$title) {
253: $title=$file;
254: } else {
255: $title=~s|/|_|g;
256: }
257: $title=~s/\.(\w+)$//;
258: $title=&clean($title);
259: $title.='.'.$ext;
260: $r->print("\n<td><input type='text' size='60' name='namefor_".$file."' value='".$title."' /></td>"
261: .&Apache::loncommon::end_data_table_row());
262: }
263: $r->print(&Apache::loncommon::end_data_table());
264: &untiehash();
265: $r->print(
1.484 raeburn 266: '<p><input type="submit" name="dumpcourse" value="'.&mt("Dump $crstype Content").'" /></p></form>');
1.329 droeschl 267: }
1.484 raeburn 268: $r->print(&endContentScreen());
1.329 droeschl 269: }
270:
271: sub group_import {
272: my ($coursenum, $coursedom, $folder, $container, $caller, @files) = @_;
1.529 raeburn 273: my ($donechk,$allmaps,%hierarchy,%titles,%addedmaps,%removefrommap,
274: %removeparam,$importuploaded,$fixuperrors);
275: $allmaps = {};
1.329 droeschl 276: while (@files) {
277: my ($name, $url, $residx) = @{ shift(@files) };
1.344 bisitz 278: if (($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$})
1.329 droeschl 279: && ($caller eq 'londocs')
280: && (!&Apache::lonnet::stat_file($url))) {
1.364 bisitz 281:
1.329 droeschl 282: my $errtext = '';
283: my $fatal = 0;
284: my $newmapstr = '<map>'."\n".
285: '<resource id="1" src="" type="start"></resource>'."\n".
286: '<link from="1" to="2" index="1"></link>'."\n".
287: '<resource id="2" src="" type="finish"></resource>'."\n".
288: '</map>';
289: $env{'form.output'}=$newmapstr;
290: my $result=&Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
291: 'output',$1.$2);
1.534 raeburn 292: if ($result !~ m{^/uploaded/}) {
1.329 droeschl 293: $errtext.='Map not saved: A network error occurred when trying to save the new map. ';
294: $fatal = 2;
295: }
296: if ($fatal) {
297: return ($errtext,$fatal);
298: }
299: }
300: if ($url) {
1.529 raeburn 301: if (($caller eq 'londocs') &&
302: ($folder =~ /^default/)) {
1.534 raeburn 303: if (($url =~ /\.(page|sequence)$/) && (!$donechk)) {
1.529 raeburn 304: my $chome = &Apache::lonnet::homeserver($coursenum,$coursedom);
305: my $cid = $coursedom.'_'.$coursenum;
306: $allmaps =
307: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
308: $chome,$cid);
309: $donechk = 1;
310: }
311: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$}) {
312: &contained_map_check($url,$folder,\%removefrommap,\%removeparam,
313: \%addedmaps,\%hierarchy,\%titles,$allmaps);
314: $importuploaded = 1;
315: } elsif ($url =~ m{^/res/.+\.(page|sequence)$}) {
316: next if ($allmaps->{$url});
317: }
318: }
1.344 bisitz 319: if (!$residx
1.329 droeschl 320: || defined($LONCAPA::map::zombies[$residx])) {
321: $residx = &LONCAPA::map::getresidx($url,$residx);
322: push(@LONCAPA::map::order, $residx);
323: }
324: my $ext = 'false';
325: if ($url=~m{^http://} || $url=~m{^https://}) { $ext = 'true'; }
326: $url = &LONCAPA::map::qtunescape($url);
327: $name = &LONCAPA::map::qtunescape($name);
1.534 raeburn 328: if ($name eq '') {
329: $name = &mt('Web Page');
330: }
331: if ($url =~ m{^/uploaded/$coursedom/$coursenum/((?:docs|supplemental)/(?:default|\d+))/new\.html$}) {
332: my $filepath = $1;
333: my $fname = $name;
334: if ($fname =~ /^\W+$/) {
335: $fname = 'web';
336: } else {
337: $fname =~ s/\W/_/g;
338: }
339: if (length($fname > 15)) {
340: $fname = substr($fname,0,14);
341: }
342: my $initialtext = &mt('Replace with your own content.');
343: my $newhtml = <<END;
344: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
345: <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
346: <head>
347: <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
348: <title>$name</title>
349: </head>
350: <body bgcolor="#ffffff">
351: $initialtext
352: </body>
353: </html>
354: END
355: $env{'form.output'}=$newhtml;
356: my $result =
357: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
358: 'output',
359: "$filepath/$residx/$fname.html");
360: if ($result =~ m{^/uploaded/}) {
361: $url = $result;
362: if ($filepath =~ /^supplemental/) {
363: $name = time.'___&&&___'.$env{'user.name'}.'___&&&___'.
364: $env{'user.domain'}.'___&&&___'.$name;
365: }
366: } else {
367: return (&mt('Failed to save new web page.'),1);
368: }
369: }
1.344 bisitz 370: $LONCAPA::map::resources[$residx] =
1.329 droeschl 371: join(':', ($name, $url, $ext, 'normal', 'res'));
372: }
373: }
1.529 raeburn 374: if ($importuploaded) {
375: my %import_errors;
376: my %updated = (
377: removefrommap => \%removefrommap,
378: removeparam => \%removeparam,
379: );
1.533 raeburn 380: my ($result,$msgsarray,$lockerror) =
381: &apply_fixups($folder,1,$coursedom,$coursenum,\%import_errors,\%updated);
1.529 raeburn 382: if (keys(%import_errors) > 0) {
1.530 raeburn 383: $fixuperrors =
1.529 raeburn 384: '<p span class="LC_warning">'."\n".
385: &mt('The following files are either dependencies of a web page or references within a folder and/or composite page for which errors occurred during import:')."\n".
386: '<ul>'."\n";
387: foreach my $key (sort(keys(%import_errors))) {
388: $fixuperrors .= '<li>'.$key.'</li>'."\n";
389: }
390: $fixuperrors .= '</ul></p>'."\n";
391: }
1.533 raeburn 392: if (ref($msgsarray) eq 'ARRAY') {
393: if (@{$msgsarray} > 0) {
394: $fixuperrors .= '<p class="LC_info">'.
395: join('<br />',@{$msgsarray}).
396: '</p>';
397: }
398: }
399: if ($lockerror) {
400: $fixuperrors .= '<p class="LC_error">'.
401: $lockerror.
402: '</p>';
403: }
1.529 raeburn 404: }
405: my ($errtext,$fatal) =
406: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
407: return ($errtext,$fatal,$fixuperrors);
1.329 droeschl 408: }
409:
410: sub log_docs {
1.494 raeburn 411: return &Apache::lonnet::write_log('course','docslog',@_);
1.329 droeschl 412: }
413:
414: {
415: my @oldresources=();
416: my @oldorder=();
417: my $parmidx;
418: my %parmaction=();
419: my %parmvalue=();
420: my $changedflag;
421:
422: sub snapshotbefore {
423: @oldresources=@LONCAPA::map::resources;
424: @oldorder=@LONCAPA::map::order;
425: $parmidx=undef;
426: %parmaction=();
427: %parmvalue=();
428: $changedflag=0;
429: }
430:
431: sub remember_parms {
432: my ($idx,$parameter,$action,$value)=@_;
433: $parmidx=$idx;
434: $parmaction{$parameter}=$action;
435: $parmvalue{$parameter}=$value;
436: $changedflag=1;
437: }
438:
439: sub log_differences {
440: my ($plain)=@_;
441: my %storehash=('folder' => $plain,
442: 'currentfolder' => $env{'form.folder'});
443: if ($parmidx) {
444: $storehash{'parameter_res'}=$oldresources[$parmidx];
445: foreach my $parm (keys(%parmaction)) {
446: $storehash{'parameter_action_'.$parm}=$parmaction{$parm};
447: $storehash{'parameter_value_'.$parm}=$parmvalue{$parm};
448: }
449: }
450: my $maxidx=$#oldresources;
451: if ($#LONCAPA::map::resources>$#oldresources) {
452: $maxidx=$#LONCAPA::map::resources;
453: }
454: for (my $idx=0; $idx<=$maxidx; $idx++) {
455: if ($LONCAPA::map::resources[$idx] ne $oldresources[$idx]) {
456: $storehash{'before_resources_'.$idx}=$oldresources[$idx];
457: $storehash{'after_resources_'.$idx}=$LONCAPA::map::resources[$idx];
458: $changedflag=1;
459: }
460: if ($LONCAPA::map::order[$idx] ne $oldorder[$idx]) {
461: $storehash{'before_order_res_'.$idx}=$oldresources[$oldorder[$idx]];
462: $storehash{'after_order_res_'.$idx}=$LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
463: $changedflag=1;
464: }
465: }
466: $storehash{'maxidx'}=$maxidx;
467: if ($changedflag) { &log_docs(\%storehash); }
468: }
469: }
470:
471: sub docs_change_log {
1.484 raeburn 472: my ($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath)=@_;
1.486 raeburn 473: my $supplementalflag=($env{'form.folderpath'}=~/^supplemental/);
1.483 raeburn 474: my $js = '<script type="text/javascript">'."\n".
475: '// <![CDATA['."\n".
476: &Apache::loncommon::display_filter_js('docslog')."\n".
1.486 raeburn 477: &editing_js($env{'user.domain'},$env{'user.name'},$supplementalflag)."\n".
1.483 raeburn 478: &history_tab_js()."\n".
1.484 raeburn 479: &Apache::lonratedt::editscript('simple')."\n".
1.483 raeburn 480: '// ]]>'."\n".
481: '</script>'."\n";
1.484 raeburn 482: $r->print(&Apache::loncommon::start_page('Content Change Log',$js));
483: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Change Log'));
1.489 raeburn 484: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.484 raeburn 485: my %orderhash;
486: my $container='sequence';
487: my $pathitem;
1.519 raeburn 488: if ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 489: $container='page';
490: }
1.519 raeburn 491: my $folderpath=$env{'form.folderpath'};
492: if ($folderpath eq '') {
493: $folderpath = 'default&'.&escape(&mt('Main '.$crstype.' Documents').':::::');
494: }
495: $pathitem = '<input type="hidden" name="folderpath" value="'.
496: &HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 497: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
498: my $jumpto = $readfile;
499: $jumpto =~ s{^/}{};
500: my $tid = 1;
1.489 raeburn 501: if ($supplementalflag) {
502: $tid = 2;
503: }
1.509 raeburn 504: my ($breadcrumbtrail) =
505: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
1.484 raeburn 506: $r->print($breadcrumbtrail.
507: &generate_edit_table($tid,\%orderhash,undef,$iconpath,$jumpto,
508: $readfile));
1.329 droeschl 509: my %docslog=&Apache::lonnet::dump('nohist_docslog',
510: $env{'course.'.$env{'request.course.id'}.'.domain'},
511: $env{'course.'.$env{'request.course.id'}.'.num'});
512:
513: if ((keys(%docslog))[0]=~/^error\:/) { undef(%docslog); }
514:
515: my %saveable_parameters = ('show' => 'scalar',);
516: &Apache::loncommon::store_course_settings('docs_log',
517: \%saveable_parameters);
518: &Apache::loncommon::restore_course_settings('docs_log',
519: \%saveable_parameters);
520: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.452 www 521: # FIXME: internationalization seems wrong here
1.329 droeschl 522: my %lt=('hiddenresource' => 'Resources hidden',
523: 'encrypturl' => 'URL hidden',
524: 'randompick' => 'Randomly pick',
525: 'randomorder' => 'Randomly ordered',
526: 'set' => 'set to',
527: 'del' => 'deleted');
1.484 raeburn 528: my $filter = &Apache::loncommon::display_filter('docslog')."\n".
529: $pathitem."\n".
530: '<input type="hidden" name="folder" value="'.$env{'form.folder'}.'" />'.
531: (' 'x2).'<input type="submit" value="'.&mt('Display').'" />';
532: $r->print('<div class="LC_left_float">'.
533: '<fieldset><legend>'.&mt('Display of Content Changes').'</legend>'."\n".
534: &makedocslogform($filter,1).
535: '</fieldset></div><br clear="all" />');
1.329 droeschl 536: $r->print(&Apache::loncommon::start_data_table().&Apache::loncommon::start_data_table_header_row().
537: '<th>'.&mt('Time').'</th><th>'.&mt('User').'</th><th>'.&mt('Folder').'</th><th>'.&mt('Before').'</th><th>'.
538: &mt('After').'</th>'.
539: &Apache::loncommon::end_data_table_header_row());
540: my $shown=0;
541: foreach my $id (sort { $docslog{$b}{'exe_time'}<=>$docslog{$a}{'exe_time'} } (keys(%docslog))) {
542: if ($env{'form.displayfilter'} eq 'currentfolder') {
543: if ($docslog{$id}{'logentry'}{'currentfolder'} ne $folder) { next; }
544: }
545: my @changes=keys(%{$docslog{$id}{'logentry'}});
546: if ($env{'form.displayfilter'} eq 'containing') {
547: my $wholeentry=$docslog{$id}{'exe_uname'}.':'.$docslog{$id}{'exe_udom'}.':'.
548: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},$docslog{$id}{'exe_udom'});
549: foreach my $key (@changes) {
550: $wholeentry.=':'.$docslog{$id}{'logentry'}{$key};
551: }
1.344 bisitz 552: if ($wholeentry!~/\Q$env{'form.containingphrase'}\E/i) { next; }
1.329 droeschl 553: }
554: my $count = 0;
555: my $time =
556: &Apache::lonlocal::locallocaltime($docslog{$id}{'exe_time'});
557: my $plainname =
558: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},
559: $docslog{$id}{'exe_udom'});
560: my $about_me_link =
561: &Apache::loncommon::aboutmewrapper($plainname,
562: $docslog{$id}{'exe_uname'},
563: $docslog{$id}{'exe_udom'});
564: my $send_msg_link='';
565: if ((($docslog{$id}{'exe_uname'} ne $env{'user.name'})
566: || ($docslog{$id}{'exe_udom'} ne $env{'user.domain'}))) {
567: $send_msg_link ='<br />'.
568: &Apache::loncommon::messagewrapper(&mt('Send message'),
569: $docslog{$id}{'exe_uname'},
570: $docslog{$id}{'exe_udom'});
571: }
572: $r->print(&Apache::loncommon::start_data_table_row());
573: $r->print('<td>'.$time.'</td>
574: <td>'.$about_me_link.
575: '<br /><tt>'.$docslog{$id}{'exe_uname'}.
576: ':'.$docslog{$id}{'exe_udom'}.'</tt>'.
577: $send_msg_link.'</td><td>'.
578: $docslog{$id}{'logentry'}{'folder'}.'</td><td>');
1.488 raeburn 579: my $is_supp = 0;
580: if ($docslog{$id}{'logentry'}{'currentfolder'} =~ /^supplemental/) {
581: $is_supp = 1;
582: }
1.329 droeschl 583: # Before
584: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
585: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
586: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
587: if ($oldname ne $newname) {
1.488 raeburn 588: my $shown = &LONCAPA::map::qtescape($oldname);
589: if ($is_supp) {
590: $shown = &Apache::loncommon::parse_supplemental_title($shown);
591: }
592: $r->print($shown);
1.329 droeschl 593: }
594: }
595: $r->print('<ul>');
596: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
597: if ($docslog{$id}{'logentry'}{'before_order_res_'.$idx}) {
1.488 raeburn 598: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'before_order_res_'.$idx}))[0]);
599: if ($is_supp) {
600: $shown = &Apache::loncommon::parse_supplemental_title($shown);
601: }
602: $r->print('<li>'.$shown.'</li>');
1.329 droeschl 603: }
604: }
605: $r->print('</ul>');
606: # After
607: $r->print('</td><td>');
608:
609: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
610: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
611: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
612: if ($oldname ne '' && $oldname ne $newname) {
1.488 raeburn 613: my $shown = &LONCAPA::map::qtescape($newname);
614: if ($is_supp) {
615: $shown = &Apache::loncommon::parse_supplemental_title(&LONCAPA::map::qtescape($newname));
616: }
617: $r->print($shown);
1.329 droeschl 618: }
1.364 bisitz 619: }
1.329 droeschl 620: $r->print('<ul>');
621: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
622: if ($docslog{$id}{'logentry'}{'after_order_res_'.$idx}) {
1.488 raeburn 623: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'after_order_res_'.$idx}))[0]);
624: if ($is_supp) {
625: $shown = &Apache::loncommon::parse_supplemental_title($shown);
626: }
627: $r->print('<li>'.$shown.'</li>');
1.329 droeschl 628: }
629: }
630: $r->print('</ul>');
631: if ($docslog{$id}{'logentry'}{'parameter_res'}) {
632: $r->print(&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'parameter_res'}))[0]).':<ul>');
633: foreach my $parameter ('randompick','hiddenresource','encrypturl','randomorder') {
634: if ($docslog{$id}{'logentry'}{'parameter_action_'.$parameter}) {
1.452 www 635: # FIXME: internationalization seems wrong here
1.329 droeschl 636: $r->print('<li>'.
637: &mt($lt{$parameter}.' '.$lt{$docslog{$id}{'logentry'}{'parameter_action_'.$parameter}}.' [_1]',
638: $docslog{$id}{'logentry'}{'parameter_value_'.$parameter})
639: .'</li>');
640: }
641: }
642: $r->print('</ul>');
643: }
644: # End
645: $r->print('</td>'.&Apache::loncommon::end_data_table_row());
646: $shown++;
647: if (!($env{'form.show'} eq &mt('all')
648: || $shown<=$env{'form.show'})) { last; }
649: }
1.484 raeburn 650: $r->print(&Apache::loncommon::end_data_table()."\n".
651: &makesimpleeditform($pathitem)."\n".
652: '</div></div>');
653: $r->print(&endContentScreen());
1.329 droeschl 654: }
655:
656: sub update_paste_buffer {
1.492 raeburn 657: my ($coursenum,$coursedom,$folder) = @_;
1.329 droeschl 658:
659: return if (!defined($env{'form.markcopy'}));
660: return if (!defined($env{'form.copyfolder'}));
661: return if ($env{'form.markcopy'} < 0);
662:
663: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
664: $env{'form.copyfolder'});
1.364 bisitz 665:
1.329 droeschl 666: return if ($fatal);
667:
668: # Mark for copying
669: my ($title,$url)=split(':',$LONCAPA::map::resources[$LONCAPA::map::order[$env{'form.markcopy'}]]);
670: if (&is_supplemental_title($title)) {
671: &Apache::lonnet::appenv({'docs.markedcopy_supplemental' => $title});
1.488 raeburn 672: ($title) = &Apache::loncommon::parse_supplemental_title($title);
1.329 droeschl 673: } elsif ($env{'docs.markedcopy_supplemental'}) {
1.346 raeburn 674: &Apache::lonnet::delenv('docs.markedcopy_supplemental');
1.329 droeschl 675: }
676: $url=~s{http(:|:)//https(:|:)//}{https$2//};
677:
1.492 raeburn 678: (my $cmd,undef)=split('_',$env{'form.cmd'});
679:
680: my %addtoenv = (
681: 'docs.markedcopy_title' => $title,
682: 'docs.markedcopy_url' => $url,
683: 'docs.markedcopy_cmd' => $cmd,
684: );
685: &Apache::lonnet::delenv('docs.markedcopy_nested');
686: &Apache::lonnet::delenv('docs.markedcopy_nestednames');
687: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(default|supplemental)_?(\d*)\.(page|sequence)$}) {
688: my $prefix = $1;
689: my $subdir =$2;
690: if ($subdir eq '') {
691: $subdir = $prefix;
692: }
693: my (%addedmaps,%removefrommap,%removeparam,%hierarchy,%titles,%allmaps);
694: &contained_map_check($url,$folder,\%removefrommap,\%removeparam,\%addedmaps,
695: \%hierarchy,\%titles,\%allmaps);
696: if (ref($hierarchy{$url}) eq 'HASH') {
697: my ($nested,$nestednames);
698: &recurse_uploaded_maps($url,$subdir,\%hierarchy,\%titles,\$nested,\$nestednames);
699: $nested =~ s/\&$//;
700: $nestednames =~ s/\Q___&&&___\E$//;
701: if ($nested ne '') {
702: $addtoenv{'docs.markedcopy_nested'} = $nested;
703: }
704: if ($nestednames ne '') {
705: $addtoenv{'docs.markedcopy_nestednames'} = $nestednames;
706: }
707: }
708: }
709: &Apache::lonnet::appenv(\%addtoenv);
1.329 droeschl 710: delete($env{'form.markcopy'});
711: }
712:
1.492 raeburn 713: sub recurse_uploaded_maps {
714: my ($url,$dir,$hierarchy,$titlesref,$nestref,$namesref) = @_;
715: if (ref($hierarchy->{$url}) eq 'HASH') {
716: my @maps = map { $hierarchy->{$url}{$_}; } sort { $a <=> $b } (keys(%{$hierarchy->{$url}}));
717: my @titles = map { $titlesref->{$url}{$_}; } sort { $a <=> $b } (keys(%{$titlesref->{$url}}));
718: my (@uploaded,@names,%shorter);
719: for (my $i=0; $i<@maps; $i++) {
720: my ($inner) = ($maps[$i] =~ m{^/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_(\d+)\.(?:page|sequence)$});
721: if ($inner ne '') {
722: push(@uploaded,$inner);
723: push(@names,&escape($titles[$i]));
724: $shorter{$maps[$i]} = $inner;
725: }
726: }
727: $$nestref .= "$dir:".join(',',@uploaded).'&';
728: $$namesref .= "$dir:".(join(',',@names)).'___&&&___';
729: foreach my $map (@maps) {
730: if ($shorter{$map} ne '') {
731: &recurse_uploaded_maps($map,$shorter{$map},$hierarchy,$titlesref,$nestref,$namesref);
732: }
733: }
734: }
735: return;
736: }
737:
1.329 droeschl 738: sub print_paste_buffer {
1.492 raeburn 739: my ($r,$container,$folder,$coursedom,$coursenum) = @_;
1.329 droeschl 740: return if (!defined($env{'docs.markedcopy_url'}));
741:
1.492 raeburn 742: my ($is_external,$othercourse,$fromsupp,$is_uploaded_map,$parent);
1.488 raeburn 743: my $extension = (split(/\./,$env{'docs.markedcopy_url'}))[-1];
744: if ($env{'docs.markedcopy_url'} =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//} ) {
745: $is_external = 1;
746: }
747:
1.527 raeburn 748: my ($canpaste,$nopaste,$othercrs,$areachange);
1.488 raeburn 749: if ($folder =~ /^supplemental/) {
1.492 raeburn 750: $canpaste = &supp_pasteable($env{'docs.markedcopy_url'});
751: unless ($canpaste) {
752: $nopaste = &mt('Paste into Supplemental Content unavailable for this type of content.');
753: }
1.488 raeburn 754: } else {
755: $canpaste = 1;
756: }
757:
758: if ($canpaste) {
1.492 raeburn 759: if ($env{'docs.markedcopy_url'} =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
760: my $srcdom = $1;
761: my $srcnum = $2;
762: my $rem = $3;
763: if (($srcdom ne $coursedom) || ($srcnum ne $coursenum)) {
764: $othercourse = 1;
765: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
766: if ($canpaste) {
767: $othercrs = '<br />'.&mt('(from another course).');
768: }
769: } else {
770: $canpaste = 0;
771: $nopaste = &mt('Paste from another course unavailable.')
772: }
773: }
774: if ($rem =~ m{^(default|supplemental)_?(\d*)\.(?:page|sequence)$}) {
775: my $prefix = $1;
776: $parent = $2;
777: if ($folder !~ /^\Q$prefix\E/) {
778: $areachange = 1;
779: }
780: $is_uploaded_map = 1;
781: }
782: }
1.488 raeburn 783: }
784:
1.381 bisitz 785: $r->print('<fieldset>'
1.492 raeburn 786: .'<legend>'.&mt('Clipboard').'</legend>');
787: my ($type,$buffer);
1.488 raeburn 788: if ($is_external) {
1.492 raeburn 789: $type = &mt('External Resource');
790: $buffer = $type.': '.
791: &LONCAPA::map::qtescape($env{'docs.markedcopy_title'}).' ('.
792: &LONCAPA::map::qtescape($env{'docs.markedcopy_url'}).')';
1.533 raeburn 793: } else {
1.492 raeburn 794: my $icon = &Apache::loncommon::icon($extension);
795: if ($extension eq 'sequence' &&
796: $env{'docs.markedcopy_url'} =~ m{/default_\d+\.sequence$ }x) {
797: $icon = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
798: $icon .= '/navmap.folder.closed.gif';
799: }
800: $icon = '<img src="'.$icon.'" alt="" class="LC_icon" />';
801: $buffer = $icon.$type.': '. &Apache::loncommon::parse_supplemental_title(&LONCAPA::map::qtescape($env{'docs.markedcopy_title'}));
1.329 droeschl 802: }
1.488 raeburn 803: if ($canpaste) {
1.492 raeburn 804: $r->print('<form name="pasteform" action="/adm/coursedocs" method="post">'.$buffer);
1.533 raeburn 805: if ((!$areachange) && (!$othercourse) &&
806: ($env{'docs.markedcopy_cmd'} eq 'cut')) {
807: if (($is_uploaded_map) ||
808: ($env{'docs.markedcopy_url'} =~ /(bulletinboard|smppg)$/) ||
809: ($env{'docs.markedcopy_url'} =~ m{^/uploaded/$coursedom/$coursenum/(?:docs|supplemental)/(.+)$})) {
810: my ($copytext,$movetext);
811: if ($is_uploaded_map) {
812: $copytext = &mt('Copy to new folder');
813: $movetext = &mt('Move old folder');
814: } elsif ($env{'docs.markedcopy_url'} =~ /bulletinboard$/) {
815: $copytext = &mt('Copy to new bulletin board (not posts)');
816: $movetext = &mt('Move old bulletin board (not posts)');
817: } elsif ($env{'docs.markedcopy_url'} =~ /smppg$/) {
818: $copytext = &mt('Copy to new simple page');
819: $movetext = &mt('Move old simple page');
820: } else {
821: $copytext = &mt('Copy to new uploaded document');
822: $movetext = &mt('Move old uploaded document');
823: }
1.492 raeburn 824: $r->print((' 'x 4).'<span id="pasteoptionstext">'.
825: '<a href="javascript:showPasteOptions();" class="LC_menubuttons_link">'.
826: &mt('Show Paste Options').'</a></span><br />'.
827: '<div id="pasteoptions" class="LC_dccid">'.(' 'x 4).
828: '<label>'.
829: '<input type="radio" name="docs.markedcopy_options" value="new" checked="checked" />'.
1.533 raeburn 830: $copytext.'</label>'.(' ' x2).
1.492 raeburn 831: '<label>'.
832: '<input type="radio" name="docs.markedcopy_options" value="move" />'.
1.533 raeburn 833: $movetext.'</label><br />');
834: if (($is_uploaded_map) && ($env{'docs.markedcopy_nested'})) {
1.492 raeburn 835: $r->print('<br />'.&mt('Folder to paste contains sub-folders').
836: '<br /><table border="0">');
837: my @pastemaps = split(/\&/,$env{'docs.markedcopy_nested'});
838: my @titles = split(/\Q___&&&___\E/,$env{'docs.markedcopy_nestednames'});
839: my $lastdir = $parent;
840: my %depths = (
841: $lastdir => 0,
842: );
843: my (%display,%deps);
844: for (my $i=0; $i<@pastemaps; $i++) {
845: ($lastdir,my $subfolderstr) = split(/\:/,$pastemaps[$i]);
846: my ($namedir,$esctitlestr) = split(/\:/,$titles[$i]);
847: my @subfolders = split(/,/,$subfolderstr);
848: $deps{$lastdir} = \@subfolders;
849: my @subfoldertitles = map { &unescape($_); } split(/,/,$esctitlestr);
850: my $depth = $depths{$lastdir} + 1;
851: my $offset = int($depth * 4);
852: my $indent = (' ' x $offset);
853: for (my $j=0; $j<@subfolders; $j++) {
854: $depths{$subfolders[$j]} = $depth;
855: $display{$subfolders[$j]} =
856: '<tr><td>'.$indent.$subfoldertitles[$j].' </td>'.
857: '<td><label>'.
858: '<input type="radio" name="docs.markedcopy_'.$subfolders[$j].'" value="new" checked="checked" />'.&mt('Copy to new').'</label>'.(' ' x2).
859: '<label>'.
860: '<input type="radio" name="docs.markedcopy_'.$subfolders[$j].'" value="move" />'.
861: &mt('Move old').'</label>'.
862: '</td></tr>';
863: }
864: }
865: &recurse_print($r,$parent,\%deps,\%display);
866: $r->print('</table>');
867: }
868: $r->print('</div>');
869: }
870: }
871: $r->print('<br /><input type="submit" name="pastemarked" value="'.&mt('Paste').'" />'.$othercrs);
1.519 raeburn 872: $r->print('
1.329 droeschl 873: <input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />
874: ');
1.488 raeburn 875: $r->print('</form>');
876: } else {
1.492 raeburn 877: $r->print(&mt('Paste buffer contains:').' '.$buffer.
878: '<br /><p class="LC_info">'.$nopaste.'</p>');
1.329 droeschl 879: }
1.488 raeburn 880: $r->print('</fieldset>');
881: }
882:
1.492 raeburn 883: sub recurse_print {
884: my ($r,$dir,$deps,$display) = @_;
885: $r->print($display->{$dir}."\n");
886: if (ref($deps->{$dir}) eq 'ARRAY') {
887: foreach my $subdir (@{$deps->{$dir}}) {
888: &recurse_print($r,$subdir,$deps,$display);
889: }
890: }
891: }
892:
1.488 raeburn 893: sub supp_pasteable {
894: my ($url) = @_;
895: if (($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//}) ||
896: (($url =~ /\.sequence$/) && ($url =~ m{^/uploaded/})) ||
897: ($url =~ m{^/uploaded/$match_domain/$match_courseid/(docs|supplemental)/(default|\d+)/\d+/}) ||
898: ($url =~ m{^/adm/$match_domain/$match_username/aboutme}) ||
899: ($url =~ m{^/public/$match_domain/$match_courseid/syllabus})) {
900: return 1;
901: }
902: return;
1.329 droeschl 903: }
904:
1.492 raeburn 905: sub paste_popup_js {
906: my %lt = &Apache::lonlocal::texthash(
907: show => 'Show Paste Options',
908: hide => 'Hide Paste Options',
909: );
910: return <<"END";
911:
912: function showPasteOptions() {
913: document.getElementById('pasteoptions').style.display='block';
914: document.getElementById('pasteoptions').style.textAlign='left';
915: document.getElementById('pasteoptions').style.textFace='normal';
916: document.getElementById('pasteoptionstext').innerHTML ='<a href="javascript:hidePasteOptions();" class="LC_menubuttons_link">$lt{'hide'}</a><br />';
917: return;
918: }
919:
920: function hidePasteOptions() {
921: document.getElementById('pasteoptions').style.display='none';
922: document.getElementById('pasteoptionstext').innerHTML ='<a href="javascript:showPasteOptions()" class="LC_menubuttons_link">$lt{'show'}</a>';
923: return;
924: }
925:
926: END
927:
928: }
929:
930:
1.329 droeschl 931: sub do_paste_from_buffer {
1.492 raeburn 932: my ($coursenum,$coursedom,$folder,$container,$errors) = @_;
1.329 droeschl 933:
1.492 raeburn 934: # Early out if paste buffer is empty
1.329 droeschl 935: if (!$env{'form.pastemarked'}) {
1.492 raeburn 936: return ();
1.329 droeschl 937: }
938:
1.492 raeburn 939: # Supplemental content may only include certain types of content
940: # Early out if pasted content is not supported in Supplemental area
941: if ($folder =~ /^supplemental/) {
942: unless (&supp_pasteable($env{'docs.markedcopy_url'})) {
943: return (&mt('Paste failed: content type is not supported within Supplemental Content'));
944: }
945: }
946:
947: # Prepare to paste resource at end of list
1.491 raeburn 948: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url'});
949: my $title=&LONCAPA::map::qtescape($env{'docs.markedcopy_title'});
950:
1.492 raeburn 951: my ($is_map,$srcdom,$srcnum,$prefixchg,%before,%after,%mapchanges,%tomove);
1.491 raeburn 952: if ($url=~/\.(page|sequence)$/) {
953: $is_map = 1;
954: }
955: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/([^/]+)}) {
956: $srcdom = $1;
957: $srcnum = $2;
958: my $oldprefix = $3;
1.492 raeburn 959: # When paste buffer was populated using an active role in a different course
960: # check for mdc privilege in the course from which the resource was pasted
1.491 raeburn 961: if (($srcdom ne $coursedom) || ($srcnum ne $coursenum)) {
962: unless ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1.492 raeburn 963: return (&mt('Paste failed: Item is from a different course which you do not have rights to edit.'));
1.491 raeburn 964: }
965: }
1.492 raeburn 966: # When pasting content from Main Content to Supplemental Content and vice versa
967: # URLs will contain different paths (which depend on whether pasted item is
968: # a folder/page or a document.
1.491 raeburn 969: if (($folder =~ /^supplemental/) && (($oldprefix =~ /^default/) || ($oldprefix eq 'docs'))) {
970: $prefixchg = 1;
971: %before = ( map => 'default',
972: doc => 'docs');
973: %after = ( map => 'supplemental',
974: doc => 'supplemental' );
975: } elsif (($folder =~ /^default/) && ($oldprefix =~ /^supplemental/)) {
976: $prefixchg = 1;
977: %before = ( map => 'supplemental',
978: doc => 'supplemental');
979: %after = ( map => 'default',
980: doc => 'docs');
981: }
982:
1.492 raeburn 983: # If pasting an uploaded map, get list of contained uploaded maps.
984: my @nested;
985: if ($env{'docs.markedcopy_nested'}) {
986: my ($type) = ($oldprefix =~ /^(default|supplemental)/);
987: my @items = split(/\&/,$env{'docs.markedcopy_nested'});
988: my @deps = map { /\d+:([\d,]+$)/ } @items;
989: foreach my $dep (@deps) {
990: if ($dep =~ /,/) {
991: push(@nested,split(/,/,$dep));
992: } else {
993: push(@nested,$dep);
994: }
995: }
996: foreach my $item (@nested) {
997: if ($env{'form.docs.markedcopy_'.$item} eq 'move') {
998: $tomove{$type.'_'.$item} = 1;
999: }
1000: }
1.488 raeburn 1001: }
1002: }
1003:
1.329 droeschl 1004: # Maps need to be copied first
1.492 raeburn 1005: my ($oldurl,%removefrommap,%removeparam,%addedmaps,%rewrites,%retitles,%copies,
1006: %dbcopies,%zombies,%params,%docmoves,%mapmoves,%newsubdir,%newurls);
1.489 raeburn 1007: $oldurl = $url;
1.491 raeburn 1008: if ($is_map) {
1009: # If pasting a map, check if map contains other maps
1.529 raeburn 1010: my ($allmaps,%hierarchy,%titles);
1011: $allmaps = {};
1.491 raeburn 1012: if ($folder =~ /^default/) {
1.529 raeburn 1013: $allmaps =
1014: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
1015: $env{"course.$env{'request.course.id'}.home"},
1016: $env{'request.course.id'});
1.488 raeburn 1017: }
1.492 raeburn 1018: &contained_map_check($url,$folder,\%removefrommap,\%removeparam,
1.529 raeburn 1019: \%addedmaps,\%hierarchy,\%titles,$allmaps);
1.488 raeburn 1020: if ($url=~ m{^/uploaded/}) {
1.492 raeburn 1021: my $newurl;
1022: unless ($env{'form.docs.markedcopy_options'} eq 'move') {
1023: ($newurl,my $error) =
1024: &get_newmap_url($url,$folder,$prefixchg,$coursedom,$coursenum,
1.529 raeburn 1025: $srcdom,$srcnum,\$title,$allmaps,\%newurls);
1.492 raeburn 1026: if ($error) {
1027: return ($error);
1028: }
1029: if ($newurl ne '') {
1030: if ($newurl ne $url) {
1031: if ($newurl =~ /(?:default|supplemental)_(\d+).(?:sequence|page)$/) {
1032: $newsubdir{$url} = $1;
1033: }
1034: $mapchanges{$url} = 1;
1035: }
1.491 raeburn 1036: }
1037: }
1.492 raeburn 1038: if (($srcdom ne $coursedom) || ($srcnum ne $coursenum) || ($prefixchg) ||
1039: (($newurl ne '') && ($newurl ne $url))) {
1.533 raeburn 1040: unless (&url_paste_fixups($url,$folder,$prefixchg,$coursedom,
1041: $coursenum,$srcdom,$srcnum,$allmaps,
1042: \%rewrites,\%retitles,\%copies,\%dbcopies,
1.492 raeburn 1043: \%zombies,\%params,\%mapmoves,\%mapchanges,\%tomove,
1044: \%newsubdir,\%newurls)) {
1045: $mapmoves{$url} = 1;
1046: }
1047: $url = $newurl;
1048: } elsif ($env{'docs.markedcopy_nested'}) {
1.533 raeburn 1049: &url_paste_fixups($url,$folder,$prefixchg,$coursedom,$coursenum,
1050: $srcdom,$srcnum,$allmaps,\%rewrites,
1.492 raeburn 1051: \%retitles,\%copies,\%dbcopies,\%zombies,\%params,\%mapmoves,
1052: \%mapchanges,\%tomove,\%newsubdir,\%newurls);
1.329 droeschl 1053: }
1.488 raeburn 1054: } elsif ($url=~m {^/res/}) {
1055: # published maps can only exists once, so remove it from paste buffer when done
1056: &Apache::lonnet::delenv('docs.markedcopy');
1.492 raeburn 1057: # if pasting published map (main content are only) check map is not already in course
1058: if ($folder =~ /^default/) {
1.529 raeburn 1059: if ((ref($allmaps) eq 'HASH') && ($allmaps->{$url})) {
1.492 raeburn 1060: return (&mt('Paste failed: only one instance of a particular published sequence or page is allowed within each course.'));
1.491 raeburn 1061: }
1.489 raeburn 1062: }
1063: }
1.329 droeschl 1064: }
1.533 raeburn 1065: my $lockerrors;
1066: if ($url=~ m{/(bulletinboard|smppg)$}) {
1067: my $prefix = $1;
1068: #need to copy the db contents to a new one, unless this is a move.
1069: my %info = (
1070: src => $url,
1071: cdom => $coursedom,
1072: cnum => $coursenum,
1073: );
1074: my (%lockerr,$msg);
1075: unless ($env{'form.docs.markedcopy_options'} eq 'move') {
1076: my ($newurl,$result,$errtext) =
1077: &dbcopy(\%info,$coursedom,$coursenum,\%lockerr);
1078: if ($result eq 'ok') {
1079: $url = $newurl;
1.491 raeburn 1080: $title=&mt('Copy of').' '.$title;
1081: } else {
1.533 raeburn 1082: if ($prefix eq 'smppg') {
1083: $msg = &mt('Paste failed: An error occurred when copying the simple page.').' '.$errtext;
1084: } elsif ($prefix eq 'bulletinboard') {
1085: $msg = &mt('Paste failed: An error occurred when copying the bulletin board.').' '.$errtext;
1086: }
1087: return ($result,undef,[$msg],$lockerr{$prefix});
1088: }
1089: if ($lockerr{$prefix}) {
1090: $lockerrors = $lockerr{$prefix};
1.491 raeburn 1091: }
1.533 raeburn 1092: }
1.329 droeschl 1093: }
1094: $title = &LONCAPA::map::qtunescape($title);
1095: my $ext='false';
1096: if ($url=~m{^http(|s)://}) { $ext='true'; }
1097: $url = &LONCAPA::map::qtunescape($url);
1.491 raeburn 1098:
1099: # For uploaded files (excluding pages/sequences) path in copied file is changed
1100: # if paste is from Main to Supplemental (or vice versa), or if pasting between
1101: # courses.
1102:
1.492 raeburn 1103: my $newidx;
1.491 raeburn 1104: unless ($is_map) {
1.492 raeburn 1105: # Now insert the URL at the bottom
1106: $newidx = &LONCAPA::map::getresidx($url);
1.491 raeburn 1107: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(.+)$}) {
1108: my $relpath = $1;
1109: if ($relpath ne '') {
1110: my ($prefix,$subdir,$rem) = ($relpath =~ m{^(default|\d+)/(\d+)/(.+)$});
1.492 raeburn 1111: my ($newloc,$newdocsdir) = ($folder =~ /^(default|supplemental)_?(\d*)/);
1.491 raeburn 1112: my $newprefix = $newloc;
1113: if ($newloc eq 'default') {
1114: $newprefix = 'docs';
1115: }
1.492 raeburn 1116: if ($newdocsdir eq '') {
1117: $newdocsdir = 'default';
1.491 raeburn 1118: }
1.533 raeburn 1119: if (($prefixchg) ||
1120: ($srcdom ne $coursedom) || ($srcnum ne $coursenum) ||
1121: ($env{'form.docs.markedcopy_options'} ne 'move')) {
1.492 raeburn 1122: my $newpath = "$newprefix/$newdocsdir/$newidx/$rem";
1.491 raeburn 1123: $url =
1124: &Apache::lonclonecourse::writefile($env{'request.course.id'},$newpath,
1125: &Apache::lonnet::getfile($oldurl));
1126: if ($url eq '/adm/notfound.html') {
1.492 raeburn 1127: return (&mt('Paste failed: an error occurred saving the file.'));
1.491 raeburn 1128: } else {
1129: my ($newsubpath) = ($newpath =~ m{^(.*/)[^/]*$});
1130: $newsubpath =~ s{/+$}{/};
1131: $docmoves{$oldurl} = $newsubpath;
1132: }
1133: }
1134: }
1.488 raeburn 1135: }
1.491 raeburn 1136: }
1.492 raeburn 1137: # Apply any changes to maps, or copy dependencies for uploaded HTML pages
1138: my ($result,$save_err);
1.529 raeburn 1139: my %updated = (
1140: rewrites => \%rewrites,
1141: zombies => \%zombies,
1142: removefrommap => \%removefrommap,
1143: removeparam => \%removeparam,
1144: dbcopies => \%dbcopies,
1145: retitles => \%retitles,
1146: );
1147: my %info = (
1148: newsubdir => \%newsubdir,
1149: params => \%params,
1150: before => \%before,
1151: after => \%after,
1152: );
1153: my %moves = (
1154: copies => \%copies,
1155: docmoves => \%docmoves,
1156: mapmoves => \%mapmoves,
1.530 raeburn 1157: );
1.533 raeburn 1158: ($result,my $msgsarray,my $lockerror) =
1.529 raeburn 1159: &apply_fixups($folder,$is_map,$coursedom,$coursenum,$errors,
1160: \%updated,\%info,\%moves,$prefixchg,$oldurl,$url,'paste');
1.533 raeburn 1161: $lockerrors .= $lockerror;
1.491 raeburn 1162: if ($result eq 'ok') {
1.492 raeburn 1163: if ($is_map) {
1164: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
1165: $folder.'.'.$container);
1.533 raeburn 1166: return ($errtext,$save_err,$msgsarray,$lockerrors) if ($fatal);
1.492 raeburn 1167:
1168: if ($#LONCAPA::map::order<1) {
1169: my $idx=&LONCAPA::map::getresidx();
1170: if ($idx<=0) { $idx=1; }
1171: $LONCAPA::map::order[0]=$idx;
1172: $LONCAPA::map::resources[$idx]='';
1173: }
1174: $newidx = &LONCAPA::map::getresidx($url);
1175: }
1.491 raeburn 1176: if ($env{'docs.markedcopy_supplemental'}) {
1.492 raeburn 1177: if ($folder !~ /^supplemental/) {
1.491 raeburn 1178: (undef,undef,$title) =
1179: &Apache::loncommon::parse_supplemental_title($env{'docs.markedcopy_supplemental'});
1.489 raeburn 1180: }
1.329 droeschl 1181: } else {
1.491 raeburn 1182: if ($folder=~/^supplemental/) {
1183: $title=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
1184: $env{'user.domain'}.'___&&&___'.$title;
1185: }
1.329 droeschl 1186: }
1.491 raeburn 1187: $LONCAPA::map::resources[$newidx]= $title.':'.$url.':'.$ext.':normal:res';
1188: push(@LONCAPA::map::order, $newidx);
1.492 raeburn 1189:
1190: # Store the result
1191: my ($errtext,$fatal) =
1192: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1193: if ($fatal) {
1194: $save_err = $errtext;
1195: }
1196: }
1.533 raeburn 1197:
1.492 raeburn 1198: if ($env{'form.docs.markedcopy_options'} eq 'move') {
1199: &Apache::lonnet::delenv('docs.markedcopy');
1200: &Apache::lonnet::delenv('docs.markedcopy_nested');
1201: &Apache::lonnet::delenv('docs.markedcopy_nestednames');
1202: }
1.533 raeburn 1203: return ($result,$save_err,$msgsarray,$lockerrors);
1.492 raeburn 1204: }
1205:
1206: sub get_newmap_url {
1207: my ($url,$folder,$prefixchg,$coursedom,$coursenum,$srcdom,$srcnum,
1208: $titleref,$allmaps,$newurls) = @_;
1209: my $newurl;
1210: if ($url=~ m{^/uploaded/}) {
1211: $$titleref=&mt('Copy of').' '.$$titleref;
1212: }
1213: my $now = time;
1214: my $suffix=$$.int(rand(100)).$now;
1215: my ($oldid,$ext) = ($url=~/^(.+)\.(\w+)$/);
1216: if ($oldid =~ m{^(/uploaded/$match_domain/$match_courseid/)(\D+)(\d+)$}) {
1217: my $path = $1;
1218: my $prefix = $2;
1219: my $ancestor = $3;
1220: if (length($ancestor) > 10) {
1221: $ancestor = substr($ancestor,-10,10);
1222: }
1223: my $newid;
1224: if ($prefixchg) {
1225: if ($folder =~ /^supplemental/) {
1226: $prefix =~ s/^default/supplemental/;
1227: } else {
1228: $prefix =~ s/^supplemental/default/;
1229: }
1230: }
1231: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
1232: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
1233: } else {
1234: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$now.'.'.$ext;
1235: }
1236: my $counter = 0;
1237: my $is_unique = &uniqueness_check($newurl);
1238: if ($folder =~ /^default/) {
1239: if ($allmaps->{$newurl}) {
1240: $is_unique = 0;
1241: }
1242: }
1243: while ((!$is_unique || $allmaps->{$newurl} || $newurls->{$newurl}) && ($counter < 100)) {
1244: $counter ++;
1245: $suffix ++;
1246: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
1247: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
1248: } else {
1249: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$ancestor.$suffix.'.'.$ext;
1250: }
1251: $is_unique = &uniqueness_check($newurl);
1252: }
1253: if ($is_unique) {
1254: $newurls->{$newurl} = 1;
1255: } else {
1256: if ($url=~/\.page$/) {
1257: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the composite page'));
1258: } else {
1259: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the folder'));
1260: }
1261: }
1.329 droeschl 1262: }
1.492 raeburn 1263: return ($newurl);
1.329 droeschl 1264: }
1265:
1.488 raeburn 1266: sub dbcopy {
1.533 raeburn 1267: my ($dbref,$coursedom,$coursenum,$lockerrorsref) = @_;
1268: my ($url,$result,$errtext);
1269: my $url = $dbref->{'src'};
1270: if (ref($dbref) eq 'HASH') {
1271: if ($url =~ m{/(smppg|bulletinboard)$}) {
1272: my $prefix = $1;
1273: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
1274: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
1275: my $db_name;
1276: my $marker = (split(m{/},$url))[4];
1277: $marker=~s/\D//g;
1278: if ($dbref->{'src'} =~ m{/smppg$}) {
1279: $db_name =
1280: &Apache::lonsimplepage::get_db_name($url,$marker,
1281: $dbref->{'cdom'},
1282: $dbref->{'cnum'});
1283: } else {
1284: $db_name = 'bulletinpage_'.$marker;
1285: }
1286: my ($suffix,$freedlock,$error) =
1287: &Apache::lonnet::get_timebased_id($prefix,'num','templated',
1288: $coursedom,$coursenum,
1289: 'concat');
1290: if (!$suffix) {
1291: if ($prefix eq 'smppg') {
1292: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a simple page [_1].',$url);
1293: } else {
1294: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a bulletin board [_1].',$url);
1295: }
1296: if ($error) {
1297: $errtext .= '<br />'.$error;
1298: }
1299: } else {
1300: #need to copy the db contents to a new one.
1301: my %contents=&Apache::lonnet::dump($db_name,
1302: $dbref->{'cdom'},
1303: $dbref->{'cnum'});
1304: if (exists($contents{'uploaded.photourl'})) {
1305: my $photo = $contents{'uploaded.photourl'};
1306: my ($subdir,$fname) =
1307: ($photo =~ m{^/uploaded/$match_domain/$match_courseid/+(bulletin|simplepage)/(?:|\d+/)([^/]+)$});
1308: my $newphoto;
1309: if ($fname ne '') {
1310: my $content = &Apache::lonnet::getfile($photo);
1311: unless ($content eq '-1') {
1312: $env{'form.'.$suffix.'.photourl'} = $content;
1313: $newphoto =
1314: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,$suffix.'.photourl',"$subdir/$suffix/$fname");
1315: delete($env{'form.'.$suffix.'.photourl'});
1316: }
1317: }
1318: if ($newphoto =~ m{^/uploaded/}) {
1319: $contents{'uploaded.photourl'} = $newphoto;
1320: }
1321: }
1322: $db_name =~ s{_\d*$ }{_$suffix}x;
1323: $result=&Apache::lonnet::put($db_name,\%contents,
1324: $coursedom,$coursenum);
1325: if ($result eq 'ok') {
1326: $url =~ s{/(\d*)/(smppg|bulletinboard)$}{/$suffix/$2}x;
1327: }
1328: }
1329: if (($freedlock ne 'ok') && (ref($lockerrorsref) eq 'HASH')) {
1330: $lockerrorsref->{$prefix} =
1331: '<div class="LC_error">'.
1332: &mt('There was a problem removing a lockfile.');
1333: if ($prefix eq 'smppg') {
1334: $lockerrorsref->{$prefix} .=
1335: &mt('This will prevent creation of additional simple pages in this course.');
1336: } else {
1337: $lockerrorsref->{$prefix} .= &mt('This will prevent creation of additional bulletin boards in this course.');
1338: }
1339: $lockerrorsref->{$prefix} .= &mt('Please contact the domain coordinator for your LON-CAPA domain.').'</div>';
1340: }
1341: }
1342: } elsif ($url =~ m{/syllabus$}) {
1343: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
1344: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
1345: if (($dbref->{'cdom'} ne $coursedom) ||
1346: ($dbref->{'cnum'} ne $coursenum)) {
1347: my %contents=&Apache::lonnet::dump('syllabus',
1348: $dbref->{'cdom'},
1349: $dbref->{'cnum'});
1350: $result=&Apache::lonnet::put('syllabus',\%contents,
1351: $coursedom,$coursenum);
1352: }
1353: }
1.488 raeburn 1354: }
1355: }
1.533 raeburn 1356: return ($url,$result,$errtext);
1.488 raeburn 1357: }
1358:
1.329 droeschl 1359: sub uniqueness_check {
1360: my ($newurl) = @_;
1361: my $unique = 1;
1362: foreach my $res (@LONCAPA::map::order) {
1363: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
1364: $url=&LONCAPA::map::qtescape($url);
1365: if ($newurl eq $url) {
1366: $unique = 0;
1.344 bisitz 1367: last;
1.329 droeschl 1368: }
1369: }
1370: return $unique;
1371: }
1372:
1.488 raeburn 1373: sub contained_map_check {
1.492 raeburn 1374: my ($url,$folder,$removefrommap,$removeparam,$addedmaps,$hierarchy,$titles,
1375: $allmaps) = @_;
1.488 raeburn 1376: my $content = &Apache::lonnet::getfile($url);
1377: unless ($content eq '-1') {
1378: my $parser = HTML::TokeParser->new(\$content);
1379: $parser->attr_encoded(1);
1380: while (my $token = $parser->get_token) {
1381: next if ($token->[0] ne 'S');
1382: if ($token->[1] eq 'resource') {
1383: next if ($token->[2]->{'type'} eq 'zombie');
1384: my $ressrc = $token->[2]->{'src'};
1385: if ($folder =~ /^supplemental/) {
1386: unless (&supp_pasteable($ressrc)) {
1.492 raeburn 1387: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.488 raeburn 1388: next;
1389: }
1390: }
1.492 raeburn 1391: if ($ressrc =~ m{^/(res|uploaded)/.+\.(sequence|page)$}) {
1392: if ($1 eq 'uploaded') {
1393: $hierarchy->{$url}{$token->[2]->{'id'}} = $ressrc;
1394: $titles->{$url}{$token->[2]->{'id'}} = $token->[2]->{'title'};
1.488 raeburn 1395: } else {
1.492 raeburn 1396: if ($allmaps->{$ressrc}) {
1.529 raeburn 1397: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.492 raeburn 1398: } elsif (ref($addedmaps->{$ressrc}) eq 'ARRAY') {
1399: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1400: } else {
1401: $addedmaps->{$ressrc} = [$url];
1402: }
1.488 raeburn 1403: }
1.492 raeburn 1404: &contained_map_check($ressrc,$folder,$removefrommap,$removeparam,
1405: $addedmaps,$hierarchy,$titles,$allmaps);
1.488 raeburn 1406: }
1.492 raeburn 1407: } elsif ($token->[1] eq 'param') {
1.488 raeburn 1408: if ($folder =~ /^supplemental/) {
1.492 raeburn 1409: if (ref($removeparam->{$url}{$token->[2]->{'to'}}) eq 'ARRAY') {
1410: push(@{$removeparam->{$url}{$token->[2]->{'to'}}},$token->[2]->{'name'});
1411: } else {
1412: $removeparam->{$url}{$token->[2]->{'to'}} = [$token->[2]->{'name'}];
1413: }
1.488 raeburn 1414: }
1415: }
1416: }
1417: }
1418: return;
1419: }
1420:
1421: sub url_paste_fixups {
1.533 raeburn 1422: my ($oldurl,$folder,$prefixchg,$cdom,$cnum,$fromcdom,$fromcnum,$allmaps,
1423: $rewrites,$retitles,$copies,$dbcopies,$zombies,$params,$mapmoves,
1424: $mapchanges,$tomove,$newsubdir,$newurls) = @_;
1.491 raeburn 1425: my $checktitle;
1426: if (($prefixchg) &&
1.492 raeburn 1427: ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/supplemental})) {
1.491 raeburn 1428: $checktitle = 1;
1429: }
1.492 raeburn 1430: my $skip;
1431: if ($oldurl =~ m{^\Q/uploaded/$cdom/$cnum/\E(default|supplemental)(_?\d*)\.(?:page|sequence)$}) {
1432: my $mapid = $1.$2;
1433: if ($tomove->{$mapid}) {
1434: $skip = 1;
1435: }
1436: }
1.491 raeburn 1437: my $file = &Apache::lonnet::getfile($oldurl);
1.488 raeburn 1438: return if ($file eq '-1');
1439: my $parser = HTML::TokeParser->new(\$file);
1440: $parser->attr_encoded(1);
1.491 raeburn 1441: my $changed = 0;
1.488 raeburn 1442: while (my $token = $parser->get_token) {
1443: next if ($token->[0] ne 'S');
1444: if ($token->[1] eq 'resource') {
1445: my $ressrc = $token->[2]->{'src'};
1446: next if ($ressrc eq '');
1.491 raeburn 1447: my $id = $token->[2]->{'id'};
1.492 raeburn 1448: my $title = $token->[2]->{'title'};
1.491 raeburn 1449: if ($checktitle) {
1450: if ($title =~ m{\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
1.532 raeburn 1451: $retitles->{$oldurl}{$id} = $ressrc;
1.491 raeburn 1452: }
1453: }
1.488 raeburn 1454: next if ($token->[2]->{'type'} eq 'external');
1455: if ($token->[2]->{'type'} eq 'zombie') {
1.492 raeburn 1456: next if ($skip);
1.532 raeburn 1457: $zombies->{$oldurl}{$id} = $ressrc;
1.491 raeburn 1458: $changed = 1;
1459: } elsif ($ressrc =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
1.492 raeburn 1460: my $srcdom = $1;
1461: my $srcnum = $2;
1.488 raeburn 1462: my $rem = $3;
1.492 raeburn 1463: my $newurl;
1464: my $mapname;
1465: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
1466: my $prefix = $1;
1467: $mapname = $prefix.$2;
1468: if ($tomove->{$mapname}) {
1.533 raeburn 1469: &url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,$cnum,
1470: $srcdom,$srcnum,$allmaps,$rewrites,
1471: $retitles,$copies,$dbcopies,$zombies,
1472: $params,$mapmoves,$mapchanges,$tomove,
1473: $newsubdir,$newurls);
1.492 raeburn 1474: next;
1475: } else {
1476: ($newurl,my $error) =
1477: &get_newmap_url($ressrc,$folder,$prefixchg,$cdom,$cnum,
1478: $srcdom,$srcnum,\$title,$allmaps,$newurls);
1479: if ($newurl =~ /(?:default|supplemental)_(\d+)\.(?:sequence|page)$/) {
1480: $newsubdir->{$ressrc} = $1;
1481: }
1482: if ($error) {
1483: next;
1484: }
1485: }
1486: }
1487: if (($srcdom ne $cdom) || ($srcnum ne $cnum) || ($prefixchg) ||
1488: ($mapchanges->{$oldurl}) || (($newurl ne '') && ($newurl ne $oldurl))) {
1489:
1.488 raeburn 1490: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
1.532 raeburn 1491: $rewrites->{$oldurl}{$id} = $ressrc;
1.491 raeburn 1492: $mapchanges->{$ressrc} = 1;
1.533 raeburn 1493: unless (&url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,
1494: $cnum,$srcdom,$srcnum,$allmaps,
1495: $rewrites,$retitles,$copies,$dbcopies,
1496: $zombies,$params,$mapmoves,$mapchanges,
1497: $tomove,$newsubdir,$newurls)) {
1.491 raeburn 1498: $mapmoves->{$ressrc} = 1;
1499: }
1500: $changed = 1;
1.488 raeburn 1501: } else {
1.532 raeburn 1502: $rewrites->{$oldurl}{$id} = $ressrc;
1.488 raeburn 1503: $copies->{$oldurl}{$ressrc} = $id;
1.491 raeburn 1504: $changed = 1;
1.488 raeburn 1505: }
1506: }
1.533 raeburn 1507: } elsif ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/.+$}) {
1508: next if ($skip);
1.492 raeburn 1509: my $srcdom = $1;
1510: my $srcnum = $2;
1511: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.532 raeburn 1512: $rewrites->{$oldurl}{$id} = $ressrc;
1.533 raeburn 1513: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
1514: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
1515: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
1516: $changed = 1;
1517: }
1518: } elsif ($ressrc =~ m{^/adm/$match_domain/$match_username/\d+/(smppg|bulletinboard)$}) {
1519: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum) ||
1520: ($env{'form.docs.markedcopy_options'} ne 'move')) {
1521: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
1522: $dbcopies->{$oldurl}{$id}{'cdom'} = $fromcdom;
1523: $dbcopies->{$oldurl}{$id}{'cnum'} = $fromcnum;
1.491 raeburn 1524: $changed = 1;
1.488 raeburn 1525: }
1526: } elsif ($ressrc =~ m{^/public/($match_domain)/($match_courseid)/(.+)$}) {
1.492 raeburn 1527: next if ($skip);
1528: my $srcdom = $1;
1529: my $srcnum = $2;
1530: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.533 raeburn 1531: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
1532: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
1533: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
1.491 raeburn 1534: $changed = 1;
1.488 raeburn 1535: }
1536: }
1537: } elsif ($token->[1] eq 'param') {
1.492 raeburn 1538: next if ($skip);
1.488 raeburn 1539: my $to = $token->[2]->{'to'};
1540: if ($to ne '') {
1541: if (ref($params->{$oldurl}{$to}) eq 'ARRAY') {
1.492 raeburn 1542: push(@{$params->{$oldurl}{$to}},$token->[2]->{'name'});
1.488 raeburn 1543: } else {
1544: @{$params->{$oldurl}{$to}} = ($token->[2]->{'name'});
1545: }
1546: }
1547: }
1548: }
1.491 raeburn 1549: return $changed;
1.488 raeburn 1550: }
1551:
1552: sub apply_fixups {
1.529 raeburn 1553: my ($folder,$is_map,$cdom,$cnum,$errors,$updated,$info,$moves,$prefixchg,
1554: $oldurl,$url,$caller) = @_;
1555: my (%rewrites,%zombies,%removefrommap,%removeparam,%dbcopies,%retitles,
1.533 raeburn 1556: %params,%newsubdir,%before,%after,%copies,%docmoves,%mapmoves,@msgs,
1557: %lockerrors,$lockmsg);
1.529 raeburn 1558: if (ref($updated) eq 'HASH') {
1559: if (ref($updated->{'rewrites'}) eq 'HASH') {
1560: %rewrites = %{$updated->{'rewrites'}};
1561: }
1562: if (ref($updated->{'zombies'}) eq 'HASH') {
1563: %zombies = %{$updated->{'zombies'}};
1564: }
1565: if (ref($updated->{'removefrommap'}) eq 'HASH') {
1566: %removefrommap = %{$updated->{'removefrommap'}};
1567: }
1568: if (ref($updated->{'removeparam'}) eq 'HASH') {
1569: %removeparam = %{$updated->{'removeparam'}};
1570: }
1571: if (ref($updated->{'dbcopies'}) eq 'HASH') {
1572: %dbcopies = %{$updated->{'dbcopies'}};
1573: }
1574: if (ref($updated->{'retitles'}) eq 'HASH') {
1575: %retitles = %{$updated->{'retitles'}};
1576: }
1577: }
1578: if (ref($info) eq 'HASH') {
1579: if (ref($info->{'newsubdir'}) eq 'HASH') {
1580: %newsubdir = %{$info->{'newsubdir'}};
1581: }
1582: if (ref($info->{'params'}) eq 'HASH') {
1583: %params = %{$info->{'params'}};
1584: }
1585: if (ref($info->{'before'}) eq 'HASH') {
1586: %before = %{$info->{'before'}};
1587: }
1588: if (ref($info->{'after'}) eq 'HASH') {
1589: %after = %{$info->{'after'}};
1590: }
1591: }
1592: if (ref($moves) eq 'HASH') {
1593: if (ref($moves->{'copies'}) eq 'HASH') {
1594: %copies = %{$moves->{'copies'}};
1595: }
1596: if (ref($moves->{'docmoves'}) eq 'HASH') {
1597: %docmoves = %{$moves->{'docmoves'}};
1598: }
1599: if (ref($moves->{'mapmoves'}) eq 'HASH') {
1600: %mapmoves = %{$moves->{'mapmoves'}};
1601: }
1602: }
1603: foreach my $key (keys(%copies),keys(%docmoves)) {
1.491 raeburn 1604: my @allcopies;
1.529 raeburn 1605: if (exists($copies{$key})) {
1606: if (ref($copies{$key}) eq 'HASH') {
1607: my %added;
1608: foreach my $innerkey (keys(%{$copies{$key}})) {
1609: if (($innerkey ne '') && (!$added{$innerkey})) {
1610: push(@allcopies,$innerkey);
1611: $added{$innerkey} = 1;
1612: }
1.491 raeburn 1613: }
1.529 raeburn 1614: undef(%added);
1.491 raeburn 1615: }
1616: }
1617: if ($key eq $oldurl) {
1.529 raeburn 1618: if ((exists($docmoves{$key}))) {
1.532 raeburn 1619: unless (grep(/^\Q$oldurl\E$/,@allcopies)) {
1.491 raeburn 1620: push(@allcopies,$oldurl);
1621: }
1622: }
1623: }
1624: if (@allcopies > 0) {
1625: foreach my $item (@allcopies) {
1.492 raeburn 1626: my ($relpath,$oldsubdir,$fname) =
1627: ($item =~ m{^(/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(default|\d+)/.*/)([^/]+)$});
1.491 raeburn 1628: if ($fname ne '') {
1629: my $content = &Apache::lonnet::getfile($item);
1630: unless ($content eq '-1') {
1631: my $storefn;
1.529 raeburn 1632: if (($key eq $oldurl) && (exists($docmoves{$key}))) {
1633: $storefn = $docmoves{$key};
1.491 raeburn 1634: } else {
1635: $storefn = $relpath;
1636: $storefn =~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 1637: if ($prefixchg && $before{'doc'} && $after{'doc'}) {
1638: $storefn =~ s/^\Q$before{'doc'}\E/$after{'doc'}/;
1.491 raeburn 1639: }
1.529 raeburn 1640: if ($newsubdir{$key}) {
1.532 raeburn 1641: $storefn =~ s#^(docs|supplemental)/\Q$oldsubdir\E/#$1/$newsubdir{$key}/#;
1.491 raeburn 1642: }
1643: }
1644: ©_dependencies($item,$storefn,$relpath,$errors,\$content);
1645: my $copyurl =
1646: &Apache::lonclonecourse::writefile($env{'request.course.id'},
1647: $storefn.$fname,$content);
1648: if ($copyurl eq '/adm/notfound.html') {
1.529 raeburn 1649: if (exists($docmoves{$oldurl})) {
1.491 raeburn 1650: return &mt('Paste failed: an error occurred copying the file.');
1651: } elsif (ref($errors) eq 'HASH') {
1652: $errors->{$item} = 1;
1.489 raeburn 1653: }
1654: }
1.488 raeburn 1655: }
1656: }
1.491 raeburn 1657: }
1658: }
1659: }
1.529 raeburn 1660: foreach my $key (keys(%mapmoves)) {
1.491 raeburn 1661: my $storefn=$key;
1662: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 1663: if ($prefixchg && $before{'map'} && $after{'map'}) {
1664: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.491 raeburn 1665: }
1.529 raeburn 1666: if ($newsubdir{$key}) {
1667: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.492 raeburn 1668: }
1.491 raeburn 1669: my $mapcontent = &Apache::lonnet::getfile($key);
1670: if ($mapcontent eq '-1') {
1671: if (ref($errors) eq 'HASH') {
1672: $errors->{$key} = 1;
1673: }
1674: } else {
1675: my $newmap =
1676: &Apache::lonclonecourse::writefile($env{'request.course.id'},$storefn,
1677: $mapcontent);
1678: if ($newmap eq '/adm/notfound.html') {
1679: if (ref($errors) eq 'HASH') {
1680: $errors->{$key} = 1;
1.489 raeburn 1681: }
1.488 raeburn 1682: }
1683: }
1684: }
1.491 raeburn 1685: my %updates;
1686: if ($is_map) {
1.529 raeburn 1687: if (ref($updated) eq 'HASH') {
1688: foreach my $type (keys(%{$updated})) {
1689: if (ref($updated->{$type}) eq 'HASH') {
1690: foreach my $key (keys(%{$updated->{$type}})) {
1691: $updates{$key} = 1;
1692: }
1693: }
1694: }
1.491 raeburn 1695: }
1696: foreach my $key (keys(%updates)) {
1.492 raeburn 1697: my (%torewrite,%toretitle,%toremove,%remparam,%currparam,%zombie,%newdb);
1.529 raeburn 1698: if (ref($rewrites{$key}) eq 'HASH') {
1699: %torewrite = %{$rewrites{$key}};
1.491 raeburn 1700: }
1.529 raeburn 1701: if (ref($retitles{$key}) eq 'HASH') {
1702: %toretitle = %{$retitles{$key}};
1.491 raeburn 1703: }
1.529 raeburn 1704: if (ref($removefrommap{$key}) eq 'HASH') {
1705: %toremove = %{$removefrommap{$key}};
1.491 raeburn 1706: }
1.529 raeburn 1707: if (ref($removeparam{$key}) eq 'HASH') {
1708: %remparam = %{$removeparam{$key}};
1.492 raeburn 1709: }
1.529 raeburn 1710: if (ref($zombies{$key}) eq 'HASH') {
1711: %zombie = %{$zombies{$key}};
1.491 raeburn 1712: }
1.529 raeburn 1713: if (ref($dbcopies{$key}) eq 'HASH') {
1.533 raeburn 1714: foreach my $idx (keys(%{$dbcopies{$key}})) {
1715: if (ref($dbcopies{$key}{$idx}) eq 'HASH') {
1716: my ($newurl,$result,$errtext) =
1717: &dbcopy($dbcopies{$key}{$idx},$cdom,$cnum,\%lockerrors);
1718: if ($result eq 'ok') {
1719: $newdb{$idx} = $newurl;
1720: } elsif (ref($errors) eq 'HASH') {
1721: $errors->{$key} = 1;
1722: }
1723: push(@msgs,$errtext);
1724: }
1.491 raeburn 1725: }
1726: }
1.529 raeburn 1727: if (ref($params{$key}) eq 'HASH') {
1728: %currparam = %{$params{$key}};
1.492 raeburn 1729: }
1730: my ($errtext,$fatal) = &LONCAPA::map::mapread($key);
1731: if ($fatal) {
1.533 raeburn 1732: return ($errtext);
1.492 raeburn 1733: }
1734: for (my $i=0; $i<@LONCAPA::map::zombies; $i++) {
1735: if (defined($LONCAPA::map::zombies[$i])) {
1736: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::zombies[$i]);
1.532 raeburn 1737: if ($zombie{$i} eq $src) {
1.492 raeburn 1738: undef($LONCAPA::map::zombies[$i]);
1739: }
1740: }
1741: }
1.529 raeburn 1742: for (my $i=0; $i<@LONCAPA::map::order; $i++) {
1743: my $idx = $LONCAPA::map::order[$i];
1744: if (defined($LONCAPA::map::resources[$idx])) {
1.492 raeburn 1745: my $changed;
1.529 raeburn 1746: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::resources[$idx]);
1747: if ((exists($toremove{$idx})) && ($toremove{$idx} eq $src)) {
1.492 raeburn 1748: splice(@LONCAPA::map::order,$i,1);
1.529 raeburn 1749: if (ref($currparam{$idx}) eq 'ARRAY') {
1750: foreach my $name (@{$currparam{$idx}}) {
1751: &LONCAPA::map::delparameter($idx,'parameter_'.$name);
1.492 raeburn 1752: }
1753: }
1754: next;
1755: }
1756: my $origsrc = $src;
1.532 raeburn 1757: if ((exists($toretitle{$idx})) && ($toretitle{$idx} eq $src)) {
1.492 raeburn 1758: if ($title =~ m{^\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
1759: $changed = 1;
1.491 raeburn 1760: }
1.492 raeburn 1761: }
1.532 raeburn 1762: if ((exists($torewrite{$idx})) && ($torewrite{$idx} eq $src)) {
1.492 raeburn 1763: $src =~ s{^/(uploaded|adm|public)/$match_domain/$match_courseid/}{/$1/$cdom/$cnum/};
1764: if ($origsrc =~ m{^/uploaded/}) {
1.529 raeburn 1765: if ($prefixchg && $before{'map'} && $after{'map'}) {
1.492 raeburn 1766: if ($src =~ /\.(page|sequence)$/) {
1.529 raeburn 1767: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'map'}\E#$1$after{'map'}#;
1.492 raeburn 1768: } else {
1.529 raeburn 1769: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'doc'}\E#$1$after{'doc'}#;
1.488 raeburn 1770: }
1.491 raeburn 1771: }
1.532 raeburn 1772: if ($origsrc =~ /\.(page|sequence)$/) {
1773: if ($newsubdir{$origsrc}) {
1.529 raeburn 1774: $src =~ s#^(/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_)(\d+)#$1$newsubdir{$origsrc}#;
1.491 raeburn 1775: }
1.532 raeburn 1776: } elsif ($newsubdir{$key}) {
1777: $src =~ s#^(/uploaded/$match_domain/$match_courseid/\w+/)(\d+)#$1$newsubdir{$key}#;
1.488 raeburn 1778: }
1779: }
1.492 raeburn 1780: $changed = 1;
1.533 raeburn 1781: } elsif ($newdb{$idx} ne '') {
1782: $src = $newdb{$idx};
1.492 raeburn 1783: $changed = 1;
1784: }
1785: if ($changed) {
1.529 raeburn 1786: $LONCAPA::map::resources[$idx] = join(':',($title,$src,$ext,$type));
1.492 raeburn 1787: }
1788: }
1789: }
1790: foreach my $idx (keys(%remparam)) {
1791: if (ref($remparam{$idx}) eq 'ARRAY') {
1792: foreach my $name (@{$remparam{$idx}}) {
1793: &LONCAPA::map::delparameter($idx,'parameter_'.$name);
1.491 raeburn 1794: }
1795: }
1796: }
1.533 raeburn 1797: if (values(%lockerrors) > 0) {
1798: $lockmsg = join('<br />',values(%lockerrors));
1799: }
1.491 raeburn 1800: my $storefn;
1801: if ($key eq $oldurl) {
1802: $storefn = $url;
1803: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1804: } else {
1805: $storefn = $key;
1806: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 1807: if ($prefixchg && $before{'map'} && $after{'map'}) {
1808: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.491 raeburn 1809: }
1.529 raeburn 1810: if ($newsubdir{$key}) {
1811: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.492 raeburn 1812: }
1.491 raeburn 1813: }
1.492 raeburn 1814: my $report;
1815: if ($folder !~ /^supplemental/) {
1816: $report = 1;
1817: }
1.527 raeburn 1818: (my $outtext,$errtext) =
1.492 raeburn 1819: &LONCAPA::map::storemap("/uploaded/$cdom/$cnum/$storefn",1,$report);
1820: if ($errtext) {
1.529 raeburn 1821: if ($caller eq 'paste') {
1.533 raeburn 1822: return (&mt('Paste failed: an error occurred saving the folder or page.'));
1.529 raeburn 1823: }
1.491 raeburn 1824: }
1825: }
1826: }
1.533 raeburn 1827: return ('ok',\@msgs,$lockmsg);
1.491 raeburn 1828: }
1829:
1830: sub copy_dependencies {
1831: my ($item,$storefn,$relpath,$errors,$contentref) = @_;
1832: my $content;
1833: if (ref($contentref)) {
1834: $content = $$contentref;
1835: } else {
1836: $content = &Apache::lonnet::getfile($item);
1837: }
1838: unless ($content eq '-1') {
1839: my $mm = new File::MMagic;
1840: my $mimetype = $mm->checktype_contents($content);
1841: if ($mimetype eq 'text/html') {
1842: my (%allfiles,%codebase,$state);
1843: my $res = &Apache::lonnet::extract_embedded_items(undef,\%allfiles,\%codebase,\$content);
1844: if ($res eq 'ok') {
1845: my ($numexisting,$numpathchanges,$existing);
1846: (undef,$numexisting,$numpathchanges,$existing) =
1847: &Apache::loncommon::ask_for_embedded_content(
1848: '/adm/coursedocs',$state,\%allfiles,\%codebase,
1849: {'error_on_invalid_names' => 1,
1850: 'ignore_remote_references' => 1,
1851: 'docs_url' => $item,
1852: 'context' => 'paste'});
1853: if ($numexisting > 0) {
1854: if (ref($existing) eq 'HASH') {
1855: foreach my $dep (keys(%{$existing})) {
1856: my $depfile = $dep;
1857: unless ($depfile =~ m{^\Q$relpath\E}) {
1858: $depfile = $relpath.$dep;
1859: }
1860: my $depcontent = &Apache::lonnet::getfile($depfile);
1861: unless ($depcontent eq '-1') {
1862: my $storedep = $dep;
1863: $storedep =~ s{^\Q$relpath\E}{};
1864: my $dep_url =
1865: &Apache::lonclonecourse::writefile(
1866: $env{'request.course.id'},
1867: $storefn.$storedep,$depcontent);
1868: if ($dep_url eq '/adm/notfound.html') {
1869: if (ref($errors) eq 'HASH') {
1870: $errors->{$depfile} = 1;
1871: }
1872: } else {
1873: ©_dependencies($depfile,$storefn,$relpath,$errors,\$depcontent);
1874: }
1875: }
1876: }
1.488 raeburn 1877: }
1878: }
1879: }
1880: }
1881: }
1882: return;
1883: }
1884:
1.329 droeschl 1885: my %parameter_type = ( 'randompick' => 'int_pos',
1886: 'hiddenresource' => 'string_yesno',
1887: 'encrypturl' => 'string_yesno',
1888: 'randomorder' => 'string_yesno',);
1889: my $valid_parameters_re = join('|',keys(%parameter_type));
1890: # set parameters
1891: sub update_parameter {
1.537 ! raeburn 1892: if ($env{'form.changeparms'} eq 'all') {
! 1893: my (@allidx,@allmapidx,%allchecked,%currchecked);
! 1894: %allchecked = (
! 1895: 'hiddenresource' => {},
! 1896: 'encrypturl' => {},
! 1897: 'randompick' => {},
! 1898: 'randomorder' => {},
! 1899: );
! 1900: foreach my $which (keys(%allchecked)) {
! 1901: $env{'form.all'.$which} =~ s/,$//;
! 1902: if ($which eq 'randompick') {
! 1903: foreach my $item (split(/,/,$env{'form.all'.$which})) {
! 1904: my ($res,$value) = split(/:/,$item);
! 1905: if ($value =~ /^\d+$/) {
! 1906: $allchecked{$which}{$res} = $value;
! 1907: }
! 1908: }
! 1909: } else {
! 1910: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.all'.$which});
! 1911: }
! 1912: }
! 1913: my $haschanges = 0;
! 1914: foreach my $res (@LONCAPA::map::order) {
! 1915: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
! 1916: $name=&LONCAPA::map::qtescape($name);
! 1917: $url=&LONCAPA::map::qtescape($url);
! 1918: next unless ($name && $url);
! 1919: my $is_map;
! 1920: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
! 1921: $is_map = 1;
! 1922: }
! 1923: foreach my $which (keys(%allchecked)) {
! 1924: if (($which eq 'randompick' || $which eq 'randomorder')) {
! 1925: next if (!$is_map);
! 1926: }
! 1927: my $oldvalue = 0;
! 1928: my $newvalue = 0;
! 1929: if ($allchecked{$which}{$res}) {
! 1930: $newvalue = $allchecked{$which}{$res};
! 1931: }
! 1932: my $current = (&LONCAPA::map::getparameter($res,'parameter_'.$which))[0];
! 1933: if ($which eq 'randompick') {
! 1934: if ($current =~ /^(\d+)$/) {
! 1935: $oldvalue = $1;
! 1936: }
! 1937: } else {
! 1938: if ($current =~ /^yes$/i) {
! 1939: $oldvalue = 1;
! 1940: }
! 1941: }
! 1942: if ($oldvalue ne $newvalue) {
! 1943: $haschanges = 1;
! 1944: if ($newvalue) {
! 1945: my $storeval = 'yes';
! 1946: if ($which eq 'randompick') {
! 1947: $storeval = $newvalue;
! 1948: }
! 1949: &LONCAPA::map::storeparameter($res,'parameter_'.$which,
! 1950: $storeval,
! 1951: $parameter_type{$which});
! 1952: &remember_parms($res,$which,'set',$storeval);
! 1953: } elsif ($oldvalue) {
! 1954: &LONCAPA::map::delparameter($res,'parameter_'.$which);
! 1955: &remember_parms($res,$which,'del');
! 1956: }
! 1957: }
! 1958: }
! 1959: }
! 1960: return $haschanges;
! 1961: } else {
! 1962: return 0 if ($env{'form.changeparms'} !~ /^($valid_parameters_re)$/);
1.329 droeschl 1963:
1.537 ! raeburn 1964: my $which = $env{'form.changeparms'};
! 1965: my $idx = $env{'form.setparms'};
! 1966: if ($env{'form.'.$which.'_'.$idx}) {
! 1967: my $value = ($which eq 'randompick') ? $env{'form.rpicknum_'.$idx}
! 1968: : 'yes';
! 1969: &LONCAPA::map::storeparameter($idx, 'parameter_'.$which, $value,
! 1970: $parameter_type{$which});
! 1971: &remember_parms($idx,$which,'set',$value);
! 1972: } else {
! 1973: &LONCAPA::map::delparameter($idx,'parameter_'.$which);
1.329 droeschl 1974:
1.537 ! raeburn 1975: &remember_parms($idx,$which,'del');
! 1976: }
! 1977: return 1;
1.329 droeschl 1978: }
1979: }
1980:
1981:
1982: sub handle_edit_cmd {
1983: my ($coursenum,$coursedom) =@_;
1984: my ($cmd,$idx)=split('_',$env{'form.cmd'});
1985:
1986: my $ratstr = $LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
1987: my ($title, $url, @rrest) = split(':', $ratstr);
1988:
1989: if ($cmd eq 'del') {
1990: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
1.463 www 1991: ($url!~/$LONCAPA::assess_page_seq_re/)) {
1.329 droeschl 1992: &Apache::lonnet::removeuploadedurl($url);
1993: } else {
1994: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
1995: }
1996: splice(@LONCAPA::map::order, $idx, 1);
1997:
1998: } elsif ($cmd eq 'cut') {
1999: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
2000: splice(@LONCAPA::map::order, $idx, 1);
2001:
1.344 bisitz 2002: } elsif ($cmd eq 'up'
1.329 droeschl 2003: && ($idx) && (defined($LONCAPA::map::order[$idx-1]))) {
2004: @LONCAPA::map::order[$idx-1,$idx] = @LONCAPA::map::order[$idx,$idx-1];
2005:
2006: } elsif ($cmd eq 'down'
2007: && defined($LONCAPA::map::order[$idx+1])) {
2008: @LONCAPA::map::order[$idx+1,$idx] = @LONCAPA::map::order[$idx,$idx+1];
2009:
2010: } elsif ($cmd eq 'rename') {
2011:
2012: my $comment = &LONCAPA::map::qtunescape($env{'form.title'});
2013: if ($comment=~/\S/) {
2014: $LONCAPA::map::resources[$LONCAPA::map::order[$idx]]=
2015: $comment.':'.join(':', $url, @rrest);
2016: }
2017: # Devalidate title cache
2018: my $renamed_url=&LONCAPA::map::qtescape($url);
2019: &Apache::lonnet::devalidate_title_cache($renamed_url);
2020: } else {
2021: return 0;
2022: }
2023: return 1;
2024: }
2025:
2026: sub editor {
1.458 raeburn 2027: my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$crstype,
1.508 raeburn 2028: $supplementalflag,$orderhash,$iconpath,$pathitem)=@_;
1.519 raeburn 2029: my ($randompick,$ishidden,$isencrypted,$plain,$is_random_order,$container);
1.510 raeburn 2030: if ($allowed) {
1.519 raeburn 2031: (my $breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
2032: $is_random_order,$container) =
1.510 raeburn 2033: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
2034: $r->print($breadcrumbtrail);
1.519 raeburn 2035: } elsif ($env{'form.folderpath'} =~ /\:1$/) {
2036: $container = 'page';
2037: } else {
2038: $container = 'sequence';
1.510 raeburn 2039: }
1.484 raeburn 2040:
1.525 raeburn 2041: my $jumpto;
2042:
2043: unless ($supplementalflag) {
2044: $jumpto = "'uploaded/$coursedom/$coursenum/$folder.$container'";
2045: }
1.484 raeburn 2046:
2047: unless ($allowed) {
2048: $randompick = -1;
2049: }
2050:
1.329 droeschl 2051: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
2052: $folder.'.'.$container);
2053: return $errtext if ($fatal);
2054:
2055: if ($#LONCAPA::map::order<1) {
2056: my $idx=&LONCAPA::map::getresidx();
2057: if ($idx<=0) { $idx=1; }
2058: $LONCAPA::map::order[0]=$idx;
2059: $LONCAPA::map::resources[$idx]='';
2060: }
1.364 bisitz 2061:
1.329 droeschl 2062: # ------------------------------------------------------------ Process commands
2063:
2064: # ---------------- if they are for this folder and user allowed to make changes
2065: if (($allowed) && ($env{'form.folder'} eq $folder)) {
2066: # set parameters and change order
2067: &snapshotbefore();
2068:
2069: if (&update_parameter()) {
2070: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
2071: return $errtext if ($fatal);
2072: }
2073:
2074: if ($env{'form.newpos'} && $env{'form.currentpos'}) {
2075: # change order
2076: my $res = splice(@LONCAPA::map::order,$env{'form.currentpos'}-1,1);
2077: splice(@LONCAPA::map::order,$env{'form.newpos'}-1,0,$res);
2078:
2079: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
2080: return $errtext if ($fatal);
2081: }
1.364 bisitz 2082:
1.329 droeschl 2083: if ($env{'form.pastemarked'}) {
1.491 raeburn 2084: my %paste_errors;
1.533 raeburn 2085: my ($paste_res,$save_error,$pastemsgarray,$lockerror) =
1.492 raeburn 2086: &do_paste_from_buffer($coursenum,$coursedom,$folder,$container,
2087: \%paste_errors);
1.533 raeburn 2088: if (ref($pastemsgarray) eq 'ARRAY') {
2089: if (@{$pastemsgarray} > 0) {
2090:
2091: $r->print('<p class="LC_info">'.
2092: join('<br />',@{$pastemsgarray}).
2093: '</p>');
2094: }
2095: }
2096: if ($lockerror) {
2097: $r->print('<p class="LC_error">'.
2098: $lockerror.
2099: '</p>');
2100: }
1.492 raeburn 2101: if ($save_error ne '') {
2102: return $save_error;
2103: }
2104: if ($paste_res ne 'ok') {
1.329 droeschl 2105: $r->print('<p><span class="LC_error">'.$paste_res.'</span></p>');
2106: }
1.491 raeburn 2107: if (keys(%paste_errors) > 0) {
2108: $r->print('<p span class="LC_warning">'."\n".
2109: &mt('The following files are either dependencies of a web page or references within a folder and/or composite page which could not be copied during the paste operation:')."\n".
2110: '<ul>'."\n");
2111: foreach my $key (sort(keys(%paste_errors))) {
2112: $r->print('<li>'.$key.'</li>'."\n");
2113: }
2114: $r->print('</ul></p>'."\n");
2115: }
1.329 droeschl 2116: }
2117:
2118: $r->print($upload_output);
2119:
2120: if (&handle_edit_cmd()) {
1.492 raeburn 2121: my $contentchg;
2122: if ($env{'form.cmd'} =~ /^(del|cut)_/) {
2123: $contentchg = 1;
2124: }
2125: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,$contentchg);
1.329 droeschl 2126: return $errtext if ($fatal);
2127: }
2128: # Group import/search
2129: if ($env{'form.importdetail'}) {
2130: my @imports;
2131: foreach my $item (split(/\&/,$env{'form.importdetail'})) {
2132: if (defined($item)) {
2133: my ($name,$url,$residx)=
1.533 raeburn 2134: map { &unescape($_); } split(/\=/,$item);
2135: if ($url =~ m{^\Q/uploaded/$coursedom/$coursenum/\E(default|supplemental)_new\.(sequence|page)$}) {
2136: my ($suffix,$errortxt,$locknotfreed) =
2137: &new_timebased_suffix($coursedom,$coursenum,'map',$1,$2);
1.504 raeburn 2138: if ($locknotfreed) {
2139: $r->print($locknotfreed);
2140: }
2141: if ($suffix) {
2142: $url =~ s/_new\./_$suffix./;
2143: } else {
2144: return $errortxt;
2145: }
1.533 raeburn 2146: } elsif ($url =~ m{^/adm/$match_domain/$match_username/new/(smppg|bulletinboard)$}) {
2147: my $type = $1;
2148: my ($suffix,$errortxt,$locknotfreed) =
2149: &new_timebased_suffix($coursedom,$coursenum,$type);
2150: if ($locknotfreed) {
2151: $r->print($locknotfreed);
2152: }
2153: if ($suffix) {
2154: $url =~ s{^(/adm/$match_domain/$match_username)/new}{$1/$suffix};
2155: } else {
2156: return $errortxt;
2157: }
1.534 raeburn 2158: } elsif ($url =~ m{^/uploaded/$coursedom/$coursenum/(docs|supplemental)/(default|\d+)/new.html$}) {
2159: if ($supplementalflag) {
2160: next unless ($1 eq 'supplemental');
2161: if ($folder eq 'supplemental') {
2162: next unless ($2 eq 'default');
2163: } else {
2164: next unless ($folder eq 'supplemental_'.$2);
2165: }
2166: } else {
2167: next unless ($1 eq 'docs');
2168: if ($folder eq 'default') {
2169: next unless ($2 eq 'default');
2170: } else {
2171: next unless ($folder eq 'default_'.$2);
2172: }
2173: }
1.504 raeburn 2174: }
1.329 droeschl 2175: push(@imports, [$name, $url, $residx]);
2176: }
2177: }
1.530 raeburn 2178: ($errtext,$fatal,my $fixuperrors) =
1.529 raeburn 2179: &group_import($coursenum, $coursedom, $folder,$container,
2180: 'londocs',@imports);
1.329 droeschl 2181: return $errtext if ($fatal);
1.529 raeburn 2182: if ($fixuperrors) {
2183: $r->print($fixuperrors);
2184: }
1.329 droeschl 2185: }
2186: # Loading a complete map
2187: if ($env{'form.loadmap'}) {
2188: if ($env{'form.importmap'}=~/\w/) {
2189: foreach my $res (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
2190: my ($title,$url,$ext,$type)=split(/\:/,$res);
2191: my $idx=&LONCAPA::map::getresidx($url);
2192: $LONCAPA::map::resources[$idx]=$res;
2193: $LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx;
2194: }
2195: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.492 raeburn 2196: $folder.'.'.$container,1);
1.329 droeschl 2197: return $errtext if ($fatal);
2198: } else {
2199: $r->print('<p><span class="LC_error">'.&mt('No map selected.').'</span></p>');
1.364 bisitz 2200:
1.329 droeschl 2201: }
2202: }
2203: &log_differences($plain);
2204: }
2205: # ---------------------------------------------------------------- End commands
2206: # ---------------------------------------------------------------- Print screen
2207: my $idx=0;
2208: my $shown=0;
2209: if (($ishidden) || ($isencrypted) || ($randompick>=0) || ($is_random_order)) {
1.381 bisitz 2210: $r->print('<div class="LC_Box">'.
1.432 raeburn 2211: '<ol class="LC_docs_parameters"><li class="LC_docs_parameters_title">'.&mt('Parameters:').'</li>'.
2212: ($randompick>=0?'<li>'.&mt('randomly pick [quant,_1,resource]',$randompick).'</li>':'').
2213: ($ishidden?'<li>'.&mt('contents hidden').'</li>':'').
2214: ($isencrypted?'<li>'.&mt('URLs hidden').'</li>':'').
2215: ($is_random_order?'<li>'.&mt('random order').'</li>':'').
1.431 raeburn 2216: '</ol>');
1.381 bisitz 2217: if ($randompick>=0) {
2218: $r->print('<p class="LC_warning">'
2219: .&mt('Caution: this folder is set to randomly pick a subset'
2220: .' of resources. Adding or removing resources from this'
2221: .' folder will change the set of resources that the'
2222: .' students see, resulting in spurious or missing credit'
2223: .' for completed problems, not limited to ones you'
2224: .' modify. Do not modify the contents of this folder if'
2225: .' it is in active student use.')
2226: .'</p>'
2227: );
2228: }
2229: if ($is_random_order) {
2230: $r->print('<p class="LC_warning">'
2231: .&mt('Caution: this folder is set to randomly order its'
2232: .' contents. Adding or removing resources from this folder'
2233: .' will change the order of resources shown.')
2234: .'</p>'
2235: );
2236: }
2237: $r->print('</div>');
1.364 bisitz 2238: }
1.381 bisitz 2239:
1.537 ! raeburn 2240: my ($to_show,$output,@allidx,@allmapidx);
1.424 onken 2241:
2242: &Apache::loncommon::start_data_table_count(); #setup a row counter
1.381 bisitz 2243: foreach my $res (@LONCAPA::map::order) {
2244: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
2245: $name=&LONCAPA::map::qtescape($name);
2246: $url=&LONCAPA::map::qtescape($url);
2247: unless ($name) { $name=(split(/\//,$url))[-1]; }
2248: unless ($name) { $idx++; next; }
1.537 ! raeburn 2249: push(@allidx,$res);
! 2250: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
! 2251: push(@allmapidx,$res);
! 2252: }
1.381 bisitz 2253: $output .= &entryline($idx,$name,$url,$folder,$allowed,$res,
1.501 raeburn 2254: $coursenum,$coursedom,$crstype,
1.519 raeburn 2255: $pathitem,$supplementalflag,$container);
1.381 bisitz 2256: $idx++;
2257: $shown++;
1.329 droeschl 2258: }
1.424 onken 2259: &Apache::loncommon::end_data_table_count();
1.510 raeburn 2260:
2261: if (($allowed) || ($supplementalflag && $folder eq 'supplemental')) {
1.520 raeburn 2262: my $toolslink = '<table><tr><td>'
2263: .&Apache::loncommon::help_open_menu('Navigation Screen',
2264: 'Navigation_Screen',undef,'RAT')
2265: .'</td><td class="LC_middle">'.&mt('Tools:').'</td>'
2266: .'<td align="left"><ul id="LC_toolbar">'
1.525 raeburn 2267: .'<li><a href="/adm/coursedocs?forcesupplement=1&command=editsupp" '
1.520 raeburn 2268: .'id="LC_content_toolbar_edittoplevel" '
2269: .'class="LC_toolbarItem" '
2270: .'title="'.&mt('Supplemental Content Editor').'">'
2271: .'</a></li></ul></td></tr></table><br />';
1.510 raeburn 2272: if ($shown) {
2273: if ($allowed) {
2274: $to_show = &Apache::loncommon::start_scrollbox('900px','880px','400px','contentscroll')
2275: .&Apache::loncommon::start_data_table(undef,'contentlist')
2276: .&Apache::loncommon::start_data_table_header_row()
2277: .'<th colspan="2">'.&mt('Move').'</th>'
2278: .'<th>'.&mt('Actions').'</th>'
2279: .'<th colspan="2">'.&mt('Document').'</th>';
2280: if ($folder !~ /^supplemental/) {
2281: $to_show .= '<th colspan="4">'.&mt('Settings').'</th>';
2282: }
1.537 ! raeburn 2283: $to_show .= &Apache::loncommon::end_data_table_header_row();
! 2284: if ($folder !~ /^supplemental/) {
! 2285: my $idxlist = join(',',@allidx);
! 2286: my $mapidxlist = join(',',@allmapidx);
! 2287: if (@allidx > 0) {
! 2288: my $path;
! 2289: if ($env{'form.folderpath'}) {
! 2290: $path =
! 2291: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
! 2292: }
! 2293: $to_show .=
! 2294: &Apache::loncommon::continue_data_table_row().
! 2295: '<td colspan="5"> </td>'.
! 2296: '<td colspan="4">'.
! 2297: '<form action="/adm/coursedocs" method="post" name="togglemultchecks">'.
! 2298: '<span class="LC_nobreak" style="font-size:x-small;font-weight:bold;">'.&mt('Select:').' '.
! 2299: '<label><input type="radio" name="showmultpick" value="0" onclick="javascript:togglePick();" checked="checked" />'.&mt('single').'</label>'.(' 'x2).'<label><input type="radio" name="showmultpick" value="1" onclick="javascript:togglePick();" />'.&mt('multiple').'</label></span></form>'.
! 2300: '<div id="multiclick" style="display: none">'.
! 2301: '<form action="/adm/coursedocs" method="post" name="cumulativechecks" onsubmit="return submitSettings(this);">'."\n".
! 2302: '<fieldset><legend style="font-size:x-small;">'.&mt('check/uncheck all').'</legend>'."\n".
! 2303: '<table><tr><td class="LC_docs_entry_parameter"><span class="LC_nobreak"><input type="checkbox" name="hiddenresourceall" id="hiddenresourceall" onclick="propagateState(this.form,'."'hiddenresource'".')" />'.&mt('Hidden').'</span></td><td class="LC_docs_entry_parameter"><span class="LC_nobreak"><input type="checkbox" name="randompickall" id="randompickall" onclick="updatePick(this.form,'."'all','check'".');propagateState(this.form,'."'randompick'".');propagateState(this.form,'."'rpicknum'".');" />'.&mt('Randomly Pick').'<span id="rpicktextall"></span><input type="hidden" name="rpicknumall" id="rpicknumall" value="" /></span></td>'.
! 2304: '</tr>'."\n".
! 2305: '<tr><td class="LC_docs_entry_parameter"><span class="LC_nobreak"><input type="checkbox" name="encrypturlall" id="encrypturlall" onclick="propagateState(this.form,'."'encrypturl'".')" />'.&mt('URL hidden').'</span></td><td class="LC_docs_entry_parameter"><span class="LC_nobreak"><input type="checkbox" name="randomorderall" id="randomorderall" onclick="propagateState(this.form,'."'randomorder'".')" />'.&mt('Random Order').'</span></td></tr></table>'."\n".
! 2306: '</fieldset>'.
! 2307: '<input type="hidden" name="folderpath" value="'.$path.'" />'.
! 2308: '<input type="hidden" name="symb" value="'.$env{'form.symb'}.'" />'.
! 2309: '<input type="hidden" name="allhiddenresource" value="" />'.
! 2310: '<input type="hidden" name="allencrypturl" value="" />'.
! 2311: '<input type="hidden" name="allrandompick" value="" />'.
! 2312: '<input type="hidden" name="allrandomorder" value="" />'.
! 2313: '<input type="hidden" name="allidx" value="'.$idxlist.'" />'.
! 2314: '<input type="hidden" name="allmapidx" value="'.$mapidxlist.'" />'.
! 2315: '<input type="hidden" name="changeparms" value="all" />'.
! 2316: '<input type="submit" name="multiplesettings" value="'.&mt('Save settings below').'" />'.
! 2317: '</form>'.
! 2318: '</div>'.
! 2319:
! 2320: '</td>'.
! 2321: &Apache::loncommon::end_data_table_row();
! 2322: }
! 2323: }
! 2324: $to_show .= $output.' '
1.510 raeburn 2325: .&Apache::loncommon::end_data_table()
2326: .'<br style="line-height:2px;" />'
2327: .&Apache::loncommon::end_scrollbox();
2328: } else {
1.520 raeburn 2329: $to_show .= $toolslink
1.510 raeburn 2330: .&Apache::loncommon::start_data_table('LC_tableOfContent')
2331: .$output.' '
2332: .&Apache::loncommon::end_data_table();
1.393 raeburn 2333: }
1.510 raeburn 2334: } else {
1.520 raeburn 2335: if (!$allowed) {
2336: $to_show .= $toolslink;
2337: }
1.510 raeburn 2338: $to_show .= &Apache::loncommon::start_scrollbox('400px','380px','200px','contentscroll')
2339: .'<div class="LC_info" id="contentlist">'
2340: .&mt('Currently no documents.')
2341: .'</div>'
2342: .&Apache::loncommon::end_scrollbox();
1.393 raeburn 2343: }
2344: } else {
1.510 raeburn 2345: if ($shown) {
2346: $to_show = '<div>'
2347: .&Apache::loncommon::start_data_table('LC_tableOfContent')
2348: .$output
2349: .&Apache::loncommon::end_data_table()
2350: .'</div>';
2351: } else {
2352: $to_show = '<div class="LC_info" id="contentlist">'
2353: .&mt('Currently no documents.')
2354: .'</div>'
2355: }
1.458 raeburn 2356: }
2357: my $tid = 1;
2358: if ($supplementalflag) {
2359: $tid = 2;
1.329 droeschl 2360: }
2361: if ($allowed) {
1.484 raeburn 2362: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
2363: $r->print(&generate_edit_table($tid,$orderhash,$to_show,$iconpath,$jumpto,
2364: $readfile));
1.492 raeburn 2365: &print_paste_buffer($r,$container,$folder,$coursedom,$coursenum);
1.460 raeburn 2366: } else {
2367: $r->print($to_show);
1.329 droeschl 2368: }
2369: return;
2370: }
2371:
2372: sub process_file_upload {
2373: my ($upload_output,$coursenum,$coursedom,$allfiles,$codebase,$uploadcmd) = @_;
2374: # upload a file, if present
1.440 raeburn 2375: my ($parseaction,$showupload,$nextphase,$mimetype);
2376: if ($env{'form.parserflag'}) {
1.329 droeschl 2377: $parseaction = 'parse';
2378: }
2379: my $folder=$env{'form.folder'};
2380: if ($folder eq '') {
2381: $folder='default';
2382: }
2383: if ( ($folder=~/^$uploadcmd/) || ($uploadcmd eq 'default') ) {
2384: my $errtext='';
2385: my $fatal=0;
2386: my $container='sequence';
1.519 raeburn 2387: if ($env{'form.folderpath'} =~ /:1$/) {
1.329 droeschl 2388: $container='page';
2389: }
2390: ($errtext,$fatal)=
1.534 raeburn 2391: &mapread($coursenum,$coursedom,$folder.'.'.$container);
1.329 droeschl 2392: if ($#LONCAPA::map::order<1) {
2393: $LONCAPA::map::order[0]=1;
2394: $LONCAPA::map::resources[1]='';
2395: }
2396: my $destination = 'docs/';
2397: if ($folder =~ /^supplemental/) {
2398: $destination = 'supplemental/';
2399: }
2400: if (($folder eq 'default') || ($folder eq 'supplemental')) {
2401: $destination .= 'default/';
2402: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
2403: $destination .= $2.'/';
2404: }
1.534 raeburn 2405: if ($fatal) {
2406: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.&mt('The uploaded file has not been stored as an error occurred reading the contents of the current folder.').'</div>';
2407: return;
2408: }
1.440 raeburn 2409: # this is for a course, not a user, so set context to coursedoc.
1.329 droeschl 2410: my $newidx=&LONCAPA::map::getresidx();
2411: $destination .= $newidx;
1.439 raeburn 2412: my $url=&Apache::lonnet::userfileupload('uploaddoc','coursedoc',$destination,
1.329 droeschl 2413: $parseaction,$allfiles,
1.440 raeburn 2414: $codebase,undef,undef,undef,undef,
2415: undef,undef,\$mimetype);
2416: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E.*/([^/]+)$}) {
2417: my $stored = $1;
2418: $showupload = '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
2419: $stored.'</span>').'</p>';
2420: } else {
2421: my ($filename) = ($env{'form.uploaddoc.filename'} =~ m{([^/]+)$});
2422:
1.457 raeburn 2423: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.&mt('Unable to save file [_1].','<span class="LC_filename">'.$filename.'</span>').'</div>';
1.440 raeburn 2424: return;
2425: }
1.329 droeschl 2426: my $ext='false';
2427: if ($url=~m{^http://}) { $ext='true'; }
2428: $url = &LONCAPA::map::qtunescape($url);
2429: my $comment=$env{'form.comment'};
2430: $comment = &LONCAPA::map::qtunescape($comment);
2431: if ($folder=~/^supplemental/) {
2432: $comment=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
2433: $env{'user.domain'}.'___&&&___'.$comment;
2434: }
2435:
2436: $LONCAPA::map::resources[$newidx]=
2437: $comment.':'.$url.':'.$ext.':normal:res';
2438: $LONCAPA::map::order[$#LONCAPA::map::order+1]= $newidx;
2439: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.492 raeburn 2440: $folder.'.'.$container,1);
1.329 droeschl 2441: if ($fatal) {
1.457 raeburn 2442: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.$errtext.'</div>';
1.440 raeburn 2443: return;
1.329 droeschl 2444: } else {
1.440 raeburn 2445: if ($parseaction eq 'parse' && $mimetype eq 'text/html') {
2446: $$upload_output = $showupload;
1.384 raeburn 2447: my $total_embedded = scalar(keys(%{$allfiles}));
1.329 droeschl 2448: if ($total_embedded > 0) {
1.440 raeburn 2449: my $uploadphase = 'upload_embedded';
2450: my $primaryurl = &HTML::Entities::encode($url,'<>&"');
2451: my $state = &embedded_form_elems($uploadphase,$primaryurl,$newidx);
2452: my ($embedded,$num) =
2453: &Apache::loncommon::ask_for_embedded_content(
2454: '/adm/coursedocs',$state,$allfiles,$codebase,{'docs_url' => $url});
2455: if ($embedded) {
2456: if ($num) {
2457: $$upload_output .=
2458: '<p>'.&mt('This file contains embedded multimedia objects, which need to be uploaded.').'</p>'.$embedded;
2459: $nextphase = $uploadphase;
2460: } else {
2461: $$upload_output .= $embedded;
2462: }
2463: } else {
2464: $$upload_output .= &mt('Embedded item(s) already present, so no additional upload(s) required').'<br />';
2465: }
1.329 droeschl 2466: } else {
1.440 raeburn 2467: $$upload_output .= &mt('No embedded items identified').'<br />';
1.329 droeschl 2468: }
1.457 raeburn 2469: $$upload_output = '<div id="uploadfileresult">'.$$upload_output.'</div>';
1.476 raeburn 2470: } elsif (&Apache::loncommon::is_archive_file($mimetype)) {
2471: $nextphase = 'decompress_uploaded';
2472: my $position = scalar(@LONCAPA::map::order)-1;
2473: my $noextract = &return_to_editor();
2474: my $archiveurl = &HTML::Entities::encode($url,'<>&"');
2475: my %archiveitems = (
2476: folderpath => $env{'form.folderpath'},
2477: cmd => $nextphase,
2478: newidx => $newidx,
2479: position => $position,
2480: phase => $nextphase,
1.477 raeburn 2481: comment => $comment,
1.480 raeburn 2482: );
2483: my ($destination,$dir_root) = &embedded_destination($coursenum,$coursedom);
2484: my @current = &get_dir_list($url,$coursenum,$coursedom,$newidx);
1.476 raeburn 2485: $$upload_output = $showupload.
2486: &Apache::loncommon::decompress_form($mimetype,
2487: $archiveurl,'/adm/coursedocs',$noextract,
1.480 raeburn 2488: \%archiveitems,\@current);
1.329 droeschl 2489: }
2490: }
2491: }
1.440 raeburn 2492: return $nextphase;
1.329 droeschl 2493: }
2494:
1.480 raeburn 2495: sub get_dir_list {
2496: my ($url,$coursenum,$coursedom,$newidx) = @_;
2497: my ($destination,$dir_root) = &embedded_destination();
2498: my ($dirlistref,$listerror) =
2499: &Apache::lonnet::dirlist("$dir_root/$destination/$newidx",$coursedom,$coursenum,1);
2500: my @dir_lines;
2501: my $dirptr=16384;
2502: if (ref($dirlistref) eq 'ARRAY') {
2503: foreach my $dir_line (sort
2504: {
2505: my ($afile)=split('&',$a,2);
2506: my ($bfile)=split('&',$b,2);
2507: return (lc($afile) cmp lc($bfile));
2508: } (@{$dirlistref})) {
2509: my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$dir_line,16);
2510: $filename =~ s/\s+$//;
2511: next if ($filename =~ /^\.\.?$/);
2512: my $isdir = 0;
2513: if ($dirptr&$testdir) {
2514: $isdir = 1;
2515: }
2516: push(@dir_lines, [$filename,$dom,$isdir,$size,$mtime,$obs]);
2517: }
2518: }
2519: return @dir_lines;
2520: }
2521:
1.329 droeschl 2522: sub is_supplemental_title {
2523: my ($title) = @_;
2524: return scalar($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/);
2525: }
2526:
2527: # --------------------------------------------------------------- An entry line
2528:
2529: sub entryline {
1.501 raeburn 2530: my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$coursedom,
1.519 raeburn 2531: $crstype,$pathitem,$supplementalflag,$container)=@_;
2532: my ($foldertitle,$renametitle);
1.329 droeschl 2533: if (&is_supplemental_title($title)) {
1.488 raeburn 2534: ($title,$foldertitle,$renametitle) = &Apache::loncommon::parse_supplemental_title($title);
1.329 droeschl 2535: } else {
2536: $title=&HTML::Entities::encode($title,'"<>&\'');
2537: $renametitle=$title;
2538: $foldertitle=$title;
2539: }
2540:
2541: my $orderidx=$LONCAPA::map::order[$index];
1.364 bisitz 2542:
1.329 droeschl 2543: $renametitle=~s/\\/\\\\/g;
2544: $renametitle=~s/\"\;/\\\"/g;
2545: $renametitle=~s/ /%20/g;
1.379 bisitz 2546: my $line=&Apache::loncommon::start_data_table_row();
1.478 raeburn 2547: my ($form_start,$form_end,$form_common);
1.329 droeschl 2548: # Edit commands
1.535 raeburn 2549: my ($esc_path, $path, $symb);
1.329 droeschl 2550: if ($env{'form.folderpath'}) {
2551: $esc_path=&escape($env{'form.folderpath'});
2552: $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
2553: # $htmlfoldername=&HTML::Entities::encode($env{'form.foldername'},'<>&"');
2554: }
1.505 raeburn 2555: my $isexternal;
1.510 raeburn 2556: if ($residx) {
1.501 raeburn 2557: my $currurl = $url;
2558: $currurl =~ s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
1.505 raeburn 2559: if ($currurl =~ m{^/adm/wrapper/ext/}) {
2560: $isexternal = 1;
2561: }
1.510 raeburn 2562: if (!$supplementalflag) {
2563: my $path = 'uploaded/'.
2564: $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
2565: $env{'course.'.$env{'request.course.id'}.'.num'}.'/';
2566: $symb = &Apache::lonnet::encode_symb($path.$folder.".$container",
2567: $residx,
2568: &Apache::lonnet::declutter($currurl));
2569: }
1.501 raeburn 2570: }
1.517 raeburn 2571: my ($renamelink,%lt);
1.329 droeschl 2572: if ($allowed) {
2573: my $incindex=$index+1;
2574: my $selectbox='';
1.471 raeburn 2575: if (($#LONCAPA::map::order>0) &&
1.329 droeschl 2576: ((split(/\:/,
1.344 bisitz 2577: $LONCAPA::map::resources[$LONCAPA::map::order[0]]))[1]
2578: ne '') &&
1.329 droeschl 2579: ((split(/\:/,
1.344 bisitz 2580: $LONCAPA::map::resources[$LONCAPA::map::order[1]]))[1]
1.329 droeschl 2581: ne '')) {
2582: $selectbox=
2583: '<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
1.373 bisitz 2584: '<select name="newpos" onchange="this.form.submit()">';
1.329 droeschl 2585: for (my $i=1;$i<=$#LONCAPA::map::order+1;$i++) {
2586: if ($i==$incindex) {
1.358 bisitz 2587: $selectbox.='<option value="" selected="selected">('.$i.')</option>';
1.329 droeschl 2588: } else {
2589: $selectbox.='<option value="'.$i.'">'.$i.'</option>';
2590: }
2591: }
2592: $selectbox.='</select>';
2593: }
1.501 raeburn 2594: %lt=&Apache::lonlocal::texthash(
1.329 droeschl 2595: 'up' => 'Move Up',
2596: 'dw' => 'Move Down',
2597: 'rm' => 'Remove',
2598: 'ct' => 'Cut',
2599: 'rn' => 'Rename',
1.501 raeburn 2600: 'cp' => 'Copy',
2601: 'ex' => 'External Resource',
2602: 'ed' => 'Edit',
2603: 'pr' => 'Preview',
2604: 'sv' => 'Save',
2605: 'ul' => 'URL',
2606: 'ti' => 'Title',
2607: );
1.329 droeschl 2608: my $nocopy=0;
2609: my $nocut=0;
1.497 raeburn 2610: my $noremove=0;
1.492 raeburn 2611: if ($url=~ m{^/res/.+\.(page|sequence)$}) {
2612: # no copy for published maps
2613: $nocopy=1;
1.329 droeschl 2614: }
1.344 bisitz 2615: if ($url=~/^\/res\/lib\/templates\//) {
2616: $nocopy=1;
1.329 droeschl 2617: $nocut=1;
2618: }
1.497 raeburn 2619: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2620: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2621: if ($url eq "/uploaded/$cdom/$cnum/group_allfolders.sequence") {
2622: if ($env{'form.folderpath'} =~ /^default&[^\&]+$/) {
2623: my %curr_groups = &Apache::longroup::coursegroups();
2624: if (keys(%curr_groups) > 0) {
2625: $noremove=1;
2626: }
2627: $nocut=1;
2628: $nocopy=1;
2629: }
2630: } elsif ($url =~ m{^\Q/uploaded/$cdom/$cnum/group_folder_\E(\w+)\.sequence$}) {
2631: my $group = $1;
2632: if ($env{'form.folderpath'} =~ /^default&[^\&]+\&group_allfolders\&[^\&]+$/) {
2633: my %curr_group = &Apache::longroup::coursegroups($cdom,$cnum,$group);
2634: if (keys(%curr_group) > 0) {
2635: $noremove=1;
2636: }
2637: }
2638: $nocut=1;
2639: $nocopy=1;
2640: } elsif ($url =~ m{^\Q/adm/$cdom/$cnum/\E(\w+)/smppg$}) {
2641: my $group = $1;
2642: if ($env{'form.folderpath'} =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&\Qgroup_folder_$group\E\&[^\&]+$/) {
2643: my %curr_group = &Apache::longroup::coursegroups($cdom,$cnum,$group);
2644: my %groupsettings = &Apache::longroup::get_group_settings($curr_group{$group});
2645: if (keys(%groupsettings) > 0) {
2646: $noremove=1;
2647: }
2648: $nocut=1;
2649: $nocopy=1;
2650: }
2651: } elsif ($env{'form.folderpath'} =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&group_folder_(\w+)\&/) {
2652: my $group = $1;
2653: my %curr_group = &Apache::longroup::coursegroups($cdom,$cnum,$group);
2654: if ($url =~ /group_boards_\Q$group\E/) {
2655: my %curr_group = &Apache::longroup::coursegroups($cdom,$cnum,$group);
2656: my %groupsettings = &Apache::longroup::get_group_settings($curr_group{$group});
2657: if (keys(%groupsettings) > 0) {
2658: if (ref($groupsettings{'functions'}) eq 'HASH') {
2659: if ($groupsettings{'functions'}{'discussion'} eq 'on') {
2660: $noremove=1;
2661: }
2662: }
2663: }
2664: $nocut=1;
2665: $nocopy=1;
2666: }
2667: }
1.517 raeburn 2668: my ($copylink,$cutlink,$removelink);
1.329 droeschl 2669: my $skip_confirm = 0;
2670: if ( $folder =~ /^supplemental/
2671: || ($url =~ m{( /smppg$
2672: |/syllabus$
2673: |/aboutme$
2674: |/navmaps$
2675: |/bulletinboard$
1.505 raeburn 2676: |\.html$)}x)
2677: || $isexternal) {
1.329 droeschl 2678: $skip_confirm = 1;
2679: }
2680:
1.508 raeburn 2681: if ($nocopy) {
1.507 raeburn 2682: $copylink=(<<ENDCOPY);
2683: <span style="visibility: hidden;">$lt{'cp'}</span>
2684: ENDCOPY
2685: } else {
1.329 droeschl 2686: $copylink=(<<ENDCOPY);
1.519 raeburn 2687: <a href="javascript:markcopy('$esc_path','$index','$renametitle','$container','$folder');" class="LC_docs_copy">$lt{'cp'}</a>
1.329 droeschl 2688: ENDCOPY
2689: }
1.508 raeburn 2690: if ($nocut) {
1.507 raeburn 2691: $cutlink=(<<ENDCUT);
2692: <span style="visibility: hidden;">$lt{'ct'}</span>
2693: ENDCUT
2694: } else {
1.329 droeschl 2695: $cutlink=(<<ENDCUT);
1.519 raeburn 2696: <a href="javascript:cutres('$esc_path','$index','$renametitle','$container','$folder',$skip_confirm);" class="LC_docs_cut">$lt{'ct'}</a>
1.329 droeschl 2697: ENDCUT
2698: }
1.507 raeburn 2699: if ($noremove) {
2700: $removelink=(<<ENDREM);
2701: <span style="visibility: hidden;">$lt{'rm'}</a>
2702: ENDREM
2703: } else {
1.497 raeburn 2704: $removelink=(<<ENDREM);
1.519 raeburn 2705: <a href='javascript:removeres("$esc_path","$index","$renametitle",$skip_confirm);' class="LC_docs_remove">$lt{'rm'}</a>
1.497 raeburn 2706: ENDREM
2707: }
1.518 raeburn 2708: unless ($isexternal) {
2709: $renamelink=(<<ENDREN);
1.519 raeburn 2710: <a href='javascript:changename("$esc_path","$index","$renametitle");' class="LC_docs_rename">$lt{'rn'}</a>
1.507 raeburn 2711: ENDREN
1.518 raeburn 2712: }
1.478 raeburn 2713: $form_start = '
2714: <form action="/adm/coursedocs" method="post">
2715: ';
2716: $form_common=(<<END);
1.535 raeburn 2717: <input type="hidden" name="folderpath" value="$path" />
2718: <input type="hidden" name="symb" value="$symb" />
1.329 droeschl 2719: <input type="hidden" name="setparms" value="$orderidx" />
2720: <input type="hidden" name="changeparms" value="0" />
2721: END
2722: $form_end = '</form>';
2723: $line.=(<<END);
2724: <td>
1.379 bisitz 2725: <div class="LC_docs_entry_move">
1.535 raeburn 2726: <a href='/adm/coursedocs?cmd=up_$index&folderpath=$esc_path&symb=$symb'>
1.501 raeburn 2727: <img src="${iconpath}move_up.gif" alt="$lt{'up'}" class="LC_icon" />
1.379 bisitz 2728: </a>
2729: </div>
2730: <div class="LC_docs_entry_move">
1.536 raeburn 2731: <a href='/adm/coursedocs?cmd=down_$index&folderpath=$esc_path&symb=$symb'>
1.501 raeburn 2732: <img src="${iconpath}move_down.gif" alt="$lt{'dw'}" class="LC_icon" />
1.379 bisitz 2733: </a>
2734: </div>
1.329 droeschl 2735: </td>
2736: <td>
2737: $form_start
1.478 raeburn 2738: $form_common
1.329 droeschl 2739: $selectbox
2740: $form_end
2741: </td>
1.507 raeburn 2742: <td class="LC_docs_entry_commands"><span class="LC_nobreak">
1.497 raeburn 2743: $removelink
1.329 droeschl 2744: $cutlink
2745: $copylink
1.507 raeburn 2746: </span>
1.329 droeschl 2747: </td>
2748: END
2749:
2750: }
2751: # Figure out what kind of a resource this is
2752: my ($extension)=($url=~/\.(\w+)$/);
2753: my $uploaded=($url=~/^\/*uploaded\//);
2754: my $icon=&Apache::loncommon::icon($url);
1.519 raeburn 2755: my $isfolder;
2756: my $ispage;
2757: my $containerarg;
1.329 droeschl 2758: if ($uploaded) {
1.472 raeburn 2759: if (($extension eq 'sequence') || ($extension eq 'page')) {
2760: $url=~/\Q$coursenum\E\/([\/\w]+)\.\Q$extension\E$/;
1.519 raeburn 2761: $containerarg = $1;
1.472 raeburn 2762: if ($extension eq 'sequence') {
2763: $icon=$iconpath.'navmap.folder.closed.gif';
2764: $isfolder=1;
2765: } else {
2766: $icon=$iconpath.'page.gif';
2767: $ispage=1;
2768: }
2769: if ($allowed) {
2770: $url='/adm/coursedocs?';
2771: } else {
2772: $url='/adm/supplemental?';
2773: }
1.329 droeschl 2774: } else {
2775: &Apache::lonnet::allowuploaded('/adm/coursedoc',$url);
2776: }
2777: }
1.364 bisitz 2778:
1.518 raeburn 2779: my ($editlink,$extresform);
1.329 droeschl 2780: my $orig_url = $url;
1.340 raeburn 2781: $orig_url=~s{http(:|:)//https(:|:)//}{https$2//};
1.510 raeburn 2782: $url=~s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
1.501 raeburn 2783: if (!$supplementalflag && $residx && $symb) {
2784: if ((!$isfolder) && (!$ispage)) {
2785: (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
2786: $url=&Apache::lonnet::clutter($url);
2787: if ($url=~/^\/*uploaded\//) {
2788: $url=~/\.(\w+)$/;
2789: my $embstyle=&Apache::loncommon::fileembstyle($1);
2790: if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
2791: $url='/adm/wrapper'.$url;
2792: } elsif ($embstyle eq 'ssi') {
2793: #do nothing with these
2794: } elsif ($url!~/\.(sequence|page)$/) {
2795: $url='/adm/coursedocs/showdoc'.$url;
2796: }
2797: } elsif ($url=~m|^/ext/|) {
2798: $url='/adm/wrapper'.$url;
1.329 droeschl 2799: }
1.501 raeburn 2800: if (&Apache::lonnet::symbverify($symb,$url)) {
2801: $url.=(($url=~/\?/)?'&':'?').'symb='.&escape($symb);
2802: } else {
2803: $url='';
2804: }
1.329 droeschl 2805: }
2806: }
1.478 raeburn 2807: my ($rand_pick_text,$rand_order_text);
1.519 raeburn 2808: if ($isfolder || $ispage || $extension eq 'sequence' || $extension eq 'page') {
1.329 droeschl 2809: my $foldername=&escape($foldertitle);
2810: my $folderpath=$env{'form.folderpath'};
2811: if ($folderpath) { $folderpath.='&' };
1.510 raeburn 2812: if (!$allowed && $supplementalflag) {
1.519 raeburn 2813: $folderpath.=$containerarg.'&'.$foldername;
1.510 raeburn 2814: $url.='folderpath='.&escape($folderpath);
2815: } else {
1.344 bisitz 2816: # Append randompick number, hidden, and encrypted with ":" to foldername,
1.329 droeschl 2817: # so it gets transferred between levels
1.519 raeburn 2818: $folderpath.=$containerarg.'&'.$foldername.
1.510 raeburn 2819: ':'.(&LONCAPA::map::getparameter($orderidx,
1.329 droeschl 2820: 'parameter_randompick'))[0]
2821: .':'.((&LONCAPA::map::getparameter($orderidx,
2822: 'parameter_hiddenresource'))[0]=~/^yes$/i)
2823: .':'.((&LONCAPA::map::getparameter($orderidx,
2824: 'parameter_encrypturl'))[0]=~/^yes$/i)
2825: .':'.((&LONCAPA::map::getparameter($orderidx,
1.519 raeburn 2826: 'parameter_randomorder'))[0]=~/^yes$/i)
2827: .':'.$ispage;
1.510 raeburn 2828: $url.='folderpath='.&escape($folderpath);
2829: my $rpicknum = (&LONCAPA::map::getparameter($orderidx,
2830: 'parameter_randompick'))[0];
2831: my $rpckchk;
2832: if ($rpicknum) {
2833: $rpckchk = ' checked="checked"';
2834: }
1.537 ! raeburn 2835: my $formname = 'edit_randompick_'.$orderidx;
1.510 raeburn 2836: $rand_pick_text =
1.478 raeburn 2837: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
2838: $form_common."\n".
1.537 ! raeburn 2839: '<span class="LC_nobreak"><label><input type="checkbox" name="randompick_'.$orderidx.'" id="randompick_'.$orderidx.'" onclick="'."updatePick(this.form,'$orderidx','check');".'"'.$rpckchk.' /> '.&mt('Randomly Pick').'</label><input type="hidden" name="rpicknum_'.$orderidx.'" id="rpicknum_'.$orderidx.'" value="'.$rpicknum.'" /><span id="randompicknum_'.$orderidx.'">';
1.510 raeburn 2840: if ($rpicknum ne '') {
2841: $rand_pick_text .= ': <a href="javascript:updatePick('."document.$formname,'$orderidx','link'".')">'.$rpicknum.'</a>';
2842: }
1.537 ! raeburn 2843: $rand_pick_text .= '</span></span>'.
! 2844: $form_end;
1.510 raeburn 2845: my $ro_set=
2846: ((&LONCAPA::map::getparameter($orderidx,'parameter_randomorder'))[0]=~/^yes$/i?' checked="checked"':'');
1.537 ! raeburn 2847: my $formname = 'edit_rorder_'.$orderidx;
1.510 raeburn 2848: $rand_order_text =
1.537 ! raeburn 2849: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
! 2850: $form_common."\n".
! 2851: '<span class="LC_nobreak"><label><input type="checkbox" name="randomorder_'.$orderidx.'" id="randomorder_'.$orderidx.'" onclick="checkForSubmit(this.form,'."'randomorder'".')"; '.$ro_set.' /> '.&mt('Random Order').' </label></span>'.
! 2852: $form_end;
1.510 raeburn 2853: }
1.509 raeburn 2854: } elsif ($supplementalflag && !$allowed) {
1.510 raeburn 2855: $url .= ($url =~ /\?/) ? '&':'?';
1.509 raeburn 2856: $url .= 'folderpath='.&HTML::Entities::encode($esc_path,'<>&"');
1.510 raeburn 2857: if ($title) {
2858: $url .= '&title='.&HTML::Entities::encode($renametitle,'<>&"');
2859: }
1.511 raeburn 2860: if ($isexternal && $orderidx) {
1.510 raeburn 2861: $url .= '&idx='.$orderidx;
2862: }
1.329 droeschl 2863: }
1.519 raeburn 2864: my ($tdalign,$tdwidth);
1.501 raeburn 2865: if ($allowed) {
2866: my $fileloc =
2867: &Apache::lonnet::declutter(&Apache::lonnet::filelocation('',$orig_url));
1.510 raeburn 2868: if ($isexternal) {
1.518 raeburn 2869: ($editlink,$extresform) =
1.510 raeburn 2870: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem);
1.511 raeburn 2871: } elsif (!$isfolder && !$ispage) {
1.503 raeburn 2872: my ($cfile,$home,$switchserver,$forceedit,$forceview) =
2873: &Apache::lonnet::can_edit_resource($fileloc,$coursenum,$coursedom,$orig_url);
1.511 raeburn 2874: if (($cfile ne '') && ($symb ne '' || $supplementalflag)) {
1.501 raeburn 2875: my $jscall =
2876: &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,
2877: $switchserver,
1.503 raeburn 2878: $forceedit,
1.511 raeburn 2879: undef,$symb,
2880: &escape($env{'form.folderpath'}),
1.524 raeburn 2881: $renametitle,'','',1);
1.501 raeburn 2882: if ($jscall) {
1.518 raeburn 2883: $editlink = '<a class="LC_docs_ext_edit" href="javascript:'.
2884: $jscall.'" >'.&mt('Edit').'</a> '."\n";
1.501 raeburn 2885: }
2886: }
2887: }
1.519 raeburn 2888: $tdalign = ' align="right" valign="top"';
2889: $tdwidth = ' width="80%"';
1.329 droeschl 2890: }
1.408 raeburn 2891: my $reinit;
2892: if ($crstype eq 'Community') {
2893: $reinit = &mt('(re-initialize community to access)');
2894: } else {
2895: $reinit = &mt('(re-initialize course to access)');
1.519 raeburn 2896: }
2897: $line.='<td class="LC_docs_entry_commands"'.$tdalign.'><span class="LC_nobreak">'.$editlink.$renamelink;
1.472 raeburn 2898: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.469 www 2899: $line.='<a href="'.$url.'"><img src="'.$icon.'" alt="" class="LC_icon" /></a>';
2900: } elsif ($url) {
1.484 raeburn 2901: $line.=&Apache::loncommon::modal_link($url.(($url=~/\?/)?'&':'?').'inhibitmenu=yes',
1.470 raeburn 2902: '<img src="'.$icon.'" alt="" class="LC_icon" />',600,500);
1.469 www 2903: } else {
2904: $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
2905: }
1.519 raeburn 2906: $line.='</span></td><td'.$tdwidth.'>';
1.472 raeburn 2907: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.469 www 2908: $line.='<a href="'.$url.'">'.$title.'</a>';
2909: } elsif ($url) {
1.484 raeburn 2910: $line.=&Apache::loncommon::modal_link($url.(($url=~/\?/)?'&':'?').'inhibitmenu=yes',
1.470 raeburn 2911: $title,600,500);
1.469 www 2912: } else {
2913: $line.=$title.' <span class="LC_docs_reinit_warn">'.$reinit.'</span>';
2914: }
1.518 raeburn 2915: $line.="$extresform</td>";
1.478 raeburn 2916: $rand_pick_text = ' ' if ($rand_pick_text eq '');
2917: $rand_order_text = ' ' if ($rand_order_text eq '');
1.329 droeschl 2918: if (($allowed) && ($folder!~/^supplemental/)) {
2919: my %lt=&Apache::lonlocal::texthash(
2920: 'hd' => 'Hidden',
2921: 'ec' => 'URL hidden');
2922: my $enctext=
1.358 bisitz 2923: ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i?' checked="checked"':'');
1.329 droeschl 2924: my $hidtext=
1.358 bisitz 2925: ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i?' checked="checked"':'');
1.537 ! raeburn 2926: my $formhidden = 'edit_hiddenresource_'.$orderidx;
! 2927: my $formurlhidden = 'edit_encrypturl_'.$orderidx;
1.329 droeschl 2928: $line.=(<<ENDPARMS);
2929: <td class="LC_docs_entry_parameter">
1.537 ! raeburn 2930: <form action="/adm/coursedocs" method="post" name="$formhidden">
1.478 raeburn 2931: $form_common
1.537 ! raeburn 2932: <label><input type="checkbox" name="hiddenresource_$orderidx" id="hiddenresource_$orderidx" onclick="checkForSubmit(this.form,'."'hiddenresource'".');" $hidtext /> $lt{'hd'}</label>
1.329 droeschl 2933: $form_end
1.458 raeburn 2934: <br />
1.537 ! raeburn 2935: <form action="/adm/coursedocs" method="post" name="$formurlhidden">
1.478 raeburn 2936: $form_common
1.537 ! raeburn 2937: <label><input type="checkbox" name="encrypturl_$orderidx" id="encrypturl_$orderidx" onclick="checkForSubmit(this.form,'."'encrypturl'".');" $enctext /> $lt{'ec'}</label>
1.329 droeschl 2938: $form_end
2939: </td>
1.478 raeburn 2940: <td class="LC_docs_entry_parameter">$rand_pick_text<br />
2941: $rand_order_text</td>
1.329 droeschl 2942: ENDPARMS
2943: }
1.379 bisitz 2944: $line.=&Apache::loncommon::end_data_table_row();
1.329 droeschl 2945: return $line;
2946: }
2947:
1.533 raeburn 2948: sub new_timebased_suffix {
2949: my ($coursedom,$coursenum,$type,$area,$container) = @_;
2950: my ($prefix,$namespace,$idtype,$errtext,$locknotfreed);
2951: if ($type eq 'map') {
2952: $prefix = 'docs';
2953: if ($area eq 'supplemental') {
2954: $prefix = 'supp';
2955: }
2956: $prefix .= $container;
2957: $namespace = 'uploadedmaps';
2958: } else {
2959: $prefix = $type;
2960: $namespace = 'templated';
1.504 raeburn 2961: }
2962: $idtype = 'concat';
2963: my ($suffix,$freedlock,$error) =
1.533 raeburn 2964: &Apache::lonnet::get_timebased_id($prefix,'num',$namespace,
1.504 raeburn 2965: $coursedom,$coursenum);
2966: if (!$suffix) {
1.533 raeburn 2967: if ($type eq 'map') {
2968: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new folder/page.');
2969: } elsif ($type eq 'smppg') {
2970: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new simple page.');
2971: } else {
2972: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new bulletin board.');
2973: }
1.504 raeburn 2974: if ($error) {
2975: $errtext .= '<br />'.$error;
2976: }
2977: }
2978: if ($freedlock ne 'ok') {
1.533 raeburn 2979: $locknotfreed =
2980: '<div class="LC_error">'.
2981: &mt('There was a problem removing a lockfile.').' ';
2982: if ($type eq 'map') {
2983: &mt('This will prevent creation of additional folders or composite pages in this course.');
2984: } elsif ($type eq 'smppg') {
2985: $locknotfreed .=
2986: &mt('This will prevent creation of additional simple pages in this course.');
2987: } else {
2988: $locknotfreed .=
2989: &mt('This will prevent creation of additional bulletin boards in this course.');
2990: }
2991: $locknotfreed .=
2992: ' '.&mt('Please contact the domain coordinator for your LON-CAPA domain.').
2993: '</div>';
1.504 raeburn 2994: }
2995: return ($suffix,$errtext,$locknotfreed);
2996: }
2997:
1.329 droeschl 2998: =pod
2999:
3000: =item tiehash()
3001:
3002: tie the hash
3003:
3004: =cut
3005:
3006: sub tiehash {
3007: my ($mode)=@_;
3008: $hashtied=0;
3009: if ($env{'request.course.fn'}) {
3010: if ($mode eq 'write') {
3011: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
3012: &GDBM_WRCREAT(),0640)) {
3013: $hashtied=2;
3014: }
3015: } else {
3016: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
3017: &GDBM_READER(),0640)) {
3018: $hashtied=1;
3019: }
3020: }
1.364 bisitz 3021: }
1.329 droeschl 3022: }
3023:
3024: sub untiehash {
3025: if ($hashtied) { untie %hash; }
3026: $hashtied=0;
3027: return OK;
3028: }
3029:
3030:
3031:
3032:
3033: sub checkonthis {
3034: my ($r,$url,$level,$title)=@_;
3035: $url=&unescape($url);
3036: $alreadyseen{$url}=1;
3037: $r->rflush();
3038: if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
3039: $r->print("\n<br />");
3040: if ($level==0) {
3041: $r->print("<br />");
3042: }
3043: for (my $i=0;$i<=$level*5;$i++) {
3044: $r->print(' ');
3045: }
3046: $r->print('<a href="'.$url.'" target="cat">'.
3047: ($title?$title:$url).'</a> ');
3048: if ($url=~/^\/res\//) {
3049: my $result=&Apache::lonnet::repcopy(
3050: &Apache::lonnet::filelocation('',$url));
3051: if ($result eq 'ok') {
3052: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
3053: $r->rflush();
3054: &Apache::lonnet::countacc($url);
3055: $url=~/\.(\w+)$/;
3056: if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
3057: $r->print('<br />');
3058: $r->rflush();
3059: for (my $i=0;$i<=$level*5;$i++) {
3060: $r->print(' ');
3061: }
3062: $r->print('- '.&mt('Rendering:').' ');
3063: my ($errorcount,$warningcount)=split(/:/,
3064: &Apache::lonnet::ssi_body($url,
3065: ('grade_target'=>'web',
3066: 'return_only_error_and_warning_counts' => 1)));
3067: if (($errorcount) ||
3068: ($warningcount)) {
3069: if ($errorcount) {
1.369 bisitz 3070: $r->print('<img src="/adm/lonMisc/bomb.gif" alt="'.&mt('bomb').'" /><span class="LC_error">'.
1.329 droeschl 3071: &mt('[quant,_1,error]',$errorcount).'</span>');
3072: }
3073: if ($warningcount) {
3074: $r->print('<span class="LC_warning">'.
3075: &mt('[quant,_1,warning]',$warningcount).'</span>');
3076: }
3077: } else {
3078: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
3079: }
3080: $r->rflush();
3081: }
3082: my $dependencies=
3083: &Apache::lonnet::metadata($url,'dependencies');
3084: foreach my $dep (split(/\,/,$dependencies)) {
3085: if (($dep=~/^\/res\//) && (!$alreadyseen{$dep})) {
3086: &checkonthis($r,$dep,$level+1);
3087: }
3088: }
3089: } elsif ($result eq 'unavailable') {
3090: $r->print('<span class="LC_error">'.&mt('connection down').'</span>');
3091: } elsif ($result eq 'not_found') {
3092: unless ($url=~/\$/) {
1.521 bisitz 3093: $r->print('<span class="LC_error">'.&mt('not found').'</span>');
1.329 droeschl 3094: } else {
1.366 bisitz 3095: $r->print('<span class="LC_error">'.&mt('unable to verify variable URL').'</span>');
1.329 droeschl 3096: }
3097: } else {
3098: $r->print('<span class="LC_error">'.&mt('access denied').'</span>');
3099: }
3100: }
3101: }
3102: }
3103:
3104:
3105:
3106: =pod
3107:
3108: =item list_symbs()
3109:
1.485 raeburn 3110: List Content Identifiers
1.329 droeschl 3111:
3112: =cut
3113:
3114: sub list_symbs {
3115: my ($r) = @_;
3116:
1.408 raeburn 3117: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 3118: $r->print(&Apache::loncommon::start_page('List of Content Identifiers'));
3119: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Identifiers'));
3120: $r->print(&startContentScreen('tools'));
1.329 droeschl 3121: my $navmap = Apache::lonnavmaps::navmap->new();
3122: if (!defined($navmap)) {
3123: $r->print('<h2>'.&mt('Retrieval of List Failed').'</h2>'.
3124: '<div class="LC_error">'.
3125: &mt('Unable to retrieve information about course contents').
3126: '</div>');
1.408 raeburn 3127: &Apache::lonnet::logthis('Symb list failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
1.329 droeschl 3128: } else {
1.484 raeburn 3129: $r->print('<h4 class="LC_info">'.&mt("$crstype Content Identifiers").'</h4>'.
3130: &Apache::loncommon::start_data_table().
3131: &Apache::loncommon::start_data_table_header_row().
3132: '<th>'.&mt('Title').'</th><th>'.&mt('Identifier').'</th>'.
3133: &Apache::loncommon::end_data_table_header_row()."\n");
3134: my $count;
1.329 droeschl 3135: foreach my $res ($navmap->retrieveResources()) {
1.484 raeburn 3136: $r->print(&Apache::loncommon::start_data_table_row().
3137: '<td>'.$res->compTitle().'</td>'.
3138: '<td>'.$res->symb().'</td>'.
1.521 bisitz 3139: &Apache::loncommon::end_data_table_row());
1.484 raeburn 3140: $count ++;
3141: }
3142: if (!$count) {
3143: $r->print(&Apache::loncommon::start_data_table_row().
3144: '<td colspan="2">'.&mt("$crstype is empty").'</td>'.
3145: &Apache::loncommon::end_data_table_row());
1.329 droeschl 3146: }
1.484 raeburn 3147: $r->print(&Apache::loncommon::end_data_table());
1.329 droeschl 3148: }
1.521 bisitz 3149: $r->print(&endContentScreen());
1.329 droeschl 3150: }
3151:
3152:
3153: sub verifycontent {
3154: my ($r) = @_;
1.408 raeburn 3155: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 3156: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Documents'));
3157: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Documents'));
3158: $r->print(&startContentScreen('tools'));
3159: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
1.329 droeschl 3160: $hashtied=0;
3161: undef %alreadyseen;
3162: %alreadyseen=();
3163: &tiehash();
1.484 raeburn 3164:
1.329 droeschl 3165: foreach my $key (keys(%hash)) {
3166: if ($hash{$key}=~/\.(page|sequence)$/) {
3167: if (($key=~/^src_/) && ($alreadyseen{&unescape($hash{$key})})) {
3168: $r->print('<hr /><span class="LC_error">'.
1.419 bisitz 3169: &mt('The following sequence or page is included more than once in your '.$crstype.':').' '.
1.329 droeschl 3170: &unescape($hash{$key}).'</span><br />'.
1.419 bisitz 3171: &mt('Note that grading records for problems included in this sequence or folder will overlap.').'<hr />');
1.329 droeschl 3172: }
3173: }
3174: if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) {
3175: &checkonthis($r,$hash{$key},0,$hash{'title_'.$1});
3176: }
3177: }
3178: &untiehash();
1.442 www 3179: $r->print('<p class="LC_success">'.&mt('Done').'</p>');
1.521 bisitz 3180: $r->print(&endContentScreen());
1.329 droeschl 3181: }
3182:
3183:
3184: sub devalidateversioncache {
3185: my $src=shift;
3186: &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
3187: &Apache::lonnet::clutter($src));
3188: }
3189:
3190: sub checkversions {
3191: my ($r) = @_;
1.408 raeburn 3192: my $crstype = &Apache::loncommon::course_type();
3193: $r->print(&Apache::loncommon::start_page("Check $crstype Document Versions"));
3194: $r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $crstype Document Versions"));
1.484 raeburn 3195: $r->print(&startContentScreen('tools'));
1.442 www 3196:
1.329 droeschl 3197: my $header='';
3198: my $startsel='';
3199: my $monthsel='';
3200: my $weeksel='';
3201: my $daysel='';
3202: my $allsel='';
3203: my %changes=();
3204: my $starttime=0;
3205: my $haschanged=0;
3206: my %setversions=&Apache::lonnet::dump('resourceversions',
3207: $env{'course.'.$env{'request.course.id'}.'.domain'},
3208: $env{'course.'.$env{'request.course.id'}.'.num'});
3209:
3210: $hashtied=0;
3211: &tiehash();
3212: my %newsetversions=();
3213: if ($env{'form.setmostrecent'}) {
3214: $haschanged=1;
3215: foreach my $key (keys(%hash)) {
3216: if ($key=~/^ids\_(\/res\/.+)$/) {
3217: $newsetversions{$1}='mostrecent';
3218: &devalidateversioncache($1);
3219: }
3220: }
3221: } elsif ($env{'form.setcurrent'}) {
3222: $haschanged=1;
3223: foreach my $key (keys(%hash)) {
3224: if ($key=~/^ids\_(\/res\/.+)$/) {
3225: my $getvers=&Apache::lonnet::getversion($1);
3226: if ($getvers>0) {
3227: $newsetversions{$1}=$getvers;
3228: &devalidateversioncache($1);
3229: }
3230: }
3231: }
3232: } elsif ($env{'form.setversions'}) {
3233: $haschanged=1;
3234: foreach my $key (keys(%env)) {
3235: if ($key=~/^form\.set_version_(.+)$/) {
3236: my $src=$1;
3237: if (($env{$key}) && ($env{$key} ne $setversions{$src})) {
3238: $newsetversions{$src}=$env{$key};
3239: &devalidateversioncache($src);
3240: }
3241: }
3242: }
3243: }
3244: if ($haschanged) {
3245: if (&Apache::lonnet::put('resourceversions',\%newsetversions,
3246: $env{'course.'.$env{'request.course.id'}.'.domain'},
1.344 bisitz 3247: $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
1.479 golterma 3248: $r->print(&Apache::loncommon::confirmwrapper(
3249: &Apache::lonhtmlcommon::confirm_success(&mt('Your Version Settings have been Saved'))));
1.329 droeschl 3250: } else {
1.479 golterma 3251: $r->print(&Apache::loncommon::confirmwrapper(
3252: &Apache::lonhtmlcommon::confirm_success(&mt('An Error Occured while Attempting to Save your Version Settings'),1)));
1.329 droeschl 3253: }
3254: &mark_hash_old();
3255: }
3256: &changewarning($r,'');
3257: if ($env{'form.timerange'} eq 'all') {
3258: # show all documents
1.408 raeburn 3259: $header=&mt('All Documents in '.$crstype);
1.521 bisitz 3260: $allsel=' selected="selected"';
1.329 droeschl 3261: foreach my $key (keys(%hash)) {
3262: if ($key=~/^ids\_(\/res\/.+)$/) {
3263: my $src=$1;
3264: $changes{$src}=1;
3265: }
3266: }
3267: } else {
3268: # show documents which changed
3269: %changes=&Apache::lonnet::dump
3270: ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
3271: $env{'course.'.$env{'request.course.id'}.'.num'});
3272: my $firstkey=(keys(%changes))[0];
3273: unless ($firstkey=~/^error\:/) {
3274: unless ($env{'form.timerange'}) {
3275: $env{'form.timerange'}=604800;
3276: }
3277: my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
3278: .&mt('seconds');
3279: if ($env{'form.timerange'}==-1) {
3280: $seltext='since start of course';
1.521 bisitz 3281: $startsel=' selected="selected"';
1.329 droeschl 3282: $env{'form.timerange'}=time;
3283: }
3284: $starttime=time-$env{'form.timerange'};
3285: if ($env{'form.timerange'}==2592000) {
3286: $seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 3287: $monthsel=' selected="selected"';
1.329 droeschl 3288: } elsif ($env{'form.timerange'}==604800) {
3289: $seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 3290: $weeksel=' selected="selected"';
1.329 droeschl 3291: } elsif ($env{'form.timerange'}==86400) {
3292: $seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 3293: $daysel=' selected="selected"';
1.329 droeschl 3294: }
3295: $header=&mt('Content changed').' '.$seltext;
3296: } else {
3297: $header=&mt('No content modifications yet.');
3298: }
3299: }
3300: %setversions=&Apache::lonnet::dump('resourceversions',
3301: $env{'course.'.$env{'request.course.id'}.'.domain'},
3302: $env{'course.'.$env{'request.course.id'}.'.num'});
3303: my %lt=&Apache::lonlocal::texthash
1.408 raeburn 3304: ('st' => 'Version changes since start of '.$crstype,
1.329 droeschl 3305: 'lm' => 'Version changes since last Month',
3306: 'lw' => 'Version changes since last Week',
3307: 'sy' => 'Version changes since Yesterday',
3308: 'al' => 'All Resources (possibly large output)',
1.484 raeburn 3309: 'cd' => 'Change display',
1.329 droeschl 3310: 'sd' => 'Display',
3311: 'fi' => 'File',
3312: 'md' => 'Modification Date',
3313: 'mr' => 'Most recently published Version',
1.408 raeburn 3314: 've' => 'Version used in '.$crstype,
3315: 'vu' => 'Set Version to be used in '.$crstype,
3316: 'sv' => 'Set Versions to be used in '.$crstype.' according to Selections below',
1.329 droeschl 3317: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
3318: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
1.479 golterma 3319: 'di' => 'Differences',
1.484 raeburn 3320: 'save' => 'Save changes',
3321: 'vers' => 'Version choice(s) for specific resources',
1.479 golterma 3322: 'act' => 'Actions');
1.329 droeschl 3323: $r->print(<<ENDHEADERS);
1.484 raeburn 3324: <h4 class="LC_info">$header</h4>
1.329 droeschl 3325: <form action="/adm/coursedocs" method="post">
3326: <input type="hidden" name="versions" value="1" />
1.484 raeburn 3327: <div class="LC_left_float">
1.479 golterma 3328: <fieldset>
1.484 raeburn 3329: <legend>$lt{'cd'}</legend>
1.329 droeschl 3330: <select name="timerange">
1.521 bisitz 3331: <option value='all'$allsel>$lt{'al'}</option>
3332: <option value="-1"$startsel>$lt{'st'}</option>
3333: <option value="2592000"$monthsel>$lt{'lm'}</option>
3334: <option value="604800"$weeksel>$lt{'lw'}</option>
3335: <option value="86400"$daysel>$lt{'sy'}</option>
1.329 droeschl 3336: </select>
3337: <input type="submit" name="display" value="$lt{'sd'}" />
1.484 raeburn 3338: </fieldset>
3339: </div>
3340: <div class="LC_left_float">
3341: <fieldset>
3342: <legend>$lt{'act'}</legend>
3343: $lt{'sm'}: <input type="submit" name="setmostrecent" value="Go" /><br />
3344: $lt{'sc'}: <input type="submit" name="setcurrent" value="Go" />
3345: </fieldset>
3346: </div>
3347: <br clear="all" />
3348: <hr />
3349: <h4>$lt{'vers'}</h4>
1.479 golterma 3350: <input type="submit" name="setversions" value="$lt{'save'}" />
1.329 droeschl 3351: ENDHEADERS
1.479 golterma 3352: #number of columns for version history
3353: $r->print(
1.521 bisitz 3354: &Apache::loncommon::start_data_table().
3355: &Apache::loncommon::start_data_table_header_row().
3356: '<th>'.&mt('Resources').'</th>'.
3357: "<th>$lt{'mr'}</th>".
3358: "<th>$lt{'ve'}</th>".
3359: "<th>$lt{'vu'}</th>".
3360: '<th>'.&mt('History').'</th>'.
3361: &Apache::loncommon::end_data_table_header_row()
3362: );
1.329 droeschl 3363: foreach my $key (sort(keys(%changes))) {
1.496 golterma 3364: #excludes not versionable problems from resource version history:
1.521 bisitz 3365: next unless ($changes{$key}>$starttime && $key !~ /^\/res\/lib\/templates/);
3366: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
3367: my $currentversion=&Apache::lonnet::getversion($key);
3368: if ($currentversion<0) {
3369: $currentversion='<span class="LC_error">'.&mt('Could not be determined.').'</span>';
3370: }
3371: my $linkurl=&Apache::lonnet::clutter($key);
1.479 golterma 3372: $r->print(
3373: &Apache::loncommon::start_data_table_row().
1.521 bisitz 3374: '<td><b>'.&Apache::lonnet::gettitle($linkurl).'</b><br />'.
1.479 golterma 3375: '<a href="'.$linkurl.'" target="cat">'.$linkurl.'</a></td>'.
1.521 bisitz 3376: '<td align="right">'.$currentversion.'<span class="LC_fontsize_medium"><br />('.
1.479 golterma 3377: &Apache::lonlocal::locallocaltime(&Apache::lonnet::metadata($root.'.'.$extension,'lastrevisiondate')).')</span></td>'.
1.521 bisitz 3378: '<td align="right">'
3379: );
3380: # Used in course
3381: my $usedversion=$hash{'version_'.$linkurl};
3382: if (($usedversion) && ($usedversion ne 'mostrecent')) {
3383: if ($usedversion != $currentversion) {
1.479 golterma 3384: $r->print('<span class="LC_warning">'.$usedversion.'</span>');
1.521 bisitz 3385: } else {
1.479 golterma 3386: $r->print($usedversion);
3387: }
1.329 droeschl 3388: } else {
1.521 bisitz 3389: $r->print($currentversion);
1.329 droeschl 3390: }
1.521 bisitz 3391: $r->print('</td><td title="'.$lt{'vu'}.'">');
3392: # Set version
3393: $r->print(&Apache::loncommon::select_form(
3394: $setversions{$linkurl},
3395: 'set_version_'.$linkurl,
3396: {'select_form_order' => ['',1..$currentversion,'mostrecent'],
3397: '' => '',
3398: 'mostrecent' => &mt('most recent'),
3399: map {$_,$_} (1..$currentversion)}));
3400: my $lastold=1;
3401: for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
3402: my $url=$root.'.'.$prevvers.'.'.$extension;
3403: if (&Apache::lonnet::metadata($url,'lastrevisiondate')<$starttime) {
3404: $lastold=$prevvers;
3405: }
3406: }
3407: $r->print('</td>');
3408: # List all available versions
3409: $r->print('<td valign="top"><span class="LC_fontsize_medium">');
3410: for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
3411: my $url=$root.'.'.$prevvers.'.'.$extension;
3412: $r->print(
3413: '<span class="LC_nobreak">'
3414: .'<a href="'.&Apache::lonnet::clutter($url).'">'
3415: .&mt('Version [_1]',$prevvers).'</a>'
3416: .' ('.&Apache::lonlocal::locallocaltime(
3417: &Apache::lonnet::metadata($url,'lastrevisiondate'))
3418: .')');
3419: if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
3420: $r->print(
3421: ' <a href="/adm/diff?filename='.
3422: &Apache::lonnet::clutter($root.'.'.$extension).
3423: &HTML::Entities::encode('&versionone='.$prevvers,'"<>&').
3424: '" target="diffs">'.&mt('Diffs').'</a>');
1.329 droeschl 3425: }
1.521 bisitz 3426: $r->print('</span><br />');
3427: }
3428: $r->print('</span></td>'.&Apache::loncommon::end_data_table_row());
1.329 droeschl 3429: }
1.521 bisitz 3430: $r->print(
3431: &Apache::loncommon::end_data_table().
3432: '<input type="submit" name="setversions" value="'.$lt{'save'}.'" />'.
3433: '</form>'
3434: );
1.329 droeschl 3435:
3436: &untiehash();
1.521 bisitz 3437: $r->print(&endContentScreen());
1.329 droeschl 3438: }
3439:
3440: sub mark_hash_old {
3441: my $retie_hash=0;
3442: if ($hashtied) {
3443: $retie_hash=1;
3444: &untiehash();
3445: }
3446: &tiehash('write');
3447: $hash{'old'}=1;
3448: &untiehash();
3449: if ($retie_hash) { &tiehash(); }
3450: }
3451:
3452: sub is_hash_old {
3453: my $untie_hash=0;
3454: if (!$hashtied) {
3455: $untie_hash=1;
3456: &tiehash();
3457: }
3458: my $return=$hash{'old'};
3459: if ($untie_hash) { &untiehash(); }
3460: return $return;
3461: }
3462:
3463: sub changewarning {
3464: my ($r,$postexec,$message,$url)=@_;
3465: if (!&is_hash_old()) { return; }
3466: my $pathvar='folderpath';
3467: my $path=&escape($env{'form.folderpath'});
3468: if (!defined($url)) {
3469: $url='/adm/coursedocs?'.$pathvar.'='.$path;
3470: }
3471: my $course_type = &Apache::loncommon::course_type();
3472: if (!defined($message)) {
3473: $message='Changes will become active for your current session after [_1], or the next time you log in.';
3474: }
3475: $r->print("\n\n".
1.372 bisitz 3476: '<script type="text/javascript">'."\n".
3477: '// <![CDATA['."\n".
3478: 'function reinit(tf) { tf.submit();'.$postexec.' }'."\n".
3479: '// ]]>'."\n".
1.369 bisitz 3480: '</script>'."\n".
1.375 tempelho 3481: '<form name="reinitform" method="post" action="/adm/roles" target="loncapaclient">'.
1.329 droeschl 3482: '<input type="hidden" name="orgurl" value="'.$url.
1.372 bisitz 3483: '" /><input type="hidden" name="selectrole" value="1" /><p class="LC_warning">'.
1.329 droeschl 3484: &mt($message,' <input type="hidden" name="'.
3485: $env{'request.role'}.'" value="1" /><input type="button" value="'.
1.369 bisitz 3486: &mt('re-initializing '.$course_type).'" onclick="reinit(this.form)" />').
1.372 bisitz 3487: $help{'Caching'}.'</p></form>'."\n\n");
1.329 droeschl 3488: }
3489:
3490:
3491: sub init_breadcrumbs {
3492: my ($form,$text)=@_;
3493: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.484 raeburn 3494: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1",
1.405 bisitz 3495: text=>&Apache::loncommon::course_type().' Editor',
1.329 droeschl 3496: faq=>273,
3497: bug=>'Instructor Interface',
3498: help => 'Docs_Adding_Course_Doc'});
3499: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?".$form.'=1',
3500: text=>$text,
3501: faq=>273,
3502: bug=>'Instructor Interface'});
3503: }
3504:
1.441 www 3505: # subroutine to list form elements
3506: sub create_list_elements {
3507: my @formarr = @_;
3508: my $list = '';
1.501 raeburn 3509: foreach my $button (@formarr){
3510: foreach my $picture (keys(%{$button})) {
3511: $list .= &Apache::lonhtmlcommon::htmltag('li', $picture.' '.$button->{$picture}, {class => 'LC_menubuttons_inline_text', id => ''});
1.441 www 3512: }
3513: }
3514: return $list;
3515: }
1.329 droeschl 3516:
1.441 www 3517: # subroutine to create ul from list elements
3518: sub create_form_ul {
3519: my $list = shift;
3520: my $ul = &Apache::lonhtmlcommon::htmltag('ul',$list, {class => 'LC_ListStyleNormal'});
3521: return $ul;
3522: }
1.329 droeschl 3523:
1.442 www 3524: #
3525: # Start tabs
3526: #
3527:
3528: sub startContentScreen {
1.484 raeburn 3529: my ($mode) = @_;
3530: my $output = '<ul class="LC_TabContentBigger" id="mainnav">';
1.472 raeburn 3531: if (($mode eq 'navmaps') || ($mode eq 'supplemental')) {
1.484 raeburn 3532: $output .= '<li'.(($mode eq 'navmaps')?' class="active"':'').'><a href="/adm/navmaps"><b> '.&mt('Content Overview').' </b></a></li>'."\n";
3533: $output .= '<li'.(($mode eq 'coursesearch')?' class="active"':'').'><a href="/adm/searchcourse"><b> '.&mt('Content Search').' </b></a></li>'."\n";
3534: $output .= '<li'.(($mode eq 'courseindex')?' class="active"':'').'><a href="/adm/indexcourse"><b> '.&mt('Content Index').' </b></a></li>'."\n";
3535: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/supplemental"><b>'.&mt('Supplemental Content').'</b></a></li>';
3536: } else {
3537: $output .= '<li '.(($mode eq 'docs')?' class="active"':'').' id="tabbededitor"><a href="/adm/coursedocs?forcestandard=1"><b> '.&mt('Content Editor').' </b></a></li>'."\n";
3538: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/coursedocs?forcesupplement=1"><b>'.&mt('Supplemental Content Editor').'</b></a></li>'."\n";
3539: $output .= '<li '.(($mode eq 'tools')?' class="active"':'').'><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>'."\n";
3540: '><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>';
3541: }
3542: $output .= "\n".'</ul>'."\n";
3543: $output .= '<div class="LC_DocsBox" style="clear:both;margin:0;" id="contenteditor">'.
3544: '<div id="maincoursedoc" style="margin:0 0;padding:0 0;">'.
3545: '<div class="LC_ContentBox" id="mainCourseDocuments" style="display: block;">';
3546: return $output;
1.442 www 3547: }
3548:
3549: #
3550: # End tabs
3551: #
3552:
3553: sub endContentScreen {
1.484 raeburn 3554: return '</div></div></div>';
1.442 www 3555: }
1.329 droeschl 3556:
1.446 www 3557: sub supplemental_base {
1.472 raeburn 3558: return 'supplemental&'.&escape(&mt('Supplemental '.&Apache::loncommon::course_type().' Content'));
1.446 www 3559: }
3560:
1.329 droeschl 3561: sub handler {
3562: my $r = shift;
3563: &Apache::loncommon::content_type($r,'text/html');
3564: $r->send_http_header;
3565: return OK if $r->header_only;
1.484 raeburn 3566:
3567: # get course data
1.408 raeburn 3568: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 3569: my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
3570: my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
3571:
3572: # graphics settings
3573: $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL').'/');
1.329 droeschl 3574:
1.443 www 3575: #
1.329 droeschl 3576: # --------------------------------------------- Initialize help topics for this
3577: foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',
3578: 'Adding_External_Resource','Navigate_Content',
3579: 'Adding_Folders','Docs_Overview', 'Load_Map',
3580: 'Supplemental','Score_Upload_Form','Adding_Pages',
1.501 raeburn 3581: 'Importing_LON-CAPA_Resource','Importing_IMS_Course',
3582: 'Uploading_From_Harddrive',
1.329 droeschl 3583: 'Check_Resource_Versions','Verify_Content') {
3584: $help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
3585: }
3586: # Composite help files
3587: $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
3588: 'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
3589: $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
3590: 'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
3591: $help{'Simple Problem'} = &Apache::loncommon::help_open_topic(
3592: 'Option_Response_Simple');
3593: $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
3594: 'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
1.347 weissno 3595: $help{'My Personal Information Page'} = &Apache::loncommon::help_open_topic(
1.329 droeschl 3596: 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
1.353 weissno 3597: $help{'Group Portfolio'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
1.329 droeschl 3598: $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
1.534 raeburn 3599: $help{'Course Roster'} = &Apache::loncommon::help_open_topic('Docs_Course_Roster');
3600: $help{'Web Page'} = &Apache::loncommon::help_open_topic('Docs_Web_Page');
3601:
1.472 raeburn 3602: my $allowed;
3603: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
3604: unless ($r->uri eq '/adm/supplemental') {
3605: # does this user have privileges to modify content.
3606: $allowed = &Apache::lonnet::allowed('mdc',$env{'request.course.id'});
3607: }
3608:
1.484 raeburn 3609: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['chooseserver',
3610: 'inhibitmenu']);
3611: if ($allowed && $env{'form.chooseserver'}) {
3612: &choose_dump_server($r);
3613: return OK;
3614: } elsif ($allowed && $env{'form.verify'}) {
1.329 droeschl 3615: &init_breadcrumbs('verify','Verify Content');
3616: &verifycontent($r);
3617: } elsif ($allowed && $env{'form.listsymbs'}) {
1.484 raeburn 3618: &init_breadcrumbs('listsymbs','List Content IDs');
1.329 droeschl 3619: &list_symbs($r);
3620: } elsif ($allowed && $env{'form.docslog'}) {
3621: &init_breadcrumbs('docslog','Show Log');
1.484 raeburn 3622: my $folder = $env{'form.folder'};
3623: if ($folder eq '') {
3624: $folder='default';
3625: }
3626: &docs_change_log($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath);
1.329 droeschl 3627: } elsif ($allowed && $env{'form.versions'}) {
3628: &init_breadcrumbs('versions','Check/Set Resource Versions');
3629: &checkversions($r);
3630: } elsif ($allowed && $env{'form.dumpcourse'}) {
1.484 raeburn 3631: &init_breadcrumbs('dumpcourse','Dump '.&Apache::loncommon::course_type().' Content to Authoring Space');
1.329 droeschl 3632: &dumpcourse($r);
3633: } elsif ($allowed && $env{'form.exportcourse'}) {
1.377 bisitz 3634: &init_breadcrumbs('exportcourse','IMS Export');
1.475 raeburn 3635: &Apache::imsexport::exportcourse($r);
1.329 droeschl 3636: } else {
1.445 www 3637: #
3638: # Done catching special calls
1.484 raeburn 3639: # The whole rest is for course and supplemental documents and utilities menu
1.445 www 3640: # Get the parameters that may be needed
3641: #
3642: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.519 raeburn 3643: ['folderpath',
3644: 'forcesupplement','forcestandard',
1.510 raeburn 3645: 'tools','symb','command','supppath']);
1.445 www 3646:
3647: # standard=1: this is a "new-style" course with an uploaded map as top level
3648: # standard=2: this is a "old-style" course, and there is nothing we can do
1.329 droeschl 3649:
3650: my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
1.445 www 3651:
1.484 raeburn 3652: # Decide whether this should display supplemental or main content or utilities
1.445 www 3653: # supplementalflag=1: show supplemental documents
3654: # supplementalflag=0: show standard documents
1.484 raeburn 3655: # toolsflag=1: show utilities
1.445 www 3656:
3657:
3658: my $supplementalflag=($env{'form.folderpath'}=~/^supplemental/);
1.519 raeburn 3659: if (($env{'form.folderpath'}=~/^default/) || ($env{'form.folderpath'} eq "")) {
1.445 www 3660: $supplementalflag=0;
3661: }
3662: if ($env{'form.forcesupplement'}) { $supplementalflag=1; }
3663: if ($env{'form.forcestandard'}) { $supplementalflag=0; }
3664: unless ($allowed) { $supplementalflag=1; }
3665: unless ($standard) { $supplementalflag=1; }
1.484 raeburn 3666: my $toolsflag=0;
3667: if ($env{'form.tools'}) { $toolsflag=1; }
1.445 www 3668:
1.329 droeschl 3669: my $script='';
3670: my $showdoc=0;
1.457 raeburn 3671: my $addentries = {};
1.475 raeburn 3672: my $container;
1.329 droeschl 3673: my $containertag;
1.508 raeburn 3674: my $pathitem;
1.329 droeschl 3675:
1.464 www 3676: # Do we directly jump somewhere?
1.466 www 3677:
1.525 raeburn 3678: if (($env{'form.command'} eq 'direct') || ($env{'form.command'} eq 'directnav')) {
1.472 raeburn 3679: if ($env{'form.symb'} ne '') {
1.522 raeburn 3680: $env{'form.folderpath'}=
3681: &Apache::loncommon::symb_to_docspath($env{'form.symb'});
1.530 raeburn 3682: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
1.525 raeburn 3683: $env{'form.command'}.'_'.$env{'form.symb'}});
1.472 raeburn 3684: } elsif ($env{'form.supppath'} ne '') {
3685: $env{'form.folderpath'}=$env{'form.supppath'};
1.530 raeburn 3686: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
1.525 raeburn 3687: $env{'form.command'}.'_'.$env{'form.supppath'}});
1.466 www 3688: }
1.472 raeburn 3689: } elsif ($env{'form.command'} eq 'editdocs') {
1.525 raeburn 3690: $env{'form.folderpath'} = 'default&'.
3691: &Apache::lonhtmlcommon::entity_encode('Main Course Content').
3692: ':::::';
3693: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => $env{'form.command'}});
1.472 raeburn 3694: } elsif ($env{'form.command'} eq 'editsupp') {
1.525 raeburn 3695: $env{'form.folderpath'} = 'supplemental&'.
1.472 raeburn 3696: &Apache::lonhtmlcommon::entity_encode('Supplemental Content');
1.525 raeburn 3697: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/supplemental'});
3698: } elsif ($env{'form.command'} eq 'contents') {
3699: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/navmaps'});
3700: } elsif ($env{'form.command'} eq 'home') {
3701: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/menu'});
1.464 www 3702: }
3703:
1.525 raeburn 3704:
1.445 www 3705: # Where do we store these for when we come back?
3706: my $stored_folderpath='docs_folderpath';
3707: if ($supplementalflag) {
3708: $stored_folderpath='docs_sup_folderpath';
3709: }
1.464 www 3710:
1.519 raeburn 3711: # No folderpath, and in edit mode, see if we have something stored
3712: if ((!$env{'form.folderpath'}) && $allowed) {
1.445 www 3713: &Apache::loncommon::restore_course_settings($stored_folderpath,
1.510 raeburn 3714: {'folderpath' => 'scalar'});
1.523 raeburn 3715: unless (&unescape($env{'form.folderpath'}) =~ m{^(default|supplemental)&}) {
3716: undef($env{'form.folderpath'});
3717: }
1.329 droeschl 3718: }
1.446 www 3719:
3720: # If we are not allowed to make changes, all we can see are supplemental docs
1.409 raeburn 3721: if (!$allowed) {
1.446 www 3722: unless ($env{'form.folderpath'} =~ /^supplemental/) {
3723: $env{'form.folderpath'} = &supplemental_base();
1.409 raeburn 3724: }
3725: }
1.446 www 3726: # Make the zeroth entry in supplemental docs page paths, so we can get to top level
1.329 droeschl 3727: if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
1.446 www 3728: $env{'form.folderpath'} = &supplemental_base()
3729: .'&'.
1.329 droeschl 3730: $env{'form.folderpath'};
3731: }
1.446 www 3732: # If after all of this, we still don't have any paths, make them
1.519 raeburn 3733: unless ($env{'form.folderpath'}) {
1.446 www 3734: if ($supplementalflag) {
3735: $env{'form.folderpath'}=&supplemental_base();
3736: } else {
1.519 raeburn 3737: $env{'form.folderpath'}='default'.&escape(&mt('Main '.$crstype.' Documents')).
3738: ':::::';
1.446 www 3739: }
1.472 raeburn 3740: }
1.446 www 3741:
1.445 www 3742: # Store this
1.484 raeburn 3743: unless ($toolsflag) {
1.510 raeburn 3744: if ($allowed) {
3745: &Apache::loncommon::store_course_settings($stored_folderpath,
1.519 raeburn 3746: {'folderpath' => 'scalar'});
1.510 raeburn 3747: }
1.519 raeburn 3748: my $folderpath;
1.484 raeburn 3749: if ($env{'form.folderpath'}) {
1.519 raeburn 3750: $folderpath = $env{'form.folderpath'};
3751: my (@folders)=split('&',$env{'form.folderpath'});
3752: $env{'form.foldername'}=&unescape(pop(@folders));
3753: if ($env{'form.foldername'} =~ /\:1$/) {
3754: $container = 'page';
3755: } else {
3756: $container = 'sequence';
3757: }
3758: $env{'form.folder'}=pop(@folders);
1.484 raeburn 3759: } else {
1.519 raeburn 3760: if ($env{'form.folder'} eq '' ||
3761: $env{'form.folder'} eq 'supplemental') {
3762: $folderpath='default&'.
3763: &escape(&mt('Main '.$crstype.' Documents')).
3764: ':::::';
1.484 raeburn 3765: }
3766: }
1.519 raeburn 3767: $containertag = '<input type="hidden" name="folderpath" value="" />';
3768: $pathitem = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 3769: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
3770: $showdoc='/'.$1;
3771: }
3772: if ($showdoc) { # got called in sequence from course
3773: $allowed=0;
3774: } else {
3775: if ($allowed) {
3776: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
3777: $script=&Apache::lonratedt::editscript('simple');
1.433 raeburn 3778: }
3779: }
1.329 droeschl 3780: }
3781:
1.344 bisitz 3782: # get personal data
1.329 droeschl 3783: my $uname=$env{'user.name'};
3784: my $udom=$env{'user.domain'};
3785: my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));
3786:
3787: if ($allowed) {
1.484 raeburn 3788: if ($toolsflag) {
3789: $script .= &inject_data_js();
3790: my ($home,$other,%outhash)=&authorhosts();
3791: if (!$home && $other) {
3792: my @hosts;
3793: foreach my $aurole (keys(%outhash)) {
3794: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
3795: push(@hosts,$outhash{$aurole});
3796: }
3797: }
3798: $script .= &dump_switchserver_js(@hosts);
3799: }
1.458 raeburn 3800: } else {
1.484 raeburn 3801: my @tabids;
3802: if ($supplementalflag) {
3803: @tabids = ('002','ee2','ff2');
3804: } else {
3805: @tabids = ('aa1','bb1','cc1','ff1');
1.519 raeburn 3806: unless ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 3807: unshift(@tabids,'001');
3808: push(@tabids,('dd1','ee1'));
3809: }
1.458 raeburn 3810: }
1.484 raeburn 3811: my $tabidstr = join("','",@tabids);
3812: $script .= &editing_js($udom,$uname,$supplementalflag).
3813: &history_tab_js().
3814: &inject_data_js().
1.510 raeburn 3815: &Apache::lonhtmlcommon::resize_scrollbox_js('docs',$tabidstr).
3816: &Apache::lonextresedit::extedit_javascript();
1.484 raeburn 3817: $addentries = {
1.485 raeburn 3818: onload => "javascript:resize_scrollbox('contentscroll','1','1');",
1.484 raeburn 3819: };
1.458 raeburn 3820: }
1.492 raeburn 3821: if ($env{'docs.markedcopy_url'}) {
3822: $script .= &paste_popup_js();
3823: }
1.501 raeburn 3824: my $confirm_switch = &mt("Editing requires switching to the resource's home server.").'\n'.
3825: &mt('Switch server?');
3826:
3827:
1.329 droeschl 3828: }
3829: # -------------------------------------------------------------------- Body tag
1.369 bisitz 3830: $script = '<script type="text/javascript">'."\n"
1.372 bisitz 3831: .'// <![CDATA['."\n"
3832: .$script."\n"
3833: .'// ]]>'."\n"
3834: .'</script>'."\n";
1.385 bisitz 3835:
3836: # Breadcrumbs
3837: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.510 raeburn 3838:
3839: if ($showdoc) {
3840: $r->print(&Apache::loncommon::start_page("$crstype documents",undef,
3841: {'force_register' => $showdoc,}));
3842: } elsif ($r->uri eq '/adm/supplemental') {
3843: my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype);
3844: $r->print(&Apache::loncommon::start_page("Supplemental $crstype Content",undef,
3845: {'bread_crumbs' => $brcrum,}));
3846: } else {
1.392 raeburn 3847: &Apache::lonhtmlcommon::add_breadcrumb({
1.446 www 3848: href=>"/adm/coursedocs",text=>"$crstype Contents"});
1.392 raeburn 3849:
1.446 www 3850: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script,
1.510 raeburn 3851: {'add_entries' => $addentries}
3852: )
1.392 raeburn 3853: .&Apache::loncommon::help_open_menu('','',273,'RAT')
3854: .&Apache::lonhtmlcommon::breadcrumbs(
1.484 raeburn 3855: 'Editing '.$crstype.' Contents',
1.392 raeburn 3856: 'Docs_Adding_Course_Doc')
3857: );
3858: }
1.364 bisitz 3859:
1.329 droeschl 3860: my %allfiles = ();
3861: my %codebase = ();
1.440 raeburn 3862: my ($upload_result,$upload_output,$uploadphase);
1.329 droeschl 3863: if ($allowed) {
3864: if (($env{'form.uploaddoc.filename'}) &&
3865: ($env{'form.cmd'}=~/^upload_(\w+)/)) {
1.440 raeburn 3866: my $context = $1;
3867: # Process file upload - phase one - upload and parse primary file.
1.329 droeschl 3868: undef($hadchanges);
1.440 raeburn 3869: $uploadphase = &process_file_upload(\$upload_output,$coursenum,$coursedom,
3870: \%allfiles,\%codebase,$context);
1.329 droeschl 3871: if ($hadchanges) {
3872: &mark_hash_old();
3873: }
1.440 raeburn 3874: $r->print($upload_output);
3875: } elsif ($env{'form.phase'} eq 'upload_embedded') {
3876: # Process file upload - phase two - upload embedded objects
3877: $uploadphase = 'check_embedded';
3878: my $primaryurl = &HTML::Entities::encode($env{'form.primaryurl'},'<>&"');
3879: my $state = &embedded_form_elems($uploadphase,$primaryurl,
3880: $env{'form.newidx'});
3881: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
3882: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
3883: my ($destination,$dir_root) = &embedded_destination();
3884: my $url_root = '/uploaded/'.$docudom.'/'.$docuname;
3885: my $actionurl = '/adm/coursedocs';
3886: my ($result,$flag) =
3887: &Apache::loncommon::upload_embedded('coursedoc',$destination,
3888: $docuname,$docudom,$dir_root,$url_root,undef,undef,undef,$state,
3889: $actionurl);
3890: $r->print($result.&return_to_editor());
3891: } elsif ($env{'form.phase'} eq 'check_embedded') {
3892: # Process file upload - phase three - modify references in HTML file
3893: $uploadphase = 'modified_orightml';
3894: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
3895: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
3896: my ($destination,$dir_root) = &embedded_destination();
1.482 raeburn 3897: my $result =
3898: &Apache::loncommon::modify_html_refs('coursedoc',$destination,
3899: $docuname,$docudom,undef,
3900: $dir_root);
3901: $r->print($result.&return_to_editor());
1.476 raeburn 3902: } elsif ($env{'form.phase'} eq 'decompress_uploaded') {
3903: $uploadphase = 'decompress_phase_one';
3904: $r->print(&decompression_phase_one().
3905: &return_to_editor());
3906: } elsif ($env{'form.phase'} eq 'decompress_cleanup') {
3907: $uploadphase = 'decompress_phase_two';
3908: $r->print(&decompression_phase_two().
3909: &return_to_editor());
1.329 droeschl 3910: }
3911: }
3912:
1.484 raeburn 3913: if ($allowed && $toolsflag) {
3914: $r->print(&startContentScreen('tools'));
3915: $r->print(&generate_admin_menu($crstype));
3916: $r->print(&endContentScreen());
3917: } elsif ((!$showdoc) && (!$uploadphase)) {
1.329 droeschl 3918: # -----------------------------------------------------------------------------
3919: my %lt=&Apache::lonlocal::texthash(
3920: 'copm' => 'All documents out of a published map into this folder',
1.501 raeburn 3921: 'upfi' => 'Upload File',
3922: 'upld' => 'Import Content',
1.329 droeschl 3923: 'srch' => 'Search',
3924: 'impo' => 'Import',
1.487 raeburn 3925: 'lnks' => 'Import from Stored Links',
1.502 raeburn 3926: 'impm' => 'Import from Assembled Map',
1.329 droeschl 3927: 'selm' => 'Select Map',
3928: 'load' => 'Load Map',
3929: 'newf' => 'New Folder',
3930: 'newp' => 'New Composite Page',
3931: 'syll' => 'Syllabus',
1.425 raeburn 3932: 'navc' => 'Table of Contents',
1.343 biermanm 3933: 'sipa' => 'Simple Course Page',
1.329 droeschl 3934: 'sipr' => 'Simple Problem',
1.534 raeburn 3935: 'webp' => 'Blank Web Page (editable)',
1.329 droeschl 3936: 'drbx' => 'Drop Box',
1.451 www 3937: 'scuf' => 'External Scores (handgrade, upload, clicker)',
1.336 schafran 3938: 'bull' => 'Discussion Board',
1.347 weissno 3939: 'mypi' => 'My Personal Information Page',
1.353 weissno 3940: 'grpo' => 'Group Portfolio',
1.329 droeschl 3941: 'rost' => 'Course Roster',
1.528 raeburn 3942: 'abou' => 'Personal Information Page for a User',
1.377 bisitz 3943: 'imsf' => 'IMS Import',
3944: 'imsl' => 'Import IMS package',
1.501 raeburn 3945: 'cms' => 'Origin of IMS package',
3946: 'se' => 'Select',
1.329 droeschl 3947: 'file' => 'File',
3948: 'title' => 'Title',
3949: 'comment' => 'Comment',
1.403 raeburn 3950: 'parse' => 'Upload embedded images/multimedia files if HTML file',
1.329 droeschl 3951: );
3952: # -----------------------------------------------------------------------------
3953: my $fileupload=(<<FIUP);
3954: $lt{'file'}:<br />
3955: <input type="file" name="uploaddoc" size="40" />
3956: FIUP
3957:
3958: my $checkbox=(<<CHBO);
3959: <!-- <label>$lt{'parse'}?
3960: <input type="checkbox" name="parserflag" />
3961: </label> -->
3962: <label>
3963: <input type="checkbox" name="parserflag" checked="checked" /> $lt{'parse'}
3964: </label>
3965: CHBO
1.501 raeburn 3966: my $imsfolder = $env{'form.folder'};
3967: if ($imsfolder eq '') {
3968: $imsfolder = 'default';
3969: }
3970: my $imspform=(<<IMSFORM);
3971: <a class="LC_menubuttons_link" href="javascript:toggleUpload('ims');">
3972: $lt{'imsf'}</a> $help{'Importing_IMS_Course'}
3973: <form name="uploadims" action="/adm/imsimportdocs" method="post" enctype="multipart/form-data" target="IMSimport">
1.516 raeburn 3974: <fieldset id="uploadimsform" style="display: none;">
1.501 raeburn 3975: <legend>$lt{'imsf'}</legend>
3976: $fileupload
3977: <br />
3978: <p>
3979: $lt{'cms'}:
3980: <select name="source">
3981: <option value="-1" selected="selected">$lt{'se'}</option>
3982: <option value="bb5">Blackboard 5</option>
3983: <option value="bb6">Blackboard 6</option>
3984: <option value="angel5">ANGEL 5.5</option>
3985: <option value="webctce4">WebCT 4 Campus Edition</option>
3986: </select>
3987: <input type="hidden" name="folder" value="$imsfolder" />
3988: </p>
3989: <input type="hidden" name="phase" value="one" />
3990: <input type="button" value="$lt{'imsl'}" onclick="makeims(this.form);" />
3991: </fieldset>
3992: </form>
3993: IMSFORM
1.329 droeschl 3994:
3995: my $fileuploadform=(<<FUFORM);
1.501 raeburn 3996: <a class="LC_menubuttons_link" href="javascript:toggleUpload('doc');">
3997: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
3998: <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.516 raeburn 3999: <fieldset id="uploaddocform" style="display: none;">
1.501 raeburn 4000: <legend>$lt{'upfi'}</legend>
1.371 tempelho 4001: <input type="hidden" name="active" value="aa" />
1.329 droeschl 4002: $fileupload
4003: <br />
4004: $lt{'title'}:<br />
1.458 raeburn 4005: <input type="text" size="60" name="comment" />
1.508 raeburn 4006: $pathitem
1.329 droeschl 4007: <input type="hidden" name="cmd" value="upload_default" />
4008: <br />
1.458 raeburn 4009: <span class="LC_nobreak" style="float:left">
1.329 droeschl 4010: $checkbox
4011: </span>
1.501 raeburn 4012: <br clear="all" />
4013: <input type="submit" value="$lt{'upld'}" />
4014: </fieldset>
4015: </form>
1.383 tempelho 4016: FUFORM
1.329 droeschl 4017:
1.502 raeburn 4018: my $importpubform=(<<SEDFFORM);
1.514 raeburn 4019: <a class="LC_menubuttons_link" href="javascript:toggleMap('map');">
1.502 raeburn 4020: $lt{'impm'}</a>$help{'Load_Map'}
4021: <form action="/adm/coursedocs" method="post" name="mapimportform">
1.516 raeburn 4022: <fieldset id="importmapform" style="display: none;">
1.502 raeburn 4023: <legend>$lt{'impm'}</legend>
1.371 tempelho 4024: <input type="hidden" name="active" value="bb" />
1.502 raeburn 4025: $lt{'copm'}<br />
4026: <span class="LC_nobreak">
4027: <input type="text" name="importmap" size="40" value=""
4028: onfocus="this.blur();openbrowser('mapimportform','importmap','sequence,page','');" />
1.516 raeburn 4029: <a href="javascript:openbrowser('mapimportform','importmap','sequence,page','');">$lt{'selm'}</a></span><br />
1.502 raeburn 4030: <input type="submit" name="loadmap" value="$lt{'load'}" />
4031: </fieldset>
4032: </form>
4033:
1.383 tempelho 4034: SEDFFORM
1.502 raeburn 4035: my @importpubforma = (
1.508 raeburn 4036: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/src.png" alt="'.$lt{srch}.'" onclick="javascript:groupsearch()" />' => $pathitem."<a class='LC_menubuttons_link' href='javascript:groupsearch()'>$lt{'srch'}</a>" },
1.423 onken 4037: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/res.png" alt="'.$lt{impo}.'" onclick="javascript:groupimport();"/>' => "<a class='LC_menubuttons_link' href='javascript:groupimport();'>$lt{'impo'}</a>$help{'Importing_LON-CAPA_Resource'}" },
1.487 raeburn 4038: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/wishlist.png" alt="'.$lt{lnks}.'" onclick="javascript:open_StoredLinks_Import();" />' => "<a class='LC_menubuttons_link' href='javascript:open_StoredLinks_Import();'>$lt{'lnks'}</a>" },
1.514 raeburn 4039: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/sequence.png" alt="'.$lt{impm}.'" onclick="javascript:toggleMap(\'map\');" />' => $importpubform }
1.383 tempelho 4040: );
1.502 raeburn 4041: $importpubform = &create_form_ul(&create_list_elements(@importpubforma));
1.510 raeburn 4042: my $extresourcesform =
4043: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
4044: $help{'Adding_External_Resource'});
1.329 droeschl 4045: if ($allowed) {
1.492 raeburn 4046: my $folder = $env{'form.folder'};
4047: if ($folder eq '') {
4048: $folder='default';
4049: }
4050: &update_paste_buffer($coursenum,$coursedom,$folder);
1.337 ehlerst 4051: $r->print(<<HIDDENFORM);
4052: <form name="renameform" method="post" action="/adm/coursedocs">
4053: <input type="hidden" name="title" />
4054: <input type="hidden" name="cmd" />
4055: <input type="hidden" name="markcopy" />
4056: <input type="hidden" name="copyfolder" />
4057: $containertag
4058: </form>
1.484 raeburn 4059:
1.337 ehlerst 4060: HIDDENFORM
1.508 raeburn 4061: $r->print(&makesimpleeditform($pathitem)."\n".
4062: &makedocslogform($pathitem."\n".
1.484 raeburn 4063: '<input type="hidden" name="folder" value="'.
4064: $env{'form.folder'}.'" />'."\n"));
1.329 droeschl 4065: }
1.442 www 4066:
4067: # Generate the tabs
1.510 raeburn 4068: my ($mode,$needs_end);
1.472 raeburn 4069: if (($supplementalflag) && (!$allowed)) {
1.510 raeburn 4070: my @folders = split('&',$env{'form.folderpath'});
4071: unless (@folders > 2) {
4072: &Apache::lonnavdisplay::startContentScreen($r,'supplemental');
4073: $needs_end = 1;
4074: }
1.472 raeburn 4075: } else {
1.484 raeburn 4076: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.510 raeburn 4077: $needs_end = 1;
1.472 raeburn 4078: }
1.443 www 4079:
1.442 www 4080: #
4081:
4082: my $savefolderpath;
4083:
1.395 raeburn 4084: if ($allowed) {
1.329 droeschl 4085: my $folder=$env{'form.folder'};
1.443 www 4086: if ($folder eq '' || $supplementalflag) {
1.329 droeschl 4087: $folder='default';
1.356 tempelho 4088: $savefolderpath = $env{'form.folderpath'};
1.442 www 4089: $env{'form.folderpath'}='default&'.&escape(&mt('Content'));
1.508 raeburn 4090: $pathitem = '<input type="hidden" name="folderpath" value="'.
1.329 droeschl 4091: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
4092: }
4093: my $postexec='';
4094: if ($folder eq 'default') {
1.372 bisitz 4095: $r->print('<script type="text/javascript">'."\n"
4096: .'// <![CDATA['."\n"
4097: .'this.window.name="loncapaclient";'."\n"
4098: .'// ]]>'."\n"
4099: .'</script>'."\n"
1.369 bisitz 4100: );
1.329 droeschl 4101: } else {
4102: #$postexec='self.close();';
4103: }
1.504 raeburn 4104: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.sequence';
4105: my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.page';
1.329 droeschl 4106: my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
4107:
4108: my $newnavform=(<<NNFORM);
4109: <form action="/adm/coursedocs" method="post" name="newnav">
1.371 tempelho 4110: <input type="hidden" name="active" value="cc" />
1.508 raeburn 4111: $pathitem
1.329 droeschl 4112: <input type="hidden" name="importdetail"
4113: value="$lt{'navc'}=/adm/navmaps" />
1.423 onken 4114: <a class="LC_menubuttons_link" href="javascript:document.newnav.submit()">$lt{'navc'}</a>
1.329 droeschl 4115: $help{'Navigate_Content'}
4116: </form>
4117: NNFORM
4118: my $newsmppageform=(<<NSPFORM);
4119: <form action="/adm/coursedocs" method="post" name="newsmppg">
1.371 tempelho 4120: <input type="hidden" name="active" value="cc" />
1.508 raeburn 4121: $pathitem
1.329 droeschl 4122: <input type="hidden" name="importdetail" value="" />
1.423 onken 4123: <a class="LC_menubuttons_link" href="javascript:makesmppage();"> $lt{'sipa'}</a>
1.383 tempelho 4124: $help{'Simple Page'}
1.329 droeschl 4125: </form>
4126: NSPFORM
4127:
4128: my $newsmpproblemform=(<<NSPROBFORM);
4129: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
1.371 tempelho 4130: <input type="hidden" name="active" value="cc" />
1.508 raeburn 4131: $pathitem
1.329 droeschl 4132: <input type="hidden" name="importdetail" value="" />
1.423 onken 4133: <a class="LC_menubuttons_link" href="javascript:makesmpproblem();">$lt{'sipr'}</a>
1.383 tempelho 4134: $help{'Simple Problem'}
1.329 droeschl 4135: </form>
4136:
4137: NSPROBFORM
4138:
4139: my $newdropboxform=(<<NDBFORM);
4140: <form action="/adm/coursedocs" method="post" name="newdropbox">
1.371 tempelho 4141: <input type="hidden" name="active" value="cc" />
1.508 raeburn 4142: $pathitem
1.329 droeschl 4143: <input type="hidden" name="importdetail" value="" />
1.423 onken 4144: <a class="LC_menubuttons_link" href="javascript:makedropbox();">$lt{'drbx'}</a>
1.344 bisitz 4145: </form>
1.329 droeschl 4146: NDBFORM
4147:
4148: my $newexuploadform=(<<NEXUFORM);
4149: <form action="/adm/coursedocs" method="post" name="newexamupload">
1.371 tempelho 4150: <input type="hidden" name="active" value="cc" />
1.508 raeburn 4151: $pathitem
1.329 droeschl 4152: <input type="hidden" name="importdetail" value="" />
1.423 onken 4153: <a class="LC_menubuttons_link" href="javascript:makeexamupload();">$lt{'scuf'}</a>
1.329 droeschl 4154: $help{'Score_Upload_Form'}
4155: </form>
4156: NEXUFORM
4157:
4158: my $newbulform=(<<NBFORM);
4159: <form action="/adm/coursedocs" method="post" name="newbul">
1.371 tempelho 4160: <input type="hidden" name="active" value="cc" />
1.508 raeburn 4161: $pathitem
1.329 droeschl 4162: <input type="hidden" name="importdetail" value="" />
1.423 onken 4163: <a class="LC_menubuttons_link" href="javascript:makebulboard();" >$lt{'bull'}</a>
1.329 droeschl 4164: $help{'Bulletin Board'}
4165: </form>
4166: NBFORM
4167:
4168: my $newaboutmeform=(<<NAMFORM);
4169: <form action="/adm/coursedocs" method="post" name="newaboutme">
1.371 tempelho 4170: <input type="hidden" name="active" value="cc" />
1.508 raeburn 4171: $pathitem
1.329 droeschl 4172: <input type="hidden" name="importdetail"
4173: value="$plainname=/adm/$udom/$uname/aboutme" />
1.423 onken 4174: <a class="LC_menubuttons_link" href="javascript:document.newaboutme.submit()">$lt{'mypi'}</a>
1.347 weissno 4175: $help{'My Personal Information Page'}
1.329 droeschl 4176: </form>
4177: NAMFORM
4178:
4179: my $newaboutsomeoneform=(<<NASOFORM);
4180: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
1.371 tempelho 4181: <input type="hidden" name="active" value="cc" />
1.508 raeburn 4182: $pathitem
1.329 droeschl 4183: <input type="hidden" name="importdetail" value="" />
1.423 onken 4184: <a class="LC_menubuttons_link" href="javascript:makeabout();">$lt{'abou'}</a>
1.329 droeschl 4185: </form>
4186: NASOFORM
4187:
4188: my $newrosterform=(<<NROSTFORM);
4189: <form action="/adm/coursedocs" method="post" name="newroster">
1.371 tempelho 4190: <input type="hidden" name="active" value="cc" />
1.508 raeburn 4191: $pathitem
1.329 droeschl 4192: <input type="hidden" name="importdetail"
4193: value="$lt{'rost'}=/adm/viewclasslist" />
1.423 onken 4194: <a class="LC_menubuttons_link" href="javascript:document.newroster.submit()">$lt{'rost'}</a>
1.329 droeschl 4195: $help{'Course Roster'}
4196: </form>
4197: NROSTFORM
4198:
1.534 raeburn 4199: my $newwebpage;
4200: if ($folder =~ /^default_?(\d*)$/) {
4201: $newwebpage = "/uploaded/$coursedom/$coursenum/docs/";
4202: if ($1) {
4203: $newwebpage .= $1;
4204: } else {
4205: $newwebpage .= 'default';
4206: }
4207: $newwebpage .= '/new.html';
4208: }
4209: my $newwebpageform =(<<NWEBFORM);
4210: <form action="/adm/coursedocs" method="post" name="newwebpage">
4211: <input type="hidden" name="active" value="cc" />
4212: $pathitem
4213: <input type="hidden" name="importdetail" value="$newwebpage" />
4214: <a class="LC_menubuttons_link" href="javascript:makewebpage();">$lt{'webp'}</a>
4215: $help{'Web Page'}
4216: </form>
4217: NWEBFORM
4218:
4219:
1.342 ehlerst 4220: my $specialdocumentsform;
1.383 tempelho 4221: my @specialdocumentsforma;
1.451 www 4222: my $gradingform;
4223: my @gradingforma;
4224: my $communityform;
4225: my @communityforma;
1.351 ehlerst 4226: my $newfolderform;
1.390 tempelho 4227: my $newfolderb;
1.342 ehlerst 4228:
1.451 www 4229: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.383 tempelho 4230:
1.329 droeschl 4231: my $newpageform=(<<NPFORM);
4232: <form action="/adm/coursedocs" method="post" name="newpage">
4233: <input type="hidden" name="folderpath" value="$path" />
4234: <input type="hidden" name="importdetail" value="" />
1.371 tempelho 4235: <input type="hidden" name="active" value="cc" />
1.423 onken 4236: <a class="LC_menubuttons_link" href="javascript:makenewpage(document.newpage,'$pageseq');">$lt{'newp'}</a>
1.383 tempelho 4237: $help{'Adding_Pages'}
1.329 droeschl 4238: </form>
4239: NPFORM
1.390 tempelho 4240:
4241:
1.351 ehlerst 4242: $newfolderform=(<<NFFORM);
1.329 droeschl 4243: <form action="/adm/coursedocs" method="post" name="newfolder">
1.508 raeburn 4244: $pathitem
1.329 droeschl 4245: <input type="hidden" name="importdetail" value="" />
1.371 tempelho 4246: <input type="hidden" name="active" value="aa" />
1.422 onken 4247: <a href="javascript:makenewfolder(document.newfolder,'$folderseq');">$lt{'newf'}</a>$help{'Adding_Folders'}
1.329 droeschl 4248: </form>
4249: NFFORM
4250:
4251: my $newsylform=(<<NSYLFORM);
4252: <form action="/adm/coursedocs" method="post" name="newsyl">
1.371 tempelho 4253: <input type="hidden" name="active" value="cc" />
1.508 raeburn 4254: $pathitem
1.329 droeschl 4255: <input type="hidden" name="importdetail"
4256: value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />
1.423 onken 4257: <a class="LC_menubuttons_link" href="javascript:document.newsyl.submit()">$lt{'syll'}</a>
1.329 droeschl 4258: $help{'Syllabus'}
1.383 tempelho 4259:
1.329 droeschl 4260: </form>
4261: NSYLFORM
1.364 bisitz 4262:
1.329 droeschl 4263: my $newgroupfileform=(<<NGFFORM);
4264: <form action="/adm/coursedocs" method="post" name="newgroupfiles">
1.371 tempelho 4265: <input type="hidden" name="active" value="cc" />
1.508 raeburn 4266: $pathitem
1.329 droeschl 4267: <input type="hidden" name="importdetail"
4268: value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
1.423 onken 4269: <a class="LC_menubuttons_link" href="javascript:document.newgroupfiles.submit()">$lt{'grpo'}</a>
1.353 weissno 4270: $help{'Group Portfolio'}
1.329 droeschl 4271: </form>
4272: NGFFORM
1.383 tempelho 4273: @specialdocumentsforma=(
1.421 onken 4274: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/page.png" alt="'.$lt{newp}.'" onclick="javascript:makenewpage(document.newpage,\''.$pageseq.'\');" />'=>$newpageform},
1.417 droeschl 4275: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="document.newsyl.submit()" />'=>$newsylform},
1.451 www 4276: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/navigation.png" alt="'.$lt{navc}.'" onclick="document.newnav.submit()" />'=>$newnavform},
4277: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simple.png" alt="'.$lt{sipa}.'" onclick="javascript:makesmppage();" />'=>$newsmppageform},
1.534 raeburn 4278: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
1.451 www 4279: );
4280: $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma));
4281:
1.434 raeburn 4282:
4283: my @importdoc = (
1.519 raeburn 4284: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="toggleUpload(\'ext\');" />'=>$extresourcesform}
4285: );
4286: unless ($container eq 'page') {
4287: push(@importdoc,
4288: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/ims.png" alt="'.$lt{imsf}.'" onclick="javascript:toggleUpload(\'ims\');" />'=>$imspform}
4289: );
4290: }
4291: push(@importdoc,
4292: {'<img class="LC_noBorder_LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'doc\');" />'=>$fileuploadform}
4293: );
1.501 raeburn 4294: $fileuploadform = &create_form_ul(&create_list_elements(@importdoc));
1.434 raeburn 4295:
1.451 www 4296: @gradingforma=(
4297: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{sipr}.'" onclick="javascript:makesmpproblem();" />'=>$newsmpproblemform},
4298: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/dropbox.png" alt="'.$lt{drbx}.'" onclick="javascript:makedropbox();" />'=>$newdropboxform},
4299: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/scoreupfrm.png" alt="'.$lt{scuf}.'" onclick="javascript:makeexamupload();" />'=>$newexuploadform},
4300:
4301: );
4302: $gradingform = &create_form_ul(&create_list_elements(@gradingforma));
4303:
4304: @communityforma=(
4305: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/bchat.png" alt="'.$lt{bull}.'" onclick="javascript:makebulboard();" />'=>$newbulform},
4306: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makebulboard();" />'=>$newaboutmeform},
4307: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/aboutme.png" alt="'.$lt{abou}.'" onclick="javascript:makeabout();" />'=>$newaboutsomeoneform},
4308: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/clst.png" alt="'.$lt{rost}.'" onclick="document.newroster.submit()" />'=>$newrosterform},
4309: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/groupportfolio.png" alt="'.$lt{grpo}.'" onclick="document.newgroupfiles.submit()" />'=>$newgroupfileform},
4310: );
4311: $communityform = &create_form_ul(&create_list_elements(@communityforma));
1.383 tempelho 4312:
1.330 tempelho 4313: my %orderhash = (
1.488 raeburn 4314: 'aa' => ['Import Content',$fileuploadform],
1.502 raeburn 4315: 'bb' => ['Published Content',$importpubform],
1.451 www 4316: 'cc' => ['Grading Resources',$gradingform],
1.330 tempelho 4317: );
1.519 raeburn 4318: unless ($container eq 'page') {
1.434 raeburn 4319: $orderhash{'00'} = ['Newfolder',$newfolderform];
1.484 raeburn 4320: $orderhash{'dd'} = ['Collaboration',$communityform];
1.515 raeburn 4321: $orderhash{'ee'} = ['Special Pages',$specialdocumentsform];
1.434 raeburn 4322: }
4323:
1.341 ehlerst 4324: $hadchanges=0;
1.484 raeburn 4325: unless (($supplementalflag || $toolsflag)) {
1.458 raeburn 4326: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.508 raeburn 4327: $supplementalflag,\%orderhash,$iconpath,$pathitem);
1.443 www 4328: if ($error) {
4329: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
4330: }
4331: if ($hadchanges) {
4332: &mark_hash_old();
4333: }
1.341 ehlerst 4334:
1.443 www 4335: &changewarning($r,'');
4336: }
1.458 raeburn 4337: }
1.442 www 4338:
1.443 www 4339: # Supplemental documents start here
4340:
1.329 droeschl 4341: my $folder=$env{'form.folder'};
1.443 www 4342: unless ($supplementalflag) {
1.329 droeschl 4343: $folder='supplemental';
4344: }
4345: if ($folder =~ /^supplemental$/ &&
4346: (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
1.446 www 4347: $env{'form.folderpath'} = &supplemental_base();
1.393 raeburn 4348: } elsif ($allowed) {
1.356 tempelho 4349: $env{'form.folderpath'} = $savefolderpath;
1.329 droeschl 4350: }
1.508 raeburn 4351: $pathitem = '<input type="hidden" name="folderpath" value="'.
4352: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
1.329 droeschl 4353: if ($allowed) {
4354: my $folderseq=
1.504 raeburn 4355: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_new.sequence';
1.329 droeschl 4356:
4357: my $supupdocform=(<<SUPDOCFORM);
1.501 raeburn 4358: <a class="LC_menubuttons_link" href="javascript:toggleUpload('suppdoc');">
4359: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
1.383 tempelho 4360: <form action="/adm/coursedocs" method="post" name="supuploaddocument" enctype="multipart/form-data">
1.516 raeburn 4361: <fieldset id="uploadsuppdocform" style="display: none;">
1.501 raeburn 4362: <legend>$lt{'upfi'}</legend>
1.371 tempelho 4363: <input type="hidden" name="active" value="ee" />
1.329 droeschl 4364: $fileupload
4365: <br />
4366: <br />
4367: <span class="LC_nobreak">
4368: $checkbox
4369: </span>
4370: <br /><br />
4371: $lt{'comment'}:<br />
1.383 tempelho 4372: <textarea cols="50" rows="4" name="comment"></textarea>
1.329 droeschl 4373: <br />
1.508 raeburn 4374: $pathitem
1.329 droeschl 4375: <input type="hidden" name="cmd" value="upload_supplemental" />
1.501 raeburn 4376: <input type='submit' value="$lt{'upld'}" />
4377: </form>
1.329 droeschl 4378: SUPDOCFORM
4379:
4380: my $supnewfolderform=(<<SNFFORM);
4381: <form action="/adm/coursedocs" method="post" name="supnewfolder">
1.371 tempelho 4382: <input type="hidden" name="active" value="ee" />
1.508 raeburn 4383: $pathitem
1.329 droeschl 4384: <input type="hidden" name="importdetail" value="" />
1.423 onken 4385: <a class="LC_menubuttons_link" href="javascript:makenewfolder(document.supnewfolder,'$folderseq');">$lt{'newf'}</a>
1.383 tempelho 4386: $help{'Adding_Folders'}
1.329 droeschl 4387: </form>
4388: SNFFORM
1.383 tempelho 4389:
1.510 raeburn 4390: my $supextform =
4391: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
4392: $help{'Adding_External_Resource'});
1.329 droeschl 4393:
4394: my $supnewsylform=(<<SNSFORM);
4395: <form action="/adm/coursedocs" method="post" name="supnewsyl">
1.371 tempelho 4396: <input type="hidden" name="active" value="ff" />
1.508 raeburn 4397: $pathitem
1.329 droeschl 4398: <input type="hidden" name="importdetail"
4399: value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
1.423 onken 4400: <a class="LC_menubuttons_link" href="javascript:document.supnewsyl.submit()">$lt{'syll'}</a>
1.329 droeschl 4401: $help{'Syllabus'}
4402: </form>
4403: SNSFORM
4404:
4405: my $supnewaboutmeform=(<<SNAMFORM);
1.383 tempelho 4406: <form action="/adm/coursedocs" method="post" name="supnewaboutme">
1.371 tempelho 4407: <input type="hidden" name="active" value="ff" />
1.508 raeburn 4408: $pathitem
1.329 droeschl 4409: <input type="hidden" name="importdetail"
4410: value="$plainname=/adm/$udom/$uname/aboutme" />
1.423 onken 4411: <a class="LC_menubuttons_link" href="javascript:document.supnewaboutme.submit()">$lt{'mypi'}</a>
1.347 weissno 4412: $help{'My Personal Information Page'}
1.329 droeschl 4413: </form>
4414: SNAMFORM
4415:
1.534 raeburn 4416: my $supwebpage;
4417: if ($folder =~ /^supplemental_?(\d*)$/) {
4418: $supwebpage = "/uploaded/$coursedom/$coursenum/supplemental/";
4419: if ($1) {
4420: $supwebpage .= $1;
4421: } else {
4422: $supwebpage .= 'default';
4423: }
4424: $supwebpage .= '/new.html';
4425: }
4426: my $supwebpageform =(<<SWEBFORM);
4427: <form action="/adm/coursedocs" method="post" name="supwebpage">
4428: <input type="hidden" name="active" value="cc" />
4429: $pathitem
4430: <input type="hidden" name="importdetail" value="$supwebpage" />
4431: <a class="LC_menubuttons_link" href="javascript:makewebpage('supp');">$lt{'webp'}</a>
4432: $help{'Web Page'}
4433: </form>
4434: SWEBFORM
4435:
1.333 muellerd 4436:
1.383 tempelho 4437: my @specialdocs = (
1.417 droeschl 4438: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="document.supnewsyl.submit()" />'
4439: =>$supnewsylform},
4440: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="document.supnewaboutme.submit()" />'
4441: =>$supnewaboutmeform},
1.534 raeburn 4442: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage('."'supp'".');" />'=>$supwebpageform},
4443:
1.383 tempelho 4444: );
1.417 droeschl 4445: my @supimportdoc = (
1.515 raeburn 4446: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="javascript:toggleUpload(\'suppext\')" />'
1.501 raeburn 4447: =>$supextform},
4448: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'suppdoc\');" />'
4449: =>$supupdocform},
4450: );
4451:
4452: $supupdocform = &create_form_ul(&create_list_elements(@supimportdoc));
1.333 muellerd 4453: my %suporderhash = (
1.390 tempelho 4454: '00' => ['Supnewfolder', $supnewfolderform],
1.488 raeburn 4455: 'ee' => ['Import Content',$supupdocform],
1.515 raeburn 4456: 'ff' => ['Special Pages',&create_form_ul(&create_list_elements(@specialdocs))]
1.333 muellerd 4457: );
1.443 www 4458: if ($supplementalflag) {
1.458 raeburn 4459: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.508 raeburn 4460: $supplementalflag,\%suporderhash,$iconpath,$pathitem);
1.443 www 4461: if ($error) {
4462: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
4463: }
1.393 raeburn 4464: }
1.443 www 4465: } elsif ($supplementalflag) {
1.458 raeburn 4466: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.508 raeburn 4467: $supplementalflag,'',$iconpath,$pathitem);
1.393 raeburn 4468: if ($error) {
4469: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.383 tempelho 4470: }
1.393 raeburn 4471: }
1.389 tempelho 4472:
1.510 raeburn 4473: if ($needs_end) {
4474: $r->print(&endContentScreen());
4475: }
1.383 tempelho 4476:
1.329 droeschl 4477: if ($allowed) {
4478: $r->print('
4479: <form method="post" name="extimport" action="/adm/coursedocs">
4480: <input type="hidden" name="title" />
4481: <input type="hidden" name="url" />
4482: <input type="hidden" name="useform" />
4483: <input type="hidden" name="residx" />
4484: </form>');
4485: }
1.484 raeburn 4486: } elsif ($showdoc) {
1.329 droeschl 4487: # -------------------------------------------------------- This is showdoc mode
1.484 raeburn 4488: $r->print("<h1>".&mt('Uploaded Document').' - '.
1.498 bisitz 4489: &Apache::lonnet::gettitle($r->uri).'</h1><p class="LC_warning">'.
1.329 droeschl 4490: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><table>".
1.484 raeburn 4491: &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');
1.329 droeschl 4492: }
4493: }
4494: $r->print(&Apache::loncommon::end_page());
4495: return OK;
1.364 bisitz 4496: }
1.329 droeschl 4497:
1.440 raeburn 4498: sub embedded_form_elems {
4499: my ($phase,$primaryurl,$newidx) = @_;
4500: my $folderpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
4501: return <<STATE;
4502: <input type="hidden" name="folderpath" value="$folderpath" />
4503: <input type="hidden" name="cmd" value="upload_embedded" />
4504: <input type="hidden" name="newidx" value="$newidx" />
4505: <input type="hidden" name="phase" value="$phase" />
4506: <input type="hidden" name="primaryurl" value="$primaryurl" />
4507: STATE
4508: }
4509:
4510: sub embedded_destination {
4511: my $folder=$env{'form.folder'};
4512: my $destination = 'docs/';
4513: if ($folder =~ /^supplemental/) {
4514: $destination = 'supplemental/';
4515: }
4516: if (($folder eq 'default') || ($folder eq 'supplemental')) {
4517: $destination .= 'default/';
4518: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
4519: $destination .= $2.'/';
4520: }
4521: $destination .= $env{'form.newidx'};
4522: my $dir_root = '/userfiles';
4523: return ($destination,$dir_root);
4524: }
4525:
4526: sub return_to_editor {
4527: my $actionurl = '/adm/coursedocs';
4528: return '<p><form name="backtoeditor" method="post" action="'.$actionurl.'" />'."\n".
4529: '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" /></form>'."\n".
4530: '<a href="javascript:document.backtoeditor.submit();">'.&mt('Return to Editor').
4531: '</a></p>';
4532: }
4533:
1.476 raeburn 4534: sub decompression_info {
4535: my ($destination,$dir_root) = &embedded_destination();
4536: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
4537: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
4538: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
4539: my $container='sequence';
1.480 raeburn 4540: my ($pathitem,$hiddenelem);
1.519 raeburn 4541: my @hiddens = ('newidx','comment','position','folderpath');
4542: if ($env{'form.folderpath'} =~ /\:1$/) {
1.476 raeburn 4543: $container='page';
4544: }
1.480 raeburn 4545: unshift(@hiddens,$pathitem);
4546: foreach my $item (@hiddens) {
4547: if ($env{'form.'.$item}) {
4548: $hiddenelem .= '<input type="hidden" name="'.$item.'" value="'.
4549: $env{'form.'.$item}.'" />'."\n";
4550: }
1.477 raeburn 4551: }
1.476 raeburn 4552: return ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,
4553: $hiddenelem);
4554: }
4555:
4556: sub decompression_phase_one {
4557: my ($dir,$file,$warning,$error,$output);
4558: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
4559: &decompression_info();
1.490 raeburn 4560: if ($env{'form.archiveurl'} !~ m{^/uploaded/\Q$docudom/$docuname/\E(?:docs|supplemental)/(?:default|\d+).*/([^/]+)$}) {
1.476 raeburn 4561: $error = &mt('Archive file "[_1]" not in the expected location.',$env{'form.archiveurl'});
4562: } else {
4563: my $file = $1;
1.481 raeburn 4564: $output =
4565: &Apache::loncommon::process_decompression($docudom,$docuname,$file,
4566: $destination,$dir_root,
4567: $hiddenelem);
4568: if ($env{'form.autoextract_camtasia'}) {
4569: $output .= &remove_archive($docudom,$docuname,$container);
4570: }
1.476 raeburn 4571: }
4572: if ($error) {
4573: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
4574: $error.'</p>'."\n";
4575: }
4576: if ($warning) {
4577: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
4578: }
4579: return $output;
4580: }
4581:
4582: sub decompression_phase_two {
4583: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
4584: &decompression_info();
1.481 raeburn 4585: my $output;
1.480 raeburn 4586: if ($env{'form.archivedelete'}) {
1.481 raeburn 4587: $output = &remove_archive($docudom,$docuname,$container);
1.480 raeburn 4588: }
4589: $output .=
1.481 raeburn 4590: &Apache::loncommon::process_extracted_files('coursedocs',$docudom,$docuname,
1.476 raeburn 4591: $destination,$dir_root,$hiddenelem);
4592: return $output;
4593: }
4594:
1.480 raeburn 4595: sub remove_archive {
4596: my ($docudom,$docuname,$container) = @_;
4597: my $map = $env{'form.folder'}.'.'.$container;
1.481 raeburn 4598: my ($output,$delwarning,$delresult,$url);
1.480 raeburn 4599: my ($errtext,$fatal) = &mapread($docuname,$docudom,$map);
4600: if ($fatal) {
4601: if ($container eq 'page') {
4602: $delwarning = &mt('An error occurred retrieving the contents of the current page.');
4603: } else {
4604: $delwarning = &mt('An error occurred retrieving the contents of the current folder.');
4605: }
4606: $delwarning .= &mt('As a result the archive file has not been removed.');
4607: } else {
4608: my $currcmd = $env{'form.cmd'};
4609: my $position = $env{'form.position'};
4610: if ($position > 0) {
4611: $env{'form.cmd'} = 'del_'.$position;
4612: my ($title,$url,@rrest) =
4613: split(/:/,$LONCAPA::map::resources[$LONCAPA::map::order[$position]]);
4614: if (&handle_edit_cmd($docuname,$docudom)) {
1.492 raeburn 4615: ($errtext,$fatal) = &storemap($docuname,$docudom,$map,1);
1.480 raeburn 4616: if ($fatal) {
4617: if ($container eq 'page') {
4618: $delwarning = &mt('An error occurred updating the contents of the current page.');
4619: } else {
4620: $delwarning = &mt('An error occurred updating the contents of the current folder.');
4621: }
4622: } else {
1.481 raeburn 4623: $delresult = &mt('Archive file removed.');
1.480 raeburn 4624: }
4625: }
4626: }
4627: $env{'form.cmd'} = $currcmd;
4628: }
4629: if ($delwarning) {
4630: $output = '<p class="LC_warning">'.
4631: $delwarning.
4632: '</p>';
4633: }
4634: if ($delresult) {
4635: $output .= '<p class="LC_info">'.
4636: $delresult.
4637: '</p>';
4638: }
1.481 raeburn 4639: return $output;
1.480 raeburn 4640: }
4641:
1.484 raeburn 4642: sub generate_admin_menu {
4643: my ($crstype) = @_;
4644: my $lc_crstype = lc($crstype);
4645: my ($home,$other,%outhash)=&authorhosts();
4646: my %lt=&Apache::lonlocal::texthash (
4647: 'vc' => 'Verify Content',
4648: 'cv' => 'Check/Set Resource Versions',
4649: 'ls' => 'List Resource Identifiers',
4650: 'imse' => 'Export contents to IMS Archive',
4651: 'dcd' => "Dump $crstype Content to Authoring Space",
4652: );
4653: my ($candump,$dumpurl);
4654: if ($home + $other > 0) {
4655: $candump = 'F';
4656: if ($home) {
4657: $dumpurl = "javascript:injectData(document.courseverify,'dummy','dumpcourse','$lt{'dcd'}')";
4658: } else {
4659: my @hosts;
4660: foreach my $aurole (keys(%outhash)) {
4661: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
4662: push(@hosts,$outhash{$aurole});
4663: }
4664: }
4665: if (@hosts == 1) {
4666: my $switchto = '/adm/switchserver?otherserver='.$hosts[0].
4667: '&role='.
4668: &HTML::Entities::encode($env{'request.role'},'"<>&').'&origurl='.
4669: &HTML::Entities::encode('/adm/coursedocs?dumpcourse=1','"<>&');
4670: $dumpurl = "javascript:dump_needs_switchserver('$switchto')";
4671: } else {
4672: $dumpurl = "javascript:choose_switchserver_window()";
4673: }
4674: }
4675: }
4676: my @menu=
4677: ({ categorytitle=>'Administration',
4678: items =>[
4679: { linktext => $lt{'vc'},
4680: url => "javascript:injectData(document.courseverify,'dummy','verify','$lt{'vc'}')",
4681: permission => 'F',
4682: help => 'Verify_Content',
4683: icon => 'verify.png',
4684: linktitle => 'Verify contents can be retrieved/rendered',
4685: },
4686: { linktext => $lt{'cv'},
4687: url => "javascript:injectData(document.courseverify,'dummy','versions','$lt{'cv'}')",
4688: permission => 'F',
4689: help => 'Check_Resource_Versions',
4690: icon => 'resversion.png',
4691: linktitle => "View version information for resources in your $lc_crstype, and fix/unfix use of specific versions",
4692: },
4693: { linktext => $lt{'ls'},
4694: url => "javascript:injectData(document.courseverify,'dummy','listsymbs','$lt{'ls'}')",
4695: permission => 'F',
4696: #help => '',
4697: icon => 'symbs.png',
4698: linktitle => "List the unique identifier used for each resource instance in your $lc_crstype"
4699: },
4700: ]
4701: },
4702: { categorytitle=>'Export',
4703: items =>[
4704: { linktext => $lt{'imse'},
4705: url => "javascript:injectData(document.courseverify,'dummy','exportcourse','$lt{'imse'}')",
4706: permission => 'F',
4707: help => 'Docs_Export_Course_Docs',
4708: icon => 'imsexport.png',
4709: linktitle => $lt{'imse'},
4710: },
4711: { linktext => $lt{'dcd'},
4712: url => $dumpurl,
4713: permission => $candump,
4714: #help => '',
4715: icon => 'dump.png',
4716: linktitle => $lt{'dcd'},
4717: },
4718: ]
4719: });
4720: return '<form action="/adm/coursedocs" method="post" name="courseverify">'."\n".
4721: '<input type="hidden" id="dummy" />'."\n".
4722: &Apache::lonhtmlcommon::generate_menu(@menu)."\n".
4723: '</form>';
1.329 droeschl 4724: }
4725:
4726: sub generate_edit_table {
1.484 raeburn 4727: my ($tid,$orderhash_ref,$to_show,$iconpath,$jumpto,$readfile) = @_;
1.406 raeburn 4728: return unless(ref($orderhash_ref) eq 'HASH');
1.342 ehlerst 4729: my %orderhash = %{$orderhash_ref};
1.344 bisitz 4730: my $form;
1.371 tempelho 4731: my $activetab;
4732: my $active;
1.526 raeburn 4733: if (($env{'form.active'} ne '') && ($env{'form.active'} ne 'aa')) {
1.371 tempelho 4734: $activetab = $env{'form.active'};
4735: }
1.472 raeburn 4736: my $backicon = $iconpath.'clickhere.gif';
1.525 raeburn 4737: my $backtext = &mt('Exit Editor');
1.458 raeburn 4738: $form = '<div class="LC_Box" style="margin:0;">'.
1.488 raeburn 4739: '<ul id="navigation'.$tid.'" class="LC_TabContent">'."\n".
4740: '<li class="goback">'.
1.525 raeburn 4741: '<a href="javascript:toContents('.$jumpto.');">'.
1.488 raeburn 4742: '<img src="'.$backicon.'" class="LC_icon" style="border: none; vertical-align: top;"'.
4743: ' alt="'.$backtext.'" />'.$backtext.'</a></li>'."\n".
4744: '<li>'.
4745: '<a href="javascript:groupopen('."'$readfile'".',1);">'.
4746: &mt('Undo Delete').'</a></li>'."\n";
4747: if ($env{'form.docslog'}) {
4748: $form .= '<li class="active">';
4749: } else {
4750: $form .= '<li>';
4751: }
4752: $form .= '<a href="javascript:toggleHistoryDisp(1);">'.
4753: &mt('History').'</a></li>'."\n";
4754: if ($env{'form.docslog'}) {
4755: $form .= '<li><a href="javascript:toggleHistoryDisp(0);">'.
4756: &mt('Edit').'</a></li>'."\n";
1.484 raeburn 4757: }
1.458 raeburn 4758: foreach my $name (reverse(sort(keys(%orderhash)))) {
1.390 tempelho 4759: if($name ne '00'){
1.371 tempelho 4760: if($activetab eq '' || $activetab ne $name){
4761: $active = '';
4762: }elsif($activetab eq $name){
4763: $active = 'class="active"';
4764: }
1.458 raeburn 4765: $form .= '<li style="float:right" '.$active
1.484 raeburn 4766: .' onclick="javascript:showPage(this, \''.$name.$tid.'\', \'navigation'.$tid.'\',\'content'.$tid.'\');"><a href="javascript:;"><b>'.&mt(${$orderhash{$name}}[0]).'</b></a></li>'."\n";
1.390 tempelho 4767: } else {
1.484 raeburn 4768: $form .= '<li '.$active.' style="float:right">'.${$orderhash{$name}}[1].'</li>'."\n";
1.390 tempelho 4769:
4770: }
1.329 droeschl 4771: }
1.484 raeburn 4772: $form .= '</ul>'."\n";
4773: $form .= '<div id="content'.$tid.'" style="padding: 0 0; margin: 0 0; overflow: hidden; clear:right">'."\n";
1.458 raeburn 4774:
4775: if ($to_show ne '') {
1.484 raeburn 4776: $form .= '<div style="padding:0;margin:0;float:left">'.$to_show.'</div>'."\n";
1.458 raeburn 4777: }
1.363 ehlerst 4778: foreach my $field (keys(%orderhash)){
1.390 tempelho 4779: if($field ne '00'){
1.422 onken 4780: if($activetab eq '' || $activetab ne $field){
1.458 raeburn 4781: $active = 'style="display: none;float:left"';
1.422 onken 4782: }elsif($activetab eq $field){
1.458 raeburn 4783: $active = 'style="display:block;float:left"';
1.422 onken 4784: }
4785: $form .= '<div id="'.$field.$tid.'"'
4786: .' class="LC_ContentBox" '.$active.'>'.${$orderhash{$field}}[1]
1.484 raeburn 4787: .'</div>'."\n";
1.363 ehlerst 4788: }
4789: }
1.484 raeburn 4790: unless ($env{'form.docslog'}) {
4791: $form .= '</div></div>'."\n";
4792: }
1.329 droeschl 4793: return $form;
4794: }
4795:
4796: sub editing_js {
1.472 raeburn 4797: my ($udom,$uname,$supplementalflag) = @_;
1.329 droeschl 4798: my %lt = &Apache::lonlocal::texthash(
4799: p_mnf => 'Name of New Folder',
4800: t_mnf => 'New Folder',
4801: p_mnp => 'Name of New Page',
4802: t_mnp => 'New Page',
1.451 www 4803: p_mxu => 'Title for the External Score',
1.349 biermanm 4804: p_msp => 'Name of Simple Course Page',
1.329 droeschl 4805: p_msb => 'Title for the Problem',
4806: p_mdb => 'Title for the Drop Box',
1.336 schafran 4807: p_mbb => 'Title for the Discussion Board',
1.534 raeburn 4808: p_mwp => 'Title for Web Page',
1.348 weissno 4809: p_mab => "Enter user:domain for User's Personal Information Page",
1.352 bisitz 4810: p_mab2 => 'Personal Information Page of ',
1.329 droeschl 4811: p_mab_alrt1 => 'Not a valid user:domain',
4812: p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',
4813: p_chn => 'New Title',
4814: p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',
4815: p_rmr2a => 'Remove[_99]',
4816: p_rmr2b => '?[_99]',
4817: p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',
4818: p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',
4819: p_ctr2a => 'Cut[_98]',
1.478 raeburn 4820: p_ctr2b => '?[_98]',
4821: rpck => 'Enter number to pick (e.g., 3)',
1.501 raeburn 4822: imsfile => 'You must choose an IMS package for import',
4823: imscms => 'You must select which Course Management System was the source of the IMS package',
4824: invurl => 'Invalid URL',
4825: titbl => 'Title is blank',
1.329 droeschl 4826: );
4827:
1.433 raeburn 4828: my $crstype = &Apache::loncommon::course_type();
1.434 raeburn 4829: my $docs_folderpath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'},'<>&"');
4830: my $main_container_page;
1.519 raeburn 4831: if (&HTML::Entities::decode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'}) =~ /\:1$/) {
4832: $main_container_page = 1;
1.434 raeburn 4833: }
1.519 raeburn 4834: my $toplevelmain = 'default&Main%20'.$crstype.'%20Documents%3A%3A%3A%3A%3A';
1.446 www 4835: my $toplevelsupp = &supplemental_base();
1.433 raeburn 4836:
1.525 raeburn 4837: my $backtourl;
1.530 raeburn 4838: if ($env{'docs.exit.'.$env{'request.course.id'}} =~ /^direct_(.+)$/) {
4839: my $caller = $1;
1.525 raeburn 4840: if ($caller =~ /^supplemental/) {
4841: $backtourl = '/adm/supplemental?folderpath='.&escape($caller);
4842: } else {
4843: my ($map,$id,$res)=&Apache::lonnet::decode_symb($caller);
4844: $res = &Apache::lonnet::clutter($res);
4845: if (&Apache::lonnet::is_on_map($res)) {
4846: $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($res),'<>&"').'?symb='.
4847: &HTML::Entities::encode($caller,'<>&"');
4848: }
4849: }
4850: } elsif ($env{'docs.exit.'.$env{'request.course.id'}} eq '/adm/menu') {
4851: $backtourl = '/adm/menu';
4852: } elsif ($supplementalflag) {
1.472 raeburn 4853: $backtourl = '/adm/supplemental';
1.525 raeburn 4854: } else {
4855: $backtourl = '/adm/navmaps';
1.472 raeburn 4856: }
4857:
1.519 raeburn 4858: my $fieldsets = "'ext','doc'";
4859: unless ($main_container_page) {
4860: $fieldsets .=",'ims'";
4861: }
1.501 raeburn 4862: if ($supplementalflag) {
4863: $fieldsets = "'suppext','suppdoc'";
4864: }
4865:
1.329 droeschl 4866: return <<ENDNEWSCRIPT;
4867: function makenewfolder(targetform,folderseq) {
4868: var foldername=prompt('$lt{"p_mnf"}','$lt{"t_mnf"}');
4869: if (foldername) {
4870: targetform.importdetail.value=escape(foldername)+"="+folderseq;
4871: targetform.submit();
4872: }
4873: }
4874:
4875: function makenewpage(targetform,folderseq) {
4876: var pagename=prompt('$lt{"p_mnp"}','$lt{"t_mnp"}');
4877: if (pagename) {
4878: targetform.importdetail.value=escape(pagename)+"="+folderseq;
4879: targetform.submit();
4880: }
4881: }
4882:
4883: function makeexamupload() {
4884: var title=prompt('$lt{"p_mxu"}');
1.344 bisitz 4885: if (title) {
1.329 droeschl 4886: this.document.forms.newexamupload.importdetail.value=
4887: escape(title)+'=/res/lib/templates/examupload.problem';
4888: this.document.forms.newexamupload.submit();
4889: }
4890: }
4891:
4892: function makesmppage() {
4893: var title=prompt('$lt{"p_msp"}');
1.344 bisitz 4894: if (title) {
1.329 droeschl 4895: this.document.forms.newsmppg.importdetail.value=
1.533 raeburn 4896: escape(title)+'=/adm/$udom/$uname/new/smppg';
1.329 droeschl 4897: this.document.forms.newsmppg.submit();
4898: }
4899: }
4900:
1.534 raeburn 4901: function makewebpage(type) {
4902: var title=prompt('$lt{"p_mwp"}');
4903: var formname;
4904: if (type == 'supp') {
4905: formname = this.document.forms.supwebpage;
4906: } else {
4907: formname = this.document.forms.newwebpage;
4908: }
4909: if (title) {
4910: var webpage = formname.importdetail.value;
4911: formname.importdetail.value = escape(title)+'='+webpage;
4912: formname.submit();
4913: }
4914: }
4915:
1.329 droeschl 4916: function makesmpproblem() {
4917: var title=prompt('$lt{"p_msb"}');
1.344 bisitz 4918: if (title) {
1.329 droeschl 4919: this.document.forms.newsmpproblem.importdetail.value=
4920: escape(title)+'=/res/lib/templates/simpleproblem.problem';
4921: this.document.forms.newsmpproblem.submit();
4922: }
4923: }
4924:
4925: function makedropbox() {
4926: var title=prompt('$lt{"p_mdb"}');
1.344 bisitz 4927: if (title) {
1.329 droeschl 4928: this.document.forms.newdropbox.importdetail.value=
4929: escape(title)+'=/res/lib/templates/DropBox.problem';
4930: this.document.forms.newdropbox.submit();
4931: }
4932: }
4933:
4934: function makebulboard() {
4935: var title=prompt('$lt{"p_mbb"}');
4936: if (title) {
4937: this.document.forms.newbul.importdetail.value=
1.533 raeburn 4938: escape(title)+'=/adm/$udom/$uname/new/bulletinboard';
1.329 droeschl 4939: this.document.forms.newbul.submit();
4940: }
4941: }
4942:
4943: function makeabout() {
4944: var user=prompt("$lt{'p_mab'}");
4945: if (user) {
4946: var comp=new Array();
4947: comp=user.split(':');
4948: if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
4949: if ((comp[0]) && (comp[1])) {
4950: this.document.forms.newaboutsomeone.importdetail.value=
4951: '$lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
1.335 ehlerst 4952: this.document.forms.newaboutsomeone.submit();
4953: } else {
4954: alert("$lt{'p_mab_alrt1'}");
1.329 droeschl 4955: }
1.335 ehlerst 4956: } else {
4957: alert("$lt{'p_mab_alrt2'}");
4958: }
4959: }
1.329 droeschl 4960: }
4961:
1.501 raeburn 4962: function toggleUpload(caller) {
4963: var blocks = Array($fieldsets);
4964: for (var i=0; i<blocks.length; i++) {
4965: var disp = 'none';
4966: if (caller == blocks[i]) {
4967: var curr = document.getElementById('upload'+caller+'form').style.display;
4968: if (curr == 'none') {
4969: disp='block';
4970: }
4971: }
4972: document.getElementById('upload'+blocks[i]+'form').style.display=disp;
4973: }
1.502 raeburn 4974: resize_scrollbox('contentscroll','1','1');
4975: return;
4976: }
4977:
1.514 raeburn 4978: function toggleMap(caller) {
1.502 raeburn 4979: var disp = 'none';
1.510 raeburn 4980: if (document.getElementById('importmapform')) {
1.514 raeburn 4981: if (caller == 'map') {
4982: var curr = document.getElementById('importmapform').style.display;
4983: if (curr == 'none') {
4984: disp='block';
4985: }
1.510 raeburn 4986: }
4987: document.getElementById('importmapform').style.display=disp;
4988: resize_scrollbox('contentscroll','1','1');
1.502 raeburn 4989: }
1.501 raeburn 4990: return;
1.329 droeschl 4991: }
4992:
1.501 raeburn 4993: function makeims(imsform) {
4994: if ((imsform.uploaddoc.value == '') || (!imsform.uploaddoc.value)) {
4995: alert("$lt{'imsfile'}");
4996: return;
4997: }
4998: if (imsform.source.selectedIndex == 0) {
4999: alert("$lt{'imscms'}");
5000: return;
5001: }
5002: newWindow = window.open('', 'IMSimport',"HEIGHT=700,WIDTH=750,scrollbars=yes");
5003: imsform.submit();
5004: }
5005:
1.519 raeburn 5006: function changename(folderpath,index,oldtitle) {
1.335 ehlerst 5007: var title=prompt('$lt{"p_chn"}',oldtitle);
5008: if (title) {
5009: this.document.forms.renameform.markcopy.value=-1;
5010: this.document.forms.renameform.title.value=title;
5011: this.document.forms.renameform.cmd.value='rename_'+index;
1.519 raeburn 5012: this.document.forms.renameform.folderpath.value=folderpath;
1.335 ehlerst 5013: this.document.forms.renameform.submit();
5014: }
1.329 droeschl 5015: }
5016:
1.519 raeburn 5017: function removeres(folderpath,index,oldtitle,skip_confirm) {
1.335 ehlerst 5018: if (skip_confirm || confirm('$lt{"p_rmr1"}\\n\\n$lt{"p_rmr2a"} "'+oldtitle+'" $lt{"p_rmr2b"}')) {
5019: this.document.forms.renameform.markcopy.value=-1;
5020: this.document.forms.renameform.cmd.value='del_'+index;
1.519 raeburn 5021: this.document.forms.renameform.folderpath.value=folderpath;
1.335 ehlerst 5022: this.document.forms.renameform.submit();
5023: }
1.329 droeschl 5024: }
5025:
1.519 raeburn 5026: function cutres(folderpath,index,oldtitle,container,folder,skip_confirm) {
1.335 ehlerst 5027: if (skip_confirm || confirm('$lt{"p_ctr1a"}\\n$lt{"p_ctr1b"}\\n\\n$lt{"p_ctr2a"} "'+oldtitle+'" $lt{"p_ctr2b"}')) {
5028: this.document.forms.renameform.cmd.value='cut_'+index;
5029: this.document.forms.renameform.markcopy.value=index;
5030: this.document.forms.renameform.copyfolder.value=folder+'.'+container;
1.519 raeburn 5031: this.document.forms.renameform.folderpath.value=folderpath;
1.335 ehlerst 5032: this.document.forms.renameform.submit();
5033: }
1.329 droeschl 5034: }
5035:
1.519 raeburn 5036: function markcopy(folderpath,index,oldtitle,container,folder) {
1.335 ehlerst 5037: this.document.forms.renameform.markcopy.value=index;
5038: this.document.forms.renameform.copyfolder.value=folder+'.'+container;
5039: this.document.forms.renameform.folderpath.value=folderpath;
5040: this.document.forms.renameform.submit();
1.329 droeschl 5041: }
5042:
1.478 raeburn 5043: function updatePick(targetform,index,caller) {
1.537 ! raeburn 5044: var pickitem;
! 5045: var picknumitem;
! 5046: var picknumtext;
! 5047: if (index == 'all') {
! 5048: pickitem = document.getElementById('randompickall');
! 5049: picknumitem = document.getElementById('rpicknumall');
! 5050: picknumtext = document.getElementById('rpicktextall');
! 5051: } else {
! 5052: pickitem = document.getElementById('randompick_'+index);
! 5053: picknumitem = document.getElementById('rpicknum_'+index);
! 5054: picknumtext = document.getElementById('randompicknum_'+index);
! 5055: }
1.478 raeburn 5056: if (pickitem.checked) {
5057: var picknum=prompt('$lt{"rpck"}',picknumitem.value);
5058: if (picknum == '' || picknum == null) {
5059: if (caller == 'check') {
5060: pickitem.checked=false;
1.537 ! raeburn 5061: if (index == 'all') {
! 5062: picknumtext.innerHTML = '';
! 5063: if (caller == 'link') {
! 5064: propagateState(targetform,'rpicknum');
! 5065: }
! 5066: } else {
! 5067: checkForSubmit(targetform,'randompick');
! 5068: }
1.478 raeburn 5069: }
5070: } else {
5071: picknum.toString();
5072: var regexdigit=/^\\d+\$/;
5073: if (regexdigit.test(picknum)) {
5074: picknumitem.value = picknum;
1.537 ! raeburn 5075: if (index == 'all') {
! 5076: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.cumulativechecks,\\'all\\',\\'link\\');">'+picknum+'</a>';
! 5077: if (caller == 'link') {
! 5078: propagateState(targetform,'rpicknum');
! 5079: }
! 5080: } else {
! 5081: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.edit_randompick_'+index+',\\''+index+'\\',\\'link\\');">'+picknum+'</a>';
! 5082: checkForSubmit(targetform,'randompick');
! 5083: }
1.478 raeburn 5084: } else {
5085: if (caller == 'check') {
1.537 ! raeburn 5086: if (index == 'all') {
! 5087: picknumtext.innerHTML = '';
! 5088: if (caller == 'link') {
! 5089: propagateState(targetform,'rpicknum');
! 5090: }
! 5091: } else {
! 5092: pickitem.checked=false;
! 5093: checkForSubmit(targetform,'randompick');
! 5094: }
1.478 raeburn 5095: }
5096: return;
5097: }
5098: }
5099: } else {
1.537 ! raeburn 5100: picknumitem.value = '';
! 5101: picknumtext.innerHTML = '';
! 5102: if (index == 'all') {
! 5103: if (caller == 'link') {
! 5104: propagateState(targetform,'rpicknum');
! 5105: }
! 5106: } else {
! 5107: checkForSubmit(targetform,'randompick');
! 5108: }
! 5109: }
! 5110: }
! 5111:
! 5112: function propagateState(form,param) {
! 5113: if (document.getElementById(param+'all')) {
! 5114: var setcheck = 0;
! 5115: var rpick = 0;
! 5116: if (param == 'rpicknum') {
! 5117: if (document.getElementById('randompickall')) {
! 5118: if (document.getElementById('randompickall').checked) {
! 5119: if (document.getElementById('rpicknumall')) {
! 5120: rpick = document.getElementById('rpicknumall').value;
! 5121: }
! 5122: }
! 5123: }
! 5124: } else {
! 5125: if (document.getElementById(param+'all').checked) {
! 5126: setcheck = 1;
! 5127: }
! 5128: }
! 5129: if ((param == 'encrypturl') || (param == 'hiddenresource')) {
! 5130: var allidxlist = form.allidx.value;
! 5131: if (allidxlist != '') {
! 5132: var allidxs = allidxlist.split(',');
! 5133: if (allidxs.length > 1) {
! 5134: for (var i=0; i<allidxs.length; i++) {
! 5135: if (document.getElementById(param+'_'+allidxs[i])) {
! 5136: if (setcheck == 1) {
! 5137: document.getElementById(param+'_'+allidxs[i]).checked = true;
! 5138: } else {
! 5139: document.getElementById(param+'_'+allidxs[i]).checked = false;
! 5140: }
! 5141: }
! 5142: }
! 5143: }
! 5144: }
! 5145: } else {
! 5146: var allmapidxlist = form.allmapidx.value;
! 5147: if (allmapidxlist != '') {
! 5148: var allmapidxs = allmapidxlist.split(',');
! 5149: if (allmapidxs.length > 1) {
! 5150: for (var i=0; i<allmapidxs.length; i++) {
! 5151: var item = param+'_'+allmapidxs[i];
! 5152: if (document.getElementById(item)) {
! 5153: if (param == 'rpicknum') {
! 5154: if (document.getElementById('randompick_'+allmapidxs[i])) {
! 5155: if (document.getElementById('randompick_'+allmapidxs[i]).checked) {
! 5156: document.getElementById(param+'_'+allmapidxs[i]).value = rpick;
! 5157: if (rpick > 0) {
! 5158: document.getElementById('randompicknum_'+allmapidxs[i]).innerHTML = ': <a href="javascript:updatePick(document.edit_randompick_'+allmapidxs[i]+',\\''+allmapidxs[i]+'\\',\\'link\\')">'+rpick+'</a>';
! 5159: } else {
! 5160: document.getElementById('randompicknum_'+allmapidxs[i]).innerHTML = '';
! 5161: }
! 5162: }
! 5163: }
! 5164: } else {
! 5165: if (setcheck == 1) {
! 5166: document.getElementById(param+'_'+allmapidxs[i]).checked = true;
! 5167: } else {
! 5168: document.getElementById(param+'_'+allmapidxs[i]).checked = false;
! 5169: }
! 5170: }
! 5171: }
! 5172: }
! 5173: }
! 5174: }
! 5175: }
! 5176: }
! 5177: return;
! 5178: }
! 5179:
! 5180: function checkForSubmit(targetform,param) {
! 5181: if (document.togglemultchecks.showmultpick.length) {
! 5182: for (var i=0; i<document.togglemultchecks.showmultpick.length; i++) {
! 5183: if (document.togglemultchecks.showmultpick[i].checked) {
! 5184: if (document.togglemultchecks.showmultpick[i].value == 0) {
! 5185: targetform.changeparms.value=param;
! 5186: targetform.submit();
! 5187: }
! 5188: }
! 5189: }
1.478 raeburn 5190: }
1.537 ! raeburn 5191: return;
1.478 raeburn 5192: }
5193:
1.334 muellerd 5194: function unselectInactive(nav) {
1.335 ehlerst 5195: currentNav = document.getElementById(nav);
5196: currentLis = currentNav.getElementsByTagName('LI');
5197: for (i = 0; i < currentLis.length; i++) {
1.472 raeburn 5198: if (currentLis[i].className == 'goback') {
5199: currentLis[i].className = 'goback';
5200: } else {
5201: if (currentLis[i].className == 'right active' || currentLis[i].className == 'right') {
1.374 tempelho 5202: currentLis[i].className = 'right';
1.472 raeburn 5203: } else {
1.374 tempelho 5204: currentLis[i].className = 'i';
1.472 raeburn 5205: }
5206: }
1.335 ehlerst 5207: }
1.332 tempelho 5208: }
5209:
1.334 muellerd 5210: function hideAll(current, nav, data) {
1.335 ehlerst 5211: unselectInactive(nav);
1.374 tempelho 5212: if(current.className == 'right'){
5213: current.className = 'right active'
5214: }else{
5215: current.className = 'active';
5216: }
1.335 ehlerst 5217: currentData = document.getElementById(data);
5218: currentDivs = currentData.getElementsByTagName('DIV');
5219: for (i = 0; i < currentDivs.length; i++) {
5220: if(currentDivs[i].className == 'LC_ContentBox'){
1.333 muellerd 5221: currentDivs[i].style.display = 'none';
1.330 tempelho 5222: }
5223: }
1.335 ehlerst 5224: }
1.330 tempelho 5225:
1.374 tempelho 5226: function openTabs(pageId) {
5227: tabnav = document.getElementById(pageId).getElementsByTagName('UL');
1.383 tempelho 5228: if(tabnav.length > 2 ){
1.389 tempelho 5229: currentNav = document.getElementById(tabnav[1].id);
1.374 tempelho 5230: currentLis = currentNav.getElementsByTagName('LI');
5231: for(i = 0; i< currentLis.length; i++){
5232: if(currentLis[i].className == 'active') {
1.375 tempelho 5233: funcString = currentLis[i].onclick.toString();
5234: tab = funcString.split('"');
1.420 onken 5235: if(tab.length < 2) {
5236: tab = funcString.split("'");
5237: }
1.375 tempelho 5238: currentData = document.getElementById(tab[1]);
5239: currentData.style.display = 'block';
1.374 tempelho 5240: }
5241: }
5242: }
5243: }
5244:
1.334 muellerd 5245: function showPage(current, pageId, nav, data) {
5246: hideAll(current, nav, data);
1.375 tempelho 5247: openTabs(pageId);
1.334 muellerd 5248: unselectInactive(nav);
1.330 tempelho 5249: current.className = 'active';
5250: currentData = document.getElementById(pageId);
5251: currentData.style.display = 'block';
1.458 raeburn 5252: activeTab = pageId;
1.501 raeburn 5253: toggleUpload();
1.503 raeburn 5254: toggleMap();
1.433 raeburn 5255: if (nav == 'mainnav') {
5256: var storedpath = "$docs_folderpath";
1.434 raeburn 5257: var storedpage = "$main_container_page";
1.433 raeburn 5258: var reg = new RegExp("^supplemental");
5259: if (pageId == 'mainCourseDocuments') {
1.434 raeburn 5260: if (storedpage == 1) {
5261: document.simpleedit.folderpath.value = '';
5262: document.uploaddocument.folderpath.value = '';
5263: } else {
5264: if (reg.test(storedpath)) {
5265: document.simpleedit.folderpath.value = '$toplevelmain';
5266: document.uploaddocument.folderpath.value = '$toplevelmain';
5267: document.newext.folderpath.value = '$toplevelmain';
5268: } else {
5269: document.simpleedit.folderpath.value = storedpath;
5270: document.uploaddocument.folderpath.value = storedpath;
5271: document.newext.folderpath.value = storedpath;
5272: }
1.433 raeburn 5273: }
5274: } else {
1.434 raeburn 5275: if (reg.test(storedpath)) {
5276: document.simpleedit.folderpath.value = storedpath;
5277: document.supuploaddocument.folderpath.value = storedpath;
5278: document.supnewext.folderpath.value = storedpath;
5279: } else {
1.433 raeburn 5280: document.simpleedit.folderpath.value = '$toplevelsupp';
5281: document.supuploaddocument.folderpath.value = '$toplevelsupp';
5282: document.supnewext.folderpath.value = '$toplevelsupp';
5283: }
5284: }
5285: }
1.485 raeburn 5286: resize_scrollbox('contentscroll','1','0');
1.330 tempelho 5287: return false;
5288: }
1.329 droeschl 5289:
1.472 raeburn 5290: function toContents(jumpto) {
5291: var newurl = '$backtourl';
1.525 raeburn 5292: if ((newurl == '/adm/navmaps') && (jumpto != '')) {
1.472 raeburn 5293: newurl = newurl+'?postdata='+jumpto;
5294: }
5295: location.href=newurl;
5296: }
5297:
1.537 ! raeburn 5298: function submitSettings(form) {
! 5299: var allidxlist = form.allidx.value;
! 5300: form.allencrypturl.value = '';
! 5301: form.allhiddenresource.value = '';
! 5302: if (allidxlist != '') {
! 5303: var allidxs = allidxlist.split(',');
! 5304: if (allidxs.length > 1) {
! 5305: for (var i=0; i<allidxs.length; i++) {
! 5306: if (document.getElementById('hiddenresource_'+allidxs[i])) {
! 5307: if (document.getElementById('hiddenresource_'+allidxs[i]).checked) {
! 5308: form.allhiddenresource.value += allidxs[i]+',';
! 5309: }
! 5310: }
! 5311: if (document.getElementById('encrypturl_'+allidxs[i])) {
! 5312: if (document.getElementById('encrypturl_'+allidxs[i]).checked) {
! 5313: form.allencrypturl.value += allidxs[i]+',';
! 5314: }
! 5315: }
! 5316: }
! 5317: }
! 5318: }
! 5319: var allmapidxlist = form.allmapidx.value;
! 5320: form.allrandompick.value = '';
! 5321: form.allrandomorder.value = '';
! 5322: if (allmapidxlist != '') {
! 5323: var allmapidxs = allmapidxlist.split(',');
! 5324: for (var i=0; i<allmapidxs.length; i++) {
! 5325: var randompick = document.getElementById('randompick_'+allmapidxs[i]);
! 5326: var rpicknum = document.getElementById('rpicknum_'+allmapidxs[i]);
! 5327: var randorder = document.getElementById('randomorder_'+allmapidxs[i]);
! 5328: if ((randompick.checked) && (rpicknum.value != '')) {
! 5329: form.allrandompick.value += allmapidxs[i]+':'+rpicknum.value+',';
! 5330: }
! 5331: if (randorder.checked) {
! 5332: form.allrandomorder.value += allmapidxs[i]+',';
! 5333: }
! 5334: }
! 5335: }
! 5336: form.submit();
! 5337: return true;
! 5338: }
! 5339:
! 5340: function togglePick() {
! 5341: var disp = 'none';
! 5342: if (document.getElementById('multiclick')) {
! 5343: var curr = document.getElementById('multiclick').style.display;
! 5344: if (curr == 'none') {
! 5345: disp='block';
! 5346: }
! 5347: document.getElementById('multiclick').style.display=disp;
! 5348: }
! 5349: if (document.getElementById('savemulti')) {
! 5350: var curr = document.getElementById('save.multi').style.display;
! 5351: if (curr == 'none') {
! 5352: disp='inline';
! 5353: }
! 5354: document.getElementById('savemulti').style.display=disp;
! 5355: }
! 5356: resize_scrollbox('contentscroll','1','1');
! 5357: return;
! 5358: }
! 5359:
1.329 droeschl 5360: ENDNEWSCRIPT
5361: }
1.457 raeburn 5362:
1.483 raeburn 5363: sub history_tab_js {
5364: return <<"ENDHIST";
5365: function toggleHistoryDisp(choice) {
5366: document.docslogform.docslog.value = choice;
5367: document.docslogform.submit();
5368: return;
5369: }
5370:
5371: ENDHIST
5372: }
5373:
1.484 raeburn 5374: sub inject_data_js {
5375: return <<ENDINJECT;
5376:
5377: function injectData(current, hiddenField, name, value) {
5378: currentElement = document.getElementById(hiddenField);
5379: currentElement.name = name;
5380: currentElement.value = value;
5381: current.submit();
5382: }
5383:
5384: ENDINJECT
5385: }
5386:
5387: sub dump_switchserver_js {
5388: my @hosts = @_;
5389: my %lt = &Apache::lonlocal::texthash(
5390: dump => 'Dumping to Authoring Space requires switching server.',
5391: swit => 'Switch server?',
5392: duco => 'Dump content to Authoring Space',
5393: yone => 'You need to switch to a server housing an Authoring Space for which you are author or co-author.',
5394: chos => 'Choose server',
5395: );
5396: my $role = $env{'request.role'};
5397: my $js = <<"ENDSWJS";
5398: <script type="text/javascript">
5399: function write_switchserver() {
5400: var server;
5401: if (document.setserver.posshosts.length > 0) {
5402: for (var i=0; i<document.setserver.posshosts.length; i++) {
5403: if (document.setserver.posshosts[i].checked) {
5404: server = document.setserver.posshosts[i].value;
5405: }
5406: }
5407: opener.document.location.href="/adm/switchserver?otherserver="+server+"&role=$role&origurl=/adm/coursedocs";
5408: }
5409: window.close();
5410: }
5411: </script>
5412:
5413: ENDSWJS
5414:
5415: my $startpage = &Apache::loncommon::start_page('Choose server',$js,
5416: {'only_body' => 1,
5417: 'js_ready' => 1,});
5418: my $endpage = &Apache::loncommon::end_page({'js_ready' => 1});
5419:
5420: my $hostpicker;
5421: my $count = 0;
5422: foreach my $host (sort(@hosts)) {
5423: my $checked;
5424: if ($count == 0) {
5425: $checked = ' checked="checked"';
5426: }
5427: $hostpicker .= '<label><input type="radio" name="posshosts" value="'.
5428: $host.'"'.$checked.' />'.$host.'</label> ';
5429: $count++;
5430: }
5431:
5432: return <<"ENDSWITCHJS";
5433:
5434: function dump_needs_switchserver(url) {
5435: if (url!='' && url!= null) {
5436: if (confirm("$lt{'dump'}\\n$lt{'swit'}")) {
5437: go(url);
5438: }
5439: }
5440: return;
5441: }
5442:
5443: function choose_switchserver_window() {
5444: newWindow = window.open('','ChooseServer','height=400,width=500,scrollbars=yes')
5445: newWindow.document.open();
5446: newWindow.document.writeln('$startpage');
5447: newWindow.document.write('<h3>$lt{'duco'}<\\/h3>\\n'+
5448: '<p>$lt{'yone'}<\\/p>\\n'+
5449: '<div class="LC_left_float"><fieldset><legend>$lt{'chos'}<\\/legend>\\n'+
5450: '<form name="setserver" method="post" action="" \\/>\\n'+
5451: '$hostpicker\\n'+
5452: '<br \\/><br \\/>\\n'+
5453: '<input type="button" name="makeswitch" value="$lt{'swit'}" '+
5454: 'onclick="write_switchserver();" \\/>\\n'+
5455: '<\\/form><\\/fieldset><\\/div><br clear="all" \\/>\\n');
5456: newWindow.document.writeln('$endpage');
5457: newWindow.document.close();
5458: newWindow.focus();
5459: }
5460:
5461: ENDSWITCHJS
5462: }
5463:
5464: sub makedocslogform {
5465: my ($formelems,$docslog) = @_;
5466: return <<"LOGSFORM";
5467: <form action="/adm/coursedocs" method="post" name="docslogform">
5468: <input type="hidden" name="docslog" value="$docslog" />
5469: $formelems
5470: </form>
5471: LOGSFORM
5472: }
5473:
5474: sub makesimpleeditform {
5475: my ($formelems) = @_;
5476: return <<"SIMPFORM";
5477: <form name="simpleedit" method="post" action="/adm/coursedocs">
5478: <input type="hidden" name="importdetail" value="" />
5479: $formelems
5480: </form>
5481: SIMPFORM
5482: }
5483:
1.329 droeschl 5484: 1;
5485: __END__
5486:
5487:
5488: =head1 NAME
5489:
5490: Apache::londocs.pm
5491:
5492: =head1 SYNOPSIS
5493:
5494: This is part of the LearningOnline Network with CAPA project
5495: described at http://www.lon-capa.org.
5496:
5497: =head1 SUBROUTINES
5498:
5499: =over
5500:
5501: =item %help=()
5502:
5503: Available help topics
5504:
5505: =item mapread()
5506:
1.344 bisitz 5507: Mapread read maps into LONCAPA::map:: global arrays
1.329 droeschl 5508: @order and @resources, determines status
5509: sets @order - pointer to resources in right order
5510: sets @resources - array with the resources with correct idx
5511:
5512: =item authorhosts()
5513:
5514: Return hash with valid author names
5515:
5516: =item clean()
5517:
5518: =item dumpcourse()
5519:
5520: Actually dump course
5521:
5522: =item group_import()
5523:
5524: Imports the given (name, url) resources into the course
5525: coursenum, coursedom, and folder must precede the list
5526:
5527: =item breadcrumbs()
5528:
5529: =item log_docs()
5530:
5531: =item docs_change_log()
5532:
5533: =item update_paste_buffer()
5534:
5535: =item print_paste_buffer()
5536:
5537: =item do_paste_from_buffer()
5538:
1.492 raeburn 5539: =item get_newmap_url()
5540:
5541: =item dbcopy()
5542:
5543: =item uniqueness_check()
5544:
5545: =item contained_map_check()
5546:
5547: =item url_paste_fixups()
5548:
5549: =item apply_fixups()
5550:
5551: =item copy_dependencies()
5552:
1.329 droeschl 5553: =item update_parameter()
5554:
5555: =item handle_edit_cmd()
5556:
5557: =item editor()
5558:
5559: =item process_file_upload()
5560:
5561: =item process_secondary_uploads()
5562:
5563: =item is_supplemental_title()
5564:
5565: =item entryline()
5566:
5567: =item tiehash()
5568:
5569: =item untiehash()
5570:
5571: =item checkonthis()
5572:
5573: check on this
5574:
5575: =item verifycontent()
5576:
5577: Verify Content
5578:
5579: =item devalidateversioncache() & checkversions()
5580:
5581: Check Versions
5582:
5583: =item mark_hash_old()
5584:
5585: =item is_hash_old()
5586:
5587: =item changewarning()
5588:
5589: =item init_breadcrumbs()
5590:
5591: Breadcrumbs for special functions
5592:
1.484 raeburn 5593: =item create_list_elements()
5594:
5595: =item create_form_ul()
5596:
5597: =item startContentScreen()
5598:
5599: =item endContentScreen()
5600:
5601: =item supplemental_base()
5602:
5603: =item embedded_form_elems()
5604:
5605: =item embedded_destination()
5606:
5607: =item return_to_editor()
5608:
5609: =item decompression_info()
5610:
5611: =item decompression_phase_one()
5612:
5613: =item decompression_phase_two()
5614:
5615: =item remove_archive()
5616:
5617: =item generate_admin_menu()
5618:
5619: =item generate_edit_table()
5620:
5621: =item editing_js()
5622:
5623: =item history_tab_js()
5624:
5625: =item inject_data_js()
5626:
5627: =item dump_switchserver_js()
5628:
1.485 raeburn 5629: =item resize_scrollbox_js()
1.484 raeburn 5630:
5631: =item makedocslogform()
5632:
1.485 raeburn 5633: =item makesimpleeditform()
5634:
1.329 droeschl 5635: =back
5636:
5637: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>