Qual: Ajax code is simpler and now works with IE6

This commit is contained in:
Laurent Destailleur 2009-08-28 01:14:35 +00:00
parent 756ca4499a
commit 5f173e01ee
16 changed files with 135 additions and 44 deletions

View File

@ -40,6 +40,14 @@ $langs->load("bills");
$langs->load("members"); $langs->load("members");
$langs->load("users"); $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 // Security check
if (! $user->rights->adherent->lire) if (! $user->rights->adherent->lire)
{ {

View File

@ -27,6 +27,15 @@ require("./pre.inc.php");
require_once(DOL_DOCUMENT_ROOT."/lib/admin.lib.php"); require_once(DOL_DOCUMENT_ROOT."/lib/admin.lib.php");
require_once(DOL_DOCUMENT_ROOT."/html.formproduct.class.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) if (!$user->admin)
accessforbidden(); accessforbidden();
@ -42,11 +51,11 @@ if ($_POST["action"] == 'set')
if ($_POST["CASHDESK_ID_THIRDPARTY"] < 0) $_POST["CASHDESK_ID_THIRDPARTY"]=''; if ($_POST["CASHDESK_ID_THIRDPARTY"] < 0) $_POST["CASHDESK_ID_THIRDPARTY"]='';
if ($_POST["CASHDESK_ID_WAREHOUSE"] < 0) $_POST["CASHDESK_ID_WAREHOUSE"]=''; if ($_POST["CASHDESK_ID_WAREHOUSE"] < 0) $_POST["CASHDESK_ID_WAREHOUSE"]='';
if ($_POST["CASHDESK_ID_BANKACCOUNT"] < 0) $_POST["CASHDESK_ID_BANKACCOUNT"]=''; 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_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_BANKACCOUNT",$_POST["CASHDESK_ID_BANKACCOUNT"],'chaine',0,'',$conf->entity);
dolibarr_set_const($db,"CASHDESK_ID_WAREHOUSE",$_POST["CASHDESK_ID_WAREHOUSE"],'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"]); dol_syslog("admin/cashdesk: level ".$_POST["level"]);
} }

View File

@ -17,32 +17,37 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Id$
*/ */
/** /**
\file htdocs/categories/edit.php \file htdocs/categories/edit.php
\ingroup category \ingroup category
\brief Page d'edition de categorie produit \brief Page d'edition de categorie produit
\version $Revision$ \version $Id$
*/ */
require "./pre.inc.php"; 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) if (!$user->rights->categorie->lire)
accessforbidden(); accessforbidden();
$type=$_REQUEST['type']; $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) if ($_POST["action"] == 'update' && $user->rights->categorie->creer)
{ {
$categorie = new Categorie ($db); $categorie = new Categorie ($db);

View File

@ -29,6 +29,15 @@
require "./pre.inc.php"; require "./pre.inc.php";
require_once(DOL_DOCUMENT_ROOT."/categories/categorie.class.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 (!$user->rights->categorie->lire) accessforbidden();
if (isset ($_REQUEST['choix'])) if (isset ($_REQUEST['choix']))
@ -53,8 +62,9 @@ if ($_REQUEST['catorigin'])
} }
// If socid provided by ajax company selector // 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']; $_POST['socid'] = $_POST['socid_id'];
$_REQUEST['socid'] = $_REQUEST['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")); $categorie->error = $langs->trans("ErrorFieldRequired",$langs->transnoentities("Description"));
$_GET["action"] = 'create'; $_GET["action"] = 'create';
} }
if ($categorie->error =="") if ($categorie->error =="")
{ {
$result = $categorie->create(); $result = $categorie->create();
@ -202,7 +212,7 @@ if ($user->rights->categorie->creer)
print '<td width="25%">'.$langs->trans("Ref").'</td><td><input name="nom" size="25" value="'.$categorie->label.'">'; print '<td width="25%">'.$langs->trans("Ref").'</td><td><input name="nom" size="25" value="'.$categorie->label.'">';
print'</td></tr>'; print'</td></tr>';
print '<tr><td valign="top">'.$langs->trans("Description").'</td><td>'; print '<tr><td valign="top">'.$langs->trans("Description").'</td><td>';
if ($conf->fckeditor->enabled && $conf->global->FCKEDITOR_ENABLE_PRODUCTDESC) if ($conf->fckeditor->enabled && $conf->global->FCKEDITOR_ENABLE_PRODUCTDESC)
{ {
require_once(DOL_DOCUMENT_ROOT."/lib/doleditor.class.php"); 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 dol_htmlentitiesbr_decode($categorie->description);
print '</textarea>'; print '</textarea>';
} }
print '</td></tr>'; print '</td></tr>';
if ($_GET['type'] == 0 && $conf->global->CATEGORY_ASSIGNED_TO_A_CUSTOMER) if ($_GET['type'] == 0 && $conf->global->CATEGORY_ASSIGNED_TO_A_CUSTOMER)
{ {

View File

@ -40,6 +40,14 @@ $langs->load("bills");
$langs->load("orders"); $langs->load("orders");
$langs->load("agenda"); $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 // Security check
$socid=isset($_GET['socid'])?$_GET['socid']:$_POST['socid']; $socid=isset($_GET['socid'])?$_GET['socid']:$_POST['socid'];
$id = isset($_GET["id"])?$_GET["id"]:''; $id = isset($_GET["id"])?$_GET["id"]:'';
@ -53,6 +61,14 @@ $cactioncomm = new CActionComm($db);
$actioncomm = new ActionComm($db); $actioncomm = new ActionComm($db);
$contact = new Contact($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 * Action creation de l'action

View File

@ -27,6 +27,14 @@ require("./pre.inc.php");
$langs->load("trips"); $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 // Security check
$id=isset($_GET["id"])?$_GET["id"]:$_POST["id"]; $id=isset($_GET["id"])?$_GET["id"]:$_POST["id"];
if ($user->societe_id) $socid=$user->societe_id; if ($user->societe_id) $socid=$user->societe_id;
@ -35,6 +43,7 @@ $result = restrictedArea($user, 'deplacement', $id,'');
$mesg = ''; $mesg = '';
/* /*
* Actions * Actions
*/ */
@ -117,6 +126,9 @@ if ($_POST["action"] == 'update' && $user->rights->deplacement->creer)
} }
/*
* View
*/
llxHeader(); llxHeader();

View File

@ -40,6 +40,14 @@ $langs->load("users");
$error = array(); $error = array();
$socid=$_GET["socid"]?$_GET["socid"]:$_POST["socid"]; $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 // Security check
$contactid = isset($_GET["id"])?$_GET["id"]:''; $contactid = isset($_GET["id"])?$_GET["id"]:'';
if ($user->societe_id) $socid=$user->societe_id; if ($user->societe_id) $socid=$user->societe_id;
@ -256,7 +264,7 @@ if ($user->rights->societe->contact->creer)
} }
print '<br>'; print '<br>';
print '<form method="post" action="fiche.php">'; print '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="add">'; print '<input type="hidden" name="action" value="add">';
print '<table class="border" width="100%">'; print '<table class="border" width="100%">';

View File

@ -59,8 +59,9 @@ if ($_GET["id"] > 0 || ! empty($_GET["ref"]))
} }
// If socid provided by ajax company selector // 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']; $_POST['socid'] = $_POST['socid_id'];
$_REQUEST['socid'] = $_REQUEST['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"); Header("Location: index.php");
return; return;

View File

@ -33,7 +33,13 @@ require_once(DOL_DOCUMENT_ROOT.'/lib/fourn.lib.php');
require_once(DOL_DOCUMENT_ROOT.'/product.class.php'); require_once(DOL_DOCUMENT_ROOT.'/product.class.php');
if ($conf->projet->enabled) require_once(DOL_DOCUMENT_ROOT.'/project.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('bills');
$langs->load('suppliers'); $langs->load('suppliers');

View File

@ -500,8 +500,8 @@ class Form
print '<td class="nobordernopadding">'; print '<td class="nobordernopadding">';
if ($socid == 0) if ($socid == 0)
{ {
$langs->load("companies"); //$langs->load("companies");
print '<input type="text" size="30" id="'.$htmlname.'" name="'.$htmlname.'" value="'.$langs->trans("SelectCompany").'" '.$htmloption.' />'; print '<input type="text" size="30" id="'.$htmlname.'" name="'.$htmlname.'" value="" '.$htmloption.' />';
} }
else else
{ {

View File

@ -471,7 +471,7 @@ class FormCompany
} }
// We call a page after a small delay when a new input has been selected // We call a page after a small delay when a new input has been selected
$javaScript = "window.location=\'./contact.php?".$var_id."=".$object->id."&amp;".$htmlname."=\' + document.getElementById(\'newcompany_id\').value;"; $javaScript = "window.location=\'./contact.php?".$var_id."=".$object->id."&amp;".$htmlname."=\' + document.getElementById(\'".$htmlname."_id\').value;";
$htmloption = 'onChange="ac_delay(\''.$javaScript.'\',\'500\')"'; $htmloption = 'onChange="ac_delay(\''.$javaScript.'\',\'500\')"';
print "\n".'<!-- Input text for third party with Ajax.Autocompleter (selectCompaniesForNewContact) -->'."\n"; print "\n".'<!-- Input text for third party with Ajax.Autocompleter (selectCompaniesForNewContact) -->'."\n";
@ -479,8 +479,9 @@ class FormCompany
print '<td class="nobordernopadding">'; print '<td class="nobordernopadding">';
if ($obj->rowid == 0) if ($obj->rowid == 0)
{ {
$langs->load("companies"); //$langs->load("companies");
print '<input type="text" size="30" id="'.$htmlname.'" name="'.$htmlname.'" value="'.$langs->trans("SelectCompany").'" '.$htmloption.' />'; //print '<input type="text" size="30" id="'.$htmlname.'_label" name="'.$htmlname.'" value="'.$langs->trans("SelectCompany").'" '.$htmloption.' />';
print '<input type="text" size="30" id="'.$htmlname.'" name="'.$htmlname.'" value="" '.$htmloption.' />';
} }
else else
{ {

View File

@ -134,6 +134,7 @@ function ajax_autocompleter($selected='',$htmlname,$url,$indicator='working')
$script.= 'new Ajax.Autocompleter(\''.$htmlname.'\',\'result'.$htmlname.'\',\''.DOL_URL_ROOT.$url.'\',{ $script.= 'new Ajax.Autocompleter(\''.$htmlname.'\',\'result'.$htmlname.'\',\''.DOL_URL_ROOT.$url.'\',{
method: \'post\', method: \'post\',
paramName: \''.$htmlname.'\', paramName: \''.$htmlname.'\',
minChars: \'1\',
indicator: \'indicator'.$htmlname.'\', indicator: \'indicator'.$htmlname.'\',
afterUpdateElement: ac_return afterUpdateElement: ac_return
});'; // Note: The ac_return will fill value inside the field htmlname (param of Autocompleter constructor) and htmlname_id (function ac_return) });'; // Note: The ac_return will fill value inside the field htmlname (param of Autocompleter constructor) and htmlname_id (function ac_return)

View File

@ -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 Input: field,item
Author: Regis Houssin Author: Regis Houssin
Licence: GPL Licence: GPL
==================================================================*/ ==================================================================*/
function ac_return(field, item){ function ac_return(field, item){
/*alert('id='+field.name+'-'+item.id);*/ /* alert('field.name='+field.name+'-'+item.innerHTML); */
$(field.name+'_id').value = item.id; /* on met en place l'expression reguliere */
/*alert('after='+$(field.name+'_id').value);*/ 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 Input: funct, delay
Author: Regis Houssin Author: Regis Houssin
Licence: GPL Licence: GPL
==================================================================*/ ==================================================================*/
function ac_delay(funct,delay) { function ac_delay(funct,delay) {
/* delay before action start */ // delay before start of action
setTimeout(funct,delay); setTimeout(funct,delay);
} }

View File

@ -35,6 +35,14 @@ $langs->load("products");
$langs->load("suppliers"); $langs->load("suppliers");
$langs->load("bills"); $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 // Security check
if (isset($_GET["id"]) || isset($_GET["ref"])) if (isset($_GET["id"]) || isset($_GET["ref"]))
{ {
@ -47,14 +55,6 @@ $result=restrictedArea($user,'produit|service',$id,'product','','',$fieldid);
$mesg = ''; $mesg = '';
//R<>cup<75>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 * Actions
*/ */

View File

@ -36,13 +36,17 @@ $ref='';
if (isset($_GET["id"])) { $projetid=$_GET["id"]; } if (isset($_GET["id"])) { $projetid=$_GET["id"]; }
if (isset($_GET["ref"])) { $ref=$_GET["ref"]; } if (isset($_GET["ref"])) { $ref=$_GET["ref"]; }
//var_dump($_REQUEST);exit;
// If socid provided by ajax company selector // 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']; $_POST['socid'] = $_POST['socid_id'];
$_REQUEST['socid'] = $_REQUEST['socid_id']; $_REQUEST['socid'] = $_REQUEST['socid_id'];
} }
if ($projetid == '' && $ref == '' && ($_GET['action'] != "create" && $_POST['action'] != "add" && $_POST["action"] != "update" && !$_POST["cancel"])) accessforbidden(); if ($projetid == '' && $ref == '' && ($_GET['action'] != "create" && $_POST['action'] != "add" && $_POST["action"] != "update" && !$_POST["cancel"])) accessforbidden();
// Security check // Security check

View File

@ -56,9 +56,10 @@ if (! empty($_POST['newcompany']) || ! empty($_POST['socid']) || ! empty($_POST[
print '<ul>'; print '<ul>';
while ($company = $db->fetch_object($resql)) while ($company = $db->fetch_object($resql))
{ {
print '<li id="'.$company->rowid.'">'; print '<li>';
print $company->nom; print $company->nom;
//print '<span id="object" class="informal" style="display:none">'.$company->rowid.'-idcache</span>'; // To output content that will not be inserted into selected field, we use span.
print '<span id="object" class="informal" style="display:none">'.$company->rowid.'-idcache</span>';
print '</li>'; print '</li>';
} }
print '</ul>'; print '</ul>';