<?php

/*******************************************************************************
 * Mo-i megyék kitöltése     
 ******************************************************************************/
if (!isset($config)) {
  require_once('config.php');
}

if (!isset($jmdb)) {
  $jmdb = ((isset($_GET['jmdb']) && in_array($_GET['jmdb'], array('jml', 'eng'))) ? $_GET['jmdb'] : 'jml');
}

$msh->query("SELECT * FROM cl_hlusers.users WHERE nCtrID=36 AND (nStateID IS NULL OR nStateID<=0);");
$res = $msh->fetchAssoc();

foreach ($res as $key => $row) {
  $msh->query("SELECT * FROM " . CRMADATBAZIS . ".u_cities WHERE strCity='" . trim($row['strCity']) . "' LIMIT 1;");
  $city = $msh->fetchAssoc();

  if (!empty($city)) {
    $city = $city[0];
    $msh->query("UPDATE " . CRMADATBAZIS . ".users SET nStateID=" . ((int)$city['nStateID'] > 0 ? (int)$city['nStateID'] : 0) . " WHERE nUserID=" . $row['nUserID'] . " LIMIT 1");
    //    print $row['nUserID']." ".$row['strName']." ".$row['strCity']." ".$city['nStateID']."<br />";
  }
}
