Added user activity support
[moodle.git] / mod / scorm / mod.html
1 <?php
2     require_once("$CFG->dirroot/mod/scorm/lib.php");
3     if (empty($form->name)) {
4         $form->name = "";
5     }
6     if (empty($form->reference)) {
7         $form->reference = "";
8     }
9     if (empty($form->summary)) {
10         $form->summary = "";
11     }
12     if (empty($form->launch)) {
13         $form->launch = "";
14     }
15     if (empty($form->auto)) {
16         $form->auto = "";
17     }
18     if (empty($form->datadir)) {
19         $form->datadir = "";
20     }
21     if (empty($form->maxgrade)) {
22         $form->maxgrade = "";
23     }
24     if (empty($form->grademethod)) {
25         $form->grademethod = "0";
26     }
27     if (empty($form->browsemode)) {
28         $form->browsemode = "1";
29     }
30     if (empty($form->width)) {
31         $form->width = $CFG->scorm_framewidth;
32     }
33     if (empty($form->height)) {
34         $form->height = $CFG->scorm_frameheight;
35     }
37     $scormid = '';
38     if (!empty($form->instance)) {
39         $scormid = '&instance='.$form->instance;
40     }
41     $datadir = '';
42     if (!empty($form->datadir)) {
43         $datadir = '&datadir='.$form->datadir;
44     }
45     $sessionkey = '';
46     if (!empty($form->sesskey)) {
47         $sessionkey = '&sesskey='.$form->sesskey;
48     }
49 ?>
51 <script type="text/javascript" src="<?php p($CFG->wwwroot) ?>/mod/scorm/request.js" ></script>
52 <script type="text/javascript">
53     function validate_scorm(theform,filename) {
54        //alert(filename);
55         var myRequest = NewHttpReq();
56        result = DoRequest(myRequest,"<?php p($CFG->wwwroot) ?>/mod/scorm/validate.php","id=<?php p($form->course) ?>&reference="+filename+"<?php echo $sessionkey.$scormid.$datadir ?>");
57        //alert(result);
58         results = result.split('\n');
59         result = '';
60         errorlogs = '';
61         datadir = '';
62         for (i=0;i<results.length;i++) {
63             element = results[i].split('=');
64             //alert(element);
65             switch(element[0]) {
66                case 'result':
67                   result = element[1];
68                break;
69                case 'launch':
70                   launch = element[1];
71                break;
72                case 'datadir':
73                   datadir = element[1];
74                break;
75                case 'pkgtype':
76                   pkgtype = element[1];
77                break;
78                case 'errorlogs':
79                    i++;
80                    do {
81                       errorlogs.concat(results[i]+'\n');
82                       i++;
83                    } while (i<results.lenght());
85                break;
86             }
87         }
88         if ((result == "found") || (result == "regular")) {
89             theform.datadir.value = datadir;
90             theform.pkgtype.value = pkgtype;
91             theform.launch.value = launch;
92             if (launch == 0) {
93                 if ('<?php echo $scormid ?>' != '') {
94                     return confirm('<?php print_string('trackingloose','scorm') ?>');
95                 }
96             }
97             return true;
98         } else {
99             result = '<?php print_string('validation','scorm') ?>: '+ result + '\n';
100             if (errorlogs != '') {
101                result.concat('<?php print_string('errorlogs','scorm') ?>:\n'+errorlogs);
102             }
103             alert(result);
104             return false;
105         }
106     }
108     function checkmethod (grademethod,maxgrade) {
109         if (grademethod.options[grademethod.selectedIndex].value == 0) {
110             maxgrade.disabled=true;
111         } else {
112             maxgrade.disabled=false;
113         }
114     }
115 </script>
117 <form name="form" method="post" action="mod.php" onsubmit="return validate_scorm(document.form,document.form.reference.value);">
118     <table cellpadding="5">
119         <tr valign="top">
120             <td align="right"><b><?php print_string("name") ?>:</b></td>
121             <td>
122                 <input type="text" name="name" size="50" value="<?php p($form->name) ?>" alt="<?php print_string("name") ?>" />
123             </td>
124         </tr>
125 <?php
126     $strfilename = get_string("coursepacket", "scorm");
127     $strchooseafile = get_string("chooseapacket", "scorm");
128 ?>
129         <tr valign="top">
130             <td align="right"><b><?php print_string("summary") ?>:</b><br />
131                <font size="1">
132                <?php helpbutton("summary", get_string("summary"), "scorm", true, true) ?>
133               </font>
134             </td>
135             <td>
136         <?php print_textarea($usehtmleditor, 10, 50, 680, 400, "summary", $form->summary); ?>
137             </td>
138         </tr>
139         <tr valign="top">
140             <td align="right" nowrap="nowrap">
141                 <b><?php echo $strfilename?>:</b>
142             </td>
143             <td>
144                 <?php
145                     echo "<input name=\"reference\" size=\"50\" value=\"$form->reference\" alt=\"$strfilename\" />&nbsp;";
146                     button_to_popup_window ("/files/index.php?id=$course->id&amp;choose=form.reference",
147                                          "coursefiles", $strchooseafile, 500, 750, $strchooseafile);
148                     helpbutton("package", get_string("coursepacket", "scorm"), "scorm", true);
149                 ?>
150             </td>
151         </tr>
152         <tr valign="top">
153             <td align="right"><b><?php print_string("grademethod", "scorm") ?>:</b></td>
154             <td>
155             <?php
156                 choose_from_menu($SCORM_GRADE_METHOD, 'grademethod', "$form->grademethod", '','checkmethod(this,document.form.maxgrade);');
157                 helpbutton("grademethod", get_string("grademethod","scorm"), "scorm");
158             ?>
159             </td>
160         </tr>
161         <tr valign="top">
162             <td align="right"><b><?php print_string("maximumgrade") ?>:</b></td>
163             <td>
164             <?php
165                 for ($i=100; $i>=1; $i--) {
166                     $grades[$i] = $i;
167                 }
168                $disabled = $form->grademethod=='0';
169                 choose_from_menu($grades, 'maxgrade', "$form->maxgrade", '','','0',false,$disabled);
170                 helpbutton('maxgrade', get_string('maximumgrade'), 'scorm');
171             ?>
172             </td>
173         </tr>
174         <tr>
175             <td align="right"><b><?php print_string("autocontinue","scorm") ?>:</b></td>
176             <td>
177             <?php
178                 $options = array();
179                 $options[0]=get_string("no");
180                 $options[1]=get_string("yes");
181                 choose_from_menu ($options, "auto", $form->auto,'');
182                 helpbutton("autocontinue", get_string("autocontinue", "scorm"), "scorm", true);
183             ?>
184             </td>
185         </tr>
186         <tr>
187             <td align="right"><b><?php print_string("enablebrowse","scorm") ?>:</b></td>
188             <td>
189             <?php
190                 $options = array();
191                 $options[0]=get_string("no");
192                 $options[1]=get_string("yes");
193                 choose_from_menu ($options, "browsemode", $form->browsemode, '');
194                 helpbutton("browsemode", get_string("browsemode", "scorm"), "scorm", true);
195             ?>
196             </td>
197         </tr>
198         <tr valign="top">
199             <td align="right"><b><?php print_string("width","scorm") ?>:</b></td>
200             <td>
201                <input type="text" name="width" value="<?php echo $form->width ?>" size="4" />
202                 <?php helpbutton("width", get_string("width", "scorm"), "scorm", true); ?>
203             </td>
204         </tr>
205         <tr valign="top">
206             <td align="right"><b><?php print_string("height","scorm") ?>:</b></td>
207             <td>
208                <input type="text" name="height" value="<?php echo $form->height ?>" size="4" />
209                 <?php helpbutton("height", get_string("height", "scorm"), "scorm", true); ?>
210             </td>
211         </tr>
212     </table>
213     <input type="hidden" name="datadir" value="<?php p($form->datadir) ?>" />
214     <input type="hidden" name="pkgtype" value="<?php p($form->pkgtype) ?>" />
215     <input type="hidden" name="launch"  value="<?php p($form->launch) ?>" />
217     <input type="hidden" name="course"  value="<?php p($form->course) ?>" />
218     <input type="hidden" name="sesskey" value="<?php p($form->sesskey) ?>" />
219     <input type="hidden" name="section" value="<?php p($form->section) ?>" />
220     <input type="hidden" name="module"  value="<?php p($form->module) ?>" />
221     <input type="hidden" name="mode"    value="<?php p($form->mode) ?>" />
222     <input type="hidden" name="coursemodule"    value="<?php p($form->coursemodule) ?>" />
223     <input type="hidden" name="modulename"      value="<?php p($form->modulename) ?>" />
224     <input type="hidden" name="instance"        value="<?php p($form->instance) ?>" />
225     <center>
226         <input type="submit" value="<?php print_string('savechanges') ?>" />
227         <input type="button" name="cancel" value="<?php print_string('cancel') ?>" onclick="document.location='view.php?id=<?php echo $form->course ?>'" />
228     </center>
229 </form>