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