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