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