Add: dbut ajout autocompletion ajax sur la liste des socits
This commit is contained in:
parent
0ee5e91095
commit
10af1d81fa
@ -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 '<table class="border" width="100%">';
|
||||
|
||||
print '<input type="hidden" name="socid" value='.$_GET["socid"].'>';
|
||||
print "<tr><td>".$langs->trans("Company")."</td><td>".$societe->getNomUrl(1)."</td></tr>";
|
||||
if ($_GET["socid"])
|
||||
{
|
||||
print '<input type="hidden" name="socid" value='.$_GET["socid"].'>';
|
||||
print "<tr><td>".$langs->trans("Company")."</td><td>".$societe->getNomUrl(1)."</td></tr>";
|
||||
}
|
||||
else
|
||||
{
|
||||
print "<tr><td>".$langs->trans("Company")."</td><td>";
|
||||
$html->select_societes('','socid','');
|
||||
print "</td></tr>";
|
||||
}
|
||||
|
||||
print "<tr><td>".$langs->trans("Date")."</td><td>";
|
||||
$html->select_date(time(),"p",'','','','fichinter');
|
||||
@ -187,7 +202,7 @@ if ($_GET["action"] == 'create')
|
||||
|
||||
print '<tr><td valign="top">'.$langs->trans("Project").'</td><td>';
|
||||
|
||||
$numprojet = $societe->has_projects();
|
||||
if ($_GET["socid"]) $numprojet = $societe->has_projects();
|
||||
|
||||
if (!$numprojet)
|
||||
{
|
||||
|
||||
@ -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 '<table class="nobordernopadding"><tr class="nocellnopadd">';
|
||||
print '<td class="nobordernopadding">';
|
||||
print '<div>';
|
||||
if ($obj->rowid == 0)
|
||||
{
|
||||
print '<input type="text" size="30" id="'.$htmlname.'" name="'.$htmlname.'" value=""/>';
|
||||
}
|
||||
else
|
||||
{
|
||||
print '<input type="text" size="30" id="'.$htmlname.'" name="'.$htmlname.'" value="'.$obj->nom.'"/>';
|
||||
}
|
||||
print ajax_autocompleter($socid,$htmlname,'/societe/ajaxcompanies.php','');
|
||||
print '</td>';
|
||||
print '<td class="nobordernopadding" align="left" width="16">';
|
||||
print ajax_indicator($htmlname,'working');
|
||||
print '</td></tr>';
|
||||
print '</table>';
|
||||
}
|
||||
else
|
||||
{
|
||||
print '<select class="flat" name="'.$htmlname.'">';
|
||||
if ($showempty) print '<option value="-1"> </option>';
|
||||
$num = $this->db->num_rows($resql);
|
||||
@ -664,8 +702,10 @@ class Form
|
||||
}
|
||||
}
|
||||
print '</select>';
|
||||
}
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
dolibarr_print_error($this->db);
|
||||
}
|
||||
}
|
||||
|
||||
@ -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
|
||||
*/
|
||||
|
||||
@ -33,16 +33,19 @@ top_htmlhead("", "", 1, 1);
|
||||
print '<body id="mainbody">';
|
||||
|
||||
// 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 '<li>';
|
||||
print $company->nom;
|
||||
print '<span id="socid" class="informal" style="display:none">'.$company->rowid.'-idcache</span>';
|
||||
print '<span id="object" class="informal" style="display:none">'.$company->rowid.'-idcache</span>';
|
||||
print '</li>';
|
||||
}
|
||||
print '</ul>';
|
||||
|
||||
Loading…
Reference in New Issue
Block a user