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