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