File:
[LON-CAPA] /
loncom /
interface /
londocs.pm
Revision
1.485:
download - view:
text,
annotated -
select for diffs
Wed May 9 19:46:30 2012 UTC (12 years, 3 months ago) by
raeburn
Branches:
MAIN
CVS tags:
HEAD
- Code used to resize scrollbox containing contents list for Content Editor
generalized, and moved from londocs.pm to lonhtmlcommon.pm to facilitate
re-use.
- In lonhtmlcommon.pm
- &start_pick_box() and &topic_bar() have additional
optional args which allow id to be passed to corresponding table or div.
- In lonparmset.pm
- javascript used to toggle visibility of mapmenu depending on choice of
level moved to routine: &showhide_js() so it can be used for both:
Table mode and Overview mode (new + existing).
1: # The LearningOnline Network
2: # Documents
3: #
4: # $Id: londocs.pm,v 1.485 2012/05/09 19:46:30 raeburn Exp $
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;
36: use Apache::lonhtmlcommon;
37: use LONCAPA::map();
38: use Apache::lonratedt();
39: use Apache::lonxml;
40: use Apache::lonclonecourse;
41: use Apache::lonnavmaps;
42: use Apache::lonnavdisplay();
43: use HTML::Entities;
44: use GDBM_File;
45: use Apache::lonlocal;
46: use Cwd;
47: use LONCAPA qw(:DEFAULT :match);
48:
49: my $iconpath;
50:
51: my %hash;
52:
53: my $hashtied;
54: my %alreadyseen=();
55:
56: my $hadchanges;
57:
58:
59: my %help=();
60:
61:
62: sub mapread {
63: my ($coursenum,$coursedom,$map)=@_;
64: return
65: &LONCAPA::map::mapread('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
66: $map);
67: }
68:
69: sub storemap {
70: my ($coursenum,$coursedom,$map)=@_;
71: my ($outtext,$errtext)=
72: &LONCAPA::map::storemap('/uploaded/'.$coursedom.'/'.$coursenum.'/'.
73: $map,1);
74: if ($errtext) { return ($errtext,2); }
75:
76: $hadchanges=1;
77: return ($errtext,0);
78: }
79:
80:
81:
82: sub authorhosts {
83: my %outhash=();
84: my $home=0;
85: my $other=0;
86: foreach my $key (keys(%env)) {
87: if ($key=~/^user\.role\.(au|ca)\.(.+)$/) {
88: my $role=$1;
89: my $realm=$2;
90: my ($start,$end)=split(/\./,$env{$key});
91: if (($start) && ($start>time)) { next; }
92: if (($end) && (time>$end)) { next; }
93: my ($ca,$cd);
94: if ($1 eq 'au') {
95: $ca=$env{'user.name'};
96: $cd=$env{'user.domain'};
97: } else {
98: ($cd,$ca)=($realm=~/^\/($match_domain)\/($match_username)$/);
99: }
100: my $allowed=0;
101: my $myhome=&Apache::lonnet::homeserver($ca,$cd);
102: my @ids=&Apache::lonnet::current_machine_ids();
103: foreach my $id (@ids) {
104: if ($id eq $myhome) {
105: $allowed=1;
106: last;
107: }
108: }
109: if ($allowed) {
110: $home++;
111: $outhash{'home_'.$ca.':'.$cd}=1;
112: } else {
113: $outhash{'otherhome_'.$ca.':'.$cd}=$myhome;
114: $other++;
115: }
116: }
117: }
118: return ($home,$other,%outhash);
119: }
120:
121:
122: sub clean {
123: my ($title)=@_;
124: $title=~s/[^\w\/\!\$\%\^\*\-\_\=\+\;\:\,\\\|\`\~]+/\_/gs;
125: return $title;
126: }
127:
128:
129:
130: sub dumpcourse {
131: my ($r) = @_;
132: my $crstype = &Apache::loncommon::course_type();
133: $r->print(&Apache::loncommon::start_page('Dump '.$crstype.' Content to Authoring Space')."\n".
134: &Apache::lonhtmlcommon::breadcrumbs('Dump '.$crstype.' Content to Authoring Space')."\n");
135: $r->print(&startContentScreen('tools'));
136: my ($home,$other,%outhash)=&authorhosts();
137: unless ($home) {
138: $r->print(&endContentScreen());
139: return '';
140: }
141: my $origcrsid=$env{'request.course.id'};
142: my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid);
143: if (($env{'form.authorspace'}) && ($env{'form.authorfolder'}=~/\w/)) {
144: # Do the dumping
145: unless ($outhash{'home_'.$env{'form.authorspace'}}) {
146: $r->print(&endContentScreen());
147: return '';
148: }
149: my ($ca,$cd)=split(/\@/,$env{'form.authorspace'});
150: $r->print('<h3>'.&mt('Copying Files').'</h3>');
151: my $title=$env{'form.authorfolder'};
152: $title=&clean($title);
153: my %replacehash=();
154: foreach my $key (keys(%env)) {
155: if ($key=~/^form\.namefor\_(.+)/) {
156: $replacehash{$1}=$env{$key};
157: }
158: }
159: my $crs='/uploaded/'.$env{'request.course.id'}.'/';
160: $crs=~s/\_/\//g;
161: foreach my $item (keys(%replacehash)) {
162: my $newfilename=$title.'/'.$replacehash{$item};
163: $newfilename=~s/\.(\w+)$//;
164: my $ext=$1;
165: $newfilename=&clean($newfilename);
166: $newfilename.='.'.$ext;
167: my @dirs=split(/\//,$newfilename);
168: my $path=$r->dir_config('lonDocRoot')."/priv/$cd/$ca";
169: my $makepath=$path;
170: my $fail=0;
171: for (my $i=0;$i<$#dirs;$i++) {
172: $makepath.='/'.$dirs[$i];
173: unless (-e $makepath) {
174: unless(mkdir($makepath,0777)) { $fail=1; }
175: }
176: }
177: $r->print('<br /><tt>'.$item.'</tt> => <tt>'.$newfilename.'</tt>: ');
178: if (my $fh=Apache::File->new('>'.$path.'/'.$newfilename)) {
179: if ($item=~/\.(sequence|page|html|htm|xml|xhtml)$/) {
180: print $fh &Apache::lonclonecourse::rewritefile(
181: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item),
182: (%replacehash,$crs => '')
183: );
184: } else {
185: print $fh
186: &Apache::lonclonecourse::readfile($env{'request.course.id'},$item);
187: }
188: $fh->close();
189: } else {
190: $fail=1;
191: }
192: if ($fail) {
193: $r->print('<span class="LC_error">'.&mt('fail').'</span>');
194: } else {
195: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
196: }
197: }
198: } else {
199: $r->print(&mt('Searching ...').'<br />');
200: $r->rflush();
201: # Input form
202: $r->print('<form name="dumpdoc" action="" method="post">'."\n");
203: unless ($home==1) {
204: $r->print('<div class="LC_left_float">'.
205: '<fieldset><legend>'.
206: &mt('Select the Authoring Space').
207: '</legend><select name="authorspace">');
208: }
209: foreach my $key (sort(keys(%outhash))) {
210: if ($key=~/^home_(.+)$/) {
211: if ($home==1) {
212: $r->print(
213: '<input type="hidden" name="authorspace" value="'.$1.'" />');
214: } else {
215: $r->print('<option value="'.$1.'">'.$1.' - '.
216: &Apache::loncommon::plainname(split(/\:/,$1)).'</option>');
217: }
218: }
219: }
220: unless ($home==1) {
221: $r->print('</select></fieldset></div>'."\n");
222: }
223: my $title=$origcrsdata{'description'};
224: $title=~s/[\/\s]+/\_/gs;
225: $title=&clean($title);
226: $r->print('<div class="LC_left_float">'.
227: '<fieldset><legend>'.&mt('Folder in Authoring Space').'</legend>'.
228: '<input type="text" size="50" name="authorfolder" value="'.
229: $title.'" />'.
230: '</fieldset></div><br clear="all" />'."\n");
231: &tiehash();
232: $r->print('<h4>'.&mt('Filenames in Authoring Space').'</h4>'
233: .&Apache::loncommon::start_data_table()
234: .&Apache::loncommon::start_data_table_header_row()
235: .'<th>'.&mt('Internal Filename').'</th>'
236: .'<th>'.&mt('Title').'</th>'
237: .'<th>'.&mt('Save as ...').'</th>'
238: .&Apache::loncommon::end_data_table_header_row());
239: foreach my $file (&Apache::lonclonecourse::crsdirlist($origcrsid,'userfiles')) {
240: $r->print(&Apache::loncommon::start_data_table_row()
241: .'<td>'.$file.'</td>');
242: my ($ext)=($file=~/\.(\w+)$/);
243: my $title=$hash{'title_'.$hash{
244: 'ids_/uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'.$file}};
245: $r->print('<td>'.($title?$title:' ').'</td>');
246: if (!$title) {
247: $title=$file;
248: } else {
249: $title=~s|/|_|g;
250: }
251: $title=~s/\.(\w+)$//;
252: $title=&clean($title);
253: $title.='.'.$ext;
254: $r->print("\n<td><input type='text' size='60' name='namefor_".$file."' value='".$title."' /></td>"
255: .&Apache::loncommon::end_data_table_row());
256: }
257: $r->print(&Apache::loncommon::end_data_table());
258: &untiehash();
259: $r->print(
260: '<p><input type="submit" name="dumpcourse" value="'.&mt("Dump $crstype Content").'" /></p></form>');
261: }
262: $r->print(&endContentScreen());
263: }
264:
265: sub group_import {
266: my ($coursenum, $coursedom, $folder, $container, $caller, @files) = @_;
267:
268: while (@files) {
269: my ($name, $url, $residx) = @{ shift(@files) };
270: if (($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$})
271: && ($caller eq 'londocs')
272: && (!&Apache::lonnet::stat_file($url))) {
273:
274: my $errtext = '';
275: my $fatal = 0;
276: my $newmapstr = '<map>'."\n".
277: '<resource id="1" src="" type="start"></resource>'."\n".
278: '<link from="1" to="2" index="1"></link>'."\n".
279: '<resource id="2" src="" type="finish"></resource>'."\n".
280: '</map>';
281: $env{'form.output'}=$newmapstr;
282: my $result=&Apache::lonnet::finishuserfileupload($coursenum,$coursedom,
283: 'output',$1.$2);
284: if ($result != m|^/uploaded/|) {
285: $errtext.='Map not saved: A network error occurred when trying to save the new map. ';
286: $fatal = 2;
287: }
288: if ($fatal) {
289: return ($errtext,$fatal);
290: }
291: }
292: if ($url) {
293: if (!$residx
294: || defined($LONCAPA::map::zombies[$residx])) {
295: $residx = &LONCAPA::map::getresidx($url,$residx);
296: push(@LONCAPA::map::order, $residx);
297: }
298: my $ext = 'false';
299: if ($url=~m{^http://} || $url=~m{^https://}) { $ext = 'true'; }
300: $url = &LONCAPA::map::qtunescape($url);
301: $name = &LONCAPA::map::qtunescape($name);
302: $LONCAPA::map::resources[$residx] =
303: join(':', ($name, $url, $ext, 'normal', 'res'));
304: }
305: }
306: return &storemap($coursenum, $coursedom, $folder.'.'.$container);
307: }
308:
309: sub breadcrumbs {
310: my ($allowed,$crstype)=@_;
311: &Apache::lonhtmlcommon::clear_breadcrumbs();
312: my (@folders);
313: if ($env{'form.pagepath'}) {
314: @folders = split('&',$env{'form.pagepath'});
315: } else {
316: @folders=split('&',$env{'form.folderpath'});
317: }
318: my $folderpath;
319: my $cpinfo='';
320: my $plain='';
321: my $randompick=-1;
322: my $isencrypted=0;
323: my $ishidden=0;
324: my $is_random_order=0;
325: while (@folders) {
326: my $folder=shift(@folders);
327: my $foldername=shift(@folders);
328: if ($folderpath) {$folderpath.='&';}
329: $folderpath.=$folder.'&'.$foldername;
330: my $url;
331: if ($allowed) {
332: $url = '/adm/coursedocs?folderpath=';
333: } else {
334: $url = '/adm/supplemental?folderpath=';
335: }
336: $url .= &escape($folderpath);
337: my $name=&unescape($foldername);
338: # randompick number, hidden, encrypted, random order, is appended with ":"s to the foldername
339: $name=~s/\:(\d*)\:(\w*)\:(\w*):(\d*)$//;
340: if ($1 ne '') {
341: $randompick=$1;
342: } else {
343: $randompick=-1;
344: }
345: if ($2) { $ishidden=1; }
346: if ($3) { $isencrypted=1; }
347: if ($4 ne '') { $is_random_order = 1; }
348: if ($folder eq 'supplemental') {
349: $name = &mt('Supplemental '.$crstype.' Content');
350: }
351: &Apache::lonhtmlcommon::add_breadcrumb(
352: {'href'=>$url.$cpinfo,
353: 'title'=>$name,
354: 'text'=>$name,
355: 'no_mt'=>1,
356: });
357: $plain.=$name.' > ';
358: }
359: $plain=~s/\>\;\s*$//;
360: return (&Apache::lonhtmlcommon::breadcrumbs(undef,undef,0,'nohelp',
361: undef, undef, 1 ),$randompick,$ishidden,
362: $isencrypted,$plain,$is_random_order);
363: }
364:
365: sub log_docs {
366: return &Apache::lonnet::instructor_log('docslog',@_);
367: }
368:
369: {
370: my @oldresources=();
371: my @oldorder=();
372: my $parmidx;
373: my %parmaction=();
374: my %parmvalue=();
375: my $changedflag;
376:
377: sub snapshotbefore {
378: @oldresources=@LONCAPA::map::resources;
379: @oldorder=@LONCAPA::map::order;
380: $parmidx=undef;
381: %parmaction=();
382: %parmvalue=();
383: $changedflag=0;
384: }
385:
386: sub remember_parms {
387: my ($idx,$parameter,$action,$value)=@_;
388: $parmidx=$idx;
389: $parmaction{$parameter}=$action;
390: $parmvalue{$parameter}=$value;
391: $changedflag=1;
392: }
393:
394: sub log_differences {
395: my ($plain)=@_;
396: my %storehash=('folder' => $plain,
397: 'currentfolder' => $env{'form.folder'});
398: if ($parmidx) {
399: $storehash{'parameter_res'}=$oldresources[$parmidx];
400: foreach my $parm (keys(%parmaction)) {
401: $storehash{'parameter_action_'.$parm}=$parmaction{$parm};
402: $storehash{'parameter_value_'.$parm}=$parmvalue{$parm};
403: }
404: }
405: my $maxidx=$#oldresources;
406: if ($#LONCAPA::map::resources>$#oldresources) {
407: $maxidx=$#LONCAPA::map::resources;
408: }
409: for (my $idx=0; $idx<=$maxidx; $idx++) {
410: if ($LONCAPA::map::resources[$idx] ne $oldresources[$idx]) {
411: $storehash{'before_resources_'.$idx}=$oldresources[$idx];
412: $storehash{'after_resources_'.$idx}=$LONCAPA::map::resources[$idx];
413: $changedflag=1;
414: }
415: if ($LONCAPA::map::order[$idx] ne $oldorder[$idx]) {
416: $storehash{'before_order_res_'.$idx}=$oldresources[$oldorder[$idx]];
417: $storehash{'after_order_res_'.$idx}=$LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
418: $changedflag=1;
419: }
420: }
421: $storehash{'maxidx'}=$maxidx;
422: if ($changedflag) { &log_docs(\%storehash); }
423: }
424: }
425:
426: sub docs_change_log {
427: my ($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath)=@_;
428: my $js = '<script type="text/javascript">'."\n".
429: '// <![CDATA['."\n".
430: &Apache::loncommon::display_filter_js('docslog')."\n".
431: &history_tab_js()."\n".
432: &Apache::lonratedt::editscript('simple')."\n".
433: '// ]]>'."\n".
434: '</script>'."\n";
435: $r->print(&Apache::loncommon::start_page('Content Change Log',$js));
436: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Change Log'));
437: $r->print(&startContentScreen('docs'));
438: my %orderhash;
439: my $container='sequence';
440: my $pathitem;
441: if ($env{'form.pagepath'}) {
442: $container='page';
443: $pathitem = '<input type="hidden" name="pagepath" value="'.
444: &HTML::Entities::encode($env{'form.pagepath'},'<>&"').'" />';
445: } else {
446: my $folderpath=$env{'form.folderpath'};
447: if ($folderpath eq '') {
448: $folderpath = 'default&'.&escape(&mt('Main '.$crstype.' Documents'));
449: }
450: $pathitem = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
451: }
452: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
453: my $jumpto = $readfile;
454: $jumpto =~ s{^/}{};
455: my $tid = 1;
456: my ($breadcrumbtrail) = &breadcrumbs($allowed,$crstype);
457: $r->print($breadcrumbtrail.
458: &generate_edit_table($tid,\%orderhash,undef,$iconpath,$jumpto,
459: $readfile));
460: my %docslog=&Apache::lonnet::dump('nohist_docslog',
461: $env{'course.'.$env{'request.course.id'}.'.domain'},
462: $env{'course.'.$env{'request.course.id'}.'.num'});
463:
464: if ((keys(%docslog))[0]=~/^error\:/) { undef(%docslog); }
465:
466: my %saveable_parameters = ('show' => 'scalar',);
467: &Apache::loncommon::store_course_settings('docs_log',
468: \%saveable_parameters);
469: &Apache::loncommon::restore_course_settings('docs_log',
470: \%saveable_parameters);
471: if (!$env{'form.show'}) { $env{'form.show'}=10; }
472: # FIXME: internationalization seems wrong here
473: my %lt=('hiddenresource' => 'Resources hidden',
474: 'encrypturl' => 'URL hidden',
475: 'randompick' => 'Randomly pick',
476: 'randomorder' => 'Randomly ordered',
477: 'set' => 'set to',
478: 'del' => 'deleted');
479: my $filter = &Apache::loncommon::display_filter('docslog')."\n".
480: $pathitem."\n".
481: '<input type="hidden" name="folder" value="'.$env{'form.folder'}.'" />'.
482: (' 'x2).'<input type="submit" value="'.&mt('Display').'" />';
483: $r->print('<div class="LC_left_float">'.
484: '<fieldset><legend>'.&mt('Display of Content Changes').'</legend>'."\n".
485: &makedocslogform($filter,1).
486: '</fieldset></div><br clear="all" />');
487: $r->print(&Apache::loncommon::start_data_table().&Apache::loncommon::start_data_table_header_row().
488: '<th>'.&mt('Time').'</th><th>'.&mt('User').'</th><th>'.&mt('Folder').'</th><th>'.&mt('Before').'</th><th>'.
489: &mt('After').'</th>'.
490: &Apache::loncommon::end_data_table_header_row());
491: my $shown=0;
492: foreach my $id (sort { $docslog{$b}{'exe_time'}<=>$docslog{$a}{'exe_time'} } (keys(%docslog))) {
493: if ($env{'form.displayfilter'} eq 'currentfolder') {
494: if ($docslog{$id}{'logentry'}{'currentfolder'} ne $folder) { next; }
495: }
496: my @changes=keys(%{$docslog{$id}{'logentry'}});
497: if ($env{'form.displayfilter'} eq 'containing') {
498: my $wholeentry=$docslog{$id}{'exe_uname'}.':'.$docslog{$id}{'exe_udom'}.':'.
499: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},$docslog{$id}{'exe_udom'});
500: foreach my $key (@changes) {
501: $wholeentry.=':'.$docslog{$id}{'logentry'}{$key};
502: }
503: if ($wholeentry!~/\Q$env{'form.containingphrase'}\E/i) { next; }
504: }
505: my $count = 0;
506: my $time =
507: &Apache::lonlocal::locallocaltime($docslog{$id}{'exe_time'});
508: my $plainname =
509: &Apache::loncommon::plainname($docslog{$id}{'exe_uname'},
510: $docslog{$id}{'exe_udom'});
511: my $about_me_link =
512: &Apache::loncommon::aboutmewrapper($plainname,
513: $docslog{$id}{'exe_uname'},
514: $docslog{$id}{'exe_udom'});
515: my $send_msg_link='';
516: if ((($docslog{$id}{'exe_uname'} ne $env{'user.name'})
517: || ($docslog{$id}{'exe_udom'} ne $env{'user.domain'}))) {
518: $send_msg_link ='<br />'.
519: &Apache::loncommon::messagewrapper(&mt('Send message'),
520: $docslog{$id}{'exe_uname'},
521: $docslog{$id}{'exe_udom'});
522: }
523: $r->print(&Apache::loncommon::start_data_table_row());
524: $r->print('<td>'.$time.'</td>
525: <td>'.$about_me_link.
526: '<br /><tt>'.$docslog{$id}{'exe_uname'}.
527: ':'.$docslog{$id}{'exe_udom'}.'</tt>'.
528: $send_msg_link.'</td><td>'.
529: $docslog{$id}{'logentry'}{'folder'}.'</td><td>');
530: # Before
531: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
532: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
533: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
534: if ($oldname ne $newname) {
535: $r->print(&LONCAPA::map::qtescape($oldname));
536: }
537: }
538: $r->print('<ul>');
539: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
540: if ($docslog{$id}{'logentry'}{'before_order_res_'.$idx}) {
541: $r->print('<li>'.&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'before_order_res_'.$idx}))[0]).'</li>');
542: }
543: }
544: $r->print('</ul>');
545: # After
546: $r->print('</td><td>');
547:
548: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
549: my $oldname=(split(/\:/,$docslog{$id}{'logentry'}{'before_resources_'.$idx}))[0];
550: my $newname=(split(/\:/,$docslog{$id}{'logentry'}{'after_resources_'.$idx}))[0];
551: if ($oldname ne '' && $oldname ne $newname) {
552: $r->print(&LONCAPA::map::qtescape($newname));
553: }
554: }
555: $r->print('<ul>');
556: for (my $idx=0;$idx<=$docslog{$id}{'logentry'}{'maxidx'};$idx++) {
557: if ($docslog{$id}{'logentry'}{'after_order_res_'.$idx}) {
558: $r->print('<li>'.&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'after_order_res_'.$idx}))[0]).'</li>');
559: }
560: }
561: $r->print('</ul>');
562: if ($docslog{$id}{'logentry'}{'parameter_res'}) {
563: $r->print(&LONCAPA::map::qtescape((split(/\:/,$docslog{$id}{'logentry'}{'parameter_res'}))[0]).':<ul>');
564: foreach my $parameter ('randompick','hiddenresource','encrypturl','randomorder') {
565: if ($docslog{$id}{'logentry'}{'parameter_action_'.$parameter}) {
566: # FIXME: internationalization seems wrong here
567: $r->print('<li>'.
568: &mt($lt{$parameter}.' '.$lt{$docslog{$id}{'logentry'}{'parameter_action_'.$parameter}}.' [_1]',
569: $docslog{$id}{'logentry'}{'parameter_value_'.$parameter})
570: .'</li>');
571: }
572: }
573: $r->print('</ul>');
574: }
575: # End
576: $r->print('</td>'.&Apache::loncommon::end_data_table_row());
577: $shown++;
578: if (!($env{'form.show'} eq &mt('all')
579: || $shown<=$env{'form.show'})) { last; }
580: }
581: $r->print(&Apache::loncommon::end_data_table()."\n".
582: &makesimpleeditform($pathitem)."\n".
583: '</div></div>');
584: $r->print(&endContentScreen());
585: }
586:
587: sub update_paste_buffer {
588: my ($coursenum,$coursedom) = @_;
589:
590: return if (!defined($env{'form.markcopy'}));
591: return if (!defined($env{'form.copyfolder'}));
592: return if ($env{'form.markcopy'} < 0);
593:
594: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
595: $env{'form.copyfolder'});
596:
597: return if ($fatal);
598:
599: # Mark for copying
600: my ($title,$url)=split(':',$LONCAPA::map::resources[$LONCAPA::map::order[$env{'form.markcopy'}]]);
601: if (&is_supplemental_title($title)) {
602: &Apache::lonnet::appenv({'docs.markedcopy_supplemental' => $title});
603: ($title) = &parse_supplemental_title($title);
604: } elsif ($env{'docs.markedcopy_supplemental'}) {
605: &Apache::lonnet::delenv('docs.markedcopy_supplemental');
606: }
607: $url=~s{http(:|:)//https(:|:)//}{https$2//};
608:
609: &Apache::lonnet::appenv({'docs.markedcopy_title' => $title,
610: 'docs.markedcopy_url' => $url});
611: delete($env{'form.markcopy'});
612: }
613:
614: sub print_paste_buffer {
615: my ($r,$container) = @_;
616: return if (!defined($env{'docs.markedcopy_url'}));
617:
618: $r->print('<fieldset>'
619: .'<legend>'.&mt('Clipboard').'</legend>'
620: .'<form name="pasteform" action="/adm/coursedocs" method="post">'
621: .'<input type="submit" name="pastemarked" value="'.&mt('Paste').'" /> '
622: );
623:
624: my $type;
625: if ($env{'docs.markedcopy_url'} =~ m{^(?:/adm/wrapper/ext|(?:http|https)(?::|:))//} ) {
626: $type = &mt('External Resource');
627: $r->print($type.': '.
628: &LONCAPA::map::qtescape($env{'docs.markedcopy_title'}).' ('.
629: &LONCAPA::map::qtescape($env{'docs.markedcopy_url'}).')');
630: } else {
631: my $extension = (split(/\./,$env{'docs.markedcopy_url'}))[-1];
632: my $icon = &Apache::loncommon::icon($extension);
633: if ($extension eq 'sequence' &&
634: $env{'docs.markedcopy_url'} =~ m{/default_\d+\.sequence$ }x) {
635: $icon = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL'));
636: $icon .= '/navmap.folder.closed.gif';
637: }
638: $icon = '<img src="'.$icon.'" alt="" class="LC_icon" />';
639: $r->print($icon.$type.': '. &parse_supplemental_title(&LONCAPA::map::qtescape($env{'docs.markedcopy_title'})));
640: }
641: if ($container eq 'page') {
642: $r->print('
643: <input type="hidden" name="pagepath" value="'.&HTML::Entities::encode($env{'form.pagepath'},'<>&"').'" />
644: <input type="hidden" name="pagesymb" value="'.&HTML::Entities::encode($env{'form.pagesymb'},'<>&"').'" />
645: ');
646: } else {
647: $r->print('
648: <input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />
649: ');
650: }
651: $r->print('</form></fieldset>');
652: }
653:
654: sub do_paste_from_buffer {
655: my ($coursenum,$coursedom,$folder) = @_;
656:
657: if (!$env{'form.pastemarked'}) {
658: return;
659: }
660:
661: # paste resource to end of list
662: my $url=&LONCAPA::map::qtescape($env{'docs.markedcopy_url'});
663: my $title=&LONCAPA::map::qtescape($env{'docs.markedcopy_title'});
664: # Maps need to be copied first
665: if (($url=~/\.(page|sequence)$/) && ($url=~/^\/uploaded\//)) {
666: $title=&mt('Copy of').' '.$title;
667: my $newid=$$.int(rand(100)).time;
668: my ($oldid,$ext) = ($url=~/^(.+)\.(\w+)$/);
669: if ($oldid =~ m{^(/uploaded/\Q$coursedom\E/\Q$coursenum\E/)(\D+)(\d+)$}) {
670: my $path = $1;
671: my $prefix = $2;
672: my $ancestor = $3;
673: if (length($ancestor) > 10) {
674: $ancestor = substr($ancestor,-10,10);
675: }
676: $oldid = $path.$prefix.$ancestor;
677: }
678: my $counter = 0;
679: my $newurl=$oldid.$newid.'.'.$ext;
680: my $is_unique = &uniqueness_check($newurl);
681: while (!$is_unique && $counter < 100) {
682: $counter ++;
683: $newid ++;
684: $newurl = $oldid.$newid;
685: $is_unique = &uniqueness_check($newurl);
686: }
687: if (!$is_unique) {
688: if ($url=~/\.page$/) {
689: return &mt('Paste failed: an error occurred creating a unique URL for the composite page');
690: } else {
691: return &mt('Paste failed: an error occurred creating a unique URL for the folder');
692: }
693: }
694: my $storefn=$newurl;
695: $storefn=~s{^/\w+/$match_domain/$match_username/}{};
696: my $paste_map_result =
697: &Apache::lonclonecourse::writefile($env{'request.course.id'},$storefn,
698: &Apache::lonnet::getfile($url));
699: if ($paste_map_result eq '/adm/notfound.html') {
700: if ($url=~/\.page$/) {
701: return &mt('Paste failed: an error occurred saving the composite page');
702: } else {
703: return &mt('Paste failed: an error occurred saving the folder');
704: }
705: }
706: $url = $newurl;
707: }
708: # published maps can only exists once, so remove it from paste buffer when done
709: if (($url=~/\.(page|sequence)$/) && ($url=~m {^/res/})) {
710: &Apache::lonnet::delenv('docs.markedcopy');
711: }
712: if ($url=~ m{/smppg$}) {
713: my $db_name = &Apache::lonsimplepage::get_db_name($url);
714: if ($db_name =~ /^smppage_/) {
715: #simple pages, need to copy the db contents to a new one.
716: my %contents=&Apache::lonnet::dump($db_name,$coursedom,$coursenum);
717: my $now = time();
718: $db_name =~ s{_\d*$ }{_$now}x;
719: my $result=&Apache::lonnet::put($db_name,\%contents,
720: $coursedom,$coursenum);
721: $url =~ s{/(\d*)/smppg$ }{/$now/smppg}x;
722: $title=&mt('Copy of').' '.$title;
723: }
724: }
725: $title = &LONCAPA::map::qtunescape($title);
726: my $ext='false';
727: if ($url=~m{^http(|s)://}) { $ext='true'; }
728: $url = &LONCAPA::map::qtunescape($url);
729: # Now insert the URL at the bottom
730: my $newidx = &LONCAPA::map::getresidx($url);
731: if ($env{'docs.markedcopy_supplemental'}) {
732: if ($folder =~ /^supplemental/) {
733: $title = $env{'docs.markedcopy_supplemental'};
734: } else {
735: (undef,undef,$title) =
736: &parse_supplemental_title($env{'docs.markedcopy_supplemental'});
737: }
738: } else {
739: if ($folder=~/^supplemental/) {
740: $title=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
741: $env{'user.domain'}.'___&&&___'.$title;
742: }
743: }
744:
745: $LONCAPA::map::resources[$newidx]= $title.':'.$url.':'.$ext.':normal:res';
746: push(@LONCAPA::map::order, $newidx);
747: return 'ok';
748: # Store the result
749: }
750:
751: sub uniqueness_check {
752: my ($newurl) = @_;
753: my $unique = 1;
754: foreach my $res (@LONCAPA::map::order) {
755: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
756: $url=&LONCAPA::map::qtescape($url);
757: if ($newurl eq $url) {
758: $unique = 0;
759: last;
760: }
761: }
762: return $unique;
763: }
764:
765: my %parameter_type = ( 'randompick' => 'int_pos',
766: 'hiddenresource' => 'string_yesno',
767: 'encrypturl' => 'string_yesno',
768: 'randomorder' => 'string_yesno',);
769: my $valid_parameters_re = join('|',keys(%parameter_type));
770: # set parameters
771: sub update_parameter {
772:
773: return 0 if ($env{'form.changeparms'} !~ /^($valid_parameters_re)$/);
774:
775: my $which = $env{'form.changeparms'};
776: my $idx = $env{'form.setparms'};
777: if ($env{'form.'.$which.'_'.$idx}) {
778: my $value = ($which eq 'randompick') ? $env{'form.'.$which.'_'.$idx}
779: : 'yes';
780: &LONCAPA::map::storeparameter($idx, 'parameter_'.$which, $value,
781: $parameter_type{$which});
782: &remember_parms($idx,$which,'set',$value);
783: } else {
784: &LONCAPA::map::delparameter($idx,'parameter_'.$which);
785:
786: &remember_parms($idx,$which,'del');
787: }
788: return 1;
789: }
790:
791:
792: sub handle_edit_cmd {
793: my ($coursenum,$coursedom) =@_;
794: my ($cmd,$idx)=split('_',$env{'form.cmd'});
795:
796: my $ratstr = $LONCAPA::map::resources[$LONCAPA::map::order[$idx]];
797: my ($title, $url, @rrest) = split(':', $ratstr);
798:
799: if ($cmd eq 'del') {
800: if (($url=~m|/+uploaded/\Q$coursedom\E/\Q$coursenum\E/|) &&
801: ($url!~/$LONCAPA::assess_page_seq_re/)) {
802: &Apache::lonnet::removeuploadedurl($url);
803: } else {
804: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
805: }
806: splice(@LONCAPA::map::order, $idx, 1);
807:
808: } elsif ($cmd eq 'cut') {
809: &LONCAPA::map::makezombie($LONCAPA::map::order[$idx]);
810: splice(@LONCAPA::map::order, $idx, 1);
811:
812: } elsif ($cmd eq 'up'
813: && ($idx) && (defined($LONCAPA::map::order[$idx-1]))) {
814: @LONCAPA::map::order[$idx-1,$idx] = @LONCAPA::map::order[$idx,$idx-1];
815:
816: } elsif ($cmd eq 'down'
817: && defined($LONCAPA::map::order[$idx+1])) {
818: @LONCAPA::map::order[$idx+1,$idx] = @LONCAPA::map::order[$idx,$idx+1];
819:
820: } elsif ($cmd eq 'rename') {
821:
822: my $comment = &LONCAPA::map::qtunescape($env{'form.title'});
823: if ($comment=~/\S/) {
824: $LONCAPA::map::resources[$LONCAPA::map::order[$idx]]=
825: $comment.':'.join(':', $url, @rrest);
826: }
827: # Devalidate title cache
828: my $renamed_url=&LONCAPA::map::qtescape($url);
829: &Apache::lonnet::devalidate_title_cache($renamed_url);
830: } else {
831: return 0;
832: }
833: return 1;
834: }
835:
836: sub editor {
837: my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$crstype,
838: $supplementalflag,$orderhash,$iconpath)=@_;
839: my $container= ($env{'form.pagepath'}) ? 'page'
840: : 'sequence';
841:
842: my ($breadcrumbtrail,$randompick,$ishidden,$isencrypted,$plain,$is_random_order) =
843: &breadcrumbs($allowed,$crstype);
844: $r->print($breadcrumbtrail);
845:
846: my $jumpto = "uploaded/$coursedom/$coursenum/$folder.$container";
847:
848: unless ($allowed) {
849: $randompick = -1;
850: }
851:
852: my ($errtext,$fatal) = &mapread($coursenum,$coursedom,
853: $folder.'.'.$container);
854: return $errtext if ($fatal);
855:
856: if ($#LONCAPA::map::order<1) {
857: my $idx=&LONCAPA::map::getresidx();
858: if ($idx<=0) { $idx=1; }
859: $LONCAPA::map::order[0]=$idx;
860: $LONCAPA::map::resources[$idx]='';
861: }
862:
863: # ------------------------------------------------------------ Process commands
864:
865: # ---------------- if they are for this folder and user allowed to make changes
866: if (($allowed) && ($env{'form.folder'} eq $folder)) {
867: # set parameters and change order
868: &snapshotbefore();
869:
870: if (&update_parameter()) {
871: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
872: return $errtext if ($fatal);
873: }
874:
875: if ($env{'form.newpos'} && $env{'form.currentpos'}) {
876: # change order
877: my $res = splice(@LONCAPA::map::order,$env{'form.currentpos'}-1,1);
878: splice(@LONCAPA::map::order,$env{'form.newpos'}-1,0,$res);
879:
880: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
881: return $errtext if ($fatal);
882: }
883:
884: if ($env{'form.pastemarked'}) {
885: my $paste_res =
886: &do_paste_from_buffer($coursenum,$coursedom,$folder);
887: if ($paste_res eq 'ok') {
888: ($errtext,$fatal) = &storemap($coursenum,$coursedom,$folder.'.'.$container);
889: return $errtext if ($fatal);
890: } elsif ($paste_res ne '') {
891: $r->print('<p><span class="LC_error">'.$paste_res.'</span></p>');
892: }
893: }
894:
895: $r->print($upload_output);
896:
897: if (&handle_edit_cmd()) {
898: ($errtext,$fatal)=&storemap($coursenum,$coursedom,$folder.'.'.$container);
899: return $errtext if ($fatal);
900: }
901: # Group import/search
902: if ($env{'form.importdetail'}) {
903: my @imports;
904: foreach my $item (split(/\&/,$env{'form.importdetail'})) {
905: if (defined($item)) {
906: my ($name,$url,$residx)=
907: map {&unescape($_)} split(/\=/,$item);
908: push(@imports, [$name, $url, $residx]);
909: }
910: }
911: ($errtext,$fatal)=&group_import($coursenum, $coursedom, $folder,
912: $container,'londocs',@imports);
913: return $errtext if ($fatal);
914: }
915: # Loading a complete map
916: if ($env{'form.loadmap'}) {
917: if ($env{'form.importmap'}=~/\w/) {
918: foreach my $res (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$env{'form.importmap'}))) {
919: my ($title,$url,$ext,$type)=split(/\:/,$res);
920: my $idx=&LONCAPA::map::getresidx($url);
921: $LONCAPA::map::resources[$idx]=$res;
922: $LONCAPA::map::order[$#LONCAPA::map::order+1]=$idx;
923: }
924: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
925: $folder.'.'.$container);
926: return $errtext if ($fatal);
927: } else {
928: $r->print('<p><span class="LC_error">'.&mt('No map selected.').'</span></p>');
929:
930: }
931: }
932: &log_differences($plain);
933: }
934: # ---------------------------------------------------------------- End commands
935: # ---------------------------------------------------------------- Print screen
936: my $idx=0;
937: my $shown=0;
938: if (($ishidden) || ($isencrypted) || ($randompick>=0) || ($is_random_order)) {
939: $r->print('<div class="LC_Box">'.
940: '<ol class="LC_docs_parameters"><li class="LC_docs_parameters_title">'.&mt('Parameters:').'</li>'.
941: ($randompick>=0?'<li>'.&mt('randomly pick [quant,_1,resource]',$randompick).'</li>':'').
942: ($ishidden?'<li>'.&mt('contents hidden').'</li>':'').
943: ($isencrypted?'<li>'.&mt('URLs hidden').'</li>':'').
944: ($is_random_order?'<li>'.&mt('random order').'</li>':'').
945: '</ol>');
946: if ($randompick>=0) {
947: $r->print('<p class="LC_warning">'
948: .&mt('Caution: this folder is set to randomly pick a subset'
949: .' of resources. Adding or removing resources from this'
950: .' folder will change the set of resources that the'
951: .' students see, resulting in spurious or missing credit'
952: .' for completed problems, not limited to ones you'
953: .' modify. Do not modify the contents of this folder if'
954: .' it is in active student use.')
955: .'</p>'
956: );
957: }
958: if ($is_random_order) {
959: $r->print('<p class="LC_warning">'
960: .&mt('Caution: this folder is set to randomly order its'
961: .' contents. Adding or removing resources from this folder'
962: .' will change the order of resources shown.')
963: .'</p>'
964: );
965: }
966: $r->print('</div>');
967: }
968:
969: my ($to_show,$output);
970:
971: &Apache::loncommon::start_data_table_count(); #setup a row counter
972: foreach my $res (@LONCAPA::map::order) {
973: my ($name,$url)=split(/\:/,$LONCAPA::map::resources[$res]);
974: $name=&LONCAPA::map::qtescape($name);
975: $url=&LONCAPA::map::qtescape($url);
976: unless ($name) { $name=(split(/\//,$url))[-1]; }
977: unless ($name) { $idx++; next; }
978: $output .= &entryline($idx,$name,$url,$folder,$allowed,$res,
979: $coursenum,$crstype);
980: $idx++;
981: $shown++;
982: }
983: &Apache::loncommon::end_data_table_count();
984:
985: if ($shown) {
986: $to_show = &Apache::loncommon::start_scrollbox('900px','880px','400px','contentscroll')
987: .&Apache::loncommon::start_data_table(undef,'contentlist');
988: if ($allowed) {
989: $to_show .= &Apache::loncommon::start_data_table_header_row()
990: .'<th colspan="2">'.&mt('Move').'</th>'
991: .'<th>'.&mt('Actions').'</th>'
992: .'<th colspan="2">'.&mt('Document').'</th>';
993: if ($folder !~ /^supplemental/) {
994: $to_show .= '<th colspan="4">'.&mt('Settings').'</th>';
995: }
996: $to_show .= &Apache::loncommon::end_data_table_header_row();
997: }
998: $to_show .= $output.' '
999: .&Apache::loncommon::end_data_table()
1000: .'<br style="line-height:2px;" />'
1001: .&Apache::loncommon::end_scrollbox();
1002: } else {
1003: $to_show .= &Apache::loncommon::start_scrollbox('400px','380px','200px','contentscroll')
1004: .'<div class="LC_info" id="contentlist">'
1005: .&mt('Currently no documents.')
1006: .'</div>'
1007: .&Apache::loncommon::end_scrollbox();
1008: }
1009: my $tid = 1;
1010: if ($supplementalflag) {
1011: $tid = 2;
1012: }
1013: if ($allowed) {
1014: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
1015: $r->print(&generate_edit_table($tid,$orderhash,$to_show,$iconpath,$jumpto,
1016: $readfile));
1017: &print_paste_buffer($r,$container);
1018: } else {
1019: if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
1020: #Function Box for Supplemental Content for users with mdc priv.
1021: my $funcname = &mt('Folder Editor');
1022: $r->print(
1023: &Apache::loncommon::head_subbox(
1024: &Apache::lonhtmlcommon::start_funclist().
1025: &Apache::lonhtmlcommon::add_item_funclist(
1026: '<a href="/adm/coursedocs?command=direct&forcesupplement=1&'.
1027: 'supppath='.&HTML::Entities::encode($env{'form.folderpath'}).'">'.
1028: '<img src="/res/adm/pages/docs.png" alt="'.$funcname.'" class="LC_icon" />'.
1029: '<span class="LC_menubuttons_inline_text">'.$funcname.'</span></a>').
1030: &Apache::lonhtmlcommon::end_funclist()));
1031: }
1032: $r->print($to_show);
1033: }
1034: return;
1035: }
1036:
1037: sub process_file_upload {
1038: my ($upload_output,$coursenum,$coursedom,$allfiles,$codebase,$uploadcmd) = @_;
1039: # upload a file, if present
1040: my ($parseaction,$showupload,$nextphase,$mimetype);
1041: if ($env{'form.parserflag'}) {
1042: $parseaction = 'parse';
1043: }
1044: my $folder=$env{'form.folder'};
1045: if ($folder eq '') {
1046: $folder='default';
1047: }
1048: if ( ($folder=~/^$uploadcmd/) || ($uploadcmd eq 'default') ) {
1049: my $errtext='';
1050: my $fatal=0;
1051: my $container='sequence';
1052: if ($env{'form.pagepath'}) {
1053: $container='page';
1054: }
1055: ($errtext,$fatal)=
1056: &mapread($coursenum,$coursedom,$folder.'.'.$container);
1057: if ($#LONCAPA::map::order<1) {
1058: $LONCAPA::map::order[0]=1;
1059: $LONCAPA::map::resources[1]='';
1060: }
1061: if ($fatal) {
1062: $$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>';
1063: return;
1064: }
1065: my $destination = 'docs/';
1066: if ($folder =~ /^supplemental/) {
1067: $destination = 'supplemental/';
1068: }
1069: if (($folder eq 'default') || ($folder eq 'supplemental')) {
1070: $destination .= 'default/';
1071: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
1072: $destination .= $2.'/';
1073: }
1074: # this is for a course, not a user, so set context to coursedoc.
1075: my $newidx=&LONCAPA::map::getresidx();
1076: $destination .= $newidx;
1077: my $url=&Apache::lonnet::userfileupload('uploaddoc','coursedoc',$destination,
1078: $parseaction,$allfiles,
1079: $codebase,undef,undef,undef,undef,
1080: undef,undef,\$mimetype);
1081: if ($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E.*/([^/]+)$}) {
1082: my $stored = $1;
1083: $showupload = '<p>'.&mt('Uploaded [_1]','<span class="LC_filename">'.
1084: $stored.'</span>').'</p>';
1085: } else {
1086: my ($filename) = ($env{'form.uploaddoc.filename'} =~ m{([^/]+)$});
1087:
1088: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.&mt('Unable to save file [_1].','<span class="LC_filename">'.$filename.'</span>').'</div>';
1089: return;
1090: }
1091: my $ext='false';
1092: if ($url=~m{^http://}) { $ext='true'; }
1093: $url = &LONCAPA::map::qtunescape($url);
1094: my $comment=$env{'form.comment'};
1095: $comment = &LONCAPA::map::qtunescape($comment);
1096: if ($folder=~/^supplemental/) {
1097: $comment=time.'___&&&___'.$env{'user.name'}.'___&&&___'.
1098: $env{'user.domain'}.'___&&&___'.$comment;
1099: }
1100:
1101: $LONCAPA::map::resources[$newidx]=
1102: $comment.':'.$url.':'.$ext.':normal:res';
1103: $LONCAPA::map::order[$#LONCAPA::map::order+1]= $newidx;
1104: ($errtext,$fatal)=&storemap($coursenum,$coursedom,
1105: $folder.'.'.$container);
1106: if ($fatal) {
1107: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.$errtext.'</div>';
1108: return;
1109: } else {
1110: if ($parseaction eq 'parse' && $mimetype eq 'text/html') {
1111: $$upload_output = $showupload;
1112: my $total_embedded = scalar(keys(%{$allfiles}));
1113: if ($total_embedded > 0) {
1114: my $uploadphase = 'upload_embedded';
1115: my $primaryurl = &HTML::Entities::encode($url,'<>&"');
1116: my $state = &embedded_form_elems($uploadphase,$primaryurl,$newidx);
1117: my ($embedded,$num) =
1118: &Apache::loncommon::ask_for_embedded_content(
1119: '/adm/coursedocs',$state,$allfiles,$codebase,{'docs_url' => $url});
1120: if ($embedded) {
1121: if ($num) {
1122: $$upload_output .=
1123: '<p>'.&mt('This file contains embedded multimedia objects, which need to be uploaded.').'</p>'.$embedded;
1124: $nextphase = $uploadphase;
1125: } else {
1126: $$upload_output .= $embedded;
1127: }
1128: } else {
1129: $$upload_output .= &mt('Embedded item(s) already present, so no additional upload(s) required').'<br />';
1130: }
1131: } else {
1132: $$upload_output .= &mt('No embedded items identified').'<br />';
1133: }
1134: $$upload_output = '<div id="uploadfileresult">'.$$upload_output.'</div>';
1135: } elsif (&Apache::loncommon::is_archive_file($mimetype)) {
1136: $nextphase = 'decompress_uploaded';
1137: my $position = scalar(@LONCAPA::map::order)-1;
1138: my $noextract = &return_to_editor();
1139: my $archiveurl = &HTML::Entities::encode($url,'<>&"');
1140: my %archiveitems = (
1141: folderpath => $env{'form.folderpath'},
1142: pagepath => $env{'form.pagepath'},
1143: cmd => $nextphase,
1144: newidx => $newidx,
1145: position => $position,
1146: phase => $nextphase,
1147: comment => $comment,
1148: );
1149: my ($destination,$dir_root) = &embedded_destination($coursenum,$coursedom);
1150: my @current = &get_dir_list($url,$coursenum,$coursedom,$newidx);
1151: $$upload_output = $showupload.
1152: &Apache::loncommon::decompress_form($mimetype,
1153: $archiveurl,'/adm/coursedocs',$noextract,
1154: \%archiveitems,\@current);
1155: }
1156: }
1157: }
1158: return $nextphase;
1159: }
1160:
1161: sub get_dir_list {
1162: my ($url,$coursenum,$coursedom,$newidx) = @_;
1163: my ($destination,$dir_root) = &embedded_destination();
1164: my ($dirlistref,$listerror) =
1165: &Apache::lonnet::dirlist("$dir_root/$destination/$newidx",$coursedom,$coursenum,1);
1166: my @dir_lines;
1167: my $dirptr=16384;
1168: if (ref($dirlistref) eq 'ARRAY') {
1169: foreach my $dir_line (sort
1170: {
1171: my ($afile)=split('&',$a,2);
1172: my ($bfile)=split('&',$b,2);
1173: return (lc($afile) cmp lc($bfile));
1174: } (@{$dirlistref})) {
1175: my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$dir_line,16);
1176: $filename =~ s/\s+$//;
1177: next if ($filename =~ /^\.\.?$/);
1178: my $isdir = 0;
1179: if ($dirptr&$testdir) {
1180: $isdir = 1;
1181: }
1182: push(@dir_lines, [$filename,$dom,$isdir,$size,$mtime,$obs]);
1183: }
1184: }
1185: return @dir_lines;
1186: }
1187:
1188: sub is_supplemental_title {
1189: my ($title) = @_;
1190: return scalar($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/);
1191: }
1192:
1193: sub parse_supplemental_title {
1194: my ($title) = @_;
1195:
1196: my ($foldertitle,$renametitle);
1197: if ($title =~ /&&&/) {
1198: $title = &HTML::Entites::decode($title);
1199: }
1200: if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
1201: $renametitle=$4;
1202: my ($time,$uname,$udom) = ($1,$2,$3);
1203: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
1204: my $name = &Apache::loncommon::plainname($uname,$udom);
1205: $name = &HTML::Entities::encode($name,'"<>&\'');
1206: $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
1207: $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.
1208: $name.': <br />'.$foldertitle;
1209: }
1210: if (wantarray) {
1211: return ($title,$foldertitle,$renametitle);
1212: }
1213: return $title;
1214: }
1215:
1216: # --------------------------------------------------------------- An entry line
1217:
1218: sub entryline {
1219: my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$crstype)=@_;
1220: my ($foldertitle,$pagetitle,$renametitle);
1221: if (&is_supplemental_title($title)) {
1222: ($title,$foldertitle,$renametitle) = &parse_supplemental_title($title);
1223: $pagetitle = $foldertitle;
1224: } else {
1225: $title=&HTML::Entities::encode($title,'"<>&\'');
1226: $renametitle=$title;
1227: $foldertitle=$title;
1228: $pagetitle=$title;
1229: }
1230:
1231: my $orderidx=$LONCAPA::map::order[$index];
1232:
1233:
1234: $renametitle=~s/\\/\\\\/g;
1235: $renametitle=~s/\"\;/\\\"/g;
1236: $renametitle=~s/ /%20/g;
1237: my $line=&Apache::loncommon::start_data_table_row();
1238: my ($form_start,$form_end,$form_common);
1239: # Edit commands
1240: my ($container, $type, $esc_path, $path, $symb);
1241: if ($env{'form.folderpath'}) {
1242: $type = 'folder';
1243: $container = 'sequence';
1244: $esc_path=&escape($env{'form.folderpath'});
1245: $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1246: # $htmlfoldername=&HTML::Entities::encode($env{'form.foldername'},'<>&"');
1247: }
1248: if ($env{'form.pagepath'}) {
1249: $type = $container = 'page';
1250: $esc_path=&escape($env{'form.pagepath'});
1251: $path = &HTML::Entities::encode($env{'form.pagepath'},'<>&"');
1252: $symb=&escape($env{'form.pagesymb'});
1253: }
1254: my $cpinfo='';
1255: if ($allowed) {
1256: my $incindex=$index+1;
1257: my $selectbox='';
1258: if (($#LONCAPA::map::order>0) &&
1259: ((split(/\:/,
1260: $LONCAPA::map::resources[$LONCAPA::map::order[0]]))[1]
1261: ne '') &&
1262: ((split(/\:/,
1263: $LONCAPA::map::resources[$LONCAPA::map::order[1]]))[1]
1264: ne '')) {
1265: $selectbox=
1266: '<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
1267: '<select name="newpos" onchange="this.form.submit()">';
1268: for (my $i=1;$i<=$#LONCAPA::map::order+1;$i++) {
1269: if ($i==$incindex) {
1270: $selectbox.='<option value="" selected="selected">('.$i.')</option>';
1271: } else {
1272: $selectbox.='<option value="'.$i.'">'.$i.'</option>';
1273: }
1274: }
1275: $selectbox.='</select>';
1276: }
1277: my %lt=&Apache::lonlocal::texthash(
1278: 'up' => 'Move Up',
1279: 'dw' => 'Move Down',
1280: 'rm' => 'Remove',
1281: 'ct' => 'Cut',
1282: 'rn' => 'Rename',
1283: 'cp' => 'Copy');
1284: my $nocopy=0;
1285: my $nocut=0;
1286: if ($url=~/\.(page|sequence)$/) {
1287: if ($url =~ m{/res/}) {
1288: # no copy for published maps
1289: $nocopy = 1;
1290: } else {
1291: foreach my $item (&Apache::lonsequence::attemptread(&Apache::lonnet::filelocation('',$url),1)) {
1292: my ($title,$url,$ext,$type)=split(/\:/,$item);
1293: if (($url=~/\.(page|sequence)/) && ($type ne 'zombie')) {
1294: $nocopy=1;
1295: last;
1296: }
1297: }
1298: }
1299: }
1300: if ($url=~/^\/res\/lib\/templates\//) {
1301: $nocopy=1;
1302: $nocut=1;
1303: }
1304: my $copylink=' ';
1305: my $cutlink=' ';
1306:
1307: my $skip_confirm = 0;
1308: if ( $folder =~ /^supplemental/
1309: || ($url =~ m{( /smppg$
1310: |/syllabus$
1311: |/aboutme$
1312: |/navmaps$
1313: |/bulletinboard$
1314: |\.html$
1315: |^/adm/wrapper/ext)}x)) {
1316: $skip_confirm = 1;
1317: }
1318:
1319: if (!$nocopy) {
1320: $copylink=(<<ENDCOPY);
1321: <a href="javascript:markcopy('$esc_path','$index','$renametitle','$container','$symb','$folder');" class="LC_docs_copy">$lt{'cp'}</a>
1322: ENDCOPY
1323: }
1324: if (!$nocut) {
1325: $cutlink=(<<ENDCUT);
1326: <a href="javascript:cutres('$esc_path','$index','$renametitle','$container','$symb','$folder',$skip_confirm);" class="LC_docs_cut">$lt{'ct'}</a>
1327: ENDCUT
1328: }
1329: $form_start = '
1330: <form action="/adm/coursedocs" method="post">
1331: ';
1332: $form_common=(<<END);
1333: <input type="hidden" name="${type}path" value="$path" />
1334: <input type="hidden" name="${type}symb" value="$symb" />
1335: <input type="hidden" name="setparms" value="$orderidx" />
1336: <input type="hidden" name="changeparms" value="0" />
1337: END
1338: $form_end = '</form>';
1339: $line.=(<<END);
1340: <td>
1341: <div class="LC_docs_entry_move">
1342: <a href='/adm/coursedocs?cmd=up_$index&${type}path=$esc_path&${type}symb=$symb$cpinfo'>
1343: <img src="${iconpath}move_up.gif" alt='$lt{'up'}' class="LC_icon" />
1344: </a>
1345: </div>
1346: <div class="LC_docs_entry_move">
1347: <a href='/adm/coursedocs?cmd=down_$index&${type}path=$esc_path&${type}symb=$symb$cpinfo'>
1348: <img src="${iconpath}move_down.gif" alt='$lt{'dw'}' class="LC_icon" />
1349: </a>
1350: </div>
1351: </td>
1352: <td>
1353: $form_start
1354: $form_common
1355: $selectbox
1356: $form_end
1357: </td>
1358: <td class="LC_docs_entry_commands">
1359: <a href='javascript:removeres("$esc_path","$index","$renametitle","$container","$symb",$skip_confirm);' class="LC_docs_remove">$lt{'rm'}</a>
1360: $cutlink
1361: <a href='javascript:changename("$esc_path","$index","$renametitle","$container","$symb");' class="LC_docs_rename">$lt{'rn'}</a>
1362: $copylink
1363: </td>
1364: END
1365:
1366: }
1367: # Figure out what kind of a resource this is
1368: my ($extension)=($url=~/\.(\w+)$/);
1369: my $uploaded=($url=~/^\/*uploaded\//);
1370: my $icon=&Apache::loncommon::icon($url);
1371: my $isfolder=0;
1372: my $ispage=0;
1373: my $folderarg;
1374: my $pagearg;
1375: my $pagefile;
1376: if ($uploaded) {
1377: if (($extension eq 'sequence') || ($extension eq 'page')) {
1378: $url=~/\Q$coursenum\E\/([\/\w]+)\.\Q$extension\E$/;
1379: my $containerarg = $1;
1380: if ($extension eq 'sequence') {
1381: $icon=$iconpath.'navmap.folder.closed.gif';
1382: $folderarg=$containerarg;
1383: $isfolder=1;
1384: } else {
1385: $icon=$iconpath.'page.gif';
1386: $pagearg=$containerarg;
1387: $ispage=1;
1388: }
1389: if ($allowed) {
1390: $url='/adm/coursedocs?';
1391: } else {
1392: $url='/adm/supplemental?';
1393: }
1394: } else {
1395: &Apache::lonnet::allowuploaded('/adm/coursedoc',$url);
1396: }
1397: }
1398:
1399: my $orig_url = $url;
1400: $orig_url=~s{http(:|:)//https(:|:)//}{https$2//};
1401: my $external = ($url=~s{^http(|s)(:|:)//}{/adm/wrapper/ext/});
1402: if ((!$isfolder) && ($residx) && ($folder!~/supplemental/) && (!$ispage)) {
1403: my $symb=&Apache::lonnet::symbclean(
1404: &Apache::lonnet::declutter('uploaded/'.
1405: $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
1406: $env{'course.'.$env{'request.course.id'}.'.num'}.'/'.$folder.
1407: '.sequence').
1408: '___'.$residx.'___'.
1409: &Apache::lonnet::declutter($url));
1410: (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
1411: $url=&Apache::lonnet::clutter($url);
1412: if ($url=~/^\/*uploaded\//) {
1413: $url=~/\.(\w+)$/;
1414: my $embstyle=&Apache::loncommon::fileembstyle($1);
1415: if (($embstyle eq 'img') || ($embstyle eq 'emb')) {
1416: $url='/adm/wrapper'.$url;
1417: } elsif ($embstyle eq 'ssi') {
1418: #do nothing with these
1419: } elsif ($url!~/\.(sequence|page)$/) {
1420: $url='/adm/coursedocs/showdoc'.$url;
1421: }
1422: } elsif ($url=~m|^/ext/|) {
1423: $url='/adm/wrapper'.$url;
1424: $external = 1;
1425: }
1426: if (&Apache::lonnet::symbverify($symb,$url)) {
1427: $url.=(($url=~/\?/)?'&':'?').'symb='.&escape($symb);
1428: } else {
1429: $url='';
1430: }
1431: if ($container eq 'page') {
1432: my $symb=$env{'form.pagesymb'};
1433:
1434: $url=&Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
1435: $url.=(($url=~/\?/)?'&':'?').'symb='.&escape($symb);
1436: }
1437: }
1438: my ($rand_pick_text,$rand_order_text);
1439: if ($isfolder || $extension eq 'sequence') {
1440: my $foldername=&escape($foldertitle);
1441: my $folderpath=$env{'form.folderpath'};
1442: if ($folderpath) { $folderpath.='&' };
1443: # Append randompick number, hidden, and encrypted with ":" to foldername,
1444: # so it gets transferred between levels
1445: $folderpath.=$folderarg.'&'.$foldername.':'.(&LONCAPA::map::getparameter($orderidx,
1446: 'parameter_randompick'))[0]
1447: .':'.((&LONCAPA::map::getparameter($orderidx,
1448: 'parameter_hiddenresource'))[0]=~/^yes$/i)
1449: .':'.((&LONCAPA::map::getparameter($orderidx,
1450: 'parameter_encrypturl'))[0]=~/^yes$/i)
1451: .':'.((&LONCAPA::map::getparameter($orderidx,
1452: 'parameter_randomorder'))[0]=~/^yes$/i);
1453: $url.='folderpath='.&escape($folderpath).$cpinfo;
1454: my $rpicknum = (&LONCAPA::map::getparameter($orderidx,
1455: 'parameter_randompick'))[0];
1456: my $rpckchk;
1457: if ($rpicknum) {
1458: $rpckchk = ' checked="checked"';
1459: }
1460: my $formname = 'edit_rpick_'.$orderidx;
1461: $rand_pick_text =
1462: '<form action="/adm/coursedocs" method="post" name="'.$formname.'">'."\n".
1463: $form_common."\n".
1464: '<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.'" />';
1465: if ($rpicknum ne '') {
1466: $rand_pick_text .= ': <a href="javascript:updatePick('."document.$formname,'$orderidx','link'".')">'.$rpicknum.'</a>';
1467: }
1468: $rand_pick_text .= '</span></form>';
1469: my $ro_set=
1470: ((&LONCAPA::map::getparameter($orderidx,'parameter_randomorder'))[0]=~/^yes$/i?' checked="checked"':'');
1471: $rand_order_text =
1472: $form_start.
1473: $form_common.'
1474: <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>';
1475: }
1476: if ($ispage) {
1477: my $pagename=&escape($pagetitle);
1478: my $pagepath;
1479: my $folderpath=$env{'form.folderpath'};
1480: if ($folderpath) { $pagepath = $folderpath.'&' };
1481: $pagepath.=$pagearg.'&'.$pagename;
1482: my $symb=$env{'form.pagesymb'};
1483: if (!$symb) {
1484: my $path='uploaded/'.
1485: $env{'course.'.$env{'request.course.id'}.'.domain'}.'/'.
1486: $env{'course.'.$env{'request.course.id'}.'.num'}.'/';
1487: $symb=&Apache::lonnet::encode_symb($path.$folder.'.sequence',
1488: $residx,
1489: $path.$pagearg.'.page');
1490: }
1491: $url.='pagepath='.&escape($pagepath).
1492: '&pagesymb='.&escape($symb).$cpinfo;
1493: }
1494: if (($external) && ($allowed)) {
1495: my $form = ($folder =~ /^default/)? 'newext' : 'supnewext';
1496: $external = ' <a class="LC_docs_ext_edit" href="javascript:edittext(\''.$form.'\',\''.$residx.'\',\''.&escape($title).'\',\''.&escape($orig_url).'\');" >'.&mt('Edit').'</a>';
1497: } else {
1498: undef($external);
1499: }
1500: my $reinit;
1501: if ($crstype eq 'Community') {
1502: $reinit = &mt('(re-initialize community to access)');
1503: } else {
1504: $reinit = &mt('(re-initialize course to access)');
1505: }
1506: $line.='<td>';
1507: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1508: $line.='<a href="'.$url.'"><img src="'.$icon.'" alt="" class="LC_icon" /></a>';
1509: } elsif ($url) {
1510: $line.=&Apache::loncommon::modal_link($url.(($url=~/\?/)?'&':'?').'inhibitmenu=yes',
1511: '<img src="'.$icon.'" alt="" class="LC_icon" />',600,500);
1512: } else {
1513: $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
1514: }
1515: $line.='</td><td>';
1516: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1517: $line.='<a href="'.$url.'">'.$title.'</a>';
1518: } elsif ($url) {
1519: $line.=&Apache::loncommon::modal_link($url.(($url=~/\?/)?'&':'?').'inhibitmenu=yes',
1520: $title,600,500);
1521: } else {
1522: $line.=$title.' <span class="LC_docs_reinit_warn">'.$reinit.'</span>';
1523: }
1524: $line.=$external."</td>";
1525: $rand_pick_text = ' ' if ($rand_pick_text eq '');
1526: $rand_order_text = ' ' if ($rand_order_text eq '');
1527: if (($allowed) && ($folder!~/^supplemental/)) {
1528: my %lt=&Apache::lonlocal::texthash(
1529: 'hd' => 'Hidden',
1530: 'ec' => 'URL hidden');
1531: my $enctext=
1532: ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i?' checked="checked"':'');
1533: my $hidtext=
1534: ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i?' checked="checked"':'');
1535: $line.=(<<ENDPARMS);
1536: <td class="LC_docs_entry_parameter">
1537: $form_start
1538: $form_common
1539: <label><input type="checkbox" name="hiddenresource_$orderidx" onclick="this.form.changeparms.value='hiddenresource';this.form.submit()" $hidtext /> $lt{'hd'}</label>
1540: $form_end
1541: <br />
1542: $form_start
1543: $form_common
1544: <label><input type="checkbox" name="encrypturl_$orderidx" onclick="this.form.changeparms.value='encrypturl';this.form.submit()" $enctext /> $lt{'ec'}</label>
1545: $form_end
1546: </td>
1547: <td class="LC_docs_entry_parameter">$rand_pick_text<br />
1548: $rand_order_text</td>
1549: ENDPARMS
1550: }
1551: $line.=&Apache::loncommon::end_data_table_row();
1552: return $line;
1553: }
1554:
1555: =pod
1556:
1557: =item tiehash()
1558:
1559: tie the hash
1560:
1561: =cut
1562:
1563: sub tiehash {
1564: my ($mode)=@_;
1565: $hashtied=0;
1566: if ($env{'request.course.fn'}) {
1567: if ($mode eq 'write') {
1568: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
1569: &GDBM_WRCREAT(),0640)) {
1570: $hashtied=2;
1571: }
1572: } else {
1573: if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.".db",
1574: &GDBM_READER(),0640)) {
1575: $hashtied=1;
1576: }
1577: }
1578: }
1579: }
1580:
1581: sub untiehash {
1582: if ($hashtied) { untie %hash; }
1583: $hashtied=0;
1584: return OK;
1585: }
1586:
1587:
1588:
1589:
1590: sub checkonthis {
1591: my ($r,$url,$level,$title)=@_;
1592: $url=&unescape($url);
1593: $alreadyseen{$url}=1;
1594: $r->rflush();
1595: if (($url) && ($url!~/^\/uploaded\//) && ($url!~/\*$/)) {
1596: $r->print("\n<br />");
1597: if ($level==0) {
1598: $r->print("<br />");
1599: }
1600: for (my $i=0;$i<=$level*5;$i++) {
1601: $r->print(' ');
1602: }
1603: $r->print('<a href="'.$url.'" target="cat">'.
1604: ($title?$title:$url).'</a> ');
1605: if ($url=~/^\/res\//) {
1606: my $result=&Apache::lonnet::repcopy(
1607: &Apache::lonnet::filelocation('',$url));
1608: if ($result eq 'ok') {
1609: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
1610: $r->rflush();
1611: &Apache::lonnet::countacc($url);
1612: $url=~/\.(\w+)$/;
1613: if (&Apache::loncommon::fileembstyle($1) eq 'ssi') {
1614: $r->print('<br />');
1615: $r->rflush();
1616: for (my $i=0;$i<=$level*5;$i++) {
1617: $r->print(' ');
1618: }
1619: $r->print('- '.&mt('Rendering:').' ');
1620: my ($errorcount,$warningcount)=split(/:/,
1621: &Apache::lonnet::ssi_body($url,
1622: ('grade_target'=>'web',
1623: 'return_only_error_and_warning_counts' => 1)));
1624: if (($errorcount) ||
1625: ($warningcount)) {
1626: if ($errorcount) {
1627: $r->print('<img src="/adm/lonMisc/bomb.gif" alt="'.&mt('bomb').'" /><span class="LC_error">'.
1628: &mt('[quant,_1,error]',$errorcount).'</span>');
1629: }
1630: if ($warningcount) {
1631: $r->print('<span class="LC_warning">'.
1632: &mt('[quant,_1,warning]',$warningcount).'</span>');
1633: }
1634: } else {
1635: $r->print('<span class="LC_success">'.&mt('ok').'</span>');
1636: }
1637: $r->rflush();
1638: }
1639: my $dependencies=
1640: &Apache::lonnet::metadata($url,'dependencies');
1641: foreach my $dep (split(/\,/,$dependencies)) {
1642: if (($dep=~/^\/res\//) && (!$alreadyseen{$dep})) {
1643: &checkonthis($r,$dep,$level+1);
1644: }
1645: }
1646: } elsif ($result eq 'unavailable') {
1647: $r->print('<span class="LC_error">'.&mt('connection down').'</span>');
1648: } elsif ($result eq 'not_found') {
1649: unless ($url=~/\$/) {
1650: $r->print('<span class="LC_error">'.&mt('not found').'</b></span>');
1651: } else {
1652: $r->print('<span class="LC_error">'.&mt('unable to verify variable URL').'</span>');
1653: }
1654: } else {
1655: $r->print('<span class="LC_error">'.&mt('access denied').'</span>');
1656: }
1657: }
1658: }
1659: }
1660:
1661:
1662:
1663: =pod
1664:
1665: =item list_symbs()
1666:
1667: List Content Identifiers
1668:
1669: =cut
1670:
1671: sub list_symbs {
1672: my ($r) = @_;
1673:
1674: my $crstype = &Apache::loncommon::course_type();
1675: $r->print(&Apache::loncommon::start_page('List of Content Identifiers'));
1676: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Identifiers'));
1677: $r->print(&startContentScreen('tools'));
1678: my $navmap = Apache::lonnavmaps::navmap->new();
1679: if (!defined($navmap)) {
1680: $r->print('<h2>'.&mt('Retrieval of List Failed').'</h2>'.
1681: '<div class="LC_error">'.
1682: &mt('Unable to retrieve information about course contents').
1683: '</div>');
1684: &Apache::lonnet::logthis('Symb list failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
1685: } else {
1686: $r->print('<h4 class="LC_info">'.&mt("$crstype Content Identifiers").'</h4>'.
1687: &Apache::loncommon::start_data_table().
1688: &Apache::loncommon::start_data_table_header_row().
1689: '<th>'.&mt('Title').'</th><th>'.&mt('Identifier').'</th>'.
1690: &Apache::loncommon::end_data_table_header_row()."\n");
1691: my $count;
1692: foreach my $res ($navmap->retrieveResources()) {
1693: $r->print(&Apache::loncommon::start_data_table_row().
1694: '<td>'.$res->compTitle().'</td>'.
1695: '<td>'.$res->symb().'</td>'.
1696: &Apache::loncommon::start_data_table_row());
1697: $count ++;
1698: }
1699: if (!$count) {
1700: $r->print(&Apache::loncommon::start_data_table_row().
1701: '<td colspan="2">'.&mt("$crstype is empty").'</td>'.
1702: &Apache::loncommon::end_data_table_row());
1703: }
1704: $r->print(&Apache::loncommon::end_data_table());
1705: }
1706: }
1707:
1708:
1709: sub verifycontent {
1710: my ($r) = @_;
1711: my $crstype = &Apache::loncommon::course_type();
1712: $r->print(&Apache::loncommon::start_page('Verify '.$crstype.' Documents'));
1713: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Verify '.$crstype.' Documents'));
1714: $r->print(&startContentScreen('tools'));
1715: $r->print('<h4 class="LC_info">'.&mt($crstype.' content verification').'</h4>');
1716: $hashtied=0;
1717: undef %alreadyseen;
1718: %alreadyseen=();
1719: &tiehash();
1720:
1721: foreach my $key (keys(%hash)) {
1722: if ($hash{$key}=~/\.(page|sequence)$/) {
1723: if (($key=~/^src_/) && ($alreadyseen{&unescape($hash{$key})})) {
1724: $r->print('<hr /><span class="LC_error">'.
1725: &mt('The following sequence or page is included more than once in your '.$crstype.':').' '.
1726: &unescape($hash{$key}).'</span><br />'.
1727: &mt('Note that grading records for problems included in this sequence or folder will overlap.').'<hr />');
1728: }
1729: }
1730: if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) {
1731: &checkonthis($r,$hash{$key},0,$hash{'title_'.$1});
1732: }
1733: }
1734: &untiehash();
1735: $r->print('<p class="LC_success">'.&mt('Done').'</p>');
1736: }
1737:
1738:
1739: sub devalidateversioncache {
1740: my $src=shift;
1741: &Apache::lonnet::devalidate_cache_new('courseresversion',$env{'request.course.id'}.'_'.
1742: &Apache::lonnet::clutter($src));
1743: }
1744:
1745: sub checkversions {
1746: my ($r) = @_;
1747: my $crstype = &Apache::loncommon::course_type();
1748: $r->print(&Apache::loncommon::start_page("Check $crstype Document Versions"));
1749: $r->print(&Apache::lonhtmlcommon::breadcrumbs("Check $crstype Document Versions"));
1750: $r->print(&startContentScreen('tools'));
1751:
1752: my $header='';
1753: my $startsel='';
1754: my $monthsel='';
1755: my $weeksel='';
1756: my $daysel='';
1757: my $allsel='';
1758: my %changes=();
1759: my $starttime=0;
1760: my $haschanged=0;
1761: my %setversions=&Apache::lonnet::dump('resourceversions',
1762: $env{'course.'.$env{'request.course.id'}.'.domain'},
1763: $env{'course.'.$env{'request.course.id'}.'.num'});
1764:
1765: $hashtied=0;
1766: &tiehash();
1767: my %newsetversions=();
1768: if ($env{'form.setmostrecent'}) {
1769: $haschanged=1;
1770: foreach my $key (keys(%hash)) {
1771: if ($key=~/^ids\_(\/res\/.+)$/) {
1772: $newsetversions{$1}='mostrecent';
1773: &devalidateversioncache($1);
1774: }
1775: }
1776: } elsif ($env{'form.setcurrent'}) {
1777: $haschanged=1;
1778: foreach my $key (keys(%hash)) {
1779: if ($key=~/^ids\_(\/res\/.+)$/) {
1780: my $getvers=&Apache::lonnet::getversion($1);
1781: if ($getvers>0) {
1782: $newsetversions{$1}=$getvers;
1783: &devalidateversioncache($1);
1784: }
1785: }
1786: }
1787: } elsif ($env{'form.setversions'}) {
1788: $haschanged=1;
1789: foreach my $key (keys(%env)) {
1790: if ($key=~/^form\.set_version_(.+)$/) {
1791: my $src=$1;
1792: if (($env{$key}) && ($env{$key} ne $setversions{$src})) {
1793: $newsetversions{$src}=$env{$key};
1794: &devalidateversioncache($src);
1795: }
1796: }
1797: }
1798: }
1799: if ($haschanged) {
1800: if (&Apache::lonnet::put('resourceversions',\%newsetversions,
1801: $env{'course.'.$env{'request.course.id'}.'.domain'},
1802: $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
1803: $r->print(&Apache::loncommon::confirmwrapper(
1804: &Apache::lonhtmlcommon::confirm_success(&mt('Your Version Settings have been Saved'))));
1805: } else {
1806: $r->print(&Apache::loncommon::confirmwrapper(
1807: &Apache::lonhtmlcommon::confirm_success(&mt('An Error Occured while Attempting to Save your Version Settings'),1)));
1808: }
1809: &mark_hash_old();
1810: }
1811: &changewarning($r,'');
1812: if ($env{'form.timerange'} eq 'all') {
1813: # show all documents
1814: $header=&mt('All Documents in '.$crstype);
1815: $allsel=1;
1816: foreach my $key (keys(%hash)) {
1817: if ($key=~/^ids\_(\/res\/.+)$/) {
1818: my $src=$1;
1819: $changes{$src}=1;
1820: }
1821: }
1822: } else {
1823: # show documents which changed
1824: %changes=&Apache::lonnet::dump
1825: ('versionupdate',$env{'course.'.$env{'request.course.id'}.'.domain'},
1826: $env{'course.'.$env{'request.course.id'}.'.num'});
1827: my $firstkey=(keys(%changes))[0];
1828: unless ($firstkey=~/^error\:/) {
1829: unless ($env{'form.timerange'}) {
1830: $env{'form.timerange'}=604800;
1831: }
1832: my $seltext=&mt('during the last').' '.$env{'form.timerange'}.' '
1833: .&mt('seconds');
1834: if ($env{'form.timerange'}==-1) {
1835: $seltext='since start of course';
1836: $startsel='selected';
1837: $env{'form.timerange'}=time;
1838: }
1839: $starttime=time-$env{'form.timerange'};
1840: if ($env{'form.timerange'}==2592000) {
1841: $seltext=&mt('during the last month').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1842: $monthsel='selected';
1843: } elsif ($env{'form.timerange'}==604800) {
1844: $seltext=&mt('during the last week').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1845: $weeksel='selected';
1846: } elsif ($env{'form.timerange'}==86400) {
1847: $seltext=&mt('since yesterday').' ('.&Apache::lonlocal::locallocaltime($starttime).')';
1848: $daysel='selected';
1849: }
1850: $header=&mt('Content changed').' '.$seltext;
1851: } else {
1852: $header=&mt('No content modifications yet.');
1853: }
1854: }
1855: %setversions=&Apache::lonnet::dump('resourceversions',
1856: $env{'course.'.$env{'request.course.id'}.'.domain'},
1857: $env{'course.'.$env{'request.course.id'}.'.num'});
1858: my %lt=&Apache::lonlocal::texthash
1859: ('st' => 'Version changes since start of '.$crstype,
1860: 'lm' => 'Version changes since last Month',
1861: 'lw' => 'Version changes since last Week',
1862: 'sy' => 'Version changes since Yesterday',
1863: 'al' => 'All Resources (possibly large output)',
1864: 'cd' => 'Change display',
1865: 'sd' => 'Display',
1866: 'fi' => 'File',
1867: 'md' => 'Modification Date',
1868: 'mr' => 'Most recently published Version',
1869: 've' => 'Version used in '.$crstype,
1870: 'vu' => 'Set Version to be used in '.$crstype,
1871: 'sv' => 'Set Versions to be used in '.$crstype.' according to Selections below',
1872: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
1873: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
1874: 'di' => 'Differences',
1875: 'save' => 'Save changes',
1876: 'vers' => 'Version choice(s) for specific resources',
1877: 'act' => 'Actions');
1878: $r->print(<<ENDHEADERS);
1879: <h4 class="LC_info">$header</h4>
1880: <form action="/adm/coursedocs" method="post">
1881: <input type="hidden" name="versions" value="1" />
1882: <div class="LC_left_float">
1883: <fieldset>
1884: <legend>$lt{'cd'}</legend>
1885: <select name="timerange">
1886: <option value='all' $allsel>$lt{'al'}</option>
1887: <option value="-1" $startsel>$lt{'st'}</option>
1888: <option value="2592000" $monthsel>$lt{'lm'}</option>
1889: <option value="604800" $weeksel>$lt{'lw'}</option>
1890: <option value="86400" $daysel>$lt{'sy'}</option>
1891: </select>
1892: <input type="submit" name="display" value="$lt{'sd'}" />
1893: </fieldset>
1894: </div>
1895: <div class="LC_left_float">
1896: <fieldset>
1897: <legend>$lt{'act'}</legend>
1898: $lt{'sm'}: <input type="submit" name="setmostrecent" value="Go" /><br />
1899: $lt{'sc'}: <input type="submit" name="setcurrent" value="Go" />
1900: </fieldset>
1901: </div>
1902: <br clear="all" />
1903: <hr />
1904: <h4>$lt{'vers'}</h4>
1905: <input type="submit" name="setversions" value="$lt{'save'}" />
1906: <table border="0">
1907: ENDHEADERS
1908: #number of columns for version history
1909: my $num_ver_col = 1;
1910: $r->print(
1911: &Apache::loncommon::start_data_table().
1912: &Apache::loncommon::start_data_table_header_row().
1913: '<th>'.&mt('Resources').'</th>'.
1914: "<th>$lt{'mr'}</th>".
1915: "<th>$lt{'ve'}</th>".
1916: "<th>$lt{'vu'}</th>".
1917: '<th colspan="'.$num_ver_col.'">'.&mt('History').'</th>'.
1918: '</b>');
1919: foreach my $key (sort(keys(%changes))) {
1920: if ($changes{$key}>$starttime) {
1921: my ($root,$extension)=($key=~/^(.*)\.(\w+)$/);
1922: my $currentversion=&Apache::lonnet::getversion($key);
1923: if ($currentversion<0) {
1924: $currentversion='<span class="LC_error">'.&mt('Could not be determined.').'</span>';
1925: }
1926: my $linkurl=&Apache::lonnet::clutter($key);
1927: $r->print(
1928: &Apache::loncommon::end_data_table_header_row().
1929: &Apache::loncommon::start_data_table_row().
1930: '<td><b>'.&Apache::lonnet::gettitle($linkurl).'</b><br>'.
1931: '<a href="'.$linkurl.'" target="cat">'.$linkurl.'</a></td>'.
1932: '<td align="right">'.$currentversion.'<span class="LC_fontsize_medium"><br>('.
1933: &Apache::lonlocal::locallocaltime(&Apache::lonnet::metadata($root.'.'.$extension,'lastrevisiondate')).')</span></td>'.
1934: '<td align="right">');
1935: # Used in course
1936: my $usedversion=$hash{'version_'.$linkurl};
1937: if (($usedversion) && ($usedversion ne 'mostrecent')) {
1938: if($usedversion != $currentversion){
1939: $r->print('<span class="LC_warning">'.$usedversion.'</span>');
1940: }else{
1941: $r->print($usedversion);
1942: }
1943: } else {
1944: $r->print($currentversion);
1945: }
1946: $r->print('</td><td title="'.$lt{'vu'}.'">');
1947: # Set version
1948: $r->print(&Apache::loncommon::select_form($setversions{$linkurl},
1949: 'set_version_'.$linkurl,
1950: {'select_form_order' =>
1951: ['',1..$currentversion,'mostrecent'],
1952: '' => '',
1953: 'mostrecent' => &mt('most recent'),
1954: map {$_,$_} (1..$currentversion)}));
1955: my $lastold=1;
1956: for (my $prevvers=1;$prevvers<$currentversion;$prevvers++) {
1957: my $url=$root.'.'.$prevvers.'.'.$extension;
1958: if (&Apache::lonnet::metadata($url,'lastrevisiondate')<
1959: $starttime) {
1960: $lastold=$prevvers;
1961: }
1962: }
1963: #
1964: # Code to figure out how many version entries should go in
1965: # each of the four columns
1966: my $entries_per_col = 0;
1967: my $num_entries = ($currentversion-$lastold);
1968: if ($num_entries % $num_ver_col == 0) {
1969: $entries_per_col = $num_entries/$num_ver_col;
1970: } else {
1971: $entries_per_col = $num_entries/$num_ver_col + 1;
1972: }
1973: my $entries_count = 0;
1974: $r->print('<td valign="top"><span class="LC_fontsize_medium">');
1975: my $cols_output = 1;
1976: for (my $prevvers=$lastold;$prevvers<$currentversion;$prevvers++) {
1977: my $url=$root.'.'.$prevvers.'.'.$extension;
1978: $r->print('<span class="LC_nobreak"><a href="'.&Apache::lonnet::clutter($url).
1979: '">'.&mt('Version').' '.$prevvers.'</a> ('.
1980: &Apache::lonlocal::locallocaltime(
1981: &Apache::lonnet::metadata($url,
1982: 'lastrevisiondate')
1983: ).
1984: ')');
1985: if (&Apache::loncommon::fileembstyle($extension) eq 'ssi') {
1986: $r->print(' <a href="/adm/diff?filename='.
1987: &Apache::lonnet::clutter($root.'.'.$extension).
1988: '&versionone='.$prevvers.
1989: '" target="diffs">'.&mt('Diffs').'</a>');
1990: }
1991: $r->print('</span><br />');
1992: if (++$entries_count % $entries_per_col == 0) {
1993: $r->print('</span></td>');
1994: if ($cols_output != $num_ver_col) {
1995: $r->print('<td valign="top"><span class="LC_fontsize_medium">');
1996: $cols_output++;
1997: }
1998: }
1999: }
2000: while($cols_output++ < $num_ver_col) {
2001: $r->print('</span></td><td>');
2002: }
2003: }
2004: }
2005: $r->print('</td>'.&Apache::loncommon::end_data_table_row().
2006: &Apache::loncommon::end_data_table().
2007: '<input type="submit" name="setversions" value="'.$lt{'save'}.'" />');
2008:
2009: &untiehash();
2010: }
2011:
2012: sub mark_hash_old {
2013: my $retie_hash=0;
2014: if ($hashtied) {
2015: $retie_hash=1;
2016: &untiehash();
2017: }
2018: &tiehash('write');
2019: $hash{'old'}=1;
2020: &untiehash();
2021: if ($retie_hash) { &tiehash(); }
2022: }
2023:
2024: sub is_hash_old {
2025: my $untie_hash=0;
2026: if (!$hashtied) {
2027: $untie_hash=1;
2028: &tiehash();
2029: }
2030: my $return=$hash{'old'};
2031: if ($untie_hash) { &untiehash(); }
2032: return $return;
2033: }
2034:
2035: sub changewarning {
2036: my ($r,$postexec,$message,$url)=@_;
2037: if (!&is_hash_old()) { return; }
2038: my $pathvar='folderpath';
2039: my $path=&escape($env{'form.folderpath'});
2040: if (!defined($url)) {
2041: if (defined($env{'form.pagepath'})) {
2042: $pathvar='pagepath';
2043: $path=&escape($env{'form.pagepath'});
2044: $path.='&pagesymb='.&escape($env{'form.pagesymb'});
2045: }
2046: $url='/adm/coursedocs?'.$pathvar.'='.$path;
2047: }
2048: my $course_type = &Apache::loncommon::course_type();
2049: if (!defined($message)) {
2050: $message='Changes will become active for your current session after [_1], or the next time you log in.';
2051: }
2052: $r->print("\n\n".
2053: '<script type="text/javascript">'."\n".
2054: '// <![CDATA['."\n".
2055: 'function reinit(tf) { tf.submit();'.$postexec.' }'."\n".
2056: '// ]]>'."\n".
2057: '</script>'."\n".
2058: '<form name="reinitform" method="post" action="/adm/roles" target="loncapaclient">'.
2059: '<input type="hidden" name="orgurl" value="'.$url.
2060: '" /><input type="hidden" name="selectrole" value="1" /><p class="LC_warning">'.
2061: &mt($message,' <input type="hidden" name="'.
2062: $env{'request.role'}.'" value="1" /><input type="button" value="'.
2063: &mt('re-initializing '.$course_type).'" onclick="reinit(this.form)" />').
2064: $help{'Caching'}.'</p></form>'."\n\n");
2065: }
2066:
2067:
2068: sub init_breadcrumbs {
2069: my ($form,$text)=@_;
2070: &Apache::lonhtmlcommon::clear_breadcrumbs();
2071: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1",
2072: text=>&Apache::loncommon::course_type().' Editor',
2073: faq=>273,
2074: bug=>'Instructor Interface',
2075: help => 'Docs_Adding_Course_Doc'});
2076: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?".$form.'=1',
2077: text=>$text,
2078: faq=>273,
2079: bug=>'Instructor Interface'});
2080: }
2081:
2082: # subroutine to list form elements
2083: sub create_list_elements {
2084: my @formarr = @_;
2085: my $list = '';
2086: for my $button (@formarr){
2087: for my $picture(keys %$button) {
2088: $list .= &Apache::lonhtmlcommon::htmltag('li', $picture.' '.$button->{$picture}, {class => 'LC_menubuttons_inline_text'});
2089: }
2090: }
2091: return $list;
2092: }
2093:
2094: # subroutine to create ul from list elements
2095: sub create_form_ul {
2096: my $list = shift;
2097: my $ul = &Apache::lonhtmlcommon::htmltag('ul',$list, {class => 'LC_ListStyleNormal'});
2098: return $ul;
2099: }
2100:
2101: #
2102: # Start tabs
2103: #
2104:
2105: sub startContentScreen {
2106: my ($mode) = @_;
2107: my $output = '<ul class="LC_TabContentBigger" id="mainnav">';
2108: if (($mode eq 'navmaps') || ($mode eq 'supplemental')) {
2109: $output .= '<li'.(($mode eq 'navmaps')?' class="active"':'').'><a href="/adm/navmaps"><b> '.&mt('Content Overview').' </b></a></li>'."\n";
2110: $output .= '<li'.(($mode eq 'coursesearch')?' class="active"':'').'><a href="/adm/searchcourse"><b> '.&mt('Content Search').' </b></a></li>'."\n";
2111: $output .= '<li'.(($mode eq 'courseindex')?' class="active"':'').'><a href="/adm/indexcourse"><b> '.&mt('Content Index').' </b></a></li>'."\n";
2112: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/supplemental"><b>'.&mt('Supplemental Content').'</b></a></li>';
2113: } else {
2114: $output .= '<li '.(($mode eq 'docs')?' class="active"':'').' id="tabbededitor"><a href="/adm/coursedocs?forcestandard=1"><b> '.&mt('Content Editor').' </b></a></li>'."\n";
2115: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/coursedocs?forcesupplement=1"><b>'.&mt('Supplemental Content Editor').'</b></a></li>'."\n";
2116: $output .= '<li '.(($mode eq 'tools')?' class="active"':'').'><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>'."\n";
2117: '><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>';
2118: }
2119: $output .= "\n".'</ul>'."\n";
2120: $output .= '<div class="LC_DocsBox" style="clear:both;margin:0;" id="contenteditor">'.
2121: '<div id="maincoursedoc" style="margin:0 0;padding:0 0;">'.
2122: '<div class="LC_ContentBox" id="mainCourseDocuments" style="display: block;">';
2123: return $output;
2124: }
2125:
2126: #
2127: # End tabs
2128: #
2129:
2130: sub endContentScreen {
2131: return '</div></div></div>';
2132: }
2133:
2134: sub supplemental_base {
2135: return 'supplemental&'.&escape(&mt('Supplemental '.&Apache::loncommon::course_type().' Content'));
2136: }
2137:
2138: sub handler {
2139: my $r = shift;
2140: &Apache::loncommon::content_type($r,'text/html');
2141: $r->send_http_header;
2142: return OK if $r->header_only;
2143:
2144: # get course data
2145: my $crstype = &Apache::loncommon::course_type();
2146: my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
2147: my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
2148:
2149: # graphics settings
2150: $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL').'/');
2151:
2152: #
2153: # --------------------------------------------- Initialize help topics for this
2154: foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',
2155: 'Adding_External_Resource','Navigate_Content',
2156: 'Adding_Folders','Docs_Overview', 'Load_Map',
2157: 'Supplemental','Score_Upload_Form','Adding_Pages',
2158: 'Importing_LON-CAPA_Resource','Uploading_From_Harddrive',
2159: 'Check_Resource_Versions','Verify_Content') {
2160: $help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
2161: }
2162: # Composite help files
2163: $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
2164: 'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
2165: $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
2166: 'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
2167: $help{'Simple Problem'} = &Apache::loncommon::help_open_topic(
2168: 'Option_Response_Simple');
2169: $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
2170: 'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
2171: $help{'My Personal Information Page'} = &Apache::loncommon::help_open_topic(
2172: 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
2173: $help{'Group Portfolio'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
2174: $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
2175:
2176:
2177: my $allowed;
2178: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
2179: unless ($r->uri eq '/adm/supplemental') {
2180: # does this user have privileges to modify content.
2181: $allowed = &Apache::lonnet::allowed('mdc',$env{'request.course.id'});
2182: }
2183:
2184: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['chooseserver',
2185: 'inhibitmenu']);
2186: if ($allowed && $env{'form.chooseserver'}) {
2187: &choose_dump_server($r);
2188: return OK;
2189: } elsif ($allowed && $env{'form.verify'}) {
2190: &init_breadcrumbs('verify','Verify Content');
2191: &verifycontent($r);
2192: } elsif ($allowed && $env{'form.listsymbs'}) {
2193: &init_breadcrumbs('listsymbs','List Content IDs');
2194: &list_symbs($r);
2195: } elsif ($allowed && $env{'form.docslog'}) {
2196: &init_breadcrumbs('docslog','Show Log');
2197: my $folder = $env{'form.folder'};
2198: if ($folder eq '') {
2199: $folder='default';
2200: }
2201: &docs_change_log($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath);
2202: } elsif ($allowed && $env{'form.versions'}) {
2203: &init_breadcrumbs('versions','Check/Set Resource Versions');
2204: &checkversions($r);
2205: } elsif ($allowed && $env{'form.dumpcourse'}) {
2206: &init_breadcrumbs('dumpcourse','Dump '.&Apache::loncommon::course_type().' Content to Authoring Space');
2207: &dumpcourse($r);
2208: } elsif ($allowed && $env{'form.exportcourse'}) {
2209: &init_breadcrumbs('exportcourse','IMS Export');
2210: &Apache::imsexport::exportcourse($r);
2211: } else {
2212: #
2213: # Done catching special calls
2214: # The whole rest is for course and supplemental documents and utilities menu
2215: # Get the parameters that may be needed
2216: #
2217: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
2218: ['folderpath','pagepath',
2219: 'pagesymb','forcesupplement','forcestandard',
2220: 'tools','symb','command']);
2221:
2222: # standard=1: this is a "new-style" course with an uploaded map as top level
2223: # standard=2: this is a "old-style" course, and there is nothing we can do
2224:
2225: my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
2226:
2227: # Decide whether this should display supplemental or main content or utilities
2228: # supplementalflag=1: show supplemental documents
2229: # supplementalflag=0: show standard documents
2230: # toolsflag=1: show utilities
2231:
2232:
2233: my $supplementalflag=($env{'form.folderpath'}=~/^supplemental/);
2234: if (($env{'form.folderpath'}=~/^default/) || $env{'form.folderpath'} eq "" || ($env{'form.pagepath'})) {
2235: $supplementalflag=0;
2236: }
2237: if ($env{'form.forcesupplement'}) { $supplementalflag=1; }
2238: if ($env{'form.forcestandard'}) { $supplementalflag=0; }
2239: unless ($allowed) { $supplementalflag=1; }
2240: unless ($standard) { $supplementalflag=1; }
2241: my $toolsflag=0;
2242: if ($env{'form.tools'}) { $toolsflag=1; }
2243:
2244: my $script='';
2245: my $showdoc=0;
2246: my $addentries = {};
2247: my $container;
2248: my $containertag;
2249: my $uploadtag;
2250:
2251: # Do we directly jump somewhere?
2252:
2253: if ($env{'form.command'} eq 'direct') {
2254: my ($mapurl,$id,$resurl);
2255: if ($env{'form.symb'} ne '') {
2256: ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($env{'form.symb'});
2257: if ($resurl=~/\.(sequence|page)$/) {
2258: $mapurl=$resurl;
2259: } elsif ($resurl eq 'adm/navmaps') {
2260: $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
2261: }
2262: my $mapresobj;
2263: my $navmap = Apache::lonnavmaps::navmap->new();
2264: if (ref($navmap)) {
2265: $mapresobj = $navmap->getResourceByUrl($mapurl);
2266: }
2267: $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
2268: my $type=$2;
2269: my $path;
2270: if (ref($mapresobj)) {
2271: my $pcslist = $mapresobj->map_hierarchy();
2272: if ($pcslist ne '') {
2273: foreach my $pc (split(/,/,$pcslist)) {
2274: next if ($pc <= 1);
2275: my $res = $navmap->getByMapPc($pc);
2276: if (ref($res)) {
2277: my $thisurl = $res->src();
2278: $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
2279: my $thistitle = $res->title();
2280: $path .= '&'.
2281: &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
2282: &Apache::lonhtmlcommon::entity_encode($thistitle).
2283: ':'.$res->randompick().
2284: ':'.$res->randomout().
2285: ':'.$res->encrypted().
2286: ':'.$res->randomorder();
2287: }
2288: }
2289: }
2290: $path .= '&'.&Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
2291: &Apache::lonhtmlcommon::entity_encode($mapresobj->title()).
2292: ':'.$mapresobj->randompick().
2293: ':'.$mapresobj->randomout().
2294: ':'.$mapresobj->encrypted().
2295: ':'.$mapresobj->randomorder();
2296: } else {
2297: my $maptitle = &Apache::lonnet::gettitle($mapurl);
2298: $path = '&default&...::::'.
2299: '&'.&Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
2300: &Apache::lonhtmlcommon::entity_encode($maptitle).'::::';
2301: }
2302: $path = 'default&'.
2303: &Apache::lonhtmlcommon::entity_encode('Main Course Documents').
2304: $path;
2305: if ($type eq 'sequence') {
2306: $env{'form.folderpath'}=$path;
2307: $env{'form.pagepath'}='';
2308: } else {
2309: $env{'form.pagepath'}=$path;
2310: $env{'form.folderpath'}='';
2311: }
2312: } elsif ($env{'form.supppath'} ne '') {
2313: $env{'form.folderpath'}=$env{'form.supppath'};
2314: }
2315: } elsif ($env{'form.command'} eq 'editdocs') {
2316: $env{'form.folderpath'} = 'default&'.
2317: &Apache::lonhtmlcommon::entity_encode('Main Course Content');
2318: $env{'form.pagepath'}='';
2319: } elsif ($env{'form.command'} eq 'editsupp') {
2320: $env{'form.folderpath'} = 'default&'.
2321: &Apache::lonhtmlcommon::entity_encode('Supplemental Content');
2322: $env{'form.pagepath'}='';
2323: }
2324:
2325: # Where do we store these for when we come back?
2326: my $stored_folderpath='docs_folderpath';
2327: if ($supplementalflag) {
2328: $stored_folderpath='docs_sup_folderpath';
2329: }
2330:
2331: # No folderpath, no pagepath, see if we have something stored
2332: if ((!$env{'form.folderpath'}) && (!$env{'form.pagepath'})) {
2333: &Apache::loncommon::restore_course_settings($stored_folderpath,
2334: {'folderpath' => 'scalar'});
2335: }
2336:
2337: # If we are not allowed to make changes, all we can see are supplemental docs
2338: if (!$allowed) {
2339: $env{'form.pagepath'}='';
2340: unless ($env{'form.folderpath'} =~ /^supplemental/) {
2341: $env{'form.folderpath'} = &supplemental_base();
2342: }
2343: }
2344: # If we still not have a folderpath, see if we can resurrect at pagepath
2345: if (!$env{'form.folderpath'} && $allowed) {
2346: &Apache::loncommon::restore_course_settings($stored_folderpath,
2347: {'pagepath' => 'scalar'});
2348: }
2349: # Make the zeroth entry in supplemental docs page paths, so we can get to top level
2350: if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
2351: $env{'form.folderpath'} = &supplemental_base()
2352: .'&'.
2353: $env{'form.folderpath'};
2354: }
2355: # If after all of this, we still don't have any paths, make them
2356: unless (($env{'form.pagepath'}) || ($env{'form.folderpath'})) {
2357: if ($supplementalflag) {
2358: $env{'form.folderpath'}=&supplemental_base();
2359: } else {
2360: $env{'form.folderpath'}='default';
2361: }
2362: }
2363:
2364: # Store this
2365: unless ($toolsflag) {
2366: &Apache::loncommon::store_course_settings($stored_folderpath,
2367: {'pagepath' => 'scalar',
2368: 'folderpath' => 'scalar'});
2369: if ($env{'form.folderpath'}) {
2370: my (@folderpath)=split('&',$env{'form.folderpath'});
2371: $env{'form.foldername'}=&unescape(pop(@folderpath));
2372: $env{'form.folder'}=pop(@folderpath);
2373: $container='sequence';
2374: }
2375: if ($env{'form.pagepath'}) {
2376: my (@pagepath)=split('&',$env{'form.pagepath'});
2377: $env{'form.pagename'}=&unescape(pop(@pagepath));
2378: $env{'form.folder'}=pop(@pagepath);
2379: $container='page';
2380: $containertag = '<input type="hidden" name="pagepath" value="" />'.
2381: '<input type="hidden" name="pagesymb" value="" />';
2382: $uploadtag =
2383: '<input type="hidden" name="pagepath" value="'.&HTML::Entities::encode($env{'form.pagepath'},'<>&"').'" />'.
2384: '<input type="hidden" name="pagesymb" value="'.&HTML::Entities::encode($env{'form.pagesymb'},'<>&"').'" />'.
2385: '<input type="hidden" name="folderpath" value="" />';
2386: } else {
2387: my $folderpath=$env{'form.folderpath'};
2388: if (!$folderpath) {
2389: if ($env{'form.folder'} eq '' ||
2390: $env{'form.folder'} eq 'supplemental') {
2391: $folderpath='default&'.
2392: &escape(&mt('Main '.$crstype.' Documents'));
2393: }
2394: }
2395: $containertag = '<input type="hidden" name="folderpath" value="" />';
2396: $uploadtag = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
2397: }
2398: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
2399: $showdoc='/'.$1;
2400: }
2401: if ($showdoc) { # got called in sequence from course
2402: $allowed=0;
2403: } else {
2404: if ($allowed) {
2405: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
2406: $script=&Apache::lonratedt::editscript('simple');
2407: }
2408: }
2409: }
2410:
2411: # get personal data
2412: my $uname=$env{'user.name'};
2413: my $udom=$env{'user.domain'};
2414: my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));
2415:
2416: if ($allowed) {
2417: if ($toolsflag) {
2418: $script .= &inject_data_js();
2419: my ($home,$other,%outhash)=&authorhosts();
2420: if (!$home && $other) {
2421: my @hosts;
2422: foreach my $aurole (keys(%outhash)) {
2423: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
2424: push(@hosts,$outhash{$aurole});
2425: }
2426: }
2427: $script .= &dump_switchserver_js(@hosts);
2428: }
2429: } else {
2430: my @tabids;
2431: if ($supplementalflag) {
2432: @tabids = ('002','ee2','ff2');
2433: } else {
2434: @tabids = ('aa1','bb1','cc1','ff1');
2435: unless ($env{'form.pagepath'}) {
2436: unshift(@tabids,'001');
2437: push(@tabids,('dd1','ee1'));
2438: }
2439: }
2440: my $tabidstr = join("','",@tabids);
2441: $script .= &editing_js($udom,$uname,$supplementalflag).
2442: &history_tab_js().
2443: &inject_data_js().
2444: &Apache::lonhtmlcommon::resize_scrollbox_js('docs',$tabidstr);
2445: $addentries = {
2446: onload => "javascript:resize_scrollbox('contentscroll','1','1');",
2447: };
2448: }
2449: }
2450: # -------------------------------------------------------------------- Body tag
2451: $script = '<script type="text/javascript">'."\n"
2452: .'// <![CDATA['."\n"
2453: .$script."\n"
2454: .'// ]]>'."\n"
2455: .'</script>'."\n";
2456:
2457: # Breadcrumbs
2458: &Apache::lonhtmlcommon::clear_breadcrumbs();
2459: unless ($showdoc) {
2460: &Apache::lonhtmlcommon::add_breadcrumb({
2461: href=>"/adm/coursedocs",text=>"$crstype Contents"});
2462:
2463: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script,
2464: {'force_register' => $showdoc,
2465: 'add_entries' => $addentries,
2466: })
2467: .&Apache::loncommon::help_open_menu('','',273,'RAT')
2468: .&Apache::lonhtmlcommon::breadcrumbs(
2469: 'Editing '.$crstype.' Contents',
2470: 'Docs_Adding_Course_Doc')
2471: );
2472: } else {
2473: $r->print(&Apache::loncommon::start_page("$crstype documents",undef,
2474: {'force_register' => $showdoc,}));
2475: }
2476:
2477: my %allfiles = ();
2478: my %codebase = ();
2479: my ($upload_result,$upload_output,$uploadphase);
2480: if ($allowed) {
2481: if (($env{'form.uploaddoc.filename'}) &&
2482: ($env{'form.cmd'}=~/^upload_(\w+)/)) {
2483: my $context = $1;
2484: # Process file upload - phase one - upload and parse primary file.
2485: undef($hadchanges);
2486: $uploadphase = &process_file_upload(\$upload_output,$coursenum,$coursedom,
2487: \%allfiles,\%codebase,$context);
2488: if ($hadchanges) {
2489: &mark_hash_old();
2490: }
2491: $r->print($upload_output);
2492: } elsif ($env{'form.phase'} eq 'upload_embedded') {
2493: # Process file upload - phase two - upload embedded objects
2494: $uploadphase = 'check_embedded';
2495: my $primaryurl = &HTML::Entities::encode($env{'form.primaryurl'},'<>&"');
2496: my $state = &embedded_form_elems($uploadphase,$primaryurl,
2497: $env{'form.newidx'});
2498: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
2499: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
2500: my ($destination,$dir_root) = &embedded_destination();
2501: my $url_root = '/uploaded/'.$docudom.'/'.$docuname;
2502: my $actionurl = '/adm/coursedocs';
2503: my ($result,$flag) =
2504: &Apache::loncommon::upload_embedded('coursedoc',$destination,
2505: $docuname,$docudom,$dir_root,$url_root,undef,undef,undef,$state,
2506: $actionurl);
2507: $r->print($result.&return_to_editor());
2508: } elsif ($env{'form.phase'} eq 'check_embedded') {
2509: # Process file upload - phase three - modify references in HTML file
2510: $uploadphase = 'modified_orightml';
2511: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
2512: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
2513: my ($destination,$dir_root) = &embedded_destination();
2514: my $result =
2515: &Apache::loncommon::modify_html_refs('coursedoc',$destination,
2516: $docuname,$docudom,undef,
2517: $dir_root);
2518: $r->print($result.&return_to_editor());
2519: } elsif ($env{'form.phase'} eq 'decompress_uploaded') {
2520: $uploadphase = 'decompress_phase_one';
2521: $r->print(&decompression_phase_one().
2522: &return_to_editor());
2523: } elsif ($env{'form.phase'} eq 'decompress_cleanup') {
2524: $uploadphase = 'decompress_phase_two';
2525: $r->print(&decompression_phase_two().
2526: &return_to_editor());
2527: }
2528: }
2529:
2530: if ($allowed && $toolsflag) {
2531: $r->print(&startContentScreen('tools'));
2532: $r->print(&generate_admin_menu($crstype));
2533: $r->print(&endContentScreen());
2534: } elsif ((!$showdoc) && (!$uploadphase)) {
2535: # -----------------------------------------------------------------------------
2536: my %lt=&Apache::lonlocal::texthash(
2537: 'uplm' => 'Upload a new main '.lc($crstype).' document',
2538: 'upls' => 'Upload a new supplemental '.lc($crstype).' document',
2539: 'impp' => 'Import a document',
2540: 'copm' => 'All documents out of a published map into this folder',
2541: 'upld' => 'Import Document',
2542: 'srch' => 'Search',
2543: 'impo' => 'Import',
2544: 'wish' => 'Import from Wishlist',
2545: 'selm' => 'Select Map',
2546: 'load' => 'Load Map',
2547: 'reco' => 'Recover Deleted Documents',
2548: 'newf' => 'New Folder',
2549: 'newp' => 'New Composite Page',
2550: 'extr' => 'External Resource',
2551: 'syll' => 'Syllabus',
2552: 'navc' => 'Table of Contents',
2553: 'sipa' => 'Simple Course Page',
2554: 'sipr' => 'Simple Problem',
2555: 'drbx' => 'Drop Box',
2556: 'scuf' => 'External Scores (handgrade, upload, clicker)',
2557: 'bull' => 'Discussion Board',
2558: 'mypi' => 'My Personal Information Page',
2559: 'grpo' => 'Group Portfolio',
2560: 'rost' => 'Course Roster',
2561: 'abou' => 'Personal Information Page for a User',
2562: 'imsf' => 'IMS Import',
2563: 'imsl' => 'Import IMS package',
2564: 'file' => 'File',
2565: 'title' => 'Title',
2566: 'comment' => 'Comment',
2567: 'parse' => 'Upload embedded images/multimedia files if HTML file',
2568: 'nd' => 'Upload Document',
2569: 'pm' => 'Published Map',
2570: 'sd' => 'Special Document',
2571: 'mo' => 'More Options',
2572: );
2573: # -----------------------------------------------------------------------------
2574: my $fileupload=(<<FIUP);
2575: $lt{'file'}:<br />
2576: <input type="file" name="uploaddoc" size="40" />
2577: FIUP
2578:
2579: my $checkbox=(<<CHBO);
2580: <!-- <label>$lt{'parse'}?
2581: <input type="checkbox" name="parserflag" />
2582: </label> -->
2583: <label>
2584: <input type="checkbox" name="parserflag" checked="checked" /> $lt{'parse'}
2585: </label>
2586: CHBO
2587:
2588: my $fileuploada = "<br clear='all' /><input type='submit' value='".$lt{'upld'}."' /> $help{'Uploading_From_Harddrive'}";
2589: my $fileuploadform=(<<FUFORM);
2590: <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
2591: <input type="hidden" name="active" value="aa" />
2592: $fileupload
2593: <br />
2594: $lt{'title'}:<br />
2595: <input type="text" size="60" name="comment" />
2596: $uploadtag
2597: <input type="hidden" name="cmd" value="upload_default" />
2598: <br />
2599: <span class="LC_nobreak" style="float:left">
2600: $checkbox
2601: </span>
2602: FUFORM
2603: $fileuploadform .= $fileuploada.'</form>';
2604:
2605: my $simpleeditdefaultform=(<<SEDFFORM);
2606: <form action="/adm/coursedocs" method="post" name="simpleeditdefault">
2607: <input type="hidden" name="active" value="bb" />
2608: SEDFFORM
2609: my @simpleeditdefaultforma = (
2610: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/src.png" alt="'.$lt{srch}.'" onclick="javascript:groupsearch()" />' => "$uploadtag<a class='LC_menubuttons_link' href='javascript:groupsearch()'>$lt{'srch'}</a>" },
2611: { '<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'}" },
2612: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/wishlist.png" alt="'.$lt{wish}.'" onclick="javascript:open_Wishlist_Import();" />' => "<a class='LC_menubuttons_link' href='javascript:open_Wishlist_Import();'>$lt{'wish'}</a>" },
2613: );
2614: $simpleeditdefaultform .= &create_form_ul(&create_list_elements(@simpleeditdefaultforma));
2615: $simpleeditdefaultform .=(<<SEDFFORM);
2616: <hr id="bb_hrule" style="width:0px;text-align:left;margin-left:0" />
2617: $lt{'copm'}<br />
2618: <input type="text" size="40" name="importmap" /><br />
2619: <span class="LC_nobreak" style="float:left"><input type="button"
2620: onclick="javascript:openbrowser('simpleeditdefault','importmap','sequence,page','')"
2621: value="$lt{'selm'}" /> <input type="submit" name="loadmap" value="$lt{'load'}" />
2622: $help{'Load_Map'}</span>
2623: </form>
2624: SEDFFORM
2625:
2626: my $extresourcesform=(<<ERFORM);
2627: <form action="/adm/coursedocs" method="post" name="newext">
2628: $uploadtag
2629: <input type="hidden" name="importdetail" value="" />
2630: <a class="LC_menubuttons_link" href="javascript:makenewext('newext');">$lt{'extr'}</a>$help{'Adding_External_Resource'}
2631: </form>
2632: ERFORM
2633:
2634:
2635: if ($allowed) {
2636: &update_paste_buffer($coursenum,$coursedom);
2637: $r->print(<<HIDDENFORM);
2638: <form name="renameform" method="post" action="/adm/coursedocs">
2639: <input type="hidden" name="title" />
2640: <input type="hidden" name="cmd" />
2641: <input type="hidden" name="markcopy" />
2642: <input type="hidden" name="copyfolder" />
2643: $containertag
2644: </form>
2645:
2646: HIDDENFORM
2647: $r->print(&makesimpleeditform($uploadtag)."\n".
2648: &makedocslogform($uploadtag."\n".
2649: '<input type="hidden" name="folder" value="'.
2650: $env{'form.folder'}.'" />'."\n"));
2651: }
2652:
2653: # Generate the tabs
2654: my $mode;
2655: if (($supplementalflag) && (!$allowed)) {
2656: &Apache::lonnavdisplay::startContentScreen($r,'supplemental');
2657: } else {
2658: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
2659: }
2660:
2661: #
2662:
2663: my $savefolderpath;
2664:
2665: if ($allowed) {
2666: my $folder=$env{'form.folder'};
2667: if ($folder eq '' || $supplementalflag) {
2668: $folder='default';
2669: $savefolderpath = $env{'form.folderpath'};
2670: $env{'form.folderpath'}='default&'.&escape(&mt('Content'));
2671: $uploadtag = '<input type="hidden" name="folderpath" value="'.
2672: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
2673: }
2674: my $postexec='';
2675: if ($folder eq 'default') {
2676: $r->print('<script type="text/javascript">'."\n"
2677: .'// <![CDATA['."\n"
2678: .'this.window.name="loncapaclient";'."\n"
2679: .'// ]]>'."\n"
2680: .'</script>'."\n"
2681: );
2682: } else {
2683: #$postexec='self.close();';
2684: }
2685: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_'.time.
2686: '.sequence';
2687: my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_'.time.
2688: '.page';
2689: my $container='sequence';
2690: if ($env{'form.pagepath'}) {
2691: $container='page';
2692: }
2693: my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
2694:
2695: my $imspform=(<<IMSPFORM);
2696: <form action="/adm/imsimportdocs" method="post" name="ims">
2697: <input type="hidden" name="folder" value="$folder" />
2698: <a class="LC_menubuttons_link" href="javascript:makeims();">$lt{'imsf'}</a>
2699: </form>
2700: IMSPFORM
2701:
2702: my $newnavform=(<<NNFORM);
2703: <form action="/adm/coursedocs" method="post" name="newnav">
2704: <input type="hidden" name="active" value="cc" />
2705: $uploadtag
2706: <input type="hidden" name="importdetail"
2707: value="$lt{'navc'}=/adm/navmaps" />
2708: <a class="LC_menubuttons_link" href="javascript:document.newnav.submit()">$lt{'navc'}</a>
2709: $help{'Navigate_Content'}
2710: </form>
2711: NNFORM
2712: my $newsmppageform=(<<NSPFORM);
2713: <form action="/adm/coursedocs" method="post" name="newsmppg">
2714: <input type="hidden" name="active" value="cc" />
2715: $uploadtag
2716: <input type="hidden" name="importdetail" value="" />
2717: <a class="LC_menubuttons_link" href="javascript:makesmppage();"> $lt{'sipa'}</a>
2718: $help{'Simple Page'}
2719: </form>
2720: NSPFORM
2721:
2722: my $newsmpproblemform=(<<NSPROBFORM);
2723: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
2724: <input type="hidden" name="active" value="cc" />
2725: $uploadtag
2726: <input type="hidden" name="importdetail" value="" />
2727: <a class="LC_menubuttons_link" href="javascript:makesmpproblem();">$lt{'sipr'}</a>
2728: $help{'Simple Problem'}
2729: </form>
2730:
2731: NSPROBFORM
2732:
2733: my $newdropboxform=(<<NDBFORM);
2734: <form action="/adm/coursedocs" method="post" name="newdropbox">
2735: <input type="hidden" name="active" value="cc" />
2736: $uploadtag
2737: <input type="hidden" name="importdetail" value="" />
2738: <a class="LC_menubuttons_link" href="javascript:makedropbox();">$lt{'drbx'}</a>
2739: </form>
2740: NDBFORM
2741:
2742: my $newexuploadform=(<<NEXUFORM);
2743: <form action="/adm/coursedocs" method="post" name="newexamupload">
2744: <input type="hidden" name="active" value="cc" />
2745: $uploadtag
2746: <input type="hidden" name="importdetail" value="" />
2747: <a class="LC_menubuttons_link" href="javascript:makeexamupload();">$lt{'scuf'}</a>
2748: $help{'Score_Upload_Form'}
2749: </form>
2750: NEXUFORM
2751:
2752: my $newbulform=(<<NBFORM);
2753: <form action="/adm/coursedocs" method="post" name="newbul">
2754: <input type="hidden" name="active" value="cc" />
2755: $uploadtag
2756: <input type="hidden" name="importdetail" value="" />
2757: <a class="LC_menubuttons_link" href="javascript:makebulboard();" >$lt{'bull'}</a>
2758: $help{'Bulletin Board'}
2759: </form>
2760: NBFORM
2761:
2762: my $newaboutmeform=(<<NAMFORM);
2763: <form action="/adm/coursedocs" method="post" name="newaboutme">
2764: <input type="hidden" name="active" value="cc" />
2765: $uploadtag
2766: <input type="hidden" name="importdetail"
2767: value="$plainname=/adm/$udom/$uname/aboutme" />
2768: <a class="LC_menubuttons_link" href="javascript:document.newaboutme.submit()">$lt{'mypi'}</a>
2769: $help{'My Personal Information Page'}
2770: </form>
2771: NAMFORM
2772:
2773: my $newaboutsomeoneform=(<<NASOFORM);
2774: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
2775: <input type="hidden" name="active" value="cc" />
2776: $uploadtag
2777: <input type="hidden" name="importdetail" value="" />
2778: <a class="LC_menubuttons_link" href="javascript:makeabout();">$lt{'abou'}</a>
2779: </form>
2780: NASOFORM
2781:
2782:
2783: my $newrosterform=(<<NROSTFORM);
2784: <form action="/adm/coursedocs" method="post" name="newroster">
2785: <input type="hidden" name="active" value="cc" />
2786: $uploadtag
2787: <input type="hidden" name="importdetail"
2788: value="$lt{'rost'}=/adm/viewclasslist" />
2789: <a class="LC_menubuttons_link" href="javascript:document.newroster.submit()">$lt{'rost'}</a>
2790: $help{'Course Roster'}
2791: </form>
2792: NROSTFORM
2793:
2794: my $specialdocumentsform;
2795: my @specialdocumentsforma;
2796: my $gradingform;
2797: my @gradingforma;
2798: my $communityform;
2799: my @communityforma;
2800: my $newfolderform;
2801: my $newfolderb;
2802:
2803: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
2804:
2805: my $newpageform=(<<NPFORM);
2806: <form action="/adm/coursedocs" method="post" name="newpage">
2807: <input type="hidden" name="folderpath" value="$path" />
2808: <input type="hidden" name="importdetail" value="" />
2809: <input type="hidden" name="active" value="cc" />
2810: <a class="LC_menubuttons_link" href="javascript:makenewpage(document.newpage,'$pageseq');">$lt{'newp'}</a>
2811: $help{'Adding_Pages'}
2812: </form>
2813: NPFORM
2814:
2815:
2816: $newfolderform=(<<NFFORM);
2817: <form action="/adm/coursedocs" method="post" name="newfolder">
2818: <input type="hidden" name="folderpath" value="$path" />
2819: <input type="hidden" name="importdetail" value="" />
2820: <input type="hidden" name="active" value="aa" />
2821: <a href="javascript:makenewfolder(document.newfolder,'$folderseq');">$lt{'newf'}</a>$help{'Adding_Folders'}
2822: </form>
2823: NFFORM
2824:
2825: my $newsylform=(<<NSYLFORM);
2826: <form action="/adm/coursedocs" method="post" name="newsyl">
2827: <input type="hidden" name="active" value="cc" />
2828: $uploadtag
2829: <input type="hidden" name="importdetail"
2830: value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />
2831: <a class="LC_menubuttons_link" href="javascript:document.newsyl.submit()">$lt{'syll'}</a>
2832: $help{'Syllabus'}
2833:
2834: </form>
2835: NSYLFORM
2836:
2837: my $newgroupfileform=(<<NGFFORM);
2838: <form action="/adm/coursedocs" method="post" name="newgroupfiles">
2839: <input type="hidden" name="active" value="cc" />
2840: $uploadtag
2841: <input type="hidden" name="importdetail"
2842: value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
2843: <a class="LC_menubuttons_link" href="javascript:document.newgroupfiles.submit()">$lt{'grpo'}</a>
2844: $help{'Group Portfolio'}
2845: </form>
2846: NGFFORM
2847: @specialdocumentsforma=(
2848: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/page.png" alt="'.$lt{newp}.'" onclick="javascript:makenewpage(document.newpage,\''.$pageseq.'\');" />'=>$newpageform},
2849: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="document.newsyl.submit()" />'=>$newsylform},
2850: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/navigation.png" alt="'.$lt{navc}.'" onclick="document.newnav.submit()" />'=>$newnavform},
2851: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simple.png" alt="'.$lt{sipa}.'" onclick="javascript:makesmppage();" />'=>$newsmppageform},
2852: );
2853: $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma));
2854:
2855:
2856: my @importdoc = (
2857: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="javascript:makenewext(\'newext\');" />'=>$extresourcesform},
2858: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/ims.png" alt="'.$lt{imsf}.'" onclick="javascript:makeims();" />'=>$imspform},);
2859: $fileuploadform = &create_form_ul(&create_list_elements(@importdoc)) . '<hr id="cc_hrule" style="width:0px;text-align:left;margin-left:0" />' . $fileuploadform;
2860:
2861: @gradingforma=(
2862: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{sipr}.'" onclick="javascript:makesmpproblem();" />'=>$newsmpproblemform},
2863: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/dropbox.png" alt="'.$lt{drbx}.'" onclick="javascript:makedropbox();" />'=>$newdropboxform},
2864: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/scoreupfrm.png" alt="'.$lt{scuf}.'" onclick="javascript:makeexamupload();" />'=>$newexuploadform},
2865:
2866: );
2867: $gradingform = &create_form_ul(&create_list_elements(@gradingforma));
2868:
2869: @communityforma=(
2870: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/bchat.png" alt="'.$lt{bull}.'" onclick="javascript:makebulboard();" />'=>$newbulform},
2871: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makebulboard();" />'=>$newaboutmeform},
2872: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/aboutme.png" alt="'.$lt{abou}.'" onclick="javascript:makeabout();" />'=>$newaboutsomeoneform},
2873: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/clst.png" alt="'.$lt{rost}.'" onclick="document.newroster.submit()" />'=>$newrosterform},
2874: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/groupportfolio.png" alt="'.$lt{grpo}.'" onclick="document.newgroupfiles.submit()" />'=>$newgroupfileform},
2875: );
2876: $communityform = &create_form_ul(&create_list_elements(@communityforma));
2877:
2878: my %orderhash = (
2879: 'aa' => ['Import Documents',$fileuploadform],
2880: 'bb' => ['Published Resources',$simpleeditdefaultform],
2881: 'cc' => ['Grading Resources',$gradingform],
2882: );
2883: unless ($env{'form.pagepath'}) {
2884: $orderhash{'00'} = ['Newfolder',$newfolderform];
2885: $orderhash{'dd'} = ['Collaboration',$communityform];
2886: $orderhash{'ee'} = ['Special Documents',$specialdocumentsform];
2887: }
2888:
2889: $hadchanges=0;
2890: unless (($supplementalflag || $toolsflag)) {
2891: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
2892: $supplementalflag,\%orderhash,$iconpath);
2893: if ($error) {
2894: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
2895: }
2896: if ($hadchanges) {
2897: &mark_hash_old();
2898: }
2899:
2900: &changewarning($r,'');
2901: }
2902: }
2903:
2904: # Supplemental documents start here
2905:
2906: my $folder=$env{'form.folder'};
2907: unless ($supplementalflag) {
2908: $folder='supplemental';
2909: }
2910: if ($folder =~ /^supplemental$/ &&
2911: (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
2912: $env{'form.folderpath'} = &supplemental_base();
2913: } elsif ($allowed) {
2914: $env{'form.folderpath'} = $savefolderpath;
2915: }
2916: $env{'form.pagepath'} = '';
2917: if ($allowed) {
2918: my $folderseq=
2919: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_'.time.
2920: '.sequence';
2921:
2922: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
2923:
2924: my $supupdocformbtn = "<input type='submit' value='".$lt{'upld'}."' />$help{'Uploading_From_Harddrive'}";
2925: my $supupdocform=(<<SUPDOCFORM);
2926: <form action="/adm/coursedocs" method="post" name="supuploaddocument" enctype="multipart/form-data">
2927: <input type="hidden" name="active" value="ee" />
2928: $fileupload
2929: <br />
2930: <br />
2931: <span class="LC_nobreak">
2932: $checkbox
2933: </span>
2934: <br /><br />
2935: $lt{'comment'}:<br />
2936: <textarea cols="50" rows="4" name="comment"></textarea>
2937: <br />
2938: <input type="hidden" name="folderpath" value="$path" />
2939: <input type="hidden" name="cmd" value="upload_supplemental" />
2940: SUPDOCFORM
2941: $supupdocform .= &create_form_ul(&Apache::lonhtmlcommon::htmltag('li',$supupdocformbtn,{class => 'LC_menubuttons_inline_text'}))."</form>";
2942:
2943: my $supnewfolderform=(<<SNFFORM);
2944: <form action="/adm/coursedocs" method="post" name="supnewfolder">
2945: <input type="hidden" name="active" value="ee" />
2946: <input type="hidden" name="folderpath" value="$path" />
2947: <input type="hidden" name="importdetail" value="" />
2948: <a class="LC_menubuttons_link" href="javascript:makenewfolder(document.supnewfolder,'$folderseq');">$lt{'newf'}</a>
2949: $help{'Adding_Folders'}
2950: </form>
2951: SNFFORM
2952:
2953:
2954: my $supnewextform=(<<SNEFORM);
2955: <form action="/adm/coursedocs" method="post" name="supnewext">
2956: <input type="hidden" name="active" value="ff" />
2957: <input type="hidden" name="folderpath" value="$path" />
2958: <input type="hidden" name="importdetail" value="" />
2959: <a class="LC_menubuttons_link" href="javascript:makenewext('supnewext');">$lt{'extr'}</a> $help{'Adding_External_Resource'}
2960: </form>
2961: SNEFORM
2962:
2963: my $supnewsylform=(<<SNSFORM);
2964: <form action="/adm/coursedocs" method="post" name="supnewsyl">
2965: <input type="hidden" name="active" value="ff" />
2966: <input type="hidden" name="folderpath" value="$path" />
2967: <input type="hidden" name="importdetail"
2968: value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
2969: <a class="LC_menubuttons_link" href="javascript:document.supnewsyl.submit()">$lt{'syll'}</a>
2970: $help{'Syllabus'}
2971: </form>
2972: SNSFORM
2973:
2974: my $supnewaboutmeform=(<<SNAMFORM);
2975: <form action="/adm/coursedocs" method="post" name="supnewaboutme">
2976: <input type="hidden" name="active" value="ff" />
2977: <input type="hidden" name="folderpath" value="$path" />
2978: <input type="hidden" name="importdetail"
2979: value="$plainname=/adm/$udom/$uname/aboutme" />
2980: <a class="LC_menubuttons_link" href="javascript:document.supnewaboutme.submit()">$lt{'mypi'}</a>
2981: $help{'My Personal Information Page'}
2982: </form>
2983: SNAMFORM
2984:
2985:
2986: my @specialdocs = (
2987: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="document.supnewsyl.submit()" />'
2988: =>$supnewsylform},
2989: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="document.supnewaboutme.submit()" />'
2990: =>$supnewaboutmeform},
2991: );
2992: my @supimportdoc = (
2993: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="javascript:makenewext(\'supnewext\');" />'
2994: =>$supnewextform},
2995: );
2996: $supupdocform = &create_form_ul(&create_list_elements(@supimportdoc)) . '<hr id="ee_hrule" style="width:0px;text-align:left;margin-left:0" />' . $supupdocform;
2997: my %suporderhash = (
2998: '00' => ['Supnewfolder', $supnewfolderform],
2999: 'ee' => ['Import Documents',$supupdocform],
3000: 'ff' => ['Special Documents',&create_form_ul(&create_list_elements(@specialdocs))]
3001: );
3002: if ($supplementalflag) {
3003: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
3004: $supplementalflag,\%suporderhash,$iconpath);
3005: if ($error) {
3006: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
3007: }
3008: }
3009: } elsif ($supplementalflag) {
3010: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
3011: $supplementalflag,'',$iconpath);
3012: if ($error) {
3013: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
3014: }
3015: }
3016:
3017: $r->print(&endContentScreen());
3018:
3019: if ($allowed) {
3020: $r->print('
3021: <form method="post" name="extimport" action="/adm/coursedocs">
3022: <input type="hidden" name="title" />
3023: <input type="hidden" name="url" />
3024: <input type="hidden" name="useform" />
3025: <input type="hidden" name="residx" />
3026: </form>');
3027: }
3028: } elsif ($showdoc) {
3029: # -------------------------------------------------------- This is showdoc mode
3030: $r->print("<h1>".&mt('Uploaded Document').' - '.
3031: &Apache::lonnet::gettitle($r->uri).'</h1><p>'.
3032: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><table>".
3033: &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');
3034: }
3035: }
3036: $r->print(&Apache::loncommon::end_page());
3037: return OK;
3038: }
3039:
3040: sub embedded_form_elems {
3041: my ($phase,$primaryurl,$newidx) = @_;
3042: my $folderpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3043: return <<STATE;
3044: <input type="hidden" name="folderpath" value="$folderpath" />
3045: <input type="hidden" name="cmd" value="upload_embedded" />
3046: <input type="hidden" name="newidx" value="$newidx" />
3047: <input type="hidden" name="phase" value="$phase" />
3048: <input type="hidden" name="primaryurl" value="$primaryurl" />
3049: STATE
3050: }
3051:
3052: sub embedded_destination {
3053: my $folder=$env{'form.folder'};
3054: my $destination = 'docs/';
3055: if ($folder =~ /^supplemental/) {
3056: $destination = 'supplemental/';
3057: }
3058: if (($folder eq 'default') || ($folder eq 'supplemental')) {
3059: $destination .= 'default/';
3060: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
3061: $destination .= $2.'/';
3062: }
3063: $destination .= $env{'form.newidx'};
3064: my $dir_root = '/userfiles';
3065: return ($destination,$dir_root);
3066: }
3067:
3068: sub return_to_editor {
3069: my $actionurl = '/adm/coursedocs';
3070: return '<p><form name="backtoeditor" method="post" action="'.$actionurl.'" />'."\n".
3071: '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" /></form>'."\n".
3072: '<a href="javascript:document.backtoeditor.submit();">'.&mt('Return to Editor').
3073: '</a></p>';
3074: }
3075:
3076: sub decompression_info {
3077: my ($destination,$dir_root) = &embedded_destination();
3078: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
3079: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
3080: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
3081: my $container='sequence';
3082: my ($pathitem,$hiddenelem);
3083: my @hiddens = ('newidx','comment','position');
3084: if ($env{'form.pagepath'}) {
3085: $container='page';
3086: $pathitem = 'pagepath';
3087: } else {
3088: $pathitem = 'folderpath';
3089: }
3090: unshift(@hiddens,$pathitem);
3091: foreach my $item (@hiddens) {
3092: if ($env{'form.'.$item}) {
3093: $hiddenelem .= '<input type="hidden" name="'.$item.'" value="'.
3094: $env{'form.'.$item}.'" />'."\n";
3095: }
3096: }
3097: return ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,
3098: $hiddenelem);
3099: }
3100:
3101: sub decompression_phase_one {
3102: my ($dir,$file,$warning,$error,$output);
3103: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
3104: &decompression_info();
3105: if ($env{'form.archiveurl'} !~ m{^/uploaded/\Q$docudom/$docuname/docs/\E(?:default|supplemental|\d+).*/([^/]+)$}) {
3106: $error = &mt('Archive file "[_1]" not in the expected location.',$env{'form.archiveurl'});
3107: } else {
3108: my $file = $1;
3109: $output =
3110: &Apache::loncommon::process_decompression($docudom,$docuname,$file,
3111: $destination,$dir_root,
3112: $hiddenelem);
3113: if ($env{'form.autoextract_camtasia'}) {
3114: $output .= &remove_archive($docudom,$docuname,$container);
3115: }
3116: }
3117: if ($error) {
3118: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
3119: $error.'</p>'."\n";
3120: }
3121: if ($warning) {
3122: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
3123: }
3124: return $output;
3125: }
3126:
3127: sub decompression_phase_two {
3128: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
3129: &decompression_info();
3130: my $output;
3131: if ($env{'form.archivedelete'}) {
3132: $output = &remove_archive($docudom,$docuname,$container);
3133: }
3134: $output .=
3135: &Apache::loncommon::process_extracted_files('coursedocs',$docudom,$docuname,
3136: $destination,$dir_root,$hiddenelem);
3137: return $output;
3138: }
3139:
3140: sub remove_archive {
3141: my ($docudom,$docuname,$container) = @_;
3142: my $map = $env{'form.folder'}.'.'.$container;
3143: my ($output,$delwarning,$delresult,$url);
3144: my ($errtext,$fatal) = &mapread($docuname,$docudom,$map);
3145: if ($fatal) {
3146: if ($container eq 'page') {
3147: $delwarning = &mt('An error occurred retrieving the contents of the current page.');
3148: } else {
3149: $delwarning = &mt('An error occurred retrieving the contents of the current folder.');
3150: }
3151: $delwarning .= &mt('As a result the archive file has not been removed.');
3152: } else {
3153: my $currcmd = $env{'form.cmd'};
3154: my $position = $env{'form.position'};
3155: if ($position > 0) {
3156: $env{'form.cmd'} = 'del_'.$position;
3157: my ($title,$url,@rrest) =
3158: split(/:/,$LONCAPA::map::resources[$LONCAPA::map::order[$position]]);
3159: if (&handle_edit_cmd($docuname,$docudom)) {
3160: ($errtext,$fatal) = &storemap($docuname,$docudom,$map);
3161: if ($fatal) {
3162: if ($container eq 'page') {
3163: $delwarning = &mt('An error occurred updating the contents of the current page.');
3164: } else {
3165: $delwarning = &mt('An error occurred updating the contents of the current folder.');
3166: }
3167: } else {
3168: $delresult = &mt('Archive file removed.');
3169: }
3170: }
3171: }
3172: $env{'form.cmd'} = $currcmd;
3173: }
3174: if ($delwarning) {
3175: $output = '<p class="LC_warning">'.
3176: $delwarning.
3177: '</p>';
3178: }
3179: if ($delresult) {
3180: $output .= '<p class="LC_info">'.
3181: $delresult.
3182: '</p>';
3183: }
3184: return $output;
3185: }
3186:
3187: sub generate_admin_menu {
3188: my ($crstype) = @_;
3189: my $lc_crstype = lc($crstype);
3190: my ($home,$other,%outhash)=&authorhosts();
3191: my %lt=&Apache::lonlocal::texthash (
3192: 'vc' => 'Verify Content',
3193: 'cv' => 'Check/Set Resource Versions',
3194: 'ls' => 'List Resource Identifiers',
3195: 'imse' => 'Export contents to IMS Archive',
3196: 'dcd' => "Dump $crstype Content to Authoring Space",
3197: );
3198: my ($candump,$dumpurl);
3199: if ($home + $other > 0) {
3200: $candump = 'F';
3201: if ($home) {
3202: $dumpurl = "javascript:injectData(document.courseverify,'dummy','dumpcourse','$lt{'dcd'}')";
3203: } else {
3204: my @hosts;
3205: foreach my $aurole (keys(%outhash)) {
3206: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
3207: push(@hosts,$outhash{$aurole});
3208: }
3209: }
3210: if (@hosts == 1) {
3211: my $switchto = '/adm/switchserver?otherserver='.$hosts[0].
3212: '&role='.
3213: &HTML::Entities::encode($env{'request.role'},'"<>&').'&origurl='.
3214: &HTML::Entities::encode('/adm/coursedocs?dumpcourse=1','"<>&');
3215: $dumpurl = "javascript:dump_needs_switchserver('$switchto')";
3216: } else {
3217: $dumpurl = "javascript:choose_switchserver_window()";
3218: }
3219: }
3220: }
3221: my @menu=
3222: ({ categorytitle=>'Administration',
3223: items =>[
3224: { linktext => $lt{'vc'},
3225: url => "javascript:injectData(document.courseverify,'dummy','verify','$lt{'vc'}')",
3226: permission => 'F',
3227: help => 'Verify_Content',
3228: icon => 'verify.png',
3229: linktitle => 'Verify contents can be retrieved/rendered',
3230: },
3231: { linktext => $lt{'cv'},
3232: url => "javascript:injectData(document.courseverify,'dummy','versions','$lt{'cv'}')",
3233: permission => 'F',
3234: help => 'Check_Resource_Versions',
3235: icon => 'resversion.png',
3236: linktitle => "View version information for resources in your $lc_crstype, and fix/unfix use of specific versions",
3237: },
3238: { linktext => $lt{'ls'},
3239: url => "javascript:injectData(document.courseverify,'dummy','listsymbs','$lt{'ls'}')",
3240: permission => 'F',
3241: #help => '',
3242: icon => 'symbs.png',
3243: linktitle => "List the unique identifier used for each resource instance in your $lc_crstype"
3244: },
3245: ]
3246: },
3247: { categorytitle=>'Export',
3248: items =>[
3249: { linktext => $lt{'imse'},
3250: url => "javascript:injectData(document.courseverify,'dummy','exportcourse','$lt{'imse'}')",
3251: permission => 'F',
3252: help => 'Docs_Export_Course_Docs',
3253: icon => 'imsexport.png',
3254: linktitle => $lt{'imse'},
3255: },
3256: { linktext => $lt{'dcd'},
3257: url => $dumpurl,
3258: permission => $candump,
3259: #help => '',
3260: icon => 'dump.png',
3261: linktitle => $lt{'dcd'},
3262: },
3263: ]
3264: });
3265: return '<form action="/adm/coursedocs" method="post" name="courseverify">'."\n".
3266: '<input type="hidden" id="dummy" />'."\n".
3267: &Apache::lonhtmlcommon::generate_menu(@menu)."\n".
3268: '</form>';
3269: }
3270:
3271: sub generate_edit_table {
3272: my ($tid,$orderhash_ref,$to_show,$iconpath,$jumpto,$readfile) = @_;
3273: return unless(ref($orderhash_ref) eq 'HASH');
3274: my %orderhash = %{$orderhash_ref};
3275: my $form;
3276: my $activetab;
3277: my $active;
3278: if($env{'form.active'} ne ''){
3279: $activetab = $env{'form.active'};
3280: }
3281: my $backicon = $iconpath.'clickhere.gif';
3282: my $backtext = &mt('To Overview');
3283: $form = '<div class="LC_Box" style="margin:0;">'.
3284: '<ul id="navigation'.$tid.'" class="LC_TabContent">'."\n".
3285: '<li class="goback">'.
3286: '<a href="javascript:toContents('."'$jumpto'".');">'.
3287: '<img src="'.$backicon.'" class="LC_icon" style="border: none; vertical-align: top;"'.
3288: ' alt="'.$backtext.'" />'.$backtext.'</a></li>'."\n";
3289: if ($tid == 1) {
3290: $form .= '<li>'.
3291: '<a href="javascript:groupopen('."'$readfile'".',1);">'.
3292: &mt('Undo Delete').'</a></li>'."\n";
3293: if ($env{'form.docslog'}) {
3294: $form .= '<li class="active">';
3295: } else {
3296: $form .= '<li>';
3297: }
3298: $form .= '<a href="javascript:toggleHistoryDisp(1);">'.
3299: &mt('History').'</a></li>'."\n";
3300: if ($env{'form.docslog'}) {
3301: $form .= '<li><a href="javascript:toggleHistoryDisp(0);">'.
3302: &mt('Edit').'</a></li>'."\n";
3303: }
3304: }
3305: foreach my $name (reverse(sort(keys(%orderhash)))) {
3306: if($name ne '00'){
3307: if($activetab eq '' || $activetab ne $name){
3308: $active = '';
3309: }elsif($activetab eq $name){
3310: $active = 'class="active"';
3311: }
3312: $form .= '<li style="float:right" '.$active
3313: .' onmouseover="javascript:showPage(this, \''.$name.$tid.'\', \'navigation'.$tid.'\',\'content'.$tid.'\');"'
3314: .' onclick="javascript:showPage(this, \''.$name.$tid.'\', \'navigation'.$tid.'\',\'content'.$tid.'\');"><a href="javascript:;"><b>'.&mt(${$orderhash{$name}}[0]).'</b></a></li>'."\n";
3315: } else {
3316: $form .= '<li '.$active.' style="float:right">'.${$orderhash{$name}}[1].'</li>'."\n";
3317:
3318: }
3319: }
3320: $form .= '</ul>'."\n";
3321: $form .= '<div id="content'.$tid.'" style="padding: 0 0; margin: 0 0; overflow: hidden; clear:right">'."\n";
3322:
3323: if ($to_show ne '') {
3324: $form .= '<div style="padding:0;margin:0;float:left">'.$to_show.'</div>'."\n";
3325: }
3326: foreach my $field (keys(%orderhash)){
3327: if($field ne '00'){
3328: if($activetab eq '' || $activetab ne $field){
3329: $active = 'style="display: none;float:left"';
3330: }elsif($activetab eq $field){
3331: $active = 'style="display:block;float:left"';
3332: }
3333: $form .= '<div id="'.$field.$tid.'"'
3334: .' class="LC_ContentBox" '.$active.'>'.${$orderhash{$field}}[1]
3335: .'</div>'."\n";
3336: }
3337: }
3338: unless ($env{'form.docslog'}) {
3339: $form .= '</div></div>'."\n";
3340: }
3341: return $form;
3342: }
3343:
3344: sub editing_js {
3345: my ($udom,$uname,$supplementalflag) = @_;
3346: my $now = time();
3347: my %lt = &Apache::lonlocal::texthash(
3348: p_mnf => 'Name of New Folder',
3349: t_mnf => 'New Folder',
3350: p_mnp => 'Name of New Page',
3351: t_mnp => 'New Page',
3352: p_mxu => 'Title for the External Score',
3353: p_msp => 'Name of Simple Course Page',
3354: p_msb => 'Title for the Problem',
3355: p_mdb => 'Title for the Drop Box',
3356: p_mbb => 'Title for the Discussion Board',
3357: p_mab => "Enter user:domain for User's Personal Information Page",
3358: p_mab2 => 'Personal Information Page of ',
3359: p_mab_alrt1 => 'Not a valid user:domain',
3360: p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',
3361: p_chn => 'New Title',
3362: p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',
3363: p_rmr2a => 'Remove[_99]',
3364: p_rmr2b => '?[_99]',
3365: p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',
3366: p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',
3367: p_ctr2a => 'Cut[_98]',
3368: p_ctr2b => '?[_98]',
3369: rpck => 'Enter number to pick (e.g., 3)',
3370: );
3371:
3372: my $crstype = &Apache::loncommon::course_type();
3373: my $docs_folderpath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'},'<>&"');
3374: my $docs_pagepath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.pagepath'},'<>&"');
3375: my $main_container_page;
3376: if ($docs_folderpath eq '') {
3377: if ($docs_pagepath ne '') {
3378: $main_container_page = 1;
3379: }
3380: }
3381: my $toplevelmain = 'default&Main%20'.$crstype.'%20Documents';
3382: my $toplevelsupp = &supplemental_base();
3383:
3384: my $backtourl = '/adm/navmaps';
3385: if ($supplementalflag) {
3386: $backtourl = '/adm/supplemental';
3387: }
3388:
3389: return <<ENDNEWSCRIPT;
3390: function makenewfolder(targetform,folderseq) {
3391: var foldername=prompt('$lt{"p_mnf"}','$lt{"t_mnf"}');
3392: if (foldername) {
3393: targetform.importdetail.value=escape(foldername)+"="+folderseq;
3394: targetform.submit();
3395: }
3396: }
3397:
3398: function makenewpage(targetform,folderseq) {
3399: var pagename=prompt('$lt{"p_mnp"}','$lt{"t_mnp"}');
3400: if (pagename) {
3401: targetform.importdetail.value=escape(pagename)+"="+folderseq;
3402: targetform.submit();
3403: }
3404: }
3405:
3406: function makenewext(targetname) {
3407: this.document.forms.extimport.useform.value=targetname;
3408: this.document.forms.extimport.title.value='';
3409: this.document.forms.extimport.url.value='';
3410: this.document.forms.extimport.residx.value='';
3411: window.open('/adm/rat/extpickframe.html');
3412: }
3413:
3414: function edittext(targetname,residx,title,url) {
3415: this.document.forms.extimport.useform.value=targetname;
3416: this.document.forms.extimport.residx.value=residx;
3417: this.document.forms.extimport.url.value=url;
3418: this.document.forms.extimport.title.value=title;
3419: window.open('/adm/rat/extpickframe.html');
3420: }
3421:
3422: function makeexamupload() {
3423: var title=prompt('$lt{"p_mxu"}');
3424: if (title) {
3425: this.document.forms.newexamupload.importdetail.value=
3426: escape(title)+'=/res/lib/templates/examupload.problem';
3427: this.document.forms.newexamupload.submit();
3428: }
3429: }
3430:
3431: function makesmppage() {
3432: var title=prompt('$lt{"p_msp"}');
3433: if (title) {
3434: this.document.forms.newsmppg.importdetail.value=
3435: escape(title)+'=/adm/$udom/$uname/$now/smppg';
3436: this.document.forms.newsmppg.submit();
3437: }
3438: }
3439:
3440: function makesmpproblem() {
3441: var title=prompt('$lt{"p_msb"}');
3442: if (title) {
3443: this.document.forms.newsmpproblem.importdetail.value=
3444: escape(title)+'=/res/lib/templates/simpleproblem.problem';
3445: this.document.forms.newsmpproblem.submit();
3446: }
3447: }
3448:
3449: function makedropbox() {
3450: var title=prompt('$lt{"p_mdb"}');
3451: if (title) {
3452: this.document.forms.newdropbox.importdetail.value=
3453: escape(title)+'=/res/lib/templates/DropBox.problem';
3454: this.document.forms.newdropbox.submit();
3455: }
3456: }
3457:
3458: function makebulboard() {
3459: var title=prompt('$lt{"p_mbb"}');
3460: if (title) {
3461: this.document.forms.newbul.importdetail.value=
3462: escape(title)+'=/adm/$udom/$uname/$now/bulletinboard';
3463: this.document.forms.newbul.submit();
3464: }
3465: }
3466:
3467: function makeabout() {
3468: var user=prompt("$lt{'p_mab'}");
3469: if (user) {
3470: var comp=new Array();
3471: comp=user.split(':');
3472: if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
3473: if ((comp[0]) && (comp[1])) {
3474: this.document.forms.newaboutsomeone.importdetail.value=
3475: '$lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
3476: this.document.forms.newaboutsomeone.submit();
3477: } else {
3478: alert("$lt{'p_mab_alrt1'}");
3479: }
3480: } else {
3481: alert("$lt{'p_mab_alrt2'}");
3482: }
3483: }
3484: }
3485:
3486: function makeims() {
3487: var caller = document.forms.ims.folder.value;
3488: var newlocation = "/adm/imsimportdocs?folder="+caller+"&phase=one";
3489: newWindow = window.open("","IMSimport","HEIGHT=700,WIDTH=750,scrollbars=yes");
3490: newWindow.location.href = newlocation;
3491: }
3492:
3493: function finishpick() {
3494: var title=this.document.forms.extimport.title.value;
3495: var url=this.document.forms.extimport.url.value;
3496: var form=this.document.forms.extimport.useform.value;
3497: var residx=this.document.forms.extimport.residx.value;
3498: eval('this.document.forms.'+form+'.importdetail.value="'+title+'='+url+'='+residx+'";this.document.forms.'+form+'.submit();');
3499: }
3500:
3501: function changename(folderpath,index,oldtitle,container,pagesymb) {
3502: var title=prompt('$lt{"p_chn"}',oldtitle);
3503: if (title) {
3504: this.document.forms.renameform.markcopy.value=-1;
3505: this.document.forms.renameform.title.value=title;
3506: this.document.forms.renameform.cmd.value='rename_'+index;
3507: if (container == 'sequence') {
3508: this.document.forms.renameform.folderpath.value=folderpath;
3509: }
3510: if (container == 'page') {
3511: this.document.forms.renameform.pagepath.value=folderpath;
3512: this.document.forms.renameform.pagesymb.value=pagesymb;
3513: }
3514: this.document.forms.renameform.submit();
3515: }
3516: }
3517:
3518: function removeres(folderpath,index,oldtitle,container,pagesymb,skip_confirm) {
3519: if (skip_confirm || confirm('$lt{"p_rmr1"}\\n\\n$lt{"p_rmr2a"} "'+oldtitle+'" $lt{"p_rmr2b"}')) {
3520: this.document.forms.renameform.markcopy.value=-1;
3521: this.document.forms.renameform.cmd.value='del_'+index;
3522: if (container == 'sequence') {
3523: this.document.forms.renameform.folderpath.value=folderpath;
3524: }
3525: if (container == 'page') {
3526: this.document.forms.renameform.pagepath.value=folderpath;
3527: this.document.forms.renameform.pagesymb.value=pagesymb;
3528: }
3529: this.document.forms.renameform.submit();
3530: }
3531: }
3532:
3533: function cutres(folderpath,index,oldtitle,container,pagesymb,folder,skip_confirm) {
3534: if (skip_confirm || confirm('$lt{"p_ctr1a"}\\n$lt{"p_ctr1b"}\\n\\n$lt{"p_ctr2a"} "'+oldtitle+'" $lt{"p_ctr2b"}')) {
3535: this.document.forms.renameform.cmd.value='cut_'+index;
3536: this.document.forms.renameform.markcopy.value=index;
3537: this.document.forms.renameform.copyfolder.value=folder+'.'+container;
3538: if (container == 'sequence') {
3539: this.document.forms.renameform.folderpath.value=folderpath;
3540: }
3541: if (container == 'page') {
3542: this.document.forms.renameform.pagepath.value=folderpath;
3543: this.document.forms.renameform.pagesymb.value=pagesymb;
3544: }
3545: this.document.forms.renameform.submit();
3546: }
3547: }
3548:
3549: function markcopy(folderpath,index,oldtitle,container,pagesymb,folder) {
3550: this.document.forms.renameform.markcopy.value=index;
3551: this.document.forms.renameform.copyfolder.value=folder+'.'+container;
3552: if (container == 'sequence') {
3553: this.document.forms.renameform.folderpath.value=folderpath;
3554: }
3555: if (container == 'page') {
3556: this.document.forms.renameform.pagepath.value=folderpath;
3557: this.document.forms.renameform.pagesymb.value=pagesymb;
3558: }
3559: this.document.forms.renameform.submit();
3560: }
3561:
3562: function updatePick(targetform,index,caller) {
3563: var pickitem = document.getElementById('rpick_'+index);
3564: var picknumitem = document.getElementById('rpicknum_'+index);
3565: if (pickitem.checked) {
3566: var picknum=prompt('$lt{"rpck"}',picknumitem.value);
3567: if (picknum == '' || picknum == null) {
3568: if (caller == 'check') {
3569: pickitem.checked=false;
3570: return;
3571: }
3572: } else {
3573: picknum.toString();
3574: var regexdigit=/^\\d+\$/;
3575: if (regexdigit.test(picknum)) {
3576: picknumitem.value = picknum;
3577: targetform.changeparms.value='randompick';
3578: targetform.submit();
3579: } else {
3580: if (caller == 'check') {
3581: pickitem.checked=false;
3582: }
3583: return;
3584: }
3585: }
3586: } else {
3587: picknumitem.value = 0;
3588: targetform.changeparms.value='randompick';
3589: targetform.submit();
3590: }
3591: }
3592:
3593: function unselectInactive(nav) {
3594: currentNav = document.getElementById(nav);
3595: currentLis = currentNav.getElementsByTagName('LI');
3596: for (i = 0; i < currentLis.length; i++) {
3597: if (currentLis[i].className == 'goback') {
3598: currentLis[i].className = 'goback';
3599: } else {
3600: if (currentLis[i].className == 'right active' || currentLis[i].className == 'right') {
3601: currentLis[i].className = 'right';
3602: } else {
3603: currentLis[i].className = 'i';
3604: }
3605: }
3606: }
3607: }
3608:
3609: function hideAll(current, nav, data) {
3610: unselectInactive(nav);
3611: if(current.className == 'right'){
3612: current.className = 'right active'
3613: }else{
3614: current.className = 'active';
3615: }
3616: currentData = document.getElementById(data);
3617: currentDivs = currentData.getElementsByTagName('DIV');
3618: for (i = 0; i < currentDivs.length; i++) {
3619: if(currentDivs[i].className == 'LC_ContentBox'){
3620: currentDivs[i].style.display = 'none';
3621: }
3622: }
3623: }
3624:
3625: function openTabs(pageId) {
3626: tabnav = document.getElementById(pageId).getElementsByTagName('UL');
3627: if(tabnav.length > 2 ){
3628: currentNav = document.getElementById(tabnav[1].id);
3629: currentLis = currentNav.getElementsByTagName('LI');
3630: for(i = 0; i< currentLis.length; i++){
3631: if(currentLis[i].className == 'active') {
3632: funcString = currentLis[i].onclick.toString();
3633: tab = funcString.split('"');
3634: if(tab.length < 2) {
3635: tab = funcString.split("'");
3636: }
3637: currentData = document.getElementById(tab[1]);
3638: currentData.style.display = 'block';
3639: }
3640: }
3641: }
3642: }
3643:
3644: function showPage(current, pageId, nav, data) {
3645: hideAll(current, nav, data);
3646: openTabs(pageId);
3647: unselectInactive(nav);
3648: current.className = 'active';
3649: currentData = document.getElementById(pageId);
3650: currentData.style.display = 'block';
3651: activeTab = pageId;
3652: if (nav == 'mainnav') {
3653: var storedpath = "$docs_folderpath";
3654: if (storedpath == '') {
3655: storedpath = "$docs_pagepath";
3656: }
3657: var storedpage = "$main_container_page";
3658: var reg = new RegExp("^supplemental");
3659: if (pageId == 'mainCourseDocuments') {
3660: if (storedpage == 1) {
3661: document.simpleedit.folderpath.value = '';
3662: document.uploaddocument.folderpath.value = '';
3663: } else {
3664: if (reg.test(storedpath)) {
3665: document.simpleedit.folderpath.value = '$toplevelmain';
3666: document.uploaddocument.folderpath.value = '$toplevelmain';
3667: document.newext.folderpath.value = '$toplevelmain';
3668: } else {
3669: document.simpleedit.folderpath.value = storedpath;
3670: document.uploaddocument.folderpath.value = storedpath;
3671: document.newext.folderpath.value = storedpath;
3672: }
3673: }
3674: } else {
3675: if (reg.test(storedpath)) {
3676: document.simpleedit.folderpath.value = storedpath;
3677: document.supuploaddocument.folderpath.value = storedpath;
3678: document.supnewext.folderpath.value = storedpath;
3679: } else {
3680: document.simpleedit.folderpath.value = '$toplevelsupp';
3681: document.supuploaddocument.folderpath.value = '$toplevelsupp';
3682: document.supnewext.folderpath.value = '$toplevelsupp';
3683: }
3684: }
3685: }
3686: resize_scrollbox('contentscroll','1','0');
3687: return false;
3688: }
3689:
3690: function toContents(jumpto) {
3691: var newurl = '$backtourl';
3692: if (jumpto != '') {
3693: newurl = newurl+'?postdata='+jumpto;
3694: ;
3695: }
3696: location.href=newurl;
3697: }
3698:
3699: ENDNEWSCRIPT
3700: }
3701:
3702: sub history_tab_js {
3703: return <<"ENDHIST";
3704: function toggleHistoryDisp(choice) {
3705: document.docslogform.docslog.value = choice;
3706: document.docslogform.submit();
3707: return;
3708: }
3709:
3710: ENDHIST
3711: }
3712:
3713: sub inject_data_js {
3714: return <<ENDINJECT;
3715:
3716: function injectData(current, hiddenField, name, value) {
3717: currentElement = document.getElementById(hiddenField);
3718: currentElement.name = name;
3719: currentElement.value = value;
3720: current.submit();
3721: }
3722:
3723: ENDINJECT
3724: }
3725:
3726: sub dump_switchserver_js {
3727: my @hosts = @_;
3728: my %lt = &Apache::lonlocal::texthash(
3729: dump => 'Dumping to Authoring Space requires switching server.',
3730: swit => 'Switch server?',
3731: duco => 'Dump content to Authoring Space',
3732: yone => 'You need to switch to a server housing an Authoring Space for which you are author or co-author.',
3733: chos => 'Choose server',
3734: );
3735: my $role = $env{'request.role'};
3736: my $js = <<"ENDSWJS";
3737: <script type="text/javascript">
3738: function write_switchserver() {
3739: var server;
3740: if (document.setserver.posshosts.length > 0) {
3741: for (var i=0; i<document.setserver.posshosts.length; i++) {
3742: if (document.setserver.posshosts[i].checked) {
3743: server = document.setserver.posshosts[i].value;
3744: }
3745: }
3746: opener.document.location.href="/adm/switchserver?otherserver="+server+"&role=$role&origurl=/adm/coursedocs";
3747: }
3748: window.close();
3749: }
3750: </script>
3751:
3752: ENDSWJS
3753:
3754: my $startpage = &Apache::loncommon::start_page('Choose server',$js,
3755: {'only_body' => 1,
3756: 'js_ready' => 1,});
3757: my $endpage = &Apache::loncommon::end_page({'js_ready' => 1});
3758:
3759: my $hostpicker;
3760: my $count = 0;
3761: foreach my $host (sort(@hosts)) {
3762: my $checked;
3763: if ($count == 0) {
3764: $checked = ' checked="checked"';
3765: }
3766: $hostpicker .= '<label><input type="radio" name="posshosts" value="'.
3767: $host.'"'.$checked.' />'.$host.'</label> ';
3768: $count++;
3769: }
3770:
3771: return <<"ENDSWITCHJS";
3772:
3773: function dump_needs_switchserver(url) {
3774: if (url!='' && url!= null) {
3775: if (confirm("$lt{'dump'}\\n$lt{'swit'}")) {
3776: go(url);
3777: }
3778: }
3779: return;
3780: }
3781:
3782: function choose_switchserver_window() {
3783: newWindow = window.open('','ChooseServer','height=400,width=500,scrollbars=yes')
3784: newWindow.document.open();
3785: newWindow.document.writeln('$startpage');
3786: newWindow.document.write('<h3>$lt{'duco'}<\\/h3>\\n'+
3787: '<p>$lt{'yone'}<\\/p>\\n'+
3788: '<div class="LC_left_float"><fieldset><legend>$lt{'chos'}<\\/legend>\\n'+
3789: '<form name="setserver" method="post" action="" \\/>\\n'+
3790: '$hostpicker\\n'+
3791: '<br \\/><br \\/>\\n'+
3792: '<input type="button" name="makeswitch" value="$lt{'swit'}" '+
3793: 'onclick="write_switchserver();" \\/>\\n'+
3794: '<\\/form><\\/fieldset><\\/div><br clear="all" \\/>\\n');
3795: newWindow.document.writeln('$endpage');
3796: newWindow.document.close();
3797: newWindow.focus();
3798: }
3799:
3800: ENDSWITCHJS
3801: }
3802:
3803: sub makedocslogform {
3804: my ($formelems,$docslog) = @_;
3805: return <<"LOGSFORM";
3806: <form action="/adm/coursedocs" method="post" name="docslogform">
3807: <input type="hidden" name="docslog" value="$docslog" />
3808: $formelems
3809: </form>
3810: LOGSFORM
3811: }
3812:
3813: sub makesimpleeditform {
3814: my ($formelems) = @_;
3815: return <<"SIMPFORM";
3816: <form name="simpleedit" method="post" action="/adm/coursedocs">
3817: <input type="hidden" name="importdetail" value="" />
3818: $formelems
3819: </form>
3820: SIMPFORM
3821: }
3822:
3823: 1;
3824: __END__
3825:
3826:
3827: =head1 NAME
3828:
3829: Apache::londocs.pm
3830:
3831: =head1 SYNOPSIS
3832:
3833: This is part of the LearningOnline Network with CAPA project
3834: described at http://www.lon-capa.org.
3835:
3836: =head1 SUBROUTINES
3837:
3838: =over
3839:
3840: =item %help=()
3841:
3842: Available help topics
3843:
3844: =item mapread()
3845:
3846: Mapread read maps into LONCAPA::map:: global arrays
3847: @order and @resources, determines status
3848: sets @order - pointer to resources in right order
3849: sets @resources - array with the resources with correct idx
3850:
3851: =item authorhosts()
3852:
3853: Return hash with valid author names
3854:
3855: =item clean()
3856:
3857: =item dumpcourse()
3858:
3859: Actually dump course
3860:
3861: =item group_import()
3862:
3863: Imports the given (name, url) resources into the course
3864: coursenum, coursedom, and folder must precede the list
3865:
3866: =item breadcrumbs()
3867:
3868: =item log_docs()
3869:
3870: =item docs_change_log()
3871:
3872: =item update_paste_buffer()
3873:
3874: =item print_paste_buffer()
3875:
3876: =item do_paste_from_buffer()
3877:
3878: =item update_parameter()
3879:
3880: =item handle_edit_cmd()
3881:
3882: =item editor()
3883:
3884: =item process_file_upload()
3885:
3886: =item process_secondary_uploads()
3887:
3888: =item is_supplemental_title()
3889:
3890: =item parse_supplemental_title()
3891:
3892: =item entryline()
3893:
3894: =item tiehash()
3895:
3896: =item untiehash()
3897:
3898: =item checkonthis()
3899:
3900: check on this
3901:
3902: =item verifycontent()
3903:
3904: Verify Content
3905:
3906: =item devalidateversioncache() & checkversions()
3907:
3908: Check Versions
3909:
3910: =item mark_hash_old()
3911:
3912: =item is_hash_old()
3913:
3914: =item changewarning()
3915:
3916: =item init_breadcrumbs()
3917:
3918: Breadcrumbs for special functions
3919:
3920: =item create_list_elements()
3921:
3922: =item create_form_ul()
3923:
3924: =item startContentScreen()
3925:
3926: =item endContentScreen()
3927:
3928: =item supplemental_base()
3929:
3930: =item embedded_form_elems()
3931:
3932: =item embedded_destination()
3933:
3934: =item return_to_editor()
3935:
3936: =item decompression_info()
3937:
3938: =item decompression_phase_one()
3939:
3940: =item decompression_phase_two()
3941:
3942: =item remove_archive()
3943:
3944: =item generate_admin_menu()
3945:
3946: =item generate_edit_table()
3947:
3948: =item editing_js()
3949:
3950: =item history_tab_js()
3951:
3952: =item inject_data_js()
3953:
3954: =item dump_switchserver_js()
3955:
3956: =item resize_scrollbox_js()
3957:
3958: =item makedocslogform()
3959:
3960: =item makesimpleeditform()
3961:
3962: =back
3963:
3964: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>