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