File:
[LON-CAPA] /
loncom /
imspackages /
imsimport.pm
Revision
1.23:
download - view:
text,
annotated -
select for diffs
Sun Aug 24 13:48:40 2008 UTC (15 years, 11 months ago) by
raeburn
Branches:
MAIN
CVS tags:
HEAD
- Localization
- Remove font tags
- Replace tables with datatable from loncommon.
- Include counts of items created for CMSs besides BB5 and ANGEL
- Pass ref to %total as additional argument to imsprocessor::copy_resources() to get
cont of files copied.
- Use lonhtmlcommon::topic_bar()
1: # Copyright Michigan State University Board of Trustees
2: #
3: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
4: #
5: # LON-CAPA is free software; you can redistribute it and/or modify
6: # it under the terms of the GNU General Public License as published by
7: # the Free Software Foundation; either version 2 of the License, or
8: # (at your option) any later version.
9: #
10: # LON-CAPA is distributed in the hope that it will be useful,
11: # but WITHOUT ANY WARRANTY; without even the implied warranty of
12: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13: # GNU General Public License for more details.
14: #
15: # You should have received a copy of the GNU General Public License
16: # along with LON-CAPA; if not, write to the Free Software
17: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18: #
19: # /home/httpd/html/adm/gpl.txt
20: #
21: # http://www.lon-capa.org/
22: #
23:
24: package Apache::imsimport;
25:
26: use strict;
27: use Apache::Constants qw(:common :http :methods);
28: use Apache::loncacc;
29: use Apache::loncommon();
30: use Apache::lonnet;
31: use Apache::imsprocessor;
32: use Apache::lonlocal;
33: use HTML::Parser;
34: use HTML::Entities();
35: use Apache::lonlocal;
36: use Apache::lonupload;
37: use File::Basename();
38: use LONCAPA;
39:
40: # ---------------------------------------------------------------- Jscript One
41: sub jscript_one {
42: my ($fullpath,$jsref,$formname) = @_;
43:
44: my %body_layout = ('rightmargin' => "0",
45: 'leftmargin' => "0",
46: 'marginwidth' => "0",
47: 'topmargin' => "0",
48: 'marginheight' => "0");
49: my $start_page =
50: &Apache::loncommon::start_page('Create IMS import directory',undef,
51: {'only_body' => 1,
52: 'add_entries' => \%body_layout,
53: 'js_ready' => 1,});
54: my $end_page =
55: &Apache::loncommon::end_page({'js_ready' => 1,});
56:
57: my %lt = &Apache::lonlocal::texthash(
58: ddir => 'You must choose a destination directory for the import',
59: cmss => 'You must choose the Course Management System from which the IMS package was exported',
60: loca => 'Location:',
61: newd => 'New Directory',
62: nndi => 'Enter the name of the new directory where you will store the contents of your IMS package.',
63: go => 'Go',
64: );
65: $$jsref = <<"END_OF_ONE";
66: function verify() {
67: if ((document.forms.$formname.newdir.value == '') || (!document.forms.$formname.newdir.value)) {
68: alert('$lt{'ddir'}')
69: return false
70: }
71: if (document.forms.$formname.source.selectedIndex == 0) {
72: alert('$lt{'cmss'}');
73: return false
74: }
75: return true
76: }
77:
78: function nextPage() {
79: if (verify()) {
80: document.forms.$formname.submit();
81: }
82: }
83:
84: function createWin() {
85: document.$formname.newdir.value = "";
86: newWindow = window.open("","CreateDir","HEIGHT=400,WIDTH=750,scrollbars=yes")
87: newWindow.document.open()
88: newWindow.document.write('$start_page')
89: newWindow.document.write("\\n<img border='0' src='/adm/lonInterFace/author.jpg' alt='[Author Header]'>\\n")
90: newWindow.document.write("<table border='0' cellspacing='0' cellpadding='0' width='600'>\\n")
91: newWindow.document.write("<tr><td width='2'> </td><td width='3'> </td>\\n")
92: newWindow.document.write("<td><h3>$lt{'loca'} <tt>$fullpath</tt></h3><h3>$lt{'newd'}</h3></td></tr>\\n")
93: newWindow.document.write("<tr><td width='2'> </td><td width='3'> </td>\\n")
94: newWindow.document.write("<td><form name='fileaction' action='/adm/cfile' method='post'>\\n")
95: newWindow.document.write("$lt{'nndi'}<br /><br />")
96: newWindow.document.write("<input type='hidden' name='filename' value='$fullpath' />")
97: newWindow.document.write("<input type='hidden' name='action' value='newdir' />")
98: newWindow.document.write("<input type='hidden' name='callingmode' value='imsimport' />")
99: newWindow.document.write("$fullpath<input type='text' name='newfilename' value='' />")
100: newWindow.document.write("<input type='button' value='$lt{'go'}' onClick='document.fileaction.submit();' />")
101: newWindow.document.write("</td></tr>\\n")
102: newWindow.document.write("</table>")
103: newWindow.document.write('$end_page')
104: newWindow.document.close()
105: newWindow.focus()
106: }
107:
108: END_OF_ONE
109:
110: }
111:
112: # ---------------------------------------------------------------- Jscript Two
113: sub jscript_two {
114: my ($javascript,$user,$dom,$numcrs) = @_;
115: my %crsentry = ();
116: my $course_list;
117: my $title_list;
118: my @crslist = ();
119: &get_ccroles($user,$dom,\%crsentry,\@crslist);
120: if (@crslist > 0) {
121: $crsentry{$crslist[0]} =~ s/("|,)//g;
122: $title_list = '"'.$crsentry{$crslist[0]}.'"';
123: if (@crslist > 1) {
124: for (my $i=1; $i<@crslist; $i++) {
125: $crsentry{$crslist[$i]} =~ s/("|,)//g;
126: $title_list .= ',"'.$crsentry{$crslist[$i]}.'"';
127: }
128: }
129: }
130: $course_list = '"'.join('","',@crslist).'"';
131: $$numcrs = @crslist;
132:
133: $$javascript = qq#
134:
135: function checkCourse() {
136: courseID_array = new Array($course_list)
137: courseTitle_array = new Array($title_list)
138: var step2Form = document.forms.pickoptions
139: var conditionType = step2Form.conditions.value
140: var curVal = step2Form.targetcourse.options[step2Form.targetcourse.selectedIndex].value
141: if (curVal == -1) {
142: if ( conditionType == 'both' ) {
143: if ( step2Form.board.checked == true || step2Form.users.checked == true ) {
144: setCourse(step2Form,'add')
145: }
146: }
147: if ( conditionType == 'users' ) {
148: if ( step2Form.users.checked == true ) {
149: setCourse(step2Form,'add')
150: }
151: }
152: if ( conditionType == 'board' ) {
153: if ( step2Form.board.checked == true ) {
154: setCourse(step2Form,'add')
155: }
156: }
157: }
158: else {
159: if ( conditionType == 'both' ) {
160: if ( step2Form.board.checked == false && step2Form.users.checked == false ) {
161: setCourse(step2Form,'clear')
162: }
163: }
164: if ( conditionType == 'users' ) {
165: if ( step2Form.users.checked == false ) {
166: setCourse(step2Form,'clear')
167: }
168: }
169: if ( conditionType == 'board' ) {
170: if ( step2Form.board.checked == false ) {
171: setCourse(step2Form,'clear')
172: }
173: }
174: }
175: }
176:
177: function setCourse(step2Form,call) {
178: step2Form.targetcourse.length = 0
179: if (call == 'add') {
180: step2Form.targetcourse.length = 0
181: step2Form.targetcourse.options[0] = new Option("Please Select","0",true,true)
182: for (var i=0; i<courseID_array.length; i++) {
183: step2Form.targetcourse.options[i+1] = new Option(courseTitle_array[i],courseID_array[i],false,false)
184: }
185: step2Form.targetcourse.selectedIndex = 0
186: }
187: else {
188: step2Form.targetcourse.options[0] = new Option("Not required","-1",true,true)
189: step2Form.targetcourse.selectedIndex = 0
190: }
191: }
192:
193:
194: function setOptions(caller,itemnum) {
195: var numCrs = $$numcrs
196: var opForm = document.forms.pickoptions
197: var menu = 1 + itemnum*2
198: opForm.elements[menu].length = 0
199: if (opForm.elements[itemnum*2].checked == true) {
200: if (caller == "board") {
201: opForm.elements[menu].options[0] = new Option("Select","-1",true,true)
202: opForm.elements[menu].options[1] = new Option("Import topics only","topics",true,true)
203: opForm.elements[menu].options[2] = new Option("Import topics + posts (with author)","allpost",true,true)
204: opForm.elements[menu].options[3] = new Option("Import topics + posts (no author)","allanon",true,true)
205: }
206: else {
207: if (caller == "users") {
208: opForm.elements[menu].length = 0
209: opForm.elements[menu].options[0] = new Option("Select","-1",true,true)
210: opForm.elements[menu].options[1] = new Option("Enroll students only","students",true,true)
211: opForm.elements[menu].options[2] = new Option("Enroll all users","all",true,true)
212: }
213: }
214: }
215: else {
216: opForm.elements[menu].options[0] = new Option("Not required","0",true,true)
217: }
218: opForm.elements[menu].selectedIndex = 0
219: if (numCrs > 0) {
220: checkCourse()
221: }
222: }
223:
224: function verify(caller) {
225: var numCrs = $$numcrs
226: var opForm = document.forms.pickoptions
227: var totcheck = 0;
228: var totchg = 0;
229: for (var i=0; i<caller; i++) {
230: if (opForm.elements[2*i].checked == true) {
231: totcheck ++
232: if (opForm.elements[2*i].name == "board") {
233: if (opForm.elements[2*i+1].selectedIndex == 0) {
234: alert("You must select one of the additional options when importing Discussion Boards ")
235: return false
236: }
237: if (numCrs == 0) {
238: opForm.elements[2*i].checked = false
239: totchg ++
240: }
241: else {
242: if (opForm.targetcourse.selectedIndex == 0) {
243: alert("You must select a target course when importing Discussion Boards")
244: return false
245: }
246: }
247: }
248: if (opForm.elements[2*i].name == "users") {
249: if (opForm.elements[2*i+1].selectedIndex == 0) {
250: alert("You must select one of the additional options when importing Enrollment")
251: return false
252: }
253: if (numCrs == 0) {
254: opForm.elements[2*i].checked = false
255: totchg ++
256: }
257: else {
258: if (opForm.targetcourse.selectedIndex == 0) {
259: alert("You must select a target course when importing enrollment information")
260: return false
261: }
262: }
263: }
264: }
265: }
266: if (totcheck == 0) {
267: alert("You must check the Checkbox for at least one Content Type");
268: return false
269: }
270: return true
271: }
272:
273: function nextPage(caller) {
274: if (verify(caller)) {
275: document.forms.pickoptions.submit()
276: }
277: }
278:
279: #;
280:
281: }
282:
283: # ---------------------------------------------------------------- Jscript Three
284: sub jscript_three {
285: my $javascript = shift;
286: }
287:
288: # ---------------------------------------------------------------- Display One
289: sub display_one {
290: my ($r,$uname,$fn,$fullpath,$formname) = @_;
291: $r->print('<form name="'.$formname.'" method="post">'.
292: &Apache::lonhtmlcommon::topic_bar(1,&mt('Specify the Course Management system used to create the package')).
293: &mt('Choose the CMS used to create your IMS content package.').'
294: <select name="source">
295: <option value="-1" selected="true">Please select</option>
296: <option value="bb5">Blackboard 5</option>
297: <option value="bb6">Blackboard 6</option>
298: <option value="angel">ANGEL</option>
299: <option value="webctce4">WebCT 4 Campus Edition</option>
300: <option value="webctvista4">WebCT Vista 4</option>
301: </select><br />'."\n".
302: &Apache::lonhtmlcommon::topic_bar(2,&mt('Create a directory where you will unpack your IMS package'))."\n".
303: &mt('Create a destination LON-CAPA directory in which to store the contents of the IMS package file.').' <input type="button" name="createdir" value="Create Directory" onClick="javascript:createWin()" /><input type="hidden" name="newdir" value="" /><br /><br />
304: <input type="hidden" name="uploaduname" value="'.$uname.'" />
305: <input type="hidden" name="filename" value="'.$fn.'" />
306: <input type="hidden" name="phase" value="three" />
307: <input type="button" name="nextpage" value="'.&mt('Proceed').'" onClick="javascript:nextPage();" />
308: <input type="button" name="exitpage" value="'.&mt('Exit now').'" onClick="javascript:location.href='."'$fullpath'".'" />
309: </form>');
310: }
311:
312: # ---------------------------------------------------------------- Display Two
313: sub display_two {
314: my ($r,$zipupload,$areas,$areaname,$cmsmap,$uname,$newdir,$numcrs,$fullpath) = @_;
315: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['folder','source']);
316: my $cms = $env{'form.source'};
317: my $dirname = $env{'form.newdir'};
318: my $tempdir = &Apache::imsprocessor::create_tempdir('CSTR',$dirname,'');
319: my $fname = &Apache::imsprocessor::uploadzip('CSTR',$tempdir,$zipupload);
320: my $unzip_result = '';
321: my $manifest_result = '';
322: unless ($tempdir eq '') {
323: $unzip_result = &Apache::imsprocessor::expand_zip($tempdir,$fname);
324: }
325: my %resources = ();
326: my %includedres = ();
327: my %includeditems = ();
328: my %items = ();
329: my %hrefs = ();
330: my %resinfo = ();
331: my %count = ();
332:
333: my %lt = &Apache::lonlocal::texthash(
334: cont => 'Choose which content types you wish to import',
335: impo => 'Import',
336: type => 'Content type',
337: addo => 'Additional options',
338: chec => 'Check Import first',
339: bbus => 'Choose a course to receive bulletin boards and user enrollment',
340: list => 'A listing of possible course targets will be displayed if import of bulletin boards and/or enrollment is checked above (step 3). If you do not plan to import either of these content types, there is no need to specify a course.',
341: chco => 'Choose course:',
342: nreq => 'Not required',
343: yodo => 'You do not have active course coordinator status in any LON-CAPA courses currently, so bulletin boards and enrollment information included in your IMS package will be discarded, regardless of your import choice for these two items above (step 3).',
344: ifyo => "If you wish to import bulletin boards and/or user information into LON-CAPA please click 'Exit now' to quit the current IMS import process, and contact your domain coordinator and request a course coordinator role in a LON-CAPA course into which you can upload bulletin boards and/or enroll users.",
345: impa => 'Import package',
346: unpa => 'Unpacking of your IMS package failed because an IMS manifest file was not located in the package',
347: proc => 'Processing of your IMS package failed because the file you uploaded could not be unzipped',
348: exit => 'Exit now',
349: );
350:
351: my $counter = 0;
352: my $iter = 0;
353: my %count = (
354: announce => 0,
355: board => 0,
356: doc => 0,
357: extlink => 0,
358: msg => 0,
359: pool => 0,
360: quiz => 0,
361: staff => 0,
362: survey => 0,
363: users => 0,
364: );
365: my $conditions;
366: if ($unzip_result eq 'ok') {
367: $manifest_result = &Apache::imsprocessor::process_manifest($cms,
368: $tempdir,\%resources,\%items,\%hrefs,\%resinfo,
369: 'choose',\%includedres,\%includeditems);
370: if ($manifest_result eq 'ok') {
371: foreach my $res (sort keys %resources) {
372: if ($cms eq 'bb5' || $cms eq 'bb6' || $cms eq 'webctce4'
373: || $cms eq 'webctvista4') {
374: foreach my $area (keys %{$$cmsmap{$cms}}) {
375: if ($resources{$res}{type} eq $$cmsmap{$cms}{$area}) {
376: $count{$area} ++;
377: }
378: }
379: } elsif ($cms eq 'angel') {
380: foreach my $area (keys %{$$cmsmap{$cms}}) {
381: if ($area eq 'doc') {
382: if (grep/^$resources{$res}{type}$/,@{$$cmsmap{$cms}{doc}}) {
383: $count{$area} ++;
384: }
385: } elsif ($resources{$res}{type} eq $$cmsmap{$cms}{$area}) {
386: $count{$area} ++;
387: }
388: }
389: }
390: }
391: if ($count{board} > 0) {
392: if ($count{users} > 0) {
393: $conditions = 'both';
394: } else {
395: $conditions = 'board';
396: }
397: } elsif ($count{users} > 0) {
398: $conditions = 'users';
399: } else {
400: $conditions = 'none';
401: }
402:
403: $r->print('<form name="pickoptions" method="post">'.
404: &Apache::lonhtmlcommon::topic_bar(3,$lt{'cont'}).
405: &Apache::loncommon::start_data_table().
406: &Apache::loncommon::start_data_table_header_row().
407: '<th>'.$lt{'impo'}.'</th><th>'.$lt{'cont'}.'</th><th>'.
408: $lt{'addo'}.'</th>'.
409: &Apache::loncommon::end_data_table_header_row());
410: foreach my $area (@{$areas}) {
411: if ($count{$area} > 0) {
412: my $count_tag = 'flag_'.$counter;
413: $r->print(&Apache::loncommon::start_data_table_row()."\n".
414: '<td><input name="'.$area.'" type="checkbox" ');
415: if ($area eq 'board' || $area eq 'users') {
416: $r->print('onClick="javascript:setOptions('."'$area','$counter'".');" ');
417: }
418: $r->print('/></td>'.
419: '<td> '.$$areaname{$area}.' - '.
420: &mt('[quant,_1,item]',$count{$area}).'</td>');
421: if ($area eq 'board') {
422: $r->print('<td>
423: <select name="db_handling">
424: <option value="-2"><-- '.$lt{'chec'}.'</option>
425: </select>
426: </td>');
427: } elsif ($area eq 'users') {
428: $r->print('<td>
429: <select name="user_handling">
430: <option value="-2"><-- '.$lt{'chec'}.'</option>
431: </select>
432: </td>');
433: } else {
434: $r->print('<td> '.&mt('None')."\n".
435: '<input type="hidden" name="'.$count_tag.'" /></td>');
436: }
437: $counter ++;
438: $r->print(&Apache::loncommon::end_data_table_row());
439: }
440: }
441: $r->print(&Apache::loncommon::end_data_table());
442: if ($count{board} + $count{users} > 0) {
443: $r->print(&Apache::lonhtmlcommon::topic_bar(4,$lt{'bbus'}));
444: if ($$numcrs > 0) {
445: $r->print($lt{'list'}.'<br /><br />'.$lt{'chco'}.' '."\n".
446: '<select name="targetcourse">
447: <option value="-1">'.$lt{'nreq'}.'</option>
448: </select>');
449: } else {
450: $r->print($lt{'yodo'}.' '.$lt{'ifyo'});
451: }
452: }
453: $r->print('<br /><br />
454: <input type="hidden" name="newdir" value="'.$env{'form.newdir'}.'" />
455: <input type="hidden" name="conditions" value="'.$conditions.'" />
456: <input type="hidden" name="source" value="'.$cms.'" />
457: <input type="hidden" name="tempdir" value="'.$tempdir.'" />
458: <input type="hidden" name="uploaduname" value="'.$uname.'">
459: <input type="hidden" name="filename" value="'.$fname.'">
460: <input type="hidden" name="phase" value="four" />'."\n");
461: if ($count{board} == 0) {
462: $r->print('<input type="hidden" name="board" value="" />'."\n");
463: }
464: if ($count{users} == 0) {
465: $r->print('<input type="hidden" name="users" value="" />'."\n");
466: }
467: $r->print('<input type="button" name="nextpage" value="'.$lt{'impa'}.'" onClick="javascript:nextPage('."'$counter.'".')" />
468: <input type="button" name="exitpage" value="'.$lt{'exit'}.'" onClick="javascript:location.href='."'$fullpath'".'" /></form>');
469: } else {
470: $r->print($lt{'unpa'});
471: }
472: } else {
473: $r->print($lt{'proc'});
474: }
475: }
476:
477: # ---------------------------------------------------------------- Display Three
478: sub display_three {
479: my ($r,$uname,$udom,$areas,$areaname,$cmsmap,$destdir,$newdir) = @_;
480: my $crs = '';
481: my $cdom = '';
482: my $db_handling = '';
483: my $timenow = time;
484: my $announce_handling = 'ok';
485: my $cms = $env{'form.source'};
486: if ( defined($env{'form.bb_crs'}) ) {
487: ($cdom,$crs) = split/\//,$env{'form.bb_crs'};
488: }
489: my $user_crs = '';
490: my $user_cdom = '';
491: my $user_handling = '';
492: if ( defined($env{'form.user_crs'}) ) {
493: ($user_cdom,$user_crs) = split/\//,$env{'form.user_crs'};
494: }
495: my $seqstem = "/res/$udom/$uname/$newdir";
496: my %importareas = ();
497: my %includedres = ();
498: my %includeditems = ();
499: my %randompicks = ();
500: my @targets = ();
501: my %resources = ();
502: my %items = ();
503: my %hrefs = ();
504: my %urls = ();
505: my %resinfo = ();
506: my %total = (
507: page => 0,
508: prob => 0,
509: seq => 0,
510: board => 0,
511: quiz => 0,
512: surv => 0,
513: file => 0,
514: );
515:
516: my @pages = ();
517: my @sequences = ();
518: my @resrcfiles = ();
519: my @assessmentfiles = ();
520:
521: my $tempdir = $env{'form.tempdir'};
522:
523: foreach my $area (@{$areas}) {
524: if (defined($env{"form.$area"}) ) {
525: if ($cms eq 'angel' && $area eq 'doc') {
526: foreach (@{$$cmsmap{$cms}{$area}}) {
527: $importareas{$_} = 1;
528: }
529: } else {
530: $importareas{$$cmsmap{$cms}{$area}} = 1;
531: }
532: if ($area eq 'board') {
533: $db_handling = $env{'form.db_handling'};
534: } elsif ($area eq 'users') {
535: $user_handling = $env{'form.user_handling'};
536: }
537: }
538: }
539:
540: my %lt = &Apache::lonlocal::texthash (
541: yims => 'Your IMS package has been processed successfully.',
542: plsv => 'Please view the imported items and use the LON-CAPA editing tools to make changes.',
543: tseq => "The sequences directory contains a file named 'Top.sequence' which includes links to the items found at the top level of your IMS package. From there you can follow links to display all the imported items. Alternatively, you can browse the pages, sequences, problems and resfiles directories directly. Note if you rename a file, you will need to modify any .sequence files or .page files which include a reference to the renamed file.",
544: tfin => 'The final step in the IMS import process is to publish the materials you have imported into your Construction Space so that you can use them in a course. Once your files are published, subsequent re-publication will result in the storage of information about changes between the different versions.',
545: disp => 'Display new directory',
546: proc => 'Processing of your IMS package failed, because the IMS content package did not contain an IMS manifest file.'
547: );
548: my $manifest_result = &Apache::imsprocessor::process_manifest($cms,$tempdir,
549: \%resources,\%items,\%hrefs,\%resinfo,'prepare',
550: \%includedres);
551: if ($manifest_result eq 'ok') {
552: foreach my $res (sort keys %resources) {
553: if ($importareas{$resources{$res}{type}}) {
554: $includedres{$res} = 1;
555: if ($resources{$res}{type} eq 'webct.manifest' ||
556: $resources{$res}{type} eq 'webct.assessment' ||
557: $resources{$res}{type} eq 'webct.question') {
558: push(@assessmentfiles,$res);
559: }
560: }
561: }
562: foreach my $itm (sort keys %items) {
563: &Apache::imsprocessor::get_imports(\%includeditems,\%items,\%resources,\%importareas,$itm);
564: }
565: }
566:
567: foreach my $itm (sort keys %includeditems) {
568: &Apache::imsprocessor::get_parents(\%includeditems,\%items,$itm);
569: }
570:
571: $manifest_result = &Apache::imsprocessor::process_manifest($cms,$tempdir,
572: \%resources,\%items,\%hrefs,\%resinfo,'build',
573: \%includedres,\%includeditems);
574: if ($manifest_result eq 'ok') {
575: &Apache::imsprocessor::target_resources(\%resources,\%importareas,\@targets);
576:
577: my @boards = ();
578: my @announcements = ();
579: my @quizzes = ();
580: my @surveys = ();
581: my @pools = ();
582: my @groups = ();
583: my %messages = ();
584: my @timestamp = ();
585: my %boardnum = ();
586: my @topurls = ();
587: my @topnames = ();
588: my @packages = ();
589:
590: &Apache::imsprocessor::process_resinfo($cms,'CSTR',$tempdir,$destdir,\%items,\%resources,\@targets,\@boards,\@announcements,\@quizzes,\@surveys,\@pools,\@groups,\%messages,\@timestamp,\%boardnum,\%resinfo,$udom,$uname,$cdom,$crs,$db_handling,$user_handling,\%total,$seqstem,$seqstem,\@resrcfiles,\@packages,\%hrefs,\@pages,\@sequences,\%randompicks);
591:
592: my $copy_result = &Apache::imsprocessor::copy_resources('CSTR',$cms,\%hrefs,$tempdir,\@targets,\%urls,$crs,$cdom,$destdir,$timenow,\@assessmentfiles,\%total);
593:
594: &Apache::imsprocessor::build_structure($cms,'CSTR',$destdir,\%items,\%resinfo,\%resources,\@targets,\%hrefs,$udom,$uname,$newdir,$timenow,$cdom,$crs,\@timestamp,\%total,\@boards,\@announcements,\@quizzes,\@surveys,\@pools,\%boardnum,\@pages,\@sequences,\@topurls,\@topnames,\@packages,\%includeditems,\%randompicks);
595:
596: $r->print("<h3>IMS import completed</h3>");
597:
598: if ($cms eq 'angel') {
599: $r->print($lt{'yims'}.' '.&mt('A total of [quant,_1,sequence], [quant,_2,composite page], and [quant,_3,bulletin board] have been created, and [quant,_4,file] copied.',$total{seq},$total{page},$total{board},$total{file})."\n");
600: } else {
601: $r->print($lt{'yims'}.' '.&mt('A total of [quant,_1,sequence], [quant,_2,composite page], [quant,_3,bulletin board], [quant,_4,quiz,quizzes], [quant,_5,survey], and [quant,_6,problem] have been created, and [quant,_7,file] copied.',$total{seq},$total{page},$total{board},$total{quiz},$total{surv},$total{prob},$total{file})."\n");
602: }
603: $r->print('<br /><br />'.$lt{'plsv'}.' '.$lt{'tseq'}.'<br /><br />'.$lt{'tfin'}.'<br /><br /><a href="/priv/'.$uname.'/'.$newdir.'">'.$lt{'disp'}.'</a>');
604: if ($destdir =~ m-^/home/$uname/public_html/-) {
605: system (" rm -r -f $destdir/temp");
606: }
607: } elsif ($manifest_result eq 'nomanifest') {
608: $r->print($lt{'proc'});
609: }
610: }
611:
612: # ---------------------------------------------------------------- Get LON-CAPA Course Coordinator roles for this user
613: sub get_ccroles {
614: my ($user,$dom,$crsentry,$crslist) = @_;
615: my %roles = ();
616: unless ($user eq '') {
617: %roles = &Apache::lonnet::dump('roles',$dom,$user);
618: }
619: my $iter = 0;
620: my @codes = ();
621: my %courses = ();
622: my @crslist = ();
623: my %descrip =();
624: foreach my $key (keys %roles ) {
625: if ($key =~ m{^/($LONCAPA::domain_re)/($LONCAPA::username_re)_cc$}) {
626: my $cdom = $1;
627: my $crs = $2;
628: my $role_end = 0;
629: my $role_start = 0;
630: my $active_chk = 1;
631: if ( $roles{$key} =~ m/^cc_(\d+)/ ) {
632: $role_end = $1;
633: if ( $roles{$key} =~ m/^cc_($role_end)_(\d+)$/ )
634: {
635: $role_start = $2;
636: }
637: }
638: if ($role_start > 0) {
639: if (time < $role_start) {
640: $active_chk = 0;
641: }
642: }
643: if ($role_end > 0) {
644: if (time > $role_end) {
645: $active_chk = 0;
646: }
647: }
648: if ($active_chk) {
649: my $currcode = '';
650: my %settings = &Apache::lonnet::get('environment',['internal.coursecode','description'],$cdom,$crs);
651: if (defined($settings{'description'}) ) {
652: $descrip{$crs} = $settings{'description'};
653: } else {
654: $descrip{$crs} = 'Unknown';
655: }
656: if (defined($settings{'internal.coursecode'}) ) {
657: $currcode = $settings{'internal.coursecode'};
658: if ($currcode eq '') {
659: $currcode = "____".$iter;
660: $iter ++;
661: }
662: } else {
663: $currcode = "____".$iter;
664: $iter ++;
665: }
666: unless (grep/^$currcode$/,@codes) {
667: push @codes,$currcode;
668: @{$courses{$currcode}} = ();
669: }
670: push @{$courses{$currcode}}, $cdom.'/'.$crs;
671: }
672: }
673: }
674: foreach my $code (sort @codes) {
675: foreach my $crsdom (@{$courses{$code}}) {
676: my ($cdom,$crs) = split/\//,$crsdom;
677: my $showcode = '';
678: unless ($code =~m/^____\d+$/) { $showcode = $code; }
679: $$crsentry{$crsdom} = $showcode.':'.$descrip{$crs};
680: push @{$crslist}, $crsdom;
681: }
682: }
683: return;
684: }
685:
686: # ---------------------------------------------------------------- Main Handler
687: sub handler {
688: my $r=shift;
689: my $uname;
690: my $udom;
691: my $javascript = '';
692: my $page_name = '';
693: my $current_page = '';
694: my $qcount = '';
695:
696: # get personal information for this user
697: my $user=$env{'user.name'};
698: my $dom=$env{'user.domain'};
699:
700: #
701: # re-attach user
702: #
703: if ($env{'form.uploaduname'}) {
704: $env{'form.filename'}='/priv/'.$env{'form.uploaduname'}.'/'.
705: $env{'form.filename'};
706: }
707: ($uname,$udom)=
708: &Apache::loncacc::constructaccess($env{'form.filename'},
709: $r->dir_config('lonDefDomain'));
710: unless (($uname) && ($udom)) {
711: $r->log_reason($uname.' at '.$udom.
712: ' trying to publish file '.$env{'form.filename'}.
713: ' - not authorized',
714: $r->filename);
715: return HTTP_NOT_ACCEPTABLE;
716: }
717:
718: my $fn;
719: if ($env{'form.filename'}) {
720: $fn=$env{'form.filename'};
721: $fn=~s/^http\:\/\/[^\/]+\///;
722: $fn=~s/^\///;
723: $fn=~s/(\~|priv\/)($LONCAPA::username_re)//;
724: $fn=~s/\/+/\//g;
725: } else {
726: $r->log_reason($env{'user.name'}.' at '.$env{'user.domain'}.
727: ' unspecified filename for upload', $r->filename);
728: return HTTP_NOT_FOUND;
729: }
730: my $zipupload = '/home/'.$uname.'/public_html'.$fn;
731: my $pathname = &File::Basename::dirname($fn);
732: my $fullpath = '/priv/'.$uname.$pathname;
733: unless ($pathname eq '/') {
734: $fullpath .= '/';
735: }
736:
737: my @areas = ();
738: my %cmsmap = ();
739: my %areaname = ();
740: my $numcrs = 0;
741:
742: &Apache::imsprocessor::ims_config(\@areas,\%cmsmap,\%areaname);
743: # ----------------------------------------------------------- Start page output
744: &Apache::loncommon::content_type($r,'text/html');
745: $r->send_http_header;
746:
747: my $formname_one = 'info';
748: if ($env{'form.phase'} eq 'two') {
749: &jscript_one($fullpath,\$javascript,$formname_one);
750: } elsif ($env{'form.phase'} eq 'three') {
751: &jscript_two(\$javascript,$user,$dom,\$numcrs);
752: } elsif ($env{'form.phase'} eq 'four') {
753: &jscript_three(\$javascript);
754: }
755: $javascript = "<script type=\"text/javascript\">\n//<!--\n$javascript\n// --></script>\n";
756:
757: my $title = 'Upload IMS package to Construction Space';
758: $r->print(&Apache::loncommon::start_page($title, $javascript));
759:
760: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
761: $r->print('<h3><font color=red>'.&mt('Co-Author').': '.$uname.
762: &mt(' at ').$udom.'</font></h3>');
763: }
764: if ($env{'form.phase'} eq 'two') {
765: my $flag = &Apache::lonupload::phasetwo($r,$fn,$uname,$udom,'imsimport');
766: if ($flag eq 'ok') {
767: &display_one($r,$uname,$fn,$fullpath,$formname_one);
768: }
769: } elsif ( ($env{'form.phase'} eq 'three') || ($env{'form.phase'} eq 'four') ) {
770: my $docroot = $env{'form.newdir'};
771: my $newdir = '';
772: if ($docroot =~ m|public_html/(.+)$|) {
773: $newdir = $1;
774: }
775: if ($env{'form.phase'} eq 'three') {
776: &display_two ($r,$zipupload,\@areas,\%areaname,\%cmsmap,$uname,$newdir,\$numcrs,$fullpath);
777: } elsif ($env{'form.phase'} eq 'four') {
778: &display_three ($r,$uname,$udom,\@areas,\%areaname,\%cmsmap,$docroot,$newdir);
779: }
780: } else {
781: &Apache::lonupload::phaseone($r,$fn,$uname,$udom,'imsimport');
782: }
783: $r->print(&Apache::loncommon::end_page());
784: return OK;
785: }
786: 1;
787: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>