Annotation of loncom/interface/londocs.pm, revision 1.508
1.329 droeschl 1: # The LearningOnline Network
2: # Documents
3: #
1.508 ! raeburn 4: # $Id: londocs.pm,v 1.507 2012/11/14 01:09:32 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 $plain='';
326: my $randompick=-1;
327: my $isencrypted=0;
328: my $ishidden=0;
329: my $is_random_order=0;
330: while (@folders) {
331: my $folder=shift(@folders);
332: my $foldername=shift(@folders);
333: if ($folderpath) {$folderpath.='&';}
334: $folderpath.=$folder.'&'.$foldername;
1.472 raeburn 335: my $url;
336: if ($allowed) {
337: $url = '/adm/coursedocs?folderpath=';
338: } else {
339: $url = '/adm/supplemental?folderpath=';
340: }
341: $url .= &escape($folderpath);
342: my $name=&unescape($foldername);
1.344 bisitz 343: # randompick number, hidden, encrypted, random order, is appended with ":"s to the foldername
1.472 raeburn 344: $name=~s/\:(\d*)\:(\w*)\:(\w*):(\d*)$//;
345: if ($1 ne '') {
346: $randompick=$1;
347: } else {
348: $randompick=-1;
349: }
350: if ($2) { $ishidden=1; }
351: if ($3) { $isencrypted=1; }
352: if ($4 ne '') { $is_random_order = 1; }
353: if ($folder eq 'supplemental') {
354: $name = &mt('Supplemental '.$crstype.' Content');
355: }
356: &Apache::lonhtmlcommon::add_breadcrumb(
1.499 raeburn 357: {'href'=>$url,
1.329 droeschl 358: 'title'=>$name,
1.367 droeschl 359: 'text'=>$name,
1.329 droeschl 360: 'no_mt'=>1,
361: });
362: $plain.=$name.' > ';
363: }
364: $plain=~s/\>\;\s*$//;
365: return (&Apache::lonhtmlcommon::breadcrumbs(undef,undef,0,'nohelp',
1.472 raeburn 366: undef, undef, 1 ),$randompick,$ishidden,
367: $isencrypted,$plain,$is_random_order);
1.329 droeschl 368: }
369:
370: sub log_docs {
1.494 raeburn 371: return &Apache::lonnet::write_log('course','docslog',@_);
1.329 droeschl 372: }
373:
374: {
375: my @oldresources=();
376: my @oldorder=();
377: my $parmidx;
378: my %parmaction=();
379: my %parmvalue=();
380: my $changedflag;
381:
382: sub snapshotbefore {
383: @oldresources=@LONCAPA::map::resources;
384: @oldorder=@LONCAPA::map::order;
385: $parmidx=undef;
386: %parmaction=();
387: %parmvalue=();
388: $changedflag=0;
389: }
390:
391: sub remember_parms {
392: my ($idx,$parameter,$action,$value)=@_;
393: $parmidx=$idx;
394: $parmaction{$parameter}=$action;
395: $parmvalue{$parameter}=$value;
396: $changedflag=1;
397: }
398:
399: sub log_differences {
400: my ($plain)=@_;
401: my %storehash=('folder' => $plain,
402: 'currentfolder' => $env{'form.folder'});
403: if ($parmidx) {
404: $storehash{'parameter_res'}=$oldresources[$parmidx];
405: foreach my $parm (keys(%parmaction)) {
406: $storehash{'parameter_action_'.$parm}=$parmaction{$parm};
407: $storehash{'parameter_value_'.$parm}=$parmvalue{$parm};
408: }
409: }
410: my $maxidx=$#oldresources;
411: if ($#LONCAPA::map::resources>$#oldresources) {
412: $maxidx=$#LONCAPA::map::resources;
413: }
414: for (my $idx=0; $idx<=$maxidx; $idx++) {
415: if ($LONCAPA::map::resources[$idx] ne $oldresources[$idx]) {
416: $storehash{'before_resources_'.$idx}=$oldresources[$idx];
417: $storehash{'after_resources_'.$idx}=$LONCAPA::map::resources[$idx];
418: $changedflag=1;
419: }
420: if ($LONCAPA::map::order[$idx] ne $oldorder[$idx]) {
421: $storehash{'before_order_res_'.$idx}=$oldresources[$oldorder[$idx]];
422: $storehash{'after_order_res_'.$idx}=$LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
423: $changedflag=1;
424: }
425: }
426: $storehash{'maxidx'}=$maxidx;
427: if ($changedflag) { &log_docs(\%storehash); }
428: }
429: }
430:
431: sub docs_change_log {
1.484 raeburn 432: my ($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath)=@_;
1.486 raeburn 433: my $supplementalflag=($env{'form.folderpath'}=~/^supplemental/);
1.483 raeburn 434: my $js = '<script type="text/javascript">'."\n".
435: '// <![CDATA['."\n".
436: &Apache::loncommon::display_filter_js('docslog')."\n".
1.486 raeburn 437: &editing_js($env{'user.domain'},$env{'user.name'},$supplementalflag)."\n".
1.483 raeburn 438: &history_tab_js()."\n".
1.484 raeburn 439: &Apache::lonratedt::editscript('simple')."\n".
1.483 raeburn 440: '// ]]>'."\n".
441: '</script>'."\n";
1.484 raeburn 442: $r->print(&Apache::loncommon::start_page('Content Change Log',$js));
443: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Change Log'));
1.489 raeburn 444: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.484 raeburn 445: my %orderhash;
446: my $container='sequence';
447: my $pathitem;
448: if ($env{'form.pagepath'}) {
449: $container='page';
450: $pathitem = '<input type="hidden" name="pagepath" value="'.
451: &HTML::Entities::encode($env{'form.pagepath'},'<>&"').'" />';
452: } else {
453: my $folderpath=$env{'form.folderpath'};
454: if ($folderpath eq '') {
455: $folderpath = 'default&'.&escape(&mt('Main '.$crstype.' Documents'));
456: }
1.508 ! raeburn 457: $pathitem = '<input type="hidden" name="folderpath" value="'.
! 458: &HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 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.508 ! raeburn 1747: $supplementalflag,$orderhash,$iconpath,$pathitem)=@_;
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);
1.504 raeburn 1832: if ($url=~ m{^\Q/uploaded/$coursedom/$coursenum/\E(default|supplemental)_new\.(sequence|page)$}) {
1833: my ($suffix,$errortxt,$locknotfreed) =
1834: &newmap_suffix($1,$2,$coursedom,$coursenum);
1835: if ($locknotfreed) {
1836: $r->print($locknotfreed);
1837: }
1838: if ($suffix) {
1839: $url =~ s/_new\./_$suffix./;
1840: } else {
1841: return $errortxt;
1842: }
1843: }
1.329 droeschl 1844: push(@imports, [$name, $url, $residx]);
1845: }
1846: }
1847: ($errtext,$fatal)=&group_import($coursenum, $coursedom, $folder,
1848: $container,'londocs',@imports);
1849: return $errtext if ($fatal);
1850: }
1851: # Loading a complete map
1852: if ($env{'form.loadmap'}) {
1853: if ($env{'form.importmap'}=~/\w/) {
1854: foreach my $res (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
1855: my ($title,$url,$ext,$type)=split(/\:/,$res);
1856: my $idx=&LONCAPA::map::getresidx($url);
1857: $LONCAPA::map::resources[$idx]=$res;
1858: $LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx;
1859: }
1860: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.492 raeburn 1861: $folder.'.'.$container,1);
1.329 droeschl 1862: return $errtext if ($fatal);
1863: } else {
1864: $r->print('<p><span class="LC_error">'.&mt('No map selected.').'</span></p>');
1.364 bisitz 1865:
1.329 droeschl 1866: }
1867: }
1868: &log_differences($plain);
1869: }
1870: # ---------------------------------------------------------------- End commands
1871: # ---------------------------------------------------------------- Print screen
1872: my $idx=0;
1873: my $shown=0;
1874: if (($ishidden) || ($isencrypted) || ($randompick>=0) || ($is_random_order)) {
1.381 bisitz 1875: $r->print('<div class="LC_Box">'.
1.432 raeburn 1876: '<ol class="LC_docs_parameters"><li class="LC_docs_parameters_title">'.&mt('Parameters:').'</li>'.
1877: ($randompick>=0?'<li>'.&mt('randomly pick [quant,_1,resource]',$randompick).'</li>':'').
1878: ($ishidden?'<li>'.&mt('contents hidden').'</li>':'').
1879: ($isencrypted?'<li>'.&mt('URLs hidden').'</li>':'').
1880: ($is_random_order?'<li>'.&mt('random order').'</li>':'').
1.431 raeburn 1881: '</ol>');
1.381 bisitz 1882: if ($randompick>=0) {
1883: $r->print('<p class="LC_warning">'
1884: .&mt('Caution: this folder is set to randomly pick a subset'
1885: .' of resources. Adding or removing resources from this'
1886: .' folder will change the set of resources that the'
1887: .' students see, resulting in spurious or missing credit'
1888: .' for completed problems, not limited to ones you'
1889: .' modify. Do not modify the contents of this folder if'
1890: .' it is in active student use.')
1891: .'</p>'
1892: );
1893: }
1894: if ($is_random_order) {
1895: $r->print('<p class="LC_warning">'
1896: .&mt('Caution: this folder is set to randomly order its'
1897: .' contents. Adding or removing resources from this folder'
1898: .' will change the order of resources shown.')
1899: .'</p>'
1900: );
1901: }
1902: $r->print('</div>');
1.364 bisitz 1903: }
1.381 bisitz 1904:
1.458 raeburn 1905: my ($to_show,$output);
1.424 onken 1906:
1907: &Apache::loncommon::start_data_table_count(); #setup a row counter
1.381 bisitz 1908: foreach my $res (@LONCAPA::map::order) {
1909: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
1910: $name=&LONCAPA::map::qtescape($name);
1911: $url=&LONCAPA::map::qtescape($url);
1912: unless ($name) { $name=(split(/\//,$url))[-1]; }
1913: unless ($name) { $idx++; next; }
1914: $output .= &entryline($idx,$name,$url,$folder,$allowed,$res,
1.501 raeburn 1915: $coursenum,$coursedom,$crstype,
1.508 ! raeburn 1916: $pathitem,$supplementalflag);
1.381 bisitz 1917: $idx++;
1918: $shown++;
1.329 droeschl 1919: }
1.424 onken 1920: &Apache::loncommon::end_data_table_count();
1921:
1.381 bisitz 1922: if ($shown) {
1.458 raeburn 1923: $to_show = &Apache::loncommon::start_scrollbox('900px','880px','400px','contentscroll')
1924: .&Apache::loncommon::start_data_table(undef,'contentlist');
1.393 raeburn 1925: if ($allowed) {
1.458 raeburn 1926: $to_show .= &Apache::loncommon::start_data_table_header_row()
1.393 raeburn 1927: .'<th colspan="2">'.&mt('Move').'</th>'
1928: .'<th>'.&mt('Actions').'</th>'
1.458 raeburn 1929: .'<th colspan="2">'.&mt('Document').'</th>';
1.393 raeburn 1930: if ($folder !~ /^supplemental/) {
1.458 raeburn 1931: $to_show .= '<th colspan="4">'.&mt('Settings').'</th>';
1.393 raeburn 1932: }
1.458 raeburn 1933: $to_show .= &Apache::loncommon::end_data_table_header_row();
1.393 raeburn 1934: }
1.458 raeburn 1935: $to_show .= $output.' '
1.393 raeburn 1936: .&Apache::loncommon::end_data_table()
1.458 raeburn 1937: .'<br style="line-height:2px;" />'
1938: .&Apache::loncommon::end_scrollbox();
1.393 raeburn 1939: } else {
1.458 raeburn 1940: $to_show .= &Apache::loncommon::start_scrollbox('400px','380px','200px','contentscroll')
1941: .'<div class="LC_info" id="contentlist">'
1.381 bisitz 1942: .&mt('Currently no documents.')
1.458 raeburn 1943: .'</div>'
1944: .&Apache::loncommon::end_scrollbox();
1945: }
1946: my $tid = 1;
1947: if ($supplementalflag) {
1948: $tid = 2;
1.329 droeschl 1949: }
1950: if ($allowed) {
1.484 raeburn 1951: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
1952: $r->print(&generate_edit_table($tid,$orderhash,$to_show,$iconpath,$jumpto,
1953: $readfile));
1.492 raeburn 1954: &print_paste_buffer($r,$container,$folder,$coursedom,$coursenum);
1.460 raeburn 1955: } else {
1.472 raeburn 1956: if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
1957: #Function Box for Supplemental Content for users with mdc priv.
1958: my $funcname = &mt('Folder Editor');
1959: $r->print(
1960: &Apache::loncommon::head_subbox(
1961: &Apache::lonhtmlcommon::start_funclist().
1962: &Apache::lonhtmlcommon::add_item_funclist(
1963: '<a href="/adm/coursedocs?command=direct&forcesupplement=1&'.
1964: 'supppath='.&HTML::Entities::encode($env{'form.folderpath'}).'">'.
1.506 raeburn 1965: '<img src="/res/adm/pages/docs-22x22.png" alt="'.$funcname.'" class="LC_icon" />'.
1.472 raeburn 1966: '<span class="LC_menubuttons_inline_text">'.$funcname.'</span></a>').
1967: &Apache::lonhtmlcommon::end_funclist()));
1968: }
1.460 raeburn 1969: $r->print($to_show);
1.329 droeschl 1970: }
1971: return;
1972: }
1973:
1974: sub process_file_upload {
1975: my ($upload_output,$coursenum,$coursedom,$allfiles,$codebase,$uploadcmd) = @_;
1976: # upload a file, if present
1.440 raeburn 1977: my ($parseaction,$showupload,$nextphase,$mimetype);
1978: if ($env{'form.parserflag'}) {
1.329 droeschl 1979: $parseaction = 'parse';
1980: }
1981: my $folder=$env{'form.folder'};
1982: if ($folder eq '') {
1983: $folder='default';
1984: }
1985: if ( ($folder=~/^$uploadcmd/) || ($uploadcmd eq 'default') ) {
1986: my $errtext='';
1987: my $fatal=0;
1988: my $container='sequence';
1989: if ($env{'form.pagepath'}) {
1990: $container='page';
1991: }
1992: ($errtext,$fatal)=
1993: &mapread($coursenum,$coursedom,$folder.'.'.$container);
1994: if ($#LONCAPA::map::order<1) {
1995: $LONCAPA::map::order[0]=1;
1996: $LONCAPA::map::resources[1]='';
1997: }
1998: if ($fatal) {
1.457 raeburn 1999: $$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 2000: return;
1.329 droeschl 2001: }
2002: my $destination = 'docs/';
2003: if ($folder =~ /^supplemental/) {
2004: $destination = 'supplemental/';
2005: }
2006: if (($folder eq 'default') || ($folder eq 'supplemental')) {
2007: $destination .= 'default/';
2008: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
2009: $destination .= $2.'/';
2010: }
1.440 raeburn 2011: # this is for a course, not a user, so set context to coursedoc.
1.329 droeschl 2012: my $newidx=&LONCAPA::map::getresidx();
2013: $destination .= $newidx;
1.439 raeburn 2014: my $url=&Apache::lonnet::userfileupload('uploaddoc','coursedoc',$destination,
1.329 droeschl 2015: $parseaction,$allfiles,
1.440 raeburn 2016: $codebase,undef,undef,undef,undef,
2017: undef,undef,\$mimetype);
2018: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E.*/([^/]+)$}) {
2019: my $stored = $1;
2020: $showupload = '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
2021: $stored.'</span>').'</p>';
2022: } else {
2023: my ($filename) = ($env{'form.uploaddoc.filename'} =~ m{([^/]+)$});
2024:
1.457 raeburn 2025: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.&mt('Unable to save file [_1].','<span class="LC_filename">'.$filename.'</span>').'</div>';
1.440 raeburn 2026: return;
2027: }
1.329 droeschl 2028: my $ext='false';
2029: if ($url=~m{^http://}) { $ext='true'; }
2030: $url = &LONCAPA::map::qtunescape($url);
2031: my $comment=$env{'form.comment'};
2032: $comment = &LONCAPA::map::qtunescape($comment);
2033: if ($folder=~/^supplemental/) {
2034: $comment=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
2035: $env{'user.domain'}.'___&&&___'.$comment;
2036: }
2037:
2038: $LONCAPA::map::resources[$newidx]=
2039: $comment.':'.$url.':'.$ext.':normal:res';
2040: $LONCAPA::map::order[$#LONCAPA::map::order+1]= $newidx;
2041: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.492 raeburn 2042: $folder.'.'.$container,1);
1.329 droeschl 2043: if ($fatal) {
1.457 raeburn 2044: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.$errtext.'</div>';
1.440 raeburn 2045: return;
1.329 droeschl 2046: } else {
1.440 raeburn 2047: if ($parseaction eq 'parse' && $mimetype eq 'text/html') {
2048: $$upload_output = $showupload;
1.384 raeburn 2049: my $total_embedded = scalar(keys(%{$allfiles}));
1.329 droeschl 2050: if ($total_embedded > 0) {
1.440 raeburn 2051: my $uploadphase = 'upload_embedded';
2052: my $primaryurl = &HTML::Entities::encode($url,'<>&"');
2053: my $state = &embedded_form_elems($uploadphase,$primaryurl,$newidx);
2054: my ($embedded,$num) =
2055: &Apache::loncommon::ask_for_embedded_content(
2056: '/adm/coursedocs',$state,$allfiles,$codebase,{'docs_url' => $url});
2057: if ($embedded) {
2058: if ($num) {
2059: $$upload_output .=
2060: '<p>'.&mt('This file contains embedded multimedia objects, which need to be uploaded.').'</p>'.$embedded;
2061: $nextphase = $uploadphase;
2062: } else {
2063: $$upload_output .= $embedded;
2064: }
2065: } else {
2066: $$upload_output .= &mt('Embedded item(s) already present, so no additional upload(s) required').'<br />';
2067: }
1.329 droeschl 2068: } else {
1.440 raeburn 2069: $$upload_output .= &mt('No embedded items identified').'<br />';
1.329 droeschl 2070: }
1.457 raeburn 2071: $$upload_output = '<div id="uploadfileresult">'.$$upload_output.'</div>';
1.476 raeburn 2072: } elsif (&Apache::loncommon::is_archive_file($mimetype)) {
2073: $nextphase = 'decompress_uploaded';
2074: my $position = scalar(@LONCAPA::map::order)-1;
2075: my $noextract = &return_to_editor();
2076: my $archiveurl = &HTML::Entities::encode($url,'<>&"');
2077: my %archiveitems = (
2078: folderpath => $env{'form.folderpath'},
2079: pagepath => $env{'form.pagepath'},
2080: cmd => $nextphase,
2081: newidx => $newidx,
2082: position => $position,
2083: phase => $nextphase,
1.477 raeburn 2084: comment => $comment,
1.480 raeburn 2085: );
2086: my ($destination,$dir_root) = &embedded_destination($coursenum,$coursedom);
2087: my @current = &get_dir_list($url,$coursenum,$coursedom,$newidx);
1.476 raeburn 2088: $$upload_output = $showupload.
2089: &Apache::loncommon::decompress_form($mimetype,
2090: $archiveurl,'/adm/coursedocs',$noextract,
1.480 raeburn 2091: \%archiveitems,\@current);
1.329 droeschl 2092: }
2093: }
2094: }
1.440 raeburn 2095: return $nextphase;
1.329 droeschl 2096: }
2097:
1.480 raeburn 2098: sub get_dir_list {
2099: my ($url,$coursenum,$coursedom,$newidx) = @_;
2100: my ($destination,$dir_root) = &embedded_destination();
2101: my ($dirlistref,$listerror) =
2102: &Apache::lonnet::dirlist("$dir_root/$destination/$newidx",$coursedom,$coursenum,1);
2103: my @dir_lines;
2104: my $dirptr=16384;
2105: if (ref($dirlistref) eq 'ARRAY') {
2106: foreach my $dir_line (sort
2107: {
2108: my ($afile)=split('&',$a,2);
2109: my ($bfile)=split('&',$b,2);
2110: return (lc($afile) cmp lc($bfile));
2111: } (@{$dirlistref})) {
2112: my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$dir_line,16);
2113: $filename =~ s/\s+$//;
2114: next if ($filename =~ /^\.\.?$/);
2115: my $isdir = 0;
2116: if ($dirptr&$testdir) {
2117: $isdir = 1;
2118: }
2119: push(@dir_lines, [$filename,$dom,$isdir,$size,$mtime,$obs]);
2120: }
2121: }
2122: return @dir_lines;
2123: }
2124:
1.329 droeschl 2125: sub is_supplemental_title {
2126: my ($title) = @_;
2127: return scalar($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/);
2128: }
2129:
2130: # --------------------------------------------------------------- An entry line
2131:
2132: sub entryline {
1.501 raeburn 2133: my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$coursedom,
1.508 ! raeburn 2134: $crstype,$pathitem,$supplementalflag)=@_;
1.329 droeschl 2135: my ($foldertitle,$pagetitle,$renametitle);
2136: if (&is_supplemental_title($title)) {
1.488 raeburn 2137: ($title,$foldertitle,$renametitle) = &Apache::loncommon::parse_supplemental_title($title);
1.329 droeschl 2138: $pagetitle = $foldertitle;
2139: } else {
2140: $title=&HTML::Entities::encode($title,'"<>&\'');
2141: $renametitle=$title;
2142: $foldertitle=$title;
2143: $pagetitle=$title;
2144: }
2145:
2146: my $orderidx=$LONCAPA::map::order[$index];
1.364 bisitz 2147:
1.329 droeschl 2148: $renametitle=~s/\\/\\\\/g;
2149: $renametitle=~s/\"\;/\\\"/g;
2150: $renametitle=~s/ /%20/g;
1.379 bisitz 2151: my $line=&Apache::loncommon::start_data_table_row();
1.478 raeburn 2152: my ($form_start,$form_end,$form_common);
1.329 droeschl 2153: # Edit commands
2154: my ($container, $type, $esc_path, $path, $symb);
2155: if ($env{'form.folderpath'}) {
2156: $type = 'folder';
2157: $container = 'sequence';
2158: $esc_path=&escape($env{'form.folderpath'});
2159: $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
2160: # $htmlfoldername=&HTML::Entities::encode($env{'form.foldername'},'<>&"');
2161: }
2162: if ($env{'form.pagepath'}) {
2163: $type = $container = 'page';
1.440 raeburn 2164: $esc_path=&escape($env{'form.pagepath'});
1.329 droeschl 2165: $path = &HTML::Entities::encode($env{'form.pagepath'},'<>&"');
2166: }
1.505 raeburn 2167: my $isexternal;
1.501 raeburn 2168: if (!$supplementalflag && $residx) {
2169: my $currurl = $url;
2170: $currurl =~ s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
1.505 raeburn 2171: if ($currurl =~ m{^/adm/wrapper/ext/}) {
2172: $isexternal = 1;
2173: }
1.501 raeburn 2174: my $path = 'uploaded/'.
2175: $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
2176: $env{'course.'.$env{'request.course.id'}.'.num'}.'/';
2177: $symb = &Apache::lonnet::encode_symb($path.$folder.".$container",
2178: $residx,
2179: &Apache::lonnet::declutter($currurl));
2180: }
2181: my %lt;
1.329 droeschl 2182: if ($allowed) {
2183: my $incindex=$index+1;
2184: my $selectbox='';
1.471 raeburn 2185: if (($#LONCAPA::map::order>0) &&
1.329 droeschl 2186: ((split(/\:/,
1.344 bisitz 2187: $LONCAPA::map::resources[$LONCAPA::map::order[0]]))[1]
2188: ne '') &&
1.329 droeschl 2189: ((split(/\:/,
1.344 bisitz 2190: $LONCAPA::map::resources[$LONCAPA::map::order[1]]))[1]
1.329 droeschl 2191: ne '')) {
2192: $selectbox=
2193: '<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
1.373 bisitz 2194: '<select name="newpos" onchange="this.form.submit()">';
1.329 droeschl 2195: for (my $i=1;$i<=$#LONCAPA::map::order+1;$i++) {
2196: if ($i==$incindex) {
1.358 bisitz 2197: $selectbox.='<option value="" selected="selected">('.$i.')</option>';
1.329 droeschl 2198: } else {
2199: $selectbox.='<option value="'.$i.'">'.$i.'</option>';
2200: }
2201: }
2202: $selectbox.='</select>';
2203: }
1.501 raeburn 2204: %lt=&Apache::lonlocal::texthash(
1.329 droeschl 2205: 'up' => 'Move Up',
2206: 'dw' => 'Move Down',
2207: 'rm' => 'Remove',
2208: 'ct' => 'Cut',
2209: 'rn' => 'Rename',
1.501 raeburn 2210: 'cp' => 'Copy',
2211: 'ex' => 'External Resource',
2212: 'ed' => 'Edit',
2213: 'pr' => 'Preview',
2214: 'sv' => 'Save',
2215: 'ul' => 'URL',
2216: 'ti' => 'Title',
2217: );
1.329 droeschl 2218: my $nocopy=0;
2219: my $nocut=0;
1.497 raeburn 2220: my $noremove=0;
1.492 raeburn 2221: if ($url=~ m{^/res/.+\.(page|sequence)$}) {
2222: # no copy for published maps
2223: $nocopy=1;
1.329 droeschl 2224: }
1.344 bisitz 2225: if ($url=~/^\/res\/lib\/templates\//) {
2226: $nocopy=1;
1.329 droeschl 2227: $nocut=1;
2228: }
1.497 raeburn 2229: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2230: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2231: if ($url eq "/uploaded/$cdom/$cnum/group_allfolders.sequence") {
2232: if ($env{'form.folderpath'} =~ /^default&[^\&]+$/) {
2233: my %curr_groups = &Apache::longroup::coursegroups();
2234: if (keys(%curr_groups) > 0) {
2235: $noremove=1;
2236: }
2237: $nocut=1;
2238: $nocopy=1;
2239: }
2240: } elsif ($url =~ m{^\Q/uploaded/$cdom/$cnum/group_folder_\E(\w+)\.sequence$}) {
2241: my $group = $1;
2242: if ($env{'form.folderpath'} =~ /^default&[^\&]+\&group_allfolders\&[^\&]+$/) {
2243: my %curr_group = &Apache::longroup::coursegroups($cdom,$cnum,$group);
2244: if (keys(%curr_group) > 0) {
2245: $noremove=1;
2246: }
2247: }
2248: $nocut=1;
2249: $nocopy=1;
2250: } elsif ($url =~ m{^\Q/adm/$cdom/$cnum/\E(\w+)/smppg$}) {
2251: my $group = $1;
2252: if ($env{'form.folderpath'} =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&\Qgroup_folder_$group\E\&[^\&]+$/) {
2253: my %curr_group = &Apache::longroup::coursegroups($cdom,$cnum,$group);
2254: my %groupsettings = &Apache::longroup::get_group_settings($curr_group{$group});
2255: if (keys(%groupsettings) > 0) {
2256: $noremove=1;
2257: }
2258: $nocut=1;
2259: $nocopy=1;
2260: }
2261: } elsif ($env{'form.folderpath'} =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&group_folder_(\w+)\&/) {
2262: my $group = $1;
2263: my %curr_group = &Apache::longroup::coursegroups($cdom,$cnum,$group);
2264: if ($url =~ /group_boards_\Q$group\E/) {
2265: my %curr_group = &Apache::longroup::coursegroups($cdom,$cnum,$group);
2266: my %groupsettings = &Apache::longroup::get_group_settings($curr_group{$group});
2267: if (keys(%groupsettings) > 0) {
2268: if (ref($groupsettings{'functions'}) eq 'HASH') {
2269: if ($groupsettings{'functions'}{'discussion'} eq 'on') {
2270: $noremove=1;
2271: }
2272: }
2273: }
2274: $nocut=1;
2275: $nocopy=1;
2276: }
2277: }
1.507 raeburn 2278: my ($copylink,$cutlink,$removelink,$renamelink);
1.329 droeschl 2279: my $skip_confirm = 0;
2280: if ( $folder =~ /^supplemental/
2281: || ($url =~ m{( /smppg$
2282: |/syllabus$
2283: |/aboutme$
2284: |/navmaps$
2285: |/bulletinboard$
1.505 raeburn 2286: |\.html$)}x)
2287: || $isexternal) {
1.329 droeschl 2288: $skip_confirm = 1;
2289: }
2290:
1.508 ! raeburn 2291: if ($nocopy) {
1.507 raeburn 2292: $copylink=(<<ENDCOPY);
2293: <span style="visibility: hidden;">$lt{'cp'}</span>
2294: ENDCOPY
2295: } else {
1.329 droeschl 2296: $copylink=(<<ENDCOPY);
1.484 raeburn 2297: <a href="javascript:markcopy('$esc_path','$index','$renametitle','$container','$symb','$folder');" class="LC_docs_copy">$lt{'cp'}</a>
1.329 droeschl 2298: ENDCOPY
2299: }
1.508 ! raeburn 2300: if ($nocut) {
1.507 raeburn 2301: $cutlink=(<<ENDCUT);
2302: <span style="visibility: hidden;">$lt{'ct'}</span>
2303: ENDCUT
2304: } else {
1.329 droeschl 2305: $cutlink=(<<ENDCUT);
1.484 raeburn 2306: <a href="javascript:cutres('$esc_path','$index','$renametitle','$container','$symb','$folder',$skip_confirm);" class="LC_docs_cut">$lt{'ct'}</a>
1.329 droeschl 2307: ENDCUT
2308: }
1.507 raeburn 2309: if ($noremove) {
2310: $removelink=(<<ENDREM);
2311: <span style="visibility: hidden;">$lt{'rm'}</a>
2312: ENDREM
2313: } else {
1.497 raeburn 2314: $removelink=(<<ENDREM);
2315: <a href='javascript:removeres("$esc_path","$index","$renametitle","$container","$symb",$skip_confirm);' class="LC_docs_remove">$lt{'rm'}</a>
2316: ENDREM
2317: }
1.507 raeburn 2318: $renamelink=(<<ENDREN);
2319: <a href='javascript:changename("$esc_path","$index","$renametitle","$container","$symb");' class="LC_docs_rename">$lt{'rn'}</a>
2320: ENDREN
1.478 raeburn 2321: $form_start = '
2322: <form action="/adm/coursedocs" method="post">
2323: ';
2324: $form_common=(<<END);
1.329 droeschl 2325: <input type="hidden" name="${type}path" value="$path" />
2326: <input type="hidden" name="${type}symb" value="$symb" />
2327: <input type="hidden" name="setparms" value="$orderidx" />
2328: <input type="hidden" name="changeparms" value="0" />
2329: END
2330: $form_end = '</form>';
2331: $line.=(<<END);
2332: <td>
1.379 bisitz 2333: <div class="LC_docs_entry_move">
1.499 raeburn 2334: <a href='/adm/coursedocs?cmd=up_$index&${type}path=$esc_path&${type}symb=$symb'>
1.501 raeburn 2335: <img src="${iconpath}move_up.gif" alt="$lt{'up'}" class="LC_icon" />
1.379 bisitz 2336: </a>
2337: </div>
2338: <div class="LC_docs_entry_move">
1.499 raeburn 2339: <a href='/adm/coursedocs?cmd=down_$index&${type}path=$esc_path&${type}symb=$symb'>
1.501 raeburn 2340: <img src="${iconpath}move_down.gif" alt="$lt{'dw'}" class="LC_icon" />
1.379 bisitz 2341: </a>
2342: </div>
1.329 droeschl 2343: </td>
2344: <td>
2345: $form_start
1.478 raeburn 2346: $form_common
1.329 droeschl 2347: $selectbox
2348: $form_end
2349: </td>
1.507 raeburn 2350: <td class="LC_docs_entry_commands"><span class="LC_nobreak">
1.497 raeburn 2351: $removelink
1.507 raeburn 2352: $renamelink
1.329 droeschl 2353: $cutlink
2354: $copylink
1.507 raeburn 2355: </span>
1.329 droeschl 2356: </td>
2357: END
2358:
2359: }
2360: # Figure out what kind of a resource this is
2361: my ($extension)=($url=~/\.(\w+)$/);
2362: my $uploaded=($url=~/^\/*uploaded\//);
2363: my $icon=&Apache::loncommon::icon($url);
2364: my $isfolder=0;
2365: my $ispage=0;
2366: my $folderarg;
2367: my $pagearg;
2368: my $pagefile;
2369: if ($uploaded) {
1.472 raeburn 2370: if (($extension eq 'sequence') || ($extension eq 'page')) {
2371: $url=~/\Q$coursenum\E\/([\/\w]+)\.\Q$extension\E$/;
2372: my $containerarg = $1;
2373: if ($extension eq 'sequence') {
2374: $icon=$iconpath.'navmap.folder.closed.gif';
2375: $folderarg=$containerarg;
2376: $isfolder=1;
2377: } else {
2378: $icon=$iconpath.'page.gif';
2379: $pagearg=$containerarg;
2380: $ispage=1;
2381: }
2382: if ($allowed) {
2383: $url='/adm/coursedocs?';
2384: } else {
2385: $url='/adm/supplemental?';
2386: }
1.329 droeschl 2387: } else {
2388: &Apache::lonnet::allowuploaded('/adm/coursedoc',$url);
2389: }
2390: }
1.364 bisitz 2391:
1.501 raeburn 2392: my $editlink;
1.329 droeschl 2393: my $orig_url = $url;
1.340 raeburn 2394: $orig_url=~s{http(:|:)//https(:|:)//}{https$2//};
1.329 droeschl 2395: my $external = ($url=~s{^http(|s)(:|:)//}{/adm/wrapper/ext/});
1.501 raeburn 2396: if (!$supplementalflag && $residx && $symb) {
2397: if ($container eq 'page') {
2398: $url=&Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
2399: $url.=(($url=~/\?/)?'&':'?').'symb='.&escape($symb);
2400: }
2401: if ((!$isfolder) && (!$ispage)) {
2402: (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
2403: $url=&Apache::lonnet::clutter($url);
2404: if ($url=~/^\/*uploaded\//) {
2405: $url=~/\.(\w+)$/;
2406: my $embstyle=&Apache::loncommon::fileembstyle($1);
2407: if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
2408: $url='/adm/wrapper'.$url;
2409: } elsif ($embstyle eq 'ssi') {
2410: #do nothing with these
2411: } elsif ($url!~/\.(sequence|page)$/) {
2412: $url='/adm/coursedocs/showdoc'.$url;
2413: }
2414: } elsif ($url=~m|^/ext/|) {
2415: $url='/adm/wrapper'.$url;
2416: $external = 1;
1.329 droeschl 2417: }
1.501 raeburn 2418: if (&Apache::lonnet::symbverify($symb,$url)) {
2419: $url.=(($url=~/\?/)?'&':'?').'symb='.&escape($symb);
2420: } else {
2421: $url='';
2422: }
1.329 droeschl 2423: }
2424: }
1.478 raeburn 2425: my ($rand_pick_text,$rand_order_text);
1.329 droeschl 2426: if ($isfolder || $extension eq 'sequence') {
2427: my $foldername=&escape($foldertitle);
2428: my $folderpath=$env{'form.folderpath'};
2429: if ($folderpath) { $folderpath.='&' };
1.344 bisitz 2430: # Append randompick number, hidden, and encrypted with ":" to foldername,
1.329 droeschl 2431: # so it gets transferred between levels
2432: $folderpath.=$folderarg.'&'.$foldername.':'.(&LONCAPA::map::getparameter($orderidx,
2433: 'parameter_randompick'))[0]
2434: .':'.((&LONCAPA::map::getparameter($orderidx,
2435: 'parameter_hiddenresource'))[0]=~/^yes$/i)
2436: .':'.((&LONCAPA::map::getparameter($orderidx,
2437: 'parameter_encrypturl'))[0]=~/^yes$/i)
2438: .':'.((&LONCAPA::map::getparameter($orderidx,
2439: 'parameter_randomorder'))[0]=~/^yes$/i);
1.499 raeburn 2440: $url.='folderpath='.&escape($folderpath);
1.478 raeburn 2441: my $rpicknum = (&LONCAPA::map::getparameter($orderidx,
2442: 'parameter_randompick'))[0];
2443: my $rpckchk;
2444: if ($rpicknum) {
2445: $rpckchk = ' checked="checked"';
2446: }
2447: my $formname = 'edit_rpick_'.$orderidx;
2448: $rand_pick_text =
2449: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
2450: $form_common."\n".
2451: '<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.'" />';
2452: if ($rpicknum ne '') {
2453: $rand_pick_text .= ': <a href="javascript:updatePick('."document.$formname,'$orderidx','link'".')">'.$rpicknum.'</a>';
2454: }
2455: $rand_pick_text .= '</span></form>';
1.329 droeschl 2456: my $ro_set=
2457: ((&LONCAPA::map::getparameter($orderidx,'parameter_randomorder'))[0]=~/^yes$/i?' checked="checked"':'');
1.478 raeburn 2458: $rand_order_text =
2459: $form_start.
2460: $form_common.'
2461: <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 2462: }
2463: if ($ispage) {
2464: my $pagename=&escape($pagetitle);
2465: my $pagepath;
2466: my $folderpath=$env{'form.folderpath'};
2467: if ($folderpath) { $pagepath = $folderpath.'&' };
2468: $pagepath.=$pagearg.'&'.$pagename;
2469: $url.='pagepath='.&escape($pagepath).
1.499 raeburn 2470: '&pagesymb='.&escape($symb);
1.329 droeschl 2471: }
1.501 raeburn 2472: if ($allowed) {
2473: my $fileloc =
2474: &Apache::lonnet::declutter(&Apache::lonnet::filelocation('',$orig_url));
2475:
2476: if ($external) {
2477: $editlink = <<"EXTLNK";
2478:
2479: <a class="LC_docs_ext_edit" href="javascript:editext('$residx');">
2480: $lt{'ed'}</a>
2481: <form action="/adm/coursedocs" method="post" name="editext_$residx">
2482: <fieldset id="uploadext$residx" style="display: none;" />
2483: <input type="hidden" name="active" value="aa" />
2484: <span class="LC_nobreak">
2485: <span class="LC_docs_ext_edit">$lt{'ul'} </span>
2486: <input type="text" size="40" name="exturl" id="exturl_$residx" value="$orig_url" />
2487: <a class="LC_docs_ext_edit" href="javascript:extUrlPreview('exturl_$residx');">$lt{'pr'}</a></span>
2488: </span><br />
2489: <span class="LC_nobreak">
2490: <span class="LC_docs_ext_edit">$lt{'ti'} </span>
2491: <input type="text" size="40" name="exttitle" value="$title" />
1.508 ! raeburn 2492: $pathitem
1.501 raeburn 2493: <input type="hidden" name="importdetail" value="" />
2494: <input type="button" value="$lt{'sv'}" onclick="javascript:setExternal(this.form,'$residx')" />
2495: </span>
2496: </fieldset>
2497: </form>
2498: EXTLNK
1.508 ! raeburn 2499: } else {
1.503 raeburn 2500: my ($cfile,$home,$switchserver,$forceedit,$forceview) =
2501: &Apache::lonnet::can_edit_resource($fileloc,$coursenum,$coursedom,$orig_url);
1.508 ! raeburn 2502: my $geteditlink;
! 2503: if ($supplementalflag) {
! 2504: if ($orig_url eq "/adm/$env{'user.domain'}/$env{'user.name'}/aboutme") {
! 2505: $geteditlink = 1;
! 2506: }
! 2507: } elsif (($cfile ne '') && ($symb ne '')) {
! 2508: $geteditlink = 1;
! 2509: }
! 2510: if ($geteditlink) {
1.501 raeburn 2511: my $jscall =
2512: &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,
2513: $switchserver,
1.503 raeburn 2514: $forceedit,
2515: undef,$symb);
1.501 raeburn 2516: if ($jscall) {
2517: $editlink = ' <a class="LC_docs_ext_edit" href="javascript:'.
2518: $jscall.'" >'.&mt('Edit').'</a>';
2519: }
2520: }
2521: }
1.329 droeschl 2522: }
1.408 raeburn 2523: my $reinit;
2524: if ($crstype eq 'Community') {
2525: $reinit = &mt('(re-initialize community to access)');
2526: } else {
2527: $reinit = &mt('(re-initialize course to access)');
2528: }
1.469 www 2529: $line.='<td>';
1.472 raeburn 2530: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.469 www 2531: $line.='<a href="'.$url.'"><img src="'.$icon.'" alt="" class="LC_icon" /></a>';
2532: } elsif ($url) {
1.484 raeburn 2533: $line.=&Apache::loncommon::modal_link($url.(($url=~/\?/)?'&':'?').'inhibitmenu=yes',
1.470 raeburn 2534: '<img src="'.$icon.'" alt="" class="LC_icon" />',600,500);
1.469 www 2535: } else {
2536: $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
2537: }
2538: $line.='</td><td>';
1.472 raeburn 2539: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.469 www 2540: $line.='<a href="'.$url.'">'.$title.'</a>';
2541: } elsif ($url) {
1.484 raeburn 2542: $line.=&Apache::loncommon::modal_link($url.(($url=~/\?/)?'&':'?').'inhibitmenu=yes',
1.470 raeburn 2543: $title,600,500);
1.469 www 2544: } else {
2545: $line.=$title.' <span class="LC_docs_reinit_warn">'.$reinit.'</span>';
2546: }
1.501 raeburn 2547: $line.=$editlink."</td>";
1.478 raeburn 2548: $rand_pick_text = ' ' if ($rand_pick_text eq '');
2549: $rand_order_text = ' ' if ($rand_order_text eq '');
1.329 droeschl 2550: if (($allowed) && ($folder!~/^supplemental/)) {
2551: my %lt=&Apache::lonlocal::texthash(
2552: 'hd' => 'Hidden',
2553: 'ec' => 'URL hidden');
2554: my $enctext=
1.358 bisitz 2555: ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i?' checked="checked"':'');
1.329 droeschl 2556: my $hidtext=
1.358 bisitz 2557: ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i?' checked="checked"':'');
1.329 droeschl 2558: $line.=(<<ENDPARMS);
2559: <td class="LC_docs_entry_parameter">
2560: $form_start
1.478 raeburn 2561: $form_common
1.369 bisitz 2562: <label><input type="checkbox" name="hiddenresource_$orderidx" onclick="this.form.changeparms.value='hiddenresource';this.form.submit()" $hidtext /> $lt{'hd'}</label>
1.329 droeschl 2563: $form_end
1.458 raeburn 2564: <br />
1.329 droeschl 2565: $form_start
1.478 raeburn 2566: $form_common
1.369 bisitz 2567: <label><input type="checkbox" name="encrypturl_$orderidx" onclick="this.form.changeparms.value='encrypturl';this.form.submit()" $enctext /> $lt{'ec'}</label>
1.329 droeschl 2568: $form_end
2569: </td>
1.478 raeburn 2570: <td class="LC_docs_entry_parameter">$rand_pick_text<br />
2571: $rand_order_text</td>
1.329 droeschl 2572: ENDPARMS
2573: }
1.379 bisitz 2574: $line.=&Apache::loncommon::end_data_table_row();
1.329 droeschl 2575: return $line;
2576: }
2577:
1.504 raeburn 2578: sub newmap_suffix {
2579: my ($area,$container,$coursedom,$coursenum) = @_;
2580: my ($prefix,$idtype,$errtext,$locknotfreed);
2581: $prefix = 'docs';
2582: if ($area eq 'supplemental') {
2583: $prefix = 'supp';
2584: }
2585: $prefix .= $container;
2586: $idtype = 'concat';
2587: my ($suffix,$freedlock,$error) =
2588: &Apache::lonnet::get_timebased_id($prefix,'num','uploadedmaps',
2589: $coursedom,$coursenum);
2590: if (!$suffix) {
2591: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new folder/page.');
2592: if ($error) {
2593: $errtext .= '<br />'.$error;
2594: }
2595: }
2596: if ($freedlock ne 'ok') {
2597: $locknotfreed = '<div class="LC_error">'.&mt('There was a problem removing a lockfile. This will prevent creation of additional folders or composite pages in this course. Please contact the domain coordinator for your LON-CAPA domain.').'</div>';
2598: }
2599: return ($suffix,$errtext,$locknotfreed);
2600: }
2601:
1.329 droeschl 2602: =pod
2603:
2604: =item tiehash()
2605:
2606: tie the hash
2607:
2608: =cut
2609:
2610: sub tiehash {
2611: my ($mode)=@_;
2612: $hashtied=0;
2613: if ($env{'request.course.fn'}) {
2614: if ($mode eq 'write') {
2615: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
2616: &GDBM_WRCREAT(),0640)) {
2617: $hashtied=2;
2618: }
2619: } else {
2620: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
2621: &GDBM_READER(),0640)) {
2622: $hashtied=1;
2623: }
2624: }
1.364 bisitz 2625: }
1.329 droeschl 2626: }
2627:
2628: sub untiehash {
2629: if ($hashtied) { untie %hash; }
2630: $hashtied=0;
2631: return OK;
2632: }
2633:
2634:
2635:
2636:
2637: sub checkonthis {
2638: my ($r,$url,$level,$title)=@_;
2639: $url=&unescape($url);
2640: $alreadyseen{$url}=1;
2641: $r->rflush();
2642: if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
2643: $r->print("\n<br />");
2644: if ($level==0) {
2645: $r->print("<br />");
2646: }
2647: for (my $i=0;$i<=$level*5;$i++) {
2648: $r->print(' ');
2649: }
2650: $r->print('<a href="'.$url.'" target="cat">'.
2651: ($title?$title:$url).'</a> ');
2652: if ($url=~/^\/res\//) {
2653: my $result=&Apache::lonnet::repcopy(
2654: &Apache::lonnet::filelocation('',$url));
2655: if ($result eq 'ok') {
2656: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
2657: $r->rflush();
2658: &Apache::lonnet::countacc($url);
2659: $url=~/\.(\w+)$/;
2660: if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
2661: $r->print('<br />');
2662: $r->rflush();
2663: for (my $i=0;$i<=$level*5;$i++) {
2664: $r->print(' ');
2665: }
2666: $r->print('- '.&mt('Rendering:').' ');
2667: my ($errorcount,$warningcount)=split(/:/,
2668: &Apache::lonnet::ssi_body($url,
2669: ('grade_target'=>'web',
2670: 'return_only_error_and_warning_counts' => 1)));
2671: if (($errorcount) ||
2672: ($warningcount)) {
2673: if ($errorcount) {
1.369 bisitz 2674: $r->print('<img src="/adm/lonMisc/bomb.gif" alt="'.&mt('bomb').'" /><span class="LC_error">'.
1.329 droeschl 2675: &mt('[quant,_1,error]',$errorcount).'</span>');
2676: }
2677: if ($warningcount) {
2678: $r->print('<span class="LC_warning">'.
2679: &mt('[quant,_1,warning]',$warningcount).'</span>');
2680: }
2681: } else {
2682: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
2683: }
2684: $r->rflush();
2685: }
2686: my $dependencies=
2687: &Apache::lonnet::metadata($url,'dependencies');
2688: foreach my $dep (split(/\,/,$dependencies)) {
2689: if (($dep=~/^\/res\//) && (!$alreadyseen{$dep})) {
2690: &checkonthis($r,$dep,$level+1);
2691: }
2692: }
2693: } elsif ($result eq 'unavailable') {
2694: $r->print('<span class="LC_error">'.&mt('connection down').'</span>');
2695: } elsif ($result eq 'not_found') {
2696: unless ($url=~/\$/) {
2697: $r->print('<span class="LC_error">'.&mt('not found').'</b></span>');
2698: } else {
1.366 bisitz 2699: $r->print('<span class="LC_error">'.&mt('unable to verify variable URL').'</span>');
1.329 droeschl 2700: }
2701: } else {
2702: $r->print('<span class="LC_error">'.&mt('access denied').'</span>');
2703: }
2704: }
2705: }
2706: }
2707:
2708:
2709:
2710: =pod
2711:
2712: =item list_symbs()
2713:
1.485 raeburn 2714: List Content Identifiers
1.329 droeschl 2715:
2716: =cut
2717:
2718: sub list_symbs {
2719: my ($r) = @_;
2720:
1.408 raeburn 2721: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 2722: $r->print(&Apache::loncommon::start_page('List of Content Identifiers'));
2723: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Identifiers'));
2724: $r->print(&startContentScreen('tools'));
1.329 droeschl 2725: my $navmap = Apache::lonnavmaps::navmap->new();
2726: if (!defined($navmap)) {
2727: $r->print('<h2>'.&mt('Retrieval of List Failed').'</h2>'.
2728: '<div class="LC_error">'.
2729: &mt('Unable to retrieve information about course contents').
2730: '</div>');
1.408 raeburn 2731: &Apache::lonnet::logthis('Symb list failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
1.329 droeschl 2732: } else {
1.484 raeburn 2733: $r->print('<h4 class="LC_info">'.&mt("$crstype Content Identifiers").'</h4>'.
2734: &Apache::loncommon::start_data_table().
2735: &Apache::loncommon::start_data_table_header_row().
2736: '<th>'.&mt('Title').'</th><th>'.&mt('Identifier').'</th>'.
2737: &Apache::loncommon::end_data_table_header_row()."\n");
2738: my $count;
1.329 droeschl 2739: foreach my $res ($navmap->retrieveResources()) {
1.484 raeburn 2740: $r->print(&Apache::loncommon::start_data_table_row().
2741: '<td>'.$res->compTitle().'</td>'.
2742: '<td>'.$res->symb().'</td>'.
2743: &Apache::loncommon::start_data_table_row());
2744: $count ++;
2745: }
2746: if (!$count) {
2747: $r->print(&Apache::loncommon::start_data_table_row().
2748: '<td colspan="2">'.&mt("$crstype is empty").'</td>'.
2749: &Apache::loncommon::end_data_table_row());
1.329 droeschl 2750: }
1.484 raeburn 2751: $r->print(&Apache::loncommon::end_data_table());
1.329 droeschl 2752: }
2753: }
2754:
2755:
2756: sub verifycontent {
2757: my ($r) = @_;
1.408 raeburn 2758: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 2759: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Documents'));
2760: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Documents'));
2761: $r->print(&startContentScreen('tools'));
2762: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
1.329 droeschl 2763: $hashtied=0;
2764: undef %alreadyseen;
2765: %alreadyseen=();
2766: &tiehash();
1.484 raeburn 2767:
1.329 droeschl 2768: foreach my $key (keys(%hash)) {
2769: if ($hash{$key}=~/\.(page|sequence)$/) {
2770: if (($key=~/^src_/) && ($alreadyseen{&unescape($hash{$key})})) {
2771: $r->print('<hr /><span class="LC_error">'.
1.419 bisitz 2772: &mt('The following sequence or page is included more than once in your '.$crstype.':').' '.
1.329 droeschl 2773: &unescape($hash{$key}).'</span><br />'.
1.419 bisitz 2774: &mt('Note that grading records for problems included in this sequence or folder will overlap.').'<hr />');
1.329 droeschl 2775: }
2776: }
2777: if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) {
2778: &checkonthis($r,$hash{$key},0,$hash{'title_'.$1});
2779: }
2780: }
2781: &untiehash();
1.442 www 2782: $r->print('<p class="LC_success">'.&mt('Done').'</p>');
1.329 droeschl 2783: }
2784:
2785:
2786: sub devalidateversioncache {
2787: my $src=shift;
2788: &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
2789: &Apache::lonnet::clutter($src));
2790: }
2791:
2792: sub checkversions {
2793: my ($r) = @_;
1.408 raeburn 2794: my $crstype = &Apache::loncommon::course_type();
2795: $r->print(&Apache::loncommon::start_page("Check $crstype Document Versions"));
2796: $r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $crstype Document Versions"));
1.484 raeburn 2797: $r->print(&startContentScreen('tools'));
1.442 www 2798:
1.329 droeschl 2799: my $header='';
2800: my $startsel='';
2801: my $monthsel='';
2802: my $weeksel='';
2803: my $daysel='';
2804: my $allsel='';
2805: my %changes=();
2806: my $starttime=0;
2807: my $haschanged=0;
2808: my %setversions=&Apache::lonnet::dump('resourceversions',
2809: $env{'course.'.$env{'request.course.id'}.'.domain'},
2810: $env{'course.'.$env{'request.course.id'}.'.num'});
2811:
2812: $hashtied=0;
2813: &tiehash();
2814: my %newsetversions=();
2815: if ($env{'form.setmostrecent'}) {
2816: $haschanged=1;
2817: foreach my $key (keys(%hash)) {
2818: if ($key=~/^ids\_(\/res\/.+)$/) {
2819: $newsetversions{$1}='mostrecent';
2820: &devalidateversioncache($1);
2821: }
2822: }
2823: } elsif ($env{'form.setcurrent'}) {
2824: $haschanged=1;
2825: foreach my $key (keys(%hash)) {
2826: if ($key=~/^ids\_(\/res\/.+)$/) {
2827: my $getvers=&Apache::lonnet::getversion($1);
2828: if ($getvers>0) {
2829: $newsetversions{$1}=$getvers;
2830: &devalidateversioncache($1);
2831: }
2832: }
2833: }
2834: } elsif ($env{'form.setversions'}) {
2835: $haschanged=1;
2836: foreach my $key (keys(%env)) {
2837: if ($key=~/^form\.set_version_(.+)$/) {
2838: my $src=$1;
2839: if (($env{$key}) && ($env{$key} ne $setversions{$src})) {
2840: $newsetversions{$src}=$env{$key};
2841: &devalidateversioncache($src);
2842: }
2843: }
2844: }
2845: }
2846: if ($haschanged) {
2847: if (&Apache::lonnet::put('resourceversions',\%newsetversions,
2848: $env{'course.'.$env{'request.course.id'}.'.domain'},
1.344 bisitz 2849: $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
1.479 golterma 2850: $r->print(&Apache::loncommon::confirmwrapper(
2851: &Apache::lonhtmlcommon::confirm_success(&mt('Your Version Settings have been Saved'))));
1.329 droeschl 2852: } else {
1.479 golterma 2853: $r->print(&Apache::loncommon::confirmwrapper(
2854: &Apache::lonhtmlcommon::confirm_success(&mt('An Error Occured while Attempting to Save your Version Settings'),1)));
1.329 droeschl 2855: }
2856: &mark_hash_old();
2857: }
2858: &changewarning($r,'');
2859: if ($env{'form.timerange'} eq 'all') {
2860: # show all documents
1.408 raeburn 2861: $header=&mt('All Documents in '.$crstype);
1.329 droeschl 2862: $allsel=1;
2863: foreach my $key (keys(%hash)) {
2864: if ($key=~/^ids\_(\/res\/.+)$/) {
2865: my $src=$1;
2866: $changes{$src}=1;
2867: }
2868: }
2869: } else {
2870: # show documents which changed
2871: %changes=&Apache::lonnet::dump
2872: ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
2873: $env{'course.'.$env{'request.course.id'}.'.num'});
2874: my $firstkey=(keys(%changes))[0];
2875: unless ($firstkey=~/^error\:/) {
2876: unless ($env{'form.timerange'}) {
2877: $env{'form.timerange'}=604800;
2878: }
2879: my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
2880: .&mt('seconds');
2881: if ($env{'form.timerange'}==-1) {
2882: $seltext='since start of course';
2883: $startsel='selected';
2884: $env{'form.timerange'}=time;
2885: }
2886: $starttime=time-$env{'form.timerange'};
2887: if ($env{'form.timerange'}==2592000) {
2888: $seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
2889: $monthsel='selected';
2890: } elsif ($env{'form.timerange'}==604800) {
2891: $seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
2892: $weeksel='selected';
2893: } elsif ($env{'form.timerange'}==86400) {
2894: $seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
2895: $daysel='selected';
2896: }
2897: $header=&mt('Content changed').' '.$seltext;
2898: } else {
2899: $header=&mt('No content modifications yet.');
2900: }
2901: }
2902: %setversions=&Apache::lonnet::dump('resourceversions',
2903: $env{'course.'.$env{'request.course.id'}.'.domain'},
2904: $env{'course.'.$env{'request.course.id'}.'.num'});
2905: my %lt=&Apache::lonlocal::texthash
1.408 raeburn 2906: ('st' => 'Version changes since start of '.$crstype,
1.329 droeschl 2907: 'lm' => 'Version changes since last Month',
2908: 'lw' => 'Version changes since last Week',
2909: 'sy' => 'Version changes since Yesterday',
2910: 'al' => 'All Resources (possibly large output)',
1.484 raeburn 2911: 'cd' => 'Change display',
1.329 droeschl 2912: 'sd' => 'Display',
2913: 'fi' => 'File',
2914: 'md' => 'Modification Date',
2915: 'mr' => 'Most recently published Version',
1.408 raeburn 2916: 've' => 'Version used in '.$crstype,
2917: 'vu' => 'Set Version to be used in '.$crstype,
2918: 'sv' => 'Set Versions to be used in '.$crstype.' according to Selections below',
1.329 droeschl 2919: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
2920: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
1.479 golterma 2921: 'di' => 'Differences',
1.484 raeburn 2922: 'save' => 'Save changes',
2923: 'vers' => 'Version choice(s) for specific resources',
1.479 golterma 2924: 'act' => 'Actions');
1.329 droeschl 2925: $r->print(<<ENDHEADERS);
1.484 raeburn 2926: <h4 class="LC_info">$header</h4>
1.329 droeschl 2927: <form action="/adm/coursedocs" method="post">
2928: <input type="hidden" name="versions" value="1" />
1.484 raeburn 2929: <div class="LC_left_float">
1.479 golterma 2930: <fieldset>
1.484 raeburn 2931: <legend>$lt{'cd'}</legend>
1.329 droeschl 2932: <select name="timerange">
2933: <option value='all' $allsel>$lt{'al'}</option>
2934: <option value="-1" $startsel>$lt{'st'}</option>
2935: <option value="2592000" $monthsel>$lt{'lm'}</option>
2936: <option value="604800" $weeksel>$lt{'lw'}</option>
2937: <option value="86400" $daysel>$lt{'sy'}</option>
2938: </select>
2939: <input type="submit" name="display" value="$lt{'sd'}" />
1.484 raeburn 2940: </fieldset>
2941: </div>
2942: <div class="LC_left_float">
2943: <fieldset>
2944: <legend>$lt{'act'}</legend>
2945: $lt{'sm'}: <input type="submit" name="setmostrecent" value="Go" /><br />
2946: $lt{'sc'}: <input type="submit" name="setcurrent" value="Go" />
2947: </fieldset>
2948: </div>
2949: <br clear="all" />
2950: <hr />
2951: <h4>$lt{'vers'}</h4>
1.479 golterma 2952: <input type="submit" name="setversions" value="$lt{'save'}" />
1.329 droeschl 2953: <table border="0">
2954: ENDHEADERS
1.479 golterma 2955: #number of columns for version history
2956: my $num_ver_col = 1;
2957: $r->print(
2958: &Apache::loncommon::start_data_table().
2959: &Apache::loncommon::start_data_table_header_row().
2960: '<th>'.&mt('Resources').'</th>'.
2961: "<th>$lt{'mr'}</th>".
2962: "<th>$lt{'ve'}</th>".
2963: "<th>$lt{'vu'}</th>".
2964: '<th colspan="'.$num_ver_col.'">'.&mt('History').'</th>'.
2965: '</b>');
1.329 droeschl 2966: foreach my $key (sort(keys(%changes))) {
1.496 golterma 2967: #excludes not versionable problems from resource version history:
2968: if ($changes{$key}>$starttime && $key !~ /^\/res\/lib\/templates/) {
1.329 droeschl 2969: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
2970: my $currentversion=&Apache::lonnet::getversion($key);
2971: if ($currentversion<0) {
1.479 golterma 2972: $currentversion='<span class="LC_error">'.&mt('Could not be determined.').'</span>';
1.329 droeschl 2973: }
2974: my $linkurl=&Apache::lonnet::clutter($key);
1.479 golterma 2975: $r->print(
2976: &Apache::loncommon::end_data_table_header_row().
2977: &Apache::loncommon::start_data_table_row().
2978: '<td><b>'.&Apache::lonnet::gettitle($linkurl).'</b><br>'.
2979: '<a href="'.$linkurl.'" target="cat">'.$linkurl.'</a></td>'.
2980: '<td align="right">'.$currentversion.'<span class="LC_fontsize_medium"><br>('.
2981: &Apache::lonlocal::locallocaltime(&Apache::lonnet::metadata($root.'.'.$extension,'lastrevisiondate')).')</span></td>'.
2982: '<td align="right">');
1.329 droeschl 2983: # Used in course
2984: my $usedversion=$hash{'version_'.$linkurl};
2985: if (($usedversion) && ($usedversion ne 'mostrecent')) {
1.479 golterma 2986: if($usedversion != $currentversion){
2987: $r->print('<span class="LC_warning">'.$usedversion.'</span>');
2988: }else{
2989: $r->print($usedversion);
2990: }
1.329 droeschl 2991: } else {
2992: $r->print($currentversion);
2993: }
1.479 golterma 2994: $r->print('</td><td title="'.$lt{'vu'}.'">');
1.329 droeschl 2995: # Set version
2996: $r->print(&Apache::loncommon::select_form($setversions{$linkurl},
2997: 'set_version_'.$linkurl,
1.428 raeburn 2998: {'select_form_order' =>
1.329 droeschl 2999: ['',1..$currentversion,'mostrecent'],
3000: '' => '',
1.411 bisitz 3001: 'mostrecent' => &mt('most recent'),
1.428 raeburn 3002: map {$_,$_} (1..$currentversion)}));
1.329 droeschl 3003: my $lastold=1;
3004: for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
3005: my $url=$root.'.'.$prevvers.'.'.$extension;
3006: if (&Apache::lonnet::metadata($url,'lastrevisiondate')<
3007: $starttime) {
3008: $lastold=$prevvers;
3009: }
3010: }
1.364 bisitz 3011: #
1.329 droeschl 3012: # Code to figure out how many version entries should go in
3013: # each of the four columns
3014: my $entries_per_col = 0;
3015: my $num_entries = ($currentversion-$lastold);
1.479 golterma 3016: if ($num_entries % $num_ver_col == 0) {
3017: $entries_per_col = $num_entries/$num_ver_col;
1.329 droeschl 3018: } else {
1.479 golterma 3019: $entries_per_col = $num_entries/$num_ver_col + 1;
1.329 droeschl 3020: }
3021: my $entries_count = 0;
1.479 golterma 3022: $r->print('<td valign="top"><span class="LC_fontsize_medium">');
1.329 droeschl 3023: my $cols_output = 1;
3024: for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
3025: my $url=$root.'.'.$prevvers.'.'.$extension;
3026: $r->print('<span class="LC_nobreak"><a href="'.&Apache::lonnet::clutter($url).
3027: '">'.&mt('Version').' '.$prevvers.'</a> ('.
3028: &Apache::lonlocal::locallocaltime(
3029: &Apache::lonnet::metadata($url,
3030: 'lastrevisiondate')
3031: ).
3032: ')');
3033: if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
3034: $r->print(' <a href="/adm/diff?filename='.
3035: &Apache::lonnet::clutter($root.'.'.$extension).
3036: '&versionone='.$prevvers.
1.462 raeburn 3037: '" target="diffs">'.&mt('Diffs').'</a>');
1.329 droeschl 3038: }
3039: $r->print('</span><br />');
3040: if (++$entries_count % $entries_per_col == 0) {
1.479 golterma 3041: $r->print('</span></td>');
3042: if ($cols_output != $num_ver_col) {
3043: $r->print('<td valign="top"><span class="LC_fontsize_medium">');
1.329 droeschl 3044: $cols_output++;
3045: }
3046: }
3047: }
1.479 golterma 3048: while($cols_output++ < $num_ver_col) {
3049: $r->print('</span></td><td>');
1.329 droeschl 3050: }
3051: }
3052: }
1.479 golterma 3053: $r->print('</td>'.&Apache::loncommon::end_data_table_row().
3054: &Apache::loncommon::end_data_table().
3055: '<input type="submit" name="setversions" value="'.$lt{'save'}.'" />');
1.329 droeschl 3056:
3057: &untiehash();
3058: }
3059:
3060: sub mark_hash_old {
3061: my $retie_hash=0;
3062: if ($hashtied) {
3063: $retie_hash=1;
3064: &untiehash();
3065: }
3066: &tiehash('write');
3067: $hash{'old'}=1;
3068: &untiehash();
3069: if ($retie_hash) { &tiehash(); }
3070: }
3071:
3072: sub is_hash_old {
3073: my $untie_hash=0;
3074: if (!$hashtied) {
3075: $untie_hash=1;
3076: &tiehash();
3077: }
3078: my $return=$hash{'old'};
3079: if ($untie_hash) { &untiehash(); }
3080: return $return;
3081: }
3082:
3083: sub changewarning {
3084: my ($r,$postexec,$message,$url)=@_;
3085: if (!&is_hash_old()) { return; }
3086: my $pathvar='folderpath';
3087: my $path=&escape($env{'form.folderpath'});
3088: if (!defined($url)) {
3089: if (defined($env{'form.pagepath'})) {
3090: $pathvar='pagepath';
3091: $path=&escape($env{'form.pagepath'});
3092: $path.='&pagesymb='.&escape($env{'form.pagesymb'});
3093: }
3094: $url='/adm/coursedocs?'.$pathvar.'='.$path;
3095: }
3096: my $course_type = &Apache::loncommon::course_type();
3097: if (!defined($message)) {
3098: $message='Changes will become active for your current session after [_1], or the next time you log in.';
3099: }
3100: $r->print("\n\n".
1.372 bisitz 3101: '<script type="text/javascript">'."\n".
3102: '// <![CDATA['."\n".
3103: 'function reinit(tf) { tf.submit();'.$postexec.' }'."\n".
3104: '// ]]>'."\n".
1.369 bisitz 3105: '</script>'."\n".
1.375 tempelho 3106: '<form name="reinitform" method="post" action="/adm/roles" target="loncapaclient">'.
1.329 droeschl 3107: '<input type="hidden" name="orgurl" value="'.$url.
1.372 bisitz 3108: '" /><input type="hidden" name="selectrole" value="1" /><p class="LC_warning">'.
1.329 droeschl 3109: &mt($message,' <input type="hidden" name="'.
3110: $env{'request.role'}.'" value="1" /><input type="button" value="'.
1.369 bisitz 3111: &mt('re-initializing '.$course_type).'" onclick="reinit(this.form)" />').
1.372 bisitz 3112: $help{'Caching'}.'</p></form>'."\n\n");
1.329 droeschl 3113: }
3114:
3115:
3116: sub init_breadcrumbs {
3117: my ($form,$text)=@_;
3118: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.484 raeburn 3119: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1",
1.405 bisitz 3120: text=>&Apache::loncommon::course_type().' Editor',
1.329 droeschl 3121: faq=>273,
3122: bug=>'Instructor Interface',
3123: help => 'Docs_Adding_Course_Doc'});
3124: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?".$form.'=1',
3125: text=>$text,
3126: faq=>273,
3127: bug=>'Instructor Interface'});
3128: }
3129:
1.441 www 3130: # subroutine to list form elements
3131: sub create_list_elements {
3132: my @formarr = @_;
3133: my $list = '';
1.501 raeburn 3134: foreach my $button (@formarr){
3135: foreach my $picture (keys(%{$button})) {
3136: $list .= &Apache::lonhtmlcommon::htmltag('li', $picture.' '.$button->{$picture}, {class => 'LC_menubuttons_inline_text', id => ''});
1.441 www 3137: }
3138: }
3139: return $list;
3140: }
1.329 droeschl 3141:
1.441 www 3142: # subroutine to create ul from list elements
3143: sub create_form_ul {
3144: my $list = shift;
3145: my $ul = &Apache::lonhtmlcommon::htmltag('ul',$list, {class => 'LC_ListStyleNormal'});
3146: return $ul;
3147: }
1.329 droeschl 3148:
1.442 www 3149: #
3150: # Start tabs
3151: #
3152:
3153: sub startContentScreen {
1.484 raeburn 3154: my ($mode) = @_;
3155: my $output = '<ul class="LC_TabContentBigger" id="mainnav">';
1.472 raeburn 3156: if (($mode eq 'navmaps') || ($mode eq 'supplemental')) {
1.484 raeburn 3157: $output .= '<li'.(($mode eq 'navmaps')?' class="active"':'').'><a href="/adm/navmaps"><b> '.&mt('Content Overview').' </b></a></li>'."\n";
3158: $output .= '<li'.(($mode eq 'coursesearch')?' class="active"':'').'><a href="/adm/searchcourse"><b> '.&mt('Content Search').' </b></a></li>'."\n";
3159: $output .= '<li'.(($mode eq 'courseindex')?' class="active"':'').'><a href="/adm/indexcourse"><b> '.&mt('Content Index').' </b></a></li>'."\n";
3160: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/supplemental"><b>'.&mt('Supplemental Content').'</b></a></li>';
3161: } else {
3162: $output .= '<li '.(($mode eq 'docs')?' class="active"':'').' id="tabbededitor"><a href="/adm/coursedocs?forcestandard=1"><b> '.&mt('Content Editor').' </b></a></li>'."\n";
3163: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/coursedocs?forcesupplement=1"><b>'.&mt('Supplemental Content Editor').'</b></a></li>'."\n";
3164: $output .= '<li '.(($mode eq 'tools')?' class="active"':'').'><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>'."\n";
3165: '><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>';
3166: }
3167: $output .= "\n".'</ul>'."\n";
3168: $output .= '<div class="LC_DocsBox" style="clear:both;margin:0;" id="contenteditor">'.
3169: '<div id="maincoursedoc" style="margin:0 0;padding:0 0;">'.
3170: '<div class="LC_ContentBox" id="mainCourseDocuments" style="display: block;">';
3171: return $output;
1.442 www 3172: }
3173:
3174: #
3175: # End tabs
3176: #
3177:
3178: sub endContentScreen {
1.484 raeburn 3179: return '</div></div></div>';
1.442 www 3180: }
1.329 droeschl 3181:
1.446 www 3182: sub supplemental_base {
1.472 raeburn 3183: return 'supplemental&'.&escape(&mt('Supplemental '.&Apache::loncommon::course_type().' Content'));
1.446 www 3184: }
3185:
1.329 droeschl 3186: sub handler {
3187: my $r = shift;
3188: &Apache::loncommon::content_type($r,'text/html');
3189: $r->send_http_header;
3190: return OK if $r->header_only;
1.484 raeburn 3191:
3192: # get course data
1.408 raeburn 3193: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 3194: my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
3195: my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
3196:
3197: # graphics settings
3198: $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL').'/');
1.329 droeschl 3199:
1.443 www 3200: #
1.329 droeschl 3201: # --------------------------------------------- Initialize help topics for this
3202: foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',
3203: 'Adding_External_Resource','Navigate_Content',
3204: 'Adding_Folders','Docs_Overview', 'Load_Map',
3205: 'Supplemental','Score_Upload_Form','Adding_Pages',
1.501 raeburn 3206: 'Importing_LON-CAPA_Resource','Importing_IMS_Course',
3207: 'Uploading_From_Harddrive',
1.329 droeschl 3208: 'Check_Resource_Versions','Verify_Content') {
3209: $help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
3210: }
3211: # Composite help files
3212: $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
3213: 'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
3214: $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
3215: 'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
3216: $help{'Simple Problem'} = &Apache::loncommon::help_open_topic(
3217: 'Option_Response_Simple');
3218: $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
3219: 'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
1.347 weissno 3220: $help{'My Personal Information Page'} = &Apache::loncommon::help_open_topic(
1.329 droeschl 3221: 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
1.353 weissno 3222: $help{'Group Portfolio'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
1.329 droeschl 3223: $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
3224:
1.472 raeburn 3225:
3226: my $allowed;
3227: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
3228: unless ($r->uri eq '/adm/supplemental') {
3229: # does this user have privileges to modify content.
3230: $allowed = &Apache::lonnet::allowed('mdc',$env{'request.course.id'});
3231: }
3232:
1.484 raeburn 3233: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['chooseserver',
3234: 'inhibitmenu']);
3235: if ($allowed && $env{'form.chooseserver'}) {
3236: &choose_dump_server($r);
3237: return OK;
3238: } elsif ($allowed && $env{'form.verify'}) {
1.329 droeschl 3239: &init_breadcrumbs('verify','Verify Content');
3240: &verifycontent($r);
3241: } elsif ($allowed && $env{'form.listsymbs'}) {
1.484 raeburn 3242: &init_breadcrumbs('listsymbs','List Content IDs');
1.329 droeschl 3243: &list_symbs($r);
3244: } elsif ($allowed && $env{'form.docslog'}) {
3245: &init_breadcrumbs('docslog','Show Log');
1.484 raeburn 3246: my $folder = $env{'form.folder'};
3247: if ($folder eq '') {
3248: $folder='default';
3249: }
3250: &docs_change_log($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath);
1.329 droeschl 3251: } elsif ($allowed && $env{'form.versions'}) {
3252: &init_breadcrumbs('versions','Check/Set Resource Versions');
3253: &checkversions($r);
3254: } elsif ($allowed && $env{'form.dumpcourse'}) {
1.484 raeburn 3255: &init_breadcrumbs('dumpcourse','Dump '.&Apache::loncommon::course_type().' Content to Authoring Space');
1.329 droeschl 3256: &dumpcourse($r);
3257: } elsif ($allowed && $env{'form.exportcourse'}) {
1.377 bisitz 3258: &init_breadcrumbs('exportcourse','IMS Export');
1.475 raeburn 3259: &Apache::imsexport::exportcourse($r);
1.329 droeschl 3260: } else {
1.445 www 3261: #
3262: # Done catching special calls
1.484 raeburn 3263: # The whole rest is for course and supplemental documents and utilities menu
1.445 www 3264: # Get the parameters that may be needed
3265: #
3266: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
3267: ['folderpath','pagepath',
1.466 www 3268: 'pagesymb','forcesupplement','forcestandard',
1.484 raeburn 3269: 'tools','symb','command']);
1.445 www 3270:
3271: # standard=1: this is a "new-style" course with an uploaded map as top level
3272: # standard=2: this is a "old-style" course, and there is nothing we can do
1.329 droeschl 3273:
3274: my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
1.445 www 3275:
1.484 raeburn 3276: # Decide whether this should display supplemental or main content or utilities
1.445 www 3277: # supplementalflag=1: show supplemental documents
3278: # supplementalflag=0: show standard documents
1.484 raeburn 3279: # toolsflag=1: show utilities
1.445 www 3280:
3281:
3282: my $supplementalflag=($env{'form.folderpath'}=~/^supplemental/);
3283: if (($env{'form.folderpath'}=~/^default/) || $env{'form.folderpath'} eq "" || ($env{'form.pagepath'})) {
3284: $supplementalflag=0;
3285: }
3286: if ($env{'form.forcesupplement'}) { $supplementalflag=1; }
3287: if ($env{'form.forcestandard'}) { $supplementalflag=0; }
3288: unless ($allowed) { $supplementalflag=1; }
3289: unless ($standard) { $supplementalflag=1; }
1.484 raeburn 3290: my $toolsflag=0;
3291: if ($env{'form.tools'}) { $toolsflag=1; }
1.445 www 3292:
1.329 droeschl 3293: my $script='';
3294: my $showdoc=0;
1.457 raeburn 3295: my $addentries = {};
1.475 raeburn 3296: my $container;
1.329 droeschl 3297: my $containertag;
1.508 ! raeburn 3298: my $pathitem;
1.329 droeschl 3299:
1.464 www 3300: # Do we directly jump somewhere?
1.466 www 3301:
1.464 www 3302: if ($env{'form.command'} eq 'direct') {
1.468 raeburn 3303: my ($mapurl,$id,$resurl);
1.472 raeburn 3304: if ($env{'form.symb'} ne '') {
1.468 raeburn 3305: ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($env{'form.symb'});
3306: if ($resurl=~/\.(sequence|page)$/) {
3307: $mapurl=$resurl;
3308: } elsif ($resurl eq 'adm/navmaps') {
3309: $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
3310: }
1.472 raeburn 3311: my $mapresobj;
3312: my $navmap = Apache::lonnavmaps::navmap->new();
3313: if (ref($navmap)) {
3314: $mapresobj = $navmap->getResourceByUrl($mapurl);
3315: }
3316: $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
3317: my $type=$2;
3318: my $path;
3319: if (ref($mapresobj)) {
3320: my $pcslist = $mapresobj->map_hierarchy();
3321: if ($pcslist ne '') {
3322: foreach my $pc (split(/,/,$pcslist)) {
3323: next if ($pc <= 1);
3324: my $res = $navmap->getByMapPc($pc);
3325: if (ref($res)) {
3326: my $thisurl = $res->src();
3327: $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
3328: my $thistitle = $res->title();
3329: $path .= '&'.
3330: &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
3331: &Apache::lonhtmlcommon::entity_encode($thistitle).
3332: ':'.$res->randompick().
3333: ':'.$res->randomout().
3334: ':'.$res->encrypted().
3335: ':'.$res->randomorder();
3336: }
1.467 raeburn 3337: }
3338: }
1.472 raeburn 3339: $path .= '&'.&Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.467 raeburn 3340: &Apache::lonhtmlcommon::entity_encode($mapresobj->title()).
3341: ':'.$mapresobj->randompick().
3342: ':'.$mapresobj->randomout().
3343: ':'.$mapresobj->encrypted().
3344: ':'.$mapresobj->randomorder();
1.472 raeburn 3345: } else {
3346: my $maptitle = &Apache::lonnet::gettitle($mapurl);
3347: $path = '&default&...::::'.
3348: '&'.&Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
3349: &Apache::lonhtmlcommon::entity_encode($maptitle).'::::';
3350: }
3351: $path = 'default&'.
3352: &Apache::lonhtmlcommon::entity_encode('Main Course Documents').
3353: $path;
3354: if ($type eq 'sequence') {
3355: $env{'form.folderpath'}=$path;
3356: $env{'form.pagepath'}='';
3357: } else {
3358: $env{'form.pagepath'}=$path;
3359: $env{'form.folderpath'}='';
3360: }
3361: } elsif ($env{'form.supppath'} ne '') {
3362: $env{'form.folderpath'}=$env{'form.supppath'};
1.466 www 3363: }
1.472 raeburn 3364: } elsif ($env{'form.command'} eq 'editdocs') {
3365: $env{'form.folderpath'} = 'default&'.
3366: &Apache::lonhtmlcommon::entity_encode('Main Course Content');
3367: $env{'form.pagepath'}='';
3368: } elsif ($env{'form.command'} eq 'editsupp') {
3369: $env{'form.folderpath'} = 'default&'.
3370: &Apache::lonhtmlcommon::entity_encode('Supplemental Content');
3371: $env{'form.pagepath'}='';
1.464 www 3372: }
3373:
1.445 www 3374: # Where do we store these for when we come back?
3375: my $stored_folderpath='docs_folderpath';
3376: if ($supplementalflag) {
3377: $stored_folderpath='docs_sup_folderpath';
3378: }
1.464 www 3379:
1.329 droeschl 3380: # No folderpath, no pagepath, see if we have something stored
3381: if ((!$env{'form.folderpath'}) && (!$env{'form.pagepath'})) {
1.445 www 3382: &Apache::loncommon::restore_course_settings($stored_folderpath,
1.329 droeschl 3383: {'folderpath' => 'scalar'});
3384: }
1.446 www 3385:
3386: # If we are not allowed to make changes, all we can see are supplemental docs
1.409 raeburn 3387: if (!$allowed) {
1.446 www 3388: $env{'form.pagepath'}='';
3389: unless ($env{'form.folderpath'} =~ /^supplemental/) {
3390: $env{'form.folderpath'} = &supplemental_base();
1.409 raeburn 3391: }
3392: }
1.446 www 3393: # If we still not have a folderpath, see if we can resurrect at pagepath
1.409 raeburn 3394: if (!$env{'form.folderpath'} && $allowed) {
1.445 www 3395: &Apache::loncommon::restore_course_settings($stored_folderpath,
1.329 droeschl 3396: {'pagepath' => 'scalar'});
3397: }
1.446 www 3398: # Make the zeroth entry in supplemental docs page paths, so we can get to top level
1.329 droeschl 3399: if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
1.446 www 3400: $env{'form.folderpath'} = &supplemental_base()
3401: .'&'.
1.329 droeschl 3402: $env{'form.folderpath'};
3403: }
1.446 www 3404: # If after all of this, we still don't have any paths, make them
3405: unless (($env{'form.pagepath'}) || ($env{'form.folderpath'})) {
3406: if ($supplementalflag) {
3407: $env{'form.folderpath'}=&supplemental_base();
3408: } else {
3409: $env{'form.folderpath'}='default';
3410: }
1.472 raeburn 3411: }
1.446 www 3412:
1.445 www 3413: # Store this
1.484 raeburn 3414: unless ($toolsflag) {
3415: &Apache::loncommon::store_course_settings($stored_folderpath,
3416: {'pagepath' => 'scalar',
3417: 'folderpath' => 'scalar'});
3418: if ($env{'form.folderpath'}) {
3419: my (@folderpath)=split('&',$env{'form.folderpath'});
3420: $env{'form.foldername'}=&unescape(pop(@folderpath));
3421: $env{'form.folder'}=pop(@folderpath);
3422: $container='sequence';
3423: }
3424: if ($env{'form.pagepath'}) {
3425: my (@pagepath)=split('&',$env{'form.pagepath'});
3426: $env{'form.pagename'}=&unescape(pop(@pagepath));
3427: $env{'form.folder'}=pop(@pagepath);
3428: $container='page';
3429: $containertag = '<input type="hidden" name="pagepath" value="" />'.
3430: '<input type="hidden" name="pagesymb" value="" />';
1.508 ! raeburn 3431: $pathitem =
1.484 raeburn 3432: '<input type="hidden" name="pagepath" value="'.&HTML::Entities::encode($env{'form.pagepath'},'<>&"').'" />'.
3433: '<input type="hidden" name="pagesymb" value="'.&HTML::Entities::encode($env{'form.pagesymb'},'<>&"').'" />'.
3434: '<input type="hidden" name="folderpath" value="" />';
3435: } else {
3436: my $folderpath=$env{'form.folderpath'};
3437: if (!$folderpath) {
3438: if ($env{'form.folder'} eq '' ||
3439: $env{'form.folder'} eq 'supplemental') {
3440: $folderpath='default&'.
3441: &escape(&mt('Main '.$crstype.' Documents'));
3442: }
3443: }
3444: $containertag = '<input type="hidden" name="folderpath" value="" />';
1.508 ! raeburn 3445: $pathitem = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 3446: }
3447: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
3448: $showdoc='/'.$1;
3449: }
3450: if ($showdoc) { # got called in sequence from course
3451: $allowed=0;
3452: } else {
3453: if ($allowed) {
3454: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
3455: $script=&Apache::lonratedt::editscript('simple');
1.433 raeburn 3456: }
3457: }
1.329 droeschl 3458: }
3459:
1.344 bisitz 3460: # get personal data
1.329 droeschl 3461: my $uname=$env{'user.name'};
3462: my $udom=$env{'user.domain'};
3463: my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));
3464:
3465: if ($allowed) {
1.484 raeburn 3466: if ($toolsflag) {
3467: $script .= &inject_data_js();
3468: my ($home,$other,%outhash)=&authorhosts();
3469: if (!$home && $other) {
3470: my @hosts;
3471: foreach my $aurole (keys(%outhash)) {
3472: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
3473: push(@hosts,$outhash{$aurole});
3474: }
3475: }
3476: $script .= &dump_switchserver_js(@hosts);
3477: }
1.458 raeburn 3478: } else {
1.484 raeburn 3479: my @tabids;
3480: if ($supplementalflag) {
3481: @tabids = ('002','ee2','ff2');
3482: } else {
3483: @tabids = ('aa1','bb1','cc1','ff1');
3484: unless ($env{'form.pagepath'}) {
3485: unshift(@tabids,'001');
3486: push(@tabids,('dd1','ee1'));
3487: }
1.458 raeburn 3488: }
1.484 raeburn 3489: my $tabidstr = join("','",@tabids);
3490: $script .= &editing_js($udom,$uname,$supplementalflag).
3491: &history_tab_js().
3492: &inject_data_js().
1.485 raeburn 3493: &Apache::lonhtmlcommon::resize_scrollbox_js('docs',$tabidstr);
1.484 raeburn 3494: $addentries = {
1.485 raeburn 3495: onload => "javascript:resize_scrollbox('contentscroll','1','1');",
1.484 raeburn 3496: };
1.458 raeburn 3497: }
1.492 raeburn 3498: if ($env{'docs.markedcopy_url'}) {
3499: $script .= &paste_popup_js();
3500: }
1.501 raeburn 3501: my $confirm_switch = &mt("Editing requires switching to the resource's home server.").'\n'.
3502: &mt('Switch server?');
3503:
3504:
1.329 droeschl 3505: }
3506: # -------------------------------------------------------------------- Body tag
1.369 bisitz 3507: $script = '<script type="text/javascript">'."\n"
1.372 bisitz 3508: .'// <![CDATA['."\n"
3509: .$script."\n"
3510: .'// ]]>'."\n"
3511: .'</script>'."\n";
1.385 bisitz 3512:
3513: # Breadcrumbs
3514: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.446 www 3515: unless ($showdoc) {
1.392 raeburn 3516: &Apache::lonhtmlcommon::add_breadcrumb({
1.446 www 3517: href=>"/adm/coursedocs",text=>"$crstype Contents"});
1.392 raeburn 3518:
1.446 www 3519: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script,
1.457 raeburn 3520: {'force_register' => $showdoc,
3521: 'add_entries' => $addentries,
3522: })
1.392 raeburn 3523: .&Apache::loncommon::help_open_menu('','',273,'RAT')
3524: .&Apache::lonhtmlcommon::breadcrumbs(
1.484 raeburn 3525: 'Editing '.$crstype.' Contents',
1.392 raeburn 3526: 'Docs_Adding_Course_Doc')
3527: );
1.446 www 3528: } else {
1.408 raeburn 3529: $r->print(&Apache::loncommon::start_page("$crstype documents",undef,
1.402 raeburn 3530: {'force_register' => $showdoc,}));
1.392 raeburn 3531: }
1.364 bisitz 3532:
1.329 droeschl 3533: my %allfiles = ();
3534: my %codebase = ();
1.440 raeburn 3535: my ($upload_result,$upload_output,$uploadphase);
1.329 droeschl 3536: if ($allowed) {
3537: if (($env{'form.uploaddoc.filename'}) &&
3538: ($env{'form.cmd'}=~/^upload_(\w+)/)) {
1.440 raeburn 3539: my $context = $1;
3540: # Process file upload - phase one - upload and parse primary file.
1.329 droeschl 3541: undef($hadchanges);
1.440 raeburn 3542: $uploadphase = &process_file_upload(\$upload_output,$coursenum,$coursedom,
3543: \%allfiles,\%codebase,$context);
1.329 droeschl 3544: if ($hadchanges) {
3545: &mark_hash_old();
3546: }
1.440 raeburn 3547: $r->print($upload_output);
3548: } elsif ($env{'form.phase'} eq 'upload_embedded') {
3549: # Process file upload - phase two - upload embedded objects
3550: $uploadphase = 'check_embedded';
3551: my $primaryurl = &HTML::Entities::encode($env{'form.primaryurl'},'<>&"');
3552: my $state = &embedded_form_elems($uploadphase,$primaryurl,
3553: $env{'form.newidx'});
3554: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
3555: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
3556: my ($destination,$dir_root) = &embedded_destination();
3557: my $url_root = '/uploaded/'.$docudom.'/'.$docuname;
3558: my $actionurl = '/adm/coursedocs';
3559: my ($result,$flag) =
3560: &Apache::loncommon::upload_embedded('coursedoc',$destination,
3561: $docuname,$docudom,$dir_root,$url_root,undef,undef,undef,$state,
3562: $actionurl);
3563: $r->print($result.&return_to_editor());
3564: } elsif ($env{'form.phase'} eq 'check_embedded') {
3565: # Process file upload - phase three - modify references in HTML file
3566: $uploadphase = 'modified_orightml';
3567: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
3568: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
3569: my ($destination,$dir_root) = &embedded_destination();
1.482 raeburn 3570: my $result =
3571: &Apache::loncommon::modify_html_refs('coursedoc',$destination,
3572: $docuname,$docudom,undef,
3573: $dir_root);
3574: $r->print($result.&return_to_editor());
1.476 raeburn 3575: } elsif ($env{'form.phase'} eq 'decompress_uploaded') {
3576: $uploadphase = 'decompress_phase_one';
3577: $r->print(&decompression_phase_one().
3578: &return_to_editor());
3579: } elsif ($env{'form.phase'} eq 'decompress_cleanup') {
3580: $uploadphase = 'decompress_phase_two';
3581: $r->print(&decompression_phase_two().
3582: &return_to_editor());
1.329 droeschl 3583: }
3584: }
3585:
1.484 raeburn 3586: if ($allowed && $toolsflag) {
3587: $r->print(&startContentScreen('tools'));
3588: $r->print(&generate_admin_menu($crstype));
3589: $r->print(&endContentScreen());
3590: } elsif ((!$showdoc) && (!$uploadphase)) {
1.329 droeschl 3591: # -----------------------------------------------------------------------------
3592: my %lt=&Apache::lonlocal::texthash(
1.408 raeburn 3593: 'uplm' => 'Upload a new main '.lc($crstype).' document',
3594: 'upls' => 'Upload a new supplemental '.lc($crstype).' document',
1.329 droeschl 3595: 'impp' => 'Import a document',
3596: 'copm' => 'All documents out of a published map into this folder',
1.501 raeburn 3597: 'upfi' => 'Upload File',
3598: 'upld' => 'Import Content',
1.329 droeschl 3599: 'srch' => 'Search',
3600: 'impo' => 'Import',
1.487 raeburn 3601: 'lnks' => 'Import from Stored Links',
1.502 raeburn 3602: 'impm' => 'Import from Assembled Map',
1.329 droeschl 3603: 'selm' => 'Select Map',
3604: 'load' => 'Load Map',
1.419 bisitz 3605: 'reco' => 'Recover Deleted Documents',
1.329 droeschl 3606: 'newf' => 'New Folder',
3607: 'newp' => 'New Composite Page',
3608: 'extr' => 'External Resource',
3609: 'syll' => 'Syllabus',
1.425 raeburn 3610: 'navc' => 'Table of Contents',
1.343 biermanm 3611: 'sipa' => 'Simple Course Page',
1.329 droeschl 3612: 'sipr' => 'Simple Problem',
3613: 'drbx' => 'Drop Box',
1.451 www 3614: 'scuf' => 'External Scores (handgrade, upload, clicker)',
1.336 schafran 3615: 'bull' => 'Discussion Board',
1.347 weissno 3616: 'mypi' => 'My Personal Information Page',
1.353 weissno 3617: 'grpo' => 'Group Portfolio',
1.329 droeschl 3618: 'rost' => 'Course Roster',
1.348 weissno 3619: 'abou' => 'Personal Information Page for a User',
1.377 bisitz 3620: 'imsf' => 'IMS Import',
3621: 'imsl' => 'Import IMS package',
1.501 raeburn 3622: 'cms' => 'Origin of IMS package',
3623: 'se' => 'Select',
1.329 droeschl 3624: 'file' => 'File',
3625: 'title' => 'Title',
3626: 'comment' => 'Comment',
1.501 raeburn 3627: 'url' => 'URL',
3628: 'prev' => 'Preview',
3629: 'lnk' => 'Add Link',
1.403 raeburn 3630: 'parse' => 'Upload embedded images/multimedia files if HTML file',
1.368 truskell 3631: 'nd' => 'Upload Document',
1.329 droeschl 3632: 'pm' => 'Published Map',
3633: 'sd' => 'Special Document',
3634: 'mo' => 'More Options',
3635: );
3636: # -----------------------------------------------------------------------------
3637: my $fileupload=(<<FIUP);
3638: $lt{'file'}:<br />
3639: <input type="file" name="uploaddoc" size="40" />
3640: FIUP
3641:
3642: my $checkbox=(<<CHBO);
3643: <!-- <label>$lt{'parse'}?
3644: <input type="checkbox" name="parserflag" />
3645: </label> -->
3646: <label>
3647: <input type="checkbox" name="parserflag" checked="checked" /> $lt{'parse'}
3648: </label>
3649: CHBO
1.501 raeburn 3650: my $imsfolder = $env{'form.folder'};
3651: if ($imsfolder eq '') {
3652: $imsfolder = 'default';
3653: }
3654: my $imspform=(<<IMSFORM);
3655: <a class="LC_menubuttons_link" href="javascript:toggleUpload('ims');">
3656: $lt{'imsf'}</a> $help{'Importing_IMS_Course'}
3657: <form name="uploadims" action="/adm/imsimportdocs" method="post" enctype="multipart/form-data" target="IMSimport">
3658: <fieldset id="uploadimsform" style="display: none;" />
3659: <legend>$lt{'imsf'}</legend>
3660: $fileupload
3661: <br />
3662: <p>
3663: $lt{'cms'}:
3664: <select name="source">
3665: <option value="-1" selected="selected">$lt{'se'}</option>
3666: <option value="bb5">Blackboard 5</option>
3667: <option value="bb6">Blackboard 6</option>
3668: <option value="angel5">ANGEL 5.5</option>
3669: <option value="webctce4">WebCT 4 Campus Edition</option>
3670: </select>
3671: <input type="hidden" name="folder" value="$imsfolder" />
3672: </p>
3673: <input type="hidden" name="phase" value="one" />
3674: <input type="button" value="$lt{'imsl'}" onclick="makeims(this.form);" />
3675: </fieldset>
3676: </form>
3677: IMSFORM
1.329 droeschl 3678:
3679: my $fileuploadform=(<<FUFORM);
1.501 raeburn 3680: <a class="LC_menubuttons_link" href="javascript:toggleUpload('doc');">
3681: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
3682: <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
3683: <fieldset id="uploaddocform" style="display: none;" />
3684: <legend>$lt{'upfi'}</legend>
1.371 tempelho 3685: <input type="hidden" name="active" value="aa" />
1.329 droeschl 3686: $fileupload
3687: <br />
3688: $lt{'title'}:<br />
1.458 raeburn 3689: <input type="text" size="60" name="comment" />
1.508 ! raeburn 3690: $pathitem
1.329 droeschl 3691: <input type="hidden" name="cmd" value="upload_default" />
3692: <br />
1.458 raeburn 3693: <span class="LC_nobreak" style="float:left">
1.329 droeschl 3694: $checkbox
3695: </span>
1.501 raeburn 3696: <br clear="all" />
3697: <input type="submit" value="$lt{'upld'}" />
3698: </fieldset>
3699: </form>
1.383 tempelho 3700: FUFORM
1.329 droeschl 3701:
1.502 raeburn 3702: my $importpubform=(<<SEDFFORM);
3703: <a class="LC_menubuttons_link" href="javascript:toggleMap();">
3704: $lt{'impm'}</a>$help{'Load_Map'}
3705: <form action="/adm/coursedocs" method="post" name="mapimportform">
3706: <fieldset id="importmapform" style="display: none;" />
3707: <legend>$lt{'impm'}</legend>
1.371 tempelho 3708: <input type="hidden" name="active" value="bb" />
1.502 raeburn 3709: $lt{'copm'}<br />
3710: <span class="LC_nobreak">
3711: <input type="text" name="importmap" size="40" value=""
3712: onfocus="this.blur();openbrowser('mapimportform','importmap','sequence,page','');" />
3713: <a href="javascript:openbrowser('mapimportform','importmap','sequence,page','');">$lt{'selm'}</a><br />
3714: <input type="submit" name="loadmap" value="$lt{'load'}" />
3715: </fieldset>
3716: </form>
3717:
1.383 tempelho 3718: SEDFFORM
1.502 raeburn 3719: my @importpubforma = (
1.508 ! raeburn 3720: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/src.png" alt="'.$lt{srch}.'" onclick="javascript:groupsearch()" />' => $pathitem."<a class='LC_menubuttons_link' href='javascript:groupsearch()'>$lt{'srch'}</a>" },
1.423 onken 3721: { '<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 3722: { '<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.502 raeburn 3723: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/sequence.png" alt="'.$lt{impm}.'" onclick="javascript:toggleMap();" />' => $importpubform }
1.383 tempelho 3724: );
1.502 raeburn 3725: $importpubform = &create_form_ul(&create_list_elements(@importpubforma));
1.329 droeschl 3726:
1.442 www 3727: my $extresourcesform=(<<ERFORM);
1.501 raeburn 3728: <a class="LC_menubuttons_link" href="javascript:toggleUpload('ext');">$lt{'extr'}</a>$help{'Adding_External_Resource'}
1.442 www 3729: <form action="/adm/coursedocs" method="post" name="newext">
1.501 raeburn 3730: <fieldset id="uploadextform" style="display: none;" />
3731: <legend>$lt{'extr'}</legend>
3732: <input type="hidden" name="active" value="aa" />
3733: $lt{'url'}:<br />
3734: <input type="text" size="60" name="exturl" id="exturl" value="http://" />
3735: <input type="button" name="view" value="$lt{'prev'}" onclick="javascript:extUrlPreview('exturl');" /><br />
3736: $lt{'title'}:<br />
3737: <input type="text" size="60" name="exttitle" value="$lt{'extr'}" />
1.508 ! raeburn 3738: $pathitem
1.501 raeburn 3739: <br />
1.442 www 3740: <input type="hidden" name="importdetail" value="" />
1.501 raeburn 3741: <input type="button" value="$lt{'lnk'}" onclick="javascript:setExternal(this.form,0)" />
3742: </fieldset>
1.442 www 3743: </form>
1.329 droeschl 3744: ERFORM
3745:
1.442 www 3746:
1.329 droeschl 3747: if ($allowed) {
1.492 raeburn 3748: my $folder = $env{'form.folder'};
3749: if ($folder eq '') {
3750: $folder='default';
3751: }
3752: &update_paste_buffer($coursenum,$coursedom,$folder);
1.337 ehlerst 3753: $r->print(<<HIDDENFORM);
3754: <form name="renameform" method="post" action="/adm/coursedocs">
3755: <input type="hidden" name="title" />
3756: <input type="hidden" name="cmd" />
3757: <input type="hidden" name="markcopy" />
3758: <input type="hidden" name="copyfolder" />
3759: $containertag
3760: </form>
1.484 raeburn 3761:
1.337 ehlerst 3762: HIDDENFORM
1.508 ! raeburn 3763: $r->print(&makesimpleeditform($pathitem)."\n".
! 3764: &makedocslogform($pathitem."\n".
1.484 raeburn 3765: '<input type="hidden" name="folder" value="'.
3766: $env{'form.folder'}.'" />'."\n"));
1.329 droeschl 3767: }
1.442 www 3768:
3769: # Generate the tabs
1.472 raeburn 3770: my $mode;
3771: if (($supplementalflag) && (!$allowed)) {
3772: &Apache::lonnavdisplay::startContentScreen($r,'supplemental');
3773: } else {
1.484 raeburn 3774: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.472 raeburn 3775: }
1.443 www 3776:
1.442 www 3777: #
3778:
3779: my $savefolderpath;
3780:
1.395 raeburn 3781: if ($allowed) {
1.329 droeschl 3782: my $folder=$env{'form.folder'};
1.443 www 3783: if ($folder eq '' || $supplementalflag) {
1.329 droeschl 3784: $folder='default';
1.356 tempelho 3785: $savefolderpath = $env{'form.folderpath'};
1.442 www 3786: $env{'form.folderpath'}='default&'.&escape(&mt('Content'));
1.508 ! raeburn 3787: $pathitem = '<input type="hidden" name="folderpath" value="'.
1.329 droeschl 3788: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
3789: }
3790: my $postexec='';
3791: if ($folder eq 'default') {
1.372 bisitz 3792: $r->print('<script type="text/javascript">'."\n"
3793: .'// <![CDATA['."\n"
3794: .'this.window.name="loncapaclient";'."\n"
3795: .'// ]]>'."\n"
3796: .'</script>'."\n"
1.369 bisitz 3797: );
1.329 droeschl 3798: } else {
3799: #$postexec='self.close();';
3800: }
1.504 raeburn 3801: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.sequence';
3802: my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.page';
1.329 droeschl 3803: my $container='sequence';
3804: if ($env{'form.pagepath'}) {
3805: $container='page';
3806: }
3807: my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
3808:
3809: my $newnavform=(<<NNFORM);
3810: <form action="/adm/coursedocs" method="post" name="newnav">
1.371 tempelho 3811: <input type="hidden" name="active" value="cc" />
1.508 ! raeburn 3812: $pathitem
1.329 droeschl 3813: <input type="hidden" name="importdetail"
3814: value="$lt{'navc'}=/adm/navmaps" />
1.423 onken 3815: <a class="LC_menubuttons_link" href="javascript:document.newnav.submit()">$lt{'navc'}</a>
1.329 droeschl 3816: $help{'Navigate_Content'}
3817: </form>
3818: NNFORM
3819: my $newsmppageform=(<<NSPFORM);
3820: <form action="/adm/coursedocs" method="post" name="newsmppg">
1.371 tempelho 3821: <input type="hidden" name="active" value="cc" />
1.508 ! raeburn 3822: $pathitem
1.329 droeschl 3823: <input type="hidden" name="importdetail" value="" />
1.423 onken 3824: <a class="LC_menubuttons_link" href="javascript:makesmppage();"> $lt{'sipa'}</a>
1.383 tempelho 3825: $help{'Simple Page'}
1.329 droeschl 3826: </form>
3827: NSPFORM
3828:
3829: my $newsmpproblemform=(<<NSPROBFORM);
3830: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
1.371 tempelho 3831: <input type="hidden" name="active" value="cc" />
1.508 ! raeburn 3832: $pathitem
1.329 droeschl 3833: <input type="hidden" name="importdetail" value="" />
1.423 onken 3834: <a class="LC_menubuttons_link" href="javascript:makesmpproblem();">$lt{'sipr'}</a>
1.383 tempelho 3835: $help{'Simple Problem'}
1.329 droeschl 3836: </form>
3837:
3838: NSPROBFORM
3839:
3840: my $newdropboxform=(<<NDBFORM);
3841: <form action="/adm/coursedocs" method="post" name="newdropbox">
1.371 tempelho 3842: <input type="hidden" name="active" value="cc" />
1.508 ! raeburn 3843: $pathitem
1.329 droeschl 3844: <input type="hidden" name="importdetail" value="" />
1.423 onken 3845: <a class="LC_menubuttons_link" href="javascript:makedropbox();">$lt{'drbx'}</a>
1.344 bisitz 3846: </form>
1.329 droeschl 3847: NDBFORM
3848:
3849: my $newexuploadform=(<<NEXUFORM);
3850: <form action="/adm/coursedocs" method="post" name="newexamupload">
1.371 tempelho 3851: <input type="hidden" name="active" value="cc" />
1.508 ! raeburn 3852: $pathitem
1.329 droeschl 3853: <input type="hidden" name="importdetail" value="" />
1.423 onken 3854: <a class="LC_menubuttons_link" href="javascript:makeexamupload();">$lt{'scuf'}</a>
1.329 droeschl 3855: $help{'Score_Upload_Form'}
3856: </form>
3857: NEXUFORM
3858:
3859: my $newbulform=(<<NBFORM);
3860: <form action="/adm/coursedocs" method="post" name="newbul">
1.371 tempelho 3861: <input type="hidden" name="active" value="cc" />
1.508 ! raeburn 3862: $pathitem
1.329 droeschl 3863: <input type="hidden" name="importdetail" value="" />
1.423 onken 3864: <a class="LC_menubuttons_link" href="javascript:makebulboard();" >$lt{'bull'}</a>
1.329 droeschl 3865: $help{'Bulletin Board'}
3866: </form>
3867: NBFORM
3868:
3869: my $newaboutmeform=(<<NAMFORM);
3870: <form action="/adm/coursedocs" method="post" name="newaboutme">
1.371 tempelho 3871: <input type="hidden" name="active" value="cc" />
1.508 ! raeburn 3872: $pathitem
1.329 droeschl 3873: <input type="hidden" name="importdetail"
3874: value="$plainname=/adm/$udom/$uname/aboutme" />
1.423 onken 3875: <a class="LC_menubuttons_link" href="javascript:document.newaboutme.submit()">$lt{'mypi'}</a>
1.347 weissno 3876: $help{'My Personal Information Page'}
1.329 droeschl 3877: </form>
3878: NAMFORM
3879:
3880: my $newaboutsomeoneform=(<<NASOFORM);
3881: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
1.371 tempelho 3882: <input type="hidden" name="active" value="cc" />
1.508 ! raeburn 3883: $pathitem
1.329 droeschl 3884: <input type="hidden" name="importdetail" value="" />
1.423 onken 3885: <a class="LC_menubuttons_link" href="javascript:makeabout();">$lt{'abou'}</a>
1.329 droeschl 3886: </form>
3887: NASOFORM
3888:
3889:
3890: my $newrosterform=(<<NROSTFORM);
3891: <form action="/adm/coursedocs" method="post" name="newroster">
1.371 tempelho 3892: <input type="hidden" name="active" value="cc" />
1.508 ! raeburn 3893: $pathitem
1.329 droeschl 3894: <input type="hidden" name="importdetail"
3895: value="$lt{'rost'}=/adm/viewclasslist" />
1.423 onken 3896: <a class="LC_menubuttons_link" href="javascript:document.newroster.submit()">$lt{'rost'}</a>
1.329 droeschl 3897: $help{'Course Roster'}
3898: </form>
3899: NROSTFORM
3900:
1.342 ehlerst 3901: my $specialdocumentsform;
1.383 tempelho 3902: my @specialdocumentsforma;
1.451 www 3903: my $gradingform;
3904: my @gradingforma;
3905: my $communityform;
3906: my @communityforma;
1.351 ehlerst 3907: my $newfolderform;
1.390 tempelho 3908: my $newfolderb;
1.342 ehlerst 3909:
1.451 www 3910: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.383 tempelho 3911:
1.329 droeschl 3912: my $newpageform=(<<NPFORM);
3913: <form action="/adm/coursedocs" method="post" name="newpage">
3914: <input type="hidden" name="folderpath" value="$path" />
3915: <input type="hidden" name="importdetail" value="" />
1.371 tempelho 3916: <input type="hidden" name="active" value="cc" />
1.423 onken 3917: <a class="LC_menubuttons_link" href="javascript:makenewpage(document.newpage,'$pageseq');">$lt{'newp'}</a>
1.383 tempelho 3918: $help{'Adding_Pages'}
1.329 droeschl 3919: </form>
3920: NPFORM
1.390 tempelho 3921:
3922:
1.351 ehlerst 3923: $newfolderform=(<<NFFORM);
1.329 droeschl 3924: <form action="/adm/coursedocs" method="post" name="newfolder">
1.508 ! raeburn 3925: $pathitem
1.329 droeschl 3926: <input type="hidden" name="importdetail" value="" />
1.371 tempelho 3927: <input type="hidden" name="active" value="aa" />
1.422 onken 3928: <a href="javascript:makenewfolder(document.newfolder,'$folderseq');">$lt{'newf'}</a>$help{'Adding_Folders'}
1.329 droeschl 3929: </form>
3930: NFFORM
3931:
3932: my $newsylform=(<<NSYLFORM);
3933: <form action="/adm/coursedocs" method="post" name="newsyl">
1.371 tempelho 3934: <input type="hidden" name="active" value="cc" />
1.508 ! raeburn 3935: $pathitem
1.329 droeschl 3936: <input type="hidden" name="importdetail"
3937: value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />
1.423 onken 3938: <a class="LC_menubuttons_link" href="javascript:document.newsyl.submit()">$lt{'syll'}</a>
1.329 droeschl 3939: $help{'Syllabus'}
1.383 tempelho 3940:
1.329 droeschl 3941: </form>
3942: NSYLFORM
1.364 bisitz 3943:
1.329 droeschl 3944: my $newgroupfileform=(<<NGFFORM);
3945: <form action="/adm/coursedocs" method="post" name="newgroupfiles">
1.371 tempelho 3946: <input type="hidden" name="active" value="cc" />
1.508 ! raeburn 3947: $pathitem
1.329 droeschl 3948: <input type="hidden" name="importdetail"
3949: value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
1.423 onken 3950: <a class="LC_menubuttons_link" href="javascript:document.newgroupfiles.submit()">$lt{'grpo'}</a>
1.353 weissno 3951: $help{'Group Portfolio'}
1.329 droeschl 3952: </form>
3953: NGFFORM
1.383 tempelho 3954: @specialdocumentsforma=(
1.421 onken 3955: {'<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 3956: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="document.newsyl.submit()" />'=>$newsylform},
1.451 www 3957: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/navigation.png" alt="'.$lt{navc}.'" onclick="document.newnav.submit()" />'=>$newnavform},
3958: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simple.png" alt="'.$lt{sipa}.'" onclick="javascript:makesmppage();" />'=>$newsmppageform},
3959: );
3960: $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma));
3961:
1.434 raeburn 3962:
3963: my @importdoc = (
1.501 raeburn 3964: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="toggleUpload(\'ext\');" />'=>$extresourcesform},
3965: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/ims.png" alt="'.$lt{imsf}.'" onclick="javascript:toggleUpload(\'ims\');" />'=>$imspform},
3966: {'<img class="LC_noBorder_LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'doc\');" />'=>$fileuploadform,
3967: });
3968: $fileuploadform = &create_form_ul(&create_list_elements(@importdoc));
1.434 raeburn 3969:
1.451 www 3970: @gradingforma=(
3971: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{sipr}.'" onclick="javascript:makesmpproblem();" />'=>$newsmpproblemform},
3972: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/dropbox.png" alt="'.$lt{drbx}.'" onclick="javascript:makedropbox();" />'=>$newdropboxform},
3973: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/scoreupfrm.png" alt="'.$lt{scuf}.'" onclick="javascript:makeexamupload();" />'=>$newexuploadform},
3974:
3975: );
3976: $gradingform = &create_form_ul(&create_list_elements(@gradingforma));
3977:
3978: @communityforma=(
3979: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/bchat.png" alt="'.$lt{bull}.'" onclick="javascript:makebulboard();" />'=>$newbulform},
3980: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makebulboard();" />'=>$newaboutmeform},
3981: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/aboutme.png" alt="'.$lt{abou}.'" onclick="javascript:makeabout();" />'=>$newaboutsomeoneform},
3982: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/clst.png" alt="'.$lt{rost}.'" onclick="document.newroster.submit()" />'=>$newrosterform},
3983: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/groupportfolio.png" alt="'.$lt{grpo}.'" onclick="document.newgroupfiles.submit()" />'=>$newgroupfileform},
3984: );
3985: $communityform = &create_form_ul(&create_list_elements(@communityforma));
1.383 tempelho 3986:
1.330 tempelho 3987: my %orderhash = (
1.488 raeburn 3988: 'aa' => ['Import Content',$fileuploadform],
1.502 raeburn 3989: 'bb' => ['Published Content',$importpubform],
1.451 www 3990: 'cc' => ['Grading Resources',$gradingform],
1.330 tempelho 3991: );
1.451 www 3992: unless ($env{'form.pagepath'}) {
1.434 raeburn 3993: $orderhash{'00'} = ['Newfolder',$newfolderform];
1.484 raeburn 3994: $orderhash{'dd'} = ['Collaboration',$communityform];
1.451 www 3995: $orderhash{'ee'} = ['Special Documents',$specialdocumentsform];
1.434 raeburn 3996: }
3997:
1.341 ehlerst 3998: $hadchanges=0;
1.484 raeburn 3999: unless (($supplementalflag || $toolsflag)) {
1.458 raeburn 4000: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.508 ! raeburn 4001: $supplementalflag,\%orderhash,$iconpath,$pathitem);
1.443 www 4002: if ($error) {
4003: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
4004: }
4005: if ($hadchanges) {
4006: &mark_hash_old();
4007: }
1.341 ehlerst 4008:
1.443 www 4009: &changewarning($r,'');
4010: }
1.458 raeburn 4011: }
1.442 www 4012:
1.443 www 4013: # Supplemental documents start here
4014:
1.329 droeschl 4015: my $folder=$env{'form.folder'};
1.443 www 4016: unless ($supplementalflag) {
1.329 droeschl 4017: $folder='supplemental';
4018: }
4019: if ($folder =~ /^supplemental$/ &&
4020: (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
1.446 www 4021: $env{'form.folderpath'} = &supplemental_base();
1.393 raeburn 4022: } elsif ($allowed) {
1.356 tempelho 4023: $env{'form.folderpath'} = $savefolderpath;
1.329 droeschl 4024: }
1.362 ehlerst 4025: $env{'form.pagepath'} = '';
1.508 ! raeburn 4026: $pathitem = '<input type="hidden" name="folderpath" value="'.
! 4027: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
1.329 droeschl 4028: if ($allowed) {
4029: my $folderseq=
1.504 raeburn 4030: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_new.sequence';
1.329 droeschl 4031:
4032: my $supupdocform=(<<SUPDOCFORM);
1.501 raeburn 4033: <a class="LC_menubuttons_link" href="javascript:toggleUpload('suppdoc');">
4034: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
1.383 tempelho 4035: <form action="/adm/coursedocs" method="post" name="supuploaddocument" enctype="multipart/form-data">
1.501 raeburn 4036: <fieldset id="uploadsuppdocform" style="display: none;" />
4037: <legend>$lt{'upfi'}</legend>
1.371 tempelho 4038: <input type="hidden" name="active" value="ee" />
1.329 droeschl 4039: $fileupload
4040: <br />
4041: <br />
4042: <span class="LC_nobreak">
4043: $checkbox
4044: </span>
4045: <br /><br />
4046: $lt{'comment'}:<br />
1.383 tempelho 4047: <textarea cols="50" rows="4" name="comment"></textarea>
1.329 droeschl 4048: <br />
1.508 ! raeburn 4049: $pathitem
1.329 droeschl 4050: <input type="hidden" name="cmd" value="upload_supplemental" />
1.501 raeburn 4051: <input type='submit' value="$lt{'upld'}" />
4052: </form>
1.329 droeschl 4053: SUPDOCFORM
4054:
4055: my $supnewfolderform=(<<SNFFORM);
4056: <form action="/adm/coursedocs" method="post" name="supnewfolder">
1.371 tempelho 4057: <input type="hidden" name="active" value="ee" />
1.508 ! raeburn 4058: $pathitem
1.329 droeschl 4059: <input type="hidden" name="importdetail" value="" />
1.423 onken 4060: <a class="LC_menubuttons_link" href="javascript:makenewfolder(document.supnewfolder,'$folderseq');">$lt{'newf'}</a>
1.383 tempelho 4061: $help{'Adding_Folders'}
1.329 droeschl 4062: </form>
4063: SNFFORM
1.383 tempelho 4064:
1.501 raeburn 4065: my $supextform=(<<ERFORM);
4066: <a class="LC_menubuttons_link" href="javascript:toggleUpload('suppext');">$lt{'extr'}</a>$help{'Adding_External_Resource'}
4067: <form action="/adm/coursedocs" method="post" name="newsuppext">
4068: <fieldset id="uploadsuppextform" style="display: none;" />
4069: <legend>$lt{'extr'}</legend>
4070: <input type="hidden" name="active" value="ee" />
4071: $lt{'url'}:<br />
4072: <input type="text" size="60" name="exturl" id="exturl" value="http://" />
4073: <input type="button" name="view" value="$lt{'prev'}" onclick="javascript:extUrlPreview('exturl');" /><br />
4074: $lt{'title'}:<br />
4075: <input type="text" size="60" name="exttitle" value="$lt{'extr'}" />
4076: <br />
1.508 ! raeburn 4077: $pathitem
1.501 raeburn 4078: <input type="hidden" name="importdetail" value="" />
4079: <input type="button" value="$lt{'lnk'}" onclick="javascript:setExternal(this.form,0)" />
4080: </fieldset>
4081: </form>
4082: ERFORM
1.329 droeschl 4083:
4084: my $supnewsylform=(<<SNSFORM);
4085: <form action="/adm/coursedocs" method="post" name="supnewsyl">
1.371 tempelho 4086: <input type="hidden" name="active" value="ff" />
1.508 ! raeburn 4087: $pathitem
1.329 droeschl 4088: <input type="hidden" name="importdetail"
4089: value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
1.423 onken 4090: <a class="LC_menubuttons_link" href="javascript:document.supnewsyl.submit()">$lt{'syll'}</a>
1.329 droeschl 4091: $help{'Syllabus'}
4092: </form>
4093: SNSFORM
4094:
4095: my $supnewaboutmeform=(<<SNAMFORM);
1.383 tempelho 4096: <form action="/adm/coursedocs" method="post" name="supnewaboutme">
1.371 tempelho 4097: <input type="hidden" name="active" value="ff" />
1.508 ! raeburn 4098: $pathitem
1.329 droeschl 4099: <input type="hidden" name="importdetail"
4100: value="$plainname=/adm/$udom/$uname/aboutme" />
1.423 onken 4101: <a class="LC_menubuttons_link" href="javascript:document.supnewaboutme.submit()">$lt{'mypi'}</a>
1.347 weissno 4102: $help{'My Personal Information Page'}
1.329 droeschl 4103: </form>
4104: SNAMFORM
4105:
1.333 muellerd 4106:
1.383 tempelho 4107: my @specialdocs = (
1.417 droeschl 4108: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="document.supnewsyl.submit()" />'
4109: =>$supnewsylform},
4110: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="document.supnewaboutme.submit()" />'
4111: =>$supnewaboutmeform},
1.383 tempelho 4112: );
1.417 droeschl 4113: my @supimportdoc = (
1.501 raeburn 4114: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="toggleUpload(\'suppext\')" />'
4115: =>$supextform},
4116: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'suppdoc\');" />'
4117: =>$supupdocform},
4118: );
4119:
4120: $supupdocform = &create_form_ul(&create_list_elements(@supimportdoc));
1.333 muellerd 4121: my %suporderhash = (
1.390 tempelho 4122: '00' => ['Supnewfolder', $supnewfolderform],
1.488 raeburn 4123: 'ee' => ['Import Content',$supupdocform],
1.443 www 4124: 'ff' => ['Special Documents',&create_form_ul(&create_list_elements(@specialdocs))]
1.333 muellerd 4125: );
1.443 www 4126: if ($supplementalflag) {
1.458 raeburn 4127: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.508 ! raeburn 4128: $supplementalflag,\%suporderhash,$iconpath,$pathitem);
1.443 www 4129: if ($error) {
4130: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
4131: }
1.393 raeburn 4132: }
1.443 www 4133: } elsif ($supplementalflag) {
1.458 raeburn 4134: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.508 ! raeburn 4135: $supplementalflag,'',$iconpath,$pathitem);
1.393 raeburn 4136: if ($error) {
4137: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.383 tempelho 4138: }
1.393 raeburn 4139: }
1.389 tempelho 4140:
1.484 raeburn 4141: $r->print(&endContentScreen());
1.383 tempelho 4142:
1.329 droeschl 4143: if ($allowed) {
4144: $r->print('
4145: <form method="post" name="extimport" action="/adm/coursedocs">
4146: <input type="hidden" name="title" />
4147: <input type="hidden" name="url" />
4148: <input type="hidden" name="useform" />
4149: <input type="hidden" name="residx" />
4150: </form>');
4151: }
1.484 raeburn 4152: } elsif ($showdoc) {
1.329 droeschl 4153: # -------------------------------------------------------- This is showdoc mode
1.484 raeburn 4154: $r->print("<h1>".&mt('Uploaded Document').' - '.
1.498 bisitz 4155: &Apache::lonnet::gettitle($r->uri).'</h1><p class="LC_warning">'.
1.329 droeschl 4156: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><table>".
1.484 raeburn 4157: &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');
1.329 droeschl 4158: }
4159: }
4160: $r->print(&Apache::loncommon::end_page());
4161: return OK;
1.364 bisitz 4162: }
1.329 droeschl 4163:
1.440 raeburn 4164: sub embedded_form_elems {
4165: my ($phase,$primaryurl,$newidx) = @_;
4166: my $folderpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
4167: return <<STATE;
4168: <input type="hidden" name="folderpath" value="$folderpath" />
4169: <input type="hidden" name="cmd" value="upload_embedded" />
4170: <input type="hidden" name="newidx" value="$newidx" />
4171: <input type="hidden" name="phase" value="$phase" />
4172: <input type="hidden" name="primaryurl" value="$primaryurl" />
4173: STATE
4174: }
4175:
4176: sub embedded_destination {
4177: my $folder=$env{'form.folder'};
4178: my $destination = 'docs/';
4179: if ($folder =~ /^supplemental/) {
4180: $destination = 'supplemental/';
4181: }
4182: if (($folder eq 'default') || ($folder eq 'supplemental')) {
4183: $destination .= 'default/';
4184: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
4185: $destination .= $2.'/';
4186: }
4187: $destination .= $env{'form.newidx'};
4188: my $dir_root = '/userfiles';
4189: return ($destination,$dir_root);
4190: }
4191:
4192: sub return_to_editor {
4193: my $actionurl = '/adm/coursedocs';
4194: return '<p><form name="backtoeditor" method="post" action="'.$actionurl.'" />'."\n".
4195: '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" /></form>'."\n".
4196: '<a href="javascript:document.backtoeditor.submit();">'.&mt('Return to Editor').
4197: '</a></p>';
4198: }
4199:
1.476 raeburn 4200: sub decompression_info {
4201: my ($destination,$dir_root) = &embedded_destination();
4202: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
4203: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
4204: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
4205: my $container='sequence';
1.480 raeburn 4206: my ($pathitem,$hiddenelem);
4207: my @hiddens = ('newidx','comment','position');
1.476 raeburn 4208: if ($env{'form.pagepath'}) {
4209: $container='page';
1.480 raeburn 4210: $pathitem = 'pagepath';
1.476 raeburn 4211: } else {
1.480 raeburn 4212: $pathitem = 'folderpath';
1.476 raeburn 4213: }
1.480 raeburn 4214: unshift(@hiddens,$pathitem);
4215: foreach my $item (@hiddens) {
4216: if ($env{'form.'.$item}) {
4217: $hiddenelem .= '<input type="hidden" name="'.$item.'" value="'.
4218: $env{'form.'.$item}.'" />'."\n";
4219: }
1.477 raeburn 4220: }
1.476 raeburn 4221: return ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,
4222: $hiddenelem);
4223: }
4224:
4225: sub decompression_phase_one {
4226: my ($dir,$file,$warning,$error,$output);
4227: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
4228: &decompression_info();
1.490 raeburn 4229: if ($env{'form.archiveurl'} !~ m{^/uploaded/\Q$docudom/$docuname/\E(?:docs|supplemental)/(?:default|\d+).*/([^/]+)$}) {
1.476 raeburn 4230: $error = &mt('Archive file "[_1]" not in the expected location.',$env{'form.archiveurl'});
4231: } else {
4232: my $file = $1;
1.481 raeburn 4233: $output =
4234: &Apache::loncommon::process_decompression($docudom,$docuname,$file,
4235: $destination,$dir_root,
4236: $hiddenelem);
4237: if ($env{'form.autoextract_camtasia'}) {
4238: $output .= &remove_archive($docudom,$docuname,$container);
4239: }
1.476 raeburn 4240: }
4241: if ($error) {
4242: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
4243: $error.'</p>'."\n";
4244: }
4245: if ($warning) {
4246: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
4247: }
4248: return $output;
4249: }
4250:
4251: sub decompression_phase_two {
4252: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
4253: &decompression_info();
1.481 raeburn 4254: my $output;
1.480 raeburn 4255: if ($env{'form.archivedelete'}) {
1.481 raeburn 4256: $output = &remove_archive($docudom,$docuname,$container);
1.480 raeburn 4257: }
4258: $output .=
1.481 raeburn 4259: &Apache::loncommon::process_extracted_files('coursedocs',$docudom,$docuname,
1.476 raeburn 4260: $destination,$dir_root,$hiddenelem);
4261: return $output;
4262: }
4263:
1.480 raeburn 4264: sub remove_archive {
4265: my ($docudom,$docuname,$container) = @_;
4266: my $map = $env{'form.folder'}.'.'.$container;
1.481 raeburn 4267: my ($output,$delwarning,$delresult,$url);
1.480 raeburn 4268: my ($errtext,$fatal) = &mapread($docuname,$docudom,$map);
4269: if ($fatal) {
4270: if ($container eq 'page') {
4271: $delwarning = &mt('An error occurred retrieving the contents of the current page.');
4272: } else {
4273: $delwarning = &mt('An error occurred retrieving the contents of the current folder.');
4274: }
4275: $delwarning .= &mt('As a result the archive file has not been removed.');
4276: } else {
4277: my $currcmd = $env{'form.cmd'};
4278: my $position = $env{'form.position'};
4279: if ($position > 0) {
4280: $env{'form.cmd'} = 'del_'.$position;
4281: my ($title,$url,@rrest) =
4282: split(/:/,$LONCAPA::map::resources[$LONCAPA::map::order[$position]]);
4283: if (&handle_edit_cmd($docuname,$docudom)) {
1.492 raeburn 4284: ($errtext,$fatal) = &storemap($docuname,$docudom,$map,1);
1.480 raeburn 4285: if ($fatal) {
4286: if ($container eq 'page') {
4287: $delwarning = &mt('An error occurred updating the contents of the current page.');
4288: } else {
4289: $delwarning = &mt('An error occurred updating the contents of the current folder.');
4290: }
4291: } else {
1.481 raeburn 4292: $delresult = &mt('Archive file removed.');
1.480 raeburn 4293: }
4294: }
4295: }
4296: $env{'form.cmd'} = $currcmd;
4297: }
4298: if ($delwarning) {
4299: $output = '<p class="LC_warning">'.
4300: $delwarning.
4301: '</p>';
4302: }
4303: if ($delresult) {
4304: $output .= '<p class="LC_info">'.
4305: $delresult.
4306: '</p>';
4307: }
1.481 raeburn 4308: return $output;
1.480 raeburn 4309: }
4310:
1.484 raeburn 4311: sub generate_admin_menu {
4312: my ($crstype) = @_;
4313: my $lc_crstype = lc($crstype);
4314: my ($home,$other,%outhash)=&authorhosts();
4315: my %lt=&Apache::lonlocal::texthash (
4316: 'vc' => 'Verify Content',
4317: 'cv' => 'Check/Set Resource Versions',
4318: 'ls' => 'List Resource Identifiers',
4319: 'imse' => 'Export contents to IMS Archive',
4320: 'dcd' => "Dump $crstype Content to Authoring Space",
4321: );
4322: my ($candump,$dumpurl);
4323: if ($home + $other > 0) {
4324: $candump = 'F';
4325: if ($home) {
4326: $dumpurl = "javascript:injectData(document.courseverify,'dummy','dumpcourse','$lt{'dcd'}')";
4327: } else {
4328: my @hosts;
4329: foreach my $aurole (keys(%outhash)) {
4330: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
4331: push(@hosts,$outhash{$aurole});
4332: }
4333: }
4334: if (@hosts == 1) {
4335: my $switchto = '/adm/switchserver?otherserver='.$hosts[0].
4336: '&role='.
4337: &HTML::Entities::encode($env{'request.role'},'"<>&').'&origurl='.
4338: &HTML::Entities::encode('/adm/coursedocs?dumpcourse=1','"<>&');
4339: $dumpurl = "javascript:dump_needs_switchserver('$switchto')";
4340: } else {
4341: $dumpurl = "javascript:choose_switchserver_window()";
4342: }
4343: }
4344: }
4345: my @menu=
4346: ({ categorytitle=>'Administration',
4347: items =>[
4348: { linktext => $lt{'vc'},
4349: url => "javascript:injectData(document.courseverify,'dummy','verify','$lt{'vc'}')",
4350: permission => 'F',
4351: help => 'Verify_Content',
4352: icon => 'verify.png',
4353: linktitle => 'Verify contents can be retrieved/rendered',
4354: },
4355: { linktext => $lt{'cv'},
4356: url => "javascript:injectData(document.courseverify,'dummy','versions','$lt{'cv'}')",
4357: permission => 'F',
4358: help => 'Check_Resource_Versions',
4359: icon => 'resversion.png',
4360: linktitle => "View version information for resources in your $lc_crstype, and fix/unfix use of specific versions",
4361: },
4362: { linktext => $lt{'ls'},
4363: url => "javascript:injectData(document.courseverify,'dummy','listsymbs','$lt{'ls'}')",
4364: permission => 'F',
4365: #help => '',
4366: icon => 'symbs.png',
4367: linktitle => "List the unique identifier used for each resource instance in your $lc_crstype"
4368: },
4369: ]
4370: },
4371: { categorytitle=>'Export',
4372: items =>[
4373: { linktext => $lt{'imse'},
4374: url => "javascript:injectData(document.courseverify,'dummy','exportcourse','$lt{'imse'}')",
4375: permission => 'F',
4376: help => 'Docs_Export_Course_Docs',
4377: icon => 'imsexport.png',
4378: linktitle => $lt{'imse'},
4379: },
4380: { linktext => $lt{'dcd'},
4381: url => $dumpurl,
4382: permission => $candump,
4383: #help => '',
4384: icon => 'dump.png',
4385: linktitle => $lt{'dcd'},
4386: },
4387: ]
4388: });
4389: return '<form action="/adm/coursedocs" method="post" name="courseverify">'."\n".
4390: '<input type="hidden" id="dummy" />'."\n".
4391: &Apache::lonhtmlcommon::generate_menu(@menu)."\n".
4392: '</form>';
1.329 droeschl 4393: }
4394:
4395: sub generate_edit_table {
1.484 raeburn 4396: my ($tid,$orderhash_ref,$to_show,$iconpath,$jumpto,$readfile) = @_;
1.406 raeburn 4397: return unless(ref($orderhash_ref) eq 'HASH');
1.342 ehlerst 4398: my %orderhash = %{$orderhash_ref};
1.344 bisitz 4399: my $form;
1.371 tempelho 4400: my $activetab;
4401: my $active;
4402: if($env{'form.active'} ne ''){
4403: $activetab = $env{'form.active'};
4404: }
1.472 raeburn 4405: my $backicon = $iconpath.'clickhere.gif';
1.481 raeburn 4406: my $backtext = &mt('To Overview');
1.458 raeburn 4407: $form = '<div class="LC_Box" style="margin:0;">'.
1.488 raeburn 4408: '<ul id="navigation'.$tid.'" class="LC_TabContent">'."\n".
4409: '<li class="goback">'.
4410: '<a href="javascript:toContents('."'$jumpto'".');">'.
4411: '<img src="'.$backicon.'" class="LC_icon" style="border: none; vertical-align: top;"'.
4412: ' alt="'.$backtext.'" />'.$backtext.'</a></li>'."\n".
4413: '<li>'.
4414: '<a href="javascript:groupopen('."'$readfile'".',1);">'.
4415: &mt('Undo Delete').'</a></li>'."\n";
4416: if ($env{'form.docslog'}) {
4417: $form .= '<li class="active">';
4418: } else {
4419: $form .= '<li>';
4420: }
4421: $form .= '<a href="javascript:toggleHistoryDisp(1);">'.
4422: &mt('History').'</a></li>'."\n";
4423: if ($env{'form.docslog'}) {
4424: $form .= '<li><a href="javascript:toggleHistoryDisp(0);">'.
4425: &mt('Edit').'</a></li>'."\n";
1.484 raeburn 4426: }
1.458 raeburn 4427: foreach my $name (reverse(sort(keys(%orderhash)))) {
1.390 tempelho 4428: if($name ne '00'){
1.371 tempelho 4429: if($activetab eq '' || $activetab ne $name){
4430: $active = '';
4431: }elsif($activetab eq $name){
4432: $active = 'class="active"';
4433: }
1.458 raeburn 4434: $form .= '<li style="float:right" '.$active
1.484 raeburn 4435: .' 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 4436: } else {
1.484 raeburn 4437: $form .= '<li '.$active.' style="float:right">'.${$orderhash{$name}}[1].'</li>'."\n";
1.390 tempelho 4438:
4439: }
1.329 droeschl 4440: }
1.484 raeburn 4441: $form .= '</ul>'."\n";
4442: $form .= '<div id="content'.$tid.'" style="padding: 0 0; margin: 0 0; overflow: hidden; clear:right">'."\n";
1.458 raeburn 4443:
4444: if ($to_show ne '') {
1.484 raeburn 4445: $form .= '<div style="padding:0;margin:0;float:left">'.$to_show.'</div>'."\n";
1.458 raeburn 4446: }
1.363 ehlerst 4447: foreach my $field (keys(%orderhash)){
1.390 tempelho 4448: if($field ne '00'){
1.422 onken 4449: if($activetab eq '' || $activetab ne $field){
1.458 raeburn 4450: $active = 'style="display: none;float:left"';
1.422 onken 4451: }elsif($activetab eq $field){
1.458 raeburn 4452: $active = 'style="display:block;float:left"';
1.422 onken 4453: }
4454: $form .= '<div id="'.$field.$tid.'"'
4455: .' class="LC_ContentBox" '.$active.'>'.${$orderhash{$field}}[1]
1.484 raeburn 4456: .'</div>'."\n";
1.363 ehlerst 4457: }
4458: }
1.484 raeburn 4459: unless ($env{'form.docslog'}) {
4460: $form .= '</div></div>'."\n";
4461: }
1.329 droeschl 4462: return $form;
4463: }
4464:
4465: sub editing_js {
1.472 raeburn 4466: my ($udom,$uname,$supplementalflag) = @_;
1.329 droeschl 4467: my $now = time();
4468: my %lt = &Apache::lonlocal::texthash(
4469: p_mnf => 'Name of New Folder',
4470: t_mnf => 'New Folder',
4471: p_mnp => 'Name of New Page',
4472: t_mnp => 'New Page',
1.451 www 4473: p_mxu => 'Title for the External Score',
1.349 biermanm 4474: p_msp => 'Name of Simple Course Page',
1.329 droeschl 4475: p_msb => 'Title for the Problem',
4476: p_mdb => 'Title for the Drop Box',
1.336 schafran 4477: p_mbb => 'Title for the Discussion Board',
1.348 weissno 4478: p_mab => "Enter user:domain for User's Personal Information Page",
1.352 bisitz 4479: p_mab2 => 'Personal Information Page of ',
1.329 droeschl 4480: p_mab_alrt1 => 'Not a valid user:domain',
4481: p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',
4482: p_chn => 'New Title',
4483: p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',
4484: p_rmr2a => 'Remove[_99]',
4485: p_rmr2b => '?[_99]',
4486: p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',
4487: p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',
4488: p_ctr2a => 'Cut[_98]',
1.478 raeburn 4489: p_ctr2b => '?[_98]',
4490: rpck => 'Enter number to pick (e.g., 3)',
1.501 raeburn 4491: imsfile => 'You must choose an IMS package for import',
4492: imscms => 'You must select which Course Management System was the source of the IMS package',
4493: invurl => 'Invalid URL',
4494: titbl => 'Title is blank',
1.329 droeschl 4495: );
4496:
1.433 raeburn 4497: my $crstype = &Apache::loncommon::course_type();
1.434 raeburn 4498: my $docs_folderpath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'},'<>&"');
4499: my $docs_pagepath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.pagepath'},'<>&"');
4500: my $main_container_page;
4501: if ($docs_folderpath eq '') {
4502: if ($docs_pagepath ne '') {
4503: $main_container_page = 1;
4504: }
4505: }
1.433 raeburn 4506: my $toplevelmain = 'default&Main%20'.$crstype.'%20Documents';
1.446 www 4507: my $toplevelsupp = &supplemental_base();
1.433 raeburn 4508:
1.472 raeburn 4509: my $backtourl = '/adm/navmaps';
4510: if ($supplementalflag) {
4511: $backtourl = '/adm/supplemental';
4512: }
4513:
1.501 raeburn 4514: my $fieldsets = "'ext','doc','ims'";
4515: if ($supplementalflag) {
4516: $fieldsets = "'suppext','suppdoc'";
4517: }
4518:
4519: my $urlregexp = <<'ENDREGEXP';
4520: /^([a-z]([a-z]|\d|\+|-|\.)*):(\/\/(((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:)*@)?((\[(|(v[\da-f]{1,}\.(([a-z]|\d|-|\.|_|~)|[!\$&'\(\)\*\+,;=]|:)+))\])|((\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]))|(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=])*)(:\d*)?)(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*|(\/((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)?)|((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)+(\/(([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)*)*)|((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)){0})(\?((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|[\uE000-\uF8FF]|\/|\?)*)?(\#((([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(%[\da-f]{2})|[!\$&'\(\)\*\+,;=]|:|@)|\/|\?)*)?$/i
4521: ENDREGEXP
4522:
1.329 droeschl 4523: return <<ENDNEWSCRIPT;
4524: function makenewfolder(targetform,folderseq) {
4525: var foldername=prompt('$lt{"p_mnf"}','$lt{"t_mnf"}');
4526: if (foldername) {
4527: targetform.importdetail.value=escape(foldername)+"="+folderseq;
4528: targetform.submit();
4529: }
4530: }
4531:
4532: function makenewpage(targetform,folderseq) {
4533: var pagename=prompt('$lt{"p_mnp"}','$lt{"t_mnp"}');
4534: if (pagename) {
4535: targetform.importdetail.value=escape(pagename)+"="+folderseq;
4536: targetform.submit();
4537: }
4538: }
4539:
1.501 raeburn 4540: function editext(residx) {
4541: if (document.getElementById('uploadext'+residx)) {
4542: var curr = document.getElementById('uploadext'+residx).style.display;
4543: if (curr == 'none') {
4544: disp = 'block';
4545: } else {
4546: disp = 'none';
4547: }
4548: document.getElementById('uploadext'+residx).style.display=disp;
4549: }
4550: resize_scrollbox('contentscroll','1','1');
4551: return;
1.329 droeschl 4552: }
4553:
4554: function makeexamupload() {
4555: var title=prompt('$lt{"p_mxu"}');
1.344 bisitz 4556: if (title) {
1.329 droeschl 4557: this.document.forms.newexamupload.importdetail.value=
4558: escape(title)+'=/res/lib/templates/examupload.problem';
4559: this.document.forms.newexamupload.submit();
4560: }
4561: }
4562:
4563: function makesmppage() {
4564: var title=prompt('$lt{"p_msp"}');
1.344 bisitz 4565: if (title) {
1.329 droeschl 4566: this.document.forms.newsmppg.importdetail.value=
4567: escape(title)+'=/adm/$udom/$uname/$now/smppg';
4568: this.document.forms.newsmppg.submit();
4569: }
4570: }
4571:
4572: function makesmpproblem() {
4573: var title=prompt('$lt{"p_msb"}');
1.344 bisitz 4574: if (title) {
1.329 droeschl 4575: this.document.forms.newsmpproblem.importdetail.value=
4576: escape(title)+'=/res/lib/templates/simpleproblem.problem';
4577: this.document.forms.newsmpproblem.submit();
4578: }
4579: }
4580:
4581: function makedropbox() {
4582: var title=prompt('$lt{"p_mdb"}');
1.344 bisitz 4583: if (title) {
1.329 droeschl 4584: this.document.forms.newdropbox.importdetail.value=
4585: escape(title)+'=/res/lib/templates/DropBox.problem';
4586: this.document.forms.newdropbox.submit();
4587: }
4588: }
4589:
4590: function makebulboard() {
4591: var title=prompt('$lt{"p_mbb"}');
4592: if (title) {
4593: this.document.forms.newbul.importdetail.value=
4594: escape(title)+'=/adm/$udom/$uname/$now/bulletinboard';
4595: this.document.forms.newbul.submit();
4596: }
4597: }
4598:
4599: function makeabout() {
4600: var user=prompt("$lt{'p_mab'}");
4601: if (user) {
4602: var comp=new Array();
4603: comp=user.split(':');
4604: if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
4605: if ((comp[0]) && (comp[1])) {
4606: this.document.forms.newaboutsomeone.importdetail.value=
4607: '$lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
1.335 ehlerst 4608: this.document.forms.newaboutsomeone.submit();
4609: } else {
4610: alert("$lt{'p_mab_alrt1'}");
1.329 droeschl 4611: }
1.335 ehlerst 4612: } else {
4613: alert("$lt{'p_mab_alrt2'}");
4614: }
4615: }
1.329 droeschl 4616: }
4617:
1.501 raeburn 4618: function toggleUpload(caller) {
4619: var blocks = Array($fieldsets);
4620: for (var i=0; i<blocks.length; i++) {
4621: var disp = 'none';
4622: if (caller == blocks[i]) {
4623: var curr = document.getElementById('upload'+caller+'form').style.display;
4624: if (curr == 'none') {
4625: disp='block';
4626: }
4627: }
4628: document.getElementById('upload'+blocks[i]+'form').style.display=disp;
4629: }
1.502 raeburn 4630: resize_scrollbox('contentscroll','1','1');
4631: return;
4632: }
4633:
4634: function toggleMap() {
4635: var disp = 'none';
4636: var curr = document.getElementById('importmapform').style.display;
4637: if (curr == 'none') {
4638: disp='block';
4639: }
4640: document.getElementById('importmapform').style.display=disp;
4641: resize_scrollbox('contentscroll','1','1');
1.501 raeburn 4642: return;
1.329 droeschl 4643: }
4644:
1.502 raeburn 4645:
1.501 raeburn 4646: function extUrlPreview(caller) {
4647: if (document.getElementById(caller)) {
4648: var url = document.getElementById(caller).value;
4649: var regexp = $urlregexp;
4650: if (regexp.test(url)) {
4651: openMyModal(url,500,400,'yes');
4652: } else {
4653: alert("$lt{'invurl'}");
4654: }
4655: }
4656: }
4657:
4658: function makeims(imsform) {
4659: if ((imsform.uploaddoc.value == '') || (!imsform.uploaddoc.value)) {
4660: alert("$lt{'imsfile'}");
4661: return;
4662: }
4663: if (imsform.source.selectedIndex == 0) {
4664: alert("$lt{'imscms'}");
4665: return;
4666: }
4667: newWindow = window.open('', 'IMSimport',"HEIGHT=700,WIDTH=750,scrollbars=yes");
4668: imsform.submit();
4669: }
4670:
4671: function setExternal(extform,residx) {
4672: var title=extform.exttitle.value;
4673: if (!String.trim) {
4674: String.prototype.trim = function() {return this.replace(\/^\\s+|\\s+$\/g, "");}; }
4675: var url=extform.exturl.value;
4676: var regexp = $urlregexp;
4677: if (title == null || title.trim()=="") {
4678: alert("$lt{'titbl'}");
4679: extform.exttitle.focus();
4680: return;
4681: }
4682: if (regexp.test(url)) {
4683: url = escape(url);
4684: if (residx > 0) {
4685: eval("extform.importdetail.value=title+'='+url+'='+residx;extform.submit();");
4686: } else {
4687: eval("extform.importdetail.value=title+'='+url;extform.submit();");
4688: }
4689: } else {
4690: alert("$lt{'invurl'}");
4691: extform.exturl.focus();
4692: return;
4693: }
1.329 droeschl 4694: }
4695:
4696: function changename(folderpath,index,oldtitle,container,pagesymb) {
1.335 ehlerst 4697: var title=prompt('$lt{"p_chn"}',oldtitle);
4698: if (title) {
4699: this.document.forms.renameform.markcopy.value=-1;
4700: this.document.forms.renameform.title.value=title;
4701: this.document.forms.renameform.cmd.value='rename_'+index;
4702: if (container == 'sequence') {
4703: this.document.forms.renameform.folderpath.value=folderpath;
4704: }
4705: if (container == 'page') {
4706: this.document.forms.renameform.pagepath.value=folderpath;
4707: this.document.forms.renameform.pagesymb.value=pagesymb;
4708: }
4709: this.document.forms.renameform.submit();
4710: }
1.329 droeschl 4711: }
4712:
4713: function removeres(folderpath,index,oldtitle,container,pagesymb,skip_confirm) {
1.335 ehlerst 4714: if (skip_confirm || confirm('$lt{"p_rmr1"}\\n\\n$lt{"p_rmr2a"} "'+oldtitle+'" $lt{"p_rmr2b"}')) {
4715: this.document.forms.renameform.markcopy.value=-1;
4716: this.document.forms.renameform.cmd.value='del_'+index;
4717: if (container == 'sequence') {
4718: this.document.forms.renameform.folderpath.value=folderpath;
4719: }
4720: if (container == 'page') {
4721: this.document.forms.renameform.pagepath.value=folderpath;
4722: this.document.forms.renameform.pagesymb.value=pagesymb;
4723: }
4724: this.document.forms.renameform.submit();
4725: }
1.329 droeschl 4726: }
4727:
4728: function cutres(folderpath,index,oldtitle,container,pagesymb,folder,skip_confirm) {
1.335 ehlerst 4729: if (skip_confirm || confirm('$lt{"p_ctr1a"}\\n$lt{"p_ctr1b"}\\n\\n$lt{"p_ctr2a"} "'+oldtitle+'" $lt{"p_ctr2b"}')) {
4730: this.document.forms.renameform.cmd.value='cut_'+index;
4731: this.document.forms.renameform.markcopy.value=index;
4732: this.document.forms.renameform.copyfolder.value=folder+'.'+container;
4733: if (container == 'sequence') {
4734: this.document.forms.renameform.folderpath.value=folderpath;
4735: }
4736: if (container == 'page') {
4737: this.document.forms.renameform.pagepath.value=folderpath;
4738: this.document.forms.renameform.pagesymb.value=pagesymb;
4739: }
4740: this.document.forms.renameform.submit();
4741: }
1.329 droeschl 4742: }
4743:
4744: function markcopy(folderpath,index,oldtitle,container,pagesymb,folder) {
1.335 ehlerst 4745: this.document.forms.renameform.markcopy.value=index;
4746: this.document.forms.renameform.copyfolder.value=folder+'.'+container;
4747: if (container == 'sequence') {
4748: this.document.forms.renameform.folderpath.value=folderpath;
4749: }
4750: if (container == 'page') {
4751: this.document.forms.renameform.pagepath.value=folderpath;
4752: this.document.forms.renameform.pagesymb.value=pagesymb;
4753: }
4754: this.document.forms.renameform.submit();
1.329 droeschl 4755: }
4756:
1.478 raeburn 4757: function updatePick(targetform,index,caller) {
4758: var pickitem = document.getElementById('rpick_'+index);
4759: var picknumitem = document.getElementById('rpicknum_'+index);
4760: if (pickitem.checked) {
4761: var picknum=prompt('$lt{"rpck"}',picknumitem.value);
4762: if (picknum == '' || picknum == null) {
4763: if (caller == 'check') {
4764: pickitem.checked=false;
4765: return;
4766: }
4767: } else {
4768: picknum.toString();
4769: var regexdigit=/^\\d+\$/;
4770: if (regexdigit.test(picknum)) {
4771: picknumitem.value = picknum;
4772: targetform.changeparms.value='randompick';
4773: targetform.submit();
4774: } else {
4775: if (caller == 'check') {
4776: pickitem.checked=false;
4777: }
4778: return;
4779: }
4780: }
4781: } else {
4782: picknumitem.value = 0;
4783: targetform.changeparms.value='randompick';
4784: targetform.submit();
4785: }
4786: }
4787:
1.334 muellerd 4788: function unselectInactive(nav) {
1.335 ehlerst 4789: currentNav = document.getElementById(nav);
4790: currentLis = currentNav.getElementsByTagName('LI');
4791: for (i = 0; i < currentLis.length; i++) {
1.472 raeburn 4792: if (currentLis[i].className == 'goback') {
4793: currentLis[i].className = 'goback';
4794: } else {
4795: if (currentLis[i].className == 'right active' || currentLis[i].className == 'right') {
1.374 tempelho 4796: currentLis[i].className = 'right';
1.472 raeburn 4797: } else {
1.374 tempelho 4798: currentLis[i].className = 'i';
1.472 raeburn 4799: }
4800: }
1.335 ehlerst 4801: }
1.332 tempelho 4802: }
4803:
1.334 muellerd 4804: function hideAll(current, nav, data) {
1.335 ehlerst 4805: unselectInactive(nav);
1.374 tempelho 4806: if(current.className == 'right'){
4807: current.className = 'right active'
4808: }else{
4809: current.className = 'active';
4810: }
1.335 ehlerst 4811: currentData = document.getElementById(data);
4812: currentDivs = currentData.getElementsByTagName('DIV');
4813: for (i = 0; i < currentDivs.length; i++) {
4814: if(currentDivs[i].className == 'LC_ContentBox'){
1.333 muellerd 4815: currentDivs[i].style.display = 'none';
1.330 tempelho 4816: }
4817: }
1.335 ehlerst 4818: }
1.330 tempelho 4819:
1.374 tempelho 4820: function openTabs(pageId) {
4821: tabnav = document.getElementById(pageId).getElementsByTagName('UL');
1.383 tempelho 4822: if(tabnav.length > 2 ){
1.389 tempelho 4823: currentNav = document.getElementById(tabnav[1].id);
1.374 tempelho 4824: currentLis = currentNav.getElementsByTagName('LI');
4825: for(i = 0; i< currentLis.length; i++){
4826: if(currentLis[i].className == 'active') {
1.375 tempelho 4827: funcString = currentLis[i].onclick.toString();
4828: tab = funcString.split('"');
1.420 onken 4829: if(tab.length < 2) {
4830: tab = funcString.split("'");
4831: }
1.375 tempelho 4832: currentData = document.getElementById(tab[1]);
4833: currentData.style.display = 'block';
1.374 tempelho 4834: }
4835: }
4836: }
4837: }
4838:
1.334 muellerd 4839: function showPage(current, pageId, nav, data) {
4840: hideAll(current, nav, data);
1.375 tempelho 4841: openTabs(pageId);
1.334 muellerd 4842: unselectInactive(nav);
1.330 tempelho 4843: current.className = 'active';
4844: currentData = document.getElementById(pageId);
4845: currentData.style.display = 'block';
1.458 raeburn 4846: activeTab = pageId;
1.501 raeburn 4847: toggleUpload();
1.503 raeburn 4848: toggleMap();
1.433 raeburn 4849: if (nav == 'mainnav') {
4850: var storedpath = "$docs_folderpath";
4851: if (storedpath == '') {
4852: storedpath = "$docs_pagepath";
4853: }
1.434 raeburn 4854: var storedpage = "$main_container_page";
1.433 raeburn 4855: var reg = new RegExp("^supplemental");
4856: if (pageId == 'mainCourseDocuments') {
1.434 raeburn 4857: if (storedpage == 1) {
4858: document.simpleedit.folderpath.value = '';
4859: document.uploaddocument.folderpath.value = '';
4860: } else {
4861: if (reg.test(storedpath)) {
4862: document.simpleedit.folderpath.value = '$toplevelmain';
4863: document.uploaddocument.folderpath.value = '$toplevelmain';
4864: document.newext.folderpath.value = '$toplevelmain';
4865: } else {
4866: document.simpleedit.folderpath.value = storedpath;
4867: document.uploaddocument.folderpath.value = storedpath;
4868: document.newext.folderpath.value = storedpath;
4869: }
1.433 raeburn 4870: }
4871: } else {
1.434 raeburn 4872: if (reg.test(storedpath)) {
4873: document.simpleedit.folderpath.value = storedpath;
4874: document.supuploaddocument.folderpath.value = storedpath;
4875: document.supnewext.folderpath.value = storedpath;
4876: } else {
1.433 raeburn 4877: document.simpleedit.folderpath.value = '$toplevelsupp';
4878: document.supuploaddocument.folderpath.value = '$toplevelsupp';
4879: document.supnewext.folderpath.value = '$toplevelsupp';
4880: }
4881: }
4882: }
1.485 raeburn 4883: resize_scrollbox('contentscroll','1','0');
1.330 tempelho 4884: return false;
4885: }
1.329 droeschl 4886:
1.472 raeburn 4887: function toContents(jumpto) {
4888: var newurl = '$backtourl';
4889: if (jumpto != '') {
4890: newurl = newurl+'?postdata='+jumpto;
4891: ;
4892: }
4893: location.href=newurl;
4894: }
4895:
1.329 droeschl 4896: ENDNEWSCRIPT
4897: }
1.457 raeburn 4898:
1.483 raeburn 4899: sub history_tab_js {
4900: return <<"ENDHIST";
4901: function toggleHistoryDisp(choice) {
4902: document.docslogform.docslog.value = choice;
4903: document.docslogform.submit();
4904: return;
4905: }
4906:
4907: ENDHIST
4908: }
4909:
1.484 raeburn 4910: sub inject_data_js {
4911: return <<ENDINJECT;
4912:
4913: function injectData(current, hiddenField, name, value) {
4914: currentElement = document.getElementById(hiddenField);
4915: currentElement.name = name;
4916: currentElement.value = value;
4917: current.submit();
4918: }
4919:
4920: ENDINJECT
4921: }
4922:
4923: sub dump_switchserver_js {
4924: my @hosts = @_;
4925: my %lt = &Apache::lonlocal::texthash(
4926: dump => 'Dumping to Authoring Space requires switching server.',
4927: swit => 'Switch server?',
4928: duco => 'Dump content to Authoring Space',
4929: yone => 'You need to switch to a server housing an Authoring Space for which you are author or co-author.',
4930: chos => 'Choose server',
4931: );
4932: my $role = $env{'request.role'};
4933: my $js = <<"ENDSWJS";
4934: <script type="text/javascript">
4935: function write_switchserver() {
4936: var server;
4937: if (document.setserver.posshosts.length > 0) {
4938: for (var i=0; i<document.setserver.posshosts.length; i++) {
4939: if (document.setserver.posshosts[i].checked) {
4940: server = document.setserver.posshosts[i].value;
4941: }
4942: }
4943: opener.document.location.href="/adm/switchserver?otherserver="+server+"&role=$role&origurl=/adm/coursedocs";
4944: }
4945: window.close();
4946: }
4947: </script>
4948:
4949: ENDSWJS
4950:
4951: my $startpage = &Apache::loncommon::start_page('Choose server',$js,
4952: {'only_body' => 1,
4953: 'js_ready' => 1,});
4954: my $endpage = &Apache::loncommon::end_page({'js_ready' => 1});
4955:
4956: my $hostpicker;
4957: my $count = 0;
4958: foreach my $host (sort(@hosts)) {
4959: my $checked;
4960: if ($count == 0) {
4961: $checked = ' checked="checked"';
4962: }
4963: $hostpicker .= '<label><input type="radio" name="posshosts" value="'.
4964: $host.'"'.$checked.' />'.$host.'</label> ';
4965: $count++;
4966: }
4967:
4968: return <<"ENDSWITCHJS";
4969:
4970: function dump_needs_switchserver(url) {
4971: if (url!='' && url!= null) {
4972: if (confirm("$lt{'dump'}\\n$lt{'swit'}")) {
4973: go(url);
4974: }
4975: }
4976: return;
4977: }
4978:
4979: function choose_switchserver_window() {
4980: newWindow = window.open('','ChooseServer','height=400,width=500,scrollbars=yes')
4981: newWindow.document.open();
4982: newWindow.document.writeln('$startpage');
4983: newWindow.document.write('<h3>$lt{'duco'}<\\/h3>\\n'+
4984: '<p>$lt{'yone'}<\\/p>\\n'+
4985: '<div class="LC_left_float"><fieldset><legend>$lt{'chos'}<\\/legend>\\n'+
4986: '<form name="setserver" method="post" action="" \\/>\\n'+
4987: '$hostpicker\\n'+
4988: '<br \\/><br \\/>\\n'+
4989: '<input type="button" name="makeswitch" value="$lt{'swit'}" '+
4990: 'onclick="write_switchserver();" \\/>\\n'+
4991: '<\\/form><\\/fieldset><\\/div><br clear="all" \\/>\\n');
4992: newWindow.document.writeln('$endpage');
4993: newWindow.document.close();
4994: newWindow.focus();
4995: }
4996:
4997: ENDSWITCHJS
4998: }
4999:
5000: sub makedocslogform {
5001: my ($formelems,$docslog) = @_;
5002: return <<"LOGSFORM";
5003: <form action="/adm/coursedocs" method="post" name="docslogform">
5004: <input type="hidden" name="docslog" value="$docslog" />
5005: $formelems
5006: </form>
5007: LOGSFORM
5008: }
5009:
5010: sub makesimpleeditform {
5011: my ($formelems) = @_;
5012: return <<"SIMPFORM";
5013: <form name="simpleedit" method="post" action="/adm/coursedocs">
5014: <input type="hidden" name="importdetail" value="" />
5015: $formelems
5016: </form>
5017: SIMPFORM
5018: }
5019:
1.329 droeschl 5020: 1;
5021: __END__
5022:
5023:
5024: =head1 NAME
5025:
5026: Apache::londocs.pm
5027:
5028: =head1 SYNOPSIS
5029:
5030: This is part of the LearningOnline Network with CAPA project
5031: described at http://www.lon-capa.org.
5032:
5033: =head1 SUBROUTINES
5034:
5035: =over
5036:
5037: =item %help=()
5038:
5039: Available help topics
5040:
5041: =item mapread()
5042:
1.344 bisitz 5043: Mapread read maps into LONCAPA::map:: global arrays
1.329 droeschl 5044: @order and @resources, determines status
5045: sets @order - pointer to resources in right order
5046: sets @resources - array with the resources with correct idx
5047:
5048: =item authorhosts()
5049:
5050: Return hash with valid author names
5051:
5052: =item clean()
5053:
5054: =item dumpcourse()
5055:
5056: Actually dump course
5057:
5058: =item group_import()
5059:
5060: Imports the given (name, url) resources into the course
5061: coursenum, coursedom, and folder must precede the list
5062:
5063: =item breadcrumbs()
5064:
5065: =item log_docs()
5066:
5067: =item docs_change_log()
5068:
5069: =item update_paste_buffer()
5070:
5071: =item print_paste_buffer()
5072:
5073: =item do_paste_from_buffer()
5074:
1.492 raeburn 5075: =item get_newmap_url()
5076:
5077: =item dbcopy()
5078:
5079: =item uniqueness_check()
5080:
5081: =item contained_map_check()
5082:
5083: =item reinit_role()
5084:
5085: =item url_paste_fixups()
5086:
5087: =item apply_fixups()
5088:
5089: =item copy_dependencies()
5090:
1.329 droeschl 5091: =item update_parameter()
5092:
5093: =item handle_edit_cmd()
5094:
5095: =item editor()
5096:
5097: =item process_file_upload()
5098:
5099: =item process_secondary_uploads()
5100:
5101: =item is_supplemental_title()
5102:
5103: =item entryline()
5104:
5105: =item tiehash()
5106:
5107: =item untiehash()
5108:
5109: =item checkonthis()
5110:
5111: check on this
5112:
5113: =item verifycontent()
5114:
5115: Verify Content
5116:
5117: =item devalidateversioncache() & checkversions()
5118:
5119: Check Versions
5120:
5121: =item mark_hash_old()
5122:
5123: =item is_hash_old()
5124:
5125: =item changewarning()
5126:
5127: =item init_breadcrumbs()
5128:
5129: Breadcrumbs for special functions
5130:
1.484 raeburn 5131: =item create_list_elements()
5132:
5133: =item create_form_ul()
5134:
5135: =item startContentScreen()
5136:
5137: =item endContentScreen()
5138:
5139: =item supplemental_base()
5140:
5141: =item embedded_form_elems()
5142:
5143: =item embedded_destination()
5144:
5145: =item return_to_editor()
5146:
5147: =item decompression_info()
5148:
5149: =item decompression_phase_one()
5150:
5151: =item decompression_phase_two()
5152:
5153: =item remove_archive()
5154:
5155: =item generate_admin_menu()
5156:
5157: =item generate_edit_table()
5158:
5159: =item editing_js()
5160:
5161: =item history_tab_js()
5162:
5163: =item inject_data_js()
5164:
5165: =item dump_switchserver_js()
5166:
1.485 raeburn 5167: =item resize_scrollbox_js()
1.484 raeburn 5168:
5169: =item makedocslogform()
5170:
1.485 raeburn 5171: =item makesimpleeditform()
5172:
1.329 droeschl 5173: =back
5174:
5175: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>