diff --git a/htdocs/core/class/html.formcompany.class.php b/htdocs/core/class/html.formcompany.class.php
index 0b4c4e499e3..c26df50bd53 100644
--- a/htdocs/core/class/html.formcompany.class.php
+++ b/htdocs/core/class/html.formcompany.class.php
@@ -757,30 +757,36 @@ class FormCompany extends Form
* @param string $sortorder Sort criteria ('position', 'code', ...)
* @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
* @return void
*/
- public function selectTypeContact($object, $selected, $htmlname = 'type', $source = 'internal', $sortorder = 'position', $showempty = 0, $morecss = '')
+ public function selectTypeContact($object, $selected, $htmlname = 'type', $source = 'internal', $sortorder = 'position', $showempty = 0, $morecss = '', $output=1)
{
global $user, $langs;
-
+ $out = '';
if (is_object($object) && method_exists($object, 'liste_type_contact'))
{
$lesTypes = $object->liste_type_contact($source, $sortorder, 0, 1);
- print '";
+ if ($user->admin) $out .= ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
- print ajax_combobox($htmlname);
+ $out .= ajax_combobox($htmlname);
- print "\n";
+ $out .= "\n";
+ }
+ if (empty($output)) {
+ return $out;
+ } else {
+ print $out;
}
}
diff --git a/htdocs/langs/en_US/projects.lang b/htdocs/langs/en_US/projects.lang
index f5f6bf3dd9d..f5456c330f8 100644
--- a/htdocs/langs/en_US/projects.lang
+++ b/htdocs/langs/en_US/projects.lang
@@ -266,4 +266,5 @@ NewInvoice=New invoice
OneLinePerTask=One line per task
OneLinePerPeriod=One line per period
RefTaskParent=Ref. Parent Task
-ProfitIsCalculatedWith=Profit is calculated using
\ No newline at end of file
+ProfitIsCalculatedWith=Profit is calculated using
+AddPersonToTask=Add also to tasks
diff --git a/htdocs/projet/contact.php b/htdocs/projet/contact.php
index e298adcd40c..a8531b4983b 100644
--- a/htdocs/projet/contact.php
+++ b/htdocs/projet/contact.php
@@ -58,7 +58,7 @@ $hookmanager->initHooks(array('projectcontactcard', 'globalcard'));
*/
// Add new contact
-if ($action == 'addcontact' && $user->rights->projet->creer)
+if ($action == 'addcontact_confirm' && $user->rights->projet->creer)
{
$result = 0;
$result = $object->fetch($id);
@@ -68,20 +68,48 @@ if ($action == 'addcontact' && $user->rights->projet->creer)
$contactid = (GETPOST('userid') ? GETPOST('userid', 'int') : GETPOST('contactid', 'int'));
$typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
$result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));
+ if ( $result < 0) {
+ if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS')
+ {
+ $langs->load("errors");
+ setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors');
+ } else {
+ setEventMessages($object->error, $object->errors, 'errors');
+ }
+ }
+
+ $affecttotask=GETPOST('tasksavailable','intcomma');
+ if (!empty($affecttotask)) {
+ require_once DOL_DOCUMENT_ROOT.'/projet/class/task.class.php';
+ $task_to_affect = explode(',',$affecttotask);
+ if (!empty($task_to_affect)) {
+ foreach($task_to_affect as $task_id) {
+ if (GETPOSTISSET('person_'.$task_id,'san_alpha') && GETPOST('person_'.$task_id,'san_alpha')=='on') {
+ $tasksToAffect = new Task($db);
+ $result=$tasksToAffect->fetch($task_id);
+ if ($result < 0) {
+ setEventMessage($tasksToAffect->error,'errors');
+ } else {
+ $result = $tasksToAffect->add_contact($contactid, GETPOST('person_role_'.$task_id), GETPOST("source", 'aZ09'));
+ if ($result < 0) {
+ if ($tasksToAffect->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
+ $langs->load("errors");
+ setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors');
+ } else {
+ setEventMessages($tasksToAffect->error, $tasksToAffect->errors, 'errors');
+ }
+ }
+ }
+ }
+ }
+ }
+ }
}
if ($result >= 0)
{
header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
exit;
- } else {
- if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS')
- {
- $langs->load("errors");
- setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors');
- } else {
- setEventMessages($object->error, $object->errors, 'errors');
- }
}
}
@@ -145,6 +173,87 @@ if ($id > 0 || !empty($ref))
$head = project_prepare_head($object);
print dol_get_fiche_head($head, 'contact', $langs->trans("Project"), -1, ($object->public ? 'projectpub' : 'project'));
+ $formconfirm = '';
+
+ // Test if we can add contact to task at the same times
+ if ($action == 'addcontact') {
+
+ $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');
+ $formquestion = array('text' => $text);
+
+ $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->ref . ' '.dol_trunc($task->label);
+ }
+ }
+ }
+ if (empty($task_to_affect)) {
+ //If person is already add to all task (how it can happen ????, anyway), redirect to to add confirm
+ header("Location: ".$_SERVER['PHP_SELF'].$url_redirect);
+ exit;
+ } else {
+ foreach($task_to_affect as $key=>$val) {
+ $formquestion[] = array('type' => 'checkbox', 'name' => 'person_'.$key, 'label' => $val, 'value' => true);
+ $formquestion[] = array(
+ 'type' => 'other',
+ 'name' => 'person_role_'. $key,
+ 'label' => $langs->trans("ContactType"),
+ 'value' => $formcompany->selectTypeContact($taskstatic, '', 'person_role_' . $key, $source, 'position', 0, 'minwidth100imp', 0));
+ }
+ $formquestion[] = array('type'=> 'other', 'name'=>'tasksavailable', 'label'=>'', 'value' => '');
+ }
+
+ $formconfirm = $form->formconfirm($_SERVER['PHP_SELF'] . $url_redirect, $text, '', 'addcontact_confirm', $formquestion, '', 1, 300, 590);
+ $formconfirm .='
+ ';
+ } else {
+ //If no task avaiblable, redirec to to add confirm
+ header("Location: ".$_SERVER['PHP_SELF'].$url_redirect.'&action=addcontact_confirm');
+ exit;
+ }
+ }
+
+ // Call Hook formConfirm
+ $parameters = array('formConfirm' => $formconfirm);
+ $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
+ if (empty($reshook)) $formconfirm .= $hookmanager->resPrint;
+ elseif ($reshook > 0) $formconfirm = $hookmanager->resPrint;
+
+ // Print form confirm
+ print $formconfirm;
// Project card