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