diff --git a/htdocs/core/lib/ajax.lib.php b/htdocs/core/lib/ajax.lib.php index 9081fba5550..f657df7185b 100644 --- a/htdocs/core/lib/ajax.lib.php +++ b/htdocs/core/lib/ajax.lib.php @@ -459,3 +459,95 @@ 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')) + * @param int $entity Entity to set + * @return void + */ +function ajax_productonoff($id, $code, $input=array(), $entity=null) +{ + require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; + global $conf, $langs, $db; + + $entity = ((isset($entity) && is_numeric($entity) && $entity >= 0) ? $entity : $conf->entity); + $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; +} +