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