Annotation of loncom/interface/lonpickcourse.pm, revision 1.92
1.1 www 1: # The LearningOnline Network
2: # Pick a course
3: #
1.92 ! raeburn 4: # $Id: lonpickcourse.pm,v 1.91 2009/12/02 18:33:27 bisitz Exp $
1.1 www 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::lonpickcourse;
30:
31: use strict;
32: use Apache::Constants qw(:common);
33: use Apache::loncommon;
34: use Apache::loncoursedata;
35: use Apache::lonnet;
1.8 www 36: use Apache::lonlocal;
1.46 raeburn 37: use Apache::longroup;
1.78 raeburn 38: use Apache::courseclassifier;
1.85 raeburn 39: use LONCAPA qw(:DEFAULT :match);
1.1 www 40:
41: sub handler {
42: my $r = shift;
1.8 www 43: &Apache::loncommon::content_type($r,'text/html');
1.1 www 44: $r->send_http_header;
45: return OK if $r->header_only;
46:
47: # ------------------------------------------------------------ Print the screen
1.40 albertel 48:
1.55 raeburn 49: # Get parameters from query string
1.1 www 50: &Apache::loncommon::get_unprocessed_cgi
1.55 raeburn 51: ($ENV{'QUERY_STRING'},['domainfilter','form','cnumelement',
1.19 raeburn 52: 'cdomelement','cnameelement','roleelement',
1.85 raeburn 53: 'multiple','type','setroles','fixeddom','cloner']);
1.90 raeburn 54: my ($type,$title,$jscript,$multelement,$multiple,$roleelement,$typeelement,
1.85 raeburn 55: $lastaction,$autosubmit,$submitopener,$cloneruname,$clonerudom);
1.55 raeburn 56:
1.83 raeburn 57: # Get course type - Course or Community.
1.54 raeburn 58: $type = $env{'form.type'};
59: if (!defined($env{'form.type'})) {
60: $type = 'Course';
61: }
1.82 bisitz 62: $title = 'Selecting a '.$type;
1.54 raeburn 63:
64: # Setup for multiple course selections, if flag for multiples set.
1.55 raeburn 65: $multiple = $env{'form.multiple'};
66: if ($multiple) {
67: ($jscript,$multelement) = &multiples_tag();
1.82 bisitz 68: $title = 'Selecting '.$type.'(s)';
1.54 raeburn 69: }
70:
1.55 raeburn 71: # if called when a DC is selecting a course
1.54 raeburn 72: my $roledom = $env{'form.roleelement'};
73: if ($roledom) {
74: $roleelement = '<input type="hidden" name="roleelement" value="'.$roledom.'" />';
1.66 raeburn 75: $submitopener = &processpick();
1.54 raeburn 76: $autosubmit = 'process_pick("'.$roledom.'")';
77: }
1.90 raeburn 78: if ($env{'form.typeelement'} ne '') {
79: $typeelement = '<input type="hidden" name="typeelement" value="'.$env{'form.typeelement'}.'" />';
80: }
1.54 raeburn 81:
1.92 ! raeburn 82: # if called when a DC is creating a course for another user.
1.85 raeburn 83: if ($env{'form.form'} eq 'ccrs') {
84: ($cloneruname,$clonerudom) = ($env{'form.cloner'} =~ /^($match_username):($match_domain)$/);
85: }
86:
87: # if called when requesting a course
88: if ($env{'form.form'} eq 'requestcrs') {
89: $cloneruname = $env{'user.name'};
90: $clonerudom = $env{'user.domain'};
91: }
92:
1.54 raeburn 93: my $onlyown = 0;
1.55 raeburn 94: # if called to assign course-based portfolio access control
1.59 raeburn 95: if ((($env{'form.form'} eq 'portform') && (!$env{'user.adv'}))) {
1.54 raeburn 96: $onlyown = 1;
1.49 raeburn 97: }
1.55 raeburn 98:
99: my %loaditem;
1.84 raeburn 100: if (($env{'form.type'} eq 'Course') && ($env{'form.numtitles'})) {
101: if (($env{'form.official'} eq 'on') && ($env{'form.state'} eq 'listing')) {
102: $loaditem{'onload'} = 'setElements(document.filterpicker); ';
103: }
1.78 raeburn 104: }
105:
1.66 raeburn 106: if ((($env{'form.form'} eq 'cu') || ($env{'form.form'} eq 'studentform')) &&
107: ($env{'form.pickedcourse'})) {
1.89 raeburn 108: $loaditem{'onload'} .= 'setRoles();setSections();';
1.30 raeburn 109: }
1.85 raeburn 110: my $js = &js_changer();
111: $r->print(&Apache::loncommon::start_page($title,$js,
1.42 albertel 112: {'add_entries' => \%loaditem,
1.41 albertel 113: 'no_nav_bar' => 1, }));
1.55 raeburn 114:
115: if ($env{'form.form'} eq 'portform') {
116: $lastaction = 'document.courselist.submit()';
1.67 raeburn 117: } elsif ($env{'form.form'} eq 'cu' || ($env{'form.form'} eq 'studentform' &&
118: !$multiple)) {
1.55 raeburn 119: $lastaction =
120: 'document.courselist.pickedcourse.value = cdom+"_"+cname;'."\n".
121: 'document.courselist.submit();';
1.34 albertel 122: } else {
1.55 raeburn 123: $lastaction = 'self.close()';
1.1 www 124: }
1.19 raeburn 125:
1.55 raeburn 126: # if called to assign a role in a course to a user via CUSR
1.66 raeburn 127: if ($env{'form.form'} eq 'cu' || $env{'form.form'} eq 'studentform') {
1.68 raeburn 128: $r->print(&create_user_javascript($type));
1.55 raeburn 129: }
1.54 raeburn 130:
1.55 raeburn 131: # print javascript functions for choosing a course
1.85 raeburn 132: if ((($env{'form.gosearch'}) && ($env{'form.updater'} eq '')) ||
133: $onlyown) {
1.58 raeburn 134: $r->print(&gochoose_javascript($type,$multiple,$autosubmit,$lastaction));
1.55 raeburn 135: }
1.79 raeburn 136: $r->print('<script type="text/javascript" language="Javascript">'.$jscript.
137: '</script>');
1.55 raeburn 138: $r->print($submitopener);
1.54 raeburn 139:
1.55 raeburn 140: # ------------------------------------------ Display of filters to limit search
1.57 raeburn 141: my $filter = {};
142: my $action = '/adm/pickcourse';
1.79 raeburn 143: my ($numtitles,$showroles,$nohost);
1.55 raeburn 144: if (!$onlyown) {
145: my $filterlist = ['domainfilter','descriptfilter',
1.79 raeburn 146: 'instcodefilter'];
147: if ($env{'form.form'} eq 'rules') {
148: push(@{$filterlist},'personfilter');
149: if (($env{'form.personfilter'} ne '') && ($env{'form.persondomfilter'} ne '')) {
150: if (&Apache::lonnet::homeserver($env{'form.personfilter'},
151: $env{'form.persondomfilter'}) eq 'no_host') {
152: $nohost = 1;
153: } else {
154: $showroles = 1;
155: }
156: }
157: } else {
158: push(@{$filterlist},'ownerfilter');
159: }
1.55 raeburn 160: # course ID filter for DCs only
161: if ($env{'user.adv'} && $env{'form.domainfilter'} &&
162: exists($env{'user.role.dc./'.$env{'form.domainfilter'}.'/'})) {
163: push(@{$filterlist},'coursefilter');
164: }
1.85 raeburn 165: if ($cloneruname ne '' && $clonerudom ne '') {
166: push(@{$filterlist},'cloneableonly');
167: }
168:
1.55 raeburn 169: $r->print(&build_filters($filterlist,$type,$roleelement,$multelement,
1.85 raeburn 170: $filter,$action,\$numtitles,undef,$cloneruname,
1.90 raeburn 171: $clonerudom,$typeelement));
1.55 raeburn 172: }
1.54 raeburn 173:
174: # ---------------------------------------------------------------- Get the data
1.85 raeburn 175: if ((($env{'form.gosearch'}) && ($env{'form.updater'} eq '')) ||
176: $onlyown) {
177: my %courses = &search_courses($r,$type,$onlyown,$filter,$numtitles,
178: $cloneruname,$clonerudom);
1.79 raeburn 179: if ($nohost) {
180: $r->print ('<span class="LC_warning">'.
181: &mt('User does not exist - username: [_1], domain: [_2].',
182: '<b>'.$filter->{'personfilter'}.'</b>',
183: '<b>'.$filter->{'persondomfilter'}.'</b>').'</span>');
184: } else {
1.85 raeburn 185: &display_matched_courses($r,$type,$multiple,$action,$showroles,$cloneruname,
186: $clonerudom,%courses);
1.79 raeburn 187: }
1.54 raeburn 188: }
189: $r->print(&Apache::loncommon::end_page());
190: return OK;
191: }
192:
1.85 raeburn 193: sub js_changer {
194: return <<"ENDJS";
195: <script type="text/javascript">
196:
197: function updateFilters(caller) {
198: if (typeof(caller) != "undefined") {
199: document.filterpicker.updater.value = caller.name;
200: }
201: document.filterpicker.submit();
202: }
203:
204: </script>
205:
206: ENDJS
207:
208: }
209:
1.66 raeburn 210: sub processpick {
211: my $openerform = 'rolechoice';
212: if ($env{'form.form'} eq 'studentform') {
213: $openerform = $env{'form.form'};
214: }
215: my $process_pick = <<"ENDONE";
216: <script type="text/javascript">
217: function process_pick(dom) {
218: var pickedCourse=opener.document.$openerform.$env{'form.cnumelement'}.value;
219: var pickedDomain=opener.document.$openerform.$env{'form.cdomelement'}.value;
220: var okDomain = 0;
221: ENDONE
222: if ($openerform eq 'rolechoice') {
223: $process_pick .= <<"ENDTWO";
224: if (pickedDomain == dom) {
225: if (pickedCourse != '') {
1.88 raeburn 226: var ccrole = "cc";
227: var pickedType = "$env{'form.type'}";
228: if (pickedType == "Community") {
229: ccrole = "co";
230: }
231: var courseTarget = ccrole+"./"+pickedDomain+"/"+pickedCourse
1.66 raeburn 232: opener.document.title='Role selected. Please stand by.';
233: opener.status='Role selected. Please stand by.';
234: opener.document.rolechoice.newrole.value=courseTarget
235: opener.document.rolechoice.submit();
236: }
237: }
238: else {
239: alert("You may only use this screen to select courses in the current domain: "+dom+"\\nPlease return to the roles page window and click the 'Select Course' link for domain: "+pickedDomain+",\\n if you are a Domain Coordinator in that domain, and wish to become a Course Coordinator in a course in the domain");
240: }
241: ENDTWO
242: } else {
243: $process_pick .= <<"ENDTHREE";
244: if (pickedDomain != dom) {
245: alert("You may only use this screen to select courses in the current domain: "+dom+"\\nPlease return to the roles page window and click the 'Select Course' link for domain: "+pickedDomain+",\\n if you are a Domain Coordinator in that domain, and wish to become a Course Coordinator in a course in the domain");
246: return;
247: }
248: ENDTHREE
249: }
250: $process_pick .= "
251: }
252:
253: </script>
254: ";
255: return $process_pick;
256: }
257:
1.55 raeburn 258: sub create_user_javascript {
259: my ($type) = @_;
260: my $output;
261: #javascript for reporting sections and groups then closing
262: if ($env{'form.pickedcourse'}) {
1.87 raeburn 263: my %coursedescription =
264: &Apache::lonnet::coursedescription($env{'form.pickedcourse'},
265: {'one_time' => '1'});
266: my $cdom = $coursedescription{'domain'};
267: my $cnum = $coursedescription{'num'};
268: my $crstype = $coursedescription{'type'};
1.55 raeburn 269: my $sec_element = 'currsec';
270: my $grplist_element = 'groups';
271: my ($sections,$groups) =
272: &Apache::loncommon::get_secgrprole_info($cdom,$cnum,'',$type);
273: my $num_sections = scalar(@{$sections});
274: my $seclist = join(',',@{$sections});
275: my $num_groups = scalar(@{$groups});
276: my $groupslist = join(',',@{$groups});
277: $output = qq|
278: <script type="text/javascript">
279: function setSections() {
280: opener.document.$env{"form.form"}.$grplist_element.value='$groupslist';
281: window.opener.setSect('$seclist');
1.87 raeburn 282: self.close();
283: }
284: function setRoles() {
285: window.opener.setRole('$crstype');
1.55 raeburn 286: }
287: </script>
288: |;
289: ;
290: }
291: return $output;
292: }
293:
1.54 raeburn 294: sub display_matched_courses {
1.85 raeburn 295: my ($r,$type,$multiple,$action,$showroles,$cloneruname,$clonerudom,%courses) = @_;
1.55 raeburn 296: if ($env{'form.form'} eq 'portform') {
297: $action = '/adm/portfolio';
298: }
1.68 raeburn 299: my $numcourses = keys(%courses);
1.55 raeburn 300: $r->print('<form name="courselist" method="post" action="'.$action.'">');
1.68 raeburn 301: if ($env{'form.form'} eq 'modifycourse') {
302: if ($numcourses > 0) {
1.89 raeburn 303: my $ccrole = 'cc';
304: if ($type eq 'Community') {
305: $ccrole = 'co';
306: }
307: my $cctitle = &Apache::lonnet::plaintext($ccrole,$type);
1.68 raeburn 308: my $dctitle = &Apache::lonnet::plaintext('dc');
309: my $ccrolechk = ' checked="checked" ';
310: my $menuchk = ' ';
311: if ($env{'form.prevphase'} ne '') {
1.92 ! raeburn 312: $ccrolechk = ' ';
! 313: $menuchk = ' checked="checked" ';
1.68 raeburn 314: }
315: $r->print(
1.75 bisitz 316: '<fieldset>'
317: .'<legend>'.&mt('Action').'</legend>'
318: .'<div class="LC_nobreak"><label>'
319: .'<input type="radio" name="phase" value="ccrole"'.$ccrolechk.'/>'
1.89 raeburn 320: .' ');
321: if ($type eq 'Community') {
322: $r->print(&mt('Enter the community with the role of [_1].',$cctitle));
323: } else {
324: $r->print(&mt('Enter the course with the role of [_1].',$cctitle));
325: }
326: $r->print('</label></div>'
1.75 bisitz 327: .'<div class="LC_nobreak"><label>'
1.89 raeburn 328: .'<input type="radio" name="phase" value="menu"'.$menuchk.'/> ');
329: if ($type eq 'Community') {
330: $r->print(&mt('View or modify community settings which only a [_1] may modify.',$dctitle));
331: } else {
332: $r->print(&mt('View or modify course settings which only a [_1] may modify.',$dctitle));
333: }
334: $r->print('</label></div>'
1.75 bisitz 335: .'</fieldset>'
336: .'<br />'
337: );
1.68 raeburn 338: }
339: }
1.54 raeburn 340: my %by_descrip;
341: foreach my $course (keys(%courses)) {
342: my $descr;
1.64 raeburn 343: if (ref($courses{$course}) eq 'HASH') {
1.65 raeburn 344: $descr = $courses{$course}{'description'};
1.64 raeburn 345: } elsif ($courses{$course} =~ m/^([^:]*):/i) {
1.54 raeburn 346: $descr = &unescape($1);
1.34 albertel 347: } else {
1.54 raeburn 348: $descr = &unescape($courses{$course});
349: }
350: my $description = $descr;
351: push (@{$by_descrip{$description}}, $course);
352: }
1.71 bisitz 353:
1.54 raeburn 354: if ($numcourses > 1 && $multiple) {
355: $r->print('<input type="button" value="check all"
356: onclick="javascript:checkAll(document.courselist.course_id)" />
357: <input type="button" value="uncheck all"
358: onclick="javascript:uncheckAll(document.courselist.course_id)" />
359: <br /><br />');
360: }
1.71 bisitz 361:
362: if (%courses) {
363: $r->print(&Apache::loncommon::start_data_table());
364: $r->print(&Apache::loncommon::start_data_table_header_row());
1.89 raeburn 365: my $titlehdr = &mt('Course Title');
366: if ($type eq 'Community') {
367: $titlehdr = &mt('Community Title');
368: }
1.71 bisitz 369: $r->print('<th>'.&mt('Select').'</th>'
1.89 raeburn 370: .'<th>'.$titlehdr.'</th>'
371: .'<th>'.&mt('Domain').'</th>');
372: unless ($type eq 'Community') {
373: $r->print('<th>'.&mt('Course Code').'</th>');
374: }
375: $r->print('<th>'.&mt('Owner/Co-owner(s)').'</th>');
1.79 raeburn 376: if ($showroles) {
377: $r->print('<th>'.&mt("Role(s) for [_1]",
378: &Apache::loncommon::plainname($env{'form.personfilter'},
379: $env{'form.persondomfilter'},'firstname')).'</th>');
380: }
1.71 bisitz 381: $r->print(&Apache::loncommon::end_data_table_header_row());
382: }
1.92 ! raeburn 383: my %cc_cloneable;
! 384: if (($env{'form.form'} eq 'ccrs') || ($env{'form.form'} eq 'requestcrs')) {
! 385: my ($coord_cloneable,$warning) =
! 386: &get_coordinator_cloneable($cloneruname,$clonerudom,$type);
! 387: if ($coord_cloneable) {
! 388: map {$cc_cloneable{$_} = 1;} split('&',$coord_cloneable);
! 389: }
! 390: }
1.54 raeburn 391: foreach my $description (sort { lc($a) cmp lc($b) } (keys(%by_descrip))) {
392: foreach my $course (@{$by_descrip{$description}}) {
1.72 raeburn 393: $r->print(&Apache::loncommon::start_data_table_row());
1.54 raeburn 394: my $cleandesc=&HTML::Entities::encode($description,'<>&"');
395: $cleandesc=~s/'/\\'/g;
396: my ($cdom,$cnum)=split(/\_/,$course);
1.85 raeburn 397: my ($descr,$instcode,$ttype,$canclone,@owners);
1.64 raeburn 398: if (ref($courses{$course}) eq 'HASH') {
399: $descr = $courses{$course}{'description'};
1.85 raeburn 400: $instcode = $courses{$course}{'inst_code'};
401: $ttype = $courses{$course}{'type'};
402: if (($env{'form.form'} eq 'ccrs') || ($env{'form.form'} eq 'requestcrs')) {
1.92 ! raeburn 403: if ($cc_cloneable{$courses{$course}{'cnum'}.':'.$courses{$course}{'domain'}}) {
! 404: $canclone = 1;
! 405: }
! 406: unless ($canclone) {
! 407: my $cloners = $courses{$course}{'cloners'};
! 408: if ($cloners ne '') {
! 409: my @cloneable = split(',',$cloners);
! 410: if (grep(/^\*$/,@cloneable)) {
! 411: $canclone = 1;
! 412: }
! 413: if (grep(/^\*:\Q$env{'form.clonerudom'}\E$/,@cloneable)) {
! 414: $canclone = 1;
! 415: }
! 416: if (grep(/^\Q$cloneruname\E:\Q$clonerudom\E$/,@cloneable)) {
! 417: $canclone = 1;
! 418: }
1.85 raeburn 419: }
420: }
421: }
1.64 raeburn 422: push(@owners,&unescape($courses{$course}{'owner'}));
423: if (ref($courses{$course}{'co-owners'}) eq 'ARRAY') {
424: foreach my $item (@{$courses{$course}{'co-owners'}}) {
425: push(@owners,&unescape($item));
426: }
427: }
428: } else {
429: my $singleowner;
430: ($descr,$instcode,$singleowner,$ttype)=split(/:/,$courses{$course});
431: push(@owners,&unescape($singleowner));
432: }
1.72 raeburn 433: my $ownerstr = join(', ',@owners);
1.85 raeburn 434: $r->print('<td>'.&course_chooser($multiple,$cdom,$cnum,$cleandesc,$canclone).'</td>');
1.71 bisitz 435: $r->print('<td>'.$description.'</td>');
436: $r->print('<td>');
437: $r->print(&Apache::lonnet::domain($cdom,'description')?
438: $cdom.' ('.&Apache::lonnet::domain($cdom,'description').')':$cdom);
439: $r->print('</td>');
1.89 raeburn 440: unless ($type eq 'Community') {
441: $r->print('<td>');
442: if ($instcode ne '') {
443: $r->print(&unescape($instcode));
444: } else {
445: $r->print(' ');
446: }
447: $r->print('</td>');
1.54 raeburn 448: }
1.72 raeburn 449: $r->print('<td>'.$ownerstr.'</td>');
1.79 raeburn 450: if ($showroles) {
451: $r->print('<td>');
452: my $rolestr;
453: if (ref($courses{$course}{'roles'}) eq 'ARRAY') {
454: my @roles = sort(@{$courses{$course}{'roles'}});
455: foreach my $role (@roles) {
456: if ($role =~ /^cr/) {
457: my (undef,$crdom,$crname,$crtitle) = split('/',$role);
458: $rolestr .= $crtitle.', ';
459: } else {
1.89 raeburn 460: $rolestr .= &Apache::lonnet::plaintext($role,$type).', ';
1.79 raeburn 461: }
462: }
463: $rolestr =~ s/\, $//;
464: }
465: $r->print($rolestr.'</td>');
466: }
1.54 raeburn 467: if ($multiple) { $r->print("</label>\n"); }
1.72 raeburn 468: $r->print(&Apache::loncommon::end_data_table_row());
1.71 bisitz 469: # $r->print("<br />\n");
1.19 raeburn 470: }
471: }
1.72 raeburn 472: if (%courses) {
473: $r->print(&Apache::loncommon::end_data_table());
474: }
1.71 bisitz 475:
1.54 raeburn 476: if (!%courses) {
477: $r->print(&mt('None found'));
478: } elsif ($multiple) {
1.57 raeburn 479: $r->print('<input type="button" value="Submit" onClick="gochoose('."'','','')".'" />');
1.54 raeburn 480: }
481: $r->print('<input type="hidden" name="form" value="'.$env{'form.form'}.'" />'.
482: "\n".'<input type="hidden" name="pickedcourse" value="" />'."\n".
483: '<input type="hidden" name="type" value="'.$type.'" />'."\n");
484: if ((exists($env{'form.roleelement'})) && ($env{'form.form'} eq 'rolechoice')) {
485: $r->print('<input type="hidden" name="roleelement" value="'.
486: $env{'form.roleelement'}.'" />'."\n");
487: }
1.55 raeburn 488: if ($env{'form.form'} eq 'portform') {
489: $r->print('<input type="hidden" name="cnum" value="" />');
490: $r->print('<input type="hidden" name="cdom" value="" />');
491: $r->print('<input type="hidden" name="setroles" value="'.$env{'form.setroles'}.'" />');
492: $r->print('<input type="hidden" name="action" value="rolepicker" />');
1.57 raeburn 493: } elsif ($env{'form.form'} eq 'modifycourse') {
1.85 raeburn 494: $r->print(&Apache::lonhtmlcommon::echo_form_input(['phase','pickedcourse','type','form','numtitles','state']));
1.57 raeburn 495: } else {
496: $r->print('<input type="hidden" name="cnumelement" value="'.
497: $env{'form.cnumelement'}.'" />'."\n".
498: '<input type="hidden" name="cdomelement" value="'.
499: $env{'form.cdomelement'}.'" />'."\n");
1.90 raeburn 500: if ($env{'form.typeelement'} ne '') {
501: $r->print('<input type="hidden" name="typeelement" value="'.
502: $env{'form.typeelement'}.'" />'."\n");
503:
504: }
1.55 raeburn 505: }
1.78 raeburn 506: if ((exists($env{'form.fixeddom'})) && ($env{'form.form'} eq 'rules')) {
507: $r->print('<input type="hidden" name="fixeddom" value="'.
508: $env{'form.fixeddom'}.'" />');
509: }
510: if ($env{'form.numtitles'}) {
511: $r->print('<input type="hidden" name="numtitles" value="'.
512: $env{'form.numtitles'}.'" />');
513: }
1.54 raeburn 514: $r->print("</form>\n");
515: return;
516: }
517:
518: sub multiples_tag {
1.55 raeburn 519: my $jscript = &Apache::loncommon::check_uncheck_jscript();
520: my $multelement = '<input type="hidden" name="multiple" value="1" />';
521: return ($jscript,$multelement);
1.1 www 522: }
1.30 raeburn 523:
1.54 raeburn 524: sub build_filters {
1.57 raeburn 525: my ($filterlist,$type,$roleelement,$multelement,$filter,$action,
1.90 raeburn 526: $numtitlesref,$caller,$cloneruname,$clonerudom,$typeelement) = @_;
1.85 raeburn 527: my ($list,$formname,$fixeddom,$codedom,$jscript);
528: $codedom = $env{'request.role.domain'};
1.57 raeburn 529: if (defined($env{'form.form'})) {
1.81 raeburn 530: $formname = $env{'form.form'};
531: } else {
532: $formname = $caller;
1.57 raeburn 533: }
1.84 raeburn 534: my $onchange;
535: unless ($env{'form.interface'} eq 'textual') {
1.85 raeburn 536: $onchange = 'javascript:updateFilters(this)';
1.84 raeburn 537: }
1.79 raeburn 538: my ($domainselectform,$sincefilterform,$ownerdomselectform,$persondomselectform,
1.78 raeburn 539: $instcodeform,$typeselectform,$instcodetitle);
1.55 raeburn 540: foreach my $item (@{$filterlist}) {
1.54 raeburn 541: $filter->{$item} = $env{'form.'.$item};
542: if ($item ne 'descriptfilter' && $item ne 'instcodefilter') {
1.79 raeburn 543: if ($item eq 'domainfilter') {
1.61 albertel 544: $filter->{$item} = &LONCAPA::clean_domain($filter->{$item});
545: } elsif ($item eq 'coursefilter') {
546: $filter->{$item} = &LONCAPA::clean_courseid($filter->{$item});
547: } elsif ($item eq 'ownerfilter') {
548: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
1.79 raeburn 549: $filter->{'ownerdomfilter'} =
550: &LONCAPA::clean_domain($env{'form.ownerdomfilter'});
551: $ownerdomselectform =
552: &Apache::loncommon::select_dom_form($filter->{'ownerdomfilter'},
553: 'ownerdomfilter',1);
554: } elsif ($item eq 'personfilter') {
555: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
556: if ($env{'form.persondomfilter'} eq '') {
1.85 raeburn 557: unless ($env{'form.gosearch'}) {
1.79 raeburn 558: $filter->{'persondomfilter'} = $env{'request.role.domain'};
559: }
560: } else {
561: $filter->{'persondomfilter'} =
562: &LONCAPA::clean_domain($env{'form.persondomfilter'});
563: }
564: $persondomselectform =
565: &Apache::loncommon::select_dom_form($filter->{'persondomfilter'},
566: 'persondomfilter',1);
1.61 albertel 567: } else {
568: $filter->{$item} =~ s/\W//g;
569: }
1.54 raeburn 570: if (!$filter->{$item}) {
571: $filter->{$item} = '';
572: }
573: }
574: if ($item eq 'domainfilter') {
1.63 albertel 575: my $allow_blank = 1;
576: if ($formname eq 'portform') {
577: $filter->{$item} ||= $env{'user.domain'};
578: $allow_blank=0;
1.67 raeburn 579: } elsif ($formname eq 'studentform') {
580: $filter->{$item} ||= $env{'request.role.domain'};
581: $allow_blank=0;
582: }
1.78 raeburn 583: if ($env{'form.fixeddom'}) {
584: $domainselectform = '<input type="hidden" name="domainfilter"'.
585: 'value="'.$env{'request.role.domain'}.'" />'.
586: &Apache::lonnet::domain($env{'request.role.domain'},
587: 'description');
588: $codedom = $env{'request.role.domain'};
1.79 raeburn 589: } else {
1.78 raeburn 590: $domainselectform =
591: &Apache::loncommon::select_dom_form($filter->{$item},
592: 'domainfilter',
1.84 raeburn 593: $allow_blank,'',$onchange);
1.78 raeburn 594: $codedom = $filter->{'domainfilter'};
595: }
1.54 raeburn 596: } else {
597: $list->{$item} = &HTML::Entities::encode($filter->{$item},'<>&"');
598: }
599: }
600:
601: # last course activity filter and selection
602: $filter->{'sincefilter'} = $env{'form.sincefilter'};
603: $filter->{'sincefilter'} =~ s/[^\d-]//g;
604: if (!$filter->{'sincefilter'}) { $filter->{'sincefilter'}=-1; }
1.91 bisitz 605: $sincefilterform=&Apache::loncommon::select_form(
606: $filter->{'sincefilter'},
607: 'sincefilter',
608: ( '-1' => '',
609: '86400' => &mt('today'),
610: '604800' => &mt('last week'),
611: '2592000' => &mt('last month'),
612: '7776000' => &mt('last three months'),
613: '15552000' => &mt('last six months'),
614: '31104000' => &mt('last year'),
615: 'select_form_order' =>
616: ['-1','86400','604800','2592000','7776000',
617: '15552000','31104000']));
618:
619: my %lt = &Apache::lonlocal::texthash(
620: 'cac' => "$type Activity",
621: 'cde' => "$type Title",
622: 'cdo' => "$type Domain",
623: 'ins' => 'Institutional Code',
624: 'inc' => 'Institutional Categorization',
625: 'cow' => "$type Owner/Co-owner",
626: 'cop' => "$type Personnel Includes",
627: 'cog' => 'Type',
1.54 raeburn 628: );
1.49 raeburn 629:
1.89 raeburn 630: if (($env{'form.form'} eq 'ccrs') || ($env{'form.form'} eq 'requestcrs')) {
631: my $typeval = 'Course';
632: if ($type eq 'Community') {
633: $typeval = 'Community';
634: }
635: $typeselectform = '<input type="hidden" name="type" value="'.$typeval.'" />';
636: } else {
637: $typeselectform = '<select name="type" size="1"';
638: if ($onchange) {
639: $typeselectform .= 'onchange="'.$onchange.'"';
640: }
641: $typeselectform .= '>'."\n";
642: foreach my $posstype ('Course','Community') {
643: $typeselectform.='<option value="'.$posstype.'"'.
644: ($posstype eq $type ? ' selected="selected" ' : ''). ">".&mt($posstype)."</option>\n";
645: }
646: $typeselectform.="</select>";
1.84 raeburn 647: }
1.85 raeburn 648:
649: my ($cloneableonlyform,$cloneabletitle);
650: if (exists($filter->{'cloneableonly'})) {
651: my $cloneableon = '';
652: my $cloneableoff = ' checked="checked"';
653: if ($filter->{'cloneableonly'}) {
654: $cloneableon = $cloneableoff;
655: $cloneableoff = '';
656: }
1.86 raeburn 657: $cloneableonlyform = '<span class="LC_nobreak"><label><input type="radio" name="cloneableonly" value="1" '.$cloneableon.'/> '.&mt('Required').'</label>'.(' 'x3).'<label><input type="radio" name="cloneableonly" value="" '.$cloneableoff.' /> '.&mt('No restriction').'</label></span>';
1.85 raeburn 658: if ($env{'form.form'} eq 'ccrs') {
659: $cloneabletitle = &mt('Cloneable for').' '.$cloneruname.':'.$clonerudom;
660: } else {
661: $cloneabletitle = &mt('Cloneable by you');
662: }
663: }
1.80 raeburn 664: my $officialjs;
1.54 raeburn 665: if ($type eq 'Course') {
1.85 raeburn 666: if (exists($filter->{'instcodefilter'})) {
667: if (($env{'form.fixeddom'}) || ($formname eq 'requestcrs')
668: || ($formname eq 'modifycourse')) {
669: $officialjs = 1;
670: ($instcodeform,$jscript,$$numtitlesref) =
671: &instcode_selectors($codedom,'filterpicker',$officialjs);
672: if ($jscript) {
673: $jscript = '<script type="text/javascript" language="Javascript">'.
674: $jscript.'</script>'."\n";
675: }
676: }
677: if ($instcodeform eq '') {
678: $instcodeform =
679: '<input type="text" name="instcodefilter" size="10" value="'.
680: $list->{'instcodefilter'}.'" />';
681: $instcodetitle = $lt{'ins'};
682: } else {
683: $instcodetitle = $lt{'inc'};
684: }
685: if ($env{'form.fixeddom'}) {
686: $instcodetitle .= '<br />('.$codedom.')';
687: }
1.78 raeburn 688: }
1.54 raeburn 689: }
1.84 raeburn 690:
1.57 raeburn 691: my $output = qq|
1.85 raeburn 692: <form method="post" name="filterpicker" action="$action">
1.57 raeburn 693: <input type="hidden" name="form" value="$formname" />
694: |;
695: if ($formname eq 'modifycourse') {
1.68 raeburn 696: $output .= '<input type="hidden" name="phase" value="courselist" />'."\n".
697: '<input type="hidden" name="prevphase" value="'.
698: $env{'form.prevphase'}.'" />'."\n";
699: } else {
1.57 raeburn 700: my $name_input;
701: if ($env{'form.cnameelement'} ne '') {
702: $name_input = '<input type="hidden" name="cnameelement" value="'.
703: $env{'form.cnameelement'}.'" />';
704: }
705: $output .= qq|
1.27 albertel 706: <input type="hidden" name="cnumelement" value="$env{'form.cnumelement'}" />
707: <input type="hidden" name="cdomelement" value="$env{'form.cdomelement'}" />
1.13 albertel 708: $name_input
1.18 raeburn 709: $roleelement
1.35 raeburn 710: $multelement
1.90 raeburn 711: $typeelement
1.57 raeburn 712: |;
1.59 raeburn 713: if ($formname eq 'portform') {
1.78 raeburn 714: $output .= '<input type="hidden" name="setroles" value="'.$env{'form.setroles'}.'" />'."\n";
1.59 raeburn 715: }
1.57 raeburn 716: }
1.78 raeburn 717: if ($env{'form.fixeddom'}) {
718: $output .= '<input type="hidden" name="fixeddom" value="'.$env{'form.fixeddom'}.'" />'."\n";
719: }
1.74 bisitz 720: $output .= "<br />\n".&Apache::lonhtmlcommon::start_pick_box();
1.57 raeburn 721: if ($sincefilterform) {
1.74 bisitz 722: $output .= &Apache::lonhtmlcommon::row_title($lt{'cac'})
723: .$sincefilterform
724: .&Apache::lonhtmlcommon::row_closure();
1.57 raeburn 725: }
726: if ($domainselectform) {
1.74 bisitz 727: $output .= &Apache::lonhtmlcommon::row_title($lt{'cdo'})
728: .$domainselectform
729: .&Apache::lonhtmlcommon::row_closure();
1.78 raeburn 730: }
1.57 raeburn 731: if ($typeselectform) {
1.89 raeburn 732: if (($env{'form.form'} eq 'ccrs') || ($env{'form.form'} eq 'requestcrs')) {
733: $output .= $typeselectform;
734: } else {
735: $output .= &Apache::lonhtmlcommon::row_title($lt{'cog'})
736: .$typeselectform
737: .&Apache::lonhtmlcommon::row_closure();
738: }
1.57 raeburn 739: }
740: if ($instcodeform) {
1.78 raeburn 741: $output .= &Apache::lonhtmlcommon::row_title($instcodetitle)
1.74 bisitz 742: .$instcodeform
743: .&Apache::lonhtmlcommon::row_closure();
1.57 raeburn 744: }
745: if (exists($filter->{'ownerfilter'})) {
1.79 raeburn 746: $output .= &Apache::lonhtmlcommon::row_title($lt{'cow'}).
747: '<table><tr><td>'.&mt('Username').'<br />'.
748: '<input type="text" name="ownerfilter" size="20" value="'.
749: $list->{'ownerfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
750: $ownerdomselectform.'</td></tr></table>'.
751: &Apache::lonhtmlcommon::row_closure();
752: }
753: if (exists($filter->{'personfilter'})) {
754: $output .= &Apache::lonhtmlcommon::row_title($lt{'cop'}).
755: '<table><tr><td>'.&mt('Username').'<br />'.
756: '<input type="text" name="personfilter" size="20" value="'.
757: $list->{'personfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
758: $persondomselectform.'</td></tr></table>'.
759: &Apache::lonhtmlcommon::row_closure();
1.57 raeburn 760: }
761: if (exists($filter->{'coursefilter'})) {
1.74 bisitz 762: $output .= &Apache::lonhtmlcommon::row_title(&mt('LON-CAPA course ID'))
763: .'<input type="text" name="coursefilter" size="25" value="'
764: .$list->{'coursefilter'}.'" />'
765: .&Apache::lonhtmlcommon::row_closure();
1.57 raeburn 766: }
1.85 raeburn 767: if ($cloneableonlyform) {
768: $output .= &Apache::lonhtmlcommon::row_title($cloneabletitle).
769: $cloneableonlyform.&Apache::lonhtmlcommon::row_closure();
770: }
1.57 raeburn 771: if (exists($filter->{'descriptfilter'})) {
1.74 bisitz 772: $output .= &Apache::lonhtmlcommon::row_title($lt{'cde'})
773: .'<input type="text" name="descriptfilter" size="40" value="'
774: .$list->{'descriptfilter'}.'" />'
775: .&Apache::lonhtmlcommon::row_closure(1);
1.57 raeburn 776: }
1.85 raeburn 777: $output .= &Apache::lonhtmlcommon::end_pick_box().'<p>';
1.92 ! raeburn 778: my ($coord_cloneable,$warning);
1.85 raeburn 779: if (($env{'form.form'} eq 'ccrs') || ($env{'form.form'} eq 'requestcrs')) {
1.92 ! raeburn 780: ($coord_cloneable,$warning) =
! 781: &get_coordinator_cloneable($cloneruname,$clonerudom,$type);
! 782: if ($env{'form.form'} eq 'ccrs') {
! 783: $output .= '<input type="hidden" name="cloner" value="'.$env{'form.cloner'}.'" />'."\n";
1.85 raeburn 784: }
1.92 ! raeburn 785: if ($coord_cloneable) {
! 786: $output .= '<input type="hidden" name="cc_clone" value="'.$coord_cloneable.'" />';
1.85 raeburn 787: }
788: }
789: $output .= '<input type="hidden" name="updater" value="">'."\n".
1.84 raeburn 790: '<input type="submit" name="gosearch" value="'.
1.70 raeburn 791: &mt('Search').'" /></p>'."\n".'</form>'."\n".'<hr />'."\n";
1.85 raeburn 792: return $jscript.$warning.$output;
1.78 raeburn 793: }
794:
1.92 ! raeburn 795: sub get_coordinator_cloneable {
! 796: my ($cloneruname,$clonerudom,$type) = @_;
! 797: if (&Apache::lonnet::homeserver($cloneruname,$clonerudom) eq 'no_host') {
! 798: my $warning = '<div class="LC_error">'.&mt('Intended course owner does not exist').
! 799: '</div>';
! 800: return ('',$warning);
! 801: } else {
! 802: my ($cc_clone,$ccrole);
! 803: if ($type eq 'Community') {
! 804: $ccrole = 'co';
! 805: } elsif ($type eq 'Course') {
! 806: $ccrole = 'cc';
! 807: }
! 808: my %ccroles = &Apache::lonnet::get_my_roles($cloneruname,$clonerudom,
! 809: 'userroles',['active'], [$ccrole]);
! 810: foreach my $key (sort(keys(%ccroles))) {
! 811: my ($cnum,$cdom,$role) = split(':',$key);
! 812: $cc_clone .= $cdom.':'.$cnum.'&';
! 813: }
! 814: $cc_clone =~ s/\&$//;
! 815: return ($cc_clone);
! 816: }
! 817: }
! 818:
1.78 raeburn 819: sub instcode_selectors {
1.80 raeburn 820: my ($codedom,$formname,$officialjs) = @_;
1.78 raeburn 821: my ($output,@codetitles,%cat_titles,%cat_order,%cat_items);
822: my ($jscript,$totcodes,$numtitles,$lasttitle) =
823: &Apache::courseclassifier::instcode_selectors_data($codedom,$formname,
1.80 raeburn 824: \%cat_items,\@codetitles,\%cat_titles,\%cat_order,$officialjs);
1.78 raeburn 825: if ($numtitles > 0) {
1.84 raeburn 826: my $official = ' checked="checked" ';
827: my $unofficial = '';
828: if ($env{'form.official'} eq 'off') {
829: $unofficial = $official;
830: $official = '';
1.80 raeburn 831: }
832: $output .= '<span class="LC_nobreak">'.&mt('Official course:').' <label>'.
1.84 raeburn 833: '<input type="radio" name="official" value="on"'.$official.' />'.
1.80 raeburn 834: &mt('Yes').'</label>'.(' 'x3).'<label>'.
1.84 raeburn 835: '<input type="radio" name="official" value="off"'.$unofficial.
1.80 raeburn 836: ' onclick="toggleOfficial();" />'.&mt('No').'</label></span><br />'.
837: &Apache::courseclassifier::build_instcode_selectors($numtitles,
838: $lasttitle,\%cat_items,\@codetitles,\%cat_titles,\%cat_order)."\n".
839: '<input type="hidden" name="numtitles" value="'.$numtitles.'" />'."\n".
840: '<input type="hidden" name="state" value="listing" />'."\n";
1.78 raeburn 841:
842: }
843: return ($output,$jscript,$numtitles);
1.54 raeburn 844: }
845:
846: sub search_courses {
1.85 raeburn 847: my ($r,$type,$onlyown,$filter,$numtitles,$cloneruname,$clonerudom) = @_;
1.89 raeburn 848: my (%courses,%showcourses,$cloner,$ccrole);
849: if ($type eq 'Community') {
850: $ccrole = 'co';
851: } else {
852: $ccrole = 'cc';
853: }
1.54 raeburn 854: if (!$onlyown) {
1.71 bisitz 855: $r->print(&mt('Searching ...').'<br /> <br />');
1.6 www 856: $r->rflush();
1.54 raeburn 857: if (($filter->{'ownerfilter'} ne '') ||
858: ($filter->{'ownerdomfilter'} ne '')) {
859: $filter->{'combownerfilter'} = $filter->{'ownerfilter'}.':'.
860: $filter->{'ownerdomfilter'};
861: }
1.80 raeburn 862: foreach my $item ('descriptfilter','coursefilter','combownerfilter') {
1.54 raeburn 863: if (!$filter->{$item}) {
864: $filter->{$item}='.';
865: }
1.52 raeburn 866: }
1.54 raeburn 867: my $timefilter =
868: ($filter->{'sincefilter'}==-1?1:time-$filter->{'sincefilter'});
1.78 raeburn 869: my ($instcodefilter,$regexpok);
870: if ($numtitles) {
1.84 raeburn 871: if ($env{'form.official'} eq 'on') {
1.80 raeburn 872: $instcodefilter =
1.84 raeburn 873: &Apache::courseclassifier::instcode_search_str($filter->{'domainfilter'},$numtitles);
1.80 raeburn 874: $regexpok = 1;
1.84 raeburn 875: } elsif ($env{'form.official'} eq 'off') {
876: $instcodefilter = &Apache::courseclassifier::instcode_search_str($filter->{'domainfilter'},$numtitles);
877: unless ($instcodefilter eq '') {
878: $regexpok = -1;
879: }
1.80 raeburn 880: }
1.78 raeburn 881: } else {
882: $instcodefilter = $filter->{'instcodefilter'};
883: }
1.80 raeburn 884: if ($instcodefilter eq '') { $instcodefilter = '.'; }
885: if ($type eq '') { $type = '.'; }
1.85 raeburn 886:
887: if (($clonerudom ne '') && ($cloneruname ne '')) {
888: $cloner = $cloneruname.':'.$clonerudom;
889: }
1.54 raeburn 890: %courses =
891: &Apache::lonnet::courseiddump($filter->{'domainfilter'},
892: $filter->{'descriptfilter'},
893: $timefilter,
1.78 raeburn 894: $instcodefilter,
1.54 raeburn 895: $filter->{'combownerfilter'},
896: $filter->{'coursefilter'},
1.85 raeburn 897: undef,undef,$type,$regexpok,undef,undef,
898: undef,undef,$cloner,$env{'form.cc_clone'},
899: $filter->{'cloneableonly'});
1.79 raeburn 900: if (($filter->{'personfilter'} ne '') && ($filter->{'persondomfilter'} ne '')) {
901: my %rolehash = &Apache::lonnet::get_my_roles($filter->{'personfilter'},
902: $filter->{'persondomfilter'},
903: 'userroles',undef,
1.89 raeburn 904: [$ccrole,'in','ad','ep','ta','cr'],
1.79 raeburn 905: $filter->{'domainfilter'});
906: foreach my $role (keys(%rolehash)) {
907: my ($cnum,$cdom,$courserole) = split(':',$role);
908: my $cid = $cdom.'_'.$cnum;
909: if (exists($courses{$cid})) {
910: if (ref($courses{$cid}) eq 'HASH') {
911: if (ref($courses{$cid}{roles}) eq 'ARRAY') {
912: if (!grep(/^\Q$courserole\E$/,@{$courses{$cid}{roles}})) {
913: push (@{$courses{$cid}{roles}},$courserole);
914: }
915: } else {
916: $courses{$cid}{roles} = [$courserole];
917: }
918: $showcourses{$cid} = $courses{$cid};
919: }
920: }
921: }
922: %courses = %showcourses;
923: }
1.54 raeburn 924: } else {
925: $r->print('<br />');
1.60 raeburn 926: my %coursehash = &Apache::loncommon::findallcourses();
927: foreach my $cid (sort(keys(%coursehash))) {
1.65 raeburn 928: $courses{$cid}{'description'} = $env{'course.'.$cid.'.description'};
1.36 raeburn 929: }
1.2 www 930: }
1.54 raeburn 931: return %courses;
1.18 raeburn 932: }
1.1 www 933:
1.30 raeburn 934: sub course_chooser {
1.85 raeburn 935: my ($multiple,$cdom,$cnum,$cleandesc,$canclone) = @_;
1.30 raeburn 936: my $output;
1.35 raeburn 937: if ($multiple) {
1.32 albertel 938: $output = '<label><input type="checkbox" name="course_id" value="'.$cdom.'_'.$cnum.'" />'."\n";
1.85 raeburn 939: } elsif ((($env{'form.form'} eq 'ccrs') || ($env{'form.form'} eq 'requestcrs')) && (!$canclone)) {
940: if ($env{'form.form'} eq 'ccrs') {
941: $output = &mt('No cloning for ').$env{'form.cloner'}."\n";
942: } else {
943: $output = &mt('No rights to clone')."\n";
944: }
1.30 raeburn 945: } else {
1.71 bisitz 946: $output = '<input type="button" value="'.&mt('Select').'" onClick="gochoose('.
1.30 raeburn 947: "'".$cnum."','".$cdom."','".$cleandesc."')".'" />'."\n";
948: }
949: return $output;
1.49 raeburn 950: }
951:
1.55 raeburn 952: sub gochoose_javascript {
1.57 raeburn 953: my ($type,$multiple,$autosubmit,$lastaction) = @_;
1.55 raeburn 954: my %elements = (
955: 'Course' => {
956: name => 'coursepick',
957: total => 'coursetotal',
958: list => 'courselist',
959: },
1.83 raeburn 960: 'Community' => {
1.88 raeburn 961: name => 'coursepick',
962: total => 'coursetotal',
963: list => 'courselist',
1.55 raeburn 964: },
965: );
1.57 raeburn 966: my $output .= qq|
1.55 raeburn 967: <script type="text/javascript">
1.57 raeburn 968: function gochoose(cname,cdom,cdesc) {
1.55 raeburn 969: var openerForm = "$env{'form.form'}";
970: courseCount = 0;
971: var courses = '';
1.57 raeburn 972: |;
973: if ($multiple) {
974: $output .= <<"ENDSCRIPT";
975: courseCount = 0;
976: var courses = '';
977: if (typeof(document.courselist.course_id.length) == 'undefined') {
978: // only 1 course checkbox was created
979: if (document.courselist.course_id.checked) {
980: courses = courses + document.courselist.course_id.value + "&&";
981: courseCount ++;
982: }
983: } else {
984: for (var j=0; j<document.courselist.course_id.length; j++) {
985: if (document.courselist.course_id[j].checked) {
986: courses = courses + document.courselist.course_id[j].value + "&&";
1.55 raeburn 987: courseCount ++;
988: }
1.57 raeburn 989: }
990: }
991: opener.document.$env{'form.form'}.$elements{$type}{'total'}.value = courseCount;
992: if (typeof(opener.document.$env{'form.form'}.$elements{$type}{'name'}.length) ==
993: 'undefined') {
994: if (opener.document.$env{'form.form'}.$elements{$type}{'name'}.value == 'specific') {
995: opener.document.$env{'form.form'}.$elements{$type}{'name'}.checked = true;
1.55 raeburn 996: } else {
1.57 raeburn 997: opener.document.$env{'form.form'}.$elements{$type}{'name'}.checked = false;
1.55 raeburn 998: }
1.57 raeburn 999: } else {
1000: for (var j=0; j<opener.document.$env{'form.form'}.$elements{$type}{'name'}.length; j++) {
1001: if (opener.document.$env{'form.form'}.$elements{$type}{'name'}\[j].value == 'specific') {
1002: opener.document.$env{'form.form'}.$elements{$type}{'name'}\[j].checked = true;
1.55 raeburn 1003: } else {
1.57 raeburn 1004: opener.document.$env{'form.form'}.$elements{$type}{'name'}\[j].checked = false;
1.54 raeburn 1005: }
1.55 raeburn 1006: }
1.57 raeburn 1007: }
1008: if (courseCount > 0) {
1009: courses = courses.substr(0,courses.length-2);
1010: opener.document.$env{'form.form'}.$elements{$type}{'list'}.value = courses;
1011: }
1012: ENDSCRIPT
1013: } else {
1.90 raeburn 1014: my ($name_code,$type_code);
1.57 raeburn 1015: if ($env{'form.cnameelement'} ne '') {
1016: $name_code = 'opener.document.'.$env{'form.form'}.'.'.
1017: $env{'form.cnameelement'}.'.value=cdesc;';
1.55 raeburn 1018: }
1.90 raeburn 1019: if ($env{'form.typeelement'} ne '') {
1020: $type_code = 'opener.document.'.$env{'form.form'}.'.'.
1021: $env{'form.typeelement'}.'.value=document.courselist.type;';
1022: }
1023:
1.57 raeburn 1024: $output .= qq|
1.55 raeburn 1025: $name_code
1.90 raeburn 1026: $type_code
1.55 raeburn 1027: opener.document.$env{'form.form'}.$env{'form.cnumelement'}.value=cname;
1028: var slct=opener.document.$env{'form.form'}.$env{'form.cdomelement'};
1029: if (slct.options == undefined) {
1030: opener.document.$env{'form.form'}.$env{'form.cdomelement'}.value=cdom;
1031: }
1032: else {
1033: var i;
1034: for (i=0;i<slct.length;i++) {
1035: if (slct.options[i].value==cdom) { slct.selectedIndex=i; }
1.54 raeburn 1036: }
1037: }
1.57 raeburn 1038: |;
1.54 raeburn 1039: }
1.57 raeburn 1040: $output .= qq|
1.55 raeburn 1041: if (openerForm == 'portform') {
1042: document.courselist.cnum.value = cname;
1043: document.courselist.cdom.value = cdom;
1044: }
1045: $autosubmit
1046: $lastaction
1.54 raeburn 1047: }
1.55 raeburn 1048: </script>
1.57 raeburn 1049: |;
1.55 raeburn 1050: return $output;
1.54 raeburn 1051: }
1052:
1.55 raeburn 1053: 1;
1054: __END__
1055:
1056: =pod
1057:
1058: =head1 NAME
1059:
1060: Apache::lonpickcourse - Search for course(s) based on user-specified criteria.
1061:
1062: =head1 SYNOPSIS
1063:
1064: Invoked by other LON-CAPA modules, when course(s) need to be selected by the user.
1065:
1066: =head1 OVERVIEW
1067:
1068: Two screens are typically displayed to the user. The first is a set of criteria which are used to constrain the search for courses.
1069:
1070: =head2 Search Criteria (Screen One)
1071:
1072: =head3 Criteria:
1073:
1074: =over 4
1075:
1076: =item *
1077: Course Activity - how recently was course last visited by anyone.
1078:
1079: =item *
1080: Course Domain - the domain of the course
1081:
1082: =item *
1.84 raeburn 1083: Type - Course or Community
1.55 raeburn 1084:
1085: =item *
1086: Course Institutional Code - the institutional identifier assigned to the course
1087:
1088: =item *
1089: Course Owner's Username - the username of the owner of the course (assigned by the Domain Coordinator and/or when the course was created).
1090:
1091: =item *
1092: Course Owner's Domain - the domain of the owner of the course
1093:
1094: =item *
1.76 bisitz 1095: Course Title - text which appears in the Course Title, as set in the Course Parameters.
1.55 raeburn 1096:
1097: =item *
1098: Course ID - the internal course number (course ID part after initial 'domain_') used by LON-CAPA (this criterion is only displayed to Domain Coordinators selecting a course in the same domain as their DC role).
1099:
1100: =back
1101:
1102: The criteria setting screen is not displayed if course picking is done by a user who does not have advanced privileges (as defined by $env{'user.adv'}).
1103:
1104: =head2 Course Display (Screen Two)
1105:
1106: A list of courses matching the search criteria is displayed. If the user is not an advanced user, screen one will have been skipped and the courses displayed will be all courses in which the user has currently active roles. The information displayed for each course is:
1107:
1108: =over 4
1109:
1110: =item *
1111: Course description
1112:
1113: =item *
1114: Domain description of course domain
1115:
1116: =item *
1117: Course institutional code
1118:
1119: =item *
1120: Course owner (username:domain)
1121:
1122: =back
1123:
1124: Depending on context, the display may include a single select box for each course, allowing selection of only a single course, or may include checkboxes allowing selection of more than one course.
1125:
1126: Following selection, and/or submission, the course description, number and domain are transferred to the browser window from which the course picker window was opened. In most cases, the child window containing the course picker screens will be closed. However, in some cases closure will be delayed until a third screen has been displayed (e.g., setting of course-based conditional access controls for portfolio files). In this case the page is generated via /adm/portfolio and the page features select boxes to allow the user to select roles, access types, sections and groups.
1127:
1128: =head1 SUBROUTINES
1129:
1130: =over 4
1131:
1132: =item *
1133: X<create_user_javascript()>
1134: B<create_user_javascript($type)>:
1135:
1.83 raeburn 1136: Input: 1 - $type - the course type - Course or Community
1.55 raeburn 1137:
1138: Output: 1 - $output - javascript wrapped in E<lt>scriptE<gt>E<lt>/scriptE<gt> tags
1139:
1140: Side Effects: None
1141:
1142: javascript code for reporting selected sections (as a string of comma separated sections) and groups in the selected course (as a comma separated list) then calling setSect() javscript function in the opener window (to populate section select box) then closing current window.
1143:
1144:
1145: =item *
1146: X<display_matched_courses()>
1.85 raeburn 1147: B<display_matched_courses($r,$type,$multiple,$action,$showroles,$cloneruname,$clonerudom,%courses)>:
1.55 raeburn 1148:
1.85 raeburn 1149: Input: 7 - request object, course type, multiple (0 or 1), form action, whether to show roles (for course personnel filter), username of new course owner, domain of new course owner, hash of courses.
1.55 raeburn 1150:
1151: Output: 0
1152:
1153: Side Effects: prints select buttons (multiple = 0) or checkboxes (multiple = 1) and hidden form elements for selection of one or more courses which met search criteria.
1154:
1155: =item *
1156: X<multiples_tag()>
1157: B<multiples_tag()>:
1158:
1159:
1160: Input: 0
1161:
1162: Output: 2 - $jscript - javascript for check all/uncheck all checkboxes; $multelement - hidden form element with multiple set to 1.
1163:
1164: Side Effects: None
1165:
1166: =item *
1167: X<build_filters()>
1.90 raeburn 1168: B<build_filters($filterlist,$type,$roleelement,$multelement,$filter,$action,$numfiltersref,$caller,$cloneruname,$clonerudom,$typeelem)>:
1.55 raeburn 1169:
1170:
1.90 raeburn 1171: Input: 11 - anonymous array of search criteria; course type; $roleelement ; $multelement ; anonymous hash of criteria and their values; form action; ref to scalar (count of number of elements in institutional codes -- e.g., 4 for year, semester, department, and number); caller context (e.g., set to 'modifycourse' when routine is called from lonmodifycourse.pm), username and domain of new course owner who wants to clone, $tyepelem
1.55 raeburn 1172:
1173: Output: 1 - $output - HTML for display of search criteria, and hidden form elements.
1174:
1175: Side Effects: None
1176:
1177: =item *
1178: X<search_courses()>
1.85 raeburn 1179: B<search_courses($r,$type,$onlyown,$filter,$numtitles,$cloneruname,$clonerudom)>:
1.55 raeburn 1180:
1181:
1.85 raeburn 1182: Input: 7 - request object, course type, search scope: only courses in which user has active role (1), or any course (0); anonymous hash of criteria and their values; for institutional codes - number of categories; optional username of new course owner, optional domain of new course owner). Last two needed when search is for courses to clone from course request form, or course creation form (DC).
1.55 raeburn 1183:
1184: Output: 1 - %courses - hash of courses satisfying search criteria, keys = course IDs, values are corresponding colon-separated escaped description, institutional code, owner and type.
1185:
1186: Side Effects: None
1187:
1188:
1189: =item *
1190: X<course_chooser()>
1.85 raeburn 1191: B<course_chooser($multiple,$cdom,$cnum,$cleandesc,$canclone)>:
1.55 raeburn 1192:
1.85 raeburn 1193: Input: 5 - single (0) or multiple (1) courses; course domain, course number; course description; can clone course (1 if new course owner has cloning rights).
1.55 raeburn 1194:
1.85 raeburn 1195: Output: 1 - HTML for either checkbox (multiple=1) or select button (multiple=0) for user to indicate course selection.
1.55 raeburn 1196:
1197: Side Effects: None
1198:
1199:
1200: =item *
1201: X<gochoose_javascript()>
1.57 raeburn 1202: B<gochoose_javascript($type,$multiple,$autosubmit,$lastaction)>:
1.55 raeburn 1203:
1.66 raeburn 1204: Input: 4 - course type; single (0) or multiple courses (1); in context of DC selecting a CC role in a course: javascript code from &processpick(); final action to take after user chooses course(s): either close window, or submit form for display of next page etc.
1.55 raeburn 1205:
1206: Output: 1 $output - javascript wrapped in E<lt>scriptE<gt>E<lt>/scriptE<gt> tags
1207:
1208: Side Effects: None
1209:
1210: javascript functions used when user selects a course(s). Different behavior depending on context:
1211:
1212: =back
1213:
1214: =over 8
1215:
1216: =item
1217:
1218: (a) Domain Coordinator using MAIL to select recipients of broadcast e-mail - && separated list of selected courses written to hidden form element in opener window. Child window closes.
1219:
1220: =item
1221:
1222: (b) Domain Coordinator choosing a course for adoption of a CC role from roles screen - write course identifying information to hidden form elements in opener window and automatically submit role selection form in opener window. Child window closes.
1223:
1224: =item
1225:
1226: (c) Domain Coordinator creating a course, and selecting a course to clone - course number and domain written to visible form elements in opener window. Child window closes.
1227:
1228: =item
1.54 raeburn 1229:
1.55 raeburn 1230: (d) User selecting a course for course-based conditional access control for a portfolio file - form is submitted, and new page is displayed for selection of roles, access types, sections and groups to be used in conditional ACL. New page is generated by /adm/portfolio.
1.54 raeburn 1231:
1.55 raeburn 1232: =item
1.54 raeburn 1233:
1.55 raeburn 1234: (e) Domain Coordinator assigning a role to a user - form is submitted, and new page does an onload call to a javascript function to (a) write lists of sections and groups to hidden elements in opener window, (b) call function in opener window to dynamically populate select box showing current sections.
1.54 raeburn 1235:
1.55 raeburn 1236: =item
1.54 raeburn 1237:
1.55 raeburn 1238: (f) Author modifying a rights entry in a .rights file - selected course number and domain are witten to visible form elements in opener window. Child window closes.
1.54 raeburn 1239:
1.55 raeburn 1240: =item
1.49 raeburn 1241:
1.55 raeburn 1242: (g) Scantron Operator uploading a scantron file to a course - course number is written to visible form element in opener window. Child window closes.
1.30 raeburn 1243:
1.84 raeburn 1244: =item
1245:
1246: (h) User requesting creation of a course, and selecting a course to clone - course number and domain written to visible form elements in opener window. Child window closes.
1247:
1.55 raeburn 1248: =back
1249:
1250: =cut
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>