Location: PHPKode > projects > Blandware AtLeap Lite - CMS on PHP > atleaplite/include/ajax/livesearch.class.php
<?php
/*
 *  Copyright 2008 Blandware (http://www.blandware.com)
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

/**
 * Processes livesearch requests.
 *
 * @package     AtleapLite
 * @author      Roman Puchkovskiy
 * @license     http://www.apache.org/licenses/LICENSE-2.0  Apache License, Version 2.0
 */

/**
 */
require 'server_options.php';

/**
 * Including common entry file header
 */
require 'include/entry_common.php';


require_once 'include/common.php';

configurateDataObject($dsn);

/**
 * Searches attribute names.
 *
 * @param string $input prefix by which to search
 * @return array results
 */
function _do_search($input) {
    // need to convert because AJAX pages are in UTF8
    $input = mb_convert_encoding($input, HTTP_CHARSET, 'utf-8');
    $dao =& getDao('attribute');
    $titles = $dao->getAttributeTitlesByPrefix($input);
    $result = array();
    foreach ($titles as $title) {
        // now converting back
        $title = mb_convert_encoding($title, 'utf-8', HTTP_CHARSET);
        $result[$title] = $title;
    }
    return $result;
}

// dynamically construct a required number of methods... rather ugly

$code = <<<EOS

class livesearch {

EOS;

for ($i = 0; $i < $maxAttributes; $i++) {
    $funcCode = <<<EOS
    function search$i(\$input) {
        return _do_search(\$input);
    }
EOS;
    $code .= $funcCode;
}


$code .= '}';

eval($code);

?>
Return current item: Blandware AtLeap Lite - CMS on PHP