diff --git a/htdocs/comm/action/card.php b/htdocs/comm/action/card.php
index eb2eddb3197..3c9bee038ff 100644
--- a/htdocs/comm/action/card.php
+++ b/htdocs/comm/action/card.php
@@ -55,7 +55,7 @@ $langs->load("agenda");
$action=GETPOST('action','alpha');
$cancel=GETPOST('cancel','alpha');
$backtopage=GETPOST('backtopage','alpha');
-$contactid=GETPOST('contactid','int');
+$TContactId=GETPOST('TContactId','array');
$origin=GETPOST('origin','alpha');
$originid=GETPOST('originid','int');
$confirm = GETPOST('confirm', 'alpha');
@@ -188,9 +188,9 @@ if ($action == 'add')
else $backtopage=DOL_URL_ROOT.'/comm/action/index.php';
}
- if ($contactid)
+ if (!empty($TContactId[0]))
{
- $result=$contact->fetch($contactid);
+ $result=$contact->fetch($TContactId[0]);
}
if ($cancel)
@@ -319,6 +319,9 @@ if ($action == 'add')
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), null, 'errors');
}
+ $object->TContactId = $TContactId;
+ if (!empty($object->TContactId[0])) $object->contactid = $object->TContactId[0];
+
// Fill array 'array_options' with data from add form
$ret = $extrafields->setOptionalsFromPost($extralabels,$object);
if ($ret < 0) $error++;
@@ -409,7 +412,8 @@ if ($action == 'update')
$object->fulldayevent= GETPOST("fullday")?1:0;
$object->location = GETPOST('location');
$object->socid = GETPOST("socid");
- $object->contactid = GETPOST("contactid",'int');
+ $object->TContactId = GETPOST("TContactId",'array');
+ $object->contactid = !empty($object->TContactId[0]) ? $object->TContactId[0] : 0;
//$object->societe->id = $_POST["socid"]; // deprecated
//$object->contact->id = $_POST["contactid"]; // deprecated
$object->fk_project = GETPOST("projectid",'int');
@@ -594,9 +598,10 @@ if ($action == 'create')
{
$contact = new Contact($db);
- if (GETPOST("contactid"))
+ $TContactId = GETPOST("TContactId", 'array');
+ if (!empty($TContactId[0]))
{
- $result=$contact->fetch(GETPOST("contactid"));
+ $result=$contact->fetch($TContactId[0]);
if ($result < 0) dol_print_error($db,$contact->error);
}
@@ -781,7 +786,7 @@ if ($action == 'create')
// Related contact
print '
'.$langs->trans("ActionOnContact").' ';
print '';
- $form->select_contacts($object->socid, $object->contactid, 'contactid', 1, '', '', 0, 'minwidth200');
+ $form->select_contacts($object->socid, $object->TContactId, 'TContactId[]', 1, '', '', 0, 'minwidth200',0, 0, array(), false, 'multiple', 'contactid');
print '
';
print ' ';
print ' ';
@@ -1368,14 +1374,24 @@ if ($id > 0)
// Related contact
print ''.$langs->trans("ActionOnContact").' ';
print '';
- if ($object->contactid > 0)
+
+ if (!empty($object->TContactId))
{
- print $object->contact->getNomUrl(1);
- if ($object->contactid && $object->type_code == 'AC_TEL')
+ foreach ($object->TContactId as $cid)
{
- if ($object->contact->fetch($object->contactid))
+ $contact = new Contact($db);
+ $result = $contact->fetch($cid);
+
+ if ($result < 0) dol_print_error($db,$contact->error);
+
+ if ($result > 0)
{
- print " ".dol_print_phone($object->contact->phone_pro);
+ print $contact->getNomUrl(1).' ';
+ if ($object->type_code == 'AC_TEL')
+ {
+ if (!empty($contact->phone_pro)) print '('.dol_print_phone($contact->phone_pro).')';
+ print ' ';
+ }
}
}
}
diff --git a/htdocs/comm/action/class/actioncomm.class.php b/htdocs/comm/action/class/actioncomm.class.php
index 8243268574c..4250fc3fa6b 100644
--- a/htdocs/comm/action/class/actioncomm.class.php
+++ b/htdocs/comm/action/class/actioncomm.class.php
@@ -113,6 +113,8 @@ class ActionComm extends CommonObject
var $userownerid; // Id of user owner = fk_user_action into table
var $userdoneid; // Id of user done (deprecated)
+ var $socpeopleassigned = array(); // Array of user ids
+ var $TContactId = array(); // Array of user ids
/**
* Object user of owner
* @var User
@@ -345,6 +347,26 @@ class ActionComm extends CommonObject
}
}
+ if (!$error)
+ {
+ if (!empty($this->TContactId))
+ {
+ foreach ($this->TContactId as $id)
+ {
+ $sql ="INSERT INTO ".MAIN_DB_PREFIX."actioncomm_resources(fk_actioncomm, element_type, fk_element, mandatory, transparency, answer_status)";
+ $sql.=" VALUES(".$this->id.", 'socpeople', ".$id.", 0, 0, 0)";
+
+ $resql = $this->db->query($sql);
+ if (! $resql)
+ {
+ $error++;
+ $this->errors[]=$this->db->lasterror();
+ }
+
+ }
+ }
+ }
+
if (! $error)
{
$action='create';
@@ -432,7 +454,8 @@ class ActionComm extends CommonObject
$objFrom = clone $this;
$this->fetch_optionals();
- $this->fetch_userassigned();
+// $this->fetch_userassigned();
+ $this->fetchResources();
$this->id=0;
@@ -587,6 +610,8 @@ class ActionComm extends CommonObject
$this->fk_element = $obj->fk_element;
$this->elementtype = $obj->elementtype;
+
+ $this->fetchResources();
}
$this->db->free($resql);
}
@@ -600,6 +625,51 @@ class ActionComm extends CommonObject
}
+ /**
+ * Initialize $this->userassigned & this->socpeopleassigned array with list of id of user and contact assigned to event
+ *
+ * @return int <0 if KO, >0 if OK
+ */
+ function fetchResources()
+ {
+ $sql ='SELECT fk_actioncomm, element_type, fk_element, answer_status, mandatory, transparency';
+ $sql.=' FROM '.MAIN_DB_PREFIX.'actioncomm_resources';
+ $sql.=' WHERE fk_actioncomm = '.$this->id;
+ $resql=$this->db->query($sql);
+ if ($resql)
+ {
+ $this->userassigned=array();
+ $this->socpeopleassigned=array();
+ $this->TContactId=array();
+
+ // If owner is known, we must but id first into list
+ if ($this->userownerid > 0) $this->userassigned[$this->userownerid]=array('id'=>$this->userownerid); // Set first so will be first into list.
+
+ while ($obj = $this->db->fetch_object($resql))
+ {
+ if ($obj->fk_element > 0)
+ {
+ switch ($obj->element_type) {
+ case 'user':
+ $this->userassigned[$obj->fk_element]=array('id'=>$obj->fk_element, 'mandatory'=>$obj->mandatory, 'answer_status'=>$obj->answer_status, 'transparency'=>$obj->transparency);
+ if (empty($this->userownerid)) $this->userownerid=$obj->fk_element; // If not defined (should not happened, we fix this)
+ break;
+ case 'socpeople':
+ $this->TContactId[] = $obj->fk_element;
+ $this->socpeopleassigned[$obj->fk_element]=array('id'=>$obj->fk_element, 'mandatory'=>$obj->mandatory, 'answer_status'=>$obj->answer_status, 'transparency'=>$obj->transparency);
+ break;
+ }
+ }
+ }
+
+ return 1;
+ }
+ else
+ {
+ dol_print_error($this->db);
+ return -1;
+ }
+ }
/**
* Initialize this->userassigned array with list of id of user assigned to event
@@ -821,6 +891,29 @@ class ActionComm extends CommonObject
//var_dump($sql);exit;
}
}
+
+ if (!$error)
+ {
+ $sql ="DELETE FROM ".MAIN_DB_PREFIX."actioncomm_resources where fk_actioncomm = ".$this->id." AND element_type = 'socpeople'";
+ $resql = $this->db->query($sql);
+
+ if (!empty($this->TContactId))
+ {
+ foreach ($this->TContactId as $id)
+ {
+ $sql ="INSERT INTO ".MAIN_DB_PREFIX."actioncomm_resources(fk_actioncomm, element_type, fk_element, mandatory, transparency, answer_status)";
+ $sql.=" VALUES(".$this->id.", 'socpeople', ".$id.", 0, 0, 0)";
+
+ $resql = $this->db->query($sql);
+ if (! $resql)
+ {
+ $error++;
+ $this->errors[]=$this->db->lasterror();
+ }
+
+ }
+ }
+ }
if (! $error && ! $notrigger)
{
diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php
index 7b112a2d333..1646e660c9f 100644
--- a/htdocs/core/class/html.form.class.php
+++ b/htdocs/core/class/html.form.class.php
@@ -1253,11 +1253,13 @@ class Form
* @param int $forcecombo Force to use combo box
* @param array $events Event options. Example: array(array('method'=>'getContacts', 'url'=>dol_buildpath('/core/ajax/contacts.php',1), 'htmlname'=>'contactid', 'params'=>array('add-customer-contact'=>'disabled')))
* @param bool $options_only Return options only (for ajax treatment)
+ * @param string $moreparam Add more parameters onto the select tag. For example 'style="width: 95%"' to avoid select2 component to go over parent container
+ * @param string $htmlid Html id to use instead of htmlname
* @return int <0 if KO, Nb of contact in list if OK
*/
- function select_contacts($socid,$selected='',$htmlname='contactid',$showempty=0,$exclude='',$limitto='',$showfunction=0, $moreclass='', $showsoc=0, $forcecombo=0, $events=array(), $options_only=false)
+ function select_contacts($socid,$selected='',$htmlname='contactid',$showempty=0,$exclude='',$limitto='',$showfunction=0, $moreclass='', $showsoc=0, $forcecombo=0, $events=array(), $options_only=false, $moreparam='', $htmlid='')
{
- print $this->selectcontacts($socid,$selected,$htmlname,$showempty,$exclude,$limitto,$showfunction, $moreclass, $options_only, $showsoc, $forcecombo, $events);
+ print $this->selectcontacts($socid,$selected,$htmlname,$showempty,$exclude,$limitto,$showfunction, $moreclass, $options_only, $showsoc, $forcecombo, $events, $moreparam, $htmlid);
return $this->num;
}
@@ -1276,14 +1278,17 @@ class Form
* @param integer $showsoc Add company into label
* @param int $forcecombo Force to use combo box
* @param array $events Event options. Example: array(array('method'=>'getContacts', 'url'=>dol_buildpath('/core/ajax/contacts.php',1), 'htmlname'=>'contactid', 'params'=>array('add-customer-contact'=>'disabled')))
+ * @param string $moreparam Add more parameters onto the select tag. For example 'style="width: 95%"' to avoid select2 component to go over parent container
+ * @param string $htmlid Html id to use instead of htmlname
* @return int <0 if KO, Nb of contact in list if OK
*/
- function selectcontacts($socid,$selected='',$htmlname='contactid',$showempty=0,$exclude='',$limitto='',$showfunction=0, $moreclass='', $options_only=false, $showsoc=0, $forcecombo=0, $events=array())
+ function selectcontacts($socid,$selected='',$htmlname='contactid',$showempty=0,$exclude='',$limitto='',$showfunction=0, $moreclass='', $options_only=false, $showsoc=0, $forcecombo=0, $events=array(), $moreparam='', $htmlid='')
{
global $conf,$langs;
$langs->load('companies');
+ if (empty($htmlid)) $htmlid = $htmlname;
$out='';
// On recherche les societes
@@ -1305,11 +1310,11 @@ class Form
if ($conf->use_javascript_ajax && ! $forcecombo && ! $options_only)
{
include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php';
- $comboenhancement = ajax_combobox($htmlname, $events, $conf->global->CONTACT_USE_SEARCH_TO_SELECT);
+ $comboenhancement = ajax_combobox($htmlid, $events, $conf->global->CONTACT_USE_SEARCH_TO_SELECT);
$out.= $comboenhancement;
}
- if ($htmlname != 'none' || $options_only) $out.= '';
+ if ($htmlname != 'none' || $options_only) $out.= '';
if ($showempty == 1) $out.= ' ';
if ($showempty == 2) $out.= ''.$langs->trans("Internal").' ';
$num = $this->db->num_rows($resql);
@@ -1319,6 +1324,7 @@ class Form
include_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
$contactstatic=new Contact($this->db);
+ if (!is_array($selected)) $selected = array($selected);
while ($i < $num)
{
$obj = $this->db->fetch_object($resql);
@@ -1332,7 +1338,7 @@ class Form
$disabled=0;
if (is_array($exclude) && count($exclude) && in_array($obj->rowid,$exclude)) $disabled=1;
if (is_array($limitto) && count($limitto) && ! in_array($obj->rowid,$limitto)) $disabled=1;
- if ($selected && $selected == $obj->rowid)
+ if (!empty($selected) && in_array($obj->rowid, $selected))
{
$out.= 'rowid)
+ if (in_array($obj->rowid, $selected))
{
$out.= $contactstatic->getFullName($langs);
if ($showfunction && $obj->poste) $out.= ' ('.$obj->poste.')';
diff --git a/htdocs/install/upgrade2.php b/htdocs/install/upgrade2.php
index 36bbeb966d4..e2d18947310 100644
--- a/htdocs/install/upgrade2.php
+++ b/htdocs/install/upgrade2.php
@@ -438,6 +438,8 @@ if (! GETPOST('action','aZ09') || preg_match('/upgrade/i',GETPOST('action','aZ09
$beforeversionarray=explode('.','6.0.9');
if (versioncompare($versiontoarray,$afterversionarray) >= 0 && versioncompare($versiontoarray,$beforeversionarray) <= 0)
{
+ migrate_event_assignement_contact($db,$langs,$conf);
+
// Reload modules (this must be always and only into last targeted version)
$listofmodule=array(
'MAIN_MODULE_USER'=>'newboxdefonly',
@@ -3813,6 +3815,83 @@ function migrate_event_assignement($db,$langs,$conf)
print ' ';
}
+/**
+ * Migrate event assignement to owner
+ *
+ * @param DoliDB $db Database handler
+ * @param Translate $langs Object langs
+ * @param Conf $conf Object conf
+ * @return void
+ */
+function migrate_event_assignement_contact($db,$langs,$conf)
+{
+ print '