source: extensions/mypolls/templates/plugin_public_question.tpl @ 13279

Last change on this file since 13279 was 3397, checked in by grum, 15 years ago

Add plugin MyPolls - this release is not published in PEM (functionnal but not tested yet...)

File size: 5.8 KB
Line 
1<!-- main page -->
2<script type="text/javascript">
3
4  var poll_id='{$block->data.ATT_ID}'; //set as a global variable
5  var results = new Array({$block->data.NBQUESTIONS});
6  var current_question = 0;
7
8  //format results (string)
9  function format_string(txt)
10  {
11    return('s:'+txt.length+':"'+txt+'";');
12  }
13  //format results (array)
14  function format_array(an_array)
15  {
16    result='a:'+an_array.length+':{';
17    for(i=0;i<an_array.length;i++)
18    {
19      result+='i:'+i+';'+an_array[i];
20    }
21    result+='}';
22
23    return(result);
24  }
25
26  //memorize answer's results
27  function memorise_result(question_num, result)
28  {
29    results[question_num] = result;
30  }
31
32  //prepare results into form
33  function prepare_results()
34  {
35    var objresult = document.getElementById("iresults");
36
37    objresult.value=format_array(results);
38  }
39
40  //load question(s)
41  function load_poll_questions(question_num)
42  {
43    var doc = document.getElementById('display_questions');
44
45    http_request=create_httpobject('get', '', '{$block->data.AJAX_URL_POLL_DETAIL}'+'&question='+question_num+'&lang={$block->data.LANG}', false);
46    http_request.send(null);
47    doc.innerHTML = http_request.responseText;
48    current_question=question_num;
49    if(question_num==0)
50    {
51      for(i=0;i<{$block->data.NBQUESTIONS};i++)
52      { results[i]=''; }
53    }
54    else
55    { results[question_num-1]=''; }
56
57    global_check();
58  }
59
60  /*
61    for multi answers, check that number of checked answers are not superior to maximal
62    and set result in results array
63  */
64  function check_multi(nbmax, names, qid)
65  {
66    var local_result=new Array();
67    var nbselected=0;
68 
69
70    for(i=0;i<document.forms['poll_form'].elements.length;i++)
71    {
72      if(document.forms['poll_form'].elements[i].name==names)
73      {
74        if(document.forms['poll_form'].elements[i].checked)
75        {
76          local_result.push(format_string(document.forms['poll_form'].elements[i].id));
77          nbselected++;
78        }
79      }
80    }
81    //disabled/enabled unchecked elements
82    for(i=0;i<document.forms['poll_form'].elements.length;i++)
83    {
84      if(document.forms['poll_form'].elements[i].name==names)
85      {
86        if(!document.forms['poll_form'].elements[i].checked)
87        { document.forms['poll_form'].elements[i].disabled=(nbselected==nbmax); }
88      }
89    }
90
91    qid--;
92    if(nbselected==0)
93    {
94      results[qid]='';
95    }
96    else
97    {
98      results[qid]=format_array(local_result);
99    }
100    global_check();
101  }
102
103  /*
104    this function permit to test in <option> of a <select> element is enabled/disabled
105    if disabled, force choice to value "-" (index 0)
106    function needed because some browsers like IE don't implement this property...
107  */
108  function check_option_enabled(id)
109  {
110    var doc = document.getElementById(id);
111    if(doc.options[doc.selectedIndex].disabled==true)
112    {
113      doc.selectedIndex=0;
114    }
115  }
116
117  /*
118    for order answers, when order is selected on an answer, disabled this choice for
119    other answers and set result in results array
120  */
121  function check_order(names, qid, id)
122  {
123    var local_result = new Array();
124    var all_selected = true;
125
126    check_option_enabled(id);
127
128    for(i=0;i<document.forms['poll_form'].elements.length;i++)
129    {
130      if(document.forms['poll_form'].elements[i].name==names)
131      {
132        local_result.push(format_string(document.forms['poll_form'].elements[i].id+'_'+document.forms['poll_form'].elements[i].selectedIndex));
133        if(document.forms['poll_form'].elements[i].selectedIndex==0)
134        { all_selected=false; }
135        for(k=1;k<document.forms['poll_form'].elements[i].options.length;k++)
136        {
137          document.forms['poll_form'].elements[i].options[k].disabled=false;
138          for(j=0;j<document.forms['poll_form'].elements.length;j++)
139          {
140            if((document.forms['poll_form'].elements[j].name==names)&&
141              (document.forms['poll_form'].elements[j].selectedIndex==k)&&
142              (i!=j))
143            {
144              document.forms['poll_form'].elements[i].options[k].disabled=true;
145            }
146          }
147        }
148      }
149    }
150
151    qid--;
152    if(all_selected==false)
153    {
154      results[qid]='';
155    }
156    else
157    {
158      results[qid]=format_array(local_result);
159    }
160    global_check();
161  }
162
163  /*
164    for mono answers set result in results array
165  */
166  function check_mono(names, qid)
167  {
168    var local_result = new Array();
169    for(i=0;i<document.forms['poll_form'].elements.length;i++)
170    {
171      if(document.forms['poll_form'].elements[i].name==names)
172      {
173        if(document.forms['poll_form'].elements[i].checked)
174        {
175          local_result[0]=format_string(document.forms['poll_form'].elements[i].id);
176        }
177      }
178    }
179    qid--;
180    results[qid]=format_array(local_result);
181    global_check();
182  }
183
184
185  /*
186    check all question and determine if disable or not the next step
187  */
188  function global_check()
189  {
190    disable_next_step=false;
191    if(current_question==0)
192    {
193      for(i=1;i<=results.length;i++)
194      {
195        if(results[i]=='')
196        {
197          disable_next_step=true;
198        }
199      }
200    }
201    else
202    {
203      if(results[current_question-1]=='')
204      {
205        disable_next_step=true;
206      }
207    }
208    obj = document.getElementById('inext_step');
209    obj.disabled=disable_next_step;
210    if(!disable_next_step)
211    {
212      prepare_results();
213    }
214  }
215
216
217
218</script>
219
220<div class="mypolls_page">
221
222{if isset($block->data.GENERIC_TEXT) and $block->data.GENERIC_TEXT!=""}
223<p>{mypolls_generic_text.GENERIC_TEXT}</p>
224<hr/>
225{/if}
226
227<p>{$block->data.DESCRIPTION}</p>
228
229<form method="post" action="" class="general" name="poll_form" id="poll_form">
230  <input type="hidden" name="fmypolls_results" id="iresults" value="">
231  <div id="display_questions">
232
233  </div>
234</form>
235
236</div>
237
238<script type="text/javascript">
239  load_poll_questions({$block->data.FIRST_QUESTION});
240</script>
Note: See TracBrowser for help on using the repository browser.