Annotation of loncom/interface/londocs.pm, revision 1.518
1.329 droeschl 1: # The LearningOnline Network
2: # Documents
3: #
1.518 ! raeburn 4: # $Id: londocs.pm,v 1.517 2012/12/02 18:54:40 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: }
1.517 raeburn 2145: my ($renamelink,%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.517 raeburn 2242: my ($copylink,$cutlink,$removelink);
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.518 ! raeburn 2282: unless ($isexternal) {
! 2283: $renamelink=(<<ENDREN);
1.507 raeburn 2284: <a href='javascript:changename("$esc_path","$index","$renametitle","$container","$symb");' class="LC_docs_rename">$lt{'rn'}</a>
2285: ENDREN
1.518 ! raeburn 2286: }
1.478 raeburn 2287: $form_start = '
2288: <form action="/adm/coursedocs" method="post">
2289: ';
2290: $form_common=(<<END);
1.329 droeschl 2291: <input type="hidden" name="${type}path" value="$path" />
2292: <input type="hidden" name="${type}symb" value="$symb" />
2293: <input type="hidden" name="setparms" value="$orderidx" />
2294: <input type="hidden" name="changeparms" value="0" />
2295: END
2296: $form_end = '</form>';
2297: $line.=(<<END);
2298: <td>
1.379 bisitz 2299: <div class="LC_docs_entry_move">
1.499 raeburn 2300: <a href='/adm/coursedocs?cmd=up_$index&${type}path=$esc_path&${type}symb=$symb'>
1.501 raeburn 2301: <img src="${iconpath}move_up.gif" alt="$lt{'up'}" class="LC_icon" />
1.379 bisitz 2302: </a>
2303: </div>
2304: <div class="LC_docs_entry_move">
1.499 raeburn 2305: <a href='/adm/coursedocs?cmd=down_$index&${type}path=$esc_path&${type}symb=$symb'>
1.501 raeburn 2306: <img src="${iconpath}move_down.gif" alt="$lt{'dw'}" class="LC_icon" />
1.379 bisitz 2307: </a>
2308: </div>
1.329 droeschl 2309: </td>
2310: <td>
2311: $form_start
1.478 raeburn 2312: $form_common
1.329 droeschl 2313: $selectbox
2314: $form_end
2315: </td>
1.507 raeburn 2316: <td class="LC_docs_entry_commands"><span class="LC_nobreak">
1.497 raeburn 2317: $removelink
1.329 droeschl 2318: $cutlink
2319: $copylink
1.507 raeburn 2320: </span>
1.329 droeschl 2321: </td>
2322: END
2323:
2324: }
2325: # Figure out what kind of a resource this is
2326: my ($extension)=($url=~/\.(\w+)$/);
2327: my $uploaded=($url=~/^\/*uploaded\//);
2328: my $icon=&Apache::loncommon::icon($url);
2329: my $isfolder=0;
2330: my $ispage=0;
2331: my $folderarg;
2332: my $pagearg;
2333: my $pagefile;
2334: if ($uploaded) {
1.472 raeburn 2335: if (($extension eq 'sequence') || ($extension eq 'page')) {
2336: $url=~/\Q$coursenum\E\/([\/\w]+)\.\Q$extension\E$/;
2337: my $containerarg = $1;
2338: if ($extension eq 'sequence') {
2339: $icon=$iconpath.'navmap.folder.closed.gif';
2340: $folderarg=$containerarg;
2341: $isfolder=1;
2342: } else {
2343: $icon=$iconpath.'page.gif';
2344: $pagearg=$containerarg;
2345: $ispage=1;
2346: }
2347: if ($allowed) {
2348: $url='/adm/coursedocs?';
2349: } else {
2350: $url='/adm/supplemental?';
2351: }
1.329 droeschl 2352: } else {
2353: &Apache::lonnet::allowuploaded('/adm/coursedoc',$url);
2354: }
2355: }
1.364 bisitz 2356:
1.518 ! raeburn 2357: my ($editlink,$extresform);
1.329 droeschl 2358: my $orig_url = $url;
1.340 raeburn 2359: $orig_url=~s{http(:|:)//https(:|:)//}{https$2//};
1.510 raeburn 2360: $url=~s{^http(|s)(:|:)//}{/adm/wrapper/ext/};
1.501 raeburn 2361: if (!$supplementalflag && $residx && $symb) {
2362: if ($container eq 'page') {
2363: $url=&Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
2364: $url.=(($url=~/\?/)?'&':'?').'symb='.&escape($symb);
2365: }
2366: if ((!$isfolder) && (!$ispage)) {
2367: (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
2368: $url=&Apache::lonnet::clutter($url);
2369: if ($url=~/^\/*uploaded\//) {
2370: $url=~/\.(\w+)$/;
2371: my $embstyle=&Apache::loncommon::fileembstyle($1);
2372: if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
2373: $url='/adm/wrapper'.$url;
2374: } elsif ($embstyle eq 'ssi') {
2375: #do nothing with these
2376: } elsif ($url!~/\.(sequence|page)$/) {
2377: $url='/adm/coursedocs/showdoc'.$url;
2378: }
2379: } elsif ($url=~m|^/ext/|) {
2380: $url='/adm/wrapper'.$url;
1.329 droeschl 2381: }
1.501 raeburn 2382: if (&Apache::lonnet::symbverify($symb,$url)) {
2383: $url.=(($url=~/\?/)?'&':'?').'symb='.&escape($symb);
2384: } else {
2385: $url='';
2386: }
1.329 droeschl 2387: }
2388: }
1.478 raeburn 2389: my ($rand_pick_text,$rand_order_text);
1.329 droeschl 2390: if ($isfolder || $extension eq 'sequence') {
2391: my $foldername=&escape($foldertitle);
2392: my $folderpath=$env{'form.folderpath'};
2393: if ($folderpath) { $folderpath.='&' };
1.510 raeburn 2394: if (!$allowed && $supplementalflag) {
2395: $folderpath.=$folderarg.'&'.$foldername;
2396: $url.='folderpath='.&escape($folderpath);
2397: } else {
1.344 bisitz 2398: # Append randompick number, hidden, and encrypted with ":" to foldername,
1.329 droeschl 2399: # so it gets transferred between levels
1.510 raeburn 2400: $folderpath.=$folderarg.'&'.$foldername.
2401: ':'.(&LONCAPA::map::getparameter($orderidx,
1.329 droeschl 2402: 'parameter_randompick'))[0]
2403: .':'.((&LONCAPA::map::getparameter($orderidx,
2404: 'parameter_hiddenresource'))[0]=~/^yes$/i)
2405: .':'.((&LONCAPA::map::getparameter($orderidx,
2406: 'parameter_encrypturl'))[0]=~/^yes$/i)
2407: .':'.((&LONCAPA::map::getparameter($orderidx,
2408: 'parameter_randomorder'))[0]=~/^yes$/i);
1.510 raeburn 2409: $url.='folderpath='.&escape($folderpath);
2410: my $rpicknum = (&LONCAPA::map::getparameter($orderidx,
2411: 'parameter_randompick'))[0];
2412: my $rpckchk;
2413: if ($rpicknum) {
2414: $rpckchk = ' checked="checked"';
2415: }
2416: my $formname = 'edit_rpick_'.$orderidx;
2417: $rand_pick_text =
1.478 raeburn 2418: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
2419: $form_common."\n".
2420: '<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 2421: if ($rpicknum ne '') {
2422: $rand_pick_text .= ': <a href="javascript:updatePick('."document.$formname,'$orderidx','link'".')">'.$rpicknum.'</a>';
2423: }
2424: $rand_pick_text .= '</span></form>';
2425: my $ro_set=
2426: ((&LONCAPA::map::getparameter($orderidx,'parameter_randomorder'))[0]=~/^yes$/i?' checked="checked"':'');
2427: $rand_order_text =
1.478 raeburn 2428: $form_start.
2429: $form_common.'
2430: <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 2431: }
1.509 raeburn 2432: } elsif ($supplementalflag && !$allowed) {
1.510 raeburn 2433: $url .= ($url =~ /\?/) ? '&':'?';
1.509 raeburn 2434: $url .= 'folderpath='.&HTML::Entities::encode($esc_path,'<>&"');
1.510 raeburn 2435: if ($title) {
2436: $url .= '&title='.&HTML::Entities::encode($renametitle,'<>&"');
2437: }
1.511 raeburn 2438: if ($isexternal && $orderidx) {
1.510 raeburn 2439: $url .= '&idx='.$orderidx;
2440: }
1.329 droeschl 2441: }
2442: if ($ispage) {
2443: my $pagename=&escape($pagetitle);
2444: my $pagepath;
2445: my $folderpath=$env{'form.folderpath'};
2446: if ($folderpath) { $pagepath = $folderpath.'&' };
2447: $pagepath.=$pagearg.'&'.$pagename;
2448: $url.='pagepath='.&escape($pagepath).
1.499 raeburn 2449: '&pagesymb='.&escape($symb);
1.329 droeschl 2450: }
1.501 raeburn 2451: if ($allowed) {
2452: my $fileloc =
2453: &Apache::lonnet::declutter(&Apache::lonnet::filelocation('',$orig_url));
1.510 raeburn 2454: if ($isexternal) {
1.518 ! raeburn 2455: ($editlink,$extresform) =
1.510 raeburn 2456: &Apache::lonextresedit::extedit_form(0,$residx,$orig_url,$title,$pathitem);
1.511 raeburn 2457: } elsif (!$isfolder && !$ispage) {
1.503 raeburn 2458: my ($cfile,$home,$switchserver,$forceedit,$forceview) =
2459: &Apache::lonnet::can_edit_resource($fileloc,$coursenum,$coursedom,$orig_url);
1.511 raeburn 2460: if (($cfile ne '') && ($symb ne '' || $supplementalflag)) {
1.501 raeburn 2461: my $jscall =
2462: &Apache::lonhtmlcommon::jump_to_editres($cfile,$home,
2463: $switchserver,
1.503 raeburn 2464: $forceedit,
1.511 raeburn 2465: undef,$symb,
2466: &escape($env{'form.folderpath'}),
2467: $renametitle);
1.501 raeburn 2468: if ($jscall) {
1.518 ! raeburn 2469: $editlink = '<a class="LC_docs_ext_edit" href="javascript:'.
! 2470: $jscall.'" >'.&mt('Edit').'</a> '."\n";
1.501 raeburn 2471: }
2472: }
2473: }
1.329 droeschl 2474: }
1.408 raeburn 2475: my $reinit;
2476: if ($crstype eq 'Community') {
2477: $reinit = &mt('(re-initialize community to access)');
2478: } else {
2479: $reinit = &mt('(re-initialize course to access)');
2480: }
1.517 raeburn 2481: $line.='<td class="LC_docs_entry_commands" align="right" valign="top"><span class="LC_nobreak">'.$editlink.$renamelink;
1.472 raeburn 2482: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.469 www 2483: $line.='<a href="'.$url.'"><img src="'.$icon.'" alt="" class="LC_icon" /></a>';
2484: } elsif ($url) {
1.484 raeburn 2485: $line.=&Apache::loncommon::modal_link($url.(($url=~/\?/)?'&':'?').'inhibitmenu=yes',
1.470 raeburn 2486: '<img src="'.$icon.'" alt="" class="LC_icon" />',600,500);
1.469 www 2487: } else {
2488: $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
2489: }
1.517 raeburn 2490: $line.='</span></td><td width="80%">';
1.472 raeburn 2491: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.469 www 2492: $line.='<a href="'.$url.'">'.$title.'</a>';
2493: } elsif ($url) {
1.484 raeburn 2494: $line.=&Apache::loncommon::modal_link($url.(($url=~/\?/)?'&':'?').'inhibitmenu=yes',
1.470 raeburn 2495: $title,600,500);
1.469 www 2496: } else {
2497: $line.=$title.' <span class="LC_docs_reinit_warn">'.$reinit.'</span>';
2498: }
1.518 ! raeburn 2499: $line.="$extresform</td>";
1.478 raeburn 2500: $rand_pick_text = ' ' if ($rand_pick_text eq '');
2501: $rand_order_text = ' ' if ($rand_order_text eq '');
1.329 droeschl 2502: if (($allowed) && ($folder!~/^supplemental/)) {
2503: my %lt=&Apache::lonlocal::texthash(
2504: 'hd' => 'Hidden',
2505: 'ec' => 'URL hidden');
2506: my $enctext=
1.358 bisitz 2507: ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i?' checked="checked"':'');
1.329 droeschl 2508: my $hidtext=
1.358 bisitz 2509: ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i?' checked="checked"':'');
1.329 droeschl 2510: $line.=(<<ENDPARMS);
2511: <td class="LC_docs_entry_parameter">
2512: $form_start
1.478 raeburn 2513: $form_common
1.369 bisitz 2514: <label><input type="checkbox" name="hiddenresource_$orderidx" onclick="this.form.changeparms.value='hiddenresource';this.form.submit()" $hidtext /> $lt{'hd'}</label>
1.329 droeschl 2515: $form_end
1.458 raeburn 2516: <br />
1.329 droeschl 2517: $form_start
1.478 raeburn 2518: $form_common
1.369 bisitz 2519: <label><input type="checkbox" name="encrypturl_$orderidx" onclick="this.form.changeparms.value='encrypturl';this.form.submit()" $enctext /> $lt{'ec'}</label>
1.329 droeschl 2520: $form_end
2521: </td>
1.478 raeburn 2522: <td class="LC_docs_entry_parameter">$rand_pick_text<br />
2523: $rand_order_text</td>
1.329 droeschl 2524: ENDPARMS
2525: }
1.379 bisitz 2526: $line.=&Apache::loncommon::end_data_table_row();
1.329 droeschl 2527: return $line;
2528: }
2529:
1.504 raeburn 2530: sub newmap_suffix {
2531: my ($area,$container,$coursedom,$coursenum) = @_;
2532: my ($prefix,$idtype,$errtext,$locknotfreed);
2533: $prefix = 'docs';
2534: if ($area eq 'supplemental') {
2535: $prefix = 'supp';
2536: }
2537: $prefix .= $container;
2538: $idtype = 'concat';
2539: my ($suffix,$freedlock,$error) =
2540: &Apache::lonnet::get_timebased_id($prefix,'num','uploadedmaps',
2541: $coursedom,$coursenum);
2542: if (!$suffix) {
2543: $errtext = &mt('Failed to acquire a unique timestamp-based suffix for the new folder/page.');
2544: if ($error) {
2545: $errtext .= '<br />'.$error;
2546: }
2547: }
2548: if ($freedlock ne 'ok') {
2549: $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>';
2550: }
2551: return ($suffix,$errtext,$locknotfreed);
2552: }
2553:
1.329 droeschl 2554: =pod
2555:
2556: =item tiehash()
2557:
2558: tie the hash
2559:
2560: =cut
2561:
2562: sub tiehash {
2563: my ($mode)=@_;
2564: $hashtied=0;
2565: if ($env{'request.course.fn'}) {
2566: if ($mode eq 'write') {
2567: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
2568: &GDBM_WRCREAT(),0640)) {
2569: $hashtied=2;
2570: }
2571: } else {
2572: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
2573: &GDBM_READER(),0640)) {
2574: $hashtied=1;
2575: }
2576: }
1.364 bisitz 2577: }
1.329 droeschl 2578: }
2579:
2580: sub untiehash {
2581: if ($hashtied) { untie %hash; }
2582: $hashtied=0;
2583: return OK;
2584: }
2585:
2586:
2587:
2588:
2589: sub checkonthis {
2590: my ($r,$url,$level,$title)=@_;
2591: $url=&unescape($url);
2592: $alreadyseen{$url}=1;
2593: $r->rflush();
2594: if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
2595: $r->print("\n<br />");
2596: if ($level==0) {
2597: $r->print("<br />");
2598: }
2599: for (my $i=0;$i<=$level*5;$i++) {
2600: $r->print(' ');
2601: }
2602: $r->print('<a href="'.$url.'" target="cat">'.
2603: ($title?$title:$url).'</a> ');
2604: if ($url=~/^\/res\//) {
2605: my $result=&Apache::lonnet::repcopy(
2606: &Apache::lonnet::filelocation('',$url));
2607: if ($result eq 'ok') {
2608: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
2609: $r->rflush();
2610: &Apache::lonnet::countacc($url);
2611: $url=~/\.(\w+)$/;
2612: if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
2613: $r->print('<br />');
2614: $r->rflush();
2615: for (my $i=0;$i<=$level*5;$i++) {
2616: $r->print(' ');
2617: }
2618: $r->print('- '.&mt('Rendering:').' ');
2619: my ($errorcount,$warningcount)=split(/:/,
2620: &Apache::lonnet::ssi_body($url,
2621: ('grade_target'=>'web',
2622: 'return_only_error_and_warning_counts' => 1)));
2623: if (($errorcount) ||
2624: ($warningcount)) {
2625: if ($errorcount) {
1.369 bisitz 2626: $r->print('<img src="/adm/lonMisc/bomb.gif" alt="'.&mt('bomb').'" /><span class="LC_error">'.
1.329 droeschl 2627: &mt('[quant,_1,error]',$errorcount).'</span>');
2628: }
2629: if ($warningcount) {
2630: $r->print('<span class="LC_warning">'.
2631: &mt('[quant,_1,warning]',$warningcount).'</span>');
2632: }
2633: } else {
2634: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
2635: }
2636: $r->rflush();
2637: }
2638: my $dependencies=
2639: &Apache::lonnet::metadata($url,'dependencies');
2640: foreach my $dep (split(/\,/,$dependencies)) {
2641: if (($dep=~/^\/res\//) && (!$alreadyseen{$dep})) {
2642: &checkonthis($r,$dep,$level+1);
2643: }
2644: }
2645: } elsif ($result eq 'unavailable') {
2646: $r->print('<span class="LC_error">'.&mt('connection down').'</span>');
2647: } elsif ($result eq 'not_found') {
2648: unless ($url=~/\$/) {
2649: $r->print('<span class="LC_error">'.&mt('not found').'</b></span>');
2650: } else {
1.366 bisitz 2651: $r->print('<span class="LC_error">'.&mt('unable to verify variable URL').'</span>');
1.329 droeschl 2652: }
2653: } else {
2654: $r->print('<span class="LC_error">'.&mt('access denied').'</span>');
2655: }
2656: }
2657: }
2658: }
2659:
2660:
2661:
2662: =pod
2663:
2664: =item list_symbs()
2665:
1.485 raeburn 2666: List Content Identifiers
1.329 droeschl 2667:
2668: =cut
2669:
2670: sub list_symbs {
2671: my ($r) = @_;
2672:
1.408 raeburn 2673: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 2674: $r->print(&Apache::loncommon::start_page('List of Content Identifiers'));
2675: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Identifiers'));
2676: $r->print(&startContentScreen('tools'));
1.329 droeschl 2677: my $navmap = Apache::lonnavmaps::navmap->new();
2678: if (!defined($navmap)) {
2679: $r->print('<h2>'.&mt('Retrieval of List Failed').'</h2>'.
2680: '<div class="LC_error">'.
2681: &mt('Unable to retrieve information about course contents').
2682: '</div>');
1.408 raeburn 2683: &Apache::lonnet::logthis('Symb list failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
1.329 droeschl 2684: } else {
1.484 raeburn 2685: $r->print('<h4 class="LC_info">'.&mt("$crstype Content Identifiers").'</h4>'.
2686: &Apache::loncommon::start_data_table().
2687: &Apache::loncommon::start_data_table_header_row().
2688: '<th>'.&mt('Title').'</th><th>'.&mt('Identifier').'</th>'.
2689: &Apache::loncommon::end_data_table_header_row()."\n");
2690: my $count;
1.329 droeschl 2691: foreach my $res ($navmap->retrieveResources()) {
1.484 raeburn 2692: $r->print(&Apache::loncommon::start_data_table_row().
2693: '<td>'.$res->compTitle().'</td>'.
2694: '<td>'.$res->symb().'</td>'.
2695: &Apache::loncommon::start_data_table_row());
2696: $count ++;
2697: }
2698: if (!$count) {
2699: $r->print(&Apache::loncommon::start_data_table_row().
2700: '<td colspan="2">'.&mt("$crstype is empty").'</td>'.
2701: &Apache::loncommon::end_data_table_row());
1.329 droeschl 2702: }
1.484 raeburn 2703: $r->print(&Apache::loncommon::end_data_table());
1.329 droeschl 2704: }
2705: }
2706:
2707:
2708: sub verifycontent {
2709: my ($r) = @_;
1.408 raeburn 2710: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 2711: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Documents'));
2712: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Documents'));
2713: $r->print(&startContentScreen('tools'));
2714: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
1.329 droeschl 2715: $hashtied=0;
2716: undef %alreadyseen;
2717: %alreadyseen=();
2718: &tiehash();
1.484 raeburn 2719:
1.329 droeschl 2720: foreach my $key (keys(%hash)) {
2721: if ($hash{$key}=~/\.(page|sequence)$/) {
2722: if (($key=~/^src_/) && ($alreadyseen{&unescape($hash{$key})})) {
2723: $r->print('<hr /><span class="LC_error">'.
1.419 bisitz 2724: &mt('The following sequence or page is included more than once in your '.$crstype.':').' '.
1.329 droeschl 2725: &unescape($hash{$key}).'</span><br />'.
1.419 bisitz 2726: &mt('Note that grading records for problems included in this sequence or folder will overlap.').'<hr />');
1.329 droeschl 2727: }
2728: }
2729: if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) {
2730: &checkonthis($r,$hash{$key},0,$hash{'title_'.$1});
2731: }
2732: }
2733: &untiehash();
1.442 www 2734: $r->print('<p class="LC_success">'.&mt('Done').'</p>');
1.329 droeschl 2735: }
2736:
2737:
2738: sub devalidateversioncache {
2739: my $src=shift;
2740: &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
2741: &Apache::lonnet::clutter($src));
2742: }
2743:
2744: sub checkversions {
2745: my ($r) = @_;
1.408 raeburn 2746: my $crstype = &Apache::loncommon::course_type();
2747: $r->print(&Apache::loncommon::start_page("Check $crstype Document Versions"));
2748: $r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $crstype Document Versions"));
1.484 raeburn 2749: $r->print(&startContentScreen('tools'));
1.442 www 2750:
1.329 droeschl 2751: my $header='';
2752: my $startsel='';
2753: my $monthsel='';
2754: my $weeksel='';
2755: my $daysel='';
2756: my $allsel='';
2757: my %changes=();
2758: my $starttime=0;
2759: my $haschanged=0;
2760: my %setversions=&Apache::lonnet::dump('resourceversions',
2761: $env{'course.'.$env{'request.course.id'}.'.domain'},
2762: $env{'course.'.$env{'request.course.id'}.'.num'});
2763:
2764: $hashtied=0;
2765: &tiehash();
2766: my %newsetversions=();
2767: if ($env{'form.setmostrecent'}) {
2768: $haschanged=1;
2769: foreach my $key (keys(%hash)) {
2770: if ($key=~/^ids\_(\/res\/.+)$/) {
2771: $newsetversions{$1}='mostrecent';
2772: &devalidateversioncache($1);
2773: }
2774: }
2775: } elsif ($env{'form.setcurrent'}) {
2776: $haschanged=1;
2777: foreach my $key (keys(%hash)) {
2778: if ($key=~/^ids\_(\/res\/.+)$/) {
2779: my $getvers=&Apache::lonnet::getversion($1);
2780: if ($getvers>0) {
2781: $newsetversions{$1}=$getvers;
2782: &devalidateversioncache($1);
2783: }
2784: }
2785: }
2786: } elsif ($env{'form.setversions'}) {
2787: $haschanged=1;
2788: foreach my $key (keys(%env)) {
2789: if ($key=~/^form\.set_version_(.+)$/) {
2790: my $src=$1;
2791: if (($env{$key}) && ($env{$key} ne $setversions{$src})) {
2792: $newsetversions{$src}=$env{$key};
2793: &devalidateversioncache($src);
2794: }
2795: }
2796: }
2797: }
2798: if ($haschanged) {
2799: if (&Apache::lonnet::put('resourceversions',\%newsetversions,
2800: $env{'course.'.$env{'request.course.id'}.'.domain'},
1.344 bisitz 2801: $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
1.479 golterma 2802: $r->print(&Apache::loncommon::confirmwrapper(
2803: &Apache::lonhtmlcommon::confirm_success(&mt('Your Version Settings have been Saved'))));
1.329 droeschl 2804: } else {
1.479 golterma 2805: $r->print(&Apache::loncommon::confirmwrapper(
2806: &Apache::lonhtmlcommon::confirm_success(&mt('An Error Occured while Attempting to Save your Version Settings'),1)));
1.329 droeschl 2807: }
2808: &mark_hash_old();
2809: }
2810: &changewarning($r,'');
2811: if ($env{'form.timerange'} eq 'all') {
2812: # show all documents
1.408 raeburn 2813: $header=&mt('All Documents in '.$crstype);
1.329 droeschl 2814: $allsel=1;
2815: foreach my $key (keys(%hash)) {
2816: if ($key=~/^ids\_(\/res\/.+)$/) {
2817: my $src=$1;
2818: $changes{$src}=1;
2819: }
2820: }
2821: } else {
2822: # show documents which changed
2823: %changes=&Apache::lonnet::dump
2824: ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
2825: $env{'course.'.$env{'request.course.id'}.'.num'});
2826: my $firstkey=(keys(%changes))[0];
2827: unless ($firstkey=~/^error\:/) {
2828: unless ($env{'form.timerange'}) {
2829: $env{'form.timerange'}=604800;
2830: }
2831: my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
2832: .&mt('seconds');
2833: if ($env{'form.timerange'}==-1) {
2834: $seltext='since start of course';
2835: $startsel='selected';
2836: $env{'form.timerange'}=time;
2837: }
2838: $starttime=time-$env{'form.timerange'};
2839: if ($env{'form.timerange'}==2592000) {
2840: $seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
2841: $monthsel='selected';
2842: } elsif ($env{'form.timerange'}==604800) {
2843: $seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
2844: $weeksel='selected';
2845: } elsif ($env{'form.timerange'}==86400) {
2846: $seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
2847: $daysel='selected';
2848: }
2849: $header=&mt('Content changed').' '.$seltext;
2850: } else {
2851: $header=&mt('No content modifications yet.');
2852: }
2853: }
2854: %setversions=&Apache::lonnet::dump('resourceversions',
2855: $env{'course.'.$env{'request.course.id'}.'.domain'},
2856: $env{'course.'.$env{'request.course.id'}.'.num'});
2857: my %lt=&Apache::lonlocal::texthash
1.408 raeburn 2858: ('st' => 'Version changes since start of '.$crstype,
1.329 droeschl 2859: 'lm' => 'Version changes since last Month',
2860: 'lw' => 'Version changes since last Week',
2861: 'sy' => 'Version changes since Yesterday',
2862: 'al' => 'All Resources (possibly large output)',
1.484 raeburn 2863: 'cd' => 'Change display',
1.329 droeschl 2864: 'sd' => 'Display',
2865: 'fi' => 'File',
2866: 'md' => 'Modification Date',
2867: 'mr' => 'Most recently published Version',
1.408 raeburn 2868: 've' => 'Version used in '.$crstype,
2869: 'vu' => 'Set Version to be used in '.$crstype,
2870: 'sv' => 'Set Versions to be used in '.$crstype.' according to Selections below',
1.329 droeschl 2871: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
2872: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
1.479 golterma 2873: 'di' => 'Differences',
1.484 raeburn 2874: 'save' => 'Save changes',
2875: 'vers' => 'Version choice(s) for specific resources',
1.479 golterma 2876: 'act' => 'Actions');
1.329 droeschl 2877: $r->print(<<ENDHEADERS);
1.484 raeburn 2878: <h4 class="LC_info">$header</h4>
1.329 droeschl 2879: <form action="/adm/coursedocs" method="post">
2880: <input type="hidden" name="versions" value="1" />
1.484 raeburn 2881: <div class="LC_left_float">
1.479 golterma 2882: <fieldset>
1.484 raeburn 2883: <legend>$lt{'cd'}</legend>
1.329 droeschl 2884: <select name="timerange">
2885: <option value='all' $allsel>$lt{'al'}</option>
2886: <option value="-1" $startsel>$lt{'st'}</option>
2887: <option value="2592000" $monthsel>$lt{'lm'}</option>
2888: <option value="604800" $weeksel>$lt{'lw'}</option>
2889: <option value="86400" $daysel>$lt{'sy'}</option>
2890: </select>
2891: <input type="submit" name="display" value="$lt{'sd'}" />
1.484 raeburn 2892: </fieldset>
2893: </div>
2894: <div class="LC_left_float">
2895: <fieldset>
2896: <legend>$lt{'act'}</legend>
2897: $lt{'sm'}: <input type="submit" name="setmostrecent" value="Go" /><br />
2898: $lt{'sc'}: <input type="submit" name="setcurrent" value="Go" />
2899: </fieldset>
2900: </div>
2901: <br clear="all" />
2902: <hr />
2903: <h4>$lt{'vers'}</h4>
1.479 golterma 2904: <input type="submit" name="setversions" value="$lt{'save'}" />
1.329 droeschl 2905: <table border="0">
2906: ENDHEADERS
1.479 golterma 2907: #number of columns for version history
2908: my $num_ver_col = 1;
2909: $r->print(
2910: &Apache::loncommon::start_data_table().
2911: &Apache::loncommon::start_data_table_header_row().
2912: '<th>'.&mt('Resources').'</th>'.
2913: "<th>$lt{'mr'}</th>".
2914: "<th>$lt{'ve'}</th>".
2915: "<th>$lt{'vu'}</th>".
2916: '<th colspan="'.$num_ver_col.'">'.&mt('History').'</th>'.
2917: '</b>');
1.329 droeschl 2918: foreach my $key (sort(keys(%changes))) {
1.496 golterma 2919: #excludes not versionable problems from resource version history:
2920: if ($changes{$key}>$starttime && $key !~ /^\/res\/lib\/templates/) {
1.329 droeschl 2921: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
2922: my $currentversion=&Apache::lonnet::getversion($key);
2923: if ($currentversion<0) {
1.479 golterma 2924: $currentversion='<span class="LC_error">'.&mt('Could not be determined.').'</span>';
1.329 droeschl 2925: }
2926: my $linkurl=&Apache::lonnet::clutter($key);
1.479 golterma 2927: $r->print(
2928: &Apache::loncommon::end_data_table_header_row().
2929: &Apache::loncommon::start_data_table_row().
2930: '<td><b>'.&Apache::lonnet::gettitle($linkurl).'</b><br>'.
2931: '<a href="'.$linkurl.'" target="cat">'.$linkurl.'</a></td>'.
2932: '<td align="right">'.$currentversion.'<span class="LC_fontsize_medium"><br>('.
2933: &Apache::lonlocal::locallocaltime(&Apache::lonnet::metadata($root.'.'.$extension,'lastrevisiondate')).')</span></td>'.
2934: '<td align="right">');
1.329 droeschl 2935: # Used in course
2936: my $usedversion=$hash{'version_'.$linkurl};
2937: if (($usedversion) && ($usedversion ne 'mostrecent')) {
1.479 golterma 2938: if($usedversion != $currentversion){
2939: $r->print('<span class="LC_warning">'.$usedversion.'</span>');
2940: }else{
2941: $r->print($usedversion);
2942: }
1.329 droeschl 2943: } else {
2944: $r->print($currentversion);
2945: }
1.479 golterma 2946: $r->print('</td><td title="'.$lt{'vu'}.'">');
1.329 droeschl 2947: # Set version
2948: $r->print(&Apache::loncommon::select_form($setversions{$linkurl},
2949: 'set_version_'.$linkurl,
1.428 raeburn 2950: {'select_form_order' =>
1.329 droeschl 2951: ['',1..$currentversion,'mostrecent'],
2952: '' => '',
1.411 bisitz 2953: 'mostrecent' => &mt('most recent'),
1.428 raeburn 2954: map {$_,$_} (1..$currentversion)}));
1.329 droeschl 2955: my $lastold=1;
2956: for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
2957: my $url=$root.'.'.$prevvers.'.'.$extension;
2958: if (&Apache::lonnet::metadata($url,'lastrevisiondate')<
2959: $starttime) {
2960: $lastold=$prevvers;
2961: }
2962: }
1.364 bisitz 2963: #
1.329 droeschl 2964: # Code to figure out how many version entries should go in
2965: # each of the four columns
2966: my $entries_per_col = 0;
2967: my $num_entries = ($currentversion-$lastold);
1.479 golterma 2968: if ($num_entries % $num_ver_col == 0) {
2969: $entries_per_col = $num_entries/$num_ver_col;
1.329 droeschl 2970: } else {
1.479 golterma 2971: $entries_per_col = $num_entries/$num_ver_col + 1;
1.329 droeschl 2972: }
2973: my $entries_count = 0;
1.479 golterma 2974: $r->print('<td valign="top"><span class="LC_fontsize_medium">');
1.329 droeschl 2975: my $cols_output = 1;
2976: for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
2977: my $url=$root.'.'.$prevvers.'.'.$extension;
2978: $r->print('<span class="LC_nobreak"><a href="'.&Apache::lonnet::clutter($url).
2979: '">'.&mt('Version').' '.$prevvers.'</a> ('.
2980: &Apache::lonlocal::locallocaltime(
2981: &Apache::lonnet::metadata($url,
2982: 'lastrevisiondate')
2983: ).
2984: ')');
2985: if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
2986: $r->print(' <a href="/adm/diff?filename='.
2987: &Apache::lonnet::clutter($root.'.'.$extension).
2988: '&versionone='.$prevvers.
1.462 raeburn 2989: '" target="diffs">'.&mt('Diffs').'</a>');
1.329 droeschl 2990: }
2991: $r->print('</span><br />');
2992: if (++$entries_count % $entries_per_col == 0) {
1.479 golterma 2993: $r->print('</span></td>');
2994: if ($cols_output != $num_ver_col) {
2995: $r->print('<td valign="top"><span class="LC_fontsize_medium">');
1.329 droeschl 2996: $cols_output++;
2997: }
2998: }
2999: }
1.479 golterma 3000: while($cols_output++ < $num_ver_col) {
3001: $r->print('</span></td><td>');
1.329 droeschl 3002: }
3003: }
3004: }
1.479 golterma 3005: $r->print('</td>'.&Apache::loncommon::end_data_table_row().
3006: &Apache::loncommon::end_data_table().
3007: '<input type="submit" name="setversions" value="'.$lt{'save'}.'" />');
1.329 droeschl 3008:
3009: &untiehash();
3010: }
3011:
3012: sub mark_hash_old {
3013: my $retie_hash=0;
3014: if ($hashtied) {
3015: $retie_hash=1;
3016: &untiehash();
3017: }
3018: &tiehash('write');
3019: $hash{'old'}=1;
3020: &untiehash();
3021: if ($retie_hash) { &tiehash(); }
3022: }
3023:
3024: sub is_hash_old {
3025: my $untie_hash=0;
3026: if (!$hashtied) {
3027: $untie_hash=1;
3028: &tiehash();
3029: }
3030: my $return=$hash{'old'};
3031: if ($untie_hash) { &untiehash(); }
3032: return $return;
3033: }
3034:
3035: sub changewarning {
3036: my ($r,$postexec,$message,$url)=@_;
3037: if (!&is_hash_old()) { return; }
3038: my $pathvar='folderpath';
3039: my $path=&escape($env{'form.folderpath'});
3040: if (!defined($url)) {
3041: if (defined($env{'form.pagepath'})) {
3042: $pathvar='pagepath';
3043: $path=&escape($env{'form.pagepath'});
3044: $path.='&pagesymb='.&escape($env{'form.pagesymb'});
3045: }
3046: $url='/adm/coursedocs?'.$pathvar.'='.$path;
3047: }
3048: my $course_type = &Apache::loncommon::course_type();
3049: if (!defined($message)) {
3050: $message='Changes will become active for your current session after [_1], or the next time you log in.';
3051: }
3052: $r->print("\n\n".
1.372 bisitz 3053: '<script type="text/javascript">'."\n".
3054: '// <![CDATA['."\n".
3055: 'function reinit(tf) { tf.submit();'.$postexec.' }'."\n".
3056: '// ]]>'."\n".
1.369 bisitz 3057: '</script>'."\n".
1.375 tempelho 3058: '<form name="reinitform" method="post" action="/adm/roles" target="loncapaclient">'.
1.329 droeschl 3059: '<input type="hidden" name="orgurl" value="'.$url.
1.372 bisitz 3060: '" /><input type="hidden" name="selectrole" value="1" /><p class="LC_warning">'.
1.329 droeschl 3061: &mt($message,' <input type="hidden" name="'.
3062: $env{'request.role'}.'" value="1" /><input type="button" value="'.
1.369 bisitz 3063: &mt('re-initializing '.$course_type).'" onclick="reinit(this.form)" />').
1.372 bisitz 3064: $help{'Caching'}.'</p></form>'."\n\n");
1.329 droeschl 3065: }
3066:
3067:
3068: sub init_breadcrumbs {
3069: my ($form,$text)=@_;
3070: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.484 raeburn 3071: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1",
1.405 bisitz 3072: text=>&Apache::loncommon::course_type().' Editor',
1.329 droeschl 3073: faq=>273,
3074: bug=>'Instructor Interface',
3075: help => 'Docs_Adding_Course_Doc'});
3076: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?".$form.'=1',
3077: text=>$text,
3078: faq=>273,
3079: bug=>'Instructor Interface'});
3080: }
3081:
1.441 www 3082: # subroutine to list form elements
3083: sub create_list_elements {
3084: my @formarr = @_;
3085: my $list = '';
1.501 raeburn 3086: foreach my $button (@formarr){
3087: foreach my $picture (keys(%{$button})) {
3088: $list .= &Apache::lonhtmlcommon::htmltag('li', $picture.' '.$button->{$picture}, {class => 'LC_menubuttons_inline_text', id => ''});
1.441 www 3089: }
3090: }
3091: return $list;
3092: }
1.329 droeschl 3093:
1.441 www 3094: # subroutine to create ul from list elements
3095: sub create_form_ul {
3096: my $list = shift;
3097: my $ul = &Apache::lonhtmlcommon::htmltag('ul',$list, {class => 'LC_ListStyleNormal'});
3098: return $ul;
3099: }
1.329 droeschl 3100:
1.442 www 3101: #
3102: # Start tabs
3103: #
3104:
3105: sub startContentScreen {
1.484 raeburn 3106: my ($mode) = @_;
3107: my $output = '<ul class="LC_TabContentBigger" id="mainnav">';
1.472 raeburn 3108: if (($mode eq 'navmaps') || ($mode eq 'supplemental')) {
1.484 raeburn 3109: $output .= '<li'.(($mode eq 'navmaps')?' class="active"':'').'><a href="/adm/navmaps"><b> '.&mt('Content Overview').' </b></a></li>'."\n";
3110: $output .= '<li'.(($mode eq 'coursesearch')?' class="active"':'').'><a href="/adm/searchcourse"><b> '.&mt('Content Search').' </b></a></li>'."\n";
3111: $output .= '<li'.(($mode eq 'courseindex')?' class="active"':'').'><a href="/adm/indexcourse"><b> '.&mt('Content Index').' </b></a></li>'."\n";
3112: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/supplemental"><b>'.&mt('Supplemental Content').'</b></a></li>';
3113: } else {
3114: $output .= '<li '.(($mode eq 'docs')?' class="active"':'').' id="tabbededitor"><a href="/adm/coursedocs?forcestandard=1"><b> '.&mt('Content Editor').' </b></a></li>'."\n";
3115: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/coursedocs?forcesupplement=1"><b>'.&mt('Supplemental Content Editor').'</b></a></li>'."\n";
3116: $output .= '<li '.(($mode eq 'tools')?' class="active"':'').'><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>'."\n";
3117: '><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>';
3118: }
3119: $output .= "\n".'</ul>'."\n";
3120: $output .= '<div class="LC_DocsBox" style="clear:both;margin:0;" id="contenteditor">'.
3121: '<div id="maincoursedoc" style="margin:0 0;padding:0 0;">'.
3122: '<div class="LC_ContentBox" id="mainCourseDocuments" style="display: block;">';
3123: return $output;
1.442 www 3124: }
3125:
3126: #
3127: # End tabs
3128: #
3129:
3130: sub endContentScreen {
1.484 raeburn 3131: return '</div></div></div>';
1.442 www 3132: }
1.329 droeschl 3133:
1.446 www 3134: sub supplemental_base {
1.472 raeburn 3135: return 'supplemental&'.&escape(&mt('Supplemental '.&Apache::loncommon::course_type().' Content'));
1.446 www 3136: }
3137:
1.329 droeschl 3138: sub handler {
3139: my $r = shift;
3140: &Apache::loncommon::content_type($r,'text/html');
3141: $r->send_http_header;
3142: return OK if $r->header_only;
1.484 raeburn 3143:
3144: # get course data
1.408 raeburn 3145: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 3146: my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
3147: my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
3148:
3149: # graphics settings
3150: $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL').'/');
1.329 droeschl 3151:
1.443 www 3152: #
1.329 droeschl 3153: # --------------------------------------------- Initialize help topics for this
3154: foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',
3155: 'Adding_External_Resource','Navigate_Content',
3156: 'Adding_Folders','Docs_Overview', 'Load_Map',
3157: 'Supplemental','Score_Upload_Form','Adding_Pages',
1.501 raeburn 3158: 'Importing_LON-CAPA_Resource','Importing_IMS_Course',
3159: 'Uploading_From_Harddrive',
1.329 droeschl 3160: 'Check_Resource_Versions','Verify_Content') {
3161: $help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
3162: }
3163: # Composite help files
3164: $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
3165: 'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
3166: $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
3167: 'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
3168: $help{'Simple Problem'} = &Apache::loncommon::help_open_topic(
3169: 'Option_Response_Simple');
3170: $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
3171: 'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
1.347 weissno 3172: $help{'My Personal Information Page'} = &Apache::loncommon::help_open_topic(
1.329 droeschl 3173: 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
1.353 weissno 3174: $help{'Group Portfolio'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
1.329 droeschl 3175: $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
3176:
1.472 raeburn 3177:
3178: my $allowed;
3179: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
3180: unless ($r->uri eq '/adm/supplemental') {
3181: # does this user have privileges to modify content.
3182: $allowed = &Apache::lonnet::allowed('mdc',$env{'request.course.id'});
3183: }
3184:
1.484 raeburn 3185: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['chooseserver',
3186: 'inhibitmenu']);
3187: if ($allowed && $env{'form.chooseserver'}) {
3188: &choose_dump_server($r);
3189: return OK;
3190: } elsif ($allowed && $env{'form.verify'}) {
1.329 droeschl 3191: &init_breadcrumbs('verify','Verify Content');
3192: &verifycontent($r);
3193: } elsif ($allowed && $env{'form.listsymbs'}) {
1.484 raeburn 3194: &init_breadcrumbs('listsymbs','List Content IDs');
1.329 droeschl 3195: &list_symbs($r);
3196: } elsif ($allowed && $env{'form.docslog'}) {
3197: &init_breadcrumbs('docslog','Show Log');
1.484 raeburn 3198: my $folder = $env{'form.folder'};
3199: if ($folder eq '') {
3200: $folder='default';
3201: }
3202: &docs_change_log($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath);
1.329 droeschl 3203: } elsif ($allowed && $env{'form.versions'}) {
3204: &init_breadcrumbs('versions','Check/Set Resource Versions');
3205: &checkversions($r);
3206: } elsif ($allowed && $env{'form.dumpcourse'}) {
1.484 raeburn 3207: &init_breadcrumbs('dumpcourse','Dump '.&Apache::loncommon::course_type().' Content to Authoring Space');
1.329 droeschl 3208: &dumpcourse($r);
3209: } elsif ($allowed && $env{'form.exportcourse'}) {
1.377 bisitz 3210: &init_breadcrumbs('exportcourse','IMS Export');
1.475 raeburn 3211: &Apache::imsexport::exportcourse($r);
1.329 droeschl 3212: } else {
1.445 www 3213: #
3214: # Done catching special calls
1.484 raeburn 3215: # The whole rest is for course and supplemental documents and utilities menu
1.445 www 3216: # Get the parameters that may be needed
3217: #
3218: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
3219: ['folderpath','pagepath',
1.466 www 3220: 'pagesymb','forcesupplement','forcestandard',
1.510 raeburn 3221: 'tools','symb','command','supppath']);
1.445 www 3222:
3223: # standard=1: this is a "new-style" course with an uploaded map as top level
3224: # standard=2: this is a "old-style" course, and there is nothing we can do
1.329 droeschl 3225:
3226: my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
1.445 www 3227:
1.484 raeburn 3228: # Decide whether this should display supplemental or main content or utilities
1.445 www 3229: # supplementalflag=1: show supplemental documents
3230: # supplementalflag=0: show standard documents
1.484 raeburn 3231: # toolsflag=1: show utilities
1.445 www 3232:
3233:
3234: my $supplementalflag=($env{'form.folderpath'}=~/^supplemental/);
3235: if (($env{'form.folderpath'}=~/^default/) || $env{'form.folderpath'} eq "" || ($env{'form.pagepath'})) {
3236: $supplementalflag=0;
3237: }
3238: if ($env{'form.forcesupplement'}) { $supplementalflag=1; }
3239: if ($env{'form.forcestandard'}) { $supplementalflag=0; }
3240: unless ($allowed) { $supplementalflag=1; }
3241: unless ($standard) { $supplementalflag=1; }
1.484 raeburn 3242: my $toolsflag=0;
3243: if ($env{'form.tools'}) { $toolsflag=1; }
1.445 www 3244:
1.329 droeschl 3245: my $script='';
3246: my $showdoc=0;
1.457 raeburn 3247: my $addentries = {};
1.475 raeburn 3248: my $container;
1.329 droeschl 3249: my $containertag;
1.508 raeburn 3250: my $pathitem;
1.329 droeschl 3251:
1.464 www 3252: # Do we directly jump somewhere?
1.466 www 3253:
1.464 www 3254: if ($env{'form.command'} eq 'direct') {
1.468 raeburn 3255: my ($mapurl,$id,$resurl);
1.472 raeburn 3256: if ($env{'form.symb'} ne '') {
1.468 raeburn 3257: ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($env{'form.symb'});
3258: if ($resurl=~/\.(sequence|page)$/) {
3259: $mapurl=$resurl;
3260: } elsif ($resurl eq 'adm/navmaps') {
3261: $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
3262: }
1.472 raeburn 3263: my $mapresobj;
3264: my $navmap = Apache::lonnavmaps::navmap->new();
3265: if (ref($navmap)) {
3266: $mapresobj = $navmap->getResourceByUrl($mapurl);
3267: }
3268: $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
3269: my $type=$2;
3270: my $path;
3271: if (ref($mapresobj)) {
3272: my $pcslist = $mapresobj->map_hierarchy();
3273: if ($pcslist ne '') {
3274: foreach my $pc (split(/,/,$pcslist)) {
3275: next if ($pc <= 1);
3276: my $res = $navmap->getByMapPc($pc);
3277: if (ref($res)) {
3278: my $thisurl = $res->src();
3279: $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
3280: my $thistitle = $res->title();
3281: $path .= '&'.
3282: &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
3283: &Apache::lonhtmlcommon::entity_encode($thistitle).
3284: ':'.$res->randompick().
3285: ':'.$res->randomout().
3286: ':'.$res->encrypted().
3287: ':'.$res->randomorder();
3288: }
1.467 raeburn 3289: }
3290: }
1.510 raeburn 3291: $path =~ s/^\&//;
3292: my $maptitle = $mapresobj->title();
3293: if ($mapurl eq 'default') {
3294: $maptitle = 'Main Course Documents';
3295: }
1.512 raeburn 3296: $path .= (($path ne '')? '&' : '').
1.510 raeburn 3297: &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
3298: &Apache::lonhtmlcommon::entity_encode($maptitle).
1.467 raeburn 3299: ':'.$mapresobj->randompick().
3300: ':'.$mapresobj->randomout().
3301: ':'.$mapresobj->encrypted().
3302: ':'.$mapresobj->randomorder();
1.472 raeburn 3303: } else {
3304: my $maptitle = &Apache::lonnet::gettitle($mapurl);
1.510 raeburn 3305: if ($mapurl eq 'default') {
3306: $maptitle = 'Main Course Documents';
3307: }
3308: $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
3309: &Apache::lonhtmlcommon::entity_encode($maptitle).'::::';
3310: }
3311: unless ($mapurl eq 'default') {
3312: $path = 'default&'.
3313: &Apache::lonhtmlcommon::entity_encode('Main Course Documents').
3314: '::::&'.$path;
1.472 raeburn 3315: }
3316: if ($type eq 'sequence') {
3317: $env{'form.folderpath'}=$path;
3318: $env{'form.pagepath'}='';
3319: } else {
3320: $env{'form.pagepath'}=$path;
3321: $env{'form.folderpath'}='';
3322: }
3323: } elsif ($env{'form.supppath'} ne '') {
3324: $env{'form.folderpath'}=$env{'form.supppath'};
1.466 www 3325: }
1.472 raeburn 3326: } elsif ($env{'form.command'} eq 'editdocs') {
3327: $env{'form.folderpath'} = 'default&'.
3328: &Apache::lonhtmlcommon::entity_encode('Main Course Content');
3329: $env{'form.pagepath'}='';
3330: } elsif ($env{'form.command'} eq 'editsupp') {
3331: $env{'form.folderpath'} = 'default&'.
3332: &Apache::lonhtmlcommon::entity_encode('Supplemental Content');
3333: $env{'form.pagepath'}='';
1.464 www 3334: }
3335:
1.445 www 3336: # Where do we store these for when we come back?
3337: my $stored_folderpath='docs_folderpath';
3338: if ($supplementalflag) {
3339: $stored_folderpath='docs_sup_folderpath';
3340: }
1.464 www 3341:
1.510 raeburn 3342: # No folderpath, no pagepath, and in edit mode, see if we have something stored
3343: if ((!$env{'form.folderpath'}) && (!$env{'form.pagepath'}) && $allowed) {
1.445 www 3344: &Apache::loncommon::restore_course_settings($stored_folderpath,
1.510 raeburn 3345: {'folderpath' => 'scalar'});
1.329 droeschl 3346: }
1.446 www 3347:
3348: # If we are not allowed to make changes, all we can see are supplemental docs
1.409 raeburn 3349: if (!$allowed) {
1.446 www 3350: $env{'form.pagepath'}='';
3351: unless ($env{'form.folderpath'} =~ /^supplemental/) {
3352: $env{'form.folderpath'} = &supplemental_base();
1.409 raeburn 3353: }
3354: }
1.446 www 3355: # If we still not have a folderpath, see if we can resurrect at pagepath
1.409 raeburn 3356: if (!$env{'form.folderpath'} && $allowed) {
1.445 www 3357: &Apache::loncommon::restore_course_settings($stored_folderpath,
1.329 droeschl 3358: {'pagepath' => 'scalar'});
3359: }
1.446 www 3360: # Make the zeroth entry in supplemental docs page paths, so we can get to top level
1.329 droeschl 3361: if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
1.446 www 3362: $env{'form.folderpath'} = &supplemental_base()
3363: .'&'.
1.329 droeschl 3364: $env{'form.folderpath'};
3365: }
1.446 www 3366: # If after all of this, we still don't have any paths, make them
3367: unless (($env{'form.pagepath'}) || ($env{'form.folderpath'})) {
3368: if ($supplementalflag) {
3369: $env{'form.folderpath'}=&supplemental_base();
3370: } else {
3371: $env{'form.folderpath'}='default';
3372: }
1.472 raeburn 3373: }
1.446 www 3374:
1.445 www 3375: # Store this
1.484 raeburn 3376: unless ($toolsflag) {
1.510 raeburn 3377: if ($allowed) {
3378: &Apache::loncommon::store_course_settings($stored_folderpath,
3379: {'pagepath' => 'scalar',
3380: 'folderpath' => 'scalar'});
3381: }
1.484 raeburn 3382: if ($env{'form.folderpath'}) {
3383: my (@folderpath)=split('&',$env{'form.folderpath'});
3384: $env{'form.foldername'}=&unescape(pop(@folderpath));
3385: $env{'form.folder'}=pop(@folderpath);
3386: $container='sequence';
3387: }
3388: if ($env{'form.pagepath'}) {
3389: my (@pagepath)=split('&',$env{'form.pagepath'});
3390: $env{'form.pagename'}=&unescape(pop(@pagepath));
3391: $env{'form.folder'}=pop(@pagepath);
3392: $container='page';
3393: $containertag = '<input type="hidden" name="pagepath" value="" />'.
3394: '<input type="hidden" name="pagesymb" value="" />';
1.508 raeburn 3395: $pathitem =
1.484 raeburn 3396: '<input type="hidden" name="pagepath" value="'.&HTML::Entities::encode($env{'form.pagepath'},'<>&"').'" />'.
3397: '<input type="hidden" name="pagesymb" value="'.&HTML::Entities::encode($env{'form.pagesymb'},'<>&"').'" />'.
3398: '<input type="hidden" name="folderpath" value="" />';
3399: } else {
3400: my $folderpath=$env{'form.folderpath'};
3401: if (!$folderpath) {
3402: if ($env{'form.folder'} eq '' ||
3403: $env{'form.folder'} eq 'supplemental') {
3404: $folderpath='default&'.
3405: &escape(&mt('Main '.$crstype.' Documents'));
3406: }
3407: }
3408: $containertag = '<input type="hidden" name="folderpath" value="" />';
1.508 raeburn 3409: $pathitem = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
1.484 raeburn 3410: }
3411: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
3412: $showdoc='/'.$1;
3413: }
3414: if ($showdoc) { # got called in sequence from course
3415: $allowed=0;
3416: } else {
3417: if ($allowed) {
3418: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
3419: $script=&Apache::lonratedt::editscript('simple');
1.433 raeburn 3420: }
3421: }
1.329 droeschl 3422: }
3423:
1.344 bisitz 3424: # get personal data
1.329 droeschl 3425: my $uname=$env{'user.name'};
3426: my $udom=$env{'user.domain'};
3427: my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));
3428:
3429: if ($allowed) {
1.484 raeburn 3430: if ($toolsflag) {
3431: $script .= &inject_data_js();
3432: my ($home,$other,%outhash)=&authorhosts();
3433: if (!$home && $other) {
3434: my @hosts;
3435: foreach my $aurole (keys(%outhash)) {
3436: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
3437: push(@hosts,$outhash{$aurole});
3438: }
3439: }
3440: $script .= &dump_switchserver_js(@hosts);
3441: }
1.458 raeburn 3442: } else {
1.484 raeburn 3443: my @tabids;
3444: if ($supplementalflag) {
3445: @tabids = ('002','ee2','ff2');
3446: } else {
3447: @tabids = ('aa1','bb1','cc1','ff1');
3448: unless ($env{'form.pagepath'}) {
3449: unshift(@tabids,'001');
3450: push(@tabids,('dd1','ee1'));
3451: }
1.458 raeburn 3452: }
1.484 raeburn 3453: my $tabidstr = join("','",@tabids);
3454: $script .= &editing_js($udom,$uname,$supplementalflag).
3455: &history_tab_js().
3456: &inject_data_js().
1.510 raeburn 3457: &Apache::lonhtmlcommon::resize_scrollbox_js('docs',$tabidstr).
3458: &Apache::lonextresedit::extedit_javascript();
1.484 raeburn 3459: $addentries = {
1.485 raeburn 3460: onload => "javascript:resize_scrollbox('contentscroll','1','1');",
1.484 raeburn 3461: };
1.458 raeburn 3462: }
1.492 raeburn 3463: if ($env{'docs.markedcopy_url'}) {
3464: $script .= &paste_popup_js();
3465: }
1.501 raeburn 3466: my $confirm_switch = &mt("Editing requires switching to the resource's home server.").'\n'.
3467: &mt('Switch server?');
3468:
3469:
1.329 droeschl 3470: }
3471: # -------------------------------------------------------------------- Body tag
1.369 bisitz 3472: $script = '<script type="text/javascript">'."\n"
1.372 bisitz 3473: .'// <![CDATA['."\n"
3474: .$script."\n"
3475: .'// ]]>'."\n"
3476: .'</script>'."\n";
1.385 bisitz 3477:
3478: # Breadcrumbs
3479: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.510 raeburn 3480:
3481: if ($showdoc) {
3482: $r->print(&Apache::loncommon::start_page("$crstype documents",undef,
3483: {'force_register' => $showdoc,}));
3484: } elsif ($r->uri eq '/adm/supplemental') {
3485: my $brcrum = &Apache::lonhtmlcommon::docs_breadcrumbs(undef,$crstype);
3486: $r->print(&Apache::loncommon::start_page("Supplemental $crstype Content",undef,
3487: {'bread_crumbs' => $brcrum,}));
3488: } else {
1.392 raeburn 3489: &Apache::lonhtmlcommon::add_breadcrumb({
1.446 www 3490: href=>"/adm/coursedocs",text=>"$crstype Contents"});
1.392 raeburn 3491:
1.446 www 3492: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script,
1.510 raeburn 3493: {'add_entries' => $addentries}
3494: )
1.392 raeburn 3495: .&Apache::loncommon::help_open_menu('','',273,'RAT')
3496: .&Apache::lonhtmlcommon::breadcrumbs(
1.484 raeburn 3497: 'Editing '.$crstype.' Contents',
1.392 raeburn 3498: 'Docs_Adding_Course_Doc')
3499: );
3500: }
1.364 bisitz 3501:
1.329 droeschl 3502: my %allfiles = ();
3503: my %codebase = ();
1.440 raeburn 3504: my ($upload_result,$upload_output,$uploadphase);
1.329 droeschl 3505: if ($allowed) {
3506: if (($env{'form.uploaddoc.filename'}) &&
3507: ($env{'form.cmd'}=~/^upload_(\w+)/)) {
1.440 raeburn 3508: my $context = $1;
3509: # Process file upload - phase one - upload and parse primary file.
1.329 droeschl 3510: undef($hadchanges);
1.440 raeburn 3511: $uploadphase = &process_file_upload(\$upload_output,$coursenum,$coursedom,
3512: \%allfiles,\%codebase,$context);
1.329 droeschl 3513: if ($hadchanges) {
3514: &mark_hash_old();
3515: }
1.440 raeburn 3516: $r->print($upload_output);
3517: } elsif ($env{'form.phase'} eq 'upload_embedded') {
3518: # Process file upload - phase two - upload embedded objects
3519: $uploadphase = 'check_embedded';
3520: my $primaryurl = &HTML::Entities::encode($env{'form.primaryurl'},'<>&"');
3521: my $state = &embedded_form_elems($uploadphase,$primaryurl,
3522: $env{'form.newidx'});
3523: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
3524: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
3525: my ($destination,$dir_root) = &embedded_destination();
3526: my $url_root = '/uploaded/'.$docudom.'/'.$docuname;
3527: my $actionurl = '/adm/coursedocs';
3528: my ($result,$flag) =
3529: &Apache::loncommon::upload_embedded('coursedoc',$destination,
3530: $docuname,$docudom,$dir_root,$url_root,undef,undef,undef,$state,
3531: $actionurl);
3532: $r->print($result.&return_to_editor());
3533: } elsif ($env{'form.phase'} eq 'check_embedded') {
3534: # Process file upload - phase three - modify references in HTML file
3535: $uploadphase = 'modified_orightml';
3536: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
3537: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
3538: my ($destination,$dir_root) = &embedded_destination();
1.482 raeburn 3539: my $result =
3540: &Apache::loncommon::modify_html_refs('coursedoc',$destination,
3541: $docuname,$docudom,undef,
3542: $dir_root);
3543: $r->print($result.&return_to_editor());
1.476 raeburn 3544: } elsif ($env{'form.phase'} eq 'decompress_uploaded') {
3545: $uploadphase = 'decompress_phase_one';
3546: $r->print(&decompression_phase_one().
3547: &return_to_editor());
3548: } elsif ($env{'form.phase'} eq 'decompress_cleanup') {
3549: $uploadphase = 'decompress_phase_two';
3550: $r->print(&decompression_phase_two().
3551: &return_to_editor());
1.329 droeschl 3552: }
3553: }
3554:
1.484 raeburn 3555: if ($allowed && $toolsflag) {
3556: $r->print(&startContentScreen('tools'));
3557: $r->print(&generate_admin_menu($crstype));
3558: $r->print(&endContentScreen());
3559: } elsif ((!$showdoc) && (!$uploadphase)) {
1.329 droeschl 3560: # -----------------------------------------------------------------------------
3561: my %lt=&Apache::lonlocal::texthash(
1.408 raeburn 3562: 'uplm' => 'Upload a new main '.lc($crstype).' document',
3563: 'upls' => 'Upload a new supplemental '.lc($crstype).' document',
1.329 droeschl 3564: 'impp' => 'Import a document',
3565: 'copm' => 'All documents out of a published map into this folder',
1.501 raeburn 3566: 'upfi' => 'Upload File',
3567: 'upld' => 'Import Content',
1.329 droeschl 3568: 'srch' => 'Search',
3569: 'impo' => 'Import',
1.487 raeburn 3570: 'lnks' => 'Import from Stored Links',
1.502 raeburn 3571: 'impm' => 'Import from Assembled Map',
1.329 droeschl 3572: 'selm' => 'Select Map',
3573: 'load' => 'Load Map',
1.419 bisitz 3574: 'reco' => 'Recover Deleted Documents',
1.329 droeschl 3575: 'newf' => 'New Folder',
3576: 'newp' => 'New Composite Page',
3577: 'extr' => 'External Resource',
3578: 'syll' => 'Syllabus',
1.425 raeburn 3579: 'navc' => 'Table of Contents',
1.343 biermanm 3580: 'sipa' => 'Simple Course Page',
1.329 droeschl 3581: 'sipr' => 'Simple Problem',
3582: 'drbx' => 'Drop Box',
1.451 www 3583: 'scuf' => 'External Scores (handgrade, upload, clicker)',
1.336 schafran 3584: 'bull' => 'Discussion Board',
1.347 weissno 3585: 'mypi' => 'My Personal Information Page',
1.353 weissno 3586: 'grpo' => 'Group Portfolio',
1.329 droeschl 3587: 'rost' => 'Course Roster',
1.348 weissno 3588: 'abou' => 'Personal Information Page for a User',
1.377 bisitz 3589: 'imsf' => 'IMS Import',
3590: 'imsl' => 'Import IMS package',
1.501 raeburn 3591: 'cms' => 'Origin of IMS package',
3592: 'se' => 'Select',
1.329 droeschl 3593: 'file' => 'File',
3594: 'title' => 'Title',
3595: 'comment' => 'Comment',
1.501 raeburn 3596: 'url' => 'URL',
3597: 'prev' => 'Preview',
3598: 'lnk' => 'Add Link',
1.403 raeburn 3599: 'parse' => 'Upload embedded images/multimedia files if HTML file',
1.329 droeschl 3600: );
3601: # -----------------------------------------------------------------------------
3602: my $fileupload=(<<FIUP);
3603: $lt{'file'}:<br />
3604: <input type="file" name="uploaddoc" size="40" />
3605: FIUP
3606:
3607: my $checkbox=(<<CHBO);
3608: <!-- <label>$lt{'parse'}?
3609: <input type="checkbox" name="parserflag" />
3610: </label> -->
3611: <label>
3612: <input type="checkbox" name="parserflag" checked="checked" /> $lt{'parse'}
3613: </label>
3614: CHBO
1.501 raeburn 3615: my $imsfolder = $env{'form.folder'};
3616: if ($imsfolder eq '') {
3617: $imsfolder = 'default';
3618: }
3619: my $imspform=(<<IMSFORM);
3620: <a class="LC_menubuttons_link" href="javascript:toggleUpload('ims');">
3621: $lt{'imsf'}</a> $help{'Importing_IMS_Course'}
3622: <form name="uploadims" action="/adm/imsimportdocs" method="post" enctype="multipart/form-data" target="IMSimport">
1.516 raeburn 3623: <fieldset id="uploadimsform" style="display: none;">
1.501 raeburn 3624: <legend>$lt{'imsf'}</legend>
3625: $fileupload
3626: <br />
3627: <p>
3628: $lt{'cms'}:
3629: <select name="source">
3630: <option value="-1" selected="selected">$lt{'se'}</option>
3631: <option value="bb5">Blackboard 5</option>
3632: <option value="bb6">Blackboard 6</option>
3633: <option value="angel5">ANGEL 5.5</option>
3634: <option value="webctce4">WebCT 4 Campus Edition</option>
3635: </select>
3636: <input type="hidden" name="folder" value="$imsfolder" />
3637: </p>
3638: <input type="hidden" name="phase" value="one" />
3639: <input type="button" value="$lt{'imsl'}" onclick="makeims(this.form);" />
3640: </fieldset>
3641: </form>
3642: IMSFORM
1.329 droeschl 3643:
3644: my $fileuploadform=(<<FUFORM);
1.501 raeburn 3645: <a class="LC_menubuttons_link" href="javascript:toggleUpload('doc');">
3646: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
3647: <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.516 raeburn 3648: <fieldset id="uploaddocform" style="display: none;">
1.501 raeburn 3649: <legend>$lt{'upfi'}</legend>
1.371 tempelho 3650: <input type="hidden" name="active" value="aa" />
1.329 droeschl 3651: $fileupload
3652: <br />
3653: $lt{'title'}:<br />
1.458 raeburn 3654: <input type="text" size="60" name="comment" />
1.508 raeburn 3655: $pathitem
1.329 droeschl 3656: <input type="hidden" name="cmd" value="upload_default" />
3657: <br />
1.458 raeburn 3658: <span class="LC_nobreak" style="float:left">
1.329 droeschl 3659: $checkbox
3660: </span>
1.501 raeburn 3661: <br clear="all" />
3662: <input type="submit" value="$lt{'upld'}" />
3663: </fieldset>
3664: </form>
1.383 tempelho 3665: FUFORM
1.329 droeschl 3666:
1.502 raeburn 3667: my $importpubform=(<<SEDFFORM);
1.514 raeburn 3668: <a class="LC_menubuttons_link" href="javascript:toggleMap('map');">
1.502 raeburn 3669: $lt{'impm'}</a>$help{'Load_Map'}
3670: <form action="/adm/coursedocs" method="post" name="mapimportform">
1.516 raeburn 3671: <fieldset id="importmapform" style="display: none;">
1.502 raeburn 3672: <legend>$lt{'impm'}</legend>
1.371 tempelho 3673: <input type="hidden" name="active" value="bb" />
1.502 raeburn 3674: $lt{'copm'}<br />
3675: <span class="LC_nobreak">
3676: <input type="text" name="importmap" size="40" value=""
3677: onfocus="this.blur();openbrowser('mapimportform','importmap','sequence,page','');" />
1.516 raeburn 3678: <a href="javascript:openbrowser('mapimportform','importmap','sequence,page','');">$lt{'selm'}</a></span><br />
1.502 raeburn 3679: <input type="submit" name="loadmap" value="$lt{'load'}" />
3680: </fieldset>
3681: </form>
3682:
1.383 tempelho 3683: SEDFFORM
1.502 raeburn 3684: my @importpubforma = (
1.508 raeburn 3685: { '<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 3686: { '<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 3687: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/wishlist.png" alt="'.$lt{lnks}.'" onclick="javascript:open_StoredLinks_Import();" />' => "<a class='LC_menubuttons_link' href='javascript:open_StoredLinks_Import();'>$lt{'lnks'}</a>" },
1.514 raeburn 3688: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/sequence.png" alt="'.$lt{impm}.'" onclick="javascript:toggleMap(\'map\');" />' => $importpubform }
1.383 tempelho 3689: );
1.502 raeburn 3690: $importpubform = &create_form_ul(&create_list_elements(@importpubforma));
1.510 raeburn 3691: my $extresourcesform =
3692: &Apache::lonextresedit::extedit_form(0,0,undef,undef,$pathitem,
3693: $help{'Adding_External_Resource'});
1.329 droeschl 3694: if ($allowed) {
1.492 raeburn 3695: my $folder = $env{'form.folder'};
3696: if ($folder eq '') {
3697: $folder='default';
3698: }
3699: &update_paste_buffer($coursenum,$coursedom,$folder);
1.337 ehlerst 3700: $r->print(<<HIDDENFORM);
3701: <form name="renameform" method="post" action="/adm/coursedocs">
3702: <input type="hidden" name="title" />
3703: <input type="hidden" name="cmd" />
3704: <input type="hidden" name="markcopy" />
3705: <input type="hidden" name="copyfolder" />
3706: $containertag
3707: </form>
1.484 raeburn 3708:
1.337 ehlerst 3709: HIDDENFORM
1.508 raeburn 3710: $r->print(&makesimpleeditform($pathitem)."\n".
3711: &makedocslogform($pathitem."\n".
1.484 raeburn 3712: '<input type="hidden" name="folder" value="'.
3713: $env{'form.folder'}.'" />'."\n"));
1.329 droeschl 3714: }
1.442 www 3715:
3716: # Generate the tabs
1.510 raeburn 3717: my ($mode,$needs_end);
1.472 raeburn 3718: if (($supplementalflag) && (!$allowed)) {
1.510 raeburn 3719: my @folders = split('&',$env{'form.folderpath'});
3720: unless (@folders > 2) {
3721: &Apache::lonnavdisplay::startContentScreen($r,'supplemental');
3722: $needs_end = 1;
3723: }
1.472 raeburn 3724: } else {
1.484 raeburn 3725: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.510 raeburn 3726: $needs_end = 1;
1.472 raeburn 3727: }
1.443 www 3728:
1.442 www 3729: #
3730:
3731: my $savefolderpath;
3732:
1.395 raeburn 3733: if ($allowed) {
1.329 droeschl 3734: my $folder=$env{'form.folder'};
1.443 www 3735: if ($folder eq '' || $supplementalflag) {
1.329 droeschl 3736: $folder='default';
1.356 tempelho 3737: $savefolderpath = $env{'form.folderpath'};
1.442 www 3738: $env{'form.folderpath'}='default&'.&escape(&mt('Content'));
1.508 raeburn 3739: $pathitem = '<input type="hidden" name="folderpath" value="'.
1.329 droeschl 3740: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
3741: }
3742: my $postexec='';
3743: if ($folder eq 'default') {
1.372 bisitz 3744: $r->print('<script type="text/javascript">'."\n"
3745: .'// <![CDATA['."\n"
3746: .'this.window.name="loncapaclient";'."\n"
3747: .'// ]]>'."\n"
3748: .'</script>'."\n"
1.369 bisitz 3749: );
1.329 droeschl 3750: } else {
3751: #$postexec='self.close();';
3752: }
1.504 raeburn 3753: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.sequence';
3754: my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_new.page';
1.329 droeschl 3755: my $container='sequence';
3756: if ($env{'form.pagepath'}) {
3757: $container='page';
3758: }
3759: my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
3760:
3761: my $newnavform=(<<NNFORM);
3762: <form action="/adm/coursedocs" method="post" name="newnav">
1.371 tempelho 3763: <input type="hidden" name="active" value="cc" />
1.508 raeburn 3764: $pathitem
1.329 droeschl 3765: <input type="hidden" name="importdetail"
3766: value="$lt{'navc'}=/adm/navmaps" />
1.423 onken 3767: <a class="LC_menubuttons_link" href="javascript:document.newnav.submit()">$lt{'navc'}</a>
1.329 droeschl 3768: $help{'Navigate_Content'}
3769: </form>
3770: NNFORM
3771: my $newsmppageform=(<<NSPFORM);
3772: <form action="/adm/coursedocs" method="post" name="newsmppg">
1.371 tempelho 3773: <input type="hidden" name="active" value="cc" />
1.508 raeburn 3774: $pathitem
1.329 droeschl 3775: <input type="hidden" name="importdetail" value="" />
1.423 onken 3776: <a class="LC_menubuttons_link" href="javascript:makesmppage();"> $lt{'sipa'}</a>
1.383 tempelho 3777: $help{'Simple Page'}
1.329 droeschl 3778: </form>
3779: NSPFORM
3780:
3781: my $newsmpproblemform=(<<NSPROBFORM);
3782: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
1.371 tempelho 3783: <input type="hidden" name="active" value="cc" />
1.508 raeburn 3784: $pathitem
1.329 droeschl 3785: <input type="hidden" name="importdetail" value="" />
1.423 onken 3786: <a class="LC_menubuttons_link" href="javascript:makesmpproblem();">$lt{'sipr'}</a>
1.383 tempelho 3787: $help{'Simple Problem'}
1.329 droeschl 3788: </form>
3789:
3790: NSPROBFORM
3791:
3792: my $newdropboxform=(<<NDBFORM);
3793: <form action="/adm/coursedocs" method="post" name="newdropbox">
1.371 tempelho 3794: <input type="hidden" name="active" value="cc" />
1.508 raeburn 3795: $pathitem
1.329 droeschl 3796: <input type="hidden" name="importdetail" value="" />
1.423 onken 3797: <a class="LC_menubuttons_link" href="javascript:makedropbox();">$lt{'drbx'}</a>
1.344 bisitz 3798: </form>
1.329 droeschl 3799: NDBFORM
3800:
3801: my $newexuploadform=(<<NEXUFORM);
3802: <form action="/adm/coursedocs" method="post" name="newexamupload">
1.371 tempelho 3803: <input type="hidden" name="active" value="cc" />
1.508 raeburn 3804: $pathitem
1.329 droeschl 3805: <input type="hidden" name="importdetail" value="" />
1.423 onken 3806: <a class="LC_menubuttons_link" href="javascript:makeexamupload();">$lt{'scuf'}</a>
1.329 droeschl 3807: $help{'Score_Upload_Form'}
3808: </form>
3809: NEXUFORM
3810:
3811: my $newbulform=(<<NBFORM);
3812: <form action="/adm/coursedocs" method="post" name="newbul">
1.371 tempelho 3813: <input type="hidden" name="active" value="cc" />
1.508 raeburn 3814: $pathitem
1.329 droeschl 3815: <input type="hidden" name="importdetail" value="" />
1.423 onken 3816: <a class="LC_menubuttons_link" href="javascript:makebulboard();" >$lt{'bull'}</a>
1.329 droeschl 3817: $help{'Bulletin Board'}
3818: </form>
3819: NBFORM
3820:
3821: my $newaboutmeform=(<<NAMFORM);
3822: <form action="/adm/coursedocs" method="post" name="newaboutme">
1.371 tempelho 3823: <input type="hidden" name="active" value="cc" />
1.508 raeburn 3824: $pathitem
1.329 droeschl 3825: <input type="hidden" name="importdetail"
3826: value="$plainname=/adm/$udom/$uname/aboutme" />
1.423 onken 3827: <a class="LC_menubuttons_link" href="javascript:document.newaboutme.submit()">$lt{'mypi'}</a>
1.347 weissno 3828: $help{'My Personal Information Page'}
1.329 droeschl 3829: </form>
3830: NAMFORM
3831:
3832: my $newaboutsomeoneform=(<<NASOFORM);
3833: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
1.371 tempelho 3834: <input type="hidden" name="active" value="cc" />
1.508 raeburn 3835: $pathitem
1.329 droeschl 3836: <input type="hidden" name="importdetail" value="" />
1.423 onken 3837: <a class="LC_menubuttons_link" href="javascript:makeabout();">$lt{'abou'}</a>
1.329 droeschl 3838: </form>
3839: NASOFORM
3840:
3841:
3842: my $newrosterform=(<<NROSTFORM);
3843: <form action="/adm/coursedocs" method="post" name="newroster">
1.371 tempelho 3844: <input type="hidden" name="active" value="cc" />
1.508 raeburn 3845: $pathitem
1.329 droeschl 3846: <input type="hidden" name="importdetail"
3847: value="$lt{'rost'}=/adm/viewclasslist" />
1.423 onken 3848: <a class="LC_menubuttons_link" href="javascript:document.newroster.submit()">$lt{'rost'}</a>
1.329 droeschl 3849: $help{'Course Roster'}
3850: </form>
3851: NROSTFORM
3852:
1.342 ehlerst 3853: my $specialdocumentsform;
1.383 tempelho 3854: my @specialdocumentsforma;
1.451 www 3855: my $gradingform;
3856: my @gradingforma;
3857: my $communityform;
3858: my @communityforma;
1.351 ehlerst 3859: my $newfolderform;
1.390 tempelho 3860: my $newfolderb;
1.342 ehlerst 3861:
1.451 www 3862: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.383 tempelho 3863:
1.329 droeschl 3864: my $newpageform=(<<NPFORM);
3865: <form action="/adm/coursedocs" method="post" name="newpage">
3866: <input type="hidden" name="folderpath" value="$path" />
3867: <input type="hidden" name="importdetail" value="" />
1.371 tempelho 3868: <input type="hidden" name="active" value="cc" />
1.423 onken 3869: <a class="LC_menubuttons_link" href="javascript:makenewpage(document.newpage,'$pageseq');">$lt{'newp'}</a>
1.383 tempelho 3870: $help{'Adding_Pages'}
1.329 droeschl 3871: </form>
3872: NPFORM
1.390 tempelho 3873:
3874:
1.351 ehlerst 3875: $newfolderform=(<<NFFORM);
1.329 droeschl 3876: <form action="/adm/coursedocs" method="post" name="newfolder">
1.508 raeburn 3877: $pathitem
1.329 droeschl 3878: <input type="hidden" name="importdetail" value="" />
1.371 tempelho 3879: <input type="hidden" name="active" value="aa" />
1.422 onken 3880: <a href="javascript:makenewfolder(document.newfolder,'$folderseq');">$lt{'newf'}</a>$help{'Adding_Folders'}
1.329 droeschl 3881: </form>
3882: NFFORM
3883:
3884: my $newsylform=(<<NSYLFORM);
3885: <form action="/adm/coursedocs" method="post" name="newsyl">
1.371 tempelho 3886: <input type="hidden" name="active" value="cc" />
1.508 raeburn 3887: $pathitem
1.329 droeschl 3888: <input type="hidden" name="importdetail"
3889: value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />
1.423 onken 3890: <a class="LC_menubuttons_link" href="javascript:document.newsyl.submit()">$lt{'syll'}</a>
1.329 droeschl 3891: $help{'Syllabus'}
1.383 tempelho 3892:
1.329 droeschl 3893: </form>
3894: NSYLFORM
1.364 bisitz 3895:
1.329 droeschl 3896: my $newgroupfileform=(<<NGFFORM);
3897: <form action="/adm/coursedocs" method="post" name="newgroupfiles">
1.371 tempelho 3898: <input type="hidden" name="active" value="cc" />
1.508 raeburn 3899: $pathitem
1.329 droeschl 3900: <input type="hidden" name="importdetail"
3901: value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
1.423 onken 3902: <a class="LC_menubuttons_link" href="javascript:document.newgroupfiles.submit()">$lt{'grpo'}</a>
1.353 weissno 3903: $help{'Group Portfolio'}
1.329 droeschl 3904: </form>
3905: NGFFORM
1.383 tempelho 3906: @specialdocumentsforma=(
1.421 onken 3907: {'<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 3908: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="document.newsyl.submit()" />'=>$newsylform},
1.451 www 3909: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/navigation.png" alt="'.$lt{navc}.'" onclick="document.newnav.submit()" />'=>$newnavform},
3910: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simple.png" alt="'.$lt{sipa}.'" onclick="javascript:makesmppage();" />'=>$newsmppageform},
3911: );
3912: $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma));
3913:
1.434 raeburn 3914:
3915: my @importdoc = (
1.501 raeburn 3916: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="toggleUpload(\'ext\');" />'=>$extresourcesform},
3917: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/ims.png" alt="'.$lt{imsf}.'" onclick="javascript:toggleUpload(\'ims\');" />'=>$imspform},
3918: {'<img class="LC_noBorder_LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'doc\');" />'=>$fileuploadform,
3919: });
3920: $fileuploadform = &create_form_ul(&create_list_elements(@importdoc));
1.434 raeburn 3921:
1.451 www 3922: @gradingforma=(
3923: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{sipr}.'" onclick="javascript:makesmpproblem();" />'=>$newsmpproblemform},
3924: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/dropbox.png" alt="'.$lt{drbx}.'" onclick="javascript:makedropbox();" />'=>$newdropboxform},
3925: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/scoreupfrm.png" alt="'.$lt{scuf}.'" onclick="javascript:makeexamupload();" />'=>$newexuploadform},
3926:
3927: );
3928: $gradingform = &create_form_ul(&create_list_elements(@gradingforma));
3929:
3930: @communityforma=(
3931: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/bchat.png" alt="'.$lt{bull}.'" onclick="javascript:makebulboard();" />'=>$newbulform},
3932: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makebulboard();" />'=>$newaboutmeform},
3933: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/aboutme.png" alt="'.$lt{abou}.'" onclick="javascript:makeabout();" />'=>$newaboutsomeoneform},
3934: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/clst.png" alt="'.$lt{rost}.'" onclick="document.newroster.submit()" />'=>$newrosterform},
3935: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/groupportfolio.png" alt="'.$lt{grpo}.'" onclick="document.newgroupfiles.submit()" />'=>$newgroupfileform},
3936: );
3937: $communityform = &create_form_ul(&create_list_elements(@communityforma));
1.383 tempelho 3938:
1.330 tempelho 3939: my %orderhash = (
1.488 raeburn 3940: 'aa' => ['Import Content',$fileuploadform],
1.502 raeburn 3941: 'bb' => ['Published Content',$importpubform],
1.451 www 3942: 'cc' => ['Grading Resources',$gradingform],
1.330 tempelho 3943: );
1.451 www 3944: unless ($env{'form.pagepath'}) {
1.434 raeburn 3945: $orderhash{'00'} = ['Newfolder',$newfolderform];
1.484 raeburn 3946: $orderhash{'dd'} = ['Collaboration',$communityform];
1.515 raeburn 3947: $orderhash{'ee'} = ['Special Pages',$specialdocumentsform];
1.434 raeburn 3948: }
3949:
1.341 ehlerst 3950: $hadchanges=0;
1.484 raeburn 3951: unless (($supplementalflag || $toolsflag)) {
1.458 raeburn 3952: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.508 raeburn 3953: $supplementalflag,\%orderhash,$iconpath,$pathitem);
1.443 www 3954: if ($error) {
3955: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
3956: }
3957: if ($hadchanges) {
3958: &mark_hash_old();
3959: }
1.341 ehlerst 3960:
1.443 www 3961: &changewarning($r,'');
3962: }
1.458 raeburn 3963: }
1.442 www 3964:
1.443 www 3965: # Supplemental documents start here
3966:
1.329 droeschl 3967: my $folder=$env{'form.folder'};
1.443 www 3968: unless ($supplementalflag) {
1.329 droeschl 3969: $folder='supplemental';
3970: }
3971: if ($folder =~ /^supplemental$/ &&
3972: (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
1.446 www 3973: $env{'form.folderpath'} = &supplemental_base();
1.393 raeburn 3974: } elsif ($allowed) {
1.356 tempelho 3975: $env{'form.folderpath'} = $savefolderpath;
1.329 droeschl 3976: }
1.362 ehlerst 3977: $env{'form.pagepath'} = '';
1.508 raeburn 3978: $pathitem = '<input type="hidden" name="folderpath" value="'.
3979: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
1.329 droeschl 3980: if ($allowed) {
3981: my $folderseq=
1.504 raeburn 3982: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_new.sequence';
1.329 droeschl 3983:
3984: my $supupdocform=(<<SUPDOCFORM);
1.501 raeburn 3985: <a class="LC_menubuttons_link" href="javascript:toggleUpload('suppdoc');">
3986: $lt{'upfi'}</a> $help{'Uploading_From_Harddrive'}
1.383 tempelho 3987: <form action="/adm/coursedocs" method="post" name="supuploaddocument" enctype="multipart/form-data">
1.516 raeburn 3988: <fieldset id="uploadsuppdocform" style="display: none;">
1.501 raeburn 3989: <legend>$lt{'upfi'}</legend>
1.371 tempelho 3990: <input type="hidden" name="active" value="ee" />
1.329 droeschl 3991: $fileupload
3992: <br />
3993: <br />
3994: <span class="LC_nobreak">
3995: $checkbox
3996: </span>
3997: <br /><br />
3998: $lt{'comment'}:<br />
1.383 tempelho 3999: <textarea cols="50" rows="4" name="comment"></textarea>
1.329 droeschl 4000: <br />
1.508 raeburn 4001: $pathitem
1.329 droeschl 4002: <input type="hidden" name="cmd" value="upload_supplemental" />
1.501 raeburn 4003: <input type='submit' value="$lt{'upld'}" />
4004: </form>
1.329 droeschl 4005: SUPDOCFORM
4006:
4007: my $supnewfolderform=(<<SNFFORM);
4008: <form action="/adm/coursedocs" method="post" name="supnewfolder">
1.371 tempelho 4009: <input type="hidden" name="active" value="ee" />
1.508 raeburn 4010: $pathitem
1.329 droeschl 4011: <input type="hidden" name="importdetail" value="" />
1.423 onken 4012: <a class="LC_menubuttons_link" href="javascript:makenewfolder(document.supnewfolder,'$folderseq');">$lt{'newf'}</a>
1.383 tempelho 4013: $help{'Adding_Folders'}
1.329 droeschl 4014: </form>
4015: SNFFORM
1.383 tempelho 4016:
1.510 raeburn 4017: my $supextform =
4018: &Apache::lonextresedit::extedit_form(1,0,undef,undef,$pathitem,
4019: $help{'Adding_External_Resource'});
1.329 droeschl 4020:
4021: my $supnewsylform=(<<SNSFORM);
4022: <form action="/adm/coursedocs" method="post" name="supnewsyl">
1.371 tempelho 4023: <input type="hidden" name="active" value="ff" />
1.508 raeburn 4024: $pathitem
1.329 droeschl 4025: <input type="hidden" name="importdetail"
4026: value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
1.423 onken 4027: <a class="LC_menubuttons_link" href="javascript:document.supnewsyl.submit()">$lt{'syll'}</a>
1.329 droeschl 4028: $help{'Syllabus'}
4029: </form>
4030: SNSFORM
4031:
4032: my $supnewaboutmeform=(<<SNAMFORM);
1.383 tempelho 4033: <form action="/adm/coursedocs" method="post" name="supnewaboutme">
1.371 tempelho 4034: <input type="hidden" name="active" value="ff" />
1.508 raeburn 4035: $pathitem
1.329 droeschl 4036: <input type="hidden" name="importdetail"
4037: value="$plainname=/adm/$udom/$uname/aboutme" />
1.423 onken 4038: <a class="LC_menubuttons_link" href="javascript:document.supnewaboutme.submit()">$lt{'mypi'}</a>
1.347 weissno 4039: $help{'My Personal Information Page'}
1.329 droeschl 4040: </form>
4041: SNAMFORM
4042:
1.333 muellerd 4043:
1.383 tempelho 4044: my @specialdocs = (
1.417 droeschl 4045: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="document.supnewsyl.submit()" />'
4046: =>$supnewsylform},
4047: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="document.supnewaboutme.submit()" />'
4048: =>$supnewaboutmeform},
1.383 tempelho 4049: );
1.417 droeschl 4050: my @supimportdoc = (
1.515 raeburn 4051: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="javascript:toggleUpload(\'suppext\')" />'
1.501 raeburn 4052: =>$supextform},
4053: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/pdfupload.png" alt="'.$lt{upl}.'" onclick="javascript:toggleUpload(\'suppdoc\');" />'
4054: =>$supupdocform},
4055: );
4056:
4057: $supupdocform = &create_form_ul(&create_list_elements(@supimportdoc));
1.333 muellerd 4058: my %suporderhash = (
1.390 tempelho 4059: '00' => ['Supnewfolder', $supnewfolderform],
1.488 raeburn 4060: 'ee' => ['Import Content',$supupdocform],
1.515 raeburn 4061: 'ff' => ['Special Pages',&create_form_ul(&create_list_elements(@specialdocs))]
1.333 muellerd 4062: );
1.443 www 4063: if ($supplementalflag) {
1.458 raeburn 4064: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.508 raeburn 4065: $supplementalflag,\%suporderhash,$iconpath,$pathitem);
1.443 www 4066: if ($error) {
4067: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
4068: }
1.393 raeburn 4069: }
1.443 www 4070: } elsif ($supplementalflag) {
1.458 raeburn 4071: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.508 raeburn 4072: $supplementalflag,'',$iconpath,$pathitem);
1.393 raeburn 4073: if ($error) {
4074: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.383 tempelho 4075: }
1.393 raeburn 4076: }
1.389 tempelho 4077:
1.510 raeburn 4078: if ($needs_end) {
4079: $r->print(&endContentScreen());
4080: }
1.383 tempelho 4081:
1.329 droeschl 4082: if ($allowed) {
4083: $r->print('
4084: <form method="post" name="extimport" action="/adm/coursedocs">
4085: <input type="hidden" name="title" />
4086: <input type="hidden" name="url" />
4087: <input type="hidden" name="useform" />
4088: <input type="hidden" name="residx" />
4089: </form>');
4090: }
1.484 raeburn 4091: } elsif ($showdoc) {
1.329 droeschl 4092: # -------------------------------------------------------- This is showdoc mode
1.484 raeburn 4093: $r->print("<h1>".&mt('Uploaded Document').' - '.
1.498 bisitz 4094: &Apache::lonnet::gettitle($r->uri).'</h1><p class="LC_warning">'.
1.329 droeschl 4095: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><table>".
1.484 raeburn 4096: &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');
1.329 droeschl 4097: }
4098: }
4099: $r->print(&Apache::loncommon::end_page());
4100: return OK;
1.364 bisitz 4101: }
1.329 droeschl 4102:
1.440 raeburn 4103: sub embedded_form_elems {
4104: my ($phase,$primaryurl,$newidx) = @_;
4105: my $folderpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
4106: return <<STATE;
4107: <input type="hidden" name="folderpath" value="$folderpath" />
4108: <input type="hidden" name="cmd" value="upload_embedded" />
4109: <input type="hidden" name="newidx" value="$newidx" />
4110: <input type="hidden" name="phase" value="$phase" />
4111: <input type="hidden" name="primaryurl" value="$primaryurl" />
4112: STATE
4113: }
4114:
4115: sub embedded_destination {
4116: my $folder=$env{'form.folder'};
4117: my $destination = 'docs/';
4118: if ($folder =~ /^supplemental/) {
4119: $destination = 'supplemental/';
4120: }
4121: if (($folder eq 'default') || ($folder eq 'supplemental')) {
4122: $destination .= 'default/';
4123: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
4124: $destination .= $2.'/';
4125: }
4126: $destination .= $env{'form.newidx'};
4127: my $dir_root = '/userfiles';
4128: return ($destination,$dir_root);
4129: }
4130:
4131: sub return_to_editor {
4132: my $actionurl = '/adm/coursedocs';
4133: return '<p><form name="backtoeditor" method="post" action="'.$actionurl.'" />'."\n".
4134: '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" /></form>'."\n".
4135: '<a href="javascript:document.backtoeditor.submit();">'.&mt('Return to Editor').
4136: '</a></p>';
4137: }
4138:
1.476 raeburn 4139: sub decompression_info {
4140: my ($destination,$dir_root) = &embedded_destination();
4141: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
4142: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
4143: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
4144: my $container='sequence';
1.480 raeburn 4145: my ($pathitem,$hiddenelem);
4146: my @hiddens = ('newidx','comment','position');
1.476 raeburn 4147: if ($env{'form.pagepath'}) {
4148: $container='page';
1.480 raeburn 4149: $pathitem = 'pagepath';
1.476 raeburn 4150: } else {
1.480 raeburn 4151: $pathitem = 'folderpath';
1.476 raeburn 4152: }
1.480 raeburn 4153: unshift(@hiddens,$pathitem);
4154: foreach my $item (@hiddens) {
4155: if ($env{'form.'.$item}) {
4156: $hiddenelem .= '<input type="hidden" name="'.$item.'" value="'.
4157: $env{'form.'.$item}.'" />'."\n";
4158: }
1.477 raeburn 4159: }
1.476 raeburn 4160: return ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,
4161: $hiddenelem);
4162: }
4163:
4164: sub decompression_phase_one {
4165: my ($dir,$file,$warning,$error,$output);
4166: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
4167: &decompression_info();
1.490 raeburn 4168: if ($env{'form.archiveurl'} !~ m{^/uploaded/\Q$docudom/$docuname/\E(?:docs|supplemental)/(?:default|\d+).*/([^/]+)$}) {
1.476 raeburn 4169: $error = &mt('Archive file "[_1]" not in the expected location.',$env{'form.archiveurl'});
4170: } else {
4171: my $file = $1;
1.481 raeburn 4172: $output =
4173: &Apache::loncommon::process_decompression($docudom,$docuname,$file,
4174: $destination,$dir_root,
4175: $hiddenelem);
4176: if ($env{'form.autoextract_camtasia'}) {
4177: $output .= &remove_archive($docudom,$docuname,$container);
4178: }
1.476 raeburn 4179: }
4180: if ($error) {
4181: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
4182: $error.'</p>'."\n";
4183: }
4184: if ($warning) {
4185: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
4186: }
4187: return $output;
4188: }
4189:
4190: sub decompression_phase_two {
4191: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
4192: &decompression_info();
1.481 raeburn 4193: my $output;
1.480 raeburn 4194: if ($env{'form.archivedelete'}) {
1.481 raeburn 4195: $output = &remove_archive($docudom,$docuname,$container);
1.480 raeburn 4196: }
4197: $output .=
1.481 raeburn 4198: &Apache::loncommon::process_extracted_files('coursedocs',$docudom,$docuname,
1.476 raeburn 4199: $destination,$dir_root,$hiddenelem);
4200: return $output;
4201: }
4202:
1.480 raeburn 4203: sub remove_archive {
4204: my ($docudom,$docuname,$container) = @_;
4205: my $map = $env{'form.folder'}.'.'.$container;
1.481 raeburn 4206: my ($output,$delwarning,$delresult,$url);
1.480 raeburn 4207: my ($errtext,$fatal) = &mapread($docuname,$docudom,$map);
4208: if ($fatal) {
4209: if ($container eq 'page') {
4210: $delwarning = &mt('An error occurred retrieving the contents of the current page.');
4211: } else {
4212: $delwarning = &mt('An error occurred retrieving the contents of the current folder.');
4213: }
4214: $delwarning .= &mt('As a result the archive file has not been removed.');
4215: } else {
4216: my $currcmd = $env{'form.cmd'};
4217: my $position = $env{'form.position'};
4218: if ($position > 0) {
4219: $env{'form.cmd'} = 'del_'.$position;
4220: my ($title,$url,@rrest) =
4221: split(/:/,$LONCAPA::map::resources[$LONCAPA::map::order[$position]]);
4222: if (&handle_edit_cmd($docuname,$docudom)) {
1.492 raeburn 4223: ($errtext,$fatal) = &storemap($docuname,$docudom,$map,1);
1.480 raeburn 4224: if ($fatal) {
4225: if ($container eq 'page') {
4226: $delwarning = &mt('An error occurred updating the contents of the current page.');
4227: } else {
4228: $delwarning = &mt('An error occurred updating the contents of the current folder.');
4229: }
4230: } else {
1.481 raeburn 4231: $delresult = &mt('Archive file removed.');
1.480 raeburn 4232: }
4233: }
4234: }
4235: $env{'form.cmd'} = $currcmd;
4236: }
4237: if ($delwarning) {
4238: $output = '<p class="LC_warning">'.
4239: $delwarning.
4240: '</p>';
4241: }
4242: if ($delresult) {
4243: $output .= '<p class="LC_info">'.
4244: $delresult.
4245: '</p>';
4246: }
1.481 raeburn 4247: return $output;
1.480 raeburn 4248: }
4249:
1.484 raeburn 4250: sub generate_admin_menu {
4251: my ($crstype) = @_;
4252: my $lc_crstype = lc($crstype);
4253: my ($home,$other,%outhash)=&authorhosts();
4254: my %lt=&Apache::lonlocal::texthash (
4255: 'vc' => 'Verify Content',
4256: 'cv' => 'Check/Set Resource Versions',
4257: 'ls' => 'List Resource Identifiers',
4258: 'imse' => 'Export contents to IMS Archive',
4259: 'dcd' => "Dump $crstype Content to Authoring Space",
4260: );
4261: my ($candump,$dumpurl);
4262: if ($home + $other > 0) {
4263: $candump = 'F';
4264: if ($home) {
4265: $dumpurl = "javascript:injectData(document.courseverify,'dummy','dumpcourse','$lt{'dcd'}')";
4266: } else {
4267: my @hosts;
4268: foreach my $aurole (keys(%outhash)) {
4269: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
4270: push(@hosts,$outhash{$aurole});
4271: }
4272: }
4273: if (@hosts == 1) {
4274: my $switchto = '/adm/switchserver?otherserver='.$hosts[0].
4275: '&role='.
4276: &HTML::Entities::encode($env{'request.role'},'"<>&').'&origurl='.
4277: &HTML::Entities::encode('/adm/coursedocs?dumpcourse=1','"<>&');
4278: $dumpurl = "javascript:dump_needs_switchserver('$switchto')";
4279: } else {
4280: $dumpurl = "javascript:choose_switchserver_window()";
4281: }
4282: }
4283: }
4284: my @menu=
4285: ({ categorytitle=>'Administration',
4286: items =>[
4287: { linktext => $lt{'vc'},
4288: url => "javascript:injectData(document.courseverify,'dummy','verify','$lt{'vc'}')",
4289: permission => 'F',
4290: help => 'Verify_Content',
4291: icon => 'verify.png',
4292: linktitle => 'Verify contents can be retrieved/rendered',
4293: },
4294: { linktext => $lt{'cv'},
4295: url => "javascript:injectData(document.courseverify,'dummy','versions','$lt{'cv'}')",
4296: permission => 'F',
4297: help => 'Check_Resource_Versions',
4298: icon => 'resversion.png',
4299: linktitle => "View version information for resources in your $lc_crstype, and fix/unfix use of specific versions",
4300: },
4301: { linktext => $lt{'ls'},
4302: url => "javascript:injectData(document.courseverify,'dummy','listsymbs','$lt{'ls'}')",
4303: permission => 'F',
4304: #help => '',
4305: icon => 'symbs.png',
4306: linktitle => "List the unique identifier used for each resource instance in your $lc_crstype"
4307: },
4308: ]
4309: },
4310: { categorytitle=>'Export',
4311: items =>[
4312: { linktext => $lt{'imse'},
4313: url => "javascript:injectData(document.courseverify,'dummy','exportcourse','$lt{'imse'}')",
4314: permission => 'F',
4315: help => 'Docs_Export_Course_Docs',
4316: icon => 'imsexport.png',
4317: linktitle => $lt{'imse'},
4318: },
4319: { linktext => $lt{'dcd'},
4320: url => $dumpurl,
4321: permission => $candump,
4322: #help => '',
4323: icon => 'dump.png',
4324: linktitle => $lt{'dcd'},
4325: },
4326: ]
4327: });
4328: return '<form action="/adm/coursedocs" method="post" name="courseverify">'."\n".
4329: '<input type="hidden" id="dummy" />'."\n".
4330: &Apache::lonhtmlcommon::generate_menu(@menu)."\n".
4331: '</form>';
1.329 droeschl 4332: }
4333:
4334: sub generate_edit_table {
1.484 raeburn 4335: my ($tid,$orderhash_ref,$to_show,$iconpath,$jumpto,$readfile) = @_;
1.406 raeburn 4336: return unless(ref($orderhash_ref) eq 'HASH');
1.342 ehlerst 4337: my %orderhash = %{$orderhash_ref};
1.344 bisitz 4338: my $form;
1.371 tempelho 4339: my $activetab;
4340: my $active;
4341: if($env{'form.active'} ne ''){
4342: $activetab = $env{'form.active'};
4343: }
1.472 raeburn 4344: my $backicon = $iconpath.'clickhere.gif';
1.515 raeburn 4345: my $backtext = &mt('Exit');
1.458 raeburn 4346: $form = '<div class="LC_Box" style="margin:0;">'.
1.488 raeburn 4347: '<ul id="navigation'.$tid.'" class="LC_TabContent">'."\n".
4348: '<li class="goback">'.
4349: '<a href="javascript:toContents('."'$jumpto'".');">'.
4350: '<img src="'.$backicon.'" class="LC_icon" style="border: none; vertical-align: top;"'.
4351: ' alt="'.$backtext.'" />'.$backtext.'</a></li>'."\n".
4352: '<li>'.
4353: '<a href="javascript:groupopen('."'$readfile'".',1);">'.
4354: &mt('Undo Delete').'</a></li>'."\n";
4355: if ($env{'form.docslog'}) {
4356: $form .= '<li class="active">';
4357: } else {
4358: $form .= '<li>';
4359: }
4360: $form .= '<a href="javascript:toggleHistoryDisp(1);">'.
4361: &mt('History').'</a></li>'."\n";
4362: if ($env{'form.docslog'}) {
4363: $form .= '<li><a href="javascript:toggleHistoryDisp(0);">'.
4364: &mt('Edit').'</a></li>'."\n";
1.484 raeburn 4365: }
1.458 raeburn 4366: foreach my $name (reverse(sort(keys(%orderhash)))) {
1.390 tempelho 4367: if($name ne '00'){
1.371 tempelho 4368: if($activetab eq '' || $activetab ne $name){
4369: $active = '';
4370: }elsif($activetab eq $name){
4371: $active = 'class="active"';
4372: }
1.458 raeburn 4373: $form .= '<li style="float:right" '.$active
1.484 raeburn 4374: .' 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 4375: } else {
1.484 raeburn 4376: $form .= '<li '.$active.' style="float:right">'.${$orderhash{$name}}[1].'</li>'."\n";
1.390 tempelho 4377:
4378: }
1.329 droeschl 4379: }
1.484 raeburn 4380: $form .= '</ul>'."\n";
4381: $form .= '<div id="content'.$tid.'" style="padding: 0 0; margin: 0 0; overflow: hidden; clear:right">'."\n";
1.458 raeburn 4382:
4383: if ($to_show ne '') {
1.484 raeburn 4384: $form .= '<div style="padding:0;margin:0;float:left">'.$to_show.'</div>'."\n";
1.458 raeburn 4385: }
1.363 ehlerst 4386: foreach my $field (keys(%orderhash)){
1.390 tempelho 4387: if($field ne '00'){
1.422 onken 4388: if($activetab eq '' || $activetab ne $field){
1.458 raeburn 4389: $active = 'style="display: none;float:left"';
1.422 onken 4390: }elsif($activetab eq $field){
1.458 raeburn 4391: $active = 'style="display:block;float:left"';
1.422 onken 4392: }
4393: $form .= '<div id="'.$field.$tid.'"'
4394: .' class="LC_ContentBox" '.$active.'>'.${$orderhash{$field}}[1]
1.484 raeburn 4395: .'</div>'."\n";
1.363 ehlerst 4396: }
4397: }
1.484 raeburn 4398: unless ($env{'form.docslog'}) {
4399: $form .= '</div></div>'."\n";
4400: }
1.329 droeschl 4401: return $form;
4402: }
4403:
4404: sub editing_js {
1.472 raeburn 4405: my ($udom,$uname,$supplementalflag) = @_;
1.329 droeschl 4406: my $now = time();
4407: my %lt = &Apache::lonlocal::texthash(
4408: p_mnf => 'Name of New Folder',
4409: t_mnf => 'New Folder',
4410: p_mnp => 'Name of New Page',
4411: t_mnp => 'New Page',
1.451 www 4412: p_mxu => 'Title for the External Score',
1.349 biermanm 4413: p_msp => 'Name of Simple Course Page',
1.329 droeschl 4414: p_msb => 'Title for the Problem',
4415: p_mdb => 'Title for the Drop Box',
1.336 schafran 4416: p_mbb => 'Title for the Discussion Board',
1.348 weissno 4417: p_mab => "Enter user:domain for User's Personal Information Page",
1.352 bisitz 4418: p_mab2 => 'Personal Information Page of ',
1.329 droeschl 4419: p_mab_alrt1 => 'Not a valid user:domain',
4420: p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',
4421: p_chn => 'New Title',
4422: p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',
4423: p_rmr2a => 'Remove[_99]',
4424: p_rmr2b => '?[_99]',
4425: p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',
4426: p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',
4427: p_ctr2a => 'Cut[_98]',
1.478 raeburn 4428: p_ctr2b => '?[_98]',
4429: rpck => 'Enter number to pick (e.g., 3)',
1.501 raeburn 4430: imsfile => 'You must choose an IMS package for import',
4431: imscms => 'You must select which Course Management System was the source of the IMS package',
4432: invurl => 'Invalid URL',
4433: titbl => 'Title is blank',
1.329 droeschl 4434: );
4435:
1.433 raeburn 4436: my $crstype = &Apache::loncommon::course_type();
1.434 raeburn 4437: my $docs_folderpath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'},'<>&"');
4438: my $docs_pagepath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.pagepath'},'<>&"');
4439: my $main_container_page;
4440: if ($docs_folderpath eq '') {
4441: if ($docs_pagepath ne '') {
4442: $main_container_page = 1;
4443: }
4444: }
1.433 raeburn 4445: my $toplevelmain = 'default&Main%20'.$crstype.'%20Documents';
1.446 www 4446: my $toplevelsupp = &supplemental_base();
1.433 raeburn 4447:
1.472 raeburn 4448: my $backtourl = '/adm/navmaps';
4449: if ($supplementalflag) {
4450: $backtourl = '/adm/supplemental';
4451: }
4452:
1.501 raeburn 4453: my $fieldsets = "'ext','doc','ims'";
4454: if ($supplementalflag) {
4455: $fieldsets = "'suppext','suppdoc'";
4456: }
4457:
1.329 droeschl 4458: return <<ENDNEWSCRIPT;
4459: function makenewfolder(targetform,folderseq) {
4460: var foldername=prompt('$lt{"p_mnf"}','$lt{"t_mnf"}');
4461: if (foldername) {
4462: targetform.importdetail.value=escape(foldername)+"="+folderseq;
4463: targetform.submit();
4464: }
4465: }
4466:
4467: function makenewpage(targetform,folderseq) {
4468: var pagename=prompt('$lt{"p_mnp"}','$lt{"t_mnp"}');
4469: if (pagename) {
4470: targetform.importdetail.value=escape(pagename)+"="+folderseq;
4471: targetform.submit();
4472: }
4473: }
4474:
4475: function makeexamupload() {
4476: var title=prompt('$lt{"p_mxu"}');
1.344 bisitz 4477: if (title) {
1.329 droeschl 4478: this.document.forms.newexamupload.importdetail.value=
4479: escape(title)+'=/res/lib/templates/examupload.problem';
4480: this.document.forms.newexamupload.submit();
4481: }
4482: }
4483:
4484: function makesmppage() {
4485: var title=prompt('$lt{"p_msp"}');
1.344 bisitz 4486: if (title) {
1.329 droeschl 4487: this.document.forms.newsmppg.importdetail.value=
4488: escape(title)+'=/adm/$udom/$uname/$now/smppg';
4489: this.document.forms.newsmppg.submit();
4490: }
4491: }
4492:
4493: function makesmpproblem() {
4494: var title=prompt('$lt{"p_msb"}');
1.344 bisitz 4495: if (title) {
1.329 droeschl 4496: this.document.forms.newsmpproblem.importdetail.value=
4497: escape(title)+'=/res/lib/templates/simpleproblem.problem';
4498: this.document.forms.newsmpproblem.submit();
4499: }
4500: }
4501:
4502: function makedropbox() {
4503: var title=prompt('$lt{"p_mdb"}');
1.344 bisitz 4504: if (title) {
1.329 droeschl 4505: this.document.forms.newdropbox.importdetail.value=
4506: escape(title)+'=/res/lib/templates/DropBox.problem';
4507: this.document.forms.newdropbox.submit();
4508: }
4509: }
4510:
4511: function makebulboard() {
4512: var title=prompt('$lt{"p_mbb"}');
4513: if (title) {
4514: this.document.forms.newbul.importdetail.value=
4515: escape(title)+'=/adm/$udom/$uname/$now/bulletinboard';
4516: this.document.forms.newbul.submit();
4517: }
4518: }
4519:
4520: function makeabout() {
4521: var user=prompt("$lt{'p_mab'}");
4522: if (user) {
4523: var comp=new Array();
4524: comp=user.split(':');
4525: if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
4526: if ((comp[0]) && (comp[1])) {
4527: this.document.forms.newaboutsomeone.importdetail.value=
4528: '$lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
1.335 ehlerst 4529: this.document.forms.newaboutsomeone.submit();
4530: } else {
4531: alert("$lt{'p_mab_alrt1'}");
1.329 droeschl 4532: }
1.335 ehlerst 4533: } else {
4534: alert("$lt{'p_mab_alrt2'}");
4535: }
4536: }
1.329 droeschl 4537: }
4538:
1.501 raeburn 4539: function toggleUpload(caller) {
4540: var blocks = Array($fieldsets);
4541: for (var i=0; i<blocks.length; i++) {
4542: var disp = 'none';
4543: if (caller == blocks[i]) {
4544: var curr = document.getElementById('upload'+caller+'form').style.display;
4545: if (curr == 'none') {
4546: disp='block';
4547: }
4548: }
4549: document.getElementById('upload'+blocks[i]+'form').style.display=disp;
4550: }
1.502 raeburn 4551: resize_scrollbox('contentscroll','1','1');
4552: return;
4553: }
4554:
1.514 raeburn 4555: function toggleMap(caller) {
1.502 raeburn 4556: var disp = 'none';
1.510 raeburn 4557: if (document.getElementById('importmapform')) {
1.514 raeburn 4558: if (caller == 'map') {
4559: var curr = document.getElementById('importmapform').style.display;
4560: if (curr == 'none') {
4561: disp='block';
4562: }
1.510 raeburn 4563: }
4564: document.getElementById('importmapform').style.display=disp;
4565: resize_scrollbox('contentscroll','1','1');
1.502 raeburn 4566: }
1.501 raeburn 4567: return;
1.329 droeschl 4568: }
4569:
1.501 raeburn 4570: function makeims(imsform) {
4571: if ((imsform.uploaddoc.value == '') || (!imsform.uploaddoc.value)) {
4572: alert("$lt{'imsfile'}");
4573: return;
4574: }
4575: if (imsform.source.selectedIndex == 0) {
4576: alert("$lt{'imscms'}");
4577: return;
4578: }
4579: newWindow = window.open('', 'IMSimport',"HEIGHT=700,WIDTH=750,scrollbars=yes");
4580: imsform.submit();
4581: }
4582:
1.329 droeschl 4583: function changename(folderpath,index,oldtitle,container,pagesymb) {
1.335 ehlerst 4584: var title=prompt('$lt{"p_chn"}',oldtitle);
4585: if (title) {
4586: this.document.forms.renameform.markcopy.value=-1;
4587: this.document.forms.renameform.title.value=title;
4588: this.document.forms.renameform.cmd.value='rename_'+index;
4589: if (container == 'sequence') {
4590: this.document.forms.renameform.folderpath.value=folderpath;
4591: }
4592: if (container == 'page') {
4593: this.document.forms.renameform.pagepath.value=folderpath;
4594: this.document.forms.renameform.pagesymb.value=pagesymb;
4595: }
4596: this.document.forms.renameform.submit();
4597: }
1.329 droeschl 4598: }
4599:
4600: function removeres(folderpath,index,oldtitle,container,pagesymb,skip_confirm) {
1.335 ehlerst 4601: if (skip_confirm || confirm('$lt{"p_rmr1"}\\n\\n$lt{"p_rmr2a"} "'+oldtitle+'" $lt{"p_rmr2b"}')) {
4602: this.document.forms.renameform.markcopy.value=-1;
4603: this.document.forms.renameform.cmd.value='del_'+index;
4604: if (container == 'sequence') {
4605: this.document.forms.renameform.folderpath.value=folderpath;
4606: }
4607: if (container == 'page') {
4608: this.document.forms.renameform.pagepath.value=folderpath;
4609: this.document.forms.renameform.pagesymb.value=pagesymb;
4610: }
4611: this.document.forms.renameform.submit();
4612: }
1.329 droeschl 4613: }
4614:
4615: function cutres(folderpath,index,oldtitle,container,pagesymb,folder,skip_confirm) {
1.335 ehlerst 4616: if (skip_confirm || confirm('$lt{"p_ctr1a"}\\n$lt{"p_ctr1b"}\\n\\n$lt{"p_ctr2a"} "'+oldtitle+'" $lt{"p_ctr2b"}')) {
4617: this.document.forms.renameform.cmd.value='cut_'+index;
4618: this.document.forms.renameform.markcopy.value=index;
4619: this.document.forms.renameform.copyfolder.value=folder+'.'+container;
4620: if (container == 'sequence') {
4621: this.document.forms.renameform.folderpath.value=folderpath;
4622: }
4623: if (container == 'page') {
4624: this.document.forms.renameform.pagepath.value=folderpath;
4625: this.document.forms.renameform.pagesymb.value=pagesymb;
4626: }
4627: this.document.forms.renameform.submit();
4628: }
1.329 droeschl 4629: }
4630:
4631: function markcopy(folderpath,index,oldtitle,container,pagesymb,folder) {
1.335 ehlerst 4632: this.document.forms.renameform.markcopy.value=index;
4633: this.document.forms.renameform.copyfolder.value=folder+'.'+container;
4634: if (container == 'sequence') {
4635: this.document.forms.renameform.folderpath.value=folderpath;
4636: }
4637: if (container == 'page') {
4638: this.document.forms.renameform.pagepath.value=folderpath;
4639: this.document.forms.renameform.pagesymb.value=pagesymb;
4640: }
4641: this.document.forms.renameform.submit();
1.329 droeschl 4642: }
4643:
1.478 raeburn 4644: function updatePick(targetform,index,caller) {
4645: var pickitem = document.getElementById('rpick_'+index);
4646: var picknumitem = document.getElementById('rpicknum_'+index);
4647: if (pickitem.checked) {
4648: var picknum=prompt('$lt{"rpck"}',picknumitem.value);
4649: if (picknum == '' || picknum == null) {
4650: if (caller == 'check') {
4651: pickitem.checked=false;
4652: return;
4653: }
4654: } else {
4655: picknum.toString();
4656: var regexdigit=/^\\d+\$/;
4657: if (regexdigit.test(picknum)) {
4658: picknumitem.value = picknum;
4659: targetform.changeparms.value='randompick';
4660: targetform.submit();
4661: } else {
4662: if (caller == 'check') {
4663: pickitem.checked=false;
4664: }
4665: return;
4666: }
4667: }
4668: } else {
4669: picknumitem.value = 0;
4670: targetform.changeparms.value='randompick';
4671: targetform.submit();
4672: }
4673: }
4674:
1.334 muellerd 4675: function unselectInactive(nav) {
1.335 ehlerst 4676: currentNav = document.getElementById(nav);
4677: currentLis = currentNav.getElementsByTagName('LI');
4678: for (i = 0; i < currentLis.length; i++) {
1.472 raeburn 4679: if (currentLis[i].className == 'goback') {
4680: currentLis[i].className = 'goback';
4681: } else {
4682: if (currentLis[i].className == 'right active' || currentLis[i].className == 'right') {
1.374 tempelho 4683: currentLis[i].className = 'right';
1.472 raeburn 4684: } else {
1.374 tempelho 4685: currentLis[i].className = 'i';
1.472 raeburn 4686: }
4687: }
1.335 ehlerst 4688: }
1.332 tempelho 4689: }
4690:
1.334 muellerd 4691: function hideAll(current, nav, data) {
1.335 ehlerst 4692: unselectInactive(nav);
1.374 tempelho 4693: if(current.className == 'right'){
4694: current.className = 'right active'
4695: }else{
4696: current.className = 'active';
4697: }
1.335 ehlerst 4698: currentData = document.getElementById(data);
4699: currentDivs = currentData.getElementsByTagName('DIV');
4700: for (i = 0; i < currentDivs.length; i++) {
4701: if(currentDivs[i].className == 'LC_ContentBox'){
1.333 muellerd 4702: currentDivs[i].style.display = 'none';
1.330 tempelho 4703: }
4704: }
1.335 ehlerst 4705: }
1.330 tempelho 4706:
1.374 tempelho 4707: function openTabs(pageId) {
4708: tabnav = document.getElementById(pageId).getElementsByTagName('UL');
1.383 tempelho 4709: if(tabnav.length > 2 ){
1.389 tempelho 4710: currentNav = document.getElementById(tabnav[1].id);
1.374 tempelho 4711: currentLis = currentNav.getElementsByTagName('LI');
4712: for(i = 0; i< currentLis.length; i++){
4713: if(currentLis[i].className == 'active') {
1.375 tempelho 4714: funcString = currentLis[i].onclick.toString();
4715: tab = funcString.split('"');
1.420 onken 4716: if(tab.length < 2) {
4717: tab = funcString.split("'");
4718: }
1.375 tempelho 4719: currentData = document.getElementById(tab[1]);
4720: currentData.style.display = 'block';
1.374 tempelho 4721: }
4722: }
4723: }
4724: }
4725:
1.334 muellerd 4726: function showPage(current, pageId, nav, data) {
4727: hideAll(current, nav, data);
1.375 tempelho 4728: openTabs(pageId);
1.334 muellerd 4729: unselectInactive(nav);
1.330 tempelho 4730: current.className = 'active';
4731: currentData = document.getElementById(pageId);
4732: currentData.style.display = 'block';
1.458 raeburn 4733: activeTab = pageId;
1.501 raeburn 4734: toggleUpload();
1.503 raeburn 4735: toggleMap();
1.433 raeburn 4736: if (nav == 'mainnav') {
4737: var storedpath = "$docs_folderpath";
4738: if (storedpath == '') {
4739: storedpath = "$docs_pagepath";
4740: }
1.434 raeburn 4741: var storedpage = "$main_container_page";
1.433 raeburn 4742: var reg = new RegExp("^supplemental");
4743: if (pageId == 'mainCourseDocuments') {
1.434 raeburn 4744: if (storedpage == 1) {
4745: document.simpleedit.folderpath.value = '';
4746: document.uploaddocument.folderpath.value = '';
4747: } else {
4748: if (reg.test(storedpath)) {
4749: document.simpleedit.folderpath.value = '$toplevelmain';
4750: document.uploaddocument.folderpath.value = '$toplevelmain';
4751: document.newext.folderpath.value = '$toplevelmain';
4752: } else {
4753: document.simpleedit.folderpath.value = storedpath;
4754: document.uploaddocument.folderpath.value = storedpath;
4755: document.newext.folderpath.value = storedpath;
4756: }
1.433 raeburn 4757: }
4758: } else {
1.434 raeburn 4759: if (reg.test(storedpath)) {
4760: document.simpleedit.folderpath.value = storedpath;
4761: document.supuploaddocument.folderpath.value = storedpath;
4762: document.supnewext.folderpath.value = storedpath;
4763: } else {
1.433 raeburn 4764: document.simpleedit.folderpath.value = '$toplevelsupp';
4765: document.supuploaddocument.folderpath.value = '$toplevelsupp';
4766: document.supnewext.folderpath.value = '$toplevelsupp';
4767: }
4768: }
4769: }
1.485 raeburn 4770: resize_scrollbox('contentscroll','1','0');
1.330 tempelho 4771: return false;
4772: }
1.329 droeschl 4773:
1.472 raeburn 4774: function toContents(jumpto) {
4775: var newurl = '$backtourl';
4776: if (jumpto != '') {
4777: newurl = newurl+'?postdata='+jumpto;
4778: ;
4779: }
4780: location.href=newurl;
4781: }
4782:
1.329 droeschl 4783: ENDNEWSCRIPT
4784: }
1.457 raeburn 4785:
1.483 raeburn 4786: sub history_tab_js {
4787: return <<"ENDHIST";
4788: function toggleHistoryDisp(choice) {
4789: document.docslogform.docslog.value = choice;
4790: document.docslogform.submit();
4791: return;
4792: }
4793:
4794: ENDHIST
4795: }
4796:
1.484 raeburn 4797: sub inject_data_js {
4798: return <<ENDINJECT;
4799:
4800: function injectData(current, hiddenField, name, value) {
4801: currentElement = document.getElementById(hiddenField);
4802: currentElement.name = name;
4803: currentElement.value = value;
4804: current.submit();
4805: }
4806:
4807: ENDINJECT
4808: }
4809:
4810: sub dump_switchserver_js {
4811: my @hosts = @_;
4812: my %lt = &Apache::lonlocal::texthash(
4813: dump => 'Dumping to Authoring Space requires switching server.',
4814: swit => 'Switch server?',
4815: duco => 'Dump content to Authoring Space',
4816: yone => 'You need to switch to a server housing an Authoring Space for which you are author or co-author.',
4817: chos => 'Choose server',
4818: );
4819: my $role = $env{'request.role'};
4820: my $js = <<"ENDSWJS";
4821: <script type="text/javascript">
4822: function write_switchserver() {
4823: var server;
4824: if (document.setserver.posshosts.length > 0) {
4825: for (var i=0; i<document.setserver.posshosts.length; i++) {
4826: if (document.setserver.posshosts[i].checked) {
4827: server = document.setserver.posshosts[i].value;
4828: }
4829: }
4830: opener.document.location.href="/adm/switchserver?otherserver="+server+"&role=$role&origurl=/adm/coursedocs";
4831: }
4832: window.close();
4833: }
4834: </script>
4835:
4836: ENDSWJS
4837:
4838: my $startpage = &Apache::loncommon::start_page('Choose server',$js,
4839: {'only_body' => 1,
4840: 'js_ready' => 1,});
4841: my $endpage = &Apache::loncommon::end_page({'js_ready' => 1});
4842:
4843: my $hostpicker;
4844: my $count = 0;
4845: foreach my $host (sort(@hosts)) {
4846: my $checked;
4847: if ($count == 0) {
4848: $checked = ' checked="checked"';
4849: }
4850: $hostpicker .= '<label><input type="radio" name="posshosts" value="'.
4851: $host.'"'.$checked.' />'.$host.'</label> ';
4852: $count++;
4853: }
4854:
4855: return <<"ENDSWITCHJS";
4856:
4857: function dump_needs_switchserver(url) {
4858: if (url!='' && url!= null) {
4859: if (confirm("$lt{'dump'}\\n$lt{'swit'}")) {
4860: go(url);
4861: }
4862: }
4863: return;
4864: }
4865:
4866: function choose_switchserver_window() {
4867: newWindow = window.open('','ChooseServer','height=400,width=500,scrollbars=yes')
4868: newWindow.document.open();
4869: newWindow.document.writeln('$startpage');
4870: newWindow.document.write('<h3>$lt{'duco'}<\\/h3>\\n'+
4871: '<p>$lt{'yone'}<\\/p>\\n'+
4872: '<div class="LC_left_float"><fieldset><legend>$lt{'chos'}<\\/legend>\\n'+
4873: '<form name="setserver" method="post" action="" \\/>\\n'+
4874: '$hostpicker\\n'+
4875: '<br \\/><br \\/>\\n'+
4876: '<input type="button" name="makeswitch" value="$lt{'swit'}" '+
4877: 'onclick="write_switchserver();" \\/>\\n'+
4878: '<\\/form><\\/fieldset><\\/div><br clear="all" \\/>\\n');
4879: newWindow.document.writeln('$endpage');
4880: newWindow.document.close();
4881: newWindow.focus();
4882: }
4883:
4884: ENDSWITCHJS
4885: }
4886:
4887: sub makedocslogform {
4888: my ($formelems,$docslog) = @_;
4889: return <<"LOGSFORM";
4890: <form action="/adm/coursedocs" method="post" name="docslogform">
4891: <input type="hidden" name="docslog" value="$docslog" />
4892: $formelems
4893: </form>
4894: LOGSFORM
4895: }
4896:
4897: sub makesimpleeditform {
4898: my ($formelems) = @_;
4899: return <<"SIMPFORM";
4900: <form name="simpleedit" method="post" action="/adm/coursedocs">
4901: <input type="hidden" name="importdetail" value="" />
4902: $formelems
4903: </form>
4904: SIMPFORM
4905: }
4906:
1.329 droeschl 4907: 1;
4908: __END__
4909:
4910:
4911: =head1 NAME
4912:
4913: Apache::londocs.pm
4914:
4915: =head1 SYNOPSIS
4916:
4917: This is part of the LearningOnline Network with CAPA project
4918: described at http://www.lon-capa.org.
4919:
4920: =head1 SUBROUTINES
4921:
4922: =over
4923:
4924: =item %help=()
4925:
4926: Available help topics
4927:
4928: =item mapread()
4929:
1.344 bisitz 4930: Mapread read maps into LONCAPA::map:: global arrays
1.329 droeschl 4931: @order and @resources, determines status
4932: sets @order - pointer to resources in right order
4933: sets @resources - array with the resources with correct idx
4934:
4935: =item authorhosts()
4936:
4937: Return hash with valid author names
4938:
4939: =item clean()
4940:
4941: =item dumpcourse()
4942:
4943: Actually dump course
4944:
4945: =item group_import()
4946:
4947: Imports the given (name, url) resources into the course
4948: coursenum, coursedom, and folder must precede the list
4949:
4950: =item breadcrumbs()
4951:
4952: =item log_docs()
4953:
4954: =item docs_change_log()
4955:
4956: =item update_paste_buffer()
4957:
4958: =item print_paste_buffer()
4959:
4960: =item do_paste_from_buffer()
4961:
1.492 raeburn 4962: =item get_newmap_url()
4963:
4964: =item dbcopy()
4965:
4966: =item uniqueness_check()
4967:
4968: =item contained_map_check()
4969:
4970: =item reinit_role()
4971:
4972: =item url_paste_fixups()
4973:
4974: =item apply_fixups()
4975:
4976: =item copy_dependencies()
4977:
1.329 droeschl 4978: =item update_parameter()
4979:
4980: =item handle_edit_cmd()
4981:
4982: =item editor()
4983:
4984: =item process_file_upload()
4985:
4986: =item process_secondary_uploads()
4987:
4988: =item is_supplemental_title()
4989:
4990: =item entryline()
4991:
4992: =item tiehash()
4993:
4994: =item untiehash()
4995:
4996: =item checkonthis()
4997:
4998: check on this
4999:
5000: =item verifycontent()
5001:
5002: Verify Content
5003:
5004: =item devalidateversioncache() & checkversions()
5005:
5006: Check Versions
5007:
5008: =item mark_hash_old()
5009:
5010: =item is_hash_old()
5011:
5012: =item changewarning()
5013:
5014: =item init_breadcrumbs()
5015:
5016: Breadcrumbs for special functions
5017:
1.484 raeburn 5018: =item create_list_elements()
5019:
5020: =item create_form_ul()
5021:
5022: =item startContentScreen()
5023:
5024: =item endContentScreen()
5025:
5026: =item supplemental_base()
5027:
5028: =item embedded_form_elems()
5029:
5030: =item embedded_destination()
5031:
5032: =item return_to_editor()
5033:
5034: =item decompression_info()
5035:
5036: =item decompression_phase_one()
5037:
5038: =item decompression_phase_two()
5039:
5040: =item remove_archive()
5041:
5042: =item generate_admin_menu()
5043:
5044: =item generate_edit_table()
5045:
5046: =item editing_js()
5047:
5048: =item history_tab_js()
5049:
5050: =item inject_data_js()
5051:
5052: =item dump_switchserver_js()
5053:
1.485 raeburn 5054: =item resize_scrollbox_js()
1.484 raeburn 5055:
5056: =item makedocslogform()
5057:
1.485 raeburn 5058: =item makesimpleeditform()
5059:
1.329 droeschl 5060: =back
5061:
5062: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>