New multi contacts on actioncomm

This commit is contained in:
phf 2017-06-06 17:43:22 +02:00
parent bfd6116e5b
commit 711f9696aa
5 changed files with 217 additions and 22 deletions

View File

@ -55,7 +55,7 @@ $langs->load("agenda");
$action=GETPOST('action','alpha'); $action=GETPOST('action','alpha');
$cancel=GETPOST('cancel','alpha'); $cancel=GETPOST('cancel','alpha');
$backtopage=GETPOST('backtopage','alpha'); $backtopage=GETPOST('backtopage','alpha');
$contactid=GETPOST('contactid','int'); $TContactId=GETPOST('TContactId','array');
$origin=GETPOST('origin','alpha'); $origin=GETPOST('origin','alpha');
$originid=GETPOST('originid','int'); $originid=GETPOST('originid','int');
$confirm = GETPOST('confirm', 'alpha'); $confirm = GETPOST('confirm', 'alpha');
@ -188,9 +188,9 @@ if ($action == 'add')
else $backtopage=DOL_URL_ROOT.'/comm/action/index.php'; 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) if ($cancel)
@ -319,6 +319,9 @@ if ($action == 'add')
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), null, 'errors'); 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 // Fill array 'array_options' with data from add form
$ret = $extrafields->setOptionalsFromPost($extralabels,$object); $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
if ($ret < 0) $error++; if ($ret < 0) $error++;
@ -409,7 +412,8 @@ if ($action == 'update')
$object->fulldayevent= GETPOST("fullday")?1:0; $object->fulldayevent= GETPOST("fullday")?1:0;
$object->location = GETPOST('location'); $object->location = GETPOST('location');
$object->socid = GETPOST("socid"); $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->societe->id = $_POST["socid"]; // deprecated
//$object->contact->id = $_POST["contactid"]; // deprecated //$object->contact->id = $_POST["contactid"]; // deprecated
$object->fk_project = GETPOST("projectid",'int'); $object->fk_project = GETPOST("projectid",'int');
@ -594,9 +598,10 @@ if ($action == 'create')
{ {
$contact = new Contact($db); $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); if ($result < 0) dol_print_error($db,$contact->error);
} }
@ -781,7 +786,7 @@ if ($action == 'create')
// Related contact // Related contact
print '<tr><td class="nowrap">'.$langs->trans("ActionOnContact").'</td><td>'; print '<tr><td class="nowrap">'.$langs->trans("ActionOnContact").'</td><td>';
$form->select_contacts(GETPOST('socid','int'), GETPOST('contactid'), 'contactid', 1, '', '', 0, 'minwidth200'); $form->select_contacts(GETPOST('socid','int'), GETPOST('TContactId', 'array'), 'TContactId[]', 1, '', '', 0, 'minwidth200',0, 0, array(), false, 'multiple', 'contactid');
print '</td></tr>'; print '</td></tr>';
@ -880,7 +885,8 @@ if ($id > 0)
$object->fulldayevent= GETPOST("fullday")?1:0; $object->fulldayevent= GETPOST("fullday")?1:0;
$object->location = GETPOST('location'); $object->location = GETPOST('location');
$object->socid = GETPOST("socid"); $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->societe->id = $_POST["socid"]; // deprecated
//$object->contact->id = $_POST["contactid"]; // deprecated //$object->contact->id = $_POST["contactid"]; // deprecated
$object->fk_project = GETPOST("projectid",'int'); $object->fk_project = GETPOST("projectid",'int');
@ -1121,7 +1127,7 @@ if ($id > 0)
// related contact // related contact
print '<tr><td>'.$langs->trans("ActionOnContact").'</td><td>'; print '<tr><td>'.$langs->trans("ActionOnContact").'</td><td>';
print '<div class="maxwidth200onsmartphone">'; print '<div class="maxwidth200onsmartphone">';
$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 '</div>'; print '</div>';
print '</td>'; print '</td>';
print '</tr>'; print '</tr>';
@ -1368,14 +1374,24 @@ if ($id > 0)
// Related contact // Related contact
print '<tr><td>'.$langs->trans("ActionOnContact").'</td>'; print '<tr><td>'.$langs->trans("ActionOnContact").'</td>';
print '<td colspan="3">'; print '<td colspan="3">';
if ($object->contactid > 0)
if (!empty($object->TContactId))
{ {
print $object->contact->getNomUrl(1); foreach ($object->TContactId as $cid)
if ($object->contactid && $object->type_code == 'AC_TEL')
{ {
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 "<br>".dol_print_phone($object->contact->phone_pro); print $contact->getNomUrl(1).'&nbsp;';
if ($object->type_code == 'AC_TEL')
{
if (!empty($contact->phone_pro)) print '('.dol_print_phone($contact->phone_pro).')';
print '<br />';
}
} }
} }
} }

View File

@ -113,6 +113,8 @@ class ActionComm extends CommonObject
var $userownerid; // Id of user owner = fk_user_action into table var $userownerid; // Id of user owner = fk_user_action into table
var $userdoneid; // Id of user done (deprecated) 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 * Object user of owner
* @var User * @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) if (! $error)
{ {
$action='create'; $action='create';
@ -432,7 +454,8 @@ class ActionComm extends CommonObject
$objFrom = clone $this; $objFrom = clone $this;
$this->fetch_optionals(); $this->fetch_optionals();
$this->fetch_userassigned(); // $this->fetch_userassigned();
$this->fetchResources();
$this->id=0; $this->id=0;
@ -587,6 +610,8 @@ class ActionComm extends CommonObject
$this->fk_element = $obj->fk_element; $this->fk_element = $obj->fk_element;
$this->elementtype = $obj->elementtype; $this->elementtype = $obj->elementtype;
$this->fetchResources();
} }
$this->db->free($resql); $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 * Initialize this->userassigned array with list of id of user assigned to event
@ -822,6 +892,29 @@ class ActionComm extends CommonObject
} }
} }
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) if (! $error && ! $notrigger)
{ {
// Call trigger // Call trigger

View File

@ -1253,11 +1253,13 @@ class Form
* @param int $forcecombo Force to use combo box * @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 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 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 * @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; return $this->num;
} }
@ -1276,14 +1278,17 @@ class Form
* @param integer $showsoc Add company into label * @param integer $showsoc Add company into label
* @param int $forcecombo Force to use combo box * @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 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 * @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; global $conf,$langs;
$langs->load('companies'); $langs->load('companies');
if (empty($htmlid)) $htmlid = $htmlname;
$out=''; $out='';
// On recherche les societes // On recherche les societes
@ -1305,11 +1310,11 @@ class Form
if ($conf->use_javascript_ajax && ! $forcecombo && ! $options_only) if ($conf->use_javascript_ajax && ! $forcecombo && ! $options_only)
{ {
include_once DOL_DOCUMENT_ROOT . '/core/lib/ajax.lib.php'; 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; $out.= $comboenhancement;
} }
if ($htmlname != 'none' || $options_only) $out.= '<select class="flat'.($moreclass?' '.$moreclass:'').'" id="'.$htmlname.'" name="'.$htmlname.'">'; if ($htmlname != 'none' || $options_only) $out.= '<select class="flat'.($moreclass?' '.$moreclass:'').'" id="'.$htmlid.'" name="'.$htmlname.'" '.(!empty($moreparam) ? $moreparam : '').'>';
if ($showempty == 1) $out.= '<option value="0"'.($selected=='0'?' selected':'').'></option>'; if ($showempty == 1) $out.= '<option value="0"'.($selected=='0'?' selected':'').'></option>';
if ($showempty == 2) $out.= '<option value="0"'.($selected=='0'?' selected':'').'>'.$langs->trans("Internal").'</option>'; if ($showempty == 2) $out.= '<option value="0"'.($selected=='0'?' selected':'').'>'.$langs->trans("Internal").'</option>';
$num = $this->db->num_rows($resql); $num = $this->db->num_rows($resql);
@ -1319,6 +1324,7 @@ class Form
include_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; include_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
$contactstatic=new Contact($this->db); $contactstatic=new Contact($this->db);
if (!is_array($selected)) $selected = array($selected);
while ($i < $num) while ($i < $num)
{ {
$obj = $this->db->fetch_object($resql); $obj = $this->db->fetch_object($resql);
@ -1332,7 +1338,7 @@ class Form
$disabled=0; $disabled=0;
if (is_array($exclude) && count($exclude) && in_array($obj->rowid,$exclude)) $disabled=1; 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 (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.= '<option value="'.$obj->rowid.'"'; $out.= '<option value="'.$obj->rowid.'"';
if ($disabled) $out.= ' disabled'; if ($disabled) $out.= ' disabled';
@ -1355,7 +1361,7 @@ class Form
} }
else else
{ {
if ($selected == $obj->rowid) if (in_array($obj->rowid, $selected))
{ {
$out.= $contactstatic->getFullName($langs); $out.= $contactstatic->getFullName($langs);
if ($showfunction && $obj->poste) $out.= ' ('.$obj->poste.')'; if ($showfunction && $obj->poste) $out.= ' ('.$obj->poste.')';

View File

@ -438,6 +438,8 @@ if (! GETPOST('action','aZ09') || preg_match('/upgrade/i',GETPOST('action','aZ09
$beforeversionarray=explode('.','6.0.9'); $beforeversionarray=explode('.','6.0.9');
if (versioncompare($versiontoarray,$afterversionarray) >= 0 && versioncompare($versiontoarray,$beforeversionarray) <= 0) 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) // Reload modules (this must be always and only into last targeted version)
$listofmodule=array( $listofmodule=array(
'MAIN_MODULE_USER'=>'newboxdefonly', 'MAIN_MODULE_USER'=>'newboxdefonly',
@ -3813,6 +3815,83 @@ function migrate_event_assignement($db,$langs,$conf)
print '</td></tr>'; print '</td></tr>';
} }
/**
* 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 '<tr><td colspan="4">';
print '<br>';
print '<b>'.$langs->trans('MigrationEventsContact')."</b><br>\n";
$error = 0;
dolibarr_install_syslog("upgrade2::migrate_event_assignement");
$db->begin();
$sqlSelect = "SELECT a.id, a.fk_contact";
$sqlSelect.= " FROM ".MAIN_DB_PREFIX."actioncomm as a";
$sqlSelect.= " LEFT JOIN ".MAIN_DB_PREFIX."actioncomm_resources as ar ON ar.fk_actioncomm = a.id AND ar.element_type = 'socpeople' AND ar.fk_element = a.fk_contact";
$sqlSelect.= " WHERE fk_contact > 0 AND fk_contact NOT IN (SELECT fk_element FROM ".MAIN_DB_PREFIX."actioncomm_resources as ar WHERE ar.fk_actioncomm = a.id AND ar.element_type = 'socpeople')";
$sqlSelect.= " ORDER BY a.id";
//print $sqlSelect;
$resql = $db->query($sqlSelect);
if ($resql)
{
$i = 0;
$num = $db->num_rows($resql);
if ($num)
{
while ($i < $num)
{
$obj = $db->fetch_object($resql);
$sqlUpdate = "INSERT INTO ".MAIN_DB_PREFIX."actioncomm_resources(fk_actioncomm, element_type, fk_element) ";
$sqlUpdate.= "VALUES(".$obj->id.", 'socpeople', ".$obj->fk_contact.")";
$result=$db->query($sqlUpdate);
if (! $result)
{
$error++;
dol_print_error($db);
}
print ". ";
$i++;
}
}
else
{
print $langs->trans('AlreadyDone')."<br>\n";
}
if (! $error)
{
$db->commit();
}
else
{
$db->rollback();
}
}
else
{
dol_print_error($db);
$db->rollback();
}
print '</td></tr>';
}
/** /**
* Migrate to add entity value into llx_societe_remise * Migrate to add entity value into llx_societe_remise
* *

View File

@ -191,6 +191,7 @@ MigrationActioncommElement=Update data on actions
MigrationPaymentMode=Data migration for payment mode MigrationPaymentMode=Data migration for payment mode
MigrationCategorieAssociation=Migration of categories MigrationCategorieAssociation=Migration of categories
MigrationEvents=Migration of events to add event owner into assignement table MigrationEvents=Migration of events to add event owner into assignement table
MigrationEventsContact=Migration of events to add event contact into assignement table
MigrationRemiseEntity=Update entity field value of llx_societe_remise MigrationRemiseEntity=Update entity field value of llx_societe_remise
MigrationRemiseExceptEntity=Update entity field value of llx_societe_remise_except MigrationRemiseExceptEntity=Update entity field value of llx_societe_remise_except
MigrationReloadModule=Reload module %s MigrationReloadModule=Reload module %s