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.
'/societe/class/societe.class.php';
 
   54if ($user->socid > 0) {
 
   55  $socid = $user->socid;
 
   56  if ($object->socid && $socid != $object->socid) {
 
   57    accessforbidden(
'Not allowed to access thirdparty id '.$id.
' with an external user on id '.$socid);
 
   78  $socid = 
GETPOST(
'socid', 
'int');
 
   81  $socid = 
GETPOST(
'id_fourn', 
'int');
 
   86  echo json_encode(array(
'nom'=>
'ErrorBadParameter', 
'label'=>
'ErrorBadParameter', 
'key'=>
'ErrorBadParameter', 
'value'=>
'ErrorBadParameter'));
 
   90$sql = 
"SELECT s.rowid, s.nom, s.name_alias, s.code_client, s.code_fournisseur, s.address, s.zip, s.town, s.email, s.siren, s.siret, s.ape, s.idprof4, s.idprof5, s.idprof6, s.client, s.fournisseur, s.datec, s.logo";
 
   92  $sql .= 
", dictp.code as country_code";
 
   94$sql .= 
" FROM ".MAIN_DB_PREFIX.
"societe as s";
 
   96  $sql .= 
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_country as dictp ON dictp.rowid = s.fk_pays";
 
   98$sql .= 
" WHERE s.entity IN (".getEntity(
'societe').
")";
 
  103    $sql .= 
"s.nom LIKE '".$db->escape($db->escapeforlike($socid)).
"%'";
 
  104    $sql .= 
" OR s.name_alias LIKE '".$db->escape($db->escapeforlike($socid)).
"%'";
 
  105    $sql .= 
" OR s.code_client LIKE '".$db->escape($db->escapeforlike($socid)).
"%'";
 
  106    $sql .= 
" OR s.code_fournisseur LIKE '".$db->escape($db->escapeforlike($socid)).
"%'";
 
  108    $sql .= 
"s.nom LIKE '%".$db->escape($db->escapeforlike($socid)).
"%'";
 
  109    $sql .= 
" OR s.name_alias LIKE '%".$db->escape($db->escapeforlike($socid)).
"%'";
 
  110    $sql .= 
" OR s.code_client LIKE '%".$db->escape($db->escapeforlike($socid)).
"%'";
 
  111    $sql .= 
" OR s.code_fournisseur LIKE '%".$db->escape($db->escapeforlike($socid)).
"%'";
 
  114    $sql .= 
" OR s.rowid = ".((int) $socid);
 
  119if ($user->socid > 0) {
 
  120  $sql .= 
" AND s.rowid = ".((int) $user->socid);
 
  123$sql .= 
" ORDER BY s.nom ASC";
 
  126$resql = $db->query($sql);
 
  128  while ($row = $db->fetch_array($resql)) {
 
  131      if (($row[
'client']) && (!empty($row[
'code_client']))) {
 
  132        $label = $row[
'code_client'].
' - ';
 
  134      if (($row[
'fournisseur']) && (!empty($row[
'code_fournisseur']))) {
 
  135        $label .= $row[
'code_fournisseur'].
' - ';
 
  139    $label .= $row[
'nom'];
 
  142      $label .= ($row[
'address'] ? 
' - '.$row[
'address'] : 
'').($row[
'zip'] ? 
' - '.$row[
'zip'] : 
'').($row[
'town'] ? 
' '.$row[
'town'] : 
'');
 
  143      if (!empty($row[
'country_code'])) {
 
  144        $label .= 
', '.$langs->trans(
'Country'.$row[
'country_code']);
 
  148      $label = preg_replace(
'/('.preg_quote($socid, 
'/').
')/i', 
'<strong>$1</strong>', $label, 1);
 
  150    $row_array[
'label'] = $label;
 
  152    $row_array[
'value'] = $row[
'nom'];
 
  153    $row_array[
'key'] = $row[
'rowid'];
 
  155    $row_array[
'name_alias'] = $row[
'name_alias'];
 
  156    $row_array[
'client'] = $row[
'client'];
 
  157    $row_array[
'fournisseur'] = $row[
'fournisseur'];
 
  158    $row_array[
'code_client'] = $row[
'code_client'];
 
  159    $row_array[
'code_fournisseur'] = $row[
'code_fournisseur'];
 
  160    $row_array[
'address'] = $row[
'address'];
 
  161    $row_array[
'zip'] = $row[
'zip'];
 
  162    $row_array[
'town'] = $row[
'town'];
 
  163    $row_array[
'email'] = $row[
'email'];
 
  164    $row_array[
'siren'] = $row[
'siren'];
 
  165    $row_array[
'siret'] = $row[
'siret'];
 
  166    $row_array[
'ape'] = $row[
'ape'];
 
  167    $row_array[
'idprof4'] = $row[
'idprof4'];
 
  168    $row_array[
'idprof5'] = $row[
'idprof5'];
 
  169    $row_array[
'idprof6'] = $row[
'idprof6'];
 
  170    $row_array[
'datec'] = $row[
'datec'];
 
  171    $row_array[
'logo'] = $row[
'logo'];
 
  173    array_push($return_arr, $row_array);
 
  176  echo json_encode($return_arr);
 
  178  echo json_encode(array(
'nom'=>
'Error', 
'label'=>
'Error', 
'key'=>
'Error', 
'value'=>
'Error'));
 
Class to manage third parties objects (customers, suppliers, prospects...)
 
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.
 
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.
 
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.