Annotation of loncom/interface/londocs.pm, revision 1.484.2.36
1.329 droeschl 1: # The LearningOnline Network
2: # Documents
3: #
1.484.2.36! raeburn 4: # $Id: londocs.pm,v 1.484.2.35 2013/05/27 00:07:52 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 {
1.484.2.36! raeburn 2805: my ($upload_output,$coursenum,$coursedom,$allfiles,$codebase,$uploadcmd,$crstype) = @_;
1.329 droeschl 2806: # upload a file, if present
1.484.2.36! raeburn 2807: my $filesize = length($env{'form.uploaddoc'});
! 2808: if (!$filesize) {
! 2809: $$upload_output = '<div class="LC_error">'.
! 2810: &mt('Unable to upload [_1]. (size = [_2] bytes)',
! 2811: '<span class="LC_filename">'.$env{'form.uploaddoc.filename'}.'</span>',
! 2812: $filesize).'<br />'.
! 2813: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
! 2814: '</div>';
! 2815: return;
! 2816: }
! 2817: my $quotatype = 'unofficial';
! 2818: if ($crstype eq 'Community') {
! 2819: $quotatype = 'community';
! 2820: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.instcode'}) {
! 2821: $quotatype = 'official';
! 2822: }
! 2823: if (&Apache::loncommon::get_user_quota($coursenum,$coursedom,'course',$quotatype)) {
! 2824: $filesize = int($filesize/1000); #expressed in kb
! 2825: $$upload_output = &Apache::loncommon::excess_filesize_warning($coursenum,$coursedom,'course',
! 2826: $env{'form.uploaddoc.filename'},$filesize,'upload');
! 2827: return if ($$upload_output);
! 2828: }
1.440 raeburn 2829: my ($parseaction,$showupload,$nextphase,$mimetype);
2830: if ($env{'form.parserflag'}) {
1.329 droeschl 2831: $parseaction = 'parse';
2832: }
2833: my $folder=$env{'form.folder'};
2834: if ($folder eq '') {
2835: $folder='default';
2836: }
2837: if ( ($folder=~/^$uploadcmd/) || ($uploadcmd eq 'default') ) {
2838: my $errtext='';
2839: my $fatal=0;
2840: my $container='sequence';
1.484.2.19 raeburn 2841: if ($env{'form.folderpath'} =~ /:1$/) {
1.329 droeschl 2842: $container='page';
2843: }
2844: ($errtext,$fatal)=
1.484.2.27 raeburn 2845: &mapread($coursenum,$coursedom,$folder.'.'.$container);
1.329 droeschl 2846: if ($#LONCAPA::map::order<1) {
2847: $LONCAPA::map::order[0]=1;
2848: $LONCAPA::map::resources[1]='';
2849: }
2850: my $destination = 'docs/';
2851: if ($folder =~ /^supplemental/) {
2852: $destination = 'supplemental/';
2853: }
2854: if (($folder eq 'default') || ($folder eq 'supplemental')) {
2855: $destination .= 'default/';
2856: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
2857: $destination .= $2.'/';
2858: }
1.484.2.27 raeburn 2859: if ($fatal) {
2860: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.&mt('The uploaded file has not been stored as an error occurred reading the contents of the current folder.').'</div>';
2861: return;
2862: }
1.440 raeburn 2863: # this is for a course, not a user, so set context to coursedoc.
1.329 droeschl 2864: my $newidx=&LONCAPA::map::getresidx();
2865: $destination .= $newidx;
1.439 raeburn 2866: my $url=&Apache::lonnet::userfileupload('uploaddoc','coursedoc',$destination,
1.329 droeschl 2867: $parseaction,$allfiles,
1.440 raeburn 2868: $codebase,undef,undef,undef,undef,
2869: undef,undef,\$mimetype);
2870: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E.*/([^/]+)$}) {
2871: my $stored = $1;
2872: $showupload = '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
2873: $stored.'</span>').'</p>';
2874: } else {
2875: my ($filename) = ($env{'form.uploaddoc.filename'} =~ m{([^/]+)$});
2876:
1.457 raeburn 2877: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.&mt('Unable to save file [_1].','<span class="LC_filename">'.$filename.'</span>').'</div>';
1.440 raeburn 2878: return;
2879: }
1.329 droeschl 2880: my $ext='false';
2881: if ($url=~m{^http://}) { $ext='true'; }
2882: $url = &LONCAPA::map::qtunescape($url);
2883: my $comment=$env{'form.comment'};
2884: $comment = &LONCAPA::map::qtunescape($comment);
2885: if ($folder=~/^supplemental/) {
2886: $comment=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
2887: $env{'user.domain'}.'___&&&___'.$comment;
2888: }
2889:
2890: $LONCAPA::map::resources[$newidx]=
2891: $comment.':'.$url.':'.$ext.':normal:res';
2892: $LONCAPA::map::order[$#LONCAPA::map::order+1]= $newidx;
2893: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.484.2.7 raeburn 2894: $folder.'.'.$container,1);
1.329 droeschl 2895: if ($fatal) {
1.457 raeburn 2896: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.$errtext.'</div>';
1.440 raeburn 2897: return;
1.329 droeschl 2898: } else {
1.440 raeburn 2899: if ($parseaction eq 'parse' && $mimetype eq 'text/html') {
2900: $$upload_output = $showupload;
1.384 raeburn 2901: my $total_embedded = scalar(keys(%{$allfiles}));
1.329 droeschl 2902: if ($total_embedded > 0) {
1.440 raeburn 2903: my $uploadphase = 'upload_embedded';
2904: my $primaryurl = &HTML::Entities::encode($url,'<>&"');
2905: my $state = &embedded_form_elems($uploadphase,$primaryurl,$newidx);
2906: my ($embedded,$num) =
2907: &Apache::loncommon::ask_for_embedded_content(
2908: '/adm/coursedocs',$state,$allfiles,$codebase,{'docs_url' => $url});
2909: if ($embedded) {
2910: if ($num) {
2911: $$upload_output .=
2912: '<p>'.&mt('This file contains embedded multimedia objects, which need to be uploaded.').'</p>'.$embedded;
2913: $nextphase = $uploadphase;
2914: } else {
2915: $$upload_output .= $embedded;
2916: }
2917: } else {
2918: $$upload_output .= &mt('Embedded item(s) already present, so no additional upload(s) required').'<br />';
2919: }
1.329 droeschl 2920: } else {
1.440 raeburn 2921: $$upload_output .= &mt('No embedded items identified').'<br />';
1.329 droeschl 2922: }
1.457 raeburn 2923: $$upload_output = '<div id="uploadfileresult">'.$$upload_output.'</div>';
1.476 raeburn 2924: } elsif (&Apache::loncommon::is_archive_file($mimetype)) {
2925: $nextphase = 'decompress_uploaded';
2926: my $position = scalar(@LONCAPA::map::order)-1;
2927: my $noextract = &return_to_editor();
2928: my $archiveurl = &HTML::Entities::encode($url,'<>&"');
2929: my %archiveitems = (
2930: folderpath => $env{'form.folderpath'},
2931: cmd => $nextphase,
2932: newidx => $newidx,
2933: position => $position,
2934: phase => $nextphase,
1.477 raeburn 2935: comment => $comment,
1.480 raeburn 2936: );
2937: my ($destination,$dir_root) = &embedded_destination($coursenum,$coursedom);
2938: my @current = &get_dir_list($url,$coursenum,$coursedom,$newidx);
1.476 raeburn 2939: $$upload_output = $showupload.
2940: &Apache::loncommon::decompress_form($mimetype,
2941: $archiveurl,'/adm/coursedocs',$noextract,
1.480 raeburn 2942: \%archiveitems,\@current);
1.329 droeschl 2943: }
2944: }
2945: }
1.440 raeburn 2946: return $nextphase;
1.329 droeschl 2947: }
2948:
1.480 raeburn 2949: sub get_dir_list {
2950: my ($url,$coursenum,$coursedom,$newidx) = @_;
2951: my ($destination,$dir_root) = &embedded_destination();
2952: my ($dirlistref,$listerror) =
2953: &Apache::lonnet::dirlist("$dir_root/$destination/$newidx",$coursedom,$coursenum,1);
2954: my @dir_lines;
2955: my $dirptr=16384;
2956: if (ref($dirlistref) eq 'ARRAY') {
2957: foreach my $dir_line (sort
2958: {
2959: my ($afile)=split('&',$a,2);
2960: my ($bfile)=split('&',$b,2);
2961: return (lc($afile) cmp lc($bfile));
2962: } (@{$dirlistref})) {
2963: my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$dir_line,16);
2964: $filename =~ s/\s+$//;
2965: next if ($filename =~ /^\.\.?$/);
2966: my $isdir = 0;
2967: if ($dirptr&$testdir) {
2968: $isdir = 1;
2969: }
2970: push(@dir_lines, [$filename,$dom,$isdir,$size,$mtime,$obs]);
2971: }
2972: }
2973: return @dir_lines;
2974: }
2975:
1.329 droeschl 2976: sub is_supplemental_title {
2977: my ($title) = @_;
2978: return scalar($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/);
2979: }
2980:
2981: # --------------------------------------------------------------- An entry line
2982:
2983: sub entryline {
1.484.2.12 raeburn 2984: my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$coursedom,
1.484.2.30 raeburn 2985: $crstype,$pathitem,$supplementalflag,$container,$filtersref,$currgroups)=@_;
1.484.2.19 raeburn 2986: my ($foldertitle,$renametitle);
1.329 droeschl 2987: if (&is_supplemental_title($title)) {
1.484.2.7 raeburn 2988: ($title,$foldertitle,$renametitle) = &Apache::loncommon::parse_supplemental_title($title);
1.329 droeschl 2989: } else {
2990: $title=&HTML::Entities::encode($title,'"<>&\'');
2991: $renametitle=$title;
2992: $foldertitle=$title;
2993: }
2994:
2995: my $orderidx=$LONCAPA::map::order[$index];
1.364 bisitz 2996:
1.329 droeschl 2997: $renametitle=~s/\\/\\\\/g;
2998: $renametitle=~s/\"\;/\\\"/g;
2999: $renametitle=~s/ /%20/g;
1.379 bisitz 3000: my $line=&Apache::loncommon::start_data_table_row();
1.484.2.30 raeburn 3001: my ($form_start,$form_end,$form_common,$form_param);
1.329 droeschl 3002: # Edit commands
1.484.2.28 raeburn 3003: my ($esc_path, $path, $symb);
1.329 droeschl 3004: if ($env{'form.folderpath'}) {
3005: $esc_path=&escape($env{'form.folderpath'});
3006: $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3007: # $htmlfoldername=&HTML::Entities::encode($env{'form.foldername'},'<>&"');
3008: }
1.484.2.16 raeburn 3009: my $isexternal;
1.484.2.19 raeburn 3010: if ($residx) {
1.484.2.12 raeburn 3011: my $currurl = $url;
3012: $currurl =~ s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
1.484.2.16 raeburn 3013: if ($currurl =~ m{^/adm/wrapper/ext/}) {
3014: $isexternal = 1;
3015: }
1.484.2.19 raeburn 3016: if (!$supplementalflag) {
3017: my $path = 'uploaded/'.
3018: $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
3019: $env{'course.'.$env{'request.course.id'}.'.num'}.'/';
3020: $symb = &Apache::lonnet::encode_symb($path.$folder.".$container",
3021: $residx,
3022: &Apache::lonnet::declutter($currurl));
3023: }
1.484.2.12 raeburn 3024: }
1.484.2.30 raeburn 3025: my ($renamelink,%lt,$ishash);
3026: if (ref($filtersref) eq 'HASH') {
3027: $ishash = 1;
3028: }
3029:
1.329 droeschl 3030: if ($allowed) {
1.484.2.30 raeburn 3031: $form_start = '
3032: <form action="/adm/coursedocs" method="post">
3033: ';
3034: $form_common=(<<END);
3035: <input type="hidden" name="folderpath" value="$path" />
3036: <input type="hidden" name="symb" value="$symb" />
3037: END
3038: $form_param=(<<END);
3039: <input type="hidden" name="setparms" value="$orderidx" />
3040: <input type="hidden" name="changeparms" value="0" />
3041: END
3042: $form_end = '</form>';
3043:
1.329 droeschl 3044: my $incindex=$index+1;
3045: my $selectbox='';
1.471 raeburn 3046: if (($#LONCAPA::map::order>0) &&
1.329 droeschl 3047: ((split(/\:/,
1.344 bisitz 3048: $LONCAPA::map::resources[$LONCAPA::map::order[0]]))[1]
3049: ne '') &&
1.329 droeschl 3050: ((split(/\:/,
1.344 bisitz 3051: $LONCAPA::map::resources[$LONCAPA::map::order[1]]))[1]
1.329 droeschl 3052: ne '')) {
3053: $selectbox=
3054: '<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
1.373 bisitz 3055: '<select name="newpos" onchange="this.form.submit()">';
1.329 droeschl 3056: for (my $i=1;$i<=$#LONCAPA::map::order+1;$i++) {
3057: if ($i==$incindex) {
1.358 bisitz 3058: $selectbox.='<option value="" selected="selected">('.$i.')</option>';
1.329 droeschl 3059: } else {
3060: $selectbox.='<option value="'.$i.'">'.$i.'</option>';
3061: }
3062: }
3063: $selectbox.='</select>';
3064: }
1.484.2.12 raeburn 3065: %lt=&Apache::lonlocal::texthash(
1.329 droeschl 3066: 'up' => 'Move Up',
3067: 'dw' => 'Move Down',
3068: 'rm' => 'Remove',
3069: 'ct' => 'Cut',
3070: 'rn' => 'Rename',
1.484.2.12 raeburn 3071: 'cp' => 'Copy',
3072: 'ex' => 'External Resource',
3073: 'ed' => 'Edit',
3074: 'pr' => 'Preview',
3075: 'sv' => 'Save',
3076: 'ul' => 'URL',
3077: 'ti' => 'Title',
3078: );
1.484.2.30 raeburn 3079: my %denied = &action_restrictions($coursenum,$coursedom,$url,
3080: $env{'form.folderpath'},
3081: $currgroups);
1.484.2.19 raeburn 3082: my ($copylink,$cutlink,$removelink);
1.329 droeschl 3083: my $skip_confirm = 0;
3084: if ( $folder =~ /^supplemental/
3085: || ($url =~ m{( /smppg$
3086: |/syllabus$
3087: |/aboutme$
3088: |/navmaps$
3089: |/bulletinboard$
1.484.2.16 raeburn 3090: |\.html$)}x)
1.484.2.19 raeburn 3091: || $isexternal) {
1.329 droeschl 3092: $skip_confirm = 1;
3093: }
1.484.2.19 raeburn 3094:
1.484.2.30 raeburn 3095: if ($denied{'copy'}) {
3096: $copylink=(<<ENDCOPY)
1.484.2.16 raeburn 3097: <span style="visibility: hidden;">$lt{'cp'}</span>
3098: ENDCOPY
3099: } else {
1.484.2.30 raeburn 3100: my $formname = 'edit_copy_'.$orderidx;
3101: my $js = "javascript:checkForSubmit(document.forms.renameform,'copy','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.484.2.19 raeburn 3102: $copylink=(<<ENDCOPY);
1.484.2.30 raeburn 3103: <form name="$formname" method="post" action="/adm/coursedocs">
3104: $form_common
3105: <input type="checkbox" name="copy" id="copy_$orderidx" value="$orderidx" onclick="javascript:singleCheck(this,'$orderidx','copy');" class="LC_hidden" /><a href="$js" class="LC_docs_copy">$lt{'cp'}</a>
3106: $form_end
1.329 droeschl 3107: ENDCOPY
1.484.2.30 raeburn 3108: if (($ishash) && (ref($filtersref->{'cancopy'}) eq 'ARRAY')) {
3109: push(@{$filtersref->{'cancopy'}},$orderidx);
3110: }
1.329 droeschl 3111: }
1.484.2.30 raeburn 3112: if ($denied{'cut'}) {
1.484.2.16 raeburn 3113: $cutlink=(<<ENDCUT);
3114: <span style="visibility: hidden;">$lt{'ct'}</span>
3115: ENDCUT
3116: } else {
1.484.2.30 raeburn 3117: my $formname = 'edit_cut_'.$orderidx;
3118: my $js = "javascript:checkForSubmit(document.forms.renameform,'cut','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.484.2.19 raeburn 3119: $cutlink=(<<ENDCUT);
1.484.2.30 raeburn 3120: <form name="$formname" method="post" action="/adm/coursedocs">
3121: $form_common
3122: <input type="hidden" name="skip_$orderidx" id="skip_cut_$orderidx" value="$skip_confirm" />
3123: <input type="checkbox" name="cut" id="cut_$orderidx" value="$orderidx" onclick="javascript:singleCheck(this,'$orderidx','cut');" class="LC_hidden" /><a href="$js" class="LC_docs_cut">$lt{'ct'}</a>
3124: $form_end
1.329 droeschl 3125: ENDCUT
1.484.2.30 raeburn 3126: if (($ishash) && (ref($filtersref->{'cancut'}) eq 'ARRAY')) {
3127: push(@{$filtersref->{'cancut'}},$orderidx);
3128: }
1.329 droeschl 3129: }
1.484.2.30 raeburn 3130: if ($denied{'remove'}) {
1.484.2.16 raeburn 3131: $removelink=(<<ENDREM);
3132: <span style="visibility: hidden;">$lt{'rm'}</a>
3133: ENDREM
3134: } else {
1.484.2.30 raeburn 3135: my $formname = 'edit_remove_'.$orderidx;
3136: my $js = "javascript:checkForSubmit(document.forms.renameform,'remove','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm);";
1.484.2.9 raeburn 3137: $removelink=(<<ENDREM);
1.484.2.30 raeburn 3138: <form name="$formname" method="post" action="/adm/coursedocs">
3139: $form_common
3140: <input type="hidden" name="skip_$orderidx" id="skip_remove_$orderidx" value="$skip_confirm" />
3141: <input type="checkbox" name="remove" id="remove_$orderidx" value="$orderidx" onclick="javascript:singleCheck(this,'$orderidx','remove');" class="LC_hidden" /><a href="$js" class="LC_docs_remove">$lt{'rm'}</a>
3142: $form_end
1.484.2.9 raeburn 3143: ENDREM
1.484.2.30 raeburn 3144: if (($ishash) && (ref($filtersref->{'canremove'}) eq 'ARRAY')) {
3145: push(@{$filtersref->{'canremove'}},$orderidx);
3146: }
1.484.2.9 raeburn 3147: }
1.484.2.35 raeburn 3148: $renamelink=(<<ENDREN);
1.484.2.19 raeburn 3149: <a href='javascript:changename("$esc_path","$index","$renametitle");' class="LC_docs_rename">$lt{'rn'}</a>
1.484.2.16 raeburn 3150: ENDREN
1.329 droeschl 3151: $line.=(<<END);
3152: <td>
1.379 bisitz 3153: <div class="LC_docs_entry_move">
1.484.2.28 raeburn 3154: <a href='/adm/coursedocs?cmd=up_$index&folderpath=$esc_path&symb=$symb'>
1.484.2.12 raeburn 3155: <img src="${iconpath}move_up.gif" alt="$lt{'up'}" class="LC_icon" />
1.379 bisitz 3156: </a>
3157: </div>
3158: <div class="LC_docs_entry_move">
1.484.2.28 raeburn 3159: <a href='/adm/coursedocs?cmd=down_$index&folderpath=$esc_path&symb=$symb'>
1.484.2.12 raeburn 3160: <img src="${iconpath}move_down.gif" alt="$lt{'dw'}" class="LC_icon" />
1.379 bisitz 3161: </a>
3162: </div>
1.329 droeschl 3163: </td>
3164: <td>
3165: $form_start
1.484.2.30 raeburn 3166: $form_param
1.478 raeburn 3167: $form_common
1.329 droeschl 3168: $selectbox
3169: $form_end
3170: </td>
1.484.2.30 raeburn 3171: <td class="LC_docs_entry_commands LC_nobreak">
1.484.2.9 raeburn 3172: $removelink
1.329 droeschl 3173: $cutlink
3174: $copylink
3175: </td>
3176: END
3177: }
3178: # Figure out what kind of a resource this is
3179: my ($extension)=($url=~/\.(\w+)$/);
3180: my $uploaded=($url=~/^\/*uploaded\//);
3181: my $icon=&Apache::loncommon::icon($url);
1.484.2.19 raeburn 3182: my $isfolder;
3183: my $ispage;
3184: my $containerarg;
1.329 droeschl 3185: if ($uploaded) {
1.472 raeburn 3186: if (($extension eq 'sequence') || ($extension eq 'page')) {
3187: $url=~/\Q$coursenum\E\/([\/\w]+)\.\Q$extension\E$/;
1.484.2.19 raeburn 3188: $containerarg = $1;
1.472 raeburn 3189: if ($extension eq 'sequence') {
3190: $icon=$iconpath.'navmap.folder.closed.gif';
3191: $isfolder=1;
3192: } else {
3193: $icon=$iconpath.'page.gif';
3194: $ispage=1;
3195: }
3196: if ($allowed) {
3197: $url='/adm/coursedocs?';
3198: } else {
3199: $url='/adm/supplemental?';
3200: }
1.329 droeschl 3201: } else {
3202: &Apache::lonnet::allowuploaded('/adm/coursedoc',$url);
3203: }
3204: }
1.364 bisitz 3205:
1.484.2.19 raeburn 3206: my ($editlink,$extresform);
1.329 droeschl 3207: my $orig_url = $url;
1.340 raeburn 3208: $orig_url=~s{http(:|:)//https(:|:)//}{https$2//};
1.484.2.19 raeburn 3209: $url=~s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
1.484.2.12 raeburn 3210: if (!$supplementalflag && $residx && $symb) {
3211: if ((!$isfolder) && (!$ispage)) {
3212: (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
3213: $url=&Apache::lonnet::clutter($url);
3214: if ($url=~/^\/*uploaded\//) {
3215: $url=~/\.(\w+)$/;
3216: my $embstyle=&Apache::loncommon::fileembstyle($1);
3217: if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
3218: $url='/adm/wrapper'.$url;
3219: } elsif ($embstyle eq 'ssi') {
3220: #do nothing with these
3221: } elsif ($url!~/\.(sequence|page)$/) {
3222: $url='/adm/coursedocs/showdoc'.$url;
3223: }
3224: } elsif ($url=~m|^/ext/|) {
3225: $url='/adm/wrapper'.$url;
1.484.2.19 raeburn 3226: }
1.484.2.12 raeburn 3227: if (&Apache::lonnet::symbverify($symb,$url)) {
1.484.2.19 raeburn 3228: $url.=(($url=~/\?/)?'&':'?').'symb='.&escape($symb);
1.484.2.12 raeburn 3229: } else {
3230: $url='';
3231: }
1.484.2.19 raeburn 3232: }
1.329 droeschl 3233: }
1.478 raeburn 3234: my ($rand_pick_text,$rand_order_text);
1.484.2.19 raeburn 3235: if ($isfolder || $ispage || $extension eq 'sequence' || $extension eq 'page') {
1.329 droeschl 3236: my $foldername=&escape($foldertitle);
3237: my $folderpath=$env{'form.folderpath'};
3238: if ($folderpath) { $folderpath.='&' };
1.484.2.19 raeburn 3239: if (!$allowed && $supplementalflag) {
3240: $folderpath.=$containerarg.'&'.$foldername;
3241: $url.='folderpath='.&escape($folderpath);
3242: } else {
1.344 bisitz 3243: # Append randompick number, hidden, and encrypted with ":" to foldername,
1.329 droeschl 3244: # so it gets transferred between levels
1.484.2.19 raeburn 3245: $folderpath.=$containerarg.'&'.$foldername.
3246: ':'.(&LONCAPA::map::getparameter($orderidx,
1.329 droeschl 3247: 'parameter_randompick'))[0]
3248: .':'.((&LONCAPA::map::getparameter($orderidx,
3249: 'parameter_hiddenresource'))[0]=~/^yes$/i)
3250: .':'.((&LONCAPA::map::getparameter($orderidx,
3251: 'parameter_encrypturl'))[0]=~/^yes$/i)
3252: .':'.((&LONCAPA::map::getparameter($orderidx,
1.484.2.19 raeburn 3253: 'parameter_randomorder'))[0]=~/^yes$/i)
3254: .':'.$ispage;
3255: $url.='folderpath='.&escape($folderpath);
3256: my $rpicknum = (&LONCAPA::map::getparameter($orderidx,
3257: 'parameter_randompick'))[0];
3258: my $rpckchk;
3259: if ($rpicknum) {
3260: $rpckchk = ' checked="checked"';
1.484.2.30 raeburn 3261: if (($ishash) && (ref($filtersref->{'randompick'}) eq 'ARRAY')) {
3262: push(@{$filtersref->{'randompick'}},$orderidx.':'.$rpicknum);
3263: }
1.484.2.19 raeburn 3264: }
1.484.2.29 raeburn 3265: my $formname = 'edit_randompick_'.$orderidx;
1.484.2.19 raeburn 3266: $rand_pick_text =
1.478 raeburn 3267: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.484.2.30 raeburn 3268: $form_param."\n".
1.478 raeburn 3269: $form_common."\n".
1.484.2.29 raeburn 3270: '<span class="LC_nobreak"><label><input type="checkbox" name="randompick_'.$orderidx.'" id="randompick_'.$orderidx.'" onclick="'."updatePick(this.form,'$orderidx','check');".'"'.$rpckchk.' /> '.&mt('Randomly Pick').'</label><input type="hidden" name="rpicknum_'.$orderidx.'" id="rpicknum_'.$orderidx.'" value="'.$rpicknum.'" /><span id="randompicknum_'.$orderidx.'">';
1.484.2.19 raeburn 3271: if ($rpicknum ne '') {
3272: $rand_pick_text .= ': <a href="javascript:updatePick('."document.$formname,'$orderidx','link'".')">'.$rpicknum.'</a>';
3273: }
1.484.2.29 raeburn 3274: $rand_pick_text .= '</span></span>'.
3275: $form_end;
1.484.2.30 raeburn 3276: my $ro_set;
3277: if ((&LONCAPA::map::getparameter($orderidx,'parameter_randomorder'))[0]=~/^yes$/i) {
3278: $ro_set = 'checked="checked"';
3279: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
3280: push(@{$filtersref->{'randomorder'}},$orderidx);
3281: }
3282: }
1.484.2.29 raeburn 3283: my $formname = 'edit_rorder_'.$orderidx;
1.484.2.19 raeburn 3284: $rand_order_text =
1.484.2.29 raeburn 3285: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.484.2.30 raeburn 3286: $form_param."\n".
1.484.2.29 raeburn 3287: $form_common."\n".
1.484.2.30 raeburn 3288: '<span class="LC_nobreak"><label><input type="checkbox" name="randomorder_'.$orderidx.'" id="randomorder_'.$orderidx.'" onclick="checkForSubmit(this.form,'."'randomorder','settings'".');" '.$ro_set.' /> '.&mt('Random Order').' </label></span>'.
1.484.2.29 raeburn 3289: $form_end;
1.484.2.19 raeburn 3290: }
1.484.2.18 raeburn 3291: } elsif ($supplementalflag && !$allowed) {
1.484.2.19 raeburn 3292: $url .= ($url =~ /\?/) ? '&':'?';
1.484.2.18 raeburn 3293: $url .= 'folderpath='.&HTML::Entities::encode($esc_path,'<>&"');
1.484.2.19 raeburn 3294: if ($title) {
3295: $url .= '&title='.&HTML::Entities::encode($renametitle,'<>&"');
3296: }
3297: if ($isexternal && $orderidx) {
3298: $url .= '&idx='.$orderidx;
3299: }
1.329 droeschl 3300: }
1.484.2.19 raeburn 3301: my ($tdalign,$tdwidth);
1.484.2.12 raeburn 3302: if ($allowed) {
1.484.2.19 raeburn 3303: my $fileloc =
1.484.2.12 raeburn 3304: &Apache::lonnet::declutter(&Apache::lonnet::filelocation('',$orig_url));
1.484.2.19 raeburn 3305: if ($isexternal) {
3306: ($editlink,$extresform) =
3307: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem);
3308: } elsif (!$isfolder && !$ispage) {
3309: my ($cfile,$home,$switchserver,$forceedit,$forceview) =
1.484.2.14 raeburn 3310: &Apache::lonnet::can_edit_resource($fileloc,$coursenum,$coursedom,$orig_url);
1.484.2.19 raeburn 3311: if (($cfile ne '') && ($symb ne '' || $supplementalflag)) {
3312: my $jscall =
1.484.2.12 raeburn 3313: &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,
3314: $switchserver,
1.484.2.14 raeburn 3315: $forceedit,
1.484.2.19 raeburn 3316: undef,$symb,
3317: &escape($env{'form.folderpath'}),
3318: $renametitle,'','',1);
1.484.2.12 raeburn 3319: if ($jscall) {
1.484.2.19 raeburn 3320: $editlink = '<a class="LC_docs_ext_edit" href="javascript:'.
3321: $jscall.'" >'.&mt('Edit').'</a> '."\n";
1.484.2.12 raeburn 3322: }
3323: }
3324: }
1.484.2.19 raeburn 3325: $tdalign = ' align="right" valign="top"';
3326: $tdwidth = ' width="80%"';
1.329 droeschl 3327: }
1.408 raeburn 3328: my $reinit;
3329: if ($crstype eq 'Community') {
3330: $reinit = &mt('(re-initialize community to access)');
3331: } else {
3332: $reinit = &mt('(re-initialize course to access)');
1.484.2.19 raeburn 3333: }
3334: $line.='<td class="LC_docs_entry_commands"'.$tdalign.'><span class="LC_nobreak">'.$editlink.$renamelink;
1.472 raeburn 3335: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.469 www 3336: $line.='<a href="'.$url.'"><img src="'.$icon.'" alt="" class="LC_icon" /></a>';
3337: } elsif ($url) {
1.484 raeburn 3338: $line.=&Apache::loncommon::modal_link($url.(($url=~/\?/)?'&':'?').'inhibitmenu=yes',
1.470 raeburn 3339: '<img src="'.$icon.'" alt="" class="LC_icon" />',600,500);
1.469 www 3340: } else {
3341: $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
3342: }
1.484.2.19 raeburn 3343: $line.='</span></td><td'.$tdwidth.'>';
1.472 raeburn 3344: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.469 www 3345: $line.='<a href="'.$url.'">'.$title.'</a>';
3346: } elsif ($url) {
1.484 raeburn 3347: $line.=&Apache::loncommon::modal_link($url.(($url=~/\?/)?'&':'?').'inhibitmenu=yes',
1.470 raeburn 3348: $title,600,500);
1.469 www 3349: } else {
3350: $line.=$title.' <span class="LC_docs_reinit_warn">'.$reinit.'</span>';
3351: }
1.484.2.19 raeburn 3352: $line.="$extresform</td>";
1.478 raeburn 3353: $rand_pick_text = ' ' if ($rand_pick_text eq '');
3354: $rand_order_text = ' ' if ($rand_order_text eq '');
1.329 droeschl 3355: if (($allowed) && ($folder!~/^supplemental/)) {
3356: my %lt=&Apache::lonlocal::texthash(
3357: 'hd' => 'Hidden',
3358: 'ec' => 'URL hidden');
1.484.2.30 raeburn 3359: my ($enctext,$hidtext);
3360: if ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) {
3361: $enctext = ' checked="checked"';
3362: if (($ishash) && (ref($filtersref->{'encrypturl'}) eq 'ARRAY')) {
3363: push(@{$filtersref->{'encrypturl'}},$orderidx);
3364: }
3365: }
3366: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
3367: $hidtext = ' checked="checked"';
3368: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
3369: push(@{$filtersref->{'hiddenresource'}},$orderidx);
3370: }
3371: }
1.484.2.29 raeburn 3372: my $formhidden = 'edit_hiddenresource_'.$orderidx;
3373: my $formurlhidden = 'edit_encrypturl_'.$orderidx;
1.329 droeschl 3374: $line.=(<<ENDPARMS);
3375: <td class="LC_docs_entry_parameter">
1.484.2.30 raeburn 3376: <form action="/adm/coursedocs" method="post" name="$formhidden">
3377: $form_param
1.478 raeburn 3378: $form_common
1.484.2.30 raeburn 3379: <label><input type="checkbox" name="hiddenresource_$orderidx" id="hiddenresource_$orderidx" onclick="checkForSubmit(this.form,'hiddenresource','settings');" $hidtext /> $lt{'hd'}</label>
1.329 droeschl 3380: $form_end
1.458 raeburn 3381: <br />
1.484.2.29 raeburn 3382: <form action="/adm/coursedocs" method="post" name="$formurlhidden">
1.484.2.30 raeburn 3383: $form_param
1.478 raeburn 3384: $form_common
1.484.2.30 raeburn 3385: <label><input type="checkbox" name="encrypturl_$orderidx" id="encrypturl_$orderidx" onclick="checkForSubmit(this.form,'encrypturl','settings');" $enctext /> $lt{'ec'}</label>
1.329 droeschl 3386: $form_end
3387: </td>
1.478 raeburn 3388: <td class="LC_docs_entry_parameter">$rand_pick_text<br />
3389: $rand_order_text</td>
1.329 droeschl 3390: ENDPARMS
3391: }
1.379 bisitz 3392: $line.=&Apache::loncommon::end_data_table_row();
1.329 droeschl 3393: return $line;
3394: }
3395:
1.484.2.30 raeburn 3396: sub action_restrictions {
3397: my ($cnum,$cdom,$url,$folderpath,$currgroups) = @_;
3398: my %denied = (
3399: cut => 0,
3400: copy => 0,
3401: remove => 0,
3402: );
3403: if ($url=~ m{^/res/.+\.(page|sequence)$}) {
3404: # no copy for published maps
3405: $denied{'copy'} = 1;
3406: } elsif ($url=~m{^/res/lib/templates/}) {
3407: $denied{'copy'} = 1;
3408: $denied{'cut'} = 1;
3409: } elsif ($url eq "/uploaded/$cdom/$cnum/group_allfolders.sequence") {
3410: if ($folderpath =~ /^default&[^\&]+$/) {
3411: if ((ref($currgroups) eq 'HASH') && (keys(%{$currgroups}) > 0)) {
3412: $denied{'remove'} = 1;
3413: }
3414: $denied{'cut'} = 1;
3415: $denied{'copy'} = 1;
3416: }
3417: } elsif ($url =~ m{^\Q/uploaded/$cdom/$cnum/group_folder_\E(\w+)\.sequence$}) {
3418: my $group = $1;
3419: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+$/) {
3420: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
3421: $denied{'remove'} = 1;
3422: }
3423: }
3424: $denied{'cut'} = 1;
3425: $denied{'copy'} = 1;
3426: } elsif ($url =~ m{^\Q/adm/$cdom/$cnum/\E(\w+)/smppg$}) {
3427: my $group = $1;
3428: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&\Qgroup_folder_$group\E\&[^\&]+$/) {
3429: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
3430: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
3431: if (keys(%groupsettings) > 0) {
3432: $denied{'remove'} = 1;
3433: }
3434: $denied{'cut'} = 1;
3435: $denied{'copy'} = 1;
3436: }
3437: }
3438: } elsif ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&group_folder_(\w+)\&/) {
3439: my $group = $1;
3440: if ($url =~ /group_boards_\Q$group\E/) {
3441: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
3442: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
3443: if (keys(%groupsettings) > 0) {
3444: if (ref($groupsettings{'functions'}) eq 'HASH') {
3445: if ($groupsettings{'functions'}{'discussion'} eq 'on') {
3446: $denied{'remove'} = 1;
3447: }
3448: }
3449: }
3450: $denied{'cut'} = 1;
3451: $denied{'copy'} = 1;
3452: }
3453: }
3454: }
3455: return %denied;
3456: }
3457:
1.484.2.26 raeburn 3458: sub new_timebased_suffix {
1.484.2.30 raeburn 3459: my ($dom,$num,$type,$area,$container) = @_;
1.484.2.26 raeburn 3460: my ($prefix,$namespace,$idtype,$errtext,$locknotfreed);
1.484.2.30 raeburn 3461: if ($type eq 'paste') {
3462: $prefix = $type;
3463: $namespace = 'courseeditor';
3464: } elsif ($type eq 'map') {
1.484.2.26 raeburn 3465: $prefix = 'docs';
3466: if ($area eq 'supplemental') {
3467: $prefix = 'supp';
3468: }
3469: $prefix .= $container;
3470: $namespace = 'uploadedmaps';
3471: } else {
3472: $prefix = $type;
3473: $namespace = 'templated';
1.484.2.15 raeburn 3474: }
3475: $idtype = 'concat';
3476: my ($suffix,$freedlock,$error) =
1.484.2.30 raeburn 3477: &Apache::lonnet::get_timebased_id($prefix,'num',$namespace,$dom,$num);
1.484.2.15 raeburn 3478: if (!$suffix) {
1.484.2.30 raeburn 3479: if ($type eq 'paste') {
3480: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when adding to the paste buffer.');
3481: } elsif ($type eq 'map') {
1.484.2.26 raeburn 3482: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new folder/page.');
3483: } elsif ($type eq 'smppg') {
3484: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new simple page.');
3485: } else {
3486: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new bulletin board.');
3487: }
1.484.2.15 raeburn 3488: if ($error) {
3489: $errtext .= '<br />'.$error;
3490: }
3491: }
3492: if ($freedlock ne 'ok') {
1.484.2.26 raeburn 3493: $locknotfreed =
3494: '<div class="LC_error">'.
3495: &mt('There was a problem removing a lockfile.').' ';
1.484.2.30 raeburn 3496: if ($type eq 'paste') {
3497: &mt('This will prevent use of the paste buffer until th next log-in.');
3498: } elsif ($type eq 'map') {
1.484.2.26 raeburn 3499: &mt('This will prevent creation of additional folders or composite pages in this course.');
3500: } elsif ($type eq 'smppg') {
3501: $locknotfreed .=
3502: &mt('This will prevent creation of additional simple pages in this course.');
3503: } else {
3504: $locknotfreed .=
3505: &mt('This will prevent creation of additional bulletin boards in this course.');
3506: }
1.484.2.30 raeburn 3507: unless ($type eq 'paste') {
3508: $locknotfreed .=
3509: ' '.&mt('Please contact the domain coordinator for your LON-CAPA domain.');
3510: }
3511: $locknotfreed .= '</div>';
1.484.2.15 raeburn 3512: }
3513: return ($suffix,$errtext,$locknotfreed);
3514: }
3515:
1.329 droeschl 3516: =pod
3517:
3518: =item tiehash()
3519:
3520: tie the hash
3521:
3522: =cut
3523:
3524: sub tiehash {
3525: my ($mode)=@_;
3526: $hashtied=0;
3527: if ($env{'request.course.fn'}) {
3528: if ($mode eq 'write') {
3529: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
3530: &GDBM_WRCREAT(),0640)) {
3531: $hashtied=2;
3532: }
3533: } else {
3534: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
3535: &GDBM_READER(),0640)) {
3536: $hashtied=1;
3537: }
3538: }
1.364 bisitz 3539: }
1.329 droeschl 3540: }
3541:
3542: sub untiehash {
3543: if ($hashtied) { untie %hash; }
3544: $hashtied=0;
3545: return OK;
3546: }
3547:
3548:
3549:
3550:
3551: sub checkonthis {
3552: my ($r,$url,$level,$title)=@_;
3553: $url=&unescape($url);
3554: $alreadyseen{$url}=1;
3555: $r->rflush();
3556: if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
3557: $r->print("\n<br />");
3558: if ($level==0) {
3559: $r->print("<br />");
3560: }
3561: for (my $i=0;$i<=$level*5;$i++) {
3562: $r->print(' ');
3563: }
3564: $r->print('<a href="'.$url.'" target="cat">'.
3565: ($title?$title:$url).'</a> ');
3566: if ($url=~/^\/res\//) {
3567: my $result=&Apache::lonnet::repcopy(
3568: &Apache::lonnet::filelocation('',$url));
3569: if ($result eq 'ok') {
3570: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
3571: $r->rflush();
3572: &Apache::lonnet::countacc($url);
3573: $url=~/\.(\w+)$/;
3574: if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
3575: $r->print('<br />');
3576: $r->rflush();
3577: for (my $i=0;$i<=$level*5;$i++) {
3578: $r->print(' ');
3579: }
3580: $r->print('- '.&mt('Rendering:').' ');
3581: my ($errorcount,$warningcount)=split(/:/,
3582: &Apache::lonnet::ssi_body($url,
3583: ('grade_target'=>'web',
3584: 'return_only_error_and_warning_counts' => 1)));
3585: if (($errorcount) ||
3586: ($warningcount)) {
3587: if ($errorcount) {
1.369 bisitz 3588: $r->print('<img src="/adm/lonMisc/bomb.gif" alt="'.&mt('bomb').'" /><span class="LC_error">'.
1.329 droeschl 3589: &mt('[quant,_1,error]',$errorcount).'</span>');
3590: }
3591: if ($warningcount) {
3592: $r->print('<span class="LC_warning">'.
3593: &mt('[quant,_1,warning]',$warningcount).'</span>');
3594: }
3595: } else {
3596: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
3597: }
3598: $r->rflush();
3599: }
3600: my $dependencies=
3601: &Apache::lonnet::metadata($url,'dependencies');
3602: foreach my $dep (split(/\,/,$dependencies)) {
3603: if (($dep=~/^\/res\//) && (!$alreadyseen{$dep})) {
3604: &checkonthis($r,$dep,$level+1);
3605: }
3606: }
3607: } elsif ($result eq 'unavailable') {
3608: $r->print('<span class="LC_error">'.&mt('connection down').'</span>');
3609: } elsif ($result eq 'not_found') {
3610: unless ($url=~/\$/) {
1.484.2.19 raeburn 3611: $r->print('<span class="LC_error">'.&mt('not found').'</span>');
1.329 droeschl 3612: } else {
1.366 bisitz 3613: $r->print('<span class="LC_error">'.&mt('unable to verify variable URL').'</span>');
1.329 droeschl 3614: }
3615: } else {
3616: $r->print('<span class="LC_error">'.&mt('access denied').'</span>');
3617: }
3618: }
3619: }
3620: }
3621:
3622:
3623:
3624: =pod
3625:
3626: =item list_symbs()
3627:
1.484.2.3 raeburn 3628: List Content Identifiers
1.329 droeschl 3629:
3630: =cut
3631:
3632: sub list_symbs {
3633: my ($r) = @_;
3634:
1.408 raeburn 3635: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 3636: $r->print(&Apache::loncommon::start_page('List of Content Identifiers'));
3637: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Identifiers'));
3638: $r->print(&startContentScreen('tools'));
1.329 droeschl 3639: my $navmap = Apache::lonnavmaps::navmap->new();
3640: if (!defined($navmap)) {
3641: $r->print('<h2>'.&mt('Retrieval of List Failed').'</h2>'.
3642: '<div class="LC_error">'.
3643: &mt('Unable to retrieve information about course contents').
3644: '</div>');
1.408 raeburn 3645: &Apache::lonnet::logthis('Symb list failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
1.329 droeschl 3646: } else {
1.484 raeburn 3647: $r->print('<h4 class="LC_info">'.&mt("$crstype Content Identifiers").'</h4>'.
3648: &Apache::loncommon::start_data_table().
3649: &Apache::loncommon::start_data_table_header_row().
3650: '<th>'.&mt('Title').'</th><th>'.&mt('Identifier').'</th>'.
3651: &Apache::loncommon::end_data_table_header_row()."\n");
3652: my $count;
1.329 droeschl 3653: foreach my $res ($navmap->retrieveResources()) {
1.484 raeburn 3654: $r->print(&Apache::loncommon::start_data_table_row().
3655: '<td>'.$res->compTitle().'</td>'.
3656: '<td>'.$res->symb().'</td>'.
1.484.2.19 raeburn 3657: &Apache::loncommon::end_data_table_row());
1.484 raeburn 3658: $count ++;
3659: }
3660: if (!$count) {
3661: $r->print(&Apache::loncommon::start_data_table_row().
3662: '<td colspan="2">'.&mt("$crstype is empty").'</td>'.
3663: &Apache::loncommon::end_data_table_row());
1.329 droeschl 3664: }
1.484 raeburn 3665: $r->print(&Apache::loncommon::end_data_table());
1.329 droeschl 3666: }
1.484.2.19 raeburn 3667: $r->print(&endContentScreen());
1.329 droeschl 3668: }
3669:
3670:
3671: sub verifycontent {
3672: my ($r) = @_;
1.408 raeburn 3673: my $crstype = &Apache::loncommon::course_type();
1.484.2.34 raeburn 3674: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
3675: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
1.484 raeburn 3676: $r->print(&startContentScreen('tools'));
3677: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
1.329 droeschl 3678: $hashtied=0;
3679: undef %alreadyseen;
3680: %alreadyseen=();
3681: &tiehash();
1.484 raeburn 3682:
1.329 droeschl 3683: foreach my $key (keys(%hash)) {
3684: if ($hash{$key}=~/\.(page|sequence)$/) {
3685: if (($key=~/^src_/) && ($alreadyseen{&unescape($hash{$key})})) {
3686: $r->print('<hr /><span class="LC_error">'.
1.419 bisitz 3687: &mt('The following sequence or page is included more than once in your '.$crstype.':').' '.
1.329 droeschl 3688: &unescape($hash{$key}).'</span><br />'.
1.419 bisitz 3689: &mt('Note that grading records for problems included in this sequence or folder will overlap.').'<hr />');
1.329 droeschl 3690: }
3691: }
3692: if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) {
3693: &checkonthis($r,$hash{$key},0,$hash{'title_'.$1});
3694: }
3695: }
3696: &untiehash();
1.442 www 3697: $r->print('<p class="LC_success">'.&mt('Done').'</p>');
1.484.2.19 raeburn 3698: $r->print(&endContentScreen());
1.329 droeschl 3699: }
3700:
3701:
3702: sub devalidateversioncache {
3703: my $src=shift;
3704: &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
3705: &Apache::lonnet::clutter($src));
3706: }
3707:
3708: sub checkversions {
3709: my ($r) = @_;
1.408 raeburn 3710: my $crstype = &Apache::loncommon::course_type();
3711: $r->print(&Apache::loncommon::start_page("Check $crstype Document Versions"));
3712: $r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $crstype Document Versions"));
1.484 raeburn 3713: $r->print(&startContentScreen('tools'));
1.442 www 3714:
1.329 droeschl 3715: my $header='';
3716: my $startsel='';
3717: my $monthsel='';
3718: my $weeksel='';
3719: my $daysel='';
3720: my $allsel='';
3721: my %changes=();
3722: my $starttime=0;
3723: my $haschanged=0;
3724: my %setversions=&Apache::lonnet::dump('resourceversions',
3725: $env{'course.'.$env{'request.course.id'}.'.domain'},
3726: $env{'course.'.$env{'request.course.id'}.'.num'});
3727:
3728: $hashtied=0;
3729: &tiehash();
3730: my %newsetversions=();
3731: if ($env{'form.setmostrecent'}) {
3732: $haschanged=1;
3733: foreach my $key (keys(%hash)) {
3734: if ($key=~/^ids\_(\/res\/.+)$/) {
3735: $newsetversions{$1}='mostrecent';
3736: &devalidateversioncache($1);
3737: }
3738: }
3739: } elsif ($env{'form.setcurrent'}) {
3740: $haschanged=1;
3741: foreach my $key (keys(%hash)) {
3742: if ($key=~/^ids\_(\/res\/.+)$/) {
3743: my $getvers=&Apache::lonnet::getversion($1);
3744: if ($getvers>0) {
3745: $newsetversions{$1}=$getvers;
3746: &devalidateversioncache($1);
3747: }
3748: }
3749: }
3750: } elsif ($env{'form.setversions'}) {
3751: $haschanged=1;
3752: foreach my $key (keys(%env)) {
3753: if ($key=~/^form\.set_version_(.+)$/) {
3754: my $src=$1;
3755: if (($env{$key}) && ($env{$key} ne $setversions{$src})) {
3756: $newsetversions{$src}=$env{$key};
3757: &devalidateversioncache($src);
3758: }
3759: }
3760: }
3761: }
3762: if ($haschanged) {
3763: if (&Apache::lonnet::put('resourceversions',\%newsetversions,
3764: $env{'course.'.$env{'request.course.id'}.'.domain'},
1.344 bisitz 3765: $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
1.479 golterma 3766: $r->print(&Apache::loncommon::confirmwrapper(
3767: &Apache::lonhtmlcommon::confirm_success(&mt('Your Version Settings have been Saved'))));
1.329 droeschl 3768: } else {
1.479 golterma 3769: $r->print(&Apache::loncommon::confirmwrapper(
3770: &Apache::lonhtmlcommon::confirm_success(&mt('An Error Occured while Attempting to Save your Version Settings'),1)));
1.329 droeschl 3771: }
3772: &mark_hash_old();
3773: }
3774: &changewarning($r,'');
3775: if ($env{'form.timerange'} eq 'all') {
3776: # show all documents
1.484.2.34 raeburn 3777: $header=&mt('All content in '.$crstype);
1.484.2.19 raeburn 3778: $allsel=' selected="selected"';
1.329 droeschl 3779: foreach my $key (keys(%hash)) {
3780: if ($key=~/^ids\_(\/res\/.+)$/) {
3781: my $src=$1;
3782: $changes{$src}=1;
3783: }
3784: }
3785: } else {
3786: # show documents which changed
3787: %changes=&Apache::lonnet::dump
3788: ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
3789: $env{'course.'.$env{'request.course.id'}.'.num'});
3790: my $firstkey=(keys(%changes))[0];
3791: unless ($firstkey=~/^error\:/) {
3792: unless ($env{'form.timerange'}) {
3793: $env{'form.timerange'}=604800;
3794: }
3795: my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
3796: .&mt('seconds');
3797: if ($env{'form.timerange'}==-1) {
3798: $seltext='since start of course';
1.484.2.19 raeburn 3799: $startsel=' selected="selected"';
1.329 droeschl 3800: $env{'form.timerange'}=time;
3801: }
3802: $starttime=time-$env{'form.timerange'};
3803: if ($env{'form.timerange'}==2592000) {
3804: $seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.484.2.19 raeburn 3805: $monthsel=' selected="selected"';
1.329 droeschl 3806: } elsif ($env{'form.timerange'}==604800) {
3807: $seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.484.2.19 raeburn 3808: $weeksel=' selected="selected"';
1.329 droeschl 3809: } elsif ($env{'form.timerange'}==86400) {
3810: $seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.484.2.19 raeburn 3811: $daysel=' selected="selected"';
1.329 droeschl 3812: }
3813: $header=&mt('Content changed').' '.$seltext;
3814: } else {
3815: $header=&mt('No content modifications yet.');
3816: }
3817: }
3818: %setversions=&Apache::lonnet::dump('resourceversions',
3819: $env{'course.'.$env{'request.course.id'}.'.domain'},
3820: $env{'course.'.$env{'request.course.id'}.'.num'});
3821: my %lt=&Apache::lonlocal::texthash
1.408 raeburn 3822: ('st' => 'Version changes since start of '.$crstype,
1.329 droeschl 3823: 'lm' => 'Version changes since last Month',
3824: 'lw' => 'Version changes since last Week',
3825: 'sy' => 'Version changes since Yesterday',
3826: 'al' => 'All Resources (possibly large output)',
1.484 raeburn 3827: 'cd' => 'Change display',
1.329 droeschl 3828: 'sd' => 'Display',
3829: 'fi' => 'File',
3830: 'md' => 'Modification Date',
3831: 'mr' => 'Most recently published Version',
1.408 raeburn 3832: 've' => 'Version used in '.$crstype,
3833: 'vu' => 'Set Version to be used in '.$crstype,
3834: 'sv' => 'Set Versions to be used in '.$crstype.' according to Selections below',
1.329 droeschl 3835: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
3836: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
1.479 golterma 3837: 'di' => 'Differences',
1.484 raeburn 3838: 'save' => 'Save changes',
3839: 'vers' => 'Version choice(s) for specific resources',
1.479 golterma 3840: 'act' => 'Actions');
1.329 droeschl 3841: $r->print(<<ENDHEADERS);
1.484 raeburn 3842: <h4 class="LC_info">$header</h4>
1.329 droeschl 3843: <form action="/adm/coursedocs" method="post">
3844: <input type="hidden" name="versions" value="1" />
1.484 raeburn 3845: <div class="LC_left_float">
1.479 golterma 3846: <fieldset>
1.484 raeburn 3847: <legend>$lt{'cd'}</legend>
1.329 droeschl 3848: <select name="timerange">
1.484.2.19 raeburn 3849: <option value='all'$allsel>$lt{'al'}</option>
3850: <option value="-1"$startsel>$lt{'st'}</option>
3851: <option value="2592000"$monthsel>$lt{'lm'}</option>
3852: <option value="604800"$weeksel>$lt{'lw'}</option>
3853: <option value="86400"$daysel>$lt{'sy'}</option>
1.329 droeschl 3854: </select>
3855: <input type="submit" name="display" value="$lt{'sd'}" />
1.484 raeburn 3856: </fieldset>
3857: </div>
3858: <div class="LC_left_float">
3859: <fieldset>
3860: <legend>$lt{'act'}</legend>
3861: $lt{'sm'}: <input type="submit" name="setmostrecent" value="Go" /><br />
3862: $lt{'sc'}: <input type="submit" name="setcurrent" value="Go" />
3863: </fieldset>
3864: </div>
3865: <br clear="all" />
3866: <hr />
3867: <h4>$lt{'vers'}</h4>
1.479 golterma 3868: <input type="submit" name="setversions" value="$lt{'save'}" />
1.329 droeschl 3869: ENDHEADERS
1.479 golterma 3870: #number of columns for version history
3871: $r->print(
1.484.2.19 raeburn 3872: &Apache::loncommon::start_data_table().
3873: &Apache::loncommon::start_data_table_header_row().
3874: '<th>'.&mt('Resources').'</th>'.
3875: "<th>$lt{'mr'}</th>".
3876: "<th>$lt{'ve'}</th>".
3877: "<th>$lt{'vu'}</th>".
3878: '<th>'.&mt('History').'</th>'.
3879: &Apache::loncommon::end_data_table_header_row()
3880: );
1.329 droeschl 3881: foreach my $key (sort(keys(%changes))) {
1.484.2.10 raeburn 3882: #excludes not versionable problems from resource version history:
3883: next unless ($changes{$key}>$starttime && $key !~ /^\/res\/lib\/templates/);
1.484.2.19 raeburn 3884: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
3885: my $currentversion=&Apache::lonnet::getversion($key);
3886: if ($currentversion<0) {
3887: $currentversion='<span class="LC_error">'.&mt('Could not be determined.').'</span>';
3888: }
3889: my $linkurl=&Apache::lonnet::clutter($key);
1.479 golterma 3890: $r->print(
3891: &Apache::loncommon::start_data_table_row().
1.484.2.19 raeburn 3892: '<td><b>'.&Apache::lonnet::gettitle($linkurl).'</b><br />'.
1.479 golterma 3893: '<a href="'.$linkurl.'" target="cat">'.$linkurl.'</a></td>'.
1.484.2.19 raeburn 3894: '<td align="right">'.$currentversion.'<span class="LC_fontsize_medium"><br />('.
1.479 golterma 3895: &Apache::lonlocal::locallocaltime(&Apache::lonnet::metadata($root.'.'.$extension,'lastrevisiondate')).')</span></td>'.
1.484.2.19 raeburn 3896: '<td align="right">'
3897: );
3898: # Used in course
3899: my $usedversion=$hash{'version_'.$linkurl};
3900: if (($usedversion) && ($usedversion ne 'mostrecent')) {
3901: if ($usedversion != $currentversion) {
1.479 golterma 3902: $r->print('<span class="LC_warning">'.$usedversion.'</span>');
1.484.2.19 raeburn 3903: } else {
1.479 golterma 3904: $r->print($usedversion);
3905: }
1.329 droeschl 3906: } else {
1.484.2.19 raeburn 3907: $r->print($currentversion);
1.329 droeschl 3908: }
1.484.2.19 raeburn 3909: $r->print('</td><td title="'.$lt{'vu'}.'">');
3910: # Set version
3911: $r->print(&Apache::loncommon::select_form(
3912: $setversions{$linkurl},
3913: 'set_version_'.$linkurl,
3914: {'select_form_order' => ['',1..$currentversion,'mostrecent'],
3915: '' => '',
3916: 'mostrecent' => &mt('most recent'),
3917: map {$_,$_} (1..$currentversion)}));
3918: my $lastold=1;
3919: for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
3920: my $url=$root.'.'.$prevvers.'.'.$extension;
3921: if (&Apache::lonnet::metadata($url,'lastrevisiondate')<$starttime) {
3922: $lastold=$prevvers;
3923: }
3924: }
3925: $r->print('</td>');
3926: # List all available versions
3927: $r->print('<td valign="top"><span class="LC_fontsize_medium">');
3928: for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
3929: my $url=$root.'.'.$prevvers.'.'.$extension;
3930: $r->print(
3931: '<span class="LC_nobreak">'
3932: .'<a href="'.&Apache::lonnet::clutter($url).'">'
3933: .&mt('Version [_1]',$prevvers).'</a>'
3934: .' ('.&Apache::lonlocal::locallocaltime(
3935: &Apache::lonnet::metadata($url,'lastrevisiondate'))
3936: .')');
3937: if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
3938: $r->print(
3939: ' <a href="/adm/diff?filename='.
3940: &Apache::lonnet::clutter($root.'.'.$extension).
3941: &HTML::Entities::encode('&versionone='.$prevvers,'"<>&').
3942: '" target="diffs">'.&mt('Diffs').'</a>');
1.329 droeschl 3943: }
1.484.2.19 raeburn 3944: $r->print('</span><br />');
3945: }
3946: $r->print('</span></td>'.&Apache::loncommon::end_data_table_row());
1.329 droeschl 3947: }
1.484.2.19 raeburn 3948: $r->print(
3949: &Apache::loncommon::end_data_table().
3950: '<input type="submit" name="setversions" value="'.$lt{'save'}.'" />'.
3951: '</form>'
3952: );
1.329 droeschl 3953:
3954: &untiehash();
1.484.2.19 raeburn 3955: $r->print(&endContentScreen());
1.329 droeschl 3956: }
3957:
3958: sub mark_hash_old {
3959: my $retie_hash=0;
3960: if ($hashtied) {
3961: $retie_hash=1;
3962: &untiehash();
3963: }
3964: &tiehash('write');
3965: $hash{'old'}=1;
3966: &untiehash();
3967: if ($retie_hash) { &tiehash(); }
3968: }
3969:
3970: sub is_hash_old {
3971: my $untie_hash=0;
3972: if (!$hashtied) {
3973: $untie_hash=1;
3974: &tiehash();
3975: }
3976: my $return=$hash{'old'};
3977: if ($untie_hash) { &untiehash(); }
3978: return $return;
3979: }
3980:
3981: sub changewarning {
3982: my ($r,$postexec,$message,$url)=@_;
3983: if (!&is_hash_old()) { return; }
3984: my $pathvar='folderpath';
3985: my $path=&escape($env{'form.folderpath'});
3986: if (!defined($url)) {
3987: $url='/adm/coursedocs?'.$pathvar.'='.$path;
3988: }
3989: my $course_type = &Apache::loncommon::course_type();
3990: if (!defined($message)) {
3991: $message='Changes will become active for your current session after [_1], or the next time you log in.';
3992: }
3993: $r->print("\n\n".
1.372 bisitz 3994: '<script type="text/javascript">'."\n".
3995: '// <![CDATA['."\n".
3996: 'function reinit(tf) { tf.submit();'.$postexec.' }'."\n".
3997: '// ]]>'."\n".
1.369 bisitz 3998: '</script>'."\n".
1.375 tempelho 3999: '<form name="reinitform" method="post" action="/adm/roles" target="loncapaclient">'.
1.329 droeschl 4000: '<input type="hidden" name="orgurl" value="'.$url.
1.372 bisitz 4001: '" /><input type="hidden" name="selectrole" value="1" /><p class="LC_warning">'.
1.329 droeschl 4002: &mt($message,' <input type="hidden" name="'.
4003: $env{'request.role'}.'" value="1" /><input type="button" value="'.
1.369 bisitz 4004: &mt('re-initializing '.$course_type).'" onclick="reinit(this.form)" />').
1.372 bisitz 4005: $help{'Caching'}.'</p></form>'."\n\n");
1.329 droeschl 4006: }
4007:
4008:
4009: sub init_breadcrumbs {
4010: my ($form,$text)=@_;
4011: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.484 raeburn 4012: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1",
1.405 bisitz 4013: text=>&Apache::loncommon::course_type().' Editor',
1.329 droeschl 4014: faq=>273,
4015: bug=>'Instructor Interface',
4016: help => 'Docs_Adding_Course_Doc'});
4017: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?".$form.'=1',
4018: text=>$text,
4019: faq=>273,
4020: bug=>'Instructor Interface'});
4021: }
4022:
1.441 www 4023: # subroutine to list form elements
4024: sub create_list_elements {
4025: my @formarr = @_;
4026: my $list = '';
1.484.2.12 raeburn 4027: foreach my $button (@formarr){
4028: foreach my $picture (keys(%{$button})) {
4029: $list .= &Apache::lonhtmlcommon::htmltag('li', $picture.' '.$button->{$picture}, {class => 'LC_menubuttons_inline_text', id => ''});
1.441 www 4030: }
4031: }
4032: return $list;
4033: }
1.329 droeschl 4034:
1.441 www 4035: # subroutine to create ul from list elements
4036: sub create_form_ul {
4037: my $list = shift;
4038: my $ul = &Apache::lonhtmlcommon::htmltag('ul',$list, {class => 'LC_ListStyleNormal'});
4039: return $ul;
4040: }
1.329 droeschl 4041:
1.442 www 4042: #
4043: # Start tabs
4044: #
4045:
4046: sub startContentScreen {
1.484 raeburn 4047: my ($mode) = @_;
4048: my $output = '<ul class="LC_TabContentBigger" id="mainnav">';
1.472 raeburn 4049: if (($mode eq 'navmaps') || ($mode eq 'supplemental')) {
1.484 raeburn 4050: $output .= '<li'.(($mode eq 'navmaps')?' class="active"':'').'><a href="/adm/navmaps"><b> '.&mt('Content Overview').' </b></a></li>'."\n";
4051: $output .= '<li'.(($mode eq 'coursesearch')?' class="active"':'').'><a href="/adm/searchcourse"><b> '.&mt('Content Search').' </b></a></li>'."\n";
4052: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/supplemental"><b>'.&mt('Supplemental Content').'</b></a></li>';
4053: } else {
1.484.2.34 raeburn 4054: $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 4055: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/coursedocs?forcesupplement=1"><b>'.&mt('Supplemental Content Editor').'</b></a></li>'."\n";
4056: $output .= '<li '.(($mode eq 'tools')?' class="active"':'').'><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>'."\n";
4057: '><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>';
4058: }
4059: $output .= "\n".'</ul>'."\n";
4060: $output .= '<div class="LC_DocsBox" style="clear:both;margin:0;" id="contenteditor">'.
4061: '<div id="maincoursedoc" style="margin:0 0;padding:0 0;">'.
4062: '<div class="LC_ContentBox" id="mainCourseDocuments" style="display: block;">';
4063: return $output;
1.442 www 4064: }
4065:
4066: #
4067: # End tabs
4068: #
4069:
4070: sub endContentScreen {
1.484 raeburn 4071: return '</div></div></div>';
1.442 www 4072: }
1.329 droeschl 4073:
1.446 www 4074: sub supplemental_base {
1.484.2.33 raeburn 4075: return 'supplemental&'.&escape(&mt('Supplemental Content'));
1.446 www 4076: }
4077:
1.329 droeschl 4078: sub handler {
4079: my $r = shift;
4080: &Apache::loncommon::content_type($r,'text/html');
4081: $r->send_http_header;
4082: return OK if $r->header_only;
1.484 raeburn 4083:
4084: # get course data
1.408 raeburn 4085: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 4086: my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
4087: my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
4088:
4089: # graphics settings
4090: $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL').'/');
1.329 droeschl 4091:
1.443 www 4092: #
1.329 droeschl 4093: # --------------------------------------------- Initialize help topics for this
4094: foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',
4095: 'Adding_External_Resource','Navigate_Content',
4096: 'Adding_Folders','Docs_Overview', 'Load_Map',
4097: 'Supplemental','Score_Upload_Form','Adding_Pages',
1.484.2.19 raeburn 4098: 'Importing_LON-CAPA_Resource','Importing_IMS_Course',
1.484.2.12 raeburn 4099: 'Uploading_From_Harddrive',
1.484.2.36! raeburn 4100: 'Check_Resource_Versions','Verify_Content',
! 4101: 'Course_Roster','Web_Page','Dropbox') {
1.329 droeschl 4102: $help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
4103: }
4104: # Composite help files
4105: $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
4106: 'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
4107: $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
4108: 'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
4109: $help{'Simple Problem'} = &Apache::loncommon::help_open_topic(
4110: 'Option_Response_Simple');
4111: $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
4112: 'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
1.347 weissno 4113: $help{'My Personal Information Page'} = &Apache::loncommon::help_open_topic(
1.329 droeschl 4114: 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
1.353 weissno 4115: $help{'Group Portfolio'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
1.329 droeschl 4116: $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
1.484.2.30 raeburn 4117:
1.472 raeburn 4118: my $allowed;
4119: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
4120: unless ($r->uri eq '/adm/supplemental') {
4121: # does this user have privileges to modify content.
4122: $allowed = &Apache::lonnet::allowed('mdc',$env{'request.course.id'});
4123: }
4124:
1.484 raeburn 4125: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['chooseserver',
4126: 'inhibitmenu']);
4127: if ($allowed && $env{'form.chooseserver'}) {
4128: &choose_dump_server($r);
4129: return OK;
4130: } elsif ($allowed && $env{'form.verify'}) {
1.329 droeschl 4131: &init_breadcrumbs('verify','Verify Content');
4132: &verifycontent($r);
4133: } elsif ($allowed && $env{'form.listsymbs'}) {
1.484 raeburn 4134: &init_breadcrumbs('listsymbs','List Content IDs');
1.329 droeschl 4135: &list_symbs($r);
4136: } elsif ($allowed && $env{'form.docslog'}) {
4137: &init_breadcrumbs('docslog','Show Log');
1.484 raeburn 4138: my $folder = $env{'form.folder'};
4139: if ($folder eq '') {
4140: $folder='default';
4141: }
4142: &docs_change_log($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath);
1.329 droeschl 4143: } elsif ($allowed && $env{'form.versions'}) {
4144: &init_breadcrumbs('versions','Check/Set Resource Versions');
4145: &checkversions($r);
4146: } elsif ($allowed && $env{'form.dumpcourse'}) {
1.484 raeburn 4147: &init_breadcrumbs('dumpcourse','Dump '.&Apache::loncommon::course_type().' Content to Authoring Space');
1.329 droeschl 4148: &dumpcourse($r);
4149: } elsif ($allowed && $env{'form.exportcourse'}) {
1.377 bisitz 4150: &init_breadcrumbs('exportcourse','IMS Export');
1.475 raeburn 4151: &Apache::imsexport::exportcourse($r);
1.329 droeschl 4152: } else {
1.445 www 4153: #
4154: # Done catching special calls
1.484 raeburn 4155: # The whole rest is for course and supplemental documents and utilities menu
1.445 www 4156: # Get the parameters that may be needed
4157: #
4158: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.484.2.19 raeburn 4159: ['folderpath',
4160: 'forcesupplement','forcestandard',
4161: 'tools','symb','command','supppath']);
1.445 www 4162:
4163: # standard=1: this is a "new-style" course with an uploaded map as top level
4164: # standard=2: this is a "old-style" course, and there is nothing we can do
1.329 droeschl 4165:
4166: my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
1.445 www 4167:
1.484 raeburn 4168: # Decide whether this should display supplemental or main content or utilities
1.445 www 4169: # supplementalflag=1: show supplemental documents
4170: # supplementalflag=0: show standard documents
1.484 raeburn 4171: # toolsflag=1: show utilities
1.445 www 4172:
1.484.2.30 raeburn 4173: $env{'form.folderpath'} = &unescape($env{'form.folderpath'});
1.445 www 4174: my $supplementalflag=($env{'form.folderpath'}=~/^supplemental/);
1.484.2.19 raeburn 4175: if (($env{'form.folderpath'}=~/^default/) || ($env{'form.folderpath'} eq "")) {
1.445 www 4176: $supplementalflag=0;
4177: }
4178: if ($env{'form.forcesupplement'}) { $supplementalflag=1; }
4179: if ($env{'form.forcestandard'}) { $supplementalflag=0; }
4180: unless ($allowed) { $supplementalflag=1; }
4181: unless ($standard) { $supplementalflag=1; }
1.484 raeburn 4182: my $toolsflag=0;
4183: if ($env{'form.tools'}) { $toolsflag=1; }
1.445 www 4184:
1.329 droeschl 4185: my $script='';
4186: my $showdoc=0;
1.457 raeburn 4187: my $addentries = {};
1.475 raeburn 4188: my $container;
1.329 droeschl 4189: my $containertag;
1.484.2.17 raeburn 4190: my $pathitem;
1.329 droeschl 4191:
1.464 www 4192: # Do we directly jump somewhere?
1.466 www 4193:
1.484.2.21 raeburn 4194: if (($env{'form.command'} eq 'direct') || ($env{'form.command'} eq 'directnav')) {
1.472 raeburn 4195: if ($env{'form.symb'} ne '') {
1.484.2.19 raeburn 4196: $env{'form.folderpath'}=
4197: &Apache::loncommon::symb_to_docspath($env{'form.symb'});
1.484.2.21 raeburn 4198: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
4199: $env{'form.command'}.'_'.$env{'form.symb'}});
1.472 raeburn 4200: } elsif ($env{'form.supppath'} ne '') {
4201: $env{'form.folderpath'}=$env{'form.supppath'};
1.484.2.21 raeburn 4202: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
4203: $env{'form.command'}.'_'.$env{'form.supppath'}});
1.466 www 4204: }
1.472 raeburn 4205: } elsif ($env{'form.command'} eq 'editdocs') {
1.484.2.21 raeburn 4206: $env{'form.folderpath'} = 'default&'.
1.484.2.33 raeburn 4207: &escape(&mt('Main Content').':::::');
1.484.2.21 raeburn 4208: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => $env{'form.command'}});
1.472 raeburn 4209: } elsif ($env{'form.command'} eq 'editsupp') {
1.484.2.21 raeburn 4210: $env{'form.folderpath'} = 'supplemental&'.
1.484.2.30 raeburn 4211: &escape('Supplemental Content');
1.484.2.21 raeburn 4212: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/supplemental'});
4213: } elsif ($env{'form.command'} eq 'contents') {
4214: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/navmaps'});
4215: } elsif ($env{'form.command'} eq 'home') {
4216: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/menu'});
1.464 www 4217: }
4218:
1.484.2.23 raeburn 4219:
1.445 www 4220: # Where do we store these for when we come back?
4221: my $stored_folderpath='docs_folderpath';
4222: if ($supplementalflag) {
4223: $stored_folderpath='docs_sup_folderpath';
4224: }
1.464 www 4225:
1.484.2.19 raeburn 4226: # No folderpath, and in edit mode, see if we have something stored
4227: if ((!$env{'form.folderpath'}) && $allowed) {
1.445 www 4228: &Apache::loncommon::restore_course_settings($stored_folderpath,
1.484.2.19 raeburn 4229: {'folderpath' => 'scalar'});
4230: unless (&unescape($env{'form.folderpath'}) =~ m{^(default|supplemental)&}) {
4231: undef($env{'form.folderpath'});
4232: }
1.329 droeschl 4233: }
1.446 www 4234:
4235: # If we are not allowed to make changes, all we can see are supplemental docs
1.409 raeburn 4236: if (!$allowed) {
1.446 www 4237: unless ($env{'form.folderpath'} =~ /^supplemental/) {
4238: $env{'form.folderpath'} = &supplemental_base();
1.409 raeburn 4239: }
4240: }
1.446 www 4241: # Make the zeroth entry in supplemental docs page paths, so we can get to top level
1.329 droeschl 4242: if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
1.446 www 4243: $env{'form.folderpath'} = &supplemental_base()
4244: .'&'.
1.329 droeschl 4245: $env{'form.folderpath'};
4246: }
1.446 www 4247: # If after all of this, we still don't have any paths, make them
1.484.2.19 raeburn 4248: unless ($env{'form.folderpath'}) {
1.446 www 4249: if ($supplementalflag) {
4250: $env{'form.folderpath'}=&supplemental_base();
4251: } else {
1.484.2.33 raeburn 4252: $env{'form.folderpath'}='default&'.&escape(&mt('Main Content').
1.484.2.30 raeburn 4253: ':::::');
1.446 www 4254: }
1.472 raeburn 4255: }
1.446 www 4256:
1.445 www 4257: # Store this
1.484 raeburn 4258: unless ($toolsflag) {
1.484.2.19 raeburn 4259: if ($allowed) {
4260: &Apache::loncommon::store_course_settings($stored_folderpath,
4261: {'folderpath' => 'scalar'});
4262: }
4263: my $folderpath;
1.484 raeburn 4264: if ($env{'form.folderpath'}) {
1.484.2.19 raeburn 4265: $folderpath = $env{'form.folderpath'};
4266: my (@folders)=split('&',$env{'form.folderpath'});
4267: $env{'form.foldername'}=&unescape(pop(@folders));
4268: if ($env{'form.foldername'} =~ /\:1$/) {
4269: $container = 'page';
4270: } else {
4271: $container = 'sequence';
4272: }
4273: $env{'form.folder'}=pop(@folders);
1.484 raeburn 4274: } else {
1.484.2.19 raeburn 4275: if ($env{'form.folder'} eq '' ||
4276: $env{'form.folder'} eq 'supplemental') {
4277: $folderpath='default&'.
1.484.2.33 raeburn 4278: &escape(&mt('Main Content').':::::');
1.484 raeburn 4279: }
4280: }
1.484.2.19 raeburn 4281: $containertag = '<input type="hidden" name="folderpath" value="" />';
4282: $pathitem = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 4283: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
4284: $showdoc='/'.$1;
4285: }
4286: if ($showdoc) { # got called in sequence from course
4287: $allowed=0;
4288: } else {
4289: if ($allowed) {
4290: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
4291: $script=&Apache::lonratedt::editscript('simple');
1.433 raeburn 4292: }
4293: }
1.329 droeschl 4294: }
4295:
1.344 bisitz 4296: # get personal data
1.329 droeschl 4297: my $uname=$env{'user.name'};
4298: my $udom=$env{'user.domain'};
4299: my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));
4300:
4301: if ($allowed) {
1.484 raeburn 4302: if ($toolsflag) {
4303: $script .= &inject_data_js();
4304: my ($home,$other,%outhash)=&authorhosts();
4305: if (!$home && $other) {
4306: my @hosts;
4307: foreach my $aurole (keys(%outhash)) {
4308: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
4309: push(@hosts,$outhash{$aurole});
4310: }
4311: }
4312: $script .= &dump_switchserver_js(@hosts);
4313: }
1.458 raeburn 4314: } else {
1.484 raeburn 4315: my @tabids;
4316: if ($supplementalflag) {
4317: @tabids = ('002','ee2','ff2');
4318: } else {
4319: @tabids = ('aa1','bb1','cc1','ff1');
1.484.2.19 raeburn 4320: unless ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 4321: unshift(@tabids,'001');
4322: push(@tabids,('dd1','ee1'));
4323: }
1.458 raeburn 4324: }
1.484 raeburn 4325: my $tabidstr = join("','",@tabids);
4326: $script .= &editing_js($udom,$uname,$supplementalflag).
4327: &history_tab_js().
4328: &inject_data_js().
1.484.2.19 raeburn 4329: &Apache::lonhtmlcommon::resize_scrollbox_js('docs',$tabidstr).
4330: &Apache::lonextresedit::extedit_javascript();
1.484 raeburn 4331: $addentries = {
1.484.2.3 raeburn 4332: onload => "javascript:resize_scrollbox('contentscroll','1','1');",
1.484 raeburn 4333: };
1.458 raeburn 4334: }
1.484.2.30 raeburn 4335: $script .= &paste_popup_js();
1.484.2.12 raeburn 4336: my $confirm_switch = &mt("Editing requires switching to the resource's home server.").'\n'.
4337: &mt('Switch server?');
1.484.2.19 raeburn 4338:
4339:
1.329 droeschl 4340: }
4341: # -------------------------------------------------------------------- Body tag
1.369 bisitz 4342: $script = '<script type="text/javascript">'."\n"
1.372 bisitz 4343: .'// <![CDATA['."\n"
4344: .$script."\n"
4345: .'// ]]>'."\n"
4346: .'</script>'."\n";
1.385 bisitz 4347:
4348: # Breadcrumbs
4349: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.484.2.19 raeburn 4350:
4351: if ($showdoc) {
4352: $r->print(&Apache::loncommon::start_page("$crstype documents",undef,
4353: {'force_register' => $showdoc,}));
4354: } elsif ($r->uri eq '/adm/supplemental') {
4355: my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype);
4356: $r->print(&Apache::loncommon::start_page("Supplemental $crstype Content",undef,
4357: {'bread_crumbs' => $brcrum,}));
4358: } else {
1.392 raeburn 4359: &Apache::lonhtmlcommon::add_breadcrumb({
1.446 www 4360: href=>"/adm/coursedocs",text=>"$crstype Contents"});
4361: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script,
1.484.2.19 raeburn 4362: {'add_entries' => $addentries}
4363: )
1.392 raeburn 4364: .&Apache::loncommon::help_open_menu('','',273,'RAT')
4365: .&Apache::lonhtmlcommon::breadcrumbs(
1.484 raeburn 4366: 'Editing '.$crstype.' Contents',
1.392 raeburn 4367: 'Docs_Adding_Course_Doc')
4368: );
4369: }
1.364 bisitz 4370:
1.329 droeschl 4371: my %allfiles = ();
4372: my %codebase = ();
1.440 raeburn 4373: my ($upload_result,$upload_output,$uploadphase);
1.329 droeschl 4374: if ($allowed) {
4375: if (($env{'form.uploaddoc.filename'}) &&
4376: ($env{'form.cmd'}=~/^upload_(\w+)/)) {
1.440 raeburn 4377: my $context = $1;
4378: # Process file upload - phase one - upload and parse primary file.
1.329 droeschl 4379: undef($hadchanges);
1.440 raeburn 4380: $uploadphase = &process_file_upload(\$upload_output,$coursenum,$coursedom,
1.484.2.36! raeburn 4381: \%allfiles,\%codebase,$context,$crstype);
1.329 droeschl 4382: if ($hadchanges) {
4383: &mark_hash_old();
4384: }
1.440 raeburn 4385: $r->print($upload_output);
4386: } elsif ($env{'form.phase'} eq 'upload_embedded') {
4387: # Process file upload - phase two - upload embedded objects
4388: $uploadphase = 'check_embedded';
4389: my $primaryurl = &HTML::Entities::encode($env{'form.primaryurl'},'<>&"');
4390: my $state = &embedded_form_elems($uploadphase,$primaryurl,
4391: $env{'form.newidx'});
4392: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
4393: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
4394: my ($destination,$dir_root) = &embedded_destination();
4395: my $url_root = '/uploaded/'.$docudom.'/'.$docuname;
4396: my $actionurl = '/adm/coursedocs';
4397: my ($result,$flag) =
4398: &Apache::loncommon::upload_embedded('coursedoc',$destination,
4399: $docuname,$docudom,$dir_root,$url_root,undef,undef,undef,$state,
4400: $actionurl);
4401: $r->print($result.&return_to_editor());
4402: } elsif ($env{'form.phase'} eq 'check_embedded') {
4403: # Process file upload - phase three - modify references in HTML file
4404: $uploadphase = 'modified_orightml';
4405: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
4406: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
4407: my ($destination,$dir_root) = &embedded_destination();
1.482 raeburn 4408: my $result =
4409: &Apache::loncommon::modify_html_refs('coursedoc',$destination,
4410: $docuname,$docudom,undef,
4411: $dir_root);
4412: $r->print($result.&return_to_editor());
1.476 raeburn 4413: } elsif ($env{'form.phase'} eq 'decompress_uploaded') {
4414: $uploadphase = 'decompress_phase_one';
4415: $r->print(&decompression_phase_one().
4416: &return_to_editor());
4417: } elsif ($env{'form.phase'} eq 'decompress_cleanup') {
4418: $uploadphase = 'decompress_phase_two';
4419: $r->print(&decompression_phase_two().
4420: &return_to_editor());
1.329 droeschl 4421: }
4422: }
4423:
1.484 raeburn 4424: if ($allowed && $toolsflag) {
4425: $r->print(&startContentScreen('tools'));
4426: $r->print(&generate_admin_menu($crstype));
4427: $r->print(&endContentScreen());
4428: } elsif ((!$showdoc) && (!$uploadphase)) {
1.329 droeschl 4429: # -----------------------------------------------------------------------------
4430: my %lt=&Apache::lonlocal::texthash(
4431: 'copm' => 'All documents out of a published map into this folder',
1.484.2.12 raeburn 4432: 'upfi' => 'Upload File',
1.484.2.36! raeburn 4433: 'upld' => 'Upload Content',
1.329 droeschl 4434: 'srch' => 'Search',
4435: 'impo' => 'Import',
1.484.2.19 raeburn 4436: 'lnks' => 'Import from Stored Links',
1.484.2.13 raeburn 4437: 'impm' => 'Import from Assembled Map',
1.329 droeschl 4438: 'selm' => 'Select Map',
4439: 'load' => 'Load Map',
4440: 'newf' => 'New Folder',
4441: 'newp' => 'New Composite Page',
4442: 'syll' => 'Syllabus',
1.425 raeburn 4443: 'navc' => 'Table of Contents',
1.343 biermanm 4444: 'sipa' => 'Simple Course Page',
1.329 droeschl 4445: 'sipr' => 'Simple Problem',
1.484.2.27 raeburn 4446: 'webp' => 'Blank Web Page (editable)',
1.329 droeschl 4447: 'drbx' => 'Drop Box',
1.451 www 4448: 'scuf' => 'External Scores (handgrade, upload, clicker)',
1.336 schafran 4449: 'bull' => 'Discussion Board',
1.347 weissno 4450: 'mypi' => 'My Personal Information Page',
1.353 weissno 4451: 'grpo' => 'Group Portfolio',
1.329 droeschl 4452: 'rost' => 'Course Roster',
1.484.2.22 raeburn 4453: 'abou' => 'Personal Information Page for a User',
1.484.2.36! raeburn 4454: 'imsf' => 'IMS Upload',
! 4455: 'imsl' => 'Upload IMS package',
1.484.2.12 raeburn 4456: 'cms' => 'Origin of IMS package',
4457: 'se' => 'Select',
1.484.2.19 raeburn 4458: 'file' => 'File',
1.329 droeschl 4459: 'title' => 'Title',
4460: 'comment' => 'Comment',
1.403 raeburn 4461: 'parse' => 'Upload embedded images/multimedia files if HTML file',
1.329 droeschl 4462: );
4463: # -----------------------------------------------------------------------------
4464: my $fileupload=(<<FIUP);
4465: $lt{'file'}:<br />
4466: <input type="file" name="uploaddoc" size="40" />
4467: FIUP
4468:
4469: my $checkbox=(<<CHBO);
4470: <!-- <label>$lt{'parse'}?
4471: <input type="checkbox" name="parserflag" />
4472: </label> -->
4473: <label>
4474: <input type="checkbox" name="parserflag" checked="checked" /> $lt{'parse'}
4475: </label>
4476: CHBO
1.484.2.12 raeburn 4477: my $imsfolder = $env{'form.folder'};
4478: if ($imsfolder eq '') {
1.484.2.19 raeburn 4479: $imsfolder = 'default';
1.484.2.12 raeburn 4480: }
4481: my $imspform=(<<IMSFORM);
4482: <a class="LC_menubuttons_link" href="javascript:toggleUpload('ims');">
4483: $lt{'imsf'}</a> $help{'Importing_IMS_Course'}
4484: <form name="uploadims" action="/adm/imsimportdocs" method="post" enctype="multipart/form-data" target="IMSimport">
1.484.2.19 raeburn 4485: <fieldset id="uploadimsform" style="display: none;">
1.484.2.12 raeburn 4486: <legend>$lt{'imsf'}</legend>
4487: $fileupload
4488: <br />
4489: <p>
1.484.2.19 raeburn 4490: $lt{'cms'}:
1.484.2.12 raeburn 4491: <select name="source">
4492: <option value="-1" selected="selected">$lt{'se'}</option>
4493: <option value="bb5">Blackboard 5</option>
4494: <option value="bb6">Blackboard 6</option>
4495: <option value="angel5">ANGEL 5.5</option>
4496: <option value="webctce4">WebCT 4 Campus Edition</option>
4497: </select>
4498: <input type="hidden" name="folder" value="$imsfolder" />
4499: </p>
4500: <input type="hidden" name="phase" value="one" />
4501: <input type="button" value="$lt{'imsl'}" onclick="makeims(this.form);" />
4502: </fieldset>
4503: </form>
4504: IMSFORM
4505:
1.484.2.19 raeburn 4506: my $fileuploadform=(<<FUFORM);
1.484.2.12 raeburn 4507: <a class="LC_menubuttons_link" href="javascript:toggleUpload('doc');">
4508: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
4509: <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.484.2.19 raeburn 4510: <fieldset id="uploaddocform" style="display: none;">
1.484.2.12 raeburn 4511: <legend>$lt{'upfi'}</legend>
1.371 tempelho 4512: <input type="hidden" name="active" value="aa" />
1.329 droeschl 4513: $fileupload
4514: <br />
4515: $lt{'title'}:<br />
1.458 raeburn 4516: <input type="text" size="60" name="comment" />
1.484.2.17 raeburn 4517: $pathitem
1.329 droeschl 4518: <input type="hidden" name="cmd" value="upload_default" />
4519: <br />
1.458 raeburn 4520: <span class="LC_nobreak" style="float:left">
1.329 droeschl 4521: $checkbox
4522: </span>
1.484.2.12 raeburn 4523: <br clear="all" />
4524: <input type="submit" value="$lt{'upld'}" />
4525: </fieldset>
4526: </form>
1.383 tempelho 4527: FUFORM
1.329 droeschl 4528:
1.484.2.19 raeburn 4529: my $importpubform=(<<SEDFFORM);
4530: <a class="LC_menubuttons_link" href="javascript:toggleMap('map');">
1.484.2.13 raeburn 4531: $lt{'impm'}</a>$help{'Load_Map'}
1.484.2.19 raeburn 4532: <form action="/adm/coursedocs" method="post" name="mapimportform">
4533: <fieldset id="importmapform" style="display: none;">
1.484.2.13 raeburn 4534: <legend>$lt{'impm'}</legend>
1.484.2.19 raeburn 4535: <input type="hidden" name="active" value="bb" />
1.484.2.13 raeburn 4536: $lt{'copm'}<br />
4537: <span class="LC_nobreak">
1.484.2.19 raeburn 4538: <input type="text" name="importmap" size="40" value=""
1.484.2.13 raeburn 4539: onfocus="this.blur();openbrowser('mapimportform','importmap','sequence,page','');" />
1.484.2.19 raeburn 4540: <a href="javascript:openbrowser('mapimportform','importmap','sequence,page','');">$lt{'selm'}</a></span><br />
1.484.2.13 raeburn 4541: <input type="submit" name="loadmap" value="$lt{'load'}" />
4542: </fieldset>
4543: </form>
4544:
1.383 tempelho 4545: SEDFFORM
1.484.2.19 raeburn 4546: my @importpubforma = (
4547: { '<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 4548: { '<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 4549: { '<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>" },
4550: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/sequence.png" alt="'.$lt{impm}.'" onclick="javascript:toggleMap(\'map\');" />' => $importpubform }
4551: );
4552: $importpubform = &create_form_ul(&create_list_elements(@importpubforma));
4553: my $extresourcesform =
4554: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
4555: $help{'Adding_External_Resource'});
1.329 droeschl 4556: if ($allowed) {
1.484.2.7 raeburn 4557: my $folder = $env{'form.folder'};
4558: if ($folder eq '') {
4559: $folder='default';
4560: }
1.484.2.30 raeburn 4561: my $output = &update_paste_buffer($coursenum,$coursedom,$folder);
4562: if ($output) {
4563: $r->print($output);
4564: }
1.337 ehlerst 4565: $r->print(<<HIDDENFORM);
4566: <form name="renameform" method="post" action="/adm/coursedocs">
4567: <input type="hidden" name="title" />
4568: <input type="hidden" name="cmd" />
4569: <input type="hidden" name="markcopy" />
4570: <input type="hidden" name="copyfolder" />
4571: $containertag
4572: </form>
1.484 raeburn 4573:
1.337 ehlerst 4574: HIDDENFORM
1.484.2.17 raeburn 4575: $r->print(&makesimpleeditform($pathitem)."\n".
4576: &makedocslogform($pathitem."\n".
1.484 raeburn 4577: '<input type="hidden" name="folder" value="'.
4578: $env{'form.folder'}.'" />'."\n"));
1.329 droeschl 4579: }
1.442 www 4580:
4581: # Generate the tabs
1.484.2.19 raeburn 4582: my ($mode,$needs_end);
1.472 raeburn 4583: if (($supplementalflag) && (!$allowed)) {
1.484.2.19 raeburn 4584: my @folders = split('&',$env{'form.folderpath'});
4585: unless (@folders > 2) {
4586: &Apache::lonnavdisplay::startContentScreen($r,'supplemental');
4587: $needs_end = 1;
4588: }
1.472 raeburn 4589: } else {
1.484 raeburn 4590: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.484.2.19 raeburn 4591: $needs_end = 1;
1.472 raeburn 4592: }
1.443 www 4593:
1.442 www 4594: #
4595:
4596: my $savefolderpath;
4597:
1.395 raeburn 4598: if ($allowed) {
1.329 droeschl 4599: my $folder=$env{'form.folder'};
1.443 www 4600: if ($folder eq '' || $supplementalflag) {
1.329 droeschl 4601: $folder='default';
1.356 tempelho 4602: $savefolderpath = $env{'form.folderpath'};
1.484.2.33 raeburn 4603: $env{'form.folderpath'}='default&'.&escape(&mt('Main Content'));
1.484.2.17 raeburn 4604: $pathitem = '<input type="hidden" name="folderpath" value="'.
1.329 droeschl 4605: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
4606: }
4607: my $postexec='';
4608: if ($folder eq 'default') {
1.372 bisitz 4609: $r->print('<script type="text/javascript">'."\n"
4610: .'// <![CDATA['."\n"
4611: .'this.window.name="loncapaclient";'."\n"
4612: .'// ]]>'."\n"
4613: .'</script>'."\n"
1.369 bisitz 4614: );
1.329 droeschl 4615: } else {
4616: #$postexec='self.close();';
4617: }
1.484.2.15 raeburn 4618: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.sequence';
4619: my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.page';
1.329 droeschl 4620: my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
4621:
4622: my $newnavform=(<<NNFORM);
4623: <form action="/adm/coursedocs" method="post" name="newnav">
1.371 tempelho 4624: <input type="hidden" name="active" value="cc" />
1.484.2.17 raeburn 4625: $pathitem
1.329 droeschl 4626: <input type="hidden" name="importdetail"
4627: value="$lt{'navc'}=/adm/navmaps" />
1.423 onken 4628: <a class="LC_menubuttons_link" href="javascript:document.newnav.submit()">$lt{'navc'}</a>
1.329 droeschl 4629: $help{'Navigate_Content'}
4630: </form>
4631: NNFORM
4632: my $newsmppageform=(<<NSPFORM);
4633: <form action="/adm/coursedocs" method="post" name="newsmppg">
1.371 tempelho 4634: <input type="hidden" name="active" value="cc" />
1.484.2.17 raeburn 4635: $pathitem
1.329 droeschl 4636: <input type="hidden" name="importdetail" value="" />
1.423 onken 4637: <a class="LC_menubuttons_link" href="javascript:makesmppage();"> $lt{'sipa'}</a>
1.383 tempelho 4638: $help{'Simple Page'}
1.329 droeschl 4639: </form>
4640: NSPFORM
4641:
4642: my $newsmpproblemform=(<<NSPROBFORM);
4643: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
1.371 tempelho 4644: <input type="hidden" name="active" value="cc" />
1.484.2.17 raeburn 4645: $pathitem
1.329 droeschl 4646: <input type="hidden" name="importdetail" value="" />
1.423 onken 4647: <a class="LC_menubuttons_link" href="javascript:makesmpproblem();">$lt{'sipr'}</a>
1.383 tempelho 4648: $help{'Simple Problem'}
1.329 droeschl 4649: </form>
4650:
4651: NSPROBFORM
4652:
4653: my $newdropboxform=(<<NDBFORM);
4654: <form action="/adm/coursedocs" method="post" name="newdropbox">
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:makedropbox();">$lt{'drbx'}</a>
1.484.2.36! raeburn 4659: $help{'Dropbox'}
1.344 bisitz 4660: </form>
1.329 droeschl 4661: NDBFORM
4662:
4663: my $newexuploadform=(<<NEXUFORM);
4664: <form action="/adm/coursedocs" method="post" name="newexamupload">
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" value="" />
1.423 onken 4668: <a class="LC_menubuttons_link" href="javascript:makeexamupload();">$lt{'scuf'}</a>
1.329 droeschl 4669: $help{'Score_Upload_Form'}
4670: </form>
4671: NEXUFORM
4672:
4673: my $newbulform=(<<NBFORM);
4674: <form action="/adm/coursedocs" method="post" name="newbul">
1.371 tempelho 4675: <input type="hidden" name="active" value="cc" />
1.484.2.17 raeburn 4676: $pathitem
1.329 droeschl 4677: <input type="hidden" name="importdetail" value="" />
1.423 onken 4678: <a class="LC_menubuttons_link" href="javascript:makebulboard();" >$lt{'bull'}</a>
1.329 droeschl 4679: $help{'Bulletin Board'}
4680: </form>
4681: NBFORM
4682:
4683: my $newaboutmeform=(<<NAMFORM);
4684: <form action="/adm/coursedocs" method="post" name="newaboutme">
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="$plainname=/adm/$udom/$uname/aboutme" />
1.423 onken 4689: <a class="LC_menubuttons_link" href="javascript:document.newaboutme.submit()">$lt{'mypi'}</a>
1.347 weissno 4690: $help{'My Personal Information Page'}
1.329 droeschl 4691: </form>
4692: NAMFORM
4693:
4694: my $newaboutsomeoneform=(<<NASOFORM);
4695: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
1.371 tempelho 4696: <input type="hidden" name="active" value="cc" />
1.484.2.17 raeburn 4697: $pathitem
1.329 droeschl 4698: <input type="hidden" name="importdetail" value="" />
1.423 onken 4699: <a class="LC_menubuttons_link" href="javascript:makeabout();">$lt{'abou'}</a>
1.329 droeschl 4700: </form>
4701: NASOFORM
4702:
4703: my $newrosterform=(<<NROSTFORM);
4704: <form action="/adm/coursedocs" method="post" name="newroster">
1.371 tempelho 4705: <input type="hidden" name="active" value="cc" />
1.484.2.17 raeburn 4706: $pathitem
1.329 droeschl 4707: <input type="hidden" name="importdetail"
4708: value="$lt{'rost'}=/adm/viewclasslist" />
1.423 onken 4709: <a class="LC_menubuttons_link" href="javascript:document.newroster.submit()">$lt{'rost'}</a>
1.329 droeschl 4710: $help{'Course Roster'}
4711: </form>
4712: NROSTFORM
4713:
1.484.2.27 raeburn 4714: my $newwebpage;
4715: if ($folder =~ /^default_?(\d*)$/) {
4716: $newwebpage = "/uploaded/$coursedom/$coursenum/docs/";
4717: if ($1) {
4718: $newwebpage .= $1;
4719: } else {
4720: $newwebpage .= 'default';
4721: }
4722: $newwebpage .= '/new.html';
4723: }
4724: my $newwebpageform =(<<NWEBFORM);
4725: <form action="/adm/coursedocs" method="post" name="newwebpage">
4726: <input type="hidden" name="active" value="cc" />
4727: $pathitem
4728: <input type="hidden" name="importdetail" value="$newwebpage" />
4729: <a class="LC_menubuttons_link" href="javascript:makewebpage();">$lt{'webp'}</a>
1.484.2.36! raeburn 4730: $help{'Web_Page'}
1.484.2.27 raeburn 4731: </form>
4732: NWEBFORM
1.484.2.30 raeburn 4733:
1.484.2.27 raeburn 4734:
1.342 ehlerst 4735: my $specialdocumentsform;
1.383 tempelho 4736: my @specialdocumentsforma;
1.451 www 4737: my $gradingform;
4738: my @gradingforma;
4739: my $communityform;
4740: my @communityforma;
1.351 ehlerst 4741: my $newfolderform;
1.390 tempelho 4742: my $newfolderb;
1.342 ehlerst 4743:
1.451 www 4744: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.383 tempelho 4745:
1.329 droeschl 4746: my $newpageform=(<<NPFORM);
4747: <form action="/adm/coursedocs" method="post" name="newpage">
4748: <input type="hidden" name="folderpath" value="$path" />
4749: <input type="hidden" name="importdetail" value="" />
1.371 tempelho 4750: <input type="hidden" name="active" value="cc" />
1.423 onken 4751: <a class="LC_menubuttons_link" href="javascript:makenewpage(document.newpage,'$pageseq');">$lt{'newp'}</a>
1.383 tempelho 4752: $help{'Adding_Pages'}
1.329 droeschl 4753: </form>
4754: NPFORM
1.390 tempelho 4755:
4756:
1.351 ehlerst 4757: $newfolderform=(<<NFFORM);
1.329 droeschl 4758: <form action="/adm/coursedocs" method="post" name="newfolder">
1.484.2.19 raeburn 4759: $pathitem
1.329 droeschl 4760: <input type="hidden" name="importdetail" value="" />
1.371 tempelho 4761: <input type="hidden" name="active" value="aa" />
1.422 onken 4762: <a href="javascript:makenewfolder(document.newfolder,'$folderseq');">$lt{'newf'}</a>$help{'Adding_Folders'}
1.329 droeschl 4763: </form>
4764: NFFORM
4765:
4766: my $newsylform=(<<NSYLFORM);
4767: <form action="/adm/coursedocs" method="post" name="newsyl">
1.371 tempelho 4768: <input type="hidden" name="active" value="cc" />
1.484.2.17 raeburn 4769: $pathitem
1.329 droeschl 4770: <input type="hidden" name="importdetail"
4771: value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />
1.423 onken 4772: <a class="LC_menubuttons_link" href="javascript:document.newsyl.submit()">$lt{'syll'}</a>
1.329 droeschl 4773: $help{'Syllabus'}
1.383 tempelho 4774:
1.329 droeschl 4775: </form>
4776: NSYLFORM
1.364 bisitz 4777:
1.329 droeschl 4778: my $newgroupfileform=(<<NGFFORM);
4779: <form action="/adm/coursedocs" method="post" name="newgroupfiles">
1.371 tempelho 4780: <input type="hidden" name="active" value="cc" />
1.484.2.17 raeburn 4781: $pathitem
1.329 droeschl 4782: <input type="hidden" name="importdetail"
4783: value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
1.423 onken 4784: <a class="LC_menubuttons_link" href="javascript:document.newgroupfiles.submit()">$lt{'grpo'}</a>
1.353 weissno 4785: $help{'Group Portfolio'}
1.329 droeschl 4786: </form>
4787: NGFFORM
1.383 tempelho 4788: @specialdocumentsforma=(
1.421 onken 4789: {'<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 4790: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="document.newsyl.submit()" />'=>$newsylform},
1.451 www 4791: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/navigation.png" alt="'.$lt{navc}.'" onclick="document.newnav.submit()" />'=>$newnavform},
4792: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simple.png" alt="'.$lt{sipa}.'" onclick="javascript:makesmppage();" />'=>$newsmppageform},
1.484.2.27 raeburn 4793: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
1.451 www 4794: );
4795: $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma));
4796:
1.434 raeburn 4797:
4798: my @importdoc = (
1.484.2.19 raeburn 4799: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="toggleUpload(\'ext\');" />'=>$extresourcesform}
4800: );
4801: unless ($container eq 'page') {
4802: push(@importdoc,
4803: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/ims.png" alt="'.$lt{imsf}.'" onclick="javascript:toggleUpload(\'ims\');" />'=>$imspform}
4804: );
4805: }
4806: push(@importdoc,
4807: {'<img class="LC_noBorder_LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'doc\');" />'=>$fileuploadform}
4808: );
1.484.2.12 raeburn 4809: $fileuploadform = &create_form_ul(&create_list_elements(@importdoc));
1.434 raeburn 4810:
1.451 www 4811: @gradingforma=(
4812: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{sipr}.'" onclick="javascript:makesmpproblem();" />'=>$newsmpproblemform},
4813: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/dropbox.png" alt="'.$lt{drbx}.'" onclick="javascript:makedropbox();" />'=>$newdropboxform},
4814: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/scoreupfrm.png" alt="'.$lt{scuf}.'" onclick="javascript:makeexamupload();" />'=>$newexuploadform},
4815:
4816: );
4817: $gradingform = &create_form_ul(&create_list_elements(@gradingforma));
4818:
4819: @communityforma=(
4820: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/bchat.png" alt="'.$lt{bull}.'" onclick="javascript:makebulboard();" />'=>$newbulform},
4821: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makebulboard();" />'=>$newaboutmeform},
4822: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/aboutme.png" alt="'.$lt{abou}.'" onclick="javascript:makeabout();" />'=>$newaboutsomeoneform},
4823: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/clst.png" alt="'.$lt{rost}.'" onclick="document.newroster.submit()" />'=>$newrosterform},
4824: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/groupportfolio.png" alt="'.$lt{grpo}.'" onclick="document.newgroupfiles.submit()" />'=>$newgroupfileform},
4825: );
4826: $communityform = &create_form_ul(&create_list_elements(@communityforma));
1.383 tempelho 4827:
1.330 tempelho 4828: my %orderhash = (
1.484.2.36! raeburn 4829: 'aa' => ['Upload',$fileuploadform],
! 4830: 'bb' => ['Import',$importpubform],
! 4831: 'cc' => ['Grading',$gradingform],
1.330 tempelho 4832: );
1.484.2.19 raeburn 4833: unless ($container eq 'page') {
1.434 raeburn 4834: $orderhash{'00'} = ['Newfolder',$newfolderform];
1.484 raeburn 4835: $orderhash{'dd'} = ['Collaboration',$communityform];
1.484.2.36! raeburn 4836: $orderhash{'ee'} = ['Other',$specialdocumentsform];
1.434 raeburn 4837: }
4838:
1.341 ehlerst 4839: $hadchanges=0;
1.484 raeburn 4840: unless (($supplementalflag || $toolsflag)) {
1.458 raeburn 4841: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.484.2.17 raeburn 4842: $supplementalflag,\%orderhash,$iconpath,$pathitem);
1.443 www 4843: if ($error) {
4844: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
4845: }
4846: if ($hadchanges) {
4847: &mark_hash_old();
4848: }
1.341 ehlerst 4849:
1.443 www 4850: &changewarning($r,'');
4851: }
1.458 raeburn 4852: }
1.442 www 4853:
1.443 www 4854: # Supplemental documents start here
4855:
1.329 droeschl 4856: my $folder=$env{'form.folder'};
1.443 www 4857: unless ($supplementalflag) {
1.329 droeschl 4858: $folder='supplemental';
4859: }
4860: if ($folder =~ /^supplemental$/ &&
4861: (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
1.446 www 4862: $env{'form.folderpath'} = &supplemental_base();
1.393 raeburn 4863: } elsif ($allowed) {
1.356 tempelho 4864: $env{'form.folderpath'} = $savefolderpath;
1.329 droeschl 4865: }
1.484.2.17 raeburn 4866: $pathitem = '<input type="hidden" name="folderpath" value="'.
4867: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
1.329 droeschl 4868: if ($allowed) {
4869: my $folderseq=
1.484.2.15 raeburn 4870: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_new.sequence';
1.329 droeschl 4871:
4872: my $supupdocform=(<<SUPDOCFORM);
1.484.2.12 raeburn 4873: <a class="LC_menubuttons_link" href="javascript:toggleUpload('suppdoc');">
4874: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
1.383 tempelho 4875: <form action="/adm/coursedocs" method="post" name="supuploaddocument" enctype="multipart/form-data">
1.484.2.19 raeburn 4876: <fieldset id="uploadsuppdocform" style="display: none;">
1.484.2.12 raeburn 4877: <legend>$lt{'upfi'}</legend>
1.371 tempelho 4878: <input type="hidden" name="active" value="ee" />
1.329 droeschl 4879: $fileupload
4880: <br />
4881: <br />
4882: <span class="LC_nobreak">
4883: $checkbox
4884: </span>
4885: <br /><br />
4886: $lt{'comment'}:<br />
1.383 tempelho 4887: <textarea cols="50" rows="4" name="comment"></textarea>
1.329 droeschl 4888: <br />
1.484.2.19 raeburn 4889: $pathitem
1.329 droeschl 4890: <input type="hidden" name="cmd" value="upload_supplemental" />
1.484.2.12 raeburn 4891: <input type='submit' value="$lt{'upld'}" />
4892: </form>
1.484.2.19 raeburn 4893: SUPDOCFORM
1.329 droeschl 4894:
4895: my $supnewfolderform=(<<SNFFORM);
4896: <form action="/adm/coursedocs" method="post" name="supnewfolder">
1.371 tempelho 4897: <input type="hidden" name="active" value="ee" />
1.484.2.17 raeburn 4898: $pathitem
1.329 droeschl 4899: <input type="hidden" name="importdetail" value="" />
1.423 onken 4900: <a class="LC_menubuttons_link" href="javascript:makenewfolder(document.supnewfolder,'$folderseq');">$lt{'newf'}</a>
1.383 tempelho 4901: $help{'Adding_Folders'}
1.329 droeschl 4902: </form>
4903: SNFFORM
1.383 tempelho 4904:
1.484.2.19 raeburn 4905: my $supextform =
4906: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
4907: $help{'Adding_External_Resource'});
1.329 droeschl 4908:
4909: my $supnewsylform=(<<SNSFORM);
4910: <form action="/adm/coursedocs" method="post" name="supnewsyl">
1.371 tempelho 4911: <input type="hidden" name="active" value="ff" />
1.484.2.19 raeburn 4912: $pathitem
1.329 droeschl 4913: <input type="hidden" name="importdetail"
4914: value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
1.423 onken 4915: <a class="LC_menubuttons_link" href="javascript:document.supnewsyl.submit()">$lt{'syll'}</a>
1.329 droeschl 4916: $help{'Syllabus'}
4917: </form>
4918: SNSFORM
4919:
4920: my $supnewaboutmeform=(<<SNAMFORM);
1.383 tempelho 4921: <form action="/adm/coursedocs" method="post" name="supnewaboutme">
1.371 tempelho 4922: <input type="hidden" name="active" value="ff" />
1.484.2.19 raeburn 4923: $pathitem
1.329 droeschl 4924: <input type="hidden" name="importdetail"
4925: value="$plainname=/adm/$udom/$uname/aboutme" />
1.423 onken 4926: <a class="LC_menubuttons_link" href="javascript:document.supnewaboutme.submit()">$lt{'mypi'}</a>
1.347 weissno 4927: $help{'My Personal Information Page'}
1.329 droeschl 4928: </form>
4929: SNAMFORM
4930:
1.484.2.27 raeburn 4931: my $supwebpage;
4932: if ($folder =~ /^supplemental_?(\d*)$/) {
4933: $supwebpage = "/uploaded/$coursedom/$coursenum/supplemental/";
4934: if ($1) {
4935: $supwebpage .= $1;
4936: } else {
4937: $supwebpage .= 'default';
4938: }
4939: $supwebpage .= '/new.html';
4940: }
4941: my $supwebpageform =(<<SWEBFORM);
4942: <form action="/adm/coursedocs" method="post" name="supwebpage">
4943: <input type="hidden" name="active" value="cc" />
4944: $pathitem
4945: <input type="hidden" name="importdetail" value="$supwebpage" />
4946: <a class="LC_menubuttons_link" href="javascript:makewebpage('supp');">$lt{'webp'}</a>
1.484.2.36! raeburn 4947: $help{'Web_Page'}
1.484.2.27 raeburn 4948: </form>
4949: SWEBFORM
4950:
1.333 muellerd 4951:
1.383 tempelho 4952: my @specialdocs = (
1.417 droeschl 4953: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="document.supnewsyl.submit()" />'
4954: =>$supnewsylform},
4955: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="document.supnewaboutme.submit()" />'
4956: =>$supnewaboutmeform},
1.484.2.27 raeburn 4957: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage('."'supp'".');" />'=>$supwebpageform},
4958:
1.383 tempelho 4959: );
1.417 droeschl 4960: my @supimportdoc = (
1.484.2.19 raeburn 4961: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="javascript:toggleUpload(\'suppext\')" />'
1.484.2.12 raeburn 4962: =>$supextform},
4963: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'suppdoc\');" />'
4964: =>$supupdocform},
1.484.2.19 raeburn 4965: );
4966:
1.484.2.12 raeburn 4967: $supupdocform = &create_form_ul(&create_list_elements(@supimportdoc));
1.333 muellerd 4968: my %suporderhash = (
1.390 tempelho 4969: '00' => ['Supnewfolder', $supnewfolderform],
1.484.2.36! raeburn 4970: 'ee' => ['Upload',$supupdocform],
! 4971: 'ff' => ['Other',&create_form_ul(&create_list_elements(@specialdocs))]
1.333 muellerd 4972: );
1.443 www 4973: if ($supplementalflag) {
1.458 raeburn 4974: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.484.2.17 raeburn 4975: $supplementalflag,\%suporderhash,$iconpath,$pathitem);
1.443 www 4976: if ($error) {
4977: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
4978: }
1.393 raeburn 4979: }
1.443 www 4980: } elsif ($supplementalflag) {
1.458 raeburn 4981: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.484.2.17 raeburn 4982: $supplementalflag,'',$iconpath,$pathitem);
1.393 raeburn 4983: if ($error) {
4984: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.383 tempelho 4985: }
1.393 raeburn 4986: }
1.389 tempelho 4987:
1.484.2.19 raeburn 4988: if ($needs_end) {
4989: $r->print(&endContentScreen());
4990: }
1.383 tempelho 4991:
1.329 droeschl 4992: if ($allowed) {
4993: $r->print('
4994: <form method="post" name="extimport" action="/adm/coursedocs">
4995: <input type="hidden" name="title" />
4996: <input type="hidden" name="url" />
4997: <input type="hidden" name="useform" />
4998: <input type="hidden" name="residx" />
4999: </form>');
5000: }
1.484 raeburn 5001: } elsif ($showdoc) {
1.329 droeschl 5002: # -------------------------------------------------------- This is showdoc mode
1.484 raeburn 5003: $r->print("<h1>".&mt('Uploaded Document').' - '.
1.484.2.10 raeburn 5004: &Apache::lonnet::gettitle($r->uri).'</h1><p class="LC_warning">'.
1.329 droeschl 5005: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><table>".
1.484 raeburn 5006: &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');
1.329 droeschl 5007: }
5008: }
5009: $r->print(&Apache::loncommon::end_page());
5010: return OK;
1.364 bisitz 5011: }
1.329 droeschl 5012:
1.440 raeburn 5013: sub embedded_form_elems {
5014: my ($phase,$primaryurl,$newidx) = @_;
5015: my $folderpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
5016: return <<STATE;
5017: <input type="hidden" name="folderpath" value="$folderpath" />
5018: <input type="hidden" name="cmd" value="upload_embedded" />
5019: <input type="hidden" name="newidx" value="$newidx" />
5020: <input type="hidden" name="phase" value="$phase" />
5021: <input type="hidden" name="primaryurl" value="$primaryurl" />
5022: STATE
5023: }
5024:
5025: sub embedded_destination {
5026: my $folder=$env{'form.folder'};
5027: my $destination = 'docs/';
5028: if ($folder =~ /^supplemental/) {
5029: $destination = 'supplemental/';
5030: }
5031: if (($folder eq 'default') || ($folder eq 'supplemental')) {
5032: $destination .= 'default/';
5033: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
5034: $destination .= $2.'/';
5035: }
5036: $destination .= $env{'form.newidx'};
5037: my $dir_root = '/userfiles';
5038: return ($destination,$dir_root);
5039: }
5040:
5041: sub return_to_editor {
5042: my $actionurl = '/adm/coursedocs';
5043: return '<p><form name="backtoeditor" method="post" action="'.$actionurl.'" />'."\n".
5044: '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" /></form>'."\n".
5045: '<a href="javascript:document.backtoeditor.submit();">'.&mt('Return to Editor').
5046: '</a></p>';
5047: }
5048:
1.476 raeburn 5049: sub decompression_info {
5050: my ($destination,$dir_root) = &embedded_destination();
5051: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
5052: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5053: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5054: my $container='sequence';
1.480 raeburn 5055: my ($pathitem,$hiddenelem);
1.484.2.19 raeburn 5056: my @hiddens = ('newidx','comment','position','folderpath');
5057: if ($env{'form.folderpath'} =~ /\:1$/) {
1.476 raeburn 5058: $container='page';
5059: }
1.480 raeburn 5060: unshift(@hiddens,$pathitem);
5061: foreach my $item (@hiddens) {
5062: if ($env{'form.'.$item}) {
5063: $hiddenelem .= '<input type="hidden" name="'.$item.'" value="'.
5064: $env{'form.'.$item}.'" />'."\n";
5065: }
1.477 raeburn 5066: }
1.476 raeburn 5067: return ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,
5068: $hiddenelem);
5069: }
5070:
5071: sub decompression_phase_one {
5072: my ($dir,$file,$warning,$error,$output);
5073: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
5074: &decompression_info();
1.484.2.7 raeburn 5075: if ($env{'form.archiveurl'} !~ m{^/uploaded/\Q$docudom/$docuname/\E(?:docs|supplemental)/(?:default|\d+).*/([^/]+)$}) {
1.476 raeburn 5076: $error = &mt('Archive file "[_1]" not in the expected location.',$env{'form.archiveurl'});
5077: } else {
5078: my $file = $1;
1.481 raeburn 5079: $output =
5080: &Apache::loncommon::process_decompression($docudom,$docuname,$file,
5081: $destination,$dir_root,
5082: $hiddenelem);
5083: if ($env{'form.autoextract_camtasia'}) {
5084: $output .= &remove_archive($docudom,$docuname,$container);
5085: }
1.476 raeburn 5086: }
5087: if ($error) {
5088: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
5089: $error.'</p>'."\n";
5090: }
5091: if ($warning) {
5092: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
5093: }
5094: return $output;
5095: }
5096:
5097: sub decompression_phase_two {
5098: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
5099: &decompression_info();
1.481 raeburn 5100: my $output;
1.480 raeburn 5101: if ($env{'form.archivedelete'}) {
1.481 raeburn 5102: $output = &remove_archive($docudom,$docuname,$container);
1.480 raeburn 5103: }
5104: $output .=
1.481 raeburn 5105: &Apache::loncommon::process_extracted_files('coursedocs',$docudom,$docuname,
1.476 raeburn 5106: $destination,$dir_root,$hiddenelem);
5107: return $output;
5108: }
5109:
1.480 raeburn 5110: sub remove_archive {
5111: my ($docudom,$docuname,$container) = @_;
5112: my $map = $env{'form.folder'}.'.'.$container;
1.481 raeburn 5113: my ($output,$delwarning,$delresult,$url);
1.480 raeburn 5114: my ($errtext,$fatal) = &mapread($docuname,$docudom,$map);
5115: if ($fatal) {
5116: if ($container eq 'page') {
5117: $delwarning = &mt('An error occurred retrieving the contents of the current page.');
5118: } else {
5119: $delwarning = &mt('An error occurred retrieving the contents of the current folder.');
5120: }
5121: $delwarning .= &mt('As a result the archive file has not been removed.');
5122: } else {
5123: my $currcmd = $env{'form.cmd'};
5124: my $position = $env{'form.position'};
5125: if ($position > 0) {
5126: $env{'form.cmd'} = 'del_'.$position;
5127: my ($title,$url,@rrest) =
5128: split(/:/,$LONCAPA::map::resources[$LONCAPA::map::order[$position]]);
5129: if (&handle_edit_cmd($docuname,$docudom)) {
1.484.2.7 raeburn 5130: ($errtext,$fatal) = &storemap($docuname,$docudom,$map,1);
1.480 raeburn 5131: if ($fatal) {
5132: if ($container eq 'page') {
5133: $delwarning = &mt('An error occurred updating the contents of the current page.');
5134: } else {
5135: $delwarning = &mt('An error occurred updating the contents of the current folder.');
5136: }
5137: } else {
1.481 raeburn 5138: $delresult = &mt('Archive file removed.');
1.480 raeburn 5139: }
5140: }
5141: }
5142: $env{'form.cmd'} = $currcmd;
5143: }
5144: if ($delwarning) {
5145: $output = '<p class="LC_warning">'.
5146: $delwarning.
5147: '</p>';
5148: }
5149: if ($delresult) {
5150: $output .= '<p class="LC_info">'.
5151: $delresult.
5152: '</p>';
5153: }
1.481 raeburn 5154: return $output;
1.480 raeburn 5155: }
5156:
1.484 raeburn 5157: sub generate_admin_menu {
5158: my ($crstype) = @_;
5159: my $lc_crstype = lc($crstype);
5160: my ($home,$other,%outhash)=&authorhosts();
5161: my %lt=&Apache::lonlocal::texthash (
5162: 'vc' => 'Verify Content',
5163: 'cv' => 'Check/Set Resource Versions',
5164: 'ls' => 'List Resource Identifiers',
5165: 'imse' => 'Export contents to IMS Archive',
5166: 'dcd' => "Dump $crstype Content to Authoring Space",
5167: );
5168: my ($candump,$dumpurl);
5169: if ($home + $other > 0) {
5170: $candump = 'F';
5171: if ($home) {
5172: $dumpurl = "javascript:injectData(document.courseverify,'dummy','dumpcourse','$lt{'dcd'}')";
5173: } else {
5174: my @hosts;
5175: foreach my $aurole (keys(%outhash)) {
5176: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
5177: push(@hosts,$outhash{$aurole});
1.484.2.30 raeburn 5178: }
1.484 raeburn 5179: }
5180: if (@hosts == 1) {
5181: my $switchto = '/adm/switchserver?otherserver='.$hosts[0].
5182: '&role='.
5183: &HTML::Entities::encode($env{'request.role'},'"<>&').'&origurl='.
5184: &HTML::Entities::encode('/adm/coursedocs?dumpcourse=1','"<>&');
5185: $dumpurl = "javascript:dump_needs_switchserver('$switchto')";
5186: } else {
5187: $dumpurl = "javascript:choose_switchserver_window()";
5188: }
5189: }
5190: }
5191: my @menu=
5192: ({ categorytitle=>'Administration',
5193: items =>[
5194: { linktext => $lt{'vc'},
5195: url => "javascript:injectData(document.courseverify,'dummy','verify','$lt{'vc'}')",
5196: permission => 'F',
5197: help => 'Verify_Content',
5198: icon => 'verify.png',
5199: linktitle => 'Verify contents can be retrieved/rendered',
5200: },
5201: { linktext => $lt{'cv'},
5202: url => "javascript:injectData(document.courseverify,'dummy','versions','$lt{'cv'}')",
5203: permission => 'F',
5204: help => 'Check_Resource_Versions',
5205: icon => 'resversion.png',
5206: linktitle => "View version information for resources in your $lc_crstype, and fix/unfix use of specific versions",
5207: },
5208: { linktext => $lt{'ls'},
5209: url => "javascript:injectData(document.courseverify,'dummy','listsymbs','$lt{'ls'}')",
5210: permission => 'F',
5211: #help => '',
5212: icon => 'symbs.png',
5213: linktitle => "List the unique identifier used for each resource instance in your $lc_crstype"
5214: },
5215: ]
5216: },
5217: { categorytitle=>'Export',
5218: items =>[
5219: { linktext => $lt{'imse'},
5220: url => "javascript:injectData(document.courseverify,'dummy','exportcourse','$lt{'imse'}')",
5221: permission => 'F',
5222: help => 'Docs_Export_Course_Docs',
5223: icon => 'imsexport.png',
5224: linktitle => $lt{'imse'},
5225: },
5226: { linktext => $lt{'dcd'},
5227: url => $dumpurl,
5228: permission => $candump,
5229: #help => '',
5230: icon => 'dump.png',
5231: linktitle => $lt{'dcd'},
5232: },
5233: ]
5234: });
5235: return '<form action="/adm/coursedocs" method="post" name="courseverify">'."\n".
5236: '<input type="hidden" id="dummy" />'."\n".
5237: &Apache::lonhtmlcommon::generate_menu(@menu)."\n".
5238: '</form>';
1.329 droeschl 5239: }
5240:
5241: sub generate_edit_table {
1.484.2.30 raeburn 5242: my ($tid,$orderhash_ref,$to_show,$iconpath,$jumpto,$readfile,
5243: $need_save,$copyfolder) = @_;
1.406 raeburn 5244: return unless(ref($orderhash_ref) eq 'HASH');
1.342 ehlerst 5245: my %orderhash = %{$orderhash_ref};
1.344 bisitz 5246: my $form;
1.371 tempelho 5247: my $activetab;
5248: my $active;
1.484.2.20 raeburn 5249: if (($env{'form.active'} ne '') && ($env{'form.active'} ne 'aa')) {
1.371 tempelho 5250: $activetab = $env{'form.active'};
5251: }
1.472 raeburn 5252: my $backicon = $iconpath.'clickhere.gif';
1.484.2.21 raeburn 5253: my $backtext = &mt('Exit Editor');
1.458 raeburn 5254: $form = '<div class="LC_Box" style="margin:0;">'.
1.484.2.19 raeburn 5255: '<ul id="navigation'.$tid.'" class="LC_TabContent">'."\n".
5256: '<li class="goback">'.
1.484.2.32 raeburn 5257: '<a href="javascript:toContents('."'$jumpto'".');">'.
1.484.2.19 raeburn 5258: '<img src="'.$backicon.'" class="LC_icon" style="border: none; vertical-align: top;"'.
5259: ' alt="'.$backtext.'" />'.$backtext.'</a></li>'."\n".
5260: '<li>'.
5261: '<a href="javascript:groupopen('."'$readfile'".',1);">'.
5262: &mt('Undo Delete').'</a></li>'."\n";
1.484.2.7 raeburn 5263: if ($env{'form.docslog'}) {
5264: $form .= '<li class="active">';
5265: } else {
5266: $form .= '<li>';
5267: }
5268: $form .= '<a href="javascript:toggleHistoryDisp(1);">'.
5269: &mt('History').'</a></li>'."\n";
5270: if ($env{'form.docslog'}) {
5271: $form .= '<li><a href="javascript:toggleHistoryDisp(0);">'.
5272: &mt('Edit').'</a></li>'."\n";
1.484 raeburn 5273: }
1.458 raeburn 5274: foreach my $name (reverse(sort(keys(%orderhash)))) {
1.390 tempelho 5275: if($name ne '00'){
1.371 tempelho 5276: if($activetab eq '' || $activetab ne $name){
5277: $active = '';
5278: }elsif($activetab eq $name){
5279: $active = 'class="active"';
5280: }
1.458 raeburn 5281: $form .= '<li style="float:right" '.$active
1.484 raeburn 5282: .' 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 5283: } else {
1.484 raeburn 5284: $form .= '<li '.$active.' style="float:right">'.${$orderhash{$name}}[1].'</li>'."\n";
1.390 tempelho 5285:
5286: }
1.329 droeschl 5287: }
1.484 raeburn 5288: $form .= '</ul>'."\n";
5289: $form .= '<div id="content'.$tid.'" style="padding: 0 0; margin: 0 0; overflow: hidden; clear:right">'."\n";
1.458 raeburn 5290:
5291: if ($to_show ne '') {
1.484.2.30 raeburn 5292: my $saveform;
5293: if ($need_save) {
5294: my $button = &mt('Make changes');
5295: my $path;
5296: if ($env{'form.folderpath'}) {
5297: $path =
5298: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
5299: }
5300: $saveform = <<"END";
5301: <div id="multisave" style="display:none; clear:both;" >
5302: <form name="saveactions" method="post" action="/adm/coursedocs" onsubmit="return checkSubmits();">
5303: <input type="hidden" name="folderpath" value="$path" />
5304: <input type="hidden" name="symb" value="$env{'form.symb'}" />
5305: <input type="hidden" name="allhiddenresource" value="" />
5306: <input type="hidden" name="allencrypturl" value="" />
5307: <input type="hidden" name="allrandompick" value="" />
5308: <input type="hidden" name="allrandomorder" value="" />
5309: <input type="hidden" name="changeparms" value="" />
5310: <input type="hidden" name="multiremove" value="" />
5311: <input type="hidden" name="multicut" value="" />
5312: <input type="hidden" name="multicopy" value="" />
5313: <input type="hidden" name="multichange" value="" />
5314: <input type="hidden" name="copyfolder" value="$copyfolder" />
5315: <input type="submit" name="savemultiples" value="$button" />
5316: </form>
5317: </div>
5318: END
5319: }
5320: $form .= '<div style="padding:0;margin:0;float:left">'.$to_show.'</div>'.$saveform."\n";
1.458 raeburn 5321: }
1.363 ehlerst 5322: foreach my $field (keys(%orderhash)){
1.390 tempelho 5323: if($field ne '00'){
1.422 onken 5324: if($activetab eq '' || $activetab ne $field){
1.458 raeburn 5325: $active = 'style="display: none;float:left"';
1.422 onken 5326: }elsif($activetab eq $field){
1.458 raeburn 5327: $active = 'style="display:block;float:left"';
1.422 onken 5328: }
5329: $form .= '<div id="'.$field.$tid.'"'
5330: .' class="LC_ContentBox" '.$active.'>'.${$orderhash{$field}}[1]
1.484 raeburn 5331: .'</div>'."\n";
1.363 ehlerst 5332: }
5333: }
1.484 raeburn 5334: unless ($env{'form.docslog'}) {
5335: $form .= '</div></div>'."\n";
5336: }
1.329 droeschl 5337: return $form;
5338: }
5339:
5340: sub editing_js {
1.472 raeburn 5341: my ($udom,$uname,$supplementalflag) = @_;
1.329 droeschl 5342: my %lt = &Apache::lonlocal::texthash(
5343: p_mnf => 'Name of New Folder',
5344: t_mnf => 'New Folder',
5345: p_mnp => 'Name of New Page',
5346: t_mnp => 'New Page',
1.451 www 5347: p_mxu => 'Title for the External Score',
1.349 biermanm 5348: p_msp => 'Name of Simple Course Page',
1.329 droeschl 5349: p_msb => 'Title for the Problem',
5350: p_mdb => 'Title for the Drop Box',
1.336 schafran 5351: p_mbb => 'Title for the Discussion Board',
1.484.2.27 raeburn 5352: p_mwp => 'Title for Web Page',
1.348 weissno 5353: p_mab => "Enter user:domain for User's Personal Information Page",
1.352 bisitz 5354: p_mab2 => 'Personal Information Page of ',
1.329 droeschl 5355: p_mab_alrt1 => 'Not a valid user:domain',
5356: p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',
5357: p_chn => 'New Title',
5358: p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',
5359: p_rmr2a => 'Remove[_99]',
5360: p_rmr2b => '?[_99]',
1.484.2.30 raeburn 5361: p_rmr3a => 'Remove those [_2]',
5362: p_rmr3b => 'items?[_2]',
1.329 droeschl 5363: p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',
5364: p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',
5365: p_ctr2a => 'Cut[_98]',
1.478 raeburn 5366: p_ctr2b => '?[_98]',
1.484.2.30 raeburn 5367: p_ctr3a => 'Cut those[_2]',
5368: p_ctr3b => 'items?[_2]',
1.478 raeburn 5369: rpck => 'Enter number to pick (e.g., 3)',
1.484.2.12 raeburn 5370: imsfile => 'You must choose an IMS package for import',
5371: imscms => 'You must select which Course Management System was the source of the IMS package',
5372: invurl => 'Invalid URL',
5373: titbl => 'Title is blank',
1.484.2.30 raeburn 5374: more => '(More ...)',
5375: less => '(Less ...)',
5376: noor => 'No actions selected or changes to settings specified.',
5377: noch => 'No changes to settings specified.',
5378: noac => 'No actions selected.',
1.329 droeschl 5379: );
5380:
1.433 raeburn 5381: my $crstype = &Apache::loncommon::course_type();
1.434 raeburn 5382: my $docs_folderpath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'},'<>&"');
5383: my $main_container_page;
1.484.2.19 raeburn 5384: if (&HTML::Entities::decode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'}) =~ /\:1$/) {
5385: $main_container_page = 1;
1.434 raeburn 5386: }
1.484.2.30 raeburn 5387: my $toplevelmain =
1.484.2.33 raeburn 5388: &escape(&mt('Main Content').':::::');
1.446 www 5389: my $toplevelsupp = &supplemental_base();
1.433 raeburn 5390:
1.484.2.21 raeburn 5391: my $backtourl;
5392: if ($env{'docs.exit.'.$env{'request.course.id'}} =~ /^direct_(.+)$/) {
5393: my $caller = $1;
5394: if ($caller =~ /^supplemental/) {
5395: $backtourl = '/adm/supplemental?folderpath='.&escape($caller);
5396: } else {
5397: my ($map,$id,$res)=&Apache::lonnet::decode_symb($caller);
5398: $res = &Apache::lonnet::clutter($res);
5399: if (&Apache::lonnet::is_on_map($res)) {
5400: $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($res),'<>&"').'?symb='.
5401: &HTML::Entities::encode($caller,'<>&"');
1.484.2.31 raeburn 5402: } else {
5403: $backtourl = '/adm/navmaps';
1.484.2.21 raeburn 5404: }
5405: }
5406: } elsif ($env{'docs.exit.'.$env{'request.course.id'}} eq '/adm/menu') {
5407: $backtourl = '/adm/menu';
5408: } elsif ($supplementalflag) {
1.472 raeburn 5409: $backtourl = '/adm/supplemental';
1.484.2.21 raeburn 5410: } else {
5411: $backtourl = '/adm/navmaps';
1.472 raeburn 5412: }
5413:
1.484.2.19 raeburn 5414: my $fieldsets = "'ext','doc'";
5415: unless ($main_container_page) {
5416: $fieldsets .=",'ims'";
5417: }
1.484.2.12 raeburn 5418: if ($supplementalflag) {
5419: $fieldsets = "'suppext','suppdoc'";
5420: }
5421:
1.329 droeschl 5422: return <<ENDNEWSCRIPT;
5423: function makenewfolder(targetform,folderseq) {
5424: var foldername=prompt('$lt{"p_mnf"}','$lt{"t_mnf"}');
5425: if (foldername) {
5426: targetform.importdetail.value=escape(foldername)+"="+folderseq;
5427: targetform.submit();
5428: }
5429: }
5430:
5431: function makenewpage(targetform,folderseq) {
5432: var pagename=prompt('$lt{"p_mnp"}','$lt{"t_mnp"}');
5433: if (pagename) {
5434: targetform.importdetail.value=escape(pagename)+"="+folderseq;
5435: targetform.submit();
5436: }
5437: }
5438:
5439: function makeexamupload() {
5440: var title=prompt('$lt{"p_mxu"}');
1.344 bisitz 5441: if (title) {
1.329 droeschl 5442: this.document.forms.newexamupload.importdetail.value=
5443: escape(title)+'=/res/lib/templates/examupload.problem';
5444: this.document.forms.newexamupload.submit();
5445: }
5446: }
5447:
5448: function makesmppage() {
5449: var title=prompt('$lt{"p_msp"}');
1.344 bisitz 5450: if (title) {
1.329 droeschl 5451: this.document.forms.newsmppg.importdetail.value=
1.484.2.26 raeburn 5452: escape(title)+'=/adm/$udom/$uname/new/smppg';
1.329 droeschl 5453: this.document.forms.newsmppg.submit();
5454: }
5455: }
5456:
1.484.2.27 raeburn 5457: function makewebpage(type) {
5458: var title=prompt('$lt{"p_mwp"}');
5459: var formname;
5460: if (type == 'supp') {
5461: formname = this.document.forms.supwebpage;
5462: } else {
5463: formname = this.document.forms.newwebpage;
5464: }
5465: if (title) {
5466: var webpage = formname.importdetail.value;
5467: formname.importdetail.value = escape(title)+'='+webpage;
5468: formname.submit();
5469: }
5470: }
5471:
1.329 droeschl 5472: function makesmpproblem() {
5473: var title=prompt('$lt{"p_msb"}');
1.344 bisitz 5474: if (title) {
1.329 droeschl 5475: this.document.forms.newsmpproblem.importdetail.value=
5476: escape(title)+'=/res/lib/templates/simpleproblem.problem';
5477: this.document.forms.newsmpproblem.submit();
5478: }
5479: }
5480:
5481: function makedropbox() {
5482: var title=prompt('$lt{"p_mdb"}');
1.344 bisitz 5483: if (title) {
1.329 droeschl 5484: this.document.forms.newdropbox.importdetail.value=
5485: escape(title)+'=/res/lib/templates/DropBox.problem';
5486: this.document.forms.newdropbox.submit();
5487: }
5488: }
5489:
5490: function makebulboard() {
5491: var title=prompt('$lt{"p_mbb"}');
5492: if (title) {
5493: this.document.forms.newbul.importdetail.value=
1.484.2.26 raeburn 5494: escape(title)+'=/adm/$udom/$uname/new/bulletinboard';
1.329 droeschl 5495: this.document.forms.newbul.submit();
5496: }
5497: }
5498:
5499: function makeabout() {
5500: var user=prompt("$lt{'p_mab'}");
5501: if (user) {
5502: var comp=new Array();
5503: comp=user.split(':');
5504: if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
5505: if ((comp[0]) && (comp[1])) {
5506: this.document.forms.newaboutsomeone.importdetail.value=
5507: '$lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
1.335 ehlerst 5508: this.document.forms.newaboutsomeone.submit();
5509: } else {
5510: alert("$lt{'p_mab_alrt1'}");
1.329 droeschl 5511: }
1.335 ehlerst 5512: } else {
5513: alert("$lt{'p_mab_alrt2'}");
5514: }
5515: }
1.329 droeschl 5516: }
5517:
1.484.2.13 raeburn 5518: function toggleUpload(caller) {
5519: var blocks = Array($fieldsets);
5520: for (var i=0; i<blocks.length; i++) {
5521: var disp = 'none';
5522: if (caller == blocks[i]) {
5523: var curr = document.getElementById('upload'+caller+'form').style.display;
5524: if (curr == 'none') {
5525: disp='block';
5526: }
5527: }
5528: document.getElementById('upload'+blocks[i]+'form').style.display=disp;
5529: }
5530: resize_scrollbox('contentscroll','1','1');
5531: return;
5532: }
5533:
1.484.2.19 raeburn 5534: function toggleMap(caller) {
1.484.2.13 raeburn 5535: var disp = 'none';
1.484.2.19 raeburn 5536: if (document.getElementById('importmapform')) {
5537: if (caller == 'map') {
5538: var curr = document.getElementById('importmapform').style.display;
5539: if (curr == 'none') {
5540: disp='block';
5541: }
1.484.2.12 raeburn 5542: }
1.484.2.19 raeburn 5543: document.getElementById('importmapform').style.display=disp;
5544: resize_scrollbox('contentscroll','1','1');
1.484.2.12 raeburn 5545: }
1.484.2.19 raeburn 5546: return;
1.329 droeschl 5547: }
5548:
1.484.2.12 raeburn 5549: function makeims(imsform) {
5550: if ((imsform.uploaddoc.value == '') || (!imsform.uploaddoc.value)) {
5551: alert("$lt{'imsfile'}");
5552: return;
5553: }
5554: if (imsform.source.selectedIndex == 0) {
5555: alert("$lt{'imscms'}");
5556: return;
5557: }
5558: newWindow = window.open('', 'IMSimport',"HEIGHT=700,WIDTH=750,scrollbars=yes");
5559: imsform.submit();
5560: }
5561:
1.484.2.19 raeburn 5562: function changename(folderpath,index,oldtitle) {
1.335 ehlerst 5563: var title=prompt('$lt{"p_chn"}',oldtitle);
5564: if (title) {
1.484.2.30 raeburn 5565: this.document.forms.renameform.markcopy.value='';
1.335 ehlerst 5566: this.document.forms.renameform.title.value=title;
5567: this.document.forms.renameform.cmd.value='rename_'+index;
1.484.2.19 raeburn 5568: this.document.forms.renameform.folderpath.value=folderpath;
1.335 ehlerst 5569: this.document.forms.renameform.submit();
5570: }
1.329 droeschl 5571: }
5572:
1.478 raeburn 5573: function updatePick(targetform,index,caller) {
1.484.2.29 raeburn 5574: var pickitem;
5575: var picknumitem;
5576: var picknumtext;
5577: if (index == 'all') {
5578: pickitem = document.getElementById('randompickall');
5579: picknumitem = document.getElementById('rpicknumall');
5580: picknumtext = document.getElementById('rpicktextall');
5581: } else {
5582: pickitem = document.getElementById('randompick_'+index);
5583: picknumitem = document.getElementById('rpicknum_'+index);
5584: picknumtext = document.getElementById('randompicknum_'+index);
5585: }
1.478 raeburn 5586: if (pickitem.checked) {
5587: var picknum=prompt('$lt{"rpck"}',picknumitem.value);
5588: if (picknum == '' || picknum == null) {
5589: if (caller == 'check') {
5590: pickitem.checked=false;
1.484.2.29 raeburn 5591: if (index == 'all') {
5592: picknumtext.innerHTML = '';
5593: if (caller == 'link') {
5594: propagateState(targetform,'rpicknum');
5595: }
5596: } else {
1.484.2.30 raeburn 5597: checkForSubmit(targetform,'randompick','settings');
1.484.2.29 raeburn 5598: }
1.478 raeburn 5599: }
5600: } else {
5601: picknum.toString();
5602: var regexdigit=/^\\d+\$/;
5603: if (regexdigit.test(picknum)) {
5604: picknumitem.value = picknum;
1.484.2.29 raeburn 5605: if (index == 'all') {
1.484.2.30 raeburn 5606: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.cumulativesettings,\\'all\\',\\'link\\');">'+picknum+'</a>';
1.484.2.29 raeburn 5607: if (caller == 'link') {
5608: propagateState(targetform,'rpicknum');
5609: }
5610: } else {
5611: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.edit_randompick_'+index+',\\''+index+'\\',\\'link\\');">'+picknum+'</a>';
1.484.2.30 raeburn 5612: checkForSubmit(targetform,'randompick','settings');
1.484.2.29 raeburn 5613: }
1.478 raeburn 5614: } else {
5615: if (caller == 'check') {
1.484.2.29 raeburn 5616: if (index == 'all') {
5617: picknumtext.innerHTML = '';
5618: if (caller == 'link') {
5619: propagateState(targetform,'rpicknum');
5620: }
5621: } else {
5622: pickitem.checked=false;
1.484.2.30 raeburn 5623: checkForSubmit(targetform,'randompick','settings');
1.484.2.29 raeburn 5624: }
1.478 raeburn 5625: }
5626: return;
5627: }
5628: }
5629: } else {
1.484.2.29 raeburn 5630: picknumitem.value = '';
5631: picknumtext.innerHTML = '';
5632: if (index == 'all') {
5633: if (caller == 'link') {
5634: propagateState(targetform,'rpicknum');
5635: }
5636: } else {
1.484.2.30 raeburn 5637: checkForSubmit(targetform,'randompick','settings');
1.484.2.29 raeburn 5638: }
5639: }
5640: }
5641:
5642: function propagateState(form,param) {
5643: if (document.getElementById(param+'all')) {
5644: var setcheck = 0;
5645: var rpick = 0;
5646: if (param == 'rpicknum') {
5647: if (document.getElementById('randompickall')) {
5648: if (document.getElementById('randompickall').checked) {
5649: if (document.getElementById('rpicknumall')) {
5650: rpick = document.getElementById('rpicknumall').value;
5651: }
5652: }
5653: }
5654: } else {
5655: if (document.getElementById(param+'all').checked) {
5656: setcheck = 1;
5657: }
5658: }
1.484.2.30 raeburn 5659: var allidxlist;
5660: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
5661: if (document.getElementById('all'+param+'idx')) {
5662: allidxlist = document.getElementById('all'+param+'idx').value;
5663: }
5664: var actions = new Array ('remove','cut','copy');
5665: for (var i=0; i<actions.length; i++) {
5666: if (actions[i] != param) {
5667: if (document.getElementById(actions[i]+'all')) {
5668: document.getElementById(actions[i]+'all').checked = false;
5669: }
5670: }
5671: }
5672: }
1.484.2.29 raeburn 5673: if ((param == 'encrypturl') || (param == 'hiddenresource')) {
1.484.2.30 raeburn 5674: allidxlist = form.allidx.value;
5675: }
5676: if ((param == 'randompick') || (param == 'rpicknum') || (param == 'randomorder')) {
5677: allidxlist = form.allmapidx.value;
5678: }
5679: if ((allidxlist != '') && (allidxlist != null)) {
5680: var allidxs = allidxlist.split(',');
5681: if (allidxs.length > 1) {
5682: for (var i=0; i<allidxs.length; i++) {
5683: if (document.getElementById(param+'_'+allidxs[i])) {
5684: if (param == 'rpicknum') {
5685: if (document.getElementById('randompick_'+allidxs[i])) {
5686: if (document.getElementById('randompick_'+allidxs[i]).checked) {
5687: document.getElementById(param+'_'+allidxs[i]).value = rpick;
5688: if (rpick > 0) {
5689: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = ': <a href="javascript:updatePick(document.edit_randompick_'+allidxs[i]+',\\''+allidxs[i]+'\\',\\'link\\')">'+rpick+'</a>';
5690: } else {
5691: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
5692: }
5693: }
5694: }
5695: } else {
1.484.2.29 raeburn 5696: if (setcheck == 1) {
5697: document.getElementById(param+'_'+allidxs[i]).checked = true;
5698: } else {
5699: document.getElementById(param+'_'+allidxs[i]).checked = false;
1.484.2.30 raeburn 5700: if (param == 'randompick') {
5701: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
5702: }
1.484.2.29 raeburn 5703: }
5704: }
5705: }
5706: }
1.484.2.30 raeburn 5707: if (setcheck == 1) {
5708: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
5709: var actions = new Array('copy','cut','remove');
5710: for (var i=0; i<actions.length; i++) {
5711: var otheractions;
5712: var otheridxs;
5713: if (actions[i] === param) {
5714: continue;
5715: } else {
5716: if (document.getElementById('all'+actions[i]+'idx')) {
5717: otheractions = document.getElementById('all'+actions[i]+'idx').value;
5718: otheridxs = otheractions.split(',');
5719: if (otheridxs.length > 1) {
5720: for (var j=0; j<otheridxs.length; j++) {
5721: if (document.getElementById(actions[i]+'_'+otheridxs[j])) {
5722: document.getElementById(actions[i]+'_'+otheridxs[j]).checked = false;
5723: }
1.484.2.29 raeburn 5724: }
5725: }
5726: }
5727: }
1.484.2.30 raeburn 5728: }
1.484.2.29 raeburn 5729: }
5730: }
5731: }
5732: }
1.478 raeburn 5733: }
1.484.2.29 raeburn 5734: return;
5735: }
5736:
1.484.2.30 raeburn 5737: function checkForSubmit(targetform,param,context,idx,folderpath,index,oldtitle,skip_confirm,container,folder) {
5738: var dosettings;
5739: var doaction;
5740: var control = document.togglemultsettings;
5741: if (context == 'actions') {
5742: control = document.togglemultactions;
5743: doaction = 1;
5744: } else {
5745: dosettings = 1;
5746: }
5747: if (control) {
5748: if (control.showmultpick.length) {
5749: for (var i=0; i<control.showmultpick.length; i++) {
5750: if (control.showmultpick[i].checked) {
5751: if (control.showmultpick[i].value == 1) {
5752: if (context == 'settings') {
5753: dosettings = 0;
5754: } else {
5755: doaction = 0;
5756: }
5757: }
5758: }
5759: }
5760: }
5761: }
5762: if (context == 'settings') {
5763: if (dosettings == 1) {
5764: targetform.changeparms.value=param;
5765: targetform.submit();
5766: }
5767: }
5768: if (context == 'actions') {
5769: if (doaction == 1) {
5770: targetform.cmd.value=param+'_'+index;
5771: targetform.folderpath.value=folderpath;
5772: targetform.markcopy.value=idx+':'+param;
5773: targetform.copyfolder.value=folder+'.'+container;
5774: if (param == 'remove') {
5775: if (skip_confirm || confirm('$lt{"p_rmr1"}\\n\\n$lt{"p_rmr2a"} "'+oldtitle+'" $lt{"p_rmr2b"}')) {
5776: targetform.markcopy.value='';
5777: targetform.copyfolder.value='';
1.484.2.29 raeburn 5778: targetform.submit();
5779: }
5780: }
1.484.2.30 raeburn 5781: if (param == 'cut') {
5782: if (skip_confirm || confirm('$lt{"p_ctr1a"}\\n$lt{"p_ctr1b"}\\n\\n$lt{"p_ctr2a"} "'+oldtitle+'" $lt{"p_ctr2b"}')) {
5783: targetform.submit();
5784: return;
5785: }
5786: }
5787: if (param == 'copy') {
5788: targetform.submit();
5789: return;
5790: }
5791: targetform.markcopy.value='';
5792: targetform.copyfolder.value='';
5793: targetform.cmd.value='';
5794: targetform.folderpath.value='';
5795: return;
5796: } else {
5797: if (document.getElementById(param+'_'+idx)) {
5798: item = document.getElementById(param+'_'+idx);
5799: if (item.type == 'checkbox') {
5800: if (item.checked) {
5801: item.checked = false;
5802: } else {
5803: item.checked = true;
5804: singleCheck(item,idx,param);
5805: }
5806: }
5807: }
5808: }
5809: }
5810: return;
5811: }
5812:
5813: function singleCheck(caller,idx,action) {
5814: actions = new Array('cut','copy','remove');
5815: if (caller.checked) {
5816: for (var i=0; i<actions.length; i++) {
5817: if (actions[i] != action) {
5818: if (document.getElementById(actions[i]+'_'+idx)) {
5819: if (document.getElementById(actions[i]+'_'+idx).checked) {
5820: document.getElementById(actions[i]+'_'+idx).checked = false;
5821: }
5822: }
5823: }
1.484.2.29 raeburn 5824: }
5825: }
5826: return;
1.478 raeburn 5827: }
5828:
1.334 muellerd 5829: function unselectInactive(nav) {
1.335 ehlerst 5830: currentNav = document.getElementById(nav);
5831: currentLis = currentNav.getElementsByTagName('LI');
5832: for (i = 0; i < currentLis.length; i++) {
1.472 raeburn 5833: if (currentLis[i].className == 'goback') {
5834: currentLis[i].className = 'goback';
5835: } else {
5836: if (currentLis[i].className == 'right active' || currentLis[i].className == 'right') {
1.374 tempelho 5837: currentLis[i].className = 'right';
1.472 raeburn 5838: } else {
1.374 tempelho 5839: currentLis[i].className = 'i';
1.472 raeburn 5840: }
5841: }
1.335 ehlerst 5842: }
1.332 tempelho 5843: }
5844:
1.334 muellerd 5845: function hideAll(current, nav, data) {
1.335 ehlerst 5846: unselectInactive(nav);
1.374 tempelho 5847: if(current.className == 'right'){
5848: current.className = 'right active'
5849: }else{
5850: current.className = 'active';
5851: }
1.335 ehlerst 5852: currentData = document.getElementById(data);
5853: currentDivs = currentData.getElementsByTagName('DIV');
5854: for (i = 0; i < currentDivs.length; i++) {
5855: if(currentDivs[i].className == 'LC_ContentBox'){
1.333 muellerd 5856: currentDivs[i].style.display = 'none';
1.330 tempelho 5857: }
5858: }
1.335 ehlerst 5859: }
1.330 tempelho 5860:
1.374 tempelho 5861: function openTabs(pageId) {
5862: tabnav = document.getElementById(pageId).getElementsByTagName('UL');
1.383 tempelho 5863: if(tabnav.length > 2 ){
1.389 tempelho 5864: currentNav = document.getElementById(tabnav[1].id);
1.374 tempelho 5865: currentLis = currentNav.getElementsByTagName('LI');
5866: for(i = 0; i< currentLis.length; i++){
5867: if(currentLis[i].className == 'active') {
1.375 tempelho 5868: funcString = currentLis[i].onclick.toString();
5869: tab = funcString.split('"');
1.420 onken 5870: if(tab.length < 2) {
5871: tab = funcString.split("'");
5872: }
1.375 tempelho 5873: currentData = document.getElementById(tab[1]);
5874: currentData.style.display = 'block';
1.374 tempelho 5875: }
5876: }
5877: }
5878: }
5879:
1.334 muellerd 5880: function showPage(current, pageId, nav, data) {
5881: hideAll(current, nav, data);
1.375 tempelho 5882: openTabs(pageId);
1.334 muellerd 5883: unselectInactive(nav);
1.330 tempelho 5884: current.className = 'active';
5885: currentData = document.getElementById(pageId);
5886: currentData.style.display = 'block';
1.458 raeburn 5887: activeTab = pageId;
1.484.2.12 raeburn 5888: toggleUpload();
1.484.2.14 raeburn 5889: toggleMap();
1.433 raeburn 5890: if (nav == 'mainnav') {
5891: var storedpath = "$docs_folderpath";
1.434 raeburn 5892: var storedpage = "$main_container_page";
1.433 raeburn 5893: var reg = new RegExp("^supplemental");
5894: if (pageId == 'mainCourseDocuments') {
1.434 raeburn 5895: if (storedpage == 1) {
5896: document.simpleedit.folderpath.value = '';
5897: document.uploaddocument.folderpath.value = '';
5898: } else {
5899: if (reg.test(storedpath)) {
5900: document.simpleedit.folderpath.value = '$toplevelmain';
5901: document.uploaddocument.folderpath.value = '$toplevelmain';
5902: document.newext.folderpath.value = '$toplevelmain';
5903: } else {
5904: document.simpleedit.folderpath.value = storedpath;
5905: document.uploaddocument.folderpath.value = storedpath;
5906: document.newext.folderpath.value = storedpath;
5907: }
1.433 raeburn 5908: }
5909: } else {
1.434 raeburn 5910: if (reg.test(storedpath)) {
5911: document.simpleedit.folderpath.value = storedpath;
5912: document.supuploaddocument.folderpath.value = storedpath;
5913: document.supnewext.folderpath.value = storedpath;
5914: } else {
1.433 raeburn 5915: document.simpleedit.folderpath.value = '$toplevelsupp';
5916: document.supuploaddocument.folderpath.value = '$toplevelsupp';
5917: document.supnewext.folderpath.value = '$toplevelsupp';
5918: }
5919: }
5920: }
1.484.2.3 raeburn 5921: resize_scrollbox('contentscroll','1','0');
1.330 tempelho 5922: return false;
5923: }
1.329 droeschl 5924:
1.472 raeburn 5925: function toContents(jumpto) {
5926: var newurl = '$backtourl';
1.484.2.21 raeburn 5927: if ((newurl == '/adm/navmaps') && (jumpto != '')) {
1.472 raeburn 5928: newurl = newurl+'?postdata='+jumpto;
5929: }
5930: location.href=newurl;
5931: }
5932:
1.484.2.30 raeburn 5933: function togglePick(caller,value) {
5934: var disp = 'none';
5935: if (document.getElementById('multi'+caller)) {
5936: var curr = document.getElementById('multi'+caller).style.display;
5937: if (value == 1) {
5938: disp='block';
5939: }
5940: if (curr == disp) {
5941: return;
5942: }
5943: document.getElementById('multi'+caller).style.display=disp;
5944: if (value == 1) {
5945: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$lt{'more'}</a>';
5946: } else {
5947: document.getElementById('more'+caller).innerHTML = '';
5948: }
5949: if (caller == 'actions') {
5950: setClass(value);
5951: setBoxes(value);
5952: }
5953: }
5954: var showButton = multiSettings();
5955: if (showButton != 1) {
5956: showButton = multiActions();
5957: }
5958: if (document.getElementById('multisave')) {
5959: if (showButton == 1) {
5960: document.getElementById('multisave').style.display='block';
5961: } else {
5962: document.getElementById('multisave').style.display='none';
5963: }
5964: }
5965: resize_scrollbox('contentscroll','1','1');
5966: return;
5967: }
5968:
5969: function toggleCheckUncheck(caller,more) {
5970: if (more == 1) {
5971: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',0);" style="text-decoration:none;">$lt{'less'}</a>';
5972: document.getElementById('allfields'+caller).style.display='block';
5973: } else {
5974: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$lt{'more'}</a>';
5975: document.getElementById('allfields'+caller).style.display='none';
5976: }
5977: resize_scrollbox('contentscroll','1','1');
5978: }
5979:
5980: function multiSettings() {
5981: var inuse = 0;
5982: var settingsform = document.togglemultsettings;
5983: if (settingsform.showmultpick.length > 1) {
5984: for (var i=0; i<settingsform.showmultpick.length; i++) {
5985: if (settingsform.showmultpick[i].checked) {
5986: if (settingsform.showmultpick[i].value == 1) {
5987: inuse = 1;
5988: }
5989: }
5990: }
5991: }
5992: return inuse;
5993: }
5994:
5995: function multiActions() {
5996: var inuse = 0;
5997: var actionsform = document.togglemultactions;
5998: if (actionsform.showmultpick.length > 1) {
5999: for (var i=0; i<actionsform.showmultpick.length; i++) {
6000: if (actionsform.showmultpick[i].checked) {
6001: if (actionsform.showmultpick[i].value == 1) {
6002: inuse = 1;
6003: }
6004: }
6005: }
6006: }
6007: return inuse;
6008: }
6009:
6010: function checkSubmits() {
6011: var numchanges = 0;
6012: var form = document.saveactions;
6013: var doactions = multiActions();
6014: var cutwarnings = 0;
6015: var remwarnings = 0;
6016: if (doactions == 1) {
6017: var remidxlist = document.cumulativeactions.allremoveidx.value;
6018: if ((remidxlist != '') && (remidxlist != null)) {
6019: var remidxs = remidxlist.split(',');
6020: for (var i=0; i<remidxs.length; i++) {
6021: if (document.getElementById('remove_'+remidxs[i])) {
6022: if (document.getElementById('remove_'+remidxs[i]).checked) {
6023: form.multiremove.value += remidxs[i]+',';
6024: numchanges ++;
6025: if (document.getElementById('skip_remove_'+remidxs[i])) {
6026: if (document.getElementById('skip_remove_'+remidxs[i]).value == 0) {
6027: remwarnings ++;
6028: }
6029: }
6030: }
6031: }
6032: }
6033: }
6034: var cutidxlist = document.cumulativeactions.allcutidx.value;
6035: if ((cutidxlist != '') && (cutidxlist != null)) {
6036: var cutidxs = cutidxlist.split(',');
6037: for (var i=0; i<cutidxs.length; i++) {
6038: if (document.getElementById('cut_'+cutidxs[i])) {
6039: if (document.getElementById('cut_'+cutidxs[i]).checked == true) {
6040: form.multicut.value += cutidxs[i]+',';
6041: numchanges ++;
6042: if (document.getElementById('skip_cut_'+cutidxs[i])) {
6043: if (document.getElementById('skip_cut_'+cutidxs[i]).value == 0) {
6044: cutwarnings ++;
6045: }
6046: }
6047: }
6048: }
6049: }
6050: }
6051: var copyidxlist = document.cumulativeactions.allcopyidx.value;
6052: if ((copyidxlist != '') && (copyidxlist != null)) {
6053: var copyidxs = copyidxlist.split(',');
6054: for (var i=0; i<copyidxs.length; i++) {
6055: if (document.getElementById('copy_'+copyidxs[i])) {
6056: if (document.getElementById('copy_'+copyidxs[i]).checked) {
6057: form.multicopy.value += copyidxs[i]+',';
6058: numchanges ++;
6059: }
6060: }
6061: }
6062: }
6063: if (numchanges > 0) {
6064: form.multichange.value = numchanges;
6065: }
6066: }
6067: var dosettings = multiSettings();
6068: var haschanges = 0;
6069: if (dosettings == 1) {
6070: form.allencrypturl.value = '';
6071: form.allhiddenresource.value = '';
6072: form.changeparms.value = 'all';
6073: var patt=new RegExp(",\$");
6074: var allidxlist = document.cumulativesettings.allidx.value;
6075: if ((allidxlist != '') && (allidxlist != null)) {
6076: var allidxs = allidxlist.split(',');
6077: if (allidxs.length > 1) {
6078: for (var i=0; i<allidxs.length; i++) {
6079: if (document.getElementById('hiddenresource_'+allidxs[i])) {
6080: if (document.getElementById('hiddenresource_'+allidxs[i]).checked) {
6081: form.allhiddenresource.value += allidxs[i]+',';
6082: }
6083: }
6084: if (document.getElementById('encrypturl_'+allidxs[i])) {
6085: if (document.getElementById('encrypturl_'+allidxs[i]).checked) {
6086: form.allencrypturl.value += allidxs[i]+',';
6087: }
1.484.2.29 raeburn 6088: }
6089: }
1.484.2.30 raeburn 6090: form.allhiddenresource.value = form.allhiddenresource.value.replace(patt,"");
6091: form.allencrypturl.value = form.allencrypturl.value.replace(patt,"");
6092: }
6093: }
6094: form.allrandompick.value = '';
6095: form.allrandomorder.value = '';
6096: var allmapidxlist = document.cumulativesettings.allmapidx.value;
6097: if ((allmapidxlist != '') && (allmapidxlist != null)) {
6098: var allmapidxs = allmapidxlist.split(',');
6099: for (var i=0; i<allmapidxs.length; i++) {
6100: var randompick = document.getElementById('randompick_'+allmapidxs[i]);
6101: var rpicknum = document.getElementById('rpicknum_'+allmapidxs[i]);
6102: var randorder = document.getElementById('randomorder_'+allmapidxs[i]);
6103: if ((randompick.checked) && (rpicknum.value != '')) {
6104: form.allrandompick.value += allmapidxs[i]+':'+rpicknum.value+',';
6105: }
6106: if (randorder.checked) {
6107: form.allrandomorder.value += allmapidxs[i]+',';
6108: }
6109: }
6110: form.allrandompick.value = form.allrandompick.value.replace(patt,"");
6111: form.allrandomorder.value = form.allrandomorder.value.replace(patt,"");
6112: }
6113: if (document.cumulativesettings.currhiddenresource.value != form.allhiddenresource.value) {
6114: haschanges = 1;
6115: }
6116: if (document.cumulativesettings.currencrypturl.value != form.allencrypturl.value) {
6117: haschanges = 1;
6118: }
6119: if (document.cumulativesettings.currrandomorder.value != form.allrandomorder.value) {
6120: haschanges = 1;
6121: }
6122: if (document.cumulativesettings.currrandompick.value != form.allrandompick.value) {
6123: haschanges = 1;
6124: }
6125: }
6126: if (doactions == 1) {
6127: if (numchanges > 0) {
6128: if ((cutwarnings > 0) || (remwarnings > 0)) {
6129: if (remwarnings > 0) {
6130: if (!confirm('$lt{"p_rmr1"}\\n\\n$lt{"p_rmr3a"} '+remwarnings+' $lt{"p_rmr3b"}')) {
6131: return false;
6132: }
6133: }
6134: if (cutwarnings > 0) {
6135: if (!confirm('$lt{"p_ctr1a"}\\n$lt{"p_ctr1b"}\\n\\n$lt{"p_ctr3a"} '+cutwarnings+' $lt{"p_ctr3b"}')) {
6136: return false;
1.484.2.29 raeburn 6137: }
6138: }
6139: }
1.484.2.30 raeburn 6140: form.submit();
6141: return true;
6142: }
6143: }
6144: if (dosettings == 1) {
6145: if (haschanges == 1) {
6146: form.submit();
6147: return true;
1.484.2.29 raeburn 6148: }
6149: }
1.484.2.30 raeburn 6150: if ((dosettings == 1) && (doactions == 1)) {
6151: alert("$lt{'noor'}");
6152: } else {
6153: if (dosettings == 1) {
6154: alert("$lt{'noch'}");
6155: } else {
6156: alert("$lt{'noac'}");
6157: }
6158: }
6159: return false;
6160: }
6161:
6162: function setClass(value) {
6163: var cutclass = 'LC_docs_cut';
6164: var copyclass = 'LC_docs_copy';
6165: var removeclass = 'LC_docs_remove';
6166: var cutreg = new RegExp("\\\\b"+cutclass+"\\\\b");
6167: var copyreg = new RegExp("\\\\b"+copyclass+"\\\\b");
6168: var removereg = new RegExp("\\\\"+removeclass+"\\\\b");
6169: var links = document.getElementsByTagName('a');
6170: for (var i=0; i<links.length; i++) {
6171: var classes = links[i].className;
6172: if (cutreg.test(classes)) {
6173: links[i].className = cutclass;
6174: if (value == 1) {
6175: links[i].className += " LC_menubuttons_link";
1.484.2.29 raeburn 6176: }
1.484.2.30 raeburn 6177: } else {
6178: if (copyreg.test(classes)) {
6179: links[i].className = copyclass;
6180: if (value == 1) {
6181: links[i].className += " LC_menubuttons_link";
6182: }
6183: } else {
6184: if (removereg.test(classes)) {
6185: links[i].className = removeclass;
6186: if (value == 1) {
6187: links[i].className += " LC_menubuttons_link";
6188: }
6189: }
1.484.2.29 raeburn 6190: }
6191: }
6192: }
1.484.2.30 raeburn 6193: return;
1.484.2.29 raeburn 6194: }
6195:
1.484.2.30 raeburn 6196: function setBoxes(value) {
6197: var remidxlist = document.cumulativeactions.allremoveidx.value;
6198: if ((remidxlist != '') && (remidxlist != null)) {
6199: var remidxs = remidxlist.split(',');
6200: for (var i=0; i<remidxs.length; i++) {
6201: if (document.getElementById('remove_'+remidxs[i])) {
6202: var item = document.getElementById('remove_'+remidxs[i]);
6203: if (value == 1) {
6204: item.className = 'LC_docs_remove';
6205: } else {
6206: item.className = 'LC_hidden';
6207: }
6208: }
1.484.2.29 raeburn 6209: }
6210: }
1.484.2.30 raeburn 6211: var cutidxlist = document.cumulativeactions.allcutidx.value;
6212: if ((cutidxlist != '') && (cutidxlist != null)) {
6213: var cutidxs = cutidxlist.split(',');
6214: for (var i=0; i<cutidxs.length; i++) {
6215: if (document.getElementById('cut_'+cutidxs[i])) {
6216: var item = document.getElementById('cut_'+cutidxs[i]);
6217: if (value == 1) {
6218: item.className = 'LC_docs_cut';
6219: } else {
6220: item.className = 'LC_hidden';
6221: }
6222: }
6223: }
6224: }
6225: var copyidxlist = document.cumulativeactions.allcopyidx.value;
6226: if ((copyidxlist != '') && (copyidxlist != null)) {
6227: var copyidxs = copyidxlist.split(',');
6228: for (var i=0; i<copyidxs.length; i++) {
6229: if (document.getElementById('copy_'+copyidxs[i])) {
6230: var item = document.getElementById('copy_'+copyidxs[i]);
6231: if (value == 1) {
6232: item.className = 'LC_docs_copy';
6233: } else {
6234: item.className = 'LC_hidden';
6235: }
6236: }
1.484.2.29 raeburn 6237: }
6238: }
6239: return;
6240: }
6241:
1.329 droeschl 6242: ENDNEWSCRIPT
6243: }
1.457 raeburn 6244:
1.483 raeburn 6245: sub history_tab_js {
6246: return <<"ENDHIST";
6247: function toggleHistoryDisp(choice) {
6248: document.docslogform.docslog.value = choice;
6249: document.docslogform.submit();
6250: return;
6251: }
6252:
6253: ENDHIST
6254: }
6255:
1.484 raeburn 6256: sub inject_data_js {
6257: return <<ENDINJECT;
6258:
6259: function injectData(current, hiddenField, name, value) {
6260: currentElement = document.getElementById(hiddenField);
6261: currentElement.name = name;
6262: currentElement.value = value;
6263: current.submit();
6264: }
6265:
6266: ENDINJECT
6267: }
6268:
6269: sub dump_switchserver_js {
6270: my @hosts = @_;
6271: my %lt = &Apache::lonlocal::texthash(
6272: dump => 'Dumping to Authoring Space requires switching server.',
6273: swit => 'Switch server?',
6274: duco => 'Dump content to Authoring Space',
6275: yone => 'You need to switch to a server housing an Authoring Space for which you are author or co-author.',
6276: chos => 'Choose server',
6277: );
6278: my $role = $env{'request.role'};
6279: my $js = <<"ENDSWJS";
6280: <script type="text/javascript">
6281: function write_switchserver() {
6282: var server;
6283: if (document.setserver.posshosts.length > 0) {
6284: for (var i=0; i<document.setserver.posshosts.length; i++) {
6285: if (document.setserver.posshosts[i].checked) {
6286: server = document.setserver.posshosts[i].value;
6287: }
6288: }
6289: opener.document.location.href="/adm/switchserver?otherserver="+server+"&role=$role&origurl=/adm/coursedocs";
6290: }
6291: window.close();
6292: }
6293: </script>
6294:
6295: ENDSWJS
6296:
6297: my $startpage = &Apache::loncommon::start_page('Choose server',$js,
6298: {'only_body' => 1,
6299: 'js_ready' => 1,});
6300: my $endpage = &Apache::loncommon::end_page({'js_ready' => 1});
6301:
6302: my $hostpicker;
6303: my $count = 0;
6304: foreach my $host (sort(@hosts)) {
6305: my $checked;
6306: if ($count == 0) {
6307: $checked = ' checked="checked"';
6308: }
6309: $hostpicker .= '<label><input type="radio" name="posshosts" value="'.
6310: $host.'"'.$checked.' />'.$host.'</label> ';
6311: $count++;
6312: }
6313:
6314: return <<"ENDSWITCHJS";
6315:
6316: function dump_needs_switchserver(url) {
6317: if (url!='' && url!= null) {
6318: if (confirm("$lt{'dump'}\\n$lt{'swit'}")) {
6319: go(url);
6320: }
6321: }
6322: return;
6323: }
6324:
6325: function choose_switchserver_window() {
6326: newWindow = window.open('','ChooseServer','height=400,width=500,scrollbars=yes')
6327: newWindow.document.open();
6328: newWindow.document.writeln('$startpage');
6329: newWindow.document.write('<h3>$lt{'duco'}<\\/h3>\\n'+
6330: '<p>$lt{'yone'}<\\/p>\\n'+
6331: '<div class="LC_left_float"><fieldset><legend>$lt{'chos'}<\\/legend>\\n'+
6332: '<form name="setserver" method="post" action="" \\/>\\n'+
6333: '$hostpicker\\n'+
6334: '<br \\/><br \\/>\\n'+
6335: '<input type="button" name="makeswitch" value="$lt{'swit'}" '+
6336: 'onclick="write_switchserver();" \\/>\\n'+
6337: '<\\/form><\\/fieldset><\\/div><br clear="all" \\/>\\n');
6338: newWindow.document.writeln('$endpage');
6339: newWindow.document.close();
6340: newWindow.focus();
6341: }
6342:
6343: ENDSWITCHJS
6344: }
6345:
6346: sub makedocslogform {
6347: my ($formelems,$docslog) = @_;
6348: return <<"LOGSFORM";
6349: <form action="/adm/coursedocs" method="post" name="docslogform">
6350: <input type="hidden" name="docslog" value="$docslog" />
6351: $formelems
6352: </form>
6353: LOGSFORM
6354: }
6355:
6356: sub makesimpleeditform {
6357: my ($formelems) = @_;
6358: return <<"SIMPFORM";
6359: <form name="simpleedit" method="post" action="/adm/coursedocs">
6360: <input type="hidden" name="importdetail" value="" />
6361: $formelems
6362: </form>
6363: SIMPFORM
6364: }
6365:
1.329 droeschl 6366: 1;
6367: __END__
6368:
6369:
6370: =head1 NAME
6371:
6372: Apache::londocs.pm
6373:
6374: =head1 SYNOPSIS
6375:
6376: This is part of the LearningOnline Network with CAPA project
6377: described at http://www.lon-capa.org.
6378:
6379: =head1 SUBROUTINES
6380:
6381: =over
6382:
6383: =item %help=()
6384:
6385: Available help topics
6386:
6387: =item mapread()
6388:
1.344 bisitz 6389: Mapread read maps into LONCAPA::map:: global arrays
1.329 droeschl 6390: @order and @resources, determines status
6391: sets @order - pointer to resources in right order
6392: sets @resources - array with the resources with correct idx
6393:
6394: =item authorhosts()
6395:
6396: Return hash with valid author names
6397:
6398: =item clean()
6399:
6400: =item dumpcourse()
6401:
6402: Actually dump course
6403:
6404: =item group_import()
6405:
6406: Imports the given (name, url) resources into the course
6407: coursenum, coursedom, and folder must precede the list
6408:
6409: =item breadcrumbs()
6410:
6411: =item log_docs()
6412:
6413: =item docs_change_log()
6414:
6415: =item update_paste_buffer()
6416:
6417: =item print_paste_buffer()
6418:
6419: =item do_paste_from_buffer()
6420:
1.484.2.30 raeburn 6421: =item do_buffer_empty()
6422:
6423: =item clear_from_buffer()
6424:
1.484.2.7 raeburn 6425: =item get_newmap_url()
6426:
6427: =item dbcopy()
6428:
6429: =item uniqueness_check()
6430:
6431: =item contained_map_check()
6432:
6433: =item url_paste_fixups()
6434:
6435: =item apply_fixups()
6436:
6437: =item copy_dependencies()
6438:
1.329 droeschl 6439: =item update_parameter()
6440:
6441: =item handle_edit_cmd()
6442:
6443: =item editor()
6444:
6445: =item process_file_upload()
6446:
6447: =item process_secondary_uploads()
6448:
6449: =item is_supplemental_title()
6450:
6451: =item entryline()
6452:
6453: =item tiehash()
6454:
6455: =item untiehash()
6456:
6457: =item checkonthis()
6458:
6459: check on this
6460:
6461: =item verifycontent()
6462:
6463: Verify Content
6464:
6465: =item devalidateversioncache() & checkversions()
6466:
6467: Check Versions
6468:
6469: =item mark_hash_old()
6470:
6471: =item is_hash_old()
6472:
6473: =item changewarning()
6474:
6475: =item init_breadcrumbs()
6476:
6477: Breadcrumbs for special functions
6478:
1.484 raeburn 6479: =item create_list_elements()
6480:
6481: =item create_form_ul()
6482:
6483: =item startContentScreen()
6484:
6485: =item endContentScreen()
6486:
6487: =item supplemental_base()
6488:
6489: =item embedded_form_elems()
6490:
6491: =item embedded_destination()
6492:
6493: =item return_to_editor()
6494:
6495: =item decompression_info()
6496:
6497: =item decompression_phase_one()
6498:
6499: =item decompression_phase_two()
6500:
6501: =item remove_archive()
6502:
6503: =item generate_admin_menu()
6504:
6505: =item generate_edit_table()
6506:
6507: =item editing_js()
6508:
6509: =item history_tab_js()
6510:
6511: =item inject_data_js()
6512:
6513: =item dump_switchserver_js()
6514:
1.484.2.3 raeburn 6515: =item resize_scrollbox_js()
1.484 raeburn 6516:
6517: =item makedocslogform()
6518:
1.484.2.3 raeburn 6519: =item makesimpleeditform()
6520:
1.329 droeschl 6521: =back
6522:
6523: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>