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