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