From 8511f1f7ef6b8a3c191320ac7b15c0ad6fc52ef0 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 15 Apr 2015 18:14:26 +0200 Subject: [PATCH 1/8] Fix the data-role parameter --- htdocs/core/class/html.formother.class.php | 8 ++++++-- htdocs/core/lib/ajax.lib.php | 6 +++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/htdocs/core/class/html.formother.class.php b/htdocs/core/class/html.formother.class.php index b7971d52c53..9de656fc44e 100644 --- a/htdocs/core/class/html.formother.class.php +++ b/htdocs/core/class/html.formother.class.php @@ -362,8 +362,12 @@ class FormOther if ($conf->use_javascript_ajax) { include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; - $out.= ajax_combobox($htmlname); - $nodatarole=' data-role="none"'; + $htmlforcombo = ajax_combobox($htmlname); + if ($htmlforcombo) + { + $out.= $htmlforcombo; + $nodatarole=' data-role="none"'; + } } // Select each sales and print them in a select input $out.=''; + $outarray=array(); if (is_array($cate_arbo)) { if (! count($cate_arbo)) $output.= ''; @@ -2959,12 +2961,16 @@ class Form $add = ''; } $output.= ''; + + $outarray[$cate_arbo[$key]['id']] = $cate_arbo[$key]['fulllabel']; } } } $output.= ''; $output.= "\n"; - return $output; + + if ($outputmode) return $outarray; + return $output; } /** diff --git a/htdocs/product/card.php b/htdocs/product/card.php index 102b86299eb..239e351cedb 100644 --- a/htdocs/product/card.php +++ b/htdocs/product/card.php @@ -40,6 +40,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/genericobject.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; if (! empty($conf->propal->enabled)) require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php'; if (! empty($conf->facture->enabled)) require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; if (! empty($conf->commande->enabled)) require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php'; @@ -271,6 +272,16 @@ if (empty($reshook)) if ($id > 0) { + // Category association + $categories = GETPOST('categories'); + if(!empty($categories)) { + $cat = new Categorie($db); + foreach($categories as $id_category) { + $cat->fetch($id_category); + $cat->add_type($object, 'product'); + } + } + header("Location: ".$_SERVER['PHP_SELF']."?id=".$id); exit; } @@ -349,6 +360,23 @@ if (empty($reshook)) { if ($object->update($object->id, $user) > 0) { + // Category association + // First we delete all categories association + $sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_product"; + $sql .= " WHERE fk_product = ".$object->id; + $db->query($sql); + + // Then we add the associated categories + $categories = GETPOST('categories'); + if(!empty($categories)) { + $cat = new Categorie($db); + + foreach($categories as $id_category) { + $cat->fetch($id_category); + $cat->add_type($object, 'product'); + } + } + $action = 'view'; } else @@ -1003,6 +1031,13 @@ else $doleditor->Create(); print ""; + + // Categories + print ''.$langs->trans("Categories").''; + $cate_arbo = $form->select_all_categories(0, '', 'parent', 64, 0, 1); + print $form->multiselectarray('categories', $cate_arbo, $arrayselected, '', 0, '', 0, 250); + print ""; + print ''; print '
'; @@ -1272,6 +1307,18 @@ else $doleditor->Create(); print ""; + + // Categories + print ''.$langs->trans("Categories").''; + $cate_arbo = $form->select_all_categories(0, '', 'parent', 64, 0, 1); + $c = new Categorie($db); + $cats = $c->containing($object->id,0); + foreach($cats as $cat) { + $arrayselected[] = $cat->id; + } + print $form->multiselectarray('categories', $cate_arbo, $arrayselected, '', 0, '', 0, 250); + print ""; + print ''; print '
'; @@ -1561,6 +1608,19 @@ else print ''.$langs->trans("Note").''.(dol_textishtml($object->note)?$object->note:dol_nl2br($object->note,1,true)).''."\n"; print ' '."\n"; + // Categories + print ''.$langs->trans("Categories").''; + $cat = new Categorie($db); + $categories = $cat->containing($object->id,0); + $catarray = $form->select_all_categories(0, '', 'parent', 64, 0, 1); + + $toprint = array(); + foreach($categories as $c) { + $toprint[] = $catarray[$c->id]; + } + print implode('
', $toprint); + print ""; + print "\n"; dol_fiche_end();