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