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