File:
[LON-CAPA] /
loncom /
interface /
portfolio.pm
Revision
1.268:
download - view:
text,
annotated -
select for diffs
Thu Dec 28 18:14:07 2023 UTC (8 months, 4 weeks ago) by
raeburn
Branches:
MAIN
CVS tags:
HEAD
- Internal name for conditional portfolio sharing for specific IP addresses
ranges when set by a user is now userip, to distinguish from those set
for externalresponse (inrenal name: ip).
- Portfolio shareability setting in domain defaults (by affiliation), with
possible override for an individual user will apply to portfolio file
requests to a LON-CAPA node running 2.11, when the file owner's homeserver
is 2.12 (or later).
1: # The LearningOnline Network
2: # portfolio browser
3: #
4: # $Id: portfolio.pm,v 1.268 2023/12/28 18:14:07 raeburn Exp $
5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28:
29: package Apache::portfolio;
30: use strict;
31: use Apache::Constants qw(:common :http);
32: use Apache::loncommon;
33: use Apache::lonnet;
34: use Apache::lontexconvert;
35: use Apache::lonfeedback;
36: use Apache::lonlocal;
37: use Apache::lonnet;
38: use Apache::longroup;
39: use Apache::lonhtmlcommon;
40: use HTML::Entities;
41: use LONCAPA qw(:DEFAULT :match);
42:
43: sub group_args {
44: my $output;
45: if (defined($env{'form.group'})) {
46: $output .= '&group='.$env{'form.group'};
47: if (defined($env{'form.ref'})) {
48: $output .= '&ref='.$env{'form.ref'};
49: }
50: }
51: return $output;
52: }
53:
54: sub group_form_data {
55: my $output;
56: if (defined($env{'form.group'})) {
57: $output = '<input type="hidden" name="group" value="'.$env{'form.group'}.'" />';
58: if (exists($env{'form.ref'})) {
59: $output .= '<input type="hidden" name="ref" value="'.
60: $env{'form.ref'}.'" />';
61: }
62: }
63: return $output;
64: }
65:
66: # receives a filename and path stub from username/userfiles/portfolio/
67: # returns an anchor tag consisting encoding filename and currentpath
68: sub make_anchor {
69: my ($url, $anchor_fields, $inner_text) = @_;
70: if ($$anchor_fields{'continue'} ne 'true') {$$anchor_fields{'continue'} = 'false'};
71: my $anchor = '<a href="'.$url.'?';
72: foreach my $field_name (keys(%$anchor_fields)) {
73: $anchor .= $field_name.'='.$$anchor_fields{$field_name}.'&';
74: }
75: $anchor =~ s/&$//;
76: $anchor .= &group_args();
77: $anchor .= '">'.$inner_text.'</a>';
78: return $anchor;
79: }
80:
81: my $dirptr=16384;
82: sub display_common {
83: my ($r,$url,$current_path,$is_empty,$dir_list,$can_upload,$group)=@_;
84: my $namespace = &get_namespace();
85: my $port_path = &get_port_path();
86: if ($can_upload) {
87: my $groupitem = &group_form_data();
88:
89: my $iconpath= $r->dir_config('lonIconsURL') . "/";
90: my %lt=&Apache::lonlocal::texthash(
91: 'upload' => 'Upload',
92: 'upload_label' => 'Upload file to current directory',
93: 'createdir' => 'Create Subdirectory',
94: 'createdir_label' => 'Create subdirectory in current directory',
95: 'parse' => 'Upload embedded images/multimedia/css/linked files if HTML file',
96: );
97: my $escuri = &HTML::Entities::encode($r->uri,'&<>"');
98: my $help_fileupload = &Apache::loncommon::help_open_topic('Portfolio AddFiles');
99: my $help_createdir = &Apache::loncommon::help_open_topic('Portfolio CreateDirectory');
100: my $help_portfolio = &Apache::loncommon::help_open_topic('Portfolio About', &mt('Help on the portfolio'));
101: $r->print(&display_portfolio_usage($group,$help_portfolio));
102: my $parse_check;
103: if (!&suppress_embed_prompt()) {
104: $parse_check = <<"END";
105: <br />
106: <span class="LC_nobreak">
107: <label>
108: <input type="checkbox" name="parserflag" checked="checked" />
109: $lt{'parse'}
110: </label>
111: </span>
112: END
113: }
114:
115: # Find space available before uploading
116: my $free_space = &free_space($group);
117:
118: # Upload File
119: $r->print('<div class="LC_left_float">'
120: .'<form method="post" enctype="multipart/form-data" action="'.$escuri.'">'
121: .'<fieldset>'
122: .'<legend>'.$lt{'upload_label'}.'</legend>'
123: .$groupitem
124: .'<input name="uploaddoc" type="file" class="LC_flUpload" />'
125: .'<input type="hidden" id="LC_free_space" value="'.$free_space.'" />'
126: .'<input type="hidden" name="currentpath" value="'.$current_path.'" />'
127: .'<input type="hidden" name="action" value="'.$env{"form.action"}.'" />'
128: .'<input type="hidden" name="symb" value="'.$env{"form.symb"}.'" />'
129: .'<input type="hidden" name="fieldname" value="'.$env{"form.fieldname"}.'" />'
130: .'<input type="hidden" name="mode" value="'.$env{"form.mode"}.'" />'
131: .'<input type="submit" name="storeupl" value="'.$lt{'upload'}.'" />'
132: .$help_fileupload
133: .$parse_check
134: .'</fieldset>'
135: .'</form>'
136: .'</div>'
137: );
138: # Create Subdirectory
139: $r->print('<div class="LC_left_float">'
140: .'<form method="post" action="'.$escuri.'">'
141: .'<fieldset>'
142: .'<legend>'.$lt{'createdir_label'}.'</legend>'
143: .'<input name="newdir" type="text" />'.$groupitem
144: .'<input type="hidden" name="currentpath" value="'.$current_path.'" />'
145: .'<input type="hidden" name="action" value="'.$env{"form.action"}.'" />'
146: .'<input type="hidden" name="symb" value="'.$env{"form.symb"}.'" />'
147: .'<input type="hidden" name="fieldname" value="'.$env{"form.fieldname"}.'" />'
148: .'<input type="hidden" name="mode" value="'.$env{"form.mode"}.'" />'
149: .'<input type="submit" name="createdir" value="'.$lt{'createdir'}.'" />'
150: .$help_createdir
151: .'</fieldset>'
152: .'</form>'
153: .'</div>'
154: );
155: } # end "if can_upload"
156:
157: my @tree = split (/\//,$current_path);
158: my %anchor_fields = (
159: 'selectfile' => $port_path,
160: 'currentpath' => '/',
161: 'mode' => $env{"form.mode"},
162: 'symb' => $env{"form.symb"},
163: 'fieldname' => $env{"form.fieldname"},
164: 'continue' => $env{"form.continue"}
165: );
166: $r->print('<br clear="all" />');
167: $r->print('<span class="LC_current_location">'.&make_anchor($url,\%anchor_fields,$port_path).'/');
168: if (@tree > 1){
169: my $newCurrentPath = '/';
170: for (my $i = 1; $i< @tree; $i++){
171: $newCurrentPath .= $tree[$i].'/';
172: my %anchor_fields = (
173: 'selectfile' => $tree[$i],
174: 'currentpath' => $newCurrentPath,
175: 'mode' => $env{"form.mode"},
176: 'symb' => $env{"form.symb"},
177: 'fieldname' => $env{"form.fieldname"},
178: 'continue' => $env{"form.continue"}
179: );
180: $r->print(&make_anchor($url,\%anchor_fields,$tree[$i]).'/');
181: }
182: }
183: $r->print('</span>');
184: $r->print(&Apache::loncommon::help_open_topic('Portfolio ChangeDirectory'));
185: &Apache::lonhtmlcommon::store_recent($namespace,$current_path,$current_path);
186: $r->print('<br /><form method="post" action="'.$url.'?mode='.$env{"form.mode"}.'&fieldname='.$env{"form.fieldname"}.'&symb='.$env{'form.symb'}.&group_args());
187: $r->print('">'.
188: &Apache::lonhtmlcommon::select_recent($namespace,'currentpath',
189: 'this.form.submit();'));
190: $r->print("</form>");
191: }
192:
193: sub display_portfolio_usage {
194: my ($group,$helpitem) = @_;
195: my $disk_quota = &get_quota($group);
196: my $getpropath = 1;
197: my $portfolio_root = &get_portfolio_root();
198: my ($uname,$udom) = &get_name_dom($group);
199: my $current_disk_usage =
200: &Apache::lonnet::diskusage($udom,$uname,$portfolio_root,$getpropath);
201: return &Apache::loncommon::head_subbox(
202: '<div style="float:right;padding-top:0;margin-top;0">'
203: .$helpitem
204: .'</div>'
205: .'<div>'
206: .&Apache::lonhtmlcommon::display_usage($current_disk_usage,
207: $disk_quota,'portfolio')
208: .'</div>');
209: }
210:
211: sub display_directory_line {
212: my ($r,$select_mode, $filename, $mtime, $size, $css_class,
213: $line, $access_controls, $curr_access, $now, $version_flag,
214: $href_location, $url, $current_path, $access_admin_text, $versions)=@_;
215:
216: my $fullpath = &prepend_group($current_path.$filename);
217: $r->print(&Apache::loncommon::start_data_table_row());
218: $r->print($line); # contains first two cells of table
219: my $lock_info;
220: if ($version_flag) { # versioned can't be versioned, so TRUE when root file
221: $r->print('<td><img alt="" src="'.&Apache::loncommon::icon($filename).'" class="LC_fileicon" /></td>');
222: $r->print('<td>'.$version_flag.'</td>');
223: } else { # this is a graded or handed back file
224: my ($user,$domain) = &get_name_dom($env{'form.group'});
225: my $permissions_hash = &Apache::lonnet::get_portfile_permissions($domain,$user);
226: if (defined($$permissions_hash{$fullpath})) {
227: foreach my $array_item (@{$$permissions_hash{$fullpath}}) {
228: if (ref($array_item) eq 'ARRAY') {
229: if ($$array_item[-1] eq 'handback') {
230: $lock_info = 'Handback';
231: } elsif ($$array_item[-1] eq 'graded') {
232: $lock_info = 'Graded';
233: }
234: }
235: }
236: }
237: if ($lock_info) {
238: my %anchor_fields = ('lockinfo' => $fullpath);
239: if ($versions) { # hold the folder open
240: my ($fname,$version,$extension) = &Apache::lonnet::file_name_version_ext($fullpath);
241: $fname =~ s|^/||;
242: $anchor_fields{'showversions'} = $fname.'.'.$extension;
243: }
244: $lock_info = &make_anchor(undef,\%anchor_fields,$lock_info);
245: }
246: $r->print('<td colspan="2">'.$lock_info.'</td>');
247: }
248: # $r->print('<td>'.$$version_flag{$filename}.'</td><td>');
249: $r->print('<td>'.&make_anchor($href_location.$filename,undef,$filename).'</td>');
250: $r->print('<td>'.$size.'</td>');
251: $r->print('<td>'.&Apache::lonlocal::locallocaltime($mtime).'</td>');
252: if ($select_mode ne 'true') {
253: $r->print('<td class="'.$css_class.'"> </td>'); # Display status
254: $r->print('<td><span class="LC_nobreak">'
255: .&mt($curr_access).' '
256: );
257: my %anchor_fields = (
258: 'access' => $filename,
259: 'currentpath' => $current_path
260: );
261: $r->print(&make_anchor($url, \%anchor_fields, $access_admin_text).'</span></td>');
262: } else {
263: $r->print('<td class="'.$css_class.'"> </td>'); # Display status
264: }
265: $r->print(&Apache::loncommon::end_data_table_row().$/);
266: }
267:
268: sub display_directory {
269: my ($r,$url,$current_path,$is_empty,$dir_list,$group,$can_upload,
270: $can_modify,$can_delete,$can_setacl,$can_viewacl)=@_;
271: my $iconpath= $r->dir_config('lonIconsURL') . "/";
272: my $select_mode;
273: my $checked_files;
274: my $port_path = &get_port_path();
275: my ($uname,$udom) = &get_name_dom($group);
276: my $access_admin_text;
277: if ($can_viewacl) {
278: $access_admin_text = &mt('View Status');
279: }
280: if ($can_setacl) {
281: $access_admin_text = &mt('View/Change Status');
282: }
283:
284: my $current_permissions = &Apache::lonnet::get_portfile_permissions($udom,
285: $uname);
286: my %locked_files = &Apache::lonnet::get_marked_as_readonly_hash(
287: $current_permissions,$group);
288: my %access_controls = &Apache::lonnet::get_access_controls($current_permissions,$group);
289: my $now = time;
290: if ($env{"form.mode"} eq 'selectfile') {
291: &select_files($r,$dir_list);
292: $checked_files =&Apache::lonnet::files_in_path($uname,$env{'form.currentpath'});
293: $select_mode = 'true';
294: }
295: if ($select_mode eq 'true') {
296: $r->print('<form method="post" name="checkselect" action="'.$url.'">');
297: $r->print(&Apache::loncommon::start_data_table()
298: .&Apache::loncommon::start_data_table_header_row()
299: .'<th>'.&mt('Select').'</th>'
300: .'<th> </th>'
301: .'<th> </th>'
302: .'<th>'.&mt('Name').'</th>'
303: .'<th>'.&mt('Size').'</th>'
304: .'<th>'.&mt('Last Modified').'</th>'
305: .'<th> </th>'
306: .&Apache::loncommon::end_data_table_header_row()
307: );
308: } else {
309: $r->print('<form method="post" action="'.$url.'">');
310: $r->print(
311: '<p>'
312: .&Apache::loncommon::help_open_topic(
313: 'Portfolio FileList',
314: &mt('Using the portfolio file list'))
315: .'</p>'
316: );
317: $r->print(&Apache::loncommon::start_data_table()
318: .&Apache::loncommon::start_data_table_header_row()
319: .'<th colspan="2">'.&mt('Actions'). &Apache::loncommon::help_open_topic('Portfolio FileAction').'</th>'
320: .'<th> </th>'
321: .'<th> </th>'
322: .'<th>'.&mt('Name').&Apache::loncommon::help_open_topic('Portfolio OpenFile').'</th>'
323: .'<th>'.&mt('Size').'</th>'
324: .'<th>'.&mt('Last Modified').'</th>'
325: .'<th> </th>'
326: .'<th>'.&mt('Current Access Status').&Apache::loncommon::help_open_topic('Portfolio ShareFile').'</th>'
327: .&Apache::loncommon::end_data_table_header_row());
328: }
329:
330: # Empty directory?
331: if ($is_empty && ($current_path ne '/') && $can_delete) {
332: my $cols = ($select_mode eq 'true') ? 7 : 9;
333: # Empty message
334: $r->print(
335: &Apache::loncommon::start_data_table_row()
336: .'<td colspan="'.$cols.'">'
337: .'<p class="LC_info">'
338: .&mt('This directory is empty.')
339: .'</p>'
340: .'</td>'
341: .&Apache::loncommon::end_data_table_row()
342: .&Apache::loncommon::end_data_table()
343: .'</form>'
344: );
345: # Delete button
346: $r->print(
347: '<form method="post" action="'.$url.'">'.
348: &group_form_data().
349: '<input type="hidden" name="action" value="deletedir" />'.
350: '<p>'.
351: '<input type="submit" name="deletedir" value="'.&mt("Delete Directory").'" />'.
352: '</p>'.
353: '<input type="hidden" name="selectfile" value="" />'.
354: '<input type="hidden" name="currentpath" value="'.$current_path.'" />'.
355: '</form>'
356: );
357: # Directory is empty, so nothing else to display
358: return;
359: }
360:
361: $r->print("\n".&group_form_data()."\n");
362:
363: my $href_location="/uploaded/$udom/$uname/$port_path".$current_path;
364: my $href_edit_location="/editupload/$udom/$uname/$port_path".$current_path;
365: my @dir_lines;
366: my %versioned;
367: if (ref($dir_list) eq 'ARRAY') {
368: foreach my $dir_line (sort
369: {
370: my ($afile)=split('&',$a,2);
371: my ($bfile)=split('&',$b,2);
372: return (lc($afile) cmp lc($bfile));
373: } (@{$dir_list})) {
374: my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$dir_line,16);
375: $filename =~ s/\s+$//;
376: my ($fname,$version,$extension) = &Apache::lonnet::file_name_version_ext($filename);
377: if ($version) {
378: my $fullpath = &prepend_group($current_path.$fname.'.'.$extension);
379: push(@{ $versioned{$fullpath} },
380: [$filename,$dom,$testdir,$size,$mtime,$obs,]);
381: } else {
382: push(@dir_lines, [$filename,$dom,$testdir,$size,$mtime,$obs]);
383: }
384: }
385: }
386: my $zerobyte;
387: foreach my $dir_line (@dir_lines) {
388: my ($filename,$dom,$testdir,$size,$mtime,$obs) = @$dir_line;
389: my ($fname,$version,$extension) = &Apache::lonnet::file_name_version_ext($filename);
390: if (($filename ne '.') && ($filename ne '..') && ($filename !~ /\.meta$/ ) && ($filename !~ /(.*)\.(\d+)\.([^\.]*)$/)) {
391: my $version_flag;
392: my $show_versions;
393: my $fullpath = &prepend_group($current_path.$filename);
394: if ($env{'form.showversions'} =~ /$filename/) {
395: $show_versions = 'true';
396: }
397: if (exists($versioned{$fullpath})) {
398: my %anchor_fields = (
399: 'selectfile' => $fullpath,
400: 'continue' => 'false',
401: 'currentpath' => $current_path,
402: );
403: if ($show_versions) {
404: # Must preserve other possible showversion files
405: my $version_remainder = $env{'form.showversions'};
406: $version_remainder =~ s/$filename//g;
407: $anchor_fields{'showversions'} = $version_remainder;
408: $version_flag = &make_anchor('portfolio',\%anchor_fields,
409: '<img class="LC_icon" alt="'.&mt('opened folder').'" src="'.$iconpath.'folder_pointer_opened.gif" />');
410: } else {
411: # allow multiple files to show versioned
412: $anchor_fields{'showversions'} = $env{'form.showversions'}.','.$filename;
413: $version_flag = &make_anchor('portfolio',\%anchor_fields,
414: '<img class="LC_icon" alt="'.&mt('closed folder').'" src="'.$iconpath.'folder_pointer_closed.gif" />');
415: }
416: } else {
417: $version_flag = ' ';
418: }
419: if ($dirptr&$testdir) {
420: my $colspan_folder='';
421: my $colspan_fill='';
422: if ($select_mode eq 'true'){
423: $colspan_fill=' colspan="3"';
424: } else {
425: $colspan_folder=' colspan="2"';
426: $colspan_fill=' colspan="4"';
427: }
428: $r->print('<tr class="LC_browser_folder">');
429: $r->print('<td'.$colspan_folder.'><img alt="'.&mt('closed folder').'" src="'.$iconpath.'navmap.folder.closed.gif" class="LC_fileicon" /></td>'
430: .'<td>'.&mt('Go to ...').'</td>');
431: my %anchor_fields = (
432: 'selectfile' => $filename.'/',
433: 'currentpath' => $current_path.$filename.'/',
434: 'mode' => $env{"form.mode"},
435: 'symb' => $env{"form.symb"},
436: 'fieldname' => $env{"form.fieldname"},
437: 'continue' => $env{"form.continue"}
438: );
439: $r->print('<td>'.$version_flag.'</td>'
440: .'<td>'.&make_anchor($url,\%anchor_fields,$filename.'/').'</td>');
441: $r->print('<td'.$colspan_fill.'> </td>');
442: $r->print('</tr>');
443: } else {
444: my $css_class = 'LC_browser_file';
445: my $line;
446: if ($select_mode eq 'true') {
447: if ($size > 0) {
448: $line='<td><input type="checkbox" name="checkfile" value="'.$filename.'"';
449: if ($$checked_files{$filename} eq 'selected') {
450: $line.=' checked="checked" ';
451: }
452: $line.=' /></td>';
453: } else {
454: $line = '<td> </td>';
455: $zerobyte ++;
456: }
457: } else {
458: if (exists $locked_files{$fullpath}) {
459: my %anchor_fields = (
460: 'lockinfo' => $fullpath
461: );
462: $line.='<td colspan="2">'.&make_anchor($url,\%anchor_fields,&mt('Locked')).'</td>';
463: $css_class= 'LC_browser_file_locked';
464: } else {
465: if (!$can_modify) {
466: $line .= '<td colspan="2">';
467: } else {
468: $line .= '<td>';
469: }
470: if ($can_delete) {
471: $line .= '<input type="checkbox" name="selectfile" value="'.$filename.'" />';
472: }
473: if ($can_modify) {
474: my $cat='<img class="LC_icon" alt="'.&mt('Metadata').'" title="'.&mt('Metadata').'" src="'.&Apache::loncommon::lonhttpdurl('/res/adm/pages/catalog.png').'" />';
475: my %anchor_fields = (
476: 'rename' => $filename,
477: currentpath => $current_path
478: );
479: $line .= &make_anchor($url,\%anchor_fields,&mt('Rename'));
480: $line .= '</td><td>'.&make_anchor($href_edit_location.$filename.'.meta',\%anchor_fields,$cat);
481: # '<a href="'.$href_edit_location.$filename.'.meta">'.$cat.'</a>';
482: }
483: $line .= '</td>';
484: }
485: }
486: my $curr_access;
487: if ($select_mode ne 'true') {
488: my $pub_access = 0;
489: my $guest_access = 0;
490: my $cond_access = 0;
491: foreach my $key (sort(keys(%{$access_controls{$fullpath}}))) {
492: my ($num,$scope,$end,$start) = &unpack_acc_key($key);
493: next if ($scope eq 'ip');
494: if (($now > $start) && (!$end || $end > $now)) {
495: if ($scope eq 'public') {
496: $pub_access = 1;
497: } elsif ($scope eq 'guest') {
498: $guest_access = 1;
499: } else {
500: $cond_access = 1;
501: }
502: }
503: }
504: if (!$pub_access && !$guest_access && !$cond_access) {
505: $curr_access = &mt('Private');
506: } else {
507: my @allaccesses;
508: if ($pub_access) {
509: push(@allaccesses,&mt('Public'));
510: }
511: if ($guest_access) {
512: push(@allaccesses,&mt('Passphrase-protected'));
513: }
514: if ($cond_access) {
515: push(@allaccesses,&mt('Conditional'));
516: }
517: $curr_access = join('+ ',@allaccesses);
518: }
519: }
520: &display_directory_line($r,$select_mode, $filename, $mtime, $size, $css_class, $line,
521: \%access_controls, $curr_access, $now, $version_flag, $href_location,
522: $url, $current_path, $access_admin_text);
523: if ($show_versions) {
524: foreach my $dir_line (@{ $versioned{$fullpath} }) {
525: my ($v_filename,$dom,$testdir,$size,$mtime,$obs) =
526: @$dir_line;
527: $line = '<td colspan="2"> </td>';
528: &display_directory_line($r,$select_mode, $v_filename, $mtime, $size,
529: $css_class, $line, \%access_controls, $curr_access, $now,
530: undef, $href_location, $url, $current_path, $access_admin_text, 1);
531: }
532: }
533: }
534: }
535: }
536: if ($select_mode eq 'true') {
537: $r->print(&Apache::loncommon::end_data_table());
538: if ($zerobyte) {
539: $r->print('<p class="LC_warning">'.&mt('[quant,_1,file] in list not selectable as file size is 0 bytes.',$zerobyte).'</p>');
540: }
541: $r->print('
542: <input type="hidden" name="continue" value="true" />
543: <input type="hidden" name="fieldname" value="'.$env{'form.fieldname'}.'" />
544: <input type="hidden" name="symb" value="'.$env{'form.symb'}.'" />
545: <input type="hidden" name="mode" value="selectfile" />
546: <p>
547: <input type="submit" name="submit" value="'.&mt('Select checked files, and continue selecting').'" /><br />
548: <input type="button" name="doit" onclick="finishSelect();" value="'.&mt('Select checked files, and close window').'" />
549: </p>
550: <input type="hidden" name="currentpath" value="'.$current_path.'" />
551: </form>');
552: } else {
553: $r->print(&Apache::loncommon::end_data_table());
554: if ($can_delete) {
555: $r->print('
556: <p>
557: <input type="submit" name="doit" value="'.&mt('Delete Selected').'" />'.
558: &Apache::loncommon::help_open_topic('Portfolio DeleteFile').'
559: </p>
560: <input type="hidden" name="action" value="delete" />
561: <input type="hidden" name="currentpath" value="'.$current_path.'" />
562: </form>'
563: );
564: }
565: }
566: }
567:
568: sub open_form {
569: my ($r,$url)=@_;
570: my @files=&Apache::loncommon::get_env_multiple('form.selectfile');
571: $r->print('<form name="portform" method="post" action="'.$url.'">');
572: $r->print('<input type="hidden" name="action" value="'.
573: $env{'form.action'}.'" />');
574: $r->print('<input type="hidden" name="confirmed" value="1" />');
575: foreach (@files) {
576: $r->print('<input type="hidden" name="selectfile" value="'.
577: $_.'" />');
578: }
579: $r->print('<input type="hidden" name="currentpath" value="'.
580: $env{'form.currentpath'}.'" />');
581: }
582:
583: sub close_form {
584: my ($r,$url,$button_text)=@_;
585: if (!defined($button_text)) {
586: $button_text = {
587: 'continue' => &mt('Continue'),
588: 'cancel' => &mt('Cancel'),
589: };
590: }
591: $r->print('<p><input type="submit" value="'.$button_text->{'continue'}.'" />');
592: $r->print(&group_form_data().'</p></form>');
593: $r->print('<form action="'.$url.'" method="post">
594: <p>
595: <input type="hidden" name="currentpath" value="'.
596: $env{'form.currentpath'}.'" />'.
597: &group_form_data());
598: $r->print("\n".' <input type="submit" value="'.$button_text->{'cancel'}.'" />
599: </p></form>');
600: }
601:
602: sub display_file {
603: my ($path,$filename)=@_;
604: my $display_file_text;
605: my $file_start='<span class="LC_filename">';
606: my $file_end='</span>';
607: if (!defined($path)) { $path=$env{'form.currentpath'}; }
608: if (!defined($filename)) {
609: $filename=$env{'form.selectfile'};
610: $display_file_text = $file_start.$path.$filename.$file_end;
611: } elsif (ref($filename) eq "ARRAY") {
612: foreach my $file (@$filename) {
613: $display_file_text .= $file_start.$path.$file.$file_end.'<br />';
614: }
615: } elsif (ref($filename) eq "SCALAR") {
616: $display_file_text = $file_start.$path.$$filename.$file_end;
617: } else {
618: $display_file_text = $file_start.$path.$filename.$file_end;
619: }
620: return $display_file_text;
621: }
622:
623: sub done {
624: my ($linktext,$url)=@_;
625: unless (defined($linktext)) {
626: $linktext='Return to directory';
627: }
628: my %anchor_fields = (
629: 'showversions' => $env{'form.showversions'},
630: 'currentpath' => $env{'form.currentpath'},
631: 'fieldname' => $env{'form.fieldname'},
632: 'symb' => $env{'form.symb'},
633: 'mode' => $env{'form.mode'}
634: );
635: my $result = &Apache::lonhtmlcommon::actionbox(
636: [&make_anchor($url,\%anchor_fields,&mt($linktext))]);
637: return $result;
638: }
639:
640: sub delete {
641: my ($r,$url,$group)=@_;
642: my @check;
643: my $file_name = $env{'form.currentpath'}.$env{'form.selectfile'};
644: $file_name = &prepend_group($file_name);
645: my @files=&Apache::loncommon::get_env_multiple('form.selectfile');
646: my ($uname,$udom) = &get_name_dom($group);
647: if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
648: $r->print(
649: '<p class="LC_warning">'
650: .&mt('The file is locked and cannot be deleted.')
651: .'</p>'
652: .&done(undef,$url)
653: );
654: } else {
655: if (scalar(@files)) {
656: &open_form($r,$url);
657: $r->print('<p>'.&mt('Delete [_1]?',&display_file(undef,\@files)).'</p>');
658: &close_form($r,$url);
659: } else {
660: $r->print('<p class="LC_warning">'.&mt('No file was checked to delete.').'</p>');
661: $r->print(&done(undef,$url));
662: }
663: }
664: }
665:
666: sub delete_confirmed {
667: my ($r,$url,$group)=@_;
668: my @files=&Apache::loncommon::get_env_multiple('form.selectfile');
669: my $result;
670: my ($uname,$udom) = &get_name_dom($group);
671: my $port_path = &get_port_path();
672: my $current_permissions = &Apache::lonnet::get_portfile_permissions($udom,
673: $uname);
674: my @msg;
675: foreach my $delete_file (@files) {
676: $result =
677: &Apache::lonnet::removeuserfile(
678: $uname,$udom,$port_path.
679: $env{'form.currentpath'}.
680: $delete_file);
681: if ($result ne 'ok') {
682: push(@msg, &Apache::lonhtmlcommon::confirm_success(
683: &mt('An error occurred ([_1]) while trying to delete [_2].'
684: ,$result,&display_file(undef, $delete_file)),1));
685: } else {
686: push(@msg, &Apache::lonhtmlcommon::confirm_success(
687: &mt('File: [_1] deleted.'
688: ,&display_file(undef,$delete_file))));
689: my $file_name = $env{'form.currentpath'}.$delete_file;
690: $file_name = &prepend_group($file_name);
691: my %access_controls =
692: &Apache::lonnet::get_access_controls($current_permissions,
693: $group,$file_name);
694: if (keys(%access_controls) > 0) {
695: my %changes;
696: foreach my $key (keys(%{$access_controls{$file_name}})) {
697: $changes{'delete'}{$key} = 1;
698: }
699: if (keys(%changes) > 0) {
700: my ($outcome,$deloutcome,$new_values,$translation) =
701: &Apache::lonnet::modify_access_controls($file_name,\%changes,
702: $udom,$uname);
703: if ($outcome ne 'ok') {
704: push(@msg, &Apache::lonhtmlcommon::confirm_success(
705: &mt('An error occurred ([_1]) while '.
706: 'trying to delete access controls for the file.',$outcome),1));
707: } else {
708: if ($deloutcome eq 'ok') {
709: push(@msg, &mt('Access controls also deleted for the file.')); # FIXME: Does the user really need this message?
710: } else {
711: push(@msg, &Apache::lonhtmlcommon::confirm_success(
712: &mt('An error occurred ([_1]) while '.
713: 'trying to delete access controls for the file.'
714: ,$deloutcome),1));
715: }
716: }
717: }
718: }
719: }
720: }
721: $r->print(&Apache::loncommon::confirmwrapper(join('<br />',@msg)));
722: $r->print(&done(undef,$url));
723: }
724:
725: sub delete_dir {
726: my ($r,$url)=@_;
727: &open_form($r,$url);
728: $r->print('<p>'.&mt('Delete [_1]?',&display_file()).'</p>');
729: &close_form($r,$url);
730: }
731:
732: sub delete_dir_confirmed {
733: my ($r,$url,$group)=@_;
734: my $directory_name = $env{'form.currentpath'};
735: $directory_name =~ s|/$||; # remove any trailing slash
736: my ($uname,$udom) = &get_name_dom($group);
737: my $namespace = &get_namespace();
738: my $port_path = &get_port_path();
739: my $result=&Apache::lonnet::removeuserfile($uname,$udom,$port_path.
740: $directory_name);
741:
742: if ($result ne 'ok') {
743: $r->print(
744: &Apache::loncommon::confirmwrapper(
745: &Apache::lonhtmlcommon::confirm_success(
746: &mt('An error occurred (dir) ([_1]) while trying to delete [_2].'
747: ,$result,$directory_name),1)));
748: $r->print(&done(undef,$url));
749: return;
750: } else {
751: # now remove from recent
752: &Apache::lonhtmlcommon::remove_recent($namespace,[$directory_name.'/']);
753: my @dirs = split m!/!, $directory_name;
754: $directory_name='/';
755: for (my $i=1; $i < (@dirs - 1); $i ++){
756: $directory_name .= $dirs[$i].'/';
757: }
758: $env{'form.currentpath'} = $directory_name;
759: }
760: $r->print(
761: &Apache::loncommon::confirmwrapper(
762: &Apache::lonhtmlcommon::confirm_success(
763: &mt('Directory successfully deleted'))));
764: $r->print(&done(undef,$url));
765: }
766:
767: sub rename {
768: my ($r,$url,$group)=@_;
769: my $file_name = $env{'form.currentpath'}.$env{'form.rename'};
770: my ($uname,$udom) = &get_name_dom($group);
771: $file_name = &prepend_group($file_name);
772: if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
773: $r->print(
774: '<p class="LC_error">'
775: .&mt('The file is locked and cannot be renamed.')
776: .'</p>'
777: );
778: $r->print(&done(undef,$url));
779: } else {
780: &open_form($r,$url);
781: $r->print('<p>'.&mt('Rename [_1] to [_2]?', &display_file()
782: , '<input name="filenewname" type="text" size="50" />').'</p>');
783: &close_form($r,$url);
784: }
785: }
786:
787: sub rename_confirmed {
788: my ($r,$url,$group)=@_;
789: my $filenewname=&Apache::lonnet::clean_filename($env{'form.filenewname'});
790: my ($uname,$udom) = &get_name_dom($group);
791: my $port_path = &get_port_path();
792:
793: # Display warning in case of filename cleaning has changed the filename
794: if ($filenewname ne $env{'form.filenewname'}) {
795: $r->print(
796: '<p><span class="LC_warning">'
797: .&mt('Invalid characters')
798: .'</span><br />'
799: .&mt('The new filename was changed from [_1] to [_2].'
800: ,'<span class="LC_filename">'.&display_file('',$env{'form.filenewname'}).'</span>'
801: ,'<span class="LC_filename">'.&display_file('',$filenewname).'</span>')
802: .'</p>'
803: );
804:
805: }
806:
807: # Filename empty?
808: if ($filenewname eq '') {
809: $r->print(
810: &Apache::loncommon::confirmwrapper(
811: &Apache::lonhtmlcommon::confirm_success(
812: &mt('Error: no valid filename was provided to rename to.'),1)));
813: $r->print(&done(undef,$url));
814: return;
815: }
816:
817: # Rename the file
818: my $chg_access;
819: my $result=
820: &Apache::lonnet::renameuserfile($uname,$udom,
821: $port_path.$env{'form.currentpath'}.$env{'form.selectfile'},
822: $port_path.$env{'form.currentpath'}.$filenewname);
823: if ($result eq 'ok') {
824: $chg_access = &access_for_renamed($filenewname,$group,$udom,$uname);
825: } else {
826: $r->print(
827: &Apache::loncommon::confirmwrapper(
828: &Apache::lonhtmlcommon::confirm_success(
829: &mt('An error occurred ([_1]) while trying to rename [_2] to [_3].'
830: ,$result,&display_file(),&display_file('',$filenewname))
831: ,1)));
832: $r->print(&done(undef,$url));
833: return;
834: }
835: $r->print($chg_access);
836: $r->print(
837: &Apache::loncommon::confirmwrapper(
838: &Apache::lonhtmlcommon::confirm_success(
839: &mt('File successfully renamed'))));
840: $r->print(&done(undef,$url));
841: }
842:
843: sub access_for_renamed {
844: my ($filenewname,$group,$udom,$uname) = @_;
845: my $oldfile = $env{'form.currentpath'}.$env{'form.selectfile'};
846: $oldfile = &prepend_group($oldfile);
847: my $newfile = $env{'form.currentpath'}.$filenewname;
848: $newfile = &prepend_group($newfile);
849: my $current_permissions =
850: &Apache::lonnet::get_portfile_permissions($udom,$uname);
851: my %access_controls =
852: &Apache::lonnet::get_access_controls($current_permissions,
853: $group,$oldfile);
854: my $chg_text;
855: if (keys(%access_controls) > 0) {
856: my %change_old;
857: my %change_new;
858: foreach my $key (keys(%{$access_controls{$oldfile}})) {
859: $change_old{'delete'}{$key} = 1;
860: $change_new{'activate'}{$key} = $access_controls{$oldfile}{$key};
861: }
862: my ($outcome,$deloutcome,$new_values,$translation) =
863: &Apache::lonnet::modify_access_controls($oldfile,\%change_old,
864: $udom,$uname);
865: if ($outcome ne 'ok') {
866: $chg_text ='<br /><br />'.&mt("An error occurred ([_1]) while ".
867: "trying to delete access control records for the old name.",$outcome).
868: '</span><br />';
869: } else {
870: if ($deloutcome ne 'ok') {
871: $chg_text = '<br /><br /><span class="LC_error"><br />'.
872: &mt("An error occurred ([_1]) while ".
873: "trying to delete access control records for the old name.",$deloutcome).
874: '</span><br />';
875: }
876: }
877: ($outcome,$deloutcome,$new_values,$translation) =
878: &Apache::lonnet::modify_access_controls($newfile,\%change_new,
879: $udom,$uname);
880: if ($outcome ne 'ok') {
881: $chg_text .= '<br /><br />'.
882: &mt("An error occurred ([_1]) while ".
883: "trying to update access control records for the new name.",$outcome).
884: '</span><br />';
885: }
886: if ($chg_text eq '') {
887: $chg_text = '<br /><br />'.&mt('Access controls updated to reflect the name change.');
888: }
889: }
890: return $chg_text;
891: }
892:
893: sub display_access {
894: my ($r,$url,$group,$can_setacl,$can_viewacl,$port_path,$action) = @_;
895: my ($uname,$udom) = &get_name_dom($group);
896: my $file_name = $env{'form.currentpath'}.$env{'form.access'};
897: $file_name = &prepend_group($file_name);
898: my $current_permissions = &Apache::lonnet::get_portfile_permissions($udom,
899: $uname);
900: my %access_controls = &Apache::lonnet::get_access_controls($current_permissions,$group,$file_name);
901: my $aclcount = keys(%access_controls);
902: my ($header,$info);
903: if ($action eq 'chgaccess') {
904: my $uhome = &Apache::lonnet::homeserver($uname,$udom);
905: my $prefix = &Apache::lonnet::url_prefix($r,$udom,$uhome,'web');
906: $header =
907: '<h2>'
908: .&mt('Allowing others to retrieve file: [_1]'
909: ,'<span class="LC_filename">'
910: .$port_path.$env{'form.currentpath'}.$env{'form.access'}
911: .'</span>')
912: .'</h2>';
913: $info .= &mt('Access to this file by others can be set to be one or more of the following types: public, passphrase-protected or conditional.');
914: $info .= '<br /><ul><li>'.&mt('Public files are available to anyone without the need for login.');
915: $info .= '</li><li>'.&mt('Passphrase-protected files do not require log-in, but will require the viewer to enter the passphrase you set.');
916: $info .= '</li><li>'.&explain_conditionals();
917: $info .= '</li></ul>'.
918: &mt('A listing of files viewable without log-in is available at: ')."<a href=\"$prefix/adm/$udom/$uname/aboutme/portfolio\">$prefix/adm/$udom/$uname/aboutme/portfolio</a>.<br />";
919: if ($group eq '') {
920: $info .= &mt("For logged in users a 'Display file listing' link will also appear (when there are viewable files) on your personal information page:");
921: } else {
922: $info .= &mt("For logged in users a 'Display file listing' link will also appear (when there are viewable files) on the course information page:");
923: }
924: $info .= "<br /><a href=\"$prefix/adm/$udom/$uname/aboutme\">$prefix/adm/$udom/$uname/aboutme</a><br />";
925: if ($group ne '') {
926: $info .= &mt("Users with course editing rights may add a 'Group Portfolio' item using the Course Editor (Collaboration tab), to provide access to viewable group portfolio files.").'<br />';
927: }
928: } else {
929: $header = '<h3>'.&mt('Conditional access controls for file: [_1]',$port_path.$env{'form.currentpath'}.$env{'form.access'}).'</h3>'.
930: &explain_conditionals().'<br />';
931: }
932: if ($can_setacl) {
933: &open_form($r,$url);
934: $r->print($header.$info);
935: $r->print('<br />'.&Apache::loncommon::help_open_topic('Portfolio ShareFile SetAccess', &mt('Help on setting up share access')));
936: $r->print(&Apache::loncommon::help_open_topic('Portfolio ShareFile ChangeSetting', &mt('Help on changing settings')));
937: $r->print(&Apache::loncommon::help_open_topic('Portfolio ShareFile StopAccess', &mt('Help on removing share access')));
938: &access_setting_table($r,$url,$file_name,$access_controls{$file_name},
939: $action);
940: my $button_text = {
941: 'continue' => &mt('Proceed'),
942: 'cancel' => &mt('Return to directory'),
943: };
944: &close_form($r,$url,$button_text);
945: } elsif ($can_viewacl) {
946: $r->print($header);
947: if ($aclcount) {
948: $r->print($info);
949: }
950: &view_access_settings($r,$url,$access_controls{$file_name},$aclcount);
951: } else {
952: $r->print($header);
953: $r->print(&mt('You do not have sufficient privileges to view access controls').'<br />');
954: }
955: my %anchor_fields = (
956: 'currentpath' => $env{'form.currentpath'}
957: );
958: $r->print('<br />'.&make_anchor($url, \%anchor_fields, &mt('Return to directory')));
959: return;
960: }
961:
962: sub explain_conditionals {
963: return
964: &mt('Conditional files are accessible to users who satisfy the conditions you set.').'<br /><ul>'.
965: '<li>'.&mt('Conditions can be IP-based, in which case no log-in is required').'</li>'.
966: '<li>'.&mt("Conditions can also be based on a user's status, in which case the user needs an account in the LON-CAPA network, and needs to be logged in.").'<br />'."\n".
967: &mt('The status-based conditions can include affiliation with a particular course or community, or a user account in a specific domain.').'<br />'."\n".
968: &mt('Alternatively access can be granted to people with specific LON-CAPA usernames and domains.').'</li></ul>';
969: }
970:
971: sub view_access_settings {
972: my ($r,$url,$access_controls,$aclcount) = @_;
973: my ($showstart,$showend);
974: my %todisplay;
975: foreach my $key (sort(keys(%{$access_controls}))) {
976: my ($num,$scope,$end,$start) = &unpack_acc_key($key);
977: $todisplay{$scope}{$key} = $$access_controls{$key};
978: }
979: if ($aclcount) {
980: $r->print('<h4>'.&mt('Current access controls defined for this file:').'</h4>');
981: $r->print(&Apache::loncommon::start_data_table());
982: $r->print(&Apache::loncommon::start_data_table_header_row());
983: $r->print('<th>'.&mt('Access control').'</th><th>'.&mt('Dates available').
984: '</th><th>'.&mt('Additional information').'</th>');
985: $r->print(&Apache::loncommon::end_data_table_header_row());
986: my $count = 1;
987: my $chg = 'none';
988: &build_access_summary($r,$count,$chg,%todisplay);
989: $r->print(&Apache::loncommon::end_data_table());
990: } else {
991: $r->print(&mt('No access control settings currently exist for this file.').'<br />');
992: }
993: my %anchor_fields = (
994: 'currentpath' => $env{'form.currentpath'}
995: );
996: $r->print('<br />'.&make_anchor($url, \%anchor_fields, &mt('Return to directory')));
997: return;
998: }
999:
1000: sub build_access_summary {
1001: my ($r,$count,$chg,%todisplay) = @_;
1002: my ($showstart,$showend);
1003: my %scope_desc = (
1004: public => 'Public',
1005: guest => 'Passphrase-protected',
1006: domains => 'Conditional: domain-based',
1007: users => 'Conditional: user-based',
1008: course => 'Conditional: course/community-based',
1009: userip => 'Conditional: IP-based',
1010: );
1011: my @allscopes = ('public','guest','domains','users','course','userip');
1012: foreach my $scope (@allscopes) {
1013: if ((!(exists($todisplay{$scope}))) || (ref($todisplay{$scope}) ne 'HASH')) {
1014: next;
1015: }
1016: foreach my $key (sort(keys(%{$todisplay{$scope}}))) {
1017: if ($count) {
1018: $r->print(&Apache::loncommon::start_data_table_row());
1019: }
1020: my ($num,$scope,$end,$start) = &unpack_acc_key($key);
1021: my $content = $todisplay{$scope}{$key};
1022: if ($chg eq 'delete') {
1023: $showstart = &mt('Deleted');
1024: $showend = $showstart;
1025: } else {
1026: $showstart = &Apache::lonlocal::locallocaltime($start);
1027: if ($end == 0) {
1028: $showend = &mt('No end date');
1029: } else {
1030: $showend = &Apache::lonlocal::locallocaltime($end);
1031: }
1032: }
1033: $r->print('<td>'.&mt($scope_desc{$scope}));
1034: my $crstype;
1035: if ($scope eq 'course') {
1036: if ($chg ne 'delete') {
1037: my $cid = $content->{'domain'}.'_'.$content->{'number'};
1038: my %course_description = &Apache::lonnet::coursedescription($cid);
1039: $r->print('<br />('.$course_description{'description'}.')');
1040: $crstype = 'Course';
1041: if ($course_description{'type'} ne '') {
1042: $crstype = $course_description{'type'};
1043: }
1044: }
1045: }
1046: $r->print('</td><td>'.&mt('Start: ').$showstart.
1047: '<br />'.&mt('End: ').$showend.'</td><td>');
1048: if ($chg ne 'delete') {
1049: if ($scope eq 'guest') {
1050: $r->print(&mt('Passphrase').': '.$content->{'password'});
1051: } elsif ($scope eq 'course') {
1052: $r->print('<table width="100%"><tr>');
1053: $r->print('<th>'.&mt('Roles').'</th><th>'.
1054: &mt('Access').'</th><th>'.
1055: &mt('Sections').'</th>');
1056: $r->print('<th>'.&mt('Groups').'</th>');
1057: $r->print('</tr>');
1058: foreach my $id (sort(keys(%{$content->{'roles'}}))) {
1059: $r->print('<tr>');
1060: foreach my $item ('role','access','section','group') {
1061: $r->print('<td>');
1062: if ($item eq 'role') {
1063: my $role_output;
1064: foreach my $role (@{$content->{'roles'}{$id}{$item}}) {
1065: if ($role eq 'all') {
1066: $role_output .= $role.',';
1067: } elsif ($role =~ /^cr/) {
1068: $role_output .= (split('/',$role))[3].',';
1069: } else {
1070: $role_output .= &Apache::lonnet::plaintext($role,$crstype).',';
1071: }
1072: }
1073: $role_output =~ s/,$//;
1074: $r->print($role_output);
1075: } else {
1076: $r->print(join(',',@{$content->{'roles'}{$id}{$item}}));
1077: }
1078: $r->print('</td>');
1079: }
1080: $r->print('</tr>');
1081: }
1082: $r->print('</table>');
1083: } elsif ($scope eq 'domains') {
1084: $r->print(&mt('Domains: ').join(',',@{$content->{'dom'}}));
1085: } elsif ($scope eq 'users') {
1086: my $curr_user_list = &sort_users($content->{'users'});
1087: $r->print(&mt('Users: ').$curr_user_list);
1088: } elsif ($scope eq 'userip') {
1089: my $curr_ips_list = &sort_ips($content->{'userip'});
1090: $r->print(&mt('IP(s):').' '.$curr_ips_list);
1091: } else {
1092: $r->print(' ');
1093: }
1094: } else {
1095: $r->print(' ');
1096: }
1097: $r->print('</td>');
1098: $r->print(&Apache::loncommon::end_data_table_row());
1099: $count ++;
1100: }
1101: }
1102: }
1103:
1104:
1105: sub update_access {
1106: my ($r,$url,$group,$port_path) = @_;
1107: my $totalprocessed = 0;
1108: my %processing;
1109: my %title = (
1110: 'activate' => 'New control(s) added',
1111: 'delete' => 'Existing control(s) deleted',
1112: 'update' => 'Existing control(s) modified',
1113: );
1114: my $changes;
1115: foreach my $chg (sort(keys(%title))) {
1116: @{$processing{$chg}} = &Apache::loncommon::get_env_multiple('form.'.$chg);
1117: $totalprocessed += @{$processing{$chg}};
1118: foreach my $num (@{$processing{$chg}}) {
1119: my $scope = $env{'form.scope_'.$num};
1120: my ($start,$end) = &get_dates_from_form($num);
1121: my $newkey = $num.':'.$scope.'_'.$end.'_'.$start;
1122: if ($chg eq 'delete') {
1123: $$changes{$chg}{$newkey} = 1;
1124: } else {
1125: $$changes{$chg}{$newkey} =
1126: &build_access_record($num,$scope,$start,$end,$chg);
1127: }
1128: }
1129: }
1130: my $file_name = $env{'form.currentpath'}.$env{'form.selectfile'};
1131: $r->print('<h2>'.&mt('Allowing others to retrieve file: [_1]',
1132: '<span class="LC_filename">'.$port_path.$file_name.'</span>').'</h2>'."\n");
1133: $file_name = &prepend_group($file_name);
1134: my ($uname,$udom) = &get_name_dom($group);
1135: my ($errors,$outcome,$deloutcome,$new_values,$translation);
1136: if ($totalprocessed) {
1137: ($outcome,$deloutcome,$new_values,$translation) =
1138: &Apache::lonnet::modify_access_controls($file_name,$changes,$udom,
1139: $uname);
1140: }
1141: my $current_permissions = &Apache::lonnet::get_portfile_permissions($udom,
1142: $uname);
1143: my %access_controls =
1144: &Apache::lonnet::get_access_controls($current_permissions,
1145: $group,$file_name);
1146: if ($totalprocessed) {
1147: if ($outcome eq 'ok') {
1148: my $updated_controls = $access_controls{$file_name};
1149: my ($showstart,$showend);
1150: $r->print(&Apache::loncommon::start_data_table());
1151: $r->print(&Apache::loncommon::start_data_table_header_row());
1152: $r->print('<th>'.&mt('Type of change').'</th><th>'.
1153: &mt('Access control').'</th><th>'.&mt('Dates available').
1154: '</th><th>'.&mt('Additional information').'</th>');
1155: $r->print(&Apache::loncommon::end_data_table_header_row());
1156: foreach my $chg (sort(keys(%processing))) {
1157: if (@{$processing{$chg}} > 0) {
1158: if ($chg eq 'delete') {
1159: if (!($deloutcome eq 'ok')) {
1160: $errors .='<span class="LC_error">'.
1161: &mt('A problem occurred deleting access controls: [_1]',$deloutcome).
1162: '</span>';
1163: next;
1164: }
1165: }
1166: my $numchgs = @{$processing{$chg}};
1167: $r->print(&Apache::loncommon::start_data_table_row());
1168: $r->print('<td rowspan="'.$numchgs.'">'.&mt($title{$chg}).
1169: '.</td>');
1170: my $count = 0;
1171: my %todisplay;
1172: foreach my $key (sort(keys(%{$$changes{$chg}}))) {
1173: my ($num,$scope,$end,$start) = &unpack_acc_key($key);
1174: my $newkey = $key;
1175: if ($chg eq 'activate') {
1176: $newkey =~ s/^(\d+)/$$translation{$1}/;
1177: }
1178: $todisplay{$scope}{$newkey} = $$updated_controls{$newkey};
1179: }
1180: &build_access_summary($r,$count,$chg,%todisplay);
1181: }
1182: }
1183: $r->print(&Apache::loncommon::end_data_table());
1184: } else {
1185: if ((@{$processing{'activate'}} > 0) || (@{$processing{'update'}} > 0)) {
1186: $errors .= '<span class="LC_error">'.
1187: &mt('A problem occurred saving access control settings: [_1]',$outcome).
1188: '</span>';
1189: }
1190: }
1191: if ($errors) {
1192: $r->print($errors);
1193: }
1194: }
1195: my $allnew = 0;
1196: my $totalnew = 0;
1197: my $status = 'new';
1198: my ($firstitem,$lastitem);
1199: my @types = ('course','domains','users','userip');
1200: foreach my $newitem (@types) {
1201: $allnew += $env{'form.new'.$newitem};
1202: }
1203: if ($allnew > 0) {
1204: my $now = time;
1205: my $then = $now + (60*60*24*180); # six months approx.
1206: &open_form($r,$url);
1207: my %showtypes = (
1208: course => 'course/community',
1209: domains => 'domain',
1210: users => 'user',
1211: userip => 'IP',
1212: );
1213: foreach my $newitem (@types) {
1214: next if ($env{'form.new'.$newitem} <= 0);
1215: $r->print(
1216: '<p>'
1217: .&mt('Add new [_1]'.$showtypes{$newitem}.'-based[_2] access control for portfolio file: [_3]',
1218: '<b>','</b>',
1219: '<span class="LC_filename"><b>'
1220: .$env{'form.currentpath'}.$env{'form.selectfile'}.'</b></span>')
1221: .'</p>');
1222: $firstitem = $totalnew;
1223: $lastitem = $totalnew + $env{'form.new'.$newitem};
1224: $totalnew = $lastitem;
1225: my @numbers;
1226: for (my $i=$firstitem; $i<$lastitem; $i++) {
1227: push(@numbers,$i);
1228: }
1229: &display_access_row($r,$status,$newitem,\@numbers,
1230: $access_controls{$file_name},$now,$then);
1231: }
1232: &close_form($r,$url);
1233: } else {
1234: my %anchor_fields = (
1235: 'currentpath' => $env{'form.currentpath'},
1236: 'access' => $env{'form.selectfile'}
1237: );
1238: my @actions;
1239: push(@actions, &make_anchor($url, \%anchor_fields, &mt('Display all access settings for this file')));
1240: delete $anchor_fields{'access'};
1241: push(@actions, &make_anchor($url,\%anchor_fields,&mt('Return to directory')));
1242: $r->print('<br />'.&Apache::lonhtmlcommon::actionbox(\@actions));
1243: }
1244: return;
1245: }
1246:
1247: sub build_access_record {
1248: my ($num,$scope,$start,$end,$chg) = @_;
1249: my $record = {
1250: type => $scope,
1251: time => {
1252: start => $start,
1253: end => $end
1254: },
1255: };
1256:
1257: if ($scope eq 'guest') {
1258: $record->{'password'} = $env{'form.password'};
1259: } elsif ($scope eq 'course') {
1260: $record->{'domain'} = $env{'form.crsdom_'.$num};
1261: $record->{'number'} = $env{'form.crsnum_'.$num};
1262: my @role_ids;
1263: my @delete_role_ids =
1264: &Apache::loncommon::get_env_multiple('form.delete_role_'.$num);
1265: my @preserves =
1266: &Apache::loncommon::get_env_multiple('form.preserve_role_'.$num);
1267: if (@delete_role_ids) {
1268: foreach my $id (@preserves) {
1269: if (grep {$_ = $id} (@delete_role_ids)) {
1270: next;
1271: }
1272: push(@role_ids,$id);
1273: }
1274: } else {
1275: push(@role_ids,@preserves);
1276: }
1277:
1278: my $next_id = $env{'form.add_role_'.$num};
1279: if ($next_id) {
1280: push(@role_ids,$next_id);
1281: }
1282:
1283: foreach my $id (@role_ids) {
1284: my (@roles,@accesses,@sections,@groups);
1285: if (($id == $next_id) && ($chg eq 'update')) {
1286: @roles = split(/,/,$env{'form.role_'.$num.'_'.$next_id});
1287: @accesses = split(/,/,$env{'form.access_'.$num.'_'.$next_id});
1288: @sections = split(/,/,$env{'form.section_'.$num.'_'.$next_id});
1289: @groups = split(/,/,$env{'form.group_'.$num.'_'.$next_id});
1290: } else {
1291: @roles = &Apache::loncommon::get_env_multiple('form.role_'.$num.'_'.$id);
1292: @accesses = &Apache::loncommon::get_env_multiple('form.access_'.$num.'_'.$id);
1293: @sections = &Apache::loncommon::get_env_multiple('form.section_'.$num.'_'.$id);
1294: @groups = &Apache::loncommon::get_env_multiple('form.group_'.$num.'_'.$id);
1295: }
1296: $record->{'roles'}{$id}{'role'} = \@roles;
1297: $record->{'roles'}{$id}{'access'} = \@accesses;
1298: $record->{'roles'}{$id}{'section'} = \@sections;
1299: $record->{'roles'}{$id}{'group'} = \@groups;
1300: }
1301: } elsif ($scope eq 'domains') {
1302: my @doms = &Apache::loncommon::get_env_multiple('form.dom_'.$num);
1303: $record->{'dom'} = \@doms;
1304: } elsif ($scope eq 'users') {
1305: my $userlist = $env{'form.users_'.$num};
1306: $userlist =~ s/\s+//sg;
1307: my %userhash = map { ($_,1) } (split(/,/,$userlist));
1308: foreach my $user (keys(%userhash)) {
1309: my ($uname,$udom) = split(/:/,$user);
1310: push(@{$record->{'users'}}, {
1311: 'uname' => $uname,
1312: 'udom' => $udom
1313: });
1314: }
1315: } elsif ($scope eq 'userip') {
1316: my $ipslist = $env{'form.ips_'.$num};
1317: $ipslist =~ s/\s+//sg;
1318: my %ipshash = map { ($_,1) } (split(/,/,$ipslist));
1319: foreach my $ip (keys(%ipshash)) {
1320: push(@{$record->{'ip'}},$ip);
1321: }
1322: }
1323: return $record;
1324: }
1325:
1326: sub get_dates_from_form {
1327: my ($id) = @_;
1328: my $startdate;
1329: my $enddate;
1330: $startdate = &Apache::lonhtmlcommon::get_date_from_form('startdate_'.$id);
1331: $enddate = &Apache::lonhtmlcommon::get_date_from_form('enddate_'.$id);
1332: if ( exists ($env{'form.noend_'.$id}) ) {
1333: $enddate = 0;
1334: }
1335: return ($startdate,$enddate);
1336: }
1337:
1338: sub sort_users {
1339: my ($users) = @_;
1340: my @curr_users = map {
1341: $_->{'uname'}.':'.$_->{'udom'}
1342: } (@{$users});
1343: my $curr_user_list = join(",\n",sort(@curr_users));
1344: return $curr_user_list;
1345: }
1346:
1347: sub sort_ips {
1348: my ($ips) = @_;
1349: if (ref($ips) eq 'ARRAY') {
1350: return join(",\n",sort(@{$ips}));
1351: }
1352: }
1353:
1354: sub access_setting_table {
1355: my ($r,$url,$filename,$access_controls,$action) = @_;
1356: my ($public,$publictext);
1357: $publictext ='Off';
1358: my ($guest,$guesttext);
1359: $guesttext = 'Off';
1360: my @courses = ();
1361: my @domains = ();
1362: my @users = ();
1363: my @ips = ();
1364: my $now = time;
1365: my $then = $now + (60*60*24*180); # six months approx.
1366: my ($num,$scope,$publicnum,$guestnum);
1367: my (%acl_count,%end,%start,%conditionals);
1368: foreach my $key (sort(keys(%{$access_controls}))) {
1369: ($num,$scope,$end{$key},$start{$key}) = &unpack_acc_key($key);
1370: if ($scope eq 'public') {
1371: $public = $key;
1372: $publicnum = $num;
1373: $publictext = &acl_status($start{$key},$end{$key},$now);
1374: } elsif ($scope eq 'guest') {
1375: $guest=$key;
1376: $guestnum = $num;
1377: $guesttext = &acl_status($start{$key},$end{$key},$now);
1378: } else {
1379: $conditionals{$scope}{$key} = $$access_controls{$key};
1380: if ($scope eq 'course') {
1381: push(@courses,$key);
1382: } elsif ($scope eq 'domains') {
1383: push(@domains,$key);
1384: } elsif ($scope eq 'users') {
1385: push(@users,$key);
1386: } elsif ($scope eq 'userip') {
1387: push(@ips,$key);
1388: }
1389: }
1390: $acl_count{$scope} ++;
1391: }
1392: $r->print('<table border="0"><tr><td valign="top">');
1393: if ($action eq 'chgaccess') {
1394: &standard_settings($r,$now,$then,$url,$filename,\%acl_count,\%start,
1395: \%end,$public,$publicnum,$publictext,$guest,$guestnum,
1396: $guesttext,$access_controls,%conditionals);
1397: } else {
1398: &condition_setting($r,$access_controls,$now,$then,\%acl_count,
1399: \@domains,\@users,\@courses,\@ips);
1400: }
1401: $r->print('</td></tr></table>');
1402: }
1403:
1404: sub standard_settings {
1405: my ($r,$now,$then,$url,$filename,$acl_count,$start,$end,$public,$publicnum,
1406: $publictext,$guest,$guestnum,$guesttext,$access_controls,%conditionals)=@_;
1407: $r->print('<h3>'.&mt('Public access: [_1]',&mt($publictext)).'</h3>');
1408: $r->print(&Apache::loncommon::start_data_table());
1409: $r->print(&Apache::loncommon::start_data_table_header_row());
1410: $r->print('<th>'.&mt('Action').'</th><th>'.&mt('Dates available').'</th>');
1411: $r->print(&Apache::loncommon::end_data_table_header_row());
1412: $r->print(&Apache::loncommon::start_data_table_row());
1413: if ($public) {
1414: $r->print('<td>'.&actionbox('old',$publicnum,'public').'</td><td>'.
1415: &dateboxes($publicnum,$start->{$public},$end->{$public}).'</td>');
1416: } else {
1417: $r->print('<td>'.&actionbox('new','0','public').'</td><td>'.
1418: &dateboxes('0',$now,$then).'</td>');
1419: }
1420: $r->print(&Apache::loncommon::end_data_table_row());
1421: $r->print(&Apache::loncommon::end_data_table());
1422: $r->print('</td><td width="40"> </td><td valign="top">');
1423: $r->print('<h3>'.&mt('Passphrase-protected access: [_1]',&mt($guesttext)).'</h3>');
1424: $r->print(&Apache::loncommon::start_data_table());
1425: $r->print(&Apache::loncommon::start_data_table_header_row());
1426: $r->print('<th>'.&mt('Action').'</th><th>'.&mt('Dates available').
1427: '</th><th>'. &mt('Passphrase').'</th>');
1428: $r->print(&Apache::loncommon::end_data_table_header_row());
1429: $r->print(&Apache::loncommon::start_data_table_row());
1430: my $passwd;
1431: if ($guest) {
1432: $passwd = $$access_controls{$guest}{'password'};
1433: $r->print('<td>'.&actionbox('old',$guestnum,'guest').'</td><td>'.
1434: &dateboxes($guestnum,$start->{$guest},$end->{$guest}).'</td>');
1435: } else {
1436: $r->print('<td>'.&actionbox('new','1','guest').'</td><td>'.
1437: &dateboxes('1',$now,$then).'</td>');
1438: }
1439: $r->print('<td><input type="text" size="15" name="password" value="'.
1440: $passwd.'" /></td>');
1441: $r->print(&Apache::loncommon::end_data_table_row());
1442: $r->print(&Apache::loncommon::end_data_table());
1443: $r->print('</td></tr><tr><td colspan="3"> </td></tr>'.
1444: '<tr><td colspan="3" valign="top">');
1445: my $numconditionals = 0;
1446: my $conditionstext;
1447: my %cond_status;
1448: foreach my $scope ('domains','users','course','userip') {
1449: $numconditionals += $acl_count->{$scope};
1450: if ($acl_count->{$scope} > 0) {
1451: if ($conditionstext ne 'Active') {
1452: foreach my $key (keys(%{$conditionals{$scope}})) {
1453: $conditionstext = &acl_status($start->{$key},$end->{$key},$now);
1454: if ($conditionstext eq 'Active') {
1455: last;
1456: }
1457: }
1458: }
1459: }
1460: }
1461: if ($conditionstext eq '') {
1462: $conditionstext = 'Off';
1463: }
1464: my %anchor_fields = (
1465: 'access' => $env{'form.selectfile'},
1466: 'action' => 'chgconditions',
1467: 'currentpath' => $env{'form.currentpath'},
1468: );
1469: $r->print('<h3>'.&mt('Conditional access: [_1]',&mt($conditionstext)).'</h3>');
1470: if ($numconditionals > 0) {
1471: my $count = 1;
1472: my $chg = 'none';
1473: $r->print(&mt('You have previously set [_1] conditional access controls.',$numconditionals).' '.&make_anchor($url,\%anchor_fields,&mt('Change Conditions')).'<br /><br />');
1474: $r->print(&Apache::loncommon::start_data_table());
1475: $r->print(&Apache::loncommon::start_data_table_header_row());
1476: $r->print('<th>'.&mt('Access control').'</th><th>'.&mt('Dates available').
1477: '</th><th>'.&mt('Additional information').'</th>');
1478: $r->print(&Apache::loncommon::end_data_table_header_row());
1479: &build_access_summary($r,$count,$chg,%conditionals);
1480: $r->print(&Apache::loncommon::end_data_table());
1481: } else {
1482: $r->print(&make_anchor($url,\%anchor_fields,&mt('Add conditional access')).' '.&mt("based on domain, username, course/community affiliation or user's IP address."));
1483: }
1484: }
1485:
1486: sub condition_setting {
1487: my ($r,$access_controls,$now,$then,$acl_count,$domains,$users,$courses,$ips) = @_;
1488: $r->print('<tr><td valign="top">');
1489: &access_element($r,'domains',$acl_count,$domains,$access_controls,$now,$then);
1490: $r->print('</td><td> </td><td valign="top">');
1491: &access_element($r,'users',$acl_count,$users,$access_controls,$now,$then);
1492: $r->print('</td></tr><tr><td colspan="3"></td></tr><tr><td valign="top">');
1493: &access_element($r,'course',$acl_count,$courses,$access_controls,$now,$then);
1494: $r->print('</td><td> </td><td valign="top">');
1495: &access_element($r,'userip',$acl_count,$ips,$access_controls,$now,$then);
1496: $r->print('</td></tr></table>');
1497: }
1498:
1499: sub acl_status {
1500: my ($start,$end,$now) = @_;
1501: if ($start > $now) {
1502: return 'Inactive';
1503: }
1504: if ($end && $end<$now) {
1505: return 'Inactive';
1506: }
1507: return 'Active';
1508: }
1509:
1510: sub access_element {
1511: my ($r,$type,$acl_count,$items,$access_controls,$now,$then) = @_;
1512: my %typetext = (
1513: domains => 'Domain',
1514: users => 'User',
1515: course => 'Course/Community',
1516: userip => 'IP',
1517: );
1518: $r->print('<h3>'.&mt($typetext{$type}.'-based conditional access:').' ');
1519: if ($$acl_count{$type}) {
1520: $r->print(&mt('[quant,_1,condition]',$$acl_count{$type}));
1521: } else {
1522: $r->print(&mt('Off'));
1523: }
1524: $r->print('</h3>');
1525: &display_access_row($r,'old',$type,$items,$access_controls,$now,$then);
1526: return;
1527: }
1528:
1529: sub display_access_row {
1530: my ($r,$status,$type,$items,$access_controls,$now,$then) = @_;
1531: my ($showtype, $infotype);
1532: if ($type eq 'course') {
1533: $showtype = &mt('Courses/Communities');
1534: $infotype = 'Course/Community';
1535: } elsif ($type eq 'domains') {
1536: $showtype = &mt('Domains');
1537: $infotype = 'Domain';
1538: } elsif ($type eq 'users') {
1539: $showtype = &mt('Users');
1540: $infotype = 'User';
1541: } elsif ($type eq 'userip') {
1542: $showtype = &mt('IP-based');
1543: $infotype = 'IP';
1544: }
1545: if (@{$items} > 0) {
1546: my @all_doms;
1547: my $colspan = 3;
1548: $r->print(&Apache::loncommon::start_data_table());
1549: $r->print(&Apache::loncommon::start_data_table_header_row());
1550: $r->print('<th>'.&mt('Action?').'</th><th>'.$showtype.'</th><th>'.
1551: &mt('Dates available').'</th>');
1552: if ($type eq 'course' && $status eq 'old') {
1553: $r->print('<th>'.&mt('Allowed course/community affiliations').
1554: '</th>');
1555: $colspan ++;
1556: } elsif ($type eq 'domains') {
1557: @all_doms = sort(&Apache::lonnet::all_domains());
1558: }
1559: $r->print(&Apache::loncommon::end_data_table_header_row());
1560: foreach my $key (@{$items}) {
1561: $r->print(&Apache::loncommon::start_data_table_row());
1562: if ($type eq 'course') {
1563: &course_row($r,$status,$type,$key,$access_controls,$now,$then);
1564: } elsif ($type eq 'domains') {
1565: &domains_row($r,$status,$key,\@all_doms,$access_controls,$now,
1566: $then);
1567: } elsif ($type eq 'users') {
1568: &users_row($r,$status,$key,$access_controls,$now,$then);
1569: } elsif ($type eq 'userip') {
1570: &ips_row($r,$status,$key,$access_controls,$now,$then);
1571: }
1572: $r->print(&Apache::loncommon::end_data_table_row());
1573: }
1574: if ($status eq 'old') {
1575: $r->print(&Apache::loncommon::start_data_table_row());
1576: $r->print('<td colspan="',$colspan.'">'.&additional_item($type).
1577: '</td>');
1578: $r->print(&Apache::loncommon::end_data_table_row());
1579: }
1580: $r->print(&Apache::loncommon::end_data_table());
1581: } else {
1582: $r->print(
1583: '<p class="LC_info">'
1584: .&mt('No '.$infotype.'-based conditions defined')
1585: .'</p>'
1586: .&additional_item($type)
1587: );
1588: }
1589: return;
1590: }
1591:
1592: sub course_js {
1593: return qq|
1594: <script type="text/javascript">
1595: // <![CDATA[
1596: function setRoleOptions(num,roleid,cdom,cnum,type) {
1597: updateIndexNum = getIndexByValue('update',num);
1598: var addItem = 'add_role_'+num;
1599: var addIndexNum = getIndexByName(addItem);
1600: if (document.portform.elements[addItem].checked) {
1601: document.portform.elements[updateIndexNum].checked = true;
1602: var url = '/adm/portfolio?action=rolepicker&setroles='+num+'_'+roleid+'&cnum='+cnum+'&cdom='+cdom+'&type='+type;
1603: var title = 'Roles_Chooser';
1604: var options = 'scrollbars=1,resizable=1,menubar=0';
1605: options += ',width=700,height=600';
1606: rolebrowser = open(url,title,options,'1');
1607: rolebrowser.focus();
1608: } else {
1609: addArray = new Array ('role','access','section','group');
1610: for (var j=0;j<addArray.length;j++) {
1611: var itemIndex = getIndexByName(addArray[j]+'_'+num+'_'+roleid);
1612: document.portform.elements[itemIndex].value = '';
1613: }
1614: }
1615: }
1616:
1617: function getIndexByName(item) {
1618: for (var i=0;i<document.portform.elements.length;i++) {
1619: if (document.portform.elements[i].name == item) {
1620: return i;
1621: }
1622: }
1623: return -1;
1624: }
1625:
1626: function getIndexByValue(name,value) {
1627: for (var i=0;i<document.portform.elements.length;i++) {
1628: if (document.portform.elements[i].name == name && document.portform.elements[i].value == value) {
1629: return i;
1630: }
1631: }
1632: return -1;
1633: }
1634:
1635: // ]]>
1636: </script>
1637: |;
1638: }
1639:
1640: sub course_row {
1641: my ($r,$status,$type,$item,$access_controls,$now,$then) = @_;
1642: my $content;
1643: my $defdom = $env{'user.domain'};
1644: if ($status eq 'old') {
1645: $content = $$access_controls{$item};
1646: $defdom = $content->{'domain'};
1647: }
1648: my $js = &Apache::loncommon::coursebrowser_javascript($defdom)
1649: .&course_js();
1650: my $showtype = &mt('Course/Community');
1651: my $crstype = 'Course';
1652: my ($num,$scope,$end,$start) = &set_identifiers($status,$item,$now,$then,
1653: $type);
1654: $r->print('<td>'.$js.&actionbox($status,$num,$scope).'</td>');
1655: if ($status eq 'old') {
1656: my $cid = $content->{'domain'}.'_'.$content->{'number'};
1657: my %course_description = &Apache::lonnet::coursedescription($cid);
1658: if ($course_description{'type'} ne '') {
1659: $crstype = $course_description{'type'};
1660: }
1661: $r->print('<td><input type="hidden" name="crsdom_'.$num.'" value="'.$content->{'domain'}.'" /><input type="hidden" name="crsnum_'.$num.'" value="'.$content->{'number'}.'" />'.$course_description{'description'}.'</td>');
1662: } elsif ($status eq 'new') {
1663: $r->print('<td>'.&Apache::loncommon::selectcourse_link('portform','crsnum_'.$num,'crsdom_'.$num,'description_'.$num,$num.'_1',undef,$showtype).' <input type="text" name="description_'.$num.'" size="30" /><input type="hidden" name="crsdom_'.$num.'" /><input type="hidden" name="crsnum_'.$num.'" /></td>');
1664: }
1665: $r->print('<td>'.&dateboxes($num,$start,$end));
1666: my $newrole_id = 1;
1667: if ($status eq 'old') {
1668: $r->print('</td><td>');
1669: my $max_id = 0;
1670: if (keys(%{$content->{'roles'}}) > 0) {
1671: $r->print('<table><tr><th>'.&mt('Action').'</th>'.
1672: '<th>'.&mt('Roles').'</th>'.
1673: '<th>'.&mt('Access').'</th>'.
1674: '<th>'.&mt('Sections').'</th>'.
1675: '<th>'.&mt('Groups').'</th></tr>');
1676: foreach my $role_id (sort(keys(%{$content->{'roles'}}))) {
1677: if ($role_id > $max_id) {
1678: $max_id = $role_id;
1679: }
1680: $max_id ++;
1681: my $role_selects = &role_selectors($num,$role_id,$crstype,$content,'display');
1682: $r->print('<tr><td><span class="LC_nobreak"><label><input type="checkbox" name="delete_role_'.$num.'" value="'.$role_id.'" />'.&mt('Delete').'</label></span><br /><input type="hidden" name="preserve_role_'.$num.'" value="'.$role_id.'" /></td>'.$role_selects.'</tr>');
1683: }
1684: $r->print('</table>');
1685: }
1686: $r->print('<br />'.&mt('Add a roles-based condition').
1687: ' <input type="checkbox" name="add_role_'.
1688: $num.'" onclick="javascript:setRoleOptions('."'$num',
1689: '$max_id','$content->{'domain'}','$content->{'number'}',
1690: '$showtype'".')" value="" />');
1691: $newrole_id = $max_id;
1692: } else {
1693: $r->print('<input type="hidden" name="add_role_'.$num.'" value="" />');
1694: }
1695: $r->print(&add_course_role($num,$newrole_id));
1696: $r->print('</td>');
1697: return;
1698: }
1699:
1700: sub add_course_role {
1701: my ($num,$max_id) = @_;
1702: my $output;
1703: $output .='<input type="hidden" name="role_'.$num.'_'.$max_id.'" />'.
1704: '<input type="hidden" name="access_'.$num.'_'.$max_id.'" />'.
1705: '<input type="hidden" name="section_'.$num.'_'.$max_id.'" />'.
1706: '<input type="hidden" name="group_'.$num.'_'.$max_id.'" />';
1707: return $output;
1708: }
1709:
1710: sub domains_row {
1711: my ($r,$status,$item,$all_doms,$access_controls,$now,$then) = @_;
1712: my ($num,$scope,$end,$start) = &set_identifiers($status,$item,$now,$then,
1713: 'domains');
1714: my $dom_select = '<select name="dom_'.$num.'" size="4" multiple="multiple">'.
1715: ' <option value="">'.&mt('Please select').'</option>';
1716: if ($status eq 'old') {
1717: my $content = $$access_controls{$item};
1718: foreach my $dom (@{$all_doms}) {
1719: if ((@{$content->{'dom'}} > 0)
1720: && (grep(/^\Q$dom\E$/,@{$content->{'dom'}}))) {
1721: $dom_select .= '<option value="'.$dom.'" selected="selected">'.
1722: $dom.'</option>';
1723: } else {
1724: $dom_select .= '<option value="'.$dom.'">'.$dom.'</option>';
1725: }
1726: }
1727: } else {
1728: foreach my $dom (@{$all_doms}) {
1729: $dom_select .= '<option value="'.$dom.'">'.$dom.'</option>';
1730: }
1731: }
1732: $dom_select .= '</select>';
1733: $r->print('<td>'.&actionbox($status,$num,$scope).'</td><td>'.$dom_select.
1734: '</td><td>'.&dateboxes($num,$start,$end).'</td>');
1735: }
1736:
1737: sub users_row {
1738: my ($r,$status,$item,$access_controls,$now,$then) = @_;
1739: my ($num,$scope,$end,$start) = &set_identifiers($status,$item,$now,$then,
1740: 'users');
1741: my $curr_user_list;
1742: if ($status eq 'old') {
1743: my $content = $$access_controls{$item};
1744: $curr_user_list = &sort_users($content->{'users'});
1745: }
1746: $r->print('<td>'.&actionbox($status,$num,$scope).'</td><td>'.&mt("Format for users' username:domain information:").'<br /><tt>sparty:msu,illini:uiuc ... etc.</tt><br /><textarea name="users_'.$num.'" cols="30" rows="5">'.$curr_user_list.'</textarea></td><td>'.&dateboxes($num,$start,$end).'</td>');
1747: }
1748:
1749: sub ips_row {
1750: my ($r,$status,$item,$access_controls,$now,$then) = @_;
1751: my ($num,$scope,$end,$start) = &set_identifiers($status,$item,$now,$then,
1752: 'userip');
1753: my $curr_ips_list;
1754: if ($status eq 'old') {
1755: my $content = $$access_controls{$item};
1756: $curr_ips_list = &sort_ips($content->{'userip'});
1757: }
1758: $r->print('<td>'.&actionbox($status,$num,$scope).'</td><td>'.&mt('Format for IP controls').'<br />'.
1759: &mt('[_1] or [_2] or [_3] or [_4] or [_5]','<tt>35.8.*</tt>','<tt>35.8.3.[34-56]</tt>',
1760: '<tt>*.msu.edu</tt>','<tt>35.8.3.34</tt>','<tt>somehostname.pa.msu.edu</tt>').'<br />'.
1761: &mt('Use a comma to separate different ranges.').'</br/>'.
1762: '<textarea name="ips_'.$num.'" cols="30" rows="5">'.$curr_ips_list.'</textarea></td>'.
1763: '<td>'.&dateboxes($num,$start,$end).'</td>');
1764: }
1765:
1766: sub additional_item {
1767: my ($type) = @_;
1768: my $showtype;
1769: if ($type eq 'course') {
1770: $showtype = 'course/community';
1771: } elsif ($type eq 'domains') {
1772: $showtype = 'domain';
1773: } elsif ($type eq 'users') {
1774: $showtype = 'user';
1775: } elsif ($type eq 'userip') {
1776: $showtype = 'IP';
1777: }
1778: return
1779: &mt('Add new '.$showtype.'-based condition(s)?')
1780: .' '.&mt('Number to add: ')
1781: .'<input type="text" name="new'.$type.'" size="3" value="0" />';
1782: }
1783:
1784: sub actionbox {
1785: my ($status,$num,$scope) = @_;
1786: my $output = '<span class="LC_nobreak"><label>';
1787: if ($status eq 'new') {
1788: my $checkstate;
1789: if ($scope eq 'domains' || $scope eq 'users' || $scope eq 'course' || $scope eq 'userip') {
1790: $checkstate = 'checked="checked"';
1791: }
1792: $output .= '<input type="checkbox" name="activate" value="'.$num.'" '.
1793: $checkstate.' />'.
1794: &mt('Activate');
1795: } else {
1796: $output .= '<input type="checkbox" name="delete" value="'.$num.
1797: '" />'.&mt('Delete').'</label></span><br /><span class="LC_nobreak">'.
1798: '<label><input type="checkbox" name="update" value="'.
1799: $num.'" />'.&mt('Update');
1800: }
1801: $output .= '</label></span><input type="hidden" name="scope_'.$num.'" value="'.$scope.'" />';
1802: return $output;
1803: }
1804:
1805: sub dateboxes {
1806: my ($num,$start,$end) = @_;
1807: my $noend;
1808: if ($end == 0) {
1809: $noend = 'checked="checked"';
1810: }
1811: my $startdate = &Apache::lonhtmlcommon::date_setter('portform',
1812: 'startdate_'.$num,$start,undef,undef,undef,1,undef,
1813: undef,undef,1);
1814: my $enddate = &Apache::lonhtmlcommon::date_setter('portform',
1815: 'enddate_'.$num,$end,undef,undef,undef,1,undef,
1816: undef,undef,1). ' <span class="LC_nobreak"><label>'.
1817: '<input type="checkbox" name="noend_'.
1818: $num.'" '.$noend.' />'.&mt('No end date').
1819: '</label></span>';
1820:
1821: my $output = &mt('Start: ').$startdate.'<br />'.&mt('End: ').$enddate;
1822: return $output;
1823: }
1824:
1825: sub unpack_acc_key {
1826: my ($acc_key) = @_;
1827: my ($num,$scope,$end,$start) = ($acc_key =~ /^([^:]+):([a-z]+)_(\d*)_?(\d*)$/);
1828: return ($num,$scope,$end,$start);
1829: }
1830:
1831: sub set_identifiers {
1832: my ($status,$item,$now,$then,$scope) = @_;
1833: if ($status eq 'old') {
1834: return(&unpack_acc_key($item));
1835: } else {
1836: return($item,$scope,$then,$now);
1837: }
1838: }
1839:
1840: sub role_selectors {
1841: my ($num,$role_id,$type,$content,$caller) = @_;
1842: my ($output,$cdom,$cnum,$longid);
1843: if ($caller eq 'display') {
1844: $longid = '_'.$num.'_'.$role_id;
1845: $cdom = $$content{'domain'};
1846: $cnum = $$content{'number'};
1847: } elsif ($caller eq 'rolepicker') {
1848: $cdom = $env{'form.cdom'};
1849: $cnum = $env{'form.cnum'};
1850: }
1851: my $crstype = 'Course';
1852: if ($cnum =~ /^$match_community$/) {
1853: $crstype = 'Community'
1854: }
1855: my ($sections,$groups,$allroles,$rolehash,$accesshash) =
1856: &Apache::loncommon::get_secgrprole_info($cdom,$cnum,1,$crstype);
1857: if (!@{$sections}) {
1858: @{$sections} = ('none');
1859: } else {
1860: unshift(@{$sections},('all','none'));
1861: }
1862: if (!@{$groups}) {
1863: @{$groups} = ('none');
1864: } else {
1865: unshift(@{$groups},('all','none'));
1866: }
1867: my @allacesses = sort(keys(%{$accesshash}));
1868: my (%sectionhash,%grouphash);
1869: foreach my $sec (@{$sections}) {
1870: $sectionhash{$sec} = $sec;
1871: }
1872: foreach my $grp (@{$groups}) {
1873: $grouphash{$grp} = $grp;
1874: }
1875: my %lookup = (
1876: 'role' => $rolehash,
1877: 'access' => $accesshash,
1878: 'section' => \%sectionhash,
1879: 'group' => \%grouphash,
1880: );
1881: my @allaccesses = sort(keys(%{$accesshash}));
1882: my %allitems = (
1883: 'role' => $allroles,
1884: 'access' => \@allaccesses,
1885: 'section' => $sections,
1886: 'group' => $groups,
1887: );
1888: foreach my $item ('role','access','section','group') {
1889: $output .= '<td><select name="'.$item.$longid.'" multiple="multiple" size="4">'."\n";
1890: foreach my $entry (@{$allitems{$item}}) {
1891: if ($caller eq 'display') {
1892: if ((@{$$content{'roles'}{$role_id}{$item}} > 0) &&
1893: (grep(/^\Q$entry\E$/,@{$$content{'roles'}{$role_id}{$item}}))) {
1894: $output .= ' <option value="'.$entry.'" selected="selected">'.
1895: $lookup{$item}{$entry}.'</option>';
1896: next;
1897: }
1898: }
1899: $output .= ' <option value="'.$entry.'">'.
1900: $lookup{$item}{$entry}.'</option>';
1901: }
1902: $output .= '</select>';
1903: }
1904: $output .= '</td>';
1905: return $output;
1906: }
1907:
1908: sub role_options_window {
1909: my ($r) = @_;
1910: my $type = $env{'form.type'};
1911: my $rolenum = $env{'form.setroles'};
1912: my ($num,$role_id) = ($rolenum =~ /^([\d_]+)_(\d+)$/);
1913: my $role_elements;
1914: foreach my $item ('role','access','section','group') {
1915: $role_elements .= "'".$item.'_'.$rolenum."',";
1916: }
1917: $role_elements =~ s/,$//;
1918: my $role_selects = &role_selectors($num,$role_id,$type,undef,
1919: 'rolepicker');
1920: $r->print(<<"END_SCRIPT");
1921: <script type="text/javascript">
1922: function setRoles() {
1923: var role_elements = new Array($role_elements);
1924: for (var i=0; i<role_elements.length; i++) {
1925: var copylist = '';
1926: for (var j=0; j<document.rolepicker.elements[i].length; j++) {
1927: if (document.rolepicker.elements[i].options[j].selected) {
1928: copylist = copylist + document.rolepicker.elements[i].options[j].value + ',';
1929: }
1930: }
1931: copylist = copylist.substr(0,copylist.length-1);
1932: var openerItem = getIndexByName(role_elements[i]);
1933: opener.document.portform.elements[openerItem].value = copylist;
1934: }
1935: var roleAdder = getIndexByName('add_role_$num');
1936: opener.document.portform.elements[roleAdder].value = '$role_id';
1937: self.close();
1938: }
1939:
1940: function getIndexByName(item) {
1941: for (var i=0;i<opener.document.portform.elements.length;i++) {
1942: if (opener.document.portform.elements[i].name == item) {
1943: return i;
1944: }
1945: }
1946: return -1;
1947: }
1948:
1949: </script>
1950: END_SCRIPT
1951: $r->print(
1952: '<p>'
1953: .&mt('Select roles, '.lc($type).' status, section(s) and group(s) for users'
1954: .' who will be able to access the portfolio file.')
1955: .'</p>'
1956: );
1957: $r->print(
1958: '<form name="rolepicker" action="/adm/portfolio" method="post">'
1959: .'<table><tr>'
1960: .'<th>'.&mt('Roles').'</th>'
1961: .'<th>'.&mt("$type status").'</th>'
1962: .'<th>'.&mt('Sections').'</th>'
1963: .'<th>'.&mt('Groups').'</th>'
1964: .'</tr><tr>'.$role_selects.'</tr>'
1965: .'</table><br />'
1966: .'<input type="button" name="rolepickbutton" value="'.&mt('Save').'" onclick="setRoles()" />'
1967: );
1968: return;
1969: }
1970:
1971: sub select_files {
1972: my ($r,$dir_list) = @_;
1973: if ($env{'form.continue'} eq 'true') {
1974: # here we update the selections for the currentpath
1975: # eventually, have to handle removing those not checked, but . . .
1976: my @items=&Apache::loncommon::get_env_multiple('form.checkfile');
1977: if (scalar(@items)){
1978: my @ok_items;
1979: if (ref($dir_list) eq 'ARRAY') {
1980: foreach my $dir_line (@{$dir_list}) {
1981: my ($filename,undef,undef,undef,undef,undef,undef,undef,$size)=split(/\&/,$dir_line,10);
1982: if (grep(/^\Q$filename\E$/,@items)) {
1983: if ($size) {
1984: push(@ok_items,$filename);
1985: }
1986: }
1987: }
1988: }
1989: &Apache::lonnet::save_selected_files($env{'user.name'}, $env{'form.currentpath'}, @ok_items);
1990: }
1991: } else {
1992: #empty the file for a fresh start
1993: &Apache::lonnet::clear_selected_files($env{'user.name'});
1994: }
1995: my @files = &Apache::lonnet::files_not_in_path($env{'user.name'}, $env{'form.currentpath'});
1996: my $java_files = join ",", @files;
1997: if ($java_files) {
1998: $java_files.=',';
1999: }
2000: my $javascript =(<<ENDSMP);
2001: <script type="text/javascript">
2002: function finishSelect() {
2003: ENDSMP
2004: $javascript .= 'fileList = "'.$java_files.'";';
2005: $javascript .= (<<ENDSMP);
2006: for (i=0;i<document.forms.checkselect.length;i++) {
2007: if (document.forms.checkselect[i].checked){
2008: fileList = fileList + document.forms.checkselect.currentpath.value + document.forms.checkselect[i].value + "," ;
2009: }
2010: }
2011: var hwfield = opener.document.getElementsByName('$env{'form.fieldname'}');
2012: hwfield[0].value = fileList;
2013: self.close();
2014: }
2015: </script>
2016: ENDSMP
2017: $r->print($javascript);
2018: $r->print("<h1>".&mt('Select portfolio files')."</h1>");
2019: my @otherfiles=&Apache::lonnet::files_not_in_path($env{'user.name'}, $env{'form.currentpath'});
2020: if (@otherfiles) {
2021: $r->print(&Apache::loncommon::start_data_table()
2022: .&Apache::loncommon::start_data_table_header_row()
2023: .'<th>'.&mt('Files selected from other directories:')."</th>"
2024: .&Apache::loncommon::end_data_table_header_row()
2025: );
2026: foreach my $file (@otherfiles) {
2027: $r->print(&Apache::loncommon::start_data_table_row()
2028: .'<td>'.$file."</td>"
2029: .&Apache::loncommon::end_data_table_row()
2030: );
2031: }
2032: $r->print(&Apache::loncommon::end_data_table()
2033: .'<br />'
2034: );
2035: }
2036: $r->print('<div>'
2037: .&mt('Check as many files as you wish in response to the problem:')
2038: .'</div>'
2039: );
2040: }
2041:
2042: sub upload {
2043: my ($r,$url,$group)=@_;
2044: my $formname = 'uploaddoc';
2045: my $fname = &Apache::lonnet::clean_filename($env{'form.'.$formname.'.filename'});
2046: my ($state,$msg);
2047: if ($fname eq '') {
2048: $r->print(
2049: &Apache::loncommon::confirmwrapper(
2050: &Apache::lonhtmlcommon::confirm_success(
2051: &mt('Invalid filename: [_1]; the name of the uploaded file did not contain any letters, '.
2052: 'so after eliminating special characters there was nothing left.',
2053: '<span class="LC_filename">'.$env{'form.uploaddoc.filename'}.'</span>'),1)));
2054:
2055: $r->print(&done(undef,$url));
2056: return;
2057: }
2058: my $disk_quota = &get_quota($group);
2059: my $portfolio_root = &get_portfolio_root();
2060: my $port_path = &get_port_path();
2061: my ($uname,$udom) = &get_name_dom($group);
2062: my $getpropath = 1;
2063: my $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$portfolio_root,$getpropath);
2064: ($state,$msg) =
2065: &Apache::loncommon::check_for_upload($env{'form.currentpath'},$fname,
2066: $group,$formname,$portfolio_root,
2067: $port_path,$disk_quota,
2068: $current_disk_usage,$uname,$udom);
2069: if ($state eq 'will_exceed_quota'
2070: || $state eq 'file_locked'
2071: || $state eq 'zero_bytes') {
2072: $r->print($msg.&done(undef,$url));
2073: return;
2074: }
2075:
2076: my (%allfiles,%codebase,$mode,$mimetype);
2077: if ($env{'form.'.$formname.'.filename'} =~ m/(\.htm|\.html|\.shtml)$/i) {
2078: if ($env{'form.parserflag'}) {
2079: $mode = 'parse';
2080: }
2081: }
2082: my $context;
2083: if ($state eq 'existingfile') {
2084: $context = $state;
2085: }
2086: my $subdir = $port_path.$env{'form.currentpath'};
2087: $subdir =~ s{(/)$}{};
2088: my ($result,$timestamp) =
2089: &Apache::lonnet::userfileupload($formname,$context,$subdir,
2090: $mode,\%allfiles,\%codebase,undef,undef,
2091: undef,undef,undef,undef,\$mimetype);
2092: if ($state eq 'existingfile') {
2093: my $group_elem;
2094: my $rootdir = $r->dir_config('lonDaemons').'/tmp/overwrites';
2095: if ($group eq '') {
2096: $rootdir .= '/'.$env{'user.domain'}.'/'.$env{'user.name'};
2097: } else {
2098: $rootdir .= '/'.$env{'course.'.$env{'request.course.id'}.'.domain'}.
2099: '/'.$env{'course.'.$env{'request.course.id'}.'.num'};
2100: $group_elem = '<input type="hidden" name="group" value="'.$group.'" />';
2101: }
2102: if (($result eq $rootdir.'/'.$port_path.$env{'form.currentpath'}.$fname) && ($timestamp =~ /^\d+$/)) {
2103: my $showfname = &HTML::Entities::encode($fname,'&<>"');
2104: my %lt = &Apache::lonlocal::texthash (
2105: over => 'Overwrite existing file?',
2106: yes => 'Yes',
2107: no => 'No',
2108: undo => 'This action can not be undone.',
2109: conf => 'Are you sure you want to overwrite an existing file?',
2110: cont => 'Continue',
2111: );
2112: my $parserflag;
2113: my $hidden = &hidden_elems();
2114: if ($mode eq 'parse') {
2115: $parserflag = '<input type="hidden" name="parserflag" value="1" />';
2116: }
2117: $r->print(<<"END");
2118: <script type="text/javascript">
2119: // <![CDATA[
2120: function confirmOverwrite() {
2121: var chosen;
2122: if (document.existingfile.overwrite.length) {
2123: for (var i=0; i<document.existingfile.overwrite.length; i++) {
2124: if (document.existingfile.overwrite[i].checked) {
2125: chosen = document.existingfile.overwrite[i].value;
2126: }
2127: }
2128: }
2129: if (chosen == 1) {
2130: if (confirm('$lt{'conf'}')) {
2131: document.existingfile.action.value = "process_overwrite";
2132: return true;
2133: } else {
2134: document.existingfile.action.value = "cancel_overwrite";
2135: if (document.existingfile.overwrite.length) {
2136: for (var i=0; i<document.existingfile.overwrite.length; i++) {
2137: if (document.existingfile.overwrite[i].value == "0") {
2138: document.existingfile.overwrite[i].checked = true;
2139: }
2140: }
2141: }
2142: return false;
2143: }
2144: } else {
2145: document.existingfile.action.value = "cancel_overwrite";
2146: return true;
2147: }
2148: }
2149: // ]]>
2150: </script>
2151: <p>
2152: $msg
2153: </p>
2154: <form method="post" action="$url" name="existingfile" onsubmit="return confirmOverwrite();">
2155: <p class="LC_nobreak">$lt{'over'}
2156: <label><input type="radio" name="overwrite" value="1" />
2157: $lt{'yes'}</label>
2158: <label><input type="radio" name="overwrite" value="0" checked="checked" />$lt{'no'}</label></p>
2159: <p>
2160: <input type="hidden" name="action" value="cancel_overwrite" />
2161: <input type="hidden" name="filename" value="$showfname" />
2162: <input type="hidden" name="timestamp" value="$timestamp" />
2163: $hidden
2164: $parserflag
2165: $group_elem
2166: <input type="submit" name="process" value="$lt{'cont'}" />
2167: </p>
2168: </form>
2169: END
2170: } else {
2171: $r->print(
2172: &Apache::loncommon::confirmwrapper(
2173: &Apache::lonhtmlcommon::confirm_success(
2174: &mt('An error occurred ([_1]) while trying to upload [_2].'
2175: ,$result,&display_file(undef,$fname)),1)));
2176: $r->print(&done(undef,$url));
2177: }
2178: } elsif ($result !~ m|^/uploaded/|) {
2179: $r->print(
2180: &Apache::loncommon::confirmwrapper(
2181: &Apache::lonhtmlcommon::confirm_success(
2182: &mt('An error occurred ([_1]) while trying to upload [_2].'
2183: ,$result,&display_file(undef,$fname)),1)));
2184: $r->print(&done(undef,$url));
2185: } else {
2186: if (!&suppress_embed_prompt()) {
2187: if ($mimetype eq 'text/html') {
2188: if (keys(%allfiles) > 0) {
2189: &print_dependency_form($r,$url,\%allfiles,\%codebase,$result);
2190: return;
2191: } else {
2192: $r->print('<p class="LC_warning">'.&mt('No embedded items identified.').'</p>');
2193: }
2194: }
2195: }
2196: $r->print(
2197: &Apache::loncommon::confirmwrapper(
2198: &Apache::lonhtmlcommon::confirm_success(
2199: &mt('File successfully uploaded'))));
2200: $r->print(&done(undef,$url));
2201: }
2202: return;
2203: }
2204:
2205: sub hidden_elems {
2206: my $contelem;
2207: if ($env{'form.mode'} eq 'selectfile') {
2208: $contelem = '<input type="hidden" name="continue" value="true" />';
2209: }
2210: return <<END;
2211: <input type="hidden" name="currentpath" value="$env{'form.currentpath'}" />
2212: <input type="hidden" name="symb" value="$env{'form.symb'}" />
2213: <input type="hidden" name="fieldname" value="$env{'form.fieldname'}" />
2214: <input type="hidden" name="mode" value="$env{'form.mode'}" />
2215: <input type="hidden" name="showversions" value="$env{'form.showversions'}" />
2216: $contelem
2217: END
2218: }
2219:
2220: sub print_dependency_form {
2221: my ($r,$url,$allfiles,$codebase,$result) = @_;
2222: my $container = &HTML::Entities::encode($result,'<>"&');
2223: my $state = &embedded_form_elems($container);
2224: my ($embedded,$num,$pathchg) = &Apache::loncommon::ask_for_embedded_content($url,$state,$allfiles,$codebase,
2225: {'error_on_invalid_names' => 1,
2226: 'ignore_remote_references' => 1,});
2227: if ($embedded) {
2228: if ($num || $pathchg) {
2229: $r->print('<h3>'.&mt("Reference Warning").'</h3>');
2230: } else {
2231: $r->print('<h3>'.&mt("Reference Information").'</h3>');
2232: }
2233: if ($num) {
2234: $r->print('<p>'.&mt('Completed upload of the file.').' '.
2235: &mt('This file contained references to other files.').' '.
2236: &mt('You must upload the referenced files or else the uploaded file may not work properly.').
2237: '</p>'.
2238: '<p>'.&mt("Please select the locations from which the referenced files are to be uploaded.").'</p>'.
2239: $embedded.
2240: '<p>'.&mt('or').'</p>'.&done('Return to directory',$url));
2241: } else {
2242: $r->print('<p>'.&mt("Completed upload of the file. This file contained references to other files.").'</p>'.
2243: $embedded.
2244: '<p>'.&done('Return to directory',$url).'</p>');
2245: }
2246: } else {
2247: $r->print(&done(undef,$url));
2248: }
2249: return;
2250: }
2251:
2252: sub overwrite {
2253: my ($r,$url,$group)=@_;
2254: my $formname = 'existingfile';
2255: my $port_path = &get_port_path();
2256: my $fname = &Apache::lonnet::clean_filename($env{'form.filename'});
2257: my (%allfiles,%codebase,$mode,$mimetype);
2258: unless (&suppress_embed_prompt()) {
2259: if ($env{'form.parserflag'}) {
2260: if ($fname =~ /\.s?html?$/i) {
2261: $mode = 'parse';
2262: }
2263: }
2264: }
2265: if ($fname eq '') {
2266: $r->print(
2267: &Apache::loncommon::confirmwrapper(
2268: &Apache::lonhtmlcommon::confirm_success(
2269: &mt('Invalid filename: [_1]; the name of the uploaded file did not contain any letters, '.
2270: 'so after eliminating special characters there was nothing left.',
2271: '<span class="LC_filename">'.$env{'form.filename'}.'</span>'),1)));
2272: $r->print(&done(undef,$url));
2273: return;
2274: }
2275: $env{'form.'.$formname.'.filename'} = $fname;
2276: my $subdir = $port_path.$env{'form.currentpath'};
2277: $subdir =~ s{(/)$}{};
2278: my $result=
2279: &Apache::lonnet::userfileupload($formname,'overwrite',$subdir,$mode,
2280: \%allfiles,\%codebase,undef,undef,undef,
2281: undef,undef,undef,\$mimetype);
2282: if ($result !~ m|^/uploaded/|) {
2283: $r->print(
2284: &Apache::loncommon::confirmwrapper(
2285: &Apache::lonhtmlcommon::confirm_success(
2286: &mt('An error occurred ([_1]) while trying to overwrite [_2].'
2287: ,$result,&display_file(undef,$fname)),1)));
2288: } else {
2289: if ($mode eq 'parse') {
2290: if ($mimetype eq 'text/html') {
2291: if (keys(%allfiles) > 0) {
2292: &print_dependency_form($r,$url,\%allfiles,\%codebase,$result);
2293: return;
2294: } else {
2295: $r->print(
2296: &Apache::loncommon::confirmwrapper(
2297: &Apache::lonhtmlcommon::confirm_success(
2298: &mt('Overwriting completed.'))
2299: .'<br />'.&mt('No embedded items identified.')));
2300: }
2301: }
2302: } else {
2303: $r->print(
2304: &Apache::loncommon::confirmwrapper(
2305: &Apache::lonhtmlcommon::confirm_success(
2306: &mt('Overwriting completed.'))));
2307: }
2308: }
2309:
2310: my $group_elem;
2311: if (defined($env{'form.group'})) {
2312: $group_elem = '<input type="hidden" name="group" value="'.$env{'form.group'}.'" />';
2313: if (defined($env{'form.ref'})) {
2314: $group_elem .= '<input type="hidden" name="ref" value="'.$env{'form.ref'}.'" />'."\n";
2315: }
2316: }
2317: my $hidden = &hidden_elems();
2318: $r->print(
2319: &Apache::lonhtmlcommon::actionbox(
2320: ['<a href="javascript:document.overwritedone.submit();">'
2321: .&mt('Return to directory')
2322: .'</a>'])
2323: .'<form name="overwritedone" method="post" action="'.$url.'">'
2324: .$hidden
2325: .$group_elem
2326: .'</form>'
2327: );
2328: return;
2329: }
2330:
2331: sub lock_info {
2332: my ($r,$url,$group) = @_;
2333: my ($uname,$udom) = &get_name_dom($group);
2334: my $current_permissions = &Apache::lonnet::get_portfile_permissions($udom,
2335: $uname);
2336: my $file_name = $env{'form.lockinfo'};
2337: $file_name = &prepend_group($file_name);
2338: if (defined($file_name) && defined($$current_permissions{$file_name})) {
2339: foreach my $array_item (@{$$current_permissions{$file_name}}) {
2340: next if (ref($array_item) ne 'ARRAY');
2341:
2342: my $filetext;
2343: if (defined($group)) {
2344: $filetext = '<strong>'.$env{'form.lockinfo'}.
2345: '</strong> (group: '.$group.')';
2346: } else {
2347: $filetext = '<span class="LC_filename">'.$file_name.'</span>';
2348: }
2349:
2350: my $title ='<strong>'.&Apache::lonnet::gettitle($$array_item[0]).
2351: '</strong><br />';
2352: if ($$array_item[-1] eq 'graded') {
2353: $r->print(&mt('[_1] was submitted in response to problem: [_2]',
2354: $filetext,$title));
2355: } elsif ($$array_item[-1] eq 'handback') {
2356: $r->print(&mt('[_1] was handed back in response to problem: [_2]',
2357: $filetext,$title));
2358: } else {
2359: # submission style lock
2360: $r->print(&mt('[_1] was submitted in response to problem: [_2]',
2361: $filetext,$title));
2362: }
2363: my %course_description =
2364: &Apache::lonnet::coursedescription($$array_item[1]);
2365: if ( $course_description{'description'} ne '') {
2366: $r->print(&mt('In the course:').' <strong>'.$course_description{'description'}.'</strong><br />');
2367: }
2368: }
2369: }
2370: $r->print(&done(undef,$url));
2371: return 'ok';
2372: }
2373:
2374: sub createdir {
2375: my ($r,$url,$group)=@_;
2376: my $newdir=&Apache::lonnet::clean_filename($env{'form.newdir'});
2377: # Display warning in case of directory name cleaning has changed the directory name
2378: if ($newdir ne $env{'form.newdir'}) {
2379: $r->print(
2380: '<p><span class="LC_warning">'
2381: .&mt('Invalid characters')
2382: .'</span><br />'
2383: .&mt('The new directory name was changed from [_1] to [_2].'
2384: ,'<span class="LC_filename">'.$env{'form.newdir'}.'</span>'
2385: ,'<span class="LC_filename">'.$newdir.'</span>')
2386: .'</p>'
2387: );
2388: }
2389:
2390: # Directory name empty?
2391: if ($newdir eq '') {
2392: $r->print(
2393: &Apache::loncommon::confirmwrapper(
2394: &Apache::lonhtmlcommon::confirm_success(
2395: &mt('Error: no directory name was provided.'),1)));
2396: $r->print(&done(undef,$url));
2397: return;
2398: }
2399:
2400: my $portfolio_root = &get_portfolio_root();
2401: my ($dirlistref,$listerror) = &get_dir_list($portfolio_root,undef,$group);
2402: my $found_file = 0;
2403: if (ref($dirlistref) eq 'ARRAY') {
2404: foreach my $line (@{$dirlistref}) {
2405: my ($filename)=split(/\&/,$line,2);
2406: if ($filename eq $newdir){
2407: $found_file = 1;
2408: }
2409: }
2410: }
2411: if ($found_file) {
2412: $r->print(
2413: &Apache::loncommon::confirmwrapper(
2414: &Apache::lonhtmlcommon::confirm_success(
2415: &mt('Unable to create a directory named [_1].'
2416: ,'<span class="LC_filename">'.$newdir.'</span>'),1)
2417: .'<br />'.&mt('A file or directory by that name already exists.')));
2418: } else {
2419: my ($uname,$udom) = &get_name_dom($group);
2420: my $port_path = &get_port_path();
2421: my $result=&Apache::lonnet::mkdiruserfile($uname,$udom,
2422: $port_path.$env{'form.currentpath'}.$newdir);
2423: if ($result ne 'ok') {
2424: $r->print(
2425: &Apache::loncommon::confirmwrapper(
2426: &Apache::lonhtmlcommon::confirm_success(
2427: &mt('An error occurred ([_1]) while trying to create a new directory [_2].'
2428: ,$result,&display_file()),1)));
2429:
2430: } else {
2431: $r->print(
2432: &Apache::loncommon::confirmwrapper(
2433: &Apache::lonhtmlcommon::confirm_success(
2434: &mt('Directory successfully created'))));
2435: }
2436: }
2437: $r->print(&done(undef,$url));
2438: }
2439:
2440: sub get_portfolio_root {
2441: my ($udom,$uname,$group) = @_;
2442: if (!(defined($udom)) || !(defined($uname))) {
2443: ($uname,$udom) = &get_name_dom($group);
2444: }
2445: my $path = '/userfiles/portfolio';
2446: if (!defined($group)) {
2447: if (defined($env{'form.group'})) {
2448: $group = $env{'form.group'};
2449: }
2450: }
2451: if (defined($group)) {
2452: $path = '/userfiles/groups/'.$group.'/portfolio';
2453: }
2454: return $path;
2455: }
2456:
2457: sub get_group_quota {
2458: my ($group) = @_;
2459: my $group_quota;
2460: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2461: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2462: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum,$group);
2463: if (%curr_groups) {
2464: my %group_info = &Apache::longroup::get_group_settings(
2465: $curr_groups{$group});
2466: $group_quota = $group_info{'quota'}; #expressed in MB
2467: if ($group_quota) {
2468: $group_quota = 1000 * $group_quota; #expressed in k
2469: }
2470: }
2471: return $group_quota;
2472: }
2473:
2474: sub get_dir_list {
2475: my ($portfolio_root,$path,$group) = @_;
2476: $path ||= $env{'form.currentpath'};
2477: my ($uname,$udom) = &get_name_dom($group);
2478: my $getpropath = 1;
2479: return &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
2480: }
2481:
2482: sub get_name_dom {
2483: my ($group) = @_;
2484: my ($uname,$udom);
2485: if (defined($group)) {
2486: $udom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2487: $uname = $env{'course.'.$env{'request.course.id'}.'.num'};
2488: } else {
2489: $udom = $env{'user.domain'};
2490: $uname = $env{'user.name'};
2491: }
2492: return ($uname,$udom);
2493: }
2494:
2495: sub prepend_group {
2496: my ($filename) = @_;
2497: if (defined($env{'form.group'})) {
2498: $filename = $env{'form.group'}.$filename;
2499: }
2500: return $filename;
2501: }
2502:
2503: sub get_namespace {
2504: my $namespace = 'portfolio';
2505: if (defined($env{'form.group'})) {
2506: my ($uname,$udom) = &get_name_dom($env{'form.group'});
2507: $namespace .= '_'.$udom.'_'.$uname.'_'.$env{'form.group'};
2508: }
2509: return $namespace;
2510: }
2511:
2512: sub get_port_path {
2513: my $port_path;
2514: if (defined($env{'form.group'})) {
2515: $port_path = "groups/$env{'form.group'}/portfolio";
2516: } else {
2517: $port_path = 'portfolio';
2518: }
2519: return $port_path;
2520: }
2521:
2522: sub missing_priv {
2523: my ($r,$url,$priv) = @_;
2524: my %longtext =
2525: &Apache::lonlocal::texthash(
2526: upload => 'upload files',
2527: delete => 'delete files',
2528: rename => 'rename files',
2529: setacl => 'set access controls for files',
2530: viewacl => 'view access controls for files',
2531: );
2532: my $escpath = &HTML::Entities::encode($env{'form.currentpath'},'&<>"');
2533: my $rtnlink = '<a href="'.$url;
2534: if ($url =~ /\?/) {
2535: $rtnlink .= '&';
2536: } else {
2537: $rtnlink .= '?';
2538: }
2539: $rtnlink .= 'currentpath='.$escpath;
2540: $r->print('<h3>'.&mt('Action disallowed').'</h3>');
2541: $r->print(&mt('You do not have sufficient privileges to [_1]',
2542: $longtext{$priv}));
2543: if (defined($env{'form.group'})) {
2544: $r->print(' '.&mt("in the group's group portfolio."));
2545: $rtnlink .= &group_args()
2546: } else {
2547: $r->print(' '.&mt('in this portfolio.'));
2548: }
2549: $rtnlink .= '">'.&mt('Return to directory').'</a>';
2550: $r->print('<br />'.$rtnlink);
2551: return;
2552: }
2553:
2554: sub coursegrp_portfolio_header {
2555: my ($cdom,$cnum,$grp_desc)=@_;
2556: my $gpterm = &Apache::loncommon::group_term();
2557: my $ucgpterm = $gpterm;
2558: $ucgpterm =~ s/^(\w)/uc($1)/e;
2559: if ($env{'form.ref'}) {
2560: &Apache::lonhtmlcommon::add_breadcrumb
2561: ({href=>"/adm/coursegroups",
2562: text=>"Groups",
2563: title=>"Course Groups"});
2564: }
2565: &Apache::lonhtmlcommon::add_breadcrumb
2566: ({href=>"/adm/$cdom/$cnum/$env{'form.group'}/smppg?ref=$env{'form.ref'}",
2567: text=>&mt('Group').": $grp_desc",
2568: title=>&mt("Go to group's home page"),
2569: no_mt=>1},
2570: {href=>"/adm/coursegrp_portfolio?".&group_args(),
2571: text=>"Group Portfolio",
2572: title=>"Display group portfolio"});
2573: my $output = &Apache::lonhtmlcommon::breadcrumbs(
2574: &mt('Group portfolio files - [_1]',$grp_desc),
2575: undef,undef,undef,undef,1);
2576: return $output;
2577: }
2578:
2579: sub get_quota {
2580: my ($group) = @_;
2581: my $disk_quota;
2582: if (defined($group)) {
2583: my $grp_quota = &get_group_quota($group); # quota expressed in k
2584: if ($grp_quota ne '') {
2585: $disk_quota = $grp_quota;
2586: } else {
2587: $disk_quota = 0;
2588: }
2589: } else {
2590: $disk_quota = &Apache::loncommon::get_user_quota($env{'user.name'},
2591: $env{'user.domain'}); #expressed in MB
2592: $disk_quota = 1024 * $disk_quota; # convert from MB to kB
2593: }
2594: return $disk_quota;
2595: }
2596:
2597: sub suppress_embed_prompt {
2598: my $suppress_prompt = 0;
2599: if (($env{'request.role'} =~ /^st/) && ($env{'request.course.id'} ne '')) {
2600: if ($env{'course.'.$env{'request.course.id'}.'.suppress_embed_prompt'} eq 'yes') {
2601: $suppress_prompt = 1;
2602: }
2603: }
2604: return $suppress_prompt;
2605: }
2606:
2607: sub embedded_form_elems {
2608: my ($container) = @_;
2609: my $state = <<STATE;
2610: <input type="hidden" name="currentpath" value="$env{'form.currentpath'}" />
2611: <input type="hidden" name="symb" value="$env{'form.symb'}" />
2612: <input type="hidden" name="fieldname" value="$env{'form.fieldname'}" />
2613: <input type="hidden" name="mode" value="$env{'form.mode'}" />
2614: <input type="hidden" name="container" value="$container" />
2615: STATE
2616: if ($env{'form.group'} ne '') {
2617: $state .= '<input type="hidden" name="group" value="'.$env{'form.group'}.'" />'."\n";
2618: }
2619: return $state;
2620: }
2621:
2622: # Find space available in a user's portfolio (convert to bytes)
2623: sub free_space {
2624: my ($group) = @_;
2625: my $disk_quota = &get_quota($group); # Expressed in kB
2626: my ($uname,$udom) = &get_name_dom($group);
2627: my $portfolio_root = &get_portfolio_root();
2628: my $getpropath = 1;
2629: my $current_disk_usage = &Apache::lonnet::diskusage($udom, $uname,
2630: $portfolio_root, $getpropath); # Expressed in kB
2631: my $free_space = 1024 * ($disk_quota - $current_disk_usage);
2632: return $free_space;
2633: }
2634:
2635: sub valid_container {
2636: my ($uname,$udom,$group) = @_;
2637: my $container_prefix;
2638: if ($group ne '') {
2639: $container_prefix = "/uploaded/$udom/$uname/groups/$group/portfolio";
2640: } else {
2641: $container_prefix = "/uploaded/$udom/$uname/portfolio";
2642: }
2643: if ($env{'form.currentpath'}) {
2644: $container_prefix .= $env{'form.currentpath'};
2645: } else {
2646: $container_prefix .= '/';
2647: }
2648: if ($env{'form.container'} =~ m{^\Q$container_prefix\E(.+)$}) {
2649: my $filename = $1;
2650: if ($filename eq &Apache::lonnet::clean_filename($filename)) {
2651: return 1;
2652: }
2653: }
2654: return;
2655: }
2656:
2657: sub invalid_parms {
2658: my ($r,$url,$currentpath) = @_;
2659: my $escpath = &HTML::Entities::encode($currentpath,'&<>"');
2660: my $rtnlink = '<a href="'.$url;
2661: if ($url =~ /\?/) {
2662: $rtnlink .= '&';
2663: } else {
2664: $rtnlink .= '?';
2665: }
2666: $rtnlink .= 'currentpath='.$escpath;
2667: $rtnlink .= '">'.&mt('Return to directory').'</a>';
2668: $r->print('<h3>'.&mt('Action disallowed').'</h3>');
2669: $r->print(&mt('Some of the data included with this request were invalid'));
2670: $r->print('<br />'.$rtnlink);
2671: return;
2672: }
2673:
2674: sub handler {
2675: # this handles file management
2676: my $r = shift;
2677: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
2678: ['selectfile','currentpath','meta','lockinfo','currentfile','action',
2679: 'fieldname','mode','rename','continue','group','access','setnum',
2680: 'cnum','cdom','type','setroles','showversions','ref','symb']);
2681: my ($uname,$udom,$portfolio_root,$url,$caller,$title,$group,$grp_desc);
2682: if ($r->uri =~ m|^(/adm/)([^/]+)|) {
2683: $url = $1.$2;
2684: $caller = $2;
2685: }
2686: my ($can_modify,$can_delete,$can_upload,$can_setacl,$can_viewacl);
2687: if ($caller eq 'coursegrp_portfolio') {
2688: # Needs to be in a course
2689: if (! ($env{'request.course.fn'})) {
2690: # Not in a course
2691: $env{'user.error.msg'}=
2692: "/adm/coursegrp_portfolio:rgf:0:0:Cannot view group portfolio";
2693: return HTTP_NOT_ACCEPTABLE;
2694: }
2695: my $earlyout = 0;
2696: my $view_permission =
2697: &Apache::lonnet::allowed('vcg',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''));
2698: $env{'form.group'} =~ s/\W//g;
2699: $group = $env{'form.group'};
2700: if ($group ne '') {
2701: ($uname,$udom) = &get_name_dom($group);
2702: my %curr_groups = &Apache::longroup::coursegroups($udom,$uname,
2703: $group);
2704: if (%curr_groups) {
2705: my %grp_content = &Apache::longroup::get_group_settings(
2706: $curr_groups{$group});
2707: $grp_desc = &unescape($grp_content{'description'});
2708: if (($view_permission) || (&Apache::lonnet::allowed('rgf',
2709: $env{'request.course.id'}.'/'.$group))) {
2710: $portfolio_root = &get_portfolio_root();
2711: } else {
2712: $r->print(&mt('You do not have the privileges required to access the shared files space for this group.'));
2713: $earlyout = 1;
2714: }
2715: } else {
2716: $r->print(&mt('Not a valid group for this course'));
2717: $earlyout = 1;
2718: }
2719: $title = &mt('Group portfolio for [_1]', $group);
2720: } else {
2721: $r->print(&mt('Invalid group'));
2722: $earlyout = 1;
2723: }
2724: if ($earlyout) { return OK; }
2725: if (&Apache::lonnet::allowed('mdg',$env{'request.course.id'})) {
2726: $can_modify = 1;
2727: $can_delete = 1;
2728: $can_upload = 1;
2729: $can_setacl = 1;
2730: $can_viewacl = 1;
2731: } else {
2732: if (&Apache::lonnet::allowed('agf',$env{'request.course.id'}.'/'.$group)) {
2733: $can_setacl = 1;
2734: }
2735: if (&Apache::lonnet::allowed('ugf',$env{'request.course.id'}.'/'.$group)) {
2736: $can_upload = 1;
2737: }
2738: if (&Apache::lonnet::allowed('mgf',$env{'request.course.id'}.'/'.$group)) {
2739: $can_modify = 1;
2740: }
2741: if (&Apache::lonnet::allowed('dgf',$env{'request.course.id'}.'/'.$group)) {
2742: $can_delete = 1;
2743: }
2744: if (&Apache::lonnet::allowed('rgf',$env{'request.course.id'}.'/'.$group)) {
2745: $can_viewacl = 1;
2746: }
2747: }
2748: } else {
2749: ($uname,$udom) = &get_name_dom();
2750: $portfolio_root = &get_portfolio_root();
2751: $title = 'My Space';
2752: $can_modify = 1;
2753: $can_delete = 1;
2754: $can_upload = 1;
2755: if (&Apache::lonnet::usertools_access('','','portaccess',
2756: undef,'tools')) {
2757: $can_viewacl = 1;
2758: $can_setacl = 1;
2759: }
2760: }
2761:
2762: my $port_path = &get_port_path();
2763: &Apache::loncommon::no_cache($r);
2764: &Apache::loncommon::content_type($r,'text/html');
2765: $r->send_http_header;
2766: # Give the LON-CAPA page header
2767: my $brcrum = [{href=>"/adm/portfolio",text=>"Portfolio Manager"}];
2768:
2769: my $js = '<script type="text/javascript"
2770: src="/res/adm/includes/file_upload.js"></script>';
2771:
2772: if ($env{"form.mode"} eq 'selectfile'){
2773: $r->print(&Apache::loncommon::start_page($title, $js,
2774: {'only_body' => 1}));
2775: } elsif ($env{'form.action'} eq 'rolepicker') {
2776: $r->print(&Apache::loncommon::start_page('New role-based condition', $js,
2777: {'no_nav_bar' => 1, }));
2778: } elsif ($caller eq 'coursegrp_portfolio') {
2779: $r->print(&Apache::loncommon::start_page($title, $js));
2780: } else {
2781: $r->print(&Apache::loncommon::start_page($title, $js,
2782: {'bread_crumbs' => $brcrum}));
2783: if (!&Apache::lonnet::usertools_access($uname,$udom,'portfolio')) {
2784: $r->print('<h2>'.&mt('No user portfolio available') .'</h2>'.
2785: &mt('This is a result of one of the following:').'<ul>'.
2786: '<li>'.&mt('The administrator of this domain has disabled portfolio functionality for this specific user.').'</li>'.
2787: '<li>'.&mt('The domain has been configured to disable, by default, portfolio functionality for all users in the domain.').'</li>'.
2788: '</ul>');
2789: $r->print(&Apache::loncommon::end_page());
2790: return OK;
2791: }
2792: }
2793: $r->rflush();
2794: # Check if access to portfolio is blocked by one or more blocking events in courses.
2795: my $clientip = &Apache::lonnet::get_requestor_ip($r);
2796: my ($blocked,$blocktext) =
2797: &Apache::loncommon::blocking_status('port',$clientip,$uname,$udom);
2798: if ($blocked) {
2799: my $evade_block;
2800: # If portfolio display is in a window popped up from a "Select Portfolio Files"
2801: # link in a .task resource, check if access to the task included proctor validation
2802: # of check-in to a slot limited by IP.
2803: # If so, and the slot is between its open and close dates, override the block.
2804: if ($env{'request.course.id'} && $env{'form.symb'}) {
2805: (undef,undef,my $res) = &Apache::lonnet::decode_symb($env{'form.symb'});
2806: if ($res =~ /\.task$/i) {
2807: my %history =
2808: &Apache::lonnet::restore($env{'form.symb'},$env{'request.course.id'},
2809: $env{'user.domain'},$env{'user.name'});
2810: my $version = $history{'resource.0.version'};
2811: if ($history{'resource.'.$version.'.0.checkedin'}) {
2812: if ($history{'resource.'.$version.'.0.checkedin.slot'}) {
2813: my %slot = &Apache::lonnet::get_slot($history{'resource.'.$version.'.0.checkedin.slot'});
2814: if ($slot{'ip'}) {
2815: if (&Apache::loncommon::check_ip_acc($slot{'ip'})) {
2816: my $now = time;
2817: if (($slot{'slottime'} < $now) && ($slot{'endtime'} > $now)) {
2818: $evade_block = 1;
2819: }
2820: }
2821: }
2822: }
2823: }
2824: }
2825: }
2826: unless ($evade_block) {
2827: $r->print($blocktext);
2828: $r->print(&Apache::loncommon::end_page());
2829: return OK;
2830: }
2831: }
2832: if (($env{'form.currentpath'}) && ($env{'form.currentpath'} ne '/')) {
2833: my $clean_currentpath = '/'.&Apache::loncommon::clean_path($env{'form.currentpath'}).'/';
2834: unless ($env{'form.currentpath'} eq $clean_currentpath) {
2835: &invalid_parms($r,$url);
2836: $r->print(&Apache::loncommon::end_page());
2837: return OK;
2838: }
2839: }
2840: if ($env{'form.container'}) {
2841: unless (&valid_container($uname,$udom,$group)) {
2842: &invalid_parms($r,$url,$env{'form.currentpath'});
2843: $r->print(&Apache::loncommon::end_page());
2844: return OK;
2845: }
2846: }
2847: if (($env{'form.storeupl'}) & (!$env{'form.uploaddoc.filename'})){
2848: $r->print(
2849: '<p><span class="LC_warning">'
2850: .&mt('No file was selected to upload.')
2851: .'</span><br />'
2852: .&mt('To upload a file, click [_1]Browse...[_2] and select a file, then click [_1]Upload[_2].'
2853: ,'<strong>','</strong>')
2854: .'</p>'
2855: );
2856: }
2857: if ($env{'form.meta'}) {
2858: &open_form($r,$url);
2859: $r->print(&mt('Edit Metadata').'<br />');
2860: &close_form($r,$url);
2861: }
2862: if ($env{'form.uploaddoc.filename'}) {
2863: if ($can_upload) {
2864: &upload($r,$url,$group);
2865: } else {
2866: &missing_priv($r,$url,'upload');
2867: }
2868: } elsif ($env{'form.action'} eq 'process_overwrite') {
2869: if ($can_upload) {
2870: &overwrite($r,$url,$group);
2871: } else {
2872: &missing_priv($r,$url,'existingfile');
2873: }
2874: } elsif ($env{'form.action'} eq 'upload_embedded') {
2875: if ($can_upload) {
2876: my $disk_quota = &get_quota($group);
2877: my $getpropath = 1;
2878: my $current_disk_usage =
2879: &Apache::lonnet::diskusage($udom,$uname,$portfolio_root,$getpropath);
2880: my $container = &HTML::Entities::encode($env{'form.container'},'<>&"');
2881: my $state = &embedded_form_elems($container).
2882: '<input type="hidden" name="action" value="modify_orightml" />';
2883: my ($result,$flag) =
2884: &Apache::loncommon::upload_embedded('portfolio',$port_path,$uname,$udom,
2885: $group,$portfolio_root,$group,$disk_quota,$current_disk_usage,$state,$url);
2886: $r->print($result.&done('Return to directory',$url));
2887: } else {
2888: &missing_priv($r,$url,'upload');
2889: }
2890: } elsif ($env{'form.action'} eq 'modify_orightml') {
2891: if ($can_upload) {
2892: my $result =
2893: &Apache::loncommon::modify_html_refs('portfolio',$port_path,$uname,
2894: $udom,$portfolio_root);
2895: $r->print($result.
2896: &done('Return to directory',$url));
2897: } else {
2898: &missing_priv($r,$url,'upload');
2899: }
2900: } elsif ($env{'form.action'} eq 'delete' && $env{'form.confirmed'}) {
2901: if ($can_delete) {
2902: &delete_confirmed($r,$url,$group);
2903: } else {
2904: &missing_priv($r,$url,'delete');
2905: }
2906: } elsif ($env{'form.action'} eq 'delete') {
2907: if ($can_delete) {
2908: &delete($r,$url,$group);
2909: } else {
2910: &missing_priv($r,$url,'delete');
2911: }
2912: } elsif ($env{'form.action'} eq 'deletedir' && $env{'form.confirmed'}) {
2913: if ($can_delete) {
2914: &delete_dir_confirmed($r,$url,$group);
2915: } else {
2916: &missing_priv($r,$url,'delete');
2917: }
2918: } elsif ($env{'form.action'} eq 'deletedir') {
2919: if ($can_delete) {
2920: &delete_dir($r,$url);
2921: } else {
2922: &missing_priv($r,$url,'delete');
2923: }
2924: } elsif ($env{'form.action'} eq 'rename' && $env{'form.confirmed'}) {
2925: if ($can_modify) {
2926: &rename_confirmed($r,$url,$group);
2927: } else {
2928: &missing_priv($r,$url,'rename');
2929: }
2930: } elsif ($env{'form.rename'}) {
2931: $env{'form.selectfile'} = $env{'form.rename'};
2932: $env{'form.action'} = 'rename';
2933: if ($can_modify) {
2934: &rename($r,$url,$group);
2935: } else {
2936: &missing_priv($r,$url,'rename');
2937: }
2938: } elsif ($env{'form.access'}) {
2939: $env{'form.selectfile'} = $env{'form.access'};
2940: if (!defined($env{'form.action'})) {
2941: $env{'form.action'} = 'chgaccess';
2942: }
2943: if (($can_viewacl) || ($can_setacl)) {
2944: &display_access($r,$url,$group,$can_setacl,$can_viewacl,$port_path,$env{'form.action'});
2945: } else {
2946: &missing_priv($r,$url,'viewacl');
2947: }
2948: } elsif (($env{'form.action'} eq 'chgaccess') ||
2949: ($env{'form.action'} eq 'chgconditions')) {
2950: if ($can_setacl) {
2951: &update_access($r,$url,$group,$port_path);
2952: } else {
2953: &missing_priv($r,$url,'setacl');
2954: }
2955: } elsif ($env{'form.action'} eq 'rolepicker') {
2956: if ($can_setacl) {
2957: &role_options_window($r);
2958: } else {
2959: &missing_priv($r,$url,'setacl');
2960: }
2961: } elsif ($env{'form.createdir'}) {
2962: if ($can_upload) {
2963: &createdir($r,$url,$group);
2964: } else {
2965: &missing_priv($r,$url,'upload');
2966: }
2967: } elsif ($env{'form.lockinfo'}) {
2968: &lock_info($r,$url,$group);
2969: } else {
2970: if ($env{'form.action'} eq 'cancel_overwrite') {
2971: if ($can_upload) {
2972: my $formname = 'existingfile';
2973: my $fname = &Apache::lonnet::clean_filename($env{'form.filename'});
2974: $env{'form.'.$formname.'.filename'} = $fname;
2975: my $subdir = $port_path.$env{'form.currentpath'};
2976: $subdir =~ s{(/)$}{};
2977: &Apache::lonnet::userfileupload($formname,'canceloverwrite',$subdir);
2978: }
2979: }
2980: my $current_path='/';
2981: if ($env{'form.currentpath'}) {
2982: $current_path = $env{'form.currentpath'};
2983: }
2984: if ($caller eq 'coursegrp_portfolio') {
2985: &Apache::lonhtmlcommon::clear_breadcrumbs();
2986: $r->print(&coursegrp_portfolio_header($udom,$uname,$grp_desc));
2987: }
2988: my ($dirlistref,$listerror) =
2989: &get_dir_list($portfolio_root,$current_path,$group);
2990: if ($listerror eq 'no_such_dir'){
2991: # two main reasons for this:
2992: # 1) never been here, so directory structure not created
2993: # 2) back-button navigation after deleting a directory
2994: if ($current_path eq '/'){
2995: &Apache::lonnet::mkdiruserfile($uname,$udom,
2996: &get_port_path());
2997: } else {
2998: # some directory that snuck in get rid of the directory
2999: # from the recent pulldown, just in case
3000: &Apache::lonhtmlcommon::remove_recent('portfolio',
3001: [$current_path]);
3002: $current_path = '/'; # force it back to the root
3003: }
3004: # now grab the directory list again, for the first time
3005: ($dirlistref,$listerror) =
3006: &get_dir_list($portfolio_root,$current_path,$group);
3007: }
3008: # need to know if directory is empty so it can be removed if desired
3009: my $is_empty;
3010: if ($listerror eq 'empty') {
3011: $is_empty = 1;
3012: } elsif (ref($dirlistref) eq 'ARRAY') {
3013: if ((scalar(@{$dirlistref}) == 2) && ($dirlistref->[0] =~ /^\.+\&/)
3014: && ($dirlistref->[1] =~ /^\.+\&/)) {
3015: $is_empty = 1;
3016: }
3017: }
3018: &display_common($r,$url,$current_path,$is_empty,$dirlistref,
3019: $can_upload,$group);
3020: &display_directory($r,$url,$current_path,$is_empty,$dirlistref,$group,
3021: $can_upload,$can_modify,$can_delete,$can_setacl,
3022: $can_viewacl);
3023: }
3024: $r->print(&Apache::loncommon::end_page());
3025: return OK;
3026: }
3027:
3028: 1;
3029: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>