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