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