Annotation of loncom/interface/portfolio.pm, revision 1.164
1.125 albertel 1: # The LearningOnline Network
2: # portfolio browser
3: #
1.164 ! raeburn 4: # $Id: portfolio.pm,v 1.163 2006/09/19 14:02:42 raeburn Exp $
1.125 albertel 5: #
1.3 banghart 6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28:
1.1 banghart 29: package Apache::portfolio;
30: use strict;
31: use Apache::Constants qw(:common :http);
1.2 banghart 32: use Apache::loncommon;
1.1 banghart 33: use Apache::lonnet;
1.2 banghart 34: use Apache::lontexconvert;
35: use Apache::lonfeedback;
36: use Apache::lonlocal;
1.82 albertel 37: use Apache::lonnet;
1.99 raeburn 38: use Apache::longroup;
1.132 raeburn 39: use Apache::lonhtmlcommon;
1.113 albertel 40: use HTML::Entities;
1.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.164 ! raeburn 553: $r->print('<span class="LC_error"> An error occured ('.$result.
! 554: ') while trying to delete '.
! 555: &display_file(undef, $delete_file).'</span><br />');
! 556: } else {
! 557: $r->print(&mt('File: [_1] deleted.',
! 558: &display_file(undef,$delete_file)));
! 559: my $file_name = $env{'form.currentpath'}.$delete_file;
! 560: $file_name = &prepend_group($file_name);
! 561: my %access_controls =
! 562: &Apache::lonnet::get_access_controls($current_permissions,
! 563: $group,$file_name);
! 564: if (keys(%access_controls) > 0) {
! 565: my %changes;
! 566: foreach my $key (%{$access_controls{$file_name}}) {
! 567: $changes{'delete'}{$key} = 1;
! 568: }
! 569: if (keys(%changes) > 0) {
! 570: my ($outcome,$deloutcome,$new_values,$translation) =
! 571: &Apache::lonnet::modify_access_controls($file_name,\%changes,
! 572: $udom,$uname);
! 573: if ($outcome ne 'ok') {
! 574: $r->print(&mt('<br />'."An error occured ($outcome) while ".
! 575: "trying to delete access controls for the file.").
! 576: '</span><br />');
! 577: } else {
! 578: if ($deloutcome eq 'ok') {
! 579: $r->print(&mt('<br />Access controls also deleted for the file.'));
! 580: } else {
! 581: $r->print('<span class="LC_error">'.
! 582: &mt('<br />'."An error occured ($deloutcome) while ".
! 583: "trying to delete access controls for the file.").
! 584: '</span><br />');
! 585: }
! 586: }
! 587: }
! 588: }
1.65 banghart 589: }
1.24 albertel 590: }
1.137 albertel 591: $r->print(&done(undef,$url));
1.24 albertel 592: }
593:
1.30 banghart 594: sub delete_dir {
1.137 albertel 595: my ($r,$url)=@_;
1.94 raeburn 596: &open_form($r,$url);
1.30 banghart 597: $r->print('<p>'.&mt('Delete').' '.&display_file().'?</p>');
1.137 albertel 598: &close_form($r,$url);
1.30 banghart 599: }
600:
601: sub delete_dir_confirmed {
1.138 albertel 602: my ($r,$url)=@_;
1.82 albertel 603: my $directory_name = $env{'form.currentpath'};
1.81 albertel 604: $directory_name =~ s|/$||; # remove any trailing slash
1.138 albertel 605: my ($uname,$udom) = &get_name_dom();
606: my $namespace = &get_namespace();
607: my $port_path = &get_port_path();
1.94 raeburn 608: my $result=&Apache::lonnet::removeuserfile($uname,$udom,$port_path.
1.30 banghart 609: $directory_name);
1.32 banghart 610:
1.30 banghart 611: if ($result ne 'ok') {
1.116 albertel 612: $r->print('<span class="LC_error"> An error occured (dir) ('.$result.
613: ') while trying to delete '.$directory_name.'</span><br />');
1.32 banghart 614: } else {
1.41 banghart 615: # now remove from recent
616: # $r->print('<br /> removing '.$directory_name.'<br /');
1.94 raeburn 617: &Apache::lonhtmlcommon::remove_recent($namespace,[$directory_name.'/']);
1.32 banghart 618: my @dirs = split m!/!, $directory_name;
619:
620: # $directory_name =~ m/^(\/*\/)(\/*.)$/;
621: $directory_name='/';
622: for (my $i=1; $i < (@dirs - 1); $i ++){
623: $directory_name .= $dirs[$i].'/';
624: }
1.82 albertel 625: $env{'form.currentpath'} = $directory_name;
1.30 banghart 626: }
1.137 albertel 627: $r->print(&done(undef,$url));
1.30 banghart 628: }
629:
1.24 albertel 630: sub rename {
1.138 albertel 631: my ($r,$url)=@_;
1.82 albertel 632: my $file_name = $env{'form.currentpath'}.$env{'form.rename'};
1.138 albertel 633: my ($uname,$udom) = &get_name_dom();
634: $file_name = &prepend_group($file_name);
1.94 raeburn 635: if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
1.55 banghart 636: $r->print ("The file is locked and cannot be renamed.<br />");
1.137 albertel 637: $r->print(&done(undef,$url));
1.55 banghart 638: } else {
1.94 raeburn 639: &open_form($r,$url);
1.55 banghart 640: $r->print('<p>'.&mt('Rename').' '.&display_file().' to
641: <input name="filenewname" type="input" size="50" />?</p>');
1.137 albertel 642: &close_form($r,$url);
1.55 banghart 643: }
1.24 albertel 644: }
645:
646: sub rename_confirmed {
1.164 ! raeburn 647: my ($r,$url,$group)=@_;
1.82 albertel 648: my $filenewname=&Apache::lonnet::clean_filename($env{'form.filenewname'});
1.138 albertel 649: my ($uname,$udom) = &get_name_dom();
650: my $port_path = &get_port_path();
1.27 albertel 651: if ($filenewname eq '') {
1.116 albertel 652: $r->print('<span class="LC_error">'.
1.27 albertel 653: &mt("Error: no valid filename was provided to rename to.").
1.116 albertel 654: '</span><br />');
1.137 albertel 655: $r->print(&done(undef,$url));
1.27 albertel 656: return;
657: }
1.164 ! raeburn 658: my $chg_access;
1.27 albertel 659: my $result=
1.94 raeburn 660: &Apache::lonnet::renameuserfile($uname,$udom,
661: $port_path.$env{'form.currentpath'}.$env{'form.selectfile'},
662: $port_path.$env{'form.currentpath'}.$filenewname);
1.164 ! raeburn 663: if ($result eq 'ok') {
! 664: $chg_access = &access_for_renamed($filenewname,$group,$udom,$uname);
! 665: } else {
1.116 albertel 666: $r->print('<span class="LC_error">'.
1.164 ! raeburn 667: &mt('An error occured ([_1]) while trying to rename [_2]'
1.116 albertel 668: .' to [_3]',$result,&display_file(),
669: &display_file('',$filenewname)).'</span><br />');
1.164 ! raeburn 670: return;
1.27 albertel 671: }
1.82 albertel 672: if ($filenewname ne $env{'form.filenewname'}) {
1.116 albertel 673: $r->print(&mt("The new file name was changed from:<br />[_1] to [_2]",
674: '<strong>'.&display_file('',$env{'form.filenewname'}).'</strong>',
675: '<strong>'.&display_file('',$filenewname).'</strong>'));
1.66 banghart 676: }
1.164 ! raeburn 677: $r->print($chg_access);
1.137 albertel 678: $r->print(&done(undef,$url));
1.27 albertel 679: }
1.102 raeburn 680:
1.164 ! raeburn 681: sub access_for_renamed {
! 682: my ($filenewname,$group,$udom,$uname) = @_;
! 683: my $oldfile = $env{'form.currentpath'}.$env{'form.selectfile'};
! 684: $oldfile = &prepend_group($oldfile);
! 685: my $newfile = $env{'form.currentpath'}.$filenewname;
! 686: $newfile = &prepend_group($newfile);
! 687: my $current_permissions =
! 688: &Apache::lonnet::get_portfile_permissions($udom,$uname);
! 689: my %access_controls =
! 690: &Apache::lonnet::get_access_controls($current_permissions,
! 691: $group,$oldfile);
! 692: my $chg_text;
! 693: if (keys(%access_controls) > 0) {
! 694: my %change_old;
! 695: my %change_new;
! 696: foreach my $key (%{$access_controls{$oldfile}}) {
! 697: $change_old{'delete'}{$key} = 1;
! 698: $change_new{'activate'}{$key} = $access_controls{$oldfile}{$key};
! 699: }
! 700: my ($outcome,$deloutcome,$new_values,$translation) =
! 701: &Apache::lonnet::modify_access_controls($oldfile,\%change_old,
! 702: $udom,$uname);
! 703: if ($outcome ne 'ok') {
! 704: $chg_text = &mt('<br /><br />'."An error occured ($outcome) while ".
! 705: "trying to delete access control records for the old name.").
! 706: '</span><br />';
! 707: } else {
! 708: if ($deloutcome ne 'ok') {
! 709: $chg_text = '<br /><br /><span class="LC_error">'.
! 710: &mt('<br />'."An error occured ($deloutcome) while ".
! 711: "trying to delete access control records for the old name.").
! 712: '</span><br />';
! 713: }
! 714: }
! 715: ($outcome,$deloutcome,$new_values,$translation) =
! 716: &Apache::lonnet::modify_access_controls($newfile,\%change_new,
! 717: $udom,$uname);
! 718: if ($outcome ne 'ok') {
! 719: $chg_text .= &mt('<br /><br />'."An error occured ($outcome) while ".
! 720: "trying to update access control records for the new name.").
! 721: '</span><br />';
! 722: }
! 723: if ($chg_text eq '') {
! 724: $chg_text = '<br /><br />'.&mt('Access controls updated to reflect the name change.');
! 725: }
! 726: }
! 727: return $chg_text;
! 728: }
! 729:
1.104 raeburn 730: sub display_access {
1.137 albertel 731: my ($r,$url,$group,$can_setacl,$port_path) = @_;
1.138 albertel 732: my ($uname,$udom) = &get_name_dom();
1.104 raeburn 733: my $file_name = $env{'form.currentpath'}.$env{'form.access'};
1.138 albertel 734: $file_name = &prepend_group($file_name);
1.104 raeburn 735: my $current_permissions = &Apache::lonnet::get_portfile_permissions($udom,
736: $uname);
737: my %access_controls = &Apache::lonnet::get_access_controls($current_permissions,$group,$file_name);
1.120 raeburn 738: my $aclcount = keys(%access_controls);
1.142 raeburn 739: my $header = '<h3>'.&mt('Allowing others to retrieve file: [_1]',$port_path.$env{'form.currentpath'}.$env{'form.access'}).'</h3>';
1.158 albertel 740: 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 741: $info .= '<br /><ul><li>'.&mt('Public files are available to anyone without the need for login.');
1.155 banghart 742: $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 743: $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 />';
744: $info .= &mt('The conditions can include affiliation with a particular course or group, or a user account in a specific domain.').'<br />';
745: $info .= &mt('Alternatively access can be granted to people with specific LON-CAPA usernames and domains.').'</li></ul>';
1.142 raeburn 746: if ($group eq '') {
1.160 raeburn 747: $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 748: }
749:
1.120 raeburn 750: if ($can_setacl) {
751: &open_form($r,$url);
752: $r->print($header.$info);
753: &access_setting_table($r,$access_controls{$file_name});
754: my $button_text = {
1.108 raeburn 755: 'continue' => &mt('Proceed'),
756: 'cancel' => &mt('Back to directory listing'),
757: };
1.137 albertel 758: &close_form($r,$url,$button_text);
1.120 raeburn 759: } else {
760: $r->print($header);
761: if ($aclcount) {
762: $r->print($info);
763: }
1.137 albertel 764: &view_access_settings($r,$url,$access_controls{$file_name},$aclcount);
1.120 raeburn 765: }
766: }
767:
768: sub view_access_settings {
1.137 albertel 769: my ($r,$url,$access_controls,$aclcount) = @_;
1.120 raeburn 770: my ($showstart,$showend);
771: my %todisplay;
772: foreach my $key (sort(keys(%{$access_controls}))) {
773: my ($num,$scope,$end,$start) = &unpack_acc_key($key);
774: $todisplay{$scope}{$key} = $$access_controls{$key};
775: }
776: if ($aclcount) {
777: $r->print(&mt('<h4>Current access controls defined for this file:</h4>'));
778: $r->print(&Apache::loncommon::start_data_table());
779: $r->print(&Apache::loncommon::start_data_table_header_row());
780: $r->print('<th>'.&mt('Access control').'</th><th>'.&mt('Dates available').
781: '</th><th>'.&mt('Additional information').'</th>');
782: $r->print(&Apache::loncommon::end_data_table_header_row());
783: my $count = 1;
784: my $chg = 'none';
785: &build_access_summary($r,$count,$chg,%todisplay);
786: $r->print(&Apache::loncommon::end_data_table());
787: } else {
788: $r->print(&mt('No access control settings currently exist for this file.<br />' ));
789: }
1.153 banghart 790: my %anchor_fields = (
791: 'currentpath' => $env{'form.currentpath'}
792: );
793: $r->print('<br />'.&make_anchor($url, \%anchor_fields, &mt('Return to directory listing')));
1.120 raeburn 794: return;
1.104 raeburn 795: }
796:
1.120 raeburn 797: sub build_access_summary {
798: my ($r,$count,$chg,%todisplay) = @_;
799: my ($showstart,$showend);
800: my %scope_desc = (
801: public => 'Public',
802: guest => 'Passphrase-protected',
803: domains => 'Conditional: domain-based',
804: users => 'Conditional: user-based',
805: course => 'Conditional: course-based',
806: group => 'Conditional: group-based',
807: );
808: my @allscopes = ('public','guest','domains','users','course','group');
809: foreach my $scope (@allscopes) {
810: if ((!(exists($todisplay{$scope}))) || (ref($todisplay{$scope}) ne 'HASH')) {
811: next;
812: }
813: foreach my $key (sort(keys(%{$todisplay{$scope}}))) {
814: if ($count) {
815: $r->print(&Apache::loncommon::start_data_table_row());
816: }
817: my ($num,$scope,$end,$start) = &unpack_acc_key($key);
818: my $content = $todisplay{$scope}{$key};
819: if ($chg eq 'delete') {
820: $showstart = &mt('Deleted');
821: $showend = $showstart;
822: } else {
823: $showstart = localtime($start);
824: if ($end == 0) {
825: $showend = &mt('No end date');
826: } else {
827: $showend = localtime($end);
828: }
829: }
830: $r->print('<td>'.&mt($scope_desc{$scope}));
831: if (($scope eq 'course') || ($scope eq 'group')) {
832: if ($chg ne 'delete') {
833: my $cid = $content->{'domain'}.'_'.$content->{'number'};
834: my %course_description = &Apache::lonnet::coursedescription($cid);
835: $r->print('<br />('.$course_description{'description'}.')');
836: }
837: }
838: $r->print('</td><td>'.&mt('Start: ').$showstart.
839: '<br />'.&mt('End: ').$showend.'</td><td>');
840: if ($chg ne 'delete') {
841: if ($scope eq 'guest') {
842: $r->print(&mt('Passphrase').': '.$content->{'password'});
843: } elsif ($scope eq 'course' || $scope eq 'group') {
844: $r->print('<table><tr>');
845: $r->print('<th>'.&mt('Roles').'</th><th>'.
846: &mt('Access').'</th><th>'.
847: &mt('Sections').'</th>');
848: if ($scope eq 'course') {
849: $r->print('<th>'.&mt('Groups').'</th>');
850: } else {
851: $r->print('<th>'.&mt('Teams').'</th>');
852: }
853: $r->print('</tr>');
854: foreach my $id (sort(keys(%{$content->{'roles'}}))) {
855: $r->print('<tr>');
856: foreach my $item ('role','access','section','group') {
857: $r->print('<td>');
858: if ($item eq 'role') {
859: my $ucscope = $scope;
860: $ucscope =~ s/^(\w)/uc($1)/e;
861: my $role_output;
862: foreach my $role (@{$content->{'roles'}{$id}{$item}}) {
863: if ($role eq 'all') {
864: $role_output .= $role.',';
865: } elsif ($role =~ /^cr/) {
866: $role_output .= (split('/',$role))[3].',';
867: } else {
868: $role_output .= &Apache::lonnet::plaintext($role,$ucscope).',';
869: }
870: }
871: $role_output =~ s/,$//;
872: $r->print($role_output);
873: } else {
874: $r->print(join(',',@{$content->{'roles'}{$id}{$item}}));
875: }
1.121 albertel 876: $r->print('</tr>');
1.120 raeburn 877: }
1.121 albertel 878: $r->print("</table>");
1.120 raeburn 879: }
1.121 albertel 880: $r->print("</tr></table>");
1.120 raeburn 881: } elsif ($scope eq 'domains') {
882: $r->print(&mt('Domains: ').join(',',@{$content->{'dom'}}));
883: } elsif ($scope eq 'users') {
884: my $curr_user_list = &sort_users($content->{'users'});
885: $r->print(&mt('Users: ').$curr_user_list);
886: } else {
887: $r->print(' ');
888: }
889: } else {
890: $r->print(' ');
891: }
892: $r->print('</td>');
893: $r->print(&Apache::loncommon::end_data_table_row());
894: $count ++;
895: }
896: }
897: }
898:
899:
1.104 raeburn 900: sub update_access {
1.137 albertel 901: my ($r,$url,$group,$port_path) = @_;
1.104 raeburn 902: my $totalprocessed = 0;
903: my %processing;
904: my %title = (
1.108 raeburn 905: 'activate' => 'New control(s) added',
906: 'delete' => 'Existing control(s) deleted',
907: 'update' => 'Existing control(s) modified',
1.104 raeburn 908: );
1.108 raeburn 909: my $changes;
1.104 raeburn 910: foreach my $chg (sort(keys(%title))) {
911: @{$processing{$chg}} = &Apache::loncommon::get_env_multiple('form.'.$chg);
912: $totalprocessed += @{$processing{$chg}};
913: foreach my $num (@{$processing{$chg}}) {
914: my $scope = $env{'form.scope_'.$num};
915: my ($start,$end) = &get_dates_from_form($num);
916: my $newkey = $num.':'.$scope.'_'.$end.'_'.$start;
917: if ($chg eq 'delete') {
918: $$changes{$chg}{$newkey} = 1;
919: } else {
920: $$changes{$chg}{$newkey} =
1.108 raeburn 921: &build_access_record($num,$scope,$start,$end,$chg);
1.104 raeburn 922: }
923: }
924: }
925: my $file_name = $env{'form.currentpath'}.$env{'form.selectfile'};
1.142 raeburn 926: $r->print('<h3>'.&mt('Allowing others to retrieve file: [_1]',
1.133 raeburn 927: $port_path.$file_name).'</h3>'."\n");
1.138 albertel 928: $file_name = &prepend_group($file_name);
929: my ($uname,$udom) = &get_name_dom();
1.104 raeburn 930: my ($errors,$outcome,$deloutcome,$new_values,$translation);
931: if ($totalprocessed) {
932: ($outcome,$deloutcome,$new_values,$translation) =
1.108 raeburn 933: &Apache::lonnet::modify_access_controls($file_name,$changes,$udom,
934: $uname);
1.104 raeburn 935: }
1.108 raeburn 936: my $current_permissions = &Apache::lonnet::get_portfile_permissions($udom,
937: $uname);
1.109 albertel 938: my %access_controls =
939: &Apache::lonnet::get_access_controls($current_permissions,
940: $group,$file_name);
1.104 raeburn 941: if ($totalprocessed) {
942: if ($outcome eq 'ok') {
943: my $updated_controls = $access_controls{$file_name};
944: my ($showstart,$showend);
945: $r->print(&Apache::loncommon::start_data_table());
1.110 albertel 946: $r->print(&Apache::loncommon::start_data_table_header_row());
1.108 raeburn 947: $r->print('<th>'.&mt('Type of change').'</th><th>'.
948: &mt('Access control').'</th><th>'.&mt('Dates available').
949: '</th><th>'.&mt('Additional information').'</th>');
1.110 albertel 950: $r->print(&Apache::loncommon::end_data_table_header_row());
1.104 raeburn 951: foreach my $chg (sort(keys(%processing))) {
952: if (@{$processing{$chg}} > 0) {
953: if ($chg eq 'delete') {
954: if (!($deloutcome eq 'ok')) {
1.116 albertel 955: $errors .='<span class="LC_error">'.
956: &mt('A problem occurred deleting access controls: [_1]',$deloutcome).
957: '</span>';
1.104 raeburn 958: next;
959: }
960: }
961: my $numchgs = @{$processing{$chg}};
962: $r->print(&Apache::loncommon::start_data_table_row());
1.108 raeburn 963: $r->print('<td rowspan="'.$numchgs.'">'.&mt($title{$chg}).
964: '.</td>');
1.104 raeburn 965: my $count = 0;
1.120 raeburn 966: my %todisplay;
1.104 raeburn 967: foreach my $key (sort(keys(%{$$changes{$chg}}))) {
1.120 raeburn 968: my ($num,$scope,$end,$start) = &unpack_acc_key($key);
1.104 raeburn 969: my $newkey = $key;
970: if ($chg eq 'activate') {
971: $newkey =~ s/^(\d+)/$$translation{$1}/;
972: }
1.120 raeburn 973: $todisplay{$scope}{$newkey} = $$updated_controls{$newkey};
1.104 raeburn 974: }
1.120 raeburn 975: &build_access_summary($r,$count,$chg,%todisplay);
1.104 raeburn 976: }
977: }
978: $r->print(&Apache::loncommon::end_data_table());
979: } else {
980: if ((@{$processing{'activate'}} > 0) || (@{$processing{'update'}} > 0)) {
1.116 albertel 981: $errors .= '<span class="LC_error">'.
982: &mt('A problem occurred storing access control settings: [_1]',$outcome).
983: '</span>';
1.104 raeburn 984: }
985: }
986: if ($errors) {
987: $r->print($errors);
988: }
989: }
1.108 raeburn 990: my $allnew = 0;
991: my $totalnew = 0;
992: my $status = 'new';
993: my ($firstitem,$lastitem);
994: foreach my $newitem ('course','group','domains','users') {
995: $allnew += $env{'form.new'.$newitem};
996: }
997: if ($allnew > 0) {
998: my $now = time;
999: my $then = $now + (60*60*24*180); # six months approx.
1.138 albertel 1000: &open_form($r,$url);
1.108 raeburn 1001: foreach my $newitem ('course','group','domains','users') {
1002: if ($env{'form.new'.$newitem} > 0) {
1003: $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 />');
1004: $firstitem = $totalnew;
1005: $lastitem = $totalnew + $env{'form.new'.$newitem};
1006: $totalnew = $lastitem;
1007: my @numbers;
1008: for (my $i=$firstitem; $i<$lastitem; $i++) {
1009: push (@numbers,$i);
1010: }
1011: &display_access_row($r,$status,$newitem,\@numbers,
1012: $access_controls{$file_name},$now,$then);
1013: }
1014: }
1.137 albertel 1015: &close_form($r,$url);
1.108 raeburn 1016: } else {
1.153 banghart 1017: my %anchor_fields = (
1018: 'currentpath' => $env{'form.currentpath'},
1019: 'access' => $env{'form.selectfile'}
1020: );
1021: $r->print('<br />'.&make_anchor($url, \%anchor_fields, &mt('Display all access settings for this file')));
1022: delete $anchor_fields{'access'};
1023: $r->print(' '.&make_anchor($url,\%anchor_fields,&mt('Return to directory listing')));
1.108 raeburn 1024: }
1.104 raeburn 1025: return;
1026: }
1027:
1028: sub build_access_record {
1.108 raeburn 1029: my ($num,$scope,$start,$end,$chg) = @_;
1.109 albertel 1030: my $record = {
1031: type => $scope,
1032: time => {
1033: start => $start,
1034: end => $end
1035: },
1036: };
1037:
1038: if ($scope eq 'guest') {
1039: $record->{'password'} = $env{'form.password'};
1.108 raeburn 1040: } elsif (($scope eq 'course') || ($scope eq 'group')) {
1.109 albertel 1041: $record->{'domain'} = $env{'form.crsdom_'.$num};
1042: $record->{'number'} = $env{'form.crsnum_'.$num};
1.108 raeburn 1043: my @role_ids;
1.109 albertel 1044: my @delete_role_ids =
1045: &Apache::loncommon::get_env_multiple('form.delete_role_'.$num);
1046: my @preserves =
1047: &Apache::loncommon::get_env_multiple('form.preserve_role_'.$num);
1048: if (@delete_role_ids) {
1049: foreach my $id (@preserves) {
1050: if (grep {$_ = $id} (@delete_role_ids)) {
1051: next;
1052: }
1053: push(@role_ids,$id);
1054: }
1055: } else {
1056: push(@role_ids,@preserves);
1057: }
1058:
1059: my $next_id = $env{'form.add_role_'.$num};
1060: if ($next_id) {
1061: push(@role_ids,$next_id);
1062: }
1063:
1.108 raeburn 1064: foreach my $id (@role_ids) {
1065: my (@roles,@accesses,@sections,@groups);
1066: if (($id == $next_id) && ($chg eq 'update')) {
1.109 albertel 1067: @roles = split(/,/,$env{'form.role_'.$num.'_'.$next_id});
1.108 raeburn 1068: @accesses = split(/,/,$env{'form.access_'.$num.'_'.$next_id});
1069: @sections = split(/,/,$env{'form.section_'.$num.'_'.$next_id});
1.109 albertel 1070: @groups = split(/,/,$env{'form.group_'.$num.'_'.$next_id});
1.108 raeburn 1071: } else {
1072: @roles = &Apache::loncommon::get_env_multiple('form.role_'.$num.'_'.$id);
1073: @accesses = &Apache::loncommon::get_env_multiple('form.access_'.$num.'_'.$id);
1074: @sections = &Apache::loncommon::get_env_multiple('form.section_'.$num.'_'.$id);
1075: @groups = &Apache::loncommon::get_env_multiple('form.group_'.$num.'_'.$id);
1076: }
1.109 albertel 1077: $record->{'roles'}{$id}{'role'} = \@roles;
1078: $record->{'roles'}{$id}{'access'} = \@accesses;
1079: $record->{'roles'}{$id}{'section'} = \@sections;
1080: $record->{'roles'}{$id}{'group'} = \@groups;
1.108 raeburn 1081: }
1082: } elsif ($scope eq 'domains') {
1083: my @doms = &Apache::loncommon::get_env_multiple('form.dom_'.$num);
1.109 albertel 1084: $record->{'dom'} = \@doms;
1.108 raeburn 1085: } elsif ($scope eq 'users') {
1086: my $userlist = $env{'form.users_'.$num};
1.109 albertel 1087: $userlist =~ s/\s+//sg;
1088: my %userhash = map { ($_,1) } (split(/,/,$userlist));
1089: foreach my $user (keys(%userhash)) {
1.108 raeburn 1090: my ($uname,$udom) = split(/:/,$user);
1.109 albertel 1091: push(@{$record->{'users'}}, {
1092: 'uname' => $uname,
1093: 'udom' => $udom
1094: });
1095: }
1.108 raeburn 1096: }
1.104 raeburn 1097: return $record;
1098: }
1099:
1100: sub get_dates_from_form {
1101: my ($id) = @_;
1102: my $startdate;
1103: my $enddate;
1104: $startdate = &Apache::lonhtmlcommon::get_date_from_form('startdate_'.$id);
1105: $enddate = &Apache::lonhtmlcommon::get_date_from_form('enddate_'.$id);
1106: if ( exists ($env{'form.noend_'.$id}) ) {
1107: $enddate = 0;
1108: }
1109: return ($startdate,$enddate);
1110: }
1111:
1.108 raeburn 1112: sub sort_users {
1.109 albertel 1113: my ($users) = @_;
1114: my @curr_users = map {
1115: $_->{'uname'}.':'.$_->{'udom'}
1116: } (@{$users});
1117: my $curr_user_list = join(",\n",sort(@curr_users));
1.108 raeburn 1118: return $curr_user_list;
1119: }
1120:
1.104 raeburn 1121: sub access_setting_table {
1122: my ($r,$access_controls) = @_;
1123: my ($public,$publictext);
1.108 raeburn 1124: $publictext = &mt('Off');
1.104 raeburn 1125: my ($guest,$guesttext);
1.108 raeburn 1126: $guesttext = &mt('Off');
1.104 raeburn 1127: my @courses = ();
1128: my @groups = ();
1129: my @domains = ();
1130: my @users = ();
1131: my $now = time;
1132: my $then = $now + (60*60*24*180); # six months approx.
1.108 raeburn 1133: my ($num,$scope,$publicnum,$guestnum);
1134: my (%acl_count,%end,%start);
1.104 raeburn 1135: foreach my $key (sort(keys(%{$access_controls}))) {
1.108 raeburn 1136: ($num,$scope,$end{$key},$start{$key}) = &unpack_acc_key($key);
1.104 raeburn 1137: if ($scope eq 'public') {
1138: $public = $key;
1.108 raeburn 1139: $publicnum = $num;
1140: $publictext = &acl_status($start{$key},$end{$key},$now);
1141: } elsif ($scope eq 'guest') {
1142: $guest=$key;
1143: $guestnum = $num;
1144: $guesttext = &acl_status($start{$key},$end{$key},$now);
1145: } elsif ($scope eq 'course') {
1146: push(@courses,$key);
1147: } elsif ($scope eq 'group') {
1148: push(@groups,$key);
1149: } elsif ($scope eq 'domains') {
1150: push(@domains,$key);
1151: } elsif ($scope eq 'users') {
1152: push(@users,$key);
1.104 raeburn 1153: }
1.108 raeburn 1154: $acl_count{$scope} ++;
1.104 raeburn 1155: }
1.108 raeburn 1156: $r->print('<table border="0"><tr><td valign="top">');
1157: $r->print('<h3>'.&mt('Public access:').' '.$publictext.'</h3>');
1.104 raeburn 1158: $r->print(&Apache::loncommon::start_data_table());
1.110 albertel 1159: $r->print(&Apache::loncommon::start_data_table_header_row());
1.108 raeburn 1160: $r->print('<th>'.&mt('Action').'</th><th>'.&mt('Dates available').'</th>');
1.110 albertel 1161: $r->print(&Apache::loncommon::end_data_table_header_row());
1.104 raeburn 1162: $r->print(&Apache::loncommon::start_data_table_row());
1.108 raeburn 1163: if ($public) {
1164: $r->print('<td>'.&actionbox('old',$publicnum,'public').'</td><td>'.
1165: &dateboxes($publicnum,$start{$public},$end{$public}).'</td>');
1166: } else {
1167: $r->print('<td>'.&actionbox('new','0','public').'</td><td>'.
1168: &dateboxes('0',$now,$then).'</td>');
1169: }
1170: $r->print(&Apache::loncommon::end_data_table_row());
1171: $r->print(&Apache::loncommon::end_data_table());
1172: $r->print('</td><td width="40"> </td><td valign="top">');
1.120 raeburn 1173: $r->print('<h3>'.&mt('Passphrase-protected access:').' '.$guesttext.'</h3>');
1.104 raeburn 1174: $r->print(&Apache::loncommon::start_data_table());
1.110 albertel 1175: $r->print(&Apache::loncommon::start_data_table_header_row());
1.108 raeburn 1176: $r->print('<th>'.&mt('Action').'</th><th>'.&mt('Dates available').
1.120 raeburn 1177: '</th><th>'. &mt('Passphrase').'</th>');
1.110 albertel 1178: $r->print(&Apache::loncommon::end_data_table_header_row());
1.108 raeburn 1179: $r->print(&Apache::loncommon::start_data_table_row());
1180: my $passwd;
1181: if ($guest) {
1.109 albertel 1182: $passwd = $$access_controls{$guest}{'password'};
1.108 raeburn 1183: $r->print('<td>'.&actionbox('old',$guestnum,'guest').'</td><td>'.
1184: &dateboxes($guestnum,$start{$guest},$end{$guest}).'</td>');
1185: } else {
1186: $r->print('<td>'.&actionbox('new','1','guest').'</td><td>'.
1187: &dateboxes('1',$now,$then).'</td>');
1.104 raeburn 1188: }
1.108 raeburn 1189: $r->print('<td><input type="text" size="15" name="password" value="'.
1190: $passwd.'" /></td>');
1.104 raeburn 1191: $r->print(&Apache::loncommon::end_data_table_row());
1192: $r->print(&Apache::loncommon::end_data_table());
1.158 albertel 1193: $r->print('</td></tr><tr><td colspan="3"> </td></tr><tr><td valign="top">');
1194: &access_element($r,'domains',\%acl_count,\@domains,$access_controls,$now,$then);
1195: $r->print('</td><td> </td><td valign="top">');
1196: &access_element($r,'users',\%acl_count,\@users,$access_controls,$now,$then);
1197: $r->print('</td></tr><tr><td colspan="3"></td></tr><tr>');
1198: if (@courses > 0 || @groups > 0) {
1199: $r->print('<td colspan="3" valign="top">');
1200: } else {
1201: $r->print('<td valign="top">');
1202: }
1203: &access_element($r,'course',\%acl_count,\@courses,$access_controls,$now,$then);
1204: $r->print('</td>');
1205: if (@courses > 0 || @groups > 0) {
1206: $r->print('</tr><tr><td colspan="3"> </td></tr><tr><td colspan="3" valign="top">');
1207: } else {
1208: $r->print('<td> </td><td valign="top">');
1209: }
1210: &access_element($r,'group',\%acl_count,\@groups,$access_controls,$now,$then);
1.108 raeburn 1211: $r->print('</td></tr></table>');
1212: }
1213:
1214: sub acl_status {
1215: my ($start,$end,$now) = @_;
1216: if ($start > $now) {
1217: return &mt('Inactive');
1218: }
1219: if ($end && $end<$now) {
1220: return &mt('Inactive');
1221: }
1222: return &mt('Active');
1223: }
1224:
1225: sub access_element {
1226: my ($r,$type,$acl_count,$items,$access_controls,$now,$then) = @_;
1227: my $title = $type;
1228: $title =~ s/s$//;
1229: $title =~ s/^(\w)/uc($1)/e;
1230: $r->print('<h3>'.&mt('[_1]-based conditional access: ',$title));
1231: if ($$acl_count{$type}) {
1232: $r->print($$acl_count{$type}.' ');
1233: if ($$acl_count{$type} > 1) {
1234: $r->print(&mt('conditions'));
1235: } else {
1236: $r->print(&mt('condition'));
1237: }
1238: } else {
1239: $r->print(&mt('Off'));
1240: }
1241: $r->print('</h3>');
1242: &display_access_row($r,'old',$type,$items,$access_controls,$now,$then);
1243: return;
1244: }
1245:
1246: sub display_access_row {
1247: my ($r,$status,$type,$items,$access_controls,$now,$then) = @_;
1248: if (@{$items} > 0) {
1249: my @all_doms;
1250: my $colspan = 3;
1251: my $uctype = $type;
1252: $uctype =~ s/^(\w)/uc($1)/e;
1253: $r->print(&Apache::loncommon::start_data_table());
1.110 albertel 1254: $r->print(&Apache::loncommon::start_data_table_header_row());
1255: $r->print('<th>'.&mt('Action?').'</th><th>'.&mt($uctype).'</th><th>'.
1.108 raeburn 1256: &mt('Dates available').'</th>');
1257: if (($type eq 'course') || ($type eq 'group')) {
1258: $r->print('<th>'.&mt('Allowed [_1] member affiliations',$type).
1259: '</th>');
1260: $colspan ++;
1261: } elsif ($type eq 'domains') {
1262: @all_doms = &Apache::loncommon::get_domains();
1263: }
1.110 albertel 1264: $r->print(&Apache::loncommon::end_data_table_header_row());
1.108 raeburn 1265: foreach my $key (@{$items}) {
1.118 albertel 1266: $r->print(&Apache::loncommon::start_data_table_row());
1.108 raeburn 1267: if (($type eq 'course') || ($type eq 'group')) {
1.118 albertel 1268: &course_row($r,$status,$type,$key,$access_controls,$now,$then);
1.108 raeburn 1269: } elsif ($type eq 'domains') {
1270: &domains_row($r,$status,$key,\@all_doms,$access_controls,$now,
1271: $then);
1272: } elsif ($type eq 'users') {
1273: &users_row($r,$status,$key,$access_controls,$now,$then);
1274: }
1.118 albertel 1275: $r->print(&Apache::loncommon::end_data_table_row());
1.108 raeburn 1276: }
1277: if ($status eq 'old') {
1.111 albertel 1278: $r->print(&Apache::loncommon::start_data_table_row());
1.108 raeburn 1279: $r->print('<td colspan="',$colspan.'">'.&additional_item($type).
1280: '</td>');
1.111 albertel 1281: $r->print(&Apache::loncommon::end_data_table_row());
1.108 raeburn 1282: }
1283: $r->print(&Apache::loncommon::end_data_table());
1284: } else {
1285: $r->print(&mt('No [_1]-based conditions defined.<br />',$type).
1286: &additional_item($type));
1287: }
1288: return;
1289: }
1290:
1.110 albertel 1291: sub course_js {
1292: return qq|
1.108 raeburn 1293: <script type="text/javascript">
1294: function setRoleOptions(caller,num,cdom,cnum,type) {
1295: addIndexnum = getCallerIndex(caller);
1296: updateIndexnum = getIndex('update',num);
1297: if (caller.checked) {
1298: document.portform.elements[updateIndexnum].checked = true;
1299: var url = '/adm/portfolio?action=rolepicker&setroles='+addIndexnum+'&cnum='+cnum+'&cdom='+cdom+'&type='+type;
1300: var title = 'Roles_Chooser';
1301: var options = 'scrollbars=1,resizable=1,menubar=0';
1302: options += ',width=700,height=600';
1303: rolebrowser = open(url,title,options,'1');
1304: rolebrowser.focus();
1305: } else {
1306: for (var j=0;j<5;j++) {
1307: document.portform.elements[addIndexnum+j].value = '';
1308: }
1309: }
1310: }
1311:
1312: function getCallerIndex(caller) {
1313: for (var i=0;i<document.portform.elements.length;i++) {
1314: if (document.portform.elements[i] == caller) {
1315: return i;
1316: }
1317: }
1318: return -1;
1319: }
1320:
1321: function getIndex(name,value) {
1322: for (var i=0;i<document.portform.elements.length;i++) {
1323: if (document.portform.elements[i].name == name && document.portform.elements[i].value == value) {
1324: return i;
1325: }
1326: }
1327: return -1;
1328: }
1329:
1330: </script>
1.110 albertel 1331: |;
1332: }
1333:
1334: sub course_row {
1.118 albertel 1335: my ($r,$status,$type,$item,$access_controls,$now,$then) = @_;
1.115 raeburn 1336: my $content;
1.110 albertel 1337: my $defdom = $env{'user.domain'};
1338: if ($status eq 'old') {
1.115 raeburn 1339: $content = $$access_controls{$item};
1340: $defdom = $content->{'domain'};
1.110 albertel 1341: }
1342: my $js = &Apache::loncommon::coursebrowser_javascript($defdom)
1343: .&course_js();
1.108 raeburn 1344: my $crsgrptext = 'Groups';
1345: if ($type eq 'group') {
1346: $crsgrptext = 'Teams';
1347: }
1.120 raeburn 1348: my $uctype = $type;
1349: $uctype =~ s/^(\w)/uc($1)/e;
1.108 raeburn 1350: my ($num,$scope,$end,$start) = &set_identifiers($status,$item,$now,$then,
1351: $type);
1.110 albertel 1352: $r->print('<td>'.$js.&actionbox($status,$num,$scope).'</td>');
1.108 raeburn 1353: if ($status eq 'old') {
1.115 raeburn 1354: my $cid = $content->{'domain'}.'_'.$content->{'number'};
1.108 raeburn 1355: my %course_description = &Apache::lonnet::coursedescription($cid);
1.115 raeburn 1356: $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 1357: } elsif ($status eq 'new') {
1358: $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>');
1359: }
1360: $r->print('<td>'.&dateboxes($num,$start,$end).'</td>');
1.118 albertel 1361: $r->print('<td><table><tr>');
1.108 raeburn 1362: $r->print('<th>'.&mt('Action').'</th><th>'.&mt('Roles').'</th><th>'.
1363: &mt('Access').'</th><th>'.&mt('Sections').'</th><th>'.
1364: &mt($crsgrptext).'</th></tr>');
1365: if ($status eq 'old') {
1366: my $max_id = 0;
1.115 raeburn 1367: foreach my $role_id (sort(keys(%{$content->{'roles'}}))) {
1.108 raeburn 1368: if ($role_id > $max_id) {
1369: $max_id = $role_id;
1370: }
1371: $max_id ++;
1.115 raeburn 1372: my $role_selects = &role_selectors($num,$role_id,$status,$type,$content,'display');
1.112 albertel 1373: $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 1374: }
1.120 raeburn 1375: $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 1376: } elsif ($status eq 'new') {
1377: my $role_id = 1;
1378: my $role_selects = &role_selectors($num,$role_id,$status,$type,undef,'display');
1379: $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);
1380: $r->print('</tr></table></td>');
1381: }
1382: return;
1383: }
1384:
1385: sub domains_row {
1386: my ($r,$status,$item,$all_doms,$access_controls,$now,$then) = @_;
1387: my ($num,$scope,$end,$start) = &set_identifiers($status,$item,$now,$then,
1388: 'domains');
1.112 albertel 1389: my $dom_select = '<select name="dom_'.$num.'" size="4" multiple="true">'.
1.108 raeburn 1390: ' <option value="">'.&mt('Please select').'</option>';
1391: if ($status eq 'old') {
1.109 albertel 1392: my $content = $$access_controls{$item};
1393: foreach my $dom (@{$all_doms}) {
1394: if ((@{$content->{'dom'}} > 0)
1395: && (grep(/^\Q$dom\E$/,@{$content->{'dom'}}))) {
1.108 raeburn 1396: $dom_select .= '<option value="'.$dom.'" selected>'.
1397: $dom.'</option>';
1398: } else {
1399: $dom_select .= '<option value="'.$dom.'">'.$dom.'</option>';
1400: }
1401: }
1402: } else {
1403: foreach my $dom (@{$all_doms}) {
1404: $dom_select .= '<option value="'.$dom.'">'.$dom.'</option>';
1405: }
1406: }
1.112 albertel 1407: $dom_select .= '</select>';
1.108 raeburn 1408: $r->print('<td>'.&actionbox($status,$num,$scope).'</td><td>'.$dom_select.
1409: '</td><td>'.&dateboxes($num,$start,$end).'</td>');
1410: }
1411:
1412: sub users_row {
1413: my ($r,$status,$item,$access_controls,$now,$then) = @_;
1414: my ($num,$scope,$end,$start) = &set_identifiers($status,$item,$now,$then,
1415: 'users');
1416: my $curr_user_list;
1417: if ($status eq 'old') {
1.109 albertel 1418: my $content = $$access_controls{$item};
1419: $curr_user_list = &sort_users($content->{'users'});
1.108 raeburn 1420: }
1421: $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>');
1422: }
1423:
1424: sub additional_item {
1425: my ($type) = @_;
1426: my $output = &mt('Add new [_1] condition(s)?',$type).' '.&mt('Number to add: ').'<input type="text" name="new'.$type.'" size="3" value="0" />';
1427: return $output;
1428: }
1429:
1430: sub actionbox {
1431: my ($status,$num,$scope) = @_;
1.112 albertel 1432: my $output = '<span style="white-space: nowrap"><label>';
1.108 raeburn 1433: if ($status eq 'new') {
1434: $output .= '<input type="checkbox" name="activate" value="'.$num.'" />'.
1435: &mt('Activate');
1436: } else {
1437: $output .= '<input type="checkbox" name="delete" value="'.$num.
1.112 albertel 1438: '" />'.&mt('Delete').'</label></span><br /><span style="white-space: nowrap">'.
1.108 raeburn 1439: '<label><input type="checkbox" name="update" value="'.
1440: $num.'" />'.&mt('Update');
1441: }
1.112 albertel 1442: $output .= '</label></span><input type="hidden" name="scope_'.$num. '" value="'.$scope.'" />';
1.108 raeburn 1443: return $output;
1444: }
1445:
1446: sub dateboxes {
1447: my ($num,$start,$end) = @_;
1448: my $noend;
1449: if ($end == 0) {
1450: $noend = 'checked="checked"';
1451: }
1452: my $startdate = &Apache::lonhtmlcommon::date_setter('portform',
1453: 'startdate_'.$num,$start,undef,undef,undef,1,undef,
1454: undef,undef,1);
1455: my $enddate = &Apache::lonhtmlcommon::date_setter('portform',
1456: 'enddate_'.$num,$end,undef,undef,undef,1,undef,
1.112 albertel 1457: undef,undef,1). ' <span style="white-space: nowrap"><label>'.
1.108 raeburn 1458: '<input type="checkbox" name="noend_'.
1459: $num.'" '.$noend.' />'.&mt('No end date').
1.112 albertel 1460: '</label></span>';
1.108 raeburn 1461:
1462: my $output = &mt('Start: ').$startdate.'<br />'.&mt('End: ').$enddate;
1463: return $output;
1464: }
1465:
1466: sub unpack_acc_key {
1467: my ($acc_key) = @_;
1468: my ($num,$scope,$end,$start) = ($acc_key =~ /^([^:]+):([a-z]+)_(\d*)_?(\d*)$/);
1469: return ($num,$scope,$end,$start);
1470: }
1471:
1472: sub set_identifiers {
1473: my ($status,$item,$now,$then,$scope) = @_;
1474: if ($status eq 'old') {
1475: return(&unpack_acc_key($item));
1476: } else {
1477: return($item,$scope,$then,$now);
1478: }
1479: }
1480:
1481: sub role_selectors {
1482: my ($num,$role_id,$status,$type,$content,$caller) = @_;
1483: my ($output,$cdom,$cnum,$longid);
1484: if ($caller eq 'display') {
1485: $longid = '_'.$num.'_'.$role_id;
1486: if ($status eq 'new') {
1487: foreach my $item ('role','access','section','group') {
1488: $output .= '<td><select name="'.$item.$longid.'">'.
1489: '<option value="">'.&mt('Pick [_1] first',$type).
1490: '</option></select></td>';
1491: }
1492: return $output;
1493: } else {
1494: $cdom = $$content{'domain'};
1495: $cnum = $$content{'number'};
1496: }
1497: } elsif ($caller eq 'rolepicker') {
1498: $cdom = $env{'form.cdom'};
1499: $cnum = $env{'form.cnum'};
1500: }
1.120 raeburn 1501: my $uctype = $type;
1502: $uctype =~ s/^(\w)/uc($1)/e;
1.108 raeburn 1503: my ($sections,$groups,$allroles,$rolehash,$accesshash) =
1.120 raeburn 1504: &Apache::loncommon::get_secgrprole_info($cdom,$cnum,1,$uctype);
1.108 raeburn 1505: if (!@{$sections}) {
1506: @{$sections} = ('none');
1507: } else {
1508: unshift(@{$sections},('all','none'));
1509: }
1510: if (!@{$groups}) {
1511: @{$groups} = ('none');
1512: } else {
1513: unshift(@{$groups},('all','none'));
1514: }
1515: my @allacesses = sort(keys(%{$accesshash}));
1516: my (%sectionhash,%grouphash);
1517: foreach my $sec (@{$sections}) {
1518: $sectionhash{$sec} = $sec;
1519: }
1520: foreach my $grp (@{$groups}) {
1521: $grouphash{$grp} = $grp;
1522: }
1523: my %lookup = (
1524: 'role' => $rolehash,
1525: 'access' => $accesshash,
1526: 'section' => \%sectionhash,
1527: 'group' => \%grouphash,
1528: );
1529: my @allaccesses = sort(keys(%{$accesshash}));
1530: my %allitems = (
1531: 'role' => $allroles,
1532: 'access' => \@allaccesses,
1533: 'section' => $sections,
1534: 'group' => $groups,
1535: );
1536: foreach my $item ('role','access','section','group') {
1537: $output .= '<td><select name="'.$item.$longid.'" multiple="true" size="4">'."\n";
1538: foreach my $entry (@{$allitems{$item}}) {
1539: if ($caller eq 'display') {
1540: if ((@{$$content{'roles'}{$role_id}{$item}} > 0) &&
1541: (grep(/^\Q$entry\E$/,@{$$content{'roles'}{$role_id}{$item}}))) {
1542: $output .= ' <option value="'.$entry.'" selected>'.
1543: $lookup{$item}{$entry}.'</option>';
1544: next;
1545: }
1546: }
1547: $output .= ' <option value="'.$entry.'">'.
1548: $lookup{$item}{$entry}.'</option>';
1549: }
1550: $output .= '</select>';
1551: }
1552: $output .= '</td>';
1553: return $output;
1554: }
1555:
1556: sub role_options_window {
1557: my ($r) = @_;
1558: my $cdom = $env{'form.cdom'};
1559: my $cnum = $env{'form.cnum'};
1560: my $type = $env{'form.type'};
1561: my $addindex = $env{'form.setroles'};
1.120 raeburn 1562: my $grouptitle = 'Groups';
1563: if ($type eq 'Group') {
1564: $grouptitle = 'Teams';
1565: }
1.108 raeburn 1566: my $role_selects = &role_selectors(1,1,'new',$type,undef,'rolepicker');
1567: $r->print(<<"END_SCRIPT");
1568: <script type="text/javascript">
1569: function setRoles() {
1570: var addidx = $addindex+1;
1571: for (var i=0; i<4; i++) {
1572: var copylist = '';
1573: for (var j=0; j<document.rolepicker.elements[i].length; j++) {
1574: if (document.rolepicker.elements[i].options[j].selected) {
1575: copylist = copylist + document.rolepicker.elements[i].options[j].value + ',';
1576: }
1577: }
1578: copylist = copylist.substr(0,copylist.length-1);
1579: opener.document.portform.elements[addidx+i].value = copylist;
1580: }
1581: self.close();
1582: }
1583: </script>
1584: END_SCRIPT
1585: $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 1586: $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 1587: return;
1.104 raeburn 1588: }
1589:
1.47 banghart 1590: sub select_files {
1.138 albertel 1591: my ($r) = @_;
1.82 albertel 1592: if ($env{'form.continue'} eq 'true') {
1.60 banghart 1593: # here we update the selections for the currentpath
1594: # eventually, have to handle removing those not checked, but . . .
1.83 banghart 1595: my @items=&Apache::loncommon::get_env_multiple('form.checkfile');
1596: if (scalar(@items)){
1.85 banghart 1597: &Apache::lonnet::save_selected_files($env{'user.name'}, $env{'form.currentpath'}, @items);
1.83 banghart 1598: }
1.62 banghart 1599: } else {
1600: #empty the file for a fresh start
1.83 banghart 1601: &Apache::lonnet::clear_selected_files($env{'user.name'});
1.62 banghart 1602: }
1.82 albertel 1603: my @files = &Apache::lonnet::files_not_in_path($env{'user.name'}, $env{'form.currentpath'});
1.62 banghart 1604: my $java_files = join ",", @files;
1605: if ($java_files) {
1606: $java_files.=',';
1.60 banghart 1607: }
1.63 banghart 1608: my $javascript =(<<ENDSMP);
1.113 albertel 1609: <script type="text/javascript">
1.48 banghart 1610: function finishSelect() {
1.62 banghart 1611: ENDSMP
1.63 banghart 1612: $javascript .= 'fileList = "'.$java_files.'";';
1613: $javascript .= (<<ENDSMP);
1.49 banghart 1614: for (i=0;i<document.forms.checkselect.length;i++) {
1615: if (document.forms.checkselect[i].checked){
1.54 banghart 1616: fileList = fileList + document.forms.checkselect.currentpath.value + document.forms.checkselect[i].value + "," ;
1.49 banghart 1617: }
1618: }
1.128 albertel 1619: opener.document.forms.lonhomework.$env{'form.fieldname'}.value=fileList;
1.48 banghart 1620: self.close();
1621: }
1622: </script>
1623: ENDSMP
1.63 banghart 1624: $r->print($javascript);
1.47 banghart 1625: $r->print("<h1>Select portfolio files</h1>
1.88 albertel 1626: Check as many as you wish in response to the problem.<br />");
1627: my @otherfiles=&Apache::lonnet::files_not_in_path($env{'user.name'}, $env{'form.currentpath'});
1628: if (@otherfiles) {
1629: $r->print("<strong>Files selected from other directories:</strong><br />");
1630: foreach my $file (@otherfiles) {
1631: $r->print($file."<br />");
1632: }
1.60 banghart 1633: }
1.47 banghart 1634: }
1.138 albertel 1635:
1.24 albertel 1636: sub upload {
1.137 albertel 1637: my ($r,$url,$group)=@_;
1.82 albertel 1638: my $fname=$env{'form.uploaddoc.filename'};
1639: my $filesize = (length($env{'form.uploaddoc'})) / 1000; #express in k (1024?)
1.38 banghart 1640: my $disk_quota = 20000; # expressed in k
1.126 raeburn 1641: if (defined($group)) {
1642: my $grp_quota = &get_group_quota($group); # quota expressed in k
1643: if ($grp_quota ne '') {
1644: $disk_quota = $grp_quota;
1645: } else {
1646: $disk_quota = 0;
1647: }
1648: }
1.34 banghart 1649: $fname=&Apache::lonnet::clean_filename($fname);
1.146 banghart 1650:
1.138 albertel 1651: my $portfolio_root=&get_portfolio_root();
1652: my ($uname,$udom) = &get_name_dom();
1653: my $port_path = &get_port_path();
1.38 banghart 1654: # Fixme --- Move the checking for existing file to LOND error return
1.138 albertel 1655: my @dir_list=&get_dir_list($portfolio_root);
1.34 banghart 1656: my $found_file = 0;
1.76 banghart 1657: my $locked_file = 0;
1.33 banghart 1658: foreach my $line (@dir_list) {
1.76 banghart 1659: my ($file_name)=split(/\&/,$line,2);
1660: if ($file_name eq $fname){
1.102 raeburn 1661: $file_name = $env{'form.currentpath'}.$file_name;
1.138 albertel 1662: $file_name = &prepend_group($file_name);
1.33 banghart 1663: $found_file = 1;
1.102 raeburn 1664: if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
1.76 banghart 1665: $locked_file = 1;
1666: }
1.33 banghart 1667: }
1668: }
1.94 raeburn 1669: my $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$portfolio_root);
1.87 albertel 1670: if (($current_disk_usage + $filesize) > $disk_quota){
1.116 albertel 1671: $r->print('<span class="LC_error">Unable to upload <strong>'.$fname.' (size = '.$filesize.' kilobytes)</strong>. Disk quota will be exceeded.</span>'.
1.38 banghart 1672: '<br />Disk quota is '.$disk_quota.' kilobytes. Your current disk usage is '.$current_disk_usage.' kilobytes.');
1.137 albertel 1673: $r->print(&done('Back',$url));
1.38 banghart 1674: }
1.76 banghart 1675: elsif ($found_file){
1676: if ($locked_file){
1.116 albertel 1677: $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 1678: '<br />You will be able to rename or delete existing '.$fname.' after a grade has been assigned.');
1.137 albertel 1679: $r->print(&done('Back',$url));
1.76 banghart 1680: } else {
1.116 albertel 1681: $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 1682: '<br />To upload, rename or delete existing '.$fname.' in '.$port_path.$env{'form.currentpath'});
1.137 albertel 1683: $r->print(&done('Back',$url));
1.76 banghart 1684: }
1.33 banghart 1685: } else {
1686: my $result=&Apache::lonnet::userfileupload('uploaddoc','',
1.94 raeburn 1687: $port_path.$env{'form.currentpath'});
1.33 banghart 1688: if ($result !~ m|^/uploaded/|) {
1.116 albertel 1689: $r->print('<span class="LC_error">'.'An errror occured ('.$result.
1690: ') while trying to upload '.&display_file().'</span><br />');
1.137 albertel 1691: $r->print(&done('Back',$url));
1.76 banghart 1692: } else {
1.137 albertel 1693: $r->print(&done(undef,$url));
1.33 banghart 1694: }
1.25 albertel 1695: }
1696: }
1.126 raeburn 1697:
1.80 banghart 1698: sub lock_info {
1.137 albertel 1699: my ($r,$url,$group) = @_;
1.138 albertel 1700: my ($uname,$udom) = &get_name_dom();
1.102 raeburn 1701: my $current_permissions = &Apache::lonnet::get_portfile_permissions($udom,
1702: $uname);
1.84 banghart 1703: my $file_name = $env{'form.lockinfo'};
1.138 albertel 1704: $file_name = &prepend_group($file_name);
1.102 raeburn 1705: if (defined($file_name) && defined($$current_permissions{$file_name})) {
1706: foreach my $array_item (@{$$current_permissions{$file_name}}) {
1.156 albertel 1707: next if (ref($array_item) ne 'ARRAY');
1708:
1709: my $filetext;
1710: if (defined($group)) {
1711: $filetext = '<strong>'.$env{'form.lockinfo'}.
1712: '</strong> (group: '.$group.')';
1713: } else {
1714: $filetext = '<strong>'.$file_name.'</strong>';
1715: }
1716:
1717: my $title ='<strong>'.&Apache::lonnet::gettitle($$array_item[0]).
1718: '</strong><br />';
1719: if ($$array_item[-1] eq 'graded') {
1720: $r->print(&mt('[_1] was submitted in response to problem: [_2]',
1721: $filetext,$title));
1722: } elsif ($$array_item[-1] eq 'handback') {
1723: $r->print(&mt('[_1] was handed back in response to problem: [_2]',
1724: $filetext,$title));
1725: } else {
1726: # submission style lock
1727: $r->print(&mt('[_1] was submitted in response to problem: [_2]',
1728: $filetext,$title));
1729: }
1730: my %course_description =
1731: &Apache::lonnet::coursedescription($$array_item[1]);
1732: if ( $course_description{'description'} ne '') {
1733: $r->print(&mt('In the course: <strong>[_1]</strong><br />',
1734: $course_description{'description'}));
1735: }
1.102 raeburn 1736: }
1.84 banghart 1737: }
1.137 albertel 1738: $r->print(&done('Back',$url));
1.80 banghart 1739: return 'ok';
1740: }
1.138 albertel 1741:
1.25 albertel 1742: sub createdir {
1.138 albertel 1743: my ($r,$url)=@_;
1.82 albertel 1744: my $newdir=&Apache::lonnet::clean_filename($env{'form.newdir'});
1.28 albertel 1745: if ($newdir eq '') {
1.116 albertel 1746: $r->print('<span class="LC_error">'.
1.37 banghart 1747: &mt("Error: no directory name was provided.").
1.116 albertel 1748: '</span><br />');
1.138 albertel 1749: $r->print(&done(undef,$url));
1.37 banghart 1750: return;
1.94 raeburn 1751: }
1.138 albertel 1752: my $portfolio_root = &get_portfolio_root();
1753: my @dir_list=&get_dir_list($portfolio_root);
1.37 banghart 1754: my $found_file = 0;
1755: foreach my $line (@dir_list) {
1756: my ($filename)=split(/\&/,$line,2);
1757: if ($filename eq $newdir){
1758: $found_file = 1;
1759: }
1760: }
1761: if ($found_file){
1.116 albertel 1762: $r->print('<span class="LC_error">'.'Unable to create a directory named <strong>'.$newdir.
1763: ' </strong>a file or directory by that name already exists.</span><br />');
1.37 banghart 1764: } else {
1.138 albertel 1765: my ($uname,$udom) = &get_name_dom();
1766: my $port_path = &get_port_path();
1.94 raeburn 1767: my $result=&Apache::lonnet::mkdiruserfile($uname,$udom,
1768: $port_path.$env{'form.currentpath'}.$newdir);
1.37 banghart 1769: if ($result ne 'ok') {
1.116 albertel 1770: $r->print('<span class="LC_error">'.'An errror occured ('.$result.
1771: ') while trying to create a new directory '.&display_file().'</span><br />');
1.37 banghart 1772: }
1.24 albertel 1773: }
1.82 albertel 1774: if ($newdir ne $env{'form.newdir'}) {
1775: $r->print("The new directory name was changed from:<br /><strong>".$env{'form.newdir'}."</strong> to <strong>$newdir </strong>");
1.67 banghart 1776: }
1.137 albertel 1777: $r->print(&done(undef,$url));
1.94 raeburn 1778: }
1779:
1780: sub get_portfolio_root {
1.163 raeburn 1781: my ($udom,$uname,$group) = @_;
1.160 raeburn 1782: if (!(defined($udom)) || !(defined($uname))) {
1783: ($uname,$udom) = &get_name_dom();
1784: }
1.163 raeburn 1785: my $path = '/userfiles/portfolio';
1786: if (!defined($group)) {
1787: if (defined($env{'form.group'})) {
1788: $group = $env{'form.group'};
1789: }
1.94 raeburn 1790: }
1.163 raeburn 1791: if (defined($group)) {
1792: $path = '/userfiles/groups/'.$group.'/portfolio';
1793: }
1.94 raeburn 1794: return (&Apache::loncommon::propath($udom,$uname).$path);
1795: }
1796:
1.126 raeburn 1797: sub get_group_quota {
1798: my ($group) = @_;
1799: my $group_quota;
1800: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1801: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1802: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum,$group);
1803: if (%curr_groups) {
1804: my %group_info = &Apache::longroup::get_group_settings(
1805: $curr_groups{$group});
1806: $group_quota = $group_info{'quota'}; #expressed in Mb
1807: if ($group_quota) {
1808: $group_quota = 1000 * $group_quota; #expressed in k
1809: }
1810: }
1811: return $group_quota;
1812: }
1813:
1.94 raeburn 1814: sub get_dir_list {
1.138 albertel 1815: my ($portfolio_root) = @_;
1816: my ($uname,$udom) = &get_name_dom();
1.94 raeburn 1817: return &Apache::lonnet::dirlist($env{'form.currentpath'},
1818: $udom,$uname,$portfolio_root);
1819: }
1820:
1821: sub get_name_dom {
1822: my ($uname,$udom);
1.138 albertel 1823: if (defined($env{'form.group'})) {
1.94 raeburn 1824: $udom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1825: $uname = $env{'course.'.$env{'request.course.id'}.'.num'};
1826: } else {
1827: $udom = $env{'user.domain'};
1828: $uname = $env{'user.name'};
1829: }
1830: return ($uname,$udom);
1831: }
1832:
1.102 raeburn 1833: sub prepend_group {
1.138 albertel 1834: my ($filename) = @_;
1835: if (defined($env{'form.group'})) {
1836: $filename = $env{'form.group'}.$filename;
1.102 raeburn 1837: }
1838: return $filename;
1839: }
1840:
1.94 raeburn 1841: sub get_namespace {
1842: my $namespace = 'portfolio';
1.138 albertel 1843: if (defined($env{'form.group'})) {
1844: my ($uname,$udom) = &get_name_dom();
1845: $namespace .= '_'.$udom.'_'.$uname.'_'.$env{'form.group'};
1.94 raeburn 1846: }
1847: return $namespace;
1848: }
1849:
1850: sub get_port_path {
1851: my $port_path;
1.138 albertel 1852: if (defined($env{'form.group'})) {
1853: $port_path = "groups/$env{'form.group'}/portfolio";
1.94 raeburn 1854: } else {
1855: $port_path = 'portfolio';
1856: }
1857: return $port_path;
1.24 albertel 1858: }
1859:
1.120 raeburn 1860: sub missing_priv {
1.138 albertel 1861: my ($r,$url,$priv) = @_;
1.120 raeburn 1862: my $longtext = {
1863: upload => 'upload files',
1864: delete => 'delete files',
1865: rename => 'rename files',
1866: setacl => 'set access controls for files',
1867: };
1868: my $escpath = &HTML::Entities::encode($env{'form.currentpath'},'&<>"');
1869: my $rtnlink = '<a href="'.$url;
1870: if ($url =~ /\?/) {
1871: $rtnlink .= '&';
1872: } else {
1873: $rtnlink .= '?';
1874: }
1875: $rtnlink .= 'currentpath='.$escpath;
1876: $r->print(&mt('<h3>Action disallowed</h3>'));
1877: $r->print(&mt('You do not have sufficient privileges to [_1] ',
1878: $longtext->{$priv}));
1.138 albertel 1879: if (defined($env{'form.group'})) {
1.120 raeburn 1880: $r->print(&mt("in the group's file repository."));
1.137 albertel 1881: $rtnlink .= &group_args()
1.120 raeburn 1882: } else {
1883: $r->print(&mt('in this portfolio.'));
1884: }
1885: $rtnlink .= '">'.&mt('Return to directory listing page').'</a>';
1886: $r->print('<br />'.$rtnlink);
1887: $r->print(&Apache::loncommon::end_page());
1888: return;
1889: }
1890:
1.132 raeburn 1891: sub coursegrp_portfolio_header {
1.137 albertel 1892: my ($cdom,$cnum,$grp_desc)=@_;
1.132 raeburn 1893: my $gpterm = &Apache::loncommon::group_term();
1894: my $ucgpterm = $gpterm;
1895: $ucgpterm =~ s/^(\w)/uc($1)/e;
1.137 albertel 1896: if ($env{'form.ref'}) {
1.136 raeburn 1897: &Apache::lonhtmlcommon::add_breadcrumb
1898: ({href=>"/adm/coursegroups",
1899: text=>"Groups",
1900: title=>"Course Groups"});
1901: }
1.132 raeburn 1902: &Apache::lonhtmlcommon::add_breadcrumb
1.138 albertel 1903: ({href=>"/adm/$cdom/$cnum/$env{'form.group'}/smppg?ref=$env{'form.ref'}",
1.132 raeburn 1904: text=>"$ucgpterm: $grp_desc",
1905: title=>"Go to group's home page"},
1.137 albertel 1906: {href=>"/adm/coursegrp_portfolio?".&group_args(),
1.132 raeburn 1907: text=>"Group Portfolio",
1.136 raeburn 1908: title=>"Display group portfolio"});
1.132 raeburn 1909: my $output = &Apache::lonhtmlcommon::breadcrumbs(
1910: &mt('[_1] portfolio files - [_2]',$gpterm,$grp_desc));
1911: return $output;
1912: }
1913:
1914:
1.24 albertel 1915: sub handler {
1916: # this handles file management
1917: my $r = shift;
1.73 banghart 1918: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.108 raeburn 1919: ['selectfile','currentpath','meta','lockinfo','currentfile','action',
1920: 'fieldname','mode','rename','continue','group','access','setnum',
1.136 raeburn 1921: 'cnum','cdom','type','setroles','showversions','ref']);
1.138 albertel 1922: my ($uname,$udom,$portfolio_root,$url,$caller,$title,$group,$grp_desc);
1.94 raeburn 1923: if ($r->uri =~ m|^(/adm/)([^/]+)|) {
1924: $url = $1.$2;
1925: $caller = $2;
1926: }
1.137 albertel 1927: my ($can_modify,$can_delete,$can_upload,$can_setacl);
1.94 raeburn 1928: if ($caller eq 'coursegrp_portfolio') {
1929: # Needs to be in a course
1930: if (! ($env{'request.course.fn'})) {
1931: # Not in a course
1932: $env{'user.error.msg'}=
1933: "/adm/coursegrp_portfolio:rgf:0:0:Cannot view group portfolio";
1934: return HTTP_NOT_ACCEPTABLE;
1935: }
1936: my $earlyout = 0;
1.136 raeburn 1937: my $view_permission =
1938: &Apache::lonnet::allowed('vcg',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''));
1.137 albertel 1939: $env{'form.group'} =~ s/\W//g;
1.138 albertel 1940: $group = $env{'form.group'};
1.94 raeburn 1941: if ($group) {
1.138 albertel 1942: ($uname,$udom) = &get_name_dom();
1.99 raeburn 1943: my %curr_groups = &Apache::longroup::coursegroups($udom,$uname,
1.98 albertel 1944: $group);
1945: if (%curr_groups) {
1.132 raeburn 1946: my %grp_content = &Apache::longroup::get_group_settings(
1947: $curr_groups{$group});
1948: $grp_desc = &unescape($grp_content{'description'});
1.94 raeburn 1949: if (($view_permission) || (&Apache::lonnet::allowed('rgf',
1950: $env{'request.course.id'}.'/'.$group))) {
1.138 albertel 1951: $portfolio_root = &get_portfolio_root();
1.94 raeburn 1952: } else {
1.116 albertel 1953: $r->print('You do not have the privileges required to access the shared files space for this group.');
1.94 raeburn 1954: $earlyout = 1;
1955: }
1956: } else {
1957: $r->print('Not a valid group for this course');
1958: $earlyout = 1;
1959: }
1960: $title = &mt('Group files').' for '.$group;
1961: } else {
1962: $r->print('Invalid group');
1963: $earlyout = 1;
1964: }
1965: if ($earlyout) { return OK; }
1.126 raeburn 1966: if (&Apache::lonnet::allowed('mdg',$env{'request.course.id'})) {
1.120 raeburn 1967: $can_modify = 1;
1968: $can_delete = 1;
1.126 raeburn 1969: $can_upload = 1;
1970: $can_setacl = 1;
1971: } else {
1972: if (&Apache::lonnet::allowed('agf',$env{'request.course.id'}.'/'.$group)) {
1973: $can_setacl = 1;
1974: }
1975: if (&Apache::lonnet::allowed('ugf',$env{'request.course.id'}.'/'.$group)) {
1976: $can_upload = 1;
1977: }
1978: if (&Apache::lonnet::allowed('mgf',$env{'request.course.id'}.'/'.$group)) {
1979: $can_modify = 1;
1980: }
1981: if (&Apache::lonnet::allowed('dgf',$env{'request.course.id'}.'/'.$group)) {
1982: $can_delete = 1;
1983: }
1.120 raeburn 1984: }
1.94 raeburn 1985: } else {
1986: ($uname,$udom) = &get_name_dom();
1987: $portfolio_root = &get_portfolio_root();
1988: $title = &mt('Portfolio Manager');
1.120 raeburn 1989: $can_modify = 1;
1990: $can_delete = 1;
1991: $can_upload = 1;
1992: $can_setacl = 1;
1.94 raeburn 1993: }
1994:
1.138 albertel 1995: my $port_path = &get_port_path();
1.24 albertel 1996: &Apache::loncommon::no_cache($r);
1997: &Apache::loncommon::content_type($r,'text/html');
1998: $r->send_http_header;
1999: # Give the LON-CAPA page header
1.82 albertel 2000: if ($env{"form.mode"} eq 'selectfile'){
1.96 albertel 2001: $r->print(&Apache::loncommon::start_page($title,undef,
1.97 albertel 2002: {'only_body' => 1}));
1.108 raeburn 2003: } elsif ($env{'form.action'} eq 'rolepicker') {
2004: $r->print(&Apache::loncommon::start_page('New role-based condition',undef,
2005: {'no_nav_bar' => 1, }));
1.74 banghart 2006: } else {
1.97 albertel 2007: $r->print(&Apache::loncommon::start_page($title));
1.74 banghart 2008: }
1.24 albertel 2009: $r->rflush();
1.88 albertel 2010: if (($env{'form.storeupl'}) & (!$env{'form.uploaddoc.filename'})){
1.116 albertel 2011: $r->print('<span class="LC_error">'.
2012: 'No file was selected to upload.'.
2013: 'To upload a file, click <strong>Browse...</strong>'.
2014: ', select a file, then click <strong>Upload</strong>.'.
2015: '</span>');
1.40 banghart 2016: }
1.82 albertel 2017: if ($env{'form.meta'}) {
1.94 raeburn 2018: &open_form($r,$url);
1.82 albertel 2019: # $r->print(&edit_meta_data($r, $env{'form.currentpath'}.$env{'form.selectfile'}));
1.70 banghart 2020: $r->print('Edit the meta data<br />');
1.137 albertel 2021: &close_form($r,$url);
1.70 banghart 2022: }
1.82 albertel 2023: if ($env{'form.store'}) {
1.70 banghart 2024: }
2025:
1.82 albertel 2026: if ($env{'form.uploaddoc.filename'}) {
1.120 raeburn 2027: if ($can_upload) {
1.137 albertel 2028: &upload($r,$url,$group);
1.120 raeburn 2029: } else {
1.138 albertel 2030: &missing_priv($r,$url,'upload');
1.120 raeburn 2031: }
1.82 albertel 2032: } elsif ($env{'form.action'} eq 'delete' && $env{'form.confirmed'}) {
1.120 raeburn 2033: if ($can_delete) {
1.164 ! raeburn 2034: &delete_confirmed($r,$url,$group);
1.120 raeburn 2035: } else {
1.138 albertel 2036: &missing_priv($r,$url,'delete');
1.120 raeburn 2037: }
1.82 albertel 2038: } elsif ($env{'form.action'} eq 'delete') {
1.120 raeburn 2039: if ($can_delete) {
1.138 albertel 2040: &delete($r,$url);
1.120 raeburn 2041: } else {
1.138 albertel 2042: &missing_priv($r,$url,'delete');
1.120 raeburn 2043: }
1.82 albertel 2044: } elsif ($env{'form.action'} eq 'deletedir' && $env{'form.confirmed'}) {
1.120 raeburn 2045: if ($can_delete) {
1.138 albertel 2046: &delete_dir_confirmed($r,$url);
1.120 raeburn 2047: } else {
1.138 albertel 2048: &missing_priv($r,$url,'delete');
1.120 raeburn 2049: }
2050: } elsif ($env{'form.action'} eq 'deletedir') {
2051: if ($can_delete) {
1.137 albertel 2052: &delete_dir($r,$url);
1.120 raeburn 2053: } else {
1.138 albertel 2054: &missing_priv($r,$url,'delete');
1.120 raeburn 2055: }
1.82 albertel 2056: } elsif ($env{'form.action'} eq 'rename' && $env{'form.confirmed'}) {
1.120 raeburn 2057: if ($can_modify) {
1.164 ! raeburn 2058: &rename_confirmed($r,$url,$group);
1.120 raeburn 2059: } else {
1.138 albertel 2060: &missing_priv($r,$url,'rename');
1.120 raeburn 2061: }
1.82 albertel 2062: } elsif ($env{'form.rename'}) {
2063: $env{'form.selectfile'} = $env{'form.rename'};
2064: $env{'form.action'} = 'rename';
1.120 raeburn 2065: if ($can_modify) {
1.138 albertel 2066: &rename($r,$url);
1.120 raeburn 2067: } else {
1.138 albertel 2068: &missing_priv($r,$url,'rename');
1.120 raeburn 2069: }
1.104 raeburn 2070: } elsif ($env{'form.access'}) {
2071: $env{'form.selectfile'} = $env{'form.access'};
2072: $env{'form.action'} = 'chgaccess';
1.137 albertel 2073: &display_access($r,$url,$group,$can_setacl,$port_path);
1.104 raeburn 2074: } elsif ($env{'form.action'} eq 'chgaccess') {
1.120 raeburn 2075: if ($can_setacl) {
1.137 albertel 2076: &update_access($r,$url,$group,$port_path);
1.120 raeburn 2077: } else {
1.138 albertel 2078: &missing_priv($r,$url,'setacl');
1.120 raeburn 2079: }
1.108 raeburn 2080: } elsif ($env{'form.action'} eq 'rolepicker') {
1.120 raeburn 2081: if ($can_setacl) {
2082: &role_options_window($r);
2083: } else {
1.138 albertel 2084: &missing_priv($r,$url,'setacl');
1.120 raeburn 2085: }
1.82 albertel 2086: } elsif ($env{'form.createdir'}) {
1.120 raeburn 2087: if ($can_upload) {
1.138 albertel 2088: &createdir($r,$url);
1.120 raeburn 2089: } else {
1.138 albertel 2090: &missing_priv($r,$url,'upload');
1.120 raeburn 2091: }
1.82 albertel 2092: } elsif ($env{'form.lockinfo'}) {
1.137 albertel 2093: &lock_info($r,$url,$group);
1.24 albertel 2094: } else {
2095: my $current_path='/';
1.82 albertel 2096: if ($env{'form.currentpath'}) {
2097: $current_path = $env{'form.currentpath'};
1.24 albertel 2098: }
1.132 raeburn 2099: if ($caller eq 'coursegrp_portfolio') {
2100: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.137 albertel 2101: $r->print(&coursegrp_portfolio_header($udom,$uname,$grp_desc));
1.132 raeburn 2102: }
1.138 albertel 2103: my @dir_list=&get_dir_list($portfolio_root);
1.46 albertel 2104: if ($dir_list[0] eq 'no_such_dir'){
2105: # two main reasons for this:
2106: # 1) never been here, so directory structure not created
2107: # 2) back-button navigation after deleting a directory
2108: if ($current_path eq '/'){
1.100 albertel 2109: &Apache::lonnet::mkdiruserfile($uname,$udom,
1.138 albertel 2110: &get_port_path());
1.46 albertel 2111: } else {
2112: # some directory that snuck in get rid of the directory
2113: # from the recent pulldown, just in case
2114: &Apache::lonhtmlcommon::remove_recent('portfolio',
2115: [$current_path]);
2116: $current_path = '/'; # force it back to the root
2117: }
2118: # now grab the directory list again, for the first time
2119: @dir_list=&Apache::lonnet::dirlist($current_path,
1.94 raeburn 2120: $udom,$uname,$portfolio_root);
1.43 banghart 2121: }
1.46 albertel 2122: # need to know if directory is empty so it can be removed if desired
2123: my $is_empty=(@dir_list == 2);
1.137 albertel 2124: &display_common($r,$url,$current_path,$is_empty,\@dir_list,
2125: $can_upload);
1.138 albertel 2126: &display_directory($r,$url,$current_path,$is_empty,\@dir_list,$group,
1.137 albertel 2127: $can_upload,$can_modify,$can_delete,$can_setacl);
1.95 albertel 2128: $r->print(&Apache::loncommon::end_page());
1.30 banghart 2129: }
1.90 albertel 2130: return OK;
1.2 banghart 2131: }
1.120 raeburn 2132:
1.1 banghart 2133: 1;
2134: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>