Annotation of loncom/interface/portfolio.pm, revision 1.173
1.125 albertel 1: # The LearningOnline Network
2: # portfolio browser
3: #
1.173 ! raeburn 4: # $Id: portfolio.pm,v 1.172 2006/11/09 22:33:32 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.172 raeburn 877: $r->print('<table width="100%"><tr>');
1.120 raeburn 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.172 raeburn 1339: if ($type eq 'course' && $status eq 'old') {
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">
1.172 raeburn 1376: function setRoleOptions(num,roleid,cdom,cnum,type) {
1377: updateIndexNum = getIndexByValue('update',num);
1378: var addItem = 'add_role_'+num;
1379: var addIndexNum = getIndexByName(addItem);
1380: if (document.portform.elements[addItem].checked) {
1381: document.portform.elements[updateIndexNum].checked = true;
1382: var url = '/adm/portfolio?action=rolepicker&setroles='+num+'_'+roleid+'&cnum='+cnum+'&cdom='+cdom+'&type='+type;
1.108 raeburn 1383: var title = 'Roles_Chooser';
1384: var options = 'scrollbars=1,resizable=1,menubar=0';
1385: options += ',width=700,height=600';
1386: rolebrowser = open(url,title,options,'1');
1387: rolebrowser.focus();
1388: } else {
1.172 raeburn 1389: addArray = new Array ('role','access','section','group');
1390: for (var j=0;j<addArray.length;j++) {
1391: var itemIndex = getIndexByName(addArray[j]+'_'+num+'_'+roleid);
1392: document.portform.elements[itemIndex].value = '';
1.108 raeburn 1393: }
1394: }
1395: }
1396:
1.172 raeburn 1397: function getIndexByName(item) {
1.108 raeburn 1398: for (var i=0;i<document.portform.elements.length;i++) {
1.172 raeburn 1399: if (document.portform.elements[i].name == item) {
1.108 raeburn 1400: return i;
1401: }
1402: }
1403: return -1;
1404: }
1405:
1.172 raeburn 1406: function getIndexByValue(name,value) {
1.108 raeburn 1407: for (var i=0;i<document.portform.elements.length;i++) {
1408: if (document.portform.elements[i].name == name && document.portform.elements[i].value == value) {
1409: return i;
1410: }
1411: }
1412: return -1;
1413: }
1414:
1415: </script>
1.110 albertel 1416: |;
1417: }
1418:
1419: sub course_row {
1.118 albertel 1420: my ($r,$status,$type,$item,$access_controls,$now,$then) = @_;
1.115 raeburn 1421: my $content;
1.110 albertel 1422: my $defdom = $env{'user.domain'};
1423: if ($status eq 'old') {
1.115 raeburn 1424: $content = $$access_controls{$item};
1425: $defdom = $content->{'domain'};
1.110 albertel 1426: }
1427: my $js = &Apache::loncommon::coursebrowser_javascript($defdom)
1428: .&course_js();
1.120 raeburn 1429: my $uctype = $type;
1430: $uctype =~ s/^(\w)/uc($1)/e;
1.108 raeburn 1431: my ($num,$scope,$end,$start) = &set_identifiers($status,$item,$now,$then,
1432: $type);
1.110 albertel 1433: $r->print('<td>'.$js.&actionbox($status,$num,$scope).'</td>');
1.108 raeburn 1434: if ($status eq 'old') {
1.115 raeburn 1435: my $cid = $content->{'domain'}.'_'.$content->{'number'};
1.108 raeburn 1436: my %course_description = &Apache::lonnet::coursedescription($cid);
1.115 raeburn 1437: $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 1438: } elsif ($status eq 'new') {
1.172 raeburn 1439: $r->print('<td>'.&Apache::loncommon::selectcourse_link('portform','crsnum_'.$num,'crsdom_'.$num,'description_'.$num,$num.'_1',undef,$uctype).' <input type="text" name="description_'.$num.'" size="30" /><input type="hidden" name="crsdom_'.$num.'" /><input type="hidden" name="crsnum_'.$num.'" /></td>');
1.108 raeburn 1440: }
1.172 raeburn 1441: $r->print('<td>'.&dateboxes($num,$start,$end));
1442: my $newrole_id = 1;
1.108 raeburn 1443: if ($status eq 'old') {
1.172 raeburn 1444: $r->print('</td><td>');
1.108 raeburn 1445: my $max_id = 0;
1.172 raeburn 1446: if (keys(%{$content->{'roles'}}) > 0) {
1447: $r->print('<table><tr><th>'.&mt('Action').'</th>'.
1448: '<th>'.&mt('Roles').'</th>'.
1449: '<th>'.&mt('Access').'</th>'.
1450: '<th>'.&mt('Sections').'</th>'.
1451: '<th>'.&mt('Groups').'</th></tr>');
1452: foreach my $role_id (sort(keys(%{$content->{'roles'}}))) {
1453: if ($role_id > $max_id) {
1454: $max_id = $role_id;
1455: }
1456: $max_id ++;
1457: my $role_selects = &role_selectors($num,$role_id,$type,$content,'display');
1458: $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>');
1459: }
1460: $r->print('</table>');
1461: }
1462: $r->print('<br />'.&mt('Add a roles-based condition').
1463: ' <input type="checkbox" name ="add_role_'.
1464: $num.'" onClick="javascript:setRoleOptions('."'$num',
1465: '$max_id','$content->{'domain'}','$content->{'number'}',
1466: '$uctype'".')" value="" />');
1467: $newrole_id = $max_id;
1468: } else {
1469: $r->print('<input type="hidden" name ="add_role_'.$num.'" value="" />');
1.108 raeburn 1470: }
1.172 raeburn 1471: $r->print(&add_course_role($num,$newrole_id));
1472: $r->print('</td>');
1.108 raeburn 1473: return;
1474: }
1475:
1.172 raeburn 1476: sub add_course_role {
1477: my ($num,$max_id) = @_;
1478: my $output;
1479: $output .='<input type="hidden" name="role_'.$num.'_'.$max_id.'" />'.
1480: '<input type="hidden" name="access_'.$num.'_'.$max_id.'" />'.
1481: '<input type="hidden" name="section_'.$num.'_'.$max_id.'" />'.
1482: '<input type="hidden" name="group_'.$num.'_'.$max_id.'" />';
1483: return $output;
1484: }
1485:
1.108 raeburn 1486: sub domains_row {
1487: my ($r,$status,$item,$all_doms,$access_controls,$now,$then) = @_;
1488: my ($num,$scope,$end,$start) = &set_identifiers($status,$item,$now,$then,
1489: 'domains');
1.112 albertel 1490: my $dom_select = '<select name="dom_'.$num.'" size="4" multiple="true">'.
1.108 raeburn 1491: ' <option value="">'.&mt('Please select').'</option>';
1492: if ($status eq 'old') {
1.109 albertel 1493: my $content = $$access_controls{$item};
1494: foreach my $dom (@{$all_doms}) {
1495: if ((@{$content->{'dom'}} > 0)
1496: && (grep(/^\Q$dom\E$/,@{$content->{'dom'}}))) {
1.108 raeburn 1497: $dom_select .= '<option value="'.$dom.'" selected>'.
1498: $dom.'</option>';
1499: } else {
1500: $dom_select .= '<option value="'.$dom.'">'.$dom.'</option>';
1501: }
1502: }
1503: } else {
1504: foreach my $dom (@{$all_doms}) {
1505: $dom_select .= '<option value="'.$dom.'">'.$dom.'</option>';
1506: }
1507: }
1.112 albertel 1508: $dom_select .= '</select>';
1.108 raeburn 1509: $r->print('<td>'.&actionbox($status,$num,$scope).'</td><td>'.$dom_select.
1510: '</td><td>'.&dateboxes($num,$start,$end).'</td>');
1511: }
1512:
1513: sub users_row {
1514: my ($r,$status,$item,$access_controls,$now,$then) = @_;
1515: my ($num,$scope,$end,$start) = &set_identifiers($status,$item,$now,$then,
1516: 'users');
1517: my $curr_user_list;
1518: if ($status eq 'old') {
1.109 albertel 1519: my $content = $$access_controls{$item};
1520: $curr_user_list = &sort_users($content->{'users'});
1.108 raeburn 1521: }
1522: $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>');
1523: }
1524:
1525: sub additional_item {
1526: my ($type) = @_;
1527: my $output = &mt('Add new [_1] condition(s)?',$type).' '.&mt('Number to add: ').'<input type="text" name="new'.$type.'" size="3" value="0" />';
1528: return $output;
1529: }
1530:
1531: sub actionbox {
1532: my ($status,$num,$scope) = @_;
1.112 albertel 1533: my $output = '<span style="white-space: nowrap"><label>';
1.108 raeburn 1534: if ($status eq 'new') {
1.170 raeburn 1535: my $checkstate;
1536: if ($scope eq 'domains' || $scope eq 'users' || $scope eq 'course') {
1537: $checkstate = 'checked="checked"';
1538: }
1539: $output .= '<input type="checkbox" name="activate" value="'.$num.'" '.
1540: $checkstate.' />'.
1.108 raeburn 1541: &mt('Activate');
1542: } else {
1543: $output .= '<input type="checkbox" name="delete" value="'.$num.
1.112 albertel 1544: '" />'.&mt('Delete').'</label></span><br /><span style="white-space: nowrap">'.
1.108 raeburn 1545: '<label><input type="checkbox" name="update" value="'.
1546: $num.'" />'.&mt('Update');
1547: }
1.112 albertel 1548: $output .= '</label></span><input type="hidden" name="scope_'.$num. '" value="'.$scope.'" />';
1.108 raeburn 1549: return $output;
1550: }
1551:
1552: sub dateboxes {
1553: my ($num,$start,$end) = @_;
1554: my $noend;
1555: if ($end == 0) {
1556: $noend = 'checked="checked"';
1557: }
1558: my $startdate = &Apache::lonhtmlcommon::date_setter('portform',
1559: 'startdate_'.$num,$start,undef,undef,undef,1,undef,
1560: undef,undef,1);
1561: my $enddate = &Apache::lonhtmlcommon::date_setter('portform',
1562: 'enddate_'.$num,$end,undef,undef,undef,1,undef,
1.112 albertel 1563: undef,undef,1). ' <span style="white-space: nowrap"><label>'.
1.108 raeburn 1564: '<input type="checkbox" name="noend_'.
1565: $num.'" '.$noend.' />'.&mt('No end date').
1.112 albertel 1566: '</label></span>';
1.108 raeburn 1567:
1568: my $output = &mt('Start: ').$startdate.'<br />'.&mt('End: ').$enddate;
1569: return $output;
1570: }
1571:
1572: sub unpack_acc_key {
1573: my ($acc_key) = @_;
1574: my ($num,$scope,$end,$start) = ($acc_key =~ /^([^:]+):([a-z]+)_(\d*)_?(\d*)$/);
1575: return ($num,$scope,$end,$start);
1576: }
1577:
1578: sub set_identifiers {
1579: my ($status,$item,$now,$then,$scope) = @_;
1580: if ($status eq 'old') {
1581: return(&unpack_acc_key($item));
1582: } else {
1583: return($item,$scope,$then,$now);
1584: }
1585: }
1586:
1587: sub role_selectors {
1.172 raeburn 1588: my ($num,$role_id,$type,$content,$caller) = @_;
1.108 raeburn 1589: my ($output,$cdom,$cnum,$longid);
1590: if ($caller eq 'display') {
1591: $longid = '_'.$num.'_'.$role_id;
1.172 raeburn 1592: $cdom = $$content{'domain'};
1593: $cnum = $$content{'number'};
1.108 raeburn 1594: } elsif ($caller eq 'rolepicker') {
1595: $cdom = $env{'form.cdom'};
1596: $cnum = $env{'form.cnum'};
1597: }
1.120 raeburn 1598: my $uctype = $type;
1599: $uctype =~ s/^(\w)/uc($1)/e;
1.108 raeburn 1600: my ($sections,$groups,$allroles,$rolehash,$accesshash) =
1.120 raeburn 1601: &Apache::loncommon::get_secgrprole_info($cdom,$cnum,1,$uctype);
1.108 raeburn 1602: if (!@{$sections}) {
1603: @{$sections} = ('none');
1604: } else {
1605: unshift(@{$sections},('all','none'));
1606: }
1607: if (!@{$groups}) {
1608: @{$groups} = ('none');
1609: } else {
1610: unshift(@{$groups},('all','none'));
1611: }
1612: my @allacesses = sort(keys(%{$accesshash}));
1613: my (%sectionhash,%grouphash);
1614: foreach my $sec (@{$sections}) {
1615: $sectionhash{$sec} = $sec;
1616: }
1617: foreach my $grp (@{$groups}) {
1618: $grouphash{$grp} = $grp;
1619: }
1620: my %lookup = (
1621: 'role' => $rolehash,
1622: 'access' => $accesshash,
1623: 'section' => \%sectionhash,
1624: 'group' => \%grouphash,
1625: );
1626: my @allaccesses = sort(keys(%{$accesshash}));
1627: my %allitems = (
1628: 'role' => $allroles,
1629: 'access' => \@allaccesses,
1630: 'section' => $sections,
1.172 raeburn 1631: 'group' => $groups,
1.108 raeburn 1632: );
1633: foreach my $item ('role','access','section','group') {
1634: $output .= '<td><select name="'.$item.$longid.'" multiple="true" size="4">'."\n";
1635: foreach my $entry (@{$allitems{$item}}) {
1636: if ($caller eq 'display') {
1637: if ((@{$$content{'roles'}{$role_id}{$item}} > 0) &&
1638: (grep(/^\Q$entry\E$/,@{$$content{'roles'}{$role_id}{$item}}))) {
1639: $output .= ' <option value="'.$entry.'" selected>'.
1640: $lookup{$item}{$entry}.'</option>';
1641: next;
1642: }
1643: }
1644: $output .= ' <option value="'.$entry.'">'.
1645: $lookup{$item}{$entry}.'</option>';
1646: }
1647: $output .= '</select>';
1648: }
1649: $output .= '</td>';
1650: return $output;
1651: }
1652:
1653: sub role_options_window {
1654: my ($r) = @_;
1655: my $type = $env{'form.type'};
1.172 raeburn 1656: my $rolenum = $env{'form.setroles'};
1657: my ($num,$role_id) = ($rolenum =~ /^([\d_]+)_(\d+)$/);
1658: my $role_elements;
1659: foreach my $item ('role','access','section','group') {
1660: $role_elements .= "'".$item.'_'.$rolenum."',";
1661: }
1662: $role_elements =~ s/,$//;
1663: my $role_selects = &role_selectors($num,$role_id,$type,undef,
1664: 'rolepicker');
1.108 raeburn 1665: $r->print(<<"END_SCRIPT");
1666: <script type="text/javascript">
1667: function setRoles() {
1.172 raeburn 1668: var role_elements = new Array($role_elements);
1669: for (var i=0; i<role_elements.length; i++) {
1.108 raeburn 1670: var copylist = '';
1671: for (var j=0; j<document.rolepicker.elements[i].length; j++) {
1672: if (document.rolepicker.elements[i].options[j].selected) {
1673: copylist = copylist + document.rolepicker.elements[i].options[j].value + ',';
1674: }
1675: }
1676: copylist = copylist.substr(0,copylist.length-1);
1.172 raeburn 1677: var openerItem = getIndexByName(role_elements[i]);
1678: opener.document.portform.elements[openerItem].value = copylist;
1.108 raeburn 1679: }
1.172 raeburn 1680: var roleAdder = getIndexByName('add_role_$num');
1681: opener.document.portform.elements[roleAdder].value = '$role_id';
1.108 raeburn 1682: self.close();
1683: }
1.172 raeburn 1684:
1685: function getIndexByName(item) {
1686: for (var i=0;i<opener.document.portform.elements.length;i++) {
1687: if (opener.document.portform.elements[i].name == item) {
1688: return i;
1689: }
1690: }
1691: return -1;
1692: }
1693:
1.108 raeburn 1694: </script>
1695: END_SCRIPT
1696: $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 1697: $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 1698: return;
1.104 raeburn 1699: }
1700:
1.47 banghart 1701: sub select_files {
1.138 albertel 1702: my ($r) = @_;
1.82 albertel 1703: if ($env{'form.continue'} eq 'true') {
1.60 banghart 1704: # here we update the selections for the currentpath
1705: # eventually, have to handle removing those not checked, but . . .
1.83 banghart 1706: my @items=&Apache::loncommon::get_env_multiple('form.checkfile');
1707: if (scalar(@items)){
1.85 banghart 1708: &Apache::lonnet::save_selected_files($env{'user.name'}, $env{'form.currentpath'}, @items);
1.83 banghart 1709: }
1.62 banghart 1710: } else {
1711: #empty the file for a fresh start
1.83 banghart 1712: &Apache::lonnet::clear_selected_files($env{'user.name'});
1.62 banghart 1713: }
1.82 albertel 1714: my @files = &Apache::lonnet::files_not_in_path($env{'user.name'}, $env{'form.currentpath'});
1.62 banghart 1715: my $java_files = join ",", @files;
1716: if ($java_files) {
1717: $java_files.=',';
1.60 banghart 1718: }
1.63 banghart 1719: my $javascript =(<<ENDSMP);
1.113 albertel 1720: <script type="text/javascript">
1.48 banghart 1721: function finishSelect() {
1.62 banghart 1722: ENDSMP
1.63 banghart 1723: $javascript .= 'fileList = "'.$java_files.'";';
1724: $javascript .= (<<ENDSMP);
1.49 banghart 1725: for (i=0;i<document.forms.checkselect.length;i++) {
1726: if (document.forms.checkselect[i].checked){
1.54 banghart 1727: fileList = fileList + document.forms.checkselect.currentpath.value + document.forms.checkselect[i].value + "," ;
1.49 banghart 1728: }
1729: }
1.128 albertel 1730: opener.document.forms.lonhomework.$env{'form.fieldname'}.value=fileList;
1.48 banghart 1731: self.close();
1732: }
1733: </script>
1734: ENDSMP
1.63 banghart 1735: $r->print($javascript);
1.47 banghart 1736: $r->print("<h1>Select portfolio files</h1>
1.88 albertel 1737: Check as many as you wish in response to the problem.<br />");
1738: my @otherfiles=&Apache::lonnet::files_not_in_path($env{'user.name'}, $env{'form.currentpath'});
1739: if (@otherfiles) {
1740: $r->print("<strong>Files selected from other directories:</strong><br />");
1741: foreach my $file (@otherfiles) {
1742: $r->print($file."<br />");
1743: }
1.60 banghart 1744: }
1.47 banghart 1745: }
1.138 albertel 1746:
1.24 albertel 1747: sub upload {
1.137 albertel 1748: my ($r,$url,$group)=@_;
1.82 albertel 1749: my $fname=$env{'form.uploaddoc.filename'};
1750: my $filesize = (length($env{'form.uploaddoc'})) / 1000; #express in k (1024?)
1.173 ! raeburn 1751: my $disk_quota;
1.126 raeburn 1752: if (defined($group)) {
1753: my $grp_quota = &get_group_quota($group); # quota expressed in k
1754: if ($grp_quota ne '') {
1755: $disk_quota = $grp_quota;
1756: } else {
1757: $disk_quota = 0;
1758: }
1.173 ! raeburn 1759: } else {
! 1760: $disk_quota = &Apache::loncommon::get_user_quota($env{'user.name'},
! 1761: $env{'user.domain'}); #expressed in Mb
! 1762: $disk_quota = 1000 * $disk_quota; # convert from Mb to kb
1.126 raeburn 1763: }
1.34 banghart 1764: $fname=&Apache::lonnet::clean_filename($fname);
1.146 banghart 1765:
1.138 albertel 1766: my $portfolio_root=&get_portfolio_root();
1767: my ($uname,$udom) = &get_name_dom();
1768: my $port_path = &get_port_path();
1.38 banghart 1769: # Fixme --- Move the checking for existing file to LOND error return
1.138 albertel 1770: my @dir_list=&get_dir_list($portfolio_root);
1.34 banghart 1771: my $found_file = 0;
1.76 banghart 1772: my $locked_file = 0;
1.33 banghart 1773: foreach my $line (@dir_list) {
1.76 banghart 1774: my ($file_name)=split(/\&/,$line,2);
1775: if ($file_name eq $fname){
1.102 raeburn 1776: $file_name = $env{'form.currentpath'}.$file_name;
1.138 albertel 1777: $file_name = &prepend_group($file_name);
1.33 banghart 1778: $found_file = 1;
1.102 raeburn 1779: if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
1.76 banghart 1780: $locked_file = 1;
1781: }
1.33 banghart 1782: }
1783: }
1.94 raeburn 1784: my $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$portfolio_root);
1.87 albertel 1785: if (($current_disk_usage + $filesize) > $disk_quota){
1.116 albertel 1786: $r->print('<span class="LC_error">Unable to upload <strong>'.$fname.' (size = '.$filesize.' kilobytes)</strong>. Disk quota will be exceeded.</span>'.
1.38 banghart 1787: '<br />Disk quota is '.$disk_quota.' kilobytes. Your current disk usage is '.$current_disk_usage.' kilobytes.');
1.137 albertel 1788: $r->print(&done('Back',$url));
1.38 banghart 1789: }
1.76 banghart 1790: elsif ($found_file){
1791: if ($locked_file){
1.116 albertel 1792: $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 1793: '<br />You will be able to rename or delete existing '.$fname.' after a grade has been assigned.');
1.137 albertel 1794: $r->print(&done('Back',$url));
1.76 banghart 1795: } else {
1.116 albertel 1796: $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 1797: '<br />To upload, rename or delete existing '.$fname.' in '.$port_path.$env{'form.currentpath'});
1.137 albertel 1798: $r->print(&done('Back',$url));
1.76 banghart 1799: }
1.33 banghart 1800: } else {
1801: my $result=&Apache::lonnet::userfileupload('uploaddoc','',
1.94 raeburn 1802: $port_path.$env{'form.currentpath'});
1.33 banghart 1803: if ($result !~ m|^/uploaded/|) {
1.116 albertel 1804: $r->print('<span class="LC_error">'.'An errror occured ('.$result.
1805: ') while trying to upload '.&display_file().'</span><br />');
1.137 albertel 1806: $r->print(&done('Back',$url));
1.76 banghart 1807: } else {
1.137 albertel 1808: $r->print(&done(undef,$url));
1.33 banghart 1809: }
1.25 albertel 1810: }
1811: }
1.126 raeburn 1812:
1.80 banghart 1813: sub lock_info {
1.137 albertel 1814: my ($r,$url,$group) = @_;
1.138 albertel 1815: my ($uname,$udom) = &get_name_dom();
1.102 raeburn 1816: my $current_permissions = &Apache::lonnet::get_portfile_permissions($udom,
1817: $uname);
1.84 banghart 1818: my $file_name = $env{'form.lockinfo'};
1.138 albertel 1819: $file_name = &prepend_group($file_name);
1.102 raeburn 1820: if (defined($file_name) && defined($$current_permissions{$file_name})) {
1821: foreach my $array_item (@{$$current_permissions{$file_name}}) {
1.156 albertel 1822: next if (ref($array_item) ne 'ARRAY');
1823:
1824: my $filetext;
1825: if (defined($group)) {
1826: $filetext = '<strong>'.$env{'form.lockinfo'}.
1827: '</strong> (group: '.$group.')';
1828: } else {
1829: $filetext = '<strong>'.$file_name.'</strong>';
1830: }
1831:
1832: my $title ='<strong>'.&Apache::lonnet::gettitle($$array_item[0]).
1833: '</strong><br />';
1834: if ($$array_item[-1] eq 'graded') {
1835: $r->print(&mt('[_1] was submitted in response to problem: [_2]',
1836: $filetext,$title));
1837: } elsif ($$array_item[-1] eq 'handback') {
1838: $r->print(&mt('[_1] was handed back in response to problem: [_2]',
1839: $filetext,$title));
1840: } else {
1841: # submission style lock
1842: $r->print(&mt('[_1] was submitted in response to problem: [_2]',
1843: $filetext,$title));
1844: }
1845: my %course_description =
1846: &Apache::lonnet::coursedescription($$array_item[1]);
1847: if ( $course_description{'description'} ne '') {
1848: $r->print(&mt('In the course: <strong>[_1]</strong><br />',
1849: $course_description{'description'}));
1850: }
1.102 raeburn 1851: }
1.84 banghart 1852: }
1.137 albertel 1853: $r->print(&done('Back',$url));
1.80 banghart 1854: return 'ok';
1855: }
1.138 albertel 1856:
1.25 albertel 1857: sub createdir {
1.138 albertel 1858: my ($r,$url)=@_;
1.82 albertel 1859: my $newdir=&Apache::lonnet::clean_filename($env{'form.newdir'});
1.28 albertel 1860: if ($newdir eq '') {
1.116 albertel 1861: $r->print('<span class="LC_error">'.
1.37 banghart 1862: &mt("Error: no directory name was provided.").
1.116 albertel 1863: '</span><br />');
1.138 albertel 1864: $r->print(&done(undef,$url));
1.37 banghart 1865: return;
1.94 raeburn 1866: }
1.138 albertel 1867: my $portfolio_root = &get_portfolio_root();
1868: my @dir_list=&get_dir_list($portfolio_root);
1.37 banghart 1869: my $found_file = 0;
1870: foreach my $line (@dir_list) {
1871: my ($filename)=split(/\&/,$line,2);
1872: if ($filename eq $newdir){
1873: $found_file = 1;
1874: }
1875: }
1876: if ($found_file){
1.116 albertel 1877: $r->print('<span class="LC_error">'.'Unable to create a directory named <strong>'.$newdir.
1878: ' </strong>a file or directory by that name already exists.</span><br />');
1.37 banghart 1879: } else {
1.138 albertel 1880: my ($uname,$udom) = &get_name_dom();
1881: my $port_path = &get_port_path();
1.94 raeburn 1882: my $result=&Apache::lonnet::mkdiruserfile($uname,$udom,
1883: $port_path.$env{'form.currentpath'}.$newdir);
1.37 banghart 1884: if ($result ne 'ok') {
1.116 albertel 1885: $r->print('<span class="LC_error">'.'An errror occured ('.$result.
1886: ') while trying to create a new directory '.&display_file().'</span><br />');
1.37 banghart 1887: }
1.24 albertel 1888: }
1.82 albertel 1889: if ($newdir ne $env{'form.newdir'}) {
1890: $r->print("The new directory name was changed from:<br /><strong>".$env{'form.newdir'}."</strong> to <strong>$newdir </strong>");
1.67 banghart 1891: }
1.137 albertel 1892: $r->print(&done(undef,$url));
1.94 raeburn 1893: }
1894:
1895: sub get_portfolio_root {
1.163 raeburn 1896: my ($udom,$uname,$group) = @_;
1.160 raeburn 1897: if (!(defined($udom)) || !(defined($uname))) {
1898: ($uname,$udom) = &get_name_dom();
1899: }
1.163 raeburn 1900: my $path = '/userfiles/portfolio';
1901: if (!defined($group)) {
1902: if (defined($env{'form.group'})) {
1903: $group = $env{'form.group'};
1904: }
1.94 raeburn 1905: }
1.163 raeburn 1906: if (defined($group)) {
1907: $path = '/userfiles/groups/'.$group.'/portfolio';
1908: }
1.94 raeburn 1909: return (&Apache::loncommon::propath($udom,$uname).$path);
1910: }
1911:
1.126 raeburn 1912: sub get_group_quota {
1913: my ($group) = @_;
1914: my $group_quota;
1915: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1916: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1917: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum,$group);
1918: if (%curr_groups) {
1919: my %group_info = &Apache::longroup::get_group_settings(
1920: $curr_groups{$group});
1921: $group_quota = $group_info{'quota'}; #expressed in Mb
1922: if ($group_quota) {
1923: $group_quota = 1000 * $group_quota; #expressed in k
1924: }
1925: }
1926: return $group_quota;
1927: }
1928:
1.94 raeburn 1929: sub get_dir_list {
1.138 albertel 1930: my ($portfolio_root) = @_;
1931: my ($uname,$udom) = &get_name_dom();
1.94 raeburn 1932: return &Apache::lonnet::dirlist($env{'form.currentpath'},
1933: $udom,$uname,$portfolio_root);
1934: }
1935:
1936: sub get_name_dom {
1937: my ($uname,$udom);
1.138 albertel 1938: if (defined($env{'form.group'})) {
1.94 raeburn 1939: $udom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1940: $uname = $env{'course.'.$env{'request.course.id'}.'.num'};
1941: } else {
1942: $udom = $env{'user.domain'};
1943: $uname = $env{'user.name'};
1944: }
1945: return ($uname,$udom);
1946: }
1947:
1.102 raeburn 1948: sub prepend_group {
1.138 albertel 1949: my ($filename) = @_;
1950: if (defined($env{'form.group'})) {
1951: $filename = $env{'form.group'}.$filename;
1.102 raeburn 1952: }
1953: return $filename;
1954: }
1955:
1.94 raeburn 1956: sub get_namespace {
1957: my $namespace = 'portfolio';
1.138 albertel 1958: if (defined($env{'form.group'})) {
1959: my ($uname,$udom) = &get_name_dom();
1960: $namespace .= '_'.$udom.'_'.$uname.'_'.$env{'form.group'};
1.94 raeburn 1961: }
1962: return $namespace;
1963: }
1964:
1965: sub get_port_path {
1966: my $port_path;
1.138 albertel 1967: if (defined($env{'form.group'})) {
1968: $port_path = "groups/$env{'form.group'}/portfolio";
1.94 raeburn 1969: } else {
1970: $port_path = 'portfolio';
1971: }
1972: return $port_path;
1.24 albertel 1973: }
1974:
1.120 raeburn 1975: sub missing_priv {
1.138 albertel 1976: my ($r,$url,$priv) = @_;
1.120 raeburn 1977: my $longtext = {
1978: upload => 'upload files',
1979: delete => 'delete files',
1980: rename => 'rename files',
1981: setacl => 'set access controls for files',
1982: };
1983: my $escpath = &HTML::Entities::encode($env{'form.currentpath'},'&<>"');
1984: my $rtnlink = '<a href="'.$url;
1985: if ($url =~ /\?/) {
1986: $rtnlink .= '&';
1987: } else {
1988: $rtnlink .= '?';
1989: }
1990: $rtnlink .= 'currentpath='.$escpath;
1991: $r->print(&mt('<h3>Action disallowed</h3>'));
1992: $r->print(&mt('You do not have sufficient privileges to [_1] ',
1993: $longtext->{$priv}));
1.138 albertel 1994: if (defined($env{'form.group'})) {
1.120 raeburn 1995: $r->print(&mt("in the group's file repository."));
1.137 albertel 1996: $rtnlink .= &group_args()
1.120 raeburn 1997: } else {
1998: $r->print(&mt('in this portfolio.'));
1999: }
2000: $rtnlink .= '">'.&mt('Return to directory listing page').'</a>';
2001: $r->print('<br />'.$rtnlink);
2002: $r->print(&Apache::loncommon::end_page());
2003: return;
2004: }
2005:
1.132 raeburn 2006: sub coursegrp_portfolio_header {
1.137 albertel 2007: my ($cdom,$cnum,$grp_desc)=@_;
1.132 raeburn 2008: my $gpterm = &Apache::loncommon::group_term();
2009: my $ucgpterm = $gpterm;
2010: $ucgpterm =~ s/^(\w)/uc($1)/e;
1.137 albertel 2011: if ($env{'form.ref'}) {
1.136 raeburn 2012: &Apache::lonhtmlcommon::add_breadcrumb
2013: ({href=>"/adm/coursegroups",
2014: text=>"Groups",
2015: title=>"Course Groups"});
2016: }
1.132 raeburn 2017: &Apache::lonhtmlcommon::add_breadcrumb
1.138 albertel 2018: ({href=>"/adm/$cdom/$cnum/$env{'form.group'}/smppg?ref=$env{'form.ref'}",
1.132 raeburn 2019: text=>"$ucgpterm: $grp_desc",
2020: title=>"Go to group's home page"},
1.137 albertel 2021: {href=>"/adm/coursegrp_portfolio?".&group_args(),
1.132 raeburn 2022: text=>"Group Portfolio",
1.136 raeburn 2023: title=>"Display group portfolio"});
1.132 raeburn 2024: my $output = &Apache::lonhtmlcommon::breadcrumbs(
2025: &mt('[_1] portfolio files - [_2]',$gpterm,$grp_desc));
2026: return $output;
2027: }
2028:
2029:
1.24 albertel 2030: sub handler {
2031: # this handles file management
2032: my $r = shift;
1.73 banghart 2033: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.108 raeburn 2034: ['selectfile','currentpath','meta','lockinfo','currentfile','action',
2035: 'fieldname','mode','rename','continue','group','access','setnum',
1.136 raeburn 2036: 'cnum','cdom','type','setroles','showversions','ref']);
1.138 albertel 2037: my ($uname,$udom,$portfolio_root,$url,$caller,$title,$group,$grp_desc);
1.94 raeburn 2038: if ($r->uri =~ m|^(/adm/)([^/]+)|) {
2039: $url = $1.$2;
2040: $caller = $2;
2041: }
1.137 albertel 2042: my ($can_modify,$can_delete,$can_upload,$can_setacl);
1.94 raeburn 2043: if ($caller eq 'coursegrp_portfolio') {
2044: # Needs to be in a course
2045: if (! ($env{'request.course.fn'})) {
2046: # Not in a course
2047: $env{'user.error.msg'}=
2048: "/adm/coursegrp_portfolio:rgf:0:0:Cannot view group portfolio";
2049: return HTTP_NOT_ACCEPTABLE;
2050: }
2051: my $earlyout = 0;
1.136 raeburn 2052: my $view_permission =
2053: &Apache::lonnet::allowed('vcg',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''));
1.137 albertel 2054: $env{'form.group'} =~ s/\W//g;
1.138 albertel 2055: $group = $env{'form.group'};
1.94 raeburn 2056: if ($group) {
1.138 albertel 2057: ($uname,$udom) = &get_name_dom();
1.99 raeburn 2058: my %curr_groups = &Apache::longroup::coursegroups($udom,$uname,
1.98 albertel 2059: $group);
2060: if (%curr_groups) {
1.132 raeburn 2061: my %grp_content = &Apache::longroup::get_group_settings(
2062: $curr_groups{$group});
2063: $grp_desc = &unescape($grp_content{'description'});
1.94 raeburn 2064: if (($view_permission) || (&Apache::lonnet::allowed('rgf',
2065: $env{'request.course.id'}.'/'.$group))) {
1.138 albertel 2066: $portfolio_root = &get_portfolio_root();
1.94 raeburn 2067: } else {
1.116 albertel 2068: $r->print('You do not have the privileges required to access the shared files space for this group.');
1.94 raeburn 2069: $earlyout = 1;
2070: }
2071: } else {
2072: $r->print('Not a valid group for this course');
2073: $earlyout = 1;
2074: }
2075: $title = &mt('Group files').' for '.$group;
2076: } else {
2077: $r->print('Invalid group');
2078: $earlyout = 1;
2079: }
2080: if ($earlyout) { return OK; }
1.126 raeburn 2081: if (&Apache::lonnet::allowed('mdg',$env{'request.course.id'})) {
1.120 raeburn 2082: $can_modify = 1;
2083: $can_delete = 1;
1.126 raeburn 2084: $can_upload = 1;
2085: $can_setacl = 1;
2086: } else {
2087: if (&Apache::lonnet::allowed('agf',$env{'request.course.id'}.'/'.$group)) {
2088: $can_setacl = 1;
2089: }
2090: if (&Apache::lonnet::allowed('ugf',$env{'request.course.id'}.'/'.$group)) {
2091: $can_upload = 1;
2092: }
2093: if (&Apache::lonnet::allowed('mgf',$env{'request.course.id'}.'/'.$group)) {
2094: $can_modify = 1;
2095: }
2096: if (&Apache::lonnet::allowed('dgf',$env{'request.course.id'}.'/'.$group)) {
2097: $can_delete = 1;
2098: }
1.120 raeburn 2099: }
1.94 raeburn 2100: } else {
2101: ($uname,$udom) = &get_name_dom();
2102: $portfolio_root = &get_portfolio_root();
2103: $title = &mt('Portfolio Manager');
1.120 raeburn 2104: $can_modify = 1;
2105: $can_delete = 1;
2106: $can_upload = 1;
2107: $can_setacl = 1;
1.94 raeburn 2108: }
2109:
1.138 albertel 2110: my $port_path = &get_port_path();
1.24 albertel 2111: &Apache::loncommon::no_cache($r);
2112: &Apache::loncommon::content_type($r,'text/html');
2113: $r->send_http_header;
2114: # Give the LON-CAPA page header
1.82 albertel 2115: if ($env{"form.mode"} eq 'selectfile'){
1.96 albertel 2116: $r->print(&Apache::loncommon::start_page($title,undef,
1.97 albertel 2117: {'only_body' => 1}));
1.108 raeburn 2118: } elsif ($env{'form.action'} eq 'rolepicker') {
2119: $r->print(&Apache::loncommon::start_page('New role-based condition',undef,
2120: {'no_nav_bar' => 1, }));
1.74 banghart 2121: } else {
1.97 albertel 2122: $r->print(&Apache::loncommon::start_page($title));
1.74 banghart 2123: }
1.24 albertel 2124: $r->rflush();
1.88 albertel 2125: if (($env{'form.storeupl'}) & (!$env{'form.uploaddoc.filename'})){
1.116 albertel 2126: $r->print('<span class="LC_error">'.
2127: 'No file was selected to upload.'.
2128: 'To upload a file, click <strong>Browse...</strong>'.
2129: ', select a file, then click <strong>Upload</strong>.'.
2130: '</span>');
1.40 banghart 2131: }
1.82 albertel 2132: if ($env{'form.meta'}) {
1.94 raeburn 2133: &open_form($r,$url);
1.82 albertel 2134: # $r->print(&edit_meta_data($r, $env{'form.currentpath'}.$env{'form.selectfile'}));
1.70 banghart 2135: $r->print('Edit the meta data<br />');
1.137 albertel 2136: &close_form($r,$url);
1.70 banghart 2137: }
1.82 albertel 2138: if ($env{'form.store'}) {
1.70 banghart 2139: }
2140:
1.82 albertel 2141: if ($env{'form.uploaddoc.filename'}) {
1.120 raeburn 2142: if ($can_upload) {
1.137 albertel 2143: &upload($r,$url,$group);
1.120 raeburn 2144: } else {
1.138 albertel 2145: &missing_priv($r,$url,'upload');
1.120 raeburn 2146: }
1.82 albertel 2147: } elsif ($env{'form.action'} eq 'delete' && $env{'form.confirmed'}) {
1.120 raeburn 2148: if ($can_delete) {
1.164 raeburn 2149: &delete_confirmed($r,$url,$group);
1.120 raeburn 2150: } else {
1.138 albertel 2151: &missing_priv($r,$url,'delete');
1.120 raeburn 2152: }
1.82 albertel 2153: } elsif ($env{'form.action'} eq 'delete') {
1.120 raeburn 2154: if ($can_delete) {
1.138 albertel 2155: &delete($r,$url);
1.120 raeburn 2156: } else {
1.138 albertel 2157: &missing_priv($r,$url,'delete');
1.120 raeburn 2158: }
1.82 albertel 2159: } elsif ($env{'form.action'} eq 'deletedir' && $env{'form.confirmed'}) {
1.120 raeburn 2160: if ($can_delete) {
1.138 albertel 2161: &delete_dir_confirmed($r,$url);
1.120 raeburn 2162: } else {
1.138 albertel 2163: &missing_priv($r,$url,'delete');
1.120 raeburn 2164: }
2165: } elsif ($env{'form.action'} eq 'deletedir') {
2166: if ($can_delete) {
1.137 albertel 2167: &delete_dir($r,$url);
1.120 raeburn 2168: } else {
1.138 albertel 2169: &missing_priv($r,$url,'delete');
1.120 raeburn 2170: }
1.82 albertel 2171: } elsif ($env{'form.action'} eq 'rename' && $env{'form.confirmed'}) {
1.120 raeburn 2172: if ($can_modify) {
1.164 raeburn 2173: &rename_confirmed($r,$url,$group);
1.120 raeburn 2174: } else {
1.138 albertel 2175: &missing_priv($r,$url,'rename');
1.120 raeburn 2176: }
1.82 albertel 2177: } elsif ($env{'form.rename'}) {
2178: $env{'form.selectfile'} = $env{'form.rename'};
2179: $env{'form.action'} = 'rename';
1.120 raeburn 2180: if ($can_modify) {
1.138 albertel 2181: &rename($r,$url);
1.120 raeburn 2182: } else {
1.138 albertel 2183: &missing_priv($r,$url,'rename');
1.120 raeburn 2184: }
1.104 raeburn 2185: } elsif ($env{'form.access'}) {
2186: $env{'form.selectfile'} = $env{'form.access'};
1.170 raeburn 2187: if (!defined($env{'form.action'})) {
2188: $env{'form.action'} = 'chgaccess';
2189: }
2190: &display_access($r,$url,$group,$can_setacl,$port_path,$env{'form.action'});
2191: } elsif (($env{'form.action'} eq 'chgaccess') ||
2192: ($env{'form.action'} eq 'chgconditions')) {
1.120 raeburn 2193: if ($can_setacl) {
1.137 albertel 2194: &update_access($r,$url,$group,$port_path);
1.120 raeburn 2195: } else {
1.138 albertel 2196: &missing_priv($r,$url,'setacl');
1.120 raeburn 2197: }
1.108 raeburn 2198: } elsif ($env{'form.action'} eq 'rolepicker') {
1.120 raeburn 2199: if ($can_setacl) {
2200: &role_options_window($r);
2201: } else {
1.138 albertel 2202: &missing_priv($r,$url,'setacl');
1.120 raeburn 2203: }
1.82 albertel 2204: } elsif ($env{'form.createdir'}) {
1.120 raeburn 2205: if ($can_upload) {
1.138 albertel 2206: &createdir($r,$url);
1.120 raeburn 2207: } else {
1.138 albertel 2208: &missing_priv($r,$url,'upload');
1.120 raeburn 2209: }
1.82 albertel 2210: } elsif ($env{'form.lockinfo'}) {
1.137 albertel 2211: &lock_info($r,$url,$group);
1.24 albertel 2212: } else {
2213: my $current_path='/';
1.82 albertel 2214: if ($env{'form.currentpath'}) {
2215: $current_path = $env{'form.currentpath'};
1.24 albertel 2216: }
1.132 raeburn 2217: if ($caller eq 'coursegrp_portfolio') {
2218: &Apache::lonhtmlcommon::clear_breadcrumbs();
1.137 albertel 2219: $r->print(&coursegrp_portfolio_header($udom,$uname,$grp_desc));
1.132 raeburn 2220: }
1.138 albertel 2221: my @dir_list=&get_dir_list($portfolio_root);
1.46 albertel 2222: if ($dir_list[0] eq 'no_such_dir'){
2223: # two main reasons for this:
2224: # 1) never been here, so directory structure not created
2225: # 2) back-button navigation after deleting a directory
2226: if ($current_path eq '/'){
1.100 albertel 2227: &Apache::lonnet::mkdiruserfile($uname,$udom,
1.138 albertel 2228: &get_port_path());
1.46 albertel 2229: } else {
2230: # some directory that snuck in get rid of the directory
2231: # from the recent pulldown, just in case
2232: &Apache::lonhtmlcommon::remove_recent('portfolio',
2233: [$current_path]);
2234: $current_path = '/'; # force it back to the root
2235: }
2236: # now grab the directory list again, for the first time
2237: @dir_list=&Apache::lonnet::dirlist($current_path,
1.94 raeburn 2238: $udom,$uname,$portfolio_root);
1.43 banghart 2239: }
1.46 albertel 2240: # need to know if directory is empty so it can be removed if desired
2241: my $is_empty=(@dir_list == 2);
1.137 albertel 2242: &display_common($r,$url,$current_path,$is_empty,\@dir_list,
2243: $can_upload);
1.138 albertel 2244: &display_directory($r,$url,$current_path,$is_empty,\@dir_list,$group,
1.137 albertel 2245: $can_upload,$can_modify,$can_delete,$can_setacl);
1.95 albertel 2246: $r->print(&Apache::loncommon::end_page());
1.30 banghart 2247: }
1.90 albertel 2248: return OK;
1.2 banghart 2249: }
1.120 raeburn 2250:
1.1 banghart 2251: 1;
2252: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>