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