From 5f173e01eef89bba223d6ffcaeb7ab7656bbdd7f Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 28 Aug 2009 01:14:35 +0000 Subject: [PATCH] Qual: Ajax code is simpler and now works with IE6 --- htdocs/adherents/fiche.php | 8 ++++++++ htdocs/admin/cashdesk.php | 13 +++++++++++-- htdocs/categories/edit.php | 25 +++++++++++++++---------- htdocs/categories/fiche.php | 18 ++++++++++++++---- htdocs/comm/action/fiche.php | 16 ++++++++++++++++ htdocs/compta/deplacement/fiche.php | 12 ++++++++++++ htdocs/contact/fiche.php | 10 +++++++++- htdocs/fichinter/fiche.php | 8 +++++--- htdocs/fourn/facture/fiche.php | 8 +++++++- htdocs/html.form.class.php | 4 ++-- htdocs/html.formcompany.class.php | 7 ++++--- htdocs/lib/ajax.lib.php | 1 + htdocs/lib/lib_head.js | 22 +++++++++++++++------- htdocs/product/fournisseurs.php | 16 ++++++++-------- htdocs/projet/fiche.php | 6 +++++- htdocs/societe/ajaxcompanies.php | 5 +++-- 16 files changed, 135 insertions(+), 44 deletions(-) diff --git a/htdocs/adherents/fiche.php b/htdocs/adherents/fiche.php index 2c0b3c206ec..6eb64f1eae1 100644 --- a/htdocs/adherents/fiche.php +++ b/htdocs/adherents/fiche.php @@ -40,6 +40,14 @@ $langs->load("bills"); $langs->load("members"); $langs->load("users"); +// If socid provided by ajax company selector +if (! empty($_REQUEST['socid_id'])) +{ + $_GET['socid'] = $_GET['socid_id']; + $_POST['socid'] = $_POST['socid_id']; + $_REQUEST['socid'] = $_REQUEST['socid_id']; +} + // Security check if (! $user->rights->adherent->lire) { diff --git a/htdocs/admin/cashdesk.php b/htdocs/admin/cashdesk.php index 40021595071..b1ecb317d07 100644 --- a/htdocs/admin/cashdesk.php +++ b/htdocs/admin/cashdesk.php @@ -27,6 +27,15 @@ require("./pre.inc.php"); require_once(DOL_DOCUMENT_ROOT."/lib/admin.lib.php"); require_once(DOL_DOCUMENT_ROOT."/html.formproduct.class.php"); +// If socid provided by ajax company selector +if (! empty($_REQUEST['socid_id'])) +{ + $_GET['socid'] = $_GET['socid_id']; + $_POST['socid'] = $_POST['socid_id']; + $_REQUEST['socid'] = $_REQUEST['socid_id']; +} + +// Security check if (!$user->admin) accessforbidden(); @@ -42,11 +51,11 @@ if ($_POST["action"] == 'set') if ($_POST["CASHDESK_ID_THIRDPARTY"] < 0) $_POST["CASHDESK_ID_THIRDPARTY"]=''; if ($_POST["CASHDESK_ID_WAREHOUSE"] < 0) $_POST["CASHDESK_ID_WAREHOUSE"]=''; if ($_POST["CASHDESK_ID_BANKACCOUNT"] < 0) $_POST["CASHDESK_ID_BANKACCOUNT"]=''; - + dolibarr_set_const($db,"CASHDESK_ID_THIRDPARTY",$_POST["CASHDESK_ID_THIRDPARTY"],'chaine',0,'',$conf->entity); dolibarr_set_const($db,"CASHDESK_ID_BANKACCOUNT",$_POST["CASHDESK_ID_BANKACCOUNT"],'chaine',0,'',$conf->entity); dolibarr_set_const($db,"CASHDESK_ID_WAREHOUSE",$_POST["CASHDESK_ID_WAREHOUSE"],'chaine',0,'',$conf->entity); - + dol_syslog("admin/cashdesk: level ".$_POST["level"]); } diff --git a/htdocs/categories/edit.php b/htdocs/categories/edit.php index 42a5aace8f9..0fbd9b93112 100644 --- a/htdocs/categories/edit.php +++ b/htdocs/categories/edit.php @@ -17,32 +17,37 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * $Id$ */ /** \file htdocs/categories/edit.php \ingroup category \brief Page d'edition de categorie produit - \version $Revision$ + \version $Id$ */ require "./pre.inc.php"; +// If socid provided by ajax company selector +if (! empty($_REQUEST['socid_id'])) +{ + $_GET['socid'] = $_GET['socid_id']; + $_POST['socid'] = $_POST['socid_id']; + $_REQUEST['socid'] = $_REQUEST['socid_id']; +} + +// Security check if (!$user->rights->categorie->lire) accessforbidden(); $type=$_REQUEST['type']; -// If socid provided by ajax company selector -if (! empty($_POST['socid_id'])) -{ - $_POST['socid'] = $_POST['socid_id']; - $_REQUEST['socid'] = $_REQUEST['socid_id']; -} -// Action mise à jour d'une catégorie +/* + * Actions + */ + +// Action mise a jour d'une categorie if ($_POST["action"] == 'update' && $user->rights->categorie->creer) { $categorie = new Categorie ($db); diff --git a/htdocs/categories/fiche.php b/htdocs/categories/fiche.php index 6ef76012192..7b5ee2df81b 100644 --- a/htdocs/categories/fiche.php +++ b/htdocs/categories/fiche.php @@ -29,6 +29,15 @@ require "./pre.inc.php"; require_once(DOL_DOCUMENT_ROOT."/categories/categorie.class.php"); +// If socid provided by ajax company selector +if (! empty($_REQUEST['socid_id'])) +{ + $_GET['socid'] = $_GET['socid_id']; + $_POST['socid'] = $_POST['socid_id']; + $_REQUEST['socid'] = $_REQUEST['socid_id']; +} + +// Security check if (!$user->rights->categorie->lire) accessforbidden(); if (isset ($_REQUEST['choix'])) @@ -53,8 +62,9 @@ if ($_REQUEST['catorigin']) } // If socid provided by ajax company selector -if (! empty($_POST['socid_id'])) +if (! empty($_REQUEST['socid_id'])) { + $_GET['socid'] = $_GET['socid_id']; $_POST['socid'] = $_POST['socid_id']; $_REQUEST['socid'] = $_REQUEST['socid_id']; } @@ -117,7 +127,7 @@ if ($_POST["action"] == 'add' && $user->rights->categorie->creer) $categorie->error = $langs->trans("ErrorFieldRequired",$langs->transnoentities("Description")); $_GET["action"] = 'create'; } - + if ($categorie->error =="") { $result = $categorie->create(); @@ -202,7 +212,7 @@ if ($user->rights->categorie->creer) print ''.$langs->trans("Ref").''; print''; print ''.$langs->trans("Description").''; - + if ($conf->fckeditor->enabled && $conf->global->FCKEDITOR_ENABLE_PRODUCTDESC) { require_once(DOL_DOCUMENT_ROOT."/lib/doleditor.class.php"); @@ -215,7 +225,7 @@ if ($user->rights->categorie->creer) print dol_htmlentitiesbr_decode($categorie->description); print ''; } - + print ''; if ($_GET['type'] == 0 && $conf->global->CATEGORY_ASSIGNED_TO_A_CUSTOMER) { diff --git a/htdocs/comm/action/fiche.php b/htdocs/comm/action/fiche.php index 1a16ad113fd..24de94121ca 100644 --- a/htdocs/comm/action/fiche.php +++ b/htdocs/comm/action/fiche.php @@ -40,6 +40,14 @@ $langs->load("bills"); $langs->load("orders"); $langs->load("agenda"); +// If socid provided by ajax company selector +if (! empty($_REQUEST['socid_id'])) +{ + $_GET['socid'] = $_GET['socid_id']; + $_POST['socid'] = $_POST['socid_id']; + $_REQUEST['socid'] = $_REQUEST['socid_id']; +} + // Security check $socid=isset($_GET['socid'])?$_GET['socid']:$_POST['socid']; $id = isset($_GET["id"])?$_GET["id"]:''; @@ -53,6 +61,14 @@ $cactioncomm = new CActionComm($db); $actioncomm = new ActionComm($db); $contact = new Contact($db); +// If socid provided by ajax company selector +if (! empty($_REQUEST['socid_id'])) +{ + $_GET['socid'] = $_GET['socid_id']; + $_POST['socid'] = $_POST['socid_id']; + $_REQUEST['socid'] = $_REQUEST['socid_id']; +} + /* * Action creation de l'action diff --git a/htdocs/compta/deplacement/fiche.php b/htdocs/compta/deplacement/fiche.php index 83e6dbb32da..14439e428eb 100644 --- a/htdocs/compta/deplacement/fiche.php +++ b/htdocs/compta/deplacement/fiche.php @@ -27,6 +27,14 @@ require("./pre.inc.php"); $langs->load("trips"); +// If socid provided by ajax company selector +if (! empty($_REQUEST['socid_id'])) +{ + $_GET['socid'] = $_GET['socid_id']; + $_POST['socid'] = $_POST['socid_id']; + $_REQUEST['socid'] = $_REQUEST['socid_id']; +} + // Security check $id=isset($_GET["id"])?$_GET["id"]:$_POST["id"]; if ($user->societe_id) $socid=$user->societe_id; @@ -35,6 +43,7 @@ $result = restrictedArea($user, 'deplacement', $id,''); $mesg = ''; + /* * Actions */ @@ -117,6 +126,9 @@ if ($_POST["action"] == 'update' && $user->rights->deplacement->creer) } +/* + * View + */ llxHeader(); diff --git a/htdocs/contact/fiche.php b/htdocs/contact/fiche.php index f4730dab63d..3d5e6f6f55c 100644 --- a/htdocs/contact/fiche.php +++ b/htdocs/contact/fiche.php @@ -40,6 +40,14 @@ $langs->load("users"); $error = array(); $socid=$_GET["socid"]?$_GET["socid"]:$_POST["socid"]; +// If socid provided by ajax company selector +if (! empty($_REQUEST['socid_id'])) +{ + $_GET['socid'] = $_GET['socid_id']; + $_POST['socid'] = $_POST['socid_id']; + $_REQUEST['socid'] = $_REQUEST['socid_id']; +} + // Security check $contactid = isset($_GET["id"])?$_GET["id"]:''; if ($user->societe_id) $socid=$user->societe_id; @@ -256,7 +264,7 @@ if ($user->rights->societe->contact->creer) } print '
'; - print '
'; + print ''; print ''; print ''; print ''; diff --git a/htdocs/fichinter/fiche.php b/htdocs/fichinter/fiche.php index 9bb99f69cb7..c20628333bb 100644 --- a/htdocs/fichinter/fiche.php +++ b/htdocs/fichinter/fiche.php @@ -59,8 +59,9 @@ if ($_GET["id"] > 0 || ! empty($_GET["ref"])) } // If socid provided by ajax company selector -if (! empty($_POST['socid_id'])) +if (! empty($_REQUEST['socid_id'])) { + $_GET['socid'] = $_GET['socid_id']; $_POST['socid'] = $_POST['socid_id']; $_REQUEST['socid'] = $_REQUEST['socid_id']; } @@ -72,9 +73,10 @@ $result = restrictedArea($user, 'ficheinter', $fichinterid, 'fichinter'); /* - * Traitements des actions + * Actions */ -if ($_REQUEST["action"] != 'create' && $_REQUEST["action"] != 'add' && ! $_REQUEST["id"] > 0 && empty($_REQUEST["ref"])) + +if ($_REQUEST["action"] != 'create' && $_REQUEST["action"] != 'add' && ! ($_REQUEST["id"] > 0) && empty($_REQUEST["ref"])) { Header("Location: index.php"); return; diff --git a/htdocs/fourn/facture/fiche.php b/htdocs/fourn/facture/fiche.php index 78669ebb96b..dbc3e2379e8 100644 --- a/htdocs/fourn/facture/fiche.php +++ b/htdocs/fourn/facture/fiche.php @@ -33,7 +33,13 @@ require_once(DOL_DOCUMENT_ROOT.'/lib/fourn.lib.php'); require_once(DOL_DOCUMENT_ROOT.'/product.class.php'); if ($conf->projet->enabled) require_once(DOL_DOCUMENT_ROOT.'/project.class.php'); -if (!$user->rights->fournisseur->facture->lire) accessforbidden(); +// If socid provided by ajax company selector +if (! empty($_REQUEST['socid_id'])) +{ + $_GET['socid'] = $_GET['socid_id']; + $_POST['socid'] = $_POST['socid_id']; + $_REQUEST['socid'] = $_REQUEST['socid_id']; +} $langs->load('bills'); $langs->load('suppliers'); diff --git a/htdocs/html.form.class.php b/htdocs/html.form.class.php index 5ef158d875a..7f82e341512 100644 --- a/htdocs/html.form.class.php +++ b/htdocs/html.form.class.php @@ -500,8 +500,8 @@ class Form print '
'; if ($socid == 0) { - $langs->load("companies"); - print ''; + //$langs->load("companies"); + print ''; } else { diff --git a/htdocs/html.formcompany.class.php b/htdocs/html.formcompany.class.php index 097d2d64c98..9a61fe8ac37 100644 --- a/htdocs/html.formcompany.class.php +++ b/htdocs/html.formcompany.class.php @@ -471,7 +471,7 @@ class FormCompany } // We call a page after a small delay when a new input has been selected - $javaScript = "window.location=\'./contact.php?".$var_id."=".$object->id."&".$htmlname."=\' + document.getElementById(\'newcompany_id\').value;"; + $javaScript = "window.location=\'./contact.php?".$var_id."=".$object->id."&".$htmlname."=\' + document.getElementById(\'".$htmlname."_id\').value;"; $htmloption = 'onChange="ac_delay(\''.$javaScript.'\',\'500\')"'; print "\n".''."\n"; @@ -479,8 +479,9 @@ class FormCompany print ''; if ($obj->rowid == 0) { - $langs->load("companies"); - print ''; + //$langs->load("companies"); + //print ''; + print ''; } else { diff --git a/htdocs/lib/ajax.lib.php b/htdocs/lib/ajax.lib.php index 4281e8d630c..772ad3a742b 100644 --- a/htdocs/lib/ajax.lib.php +++ b/htdocs/lib/ajax.lib.php @@ -134,6 +134,7 @@ function ajax_autocompleter($selected='',$htmlname,$url,$indicator='working') $script.= 'new Ajax.Autocompleter(\''.$htmlname.'\',\'result'.$htmlname.'\',\''.DOL_URL_ROOT.$url.'\',{ method: \'post\', paramName: \''.$htmlname.'\', + minChars: \'1\', indicator: \'indicator'.$htmlname.'\', afterUpdateElement: ac_return });'; // Note: The ac_return will fill value inside the field htmlname (param of Autocompleter constructor) and htmlname_id (function ac_return) diff --git a/htdocs/lib/lib_head.js b/htdocs/lib/lib_head.js index 6fac4b050fa..3f542634fdb 100644 --- a/htdocs/lib/lib_head.js +++ b/htdocs/lib/lib_head.js @@ -579,25 +579,33 @@ function newpopup(url,title) { /*================================================================= - Purpose: Récupère l'id d'une autcompletion Ajax + Purpose: Recupere id d'une autcompletion Ajax Input: field,item Author: Regis Houssin Licence: GPL ==================================================================*/ function ac_return(field, item){ - /*alert('id='+field.name+'-'+item.id);*/ - $(field.name+'_id').value = item.id; - /*alert('after='+$(field.name+'_id').value);*/ +/* alert('field.name='+field.name+'-'+item.innerHTML); */ + /* on met en place l'expression reguliere */ + var regex = new RegExp('[0123456789]*-idcache', 'i'); + /* on l'applique au contenu */ + var idCache = regex.exec(item.innerHTML); + /* on recupere id */ + id = idCache[0].replace('-idcache', ''); +/* alert('field.name='+field.name+'-'+idCache[0]+'-'+id); */ + /* et on l'affecte au champ cache */ +/* alert('field.name='+field.name+'-'+item.innerHTML+'-id='+id); */ + $(field.name+'_id').value = id; } /*================================================================= - Purpose: Applique un délai avant execution + Purpose: Applique un delai avant execution Input: funct, delay Author: Regis Houssin Licence: GPL ==================================================================*/ -function ac_delay(funct,delay) { - /* delay before action start */ + function ac_delay(funct,delay) { + // delay before start of action setTimeout(funct,delay); } diff --git a/htdocs/product/fournisseurs.php b/htdocs/product/fournisseurs.php index 426f2c5bce4..eaea6d1cd07 100644 --- a/htdocs/product/fournisseurs.php +++ b/htdocs/product/fournisseurs.php @@ -35,6 +35,14 @@ $langs->load("products"); $langs->load("suppliers"); $langs->load("bills"); +// If socid provided by ajax company selector +if (! empty($_REQUEST['id_fourn_id'])) +{ + $_GET['id_fourn'] = $_GET['id_fourn_id']; + $_POST['id_fourn'] = $_POST['id_fourn_id']; + $_REQUEST['id_fourn'] = $_REQUEST['id_fourn_id']; +} + // Security check if (isset($_GET["id"]) || isset($_GET["ref"])) { @@ -47,14 +55,6 @@ $result=restrictedArea($user,'produit|service',$id,'product','','',$fieldid); $mesg = ''; -//R�cup�re le r�sultat de la recherche Ajax -//Todo: voir pour le supprimer par la suite -if ($conf->use_javascript_ajax && $conf->global->COMPANY_USE_SEARCH_TO_SELECT && $_POST['id_fourn_id']) -{ - $_POST['id_fourn'] = $_POST['id_fourn_id']; -} - - /* * Actions */ diff --git a/htdocs/projet/fiche.php b/htdocs/projet/fiche.php index deb25bcaf17..e6b303e7e4d 100644 --- a/htdocs/projet/fiche.php +++ b/htdocs/projet/fiche.php @@ -36,13 +36,17 @@ $ref=''; if (isset($_GET["id"])) { $projetid=$_GET["id"]; } if (isset($_GET["ref"])) { $ref=$_GET["ref"]; } +//var_dump($_REQUEST);exit; + // If socid provided by ajax company selector -if (! empty($_POST['socid_id'])) +if (! empty($_REQUEST['socid_id'])) { + $_GET['socid'] = $_GET['socid_id']; $_POST['socid'] = $_POST['socid_id']; $_REQUEST['socid'] = $_REQUEST['socid_id']; } + if ($projetid == '' && $ref == '' && ($_GET['action'] != "create" && $_POST['action'] != "add" && $_POST["action"] != "update" && !$_POST["cancel"])) accessforbidden(); // Security check diff --git a/htdocs/societe/ajaxcompanies.php b/htdocs/societe/ajaxcompanies.php index 36a8d6e602a..6f190e0c7a5 100644 --- a/htdocs/societe/ajaxcompanies.php +++ b/htdocs/societe/ajaxcompanies.php @@ -56,9 +56,10 @@ if (! empty($_POST['newcompany']) || ! empty($_POST['socid']) || ! empty($_POST[ print '
    '; while ($company = $db->fetch_object($resql)) { - print '
  • '; + print '
  • '; print $company->nom; - //print ''; + // To output content that will not be inserted into selected field, we use span. + print ''; print '
  • '; } print '
';