Ejemplo n.º 1
0
 /**
  * Returns an XML document
  * @param    int        $quid: question UID
  * @return    string    xml-document
  */
 function getAjaxDetails($quid)
 {
     $quid = intval($quid);
     $nr = 0;
     $sOut = '';
     //$template = str_replace('\"', '', $template);
     $template = $this->cObj->getSubpart($this->templateCode, "###TEMPLATE_DETAILS_ITEM###");
     //$template_item = preg_replace('/\r?\n/', " ", $template_item);
     //$template_item = str_replace("'", '"', $template_item);
     $template = str_replace('###PREFIX###', $this->prefixId, $template);
     $result = $GLOBALS['TYPO3_DB']->exec_SELECTquery('COUNT(*) anzahl', 'tx_myquizpoll_relation', 'LENGTH(textinput)>0 AND question_id=' . $quid, '', '', '');
     $rowA = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result);
     $gesamt = $rowA['anzahl'];
     $GLOBALS['TYPO3_DB']->sql_free_result($result);
     if ($gesamt > 0) {
         $result = $GLOBALS['TYPO3_DB']->exec_SELECTquery('DISTINCT textinput texte, COUNT( textinput ) anzahl', 'tx_myquizpoll_relation', 'LENGTH(textinput)>0 AND question_id=' . $quid, 'textinput', '', '');
         $rows = $GLOBALS['TYPO3_DB']->sql_num_rows($result);
         if ($rows > 0) {
             while ($rowA = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($result)) {
                 if ($nr % 2 == 0) {
                     $even_odd = 'even';
                 } else {
                     $even_odd = 'odd';
                 }
                 $prozent = number_format(100 * $rowA['anzahl'] / $gesamt, 2, ',', ' ');
                 //$texte = preg_replace("/(\r\n)+|(\n|\r)+/", "<br />", $rowA['texte']);    // nl2br funktioniert auch nicht
                 $texte = str_replace('\\r\\n', '<br />', htmlspecialchars($rowA['texte']));
                 $temp = str_replace('###ITEM_EVEN_ODD###', $even_odd, $template);
                 $temp = str_replace('###ITEM_ANSWER###', $texte, $temp);
                 $temp = str_replace('###ITEM_PERCENT###', $prozent, $temp);
                 $temp = str_replace('###ITEM_COUNTS###', $rowA['anzahl'], $temp);
                 $sOut .= $temp;
                 $nr++;
             }
         }
     }
     /* instantiate the xajaxResponse object */
     $objResponse = new tx_xajax_response();
     $objResponse->addScript("document.getElementById('details_hidden-{$quid}').style.display='block'; document.getElementById('show_details-{$quid}').style.display='none';");
     /* We alter the contents of the HTML element. The property 'innerHTML' is the html code inside this element. We replace it with the result in our $sOut variable */
     $objResponse->addAssign("details-{$quid}", "innerHTML", $sOut);
     /* With the getXML() method on the xajaxResponse objectwe send everything back to the client */
     return $objResponse->getXML();
 }
    /**
     * Function for the ajax search
     *
     * @param	string		$searchFields: The search fiels (search word & search on map only)
     * @return	Records found with search value
     */
    function search($searchForm)
    {
        $template['list'] = $this->cObj->getSubpart($this->templateCode, '###TEMPLATE_SEARCH_RESULTS###');
        $template["item"] = $this->cObj->getSubpart($template["list"], "###SINGLE###");
        $objResponse = new tx_xajax_response($GLOBALS['TSFE']->metaCharset);
        $test = "";
        // minimum characters needed, default = 3
        if (strlen($searchForm['rggmsearchValue']) >= $this->conf['search.']['minChars'] || $searchForm['rggmActivateRadius'] == "on" && $searchForm['rggmRadius'] > 0) {
            $res = array();
            // search for a text
            // escaping the search-value
            $delete = array("'", "\"", "\\", "/", "");
            $searchExpression = $searchForm['rggmsearchValue'];
            $searchExpression = str_replace($delete, "", $searchExpression);
            $tablelist = explode(',', $this->config['tables']);
            foreach ($tablelist as $key => $table) {
                $where = 'deleted = 0 AND pid IN (' . $this->config['pid_list'] . ')  ';
                if ($this->conf['search.'][$table]) {
                    $select = '*';
                    $searchField = explode(',', $this->conf['search.'][$table]);
                    $where2 = '';
                    foreach ($searchField as $key => $value) {
                        $where2 .= " {$value} LIKE '%{$searchExpression}%' OR";
                    }
                    $where .= ' AND ( ' . substr($where2, 0, -3) . ' ) ';
                    // search only within the map area
                    if ($searchForm['rggmOnMap'] == 'on') {
                        $areaArr = preg_split('/%2C%20/', $searchForm['rggmBound']);
                        $where .= 'AND lng between ' . $areaArr[1] . ' AND ' . $areaArr[3] . '
                          AND	lat between ' . $areaArr[0] . ' AND ' . $areaArr[2];
                    }
                    // radius search (umkreissuche)
                    if ($searchForm['rggmActivateRadius'] == "on") {
                        $coordinates = $this->geoCodeAddress("", $searchForm['rggmZip']);
                        if ($coordinates != "") {
                            $coordinates = explode(',', $coordinates);
                            $select = '*,SQRT(POW(' . $coordinates[1] . '-lng,2)*6400 + POW(' . $coordinates[0] . '-lat,2)*12100) AS distance';
                            $where .= ' AND SQRT(POW(' . $coordinates[1] . '-lng,2)*6400 + POW(' . $coordinates[0] . '-lat,2)*12100) <' . intval($searchForm['rggmRadius']);
                            $orderBy = 'distance';
                            $offset = '0,' . $this->conf['recordsPerPage'];
                            $offset = '0,10';
                            $test = "\n                marker = createMarker(new GLatLng({$coordinates['0']},{$coordinates['1']}), 99999, 'dot.png', 'Standort (" . $searchForm['rggmZip'] . ")', 'fe_users'); map.addOverlay( marker );\n                bounds.extend(new GLatLng({$coordinates['0']},{$coordinates['1']}));\n                 ";
                        }
                    }
                    $res = $this->generic->exec_SELECTquery($select, $table, $where, $groupBy, $orderBy, '0,' . $this->conf['recordsPerPage']);
                    #$content.=t3lib_div::view_array($res);
                }
            }
            #$res = $this->generic->exec_SELECTquery('*',$table,$where,$groupBy,$orderBy,'0,'.$this->conf['recordsPerPage'],1);
            $i = 0;
            $jsResultDelete = 'deleteSearchResult();';
            $jsResultUpdate = 'var bounds = new GLatLngBounds();';
            while ($row = array_shift($res)) {
                $tmp = $this->getMarker($row, 'search.');
                $markerArray = $tmp['markerArray'];
                $wrappedSubpartArray = $tmp['wrappedSubpartArray'];
                $i++;
                $markerArray['###SEARCHID###'] = $i;
                $title = '"marker' . $i . '.png"';
                $jsResultUpdate .= "\n          marker = createMarker(new GLatLng({$row['lat']},{$row['lng']}), {$row['uid']}, {$title}, '{$row['name']}', '{$row['table']}');\n          map.addOverlay( marker );\n          tempmarkers[{$row['uid']}] = marker;\n          bounds.extend(new GLatLng({$row['lat']},{$row['lng']}));\n        ";
                $content_item .= $this->cObj->substituteMarkerArrayCached($template["item"], $markerArray, array(), $wrappedSubpartArray);
            }
            $jsResultUpdate .= $test;
            $markerArray['###SEARCHEXPRESSION###'] = $searchForm['rggmsearchValue'];
            $markerArray['###SEARCHCOUNT###'] = $i;
            $subpartArray["###CONTENT###"] = $content_item;
            $jsResultUpdate .= '
        var zoom=map.getBoundsZoomLevel(bounds);

        var centerLat = (bounds.getNorthEast().lat() + bounds.getSouthWest().lat()) /2;
        var centerLng = (bounds.getNorthEast().lng() + bounds.getSouthWest().lng()) /2;
        map.setCenter(new GLatLng(centerLat,centerLng),zoom);
      ';
            // Nothing found
            if ($i == 0) {
                $subpartArray["###CONTENT###"] = $this->pi_getLL('searchNoResult');
                $jsResultUpdate = '';
            }
            $content .= $this->cObj->substituteMarkerArrayCached($template['list'], $markerArray, $subpartArray, $wrappedSubpartArray);
            $objResponse->addScript($jsResultDelete);
            $objResponse->addAssign('searchFormResult', 'innerHTML', $content);
            $objResponse->addScript($jsResultUpdate);
            $objResponse->addAssign('searchFormError', 'innerHTML', '');
            // minimum character length not reached
        } else {
            $content .= sprintf($this->pi_getLL('searchMinChars'), $this->conf['search.']['minChars']);
            $objResponse->addAssign('searchFormError', 'innerHTML', $content);
        }
        //	$objResponse->addScript('fdTableSort.init()');
        return $objResponse->getXML();
    }