First step to SCORM2004, new communication subsystem
[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->popup)) {
22         $form->popup = "";
23     }
24     if (empty($form->maxgrade)) {
25         $form->maxgrade = "";
26     }
27     if (empty($form->grademethod)) {
28         $form->grademethod = "0";
29     }
30     $scormid ='';
31     if (!empty($form->instance)) {
32         $scormid = '&instance='.$form->instance;
33     }
34     $datadir ='';
35     if (!empty($form->datadir)) {
36         $datadir = '&datadir='.$form->datadir;
37     }
38 ?>
40 <script type="text/javascript" src="<?php p($CFG->wwwroot) ?>/mod/scorm/request.js" >
41 </script>
42 <script type="text/javascript">
43     function validate_scorm(theform,filename) {
44         //alert(filename);
45         var myRequest = NewHttpReq();
46         result = DoRequest(myRequest,"<?php p($CFG->wwwroot) ?>/mod/scorm/validate.php?id=<?php p($form->course) ?>&reference="+filename+"<?php echo $scormid.$datadir ?>");
47         //alert(result);
48         results = result.split('\n');
49         if ((results[0] == "found") || (results[0] == "regular")) {
50             theform.datadir.value = results[2];
51             if (results[1] == 0) {
52                 theform.launch.value = results[1];
53                 if ('<?php echo $scormid ?>' != '') {
54                     return confirm('<?php print_string('trackingloose','scorm') ?>');
55                 }
56             }
57             return true;
58         } else {
59             result = '<?php print_string('validation','scorm') ?>: '+ results[0] + '\n';
60             result.concat('<?php print_string('errorlogs','scorm') ?>:\n',results[3]);
61             alert(result);
62             return false;
63         }
64     }
65 </script>
67 <form name="form" method="post" action="mod.php" onsubmit="return validate_scorm(document.form,document.form.reference.value);">
68     <table cellpadding="5">
69         <tr valign="top">
70             <td align="right"><b><?php print_string("name") ?>:</b></td>
71             <td>
72                 <input type="text" name="name" size="50" value="<?php p($form->name) ?>" alt="<?php print_string("name") ?>" />
73             </td>
74         </tr>
75 <?php 
76     $strfilename = get_string("coursepacket", "scorm");
77     $strchooseafile = get_string("chooseapacket", "scorm");
78 ?>
79         <tr valign="top">
80             <td align="right"><b><?php print_string("summary") ?>:</b><br />
81                 <font size="1">
82                 <?php helpbutton("summary", get_string("summary"), "scorm", true, true) ?>
83                 </font>
84             </td>
85             <td>
86         <?php print_textarea($usehtmleditor, 10, 50, 680, 400, "summary", $form->summary); ?>
87             </td>
88         </tr>
89         <tr valign="top">
90             <td align="right" nowrap="nowrap">
91                 <b><?php echo $strfilename?>:</b>
92             </td>
93             <td>
94                 <?php
95                     echo "<input name=\"reference\" size=\"50\" value=\"$form->reference\" alt=\"$strfilename\" />&nbsp;";
96                     button_to_popup_window ("/files/index.php?id=$course->id&amp;choose=form.reference", 
97                                             "coursefiles", $strchooseafile, 500, 750, $strchooseafile);
98                     helpbutton("package", get_string("coursepacket", "scorm"), "scorm", true);
99                 ?>
100             </td>
101         </tr>
102 <?php   
103         $strnewwindow     = get_string("newwindow", "scorm");
104         $strnewwindowopen = get_string("newwindowopen", "scorm");
105         foreach ($SCORM_WINDOW_OPTIONS as $optionname) {
106             $stringname = "str$optionname";
107             $$stringname = get_string("new$optionname", "scorm");
108             $window->$optionname = "";
109             $jsoption[] = "\"$optionname\"";
110         }
111         $alljsoptions = implode(",", $jsoption);
112         
113         if ($form->instance) {     // Re-editing
114             if ($form->popup == "") {
115                 $newwindow = "";   // Disable the new window
116                 foreach ($SCORM_WINDOW_OPTIONS as $optionname) {
117                     $defaultvalue = "scorm_popup$optionname";
118                     $window->$optionname = $CFG->$defaultvalue;
119                 }
120             } else {
121                 $newwindow = "checked";
122                 $rawoptions = explode(',', $form->popup); 
123                 foreach ($rawoptions as $rawoption) {
124                     $option = explode('=', trim($rawoption));
125                     if (($option[0] != 'location') && ($option[0] != 'menubar') && ($option[0] != 'toolbar')) {
126                         $optionname = $option[0];
127                         $optionvalue = $option[1];
128                         if ($optionname == "height" or $optionname == "width") {
129                             $window->$optionname = $optionvalue;
130                         } else if ($optionvalue == 1) {
131                             $window->$optionname = "checked";
132                         }
133                     }
134                 }
135             }
136         } else {
137             foreach ($SCORM_WINDOW_OPTIONS as $optionname) {
138                 $defaultvalue = "scorm_popup$optionname";
139                 $window->$optionname = $CFG->$defaultvalue;
140             }
141             $newwindow = $CFG->scorm_popup;
142         }    
143 ?>
144         <tr valign="top">
145             <td align="right"><b><?php print_string("grademethod", "scorm") ?>:</b></td>
146             <td>
147             <?php
148                 choose_from_menu($SCORM_GRADE_METHOD, "grademethod", "$form->grademethod", "");
149                 helpbutton("grademethod", get_string("grademethod","scorm"), "scorm");
150             ?>
151             </td>
152         </tr>
153         <tr valign="top">
154             <td align="right"><b><?php print_string("maximumgrade") ?>:</b></td>
155             <td>
156             <?php
157                 for ($i=100; $i>=1; $i--) {
158                     $grades[$i] = $i;
159                 }
161                 choose_from_menu($grades, "maxgrade", "$form->maxgrade", "");
162                 helpbutton("maxgrade", get_string("maximumgrade"), "scorm");
163             ?>
164             </td>
165         </tr>    
166         <tr>
167             <td align="right"><b><?php print_string("display", "scorm") ?>:</b></td>
168             <td>
169                 <input type="button" value="hide settings" id="windowsettingsbutton" onclick="javascript: return showhide('windowsettings');" />
170                 <input type="hidden" name="windowsettingspref" id="windowsettingspref" 
171                  value="<?php echo get_user_preferences('windowsettingspref', $CFG->scorm_windowsettings); ?>" />
172                 <?php helpbutton("window", get_string("display", "scorm"), "scorm", true) ?>
173             </td>
174         </tr>
175     </table>
176     <script type="text/javascript">
177         var subitems = [<?php echo $alljsoptions; ?>];
178                     
179         function autowindow(set) {
180             divobj = document.getElementById('autocontinue');
181             if (document.form.newwindow.checked) {
182                 divobj.style.display = 'none';
183             } else {
184                 divobj.style.display = 'block';
185             }
186         }
187                   
188         function showhide (id, set) {
189             divobj = document.getElementById(id);
190             butobj = document.getElementById(id+'button');
191             prefobj = document.getElementById(id+'pref');
192             if (set == true) {
193                 if (prefobj.value == '1') {
194                     divobj.style.display = 'block';
195                     butobj.value = '<?php print_string("hidesettings") ?>';
196                 } else {
197                     divobj.style.display = 'none';
198                     butobj.value = '<?php print_string("showsettings") ?>...';
199                 }
200             } else {
201                 if (prefobj.value == '1') {
202                     divobj.style.display = 'none';
203                     butobj.value = '<?php print_string("showsettings") ?>...';
204                     prefobj.value = '0';
205                 } else {
206                     divobj.style.display = 'block';
207                     butobj.value = '<?php print_string("hidesettings") ?>';
208                     prefobj.value = '1';
209                 }
210             }
211         }
212     </script>
213  
214  <div id="windowsettings" align="center">
215     <table>
216         <tr valign="top">
217             <td align="right" nowrap="nowrap">
218                 <b><?php p($strnewwindow) ?>:</b>
219             </td>
220             <td>
221                 <input name="setnewwindow" type="hidden" value="1" />
222                 <input name="newwindow" type="checkbox" value="1" onclick="autowindow();return lockoptions('form','newwindow', subitems);" <?php echo $newwindow ?> /> 
223                 <?php echo $strnewwindowopen."\n"; ?>
224                 <ul style='list-style-type:none;'><li>
225                 <?php
226                      foreach ($window as $name => $value) {
227                          if ($name == "height" or $name == "width") {
228                              continue;
229                          }
230                          echo "\t\t<input name=\"h$name\" type=\"hidden\" value=\"0\" />\n";
231                          if ($window->$name == 'checked') {
232                              $window->$name = 'checked="checked"';
233                          }
234                          echo "\t\t<input name=\"$name\" type=\"checkbox\" value=\"1\" ".$window->$name." /> ";
235                          $stringname = "str$name";
236                          echo $$stringname."<br />\n";
237                      }
238                 ?>
240                 <input name="hwidth" type="hidden" value="0" />
241                 <input name="width" type="text" size="4" value="<?php p($window->width) ?>" alt="width" /> <?php p($strwidth) ?><br />
242                 <input name="hheight" type="hidden" value="0" />
243                 <input name="height" type="text" size="4" value="<?php p($window->height) ?>" alt="height" /> <?php p($strheight) ?><br />
244                 <?php
245                      if (!$newwindow) {
246                          echo "<script type=\"text/javascript\">\n<!--\n";
247                          echo "\tlockoptions('form','newwindow', subitems);";
248                          echo "\n-->\n</script>";
249                      }
250                  ?>
251                  </li></ul>
252              </td>
253          </tr>
254       </table>
255       <div id="autocontinue">
256         <table>
257             <tr>
258             <td align="right"><b><?php print_string("autocontinue","scorm") ?>:</b></td>
259                 <td>
260                 <?php
261                 $options = array();
262                 $options[0]=get_string("no");
263                 $options[1]=get_string("yes");
264                 choose_from_menu ($options, "auto", $form->auto);
265                 helpbutton("autocontinue", get_string("autocontinue", "scorm"), "scorm", true);
266                 ?>
267                 </td>
268             </tr>
269         </table>
270      </div>
271   </div>
272     <script type="text/javascript">
273     <?php
274         if ($newwindow == "checked") {
275             echo "autowindow();\n";
276             echo "showhide('windowsettings',false);\n";
277             $newwindow = "checked='checked'";
278         } else {
279             echo "showhide('windowsettings',true);\n";
280         }
281     ?>
282     </script>
283     <input type="hidden" name="datadir" value="<?php p($form->datadir) ?>" />
284     <input type="hidden" name="launch"  value="<?php p($form->launch) ?>" />
285     <input type="hidden" name="popup"   value="<?php p($form->popup) ?>" />
286     <input type="hidden" name="auto"    value="<?php p($form->auto) ?>" />
287     <input type="hidden" name="maxgrade"        value="<?php p($form->maxgrade) ?>" />
288     <input type="hidden" name="grademethod"     value="<?php p($form->grademethod) ?>" />
289     
290     <input type="hidden" name="course"  value="<?php p($form->course) ?>" />
291     <input type="hidden" name="sesskey" value="<?php p($form->sesskey) ?>" />
292     <input type="hidden" name="coursemodule"    value="<?php p($form->coursemodule) ?>" />
293     <input type="hidden" name="section" value="<?php p($form->section) ?>" />
294     <input type="hidden" name="module"  value="<?php p($form->module) ?>" />
295     <input type="hidden" name="modulename"      value="<?php p($form->modulename) ?>" />
296     <input type="hidden" name="instance"        value="<?php p($form->instance) ?>" />
297     <input type="hidden" name="mode"            value="<?php p($form->mode) ?>" />
298     <center>
299         <input type="submit" value="<?php print_string('savechanges') ?>" />
300         <input type="button" name="cancel" value="<?php print_string('cancel') ?>" onclick="document.location='view.php?id=<?php echo $form->course ?>'" />
301     </center>
302 </form>