Annotation of loncom/interface/londocs.pm, revision 1.567
1.329 droeschl 1: # The LearningOnline Network
2: # Documents
3: #
1.567 ! raeburn 4: # $Id: londocs.pm,v 1.566 2013/10/06 20:33:45 raeburn Exp $
1.329 droeschl 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28:
29: package Apache::londocs;
30:
31: use strict;
32: use Apache::Constants qw(:common :http);
33: use Apache::imsexport;
34: use Apache::lonnet;
35: use Apache::loncommon;
1.383 tempelho 36: use Apache::lonhtmlcommon;
1.329 droeschl 37: use LONCAPA::map();
38: use Apache::lonratedt();
39: use Apache::lonxml;
40: use Apache::lonclonecourse;
41: use Apache::lonnavmaps;
1.472 raeburn 42: use Apache::lonnavdisplay();
1.510 raeburn 43: use Apache::lonextresedit();
1.567 ! raeburn 44: use Apache::lontemplate();
! 45: use Apache::lonsimplepage();
1.329 droeschl 46: use HTML::Entities;
1.488 raeburn 47: use HTML::TokeParser;
1.329 droeschl 48: use GDBM_File;
49: use Apache::lonlocal;
50: use Cwd;
51: use LONCAPA qw(:DEFAULT :match);
52:
53: my $iconpath;
54:
55: my %hash;
56:
57: my $hashtied;
58: my %alreadyseen=();
59:
60: my $hadchanges;
1.557 raeburn 61: my $suppchanges;
1.329 droeschl 62:
63:
64: my %help=();
65:
66:
67: sub mapread {
68: my ($coursenum,$coursedom,$map)=@_;
69: return
70: &LONCAPA::map::mapread('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
71: $map);
72: }
73:
74: sub storemap {
1.492 raeburn 75: my ($coursenum,$coursedom,$map,$contentchg)=@_;
76: my $report;
77: if (($contentchg) && ($map =~ /^default/)) {
78: $report = 1;
79: }
1.329 droeschl 80: my ($outtext,$errtext)=
81: &LONCAPA::map::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
1.492 raeburn 82: $map,1,$report);
1.329 droeschl 83: if ($errtext) { return ($errtext,2); }
1.364 bisitz 84:
1.557 raeburn 85: if ($map =~ /^default/) {
86: $hadchanges=1;
87: } else {
88: $suppchanges=1;
89: }
1.329 droeschl 90: return ($errtext,0);
91: }
92:
93:
94:
95: sub authorhosts {
96: my %outhash=();
97: my $home=0;
98: my $other=0;
99: foreach my $key (keys(%env)) {
100: if ($key=~/^user\.role\.(au|ca)\.(.+)$/) {
101: my $role=$1;
102: my $realm=$2;
103: my ($start,$end)=split(/\./,$env{$key});
104: if (($start) && ($start>time)) { next; }
105: if (($end) && (time>$end)) { next; }
106: my ($ca,$cd);
107: if ($1 eq 'au') {
108: $ca=$env{'user.name'};
109: $cd=$env{'user.domain'};
110: } else {
111: ($cd,$ca)=($realm=~/^\/($match_domain)\/($match_username)$/);
112: }
113: my $allowed=0;
114: my $myhome=&Apache::lonnet::homeserver($ca,$cd);
115: my @ids=&Apache::lonnet::current_machine_ids();
1.484 raeburn 116: foreach my $id (@ids) {
117: if ($id eq $myhome) {
118: $allowed=1;
119: last;
120: }
121: }
1.329 droeschl 122: if ($allowed) {
123: $home++;
1.484 raeburn 124: $outhash{'home_'.$ca.':'.$cd}=1;
1.329 droeschl 125: } else {
1.484 raeburn 126: $outhash{'otherhome_'.$ca.':'.$cd}=$myhome;
1.329 droeschl 127: $other++;
128: }
129: }
130: }
131: return ($home,$other,%outhash);
132: }
133:
134:
135: sub clean {
136: my ($title)=@_;
137: $title=~s/[^\w\/\!\$\%\^\*\-\_\=\+\;\:\,\\\|\`\~]+/\_/gs;
1.344 bisitz 138: return $title;
1.329 droeschl 139: }
140:
141:
142:
143: sub dumpcourse {
144: my ($r) = @_;
1.408 raeburn 145: my $crstype = &Apache::loncommon::course_type();
1.567 ! raeburn 146: my ($starthash,$js);
! 147: unless (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
! 148: $js = <<"ENDJS";
! 149: <script type="text/javascript">
! 150: // <![CDATA[
! 151:
! 152: function hide_searching() {
! 153: if (document.getElementById('searching')) {
! 154: document.getElementById('searching').style.display = 'none';
! 155: }
! 156: return;
! 157: }
! 158:
! 159: // ]]>
! 160: </script>
! 161: ENDJS
! 162: $starthash = {
! 163: add_entries => {'onload' => "hide_searching();"},
! 164: };
! 165: }
! 166: $r->print(&Apache::loncommon::start_page('Dump '.$crstype.' Content to Authoring Space',$js,$starthash)."\n".
1.484 raeburn 167: &Apache::lonhtmlcommon::breadcrumbs('Dump '.$crstype.' Content to Authoring Space')."\n");
168: $r->print(&startContentScreen('tools'));
1.329 droeschl 169: my ($home,$other,%outhash)=&authorhosts();
1.484 raeburn 170: unless ($home) {
171: $r->print(&endContentScreen());
172: return '';
173: }
1.329 droeschl 174: my $origcrsid=$env{'request.course.id'};
175: my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
176: if (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
177: # Do the dumping
1.484 raeburn 178: unless ($outhash{'home_'.$env{'form.authorspace'}}) {
179: $r->print(&endContentScreen());
180: return '';
181: }
1.531 raeburn 182: my ($ca,$cd)=split(/\:/,$env{'form.authorspace'});
1.329 droeschl 183: $r->print('<h3>'.&mt('Copying Files').'</h3>');
184: my $title=$env{'form.authorfolder'};
185: $title=&clean($title);
1.567 ! raeburn 186: my ($navmap,$errormsg) =
! 187: &Apache::loncourserespicker::get_navmap_object($crstype,'dumpdocs');
! 188: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
! 189: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
! 190: my (%maps,%resources,%titles);
! 191: if (!ref($navmap)) {
! 192: $r->print($errormsg.
! 193: &endContentScreen());
! 194: return '';
! 195: } else {
! 196: &Apache::loncourserespicker::enumerate_course_contents($navmap,\%maps,\%resources,\%titles,
! 197: 'dumpdocs',$cdom,$cnum);
1.329 droeschl 198: }
1.567 ! raeburn 199: my @todump = &Apache::loncommon::get_env_multiple('form.archive');
! 200: my (%tocopy,%replacehash,%lookup,%deps,%display,%result,%depresult,%simpleproblems,%simplepages,
! 201: %newcontent,%has_simpleprobs);
! 202: foreach my $item (sort {$a <=> $b} (@todump)) {
! 203: my $name = $env{'form.namefor_'.$item};
! 204: if ($resources{$item}) {
! 205: my ($map,$id,$res) = &Apache::lonnet::decode_symb($resources{$item});
! 206: if ($res =~ m{^uploaded/$cdom/$cnum/\E((?:docs|supplemental)/.+)$}) {
! 207: $tocopy{$1} = $name;
! 208: $display{$item} = $1;
! 209: $lookup{$1} = $item;
! 210: } elsif ($res eq 'lib/templates/simpleproblem.problem') {
! 211: $simpleproblems{$item} = {
! 212: symb => $resources{$item},
! 213: name => $name,
! 214: };
! 215: $display{$item} = 'simpleproblem_'.$name;
! 216: if ($map =~ m{^\Quploaded/$cdom/$cnum/\E(.+)$}) {
! 217: $has_simpleprobs{$1}{$id} = $item;
! 218: }
! 219: } elsif ($res =~ m{^adm/$match_domain/$match_username/(\d+)/smppg}) {
! 220: my $marker = $1;
! 221: my $db_name = &Apache::lonsimplepage::get_db_name($res,$marker,$cdom,$cnum);
! 222: $simplepages{$item} = {
! 223: res => $res,
! 224: title => $titles{$item},
! 225: db => $db_name,
! 226: marker => $marker,
! 227: symb => $resources{$item},
! 228: name => $name,
! 229: };
! 230: $display{$item} = '/'.$res;
! 231: }
! 232: } elsif ($maps{$item}) {
! 233: if ($maps{$item} =~ m{^\Quploaded/$cdom/$cnum/\E((?:default|supplemental)_\d+\.(?:sequence|page))$}) {
! 234: $tocopy{$1} = $name;
! 235: $display{$item} = $1;
! 236: $lookup{$1} = $item;
! 237: }
! 238: } else {
! 239: next;
! 240: }
! 241: }
1.329 droeschl 242: my $crs='/uploaded/'.$env{'request.course.id'}.'/';
243: $crs=~s/\_/\//g;
1.567 ! raeburn 244: my $mm = new File::MMagic;
! 245: my $prefix = "/uploaded/$cdom/$cnum/";
! 246: %replacehash = %tocopy;
! 247: foreach my $item (sort(keys(%simpleproblems))) {
! 248: my $content = &Apache::imsexport::simpleproblem($simpleproblems{$item}{'symb'});
! 249: $newcontent{$display{$item}} = $content;
! 250: }
! 251: my $gateway = Apache::lonhtmlgateway->new('web');
! 252: foreach my $item (sort(keys(%simplepages))) {
! 253: if (ref($simplepages{$item}) eq 'HASH') {
! 254: my $pagetitle = $simplepages{$item}{'title'};
! 255: my %fields = &Apache::lonnet::dump($simplepages{$item}{'db'},$cdom,$cnum);
! 256: my %contents;
! 257: foreach my $field (keys(%fields)) {
! 258: if ($field =~ /^(?:aaa|bbb|ccc)_(\w+)$/) {
! 259: my $name = $1;
! 260: my $msg = $fields{$field};
! 261: if ($name eq 'webreferences') {
! 262: if ($msg =~ m{^https?://}) {
! 263: $contents{$name} = '<a href="'.$msg.'"><tt>'.$msg.'</tt></a>';
! 264: }
! 265: } else {
! 266: $msg = &Encode::decode('utf8',$msg);
! 267: $msg = $gateway->process_outgoing_html($msg,1);
! 268: $contents{$name} = $msg;
! 269: }
! 270: } elsif ($field eq 'uploaded.photourl') {
! 271: my $marker = $simplepages{$item}{marker};
! 272: if ($fields{$field} =~ m{^\Q$prefix\E(simplepage/$marker/.+)$}) {
! 273: my $filepath = $1;
! 274: my ($relpath,$fname) = ($filepath =~ m{^(.+/)([^/]+)$});
! 275: if ($fname ne '') {
! 276: $fname=~s/\.(\w+)$//;
! 277: my $ext=$1;
! 278: $fname = &clean($fname);
! 279: $fname.='.'.$ext;
! 280: $contents{image} = '<img src="'.$relpath.$fname.'" alt="Image" />';
! 281: $replacehash{$filepath} = $relpath.$fname;
! 282: $deps{$item}{$filepath} = 1;
! 283: }
! 284: }
! 285: }
! 286: }
! 287: $replacehash{'/'.$simplepages{$item}{'res'}} = $simplepages{$item}{'name'};
! 288: $lookup{'/'.$simplepages{$item}{'res'}} = $item;
! 289: my $content = '
! 290: <html>
! 291: <head>
! 292: <title>'.$pagetitle.'</title>
! 293: </head>
! 294: <body bgcolor="#ffffff">';
! 295: if ($contents{title}) {
! 296: $content .= "\n".'<h2>'.$contents{title}.'</h2>';
! 297: }
! 298: if ($contents{image}) {
! 299: $content .= "\n".$contents{image};
! 300: }
! 301: if ($contents{content}) {
! 302: $content .= '
! 303: <div class="LC_Box">
! 304: <h4 class="LC_hcell">Content</h4>'.
! 305: $contents{content}.'
! 306: </div>';
! 307: }
! 308: if ($contents{webreferences}) {
! 309: $content .= '
! 310: <div class="LC_Box">
! 311: <h4 class="LC_hcell">Web References</h4>'.
! 312: $contents{webreferences}.'
! 313: </div>';
! 314: }
! 315: $content .= '
! 316: </body>
! 317: </html>
! 318: ';
! 319: $newcontent{'/'.$simplepages{$item}{res}} = $content;
! 320: }
! 321: }
! 322: foreach my $item (keys(%tocopy)) {
! 323: unless ($item=~/\.(sequence|page)$/) {
! 324: my $currurlpath = $prefix.$item;
! 325: my $currdirpath = &Apache::lonnet::filelocation('',$currurlpath);
! 326: &recurse_html($mm,$prefix,$currdirpath,$currurlpath,$item,$lookup{$item},\%replacehash,\%deps);
! 327: }
! 328: }
! 329: foreach my $num (sort {$a <=> $b} (@todump)) {
! 330: my $src = $display{$num};
! 331: next if ($src eq '');
! 332: my @needcopy = ();
! 333: if ($replacehash{$src}) {
! 334: push(@needcopy,$src);
! 335: if (ref($deps{$num}) eq 'HASH') {
! 336: foreach my $dep (sort(keys(%{$deps{$num}}))) {
! 337: if ($replacehash{$dep}) {
! 338: push(@needcopy,$dep);
! 339: }
! 340: }
! 341: }
! 342: } elsif ($src =~ /^simpleproblem_/) {
! 343: push(@needcopy,$src);
! 344: }
! 345: next if (@needcopy == 0);
! 346: my ($result,$depresult);
! 347: for (my $i=0; $i<@needcopy; $i++) {
! 348: my $item = $needcopy[$i];
! 349: my $newfilename;
! 350: if ($simpleproblems{$num}) {
! 351: $newfilename=$title.'/'.$simpleproblems{$num}{'name'};
! 352: } else {
! 353: $newfilename=$title.'/'.$replacehash{$item};
! 354: }
! 355: $newfilename=~s/\.(\w+)$//;
! 356: my $ext=$1;
! 357: $newfilename=&clean($newfilename);
! 358: $newfilename.='.'.$ext;
! 359: my ($newrelpath) = ($newfilename =~ m{^\Q$title/\E(.+)$});
! 360: if ($newrelpath ne $replacehash{$item}) {
! 361: $replacehash{$item} = $newrelpath;
! 362: }
! 363: my @dirs=split(/\//,$newfilename);
! 364: my $path=$r->dir_config('lonDocRoot')."/priv/$cd/$ca";
! 365: my $makepath=$path;
! 366: my $fail;
! 367: my $origin;
! 368: for (my $i=0;$i<$#dirs;$i++) {
! 369: $makepath.='/'.$dirs[$i];
! 370: unless (-e $makepath) {
! 371: unless(mkdir($makepath,0755)) {
! 372: $fail = &mt('Directory creation failed.');
! 373: }
! 374: }
! 375: }
! 376: if ($i == 0) {
! 377: $result = '<br /><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt>: ';
! 378: } else {
! 379: $depresult .= '<li><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt> '.
! 380: '<span class="LC_fontsize_small" style="font-weight: bold;">'.
! 381: &mt('(dependency)').'</span>: ';
! 382: }
! 383: if (-e $path.'/'.$newfilename) {
! 384: $fail = &mt('Destination already exists -- not overwriting.');
! 385: } else {
! 386: if (my $fh=Apache::File->new('>'.$path.'/'.$newfilename)) {
! 387: if (($item =~ m{^/adm/$match_domain/$match_username/\d+/smppg}) ||
! 388: ($item =~ /^simpleproblem_/)) {
! 389: print $fh $newcontent{$item};
! 390: } else {
! 391: my $fileloc = &Apache::lonnet::filelocation('',$prefix.$item);
! 392: if (-e $fileloc) {
! 393: if ($item=~/\.(sequence|page|html|htm|xml|xhtml)$/) {
! 394: if ((($1 eq 'sequence') || ($1 eq 'page')) &&
! 395: (ref($has_simpleprobs{$item}) eq 'HASH')) {
! 396: my %changes = %{$has_simpleprobs{$item}};
! 397: my $content = &Apache::lonclonecourse::rewritefile(
! 398: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
! 399: (%replacehash,$crs => '')
! 400: );
! 401: my $updatedcontent = '';
! 402: my $parser = HTML::TokeParser->new(\$content);
! 403: $parser->attr_encoded(1);
! 404: while (my $token = $parser->get_token) {
! 405: if ($token->[0] eq 'S') {
! 406: if (($token->[1] eq 'resource') &&
! 407: ($token->[2]->{'src'} eq '/res/lib/templates/simpleproblem.problem') &&
! 408: ($changes{$token->[2]->{'id'}})) {
! 409: my $id = $token->[2]->{'id'};
! 410: $updatedcontent .= '<'.$token->[1];
! 411: foreach my $attrib (@{$token->[3]}) {
! 412: next unless ($attrib =~ /^(src|type|title|id)$/);
! 413: if ($attrib eq 'src') {
! 414: my ($file) = ($display{$changes{$id}} =~ /^\Qsimpleproblem_\E(.+)$/);
! 415: if ($file) {
! 416: $updatedcontent .= ' '.$attrib.'="'.$file.'"';
! 417: } else {
! 418: $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"';
! 419: }
! 420: } else {
! 421: $updatedcontent .= ' '.$attrib.'="'.$token->[2]->{$attrib}.'"';
! 422: }
! 423: }
! 424: $updatedcontent .= ' />'."\n";
! 425: } else {
! 426: $updatedcontent .= $token->[4]."\n";
! 427: }
! 428: } else {
! 429: $updatedcontent .= $token->[2];
! 430: }
! 431: }
! 432: print $fh $updatedcontent;
! 433: } else {
! 434: print $fh &Apache::lonclonecourse::rewritefile(
! 435: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
! 436: (%replacehash,$crs => '')
! 437: );
! 438: }
! 439: } else {
! 440: print $fh
! 441: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item);
! 442: }
! 443: } else {
! 444: $fail = &mt('Source does not exist.');
! 445: }
! 446: }
! 447: $fh->close();
! 448: } else {
! 449: $fail = &mt('Could not write to destination.');
! 450: }
! 451: }
! 452: my $text;
! 453: if ($fail) {
! 454: $text = '<span class="LC_error">'.&mt('fail').(' 'x3).$fail.'</span>';
! 455: } else {
! 456: $text = '<span class="LC_success">'.&mt('ok').'</span>';
! 457: }
! 458: if ($i == 0) {
! 459: $result .= $text;
! 460: } else {
! 461: $depresult .= $text.'</li>';
! 462: }
! 463: }
! 464: $r->print($result);
! 465: if ($depresult) {
! 466: $r->print('<ul>'.$depresult.'</ul>');
! 467: }
! 468: }
! 469: } else {
! 470: my ($navmap,$errormsg) =
! 471: &Apache::loncourserespicker::get_navmap_object($crstype,'dumpdocs');
! 472: if (!ref($navmap)) {
! 473: $r->print($errormsg);
! 474: } else {
! 475: $r->print('<div id="searching">'.&mt('Searching ...').'</div>');
! 476: $r->rflush();
! 477: my ($preamble,$formname);
! 478: $formname = 'dumpdoc';
! 479: unless ($home==1) {
! 480: $preamble = '<div class="LC_left_float">'.
! 481: '<fieldset><legend>'.
! 482: &mt('Select the Authoring Space').
! 483: '</legend><select name="authorspace">';
1.329 droeschl 484: }
1.567 ! raeburn 485: my @orderspaces = ();
! 486: foreach my $key (sort(keys(%outhash))) {
! 487: if ($key=~/^home_(.+)$/) {
! 488: if ($1 eq $env{'user.name'}.':'.$env{'user.domain'}) {
! 489: unshift(@orderspaces,$1);
! 490: } else {
! 491: push(@orderspaces,$1);
! 492: }
! 493: }
! 494: }
! 495: foreach my $user (@orderspaces) {
1.329 droeschl 496: if ($home==1) {
1.567 ! raeburn 497: $preamble .= '<input type="hidden" name="authorspace" value="'.$user.'" />';
1.329 droeschl 498: } else {
1.567 ! raeburn 499: $preamble .= '<option value="'.$user.'">'.$user.' - '.
! 500: &Apache::loncommon::plainname(split(/\:/,$user)).'</option>';
! 501: }
1.329 droeschl 502: }
1.567 ! raeburn 503: unless ($home==1) {
! 504: $preamble .= '</select></fieldset></div>'."\n";
1.329 droeschl 505: }
1.567 ! raeburn 506: my $title=$origcrsdata{'description'};
! 507: $title=~s/[\/\s]+/\_/gs;
1.329 droeschl 508: $title=&clean($title);
1.567 ! raeburn 509: $preamble .= '<div class="LC_left_float">'.
! 510: '<fieldset><legend>'.&mt('Folder in Authoring Space').'</legend>'.
! 511: '<input type="text" size="50" name="authorfolder" value="'.
! 512: $title.'" />'.
! 513: '</fieldset></div><div style="padding:0;clear:both;margin:0;border:0"></div>'."\n";
! 514: my %uploadedfiles;
! 515: &tiehash();
! 516: foreach my $file (&Apache::lonclonecourse::crsdirlist($origcrsid,'userfiles')) {
! 517: my ($ext)=($file=~/\.(\w+)$/);
! 518: # FIXME Check supplemental here
! 519: my $title=$hash{'title_'.$hash{
! 520: 'ids_/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'.$file}};
! 521: if (!$title) {
! 522: $title=$file;
! 523: } else {
! 524: $title=~s|/|_|g;
! 525: }
! 526: $title=~s/\.(\w+)$//;
! 527: $title=&clean($title);
! 528: $title.='.'.$ext;
! 529: # $r->print("\n<td><input type='text' size='60' name='namefor_".$file."' value='".$title."' /></td>"
! 530: $uploadedfiles{$file} = $title;
! 531: }
! 532: &untiehash();
! 533: $r->print(&Apache::loncourserespicker::create_picker($navmap,'dumpdocs',$formname,$crstype,undef,
! 534: undef,undef,$preamble,$home,\%uploadedfiles));
! 535: }
1.329 droeschl 536: }
1.484 raeburn 537: $r->print(&endContentScreen());
1.329 droeschl 538: }
539:
1.567 ! raeburn 540: sub recurse_html {
! 541: my ($mm,$prefix,$currdirpath,$currurlpath,$container,$item,$replacehash,$deps) = @_;
! 542: return unless ((ref($replacehash) eq 'HASH') && (ref($deps) eq 'HASH'));
! 543: my (%allfiles,%codebase);
! 544: if (&Apache::lonnet::extract_embedded_items($currdirpath,\%allfiles,\%codebase) eq 'ok') {
! 545: if (keys(%allfiles)) {
! 546: foreach my $dependency (keys(%allfiles)) {
! 547: next if (($dependency =~ m{^/(res|adm)/}) || ($dependency =~ m{^https?://}));
! 548: my ($depurl,$relfile,$newcontainer);
! 549: if ($dependency =~ m{^/}) {
! 550: if ($dependency =~ m{^\Q$currurlpath/\E(.+)$}) {
! 551: $relfile = $1;
! 552: if ($dependency =~ m{^\Q$prefix\E(.+)$}) {
! 553: $newcontainer = $1;
! 554: next if ($replacehash->{$newcontainer});
! 555: }
! 556: $depurl = $dependency;
! 557: } else {
! 558: next;
! 559: }
! 560: } else {
! 561: $relfile = $dependency;
! 562: $depurl = $currurlpath;
! 563: $depurl =~ s{[^/]+$}{};
! 564: $depurl .= $dependency;
! 565: ($newcontainer) = ($depurl =~ m{^\Q$prefix\E(.+)$});
! 566: }
! 567: next if ($relfile eq '');
! 568: my $newname = $replacehash->{$container};
! 569: $newname =~ s{[^/]+$}{};
! 570: $replacehash->{$newcontainer} = $newname.$relfile;
! 571: $deps->{$item}{$newcontainer} = 1;
! 572: my ($newurlpath) = ($depurl =~ m{^(.*)/[^/]+$});
! 573: my $depfile = &Apache::lonnet::filelocation('',$depurl);
! 574: my $type = $mm->checktype_filename($depfile);
! 575: if ($type eq 'text/html') {
! 576: &recurse_html($mm,$prefix,$depfile,$newurlpath,$newcontainer,$item,$replacehash,$deps);
! 577: }
! 578: }
! 579: }
! 580: }
! 581: return;
! 582: }
! 583:
1.329 droeschl 584: sub group_import {
585: my ($coursenum, $coursedom, $folder, $container, $caller, @files) = @_;
1.529 raeburn 586: my ($donechk,$allmaps,%hierarchy,%titles,%addedmaps,%removefrommap,
587: %removeparam,$importuploaded,$fixuperrors);
588: $allmaps = {};
1.329 droeschl 589: while (@files) {
590: my ($name, $url, $residx) = @{ shift(@files) };
1.344 bisitz 591: if (($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$})
1.329 droeschl 592: && ($caller eq 'londocs')
593: && (!&Apache::lonnet::stat_file($url))) {
1.364 bisitz 594:
1.329 droeschl 595: my $errtext = '';
596: my $fatal = 0;
597: my $newmapstr = '<map>'."\n".
598: '<resource id="1" src="" type="start"></resource>'."\n".
599: '<link from="1" to="2" index="1"></link>'."\n".
600: '<resource id="2" src="" type="finish"></resource>'."\n".
601: '</map>';
602: $env{'form.output'}=$newmapstr;
603: my $result=&Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
604: 'output',$1.$2);
1.534 raeburn 605: if ($result !~ m{^/uploaded/}) {
1.329 droeschl 606: $errtext.='Map not saved: A network error occurred when trying to save the new map. ';
607: $fatal = 2;
608: }
609: if ($fatal) {
610: return ($errtext,$fatal);
611: }
612: }
613: if ($url) {
1.529 raeburn 614: if (($caller eq 'londocs') &&
615: ($folder =~ /^default/)) {
1.534 raeburn 616: if (($url =~ /\.(page|sequence)$/) && (!$donechk)) {
1.529 raeburn 617: my $chome = &Apache::lonnet::homeserver($coursenum,$coursedom);
618: my $cid = $coursedom.'_'.$coursenum;
619: $allmaps =
620: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
621: $chome,$cid);
622: $donechk = 1;
623: }
624: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$}) {
625: &contained_map_check($url,$folder,\%removefrommap,\%removeparam,
626: \%addedmaps,\%hierarchy,\%titles,$allmaps);
627: $importuploaded = 1;
628: } elsif ($url =~ m{^/res/.+\.(page|sequence)$}) {
629: next if ($allmaps->{$url});
630: }
631: }
1.344 bisitz 632: if (!$residx
1.329 droeschl 633: || defined($LONCAPA::map::zombies[$residx])) {
634: $residx = &LONCAPA::map::getresidx($url,$residx);
635: push(@LONCAPA::map::order, $residx);
636: }
637: my $ext = 'false';
638: if ($url=~m{^http://} || $url=~m{^https://}) { $ext = 'true'; }
639: $name = &LONCAPA::map::qtunescape($name);
1.534 raeburn 640: if ($name eq '') {
1.538 raeburn 641: $name = &LONCAPA::map::qtunescape(&mt('Web Page'));
1.534 raeburn 642: }
643: if ($url =~ m{^/uploaded/$coursedom/$coursenum/((?:docs|supplemental)/(?:default|\d+))/new\.html$}) {
644: my $filepath = $1;
645: my $fname = $name;
646: if ($fname =~ /^\W+$/) {
647: $fname = 'web';
648: } else {
649: $fname =~ s/\W/_/g;
650: }
651: if (length($fname > 15)) {
652: $fname = substr($fname,0,14);
653: }
654: my $initialtext = &mt('Replace with your own content.');
655: my $newhtml = <<END;
1.545 raeburn 656: <html>
1.534 raeburn 657: <head>
658: <title>$name</title>
659: </head>
660: <body bgcolor="#ffffff">
661: $initialtext
662: </body>
663: </html>
664: END
665: $env{'form.output'}=$newhtml;
666: my $result =
667: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
668: 'output',
669: "$filepath/$residx/$fname.html");
670: if ($result =~ m{^/uploaded/}) {
671: $url = $result;
672: if ($filepath =~ /^supplemental/) {
673: $name = time.'___&&&___'.$env{'user.name'}.'___&&&___'.
674: $env{'user.domain'}.'___&&&___'.$name;
675: }
676: } else {
677: return (&mt('Failed to save new web page.'),1);
678: }
679: }
1.538 raeburn 680: $url = &LONCAPA::map::qtunescape($url);
1.344 bisitz 681: $LONCAPA::map::resources[$residx] =
1.329 droeschl 682: join(':', ($name, $url, $ext, 'normal', 'res'));
683: }
684: }
1.529 raeburn 685: if ($importuploaded) {
686: my %import_errors;
687: my %updated = (
688: removefrommap => \%removefrommap,
689: removeparam => \%removeparam,
690: );
1.533 raeburn 691: my ($result,$msgsarray,$lockerror) =
692: &apply_fixups($folder,1,$coursedom,$coursenum,\%import_errors,\%updated);
1.529 raeburn 693: if (keys(%import_errors) > 0) {
1.530 raeburn 694: $fixuperrors =
1.529 raeburn 695: '<p span class="LC_warning">'."\n".
696: &mt('The following files are either dependencies of a web page or references within a folder and/or composite page for which errors occurred during import:')."\n".
697: '<ul>'."\n";
698: foreach my $key (sort(keys(%import_errors))) {
699: $fixuperrors .= '<li>'.$key.'</li>'."\n";
700: }
701: $fixuperrors .= '</ul></p>'."\n";
702: }
1.533 raeburn 703: if (ref($msgsarray) eq 'ARRAY') {
704: if (@{$msgsarray} > 0) {
705: $fixuperrors .= '<p class="LC_info">'.
706: join('<br />',@{$msgsarray}).
707: '</p>';
708: }
709: }
710: if ($lockerror) {
711: $fixuperrors .= '<p class="LC_error">'.
712: $lockerror.
713: '</p>';
714: }
1.529 raeburn 715: }
716: my ($errtext,$fatal) =
717: &storemap($coursenum, $coursedom, $folder.'.'.$container,1);
1.557 raeburn 718: unless ($fatal) {
719: if ($folder =~ /^supplemental/) {
720: &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1);
1.561 raeburn 721: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
722: $folder.'.'.$container);
1.557 raeburn 723: }
724: }
1.529 raeburn 725: return ($errtext,$fatal,$fixuperrors);
1.329 droeschl 726: }
727:
728: sub log_docs {
1.494 raeburn 729: return &Apache::lonnet::write_log('course','docslog',@_);
1.329 droeschl 730: }
731:
732: {
733: my @oldresources=();
734: my @oldorder=();
735: my $parmidx;
736: my %parmaction=();
737: my %parmvalue=();
738: my $changedflag;
739:
740: sub snapshotbefore {
741: @oldresources=@LONCAPA::map::resources;
742: @oldorder=@LONCAPA::map::order;
743: $parmidx=undef;
744: %parmaction=();
745: %parmvalue=();
746: $changedflag=0;
747: }
748:
749: sub remember_parms {
750: my ($idx,$parameter,$action,$value)=@_;
751: $parmidx=$idx;
752: $parmaction{$parameter}=$action;
753: $parmvalue{$parameter}=$value;
754: $changedflag=1;
755: }
756:
757: sub log_differences {
758: my ($plain)=@_;
759: my %storehash=('folder' => $plain,
760: 'currentfolder' => $env{'form.folder'});
761: if ($parmidx) {
762: $storehash{'parameter_res'}=$oldresources[$parmidx];
763: foreach my $parm (keys(%parmaction)) {
764: $storehash{'parameter_action_'.$parm}=$parmaction{$parm};
765: $storehash{'parameter_value_'.$parm}=$parmvalue{$parm};
766: }
767: }
768: my $maxidx=$#oldresources;
769: if ($#LONCAPA::map::resources>$#oldresources) {
770: $maxidx=$#LONCAPA::map::resources;
771: }
772: for (my $idx=0; $idx<=$maxidx; $idx++) {
773: if ($LONCAPA::map::resources[$idx] ne $oldresources[$idx]) {
774: $storehash{'before_resources_'.$idx}=$oldresources[$idx];
775: $storehash{'after_resources_'.$idx}=$LONCAPA::map::resources[$idx];
776: $changedflag=1;
777: }
778: if ($LONCAPA::map::order[$idx] ne $oldorder[$idx]) {
779: $storehash{'before_order_res_'.$idx}=$oldresources[$oldorder[$idx]];
780: $storehash{'after_order_res_'.$idx}=$LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
781: $changedflag=1;
782: }
783: }
784: $storehash{'maxidx'}=$maxidx;
785: if ($changedflag) { &log_docs(\%storehash); }
786: }
787: }
788:
789: sub docs_change_log {
1.484 raeburn 790: my ($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath)=@_;
1.486 raeburn 791: my $supplementalflag=($env{'form.folderpath'}=~/^supplemental/);
1.483 raeburn 792: my $js = '<script type="text/javascript">'."\n".
793: '// <![CDATA['."\n".
794: &Apache::loncommon::display_filter_js('docslog')."\n".
1.486 raeburn 795: &editing_js($env{'user.domain'},$env{'user.name'},$supplementalflag)."\n".
1.483 raeburn 796: &history_tab_js()."\n".
1.484 raeburn 797: &Apache::lonratedt::editscript('simple')."\n".
1.483 raeburn 798: '// ]]>'."\n".
799: '</script>'."\n";
1.484 raeburn 800: $r->print(&Apache::loncommon::start_page('Content Change Log',$js));
801: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Change Log'));
1.489 raeburn 802: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.484 raeburn 803: my %orderhash;
804: my $container='sequence';
805: my $pathitem;
1.519 raeburn 806: if ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 807: $container='page';
808: }
1.519 raeburn 809: my $folderpath=$env{'form.folderpath'};
810: if ($folderpath eq '') {
1.548 raeburn 811: $folderpath = 'default&'.&escape(&mt('Main Content').':::::');
1.519 raeburn 812: }
813: $pathitem = '<input type="hidden" name="folderpath" value="'.
814: &HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 815: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
816: my $jumpto = $readfile;
817: $jumpto =~ s{^/}{};
818: my $tid = 1;
1.489 raeburn 819: if ($supplementalflag) {
820: $tid = 2;
821: }
1.509 raeburn 822: my ($breadcrumbtrail) =
823: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
1.484 raeburn 824: $r->print($breadcrumbtrail.
825: &generate_edit_table($tid,\%orderhash,undef,$iconpath,$jumpto,
826: $readfile));
1.329 droeschl 827: my %docslog=&Apache::lonnet::dump('nohist_docslog',
828: $env{'course.'.$env{'request.course.id'}.'.domain'},
829: $env{'course.'.$env{'request.course.id'}.'.num'});
830:
831: if ((keys(%docslog))[0]=~/^error\:/) { undef(%docslog); }
832:
833: my %saveable_parameters = ('show' => 'scalar',);
834: &Apache::loncommon::store_course_settings('docs_log',
835: \%saveable_parameters);
836: &Apache::loncommon::restore_course_settings('docs_log',
837: \%saveable_parameters);
838: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.452 www 839: # FIXME: internationalization seems wrong here
1.329 droeschl 840: my %lt=('hiddenresource' => 'Resources hidden',
841: 'encrypturl' => 'URL hidden',
842: 'randompick' => 'Randomly pick',
843: 'randomorder' => 'Randomly ordered',
844: 'set' => 'set to',
845: 'del' => 'deleted');
1.484 raeburn 846: my $filter = &Apache::loncommon::display_filter('docslog')."\n".
847: $pathitem."\n".
848: '<input type="hidden" name="folder" value="'.$env{'form.folder'}.'" />'.
849: (' 'x2).'<input type="submit" value="'.&mt('Display').'" />';
850: $r->print('<div class="LC_left_float">'.
851: '<fieldset><legend>'.&mt('Display of Content Changes').'</legend>'."\n".
852: &makedocslogform($filter,1).
853: '</fieldset></div><br clear="all" />');
1.329 droeschl 854: $r->print(&Apache::loncommon::start_data_table().&Apache::loncommon::start_data_table_header_row().
855: '<th>'.&mt('Time').'</th><th>'.&mt('User').'</th><th>'.&mt('Folder').'</th><th>'.&mt('Before').'</th><th>'.
856: &mt('After').'</th>'.
857: &Apache::loncommon::end_data_table_header_row());
858: my $shown=0;
859: foreach my $id (sort { $docslog{$b}{'exe_time'}<=>$docslog{$a}{'exe_time'} } (keys(%docslog))) {
860: if ($env{'form.displayfilter'} eq 'currentfolder') {
861: if ($docslog{$id}{'logentry'}{'currentfolder'} ne $folder) { next; }
862: }
863: my @changes=keys(%{$docslog{$id}{'logentry'}});
864: if ($env{'form.displayfilter'} eq 'containing') {
865: my $wholeentry=$docslog{$id}{'exe_uname'}.':'.$docslog{$id}{'exe_udom'}.':'.
866: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},$docslog{$id}{'exe_udom'});
867: foreach my $key (@changes) {
868: $wholeentry.=':'.$docslog{$id}{'logentry'}{$key};
869: }
1.344 bisitz 870: if ($wholeentry!~/\Q$env{'form.containingphrase'}\E/i) { next; }
1.329 droeschl 871: }
872: my $count = 0;
873: my $time =
874: &Apache::lonlocal::locallocaltime($docslog{$id}{'exe_time'});
875: my $plainname =
876: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},
877: $docslog{$id}{'exe_udom'});
878: my $about_me_link =
879: &Apache::loncommon::aboutmewrapper($plainname,
880: $docslog{$id}{'exe_uname'},
881: $docslog{$id}{'exe_udom'});
882: my $send_msg_link='';
883: if ((($docslog{$id}{'exe_uname'} ne $env{'user.name'})
884: || ($docslog{$id}{'exe_udom'} ne $env{'user.domain'}))) {
885: $send_msg_link ='<br />'.
886: &Apache::loncommon::messagewrapper(&mt('Send message'),
887: $docslog{$id}{'exe_uname'},
888: $docslog{$id}{'exe_udom'});
889: }
890: $r->print(&Apache::loncommon::start_data_table_row());
891: $r->print('<td>'.$time.'</td>
892: <td>'.$about_me_link.
893: '<br /><tt>'.$docslog{$id}{'exe_uname'}.
894: ':'.$docslog{$id}{'exe_udom'}.'</tt>'.
895: $send_msg_link.'</td><td>'.
896: $docslog{$id}{'logentry'}{'folder'}.'</td><td>');
1.488 raeburn 897: my $is_supp = 0;
898: if ($docslog{$id}{'logentry'}{'currentfolder'} =~ /^supplemental/) {
899: $is_supp = 1;
900: }
1.329 droeschl 901: # Before
902: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
903: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
904: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
905: if ($oldname ne $newname) {
1.488 raeburn 906: my $shown = &LONCAPA::map::qtescape($oldname);
907: if ($is_supp) {
908: $shown = &Apache::loncommon::parse_supplemental_title($shown);
909: }
910: $r->print($shown);
1.329 droeschl 911: }
912: }
913: $r->print('<ul>');
914: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
915: if ($docslog{$id}{'logentry'}{'before_order_res_'.$idx}) {
1.488 raeburn 916: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'before_order_res_'.$idx}))[0]);
917: if ($is_supp) {
918: $shown = &Apache::loncommon::parse_supplemental_title($shown);
919: }
920: $r->print('<li>'.$shown.'</li>');
1.329 droeschl 921: }
922: }
923: $r->print('</ul>');
924: # After
925: $r->print('</td><td>');
926:
927: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
928: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
929: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
930: if ($oldname ne '' && $oldname ne $newname) {
1.488 raeburn 931: my $shown = &LONCAPA::map::qtescape($newname);
932: if ($is_supp) {
933: $shown = &Apache::loncommon::parse_supplemental_title(&LONCAPA::map::qtescape($newname));
934: }
935: $r->print($shown);
1.329 droeschl 936: }
1.364 bisitz 937: }
1.329 droeschl 938: $r->print('<ul>');
939: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
940: if ($docslog{$id}{'logentry'}{'after_order_res_'.$idx}) {
1.488 raeburn 941: my $shown = &LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'after_order_res_'.$idx}))[0]);
942: if ($is_supp) {
943: $shown = &Apache::loncommon::parse_supplemental_title($shown);
944: }
945: $r->print('<li>'.$shown.'</li>');
1.329 droeschl 946: }
947: }
948: $r->print('</ul>');
949: if ($docslog{$id}{'logentry'}{'parameter_res'}) {
950: $r->print(&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'parameter_res'}))[0]).':<ul>');
951: foreach my $parameter ('randompick','hiddenresource','encrypturl','randomorder') {
952: if ($docslog{$id}{'logentry'}{'parameter_action_'.$parameter}) {
1.452 www 953: # FIXME: internationalization seems wrong here
1.329 droeschl 954: $r->print('<li>'.
955: &mt($lt{$parameter}.' '.$lt{$docslog{$id}{'logentry'}{'parameter_action_'.$parameter}}.' [_1]',
956: $docslog{$id}{'logentry'}{'parameter_value_'.$parameter})
957: .'</li>');
958: }
959: }
960: $r->print('</ul>');
961: }
962: # End
963: $r->print('</td>'.&Apache::loncommon::end_data_table_row());
964: $shown++;
965: if (!($env{'form.show'} eq &mt('all')
966: || $shown<=$env{'form.show'})) { last; }
967: }
1.484 raeburn 968: $r->print(&Apache::loncommon::end_data_table()."\n".
969: &makesimpleeditform($pathitem)."\n".
970: '</div></div>');
971: $r->print(&endContentScreen());
1.329 droeschl 972: }
973:
974: sub update_paste_buffer {
1.492 raeburn 975: my ($coursenum,$coursedom,$folder) = @_;
1.538 raeburn 976: my (@possibles,%removals,%cuts);
977: if ($env{'form.multiremove'}) {
978: $env{'form.multiremove'} =~ s/,$//;
979: map { $removals{$_} = 1; } split(/,/,$env{'form.multiremove'});
980: }
981: if (($env{'form.multicopy'}) || ($env{'form.multicut'})) {
982: if ($env{'form.multicut'}) {
983: $env{'form.multicut'} =~ s/,$//;
984: foreach my $item (split(/,/,$env{'form.multicut'})) {
985: unless ($removals{$item}) {
986: $cuts{$item} = 1;
987: push(@possibles,$item.':cut');
988: }
989: }
990: }
991: if ($env{'form.multicopy'}) {
992: $env{'form.multicopy'} =~ s/,$//;
993: foreach my $item (split(/,/,$env{'form.multicopy'})) {
994: unless ($removals{$item} || $cuts{$item}) {
995: push(@possibles,$item.':copy');
996: }
997: }
998: }
999: } elsif ($env{'form.markcopy'}) {
1000: @possibles = split(/,/,$env{'form.markcopy'});
1001: }
1.329 droeschl 1002:
1.538 raeburn 1003: return if (@possibles == 0);
1.329 droeschl 1004: return if (!defined($env{'form.copyfolder'}));
1005:
1006: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
1007: $env{'form.copyfolder'});
1.538 raeburn 1008: return if ($fatal);
1009:
1010: my %curr_groups = &Apache::longroup::coursegroups();
1.364 bisitz 1011:
1.538 raeburn 1012: # Retrieve current paste buffer suffixes.
1013: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1014: my (%pasteurls,@newpaste);
1015:
1016: # Construct identifiers for current contents of user's paste buffer
1017: if (@currpaste) {
1018: foreach my $suffix (@currpaste) {
1019: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1020: my $url = $env{'docs.markedcopy_url_'.$suffix};
1021: if (($cid =~ /^$match_domain(?:_)$match_courseid$/) &&
1022: ($url ne '')) {
1.564 raeburn 1023: $pasteurls{$cid.'_'.$url} = 1;
1.538 raeburn 1024: }
1025: }
1026: }
1027:
1028: # Mark items for copying (skip any items already in user's paste buffer)
1029: my %addtoenv;
1030:
1031: foreach my $item (@possibles) {
1032: my ($orderidx,$cmd) = split(/:/,$item);
1033: next if ($orderidx =~ /\D/);
1034: next unless (($cmd eq 'cut') || ($cmd eq 'copy') || ($cmd eq 'remove'));
1035: my ($title,$url)=split(':',$LONCAPA::map::resources[$orderidx]);
1036: my %denied = &action_restrictions($coursenum,$coursedom,
1037: &LONCAPA::map::qtescape($url),
1038: $env{'form.folderpath'},\%curr_groups);
1039: next if ($denied{'copy'});
1040: $url=~s{http(:|:)//https(:|:)//}{https$2//};
1041: next if (exists($pasteurls{$coursedom.'_'.$coursenum.'_'.$url}));
1042: my ($suffix,$errortxt,$locknotfreed) =
1043: &new_timebased_suffix($env{'user.domain'},$env{'user.name'},'paste');
1044: push(@newpaste,$suffix);
1045: if ($locknotfreed) {
1046: return $locknotfreed;
1047: last;
1048: }
1049: if (&is_supplemental_title($title)) {
1050: &Apache::lonnet::appenv({'docs.markedcopy_supplemental_'.$suffix => $title});
1051: ($title) = &Apache::loncommon::parse_supplemental_title($title);
1052: }
1.329 droeschl 1053:
1.538 raeburn 1054: $addtoenv{'docs.markedcopy_title_'.$suffix} = $title,
1055: $addtoenv{'docs.markedcopy_url_'.$suffix} = $url,
1056: $addtoenv{'docs.markedcopy_cmd_'.$suffix} = $cmd,
1057: $addtoenv{'docs.markedcopy_crs_'.$suffix} = $env{'request.course.id'};
1058:
1059: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(default|supplemental)_?(\d*)\.(page|sequence)$}) {
1060: my $prefix = $1;
1061: my $subdir =$2;
1062: if ($subdir eq '') {
1063: $subdir = $prefix;
1.492 raeburn 1064: }
1.538 raeburn 1065: my (%addedmaps,%removefrommap,%removeparam,%hierarchy,%titles,%allmaps);
1066: &contained_map_check($url,$folder,\%removefrommap,\%removeparam,\%addedmaps,
1067: \%hierarchy,\%titles,\%allmaps);
1068: if (ref($hierarchy{$url}) eq 'HASH') {
1069: my ($nested,$nestednames);
1070: &recurse_uploaded_maps($url,$subdir,\%hierarchy,\%titles,\$nested,\$nestednames);
1071: $nested =~ s/\&$//;
1072: $nestednames =~ s/\Q___&&&___\E$//;
1073: if ($nested ne '') {
1074: $addtoenv{'docs.markedcopy_nested_'.$suffix} = $nested;
1075: }
1076: if ($nestednames ne '') {
1077: $addtoenv{'docs.markedcopy_nestednames_'.$suffix} = $nestednames;
1078: }
1.492 raeburn 1079: }
1080: }
1081: }
1.538 raeburn 1082: if (@newpaste) {
1083: $addtoenv{'docs.markedcopies'} = join(',',(@currpaste,@newpaste));
1084: }
1.492 raeburn 1085: &Apache::lonnet::appenv(\%addtoenv);
1.329 droeschl 1086: delete($env{'form.markcopy'});
1087: }
1088:
1.492 raeburn 1089: sub recurse_uploaded_maps {
1090: my ($url,$dir,$hierarchy,$titlesref,$nestref,$namesref) = @_;
1091: if (ref($hierarchy->{$url}) eq 'HASH') {
1092: my @maps = map { $hierarchy->{$url}{$_}; } sort { $a <=> $b } (keys(%{$hierarchy->{$url}}));
1093: my @titles = map { $titlesref->{$url}{$_}; } sort { $a <=> $b } (keys(%{$titlesref->{$url}}));
1094: my (@uploaded,@names,%shorter);
1095: for (my $i=0; $i<@maps; $i++) {
1096: my ($inner) = ($maps[$i] =~ m{^/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_(\d+)\.(?:page|sequence)$});
1097: if ($inner ne '') {
1098: push(@uploaded,$inner);
1099: push(@names,&escape($titles[$i]));
1100: $shorter{$maps[$i]} = $inner;
1101: }
1102: }
1103: $$nestref .= "$dir:".join(',',@uploaded).'&';
1104: $$namesref .= "$dir:".(join(',',@names)).'___&&&___';
1105: foreach my $map (@maps) {
1106: if ($shorter{$map} ne '') {
1107: &recurse_uploaded_maps($map,$shorter{$map},$hierarchy,$titlesref,$nestref,$namesref);
1108: }
1109: }
1110: }
1111: return;
1112: }
1113:
1.329 droeschl 1114: sub print_paste_buffer {
1.492 raeburn 1115: my ($r,$container,$folder,$coursedom,$coursenum) = @_;
1.538 raeburn 1116: return if (!defined($env{'docs.markedcopies'}));
1.329 droeschl 1117:
1.538 raeburn 1118: unless (($env{'form.pastemarked'}) || ($env{'form.clearmarked'})) {
1119: return if ($env{'docs.markedcopies'} eq '');
1.488 raeburn 1120: }
1121:
1.538 raeburn 1122: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1123: my ($pasteitems,@pasteable);
1.488 raeburn 1124:
1.538 raeburn 1125: # Construct identifiers for current contents of user's paste buffer
1126: foreach my $suffix (@currpaste) {
1127: next if ($suffix =~ /\D/);
1128: my $cid = $env{'docs.markedcopy_crs_'.$suffix};
1129: my $url = $env{'docs.markedcopy_url_'.$suffix};
1130: if (($cid =~ /^$match_domain\_$match_courseid$/) &&
1131: ($url ne '')) {
1132: my ($is_external,$othercourse,$fromsupp,$is_uploaded_map,$parent,
1133: $canpaste,$nopaste,$othercrs,$areachange);
1134: my $extension = (split(/\./,$env{'docs.markedcopy_url_'.$suffix}))[-1];
1135: if ($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//} ) {
1136: $is_external = 1;
1137: }
1138: if ($folder =~ /^supplemental/) {
1139: $canpaste = &supp_pasteable($env{'docs.markedcopy_url_'.$suffix});
1140: unless ($canpaste) {
1141: $nopaste = &mt('Paste into Supplemental Content unavailable.');
1142: }
1143: } else {
1144: $canpaste = 1;
1145: }
1146: if ($canpaste) {
1147: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
1148: my $srcdom = $1;
1149: my $srcnum = $2;
1150: my $rem = $3;
1151: if (($srcdom ne $coursedom) || ($srcnum ne $coursenum)) {
1152: $othercourse = 1;
1153: if ($env{"user.priv.cm./$srcdom/$srcnum"} =~ /\Q:mdc&F\E/) {
1154: if ($canpaste) {
1.539 raeburn 1155: $othercrs = '<br />'.&mt('(from another course)');
1.538 raeburn 1156: }
1157: } else {
1158: $canpaste = 0;
1159: $nopaste = &mt('Paste from another course unavailable.');
1160: }
1161: }
1162: if ($rem =~ m{^(default|supplemental)_?(\d*)\.(?:page|sequence)$}) {
1163: my $prefix = $1;
1164: $parent = $2;
1165: if ($folder !~ /^\Q$prefix\E/) {
1166: $areachange = 1;
1167: }
1168: $is_uploaded_map = 1;
1.492 raeburn 1169: }
1170: }
1171: }
1.538 raeburn 1172: if ($canpaste) {
1173: push(@pasteable,$suffix);
1174: }
1175: my $buffer;
1176: if ($is_external) {
1177: $buffer = &mt('External Resource').': '.
1178: &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix}).' ('.
1179: &LONCAPA::map::qtescape($url).')';
1180: } else {
1181: my $icon = &Apache::loncommon::icon($extension);
1182: if ($extension eq 'sequence' &&
1183: $url =~ m{/default_\d+\.sequence$}x) {
1184: $icon = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
1185: $icon .= '/navmap.folder.closed.gif';
1186: }
1187: $buffer = '<img src="'.$icon.'" alt="" class="LC_icon" />'.
1188: ': '.
1189: &Apache::loncommon::parse_supplemental_title(
1190: &LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix}));
1191: }
1192: $pasteitems .= '<div class="LC_left_float">';
1193: my ($options,$onclick);
1194: if (($canpaste) && (!$areachange) && (!$othercourse) &&
1195: ($env{'docs.markedcopy_cmd_'.$suffix} eq 'cut')) {
1196: if (($is_uploaded_map) ||
1197: ($url =~ /(bulletinboard|smppg)$/) ||
1198: ($url =~ m{^/uploaded/$coursedom/$coursenum/(?:docs|supplemental)/(.+)$})) {
1199: $options = &paste_options($suffix,$is_uploaded_map,$parent);
1200: $onclick= 'onclick="showOptions(this,'."'$suffix'".');" ';
1201: }
1202: }
1203: $pasteitems .= '<label><input type="checkbox" name="pasting" id="pasting_'.$suffix.'" value="'.$suffix.'" '.$onclick.'/>'.$buffer.'</label>';
1204: if ($nopaste) {
1205: $pasteitems .= $nopaste;
1206: } else {
1207: if ($othercrs) {
1208: $pasteitems .= $othercrs;
1209: }
1210: if ($options) {
1211: $pasteitems .= $options;
1.492 raeburn 1212: }
1213: }
1.538 raeburn 1214: $pasteitems .= '</div>';
1215: }
1216: }
1217: if ($pasteitems eq '') {
1218: &Apache::lonnet::delenv('docs.markedcopies');
1219: }
1220: my ($pasteform,$form_start,$buttons,$form_end);
1221: if ($pasteitems) {
1222: $pasteitems .= '<div style="padding:0;clear:both;margin:0;border:0"></div>';
1.541 raeburn 1223: $form_start = '<form name="pasteform" action="/adm/coursedocs" method="post" onsubmit="return validateClipboard();">';
1.538 raeburn 1224: if (@pasteable) {
1225: $buttons = '<input type="submit" name="pastemarked" value="'.&mt('Paste selected').'" />'.(' 'x2);
1.492 raeburn 1226: }
1.538 raeburn 1227: $buttons .= '<input type="submit" name="clearmarked" value="'.&mt('Clear selected').'" />'.
1228: '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
1229: $form_end = '</form>';
1230: } else {
1231: $pasteitems = &mt('Clipboard is empty');
1.488 raeburn 1232: }
1.538 raeburn 1233: $r->print($form_start
1234: .'<fieldset>'
1235: .'<legend>'.&mt('Clipboard').(' ' x2).$buttons.'</legend>'
1236: .$pasteitems
1237: .'</fieldset>'
1238: .$form_end);
1239: }
1240:
1241: sub paste_options {
1242: my ($suffix,$is_uploaded_map,$parent) = @_;
1243: my ($copytext,$movetext);
1244: if ($is_uploaded_map) {
1245: $copytext = &mt('Copy to new folder');
1246: $movetext = &mt('Move old');
1247: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /bulletinboard$/) {
1248: $copytext = &mt('Copy to new board');
1249: $movetext = &mt('Move (not posts)');
1250: } elsif ($env{'docs.markedcopy_url_'.$suffix} =~ /smppg$/) {
1251: $copytext = &mt('Copy to new page');
1252: $movetext = &mt('Move');
1.533 raeburn 1253: } else {
1.538 raeburn 1254: $copytext = &mt('Copy to new file');
1255: $movetext = &mt('Move');
1256: }
1257: my $output = '<br />'.
1258: '<span id="pasteoptionstext_'.$suffix.'" class="LC_fontsize_small LC_nobreak"></span>'.
1259: '<div id="pasteoptions_'.$suffix.'" class="LC_dccid" style="display:none;"><span class="LC_nobreak">'.(' 'x 4).
1260: '<label>'.
1261: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="new" checked="checked" />'.
1262: $copytext.'</label></span>'.(' 'x2).' '.
1263: '<span class="LC_nobreak"><label>'.
1264: '<input type="radio" name="docs.markedcopy_options_'.$suffix.'" value="move" />'.
1265: $movetext.'</label></span>';
1266: if (($is_uploaded_map) && ($env{'docs.markedcopy_nested_'.$suffix})) {
1267: $output .= '<br /><fieldset><legend>'.&mt('Folder to paste contains sub-folders').
1268: '</legend><table border="0">';
1269: my @pastemaps = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1270: my @titles = split(/\Q___&&&___\E/,$env{'docs.markedcopy_nestednames_'.$suffix});
1271: my $lastdir = $parent;
1272: my %depths = (
1273: $lastdir => 0,
1274: );
1275: my (%display,%deps);
1276: for (my $i=0; $i<@pastemaps; $i++) {
1277: ($lastdir,my $subfolderstr) = split(/\:/,$pastemaps[$i]);
1278: my ($namedir,$esctitlestr) = split(/\:/,$titles[$i]);
1279: my @subfolders = split(/,/,$subfolderstr);
1280: $deps{$lastdir} = \@subfolders;
1281: my @subfoldertitles = map { &unescape($_); } split(/,/,$esctitlestr);
1282: my $depth = $depths{$lastdir} + 1;
1283: my $offset = int($depth * 4);
1284: my $indent = (' ' x $offset);
1285: for (my $j=0; $j<@subfolders; $j++) {
1286: $depths{$subfolders[$j]} = $depth;
1287: $display{$subfolders[$j]} =
1288: '<tr><td>'.$indent.$subfoldertitles[$j].' </td>'.
1289: '<td><label>'.
1290: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="new" checked="checked" />'.&mt('Copy to new').'</label>'.(' ' x2).
1291: '<label>'.
1292: '<input type="radio" name="docs.markedcopy_'.$suffix.'_'.$subfolders[$j].'" value="move" />'.
1293: &mt('Move old').'</label>'.
1294: '</td></tr>';
1295: }
1.492 raeburn 1296: }
1.538 raeburn 1297: &recurse_print(\$output,$parent,\%deps,\%display);
1298: $output .= '</table></fieldset>';
1.329 droeschl 1299: }
1.538 raeburn 1300: $output .= '</div>';
1301: return $output;
1.488 raeburn 1302: }
1303:
1.492 raeburn 1304: sub recurse_print {
1.538 raeburn 1305: my ($outputref,$dir,$deps,$display) = @_;
1306: $$outputref .= $display->{$dir}."\n";
1.492 raeburn 1307: if (ref($deps->{$dir}) eq 'ARRAY') {
1308: foreach my $subdir (@{$deps->{$dir}}) {
1.538 raeburn 1309: &recurse_print($outputref,$subdir,$deps,$display);
1.492 raeburn 1310: }
1311: }
1312: }
1313:
1.488 raeburn 1314: sub supp_pasteable {
1315: my ($url) = @_;
1316: if (($url =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//}) ||
1317: (($url =~ /\.sequence$/) && ($url =~ m{^/uploaded/})) ||
1318: ($url =~ m{^/uploaded/$match_domain/$match_courseid/(docs|supplemental)/(default|\d+)/\d+/}) ||
1319: ($url =~ m{^/adm/$match_domain/$match_username/aboutme}) ||
1320: ($url =~ m{^/public/$match_domain/$match_courseid/syllabus})) {
1321: return 1;
1322: }
1323: return;
1.329 droeschl 1324: }
1325:
1.492 raeburn 1326: sub paste_popup_js {
1327: my %lt = &Apache::lonlocal::texthash(
1.538 raeburn 1328: show => 'Show Options',
1329: hide => 'Hide Options',
1.541 raeburn 1330: none => 'No items selected from clipboard.',
1.492 raeburn 1331: );
1332: return <<"END";
1333:
1.538 raeburn 1334: function showPasteOptions(suffix) {
1335: document.getElementById('pasteoptions_'+suffix).style.display='block';
1336: document.getElementById('pasteoptionstext_'+suffix).innerHTML = ' <a href="javascript:hidePasteOptions(\\''+suffix+'\\');" class="LC_menubuttons_link">$lt{'hide'}</a>';
1.492 raeburn 1337: return;
1338: }
1339:
1.538 raeburn 1340: function hidePasteOptions(suffix) {
1341: document.getElementById('pasteoptions_'+suffix).style.display='none';
1342: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$lt{'show'}</a>';
1343: return;
1344: }
1345:
1346: function showOptions(caller,suffix) {
1347: if (document.getElementById('pasteoptionstext_'+suffix)) {
1348: if (caller.checked) {
1349: document.getElementById('pasteoptionstext_'+suffix).innerHTML =' <a href="javascript:showPasteOptions(\\''+suffix+'\\')" class="LC_menubuttons_link">$lt{'show'}</a>';
1350: } else {
1351: document.getElementById('pasteoptionstext_'+suffix).innerHTML ='';
1352: }
1353: if (document.getElementById('pasteoptions_'+suffix)) {
1354: document.getElementById('pasteoptions_'+suffix).style.display='none';
1355: }
1356: }
1.492 raeburn 1357: return;
1358: }
1359:
1.541 raeburn 1360: function validateClipboard() {
1361: var numchk = 0;
1362: if (document.pasteform.pasting.length > 1) {
1363: for (var i=0; i<document.pasteform.pasting.length; i++) {
1364: if (document.pasteform.pasting[i].checked) {
1365: numchk ++;
1366: }
1367: }
1368: } else {
1369: if (document.pasteform.pasting.type == 'checkbox') {
1370: if (document.pasteform.pasting.checked) {
1371: numchk ++;
1372: }
1373: }
1374: }
1375: if (numchk > 0) {
1376: return true;
1377: } else {
1378: alert("$lt{'none'}");
1379: return false;
1380: }
1381: }
1382:
1.492 raeburn 1383: END
1384:
1385: }
1386:
1.329 droeschl 1387: sub do_paste_from_buffer {
1.492 raeburn 1388: my ($coursenum,$coursedom,$folder,$container,$errors) = @_;
1.329 droeschl 1389:
1.538 raeburn 1390: # Array of items in paste buffer
1391: my (@currpaste,%pastebuffer,%allerrors);
1392: @currpaste = split(/,/,$env{'docs.markedcopies'});
1393:
1.492 raeburn 1394: # Early out if paste buffer is empty
1.538 raeburn 1395: if (@currpaste == 0) {
1.492 raeburn 1396: return ();
1.538 raeburn 1397: }
1398: map { $pastebuffer{$_} = 1; } @currpaste;
1399:
1400: # Array of items selected items to paste
1401: my @reqpaste = &Apache::loncommon::get_env_multiple('form.pasting');
1402:
1403: # Early out if nothing selected to paste
1404: if (@reqpaste == 0) {
1405: return();
1406: }
1407: my @topaste;
1408: foreach my $suffix (@reqpaste) {
1409: next if ($suffix =~ /\D/);
1410: next unless (exists($pastebuffer{$suffix}));
1411: push(@topaste,$suffix);
1412: }
1413:
1414: # Early out if nothing available to paste
1415: if (@topaste == 0) {
1416: return();
1.329 droeschl 1417: }
1418:
1.538 raeburn 1419: my (%msgs,%before,%after,@dopaste,%is_map,%notinsupp,%notincrs,%duplicate,
1.564 raeburn 1420: %prefixchg,%srcdom,%srcnum,%marktomove,$save_err,$lockerrors,$allresult);
1.538 raeburn 1421:
1422: foreach my $suffix (@topaste) {
1423: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1.492 raeburn 1424: # Supplemental content may only include certain types of content
1425: # Early out if pasted content is not supported in Supplemental area
1.538 raeburn 1426: if ($folder =~ /^supplemental/) {
1427: unless (&supp_pasteable($url)) {
1428: $notinsupp{$suffix} = 1;
1429: next;
1430: }
1.492 raeburn 1431: }
1.538 raeburn 1432: if ($url =~ m{^/uploaded/($match_domain)/($match_courseid)/}) {
1433: my $srcd = $1;
1434: my $srcn = $2;
1.492 raeburn 1435: # When paste buffer was populated using an active role in a different course
1.538 raeburn 1436: # check for mdc privilege in the course from which the resource was pasted
1437: if (($srcd ne $coursedom) || ($srcn ne $coursenum)) {
1438: unless ($env{"user.priv.cm./$srcd/$srcn"} =~ /\Q:mdc&F\E/) {
1439: $notincrs{$suffix} = 1;
1440: next;
1441: }
1.491 raeburn 1442: }
1.538 raeburn 1443: $srcdom{$suffix} = $srcd;
1444: $srcnum{$suffix} = $srcn;
1.491 raeburn 1445: }
1.538 raeburn 1446:
1447: push(@dopaste,$suffix);
1448: if ($url=~/\.(page|sequence)$/) {
1449: $is_map{$suffix} = 1;
1450: }
1451:
1452: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/([^/]+)}) {
1453: my $oldprefix = $1;
1.492 raeburn 1454: # When pasting content from Main Content to Supplemental Content and vice versa
1455: # URLs will contain different paths (which depend on whether pasted item is
1456: # a folder/page or a document.
1.538 raeburn 1457: if (($folder =~ /^supplemental/) && (($oldprefix =~ /^default/) || ($oldprefix eq 'docs'))) {
1458: $prefixchg{$suffix} = 'docstosupp';
1459: } elsif (($folder =~ /^default/) && ($oldprefix =~ /^supplemental/)) {
1460: $prefixchg{$suffix} = 'supptodocs';
1461: }
1.491 raeburn 1462:
1.492 raeburn 1463: # If pasting an uploaded map, get list of contained uploaded maps.
1.538 raeburn 1464: if ($env{'docs.markedcopy_nested_'.$suffix}) {
1465: my @nested;
1466: my ($type) = ($oldprefix =~ /^(default|supplemental)/);
1467: my @items = split(/\&/,$env{'docs.markedcopy_nested_'.$suffix});
1468: my @deps = map { /\d+:([\d,]+$)/ } @items;
1469: foreach my $dep (@deps) {
1470: if ($dep =~ /,/) {
1471: push(@nested,split(/,/,$dep));
1472: } else {
1473: push(@nested,$dep);
1474: }
1.492 raeburn 1475: }
1.538 raeburn 1476: foreach my $item (@nested) {
1477: if ($env{'form.docs.markedcopy_'.$suffix.'_'.$item} eq 'move') {
1478: push(@{$marktomove{$suffix}},$type.'_'.$item);
1479: }
1.492 raeburn 1480: }
1481: }
1.488 raeburn 1482: }
1483: }
1484:
1.538 raeburn 1485: # Early out if nothing available to paste
1486: if (@dopaste == 0) {
1487: return ();
1488: }
1489:
1490: # Populate message hash and hashes used for main content <=> supplemental content
1491: # changes
1492:
1493: %msgs = &Apache::lonlocal::texthash (
1494: notinsupp => 'Paste failed: content type is not supported within Supplemental Content',
1495: notincrs => 'Paste failed: Item is from a different course which you do not have rights to edit.',
1496: duplicate => 'Paste failed: only one instance of a particular published sequence or page is allowed within each course.',
1497: );
1498:
1499: %before = (
1500: docstosupp => {
1501: map => 'default',
1502: doc => 'docs',
1503: },
1504: supptodocs => {
1505: map => 'supplemental',
1506: doc => 'supplemental',
1507: },
1508: );
1509:
1510: %after = (
1511: docstosupp => {
1512: map => 'supplemental',
1513: doc => 'supplemental'
1514: },
1515: supptodocs => {
1516: map => 'default',
1517: doc => 'docs',
1518: },
1519: );
1520:
1521: # Retrieve information about all course maps in main content area
1522:
1523: my $allmaps = {};
1524: if ($folder =~ /^default/) {
1525: $allmaps =
1526: &Apache::loncommon::allmaps_incourse($coursedom,$coursenum,
1527: $env{"course.$env{'request.course.id'}.home"},
1528: $env{'request.course.id'});
1529: }
1530:
1531: my (@toclear,%mapurls,%lockerrs,%msgerrs,%results);
1532:
1533: # Loop over the items to paste
1534: foreach my $suffix (@dopaste) {
1.329 droeschl 1535: # Maps need to be copied first
1.538 raeburn 1536: my (%removefrommap,%removeparam,%addedmaps,%rewrites,%retitles,%copies,
1537: %dbcopies,%zombies,%params,%docmoves,%mapmoves,%mapchanges,%newsubdir,
1538: %newurls,%tomove);
1539: if (ref($marktomove{$suffix}) eq 'ARRAY') {
1540: map { $tomove{$_} = 1; } @{$marktomove{$suffix}};
1541: }
1542: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url_'.$suffix});
1543: my $title=&LONCAPA::map::qtescape($env{'docs.markedcopy_title_'.$suffix});
1544: my $oldurl = $url;
1545: if ($is_map{$suffix}) {
1.491 raeburn 1546: # If pasting a map, check if map contains other maps
1.538 raeburn 1547: my (%hierarchy,%titles);
1548: &contained_map_check($url,$folder,\%removefrommap,\%removeparam,
1549: \%addedmaps,\%hierarchy,\%titles,$allmaps);
1550: if ($url=~ m{^/uploaded/}) {
1551: my $newurl;
1552: unless ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
1553: ($newurl,my $error) =
1554: &get_newmap_url($url,$folder,$prefixchg{$suffix},$coursedom,
1555: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1556: \$title,$allmaps,\%newurls);
1557: if ($error) {
1558: $allerrors{$suffix} = $error;
1559: next;
1560: }
1561: if ($newurl ne '') {
1562: if ($newurl ne $url) {
1563: if ($newurl =~ /(?:default|supplemental)_(\d+).(?:sequence|page)$/) {
1564: $newsubdir{$url} = $1;
1565: }
1566: $mapchanges{$url} = 1;
1.492 raeburn 1567: }
1.538 raeburn 1568: }
1569: }
1570: if (($srcdom{$suffix} ne $coursedom) ||
1571: ($srcnum{$suffix} ne $coursenum) ||
1572: ($prefixchg{$suffix}) || (($newurl ne '') && ($newurl ne $url))) {
1573: unless (&url_paste_fixups($url,$folder,$prefixchg{$suffix},
1574: $coursedom,$coursenum,$srcdom{$suffix},
1575: $srcnum{$suffix},$allmaps,\%rewrites,
1576: \%retitles,\%copies,\%dbcopies,
1577: \%zombies,\%params,\%mapmoves,
1578: \%mapchanges,\%tomove,\%newsubdir,
1579: \%newurls)) {
1580: $mapmoves{$url} = 1;
1581: }
1582: $url = $newurl;
1583: } elsif ($env{'docs.markedcopy_nested_'.$suffix}) {
1584: &url_paste_fixups($url,$folder,$prefixchg{$suffix},$coursedom,
1585: $coursenum,$srcdom{$suffix},$srcnum{$suffix},
1586: $allmaps,\%rewrites,\%retitles,\%copies,\%dbcopies,
1587: \%zombies,\%params,\%mapmoves,\%mapchanges,
1588: \%tomove,\%newsubdir,\%newurls);
1589: }
1590: } elsif ($url=~m {^/res/}) {
1591: # published map can only exists once, so remove from paste buffer when done
1592: push(@toclear,$suffix);
1593: # if pasting published map (main content area only) check map not already in course
1594: if ($folder =~ /^default/) {
1595: if ((ref($allmaps) eq 'HASH') && ($allmaps->{$url})) {
1596: $duplicate{$suffix} = 1;
1597: next;
1.492 raeburn 1598: }
1.491 raeburn 1599: }
1600: }
1.538 raeburn 1601: }
1602: if ($url=~ m{/(bulletinboard|smppg)$}) {
1603: my $prefix = $1;
1604: #need to copy the db contents to a new one, unless this is a move.
1605: my %info = (
1606: src => $url,
1607: cdom => $coursedom,
1608: cnum => $coursenum,
1609: );
1610: unless ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
1611: my (%lockerr,$msg);
1612: my ($newurl,$result,$errtext) =
1613: &dbcopy(\%info,$coursedom,$coursenum,\%lockerr);
1614: if ($result eq 'ok') {
1615: $url = $newurl;
1616: $title=&mt('Copy of').' '.$title;
1617: } else {
1618: if ($prefix eq 'smppg') {
1619: $msg = &mt('Paste failed: An error occurred when copying the simple page.').' '.$errtext;
1620: } elsif ($prefix eq 'bulletinboard') {
1.565 bisitz 1621: $msg = &mt('Paste failed: An error occurred when copying the discussion board.').' '.$errtext;
1.538 raeburn 1622: }
1623: $results{$suffix} = $result;
1624: $msgerrs{$suffix} = $msg;
1625: $lockerrs{$suffix} = $lockerr{$prefix};
1626: next;
1627: }
1628: if ($lockerr{$prefix}) {
1629: $lockerrs{$suffix} = $lockerr{$prefix};
1.491 raeburn 1630: }
1.489 raeburn 1631: }
1632: }
1.538 raeburn 1633: $title = &LONCAPA::map::qtunescape($title);
1634: my $ext='false';
1635: if ($url=~m{^http(|s)://}) { $ext='true'; }
1636: if ($env{'docs.markedcopy_supplemental_'.$suffix}) {
1637: if ($folder !~ /^supplemental/) {
1638: (undef,undef,$title) =
1639: &Apache::loncommon::parse_supplemental_title($env{'docs.markedcopy_supplemental_'.$suffix});
1640: }
1641: } else {
1642: if ($folder=~/^supplemental/) {
1643: $title=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
1644: $env{'user.domain'}.'___&&&___'.$title;
1.491 raeburn 1645: }
1.533 raeburn 1646: }
1.491 raeburn 1647:
1648: # For uploaded files (excluding pages/sequences) path in copied file is changed
1649: # if paste is from Main to Supplemental (or vice versa), or if pasting between
1650: # courses.
1651:
1.538 raeburn 1652: unless ($is_map{$suffix}) {
1653: my $newidx;
1.492 raeburn 1654: # Now insert the URL at the bottom
1.538 raeburn 1655: $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
1656: if ($url =~ m{^/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(.+)$}) {
1657: my $relpath = $1;
1658: if ($relpath ne '') {
1659: my ($prefix,$subdir,$rem) = ($relpath =~ m{^(default|\d+)/(\d+)/(.+)$});
1660: my ($newloc,$newdocsdir) = ($folder =~ /^(default|supplemental)_?(\d*)/);
1661: my $newprefix = $newloc;
1662: if ($newloc eq 'default') {
1663: $newprefix = 'docs';
1664: }
1665: if ($newdocsdir eq '') {
1666: $newdocsdir = 'default';
1667: }
1668: if (($prefixchg{$suffix}) ||
1669: ($srcdom{$suffix} ne $coursedom) ||
1670: ($srcnum{$suffix} ne $coursenum) ||
1671: ($env{'form.docs.markedcopy_options_'.$suffix} ne 'move')) {
1672: my $newpath = "$newprefix/$newdocsdir/$newidx/$rem";
1673: $url =
1674: &Apache::lonclonecourse::writefile($env{'request.course.id'},$newpath,
1675: &Apache::lonnet::getfile($oldurl));
1676: if ($url eq '/adm/notfound.html') {
1677: $msgs{$suffix} = &mt('Paste failed: an error occurred saving the file.');
1678: next;
1679: } else {
1680: my ($newsubpath) = ($newpath =~ m{^(.*/)[^/]*$});
1681: $newsubpath =~ s{/+$}{/};
1682: $docmoves{$oldurl} = $newsubpath;
1683: }
1.491 raeburn 1684: }
1685: }
1686: }
1.538 raeburn 1687: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
1688: ':'.$ext.':normal:res';
1689: push(@LONCAPA::map::order,$newidx);
1690: # Store the result
1691: my ($errtext,$fatal) =
1692: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1693: if ($fatal) {
1694: $save_err .= $errtext;
1695: $allresult = 'fail';
1696: }
1.488 raeburn 1697: }
1.538 raeburn 1698:
1.492 raeburn 1699: # Apply any changes to maps, or copy dependencies for uploaded HTML pages
1.538 raeburn 1700: unless ($allresult eq 'fail') {
1701: my %updated = (
1702: rewrites => \%rewrites,
1703: zombies => \%zombies,
1704: removefrommap => \%removefrommap,
1705: removeparam => \%removeparam,
1706: dbcopies => \%dbcopies,
1707: retitles => \%retitles,
1708: );
1709: my %info = (
1710: newsubdir => \%newsubdir,
1711: params => \%params,
1712: );
1713: if ($prefixchg{$suffix}) {
1714: $info{'before'} = $before{$prefixchg{$suffix}};
1715: $info{'after'} = $after{$prefixchg{$suffix}};
1716: }
1717: my %moves = (
1718: copies => \%copies,
1719: docmoves => \%docmoves,
1720: mapmoves => \%mapmoves,
1721: );
1722: (my $result,$msgs{$suffix},my $lockerror) =
1723: &apply_fixups($folder,$is_map{$suffix},$coursedom,$coursenum,$errors,
1724: \%updated,\%info,\%moves,$prefixchg{$suffix},$oldurl,
1725: $url,'paste');
1726: $lockerrors .= $lockerror;
1727: if ($result eq 'ok') {
1728: if ($is_map{$suffix}) {
1729: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
1730: $folder.'.'.$container);
1731: if ($fatal) {
1732: $allresult = 'failread';
1733: } else {
1734: if ($#LONCAPA::map::order<1) {
1735: my $idx=&LONCAPA::map::getresidx();
1736: if ($idx<=0) { $idx=1; }
1737: $LONCAPA::map::order[0]=$idx;
1738: $LONCAPA::map::resources[$idx]='';
1739: }
1740: my $newidx = &LONCAPA::map::getresidx(&LONCAPA::map::qtunescape($url));
1741: $LONCAPA::map::resources[$newidx]=$title.':'.&LONCAPA::map::qtunescape($url).
1742: ':'.$ext.':normal:res';
1743: push(@LONCAPA::map::order,$newidx);
1.492 raeburn 1744:
1745: # Store the result
1.538 raeburn 1746: my ($errtext,$fatal) =
1747: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
1748: if ($fatal) {
1749: $save_err .= $errtext;
1750: $allresult = 'failstore';
1751: }
1752: }
1753: }
1754: if ($env{'form.docs.markedcopy_options_'.$suffix} eq 'move') {
1755: push(@toclear,$suffix);
1756: }
1757: }
1.492 raeburn 1758: }
1759: }
1.538 raeburn 1760: &clear_from_buffer(\@toclear,\@currpaste);
1761: my $msgsarray;
1762: foreach my $suffix (keys(%msgs)) {
1763: if (ref($msgs{$suffix}) eq 'ARRAY') {
1764: $msgsarray .= join(',',@{$msgs{$suffix}});
1765: }
1766: }
1767: return ($allresult,$save_err,$msgsarray,$lockerrors);
1768: }
1.533 raeburn 1769:
1.538 raeburn 1770: sub do_buffer_empty {
1771: my @currpaste = split(/,/,$env{'docs.markedcopies'});
1772: if (@currpaste == 0) {
1773: return &mt('Clipboard is already empty');
1774: }
1775: my @toclear = &Apache::loncommon::get_env_multiple('form.pasting');
1776: if (@toclear == 0) {
1777: return &mt('Nothing selected to clear from clipboard');
1778: }
1779: my $numdel = &clear_from_buffer(\@toclear,\@currpaste);
1780: if ($numdel) {
1781: return &mt('[quant,_1,item] cleared from clipboard',$numdel);
1782: } else {
1783: return &mt('Clipboard unchanged');
1.492 raeburn 1784: }
1.538 raeburn 1785: return;
1786: }
1787:
1788: sub clear_from_buffer {
1789: my ($toclear,$currpaste) = @_;
1790: return unless ((ref($toclear) eq 'ARRAY') && (ref($currpaste) eq 'ARRAY'));
1791: my %pastebuffer;
1792: map { $pastebuffer{$_} = 1; } @{$currpaste};
1793: my $numdel = 0;
1794: foreach my $suffix (@{$toclear}) {
1795: next if ($suffix =~ /\D/);
1796: next unless (exists($pastebuffer{$suffix}));
1797: my $regexp = 'docs.markedcopy_[a-z]+_'.$suffix;
1798: if (&Apache::lonnet::delenv($regexp,1) eq 'ok') {
1799: delete($pastebuffer{$suffix});
1800: $numdel ++;
1801: }
1802: }
1803: my $newbuffer = join(',',sort(keys(%pastebuffer)));
1804: &Apache::lonnet::appenv({'docs.markedcopies' => $newbuffer});
1805: return $numdel;
1.492 raeburn 1806: }
1807:
1808: sub get_newmap_url {
1809: my ($url,$folder,$prefixchg,$coursedom,$coursenum,$srcdom,$srcnum,
1810: $titleref,$allmaps,$newurls) = @_;
1811: my $newurl;
1812: if ($url=~ m{^/uploaded/}) {
1813: $$titleref=&mt('Copy of').' '.$$titleref;
1814: }
1815: my $now = time;
1816: my $suffix=$$.int(rand(100)).$now;
1817: my ($oldid,$ext) = ($url=~/^(.+)\.(\w+)$/);
1818: if ($oldid =~ m{^(/uploaded/$match_domain/$match_courseid/)(\D+)(\d+)$}) {
1819: my $path = $1;
1820: my $prefix = $2;
1821: my $ancestor = $3;
1822: if (length($ancestor) > 10) {
1823: $ancestor = substr($ancestor,-10,10);
1824: }
1825: my $newid;
1826: if ($prefixchg) {
1827: if ($folder =~ /^supplemental/) {
1828: $prefix =~ s/^default/supplemental/;
1829: } else {
1830: $prefix =~ s/^supplemental/default/;
1831: }
1832: }
1833: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
1834: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
1835: } else {
1836: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$now.'.'.$ext;
1837: }
1838: my $counter = 0;
1839: my $is_unique = &uniqueness_check($newurl);
1840: if ($folder =~ /^default/) {
1841: if ($allmaps->{$newurl}) {
1842: $is_unique = 0;
1843: }
1844: }
1845: while ((!$is_unique || $allmaps->{$newurl} || $newurls->{$newurl}) && ($counter < 100)) {
1846: $counter ++;
1847: $suffix ++;
1848: if (($srcdom eq $coursedom) && ($srcnum eq $coursenum)) {
1849: $newurl = $path.$prefix.$ancestor.$suffix.'.'.$ext;
1850: } else {
1851: $newurl = "/uploaded/$coursedom/$coursenum/$prefix".$ancestor.$suffix.'.'.$ext;
1852: }
1853: $is_unique = &uniqueness_check($newurl);
1854: }
1855: if ($is_unique) {
1856: $newurls->{$newurl} = 1;
1857: } else {
1858: if ($url=~/\.page$/) {
1859: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the composite page'));
1860: } else {
1861: return (undef,&mt('Paste failed: an error occurred creating a unique URL for the folder'));
1862: }
1863: }
1.329 droeschl 1864: }
1.492 raeburn 1865: return ($newurl);
1.329 droeschl 1866: }
1867:
1.488 raeburn 1868: sub dbcopy {
1.533 raeburn 1869: my ($dbref,$coursedom,$coursenum,$lockerrorsref) = @_;
1870: my ($url,$result,$errtext);
1.564 raeburn 1871: $url = $dbref->{'src'};
1.533 raeburn 1872: if (ref($dbref) eq 'HASH') {
1873: if ($url =~ m{/(smppg|bulletinboard)$}) {
1874: my $prefix = $1;
1875: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
1876: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
1877: my $db_name;
1878: my $marker = (split(m{/},$url))[4];
1879: $marker=~s/\D//g;
1880: if ($dbref->{'src'} =~ m{/smppg$}) {
1881: $db_name =
1882: &Apache::lonsimplepage::get_db_name($url,$marker,
1883: $dbref->{'cdom'},
1884: $dbref->{'cnum'});
1885: } else {
1886: $db_name = 'bulletinpage_'.$marker;
1887: }
1888: my ($suffix,$freedlock,$error) =
1889: &Apache::lonnet::get_timebased_id($prefix,'num','templated',
1890: $coursedom,$coursenum,
1891: 'concat');
1892: if (!$suffix) {
1893: if ($prefix eq 'smppg') {
1894: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a simple page [_1].',$url);
1895: } else {
1.565 bisitz 1896: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when copying a discussion board [_1].',$url);
1.533 raeburn 1897: }
1898: if ($error) {
1899: $errtext .= '<br />'.$error;
1900: }
1901: } else {
1902: #need to copy the db contents to a new one.
1903: my %contents=&Apache::lonnet::dump($db_name,
1904: $dbref->{'cdom'},
1905: $dbref->{'cnum'});
1906: if (exists($contents{'uploaded.photourl'})) {
1907: my $photo = $contents{'uploaded.photourl'};
1908: my ($subdir,$fname) =
1909: ($photo =~ m{^/uploaded/$match_domain/$match_courseid/+(bulletin|simplepage)/(?:|\d+/)([^/]+)$});
1910: my $newphoto;
1911: if ($fname ne '') {
1912: my $content = &Apache::lonnet::getfile($photo);
1913: unless ($content eq '-1') {
1914: $env{'form.'.$suffix.'.photourl'} = $content;
1915: $newphoto =
1916: &Apache::lonnet::finishuserfileupload($coursenum,$coursedom,$suffix.'.photourl',"$subdir/$suffix/$fname");
1917: delete($env{'form.'.$suffix.'.photourl'});
1918: }
1919: }
1920: if ($newphoto =~ m{^/uploaded/}) {
1921: $contents{'uploaded.photourl'} = $newphoto;
1922: }
1923: }
1924: $db_name =~ s{_\d*$ }{_$suffix}x;
1925: $result=&Apache::lonnet::put($db_name,\%contents,
1926: $coursedom,$coursenum);
1927: if ($result eq 'ok') {
1928: $url =~ s{/(\d*)/(smppg|bulletinboard)$}{/$suffix/$2}x;
1929: }
1930: }
1931: if (($freedlock ne 'ok') && (ref($lockerrorsref) eq 'HASH')) {
1.559 raeburn 1932: $lockerrorsref->{$prefix} =
1.533 raeburn 1933: '<div class="LC_error">'.
1934: &mt('There was a problem removing a lockfile.');
1935: if ($prefix eq 'smppg') {
1.560 raeburn 1936: $lockerrorsref->{$prefix} .=
1.559 raeburn 1937: ' '.&mt('This will prevent creation of additional simple pages in this course.');
1.533 raeburn 1938: } else {
1.565 bisitz 1939: $lockerrorsref->{$prefix} .= ' '.&mt('This will prevent creation of additional discussion boards in this course.');
1.533 raeburn 1940: }
1.560 raeburn 1941: $lockerrorsref->{$prefix} .= ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
1942: '<a href="/adm/helpdesk" target="_helpdesk">','</a>').
1943: '</div>';
1.533 raeburn 1944: }
1945: }
1946: } elsif ($url =~ m{/syllabus$}) {
1947: if (($dbref->{'cdom'} =~ /^$match_domain$/) &&
1948: ($dbref->{'cnum'} =~ /^$match_courseid$/)) {
1949: if (($dbref->{'cdom'} ne $coursedom) ||
1950: ($dbref->{'cnum'} ne $coursenum)) {
1951: my %contents=&Apache::lonnet::dump('syllabus',
1952: $dbref->{'cdom'},
1953: $dbref->{'cnum'});
1954: $result=&Apache::lonnet::put('syllabus',\%contents,
1955: $coursedom,$coursenum);
1956: }
1957: }
1.488 raeburn 1958: }
1959: }
1.533 raeburn 1960: return ($url,$result,$errtext);
1.488 raeburn 1961: }
1962:
1.329 droeschl 1963: sub uniqueness_check {
1964: my ($newurl) = @_;
1965: my $unique = 1;
1966: foreach my $res (@LONCAPA::map::order) {
1967: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
1968: $url=&LONCAPA::map::qtescape($url);
1969: if ($newurl eq $url) {
1970: $unique = 0;
1.344 bisitz 1971: last;
1.329 droeschl 1972: }
1973: }
1974: return $unique;
1975: }
1976:
1.488 raeburn 1977: sub contained_map_check {
1.492 raeburn 1978: my ($url,$folder,$removefrommap,$removeparam,$addedmaps,$hierarchy,$titles,
1979: $allmaps) = @_;
1.488 raeburn 1980: my $content = &Apache::lonnet::getfile($url);
1981: unless ($content eq '-1') {
1982: my $parser = HTML::TokeParser->new(\$content);
1983: $parser->attr_encoded(1);
1984: while (my $token = $parser->get_token) {
1985: next if ($token->[0] ne 'S');
1986: if ($token->[1] eq 'resource') {
1987: next if ($token->[2]->{'type'} eq 'zombie');
1988: my $ressrc = $token->[2]->{'src'};
1989: if ($folder =~ /^supplemental/) {
1990: unless (&supp_pasteable($ressrc)) {
1.492 raeburn 1991: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.488 raeburn 1992: next;
1993: }
1994: }
1.492 raeburn 1995: if ($ressrc =~ m{^/(res|uploaded)/.+\.(sequence|page)$}) {
1996: if ($1 eq 'uploaded') {
1997: $hierarchy->{$url}{$token->[2]->{'id'}} = $ressrc;
1998: $titles->{$url}{$token->[2]->{'id'}} = $token->[2]->{'title'};
1.488 raeburn 1999: } else {
1.492 raeburn 2000: if ($allmaps->{$ressrc}) {
1.529 raeburn 2001: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
1.492 raeburn 2002: } elsif (ref($addedmaps->{$ressrc}) eq 'ARRAY') {
2003: $removefrommap->{$url}{$token->[2]->{'id'}} = $ressrc;
2004: } else {
2005: $addedmaps->{$ressrc} = [$url];
2006: }
1.488 raeburn 2007: }
1.492 raeburn 2008: &contained_map_check($ressrc,$folder,$removefrommap,$removeparam,
2009: $addedmaps,$hierarchy,$titles,$allmaps);
1.488 raeburn 2010: }
1.492 raeburn 2011: } elsif ($token->[1] eq 'param') {
1.488 raeburn 2012: if ($folder =~ /^supplemental/) {
1.492 raeburn 2013: if (ref($removeparam->{$url}{$token->[2]->{'to'}}) eq 'ARRAY') {
2014: push(@{$removeparam->{$url}{$token->[2]->{'to'}}},$token->[2]->{'name'});
2015: } else {
2016: $removeparam->{$url}{$token->[2]->{'to'}} = [$token->[2]->{'name'}];
2017: }
1.488 raeburn 2018: }
2019: }
2020: }
2021: }
2022: return;
2023: }
2024:
2025: sub url_paste_fixups {
1.533 raeburn 2026: my ($oldurl,$folder,$prefixchg,$cdom,$cnum,$fromcdom,$fromcnum,$allmaps,
2027: $rewrites,$retitles,$copies,$dbcopies,$zombies,$params,$mapmoves,
2028: $mapchanges,$tomove,$newsubdir,$newurls) = @_;
1.491 raeburn 2029: my $checktitle;
2030: if (($prefixchg) &&
1.492 raeburn 2031: ($oldurl =~ m{^/uploaded/$match_domain/$match_courseid/supplemental})) {
1.491 raeburn 2032: $checktitle = 1;
2033: }
1.492 raeburn 2034: my $skip;
2035: if ($oldurl =~ m{^\Q/uploaded/$cdom/$cnum/\E(default|supplemental)(_?\d*)\.(?:page|sequence)$}) {
2036: my $mapid = $1.$2;
2037: if ($tomove->{$mapid}) {
2038: $skip = 1;
2039: }
2040: }
1.491 raeburn 2041: my $file = &Apache::lonnet::getfile($oldurl);
1.488 raeburn 2042: return if ($file eq '-1');
2043: my $parser = HTML::TokeParser->new(\$file);
2044: $parser->attr_encoded(1);
1.491 raeburn 2045: my $changed = 0;
1.488 raeburn 2046: while (my $token = $parser->get_token) {
2047: next if ($token->[0] ne 'S');
2048: if ($token->[1] eq 'resource') {
2049: my $ressrc = $token->[2]->{'src'};
2050: next if ($ressrc eq '');
1.491 raeburn 2051: my $id = $token->[2]->{'id'};
1.492 raeburn 2052: my $title = $token->[2]->{'title'};
1.491 raeburn 2053: if ($checktitle) {
2054: if ($title =~ m{\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
1.532 raeburn 2055: $retitles->{$oldurl}{$id} = $ressrc;
1.491 raeburn 2056: }
2057: }
1.488 raeburn 2058: next if ($token->[2]->{'type'} eq 'external');
2059: if ($token->[2]->{'type'} eq 'zombie') {
1.492 raeburn 2060: next if ($skip);
1.532 raeburn 2061: $zombies->{$oldurl}{$id} = $ressrc;
1.491 raeburn 2062: $changed = 1;
2063: } elsif ($ressrc =~ m{^/uploaded/($match_domain)/($match_courseid)/(.+)$}) {
1.492 raeburn 2064: my $srcdom = $1;
2065: my $srcnum = $2;
1.488 raeburn 2066: my $rem = $3;
1.492 raeburn 2067: my $newurl;
2068: my $mapname;
2069: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
2070: my $prefix = $1;
2071: $mapname = $prefix.$2;
2072: if ($tomove->{$mapname}) {
1.533 raeburn 2073: &url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,$cnum,
2074: $srcdom,$srcnum,$allmaps,$rewrites,
2075: $retitles,$copies,$dbcopies,$zombies,
2076: $params,$mapmoves,$mapchanges,$tomove,
2077: $newsubdir,$newurls);
1.492 raeburn 2078: next;
2079: } else {
2080: ($newurl,my $error) =
2081: &get_newmap_url($ressrc,$folder,$prefixchg,$cdom,$cnum,
2082: $srcdom,$srcnum,\$title,$allmaps,$newurls);
2083: if ($newurl =~ /(?:default|supplemental)_(\d+)\.(?:sequence|page)$/) {
2084: $newsubdir->{$ressrc} = $1;
2085: }
2086: if ($error) {
2087: next;
2088: }
2089: }
2090: }
2091: if (($srcdom ne $cdom) || ($srcnum ne $cnum) || ($prefixchg) ||
2092: ($mapchanges->{$oldurl}) || (($newurl ne '') && ($newurl ne $oldurl))) {
2093:
1.488 raeburn 2094: if ($rem =~ /^(default|supplemental)(_?\d*).(sequence|page)$/) {
1.532 raeburn 2095: $rewrites->{$oldurl}{$id} = $ressrc;
1.491 raeburn 2096: $mapchanges->{$ressrc} = 1;
1.533 raeburn 2097: unless (&url_paste_fixups($ressrc,$folder,$prefixchg,$cdom,
2098: $cnum,$srcdom,$srcnum,$allmaps,
2099: $rewrites,$retitles,$copies,$dbcopies,
2100: $zombies,$params,$mapmoves,$mapchanges,
2101: $tomove,$newsubdir,$newurls)) {
1.491 raeburn 2102: $mapmoves->{$ressrc} = 1;
2103: }
2104: $changed = 1;
1.488 raeburn 2105: } else {
1.532 raeburn 2106: $rewrites->{$oldurl}{$id} = $ressrc;
1.488 raeburn 2107: $copies->{$oldurl}{$ressrc} = $id;
1.491 raeburn 2108: $changed = 1;
1.488 raeburn 2109: }
2110: }
1.533 raeburn 2111: } elsif ($ressrc =~ m{^/adm/($match_domain)/($match_courseid)/.+$}) {
2112: next if ($skip);
1.492 raeburn 2113: my $srcdom = $1;
2114: my $srcnum = $2;
2115: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.532 raeburn 2116: $rewrites->{$oldurl}{$id} = $ressrc;
1.533 raeburn 2117: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2118: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2119: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
2120: $changed = 1;
2121: }
2122: } elsif ($ressrc =~ m{^/adm/$match_domain/$match_username/\d+/(smppg|bulletinboard)$}) {
2123: if (($fromcdom ne $cdom) || ($fromcnum ne $cnum) ||
2124: ($env{'form.docs.markedcopy_options'} ne 'move')) {
2125: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2126: $dbcopies->{$oldurl}{$id}{'cdom'} = $fromcdom;
2127: $dbcopies->{$oldurl}{$id}{'cnum'} = $fromcnum;
1.491 raeburn 2128: $changed = 1;
1.488 raeburn 2129: }
2130: } elsif ($ressrc =~ m{^/public/($match_domain)/($match_courseid)/(.+)$}) {
1.492 raeburn 2131: next if ($skip);
2132: my $srcdom = $1;
2133: my $srcnum = $2;
2134: if (($srcdom ne $cdom) || ($srcnum ne $cnum)) {
1.533 raeburn 2135: $dbcopies->{$oldurl}{$id}{'src'} = $ressrc;
2136: $dbcopies->{$oldurl}{$id}{'cdom'} = $srcdom;
2137: $dbcopies->{$oldurl}{$id}{'cnum'} = $srcnum;
1.491 raeburn 2138: $changed = 1;
1.488 raeburn 2139: }
2140: }
2141: } elsif ($token->[1] eq 'param') {
1.492 raeburn 2142: next if ($skip);
1.488 raeburn 2143: my $to = $token->[2]->{'to'};
2144: if ($to ne '') {
2145: if (ref($params->{$oldurl}{$to}) eq 'ARRAY') {
1.492 raeburn 2146: push(@{$params->{$oldurl}{$to}},$token->[2]->{'name'});
1.488 raeburn 2147: } else {
2148: @{$params->{$oldurl}{$to}} = ($token->[2]->{'name'});
2149: }
2150: }
2151: }
2152: }
1.491 raeburn 2153: return $changed;
1.488 raeburn 2154: }
2155:
2156: sub apply_fixups {
1.529 raeburn 2157: my ($folder,$is_map,$cdom,$cnum,$errors,$updated,$info,$moves,$prefixchg,
2158: $oldurl,$url,$caller) = @_;
2159: my (%rewrites,%zombies,%removefrommap,%removeparam,%dbcopies,%retitles,
1.533 raeburn 2160: %params,%newsubdir,%before,%after,%copies,%docmoves,%mapmoves,@msgs,
2161: %lockerrors,$lockmsg);
1.529 raeburn 2162: if (ref($updated) eq 'HASH') {
2163: if (ref($updated->{'rewrites'}) eq 'HASH') {
2164: %rewrites = %{$updated->{'rewrites'}};
2165: }
2166: if (ref($updated->{'zombies'}) eq 'HASH') {
2167: %zombies = %{$updated->{'zombies'}};
2168: }
2169: if (ref($updated->{'removefrommap'}) eq 'HASH') {
2170: %removefrommap = %{$updated->{'removefrommap'}};
2171: }
2172: if (ref($updated->{'removeparam'}) eq 'HASH') {
2173: %removeparam = %{$updated->{'removeparam'}};
2174: }
2175: if (ref($updated->{'dbcopies'}) eq 'HASH') {
2176: %dbcopies = %{$updated->{'dbcopies'}};
2177: }
2178: if (ref($updated->{'retitles'}) eq 'HASH') {
2179: %retitles = %{$updated->{'retitles'}};
2180: }
2181: }
2182: if (ref($info) eq 'HASH') {
2183: if (ref($info->{'newsubdir'}) eq 'HASH') {
2184: %newsubdir = %{$info->{'newsubdir'}};
2185: }
2186: if (ref($info->{'params'}) eq 'HASH') {
2187: %params = %{$info->{'params'}};
2188: }
2189: if (ref($info->{'before'}) eq 'HASH') {
2190: %before = %{$info->{'before'}};
2191: }
2192: if (ref($info->{'after'}) eq 'HASH') {
2193: %after = %{$info->{'after'}};
2194: }
2195: }
2196: if (ref($moves) eq 'HASH') {
2197: if (ref($moves->{'copies'}) eq 'HASH') {
2198: %copies = %{$moves->{'copies'}};
2199: }
2200: if (ref($moves->{'docmoves'}) eq 'HASH') {
2201: %docmoves = %{$moves->{'docmoves'}};
2202: }
2203: if (ref($moves->{'mapmoves'}) eq 'HASH') {
2204: %mapmoves = %{$moves->{'mapmoves'}};
2205: }
2206: }
2207: foreach my $key (keys(%copies),keys(%docmoves)) {
1.491 raeburn 2208: my @allcopies;
1.529 raeburn 2209: if (exists($copies{$key})) {
2210: if (ref($copies{$key}) eq 'HASH') {
2211: my %added;
2212: foreach my $innerkey (keys(%{$copies{$key}})) {
2213: if (($innerkey ne '') && (!$added{$innerkey})) {
2214: push(@allcopies,$innerkey);
2215: $added{$innerkey} = 1;
2216: }
1.491 raeburn 2217: }
1.529 raeburn 2218: undef(%added);
1.491 raeburn 2219: }
2220: }
2221: if ($key eq $oldurl) {
1.529 raeburn 2222: if ((exists($docmoves{$key}))) {
1.532 raeburn 2223: unless (grep(/^\Q$oldurl\E$/,@allcopies)) {
1.491 raeburn 2224: push(@allcopies,$oldurl);
2225: }
2226: }
2227: }
2228: if (@allcopies > 0) {
2229: foreach my $item (@allcopies) {
1.492 raeburn 2230: my ($relpath,$oldsubdir,$fname) =
2231: ($item =~ m{^(/uploaded/$match_domain/$match_courseid/(?:docs|supplemental)/(default|\d+)/.*/)([^/]+)$});
1.491 raeburn 2232: if ($fname ne '') {
2233: my $content = &Apache::lonnet::getfile($item);
2234: unless ($content eq '-1') {
2235: my $storefn;
1.529 raeburn 2236: if (($key eq $oldurl) && (exists($docmoves{$key}))) {
2237: $storefn = $docmoves{$key};
1.491 raeburn 2238: } else {
2239: $storefn = $relpath;
2240: $storefn =~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 2241: if ($prefixchg && $before{'doc'} && $after{'doc'}) {
2242: $storefn =~ s/^\Q$before{'doc'}\E/$after{'doc'}/;
1.491 raeburn 2243: }
1.529 raeburn 2244: if ($newsubdir{$key}) {
1.532 raeburn 2245: $storefn =~ s#^(docs|supplemental)/\Q$oldsubdir\E/#$1/$newsubdir{$key}/#;
1.491 raeburn 2246: }
2247: }
2248: ©_dependencies($item,$storefn,$relpath,$errors,\$content);
2249: my $copyurl =
2250: &Apache::lonclonecourse::writefile($env{'request.course.id'},
2251: $storefn.$fname,$content);
2252: if ($copyurl eq '/adm/notfound.html') {
1.529 raeburn 2253: if (exists($docmoves{$oldurl})) {
1.491 raeburn 2254: return &mt('Paste failed: an error occurred copying the file.');
2255: } elsif (ref($errors) eq 'HASH') {
2256: $errors->{$item} = 1;
1.489 raeburn 2257: }
2258: }
1.488 raeburn 2259: }
2260: }
1.491 raeburn 2261: }
2262: }
2263: }
1.529 raeburn 2264: foreach my $key (keys(%mapmoves)) {
1.491 raeburn 2265: my $storefn=$key;
2266: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 2267: if ($prefixchg && $before{'map'} && $after{'map'}) {
2268: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.491 raeburn 2269: }
1.529 raeburn 2270: if ($newsubdir{$key}) {
2271: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.492 raeburn 2272: }
1.491 raeburn 2273: my $mapcontent = &Apache::lonnet::getfile($key);
2274: if ($mapcontent eq '-1') {
2275: if (ref($errors) eq 'HASH') {
2276: $errors->{$key} = 1;
2277: }
2278: } else {
2279: my $newmap =
2280: &Apache::lonclonecourse::writefile($env{'request.course.id'},$storefn,
2281: $mapcontent);
2282: if ($newmap eq '/adm/notfound.html') {
2283: if (ref($errors) eq 'HASH') {
2284: $errors->{$key} = 1;
1.489 raeburn 2285: }
1.488 raeburn 2286: }
2287: }
2288: }
1.491 raeburn 2289: my %updates;
2290: if ($is_map) {
1.529 raeburn 2291: if (ref($updated) eq 'HASH') {
2292: foreach my $type (keys(%{$updated})) {
2293: if (ref($updated->{$type}) eq 'HASH') {
2294: foreach my $key (keys(%{$updated->{$type}})) {
2295: $updates{$key} = 1;
2296: }
2297: }
2298: }
1.491 raeburn 2299: }
2300: foreach my $key (keys(%updates)) {
1.492 raeburn 2301: my (%torewrite,%toretitle,%toremove,%remparam,%currparam,%zombie,%newdb);
1.529 raeburn 2302: if (ref($rewrites{$key}) eq 'HASH') {
2303: %torewrite = %{$rewrites{$key}};
1.491 raeburn 2304: }
1.529 raeburn 2305: if (ref($retitles{$key}) eq 'HASH') {
2306: %toretitle = %{$retitles{$key}};
1.491 raeburn 2307: }
1.529 raeburn 2308: if (ref($removefrommap{$key}) eq 'HASH') {
2309: %toremove = %{$removefrommap{$key}};
1.491 raeburn 2310: }
1.529 raeburn 2311: if (ref($removeparam{$key}) eq 'HASH') {
2312: %remparam = %{$removeparam{$key}};
1.492 raeburn 2313: }
1.529 raeburn 2314: if (ref($zombies{$key}) eq 'HASH') {
2315: %zombie = %{$zombies{$key}};
1.491 raeburn 2316: }
1.529 raeburn 2317: if (ref($dbcopies{$key}) eq 'HASH') {
1.533 raeburn 2318: foreach my $idx (keys(%{$dbcopies{$key}})) {
2319: if (ref($dbcopies{$key}{$idx}) eq 'HASH') {
2320: my ($newurl,$result,$errtext) =
2321: &dbcopy($dbcopies{$key}{$idx},$cdom,$cnum,\%lockerrors);
2322: if ($result eq 'ok') {
2323: $newdb{$idx} = $newurl;
2324: } elsif (ref($errors) eq 'HASH') {
2325: $errors->{$key} = 1;
2326: }
2327: push(@msgs,$errtext);
2328: }
1.491 raeburn 2329: }
2330: }
1.529 raeburn 2331: if (ref($params{$key}) eq 'HASH') {
2332: %currparam = %{$params{$key}};
1.492 raeburn 2333: }
2334: my ($errtext,$fatal) = &LONCAPA::map::mapread($key);
2335: if ($fatal) {
1.533 raeburn 2336: return ($errtext);
1.492 raeburn 2337: }
2338: for (my $i=0; $i<@LONCAPA::map::zombies; $i++) {
2339: if (defined($LONCAPA::map::zombies[$i])) {
2340: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::zombies[$i]);
1.532 raeburn 2341: if ($zombie{$i} eq $src) {
1.492 raeburn 2342: undef($LONCAPA::map::zombies[$i]);
2343: }
2344: }
2345: }
1.529 raeburn 2346: for (my $i=0; $i<@LONCAPA::map::order; $i++) {
2347: my $idx = $LONCAPA::map::order[$i];
2348: if (defined($LONCAPA::map::resources[$idx])) {
1.492 raeburn 2349: my $changed;
1.529 raeburn 2350: my ($title,$src,$ext,$type)=split(/\:/,$LONCAPA::map::resources[$idx]);
1.538 raeburn 2351: if ((exists($toremove{$idx})) &&
2352: ($toremove{$idx} eq &LONCAPA::map::qtescape($src))) {
1.492 raeburn 2353: splice(@LONCAPA::map::order,$i,1);
1.529 raeburn 2354: if (ref($currparam{$idx}) eq 'ARRAY') {
2355: foreach my $name (@{$currparam{$idx}}) {
2356: &LONCAPA::map::delparameter($idx,'parameter_'.$name);
1.492 raeburn 2357: }
2358: }
2359: next;
2360: }
2361: my $origsrc = $src;
1.532 raeburn 2362: if ((exists($toretitle{$idx})) && ($toretitle{$idx} eq $src)) {
1.492 raeburn 2363: if ($title =~ m{^\d+\Q___&&&___\E$match_username\Q___&&&___\E$match_domain\Q___&&&___\E(.+)$}) {
2364: $changed = 1;
1.491 raeburn 2365: }
1.492 raeburn 2366: }
1.532 raeburn 2367: if ((exists($torewrite{$idx})) && ($torewrite{$idx} eq $src)) {
1.492 raeburn 2368: $src =~ s{^/(uploaded|adm|public)/$match_domain/$match_courseid/}{/$1/$cdom/$cnum/};
2369: if ($origsrc =~ m{^/uploaded/}) {
1.529 raeburn 2370: if ($prefixchg && $before{'map'} && $after{'map'}) {
1.492 raeburn 2371: if ($src =~ /\.(page|sequence)$/) {
1.529 raeburn 2372: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'map'}\E#$1$after{'map'}#;
1.492 raeburn 2373: } else {
1.529 raeburn 2374: $src =~ s#^(/uploaded/$match_domain/$match_courseid/)\Q$before{'doc'}\E#$1$after{'doc'}#;
1.488 raeburn 2375: }
1.491 raeburn 2376: }
1.532 raeburn 2377: if ($origsrc =~ /\.(page|sequence)$/) {
2378: if ($newsubdir{$origsrc}) {
1.529 raeburn 2379: $src =~ s#^(/uploaded/$match_domain/$match_courseid/(?:default|supplemental)_)(\d+)#$1$newsubdir{$origsrc}#;
1.491 raeburn 2380: }
1.532 raeburn 2381: } elsif ($newsubdir{$key}) {
2382: $src =~ s#^(/uploaded/$match_domain/$match_courseid/\w+/)(\d+)#$1$newsubdir{$key}#;
1.488 raeburn 2383: }
2384: }
1.492 raeburn 2385: $changed = 1;
1.533 raeburn 2386: } elsif ($newdb{$idx} ne '') {
2387: $src = $newdb{$idx};
1.492 raeburn 2388: $changed = 1;
2389: }
2390: if ($changed) {
1.538 raeburn 2391: $LONCAPA::map::resources[$idx] = join(':',($title,&LONCAPA::map::qtunescape($src),$ext,$type));
1.492 raeburn 2392: }
2393: }
2394: }
2395: foreach my $idx (keys(%remparam)) {
2396: if (ref($remparam{$idx}) eq 'ARRAY') {
2397: foreach my $name (@{$remparam{$idx}}) {
2398: &LONCAPA::map::delparameter($idx,'parameter_'.$name);
1.491 raeburn 2399: }
2400: }
2401: }
1.533 raeburn 2402: if (values(%lockerrors) > 0) {
2403: $lockmsg = join('<br />',values(%lockerrors));
2404: }
1.491 raeburn 2405: my $storefn;
2406: if ($key eq $oldurl) {
2407: $storefn = $url;
2408: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
2409: } else {
2410: $storefn = $key;
2411: $storefn=~s{^/uploaded/$match_domain/$match_courseid/}{};
1.529 raeburn 2412: if ($prefixchg && $before{'map'} && $after{'map'}) {
2413: $storefn =~ s/^\Q$before{'map'}\E/$after{'map'}/;
1.491 raeburn 2414: }
1.529 raeburn 2415: if ($newsubdir{$key}) {
2416: $storefn =~ s/^((?:default|supplemental)_)(\d+)/$1$newsubdir{$key}/;
1.492 raeburn 2417: }
1.491 raeburn 2418: }
1.492 raeburn 2419: my $report;
2420: if ($folder !~ /^supplemental/) {
2421: $report = 1;
2422: }
1.527 raeburn 2423: (my $outtext,$errtext) =
1.492 raeburn 2424: &LONCAPA::map::storemap("/uploaded/$cdom/$cnum/$storefn",1,$report);
2425: if ($errtext) {
1.529 raeburn 2426: if ($caller eq 'paste') {
1.533 raeburn 2427: return (&mt('Paste failed: an error occurred saving the folder or page.'));
1.529 raeburn 2428: }
1.491 raeburn 2429: }
2430: }
2431: }
1.533 raeburn 2432: return ('ok',\@msgs,$lockmsg);
1.491 raeburn 2433: }
2434:
2435: sub copy_dependencies {
2436: my ($item,$storefn,$relpath,$errors,$contentref) = @_;
2437: my $content;
2438: if (ref($contentref)) {
2439: $content = $$contentref;
2440: } else {
2441: $content = &Apache::lonnet::getfile($item);
2442: }
2443: unless ($content eq '-1') {
2444: my $mm = new File::MMagic;
2445: my $mimetype = $mm->checktype_contents($content);
2446: if ($mimetype eq 'text/html') {
2447: my (%allfiles,%codebase,$state);
2448: my $res = &Apache::lonnet::extract_embedded_items(undef,\%allfiles,\%codebase,\$content);
2449: if ($res eq 'ok') {
2450: my ($numexisting,$numpathchanges,$existing);
2451: (undef,$numexisting,$numpathchanges,$existing) =
2452: &Apache::loncommon::ask_for_embedded_content(
2453: '/adm/coursedocs',$state,\%allfiles,\%codebase,
2454: {'error_on_invalid_names' => 1,
2455: 'ignore_remote_references' => 1,
2456: 'docs_url' => $item,
2457: 'context' => 'paste'});
2458: if ($numexisting > 0) {
2459: if (ref($existing) eq 'HASH') {
2460: foreach my $dep (keys(%{$existing})) {
2461: my $depfile = $dep;
2462: unless ($depfile =~ m{^\Q$relpath\E}) {
2463: $depfile = $relpath.$dep;
2464: }
2465: my $depcontent = &Apache::lonnet::getfile($depfile);
2466: unless ($depcontent eq '-1') {
2467: my $storedep = $dep;
2468: $storedep =~ s{^\Q$relpath\E}{};
2469: my $dep_url =
2470: &Apache::lonclonecourse::writefile(
2471: $env{'request.course.id'},
2472: $storefn.$storedep,$depcontent);
2473: if ($dep_url eq '/adm/notfound.html') {
2474: if (ref($errors) eq 'HASH') {
2475: $errors->{$depfile} = 1;
2476: }
2477: } else {
2478: ©_dependencies($depfile,$storefn,$relpath,$errors,\$depcontent);
2479: }
2480: }
2481: }
1.488 raeburn 2482: }
2483: }
2484: }
2485: }
2486: }
2487: return;
2488: }
2489:
1.329 droeschl 2490: my %parameter_type = ( 'randompick' => 'int_pos',
2491: 'hiddenresource' => 'string_yesno',
2492: 'encrypturl' => 'string_yesno',
2493: 'randomorder' => 'string_yesno',);
2494: my $valid_parameters_re = join('|',keys(%parameter_type));
2495: # set parameters
2496: sub update_parameter {
1.537 raeburn 2497: if ($env{'form.changeparms'} eq 'all') {
2498: my (@allidx,@allmapidx,%allchecked,%currchecked);
2499: %allchecked = (
2500: 'hiddenresource' => {},
2501: 'encrypturl' => {},
2502: 'randompick' => {},
2503: 'randomorder' => {},
2504: );
2505: foreach my $which (keys(%allchecked)) {
2506: $env{'form.all'.$which} =~ s/,$//;
2507: if ($which eq 'randompick') {
2508: foreach my $item (split(/,/,$env{'form.all'.$which})) {
2509: my ($res,$value) = split(/:/,$item);
2510: if ($value =~ /^\d+$/) {
2511: $allchecked{$which}{$res} = $value;
2512: }
2513: }
2514: } else {
1.539 raeburn 2515: if ($env{'form.all'.$which}) {
2516: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.all'.$which});
2517: }
1.537 raeburn 2518: }
2519: }
2520: my $haschanges = 0;
2521: foreach my $res (@LONCAPA::map::order) {
2522: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
2523: $name=&LONCAPA::map::qtescape($name);
2524: $url=&LONCAPA::map::qtescape($url);
2525: next unless ($name && $url);
2526: my $is_map;
2527: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
2528: $is_map = 1;
2529: }
2530: foreach my $which (keys(%allchecked)) {
2531: if (($which eq 'randompick' || $which eq 'randomorder')) {
2532: next if (!$is_map);
2533: }
2534: my $oldvalue = 0;
2535: my $newvalue = 0;
2536: if ($allchecked{$which}{$res}) {
2537: $newvalue = $allchecked{$which}{$res};
2538: }
2539: my $current = (&LONCAPA::map::getparameter($res,'parameter_'.$which))[0];
2540: if ($which eq 'randompick') {
2541: if ($current =~ /^(\d+)$/) {
2542: $oldvalue = $1;
2543: }
2544: } else {
2545: if ($current =~ /^yes$/i) {
2546: $oldvalue = 1;
2547: }
2548: }
2549: if ($oldvalue ne $newvalue) {
2550: $haschanges = 1;
2551: if ($newvalue) {
2552: my $storeval = 'yes';
2553: if ($which eq 'randompick') {
2554: $storeval = $newvalue;
2555: }
2556: &LONCAPA::map::storeparameter($res,'parameter_'.$which,
2557: $storeval,
2558: $parameter_type{$which});
2559: &remember_parms($res,$which,'set',$storeval);
2560: } elsif ($oldvalue) {
2561: &LONCAPA::map::delparameter($res,'parameter_'.$which);
2562: &remember_parms($res,$which,'del');
2563: }
2564: }
2565: }
2566: }
2567: return $haschanges;
2568: } else {
2569: return 0 if ($env{'form.changeparms'} !~ /^($valid_parameters_re)$/);
1.329 droeschl 2570:
1.537 raeburn 2571: my $which = $env{'form.changeparms'};
2572: my $idx = $env{'form.setparms'};
2573: if ($env{'form.'.$which.'_'.$idx}) {
2574: my $value = ($which eq 'randompick') ? $env{'form.rpicknum_'.$idx}
2575: : 'yes';
2576: &LONCAPA::map::storeparameter($idx, 'parameter_'.$which, $value,
2577: $parameter_type{$which});
2578: &remember_parms($idx,$which,'set',$value);
2579: } else {
2580: &LONCAPA::map::delparameter($idx,'parameter_'.$which);
1.329 droeschl 2581:
1.537 raeburn 2582: &remember_parms($idx,$which,'del');
2583: }
2584: return 1;
1.329 droeschl 2585: }
2586: }
2587:
2588:
2589: sub handle_edit_cmd {
2590: my ($coursenum,$coursedom) =@_;
1.543 raeburn 2591: if ($env{'form.cmd'} eq '') {
2592: return 0;
2593: }
1.329 droeschl 2594: my ($cmd,$idx)=split('_',$env{'form.cmd'});
2595:
2596: my $ratstr = $LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
2597: my ($title, $url, @rrest) = split(':', $ratstr);
2598:
1.538 raeburn 2599: if ($cmd eq 'remove') {
1.329 droeschl 2600: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
1.463 www 2601: ($url!~/$LONCAPA::assess_page_seq_re/)) {
1.329 droeschl 2602: &Apache::lonnet::removeuploadedurl($url);
2603: } else {
2604: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
2605: }
2606: splice(@LONCAPA::map::order, $idx, 1);
2607:
2608: } elsif ($cmd eq 'cut') {
2609: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
2610: splice(@LONCAPA::map::order, $idx, 1);
2611:
1.344 bisitz 2612: } elsif ($cmd eq 'up'
1.329 droeschl 2613: && ($idx) && (defined($LONCAPA::map::order[$idx-1]))) {
2614: @LONCAPA::map::order[$idx-1,$idx] = @LONCAPA::map::order[$idx,$idx-1];
2615:
2616: } elsif ($cmd eq 'down'
2617: && defined($LONCAPA::map::order[$idx+1])) {
2618: @LONCAPA::map::order[$idx+1,$idx] = @LONCAPA::map::order[$idx,$idx+1];
2619:
2620: } elsif ($cmd eq 'rename') {
2621: my $comment = &LONCAPA::map::qtunescape($env{'form.title'});
2622: if ($comment=~/\S/) {
2623: $LONCAPA::map::resources[$LONCAPA::map::order[$idx]]=
2624: $comment.':'.join(':', $url, @rrest);
2625: }
2626: # Devalidate title cache
2627: my $renamed_url=&LONCAPA::map::qtescape($url);
2628: &Apache::lonnet::devalidate_title_cache($renamed_url);
1.538 raeburn 2629:
1.329 droeschl 2630: } else {
2631: return 0;
2632: }
2633: return 1;
2634: }
2635:
2636: sub editor {
1.458 raeburn 2637: my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$crstype,
1.508 raeburn 2638: $supplementalflag,$orderhash,$iconpath,$pathitem)=@_;
1.519 raeburn 2639: my ($randompick,$ishidden,$isencrypted,$plain,$is_random_order,$container);
1.510 raeburn 2640: if ($allowed) {
1.519 raeburn 2641: (my $breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,
2642: $is_random_order,$container) =
1.510 raeburn 2643: &Apache::lonhtmlcommon::docs_breadcrumbs($allowed,$crstype,1);
2644: $r->print($breadcrumbtrail);
1.519 raeburn 2645: } elsif ($env{'form.folderpath'} =~ /\:1$/) {
2646: $container = 'page';
2647: } else {
2648: $container = 'sequence';
1.510 raeburn 2649: }
1.484 raeburn 2650:
1.525 raeburn 2651: my $jumpto;
2652:
2653: unless ($supplementalflag) {
1.546 raeburn 2654: $jumpto = "uploaded/$coursedom/$coursenum/$folder.$container";
1.525 raeburn 2655: }
1.484 raeburn 2656:
2657: unless ($allowed) {
2658: $randompick = -1;
2659: }
2660:
1.329 droeschl 2661: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
2662: $folder.'.'.$container);
2663: return $errtext if ($fatal);
2664:
2665: if ($#LONCAPA::map::order<1) {
2666: my $idx=&LONCAPA::map::getresidx();
2667: if ($idx<=0) { $idx=1; }
2668: $LONCAPA::map::order[0]=$idx;
2669: $LONCAPA::map::resources[$idx]='';
2670: }
1.364 bisitz 2671:
1.329 droeschl 2672: # ------------------------------------------------------------ Process commands
2673:
2674: # ---------------- if they are for this folder and user allowed to make changes
2675: if (($allowed) && ($env{'form.folder'} eq $folder)) {
2676: # set parameters and change order
2677: &snapshotbefore();
2678:
2679: if (&update_parameter()) {
2680: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
2681: return $errtext if ($fatal);
2682: }
2683:
2684: if ($env{'form.newpos'} && $env{'form.currentpos'}) {
2685: # change order
2686: my $res = splice(@LONCAPA::map::order,$env{'form.currentpos'}-1,1);
2687: splice(@LONCAPA::map::order,$env{'form.newpos'}-1,0,$res);
2688:
2689: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
2690: return $errtext if ($fatal);
2691: }
1.364 bisitz 2692:
1.329 droeschl 2693: if ($env{'form.pastemarked'}) {
1.491 raeburn 2694: my %paste_errors;
1.533 raeburn 2695: my ($paste_res,$save_error,$pastemsgarray,$lockerror) =
1.492 raeburn 2696: &do_paste_from_buffer($coursenum,$coursedom,$folder,$container,
2697: \%paste_errors);
1.541 raeburn 2698: if (ref($pastemsgarray) eq 'ARRAY') {
2699: if (@{$pastemsgarray} > 0) {
2700: $r->print('<p class="LC_info">'.
2701: join('<br />',@{$pastemsgarray}).
1.533 raeburn 2702: '</p>');
2703: }
1.541 raeburn 2704: }
2705: if ($lockerror) {
2706: $r->print('<p class="LC_error">'.
2707: $lockerror.
2708: '</p>');
2709: }
2710: if ($save_error ne '') {
2711: return $save_error;
2712: }
2713: if ($paste_res) {
2714: my %errortext = &Apache::lonlocal::texthash (
2715: fail => 'Storage of folder contents failed',
2716: failread => 'Reading folder contents failed',
2717: failstore => 'Storage of folder contents failed',
2718: );
2719: if ($errortext{$paste_res}) {
2720: $r->print('<p class="LC_error">'.$errortext{$paste_res}.'</p>');
1.492 raeburn 2721: }
1.329 droeschl 2722: }
1.491 raeburn 2723: if (keys(%paste_errors) > 0) {
1.538 raeburn 2724: $r->print('<p class="LC_warning">'."\n".
1.491 raeburn 2725: &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".
2726: '<ul>'."\n");
2727: foreach my $key (sort(keys(%paste_errors))) {
2728: $r->print('<li>'.$key.'</li>'."\n");
2729: }
2730: $r->print('</ul></p>'."\n");
2731: }
1.538 raeburn 2732: } elsif ($env{'form.clearmarked'}) {
2733: my $output = &do_buffer_empty();
2734: if ($output) {
2735: $r->print('<p class="LC_info">'.$output.'</p>');
2736: }
2737: }
1.329 droeschl 2738:
2739: $r->print($upload_output);
2740:
1.538 raeburn 2741: # Rename, cut, copy or remove a single resource
1.329 droeschl 2742: if (&handle_edit_cmd()) {
1.492 raeburn 2743: my $contentchg;
1.538 raeburn 2744: if ($env{'form.cmd'} =~ m{^(del|cut)_}) {
1.492 raeburn 2745: $contentchg = 1;
2746: }
2747: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container,$contentchg);
1.329 droeschl 2748: return $errtext if ($fatal);
2749: }
1.538 raeburn 2750:
2751: # Cut, copy and/or remove multiple resources
2752: if ($env{'form.multichange'}) {
2753: my %allchecked = (
2754: cut => {},
2755: remove => {},
2756: );
2757: my $needsupdate;
2758: foreach my $which (keys(%allchecked)) {
2759: $env{'form.multi'.$which} =~ s/,$//;
2760: if ($env{'form.multi'.$which}) {
2761: map { $allchecked{$which}{$_} = 1; } split(/,/,$env{'form.multi'.$which});
2762: if (ref($allchecked{$which}) eq 'HASH') {
2763: $needsupdate += scalar(keys(%{$allchecked{$which}}));
2764: }
2765: }
2766: }
2767: if ($needsupdate) {
2768: my $haschanges = 0;
2769: my %curr_groups = &Apache::longroup::coursegroups();
2770: my $total = scalar(@LONCAPA::map::order) - 1;
2771: for (my $i=$total; $i>=0; $i--) {
2772: my $res = $LONCAPA::map::order[$i];
2773: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
2774: $name=&LONCAPA::map::qtescape($name);
2775: $url=&LONCAPA::map::qtescape($url);
2776: next unless ($name && $url);
2777: my %denied =
2778: &action_restrictions($coursenum,$coursedom,$url,
2779: $env{'form.folderpath'},\%curr_groups);
2780: foreach my $which (keys(%allchecked)) {
2781: next if ($denied{$which});
2782: next unless ($allchecked{$which}{$res});
2783: if ($which eq 'remove') {
2784: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
2785: ($url!~/$LONCAPA::assess_page_seq_re/)) {
2786: &Apache::lonnet::removeuploadedurl($url);
2787: } else {
2788: &LONCAPA::map::makezombie($res);
2789: }
2790: splice(@LONCAPA::map::order,$i,1);
2791: $haschanges ++;
2792: } elsif ($which eq 'cut') {
2793: &LONCAPA::map::makezombie($res);
2794: splice(@LONCAPA::map::order,$i,1);
2795: $haschanges ++;
2796: }
2797: }
2798: }
2799: if ($haschanges) {
2800: ($errtext,$fatal) =
2801: &storemap($coursenum,$coursedom,$folder.'.'.$container,1);
2802: return $errtext if ($fatal);
2803: }
2804: }
2805: }
2806:
1.329 droeschl 2807: # Group import/search
2808: if ($env{'form.importdetail'}) {
2809: my @imports;
2810: foreach my $item (split(/\&/,$env{'form.importdetail'})) {
2811: if (defined($item)) {
2812: my ($name,$url,$residx)=
1.533 raeburn 2813: map { &unescape($_); } split(/\=/,$item);
2814: if ($url =~ m{^\Q/uploaded/$coursedom/$coursenum/\E(default|supplemental)_new\.(sequence|page)$}) {
2815: my ($suffix,$errortxt,$locknotfreed) =
2816: &new_timebased_suffix($coursedom,$coursenum,'map',$1,$2);
1.504 raeburn 2817: if ($locknotfreed) {
2818: $r->print($locknotfreed);
2819: }
2820: if ($suffix) {
2821: $url =~ s/_new\./_$suffix./;
2822: } else {
2823: return $errortxt;
2824: }
1.533 raeburn 2825: } elsif ($url =~ m{^/adm/$match_domain/$match_username/new/(smppg|bulletinboard)$}) {
2826: my $type = $1;
2827: my ($suffix,$errortxt,$locknotfreed) =
2828: &new_timebased_suffix($coursedom,$coursenum,$type);
2829: if ($locknotfreed) {
2830: $r->print($locknotfreed);
2831: }
2832: if ($suffix) {
2833: $url =~ s{^(/adm/$match_domain/$match_username)/new}{$1/$suffix};
2834: } else {
2835: return $errortxt;
2836: }
1.534 raeburn 2837: } elsif ($url =~ m{^/uploaded/$coursedom/$coursenum/(docs|supplemental)/(default|\d+)/new.html$}) {
2838: if ($supplementalflag) {
2839: next unless ($1 eq 'supplemental');
2840: if ($folder eq 'supplemental') {
2841: next unless ($2 eq 'default');
2842: } else {
2843: next unless ($folder eq 'supplemental_'.$2);
2844: }
2845: } else {
2846: next unless ($1 eq 'docs');
2847: if ($folder eq 'default') {
2848: next unless ($2 eq 'default');
2849: } else {
2850: next unless ($folder eq 'default_'.$2);
2851: }
2852: }
1.504 raeburn 2853: }
1.329 droeschl 2854: push(@imports, [$name, $url, $residx]);
2855: }
2856: }
1.530 raeburn 2857: ($errtext,$fatal,my $fixuperrors) =
1.529 raeburn 2858: &group_import($coursenum, $coursedom, $folder,$container,
2859: 'londocs',@imports);
1.329 droeschl 2860: return $errtext if ($fatal);
1.529 raeburn 2861: if ($fixuperrors) {
2862: $r->print($fixuperrors);
2863: }
1.329 droeschl 2864: }
2865: # Loading a complete map
2866: if ($env{'form.loadmap'}) {
2867: if ($env{'form.importmap'}=~/\w/) {
2868: foreach my $res (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
2869: my ($title,$url,$ext,$type)=split(/\:/,$res);
2870: my $idx=&LONCAPA::map::getresidx($url);
2871: $LONCAPA::map::resources[$idx]=$res;
2872: $LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx;
2873: }
2874: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.492 raeburn 2875: $folder.'.'.$container,1);
1.329 droeschl 2876: return $errtext if ($fatal);
2877: } else {
2878: $r->print('<p><span class="LC_error">'.&mt('No map selected.').'</span></p>');
1.364 bisitz 2879:
1.329 droeschl 2880: }
2881: }
2882: &log_differences($plain);
2883: }
2884: # ---------------------------------------------------------------- End commands
2885: # ---------------------------------------------------------------- Print screen
2886: my $idx=0;
2887: my $shown=0;
2888: if (($ishidden) || ($isencrypted) || ($randompick>=0) || ($is_random_order)) {
1.381 bisitz 2889: $r->print('<div class="LC_Box">'.
1.432 raeburn 2890: '<ol class="LC_docs_parameters"><li class="LC_docs_parameters_title">'.&mt('Parameters:').'</li>'.
2891: ($randompick>=0?'<li>'.&mt('randomly pick [quant,_1,resource]',$randompick).'</li>':'').
2892: ($ishidden?'<li>'.&mt('contents hidden').'</li>':'').
2893: ($isencrypted?'<li>'.&mt('URLs hidden').'</li>':'').
2894: ($is_random_order?'<li>'.&mt('random order').'</li>':'').
1.431 raeburn 2895: '</ol>');
1.381 bisitz 2896: if ($randompick>=0) {
2897: $r->print('<p class="LC_warning">'
2898: .&mt('Caution: this folder is set to randomly pick a subset'
2899: .' of resources. Adding or removing resources from this'
2900: .' folder will change the set of resources that the'
2901: .' students see, resulting in spurious or missing credit'
2902: .' for completed problems, not limited to ones you'
2903: .' modify. Do not modify the contents of this folder if'
2904: .' it is in active student use.')
2905: .'</p>'
2906: );
2907: }
2908: if ($is_random_order) {
2909: $r->print('<p class="LC_warning">'
2910: .&mt('Caution: this folder is set to randomly order its'
2911: .' contents. Adding or removing resources from this folder'
2912: .' will change the order of resources shown.')
2913: .'</p>'
2914: );
2915: }
2916: $r->print('</div>');
1.364 bisitz 2917: }
1.381 bisitz 2918:
1.538 raeburn 2919: my ($to_show,$output,@allidx,@allmapidx,%filters,%lists,%curr_groups);
2920: %filters = (
1.543 raeburn 2921: canremove => [],
2922: cancut => [],
2923: cancopy => [],
2924: hiddenresource => [],
2925: encrypturl => [],
2926: randomorder => [],
2927: randompick => [],
1.538 raeburn 2928: );
2929: %curr_groups = &Apache::longroup::coursegroups();
1.424 onken 2930: &Apache::loncommon::start_data_table_count(); #setup a row counter
1.381 bisitz 2931: foreach my $res (@LONCAPA::map::order) {
2932: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
2933: $name=&LONCAPA::map::qtescape($name);
2934: $url=&LONCAPA::map::qtescape($url);
2935: unless ($name) { $name=(split(/\//,$url))[-1]; }
2936: unless ($name) { $idx++; next; }
1.537 raeburn 2937: push(@allidx,$res);
2938: if ($url =~ m{/uploaded/.+\.(page|sequence)$}) {
2939: push(@allmapidx,$res);
2940: }
1.381 bisitz 2941: $output .= &entryline($idx,$name,$url,$folder,$allowed,$res,
1.501 raeburn 2942: $coursenum,$coursedom,$crstype,
1.538 raeburn 2943: $pathitem,$supplementalflag,$container,
2944: \%filters,\%curr_groups);
1.381 bisitz 2945: $idx++;
2946: $shown++;
1.329 droeschl 2947: }
1.424 onken 2948: &Apache::loncommon::end_data_table_count();
1.510 raeburn 2949:
1.538 raeburn 2950: my $need_save;
1.510 raeburn 2951: if (($allowed) || ($supplementalflag && $folder eq 'supplemental')) {
1.544 raeburn 2952: my $toolslink;
2953: if ($allowed || &Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
2954: $toolslink = '<table><tr><td>'
1.520 raeburn 2955: .&Apache::loncommon::help_open_menu('Navigation Screen',
2956: 'Navigation_Screen',undef,'RAT')
2957: .'</td><td class="LC_middle">'.&mt('Tools:').'</td>'
2958: .'<td align="left"><ul id="LC_toolbar">'
1.525 raeburn 2959: .'<li><a href="/adm/coursedocs?forcesupplement=1&command=editsupp" '
1.520 raeburn 2960: .'id="LC_content_toolbar_edittoplevel" '
2961: .'class="LC_toolbarItem" '
2962: .'title="'.&mt('Supplemental Content Editor').'">'
2963: .'</a></li></ul></td></tr></table><br />';
1.544 raeburn 2964: }
1.510 raeburn 2965: if ($shown) {
2966: if ($allowed) {
2967: $to_show = &Apache::loncommon::start_scrollbox('900px','880px','400px','contentscroll')
2968: .&Apache::loncommon::start_data_table(undef,'contentlist')
2969: .&Apache::loncommon::start_data_table_header_row()
2970: .'<th colspan="2">'.&mt('Move').'</th>'
1.538 raeburn 2971: .'<th colspan="2">'.&mt('Actions').'</th>'
2972: .'<th>'.&mt('Document').'</th>';
1.510 raeburn 2973: if ($folder !~ /^supplemental/) {
2974: $to_show .= '<th colspan="4">'.&mt('Settings').'</th>';
2975: }
1.537 raeburn 2976: $to_show .= &Apache::loncommon::end_data_table_header_row();
2977: if ($folder !~ /^supplemental/) {
1.538 raeburn 2978: $lists{'canhide'} = join(',',@allidx);
2979: $lists{'canrandomlyorder'} = join(',',@allmapidx);
1.543 raeburn 2980: my @possfilters = ('canremove','cancut','cancopy','hiddenresource','encrypturl',
2981: 'randomorder','randompick');
2982: foreach my $item (@possfilters) {
1.538 raeburn 2983: if (ref($filters{$item}) eq 'ARRAY') {
1.543 raeburn 2984: if (@{$filters{$item}} > 0) {
2985: $lists{$item} = join(',',@{$filters{$item}});
2986: }
1.538 raeburn 2987: }
2988: }
1.537 raeburn 2989: if (@allidx > 0) {
2990: my $path;
2991: if ($env{'form.folderpath'}) {
2992: $path =
2993: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
2994: }
1.538 raeburn 2995: if (@allidx > 1) {
2996: $to_show .=
2997: &Apache::loncommon::continue_data_table_row().
2998: '<td colspan="2"> </td>'.
2999: '<td>'.
3000: &multiple_check_form('actions',\%lists).
3001: '</td>'.
3002: '<td> </td>'.
3003: '<td> </td>'.
3004: '<td colspan="4">'.
3005: &multiple_check_form('settings',\%lists).
3006: '</td>'.
3007: &Apache::loncommon::end_data_table_row();
3008: $need_save = 1;
3009: }
1.537 raeburn 3010: }
3011: }
3012: $to_show .= $output.' '
1.510 raeburn 3013: .&Apache::loncommon::end_data_table()
3014: .'<br style="line-height:2px;" />'
3015: .&Apache::loncommon::end_scrollbox();
3016: } else {
1.520 raeburn 3017: $to_show .= $toolslink
1.510 raeburn 3018: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3019: .$output.' '
3020: .&Apache::loncommon::end_data_table();
1.393 raeburn 3021: }
1.510 raeburn 3022: } else {
1.520 raeburn 3023: if (!$allowed) {
3024: $to_show .= $toolslink;
3025: }
1.510 raeburn 3026: $to_show .= &Apache::loncommon::start_scrollbox('400px','380px','200px','contentscroll')
3027: .'<div class="LC_info" id="contentlist">'
1.550 raeburn 3028: .&mt('Currently empty')
1.510 raeburn 3029: .'</div>'
3030: .&Apache::loncommon::end_scrollbox();
1.393 raeburn 3031: }
3032: } else {
1.510 raeburn 3033: if ($shown) {
3034: $to_show = '<div>'
3035: .&Apache::loncommon::start_data_table('LC_tableOfContent')
3036: .$output
3037: .&Apache::loncommon::end_data_table()
3038: .'</div>';
3039: } else {
3040: $to_show = '<div class="LC_info" id="contentlist">'
1.550 raeburn 3041: .&mt('Currently empty')
1.510 raeburn 3042: .'</div>'
3043: }
1.458 raeburn 3044: }
3045: my $tid = 1;
3046: if ($supplementalflag) {
3047: $tid = 2;
1.329 droeschl 3048: }
3049: if ($allowed) {
1.484 raeburn 3050: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
1.538 raeburn 3051: $r->print(&generate_edit_table($tid,$orderhash,$to_show,$iconpath,
3052: $jumpto,$readfile,$need_save,"$folder.$container"));
1.492 raeburn 3053: &print_paste_buffer($r,$container,$folder,$coursedom,$coursenum);
1.460 raeburn 3054: } else {
3055: $r->print($to_show);
1.329 droeschl 3056: }
3057: return;
3058: }
3059:
1.538 raeburn 3060: sub multiple_check_form {
3061: my ($caller,$listsref) = @_;
3062: return unless (ref($listsref) eq 'HASH');
3063: my $output =
3064: '<form action="/adm/coursedocs" method="post" name="togglemult'.$caller.'">'.
3065: '<span class="LC_nobreak" style="font-size:x-small;font-weight:bold;">'.
3066: '<label><input type="radio" name="showmultpick" value="0" onclick="javascript:togglePick('."'$caller','0'".');" checked="checked" />'.&mt('one').'</label>'.(' 'x2).'<label><input type="radio" name="showmultpick" value="1" onclick="javascript:togglePick('."'$caller','1'".');" />'.&mt('multiple').'</label></span><span id="more'.$caller.'" class="LC_nobreak LC_docs_ext_edit"></span></form>'.
3067: '<div id="multi'.$caller.'" style="display:none;margin:0;padding:0;border:0">'.
3068: '<form action="/adm/coursedocs" method="post" name="cumulative'.$caller.'">'."\n".
3069: '<fieldset id="allfields'.$caller.'" style="display:none"><legend style="font-size:x-small;">'.&mt('check/uncheck all').'</legend>'."\n";
3070: if ($caller eq 'settings') {
3071: $output .=
3072: '<table><tr>'.
3073: '<td class="LC_docs_entry_parameter">'.
3074: '<span class="LC_nobreak"><label>'.
3075: '<input type="checkbox" name="hiddenresourceall" id="hiddenresourceall" onclick="propagateState(this.form,'."'hiddenresource'".')" />'.&mt('Hidden').
3076: '</label></span></td>'.
3077: '<td class="LC_docs_entry_parameter">'.
3078: '<span class="LC_nobreak"><label><input type="checkbox" name="randompickall" id="randompickall" onclick="updatePick(this.form,'."'all','check'".');propagateState(this.form,'."'randompick'".');propagateState(this.form,'."'rpicknum'".');" />'.&mt('Randomly Pick').'</label><span id="rpicktextall"></span><input type="hidden" name="rpicknumall" id="rpicknumall" value="" />'.
3079: '</span></td>'.
3080: '</tr>'."\n".
3081: '<tr>'.
3082: '<td class="LC_docs_entry_parameter">'.
3083: '<span class="LC_nobreak"><label><input type="checkbox" name="encrypturlall" id="encrypturlall" onclick="propagateState(this.form,'."'encrypturl'".')" />'.&mt('URL hidden').'</label></span></td><td class="LC_docs_entry_parameter"><span class="LC_nobreak"><label><input type="checkbox" name="randomorderall" id="randomorderall" onclick="propagateState(this.form,'."'randomorder'".')" />'.&mt('Random Order').
3084: '</label></span>'.
3085: '</td></tr></table>'."\n";
3086: } else {
3087: $output .=
3088: '<table><tr>'.
3089: '<td class="LC_docs_entry_parameter">'.
3090: '<span class="LC_nobreak LC_docs_remove">'.
3091: '<label><input type="checkbox" name="removeall" id="removeall" onclick="propagateState(this.form,'."'remove'".')" />'.&mt('Remove').
3092: '</label></span></td>'.
3093: '<td class="LC_docs_entry_parameter">'.
3094: '<span class="LC_nobreak LC_docs_cut">'.
3095: '<label><input type="checkbox" name="cut" id="cutall" onclick="propagateState(this.form,'."'cut'".');" />'.&mt('Cut').
3096: '</label></span></td>'."\n".
3097: '<td class="LC_docs_entry_parameter">'.
3098: '<span class="LC_nobreak LC_docs_copy">'.
3099: '<label><input type="checkbox" name="copyall" id="copyall" onclick="propagateState(this.form,'."'copy'".')" />'.&mt('Copy').
3100: '</label></span></td>'.
3101: '</tr></table>'."\n";
3102: }
3103: $output .=
3104: '</fieldset>'.
3105: '<input type="hidden" name="allidx" value="'.$listsref->{'canhide'}.'" />';
3106: if ($caller eq 'settings') {
3107: $output .=
1.543 raeburn 3108: '<input type="hidden" name="allmapidx" value="'.$listsref->{'canrandomlyorder'}.'" />'."\n".
3109: '<input type="hidden" name="currhiddenresource" value="'.$listsref->{'hiddenresource'}.'" />'."\n".
3110: '<input type="hidden" name="currencrypturl" value="'.$listsref->{'encrypturl'}.'" />'."\n".
3111: '<input type="hidden" name="currrandomorder" value="'.$listsref->{'randomorder'}.'" />'."\n".
3112: '<input type="hidden" name="currrandompick" value="'.$listsref->{'randompick'}.'" />'."\n";
1.538 raeburn 3113: } elsif ($caller eq 'actions') {
3114: $output .=
3115: '<input type="hidden" name="allremoveidx" id="allremoveidx" value="'.$listsref->{'canremove'}.'" />'.
3116: '<input type="hidden" name="allcutidx" id="allcutidx" value="'.$listsref->{'cancut'}.'" />'.
3117: '<input type="hidden" name="allcopyidx" id="allcopyidx" value="'.$listsref->{'cancopy'}.'" />';
3118: }
3119: $output .=
3120: '</form>'.
3121: '</div>';
3122: return $output;
3123: }
3124:
1.329 droeschl 3125: sub process_file_upload {
1.552 raeburn 3126: my ($upload_output,$coursenum,$coursedom,$allfiles,$codebase,$uploadcmd,$crstype) = @_;
1.329 droeschl 3127: # upload a file, if present
1.552 raeburn 3128: my $filesize = length($env{'form.uploaddoc'});
3129: if (!$filesize) {
3130: $$upload_output = '<div class="LC_error">'.
3131: &mt('Unable to upload [_1]. (size = [_2] bytes)',
3132: '<span class="LC_filename">'.$env{'form.uploaddoc.filename'}.'</span>',
3133: $filesize).'<br />'.
3134: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
3135: '</div>';
3136: return;
3137: }
3138: my $quotatype = 'unofficial';
3139: if ($crstype eq 'Community') {
3140: $quotatype = 'community';
3141: } elsif ($env{'course.'.$coursedom.'_'.$coursenum.'.internal.instcode'}) {
3142: $quotatype = 'official';
3143: }
3144: if (&Apache::loncommon::get_user_quota($coursenum,$coursedom,'course',$quotatype)) {
3145: $filesize = int($filesize/1000); #expressed in kb
3146: $$upload_output = &Apache::loncommon::excess_filesize_warning($coursenum,$coursedom,'course',
3147: $env{'form.uploaddoc.filename'},$filesize,'upload');
3148: return if ($$upload_output);
3149: }
1.440 raeburn 3150: my ($parseaction,$showupload,$nextphase,$mimetype);
3151: if ($env{'form.parserflag'}) {
1.329 droeschl 3152: $parseaction = 'parse';
3153: }
3154: my $folder=$env{'form.folder'};
3155: if ($folder eq '') {
3156: $folder='default';
3157: }
3158: if ( ($folder=~/^$uploadcmd/) || ($uploadcmd eq 'default') ) {
3159: my $errtext='';
3160: my $fatal=0;
3161: my $container='sequence';
1.519 raeburn 3162: if ($env{'form.folderpath'} =~ /:1$/) {
1.329 droeschl 3163: $container='page';
3164: }
3165: ($errtext,$fatal)=
1.534 raeburn 3166: &mapread($coursenum,$coursedom,$folder.'.'.$container);
1.329 droeschl 3167: if ($#LONCAPA::map::order<1) {
3168: $LONCAPA::map::order[0]=1;
3169: $LONCAPA::map::resources[1]='';
3170: }
3171: my $destination = 'docs/';
3172: if ($folder =~ /^supplemental/) {
3173: $destination = 'supplemental/';
3174: }
3175: if (($folder eq 'default') || ($folder eq 'supplemental')) {
3176: $destination .= 'default/';
3177: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
3178: $destination .= $2.'/';
3179: }
1.534 raeburn 3180: if ($fatal) {
3181: $$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>';
3182: return;
3183: }
1.440 raeburn 3184: # this is for a course, not a user, so set context to coursedoc.
1.329 droeschl 3185: my $newidx=&LONCAPA::map::getresidx();
3186: $destination .= $newidx;
1.439 raeburn 3187: my $url=&Apache::lonnet::userfileupload('uploaddoc','coursedoc',$destination,
1.329 droeschl 3188: $parseaction,$allfiles,
1.440 raeburn 3189: $codebase,undef,undef,undef,undef,
3190: undef,undef,\$mimetype);
3191: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E.*/([^/]+)$}) {
3192: my $stored = $1;
3193: $showupload = '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
3194: $stored.'</span>').'</p>';
3195: } else {
3196: my ($filename) = ($env{'form.uploaddoc.filename'} =~ m{([^/]+)$});
3197:
1.457 raeburn 3198: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.&mt('Unable to save file [_1].','<span class="LC_filename">'.$filename.'</span>').'</div>';
1.440 raeburn 3199: return;
3200: }
1.329 droeschl 3201: my $ext='false';
3202: if ($url=~m{^http://}) { $ext='true'; }
3203: $url = &LONCAPA::map::qtunescape($url);
3204: my $comment=$env{'form.comment'};
3205: $comment = &LONCAPA::map::qtunescape($comment);
3206: if ($folder=~/^supplemental/) {
3207: $comment=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
3208: $env{'user.domain'}.'___&&&___'.$comment;
3209: }
3210:
3211: $LONCAPA::map::resources[$newidx]=
3212: $comment.':'.$url.':'.$ext.':normal:res';
3213: $LONCAPA::map::order[$#LONCAPA::map::order+1]= $newidx;
3214: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1.492 raeburn 3215: $folder.'.'.$container,1);
1.329 droeschl 3216: if ($fatal) {
1.457 raeburn 3217: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.$errtext.'</div>';
1.440 raeburn 3218: return;
1.329 droeschl 3219: } else {
1.440 raeburn 3220: if ($parseaction eq 'parse' && $mimetype eq 'text/html') {
3221: $$upload_output = $showupload;
1.384 raeburn 3222: my $total_embedded = scalar(keys(%{$allfiles}));
1.329 droeschl 3223: if ($total_embedded > 0) {
1.440 raeburn 3224: my $uploadphase = 'upload_embedded';
3225: my $primaryurl = &HTML::Entities::encode($url,'<>&"');
3226: my $state = &embedded_form_elems($uploadphase,$primaryurl,$newidx);
3227: my ($embedded,$num) =
3228: &Apache::loncommon::ask_for_embedded_content(
3229: '/adm/coursedocs',$state,$allfiles,$codebase,{'docs_url' => $url});
3230: if ($embedded) {
3231: if ($num) {
3232: $$upload_output .=
3233: '<p>'.&mt('This file contains embedded multimedia objects, which need to be uploaded.').'</p>'.$embedded;
3234: $nextphase = $uploadphase;
3235: } else {
3236: $$upload_output .= $embedded;
3237: }
3238: } else {
3239: $$upload_output .= &mt('Embedded item(s) already present, so no additional upload(s) required').'<br />';
3240: }
1.329 droeschl 3241: } else {
1.440 raeburn 3242: $$upload_output .= &mt('No embedded items identified').'<br />';
1.329 droeschl 3243: }
1.457 raeburn 3244: $$upload_output = '<div id="uploadfileresult">'.$$upload_output.'</div>';
1.476 raeburn 3245: } elsif (&Apache::loncommon::is_archive_file($mimetype)) {
3246: $nextphase = 'decompress_uploaded';
3247: my $position = scalar(@LONCAPA::map::order)-1;
3248: my $noextract = &return_to_editor();
3249: my $archiveurl = &HTML::Entities::encode($url,'<>&"');
3250: my %archiveitems = (
3251: folderpath => $env{'form.folderpath'},
3252: cmd => $nextphase,
3253: newidx => $newidx,
3254: position => $position,
3255: phase => $nextphase,
1.477 raeburn 3256: comment => $comment,
1.480 raeburn 3257: );
3258: my ($destination,$dir_root) = &embedded_destination($coursenum,$coursedom);
3259: my @current = &get_dir_list($url,$coursenum,$coursedom,$newidx);
1.476 raeburn 3260: $$upload_output = $showupload.
3261: &Apache::loncommon::decompress_form($mimetype,
3262: $archiveurl,'/adm/coursedocs',$noextract,
1.480 raeburn 3263: \%archiveitems,\@current);
1.329 droeschl 3264: }
3265: }
3266: }
1.440 raeburn 3267: return $nextphase;
1.329 droeschl 3268: }
3269:
1.480 raeburn 3270: sub get_dir_list {
3271: my ($url,$coursenum,$coursedom,$newidx) = @_;
3272: my ($destination,$dir_root) = &embedded_destination();
3273: my ($dirlistref,$listerror) =
3274: &Apache::lonnet::dirlist("$dir_root/$destination/$newidx",$coursedom,$coursenum,1);
3275: my @dir_lines;
3276: my $dirptr=16384;
3277: if (ref($dirlistref) eq 'ARRAY') {
3278: foreach my $dir_line (sort
3279: {
3280: my ($afile)=split('&',$a,2);
3281: my ($bfile)=split('&',$b,2);
3282: return (lc($afile) cmp lc($bfile));
3283: } (@{$dirlistref})) {
3284: my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$dir_line,16);
3285: $filename =~ s/\s+$//;
3286: next if ($filename =~ /^\.\.?$/);
3287: my $isdir = 0;
3288: if ($dirptr&$testdir) {
3289: $isdir = 1;
3290: }
3291: push(@dir_lines, [$filename,$dom,$isdir,$size,$mtime,$obs]);
3292: }
3293: }
3294: return @dir_lines;
3295: }
3296:
1.329 droeschl 3297: sub is_supplemental_title {
3298: my ($title) = @_;
3299: return scalar($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/);
3300: }
3301:
3302: # --------------------------------------------------------------- An entry line
3303:
3304: sub entryline {
1.501 raeburn 3305: my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$coursedom,
1.538 raeburn 3306: $crstype,$pathitem,$supplementalflag,$container,$filtersref,$currgroups)=@_;
1.519 raeburn 3307: my ($foldertitle,$renametitle);
1.329 droeschl 3308: if (&is_supplemental_title($title)) {
1.488 raeburn 3309: ($title,$foldertitle,$renametitle) = &Apache::loncommon::parse_supplemental_title($title);
1.329 droeschl 3310: } else {
3311: $title=&HTML::Entities::encode($title,'"<>&\'');
3312: $renametitle=$title;
3313: $foldertitle=$title;
3314: }
3315:
3316: my $orderidx=$LONCAPA::map::order[$index];
1.364 bisitz 3317:
1.329 droeschl 3318: $renametitle=~s/\\/\\\\/g;
3319: $renametitle=~s/\"\;/\\\"/g;
3320: $renametitle=~s/ /%20/g;
1.379 bisitz 3321: my $line=&Apache::loncommon::start_data_table_row();
1.538 raeburn 3322: my ($form_start,$form_end,$form_common,$form_param);
1.329 droeschl 3323: # Edit commands
1.535 raeburn 3324: my ($esc_path, $path, $symb);
1.329 droeschl 3325: if ($env{'form.folderpath'}) {
3326: $esc_path=&escape($env{'form.folderpath'});
3327: $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3328: # $htmlfoldername=&HTML::Entities::encode($env{'form.foldername'},'<>&"');
3329: }
1.505 raeburn 3330: my $isexternal;
1.510 raeburn 3331: if ($residx) {
1.501 raeburn 3332: my $currurl = $url;
3333: $currurl =~ s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
1.505 raeburn 3334: if ($currurl =~ m{^/adm/wrapper/ext/}) {
3335: $isexternal = 1;
3336: }
1.510 raeburn 3337: if (!$supplementalflag) {
3338: my $path = 'uploaded/'.
3339: $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
3340: $env{'course.'.$env{'request.course.id'}.'.num'}.'/';
3341: $symb = &Apache::lonnet::encode_symb($path.$folder.".$container",
3342: $residx,
3343: &Apache::lonnet::declutter($currurl));
3344: }
1.501 raeburn 3345: }
1.538 raeburn 3346: my ($renamelink,%lt,$ishash);
3347: if (ref($filtersref) eq 'HASH') {
3348: $ishash = 1;
3349: }
3350:
1.329 droeschl 3351: if ($allowed) {
1.538 raeburn 3352: $form_start = '
3353: <form action="/adm/coursedocs" method="post">
3354: ';
3355: $form_common=(<<END);
3356: <input type="hidden" name="folderpath" value="$path" />
3357: <input type="hidden" name="symb" value="$symb" />
3358: END
3359: $form_param=(<<END);
3360: <input type="hidden" name="setparms" value="$orderidx" />
3361: <input type="hidden" name="changeparms" value="0" />
3362: END
3363: $form_end = '</form>';
3364:
1.329 droeschl 3365: my $incindex=$index+1;
3366: my $selectbox='';
1.471 raeburn 3367: if (($#LONCAPA::map::order>0) &&
1.329 droeschl 3368: ((split(/\:/,
1.344 bisitz 3369: $LONCAPA::map::resources[$LONCAPA::map::order[0]]))[1]
3370: ne '') &&
1.329 droeschl 3371: ((split(/\:/,
1.344 bisitz 3372: $LONCAPA::map::resources[$LONCAPA::map::order[1]]))[1]
1.329 droeschl 3373: ne '')) {
3374: $selectbox=
3375: '<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
1.373 bisitz 3376: '<select name="newpos" onchange="this.form.submit()">';
1.329 droeschl 3377: for (my $i=1;$i<=$#LONCAPA::map::order+1;$i++) {
3378: if ($i==$incindex) {
1.358 bisitz 3379: $selectbox.='<option value="" selected="selected">('.$i.')</option>';
1.329 droeschl 3380: } else {
3381: $selectbox.='<option value="'.$i.'">'.$i.'</option>';
3382: }
3383: }
3384: $selectbox.='</select>';
3385: }
1.501 raeburn 3386: %lt=&Apache::lonlocal::texthash(
1.329 droeschl 3387: 'up' => 'Move Up',
3388: 'dw' => 'Move Down',
3389: 'rm' => 'Remove',
3390: 'ct' => 'Cut',
3391: 'rn' => 'Rename',
1.501 raeburn 3392: 'cp' => 'Copy',
3393: 'ex' => 'External Resource',
3394: 'ed' => 'Edit',
3395: 'pr' => 'Preview',
3396: 'sv' => 'Save',
3397: 'ul' => 'URL',
3398: 'ti' => 'Title',
3399: );
1.538 raeburn 3400: my %denied = &action_restrictions($coursenum,$coursedom,$url,
3401: $env{'form.folderpath'},
3402: $currgroups);
1.517 raeburn 3403: my ($copylink,$cutlink,$removelink);
1.329 droeschl 3404: my $skip_confirm = 0;
3405: if ( $folder =~ /^supplemental/
3406: || ($url =~ m{( /smppg$
3407: |/syllabus$
3408: |/aboutme$
3409: |/navmaps$
3410: |/bulletinboard$
1.505 raeburn 3411: |\.html$)}x)
3412: || $isexternal) {
1.329 droeschl 3413: $skip_confirm = 1;
3414: }
3415:
1.538 raeburn 3416: if ($denied{'copy'}) {
1.543 raeburn 3417: $copylink=(<<ENDCOPY)
1.507 raeburn 3418: <span style="visibility: hidden;">$lt{'cp'}</span>
3419: ENDCOPY
3420: } else {
1.538 raeburn 3421: my $formname = 'edit_copy_'.$orderidx;
3422: my $js = "javascript:checkForSubmit(document.forms.renameform,'copy','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.329 droeschl 3423: $copylink=(<<ENDCOPY);
1.538 raeburn 3424: <form name="$formname" method="post" action="/adm/coursedocs">
3425: $form_common
1.540 raeburn 3426: <input type="checkbox" name="copy" id="copy_$orderidx" value="$orderidx" onclick="javascript:singleCheck(this,'$orderidx','copy');" class="LC_hidden" /><a href="$js" class="LC_docs_copy">$lt{'cp'}</a>
1.538 raeburn 3427: $form_end
1.329 droeschl 3428: ENDCOPY
1.538 raeburn 3429: if (($ishash) && (ref($filtersref->{'cancopy'}) eq 'ARRAY')) {
3430: push(@{$filtersref->{'cancopy'}},$orderidx);
3431: }
1.329 droeschl 3432: }
1.538 raeburn 3433: if ($denied{'cut'}) {
1.507 raeburn 3434: $cutlink=(<<ENDCUT);
3435: <span style="visibility: hidden;">$lt{'ct'}</span>
3436: ENDCUT
3437: } else {
1.538 raeburn 3438: my $formname = 'edit_cut_'.$orderidx;
3439: my $js = "javascript:checkForSubmit(document.forms.renameform,'cut','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm,'$container','$folder');";
1.329 droeschl 3440: $cutlink=(<<ENDCUT);
1.538 raeburn 3441: <form name="$formname" method="post" action="/adm/coursedocs">
3442: $form_common
1.542 raeburn 3443: <input type="hidden" name="skip_$orderidx" id="skip_cut_$orderidx" value="$skip_confirm" />
1.540 raeburn 3444: <input type="checkbox" name="cut" id="cut_$orderidx" value="$orderidx" onclick="javascript:singleCheck(this,'$orderidx','cut');" class="LC_hidden" /><a href="$js" class="LC_docs_cut">$lt{'ct'}</a>
1.538 raeburn 3445: $form_end
1.329 droeschl 3446: ENDCUT
1.538 raeburn 3447: if (($ishash) && (ref($filtersref->{'cancut'}) eq 'ARRAY')) {
3448: push(@{$filtersref->{'cancut'}},$orderidx);
3449: }
1.329 droeschl 3450: }
1.538 raeburn 3451: if ($denied{'remove'}) {
1.507 raeburn 3452: $removelink=(<<ENDREM);
3453: <span style="visibility: hidden;">$lt{'rm'}</a>
3454: ENDREM
3455: } else {
1.538 raeburn 3456: my $formname = 'edit_remove_'.$orderidx;
3457: my $js = "javascript:checkForSubmit(document.forms.renameform,'remove','actions','$orderidx','$esc_path','$index','$renametitle',$skip_confirm);";
1.497 raeburn 3458: $removelink=(<<ENDREM);
1.538 raeburn 3459: <form name="$formname" method="post" action="/adm/coursedocs">
3460: $form_common
1.542 raeburn 3461: <input type="hidden" name="skip_$orderidx" id="skip_remove_$orderidx" value="$skip_confirm" />
1.540 raeburn 3462: <input type="checkbox" name="remove" id="remove_$orderidx" value="$orderidx" onclick="javascript:singleCheck(this,'$orderidx','remove');" class="LC_hidden" /><a href="$js" class="LC_docs_remove">$lt{'rm'}</a>
1.538 raeburn 3463: $form_end
1.497 raeburn 3464: ENDREM
1.538 raeburn 3465: if (($ishash) && (ref($filtersref->{'canremove'}) eq 'ARRAY')) {
3466: push(@{$filtersref->{'canremove'}},$orderidx);
3467: }
1.497 raeburn 3468: }
1.551 raeburn 3469: $renamelink=(<<ENDREN);
1.519 raeburn 3470: <a href='javascript:changename("$esc_path","$index","$renametitle");' class="LC_docs_rename">$lt{'rn'}</a>
1.507 raeburn 3471: ENDREN
1.329 droeschl 3472: $line.=(<<END);
3473: <td>
1.379 bisitz 3474: <div class="LC_docs_entry_move">
1.535 raeburn 3475: <a href='/adm/coursedocs?cmd=up_$index&folderpath=$esc_path&symb=$symb'>
1.501 raeburn 3476: <img src="${iconpath}move_up.gif" alt="$lt{'up'}" class="LC_icon" />
1.379 bisitz 3477: </a>
3478: </div>
3479: <div class="LC_docs_entry_move">
1.536 raeburn 3480: <a href='/adm/coursedocs?cmd=down_$index&folderpath=$esc_path&symb=$symb'>
1.501 raeburn 3481: <img src="${iconpath}move_down.gif" alt="$lt{'dw'}" class="LC_icon" />
1.379 bisitz 3482: </a>
3483: </div>
1.329 droeschl 3484: </td>
3485: <td>
3486: $form_start
1.538 raeburn 3487: $form_param
1.478 raeburn 3488: $form_common
1.329 droeschl 3489: $selectbox
3490: $form_end
3491: </td>
1.540 raeburn 3492: <td class="LC_docs_entry_commands LC_nobreak">
1.497 raeburn 3493: $removelink
1.329 droeschl 3494: $cutlink
3495: $copylink
3496: </td>
3497: END
3498: }
3499: # Figure out what kind of a resource this is
3500: my ($extension)=($url=~/\.(\w+)$/);
3501: my $uploaded=($url=~/^\/*uploaded\//);
3502: my $icon=&Apache::loncommon::icon($url);
1.519 raeburn 3503: my $isfolder;
3504: my $ispage;
3505: my $containerarg;
1.329 droeschl 3506: if ($uploaded) {
1.472 raeburn 3507: if (($extension eq 'sequence') || ($extension eq 'page')) {
3508: $url=~/\Q$coursenum\E\/([\/\w]+)\.\Q$extension\E$/;
1.519 raeburn 3509: $containerarg = $1;
1.472 raeburn 3510: if ($extension eq 'sequence') {
3511: $icon=$iconpath.'navmap.folder.closed.gif';
3512: $isfolder=1;
3513: } else {
3514: $icon=$iconpath.'page.gif';
3515: $ispage=1;
3516: }
3517: if ($allowed) {
3518: $url='/adm/coursedocs?';
3519: } else {
3520: $url='/adm/supplemental?';
3521: }
1.329 droeschl 3522: } else {
3523: &Apache::lonnet::allowuploaded('/adm/coursedoc',$url);
3524: }
3525: }
1.364 bisitz 3526:
1.518 raeburn 3527: my ($editlink,$extresform);
1.329 droeschl 3528: my $orig_url = $url;
1.340 raeburn 3529: $orig_url=~s{http(:|:)//https(:|:)//}{https$2//};
1.510 raeburn 3530: $url=~s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
1.501 raeburn 3531: if (!$supplementalflag && $residx && $symb) {
3532: if ((!$isfolder) && (!$ispage)) {
3533: (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
3534: $url=&Apache::lonnet::clutter($url);
3535: if ($url=~/^\/*uploaded\//) {
3536: $url=~/\.(\w+)$/;
3537: my $embstyle=&Apache::loncommon::fileembstyle($1);
3538: if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
3539: $url='/adm/wrapper'.$url;
3540: } elsif ($embstyle eq 'ssi') {
3541: #do nothing with these
3542: } elsif ($url!~/\.(sequence|page)$/) {
3543: $url='/adm/coursedocs/showdoc'.$url;
3544: }
3545: } elsif ($url=~m|^/ext/|) {
3546: $url='/adm/wrapper'.$url;
1.329 droeschl 3547: }
1.501 raeburn 3548: if (&Apache::lonnet::symbverify($symb,$url)) {
3549: $url.=(($url=~/\?/)?'&':'?').'symb='.&escape($symb);
3550: } else {
3551: $url='';
3552: }
1.329 droeschl 3553: }
3554: }
1.478 raeburn 3555: my ($rand_pick_text,$rand_order_text);
1.519 raeburn 3556: if ($isfolder || $ispage || $extension eq 'sequence' || $extension eq 'page') {
1.329 droeschl 3557: my $foldername=&escape($foldertitle);
3558: my $folderpath=$env{'form.folderpath'};
3559: if ($folderpath) { $folderpath.='&' };
1.510 raeburn 3560: if (!$allowed && $supplementalflag) {
1.519 raeburn 3561: $folderpath.=$containerarg.'&'.$foldername;
1.510 raeburn 3562: $url.='folderpath='.&escape($folderpath);
3563: } else {
1.344 bisitz 3564: # Append randompick number, hidden, and encrypted with ":" to foldername,
1.329 droeschl 3565: # so it gets transferred between levels
1.519 raeburn 3566: $folderpath.=$containerarg.'&'.$foldername.
1.510 raeburn 3567: ':'.(&LONCAPA::map::getparameter($orderidx,
1.329 droeschl 3568: 'parameter_randompick'))[0]
3569: .':'.((&LONCAPA::map::getparameter($orderidx,
3570: 'parameter_hiddenresource'))[0]=~/^yes$/i)
3571: .':'.((&LONCAPA::map::getparameter($orderidx,
3572: 'parameter_encrypturl'))[0]=~/^yes$/i)
3573: .':'.((&LONCAPA::map::getparameter($orderidx,
1.519 raeburn 3574: 'parameter_randomorder'))[0]=~/^yes$/i)
3575: .':'.$ispage;
1.510 raeburn 3576: $url.='folderpath='.&escape($folderpath);
3577: my $rpicknum = (&LONCAPA::map::getparameter($orderidx,
3578: 'parameter_randompick'))[0];
3579: my $rpckchk;
3580: if ($rpicknum) {
3581: $rpckchk = ' checked="checked"';
1.543 raeburn 3582: if (($ishash) && (ref($filtersref->{'randompick'}) eq 'ARRAY')) {
3583: push(@{$filtersref->{'randompick'}},$orderidx.':'.$rpicknum);
3584: }
1.510 raeburn 3585: }
1.537 raeburn 3586: my $formname = 'edit_randompick_'.$orderidx;
1.510 raeburn 3587: $rand_pick_text =
1.478 raeburn 3588: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.538 raeburn 3589: $form_param."\n".
1.478 raeburn 3590: $form_common."\n".
1.537 raeburn 3591: '<span class="LC_nobreak"><label><input type="checkbox" name="randompick_'.$orderidx.'" id="randompick_'.$orderidx.'" onclick="'."updatePick(this.form,'$orderidx','check');".'"'.$rpckchk.' /> '.&mt('Randomly Pick').'</label><input type="hidden" name="rpicknum_'.$orderidx.'" id="rpicknum_'.$orderidx.'" value="'.$rpicknum.'" /><span id="randompicknum_'.$orderidx.'">';
1.510 raeburn 3592: if ($rpicknum ne '') {
3593: $rand_pick_text .= ': <a href="javascript:updatePick('."document.$formname,'$orderidx','link'".')">'.$rpicknum.'</a>';
3594: }
1.537 raeburn 3595: $rand_pick_text .= '</span></span>'.
3596: $form_end;
1.543 raeburn 3597: my $ro_set;
3598: if ((&LONCAPA::map::getparameter($orderidx,'parameter_randomorder'))[0]=~/^yes$/i) {
3599: $ro_set = 'checked="checked"';
3600: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
3601: push(@{$filtersref->{'randomorder'}},$orderidx);
3602: }
3603: }
1.564 raeburn 3604: $formname = 'edit_rorder_'.$orderidx;
1.510 raeburn 3605: $rand_order_text =
1.537 raeburn 3606: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1.538 raeburn 3607: $form_param."\n".
1.537 raeburn 3608: $form_common."\n".
1.538 raeburn 3609: '<span class="LC_nobreak"><label><input type="checkbox" name="randomorder_'.$orderidx.'" id="randomorder_'.$orderidx.'" onclick="checkForSubmit(this.form,'."'randomorder','settings'".');" '.$ro_set.' /> '.&mt('Random Order').' </label></span>'.
1.537 raeburn 3610: $form_end;
1.510 raeburn 3611: }
1.509 raeburn 3612: } elsif ($supplementalflag && !$allowed) {
1.510 raeburn 3613: $url .= ($url =~ /\?/) ? '&':'?';
1.509 raeburn 3614: $url .= 'folderpath='.&HTML::Entities::encode($esc_path,'<>&"');
1.510 raeburn 3615: if ($title) {
3616: $url .= '&title='.&HTML::Entities::encode($renametitle,'<>&"');
3617: }
1.511 raeburn 3618: if ($isexternal && $orderidx) {
1.510 raeburn 3619: $url .= '&idx='.$orderidx;
3620: }
1.329 droeschl 3621: }
1.519 raeburn 3622: my ($tdalign,$tdwidth);
1.501 raeburn 3623: if ($allowed) {
3624: my $fileloc =
3625: &Apache::lonnet::declutter(&Apache::lonnet::filelocation('',$orig_url));
1.510 raeburn 3626: if ($isexternal) {
1.518 raeburn 3627: ($editlink,$extresform) =
1.510 raeburn 3628: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem);
1.511 raeburn 3629: } elsif (!$isfolder && !$ispage) {
1.503 raeburn 3630: my ($cfile,$home,$switchserver,$forceedit,$forceview) =
3631: &Apache::lonnet::can_edit_resource($fileloc,$coursenum,$coursedom,$orig_url);
1.511 raeburn 3632: if (($cfile ne '') && ($symb ne '' || $supplementalflag)) {
1.501 raeburn 3633: my $jscall =
3634: &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,
3635: $switchserver,
1.503 raeburn 3636: $forceedit,
1.511 raeburn 3637: undef,$symb,
3638: &escape($env{'form.folderpath'}),
1.524 raeburn 3639: $renametitle,'','',1);
1.501 raeburn 3640: if ($jscall) {
1.518 raeburn 3641: $editlink = '<a class="LC_docs_ext_edit" href="javascript:'.
3642: $jscall.'" >'.&mt('Edit').'</a> '."\n";
1.501 raeburn 3643: }
3644: }
3645: }
1.519 raeburn 3646: $tdalign = ' align="right" valign="top"';
3647: $tdwidth = ' width="80%"';
1.329 droeschl 3648: }
1.408 raeburn 3649: my $reinit;
3650: if ($crstype eq 'Community') {
3651: $reinit = &mt('(re-initialize community to access)');
3652: } else {
3653: $reinit = &mt('(re-initialize course to access)');
1.519 raeburn 3654: }
3655: $line.='<td class="LC_docs_entry_commands"'.$tdalign.'><span class="LC_nobreak">'.$editlink.$renamelink;
1.472 raeburn 3656: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.469 www 3657: $line.='<a href="'.$url.'"><img src="'.$icon.'" alt="" class="LC_icon" /></a>';
3658: } elsif ($url) {
1.484 raeburn 3659: $line.=&Apache::loncommon::modal_link($url.(($url=~/\?/)?'&':'?').'inhibitmenu=yes',
1.470 raeburn 3660: '<img src="'.$icon.'" alt="" class="LC_icon" />',600,500);
1.469 www 3661: } else {
3662: $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
3663: }
1.519 raeburn 3664: $line.='</span></td><td'.$tdwidth.'>';
1.472 raeburn 3665: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.469 www 3666: $line.='<a href="'.$url.'">'.$title.'</a>';
3667: } elsif ($url) {
1.484 raeburn 3668: $line.=&Apache::loncommon::modal_link($url.(($url=~/\?/)?'&':'?').'inhibitmenu=yes',
1.470 raeburn 3669: $title,600,500);
1.469 www 3670: } else {
3671: $line.=$title.' <span class="LC_docs_reinit_warn">'.$reinit.'</span>';
3672: }
1.518 raeburn 3673: $line.="$extresform</td>";
1.478 raeburn 3674: $rand_pick_text = ' ' if ($rand_pick_text eq '');
3675: $rand_order_text = ' ' if ($rand_order_text eq '');
1.329 droeschl 3676: if (($allowed) && ($folder!~/^supplemental/)) {
3677: my %lt=&Apache::lonlocal::texthash(
3678: 'hd' => 'Hidden',
3679: 'ec' => 'URL hidden');
1.543 raeburn 3680: my ($enctext,$hidtext);
3681: if ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i) {
3682: $enctext = ' checked="checked"';
3683: if (($ishash) && (ref($filtersref->{'encrypturl'}) eq 'ARRAY')) {
3684: push(@{$filtersref->{'encrypturl'}},$orderidx);
3685: }
3686: }
3687: if ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i) {
3688: $hidtext = ' checked="checked"';
3689: if (($ishash) && (ref($filtersref->{'randomorder'}) eq 'ARRAY')) {
3690: push(@{$filtersref->{'hiddenresource'}},$orderidx);
3691: }
3692: }
1.537 raeburn 3693: my $formhidden = 'edit_hiddenresource_'.$orderidx;
3694: my $formurlhidden = 'edit_encrypturl_'.$orderidx;
1.329 droeschl 3695: $line.=(<<ENDPARMS);
3696: <td class="LC_docs_entry_parameter">
1.537 raeburn 3697: <form action="/adm/coursedocs" method="post" name="$formhidden">
1.538 raeburn 3698: $form_param
1.478 raeburn 3699: $form_common
1.538 raeburn 3700: <label><input type="checkbox" name="hiddenresource_$orderidx" id="hiddenresource_$orderidx" onclick="checkForSubmit(this.form,'hiddenresource','settings');" $hidtext /> $lt{'hd'}</label>
1.329 droeschl 3701: $form_end
1.458 raeburn 3702: <br />
1.537 raeburn 3703: <form action="/adm/coursedocs" method="post" name="$formurlhidden">
1.538 raeburn 3704: $form_param
1.478 raeburn 3705: $form_common
1.538 raeburn 3706: <label><input type="checkbox" name="encrypturl_$orderidx" id="encrypturl_$orderidx" onclick="checkForSubmit(this.form,'encrypturl','settings');" $enctext /> $lt{'ec'}</label>
1.329 droeschl 3707: $form_end
3708: </td>
1.478 raeburn 3709: <td class="LC_docs_entry_parameter">$rand_pick_text<br />
3710: $rand_order_text</td>
1.329 droeschl 3711: ENDPARMS
3712: }
1.379 bisitz 3713: $line.=&Apache::loncommon::end_data_table_row();
1.329 droeschl 3714: return $line;
3715: }
3716:
1.538 raeburn 3717: sub action_restrictions {
3718: my ($cnum,$cdom,$url,$folderpath,$currgroups) = @_;
3719: my %denied = (
3720: cut => 0,
3721: copy => 0,
3722: remove => 0,
3723: );
3724: if ($url=~ m{^/res/.+\.(page|sequence)$}) {
3725: # no copy for published maps
3726: $denied{'copy'} = 1;
3727: } elsif ($url=~m{^/res/lib/templates/}) {
3728: $denied{'copy'} = 1;
3729: $denied{'cut'} = 1;
3730: } elsif ($url eq "/uploaded/$cdom/$cnum/group_allfolders.sequence") {
3731: if ($folderpath =~ /^default&[^\&]+$/) {
3732: if ((ref($currgroups) eq 'HASH') && (keys(%{$currgroups}) > 0)) {
3733: $denied{'remove'} = 1;
3734: }
3735: $denied{'cut'} = 1;
3736: $denied{'copy'} = 1;
3737: }
3738: } elsif ($url =~ m{^\Q/uploaded/$cdom/$cnum/group_folder_\E(\w+)\.sequence$}) {
3739: my $group = $1;
3740: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+$/) {
3741: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
3742: $denied{'remove'} = 1;
3743: }
3744: }
3745: $denied{'cut'} = 1;
3746: $denied{'copy'} = 1;
3747: } elsif ($url =~ m{^\Q/adm/$cdom/$cnum/\E(\w+)/smppg$}) {
3748: my $group = $1;
3749: if ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&\Qgroup_folder_$group\E\&[^\&]+$/) {
3750: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
3751: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
3752: if (keys(%groupsettings) > 0) {
3753: $denied{'remove'} = 1;
3754: }
3755: $denied{'cut'} = 1;
3756: $denied{'copy'} = 1;
3757: }
3758: }
3759: } elsif ($folderpath =~ /^default&[^\&]+\&group_allfolders\&[^\&]+\&group_folder_(\w+)\&/) {
3760: my $group = $1;
3761: if ($url =~ /group_boards_\Q$group\E/) {
3762: if ((ref($currgroups) eq 'HASH') && (exists($currgroups->{$group}))) {
3763: my %groupsettings = &Apache::longroup::get_group_settings($currgroups->{$group});
3764: if (keys(%groupsettings) > 0) {
3765: if (ref($groupsettings{'functions'}) eq 'HASH') {
3766: if ($groupsettings{'functions'}{'discussion'} eq 'on') {
3767: $denied{'remove'} = 1;
3768: }
3769: }
3770: }
3771: $denied{'cut'} = 1;
3772: $denied{'copy'} = 1;
3773: }
3774: }
3775: }
3776: return %denied;
3777: }
3778:
1.533 raeburn 3779: sub new_timebased_suffix {
1.538 raeburn 3780: my ($dom,$num,$type,$area,$container) = @_;
1.533 raeburn 3781: my ($prefix,$namespace,$idtype,$errtext,$locknotfreed);
1.538 raeburn 3782: if ($type eq 'paste') {
3783: $prefix = $type;
3784: $namespace = 'courseeditor';
3785: } elsif ($type eq 'map') {
1.533 raeburn 3786: $prefix = 'docs';
3787: if ($area eq 'supplemental') {
3788: $prefix = 'supp';
3789: }
3790: $prefix .= $container;
3791: $namespace = 'uploadedmaps';
3792: } else {
3793: $prefix = $type;
3794: $namespace = 'templated';
1.504 raeburn 3795: }
3796: $idtype = 'concat';
3797: my ($suffix,$freedlock,$error) =
1.538 raeburn 3798: &Apache::lonnet::get_timebased_id($prefix,'num',$namespace,$dom,$num);
1.504 raeburn 3799: if (!$suffix) {
1.538 raeburn 3800: if ($type eq 'paste') {
3801: $errtext = &mt('Failed to acquire a unique timestamp-based suffix when adding to the paste buffer.');
3802: } elsif ($type eq 'map') {
1.533 raeburn 3803: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new folder/page.');
3804: } elsif ($type eq 'smppg') {
3805: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new simple page.');
3806: } else {
1.565 bisitz 3807: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new discussion board.');
1.533 raeburn 3808: }
1.504 raeburn 3809: if ($error) {
3810: $errtext .= '<br />'.$error;
3811: }
3812: }
3813: if ($freedlock ne 'ok') {
1.533 raeburn 3814: $locknotfreed =
3815: '<div class="LC_error">'.
3816: &mt('There was a problem removing a lockfile.').' ';
1.538 raeburn 3817: if ($type eq 'paste') {
3818: &mt('This will prevent use of the paste buffer until th next log-in.');
3819: } elsif ($type eq 'map') {
1.533 raeburn 3820: &mt('This will prevent creation of additional folders or composite pages in this course.');
3821: } elsif ($type eq 'smppg') {
3822: $locknotfreed .=
3823: &mt('This will prevent creation of additional simple pages in this course.');
3824: } else {
3825: $locknotfreed .=
1.565 bisitz 3826: &mt('This will prevent creation of additional discussion boards in this course.');
1.533 raeburn 3827: }
1.538 raeburn 3828: unless ($type eq 'paste') {
3829: $locknotfreed .=
1.560 raeburn 3830: ' '.&mt('Please contact the [_1]helpdesk[_2] for assistance.',
3831: '<a href="/adm/helpdesk" target="_helpdesk">','</a>');
1.538 raeburn 3832: }
3833: $locknotfreed .= '</div>';
1.504 raeburn 3834: }
3835: return ($suffix,$errtext,$locknotfreed);
3836: }
3837:
1.329 droeschl 3838: =pod
3839:
3840: =item tiehash()
3841:
3842: tie the hash
3843:
3844: =cut
3845:
3846: sub tiehash {
3847: my ($mode)=@_;
3848: $hashtied=0;
3849: if ($env{'request.course.fn'}) {
3850: if ($mode eq 'write') {
3851: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
3852: &GDBM_WRCREAT(),0640)) {
3853: $hashtied=2;
3854: }
3855: } else {
3856: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
3857: &GDBM_READER(),0640)) {
3858: $hashtied=1;
3859: }
3860: }
1.364 bisitz 3861: }
1.329 droeschl 3862: }
3863:
3864: sub untiehash {
3865: if ($hashtied) { untie %hash; }
3866: $hashtied=0;
3867: return OK;
3868: }
3869:
3870:
3871:
3872:
3873: sub checkonthis {
3874: my ($r,$url,$level,$title)=@_;
3875: $url=&unescape($url);
3876: $alreadyseen{$url}=1;
3877: $r->rflush();
3878: if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
3879: $r->print("\n<br />");
3880: if ($level==0) {
3881: $r->print("<br />");
3882: }
3883: for (my $i=0;$i<=$level*5;$i++) {
3884: $r->print(' ');
3885: }
3886: $r->print('<a href="'.$url.'" target="cat">'.
3887: ($title?$title:$url).'</a> ');
3888: if ($url=~/^\/res\//) {
3889: my $result=&Apache::lonnet::repcopy(
3890: &Apache::lonnet::filelocation('',$url));
3891: if ($result eq 'ok') {
3892: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
3893: $r->rflush();
3894: &Apache::lonnet::countacc($url);
3895: $url=~/\.(\w+)$/;
3896: if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
3897: $r->print('<br />');
3898: $r->rflush();
3899: for (my $i=0;$i<=$level*5;$i++) {
3900: $r->print(' ');
3901: }
3902: $r->print('- '.&mt('Rendering:').' ');
3903: my ($errorcount,$warningcount)=split(/:/,
3904: &Apache::lonnet::ssi_body($url,
3905: ('grade_target'=>'web',
3906: 'return_only_error_and_warning_counts' => 1)));
3907: if (($errorcount) ||
3908: ($warningcount)) {
3909: if ($errorcount) {
1.369 bisitz 3910: $r->print('<img src="/adm/lonMisc/bomb.gif" alt="'.&mt('bomb').'" /><span class="LC_error">'.
1.329 droeschl 3911: &mt('[quant,_1,error]',$errorcount).'</span>');
3912: }
3913: if ($warningcount) {
3914: $r->print('<span class="LC_warning">'.
3915: &mt('[quant,_1,warning]',$warningcount).'</span>');
3916: }
3917: } else {
3918: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
3919: }
3920: $r->rflush();
3921: }
3922: my $dependencies=
3923: &Apache::lonnet::metadata($url,'dependencies');
3924: foreach my $dep (split(/\,/,$dependencies)) {
3925: if (($dep=~/^\/res\//) && (!$alreadyseen{$dep})) {
3926: &checkonthis($r,$dep,$level+1);
3927: }
3928: }
3929: } elsif ($result eq 'unavailable') {
3930: $r->print('<span class="LC_error">'.&mt('connection down').'</span>');
3931: } elsif ($result eq 'not_found') {
3932: unless ($url=~/\$/) {
1.521 bisitz 3933: $r->print('<span class="LC_error">'.&mt('not found').'</span>');
1.329 droeschl 3934: } else {
1.366 bisitz 3935: $r->print('<span class="LC_error">'.&mt('unable to verify variable URL').'</span>');
1.329 droeschl 3936: }
3937: } else {
3938: $r->print('<span class="LC_error">'.&mt('access denied').'</span>');
3939: }
3940: }
3941: }
3942: }
3943:
3944:
3945:
3946: =pod
3947:
3948: =item list_symbs()
3949:
1.485 raeburn 3950: List Content Identifiers
1.329 droeschl 3951:
3952: =cut
3953:
3954: sub list_symbs {
3955: my ($r) = @_;
3956:
1.408 raeburn 3957: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 3958: $r->print(&Apache::loncommon::start_page('List of Content Identifiers'));
3959: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Identifiers'));
3960: $r->print(&startContentScreen('tools'));
1.329 droeschl 3961: my $navmap = Apache::lonnavmaps::navmap->new();
3962: if (!defined($navmap)) {
3963: $r->print('<h2>'.&mt('Retrieval of List Failed').'</h2>'.
3964: '<div class="LC_error">'.
3965: &mt('Unable to retrieve information about course contents').
3966: '</div>');
1.408 raeburn 3967: &Apache::lonnet::logthis('Symb list failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
1.329 droeschl 3968: } else {
1.484 raeburn 3969: $r->print('<h4 class="LC_info">'.&mt("$crstype Content Identifiers").'</h4>'.
3970: &Apache::loncommon::start_data_table().
3971: &Apache::loncommon::start_data_table_header_row().
3972: '<th>'.&mt('Title').'</th><th>'.&mt('Identifier').'</th>'.
3973: &Apache::loncommon::end_data_table_header_row()."\n");
3974: my $count;
1.329 droeschl 3975: foreach my $res ($navmap->retrieveResources()) {
1.484 raeburn 3976: $r->print(&Apache::loncommon::start_data_table_row().
3977: '<td>'.$res->compTitle().'</td>'.
3978: '<td>'.$res->symb().'</td>'.
1.521 bisitz 3979: &Apache::loncommon::end_data_table_row());
1.484 raeburn 3980: $count ++;
3981: }
3982: if (!$count) {
3983: $r->print(&Apache::loncommon::start_data_table_row().
3984: '<td colspan="2">'.&mt("$crstype is empty").'</td>'.
3985: &Apache::loncommon::end_data_table_row());
1.329 droeschl 3986: }
1.484 raeburn 3987: $r->print(&Apache::loncommon::end_data_table());
1.329 droeschl 3988: }
1.521 bisitz 3989: $r->print(&endContentScreen());
1.329 droeschl 3990: }
3991:
3992:
3993: sub verifycontent {
3994: my ($r) = @_;
1.408 raeburn 3995: my $crstype = &Apache::loncommon::course_type();
1.549 raeburn 3996: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Content'));
3997: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Content'));
1.484 raeburn 3998: $r->print(&startContentScreen('tools'));
3999: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
1.329 droeschl 4000: $hashtied=0;
4001: undef %alreadyseen;
4002: %alreadyseen=();
4003: &tiehash();
1.484 raeburn 4004:
1.329 droeschl 4005: foreach my $key (keys(%hash)) {
4006: if ($hash{$key}=~/\.(page|sequence)$/) {
4007: if (($key=~/^src_/) && ($alreadyseen{&unescape($hash{$key})})) {
4008: $r->print('<hr /><span class="LC_error">'.
1.419 bisitz 4009: &mt('The following sequence or page is included more than once in your '.$crstype.':').' '.
1.329 droeschl 4010: &unescape($hash{$key}).'</span><br />'.
1.419 bisitz 4011: &mt('Note that grading records for problems included in this sequence or folder will overlap.').'<hr />');
1.329 droeschl 4012: }
4013: }
4014: if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) {
4015: &checkonthis($r,$hash{$key},0,$hash{'title_'.$1});
4016: }
4017: }
4018: &untiehash();
1.442 www 4019: $r->print('<p class="LC_success">'.&mt('Done').'</p>');
1.521 bisitz 4020: $r->print(&endContentScreen());
1.329 droeschl 4021: }
4022:
4023:
4024: sub devalidateversioncache {
4025: my $src=shift;
4026: &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
4027: &Apache::lonnet::clutter($src));
4028: }
4029:
4030: sub checkversions {
4031: my ($r) = @_;
1.408 raeburn 4032: my $crstype = &Apache::loncommon::course_type();
4033: $r->print(&Apache::loncommon::start_page("Check $crstype Document Versions"));
4034: $r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $crstype Document Versions"));
1.484 raeburn 4035: $r->print(&startContentScreen('tools'));
1.442 www 4036:
1.329 droeschl 4037: my $header='';
4038: my $startsel='';
4039: my $monthsel='';
4040: my $weeksel='';
4041: my $daysel='';
4042: my $allsel='';
4043: my %changes=();
4044: my $starttime=0;
4045: my $haschanged=0;
4046: my %setversions=&Apache::lonnet::dump('resourceversions',
4047: $env{'course.'.$env{'request.course.id'}.'.domain'},
4048: $env{'course.'.$env{'request.course.id'}.'.num'});
4049:
4050: $hashtied=0;
4051: &tiehash();
4052: my %newsetversions=();
4053: if ($env{'form.setmostrecent'}) {
4054: $haschanged=1;
4055: foreach my $key (keys(%hash)) {
4056: if ($key=~/^ids\_(\/res\/.+)$/) {
4057: $newsetversions{$1}='mostrecent';
4058: &devalidateversioncache($1);
4059: }
4060: }
4061: } elsif ($env{'form.setcurrent'}) {
4062: $haschanged=1;
4063: foreach my $key (keys(%hash)) {
4064: if ($key=~/^ids\_(\/res\/.+)$/) {
4065: my $getvers=&Apache::lonnet::getversion($1);
4066: if ($getvers>0) {
4067: $newsetversions{$1}=$getvers;
4068: &devalidateversioncache($1);
4069: }
4070: }
4071: }
4072: } elsif ($env{'form.setversions'}) {
4073: $haschanged=1;
4074: foreach my $key (keys(%env)) {
4075: if ($key=~/^form\.set_version_(.+)$/) {
4076: my $src=$1;
4077: if (($env{$key}) && ($env{$key} ne $setversions{$src})) {
4078: $newsetversions{$src}=$env{$key};
4079: &devalidateversioncache($src);
4080: }
4081: }
4082: }
4083: }
4084: if ($haschanged) {
4085: if (&Apache::lonnet::put('resourceversions',\%newsetversions,
4086: $env{'course.'.$env{'request.course.id'}.'.domain'},
1.344 bisitz 4087: $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
1.479 golterma 4088: $r->print(&Apache::loncommon::confirmwrapper(
4089: &Apache::lonhtmlcommon::confirm_success(&mt('Your Version Settings have been Saved'))));
1.329 droeschl 4090: } else {
1.479 golterma 4091: $r->print(&Apache::loncommon::confirmwrapper(
4092: &Apache::lonhtmlcommon::confirm_success(&mt('An Error Occured while Attempting to Save your Version Settings'),1)));
1.329 droeschl 4093: }
4094: &mark_hash_old();
4095: }
4096: &changewarning($r,'');
4097: if ($env{'form.timerange'} eq 'all') {
4098: # show all documents
1.549 raeburn 4099: $header=&mt('All content in '.$crstype);
1.521 bisitz 4100: $allsel=' selected="selected"';
1.329 droeschl 4101: foreach my $key (keys(%hash)) {
4102: if ($key=~/^ids\_(\/res\/.+)$/) {
4103: my $src=$1;
4104: $changes{$src}=1;
4105: }
4106: }
4107: } else {
4108: # show documents which changed
4109: %changes=&Apache::lonnet::dump
4110: ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
4111: $env{'course.'.$env{'request.course.id'}.'.num'});
4112: my $firstkey=(keys(%changes))[0];
4113: unless ($firstkey=~/^error\:/) {
4114: unless ($env{'form.timerange'}) {
4115: $env{'form.timerange'}=604800;
4116: }
4117: my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
4118: .&mt('seconds');
4119: if ($env{'form.timerange'}==-1) {
4120: $seltext='since start of course';
1.521 bisitz 4121: $startsel=' selected="selected"';
1.329 droeschl 4122: $env{'form.timerange'}=time;
4123: }
4124: $starttime=time-$env{'form.timerange'};
4125: if ($env{'form.timerange'}==2592000) {
4126: $seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 4127: $monthsel=' selected="selected"';
1.329 droeschl 4128: } elsif ($env{'form.timerange'}==604800) {
4129: $seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 4130: $weeksel=' selected="selected"';
1.329 droeschl 4131: } elsif ($env{'form.timerange'}==86400) {
4132: $seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1.521 bisitz 4133: $daysel=' selected="selected"';
1.329 droeschl 4134: }
4135: $header=&mt('Content changed').' '.$seltext;
4136: } else {
4137: $header=&mt('No content modifications yet.');
4138: }
4139: }
4140: %setversions=&Apache::lonnet::dump('resourceversions',
4141: $env{'course.'.$env{'request.course.id'}.'.domain'},
4142: $env{'course.'.$env{'request.course.id'}.'.num'});
4143: my %lt=&Apache::lonlocal::texthash
1.408 raeburn 4144: ('st' => 'Version changes since start of '.$crstype,
1.329 droeschl 4145: 'lm' => 'Version changes since last Month',
4146: 'lw' => 'Version changes since last Week',
4147: 'sy' => 'Version changes since Yesterday',
4148: 'al' => 'All Resources (possibly large output)',
1.484 raeburn 4149: 'cd' => 'Change display',
1.329 droeschl 4150: 'sd' => 'Display',
4151: 'fi' => 'File',
4152: 'md' => 'Modification Date',
4153: 'mr' => 'Most recently published Version',
1.408 raeburn 4154: 've' => 'Version used in '.$crstype,
4155: 'vu' => 'Set Version to be used in '.$crstype,
4156: 'sv' => 'Set Versions to be used in '.$crstype.' according to Selections below',
1.329 droeschl 4157: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
4158: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
1.479 golterma 4159: 'di' => 'Differences',
1.484 raeburn 4160: 'save' => 'Save changes',
4161: 'vers' => 'Version choice(s) for specific resources',
1.479 golterma 4162: 'act' => 'Actions');
1.329 droeschl 4163: $r->print(<<ENDHEADERS);
1.484 raeburn 4164: <h4 class="LC_info">$header</h4>
1.329 droeschl 4165: <form action="/adm/coursedocs" method="post">
4166: <input type="hidden" name="versions" value="1" />
1.484 raeburn 4167: <div class="LC_left_float">
1.479 golterma 4168: <fieldset>
1.484 raeburn 4169: <legend>$lt{'cd'}</legend>
1.329 droeschl 4170: <select name="timerange">
1.521 bisitz 4171: <option value='all'$allsel>$lt{'al'}</option>
4172: <option value="-1"$startsel>$lt{'st'}</option>
4173: <option value="2592000"$monthsel>$lt{'lm'}</option>
4174: <option value="604800"$weeksel>$lt{'lw'}</option>
4175: <option value="86400"$daysel>$lt{'sy'}</option>
1.329 droeschl 4176: </select>
4177: <input type="submit" name="display" value="$lt{'sd'}" />
1.484 raeburn 4178: </fieldset>
4179: </div>
4180: <div class="LC_left_float">
4181: <fieldset>
4182: <legend>$lt{'act'}</legend>
4183: $lt{'sm'}: <input type="submit" name="setmostrecent" value="Go" /><br />
4184: $lt{'sc'}: <input type="submit" name="setcurrent" value="Go" />
4185: </fieldset>
4186: </div>
4187: <br clear="all" />
4188: <hr />
4189: <h4>$lt{'vers'}</h4>
1.479 golterma 4190: <input type="submit" name="setversions" value="$lt{'save'}" />
1.329 droeschl 4191: ENDHEADERS
1.479 golterma 4192: #number of columns for version history
4193: $r->print(
1.521 bisitz 4194: &Apache::loncommon::start_data_table().
4195: &Apache::loncommon::start_data_table_header_row().
4196: '<th>'.&mt('Resources').'</th>'.
4197: "<th>$lt{'mr'}</th>".
4198: "<th>$lt{'ve'}</th>".
4199: "<th>$lt{'vu'}</th>".
4200: '<th>'.&mt('History').'</th>'.
4201: &Apache::loncommon::end_data_table_header_row()
4202: );
1.329 droeschl 4203: foreach my $key (sort(keys(%changes))) {
1.496 golterma 4204: #excludes not versionable problems from resource version history:
1.521 bisitz 4205: next unless ($changes{$key}>$starttime && $key !~ /^\/res\/lib\/templates/);
4206: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
4207: my $currentversion=&Apache::lonnet::getversion($key);
4208: if ($currentversion<0) {
4209: $currentversion='<span class="LC_error">'.&mt('Could not be determined.').'</span>';
4210: }
4211: my $linkurl=&Apache::lonnet::clutter($key);
1.479 golterma 4212: $r->print(
4213: &Apache::loncommon::start_data_table_row().
1.521 bisitz 4214: '<td><b>'.&Apache::lonnet::gettitle($linkurl).'</b><br />'.
1.479 golterma 4215: '<a href="'.$linkurl.'" target="cat">'.$linkurl.'</a></td>'.
1.521 bisitz 4216: '<td align="right">'.$currentversion.'<span class="LC_fontsize_medium"><br />('.
1.479 golterma 4217: &Apache::lonlocal::locallocaltime(&Apache::lonnet::metadata($root.'.'.$extension,'lastrevisiondate')).')</span></td>'.
1.521 bisitz 4218: '<td align="right">'
4219: );
4220: # Used in course
4221: my $usedversion=$hash{'version_'.$linkurl};
4222: if (($usedversion) && ($usedversion ne 'mostrecent')) {
4223: if ($usedversion != $currentversion) {
1.479 golterma 4224: $r->print('<span class="LC_warning">'.$usedversion.'</span>');
1.521 bisitz 4225: } else {
1.479 golterma 4226: $r->print($usedversion);
4227: }
1.329 droeschl 4228: } else {
1.521 bisitz 4229: $r->print($currentversion);
1.329 droeschl 4230: }
1.521 bisitz 4231: $r->print('</td><td title="'.$lt{'vu'}.'">');
4232: # Set version
4233: $r->print(&Apache::loncommon::select_form(
4234: $setversions{$linkurl},
4235: 'set_version_'.$linkurl,
4236: {'select_form_order' => ['',1..$currentversion,'mostrecent'],
4237: '' => '',
4238: 'mostrecent' => &mt('most recent'),
4239: map {$_,$_} (1..$currentversion)}));
4240: my $lastold=1;
4241: for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
4242: my $url=$root.'.'.$prevvers.'.'.$extension;
4243: if (&Apache::lonnet::metadata($url,'lastrevisiondate')<$starttime) {
4244: $lastold=$prevvers;
4245: }
4246: }
4247: $r->print('</td>');
4248: # List all available versions
4249: $r->print('<td valign="top"><span class="LC_fontsize_medium">');
4250: for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
4251: my $url=$root.'.'.$prevvers.'.'.$extension;
4252: $r->print(
4253: '<span class="LC_nobreak">'
4254: .'<a href="'.&Apache::lonnet::clutter($url).'">'
4255: .&mt('Version [_1]',$prevvers).'</a>'
4256: .' ('.&Apache::lonlocal::locallocaltime(
4257: &Apache::lonnet::metadata($url,'lastrevisiondate'))
4258: .')');
4259: if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
4260: $r->print(
4261: ' <a href="/adm/diff?filename='.
4262: &Apache::lonnet::clutter($root.'.'.$extension).
4263: &HTML::Entities::encode('&versionone='.$prevvers,'"<>&').
4264: '" target="diffs">'.&mt('Diffs').'</a>');
1.329 droeschl 4265: }
1.521 bisitz 4266: $r->print('</span><br />');
4267: }
4268: $r->print('</span></td>'.&Apache::loncommon::end_data_table_row());
1.329 droeschl 4269: }
1.521 bisitz 4270: $r->print(
4271: &Apache::loncommon::end_data_table().
4272: '<input type="submit" name="setversions" value="'.$lt{'save'}.'" />'.
4273: '</form>'
4274: );
1.329 droeschl 4275:
4276: &untiehash();
1.521 bisitz 4277: $r->print(&endContentScreen());
1.329 droeschl 4278: }
4279:
4280: sub mark_hash_old {
4281: my $retie_hash=0;
4282: if ($hashtied) {
4283: $retie_hash=1;
4284: &untiehash();
4285: }
4286: &tiehash('write');
4287: $hash{'old'}=1;
4288: &untiehash();
4289: if ($retie_hash) { &tiehash(); }
4290: }
4291:
4292: sub is_hash_old {
4293: my $untie_hash=0;
4294: if (!$hashtied) {
4295: $untie_hash=1;
4296: &tiehash();
4297: }
4298: my $return=$hash{'old'};
4299: if ($untie_hash) { &untiehash(); }
4300: return $return;
4301: }
4302:
4303: sub changewarning {
4304: my ($r,$postexec,$message,$url)=@_;
4305: if (!&is_hash_old()) { return; }
4306: my $pathvar='folderpath';
4307: my $path=&escape($env{'form.folderpath'});
4308: if (!defined($url)) {
4309: $url='/adm/coursedocs?'.$pathvar.'='.$path;
4310: }
4311: my $course_type = &Apache::loncommon::course_type();
4312: if (!defined($message)) {
4313: $message='Changes will become active for your current session after [_1], or the next time you log in.';
4314: }
4315: $r->print("\n\n".
1.372 bisitz 4316: '<script type="text/javascript">'."\n".
4317: '// <![CDATA['."\n".
4318: 'function reinit(tf) { tf.submit();'.$postexec.' }'."\n".
4319: '// ]]>'."\n".
1.369 bisitz 4320: '</script>'."\n".
1.375 tempelho 4321: '<form name="reinitform" method="post" action="/adm/roles" target="loncapaclient">'.
1.329 droeschl 4322: '<input type="hidden" name="orgurl" value="'.$url.
1.372 bisitz 4323: '" /><input type="hidden" name="selectrole" value="1" /><p class="LC_warning">'.
1.329 droeschl 4324: &mt($message,' <input type="hidden" name="'.
4325: $env{'request.role'}.'" value="1" /><input type="button" value="'.
1.369 bisitz 4326: &mt('re-initializing '.$course_type).'" onclick="reinit(this.form)" />').
1.372 bisitz 4327: $help{'Caching'}.'</p></form>'."\n\n");
1.329 droeschl 4328: }
4329:
4330:
4331: sub init_breadcrumbs {
4332: my ($form,$text)=@_;
4333: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.484 raeburn 4334: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1",
1.405 bisitz 4335: text=>&Apache::loncommon::course_type().' Editor',
1.329 droeschl 4336: faq=>273,
4337: bug=>'Instructor Interface',
4338: help => 'Docs_Adding_Course_Doc'});
4339: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?".$form.'=1',
4340: text=>$text,
4341: faq=>273,
4342: bug=>'Instructor Interface'});
4343: }
4344:
1.441 www 4345: # subroutine to list form elements
4346: sub create_list_elements {
4347: my @formarr = @_;
4348: my $list = '';
1.501 raeburn 4349: foreach my $button (@formarr){
4350: foreach my $picture (keys(%{$button})) {
4351: $list .= &Apache::lonhtmlcommon::htmltag('li', $picture.' '.$button->{$picture}, {class => 'LC_menubuttons_inline_text', id => ''});
1.441 www 4352: }
4353: }
4354: return $list;
4355: }
1.329 droeschl 4356:
1.441 www 4357: # subroutine to create ul from list elements
4358: sub create_form_ul {
4359: my $list = shift;
4360: my $ul = &Apache::lonhtmlcommon::htmltag('ul',$list, {class => 'LC_ListStyleNormal'});
4361: return $ul;
4362: }
1.329 droeschl 4363:
1.442 www 4364: #
4365: # Start tabs
4366: #
4367:
4368: sub startContentScreen {
1.484 raeburn 4369: my ($mode) = @_;
4370: my $output = '<ul class="LC_TabContentBigger" id="mainnav">';
1.472 raeburn 4371: if (($mode eq 'navmaps') || ($mode eq 'supplemental')) {
1.484 raeburn 4372: $output .= '<li'.(($mode eq 'navmaps')?' class="active"':'').'><a href="/adm/navmaps"><b> '.&mt('Content Overview').' </b></a></li>'."\n";
4373: $output .= '<li'.(($mode eq 'coursesearch')?' class="active"':'').'><a href="/adm/searchcourse"><b> '.&mt('Content Search').' </b></a></li>'."\n";
4374: $output .= '<li'.(($mode eq 'courseindex')?' class="active"':'').'><a href="/adm/indexcourse"><b> '.&mt('Content Index').' </b></a></li>'."\n";
4375: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/supplemental"><b>'.&mt('Supplemental Content').'</b></a></li>';
4376: } else {
1.549 raeburn 4377: $output .= '<li '.(($mode eq 'docs')?' class="active"':'').' id="tabbededitor"><a href="/adm/coursedocs?forcestandard=1"><b> '.&mt('Main Content Editor').' </b></a></li>'."\n";
1.484 raeburn 4378: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/coursedocs?forcesupplement=1"><b>'.&mt('Supplemental Content Editor').'</b></a></li>'."\n";
4379: $output .= '<li '.(($mode eq 'tools')?' class="active"':'').'><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>'."\n";
4380: '><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>';
4381: }
4382: $output .= "\n".'</ul>'."\n";
4383: $output .= '<div class="LC_DocsBox" style="clear:both;margin:0;" id="contenteditor">'.
4384: '<div id="maincoursedoc" style="margin:0 0;padding:0 0;">'.
4385: '<div class="LC_ContentBox" id="mainCourseDocuments" style="display: block;">';
4386: return $output;
1.442 www 4387: }
4388:
4389: #
4390: # End tabs
4391: #
4392:
4393: sub endContentScreen {
1.484 raeburn 4394: return '</div></div></div>';
1.442 www 4395: }
1.329 droeschl 4396:
1.446 www 4397: sub supplemental_base {
1.548 raeburn 4398: return 'supplemental&'.&escape(&mt('Supplemental Content'));
1.446 www 4399: }
4400:
1.329 droeschl 4401: sub handler {
4402: my $r = shift;
4403: &Apache::loncommon::content_type($r,'text/html');
4404: $r->send_http_header;
4405: return OK if $r->header_only;
1.484 raeburn 4406:
4407: # get course data
1.408 raeburn 4408: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 4409: my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
4410: my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
4411:
4412: # graphics settings
4413: $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL').'/');
1.329 droeschl 4414:
1.443 www 4415: #
1.329 droeschl 4416: # --------------------------------------------- Initialize help topics for this
4417: foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',
4418: 'Adding_External_Resource','Navigate_Content',
4419: 'Adding_Folders','Docs_Overview', 'Load_Map',
4420: 'Supplemental','Score_Upload_Form','Adding_Pages',
1.501 raeburn 4421: 'Importing_LON-CAPA_Resource','Importing_IMS_Course',
4422: 'Uploading_From_Harddrive',
1.554 raeburn 4423: 'Check_Resource_Versions','Verify_Content',
4424: 'Course_Roster','Web_Page','Dropbox') {
1.329 droeschl 4425: $help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
4426: }
4427: # Composite help files
4428: $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
4429: 'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
4430: $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
4431: 'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
4432: $help{'Simple Problem'} = &Apache::loncommon::help_open_topic(
4433: 'Option_Response_Simple');
4434: $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
4435: 'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
1.347 weissno 4436: $help{'My Personal Information Page'} = &Apache::loncommon::help_open_topic(
1.329 droeschl 4437: 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
1.353 weissno 4438: $help{'Group Portfolio'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
1.329 droeschl 4439: $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
1.534 raeburn 4440:
1.472 raeburn 4441: my $allowed;
4442: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
4443: unless ($r->uri eq '/adm/supplemental') {
4444: # does this user have privileges to modify content.
4445: $allowed = &Apache::lonnet::allowed('mdc',$env{'request.course.id'});
4446: }
4447:
1.484 raeburn 4448: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['chooseserver',
4449: 'inhibitmenu']);
4450: if ($allowed && $env{'form.chooseserver'}) {
4451: &choose_dump_server($r);
4452: return OK;
4453: } elsif ($allowed && $env{'form.verify'}) {
1.329 droeschl 4454: &init_breadcrumbs('verify','Verify Content');
4455: &verifycontent($r);
4456: } elsif ($allowed && $env{'form.listsymbs'}) {
1.484 raeburn 4457: &init_breadcrumbs('listsymbs','List Content IDs');
1.329 droeschl 4458: &list_symbs($r);
4459: } elsif ($allowed && $env{'form.docslog'}) {
4460: &init_breadcrumbs('docslog','Show Log');
1.484 raeburn 4461: my $folder = $env{'form.folder'};
4462: if ($folder eq '') {
4463: $folder='default';
4464: }
4465: &docs_change_log($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath);
1.329 droeschl 4466: } elsif ($allowed && $env{'form.versions'}) {
4467: &init_breadcrumbs('versions','Check/Set Resource Versions');
4468: &checkversions($r);
4469: } elsif ($allowed && $env{'form.dumpcourse'}) {
1.484 raeburn 4470: &init_breadcrumbs('dumpcourse','Dump '.&Apache::loncommon::course_type().' Content to Authoring Space');
1.329 droeschl 4471: &dumpcourse($r);
4472: } elsif ($allowed && $env{'form.exportcourse'}) {
1.377 bisitz 4473: &init_breadcrumbs('exportcourse','IMS Export');
1.475 raeburn 4474: &Apache::imsexport::exportcourse($r);
1.329 droeschl 4475: } else {
1.445 www 4476: #
4477: # Done catching special calls
1.484 raeburn 4478: # The whole rest is for course and supplemental documents and utilities menu
1.445 www 4479: # Get the parameters that may be needed
4480: #
4481: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.519 raeburn 4482: ['folderpath',
4483: 'forcesupplement','forcestandard',
1.510 raeburn 4484: 'tools','symb','command','supppath']);
1.445 www 4485:
4486: # standard=1: this is a "new-style" course with an uploaded map as top level
4487: # standard=2: this is a "old-style" course, and there is nothing we can do
1.329 droeschl 4488:
4489: my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
1.445 www 4490:
1.484 raeburn 4491: # Decide whether this should display supplemental or main content or utilities
1.445 www 4492: # supplementalflag=1: show supplemental documents
4493: # supplementalflag=0: show standard documents
1.484 raeburn 4494: # toolsflag=1: show utilities
1.445 www 4495:
1.561 raeburn 4496: my $unesc_folderpath = &unescape($env{'form.folderpath'});
4497: my $supplementalflag=($unesc_folderpath=~/^supplemental/);
4498: if (($unesc_folderpath=~/^default/) || ($unesc_folderpath eq "")) {
1.445 www 4499: $supplementalflag=0;
4500: }
4501: if ($env{'form.forcesupplement'}) { $supplementalflag=1; }
4502: if ($env{'form.forcestandard'}) { $supplementalflag=0; }
4503: unless ($allowed) { $supplementalflag=1; }
4504: unless ($standard) { $supplementalflag=1; }
1.484 raeburn 4505: my $toolsflag=0;
4506: if ($env{'form.tools'}) { $toolsflag=1; }
1.445 www 4507:
1.329 droeschl 4508: my $script='';
4509: my $showdoc=0;
1.457 raeburn 4510: my $addentries = {};
1.475 raeburn 4511: my $container;
1.329 droeschl 4512: my $containertag;
1.508 raeburn 4513: my $pathitem;
1.329 droeschl 4514:
1.464 www 4515: # Do we directly jump somewhere?
1.466 www 4516:
1.525 raeburn 4517: if (($env{'form.command'} eq 'direct') || ($env{'form.command'} eq 'directnav')) {
1.472 raeburn 4518: if ($env{'form.symb'} ne '') {
1.522 raeburn 4519: $env{'form.folderpath'}=
4520: &Apache::loncommon::symb_to_docspath($env{'form.symb'});
1.530 raeburn 4521: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
1.525 raeburn 4522: $env{'form.command'}.'_'.$env{'form.symb'}});
1.472 raeburn 4523: } elsif ($env{'form.supppath'} ne '') {
4524: $env{'form.folderpath'}=$env{'form.supppath'};
1.530 raeburn 4525: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} =>
1.525 raeburn 4526: $env{'form.command'}.'_'.$env{'form.supppath'}});
1.466 www 4527: }
1.472 raeburn 4528: } elsif ($env{'form.command'} eq 'editdocs') {
1.525 raeburn 4529: $env{'form.folderpath'} = 'default&'.
1.548 raeburn 4530: &escape(&mt('Main Content').':::::');
1.525 raeburn 4531: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => $env{'form.command'}});
1.472 raeburn 4532: } elsif ($env{'form.command'} eq 'editsupp') {
1.525 raeburn 4533: $env{'form.folderpath'} = 'supplemental&'.
1.538 raeburn 4534: &escape('Supplemental Content');
1.525 raeburn 4535: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/supplemental'});
4536: } elsif ($env{'form.command'} eq 'contents') {
4537: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/navmaps'});
4538: } elsif ($env{'form.command'} eq 'home') {
4539: &Apache::lonnet::appenv({'docs.exit.'.$env{'request.course.id'} => '/adm/menu'});
1.464 www 4540: }
4541:
1.525 raeburn 4542:
1.445 www 4543: # Where do we store these for when we come back?
4544: my $stored_folderpath='docs_folderpath';
4545: if ($supplementalflag) {
4546: $stored_folderpath='docs_sup_folderpath';
4547: }
1.464 www 4548:
1.519 raeburn 4549: # No folderpath, and in edit mode, see if we have something stored
4550: if ((!$env{'form.folderpath'}) && $allowed) {
1.445 www 4551: &Apache::loncommon::restore_course_settings($stored_folderpath,
1.510 raeburn 4552: {'folderpath' => 'scalar'});
1.523 raeburn 4553: unless (&unescape($env{'form.folderpath'}) =~ m{^(default|supplemental)&}) {
4554: undef($env{'form.folderpath'});
4555: }
1.329 droeschl 4556: }
1.446 www 4557:
4558: # If we are not allowed to make changes, all we can see are supplemental docs
1.409 raeburn 4559: if (!$allowed) {
1.446 www 4560: unless ($env{'form.folderpath'} =~ /^supplemental/) {
4561: $env{'form.folderpath'} = &supplemental_base();
1.409 raeburn 4562: }
4563: }
1.446 www 4564: # Make the zeroth entry in supplemental docs page paths, so we can get to top level
1.329 droeschl 4565: if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
1.446 www 4566: $env{'form.folderpath'} = &supplemental_base()
4567: .'&'.
1.329 droeschl 4568: $env{'form.folderpath'};
4569: }
1.446 www 4570: # If after all of this, we still don't have any paths, make them
1.519 raeburn 4571: unless ($env{'form.folderpath'}) {
1.446 www 4572: if ($supplementalflag) {
4573: $env{'form.folderpath'}=&supplemental_base();
4574: } else {
1.548 raeburn 4575: $env{'form.folderpath'}='default&'.&escape(&mt('Main Content').
1.538 raeburn 4576: ':::::');
1.446 www 4577: }
1.472 raeburn 4578: }
1.446 www 4579:
1.445 www 4580: # Store this
1.484 raeburn 4581: unless ($toolsflag) {
1.510 raeburn 4582: if ($allowed) {
4583: &Apache::loncommon::store_course_settings($stored_folderpath,
1.519 raeburn 4584: {'folderpath' => 'scalar'});
1.510 raeburn 4585: }
1.519 raeburn 4586: my $folderpath;
1.484 raeburn 4587: if ($env{'form.folderpath'}) {
1.519 raeburn 4588: $folderpath = $env{'form.folderpath'};
4589: my (@folders)=split('&',$env{'form.folderpath'});
4590: $env{'form.foldername'}=&unescape(pop(@folders));
4591: if ($env{'form.foldername'} =~ /\:1$/) {
4592: $container = 'page';
4593: } else {
4594: $container = 'sequence';
4595: }
4596: $env{'form.folder'}=pop(@folders);
1.484 raeburn 4597: } else {
1.519 raeburn 4598: if ($env{'form.folder'} eq '' ||
4599: $env{'form.folder'} eq 'supplemental') {
4600: $folderpath='default&'.
1.548 raeburn 4601: &escape(&mt('Main Content').':::::');
1.484 raeburn 4602: }
4603: }
1.519 raeburn 4604: $containertag = '<input type="hidden" name="folderpath" value="" />';
4605: $pathitem = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 4606: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
4607: $showdoc='/'.$1;
4608: }
4609: if ($showdoc) { # got called in sequence from course
4610: $allowed=0;
4611: } else {
4612: if ($allowed) {
4613: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
4614: $script=&Apache::lonratedt::editscript('simple');
1.433 raeburn 4615: }
4616: }
1.329 droeschl 4617: }
4618:
1.344 bisitz 4619: # get personal data
1.329 droeschl 4620: my $uname=$env{'user.name'};
4621: my $udom=$env{'user.domain'};
4622: my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));
4623:
4624: if ($allowed) {
1.484 raeburn 4625: if ($toolsflag) {
4626: $script .= &inject_data_js();
4627: my ($home,$other,%outhash)=&authorhosts();
4628: if (!$home && $other) {
4629: my @hosts;
4630: foreach my $aurole (keys(%outhash)) {
4631: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
4632: push(@hosts,$outhash{$aurole});
4633: }
4634: }
4635: $script .= &dump_switchserver_js(@hosts);
4636: }
1.458 raeburn 4637: } else {
1.484 raeburn 4638: my @tabids;
4639: if ($supplementalflag) {
4640: @tabids = ('002','ee2','ff2');
4641: } else {
4642: @tabids = ('aa1','bb1','cc1','ff1');
1.519 raeburn 4643: unless ($env{'form.folderpath'} =~ /\:1$/) {
1.484 raeburn 4644: unshift(@tabids,'001');
4645: push(@tabids,('dd1','ee1'));
4646: }
1.458 raeburn 4647: }
1.484 raeburn 4648: my $tabidstr = join("','",@tabids);
4649: $script .= &editing_js($udom,$uname,$supplementalflag).
4650: &history_tab_js().
4651: &inject_data_js().
1.510 raeburn 4652: &Apache::lonhtmlcommon::resize_scrollbox_js('docs',$tabidstr).
4653: &Apache::lonextresedit::extedit_javascript();
1.484 raeburn 4654: $addentries = {
1.485 raeburn 4655: onload => "javascript:resize_scrollbox('contentscroll','1','1');",
1.484 raeburn 4656: };
1.458 raeburn 4657: }
1.538 raeburn 4658: $script .= &paste_popup_js();
1.501 raeburn 4659: my $confirm_switch = &mt("Editing requires switching to the resource's home server.").'\n'.
4660: &mt('Switch server?');
4661:
4662:
1.329 droeschl 4663: }
4664: # -------------------------------------------------------------------- Body tag
1.369 bisitz 4665: $script = '<script type="text/javascript">'."\n"
1.372 bisitz 4666: .'// <![CDATA['."\n"
4667: .$script."\n"
4668: .'// ]]>'."\n"
4669: .'</script>'."\n";
1.385 bisitz 4670:
4671: # Breadcrumbs
4672: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.510 raeburn 4673:
4674: if ($showdoc) {
4675: $r->print(&Apache::loncommon::start_page("$crstype documents",undef,
4676: {'force_register' => $showdoc,}));
4677: } elsif ($r->uri eq '/adm/supplemental') {
4678: my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype);
4679: $r->print(&Apache::loncommon::start_page("Supplemental $crstype Content",undef,
4680: {'bread_crumbs' => $brcrum,}));
4681: } else {
1.392 raeburn 4682: &Apache::lonhtmlcommon::add_breadcrumb({
1.446 www 4683: href=>"/adm/coursedocs",text=>"$crstype Contents"});
4684: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script,
1.510 raeburn 4685: {'add_entries' => $addentries}
4686: )
1.392 raeburn 4687: .&Apache::loncommon::help_open_menu('','',273,'RAT')
4688: .&Apache::lonhtmlcommon::breadcrumbs(
1.484 raeburn 4689: 'Editing '.$crstype.' Contents',
1.392 raeburn 4690: 'Docs_Adding_Course_Doc')
4691: );
4692: }
1.364 bisitz 4693:
1.329 droeschl 4694: my %allfiles = ();
4695: my %codebase = ();
1.440 raeburn 4696: my ($upload_result,$upload_output,$uploadphase);
1.329 droeschl 4697: if ($allowed) {
4698: if (($env{'form.uploaddoc.filename'}) &&
4699: ($env{'form.cmd'}=~/^upload_(\w+)/)) {
1.440 raeburn 4700: my $context = $1;
4701: # Process file upload - phase one - upload and parse primary file.
1.329 droeschl 4702: undef($hadchanges);
1.440 raeburn 4703: $uploadphase = &process_file_upload(\$upload_output,$coursenum,$coursedom,
1.552 raeburn 4704: \%allfiles,\%codebase,$context,$crstype);
1.329 droeschl 4705: if ($hadchanges) {
4706: &mark_hash_old();
4707: }
1.440 raeburn 4708: $r->print($upload_output);
4709: } elsif ($env{'form.phase'} eq 'upload_embedded') {
4710: # Process file upload - phase two - upload embedded objects
4711: $uploadphase = 'check_embedded';
4712: my $primaryurl = &HTML::Entities::encode($env{'form.primaryurl'},'<>&"');
4713: my $state = &embedded_form_elems($uploadphase,$primaryurl,
4714: $env{'form.newidx'});
4715: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
4716: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
4717: my ($destination,$dir_root) = &embedded_destination();
4718: my $url_root = '/uploaded/'.$docudom.'/'.$docuname;
4719: my $actionurl = '/adm/coursedocs';
4720: my ($result,$flag) =
4721: &Apache::loncommon::upload_embedded('coursedoc',$destination,
4722: $docuname,$docudom,$dir_root,$url_root,undef,undef,undef,$state,
4723: $actionurl);
4724: $r->print($result.&return_to_editor());
4725: } elsif ($env{'form.phase'} eq 'check_embedded') {
4726: # Process file upload - phase three - modify references in HTML file
4727: $uploadphase = 'modified_orightml';
4728: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
4729: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
4730: my ($destination,$dir_root) = &embedded_destination();
1.482 raeburn 4731: my $result =
4732: &Apache::loncommon::modify_html_refs('coursedoc',$destination,
4733: $docuname,$docudom,undef,
4734: $dir_root);
4735: $r->print($result.&return_to_editor());
1.476 raeburn 4736: } elsif ($env{'form.phase'} eq 'decompress_uploaded') {
4737: $uploadphase = 'decompress_phase_one';
4738: $r->print(&decompression_phase_one().
4739: &return_to_editor());
4740: } elsif ($env{'form.phase'} eq 'decompress_cleanup') {
4741: $uploadphase = 'decompress_phase_two';
4742: $r->print(&decompression_phase_two().
4743: &return_to_editor());
1.329 droeschl 4744: }
4745: }
4746:
1.484 raeburn 4747: if ($allowed && $toolsflag) {
4748: $r->print(&startContentScreen('tools'));
4749: $r->print(&generate_admin_menu($crstype));
4750: $r->print(&endContentScreen());
4751: } elsif ((!$showdoc) && (!$uploadphase)) {
1.329 droeschl 4752: # -----------------------------------------------------------------------------
4753: my %lt=&Apache::lonlocal::texthash(
4754: 'copm' => 'All documents out of a published map into this folder',
1.501 raeburn 4755: 'upfi' => 'Upload File',
1.553 raeburn 4756: 'upld' => 'Upload Content',
1.329 droeschl 4757: 'srch' => 'Search',
4758: 'impo' => 'Import',
1.487 raeburn 4759: 'lnks' => 'Import from Stored Links',
1.502 raeburn 4760: 'impm' => 'Import from Assembled Map',
1.329 droeschl 4761: 'selm' => 'Select Map',
4762: 'load' => 'Load Map',
4763: 'newf' => 'New Folder',
4764: 'newp' => 'New Composite Page',
4765: 'syll' => 'Syllabus',
1.425 raeburn 4766: 'navc' => 'Table of Contents',
1.343 biermanm 4767: 'sipa' => 'Simple Course Page',
1.329 droeschl 4768: 'sipr' => 'Simple Problem',
1.534 raeburn 4769: 'webp' => 'Blank Web Page (editable)',
1.329 droeschl 4770: 'drbx' => 'Drop Box',
1.451 www 4771: 'scuf' => 'External Scores (handgrade, upload, clicker)',
1.336 schafran 4772: 'bull' => 'Discussion Board',
1.347 weissno 4773: 'mypi' => 'My Personal Information Page',
1.353 weissno 4774: 'grpo' => 'Group Portfolio',
1.329 droeschl 4775: 'rost' => 'Course Roster',
1.528 raeburn 4776: 'abou' => 'Personal Information Page for a User',
1.553 raeburn 4777: 'imsf' => 'IMS Upload',
4778: 'imsl' => 'Upload IMS package',
1.501 raeburn 4779: 'cms' => 'Origin of IMS package',
4780: 'se' => 'Select',
1.329 droeschl 4781: 'file' => 'File',
4782: 'title' => 'Title',
4783: 'comment' => 'Comment',
1.403 raeburn 4784: 'parse' => 'Upload embedded images/multimedia files if HTML file',
1.329 droeschl 4785: );
4786: # -----------------------------------------------------------------------------
4787: my $fileupload=(<<FIUP);
4788: $lt{'file'}:<br />
4789: <input type="file" name="uploaddoc" size="40" />
4790: FIUP
4791:
4792: my $checkbox=(<<CHBO);
4793: <!-- <label>$lt{'parse'}?
4794: <input type="checkbox" name="parserflag" />
4795: </label> -->
4796: <label>
4797: <input type="checkbox" name="parserflag" checked="checked" /> $lt{'parse'}
4798: </label>
4799: CHBO
1.501 raeburn 4800: my $imsfolder = $env{'form.folder'};
4801: if ($imsfolder eq '') {
4802: $imsfolder = 'default';
4803: }
4804: my $imspform=(<<IMSFORM);
4805: <a class="LC_menubuttons_link" href="javascript:toggleUpload('ims');">
4806: $lt{'imsf'}</a> $help{'Importing_IMS_Course'}
4807: <form name="uploadims" action="/adm/imsimportdocs" method="post" enctype="multipart/form-data" target="IMSimport">
1.516 raeburn 4808: <fieldset id="uploadimsform" style="display: none;">
1.501 raeburn 4809: <legend>$lt{'imsf'}</legend>
4810: $fileupload
4811: <br />
4812: <p>
4813: $lt{'cms'}:
4814: <select name="source">
4815: <option value="-1" selected="selected">$lt{'se'}</option>
4816: <option value="bb5">Blackboard 5</option>
4817: <option value="bb6">Blackboard 6</option>
4818: <option value="angel5">ANGEL 5.5</option>
4819: <option value="webctce4">WebCT 4 Campus Edition</option>
4820: </select>
4821: <input type="hidden" name="folder" value="$imsfolder" />
4822: </p>
4823: <input type="hidden" name="phase" value="one" />
4824: <input type="button" value="$lt{'imsl'}" onclick="makeims(this.form);" />
4825: </fieldset>
4826: </form>
4827: IMSFORM
1.329 droeschl 4828:
4829: my $fileuploadform=(<<FUFORM);
1.501 raeburn 4830: <a class="LC_menubuttons_link" href="javascript:toggleUpload('doc');">
4831: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
4832: <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.516 raeburn 4833: <fieldset id="uploaddocform" style="display: none;">
1.501 raeburn 4834: <legend>$lt{'upfi'}</legend>
1.371 tempelho 4835: <input type="hidden" name="active" value="aa" />
1.329 droeschl 4836: $fileupload
4837: <br />
4838: $lt{'title'}:<br />
1.458 raeburn 4839: <input type="text" size="60" name="comment" />
1.508 raeburn 4840: $pathitem
1.329 droeschl 4841: <input type="hidden" name="cmd" value="upload_default" />
4842: <br />
1.458 raeburn 4843: <span class="LC_nobreak" style="float:left">
1.329 droeschl 4844: $checkbox
4845: </span>
1.501 raeburn 4846: <br clear="all" />
4847: <input type="submit" value="$lt{'upld'}" />
4848: </fieldset>
4849: </form>
1.383 tempelho 4850: FUFORM
1.329 droeschl 4851:
1.502 raeburn 4852: my $importpubform=(<<SEDFFORM);
1.514 raeburn 4853: <a class="LC_menubuttons_link" href="javascript:toggleMap('map');">
1.502 raeburn 4854: $lt{'impm'}</a>$help{'Load_Map'}
4855: <form action="/adm/coursedocs" method="post" name="mapimportform">
1.516 raeburn 4856: <fieldset id="importmapform" style="display: none;">
1.502 raeburn 4857: <legend>$lt{'impm'}</legend>
1.371 tempelho 4858: <input type="hidden" name="active" value="bb" />
1.502 raeburn 4859: $lt{'copm'}<br />
4860: <span class="LC_nobreak">
4861: <input type="text" name="importmap" size="40" value=""
4862: onfocus="this.blur();openbrowser('mapimportform','importmap','sequence,page','');" />
1.516 raeburn 4863: <a href="javascript:openbrowser('mapimportform','importmap','sequence,page','');">$lt{'selm'}</a></span><br />
1.502 raeburn 4864: <input type="submit" name="loadmap" value="$lt{'load'}" />
4865: </fieldset>
4866: </form>
4867:
1.383 tempelho 4868: SEDFFORM
1.502 raeburn 4869: my @importpubforma = (
1.508 raeburn 4870: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/src.png" alt="'.$lt{srch}.'" onclick="javascript:groupsearch()" />' => $pathitem."<a class='LC_menubuttons_link' href='javascript:groupsearch()'>$lt{'srch'}</a>" },
1.423 onken 4871: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/res.png" alt="'.$lt{impo}.'" onclick="javascript:groupimport();"/>' => "<a class='LC_menubuttons_link' href='javascript:groupimport();'>$lt{'impo'}</a>$help{'Importing_LON-CAPA_Resource'}" },
1.487 raeburn 4872: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/wishlist.png" alt="'.$lt{lnks}.'" onclick="javascript:open_StoredLinks_Import();" />' => "<a class='LC_menubuttons_link' href='javascript:open_StoredLinks_Import();'>$lt{'lnks'}</a>" },
1.514 raeburn 4873: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/sequence.png" alt="'.$lt{impm}.'" onclick="javascript:toggleMap(\'map\');" />' => $importpubform }
1.383 tempelho 4874: );
1.502 raeburn 4875: $importpubform = &create_form_ul(&create_list_elements(@importpubforma));
1.510 raeburn 4876: my $extresourcesform =
4877: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
4878: $help{'Adding_External_Resource'});
1.329 droeschl 4879: if ($allowed) {
1.492 raeburn 4880: my $folder = $env{'form.folder'};
4881: if ($folder eq '') {
4882: $folder='default';
4883: }
1.538 raeburn 4884: my $output = &update_paste_buffer($coursenum,$coursedom,$folder);
4885: if ($output) {
4886: $r->print($output);
4887: }
1.337 ehlerst 4888: $r->print(<<HIDDENFORM);
4889: <form name="renameform" method="post" action="/adm/coursedocs">
4890: <input type="hidden" name="title" />
4891: <input type="hidden" name="cmd" />
4892: <input type="hidden" name="markcopy" />
4893: <input type="hidden" name="copyfolder" />
4894: $containertag
4895: </form>
1.484 raeburn 4896:
1.337 ehlerst 4897: HIDDENFORM
1.508 raeburn 4898: $r->print(&makesimpleeditform($pathitem)."\n".
4899: &makedocslogform($pathitem."\n".
1.484 raeburn 4900: '<input type="hidden" name="folder" value="'.
4901: $env{'form.folder'}.'" />'."\n"));
1.329 droeschl 4902: }
1.442 www 4903:
4904: # Generate the tabs
1.510 raeburn 4905: my ($mode,$needs_end);
1.472 raeburn 4906: if (($supplementalflag) && (!$allowed)) {
1.510 raeburn 4907: my @folders = split('&',$env{'form.folderpath'});
4908: unless (@folders > 2) {
4909: &Apache::lonnavdisplay::startContentScreen($r,'supplemental');
4910: $needs_end = 1;
4911: }
1.472 raeburn 4912: } else {
1.484 raeburn 4913: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.510 raeburn 4914: $needs_end = 1;
1.472 raeburn 4915: }
1.443 www 4916:
1.442 www 4917: #
4918:
4919: my $savefolderpath;
4920:
1.395 raeburn 4921: if ($allowed) {
1.329 droeschl 4922: my $folder=$env{'form.folder'};
1.443 www 4923: if ($folder eq '' || $supplementalflag) {
1.329 droeschl 4924: $folder='default';
1.356 tempelho 4925: $savefolderpath = $env{'form.folderpath'};
1.548 raeburn 4926: $env{'form.folderpath'}='default&'.&escape(&mt('Main Content'));
1.508 raeburn 4927: $pathitem = '<input type="hidden" name="folderpath" value="'.
1.329 droeschl 4928: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
4929: }
4930: my $postexec='';
4931: if ($folder eq 'default') {
1.372 bisitz 4932: $r->print('<script type="text/javascript">'."\n"
4933: .'// <![CDATA['."\n"
4934: .'this.window.name="loncapaclient";'."\n"
4935: .'// ]]>'."\n"
4936: .'</script>'."\n"
1.369 bisitz 4937: );
1.329 droeschl 4938: } else {
4939: #$postexec='self.close();';
4940: }
1.504 raeburn 4941: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.sequence';
4942: my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.page';
1.329 droeschl 4943: my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
4944:
4945: my $newnavform=(<<NNFORM);
4946: <form action="/adm/coursedocs" method="post" name="newnav">
1.371 tempelho 4947: <input type="hidden" name="active" value="cc" />
1.508 raeburn 4948: $pathitem
1.329 droeschl 4949: <input type="hidden" name="importdetail"
4950: value="$lt{'navc'}=/adm/navmaps" />
1.423 onken 4951: <a class="LC_menubuttons_link" href="javascript:document.newnav.submit()">$lt{'navc'}</a>
1.329 droeschl 4952: $help{'Navigate_Content'}
4953: </form>
4954: NNFORM
4955: my $newsmppageform=(<<NSPFORM);
4956: <form action="/adm/coursedocs" method="post" name="newsmppg">
1.371 tempelho 4957: <input type="hidden" name="active" value="cc" />
1.508 raeburn 4958: $pathitem
1.329 droeschl 4959: <input type="hidden" name="importdetail" value="" />
1.423 onken 4960: <a class="LC_menubuttons_link" href="javascript:makesmppage();"> $lt{'sipa'}</a>
1.383 tempelho 4961: $help{'Simple Page'}
1.329 droeschl 4962: </form>
4963: NSPFORM
4964:
4965: my $newsmpproblemform=(<<NSPROBFORM);
4966: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
1.371 tempelho 4967: <input type="hidden" name="active" value="cc" />
1.508 raeburn 4968: $pathitem
1.329 droeschl 4969: <input type="hidden" name="importdetail" value="" />
1.423 onken 4970: <a class="LC_menubuttons_link" href="javascript:makesmpproblem();">$lt{'sipr'}</a>
1.383 tempelho 4971: $help{'Simple Problem'}
1.329 droeschl 4972: </form>
4973:
4974: NSPROBFORM
4975:
4976: my $newdropboxform=(<<NDBFORM);
4977: <form action="/adm/coursedocs" method="post" name="newdropbox">
1.371 tempelho 4978: <input type="hidden" name="active" value="cc" />
1.508 raeburn 4979: $pathitem
1.329 droeschl 4980: <input type="hidden" name="importdetail" value="" />
1.423 onken 4981: <a class="LC_menubuttons_link" href="javascript:makedropbox();">$lt{'drbx'}</a>
1.554 raeburn 4982: $help{'Dropbox'}
1.344 bisitz 4983: </form>
1.329 droeschl 4984: NDBFORM
4985:
4986: my $newexuploadform=(<<NEXUFORM);
4987: <form action="/adm/coursedocs" method="post" name="newexamupload">
1.371 tempelho 4988: <input type="hidden" name="active" value="cc" />
1.508 raeburn 4989: $pathitem
1.329 droeschl 4990: <input type="hidden" name="importdetail" value="" />
1.423 onken 4991: <a class="LC_menubuttons_link" href="javascript:makeexamupload();">$lt{'scuf'}</a>
1.329 droeschl 4992: $help{'Score_Upload_Form'}
4993: </form>
4994: NEXUFORM
4995:
4996: my $newbulform=(<<NBFORM);
4997: <form action="/adm/coursedocs" method="post" name="newbul">
1.371 tempelho 4998: <input type="hidden" name="active" value="cc" />
1.508 raeburn 4999: $pathitem
1.329 droeschl 5000: <input type="hidden" name="importdetail" value="" />
1.423 onken 5001: <a class="LC_menubuttons_link" href="javascript:makebulboard();" >$lt{'bull'}</a>
1.329 droeschl 5002: $help{'Bulletin Board'}
5003: </form>
5004: NBFORM
5005:
5006: my $newaboutmeform=(<<NAMFORM);
5007: <form action="/adm/coursedocs" method="post" name="newaboutme">
1.371 tempelho 5008: <input type="hidden" name="active" value="cc" />
1.508 raeburn 5009: $pathitem
1.329 droeschl 5010: <input type="hidden" name="importdetail"
5011: value="$plainname=/adm/$udom/$uname/aboutme" />
1.423 onken 5012: <a class="LC_menubuttons_link" href="javascript:document.newaboutme.submit()">$lt{'mypi'}</a>
1.347 weissno 5013: $help{'My Personal Information Page'}
1.329 droeschl 5014: </form>
5015: NAMFORM
5016:
5017: my $newaboutsomeoneform=(<<NASOFORM);
5018: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
1.371 tempelho 5019: <input type="hidden" name="active" value="cc" />
1.508 raeburn 5020: $pathitem
1.329 droeschl 5021: <input type="hidden" name="importdetail" value="" />
1.423 onken 5022: <a class="LC_menubuttons_link" href="javascript:makeabout();">$lt{'abou'}</a>
1.329 droeschl 5023: </form>
5024: NASOFORM
5025:
5026: my $newrosterform=(<<NROSTFORM);
5027: <form action="/adm/coursedocs" method="post" name="newroster">
1.371 tempelho 5028: <input type="hidden" name="active" value="cc" />
1.508 raeburn 5029: $pathitem
1.329 droeschl 5030: <input type="hidden" name="importdetail"
5031: value="$lt{'rost'}=/adm/viewclasslist" />
1.423 onken 5032: <a class="LC_menubuttons_link" href="javascript:document.newroster.submit()">$lt{'rost'}</a>
1.556 raeburn 5033: $help{'Course_Roster'}
1.329 droeschl 5034: </form>
5035: NROSTFORM
5036:
1.534 raeburn 5037: my $newwebpage;
5038: if ($folder =~ /^default_?(\d*)$/) {
5039: $newwebpage = "/uploaded/$coursedom/$coursenum/docs/";
5040: if ($1) {
5041: $newwebpage .= $1;
5042: } else {
5043: $newwebpage .= 'default';
5044: }
5045: $newwebpage .= '/new.html';
5046: }
5047: my $newwebpageform =(<<NWEBFORM);
5048: <form action="/adm/coursedocs" method="post" name="newwebpage">
5049: <input type="hidden" name="active" value="cc" />
5050: $pathitem
5051: <input type="hidden" name="importdetail" value="$newwebpage" />
5052: <a class="LC_menubuttons_link" href="javascript:makewebpage();">$lt{'webp'}</a>
1.556 raeburn 5053: $help{'Web_Page'}
1.534 raeburn 5054: </form>
5055: NWEBFORM
5056:
5057:
1.342 ehlerst 5058: my $specialdocumentsform;
1.383 tempelho 5059: my @specialdocumentsforma;
1.451 www 5060: my $gradingform;
5061: my @gradingforma;
5062: my $communityform;
5063: my @communityforma;
1.351 ehlerst 5064: my $newfolderform;
1.390 tempelho 5065: my $newfolderb;
1.342 ehlerst 5066:
1.451 www 5067: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.383 tempelho 5068:
1.329 droeschl 5069: my $newpageform=(<<NPFORM);
5070: <form action="/adm/coursedocs" method="post" name="newpage">
5071: <input type="hidden" name="folderpath" value="$path" />
5072: <input type="hidden" name="importdetail" value="" />
1.371 tempelho 5073: <input type="hidden" name="active" value="cc" />
1.423 onken 5074: <a class="LC_menubuttons_link" href="javascript:makenewpage(document.newpage,'$pageseq');">$lt{'newp'}</a>
1.383 tempelho 5075: $help{'Adding_Pages'}
1.329 droeschl 5076: </form>
5077: NPFORM
1.390 tempelho 5078:
5079:
1.351 ehlerst 5080: $newfolderform=(<<NFFORM);
1.329 droeschl 5081: <form action="/adm/coursedocs" method="post" name="newfolder">
1.508 raeburn 5082: $pathitem
1.329 droeschl 5083: <input type="hidden" name="importdetail" value="" />
1.371 tempelho 5084: <input type="hidden" name="active" value="aa" />
1.422 onken 5085: <a href="javascript:makenewfolder(document.newfolder,'$folderseq');">$lt{'newf'}</a>$help{'Adding_Folders'}
1.329 droeschl 5086: </form>
5087: NFFORM
5088:
5089: my $newsylform=(<<NSYLFORM);
5090: <form action="/adm/coursedocs" method="post" name="newsyl">
1.371 tempelho 5091: <input type="hidden" name="active" value="cc" />
1.508 raeburn 5092: $pathitem
1.329 droeschl 5093: <input type="hidden" name="importdetail"
5094: value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />
1.423 onken 5095: <a class="LC_menubuttons_link" href="javascript:document.newsyl.submit()">$lt{'syll'}</a>
1.329 droeschl 5096: $help{'Syllabus'}
1.383 tempelho 5097:
1.329 droeschl 5098: </form>
5099: NSYLFORM
1.364 bisitz 5100:
1.329 droeschl 5101: my $newgroupfileform=(<<NGFFORM);
5102: <form action="/adm/coursedocs" method="post" name="newgroupfiles">
1.371 tempelho 5103: <input type="hidden" name="active" value="cc" />
1.508 raeburn 5104: $pathitem
1.329 droeschl 5105: <input type="hidden" name="importdetail"
5106: value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
1.423 onken 5107: <a class="LC_menubuttons_link" href="javascript:document.newgroupfiles.submit()">$lt{'grpo'}</a>
1.353 weissno 5108: $help{'Group Portfolio'}
1.329 droeschl 5109: </form>
5110: NGFFORM
1.383 tempelho 5111: @specialdocumentsforma=(
1.421 onken 5112: {'<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 5113: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="document.newsyl.submit()" />'=>$newsylform},
1.451 www 5114: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/navigation.png" alt="'.$lt{navc}.'" onclick="document.newnav.submit()" />'=>$newnavform},
5115: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simple.png" alt="'.$lt{sipa}.'" onclick="javascript:makesmppage();" />'=>$newsmppageform},
1.534 raeburn 5116: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage();" />'=>$newwebpageform},
1.451 www 5117: );
5118: $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma));
5119:
1.434 raeburn 5120:
5121: my @importdoc = (
1.519 raeburn 5122: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="toggleUpload(\'ext\');" />'=>$extresourcesform}
5123: );
5124: unless ($container eq 'page') {
5125: push(@importdoc,
5126: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/ims.png" alt="'.$lt{imsf}.'" onclick="javascript:toggleUpload(\'ims\');" />'=>$imspform}
5127: );
5128: }
5129: push(@importdoc,
1.558 raeburn 5130: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'doc\');" />'=>$fileuploadform}
1.519 raeburn 5131: );
1.501 raeburn 5132: $fileuploadform = &create_form_ul(&create_list_elements(@importdoc));
1.434 raeburn 5133:
1.451 www 5134: @gradingforma=(
5135: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{sipr}.'" onclick="javascript:makesmpproblem();" />'=>$newsmpproblemform},
5136: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/dropbox.png" alt="'.$lt{drbx}.'" onclick="javascript:makedropbox();" />'=>$newdropboxform},
5137: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/scoreupfrm.png" alt="'.$lt{scuf}.'" onclick="javascript:makeexamupload();" />'=>$newexuploadform},
5138:
5139: );
5140: $gradingform = &create_form_ul(&create_list_elements(@gradingforma));
5141:
5142: @communityforma=(
5143: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/bchat.png" alt="'.$lt{bull}.'" onclick="javascript:makebulboard();" />'=>$newbulform},
5144: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makebulboard();" />'=>$newaboutmeform},
5145: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/aboutme.png" alt="'.$lt{abou}.'" onclick="javascript:makeabout();" />'=>$newaboutsomeoneform},
5146: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/clst.png" alt="'.$lt{rost}.'" onclick="document.newroster.submit()" />'=>$newrosterform},
5147: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/groupportfolio.png" alt="'.$lt{grpo}.'" onclick="document.newgroupfiles.submit()" />'=>$newgroupfileform},
5148: );
5149: $communityform = &create_form_ul(&create_list_elements(@communityforma));
1.383 tempelho 5150:
1.330 tempelho 5151: my %orderhash = (
1.553 raeburn 5152: 'aa' => ['Upload',$fileuploadform],
5153: 'bb' => ['Import',$importpubform],
5154: 'cc' => ['Grading',$gradingform],
1.330 tempelho 5155: );
1.519 raeburn 5156: unless ($container eq 'page') {
1.434 raeburn 5157: $orderhash{'00'} = ['Newfolder',$newfolderform];
1.484 raeburn 5158: $orderhash{'dd'} = ['Collaboration',$communityform];
1.553 raeburn 5159: $orderhash{'ee'} = ['Other',$specialdocumentsform];
1.434 raeburn 5160: }
5161:
1.341 ehlerst 5162: $hadchanges=0;
1.484 raeburn 5163: unless (($supplementalflag || $toolsflag)) {
1.458 raeburn 5164: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.508 raeburn 5165: $supplementalflag,\%orderhash,$iconpath,$pathitem);
1.443 www 5166: if ($error) {
5167: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
5168: }
5169: if ($hadchanges) {
5170: &mark_hash_old();
5171: }
1.341 ehlerst 5172:
1.443 www 5173: &changewarning($r,'');
5174: }
1.458 raeburn 5175: }
1.442 www 5176:
1.443 www 5177: # Supplemental documents start here
5178:
1.329 droeschl 5179: my $folder=$env{'form.folder'};
1.443 www 5180: unless ($supplementalflag) {
1.329 droeschl 5181: $folder='supplemental';
5182: }
5183: if ($folder =~ /^supplemental$/ &&
5184: (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
1.446 www 5185: $env{'form.folderpath'} = &supplemental_base();
1.393 raeburn 5186: } elsif ($allowed) {
1.356 tempelho 5187: $env{'form.folderpath'} = $savefolderpath;
1.329 droeschl 5188: }
1.508 raeburn 5189: $pathitem = '<input type="hidden" name="folderpath" value="'.
5190: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
1.329 droeschl 5191: if ($allowed) {
5192: my $folderseq=
1.504 raeburn 5193: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_new.sequence';
1.329 droeschl 5194:
5195: my $supupdocform=(<<SUPDOCFORM);
1.501 raeburn 5196: <a class="LC_menubuttons_link" href="javascript:toggleUpload('suppdoc');">
5197: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
1.383 tempelho 5198: <form action="/adm/coursedocs" method="post" name="supuploaddocument" enctype="multipart/form-data">
1.516 raeburn 5199: <fieldset id="uploadsuppdocform" style="display: none;">
1.501 raeburn 5200: <legend>$lt{'upfi'}</legend>
1.371 tempelho 5201: <input type="hidden" name="active" value="ee" />
1.329 droeschl 5202: $fileupload
5203: <br />
5204: <br />
5205: <span class="LC_nobreak">
5206: $checkbox
5207: </span>
5208: <br /><br />
5209: $lt{'comment'}:<br />
1.383 tempelho 5210: <textarea cols="50" rows="4" name="comment"></textarea>
1.329 droeschl 5211: <br />
1.508 raeburn 5212: $pathitem
1.329 droeschl 5213: <input type="hidden" name="cmd" value="upload_supplemental" />
1.501 raeburn 5214: <input type='submit' value="$lt{'upld'}" />
5215: </form>
1.329 droeschl 5216: SUPDOCFORM
5217:
5218: my $supnewfolderform=(<<SNFFORM);
5219: <form action="/adm/coursedocs" method="post" name="supnewfolder">
1.371 tempelho 5220: <input type="hidden" name="active" value="ee" />
1.508 raeburn 5221: $pathitem
1.329 droeschl 5222: <input type="hidden" name="importdetail" value="" />
1.423 onken 5223: <a class="LC_menubuttons_link" href="javascript:makenewfolder(document.supnewfolder,'$folderseq');">$lt{'newf'}</a>
1.383 tempelho 5224: $help{'Adding_Folders'}
1.329 droeschl 5225: </form>
5226: SNFFORM
1.383 tempelho 5227:
1.510 raeburn 5228: my $supextform =
5229: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
5230: $help{'Adding_External_Resource'});
1.329 droeschl 5231:
5232: my $supnewsylform=(<<SNSFORM);
5233: <form action="/adm/coursedocs" method="post" name="supnewsyl">
1.371 tempelho 5234: <input type="hidden" name="active" value="ff" />
1.508 raeburn 5235: $pathitem
1.329 droeschl 5236: <input type="hidden" name="importdetail"
5237: value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
1.423 onken 5238: <a class="LC_menubuttons_link" href="javascript:document.supnewsyl.submit()">$lt{'syll'}</a>
1.329 droeschl 5239: $help{'Syllabus'}
5240: </form>
5241: SNSFORM
5242:
5243: my $supnewaboutmeform=(<<SNAMFORM);
1.383 tempelho 5244: <form action="/adm/coursedocs" method="post" name="supnewaboutme">
1.371 tempelho 5245: <input type="hidden" name="active" value="ff" />
1.508 raeburn 5246: $pathitem
1.329 droeschl 5247: <input type="hidden" name="importdetail"
5248: value="$plainname=/adm/$udom/$uname/aboutme" />
1.423 onken 5249: <a class="LC_menubuttons_link" href="javascript:document.supnewaboutme.submit()">$lt{'mypi'}</a>
1.347 weissno 5250: $help{'My Personal Information Page'}
1.329 droeschl 5251: </form>
5252: SNAMFORM
5253:
1.534 raeburn 5254: my $supwebpage;
5255: if ($folder =~ /^supplemental_?(\d*)$/) {
5256: $supwebpage = "/uploaded/$coursedom/$coursenum/supplemental/";
5257: if ($1) {
5258: $supwebpage .= $1;
5259: } else {
5260: $supwebpage .= 'default';
5261: }
5262: $supwebpage .= '/new.html';
5263: }
5264: my $supwebpageform =(<<SWEBFORM);
5265: <form action="/adm/coursedocs" method="post" name="supwebpage">
5266: <input type="hidden" name="active" value="cc" />
5267: $pathitem
5268: <input type="hidden" name="importdetail" value="$supwebpage" />
5269: <a class="LC_menubuttons_link" href="javascript:makewebpage('supp');">$lt{'webp'}</a>
1.556 raeburn 5270: $help{'Web_Page'}
1.534 raeburn 5271: </form>
5272: SWEBFORM
5273:
1.333 muellerd 5274:
1.383 tempelho 5275: my @specialdocs = (
1.417 droeschl 5276: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="document.supnewsyl.submit()" />'
5277: =>$supnewsylform},
5278: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="document.supnewaboutme.submit()" />'
5279: =>$supnewaboutmeform},
1.534 raeburn 5280: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/webpage.png" alt="'.$lt{webp}.'" onclick="javascript:makewebpage('."'supp'".');" />'=>$supwebpageform},
5281:
1.383 tempelho 5282: );
1.417 droeschl 5283: my @supimportdoc = (
1.515 raeburn 5284: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="javascript:toggleUpload(\'suppext\')" />'
1.501 raeburn 5285: =>$supextform},
5286: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'suppdoc\');" />'
5287: =>$supupdocform},
5288: );
5289:
5290: $supupdocform = &create_form_ul(&create_list_elements(@supimportdoc));
1.333 muellerd 5291: my %suporderhash = (
1.390 tempelho 5292: '00' => ['Supnewfolder', $supnewfolderform],
1.553 raeburn 5293: 'ee' => ['Upload',$supupdocform],
5294: 'ff' => ['Other',&create_form_ul(&create_list_elements(@specialdocs))]
1.333 muellerd 5295: );
1.443 www 5296: if ($supplementalflag) {
1.458 raeburn 5297: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.508 raeburn 5298: $supplementalflag,\%suporderhash,$iconpath,$pathitem);
1.443 www 5299: if ($error) {
5300: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.557 raeburn 5301: } else {
5302: if ($suppchanges) {
5303: my %servers = &Apache::lonnet::internet_dom_servers($coursedom);
5304: my @ids=&Apache::lonnet::current_machine_ids();
5305: foreach my $server (keys(%servers)) {
5306: next if (grep(/^\Q$server\E$/,@ids));
5307: my $hashid=$coursenum.':'.$coursedom;
1.566 raeburn 5308: my $cachekey = &escape('suppcount').':'.&escape($hashid);
5309: &Apache::lonnet::remote_devalidate_cache($server,[$cachekey]);
1.557 raeburn 5310: }
5311: &Apache::lonnet::get_numsuppfiles($coursenum,$coursedom,1);
5312: undef($suppchanges);
5313: }
5314: }
1.393 raeburn 5315: }
1.443 www 5316: } elsif ($supplementalflag) {
1.458 raeburn 5317: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.508 raeburn 5318: $supplementalflag,'',$iconpath,$pathitem);
1.393 raeburn 5319: if ($error) {
5320: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.383 tempelho 5321: }
1.393 raeburn 5322: }
1.389 tempelho 5323:
1.510 raeburn 5324: if ($needs_end) {
5325: $r->print(&endContentScreen());
5326: }
1.383 tempelho 5327:
1.329 droeschl 5328: if ($allowed) {
5329: $r->print('
5330: <form method="post" name="extimport" action="/adm/coursedocs">
5331: <input type="hidden" name="title" />
5332: <input type="hidden" name="url" />
5333: <input type="hidden" name="useform" />
5334: <input type="hidden" name="residx" />
5335: </form>');
5336: }
1.484 raeburn 5337: } elsif ($showdoc) {
1.329 droeschl 5338: # -------------------------------------------------------- This is showdoc mode
1.484 raeburn 5339: $r->print("<h1>".&mt('Uploaded Document').' - '.
1.498 bisitz 5340: &Apache::lonnet::gettitle($r->uri).'</h1><p class="LC_warning">'.
1.329 droeschl 5341: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><table>".
1.484 raeburn 5342: &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');
1.329 droeschl 5343: }
5344: }
5345: $r->print(&Apache::loncommon::end_page());
5346: return OK;
1.364 bisitz 5347: }
1.329 droeschl 5348:
1.440 raeburn 5349: sub embedded_form_elems {
5350: my ($phase,$primaryurl,$newidx) = @_;
5351: my $folderpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
5352: return <<STATE;
5353: <input type="hidden" name="folderpath" value="$folderpath" />
5354: <input type="hidden" name="cmd" value="upload_embedded" />
5355: <input type="hidden" name="newidx" value="$newidx" />
5356: <input type="hidden" name="phase" value="$phase" />
5357: <input type="hidden" name="primaryurl" value="$primaryurl" />
5358: STATE
5359: }
5360:
5361: sub embedded_destination {
5362: my $folder=$env{'form.folder'};
5363: my $destination = 'docs/';
5364: if ($folder =~ /^supplemental/) {
5365: $destination = 'supplemental/';
5366: }
5367: if (($folder eq 'default') || ($folder eq 'supplemental')) {
5368: $destination .= 'default/';
5369: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
5370: $destination .= $2.'/';
5371: }
5372: $destination .= $env{'form.newidx'};
5373: my $dir_root = '/userfiles';
5374: return ($destination,$dir_root);
5375: }
5376:
5377: sub return_to_editor {
5378: my $actionurl = '/adm/coursedocs';
5379: return '<p><form name="backtoeditor" method="post" action="'.$actionurl.'" />'."\n".
5380: '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" /></form>'."\n".
5381: '<a href="javascript:document.backtoeditor.submit();">'.&mt('Return to Editor').
5382: '</a></p>';
5383: }
5384:
1.476 raeburn 5385: sub decompression_info {
5386: my ($destination,$dir_root) = &embedded_destination();
5387: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
5388: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5389: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
5390: my $container='sequence';
1.480 raeburn 5391: my ($pathitem,$hiddenelem);
1.519 raeburn 5392: my @hiddens = ('newidx','comment','position','folderpath');
5393: if ($env{'form.folderpath'} =~ /\:1$/) {
1.476 raeburn 5394: $container='page';
5395: }
1.480 raeburn 5396: unshift(@hiddens,$pathitem);
5397: foreach my $item (@hiddens) {
5398: if ($env{'form.'.$item}) {
5399: $hiddenelem .= '<input type="hidden" name="'.$item.'" value="'.
5400: $env{'form.'.$item}.'" />'."\n";
5401: }
1.477 raeburn 5402: }
1.476 raeburn 5403: return ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,
5404: $hiddenelem);
5405: }
5406:
5407: sub decompression_phase_one {
5408: my ($dir,$file,$warning,$error,$output);
5409: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
5410: &decompression_info();
1.490 raeburn 5411: if ($env{'form.archiveurl'} !~ m{^/uploaded/\Q$docudom/$docuname/\E(?:docs|supplemental)/(?:default|\d+).*/([^/]+)$}) {
1.476 raeburn 5412: $error = &mt('Archive file "[_1]" not in the expected location.',$env{'form.archiveurl'});
5413: } else {
5414: my $file = $1;
1.481 raeburn 5415: $output =
5416: &Apache::loncommon::process_decompression($docudom,$docuname,$file,
5417: $destination,$dir_root,
5418: $hiddenelem);
5419: if ($env{'form.autoextract_camtasia'}) {
5420: $output .= &remove_archive($docudom,$docuname,$container);
5421: }
1.476 raeburn 5422: }
5423: if ($error) {
5424: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
5425: $error.'</p>'."\n";
5426: }
5427: if ($warning) {
5428: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
5429: }
5430: return $output;
5431: }
5432:
5433: sub decompression_phase_two {
5434: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
5435: &decompression_info();
1.481 raeburn 5436: my $output;
1.480 raeburn 5437: if ($env{'form.archivedelete'}) {
1.481 raeburn 5438: $output = &remove_archive($docudom,$docuname,$container);
1.480 raeburn 5439: }
5440: $output .=
1.481 raeburn 5441: &Apache::loncommon::process_extracted_files('coursedocs',$docudom,$docuname,
1.476 raeburn 5442: $destination,$dir_root,$hiddenelem);
5443: return $output;
5444: }
5445:
1.480 raeburn 5446: sub remove_archive {
5447: my ($docudom,$docuname,$container) = @_;
5448: my $map = $env{'form.folder'}.'.'.$container;
1.481 raeburn 5449: my ($output,$delwarning,$delresult,$url);
1.480 raeburn 5450: my ($errtext,$fatal) = &mapread($docuname,$docudom,$map);
5451: if ($fatal) {
5452: if ($container eq 'page') {
5453: $delwarning = &mt('An error occurred retrieving the contents of the current page.');
5454: } else {
5455: $delwarning = &mt('An error occurred retrieving the contents of the current folder.');
5456: }
5457: $delwarning .= &mt('As a result the archive file has not been removed.');
5458: } else {
5459: my $currcmd = $env{'form.cmd'};
5460: my $position = $env{'form.position'};
1.563 raeburn 5461: if ($position > 0) {
5462: $env{'form.cmd'} = 'remove_'.$position;
1.480 raeburn 5463: my ($title,$url,@rrest) =
5464: split(/:/,$LONCAPA::map::resources[$LONCAPA::map::order[$position]]);
5465: if (&handle_edit_cmd($docuname,$docudom)) {
1.492 raeburn 5466: ($errtext,$fatal) = &storemap($docuname,$docudom,$map,1);
1.480 raeburn 5467: if ($fatal) {
5468: if ($container eq 'page') {
5469: $delwarning = &mt('An error occurred updating the contents of the current page.');
5470: } else {
5471: $delwarning = &mt('An error occurred updating the contents of the current folder.');
5472: }
5473: } else {
1.481 raeburn 5474: $delresult = &mt('Archive file removed.');
1.480 raeburn 5475: }
5476: }
5477: }
5478: $env{'form.cmd'} = $currcmd;
5479: }
5480: if ($delwarning) {
5481: $output = '<p class="LC_warning">'.
5482: $delwarning.
5483: '</p>';
5484: }
5485: if ($delresult) {
5486: $output .= '<p class="LC_info">'.
5487: $delresult.
5488: '</p>';
5489: }
1.481 raeburn 5490: return $output;
1.480 raeburn 5491: }
5492:
1.484 raeburn 5493: sub generate_admin_menu {
5494: my ($crstype) = @_;
5495: my $lc_crstype = lc($crstype);
5496: my ($home,$other,%outhash)=&authorhosts();
1.562 bisitz 5497: my %lt= ( # do not translate here
1.484 raeburn 5498: 'vc' => 'Verify Content',
5499: 'cv' => 'Check/Set Resource Versions',
5500: 'ls' => 'List Resource Identifiers',
5501: 'imse' => 'Export contents to IMS Archive',
5502: 'dcd' => "Dump $crstype Content to Authoring Space",
1.562 bisitz 5503: );
1.484 raeburn 5504: my ($candump,$dumpurl);
5505: if ($home + $other > 0) {
5506: $candump = 'F';
5507: if ($home) {
5508: $dumpurl = "javascript:injectData(document.courseverify,'dummy','dumpcourse','$lt{'dcd'}')";
5509: } else {
5510: my @hosts;
5511: foreach my $aurole (keys(%outhash)) {
5512: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
5513: push(@hosts,$outhash{$aurole});
1.538 raeburn 5514: }
1.484 raeburn 5515: }
5516: if (@hosts == 1) {
5517: my $switchto = '/adm/switchserver?otherserver='.$hosts[0].
5518: '&role='.
5519: &HTML::Entities::encode($env{'request.role'},'"<>&').'&origurl='.
5520: &HTML::Entities::encode('/adm/coursedocs?dumpcourse=1','"<>&');
5521: $dumpurl = "javascript:dump_needs_switchserver('$switchto')";
5522: } else {
5523: $dumpurl = "javascript:choose_switchserver_window()";
5524: }
5525: }
5526: }
5527: my @menu=
5528: ({ categorytitle=>'Administration',
5529: items =>[
5530: { linktext => $lt{'vc'},
5531: url => "javascript:injectData(document.courseverify,'dummy','verify','$lt{'vc'}')",
5532: permission => 'F',
5533: help => 'Verify_Content',
5534: icon => 'verify.png',
5535: linktitle => 'Verify contents can be retrieved/rendered',
5536: },
5537: { linktext => $lt{'cv'},
5538: url => "javascript:injectData(document.courseverify,'dummy','versions','$lt{'cv'}')",
5539: permission => 'F',
5540: help => 'Check_Resource_Versions',
5541: icon => 'resversion.png',
5542: linktitle => "View version information for resources in your $lc_crstype, and fix/unfix use of specific versions",
5543: },
5544: { linktext => $lt{'ls'},
5545: url => "javascript:injectData(document.courseverify,'dummy','listsymbs','$lt{'ls'}')",
5546: permission => 'F',
5547: #help => '',
5548: icon => 'symbs.png',
5549: linktitle => "List the unique identifier used for each resource instance in your $lc_crstype"
5550: },
5551: ]
5552: },
5553: { categorytitle=>'Export',
5554: items =>[
5555: { linktext => $lt{'imse'},
5556: url => "javascript:injectData(document.courseverify,'dummy','exportcourse','$lt{'imse'}')",
5557: permission => 'F',
5558: help => 'Docs_Export_Course_Docs',
5559: icon => 'imsexport.png',
5560: linktitle => $lt{'imse'},
5561: },
5562: { linktext => $lt{'dcd'},
5563: url => $dumpurl,
5564: permission => $candump,
5565: #help => '',
5566: icon => 'dump.png',
5567: linktitle => $lt{'dcd'},
5568: },
5569: ]
5570: });
5571: return '<form action="/adm/coursedocs" method="post" name="courseverify">'."\n".
5572: '<input type="hidden" id="dummy" />'."\n".
5573: &Apache::lonhtmlcommon::generate_menu(@menu)."\n".
5574: '</form>';
1.329 droeschl 5575: }
5576:
5577: sub generate_edit_table {
1.538 raeburn 5578: my ($tid,$orderhash_ref,$to_show,$iconpath,$jumpto,$readfile,
5579: $need_save,$copyfolder) = @_;
1.406 raeburn 5580: return unless(ref($orderhash_ref) eq 'HASH');
1.342 ehlerst 5581: my %orderhash = %{$orderhash_ref};
1.344 bisitz 5582: my $form;
1.371 tempelho 5583: my $activetab;
5584: my $active;
1.526 raeburn 5585: if (($env{'form.active'} ne '') && ($env{'form.active'} ne 'aa')) {
1.371 tempelho 5586: $activetab = $env{'form.active'};
5587: }
1.472 raeburn 5588: my $backicon = $iconpath.'clickhere.gif';
1.525 raeburn 5589: my $backtext = &mt('Exit Editor');
1.458 raeburn 5590: $form = '<div class="LC_Box" style="margin:0;">'.
1.488 raeburn 5591: '<ul id="navigation'.$tid.'" class="LC_TabContent">'."\n".
5592: '<li class="goback">'.
1.546 raeburn 5593: '<a href="javascript:toContents('."'$jumpto'".');">'.
1.488 raeburn 5594: '<img src="'.$backicon.'" class="LC_icon" style="border: none; vertical-align: top;"'.
5595: ' alt="'.$backtext.'" />'.$backtext.'</a></li>'."\n".
5596: '<li>'.
5597: '<a href="javascript:groupopen('."'$readfile'".',1);">'.
5598: &mt('Undo Delete').'</a></li>'."\n";
5599: if ($env{'form.docslog'}) {
5600: $form .= '<li class="active">';
5601: } else {
5602: $form .= '<li>';
5603: }
5604: $form .= '<a href="javascript:toggleHistoryDisp(1);">'.
5605: &mt('History').'</a></li>'."\n";
5606: if ($env{'form.docslog'}) {
5607: $form .= '<li><a href="javascript:toggleHistoryDisp(0);">'.
5608: &mt('Edit').'</a></li>'."\n";
1.484 raeburn 5609: }
1.458 raeburn 5610: foreach my $name (reverse(sort(keys(%orderhash)))) {
1.390 tempelho 5611: if($name ne '00'){
1.371 tempelho 5612: if($activetab eq '' || $activetab ne $name){
5613: $active = '';
5614: }elsif($activetab eq $name){
5615: $active = 'class="active"';
5616: }
1.458 raeburn 5617: $form .= '<li style="float:right" '.$active
1.484 raeburn 5618: .' 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 5619: } else {
1.484 raeburn 5620: $form .= '<li '.$active.' style="float:right">'.${$orderhash{$name}}[1].'</li>'."\n";
1.390 tempelho 5621:
5622: }
1.329 droeschl 5623: }
1.484 raeburn 5624: $form .= '</ul>'."\n";
5625: $form .= '<div id="content'.$tid.'" style="padding: 0 0; margin: 0 0; overflow: hidden; clear:right">'."\n";
1.458 raeburn 5626:
5627: if ($to_show ne '') {
1.538 raeburn 5628: my $saveform;
5629: if ($need_save) {
5630: my $button = &mt('Make changes');
5631: my $path;
5632: if ($env{'form.folderpath'}) {
5633: $path =
5634: &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
5635: }
5636: $saveform = <<"END";
5637: <div id="multisave" style="display:none; clear:both;" >
5638: <form name="saveactions" method="post" action="/adm/coursedocs" onsubmit="return checkSubmits();">
5639: <input type="hidden" name="folderpath" value="$path" />
5640: <input type="hidden" name="symb" value="$env{'form.symb'}" />
5641: <input type="hidden" name="allhiddenresource" value="" />
5642: <input type="hidden" name="allencrypturl" value="" />
5643: <input type="hidden" name="allrandompick" value="" />
5644: <input type="hidden" name="allrandomorder" value="" />
5645: <input type="hidden" name="changeparms" value="" />
5646: <input type="hidden" name="multiremove" value="" />
5647: <input type="hidden" name="multicut" value="" />
5648: <input type="hidden" name="multicopy" value="" />
5649: <input type="hidden" name="multichange" value="" />
5650: <input type="hidden" name="copyfolder" value="$copyfolder" />
5651: <input type="submit" name="savemultiples" value="$button" />
5652: </form>
5653: </div>
5654: END
5655: }
5656: $form .= '<div style="padding:0;margin:0;float:left">'.$to_show.'</div>'.$saveform."\n";
1.458 raeburn 5657: }
1.363 ehlerst 5658: foreach my $field (keys(%orderhash)){
1.390 tempelho 5659: if($field ne '00'){
1.422 onken 5660: if($activetab eq '' || $activetab ne $field){
1.458 raeburn 5661: $active = 'style="display: none;float:left"';
1.422 onken 5662: }elsif($activetab eq $field){
1.458 raeburn 5663: $active = 'style="display:block;float:left"';
1.422 onken 5664: }
5665: $form .= '<div id="'.$field.$tid.'"'
5666: .' class="LC_ContentBox" '.$active.'>'.${$orderhash{$field}}[1]
1.484 raeburn 5667: .'</div>'."\n";
1.363 ehlerst 5668: }
5669: }
1.484 raeburn 5670: unless ($env{'form.docslog'}) {
5671: $form .= '</div></div>'."\n";
5672: }
1.329 droeschl 5673: return $form;
5674: }
5675:
5676: sub editing_js {
1.472 raeburn 5677: my ($udom,$uname,$supplementalflag) = @_;
1.329 droeschl 5678: my %lt = &Apache::lonlocal::texthash(
5679: p_mnf => 'Name of New Folder',
5680: t_mnf => 'New Folder',
5681: p_mnp => 'Name of New Page',
5682: t_mnp => 'New Page',
1.451 www 5683: p_mxu => 'Title for the External Score',
1.349 biermanm 5684: p_msp => 'Name of Simple Course Page',
1.329 droeschl 5685: p_msb => 'Title for the Problem',
5686: p_mdb => 'Title for the Drop Box',
1.336 schafran 5687: p_mbb => 'Title for the Discussion Board',
1.534 raeburn 5688: p_mwp => 'Title for Web Page',
1.348 weissno 5689: p_mab => "Enter user:domain for User's Personal Information Page",
1.352 bisitz 5690: p_mab2 => 'Personal Information Page of ',
1.329 droeschl 5691: p_mab_alrt1 => 'Not a valid user:domain',
5692: p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',
5693: p_chn => 'New Title',
5694: p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',
5695: p_rmr2a => 'Remove[_99]',
5696: p_rmr2b => '?[_99]',
1.542 raeburn 5697: p_rmr3a => 'Remove those [_2]',
5698: p_rmr3b => 'items?[_2]',
1.329 droeschl 5699: p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',
5700: p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',
5701: p_ctr2a => 'Cut[_98]',
1.478 raeburn 5702: p_ctr2b => '?[_98]',
1.542 raeburn 5703: p_ctr3a => 'Cut those[_2]',
5704: p_ctr3b => 'items?[_2]',
1.478 raeburn 5705: rpck => 'Enter number to pick (e.g., 3)',
1.501 raeburn 5706: imsfile => 'You must choose an IMS package for import',
5707: imscms => 'You must select which Course Management System was the source of the IMS package',
5708: invurl => 'Invalid URL',
5709: titbl => 'Title is blank',
1.538 raeburn 5710: more => '(More ...)',
5711: less => '(Less ...)',
1.543 raeburn 5712: noor => 'No actions selected or changes to settings specified.',
5713: noch => 'No changes to settings specified.',
5714: noac => 'No actions selected.',
1.329 droeschl 5715: );
5716:
1.433 raeburn 5717: my $crstype = &Apache::loncommon::course_type();
1.434 raeburn 5718: my $docs_folderpath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'},'<>&"');
5719: my $main_container_page;
1.519 raeburn 5720: if (&HTML::Entities::decode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'}) =~ /\:1$/) {
5721: $main_container_page = 1;
1.434 raeburn 5722: }
1.538 raeburn 5723: my $toplevelmain =
1.548 raeburn 5724: &escape(&mt('Main Content').':::::');
1.446 www 5725: my $toplevelsupp = &supplemental_base();
1.433 raeburn 5726:
1.525 raeburn 5727: my $backtourl;
1.530 raeburn 5728: if ($env{'docs.exit.'.$env{'request.course.id'}} =~ /^direct_(.+)$/) {
5729: my $caller = $1;
1.525 raeburn 5730: if ($caller =~ /^supplemental/) {
5731: $backtourl = '/adm/supplemental?folderpath='.&escape($caller);
5732: } else {
5733: my ($map,$id,$res)=&Apache::lonnet::decode_symb($caller);
5734: $res = &Apache::lonnet::clutter($res);
5735: if (&Apache::lonnet::is_on_map($res)) {
5736: $backtourl = &HTML::Entities::encode(&Apache::lonnet::clutter($res),'<>&"').'?symb='.
5737: &HTML::Entities::encode($caller,'<>&"');
1.544 raeburn 5738: } else {
5739: $backtourl = '/adm/navmaps';
1.525 raeburn 5740: }
5741: }
5742: } elsif ($env{'docs.exit.'.$env{'request.course.id'}} eq '/adm/menu') {
5743: $backtourl = '/adm/menu';
5744: } elsif ($supplementalflag) {
1.472 raeburn 5745: $backtourl = '/adm/supplemental';
1.525 raeburn 5746: } else {
5747: $backtourl = '/adm/navmaps';
1.472 raeburn 5748: }
5749:
1.519 raeburn 5750: my $fieldsets = "'ext','doc'";
5751: unless ($main_container_page) {
5752: $fieldsets .=",'ims'";
5753: }
1.501 raeburn 5754: if ($supplementalflag) {
5755: $fieldsets = "'suppext','suppdoc'";
5756: }
5757:
1.329 droeschl 5758: return <<ENDNEWSCRIPT;
5759: function makenewfolder(targetform,folderseq) {
5760: var foldername=prompt('$lt{"p_mnf"}','$lt{"t_mnf"}');
5761: if (foldername) {
5762: targetform.importdetail.value=escape(foldername)+"="+folderseq;
5763: targetform.submit();
5764: }
5765: }
5766:
5767: function makenewpage(targetform,folderseq) {
5768: var pagename=prompt('$lt{"p_mnp"}','$lt{"t_mnp"}');
5769: if (pagename) {
5770: targetform.importdetail.value=escape(pagename)+"="+folderseq;
5771: targetform.submit();
5772: }
5773: }
5774:
5775: function makeexamupload() {
5776: var title=prompt('$lt{"p_mxu"}');
1.344 bisitz 5777: if (title) {
1.329 droeschl 5778: this.document.forms.newexamupload.importdetail.value=
5779: escape(title)+'=/res/lib/templates/examupload.problem';
5780: this.document.forms.newexamupload.submit();
5781: }
5782: }
5783:
5784: function makesmppage() {
5785: var title=prompt('$lt{"p_msp"}');
1.344 bisitz 5786: if (title) {
1.329 droeschl 5787: this.document.forms.newsmppg.importdetail.value=
1.533 raeburn 5788: escape(title)+'=/adm/$udom/$uname/new/smppg';
1.329 droeschl 5789: this.document.forms.newsmppg.submit();
5790: }
5791: }
5792:
1.534 raeburn 5793: function makewebpage(type) {
5794: var title=prompt('$lt{"p_mwp"}');
5795: var formname;
5796: if (type == 'supp') {
5797: formname = this.document.forms.supwebpage;
5798: } else {
5799: formname = this.document.forms.newwebpage;
5800: }
5801: if (title) {
5802: var webpage = formname.importdetail.value;
5803: formname.importdetail.value = escape(title)+'='+webpage;
5804: formname.submit();
5805: }
5806: }
5807:
1.329 droeschl 5808: function makesmpproblem() {
5809: var title=prompt('$lt{"p_msb"}');
1.344 bisitz 5810: if (title) {
1.329 droeschl 5811: this.document.forms.newsmpproblem.importdetail.value=
5812: escape(title)+'=/res/lib/templates/simpleproblem.problem';
5813: this.document.forms.newsmpproblem.submit();
5814: }
5815: }
5816:
5817: function makedropbox() {
5818: var title=prompt('$lt{"p_mdb"}');
1.344 bisitz 5819: if (title) {
1.329 droeschl 5820: this.document.forms.newdropbox.importdetail.value=
5821: escape(title)+'=/res/lib/templates/DropBox.problem';
5822: this.document.forms.newdropbox.submit();
5823: }
5824: }
5825:
5826: function makebulboard() {
5827: var title=prompt('$lt{"p_mbb"}');
5828: if (title) {
5829: this.document.forms.newbul.importdetail.value=
1.533 raeburn 5830: escape(title)+'=/adm/$udom/$uname/new/bulletinboard';
1.329 droeschl 5831: this.document.forms.newbul.submit();
5832: }
5833: }
5834:
5835: function makeabout() {
5836: var user=prompt("$lt{'p_mab'}");
5837: if (user) {
5838: var comp=new Array();
5839: comp=user.split(':');
5840: if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
5841: if ((comp[0]) && (comp[1])) {
5842: this.document.forms.newaboutsomeone.importdetail.value=
5843: '$lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
1.335 ehlerst 5844: this.document.forms.newaboutsomeone.submit();
5845: } else {
5846: alert("$lt{'p_mab_alrt1'}");
1.329 droeschl 5847: }
1.335 ehlerst 5848: } else {
5849: alert("$lt{'p_mab_alrt2'}");
5850: }
5851: }
1.329 droeschl 5852: }
5853:
1.501 raeburn 5854: function toggleUpload(caller) {
5855: var blocks = Array($fieldsets);
5856: for (var i=0; i<blocks.length; i++) {
5857: var disp = 'none';
5858: if (caller == blocks[i]) {
5859: var curr = document.getElementById('upload'+caller+'form').style.display;
5860: if (curr == 'none') {
5861: disp='block';
5862: }
5863: }
5864: document.getElementById('upload'+blocks[i]+'form').style.display=disp;
5865: }
1.502 raeburn 5866: resize_scrollbox('contentscroll','1','1');
5867: return;
5868: }
5869:
1.514 raeburn 5870: function toggleMap(caller) {
1.502 raeburn 5871: var disp = 'none';
1.510 raeburn 5872: if (document.getElementById('importmapform')) {
1.514 raeburn 5873: if (caller == 'map') {
5874: var curr = document.getElementById('importmapform').style.display;
5875: if (curr == 'none') {
5876: disp='block';
5877: }
1.510 raeburn 5878: }
5879: document.getElementById('importmapform').style.display=disp;
5880: resize_scrollbox('contentscroll','1','1');
1.502 raeburn 5881: }
1.501 raeburn 5882: return;
1.329 droeschl 5883: }
5884:
1.501 raeburn 5885: function makeims(imsform) {
5886: if ((imsform.uploaddoc.value == '') || (!imsform.uploaddoc.value)) {
5887: alert("$lt{'imsfile'}");
5888: return;
5889: }
5890: if (imsform.source.selectedIndex == 0) {
5891: alert("$lt{'imscms'}");
5892: return;
5893: }
5894: newWindow = window.open('', 'IMSimport',"HEIGHT=700,WIDTH=750,scrollbars=yes");
5895: imsform.submit();
5896: }
5897:
1.519 raeburn 5898: function changename(folderpath,index,oldtitle) {
1.335 ehlerst 5899: var title=prompt('$lt{"p_chn"}',oldtitle);
5900: if (title) {
1.538 raeburn 5901: this.document.forms.renameform.markcopy.value='';
1.335 ehlerst 5902: this.document.forms.renameform.title.value=title;
5903: this.document.forms.renameform.cmd.value='rename_'+index;
1.519 raeburn 5904: this.document.forms.renameform.folderpath.value=folderpath;
1.335 ehlerst 5905: this.document.forms.renameform.submit();
5906: }
1.329 droeschl 5907: }
5908:
1.478 raeburn 5909: function updatePick(targetform,index,caller) {
1.537 raeburn 5910: var pickitem;
5911: var picknumitem;
5912: var picknumtext;
5913: if (index == 'all') {
5914: pickitem = document.getElementById('randompickall');
5915: picknumitem = document.getElementById('rpicknumall');
5916: picknumtext = document.getElementById('rpicktextall');
5917: } else {
5918: pickitem = document.getElementById('randompick_'+index);
5919: picknumitem = document.getElementById('rpicknum_'+index);
5920: picknumtext = document.getElementById('randompicknum_'+index);
5921: }
1.478 raeburn 5922: if (pickitem.checked) {
5923: var picknum=prompt('$lt{"rpck"}',picknumitem.value);
5924: if (picknum == '' || picknum == null) {
5925: if (caller == 'check') {
5926: pickitem.checked=false;
1.537 raeburn 5927: if (index == 'all') {
5928: picknumtext.innerHTML = '';
5929: if (caller == 'link') {
5930: propagateState(targetform,'rpicknum');
5931: }
5932: } else {
1.538 raeburn 5933: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 5934: }
1.478 raeburn 5935: }
5936: } else {
5937: picknum.toString();
5938: var regexdigit=/^\\d+\$/;
5939: if (regexdigit.test(picknum)) {
5940: picknumitem.value = picknum;
1.537 raeburn 5941: if (index == 'all') {
1.538 raeburn 5942: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.cumulativesettings,\\'all\\',\\'link\\');">'+picknum+'</a>';
1.537 raeburn 5943: if (caller == 'link') {
5944: propagateState(targetform,'rpicknum');
5945: }
5946: } else {
5947: picknumtext.innerHTML = ' <a href="javascript:updatePick(document.edit_randompick_'+index+',\\''+index+'\\',\\'link\\');">'+picknum+'</a>';
1.538 raeburn 5948: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 5949: }
1.478 raeburn 5950: } else {
5951: if (caller == 'check') {
1.537 raeburn 5952: if (index == 'all') {
5953: picknumtext.innerHTML = '';
5954: if (caller == 'link') {
5955: propagateState(targetform,'rpicknum');
5956: }
5957: } else {
5958: pickitem.checked=false;
1.538 raeburn 5959: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 5960: }
1.478 raeburn 5961: }
5962: return;
5963: }
5964: }
5965: } else {
1.537 raeburn 5966: picknumitem.value = '';
5967: picknumtext.innerHTML = '';
5968: if (index == 'all') {
5969: if (caller == 'link') {
5970: propagateState(targetform,'rpicknum');
5971: }
5972: } else {
1.538 raeburn 5973: checkForSubmit(targetform,'randompick','settings');
1.537 raeburn 5974: }
5975: }
5976: }
5977:
5978: function propagateState(form,param) {
5979: if (document.getElementById(param+'all')) {
5980: var setcheck = 0;
5981: var rpick = 0;
5982: if (param == 'rpicknum') {
5983: if (document.getElementById('randompickall')) {
5984: if (document.getElementById('randompickall').checked) {
5985: if (document.getElementById('rpicknumall')) {
5986: rpick = document.getElementById('rpicknumall').value;
5987: }
5988: }
5989: }
5990: } else {
5991: if (document.getElementById(param+'all').checked) {
5992: setcheck = 1;
5993: }
5994: }
1.538 raeburn 5995: var allidxlist;
5996: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
5997: if (document.getElementById('all'+param+'idx')) {
5998: allidxlist = document.getElementById('all'+param+'idx').value;
5999: }
6000: var actions = new Array ('remove','cut','copy');
6001: for (var i=0; i<actions.length; i++) {
6002: if (actions[i] != param) {
6003: if (document.getElementById(actions[i]+'all')) {
6004: document.getElementById(actions[i]+'all').checked = false;
6005: }
6006: }
6007: }
6008: }
1.537 raeburn 6009: if ((param == 'encrypturl') || (param == 'hiddenresource')) {
1.538 raeburn 6010: allidxlist = form.allidx.value;
6011: }
6012: if ((param == 'randompick') || (param == 'rpicknum') || (param == 'randomorder')) {
6013: allidxlist = form.allmapidx.value;
6014: }
6015: if ((allidxlist != '') && (allidxlist != null)) {
6016: var allidxs = allidxlist.split(',');
6017: if (allidxs.length > 1) {
6018: for (var i=0; i<allidxs.length; i++) {
6019: if (document.getElementById(param+'_'+allidxs[i])) {
6020: if (param == 'rpicknum') {
6021: if (document.getElementById('randompick_'+allidxs[i])) {
6022: if (document.getElementById('randompick_'+allidxs[i]).checked) {
6023: document.getElementById(param+'_'+allidxs[i]).value = rpick;
6024: if (rpick > 0) {
6025: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = ': <a href="javascript:updatePick(document.edit_randompick_'+allidxs[i]+',\\''+allidxs[i]+'\\',\\'link\\')">'+rpick+'</a>';
6026: } else {
6027: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
6028: }
6029: }
6030: }
6031: } else {
1.537 raeburn 6032: if (setcheck == 1) {
6033: document.getElementById(param+'_'+allidxs[i]).checked = true;
6034: } else {
6035: document.getElementById(param+'_'+allidxs[i]).checked = false;
1.538 raeburn 6036: if (param == 'randompick') {
6037: document.getElementById('randompicknum_'+allidxs[i]).innerHTML = '';
6038: }
1.537 raeburn 6039: }
6040: }
6041: }
6042: }
1.538 raeburn 6043: if (setcheck == 1) {
6044: if ((param == 'remove') || (param == 'cut') || (param == 'copy')) {
6045: var actions = new Array('copy','cut','remove');
6046: for (var i=0; i<actions.length; i++) {
6047: var otheractions;
6048: var otheridxs;
6049: if (actions[i] === param) {
6050: continue;
6051: } else {
6052: if (document.getElementById('all'+actions[i]+'idx')) {
6053: otheractions = document.getElementById('all'+actions[i]+'idx').value;
6054: otheridxs = otheractions.split(',');
6055: if (otheridxs.length > 1) {
6056: for (var j=0; j<otheridxs.length; j++) {
6057: if (document.getElementById(actions[i]+'_'+otheridxs[j])) {
6058: document.getElementById(actions[i]+'_'+otheridxs[j]).checked = false;
6059: }
1.537 raeburn 6060: }
6061: }
6062: }
1.538 raeburn 6063: }
6064: }
6065: }
6066: }
6067: }
6068: }
6069: }
6070: return;
6071: }
6072:
6073: function checkForSubmit(targetform,param,context,idx,folderpath,index,oldtitle,skip_confirm,container,folder) {
1.539 raeburn 6074: var dosettings;
6075: var doaction;
1.538 raeburn 6076: var control = document.togglemultsettings;
6077: if (context == 'actions') {
6078: control = document.togglemultactions;
1.539 raeburn 6079: doaction = 1;
6080: } else {
6081: dosettings = 1;
1.538 raeburn 6082: }
1.539 raeburn 6083: if (control) {
6084: if (control.showmultpick.length) {
6085: for (var i=0; i<control.showmultpick.length; i++) {
6086: if (control.showmultpick[i].checked) {
6087: if (control.showmultpick[i].value == 1) {
6088: if (context == 'settings') {
6089: dosettings = 0;
6090: } else {
6091: doaction = 0;
1.538 raeburn 6092: }
6093: }
6094: }
1.537 raeburn 6095: }
6096: }
1.539 raeburn 6097: }
6098: if (context == 'settings') {
6099: if (dosettings == 1) {
1.538 raeburn 6100: targetform.changeparms.value=param;
6101: targetform.submit();
6102: }
1.537 raeburn 6103: }
1.539 raeburn 6104: if (context == 'actions') {
6105: if (doaction == 1) {
6106: targetform.cmd.value=param+'_'+index;
6107: targetform.folderpath.value=folderpath;
6108: targetform.markcopy.value=idx+':'+param;
6109: targetform.copyfolder.value=folder+'.'+container;
6110: if (param == 'remove') {
6111: if (skip_confirm || confirm('$lt{"p_rmr1"}\\n\\n$lt{"p_rmr2a"} "'+oldtitle+'" $lt{"p_rmr2b"}')) {
6112: targetform.markcopy.value='';
6113: targetform.copyfolder.value='';
6114: targetform.submit();
6115: }
6116: }
6117: if (param == 'cut') {
6118: if (skip_confirm || confirm('$lt{"p_ctr1a"}\\n$lt{"p_ctr1b"}\\n\\n$lt{"p_ctr2a"} "'+oldtitle+'" $lt{"p_ctr2b"}')) {
6119: targetform.submit();
6120: return;
6121: }
6122: }
6123: if (param == 'copy') {
6124: targetform.submit();
6125: return;
6126: }
6127: targetform.markcopy.value='';
6128: targetform.copyfolder.value='';
6129: targetform.cmd.value='';
6130: targetform.folderpath.value='';
6131: return;
6132: } else {
6133: if (document.getElementById(param+'_'+idx)) {
6134: item = document.getElementById(param+'_'+idx);
6135: if (item.type == 'checkbox') {
6136: if (item.checked) {
6137: item.checked = false;
6138: } else {
6139: item.checked = true;
6140: singleCheck(item,idx,param);
6141: }
6142: }
6143: }
6144: }
6145: }
1.537 raeburn 6146: return;
6147: }
6148:
1.538 raeburn 6149: function singleCheck(caller,idx,action) {
6150: actions = new Array('cut','copy','remove');
6151: if (caller.checked) {
6152: for (var i=0; i<actions.length; i++) {
6153: if (actions[i] != action) {
6154: if (document.getElementById(actions[i]+'_'+idx)) {
6155: if (document.getElementById(actions[i]+'_'+idx).checked) {
6156: document.getElementById(actions[i]+'_'+idx).checked = false;
6157: }
1.537 raeburn 6158: }
6159: }
6160: }
1.478 raeburn 6161: }
1.537 raeburn 6162: return;
1.478 raeburn 6163: }
6164:
1.334 muellerd 6165: function unselectInactive(nav) {
1.335 ehlerst 6166: currentNav = document.getElementById(nav);
6167: currentLis = currentNav.getElementsByTagName('LI');
6168: for (i = 0; i < currentLis.length; i++) {
1.472 raeburn 6169: if (currentLis[i].className == 'goback') {
6170: currentLis[i].className = 'goback';
6171: } else {
6172: if (currentLis[i].className == 'right active' || currentLis[i].className == 'right') {
1.374 tempelho 6173: currentLis[i].className = 'right';
1.472 raeburn 6174: } else {
1.374 tempelho 6175: currentLis[i].className = 'i';
1.472 raeburn 6176: }
6177: }
1.335 ehlerst 6178: }
1.332 tempelho 6179: }
6180:
1.334 muellerd 6181: function hideAll(current, nav, data) {
1.335 ehlerst 6182: unselectInactive(nav);
1.374 tempelho 6183: if(current.className == 'right'){
6184: current.className = 'right active'
6185: }else{
6186: current.className = 'active';
6187: }
1.335 ehlerst 6188: currentData = document.getElementById(data);
6189: currentDivs = currentData.getElementsByTagName('DIV');
6190: for (i = 0; i < currentDivs.length; i++) {
6191: if(currentDivs[i].className == 'LC_ContentBox'){
1.333 muellerd 6192: currentDivs[i].style.display = 'none';
1.330 tempelho 6193: }
6194: }
1.335 ehlerst 6195: }
1.330 tempelho 6196:
1.374 tempelho 6197: function openTabs(pageId) {
6198: tabnav = document.getElementById(pageId).getElementsByTagName('UL');
1.383 tempelho 6199: if(tabnav.length > 2 ){
1.389 tempelho 6200: currentNav = document.getElementById(tabnav[1].id);
1.374 tempelho 6201: currentLis = currentNav.getElementsByTagName('LI');
6202: for(i = 0; i< currentLis.length; i++){
6203: if(currentLis[i].className == 'active') {
1.375 tempelho 6204: funcString = currentLis[i].onclick.toString();
6205: tab = funcString.split('"');
1.420 onken 6206: if(tab.length < 2) {
6207: tab = funcString.split("'");
6208: }
1.375 tempelho 6209: currentData = document.getElementById(tab[1]);
6210: currentData.style.display = 'block';
1.374 tempelho 6211: }
6212: }
6213: }
6214: }
6215:
1.334 muellerd 6216: function showPage(current, pageId, nav, data) {
6217: hideAll(current, nav, data);
1.375 tempelho 6218: openTabs(pageId);
1.334 muellerd 6219: unselectInactive(nav);
1.330 tempelho 6220: current.className = 'active';
6221: currentData = document.getElementById(pageId);
6222: currentData.style.display = 'block';
1.458 raeburn 6223: activeTab = pageId;
1.501 raeburn 6224: toggleUpload();
1.503 raeburn 6225: toggleMap();
1.433 raeburn 6226: if (nav == 'mainnav') {
6227: var storedpath = "$docs_folderpath";
1.434 raeburn 6228: var storedpage = "$main_container_page";
1.433 raeburn 6229: var reg = new RegExp("^supplemental");
6230: if (pageId == 'mainCourseDocuments') {
1.434 raeburn 6231: if (storedpage == 1) {
6232: document.simpleedit.folderpath.value = '';
6233: document.uploaddocument.folderpath.value = '';
6234: } else {
6235: if (reg.test(storedpath)) {
6236: document.simpleedit.folderpath.value = '$toplevelmain';
6237: document.uploaddocument.folderpath.value = '$toplevelmain';
6238: document.newext.folderpath.value = '$toplevelmain';
6239: } else {
6240: document.simpleedit.folderpath.value = storedpath;
6241: document.uploaddocument.folderpath.value = storedpath;
6242: document.newext.folderpath.value = storedpath;
6243: }
1.433 raeburn 6244: }
6245: } else {
1.434 raeburn 6246: if (reg.test(storedpath)) {
6247: document.simpleedit.folderpath.value = storedpath;
6248: document.supuploaddocument.folderpath.value = storedpath;
6249: document.supnewext.folderpath.value = storedpath;
6250: } else {
1.433 raeburn 6251: document.simpleedit.folderpath.value = '$toplevelsupp';
6252: document.supuploaddocument.folderpath.value = '$toplevelsupp';
6253: document.supnewext.folderpath.value = '$toplevelsupp';
6254: }
6255: }
6256: }
1.485 raeburn 6257: resize_scrollbox('contentscroll','1','0');
1.330 tempelho 6258: return false;
6259: }
1.329 droeschl 6260:
1.472 raeburn 6261: function toContents(jumpto) {
6262: var newurl = '$backtourl';
1.525 raeburn 6263: if ((newurl == '/adm/navmaps') && (jumpto != '')) {
1.472 raeburn 6264: newurl = newurl+'?postdata='+jumpto;
6265: }
6266: location.href=newurl;
6267: }
6268:
1.538 raeburn 6269: function togglePick(caller,value) {
6270: var disp = 'none';
6271: if (document.getElementById('multi'+caller)) {
6272: var curr = document.getElementById('multi'+caller).style.display;
6273: if (value == 1) {
6274: disp='block';
6275: }
6276: if (curr == disp) {
6277: return;
6278: }
6279: document.getElementById('multi'+caller).style.display=disp;
6280: if (value == 1) {
6281: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$lt{'more'}</a>';
6282: } else {
6283: document.getElementById('more'+caller).innerHTML = '';
6284: }
6285: if (caller == 'actions') {
6286: setClass(value);
6287: setBoxes(value);
6288: }
6289: }
6290: var showButton = multiSettings();
6291: if (showButton != 1) {
6292: showButton = multiActions();
6293: }
6294: if (document.getElementById('multisave')) {
6295: if (showButton == 1) {
6296: document.getElementById('multisave').style.display='block';
6297: } else {
6298: document.getElementById('multisave').style.display='none';
6299: }
6300: }
6301: resize_scrollbox('contentscroll','1','1');
6302: return;
6303: }
6304:
6305: function toggleCheckUncheck(caller,more) {
6306: if (more == 1) {
6307: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',0);" style="text-decoration:none;">$lt{'less'}</a>';
6308: document.getElementById('allfields'+caller).style.display='block';
6309: } else {
6310: document.getElementById('more'+caller).innerHTML = ' <a href="javascript:toggleCheckUncheck(\\''+caller+'\\',1);" style="text-decoration:none;">$lt{'more'}</a>';
6311: document.getElementById('allfields'+caller).style.display='none';
6312: }
6313: resize_scrollbox('contentscroll','1','1');
6314: }
6315:
6316: function multiSettings() {
6317: var inuse = 0;
6318: var settingsform = document.togglemultsettings;
6319: if (settingsform.showmultpick.length > 1) {
6320: for (var i=0; i<settingsform.showmultpick.length; i++) {
6321: if (settingsform.showmultpick[i].checked) {
6322: if (settingsform.showmultpick[i].value == 1) {
6323: inuse = 1;
6324: }
6325: }
6326: }
6327: }
6328: return inuse;
6329: }
6330:
6331: function multiActions() {
6332: var inuse = 0;
6333: var actionsform = document.togglemultactions;
6334: if (actionsform.showmultpick.length > 1) {
6335: for (var i=0; i<actionsform.showmultpick.length; i++) {
6336: if (actionsform.showmultpick[i].checked) {
6337: if (actionsform.showmultpick[i].value == 1) {
6338: inuse = 1;
6339: }
6340: }
6341: }
6342: }
6343: return inuse;
6344: }
6345:
6346: function checkSubmits() {
6347: var numchanges = 0;
6348: var form = document.saveactions;
6349: var doactions = multiActions();
1.542 raeburn 6350: var cutwarnings = 0;
6351: var remwarnings = 0;
1.538 raeburn 6352: if (doactions == 1) {
6353: var remidxlist = document.cumulativeactions.allremoveidx.value;
6354: if ((remidxlist != '') && (remidxlist != null)) {
6355: var remidxs = remidxlist.split(',');
6356: for (var i=0; i<remidxs.length; i++) {
6357: if (document.getElementById('remove_'+remidxs[i])) {
6358: if (document.getElementById('remove_'+remidxs[i]).checked) {
6359: form.multiremove.value += remidxs[i]+',';
6360: numchanges ++;
1.542 raeburn 6361: if (document.getElementById('skip_remove_'+remidxs[i])) {
6362: if (document.getElementById('skip_remove_'+remidxs[i]).value == 0) {
6363: remwarnings ++;
6364: }
6365: }
1.537 raeburn 6366: }
6367: }
1.538 raeburn 6368: }
6369: }
6370: var cutidxlist = document.cumulativeactions.allcutidx.value;
6371: if ((cutidxlist != '') && (cutidxlist != null)) {
6372: var cutidxs = cutidxlist.split(',');
6373: for (var i=0; i<cutidxs.length; i++) {
6374: if (document.getElementById('cut_'+cutidxs[i])) {
6375: if (document.getElementById('cut_'+cutidxs[i]).checked == true) {
6376: form.multicut.value += cutidxs[i]+',';
6377: numchanges ++;
1.542 raeburn 6378: if (document.getElementById('skip_cut_'+cutidxs[i])) {
6379: if (document.getElementById('skip_cut_'+cutidxs[i]).value == 0) {
6380: cutwarnings ++;
6381: }
6382: }
1.537 raeburn 6383: }
6384: }
6385: }
6386: }
1.538 raeburn 6387: var copyidxlist = document.cumulativeactions.allcopyidx.value;
6388: if ((copyidxlist != '') && (copyidxlist != null)) {
6389: var copyidxs = copyidxlist.split(',');
6390: for (var i=0; i<copyidxs.length; i++) {
6391: if (document.getElementById('copy_'+copyidxs[i])) {
6392: if (document.getElementById('copy_'+copyidxs[i]).checked) {
6393: form.multicopy.value += copyidxs[i]+',';
6394: numchanges ++;
6395: }
6396: }
6397: }
6398: }
6399: if (numchanges > 0) {
6400: form.multichange.value = numchanges;
6401: }
1.537 raeburn 6402: }
1.538 raeburn 6403: var dosettings = multiSettings();
1.543 raeburn 6404: var haschanges = 0;
1.538 raeburn 6405: if (dosettings == 1) {
6406: form.allencrypturl.value = '';
6407: form.allhiddenresource.value = '';
1.543 raeburn 6408: form.changeparms.value = 'all';
6409: var patt=new RegExp(",\$");
1.538 raeburn 6410: var allidxlist = document.cumulativesettings.allidx.value;
6411: if ((allidxlist != '') && (allidxlist != null)) {
6412: var allidxs = allidxlist.split(',');
6413: if (allidxs.length > 1) {
6414: for (var i=0; i<allidxs.length; i++) {
6415: if (document.getElementById('hiddenresource_'+allidxs[i])) {
6416: if (document.getElementById('hiddenresource_'+allidxs[i]).checked) {
6417: form.allhiddenresource.value += allidxs[i]+',';
6418: }
6419: }
6420: if (document.getElementById('encrypturl_'+allidxs[i])) {
6421: if (document.getElementById('encrypturl_'+allidxs[i]).checked) {
6422: form.allencrypturl.value += allidxs[i]+',';
6423: }
6424: }
6425: }
1.543 raeburn 6426: form.allhiddenresource.value = form.allhiddenresource.value.replace(patt,"");
6427: form.allencrypturl.value = form.allencrypturl.value.replace(patt,"");
1.537 raeburn 6428: }
1.538 raeburn 6429: }
6430: form.allrandompick.value = '';
6431: form.allrandomorder.value = '';
6432: var allmapidxlist = document.cumulativesettings.allmapidx.value;
6433: if ((allmapidxlist != '') && (allmapidxlist != null)) {
6434: var allmapidxs = allmapidxlist.split(',');
6435: for (var i=0; i<allmapidxs.length; i++) {
6436: var randompick = document.getElementById('randompick_'+allmapidxs[i]);
6437: var rpicknum = document.getElementById('rpicknum_'+allmapidxs[i]);
6438: var randorder = document.getElementById('randomorder_'+allmapidxs[i]);
6439: if ((randompick.checked) && (rpicknum.value != '')) {
6440: form.allrandompick.value += allmapidxs[i]+':'+rpicknum.value+',';
6441: }
6442: if (randorder.checked) {
6443: form.allrandomorder.value += allmapidxs[i]+',';
6444: }
1.537 raeburn 6445: }
1.543 raeburn 6446: form.allrandompick.value = form.allrandompick.value.replace(patt,"");
6447: form.allrandomorder.value = form.allrandomorder.value.replace(patt,"");
6448: }
6449: if (document.cumulativesettings.currhiddenresource.value != form.allhiddenresource.value) {
6450: haschanges = 1;
6451: }
6452: if (document.cumulativesettings.currencrypturl.value != form.allencrypturl.value) {
6453: haschanges = 1;
6454: }
6455: if (document.cumulativesettings.currrandomorder.value != form.allrandomorder.value) {
6456: haschanges = 1;
6457: }
6458: if (document.cumulativesettings.currrandompick.value != form.allrandompick.value) {
6459: haschanges = 1;
1.537 raeburn 6460: }
6461: }
1.543 raeburn 6462: if (doactions == 1) {
1.542 raeburn 6463: if (numchanges > 0) {
6464: if ((cutwarnings > 0) || (remwarnings > 0)) {
6465: if (remwarnings > 0) {
6466: if (!confirm('$lt{"p_rmr1"}\\n\\n$lt{"p_rmr3a"} '+remwarnings+' $lt{"p_rmr3b"}')) {
6467: return false;
6468: }
6469: }
6470: if (cutwarnings > 0) {
6471: if (!confirm('$lt{"p_ctr1a"}\\n$lt{"p_ctr1b"}\\n\\n$lt{"p_ctr3a"} '+cutwarnings+' $lt{"p_ctr3b"}')) {
6472: return false;
6473: }
6474: }
6475: }
6476: form.submit();
6477: return true;
1.543 raeburn 6478: }
6479: }
6480: if (dosettings == 1) {
6481: if (haschanges == 1) {
1.542 raeburn 6482: form.submit();
6483: return true;
6484: }
1.543 raeburn 6485: }
6486: if ((dosettings == 1) && (doactions == 1)) {
6487: alert("$lt{'noor'}");
6488: } else {
6489: if (dosettings == 1) {
6490: alert("$lt{'noch'}");
6491: } else {
6492: alert("$lt{'noac'}");
6493: }
6494: }
1.538 raeburn 6495: return false;
6496: }
6497:
6498: function setClass(value) {
6499: var cutclass = 'LC_docs_cut';
6500: var copyclass = 'LC_docs_copy';
6501: var removeclass = 'LC_docs_remove';
6502: var cutreg = new RegExp("\\\\b"+cutclass+"\\\\b");
6503: var copyreg = new RegExp("\\\\b"+copyclass+"\\\\b");
6504: var removereg = new RegExp("\\\\"+removeclass+"\\\\b");
6505: var links = document.getElementsByTagName('a');
6506: for (var i=0; i<links.length; i++) {
6507: var classes = links[i].className;
6508: if (cutreg.test(classes)) {
6509: links[i].className = cutclass;
6510: if (value == 1) {
6511: links[i].className += " LC_menubuttons_link";
6512: }
6513: } else {
6514: if (copyreg.test(classes)) {
6515: links[i].className = copyclass;
6516: if (value == 1) {
6517: links[i].className += " LC_menubuttons_link";
6518: }
6519: } else {
6520: if (removereg.test(classes)) {
6521: links[i].className = removeclass;
6522: if (value == 1) {
6523: links[i].className += " LC_menubuttons_link";
6524: }
6525: }
6526: }
6527: }
6528: }
6529: return;
1.537 raeburn 6530: }
6531:
1.538 raeburn 6532: function setBoxes(value) {
6533: var remidxlist = document.cumulativeactions.allremoveidx.value;
6534: if ((remidxlist != '') && (remidxlist != null)) {
6535: var remidxs = remidxlist.split(',');
6536: for (var i=0; i<remidxs.length; i++) {
6537: if (document.getElementById('remove_'+remidxs[i])) {
6538: var item = document.getElementById('remove_'+remidxs[i]);
6539: if (value == 1) {
6540: item.className = 'LC_docs_remove';
6541: } else {
6542: item.className = 'LC_hidden';
6543: }
6544: }
6545: }
6546: }
6547: var cutidxlist = document.cumulativeactions.allcutidx.value;
6548: if ((cutidxlist != '') && (cutidxlist != null)) {
6549: var cutidxs = cutidxlist.split(',');
6550: for (var i=0; i<cutidxs.length; i++) {
6551: if (document.getElementById('cut_'+cutidxs[i])) {
6552: var item = document.getElementById('cut_'+cutidxs[i]);
6553: if (value == 1) {
6554: item.className = 'LC_docs_cut';
6555: } else {
6556: item.className = 'LC_hidden';
6557: }
6558: }
1.537 raeburn 6559: }
6560: }
1.538 raeburn 6561: var copyidxlist = document.cumulativeactions.allcopyidx.value;
6562: if ((copyidxlist != '') && (copyidxlist != null)) {
6563: var copyidxs = copyidxlist.split(',');
6564: for (var i=0; i<copyidxs.length; i++) {
6565: if (document.getElementById('copy_'+copyidxs[i])) {
6566: var item = document.getElementById('copy_'+copyidxs[i]);
6567: if (value == 1) {
6568: item.className = 'LC_docs_copy';
6569: } else {
6570: item.className = 'LC_hidden';
6571: }
6572: }
1.537 raeburn 6573: }
6574: }
6575: return;
6576: }
6577:
1.329 droeschl 6578: ENDNEWSCRIPT
6579: }
1.457 raeburn 6580:
1.483 raeburn 6581: sub history_tab_js {
6582: return <<"ENDHIST";
6583: function toggleHistoryDisp(choice) {
6584: document.docslogform.docslog.value = choice;
6585: document.docslogform.submit();
6586: return;
6587: }
6588:
6589: ENDHIST
6590: }
6591:
1.484 raeburn 6592: sub inject_data_js {
6593: return <<ENDINJECT;
6594:
6595: function injectData(current, hiddenField, name, value) {
6596: currentElement = document.getElementById(hiddenField);
6597: currentElement.name = name;
6598: currentElement.value = value;
6599: current.submit();
6600: }
6601:
6602: ENDINJECT
6603: }
6604:
6605: sub dump_switchserver_js {
6606: my @hosts = @_;
6607: my %lt = &Apache::lonlocal::texthash(
6608: dump => 'Dumping to Authoring Space requires switching server.',
6609: swit => 'Switch server?',
6610: duco => 'Dump content to Authoring Space',
6611: yone => 'You need to switch to a server housing an Authoring Space for which you are author or co-author.',
6612: chos => 'Choose server',
6613: );
6614: my $role = $env{'request.role'};
6615: my $js = <<"ENDSWJS";
6616: <script type="text/javascript">
6617: function write_switchserver() {
6618: var server;
6619: if (document.setserver.posshosts.length > 0) {
6620: for (var i=0; i<document.setserver.posshosts.length; i++) {
6621: if (document.setserver.posshosts[i].checked) {
6622: server = document.setserver.posshosts[i].value;
6623: }
6624: }
6625: opener.document.location.href="/adm/switchserver?otherserver="+server+"&role=$role&origurl=/adm/coursedocs";
6626: }
6627: window.close();
6628: }
6629: </script>
6630:
6631: ENDSWJS
6632:
6633: my $startpage = &Apache::loncommon::start_page('Choose server',$js,
6634: {'only_body' => 1,
6635: 'js_ready' => 1,});
6636: my $endpage = &Apache::loncommon::end_page({'js_ready' => 1});
6637:
6638: my $hostpicker;
6639: my $count = 0;
6640: foreach my $host (sort(@hosts)) {
6641: my $checked;
6642: if ($count == 0) {
6643: $checked = ' checked="checked"';
6644: }
6645: $hostpicker .= '<label><input type="radio" name="posshosts" value="'.
6646: $host.'"'.$checked.' />'.$host.'</label> ';
6647: $count++;
6648: }
6649:
6650: return <<"ENDSWITCHJS";
6651:
6652: function dump_needs_switchserver(url) {
6653: if (url!='' && url!= null) {
6654: if (confirm("$lt{'dump'}\\n$lt{'swit'}")) {
6655: go(url);
6656: }
6657: }
6658: return;
6659: }
6660:
6661: function choose_switchserver_window() {
6662: newWindow = window.open('','ChooseServer','height=400,width=500,scrollbars=yes')
6663: newWindow.document.open();
6664: newWindow.document.writeln('$startpage');
6665: newWindow.document.write('<h3>$lt{'duco'}<\\/h3>\\n'+
6666: '<p>$lt{'yone'}<\\/p>\\n'+
6667: '<div class="LC_left_float"><fieldset><legend>$lt{'chos'}<\\/legend>\\n'+
6668: '<form name="setserver" method="post" action="" \\/>\\n'+
6669: '$hostpicker\\n'+
6670: '<br \\/><br \\/>\\n'+
6671: '<input type="button" name="makeswitch" value="$lt{'swit'}" '+
6672: 'onclick="write_switchserver();" \\/>\\n'+
6673: '<\\/form><\\/fieldset><\\/div><br clear="all" \\/>\\n');
6674: newWindow.document.writeln('$endpage');
6675: newWindow.document.close();
6676: newWindow.focus();
6677: }
6678:
6679: ENDSWITCHJS
6680: }
6681:
6682: sub makedocslogform {
6683: my ($formelems,$docslog) = @_;
6684: return <<"LOGSFORM";
6685: <form action="/adm/coursedocs" method="post" name="docslogform">
6686: <input type="hidden" name="docslog" value="$docslog" />
6687: $formelems
6688: </form>
6689: LOGSFORM
6690: }
6691:
6692: sub makesimpleeditform {
6693: my ($formelems) = @_;
6694: return <<"SIMPFORM";
6695: <form name="simpleedit" method="post" action="/adm/coursedocs">
6696: <input type="hidden" name="importdetail" value="" />
6697: $formelems
6698: </form>
6699: SIMPFORM
6700: }
6701:
1.329 droeschl 6702: 1;
6703: __END__
6704:
6705:
6706: =head1 NAME
6707:
6708: Apache::londocs.pm
6709:
6710: =head1 SYNOPSIS
6711:
6712: This is part of the LearningOnline Network with CAPA project
6713: described at http://www.lon-capa.org.
6714:
6715: =head1 SUBROUTINES
6716:
6717: =over
6718:
6719: =item %help=()
6720:
6721: Available help topics
6722:
6723: =item mapread()
6724:
1.344 bisitz 6725: Mapread read maps into LONCAPA::map:: global arrays
1.329 droeschl 6726: @order and @resources, determines status
6727: sets @order - pointer to resources in right order
6728: sets @resources - array with the resources with correct idx
6729:
6730: =item authorhosts()
6731:
6732: Return hash with valid author names
6733:
6734: =item clean()
6735:
6736: =item dumpcourse()
6737:
6738: Actually dump course
6739:
6740: =item group_import()
6741:
6742: Imports the given (name, url) resources into the course
6743: coursenum, coursedom, and folder must precede the list
6744:
6745: =item breadcrumbs()
6746:
6747: =item log_docs()
6748:
6749: =item docs_change_log()
6750:
6751: =item update_paste_buffer()
6752:
6753: =item print_paste_buffer()
6754:
6755: =item do_paste_from_buffer()
6756:
1.538 raeburn 6757: =item do_buffer_empty()
6758:
6759: =item clear_from_buffer()
6760:
1.492 raeburn 6761: =item get_newmap_url()
6762:
6763: =item dbcopy()
6764:
6765: =item uniqueness_check()
6766:
6767: =item contained_map_check()
6768:
6769: =item url_paste_fixups()
6770:
6771: =item apply_fixups()
6772:
6773: =item copy_dependencies()
6774:
1.329 droeschl 6775: =item update_parameter()
6776:
6777: =item handle_edit_cmd()
6778:
6779: =item editor()
6780:
6781: =item process_file_upload()
6782:
6783: =item process_secondary_uploads()
6784:
6785: =item is_supplemental_title()
6786:
6787: =item entryline()
6788:
6789: =item tiehash()
6790:
6791: =item untiehash()
6792:
6793: =item checkonthis()
6794:
6795: check on this
6796:
6797: =item verifycontent()
6798:
6799: Verify Content
6800:
6801: =item devalidateversioncache() & checkversions()
6802:
6803: Check Versions
6804:
6805: =item mark_hash_old()
6806:
6807: =item is_hash_old()
6808:
6809: =item changewarning()
6810:
6811: =item init_breadcrumbs()
6812:
6813: Breadcrumbs for special functions
6814:
1.484 raeburn 6815: =item create_list_elements()
6816:
6817: =item create_form_ul()
6818:
6819: =item startContentScreen()
6820:
6821: =item endContentScreen()
6822:
6823: =item supplemental_base()
6824:
6825: =item embedded_form_elems()
6826:
6827: =item embedded_destination()
6828:
6829: =item return_to_editor()
6830:
6831: =item decompression_info()
6832:
6833: =item decompression_phase_one()
6834:
6835: =item decompression_phase_two()
6836:
6837: =item remove_archive()
6838:
6839: =item generate_admin_menu()
6840:
6841: =item generate_edit_table()
6842:
6843: =item editing_js()
6844:
6845: =item history_tab_js()
6846:
6847: =item inject_data_js()
6848:
6849: =item dump_switchserver_js()
6850:
1.485 raeburn 6851: =item resize_scrollbox_js()
1.484 raeburn 6852:
6853: =item makedocslogform()
6854:
1.485 raeburn 6855: =item makesimpleeditform()
6856:
1.329 droeschl 6857: =back
6858:
6859: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>