Subversion Repositories wimsdev

Rev

Rev 3060 | Rev 3665 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. <script type="text/javascript"  src="$jsdir/zirkel2wims.js"></script>
  2. <script type="text/javascript">
  3.     !!! this is used for filling_in the inputfields myinput[n] after a return: the inputfields are present in a variable-string and thus can "not be filled" by wims... note: if $embed=1 ... WIMS will fill in the rejected answer...see below [id=myinput]
  4.     function refill(){
  5.         var hi="$(reply$n)";
  6.         if(hi.length !=0){
  7.             hi=hi.split(',');
  8.             for(var i=0;i<hi.length;i++){
  9.                 document.getElementById("myinput"+i).value=hi[i];
  10.             }
  11.         }
  12.     }
  13.  
  14.     var maxcookies=20;
  15.     var cookiesize=400;
  16.     var cookiecount=-1;
  17.     var reply="";
  18.     function readapplet(){
  19.         !if $list_of_things = $empty
  20.             reply=zirkel2wims(null,null);
  21.         !else
  22.             !! we decide what we want from the drawing. note the pupil must name the objects correctly
  23.             !! this array should be filled by WIMS : scheme ["type,name1,name2..." , "type,name1,name2..."]
  24.             !! like ["point,p1,p2,p3","line,l1,l2","function,f1,f2,f3","area,poly1","angle,a1","circle,c1","segment,s1"];
  25.             var list_of_things = new Array();
  26.             list_of_things= $list_of_things ;
  27.             var tmp;var tmp2;
  28.             for(var p=0; p<list_of_things.length;p++){
  29.                 tmp=list_of_things[p].split(',');
  30.                 if(tmp[0].length>0){
  31.                     for(var s=1;s<tmp.length;s++){
  32.                         tmp2=zirkel2wims(tmp[0],tmp[s]);if(tmp2 == "error"){return;}else{reply=reply+tmp2;}
  33.                     }
  34.                 }
  35.             }
  36.         !endif
  37.         reply=encodeURIComponent(reply);
  38.        
  39.         !! setting a cookie to save the much too large xml-string...splitting in small cookies...
  40.         !! no way to retreive browser settings for this cookie cache space...all react different
  41.         var myConstruction=document.getElementById("zirkel").getConstruction();
  42.         myConstruction=encodeURIComponent(""+myConstruction+"");
  43.             var date = new Date();date.setTime(date.getTime()+600000);var expires=date.toGMTString();
  44.             cookiecount=0;cookiearray=new Array();var t1=0;var t2=cookiesize;
  45.             totalsize=0;
  46.             while(myConstruction.substring(t1,t2).length>0){
  47.                 cookiearray[cookiecount]=myConstruction.substring(t1,t2);
  48.                 totalsize=(totalsize+cookiesize);cookiecount++;t1=t2;t2=t2+cookiesize;
  49.             }
  50.             if(cookiecount>maxcookies){
  51.                 setAlarm("construction is too big to be stored in cookies \n If the exercise is returned by WIMS for correction,\n You will have to draw it all over again...");
  52.                 cookiecount=-1;
  53.             }
  54.             else
  55.             {
  56.                 for(var p=0;p<cookiecount;p++){
  57.                     document.cookie ="zirkel"+p+"="+cookiearray[p]+"; expires= ; path=/";
  58.                     !!document.cookie ="zirkel"+p+"="+cookiearray[p]+"; expires="+expires+"; path=/";
  59.                 }
  60.             }
  61.     }
  62.    
  63.     function sendanswer(){
  64.         if(document.mydefaultform){
  65.             var extra_answer=new Array();
  66.             var show="";
  67.             var input="";var t1;
  68.             var ml=document.mydefaultform.elements.length;
  69.             var inputfieldnumber=0;
  70.             for(z=0;z<ml;z++){
  71.                 input=document.mydefaultform[z].value;
  72.                 v=input.length;if (v==0){var qu=z+1; setAlarm(r1+"\ "+qu);return;}
  73.                 input=nthroot(input);if(input=="error"){return;}
  74.                 if(input.indexOf(',')!=-1){setAlarm(r4);return;}
  75.                 input=arrows(input,2,"","");if(input=="error"){return;}
  76.                 if(check_f(input)==0){return;}if(check_o(input)==0){return;}
  77.                 if(check_log_NaN(input)==0){return;}if(check_sqrt_NaN(input)==0){return;}
  78.                 input=science(input);if(input=="error"){return;}
  79.                 if(check_x(input)==0){return;}
  80.                 t1=input.indexOf("[");
  81.                 if(t1 !=- 1){
  82.                     if(input.indexOf("sqrt[")!=-1){input=specialroot(input);if(input=="error"){return;}}
  83.                     if(input.indexOf("log[")!=-1){input=speciallog(input);if(input=="error"){return;}}
  84.                     t1=input.indexOf("[");if(t1!=-1){setAlarm(r13);return;}
  85.                 }
  86.                 input=input.replace(/#/g,' ');
  87.                 extra_answer[z]=input;
  88.                 show=show+(z+1)+")  "+input+"\n";
  89.             }
  90.             readapplet();
  91.             var t=confirm(" $send ?\n"+show);
  92.             if(t==true){
  93.                 extra_answer=encodeURIComponent( extra_answer );
  94.                 var URL = '$wims_ref_name?session=$session&+module=$module&+cmd=reply&+reply$n='+reply+','+extra_answer+'&+myvar$n='+cookiecount;
  95.                 document.location.href = URL;
  96.                 document.getElementById("zirkel").destroy();
  97.             }
  98.         }
  99.         else
  100.         {    
  101.             readapplet();
  102.             var t=confirm(" $send ?");
  103.             if(t==true){
  104.                 var URL = '$wims_ref_name?session=$session&+module=$module&+cmd=reply&+reply$n='+reply+'&+myvar$n='+cookiecount ;
  105.                 document.location.href = URL;
  106.                 !!document.getElementById("zirkel").destroy();
  107.             }
  108.         }
  109.     }        
  110.  
  111.     function dontknow(){
  112.         var t=confirm(" $dontknow ?");
  113.         if(t==true){URL = '$wims_ref_name?session=$session&+module=$module&+cmd=reply&+reply$n=%3F' ;
  114.         document.location.href = URL;document.getElementById("zirkel").destroy();
  115.         }                                                                                                                                                                
  116.     }
  117. </script>
  118.  
  119. <p align="center">
  120. <table summary="" bgcolor="$bgcolor1" cellpadding="$cellpadding" cellspacing="$cellspacing">
  121.     <tr>
  122.     <td valign="top" align="left">
  123.         $(question$n)
  124.         !if $(formula$n) != $empty
  125.             <br>
  126.             !insmath $(formula$n)
  127.         !endif
  128.         !if $exotext != $empty
  129.             <br>
  130.             $exotext
  131.         !endif
  132.         !if $inputs>0
  133.             <table summary="">
  134.                 <form name="mydefaultform" id="mydefaultform "action="">
  135.                     !for i=1 to $inputs
  136.                         <tr>
  137.                         <td>
  138.                             $(inputtext$i)
  139.                         </td>
  140.                         <td>
  141.                             $m_rightarrow
  142.                         </td>
  143.                         <td>
  144.                         !if $wims_user=supervisor
  145.                             !set voorzeggen=!item $i of $(answer$n)
  146.                             <input id="myinput$[$i-1]" style=$textareastyle name="myinput$[$i-1]" size="$cols" value="$voorzeggen">
  147.                         !else
  148.                             <input id="myinput$[$i-1]" style=$textareastyle name="myinput$[$i-1]" size="$cols" value="$(myinput$[$i-1])">
  149.                         !endif
  150.                         </td>
  151.                         </tr>
  152.                     !next i
  153.                 </form>
  154.             </table>
  155.         !endif
  156.     </td>
  157.     !if $XSIZE>640
  158.     </tr><tr>
  159.     !endif
  160.     <td  valign="top">
  161.         !if $width=$empty
  162.             !set width=640
  163.             !set height=480
  164.         !endif
  165.         <p align="center">
  166.             <applet id="zirkel" name="zirkel" code="rene.zirkel.ZirkelApplet.class" codebase="$appletdir" archive="zirkel.jar" width=$xsize height=$ysize MAYSCRIPT>
  167.                 <param name="language" value="$taal">
  168.                 $var1
  169.                 $nojava
  170.             </applet>
  171.         </p>
  172.     </td>
  173.     </tr>
  174. </table>
  175. <table summary="">
  176.     <tr>
  177.     <th>
  178.         <input type=button style="$mybuttonstyle" onclick="sendanswer();" name="but1" value="$send">
  179.     </th>
  180.     <th>
  181.         <input type=button style="$mybuttonstyle" onclick="dontknow();" name="but2" value="$dontknow">
  182.     </th>
  183.     </tr>
  184. </table>
  185. </p>
  186. !if $(myvar$n) != $empty
  187.     !if $(myvar$n)>-1
  188.     !! get the stored cookies .
  189.     <script type="text/javascript">
  190.         var cookiecount=$(myvar$n) ;
  191.         function get_cookie(Name) {
  192.             var search = Name + "=";
  193.             var returnvalue = "";var end;var offset;
  194.             if (document.cookie.length > 0) {
  195.                 offset = document.cookie.indexOf(search);
  196.                 if (offset != -1) {
  197.                     offset += search.length;
  198.                     end = document.cookie.indexOf(";", offset);
  199.                     if (end == -1) end = document.cookie.length;
  200.                     returnvalue=unescape(document.cookie.substring(offset, end))
  201.                 }
  202.             }
  203.             return returnvalue;
  204.         }
  205.         var test="";var stored_construction="";
  206.         for(var p=0;p<=cookiecount;p++){
  207.             test = get_cookie("zirkel"+p);
  208.             if(test.length != 0){
  209.                 stored_construction=stored_construction+""+test;
  210.             }
  211.         }
  212.         var test=decodeURIComponent(stored_construction);
  213.         document.getElementById("zirkel").putConstruction(test);
  214.     </script>
  215.     !endif
  216. !endif
  217. !!! after the inputelements are in the DOM-tree: fill-in the previous answers
  218. <script type="text/javascript">
  219.     try{document.onload=refill();}catch(e){}
  220. </script>
  221.