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