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