changed all the POST with option/required_param functions
[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->popup)) {
19         $form->popup = "0";
20     }
21     if (empty($form->datadir)) {
22         $form->datadir = "";
23     }
24     if (empty($form->maxgrade)) {
25         $form->maxgrade = "";
26     }
27     if (empty($form->grademethod)) {
28         $form->grademethod = "0";
29     }
30     if (empty($form->hidebrowse)) {
31         $form->hidebrowse = "0";
32     }
33     if (empty($form->hidetoc)) {
34         $form->hidetoc = "0";
35     }
36     if (empty($form->width)) {
37         $form->width = $CFG->scorm_framewidth;
38     }
39     if (empty($form->height)) {
40         $form->height = $CFG->scorm_frameheight;
41     }
43     $scormid = '';
44     if (!empty($form->instance)) {
45         $scormid = '&instance='.$form->instance;
46     }
47     $datadir = '';
48     if (!empty($form->datadir)) {
49         $datadir = '&datadir='.$form->datadir;
50     }
51     $sessionkey = '';
52     if (!empty($form->sesskey)) {
53         $sessionkey = '&sesskey='.$form->sesskey;
54     }
56     $strfilename = get_string("coursepacket", "scorm");
57     $strchooseafile = get_string("chooseapacket", "scorm");
58 ?>
60 <script type="text/javascript" src="<?php p($CFG->wwwroot) ?>/mod/scorm/request.js" ></script>
61 <script type="text/javascript">
62     function validate_scorm(theform,filename) {
63         var myRequest = NewHttpReq();
64         result = DoRequest(myRequest,"<?php p($CFG->wwwroot) ?>/mod/scorm/validate.php","id=<?php p($form->course) ?>&reference="+filename+"<?php echo $sessionkey.$scormid.$datadir ?>");
65         results = result.split('\n');
66         result = '';
67         errorlogs = '';
68         datadir = '';
69         for (i=0;i<results.length;i++) {
70             element = results[i].split('=');
71             switch(element[0]) {
72                case 'result':
73                   result = element[1];
74                break;
75                case 'launch':
76                   launch = element[1];
77                break;
78                case 'datadir':
79                   datadir = element[1];
80                break;
81                case 'pkgtype':
82                   pkgtype = element[1];
83                break;
84                case 'errorlogs':
85                    i++;
86                    do {
87                       errorlogs.concat(results[i]+'\n');
88                       i++;
89                    } while (i<results.lenght());
91                break;
92             }
93         }
94         if ((result == "found") || (result == "regular")) {
95             theform.datadir.value = datadir;
96             theform.pkgtype.value = pkgtype;
97             theform.launch.value = launch;
98             if (launch == 0) {
99                 if ('<?php echo $scormid ?>' != '') {
100                     return confirm('<?php print_string('trackingloose','scorm') ?>');
101                 }
102             }
103             return true;
104         } else {
105             result = '<?php print_string('validation','scorm') ?>: '+ result + '\n';
106             if (errorlogs != '') {
107                result.concat('<?php print_string('errorlogs','scorm') ?>:\n'+errorlogs);
108             }
109             alert(result);
110             return false;
111         }
112     }
114     function checkmethod (grademethod,maxgrade) {
115         if (grademethod.options[grademethod.selectedIndex].value == 0) {
116             maxgrade.disabled=true;
117         } else {
118             maxgrade.disabled=false;
119         }
120     }
121     
122     function showhide (id, set) {
123         divobj = document.getElementById(id);
124         butobj = document.getElementById(id+'button');
125         prefobj = document.getElementById(id+'pref');
126         if (set == true) {
127             if (prefobj.value == '1') {
128                 divobj.style.display = 'block';
129                 butobj.value = '<?php print_string("hidesettings") ?>';
130             } else {
131                 divobj.style.display = 'none';
132                 butobj.value = '<?php print_string("showsettings") ?>...';
133             }
134         } else {
135             if (prefobj.value == '1') {
136                 divobj.style.display = 'none';
137                 butobj.value = '<?php print_string("showsettings") ?>...';
138                 prefobj.value = '0';
139             } else {
140                 divobj.style.display = 'block';
141                 butobj.value = '<?php print_string("hidesettings") ?>';
142                 prefobj.value = '1';
143             }
144         }
145     }
146 </script>
148 <form name="form" method="post" action="mod.php" onsubmit="return validate_scorm(document.form,document.form.reference.value);">
149     <table cellpadding="5">
150         <tr valign="top">
151             <td align="right"><b><?php print_string("name") ?>:</b></td>
152             <td>
153                 <input type="text" name="name" size="50" value="<?php p($form->name) ?>" alt="<?php print_string("name") ?>" />
154             </td>
155         </tr>
156         <tr valign="top">
157             <td align="right"><b><?php print_string("summary") ?>:</b><br />
158                 <?php helpbutton("summary", get_string("summary"), "scorm", true, true) ?>
159             </td>
160             <td>
161                 <?php print_textarea($usehtmleditor, 10, 50, 680, 400, "summary", $form->summary); ?>
162             </td>
163         </tr>
164         <tr valign="top">
165             <td align="right" nowrap="nowrap">
166                 <b><?php echo $strfilename?>:</b>
167             </td>
168             <td>
169                 <?php
170                     echo "<input name=\"reference\" size=\"50\" value=\"$form->reference\" alt=\"$strfilename\" />&nbsp;";
171                     button_to_popup_window ("/files/index.php?id=$course->id&amp;choose=form.reference",
172                                             "coursefiles", $strchooseafile, 500, 750, $strchooseafile);
173                     helpbutton("package", get_string("coursepacket", "scorm"), "scorm", true);
174                 ?>
175             </td>
176         </tr>
177         <tr valign="top">
178             <td align="right"><b><?php print_string("grademethod", "scorm") ?>:</b></td>
179             <td>
180             <?php
181                 choose_from_menu($SCORM_GRADE_METHOD, 'grademethod', "$form->grademethod", '','checkmethod(this,document.form.maxgrade);');
182                 helpbutton("grademethod", get_string("grademethod","scorm"), "scorm");
183             ?>
184             </td>
185         </tr>
186         <tr valign="top">
187             <td align="right"><b><?php print_string("maximumgrade") ?>:</b></td>
188             <td>
189             <?php
190                 for ($i=100; $i>=1; $i--) {
191                     $grades[$i] = $i;
192                 }
193                 $disabled = $form->grademethod=='0';
194                 choose_from_menu($grades, 'maxgrade', "$form->maxgrade", '','','0',false,$disabled);
195                 helpbutton('maxgrade', get_string('maximumgrade'), 'scorm');
196             ?>
197             </td>
198         </tr>
199         <tr><td colspan="2"><hr /></td></tr>
201         <tr>
202             <td align="right"><b><?php print_string("advanced", "scorm") ?>:</b></td>
203             <td>
204                 <input type="button" value="<?php print_string("hidesettings") ?>" id="advancedsettingsbutton" onclick="javascrip: return showhide('advancedsettings');" />
205                 <input type="hidden" name="advancedsettingspref" id="advancedsettingspref" 
206                        value="<?php echo get_user_preferences('scorm_advancedsettingspref', $CFG->scorm_advancedsettings); ?>" />
207                 <?php helpbutton("advanced", get_string("advanced", "scorm"), "scorm", true) ?>
208             </td>
209         </tr>
210         <tr>
211             <td colspan="2">
212                 <div id="advancedsettings">
213                     <table align="center">
214                         <tr>
215                             <td align="right"><b><?php print_string("autocontinue","scorm") ?>:</b></td>
216                             <td>
217                             <?php
218                                 $options = array();
219                                 $options[0]=get_string("no");
220                                 $options[1]=get_string("yes");
221                                 choose_from_menu ($options, "auto", $form->auto,'');
222                                 helpbutton("autocontinue", get_string("autocontinue", "scorm"), "scorm", true);
223                             ?>
224                             </td>
225                         </tr>
226                         <tr>
227                             <td align="right"><b><?php print_string("hidebrowse","scorm") ?>:</b></td>
228                             <td>
229                             <?php
230                                 $options = array();
231                                 $options[0]=get_string("no");
232                                 $options[1]=get_string("yes");
233                                 choose_from_menu ($options, "hidebrowse", $form->hidebrowse, '');
234                                 helpbutton("browsemode", get_string("hidebrowse", "scorm"), "scorm", true);
235                             ?>
236                             </td>
237                         </tr>
238                         <tr>
239                             <td align="right"><b><?php print_string("hidetoc","scorm") ?>:</b></td>
240                             <td>
241                             <?php
242                                 $options = array();
243                                 $options[0]=get_string("no");
244                                 $options[1]=get_string("yes");
245                                 choose_from_menu ($options, "hidetoc", $form->hidetoc, '');
246                                 helpbutton("tocdisplay", get_string("hidetoc", "scorm"), "scorm", true);
247                             ?>
248                             </td>
249                         </tr>
250                     </table>
251                 </div>
252             </td>
253         </tr>
254         <tr>
255             <td align="right"><b><?php print_string("window", "scorm") ?>:</b></td>
256             <td>
257                 <input type="button" value="<?php print_string("hidesettings") ?>" id="windowsettingsbutton" onclick="javascrip: return showhide('windowsettings');" />
258                 <input type="hidden" name="windowsettingspref" id="windowsettingspref" 
259                        value="<?php echo get_user_preferences('scorm_windowsettingspref', $CFG->scorm_windowsettings); ?>" />
260                 <?php helpbutton("window", get_string("window", "scorm"), "scorm", true) ?>
261             </td>
262         </tr>
263         <tr>
264             <td colspan="2">
265                 <div id="windowsettings">
266                     <table align="center">
267                         <tr>
268                             <td align="right"><b><?php print_string("popup","scorm") ?>:</b></td>
269                             <td>
270                             <?php
271                                 $options = array();
272                                 $options[0]=get_string("no");
273                                 $options[1]=get_string("yes");
274                                 choose_from_menu ($options, "popup", $form->popup,'');
275                                 helpbutton("popupwindow", get_string("popup", "scorm"), "scorm", true);
276                             ?>
277                             </td>
278                         </tr>
279                         <tr valign="top">
280                             <td align="right">
281                                 <b><?php print_string("stagesize","scorm") ?></b>
282                                 <?php helpbutton("size", get_string("stagesize", "scorm"), "scorm", true); ?>
283                             </td>
284                             <td>&nbsp;</td>
285                         </tr>
286                         <tr valign="top">
287                             <td align="right"><b><?php print_string("width","scorm") ?>:</b></td>
288                             <td>
289                                <input type="text" name="width" value="<?php echo $form->width ?>" size="4" />
290                             </td>
291                         </tr>
292                         <tr valign="top">
293                             <td align="right"><b><?php print_string("height","scorm") ?>:</b></td>
294                             <td>
295                                <input type="text" name="height" value="<?php echo $form->height ?>" size="4" />
296                             </td>
297                         </tr>
298                     </table>
299                 </div>
300                 <script language="javascript" type="text/javascript">
301                     showhide('advancedsettings', true);
302                     showhide('windowsettings', true);
303                 </script>
304             </td>
305         </tr>
306     </table>
307     <input type="hidden" name="datadir" value="<?php p($form->datadir) ?>" />
308     <input type="hidden" name="pkgtype" value="<?php p($form->pkgtype) ?>" />
309     <input type="hidden" name="launch"  value="<?php p($form->launch) ?>" />
310     <?php
311         $scorms = get_all_instances_in_course("scorm", $course);
312         $coursescorm = current($scorms);
313         if (($course->format == 'scorm') && ((count($scorms) == 0) || ($form->instance == $coursescorm->id))) {
314     ?>
315     <input type="hidden" name="redirect"       value="yes" />
316     <input type="hidden" name="redirecturl"    value="../course/view.php?id=<?php p($form->course) ?>" />    
317     <?php
318         } 
319     ?>
320     <input type="hidden" name="course"  value="<?php p($form->course) ?>" />
321     <input type="hidden" name="sesskey" value="<?php p($form->sesskey) ?>" />
322     <input type="hidden" name="section" value="<?php p($form->section) ?>" />
323     <input type="hidden" name="module"  value="<?php p($form->module) ?>" />
324     <input type="hidden" name="mode"    value="<?php p($form->mode) ?>" />
325     <input type="hidden" name="coursemodule"    value="<?php p($form->coursemodule) ?>" />
326     <input type="hidden" name="modulename"      value="<?php p($form->modulename) ?>" />
327     <input type="hidden" name="instance"        value="<?php p($form->instance) ?>" />
328     <center>
329         <input type="submit" value="<?php print_string('savechanges') ?>" />
330         <input type="button" name="cancel" value="<?php print_string('cancel') ?>" onclick="document.location='view.php?id=<?php echo $form->course ?>'" />
331     </center>
332 </form>