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