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