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