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