1<?php
2
3    /**
4     * @file
5     *
6     * This file holds the widget for the yes-no question type, to edit it's default values.
7     *
8     * Features:
9     * - YES/NO preselection
10     * - EM integration to insert an em expression like {TOKEN:ATTRIBUTE_6}. At this state there is no validation implemented. Attributes must hold Y or N.
11     *
12     * DEV MEMO:
13     * Validation could be difficult cause if you using tokens and you don't had setup a working token dataset
14     *
15     * For this feature you need editDefaultvalues.php, database.php, adminstyle.css
16     */
17
18    class yesNo_defaultvalue_widget extends CWidget
19    {
20        public $widgetOptions;
21
22        //init() method is called automatically before all others
23        public function init()
24        {
25            /*you can set initial default values and other stuff here.
26             * it's also a good place to register any CSS or Javascript your
27             * widget may need. */
28
29        }
30
31        public function run()
32        {
33
34            $qtproperties = $this->widgetOptions['qtproperties'];
35            $questionrow = $this->widgetOptions['questionrow'];
36            $langopts = $this->widgetOptions['langopts'];
37            $language = $this->widgetOptions['language'];
38            $defaultValues =  $this->widgetOptions['langopts'][$language][$questionrow['type']][0];
39
40            $emfield_css = '';
41            $emValue = '';
42            $select = '';
43            $sEmfield_css_class = '';
44
45            // prepare variables for prefilling the form
46            if(!is_null ($defaultValues))
47            {
48                $sDefaultValue = $defaultValues;
49                if(($sDefaultValue == 'N') || ($sDefaultValue == 'Y') || ($sDefaultValue == '') ){ //|| 'Y' || NULL)){
50                $select = $defaultValues;
51            }else{
52                $select = 'EM';
53                $emValue = $defaultValues;
54            }
55            }
56
57            if($questionrow['type'] == 'Y') // do we need this?
58            {
59                $sElement_id = 'defaultanswerscale_0_' . $language;
60
61                $aList = array(
62                    'N'    => gT('No','unescaped'),
63                    'Y'    => gT('Yes','unescaped'),
64                    'EM'   => gT('EM value','unescaped')
65                );
66
67                $aHtmlOptions = array(
68                    'empty'    => gT('<No default value>'),
69                    'class'    => $sElement_id . ' form-control',
70                    'onchange' => '// show EM Value Field
71                                   if ($(this).val() == "EM"){
72                                       $("#"+$(this).closest("select").attr("id")+ "_EM").removeClass("hide");
73                                   }else{
74                                       $("#"+$(this).closest("select").attr("id")+ "_EM").addClass("hide");} '
75                );
76
77                echo CHtml::dropDownList($sElement_id, $select, $aList, $aHtmlOptions);
78
79                // textfield preparation
80                if(empty($defaultValues) ||  $defaultValues == 'Y')
81                {
82                    $sEmfield_css_class = 'hide';
83                }
84                echo CHtml::textField ($sElement_id . '_EM', $emValue,array(
85                        'id'    => $sElement_id . '_EM',
86                        'class' => $sEmfield_css_class,
87                        'width' => 100
88                    ));
89            }
90        }
91    }
92