Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dolibarr
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Container Registry
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Software_Artifact_Infrastructure_Repository
dolibarr
Commits
9d8036e5
Commit
9d8036e5
authored
9 years ago
by
Maxime Kohlhaas
Browse files
Options
Downloads
Patches
Plain Diff
New : categories as multi-select on product
parent
56173999
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
htdocs/core/class/html.form.class.php
+8
-2
8 additions, 2 deletions
htdocs/core/class/html.form.class.php
htdocs/product/card.php
+60
-0
60 additions, 0 deletions
htdocs/product/card.php
with
68 additions
and
2 deletions
htdocs/core/class/html.form.class.php
+
8
−
2
View file @
9d8036e5
...
...
@@ -2930,10 +2930,11 @@ class Form
* @param string $htmlname HTML field name
* @param int $maxlength Maximum length for labels
* @param int $excludeafterid Exclude all categories after this leaf in category tree.
* @param int $outputmode 0=HTML select string, 1=Array
* @return string
* @see select_categories
*/
function
select_all_categories
(
$type
,
$selected
=
''
,
$htmlname
=
"parent"
,
$maxlength
=
64
,
$excludeafterid
=
0
)
function
select_all_categories
(
$type
,
$selected
=
''
,
$htmlname
=
"parent"
,
$maxlength
=
64
,
$excludeafterid
=
0
,
$outputmode
=
0
)
{
global
$langs
;
$langs
->
load
(
"categories"
);
...
...
@@ -2942,6 +2943,7 @@ class Form
$cate_arbo
=
$cat
->
get_full_arbo
(
$type
,
$excludeafterid
);
$output
=
'<select class="flat" name="'
.
$htmlname
.
'">'
;
$outarray
=
array
();
if
(
is_array
(
$cate_arbo
))
{
if
(
!
count
(
$cate_arbo
))
$output
.
=
'<option value="-1" disabled="disabled">'
.
$langs
->
trans
(
"NoCategoriesDefined"
)
.
'</option>'
;
...
...
@@ -2959,12 +2961,16 @@ class Form
$add
=
''
;
}
$output
.
=
'<option '
.
$add
.
'value="'
.
$cate_arbo
[
$key
][
'id'
]
.
'">'
.
dol_trunc
(
$cate_arbo
[
$key
][
'fulllabel'
],
$maxlength
,
'middle'
)
.
'</option>'
;
$outarray
[
$cate_arbo
[
$key
][
'id'
]]
=
$cate_arbo
[
$key
][
'fulllabel'
];
}
}
}
$output
.
=
'</select>'
;
$output
.
=
"
\n
"
;
return
$output
;
if
(
$outputmode
)
return
$outarray
;
return
$output
;
}
/**
...
...
This diff is collapsed.
Click to expand it.
htdocs/product/card.php
+
60
−
0
View file @
9d8036e5
...
...
@@ -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
"</td></tr>"
;
// Categories
print
'<tr><td valign="top">'
.
$langs
->
trans
(
"Categories"
)
.
'</td><td colspan="3">'
;
$cate_arbo
=
$form
->
select_all_categories
(
0
,
''
,
'parent'
,
64
,
0
,
1
);
print
$form
->
multiselectarray
(
'categories'
,
$cate_arbo
,
$arrayselected
,
''
,
0
,
''
,
0
,
250
);
print
"</td></tr>"
;
print
'</table>'
;
print
'<br>'
;
...
...
@@ -1272,6 +1307,18 @@ else
$doleditor
->
Create
();
print
"</td></tr>"
;
// Categories
print
'<tr><td valign="top">'
.
$langs
->
trans
(
"Categories"
)
.
'</td><td colspan="3">'
;
$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
"</td></tr>"
;
print
'</table>'
;
print
'<br>'
;
...
...
@@ -1561,6 +1608,19 @@ else
print
'<tr><td valign="top">'
.
$langs
->
trans
(
"Note"
)
.
'</td><td colspan="'
.
(
2
+
((
$showphoto
||
$showbarcode
)
?
1
:
0
))
.
'">'
.
(
dol_textishtml
(
$object
->
note
)
?
$object
->
note
:
dol_nl2br
(
$object
->
note
,
1
,
true
))
.
'</td></tr>'
.
"
\n
"
;
print
'<!-- End show Note --> '
.
"
\n
"
;
// Categories
print
'<tr><td valign="top">'
.
$langs
->
trans
(
"Categories"
)
.
'</td><td colspan="3">'
;
$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
(
'<br>'
,
$toprint
);
print
"</td></tr>"
;
print
"</table>
\n
"
;
dol_fiche_end
();
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment