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