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