Merge pull request #3016 from GPCsolutions/dolibarr-2571
Added tag/categories management to contact card
This commit is contained in:
commit
609b1291c7
@ -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 '</td></tr>';
|
||||
|
||||
// Categories
|
||||
if (! empty($conf->categorie->enabled) && ! empty($user->rights->categorie->lire)) {
|
||||
print '<tr><td>' . fieldLabel( 'Categories', 'contcats' ) . '</td><td colspan="3">';
|
||||
$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 "</td></tr>";
|
||||
}
|
||||
|
||||
// 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 '</td></tr>';
|
||||
|
||||
// Categories
|
||||
if (!empty( $conf->categorie->enabled ) && !empty( $user->rights->categorie->lire )) {
|
||||
print '<tr><td>' . fieldLabel( 'Categories', 'contcats' ) . '</td>';
|
||||
print '<td colspan="3">';
|
||||
$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 "</td></tr>";
|
||||
}
|
||||
|
||||
// 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 '</td>';
|
||||
print '</tr>'."\n";
|
||||
|
||||
// Categories
|
||||
if (! empty($conf->categorie->enabled) && ! empty($user->rights->categorie->lire)) {
|
||||
print '<tr><td>' . $langs->trans( "Categories" ) . '</td>';
|
||||
print '<td colspan="3">';
|
||||
print $form->showCategories( $object->id, 'contact', 1 );
|
||||
print '</td></tr>';
|
||||
}
|
||||
|
||||
// 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
|
||||
|
||||
@ -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");
|
||||
|
||||
Loading…
Reference in New Issue
Block a user