Annotation of loncom/interface/londocs.pm, revision 1.531
1.329 droeschl 1: # The LearningOnline Network
2: # Documents
3: #
1.531 ! raeburn 4: # $Id: londocs.pm,v 1.530 2013/01/09 17:22:51 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.510 raeburn 43: use Apache::lonextresedit();
1.329 droeschl 44: use HTML::Entities;
1.488 raeburn 45: use HTML::TokeParser;
1.329 droeschl 46: use GDBM_File;
47: use Apache::lonlocal;
48: use Cwd;
49: use LONCAPA qw(:DEFAULT :match);
50:
51: my $iconpath;
52:
53: my %hash;
54:
55: my $hashtied;
56: my %alreadyseen=();
57:
58: my $hadchanges;
59:
60:
61: my %help=();
62:
63:
64: sub mapread {
65: my ($coursenum,$coursedom,$map)=@_;
66: return
67: &LONCAPA::map::mapread('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
68: $map);
69: }
70:
71: sub storemap {
1.492 raeburn 72: my ($coursenum,$coursedom,$map,$contentchg)=@_;
73: my $report;
74: if (($contentchg) && ($map =~ /^default/)) {
75: $report = 1;
76: }
1.329 droeschl 77: my ($outtext,$errtext)=
78: &LONCAPA::map::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
1.492 raeburn 79: $map,1,$report);
1.329 droeschl 80: if ($errtext) { return ($errtext,2); }
1.364 bisitz 81:
1.329 droeschl 82: $hadchanges=1;
83: return ($errtext,0);
84: }
85:
86:
87:
88: sub authorhosts {
89: my %outhash=();
90: my $home=0;
91: my $other=0;
92: foreach my $key (keys(%env)) {
93: if ($key=~/^user\.role\.(au|ca)\.(.+)$/) {
94: my $role=$1;
95: my $realm=$2;
96: my ($start,$end)=split(/\./,$env{$key});
97: if (($start) && ($start>time)) { next; }
98: if (($end) && (time>$end)) { next; }
99: my ($ca,$cd);
100: if ($1 eq 'au') {
101: $ca=$env{'user.name'};
102: $cd=$env{'user.domain'};
103: } else {
104: ($cd,$ca)=($realm=~/^\/($match_domain)\/($match_username)$/);
105: }
106: my $allowed=0;
107: my $myhome=&Apache::lonnet::homeserver($ca,$cd);
108: my @ids=&Apache::lonnet::current_machine_ids();
1.484 raeburn 109: foreach my $id (@ids) {
110: if ($id eq $myhome) {
111: $allowed=1;
112: last;
113: }
114: }
1.329 droeschl 115: if ($allowed) {
116: $home++;
1.484 raeburn 117: $outhash{'home_'.$ca.':'.$cd}=1;
1.329 droeschl 118: } else {
1.484 raeburn 119: $outhash{'otherhome_'.$ca.':'.$cd}=$myhome;
1.329 droeschl 120: $other++;
121: }
122: }
123: }
124: return ($home,$other,%outhash);
125: }
126:
127:
128: sub clean {
129: my ($title)=@_;
130: $title=~s/[^\w\/\!\$\%\^\*\-\_\=\+\;\:\,\\\|\`\~]+/\_/gs;
1.344 bisitz 131: return $title;
1.329 droeschl 132: }
133:
134:
135:
136: sub dumpcourse {
137: my ($r) = @_;
1.408 raeburn 138: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 139: $r->print(&Apache::loncommon::start_page('Dump '.$crstype.' Content to Authoring Space')."\n".
140: &Apache::lonhtmlcommon::breadcrumbs('Dump '.$crstype.' Content to Authoring Space')."\n");
141: $r->print(&startContentScreen('tools'));
1.329 droeschl 142: my ($home,$other,%outhash)=&authorhosts();
1.484 raeburn 143: unless ($home) {
144: $r->print(&endContentScreen());
145: return '';
146: }
1.329 droeschl 147: my $origcrsid=$env{'request.course.id'};
148: my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
149: if (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
150: # Do the dumping
1.484 raeburn 151: unless ($outhash{'home_'.$env{'form.authorspace'}}) {
152: $r->print(&endContentScreen());
153: return '';
154: }
1.531 ! raeburn 155: my ($ca,$cd)=split(/\:/,$env{'form.authorspace'});
1.329 droeschl 156: $r->print('<h3>'.&mt('Copying Files').'</h3>');
157: my $title=$env{'form.authorfolder'};
158: $title=&clean($title);
159: my %replacehash=();
160: foreach my $key (keys(%env)) {
161: if ($key=~/^form\.namefor\_(.+)/) {
162: $replacehash{$1}=$env{$key};
163: }
164: }
165: my $crs='/uploaded/'.$env{'request.course.id'}.'/';
166: $crs=~s/\_/\//g;
167: foreach my $item (keys(%replacehash)) {
168: my $newfilename=$title.'/'.$replacehash{$item};
169: $newfilename=~s/\.(\w+)$//;
170: my $ext=$1;
171: $newfilename=&clean($newfilename);
172: $newfilename.='.'.$ext;
173: my @dirs=split(/\//,$newfilename);
1.462 raeburn 174: my $path=$r->dir_config('lonDocRoot')."/priv/$cd/$ca";
1.329 droeschl 175: my $makepath=$path;
176: my $fail=0;
177: for (my $i=0;$i<$#dirs;$i++) {
178: $makepath.='/'.$dirs[$i];
1.344 bisitz 179: unless (-e $makepath) {
180: unless(mkdir($makepath,0777)) { $fail=1; }
1.329 droeschl 181: }
182: }
183: $r->print('<br /><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt>: ');
184: if (my $fh=Apache::File->new('>'.$path.'/'.$newfilename)) {
185: if ($item=~/\.(sequence|page|html|htm|xml|xhtml)$/) {
186: print $fh &Apache::lonclonecourse::rewritefile(
187: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
188: (%replacehash,$crs => '')
189: );
190: } else {
191: print $fh
192: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item);
193: }
194: $fh->close();
195: } else {
196: $fail=1;
197: }
198: if ($fail) {
199: $r->print('<span class="LC_error">'.&mt('fail').'</span>');
200: } else {
201: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
202: }
203: }
204: } else {
1.484 raeburn 205: $r->print(&mt('Searching ...').'<br />');
206: $r->rflush();
1.329 droeschl 207: # Input form
1.484 raeburn 208: $r->print('<form name="dumpdoc" action="" method="post">'."\n");
1.329 droeschl 209: unless ($home==1) {
1.484 raeburn 210: $r->print('<div class="LC_left_float">'.
211: '<fieldset><legend>'.
212: &mt('Select the Authoring Space').
213: '</legend><select name="authorspace">');
1.329 droeschl 214: }
215: foreach my $key (sort(keys(%outhash))) {
216: if ($key=~/^home_(.+)$/) {
217: if ($home==1) {
218: $r->print(
219: '<input type="hidden" name="authorspace" value="'.$1.'" />');
220: } else {
221: $r->print('<option value="'.$1.'">'.$1.' - '.
1.484 raeburn 222: &Apache::loncommon::plainname(split(/\:/,$1)).'</option>');
1.329 droeschl 223: }
224: }
225: }
226: unless ($home==1) {
1.484 raeburn 227: $r->print('</select></fieldset></div>'."\n");
1.329 droeschl 228: }
229: my $title=$origcrsdata{'description'};
230: $title=~s/[\/\s]+/\_/gs;
231: $title=&clean($title);
1.484 raeburn 232: $r->print('<div class="LC_left_float">'.
233: '<fieldset><legend>'.&mt('Folder in Authoring Space').'</legend>'.
234: '<input type="text" size="50" name="authorfolder" value="'.
235: $title.'" />'.
236: '</fieldset></div><br clear="all" />'."\n");
1.329 droeschl 237: &tiehash();
1.484 raeburn 238: $r->print('<h4>'.&mt('Filenames in Authoring Space').'</h4>'
1.329 droeschl 239: .&Apache::loncommon::start_data_table()
240: .&Apache::loncommon::start_data_table_header_row()
241: .'<th>'.&mt('Internal Filename').'</th>'
242: .'<th>'.&mt('Title').'</th>'
243: .'<th>'.&mt('Save as ...').'</th>'
244: .&Apache::loncommon::end_data_table_header_row());
245: foreach my $file (&Apache::lonclonecourse::crsdirlist($origcrsid,'userfiles')) {
246: $r->print(&Apache::loncommon::start_data_table_row()
247: .'<td>'.$file.'</td>');
248: my ($ext)=($file=~/\.(\w+)$/);
249: my $title=$hash{'title_'.$hash{
250: 'ids_/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'.$file}};
251: $r->print('<td>'.($title?$title:' ').'</td>');
252: if (!$title) {
253: $title=$file;
254: } else {
255: $title=~s|/|_|g;
256: }
257: $title=~s/\.(\w+)$//;
258: $title=&clean($title);
259: $title.='.'.$ext;
260: $r->print("\n<td><input type='text' size='60' name='namefor_".$file."' value='".$title."' /></td>"
261: .&Apache::loncommon::end_data_table_row());
262: }
263: $r->print(&Apache::loncommon::end_data_table());
264: &untiehash();
265: $r->print(
1.484 raeburn 266: '<p><input type="submit" name="dumpcourse" value="'.&mt("Dump $crstype Content").'" /></p></form>');
1.329 droeschl 267: }
1.484 raeburn 268: $r->print(&endContentScreen());
1.329 droeschl 269: }
270:
271: sub group_import {
272: my ($coursenum, $coursedom, $folder, $container, $caller, @files) = @_;
1.529 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.529 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.529 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) {
1.530 raeburn 340: $fixuperrors =
1.529 raeburn 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.494 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.486 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.486 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.489 raeburn 429: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.484 raeburn 430: my %orderhash;
431: my $container='sequence';
432: my $pathitem;
1.519 raeburn 433: if ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 434: $container='page';
435: }
1.519 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.489 raeburn 446: if ($supplementalflag) {
447: $tid = 2;
448: }
1.509 raeburn 449: my ($breadcrumbtrail) =
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.488 raeburn 524: my $is_supp = 0;
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.488 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.488 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: }
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.488 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.488 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.492 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.488 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.492 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.492 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.492 raeburn 684: my ($r,$container,$folder,$coursedom,$coursenum) = @_;
1.329 droeschl 685: return if (!defined($env{'docs.markedcopy_url'}));
686:
1.492 raeburn 687: my ($is_external,$othercourse,$fromsupp,$is_uploaded_map,$parent);
1.488 raeburn 688: my $extension = (split(/\./,$env{'docs.markedcopy_url'}))[-1];
689: if ($env{'docs.markedcopy_url'} =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//} ) {
690: $is_external = 1;
691: }
692:
1.527 raeburn 693: my ($canpaste,$nopaste,$othercrs,$areachange);
1.488 raeburn 694: if ($folder =~ /^supplemental/) {
1.492 raeburn 695: $canpaste = &supp_pasteable($env{'docs.markedcopy_url'});
696: unless ($canpaste) {
697: $nopaste = &mt('Paste into Supplemental Content unavailable for this type of content.');
698: }
1.488 raeburn 699: } else {
700: $canpaste = 1;
701: }
702:
703: if ($canpaste) {
1.492 raeburn 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) {
712: $othercrs = '<br />'.&mt('(from another course).');
713: }
714: } else {
715: $canpaste = 0;
716: $nopaste = &mt('Paste from another course unavailable.')
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: }
1.488 raeburn 728: }
729:
1.381 bisitz 730: $r->print('<fieldset>'
1.492 raeburn 731: .'<legend>'.&mt('Clipboard').'</legend>');
732: my ($type,$buffer);
1.488 raeburn 733: if ($is_external) {
1.492 raeburn 734: $type = &mt('External Resource');
735: $buffer = $type.': '.
736: &LONCAPA::map::qtescape($env{'docs.markedcopy_title'}).' ('.
737: &LONCAPA::map::qtescape($env{'docs.markedcopy_url'}).')';
1.329 droeschl 738: } else {
1.492 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" />';
746: $buffer = $icon.$type.': '. &Apache::loncommon::parse_supplemental_title(&LONCAPA::map::qtescape($env{'docs.markedcopy_title'}));
1.329 droeschl 747: }
1.488 raeburn 748: if ($canpaste) {
1.492 raeburn 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).
759: '<label>'.
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: );
771: my (%display,%deps);
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;
783: $display{$subfolders[$j]} =
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.519 raeburn 800: $r->print('
1.329 droeschl 801: <input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />
802: ');
1.488 raeburn 803: $r->print('</form>');
804: } else {
1.492 raeburn 805: $r->print(&mt('Paste buffer contains:').' '.$buffer.
806: '<br /><p class="LC_info">'.$nopaste.'</p>');
1.329 droeschl 807: }
1.488 raeburn 808: $r->print('</fieldset>');
809: }
810:
1.492 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:
1.488 raeburn 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;
1.329 droeschl 831: }
832:
1.492 raeburn 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.492 raeburn 860: my ($coursenum,$coursedom,$folder,$container,$errors) = @_;
1.329 droeschl 861:
1.492 raeburn 862: # Early out if paste buffer is empty
1.329 droeschl 863: if (!$env{'form.pastemarked'}) {
1.492 raeburn 864: return ();
1.329 droeschl 865: }
866:
1.492 raeburn 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: }
873: }
874:
875: # Prepare to paste resource at end of list
1.491 raeburn 876: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url'});
877: my $title=&LONCAPA::map::qtescape($env{'docs.markedcopy_title'});
878:
1.492 raeburn 879: my ($is_map,$srcdom,$srcnum,$prefixchg,%before,%after,%mapchanges,%tomove);
1.491 raeburn 880: if ($url=~/\.(page|sequence)$/) {
881: $is_map = 1;
882: }
883: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/([^/]+)}) {
884: $srcdom = $1;
885: $srcnum = $2;
886: my $oldprefix = $3;
1.492 raeburn 887: # When paste buffer was populated using an active role in a different course
888: # check for mdc privilege in the course from which the resource was pasted
1.491 raeburn 889: if (($srcdom ne $coursedom) || ($srcnum ne $coursenum)) {
890: unless ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1.492 raeburn 891: return (&mt('Paste failed: Item is from a different course which you do not have rights to edit.'));
1.491 raeburn 892: }
893: }
1.492 raeburn 894: # When pasting content from Main Content to Supplemental Content and vice versa
895: # URLs will contain different paths (which depend on whether pasted item is
896: # a folder/page or a document.
1.491 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:
1.492 raeburn 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.488 raeburn 929: }
930: }
931:
1.329 droeschl 932: # Maps need to be copied first
1.492 raeburn 933: my ($oldurl,%removefrommap,%removeparam,%addedmaps,%rewrites,%retitles,%copies,
934: %dbcopies,%zombies,%params,%docmoves,%mapmoves,%newsubdir,%newurls);
1.489 raeburn 935: $oldurl = $url;
1.491 raeburn 936: if ($is_map) {
937: # If pasting a map, check if map contains other maps
1.529 raeburn 938: my ($allmaps,%hierarchy,%titles);
939: $allmaps = {};
1.491 raeburn 940: if ($folder =~ /^default/) {
1.529 raeburn 941: $allmaps =
942: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
943: $env{"course.$env{'request.course.id'}.home"},
944: $env{'request.course.id'});
1.488 raeburn 945: }
1.492 raeburn 946: &contained_map_check($url,$folder,\%removefrommap,\%removeparam,
1.529 raeburn 947: \%addedmaps,\%hierarchy,\%titles,$allmaps);
1.488 raeburn 948: if ($url=~ m{^/uploaded/}) {
1.492 raeburn 949: my $newurl;
950: unless ($env{'form.docs.markedcopy_options'} eq 'move') {
951: ($newurl,my $error) =
952: &get_newmap_url($url,$folder,$prefixchg,$coursedom,$coursenum,
1.529 raeburn 953: $srcdom,$srcnum,\$title,$allmaps,\%newurls);
1.492 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: }
1.491 raeburn 964: }
965: }
1.492 raeburn 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.529 raeburn 969: $allmaps,\%rewrites,\%retitles,\%copies,\%dbcopies,
1.492 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.529 raeburn 976: &url_paste_fixups($url,$folder,$prefixchg,$coursedom,$coursenum,$allmaps,\%rewrites,
1.492 raeburn 977: \%retitles,\%copies,\%dbcopies,\%zombies,\%params,\%mapmoves,
978: \%mapchanges,\%tomove,\%newsubdir,\%newurls);
1.329 droeschl 979: }
1.488 raeburn 980: } elsif ($url=~m {^/res/}) {
981: # published maps can only exists once, so remove it from paste buffer when done
982: &Apache::lonnet::delenv('docs.markedcopy');
1.492 raeburn 983: # if pasting published map (main content are only) check map is not already in course
984: if ($folder =~ /^default/) {
1.529 raeburn 985: if ((ref($allmaps) eq 'HASH') && ($allmaps->{$url})) {
1.492 raeburn 986: return (&mt('Paste failed: only one instance of a particular published sequence or page is allowed within each course.'));
1.491 raeburn 987: }
1.489 raeburn 988: }
989: }
1.329 droeschl 990: }
991: if ($url=~ m{/smppg$}) {
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;
1.491 raeburn 998: my $dbresult=&Apache::lonnet::put($db_name,\%contents,
1.329 droeschl 999: $coursedom,$coursenum);
1.491 raeburn 1000: if ($dbresult eq 'ok') {
1001: $url =~ s{/(\d*)/smppg$ }{/$now/smppg}x;
1002: $title=&mt('Copy of').' '.$title;
1003: } else {
1.492 raeburn 1004: return (&mt('Paste failed: An error occurred when copying the simple page.'));
1.491 raeburn 1005: }
1.329 droeschl 1006: }
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.491 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:
1.492 raeburn 1017: my $newidx;
1.491 raeburn 1018: unless ($is_map) {
1.492 raeburn 1019: # Now insert the URL at the bottom
1020: $newidx = &LONCAPA::map::getresidx($url);
1.491 raeburn 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+)/(.+)$});
1.492 raeburn 1025: my ($newloc,$newdocsdir) = ($folder =~ /^(default|supplemental)_?(\d*)/);
1.491 raeburn 1026: my $newprefix = $newloc;
1027: if ($newloc eq 'default') {
1028: $newprefix = 'docs';
1029: }
1.492 raeburn 1030: if ($newdocsdir eq '') {
1031: $newdocsdir = 'default';
1.491 raeburn 1032: }
1033: if (($prefixchg) || ($srcdom ne $coursedom) || ($srcnum ne $coursenum)) {
1.492 raeburn 1034: my $newpath = "$newprefix/$newdocsdir/$newidx/$rem";
1.491 raeburn 1035: $url =
1036: &Apache::lonclonecourse::writefile($env{'request.course.id'},$newpath,
1037: &Apache::lonnet::getfile($oldurl));
1038: if ($url eq '/adm/notfound.html') {
1.492 raeburn 1039: return (&mt('Paste failed: an error occurred saving the file.'));
1.491 raeburn 1040: } else {
1041: my ($newsubpath) = ($newpath =~ m{^(.*/)[^/]*$});
1042: $newsubpath =~ s{/+$}{/};
1043: $docmoves{$oldurl} = $newsubpath;
1044: }
1045: }
1046: }
1.488 raeburn 1047: }
1.491 raeburn 1048: }
1.492 raeburn 1049: # Apply any changes to maps, or copy dependencies for uploaded HTML pages
1050: my ($result,$save_err);
1.529 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,
1.530 raeburn 1069: );
1.492 raeburn 1070: $result =
1.529 raeburn 1071: &apply_fixups($folder,$is_map,$coursedom,$coursenum,$errors,
1072: \%updated,\%info,\%moves,$prefixchg,$oldurl,$url,'paste');
1.491 raeburn 1073: if ($result eq 'ok') {
1.492 raeburn 1074: if ($is_map) {
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: }
1.491 raeburn 1087: if ($env{'docs.markedcopy_supplemental'}) {
1.492 raeburn 1088: if ($folder !~ /^supplemental/) {
1.491 raeburn 1089: (undef,undef,$title) =
1090: &Apache::loncommon::parse_supplemental_title($env{'docs.markedcopy_supplemental'});
1.489 raeburn 1091: }
1.329 droeschl 1092: } else {
1.491 raeburn 1093: if ($folder=~/^supplemental/) {
1094: $title=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
1095: $env{'user.domain'}.'___&&&___'.$title;
1096: }
1.329 droeschl 1097: }
1.491 raeburn 1098: $LONCAPA::map::resources[$newidx]= $title.':'.$url.':'.$ext.':normal:res';
1099: push(@LONCAPA::map::order, $newidx);
1.492 raeburn 1100:
1101: # Store the result
1102: my ($errtext,$fatal) =
1103: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1104: if ($fatal) {
1105: $save_err = $errtext;
1106: }
1107: }
1108:
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: }
1.329 droeschl 1173: }
1.492 raeburn 1174: return ($newurl);
1.329 droeschl 1175: }
1176:
1.488 raeburn 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;
1192: }
1193:
1.329 droeschl 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.488 raeburn 1208: sub contained_map_check {
1.492 raeburn 1209: my ($url,$folder,$removefrommap,$removeparam,$addedmaps,$hierarchy,$titles,
1210: $allmaps) = @_;
1.488 raeburn 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)) {
1.492 raeburn 1222: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.488 raeburn 1223: next;
1224: }
1225: }
1.492 raeburn 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'};
1.488 raeburn 1230: } else {
1.492 raeburn 1231: if ($allmaps->{$ressrc}) {
1.529 raeburn 1232: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.492 raeburn 1233: } elsif (ref($addedmaps->{$ressrc}) eq 'ARRAY') {
1234: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1235: } else {
1236: $addedmaps->{$ressrc} = [$url];
1237: }
1.488 raeburn 1238: }
1.492 raeburn 1239: &contained_map_check($ressrc,$folder,$removefrommap,$removeparam,
1240: $addedmaps,$hierarchy,$titles,$allmaps);
1.488 raeburn 1241: }
1.492 raeburn 1242: } elsif ($token->[1] eq 'param') {
1.488 raeburn 1243: if ($folder =~ /^supplemental/) {
1.492 raeburn 1244: if (ref($removeparam->{$url}{$token->[2]->{'to'}}) eq 'ARRAY') {
1245: push(@{$removeparam->{$url}{$token->[2]->{'to'}}},$token->[2]->{'name'});
1246: } else {
1247: $removeparam->{$url}{$token->[2]->{'to'}} = [$token->[2]->{'name'}];
1248: }
1.488 raeburn 1249: }
1250: }
1251: }
1252: }
1253: return;
1254: }
1255:
1256: sub url_paste_fixups {
1.492 raeburn 1257: my ($oldurl,$folder,$prefixchg,$cdom,$cnum,$allmaps,$rewrites,$retitles,$copies,
1258: $dbcopies,$zombies,$params,$mapmoves,$mapchanges,$tomove,$newsubdir,$newurls) = @_;
1.491 raeburn 1259: my $checktitle;
1260: if (($prefixchg) &&
1.492 raeburn 1261: ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/supplemental})) {
1.491 raeburn 1262: $checktitle = 1;
1263: }
1.492 raeburn 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: }
1.491 raeburn 1271: my $file = &Apache::lonnet::getfile($oldurl);
1.488 raeburn 1272: return if ($file eq '-1');
1273: my $parser = HTML::TokeParser->new(\$file);
1274: $parser->attr_encoded(1);
1.491 raeburn 1275: my $changed = 0;
1.488 raeburn 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 '');
1.491 raeburn 1281: my $id = $token->[2]->{'id'};
1.492 raeburn 1282: my $title = $token->[2]->{'title'};
1.491 raeburn 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: }
1.488 raeburn 1288: next if ($token->[2]->{'type'} eq 'external');
1289: if ($token->[2]->{'type'} eq 'zombie') {
1.492 raeburn 1290: next if ($skip);
1.488 raeburn 1291: $zombies->{$oldurl}{$ressrc} = $id;
1.491 raeburn 1292: $changed = 1;
1293: } elsif ($ressrc =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
1.492 raeburn 1294: my $srcdom = $1;
1295: my $srcnum = $2;
1.488 raeburn 1296: my $rem = $3;
1.492 raeburn 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))) {
1322:
1.488 raeburn 1323: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
1324: $rewrites->{$oldurl}{$ressrc} = $id;
1.491 raeburn 1325: $mapchanges->{$ressrc} = 1;
1.492 raeburn 1326: unless (&url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,$cnum,$allmaps,
1.491 raeburn 1327: $rewrites,$retitles,$copies,$dbcopies,$zombies,
1.492 raeburn 1328: $params,$mapmoves,$mapchanges,$tomove,$newsubdir,
1329: $newurls)) {
1.491 raeburn 1330: $mapmoves->{$ressrc} = 1;
1331: }
1332: $changed = 1;
1.488 raeburn 1333: } else {
1.489 raeburn 1334: $rewrites->{$oldurl}{$ressrc} = $id;
1.488 raeburn 1335: $copies->{$oldurl}{$ressrc} = $id;
1.491 raeburn 1336: $changed = 1;
1.488 raeburn 1337: }
1338: }
1339: } elsif ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/(.+)$}) {
1.492 raeburn 1340: next if ($skip);
1341: my $srcdom = $1;
1342: my $srcnum = $2;
1343: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.488 raeburn 1344: $rewrites->{$oldurl}{$ressrc} = $id;
1345: $dbcopies->{$oldurl}{$ressrc} = $id;
1.491 raeburn 1346: $changed = 1;
1.488 raeburn 1347: }
1348: } elsif ($ressrc =~ m{^/public/($match_domain)/($match_courseid)/(.+)$}) {
1.492 raeburn 1349: next if ($skip);
1350: my $srcdom = $1;
1351: my $srcnum = $2;
1352: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.488 raeburn 1353: $rewrites->{$oldurl}{$ressrc} = $id;
1354: $dbcopies->{$oldurl}{$ressrc} = $id;
1.491 raeburn 1355: $changed = 1;
1.488 raeburn 1356: }
1357: }
1358: } elsif ($token->[1] eq 'param') {
1.492 raeburn 1359: next if ($skip);
1.488 raeburn 1360: my $to = $token->[2]->{'to'};
1361: if ($to ne '') {
1362: if (ref($params->{$oldurl}{$to}) eq 'ARRAY') {
1.492 raeburn 1363: push(@{$params->{$oldurl}{$to}},$token->[2]->{'name'});
1.488 raeburn 1364: } else {
1365: @{$params->{$oldurl}{$to}} = ($token->[2]->{'name'});
1366: }
1367: }
1368: }
1369: }
1.491 raeburn 1370: return $changed;
1.488 raeburn 1371: }
1372:
1373: sub apply_fixups {
1.529 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.491 raeburn 1424: my @allcopies;
1.529 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.491 raeburn 1433: }
1.529 raeburn 1434: undef(%added);
1.491 raeburn 1435: }
1436: }
1437: if ($key eq $oldurl) {
1.529 raeburn 1438: if ((exists($docmoves{$key}))) {
1.491 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.492 raeburn 1446: my ($relpath,$oldsubdir,$fname) =
1447: ($item =~ m{^(/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(default|\d+)/.*/)([^/]+)$});
1.491 raeburn 1448: if ($fname ne '') {
1449: my $content = &Apache::lonnet::getfile($item);
1450: unless ($content eq '-1') {
1451: my $storefn;
1.529 raeburn 1452: if (($key eq $oldurl) && (exists($docmoves{$key}))) {
1453: $storefn = $docmoves{$key};
1.491 raeburn 1454: } else {
1455: $storefn = $relpath;
1456: $storefn =~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 1457: if ($prefixchg && $before{'doc'} && $after{'doc'}) {
1458: $storefn =~ s/^\Q$before{'doc'}\E/$after{'doc'}/;
1.491 raeburn 1459: }
1.529 raeburn 1460: if ($newsubdir{$key}) {
1461: $storefn =~ s#^(docs|supplemental)/\Q$oldsubdir\E/#$1/$newsubdir{$key}#;
1.491 raeburn 1462: }
1463: }
1464: ©_dependencies($item,$storefn,$relpath,$errors,\$content);
1465: my $copyurl =
1466: &Apache::lonclonecourse::writefile($env{'request.course.id'},
1467: $storefn.$fname,$content);
1468: if ($copyurl eq '/adm/notfound.html') {
1.529 raeburn 1469: if (exists($docmoves{$oldurl})) {
1.491 raeburn 1470: return &mt('Paste failed: an error occurred copying the file.');
1471: } elsif (ref($errors) eq 'HASH') {
1472: $errors->{$item} = 1;
1.489 raeburn 1473: }
1474: }
1.488 raeburn 1475: }
1476: }
1.491 raeburn 1477: }
1478: }
1479: }
1.529 raeburn 1480: foreach my $key (keys(%mapmoves)) {
1.491 raeburn 1481: my $storefn=$key;
1482: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 1483: if ($prefixchg && $before{'map'} && $after{'map'}) {
1484: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.491 raeburn 1485: }
1.529 raeburn 1486: if ($newsubdir{$key}) {
1487: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.492 raeburn 1488: }
1.491 raeburn 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;
1.489 raeburn 1501: }
1.488 raeburn 1502: }
1503: }
1504: }
1.491 raeburn 1505: my %updates;
1506: if ($is_map) {
1.529 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.491 raeburn 1515: }
1516: foreach my $key (keys(%updates)) {
1.492 raeburn 1517: my (%torewrite,%toretitle,%toremove,%remparam,%currparam,%zombie,%newdb);
1.529 raeburn 1518: if (ref($rewrites{$key}) eq 'HASH') {
1519: %torewrite = %{$rewrites{$key}};
1.491 raeburn 1520: }
1.529 raeburn 1521: if (ref($retitles{$key}) eq 'HASH') {
1522: %toretitle = %{$retitles{$key}};
1.491 raeburn 1523: }
1.529 raeburn 1524: if (ref($removefrommap{$key}) eq 'HASH') {
1525: %toremove = %{$removefrommap{$key}};
1.491 raeburn 1526: }
1.529 raeburn 1527: if (ref($removeparam{$key}) eq 'HASH') {
1528: %remparam = %{$removeparam{$key}};
1.492 raeburn 1529: }
1.529 raeburn 1530: if (ref($zombies{$key}) eq 'HASH') {
1531: %zombie = %{$zombies{$key}};
1.491 raeburn 1532: }
1.529 raeburn 1533: if (ref($dbcopies{$key}) eq 'HASH') {
1534: foreach my $item (keys(%{$dbcopies{$key}})) {
1.491 raeburn 1535: $newdb{$item} = &dbcopy($item);
1536: }
1537: }
1.529 raeburn 1538: if (ref($params{$key}) eq 'HASH') {
1539: %currparam = %{$params{$key}};
1.492 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.529 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.492 raeburn 1556: my $changed;
1.529 raeburn 1557: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::resources[$idx]);
1558: if ((exists($toremove{$idx})) && ($toremove{$idx} eq $src)) {
1.492 raeburn 1559: splice(@LONCAPA::map::order,$i,1);
1.529 raeburn 1560: if (ref($currparam{$idx}) eq 'ARRAY') {
1561: foreach my $name (@{$currparam{$idx}}) {
1562: &LONCAPA::map::delparameter($idx,'parameter_'.$name);
1.492 raeburn 1563: }
1564: }
1565: next;
1566: }
1567: my $origsrc = $src;
1.529 raeburn 1568: if ((exists($toretitle{$src})) && ($toretitle{$src} eq $idx)) {
1.492 raeburn 1569: if ($title =~ m{^\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
1570: $changed = 1;
1.491 raeburn 1571: }
1.492 raeburn 1572: }
1.529 raeburn 1573: if ((exists($torewrite{$src})) && ($torewrite{$src} eq $idx)) {
1.492 raeburn 1574: $src =~ s{^/(uploaded|adm|public)/$match_domain/$match_courseid/}{/$1/$cdom/$cnum/};
1575: if ($origsrc =~ m{^/uploaded/}) {
1.529 raeburn 1576: if ($prefixchg && $before{'map'} && $after{'map'}) {
1.492 raeburn 1577: if ($src =~ /\.(page|sequence)$/) {
1.529 raeburn 1578: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'map'}\E#$1$after{'map'}#;
1.492 raeburn 1579: } else {
1.529 raeburn 1580: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'doc'}\E#$1$after{'doc'}#;
1.488 raeburn 1581: }
1.491 raeburn 1582: }
1.529 raeburn 1583: if ($newsubdir{$origsrc}) {
1.492 raeburn 1584: if ($src =~ /\.(page|sequence)$/) {
1.529 raeburn 1585: $src =~ s#^(/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_)(\d+)#$1$newsubdir{$origsrc}#;
1.492 raeburn 1586: } else {
1.529 raeburn 1587: $src =~ s#^(/uploaded/$match_domain/$match_courseid/\w+/)(\d+)#$1$newsubdir{$origsrc}#;
1.491 raeburn 1588: }
1.488 raeburn 1589: }
1590: }
1.492 raeburn 1591: $changed = 1;
1592: } elsif ($newdb{$src} ne '') {
1593: $src = $newdb{$src};
1594: $changed = 1;
1595: }
1596: if ($changed) {
1.529 raeburn 1597: $LONCAPA::map::resources[$idx] = join(':',($title,$src,$ext,$type));
1.492 raeburn 1598: }
1599: }
1600: }
1601: foreach my $idx (keys(%remparam)) {
1602: if (ref($remparam{$idx}) eq 'ARRAY') {
1603: foreach my $name (@{$remparam{$idx}}) {
1604: &LONCAPA::map::delparameter($idx,'parameter_'.$name);
1.491 raeburn 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.529 raeburn 1615: if ($prefixchg && $before{'map'} && $after{'map'}) {
1616: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.491 raeburn 1617: }
1.529 raeburn 1618: if ($newsubdir{$key}) {
1619: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.492 raeburn 1620: }
1.491 raeburn 1621: }
1.492 raeburn 1622: my $report;
1623: if ($folder !~ /^supplemental/) {
1624: $report = 1;
1625: }
1.527 raeburn 1626: (my $outtext,$errtext) =
1.492 raeburn 1627: &LONCAPA::map::storemap("/uploaded/$cdom/$cnum/$storefn",1,$report);
1628: if ($errtext) {
1.529 raeburn 1629: if ($caller eq 'paste') {
1630: return &mt('Paste failed: an error occurred saving the folder or page.');
1631: }
1.491 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: }
1.488 raeburn 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.508 raeburn 1766: $supplementalflag,$orderhash,$iconpath,$pathitem)=@_;
1.519 raeburn 1767: my ($randompick,$ishidden,$isencrypted,$plain,$is_random_order,$container);
1.510 raeburn 1768: if ($allowed) {
1.519 raeburn 1769: (my $breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
1770: $is_random_order,$container) =
1.510 raeburn 1771: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
1772: $r->print($breadcrumbtrail);
1.519 raeburn 1773: } elsif ($env{'form.folderpath'} =~ /\:1$/) {
1774: $container = 'page';
1775: } else {
1776: $container = 'sequence';
1.510 raeburn 1777: }
1.484 raeburn 1778:
1.525 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.491 raeburn 1822: my %paste_errors;
1.492 raeburn 1823: my ($paste_res,$save_error) =
1824: &do_paste_from_buffer($coursenum,$coursedom,$folder,$container,
1825: \%paste_errors);
1826: if ($save_error ne '') {
1827: return $save_error;
1828: }
1829: if ($paste_res ne 'ok') {
1.329 droeschl 1830: $r->print('<p><span class="LC_error">'.$paste_res.'</span></p>');
1831: }
1.491 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.492 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.504 raeburn 1860: if ($url=~ m{^\Q/uploaded/$coursedom/$coursenum/\E(default|supplemental)_new\.(sequence|page)$}) {
1861: my ($suffix,$errortxt,$locknotfreed) =
1862: &newmap_suffix($1,$2,$coursedom,$coursenum);
1863: if ($locknotfreed) {
1864: $r->print($locknotfreed);
1865: }
1866: if ($suffix) {
1867: $url =~ s/_new\./_$suffix./;
1868: } else {
1869: return $errortxt;
1870: }
1871: }
1.329 droeschl 1872: push(@imports, [$name, $url, $residx]);
1873: }
1874: }
1.530 raeburn 1875: ($errtext,$fatal,my $fixuperrors) =
1.529 raeburn 1876: &group_import($coursenum, $coursedom, $folder,$container,
1877: 'londocs',@imports);
1.329 droeschl 1878: return $errtext if ($fatal);
1.529 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.492 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.501 raeburn 1947: $coursenum,$coursedom,$crstype,
1.519 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.510 raeburn 1953:
1954: if (($allowed) || ($supplementalflag && $folder eq 'supplemental')) {
1.520 raeburn 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.525 raeburn 1960: .'<li><a href="/adm/coursedocs?forcesupplement=1&command=editsupp" '
1.520 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 />';
1.510 raeburn 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 {
1.520 raeburn 1982: $to_show .= $toolslink
1.510 raeburn 1983: .&Apache::loncommon::start_data_table('LC_tableOfContent')
1984: .$output.' '
1985: .&Apache::loncommon::end_data_table();
1.393 raeburn 1986: }
1.510 raeburn 1987: } else {
1.520 raeburn 1988: if (!$allowed) {
1989: $to_show .= $toolslink;
1990: }
1.510 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.510 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.492 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.519 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.492 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.501 raeburn 2183: my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$coursedom,
1.519 raeburn 2184: $crstype,$pathitem,$supplementalflag,$container)=@_;
2185: my ($foldertitle,$renametitle);
1.329 droeschl 2186: if (&is_supplemental_title($title)) {
1.488 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.519 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.505 raeburn 2213: my $isexternal;
1.510 raeburn 2214: if ($residx) {
1.501 raeburn 2215: my $currurl = $url;
2216: $currurl =~ s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
1.505 raeburn 2217: if ($currurl =~ m{^/adm/wrapper/ext/}) {
2218: $isexternal = 1;
2219: }
1.510 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.501 raeburn 2228: }
1.517 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.501 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.501 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.497 raeburn 2268: my $noremove=0;
1.492 raeburn 2269: if ($url=~ m{^/res/.+\.(page|sequence)$}) {
2270: # no copy for published maps
2271: $nocopy=1;
1.329 droeschl 2272: }
1.344 bisitz 2273: if ($url=~/^\/res\/lib\/templates\//) {
2274: $nocopy=1;
1.329 droeschl 2275: $nocut=1;
2276: }
1.497 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.517 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.505 raeburn 2334: |\.html$)}x)
2335: || $isexternal) {
1.329 droeschl 2336: $skip_confirm = 1;
2337: }
2338:
1.508 raeburn 2339: if ($nocopy) {
1.507 raeburn 2340: $copylink=(<<ENDCOPY);
2341: <span style="visibility: hidden;">$lt{'cp'}</span>
2342: ENDCOPY
2343: } else {
1.329 droeschl 2344: $copylink=(<<ENDCOPY);
1.519 raeburn 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.508 raeburn 2348: if ($nocut) {
1.507 raeburn 2349: $cutlink=(<<ENDCUT);
2350: <span style="visibility: hidden;">$lt{'ct'}</span>
2351: ENDCUT
2352: } else {
1.329 droeschl 2353: $cutlink=(<<ENDCUT);
1.519 raeburn 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.507 raeburn 2357: if ($noremove) {
2358: $removelink=(<<ENDREM);
2359: <span style="visibility: hidden;">$lt{'rm'}</a>
2360: ENDREM
2361: } else {
1.497 raeburn 2362: $removelink=(<<ENDREM);
1.519 raeburn 2363: <a href='javascript:removeres("$esc_path","$index","$renametitle",$skip_confirm);' class="LC_docs_remove">$lt{'rm'}</a>
1.497 raeburn 2364: ENDREM
2365: }
1.518 raeburn 2366: unless ($isexternal) {
2367: $renamelink=(<<ENDREN);
1.519 raeburn 2368: <a href='javascript:changename("$esc_path","$index","$renametitle");' class="LC_docs_rename">$lt{'rn'}</a>
1.507 raeburn 2369: ENDREN
1.518 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.499 raeburn 2384: <a href='/adm/coursedocs?cmd=up_$index&${type}path=$esc_path&${type}symb=$symb'>
1.501 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.499 raeburn 2389: <a href='/adm/coursedocs?cmd=down_$index&${type}path=$esc_path&${type}symb=$symb'>
1.501 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.507 raeburn 2400: <td class="LC_docs_entry_commands"><span class="LC_nobreak">
1.497 raeburn 2401: $removelink
1.329 droeschl 2402: $cutlink
2403: $copylink
1.507 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.519 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.519 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.518 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.510 raeburn 2440: $url=~s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
1.501 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.329 droeschl 2457: }
1.501 raeburn 2458: if (&Apache::lonnet::symbverify($symb,$url)) {
2459: $url.=(($url=~/\?/)?'&':'?').'symb='.&escape($symb);
2460: } else {
2461: $url='';
2462: }
1.329 droeschl 2463: }
2464: }
1.478 raeburn 2465: my ($rand_pick_text,$rand_order_text);
1.519 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.510 raeburn 2470: if (!$allowed && $supplementalflag) {
1.519 raeburn 2471: $folderpath.=$containerarg.'&'.$foldername;
1.510 raeburn 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.519 raeburn 2476: $folderpath.=$containerarg.'&'.$foldername.
1.510 raeburn 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.519 raeburn 2484: 'parameter_randomorder'))[0]=~/^yes$/i)
2485: .':'.$ispage;
1.510 raeburn 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.510 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.510 raeburn 2508: }
1.509 raeburn 2509: } elsif ($supplementalflag && !$allowed) {
1.510 raeburn 2510: $url .= ($url =~ /\?/) ? '&':'?';
1.509 raeburn 2511: $url .= 'folderpath='.&HTML::Entities::encode($esc_path,'<>&"');
1.510 raeburn 2512: if ($title) {
2513: $url .= '&title='.&HTML::Entities::encode($renametitle,'<>&"');
2514: }
1.511 raeburn 2515: if ($isexternal && $orderidx) {
1.510 raeburn 2516: $url .= '&idx='.$orderidx;
2517: }
1.329 droeschl 2518: }
1.519 raeburn 2519: my ($tdalign,$tdwidth);
1.501 raeburn 2520: if ($allowed) {
2521: my $fileloc =
2522: &Apache::lonnet::declutter(&Apache::lonnet::filelocation('',$orig_url));
1.510 raeburn 2523: if ($isexternal) {
1.518 raeburn 2524: ($editlink,$extresform) =
1.510 raeburn 2525: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem);
1.511 raeburn 2526: } elsif (!$isfolder && !$ispage) {
1.503 raeburn 2527: my ($cfile,$home,$switchserver,$forceedit,$forceview) =
2528: &Apache::lonnet::can_edit_resource($fileloc,$coursenum,$coursedom,$orig_url);
1.511 raeburn 2529: if (($cfile ne '') && ($symb ne '' || $supplementalflag)) {
1.501 raeburn 2530: my $jscall =
2531: &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,
2532: $switchserver,
1.503 raeburn 2533: $forceedit,
1.511 raeburn 2534: undef,$symb,
2535: &escape($env{'form.folderpath'}),
1.524 raeburn 2536: $renametitle,'','',1);
1.501 raeburn 2537: if ($jscall) {
1.518 raeburn 2538: $editlink = '<a class="LC_docs_ext_edit" href="javascript:'.
2539: $jscall.'" >'.&mt('Edit').'</a> '."\n";
1.501 raeburn 2540: }
2541: }
2542: }
1.519 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.519 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.519 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.518 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.504 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.521 bisitz 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.485 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.521 bisitz 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.521 bisitz 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.521 bisitz 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.521 bisitz 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.521 bisitz 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.521 bisitz 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.521 bisitz 2917: $weeksel=' selected="selected"';
1.329 droeschl 2918: } elsif ($env{'form.timerange'}==86400) {
2919: $seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 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.521 bisitz 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.521 bisitz 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.496 golterma 2991: #excludes not versionable problems from resource version history:
1.521 bisitz 2992: next unless ($changes{$key}>$starttime && $key !~ /^\/res\/lib\/templates/);
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.521 bisitz 3001: '<td><b>'.&Apache::lonnet::gettitle($linkurl).'</b><br />'.
1.479 golterma 3002: '<a href="'.$linkurl.'" target="cat">'.$linkurl.'</a></td>'.
1.521 bisitz 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.521 bisitz 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.521 bisitz 3012: } else {
1.479 golterma 3013: $r->print($usedversion);
3014: }
1.329 droeschl 3015: } else {
1.521 bisitz 3016: $r->print($currentversion);
1.329 droeschl 3017: }
1.521 bisitz 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.521 bisitz 3053: $r->print('</span><br />');
3054: }
3055: $r->print('</span></td>'.&Apache::loncommon::end_data_table_row());
1.329 droeschl 3056: }
1.521 bisitz 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.521 bisitz 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.501 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 'courseindex')?' class="active"':'').'><a href="/adm/indexcourse"><b> '.&mt('Content Index').' </b></a></li>'."\n";
3162: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/supplemental"><b>'.&mt('Supplemental Content').'</b></a></li>';
3163: } else {
3164: $output .= '<li '.(($mode eq 'docs')?' class="active"':'').' id="tabbededitor"><a href="/adm/coursedocs?forcestandard=1"><b> '.&mt('Content Editor').' </b></a></li>'."\n";
3165: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/coursedocs?forcesupplement=1"><b>'.&mt('Supplemental Content Editor').'</b></a></li>'."\n";
3166: $output .= '<li '.(($mode eq 'tools')?' class="active"':'').'><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>'."\n";
3167: '><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>';
3168: }
3169: $output .= "\n".'</ul>'."\n";
3170: $output .= '<div class="LC_DocsBox" style="clear:both;margin:0;" id="contenteditor">'.
3171: '<div id="maincoursedoc" style="margin:0 0;padding:0 0;">'.
3172: '<div class="LC_ContentBox" id="mainCourseDocuments" style="display: block;">';
3173: return $output;
1.442 www 3174: }
3175:
3176: #
3177: # End tabs
3178: #
3179:
3180: sub endContentScreen {
1.484 raeburn 3181: return '</div></div></div>';
1.442 www 3182: }
1.329 droeschl 3183:
1.446 www 3184: sub supplemental_base {
1.472 raeburn 3185: return 'supplemental&'.&escape(&mt('Supplemental '.&Apache::loncommon::course_type().' Content'));
1.446 www 3186: }
3187:
1.329 droeschl 3188: sub handler {
3189: my $r = shift;
3190: &Apache::loncommon::content_type($r,'text/html');
3191: $r->send_http_header;
3192: return OK if $r->header_only;
1.484 raeburn 3193:
3194: # get course data
1.408 raeburn 3195: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 3196: my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
3197: my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
3198:
3199: # graphics settings
3200: $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL').'/');
1.329 droeschl 3201:
1.443 www 3202: #
1.329 droeschl 3203: # --------------------------------------------- Initialize help topics for this
3204: foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',
3205: 'Adding_External_Resource','Navigate_Content',
3206: 'Adding_Folders','Docs_Overview', 'Load_Map',
3207: 'Supplemental','Score_Upload_Form','Adding_Pages',
1.501 raeburn 3208: 'Importing_LON-CAPA_Resource','Importing_IMS_Course',
3209: 'Uploading_From_Harddrive',
1.329 droeschl 3210: 'Check_Resource_Versions','Verify_Content') {
3211: $help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
3212: }
3213: # Composite help files
3214: $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
3215: 'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
3216: $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
3217: 'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
3218: $help{'Simple Problem'} = &Apache::loncommon::help_open_topic(
3219: 'Option_Response_Simple');
3220: $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
3221: 'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
1.347 weissno 3222: $help{'My Personal Information Page'} = &Apache::loncommon::help_open_topic(
1.329 droeschl 3223: 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
1.353 weissno 3224: $help{'Group Portfolio'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
1.329 droeschl 3225: $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
3226:
1.472 raeburn 3227:
3228: my $allowed;
3229: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
3230: unless ($r->uri eq '/adm/supplemental') {
3231: # does this user have privileges to modify content.
3232: $allowed = &Apache::lonnet::allowed('mdc',$env{'request.course.id'});
3233: }
3234:
1.484 raeburn 3235: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['chooseserver',
3236: 'inhibitmenu']);
3237: if ($allowed && $env{'form.chooseserver'}) {
3238: &choose_dump_server($r);
3239: return OK;
3240: } elsif ($allowed && $env{'form.verify'}) {
1.329 droeschl 3241: &init_breadcrumbs('verify','Verify Content');
3242: &verifycontent($r);
3243: } elsif ($allowed && $env{'form.listsymbs'}) {
1.484 raeburn 3244: &init_breadcrumbs('listsymbs','List Content IDs');
1.329 droeschl 3245: &list_symbs($r);
3246: } elsif ($allowed && $env{'form.docslog'}) {
3247: &init_breadcrumbs('docslog','Show Log');
1.484 raeburn 3248: my $folder = $env{'form.folder'};
3249: if ($folder eq '') {
3250: $folder='default';
3251: }
3252: &docs_change_log($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath);
1.329 droeschl 3253: } elsif ($allowed && $env{'form.versions'}) {
3254: &init_breadcrumbs('versions','Check/Set Resource Versions');
3255: &checkversions($r);
3256: } elsif ($allowed && $env{'form.dumpcourse'}) {
1.484 raeburn 3257: &init_breadcrumbs('dumpcourse','Dump '.&Apache::loncommon::course_type().' Content to Authoring Space');
1.329 droeschl 3258: &dumpcourse($r);
3259: } elsif ($allowed && $env{'form.exportcourse'}) {
1.377 bisitz 3260: &init_breadcrumbs('exportcourse','IMS Export');
1.475 raeburn 3261: &Apache::imsexport::exportcourse($r);
1.329 droeschl 3262: } else {
1.445 www 3263: #
3264: # Done catching special calls
1.484 raeburn 3265: # The whole rest is for course and supplemental documents and utilities menu
1.445 www 3266: # Get the parameters that may be needed
3267: #
3268: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.519 raeburn 3269: ['folderpath',
3270: 'forcesupplement','forcestandard',
1.510 raeburn 3271: 'tools','symb','command','supppath']);
1.445 www 3272:
3273: # standard=1: this is a "new-style" course with an uploaded map as top level
3274: # standard=2: this is a "old-style" course, and there is nothing we can do
1.329 droeschl 3275:
3276: my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
1.445 www 3277:
1.484 raeburn 3278: # Decide whether this should display supplemental or main content or utilities
1.445 www 3279: # supplementalflag=1: show supplemental documents
3280: # supplementalflag=0: show standard documents
1.484 raeburn 3281: # toolsflag=1: show utilities
1.445 www 3282:
3283:
3284: my $supplementalflag=($env{'form.folderpath'}=~/^supplemental/);
1.519 raeburn 3285: if (($env{'form.folderpath'}=~/^default/) || ($env{'form.folderpath'} eq "")) {
1.445 www 3286: $supplementalflag=0;
3287: }
3288: if ($env{'form.forcesupplement'}) { $supplementalflag=1; }
3289: if ($env{'form.forcestandard'}) { $supplementalflag=0; }
3290: unless ($allowed) { $supplementalflag=1; }
3291: unless ($standard) { $supplementalflag=1; }
1.484 raeburn 3292: my $toolsflag=0;
3293: if ($env{'form.tools'}) { $toolsflag=1; }
1.445 www 3294:
1.329 droeschl 3295: my $script='';
3296: my $showdoc=0;
1.457 raeburn 3297: my $addentries = {};
1.475 raeburn 3298: my $container;
1.329 droeschl 3299: my $containertag;
1.508 raeburn 3300: my $pathitem;
1.329 droeschl 3301:
1.464 www 3302: # Do we directly jump somewhere?
1.466 www 3303:
1.525 raeburn 3304: if (($env{'form.command'} eq 'direct') || ($env{'form.command'} eq 'directnav')) {
1.472 raeburn 3305: if ($env{'form.symb'} ne '') {
1.522 raeburn 3306: $env{'form.folderpath'}=
3307: &Apache::loncommon::symb_to_docspath($env{'form.symb'});
1.530 raeburn 3308: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
1.525 raeburn 3309: $env{'form.command'}.'_'.$env{'form.symb'}});
1.472 raeburn 3310: } elsif ($env{'form.supppath'} ne '') {
3311: $env{'form.folderpath'}=$env{'form.supppath'};
1.530 raeburn 3312: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
1.525 raeburn 3313: $env{'form.command'}.'_'.$env{'form.supppath'}});
1.466 www 3314: }
1.472 raeburn 3315: } elsif ($env{'form.command'} eq 'editdocs') {
1.525 raeburn 3316: $env{'form.folderpath'} = 'default&'.
3317: &Apache::lonhtmlcommon::entity_encode('Main Course Content').
3318: ':::::';
3319: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => $env{'form.command'}});
1.472 raeburn 3320: } elsif ($env{'form.command'} eq 'editsupp') {
1.525 raeburn 3321: $env{'form.folderpath'} = 'supplemental&'.
1.472 raeburn 3322: &Apache::lonhtmlcommon::entity_encode('Supplemental Content');
1.525 raeburn 3323: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/supplemental'});
3324: } elsif ($env{'form.command'} eq 'contents') {
3325: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/navmaps'});
3326: } elsif ($env{'form.command'} eq 'home') {
3327: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/menu'});
1.464 www 3328: }
3329:
1.525 raeburn 3330:
1.445 www 3331: # Where do we store these for when we come back?
3332: my $stored_folderpath='docs_folderpath';
3333: if ($supplementalflag) {
3334: $stored_folderpath='docs_sup_folderpath';
3335: }
1.464 www 3336:
1.519 raeburn 3337: # No folderpath, and in edit mode, see if we have something stored
3338: if ((!$env{'form.folderpath'}) && $allowed) {
1.445 www 3339: &Apache::loncommon::restore_course_settings($stored_folderpath,
1.510 raeburn 3340: {'folderpath' => 'scalar'});
1.523 raeburn 3341: unless (&unescape($env{'form.folderpath'}) =~ m{^(default|supplemental)&}) {
3342: undef($env{'form.folderpath'});
3343: }
1.329 droeschl 3344: }
1.446 www 3345:
3346: # If we are not allowed to make changes, all we can see are supplemental docs
1.409 raeburn 3347: if (!$allowed) {
1.446 www 3348: unless ($env{'form.folderpath'} =~ /^supplemental/) {
3349: $env{'form.folderpath'} = &supplemental_base();
1.409 raeburn 3350: }
3351: }
1.446 www 3352: # Make the zeroth entry in supplemental docs page paths, so we can get to top level
1.329 droeschl 3353: if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
1.446 www 3354: $env{'form.folderpath'} = &supplemental_base()
3355: .'&'.
1.329 droeschl 3356: $env{'form.folderpath'};
3357: }
1.446 www 3358: # If after all of this, we still don't have any paths, make them
1.519 raeburn 3359: unless ($env{'form.folderpath'}) {
1.446 www 3360: if ($supplementalflag) {
3361: $env{'form.folderpath'}=&supplemental_base();
3362: } else {
1.519 raeburn 3363: $env{'form.folderpath'}='default'.&escape(&mt('Main '.$crstype.' Documents')).
3364: ':::::';
1.446 www 3365: }
1.472 raeburn 3366: }
1.446 www 3367:
1.445 www 3368: # Store this
1.484 raeburn 3369: unless ($toolsflag) {
1.510 raeburn 3370: if ($allowed) {
3371: &Apache::loncommon::store_course_settings($stored_folderpath,
1.519 raeburn 3372: {'folderpath' => 'scalar'});
1.510 raeburn 3373: }
1.519 raeburn 3374: my $folderpath;
1.484 raeburn 3375: if ($env{'form.folderpath'}) {
1.519 raeburn 3376: $folderpath = $env{'form.folderpath'};
3377: my (@folders)=split('&',$env{'form.folderpath'});
3378: $env{'form.foldername'}=&unescape(pop(@folders));
3379: if ($env{'form.foldername'} =~ /\:1$/) {
3380: $container = 'page';
3381: } else {
3382: $container = 'sequence';
3383: }
3384: $env{'form.folder'}=pop(@folders);
1.484 raeburn 3385: } else {
1.519 raeburn 3386: if ($env{'form.folder'} eq '' ||
3387: $env{'form.folder'} eq 'supplemental') {
3388: $folderpath='default&'.
3389: &escape(&mt('Main '.$crstype.' Documents')).
3390: ':::::';
1.484 raeburn 3391: }
3392: }
1.519 raeburn 3393: $containertag = '<input type="hidden" name="folderpath" value="" />';
3394: $pathitem = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 3395: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
3396: $showdoc='/'.$1;
3397: }
3398: if ($showdoc) { # got called in sequence from course
3399: $allowed=0;
3400: } else {
3401: if ($allowed) {
3402: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
3403: $script=&Apache::lonratedt::editscript('simple');
1.433 raeburn 3404: }
3405: }
1.329 droeschl 3406: }
3407:
1.344 bisitz 3408: # get personal data
1.329 droeschl 3409: my $uname=$env{'user.name'};
3410: my $udom=$env{'user.domain'};
3411: my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));
3412:
3413: if ($allowed) {
1.484 raeburn 3414: if ($toolsflag) {
3415: $script .= &inject_data_js();
3416: my ($home,$other,%outhash)=&authorhosts();
3417: if (!$home && $other) {
3418: my @hosts;
3419: foreach my $aurole (keys(%outhash)) {
3420: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
3421: push(@hosts,$outhash{$aurole});
3422: }
3423: }
3424: $script .= &dump_switchserver_js(@hosts);
3425: }
1.458 raeburn 3426: } else {
1.484 raeburn 3427: my @tabids;
3428: if ($supplementalflag) {
3429: @tabids = ('002','ee2','ff2');
3430: } else {
3431: @tabids = ('aa1','bb1','cc1','ff1');
1.519 raeburn 3432: unless ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 3433: unshift(@tabids,'001');
3434: push(@tabids,('dd1','ee1'));
3435: }
1.458 raeburn 3436: }
1.484 raeburn 3437: my $tabidstr = join("','",@tabids);
3438: $script .= &editing_js($udom,$uname,$supplementalflag).
3439: &history_tab_js().
3440: &inject_data_js().
1.510 raeburn 3441: &Apache::lonhtmlcommon::resize_scrollbox_js('docs',$tabidstr).
3442: &Apache::lonextresedit::extedit_javascript();
1.484 raeburn 3443: $addentries = {
1.485 raeburn 3444: onload => "javascript:resize_scrollbox('contentscroll','1','1');",
1.484 raeburn 3445: };
1.458 raeburn 3446: }
1.492 raeburn 3447: if ($env{'docs.markedcopy_url'}) {
3448: $script .= &paste_popup_js();
3449: }
1.501 raeburn 3450: my $confirm_switch = &mt("Editing requires switching to the resource's home server.").'\n'.
3451: &mt('Switch server?');
3452:
3453:
1.329 droeschl 3454: }
3455: # -------------------------------------------------------------------- Body tag
1.369 bisitz 3456: $script = '<script type="text/javascript">'."\n"
1.372 bisitz 3457: .'// <![CDATA['."\n"
3458: .$script."\n"
3459: .'// ]]>'."\n"
3460: .'</script>'."\n";
1.385 bisitz 3461:
3462: # Breadcrumbs
3463: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.510 raeburn 3464:
3465: if ($showdoc) {
3466: $r->print(&Apache::loncommon::start_page("$crstype documents",undef,
3467: {'force_register' => $showdoc,}));
3468: } elsif ($r->uri eq '/adm/supplemental') {
3469: my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype);
3470: $r->print(&Apache::loncommon::start_page("Supplemental $crstype Content",undef,
3471: {'bread_crumbs' => $brcrum,}));
3472: } else {
1.392 raeburn 3473: &Apache::lonhtmlcommon::add_breadcrumb({
1.446 www 3474: href=>"/adm/coursedocs",text=>"$crstype Contents"});
1.392 raeburn 3475:
1.446 www 3476: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script,
1.510 raeburn 3477: {'add_entries' => $addentries}
3478: )
1.392 raeburn 3479: .&Apache::loncommon::help_open_menu('','',273,'RAT')
3480: .&Apache::lonhtmlcommon::breadcrumbs(
1.484 raeburn 3481: 'Editing '.$crstype.' Contents',
1.392 raeburn 3482: 'Docs_Adding_Course_Doc')
3483: );
3484: }
1.364 bisitz 3485:
1.329 droeschl 3486: my %allfiles = ();
3487: my %codebase = ();
1.440 raeburn 3488: my ($upload_result,$upload_output,$uploadphase);
1.329 droeschl 3489: if ($allowed) {
3490: if (($env{'form.uploaddoc.filename'}) &&
3491: ($env{'form.cmd'}=~/^upload_(\w+)/)) {
1.440 raeburn 3492: my $context = $1;
3493: # Process file upload - phase one - upload and parse primary file.
1.329 droeschl 3494: undef($hadchanges);
1.440 raeburn 3495: $uploadphase = &process_file_upload(\$upload_output,$coursenum,$coursedom,
3496: \%allfiles,\%codebase,$context);
1.329 droeschl 3497: if ($hadchanges) {
3498: &mark_hash_old();
3499: }
1.440 raeburn 3500: $r->print($upload_output);
3501: } elsif ($env{'form.phase'} eq 'upload_embedded') {
3502: # Process file upload - phase two - upload embedded objects
3503: $uploadphase = 'check_embedded';
3504: my $primaryurl = &HTML::Entities::encode($env{'form.primaryurl'},'<>&"');
3505: my $state = &embedded_form_elems($uploadphase,$primaryurl,
3506: $env{'form.newidx'});
3507: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
3508: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
3509: my ($destination,$dir_root) = &embedded_destination();
3510: my $url_root = '/uploaded/'.$docudom.'/'.$docuname;
3511: my $actionurl = '/adm/coursedocs';
3512: my ($result,$flag) =
3513: &Apache::loncommon::upload_embedded('coursedoc',$destination,
3514: $docuname,$docudom,$dir_root,$url_root,undef,undef,undef,$state,
3515: $actionurl);
3516: $r->print($result.&return_to_editor());
3517: } elsif ($env{'form.phase'} eq 'check_embedded') {
3518: # Process file upload - phase three - modify references in HTML file
3519: $uploadphase = 'modified_orightml';
3520: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
3521: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
3522: my ($destination,$dir_root) = &embedded_destination();
1.482 raeburn 3523: my $result =
3524: &Apache::loncommon::modify_html_refs('coursedoc',$destination,
3525: $docuname,$docudom,undef,
3526: $dir_root);
3527: $r->print($result.&return_to_editor());
1.476 raeburn 3528: } elsif ($env{'form.phase'} eq 'decompress_uploaded') {
3529: $uploadphase = 'decompress_phase_one';
3530: $r->print(&decompression_phase_one().
3531: &return_to_editor());
3532: } elsif ($env{'form.phase'} eq 'decompress_cleanup') {
3533: $uploadphase = 'decompress_phase_two';
3534: $r->print(&decompression_phase_two().
3535: &return_to_editor());
1.329 droeschl 3536: }
3537: }
3538:
1.484 raeburn 3539: if ($allowed && $toolsflag) {
3540: $r->print(&startContentScreen('tools'));
3541: $r->print(&generate_admin_menu($crstype));
3542: $r->print(&endContentScreen());
3543: } elsif ((!$showdoc) && (!$uploadphase)) {
1.329 droeschl 3544: # -----------------------------------------------------------------------------
3545: my %lt=&Apache::lonlocal::texthash(
3546: 'copm' => 'All documents out of a published map into this folder',
1.501 raeburn 3547: 'upfi' => 'Upload File',
3548: 'upld' => 'Import Content',
1.329 droeschl 3549: 'srch' => 'Search',
3550: 'impo' => 'Import',
1.487 raeburn 3551: 'lnks' => 'Import from Stored Links',
1.502 raeburn 3552: 'impm' => 'Import from Assembled Map',
1.329 droeschl 3553: 'selm' => 'Select Map',
3554: 'load' => 'Load Map',
3555: 'newf' => 'New Folder',
3556: 'newp' => 'New Composite Page',
3557: 'syll' => 'Syllabus',
1.425 raeburn 3558: 'navc' => 'Table of Contents',
1.343 biermanm 3559: 'sipa' => 'Simple Course Page',
1.329 droeschl 3560: 'sipr' => 'Simple Problem',
3561: 'drbx' => 'Drop Box',
1.451 www 3562: 'scuf' => 'External Scores (handgrade, upload, clicker)',
1.336 schafran 3563: 'bull' => 'Discussion Board',
1.347 weissno 3564: 'mypi' => 'My Personal Information Page',
1.353 weissno 3565: 'grpo' => 'Group Portfolio',
1.329 droeschl 3566: 'rost' => 'Course Roster',
1.528 raeburn 3567: 'abou' => 'Personal Information Page for a User',
1.377 bisitz 3568: 'imsf' => 'IMS Import',
3569: 'imsl' => 'Import IMS package',
1.501 raeburn 3570: 'cms' => 'Origin of IMS package',
3571: 'se' => 'Select',
1.329 droeschl 3572: 'file' => 'File',
3573: 'title' => 'Title',
3574: 'comment' => 'Comment',
1.403 raeburn 3575: 'parse' => 'Upload embedded images/multimedia files if HTML file',
1.329 droeschl 3576: );
3577: # -----------------------------------------------------------------------------
3578: my $fileupload=(<<FIUP);
3579: $lt{'file'}:<br />
3580: <input type="file" name="uploaddoc" size="40" />
3581: FIUP
3582:
3583: my $checkbox=(<<CHBO);
3584: <!-- <label>$lt{'parse'}?
3585: <input type="checkbox" name="parserflag" />
3586: </label> -->
3587: <label>
3588: <input type="checkbox" name="parserflag" checked="checked" /> $lt{'parse'}
3589: </label>
3590: CHBO
1.501 raeburn 3591: my $imsfolder = $env{'form.folder'};
3592: if ($imsfolder eq '') {
3593: $imsfolder = 'default';
3594: }
3595: my $imspform=(<<IMSFORM);
3596: <a class="LC_menubuttons_link" href="javascript:toggleUpload('ims');">
3597: $lt{'imsf'}</a> $help{'Importing_IMS_Course'}
3598: <form name="uploadims" action="/adm/imsimportdocs" method="post" enctype="multipart/form-data" target="IMSimport">
1.516 raeburn 3599: <fieldset id="uploadimsform" style="display: none;">
1.501 raeburn 3600: <legend>$lt{'imsf'}</legend>
3601: $fileupload
3602: <br />
3603: <p>
3604: $lt{'cms'}:
3605: <select name="source">
3606: <option value="-1" selected="selected">$lt{'se'}</option>
3607: <option value="bb5">Blackboard 5</option>
3608: <option value="bb6">Blackboard 6</option>
3609: <option value="angel5">ANGEL 5.5</option>
3610: <option value="webctce4">WebCT 4 Campus Edition</option>
3611: </select>
3612: <input type="hidden" name="folder" value="$imsfolder" />
3613: </p>
3614: <input type="hidden" name="phase" value="one" />
3615: <input type="button" value="$lt{'imsl'}" onclick="makeims(this.form);" />
3616: </fieldset>
3617: </form>
3618: IMSFORM
1.329 droeschl 3619:
3620: my $fileuploadform=(<<FUFORM);
1.501 raeburn 3621: <a class="LC_menubuttons_link" href="javascript:toggleUpload('doc');">
3622: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
3623: <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.516 raeburn 3624: <fieldset id="uploaddocform" style="display: none;">
1.501 raeburn 3625: <legend>$lt{'upfi'}</legend>
1.371 tempelho 3626: <input type="hidden" name="active" value="aa" />
1.329 droeschl 3627: $fileupload
3628: <br />
3629: $lt{'title'}:<br />
1.458 raeburn 3630: <input type="text" size="60" name="comment" />
1.508 raeburn 3631: $pathitem
1.329 droeschl 3632: <input type="hidden" name="cmd" value="upload_default" />
3633: <br />
1.458 raeburn 3634: <span class="LC_nobreak" style="float:left">
1.329 droeschl 3635: $checkbox
3636: </span>
1.501 raeburn 3637: <br clear="all" />
3638: <input type="submit" value="$lt{'upld'}" />
3639: </fieldset>
3640: </form>
1.383 tempelho 3641: FUFORM
1.329 droeschl 3642:
1.502 raeburn 3643: my $importpubform=(<<SEDFFORM);
1.514 raeburn 3644: <a class="LC_menubuttons_link" href="javascript:toggleMap('map');">
1.502 raeburn 3645: $lt{'impm'}</a>$help{'Load_Map'}
3646: <form action="/adm/coursedocs" method="post" name="mapimportform">
1.516 raeburn 3647: <fieldset id="importmapform" style="display: none;">
1.502 raeburn 3648: <legend>$lt{'impm'}</legend>
1.371 tempelho 3649: <input type="hidden" name="active" value="bb" />
1.502 raeburn 3650: $lt{'copm'}<br />
3651: <span class="LC_nobreak">
3652: <input type="text" name="importmap" size="40" value=""
3653: onfocus="this.blur();openbrowser('mapimportform','importmap','sequence,page','');" />
1.516 raeburn 3654: <a href="javascript:openbrowser('mapimportform','importmap','sequence,page','');">$lt{'selm'}</a></span><br />
1.502 raeburn 3655: <input type="submit" name="loadmap" value="$lt{'load'}" />
3656: </fieldset>
3657: </form>
3658:
1.383 tempelho 3659: SEDFFORM
1.502 raeburn 3660: my @importpubforma = (
1.508 raeburn 3661: { '<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 3662: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/res.png" alt="'.$lt{impo}.'" onclick="javascript:groupimport();"/>' => "<a class='LC_menubuttons_link' href='javascript:groupimport();'>$lt{'impo'}</a>$help{'Importing_LON-CAPA_Resource'}" },
1.487 raeburn 3663: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/wishlist.png" alt="'.$lt{lnks}.'" onclick="javascript:open_StoredLinks_Import();" />' => "<a class='LC_menubuttons_link' href='javascript:open_StoredLinks_Import();'>$lt{'lnks'}</a>" },
1.514 raeburn 3664: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/sequence.png" alt="'.$lt{impm}.'" onclick="javascript:toggleMap(\'map\');" />' => $importpubform }
1.383 tempelho 3665: );
1.502 raeburn 3666: $importpubform = &create_form_ul(&create_list_elements(@importpubforma));
1.510 raeburn 3667: my $extresourcesform =
3668: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
3669: $help{'Adding_External_Resource'});
1.329 droeschl 3670: if ($allowed) {
1.492 raeburn 3671: my $folder = $env{'form.folder'};
3672: if ($folder eq '') {
3673: $folder='default';
3674: }
3675: &update_paste_buffer($coursenum,$coursedom,$folder);
1.337 ehlerst 3676: $r->print(<<HIDDENFORM);
3677: <form name="renameform" method="post" action="/adm/coursedocs">
3678: <input type="hidden" name="title" />
3679: <input type="hidden" name="cmd" />
3680: <input type="hidden" name="markcopy" />
3681: <input type="hidden" name="copyfolder" />
3682: $containertag
3683: </form>
1.484 raeburn 3684:
1.337 ehlerst 3685: HIDDENFORM
1.508 raeburn 3686: $r->print(&makesimpleeditform($pathitem)."\n".
3687: &makedocslogform($pathitem."\n".
1.484 raeburn 3688: '<input type="hidden" name="folder" value="'.
3689: $env{'form.folder'}.'" />'."\n"));
1.329 droeschl 3690: }
1.442 www 3691:
3692: # Generate the tabs
1.510 raeburn 3693: my ($mode,$needs_end);
1.472 raeburn 3694: if (($supplementalflag) && (!$allowed)) {
1.510 raeburn 3695: my @folders = split('&',$env{'form.folderpath'});
3696: unless (@folders > 2) {
3697: &Apache::lonnavdisplay::startContentScreen($r,'supplemental');
3698: $needs_end = 1;
3699: }
1.472 raeburn 3700: } else {
1.484 raeburn 3701: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.510 raeburn 3702: $needs_end = 1;
1.472 raeburn 3703: }
1.443 www 3704:
1.442 www 3705: #
3706:
3707: my $savefolderpath;
3708:
1.395 raeburn 3709: if ($allowed) {
1.329 droeschl 3710: my $folder=$env{'form.folder'};
1.443 www 3711: if ($folder eq '' || $supplementalflag) {
1.329 droeschl 3712: $folder='default';
1.356 tempelho 3713: $savefolderpath = $env{'form.folderpath'};
1.442 www 3714: $env{'form.folderpath'}='default&'.&escape(&mt('Content'));
1.508 raeburn 3715: $pathitem = '<input type="hidden" name="folderpath" value="'.
1.329 droeschl 3716: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
3717: }
3718: my $postexec='';
3719: if ($folder eq 'default') {
1.372 bisitz 3720: $r->print('<script type="text/javascript">'."\n"
3721: .'// <![CDATA['."\n"
3722: .'this.window.name="loncapaclient";'."\n"
3723: .'// ]]>'."\n"
3724: .'</script>'."\n"
1.369 bisitz 3725: );
1.329 droeschl 3726: } else {
3727: #$postexec='self.close();';
3728: }
1.504 raeburn 3729: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.sequence';
3730: my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.page';
1.329 droeschl 3731: my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
3732:
3733: my $newnavform=(<<NNFORM);
3734: <form action="/adm/coursedocs" method="post" name="newnav">
1.371 tempelho 3735: <input type="hidden" name="active" value="cc" />
1.508 raeburn 3736: $pathitem
1.329 droeschl 3737: <input type="hidden" name="importdetail"
3738: value="$lt{'navc'}=/adm/navmaps" />
1.423 onken 3739: <a class="LC_menubuttons_link" href="javascript:document.newnav.submit()">$lt{'navc'}</a>
1.329 droeschl 3740: $help{'Navigate_Content'}
3741: </form>
3742: NNFORM
3743: my $newsmppageform=(<<NSPFORM);
3744: <form action="/adm/coursedocs" method="post" name="newsmppg">
1.371 tempelho 3745: <input type="hidden" name="active" value="cc" />
1.508 raeburn 3746: $pathitem
1.329 droeschl 3747: <input type="hidden" name="importdetail" value="" />
1.423 onken 3748: <a class="LC_menubuttons_link" href="javascript:makesmppage();"> $lt{'sipa'}</a>
1.383 tempelho 3749: $help{'Simple Page'}
1.329 droeschl 3750: </form>
3751: NSPFORM
3752:
3753: my $newsmpproblemform=(<<NSPROBFORM);
3754: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
1.371 tempelho 3755: <input type="hidden" name="active" value="cc" />
1.508 raeburn 3756: $pathitem
1.329 droeschl 3757: <input type="hidden" name="importdetail" value="" />
1.423 onken 3758: <a class="LC_menubuttons_link" href="javascript:makesmpproblem();">$lt{'sipr'}</a>
1.383 tempelho 3759: $help{'Simple Problem'}
1.329 droeschl 3760: </form>
3761:
3762: NSPROBFORM
3763:
3764: my $newdropboxform=(<<NDBFORM);
3765: <form action="/adm/coursedocs" method="post" name="newdropbox">
1.371 tempelho 3766: <input type="hidden" name="active" value="cc" />
1.508 raeburn 3767: $pathitem
1.329 droeschl 3768: <input type="hidden" name="importdetail" value="" />
1.423 onken 3769: <a class="LC_menubuttons_link" href="javascript:makedropbox();">$lt{'drbx'}</a>
1.344 bisitz 3770: </form>
1.329 droeschl 3771: NDBFORM
3772:
3773: my $newexuploadform=(<<NEXUFORM);
3774: <form action="/adm/coursedocs" method="post" name="newexamupload">
1.371 tempelho 3775: <input type="hidden" name="active" value="cc" />
1.508 raeburn 3776: $pathitem
1.329 droeschl 3777: <input type="hidden" name="importdetail" value="" />
1.423 onken 3778: <a class="LC_menubuttons_link" href="javascript:makeexamupload();">$lt{'scuf'}</a>
1.329 droeschl 3779: $help{'Score_Upload_Form'}
3780: </form>
3781: NEXUFORM
3782:
3783: my $newbulform=(<<NBFORM);
3784: <form action="/adm/coursedocs" method="post" name="newbul">
1.371 tempelho 3785: <input type="hidden" name="active" value="cc" />
1.508 raeburn 3786: $pathitem
1.329 droeschl 3787: <input type="hidden" name="importdetail" value="" />
1.423 onken 3788: <a class="LC_menubuttons_link" href="javascript:makebulboard();" >$lt{'bull'}</a>
1.329 droeschl 3789: $help{'Bulletin Board'}
3790: </form>
3791: NBFORM
3792:
3793: my $newaboutmeform=(<<NAMFORM);
3794: <form action="/adm/coursedocs" method="post" name="newaboutme">
1.371 tempelho 3795: <input type="hidden" name="active" value="cc" />
1.508 raeburn 3796: $pathitem
1.329 droeschl 3797: <input type="hidden" name="importdetail"
3798: value="$plainname=/adm/$udom/$uname/aboutme" />
1.423 onken 3799: <a class="LC_menubuttons_link" href="javascript:document.newaboutme.submit()">$lt{'mypi'}</a>
1.347 weissno 3800: $help{'My Personal Information Page'}
1.329 droeschl 3801: </form>
3802: NAMFORM
3803:
3804: my $newaboutsomeoneform=(<<NASOFORM);
3805: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
1.371 tempelho 3806: <input type="hidden" name="active" value="cc" />
1.508 raeburn 3807: $pathitem
1.329 droeschl 3808: <input type="hidden" name="importdetail" value="" />
1.423 onken 3809: <a class="LC_menubuttons_link" href="javascript:makeabout();">$lt{'abou'}</a>
1.329 droeschl 3810: </form>
3811: NASOFORM
3812:
3813:
3814: my $newrosterform=(<<NROSTFORM);
3815: <form action="/adm/coursedocs" method="post" name="newroster">
1.371 tempelho 3816: <input type="hidden" name="active" value="cc" />
1.508 raeburn 3817: $pathitem
1.329 droeschl 3818: <input type="hidden" name="importdetail"
3819: value="$lt{'rost'}=/adm/viewclasslist" />
1.423 onken 3820: <a class="LC_menubuttons_link" href="javascript:document.newroster.submit()">$lt{'rost'}</a>
1.329 droeschl 3821: $help{'Course Roster'}
3822: </form>
3823: NROSTFORM
3824:
1.342 ehlerst 3825: my $specialdocumentsform;
1.383 tempelho 3826: my @specialdocumentsforma;
1.451 www 3827: my $gradingform;
3828: my @gradingforma;
3829: my $communityform;
3830: my @communityforma;
1.351 ehlerst 3831: my $newfolderform;
1.390 tempelho 3832: my $newfolderb;
1.342 ehlerst 3833:
1.451 www 3834: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.383 tempelho 3835:
1.329 droeschl 3836: my $newpageform=(<<NPFORM);
3837: <form action="/adm/coursedocs" method="post" name="newpage">
3838: <input type="hidden" name="folderpath" value="$path" />
3839: <input type="hidden" name="importdetail" value="" />
1.371 tempelho 3840: <input type="hidden" name="active" value="cc" />
1.423 onken 3841: <a class="LC_menubuttons_link" href="javascript:makenewpage(document.newpage,'$pageseq');">$lt{'newp'}</a>
1.383 tempelho 3842: $help{'Adding_Pages'}
1.329 droeschl 3843: </form>
3844: NPFORM
1.390 tempelho 3845:
3846:
1.351 ehlerst 3847: $newfolderform=(<<NFFORM);
1.329 droeschl 3848: <form action="/adm/coursedocs" method="post" name="newfolder">
1.508 raeburn 3849: $pathitem
1.329 droeschl 3850: <input type="hidden" name="importdetail" value="" />
1.371 tempelho 3851: <input type="hidden" name="active" value="aa" />
1.422 onken 3852: <a href="javascript:makenewfolder(document.newfolder,'$folderseq');">$lt{'newf'}</a>$help{'Adding_Folders'}
1.329 droeschl 3853: </form>
3854: NFFORM
3855:
3856: my $newsylform=(<<NSYLFORM);
3857: <form action="/adm/coursedocs" method="post" name="newsyl">
1.371 tempelho 3858: <input type="hidden" name="active" value="cc" />
1.508 raeburn 3859: $pathitem
1.329 droeschl 3860: <input type="hidden" name="importdetail"
3861: value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />
1.423 onken 3862: <a class="LC_menubuttons_link" href="javascript:document.newsyl.submit()">$lt{'syll'}</a>
1.329 droeschl 3863: $help{'Syllabus'}
1.383 tempelho 3864:
1.329 droeschl 3865: </form>
3866: NSYLFORM
1.364 bisitz 3867:
1.329 droeschl 3868: my $newgroupfileform=(<<NGFFORM);
3869: <form action="/adm/coursedocs" method="post" name="newgroupfiles">
1.371 tempelho 3870: <input type="hidden" name="active" value="cc" />
1.508 raeburn 3871: $pathitem
1.329 droeschl 3872: <input type="hidden" name="importdetail"
3873: value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
1.423 onken 3874: <a class="LC_menubuttons_link" href="javascript:document.newgroupfiles.submit()">$lt{'grpo'}</a>
1.353 weissno 3875: $help{'Group Portfolio'}
1.329 droeschl 3876: </form>
3877: NGFFORM
1.383 tempelho 3878: @specialdocumentsforma=(
1.421 onken 3879: {'<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 3880: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="document.newsyl.submit()" />'=>$newsylform},
1.451 www 3881: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/navigation.png" alt="'.$lt{navc}.'" onclick="document.newnav.submit()" />'=>$newnavform},
3882: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simple.png" alt="'.$lt{sipa}.'" onclick="javascript:makesmppage();" />'=>$newsmppageform},
3883: );
3884: $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma));
3885:
1.434 raeburn 3886:
3887: my @importdoc = (
1.519 raeburn 3888: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="toggleUpload(\'ext\');" />'=>$extresourcesform}
3889: );
3890: unless ($container eq 'page') {
3891: push(@importdoc,
3892: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/ims.png" alt="'.$lt{imsf}.'" onclick="javascript:toggleUpload(\'ims\');" />'=>$imspform}
3893: );
3894: }
3895: push(@importdoc,
3896: {'<img class="LC_noBorder_LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'doc\');" />'=>$fileuploadform}
3897: );
1.501 raeburn 3898: $fileuploadform = &create_form_ul(&create_list_elements(@importdoc));
1.434 raeburn 3899:
1.451 www 3900: @gradingforma=(
3901: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{sipr}.'" onclick="javascript:makesmpproblem();" />'=>$newsmpproblemform},
3902: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/dropbox.png" alt="'.$lt{drbx}.'" onclick="javascript:makedropbox();" />'=>$newdropboxform},
3903: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/scoreupfrm.png" alt="'.$lt{scuf}.'" onclick="javascript:makeexamupload();" />'=>$newexuploadform},
3904:
3905: );
3906: $gradingform = &create_form_ul(&create_list_elements(@gradingforma));
3907:
3908: @communityforma=(
3909: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/bchat.png" alt="'.$lt{bull}.'" onclick="javascript:makebulboard();" />'=>$newbulform},
3910: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makebulboard();" />'=>$newaboutmeform},
3911: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/aboutme.png" alt="'.$lt{abou}.'" onclick="javascript:makeabout();" />'=>$newaboutsomeoneform},
3912: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/clst.png" alt="'.$lt{rost}.'" onclick="document.newroster.submit()" />'=>$newrosterform},
3913: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/groupportfolio.png" alt="'.$lt{grpo}.'" onclick="document.newgroupfiles.submit()" />'=>$newgroupfileform},
3914: );
3915: $communityform = &create_form_ul(&create_list_elements(@communityforma));
1.383 tempelho 3916:
1.330 tempelho 3917: my %orderhash = (
1.488 raeburn 3918: 'aa' => ['Import Content',$fileuploadform],
1.502 raeburn 3919: 'bb' => ['Published Content',$importpubform],
1.451 www 3920: 'cc' => ['Grading Resources',$gradingform],
1.330 tempelho 3921: );
1.519 raeburn 3922: unless ($container eq 'page') {
1.434 raeburn 3923: $orderhash{'00'} = ['Newfolder',$newfolderform];
1.484 raeburn 3924: $orderhash{'dd'} = ['Collaboration',$communityform];
1.515 raeburn 3925: $orderhash{'ee'} = ['Special Pages',$specialdocumentsform];
1.434 raeburn 3926: }
3927:
1.341 ehlerst 3928: $hadchanges=0;
1.484 raeburn 3929: unless (($supplementalflag || $toolsflag)) {
1.458 raeburn 3930: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.508 raeburn 3931: $supplementalflag,\%orderhash,$iconpath,$pathitem);
1.443 www 3932: if ($error) {
3933: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
3934: }
3935: if ($hadchanges) {
3936: &mark_hash_old();
3937: }
1.341 ehlerst 3938:
1.443 www 3939: &changewarning($r,'');
3940: }
1.458 raeburn 3941: }
1.442 www 3942:
1.443 www 3943: # Supplemental documents start here
3944:
1.329 droeschl 3945: my $folder=$env{'form.folder'};
1.443 www 3946: unless ($supplementalflag) {
1.329 droeschl 3947: $folder='supplemental';
3948: }
3949: if ($folder =~ /^supplemental$/ &&
3950: (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
1.446 www 3951: $env{'form.folderpath'} = &supplemental_base();
1.393 raeburn 3952: } elsif ($allowed) {
1.356 tempelho 3953: $env{'form.folderpath'} = $savefolderpath;
1.329 droeschl 3954: }
1.508 raeburn 3955: $pathitem = '<input type="hidden" name="folderpath" value="'.
3956: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
1.329 droeschl 3957: if ($allowed) {
3958: my $folderseq=
1.504 raeburn 3959: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_new.sequence';
1.329 droeschl 3960:
3961: my $supupdocform=(<<SUPDOCFORM);
1.501 raeburn 3962: <a class="LC_menubuttons_link" href="javascript:toggleUpload('suppdoc');">
3963: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
1.383 tempelho 3964: <form action="/adm/coursedocs" method="post" name="supuploaddocument" enctype="multipart/form-data">
1.516 raeburn 3965: <fieldset id="uploadsuppdocform" style="display: none;">
1.501 raeburn 3966: <legend>$lt{'upfi'}</legend>
1.371 tempelho 3967: <input type="hidden" name="active" value="ee" />
1.329 droeschl 3968: $fileupload
3969: <br />
3970: <br />
3971: <span class="LC_nobreak">
3972: $checkbox
3973: </span>
3974: <br /><br />
3975: $lt{'comment'}:<br />
1.383 tempelho 3976: <textarea cols="50" rows="4" name="comment"></textarea>
1.329 droeschl 3977: <br />
1.508 raeburn 3978: $pathitem
1.329 droeschl 3979: <input type="hidden" name="cmd" value="upload_supplemental" />
1.501 raeburn 3980: <input type='submit' value="$lt{'upld'}" />
3981: </form>
1.329 droeschl 3982: SUPDOCFORM
3983:
3984: my $supnewfolderform=(<<SNFFORM);
3985: <form action="/adm/coursedocs" method="post" name="supnewfolder">
1.371 tempelho 3986: <input type="hidden" name="active" value="ee" />
1.508 raeburn 3987: $pathitem
1.329 droeschl 3988: <input type="hidden" name="importdetail" value="" />
1.423 onken 3989: <a class="LC_menubuttons_link" href="javascript:makenewfolder(document.supnewfolder,'$folderseq');">$lt{'newf'}</a>
1.383 tempelho 3990: $help{'Adding_Folders'}
1.329 droeschl 3991: </form>
3992: SNFFORM
1.383 tempelho 3993:
1.510 raeburn 3994: my $supextform =
3995: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
3996: $help{'Adding_External_Resource'});
1.329 droeschl 3997:
3998: my $supnewsylform=(<<SNSFORM);
3999: <form action="/adm/coursedocs" method="post" name="supnewsyl">
1.371 tempelho 4000: <input type="hidden" name="active" value="ff" />
1.508 raeburn 4001: $pathitem
1.329 droeschl 4002: <input type="hidden" name="importdetail"
4003: value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
1.423 onken 4004: <a class="LC_menubuttons_link" href="javascript:document.supnewsyl.submit()">$lt{'syll'}</a>
1.329 droeschl 4005: $help{'Syllabus'}
4006: </form>
4007: SNSFORM
4008:
4009: my $supnewaboutmeform=(<<SNAMFORM);
1.383 tempelho 4010: <form action="/adm/coursedocs" method="post" name="supnewaboutme">
1.371 tempelho 4011: <input type="hidden" name="active" value="ff" />
1.508 raeburn 4012: $pathitem
1.329 droeschl 4013: <input type="hidden" name="importdetail"
4014: value="$plainname=/adm/$udom/$uname/aboutme" />
1.423 onken 4015: <a class="LC_menubuttons_link" href="javascript:document.supnewaboutme.submit()">$lt{'mypi'}</a>
1.347 weissno 4016: $help{'My Personal Information Page'}
1.329 droeschl 4017: </form>
4018: SNAMFORM
4019:
1.333 muellerd 4020:
1.383 tempelho 4021: my @specialdocs = (
1.417 droeschl 4022: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="document.supnewsyl.submit()" />'
4023: =>$supnewsylform},
4024: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="document.supnewaboutme.submit()" />'
4025: =>$supnewaboutmeform},
1.383 tempelho 4026: );
1.417 droeschl 4027: my @supimportdoc = (
1.515 raeburn 4028: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="javascript:toggleUpload(\'suppext\')" />'
1.501 raeburn 4029: =>$supextform},
4030: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'suppdoc\');" />'
4031: =>$supupdocform},
4032: );
4033:
4034: $supupdocform = &create_form_ul(&create_list_elements(@supimportdoc));
1.333 muellerd 4035: my %suporderhash = (
1.390 tempelho 4036: '00' => ['Supnewfolder', $supnewfolderform],
1.488 raeburn 4037: 'ee' => ['Import Content',$supupdocform],
1.515 raeburn 4038: 'ff' => ['Special Pages',&create_form_ul(&create_list_elements(@specialdocs))]
1.333 muellerd 4039: );
1.443 www 4040: if ($supplementalflag) {
1.458 raeburn 4041: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.508 raeburn 4042: $supplementalflag,\%suporderhash,$iconpath,$pathitem);
1.443 www 4043: if ($error) {
4044: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
4045: }
1.393 raeburn 4046: }
1.443 www 4047: } elsif ($supplementalflag) {
1.458 raeburn 4048: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.508 raeburn 4049: $supplementalflag,'',$iconpath,$pathitem);
1.393 raeburn 4050: if ($error) {
4051: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.383 tempelho 4052: }
1.393 raeburn 4053: }
1.389 tempelho 4054:
1.510 raeburn 4055: if ($needs_end) {
4056: $r->print(&endContentScreen());
4057: }
1.383 tempelho 4058:
1.329 droeschl 4059: if ($allowed) {
4060: $r->print('
4061: <form method="post" name="extimport" action="/adm/coursedocs">
4062: <input type="hidden" name="title" />
4063: <input type="hidden" name="url" />
4064: <input type="hidden" name="useform" />
4065: <input type="hidden" name="residx" />
4066: </form>');
4067: }
1.484 raeburn 4068: } elsif ($showdoc) {
1.329 droeschl 4069: # -------------------------------------------------------- This is showdoc mode
1.484 raeburn 4070: $r->print("<h1>".&mt('Uploaded Document').' - '.
1.498 bisitz 4071: &Apache::lonnet::gettitle($r->uri).'</h1><p class="LC_warning">'.
1.329 droeschl 4072: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><table>".
1.484 raeburn 4073: &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');
1.329 droeschl 4074: }
4075: }
4076: $r->print(&Apache::loncommon::end_page());
4077: return OK;
1.364 bisitz 4078: }
1.329 droeschl 4079:
1.440 raeburn 4080: sub embedded_form_elems {
4081: my ($phase,$primaryurl,$newidx) = @_;
4082: my $folderpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
4083: return <<STATE;
4084: <input type="hidden" name="folderpath" value="$folderpath" />
4085: <input type="hidden" name="cmd" value="upload_embedded" />
4086: <input type="hidden" name="newidx" value="$newidx" />
4087: <input type="hidden" name="phase" value="$phase" />
4088: <input type="hidden" name="primaryurl" value="$primaryurl" />
4089: STATE
4090: }
4091:
4092: sub embedded_destination {
4093: my $folder=$env{'form.folder'};
4094: my $destination = 'docs/';
4095: if ($folder =~ /^supplemental/) {
4096: $destination = 'supplemental/';
4097: }
4098: if (($folder eq 'default') || ($folder eq 'supplemental')) {
4099: $destination .= 'default/';
4100: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
4101: $destination .= $2.'/';
4102: }
4103: $destination .= $env{'form.newidx'};
4104: my $dir_root = '/userfiles';
4105: return ($destination,$dir_root);
4106: }
4107:
4108: sub return_to_editor {
4109: my $actionurl = '/adm/coursedocs';
4110: return '<p><form name="backtoeditor" method="post" action="'.$actionurl.'" />'."\n".
4111: '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" /></form>'."\n".
4112: '<a href="javascript:document.backtoeditor.submit();">'.&mt('Return to Editor').
4113: '</a></p>';
4114: }
4115:
1.476 raeburn 4116: sub decompression_info {
4117: my ($destination,$dir_root) = &embedded_destination();
4118: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
4119: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
4120: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
4121: my $container='sequence';
1.480 raeburn 4122: my ($pathitem,$hiddenelem);
1.519 raeburn 4123: my @hiddens = ('newidx','comment','position','folderpath');
4124: if ($env{'form.folderpath'} =~ /\:1$/) {
1.476 raeburn 4125: $container='page';
4126: }
1.480 raeburn 4127: unshift(@hiddens,$pathitem);
4128: foreach my $item (@hiddens) {
4129: if ($env{'form.'.$item}) {
4130: $hiddenelem .= '<input type="hidden" name="'.$item.'" value="'.
4131: $env{'form.'.$item}.'" />'."\n";
4132: }
1.477 raeburn 4133: }
1.476 raeburn 4134: return ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,
4135: $hiddenelem);
4136: }
4137:
4138: sub decompression_phase_one {
4139: my ($dir,$file,$warning,$error,$output);
4140: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
4141: &decompression_info();
1.490 raeburn 4142: if ($env{'form.archiveurl'} !~ m{^/uploaded/\Q$docudom/$docuname/\E(?:docs|supplemental)/(?:default|\d+).*/([^/]+)$}) {
1.476 raeburn 4143: $error = &mt('Archive file "[_1]" not in the expected location.',$env{'form.archiveurl'});
4144: } else {
4145: my $file = $1;
1.481 raeburn 4146: $output =
4147: &Apache::loncommon::process_decompression($docudom,$docuname,$file,
4148: $destination,$dir_root,
4149: $hiddenelem);
4150: if ($env{'form.autoextract_camtasia'}) {
4151: $output .= &remove_archive($docudom,$docuname,$container);
4152: }
1.476 raeburn 4153: }
4154: if ($error) {
4155: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
4156: $error.'</p>'."\n";
4157: }
4158: if ($warning) {
4159: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
4160: }
4161: return $output;
4162: }
4163:
4164: sub decompression_phase_two {
4165: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
4166: &decompression_info();
1.481 raeburn 4167: my $output;
1.480 raeburn 4168: if ($env{'form.archivedelete'}) {
1.481 raeburn 4169: $output = &remove_archive($docudom,$docuname,$container);
1.480 raeburn 4170: }
4171: $output .=
1.481 raeburn 4172: &Apache::loncommon::process_extracted_files('coursedocs',$docudom,$docuname,
1.476 raeburn 4173: $destination,$dir_root,$hiddenelem);
4174: return $output;
4175: }
4176:
1.480 raeburn 4177: sub remove_archive {
4178: my ($docudom,$docuname,$container) = @_;
4179: my $map = $env{'form.folder'}.'.'.$container;
1.481 raeburn 4180: my ($output,$delwarning,$delresult,$url);
1.480 raeburn 4181: my ($errtext,$fatal) = &mapread($docuname,$docudom,$map);
4182: if ($fatal) {
4183: if ($container eq 'page') {
4184: $delwarning = &mt('An error occurred retrieving the contents of the current page.');
4185: } else {
4186: $delwarning = &mt('An error occurred retrieving the contents of the current folder.');
4187: }
4188: $delwarning .= &mt('As a result the archive file has not been removed.');
4189: } else {
4190: my $currcmd = $env{'form.cmd'};
4191: my $position = $env{'form.position'};
4192: if ($position > 0) {
4193: $env{'form.cmd'} = 'del_'.$position;
4194: my ($title,$url,@rrest) =
4195: split(/:/,$LONCAPA::map::resources[$LONCAPA::map::order[$position]]);
4196: if (&handle_edit_cmd($docuname,$docudom)) {
1.492 raeburn 4197: ($errtext,$fatal) = &storemap($docuname,$docudom,$map,1);
1.480 raeburn 4198: if ($fatal) {
4199: if ($container eq 'page') {
4200: $delwarning = &mt('An error occurred updating the contents of the current page.');
4201: } else {
4202: $delwarning = &mt('An error occurred updating the contents of the current folder.');
4203: }
4204: } else {
1.481 raeburn 4205: $delresult = &mt('Archive file removed.');
1.480 raeburn 4206: }
4207: }
4208: }
4209: $env{'form.cmd'} = $currcmd;
4210: }
4211: if ($delwarning) {
4212: $output = '<p class="LC_warning">'.
4213: $delwarning.
4214: '</p>';
4215: }
4216: if ($delresult) {
4217: $output .= '<p class="LC_info">'.
4218: $delresult.
4219: '</p>';
4220: }
1.481 raeburn 4221: return $output;
1.480 raeburn 4222: }
4223:
1.484 raeburn 4224: sub generate_admin_menu {
4225: my ($crstype) = @_;
4226: my $lc_crstype = lc($crstype);
4227: my ($home,$other,%outhash)=&authorhosts();
4228: my %lt=&Apache::lonlocal::texthash (
4229: 'vc' => 'Verify Content',
4230: 'cv' => 'Check/Set Resource Versions',
4231: 'ls' => 'List Resource Identifiers',
4232: 'imse' => 'Export contents to IMS Archive',
4233: 'dcd' => "Dump $crstype Content to Authoring Space",
4234: );
4235: my ($candump,$dumpurl);
4236: if ($home + $other > 0) {
4237: $candump = 'F';
4238: if ($home) {
4239: $dumpurl = "javascript:injectData(document.courseverify,'dummy','dumpcourse','$lt{'dcd'}')";
4240: } else {
4241: my @hosts;
4242: foreach my $aurole (keys(%outhash)) {
4243: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
4244: push(@hosts,$outhash{$aurole});
4245: }
4246: }
4247: if (@hosts == 1) {
4248: my $switchto = '/adm/switchserver?otherserver='.$hosts[0].
4249: '&role='.
4250: &HTML::Entities::encode($env{'request.role'},'"<>&').'&origurl='.
4251: &HTML::Entities::encode('/adm/coursedocs?dumpcourse=1','"<>&');
4252: $dumpurl = "javascript:dump_needs_switchserver('$switchto')";
4253: } else {
4254: $dumpurl = "javascript:choose_switchserver_window()";
4255: }
4256: }
4257: }
4258: my @menu=
4259: ({ categorytitle=>'Administration',
4260: items =>[
4261: { linktext => $lt{'vc'},
4262: url => "javascript:injectData(document.courseverify,'dummy','verify','$lt{'vc'}')",
4263: permission => 'F',
4264: help => 'Verify_Content',
4265: icon => 'verify.png',
4266: linktitle => 'Verify contents can be retrieved/rendered',
4267: },
4268: { linktext => $lt{'cv'},
4269: url => "javascript:injectData(document.courseverify,'dummy','versions','$lt{'cv'}')",
4270: permission => 'F',
4271: help => 'Check_Resource_Versions',
4272: icon => 'resversion.png',
4273: linktitle => "View version information for resources in your $lc_crstype, and fix/unfix use of specific versions",
4274: },
4275: { linktext => $lt{'ls'},
4276: url => "javascript:injectData(document.courseverify,'dummy','listsymbs','$lt{'ls'}')",
4277: permission => 'F',
4278: #help => '',
4279: icon => 'symbs.png',
4280: linktitle => "List the unique identifier used for each resource instance in your $lc_crstype"
4281: },
4282: ]
4283: },
4284: { categorytitle=>'Export',
4285: items =>[
4286: { linktext => $lt{'imse'},
4287: url => "javascript:injectData(document.courseverify,'dummy','exportcourse','$lt{'imse'}')",
4288: permission => 'F',
4289: help => 'Docs_Export_Course_Docs',
4290: icon => 'imsexport.png',
4291: linktitle => $lt{'imse'},
4292: },
4293: { linktext => $lt{'dcd'},
4294: url => $dumpurl,
4295: permission => $candump,
4296: #help => '',
4297: icon => 'dump.png',
4298: linktitle => $lt{'dcd'},
4299: },
4300: ]
4301: });
4302: return '<form action="/adm/coursedocs" method="post" name="courseverify">'."\n".
4303: '<input type="hidden" id="dummy" />'."\n".
4304: &Apache::lonhtmlcommon::generate_menu(@menu)."\n".
4305: '</form>';
1.329 droeschl 4306: }
4307:
4308: sub generate_edit_table {
1.484 raeburn 4309: my ($tid,$orderhash_ref,$to_show,$iconpath,$jumpto,$readfile) = @_;
1.406 raeburn 4310: return unless(ref($orderhash_ref) eq 'HASH');
1.342 ehlerst 4311: my %orderhash = %{$orderhash_ref};
1.344 bisitz 4312: my $form;
1.371 tempelho 4313: my $activetab;
4314: my $active;
1.526 raeburn 4315: if (($env{'form.active'} ne '') && ($env{'form.active'} ne 'aa')) {
1.371 tempelho 4316: $activetab = $env{'form.active'};
4317: }
1.472 raeburn 4318: my $backicon = $iconpath.'clickhere.gif';
1.525 raeburn 4319: my $backtext = &mt('Exit Editor');
1.458 raeburn 4320: $form = '<div class="LC_Box" style="margin:0;">'.
1.488 raeburn 4321: '<ul id="navigation'.$tid.'" class="LC_TabContent">'."\n".
4322: '<li class="goback">'.
1.525 raeburn 4323: '<a href="javascript:toContents('.$jumpto.');">'.
1.488 raeburn 4324: '<img src="'.$backicon.'" class="LC_icon" style="border: none; vertical-align: top;"'.
4325: ' alt="'.$backtext.'" />'.$backtext.'</a></li>'."\n".
4326: '<li>'.
4327: '<a href="javascript:groupopen('."'$readfile'".',1);">'.
4328: &mt('Undo Delete').'</a></li>'."\n";
4329: if ($env{'form.docslog'}) {
4330: $form .= '<li class="active">';
4331: } else {
4332: $form .= '<li>';
4333: }
4334: $form .= '<a href="javascript:toggleHistoryDisp(1);">'.
4335: &mt('History').'</a></li>'."\n";
4336: if ($env{'form.docslog'}) {
4337: $form .= '<li><a href="javascript:toggleHistoryDisp(0);">'.
4338: &mt('Edit').'</a></li>'."\n";
1.484 raeburn 4339: }
1.458 raeburn 4340: foreach my $name (reverse(sort(keys(%orderhash)))) {
1.390 tempelho 4341: if($name ne '00'){
1.371 tempelho 4342: if($activetab eq '' || $activetab ne $name){
4343: $active = '';
4344: }elsif($activetab eq $name){
4345: $active = 'class="active"';
4346: }
1.458 raeburn 4347: $form .= '<li style="float:right" '.$active
1.484 raeburn 4348: .' 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 4349: } else {
1.484 raeburn 4350: $form .= '<li '.$active.' style="float:right">'.${$orderhash{$name}}[1].'</li>'."\n";
1.390 tempelho 4351:
4352: }
1.329 droeschl 4353: }
1.484 raeburn 4354: $form .= '</ul>'."\n";
4355: $form .= '<div id="content'.$tid.'" style="padding: 0 0; margin: 0 0; overflow: hidden; clear:right">'."\n";
1.458 raeburn 4356:
4357: if ($to_show ne '') {
1.484 raeburn 4358: $form .= '<div style="padding:0;margin:0;float:left">'.$to_show.'</div>'."\n";
1.458 raeburn 4359: }
1.363 ehlerst 4360: foreach my $field (keys(%orderhash)){
1.390 tempelho 4361: if($field ne '00'){
1.422 onken 4362: if($activetab eq '' || $activetab ne $field){
1.458 raeburn 4363: $active = 'style="display: none;float:left"';
1.422 onken 4364: }elsif($activetab eq $field){
1.458 raeburn 4365: $active = 'style="display:block;float:left"';
1.422 onken 4366: }
4367: $form .= '<div id="'.$field.$tid.'"'
4368: .' class="LC_ContentBox" '.$active.'>'.${$orderhash{$field}}[1]
1.484 raeburn 4369: .'</div>'."\n";
1.363 ehlerst 4370: }
4371: }
1.484 raeburn 4372: unless ($env{'form.docslog'}) {
4373: $form .= '</div></div>'."\n";
4374: }
1.329 droeschl 4375: return $form;
4376: }
4377:
4378: sub editing_js {
1.472 raeburn 4379: my ($udom,$uname,$supplementalflag) = @_;
1.329 droeschl 4380: my $now = time();
4381: my %lt = &Apache::lonlocal::texthash(
4382: p_mnf => 'Name of New Folder',
4383: t_mnf => 'New Folder',
4384: p_mnp => 'Name of New Page',
4385: t_mnp => 'New Page',
1.451 www 4386: p_mxu => 'Title for the External Score',
1.349 biermanm 4387: p_msp => 'Name of Simple Course Page',
1.329 droeschl 4388: p_msb => 'Title for the Problem',
4389: p_mdb => 'Title for the Drop Box',
1.336 schafran 4390: p_mbb => 'Title for the Discussion Board',
1.348 weissno 4391: p_mab => "Enter user:domain for User's Personal Information Page",
1.352 bisitz 4392: p_mab2 => 'Personal Information Page of ',
1.329 droeschl 4393: p_mab_alrt1 => 'Not a valid user:domain',
4394: p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',
4395: p_chn => 'New Title',
4396: p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',
4397: p_rmr2a => 'Remove[_99]',
4398: p_rmr2b => '?[_99]',
4399: p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',
4400: p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',
4401: p_ctr2a => 'Cut[_98]',
1.478 raeburn 4402: p_ctr2b => '?[_98]',
4403: rpck => 'Enter number to pick (e.g., 3)',
1.501 raeburn 4404: imsfile => 'You must choose an IMS package for import',
4405: imscms => 'You must select which Course Management System was the source of the IMS package',
4406: invurl => 'Invalid URL',
4407: titbl => 'Title is blank',
1.329 droeschl 4408: );
4409:
1.433 raeburn 4410: my $crstype = &Apache::loncommon::course_type();
1.434 raeburn 4411: my $docs_folderpath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'},'<>&"');
4412: my $main_container_page;
1.519 raeburn 4413: if (&HTML::Entities::decode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'}) =~ /\:1$/) {
4414: $main_container_page = 1;
1.434 raeburn 4415: }
1.519 raeburn 4416: my $toplevelmain = 'default&Main%20'.$crstype.'%20Documents%3A%3A%3A%3A%3A';
1.446 www 4417: my $toplevelsupp = &supplemental_base();
1.433 raeburn 4418:
1.525 raeburn 4419: my $backtourl;
1.530 raeburn 4420: if ($env{'docs.exit.'.$env{'request.course.id'}} =~ /^direct_(.+)$/) {
4421: my $caller = $1;
1.525 raeburn 4422: if ($caller =~ /^supplemental/) {
4423: $backtourl = '/adm/supplemental?folderpath='.&escape($caller);
4424: } else {
4425: my ($map,$id,$res)=&Apache::lonnet::decode_symb($caller);
4426: $res = &Apache::lonnet::clutter($res);
4427: if (&Apache::lonnet::is_on_map($res)) {
4428: $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($res),'<>&"').'?symb='.
4429: &HTML::Entities::encode($caller,'<>&"');
4430: }
4431: }
4432: } elsif ($env{'docs.exit.'.$env{'request.course.id'}} eq '/adm/menu') {
4433: $backtourl = '/adm/menu';
4434: } elsif ($supplementalflag) {
1.472 raeburn 4435: $backtourl = '/adm/supplemental';
1.525 raeburn 4436: } else {
4437: $backtourl = '/adm/navmaps';
1.472 raeburn 4438: }
4439:
1.519 raeburn 4440: my $fieldsets = "'ext','doc'";
4441: unless ($main_container_page) {
4442: $fieldsets .=",'ims'";
4443: }
1.501 raeburn 4444: if ($supplementalflag) {
4445: $fieldsets = "'suppext','suppdoc'";
4446: }
4447:
1.329 droeschl 4448: return <<ENDNEWSCRIPT;
4449: function makenewfolder(targetform,folderseq) {
4450: var foldername=prompt('$lt{"p_mnf"}','$lt{"t_mnf"}');
4451: if (foldername) {
4452: targetform.importdetail.value=escape(foldername)+"="+folderseq;
4453: targetform.submit();
4454: }
4455: }
4456:
4457: function makenewpage(targetform,folderseq) {
4458: var pagename=prompt('$lt{"p_mnp"}','$lt{"t_mnp"}');
4459: if (pagename) {
4460: targetform.importdetail.value=escape(pagename)+"="+folderseq;
4461: targetform.submit();
4462: }
4463: }
4464:
4465: function makeexamupload() {
4466: var title=prompt('$lt{"p_mxu"}');
1.344 bisitz 4467: if (title) {
1.329 droeschl 4468: this.document.forms.newexamupload.importdetail.value=
4469: escape(title)+'=/res/lib/templates/examupload.problem';
4470: this.document.forms.newexamupload.submit();
4471: }
4472: }
4473:
4474: function makesmppage() {
4475: var title=prompt('$lt{"p_msp"}');
1.344 bisitz 4476: if (title) {
1.329 droeschl 4477: this.document.forms.newsmppg.importdetail.value=
4478: escape(title)+'=/adm/$udom/$uname/$now/smppg';
4479: this.document.forms.newsmppg.submit();
4480: }
4481: }
4482:
4483: function makesmpproblem() {
4484: var title=prompt('$lt{"p_msb"}');
1.344 bisitz 4485: if (title) {
1.329 droeschl 4486: this.document.forms.newsmpproblem.importdetail.value=
4487: escape(title)+'=/res/lib/templates/simpleproblem.problem';
4488: this.document.forms.newsmpproblem.submit();
4489: }
4490: }
4491:
4492: function makedropbox() {
4493: var title=prompt('$lt{"p_mdb"}');
1.344 bisitz 4494: if (title) {
1.329 droeschl 4495: this.document.forms.newdropbox.importdetail.value=
4496: escape(title)+'=/res/lib/templates/DropBox.problem';
4497: this.document.forms.newdropbox.submit();
4498: }
4499: }
4500:
4501: function makebulboard() {
4502: var title=prompt('$lt{"p_mbb"}');
4503: if (title) {
4504: this.document.forms.newbul.importdetail.value=
4505: escape(title)+'=/adm/$udom/$uname/$now/bulletinboard';
4506: this.document.forms.newbul.submit();
4507: }
4508: }
4509:
4510: function makeabout() {
4511: var user=prompt("$lt{'p_mab'}");
4512: if (user) {
4513: var comp=new Array();
4514: comp=user.split(':');
4515: if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
4516: if ((comp[0]) && (comp[1])) {
4517: this.document.forms.newaboutsomeone.importdetail.value=
4518: '$lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
1.335 ehlerst 4519: this.document.forms.newaboutsomeone.submit();
4520: } else {
4521: alert("$lt{'p_mab_alrt1'}");
1.329 droeschl 4522: }
1.335 ehlerst 4523: } else {
4524: alert("$lt{'p_mab_alrt2'}");
4525: }
4526: }
1.329 droeschl 4527: }
4528:
1.501 raeburn 4529: function toggleUpload(caller) {
4530: var blocks = Array($fieldsets);
4531: for (var i=0; i<blocks.length; i++) {
4532: var disp = 'none';
4533: if (caller == blocks[i]) {
4534: var curr = document.getElementById('upload'+caller+'form').style.display;
4535: if (curr == 'none') {
4536: disp='block';
4537: }
4538: }
4539: document.getElementById('upload'+blocks[i]+'form').style.display=disp;
4540: }
1.502 raeburn 4541: resize_scrollbox('contentscroll','1','1');
4542: return;
4543: }
4544:
1.514 raeburn 4545: function toggleMap(caller) {
1.502 raeburn 4546: var disp = 'none';
1.510 raeburn 4547: if (document.getElementById('importmapform')) {
1.514 raeburn 4548: if (caller == 'map') {
4549: var curr = document.getElementById('importmapform').style.display;
4550: if (curr == 'none') {
4551: disp='block';
4552: }
1.510 raeburn 4553: }
4554: document.getElementById('importmapform').style.display=disp;
4555: resize_scrollbox('contentscroll','1','1');
1.502 raeburn 4556: }
1.501 raeburn 4557: return;
1.329 droeschl 4558: }
4559:
1.501 raeburn 4560: function makeims(imsform) {
4561: if ((imsform.uploaddoc.value == '') || (!imsform.uploaddoc.value)) {
4562: alert("$lt{'imsfile'}");
4563: return;
4564: }
4565: if (imsform.source.selectedIndex == 0) {
4566: alert("$lt{'imscms'}");
4567: return;
4568: }
4569: newWindow = window.open('', 'IMSimport',"HEIGHT=700,WIDTH=750,scrollbars=yes");
4570: imsform.submit();
4571: }
4572:
1.519 raeburn 4573: function changename(folderpath,index,oldtitle) {
1.335 ehlerst 4574: var title=prompt('$lt{"p_chn"}',oldtitle);
4575: if (title) {
4576: this.document.forms.renameform.markcopy.value=-1;
4577: this.document.forms.renameform.title.value=title;
4578: this.document.forms.renameform.cmd.value='rename_'+index;
1.519 raeburn 4579: this.document.forms.renameform.folderpath.value=folderpath;
1.335 ehlerst 4580: this.document.forms.renameform.submit();
4581: }
1.329 droeschl 4582: }
4583:
1.519 raeburn 4584: function removeres(folderpath,index,oldtitle,skip_confirm) {
1.335 ehlerst 4585: if (skip_confirm || confirm('$lt{"p_rmr1"}\\n\\n$lt{"p_rmr2a"} "'+oldtitle+'" $lt{"p_rmr2b"}')) {
4586: this.document.forms.renameform.markcopy.value=-1;
4587: this.document.forms.renameform.cmd.value='del_'+index;
1.519 raeburn 4588: this.document.forms.renameform.folderpath.value=folderpath;
1.335 ehlerst 4589: this.document.forms.renameform.submit();
4590: }
1.329 droeschl 4591: }
4592:
1.519 raeburn 4593: function cutres(folderpath,index,oldtitle,container,folder,skip_confirm) {
1.335 ehlerst 4594: if (skip_confirm || confirm('$lt{"p_ctr1a"}\\n$lt{"p_ctr1b"}\\n\\n$lt{"p_ctr2a"} "'+oldtitle+'" $lt{"p_ctr2b"}')) {
4595: this.document.forms.renameform.cmd.value='cut_'+index;
4596: this.document.forms.renameform.markcopy.value=index;
4597: this.document.forms.renameform.copyfolder.value=folder+'.'+container;
1.519 raeburn 4598: this.document.forms.renameform.folderpath.value=folderpath;
1.335 ehlerst 4599: this.document.forms.renameform.submit();
4600: }
1.329 droeschl 4601: }
4602:
1.519 raeburn 4603: function markcopy(folderpath,index,oldtitle,container,folder) {
1.335 ehlerst 4604: this.document.forms.renameform.markcopy.value=index;
4605: this.document.forms.renameform.copyfolder.value=folder+'.'+container;
4606: this.document.forms.renameform.folderpath.value=folderpath;
4607: this.document.forms.renameform.submit();
1.329 droeschl 4608: }
4609:
1.478 raeburn 4610: function updatePick(targetform,index,caller) {
4611: var pickitem = document.getElementById('rpick_'+index);
4612: var picknumitem = document.getElementById('rpicknum_'+index);
4613: if (pickitem.checked) {
4614: var picknum=prompt('$lt{"rpck"}',picknumitem.value);
4615: if (picknum == '' || picknum == null) {
4616: if (caller == 'check') {
4617: pickitem.checked=false;
4618: return;
4619: }
4620: } else {
4621: picknum.toString();
4622: var regexdigit=/^\\d+\$/;
4623: if (regexdigit.test(picknum)) {
4624: picknumitem.value = picknum;
4625: targetform.changeparms.value='randompick';
4626: targetform.submit();
4627: } else {
4628: if (caller == 'check') {
4629: pickitem.checked=false;
4630: }
4631: return;
4632: }
4633: }
4634: } else {
4635: picknumitem.value = 0;
4636: targetform.changeparms.value='randompick';
4637: targetform.submit();
4638: }
4639: }
4640:
1.334 muellerd 4641: function unselectInactive(nav) {
1.335 ehlerst 4642: currentNav = document.getElementById(nav);
4643: currentLis = currentNav.getElementsByTagName('LI');
4644: for (i = 0; i < currentLis.length; i++) {
1.472 raeburn 4645: if (currentLis[i].className == 'goback') {
4646: currentLis[i].className = 'goback';
4647: } else {
4648: if (currentLis[i].className == 'right active' || currentLis[i].className == 'right') {
1.374 tempelho 4649: currentLis[i].className = 'right';
1.472 raeburn 4650: } else {
1.374 tempelho 4651: currentLis[i].className = 'i';
1.472 raeburn 4652: }
4653: }
1.335 ehlerst 4654: }
1.332 tempelho 4655: }
4656:
1.334 muellerd 4657: function hideAll(current, nav, data) {
1.335 ehlerst 4658: unselectInactive(nav);
1.374 tempelho 4659: if(current.className == 'right'){
4660: current.className = 'right active'
4661: }else{
4662: current.className = 'active';
4663: }
1.335 ehlerst 4664: currentData = document.getElementById(data);
4665: currentDivs = currentData.getElementsByTagName('DIV');
4666: for (i = 0; i < currentDivs.length; i++) {
4667: if(currentDivs[i].className == 'LC_ContentBox'){
1.333 muellerd 4668: currentDivs[i].style.display = 'none';
1.330 tempelho 4669: }
4670: }
1.335 ehlerst 4671: }
1.330 tempelho 4672:
1.374 tempelho 4673: function openTabs(pageId) {
4674: tabnav = document.getElementById(pageId).getElementsByTagName('UL');
1.383 tempelho 4675: if(tabnav.length > 2 ){
1.389 tempelho 4676: currentNav = document.getElementById(tabnav[1].id);
1.374 tempelho 4677: currentLis = currentNav.getElementsByTagName('LI');
4678: for(i = 0; i< currentLis.length; i++){
4679: if(currentLis[i].className == 'active') {
1.375 tempelho 4680: funcString = currentLis[i].onclick.toString();
4681: tab = funcString.split('"');
1.420 onken 4682: if(tab.length < 2) {
4683: tab = funcString.split("'");
4684: }
1.375 tempelho 4685: currentData = document.getElementById(tab[1]);
4686: currentData.style.display = 'block';
1.374 tempelho 4687: }
4688: }
4689: }
4690: }
4691:
1.334 muellerd 4692: function showPage(current, pageId, nav, data) {
4693: hideAll(current, nav, data);
1.375 tempelho 4694: openTabs(pageId);
1.334 muellerd 4695: unselectInactive(nav);
1.330 tempelho 4696: current.className = 'active';
4697: currentData = document.getElementById(pageId);
4698: currentData.style.display = 'block';
1.458 raeburn 4699: activeTab = pageId;
1.501 raeburn 4700: toggleUpload();
1.503 raeburn 4701: toggleMap();
1.433 raeburn 4702: if (nav == 'mainnav') {
4703: var storedpath = "$docs_folderpath";
1.434 raeburn 4704: var storedpage = "$main_container_page";
1.433 raeburn 4705: var reg = new RegExp("^supplemental");
4706: if (pageId == 'mainCourseDocuments') {
1.434 raeburn 4707: if (storedpage == 1) {
4708: document.simpleedit.folderpath.value = '';
4709: document.uploaddocument.folderpath.value = '';
4710: } else {
4711: if (reg.test(storedpath)) {
4712: document.simpleedit.folderpath.value = '$toplevelmain';
4713: document.uploaddocument.folderpath.value = '$toplevelmain';
4714: document.newext.folderpath.value = '$toplevelmain';
4715: } else {
4716: document.simpleedit.folderpath.value = storedpath;
4717: document.uploaddocument.folderpath.value = storedpath;
4718: document.newext.folderpath.value = storedpath;
4719: }
1.433 raeburn 4720: }
4721: } else {
1.434 raeburn 4722: if (reg.test(storedpath)) {
4723: document.simpleedit.folderpath.value = storedpath;
4724: document.supuploaddocument.folderpath.value = storedpath;
4725: document.supnewext.folderpath.value = storedpath;
4726: } else {
1.433 raeburn 4727: document.simpleedit.folderpath.value = '$toplevelsupp';
4728: document.supuploaddocument.folderpath.value = '$toplevelsupp';
4729: document.supnewext.folderpath.value = '$toplevelsupp';
4730: }
4731: }
4732: }
1.485 raeburn 4733: resize_scrollbox('contentscroll','1','0');
1.330 tempelho 4734: return false;
4735: }
1.329 droeschl 4736:
1.472 raeburn 4737: function toContents(jumpto) {
4738: var newurl = '$backtourl';
1.525 raeburn 4739: if ((newurl == '/adm/navmaps') && (jumpto != '')) {
1.472 raeburn 4740: newurl = newurl+'?postdata='+jumpto;
4741: }
4742: location.href=newurl;
4743: }
4744:
1.329 droeschl 4745: ENDNEWSCRIPT
4746: }
1.457 raeburn 4747:
1.483 raeburn 4748: sub history_tab_js {
4749: return <<"ENDHIST";
4750: function toggleHistoryDisp(choice) {
4751: document.docslogform.docslog.value = choice;
4752: document.docslogform.submit();
4753: return;
4754: }
4755:
4756: ENDHIST
4757: }
4758:
1.484 raeburn 4759: sub inject_data_js {
4760: return <<ENDINJECT;
4761:
4762: function injectData(current, hiddenField, name, value) {
4763: currentElement = document.getElementById(hiddenField);
4764: currentElement.name = name;
4765: currentElement.value = value;
4766: current.submit();
4767: }
4768:
4769: ENDINJECT
4770: }
4771:
4772: sub dump_switchserver_js {
4773: my @hosts = @_;
4774: my %lt = &Apache::lonlocal::texthash(
4775: dump => 'Dumping to Authoring Space requires switching server.',
4776: swit => 'Switch server?',
4777: duco => 'Dump content to Authoring Space',
4778: yone => 'You need to switch to a server housing an Authoring Space for which you are author or co-author.',
4779: chos => 'Choose server',
4780: );
4781: my $role = $env{'request.role'};
4782: my $js = <<"ENDSWJS";
4783: <script type="text/javascript">
4784: function write_switchserver() {
4785: var server;
4786: if (document.setserver.posshosts.length > 0) {
4787: for (var i=0; i<document.setserver.posshosts.length; i++) {
4788: if (document.setserver.posshosts[i].checked) {
4789: server = document.setserver.posshosts[i].value;
4790: }
4791: }
4792: opener.document.location.href="/adm/switchserver?otherserver="+server+"&role=$role&origurl=/adm/coursedocs";
4793: }
4794: window.close();
4795: }
4796: </script>
4797:
4798: ENDSWJS
4799:
4800: my $startpage = &Apache::loncommon::start_page('Choose server',$js,
4801: {'only_body' => 1,
4802: 'js_ready' => 1,});
4803: my $endpage = &Apache::loncommon::end_page({'js_ready' => 1});
4804:
4805: my $hostpicker;
4806: my $count = 0;
4807: foreach my $host (sort(@hosts)) {
4808: my $checked;
4809: if ($count == 0) {
4810: $checked = ' checked="checked"';
4811: }
4812: $hostpicker .= '<label><input type="radio" name="posshosts" value="'.
4813: $host.'"'.$checked.' />'.$host.'</label> ';
4814: $count++;
4815: }
4816:
4817: return <<"ENDSWITCHJS";
4818:
4819: function dump_needs_switchserver(url) {
4820: if (url!='' && url!= null) {
4821: if (confirm("$lt{'dump'}\\n$lt{'swit'}")) {
4822: go(url);
4823: }
4824: }
4825: return;
4826: }
4827:
4828: function choose_switchserver_window() {
4829: newWindow = window.open('','ChooseServer','height=400,width=500,scrollbars=yes')
4830: newWindow.document.open();
4831: newWindow.document.writeln('$startpage');
4832: newWindow.document.write('<h3>$lt{'duco'}<\\/h3>\\n'+
4833: '<p>$lt{'yone'}<\\/p>\\n'+
4834: '<div class="LC_left_float"><fieldset><legend>$lt{'chos'}<\\/legend>\\n'+
4835: '<form name="setserver" method="post" action="" \\/>\\n'+
4836: '$hostpicker\\n'+
4837: '<br \\/><br \\/>\\n'+
4838: '<input type="button" name="makeswitch" value="$lt{'swit'}" '+
4839: 'onclick="write_switchserver();" \\/>\\n'+
4840: '<\\/form><\\/fieldset><\\/div><br clear="all" \\/>\\n');
4841: newWindow.document.writeln('$endpage');
4842: newWindow.document.close();
4843: newWindow.focus();
4844: }
4845:
4846: ENDSWITCHJS
4847: }
4848:
4849: sub makedocslogform {
4850: my ($formelems,$docslog) = @_;
4851: return <<"LOGSFORM";
4852: <form action="/adm/coursedocs" method="post" name="docslogform">
4853: <input type="hidden" name="docslog" value="$docslog" />
4854: $formelems
4855: </form>
4856: LOGSFORM
4857: }
4858:
4859: sub makesimpleeditform {
4860: my ($formelems) = @_;
4861: return <<"SIMPFORM";
4862: <form name="simpleedit" method="post" action="/adm/coursedocs">
4863: <input type="hidden" name="importdetail" value="" />
4864: $formelems
4865: </form>
4866: SIMPFORM
4867: }
4868:
1.329 droeschl 4869: 1;
4870: __END__
4871:
4872:
4873: =head1 NAME
4874:
4875: Apache::londocs.pm
4876:
4877: =head1 SYNOPSIS
4878:
4879: This is part of the LearningOnline Network with CAPA project
4880: described at http://www.lon-capa.org.
4881:
4882: =head1 SUBROUTINES
4883:
4884: =over
4885:
4886: =item %help=()
4887:
4888: Available help topics
4889:
4890: =item mapread()
4891:
1.344 bisitz 4892: Mapread read maps into LONCAPA::map:: global arrays
1.329 droeschl 4893: @order and @resources, determines status
4894: sets @order - pointer to resources in right order
4895: sets @resources - array with the resources with correct idx
4896:
4897: =item authorhosts()
4898:
4899: Return hash with valid author names
4900:
4901: =item clean()
4902:
4903: =item dumpcourse()
4904:
4905: Actually dump course
4906:
4907: =item group_import()
4908:
4909: Imports the given (name, url) resources into the course
4910: coursenum, coursedom, and folder must precede the list
4911:
4912: =item breadcrumbs()
4913:
4914: =item log_docs()
4915:
4916: =item docs_change_log()
4917:
4918: =item update_paste_buffer()
4919:
4920: =item print_paste_buffer()
4921:
4922: =item do_paste_from_buffer()
4923:
1.492 raeburn 4924: =item get_newmap_url()
4925:
4926: =item dbcopy()
4927:
4928: =item uniqueness_check()
4929:
4930: =item contained_map_check()
4931:
4932: =item url_paste_fixups()
4933:
4934: =item apply_fixups()
4935:
4936: =item copy_dependencies()
4937:
1.329 droeschl 4938: =item update_parameter()
4939:
4940: =item handle_edit_cmd()
4941:
4942: =item editor()
4943:
4944: =item process_file_upload()
4945:
4946: =item process_secondary_uploads()
4947:
4948: =item is_supplemental_title()
4949:
4950: =item entryline()
4951:
4952: =item tiehash()
4953:
4954: =item untiehash()
4955:
4956: =item checkonthis()
4957:
4958: check on this
4959:
4960: =item verifycontent()
4961:
4962: Verify Content
4963:
4964: =item devalidateversioncache() & checkversions()
4965:
4966: Check Versions
4967:
4968: =item mark_hash_old()
4969:
4970: =item is_hash_old()
4971:
4972: =item changewarning()
4973:
4974: =item init_breadcrumbs()
4975:
4976: Breadcrumbs for special functions
4977:
1.484 raeburn 4978: =item create_list_elements()
4979:
4980: =item create_form_ul()
4981:
4982: =item startContentScreen()
4983:
4984: =item endContentScreen()
4985:
4986: =item supplemental_base()
4987:
4988: =item embedded_form_elems()
4989:
4990: =item embedded_destination()
4991:
4992: =item return_to_editor()
4993:
4994: =item decompression_info()
4995:
4996: =item decompression_phase_one()
4997:
4998: =item decompression_phase_two()
4999:
5000: =item remove_archive()
5001:
5002: =item generate_admin_menu()
5003:
5004: =item generate_edit_table()
5005:
5006: =item editing_js()
5007:
5008: =item history_tab_js()
5009:
5010: =item inject_data_js()
5011:
5012: =item dump_switchserver_js()
5013:
1.485 raeburn 5014: =item resize_scrollbox_js()
1.484 raeburn 5015:
5016: =item makedocslogform()
5017:
1.485 raeburn 5018: =item makesimpleeditform()
5019:
1.329 droeschl 5020: =back
5021:
5022: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>