1<?php
2
3class listRadio extends CApplicationComponent
4{
5    public function doQuestion($ia)
6    {
7        global $thissurvey;
8        if ($thissurvey['nokeyboard']=='Y')
9        {
10            includeKeypad();
11            $kpclass = "text-keypad";
12        }
13        else
14        {
15            $kpclass = "";
16        }
17
18        $checkconditionFunction = "checkconditions";
19
20        $aQuestionAttributes = QuestionAttribute::model()->getQuestionAttributes($ia[0]);
21
22        $query = "SELECT other FROM {{questions}} WHERE qid=".$ia[0]." AND language='".$_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['s_lang']."' ";
23        $result = Yii::app()->db->createCommand($query)->query();
24        foreach ($result->readAll() as $row)
25        {
26            $other = $row['other'];
27        }
28
29        //question attribute random order set?
30        if ($aQuestionAttributes['random_order']==1) {
31            $ansquery = "SELECT * FROM {{answers}} WHERE qid=$ia[0] AND language='".$_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['s_lang']."' and scale_id=0 ORDER BY ".dbRandom();
32        }
33
34        //question attribute alphasort set?
35        elseif ($aQuestionAttributes['alphasort']==1)
36        {
37            $ansquery = "SELECT * FROM {{answers}} WHERE qid=$ia[0] AND language='".$_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['s_lang']."' and scale_id=0 ORDER BY answer";
38        }
39
40        //no question attributes -> order by sortorder
41        else
42        {
43            $ansquery = "SELECT * FROM {{answers}} WHERE qid=$ia[0] AND language='".$_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['s_lang']."' and scale_id=0 ORDER BY sortorder, answer";
44        }
45
46        $ansresult = dbExecuteAssoc($ansquery)->readAll();  //Checked
47        $anscount = count($ansresult);
48
49        if (trim($aQuestionAttributes['display_columns'])!='')
50        {
51            $dcols = $aQuestionAttributes['display_columns'];
52        }
53        else
54        {
55            $dcols= 1;
56        }
57
58        if (trim($aQuestionAttributes['other_replace_text'][$_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['s_lang']])!='')
59        {
60            $othertext=$aQuestionAttributes['other_replace_text'][$_SESSION['survey_'.Yii::app()->getConfig('surveyID')]['s_lang']];
61        }
62        else
63        {
64            $othertext=gT('Other:');
65        }
66
67        if (isset($other) && $other=='Y') {$anscount++;} //Count up for the Other answer
68        if ($ia[6] != 'Y' && SHOW_NO_ANSWER == 1) {$anscount++;} //Count up if "No answer" is showing
69
70        $wrapper = setupColumns($dcols , $anscount,"answers-list radio-list","answer-item radio-item");
71
72        $iBootCols = round(12/$dcols);
73        $ansByCol = round($anscount/$dcols); $ansByCol = ($ansByCol > 0)?$ansByCol:1;
74
75        //$answer = 'IKI: '.$iBootCols.' '.$ansByCol.' '.$wrapper['whole-start'];
76        $answer = '<div class="row">';
77        $answer .= '    <div class="col-xs-'.$iBootCols.'">AAAAAAAAAAAAAA';
78
79        //Time Limit Code
80        if (trim($aQuestionAttributes['time_limit'])!='')
81        {
82            $answer .= return_timer_script($aQuestionAttributes, $ia);
83        }
84        //End Time Limit Code
85
86        // Get array_filter stuff
87
88        $rowcounter = 0;
89        $colcounter = 1;
90        $trbc='';
91
92        foreach ($ansresult as $key=>$ansrow)
93        {
94            $myfname = $ia[1].$ansrow['code'];
95            $check_ans = '';
96            if ($_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$ia[1]] == $ansrow['code'])
97            {
98                $check_ans = CHECKED;
99            }
100            list($htmltbody2, $hiddenfield)=return_array_filter_strings($ia, $aQuestionAttributes, $thissurvey, $ansrow, $myfname, '', $myfname, "div","form-group answer-item radio-item");
101        /*    if(substr($wrapper['item-start'],0,4) == "\t<li")
102            {
103                $startitem = "\t$htmltbody2\n";
104            } else {
105                $startitem = $wrapper['item-start'];
106            }
107
108            $answer .= $startitem;*/
109            $answer .= "\t$hiddenfield\n";
110
111            $answer .= '<div  class="form-group">';
112            $answer .= '    <label for="answer'.$ia[1].$ansrow['code'].'" class="answertext control-label">'.$ansrow['answer'].'</label>';
113            $answer .= '        <input class="radio" type="radio" value="'.$ansrow['code'].'" name="'.$ia[1].'" id="answer'.$ia[1].$ansrow['code'].'"'.$check_ans.' onclick="if (document.getElementById(\'answer'.$ia[1].'othertext\') != null) document.getElementById(\'answer'.$ia[1].'othertext\').value=\'\';'.$checkconditionFunction.'(this.value, this.name, this.type)" />';
114            $answer .=          $wrapper['item-end'];
115            $answer .= '</div>';
116
117            ++$rowcounter;
118            //if ($rowcounter == $wrapper['maxrows'] && $colcounter < $wrapper['cols'] || (count($ansresult)-$key)==$wrapper['cols']-$colcounter)
119            if ($rowcounter == $ansByCol && $colcounter < $wrapper['cols'])
120            {
121                if($colcounter == $wrapper['cols'] )
122                {
123                    //$answer .= 'là '.$wrapper['col-devide-last'];
124                    $answer .= '    </div><!-- last -->';
125                }
126                else
127                {
128                    //$answer .= 'et là '.$wrapper['col-devide'];
129                    $answer .= '    </div><!-- devide --> ';
130                    $answer .= '    <div class="col-xs-'.$iBootCols.'">';
131                }
132                $rowcounter = 0;
133                ++$colcounter;
134            }
135        }
136
137        if (isset($other) && $other=='Y')
138        {
139
140            $sSeparator = getRadixPointData($thissurvey['surveyls_numberformat']);
141            $sSeparator = $sSeparator['separator'];
142
143            if ($aQuestionAttributes['other_numbers_only']==1)
144            {
145                $oth_checkconditionFunction = 'fixnum_checkconditions';
146            }
147            else
148            {
149                $oth_checkconditionFunction = 'checkconditions';
150            }
151
152
153            if ($_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$ia[1]] == '-oth-')
154            {
155                $check_ans = CHECKED;
156            }
157            else
158            {
159                $check_ans = '';
160            }
161
162            $thisfieldname=$ia[1].'other';
163            if (isset($_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$thisfieldname]))
164            {
165                $dispVal = $_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$thisfieldname];
166                if ($aQuestionAttributes['other_numbers_only']==1)
167                {
168                    $dispVal = str_replace('.',$sSeparator,$dispVal);
169                }
170                $answer_other = ' value="'.htmlspecialchars($dispVal,ENT_QUOTES).'"';
171            }
172            else
173            {
174                $answer_other = ' value=""';
175            }
176
177            list($htmltbody2, $hiddenfield)=return_array_filter_strings($ia, $aQuestionAttributes, $thissurvey, array("code"=>"other"), $thisfieldname, $trbc, $myfname, "div", "form-group answer-item radio-item other-item other");
178
179            $answer .= "\t$hiddenfield\n";
180            $answer .= '<div  class="form-group">';
181            $answer .= '    <label for="SOTH'.$ia[1].'" class="answertext control-label">'.$othertext.'</label>';
182            $answer .= '    <input class="radio" type="radio" value="-oth-" name="'.$ia[1].'" id="SOTH'.$ia[1].'"'.$check_ans.' onclick="'.$checkconditionFunction.'(this.value, this.name, this.type)" />';
183            $answer .= '    <input type="text" class="text '.$kpclass.'" id="answer'.$ia[1].'othertext" name="'.$ia[1].'other" title="'.gT('Other').'"'.$answer_other.' onkeyup="if($.trim($(this).val())!=\'\'){ $(\'#SOTH'.$ia[1].'\').click(); }; '.$oth_checkconditionFunction.'(this.value, this.name, this.type);" />';
184            $answer .=      $wrapper['item-end'];
185            $answer .= '</div>';
186            $inputnames[]=$thisfieldname;
187
188            ++$rowcounter;
189            if ($rowcounter == $ansByCol && $colcounter < $wrapper['cols'])
190            {
191                if($colcounter == $wrapper['cols'] )
192                {
193                    $answer .= '    </div><!-- last -->';
194                }
195                else
196                {
197                    $answer .= '    </div><!-- devide -->';
198                    $answer .= '    <div class="col-xs-'.$iBootCols.'">';
199                }
200                $rowcounter = 0;
201                ++$colcounter;
202            }
203        }
204
205        if ($ia[6] != 'Y' && SHOW_NO_ANSWER == 1)
206        {
207            if ((!isset($_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$ia[1]]) || $_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$ia[1]] == '') || ($_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$ia[1]] == ' ' ))
208            {
209                $check_ans = CHECKED; //Check the "no answer" radio button if there is no answer in session.
210            }
211            else
212            {
213                $check_ans = '';
214            }
215
216            $answer .= '<div  class="form-group">';
217            $answer .= '    <label for="answer'.$ia[1].'" class="answertext control-label">'.gT('No answer').'</label>';
218            $answer .= '        <input class="radio" type="radio" name="'.$ia[1].'" id="answer'.$ia[1].'" value=""'.$check_ans.' onclick="if (document.getElementById(\'answer'.$ia[1].'othertext\') != null) document.getElementById(\'answer'.$ia[1].'othertext\').value=\'\';'.$checkconditionFunction.'(this.value, this.name, this.type)" />';
219            $answer .=          $wrapper['item-end'];
220            $answer .= '</div>';
221
222            // --> END NEW FEATURE - SAVE
223
224            ++$rowcounter;
225            //if ($rowcounter == $wrapper['maxrows'] && $colcounter < $wrapper['cols'])
226            if ($rowcounter == $ansByCol && $colcounter < $wrapper['cols'])
227            {
228                if($colcounter == $wrapper['cols'] )
229                {
230                    //$answer .= $wrapper['col-devide-last'];
231                    $answer .= '    </div><!-- last -->';
232                }
233                else
234                {
235                    //$answer .= $wrapper['col-devide'];
236                    $answer .= '    </div><!-- devide -->';
237                    $answer .= '    <div class="col-xs-'.$iBootCols.'">';
238                }
239                $rowcounter = 0;
240                ++$colcounter;
241            }
242
243        }
244        //END OF ITEMS
245        //$answer .= $wrapper['whole-end'].'
246        $answer .= '    <input type="hidden" name="java'.$ia[1].'" id="java'.$ia[1]."\" value=\"".$_SESSION['survey_'.Yii::app()->getConfig('surveyID')][$ia[1]]."\" />\n";
247        $answer .= '</div> <!-- wrapper row -->';
248
249        $inputnames[]=$ia[1];
250        return array($answer, $inputnames);
251
252    }
253}
254