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