Merge pull request #6961 from atm-ph/new_event_with_multi_contact
New multi contacts on actioncomm
This commit is contained in:
commit
fd5cb736ce
@ -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 '<tr><td class="nowrap">'.$langs->trans("ActionOnContact").'</td><td>';
|
||||
print $form->selectcontacts(GETPOST('socid','int'), GETPOST('contactid'), 'contactid', 1, '', '', 0, 'minwidth300');
|
||||
echo $form->selectcontacts(GETPOST('socid','int'), GETPOST('socpeopleassigned', 'array'), 'socpeopleassigned[]', 1, '', '', 0, 'minwidth200',0, 0, array(), false, 'multiple', 'contactid');
|
||||
print '</td></tr>';
|
||||
|
||||
|
||||
@ -876,6 +889,8 @@ if ($id > 0)
|
||||
$object->fulldayevent= GETPOST("fullday")?1:0;
|
||||
$object->location = GETPOST('location');
|
||||
$object->socid = GETPOST("socid");
|
||||
$socpeopleassigned = GETPOST("socpeopleassigned",'array');
|
||||
foreach ($socpeopleassigned as $id) $object->socpeopleassigned[$id] = array('id' => $id);
|
||||
$object->contactid = GETPOST("contactid",'int');
|
||||
$object->fk_project = GETPOST("projectid",'int');
|
||||
|
||||
@ -1122,7 +1137,7 @@ if ($id > 0)
|
||||
// related contact
|
||||
print '<tr><td>'.$langs->trans("ActionOnContact").'</td><td>';
|
||||
print '<div class="maxwidth200onsmartphone">';
|
||||
$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 '</div>';
|
||||
print '</td>';
|
||||
print '</tr>';
|
||||
@ -1368,14 +1383,24 @@ if ($id > 0)
|
||||
// Related contact
|
||||
print '<tr><td>'.$langs->trans("ActionOnContact").'</td>';
|
||||
print '<td colspan="3">';
|
||||
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 "<br>".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 '<br />';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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)
|
||||
{
|
||||
|
||||
@ -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.= '<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 == 2) $out.= '<option value="0"'.($selected=='0'?' selected':'').'>'.$langs->trans("Internal").'</option>';
|
||||
$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.= '<option value="'.$obj->rowid.'"';
|
||||
if ($disabled) $out.= ' disabled';
|
||||
@ -1378,7 +1384,7 @@ class Form
|
||||
}
|
||||
else
|
||||
{
|
||||
if ($selected == $obj->rowid)
|
||||
if (in_array($obj->rowid, $selected))
|
||||
{
|
||||
$out.= $contactstatic->getFullName($langs);
|
||||
if ($showfunction && $obj->poste) $out.= ' ('.$obj->poste.')';
|
||||
|
||||
@ -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 '</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
|
||||
*
|
||||
|
||||
@ -191,6 +191,7 @@ MigrationActioncommElement=Update data on actions
|
||||
MigrationPaymentMode=Data migration for payment mode
|
||||
MigrationCategorieAssociation=Migration of categories
|
||||
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
|
||||
MigrationRemiseExceptEntity=Update entity field value of llx_societe_remise_except
|
||||
MigrationReloadModule=Reload module %s
|
||||
|
||||
Loading…
Reference in New Issue
Block a user