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