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