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