Annotation of loncom/interface/londocs.pm, revision 1.484.2.5
1.329 droeschl 1: # The LearningOnline Network
2: # Documents
3: #
1.484.2.5! raeburn 4: # $Id: londocs.pm,v 1.484.2.4 2012/05/13 22:59:39 raeburn Exp $
1.329 droeschl 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28:
29: package Apache::londocs;
30:
31: use strict;
32: use Apache::Constants qw(:common :http);
33: use Apache::imsexport;
34: use Apache::lonnet;
35: use Apache::loncommon;
1.383 tempelho 36: use Apache::lonhtmlcommon;
1.329 droeschl 37: use LONCAPA::map();
38: use Apache::lonratedt();
39: use Apache::lonxml;
40: use Apache::lonclonecourse;
41: use Apache::lonnavmaps;
1.472 raeburn 42: use Apache::lonnavdisplay();
1.329 droeschl 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); }
1.364 bisitz 75:
1.329 droeschl 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();
1.484 raeburn 103: foreach my $id (@ids) {
104: if ($id eq $myhome) {
105: $allowed=1;
106: last;
107: }
108: }
1.329 droeschl 109: if ($allowed) {
110: $home++;
1.484 raeburn 111: $outhash{'home_'.$ca.':'.$cd}=1;
1.329 droeschl 112: } else {
1.484 raeburn 113: $outhash{'otherhome_'.$ca.':'.$cd}=$myhome;
1.329 droeschl 114: $other++;
115: }
116: }
117: }
118: return ($home,$other,%outhash);
119: }
120:
121:
122: sub clean {
123: my ($title)=@_;
124: $title=~s/[^\w\/\!\$\%\^\*\-\_\=\+\;\:\,\\\|\`\~]+/\_/gs;
1.344 bisitz 125: return $title;
1.329 droeschl 126: }
127:
128:
129:
130: sub dumpcourse {
131: my ($r) = @_;
1.408 raeburn 132: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 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'));
1.329 droeschl 136: my ($home,$other,%outhash)=&authorhosts();
1.484 raeburn 137: unless ($home) {
138: $r->print(&endContentScreen());
139: return '';
140: }
1.329 droeschl 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
1.484 raeburn 145: unless ($outhash{'home_'.$env{'form.authorspace'}}) {
146: $r->print(&endContentScreen());
147: return '';
148: }
1.329 droeschl 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);
1.462 raeburn 168: my $path=$r->dir_config('lonDocRoot')."/priv/$cd/$ca";
1.329 droeschl 169: my $makepath=$path;
170: my $fail=0;
171: for (my $i=0;$i<$#dirs;$i++) {
172: $makepath.='/'.$dirs[$i];
1.344 bisitz 173: unless (-e $makepath) {
174: unless(mkdir($makepath,0777)) { $fail=1; }
1.329 droeschl 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 {
1.484 raeburn 199: $r->print(&mt('Searching ...').'<br />');
200: $r->rflush();
1.329 droeschl 201: # Input form
1.484 raeburn 202: $r->print('<form name="dumpdoc" action="" method="post">'."\n");
1.329 droeschl 203: unless ($home==1) {
1.484 raeburn 204: $r->print('<div class="LC_left_float">'.
205: '<fieldset><legend>'.
206: &mt('Select the Authoring Space').
207: '</legend><select name="authorspace">');
1.329 droeschl 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.' - '.
1.484 raeburn 216: &Apache::loncommon::plainname(split(/\:/,$1)).'</option>');
1.329 droeschl 217: }
218: }
219: }
220: unless ($home==1) {
1.484 raeburn 221: $r->print('</select></fieldset></div>'."\n");
1.329 droeschl 222: }
223: my $title=$origcrsdata{'description'};
224: $title=~s/[\/\s]+/\_/gs;
225: $title=&clean($title);
1.484 raeburn 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");
1.329 droeschl 231: &tiehash();
1.484 raeburn 232: $r->print('<h4>'.&mt('Filenames in Authoring Space').'</h4>'
1.329 droeschl 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(
1.484 raeburn 260: '<p><input type="submit" name="dumpcourse" value="'.&mt("Dump $crstype Content").'" /></p></form>');
1.329 droeschl 261: }
1.484 raeburn 262: $r->print(&endContentScreen());
1.329 droeschl 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) };
1.344 bisitz 270: if (($url =~ m{^/uploaded/\Q$coursedom\E/\Q$coursenum\E/(default_\d+\.)(page|sequence)$})
1.329 droeschl 271: && ($caller eq 'londocs')
272: && (!&Apache::lonnet::stat_file($url))) {
1.364 bisitz 273:
1.329 droeschl 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) {
1.344 bisitz 293: if (!$residx
1.329 droeschl 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);
1.344 bisitz 302: $LONCAPA::map::resources[$residx] =
1.329 droeschl 303: join(':', ($name, $url, $ext, 'normal', 'res'));
304: }
305: }
306: return &storemap($coursenum, $coursedom, $folder.'.'.$container);
307: }
308:
309: sub breadcrumbs {
1.408 raeburn 310: my ($allowed,$crstype)=@_;
1.329 droeschl 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;
1.472 raeburn 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);
1.344 bisitz 338: # randompick number, hidden, encrypted, random order, is appended with ":"s to the foldername
1.472 raeburn 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(
1.329 droeschl 352: {'href'=>$url.$cpinfo,
353: 'title'=>$name,
1.367 droeschl 354: 'text'=>$name,
1.329 droeschl 355: 'no_mt'=>1,
356: });
357: $plain.=$name.' > ';
358: }
359: $plain=~s/\>\;\s*$//;
360: return (&Apache::lonhtmlcommon::breadcrumbs(undef,undef,0,'nohelp',
1.472 raeburn 361: undef, undef, 1 ),$randompick,$ishidden,
362: $isencrypted,$plain,$is_random_order);
1.329 droeschl 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 {
1.484 raeburn 427: my ($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath)=@_;
1.483 raeburn 428: my $js = '<script type="text/javascript">'."\n".
429: '// <![CDATA['."\n".
430: &Apache::loncommon::display_filter_js('docslog')."\n".
431: &history_tab_js()."\n".
1.484 raeburn 432: &Apache::lonratedt::editscript('simple')."\n".
1.483 raeburn 433: '// ]]>'."\n".
434: '</script>'."\n";
1.484 raeburn 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));
1.329 droeschl 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; }
1.452 www 472: # FIXME: internationalization seems wrong here
1.329 droeschl 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');
1.484 raeburn 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" />');
1.329 droeschl 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: }
1.344 bisitz 503: if ($wholeentry!~/\Q$env{'form.containingphrase'}\E/i) { next; }
1.329 droeschl 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: }
1.364 bisitz 554: }
1.329 droeschl 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}) {
1.452 www 566: # FIXME: internationalization seems wrong here
1.329 droeschl 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: }
1.484 raeburn 581: $r->print(&Apache::loncommon::end_data_table()."\n".
582: &makesimpleeditform($pathitem)."\n".
583: '</div></div>');
584: $r->print(&endContentScreen());
1.329 droeschl 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'});
1.364 bisitz 596:
1.329 droeschl 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'}) {
1.346 raeburn 605: &Apache::lonnet::delenv('docs.markedcopy_supplemental');
1.329 droeschl 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:
1.381 bisitz 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: );
1.329 droeschl 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'));
1.380 bisitz 636: $icon .= '/navmap.folder.closed.gif';
1.329 droeschl 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: }
1.381 bisitz 651: $r->print('</form></fieldset>');
1.329 droeschl 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/})) {
1.346 raeburn 710: &Apache::lonnet::delenv('docs.markedcopy');
1.329 droeschl 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);
1.344 bisitz 721: $url =~ s{/(\d*)/smppg$ }{/$now/smppg}x;
1.329 droeschl 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 {
1.344 bisitz 735: (undef,undef,$title) =
1.329 droeschl 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;
1.344 bisitz 759: last;
1.329 droeschl 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);
1.364 bisitz 785:
1.329 droeschl 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/|) &&
1.463 www 801: ($url!~/$LONCAPA::assess_page_seq_re/)) {
1.329 droeschl 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:
1.344 bisitz 812: } elsif ($cmd eq 'up'
1.329 droeschl 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 {
1.458 raeburn 837: my ($r,$coursenum,$coursedom,$folder,$allowed,$upload_output,$crstype,
1.472 raeburn 838: $supplementalflag,$orderhash,$iconpath)=@_;
1.329 droeschl 839: my $container= ($env{'form.pagepath'}) ? 'page'
840: : 'sequence';
841:
1.484 raeburn 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:
1.329 droeschl 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: }
1.364 bisitz 862:
1.329 droeschl 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: }
1.364 bisitz 883:
1.329 droeschl 884: if ($env{'form.pastemarked'}) {
1.344 bisitz 885: my $paste_res =
1.329 droeschl 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>');
1.364 bisitz 929:
1.329 droeschl 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)) {
1.381 bisitz 939: $r->print('<div class="LC_Box">'.
1.432 raeburn 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>':'').
1.431 raeburn 945: '</ol>');
1.381 bisitz 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>');
1.364 bisitz 967: }
1.381 bisitz 968:
1.458 raeburn 969: my ($to_show,$output);
1.424 onken 970:
971: &Apache::loncommon::start_data_table_count(); #setup a row counter
1.381 bisitz 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,
1.408 raeburn 979: $coursenum,$crstype);
1.381 bisitz 980: $idx++;
981: $shown++;
1.329 droeschl 982: }
1.424 onken 983: &Apache::loncommon::end_data_table_count();
984:
1.381 bisitz 985: if ($shown) {
1.458 raeburn 986: $to_show = &Apache::loncommon::start_scrollbox('900px','880px','400px','contentscroll')
987: .&Apache::loncommon::start_data_table(undef,'contentlist');
1.393 raeburn 988: if ($allowed) {
1.458 raeburn 989: $to_show .= &Apache::loncommon::start_data_table_header_row()
1.393 raeburn 990: .'<th colspan="2">'.&mt('Move').'</th>'
991: .'<th>'.&mt('Actions').'</th>'
1.458 raeburn 992: .'<th colspan="2">'.&mt('Document').'</th>';
1.393 raeburn 993: if ($folder !~ /^supplemental/) {
1.458 raeburn 994: $to_show .= '<th colspan="4">'.&mt('Settings').'</th>';
1.393 raeburn 995: }
1.458 raeburn 996: $to_show .= &Apache::loncommon::end_data_table_header_row();
1.393 raeburn 997: }
1.458 raeburn 998: $to_show .= $output.' '
1.393 raeburn 999: .&Apache::loncommon::end_data_table()
1.458 raeburn 1000: .'<br style="line-height:2px;" />'
1001: .&Apache::loncommon::end_scrollbox();
1.393 raeburn 1002: } else {
1.458 raeburn 1003: $to_show .= &Apache::loncommon::start_scrollbox('400px','380px','200px','contentscroll')
1004: .'<div class="LC_info" id="contentlist">'
1.381 bisitz 1005: .&mt('Currently no documents.')
1.458 raeburn 1006: .'</div>'
1007: .&Apache::loncommon::end_scrollbox();
1008: }
1009: my $tid = 1;
1010: if ($supplementalflag) {
1011: $tid = 2;
1.329 droeschl 1012: }
1013: if ($allowed) {
1.484 raeburn 1014: my $readfile="/uploaded/$coursedom/$coursenum/$folder.$container";
1015: $r->print(&generate_edit_table($tid,$orderhash,$to_show,$iconpath,$jumpto,
1016: $readfile));
1.329 droeschl 1017: &print_paste_buffer($r,$container);
1.460 raeburn 1018: } else {
1.472 raeburn 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: }
1.460 raeburn 1032: $r->print($to_show);
1.329 droeschl 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
1.440 raeburn 1040: my ($parseaction,$showupload,$nextphase,$mimetype);
1041: if ($env{'form.parserflag'}) {
1.329 droeschl 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) {
1.457 raeburn 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>';
1.440 raeburn 1063: return;
1.329 droeschl 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: }
1.440 raeburn 1074: # this is for a course, not a user, so set context to coursedoc.
1.329 droeschl 1075: my $newidx=&LONCAPA::map::getresidx();
1076: $destination .= $newidx;
1.439 raeburn 1077: my $url=&Apache::lonnet::userfileupload('uploaddoc','coursedoc',$destination,
1.329 droeschl 1078: $parseaction,$allfiles,
1.440 raeburn 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:
1.457 raeburn 1088: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.&mt('Unable to save file [_1].','<span class="LC_filename">'.$filename.'</span>').'</div>';
1.440 raeburn 1089: return;
1090: }
1.329 droeschl 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) {
1.457 raeburn 1107: $$upload_output = '<div class="LC_error" id="uploadfileresult">'.$errtext.'</div>';
1.440 raeburn 1108: return;
1.329 droeschl 1109: } else {
1.440 raeburn 1110: if ($parseaction eq 'parse' && $mimetype eq 'text/html') {
1111: $$upload_output = $showupload;
1.384 raeburn 1112: my $total_embedded = scalar(keys(%{$allfiles}));
1.329 droeschl 1113: if ($total_embedded > 0) {
1.440 raeburn 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: }
1.329 droeschl 1131: } else {
1.440 raeburn 1132: $$upload_output .= &mt('No embedded items identified').'<br />';
1.329 droeschl 1133: }
1.457 raeburn 1134: $$upload_output = '<div id="uploadfileresult">'.$$upload_output.'</div>';
1.476 raeburn 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,
1.477 raeburn 1147: comment => $comment,
1.480 raeburn 1148: );
1149: my ($destination,$dir_root) = &embedded_destination($coursenum,$coursedom);
1150: my @current = &get_dir_list($url,$coursenum,$coursedom,$newidx);
1.476 raeburn 1151: $$upload_output = $showupload.
1152: &Apache::loncommon::decompress_form($mimetype,
1153: $archiveurl,'/adm/coursedocs',$noextract,
1.480 raeburn 1154: \%archiveitems,\@current);
1.329 droeschl 1155: }
1156: }
1157: }
1.440 raeburn 1158: return $nextphase;
1.329 droeschl 1159: }
1160:
1.480 raeburn 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:
1.329 droeschl 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,'"<>&\'');
1.418 raeburn 1206: $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
1.329 droeschl 1207: $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.
1208: $name.': <br />'.$foldertitle;
1209: }
1210: if (wantarray) {
1211: return ($title,$foldertitle,$renametitle);
1.364 bisitz 1212: }
1.329 droeschl 1213: return $title;
1214: }
1215:
1216: # --------------------------------------------------------------- An entry line
1217:
1218: sub entryline {
1.408 raeburn 1219: my ($index,$title,$url,$folder,$allowed,$residx,$coursenum,$crstype)=@_;
1.329 droeschl 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];
1.364 bisitz 1232:
1.329 droeschl 1233:
1234: $renametitle=~s/\\/\\\\/g;
1235: $renametitle=~s/\"\;/\\\"/g;
1236: $renametitle=~s/ /%20/g;
1.379 bisitz 1237: my $line=&Apache::loncommon::start_data_table_row();
1.478 raeburn 1238: my ($form_start,$form_end,$form_common);
1.329 droeschl 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';
1.440 raeburn 1250: $esc_path=&escape($env{'form.pagepath'});
1.329 droeschl 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='';
1.471 raeburn 1258: if (($#LONCAPA::map::order>0) &&
1.329 droeschl 1259: ((split(/\:/,
1.344 bisitz 1260: $LONCAPA::map::resources[$LONCAPA::map::order[0]]))[1]
1261: ne '') &&
1.329 droeschl 1262: ((split(/\:/,
1.344 bisitz 1263: $LONCAPA::map::resources[$LONCAPA::map::order[1]]))[1]
1.329 droeschl 1264: ne '')) {
1265: $selectbox=
1266: '<input type="hidden" name="currentpos" value="'.$incindex.'" />'.
1.373 bisitz 1267: '<select name="newpos" onchange="this.form.submit()">';
1.329 droeschl 1268: for (my $i=1;$i<=$#LONCAPA::map::order+1;$i++) {
1269: if ($i==$incindex) {
1.358 bisitz 1270: $selectbox.='<option value="" selected="selected">('.$i.')</option>';
1.329 droeschl 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: }
1.344 bisitz 1300: if ($url=~/^\/res\/lib\/templates\//) {
1301: $nocopy=1;
1.329 droeschl 1302: $nocut=1;
1303: }
1304: my $copylink=' ';
1305: my $cutlink=' ';
1.364 bisitz 1306:
1.329 droeschl 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);
1.484 raeburn 1321: <a href="javascript:markcopy('$esc_path','$index','$renametitle','$container','$symb','$folder');" class="LC_docs_copy">$lt{'cp'}</a>
1.329 droeschl 1322: ENDCOPY
1323: }
1324: if (!$nocut) {
1325: $cutlink=(<<ENDCUT);
1.484 raeburn 1326: <a href="javascript:cutres('$esc_path','$index','$renametitle','$container','$symb','$folder',$skip_confirm);" class="LC_docs_cut">$lt{'ct'}</a>
1.329 droeschl 1327: ENDCUT
1328: }
1.478 raeburn 1329: $form_start = '
1330: <form action="/adm/coursedocs" method="post">
1331: ';
1332: $form_common=(<<END);
1.329 droeschl 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>
1.379 bisitz 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>
1.329 droeschl 1351: </td>
1352: <td>
1353: $form_start
1.478 raeburn 1354: $form_common
1.329 droeschl 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) {
1.472 raeburn 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: }
1.329 droeschl 1394: } else {
1395: &Apache::lonnet::allowuploaded('/adm/coursedoc',$url);
1396: }
1397: }
1.364 bisitz 1398:
1.329 droeschl 1399: my $orig_url = $url;
1.340 raeburn 1400: $orig_url=~s{http(:|:)//https(:|:)//}{https$2//};
1.329 droeschl 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: }
1.344 bisitz 1422: } elsif ($url=~m|^/ext/|) {
1.329 droeschl 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'};
1.364 bisitz 1433:
1.329 droeschl 1434: $url=&Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
1435: $url.=(($url=~/\?/)?'&':'?').'symb='.&escape($symb);
1436: }
1437: }
1.478 raeburn 1438: my ($rand_pick_text,$rand_order_text);
1.329 droeschl 1439: if ($isfolder || $extension eq 'sequence') {
1440: my $foldername=&escape($foldertitle);
1441: my $folderpath=$env{'form.folderpath'};
1442: if ($folderpath) { $folderpath.='&' };
1.344 bisitz 1443: # Append randompick number, hidden, and encrypted with ":" to foldername,
1.329 droeschl 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;
1.478 raeburn 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>';
1.329 droeschl 1469: my $ro_set=
1470: ((&LONCAPA::map::getparameter($orderidx,'parameter_randomorder'))[0]=~/^yes$/i?' checked="checked"':'');
1.478 raeburn 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>';
1.329 droeschl 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: }
1.396 raeburn 1494: if (($external) && ($allowed)) {
1.329 droeschl 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: }
1.408 raeburn 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: }
1.469 www 1506: $line.='<td>';
1.472 raeburn 1507: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.469 www 1508: $line.='<a href="'.$url.'"><img src="'.$icon.'" alt="" class="LC_icon" /></a>';
1509: } elsif ($url) {
1.484 raeburn 1510: $line.=&Apache::loncommon::modal_link($url.(($url=~/\?/)?'&':'?').'inhibitmenu=yes',
1.470 raeburn 1511: '<img src="'.$icon.'" alt="" class="LC_icon" />',600,500);
1.469 www 1512: } else {
1513: $line.='<img src="'.$icon.'" alt="" class="LC_icon" />';
1514: }
1515: $line.='</td><td>';
1.472 raeburn 1516: if (($url=~m{/adm/(coursedocs|supplemental)}) || (!$allowed && $url)) {
1.469 www 1517: $line.='<a href="'.$url.'">'.$title.'</a>';
1518: } elsif ($url) {
1.484 raeburn 1519: $line.=&Apache::loncommon::modal_link($url.(($url=~/\?/)?'&':'?').'inhibitmenu=yes',
1.470 raeburn 1520: $title,600,500);
1.469 www 1521: } else {
1522: $line.=$title.' <span class="LC_docs_reinit_warn">'.$reinit.'</span>';
1523: }
1524: $line.=$external."</td>";
1.478 raeburn 1525: $rand_pick_text = ' ' if ($rand_pick_text eq '');
1526: $rand_order_text = ' ' if ($rand_order_text eq '');
1.329 droeschl 1527: if (($allowed) && ($folder!~/^supplemental/)) {
1528: my %lt=&Apache::lonlocal::texthash(
1529: 'hd' => 'Hidden',
1530: 'ec' => 'URL hidden');
1531: my $enctext=
1.358 bisitz 1532: ((&LONCAPA::map::getparameter($orderidx,'parameter_encrypturl'))[0]=~/^yes$/i?' checked="checked"':'');
1.329 droeschl 1533: my $hidtext=
1.358 bisitz 1534: ((&LONCAPA::map::getparameter($orderidx,'parameter_hiddenresource'))[0]=~/^yes$/i?' checked="checked"':'');
1.329 droeschl 1535: $line.=(<<ENDPARMS);
1536: <td class="LC_docs_entry_parameter">
1537: $form_start
1.478 raeburn 1538: $form_common
1.369 bisitz 1539: <label><input type="checkbox" name="hiddenresource_$orderidx" onclick="this.form.changeparms.value='hiddenresource';this.form.submit()" $hidtext /> $lt{'hd'}</label>
1.329 droeschl 1540: $form_end
1.458 raeburn 1541: <br />
1.329 droeschl 1542: $form_start
1.478 raeburn 1543: $form_common
1.369 bisitz 1544: <label><input type="checkbox" name="encrypturl_$orderidx" onclick="this.form.changeparms.value='encrypturl';this.form.submit()" $enctext /> $lt{'ec'}</label>
1.329 droeschl 1545: $form_end
1546: </td>
1.478 raeburn 1547: <td class="LC_docs_entry_parameter">$rand_pick_text<br />
1548: $rand_order_text</td>
1.329 droeschl 1549: ENDPARMS
1550: }
1.379 bisitz 1551: $line.=&Apache::loncommon::end_data_table_row();
1.329 droeschl 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: }
1.364 bisitz 1578: }
1.329 droeschl 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) {
1.369 bisitz 1627: $r->print('<img src="/adm/lonMisc/bomb.gif" alt="'.&mt('bomb').'" /><span class="LC_error">'.
1.329 droeschl 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 {
1.366 bisitz 1652: $r->print('<span class="LC_error">'.&mt('unable to verify variable URL').'</span>');
1.329 droeschl 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:
1.484.2.3 raeburn 1667: List Content Identifiers
1.329 droeschl 1668:
1669: =cut
1670:
1671: sub list_symbs {
1672: my ($r) = @_;
1673:
1.408 raeburn 1674: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 1675: $r->print(&Apache::loncommon::start_page('List of Content Identifiers'));
1676: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Content Identifiers'));
1677: $r->print(&startContentScreen('tools'));
1.329 droeschl 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>');
1.408 raeburn 1684: &Apache::lonnet::logthis('Symb list failed - could not create navmap object in '.lc($crstype).':'.$env{'request.course.id'});
1.329 droeschl 1685: } else {
1.484 raeburn 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;
1.329 droeschl 1692: foreach my $res ($navmap->retrieveResources()) {
1.484 raeburn 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());
1.329 droeschl 1703: }
1.484 raeburn 1704: $r->print(&Apache::loncommon::end_data_table());
1.329 droeschl 1705: }
1706: }
1707:
1708:
1709: sub verifycontent {
1710: my ($r) = @_;
1.408 raeburn 1711: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 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>');
1.329 droeschl 1716: $hashtied=0;
1717: undef %alreadyseen;
1718: %alreadyseen=();
1719: &tiehash();
1.484 raeburn 1720:
1.329 droeschl 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">'.
1.419 bisitz 1725: &mt('The following sequence or page is included more than once in your '.$crstype.':').' '.
1.329 droeschl 1726: &unescape($hash{$key}).'</span><br />'.
1.419 bisitz 1727: &mt('Note that grading records for problems included in this sequence or folder will overlap.').'<hr />');
1.329 droeschl 1728: }
1729: }
1730: if (($key=~/^src\_(.+)$/) && (!$alreadyseen{&unescape($hash{$key})})) {
1731: &checkonthis($r,$hash{$key},0,$hash{'title_'.$1});
1732: }
1733: }
1734: &untiehash();
1.442 www 1735: $r->print('<p class="LC_success">'.&mt('Done').'</p>');
1.329 droeschl 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) = @_;
1.408 raeburn 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"));
1.484 raeburn 1750: $r->print(&startContentScreen('tools'));
1.442 www 1751:
1.329 droeschl 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'},
1.344 bisitz 1802: $env{'course.'.$env{'request.course.id'}.'.num'}) eq 'ok') {
1.479 golterma 1803: $r->print(&Apache::loncommon::confirmwrapper(
1804: &Apache::lonhtmlcommon::confirm_success(&mt('Your Version Settings have been Saved'))));
1.329 droeschl 1805: } else {
1.479 golterma 1806: $r->print(&Apache::loncommon::confirmwrapper(
1807: &Apache::lonhtmlcommon::confirm_success(&mt('An Error Occured while Attempting to Save your Version Settings'),1)));
1.329 droeschl 1808: }
1809: &mark_hash_old();
1810: }
1811: &changewarning($r,'');
1812: if ($env{'form.timerange'} eq 'all') {
1813: # show all documents
1.408 raeburn 1814: $header=&mt('All Documents in '.$crstype);
1.329 droeschl 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
1.408 raeburn 1859: ('st' => 'Version changes since start of '.$crstype,
1.329 droeschl 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)',
1.484 raeburn 1864: 'cd' => 'Change display',
1.329 droeschl 1865: 'sd' => 'Display',
1866: 'fi' => 'File',
1867: 'md' => 'Modification Date',
1868: 'mr' => 'Most recently published Version',
1.408 raeburn 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',
1.329 droeschl 1872: 'sm' => 'Keep all Resources up-to-date with most recent Versions (default)',
1873: 'sc' => 'Set all Resource Versions to current Version (Fix Versions)',
1.479 golterma 1874: 'di' => 'Differences',
1.484 raeburn 1875: 'save' => 'Save changes',
1876: 'vers' => 'Version choice(s) for specific resources',
1.479 golterma 1877: 'act' => 'Actions');
1.329 droeschl 1878: $r->print(<<ENDHEADERS);
1.484 raeburn 1879: <h4 class="LC_info">$header</h4>
1.329 droeschl 1880: <form action="/adm/coursedocs" method="post">
1881: <input type="hidden" name="versions" value="1" />
1.484 raeburn 1882: <div class="LC_left_float">
1.479 golterma 1883: <fieldset>
1.484 raeburn 1884: <legend>$lt{'cd'}</legend>
1.329 droeschl 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'}" />
1.484 raeburn 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>
1.479 golterma 1905: <input type="submit" name="setversions" value="$lt{'save'}" />
1.329 droeschl 1906: <table border="0">
1907: ENDHEADERS
1.479 golterma 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>');
1.329 droeschl 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) {
1.479 golterma 1924: $currentversion='<span class="LC_error">'.&mt('Could not be determined.').'</span>';
1.329 droeschl 1925: }
1926: my $linkurl=&Apache::lonnet::clutter($key);
1.479 golterma 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">');
1.329 droeschl 1935: # Used in course
1936: my $usedversion=$hash{'version_'.$linkurl};
1937: if (($usedversion) && ($usedversion ne 'mostrecent')) {
1.479 golterma 1938: if($usedversion != $currentversion){
1939: $r->print('<span class="LC_warning">'.$usedversion.'</span>');
1940: }else{
1941: $r->print($usedversion);
1942: }
1.329 droeschl 1943: } else {
1944: $r->print($currentversion);
1945: }
1.479 golterma 1946: $r->print('</td><td title="'.$lt{'vu'}.'">');
1.329 droeschl 1947: # Set version
1948: $r->print(&Apache::loncommon::select_form($setversions{$linkurl},
1949: 'set_version_'.$linkurl,
1.428 raeburn 1950: {'select_form_order' =>
1.329 droeschl 1951: ['',1..$currentversion,'mostrecent'],
1952: '' => '',
1.411 bisitz 1953: 'mostrecent' => &mt('most recent'),
1.428 raeburn 1954: map {$_,$_} (1..$currentversion)}));
1.329 droeschl 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: }
1.364 bisitz 1963: #
1.329 droeschl 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);
1.479 golterma 1968: if ($num_entries % $num_ver_col == 0) {
1969: $entries_per_col = $num_entries/$num_ver_col;
1.329 droeschl 1970: } else {
1.479 golterma 1971: $entries_per_col = $num_entries/$num_ver_col + 1;
1.329 droeschl 1972: }
1973: my $entries_count = 0;
1.479 golterma 1974: $r->print('<td valign="top"><span class="LC_fontsize_medium">');
1.329 droeschl 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.
1.462 raeburn 1989: '" target="diffs">'.&mt('Diffs').'</a>');
1.329 droeschl 1990: }
1991: $r->print('</span><br />');
1992: if (++$entries_count % $entries_per_col == 0) {
1.479 golterma 1993: $r->print('</span></td>');
1994: if ($cols_output != $num_ver_col) {
1995: $r->print('<td valign="top"><span class="LC_fontsize_medium">');
1.329 droeschl 1996: $cols_output++;
1997: }
1998: }
1999: }
1.479 golterma 2000: while($cols_output++ < $num_ver_col) {
2001: $r->print('</span></td><td>');
1.329 droeschl 2002: }
2003: }
2004: }
1.479 golterma 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'}.'" />');
1.329 droeschl 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".
1.372 bisitz 2053: '<script type="text/javascript">'."\n".
2054: '// <![CDATA['."\n".
2055: 'function reinit(tf) { tf.submit();'.$postexec.' }'."\n".
2056: '// ]]>'."\n".
1.369 bisitz 2057: '</script>'."\n".
1.375 tempelho 2058: '<form name="reinitform" method="post" action="/adm/roles" target="loncapaclient">'.
1.329 droeschl 2059: '<input type="hidden" name="orgurl" value="'.$url.
1.372 bisitz 2060: '" /><input type="hidden" name="selectrole" value="1" /><p class="LC_warning">'.
1.329 droeschl 2061: &mt($message,' <input type="hidden" name="'.
2062: $env{'request.role'}.'" value="1" /><input type="button" value="'.
1.369 bisitz 2063: &mt('re-initializing '.$course_type).'" onclick="reinit(this.form)" />').
1.372 bisitz 2064: $help{'Caching'}.'</p></form>'."\n\n");
1.329 droeschl 2065: }
2066:
2067:
2068: sub init_breadcrumbs {
2069: my ($form,$text)=@_;
2070: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.484 raeburn 2071: &Apache::lonhtmlcommon::add_breadcrumb({href=>"/adm/coursedocs?tools=1",
1.405 bisitz 2072: text=>&Apache::loncommon::course_type().' Editor',
1.329 droeschl 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:
1.441 www 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: }
1.329 droeschl 2093:
1.441 www 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: }
1.329 droeschl 2100:
1.442 www 2101: #
2102: # Start tabs
2103: #
2104:
2105: sub startContentScreen {
1.484 raeburn 2106: my ($mode) = @_;
2107: my $output = '<ul class="LC_TabContentBigger" id="mainnav">';
1.472 raeburn 2108: if (($mode eq 'navmaps') || ($mode eq 'supplemental')) {
1.484 raeburn 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 'suppdocs')?' class="active"':'').'><a href="/adm/supplemental"><b>'.&mt('Supplemental Content').'</b></a></li>';
2112: } else {
2113: $output .= '<li '.(($mode eq 'docs')?' class="active"':'').' id="tabbededitor"><a href="/adm/coursedocs?forcestandard=1"><b> '.&mt('Content Editor').' </b></a></li>'."\n";
2114: $output .= '<li '.(($mode eq 'suppdocs')?' class="active"':'').'><a href="/adm/coursedocs?forcesupplement=1"><b>'.&mt('Supplemental Content Editor').'</b></a></li>'."\n";
2115: $output .= '<li '.(($mode eq 'tools')?' class="active"':'').'><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>'."\n";
2116: '><a href="/adm/coursedocs?tools=1"><b> '.&mt('Content Utilities').' </b></a></li>';
2117: }
2118: $output .= "\n".'</ul>'."\n";
2119: $output .= '<div class="LC_DocsBox" style="clear:both;margin:0;" id="contenteditor">'.
2120: '<div id="maincoursedoc" style="margin:0 0;padding:0 0;">'.
2121: '<div class="LC_ContentBox" id="mainCourseDocuments" style="display: block;">';
2122: return $output;
1.442 www 2123: }
2124:
2125: #
2126: # End tabs
2127: #
2128:
2129: sub endContentScreen {
1.484 raeburn 2130: return '</div></div></div>';
1.442 www 2131: }
1.329 droeschl 2132:
1.446 www 2133: sub supplemental_base {
1.472 raeburn 2134: return 'supplemental&'.&escape(&mt('Supplemental '.&Apache::loncommon::course_type().' Content'));
1.446 www 2135: }
2136:
1.329 droeschl 2137: sub handler {
2138: my $r = shift;
2139: &Apache::loncommon::content_type($r,'text/html');
2140: $r->send_http_header;
2141: return OK if $r->header_only;
1.484 raeburn 2142:
2143: # get course data
1.408 raeburn 2144: my $crstype = &Apache::loncommon::course_type();
1.484 raeburn 2145: my $coursenum=$env{'course.'.$env{'request.course.id'}.'.num'};
2146: my $coursedom=$env{'course.'.$env{'request.course.id'}.'.domain'};
2147:
2148: # graphics settings
2149: $iconpath = &Apache::loncommon::lonhttpdurl($r->dir_config('lonIconsURL').'/');
1.329 droeschl 2150:
1.443 www 2151: #
1.329 droeschl 2152: # --------------------------------------------- Initialize help topics for this
2153: foreach my $topic ('Adding_Course_Doc','Main_Course_Documents',
2154: 'Adding_External_Resource','Navigate_Content',
2155: 'Adding_Folders','Docs_Overview', 'Load_Map',
2156: 'Supplemental','Score_Upload_Form','Adding_Pages',
2157: 'Importing_LON-CAPA_Resource','Uploading_From_Harddrive',
2158: 'Check_Resource_Versions','Verify_Content') {
2159: $help{$topic}=&Apache::loncommon::help_open_topic('Docs_'.$topic);
2160: }
2161: # Composite help files
2162: $help{'Syllabus'} = &Apache::loncommon::help_open_topic(
2163: 'Docs_About_Syllabus,Docs_Editing_Templated_Pages');
2164: $help{'Simple Page'} = &Apache::loncommon::help_open_topic(
2165: 'Docs_About_Simple_Page,Docs_Editing_Templated_Pages');
2166: $help{'Simple Problem'} = &Apache::loncommon::help_open_topic(
2167: 'Option_Response_Simple');
2168: $help{'Bulletin Board'} = &Apache::loncommon::help_open_topic(
2169: 'Docs_About_Bulletin_Board,Docs_Editing_Templated_Pages');
1.347 weissno 2170: $help{'My Personal Information Page'} = &Apache::loncommon::help_open_topic(
1.329 droeschl 2171: 'Docs_About_My_Personal_Info,Docs_Editing_Templated_Pages');
1.353 weissno 2172: $help{'Group Portfolio'} = &Apache::loncommon::help_open_topic('Docs_About_Group_Files');
1.329 droeschl 2173: $help{'Caching'} = &Apache::loncommon::help_open_topic('Caching');
2174:
1.472 raeburn 2175:
2176: my $allowed;
2177: # URI is /adm/supplemental when viewing supplemental docs in non-edit mode.
2178: unless ($r->uri eq '/adm/supplemental') {
2179: # does this user have privileges to modify content.
2180: $allowed = &Apache::lonnet::allowed('mdc',$env{'request.course.id'});
2181: }
2182:
1.484 raeburn 2183: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['chooseserver',
2184: 'inhibitmenu']);
2185: if ($allowed && $env{'form.chooseserver'}) {
2186: &choose_dump_server($r);
2187: return OK;
2188: } elsif ($allowed && $env{'form.verify'}) {
1.329 droeschl 2189: &init_breadcrumbs('verify','Verify Content');
2190: &verifycontent($r);
2191: } elsif ($allowed && $env{'form.listsymbs'}) {
1.484 raeburn 2192: &init_breadcrumbs('listsymbs','List Content IDs');
1.329 droeschl 2193: &list_symbs($r);
2194: } elsif ($allowed && $env{'form.docslog'}) {
2195: &init_breadcrumbs('docslog','Show Log');
1.484 raeburn 2196: my $folder = $env{'form.folder'};
2197: if ($folder eq '') {
2198: $folder='default';
2199: }
2200: &docs_change_log($r,$coursenum,$coursedom,$folder,$allowed,$crstype,$iconpath);
1.329 droeschl 2201: } elsif ($allowed && $env{'form.versions'}) {
2202: &init_breadcrumbs('versions','Check/Set Resource Versions');
2203: &checkversions($r);
2204: } elsif ($allowed && $env{'form.dumpcourse'}) {
1.484 raeburn 2205: &init_breadcrumbs('dumpcourse','Dump '.&Apache::loncommon::course_type().' Content to Authoring Space');
1.329 droeschl 2206: &dumpcourse($r);
2207: } elsif ($allowed && $env{'form.exportcourse'}) {
1.377 bisitz 2208: &init_breadcrumbs('exportcourse','IMS Export');
1.475 raeburn 2209: &Apache::imsexport::exportcourse($r);
1.329 droeschl 2210: } else {
1.445 www 2211: #
2212: # Done catching special calls
1.484 raeburn 2213: # The whole rest is for course and supplemental documents and utilities menu
1.445 www 2214: # Get the parameters that may be needed
2215: #
2216: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
2217: ['folderpath','pagepath',
1.466 www 2218: 'pagesymb','forcesupplement','forcestandard',
1.484 raeburn 2219: 'tools','symb','command']);
1.445 www 2220:
2221: # standard=1: this is a "new-style" course with an uploaded map as top level
2222: # standard=2: this is a "old-style" course, and there is nothing we can do
1.329 droeschl 2223:
2224: my $standard=($env{'request.course.uri'}=~/^\/uploaded\//);
1.445 www 2225:
1.484 raeburn 2226: # Decide whether this should display supplemental or main content or utilities
1.445 www 2227: # supplementalflag=1: show supplemental documents
2228: # supplementalflag=0: show standard documents
1.484 raeburn 2229: # toolsflag=1: show utilities
1.445 www 2230:
2231:
2232: my $supplementalflag=($env{'form.folderpath'}=~/^supplemental/);
2233: if (($env{'form.folderpath'}=~/^default/) || $env{'form.folderpath'} eq "" || ($env{'form.pagepath'})) {
2234: $supplementalflag=0;
2235: }
2236: if ($env{'form.forcesupplement'}) { $supplementalflag=1; }
2237: if ($env{'form.forcestandard'}) { $supplementalflag=0; }
2238: unless ($allowed) { $supplementalflag=1; }
2239: unless ($standard) { $supplementalflag=1; }
1.484 raeburn 2240: my $toolsflag=0;
2241: if ($env{'form.tools'}) { $toolsflag=1; }
1.445 www 2242:
1.329 droeschl 2243: my $script='';
2244: my $showdoc=0;
1.457 raeburn 2245: my $addentries = {};
1.475 raeburn 2246: my $container;
1.329 droeschl 2247: my $containertag;
2248: my $uploadtag;
2249:
1.464 www 2250: # Do we directly jump somewhere?
1.466 www 2251:
1.464 www 2252: if ($env{'form.command'} eq 'direct') {
1.468 raeburn 2253: my ($mapurl,$id,$resurl);
1.472 raeburn 2254: if ($env{'form.symb'} ne '') {
1.468 raeburn 2255: ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($env{'form.symb'});
2256: if ($resurl=~/\.(sequence|page)$/) {
2257: $mapurl=$resurl;
2258: } elsif ($resurl eq 'adm/navmaps') {
2259: $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
2260: }
1.472 raeburn 2261: my $mapresobj;
2262: my $navmap = Apache::lonnavmaps::navmap->new();
2263: if (ref($navmap)) {
2264: $mapresobj = $navmap->getResourceByUrl($mapurl);
2265: }
2266: $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
2267: my $type=$2;
2268: my $path;
2269: if (ref($mapresobj)) {
2270: my $pcslist = $mapresobj->map_hierarchy();
2271: if ($pcslist ne '') {
2272: foreach my $pc (split(/,/,$pcslist)) {
2273: next if ($pc <= 1);
2274: my $res = $navmap->getByMapPc($pc);
2275: if (ref($res)) {
2276: my $thisurl = $res->src();
2277: $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
2278: my $thistitle = $res->title();
2279: $path .= '&'.
2280: &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
2281: &Apache::lonhtmlcommon::entity_encode($thistitle).
2282: ':'.$res->randompick().
2283: ':'.$res->randomout().
2284: ':'.$res->encrypted().
2285: ':'.$res->randomorder();
2286: }
1.467 raeburn 2287: }
2288: }
1.472 raeburn 2289: $path .= '&'.&Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.467 raeburn 2290: &Apache::lonhtmlcommon::entity_encode($mapresobj->title()).
2291: ':'.$mapresobj->randompick().
2292: ':'.$mapresobj->randomout().
2293: ':'.$mapresobj->encrypted().
2294: ':'.$mapresobj->randomorder();
1.472 raeburn 2295: } else {
2296: my $maptitle = &Apache::lonnet::gettitle($mapurl);
2297: $path = '&default&...::::'.
2298: '&'.&Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
2299: &Apache::lonhtmlcommon::entity_encode($maptitle).'::::';
2300: }
2301: $path = 'default&'.
2302: &Apache::lonhtmlcommon::entity_encode('Main Course Documents').
2303: $path;
2304: if ($type eq 'sequence') {
2305: $env{'form.folderpath'}=$path;
2306: $env{'form.pagepath'}='';
2307: } else {
2308: $env{'form.pagepath'}=$path;
2309: $env{'form.folderpath'}='';
2310: }
2311: } elsif ($env{'form.supppath'} ne '') {
2312: $env{'form.folderpath'}=$env{'form.supppath'};
1.466 www 2313: }
1.472 raeburn 2314: } elsif ($env{'form.command'} eq 'editdocs') {
2315: $env{'form.folderpath'} = 'default&'.
2316: &Apache::lonhtmlcommon::entity_encode('Main Course Content');
2317: $env{'form.pagepath'}='';
2318: } elsif ($env{'form.command'} eq 'editsupp') {
2319: $env{'form.folderpath'} = 'default&'.
2320: &Apache::lonhtmlcommon::entity_encode('Supplemental Content');
2321: $env{'form.pagepath'}='';
1.464 www 2322: }
2323:
1.445 www 2324: # Where do we store these for when we come back?
2325: my $stored_folderpath='docs_folderpath';
2326: if ($supplementalflag) {
2327: $stored_folderpath='docs_sup_folderpath';
2328: }
1.464 www 2329:
1.329 droeschl 2330: # No folderpath, no pagepath, see if we have something stored
2331: if ((!$env{'form.folderpath'}) && (!$env{'form.pagepath'})) {
1.445 www 2332: &Apache::loncommon::restore_course_settings($stored_folderpath,
1.329 droeschl 2333: {'folderpath' => 'scalar'});
2334: }
1.446 www 2335:
2336: # If we are not allowed to make changes, all we can see are supplemental docs
1.409 raeburn 2337: if (!$allowed) {
1.446 www 2338: $env{'form.pagepath'}='';
2339: unless ($env{'form.folderpath'} =~ /^supplemental/) {
2340: $env{'form.folderpath'} = &supplemental_base();
1.409 raeburn 2341: }
2342: }
1.446 www 2343: # If we still not have a folderpath, see if we can resurrect at pagepath
1.409 raeburn 2344: if (!$env{'form.folderpath'} && $allowed) {
1.445 www 2345: &Apache::loncommon::restore_course_settings($stored_folderpath,
1.329 droeschl 2346: {'pagepath' => 'scalar'});
2347: }
1.446 www 2348: # Make the zeroth entry in supplemental docs page paths, so we can get to top level
1.329 droeschl 2349: if ($env{'form.folderpath'} =~ /^supplemental_\d+/) {
1.446 www 2350: $env{'form.folderpath'} = &supplemental_base()
2351: .'&'.
1.329 droeschl 2352: $env{'form.folderpath'};
2353: }
1.446 www 2354: # If after all of this, we still don't have any paths, make them
2355: unless (($env{'form.pagepath'}) || ($env{'form.folderpath'})) {
2356: if ($supplementalflag) {
2357: $env{'form.folderpath'}=&supplemental_base();
2358: } else {
2359: $env{'form.folderpath'}='default';
2360: }
1.472 raeburn 2361: }
1.446 www 2362:
1.445 www 2363: # Store this
1.484 raeburn 2364: unless ($toolsflag) {
2365: &Apache::loncommon::store_course_settings($stored_folderpath,
2366: {'pagepath' => 'scalar',
2367: 'folderpath' => 'scalar'});
2368: if ($env{'form.folderpath'}) {
2369: my (@folderpath)=split('&',$env{'form.folderpath'});
2370: $env{'form.foldername'}=&unescape(pop(@folderpath));
2371: $env{'form.folder'}=pop(@folderpath);
2372: $container='sequence';
2373: }
2374: if ($env{'form.pagepath'}) {
2375: my (@pagepath)=split('&',$env{'form.pagepath'});
2376: $env{'form.pagename'}=&unescape(pop(@pagepath));
2377: $env{'form.folder'}=pop(@pagepath);
2378: $container='page';
2379: $containertag = '<input type="hidden" name="pagepath" value="" />'.
2380: '<input type="hidden" name="pagesymb" value="" />';
2381: $uploadtag =
2382: '<input type="hidden" name="pagepath" value="'.&HTML::Entities::encode($env{'form.pagepath'},'<>&"').'" />'.
2383: '<input type="hidden" name="pagesymb" value="'.&HTML::Entities::encode($env{'form.pagesymb'},'<>&"').'" />'.
2384: '<input type="hidden" name="folderpath" value="" />';
2385: } else {
2386: my $folderpath=$env{'form.folderpath'};
2387: if (!$folderpath) {
2388: if ($env{'form.folder'} eq '' ||
2389: $env{'form.folder'} eq 'supplemental') {
2390: $folderpath='default&'.
2391: &escape(&mt('Main '.$crstype.' Documents'));
2392: }
2393: }
2394: $containertag = '<input type="hidden" name="folderpath" value="" />';
2395: $uploadtag = '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($folderpath,'<>&"').'" />';
2396: }
2397: if ($r->uri=~/^\/adm\/coursedocs\/showdoc\/(.*)$/) {
2398: $showdoc='/'.$1;
2399: }
2400: if ($showdoc) { # got called in sequence from course
2401: $allowed=0;
2402: } else {
2403: if ($allowed) {
2404: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['cmd']);
2405: $script=&Apache::lonratedt::editscript('simple');
1.433 raeburn 2406: }
2407: }
1.329 droeschl 2408: }
2409:
1.344 bisitz 2410: # get personal data
1.329 droeschl 2411: my $uname=$env{'user.name'};
2412: my $udom=$env{'user.domain'};
2413: my $plainname=&escape(&Apache::loncommon::plainname($uname,$udom));
2414:
2415: if ($allowed) {
1.484 raeburn 2416: if ($toolsflag) {
2417: $script .= &inject_data_js();
2418: my ($home,$other,%outhash)=&authorhosts();
2419: if (!$home && $other) {
2420: my @hosts;
2421: foreach my $aurole (keys(%outhash)) {
2422: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
2423: push(@hosts,$outhash{$aurole});
2424: }
2425: }
2426: $script .= &dump_switchserver_js(@hosts);
2427: }
1.458 raeburn 2428: } else {
1.484 raeburn 2429: my @tabids;
2430: if ($supplementalflag) {
2431: @tabids = ('002','ee2','ff2');
2432: } else {
2433: @tabids = ('aa1','bb1','cc1','ff1');
2434: unless ($env{'form.pagepath'}) {
2435: unshift(@tabids,'001');
2436: push(@tabids,('dd1','ee1'));
2437: }
1.458 raeburn 2438: }
1.484 raeburn 2439: my $tabidstr = join("','",@tabids);
2440: $script .= &editing_js($udom,$uname,$supplementalflag).
2441: &history_tab_js().
2442: &inject_data_js().
1.484.2.3 raeburn 2443: &Apache::lonhtmlcommon::resize_scrollbox_js('docs',$tabidstr);
1.484 raeburn 2444: $addentries = {
1.484.2.3 raeburn 2445: onload => "javascript:resize_scrollbox('contentscroll','1','1');",
1.484 raeburn 2446: };
1.458 raeburn 2447: }
1.329 droeschl 2448: }
2449: # -------------------------------------------------------------------- Body tag
1.369 bisitz 2450: $script = '<script type="text/javascript">'."\n"
1.372 bisitz 2451: .'// <![CDATA['."\n"
2452: .$script."\n"
2453: .'// ]]>'."\n"
2454: .'</script>'."\n";
1.385 bisitz 2455:
2456: # Breadcrumbs
2457: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.446 www 2458: unless ($showdoc) {
1.392 raeburn 2459: &Apache::lonhtmlcommon::add_breadcrumb({
1.446 www 2460: href=>"/adm/coursedocs",text=>"$crstype Contents"});
1.392 raeburn 2461:
1.446 www 2462: $r->print(&Apache::loncommon::start_page("$crstype Contents", $script,
1.457 raeburn 2463: {'force_register' => $showdoc,
2464: 'add_entries' => $addentries,
2465: })
1.392 raeburn 2466: .&Apache::loncommon::help_open_menu('','',273,'RAT')
2467: .&Apache::lonhtmlcommon::breadcrumbs(
1.484 raeburn 2468: 'Editing '.$crstype.' Contents',
1.392 raeburn 2469: 'Docs_Adding_Course_Doc')
2470: );
1.446 www 2471: } else {
1.408 raeburn 2472: $r->print(&Apache::loncommon::start_page("$crstype documents",undef,
1.402 raeburn 2473: {'force_register' => $showdoc,}));
1.392 raeburn 2474: }
1.364 bisitz 2475:
1.329 droeschl 2476: my %allfiles = ();
2477: my %codebase = ();
1.440 raeburn 2478: my ($upload_result,$upload_output,$uploadphase);
1.329 droeschl 2479: if ($allowed) {
2480: if (($env{'form.uploaddoc.filename'}) &&
2481: ($env{'form.cmd'}=~/^upload_(\w+)/)) {
1.440 raeburn 2482: my $context = $1;
2483: # Process file upload - phase one - upload and parse primary file.
1.329 droeschl 2484: undef($hadchanges);
1.440 raeburn 2485: $uploadphase = &process_file_upload(\$upload_output,$coursenum,$coursedom,
2486: \%allfiles,\%codebase,$context);
1.329 droeschl 2487: if ($hadchanges) {
2488: &mark_hash_old();
2489: }
1.440 raeburn 2490: $r->print($upload_output);
2491: } elsif ($env{'form.phase'} eq 'upload_embedded') {
2492: # Process file upload - phase two - upload embedded objects
2493: $uploadphase = 'check_embedded';
2494: my $primaryurl = &HTML::Entities::encode($env{'form.primaryurl'},'<>&"');
2495: my $state = &embedded_form_elems($uploadphase,$primaryurl,
2496: $env{'form.newidx'});
2497: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
2498: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
2499: my ($destination,$dir_root) = &embedded_destination();
2500: my $url_root = '/uploaded/'.$docudom.'/'.$docuname;
2501: my $actionurl = '/adm/coursedocs';
2502: my ($result,$flag) =
2503: &Apache::loncommon::upload_embedded('coursedoc',$destination,
2504: $docuname,$docudom,$dir_root,$url_root,undef,undef,undef,$state,
2505: $actionurl);
2506: $r->print($result.&return_to_editor());
2507: } elsif ($env{'form.phase'} eq 'check_embedded') {
2508: # Process file upload - phase three - modify references in HTML file
2509: $uploadphase = 'modified_orightml';
2510: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
2511: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
2512: my ($destination,$dir_root) = &embedded_destination();
1.482 raeburn 2513: my $result =
2514: &Apache::loncommon::modify_html_refs('coursedoc',$destination,
2515: $docuname,$docudom,undef,
2516: $dir_root);
2517: $r->print($result.&return_to_editor());
1.476 raeburn 2518: } elsif ($env{'form.phase'} eq 'decompress_uploaded') {
2519: $uploadphase = 'decompress_phase_one';
2520: $r->print(&decompression_phase_one().
2521: &return_to_editor());
2522: } elsif ($env{'form.phase'} eq 'decompress_cleanup') {
2523: $uploadphase = 'decompress_phase_two';
2524: $r->print(&decompression_phase_two().
2525: &return_to_editor());
1.329 droeschl 2526: }
2527: }
2528:
1.484 raeburn 2529: if ($allowed && $toolsflag) {
2530: $r->print(&startContentScreen('tools'));
2531: $r->print(&generate_admin_menu($crstype));
2532: $r->print(&endContentScreen());
2533: } elsif ((!$showdoc) && (!$uploadphase)) {
1.329 droeschl 2534: # -----------------------------------------------------------------------------
2535: my %lt=&Apache::lonlocal::texthash(
1.408 raeburn 2536: 'uplm' => 'Upload a new main '.lc($crstype).' document',
2537: 'upls' => 'Upload a new supplemental '.lc($crstype).' document',
1.329 droeschl 2538: 'impp' => 'Import a document',
2539: 'copm' => 'All documents out of a published map into this folder',
1.417 droeschl 2540: 'upld' => 'Import Document',
1.329 droeschl 2541: 'srch' => 'Search',
2542: 'impo' => 'Import',
1.484.2.5! raeburn 2543: 'book' => 'Import from Stored Links',
1.329 droeschl 2544: 'selm' => 'Select Map',
2545: 'load' => 'Load Map',
1.419 bisitz 2546: 'reco' => 'Recover Deleted Documents',
1.329 droeschl 2547: 'newf' => 'New Folder',
2548: 'newp' => 'New Composite Page',
2549: 'extr' => 'External Resource',
2550: 'syll' => 'Syllabus',
1.425 raeburn 2551: 'navc' => 'Table of Contents',
1.343 biermanm 2552: 'sipa' => 'Simple Course Page',
1.329 droeschl 2553: 'sipr' => 'Simple Problem',
2554: 'drbx' => 'Drop Box',
1.451 www 2555: 'scuf' => 'External Scores (handgrade, upload, clicker)',
1.336 schafran 2556: 'bull' => 'Discussion Board',
1.347 weissno 2557: 'mypi' => 'My Personal Information Page',
1.353 weissno 2558: 'grpo' => 'Group Portfolio',
1.329 droeschl 2559: 'rost' => 'Course Roster',
1.348 weissno 2560: 'abou' => 'Personal Information Page for a User',
1.377 bisitz 2561: 'imsf' => 'IMS Import',
2562: 'imsl' => 'Import IMS package',
1.329 droeschl 2563: 'file' => 'File',
2564: 'title' => 'Title',
2565: 'comment' => 'Comment',
1.403 raeburn 2566: 'parse' => 'Upload embedded images/multimedia files if HTML file',
1.368 truskell 2567: 'nd' => 'Upload Document',
1.329 droeschl 2568: 'pm' => 'Published Map',
2569: 'sd' => 'Special Document',
2570: 'mo' => 'More Options',
2571: );
2572: # -----------------------------------------------------------------------------
2573: my $fileupload=(<<FIUP);
2574: $lt{'file'}:<br />
2575: <input type="file" name="uploaddoc" size="40" />
2576: FIUP
2577:
2578: my $checkbox=(<<CHBO);
2579: <!-- <label>$lt{'parse'}?
2580: <input type="checkbox" name="parserflag" />
2581: </label> -->
2582: <label>
2583: <input type="checkbox" name="parserflag" checked="checked" /> $lt{'parse'}
2584: </label>
2585: CHBO
2586:
1.458 raeburn 2587: my $fileuploada = "<br clear='all' /><input type='submit' value='".$lt{'upld'}."' /> $help{'Uploading_From_Harddrive'}";
1.329 droeschl 2588: my $fileuploadform=(<<FUFORM);
2589: <form name="uploaddocument" action="/adm/coursedocs" method="post" enctype="multipart/form-data">
1.371 tempelho 2590: <input type="hidden" name="active" value="aa" />
1.329 droeschl 2591: $fileupload
2592: <br />
2593: $lt{'title'}:<br />
1.458 raeburn 2594: <input type="text" size="60" name="comment" />
1.329 droeschl 2595: $uploadtag
2596: <input type="hidden" name="cmd" value="upload_default" />
2597: <br />
1.458 raeburn 2598: <span class="LC_nobreak" style="float:left">
1.329 droeschl 2599: $checkbox
2600: </span>
1.383 tempelho 2601: FUFORM
1.459 raeburn 2602: $fileuploadform .= $fileuploada.'</form>';
1.329 droeschl 2603:
2604: my $simpleeditdefaultform=(<<SEDFFORM);
2605: <form action="/adm/coursedocs" method="post" name="simpleeditdefault">
1.371 tempelho 2606: <input type="hidden" name="active" value="bb" />
1.383 tempelho 2607: SEDFFORM
2608: my @simpleeditdefaultforma = (
1.423 onken 2609: { '<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>" },
2610: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/res.png" alt="'.$lt{impo}.'" onclick="javascript:groupimport();"/>' => "<a class='LC_menubuttons_link' href='javascript:groupimport();'>$lt{'impo'}</a>$help{'Importing_LON-CAPA_Resource'}" },
1.484.2.5! raeburn 2611: { '<img class="LC_noBorder LC_middle" src="/res/adm/pages/wishlist.png" alt="'.$lt{lnks}.'" onclick="javascript:open_StoredLinks_Import();" />' => "<a class='LC_menubuttons_link' href='javascript:open_StoredLinks_Import();'>$lt{'lnks'}</a>" },
1.383 tempelho 2612: );
1.443 www 2613: $simpleeditdefaultform .= &create_form_ul(&create_list_elements(@simpleeditdefaultforma));
1.383 tempelho 2614: $simpleeditdefaultform .=(<<SEDFFORM);
1.459 raeburn 2615: <hr id="bb_hrule" style="width:0px;text-align:left;margin-left:0" />
1.329 droeschl 2616: $lt{'copm'}<br />
2617: <input type="text" size="40" name="importmap" /><br />
1.458 raeburn 2618: <span class="LC_nobreak" style="float:left"><input type="button"
1.369 bisitz 2619: onclick="javascript:openbrowser('simpleeditdefault','importmap','sequence,page','')"
1.329 droeschl 2620: value="$lt{'selm'}" /> <input type="submit" name="loadmap" value="$lt{'load'}" />
2621: $help{'Load_Map'}</span>
2622: </form>
2623: SEDFFORM
2624:
1.442 www 2625: my $extresourcesform=(<<ERFORM);
2626: <form action="/adm/coursedocs" method="post" name="newext">
2627: $uploadtag
2628: <input type="hidden" name="importdetail" value="" />
2629: <a class="LC_menubuttons_link" href="javascript:makenewext('newext');">$lt{'extr'}</a>$help{'Adding_External_Resource'}
2630: </form>
1.329 droeschl 2631: ERFORM
2632:
1.442 www 2633:
1.329 droeschl 2634: if ($allowed) {
2635: &update_paste_buffer($coursenum,$coursedom);
1.337 ehlerst 2636: $r->print(<<HIDDENFORM);
2637: <form name="renameform" method="post" action="/adm/coursedocs">
2638: <input type="hidden" name="title" />
2639: <input type="hidden" name="cmd" />
2640: <input type="hidden" name="markcopy" />
2641: <input type="hidden" name="copyfolder" />
2642: $containertag
2643: </form>
1.484 raeburn 2644:
1.337 ehlerst 2645: HIDDENFORM
1.484 raeburn 2646: $r->print(&makesimpleeditform($uploadtag)."\n".
2647: &makedocslogform($uploadtag."\n".
2648: '<input type="hidden" name="folder" value="'.
2649: $env{'form.folder'}.'" />'."\n"));
1.329 droeschl 2650: }
1.442 www 2651:
2652: # Generate the tabs
1.472 raeburn 2653: my $mode;
2654: if (($supplementalflag) && (!$allowed)) {
2655: &Apache::lonnavdisplay::startContentScreen($r,'supplemental');
2656: } else {
1.484 raeburn 2657: $r->print(&startContentScreen(($supplementalflag?'suppdocs':'docs')));
1.472 raeburn 2658: }
1.443 www 2659:
1.442 www 2660: #
2661:
2662: my $savefolderpath;
2663:
1.395 raeburn 2664: if ($allowed) {
1.329 droeschl 2665: my $folder=$env{'form.folder'};
1.443 www 2666: if ($folder eq '' || $supplementalflag) {
1.329 droeschl 2667: $folder='default';
1.356 tempelho 2668: $savefolderpath = $env{'form.folderpath'};
1.442 www 2669: $env{'form.folderpath'}='default&'.&escape(&mt('Content'));
1.329 droeschl 2670: $uploadtag = '<input type="hidden" name="folderpath" value="'.
2671: &HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" />';
2672: }
2673: my $postexec='';
2674: if ($folder eq 'default') {
1.372 bisitz 2675: $r->print('<script type="text/javascript">'."\n"
2676: .'// <![CDATA['."\n"
2677: .'this.window.name="loncapaclient";'."\n"
2678: .'// ]]>'."\n"
2679: .'</script>'."\n"
1.369 bisitz 2680: );
1.329 droeschl 2681: } else {
2682: #$postexec='self.close();';
2683: }
2684: my $folderseq='/uploaded/'.$coursedom.'/'.$coursenum.'/default_'.time.
2685: '.sequence';
2686: my $pageseq = '/uploaded/'.$coursedom.'/'.$coursenum.'/default_'.time.
2687: '.page';
2688: my $container='sequence';
2689: if ($env{'form.pagepath'}) {
2690: $container='page';
2691: }
2692: my $readfile='/uploaded/'.$coursedom.'/'.$coursenum.'/'.$folder.'.'.$container;
2693:
2694: my $imspform=(<<IMSPFORM);
2695: <form action="/adm/imsimportdocs" method="post" name="ims">
2696: <input type="hidden" name="folder" value="$folder" />
1.423 onken 2697: <a class="LC_menubuttons_link" href="javascript:makeims();">$lt{'imsf'}</a>
1.329 droeschl 2698: </form>
2699: IMSPFORM
2700:
2701: my $newnavform=(<<NNFORM);
2702: <form action="/adm/coursedocs" method="post" name="newnav">
1.371 tempelho 2703: <input type="hidden" name="active" value="cc" />
1.329 droeschl 2704: $uploadtag
2705: <input type="hidden" name="importdetail"
2706: value="$lt{'navc'}=/adm/navmaps" />
1.423 onken 2707: <a class="LC_menubuttons_link" href="javascript:document.newnav.submit()">$lt{'navc'}</a>
1.329 droeschl 2708: $help{'Navigate_Content'}
2709: </form>
2710: NNFORM
2711: my $newsmppageform=(<<NSPFORM);
2712: <form action="/adm/coursedocs" method="post" name="newsmppg">
1.371 tempelho 2713: <input type="hidden" name="active" value="cc" />
1.329 droeschl 2714: $uploadtag
2715: <input type="hidden" name="importdetail" value="" />
1.423 onken 2716: <a class="LC_menubuttons_link" href="javascript:makesmppage();"> $lt{'sipa'}</a>
1.383 tempelho 2717: $help{'Simple Page'}
1.329 droeschl 2718: </form>
2719: NSPFORM
2720:
2721: my $newsmpproblemform=(<<NSPROBFORM);
2722: <form action="/adm/coursedocs" method="post" name="newsmpproblem">
1.371 tempelho 2723: <input type="hidden" name="active" value="cc" />
1.329 droeschl 2724: $uploadtag
2725: <input type="hidden" name="importdetail" value="" />
1.423 onken 2726: <a class="LC_menubuttons_link" href="javascript:makesmpproblem();">$lt{'sipr'}</a>
1.383 tempelho 2727: $help{'Simple Problem'}
1.329 droeschl 2728: </form>
2729:
2730: NSPROBFORM
2731:
2732: my $newdropboxform=(<<NDBFORM);
2733: <form action="/adm/coursedocs" method="post" name="newdropbox">
1.371 tempelho 2734: <input type="hidden" name="active" value="cc" />
1.344 bisitz 2735: $uploadtag
1.329 droeschl 2736: <input type="hidden" name="importdetail" value="" />
1.423 onken 2737: <a class="LC_menubuttons_link" href="javascript:makedropbox();">$lt{'drbx'}</a>
1.344 bisitz 2738: </form>
1.329 droeschl 2739: NDBFORM
2740:
2741: my $newexuploadform=(<<NEXUFORM);
2742: <form action="/adm/coursedocs" method="post" name="newexamupload">
1.371 tempelho 2743: <input type="hidden" name="active" value="cc" />
1.329 droeschl 2744: $uploadtag
2745: <input type="hidden" name="importdetail" value="" />
1.423 onken 2746: <a class="LC_menubuttons_link" href="javascript:makeexamupload();">$lt{'scuf'}</a>
1.329 droeschl 2747: $help{'Score_Upload_Form'}
2748: </form>
2749: NEXUFORM
2750:
2751: my $newbulform=(<<NBFORM);
2752: <form action="/adm/coursedocs" method="post" name="newbul">
1.371 tempelho 2753: <input type="hidden" name="active" value="cc" />
1.329 droeschl 2754: $uploadtag
2755: <input type="hidden" name="importdetail" value="" />
1.423 onken 2756: <a class="LC_menubuttons_link" href="javascript:makebulboard();" >$lt{'bull'}</a>
1.329 droeschl 2757: $help{'Bulletin Board'}
2758: </form>
2759: NBFORM
2760:
2761: my $newaboutmeform=(<<NAMFORM);
2762: <form action="/adm/coursedocs" method="post" name="newaboutme">
1.371 tempelho 2763: <input type="hidden" name="active" value="cc" />
1.329 droeschl 2764: $uploadtag
2765: <input type="hidden" name="importdetail"
2766: value="$plainname=/adm/$udom/$uname/aboutme" />
1.423 onken 2767: <a class="LC_menubuttons_link" href="javascript:document.newaboutme.submit()">$lt{'mypi'}</a>
1.347 weissno 2768: $help{'My Personal Information Page'}
1.329 droeschl 2769: </form>
2770: NAMFORM
2771:
2772: my $newaboutsomeoneform=(<<NASOFORM);
2773: <form action="/adm/coursedocs" method="post" name="newaboutsomeone">
1.371 tempelho 2774: <input type="hidden" name="active" value="cc" />
1.329 droeschl 2775: $uploadtag
2776: <input type="hidden" name="importdetail" value="" />
1.423 onken 2777: <a class="LC_menubuttons_link" href="javascript:makeabout();">$lt{'abou'}</a>
1.329 droeschl 2778: </form>
2779: NASOFORM
2780:
2781:
2782: my $newrosterform=(<<NROSTFORM);
2783: <form action="/adm/coursedocs" method="post" name="newroster">
1.371 tempelho 2784: <input type="hidden" name="active" value="cc" />
1.329 droeschl 2785: $uploadtag
2786: <input type="hidden" name="importdetail"
2787: value="$lt{'rost'}=/adm/viewclasslist" />
1.423 onken 2788: <a class="LC_menubuttons_link" href="javascript:document.newroster.submit()">$lt{'rost'}</a>
1.329 droeschl 2789: $help{'Course Roster'}
2790: </form>
2791: NROSTFORM
2792:
1.342 ehlerst 2793: my $specialdocumentsform;
1.383 tempelho 2794: my @specialdocumentsforma;
1.451 www 2795: my $gradingform;
2796: my @gradingforma;
2797: my $communityform;
2798: my @communityforma;
1.351 ehlerst 2799: my $newfolderform;
1.390 tempelho 2800: my $newfolderb;
1.342 ehlerst 2801:
1.451 www 2802: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
1.383 tempelho 2803:
1.329 droeschl 2804: my $newpageform=(<<NPFORM);
2805: <form action="/adm/coursedocs" method="post" name="newpage">
2806: <input type="hidden" name="folderpath" value="$path" />
2807: <input type="hidden" name="importdetail" value="" />
1.371 tempelho 2808: <input type="hidden" name="active" value="cc" />
1.423 onken 2809: <a class="LC_menubuttons_link" href="javascript:makenewpage(document.newpage,'$pageseq');">$lt{'newp'}</a>
1.383 tempelho 2810: $help{'Adding_Pages'}
1.329 droeschl 2811: </form>
2812: NPFORM
1.390 tempelho 2813:
2814:
1.351 ehlerst 2815: $newfolderform=(<<NFFORM);
1.329 droeschl 2816: <form action="/adm/coursedocs" method="post" name="newfolder">
2817: <input type="hidden" name="folderpath" value="$path" />
2818: <input type="hidden" name="importdetail" value="" />
1.371 tempelho 2819: <input type="hidden" name="active" value="aa" />
1.422 onken 2820: <a href="javascript:makenewfolder(document.newfolder,'$folderseq');">$lt{'newf'}</a>$help{'Adding_Folders'}
1.329 droeschl 2821: </form>
2822: NFFORM
2823:
2824: my $newsylform=(<<NSYLFORM);
2825: <form action="/adm/coursedocs" method="post" name="newsyl">
1.371 tempelho 2826: <input type="hidden" name="active" value="cc" />
1.329 droeschl 2827: $uploadtag
2828: <input type="hidden" name="importdetail"
2829: value="$lt{'syll'}=/public/$coursedom/$coursenum/syllabus" />
1.423 onken 2830: <a class="LC_menubuttons_link" href="javascript:document.newsyl.submit()">$lt{'syll'}</a>
1.329 droeschl 2831: $help{'Syllabus'}
1.383 tempelho 2832:
1.329 droeschl 2833: </form>
2834: NSYLFORM
1.364 bisitz 2835:
1.329 droeschl 2836: my $newgroupfileform=(<<NGFFORM);
2837: <form action="/adm/coursedocs" method="post" name="newgroupfiles">
1.371 tempelho 2838: <input type="hidden" name="active" value="cc" />
1.329 droeschl 2839: $uploadtag
2840: <input type="hidden" name="importdetail"
2841: value="$lt{'grpo'}=/adm/$coursedom/$coursenum/aboutme" />
1.423 onken 2842: <a class="LC_menubuttons_link" href="javascript:document.newgroupfiles.submit()">$lt{'grpo'}</a>
1.353 weissno 2843: $help{'Group Portfolio'}
1.329 droeschl 2844: </form>
2845: NGFFORM
1.383 tempelho 2846: @specialdocumentsforma=(
1.421 onken 2847: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/page.png" alt="'.$lt{newp}.'" onclick="javascript:makenewpage(document.newpage,\''.$pageseq.'\');" />'=>$newpageform},
1.417 droeschl 2848: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="document.newsyl.submit()" />'=>$newsylform},
1.451 www 2849: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/navigation.png" alt="'.$lt{navc}.'" onclick="document.newnav.submit()" />'=>$newnavform},
2850: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simple.png" alt="'.$lt{sipa}.'" onclick="javascript:makesmppage();" />'=>$newsmppageform},
2851: );
2852: $specialdocumentsform = &create_form_ul(&create_list_elements(@specialdocumentsforma));
2853:
1.434 raeburn 2854:
2855: my @importdoc = (
2856: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="javascript:makenewext(\'newext\');" />'=>$extresourcesform},
2857: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/ims.png" alt="'.$lt{imsf}.'" onclick="javascript:makeims();" />'=>$imspform},);
1.459 raeburn 2858: $fileuploadform = &create_form_ul(&create_list_elements(@importdoc)) . '<hr id="cc_hrule" style="width:0px;text-align:left;margin-left:0" />' . $fileuploadform;
1.434 raeburn 2859:
1.451 www 2860: @gradingforma=(
2861: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/simpprob.png" alt="'.$lt{sipr}.'" onclick="javascript:makesmpproblem();" />'=>$newsmpproblemform},
2862: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/dropbox.png" alt="'.$lt{drbx}.'" onclick="javascript:makedropbox();" />'=>$newdropboxform},
2863: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/scoreupfrm.png" alt="'.$lt{scuf}.'" onclick="javascript:makeexamupload();" />'=>$newexuploadform},
2864:
2865: );
2866: $gradingform = &create_form_ul(&create_list_elements(@gradingforma));
2867:
2868: @communityforma=(
2869: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/bchat.png" alt="'.$lt{bull}.'" onclick="javascript:makebulboard();" />'=>$newbulform},
2870: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="javascript:makebulboard();" />'=>$newaboutmeform},
2871: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/aboutme.png" alt="'.$lt{abou}.'" onclick="javascript:makeabout();" />'=>$newaboutsomeoneform},
2872: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/clst.png" alt="'.$lt{rost}.'" onclick="document.newroster.submit()" />'=>$newrosterform},
2873: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/groupportfolio.png" alt="'.$lt{grpo}.'" onclick="document.newgroupfiles.submit()" />'=>$newgroupfileform},
2874: );
2875: $communityform = &create_form_ul(&create_list_elements(@communityforma));
1.383 tempelho 2876:
1.330 tempelho 2877: my %orderhash = (
1.417 droeschl 2878: 'aa' => ['Import Documents',$fileuploadform],
1.377 bisitz 2879: 'bb' => ['Published Resources',$simpleeditdefaultform],
1.451 www 2880: 'cc' => ['Grading Resources',$gradingform],
1.330 tempelho 2881: );
1.451 www 2882: unless ($env{'form.pagepath'}) {
1.434 raeburn 2883: $orderhash{'00'} = ['Newfolder',$newfolderform];
1.484 raeburn 2884: $orderhash{'dd'} = ['Collaboration',$communityform];
1.451 www 2885: $orderhash{'ee'} = ['Special Documents',$specialdocumentsform];
1.434 raeburn 2886: }
2887:
1.341 ehlerst 2888: $hadchanges=0;
1.484 raeburn 2889: unless (($supplementalflag || $toolsflag)) {
1.458 raeburn 2890: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.472 raeburn 2891: $supplementalflag,\%orderhash,$iconpath);
1.443 www 2892: if ($error) {
2893: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
2894: }
2895: if ($hadchanges) {
2896: &mark_hash_old();
2897: }
1.341 ehlerst 2898:
1.443 www 2899: &changewarning($r,'');
2900: }
1.458 raeburn 2901: }
1.442 www 2902:
1.443 www 2903: # Supplemental documents start here
2904:
1.329 droeschl 2905: my $folder=$env{'form.folder'};
1.443 www 2906: unless ($supplementalflag) {
1.329 droeschl 2907: $folder='supplemental';
2908: }
2909: if ($folder =~ /^supplemental$/ &&
2910: (($env{'form.folderpath'} =~ /^default\&/) || ($env{'form.folderpath'} eq ''))) {
1.446 www 2911: $env{'form.folderpath'} = &supplemental_base();
1.393 raeburn 2912: } elsif ($allowed) {
1.356 tempelho 2913: $env{'form.folderpath'} = $savefolderpath;
1.329 droeschl 2914: }
1.362 ehlerst 2915: $env{'form.pagepath'} = '';
1.329 droeschl 2916: if ($allowed) {
2917: my $folderseq=
2918: '/uploaded/'.$coursedom.'/'.$coursenum.'/supplemental_'.time.
2919: '.sequence';
2920:
2921: my $path = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
2922:
1.400 droeschl 2923: my $supupdocformbtn = "<input type='submit' value='".$lt{'upld'}."' />$help{'Uploading_From_Harddrive'}";
1.329 droeschl 2924: my $supupdocform=(<<SUPDOCFORM);
1.383 tempelho 2925: <form action="/adm/coursedocs" method="post" name="supuploaddocument" enctype="multipart/form-data">
1.371 tempelho 2926: <input type="hidden" name="active" value="ee" />
1.329 droeschl 2927: $fileupload
2928: <br />
2929: <br />
2930: <span class="LC_nobreak">
2931: $checkbox
2932: </span>
2933: <br /><br />
2934: $lt{'comment'}:<br />
1.383 tempelho 2935: <textarea cols="50" rows="4" name="comment"></textarea>
1.329 droeschl 2936: <br />
2937: <input type="hidden" name="folderpath" value="$path" />
2938: <input type="hidden" name="cmd" value="upload_supplemental" />
2939: SUPDOCFORM
1.443 www 2940: $supupdocform .= &create_form_ul(&Apache::lonhtmlcommon::htmltag('li',$supupdocformbtn,{class => 'LC_menubuttons_inline_text'}))."</form>";
1.329 droeschl 2941:
2942: my $supnewfolderform=(<<SNFFORM);
2943: <form action="/adm/coursedocs" method="post" name="supnewfolder">
1.371 tempelho 2944: <input type="hidden" name="active" value="ee" />
1.329 droeschl 2945: <input type="hidden" name="folderpath" value="$path" />
2946: <input type="hidden" name="importdetail" value="" />
1.423 onken 2947: <a class="LC_menubuttons_link" href="javascript:makenewfolder(document.supnewfolder,'$folderseq');">$lt{'newf'}</a>
1.383 tempelho 2948: $help{'Adding_Folders'}
1.329 droeschl 2949: </form>
2950: SNFFORM
1.383 tempelho 2951:
1.329 droeschl 2952:
2953: my $supnewextform=(<<SNEFORM);
2954: <form action="/adm/coursedocs" method="post" name="supnewext">
1.371 tempelho 2955: <input type="hidden" name="active" value="ff" />
1.329 droeschl 2956: <input type="hidden" name="folderpath" value="$path" />
2957: <input type="hidden" name="importdetail" value="" />
1.423 onken 2958: <a class="LC_menubuttons_link" href="javascript:makenewext('supnewext');">$lt{'extr'}</a> $help{'Adding_External_Resource'}
1.329 droeschl 2959: </form>
2960: SNEFORM
2961:
2962: my $supnewsylform=(<<SNSFORM);
2963: <form action="/adm/coursedocs" method="post" name="supnewsyl">
1.371 tempelho 2964: <input type="hidden" name="active" value="ff" />
1.329 droeschl 2965: <input type="hidden" name="folderpath" value="$path" />
2966: <input type="hidden" name="importdetail"
2967: value="Syllabus=/public/$coursedom/$coursenum/syllabus" />
1.423 onken 2968: <a class="LC_menubuttons_link" href="javascript:document.supnewsyl.submit()">$lt{'syll'}</a>
1.329 droeschl 2969: $help{'Syllabus'}
2970: </form>
2971: SNSFORM
2972:
2973: my $supnewaboutmeform=(<<SNAMFORM);
1.383 tempelho 2974: <form action="/adm/coursedocs" method="post" name="supnewaboutme">
1.371 tempelho 2975: <input type="hidden" name="active" value="ff" />
1.329 droeschl 2976: <input type="hidden" name="folderpath" value="$path" />
2977: <input type="hidden" name="importdetail"
2978: value="$plainname=/adm/$udom/$uname/aboutme" />
1.423 onken 2979: <a class="LC_menubuttons_link" href="javascript:document.supnewaboutme.submit()">$lt{'mypi'}</a>
1.347 weissno 2980: $help{'My Personal Information Page'}
1.329 droeschl 2981: </form>
2982: SNAMFORM
2983:
1.333 muellerd 2984:
1.383 tempelho 2985: my @specialdocs = (
1.417 droeschl 2986: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/syllabus.png" alt="'.$lt{syll}.'" onclick="document.supnewsyl.submit()" />'
2987: =>$supnewsylform},
2988: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/myaboutme.png" alt="'.$lt{mypi}.'" onclick="document.supnewaboutme.submit()" />'
2989: =>$supnewaboutmeform},
1.383 tempelho 2990: );
1.417 droeschl 2991: my @supimportdoc = (
2992: {'<img class="LC_noBorder LC_middle" src="/res/adm/pages/extres.png" alt="'.$lt{extr}.'" onclick="javascript:makenewext(\'supnewext\');" />'
2993: =>$supnewextform},
2994: );
1.459 raeburn 2995: $supupdocform = &create_form_ul(&create_list_elements(@supimportdoc)) . '<hr id="ee_hrule" style="width:0px;text-align:left;margin-left:0" />' . $supupdocform;
1.333 muellerd 2996: my %suporderhash = (
1.390 tempelho 2997: '00' => ['Supnewfolder', $supnewfolderform],
1.417 droeschl 2998: 'ee' => ['Import Documents',$supupdocform],
1.443 www 2999: 'ff' => ['Special Documents',&create_form_ul(&create_list_elements(@specialdocs))]
1.333 muellerd 3000: );
1.443 www 3001: if ($supplementalflag) {
1.458 raeburn 3002: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.472 raeburn 3003: $supplementalflag,\%suporderhash,$iconpath);
1.443 www 3004: if ($error) {
3005: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
3006: }
1.393 raeburn 3007: }
1.443 www 3008: } elsif ($supplementalflag) {
1.458 raeburn 3009: my $error = &editor($r,$coursenum,$coursedom,$folder,$allowed,'',$crstype,
1.472 raeburn 3010: $supplementalflag,'',$iconpath);
1.393 raeburn 3011: if ($error) {
3012: $r->print('<p><span class="LC_error">'.$error.'</span></p>');
1.383 tempelho 3013: }
1.393 raeburn 3014: }
1.389 tempelho 3015:
1.484 raeburn 3016: $r->print(&endContentScreen());
1.383 tempelho 3017:
1.329 droeschl 3018: if ($allowed) {
3019: $r->print('
3020: <form method="post" name="extimport" action="/adm/coursedocs">
3021: <input type="hidden" name="title" />
3022: <input type="hidden" name="url" />
3023: <input type="hidden" name="useform" />
3024: <input type="hidden" name="residx" />
3025: </form>');
3026: }
1.484 raeburn 3027: } elsif ($showdoc) {
1.329 droeschl 3028: # -------------------------------------------------------- This is showdoc mode
1.484 raeburn 3029: $r->print("<h1>".&mt('Uploaded Document').' - '.
1.329 droeschl 3030: &Apache::lonnet::gettitle($r->uri).'</h1><p>'.
3031: &mt('It is recommended that you use an up-to-date virus scanner before handling this file.')."</p><table>".
1.484 raeburn 3032: &entryline(0,&mt("Click to download or use your browser's Save Link function"),$showdoc).'</table>');
1.329 droeschl 3033: }
3034: }
3035: $r->print(&Apache::loncommon::end_page());
3036: return OK;
1.364 bisitz 3037: }
1.329 droeschl 3038:
1.440 raeburn 3039: sub embedded_form_elems {
3040: my ($phase,$primaryurl,$newidx) = @_;
3041: my $folderpath = &HTML::Entities::encode($env{'form.folderpath'},'<>&"');
3042: return <<STATE;
3043: <input type="hidden" name="folderpath" value="$folderpath" />
3044: <input type="hidden" name="cmd" value="upload_embedded" />
3045: <input type="hidden" name="newidx" value="$newidx" />
3046: <input type="hidden" name="phase" value="$phase" />
3047: <input type="hidden" name="primaryurl" value="$primaryurl" />
3048: STATE
3049: }
3050:
3051: sub embedded_destination {
3052: my $folder=$env{'form.folder'};
3053: my $destination = 'docs/';
3054: if ($folder =~ /^supplemental/) {
3055: $destination = 'supplemental/';
3056: }
3057: if (($folder eq 'default') || ($folder eq 'supplemental')) {
3058: $destination .= 'default/';
3059: } elsif ($folder =~ /^(default|supplemental)_(\d+)$/) {
3060: $destination .= $2.'/';
3061: }
3062: $destination .= $env{'form.newidx'};
3063: my $dir_root = '/userfiles';
3064: return ($destination,$dir_root);
3065: }
3066:
3067: sub return_to_editor {
3068: my $actionurl = '/adm/coursedocs';
3069: return '<p><form name="backtoeditor" method="post" action="'.$actionurl.'" />'."\n".
3070: '<input type="hidden" name="folderpath" value="'.&HTML::Entities::encode($env{'form.folderpath'},'<>&"').'" /></form>'."\n".
3071: '<a href="javascript:document.backtoeditor.submit();">'.&mt('Return to Editor').
3072: '</a></p>';
3073: }
3074:
1.476 raeburn 3075: sub decompression_info {
3076: my ($destination,$dir_root) = &embedded_destination();
3077: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
3078: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
3079: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
3080: my $container='sequence';
1.480 raeburn 3081: my ($pathitem,$hiddenelem);
3082: my @hiddens = ('newidx','comment','position');
1.476 raeburn 3083: if ($env{'form.pagepath'}) {
3084: $container='page';
1.480 raeburn 3085: $pathitem = 'pagepath';
1.476 raeburn 3086: } else {
1.480 raeburn 3087: $pathitem = 'folderpath';
1.476 raeburn 3088: }
1.480 raeburn 3089: unshift(@hiddens,$pathitem);
3090: foreach my $item (@hiddens) {
3091: if ($env{'form.'.$item}) {
3092: $hiddenelem .= '<input type="hidden" name="'.$item.'" value="'.
3093: $env{'form.'.$item}.'" />'."\n";
3094: }
1.477 raeburn 3095: }
1.476 raeburn 3096: return ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,
3097: $hiddenelem);
3098: }
3099:
3100: sub decompression_phase_one {
3101: my ($dir,$file,$warning,$error,$output);
3102: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
3103: &decompression_info();
3104: if ($env{'form.archiveurl'} !~ m{^/uploaded/\Q$docudom/$docuname/docs/\E(?:default|supplemental|\d+).*/([^/]+)$}) {
3105: $error = &mt('Archive file "[_1]" not in the expected location.',$env{'form.archiveurl'});
3106: } else {
3107: my $file = $1;
1.481 raeburn 3108: $output =
3109: &Apache::loncommon::process_decompression($docudom,$docuname,$file,
3110: $destination,$dir_root,
3111: $hiddenelem);
3112: if ($env{'form.autoextract_camtasia'}) {
3113: $output .= &remove_archive($docudom,$docuname,$container);
3114: }
1.476 raeburn 3115: }
3116: if ($error) {
3117: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
3118: $error.'</p>'."\n";
3119: }
3120: if ($warning) {
3121: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
3122: }
3123: return $output;
3124: }
3125:
3126: sub decompression_phase_two {
3127: my ($destination,$dir_root,$londocroot,$docudom,$docuname,$container,$hiddenelem)=
3128: &decompression_info();
1.481 raeburn 3129: my $output;
1.480 raeburn 3130: if ($env{'form.archivedelete'}) {
1.481 raeburn 3131: $output = &remove_archive($docudom,$docuname,$container);
1.480 raeburn 3132: }
3133: $output .=
1.481 raeburn 3134: &Apache::loncommon::process_extracted_files('coursedocs',$docudom,$docuname,
1.476 raeburn 3135: $destination,$dir_root,$hiddenelem);
3136: return $output;
3137: }
3138:
1.480 raeburn 3139: sub remove_archive {
3140: my ($docudom,$docuname,$container) = @_;
3141: my $map = $env{'form.folder'}.'.'.$container;
1.481 raeburn 3142: my ($output,$delwarning,$delresult,$url);
1.480 raeburn 3143: my ($errtext,$fatal) = &mapread($docuname,$docudom,$map);
3144: if ($fatal) {
3145: if ($container eq 'page') {
3146: $delwarning = &mt('An error occurred retrieving the contents of the current page.');
3147: } else {
3148: $delwarning = &mt('An error occurred retrieving the contents of the current folder.');
3149: }
3150: $delwarning .= &mt('As a result the archive file has not been removed.');
3151: } else {
3152: my $currcmd = $env{'form.cmd'};
3153: my $position = $env{'form.position'};
3154: if ($position > 0) {
3155: $env{'form.cmd'} = 'del_'.$position;
3156: my ($title,$url,@rrest) =
3157: split(/:/,$LONCAPA::map::resources[$LONCAPA::map::order[$position]]);
3158: if (&handle_edit_cmd($docuname,$docudom)) {
3159: ($errtext,$fatal) = &storemap($docuname,$docudom,$map);
3160: if ($fatal) {
3161: if ($container eq 'page') {
3162: $delwarning = &mt('An error occurred updating the contents of the current page.');
3163: } else {
3164: $delwarning = &mt('An error occurred updating the contents of the current folder.');
3165: }
3166: } else {
1.481 raeburn 3167: $delresult = &mt('Archive file removed.');
1.480 raeburn 3168: }
3169: }
3170: }
3171: $env{'form.cmd'} = $currcmd;
3172: }
3173: if ($delwarning) {
3174: $output = '<p class="LC_warning">'.
3175: $delwarning.
3176: '</p>';
3177: }
3178: if ($delresult) {
3179: $output .= '<p class="LC_info">'.
3180: $delresult.
3181: '</p>';
3182: }
1.481 raeburn 3183: return $output;
1.480 raeburn 3184: }
3185:
1.484 raeburn 3186: sub generate_admin_menu {
3187: my ($crstype) = @_;
3188: my $lc_crstype = lc($crstype);
3189: my ($home,$other,%outhash)=&authorhosts();
3190: my %lt=&Apache::lonlocal::texthash (
3191: 'vc' => 'Verify Content',
3192: 'cv' => 'Check/Set Resource Versions',
3193: 'ls' => 'List Resource Identifiers',
3194: 'imse' => 'Export contents to IMS Archive',
3195: 'dcd' => "Dump $crstype Content to Authoring Space",
3196: );
3197: my ($candump,$dumpurl);
3198: if ($home + $other > 0) {
3199: $candump = 'F';
3200: if ($home) {
3201: $dumpurl = "javascript:injectData(document.courseverify,'dummy','dumpcourse','$lt{'dcd'}')";
3202: } else {
3203: my @hosts;
3204: foreach my $aurole (keys(%outhash)) {
3205: unless(grep(/^\Q$outhash{$aurole}\E/,@hosts)) {
3206: push(@hosts,$outhash{$aurole});
3207: }
3208: }
3209: if (@hosts == 1) {
3210: my $switchto = '/adm/switchserver?otherserver='.$hosts[0].
3211: '&role='.
3212: &HTML::Entities::encode($env{'request.role'},'"<>&').'&origurl='.
3213: &HTML::Entities::encode('/adm/coursedocs?dumpcourse=1','"<>&');
3214: $dumpurl = "javascript:dump_needs_switchserver('$switchto')";
3215: } else {
3216: $dumpurl = "javascript:choose_switchserver_window()";
3217: }
3218: }
3219: }
3220: my @menu=
3221: ({ categorytitle=>'Administration',
3222: items =>[
3223: { linktext => $lt{'vc'},
3224: url => "javascript:injectData(document.courseverify,'dummy','verify','$lt{'vc'}')",
3225: permission => 'F',
3226: help => 'Verify_Content',
3227: icon => 'verify.png',
3228: linktitle => 'Verify contents can be retrieved/rendered',
3229: },
3230: { linktext => $lt{'cv'},
3231: url => "javascript:injectData(document.courseverify,'dummy','versions','$lt{'cv'}')",
3232: permission => 'F',
3233: help => 'Check_Resource_Versions',
3234: icon => 'resversion.png',
3235: linktitle => "View version information for resources in your $lc_crstype, and fix/unfix use of specific versions",
3236: },
3237: { linktext => $lt{'ls'},
3238: url => "javascript:injectData(document.courseverify,'dummy','listsymbs','$lt{'ls'}')",
3239: permission => 'F',
3240: #help => '',
3241: icon => 'symbs.png',
3242: linktitle => "List the unique identifier used for each resource instance in your $lc_crstype"
3243: },
3244: ]
3245: },
3246: { categorytitle=>'Export',
3247: items =>[
3248: { linktext => $lt{'imse'},
3249: url => "javascript:injectData(document.courseverify,'dummy','exportcourse','$lt{'imse'}')",
3250: permission => 'F',
3251: help => 'Docs_Export_Course_Docs',
3252: icon => 'imsexport.png',
3253: linktitle => $lt{'imse'},
3254: },
3255: { linktext => $lt{'dcd'},
3256: url => $dumpurl,
3257: permission => $candump,
3258: #help => '',
3259: icon => 'dump.png',
3260: linktitle => $lt{'dcd'},
3261: },
3262: ]
3263: });
3264: return '<form action="/adm/coursedocs" method="post" name="courseverify">'."\n".
3265: '<input type="hidden" id="dummy" />'."\n".
3266: &Apache::lonhtmlcommon::generate_menu(@menu)."\n".
3267: '</form>';
1.329 droeschl 3268: }
3269:
3270: sub generate_edit_table {
1.484 raeburn 3271: my ($tid,$orderhash_ref,$to_show,$iconpath,$jumpto,$readfile) = @_;
1.406 raeburn 3272: return unless(ref($orderhash_ref) eq 'HASH');
1.342 ehlerst 3273: my %orderhash = %{$orderhash_ref};
1.344 bisitz 3274: my $form;
1.371 tempelho 3275: my $activetab;
3276: my $active;
3277: if($env{'form.active'} ne ''){
3278: $activetab = $env{'form.active'};
3279: }
1.472 raeburn 3280: my $backicon = $iconpath.'clickhere.gif';
1.481 raeburn 3281: my $backtext = &mt('To Overview');
1.458 raeburn 3282: $form = '<div class="LC_Box" style="margin:0;">'.
1.484 raeburn 3283: '<ul id="navigation'.$tid.'" class="LC_TabContent">'."\n".
1.472 raeburn 3284: '<li class="goback">'.
3285: '<a href="javascript:toContents('."'$jumpto'".');">'.
1.473 raeburn 3286: '<img src="'.$backicon.'" class="LC_icon" style="border: none; vertical-align: top;"'.
1.484 raeburn 3287: ' alt="'.$backtext.'" />'.$backtext.'</a></li>'."\n";
3288: if ($tid == 1) {
3289: $form .= '<li>'.
1.484.2.5! raeburn 3290: '<a href="javascript:groupopen('."'$readfile'".',1);">'.
1.484 raeburn 3291: &mt('Undo Delete').'</a></li>'."\n";
3292: if ($env{'form.docslog'}) {
3293: $form .= '<li class="active">';
3294: } else {
3295: $form .= '<li>';
3296: }
3297: $form .= '<a href="javascript:toggleHistoryDisp(1);">'.
3298: &mt('History').'</a></li>'."\n";
3299: if ($env{'form.docslog'}) {
3300: $form .= '<li><a href="javascript:toggleHistoryDisp(0);">'.
3301: &mt('Edit').'</a></li>'."\n";
3302: }
3303: }
1.458 raeburn 3304: foreach my $name (reverse(sort(keys(%orderhash)))) {
1.390 tempelho 3305: if($name ne '00'){
1.371 tempelho 3306: if($activetab eq '' || $activetab ne $name){
3307: $active = '';
3308: }elsif($activetab eq $name){
3309: $active = 'class="active"';
3310: }
1.458 raeburn 3311: $form .= '<li style="float:right" '.$active
1.429 droeschl 3312: .' onmouseover="javascript:showPage(this, \''.$name.$tid.'\', \'navigation'.$tid.'\',\'content'.$tid.'\');"'
1.484 raeburn 3313: .' onclick="javascript:showPage(this, \''.$name.$tid.'\', \'navigation'.$tid.'\',\'content'.$tid.'\');"><a href="javascript:;"><b>'.&mt(${$orderhash{$name}}[0]).'</b></a></li>'."\n";
1.390 tempelho 3314: } else {
1.484 raeburn 3315: $form .= '<li '.$active.' style="float:right">'.${$orderhash{$name}}[1].'</li>'."\n";
1.390 tempelho 3316:
3317: }
1.329 droeschl 3318: }
1.484 raeburn 3319: $form .= '</ul>'."\n";
3320: $form .= '<div id="content'.$tid.'" style="padding: 0 0; margin: 0 0; overflow: hidden; clear:right">'."\n";
1.458 raeburn 3321:
3322: if ($to_show ne '') {
1.484 raeburn 3323: $form .= '<div style="padding:0;margin:0;float:left">'.$to_show.'</div>'."\n";
1.458 raeburn 3324: }
1.363 ehlerst 3325: foreach my $field (keys(%orderhash)){
1.390 tempelho 3326: if($field ne '00'){
1.422 onken 3327: if($activetab eq '' || $activetab ne $field){
1.458 raeburn 3328: $active = 'style="display: none;float:left"';
1.422 onken 3329: }elsif($activetab eq $field){
1.458 raeburn 3330: $active = 'style="display:block;float:left"';
1.422 onken 3331: }
3332: $form .= '<div id="'.$field.$tid.'"'
3333: .' class="LC_ContentBox" '.$active.'>'.${$orderhash{$field}}[1]
1.484 raeburn 3334: .'</div>'."\n";
1.363 ehlerst 3335: }
3336: }
1.484 raeburn 3337: unless ($env{'form.docslog'}) {
3338: $form .= '</div></div>'."\n";
3339: }
1.329 droeschl 3340: return $form;
3341: }
3342:
3343: sub editing_js {
1.472 raeburn 3344: my ($udom,$uname,$supplementalflag) = @_;
1.329 droeschl 3345: my $now = time();
3346: my %lt = &Apache::lonlocal::texthash(
3347: p_mnf => 'Name of New Folder',
3348: t_mnf => 'New Folder',
3349: p_mnp => 'Name of New Page',
3350: t_mnp => 'New Page',
1.451 www 3351: p_mxu => 'Title for the External Score',
1.349 biermanm 3352: p_msp => 'Name of Simple Course Page',
1.329 droeschl 3353: p_msb => 'Title for the Problem',
3354: p_mdb => 'Title for the Drop Box',
1.336 schafran 3355: p_mbb => 'Title for the Discussion Board',
1.348 weissno 3356: p_mab => "Enter user:domain for User's Personal Information Page",
1.352 bisitz 3357: p_mab2 => 'Personal Information Page of ',
1.329 droeschl 3358: p_mab_alrt1 => 'Not a valid user:domain',
3359: p_mab_alrt2 => 'Please enter both user and domain in the format user:domain',
3360: p_chn => 'New Title',
3361: p_rmr1 => 'WARNING: Removing a resource makes associated grades and scores inaccessible!',
3362: p_rmr2a => 'Remove[_99]',
3363: p_rmr2b => '?[_99]',
3364: p_ctr1a => 'WARNING: Cutting a resource makes associated grades and scores inaccessible!',
3365: p_ctr1b => 'Grades remain inaccessible if resource is pasted into another folder.',
3366: p_ctr2a => 'Cut[_98]',
1.478 raeburn 3367: p_ctr2b => '?[_98]',
3368: rpck => 'Enter number to pick (e.g., 3)',
1.329 droeschl 3369: );
3370:
1.433 raeburn 3371: my $crstype = &Apache::loncommon::course_type();
1.434 raeburn 3372: my $docs_folderpath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.folderpath'},'<>&"');
3373: my $docs_pagepath = &HTML::Entities::encode($env{'environment.internal.'.$env{'request.course.id'}.'.docs_folderpath.pagepath'},'<>&"');
3374: my $main_container_page;
3375: if ($docs_folderpath eq '') {
3376: if ($docs_pagepath ne '') {
3377: $main_container_page = 1;
3378: }
3379: }
1.433 raeburn 3380: my $toplevelmain = 'default&Main%20'.$crstype.'%20Documents';
1.446 www 3381: my $toplevelsupp = &supplemental_base();
1.433 raeburn 3382:
1.472 raeburn 3383: my $backtourl = '/adm/navmaps';
3384: if ($supplementalflag) {
3385: $backtourl = '/adm/supplemental';
3386: }
3387:
1.329 droeschl 3388: return <<ENDNEWSCRIPT;
3389: function makenewfolder(targetform,folderseq) {
3390: var foldername=prompt('$lt{"p_mnf"}','$lt{"t_mnf"}');
3391: if (foldername) {
3392: targetform.importdetail.value=escape(foldername)+"="+folderseq;
3393: targetform.submit();
3394: }
3395: }
3396:
3397: function makenewpage(targetform,folderseq) {
3398: var pagename=prompt('$lt{"p_mnp"}','$lt{"t_mnp"}');
3399: if (pagename) {
3400: targetform.importdetail.value=escape(pagename)+"="+folderseq;
3401: targetform.submit();
3402: }
3403: }
3404:
3405: function makenewext(targetname) {
3406: this.document.forms.extimport.useform.value=targetname;
3407: this.document.forms.extimport.title.value='';
3408: this.document.forms.extimport.url.value='';
3409: this.document.forms.extimport.residx.value='';
3410: window.open('/adm/rat/extpickframe.html');
3411: }
3412:
3413: function edittext(targetname,residx,title,url) {
3414: this.document.forms.extimport.useform.value=targetname;
3415: this.document.forms.extimport.residx.value=residx;
3416: this.document.forms.extimport.url.value=url;
3417: this.document.forms.extimport.title.value=title;
3418: window.open('/adm/rat/extpickframe.html');
3419: }
3420:
3421: function makeexamupload() {
3422: var title=prompt('$lt{"p_mxu"}');
1.344 bisitz 3423: if (title) {
1.329 droeschl 3424: this.document.forms.newexamupload.importdetail.value=
3425: escape(title)+'=/res/lib/templates/examupload.problem';
3426: this.document.forms.newexamupload.submit();
3427: }
3428: }
3429:
3430: function makesmppage() {
3431: var title=prompt('$lt{"p_msp"}');
1.344 bisitz 3432: if (title) {
1.329 droeschl 3433: this.document.forms.newsmppg.importdetail.value=
3434: escape(title)+'=/adm/$udom/$uname/$now/smppg';
3435: this.document.forms.newsmppg.submit();
3436: }
3437: }
3438:
3439: function makesmpproblem() {
3440: var title=prompt('$lt{"p_msb"}');
1.344 bisitz 3441: if (title) {
1.329 droeschl 3442: this.document.forms.newsmpproblem.importdetail.value=
3443: escape(title)+'=/res/lib/templates/simpleproblem.problem';
3444: this.document.forms.newsmpproblem.submit();
3445: }
3446: }
3447:
3448: function makedropbox() {
3449: var title=prompt('$lt{"p_mdb"}');
1.344 bisitz 3450: if (title) {
1.329 droeschl 3451: this.document.forms.newdropbox.importdetail.value=
3452: escape(title)+'=/res/lib/templates/DropBox.problem';
3453: this.document.forms.newdropbox.submit();
3454: }
3455: }
3456:
3457: function makebulboard() {
3458: var title=prompt('$lt{"p_mbb"}');
3459: if (title) {
3460: this.document.forms.newbul.importdetail.value=
3461: escape(title)+'=/adm/$udom/$uname/$now/bulletinboard';
3462: this.document.forms.newbul.submit();
3463: }
3464: }
3465:
3466: function makeabout() {
3467: var user=prompt("$lt{'p_mab'}");
3468: if (user) {
3469: var comp=new Array();
3470: comp=user.split(':');
3471: if ((typeof(comp[0])!=undefined) && (typeof(comp[1])!=undefined)) {
3472: if ((comp[0]) && (comp[1])) {
3473: this.document.forms.newaboutsomeone.importdetail.value=
3474: '$lt{"p_mab2"}'+escape(user)+'=/adm/'+comp[1]+'/'+comp[0]+'/aboutme';
1.335 ehlerst 3475: this.document.forms.newaboutsomeone.submit();
3476: } else {
3477: alert("$lt{'p_mab_alrt1'}");
1.329 droeschl 3478: }
1.335 ehlerst 3479: } else {
3480: alert("$lt{'p_mab_alrt2'}");
3481: }
3482: }
1.329 droeschl 3483: }
3484:
3485: function makeims() {
1.335 ehlerst 3486: var caller = document.forms.ims.folder.value;
3487: var newlocation = "/adm/imsimportdocs?folder="+caller+"&phase=one";
3488: newWindow = window.open("","IMSimport","HEIGHT=700,WIDTH=750,scrollbars=yes");
3489: newWindow.location.href = newlocation;
1.329 droeschl 3490: }
3491:
3492: function finishpick() {
1.335 ehlerst 3493: var title=this.document.forms.extimport.title.value;
3494: var url=this.document.forms.extimport.url.value;
3495: var form=this.document.forms.extimport.useform.value;
3496: var residx=this.document.forms.extimport.residx.value;
3497: eval('this.document.forms.'+form+'.importdetail.value="'+title+'='+url+'='+residx+'";this.document.forms.'+form+'.submit();');
1.329 droeschl 3498: }
3499:
3500: function changename(folderpath,index,oldtitle,container,pagesymb) {
1.335 ehlerst 3501: var title=prompt('$lt{"p_chn"}',oldtitle);
3502: if (title) {
3503: this.document.forms.renameform.markcopy.value=-1;
3504: this.document.forms.renameform.title.value=title;
3505: this.document.forms.renameform.cmd.value='rename_'+index;
3506: if (container == 'sequence') {
3507: this.document.forms.renameform.folderpath.value=folderpath;
3508: }
3509: if (container == 'page') {
3510: this.document.forms.renameform.pagepath.value=folderpath;
3511: this.document.forms.renameform.pagesymb.value=pagesymb;
3512: }
3513: this.document.forms.renameform.submit();
3514: }
1.329 droeschl 3515: }
3516:
3517: function removeres(folderpath,index,oldtitle,container,pagesymb,skip_confirm) {
1.335 ehlerst 3518: if (skip_confirm || confirm('$lt{"p_rmr1"}\\n\\n$lt{"p_rmr2a"} "'+oldtitle+'" $lt{"p_rmr2b"}')) {
3519: this.document.forms.renameform.markcopy.value=-1;
3520: this.document.forms.renameform.cmd.value='del_'+index;
3521: if (container == 'sequence') {
3522: this.document.forms.renameform.folderpath.value=folderpath;
3523: }
3524: if (container == 'page') {
3525: this.document.forms.renameform.pagepath.value=folderpath;
3526: this.document.forms.renameform.pagesymb.value=pagesymb;
3527: }
3528: this.document.forms.renameform.submit();
3529: }
1.329 droeschl 3530: }
3531:
3532: function cutres(folderpath,index,oldtitle,container,pagesymb,folder,skip_confirm) {
1.335 ehlerst 3533: if (skip_confirm || confirm('$lt{"p_ctr1a"}\\n$lt{"p_ctr1b"}\\n\\n$lt{"p_ctr2a"} "'+oldtitle+'" $lt{"p_ctr2b"}')) {
3534: this.document.forms.renameform.cmd.value='cut_'+index;
3535: this.document.forms.renameform.markcopy.value=index;
3536: this.document.forms.renameform.copyfolder.value=folder+'.'+container;
3537: if (container == 'sequence') {
3538: this.document.forms.renameform.folderpath.value=folderpath;
3539: }
3540: if (container == 'page') {
3541: this.document.forms.renameform.pagepath.value=folderpath;
3542: this.document.forms.renameform.pagesymb.value=pagesymb;
3543: }
3544: this.document.forms.renameform.submit();
3545: }
1.329 droeschl 3546: }
3547:
3548: function markcopy(folderpath,index,oldtitle,container,pagesymb,folder) {
1.335 ehlerst 3549: this.document.forms.renameform.markcopy.value=index;
3550: this.document.forms.renameform.copyfolder.value=folder+'.'+container;
3551: if (container == 'sequence') {
3552: this.document.forms.renameform.folderpath.value=folderpath;
3553: }
3554: if (container == 'page') {
3555: this.document.forms.renameform.pagepath.value=folderpath;
3556: this.document.forms.renameform.pagesymb.value=pagesymb;
3557: }
3558: this.document.forms.renameform.submit();
1.329 droeschl 3559: }
3560:
1.478 raeburn 3561: function updatePick(targetform,index,caller) {
3562: var pickitem = document.getElementById('rpick_'+index);
3563: var picknumitem = document.getElementById('rpicknum_'+index);
3564: if (pickitem.checked) {
3565: var picknum=prompt('$lt{"rpck"}',picknumitem.value);
3566: if (picknum == '' || picknum == null) {
3567: if (caller == 'check') {
3568: pickitem.checked=false;
3569: return;
3570: }
3571: } else {
3572: picknum.toString();
3573: var regexdigit=/^\\d+\$/;
3574: if (regexdigit.test(picknum)) {
3575: picknumitem.value = picknum;
3576: targetform.changeparms.value='randompick';
3577: targetform.submit();
3578: } else {
3579: if (caller == 'check') {
3580: pickitem.checked=false;
3581: }
3582: return;
3583: }
3584: }
3585: } else {
3586: picknumitem.value = 0;
3587: targetform.changeparms.value='randompick';
3588: targetform.submit();
3589: }
3590: }
3591:
1.334 muellerd 3592: function unselectInactive(nav) {
1.335 ehlerst 3593: currentNav = document.getElementById(nav);
3594: currentLis = currentNav.getElementsByTagName('LI');
3595: for (i = 0; i < currentLis.length; i++) {
1.472 raeburn 3596: if (currentLis[i].className == 'goback') {
3597: currentLis[i].className = 'goback';
3598: } else {
3599: if (currentLis[i].className == 'right active' || currentLis[i].className == 'right') {
1.374 tempelho 3600: currentLis[i].className = 'right';
1.472 raeburn 3601: } else {
1.374 tempelho 3602: currentLis[i].className = 'i';
1.472 raeburn 3603: }
3604: }
1.335 ehlerst 3605: }
1.332 tempelho 3606: }
3607:
1.334 muellerd 3608: function hideAll(current, nav, data) {
1.335 ehlerst 3609: unselectInactive(nav);
1.374 tempelho 3610: if(current.className == 'right'){
3611: current.className = 'right active'
3612: }else{
3613: current.className = 'active';
3614: }
1.335 ehlerst 3615: currentData = document.getElementById(data);
3616: currentDivs = currentData.getElementsByTagName('DIV');
3617: for (i = 0; i < currentDivs.length; i++) {
3618: if(currentDivs[i].className == 'LC_ContentBox'){
1.333 muellerd 3619: currentDivs[i].style.display = 'none';
1.330 tempelho 3620: }
3621: }
1.335 ehlerst 3622: }
1.330 tempelho 3623:
1.374 tempelho 3624: function openTabs(pageId) {
3625: tabnav = document.getElementById(pageId).getElementsByTagName('UL');
1.383 tempelho 3626: if(tabnav.length > 2 ){
1.389 tempelho 3627: currentNav = document.getElementById(tabnav[1].id);
1.374 tempelho 3628: currentLis = currentNav.getElementsByTagName('LI');
3629: for(i = 0; i< currentLis.length; i++){
3630: if(currentLis[i].className == 'active') {
1.375 tempelho 3631: funcString = currentLis[i].onclick.toString();
3632: tab = funcString.split('"');
1.420 onken 3633: if(tab.length < 2) {
3634: tab = funcString.split("'");
3635: }
1.375 tempelho 3636: currentData = document.getElementById(tab[1]);
3637: currentData.style.display = 'block';
1.374 tempelho 3638: }
3639: }
3640: }
3641: }
3642:
1.334 muellerd 3643: function showPage(current, pageId, nav, data) {
3644: hideAll(current, nav, data);
1.375 tempelho 3645: openTabs(pageId);
1.334 muellerd 3646: unselectInactive(nav);
1.330 tempelho 3647: current.className = 'active';
3648: currentData = document.getElementById(pageId);
3649: currentData.style.display = 'block';
1.458 raeburn 3650: activeTab = pageId;
1.433 raeburn 3651: if (nav == 'mainnav') {
3652: var storedpath = "$docs_folderpath";
3653: if (storedpath == '') {
3654: storedpath = "$docs_pagepath";
3655: }
1.434 raeburn 3656: var storedpage = "$main_container_page";
1.433 raeburn 3657: var reg = new RegExp("^supplemental");
3658: if (pageId == 'mainCourseDocuments') {
1.434 raeburn 3659: if (storedpage == 1) {
3660: document.simpleedit.folderpath.value = '';
3661: document.uploaddocument.folderpath.value = '';
3662: } else {
3663: if (reg.test(storedpath)) {
3664: document.simpleedit.folderpath.value = '$toplevelmain';
3665: document.uploaddocument.folderpath.value = '$toplevelmain';
3666: document.newext.folderpath.value = '$toplevelmain';
3667: } else {
3668: document.simpleedit.folderpath.value = storedpath;
3669: document.uploaddocument.folderpath.value = storedpath;
3670: document.newext.folderpath.value = storedpath;
3671: }
1.433 raeburn 3672: }
3673: } else {
1.434 raeburn 3674: if (reg.test(storedpath)) {
3675: document.simpleedit.folderpath.value = storedpath;
3676: document.supuploaddocument.folderpath.value = storedpath;
3677: document.supnewext.folderpath.value = storedpath;
3678: } else {
1.433 raeburn 3679: document.simpleedit.folderpath.value = '$toplevelsupp';
3680: document.supuploaddocument.folderpath.value = '$toplevelsupp';
3681: document.supnewext.folderpath.value = '$toplevelsupp';
3682: }
3683: }
3684: }
1.484.2.3 raeburn 3685: resize_scrollbox('contentscroll','1','0');
1.330 tempelho 3686: return false;
3687: }
1.329 droeschl 3688:
1.472 raeburn 3689: function toContents(jumpto) {
3690: var newurl = '$backtourl';
3691: if (jumpto != '') {
3692: newurl = newurl+'?postdata='+jumpto;
3693: ;
3694: }
3695: location.href=newurl;
3696: }
3697:
1.329 droeschl 3698: ENDNEWSCRIPT
3699: }
1.457 raeburn 3700:
1.483 raeburn 3701: sub history_tab_js {
3702: return <<"ENDHIST";
3703: function toggleHistoryDisp(choice) {
3704: document.docslogform.docslog.value = choice;
3705: document.docslogform.submit();
3706: return;
3707: }
3708:
3709: ENDHIST
3710: }
3711:
1.484 raeburn 3712: sub inject_data_js {
3713: return <<ENDINJECT;
3714:
3715: function injectData(current, hiddenField, name, value) {
3716: currentElement = document.getElementById(hiddenField);
3717: currentElement.name = name;
3718: currentElement.value = value;
3719: current.submit();
3720: }
3721:
3722: ENDINJECT
3723: }
3724:
3725: sub dump_switchserver_js {
3726: my @hosts = @_;
3727: my %lt = &Apache::lonlocal::texthash(
3728: dump => 'Dumping to Authoring Space requires switching server.',
3729: swit => 'Switch server?',
3730: duco => 'Dump content to Authoring Space',
3731: yone => 'You need to switch to a server housing an Authoring Space for which you are author or co-author.',
3732: chos => 'Choose server',
3733: );
3734: my $role = $env{'request.role'};
3735: my $js = <<"ENDSWJS";
3736: <script type="text/javascript">
3737: function write_switchserver() {
3738: var server;
3739: if (document.setserver.posshosts.length > 0) {
3740: for (var i=0; i<document.setserver.posshosts.length; i++) {
3741: if (document.setserver.posshosts[i].checked) {
3742: server = document.setserver.posshosts[i].value;
3743: }
3744: }
3745: opener.document.location.href="/adm/switchserver?otherserver="+server+"&role=$role&origurl=/adm/coursedocs";
3746: }
3747: window.close();
3748: }
3749: </script>
3750:
3751: ENDSWJS
3752:
3753: my $startpage = &Apache::loncommon::start_page('Choose server',$js,
3754: {'only_body' => 1,
3755: 'js_ready' => 1,});
3756: my $endpage = &Apache::loncommon::end_page({'js_ready' => 1});
3757:
3758: my $hostpicker;
3759: my $count = 0;
3760: foreach my $host (sort(@hosts)) {
3761: my $checked;
3762: if ($count == 0) {
3763: $checked = ' checked="checked"';
3764: }
3765: $hostpicker .= '<label><input type="radio" name="posshosts" value="'.
3766: $host.'"'.$checked.' />'.$host.'</label> ';
3767: $count++;
3768: }
3769:
3770: return <<"ENDSWITCHJS";
3771:
3772: function dump_needs_switchserver(url) {
3773: if (url!='' && url!= null) {
3774: if (confirm("$lt{'dump'}\\n$lt{'swit'}")) {
3775: go(url);
3776: }
3777: }
3778: return;
3779: }
3780:
3781: function choose_switchserver_window() {
3782: newWindow = window.open('','ChooseServer','height=400,width=500,scrollbars=yes')
3783: newWindow.document.open();
3784: newWindow.document.writeln('$startpage');
3785: newWindow.document.write('<h3>$lt{'duco'}<\\/h3>\\n'+
3786: '<p>$lt{'yone'}<\\/p>\\n'+
3787: '<div class="LC_left_float"><fieldset><legend>$lt{'chos'}<\\/legend>\\n'+
3788: '<form name="setserver" method="post" action="" \\/>\\n'+
3789: '$hostpicker\\n'+
3790: '<br \\/><br \\/>\\n'+
3791: '<input type="button" name="makeswitch" value="$lt{'swit'}" '+
3792: 'onclick="write_switchserver();" \\/>\\n'+
3793: '<\\/form><\\/fieldset><\\/div><br clear="all" \\/>\\n');
3794: newWindow.document.writeln('$endpage');
3795: newWindow.document.close();
3796: newWindow.focus();
3797: }
3798:
3799: ENDSWITCHJS
3800: }
3801:
3802: sub makedocslogform {
3803: my ($formelems,$docslog) = @_;
3804: return <<"LOGSFORM";
3805: <form action="/adm/coursedocs" method="post" name="docslogform">
3806: <input type="hidden" name="docslog" value="$docslog" />
3807: $formelems
3808: </form>
3809: LOGSFORM
3810: }
3811:
3812: sub makesimpleeditform {
3813: my ($formelems) = @_;
3814: return <<"SIMPFORM";
3815: <form name="simpleedit" method="post" action="/adm/coursedocs">
3816: <input type="hidden" name="importdetail" value="" />
3817: $formelems
3818: </form>
3819: SIMPFORM
3820: }
3821:
1.329 droeschl 3822: 1;
3823: __END__
3824:
3825:
3826: =head1 NAME
3827:
3828: Apache::londocs.pm
3829:
3830: =head1 SYNOPSIS
3831:
3832: This is part of the LearningOnline Network with CAPA project
3833: described at http://www.lon-capa.org.
3834:
3835: =head1 SUBROUTINES
3836:
3837: =over
3838:
3839: =item %help=()
3840:
3841: Available help topics
3842:
3843: =item mapread()
3844:
1.344 bisitz 3845: Mapread read maps into LONCAPA::map:: global arrays
1.329 droeschl 3846: @order and @resources, determines status
3847: sets @order - pointer to resources in right order
3848: sets @resources - array with the resources with correct idx
3849:
3850: =item authorhosts()
3851:
3852: Return hash with valid author names
3853:
3854: =item clean()
3855:
3856: =item dumpcourse()
3857:
3858: Actually dump course
3859:
3860: =item group_import()
3861:
3862: Imports the given (name, url) resources into the course
3863: coursenum, coursedom, and folder must precede the list
3864:
3865: =item breadcrumbs()
3866:
3867: =item log_docs()
3868:
3869: =item docs_change_log()
3870:
3871: =item update_paste_buffer()
3872:
3873: =item print_paste_buffer()
3874:
3875: =item do_paste_from_buffer()
3876:
3877: =item update_parameter()
3878:
3879: =item handle_edit_cmd()
3880:
3881: =item editor()
3882:
3883: =item process_file_upload()
3884:
3885: =item process_secondary_uploads()
3886:
3887: =item is_supplemental_title()
3888:
3889: =item parse_supplemental_title()
3890:
3891: =item entryline()
3892:
3893: =item tiehash()
3894:
3895: =item untiehash()
3896:
3897: =item checkonthis()
3898:
3899: check on this
3900:
3901: =item verifycontent()
3902:
3903: Verify Content
3904:
3905: =item devalidateversioncache() & checkversions()
3906:
3907: Check Versions
3908:
3909: =item mark_hash_old()
3910:
3911: =item is_hash_old()
3912:
3913: =item changewarning()
3914:
3915: =item init_breadcrumbs()
3916:
3917: Breadcrumbs for special functions
3918:
1.484 raeburn 3919: =item create_list_elements()
3920:
3921: =item create_form_ul()
3922:
3923: =item startContentScreen()
3924:
3925: =item endContentScreen()
3926:
3927: =item supplemental_base()
3928:
3929: =item embedded_form_elems()
3930:
3931: =item embedded_destination()
3932:
3933: =item return_to_editor()
3934:
3935: =item decompression_info()
3936:
3937: =item decompression_phase_one()
3938:
3939: =item decompression_phase_two()
3940:
3941: =item remove_archive()
3942:
3943: =item generate_admin_menu()
3944:
3945: =item generate_edit_table()
3946:
3947: =item editing_js()
3948:
3949: =item history_tab_js()
3950:
3951: =item inject_data_js()
3952:
3953: =item dump_switchserver_js()
3954:
1.484.2.3 raeburn 3955: =item resize_scrollbox_js()
1.484 raeburn 3956:
3957: =item makedocslogform()
3958:
1.484.2.3 raeburn 3959: =item makesimpleeditform()
3960:
1.329 droeschl 3961: =back
3962:
3963: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>