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