diff --git a/htdocs/contact/card.php b/htdocs/contact/card.php
index 742378a2db3..e39c5502b4d 100644
--- a/htdocs/contact/card.php
+++ b/htdocs/contact/card.php
@@ -40,6 +40,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
require_once DOL_DOCUMENT_ROOT. '/core/class/html.form.class.php';
require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
+require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php';
$langs->load("companies");
$langs->load("users");
$langs->load("other");
@@ -220,7 +221,17 @@ if (empty($reshook))
{
$error++; $errors=array_merge($errors,($object->error?array($object->error):$object->errors));
$action = 'create';
- }
+ } else {
+ // Categories association
+ $contcats = GETPOST( 'contcats', 'array' );
+ if (!empty( $contcats )) {
+ $cat = new Categorie( $db );
+ foreach ($contcats as $id_category) {
+ $cat->fetch( $id_category );
+ $cat->add_type( $object, 'contact' );
+ }
+ }
+ }
}
if (! $error && $id > 0)
@@ -313,8 +324,22 @@ if (empty($reshook))
$result = $object->update($contactid, $user);
- if ($result > 0)
- {
+ if ($result > 0) {
+ // Categories association
+ // First we delete all categories association
+ $sql = 'DELETE FROM ' . MAIN_DB_PREFIX . 'categorie_contact';
+ $sql .= ' WHERE fk_socpeople = ' . $object->id;
+ $db->query( $sql );
+
+ // Then we add the associated categories
+ $categories = GETPOST( 'contcats', 'array' );
+ if (!empty( $categories )) {
+ $cat = new Categorie( $db );
+ foreach ($categories as $id_category) {
+ $cat->fetch( $id_category );
+ $cat->add_type( $object, 'contact' );
+ }
+ }
$object->old_lastname='';
$object->old_firstname='';
$action = 'view';
@@ -580,6 +605,15 @@ else
print $form->selectarray('priv',$selectarray,(GETPOST("priv",'alpha')?GETPOST("priv",'alpha'):$object->priv),0);
print '';
+ // Categories
+ if (! empty($conf->categorie->enabled) && ! empty($user->rights->categorie->lire)) {
+ print '
| ' . fieldLabel( 'Categories', 'contcats' ) . ' | ';
+ $cate_arbo = $form->select_all_categories( Categorie::TYPE_CONTACT, null, 'parent', null, null, 1 );
+ print $form->multiselectarray( 'contcats', $cate_arbo, GETPOST( 'contcats', 'array' ), null, null, null,
+ null, '90%' );
+ print " |
";
+ }
+
// Other attributes
$parameters=array('colspan' => ' colspan="3"');
$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
@@ -819,6 +853,20 @@ else
print $object->getLibStatut(4);
print '';
+ // Categories
+ if (!empty( $conf->categorie->enabled ) && !empty( $user->rights->categorie->lire )) {
+ print '| ' . fieldLabel( 'Categories', 'contcats' ) . ' | ';
+ print '';
+ $cate_arbo = $form->select_all_categories( Categorie::TYPE_CONTACT, null, null, null, null, 1 );
+ $c = new Categorie( $db );
+ $cats = $c->containing( $object->id, Categorie::TYPE_CONTACT );
+ foreach ($cats as $cat) {
+ $arrayselected[] = $cat->id;
+ }
+ print $form->multiselectarray( 'contcats', $cate_arbo, $arrayselected, '', 0, '', 0, '90%' );
+ print " |
";
+ }
+
// Other attributes
$parameters=array('colspan' => ' colspan="3"');
$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
@@ -1043,6 +1091,15 @@ else
print $object->getLibStatut(4);
print '';
print ''."\n";
+
+ // Categories
+ if (! empty($conf->categorie->enabled) && ! empty($user->rights->categorie->lire)) {
+ print '| ' . $langs->trans( "Categories" ) . ' | ';
+ print '';
+ print $form->showCategories( $object->id, 'contact', 1 );
+ print ' |
';
+ }
+
// Other attributes
$parameters=array('socid'=>$socid, 'colspan' => ' colspan="3"');
$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
diff --git a/htdocs/core/lib/contact.lib.php b/htdocs/core/lib/contact.lib.php
index 3a50b79edd7..40dab648de1 100644
--- a/htdocs/core/lib/contact.lib.php
+++ b/htdocs/core/lib/contact.lib.php
@@ -87,16 +87,6 @@ function contact_prepare_head(Contact $object)
$head[$tab][2] = 'documents';
$tab++;
- if (! empty($conf->categorie->enabled) && ! empty($user->rights->categorie->lire))
- {
- require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php';
- $type = Categorie::TYPE_CONTACT;
- $head[$tab][0] = DOL_URL_ROOT.'/categories/categorie.php?id='.$object->id."&type=".$type;
- $head[$tab][1] = $langs->trans('Categories');
- $head[$tab][2] = 'category';
- $tab++;
- }
-
// Info
$head[$tab][0] = DOL_URL_ROOT.'/contact/info.php?id='.$object->id;
$head[$tab][1] = $langs->trans("Info");