diff --git a/htdocs/comm/action/card.php b/htdocs/comm/action/card.php
index f306b9329a1..eaf873f2aee 100644
--- a/htdocs/comm/action/card.php
+++ b/htdocs/comm/action/card.php
@@ -52,7 +52,7 @@ $langs->load("agenda");
$action=GETPOST('action','alpha');
$cancel=GETPOST('cancel','alpha');
$backtopage=GETPOST('backtopage','alpha');
-$contactid=GETPOST('contactid','int');
+$socpeopleassigned=GETPOST('socpeopleassigned','array');
$origin=GETPOST('origin','alpha');
$originid=GETPOST('originid','int');
$confirm = GETPOST('confirm', 'alpha');
@@ -185,9 +185,9 @@ if ($action == 'add')
else $backtopage=DOL_URL_ROOT.'/comm/action/index.php';
}
- if ($contactid)
+ if (!empty($socpeopleassigned[0]))
{
- $result=$contact->fetch($contactid);
+ $result=$contact->fetch($socpeopleassigned[0]);
}
if ($cancel)
@@ -316,6 +316,16 @@ if ($action == 'add')
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), null, 'errors');
}
+ foreach ($socpeopleassigned as $cid)
+ {
+ $object->socpeopleassigned[$cid] = array('id' => $cid);
+ }
+ if (!empty($object->socpeopleassigned))
+ {
+ reset($object->socpeopleassigned);
+ $object->contactid = key($object->socpeopleassigned);
+ }
+
// Fill array 'array_options' with data from add form
$ret = $extrafields->setOptionalsFromPost($extralabels,$object);
if ($ret < 0) $error++;
@@ -406,6 +416,8 @@ if ($action == 'update')
$object->fulldayevent= GETPOST("fullday")?1:0;
$object->location = GETPOST('location');
$object->socid = GETPOST("socid");
+ $socpeopleassigned = GETPOST("socpeopleassigned",'array');
+ foreach ($socpeopleassigned as $cid) $object->socpeopleassigned[$cid] = array('id' => $cid);
$object->contactid = GETPOST("contactid",'int');
$object->fk_project = GETPOST("projectid",'int');
$object->note = GETPOST("note");
@@ -594,9 +606,10 @@ if ($action == 'create')
{
$contact = new Contact($db);
- if (GETPOST("contactid"))
+ $socpeopleassigned = GETPOST("socpeopleassigned", 'array');
+ if (!empty($socpeopleassigned[0]))
{
- $result=$contact->fetch(GETPOST("contactid"));
+ $result=$contact->fetch($socpeopleassigned[0]);
if ($result < 0) dol_print_error($db,$contact->error);
}
@@ -781,7 +794,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, array_keys($object->socpeopleassigned), 'socpeopleassigned[]', 1, '', '', 0, 'minwidth200',0, 0, array(), false, 'multiple', 'contactid');
print '
';
print ' ';
print ' ';
@@ -1368,14 +1383,24 @@ if ($id > 0)
// Related contact
print ''.$langs->trans("ActionOnContact").' ';
print '';
- if ($object->contactid > 0)
+
+ if (!empty($object->socpeopleassigned))
{
- print $object->contact->getNomUrl(1);
- if ($object->contactid && $object->type_code == 'AC_TEL')
+ foreach ($object->socpeopleassigned as $cid => $Tab)
{
- 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 39de3a68fb4..6725473ff79 100644
--- a/htdocs/comm/action/class/actioncomm.class.php
+++ b/htdocs/comm/action/class/actioncomm.class.php
@@ -113,6 +113,7 @@ 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
/**
* Object user of owner
* @var User
@@ -345,6 +346,26 @@ class ActionComm extends CommonObject
}
}
+ if (!$error)
+ {
+ if (!empty($this->socpeopleassigned))
+ {
+ foreach ($this->socpeopleassigned as $id => $Tab)
+ {
+ $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 +453,8 @@ class ActionComm extends CommonObject
$objFrom = clone $this;
$this->fetch_optionals();
- $this->fetch_userassigned();
+// $this->fetch_userassigned();
+ $this->fetchResources();
$this->id=0;
@@ -587,6 +609,8 @@ class ActionComm extends CommonObject
$this->fk_element = $obj->fk_element;
$this->elementtype = $obj->elementtype;
+
+ $this->fetchResources();
}
$this->db->free($resql);
}
@@ -600,6 +624,50 @@ 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;
+ $sql.=" AND element_type IN ('user', 'socpeople')";
+ $resql=$this->db->query($sql);
+ if ($resql)
+ {
+ $this->userassigned=array();
+ $this->socpeopleassigned=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->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 +889,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->socpeopleassigned))
+ {
+ foreach (array_keys($this->socpeopleassigned) 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 2708ad17a32..4bc3ca9692f 100644
--- a/htdocs/core/class/html.form.class.php
+++ b/htdocs/core/class/html.form.class.php
@@ -1274,12 +1274,14 @@ 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
* @deprected You can use selectcontacts directly (warning order of param was changed)
*/
- 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;
}
@@ -1299,15 +1301,18 @@ 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');
- $out='';
+ if (empty($htmlid)) $htmlid = $htmlname;
+ $out='';
// On recherche les societes
$sql = "SELECT sp.rowid, sp.lastname, sp.statut, sp.firstname, sp.poste";
@@ -1328,11 +1333,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);
@@ -1342,6 +1347,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);
@@ -1355,7 +1361,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 36fd5135e83..ac4e5680ede 100644
--- a/htdocs/install/upgrade2.php
+++ b/htdocs/install/upgrade2.php
@@ -373,6 +373,15 @@ if (! GETPOST('action','aZ09') || preg_match('/upgrade/i',GETPOST('action','aZ09
{
// No particular code
}
+
+ // Scripts for last version
+ $afterversionarray=explode('.','6.0.9');
+ $beforeversionarray=explode('.','7.0.9');
+ if (versioncompare($versiontoarray,$afterversionarray) >= 0 && versioncompare($versiontoarray,$beforeversionarray) <= 0)
+ {
+ // Migrate contact association
+ migrate_event_assignement_contact($db,$langs,$conf);
+ }
}
// Code executed only if migrate is LAST ONE. Must always be done.
@@ -3786,6 +3795,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 '