diff --git a/htdocs/core/ajax/productonoff.php b/htdocs/core/ajax/objectonoff.php
similarity index 84%
rename from htdocs/core/ajax/productonoff.php
rename to htdocs/core/ajax/objectonoff.php
index 05eebc7a65f..6ac5abd3bbb 100644
--- a/htdocs/core/ajax/productonoff.php
+++ b/htdocs/core/ajax/objectonoff.php
@@ -32,9 +32,10 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/genericobject.class.php';
$action=GETPOST('action','alpha');
$id=GETPOST('id', 'int');
$value=GETPOST('value', 'int');
+$field=GETPOST('field', 'alpha');
+$element=GETPOST('element', 'alpha');
$object = new GenericObject($db);
-
/*
* View
*/
@@ -44,9 +45,5 @@ top_httphead();
print ''."\n";
// Registering new values
-if (! empty($action) && ! empty($id) && $user->rights->produit->creer) {
- if ($action == 'setstatus')
- $object->setValueFrom('tosell', $value, 'product', $id);
- else if ($action == 'setstatus_buy')
- $object->setValueFrom('tobuy', $value, 'product', $id);
-}
+if (($action == 'set') && ! empty($id))
+ $object->setValueFrom($field, $value, $element, $id);
diff --git a/htdocs/core/lib/ajax.lib.php b/htdocs/core/lib/ajax.lib.php
index 4bc6da083aa..709911faaec 100644
--- a/htdocs/core/lib/ajax.lib.php
+++ b/htdocs/core/lib/ajax.lib.php
@@ -460,35 +460,36 @@ function ajax_constantonoff($code, $input=array(), $entity=null, $revertonoff=0,
}
/**
- * On/off button for product tosell or tobuy
+ * On/off button for object
*
- * @param int $id Id product to set
- * @param string $code Name of constant : status or status_buy
+ * @param int $object Id product to set
+ * @param string $code Name of constant : status or status_buy for product by example
+ * @param string $field Name of database field : tosell or tobuy for product by example
+ * @param string $text_on Text if on
+ * @param string $text_off Text if off
* @param array $input Array of type->list of CSS element to switch. Example: array('disabled'=>array(0=>'cssid'))
* @return void
*/
-function ajax_productonoff($id, $code, $input=array())
+function ajax_object_onoff($object, $code, $field, $text_on, $text_off, $input=array())
{
- require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
- global $conf, $langs, $db;
-
- $object = new Product($db);
- $object->fetch($id);
+ global $langs;
$out= '';
- if ($code=='status') {
- $out.= ''.img_picto($langs->trans("ProductStatusNotOnSell"),'switch_off').'';
- $out.= ''.img_picto($langs->trans("ProductStatusOnSell"),'switch_on').'';
- }
- if ($code=='status_buy') {
- $out.= ''.img_picto($langs->trans("ProductStatusNotOnBuy"),'switch_off').'';
- $out.= ''.img_picto($langs->trans("ProductStatusOnBuy"),'switch_on').'';
- }
+ $out.= ''.img_picto($langs->trans($text_off),'switch_off').'';
+ $out.= ''.img_picto($langs->trans($text_on),'switch_on').'';
+
return $out;
}
diff --git a/htdocs/product/card.php b/htdocs/product/card.php
index 8ec7c5b12a7..237fa97c0f0 100644
--- a/htdocs/product/card.php
+++ b/htdocs/product/card.php
@@ -1420,7 +1420,7 @@ else
// Status (to sell)
print '
| '.$langs->trans("Status").' ('.$langs->trans("Sell").') | ';
if (! empty($conf->use_javascript_ajax) && $user->rights->produit->creer) {
- print ajax_productonoff($object->id, 'status');
+ print ajax_object_onoff($object, 'status', 'tosell', 'ProductStatusOnSell', 'ProductStatusNotOnSell');
} else {
print $object->getLibStatut(2,0);
}
@@ -1429,18 +1429,22 @@ else
// Status (to buy)
print ' |
| '.$langs->trans("Status").' ('.$langs->trans("Buy").') | ';
if (! empty($conf->use_javascript_ajax) && $user->rights->produit->creer) {
- print ajax_productonoff($object->id, 'status_buy');
+ print ajax_object_onoff($object, 'status_buy', 'tobuy', 'ProductStatusOnBuy', 'ProductStatusNotOnBuy');
} else {
print $object->getLibStatut(2,1);
}
print ' |
';
- // Batch number management (to batch)
- if ($conf->productbatch->enabled) {
- print '| '.$langs->trans("Status").' ('.$langs->trans("Lot").') | ';
- print $object->getLibStatut(2,2);
- print ' |
';
- }
+ // Batch number management (to batch)
+ if ($conf->productbatch->enabled) {
+ print '| '.$langs->trans("Status").' ('.$langs->trans("Lot").') | ';
+ if (! empty($conf->use_javascript_ajax) && $user->rights->produit->creer) {
+ print ajax_object_onoff($object, 'status_batch', 'tobatch', 'ProductStatusOnBatch', 'ProductStatusNotOnBatch');
+ } else {
+ print $object->getLibStatut(2,2);
+ }
+ print ' |
';
+ }
// Description
print '| '.$langs->trans("Description").' | '.(dol_textishtml($object->description)?$object->description:dol_nl2br($object->description,1,true)).' |
';
diff --git a/htdocs/product/list.php b/htdocs/product/list.php
index 3629f98365e..55b9beb259c 100644
--- a/htdocs/product/list.php
+++ b/htdocs/product/list.php
@@ -507,11 +507,25 @@ else
}
}
- // Status (to buy)
- print ''.$product_static->LibStatut($objp->tosell,5,0).' | ';
-
+ $product_static->status_buy = $objp->tobuy;
+ $product_static->status = $objp->tosell;
// Status (to sell)
- print ''.$product_static->LibStatut($objp->tobuy,5,1).' | ';
+ print '';
+ if (! empty($conf->use_javascript_ajax) && $user->rights->produit->creer) {
+ print ajax_object_onoff($product_static, 'status', 'tosell', 'ProductStatusOnSell', 'ProductStatusNotOnSell');
+ } else {
+ print $product_static->LibStatut($objp->tosell,5,0);
+ }
+ print ' | ';
+
+ // Status (to buy)
+ print '';
+ if (! empty($conf->use_javascript_ajax) && $user->rights->produit->creer) {
+ print ajax_object_onoff($product_static, 'status_buy', 'tobuy', 'ProductStatusOnBuy', 'ProductStatusNotOnBuy');
+ } else {
+ print $product_static->LibStatut($objp->tobuy,5,1);
+ }
+ print ' | ';
print ' | ';
diff --git a/htdocs/product/stock/product.php b/htdocs/product/stock/product.php
index ae8afe696bc..7885553095e 100644
--- a/htdocs/product/stock/product.php
+++ b/htdocs/product/stock/product.php
@@ -279,7 +279,7 @@ if ($id > 0 || $ref)
// Status (to sell)
print '| '.$langs->trans("Status").' ('.$langs->trans("Sell").') | ';
if (! empty($conf->use_javascript_ajax) && $user->rights->produit->creer) {
- print ajax_productonoff($product->id, 'status');
+ print ajax_object_onoff($product, 'status', 'tosell', 'ProductStatusOnSell', 'ProductStatusNotOnSell');
} else {
print $product->getLibStatut(2,0);
}
@@ -288,7 +288,7 @@ if ($id > 0 || $ref)
// Status (to buy)
print ' |
| '.$langs->trans("Status").' ('.$langs->trans("Buy").') | ';
if (! empty($conf->use_javascript_ajax) && $user->rights->produit->creer) {
- print ajax_productonoff($product->id, 'status_buy');
+ print ajax_object_onoff($product, 'status_buy', 'tobuy', 'ProductStatusOnBuy', 'ProductStatusNotOnBuy');
} else {
print $product->getLibStatut(2,1);
}
diff --git a/htdocs/societe/soc.php b/htdocs/societe/soc.php
index 65b1e4783d8..795e8fe5cd5 100644
--- a/htdocs/societe/soc.php
+++ b/htdocs/societe/soc.php
@@ -1698,7 +1698,11 @@ else
// Status
print ' |
| '.$langs->trans("Status").' | ';
print '';
- print $object->getLibStatut(2);
+ if (! empty($conf->use_javascript_ajax) && $user->rights->societe->creer) {
+ print ajax_object_onoff($object, 'status', 'status', 'InActivity', 'ActivityCeased');
+ } else {
+ print $object->getLibStatut(2);
+ }
print ' | ';
print $htmllogobar; $htmllogobar='';
print '
';