diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php
index 4ada3c368d0..cc67030ccf6 100644
--- a/htdocs/core/class/commonobject.class.php
+++ b/htdocs/core/class/commonobject.class.php
@@ -970,7 +970,7 @@ abstract class CommonObject
* @param int|string $type_contact Type of contact (code or id). Must be id or code found into table llx_c_type_contact. For example: SALESREPFOLL
* @param string $source external=Contact extern (llx_socpeople), internal=Contact intern (llx_user)
* @param int $notrigger Disable all triggers
- * @return int <0 if KO, >0 if OK
+ * @return int <0 if KO, 0 if already added, >0 if OK
*/
public function add_contact($fk_socpeople, $type_contact, $source = 'external', $notrigger = 0)
{
@@ -1075,7 +1075,9 @@ abstract class CommonObject
return -1;
}
}
- } else return 0;
+ } else {
+ return 0;
+ }
}
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php
index 7fbff101859..4284b009019 100644
--- a/htdocs/core/class/html.form.class.php
+++ b/htdocs/core/class/html.form.class.php
@@ -4308,7 +4308,7 @@ class Form
* @param string $question Question
* @param string $action Action
* @param array|string $formquestion An array with complementary inputs to add into forms: array(array('label'=> ,'type'=> , 'size'=>, 'morecss'=>, 'moreattr'=>))
- * type can be 'hidden', 'text', 'password', 'checkbox', 'radio', 'date', 'morecss', ...
+ * type can be 'hidden', 'text', 'password', 'checkbox', 'radio', 'date', 'morecss', 'other' or 'onecolumn'...
* @param string $selectedchoice '' or 'no', or 'yes' or '1' or '0'
* @param int|string $useajax 0=No, 1=Yes, 2=Yes but submit page with &confirm=no if choice is No, 'xxx'=Yes and preoutput confirm box with div id=dialog-confirm-xxx
* @param int|string $height Force height of box (0 = auto)
@@ -4422,6 +4422,8 @@ class Form
$moreonecolumn .= '
'."\n";
+ } else {
+ $more .= 'Error type '.$input['type'].' for the confirm box is not a supported type';
}
}
}
@@ -4449,16 +4451,24 @@ class Form
}
$pageyes = $page.(preg_match('/\?/', $page) ? '&' : '?').'action='.$action.'&confirm=yes';
$pageno = ($useajax == 2 ? $page.(preg_match('/\?/', $page) ? '&' : '?').'confirm=no' : '');
+
// Add input fields into list of fields to read during submit (inputok and inputko)
- if (is_array($formquestion))
- {
- foreach ($formquestion as $key => $input)
- {
+ if (is_array($formquestion)) {
+ foreach ($formquestion as $key => $input) {
//print "xx ".$key." rr ".is_array($input)." \n";
- if (is_array($input) && isset($input['name'])) array_push($inputok, $input['name']);
+ // Add name of fields to propagate with the GET when submitting the form with button OK.
+ if (is_array($input) && isset($input['name'])) {
+ if (strpos($input['name'], ',') > 0) {
+ $inputok = array_merge($inputok, explode(',', $input['name']));
+ } else {
+ array_push($inputok, $input['name']);
+ }
+ }
+ // Add name of fields to propagate with the GET when submitting the form with button KO.
if (isset($input['inputko']) && $input['inputko'] == 1) array_push($inputko, $input['name']);
}
}
+
// Show JQuery confirm box.
$formconfirm .= '
';
if (is_array($formquestion) && !empty($formquestion['text'])) {
diff --git a/htdocs/core/class/html.formcompany.class.php b/htdocs/core/class/html.formcompany.class.php
index 93b8f5391e7..e84a6716134 100644
--- a/htdocs/core/class/html.formcompany.class.php
+++ b/htdocs/core/class/html.formcompany.class.php
@@ -758,9 +758,10 @@ class FormCompany extends Form
* @param int $showempty 1=Add en empty line
* @param string $morecss Add more css to select component
* @param int $output 0=return HTML, 1= direct print
+ * @param int $forcehidetooltip Force hide tooltip for admin
* @return void
*/
- public function selectTypeContact($object, $selected, $htmlname = 'type', $source = 'internal', $sortorder = 'position', $showempty = 0, $morecss = '', $output = 1)
+ public function selectTypeContact($object, $selected, $htmlname = 'type', $source = 'internal', $sortorder = 'position', $showempty = 0, $morecss = '', $output = 1, $forcehidetooltip = 0)
{
global $user, $langs;
$out = '';
@@ -777,7 +778,7 @@ class FormCompany extends Form
$out .= '>'.$value.'';
}
$out .= "";
- if ($user->admin) $out .= ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
+ if ($user->admin && empty($forcehidetooltip)) $out .= ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
$out .= ajax_combobox($htmlname);
diff --git a/htdocs/projet/contact.php b/htdocs/projet/contact.php
index 4df3b63b199..f4581da7cc9 100644
--- a/htdocs/projet/contact.php
+++ b/htdocs/projet/contact.php
@@ -24,6 +24,7 @@
require '../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
+require_once DOL_DOCUMENT_ROOT.'/projet/class/task.class.php';
require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
@@ -53,10 +54,91 @@ $result = restrictedArea($user, 'projet', $id, 'projet&project');
$hookmanager->initHooks(array('projectcontactcard', 'globalcard'));
+
/*
* Actions
*/
+// Test if we can add contact to the tasks at the same times, if not or not required, make a redirect
+$formconfirmtoaddtasks = '';
+if ($action == 'addcontact') {
+ $form = new Form($db);
+
+ $source=GETPOST("source", 'aZ09');
+
+ $taskstatic = new Task($db);
+ $task_array = $taskstatic->getTasksArray(0, 0, $object->id, 0, 0);
+ $nbTasks = count($task_array);
+
+ //If no task avaiblable, redirec to to add confirm
+ $type_to = (GETPOST('typecontact') ? 'typecontact='.GETPOST('typecontact') : 'type='.GETPOST('type'));
+ $personToAffect = (GETPOST('userid') ? GETPOST('userid', 'int') : GETPOST('contactid', 'int'));
+ $affect_to = (GETPOST('userid') ? 'userid='.$personToAffect : 'contactid='.$personToAffect);
+ $url_redirect='?id='.$object->id.'&'.$affect_to.'&'.$type_to.'&source='.$source;
+
+ if (empty($conf->global->PROJECT_HIDE_TASKS) || $nbTasks > 0) {
+ $text = $langs->trans('AddPersonToTask');
+ $textbody = $text.' ('.$langs->trans("SelectAll").')';
+ $formquestion = array('text' => $textbody);
+
+ $task_to_affect = array();
+ foreach ($task_array as $task) {
+ $task_already_affected=false;
+ $personsLinked = $task->liste_contact(-1, $source);
+ if (!is_array($personsLinked) && coun($personsLinked) < 0) {
+ setEventMessage($object->error, 'errors');
+ } else {
+ foreach ($personsLinked as $person) {
+ if ($person['id']==$personToAffect) {
+ $task_already_affected = true;
+ break;
+ }
+ }
+ if (!$task_already_affected) {
+ $task_to_affect[$task->id] = $task->id;
+ }
+ }
+ }
+
+ if (empty($task_to_affect)) {
+ $action = 'addcontact_confirm';
+ } else {
+ $formcompany = new FormCompany($db);
+ foreach ($task_array as $task) {
+ $key = $task->id;
+ $val = $task->ref . ' '.dol_trunc($task->label);
+ $formquestion[] = array(
+ 'type' => 'other',
+ 'name' => 'person_'.$key.',person_role_'.$key,
+ 'label' => '