26if (!defined(
'NOTOKENRENEWAL')) {
 
   27  define(
'NOTOKENRENEWAL', 1); 
 
   29if (!defined(
'NOREQUIREMENU')) {
 
   30  define(
'NOREQUIREMENU', 
'1');
 
   32if (!defined(
'NOREQUIREHTML')) {
 
   33  define(
'NOREQUIREHTML', 
'1');
 
   35if (!defined(
'NOREQUIREAJAX')) {
 
   36  define(
'NOREQUIREAJAX', 
'1');
 
   38if (!defined(
'NOREQUIRESOC')) {
 
   39  define(
'NOREQUIRESOC', 
'1');
 
   43require 
'../../main.inc.php';
 
   44require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formcompany.class.php';
 
   49  $result = 
restrictedArea($user, 
'societe', 0, 
'&societe', 
'', 
'fk_soc', 
'rowid', 0);
 
   65  $return_arr = array();
 
   73    $sql = 
"SELECT z.rowid, z.zip, z.town, z.fk_county as state_id, z.fk_pays as country_id";
 
   74    $sql .= 
", c.code as country_code, c.label as country_label";
 
   75    $sql .= 
", d.code_departement as state_code, d.nom as state_label";
 
   76    $sql .= 
" FROM ".MAIN_DB_PREFIX.
"c_ziptown as z";
 
   77    $sql .= 
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_departements as d ON z.fk_county = d.rowid";
 
   78    $sql .= 
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_regions as r ON d.fk_region = r.code_region,";
 
   79    $sql .= 
" ".MAIN_DB_PREFIX.
"c_country as c";
 
   80    $sql .= 
" WHERE z.fk_pays = c.rowid";
 
   81    $sql .= 
" AND z.active = 1 AND c.active = 1";
 
   83      $sql .= 
" AND z.zip LIKE '".$db->escape($db->escapeforlike($zipcode)).
"%'";
 
   86      $sql .= 
" AND z.town LIKE '%".$db->escape($db->escapeforlike($town)).
"%'";
 
   88    $sql .= 
" ORDER BY z.zip, z.town";
 
   89    $sql .= $db->plimit(100); 
 
   91    $sql = 
"SELECT DISTINCT s.zip, s.town, s.fk_departement as state_id, s.fk_pays as country_id";
 
   92    $sql .= 
", c.code as country_code, c.label as country_label";
 
   93    $sql .= 
", d.code_departement as state_code, d.nom as state_label";
 
   94    $sql .= 
" FROM ".MAIN_DB_PREFIX.
'societe as s';
 
   95    $sql .= 
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_departements as d ON s.fk_departement = d.rowid";
 
   96    $sql .= 
" LEFT JOIN ".MAIN_DB_PREFIX.
'c_country as c ON s.fk_pays = c.rowid';
 
   99      $sql .= 
" s.zip LIKE '".$db->escape($db->escapeforlike($zipcode)).
"%'";
 
  102      $sql .= 
" s.town LIKE '%".$db->escape($db->escapeforlike($town)).
"%'";
 
  104    $sql .= 
" ORDER BY s.fk_pays, s.zip, s.town";
 
  105    $sql .= $db->plimit(100); 
 
  109  $resql = $db->query($sql);
 
  112    while ($row = $db->fetch_array($resql)) {
 
  114      $country = $row[
'country_id'] ? ($langs->transnoentitiesnoconv(
'Country'.$row[
'country_code']) != 
'Country'.$row[
'country_code'] ? $langs->transnoentitiesnoconv(
'Country'.$row[
'country_code']) : $row[
'country_label']) : 
'';
 
  115      $county = $row[
'state_id'] ? ($langs->transnoentitiesnoconv($row[
'state_code']) != $row[
'state_code'] ? $langs->transnoentitiesnoconv($row[
'state_code']) : ($row[
'state_label'] != 
'-' ? $row[
'state_label'] : 
'')) : 
'';
 
  117      $row_array[
'label'] = $row[
'zip'].
' '.$row[
'town'];
 
  118      $row_array[
'label'] .= ($county || $country) ? 
' (' : 
'';
 
  119      $row_array[
'label'] .= $county;
 
  120      $row_array[
'label'] .= ($county && $country ? 
' - ' : 
'');
 
  121      $row_array[
'label'] .= $country;
 
  122      $row_array[
'label'] .= ($county || $country) ? 
')' : 
'';
 
  124        $row_array[
'value'] = $row[
'zip'];
 
  125        $row_array[
'town'] = $row[
'town'];
 
  128        $row_array[
'value'] = $row[
'town'];
 
  129        $row_array[
'zipcode'] = $row[
'zip'];
 
  131      $row_array[
'selectcountry_id'] = $row[
'country_id'];
 
  132      $row_array[
'state_id'] = $row[
'state_id'];
 
  135      $row_array[
'states'] = $formcompany->select_state(
'', $row[
'country_id'], 
'');
 
  137      array_push($return_arr, $row_array);
 
  141  echo json_encode($return_arr);
 
  142} elseif (GETPOSTISSET(
'country_codeid')) {
 
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
 
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
 
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
 
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
 
if(!defined( 'NOREQUIREMENU')) if(!empty(GETPOST('seteventmessages', 'alpha'))) if(!function_exists("llxHeader")) top_httphead($contenttype='text/html', $forcenocache=0)
Show HTTP header.
 
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.