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