function smarty_function_artist_altnames_list($params, &$smarty)
{
    if (empty($params['var'])) {
        $smarty->trigger_error("assign: missing 'var' parameter");
        return;
    }
    if (empty($params['query'])) {
        $smarty->trigger_error("assign: missing 'var' parameter");
        return;
    } else {
        $query = $params['query'];
    }
    $searchterm = $query['artist'];
    $searchtype = 'parentid';
    global $db, $db_prefix;
    $thesaurus = new thesaurusDB($db, $db_prefix);
    $rs = $thesaurus->query('names', $searchterm, $searchtype);
    $sql = "queried through thesaurusDB::query('names', '{$searchterm}', '{$searchtype}');";
    if (count($rs)) {
        foreach ($rs as $row) {
            array_walk($row, '__stripslashes');
            $result[$row['id']] = $row;
        }
    } else {
        $result = false;
    }
    $smarty->assign($params['var'], $result);
    if (!empty($params['sql'])) {
        $smarty->assign($params['sql'], $sql);
    }
}
function smarty_function_artist_list($params, &$smarty)
{
    if (empty($params['var'])) {
        $smarty->trigger_error("assign: missing 'var' parameter");
        return;
    }
    if (empty($params['query'])) {
        $smarty->trigger_error("assign: missing 'var' parameter");
        return;
    } else {
        $query = $params['query'];
    }
    //debug($query);
    global $db, $db_prefix;
    $thesaurus = new thesaurusDB($db, $db_prefix);
    // $frommeta indicates whether or not the data is coming from the _existing_ metadata
    $frommeta = false;
    // search for artists by the artistsearch field if given or by the meta-id otherwise
    if (empty($query['searchartist'])) {
        if (empty($query['id'])) {
            $searchtype = false;
        } else {
            extractID($query['id'], $collectionid, $imageid);
            $searchterm = "{$collectionid}:{$imageid}";
            $searchtype = 'metaid';
            $frommeta = true;
        }
    } else {
        $searchterm = $query['searchartist'];
        $searchtype = 'name';
    }
    $result = array();
    if ($searchtype != false) {
        $rs = $thesaurus->query('names', $searchterm, $searchtype);
        $sql = "queried through thesaurusDB::query('names', '{$searchterm}', '{$searchtype}');";
        /*if ($frommeta) {
              $params['query']['name1id'] = $rs[0]['id'];
              $params['query']['name1text'] = $rs[0]['name'];
              $params['query']['name1id'] = $rs[0]['id'];
              $params['query']['name1text'] = $rs[0]['name'];
              $smarty->assign('query', $params['query']);
          }*/
        //make the ids be keys, and strip slashes out
        foreach ($rs as $row) {
            array_walk($row, '__stripslashes');
            $result[$row['id']] = $row;
        }
    } else {
        $sql = 'no query';
    }
    //debug($result);
    $smarty->assign($params['var'], $result);
    if (!empty($params['sql'])) {
        $smarty->assign($params['sql'], $sql);
    }
}
Ejemplo n.º 3
0
function smarty_function_city_list($params, &$smarty)
{
    if (empty($params['var'])) {
        $smarty->trigger_error("assign: missing 'var' parameter");
        return;
    }
    if (empty($params['query'])) {
        $smarty->trigger_error("assign: missing 'query' parameter");
        return;
    }
    global $db, $db_prefix;
    // query the existing locations
    /*$sql = "SELECT DISTINCT city FROM {$db_prefix}meta ORDER BY city ASC";
    	$rs = $db->GetArray( $sql );*/
    //debug($_REQUEST, false);
    //debug($params['query']);
    $thesaurus = new thesaurusDB($db, $db_prefix);
    // $frommeta indicates whether or not the data is coming from the _existing_ metadata
    $frommeta = false;
    // search by the citysearch field if given, by the meta-id otherwise
    if (empty($params['query']['citysearch'])) {
        if (empty($params['query']['id'])) {
            $searchtype = false;
        } else {
            $searchterm = $params['query']['id'];
            $searchtype = 'metaid';
            $frommeta = true;
        }
    } else {
        $searchterm = $params['query']['citysearch'];
        $searchtype = 'location';
    }
    $result = array();
    if ($searchtype != false) {
        $rs = $thesaurus->query('locations', $searchterm, $searchtype);
        $sql = "queried through thesaurusDB::query('locations', '{$searchterm}', '{$searchtype}');";
        if ($frommeta) {
            $params['query']['city'] = $rs[0]['id'];
            $params['query']['cityname'] = $rs[0]['location'];
            $smarty->assign('query', $params['query']);
        }
        //make the ids be keys
        $result = array();
        foreach ($rs as $row) {
            $result[$row['id']] = $row;
        }
    } else {
        $sql = 'no query';
    }
    $smarty->assign($params['var'], $result);
    $smarty->assign($params['frommeta'], $frommeta);
    if (!empty($params['sql'])) {
        $smarty->assign($params['sql'], $sql);
    }
}
function get_or_set_values($db, $db_prefix, $dilpsid, $field, $fieldtext, $recordid)
{
    //    $name1 = get_or_set_values($db, $db_prefix, $edit['id'], 'name', $edit['name1text'], $edit['name1id']);
    global $config;
    include_once $config['includepath'] . 'thesauri/soundex_fr.php';
    // $db->debug = true;
    switch ($field) {
        case 'location':
            $table = 'location';
            break;
        case 'name':
            $table = 'artist';
            break;
        default:
            $id['is_error'] = true;
            $id['error_msg'] = "\n" . __FILE__ . "::" . __LINE__ . ": Unrecognized field parameter: {$field}\n";
            return $id;
    }
    $table = $db_prefix . $table;
    $text = trim($fieldtext);
    if ($text == '') {
        $result['id'] = 0;
        $result[$field] = $text;
        $result['sounds'] = '';
    } else {
        if ($recordid == 'new') {
            $sql = "select id,  {$field}, sounds from {$table} where lower('{$text}') = trim(lower({$field}))";
        } else {
            $sql = "select id,  {$field}, sounds from {$table} where id = '{$recordid}'";
        }
        //bk: here, may need to handle multiple results - user should be able to pick from available locations
        //    or specify a new hierarchy for the given location
        // for now, just take the first result
        // hopefully, the thesaurus will be comprehensive enough, so that this won't be a problem
        $rs = $db->GetRow($sql);
        if ($rs === false) {
            $result['is_error'] = true;
            $result['error_msg'] = "\n" . $db->ErrorMsg() . "[{$sql}]";
        } else {
            if (empty($rs)) {
                if ($recordid != 'new') {
                    $result['is_error'] = true;
                    $result['error_msg'] = "\nNo record found, when id should exist [{$sql}]";
                } else {
                    $result = false;
                }
            } else {
                $result = $rs;
            }
        }
    }
    // if no matching record was found, insert a new one and get it's id
    if ($result === false) {
        $tdb = new thesaurusDB($db, $db_prefix);
        $sounds = $tdb->get_sounds_string($text);
        if ($field == 'location') {
            $sql = "insert into {$table} (src, source_id, location, loc_type, sounds) " . "values ('dilps'," . $db->qstr($dilpsid) . "," . $db->qstr($text) . ", '83002/inhabited place'," . $db->qstr($sounds) . ")";
        } else {
            if ($field == 'name') {
                $sql = "insert into {$table} (src, name, sounds) " . "values ('dilps'," . $db->qstr($text) . "," . $db->qstr($sounds) . ")";
            } else {
                $sql = "error";
            }
        }
        //die("about to insert: $sql");
        if (!$db->Execute($sql)) {
            $result['is_error'] = true;
            $result['error_msg'] = "\n" . $db->ErrorMsg() . "[{$sql}]";
        } else {
            $result['id'] = $db->Insert_ID();
            $result[$field] = $text;
            $result['sounds'] = $sounds;
        }
    }
    return $result;
}
<?php

// to load names into db from thesaurus file:
require_once '../../globals.inc.php';
include_once $config['includepath'] . 'adodb/adodb.inc.php';
$db = NewADOConnection("mysql");
$res = $db->PConnect($db_host, $db_user, $db_pwd, $db_db);
$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
if (!$res) {
    die('no connection');
}
$thesaurus = new thesaurusDB($db, $db_prefix);
$thesaurus->loadDB_names('/home/brian/projects/dilps/test/pknd_0.1.xml');
<?php

/*  to load locations into db from thesaurus file.
 * NOTE: backup and truncate the location table before running this script
 * NOTE: after running this script, run update_meta_table_after_location_reload.php
*/
//$load_sourcedir is defined in thesauri_load_config.inc.php
require_once '../../globals.inc.php';
include_once $config['includepath'] . 'adodb/adodb.inc.php';
include_once $config['includepath'] . 'thesauri/thesauri_load_config.inc.php';
$db = NewADOConnection("mysql");
$res = $db->PConnect($db_host, $db_user, $db_pwd, $db_db);
$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
if (!$res) {
    echo 'no connection';
    exit(1);
}
if (isset($argv[1])) {
    $load_sourcefile = $argv[1];
    if (!is_readable($load_sourcefile)) {
        echo "file '{$load_sourcefile}' does not exist or could not be read";
        exit(1);
    }
} else {
    echo 'must specify a source file';
    exit(1);
}
$thesaurus = new thesaurusDB($db, $db_prefix);
//$thesaurus->loadDB_locations($load_sourcedir);
$result = $thesaurus->loadDB_locations($load_sourcefile);
exit($result);
<?php

/*  to update meta table after running reload_location_thesaurus.php
 * NOTE: backup the meta table before running this script
*/
require_once $config['includepath'] . 'globals.inc.php';
include_once $config['includepath'] . 'adodb/adodb.inc.php';
$db = NewADOConnection("mysql");
$res = $db->PConnect($db_host, $db_user, $db_pwd, $db_db);
$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
if (!$res) {
    die('no connection');
}
$thesaurus = new thesaurusDB($db, $db_prefix);
$thesaurus->_update_records_from_location_thesaurus();
echo "Finished!\n";