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