1<?php $myfield = "{$surveyid}X{$flt[1]}X{$flt[0]}"; $niceqtext=flattenText($flt[5]); ?>
2
3<?php
4
5    //$specialQuestionTypes = array("M","P","T","S","Q","|","","N","K","D");
6    $specialQuestionTypes = array("M", "P");
7    if ( in_array( $flt[2], $specialQuestionTypes))
8    {
9        $myfield = $flt[2].$myfield;
10    }
11    $counter2 = 0;
12?>
13
14
15
16
17    <div class="question-filter-container grow-3 nofloat ls-space padding all-10">
18    <?php echo "<!-- Question type :  $flt[2] -->"; ?>
19        <?php if ($flt[2]=='M' || $flt[2]=='|' || $flt[2]=='P' || $flt[2]=='L' || $flt[2]=='5' || $flt[2]=='G' || $flt[2]=='I' || $flt[2]=='O' || $flt[2]=='Y' || $flt[2]=='!'): ?>
20            <!--  TYPE =='M' || 'P' || 'N' || 'L' || '5' || 'G' || 'I' || 'O' || 'Y' || '!' -->
21            <div class="statistics-responses-label-group ls-space padding bottom-5 top-15 ls-flex-item">
22                <input type='checkbox'
23                    id='filter<?php echo $myfield; ?>'
24                    name='summary[]'
25                    value='<?php echo $myfield; ?>' <?php
26                    if (isset($summary) && (array_search("{$surveyid}X{$flt[1]}X{$flt[0]}", $summary) !== FALSE
27                    || array_search("M{$surveyid}X{$flt[1]}X{$flt[0]}", $summary) !== FALSE
28                    || array_search("P{$surveyid}X{$flt[1]}X{$flt[0]}", $summary) !== FALSE
29                    || array_search("N{$surveyid}X{$flt[1]}X{$flt[0]}", $summary) !== FALSE))
30                    { echo " checked='checked'"; }
31                    ?>
32                    />
33                <label for='filter<?php echo $myfield; ?>'>&nbsp;<?php echo $flt[3].' - '.$oStatisticsHelper::_showSpeaker(flattenText($flt[5],true)); ?>
34                </label>
35            </div>
36
37            <?php if ($flt[2] != "N" && $flt[2] != "|"):?>
38                <select name='<?php
39                    if ($flt[2] == "M" ) { echo "M";};
40                    if ($flt[2] == "P" ) { echo "P";};
41                    echo "{$surveyid}X{$flt[1]}X{$flt[0]}[]";?>' multiple='multiple' class='form-control'>
42            <?php endif; ?>
43
44        <?php endif; ?>
45        <!-- QUESTION TYPE = <?php echo $flt[2]; ?> -->
46        <?php
47        switch ($flt[2])
48        {
49            case "K": // Multiple Numerical
50                echo '<h4 class="question-selector-title">'.$oStatisticsHelper::_showSpeaker($niceqtext).'</h4><br/>';
51                //go through all the (multiple) answers
52                foreach($result[$key1] as $row1)
53                {
54                    $row1 = array_values($row1);
55
56                    foreach($row1 as $row)
57                    {
58                        $row = array_values($row);
59                        /*
60                        * filter form for numerical input
61                        * - checkbox
62                        * - greater than
63                        * - less than
64                        */
65
66                        $myfield1="K".$myfield.$row[0];
67                        $myfield2="K{$myfield}".$row[0]."G";
68                        $myfield3="K{$myfield}".$row[0]."L";
69                        if ($counter2 == 4) { echo "\t</tr>\n\t<tr>\n"; $counter2=0;}
70
71                        //checkbox
72                        echo '<div class="statistics-responses-label-group ls-space padding bottom-5 top-15 ls-flex-item">';
73                        echo "<input type='checkbox'  name='summary[]' value='$myfield1'";
74
75                        //check SGQA -> do we want to pre-check the checkbox?
76                        if (isset($summary) && (array_search("K{$surveyid}X{$flt[1]}X{$flt[0]}{$row[0]}", $summary) !== FALSE))
77                        {
78                            echo " checked='checked'";
79                        }
80
81                        echo " />&nbsp;";
82
83                        //show speaker
84                        echo $oStatisticsHelper::_showSpeaker($flt[3]." - ".flattenText($row[1],true))
85                        ."</div>\n";?>
86
87                        <span class='smalltext'><?php eT("Number greater than");?>:</span><br />
88                        <?php echo CHtml::textField($myfield2,isset($_POST[$myfield2])?$_POST[$myfield2]:'',array('onkeypress'=>"returnwindow.LS.goodchars(event,'0123456789.,')"));?>
89                        <br>
90                        <span class='smalltext'><?php eT("Number less than");?>:</span><br>
91                        <?php echo CHtml::textField($myfield3,isset($_POST[$myfield3])?$_POST[$myfield3]:'',array('onkeypress'=>"returnwindow.LS.goodchars(event,'0123456789.,')"));?>
92                        <br>
93                        <?php
94                    }
95
96                }
97                break;
98
99
100
101            case "Q": // Multiple Short Text
102                echo '<h4 class="question-selector-title">'.$oStatisticsHelper::_showSpeaker($niceqtext).'</h4><br/>';
103                //get subqestions
104                $result[$key1] = Question::model()->getQuestionsForStatistics('title as code, question as answer', "parent_qid='$flt[0]' AND language = '{$language}'", 'question_order');
105                //$counter2=0;
106
107                //loop through all answers
108                $count = 0;
109                foreach($result[$key1] as $row)
110                {
111                    echo '<div class="row"><div class="col-sm-12">';
112
113                    $row = array_values($row);
114                    //collecting data for output, for details see above (question type "N")
115
116                    //we have one input field for each answer
117                    $myfield2 = "Q".$myfield."$row[0]";
118                    echo "&nbsp;&nbsp; <input type='checkbox'  name='summary[]' value='$myfield2'";
119
120                    if (isset($summary) && (array_search("Q{$surveyid}X{$flt[1]}X{$flt[0]}{$row[0]}", $summary) !== FALSE))
121                    {
122                        echo " checked='checked'";
123                    }
124
125                    echo " />&nbsp;";
126                    echo $oStatisticsHelper::_showSpeaker($flt[3]." - ".flattenText($row[1],true))
127                    ."<br /><p style='padding: 1em;'>\n"
128                    ."\t<span class='smalltext'>".gT("Responses containing").":</span><br />\n";
129                    echo CHtml::textField($myfield2,isset($_POST[$myfield2])?$_POST[$myfield2]:'',array());
130                    echo "</p>";
131                    echo '</div></div>';
132                }
133                break;
134
135
136            /*
137            * all "free text" types (T, U, S)  get the same prefix ("T")
138            * Equations are treated the same way
139            */
140            case "T": // Long free text
141            case "U": // Huge free text
142            case '*': // Equation
143                echo '<div class="statistics-responses-label-group ls-space padding bottom-5 top-15 ls-flex-item">';
144                $myfield2="T$myfield";
145                echo "\t<input type='checkbox'  name='summary[]' value='$myfield2'";
146                if (isset($summary) && (array_search("T{$surveyid}X{$flt[1]}X{$flt[0]}", $summary) !== FALSE))
147                {echo " checked='checked'";}
148
149                echo " />&nbsp;"
150                ."&nbsp;".$oStatisticsHelper::_showSpeaker($niceqtext)
151                ."<br />\n"
152                ."\t<span class='smalltext'>".gT("Responses containing").":</span>
153                </div>\n"
154                .CHtml::textArea($myfield2,isset($_POST[$myfield2])?$_POST[$myfield2]:'',array('rows'=>'3','cols'=>'40'));
155                break;
156
157
158
159            case "S": // Short free text
160                echo '<div class="statistics-responses-label-group ls-space padding bottom-5 top-15 ls-flex-item">';
161                $myfield2="T$myfield";
162                echo "<input type='checkbox'  name='summary[]' value='$myfield2'";
163
164                if (isset($summary) && (array_search("T{$surveyid}X{$flt[1]}X{$flt[0]}", $summary) !== FALSE))
165                {echo " checked='checked'";}
166
167                echo " />&nbsp;"
168                ."&nbsp;".$oStatisticsHelper::_showSpeaker($niceqtext)
169                ."<br />\n"
170                ."\t<span class='smalltext'>".gT("Responses containing").":</span>
171                </div>\n"
172                .CHtml::textField($myfield2,isset($_POST[$myfield2])?$_POST[$myfield2]:'',array());
173                break;
174
175
176
177            case "N": // Numerical
178                //textfields for greater and less than X
179                ?>
180                <div class="statistics-responses-label-group ls-space padding bottom-5 top-15 ls-flex-item">
181                    <input type='checkbox'
182                        id='filter<?php echo $myfield; ?>'
183                        name='summary[]'
184                        value='N<?php echo $myfield; ?>' <?php
185                        if (isset($summary) && (array_search("{$surveyid}X{$flt[1]}X{$flt[0]}", $summary) !== FALSE
186                        || array_search("M{$surveyid}X{$flt[1]}X{$flt[0]}", $summary) !== FALSE
187                        || array_search("P{$surveyid}X{$flt[1]}X{$flt[0]}", $summary) !== FALSE
188                        || array_search("N{$surveyid}X{$flt[1]}X{$flt[0]}", $summary) !== FALSE))
189                        { echo " checked='checked'"; }
190                        ?>
191                        />
192                    <label for='filter<?php echo $myfield; ?>'>&nbsp;<?php echo $flt[3].' - '.$oStatisticsHelper::_showSpeaker(flattenText($flt[5],true)); ?>
193                    </label>
194                </div>
195                <?php
196                $myfield2="{$myfield}G";
197                $myfield3="{$myfield}L";
198                echo "\t<span class='smalltext'>".gT("Number greater than").":</span><br />\n"
199                .CHtml::textField('N'.$myfield2,isset($_POST[$myfield2])?'N'.$_POST[$myfield2]:'',array( 'onkeypress'=>"returnwindow.LS.goodchars(event,'0123456789.,')" ))
200                ."\t<br />\n"
201                ."\t<span class='smalltext'>".gT("Number less than").":</span><br />\n"
202                .CHtml::textField('N'.$myfield3,isset($_POST[$myfield3])?'N'.$_POST[$myfield3]:'',array( 'onkeypress'=>"returnwindow.LS.goodchars(event,'0123456789.,')" ))
203                ."\t<br />\n";
204
205                //put field names into array
206
207                break;
208
209
210            case "|": // File Upload
211
212                // Number of files uploaded for greater and less than X
213                $myfield2 = "{$myfield}G";
214                $myfield3 = "{$myfield}L";
215                echo "\t<span class='smalltext'>".gT("Number of files greater than").":</span><br />\n"
216                .CHtml::textField($myfield2,isset($_POST[$myfield2])?$_POST[$myfield2]:'',array( 'onkeypress'=>"returnwindow.LS.goodchars(event,'0123456789.,')" ))
217                ."<br />\n"
218                ."\t<span class='smalltext'>".gT("Number of files less than").":</span><br />\n"
219                .CHtml::textField($myfield3,isset($_POST[$myfield3])?$_POST[$myfield3]:'',array( 'onkeypress'=>"returnwindow.LS.goodchars(event,'0123456789.,')" ))
220                ."<br />\n";
221                break;
222
223
224            /*
225            * DON'T show any statistics for date questions
226            * because there aren't any statistics implemented yet!
227            *
228            * Only filtering by date is possible.
229            *
230            * See bug report #2539 and
231            * feature request #2620
232            */
233            case "D": // Date
234
235                /*
236                * - input name
237                * - date equals
238                * - date less than
239                * - date greater than
240                */
241                $myfield2="D$myfield";
242                $myfield3=$myfield2."eq";
243                $myfield4=$myfield2."less";
244                $myfield5=$myfield2."more";
245                echo '<div class="statistics-responses-label-group ls-space padding bottom-5 top-15 ls-flex-item">';
246                echo "<input type='checkbox'  name='summary[]' value='$myfield2'";
247
248                if (isset($summary) && (array_search("D{$surveyid}X{$flt[1]}X{$flt[0]}", $summary) !== FALSE))
249                {echo " checked='checked'";}
250
251                echo " />";
252                echo '<strong>'.$oStatisticsHelper::_showSpeaker($niceqtext).'</strong>'
253                ."<br />\n"
254
255                ."\t<span class='smalltext'>".gT("Date (YYYY-MM-DD) equals").":<br />\n"
256                .CHtml::textField($myfield3,isset($_POST[$myfield3])?$_POST[$myfield3]:'',array() )
257                ."<br />\n"
258                ."\t&nbsp;&nbsp;".gT("Date is")." >=<br />\n"
259                .CHtml::textField($myfield4,isset($_POST[$myfield4])?$_POST[$myfield4]:'',array() )
260                ."<br />"
261                .gT("AND/OR Date is")." <= <br />"
262                .CHtml::textField($myfield5,isset($_POST[$myfield5])?$_POST[$myfield5]:'',array() )
263                ."</span>\n";
264                echo '</div>';
265                break;
266
267
268
269            case "5": // 5 point choice
270
271                //we need a list of 5 entries
272                for ($i=1; $i<=5; $i++)
273                {
274                    echo "\t<option value='$i'";
275
276                    //pre-select values which were marked before
277                    if (isset($_POST[$myfield]) && is_array($_POST[$myfield]) && in_array($i, $_POST[$myfield]))
278                    {echo " selected='selected' ";}
279
280                    echo ">$i</option>\n";
281                }
282
283                //End the select which starts before the CASE statement (around line 411)
284                echo"\t</select>\n";
285                break;
286
287
288
289            case "G": // Gender
290                echo "\t<option value='F'";
291
292                //pre-select values which were marked before
293                if (isset($_POST[$myfield]) && is_array($_POST[$myfield]) && in_array("F", $_POST[$myfield])) {echo " selected='selected' ";}
294
295                echo ">".gT("Female")."</option>\n";
296                echo "\t<option value='M'";
297
298                //pre-select values which were marked before
299                if (isset($_POST[$myfield]) && is_array($_POST[$myfield]) && in_array("M", $_POST[$myfield])) {echo " selected='selected' ";}
300
301                echo ">".gT("Male")."</option>\n\t</select>\n";
302                break;
303
304
305
306            case "Y": // Yes\No
307                echo "\t<option value='Y'";
308
309                //pre-select values which were marked before
310                if (isset($_POST[$myfield]) && is_array($_POST[$myfield]) && in_array("Y", $_POST[$myfield])) {echo " selected='selected' ";}
311
312                echo ">".gT("Yes")."</option>\n"
313                ."\t<option value='N'";
314
315                //pre-select values which were marked before
316                if (isset($_POST[$myfield]) && is_array($_POST[$myfield]) && in_array("N", $_POST[$myfield])) {echo " selected='selected' ";}
317
318                echo ">".gT("No")."</option></select>\n";
319                break;
320
321
322
323            case "I": // Language
324                $survlangs = Survey::model()->findByPk($surveyid)->additionalLanguages;
325                $survlangs[] = Survey::model()->findByPk($surveyid)->language;
326                foreach ($survlangs  as $availlang)
327                {
328                    echo "\t<option value='".$availlang."'";
329
330                    //pre-select values which were marked before
331                    if (isset($_POST[$myfield]) && is_array($_POST[$myfield]) && in_array($availlang, $_POST[$myfield]))
332                    {echo " selected='selected' ";}
333
334                    echo ">".getLanguageNameFromCode($availlang,false)."</option>\n";
335                }
336                echo "</select>";
337                break;
338
339
340
341                //----------------------- ARRAYS --------------------------
342
343            case "A": // ARRAY OF 5 POINT CHOICE QUESTIONS
344                echo '<h4 class="question-selector-title">'.$oStatisticsHelper::_showSpeaker($niceqtext).'</h4><br/>';
345                //get answers
346                $result[$key1] = Question::model()->getQuestionsForStatistics('title, question', "parent_qid='$flt[0]' AND language = '{$language}'", 'question_order');
347                //$counter2=0;
348
349                //check all the results
350                foreach($result[$key1] as $row)
351                {
352                    $row = array_values($row);
353                    $myfield2 = $myfield.$row[0];
354                    echo "<!-- $myfield2 - ";
355
356                    if (isset($_POST[$myfield2])) {echo htmlspecialchars($_POST[$myfield2]);}
357
358                    echo " -->\n";
359                    echo '<div class="statistics-responses-label-group ls-space padding bottom-5 top-15 ls-flex-item">';
360                    echo "<input type='checkbox'  name='summary[]' value='$myfield2'";
361
362                    //pre-check
363                    if (isset($summary) && array_search($myfield2, $summary)!== FALSE) {echo " checked='checked'";}
364
365                    echo " />&nbsp;"
366                    .$oStatisticsHelper::_showSpeaker($niceqtext." ".str_replace("'", "`", $row[1])." - # ".$flt[3])
367                    ."</div>\n"
368                    ."\t<select name='{$surveyid}X{$flt[1]}X{$flt[0]}{$row[0]}[]' multiple='multiple' class='form-control'>\n";
369
370                    //there are always exactly 5 values which have to be listed
371                    for ($i=1; $i<=5; $i++)
372                    {
373                        echo "\t<option value='$i'";
374
375                        //pre-select
376                        if (isset($_POST[$myfield2]) && is_array($_POST[$myfield2]) && in_array($i, $_POST[$myfield2])) {echo " selected='selected' ";}
377                        if (isset($_POST[$myfield2]) && $_POST[$myfield2] == $i) {echo " selected='selected' ";}
378
379                        echo ">$i</option>\n";
380                    }
381
382                    echo "\t</select>\n\t";
383                    //add this to all the other fields
384                }
385                break;
386
387
388
389            //just like above only a different loop
390            case "B": // ARRAY OF 10 POINT CHOICE QUESTIONS
391                echo '<h4 class="question-selector-title">'.$oStatisticsHelper::_showSpeaker($niceqtext).'</h4><br/>';
392                foreach($result[$key1] as $row)
393                {
394                    $row=array_values($row);
395                    $myfield2 = $myfield . "$row[0]";
396                    echo "<!-- $myfield2 - ";
397
398                    if (isset($_POST[$myfield2])) {echo htmlspecialchars($_POST[$myfield2]);}
399
400                    echo " -->\n";
401                    echo '<div class="statistics-responses-label-group ls-space padding bottom-5 top-15 ls-flex-item">';
402
403                    echo "<input type='checkbox'  name='summary[]' value='$myfield2'";
404
405                    if (isset($summary) && array_search($myfield2, $summary)!== FALSE) {echo " checked='checked'";}
406
407                    echo " />&nbsp;"
408                    .'<strong>'.$oStatisticsHelper::_showSpeaker($niceqtext." ".str_replace("'", "`", $row[1])." - # ".$flt[3]).'</strong>'
409                    ."</div>\n"
410                    ."\t<select name='{$surveyid}X{$flt[1]}X{$flt[0]}{$row[0]}[]' multiple='multiple' class='form-control'>\n";
411
412                    //here wo loop through 10 entries to create a larger output form
413                    for ($i=1; $i<=10; $i++)
414                    {
415                        echo "\t<option value='$i'";
416                        if (isset($_POST[$myfield2]) && is_array($_POST[$myfield2]) && in_array($i, $_POST[$myfield2])) {echo " selected='selected' ";}
417                        if (isset($_POST[$myfield2]) && $_POST[$myfield2] == $i) {echo " selected='selected' ";}
418                        echo ">$i</option>\n";
419                    }
420
421                    echo "\t</select>\n\t";
422                }
423                break;
424
425
426
427            case "C": // ARRAY OF YES\No\gT("Uncertain") QUESTIONS
428                echo '<h4 class="question-selector-title">'.$oStatisticsHelper::_showSpeaker($niceqtext).'</h4><br/>';
429                //loop answers
430                foreach($result[$key1] as $row)
431                {
432                    $row=array_values($row);
433                    $myfield2 = $myfield . "$row[0]";
434                    echo "<!-- $myfield2 - ";
435
436                    if (isset($_POST[$myfield2])) {echo htmlspecialchars($_POST[$myfield2]);}
437
438                    echo " -->\n";
439                    echo '<div class="statistics-responses-label-group ls-space padding bottom-5 top-15 ls-flex-item">';
440
441                    echo "<input type='checkbox'  name='summary[]' value='$myfield2'";
442
443                    if (isset($summary) && array_search($myfield2, $summary)!== FALSE)
444                    {echo " checked='checked'";}
445
446                    echo " />&nbsp;<strong>"
447                    .$oStatisticsHelper::_showSpeaker($niceqtext." ".str_replace("'", "`", $row[1])." - # ".$flt[3])
448                    ."</strong>\n"
449                    ."</div>\n"
450                    ."\t<select name='{$surveyid}X{$flt[1]}X{$flt[0]}{$row[0]}[]' multiple='multiple' class='form-control'>\n"
451                    ."\t<option value='Y'";
452
453                    //pre-select "yes"
454                    if (isset($_POST[$myfield2]) && is_array($_POST[$myfield2]) && in_array("Y", $_POST[$myfield2])) {echo " selected='selected' ";}
455
456                    echo ">".gT("Yes")."</option>\n"
457                    ."\t<option value='U'";
458
459                    //pre-select "uncertain"
460                    if (isset($_POST[$myfield2]) && is_array($_POST[$myfield2]) && in_array("U", $_POST[$myfield2])) {echo " selected='selected' ";}
461
462                    echo ">".gT("Uncertain")."</option>\n"
463                    ."\t<option value='N'";
464
465                    //pre-select "no"
466                    if (isset($_POST[$myfield2]) && is_array($_POST[$myfield2]) && in_array("N", $_POST[$myfield2])) {echo " selected='selected' ";}
467
468                    echo ">".gT("No")."</option>\n"
469                    ."\t</select>";
470                    //add to array
471                }
472                break;
473
474
475
476            //similiar to the above one
477            case "E": // ARRAY OF Increase/Same/Decrease QUESTIONS
478                echo '<h4 class="question-selector-title">'.$oStatisticsHelper::_showSpeaker($niceqtext).'</h4><br/>';
479                foreach($result[$key1] as $row)
480                {
481                    $row=array_values($row);
482                    $myfield2 = $myfield . "$row[0]";
483                    echo "<!-- $myfield2 - ";
484
485                    if (isset($_POST[$myfield2])) {echo htmlspecialchars($_POST[$myfield2]);}
486
487                    echo " -->\n";
488                    echo '<div class="statistics-responses-label-group ls-space padding bottom-5 top-15 ls-flex-item">';
489                    echo "<input type='checkbox'  name='summary[]' value='$myfield2'";
490
491                    if (isset($summary) && array_search($myfield2, $summary)!== FALSE) {echo " checked='checked'";}
492
493                    echo " />&nbsp;<strong>"
494                    .$oStatisticsHelper::_showSpeaker($niceqtext." ".str_replace("'", "`", $row[1])." - # ".$flt[3])
495                    ."</strong>\n"
496                    ."</div>\n"
497                    ."\t<select name='{$surveyid}X{$flt[1]}X{$flt[0]}{$row[0]}[]' multiple='multiple'  class='form-control'>\n"
498                    ."\t<option value='I'";
499
500                    if (isset($_POST[$myfield2]) && is_array($_POST[$myfield2]) && in_array("I", $_POST[$myfield2])) {echo " selected='selected' ";}
501
502                    echo ">".gT("Increase")."</option>\n"
503                    ."\t<option value='S'";
504
505                    if (isset($_POST[$myfield]) && is_array($_POST[$myfield2]) && in_array("S", $_POST[$myfield2])) {echo " selected='selected' ";}
506
507                    echo ">".gT("Same")."</option>\n"
508                    ."\t<option value='D'";
509
510                    if (isset($_POST[$myfield]) && is_array($_POST[$myfield2]) && in_array("D", $_POST[$myfield2])) {echo " selected='selected' ";}
511
512                    echo ">".gT("Decrease")."</option>\n"
513                    ."\t</select>";
514                }
515
516                $counter=0;
517                break;
518
519            case ";":  //ARRAY (Multi Flex) (Text)
520                echo '<h4 class="question-selector-title">'.$oStatisticsHelper::_showSpeaker($niceqtext).'</h4><br/>';
521                foreach($result[$key1] as $key => $row)
522                {
523                    $row = array_values($row);
524                    $fresult = $fresults[$key1][$key];
525                    foreach($fresult as $frow)
526                    {
527                        $myfield2 = "T".$myfield . $row[0] . "_" . $frow['title'];
528                        echo "<!-- $myfield2 - ";
529                        if (isset($_POST[$myfield2])) {echo htmlspecialchars($_POST[$myfield2]);}
530                        echo " -->\n";
531                        echo "<input type='checkbox'  name='summary[]' value='$myfield2'";
532                        if (isset($summary) && array_search($myfield2, $summary)!== FALSE) {echo " checked='checked'";}
533                        echo " />&nbsp;<strong>"
534                        .$oStatisticsHelper::_showSpeaker($niceqtext." ".str_replace("'", "`", $row[1]." [".$frow['question']."]")." - ".$row[0]."/".$frow['title'])
535                        ."</strong><br />\n";
536                        echo "\t<span class='smalltext'>".gT("Responses containing").":</span><br />\n"
537                        .CHtml::textField($myfield2,isset($_POST[$myfield2])?$_POST[$myfield2]:'',array() );
538                        echo "<hr/>";
539                        $counter2++;
540                    }
541                }
542                $counter=0;
543                break;
544
545            case ":":  //ARRAY (Multi Flex) (Numbers)
546                //Get qidattributes for this question
547                echo '<h4 class="question-selector-title">'.$oStatisticsHelper::_showSpeaker($niceqtext).'</h4><br/>';
548                $qidattributes=QuestionAttribute::model()->getQuestionAttributes($flt[0]);
549                if (trim($qidattributes['multiflexible_max'])!='' && trim($qidattributes['multiflexible_min']) ==''){
550                    $maxvalue=$qidattributes['multiflexible_max'];
551                    $minvalue=1;
552                }
553                if (trim($qidattributes['multiflexible_min'])!='' && trim($qidattributes['multiflexible_max']) ==''){
554                    $minvalue=$qidattributes['multiflexible_min'];
555                    $maxvalue=$qidattributes['multiflexible_min'] + 10;
556                }
557                if (trim($qidattributes['multiflexible_min'])=='' && trim($qidattributes['multiflexible_max']) ==''){
558                    $minvalue=1;
559                    $maxvalue=10;
560                }
561                if (trim($qidattributes['multiflexible_min']) !='' && trim($qidattributes['multiflexible_max']) !=''){
562                    if($qidattributes['multiflexible_min'] < $qidattributes['multiflexible_max']){
563                        $minvalue=$qidattributes['multiflexible_min'];
564                        $maxvalue=$qidattributes['multiflexible_max'];
565                    }
566                }
567
568                if (trim($qidattributes['multiflexible_step'])!='') {
569                    $stepvalue=$qidattributes['multiflexible_step'];
570                } else {
571                    $stepvalue=1;
572                }
573                if ($qidattributes['multiflexible_checkbox']!=0)
574                {
575                    $minvalue=0;
576                    $maxvalue=1;
577                    $stepvalue=1;
578                }
579                foreach($result[$key1] as $row)
580                {
581                    $row = array_values($row);
582                    $fresult = Question::model()->getQuestionsForStatistics('*', "parent_qid='$flt[0]' AND language = '{$language}' AND scale_id = 1", 'question_order, title');
583                    foreach($fresult as $frow)
584                    {
585                        $myfield2 = $myfield . $row[0] . "_" . $frow['title'];
586                        echo "<!-- MyField2:  $myfield2 - ";
587                        if (isset($_POST[$myfield2])) {echo htmlspecialchars($_POST[$myfield2]);}
588                        echo " -->\n";
589                        echo '<div class="statistics-responses-label-group ls-space padding bottom-5 top-15 ls-flex-item">';
590                        if ($counter2 == 4) {echo "\t</tr>\n\t<tr>\n"; $counter2=0;}
591                        echo "<input type='checkbox'  name='summary[]' value='$myfield2'";
592                        if (isset($summary) && array_search($myfield2, $summary)!== FALSE) {echo " checked='checked'";}
593                        echo " />&nbsp;<strong>"
594                        .$oStatisticsHelper::_showSpeaker($niceqtext." ".str_replace("'", "`", $row[1]." [".$frow['question']."]")." - ".$row[0]."/".$frow['title'])
595                        ."</strong>\n"
596                        ."</div>\n";
597                        echo "\t<select name='{$myfield2}[]' multiple='multiple' rows='5' cols='5' class='form-control'>\n";
598                        for($ii=$minvalue; $ii<=$maxvalue; $ii+=$stepvalue)
599                        {
600                            echo "\t<option value='$ii'";
601                            if (isset($_POST[$myfield2]) && is_array($_POST[$myfield2]) && in_array($frow['code'], $_POST[$myfield2])) {echo " selected='selected' ";}
602                            echo ">$ii</option>\n";
603                        }
604                        echo "\t</select>";
605                    }
606                }
607                break;
608
609            /*
610            * For question type "F" and "H" you can use labels.
611            * The only difference is that the labels are applied to column heading
612            * or rows respectively
613            */
614            case "F": // FlEXIBLE ARRAY
615            case "H": // ARRAY (By Column)
616
617                //Get answers. We always use the answer code because the label might be too long elsewise
618                echo '<h4 class="question-selector-title">'.$oStatisticsHelper::_showSpeaker($niceqtext).'</h4><br/>';
619                //check all the answers
620                foreach($result[$key1] as $key=>$row)
621                {
622                    $row=array_values($row);
623                    $myfield2 = $myfield . "$row[0]";
624                    echo "<!-- $myfield2 -->\n";
625
626                    if ($counter2 == 4)
627                    {
628                        echo "\t</tr>\n\t<tr>\n";
629                        $counter2=0;
630                    }
631                    echo '<div class="statistics-responses-label-group ls-space padding bottom-5 top-15 ls-flex-item">';
632                    echo "<input type='checkbox'  name='summary[]' value='$myfield2'";
633
634                    if (isset($summary) && array_search($myfield2, $summary)!== FALSE) {echo " checked='checked'";}
635
636                    echo " />&nbsp;<strong>"
637                    .$oStatisticsHelper::_showSpeaker($niceqtext." ".str_replace("'", "`", $row[1])." - # ".$flt[3])
638                    ."</strong>
639                    </div>\n";
640
641                    /*
642                    * when hoovering the speaker symbol we show the whole question
643                    *
644                    * flt[6] is the label ID
645                    *
646                    * table "labels" contains
647                    * - lid
648                    * - code
649                    * - title
650                    * - sortorder
651                    * - language
652                    */
653                    $fresult = $fresults[$key1];
654
655                    //for debugging only:
656
657                    //creating form
658                    echo "\t<select name='{$surveyid}X{$flt[1]}X{$flt[0]}{$row[0]}[]' multiple='multiple' class='form-control'>\n";
659
660                    //loop through all possible answers
661                    foreach($fresult as $frow)
662                    {
663                        echo "\t<option value='{$frow['code']}'";
664
665                        //pre-select
666                        if (isset($_POST[$myfield2]) && is_array($_POST[$myfield2]) && in_array($frow['code'], $_POST[$myfield2])) {echo " selected='selected' ";}
667
668                        echo ">({$frow['code']}) ".flattenText($frow['answer'],true)."</option>\n";
669                    }
670
671                    echo "\t</select>";
672                    //add fields to main array
673                }
674
675                break;
676
677
678
679                case "R": //RANKING
680
681                //get some answers
682                //get number of columns
683                $answersCount = count($result[$key1]);
684                $maxDbAnswer=QuestionAttribute::model()->find("qid = :qid AND attribute = 'max_subquestions'",array(':qid' => $flt[0]));
685                $columnsCount=(!$maxDbAnswer || intval($maxDbAnswer->value)<1) ? $answersCount : intval($maxDbAnswer->value); // If max_subquestions is not set or is invalid : get the answer count
686                $columnsCount = min($columnsCount,$answersCount); // Can not be upper than current answers #14899
687                //lets put the answer code and text into the answers array
688                foreach($result[$key1] as $row)
689                {
690                    $answers[]=array($row['code'], $row['answer']);
691                }
692
693                //loop through all answers. if there are 3 items to rate there will be 3 statistics
694                for ($i=1; $i<=$columnsCount; $i++)
695                {
696                    //adjust layout depending on counter
697                    //if ($counter2 == 4) {echo "\t</tr>\n\t<tr>\n"; $counter2=0;}
698
699                    //myfield is the SGQ identifier
700                    //myfield2 is just used as comment in HTML like "R40X34X1721-1"
701                    $myfield2 = "R" . $myfield . $i . "-" . strlen($i);
702                    $myfield3 = $myfield . $i;
703                    echo "<!-- $myfield2 --> ";
704                    echo '<div class="statistics-responses-label-group ls-space padding bottom-5 top-15 ls-flex-item">';
705                    if (isset($_POST[$myfield2])) {echo htmlspecialchars($_POST[$myfield2]);}
706
707                    echo "<input type='checkbox'  name='summary[]' value='$myfield2'";
708
709                    //pre-check
710                    if (isset($summary) && array_search($myfield2, $summary) !== FALSE) {echo " checked='checked'";}
711
712                    $trow = array_values($row);
713
714                    echo " />&nbsp;<strong>"
715                    .$oStatisticsHelper::_showSpeaker($niceqtext." ".str_replace("'", "`", $trow[1])." - # ".$flt[3])
716                    ."</strong>
717                    </div>\n"
718                    ."\t<select name='{$surveyid}X{$flt[1]}X{$flt[0]}{$i}[]' multiple='multiple' class='form-control'>\n";
719
720                    //output lists of ranking items
721                    foreach ($answers as $ans)
722                    {
723                        echo "\t<option value='$ans[0]'";
724
725                        //pre-select
726                        if (isset($_POST[$myfield3]) && is_array($_POST[$myfield3]) && in_array("$ans[0]", $_POST[$myfield3])) {echo " selected='selected' ";}
727
728                        echo ">".flattenText($ans[1])."</option>\n";
729                    }
730
731                    echo "\t</select>";
732                    //add averything to main array
733                }
734
735                //Link to rankwinner script - awaiting completion - probably never gonna happen. Mystery creator.
736                //          echo "\t</tr>\n\t<tr bgcolor='#DDDDDD'>\n"
737                //              ."<td colspan=$count align=center>"
738                //              ."<input type='button' value='Show Rank Summary' onclick=\"window.open('rankwinner.php?sid=$surveyid&amp;qid=$flt[0]', '_blank', 'toolbar=no, directories=no, location=no, status=yes, menubar=no, resizable=no, scrollbars=no, width=400, height=300, left=100, top=100')\">"
739                //              ."</td></tr>\n\t<tr>\n";
740                $counter=0;
741                unset($answers);
742                break;
743
744
745            case "1": // MULTI SCALE
746
747                //special dual scale counter
748                echo '<h4 class="question-selector-title">'.$oStatisticsHelper::_showSpeaker($niceqtext).'</h4><br/>';
749                //loop through answers
750                foreach($result[$key1] as $row)
751                {
752                    $row=array_values($row);
753
754                    //----------------- LABEL 1 ---------------------
755                    //myfield2 = answer code.
756                    $myfield2 = $myfield . "$row[0]#0";
757
758                    //3 lines of debugging output
759                    echo "<!-- $myfield2 - ";
760                    if (isset($_POST[$myfield2]))
761                    {
762                        echo htmlspecialchars($_POST[$myfield2]);
763                    }
764                    echo " -->\n";
765
766                    echo '<div class="statistics-responses-label-group ls-space padding bottom-5 top-15 ls-flex-item">';
767                    //output checkbox and question/label text
768                    echo "<input type='checkbox' name='summary[]' value='$myfield2'";
769
770                    //pre-check
771                    if (isset($summary) && array_search($myfield2, $summary)!== FALSE) {echo " checked='checked'";}
772
773                    //check if there is a dualscale_headerA/B
774                    $dshresult = $dshresults[$key1][0];
775
776                    //get header
777                    foreach($dshresult as $dshrow)
778                    {
779                        $dshrow=array_values($dshrow);
780                        $dualscaleheadera = $dshrow[0];
781                    }
782
783                    if(isset($dualscaleheadera) && $dualscaleheadera != "")
784                    {
785                        $labeltitle = $dualscaleheadera;
786                    }
787                    else
788                    {
789                        $labeltitle='';
790                    }
791
792                    echo " />&nbsp;"
793                    ."<strong>"
794                    .$oStatisticsHelper::_showSpeaker($niceqtext." [".str_replace("'", "`", $row[1])."] - ".gT("Label").": ".$labeltitle)
795                    ."</strong>
796                    </div>\n";
797
798                    /* get labels
799                    * table "labels" contains
800                    * - lid
801                    * - code
802                    * - title
803                    * - sortorder
804                    * - language
805                    */
806                    $fresult = Answer::model()->getQuestionsForStatistics('*', "qid='$flt[0]' AND language = '{$language}' AND scale_id = 0", 'sortorder, code');
807
808                    //this is for debugging only
809                    echo "\t<select name='{$surveyid}X{$flt[1]}X{$flt[0]}{$row[0]}#{0}[]' multiple='multiple' class='form-control'>\n";
810
811                    //list answers
812                    foreach($fresult as $frow)
813                    {
814                        echo "\t<option value='{$frow['code']}'";
815
816                        //pre-check
817                        if (isset($_POST[$myfield2]) && is_array($_POST[$myfield2]) && in_array($frow['code'], $_POST[$myfield2])) {echo " selected='selected' ";}
818
819                        echo ">({$frow['code']}) ".flattenText($frow['answer'],true)."</option>\n";
820
821                    }
822
823                    echo "\t</select>";
824
825                    //----------------- LABEL 2 ---------------------
826
827                    //myfield2 = answer code
828                    $myfield2 = $myfield . "$row[0]#1";
829
830                    //3 lines of debugging output
831                    echo "<!-- $myfield2 - ";
832                    if (isset($_POST[$myfield2]))
833                    {
834                        echo htmlspecialchars($_POST[$myfield2]);
835                    }
836
837                    echo " -->\n";
838                    echo '<div class="statistics-responses-label-group ls-space padding bottom-5 top-15 ls-flex-item">';
839                    echo "<input type='checkbox' name='summary[]' value='$myfield2'";
840                    //pre-check
841                    if (isset($summary) && array_search($myfield2, $summary)!== FALSE) {echo " checked='checked'";}
842
843                    //check if there is a dualsclae_headerA/B
844                    $dshresult2 = $dshresults2[$key1][0];
845
846                    //get header
847                    foreach($dshresult2 as $dshrow2)
848                    {
849                        $dshrow2=array_values($dshrow2);
850                        $dualscaleheaderb = $dshrow2[0];
851                    }
852
853                    if(isset($dualscaleheaderb) && $dualscaleheaderb != "")
854                    {
855                        $labeltitle2 = $dualscaleheaderb;
856                    }
857                    else
858                    {
859                        //get label text
860
861                        $labeltitle2 = '';
862                    }
863
864                    echo " />&nbsp;<strong>"
865                    .$oStatisticsHelper::_showSpeaker($niceqtext." [".str_replace("'", "`", $row[1])."] - ".gT("Label").": ".$labeltitle2)
866                    ."</strong>
867                    </div>\n";
868                    $fresult = Answer::model()->getQuestionsForStatistics('*', "qid='$flt[0]' AND language = '$language' AND scale_id = 1", 'sortorder, code');
869
870                    //this is for debugging only
871                    echo "\t<select name='{$surveyid}X{$flt[1]}X{$flt[0]}{$row[0]}#{1}[]' multiple='multiple' class='form-control'>\n";
872
873                    //list answers
874                    foreach($fresult as $frow)
875                    {
876                        echo "\t<option value='{$frow['code']}'";
877
878                        //pre-check
879                        if (isset($_POST[$myfield2]) && is_array($_POST[$myfield2]) && in_array($frow['code'], $_POST[$myfield2])) {echo " selected='selected' ";}
880
881                        echo ">({$frow['code']}) ".flattenText($frow['answer'],true)."</option>\n";
882
883                    }
884
885                    echo "\t</select>";
886
887                }   //end WHILE -> loop through all answers
888
889                break;
890
891            case "P":  //P - Multiple choice with comments
892            case "M":  //M - Multiple choice
893                echo '<h4 class="question-selector-title">'.$oStatisticsHelper::_showSpeaker($niceqtext).'</h4><br/>';
894                //loop through answers
895                foreach($result[$key1] as $row)
896                {
897                    $row=array_values($row);
898                    echo "\t<option value='{$row[0]}'";
899
900                    //pre-check
901                    if (isset($_POST[$myfield]) && is_array($_POST[$myfield]) && in_array($row[0], $_POST[$myfield])) {echo " selected='selected' ";}
902
903                    echo '>'.flattenText($row[1],true)."</option>\n";
904                }
905
906                echo "\t</select>";
907                break;
908
909            //Boilerplate questions are only used to put some text between other questions -> no analysis needed
910            case "X": //This is a boilerplate question and it has no business in this script
911                echo '<h4 class="question-selector-title">'.$oStatisticsHelper::_showSpeaker($niceqtext).'</h4><br/>';
912                eT("This question type can't be selected.");
913                break;
914
915                /*
916                * This question types use the default settings:
917                *  L - List (Radio)
918                O - List With Comment
919                P - Multiple choice with comments
920                ! - List (Dropdown)
921                */
922            default:
923                echo "<!-- Default rendering in _question view -->";
924                //loop through answers
925                foreach($result[$key1] as $row)
926                {
927                    $row=array_values($row);
928                    echo "\t<option value='{$row[0]}'";
929
930                    //pre-check
931                    if (isset($_POST[$myfield]) && is_array($_POST[$myfield]) && in_array($row[0], $_POST[$myfield])) {echo " selected='selected' ";}
932
933                    echo '>'.flattenText($row[1],true)."</option>\n";
934                }
935
936                echo "\t</select>\n\t";
937                //</td><div class='inerTableBox'>\n";
938                break;
939
940        }   //end switch -> check question types and create filter forms
941    ?>
942</div>
943