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