Add missing call of hook doActions in projet/contact.php

This commit is contained in:
Laurent Destailleur 2023-02-02 21:11:52 +01:00
parent e9c43718ba
commit af61006b8b

View File

@ -69,134 +69,142 @@ $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 ($personToAffect > 0 && (empty($conf->global->PROJECT_HIDE_TASKS) || $nbTasks > 0)) {
$text = $langs->trans('AddPersonToTask');
$textbody = $text.' (<a href="#" class="selectall">'.$langs->trans("SelectAll").'</a>)';
$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) && count($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' => '<input type="checkbox" class="flat'.(in_array($key, $task_to_affect) ? ' taskcheckboxes"' : '" checked disabled').' id="person_'.$key.'" name="person_'.$key.'" value="1"> <label for="person_'.$key.'">'.$val.'<label>',
'value' => $formcompany->selectTypeContact($taskstatic, '', 'person_role_'.$key, $source, 'position', 0, 'minwidth100imp', 0, 1)
);
}
$formquestion[] = array('type'=> 'other', 'name'=>'tasksavailable', 'label'=>'', 'value' => '<input type="hidden" id="tasksavailable" name="tasksavailable" value="'.implode(',', array_keys($task_to_affect)).'">');
}
$formconfirmtoaddtasks = $form->formconfirm($_SERVER['PHP_SELF'] . $url_redirect, $text, '', 'addcontact_confirm', $formquestion, '', 1, 300, 590);
$formconfirmtoaddtasks .='
<script>
$(document).ready(function() {
var saveprop = false;
$(".selectall").click(function(){
console.log("We click on select all with "+saveprop);
if (!saveprop) {
$(".taskcheckboxes").prop("checked", true);
saveprop = true;
} else {
$(".taskcheckboxes").prop("checked", false);
saveprop = false;
}
});
});
</script>';
} else {
$action = 'addcontact_confirm';
}
$parameters = array('id'=>$id);
$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action);
if ($reshook < 0) {
setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
}
// Add new contact
if ($action == 'addcontact_confirm' && $user->rights->projet->creer) {
$contactid = (GETPOST('userid') ? GETPOST('userid', 'int') : GETPOST('contactid', 'int'));
$typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
if (empty($reshook)) {
// 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);
if (! ($contactid > 0)) {
$error++;
$langs->load("errors");
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Contact")), null, 'errors');
$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 ($personToAffect > 0 && (empty($conf->global->PROJECT_HIDE_TASKS) || $nbTasks > 0)) {
$text = $langs->trans('AddPersonToTask');
$textbody = $text.' (<a href="#" class="selectall">'.$langs->trans("SelectAll").'</a>)';
$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) && count($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' => '<input type="checkbox" class="flat'.(in_array($key, $task_to_affect) ? ' taskcheckboxes"' : '" checked disabled').' id="person_'.$key.'" name="person_'.$key.'" value="1"> <label for="person_'.$key.'">'.$val.'<label>',
'value' => $formcompany->selectTypeContact($taskstatic, '', 'person_role_'.$key, $source, 'position', 0, 'minwidth100imp', 0, 1)
);
}
$formquestion[] = array('type'=> 'other', 'name'=>'tasksavailable', 'label'=>'', 'value' => '<input type="hidden" id="tasksavailable" name="tasksavailable" value="'.implode(',', array_keys($task_to_affect)).'">');
}
$formconfirmtoaddtasks = $form->formconfirm($_SERVER['PHP_SELF'] . $url_redirect, $text, '', 'addcontact_confirm', $formquestion, '', 1, 300, 590);
$formconfirmtoaddtasks .='
<script>
$(document).ready(function() {
var saveprop = false;
$(".selectall").click(function(){
console.log("We click on select all with "+saveprop);
if (!saveprop) {
$(".taskcheckboxes").prop("checked", true);
saveprop = true;
} else {
$(".taskcheckboxes").prop("checked", false);
saveprop = false;
}
});
});
</script>';
} else {
$action = 'addcontact_confirm';
}
}
$result = 0;
$result = $object->fetch($id);
// Add new contact
if ($action == 'addcontact_confirm' && $user->rights->projet->creer) {
$contactid = (GETPOST('userid') ? GETPOST('userid', 'int') : GETPOST('contactid', 'int'));
$typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
if (!$error && $result > 0 && $id > 0) {
$result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));
if ($result == 0) {
if (! ($contactid > 0)) {
$error++;
$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');
}
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Contact")), null, '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'));
$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');
}
}
$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');
}
}
}
}
@ -204,37 +212,36 @@ if ($action == 'addcontact_confirm' && $user->rights->projet->creer) {
}
}
}
if ($result >= 0) {
header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
exit;
}
}
if ($result >= 0) {
header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
exit;
// Change contact's status
if ($action == 'swapstatut' && $user->rights->projet->creer) {
if ($object->fetch($id)) {
$result = $object->swapContactStatus(GETPOST('ligne', 'int'));
} else {
dol_print_error($db);
}
}
// Delete a contact
if (($action == 'deleteline' || $action == 'deletecontact') && $user->rights->projet->creer) {
$object->fetch($id);
$result = $object->delete_contact(GETPOST("lineid", 'int'));
if ($result >= 0) {
header("Location: contact.php?id=".$object->id);
exit;
} else {
dol_print_error($db);
}
}
}
// Change contact's status
if ($action == 'swapstatut' && $user->rights->projet->creer) {
if ($object->fetch($id)) {
$result = $object->swapContactStatus(GETPOST('ligne', 'int'));
} else {
dol_print_error($db);
}
}
// Delete a contact
if (($action == 'deleteline' || $action == 'deletecontact') && $user->rights->projet->creer) {
$object->fetch($id);
$result = $object->delete_contact(GETPOST("lineid", 'int'));
if ($result >= 0) {
header("Location: contact.php?id=".$object->id);
exit;
} else {
dol_print_error($db);
}
}
/*
* View