diff --git a/htdocs/fichinter/fiche.php b/htdocs/fichinter/fiche.php index 04356954127..4668447b9dc 100644 --- a/htdocs/fichinter/fiche.php +++ b/htdocs/fichinter/fiche.php @@ -46,6 +46,12 @@ $fichinterid = isset($_GET["id"])?$_GET["id"]:''; // Sécurité d'accès client et commerciaux $socid = restrictedArea($user, 'ficheinter', $fichinterid, 'fichinter'); +//Récupère le résultat de la recherche Ajax +//Todo: voir pour le supprimer par la suite +if ($conf->use_ajax && $conf->global->COMPANY_USE_SEARCH_TO_SELECT && $_POST['socid_id']) +{ + $_POST['socid'] = $_POST['socid_id']; +} /* * Traitements des actions @@ -166,8 +172,17 @@ if ($_GET["action"] == 'create') $syear = date("Y", time()); print ''; - print ''; - print ""; + if ($_GET["socid"]) + { + print ''; + print ""; + } + else + { + print ""; + } print "
".$langs->trans("Company")."".$societe->getNomUrl(1)."
".$langs->trans("Company")."".$societe->getNomUrl(1)."
".$langs->trans("Company").""; + $html->select_societes('','socid',''); + print "
".$langs->trans("Date").""; $html->select_date(time(),"p",'','','','fichinter'); @@ -187,7 +202,7 @@ if ($_GET["action"] == 'create') print '
'.$langs->trans("Project").''; - $numprojet = $societe->has_projects(); + if ($_GET["socid"]) $numprojet = $societe->has_projects(); if (!$numprojet) { diff --git a/htdocs/html.form.class.php b/htdocs/html.form.class.php index 74c9c66553f..09c5c16b8e8 100644 --- a/htdocs/html.form.class.php +++ b/htdocs/html.form.class.php @@ -633,16 +633,54 @@ class Form * \param filter Criteres optionnels de filtre */ function select_societes($selected='',$htmlname='socid',$filter='',$showempty=0) - { + { + global $conf; // On recherche les societes $sql = "SELECT s.rowid, s.nom FROM"; $sql.= " ".MAIN_DB_PREFIX ."societe as s"; - if ($filter) $sql.= " WHERE $filter"; + if ($filter) $sql.= " WHERE ".$filter; + if ($selected && $conf->use_ajax && $conf->global->COMPANY_USE_SEARCH_TO_SELECT) + { + if ($filter) + { + $sql.= " AND"; + } + else + { + $sql.= " WHERE"; + } + $sql.= " rowid = ".$selected; + } $sql.= " ORDER BY nom ASC"; $resql=$this->db->query($sql); if ($resql) { + if ($conf->use_ajax && $conf->global->COMPANY_USE_SEARCH_TO_SELECT) + { + if ($selected) $obj = $this->db->fetch_object($resql); + $socid = $obj->rowid?$obj->rowid:''; + + print ''; + print ''; + print ''; + print '
'; + print '
'; + if ($obj->rowid == 0) + { + print ''; + } + else + { + print ''; + } + print ajax_autocompleter($socid,$htmlname,'/societe/ajaxcompanies.php',''); + print '
'; + print ajax_indicator($htmlname,'working'); + print '
'; + } + else + { print ''; + } } - else { + else + { dolibarr_print_error($this->db); } } diff --git a/htdocs/product/fournisseurs.php b/htdocs/product/fournisseurs.php index 7abbf0c5071..2456293eb65 100644 --- a/htdocs/product/fournisseurs.php +++ b/htdocs/product/fournisseurs.php @@ -46,6 +46,13 @@ $mesg = ''; if (! $user->rights->produit->lire) accessforbidden(); +//Récupère le résultat de la recherche Ajax +//Todo: voir pour le supprimer par la suite +if ($conf->use_ajax && $conf->global->COMPANY_USE_SEARCH_TO_SELECT && $_POST['id_fourn_id']) +{ + $_POST['id_fourn'] = $_POST['id_fourn_id']; +} + /* * Actions */ diff --git a/htdocs/societe/ajaxcompanies.php b/htdocs/societe/ajaxcompanies.php index a0a2ec58ba3..2f248760c04 100644 --- a/htdocs/societe/ajaxcompanies.php +++ b/htdocs/societe/ajaxcompanies.php @@ -33,16 +33,19 @@ top_htmlhead("", "", 1, 1); print ''; // Generation liste des sociétés -if(isset($_POST['newcompany']) && !empty($_POST['newcompany'])) +if(isset($_POST['newcompany']) && !empty($_POST['newcompany']) || isset($_POST['socid']) && !empty($_POST['socid']) + || isset($_POST['id_fourn']) && !empty($_POST['id_fourn'])) { - global $langs; - $langs->load("dict"); + $socid = $_POST['newcompany']?$_POST['newcompany']:''; + $socid = $_POST['socid']?$_POST['socid']:''; + $socid = $_POST['id_fourn']?$_POST['id_fourn']:''; + $sql = "SELECT rowid, nom"; $sql.= " FROM ".MAIN_DB_PREFIX."societe"; - $sql.= " WHERE nom LIKE '%" . utf8_decode($_POST['newcompany']) . "%'"; + $sql.= " WHERE nom LIKE '%" . utf8_decode($socid) . "%'"; $sql.= " ORDER BY nom ASC;"; - + $resql=$db->query($sql); if ($resql) @@ -52,7 +55,7 @@ if(isset($_POST['newcompany']) && !empty($_POST['newcompany'])) { print '
  • '; print $company->nom; - print ''; + print ''; print '
  • '; } print '';