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