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