Annotation of loncom/interface/londocs.pm, revision 1.484.2.16
1.329 droeschl 1: # The LearningOnline Network
2: # Documents
3: #
1.484.2.16! raeburn 4: # $Id: londocs.pm,v 1.484.2.15 2012/12/13 02:45:27 raeburn Exp $
1.329 droeschl 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28:
29: package Apache::londocs;
30:
31: use strict;
32: use Apache::Constants qw(:common :http);
33: use Apache::imsexport;
34: use Apache::lonnet;
35: use Apache::loncommon;
1.383 tempelho 36: use Apache::lonhtmlcommon;
1.329 droeschl 37: use LONCAPA::map();
38: use Apache::lonratedt();
39: use Apache::lonxml;
40: use Apache::lonclonecourse;
41: use Apache::lonnavmaps;
1.472 raeburn 42: use Apache::lonnavdisplay();
1.484.2.7 raeburn 43: use Apache::lonuserstate();
1.329 droeschl 44: use HTML::Entities;
1.484.2.7 raeburn 45: use HTML::TokeParser;
1.329 droeschl 46: use GDBM_File;
47: use Apache::lonlocal;
48: use Cwd;
49: use LONCAPA qw(:DEFAULT :match);
50:
51: my $iconpath;
52:
53: my %hash;
54:
55: my $hashtied;
56: my %alreadyseen=();
57:
58: my $hadchanges;
59:
60:
61: my %help=();
62:
63:
64: sub mapread {
65: my ($coursenum,$coursedom,$map)=@_;
66: return
67: &LONCAPA::map::mapread('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
68: $map);
69: }
70:
71: sub storemap {
1.484.2.7 raeburn 72: my ($coursenum,$coursedom,$map,$contentchg)=@_;
73: my $report;
74: if (($contentchg) && ($map =~ /^default/)) {
75: $report = 1;
76: }
1.329 droeschl 77: my ($outtext,$errtext)=
78: &LONCAPA::map::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
1.484.2.7 raeburn 79: $map,1,$report);
1.329 droeschl 80: if ($errtext) { return ($errtext,2); }
1.364 bisitz 81:
1.329 droeschl 82: $hadchanges=1;
83: return ($errtext,0);
84: }
85:
86:
87:
88: sub authorhosts {
89: my %outhash=();
90: my $home=0;
91: my $other=0;
92: foreach my $key (keys(%env)) {
93: if ($key=~/^user\.role\.(au|ca)\.(.+)$/) {
94: my $role=$1;
95: my $realm=$2;
96: my ($start,$end)=split(/\./,$env{$key});
97: if (($start) && ($start>time)) { next; }
98: if (($end) && (time>$end)) { next; }
99: my ($ca,$cd);
100: if ($1 eq 'au') {
101: $ca=$env{'user.name'};
102: $cd=$env{'user.domain'};
103: } else {
104: ($cd,$ca)=($realm=~/^\/($match_domain)\/($match_username)$/);
105: }
106: my $allowed=0;
107: my $myhome=&Apache::lonnet::homeserver($ca,$cd);
108: my @ids=&Apache::lonnet::current_machine_ids();
1.484 raeburn 109: foreach my $id (@ids) {
110: if ($id eq $myhome) {
111: $allowed=1;
112: last;
113: }
114: }
1.329 droeschl 115: if ($allowed) {
116: $home++;
1.484 raeburn 117: $outhash{'home_'.$ca.':'.$cd}=1;
1.329 droeschl 118: } else {
1.484 raeburn 119: $outhash{'otherhome_'.$ca.':'.$cd}=$myhome;
1.329 droeschl 120: $other++;
121: }
122: }
123: }
124: return ($home,$other,%outhash);
125: }
126:
127:
128: sub clean {
129: my ($title)=@_;
130: $title=~s/[^\w\/\!\$\%\^\*\-\_\=\+\;\:\,\\\|\`\~]+/\_/gs;
1.344 bisitz 131: return $title;
1.329 droeschl 132: }
133:
134:
135:
136: sub dumpcourse {
137: my ($r) = @_;
1.408 raeburn 138: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 139: $r->print(&Apache::loncommon::start_page('Dump '.$crstype.' Content to Authoring Space')."\n".
140: &Apache::lonhtmlcommon::breadcrumbs('Dump '.$crstype.' Content to Authoring Space')."\n");
141: $r->print(&startContentScreen('tools'));
1.329 droeschl 142: my ($home,$other,%outhash)=&authorhosts();
1.484 raeburn 143: unless ($home) {
144: $r->print(&endContentScreen());
145: return '';
146: }
1.329 droeschl 147: my $origcrsid=$env{'request.course.id'};
148: my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
149: if (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
150: # Do the dumping
1.484 raeburn 151: unless ($outhash{'home_'.$env{'form.authorspace'}}) {
152: $r->print(&endContentScreen());
153: return '';
154: }
1.329 droeschl 155: my ($ca,$cd)=split(/\@/,$env{'form.authorspace'});
156: $r->print('<h3>'.&mt('Copying Files').'</h3>');
157: my $title=$env{'form.authorfolder'};
158: $title=&clean($title);
159: my %replacehash=();
160: foreach my $key (keys(%env)) {
161: if ($key=~/^form\.namefor\_(.+)/) {
162: $replacehash{$1}=$env{$key};
163: }
164: }
165: my $crs='/uploaded/'.$env{'request.course.id'}.'/';
166: $crs=~s/\_/\//g;
167: foreach my $item (keys(%replacehash)) {
168: my $newfilename=$title.'/'.$replacehash{$item};
169: $newfilename=~s/\.(\w+)$//;
170: my $ext=$1;
171: $newfilename=&clean($newfilename);
172: $newfilename.='.'.$ext;
173: my @dirs=split(/\//,$newfilename);
1.462 raeburn 174: my $path=$r->dir_config('lonDocRoot')."/priv/$cd/$ca";
1.329 droeschl 175: my $makepath=$path;
176: my $fail=0;
177: for (my $i=0;$i<$#dirs;$i++) {
178: $makepath.='/'.$dirs[$i];
1.344 bisitz 179: unless (-e $makepath) {
180: unless(mkdir($makepath,0777)) { $fail=1; }
1.329 droeschl 181: }
182: }
183: $r->print('<br /><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt>: ');
184: if (my $fh=Apache::File->new('>'.$path.'/'.$newfilename)) {
185: if ($item=~/\.(sequence|page|html|htm|xml|xhtml)$/) {
186: print $fh &Apache::lonclonecourse::rewritefile(
187: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
188: (%replacehash,$crs => '')
189: );
190: } else {
191: print $fh
192: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item);
193: }
194: $fh->close();
195: } else {
196: $fail=1;
197: }
198: if ($fail) {
199: $r->print('<span class="LC_error">'.&mt('fail').'</span>');
200: } else {
201: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
202: }
203: }
204: } else {
1.484 raeburn 205: $r->print(&mt('Searching ...').'<br />');
206: $r->rflush();
1.329 droeschl 207: # Input form
1.484 raeburn 208: $r->print('<form name="dumpdoc" action="" method="post">'."\n");
1.329 droeschl 209: unless ($home==1) {
1.484 raeburn 210: $r->print('<div class="LC_left_float">'.
211: '<fieldset><legend>'.
212: &mt('Select the Authoring Space').
213: '</legend><select name="authorspace">');
1.329 droeschl 214: }
215: foreach my $key (sort(keys(%outhash))) {
216: if ($key=~/^home_(.+)$/) {
217: if ($home==1) {
218: $r->print(
219: '<input type="hidden" name="authorspace" value="'.$1.'" />');
220: } else {
221: $r->print('<option value="'.$1.'">'.$1.' - '.
1.484 raeburn 222: &Apache::loncommon::plainname(split(/\:/,$1)).'</option>');
1.329 droeschl 223: }
224: }
225: }
226: unless ($home==1) {
1.484 raeburn 227: $r->print('</select></fieldset></div>'."\n");
1.329 droeschl 228: }
229: my $title=$origcrsdata{'description'};
230: $title=~s/[\/\s]+/\_/gs;
231: $title=&clean($title);
1.484 raeburn 232: $r->print('<div class="LC_left_float">'.
233: '<fieldset><legend>'.&mt('Folder in Authoring Space').'</legend>'.
234: '<input type="text" size="50" name="authorfolder" value="'.
235: $title.'" />'.
236: '</fieldset></div><br clear="all" />'."\n");
1.329 droeschl 237: &tiehash();
1.484 raeburn 238: $r->print('<h4>'.&mt('Filenames in Authoring Space').'</h4>'
1.329 droeschl 239: .&Apache::loncommon::start_data_table()
240: .&Apache::loncommon::start_data_table_header_row()
241: .'<th>'.&mt('Internal Filename').'</th>'
242: .'<th>'.&mt('Title').'</th>'
243: .'<th>'.&mt('Save as ...').'</th>'
244: .&Apache::loncommon::end_data_table_header_row());
245: foreach my $file (&Apache::lonclonecourse::crsdirlist($origcrsid,'userfiles')) {
246: $r->print(&Apache::loncommon::start_data_table_row()
247: .'<td>'.$file.'</td>');
248: my ($ext)=($file=~/\.(\w+)$/);
249: my $title=$hash{'title_'.$hash{
250: 'ids_/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'.$file}};
251: $r->print('<td>'.($title?$title:' ').'</td>');
252: if (!$title) {
253: $title=$file;
254: } else {
255: $title=~s|/|_|g;
256: }
257: $title=~s/\.(\w+)$//;
258: $title=&clean($title);
259: $title.='.'.$ext;
260: $r->print("\n<td><input type='text' size='60' name='namefor_".$file."' value='".$title."' /></td>"
261: .&Apache::loncommon::end_data_table_row());
262: }
263: $r->print(&Apache::loncommon::end_data_table());
264: &untiehash();
265: $r->print(
1.484 raeburn 266: '<p><input type="submit" name="dumpcourse" value="'.&mt("Dump $crstype Content").'" /></p></form>');
1.329 droeschl 267: }
1.484 raeburn 268: $r->print(&endContentScreen());
1.329 droeschl 269: }
270:
271: sub group_import {
272: my ($coursenum, $coursedom, $folder, $container, $caller, @files) = @_;
273:
274: while (@files) {
275: my ($name, $url, $residx) = @{ shift(@files) };
1.344 bisitz 276: if (($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$})
1.329 droeschl 277: && ($caller eq 'londocs')
278: && (!&Apache::lonnet::stat_file($url))) {
1.364 bisitz 279:
1.329 droeschl 280: my $errtext = '';
281: my $fatal = 0;
282: my $newmapstr = '<map>'."\n".
283: '<resource id="1" src="" type="start"></resource>'."\n".
284: '<link from="1" to="2" index="1"></link>'."\n".
285: '<resource id="2" src="" type="finish"></resource>'."\n".
286: '</map>';
287: $env{'form.output'}=$newmapstr;
288: my $result=&Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
289: 'output',$1.$2);
290: if ($result != m|^/uploaded/|) {
291: $errtext.='Map not saved: A network error occurred when trying to save the new map. ';
292: $fatal = 2;
293: }
294: if ($fatal) {
295: return ($errtext,$fatal);
296: }
297: }
298: if ($url) {
1.344 bisitz 299: if (!$residx
1.329 droeschl 300: || defined($LONCAPA::map::zombies[$residx])) {
301: $residx = &LONCAPA::map::getresidx($url,$residx);
302: push(@LONCAPA::map::order, $residx);
303: }
304: my $ext = 'false';
305: if ($url=~m{^http://} || $url=~m{^https://}) { $ext = 'true'; }
306: $url = &LONCAPA::map::qtunescape($url);
307: $name = &LONCAPA::map::qtunescape($name);
1.344 bisitz 308: $LONCAPA::map::resources[$residx] =
1.329 droeschl 309: join(':', ($name, $url, $ext, 'normal', 'res'));
310: }
311: }
1.484.2.7 raeburn 312: return &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
1.329 droeschl 313: }
314:
315: sub breadcrumbs {
1.408 raeburn 316: my ($allowed,$crstype)=@_;
1.329 droeschl 317: &Apache::lonhtmlcommon::clear_breadcrumbs();
318: my (@folders);
319: if ($env{'form.pagepath'}) {
320: @folders = split('&',$env{'form.pagepath'});
321: } else {
322: @folders=split('&',$env{'form.folderpath'});
323: }
324: my $folderpath;
325: my $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.484.2.10 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.484.2.8 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.484.2.6 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.484.2.6 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.484.2.7 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.484.2.7 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.484.2.7 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.484.2.7 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.484.2.7 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.484.2.7 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.484.2.7 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.484.2.7 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.484.2.7 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.484.2.7 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.484.2.7 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.484.2.7 raeburn 700: my ($r,$container,$folder,$coursedom,$coursenum) = @_;
1.329 droeschl 701: return if (!defined($env{'docs.markedcopy_url'}));
702:
1.484.2.7 raeburn 703: my ($is_external,$othercourse,$fromsupp,$is_uploaded_map,$parent);
704: my $extension = (split(/\./,$env{'docs.markedcopy_url'}))[-1];
1.329 droeschl 705: if ($env{'docs.markedcopy_url'} =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//} ) {
1.484.2.7 raeburn 706: $is_external = 1;
707: }
708:
709: my ($canpaste,$nopaste,$othercrs,$areachange,$is_uploaded_map);
710: if ($folder =~ /^supplemental/) {
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: }
715: } else {
716: $canpaste = 1;
717: }
718:
719: if ($canpaste) {
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: }
744: }
745:
746: $r->print('<fieldset>'
747: .'<legend>'.&mt('Clipboard').'</legend>');
748: my ($type,$buffer);
749: if ($is_external) {
1.329 droeschl 750: $type = &mt('External Resource');
1.484.2.7 raeburn 751: $buffer = $type.': '.
1.329 droeschl 752: &LONCAPA::map::qtescape($env{'docs.markedcopy_title'}).' ('.
1.484.2.7 raeburn 753: &LONCAPA::map::qtescape($env{'docs.markedcopy_url'}).')';
1.329 droeschl 754: } else {
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'));
1.380 bisitz 759: $icon .= '/navmap.folder.closed.gif';
1.329 droeschl 760: }
761: $icon = '<img src="'.$icon.'" alt="" class="LC_icon" />';
1.484.2.7 raeburn 762: $buffer = $icon.$type.': '. &Apache::loncommon::parse_supplemental_title(&LONCAPA::map::qtescape($env{'docs.markedcopy_title'}));
1.329 droeschl 763: }
1.484.2.7 raeburn 764: if ($canpaste) {
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);
816: if ($container eq 'page') {
817: $r->print('
1.329 droeschl 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'},'<>&"').'" />
820: ');
1.484.2.7 raeburn 821: } else {
822: $r->print('
1.329 droeschl 823: <input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />
824: ');
1.484.2.7 raeburn 825: }
826: $r->print('</form>');
827: } else {
828: $r->print(&mt('Paste buffer contains:').' '.$buffer.
829: '<br /><p class="LC_info">'.$nopaste.'</p>');
1.329 droeschl 830: }
1.484.2.7 raeburn 831: $r->print('</fieldset>');
1.329 droeschl 832: }
833:
1.484.2.7 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:
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;
854: }
855:
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.484.2.7 raeburn 883: my ($coursenum,$coursedom,$folder,$container,$errors) = @_;
1.329 droeschl 884:
1.484.2.7 raeburn 885: # Early out if paste buffer is empty
1.329 droeschl 886: if (!$env{'form.pastemarked'}) {
1.484.2.7 raeburn 887: return ();
888: }
889:
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: }
1.329 droeschl 896: }
897:
1.484.2.7 raeburn 898: # Prepare to paste resource at end of list
1.329 droeschl 899: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url'});
900: my $title=&LONCAPA::map::qtescape($env{'docs.markedcopy_title'});
1.484.2.7 raeburn 901:
902: my ($is_map,$srcdom,$srcnum,$prefixchg,%before,%after,%mapchanges,%tomove);
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;
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
912: if (($srcdom ne $coursedom) || ($srcnum ne $coursenum)) {
913: unless ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
914: return (&mt('Paste failed: Item is from a different course which you do not have rights to edit.'));
1.329 droeschl 915: }
916: }
1.484.2.7 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.
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:
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.329 droeschl 952: }
1.484.2.7 raeburn 953: }
954:
955: # Maps need to be copied first
956: my ($oldurl,%removefrommap,%removeparam,%addedmaps,%rewrites,%retitles,%copies,
957: %dbcopies,%zombies,%params,%docmoves,%mapmoves,%newsubdir,%newurls);
958: $oldurl = $url;
959: if ($is_map) {
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"});
1.329 droeschl 964: }
965: }
1.484.2.7 raeburn 966: # If pasting a map, check if map contains other maps
967: my (%allmaps,%hierarchy,%titles);
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.329 droeschl 974: }
975: }
1.484.2.7 raeburn 976: &contained_map_check($url,$folder,\%removefrommap,\%removeparam,
977: \%addedmaps,\%hierarchy,\%titles,\%allmaps);
978: if ($url=~ m{^/uploaded/}) {
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: }
994: }
995: }
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);
1009: }
1010: } elsif ($url=~m {^/res/}) {
1.329 droeschl 1011: # published maps can only exists once, so remove it from paste buffer when done
1.484.2.7 raeburn 1012: &Apache::lonnet::delenv('docs.markedcopy');
1013: # if pasting published map (main content are only) check map is not already in course
1014: if ($folder =~ /^default/) {
1015: if ($allmaps{$url}) {
1016: return (&mt('Paste failed: only one instance of a particular published sequence or page is allowed within each course.'));
1017: }
1018: }
1019: }
1.329 droeschl 1020: }
1021: if ($url=~ m{/smppg$}) {
1.484.2.7 raeburn 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;
1028: my $dbresult=&Apache::lonnet::put($db_name,\%contents,
1029: $coursedom,$coursenum);
1030: if ($dbresult eq 'ok') {
1031: $url =~ s{/(\d*)/smppg$ }{/$now/smppg}x;
1032: $title=&mt('Copy of').' '.$title;
1033: } else {
1034: return (&mt('Paste failed: An error occurred when copying the simple page.'));
1035: }
1036: }
1.329 droeschl 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.484.2.7 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:
1047: my $newidx;
1048: unless ($is_map) {
1.329 droeschl 1049: # Now insert the URL at the bottom
1.484.2.7 raeburn 1050: $newidx = &LONCAPA::map::getresidx($url);
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+)/(.+)$});
1055: my ($newloc,$newdocsdir) = ($folder =~ /^(default|supplemental)_?(\d*)/);
1056: my $newprefix = $newloc;
1057: if ($newloc eq 'default') {
1058: $newprefix = 'docs';
1059: }
1060: if ($newdocsdir eq '') {
1061: $newdocsdir = 'default';
1062: }
1063: if (($prefixchg) || ($srcdom ne $coursedom) || ($srcnum ne $coursenum)) {
1064: my $newpath = "$newprefix/$newdocsdir/$newidx/$rem";
1065: $url =
1066: &Apache::lonclonecourse::writefile($env{'request.course.id'},$newpath,
1067: &Apache::lonnet::getfile($oldurl));
1068: if ($url eq '/adm/notfound.html') {
1069: return (&mt('Paste failed: an error occurred saving the file.'));
1070: } else {
1071: my ($newsubpath) = ($newpath =~ m{^(.*/)[^/]*$});
1072: $newsubpath =~ s{/+$}{/};
1073: $docmoves{$oldurl} = $newsubpath;
1074: }
1075: }
1076: }
1077: }
1078: }
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);
1086: if ($result eq 'ok') {
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: }
1100: if ($env{'docs.markedcopy_supplemental'}) {
1101: if ($folder !~ /^supplemental/) {
1102: (undef,undef,$title) =
1103: &Apache::loncommon::parse_supplemental_title($env{'docs.markedcopy_supplemental'});
1104: }
1.329 droeschl 1105: } else {
1.484.2.7 raeburn 1106: if ($folder=~/^supplemental/) {
1107: $title=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
1108: $env{'user.domain'}.'___&&&___'.$title;
1109: }
1.329 droeschl 1110: }
1.484.2.7 raeburn 1111: $LONCAPA::map::resources[$newidx]= $title.':'.$url.':'.$ext.':normal:res';
1112: push(@LONCAPA::map::order, $newidx);
1113:
1114: # Store the result
1115: my ($errtext,$fatal) =
1116: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1117: if ($fatal) {
1118: $save_err = $errtext;
1.329 droeschl 1119: }
1120: }
1121:
1.484.2.7 raeburn 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: }
1186: }
1187: return ($newurl);
1188: }
1189:
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;
1.329 droeschl 1205: }
1206:
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.484.2.7 raeburn 1221: sub contained_map_check {
1222: my ($url,$folder,$removefrommap,$removeparam,$addedmaps,$hierarchy,$titles,
1223: $allmaps) = @_;
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)) {
1235: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1236: next;
1237: }
1238: }
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'};
1243: } else {
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: }
1251: }
1252: &contained_map_check($ressrc,$folder,$removefrommap,$removeparam,
1253: $addedmaps,$hierarchy,$titles,$allmaps);
1254: }
1255: } elsif ($token->[1] eq 'param') {
1256: if ($folder =~ /^supplemental/) {
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: }
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 {
1279: my ($oldurl,$folder,$prefixchg,$cdom,$cnum,$allmaps,$rewrites,$retitles,$copies,
1280: $dbcopies,$zombies,$params,$mapmoves,$mapchanges,$tomove,$newsubdir,$newurls) = @_;
1281: my $checktitle;
1282: if (($prefixchg) &&
1283: ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/supplemental})) {
1284: $checktitle = 1;
1285: }
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: }
1293: my $file = &Apache::lonnet::getfile($oldurl);
1294: return if ($file eq '-1');
1295: my $parser = HTML::TokeParser->new(\$file);
1296: $parser->attr_encoded(1);
1297: my $changed = 0;
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 '');
1303: my $id = $token->[2]->{'id'};
1304: my $title = $token->[2]->{'title'};
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: }
1310: next if ($token->[2]->{'type'} eq 'external');
1311: if ($token->[2]->{'type'} eq 'zombie') {
1312: next if ($skip);
1313: $zombies->{$oldurl}{$ressrc} = $id;
1314: $changed = 1;
1315: } elsif ($ressrc =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
1316: my $srcdom = $1;
1317: my $srcnum = $2;
1318: my $rem = $3;
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:
1345: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
1346: $rewrites->{$oldurl}{$ressrc} = $id;
1347: $mapchanges->{$ressrc} = 1;
1348: unless (&url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,$cnum,$allmaps,
1349: $rewrites,$retitles,$copies,$dbcopies,$zombies,
1350: $params,$mapmoves,$mapchanges,$tomove,$newsubdir,
1351: $newurls)) {
1352: $mapmoves->{$ressrc} = 1;
1353: }
1354: $changed = 1;
1355: } else {
1356: $rewrites->{$oldurl}{$ressrc} = $id;
1357: $copies->{$oldurl}{$ressrc} = $id;
1358: $changed = 1;
1359: }
1360: }
1361: } elsif ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/(.+)$}) {
1362: next if ($skip);
1363: my $srcdom = $1;
1364: my $srcnum = $2;
1365: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1366: $rewrites->{$oldurl}{$ressrc} = $id;
1367: $dbcopies->{$oldurl}{$ressrc} = $id;
1368: $changed = 1;
1369: }
1370: } elsif ($ressrc =~ m{^/public/($match_domain)/($match_courseid)/(.+)$}) {
1371: next if ($skip);
1372: my $srcdom = $1;
1373: my $srcnum = $2;
1374: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1375: $rewrites->{$oldurl}{$ressrc} = $id;
1376: $dbcopies->{$oldurl}{$ressrc} = $id;
1377: $changed = 1;
1378: }
1379: }
1380: } elsif ($token->[1] eq 'param') {
1381: next if ($skip);
1382: my $to = $token->[2]->{'to'};
1383: if ($to ne '') {
1384: if (ref($params->{$oldurl}{$to}) eq 'ARRAY') {
1385: push(@{$params->{$oldurl}{$to}},$token->[2]->{'name'});
1386: } else {
1387: @{$params->{$oldurl}{$to}} = ($token->[2]->{'name'});
1388: }
1389: }
1390: }
1391: }
1392: return $changed;
1393: }
1394:
1395: sub apply_fixups {
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) = @_;
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) {
1420: my ($relpath,$oldsubdir,$fname) =
1421: ($item =~ m{^(/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(default|\d+)/.*/)([^/]+)$});
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: }
1434: if ($newsubdir->{$key}) {
1435: $storefn =~ s#^(docs|supplemental)/\Q$oldsubdir\E/#$1/$newsubdir->{$key}#;
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;
1447: }
1448: }
1449: }
1450: }
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: }
1460: if ($newsubdir->{$key}) {
1461: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir->{$key}/;
1462: }
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;
1475: }
1476: }
1477: }
1478: }
1479: my %updates;
1480: if ($is_map) {
1481: foreach my $key (keys(%{$rewrites})) {
1482: $updates{$key} = 1;
1483: }
1484: foreach my $key (keys(%{$zombies})) {
1485: $updates{$key} = 1;
1486: }
1487: foreach my $key (keys(%{$removefrommap})) {
1488: $updates{$key} = 1;
1489: }
1490: foreach my $key (keys(%{$removeparam})) {
1491: $updates{$key} = 1;
1492: }
1493: foreach my $key (keys(%{$dbcopies})) {
1494: $updates{$key} = 1;
1495: }
1496: foreach my $key (keys(%{$retitles})) {
1497: $updates{$key} = 1;
1498: }
1499: foreach my $key (keys(%updates)) {
1500: my (%torewrite,%toretitle,%toremove,%remparam,%currparam,%zombie,%newdb);
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: }
1510: if (ref($removeparam->{$key}) eq 'HASH') {
1511: %remparam = %{$removeparam->{$key}};
1512: }
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: }
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;
1553: }
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'}#;
1563: }
1564: }
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}#;
1570: }
1571: }
1572: }
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);
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: }
1600: if ($newsubdir->{$key}) {
1601: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir->{$key}/;
1602: }
1603: }
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) {
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: }
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.484.2.12 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.484.2.7 raeburn 1793: my %paste_errors;
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.484.2.7 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.484.2.7 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);
1.484.2.15 raeburn 1831: if ($url=~ m{^\Q/uploaded/$coursedom/$coursenum/\E(default|supplemental)_new\.(sequence|page)$}) {
1832: my ($suffix,$errortxt,$locknotfreed) =
1833: &newmap_suffix($1,$2,$coursedom,$coursenum);
1834: if ($locknotfreed) {
1835: $r->print($locknotfreed);
1836: }
1837: if ($suffix) {
1838: $url =~ s/_new\./_$suffix./;
1839: } else {
1840: return $errortxt;
1841: }
1842: }
1.329 droeschl 1843: push(@imports, [$name, $url, $residx]);
1844: }
1845: }
1846: ($errtext,$fatal)=&group_import($coursenum, $coursedom, $folder,
1847: $container,'londocs',@imports);
1848: return $errtext if ($fatal);
1849: }
1850: # Loading a complete map
1851: if ($env{'form.loadmap'}) {
1852: if ($env{'form.importmap'}=~/\w/) {
1853: foreach my $res (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
1854: my ($title,$url,$ext,$type)=split(/\:/,$res);
1855: my $idx=&LONCAPA::map::getresidx($url);
1856: $LONCAPA::map::resources[$idx]=$res;
1857: $LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx;
1858: }
1859: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.484.2.7 raeburn 1860: $folder.'.'.$container,1);
1.329 droeschl 1861: return $errtext if ($fatal);
1862: } else {
1863: $r->print('<p><span class="LC_error">'.&mt('No map selected.').'</span></p>');
1.364 bisitz 1864:
1.329 droeschl 1865: }
1866: }
1867: &log_differences($plain);
1868: }
1869: # ---------------------------------------------------------------- End commands
1870: # ---------------------------------------------------------------- Print screen
1871: my $idx=0;
1872: my $shown=0;
1873: if (($ishidden) || ($isencrypted) || ($randompick>=0) || ($is_random_order)) {
1.381 bisitz 1874: $r->print('<div class="LC_Box">'.
1.432 raeburn 1875: '<ol class="LC_docs_parameters"><li class="LC_docs_parameters_title">'.&mt('Parameters:').'</li>'.
1876: ($randompick>=0?'<li>'.&mt('randomly pick [quant,_1,resource]',$randompick).'</li>':'').
1877: ($ishidden?'<li>'.&mt('contents hidden').'</li>':'').
1878: ($isencrypted?'<li>'.&mt('URLs hidden').'</li>':'').
1879: ($is_random_order?'<li>'.&mt('random order').'</li>':'').
1.431 raeburn 1880: '</ol>');
1.381 bisitz 1881: if ($randompick>=0) {
1882: $r->print('<p class="LC_warning">'
1883: .&mt('Caution: this folder is set to randomly pick a subset'
1884: .' of resources. Adding or removing resources from this'
1885: .' folder will change the set of resources that the'
1886: .' students see, resulting in spurious or missing credit'
1887: .' for completed problems, not limited to ones you'
1888: .' modify. Do not modify the contents of this folder if'
1889: .' it is in active student use.')
1890: .'</p>'
1891: );
1892: }
1893: if ($is_random_order) {
1894: $r->print('<p class="LC_warning">'
1895: .&mt('Caution: this folder is set to randomly order its'
1896: .' contents. Adding or removing resources from this folder'
1897: .' will change the order of resources shown.')
1898: .'</p>'
1899: );
1900: }
1901: $r->print('</div>');
1.364 bisitz 1902: }
1.381 bisitz 1903:
1.458 raeburn 1904: my ($to_show,$output);
1.424 onken 1905:
1906: &Apache::loncommon::start_data_table_count(); #setup a row counter
1.381 bisitz 1907: foreach my $res (@LONCAPA::map::order) {
1908: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
1909: $name=&LONCAPA::map::qtescape($name);
1910: $url=&LONCAPA::map::qtescape($url);
1911: unless ($name) { $name=(split(/\//,$url))[-1]; }
1912: unless ($name) { $idx++; next; }
1913: $output .= &entryline($idx,$name,$url,$folder,$allowed,$res,
1.484.2.12 raeburn 1914: $coursenum,$coursedom,$crstype,
1915: $uploadtag,$supplementalflag);
1.381 bisitz 1916: $idx++;
1917: $shown++;
1.329 droeschl 1918: }
1.424 onken 1919: &Apache::loncommon::end_data_table_count();
1920:
1.381 bisitz 1921: if ($shown) {
1.458 raeburn 1922: $to_show = &Apache::loncommon::start_scrollbox('900px','880px','400px','contentscroll')
1923: .&Apache::loncommon::start_data_table(undef,'contentlist');
1.393 raeburn 1924: if ($allowed) {
1.458 raeburn 1925: $to_show .= &Apache::loncommon::start_data_table_header_row()
1.393 raeburn 1926: .'<th colspan="2">'.&mt('Move').'</th>'
1927: .'<th>'.&mt('Actions').'</th>'
1.458 raeburn 1928: .'<th colspan="2">'.&mt('Document').'</th>';
1.393 raeburn 1929: if ($folder !~ /^supplemental/) {
1.458 raeburn 1930: $to_show .= '<th colspan="4">'.&mt('Settings').'</th>';
1.393 raeburn 1931: }
1.458 raeburn 1932: $to_show .= &Apache::loncommon::end_data_table_header_row();
1.393 raeburn 1933: }
1.458 raeburn 1934: $to_show .= $output.' '
1.393 raeburn 1935: .&Apache::loncommon::end_data_table()
1.458 raeburn 1936: .'<br style="line-height:2px;" />'
1937: .&Apache::loncommon::end_scrollbox();
1.393 raeburn 1938: } else {
1.458 raeburn 1939: $to_show .= &Apache::loncommon::start_scrollbox('400px','380px','200px','contentscroll')
1940: .'<div class="LC_info" id="contentlist">'
1.381 bisitz 1941: .&mt('Currently no documents.')
1.458 raeburn 1942: .'</div>'
1943: .&Apache::loncommon::end_scrollbox();
1944: }
1945: my $tid = 1;
1946: if ($supplementalflag) {
1947: $tid = 2;
1.329 droeschl 1948: }
1949: if ($allowed) {
1.484 raeburn 1950: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
1951: $r->print(&generate_edit_table($tid,$orderhash,$to_show,$iconpath,$jumpto,
1952: $readfile));
1.484.2.7 raeburn 1953: &print_paste_buffer($r,$container,$folder,$coursedom,$coursenum);
1.460 raeburn 1954: } else {
1.472 raeburn 1955: if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
1956: #Function Box for Supplemental Content for users with mdc priv.
1957: my $funcname = &mt('Folder Editor');
1958: $r->print(
1959: &Apache::loncommon::head_subbox(
1960: &Apache::lonhtmlcommon::start_funclist().
1961: &Apache::lonhtmlcommon::add_item_funclist(
1962: '<a href="/adm/coursedocs?command=direct&forcesupplement=1&'.
1963: 'supppath='.&HTML::Entities::encode($env{'form.folderpath'}).'">'.
1.484.2.16! raeburn 1964: '<img src="/res/adm/pages/docs-22x22.png" alt="'.$funcname.'" class="LC_icon" />'.
1.472 raeburn 1965: '<span class="LC_menubuttons_inline_text">'.$funcname.'</span></a>').
1966: &Apache::lonhtmlcommon::end_funclist()));
1967: }
1.460 raeburn 1968: $r->print($to_show);
1.329 droeschl 1969: }
1970: return;
1971: }
1972:
1973: sub process_file_upload {
1974: my ($upload_output,$coursenum,$coursedom,$allfiles,$codebase,$uploadcmd) = @_;
1975: # upload a file, if present
1.440 raeburn 1976: my ($parseaction,$showupload,$nextphase,$mimetype);
1977: if ($env{'form.parserflag'}) {
1.329 droeschl 1978: $parseaction = 'parse';
1979: }
1980: my $folder=$env{'form.folder'};
1981: if ($folder eq '') {
1982: $folder='default';
1983: }
1984: if ( ($folder=~/^$uploadcmd/) || ($uploadcmd eq 'default') ) {
1985: my $errtext='';
1986: my $fatal=0;
1987: my $container='sequence';
1988: if ($env{'form.pagepath'}) {
1989: $container='page';
1990: }
1991: ($errtext,$fatal)=
1992: &mapread($coursenum,$coursedom,$folder.'.'.$container);
1993: if ($#LONCAPA::map::order<1) {
1994: $LONCAPA::map::order[0]=1;
1995: $LONCAPA::map::resources[1]='';
1996: }
1997: if ($fatal) {
1.457 raeburn 1998: $$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 1999: return;
1.329 droeschl 2000: }
2001: my $destination = 'docs/';
2002: if ($folder =~ /^supplemental/) {
2003: $destination = 'supplemental/';
2004: }
2005: if (($folder eq 'default') || ($folder eq 'supplemental')) {
2006: $destination .= 'default/';
2007: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
2008: $destination .= $2.'/';
2009: }
1.440 raeburn 2010: # this is for a course, not a user, so set context to coursedoc.
1.329 droeschl 2011: my $newidx=&LONCAPA::map::getresidx();
2012: $destination .= $newidx;
1.439 raeburn 2013: my $url=&Apache::lonnet::userfileupload('uploaddoc','coursedoc',$destination,
1.329 droeschl 2014: $parseaction,$allfiles,
1.440 raeburn 2015: $codebase,undef,undef,undef,undef,
2016: undef,undef,\$mimetype);
2017: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E.*/([^/]+)$}) {
2018: my $stored = $1;
2019: $showupload = '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
2020: $stored.'</span>').'</p>';
2021: } else {
2022: my ($filename) = ($env{'form.uploaddoc.filename'} =~ m{([^/]+)$});
2023:
1.457 raeburn 2024: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.&mt('Unable to save file [_1].','<span class="LC_filename">'.$filename.'</span>').'</div>';
1.440 raeburn 2025: return;
2026: }
1.329 droeschl 2027: my $ext='false';
2028: if ($url=~m{^http://}) { $ext='true'; }
2029: $url = &LONCAPA::map::qtunescape($url);
2030: my $comment=$env{'form.comment'};
2031: $comment = &LONCAPA::map::qtunescape($comment);
2032: if ($folder=~/^supplemental/) {
2033: $comment=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
2034: $env{'user.domain'}.'___&&&___'.$comment;
2035: }
2036:
2037: $LONCAPA::map::resources[$newidx]=
2038: $comment.':'.$url.':'.$ext.':normal:res';
2039: $LONCAPA::map::order[$#LONCAPA::map::order+1]= $newidx;
2040: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.484.2.7 raeburn 2041: $folder.'.'.$container,1);
1.329 droeschl 2042: if ($fatal) {
1.457 raeburn 2043: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.$errtext.'</div>';
1.440 raeburn 2044: return;
1.329 droeschl 2045: } else {
1.440 raeburn 2046: if ($parseaction eq 'parse' && $mimetype eq 'text/html') {
2047: $$upload_output = $showupload;
1.384 raeburn 2048: my $total_embedded = scalar(keys(%{$allfiles}));
1.329 droeschl 2049: if ($total_embedded > 0) {
1.440 raeburn 2050: my $uploadphase = 'upload_embedded';
2051: my $primaryurl = &HTML::Entities::encode($url,'<>&"');
2052: my $state = &embedded_form_elems($uploadphase,$primaryurl,$newidx);
2053: my ($embedded,$num) =
2054: &Apache::loncommon::ask_for_embedded_content(
2055: '/adm/coursedocs',$state,$allfiles,$codebase,{'docs_url' => $url});
2056: if ($embedded) {
2057: if ($num) {
2058: $$upload_output .=
2059: '<p>'.&mt('This file contains embedded multimedia objects, which need to be uploaded.').'</p>'.$embedded;
2060: $nextphase = $uploadphase;
2061: } else {
2062: $$upload_output .= $embedded;
2063: }
2064: } else {
2065: $$upload_output .= &mt('Embedded item(s) already present, so no additional upload(s) required').'<br />';
2066: }
1.329 droeschl 2067: } else {
1.440 raeburn 2068: $$upload_output .= &mt('No embedded items identified').'<br />';
1.329 droeschl 2069: }
1.457 raeburn 2070: $$upload_output = '<div id="uploadfileresult">'.$$upload_output.'</div>';
1.476 raeburn 2071: } elsif (&Apache::loncommon::is_archive_file($mimetype)) {
2072: $nextphase = 'decompress_uploaded';
2073: my $position = scalar(@LONCAPA::map::order)-1;
2074: my $noextract = &return_to_editor();
2075: my $archiveurl = &HTML::Entities::encode($url,'<>&"');
2076: my %archiveitems = (
2077: folderpath => $env{'form.folderpath'},
2078: pagepath => $env{'form.pagepath'},
2079: cmd => $nextphase,
2080: newidx => $newidx,
2081: position => $position,
2082: phase => $nextphase,
1.477 raeburn 2083: comment => $comment,
1.480 raeburn 2084: );
2085: my ($destination,$dir_root) = &embedded_destination($coursenum,$coursedom);
2086: my @current = &get_dir_list($url,$coursenum,$coursedom,$newidx);
1.476 raeburn 2087: $$upload_output = $showupload.
2088: &Apache::loncommon::decompress_form($mimetype,
2089: $archiveurl,'/adm/coursedocs',$noextract,
1.480 raeburn 2090: \%archiveitems,\@current);
1.329 droeschl 2091: }
2092: }
2093: }
1.440 raeburn 2094: return $nextphase;
1.329 droeschl 2095: }
2096:
1.480 raeburn 2097: sub get_dir_list {
2098: my ($url,$coursenum,$coursedom,$newidx) = @_;
2099: my ($destination,$dir_root) = &embedded_destination();
2100: my ($dirlistref,$listerror) =
2101: &Apache::lonnet::dirlist("$dir_root/$destination/$newidx",$coursedom,$coursenum,1);
2102: my @dir_lines;
2103: my $dirptr=16384;
2104: if (ref($dirlistref) eq 'ARRAY') {
2105: foreach my $dir_line (sort
2106: {
2107: my ($afile)=split('&',$a,2);
2108: my ($bfile)=split('&',$b,2);
2109: return (lc($afile) cmp lc($bfile));
2110: } (@{$dirlistref})) {
2111: my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$dir_line,16);
2112: $filename =~ s/\s+$//;
2113: next if ($filename =~ /^\.\.?$/);
2114: my $isdir = 0;
2115: if ($dirptr&$testdir) {
2116: $isdir = 1;
2117: }
2118: push(@dir_lines, [$filename,$dom,$isdir,$size,$mtime,$obs]);
2119: }
2120: }
2121: return @dir_lines;
2122: }
2123:
1.329 droeschl 2124: sub is_supplemental_title {
2125: my ($title) = @_;
2126: return scalar($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/);
2127: }
2128:
2129: # --------------------------------------------------------------- An entry line
2130:
2131: sub entryline {
1.484.2.12 raeburn 2132: my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$coursedom,
2133: $crstype,$uploadtag,$supplementalflag)=@_;
1.329 droeschl 2134: my ($foldertitle,$pagetitle,$renametitle);
2135: if (&is_supplemental_title($title)) {
1.484.2.7 raeburn 2136: ($title,$foldertitle,$renametitle) = &Apache::loncommon::parse_supplemental_title($title);
1.329 droeschl 2137: $pagetitle = $foldertitle;
2138: } else {
2139: $title=&HTML::Entities::encode($title,'"<>&\'');
2140: $renametitle=$title;
2141: $foldertitle=$title;
2142: $pagetitle=$title;
2143: }
2144:
2145: my $orderidx=$LONCAPA::map::order[$index];
1.364 bisitz 2146:
1.329 droeschl 2147: $renametitle=~s/\\/\\\\/g;
2148: $renametitle=~s/\"\;/\\\"/g;
2149: $renametitle=~s/ /%20/g;
1.379 bisitz 2150: my $line=&Apache::loncommon::start_data_table_row();
1.478 raeburn 2151: my ($form_start,$form_end,$form_common);
1.329 droeschl 2152: # Edit commands
2153: my ($container, $type, $esc_path, $path, $symb);
2154: if ($env{'form.folderpath'}) {
2155: $type = 'folder';
2156: $container = 'sequence';
2157: $esc_path=&escape($env{'form.folderpath'});
2158: $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
2159: # $htmlfoldername=&HTML::Entities::encode($env{'form.foldername'},'<>&"');
2160: }
2161: if ($env{'form.pagepath'}) {
2162: $type = $container = 'page';
1.440 raeburn 2163: $esc_path=&escape($env{'form.pagepath'});
1.329 droeschl 2164: $path = &HTML::Entities::encode($env{'form.pagepath'},'<>&"');
2165: }
1.484.2.16! raeburn 2166: my $isexternal;
1.484.2.12 raeburn 2167: if (!$supplementalflag && $residx) {
2168: my $currurl = $url;
2169: $currurl =~ s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
1.484.2.16! raeburn 2170: if ($currurl =~ m{^/adm/wrapper/ext/}) {
! 2171: $isexternal = 1;
! 2172: }
1.484.2.12 raeburn 2173: my $path = 'uploaded/'.
2174: $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
2175: $env{'course.'.$env{'request.course.id'}.'.num'}.'/';
2176: $symb = &Apache::lonnet::encode_symb($path.$folder.".$container",
2177: $residx,
2178: &Apache::lonnet::declutter($currurl));
2179: }
2180: my %lt;
1.329 droeschl 2181: if ($allowed) {
2182: my $incindex=$index+1;
2183: my $selectbox='';
1.471 raeburn 2184: if (($#LONCAPA::map::order>0) &&
1.329 droeschl 2185: ((split(/\:/,
1.344 bisitz 2186: $LONCAPA::map::resources[$LONCAPA::map::order[0]]))[1]
2187: ne '') &&
1.329 droeschl 2188: ((split(/\:/,
1.344 bisitz 2189: $LONCAPA::map::resources[$LONCAPA::map::order[1]]))[1]
1.329 droeschl 2190: ne '')) {
2191: $selectbox=
2192: '<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
1.373 bisitz 2193: '<select name="newpos" onchange="this.form.submit()">';
1.329 droeschl 2194: for (my $i=1;$i<=$#LONCAPA::map::order+1;$i++) {
2195: if ($i==$incindex) {
1.358 bisitz 2196: $selectbox.='<option value="" selected="selected">('.$i.')</option>';
1.329 droeschl 2197: } else {
2198: $selectbox.='<option value="'.$i.'">'.$i.'</option>';
2199: }
2200: }
2201: $selectbox.='</select>';
2202: }
1.484.2.12 raeburn 2203: %lt=&Apache::lonlocal::texthash(
1.329 droeschl 2204: 'up' => 'Move Up',
2205: 'dw' => 'Move Down',
2206: 'rm' => 'Remove',
2207: 'ct' => 'Cut',
2208: 'rn' => 'Rename',
1.484.2.12 raeburn 2209: 'cp' => 'Copy',
2210: 'ex' => 'External Resource',
2211: 'ed' => 'Edit',
2212: 'pr' => 'Preview',
2213: 'sv' => 'Save',
2214: 'ul' => 'URL',
2215: 'ti' => 'Title',
2216: );
1.329 droeschl 2217: my $nocopy=0;
2218: my $nocut=0;
1.484.2.9 raeburn 2219: my $noremove=0;
1.484.2.7 raeburn 2220: if ($url=~ m{^/res/.+\.(page|sequence)$}) {
2221: # no copy for published maps
2222: $nocopy=1;
2223: }
1.344 bisitz 2224: if ($url=~/^\/res\/lib\/templates\//) {
2225: $nocopy=1;
1.329 droeschl 2226: $nocut=1;
2227: }
1.484.2.9 raeburn 2228: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2229: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2230: if ($url eq "/uploaded/$cdom/$cnum/group_allfolders.sequence") {
2231: if ($env{'form.folderpath'} =~ /^default&[^\&]+$/) {
2232: my %curr_groups = &Apache::longroup::coursegroups();
2233: if (keys(%curr_groups) > 0) {
2234: $noremove=1;
2235: }
2236: $nocut=1;
2237: $nocopy=1;
2238: }
2239: } elsif ($url =~ m{^\Q/uploaded/$cdom/$cnum/group_folder_\E(\w+)\.sequence$}) {
2240: my $group = $1;
2241: if ($env{'form.folderpath'} =~ /^default&[^\&]+\&group_allfolders\&[^\&]+$/) {
2242: my %curr_group = &Apache::longroup::coursegroups($cdom,$cnum,$group);
2243: if (keys(%curr_group) > 0) {
2244: $noremove=1;
2245: }
2246: }
2247: $nocut=1;
2248: $nocopy=1;
2249: } elsif ($url =~ m{^\Q/adm/$cdom/$cnum/\E(\w+)/smppg$}) {
2250: my $group = $1;
2251: if ($env{'form.folderpath'} =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&\Qgroup_folder_$group\E\&[^\&]+$/) {
2252: my %curr_group = &Apache::longroup::coursegroups($cdom,$cnum,$group);
2253: my %groupsettings = &Apache::longroup::get_group_settings($curr_group{$group});
2254: if (keys(%groupsettings) > 0) {
2255: $noremove=1;
2256: }
2257: $nocut=1;
2258: $nocopy=1;
2259: }
2260: } elsif ($env{'form.folderpath'} =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&group_folder_(\w+)\&/) {
2261: my $group = $1;
2262: my %curr_group = &Apache::longroup::coursegroups($cdom,$cnum,$group);
2263: if ($url =~ /group_boards_\Q$group\E/) {
2264: my %curr_group = &Apache::longroup::coursegroups($cdom,$cnum,$group);
2265: my %groupsettings = &Apache::longroup::get_group_settings($curr_group{$group});
2266: if (keys(%groupsettings) > 0) {
2267: if (ref($groupsettings{'functions'}) eq 'HASH') {
2268: if ($groupsettings{'functions'}{'discussion'} eq 'on') {
2269: $noremove=1;
2270: }
2271: }
2272: }
2273: $nocut=1;
2274: $nocopy=1;
2275: }
2276: }
1.484.2.16! raeburn 2277: my ($copylink,$cutlink,$removelink,$renamelink);
1.364 bisitz 2278:
1.329 droeschl 2279: my $skip_confirm = 0;
2280: if ( $folder =~ /^supplemental/
2281: || ($url =~ m{( /smppg$
2282: |/syllabus$
2283: |/aboutme$
2284: |/navmaps$
2285: |/bulletinboard$
1.484.2.16! raeburn 2286: |\.html$)}x)
! 2287: || $isexternal) {
1.329 droeschl 2288: $skip_confirm = 1;
2289: }
1.484.2.16! raeburn 2290: if ($nocopy) {
! 2291: $copylink=(<<ENDCOPY);
! 2292: <span style="visibility: hidden;">$lt{'cp'}</span>
! 2293: ENDCOPY
! 2294: } else {
! 2295: $copylink=(<<ENDCOPY);
1.484 raeburn 2296: <a href="javascript:markcopy('$esc_path','$index','$renametitle','$container','$symb','$folder');" class="LC_docs_copy">$lt{'cp'}</a>
1.329 droeschl 2297: ENDCOPY
2298: }
1.484.2.16! raeburn 2299: if ($nocut) {
! 2300: $cutlink=(<<ENDCUT);
! 2301: <span style="visibility: hidden;">$lt{'ct'}</span>
! 2302: ENDCUT
! 2303: } else {
! 2304: $cutlink=(<<ENDCUT);
1.484 raeburn 2305: <a href="javascript:cutres('$esc_path','$index','$renametitle','$container','$symb','$folder',$skip_confirm);" class="LC_docs_cut">$lt{'ct'}</a>
1.329 droeschl 2306: ENDCUT
2307: }
1.484.2.16! raeburn 2308: if ($noremove) {
! 2309: $removelink=(<<ENDREM);
! 2310: <span style="visibility: hidden;">$lt{'rm'}</a>
! 2311: ENDREM
! 2312: } else {
1.484.2.9 raeburn 2313: $removelink=(<<ENDREM);
2314: <a href='javascript:removeres("$esc_path","$index","$renametitle","$container","$symb",$skip_confirm);' class="LC_docs_remove">$lt{'rm'}</a>
2315: ENDREM
2316: }
1.484.2.16! raeburn 2317: $renamelink=(<<ENDREN);
! 2318: <a href='javascript:changename("$esc_path","$index","$renametitle","$container","$symb");' class="LC_docs_rename">$lt{'rn'}</a>
! 2319: ENDREN
1.478 raeburn 2320: $form_start = '
2321: <form action="/adm/coursedocs" method="post">
2322: ';
2323: $form_common=(<<END);
1.329 droeschl 2324: <input type="hidden" name="${type}path" value="$path" />
2325: <input type="hidden" name="${type}symb" value="$symb" />
2326: <input type="hidden" name="setparms" value="$orderidx" />
2327: <input type="hidden" name="changeparms" value="0" />
2328: END
2329: $form_end = '</form>';
2330: $line.=(<<END);
2331: <td>
1.379 bisitz 2332: <div class="LC_docs_entry_move">
1.484.2.10 raeburn 2333: <a href='/adm/coursedocs?cmd=up_$index&${type}path=$esc_path&${type}symb=$symb'>
1.484.2.12 raeburn 2334: <img src="${iconpath}move_up.gif" alt="$lt{'up'}" class="LC_icon" />
1.379 bisitz 2335: </a>
2336: </div>
2337: <div class="LC_docs_entry_move">
1.484.2.10 raeburn 2338: <a href='/adm/coursedocs?cmd=down_$index&${type}path=$esc_path&${type}symb=$symb'>
1.484.2.12 raeburn 2339: <img src="${iconpath}move_down.gif" alt="$lt{'dw'}" class="LC_icon" />
1.379 bisitz 2340: </a>
2341: </div>
1.329 droeschl 2342: </td>
2343: <td>
2344: $form_start
1.478 raeburn 2345: $form_common
1.329 droeschl 2346: $selectbox
2347: $form_end
2348: </td>
1.484.2.16! raeburn 2349: <td class="LC_docs_entry_commands"><span class="LC_nobreak">
1.484.2.9 raeburn 2350: $removelink
1.484.2.16! raeburn 2351: $renamelink
1.329 droeschl 2352: $cutlink
2353: $copylink
1.484.2.16! raeburn 2354: </span>
1.329 droeschl 2355: </td>
2356: END
2357:
2358: }
2359: # Figure out what kind of a resource this is
2360: my ($extension)=($url=~/\.(\w+)$/);
2361: my $uploaded=($url=~/^\/*uploaded\//);
2362: my $icon=&Apache::loncommon::icon($url);
2363: my $isfolder=0;
2364: my $ispage=0;
2365: my $folderarg;
2366: my $pagearg;
2367: my $pagefile;
2368: if ($uploaded) {
1.472 raeburn 2369: if (($extension eq 'sequence') || ($extension eq 'page')) {
2370: $url=~/\Q$coursenum\E\/([\/\w]+)\.\Q$extension\E$/;
2371: my $containerarg = $1;
2372: if ($extension eq 'sequence') {
2373: $icon=$iconpath.'navmap.folder.closed.gif';
2374: $folderarg=$containerarg;
2375: $isfolder=1;
2376: } else {
2377: $icon=$iconpath.'page.gif';
2378: $pagearg=$containerarg;
2379: $ispage=1;
2380: }
2381: if ($allowed) {
2382: $url='/adm/coursedocs?';
2383: } else {
2384: $url='/adm/supplemental?';
2385: }
1.329 droeschl 2386: } else {
2387: &Apache::lonnet::allowuploaded('/adm/coursedoc',$url);
2388: }
2389: }
1.364 bisitz 2390:
1.484.2.12 raeburn 2391: my $editlink;
1.329 droeschl 2392: my $orig_url = $url;
1.340 raeburn 2393: $orig_url=~s{http(:|:)//https(:|:)//}{https$2//};
1.329 droeschl 2394: my $external = ($url=~s{^http(|s)(:|:)//}{/adm/wrapper/ext/});
1.484.2.12 raeburn 2395: if (!$supplementalflag && $residx && $symb) {
2396: if ($container eq 'page') {
2397: $url=&Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
2398: $url.=(($url=~/\?/)?'&':'?').'symb='.&escape($symb);
2399: }
2400: if ((!$isfolder) && (!$ispage)) {
2401: (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
2402: $url=&Apache::lonnet::clutter($url);
2403: if ($url=~/^\/*uploaded\//) {
2404: $url=~/\.(\w+)$/;
2405: my $embstyle=&Apache::loncommon::fileembstyle($1);
2406: if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
2407: $url='/adm/wrapper'.$url;
2408: } elsif ($embstyle eq 'ssi') {
2409: #do nothing with these
2410: } elsif ($url!~/\.(sequence|page)$/) {
2411: $url='/adm/coursedocs/showdoc'.$url;
2412: }
2413: } elsif ($url=~m|^/ext/|) {
2414: $url='/adm/wrapper'.$url;
2415: $external = 1;
2416: }
2417: if (&Apache::lonnet::symbverify($symb,$url)) {
2418: $url.=(($url=~/\?/)?'&':'?').'symb='.&escape($symb);
2419: } else {
2420: $url='';
2421: }
1.329 droeschl 2422: }
2423: }
1.478 raeburn 2424: my ($rand_pick_text,$rand_order_text);
1.329 droeschl 2425: if ($isfolder || $extension eq 'sequence') {
2426: my $foldername=&escape($foldertitle);
2427: my $folderpath=$env{'form.folderpath'};
2428: if ($folderpath) { $folderpath.='&' };
1.344 bisitz 2429: # Append randompick number, hidden, and encrypted with ":" to foldername,
1.329 droeschl 2430: # so it gets transferred between levels
2431: $folderpath.=$folderarg.'&'.$foldername.':'.(&LONCAPA::map::getparameter($orderidx,
2432: 'parameter_randompick'))[0]
2433: .':'.((&LONCAPA::map::getparameter($orderidx,
2434: 'parameter_hiddenresource'))[0]=~/^yes$/i)
2435: .':'.((&LONCAPA::map::getparameter($orderidx,
2436: 'parameter_encrypturl'))[0]=~/^yes$/i)
2437: .':'.((&LONCAPA::map::getparameter($orderidx,
2438: 'parameter_randomorder'))[0]=~/^yes$/i);
1.484.2.10 raeburn 2439: $url.='folderpath='.&escape($folderpath);
1.478 raeburn 2440: my $rpicknum = (&LONCAPA::map::getparameter($orderidx,
2441: 'parameter_randompick'))[0];
2442: my $rpckchk;
2443: if ($rpicknum) {
2444: $rpckchk = ' checked="checked"';
2445: }
2446: my $formname = 'edit_rpick_'.$orderidx;
2447: $rand_pick_text =
2448: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
2449: $form_common."\n".
2450: '<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.'" />';
2451: if ($rpicknum ne '') {
2452: $rand_pick_text .= ': <a href="javascript:updatePick('."document.$formname,'$orderidx','link'".')">'.$rpicknum.'</a>';
2453: }
2454: $rand_pick_text .= '</span></form>';
1.329 droeschl 2455: my $ro_set=
2456: ((&LONCAPA::map::getparameter($orderidx,'parameter_randomorder'))[0]=~/^yes$/i?' checked="checked"':'');
1.478 raeburn 2457: $rand_order_text =
2458: $form_start.
2459: $form_common.'
2460: <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 2461: }
2462: if ($ispage) {
2463: my $pagename=&escape($pagetitle);
2464: my $pagepath;
2465: my $folderpath=$env{'form.folderpath'};
2466: if ($folderpath) { $pagepath = $folderpath.'&' };
2467: $pagepath.=$pagearg.'&'.$pagename;
2468: $url.='pagepath='.&escape($pagepath).
1.484.2.10 raeburn 2469: '&pagesymb='.&escape($symb);
1.329 droeschl 2470: }
1.484.2.12 raeburn 2471: if ($allowed) {
2472: my $fileloc =
2473: &Apache::lonnet::declutter(&Apache::lonnet::filelocation('',$orig_url));
2474:
2475: if ($external) {
2476: $editlink = <<"EXTLNK";
2477:
2478: <a class="LC_docs_ext_edit" href="javascript:editext('$residx');">
2479: $lt{'ed'}</a>
2480: <form action="/adm/coursedocs" method="post" name="editext_$residx">
2481: <fieldset id="uploadext$residx" style="display: none;" />
2482: <input type="hidden" name="active" value="aa" />
2483: <span class="LC_nobreak">
2484: <span class="LC_docs_ext_edit">$lt{'ul'} </span>
2485: <input type="text" size="40" name="exturl" id="exturl_$residx" value="$orig_url" />
2486: <a class="LC_docs_ext_edit" href="javascript:extUrlPreview('exturl_$residx');">$lt{'pr'}</a></span>
2487: </span><br />
2488: <span class="LC_nobreak">
2489: <span class="LC_docs_ext_edit">$lt{'ti'} </span>
2490: <input type="text" size="40" name="exttitle" value="$title" />
2491: $uploadtag
2492: <input type="hidden" name="importdetail" value="" />
2493: <input type="button" value="$lt{'sv'}" onclick="javascript:setExternal(this.form,'$residx')" />
2494: </span>
2495: </fieldset>
2496: </form>
2497: EXTLNK
2498: } else {
1.484.2.14 raeburn 2499: my ($cfile,$home,$switchserver,$forceedit,$forceview) =
2500: &Apache::lonnet::can_edit_resource($fileloc,$coursenum,$coursedom,$orig_url);
1.484.2.12 raeburn 2501: if (($cfile ne '') && ($symb ne '')) {
2502: my $jscall =
2503: &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,
2504: $switchserver,
1.484.2.14 raeburn 2505: $forceedit,
2506: undef,$symb);
1.484.2.12 raeburn 2507: if ($jscall) {
2508: $editlink = ' <a class="LC_docs_ext_edit" href="javascript:'.
2509: $jscall.'" >'.&mt('Edit').'</a>';
2510: }
2511: }
2512: }
1.329 droeschl 2513: }
1.408 raeburn 2514: my $reinit;
2515: if ($crstype eq 'Community') {
2516: $reinit = &mt('(re-initialize community to access)');
2517: } else {
2518: $reinit = &mt('(re-initialize course to access)');
2519: }
1.469 www 2520: $line.='<td>';
1.472 raeburn 2521: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.469 www 2522: $line.='<a href="'.$url.'"><img src="'.$icon.'" alt="" class="LC_icon" /></a>';
2523: } elsif ($url) {
1.484 raeburn 2524: $line.=&Apache::loncommon::modal_link($url.(($url=~/\?/)?'&':'?').'inhibitmenu=yes',
1.470 raeburn 2525: '<img src="'.$icon.'" alt="" class="LC_icon" />',600,500);
1.469 www 2526: } else {
2527: $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
2528: }
2529: $line.='</td><td>';
1.472 raeburn 2530: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.469 www 2531: $line.='<a href="'.$url.'">'.$title.'</a>';
2532: } elsif ($url) {
1.484 raeburn 2533: $line.=&Apache::loncommon::modal_link($url.(($url=~/\?/)?'&':'?').'inhibitmenu=yes',
1.470 raeburn 2534: $title,600,500);
1.469 www 2535: } else {
2536: $line.=$title.' <span class="LC_docs_reinit_warn">'.$reinit.'</span>';
2537: }
1.484.2.12 raeburn 2538: $line.=$editlink."</td>";
1.478 raeburn 2539: $rand_pick_text = ' ' if ($rand_pick_text eq '');
2540: $rand_order_text = ' ' if ($rand_order_text eq '');
1.329 droeschl 2541: if (($allowed) && ($folder!~/^supplemental/)) {
2542: my %lt=&Apache::lonlocal::texthash(
2543: 'hd' => 'Hidden',
2544: 'ec' => 'URL hidden');
2545: my $enctext=
1.358 bisitz 2546: ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i?' checked="checked"':'');
1.329 droeschl 2547: my $hidtext=
1.358 bisitz 2548: ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i?' checked="checked"':'');
1.329 droeschl 2549: $line.=(<<ENDPARMS);
2550: <td class="LC_docs_entry_parameter">
2551: $form_start
1.478 raeburn 2552: $form_common
1.369 bisitz 2553: <label><input type="checkbox" name="hiddenresource_$orderidx" onclick="this.form.changeparms.value='hiddenresource';this.form.submit()" $hidtext /> $lt{'hd'}</label>
1.329 droeschl 2554: $form_end
1.458 raeburn 2555: <br />
1.329 droeschl 2556: $form_start
1.478 raeburn 2557: $form_common
1.369 bisitz 2558: <label><input type="checkbox" name="encrypturl_$orderidx" onclick="this.form.changeparms.value='encrypturl';this.form.submit()" $enctext /> $lt{'ec'}</label>
1.329 droeschl 2559: $form_end
2560: </td>
1.478 raeburn 2561: <td class="LC_docs_entry_parameter">$rand_pick_text<br />
2562: $rand_order_text</td>
1.329 droeschl 2563: ENDPARMS
2564: }
1.379 bisitz 2565: $line.=&Apache::loncommon::end_data_table_row();
1.329 droeschl 2566: return $line;
2567: }
2568:
1.484.2.15 raeburn 2569: sub newmap_suffix {
2570: my ($area,$container,$coursedom,$coursenum) = @_;
2571: my ($prefix,$idtype,$errtext,$locknotfreed);
2572: $prefix = 'docs';
2573: if ($area eq 'supplemental') {
2574: $prefix = 'supp';
2575: }
2576: $prefix .= $container;
2577: $idtype = 'concat';
2578: my ($suffix,$freedlock,$error) =
2579: &Apache::lonnet::get_timebased_id($prefix,'num','uploadedmaps',
2580: $coursedom,$coursenum);
2581: if (!$suffix) {
2582: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new folder/page.');
2583: if ($error) {
2584: $errtext .= '<br />'.$error;
2585: }
2586: }
2587: if ($freedlock ne 'ok') {
2588: $locknotfreed = '<div class="LC_error">'.&mt('There was a problem removing a lockfile. This will prevent creation of additional folders or composite pages in this course. Please contact the domain coordinator for your LON-CAPA domain.').'</div>';
2589: }
2590: return ($suffix,$errtext,$locknotfreed);
2591: }
2592:
1.329 droeschl 2593: =pod
2594:
2595: =item tiehash()
2596:
2597: tie the hash
2598:
2599: =cut
2600:
2601: sub tiehash {
2602: my ($mode)=@_;
2603: $hashtied=0;
2604: if ($env{'request.course.fn'}) {
2605: if ($mode eq 'write') {
2606: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
2607: &GDBM_WRCREAT(),0640)) {
2608: $hashtied=2;
2609: }
2610: } else {
2611: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
2612: &GDBM_READER(),0640)) {
2613: $hashtied=1;
2614: }
2615: }
1.364 bisitz 2616: }
1.329 droeschl 2617: }
2618:
2619: sub untiehash {
2620: if ($hashtied) { untie %hash; }
2621: $hashtied=0;
2622: return OK;
2623: }
2624:
2625:
2626:
2627:
2628: sub checkonthis {
2629: my ($r,$url,$level,$title)=@_;
2630: $url=&unescape($url);
2631: $alreadyseen{$url}=1;
2632: $r->rflush();
2633: if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
2634: $r->print("\n<br />");
2635: if ($level==0) {
2636: $r->print("<br />");
2637: }
2638: for (my $i=0;$i<=$level*5;$i++) {
2639: $r->print(' ');
2640: }
2641: $r->print('<a href="'.$url.'" target="cat">'.
2642: ($title?$title:$url).'</a> ');
2643: if ($url=~/^\/res\//) {
2644: my $result=&Apache::lonnet::repcopy(
2645: &Apache::lonnet::filelocation('',$url));
2646: if ($result eq 'ok') {
2647: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
2648: $r->rflush();
2649: &Apache::lonnet::countacc($url);
2650: $url=~/\.(\w+)$/;
2651: if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
2652: $r->print('<br />');
2653: $r->rflush();
2654: for (my $i=0;$i<=$level*5;$i++) {
2655: $r->print(' ');
2656: }
2657: $r->print('- '.&mt('Rendering:').' ');
2658: my ($errorcount,$warningcount)=split(/:/,
2659: &Apache::lonnet::ssi_body($url,
2660: ('grade_target'=>'web',
2661: 'return_only_error_and_warning_counts' => 1)));
2662: if (($errorcount) ||
2663: ($warningcount)) {
2664: if ($errorcount) {
1.369 bisitz 2665: $r->print('<img src="/adm/lonMisc/bomb.gif" alt="'.&mt('bomb').'" /><span class="LC_error">'.
1.329 droeschl 2666: &mt('[quant,_1,error]',$errorcount).'</span>');
2667: }
2668: if ($warningcount) {
2669: $r->print('<span class="LC_warning">'.
2670: &mt('[quant,_1,warning]',$warningcount).'</span>');
2671: }
2672: } else {
2673: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
2674: }
2675: $r->rflush();
2676: }
2677: my $dependencies=
2678: &Apache::lonnet::metadata($url,'dependencies');
2679: foreach my $dep (split(/\,/,$dependencies)) {
2680: if (($dep=~/^\/res\//) && (!$alreadyseen{$dep})) {
2681: &checkonthis($r,$dep,$level+1);
2682: }
2683: }
2684: } elsif ($result eq 'unavailable') {
2685: $r->print('<span class="LC_error">'.&mt('connection down').'</span>');
2686: } elsif ($result eq 'not_found') {
2687: unless ($url=~/\$/) {
2688: $r->print('<span class="LC_error">'.&mt('not found').'</b></span>');
2689: } else {
1.366 bisitz 2690: $r->print('<span class="LC_error">'.&mt('unable to verify variable URL').'</span>');
1.329 droeschl 2691: }
2692: } else {
2693: $r->print('<span class="LC_error">'.&mt('access denied').'</span>');
2694: }
2695: }
2696: }
2697: }
2698:
2699:
2700:
2701: =pod
2702:
2703: =item list_symbs()
2704:
1.484.2.3 raeburn 2705: List Content Identifiers
1.329 droeschl 2706:
2707: =cut
2708:
2709: sub list_symbs {
2710: my ($r) = @_;
2711:
1.408 raeburn 2712: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 2713: $r->print(&Apache::loncommon::start_page('List of Content Identifiers'));
2714: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Identifiers'));
2715: $r->print(&startContentScreen('tools'));
1.329 droeschl 2716: my $navmap = Apache::lonnavmaps::navmap->new();
2717: if (!defined($navmap)) {
2718: $r->print('<h2>'.&mt('Retrieval of List Failed').'</h2>'.
2719: '<div class="LC_error">'.
2720: &mt('Unable to retrieve information about course contents').
2721: '</div>');
1.408 raeburn 2722: &Apache::lonnet::logthis('Symb list failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
1.329 droeschl 2723: } else {
1.484 raeburn 2724: $r->print('<h4 class="LC_info">'.&mt("$crstype Content Identifiers").'</h4>'.
2725: &Apache::loncommon::start_data_table().
2726: &Apache::loncommon::start_data_table_header_row().
2727: '<th>'.&mt('Title').'</th><th>'.&mt('Identifier').'</th>'.
2728: &Apache::loncommon::end_data_table_header_row()."\n");
2729: my $count;
1.329 droeschl 2730: foreach my $res ($navmap->retrieveResources()) {
1.484 raeburn 2731: $r->print(&Apache::loncommon::start_data_table_row().
2732: '<td>'.$res->compTitle().'</td>'.
2733: '<td>'.$res->symb().'</td>'.
2734: &Apache::loncommon::start_data_table_row());
2735: $count ++;
2736: }
2737: if (!$count) {
2738: $r->print(&Apache::loncommon::start_data_table_row().
2739: '<td colspan="2">'.&mt("$crstype is empty").'</td>'.
2740: &Apache::loncommon::end_data_table_row());
1.329 droeschl 2741: }
1.484 raeburn 2742: $r->print(&Apache::loncommon::end_data_table());
1.329 droeschl 2743: }
2744: }
2745:
2746:
2747: sub verifycontent {
2748: my ($r) = @_;
1.408 raeburn 2749: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 2750: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Documents'));
2751: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Documents'));
2752: $r->print(&startContentScreen('tools'));
2753: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
1.329 droeschl 2754: $hashtied=0;
2755: undef %alreadyseen;
2756: %alreadyseen=();
2757: &tiehash();
1.484 raeburn 2758:
1.329 droeschl 2759: foreach my $key (keys(%hash)) {
2760: if ($hash{$key}=~/\.(page|sequence)$/) {
2761: if (($key=~/^src_/) && ($alreadyseen{&unescape($hash{$key})})) {
2762: $r->print('<hr /><span class="LC_error">'.
1.419 bisitz 2763: &mt('The following sequence or page is included more than once in your '.$crstype.':').' '.
1.329 droeschl 2764: &unescape($hash{$key}).'</span><br />'.
1.419 bisitz 2765: &mt('Note that grading records for problems included in this sequence or folder will overlap.').'<hr />');
1.329 droeschl 2766: }
2767: }
2768: if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) {
2769: &checkonthis($r,$hash{$key},0,$hash{'title_'.$1});
2770: }
2771: }
2772: &untiehash();
1.442 www 2773: $r->print('<p class="LC_success">'.&mt('Done').'</p>');
1.329 droeschl 2774: }
2775:
2776:
2777: sub devalidateversioncache {
2778: my $src=shift;
2779: &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
2780: &Apache::lonnet::clutter($src));
2781: }
2782:
2783: sub checkversions {
2784: my ($r) = @_;
1.408 raeburn 2785: my $crstype = &Apache::loncommon::course_type();
2786: $r->print(&Apache::loncommon::start_page("Check $crstype Document Versions"));
2787: $r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $crstype Document Versions"));
1.484 raeburn 2788: $r->print(&startContentScreen('tools'));
1.442 www 2789:
1.329 droeschl 2790: my $header='';
2791: my $startsel='';
2792: my $monthsel='';
2793: my $weeksel='';
2794: my $daysel='';
2795: my $allsel='';
2796: my %changes=();
2797: my $starttime=0;
2798: my $haschanged=0;
2799: my %setversions=&Apache::lonnet::dump('resourceversions',
2800: $env{'course.'.$env{'request.course.id'}.'.domain'},
2801: $env{'course.'.$env{'request.course.id'}.'.num'});
2802:
2803: $hashtied=0;
2804: &tiehash();
2805: my %newsetversions=();
2806: if ($env{'form.setmostrecent'}) {
2807: $haschanged=1;
2808: foreach my $key (keys(%hash)) {
2809: if ($key=~/^ids\_(\/res\/.+)$/) {
2810: $newsetversions{$1}='mostrecent';
2811: &devalidateversioncache($1);
2812: }
2813: }
2814: } elsif ($env{'form.setcurrent'}) {
2815: $haschanged=1;
2816: foreach my $key (keys(%hash)) {
2817: if ($key=~/^ids\_(\/res\/.+)$/) {
2818: my $getvers=&Apache::lonnet::getversion($1);
2819: if ($getvers>0) {
2820: $newsetversions{$1}=$getvers;
2821: &devalidateversioncache($1);
2822: }
2823: }
2824: }
2825: } elsif ($env{'form.setversions'}) {
2826: $haschanged=1;
2827: foreach my $key (keys(%env)) {
2828: if ($key=~/^form\.set_version_(.+)$/) {
2829: my $src=$1;
2830: if (($env{$key}) && ($env{$key} ne $setversions{$src})) {
2831: $newsetversions{$src}=$env{$key};
2832: &devalidateversioncache($src);
2833: }
2834: }
2835: }
2836: }
2837: if ($haschanged) {
2838: if (&Apache::lonnet::put('resourceversions',\%newsetversions,
2839: $env{'course.'.$env{'request.course.id'}.'.domain'},
1.344 bisitz 2840: $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
1.479 golterma 2841: $r->print(&Apache::loncommon::confirmwrapper(
2842: &Apache::lonhtmlcommon::confirm_success(&mt('Your Version Settings have been Saved'))));
1.329 droeschl 2843: } else {
1.479 golterma 2844: $r->print(&Apache::loncommon::confirmwrapper(
2845: &Apache::lonhtmlcommon::confirm_success(&mt('An Error Occured while Attempting to Save your Version Settings'),1)));
1.329 droeschl 2846: }
2847: &mark_hash_old();
2848: }
2849: &changewarning($r,'');
2850: if ($env{'form.timerange'} eq 'all') {
2851: # show all documents
1.408 raeburn 2852: $header=&mt('All Documents in '.$crstype);
1.329 droeschl 2853: $allsel=1;
2854: foreach my $key (keys(%hash)) {
2855: if ($key=~/^ids\_(\/res\/.+)$/) {
2856: my $src=$1;
2857: $changes{$src}=1;
2858: }
2859: }
2860: } else {
2861: # show documents which changed
2862: %changes=&Apache::lonnet::dump
2863: ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
2864: $env{'course.'.$env{'request.course.id'}.'.num'});
2865: my $firstkey=(keys(%changes))[0];
2866: unless ($firstkey=~/^error\:/) {
2867: unless ($env{'form.timerange'}) {
2868: $env{'form.timerange'}=604800;
2869: }
2870: my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
2871: .&mt('seconds');
2872: if ($env{'form.timerange'}==-1) {
2873: $seltext='since start of course';
2874: $startsel='selected';
2875: $env{'form.timerange'}=time;
2876: }
2877: $starttime=time-$env{'form.timerange'};
2878: if ($env{'form.timerange'}==2592000) {
2879: $seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
2880: $monthsel='selected';
2881: } elsif ($env{'form.timerange'}==604800) {
2882: $seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
2883: $weeksel='selected';
2884: } elsif ($env{'form.timerange'}==86400) {
2885: $seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
2886: $daysel='selected';
2887: }
2888: $header=&mt('Content changed').' '.$seltext;
2889: } else {
2890: $header=&mt('No content modifications yet.');
2891: }
2892: }
2893: %setversions=&Apache::lonnet::dump('resourceversions',
2894: $env{'course.'.$env{'request.course.id'}.'.domain'},
2895: $env{'course.'.$env{'request.course.id'}.'.num'});
2896: my %lt=&Apache::lonlocal::texthash
1.408 raeburn 2897: ('st' => 'Version changes since start of '.$crstype,
1.329 droeschl 2898: 'lm' => 'Version changes since last Month',
2899: 'lw' => 'Version changes since last Week',
2900: 'sy' => 'Version changes since Yesterday',
2901: 'al' => 'All Resources (possibly large output)',
1.484 raeburn 2902: 'cd' => 'Change display',
1.329 droeschl 2903: 'sd' => 'Display',
2904: 'fi' => 'File',
2905: 'md' => 'Modification Date',
2906: 'mr' => 'Most recently published Version',
1.408 raeburn 2907: 've' => 'Version used in '.$crstype,
2908: 'vu' => 'Set Version to be used in '.$crstype,
2909: 'sv' => 'Set Versions to be used in '.$crstype.' according to Selections below',
1.329 droeschl 2910: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
2911: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
1.479 golterma 2912: 'di' => 'Differences',
1.484 raeburn 2913: 'save' => 'Save changes',
2914: 'vers' => 'Version choice(s) for specific resources',
1.479 golterma 2915: 'act' => 'Actions');
1.329 droeschl 2916: $r->print(<<ENDHEADERS);
1.484 raeburn 2917: <h4 class="LC_info">$header</h4>
1.329 droeschl 2918: <form action="/adm/coursedocs" method="post">
2919: <input type="hidden" name="versions" value="1" />
1.484 raeburn 2920: <div class="LC_left_float">
1.479 golterma 2921: <fieldset>
1.484 raeburn 2922: <legend>$lt{'cd'}</legend>
1.329 droeschl 2923: <select name="timerange">
2924: <option value='all' $allsel>$lt{'al'}</option>
2925: <option value="-1" $startsel>$lt{'st'}</option>
2926: <option value="2592000" $monthsel>$lt{'lm'}</option>
2927: <option value="604800" $weeksel>$lt{'lw'}</option>
2928: <option value="86400" $daysel>$lt{'sy'}</option>
2929: </select>
2930: <input type="submit" name="display" value="$lt{'sd'}" />
1.484 raeburn 2931: </fieldset>
2932: </div>
2933: <div class="LC_left_float">
2934: <fieldset>
2935: <legend>$lt{'act'}</legend>
2936: $lt{'sm'}: <input type="submit" name="setmostrecent" value="Go" /><br />
2937: $lt{'sc'}: <input type="submit" name="setcurrent" value="Go" />
2938: </fieldset>
2939: </div>
2940: <br clear="all" />
2941: <hr />
2942: <h4>$lt{'vers'}</h4>
1.479 golterma 2943: <input type="submit" name="setversions" value="$lt{'save'}" />
1.329 droeschl 2944: <table border="0">
2945: ENDHEADERS
1.479 golterma 2946: #number of columns for version history
2947: my $num_ver_col = 1;
2948: $r->print(
2949: &Apache::loncommon::start_data_table().
2950: &Apache::loncommon::start_data_table_header_row().
2951: '<th>'.&mt('Resources').'</th>'.
2952: "<th>$lt{'mr'}</th>".
2953: "<th>$lt{'ve'}</th>".
2954: "<th>$lt{'vu'}</th>".
2955: '<th colspan="'.$num_ver_col.'">'.&mt('History').'</th>'.
2956: '</b>');
1.329 droeschl 2957: foreach my $key (sort(keys(%changes))) {
1.484.2.10 raeburn 2958: #excludes not versionable problems from resource version history:
2959: next unless ($changes{$key}>$starttime && $key !~ /^\/res\/lib\/templates/);
1.329 droeschl 2960: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
2961: my $currentversion=&Apache::lonnet::getversion($key);
2962: if ($currentversion<0) {
1.479 golterma 2963: $currentversion='<span class="LC_error">'.&mt('Could not be determined.').'</span>';
1.329 droeschl 2964: }
2965: my $linkurl=&Apache::lonnet::clutter($key);
1.479 golterma 2966: $r->print(
2967: &Apache::loncommon::end_data_table_header_row().
2968: &Apache::loncommon::start_data_table_row().
2969: '<td><b>'.&Apache::lonnet::gettitle($linkurl).'</b><br>'.
2970: '<a href="'.$linkurl.'" target="cat">'.$linkurl.'</a></td>'.
2971: '<td align="right">'.$currentversion.'<span class="LC_fontsize_medium"><br>('.
2972: &Apache::lonlocal::locallocaltime(&Apache::lonnet::metadata($root.'.'.$extension,'lastrevisiondate')).')</span></td>'.
2973: '<td align="right">');
1.329 droeschl 2974: # Used in course
2975: my $usedversion=$hash{'version_'.$linkurl};
2976: if (($usedversion) && ($usedversion ne 'mostrecent')) {
1.479 golterma 2977: if($usedversion != $currentversion){
2978: $r->print('<span class="LC_warning">'.$usedversion.'</span>');
2979: }else{
2980: $r->print($usedversion);
2981: }
1.329 droeschl 2982: } else {
2983: $r->print($currentversion);
2984: }
1.479 golterma 2985: $r->print('</td><td title="'.$lt{'vu'}.'">');
1.329 droeschl 2986: # Set version
2987: $r->print(&Apache::loncommon::select_form($setversions{$linkurl},
2988: 'set_version_'.$linkurl,
1.428 raeburn 2989: {'select_form_order' =>
1.329 droeschl 2990: ['',1..$currentversion,'mostrecent'],
2991: '' => '',
1.411 bisitz 2992: 'mostrecent' => &mt('most recent'),
1.428 raeburn 2993: map {$_,$_} (1..$currentversion)}));
1.329 droeschl 2994: my $lastold=1;
2995: for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
2996: my $url=$root.'.'.$prevvers.'.'.$extension;
2997: if (&Apache::lonnet::metadata($url,'lastrevisiondate')<
2998: $starttime) {
2999: $lastold=$prevvers;
3000: }
3001: }
1.364 bisitz 3002: #
1.329 droeschl 3003: # Code to figure out how many version entries should go in
3004: # each of the four columns
3005: my $entries_per_col = 0;
3006: my $num_entries = ($currentversion-$lastold);
1.479 golterma 3007: if ($num_entries % $num_ver_col == 0) {
3008: $entries_per_col = $num_entries/$num_ver_col;
1.329 droeschl 3009: } else {
1.479 golterma 3010: $entries_per_col = $num_entries/$num_ver_col + 1;
1.329 droeschl 3011: }
3012: my $entries_count = 0;
1.479 golterma 3013: $r->print('<td valign="top"><span class="LC_fontsize_medium">');
1.329 droeschl 3014: my $cols_output = 1;
3015: for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
3016: my $url=$root.'.'.$prevvers.'.'.$extension;
3017: $r->print('<span class="LC_nobreak"><a href="'.&Apache::lonnet::clutter($url).
3018: '">'.&mt('Version').' '.$prevvers.'</a> ('.
3019: &Apache::lonlocal::locallocaltime(
3020: &Apache::lonnet::metadata($url,
3021: 'lastrevisiondate')
3022: ).
3023: ')');
3024: if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
3025: $r->print(' <a href="/adm/diff?filename='.
3026: &Apache::lonnet::clutter($root.'.'.$extension).
3027: '&versionone='.$prevvers.
1.462 raeburn 3028: '" target="diffs">'.&mt('Diffs').'</a>');
1.329 droeschl 3029: }
3030: $r->print('</span><br />');
3031: if (++$entries_count % $entries_per_col == 0) {
1.479 golterma 3032: $r->print('</span></td>');
3033: if ($cols_output != $num_ver_col) {
3034: $r->print('<td valign="top"><span class="LC_fontsize_medium">');
1.329 droeschl 3035: $cols_output++;
3036: }
3037: }
3038: }
1.479 golterma 3039: while($cols_output++ < $num_ver_col) {
3040: $r->print('</span></td><td>');
1.329 droeschl 3041: }
3042: }
3043: }
1.479 golterma 3044: $r->print('</td>'.&Apache::loncommon::end_data_table_row().
3045: &Apache::loncommon::end_data_table().
3046: '<input type="submit" name="setversions" value="'.$lt{'save'}.'" />');
1.329 droeschl 3047:
3048: &untiehash();
3049: }
3050:
3051: sub mark_hash_old {
3052: my $retie_hash=0;
3053: if ($hashtied) {
3054: $retie_hash=1;
3055: &untiehash();
3056: }
3057: &tiehash('write');
3058: $hash{'old'}=1;
3059: &untiehash();
3060: if ($retie_hash) { &tiehash(); }
3061: }
3062:
3063: sub is_hash_old {
3064: my $untie_hash=0;
3065: if (!$hashtied) {
3066: $untie_hash=1;
3067: &tiehash();
3068: }
3069: my $return=$hash{'old'};
3070: if ($untie_hash) { &untiehash(); }
3071: return $return;
3072: }
3073:
3074: sub changewarning {
3075: my ($r,$postexec,$message,$url)=@_;
3076: if (!&is_hash_old()) { return; }
3077: my $pathvar='folderpath';
3078: my $path=&escape($env{'form.folderpath'});
3079: if (!defined($url)) {
3080: if (defined($env{'form.pagepath'})) {
3081: $pathvar='pagepath';
3082: $path=&escape($env{'form.pagepath'});
3083: $path.='&pagesymb='.&escape($env{'form.pagesymb'});
3084: }
3085: $url='/adm/coursedocs?'.$pathvar.'='.$path;
3086: }
3087: my $course_type = &Apache::loncommon::course_type();
3088: if (!defined($message)) {
3089: $message='Changes will become active for your current session after [_1], or the next time you log in.';
3090: }
3091: $r->print("\n\n".
1.372 bisitz 3092: '<script type="text/javascript">'."\n".
3093: '// <![CDATA['."\n".
3094: 'function reinit(tf) { tf.submit();'.$postexec.' }'."\n".
3095: '// ]]>'."\n".
1.369 bisitz 3096: '</script>'."\n".
1.375 tempelho 3097: '<form name="reinitform" method="post" action="/adm/roles" target="loncapaclient">'.
1.329 droeschl 3098: '<input type="hidden" name="orgurl" value="'.$url.
1.372 bisitz 3099: '" /><input type="hidden" name="selectrole" value="1" /><p class="LC_warning">'.
1.329 droeschl 3100: &mt($message,' <input type="hidden" name="'.
3101: $env{'request.role'}.'" value="1" /><input type="button" value="'.
1.369 bisitz 3102: &mt('re-initializing '.$course_type).'" onclick="reinit(this.form)" />').
1.372 bisitz 3103: $help{'Caching'}.'</p></form>'."\n\n");
1.329 droeschl 3104: }
3105:
3106:
3107: sub init_breadcrumbs {
3108: my ($form,$text)=@_;
3109: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.484 raeburn 3110: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1",
1.405 bisitz 3111: text=>&Apache::loncommon::course_type().' Editor',
1.329 droeschl 3112: faq=>273,
3113: bug=>'Instructor Interface',
3114: help => 'Docs_Adding_Course_Doc'});
3115: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?".$form.'=1',
3116: text=>$text,
3117: faq=>273,
3118: bug=>'Instructor Interface'});
3119: }
3120:
1.441 www 3121: # subroutine to list form elements
3122: sub create_list_elements {
3123: my @formarr = @_;
3124: my $list = '';
1.484.2.12 raeburn 3125: foreach my $button (@formarr){
3126: foreach my $picture (keys(%{$button})) {
3127: $list .= &Apache::lonhtmlcommon::htmltag('li', $picture.' '.$button->{$picture}, {class => 'LC_menubuttons_inline_text', id => ''});
1.441 www 3128: }
3129: }
3130: return $list;
3131: }
1.329 droeschl 3132:
1.441 www 3133: # subroutine to create ul from list elements
3134: sub create_form_ul {
3135: my $list = shift;
3136: my $ul = &Apache::lonhtmlcommon::htmltag('ul',$list, {class => 'LC_ListStyleNormal'});
3137: return $ul;
3138: }
1.329 droeschl 3139:
1.442 www 3140: #
3141: # Start tabs
3142: #
3143:
3144: sub startContentScreen {
1.484 raeburn 3145: my ($mode) = @_;
3146: my $output = '<ul class="LC_TabContentBigger" id="mainnav">';
1.472 raeburn 3147: if (($mode eq 'navmaps') || ($mode eq 'supplemental')) {
1.484 raeburn 3148: $output .= '<li'.(($mode eq 'navmaps')?' class="active"':'').'><a href="/adm/navmaps"><b> '.&mt('Content Overview').' </b></a></li>'."\n";
3149: $output .= '<li'.(($mode eq 'coursesearch')?' class="active"':'').'><a href="/adm/searchcourse"><b> '.&mt('Content Search').' </b></a></li>'."\n";
3150: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/supplemental"><b>'.&mt('Supplemental Content').'</b></a></li>';
3151: } else {
3152: $output .= '<li '.(($mode eq 'docs')?' class="active"':'').' id="tabbededitor"><a href="/adm/coursedocs?forcestandard=1"><b> '.&mt('Content Editor').' </b></a></li>'."\n";
3153: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/coursedocs?forcesupplement=1"><b>'.&mt('Supplemental Content Editor').'</b></a></li>'."\n";
3154: $output .= '<li '.(($mode eq 'tools')?' class="active"':'').'><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>'."\n";
3155: '><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>';
3156: }
3157: $output .= "\n".'</ul>'."\n";
3158: $output .= '<div class="LC_DocsBox" style="clear:both;margin:0;" id="contenteditor">'.
3159: '<div id="maincoursedoc" style="margin:0 0;padding:0 0;">'.
3160: '<div class="LC_ContentBox" id="mainCourseDocuments" style="display: block;">';
3161: return $output;
1.442 www 3162: }
3163:
3164: #
3165: # End tabs
3166: #
3167:
3168: sub endContentScreen {
1.484 raeburn 3169: return '</div></div></div>';
1.442 www 3170: }
1.329 droeschl 3171:
1.446 www 3172: sub supplemental_base {
1.472 raeburn 3173: return 'supplemental&'.&escape(&mt('Supplemental '.&Apache::loncommon::course_type().' Content'));
1.446 www 3174: }
3175:
1.329 droeschl 3176: sub handler {
3177: my $r = shift;
3178: &Apache::loncommon::content_type($r,'text/html');
3179: $r->send_http_header;
3180: return OK if $r->header_only;
1.484 raeburn 3181:
3182: # get course data
1.408 raeburn 3183: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 3184: my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
3185: my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
3186:
3187: # graphics settings
3188: $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL').'/');
1.329 droeschl 3189:
1.443 www 3190: #
1.329 droeschl 3191: # --------------------------------------------- Initialize help topics for this
3192: foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',
3193: 'Adding_External_Resource','Navigate_Content',
3194: 'Adding_Folders','Docs_Overview', 'Load_Map',
3195: 'Supplemental','Score_Upload_Form','Adding_Pages',
1.484.2.12 raeburn 3196: 'Importing_LON-CAPA_Resource','Importing_IMS_Course',
3197: 'Uploading_From_Harddrive',
1.329 droeschl 3198: 'Check_Resource_Versions','Verify_Content') {
3199: $help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
3200: }
3201: # Composite help files
3202: $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
3203: 'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
3204: $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
3205: 'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
3206: $help{'Simple Problem'} = &Apache::loncommon::help_open_topic(
3207: 'Option_Response_Simple');
3208: $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
3209: 'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
1.347 weissno 3210: $help{'My Personal Information Page'} = &Apache::loncommon::help_open_topic(
1.329 droeschl 3211: 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
1.353 weissno 3212: $help{'Group Portfolio'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
1.329 droeschl 3213: $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
3214:
1.472 raeburn 3215:
3216: my $allowed;
3217: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
3218: unless ($r->uri eq '/adm/supplemental') {
3219: # does this user have privileges to modify content.
3220: $allowed = &Apache::lonnet::allowed('mdc',$env{'request.course.id'});
3221: }
3222:
1.484 raeburn 3223: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['chooseserver',
3224: 'inhibitmenu']);
3225: if ($allowed && $env{'form.chooseserver'}) {
3226: &choose_dump_server($r);
3227: return OK;
3228: } elsif ($allowed && $env{'form.verify'}) {
1.329 droeschl 3229: &init_breadcrumbs('verify','Verify Content');
3230: &verifycontent($r);
3231: } elsif ($allowed && $env{'form.listsymbs'}) {
1.484 raeburn 3232: &init_breadcrumbs('listsymbs','List Content IDs');
1.329 droeschl 3233: &list_symbs($r);
3234: } elsif ($allowed && $env{'form.docslog'}) {
3235: &init_breadcrumbs('docslog','Show Log');
1.484 raeburn 3236: my $folder = $env{'form.folder'};
3237: if ($folder eq '') {
3238: $folder='default';
3239: }
3240: &docs_change_log($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath);
1.329 droeschl 3241: } elsif ($allowed && $env{'form.versions'}) {
3242: &init_breadcrumbs('versions','Check/Set Resource Versions');
3243: &checkversions($r);
3244: } elsif ($allowed && $env{'form.dumpcourse'}) {
1.484 raeburn 3245: &init_breadcrumbs('dumpcourse','Dump '.&Apache::loncommon::course_type().' Content to Authoring Space');
1.329 droeschl 3246: &dumpcourse($r);
3247: } elsif ($allowed && $env{'form.exportcourse'}) {
1.377 bisitz 3248: &init_breadcrumbs('exportcourse','IMS Export');
1.475 raeburn 3249: &Apache::imsexport::exportcourse($r);
1.329 droeschl 3250: } else {
1.445 www 3251: #
3252: # Done catching special calls
1.484 raeburn 3253: # The whole rest is for course and supplemental documents and utilities menu
1.445 www 3254: # Get the parameters that may be needed
3255: #
3256: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
3257: ['folderpath','pagepath',
1.466 www 3258: 'pagesymb','forcesupplement','forcestandard',
1.484 raeburn 3259: 'tools','symb','command']);
1.445 www 3260:
3261: # standard=1: this is a "new-style" course with an uploaded map as top level
3262: # standard=2: this is a "old-style" course, and there is nothing we can do
1.329 droeschl 3263:
3264: my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
1.445 www 3265:
1.484 raeburn 3266: # Decide whether this should display supplemental or main content or utilities
1.445 www 3267: # supplementalflag=1: show supplemental documents
3268: # supplementalflag=0: show standard documents
1.484 raeburn 3269: # toolsflag=1: show utilities
1.445 www 3270:
3271:
3272: my $supplementalflag=($env{'form.folderpath'}=~/^supplemental/);
3273: if (($env{'form.folderpath'}=~/^default/) || $env{'form.folderpath'} eq "" || ($env{'form.pagepath'})) {
3274: $supplementalflag=0;
3275: }
3276: if ($env{'form.forcesupplement'}) { $supplementalflag=1; }
3277: if ($env{'form.forcestandard'}) { $supplementalflag=0; }
3278: unless ($allowed) { $supplementalflag=1; }
3279: unless ($standard) { $supplementalflag=1; }
1.484 raeburn 3280: my $toolsflag=0;
3281: if ($env{'form.tools'}) { $toolsflag=1; }
1.445 www 3282:
1.329 droeschl 3283: my $script='';
3284: my $showdoc=0;
1.457 raeburn 3285: my $addentries = {};
1.475 raeburn 3286: my $container;
1.329 droeschl 3287: my $containertag;
3288: my $uploadtag;
3289:
1.464 www 3290: # Do we directly jump somewhere?
1.466 www 3291:
1.464 www 3292: if ($env{'form.command'} eq 'direct') {
1.468 raeburn 3293: my ($mapurl,$id,$resurl);
1.472 raeburn 3294: if ($env{'form.symb'} ne '') {
1.468 raeburn 3295: ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($env{'form.symb'});
3296: if ($resurl=~/\.(sequence|page)$/) {
3297: $mapurl=$resurl;
3298: } elsif ($resurl eq 'adm/navmaps') {
3299: $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
3300: }
1.472 raeburn 3301: my $mapresobj;
3302: my $navmap = Apache::lonnavmaps::navmap->new();
3303: if (ref($navmap)) {
3304: $mapresobj = $navmap->getResourceByUrl($mapurl);
3305: }
3306: $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
3307: my $type=$2;
3308: my $path;
3309: if (ref($mapresobj)) {
3310: my $pcslist = $mapresobj->map_hierarchy();
3311: if ($pcslist ne '') {
3312: foreach my $pc (split(/,/,$pcslist)) {
3313: next if ($pc <= 1);
3314: my $res = $navmap->getByMapPc($pc);
3315: if (ref($res)) {
3316: my $thisurl = $res->src();
3317: $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
3318: my $thistitle = $res->title();
3319: $path .= '&'.
3320: &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
3321: &Apache::lonhtmlcommon::entity_encode($thistitle).
3322: ':'.$res->randompick().
3323: ':'.$res->randomout().
3324: ':'.$res->encrypted().
3325: ':'.$res->randomorder();
3326: }
1.467 raeburn 3327: }
3328: }
1.472 raeburn 3329: $path .= '&'.&Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.467 raeburn 3330: &Apache::lonhtmlcommon::entity_encode($mapresobj->title()).
3331: ':'.$mapresobj->randompick().
3332: ':'.$mapresobj->randomout().
3333: ':'.$mapresobj->encrypted().
3334: ':'.$mapresobj->randomorder();
1.472 raeburn 3335: } else {
3336: my $maptitle = &Apache::lonnet::gettitle($mapurl);
3337: $path = '&default&...::::'.
3338: '&'.&Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
3339: &Apache::lonhtmlcommon::entity_encode($maptitle).'::::';
3340: }
3341: $path = 'default&'.
3342: &Apache::lonhtmlcommon::entity_encode('Main Course Documents').
3343: $path;
3344: if ($type eq 'sequence') {
3345: $env{'form.folderpath'}=$path;
3346: $env{'form.pagepath'}='';
3347: } else {
3348: $env{'form.pagepath'}=$path;
3349: $env{'form.folderpath'}='';
3350: }
3351: } elsif ($env{'form.supppath'} ne '') {
3352: $env{'form.folderpath'}=$env{'form.supppath'};
1.466 www 3353: }
1.472 raeburn 3354: } elsif ($env{'form.command'} eq 'editdocs') {
3355: $env{'form.folderpath'} = 'default&'.
3356: &Apache::lonhtmlcommon::entity_encode('Main Course Content');
3357: $env{'form.pagepath'}='';
3358: } elsif ($env{'form.command'} eq 'editsupp') {
3359: $env{'form.folderpath'} = 'default&'.
3360: &Apache::lonhtmlcommon::entity_encode('Supplemental Content');
3361: $env{'form.pagepath'}='';
1.464 www 3362: }
3363:
1.445 www 3364: # Where do we store these for when we come back?
3365: my $stored_folderpath='docs_folderpath';
3366: if ($supplementalflag) {
3367: $stored_folderpath='docs_sup_folderpath';
3368: }
1.464 www 3369:
1.329 droeschl 3370: # No folderpath, no pagepath, see if we have something stored
3371: if ((!$env{'form.folderpath'}) && (!$env{'form.pagepath'})) {
1.445 www 3372: &Apache::loncommon::restore_course_settings($stored_folderpath,
1.329 droeschl 3373: {'folderpath' => 'scalar'});
3374: }
1.446 www 3375:
3376: # If we are not allowed to make changes, all we can see are supplemental docs
1.409 raeburn 3377: if (!$allowed) {
1.446 www 3378: $env{'form.pagepath'}='';
3379: unless ($env{'form.folderpath'} =~ /^supplemental/) {
3380: $env{'form.folderpath'} = &supplemental_base();
1.409 raeburn 3381: }
3382: }
1.446 www 3383: # If we still not have a folderpath, see if we can resurrect at pagepath
1.409 raeburn 3384: if (!$env{'form.folderpath'} && $allowed) {
1.445 www 3385: &Apache::loncommon::restore_course_settings($stored_folderpath,
1.329 droeschl 3386: {'pagepath' => 'scalar'});
3387: }
1.446 www 3388: # Make the zeroth entry in supplemental docs page paths, so we can get to top level
1.329 droeschl 3389: if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
1.446 www 3390: $env{'form.folderpath'} = &supplemental_base()
3391: .'&'.
1.329 droeschl 3392: $env{'form.folderpath'};
3393: }
1.446 www 3394: # If after all of this, we still don't have any paths, make them
3395: unless (($env{'form.pagepath'}) || ($env{'form.folderpath'})) {
3396: if ($supplementalflag) {
3397: $env{'form.folderpath'}=&supplemental_base();
3398: } else {
3399: $env{'form.folderpath'}='default';
3400: }
1.472 raeburn 3401: }
1.446 www 3402:
1.445 www 3403: # Store this
1.484 raeburn 3404: unless ($toolsflag) {
3405: &Apache::loncommon::store_course_settings($stored_folderpath,
3406: {'pagepath' => 'scalar',
3407: 'folderpath' => 'scalar'});
3408: if ($env{'form.folderpath'}) {
3409: my (@folderpath)=split('&',$env{'form.folderpath'});
3410: $env{'form.foldername'}=&unescape(pop(@folderpath));
3411: $env{'form.folder'}=pop(@folderpath);
3412: $container='sequence';
3413: }
3414: if ($env{'form.pagepath'}) {
3415: my (@pagepath)=split('&',$env{'form.pagepath'});
3416: $env{'form.pagename'}=&unescape(pop(@pagepath));
3417: $env{'form.folder'}=pop(@pagepath);
3418: $container='page';
3419: $containertag = '<input type="hidden" name="pagepath" value="" />'.
3420: '<input type="hidden" name="pagesymb" value="" />';
3421: $uploadtag =
3422: '<input type="hidden" name="pagepath" value="'.&HTML::Entities::encode($env{'form.pagepath'},'<>&"').'" />'.
3423: '<input type="hidden" name="pagesymb" value="'.&HTML::Entities::encode($env{'form.pagesymb'},'<>&"').'" />'.
3424: '<input type="hidden" name="folderpath" value="" />';
3425: } else {
3426: my $folderpath=$env{'form.folderpath'};
3427: if (!$folderpath) {
3428: if ($env{'form.folder'} eq '' ||
3429: $env{'form.folder'} eq 'supplemental') {
3430: $folderpath='default&'.
3431: &escape(&mt('Main '.$crstype.' Documents'));
3432: }
3433: }
3434: $containertag = '<input type="hidden" name="folderpath" value="" />';
3435: $uploadtag = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
3436: }
3437: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
3438: $showdoc='/'.$1;
3439: }
3440: if ($showdoc) { # got called in sequence from course
3441: $allowed=0;
3442: } else {
3443: if ($allowed) {
3444: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
3445: $script=&Apache::lonratedt::editscript('simple');
1.433 raeburn 3446: }
3447: }
1.329 droeschl 3448: }
3449:
1.344 bisitz 3450: # get personal data
1.329 droeschl 3451: my $uname=$env{'user.name'};
3452: my $udom=$env{'user.domain'};
3453: my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));
3454:
3455: if ($allowed) {
1.484 raeburn 3456: if ($toolsflag) {
3457: $script .= &inject_data_js();
3458: my ($home,$other,%outhash)=&authorhosts();
3459: if (!$home && $other) {
3460: my @hosts;
3461: foreach my $aurole (keys(%outhash)) {
3462: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
3463: push(@hosts,$outhash{$aurole});
3464: }
3465: }
3466: $script .= &dump_switchserver_js(@hosts);
3467: }
1.458 raeburn 3468: } else {
1.484 raeburn 3469: my @tabids;
3470: if ($supplementalflag) {
3471: @tabids = ('002','ee2','ff2');
3472: } else {
3473: @tabids = ('aa1','bb1','cc1','ff1');
3474: unless ($env{'form.pagepath'}) {
3475: unshift(@tabids,'001');
3476: push(@tabids,('dd1','ee1'));
3477: }
1.458 raeburn 3478: }
1.484 raeburn 3479: my $tabidstr = join("','",@tabids);
3480: $script .= &editing_js($udom,$uname,$supplementalflag).
3481: &history_tab_js().
3482: &inject_data_js().
1.484.2.3 raeburn 3483: &Apache::lonhtmlcommon::resize_scrollbox_js('docs',$tabidstr);
1.484 raeburn 3484: $addentries = {
1.484.2.3 raeburn 3485: onload => "javascript:resize_scrollbox('contentscroll','1','1');",
1.484 raeburn 3486: };
1.458 raeburn 3487: }
1.484.2.7 raeburn 3488: if ($env{'docs.markedcopy_url'}) {
3489: $script .= &paste_popup_js();
3490: }
1.484.2.12 raeburn 3491: my $confirm_switch = &mt("Editing requires switching to the resource's home server.").'\n'.
3492: &mt('Switch server?');
1.329 droeschl 3493: }
3494: # -------------------------------------------------------------------- Body tag
1.369 bisitz 3495: $script = '<script type="text/javascript">'."\n"
1.372 bisitz 3496: .'// <![CDATA['."\n"
3497: .$script."\n"
3498: .'// ]]>'."\n"
3499: .'</script>'."\n";
1.385 bisitz 3500:
3501: # Breadcrumbs
3502: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.446 www 3503: unless ($showdoc) {
1.392 raeburn 3504: &Apache::lonhtmlcommon::add_breadcrumb({
1.446 www 3505: href=>"/adm/coursedocs",text=>"$crstype Contents"});
1.392 raeburn 3506:
1.446 www 3507: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script,
1.457 raeburn 3508: {'force_register' => $showdoc,
3509: 'add_entries' => $addentries,
3510: })
1.392 raeburn 3511: .&Apache::loncommon::help_open_menu('','',273,'RAT')
3512: .&Apache::lonhtmlcommon::breadcrumbs(
1.484 raeburn 3513: 'Editing '.$crstype.' Contents',
1.392 raeburn 3514: 'Docs_Adding_Course_Doc')
3515: );
1.446 www 3516: } else {
1.408 raeburn 3517: $r->print(&Apache::loncommon::start_page("$crstype documents",undef,
1.402 raeburn 3518: {'force_register' => $showdoc,}));
1.392 raeburn 3519: }
1.364 bisitz 3520:
1.329 droeschl 3521: my %allfiles = ();
3522: my %codebase = ();
1.440 raeburn 3523: my ($upload_result,$upload_output,$uploadphase);
1.329 droeschl 3524: if ($allowed) {
3525: if (($env{'form.uploaddoc.filename'}) &&
3526: ($env{'form.cmd'}=~/^upload_(\w+)/)) {
1.440 raeburn 3527: my $context = $1;
3528: # Process file upload - phase one - upload and parse primary file.
1.329 droeschl 3529: undef($hadchanges);
1.440 raeburn 3530: $uploadphase = &process_file_upload(\$upload_output,$coursenum,$coursedom,
3531: \%allfiles,\%codebase,$context);
1.329 droeschl 3532: if ($hadchanges) {
3533: &mark_hash_old();
3534: }
1.440 raeburn 3535: $r->print($upload_output);
3536: } elsif ($env{'form.phase'} eq 'upload_embedded') {
3537: # Process file upload - phase two - upload embedded objects
3538: $uploadphase = 'check_embedded';
3539: my $primaryurl = &HTML::Entities::encode($env{'form.primaryurl'},'<>&"');
3540: my $state = &embedded_form_elems($uploadphase,$primaryurl,
3541: $env{'form.newidx'});
3542: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
3543: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
3544: my ($destination,$dir_root) = &embedded_destination();
3545: my $url_root = '/uploaded/'.$docudom.'/'.$docuname;
3546: my $actionurl = '/adm/coursedocs';
3547: my ($result,$flag) =
3548: &Apache::loncommon::upload_embedded('coursedoc',$destination,
3549: $docuname,$docudom,$dir_root,$url_root,undef,undef,undef,$state,
3550: $actionurl);
3551: $r->print($result.&return_to_editor());
3552: } elsif ($env{'form.phase'} eq 'check_embedded') {
3553: # Process file upload - phase three - modify references in HTML file
3554: $uploadphase = 'modified_orightml';
3555: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
3556: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
3557: my ($destination,$dir_root) = &embedded_destination();
1.482 raeburn 3558: my $result =
3559: &Apache::loncommon::modify_html_refs('coursedoc',$destination,
3560: $docuname,$docudom,undef,
3561: $dir_root);
3562: $r->print($result.&return_to_editor());
1.476 raeburn 3563: } elsif ($env{'form.phase'} eq 'decompress_uploaded') {
3564: $uploadphase = 'decompress_phase_one';
3565: $r->print(&decompression_phase_one().
3566: &return_to_editor());
3567: } elsif ($env{'form.phase'} eq 'decompress_cleanup') {
3568: $uploadphase = 'decompress_phase_two';
3569: $r->print(&decompression_phase_two().
3570: &return_to_editor());
1.329 droeschl 3571: }
3572: }
3573:
1.484 raeburn 3574: if ($allowed && $toolsflag) {
3575: $r->print(&startContentScreen('tools'));
3576: $r->print(&generate_admin_menu($crstype));
3577: $r->print(&endContentScreen());
3578: } elsif ((!$showdoc) && (!$uploadphase)) {
1.329 droeschl 3579: # -----------------------------------------------------------------------------
3580: my %lt=&Apache::lonlocal::texthash(
1.408 raeburn 3581: 'uplm' => 'Upload a new main '.lc($crstype).' document',
3582: 'upls' => 'Upload a new supplemental '.lc($crstype).' document',
1.329 droeschl 3583: 'impp' => 'Import a document',
3584: 'copm' => 'All documents out of a published map into this folder',
1.484.2.12 raeburn 3585: 'upfi' => 'Upload File',
3586: 'upld' => 'Import Content',
1.329 droeschl 3587: 'srch' => 'Search',
3588: 'impo' => 'Import',
1.484.2.6 raeburn 3589: 'lnks' => 'Import from Stored Links',
1.484.2.13 raeburn 3590: 'impm' => 'Import from Assembled Map',
1.329 droeschl 3591: 'selm' => 'Select Map',
3592: 'load' => 'Load Map',
1.419 bisitz 3593: 'reco' => 'Recover Deleted Documents',
1.329 droeschl 3594: 'newf' => 'New Folder',
3595: 'newp' => 'New Composite Page',
3596: 'extr' => 'External Resource',
3597: 'syll' => 'Syllabus',
1.425 raeburn 3598: 'navc' => 'Table of Contents',
1.343 biermanm 3599: 'sipa' => 'Simple Course Page',
1.329 droeschl 3600: 'sipr' => 'Simple Problem',
3601: 'drbx' => 'Drop Box',
1.451 www 3602: 'scuf' => 'External Scores (handgrade, upload, clicker)',
1.336 schafran 3603: 'bull' => 'Discussion Board',
1.347 weissno 3604: 'mypi' => 'My Personal Information Page',
1.353 weissno 3605: 'grpo' => 'Group Portfolio',
1.329 droeschl 3606: 'rost' => 'Course Roster',
1.348 weissno 3607: 'abou' => 'Personal Information Page for a User',
1.377 bisitz 3608: 'imsf' => 'IMS Import',
3609: 'imsl' => 'Import IMS package',
1.484.2.12 raeburn 3610: 'cms' => 'Origin of IMS package',
1.329 droeschl 3611: 'file' => 'File',
1.484.2.12 raeburn 3612: 'se' => 'Select',
1.329 droeschl 3613: 'title' => 'Title',
3614: 'comment' => 'Comment',
1.484.2.12 raeburn 3615: 'url' => 'URL',
3616: 'prev' => 'Preview',
3617: 'lnk' => 'Add Link',
1.403 raeburn 3618: 'parse' => 'Upload embedded images/multimedia files if HTML file',
1.368 truskell 3619: 'nd' => 'Upload Document',
1.329 droeschl 3620: 'pm' => 'Published Map',
3621: 'sd' => 'Special Document',
3622: 'mo' => 'More Options',
3623: );
3624: # -----------------------------------------------------------------------------
3625: my $fileupload=(<<FIUP);
3626: $lt{'file'}:<br />
3627: <input type="file" name="uploaddoc" size="40" />
3628: FIUP
3629:
3630: my $checkbox=(<<CHBO);
3631: <!-- <label>$lt{'parse'}?
3632: <input type="checkbox" name="parserflag" />
3633: </label> -->
3634: <label>
3635: <input type="checkbox" name="parserflag" checked="checked" /> $lt{'parse'}
3636: </label>
3637: CHBO
1.484.2.12 raeburn 3638: my $imsfolder = $env{'form.folder'};
3639: if ($imsfolder eq '') {
3640: $imsfolder = 'default';
3641: }
3642: my $imspform=(<<IMSFORM);
3643: <a class="LC_menubuttons_link" href="javascript:toggleUpload('ims');">
3644: $lt{'imsf'}</a> $help{'Importing_IMS_Course'}
3645: <form name="uploadims" action="/adm/imsimportdocs" method="post" enctype="multipart/form-data" target="IMSimport">
3646: <fieldset id="uploadimsform" style="display: none;" />
3647: <legend>$lt{'imsf'}</legend>
3648: $fileupload
3649: <br />
3650: <p>
3651: $lt{'cms'}:
3652: <select name="source">
3653: <option value="-1" selected="selected">$lt{'se'}</option>
3654: <option value="bb5">Blackboard 5</option>
3655: <option value="bb6">Blackboard 6</option>
3656: <option value="angel5">ANGEL 5.5</option>
3657: <option value="webctce4">WebCT 4 Campus Edition</option>
3658: </select>
3659: <input type="hidden" name="folder" value="$imsfolder" />
3660: </p>
3661: <input type="hidden" name="phase" value="one" />
3662: <input type="button" value="$lt{'imsl'}" onclick="makeims(this.form);" />
3663: </fieldset>
3664: </form>
3665: IMSFORM
3666:
3667: my $fileuploadform=(<<FUFORM);
3668: <a class="LC_menubuttons_link" href="javascript:toggleUpload('doc');">
3669: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
3670: <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
3671: <fieldset id="uploaddocform" style="display: none;" />
3672: <legend>$lt{'upfi'}</legend>
1.371 tempelho 3673: <input type="hidden" name="active" value="aa" />
1.329 droeschl 3674: $fileupload
3675: <br />
3676: $lt{'title'}:<br />
1.458 raeburn 3677: <input type="text" size="60" name="comment" />
1.329 droeschl 3678: $uploadtag
3679: <input type="hidden" name="cmd" value="upload_default" />
3680: <br />
1.458 raeburn 3681: <span class="LC_nobreak" style="float:left">
1.329 droeschl 3682: $checkbox
3683: </span>
1.484.2.12 raeburn 3684: <br clear="all" />
3685: <input type="submit" value="$lt{'upld'}" />
3686: </fieldset>
3687: </form>
1.383 tempelho 3688: FUFORM
1.329 droeschl 3689:
1.484.2.13 raeburn 3690: my $importpubform=(<<SEDFFORM);
3691: <a class="LC_menubuttons_link" href="javascript:toggleMap();">
3692: $lt{'impm'}</a>$help{'Load_Map'}
3693: <form action="/adm/coursedocs" method="post" name="mapimportform">
3694: <fieldset id="importmapform" style="display: none;" />
3695: <legend>$lt{'impm'}</legend>
3696: <input type="hidden" name="active" value="bb" />
3697: $lt{'copm'}<br />
3698: <span class="LC_nobreak">
3699: <input type="text" name="importmap" size="40" value=""
3700: onfocus="this.blur();openbrowser('mapimportform','importmap','sequence,page','');" />
3701: <a href="javascript:openbrowser('mapimportform','importmap','sequence,page','');">$lt{'selm'}</a><br />
3702: <input type="submit" name="loadmap" value="$lt{'load'}" />
3703: </fieldset>
3704: </form>
3705:
1.383 tempelho 3706: SEDFFORM
1.484.2.13 raeburn 3707:
1.383 tempelho 3708: my @simpleeditdefaultforma = (
1.423 onken 3709: { '<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>" },
3710: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/res.png" alt="'.$lt{impo}.'" onclick="javascript:groupimport();"/>' => "<a class='LC_menubuttons_link' href='javascript:groupimport();'>$lt{'impo'}</a>$help{'Importing_LON-CAPA_Resource'}" },
1.484.2.5 raeburn 3711: { '<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.484.2.13 raeburn 3712: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/sequence.png" alt="'.$lt{impm}.'" onclick="javascript:toggleMap();" />' => $importpubform }
3713: );
3714: $importpubform = &create_form_ul(&create_list_elements(@importpubforma));
1.329 droeschl 3715:
1.442 www 3716: my $extresourcesform=(<<ERFORM);
1.484.2.12 raeburn 3717: <a class="LC_menubuttons_link" href="javascript:toggleUpload('ext');">$lt{'extr'}</a>$help{'Adding_External_Resource'}
1.442 www 3718: <form action="/adm/coursedocs" method="post" name="newext">
1.484.2.12 raeburn 3719: <fieldset id="uploadextform" style="display: none;" />
3720: <legend>$lt{'extr'}</legend>
3721: <input type="hidden" name="active" value="aa" />
3722: $lt{'url'}:<br />
3723: <input type="text" size="60" name="exturl" id="exturl" value="http://" />
3724: <input type="button" name="view" value="$lt{'prev'}" onclick="javascript:extUrlPreview('exturl');" /><br />
3725: $lt{'title'}:<br />
3726: <input type="text" size="60" name="exttitle" value="$lt{'extr'}" />
1.442 www 3727: $uploadtag
1.484.2.12 raeburn 3728: <br />
1.442 www 3729: <input type="hidden" name="importdetail" value="" />
1.484.2.12 raeburn 3730: <input type="button" value="$lt{'lnk'}" onclick="javascript:setExternal(this.form,0)" />
3731: </fieldset>
1.442 www 3732: </form>
1.329 droeschl 3733: ERFORM
3734:
1.442 www 3735:
1.329 droeschl 3736: if ($allowed) {
1.484.2.7 raeburn 3737: my $folder = $env{'form.folder'};
3738: if ($folder eq '') {
3739: $folder='default';
3740: }
3741: &update_paste_buffer($coursenum,$coursedom,$folder);
1.337 ehlerst 3742: $r->print(<<HIDDENFORM);
3743: <form name="renameform" method="post" action="/adm/coursedocs">
3744: <input type="hidden" name="title" />
3745: <input type="hidden" name="cmd" />
3746: <input type="hidden" name="markcopy" />
3747: <input type="hidden" name="copyfolder" />
3748: $containertag
3749: </form>
1.484 raeburn 3750:
1.337 ehlerst 3751: HIDDENFORM
1.484 raeburn 3752: $r->print(&makesimpleeditform($uploadtag)."\n".
3753: &makedocslogform($uploadtag."\n".
3754: '<input type="hidden" name="folder" value="'.
3755: $env{'form.folder'}.'" />'."\n"));
1.329 droeschl 3756: }
1.442 www 3757:
3758: # Generate the tabs
1.472 raeburn 3759: my $mode;
3760: if (($supplementalflag) && (!$allowed)) {
3761: &Apache::lonnavdisplay::startContentScreen($r,'supplemental');
3762: } else {
1.484 raeburn 3763: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.472 raeburn 3764: }
1.443 www 3765:
1.442 www 3766: #
3767:
3768: my $savefolderpath;
3769:
1.395 raeburn 3770: if ($allowed) {
1.329 droeschl 3771: my $folder=$env{'form.folder'};
1.443 www 3772: if ($folder eq '' || $supplementalflag) {
1.329 droeschl 3773: $folder='default';
1.356 tempelho 3774: $savefolderpath = $env{'form.folderpath'};
1.442 www 3775: $env{'form.folderpath'}='default&'.&escape(&mt('Content'));
1.329 droeschl 3776: $uploadtag = '<input type="hidden" name="folderpath" value="'.
3777: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
3778: }
3779: my $postexec='';
3780: if ($folder eq 'default') {
1.372 bisitz 3781: $r->print('<script type="text/javascript">'."\n"
3782: .'// <![CDATA['."\n"
3783: .'this.window.name="loncapaclient";'."\n"
3784: .'// ]]>'."\n"
3785: .'</script>'."\n"
1.369 bisitz 3786: );
1.329 droeschl 3787: } else {
3788: #$postexec='self.close();';
3789: }
1.484.2.15 raeburn 3790: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.sequence';
1.329 droeschl 3791: '.sequence';
1.484.2.15 raeburn 3792: my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.page';
1.329 droeschl 3793: '.page';
3794: my $container='sequence';
3795: if ($env{'form.pagepath'}) {
3796: $container='page';
3797: }
3798: my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
3799:
3800: my $newnavform=(<<NNFORM);
3801: <form action="/adm/coursedocs" method="post" name="newnav">
1.371 tempelho 3802: <input type="hidden" name="active" value="cc" />
1.329 droeschl 3803: $uploadtag
3804: <input type="hidden" name="importdetail"
3805: value="$lt{'navc'}=/adm/navmaps" />
1.423 onken 3806: <a class="LC_menubuttons_link" href="javascript:document.newnav.submit()">$lt{'navc'}</a>
1.329 droeschl 3807: $help{'Navigate_Content'}
3808: </form>
3809: NNFORM
3810: my $newsmppageform=(<<NSPFORM);
3811: <form action="/adm/coursedocs" method="post" name="newsmppg">
1.371 tempelho 3812: <input type="hidden" name="active" value="cc" />
1.329 droeschl 3813: $uploadtag
3814: <input type="hidden" name="importdetail" value="" />
1.423 onken 3815: <a class="LC_menubuttons_link" href="javascript:makesmppage();"> $lt{'sipa'}</a>
1.383 tempelho 3816: $help{'Simple Page'}
1.329 droeschl 3817: </form>
3818: NSPFORM
3819:
3820: my $newsmpproblemform=(<<NSPROBFORM);
3821: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
1.371 tempelho 3822: <input type="hidden" name="active" value="cc" />
1.329 droeschl 3823: $uploadtag
3824: <input type="hidden" name="importdetail" value="" />
1.423 onken 3825: <a class="LC_menubuttons_link" href="javascript:makesmpproblem();">$lt{'sipr'}</a>
1.383 tempelho 3826: $help{'Simple Problem'}
1.329 droeschl 3827: </form>
3828:
3829: NSPROBFORM
3830:
3831: my $newdropboxform=(<<NDBFORM);
3832: <form action="/adm/coursedocs" method="post" name="newdropbox">
1.371 tempelho 3833: <input type="hidden" name="active" value="cc" />
1.344 bisitz 3834: $uploadtag
1.329 droeschl 3835: <input type="hidden" name="importdetail" value="" />
1.423 onken 3836: <a class="LC_menubuttons_link" href="javascript:makedropbox();">$lt{'drbx'}</a>
1.344 bisitz 3837: </form>
1.329 droeschl 3838: NDBFORM
3839:
3840: my $newexuploadform=(<<NEXUFORM);
3841: <form action="/adm/coursedocs" method="post" name="newexamupload">
1.371 tempelho 3842: <input type="hidden" name="active" value="cc" />
1.329 droeschl 3843: $uploadtag
3844: <input type="hidden" name="importdetail" value="" />
1.423 onken 3845: <a class="LC_menubuttons_link" href="javascript:makeexamupload();">$lt{'scuf'}</a>
1.329 droeschl 3846: $help{'Score_Upload_Form'}
3847: </form>
3848: NEXUFORM
3849:
3850: my $newbulform=(<<NBFORM);
3851: <form action="/adm/coursedocs" method="post" name="newbul">
1.371 tempelho 3852: <input type="hidden" name="active" value="cc" />
1.329 droeschl 3853: $uploadtag
3854: <input type="hidden" name="importdetail" value="" />
1.423 onken 3855: <a class="LC_menubuttons_link" href="javascript:makebulboard();" >$lt{'bull'}</a>
1.329 droeschl 3856: $help{'Bulletin Board'}
3857: </form>
3858: NBFORM
3859:
3860: my $newaboutmeform=(<<NAMFORM);
3861: <form action="/adm/coursedocs" method="post" name="newaboutme">
1.371 tempelho 3862: <input type="hidden" name="active" value="cc" />
1.329 droeschl 3863: $uploadtag
3864: <input type="hidden" name="importdetail"
3865: value="$plainname=/adm/$udom/$uname/aboutme" />
1.423 onken 3866: <a class="LC_menubuttons_link" href="javascript:document.newaboutme.submit()">$lt{'mypi'}</a>
1.347 weissno 3867: $help{'My Personal Information Page'}
1.329 droeschl 3868: </form>
3869: NAMFORM
3870:
3871: my $newaboutsomeoneform=(<<NASOFORM);
3872: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
1.371 tempelho 3873: <input type="hidden" name="active" value="cc" />
1.329 droeschl 3874: $uploadtag
3875: <input type="hidden" name="importdetail" value="" />
1.423 onken 3876: <a class="LC_menubuttons_link" href="javascript:makeabout();">$lt{'abou'}</a>
1.329 droeschl 3877: </form>
3878: NASOFORM
3879:
3880:
3881: my $newrosterform=(<<NROSTFORM);
3882: <form action="/adm/coursedocs" method="post" name="newroster">
1.371 tempelho 3883: <input type="hidden" name="active" value="cc" />
1.329 droeschl 3884: $uploadtag
3885: <input type="hidden" name="importdetail"
3886: value="$lt{'rost'}=/adm/viewclasslist" />
1.423 onken 3887: <a class="LC_menubuttons_link" href="javascript:document.newroster.submit()">$lt{'rost'}</a>
1.329 droeschl 3888: $help{'Course Roster'}
3889: </form>
3890: NROSTFORM
3891:
1.342 ehlerst 3892: my $specialdocumentsform;
1.383 tempelho 3893: my @specialdocumentsforma;
1.451 www 3894: my $gradingform;
3895: my @gradingforma;
3896: my $communityform;
3897: my @communityforma;
1.351 ehlerst 3898: my $newfolderform;
1.390 tempelho 3899: my $newfolderb;
1.342 ehlerst 3900:
1.451 www 3901: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.383 tempelho 3902:
1.329 droeschl 3903: my $newpageform=(<<NPFORM);
3904: <form action="/adm/coursedocs" method="post" name="newpage">
3905: <input type="hidden" name="folderpath" value="$path" />
3906: <input type="hidden" name="importdetail" value="" />
1.371 tempelho 3907: <input type="hidden" name="active" value="cc" />
1.423 onken 3908: <a class="LC_menubuttons_link" href="javascript:makenewpage(document.newpage,'$pageseq');">$lt{'newp'}</a>
1.383 tempelho 3909: $help{'Adding_Pages'}
1.329 droeschl 3910: </form>
3911: NPFORM
1.390 tempelho 3912:
3913:
1.351 ehlerst 3914: $newfolderform=(<<NFFORM);
1.329 droeschl 3915: <form action="/adm/coursedocs" method="post" name="newfolder">
3916: <input type="hidden" name="folderpath" value="$path" />
3917: <input type="hidden" name="importdetail" value="" />
1.371 tempelho 3918: <input type="hidden" name="active" value="aa" />
1.422 onken 3919: <a href="javascript:makenewfolder(document.newfolder,'$folderseq');">$lt{'newf'}</a>$help{'Adding_Folders'}
1.329 droeschl 3920: </form>
3921: NFFORM
3922:
3923: my $newsylform=(<<NSYLFORM);
3924: <form action="/adm/coursedocs" method="post" name="newsyl">
1.371 tempelho 3925: <input type="hidden" name="active" value="cc" />
1.329 droeschl 3926: $uploadtag
3927: <input type="hidden" name="importdetail"
3928: value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />
1.423 onken 3929: <a class="LC_menubuttons_link" href="javascript:document.newsyl.submit()">$lt{'syll'}</a>
1.329 droeschl 3930: $help{'Syllabus'}
1.383 tempelho 3931:
1.329 droeschl 3932: </form>
3933: NSYLFORM
1.364 bisitz 3934:
1.329 droeschl 3935: my $newgroupfileform=(<<NGFFORM);
3936: <form action="/adm/coursedocs" method="post" name="newgroupfiles">
1.371 tempelho 3937: <input type="hidden" name="active" value="cc" />
1.329 droeschl 3938: $uploadtag
3939: <input type="hidden" name="importdetail"
3940: value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
1.423 onken 3941: <a class="LC_menubuttons_link" href="javascript:document.newgroupfiles.submit()">$lt{'grpo'}</a>
1.353 weissno 3942: $help{'Group Portfolio'}
1.329 droeschl 3943: </form>
3944: NGFFORM
1.383 tempelho 3945: @specialdocumentsforma=(
1.421 onken 3946: {'<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 3947: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="document.newsyl.submit()" />'=>$newsylform},
1.451 www 3948: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/navigation.png" alt="'.$lt{navc}.'" onclick="document.newnav.submit()" />'=>$newnavform},
3949: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simple.png" alt="'.$lt{sipa}.'" onclick="javascript:makesmppage();" />'=>$newsmppageform},
3950: );
3951: $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma));
3952:
1.434 raeburn 3953:
1.484.2.12 raeburn 3954:
1.434 raeburn 3955: my @importdoc = (
1.484.2.12 raeburn 3956: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="toggleUpload(\'ext\');" />'=>$extresourcesform},
3957: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/ims.png" alt="'.$lt{imsf}.'" onclick="javascript:toggleUpload(\'ims\');" />'=>$imspform},
3958: {'<img class="LC_noBorder_LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'doc\');" />'=>$fileuploadform,
3959: });
3960: $fileuploadform = &create_form_ul(&create_list_elements(@importdoc));
1.434 raeburn 3961:
1.451 www 3962: @gradingforma=(
3963: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{sipr}.'" onclick="javascript:makesmpproblem();" />'=>$newsmpproblemform},
3964: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/dropbox.png" alt="'.$lt{drbx}.'" onclick="javascript:makedropbox();" />'=>$newdropboxform},
3965: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/scoreupfrm.png" alt="'.$lt{scuf}.'" onclick="javascript:makeexamupload();" />'=>$newexuploadform},
3966:
3967: );
3968: $gradingform = &create_form_ul(&create_list_elements(@gradingforma));
3969:
3970: @communityforma=(
3971: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/bchat.png" alt="'.$lt{bull}.'" onclick="javascript:makebulboard();" />'=>$newbulform},
3972: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makebulboard();" />'=>$newaboutmeform},
3973: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/aboutme.png" alt="'.$lt{abou}.'" onclick="javascript:makeabout();" />'=>$newaboutsomeoneform},
3974: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/clst.png" alt="'.$lt{rost}.'" onclick="document.newroster.submit()" />'=>$newrosterform},
3975: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/groupportfolio.png" alt="'.$lt{grpo}.'" onclick="document.newgroupfiles.submit()" />'=>$newgroupfileform},
3976: );
3977: $communityform = &create_form_ul(&create_list_elements(@communityforma));
1.383 tempelho 3978:
1.330 tempelho 3979: my %orderhash = (
1.484.2.7 raeburn 3980: 'aa' => ['Import Content',$fileuploadform],
1.484.2.13 raeburn 3981: 'bb' => ['Published Content',$importpubform],
1.451 www 3982: 'cc' => ['Grading Resources',$gradingform],
1.330 tempelho 3983: );
1.451 www 3984: unless ($env{'form.pagepath'}) {
1.434 raeburn 3985: $orderhash{'00'} = ['Newfolder',$newfolderform];
1.484 raeburn 3986: $orderhash{'dd'} = ['Collaboration',$communityform];
1.451 www 3987: $orderhash{'ee'} = ['Special Documents',$specialdocumentsform];
1.434 raeburn 3988: }
3989:
1.341 ehlerst 3990: $hadchanges=0;
1.484 raeburn 3991: unless (($supplementalflag || $toolsflag)) {
1.458 raeburn 3992: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.484.2.12 raeburn 3993: $supplementalflag,\%orderhash,$iconpath,$uploadtag);
1.443 www 3994: if ($error) {
3995: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
3996: }
3997: if ($hadchanges) {
3998: &mark_hash_old();
3999: }
1.341 ehlerst 4000:
1.443 www 4001: &changewarning($r,'');
4002: }
1.458 raeburn 4003: }
1.442 www 4004:
1.443 www 4005: # Supplemental documents start here
4006:
1.329 droeschl 4007: my $folder=$env{'form.folder'};
1.443 www 4008: unless ($supplementalflag) {
1.329 droeschl 4009: $folder='supplemental';
4010: }
4011: if ($folder =~ /^supplemental$/ &&
4012: (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
1.446 www 4013: $env{'form.folderpath'} = &supplemental_base();
1.393 raeburn 4014: } elsif ($allowed) {
1.356 tempelho 4015: $env{'form.folderpath'} = $savefolderpath;
1.329 droeschl 4016: }
1.362 ehlerst 4017: $env{'form.pagepath'} = '';
1.329 droeschl 4018: if ($allowed) {
4019: my $folderseq=
1.484.2.15 raeburn 4020: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_new.sequence';
1.329 droeschl 4021:
4022: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
4023:
4024: my $supupdocform=(<<SUPDOCFORM);
1.484.2.12 raeburn 4025: <a class="LC_menubuttons_link" href="javascript:toggleUpload('suppdoc');">
4026: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
1.383 tempelho 4027: <form action="/adm/coursedocs" method="post" name="supuploaddocument" enctype="multipart/form-data">
1.484.2.12 raeburn 4028: <fieldset id="uploadsuppdocform" style="display: none;" />
4029: <legend>$lt{'upfi'}</legend>
1.371 tempelho 4030: <input type="hidden" name="active" value="ee" />
1.329 droeschl 4031: $fileupload
4032: <br />
4033: <br />
4034: <span class="LC_nobreak">
4035: $checkbox
4036: </span>
4037: <br /><br />
4038: $lt{'comment'}:<br />
1.383 tempelho 4039: <textarea cols="50" rows="4" name="comment"></textarea>
1.329 droeschl 4040: <br />
4041: <input type="hidden" name="folderpath" value="$path" />
4042: <input type="hidden" name="cmd" value="upload_supplemental" />
1.484.2.12 raeburn 4043: <input type='submit' value="$lt{'upld'}" />
4044: </form>
1.329 droeschl 4045:
4046: my $supnewfolderform=(<<SNFFORM);
4047: <form action="/adm/coursedocs" method="post" name="supnewfolder">
1.371 tempelho 4048: <input type="hidden" name="active" value="ee" />
1.329 droeschl 4049: <input type="hidden" name="folderpath" value="$path" />
4050: <input type="hidden" name="importdetail" value="" />
1.423 onken 4051: <a class="LC_menubuttons_link" href="javascript:makenewfolder(document.supnewfolder,'$folderseq');">$lt{'newf'}</a>
1.383 tempelho 4052: $help{'Adding_Folders'}
1.329 droeschl 4053: </form>
4054: SNFFORM
1.383 tempelho 4055:
1.484.2.12 raeburn 4056: my $supextform=(<<ERFORM);
4057: <a class="LC_menubuttons_link" href="javascript:toggleUpload('suppext');">$lt{'extr'}</a>$help{'Adding_External_Resource'}
4058: <form action="/adm/coursedocs" method="post" name="newsuppext">
4059: <fieldset id="uploadsuppextform" style="display: none;" />
4060: <legend>$lt{'extr'}</legend>
4061: <input type="hidden" name="active" value="ee" />
4062: $lt{'url'}:<br />
4063: <input type="text" size="60" name="exturl" id="exturl" value="http://" />
4064: <input type="button" name="view" value="$lt{'prev'}" onclick="javascript:extUrlPreview('exturl');" /><br />
4065: $lt{'title'}:<br />
4066: <input type="text" size="60" name="exttitle" value="$lt{'extr'}" />
4067: $uploadtag
4068: <br />
4069: <input type="hidden" name="importdetail" value="" />
4070: <input type="button" value="$lt{'lnk'}" onclick="javascript:setExternal(this.form,0)" />
4071: </fieldset>
4072: </form>
4073: ERFORM
1.329 droeschl 4074:
4075: my $supnewsylform=(<<SNSFORM);
4076: <form action="/adm/coursedocs" method="post" name="supnewsyl">
1.371 tempelho 4077: <input type="hidden" name="active" value="ff" />
1.329 droeschl 4078: <input type="hidden" name="folderpath" value="$path" />
4079: <input type="hidden" name="importdetail"
4080: value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
1.423 onken 4081: <a class="LC_menubuttons_link" href="javascript:document.supnewsyl.submit()">$lt{'syll'}</a>
1.329 droeschl 4082: $help{'Syllabus'}
4083: </form>
4084: SNSFORM
4085:
4086: my $supnewaboutmeform=(<<SNAMFORM);
1.383 tempelho 4087: <form action="/adm/coursedocs" method="post" name="supnewaboutme">
1.371 tempelho 4088: <input type="hidden" name="active" value="ff" />
1.329 droeschl 4089: <input type="hidden" name="folderpath" value="$path" />
4090: <input type="hidden" name="importdetail"
4091: value="$plainname=/adm/$udom/$uname/aboutme" />
1.423 onken 4092: <a class="LC_menubuttons_link" href="javascript:document.supnewaboutme.submit()">$lt{'mypi'}</a>
1.347 weissno 4093: $help{'My Personal Information Page'}
1.329 droeschl 4094: </form>
4095: SNAMFORM
4096:
1.333 muellerd 4097:
1.383 tempelho 4098: my @specialdocs = (
1.417 droeschl 4099: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="document.supnewsyl.submit()" />'
4100: =>$supnewsylform},
4101: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="document.supnewaboutme.submit()" />'
4102: =>$supnewaboutmeform},
1.383 tempelho 4103: );
1.417 droeschl 4104: my @supimportdoc = (
1.484.2.12 raeburn 4105: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="javascript:makenewext(\'supext\');" />'
4106: =>$supextform},
4107: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'suppdoc\');" />'
4108: =>$supupdocform},
1.417 droeschl 4109: );
1.484.2.12 raeburn 4110: $supupdocform = &create_form_ul(&create_list_elements(@supimportdoc));
1.333 muellerd 4111: my %suporderhash = (
1.390 tempelho 4112: '00' => ['Supnewfolder', $supnewfolderform],
1.484.2.7 raeburn 4113: 'ee' => ['Import Content',$supupdocform],
1.443 www 4114: 'ff' => ['Special Documents',&create_form_ul(&create_list_elements(@specialdocs))]
1.333 muellerd 4115: );
1.443 www 4116: if ($supplementalflag) {
1.458 raeburn 4117: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.484.2.12 raeburn 4118: $supplementalflag,\%suporderhash,$iconpath,$uploadtag);
1.443 www 4119: if ($error) {
4120: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
4121: }
1.393 raeburn 4122: }
1.443 www 4123: } elsif ($supplementalflag) {
1.458 raeburn 4124: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.484.2.12 raeburn 4125: $supplementalflag,'',$iconpath,$uploadtag);
1.393 raeburn 4126: if ($error) {
4127: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.383 tempelho 4128: }
1.393 raeburn 4129: }
1.389 tempelho 4130:
1.484 raeburn 4131: $r->print(&endContentScreen());
1.383 tempelho 4132:
1.329 droeschl 4133: if ($allowed) {
4134: $r->print('
4135: <form method="post" name="extimport" action="/adm/coursedocs">
4136: <input type="hidden" name="title" />
4137: <input type="hidden" name="url" />
4138: <input type="hidden" name="useform" />
4139: <input type="hidden" name="residx" />
4140: </form>');
4141: }
1.484 raeburn 4142: } elsif ($showdoc) {
1.329 droeschl 4143: # -------------------------------------------------------- This is showdoc mode
1.484 raeburn 4144: $r->print("<h1>".&mt('Uploaded Document').' - '.
1.484.2.10 raeburn 4145: &Apache::lonnet::gettitle($r->uri).'</h1><p class="LC_warning">'.
1.329 droeschl 4146: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><table>".
1.484 raeburn 4147: &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');
1.329 droeschl 4148: }
4149: }
4150: $r->print(&Apache::loncommon::end_page());
4151: return OK;
1.364 bisitz 4152: }
1.329 droeschl 4153:
1.440 raeburn 4154: sub embedded_form_elems {
4155: my ($phase,$primaryurl,$newidx) = @_;
4156: my $folderpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
4157: return <<STATE;
4158: <input type="hidden" name="folderpath" value="$folderpath" />
4159: <input type="hidden" name="cmd" value="upload_embedded" />
4160: <input type="hidden" name="newidx" value="$newidx" />
4161: <input type="hidden" name="phase" value="$phase" />
4162: <input type="hidden" name="primaryurl" value="$primaryurl" />
4163: STATE
4164: }
4165:
4166: sub embedded_destination {
4167: my $folder=$env{'form.folder'};
4168: my $destination = 'docs/';
4169: if ($folder =~ /^supplemental/) {
4170: $destination = 'supplemental/';
4171: }
4172: if (($folder eq 'default') || ($folder eq 'supplemental')) {
4173: $destination .= 'default/';
4174: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
4175: $destination .= $2.'/';
4176: }
4177: $destination .= $env{'form.newidx'};
4178: my $dir_root = '/userfiles';
4179: return ($destination,$dir_root);
4180: }
4181:
4182: sub return_to_editor {
4183: my $actionurl = '/adm/coursedocs';
4184: return '<p><form name="backtoeditor" method="post" action="'.$actionurl.'" />'."\n".
4185: '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" /></form>'."\n".
4186: '<a href="javascript:document.backtoeditor.submit();">'.&mt('Return to Editor').
4187: '</a></p>';
4188: }
4189:
1.476 raeburn 4190: sub decompression_info {
4191: my ($destination,$dir_root) = &embedded_destination();
4192: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
4193: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
4194: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
4195: my $container='sequence';
1.480 raeburn 4196: my ($pathitem,$hiddenelem);
4197: my @hiddens = ('newidx','comment','position');
1.476 raeburn 4198: if ($env{'form.pagepath'}) {
4199: $container='page';
1.480 raeburn 4200: $pathitem = 'pagepath';
1.476 raeburn 4201: } else {
1.480 raeburn 4202: $pathitem = 'folderpath';
1.476 raeburn 4203: }
1.480 raeburn 4204: unshift(@hiddens,$pathitem);
4205: foreach my $item (@hiddens) {
4206: if ($env{'form.'.$item}) {
4207: $hiddenelem .= '<input type="hidden" name="'.$item.'" value="'.
4208: $env{'form.'.$item}.'" />'."\n";
4209: }
1.477 raeburn 4210: }
1.476 raeburn 4211: return ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,
4212: $hiddenelem);
4213: }
4214:
4215: sub decompression_phase_one {
4216: my ($dir,$file,$warning,$error,$output);
4217: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
4218: &decompression_info();
1.484.2.7 raeburn 4219: if ($env{'form.archiveurl'} !~ m{^/uploaded/\Q$docudom/$docuname/\E(?:docs|supplemental)/(?:default|\d+).*/([^/]+)$}) {
1.476 raeburn 4220: $error = &mt('Archive file "[_1]" not in the expected location.',$env{'form.archiveurl'});
4221: } else {
4222: my $file = $1;
1.481 raeburn 4223: $output =
4224: &Apache::loncommon::process_decompression($docudom,$docuname,$file,
4225: $destination,$dir_root,
4226: $hiddenelem);
4227: if ($env{'form.autoextract_camtasia'}) {
4228: $output .= &remove_archive($docudom,$docuname,$container);
4229: }
1.476 raeburn 4230: }
4231: if ($error) {
4232: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
4233: $error.'</p>'."\n";
4234: }
4235: if ($warning) {
4236: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
4237: }
4238: return $output;
4239: }
4240:
4241: sub decompression_phase_two {
4242: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
4243: &decompression_info();
1.481 raeburn 4244: my $output;
1.480 raeburn 4245: if ($env{'form.archivedelete'}) {
1.481 raeburn 4246: $output = &remove_archive($docudom,$docuname,$container);
1.480 raeburn 4247: }
4248: $output .=
1.481 raeburn 4249: &Apache::loncommon::process_extracted_files('coursedocs',$docudom,$docuname,
1.476 raeburn 4250: $destination,$dir_root,$hiddenelem);
4251: return $output;
4252: }
4253:
1.480 raeburn 4254: sub remove_archive {
4255: my ($docudom,$docuname,$container) = @_;
4256: my $map = $env{'form.folder'}.'.'.$container;
1.481 raeburn 4257: my ($output,$delwarning,$delresult,$url);
1.480 raeburn 4258: my ($errtext,$fatal) = &mapread($docuname,$docudom,$map);
4259: if ($fatal) {
4260: if ($container eq 'page') {
4261: $delwarning = &mt('An error occurred retrieving the contents of the current page.');
4262: } else {
4263: $delwarning = &mt('An error occurred retrieving the contents of the current folder.');
4264: }
4265: $delwarning .= &mt('As a result the archive file has not been removed.');
4266: } else {
4267: my $currcmd = $env{'form.cmd'};
4268: my $position = $env{'form.position'};
4269: if ($position > 0) {
4270: $env{'form.cmd'} = 'del_'.$position;
4271: my ($title,$url,@rrest) =
4272: split(/:/,$LONCAPA::map::resources[$LONCAPA::map::order[$position]]);
4273: if (&handle_edit_cmd($docuname,$docudom)) {
1.484.2.7 raeburn 4274: ($errtext,$fatal) = &storemap($docuname,$docudom,$map,1);
1.480 raeburn 4275: if ($fatal) {
4276: if ($container eq 'page') {
4277: $delwarning = &mt('An error occurred updating the contents of the current page.');
4278: } else {
4279: $delwarning = &mt('An error occurred updating the contents of the current folder.');
4280: }
4281: } else {
1.481 raeburn 4282: $delresult = &mt('Archive file removed.');
1.480 raeburn 4283: }
4284: }
4285: }
4286: $env{'form.cmd'} = $currcmd;
4287: }
4288: if ($delwarning) {
4289: $output = '<p class="LC_warning">'.
4290: $delwarning.
4291: '</p>';
4292: }
4293: if ($delresult) {
4294: $output .= '<p class="LC_info">'.
4295: $delresult.
4296: '</p>';
4297: }
1.481 raeburn 4298: return $output;
1.480 raeburn 4299: }
4300:
1.484 raeburn 4301: sub generate_admin_menu {
4302: my ($crstype) = @_;
4303: my $lc_crstype = lc($crstype);
4304: my ($home,$other,%outhash)=&authorhosts();
4305: my %lt=&Apache::lonlocal::texthash (
4306: 'vc' => 'Verify Content',
4307: 'cv' => 'Check/Set Resource Versions',
4308: 'ls' => 'List Resource Identifiers',
4309: 'imse' => 'Export contents to IMS Archive',
4310: 'dcd' => "Dump $crstype Content to Authoring Space",
4311: );
4312: my ($candump,$dumpurl);
4313: if ($home + $other > 0) {
4314: $candump = 'F';
4315: if ($home) {
4316: $dumpurl = "javascript:injectData(document.courseverify,'dummy','dumpcourse','$lt{'dcd'}')";
4317: } else {
4318: my @hosts;
4319: foreach my $aurole (keys(%outhash)) {
4320: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
4321: push(@hosts,$outhash{$aurole});
4322: }
4323: }
4324: if (@hosts == 1) {
4325: my $switchto = '/adm/switchserver?otherserver='.$hosts[0].
4326: '&role='.
4327: &HTML::Entities::encode($env{'request.role'},'"<>&').'&origurl='.
4328: &HTML::Entities::encode('/adm/coursedocs?dumpcourse=1','"<>&');
4329: $dumpurl = "javascript:dump_needs_switchserver('$switchto')";
4330: } else {
4331: $dumpurl = "javascript:choose_switchserver_window()";
4332: }
4333: }
4334: }
4335: my @menu=
4336: ({ categorytitle=>'Administration',
4337: items =>[
4338: { linktext => $lt{'vc'},
4339: url => "javascript:injectData(document.courseverify,'dummy','verify','$lt{'vc'}')",
4340: permission => 'F',
4341: help => 'Verify_Content',
4342: icon => 'verify.png',
4343: linktitle => 'Verify contents can be retrieved/rendered',
4344: },
4345: { linktext => $lt{'cv'},
4346: url => "javascript:injectData(document.courseverify,'dummy','versions','$lt{'cv'}')",
4347: permission => 'F',
4348: help => 'Check_Resource_Versions',
4349: icon => 'resversion.png',
4350: linktitle => "View version information for resources in your $lc_crstype, and fix/unfix use of specific versions",
4351: },
4352: { linktext => $lt{'ls'},
4353: url => "javascript:injectData(document.courseverify,'dummy','listsymbs','$lt{'ls'}')",
4354: permission => 'F',
4355: #help => '',
4356: icon => 'symbs.png',
4357: linktitle => "List the unique identifier used for each resource instance in your $lc_crstype"
4358: },
4359: ]
4360: },
4361: { categorytitle=>'Export',
4362: items =>[
4363: { linktext => $lt{'imse'},
4364: url => "javascript:injectData(document.courseverify,'dummy','exportcourse','$lt{'imse'}')",
4365: permission => 'F',
4366: help => 'Docs_Export_Course_Docs',
4367: icon => 'imsexport.png',
4368: linktitle => $lt{'imse'},
4369: },
4370: { linktext => $lt{'dcd'},
4371: url => $dumpurl,
4372: permission => $candump,
4373: #help => '',
4374: icon => 'dump.png',
4375: linktitle => $lt{'dcd'},
4376: },
4377: ]
4378: });
4379: return '<form action="/adm/coursedocs" method="post" name="courseverify">'."\n".
4380: '<input type="hidden" id="dummy" />'."\n".
4381: &Apache::lonhtmlcommon::generate_menu(@menu)."\n".
4382: '</form>';
1.329 droeschl 4383: }
4384:
4385: sub generate_edit_table {
1.484 raeburn 4386: my ($tid,$orderhash_ref,$to_show,$iconpath,$jumpto,$readfile) = @_;
1.406 raeburn 4387: return unless(ref($orderhash_ref) eq 'HASH');
1.342 ehlerst 4388: my %orderhash = %{$orderhash_ref};
1.344 bisitz 4389: my $form;
1.371 tempelho 4390: my $activetab;
4391: my $active;
4392: if($env{'form.active'} ne ''){
4393: $activetab = $env{'form.active'};
4394: }
1.472 raeburn 4395: my $backicon = $iconpath.'clickhere.gif';
1.481 raeburn 4396: my $backtext = &mt('To Overview');
1.458 raeburn 4397: $form = '<div class="LC_Box" style="margin:0;">'.
1.484 raeburn 4398: '<ul id="navigation'.$tid.'" class="LC_TabContent">'."\n".
1.472 raeburn 4399: '<li class="goback">'.
4400: '<a href="javascript:toContents('."'$jumpto'".');">'.
1.473 raeburn 4401: '<img src="'.$backicon.'" class="LC_icon" style="border: none; vertical-align: top;"'.
1.484.2.7 raeburn 4402: ' alt="'.$backtext.'" />'.$backtext.'</a></li>'."\n".
4403: '<li>'.
4404: '<a href="javascript:groupopen('."'$readfile'".',1);">'.
4405: &mt('Undo Delete').'</a></li>'."\n";
4406: if ($env{'form.docslog'}) {
4407: $form .= '<li class="active">';
4408: } else {
4409: $form .= '<li>';
4410: }
4411: $form .= '<a href="javascript:toggleHistoryDisp(1);">'.
4412: &mt('History').'</a></li>'."\n";
4413: if ($env{'form.docslog'}) {
4414: $form .= '<li><a href="javascript:toggleHistoryDisp(0);">'.
4415: &mt('Edit').'</a></li>'."\n";
1.484 raeburn 4416: }
1.458 raeburn 4417: foreach my $name (reverse(sort(keys(%orderhash)))) {
1.390 tempelho 4418: if($name ne '00'){
1.371 tempelho 4419: if($activetab eq '' || $activetab ne $name){
4420: $active = '';
4421: }elsif($activetab eq $name){
4422: $active = 'class="active"';
4423: }
1.458 raeburn 4424: $form .= '<li style="float:right" '.$active
1.484 raeburn 4425: .' 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 4426: } else {
1.484 raeburn 4427: $form .= '<li '.$active.' style="float:right">'.${$orderhash{$name}}[1].'</li>'."\n";
1.390 tempelho 4428:
4429: }
1.329 droeschl 4430: }
1.484 raeburn 4431: $form .= '</ul>'."\n";
4432: $form .= '<div id="content'.$tid.'" style="padding: 0 0; margin: 0 0; overflow: hidden; clear:right">'."\n";
1.458 raeburn 4433:
4434: if ($to_show ne '') {
1.484 raeburn 4435: $form .= '<div style="padding:0;margin:0;float:left">'.$to_show.'</div>'."\n";
1.458 raeburn 4436: }
1.363 ehlerst 4437: foreach my $field (keys(%orderhash)){
1.390 tempelho 4438: if($field ne '00'){
1.422 onken 4439: if($activetab eq '' || $activetab ne $field){
1.458 raeburn 4440: $active = 'style="display: none;float:left"';
1.422 onken 4441: }elsif($activetab eq $field){
1.458 raeburn 4442: $active = 'style="display:block;float:left"';
1.422 onken 4443: }
4444: $form .= '<div id="'.$field.$tid.'"'
4445: .' class="LC_ContentBox" '.$active.'>'.${$orderhash{$field}}[1]
1.484 raeburn 4446: .'</div>'."\n";
1.363 ehlerst 4447: }
4448: }
1.484 raeburn 4449: unless ($env{'form.docslog'}) {
4450: $form .= '</div></div>'."\n";
4451: }
1.329 droeschl 4452: return $form;
4453: }
4454:
4455: sub editing_js {
1.472 raeburn 4456: my ($udom,$uname,$supplementalflag) = @_;
1.329 droeschl 4457: my $now = time();
4458: my %lt = &Apache::lonlocal::texthash(
4459: p_mnf => 'Name of New Folder',
4460: t_mnf => 'New Folder',
4461: p_mnp => 'Name of New Page',
4462: t_mnp => 'New Page',
1.451 www 4463: p_mxu => 'Title for the External Score',
1.349 biermanm 4464: p_msp => 'Name of Simple Course Page',
1.329 droeschl 4465: p_msb => 'Title for the Problem',
4466: p_mdb => 'Title for the Drop Box',
1.336 schafran 4467: p_mbb => 'Title for the Discussion Board',
1.348 weissno 4468: p_mab => "Enter user:domain for User's Personal Information Page",
1.352 bisitz 4469: p_mab2 => 'Personal Information Page of ',
1.329 droeschl 4470: p_mab_alrt1 => 'Not a valid user:domain',
4471: p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',
4472: p_chn => 'New Title',
4473: p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',
4474: p_rmr2a => 'Remove[_99]',
4475: p_rmr2b => '?[_99]',
4476: p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',
4477: p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',
4478: p_ctr2a => 'Cut[_98]',
1.478 raeburn 4479: p_ctr2b => '?[_98]',
4480: rpck => 'Enter number to pick (e.g., 3)',
1.484.2.12 raeburn 4481: imsfile => 'You must choose an IMS package for import',
4482: imscms => 'You must select which Course Management System was the source of the IMS package',
4483: invurl => 'Invalid URL',
4484: titbl => 'Title is blank',
1.329 droeschl 4485: );
4486:
1.433 raeburn 4487: my $crstype = &Apache::loncommon::course_type();
1.434 raeburn 4488: my $docs_folderpath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'},'<>&"');
4489: my $docs_pagepath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.pagepath'},'<>&"');
4490: my $main_container_page;
4491: if ($docs_folderpath eq '') {
4492: if ($docs_pagepath ne '') {
4493: $main_container_page = 1;
4494: }
4495: }
1.433 raeburn 4496: my $toplevelmain = 'default&Main%20'.$crstype.'%20Documents';
1.446 www 4497: my $toplevelsupp = &supplemental_base();
1.433 raeburn 4498:
1.472 raeburn 4499: my $backtourl = '/adm/navmaps';
4500: if ($supplementalflag) {
4501: $backtourl = '/adm/supplemental';
4502: }
4503:
1.484.2.12 raeburn 4504: my $fieldsets = "'ext','doc','ims'";
4505: if ($supplementalflag) {
4506: $fieldsets = "'suppext','suppdoc'";
4507: }
4508:
4509: my $urlregexp = <<'ENDREGEXP';
4510: /^([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
4511: ENDREGEXP
4512:
1.329 droeschl 4513: return <<ENDNEWSCRIPT;
4514: function makenewfolder(targetform,folderseq) {
4515: var foldername=prompt('$lt{"p_mnf"}','$lt{"t_mnf"}');
4516: if (foldername) {
4517: targetform.importdetail.value=escape(foldername)+"="+folderseq;
4518: targetform.submit();
4519: }
4520: }
4521:
4522: function makenewpage(targetform,folderseq) {
4523: var pagename=prompt('$lt{"p_mnp"}','$lt{"t_mnp"}');
4524: if (pagename) {
4525: targetform.importdetail.value=escape(pagename)+"="+folderseq;
4526: targetform.submit();
4527: }
4528: }
4529:
1.484.2.12 raeburn 4530: function editext(residx) {
4531: if (document.getElementById('uploadext'+residx)) {
4532: var curr = document.getElementById('uploadext'+residx).style.display;
4533: if (curr == 'none') {
4534: disp = 'block';
4535: } else {
4536: disp = 'none';
4537: }
4538: document.getElementById('uploadext'+residx).style.display=disp;
4539: }
4540: resize_scrollbox('contentscroll','1','1');
4541: return;
1.329 droeschl 4542: }
4543:
4544: function makeexamupload() {
4545: var title=prompt('$lt{"p_mxu"}');
1.344 bisitz 4546: if (title) {
1.329 droeschl 4547: this.document.forms.newexamupload.importdetail.value=
4548: escape(title)+'=/res/lib/templates/examupload.problem';
4549: this.document.forms.newexamupload.submit();
4550: }
4551: }
4552:
4553: function makesmppage() {
4554: var title=prompt('$lt{"p_msp"}');
1.344 bisitz 4555: if (title) {
1.329 droeschl 4556: this.document.forms.newsmppg.importdetail.value=
4557: escape(title)+'=/adm/$udom/$uname/$now/smppg';
4558: this.document.forms.newsmppg.submit();
4559: }
4560: }
4561:
4562: function makesmpproblem() {
4563: var title=prompt('$lt{"p_msb"}');
1.344 bisitz 4564: if (title) {
1.329 droeschl 4565: this.document.forms.newsmpproblem.importdetail.value=
4566: escape(title)+'=/res/lib/templates/simpleproblem.problem';
4567: this.document.forms.newsmpproblem.submit();
4568: }
4569: }
4570:
4571: function makedropbox() {
4572: var title=prompt('$lt{"p_mdb"}');
1.344 bisitz 4573: if (title) {
1.329 droeschl 4574: this.document.forms.newdropbox.importdetail.value=
4575: escape(title)+'=/res/lib/templates/DropBox.problem';
4576: this.document.forms.newdropbox.submit();
4577: }
4578: }
4579:
4580: function makebulboard() {
4581: var title=prompt('$lt{"p_mbb"}');
4582: if (title) {
4583: this.document.forms.newbul.importdetail.value=
4584: escape(title)+'=/adm/$udom/$uname/$now/bulletinboard';
4585: this.document.forms.newbul.submit();
4586: }
4587: }
4588:
4589: function makeabout() {
4590: var user=prompt("$lt{'p_mab'}");
4591: if (user) {
4592: var comp=new Array();
4593: comp=user.split(':');
4594: if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
4595: if ((comp[0]) && (comp[1])) {
4596: this.document.forms.newaboutsomeone.importdetail.value=
4597: '$lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
1.335 ehlerst 4598: this.document.forms.newaboutsomeone.submit();
4599: } else {
4600: alert("$lt{'p_mab_alrt1'}");
1.329 droeschl 4601: }
1.335 ehlerst 4602: } else {
4603: alert("$lt{'p_mab_alrt2'}");
4604: }
4605: }
1.329 droeschl 4606: }
4607:
1.484.2.13 raeburn 4608: function toggleUpload(caller) {
4609: var blocks = Array($fieldsets);
4610: for (var i=0; i<blocks.length; i++) {
4611: var disp = 'none';
4612: if (caller == blocks[i]) {
4613: var curr = document.getElementById('upload'+caller+'form').style.display;
4614: if (curr == 'none') {
4615: disp='block';
4616: }
4617: }
4618: document.getElementById('upload'+blocks[i]+'form').style.display=disp;
4619: }
4620: resize_scrollbox('contentscroll','1','1');
4621: return;
4622: }
4623:
4624: function toggleMap() {
4625: var disp = 'none';
4626: var curr = document.getElementById('importmapform').style.display;
4627: if (curr == 'none') {
4628: disp='block';
4629: }
4630: document.getElementById('importmapform').style.display=disp;
4631: resize_scrollbox('contentscroll','1','1');
4632: return;
4633: }
4634:
4635:
1.484.2.12 raeburn 4636: function extUrlPreview(caller) {
4637: if (document.getElementById(caller)) {
4638: var url = document.getElementById(caller).value;
4639: var regexp = $urlregexp;
4640: if (regexp.test(url)) {
4641: openMyModal(url,500,400,'yes');
4642: } else {
4643: alert("$lt{'invurl'}");
4644: }
4645: }
1.329 droeschl 4646: }
4647:
1.484.2.12 raeburn 4648: function makeims(imsform) {
4649: if ((imsform.uploaddoc.value == '') || (!imsform.uploaddoc.value)) {
4650: alert("$lt{'imsfile'}");
4651: return;
4652: }
4653: if (imsform.source.selectedIndex == 0) {
4654: alert("$lt{'imscms'}");
4655: return;
4656: }
4657: newWindow = window.open('', 'IMSimport',"HEIGHT=700,WIDTH=750,scrollbars=yes");
4658: imsform.submit();
4659: }
4660:
4661: function setExternal(extform,residx) {
4662: var title=extform.exttitle.value;
4663: if (!String.trim) {
4664: String.prototype.trim = function() {return this.replace(\/^\\s+|\\s+$\/g, "");}; }
4665: var url=extform.exturl.value;
4666: var regexp = $urlregexp;
4667: if (title == null || title.trim()=="") {
4668: alert("$lt{'titbl'}");
4669: extform.exttitle.focus();
4670: return;
4671: }
4672: if (regexp.test(url)) {
4673: url = escape(url);
4674: if (residx > 0) {
4675: eval("extform.importdetail.value=title+'='+url+'='+residx;extform.submit();");
4676: } else {
4677: eval("extform.importdetail.value=title+'='+url;extform.submit();");
4678: }
4679: } else {
4680: alert("$lt{'invurl'}");
4681: extform.exturl.focus();
4682: return;
4683: }
1.329 droeschl 4684: }
4685:
4686: function changename(folderpath,index,oldtitle,container,pagesymb) {
1.335 ehlerst 4687: var title=prompt('$lt{"p_chn"}',oldtitle);
4688: if (title) {
4689: this.document.forms.renameform.markcopy.value=-1;
4690: this.document.forms.renameform.title.value=title;
4691: this.document.forms.renameform.cmd.value='rename_'+index;
4692: if (container == 'sequence') {
4693: this.document.forms.renameform.folderpath.value=folderpath;
4694: }
4695: if (container == 'page') {
4696: this.document.forms.renameform.pagepath.value=folderpath;
4697: this.document.forms.renameform.pagesymb.value=pagesymb;
4698: }
4699: this.document.forms.renameform.submit();
4700: }
1.329 droeschl 4701: }
4702:
4703: function removeres(folderpath,index,oldtitle,container,pagesymb,skip_confirm) {
1.335 ehlerst 4704: if (skip_confirm || confirm('$lt{"p_rmr1"}\\n\\n$lt{"p_rmr2a"} "'+oldtitle+'" $lt{"p_rmr2b"}')) {
4705: this.document.forms.renameform.markcopy.value=-1;
4706: this.document.forms.renameform.cmd.value='del_'+index;
4707: if (container == 'sequence') {
4708: this.document.forms.renameform.folderpath.value=folderpath;
4709: }
4710: if (container == 'page') {
4711: this.document.forms.renameform.pagepath.value=folderpath;
4712: this.document.forms.renameform.pagesymb.value=pagesymb;
4713: }
4714: this.document.forms.renameform.submit();
4715: }
1.329 droeschl 4716: }
4717:
4718: function cutres(folderpath,index,oldtitle,container,pagesymb,folder,skip_confirm) {
1.335 ehlerst 4719: if (skip_confirm || confirm('$lt{"p_ctr1a"}\\n$lt{"p_ctr1b"}\\n\\n$lt{"p_ctr2a"} "'+oldtitle+'" $lt{"p_ctr2b"}')) {
4720: this.document.forms.renameform.cmd.value='cut_'+index;
4721: this.document.forms.renameform.markcopy.value=index;
4722: this.document.forms.renameform.copyfolder.value=folder+'.'+container;
4723: if (container == 'sequence') {
4724: this.document.forms.renameform.folderpath.value=folderpath;
4725: }
4726: if (container == 'page') {
4727: this.document.forms.renameform.pagepath.value=folderpath;
4728: this.document.forms.renameform.pagesymb.value=pagesymb;
4729: }
4730: this.document.forms.renameform.submit();
4731: }
1.329 droeschl 4732: }
4733:
4734: function markcopy(folderpath,index,oldtitle,container,pagesymb,folder) {
1.335 ehlerst 4735: this.document.forms.renameform.markcopy.value=index;
4736: this.document.forms.renameform.copyfolder.value=folder+'.'+container;
4737: if (container == 'sequence') {
4738: this.document.forms.renameform.folderpath.value=folderpath;
4739: }
4740: if (container == 'page') {
4741: this.document.forms.renameform.pagepath.value=folderpath;
4742: this.document.forms.renameform.pagesymb.value=pagesymb;
4743: }
4744: this.document.forms.renameform.submit();
1.329 droeschl 4745: }
4746:
1.478 raeburn 4747: function updatePick(targetform,index,caller) {
4748: var pickitem = document.getElementById('rpick_'+index);
4749: var picknumitem = document.getElementById('rpicknum_'+index);
4750: if (pickitem.checked) {
4751: var picknum=prompt('$lt{"rpck"}',picknumitem.value);
4752: if (picknum == '' || picknum == null) {
4753: if (caller == 'check') {
4754: pickitem.checked=false;
4755: return;
4756: }
4757: } else {
4758: picknum.toString();
4759: var regexdigit=/^\\d+\$/;
4760: if (regexdigit.test(picknum)) {
4761: picknumitem.value = picknum;
4762: targetform.changeparms.value='randompick';
4763: targetform.submit();
4764: } else {
4765: if (caller == 'check') {
4766: pickitem.checked=false;
4767: }
4768: return;
4769: }
4770: }
4771: } else {
4772: picknumitem.value = 0;
4773: targetform.changeparms.value='randompick';
4774: targetform.submit();
4775: }
4776: }
4777:
1.334 muellerd 4778: function unselectInactive(nav) {
1.335 ehlerst 4779: currentNav = document.getElementById(nav);
4780: currentLis = currentNav.getElementsByTagName('LI');
4781: for (i = 0; i < currentLis.length; i++) {
1.472 raeburn 4782: if (currentLis[i].className == 'goback') {
4783: currentLis[i].className = 'goback';
4784: } else {
4785: if (currentLis[i].className == 'right active' || currentLis[i].className == 'right') {
1.374 tempelho 4786: currentLis[i].className = 'right';
1.472 raeburn 4787: } else {
1.374 tempelho 4788: currentLis[i].className = 'i';
1.472 raeburn 4789: }
4790: }
1.335 ehlerst 4791: }
1.332 tempelho 4792: }
4793:
1.334 muellerd 4794: function hideAll(current, nav, data) {
1.335 ehlerst 4795: unselectInactive(nav);
1.374 tempelho 4796: if(current.className == 'right'){
4797: current.className = 'right active'
4798: }else{
4799: current.className = 'active';
4800: }
1.335 ehlerst 4801: currentData = document.getElementById(data);
4802: currentDivs = currentData.getElementsByTagName('DIV');
4803: for (i = 0; i < currentDivs.length; i++) {
4804: if(currentDivs[i].className == 'LC_ContentBox'){
1.333 muellerd 4805: currentDivs[i].style.display = 'none';
1.330 tempelho 4806: }
4807: }
1.335 ehlerst 4808: }
1.330 tempelho 4809:
1.374 tempelho 4810: function openTabs(pageId) {
4811: tabnav = document.getElementById(pageId).getElementsByTagName('UL');
1.383 tempelho 4812: if(tabnav.length > 2 ){
1.389 tempelho 4813: currentNav = document.getElementById(tabnav[1].id);
1.374 tempelho 4814: currentLis = currentNav.getElementsByTagName('LI');
4815: for(i = 0; i< currentLis.length; i++){
4816: if(currentLis[i].className == 'active') {
1.375 tempelho 4817: funcString = currentLis[i].onclick.toString();
4818: tab = funcString.split('"');
1.420 onken 4819: if(tab.length < 2) {
4820: tab = funcString.split("'");
4821: }
1.375 tempelho 4822: currentData = document.getElementById(tab[1]);
4823: currentData.style.display = 'block';
1.374 tempelho 4824: }
4825: }
4826: }
4827: }
4828:
1.334 muellerd 4829: function showPage(current, pageId, nav, data) {
4830: hideAll(current, nav, data);
1.375 tempelho 4831: openTabs(pageId);
1.334 muellerd 4832: unselectInactive(nav);
1.330 tempelho 4833: current.className = 'active';
4834: currentData = document.getElementById(pageId);
4835: currentData.style.display = 'block';
1.458 raeburn 4836: activeTab = pageId;
1.484.2.12 raeburn 4837: toggleUpload();
1.484.2.14 raeburn 4838: toggleMap();
1.433 raeburn 4839: if (nav == 'mainnav') {
4840: var storedpath = "$docs_folderpath";
4841: if (storedpath == '') {
4842: storedpath = "$docs_pagepath";
4843: }
1.434 raeburn 4844: var storedpage = "$main_container_page";
1.433 raeburn 4845: var reg = new RegExp("^supplemental");
4846: if (pageId == 'mainCourseDocuments') {
1.434 raeburn 4847: if (storedpage == 1) {
4848: document.simpleedit.folderpath.value = '';
4849: document.uploaddocument.folderpath.value = '';
4850: } else {
4851: if (reg.test(storedpath)) {
4852: document.simpleedit.folderpath.value = '$toplevelmain';
4853: document.uploaddocument.folderpath.value = '$toplevelmain';
4854: document.newext.folderpath.value = '$toplevelmain';
4855: } else {
4856: document.simpleedit.folderpath.value = storedpath;
4857: document.uploaddocument.folderpath.value = storedpath;
4858: document.newext.folderpath.value = storedpath;
4859: }
1.433 raeburn 4860: }
4861: } else {
1.434 raeburn 4862: if (reg.test(storedpath)) {
4863: document.simpleedit.folderpath.value = storedpath;
4864: document.supuploaddocument.folderpath.value = storedpath;
4865: document.supnewext.folderpath.value = storedpath;
4866: } else {
1.433 raeburn 4867: document.simpleedit.folderpath.value = '$toplevelsupp';
4868: document.supuploaddocument.folderpath.value = '$toplevelsupp';
4869: document.supnewext.folderpath.value = '$toplevelsupp';
4870: }
4871: }
4872: }
1.484.2.3 raeburn 4873: resize_scrollbox('contentscroll','1','0');
1.330 tempelho 4874: return false;
4875: }
1.329 droeschl 4876:
1.472 raeburn 4877: function toContents(jumpto) {
4878: var newurl = '$backtourl';
4879: if (jumpto != '') {
4880: newurl = newurl+'?postdata='+jumpto;
4881: ;
4882: }
4883: location.href=newurl;
4884: }
4885:
1.329 droeschl 4886: ENDNEWSCRIPT
4887: }
1.457 raeburn 4888:
1.483 raeburn 4889: sub history_tab_js {
4890: return <<"ENDHIST";
4891: function toggleHistoryDisp(choice) {
4892: document.docslogform.docslog.value = choice;
4893: document.docslogform.submit();
4894: return;
4895: }
4896:
4897: ENDHIST
4898: }
4899:
1.484 raeburn 4900: sub inject_data_js {
4901: return <<ENDINJECT;
4902:
4903: function injectData(current, hiddenField, name, value) {
4904: currentElement = document.getElementById(hiddenField);
4905: currentElement.name = name;
4906: currentElement.value = value;
4907: current.submit();
4908: }
4909:
4910: ENDINJECT
4911: }
4912:
4913: sub dump_switchserver_js {
4914: my @hosts = @_;
4915: my %lt = &Apache::lonlocal::texthash(
4916: dump => 'Dumping to Authoring Space requires switching server.',
4917: swit => 'Switch server?',
4918: duco => 'Dump content to Authoring Space',
4919: yone => 'You need to switch to a server housing an Authoring Space for which you are author or co-author.',
4920: chos => 'Choose server',
4921: );
4922: my $role = $env{'request.role'};
4923: my $js = <<"ENDSWJS";
4924: <script type="text/javascript">
4925: function write_switchserver() {
4926: var server;
4927: if (document.setserver.posshosts.length > 0) {
4928: for (var i=0; i<document.setserver.posshosts.length; i++) {
4929: if (document.setserver.posshosts[i].checked) {
4930: server = document.setserver.posshosts[i].value;
4931: }
4932: }
4933: opener.document.location.href="/adm/switchserver?otherserver="+server+"&role=$role&origurl=/adm/coursedocs";
4934: }
4935: window.close();
4936: }
4937: </script>
4938:
4939: ENDSWJS
4940:
4941: my $startpage = &Apache::loncommon::start_page('Choose server',$js,
4942: {'only_body' => 1,
4943: 'js_ready' => 1,});
4944: my $endpage = &Apache::loncommon::end_page({'js_ready' => 1});
4945:
4946: my $hostpicker;
4947: my $count = 0;
4948: foreach my $host (sort(@hosts)) {
4949: my $checked;
4950: if ($count == 0) {
4951: $checked = ' checked="checked"';
4952: }
4953: $hostpicker .= '<label><input type="radio" name="posshosts" value="'.
4954: $host.'"'.$checked.' />'.$host.'</label> ';
4955: $count++;
4956: }
4957:
4958: return <<"ENDSWITCHJS";
4959:
4960: function dump_needs_switchserver(url) {
4961: if (url!='' && url!= null) {
4962: if (confirm("$lt{'dump'}\\n$lt{'swit'}")) {
4963: go(url);
4964: }
4965: }
4966: return;
4967: }
4968:
4969: function choose_switchserver_window() {
4970: newWindow = window.open('','ChooseServer','height=400,width=500,scrollbars=yes')
4971: newWindow.document.open();
4972: newWindow.document.writeln('$startpage');
4973: newWindow.document.write('<h3>$lt{'duco'}<\\/h3>\\n'+
4974: '<p>$lt{'yone'}<\\/p>\\n'+
4975: '<div class="LC_left_float"><fieldset><legend>$lt{'chos'}<\\/legend>\\n'+
4976: '<form name="setserver" method="post" action="" \\/>\\n'+
4977: '$hostpicker\\n'+
4978: '<br \\/><br \\/>\\n'+
4979: '<input type="button" name="makeswitch" value="$lt{'swit'}" '+
4980: 'onclick="write_switchserver();" \\/>\\n'+
4981: '<\\/form><\\/fieldset><\\/div><br clear="all" \\/>\\n');
4982: newWindow.document.writeln('$endpage');
4983: newWindow.document.close();
4984: newWindow.focus();
4985: }
4986:
4987: ENDSWITCHJS
4988: }
4989:
4990: sub makedocslogform {
4991: my ($formelems,$docslog) = @_;
4992: return <<"LOGSFORM";
4993: <form action="/adm/coursedocs" method="post" name="docslogform">
4994: <input type="hidden" name="docslog" value="$docslog" />
4995: $formelems
4996: </form>
4997: LOGSFORM
4998: }
4999:
5000: sub makesimpleeditform {
5001: my ($formelems) = @_;
5002: return <<"SIMPFORM";
5003: <form name="simpleedit" method="post" action="/adm/coursedocs">
5004: <input type="hidden" name="importdetail" value="" />
5005: $formelems
5006: </form>
5007: SIMPFORM
5008: }
5009:
1.329 droeschl 5010: 1;
5011: __END__
5012:
5013:
5014: =head1 NAME
5015:
5016: Apache::londocs.pm
5017:
5018: =head1 SYNOPSIS
5019:
5020: This is part of the LearningOnline Network with CAPA project
5021: described at http://www.lon-capa.org.
5022:
5023: =head1 SUBROUTINES
5024:
5025: =over
5026:
5027: =item %help=()
5028:
5029: Available help topics
5030:
5031: =item mapread()
5032:
1.344 bisitz 5033: Mapread read maps into LONCAPA::map:: global arrays
1.329 droeschl 5034: @order and @resources, determines status
5035: sets @order - pointer to resources in right order
5036: sets @resources - array with the resources with correct idx
5037:
5038: =item authorhosts()
5039:
5040: Return hash with valid author names
5041:
5042: =item clean()
5043:
5044: =item dumpcourse()
5045:
5046: Actually dump course
5047:
5048: =item group_import()
5049:
5050: Imports the given (name, url) resources into the course
5051: coursenum, coursedom, and folder must precede the list
5052:
5053: =item breadcrumbs()
5054:
5055: =item log_docs()
5056:
5057: =item docs_change_log()
5058:
5059: =item update_paste_buffer()
5060:
5061: =item print_paste_buffer()
5062:
5063: =item do_paste_from_buffer()
5064:
1.484.2.7 raeburn 5065: =item get_newmap_url()
5066:
5067: =item dbcopy()
5068:
5069: =item uniqueness_check()
5070:
5071: =item contained_map_check()
5072:
5073: =item reinit_role()
5074:
5075: =item url_paste_fixups()
5076:
5077: =item apply_fixups()
5078:
5079: =item copy_dependencies()
5080:
1.329 droeschl 5081: =item update_parameter()
5082:
5083: =item handle_edit_cmd()
5084:
5085: =item editor()
5086:
5087: =item process_file_upload()
5088:
5089: =item process_secondary_uploads()
5090:
5091: =item is_supplemental_title()
5092:
5093: =item entryline()
5094:
5095: =item tiehash()
5096:
5097: =item untiehash()
5098:
5099: =item checkonthis()
5100:
5101: check on this
5102:
5103: =item verifycontent()
5104:
5105: Verify Content
5106:
5107: =item devalidateversioncache() & checkversions()
5108:
5109: Check Versions
5110:
5111: =item mark_hash_old()
5112:
5113: =item is_hash_old()
5114:
5115: =item changewarning()
5116:
5117: =item init_breadcrumbs()
5118:
5119: Breadcrumbs for special functions
5120:
1.484 raeburn 5121: =item create_list_elements()
5122:
5123: =item create_form_ul()
5124:
5125: =item startContentScreen()
5126:
5127: =item endContentScreen()
5128:
5129: =item supplemental_base()
5130:
5131: =item embedded_form_elems()
5132:
5133: =item embedded_destination()
5134:
5135: =item return_to_editor()
5136:
5137: =item decompression_info()
5138:
5139: =item decompression_phase_one()
5140:
5141: =item decompression_phase_two()
5142:
5143: =item remove_archive()
5144:
5145: =item generate_admin_menu()
5146:
5147: =item generate_edit_table()
5148:
5149: =item editing_js()
5150:
5151: =item history_tab_js()
5152:
5153: =item inject_data_js()
5154:
5155: =item dump_switchserver_js()
5156:
1.484.2.3 raeburn 5157: =item resize_scrollbox_js()
1.484 raeburn 5158:
5159: =item makedocslogform()
5160:
1.484.2.3 raeburn 5161: =item makesimpleeditform()
5162:
1.329 droeschl 5163: =back
5164:
5165: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>