From e6e953b4d80f37862386eab294b205434d59c5a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Sun, 12 Oct 2014 14:20:49 +0200 Subject: [PATCH 1/9] Update ajax.lib.php --- htdocs/core/lib/ajax.lib.php | 92 ++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) diff --git a/htdocs/core/lib/ajax.lib.php b/htdocs/core/lib/ajax.lib.php index 9081fba5550d0..f657df7185b80 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; +} + From 77d77642154d1aeb15f544d58e3407cf9f3040d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Sun, 12 Oct 2014 14:22:32 +0200 Subject: [PATCH 2/9] Create productonoff.php --- htdocs/core/ajax/productonoff.php | 65 +++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 htdocs/core/ajax/productonoff.php diff --git a/htdocs/core/ajax/productonoff.php b/htdocs/core/ajax/productonoff.php new file mode 100644 index 0000000000000..4def2898c10a8 --- /dev/null +++ b/htdocs/core/ajax/productonoff.php @@ -0,0 +1,65 @@ +. + */ + +/** + * \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.'/product/class/product.class.php'; + +$action=GETPOST('action','alpha'); +$name=GETPOST('name','alpha'); +$id=GETPOST('id', 'int'); + +/* + * View + */ + +top_httphead(); + +print ''."\n"; + +// Registering the location of boxes +if (! empty($action) && ! empty($name) &&! empty($id)) +{ + //$entity = GETPOST('entity','int'); + + if ($user->rights->produit->creer) { + if ($action == 'set' && $name== 'status') { + $sql = "UPDATE llx_product SET tosell=1 WHERE rowid=".$id; + $resql = $db->query($sql); + } else if ($action == 'set' && $name== 'status_buy') { + $sql = "UPDATE llx_product SET tobuy=1 WHERE rowid=".$id; + $resql = $db->query($sql); + } else if ($action == 'del' && $name== 'status') { + $sql = "UPDATE llx_product SET tosell=0 WHERE rowid=".$id; + $resql = $db->query($sql); + } else if ($action == 'del' && $name== 'status_buy') { + $sql = "UPDATE llx_product SET tobuy=0 WHERE rowid=".$id; + $resql = $db->query($sql); + } + + } +} From 633f01e5a2e1c8b3ca2f6bd5af04d249a57edb50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Sun, 12 Oct 2014 14:26:51 +0200 Subject: [PATCH 3/9] Update card.php --- htdocs/product/card.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/htdocs/product/card.php b/htdocs/product/card.php index a9f533ba40b4d..0f374dc2b3a31 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)) { + 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)) { + print ajax_productonoff($object->id, 'status_buy'); + } else { + print $object->getLibStatut(2,1); + } print ''; // Batch number management (to batch) From f25c4f18e693fe31d75fa7430db15b03a8c538b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Sun, 12 Oct 2014 15:55:18 +0200 Subject: [PATCH 4/9] Update ajax.lib.php --- htdocs/core/lib/ajax.lib.php | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/htdocs/core/lib/ajax.lib.php b/htdocs/core/lib/ajax.lib.php index f657df7185b80..4a43c06ad3612 100644 --- a/htdocs/core/lib/ajax.lib.php +++ b/htdocs/core/lib/ajax.lib.php @@ -468,12 +468,11 @@ function ajax_constantonoff($code, $input=array(), $entity=null, $revertonoff=0, * @param int $entity Entity to set * @return void */ -function ajax_productonoff($id, $code, $input=array(), $entity=null) +function ajax_productonoff($id, $code, $input=array()) { 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); @@ -484,10 +483,9 @@ function ajax_productonoff($id, $code, $input=array(), $entity=null) // Set constant $("#set_'.$code.'").click(function() { $.get( "'.DOL_URL_ROOT.'/core/ajax/productonoff.php", { - action: \'set\', - name: \''.$code.'\', - id: \''.$id.'\', - entity: \''.$entity.'\' + action: \'set'.$code.'\', + value: \'1\', + id: \''.$id.'\' }, function() { $("#set_'.$code.'").hide(); @@ -513,10 +511,9 @@ function() { // Del constant $("#del_'.$code.'").click(function() { $.get( "'.DOL_URL_ROOT.'/core/ajax/productonoff.php", { - action: \'del\', - name: \''.$code.'\', - id: \''.$id.'\', - entity: \''.$entity.'\' + action: \'set'.$code.'\', + value: \'0\', + id: \''.$id.'\' }, function() { $("#del_'.$code.'").hide(); From 052e507271961c87b32b10d1197125b58f3db4da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Sun, 12 Oct 2014 15:56:04 +0200 Subject: [PATCH 5/9] Update productonoff.php --- htdocs/core/ajax/productonoff.php | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/htdocs/core/ajax/productonoff.php b/htdocs/core/ajax/productonoff.php index 4def2898c10a8..227a9ef900129 100644 --- a/htdocs/core/ajax/productonoff.php +++ b/htdocs/core/ajax/productonoff.php @@ -27,12 +27,14 @@ if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1'); require '../../main.inc.php'; -require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/genericobject.class.php'; $action=GETPOST('action','alpha'); $name=GETPOST('name','alpha'); $id=GETPOST('id', 'int'); +$value=GETPOST('value', 'int'); +$object = new GenericObject($db); /* * View */ @@ -42,24 +44,15 @@ print ''."\n"; // Registering the location of boxes -if (! empty($action) && ! empty($name) &&! empty($id)) +if (! empty($action) && ! empty($id)) { //$entity = GETPOST('entity','int'); if ($user->rights->produit->creer) { - if ($action == 'set' && $name== 'status') { - $sql = "UPDATE llx_product SET tosell=1 WHERE rowid=".$id; - $resql = $db->query($sql); - } else if ($action == 'set' && $name== 'status_buy') { - $sql = "UPDATE llx_product SET tobuy=1 WHERE rowid=".$id; - $resql = $db->query($sql); - } else if ($action == 'del' && $name== 'status') { - $sql = "UPDATE llx_product SET tosell=0 WHERE rowid=".$id; - $resql = $db->query($sql); - } else if ($action == 'del' && $name== 'status_buy') { - $sql = "UPDATE llx_product SET tobuy=0 WHERE rowid=".$id; - $resql = $db->query($sql); - } + if ($action == 'setstatus') + $object->setValueFrom('tosell', $value, 'product', $id); + else if ($action == 'setstatus_buy') + $object->setValueFrom('tobuy', $value, 'product', $id); } } From f5f50045d6c63b01b1e3cc23901df7eda3cb7f03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Sun, 12 Oct 2014 16:09:42 +0200 Subject: [PATCH 6/9] Update ajax.lib.php --- htdocs/core/lib/ajax.lib.php | 1 - 1 file changed, 1 deletion(-) diff --git a/htdocs/core/lib/ajax.lib.php b/htdocs/core/lib/ajax.lib.php index 4a43c06ad3612..4bc6da083aa29 100644 --- a/htdocs/core/lib/ajax.lib.php +++ b/htdocs/core/lib/ajax.lib.php @@ -465,7 +465,6 @@ function ajax_constantonoff($code, $input=array(), $entity=null, $revertonoff=0, * @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()) From 33bb150b440af67c70f5b10bd29e70d9ef25f127 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Sun, 12 Oct 2014 16:30:58 +0200 Subject: [PATCH 7/9] Update productonoff.php --- htdocs/core/ajax/productonoff.php | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/htdocs/core/ajax/productonoff.php b/htdocs/core/ajax/productonoff.php index 227a9ef900129..a6c63507f21e0 100644 --- a/htdocs/core/ajax/productonoff.php +++ b/htdocs/core/ajax/productonoff.php @@ -35,6 +35,7 @@ $value=GETPOST('value', 'int'); $object = new GenericObject($db); + /* * View */ @@ -43,16 +44,10 @@ print ''."\n"; -// Registering the location of boxes -if (! empty($action) && ! empty($id)) -{ - //$entity = GETPOST('entity','int'); - - if ($user->rights->produit->creer) { - if ($action == 'setstatus') - $object->setValueFrom('tosell', $value, 'product', $id); - else if ($action == 'setstatus_buy') - $object->setValueFrom('tobuy', $value, 'product', $id); - - } +// 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); } From 7f308bf9b5af2a7dca78a1bc626b7148d4934317 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Sun, 12 Oct 2014 17:00:42 +0200 Subject: [PATCH 8/9] Update productonoff.php --- htdocs/core/ajax/productonoff.php | 1 - 1 file changed, 1 deletion(-) diff --git a/htdocs/core/ajax/productonoff.php b/htdocs/core/ajax/productonoff.php index a6c63507f21e0..05eebc7a65fb5 100644 --- a/htdocs/core/ajax/productonoff.php +++ b/htdocs/core/ajax/productonoff.php @@ -30,7 +30,6 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/genericobject.class.php'; $action=GETPOST('action','alpha'); -$name=GETPOST('name','alpha'); $id=GETPOST('id', 'int'); $value=GETPOST('value', 'int'); From 99dde1ad1e1c8c81842874978f7895fe230ae833 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Sun, 12 Oct 2014 20:44:50 +0200 Subject: [PATCH 9/9] Update card.php --- htdocs/product/card.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/product/card.php b/htdocs/product/card.php index 0f374dc2b3a31..5644e41df1cc7 100644 --- a/htdocs/product/card.php +++ b/htdocs/product/card.php @@ -1420,7 +1420,7 @@ // Status (to sell) print ''.$langs->trans("Status").' ('.$langs->trans("Sell").')'; - if (! empty($conf->use_javascript_ajax)) { + if (! empty($conf->use_javascript_ajax) && $user->rights->produit->creer) { print ajax_productonoff($object->id, 'status'); } else { print $object->getLibStatut(2,0); @@ -1429,7 +1429,7 @@ // Status (to buy) print ''.$langs->trans("Status").' ('.$langs->trans("Buy").')'; - if (! empty($conf->use_javascript_ajax)) { + if (! empty($conf->use_javascript_ajax) && $user->rights->produit->creer) { print ajax_productonoff($object->id, 'status_buy'); } else { print $object->getLibStatut(2,1);