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