Exemplo n.º 1
0
function do_shortfreetext($ia)
{
    global $thissurvey;
    $sGoogleMapsAPIKey = trim(Yii::app()->getConfig("googleMapsAPIKey"));
    if ($sGoogleMapsAPIKey != '') {
        $sGoogleMapsAPIKey = '&key=' . $sGoogleMapsAPIKey;
    }
    $extraclass = "";
    $aQuestionAttributes = getQuestionAttributeValues($ia[0]);
    if ($aQuestionAttributes['numbers_only'] == 1) {
        $sSeparator = getRadixPointData($thissurvey['surveyls_numberformat']);
        $sSeparator = $sSeparator['separator'];
        $extraclass .= " numberonly";
        $checkconditionFunction = "fixnum_checkconditions";
    } else {
        $checkconditionFunction = "checkconditions";
    }
    if (intval(trim($aQuestionAttributes['maximum_chars'])) > 0) {
        // Only maxlength attribute, use textarea[maxlength] jquery selector for textarea
        $maximum_chars = intval(trim($aQuestionAttributes['maximum_chars']));
        $maxlength = "maxlength='{$maximum_chars}' ";
        $extraclass .= " maxchars maxchars-" . $maximum_chars;
    } else {
        $maxlength = "";
    }
    if (trim($aQuestionAttributes['text_input_width']) != '') {
        $tiwidth = $aQuestionAttributes['text_input_width'];
        $extraclass .= " inputwidth-" . trim($aQuestionAttributes['text_input_width']);
    } else {
        $tiwidth = 50;
    }
    if (trim($aQuestionAttributes['prefix'][$_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang']]) != '') {
        $prefix = $aQuestionAttributes['prefix'][$_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang']];
        $extraclass .= " withprefix";
    } else {
        $prefix = '';
    }
    if (trim($aQuestionAttributes['suffix'][$_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang']]) != '') {
        $suffix = $aQuestionAttributes['suffix'][$_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang']];
        $extraclass .= " withsuffix";
    } else {
        $suffix = '';
    }
    if ($thissurvey['nokeyboard'] == 'Y') {
        includeKeypad();
        $kpclass = "text-keypad";
        $extraclass .= " inputkeypad";
    } else {
        $kpclass = "";
    }
    if (trim($aQuestionAttributes['display_rows']) != '') {
        //question attribute "display_rows" is set -> we need a textarea to be able to show several rows
        $drows = $aQuestionAttributes['display_rows'];
        //if a textarea should be displayed we make it equal width to the long text question
        //this looks nicer and more continuous
        if ($tiwidth == 50) {
            $tiwidth = 40;
        }
        //NEW: textarea instead of input=text field
        // --> START NEW FEATURE - SAVE
        $answer = "<p class='question answer-item text-item {$extraclass}'><label for='answer{$ia[1]}' class='hide label'>" . gT('Your answer') . "</label>" . '<textarea class="textarea ' . $kpclass . '" name="' . $ia[1] . '" id="answer' . $ia[1] . '" ' . 'rows="' . $drows . '" cols="' . $tiwidth . '" ' . $maxlength . ' onkeyup="' . $checkconditionFunction . '(this.value, this.name, this.type);">';
        // --> END NEW FEATURE - SAVE
        if ($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$ia[1]]) {
            $dispVal = str_replace("\\", "", $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$ia[1]]);
            if ($aQuestionAttributes['numbers_only'] == 1) {
                $dispVal = str_replace('.', $sSeparator, $dispVal);
            }
            $answer .= $dispVal;
        }
        $answer .= "</textarea></p>\n";
    } elseif ((int) $aQuestionAttributes['location_mapservice'] == 1) {
        $mapservice = $aQuestionAttributes['location_mapservice'];
        $currentLocation = $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$ia[1]];
        $currentLatLong = null;
        $floatLat = 0;
        $floatLng = 0;
        // Get the latitude/longtitude for the point that needs to be displayed by default
        if (strlen($currentLocation) > 2) {
            $currentLatLong = explode(';', $currentLocation);
            $currentLatLong = array($currentLatLong[0], $currentLatLong[1]);
        } else {
            if ((int) $aQuestionAttributes['location_nodefaultfromip'] == 0) {
                $currentLatLong = getLatLongFromIp(getIPAddress());
            }
            if (!isset($currentLatLong) || $currentLatLong == false) {
                $floatLat = 0;
                $floatLng = 0;
                $LatLong = explode(" ", trim($aQuestionAttributes['location_defaultcoordinates']));
                if (isset($LatLong[0]) && isset($LatLong[1])) {
                    $floatLat = $LatLong[0];
                    $floatLng = $LatLong[1];
                }
                $currentLatLong = array($floatLat, $floatLng);
            }
        }
        // 2 - city; 3 - state; 4 - country; 5 - postal
        $strBuild = "";
        if ($aQuestionAttributes['location_city']) {
            $strBuild .= "2";
        }
        if ($aQuestionAttributes['location_state']) {
            $strBuild .= "3";
        }
        if ($aQuestionAttributes['location_country']) {
            $strBuild .= "4";
        }
        if ($aQuestionAttributes['location_postal']) {
            $strBuild .= "5";
        }
        $currentLocation = $currentLatLong[0] . " " . $currentLatLong[1];
        $answer = "\n        <script type=\"text/javascript\">\n        zoom['{$ia['1']}'] = {$aQuestionAttributes['location_mapzoom']};\n        </script>\n\n        <div class=\"question answer-item geoloc-item {$extraclass}\">\n        <input type=\"hidden\" name=\"{$ia['1']}\" id=\"answer{$ia['1']}\" value=\"{$_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$ia[1]]}\">\n\n        <input class=\"text location " . $kpclass . "\" type=\"text\" size=\"20\" name=\"{$ia['1']}_c\"\n        id=\"answer{$ia['1']}_c\" value=\"{$currentLocation}\"\n        onchange=\"{$checkconditionFunction}(this.value, this.name, this.type)\" />\n\n        <input type=\"hidden\" name=\"boycott_{$ia['1']}\" id=\"boycott_{$ia['1']}\"\n        value = \"{$strBuild}\" >\n\n        <input type=\"hidden\" name=\"mapservice_{$ia['1']}\" id=\"mapservice_{$ia['1']}\"\n        class=\"mapservice\" value = \"{$aQuestionAttributes['location_mapservice']}\" >\n        <div id=\"gmap_canvas_{$ia['1']}_c\" style=\"width: {$aQuestionAttributes['location_mapwidth']}px; height: {$aQuestionAttributes['location_mapheight']}px\"></div>\n        </div>";
        Yii::app()->getClientScript()->registerScriptFile(Yii::app()->getConfig('generalscripts') . "map.js");
        if ($aQuestionAttributes['location_mapservice'] == 1 && !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != "off") {
            Yii::app()->getClientScript()->registerScriptFile("https://maps.googleapis.com/maps/api/js?sensor=false{$sGoogleMapsAPIKey}");
        } else {
            if ($aQuestionAttributes['location_mapservice'] == 1) {
                Yii::app()->getClientScript()->registerScriptFile("http://maps.googleapis.com/maps/api/js?sensor=false{$sGoogleMapsAPIKey}");
            } elseif ($aQuestionAttributes['location_mapservice'] == 2) {
                Yii::app()->getClientScript()->registerScriptFile("http://www.openlayers.org/api/OpenLayers.js");
            }
        }
        if (isset($aQuestionAttributes['hide_tip']) && $aQuestionAttributes['hide_tip'] == 0) {
            $answer .= "<div class=\"questionhelp\">" . gT('Drag and drop the pin to the desired location. You may also right click on the map to move the pin.') . '</div>';
            $question_text['help'] = gT('Drag and drop the pin to the desired location. You may also right click on the map to move the pin.');
        }
    } elseif ((int) $aQuestionAttributes['location_mapservice'] == 100) {
        $currentLocation = $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$ia[1]];
        $currentCenter = $currentLatLong = null;
        // Get the latitude/longtitude for the point that needs to be displayed by default
        if (strlen($currentLocation) > 2 && strpos($currentLocation, ";")) {
            $currentLatLong = explode(';', $currentLocation);
            $currentCenter = $currentLatLong = array($currentLatLong[0], $currentLatLong[1]);
        } elseif ((int) $aQuestionAttributes['location_nodefaultfromip'] == 0) {
            $currentCenter = $currentLatLong = getLatLongFromIp(getIPAddress());
        }
        // If it's not set : set the center to the default position, but don't set the marker
        if (!$currentLatLong) {
            $currentLatLong = array("", "");
            $currentCenter = explode(" ", trim($aQuestionAttributes['location_defaultcoordinates']));
            if (count($currentCenter) != 2) {
                $currentCenter = array("", "");
            }
        }
        // 2 - city; 3 - state; 4 - country; 5 - postal
        // TODO : move it to aThisMapScriptVar and use geoname reverse geocoding (http://www.geonames.org/export/reverse-geocoding.html)
        $strBuild = "";
        /*if ($aQuestionAttributes['location_city'])
              $strBuild .= "2";
          if ($aQuestionAttributes['location_state'])
              $strBuild .= "3";
          if ($aQuestionAttributes['location_country'])
              $strBuild .= "4";
          if ($aQuestionAttributes['location_postal'])
              $strBuild .= "5";*/
        $aGlobalMapScriptVar = array('geonameUser' => getGlobalSetting('GeoNamesUsername'), 'geonameLang' => Yii::app()->language);
        $aThisMapScriptVar = array('zoomLevel' => $aQuestionAttributes['location_mapzoom'], 'latitude' => $currentCenter[0], 'longitude' => $currentCenter[1]);
        App()->getClientScript()->registerPackage('leaflet');
        Yii::app()->getClientScript()->registerScript('sGlobalMapScriptVar', "LSmap=" . ls_json_encode($aGlobalMapScriptVar) . ";\nLSmaps= new Array();", CClientScript::POS_HEAD);
        Yii::app()->getClientScript()->registerScript('sThisMapScriptVar' . $ia[1], "LSmaps['{$ia[1]}']=" . ls_json_encode($aThisMapScriptVar), CClientScript::POS_HEAD);
        Yii::app()->getClientScript()->registerScriptFile(Yii::app()->getConfig('generalscripts') . "map.js");
        Yii::app()->getClientScript()->registerCssFile(Yii::app()->getConfig('publicstyleurl') . 'map.css');
        $answer = "\n        <div class=\"question answer-item geoloc-item {$extraclass}\">\n            <input type=\"hidden\"  name=\"{$ia['1']}\" id=\"answer{$ia['1']}\" value=\"{$_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$ia[1]]}\"><!-- No javascript need a way to answer -->\n            <input type=\"hidden\" class=\"location\" name=\"{$ia['1']}_c\" id=\"answer{$ia['1']}_c\" value=\"{$currentLatLong[0]} {$currentLatLong[1]}\" />\n\n            <ul class=\"coordinates-list\">\n                <li class=\"coordinate-item\">" . gt("Latitude:") . "<input class=\"coords text\" type=\"text\" name=\"{$ia['1']}_c1\" id=\"answer_lat{$ia['1']}_c\"  value=\"{$currentLatLong[0]}\" /></li>\n                <li class=\"coordinate-item\">" . gt("Longitude:") . "<input class=\"coords text\" type=\"text\" name=\"{$ia['1']}_c2\" id=\"answer_lng{$ia['1']}_c\" value=\"{$currentLatLong[1]}\" /></li>\n            </ul>\n\n            <input type=\"hidden\" name=\"boycott_{$ia['1']}\" id=\"boycott_{$ia['1']}\" value = \"{$strBuild}\" > \n            <input type=\"hidden\" name=\"mapservice_{$ia['1']}\" id=\"mapservice_{$ia['1']}\" class=\"mapservice\" value = \"{$aQuestionAttributes['location_mapservice']}\" >\n\n            <div>\n                <div class=\"geoname_restrict\">\n                    <input type=\"checkbox\" id=\"restrictToExtent_{$ia[1]}\"> <label for=\"restrictToExtent_{$ia[1]}\">" . gt("Restrict search place to map extent") . "</label>\n                </div>\n                <div class=\"geoname_search\" >\n                    <input id=\"searchbox_{$ia[1]}\" placeholder=\"" . gt("Search") . "\" width=\"15\">\n                </div>\n            </div>\n            <div id=\"map_{$ia[1]}\" style=\"width: 100%; height: {$aQuestionAttributes['location_mapheight']}px;\">\n        </div>\n        ";
        if (isset($aQuestionAttributes['hide_tip']) && $aQuestionAttributes['hide_tip'] == 0) {
            $answer .= "<div class=\"questionhelp\">" . gT('Click to set the location or drag and drop the pin. You may may also enter coordinates') . '</div>';
            $question_text['help'] = gT('Click to set the location or drag and drop the pin. You may may also enter coordinates');
        }
    } else {
        //no question attribute set, use common input text field
        $answer = "<p class=\"question answer-item text-item {$extraclass}\">\n" . "<label for='answer{$ia[1]}' class='hide label'>" . gT('Your answer') . "</label>" . "{$prefix}\t<input class=\"text {$kpclass}\" type=\"text\" size=\"{$tiwidth}\" name=\"{$ia['1']}\" id=\"answer{$ia['1']}\"";
        $dispVal = $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$ia[1]];
        if ($aQuestionAttributes['numbers_only'] == 1) {
            $dispVal = str_replace('.', $sSeparator, $dispVal);
        }
        $dispVal = htmlspecialchars($dispVal, ENT_QUOTES, 'UTF-8');
        $answer .= " value=\"{$dispVal}\"";
        $answer .= " {$maxlength} onkeyup=\"{$checkconditionFunction}(this.value, this.name, this.type)\"/>\n\t{$suffix}\n</p>\n";
    }
    if (trim($aQuestionAttributes['time_limit']) != '') {
        $answer .= return_timer_script($aQuestionAttributes, $ia, "answer" . $ia[1]);
    }
    $inputnames[] = $ia[1];
    return array($answer, $inputnames);
}
Exemplo n.º 2
0
function do_shortfreetext($ia)
{
    global $thissurvey;
    $sGoogleMapsAPIKey = trim(Yii::app()->getConfig("googleMapsAPIKey"));
    if ($sGoogleMapsAPIKey != '') {
        $sGoogleMapsAPIKey = '&key=' . $sGoogleMapsAPIKey;
    }
    $extraclass = "";
    $aQuestionAttributes = QuestionAttribute::model()->getQuestionAttributes($ia[0]);
    if ($aQuestionAttributes['numbers_only'] == 1) {
        $sSeparator = getRadixPointData($thissurvey['surveyls_numberformat']);
        $sSeparator = $sSeparator['separator'];
        $extraclass .= " numberonly";
        $checkconditionFunction = "fixnum_checkconditions";
    } else {
        $checkconditionFunction = "checkconditions";
    }
    if (intval(trim($aQuestionAttributes['maximum_chars'])) > 0) {
        // Only maxlength attribute, use textarea[maxlength] jquery selector for textarea
        $maximum_chars = intval(trim($aQuestionAttributes['maximum_chars']));
        $maxlength = "maxlength='{$maximum_chars}' ";
        $extraclass .= " maxchars maxchars-" . $maximum_chars;
    } else {
        $maxlength = "";
    }
    if (trim($aQuestionAttributes['text_input_width']) != '') {
        $tiwidth = $aQuestionAttributes['text_input_width'];
        $extraclass .= " inputwidth-" . trim($aQuestionAttributes['text_input_width']);
        $col = $aQuestionAttributes['text_input_width'] <= 12 ? $aQuestionAttributes['text_input_width'] : 12;
        $extraclass .= " col-sm-" . trim($col);
    } else {
        $tiwidth = 50;
    }
    if (trim($aQuestionAttributes['prefix'][$_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang']]) != '') {
        $prefix = $aQuestionAttributes['prefix'][$_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang']];
        $extraclass .= " withprefix";
    } else {
        $prefix = '';
    }
    if (trim($aQuestionAttributes['suffix'][$_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang']]) != '') {
        $suffix = $aQuestionAttributes['suffix'][$_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang']];
        $extraclass .= " withsuffix";
    } else {
        $suffix = '';
    }
    if ($thissurvey['nokeyboard'] == 'Y') {
        includeKeypad();
        $kpclass = "text-keypad";
        $extraclass .= " inputkeypad";
    } else {
        $kpclass = "";
    }
    $answer = "";
    if (trim($aQuestionAttributes['display_rows']) != '') {
        //question attribute "display_rows" is set -> we need a textarea to be able to show several rows
        $drows = $aQuestionAttributes['display_rows'];
        //if a textarea should be displayed we make it equal width to the long text question
        //this looks nicer and more continuous
        if ($tiwidth == 50) {
            $tiwidth = 40;
        }
        $dispVal = "";
        if ($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$ia[1]]) {
            $dispVal = str_replace("\\", "", $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$ia[1]]);
            if ($aQuestionAttributes['numbers_only'] == 1) {
                $dispVal = str_replace('.', $sSeparator, $dispVal);
            }
            $dispVal = htmlspecialchars($dispVal);
        }
        $answer .= doRender('/survey/questions/shortfreetext/textarea/item', array('extraclass' => $extraclass, 'freeTextId' => 'answer' . $ia[1], 'labelText' => gT('Your answer'), 'name' => $ia[1], 'drows' => $drows, 'tiwidth' => $tiwidth, 'checkconditionFunction' => $checkconditionFunction . '(this.value, this.name, this.type)', 'dispVal' => $dispVal, 'maxlength' => $maxlength, 'kpclass' => $kpclass, 'prefix' => $prefix, 'suffix' => $suffix, 'sm_col' => decide_sm_col($prefix, $suffix)), true);
    } elseif ((int) $aQuestionAttributes['location_mapservice'] == 1) {
        $mapservice = $aQuestionAttributes['location_mapservice'];
        $currentLocation = $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$ia[1]];
        $currentLatLong = null;
        $floatLat = 0;
        $floatLng = 0;
        // Get the latitude/longtitude for the point that needs to be displayed by default
        if (strlen($currentLocation) > 2) {
            $currentLatLong = explode(';', $currentLocation);
            $currentLatLong = array($currentLatLong[0], $currentLatLong[1]);
        } else {
            if ((int) $aQuestionAttributes['location_nodefaultfromip'] == 0) {
                $currentLatLong = getLatLongFromIp(getIPAddress());
            }
            if (!isset($currentLatLong) || $currentLatLong == false) {
                $floatLat = 0;
                $floatLng = 0;
                $LatLong = explode(" ", trim($aQuestionAttributes['location_defaultcoordinates']));
                if (isset($LatLong[0]) && isset($LatLong[1])) {
                    $floatLat = $LatLong[0];
                    $floatLng = $LatLong[1];
                }
                $currentLatLong = array($floatLat, $floatLng);
            }
        }
        // 2 - city; 3 - state; 4 - country; 5 - postal
        $strBuild = "";
        if ($aQuestionAttributes['location_city']) {
            $strBuild .= "2";
        }
        if ($aQuestionAttributes['location_state']) {
            $strBuild .= "3";
        }
        if ($aQuestionAttributes['location_country']) {
            $strBuild .= "4";
        }
        if ($aQuestionAttributes['location_postal']) {
            $strBuild .= "5";
        }
        $currentLocation = $currentLatLong[0] . " " . $currentLatLong[1];
        Yii::app()->getClientScript()->registerScriptFile(Yii::app()->getConfig('generalscripts') . "map.js");
        if ($aQuestionAttributes['location_mapservice'] == 1 && !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != "off") {
            Yii::app()->getClientScript()->registerScriptFile("https://maps.googleapis.com/maps/api/js?sensor=false{$sGoogleMapsAPIKey}");
        } else {
            if ($aQuestionAttributes['location_mapservice'] == 1) {
                Yii::app()->getClientScript()->registerScriptFile("http://maps.googleapis.com/maps/api/js?sensor=false{$sGoogleMapsAPIKey}");
            } elseif ($aQuestionAttributes['location_mapservice'] == 2) {
                Yii::app()->getClientScript()->registerScriptFile("http://www.openlayers.org/api/OpenLayers.js");
            }
        }
        $questionHelp = false;
        if (isset($aQuestionAttributes['hide_tip']) && $aQuestionAttributes['hide_tip'] == 0) {
            $questionHelp = true;
            $question_text['help'] = gT('Drag and drop the pin to the desired location. You may also right click on the map to move the pin.');
        }
        $answer = doRender('/survey/questions/shortfreetext/location_mapservice/item', array('extraclass' => $extraclass, 'freeTextId' => 'answer' . $ia[1], 'labelText' => gT('Your answer'), 'name' => $ia[1], 'checkconditionFunction' => $checkconditionFunction . '(this.value, this.name, this.type)', 'value' => $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$ia[1]], 'kpclass' => $kpclass, 'currentLocation' => $currentLocation, 'strBuild' => $strBuild, 'location_mapservice' => $aQuestionAttributes['location_mapservice'], 'location_mapzoom' => $aQuestionAttributes['location_mapzoom'], 'location_mapheight' => $aQuestionAttributes['location_mapheight'], 'questionHelp' => $questionHelp, 'question_text_help' => isset($question_text) ? $question_text['help'] : '', 'sm_col' => decide_sm_col($prefix, $suffix)), true);
    } elseif ((int) $aQuestionAttributes['location_mapservice'] == 100) {
        $currentLocation = $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$ia[1]];
        $currentCenter = $currentLatLong = null;
        // Get the latitude/longtitude for the point that needs to be displayed by default
        if (strlen($currentLocation) > 2 && strpos($currentLocation, ";")) {
            $currentLatLong = explode(';', $currentLocation);
            $currentCenter = $currentLatLong = array($currentLatLong[0], $currentLatLong[1]);
        } elseif ((int) $aQuestionAttributes['location_nodefaultfromip'] == 0) {
            $currentCenter = $currentLatLong = getLatLongFromIp(getIPAddress());
        }
        // If it's not set : set the center to the default position, but don't set the marker
        if (!$currentLatLong) {
            $currentLatLong = array("", "");
            $currentCenter = explode(" ", trim($aQuestionAttributes['location_defaultcoordinates']));
            if (count($currentCenter) != 2) {
                $currentCenter = array("", "");
            }
        }
        $strBuild = "";
        $aGlobalMapScriptVar = array('geonameUser' => getGlobalSetting('GeoNamesUsername'), 'geonameLang' => Yii::app()->language);
        $aThisMapScriptVar = array('zoomLevel' => $aQuestionAttributes['location_mapzoom'], 'latitude' => $currentCenter[0], 'longitude' => $currentCenter[1]);
        App()->getClientScript()->registerPackage('leaflet');
        Yii::app()->getClientScript()->registerScript('sGlobalMapScriptVar', "LSmap=" . ls_json_encode($aGlobalMapScriptVar) . ";\nLSmaps= new Array();", CClientScript::POS_HEAD);
        Yii::app()->getClientScript()->registerScript('sThisMapScriptVar' . $ia[1], "LSmaps['{$ia[1]}']=" . ls_json_encode($aThisMapScriptVar), CClientScript::POS_HEAD);
        Yii::app()->getClientScript()->registerScriptFile(Yii::app()->getConfig('generalscripts') . "map.js");
        Yii::app()->getClientScript()->registerCssFile(Yii::app()->getConfig('publicstyleurl') . 'map.css');
        if (isset($aQuestionAttributes['hide_tip']) && $aQuestionAttributes['hide_tip'] == 0) {
            $questionHelp = true;
            $question_text['help'] = gT('Click to set the location or drag and drop the pin. You may may also enter coordinates');
        }
        $itemDatas = array('extraclass' => $extraclass, 'name' => $ia[1], 'checkconditionFunction' => $checkconditionFunction . '(this.value, this.name, this.type)', 'value' => $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$ia[1]], 'strBuild' => $strBuild, 'location_mapservice' => $aQuestionAttributes['location_mapservice'], 'location_mapzoom' => $aQuestionAttributes['location_mapzoom'], 'location_mapheight' => $aQuestionAttributes['location_mapheight'], 'questionHelp' => isset($questionHelp) ? $questionHelp : '', 'question_text_help' => $question_text['help'], 'location_value' => $currentLatLong[0] . ' ' . $currentLatLong[1], 'currentLat' => $currentLatLong[0], 'currentLong' => $currentLatLong[1]);
        $answer = doRender('/survey/questions/shortfreetext/location_mapservice/item_100', $itemDatas, true);
    } else {
        //no question attribute set, use common input text field
        $dispVal = $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$ia[1]];
        if ($aQuestionAttributes['numbers_only'] == 1) {
            $dispVal = str_replace('.', $sSeparator, $dispVal);
        }
        $dispVal = htmlspecialchars($dispVal, ENT_QUOTES, 'UTF-8');
        $itemDatas = array('extraclass' => $extraclass, 'name' => $ia[1], 'checkconditionFunction' => $checkconditionFunction . '(this.value, this.name, this.type)', 'prefix' => $prefix, 'suffix' => $suffix, 'kpclass' => $kpclass, 'tiwidth' => $tiwidth, 'dispVal' => $dispVal, 'maxlength' => $maxlength, 'sm_col' => decide_sm_col($prefix, $suffix));
        $answer = doRender('/survey/questions/shortfreetext/text/item', $itemDatas, true);
    }
    if (trim($aQuestionAttributes['time_limit']) != '') {
        $answer .= return_timer_script($aQuestionAttributes, $ia, "answer" . $ia[1]);
    }
    $inputnames = array();
    $inputnames[] = $ia[1];
    return array($answer, $inputnames);
}
Exemplo n.º 3
0
function do_shortfreetext($ia)
{
    global $thissurvey;
    $clang = Yii::app()->lang;
    $sGoogleMapsAPIKey = trim(Yii::app()->getConfig("googleMapsAPIKey"));
    if ($sGoogleMapsAPIKey != '') {
        $sGoogleMapsAPIKey = '&key=' . $sGoogleMapsAPIKey;
    }
    $extraclass = "";
    $aQuestionAttributes = getQuestionAttributeValues($ia[0], $ia[4]);
    if ($aQuestionAttributes['numbers_only'] == 1) {
        $sSeparator = getRadixPointData($thissurvey['surveyls_numberformat']);
        $sSeparator = $sSeparator['separator'];
        $extraclass .= " numberonly";
        $checkconditionFunction = "fixnum_checkconditions";
    } else {
        $checkconditionFunction = "checkconditions";
    }
    if (intval(trim($aQuestionAttributes['maximum_chars'])) > 0) {
        // Only maxlength attribute, use textarea[maxlength] jquery selector for textarea
        $maximum_chars = intval(trim($aQuestionAttributes['maximum_chars']));
        $maxlength = "maxlength='{$maximum_chars}' ";
        $extraclass .= " maxchars maxchars-" . $maximum_chars;
    } else {
        $maxlength = "";
    }
    if (trim($aQuestionAttributes['text_input_width']) != '') {
        $tiwidth = $aQuestionAttributes['text_input_width'];
        $extraclass .= " inputwidth-" . trim($aQuestionAttributes['text_input_width']);
    } else {
        $tiwidth = 50;
    }
    if (trim($aQuestionAttributes['prefix'][$_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang']]) != '') {
        $prefix = $aQuestionAttributes['prefix'][$_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang']];
        $extraclass .= " withprefix";
    } else {
        $prefix = '';
    }
    if (trim($aQuestionAttributes['suffix'][$_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang']]) != '') {
        $suffix = $aQuestionAttributes['suffix'][$_SESSION['survey_' . Yii::app()->getConfig('surveyID')]['s_lang']];
        $extraclass .= " withsuffix";
    } else {
        $suffix = '';
    }
    if ($thissurvey['nokeyboard'] == 'Y') {
        includeKeypad();
        $kpclass = "text-keypad";
        $extraclass .= " inputkeypad";
    } else {
        $kpclass = "";
    }
    if (trim($aQuestionAttributes['display_rows']) != '') {
        //question attribute "display_rows" is set -> we need a textarea to be able to show several rows
        $drows = $aQuestionAttributes['display_rows'];
        //if a textarea should be displayed we make it equal width to the long text question
        //this looks nicer and more continuous
        if ($tiwidth == 50) {
            $tiwidth = 40;
        }
        //NEW: textarea instead of input=text field
        // --> START NEW FEATURE - SAVE
        $answer = "<p class='question answer-item text-item {$extraclass}'><label for='answer{$ia[1]}' class='hide label'>{$clang->gT('Answer')}</label>" . '<textarea class="textarea ' . $kpclass . '" name="' . $ia[1] . '" id="answer' . $ia[1] . '" ' . 'rows="' . $drows . '" cols="' . $tiwidth . '" ' . $maxlength . ' onkeyup="' . $checkconditionFunction . '(this.value, this.name, this.type);">';
        // --> END NEW FEATURE - SAVE
        if ($_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$ia[1]]) {
            $dispVal = str_replace("\\", "", $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$ia[1]]);
            if ($aQuestionAttributes['numbers_only'] == 1) {
                $dispVal = str_replace('.', $sSeparator, $dispVal);
            }
            $answer .= $dispVal;
        }
        $answer .= "</textarea></p>\n";
    } elseif ((int) $aQuestionAttributes['location_mapservice'] != 0) {
        $mapservice = $aQuestionAttributes['location_mapservice'];
        $currentLocation = $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$ia[1]];
        $currentLatLong = null;
        $floatLat = 0;
        $floatLng = 0;
        // Get the latitude/longtitude for the point that needs to be displayed by default
        if (strlen($currentLocation) > 2) {
            $currentLatLong = explode(';', $currentLocation);
            $currentLatLong = array($currentLatLong[0], $currentLatLong[1]);
        } else {
            if ((int) $aQuestionAttributes['location_nodefaultfromip'] == 0) {
                $currentLatLong = getLatLongFromIp(getIPAddress());
            }
            if (!isset($currentLatLong) || $currentLatLong == false) {
                $floatLat = 0;
                $floatLng = 0;
                $LatLong = explode(" ", trim($aQuestionAttributes['location_defaultcoordinates']));
                if (isset($LatLong[0]) && isset($LatLong[1])) {
                    $floatLat = $LatLong[0];
                    $floatLng = $LatLong[1];
                }
                $currentLatLong = array($floatLat, $floatLng);
            }
        }
        // 2 - city; 3 - state; 4 - country; 5 - postal
        $strBuild = "";
        if ($aQuestionAttributes['location_city']) {
            $strBuild .= "2";
        }
        if ($aQuestionAttributes['location_state']) {
            $strBuild .= "3";
        }
        if ($aQuestionAttributes['location_country']) {
            $strBuild .= "4";
        }
        if ($aQuestionAttributes['location_postal']) {
            $strBuild .= "5";
        }
        $currentLocation = $currentLatLong[0] . " " . $currentLatLong[1];
        $answer = "\n        <script type=\"text/javascript\">\n        zoom['{$ia['1']}'] = {$aQuestionAttributes['location_mapzoom']};\n        </script>\n        <div class=\"question answer-item geoloc-item {$extraclass}\">\n        <input type=\"hidden\" name=\"{$ia['1']}\" id=\"answer{$ia['1']}\" value=\"{$_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$ia[1]]}\">\n\n        <input class=\"text location " . $kpclass . "\" type=\"text\" size=\"20\" name=\"{$ia['1']}_c\"\n        id=\"answer{$ia['1']}_c\" value=\"{$currentLocation}\"\n        onchange=\"{$checkconditionFunction}(this.value, this.name, this.type)\" />\n\n        <input type=\"hidden\" name=\"boycott_{$ia['1']}\" id=\"boycott_{$ia['1']}\"\n        value = \"{$strBuild}\" >\n        <input type=\"hidden\" name=\"mapservice_{$ia['1']}\" id=\"mapservice_{$ia['1']}\"\n        class=\"mapservice\" value = \"{$aQuestionAttributes['location_mapservice']}\" >\n        <div id=\"gmap_canvas_{$ia['1']}_c\" style=\"width: {$aQuestionAttributes['location_mapwidth']}px; height: {$aQuestionAttributes['location_mapheight']}px\"></div>\n        </div>";
        Yii::app()->getClientScript()->registerScriptFile(Yii::app()->getConfig('generalscripts') . "map.js");
        if ($aQuestionAttributes['location_mapservice'] == 1 && !empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != "off") {
            Yii::app()->getClientScript()->registerScriptFile("https://maps.googleapis.com/maps/api/js?sensor=false{$sGoogleMapsAPIKey}");
        } else {
            if ($aQuestionAttributes['location_mapservice'] == 1) {
                Yii::app()->getClientScript()->registerScriptFile("http://maps.googleapis.com/maps/api/js?sensor=false{$sGoogleMapsAPIKey}");
            } elseif ($aQuestionAttributes['location_mapservice'] == 2) {
                Yii::app()->getClientScript()->registerScriptFile("http://www.openlayers.org/api/OpenLayers.js");
            }
        }
        if (isset($aQuestionAttributes['hide_tip']) && $aQuestionAttributes['hide_tip'] == 0) {
            $answer .= "<div class=\"questionhelp\">" . $clang->gT('Drag and drop the pin to the desired location. You may also right click on the map to move the pin.') . '</div>';
            $question_text['help'] = $clang->gT('Drag and drop the pin to the desired location. You may also right click on the map to move the pin.');
        }
    } else {
        //no question attribute set, use common input text field
        $answer = "<p class=\"question answer-item text-item {$extraclass}\">\n" . "<label for='answer{$ia[1]}' class='hide label'>{$clang->gT('Answer')}</label>" . "{$prefix}\t<input class=\"text {$kpclass}\" type=\"text\" size=\"{$tiwidth}\" name=\"{$ia['1']}\" id=\"answer{$ia['1']}\"";
        $dispVal = $_SESSION['survey_' . Yii::app()->getConfig('surveyID')][$ia[1]];
        if ($aQuestionAttributes['numbers_only'] == 1) {
            $dispVal = str_replace('.', $sSeparator, $dispVal);
        }
        $dispVal = htmlspecialchars($dispVal, ENT_QUOTES, 'UTF-8');
        $answer .= " value=\"{$dispVal}\"";
        $answer .= " {$maxlength} onkeyup=\"{$checkconditionFunction}(this.value, this.name, this.type)\"/>\n\t{$suffix}\n</p>\n";
    }
    if (trim($aQuestionAttributes['time_limit']) != '') {
        $answer .= return_timer_script($aQuestionAttributes, $ia, "answer" . $ia[1]);
    }
    $inputnames[] = $ia[1];
    return array($answer, $inputnames);
}
Exemplo n.º 4
0
function do_shortfreetext($ia)
{
    global $clang, $js_header_includes, $thissurvey,$googleMapsAPIKey;

    if ($ia[8] == 'Y')
    {
        $checkconditionFunction = "checkconditions";
    }
    else
    {
        $checkconditionFunction = "noop_checkconditions";
    }

    $qidattributes=getQuestionAttributes($ia[0],$ia[4]);

    if ($qidattributes['numbers_only']==1)
    {
        $sSeperator = getRadixPointData($thissurvey['surveyls_numberformat']);
        $sSeperator = $sSeperator['seperator'];
        $numbersonly = 'onkeypress="return goodchars(event,\'0123456789'.$sSeperator.'\')"';
    }
    else
    {
        $numbersonly = '';
    }
    if (trim($qidattributes['maximum_chars'])!='')
    {
        $maxsize=$qidattributes['maximum_chars'];
    }
    else
    {
        $maxsize=255;
    }
    if (trim($qidattributes['text_input_width'])!='')
    {
        $tiwidth=$qidattributes['text_input_width'];
    }
    else
    {
        $tiwidth=50;
    }
    if (trim($qidattributes['prefix'])!='') {
        $prefix=$qidattributes['prefix'];
    }
    else
    {
        $prefix = '';
    }
    if (trim($qidattributes['suffix'])!='') {
        $suffix=$qidattributes['suffix'];
    }
    else
    {
        $suffix = '';
    }
    if ($thissurvey['nokeyboard']=='Y')
    {
        vIncludeKeypad();
        $kpclass = "text-keypad";
    }
    else
    {
        $kpclass = "";
    }
    if (trim($qidattributes['display_rows'])!='')
    {
        //question attribute "display_rows" is set -> we need a textarea to be able to show several rows
        $drows=$qidattributes['display_rows'];

        //extend maximum chars if this is set to short text default of 255
        if($maxsize == 255)
        {
            $maxsize=65525;
        }

        //if a textarea should be displayed we make it equal width to the long text question
        //this looks nicer and more continuous
        if($tiwidth == 50)
        {
            $tiwidth=40;
        }


        //some JS to check max possible input
        $answer = "<script type='text/javascript'>
               <!--
               function textLimit(field, maxlen) {
                if (document.getElementById(field).value.length > maxlen)
                document.getElementById(field).value = document.getElementById(field).value.substring(0, maxlen);
                }
               //-->
               </script>\n";

        //NEW: textarea instead of input=text field

        // --> START NEW FEATURE - SAVE
        $answer .= '<textarea class="textarea '.$kpclass.'" name="'.$ia[1].'" id="answer'.$ia[1].'" '
        .'rows="'.$drows.'" cols="'.$tiwidth.'" onkeyup="textLimit(\'answer'.$ia[1].'\', '.$maxsize.'); '.$checkconditionFunction.'(this.value, this.name, this.type);" '.$numbersonly.'>';
        // --> END NEW FEATURE - SAVE

        if ($_SESSION[$ia[1]]) {$answer .= str_replace("\\", "", $_SESSION[$ia[1]]);}

        $answer .= "</textarea>\n";
    }
    elseif((int)($qidattributes['location_mapservice'])!=0){

        $mapservice = $qidattributes['location_mapservice'];
        $currentLocation = $_SESSION[$ia[1]];
        $currentLatLong = null;

        $floatLat = 0;
        $floatLng = 0;

        // Get the latitude/longtitude for the point that needs to be displayed by default
        if (strlen($currentLocation) > 2){
            $currentLatLong = explode(';',$currentLocation);
            $currentLatLong = array($currentLatLong[0],$currentLatLong[1]);
        }
        else{
            if ((int)($qidattributes['location_nodefaultfromip'])==0)
                $currentLatLong = getLatLongFromIp($_SERVER['REMOTE_ADDR']);
            if (!isset($currentLatLong) || $currentLatLong==false){
                $floatLat = 0;
                $floatLng = 0;
                $LatLong = explode(" ",trim($qidattributes['location_defaultcoordinates']));

                if (isset($LatLong[0]) && isset($LatLong[1])){
                    $floatLat = $LatLong[0];
                    $floatLng = $LatLong[1];
                }

                $currentLatLong = array($floatLat,$floatLng);
            }
        }
        // 2 - city; 3 - state; 4 - country; 5 - postal
        $strBuild = "";
        if ($qidattributes['location_city'])
            $strBuild .= "2";
        if ($qidattributes['location_state'])
            $strBuild .= "3";
        if ($qidattributes['location_country'])
            $strBuild .= "4";
        if ($qidattributes['location_postal'])
            $strBuild .= "5";

        $currentLocation = $currentLatLong[0] . " " . $currentLatLong[1];
        $answer = "
        	<script type=\"text/javascript\">
        		zoom['$ia[1]'] = {$qidattributes['location_mapzoom']};
        	</script>
            <p class=\"question\">
            <input type=\"hidden\" name=\"$ia[1]\" id=\"answer$ia[1]\" value=\"{$_SESSION[$ia[1]]}\">

            <input class=\"text location\" type=\"text\" size=\"20\" name=\"$ia[1]_c\"
                id=\"answer$ia[1]_c\" value=\"$currentLocation\"
                onkeyup=\"$checkconditionFunction(this.value, this.name, this.type)\" />
            </p>

            <input type=\"hidden\" name=\"boycott_$ia[1]\" id=\"boycott_$ia[1]\"
                value = \"{$strBuild}\" >
            <input type=\"hidden\" name=\"mapservice_$ia[1]\" id=\"mapservice_$ia[1]\"
                class=\"mapservice\" value = \"{$qidattributes['location_mapservice']}\" >
            <div id=\"gmap_canvas_$ia[1]_c\" style=\"width: {$qidattributes['location_mapwidth']}px; height: {$qidattributes['location_mapheight']}px\"></div>";

        if ($qidattributes['location_mapservice']==1)
            $js_header_includes[] = "http://maps.google.com/maps?file=api&amp;v=2&amp;sensor=false&amp;key={$googleMapsAPIKey}";
        elseif ($qidattributes['location_mapservice']==2)
            $js_header_includes[] = "http://www.openlayers.org/api/OpenLayers.js";

	    if (isset($qidattributes['hide_tip']) && $qidattributes['hide_tip']==0)
            {
                $answer .= "<br />\n<span class=\"questionhelp\">"
                . $clang->gT('Drag and drop the pin to the desired location. You may also right click on the map to move the pin.').'</span>';
                $question_text['help'] = $clang->gT('Drag and drop the pin to the desired location. You may also right click on the map to move the pin.');
            }


    }
    else
    {
        //no question attribute set, use common input text field
        $answer = "<p class=\"question\">\n\t$prefix\n\t<input class=\"text $kpclass\" type=\"text\" size=\"$tiwidth\" name=\"$ia[1]\" id=\"answer$ia[1]\" value=\""
        .htmlspecialchars($_SESSION[$ia[1]],ENT_QUOTES,'UTF-8')
        ."\" maxlength=\"$maxsize\" onkeyup=\"$checkconditionFunction(this.value, this.name, this.type)\" $numbersonly />\n\t$suffix\n</p>\n";
    }


    if (trim($qidattributes['time_limit'])!='')
    {
		$js_header_includes[] = '/scripts/coookies.js';
        $answer .= return_timer_script($qidattributes, $ia, "answer".$ia[1]);
    }

    $inputnames[]=$ia[1];
    return array($answer, $inputnames);

}