1: # The LearningOnline Network
2: # portfolio browser
3: #
4: # $Id: portfolio.pm,v 1.267 2023/12/28 15:57:27 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 qw(:DEFAULT :match);
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 filename 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' => 'Create subdirectory in current directory',
95: 'parse' => 'Upload embedded images/multimedia/css/linked files if HTML file',
96: );
97: my $escuri = &HTML::Entities::encode($r->uri,'&<>"');
98: my $help_fileupload = &Apache::loncommon::help_open_topic('Portfolio AddFiles');
99: my $help_createdir = &Apache::loncommon::help_open_topic('Portfolio CreateDirectory');
100: my $help_portfolio = &Apache::loncommon::help_open_topic('Portfolio About', &mt('Help on the portfolio'));
101: $r->print(&display_portfolio_usage($group,$help_portfolio));
102: my $parse_check;
103: if (!&suppress_embed_prompt()) {
104: $parse_check = <<"END";
105: <br />
106: <span class="LC_nobreak">
107: <label>
108: <input type="checkbox" name="parserflag" checked="checked" />
109: $lt{'parse'}
110: </label>
111: </span>
112: END
113: }
114:
115: # Find space available before uploading
116: my $free_space = &free_space($group);
117:
118: # Upload File
119: $r->print('<div class="LC_left_float">'
120: .'<form method="post" enctype="multipart/form-data" action="'.$escuri.'">'
121: .'<fieldset>'
122: .'<legend>'.$lt{'upload_label'}.'</legend>'
123: .$groupitem
124: .'<input name="uploaddoc" type="file" class="LC_flUpload" />'
125: .'<input type="hidden" id="LC_free_space" value="'.$free_space.'" />'
126: .'<input type="hidden" name="currentpath" value="'.$current_path.'" />'
127: .'<input type="hidden" name="action" value="'.$env{"form.action"}.'" />'
128: .'<input type="hidden" name="symb" value="'.$env{"form.symb"}.'" />'
129: .'<input type="hidden" name="fieldname" value="'.$env{"form.fieldname"}.'" />'
130: .'<input type="hidden" name="mode" value="'.$env{"form.mode"}.'" />'
131: .'<input type="submit" name="storeupl" value="'.$lt{'upload'}.'" />'
132: .$help_fileupload
133: .$parse_check
134: .'</fieldset>'
135: .'</form>'
136: .'</div>'
137: );
138: # Create Subdirectory
139: $r->print('<div class="LC_left_float">'
140: .'<form method="post" action="'.$escuri.'">'
141: .'<fieldset>'
142: .'<legend>'.$lt{'createdir_label'}.'</legend>'
143: .'<input name="newdir" type="text" />'.$groupitem
144: .'<input type="hidden" name="currentpath" value="'.$current_path.'" />'
145: .'<input type="hidden" name="action" value="'.$env{"form.action"}.'" />'
146: .'<input type="hidden" name="symb" value="'.$env{"form.symb"}.'" />'
147: .'<input type="hidden" name="fieldname" value="'.$env{"form.fieldname"}.'" />'
148: .'<input type="hidden" name="mode" value="'.$env{"form.mode"}.'" />'
149: .'<input type="submit" name="createdir" value="'.$lt{'createdir'}.'" />'
150: .$help_createdir
151: .'</fieldset>'
152: .'</form>'
153: .'</div>'
154: );
155: } # end "if can_upload"
156:
157: my @tree = split (/\//,$current_path);
158: my %anchor_fields = (
159: 'selectfile' => $port_path,
160: 'currentpath' => '/',
161: 'mode' => $env{"form.mode"},
162: 'symb' => $env{"form.symb"},
163: 'fieldname' => $env{"form.fieldname"},
164: 'continue' => $env{"form.continue"}
165: );
166: $r->print('<br clear="all" />');
167: $r->print('<span class="LC_current_location">'.&make_anchor($url,\%anchor_fields,$port_path).'/');
168: if (@tree > 1){
169: my $newCurrentPath = '/';
170: for (my $i = 1; $i< @tree; $i++){
171: $newCurrentPath .= $tree[$i].'/';
172: my %anchor_fields = (
173: 'selectfile' => $tree[$i],
174: 'currentpath' => $newCurrentPath,
175: 'mode' => $env{"form.mode"},
176: 'symb' => $env{"form.symb"},
177: 'fieldname' => $env{"form.fieldname"},
178: 'continue' => $env{"form.continue"}
179: );
180: $r->print(&make_anchor($url,\%anchor_fields,$tree[$i]).'/');
181: }
182: }
183: $r->print('</span>');
184: $r->print(&Apache::loncommon::help_open_topic('Portfolio ChangeDirectory'));
185: &Apache::lonhtmlcommon::store_recent($namespace,$current_path,$current_path);
186: $r->print('<br /><form method="post" action="'.$url.'?mode='.$env{"form.mode"}.'&fieldname='.$env{"form.fieldname"}.'&symb='.$env{'form.symb'}.&group_args());
187: $r->print('">'.
188: &Apache::lonhtmlcommon::select_recent($namespace,'currentpath',
189: 'this.form.submit();'));
190: $r->print("</form>");
191: }
192:
193: sub display_portfolio_usage {
194: my ($group,$helpitem) = @_;
195: my $disk_quota = &get_quota($group);
196: my $getpropath = 1;
197: my $portfolio_root = &get_portfolio_root();
198: my ($uname,$udom) = &get_name_dom($group);
199: my $current_disk_usage =
200: &Apache::lonnet::diskusage($udom,$uname,$portfolio_root,$getpropath);
201: return &Apache::loncommon::head_subbox(
202: '<div style="float:right;padding-top:0;margin-top;0">'
203: .$helpitem
204: .'</div>'
205: .'<div>'
206: .&Apache::lonhtmlcommon::display_usage($current_disk_usage,
207: $disk_quota,'portfolio')
208: .'</div>');
209: }
210:
211: sub display_directory_line {
212: my ($r,$select_mode, $filename, $mtime, $size, $css_class,
213: $line, $access_controls, $curr_access, $now, $version_flag,
214: $href_location, $url, $current_path, $access_admin_text, $versions)=@_;
215:
216: my $fullpath = &prepend_group($current_path.$filename);
217: $r->print(&Apache::loncommon::start_data_table_row());
218: $r->print($line); # contains first two cells of table
219: my $lock_info;
220: if ($version_flag) { # versioned can't be versioned, so TRUE when root file
221: $r->print('<td><img alt="" src="'.&Apache::loncommon::icon($filename).'" class="LC_fileicon" /></td>');
222: $r->print('<td>'.$version_flag.'</td>');
223: } else { # this is a graded or handed back file
224: my ($user,$domain) = &get_name_dom($env{'form.group'});
225: my $permissions_hash = &Apache::lonnet::get_portfile_permissions($domain,$user);
226: if (defined($$permissions_hash{$fullpath})) {
227: foreach my $array_item (@{$$permissions_hash{$fullpath}}) {
228: if (ref($array_item) eq 'ARRAY') {
229: if ($$array_item[-1] eq 'handback') {
230: $lock_info = 'Handback';
231: } elsif ($$array_item[-1] eq 'graded') {
232: $lock_info = 'Graded';
233: }
234: }
235: }
236: }
237: if ($lock_info) {
238: my %anchor_fields = ('lockinfo' => $fullpath);
239: if ($versions) { # hold the folder open
240: my ($fname,$version,$extension) = &Apache::lonnet::file_name_version_ext($fullpath);
241: $fname =~ s|^/||;
242: $anchor_fields{'showversions'} = $fname.'.'.$extension;
243: }
244: $lock_info = &make_anchor(undef,\%anchor_fields,$lock_info);
245: }
246: $r->print('<td colspan="2">'.$lock_info.'</td>');
247: }
248: # $r->print('<td>'.$$version_flag{$filename}.'</td><td>');
249: $r->print('<td>'.&make_anchor($href_location.$filename,undef,$filename).'</td>');
250: $r->print('<td>'.$size.'</td>');
251: $r->print('<td>'.&Apache::lonlocal::locallocaltime($mtime).'</td>');
252: if ($select_mode ne 'true') {
253: $r->print('<td class="'.$css_class.'"> </td>'); # Display status
254: $r->print('<td><span class="LC_nobreak">'
255: .&mt($curr_access).' '
256: );
257: my %anchor_fields = (
258: 'access' => $filename,
259: 'currentpath' => $current_path
260: );
261: $r->print(&make_anchor($url, \%anchor_fields, $access_admin_text).'</span></td>');
262: } else {
263: $r->print('<td class="'.$css_class.'"> </td>'); # Display status
264: }
265: $r->print(&Apache::loncommon::end_data_table_row().$/);
266: }
267:
268: sub display_directory {
269: my ($r,$url,$current_path,$is_empty,$dir_list,$group,$can_upload,
270: $can_modify,$can_delete,$can_setacl,$can_viewacl)=@_;
271: my $iconpath= $r->dir_config('lonIconsURL') . "/";
272: my $select_mode;
273: my $checked_files;
274: my $port_path = &get_port_path();
275: my ($uname,$udom) = &get_name_dom($group);
276: my $access_admin_text;
277: if ($can_viewacl) {
278: $access_admin_text = &mt('View Status');
279: }
280: if ($can_setacl) {
281: $access_admin_text = &mt('View/Change Status');
282: }
283:
284: my $current_permissions = &Apache::lonnet::get_portfile_permissions($udom,
285: $uname);
286: my %locked_files = &Apache::lonnet::get_marked_as_readonly_hash(
287: $current_permissions,$group);
288: my %access_controls = &Apache::lonnet::get_access_controls($current_permissions,$group);
289: my $now = time;
290: if ($env{"form.mode"} eq 'selectfile') {
291: &select_files($r,$dir_list);
292: $checked_files =&Apache::lonnet::files_in_path($uname,$env{'form.currentpath'});
293: $select_mode = 'true';
294: }
295: if ($select_mode eq 'true') {
296: $r->print('<form method="post" name="checkselect" action="'.$url.'">');
297: $r->print(&Apache::loncommon::start_data_table()
298: .&Apache::loncommon::start_data_table_header_row()
299: .'<th>'.&mt('Select').'</th>'
300: .'<th> </th>'
301: .'<th> </th>'
302: .'<th>'.&mt('Name').'</th>'
303: .'<th>'.&mt('Size').'</th>'
304: .'<th>'.&mt('Last Modified').'</th>'
305: .'<th> </th>'
306: .&Apache::loncommon::end_data_table_header_row()
307: );
308: } else {
309: $r->print('<form method="post" action="'.$url.'">');
310: $r->print(
311: '<p>'
312: .&Apache::loncommon::help_open_topic(
313: 'Portfolio FileList',
314: &mt('Using the portfolio file list'))
315: .'</p>'
316: );
317: $r->print(&Apache::loncommon::start_data_table()
318: .&Apache::loncommon::start_data_table_header_row()
319: .'<th colspan="2">'.&mt('Actions'). &Apache::loncommon::help_open_topic('Portfolio FileAction').'</th>'
320: .'<th> </th>'
321: .'<th> </th>'
322: .'<th>'.&mt('Name').&Apache::loncommon::help_open_topic('Portfolio OpenFile').'</th>'
323: .'<th>'.&mt('Size').'</th>'
324: .'<th>'.&mt('Last Modified').'</th>'
325: .'<th> </th>'
326: .'<th>'.&mt('Current Access Status').&Apache::loncommon::help_open_topic('Portfolio ShareFile').'</th>'
327: .&Apache::loncommon::end_data_table_header_row());
328: }
329:
330: # Empty directory?
331: if ($is_empty && ($current_path ne '/') && $can_delete) {
332: my $cols = ($select_mode eq 'true') ? 7 : 9;
333: # Empty message
334: $r->print(
335: &Apache::loncommon::start_data_table_row()
336: .'<td colspan="'.$cols.'">'
337: .'<p class="LC_info">'
338: .&mt('This directory is empty.')
339: .'</p>'
340: .'</td>'
341: .&Apache::loncommon::end_data_table_row()
342: .&Apache::loncommon::end_data_table()
343: .'</form>'
344: );
345: # Delete button
346: $r->print(
347: '<form method="post" action="'.$url.'">'.
348: &group_form_data().
349: '<input type="hidden" name="action" value="deletedir" />'.
350: '<p>'.
351: '<input type="submit" name="deletedir" value="'.&mt("Delete Directory").'" />'.
352: '</p>'.
353: '<input type="hidden" name="selectfile" value="" />'.
354: '<input type="hidden" name="currentpath" value="'.$current_path.'" />'.
355: '</form>'
356: );
357: # Directory is empty, so nothing else to display
358: return;
359: }
360:
361: $r->print("\n".&group_form_data()."\n");
362:
363: my $href_location="/uploaded/$udom/$uname/$port_path".$current_path;
364: my $href_edit_location="/editupload/$udom/$uname/$port_path".$current_path;
365: my @dir_lines;
366: my %versioned;
367: if (ref($dir_list) eq 'ARRAY') {
368: foreach my $dir_line (sort
369: {
370: my ($afile)=split('&',$a,2);
371: my ($bfile)=split('&',$b,2);
372: return (lc($afile) cmp lc($bfile));
373: } (@{$dir_list})) {
374: my ($filename,$dom,undef,$testdir,undef,undef,undef,undef,$size,undef,$mtime,undef,undef,undef,$obs,undef)=split(/\&/,$dir_line,16);
375: $filename =~ s/\s+$//;
376: my ($fname,$version,$extension) = &Apache::lonnet::file_name_version_ext($filename);
377: if ($version) {
378: my $fullpath = &prepend_group($current_path.$fname.'.'.$extension);
379: push(@{ $versioned{$fullpath} },
380: [$filename,$dom,$testdir,$size,$mtime,$obs,]);
381: } else {
382: push(@dir_lines, [$filename,$dom,$testdir,$size,$mtime,$obs]);
383: }
384: }
385: }
386: my $zerobyte;
387: foreach my $dir_line (@dir_lines) {
388: my ($filename,$dom,$testdir,$size,$mtime,$obs) = @$dir_line;
389: my ($fname,$version,$extension) = &Apache::lonnet::file_name_version_ext($filename);
390: if (($filename ne '.') && ($filename ne '..') && ($filename !~ /\.meta$/ ) && ($filename !~ /(.*)\.(\d+)\.([^\.]*)$/)) {
391: my $version_flag;
392: my $show_versions;
393: my $fullpath = &prepend_group($current_path.$filename);
394: if ($env{'form.showversions'} =~ /$filename/) {
395: $show_versions = 'true';
396: }
397: if (exists($versioned{$fullpath})) {
398: my %anchor_fields = (
399: 'selectfile' => $fullpath,
400: 'continue' => 'false',
401: 'currentpath' => $current_path,
402: );
403: if ($show_versions) {
404: # Must preserve other possible showversion files
405: my $version_remainder = $env{'form.showversions'};
406: $version_remainder =~ s/$filename//g;
407: $anchor_fields{'showversions'} = $version_remainder;
408: $version_flag = &make_anchor('portfolio',\%anchor_fields,
409: '<img class="LC_icon" alt="'.&mt('opened folder').'" src="'.$iconpath.'folder_pointer_opened.gif" />');
410: } else {
411: # allow multiple files to show versioned
412: $anchor_fields{'showversions'} = $env{'form.showversions'}.','.$filename;
413: $version_flag = &make_anchor('portfolio',\%anchor_fields,
414: '<img class="LC_icon" alt="'.&mt('closed folder').'" src="'.$iconpath.'folder_pointer_closed.gif" />');
415: }
416: } else {
417: $version_flag = ' ';
418: }
419: if ($dirptr&$testdir) {
420: my $colspan_folder='';
421: my $colspan_fill='';
422: if ($select_mode eq 'true'){
423: $colspan_fill=' colspan="3"';
424: } else {
425: $colspan_folder=' colspan="2"';
426: $colspan_fill=' colspan="4"';
427: }
428: $r->print('<tr class="LC_browser_folder">');
429: $r->print('<td'.$colspan_folder.'><img alt="'.&mt('closed folder').'" src="'.$iconpath.'navmap.folder.closed.gif" class="LC_fileicon" /></td>'
430: .'<td>'.&mt('Go to ...').'</td>');
431: my %anchor_fields = (
432: 'selectfile' => $filename.'/',
433: 'currentpath' => $current_path.$filename.'/',
434: 'mode' => $env{"form.mode"},
435: 'symb' => $env{"form.symb"},
436: 'fieldname' => $env{"form.fieldname"},
437: 'continue' => $env{"form.continue"}
438: );
439: $r->print('<td>'.$version_flag.'</td>'
440: .'<td>'.&make_anchor($url,\%anchor_fields,$filename.'/').'</td>');
441: $r->print('<td'.$colspan_fill.'> </td>');
442: $r->print('</tr>');
443: } else {
444: my $css_class = 'LC_browser_file';
445: my $line;
446: if ($select_mode eq 'true') {
447: if ($size > 0) {
448: $line='<td><input type="checkbox" name="checkfile" value="'.$filename.'"';
449: if ($$checked_files{$filename} eq 'selected') {
450: $line.=' checked="checked" ';
451: }
452: $line.=' /></td>';
453: } else {
454: $line = '<td> </td>';
455: $zerobyte ++;
456: }
457: } else {
458: if (exists $locked_files{$fullpath}) {
459: my %anchor_fields = (
460: 'lockinfo' => $fullpath
461: );
462: $line.='<td colspan="2">'.&make_anchor($url,\%anchor_fields,&mt('Locked')).'</td>';
463: $css_class= 'LC_browser_file_locked';
464: } else {
465: if (!$can_modify) {
466: $line .= '<td colspan="2">';
467: } else {
468: $line .= '<td>';
469: }
470: if ($can_delete) {
471: $line .= '<input type="checkbox" name="selectfile" value="'.$filename.'" />';
472: }
473: if ($can_modify) {
474: my $cat='<img class="LC_icon" alt="'.&mt('Metadata').'" title="'.&mt('Metadata').'" src="'.&Apache::loncommon::lonhttpdurl('/res/adm/pages/catalog.png').'" />';
475: my %anchor_fields = (
476: 'rename' => $filename,
477: currentpath => $current_path
478: );
479: $line .= &make_anchor($url,\%anchor_fields,&mt('Rename'));
480: $line .= '</td><td>'.&make_anchor($href_edit_location.$filename.'.meta',\%anchor_fields,$cat);
481: # '<a href="'.$href_edit_location.$filename.'.meta">'.$cat.'</a>';
482: }
483: $line .= '</td>';
484: }
485: }
486: my $curr_access;
487: if ($select_mode ne 'true') {
488: my $pub_access = 0;
489: my $guest_access = 0;
490: my $cond_access = 0;
491: foreach my $key (sort(keys(%{$access_controls{$fullpath}}))) {
492: my ($num,$scope,$end,$start) = &unpack_acc_key($key);
493: if (($now > $start) && (!$end || $end > $now)) {
494: if ($scope eq 'public') {
495: $pub_access = 1;
496: } elsif ($scope eq 'guest') {
497: $guest_access = 1;
498: } else {
499: $cond_access = 1;
500: }
501: }
502: }
503: if (!$pub_access && !$guest_access && !$cond_access) {
504: $curr_access = &mt('Private');
505: } else {
506: my @allaccesses;
507: if ($pub_access) {
508: push(@allaccesses,&mt('Public'));
509: }
510: if ($guest_access) {
511: push(@allaccesses,&mt('Passphrase-protected'));
512: }
513: if ($cond_access) {
514: push(@allaccesses,&mt('Conditional'));
515: }
516: $curr_access = join('+ ',@allaccesses);
517: }
518: }
519: &display_directory_line($r,$select_mode, $filename, $mtime, $size, $css_class, $line,
520: \%access_controls, $curr_access, $now, $version_flag, $href_location,
521: $url, $current_path, $access_admin_text);
522: if ($show_versions) {
523: foreach my $dir_line (@{ $versioned{$fullpath} }) {
524: my ($v_filename,$dom,$testdir,$size,$mtime,$obs) =
525: @$dir_line;
526: $line = '<td colspan="2"> </td>';
527: &display_directory_line($r,$select_mode, $v_filename, $mtime, $size,
528: $css_class, $line, \%access_controls, $curr_access, $now,
529: undef, $href_location, $url, $current_path, $access_admin_text, 1);
530: }
531: }
532: }
533: }
534: }
535: if ($select_mode eq 'true') {
536: $r->print(&Apache::loncommon::end_data_table());
537: if ($zerobyte) {
538: $r->print('<p class="LC_warning">'.&mt('[quant,_1,file] in list not selectable as file size is 0 bytes.',$zerobyte).'</p>');
539: }
540: $r->print('
541: <input type="hidden" name="continue" value="true" />
542: <input type="hidden" name="fieldname" value="'.$env{'form.fieldname'}.'" />
543: <input type="hidden" name="symb" value="'.$env{'form.symb'}.'" />
544: <input type="hidden" name="mode" value="selectfile" />
545: <p>
546: <input type="submit" name="submit" value="'.&mt('Select checked files, and continue selecting').'" /><br />
547: <input type="button" name="doit" onclick="finishSelect();" value="'.&mt('Select checked files, and close window').'" />
548: </p>
549: <input type="hidden" name="currentpath" value="'.$current_path.'" />
550: </form>');
551: } else {
552: $r->print(&Apache::loncommon::end_data_table());
553: if ($can_delete) {
554: $r->print('
555: <p>
556: <input type="submit" name="doit" value="'.&mt('Delete Selected').'" />'.
557: &Apache::loncommon::help_open_topic('Portfolio DeleteFile').'
558: </p>
559: <input type="hidden" name="action" value="delete" />
560: <input type="hidden" name="currentpath" value="'.$current_path.'" />
561: </form>'
562: );
563: }
564: }
565: }
566:
567: sub open_form {
568: my ($r,$url)=@_;
569: my @files=&Apache::loncommon::get_env_multiple('form.selectfile');
570: $r->print('<form name="portform" method="post" action="'.$url.'">');
571: $r->print('<input type="hidden" name="action" value="'.
572: $env{'form.action'}.'" />');
573: $r->print('<input type="hidden" name="confirmed" value="1" />');
574: foreach (@files) {
575: $r->print('<input type="hidden" name="selectfile" value="'.
576: $_.'" />');
577: }
578: $r->print('<input type="hidden" name="currentpath" value="'.
579: $env{'form.currentpath'}.'" />');
580: }
581:
582: sub close_form {
583: my ($r,$url,$button_text)=@_;
584: if (!defined($button_text)) {
585: $button_text = {
586: 'continue' => &mt('Continue'),
587: 'cancel' => &mt('Cancel'),
588: };
589: }
590: $r->print('<p><input type="submit" value="'.$button_text->{'continue'}.'" />');
591: $r->print(&group_form_data().'</p></form>');
592: $r->print('<form action="'.$url.'" method="post">
593: <p>
594: <input type="hidden" name="currentpath" value="'.
595: $env{'form.currentpath'}.'" />'.
596: &group_form_data());
597: $r->print("\n".' <input type="submit" value="'.$button_text->{'cancel'}.'" />
598: </p></form>');
599: }
600:
601: sub display_file {
602: my ($path,$filename)=@_;
603: my $display_file_text;
604: my $file_start='<span class="LC_filename">';
605: my $file_end='</span>';
606: if (!defined($path)) { $path=$env{'form.currentpath'}; }
607: if (!defined($filename)) {
608: $filename=$env{'form.selectfile'};
609: $display_file_text = $file_start.$path.$filename.$file_end;
610: } elsif (ref($filename) eq "ARRAY") {
611: foreach my $file (@$filename) {
612: $display_file_text .= $file_start.$path.$file.$file_end.'<br />';
613: }
614: } elsif (ref($filename) eq "SCALAR") {
615: $display_file_text = $file_start.$path.$$filename.$file_end;
616: } else {
617: $display_file_text = $file_start.$path.$filename.$file_end;
618: }
619: return $display_file_text;
620: }
621:
622: sub done {
623: my ($linktext,$url)=@_;
624: unless (defined($linktext)) {
625: $linktext='Return to directory';
626: }
627: my %anchor_fields = (
628: 'showversions' => $env{'form.showversions'},
629: 'currentpath' => $env{'form.currentpath'},
630: 'fieldname' => $env{'form.fieldname'},
631: 'symb' => $env{'form.symb'},
632: 'mode' => $env{'form.mode'}
633: );
634: my $result = &Apache::lonhtmlcommon::actionbox(
635: [&make_anchor($url,\%anchor_fields,&mt($linktext))]);
636: return $result;
637: }
638:
639: sub delete {
640: my ($r,$url,$group)=@_;
641: my @check;
642: my $file_name = $env{'form.currentpath'}.$env{'form.selectfile'};
643: $file_name = &prepend_group($file_name);
644: my @files=&Apache::loncommon::get_env_multiple('form.selectfile');
645: my ($uname,$udom) = &get_name_dom($group);
646: if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
647: $r->print(
648: '<p class="LC_warning">'
649: .&mt('The file is locked and cannot be deleted.')
650: .'</p>'
651: .&done(undef,$url)
652: );
653: } else {
654: if (scalar(@files)) {
655: &open_form($r,$url);
656: $r->print('<p>'.&mt('Delete [_1]?',&display_file(undef,\@files)).'</p>');
657: &close_form($r,$url);
658: } else {
659: $r->print('<p class="LC_warning">'.&mt('No file was checked to delete.').'</p>');
660: $r->print(&done(undef,$url));
661: }
662: }
663: }
664:
665: sub delete_confirmed {
666: my ($r,$url,$group)=@_;
667: my @files=&Apache::loncommon::get_env_multiple('form.selectfile');
668: my $result;
669: my ($uname,$udom) = &get_name_dom($group);
670: my $port_path = &get_port_path();
671: my $current_permissions = &Apache::lonnet::get_portfile_permissions($udom,
672: $uname);
673: my @msg;
674: foreach my $delete_file (@files) {
675: $result =
676: &Apache::lonnet::removeuserfile(
677: $uname,$udom,$port_path.
678: $env{'form.currentpath'}.
679: $delete_file);
680: if ($result ne 'ok') {
681: push(@msg, &Apache::lonhtmlcommon::confirm_success(
682: &mt('An error occurred ([_1]) while trying to delete [_2].'
683: ,$result,&display_file(undef, $delete_file)),1));
684: } else {
685: push(@msg, &Apache::lonhtmlcommon::confirm_success(
686: &mt('File: [_1] deleted.'
687: ,&display_file(undef,$delete_file))));
688: my $file_name = $env{'form.currentpath'}.$delete_file;
689: $file_name = &prepend_group($file_name);
690: my %access_controls =
691: &Apache::lonnet::get_access_controls($current_permissions,
692: $group,$file_name);
693: if (keys(%access_controls) > 0) {
694: my %changes;
695: foreach my $key (keys(%{$access_controls{$file_name}})) {
696: $changes{'delete'}{$key} = 1;
697: }
698: if (keys(%changes) > 0) {
699: my ($outcome,$deloutcome,$new_values,$translation) =
700: &Apache::lonnet::modify_access_controls($file_name,\%changes,
701: $udom,$uname);
702: if ($outcome ne 'ok') {
703: push(@msg, &Apache::lonhtmlcommon::confirm_success(
704: &mt('An error occurred ([_1]) while '.
705: 'trying to delete access controls for the file.',$outcome),1));
706: } else {
707: if ($deloutcome eq 'ok') {
708: push(@msg, &mt('Access controls also deleted for the file.')); # FIXME: Does the user really need this message?
709: } else {
710: push(@msg, &Apache::lonhtmlcommon::confirm_success(
711: &mt('An error occurred ([_1]) while '.
712: 'trying to delete access controls for the file.'
713: ,$deloutcome),1));
714: }
715: }
716: }
717: }
718: }
719: }
720: $r->print(&Apache::loncommon::confirmwrapper(join('<br />',@msg)));
721: $r->print(&done(undef,$url));
722: }
723:
724: sub delete_dir {
725: my ($r,$url)=@_;
726: &open_form($r,$url);
727: $r->print('<p>'.&mt('Delete [_1]?',&display_file()).'</p>');
728: &close_form($r,$url);
729: }
730:
731: sub delete_dir_confirmed {
732: my ($r,$url,$group)=@_;
733: my $directory_name = $env{'form.currentpath'};
734: $directory_name =~ s|/$||; # remove any trailing slash
735: my ($uname,$udom) = &get_name_dom($group);
736: my $namespace = &get_namespace();
737: my $port_path = &get_port_path();
738: my $result=&Apache::lonnet::removeuserfile($uname,$udom,$port_path.
739: $directory_name);
740:
741: if ($result ne 'ok') {
742: $r->print(
743: &Apache::loncommon::confirmwrapper(
744: &Apache::lonhtmlcommon::confirm_success(
745: &mt('An error occurred (dir) ([_1]) while trying to delete [_2].'
746: ,$result,$directory_name),1)));
747: $r->print(&done(undef,$url));
748: return;
749: } else {
750: # now remove from recent
751: &Apache::lonhtmlcommon::remove_recent($namespace,[$directory_name.'/']);
752: my @dirs = split m!/!, $directory_name;
753: $directory_name='/';
754: for (my $i=1; $i < (@dirs - 1); $i ++){
755: $directory_name .= $dirs[$i].'/';
756: }
757: $env{'form.currentpath'} = $directory_name;
758: }
759: $r->print(
760: &Apache::loncommon::confirmwrapper(
761: &Apache::lonhtmlcommon::confirm_success(
762: &mt('Directory successfully deleted'))));
763: $r->print(&done(undef,$url));
764: }
765:
766: sub rename {
767: my ($r,$url,$group)=@_;
768: my $file_name = $env{'form.currentpath'}.$env{'form.rename'};
769: my ($uname,$udom) = &get_name_dom($group);
770: $file_name = &prepend_group($file_name);
771: if (&Apache::lonnet::is_locked($file_name,$udom,$uname) eq 'true') {
772: $r->print(
773: '<p class="LC_error">'
774: .&mt('The file is locked and cannot be renamed.')
775: .'</p>'
776: );
777: $r->print(&done(undef,$url));
778: } else {
779: &open_form($r,$url);
780: $r->print('<p>'.&mt('Rename [_1] to [_2]?', &display_file()
781: , '<input name="filenewname" type="text" size="50" />').'</p>');
782: &close_form($r,$url);
783: }
784: }
785:
786: sub rename_confirmed {
787: my ($r,$url,$group)=@_;
788: my $filenewname=&Apache::lonnet::clean_filename($env{'form.filenewname'});
789: my ($uname,$udom) = &get_name_dom($group);
790: my $port_path = &get_port_path();
791:
792: # Display warning in case of filename cleaning has changed the filename
793: if ($filenewname ne $env{'form.filenewname'}) {
794: $r->print(
795: '<p><span class="LC_warning">'
796: .&mt('Invalid characters')
797: .'</span><br />'
798: .&mt('The new filename was changed from [_1] to [_2].'
799: ,'<span class="LC_filename">'.&display_file('',$env{'form.filenewname'}).'</span>'
800: ,'<span class="LC_filename">'.&display_file('',$filenewname).'</span>')
801: .'</p>'
802: );
803:
804: }
805:
806: # Filename empty?
807: if ($filenewname eq '') {
808: $r->print(
809: &Apache::loncommon::confirmwrapper(
810: &Apache::lonhtmlcommon::confirm_success(
811: &mt('Error: no valid filename was provided to rename to.'),1)));
812: $r->print(&done(undef,$url));
813: return;
814: }
815:
816: # Rename the file
817: my $chg_access;
818: my $result=
819: &Apache::lonnet::renameuserfile($uname,$udom,
820: $port_path.$env{'form.currentpath'}.$env{'form.selectfile'},
821: $port_path.$env{'form.currentpath'}.$filenewname);
822: if ($result eq 'ok') {
823: $chg_access = &access_for_renamed($filenewname,$group,$udom,$uname);
824: } else {
825: $r->print(
826: &Apache::loncommon::confirmwrapper(
827: &Apache::lonhtmlcommon::confirm_success(
828: &mt('An error occurred ([_1]) while trying to rename [_2] to [_3].'
829: ,$result,&display_file(),&display_file('',$filenewname))
830: ,1)));
831: $r->print(&done(undef,$url));
832: return;
833: }
834: $r->print($chg_access);
835: $r->print(
836: &Apache::loncommon::confirmwrapper(
837: &Apache::lonhtmlcommon::confirm_success(
838: &mt('File successfully renamed'))));
839: $r->print(&done(undef,$url));
840: }
841:
842: sub access_for_renamed {
843: my ($filenewname,$group,$udom,$uname) = @_;
844: my $oldfile = $env{'form.currentpath'}.$env{'form.selectfile'};
845: $oldfile = &prepend_group($oldfile);
846: my $newfile = $env{'form.currentpath'}.$filenewname;
847: $newfile = &prepend_group($newfile);
848: my $current_permissions =
849: &Apache::lonnet::get_portfile_permissions($udom,$uname);
850: my %access_controls =
851: &Apache::lonnet::get_access_controls($current_permissions,
852: $group,$oldfile);
853: my $chg_text;
854: if (keys(%access_controls) > 0) {
855: my %change_old;
856: my %change_new;
857: foreach my $key (keys(%{$access_controls{$oldfile}})) {
858: $change_old{'delete'}{$key} = 1;
859: $change_new{'activate'}{$key} = $access_controls{$oldfile}{$key};
860: }
861: my ($outcome,$deloutcome,$new_values,$translation) =
862: &Apache::lonnet::modify_access_controls($oldfile,\%change_old,
863: $udom,$uname);
864: if ($outcome ne 'ok') {
865: $chg_text ='<br /><br />'.&mt("An error occurred ([_1]) while ".
866: "trying to delete access control records for the old name.",$outcome).
867: '</span><br />';
868: } else {
869: if ($deloutcome ne 'ok') {
870: $chg_text = '<br /><br /><span class="LC_error"><br />'.
871: &mt("An error occurred ([_1]) while ".
872: "trying to delete access control records for the old name.",$deloutcome).
873: '</span><br />';
874: }
875: }
876: ($outcome,$deloutcome,$new_values,$translation) =
877: &Apache::lonnet::modify_access_controls($newfile,\%change_new,
878: $udom,$uname);
879: if ($outcome ne 'ok') {
880: $chg_text .= '<br /><br />'.
881: &mt("An error occurred ([_1]) while ".
882: "trying to update access control records for the new name.",$outcome).
883: '</span><br />';
884: }
885: if ($chg_text eq '') {
886: $chg_text = '<br /><br />'.&mt('Access controls updated to reflect the name change.');
887: }
888: }
889: return $chg_text;
890: }
891:
892: sub display_access {
893: my ($r,$url,$group,$can_setacl,$can_viewacl,$port_path,$action) = @_;
894: my ($uname,$udom) = &get_name_dom($group);
895: my $file_name = $env{'form.currentpath'}.$env{'form.access'};
896: $file_name = &prepend_group($file_name);
897: my $current_permissions = &Apache::lonnet::get_portfile_permissions($udom,
898: $uname);
899: my %access_controls = &Apache::lonnet::get_access_controls($current_permissions,$group,$file_name);
900: my $aclcount = keys(%access_controls);
901: my ($header,$info);
902: if ($action eq 'chgaccess') {
903: my $uhome = &Apache::lonnet::homeserver($uname,$udom);
904: my $prefix = &Apache::lonnet::url_prefix($r,$udom,$uhome,'web');
905: $header =
906: '<h2>'
907: .&mt('Allowing others to retrieve file: [_1]'
908: ,'<span class="LC_filename">'
909: .$port_path.$env{'form.currentpath'}.$env{'form.access'}
910: .'</span>')
911: .'</h2>';
912: $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.');
913: $info .= '<br /><ul><li>'.&mt('Public files are available to anyone without the need for login.');
914: $info .= '</li><li>'.&mt('Passphrase-protected files do not require log-in, but will require the viewer to enter the passphrase you set.');
915: $info .= '</li><li>'.&explain_conditionals();
916: $info .= '</li></ul>'.
917: &mt('A listing of files viewable without log-in is available at: ')."<a href=\"$prefix/adm/$udom/$uname/aboutme/portfolio\">$prefix/adm/$udom/$uname/aboutme/portfolio</a>.<br />";
918: if ($group eq '') {
919: $info .= &mt("For logged in users a 'Display file listing' link will also appear (when there are viewable files) on your personal information page:");
920: } else {
921: $info .= &mt("For logged in users a 'Display file listing' link will also appear (when there are viewable files) on the course information page:");
922: }
923: $info .= "<br /><a href=\"$prefix/adm/$udom/$uname/aboutme\">$prefix/adm/$udom/$uname/aboutme</a><br />";
924: if ($group ne '') {
925: $info .= &mt("Users with course editing rights may add a 'Group Portfolio' item using the Course Editor (Collaboration tab), to provide access to viewable group portfolio files.").'<br />';
926: }
927: } else {
928: $header = '<h3>'.&mt('Conditional access controls for file: [_1]',$port_path.$env{'form.currentpath'}.$env{'form.access'}).'</h3>'.
929: &explain_conditionals().'<br />';
930: }
931: if ($can_setacl) {
932: &open_form($r,$url);
933: $r->print($header.$info);
934: $r->print('<br />'.&Apache::loncommon::help_open_topic('Portfolio ShareFile SetAccess', &mt('Help on setting up share access')));
935: $r->print(&Apache::loncommon::help_open_topic('Portfolio ShareFile ChangeSetting', &mt('Help on changing settings')));
936: $r->print(&Apache::loncommon::help_open_topic('Portfolio ShareFile StopAccess', &mt('Help on removing share access')));
937: &access_setting_table($r,$url,$file_name,$access_controls{$file_name},
938: $action);
939: my $button_text = {
940: 'continue' => &mt('Proceed'),
941: 'cancel' => &mt('Return to directory'),
942: };
943: &close_form($r,$url,$button_text);
944: } elsif ($can_viewacl) {
945: $r->print($header);
946: if ($aclcount) {
947: $r->print($info);
948: }
949: &view_access_settings($r,$url,$access_controls{$file_name},$aclcount);
950: } else {
951: $r->print($header);
952: $r->print(&mt('You do not have sufficient privileges to view access controls').'<br />');
953: }
954: my %anchor_fields = (
955: 'currentpath' => $env{'form.currentpath'}
956: );
957: $r->print('<br />'.&make_anchor($url, \%anchor_fields, &mt('Return to directory')));
958: return;
959: }
960:
961: sub explain_conditionals {
962: return
963: &mt('Conditional files are accessible to users who satisfy the conditions you set.').'<br /><ul>'.
964: '<li>'.&mt('Conditions can be IP-based, in which case no log-in is required').'</li>'.
965: '<li>'.&mt("Conditions can also be based on a user's status, in which case the user needs an account in the LON-CAPA network, and needs to be logged in.").'<br />'."\n".
966: &mt('The status-based conditions can include affiliation with a particular course or community, or a user account in a specific domain.').'<br />'."\n".
967: &mt('Alternatively access can be granted to people with specific LON-CAPA usernames and domains.').'</li></ul>';
968: }
969:
970: sub view_access_settings {
971: my ($r,$url,$access_controls,$aclcount) = @_;
972: my ($showstart,$showend);
973: my %todisplay;
974: foreach my $key (sort(keys(%{$access_controls}))) {
975: my ($num,$scope,$end,$start) = &unpack_acc_key($key);
976: $todisplay{$scope}{$key} = $$access_controls{$key};
977: }
978: if ($aclcount) {
979: $r->print('<h4>'.&mt('Current access controls defined for this file:').'</h4>');
980: $r->print(&Apache::loncommon::start_data_table());
981: $r->print(&Apache::loncommon::start_data_table_header_row());
982: $r->print('<th>'.&mt('Access control').'</th><th>'.&mt('Dates available').
983: '</th><th>'.&mt('Additional information').'</th>');
984: $r->print(&Apache::loncommon::end_data_table_header_row());
985: my $count = 1;
986: my $chg = 'none';
987: &build_access_summary($r,$count,$chg,%todisplay);
988: $r->print(&Apache::loncommon::end_data_table());
989: } else {
990: $r->print(&mt('No access control settings currently exist for this file.').'<br />');
991: }
992: my %anchor_fields = (
993: 'currentpath' => $env{'form.currentpath'}
994: );
995: $r->print('<br />'.&make_anchor($url, \%anchor_fields, &mt('Return to directory')));
996: return;
997: }
998:
999: sub build_access_summary {
1000: my ($r,$count,$chg,%todisplay) = @_;
1001: my ($showstart,$showend);
1002: my %scope_desc = (
1003: public => 'Public',
1004: guest => 'Passphrase-protected',
1005: domains => 'Conditional: domain-based',
1006: users => 'Conditional: user-based',
1007: course => 'Conditional: course/community-based',
1008: ip => 'Conditional: IP-based',
1009: );
1010: my @allscopes = ('public','guest','domains','users','course','ip');
1011: foreach my $scope (@allscopes) {
1012: if ((!(exists($todisplay{$scope}))) || (ref($todisplay{$scope}) ne 'HASH')) {
1013: next;
1014: }
1015: foreach my $key (sort(keys(%{$todisplay{$scope}}))) {
1016: if ($count) {
1017: $r->print(&Apache::loncommon::start_data_table_row());
1018: }
1019: my ($num,$scope,$end,$start) = &unpack_acc_key($key);
1020: my $content = $todisplay{$scope}{$key};
1021: if ($chg eq 'delete') {
1022: $showstart = &mt('Deleted');
1023: $showend = $showstart;
1024: } else {
1025: $showstart = &Apache::lonlocal::locallocaltime($start);
1026: if ($end == 0) {
1027: $showend = &mt('No end date');
1028: } else {
1029: $showend = &Apache::lonlocal::locallocaltime($end);
1030: }
1031: }
1032: $r->print('<td>'.&mt($scope_desc{$scope}));
1033: my $crstype;
1034: if ($scope eq 'course') {
1035: if ($chg ne 'delete') {
1036: my $cid = $content->{'domain'}.'_'.$content->{'number'};
1037: my %course_description = &Apache::lonnet::coursedescription($cid);
1038: $r->print('<br />('.$course_description{'description'}.')');
1039: $crstype = 'Course';
1040: if ($course_description{'type'} ne '') {
1041: $crstype = $course_description{'type'};
1042: }
1043: }
1044: }
1045: $r->print('</td><td>'.&mt('Start: ').$showstart.
1046: '<br />'.&mt('End: ').$showend.'</td><td>');
1047: if ($chg ne 'delete') {
1048: if ($scope eq 'guest') {
1049: $r->print(&mt('Passphrase').': '.$content->{'password'});
1050: } elsif ($scope eq 'course') {
1051: $r->print('<table width="100%"><tr>');
1052: $r->print('<th>'.&mt('Roles').'</th><th>'.
1053: &mt('Access').'</th><th>'.
1054: &mt('Sections').'</th>');
1055: $r->print('<th>'.&mt('Groups').'</th>');
1056: $r->print('</tr>');
1057: foreach my $id (sort(keys(%{$content->{'roles'}}))) {
1058: $r->print('<tr>');
1059: foreach my $item ('role','access','section','group') {
1060: $r->print('<td>');
1061: if ($item eq 'role') {
1062: my $role_output;
1063: foreach my $role (@{$content->{'roles'}{$id}{$item}}) {
1064: if ($role eq 'all') {
1065: $role_output .= $role.',';
1066: } elsif ($role =~ /^cr/) {
1067: $role_output .= (split('/',$role))[3].',';
1068: } else {
1069: $role_output .= &Apache::lonnet::plaintext($role,$crstype).',';
1070: }
1071: }
1072: $role_output =~ s/,$//;
1073: $r->print($role_output);
1074: } else {
1075: $r->print(join(',',@{$content->{'roles'}{$id}{$item}}));
1076: }
1077: $r->print('</td>');
1078: }
1079: $r->print('</tr>');
1080: }
1081: $r->print('</table>');
1082: } elsif ($scope eq 'domains') {
1083: $r->print(&mt('Domains: ').join(',',@{$content->{'dom'}}));
1084: } elsif ($scope eq 'users') {
1085: my $curr_user_list = &sort_users($content->{'users'});
1086: $r->print(&mt('Users: ').$curr_user_list);
1087: } elsif ($scope eq 'ip') {
1088: my $curr_ips_list = &sort_ips($content->{'ip'});
1089: $r->print(&mt('IP(s):').' '.$curr_ips_list);
1090: } else {
1091: $r->print(' ');
1092: }
1093: } else {
1094: $r->print(' ');
1095: }
1096: $r->print('</td>');
1097: $r->print(&Apache::loncommon::end_data_table_row());
1098: $count ++;
1099: }
1100: }
1101: }
1102:
1103:
1104: sub update_access {
1105: my ($r,$url,$group,$port_path) = @_;
1106: my $totalprocessed = 0;
1107: my %processing;
1108: my %title = (
1109: 'activate' => 'New control(s) added',
1110: 'delete' => 'Existing control(s) deleted',
1111: 'update' => 'Existing control(s) modified',
1112: );
1113: my $changes;
1114: foreach my $chg (sort(keys(%title))) {
1115: @{$processing{$chg}} = &Apache::loncommon::get_env_multiple('form.'.$chg);
1116: $totalprocessed += @{$processing{$chg}};
1117: foreach my $num (@{$processing{$chg}}) {
1118: my $scope = $env{'form.scope_'.$num};
1119: my ($start,$end) = &get_dates_from_form($num);
1120: my $newkey = $num.':'.$scope.'_'.$end.'_'.$start;
1121: if ($chg eq 'delete') {
1122: $$changes{$chg}{$newkey} = 1;
1123: } else {
1124: $$changes{$chg}{$newkey} =
1125: &build_access_record($num,$scope,$start,$end,$chg);
1126: }
1127: }
1128: }
1129: my $file_name = $env{'form.currentpath'}.$env{'form.selectfile'};
1130: $r->print('<h2>'.&mt('Allowing others to retrieve file: [_1]',
1131: '<span class="LC_filename">'.$port_path.$file_name.'</span>').'</h2>'."\n");
1132: $file_name = &prepend_group($file_name);
1133: my ($uname,$udom) = &get_name_dom($group);
1134: my ($errors,$outcome,$deloutcome,$new_values,$translation);
1135: if ($totalprocessed) {
1136: ($outcome,$deloutcome,$new_values,$translation) =
1137: &Apache::lonnet::modify_access_controls($file_name,$changes,$udom,
1138: $uname);
1139: }
1140: my $current_permissions = &Apache::lonnet::get_portfile_permissions($udom,
1141: $uname);
1142: my %access_controls =
1143: &Apache::lonnet::get_access_controls($current_permissions,
1144: $group,$file_name);
1145: if ($totalprocessed) {
1146: if ($outcome eq 'ok') {
1147: my $updated_controls = $access_controls{$file_name};
1148: my ($showstart,$showend);
1149: $r->print(&Apache::loncommon::start_data_table());
1150: $r->print(&Apache::loncommon::start_data_table_header_row());
1151: $r->print('<th>'.&mt('Type of change').'</th><th>'.
1152: &mt('Access control').'</th><th>'.&mt('Dates available').
1153: '</th><th>'.&mt('Additional information').'</th>');
1154: $r->print(&Apache::loncommon::end_data_table_header_row());
1155: foreach my $chg (sort(keys(%processing))) {
1156: if (@{$processing{$chg}} > 0) {
1157: if ($chg eq 'delete') {
1158: if (!($deloutcome eq 'ok')) {
1159: $errors .='<span class="LC_error">'.
1160: &mt('A problem occurred deleting access controls: [_1]',$deloutcome).
1161: '</span>';
1162: next;
1163: }
1164: }
1165: my $numchgs = @{$processing{$chg}};
1166: $r->print(&Apache::loncommon::start_data_table_row());
1167: $r->print('<td rowspan="'.$numchgs.'">'.&mt($title{$chg}).
1168: '.</td>');
1169: my $count = 0;
1170: my %todisplay;
1171: foreach my $key (sort(keys(%{$$changes{$chg}}))) {
1172: my ($num,$scope,$end,$start) = &unpack_acc_key($key);
1173: my $newkey = $key;
1174: if ($chg eq 'activate') {
1175: $newkey =~ s/^(\d+)/$$translation{$1}/;
1176: }
1177: $todisplay{$scope}{$newkey} = $$updated_controls{$newkey};
1178: }
1179: &build_access_summary($r,$count,$chg,%todisplay);
1180: }
1181: }
1182: $r->print(&Apache::loncommon::end_data_table());
1183: } else {
1184: if ((@{$processing{'activate'}} > 0) || (@{$processing{'update'}} > 0)) {
1185: $errors .= '<span class="LC_error">'.
1186: &mt('A problem occurred saving access control settings: [_1]',$outcome).
1187: '</span>';
1188: }
1189: }
1190: if ($errors) {
1191: $r->print($errors);
1192: }
1193: }
1194: my $allnew = 0;
1195: my $totalnew = 0;
1196: my $status = 'new';
1197: my ($firstitem,$lastitem);
1198: my @types = ('course','domains','users','ip');
1199: foreach my $newitem (@types) {
1200: $allnew += $env{'form.new'.$newitem};
1201: }
1202: if ($allnew > 0) {
1203: my $now = time;
1204: my $then = $now + (60*60*24*180); # six months approx.
1205: &open_form($r,$url);
1206: my %showtypes = (
1207: course => 'course/community',
1208: domains => 'domain',
1209: users => 'user',
1210: ip => 'IP',
1211: );
1212: foreach my $newitem (@types) {
1213: next if ($env{'form.new'.$newitem} <= 0);
1214: $r->print(
1215: '<p>'
1216: .&mt('Add new [_1]'.$showtypes{$newitem}.'-based[_2] access control for portfolio file: [_3]',
1217: '<b>','</b>',
1218: '<span class="LC_filename"><b>'
1219: .$env{'form.currentpath'}.$env{'form.selectfile'}.'</b></span>')
1220: .'</p>');
1221: $firstitem = $totalnew;
1222: $lastitem = $totalnew + $env{'form.new'.$newitem};
1223: $totalnew = $lastitem;
1224: my @numbers;
1225: for (my $i=$firstitem; $i<$lastitem; $i++) {
1226: push(@numbers,$i);
1227: }
1228: &display_access_row($r,$status,$newitem,\@numbers,
1229: $access_controls{$file_name},$now,$then);
1230: }
1231: &close_form($r,$url);
1232: } else {
1233: my %anchor_fields = (
1234: 'currentpath' => $env{'form.currentpath'},
1235: 'access' => $env{'form.selectfile'}
1236: );
1237: my @actions;
1238: push(@actions, &make_anchor($url, \%anchor_fields, &mt('Display all access settings for this file')));
1239: delete $anchor_fields{'access'};
1240: push(@actions, &make_anchor($url,\%anchor_fields,&mt('Return to directory')));
1241: $r->print('<br />'.&Apache::lonhtmlcommon::actionbox(\@actions));
1242: }
1243: return;
1244: }
1245:
1246: sub build_access_record {
1247: my ($num,$scope,$start,$end,$chg) = @_;
1248: my $record = {
1249: type => $scope,
1250: time => {
1251: start => $start,
1252: end => $end
1253: },
1254: };
1255:
1256: if ($scope eq 'guest') {
1257: $record->{'password'} = $env{'form.password'};
1258: } elsif ($scope eq 'course') {
1259: $record->{'domain'} = $env{'form.crsdom_'.$num};
1260: $record->{'number'} = $env{'form.crsnum_'.$num};
1261: my @role_ids;
1262: my @delete_role_ids =
1263: &Apache::loncommon::get_env_multiple('form.delete_role_'.$num);
1264: my @preserves =
1265: &Apache::loncommon::get_env_multiple('form.preserve_role_'.$num);
1266: if (@delete_role_ids) {
1267: foreach my $id (@preserves) {
1268: if (grep {$_ = $id} (@delete_role_ids)) {
1269: next;
1270: }
1271: push(@role_ids,$id);
1272: }
1273: } else {
1274: push(@role_ids,@preserves);
1275: }
1276:
1277: my $next_id = $env{'form.add_role_'.$num};
1278: if ($next_id) {
1279: push(@role_ids,$next_id);
1280: }
1281:
1282: foreach my $id (@role_ids) {
1283: my (@roles,@accesses,@sections,@groups);
1284: if (($id == $next_id) && ($chg eq 'update')) {
1285: @roles = split(/,/,$env{'form.role_'.$num.'_'.$next_id});
1286: @accesses = split(/,/,$env{'form.access_'.$num.'_'.$next_id});
1287: @sections = split(/,/,$env{'form.section_'.$num.'_'.$next_id});
1288: @groups = split(/,/,$env{'form.group_'.$num.'_'.$next_id});
1289: } else {
1290: @roles = &Apache::loncommon::get_env_multiple('form.role_'.$num.'_'.$id);
1291: @accesses = &Apache::loncommon::get_env_multiple('form.access_'.$num.'_'.$id);
1292: @sections = &Apache::loncommon::get_env_multiple('form.section_'.$num.'_'.$id);
1293: @groups = &Apache::loncommon::get_env_multiple('form.group_'.$num.'_'.$id);
1294: }
1295: $record->{'roles'}{$id}{'role'} = \@roles;
1296: $record->{'roles'}{$id}{'access'} = \@accesses;
1297: $record->{'roles'}{$id}{'section'} = \@sections;
1298: $record->{'roles'}{$id}{'group'} = \@groups;
1299: }
1300: } elsif ($scope eq 'domains') {
1301: my @doms = &Apache::loncommon::get_env_multiple('form.dom_'.$num);
1302: $record->{'dom'} = \@doms;
1303: } elsif ($scope eq 'users') {
1304: my $userlist = $env{'form.users_'.$num};
1305: $userlist =~ s/\s+//sg;
1306: my %userhash = map { ($_,1) } (split(/,/,$userlist));
1307: foreach my $user (keys(%userhash)) {
1308: my ($uname,$udom) = split(/:/,$user);
1309: push(@{$record->{'users'}}, {
1310: 'uname' => $uname,
1311: 'udom' => $udom
1312: });
1313: }
1314: } elsif ($scope eq 'ip') {
1315: my $ipslist = $env{'form.ips_'.$num};
1316: $ipslist =~ s/\s+//sg;
1317: my %ipshash = map { ($_,1) } (split(/,/,$ipslist));
1318: foreach my $ip (keys(%ipshash)) {
1319: push(@{$record->{'ip'}},$ip);
1320: }
1321: }
1322: return $record;
1323: }
1324:
1325: sub get_dates_from_form {
1326: my ($id) = @_;
1327: my $startdate;
1328: my $enddate;
1329: $startdate = &Apache::lonhtmlcommon::get_date_from_form('startdate_'.$id);
1330: $enddate = &Apache::lonhtmlcommon::get_date_from_form('enddate_'.$id);
1331: if ( exists ($env{'form.noend_'.$id}) ) {
1332: $enddate = 0;
1333: }
1334: return ($startdate,$enddate);
1335: }
1336:
1337: sub sort_users {
1338: my ($users) = @_;
1339: my @curr_users = map {
1340: $_->{'uname'}.':'.$_->{'udom'}
1341: } (@{$users});
1342: my $curr_user_list = join(",\n",sort(@curr_users));
1343: return $curr_user_list;
1344: }
1345:
1346: sub sort_ips {
1347: my ($ips) = @_;
1348: if (ref($ips) eq 'ARRAY') {
1349: return join(",\n",sort(@{$ips}));
1350: }
1351: }
1352:
1353: sub access_setting_table {
1354: my ($r,$url,$filename,$access_controls,$action) = @_;
1355: my ($public,$publictext);
1356: $publictext ='Off';
1357: my ($guest,$guesttext);
1358: $guesttext = 'Off';
1359: my @courses = ();
1360: my @domains = ();
1361: my @users = ();
1362: my @ips = ();
1363: my $now = time;
1364: my $then = $now + (60*60*24*180); # six months approx.
1365: my ($num,$scope,$publicnum,$guestnum);
1366: my (%acl_count,%end,%start,%conditionals);
1367: foreach my $key (sort(keys(%{$access_controls}))) {
1368: ($num,$scope,$end{$key},$start{$key}) = &unpack_acc_key($key);
1369: if ($scope eq 'public') {
1370: $public = $key;
1371: $publicnum = $num;
1372: $publictext = &acl_status($start{$key},$end{$key},$now);
1373: } elsif ($scope eq 'guest') {
1374: $guest=$key;
1375: $guestnum = $num;
1376: $guesttext = &acl_status($start{$key},$end{$key},$now);
1377: } else {
1378: $conditionals{$scope}{$key} = $$access_controls{$key};
1379: if ($scope eq 'course') {
1380: push(@courses,$key);
1381: } elsif ($scope eq 'domains') {
1382: push(@domains,$key);
1383: } elsif ($scope eq 'users') {
1384: push(@users,$key);
1385: } elsif ($scope eq 'ip') {
1386: push(@ips,$key);
1387: }
1388: }
1389: $acl_count{$scope} ++;
1390: }
1391: $r->print('<table border="0"><tr><td valign="top">');
1392: if ($action eq 'chgaccess') {
1393: &standard_settings($r,$now,$then,$url,$filename,\%acl_count,\%start,
1394: \%end,$public,$publicnum,$publictext,$guest,$guestnum,
1395: $guesttext,$access_controls,%conditionals);
1396: } else {
1397: &condition_setting($r,$access_controls,$now,$then,\%acl_count,
1398: \@domains,\@users,\@courses,\@ips);
1399: }
1400: $r->print('</td></tr></table>');
1401: }
1402:
1403: sub standard_settings {
1404: my ($r,$now,$then,$url,$filename,$acl_count,$start,$end,$public,$publicnum,
1405: $publictext,$guest,$guestnum,$guesttext,$access_controls,%conditionals)=@_;
1406: $r->print('<h3>'.&mt('Public access: [_1]',&mt($publictext)).'</h3>');
1407: $r->print(&Apache::loncommon::start_data_table());
1408: $r->print(&Apache::loncommon::start_data_table_header_row());
1409: $r->print('<th>'.&mt('Action').'</th><th>'.&mt('Dates available').'</th>');
1410: $r->print(&Apache::loncommon::end_data_table_header_row());
1411: $r->print(&Apache::loncommon::start_data_table_row());
1412: if ($public) {
1413: $r->print('<td>'.&actionbox('old',$publicnum,'public').'</td><td>'.
1414: &dateboxes($publicnum,$start->{$public},$end->{$public}).'</td>');
1415: } else {
1416: $r->print('<td>'.&actionbox('new','0','public').'</td><td>'.
1417: &dateboxes('0',$now,$then).'</td>');
1418: }
1419: $r->print(&Apache::loncommon::end_data_table_row());
1420: $r->print(&Apache::loncommon::end_data_table());
1421: $r->print('</td><td width="40"> </td><td valign="top">');
1422: $r->print('<h3>'.&mt('Passphrase-protected access: [_1]',&mt($guesttext)).'</h3>');
1423: $r->print(&Apache::loncommon::start_data_table());
1424: $r->print(&Apache::loncommon::start_data_table_header_row());
1425: $r->print('<th>'.&mt('Action').'</th><th>'.&mt('Dates available').
1426: '</th><th>'. &mt('Passphrase').'</th>');
1427: $r->print(&Apache::loncommon::end_data_table_header_row());
1428: $r->print(&Apache::loncommon::start_data_table_row());
1429: my $passwd;
1430: if ($guest) {
1431: $passwd = $$access_controls{$guest}{'password'};
1432: $r->print('<td>'.&actionbox('old',$guestnum,'guest').'</td><td>'.
1433: &dateboxes($guestnum,$start->{$guest},$end->{$guest}).'</td>');
1434: } else {
1435: $r->print('<td>'.&actionbox('new','1','guest').'</td><td>'.
1436: &dateboxes('1',$now,$then).'</td>');
1437: }
1438: $r->print('<td><input type="text" size="15" name="password" value="'.
1439: $passwd.'" /></td>');
1440: $r->print(&Apache::loncommon::end_data_table_row());
1441: $r->print(&Apache::loncommon::end_data_table());
1442: $r->print('</td></tr><tr><td colspan="3"> </td></tr>'.
1443: '<tr><td colspan="3" valign="top">');
1444: my $numconditionals = 0;
1445: my $conditionstext;
1446: my %cond_status;
1447: foreach my $scope ('domains','users','course','ip') {
1448: $numconditionals += $acl_count->{$scope};
1449: if ($acl_count->{$scope} > 0) {
1450: if ($conditionstext ne 'Active') {
1451: foreach my $key (keys(%{$conditionals{$scope}})) {
1452: $conditionstext = &acl_status($start->{$key},$end->{$key},$now);
1453: if ($conditionstext eq 'Active') {
1454: last;
1455: }
1456: }
1457: }
1458: }
1459: }
1460: if ($conditionstext eq '') {
1461: $conditionstext = 'Off';
1462: }
1463: my %anchor_fields = (
1464: 'access' => $env{'form.selectfile'},
1465: 'action' => 'chgconditions',
1466: 'currentpath' => $env{'form.currentpath'},
1467: );
1468: $r->print('<h3>'.&mt('Conditional access: [_1]',&mt($conditionstext)).'</h3>');
1469: if ($numconditionals > 0) {
1470: my $count = 1;
1471: my $chg = 'none';
1472: $r->print(&mt('You have previously set [_1] conditional access controls.',$numconditionals).' '.&make_anchor($url,\%anchor_fields,&mt('Change Conditions')).'<br /><br />');
1473: $r->print(&Apache::loncommon::start_data_table());
1474: $r->print(&Apache::loncommon::start_data_table_header_row());
1475: $r->print('<th>'.&mt('Access control').'</th><th>'.&mt('Dates available').
1476: '</th><th>'.&mt('Additional information').'</th>');
1477: $r->print(&Apache::loncommon::end_data_table_header_row());
1478: &build_access_summary($r,$count,$chg,%conditionals);
1479: $r->print(&Apache::loncommon::end_data_table());
1480: } else {
1481: $r->print(&make_anchor($url,\%anchor_fields,&mt('Add conditional access')).' '.&mt("based on domain, username, course/community affiliation or user's IP address."));
1482: }
1483: }
1484:
1485: sub condition_setting {
1486: my ($r,$access_controls,$now,$then,$acl_count,$domains,$users,$courses,$ips) = @_;
1487: $r->print('<tr><td valign="top">');
1488: &access_element($r,'domains',$acl_count,$domains,$access_controls,$now,$then);
1489: $r->print('</td><td> </td><td valign="top">');
1490: &access_element($r,'users',$acl_count,$users,$access_controls,$now,$then);
1491: $r->print('</td></tr><tr><td colspan="3"></td></tr><tr><td valign="top">');
1492: &access_element($r,'course',$acl_count,$courses,$access_controls,$now,$then);
1493: $r->print('</td><td> </td><td valign="top">');
1494: &access_element($r,'ip',$acl_count,$ips,$access_controls,$now,$then);
1495: $r->print('</td></tr></table>');
1496: }
1497:
1498: sub acl_status {
1499: my ($start,$end,$now) = @_;
1500: if ($start > $now) {
1501: return 'Inactive';
1502: }
1503: if ($end && $end<$now) {
1504: return 'Inactive';
1505: }
1506: return 'Active';
1507: }
1508:
1509: sub access_element {
1510: my ($r,$type,$acl_count,$items,$access_controls,$now,$then) = @_;
1511: my %typetext = (
1512: domains => 'Domain',
1513: users => 'User',
1514: course => 'Course/Community',
1515: ip => 'IP',
1516: );
1517: $r->print('<h3>'.&mt($typetext{$type}.'-based conditional access:').' ');
1518: if ($$acl_count{$type}) {
1519: $r->print(&mt('[quant,_1,condition]',$$acl_count{$type}));
1520: } else {
1521: $r->print(&mt('Off'));
1522: }
1523: $r->print('</h3>');
1524: &display_access_row($r,'old',$type,$items,$access_controls,$now,$then);
1525: return;
1526: }
1527:
1528: sub display_access_row {
1529: my ($r,$status,$type,$items,$access_controls,$now,$then) = @_;
1530: my ($showtype, $infotype);
1531: if ($type eq 'course') {
1532: $showtype = &mt('Courses/Communities');
1533: $infotype = 'Course/Community';
1534: } elsif ($type eq 'domains') {
1535: $showtype = &mt('Domains');
1536: $infotype = 'Domain';
1537: } elsif ($type eq 'users') {
1538: $showtype = &mt('Users');
1539: $infotype = 'User';
1540: } elsif ($type eq 'ip') {
1541: $showtype = &mt('IP-based');
1542: $infotype = 'IP';
1543: }
1544: if (@{$items} > 0) {
1545: my @all_doms;
1546: my $colspan = 3;
1547: $r->print(&Apache::loncommon::start_data_table());
1548: $r->print(&Apache::loncommon::start_data_table_header_row());
1549: $r->print('<th>'.&mt('Action?').'</th><th>'.$showtype.'</th><th>'.
1550: &mt('Dates available').'</th>');
1551: if ($type eq 'course' && $status eq 'old') {
1552: $r->print('<th>'.&mt('Allowed course/community affiliations').
1553: '</th>');
1554: $colspan ++;
1555: } elsif ($type eq 'domains') {
1556: @all_doms = sort(&Apache::lonnet::all_domains());
1557: }
1558: $r->print(&Apache::loncommon::end_data_table_header_row());
1559: foreach my $key (@{$items}) {
1560: $r->print(&Apache::loncommon::start_data_table_row());
1561: if ($type eq 'course') {
1562: &course_row($r,$status,$type,$key,$access_controls,$now,$then);
1563: } elsif ($type eq 'domains') {
1564: &domains_row($r,$status,$key,\@all_doms,$access_controls,$now,
1565: $then);
1566: } elsif ($type eq 'users') {
1567: &users_row($r,$status,$key,$access_controls,$now,$then);
1568: } elsif ($type eq 'ip') {
1569: &ips_row($r,$status,$key,$access_controls,$now,$then);
1570: }
1571: $r->print(&Apache::loncommon::end_data_table_row());
1572: }
1573: if ($status eq 'old') {
1574: $r->print(&Apache::loncommon::start_data_table_row());
1575: $r->print('<td colspan="',$colspan.'">'.&additional_item($type).
1576: '</td>');
1577: $r->print(&Apache::loncommon::end_data_table_row());
1578: }
1579: $r->print(&Apache::loncommon::end_data_table());
1580: } else {
1581: $r->print(
1582: '<p class="LC_info">'
1583: .&mt('No '.$infotype.'-based conditions defined')
1584: .'</p>'
1585: .&additional_item($type)
1586: );
1587: }
1588: return;
1589: }
1590:
1591: sub course_js {
1592: return qq|
1593: <script type="text/javascript">
1594: // <![CDATA[
1595: function setRoleOptions(num,roleid,cdom,cnum,type) {
1596: updateIndexNum = getIndexByValue('update',num);
1597: var addItem = 'add_role_'+num;
1598: var addIndexNum = getIndexByName(addItem);
1599: if (document.portform.elements[addItem].checked) {
1600: document.portform.elements[updateIndexNum].checked = true;
1601: var url = '/adm/portfolio?action=rolepicker&setroles='+num+'_'+roleid+'&cnum='+cnum+'&cdom='+cdom+'&type='+type;
1602: var title = 'Roles_Chooser';
1603: var options = 'scrollbars=1,resizable=1,menubar=0';
1604: options += ',width=700,height=600';
1605: rolebrowser = open(url,title,options,'1');
1606: rolebrowser.focus();
1607: } else {
1608: addArray = new Array ('role','access','section','group');
1609: for (var j=0;j<addArray.length;j++) {
1610: var itemIndex = getIndexByName(addArray[j]+'_'+num+'_'+roleid);
1611: document.portform.elements[itemIndex].value = '';
1612: }
1613: }
1614: }
1615:
1616: function getIndexByName(item) {
1617: for (var i=0;i<document.portform.elements.length;i++) {
1618: if (document.portform.elements[i].name == item) {
1619: return i;
1620: }
1621: }
1622: return -1;
1623: }
1624:
1625: function getIndexByValue(name,value) {
1626: for (var i=0;i<document.portform.elements.length;i++) {
1627: if (document.portform.elements[i].name == name && document.portform.elements[i].value == value) {
1628: return i;
1629: }
1630: }
1631: return -1;
1632: }
1633:
1634: // ]]>
1635: </script>
1636: |;
1637: }
1638:
1639: sub course_row {
1640: my ($r,$status,$type,$item,$access_controls,$now,$then) = @_;
1641: my $content;
1642: my $defdom = $env{'user.domain'};
1643: if ($status eq 'old') {
1644: $content = $$access_controls{$item};
1645: $defdom = $content->{'domain'};
1646: }
1647: my $js = &Apache::loncommon::coursebrowser_javascript($defdom)
1648: .&course_js();
1649: my $showtype = &mt('Course/Community');
1650: my $crstype = 'Course';
1651: my ($num,$scope,$end,$start) = &set_identifiers($status,$item,$now,$then,
1652: $type);
1653: $r->print('<td>'.$js.&actionbox($status,$num,$scope).'</td>');
1654: if ($status eq 'old') {
1655: my $cid = $content->{'domain'}.'_'.$content->{'number'};
1656: my %course_description = &Apache::lonnet::coursedescription($cid);
1657: if ($course_description{'type'} ne '') {
1658: $crstype = $course_description{'type'};
1659: }
1660: $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>');
1661: } elsif ($status eq 'new') {
1662: $r->print('<td>'.&Apache::loncommon::selectcourse_link('portform','crsnum_'.$num,'crsdom_'.$num,'description_'.$num,$num.'_1',undef,$showtype).' <input type="text" name="description_'.$num.'" size="30" /><input type="hidden" name="crsdom_'.$num.'" /><input type="hidden" name="crsnum_'.$num.'" /></td>');
1663: }
1664: $r->print('<td>'.&dateboxes($num,$start,$end));
1665: my $newrole_id = 1;
1666: if ($status eq 'old') {
1667: $r->print('</td><td>');
1668: my $max_id = 0;
1669: if (keys(%{$content->{'roles'}}) > 0) {
1670: $r->print('<table><tr><th>'.&mt('Action').'</th>'.
1671: '<th>'.&mt('Roles').'</th>'.
1672: '<th>'.&mt('Access').'</th>'.
1673: '<th>'.&mt('Sections').'</th>'.
1674: '<th>'.&mt('Groups').'</th></tr>');
1675: foreach my $role_id (sort(keys(%{$content->{'roles'}}))) {
1676: if ($role_id > $max_id) {
1677: $max_id = $role_id;
1678: }
1679: $max_id ++;
1680: my $role_selects = &role_selectors($num,$role_id,$crstype,$content,'display');
1681: $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>');
1682: }
1683: $r->print('</table>');
1684: }
1685: $r->print('<br />'.&mt('Add a roles-based condition').
1686: ' <input type="checkbox" name="add_role_'.
1687: $num.'" onclick="javascript:setRoleOptions('."'$num',
1688: '$max_id','$content->{'domain'}','$content->{'number'}',
1689: '$showtype'".')" value="" />');
1690: $newrole_id = $max_id;
1691: } else {
1692: $r->print('<input type="hidden" name="add_role_'.$num.'" value="" />');
1693: }
1694: $r->print(&add_course_role($num,$newrole_id));
1695: $r->print('</td>');
1696: return;
1697: }
1698:
1699: sub add_course_role {
1700: my ($num,$max_id) = @_;
1701: my $output;
1702: $output .='<input type="hidden" name="role_'.$num.'_'.$max_id.'" />'.
1703: '<input type="hidden" name="access_'.$num.'_'.$max_id.'" />'.
1704: '<input type="hidden" name="section_'.$num.'_'.$max_id.'" />'.
1705: '<input type="hidden" name="group_'.$num.'_'.$max_id.'" />';
1706: return $output;
1707: }
1708:
1709: sub domains_row {
1710: my ($r,$status,$item,$all_doms,$access_controls,$now,$then) = @_;
1711: my ($num,$scope,$end,$start) = &set_identifiers($status,$item,$now,$then,
1712: 'domains');
1713: my $dom_select = '<select name="dom_'.$num.'" size="4" multiple="multiple">'.
1714: ' <option value="">'.&mt('Please select').'</option>';
1715: if ($status eq 'old') {
1716: my $content = $$access_controls{$item};
1717: foreach my $dom (@{$all_doms}) {
1718: if ((@{$content->{'dom'}} > 0)
1719: && (grep(/^\Q$dom\E$/,@{$content->{'dom'}}))) {
1720: $dom_select .= '<option value="'.$dom.'" selected="selected">'.
1721: $dom.'</option>';
1722: } else {
1723: $dom_select .= '<option value="'.$dom.'">'.$dom.'</option>';
1724: }
1725: }
1726: } else {
1727: foreach my $dom (@{$all_doms}) {
1728: $dom_select .= '<option value="'.$dom.'">'.$dom.'</option>';
1729: }
1730: }
1731: $dom_select .= '</select>';
1732: $r->print('<td>'.&actionbox($status,$num,$scope).'</td><td>'.$dom_select.
1733: '</td><td>'.&dateboxes($num,$start,$end).'</td>');
1734: }
1735:
1736: sub users_row {
1737: my ($r,$status,$item,$access_controls,$now,$then) = @_;
1738: my ($num,$scope,$end,$start) = &set_identifiers($status,$item,$now,$then,
1739: 'users');
1740: my $curr_user_list;
1741: if ($status eq 'old') {
1742: my $content = $$access_controls{$item};
1743: $curr_user_list = &sort_users($content->{'users'});
1744: }
1745: $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>');
1746: }
1747:
1748: sub ips_row {
1749: my ($r,$status,$item,$access_controls,$now,$then) = @_;
1750: my ($num,$scope,$end,$start) = &set_identifiers($status,$item,$now,$then,
1751: 'ip');
1752: my $curr_ips_list;
1753: if ($status eq 'old') {
1754: my $content = $$access_controls{$item};
1755: $curr_ips_list = &sort_ips($content->{'ip'});
1756: }
1757: $r->print('<td>'.&actionbox($status,$num,$scope).'</td><td>'.&mt('Format for IP controls').'<br />'.
1758: &mt('[_1] or [_2] or [_3] or [_4] or [_5]','<tt>35.8.*</tt>','<tt>35.8.3.[34-56]</tt>',
1759: '<tt>*.msu.edu</tt>','<tt>35.8.3.34</tt>','<tt>somehostname.pa.msu.edu</tt>').'<br />'.
1760: &mt('Use a comma to separate different ranges.').'</br/>'.
1761: '<textarea name="ips_'.$num.'" cols="30" rows="5">'.$curr_ips_list.'</textarea></td>'.
1762: '<td>'.&dateboxes($num,$start,$end).'</td>');
1763: }
1764:
1765: sub additional_item {
1766: my ($type) = @_;
1767: my $showtype;
1768: if ($type eq 'course') {
1769: $showtype = 'course/community';
1770: } elsif ($type eq 'domains') {
1771: $showtype = 'domain';
1772: } elsif ($type eq 'users') {
1773: $showtype = 'user';
1774: } elsif ($type eq 'ip') {
1775: $showtype = 'IP';
1776: }
1777: return
1778: &mt('Add new '.$showtype.'-based condition(s)?')
1779: .' '.&mt('Number to add: ')
1780: .'<input type="text" name="new'.$type.'" size="3" value="0" />';
1781: }
1782:
1783: sub actionbox {
1784: my ($status,$num,$scope) = @_;
1785: my $output = '<span class="LC_nobreak"><label>';
1786: if ($status eq 'new') {
1787: my $checkstate;
1788: if ($scope eq 'domains' || $scope eq 'users' || $scope eq 'course' || $scope eq 'ip') {
1789: $checkstate = 'checked="checked"';
1790: }
1791: $output .= '<input type="checkbox" name="activate" value="'.$num.'" '.
1792: $checkstate.' />'.
1793: &mt('Activate');
1794: } else {
1795: $output .= '<input type="checkbox" name="delete" value="'.$num.
1796: '" />'.&mt('Delete').'</label></span><br /><span class="LC_nobreak">'.
1797: '<label><input type="checkbox" name="update" value="'.
1798: $num.'" />'.&mt('Update');
1799: }
1800: $output .= '</label></span><input type="hidden" name="scope_'.$num.'" value="'.$scope.'" />';
1801: return $output;
1802: }
1803:
1804: sub dateboxes {
1805: my ($num,$start,$end) = @_;
1806: my $noend;
1807: if ($end == 0) {
1808: $noend = 'checked="checked"';
1809: }
1810: my $startdate = &Apache::lonhtmlcommon::date_setter('portform',
1811: 'startdate_'.$num,$start,undef,undef,undef,1,undef,
1812: undef,undef,1);
1813: my $enddate = &Apache::lonhtmlcommon::date_setter('portform',
1814: 'enddate_'.$num,$end,undef,undef,undef,1,undef,
1815: undef,undef,1). ' <span class="LC_nobreak"><label>'.
1816: '<input type="checkbox" name="noend_'.
1817: $num.'" '.$noend.' />'.&mt('No end date').
1818: '</label></span>';
1819:
1820: my $output = &mt('Start: ').$startdate.'<br />'.&mt('End: ').$enddate;
1821: return $output;
1822: }
1823:
1824: sub unpack_acc_key {
1825: my ($acc_key) = @_;
1826: my ($num,$scope,$end,$start) = ($acc_key =~ /^([^:]+):([a-z]+)_(\d*)_?(\d*)$/);
1827: return ($num,$scope,$end,$start);
1828: }
1829:
1830: sub set_identifiers {
1831: my ($status,$item,$now,$then,$scope) = @_;
1832: if ($status eq 'old') {
1833: return(&unpack_acc_key($item));
1834: } else {
1835: return($item,$scope,$then,$now);
1836: }
1837: }
1838:
1839: sub role_selectors {
1840: my ($num,$role_id,$type,$content,$caller) = @_;
1841: my ($output,$cdom,$cnum,$longid);
1842: if ($caller eq 'display') {
1843: $longid = '_'.$num.'_'.$role_id;
1844: $cdom = $$content{'domain'};
1845: $cnum = $$content{'number'};
1846: } elsif ($caller eq 'rolepicker') {
1847: $cdom = $env{'form.cdom'};
1848: $cnum = $env{'form.cnum'};
1849: }
1850: my $crstype = 'Course';
1851: if ($cnum =~ /^$match_community$/) {
1852: $crstype = 'Community'
1853: }
1854: my ($sections,$groups,$allroles,$rolehash,$accesshash) =
1855: &Apache::loncommon::get_secgrprole_info($cdom,$cnum,1,$crstype);
1856: if (!@{$sections}) {
1857: @{$sections} = ('none');
1858: } else {
1859: unshift(@{$sections},('all','none'));
1860: }
1861: if (!@{$groups}) {
1862: @{$groups} = ('none');
1863: } else {
1864: unshift(@{$groups},('all','none'));
1865: }
1866: my @allacesses = sort(keys(%{$accesshash}));
1867: my (%sectionhash,%grouphash);
1868: foreach my $sec (@{$sections}) {
1869: $sectionhash{$sec} = $sec;
1870: }
1871: foreach my $grp (@{$groups}) {
1872: $grouphash{$grp} = $grp;
1873: }
1874: my %lookup = (
1875: 'role' => $rolehash,
1876: 'access' => $accesshash,
1877: 'section' => \%sectionhash,
1878: 'group' => \%grouphash,
1879: );
1880: my @allaccesses = sort(keys(%{$accesshash}));
1881: my %allitems = (
1882: 'role' => $allroles,
1883: 'access' => \@allaccesses,
1884: 'section' => $sections,
1885: 'group' => $groups,
1886: );
1887: foreach my $item ('role','access','section','group') {
1888: $output .= '<td><select name="'.$item.$longid.'" multiple="multiple" size="4">'."\n";
1889: foreach my $entry (@{$allitems{$item}}) {
1890: if ($caller eq 'display') {
1891: if ((@{$$content{'roles'}{$role_id}{$item}} > 0) &&
1892: (grep(/^\Q$entry\E$/,@{$$content{'roles'}{$role_id}{$item}}))) {
1893: $output .= ' <option value="'.$entry.'" selected="selected">'.
1894: $lookup{$item}{$entry}.'</option>';
1895: next;
1896: }
1897: }
1898: $output .= ' <option value="'.$entry.'">'.
1899: $lookup{$item}{$entry}.'</option>';
1900: }
1901: $output .= '</select>';
1902: }
1903: $output .= '</td>';
1904: return $output;
1905: }
1906:
1907: sub role_options_window {
1908: my ($r) = @_;
1909: my $type = $env{'form.type'};
1910: my $rolenum = $env{'form.setroles'};
1911: my ($num,$role_id) = ($rolenum =~ /^([\d_]+)_(\d+)$/);
1912: my $role_elements;
1913: foreach my $item ('role','access','section','group') {
1914: $role_elements .= "'".$item.'_'.$rolenum."',";
1915: }
1916: $role_elements =~ s/,$//;
1917: my $role_selects = &role_selectors($num,$role_id,$type,undef,
1918: 'rolepicker');
1919: $r->print(<<"END_SCRIPT");
1920: <script type="text/javascript">
1921: function setRoles() {
1922: var role_elements = new Array($role_elements);
1923: for (var i=0; i<role_elements.length; i++) {
1924: var copylist = '';
1925: for (var j=0; j<document.rolepicker.elements[i].length; j++) {
1926: if (document.rolepicker.elements[i].options[j].selected) {
1927: copylist = copylist + document.rolepicker.elements[i].options[j].value + ',';
1928: }
1929: }
1930: copylist = copylist.substr(0,copylist.length-1);
1931: var openerItem = getIndexByName(role_elements[i]);
1932: opener.document.portform.elements[openerItem].value = copylist;
1933: }
1934: var roleAdder = getIndexByName('add_role_$num');
1935: opener.document.portform.elements[roleAdder].value = '$role_id';
1936: self.close();
1937: }
1938:
1939: function getIndexByName(item) {
1940: for (var i=0;i<opener.document.portform.elements.length;i++) {
1941: if (opener.document.portform.elements[i].name == item) {
1942: return i;
1943: }
1944: }
1945: return -1;
1946: }
1947:
1948: </script>
1949: END_SCRIPT
1950: $r->print(
1951: '<p>'
1952: .&mt('Select roles, '.lc($type).' status, section(s) and group(s) for users'
1953: .' who will be able to access the portfolio file.')
1954: .'</p>'
1955: );
1956: $r->print(
1957: '<form name="rolepicker" action="/adm/portfolio" method="post">'
1958: .'<table><tr>'
1959: .'<th>'.&mt('Roles').'</th>'
1960: .'<th>'.&mt("$type status").'</th>'
1961: .'<th>'.&mt('Sections').'</th>'
1962: .'<th>'.&mt('Groups').'</th>'
1963: .'</tr><tr>'.$role_selects.'</tr>'
1964: .'</table><br />'
1965: .'<input type="button" name="rolepickbutton" value="'.&mt('Save').'" onclick="setRoles()" />'
1966: );
1967: return;
1968: }
1969:
1970: sub select_files {
1971: my ($r,$dir_list) = @_;
1972: if ($env{'form.continue'} eq 'true') {
1973: # here we update the selections for the currentpath
1974: # eventually, have to handle removing those not checked, but . . .
1975: my @items=&Apache::loncommon::get_env_multiple('form.checkfile');
1976: if (scalar(@items)){
1977: my @ok_items;
1978: if (ref($dir_list) eq 'ARRAY') {
1979: foreach my $dir_line (@{$dir_list}) {
1980: my ($filename,undef,undef,undef,undef,undef,undef,undef,$size)=split(/\&/,$dir_line,10);
1981: if (grep(/^\Q$filename\E$/,@items)) {
1982: if ($size) {
1983: push(@ok_items,$filename);
1984: }
1985: }
1986: }
1987: }
1988: &Apache::lonnet::save_selected_files($env{'user.name'}, $env{'form.currentpath'}, @ok_items);
1989: }
1990: } else {
1991: #empty the file for a fresh start
1992: &Apache::lonnet::clear_selected_files($env{'user.name'});
1993: }
1994: my @files = &Apache::lonnet::files_not_in_path($env{'user.name'}, $env{'form.currentpath'});
1995: my $java_files = join ",", @files;
1996: if ($java_files) {
1997: $java_files.=',';
1998: }
1999: my $javascript =(<<ENDSMP);
2000: <script type="text/javascript">
2001: function finishSelect() {
2002: ENDSMP
2003: $javascript .= 'fileList = "'.$java_files.'";';
2004: $javascript .= (<<ENDSMP);
2005: for (i=0;i<document.forms.checkselect.length;i++) {
2006: if (document.forms.checkselect[i].checked){
2007: fileList = fileList + document.forms.checkselect.currentpath.value + document.forms.checkselect[i].value + "," ;
2008: }
2009: }
2010: var hwfield = opener.document.getElementsByName('$env{'form.fieldname'}');
2011: hwfield[0].value = fileList;
2012: self.close();
2013: }
2014: </script>
2015: ENDSMP
2016: $r->print($javascript);
2017: $r->print("<h1>".&mt('Select portfolio files')."</h1>");
2018: my @otherfiles=&Apache::lonnet::files_not_in_path($env{'user.name'}, $env{'form.currentpath'});
2019: if (@otherfiles) {
2020: $r->print(&Apache::loncommon::start_data_table()
2021: .&Apache::loncommon::start_data_table_header_row()
2022: .'<th>'.&mt('Files selected from other directories:')."</th>"
2023: .&Apache::loncommon::end_data_table_header_row()
2024: );
2025: foreach my $file (@otherfiles) {
2026: $r->print(&Apache::loncommon::start_data_table_row()
2027: .'<td>'.$file."</td>"
2028: .&Apache::loncommon::end_data_table_row()
2029: );
2030: }
2031: $r->print(&Apache::loncommon::end_data_table()
2032: .'<br />'
2033: );
2034: }
2035: $r->print('<div>'
2036: .&mt('Check as many files as you wish in response to the problem:')
2037: .'</div>'
2038: );
2039: }
2040:
2041: sub upload {
2042: my ($r,$url,$group)=@_;
2043: my $formname = 'uploaddoc';
2044: my $fname = &Apache::lonnet::clean_filename($env{'form.'.$formname.'.filename'});
2045: my ($state,$msg);
2046: if ($fname eq '') {
2047: $r->print(
2048: &Apache::loncommon::confirmwrapper(
2049: &Apache::lonhtmlcommon::confirm_success(
2050: &mt('Invalid filename: [_1]; the name of the uploaded file did not contain any letters, '.
2051: 'so after eliminating special characters there was nothing left.',
2052: '<span class="LC_filename">'.$env{'form.uploaddoc.filename'}.'</span>'),1)));
2053:
2054: $r->print(&done(undef,$url));
2055: return;
2056: }
2057: my $disk_quota = &get_quota($group);
2058: my $portfolio_root = &get_portfolio_root();
2059: my $port_path = &get_port_path();
2060: my ($uname,$udom) = &get_name_dom($group);
2061: my $getpropath = 1;
2062: my $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$portfolio_root,$getpropath);
2063: ($state,$msg) =
2064: &Apache::loncommon::check_for_upload($env{'form.currentpath'},$fname,
2065: $group,$formname,$portfolio_root,
2066: $port_path,$disk_quota,
2067: $current_disk_usage,$uname,$udom);
2068: if ($state eq 'will_exceed_quota'
2069: || $state eq 'file_locked'
2070: || $state eq 'zero_bytes') {
2071: $r->print($msg.&done(undef,$url));
2072: return;
2073: }
2074:
2075: my (%allfiles,%codebase,$mode,$mimetype);
2076: if ($env{'form.'.$formname.'.filename'} =~ m/(\.htm|\.html|\.shtml)$/i) {
2077: if ($env{'form.parserflag'}) {
2078: $mode = 'parse';
2079: }
2080: }
2081: my $context;
2082: if ($state eq 'existingfile') {
2083: $context = $state;
2084: }
2085: my $subdir = $port_path.$env{'form.currentpath'};
2086: $subdir =~ s{(/)$}{};
2087: my ($result,$timestamp) =
2088: &Apache::lonnet::userfileupload($formname,$context,$subdir,
2089: $mode,\%allfiles,\%codebase,undef,undef,
2090: undef,undef,undef,undef,\$mimetype);
2091: if ($state eq 'existingfile') {
2092: my $group_elem;
2093: my $rootdir = $r->dir_config('lonDaemons').'/tmp/overwrites';
2094: if ($group eq '') {
2095: $rootdir .= '/'.$env{'user.domain'}.'/'.$env{'user.name'};
2096: } else {
2097: $rootdir .= '/'.$env{'course.'.$env{'request.course.id'}.'.domain'}.
2098: '/'.$env{'course.'.$env{'request.course.id'}.'.num'};
2099: $group_elem = '<input type="hidden" name="group" value="'.$group.'" />';
2100: }
2101: if (($result eq $rootdir.'/'.$port_path.$env{'form.currentpath'}.$fname) && ($timestamp =~ /^\d+$/)) {
2102: my $showfname = &HTML::Entities::encode($fname,'&<>"');
2103: my %lt = &Apache::lonlocal::texthash (
2104: over => 'Overwrite existing file?',
2105: yes => 'Yes',
2106: no => 'No',
2107: undo => 'This action can not be undone.',
2108: conf => 'Are you sure you want to overwrite an existing file?',
2109: cont => 'Continue',
2110: );
2111: my $parserflag;
2112: my $hidden = &hidden_elems();
2113: if ($mode eq 'parse') {
2114: $parserflag = '<input type="hidden" name="parserflag" value="1" />';
2115: }
2116: $r->print(<<"END");
2117: <script type="text/javascript">
2118: // <![CDATA[
2119: function confirmOverwrite() {
2120: var chosen;
2121: if (document.existingfile.overwrite.length) {
2122: for (var i=0; i<document.existingfile.overwrite.length; i++) {
2123: if (document.existingfile.overwrite[i].checked) {
2124: chosen = document.existingfile.overwrite[i].value;
2125: }
2126: }
2127: }
2128: if (chosen == 1) {
2129: if (confirm('$lt{'conf'}')) {
2130: document.existingfile.action.value = "process_overwrite";
2131: return true;
2132: } else {
2133: document.existingfile.action.value = "cancel_overwrite";
2134: if (document.existingfile.overwrite.length) {
2135: for (var i=0; i<document.existingfile.overwrite.length; i++) {
2136: if (document.existingfile.overwrite[i].value == "0") {
2137: document.existingfile.overwrite[i].checked = true;
2138: }
2139: }
2140: }
2141: return false;
2142: }
2143: } else {
2144: document.existingfile.action.value = "cancel_overwrite";
2145: return true;
2146: }
2147: }
2148: // ]]>
2149: </script>
2150: <p>
2151: $msg
2152: </p>
2153: <form method="post" action="$url" name="existingfile" onsubmit="return confirmOverwrite();">
2154: <p class="LC_nobreak">$lt{'over'}
2155: <label><input type="radio" name="overwrite" value="1" />
2156: $lt{'yes'}</label>
2157: <label><input type="radio" name="overwrite" value="0" checked="checked" />$lt{'no'}</label></p>
2158: <p>
2159: <input type="hidden" name="action" value="cancel_overwrite" />
2160: <input type="hidden" name="filename" value="$showfname" />
2161: <input type="hidden" name="timestamp" value="$timestamp" />
2162: $hidden
2163: $parserflag
2164: $group_elem
2165: <input type="submit" name="process" value="$lt{'cont'}" />
2166: </p>
2167: </form>
2168: END
2169: } else {
2170: $r->print(
2171: &Apache::loncommon::confirmwrapper(
2172: &Apache::lonhtmlcommon::confirm_success(
2173: &mt('An error occurred ([_1]) while trying to upload [_2].'
2174: ,$result,&display_file(undef,$fname)),1)));
2175: $r->print(&done(undef,$url));
2176: }
2177: } elsif ($result !~ m|^/uploaded/|) {
2178: $r->print(
2179: &Apache::loncommon::confirmwrapper(
2180: &Apache::lonhtmlcommon::confirm_success(
2181: &mt('An error occurred ([_1]) while trying to upload [_2].'
2182: ,$result,&display_file(undef,$fname)),1)));
2183: $r->print(&done(undef,$url));
2184: } else {
2185: if (!&suppress_embed_prompt()) {
2186: if ($mimetype eq 'text/html') {
2187: if (keys(%allfiles) > 0) {
2188: &print_dependency_form($r,$url,\%allfiles,\%codebase,$result);
2189: return;
2190: } else {
2191: $r->print('<p class="LC_warning">'.&mt('No embedded items identified.').'</p>');
2192: }
2193: }
2194: }
2195: $r->print(
2196: &Apache::loncommon::confirmwrapper(
2197: &Apache::lonhtmlcommon::confirm_success(
2198: &mt('File successfully uploaded'))));
2199: $r->print(&done(undef,$url));
2200: }
2201: return;
2202: }
2203:
2204: sub hidden_elems {
2205: my $contelem;
2206: if ($env{'form.mode'} eq 'selectfile') {
2207: $contelem = '<input type="hidden" name="continue" value="true" />';
2208: }
2209: return <<END;
2210: <input type="hidden" name="currentpath" value="$env{'form.currentpath'}" />
2211: <input type="hidden" name="symb" value="$env{'form.symb'}" />
2212: <input type="hidden" name="fieldname" value="$env{'form.fieldname'}" />
2213: <input type="hidden" name="mode" value="$env{'form.mode'}" />
2214: <input type="hidden" name="showversions" value="$env{'form.showversions'}" />
2215: $contelem
2216: END
2217: }
2218:
2219: sub print_dependency_form {
2220: my ($r,$url,$allfiles,$codebase,$result) = @_;
2221: my $container = &HTML::Entities::encode($result,'<>"&');
2222: my $state = &embedded_form_elems($container);
2223: my ($embedded,$num,$pathchg) = &Apache::loncommon::ask_for_embedded_content($url,$state,$allfiles,$codebase,
2224: {'error_on_invalid_names' => 1,
2225: 'ignore_remote_references' => 1,});
2226: if ($embedded) {
2227: if ($num || $pathchg) {
2228: $r->print('<h3>'.&mt("Reference Warning").'</h3>');
2229: } else {
2230: $r->print('<h3>'.&mt("Reference Information").'</h3>');
2231: }
2232: if ($num) {
2233: $r->print('<p>'.&mt('Completed upload of the file.').' '.
2234: &mt('This file contained references to other files.').' '.
2235: &mt('You must upload the referenced files or else the uploaded file may not work properly.').
2236: '</p>'.
2237: '<p>'.&mt("Please select the locations from which the referenced files are to be uploaded.").'</p>'.
2238: $embedded.
2239: '<p>'.&mt('or').'</p>'.&done('Return to directory',$url));
2240: } else {
2241: $r->print('<p>'.&mt("Completed upload of the file. This file contained references to other files.").'</p>'.
2242: $embedded.
2243: '<p>'.&done('Return to directory',$url).'</p>');
2244: }
2245: } else {
2246: $r->print(&done(undef,$url));
2247: }
2248: return;
2249: }
2250:
2251: sub overwrite {
2252: my ($r,$url,$group)=@_;
2253: my $formname = 'existingfile';
2254: my $port_path = &get_port_path();
2255: my $fname = &Apache::lonnet::clean_filename($env{'form.filename'});
2256: my (%allfiles,%codebase,$mode,$mimetype);
2257: unless (&suppress_embed_prompt()) {
2258: if ($env{'form.parserflag'}) {
2259: if ($fname =~ /\.s?html?$/i) {
2260: $mode = 'parse';
2261: }
2262: }
2263: }
2264: if ($fname eq '') {
2265: $r->print(
2266: &Apache::loncommon::confirmwrapper(
2267: &Apache::lonhtmlcommon::confirm_success(
2268: &mt('Invalid filename: [_1]; the name of the uploaded file did not contain any letters, '.
2269: 'so after eliminating special characters there was nothing left.',
2270: '<span class="LC_filename">'.$env{'form.filename'}.'</span>'),1)));
2271: $r->print(&done(undef,$url));
2272: return;
2273: }
2274: $env{'form.'.$formname.'.filename'} = $fname;
2275: my $subdir = $port_path.$env{'form.currentpath'};
2276: $subdir =~ s{(/)$}{};
2277: my $result=
2278: &Apache::lonnet::userfileupload($formname,'overwrite',$subdir,$mode,
2279: \%allfiles,\%codebase,undef,undef,undef,
2280: undef,undef,undef,\$mimetype);
2281: if ($result !~ m|^/uploaded/|) {
2282: $r->print(
2283: &Apache::loncommon::confirmwrapper(
2284: &Apache::lonhtmlcommon::confirm_success(
2285: &mt('An error occurred ([_1]) while trying to overwrite [_2].'
2286: ,$result,&display_file(undef,$fname)),1)));
2287: } else {
2288: if ($mode eq 'parse') {
2289: if ($mimetype eq 'text/html') {
2290: if (keys(%allfiles) > 0) {
2291: &print_dependency_form($r,$url,\%allfiles,\%codebase,$result);
2292: return;
2293: } else {
2294: $r->print(
2295: &Apache::loncommon::confirmwrapper(
2296: &Apache::lonhtmlcommon::confirm_success(
2297: &mt('Overwriting completed.'))
2298: .'<br />'.&mt('No embedded items identified.')));
2299: }
2300: }
2301: } else {
2302: $r->print(
2303: &Apache::loncommon::confirmwrapper(
2304: &Apache::lonhtmlcommon::confirm_success(
2305: &mt('Overwriting completed.'))));
2306: }
2307: }
2308:
2309: my $group_elem;
2310: if (defined($env{'form.group'})) {
2311: $group_elem = '<input type="hidden" name="group" value="'.$env{'form.group'}.'" />';
2312: if (defined($env{'form.ref'})) {
2313: $group_elem .= '<input type="hidden" name="ref" value="'.$env{'form.ref'}.'" />'."\n";
2314: }
2315: }
2316: my $hidden = &hidden_elems();
2317: $r->print(
2318: &Apache::lonhtmlcommon::actionbox(
2319: ['<a href="javascript:document.overwritedone.submit();">'
2320: .&mt('Return to directory')
2321: .'</a>'])
2322: .'<form name="overwritedone" method="post" action="'.$url.'">'
2323: .$hidden
2324: .$group_elem
2325: .'</form>'
2326: );
2327: return;
2328: }
2329:
2330: sub lock_info {
2331: my ($r,$url,$group) = @_;
2332: my ($uname,$udom) = &get_name_dom($group);
2333: my $current_permissions = &Apache::lonnet::get_portfile_permissions($udom,
2334: $uname);
2335: my $file_name = $env{'form.lockinfo'};
2336: $file_name = &prepend_group($file_name);
2337: if (defined($file_name) && defined($$current_permissions{$file_name})) {
2338: foreach my $array_item (@{$$current_permissions{$file_name}}) {
2339: next if (ref($array_item) ne 'ARRAY');
2340:
2341: my $filetext;
2342: if (defined($group)) {
2343: $filetext = '<strong>'.$env{'form.lockinfo'}.
2344: '</strong> (group: '.$group.')';
2345: } else {
2346: $filetext = '<span class="LC_filename">'.$file_name.'</span>';
2347: }
2348:
2349: my $title ='<strong>'.&Apache::lonnet::gettitle($$array_item[0]).
2350: '</strong><br />';
2351: if ($$array_item[-1] eq 'graded') {
2352: $r->print(&mt('[_1] was submitted in response to problem: [_2]',
2353: $filetext,$title));
2354: } elsif ($$array_item[-1] eq 'handback') {
2355: $r->print(&mt('[_1] was handed back in response to problem: [_2]',
2356: $filetext,$title));
2357: } else {
2358: # submission style lock
2359: $r->print(&mt('[_1] was submitted in response to problem: [_2]',
2360: $filetext,$title));
2361: }
2362: my %course_description =
2363: &Apache::lonnet::coursedescription($$array_item[1]);
2364: if ( $course_description{'description'} ne '') {
2365: $r->print(&mt('In the course:').' <strong>'.$course_description{'description'}.'</strong><br />');
2366: }
2367: }
2368: }
2369: $r->print(&done(undef,$url));
2370: return 'ok';
2371: }
2372:
2373: sub createdir {
2374: my ($r,$url,$group)=@_;
2375: my $newdir=&Apache::lonnet::clean_filename($env{'form.newdir'});
2376: # Display warning in case of directory name cleaning has changed the directory name
2377: if ($newdir ne $env{'form.newdir'}) {
2378: $r->print(
2379: '<p><span class="LC_warning">'
2380: .&mt('Invalid characters')
2381: .'</span><br />'
2382: .&mt('The new directory name was changed from [_1] to [_2].'
2383: ,'<span class="LC_filename">'.$env{'form.newdir'}.'</span>'
2384: ,'<span class="LC_filename">'.$newdir.'</span>')
2385: .'</p>'
2386: );
2387: }
2388:
2389: # Directory name empty?
2390: if ($newdir eq '') {
2391: $r->print(
2392: &Apache::loncommon::confirmwrapper(
2393: &Apache::lonhtmlcommon::confirm_success(
2394: &mt('Error: no directory name was provided.'),1)));
2395: $r->print(&done(undef,$url));
2396: return;
2397: }
2398:
2399: my $portfolio_root = &get_portfolio_root();
2400: my ($dirlistref,$listerror) = &get_dir_list($portfolio_root,undef,$group);
2401: my $found_file = 0;
2402: if (ref($dirlistref) eq 'ARRAY') {
2403: foreach my $line (@{$dirlistref}) {
2404: my ($filename)=split(/\&/,$line,2);
2405: if ($filename eq $newdir){
2406: $found_file = 1;
2407: }
2408: }
2409: }
2410: if ($found_file) {
2411: $r->print(
2412: &Apache::loncommon::confirmwrapper(
2413: &Apache::lonhtmlcommon::confirm_success(
2414: &mt('Unable to create a directory named [_1].'
2415: ,'<span class="LC_filename">'.$newdir.'</span>'),1)
2416: .'<br />'.&mt('A file or directory by that name already exists.')));
2417: } else {
2418: my ($uname,$udom) = &get_name_dom($group);
2419: my $port_path = &get_port_path();
2420: my $result=&Apache::lonnet::mkdiruserfile($uname,$udom,
2421: $port_path.$env{'form.currentpath'}.$newdir);
2422: if ($result ne 'ok') {
2423: $r->print(
2424: &Apache::loncommon::confirmwrapper(
2425: &Apache::lonhtmlcommon::confirm_success(
2426: &mt('An error occurred ([_1]) while trying to create a new directory [_2].'
2427: ,$result,&display_file()),1)));
2428:
2429: } else {
2430: $r->print(
2431: &Apache::loncommon::confirmwrapper(
2432: &Apache::lonhtmlcommon::confirm_success(
2433: &mt('Directory successfully created'))));
2434: }
2435: }
2436: $r->print(&done(undef,$url));
2437: }
2438:
2439: sub get_portfolio_root {
2440: my ($udom,$uname,$group) = @_;
2441: if (!(defined($udom)) || !(defined($uname))) {
2442: ($uname,$udom) = &get_name_dom($group);
2443: }
2444: my $path = '/userfiles/portfolio';
2445: if (!defined($group)) {
2446: if (defined($env{'form.group'})) {
2447: $group = $env{'form.group'};
2448: }
2449: }
2450: if (defined($group)) {
2451: $path = '/userfiles/groups/'.$group.'/portfolio';
2452: }
2453: return $path;
2454: }
2455:
2456: sub get_group_quota {
2457: my ($group) = @_;
2458: my $group_quota;
2459: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2460: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2461: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum,$group);
2462: if (%curr_groups) {
2463: my %group_info = &Apache::longroup::get_group_settings(
2464: $curr_groups{$group});
2465: $group_quota = $group_info{'quota'}; #expressed in MB
2466: if ($group_quota) {
2467: $group_quota = 1000 * $group_quota; #expressed in k
2468: }
2469: }
2470: return $group_quota;
2471: }
2472:
2473: sub get_dir_list {
2474: my ($portfolio_root,$path,$group) = @_;
2475: $path ||= $env{'form.currentpath'};
2476: my ($uname,$udom) = &get_name_dom($group);
2477: my $getpropath = 1;
2478: return &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
2479: }
2480:
2481: sub get_name_dom {
2482: my ($group) = @_;
2483: my ($uname,$udom);
2484: if (defined($group)) {
2485: $udom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2486: $uname = $env{'course.'.$env{'request.course.id'}.'.num'};
2487: } else {
2488: $udom = $env{'user.domain'};
2489: $uname = $env{'user.name'};
2490: }
2491: return ($uname,$udom);
2492: }
2493:
2494: sub prepend_group {
2495: my ($filename) = @_;
2496: if (defined($env{'form.group'})) {
2497: $filename = $env{'form.group'}.$filename;
2498: }
2499: return $filename;
2500: }
2501:
2502: sub get_namespace {
2503: my $namespace = 'portfolio';
2504: if (defined($env{'form.group'})) {
2505: my ($uname,$udom) = &get_name_dom($env{'form.group'});
2506: $namespace .= '_'.$udom.'_'.$uname.'_'.$env{'form.group'};
2507: }
2508: return $namespace;
2509: }
2510:
2511: sub get_port_path {
2512: my $port_path;
2513: if (defined($env{'form.group'})) {
2514: $port_path = "groups/$env{'form.group'}/portfolio";
2515: } else {
2516: $port_path = 'portfolio';
2517: }
2518: return $port_path;
2519: }
2520:
2521: sub missing_priv {
2522: my ($r,$url,$priv) = @_;
2523: my %longtext =
2524: &Apache::lonlocal::texthash(
2525: upload => 'upload files',
2526: delete => 'delete files',
2527: rename => 'rename files',
2528: setacl => 'set access controls for files',
2529: viewacl => 'view access controls for files',
2530: );
2531: my $escpath = &HTML::Entities::encode($env{'form.currentpath'},'&<>"');
2532: my $rtnlink = '<a href="'.$url;
2533: if ($url =~ /\?/) {
2534: $rtnlink .= '&';
2535: } else {
2536: $rtnlink .= '?';
2537: }
2538: $rtnlink .= 'currentpath='.$escpath;
2539: $r->print('<h3>'.&mt('Action disallowed').'</h3>');
2540: $r->print(&mt('You do not have sufficient privileges to [_1]',
2541: $longtext{$priv}));
2542: if (defined($env{'form.group'})) {
2543: $r->print(' '.&mt("in the group's group portfolio."));
2544: $rtnlink .= &group_args()
2545: } else {
2546: $r->print(' '.&mt('in this portfolio.'));
2547: }
2548: $rtnlink .= '">'.&mt('Return to directory').'</a>';
2549: $r->print('<br />'.$rtnlink);
2550: return;
2551: }
2552:
2553: sub coursegrp_portfolio_header {
2554: my ($cdom,$cnum,$grp_desc)=@_;
2555: my $gpterm = &Apache::loncommon::group_term();
2556: my $ucgpterm = $gpterm;
2557: $ucgpterm =~ s/^(\w)/uc($1)/e;
2558: if ($env{'form.ref'}) {
2559: &Apache::lonhtmlcommon::add_breadcrumb
2560: ({href=>"/adm/coursegroups",
2561: text=>"Groups",
2562: title=>"Course Groups"});
2563: }
2564: &Apache::lonhtmlcommon::add_breadcrumb
2565: ({href=>"/adm/$cdom/$cnum/$env{'form.group'}/smppg?ref=$env{'form.ref'}",
2566: text=>&mt('Group').": $grp_desc",
2567: title=>&mt("Go to group's home page"),
2568: no_mt=>1},
2569: {href=>"/adm/coursegrp_portfolio?".&group_args(),
2570: text=>"Group Portfolio",
2571: title=>"Display group portfolio"});
2572: my $output = &Apache::lonhtmlcommon::breadcrumbs(
2573: &mt('Group portfolio files - [_1]',$grp_desc),
2574: undef,undef,undef,undef,1);
2575: return $output;
2576: }
2577:
2578: sub get_quota {
2579: my ($group) = @_;
2580: my $disk_quota;
2581: if (defined($group)) {
2582: my $grp_quota = &get_group_quota($group); # quota expressed in k
2583: if ($grp_quota ne '') {
2584: $disk_quota = $grp_quota;
2585: } else {
2586: $disk_quota = 0;
2587: }
2588: } else {
2589: $disk_quota = &Apache::loncommon::get_user_quota($env{'user.name'},
2590: $env{'user.domain'}); #expressed in MB
2591: $disk_quota = 1024 * $disk_quota; # convert from MB to kB
2592: }
2593: return $disk_quota;
2594: }
2595:
2596: sub suppress_embed_prompt {
2597: my $suppress_prompt = 0;
2598: if (($env{'request.role'} =~ /^st/) && ($env{'request.course.id'} ne '')) {
2599: if ($env{'course.'.$env{'request.course.id'}.'.suppress_embed_prompt'} eq 'yes') {
2600: $suppress_prompt = 1;
2601: }
2602: }
2603: return $suppress_prompt;
2604: }
2605:
2606: sub embedded_form_elems {
2607: my ($container) = @_;
2608: my $state = <<STATE;
2609: <input type="hidden" name="currentpath" value="$env{'form.currentpath'}" />
2610: <input type="hidden" name="symb" value="$env{'form.symb'}" />
2611: <input type="hidden" name="fieldname" value="$env{'form.fieldname'}" />
2612: <input type="hidden" name="mode" value="$env{'form.mode'}" />
2613: <input type="hidden" name="container" value="$container" />
2614: STATE
2615: if ($env{'form.group'} ne '') {
2616: $state .= '<input type="hidden" name="group" value="'.$env{'form.group'}.'" />'."\n";
2617: }
2618: return $state;
2619: }
2620:
2621: # Find space available in a user's portfolio (convert to bytes)
2622: sub free_space {
2623: my ($group) = @_;
2624: my $disk_quota = &get_quota($group); # Expressed in kB
2625: my ($uname,$udom) = &get_name_dom($group);
2626: my $portfolio_root = &get_portfolio_root();
2627: my $getpropath = 1;
2628: my $current_disk_usage = &Apache::lonnet::diskusage($udom, $uname,
2629: $portfolio_root, $getpropath); # Expressed in kB
2630: my $free_space = 1024 * ($disk_quota - $current_disk_usage);
2631: return $free_space;
2632: }
2633:
2634: sub valid_container {
2635: my ($uname,$udom,$group) = @_;
2636: my $container_prefix;
2637: if ($group ne '') {
2638: $container_prefix = "/uploaded/$udom/$uname/groups/$group/portfolio";
2639: } else {
2640: $container_prefix = "/uploaded/$udom/$uname/portfolio";
2641: }
2642: if ($env{'form.currentpath'}) {
2643: $container_prefix .= $env{'form.currentpath'};
2644: } else {
2645: $container_prefix .= '/';
2646: }
2647: if ($env{'form.container'} =~ m{^\Q$container_prefix\E(.+)$}) {
2648: my $filename = $1;
2649: if ($filename eq &Apache::lonnet::clean_filename($filename)) {
2650: return 1;
2651: }
2652: }
2653: return;
2654: }
2655:
2656: sub invalid_parms {
2657: my ($r,$url,$currentpath) = @_;
2658: my $escpath = &HTML::Entities::encode($currentpath,'&<>"');
2659: my $rtnlink = '<a href="'.$url;
2660: if ($url =~ /\?/) {
2661: $rtnlink .= '&';
2662: } else {
2663: $rtnlink .= '?';
2664: }
2665: $rtnlink .= 'currentpath='.$escpath;
2666: $rtnlink .= '">'.&mt('Return to directory').'</a>';
2667: $r->print('<h3>'.&mt('Action disallowed').'</h3>');
2668: $r->print(&mt('Some of the data included with this request were invalid'));
2669: $r->print('<br />'.$rtnlink);
2670: return;
2671: }
2672:
2673: sub handler {
2674: # this handles file management
2675: my $r = shift;
2676: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
2677: ['selectfile','currentpath','meta','lockinfo','currentfile','action',
2678: 'fieldname','mode','rename','continue','group','access','setnum',
2679: 'cnum','cdom','type','setroles','showversions','ref','symb']);
2680: my ($uname,$udom,$portfolio_root,$url,$caller,$title,$group,$grp_desc);
2681: if ($r->uri =~ m|^(/adm/)([^/]+)|) {
2682: $url = $1.$2;
2683: $caller = $2;
2684: }
2685: my ($can_modify,$can_delete,$can_upload,$can_setacl,$can_viewacl);
2686: if ($caller eq 'coursegrp_portfolio') {
2687: # Needs to be in a course
2688: if (! ($env{'request.course.fn'})) {
2689: # Not in a course
2690: $env{'user.error.msg'}=
2691: "/adm/coursegrp_portfolio:rgf:0:0:Cannot view group portfolio";
2692: return HTTP_NOT_ACCEPTABLE;
2693: }
2694: my $earlyout = 0;
2695: my $view_permission =
2696: &Apache::lonnet::allowed('vcg',$env{'request.course.id'}.($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:''));
2697: $env{'form.group'} =~ s/\W//g;
2698: $group = $env{'form.group'};
2699: if ($group ne '') {
2700: ($uname,$udom) = &get_name_dom($group);
2701: my %curr_groups = &Apache::longroup::coursegroups($udom,$uname,
2702: $group);
2703: if (%curr_groups) {
2704: my %grp_content = &Apache::longroup::get_group_settings(
2705: $curr_groups{$group});
2706: $grp_desc = &unescape($grp_content{'description'});
2707: if (($view_permission) || (&Apache::lonnet::allowed('rgf',
2708: $env{'request.course.id'}.'/'.$group))) {
2709: $portfolio_root = &get_portfolio_root();
2710: } else {
2711: $r->print(&mt('You do not have the privileges required to access the shared files space for this group.'));
2712: $earlyout = 1;
2713: }
2714: } else {
2715: $r->print(&mt('Not a valid group for this course'));
2716: $earlyout = 1;
2717: }
2718: $title = &mt('Group portfolio for [_1]', $group);
2719: } else {
2720: $r->print(&mt('Invalid group'));
2721: $earlyout = 1;
2722: }
2723: if ($earlyout) { return OK; }
2724: if (&Apache::lonnet::allowed('mdg',$env{'request.course.id'})) {
2725: $can_modify = 1;
2726: $can_delete = 1;
2727: $can_upload = 1;
2728: $can_setacl = 1;
2729: $can_viewacl = 1;
2730: } else {
2731: if (&Apache::lonnet::allowed('agf',$env{'request.course.id'}.'/'.$group)) {
2732: $can_setacl = 1;
2733: }
2734: if (&Apache::lonnet::allowed('ugf',$env{'request.course.id'}.'/'.$group)) {
2735: $can_upload = 1;
2736: }
2737: if (&Apache::lonnet::allowed('mgf',$env{'request.course.id'}.'/'.$group)) {
2738: $can_modify = 1;
2739: }
2740: if (&Apache::lonnet::allowed('dgf',$env{'request.course.id'}.'/'.$group)) {
2741: $can_delete = 1;
2742: }
2743: if (&Apache::lonnet::allowed('rgf',$env{'request.course.id'}.'/'.$group)) {
2744: $can_viewacl = 1;
2745: }
2746: }
2747: } else {
2748: ($uname,$udom) = &get_name_dom();
2749: $portfolio_root = &get_portfolio_root();
2750: $title = 'My Space';
2751: $can_modify = 1;
2752: $can_delete = 1;
2753: $can_upload = 1;
2754: if (&Apache::lonnet::usertools_access('','','portaccess',
2755: undef,'tools')) {
2756: $can_viewacl = 1;
2757: $can_setacl = 1;
2758: }
2759: }
2760:
2761: my $port_path = &get_port_path();
2762: &Apache::loncommon::no_cache($r);
2763: &Apache::loncommon::content_type($r,'text/html');
2764: $r->send_http_header;
2765: # Give the LON-CAPA page header
2766: my $brcrum = [{href=>"/adm/portfolio",text=>"Portfolio Manager"}];
2767:
2768: my $js = '<script type="text/javascript"
2769: src="/res/adm/includes/file_upload.js"></script>';
2770:
2771: if ($env{"form.mode"} eq 'selectfile'){
2772: $r->print(&Apache::loncommon::start_page($title, $js,
2773: {'only_body' => 1}));
2774: } elsif ($env{'form.action'} eq 'rolepicker') {
2775: $r->print(&Apache::loncommon::start_page('New role-based condition', $js,
2776: {'no_nav_bar' => 1, }));
2777: } elsif ($caller eq 'coursegrp_portfolio') {
2778: $r->print(&Apache::loncommon::start_page($title, $js));
2779: } else {
2780: $r->print(&Apache::loncommon::start_page($title, $js,
2781: {'bread_crumbs' => $brcrum}));
2782: if (!&Apache::lonnet::usertools_access($uname,$udom,'portfolio')) {
2783: $r->print('<h2>'.&mt('No user portfolio available') .'</h2>'.
2784: &mt('This is a result of one of the following:').'<ul>'.
2785: '<li>'.&mt('The administrator of this domain has disabled portfolio functionality for this specific user.').'</li>'.
2786: '<li>'.&mt('The domain has been configured to disable, by default, portfolio functionality for all users in the domain.').'</li>'.
2787: '</ul>');
2788: $r->print(&Apache::loncommon::end_page());
2789: return OK;
2790: }
2791: }
2792: $r->rflush();
2793: # Check if access to portfolio is blocked by one or more blocking events in courses.
2794: my $clientip = &Apache::lonnet::get_requestor_ip($r);
2795: my ($blocked,$blocktext) =
2796: &Apache::loncommon::blocking_status('port',$clientip,$uname,$udom);
2797: if ($blocked) {
2798: my $evade_block;
2799: # If portfolio display is in a window popped up from a "Select Portfolio Files"
2800: # link in a .task resource, check if access to the task included proctor validation
2801: # of check-in to a slot limited by IP.
2802: # If so, and the slot is between its open and close dates, override the block.
2803: if ($env{'request.course.id'} && $env{'form.symb'}) {
2804: (undef,undef,my $res) = &Apache::lonnet::decode_symb($env{'form.symb'});
2805: if ($res =~ /\.task$/i) {
2806: my %history =
2807: &Apache::lonnet::restore($env{'form.symb'},$env{'request.course.id'},
2808: $env{'user.domain'},$env{'user.name'});
2809: my $version = $history{'resource.0.version'};
2810: if ($history{'resource.'.$version.'.0.checkedin'}) {
2811: if ($history{'resource.'.$version.'.0.checkedin.slot'}) {
2812: my %slot = &Apache::lonnet::get_slot($history{'resource.'.$version.'.0.checkedin.slot'});
2813: if ($slot{'ip'}) {
2814: if (&Apache::loncommon::check_ip_acc($slot{'ip'})) {
2815: my $now = time;
2816: if (($slot{'slottime'} < $now) && ($slot{'endtime'} > $now)) {
2817: $evade_block = 1;
2818: }
2819: }
2820: }
2821: }
2822: }
2823: }
2824: }
2825: unless ($evade_block) {
2826: $r->print($blocktext);
2827: $r->print(&Apache::loncommon::end_page());
2828: return OK;
2829: }
2830: }
2831: if (($env{'form.currentpath'}) && ($env{'form.currentpath'} ne '/')) {
2832: my $clean_currentpath = '/'.&Apache::loncommon::clean_path($env{'form.currentpath'}).'/';
2833: unless ($env{'form.currentpath'} eq $clean_currentpath) {
2834: &invalid_parms($r,$url);
2835: $r->print(&Apache::loncommon::end_page());
2836: return OK;
2837: }
2838: }
2839: if ($env{'form.container'}) {
2840: unless (&valid_container($uname,$udom,$group)) {
2841: &invalid_parms($r,$url,$env{'form.currentpath'});
2842: $r->print(&Apache::loncommon::end_page());
2843: return OK;
2844: }
2845: }
2846: if (($env{'form.storeupl'}) & (!$env{'form.uploaddoc.filename'})){
2847: $r->print(
2848: '<p><span class="LC_warning">'
2849: .&mt('No file was selected to upload.')
2850: .'</span><br />'
2851: .&mt('To upload a file, click [_1]Browse...[_2] and select a file, then click [_1]Upload[_2].'
2852: ,'<strong>','</strong>')
2853: .'</p>'
2854: );
2855: }
2856: if ($env{'form.meta'}) {
2857: &open_form($r,$url);
2858: $r->print(&mt('Edit Metadata').'<br />');
2859: &close_form($r,$url);
2860: }
2861: if ($env{'form.uploaddoc.filename'}) {
2862: if ($can_upload) {
2863: &upload($r,$url,$group);
2864: } else {
2865: &missing_priv($r,$url,'upload');
2866: }
2867: } elsif ($env{'form.action'} eq 'process_overwrite') {
2868: if ($can_upload) {
2869: &overwrite($r,$url,$group);
2870: } else {
2871: &missing_priv($r,$url,'existingfile');
2872: }
2873: } elsif ($env{'form.action'} eq 'upload_embedded') {
2874: if ($can_upload) {
2875: my $disk_quota = &get_quota($group);
2876: my $getpropath = 1;
2877: my $current_disk_usage =
2878: &Apache::lonnet::diskusage($udom,$uname,$portfolio_root,$getpropath);
2879: my $container = &HTML::Entities::encode($env{'form.container'},'<>&"');
2880: my $state = &embedded_form_elems($container).
2881: '<input type="hidden" name="action" value="modify_orightml" />';
2882: my ($result,$flag) =
2883: &Apache::loncommon::upload_embedded('portfolio',$port_path,$uname,$udom,
2884: $group,$portfolio_root,$group,$disk_quota,$current_disk_usage,$state,$url);
2885: $r->print($result.&done('Return to directory',$url));
2886: } else {
2887: &missing_priv($r,$url,'upload');
2888: }
2889: } elsif ($env{'form.action'} eq 'modify_orightml') {
2890: if ($can_upload) {
2891: my $result =
2892: &Apache::loncommon::modify_html_refs('portfolio',$port_path,$uname,
2893: $udom,$portfolio_root);
2894: $r->print($result.
2895: &done('Return to directory',$url));
2896: } else {
2897: &missing_priv($r,$url,'upload');
2898: }
2899: } elsif ($env{'form.action'} eq 'delete' && $env{'form.confirmed'}) {
2900: if ($can_delete) {
2901: &delete_confirmed($r,$url,$group);
2902: } else {
2903: &missing_priv($r,$url,'delete');
2904: }
2905: } elsif ($env{'form.action'} eq 'delete') {
2906: if ($can_delete) {
2907: &delete($r,$url,$group);
2908: } else {
2909: &missing_priv($r,$url,'delete');
2910: }
2911: } elsif ($env{'form.action'} eq 'deletedir' && $env{'form.confirmed'}) {
2912: if ($can_delete) {
2913: &delete_dir_confirmed($r,$url,$group);
2914: } else {
2915: &missing_priv($r,$url,'delete');
2916: }
2917: } elsif ($env{'form.action'} eq 'deletedir') {
2918: if ($can_delete) {
2919: &delete_dir($r,$url);
2920: } else {
2921: &missing_priv($r,$url,'delete');
2922: }
2923: } elsif ($env{'form.action'} eq 'rename' && $env{'form.confirmed'}) {
2924: if ($can_modify) {
2925: &rename_confirmed($r,$url,$group);
2926: } else {
2927: &missing_priv($r,$url,'rename');
2928: }
2929: } elsif ($env{'form.rename'}) {
2930: $env{'form.selectfile'} = $env{'form.rename'};
2931: $env{'form.action'} = 'rename';
2932: if ($can_modify) {
2933: &rename($r,$url,$group);
2934: } else {
2935: &missing_priv($r,$url,'rename');
2936: }
2937: } elsif ($env{'form.access'}) {
2938: $env{'form.selectfile'} = $env{'form.access'};
2939: if (!defined($env{'form.action'})) {
2940: $env{'form.action'} = 'chgaccess';
2941: }
2942: if (($can_viewacl) || ($can_setacl)) {
2943: &display_access($r,$url,$group,$can_setacl,$can_viewacl,$port_path,$env{'form.action'});
2944: } else {
2945: &missing_priv($r,$url,'viewacl');
2946: }
2947: } elsif (($env{'form.action'} eq 'chgaccess') ||
2948: ($env{'form.action'} eq 'chgconditions')) {
2949: if ($can_setacl) {
2950: &update_access($r,$url,$group,$port_path);
2951: } else {
2952: &missing_priv($r,$url,'setacl');
2953: }
2954: } elsif ($env{'form.action'} eq 'rolepicker') {
2955: if ($can_setacl) {
2956: &role_options_window($r);
2957: } else {
2958: &missing_priv($r,$url,'setacl');
2959: }
2960: } elsif ($env{'form.createdir'}) {
2961: if ($can_upload) {
2962: &createdir($r,$url,$group);
2963: } else {
2964: &missing_priv($r,$url,'upload');
2965: }
2966: } elsif ($env{'form.lockinfo'}) {
2967: &lock_info($r,$url,$group);
2968: } else {
2969: if ($env{'form.action'} eq 'cancel_overwrite') {
2970: if ($can_upload) {
2971: my $formname = 'existingfile';
2972: my $fname = &Apache::lonnet::clean_filename($env{'form.filename'});
2973: $env{'form.'.$formname.'.filename'} = $fname;
2974: my $subdir = $port_path.$env{'form.currentpath'};
2975: $subdir =~ s{(/)$}{};
2976: &Apache::lonnet::userfileupload($formname,'canceloverwrite',$subdir);
2977: }
2978: }
2979: my $current_path='/';
2980: if ($env{'form.currentpath'}) {
2981: $current_path = $env{'form.currentpath'};
2982: }
2983: if ($caller eq 'coursegrp_portfolio') {
2984: &Apache::lonhtmlcommon::clear_breadcrumbs();
2985: $r->print(&coursegrp_portfolio_header($udom,$uname,$grp_desc));
2986: }
2987: my ($dirlistref,$listerror) =
2988: &get_dir_list($portfolio_root,$current_path,$group);
2989: if ($listerror eq 'no_such_dir'){
2990: # two main reasons for this:
2991: # 1) never been here, so directory structure not created
2992: # 2) back-button navigation after deleting a directory
2993: if ($current_path eq '/'){
2994: &Apache::lonnet::mkdiruserfile($uname,$udom,
2995: &get_port_path());
2996: } else {
2997: # some directory that snuck in get rid of the directory
2998: # from the recent pulldown, just in case
2999: &Apache::lonhtmlcommon::remove_recent('portfolio',
3000: [$current_path]);
3001: $current_path = '/'; # force it back to the root
3002: }
3003: # now grab the directory list again, for the first time
3004: ($dirlistref,$listerror) =
3005: &get_dir_list($portfolio_root,$current_path,$group);
3006: }
3007: # need to know if directory is empty so it can be removed if desired
3008: my $is_empty;
3009: if ($listerror eq 'empty') {
3010: $is_empty = 1;
3011: } elsif (ref($dirlistref) eq 'ARRAY') {
3012: if ((scalar(@{$dirlistref}) == 2) && ($dirlistref->[0] =~ /^\.+\&/)
3013: && ($dirlistref->[1] =~ /^\.+\&/)) {
3014: $is_empty = 1;
3015: }
3016: }
3017: &display_common($r,$url,$current_path,$is_empty,$dirlistref,
3018: $can_upload,$group);
3019: &display_directory($r,$url,$current_path,$is_empty,$dirlistref,$group,
3020: $can_upload,$can_modify,$can_delete,$can_setacl,
3021: $can_viewacl);
3022: }
3023: $r->print(&Apache::loncommon::end_page());
3024: return OK;
3025: }
3026:
3027: 1;
3028: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>