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