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