Skip to content

Commit

Permalink
Close Dolibarr#27774 new contact in project
Browse files Browse the repository at this point in the history
  • Loading branch information
Hystepik committed Feb 1, 2024
1 parent eee2955 commit 022243b
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 33 deletions.
27 changes: 27 additions & 0 deletions htdocs/core/tpl/contacts.tpl.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,33 @@
<?php
}

if ($module == 'project') {
?>
<form class="tagtr impair nohover" action="<?php echo $_SERVER["PHP_SELF"].'?id='.$object->id; ?>" method="POST">
<input type="hidden" name="token" value="<?php echo newToken(); ?>" />
<input type="hidden" name="id" value="<?php echo $object->id; ?>" />
<input type="hidden" name="action" value="addcontact" />
<input type="hidden" name="source" value="internal" />
<input type="hidden" name="page_y" value="" />
<?php if (!empty($withproject)) {
print '<input type="hidden" name="withproject" value="'.$withproject.'">';
} ?>
<div class="tagtd"><?php echo $conf->global->MAIN_INFO_SOCIETE_NOM; ?></div>
<!-- <div class="nowrap tagtd"><?php echo img_object('', 'group').' '.$langs->trans("Groups"); ?></div> -->
<div class="tagtd maxwidthonsmartphone"><?php echo img_object('', 'group', 'class="pictofixedwidth"').$form->select_dolgroups(0, 'groupid', 0, '', 0, '', array(), '0', false, 'minwidth100imp widthcentpercentminusxx maxwidth400'); ?></div>
<div class="tagtd maxwidthonsmartphone">
<?php
$tmpobject = $object;
if (($object->element == 'shipping' || $object->element == 'reception') && is_object($objectsrc)) {
$tmpobject = $objectsrc;
}
$formcompany->selectTypeContact($tmpobject, '', 'type', 'internal', 'position', 0, 'minwidth125imp widthcentpercentminusx maxwidth400'); ?></div>
<div class="tagtd">&nbsp;</div>
<div class="tagtd center"><input type="submit" class="button small" value="<?php echo $langs->trans("Add"); ?>"></div>
</form>
<?php
}

if (empty($hideaddcontactforthirdparty)) {
?>

Expand Down
2 changes: 2 additions & 0 deletions htdocs/langs/en_US/errors.lang
Original file line number Diff line number Diff line change
Expand Up @@ -408,3 +408,5 @@ TotalAmountEmpty=Total Amount Empty
FailedToFoundTheConversionRateForInvoice=Failed to found the conversion rate for invoice
ThisIdNotDefined=$this->id not defined
OperNotDefined=Oper not defined
ErrorThisContactXIsAlreadyDefinedAsThisType=%s is already defined as contact for this type.
ErrorThisGroupIsAlreadyDefinedAsThisType=The contacts with this group are already defined as contact for this type.
111 changes: 78 additions & 33 deletions htdocs/projet/contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,50 +165,83 @@

$contactid = (GETPOST('userid') ? GETPOST('userid', 'int') : GETPOST('contactid', 'int'));
$typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));

if (! ($contactid > 0)) {
$groupid = GETPOSTINT('groupid');
$contactarray = array();
$errorgroup = 0;
$errorgrouparray = array();

if ($groupid > 0) {
require_once DOL_DOCUMENT_ROOT.'/user/class/usergroup.class.php';
$usergroup = new UserGroup($db);
$result = $usergroup->fetch($groupid);
if ($result > 0) {
$tmpcontactarray = $usergroup->listUsersForGroup();
if ($contactarray <= 0) {
$error++;
} else {
foreach ($tmpcontactarray as $tmpuser) {
$contactarray[] = $tmpuser->id;
}
}
} else {
$error++;
}
} elseif (! ($contactid > 0)) {
$error++;
$langs->load("errors");
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Contact")), null, 'errors');
} else {
$contactarray[] = $contactid;
}

$result = 0;
$result = $object->fetch($id);

if (!$error && $result > 0 && $id > 0) {
$result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));

if ($result == 0) {
$langs->load("errors");
setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors');
} elseif ($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');
foreach ($contactarray as $key => $contactid) {
$result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));

if ($result == 0) {
if ($groupid > 0) {
$errorgroup++;
$errorgrouparray[] = $contactid;
} else {
$langs->load("errors");
setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors');
}
} elseif ($result < 0) {
if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
if ($groupid > 0) {
$errorgroup++;
$errorgrouparray[] = $contactid;
} else {
$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) && GETPOST('person_'.$task_id, 'san_alpha')) {
$tasksToAffect = new Task($db);
$result=$tasksToAffect->fetch($task_id);
if ($result < 0) {
setEventMessages($tasksToAffect->error, null, 'errors');
} else {
$result = $tasksToAffect->add_contact($contactid, GETPOST('person_role_'.$task_id), GETPOST("source", 'aZ09'));
$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) && GETPOST('person_'.$task_id, 'san_alpha')) {
$tasksToAffect = new Task($db);
$result=$tasksToAffect->fetch($task_id);
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');
setEventMessages($tasksToAffect->error, null, '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');
}
}
}
}
Expand All @@ -217,6 +250,18 @@
}
}
}
if ($errorgroup > 0) {
$langs->load("errors");
if ($errorgroup == count($contactarray)) {
setEventMessages($langs->trans("ErrorThisGroupIsAlreadyDefinedAsThisType"), null, 'errors');
} else {
$tmpuser = new User($db);
foreach ($errorgrouparray as $key => $value) {
$tmpuser->fetch($value);
setEventMessages($langs->trans("ErrorThisContactXIsAlreadyDefinedAsThisType", dolGetFirstLastname($tmpuser->firstname, $tmpuser->lastname)), null, 'errors');
}
}
}

if ($result >= 0) {
header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
Expand Down

0 comments on commit 022243b

Please sign in to comment.