diff --git a/htdocs/core/ajax/productonoff.php b/htdocs/core/ajax/productonoff.php new file mode 100644 index 0000000000000..05eebc7a65fb5 --- /dev/null +++ b/htdocs/core/ajax/productonoff.php @@ -0,0 +1,52 @@ +. + */ + +/** + * \file htdocs/core/ajax/productonoff.php + * \brief File to set tosell and tobuy for product + */ + +if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL','1'); // Disables token renewal +if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU','1'); +if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML','1'); +if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1'); +if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1'); +if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1'); + +require '../../main.inc.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/genericobject.class.php'; + +$action=GETPOST('action','alpha'); +$id=GETPOST('id', 'int'); +$value=GETPOST('value', 'int'); + +$object = new GenericObject($db); + +/* + * View + */ + +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); +} diff --git a/htdocs/core/lib/ajax.lib.php b/htdocs/core/lib/ajax.lib.php index 9081fba5550d0..4bc6da083aa29 100644 --- a/htdocs/core/lib/ajax.lib.php +++ b/htdocs/core/lib/ajax.lib.php @@ -459,3 +459,91 @@ function ajax_constantonoff($code, $input=array(), $entity=null, $revertonoff=0, return $out; } +/** + * On/off button for product tosell or tobuy + * + * @param int $id Id product to set + * @param string $code Name of constant : status or status_buy + * @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()) +{ + require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; + global $conf, $langs, $db; + + $object = new Product($db); + $object->fetch($id); + + $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').''; + } + return $out; +} + diff --git a/htdocs/product/card.php b/htdocs/product/card.php index a9f533ba40b4d..5644e41df1cc7 100644 --- a/htdocs/product/card.php +++ b/htdocs/product/card.php @@ -1420,12 +1420,20 @@ // Status (to sell) print ''.$langs->trans("Status").' ('.$langs->trans("Sell").')'; - print $object->getLibStatut(2,0); + if (! empty($conf->use_javascript_ajax) && $user->rights->produit->creer) { + print ajax_productonoff($object->id, 'status'); + } else { + print $object->getLibStatut(2,0); + } print ''; // Status (to buy) print ''.$langs->trans("Status").' ('.$langs->trans("Buy").')'; - print $object->getLibStatut(2,1); + if (! empty($conf->use_javascript_ajax) && $user->rights->produit->creer) { + print ajax_productonoff($object->id, 'status_buy'); + } else { + print $object->getLibStatut(2,1); + } print ''; // Batch number management (to batch)