Add missing call of hook doActions in projet/contact.php
This commit is contained in:
parent
e9c43718ba
commit
af61006b8b
@ -69,134 +69,142 @@ $hookmanager->initHooks(array('projectcontactcard', 'globalcard'));
|
|||||||
* Actions
|
* Actions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// Test if we can add contact to the tasks at the same times, if not or not required, make a redirect
|
$parameters = array('id'=>$id);
|
||||||
$formconfirmtoaddtasks = '';
|
$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action);
|
||||||
if ($action == 'addcontact') {
|
if ($reshook < 0) {
|
||||||
$form = new Form($db);
|
setEventMessages($hookmanager->error, $hookmanager->errors, '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';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add new contact
|
if (empty($reshook)) {
|
||||||
if ($action == 'addcontact_confirm' && $user->rights->projet->creer) {
|
// Test if we can add contact to the tasks at the same times, if not or not required, make a redirect
|
||||||
$contactid = (GETPOST('userid') ? GETPOST('userid', 'int') : GETPOST('contactid', 'int'));
|
$formconfirmtoaddtasks = '';
|
||||||
$typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
|
if ($action == 'addcontact') {
|
||||||
|
$form = new Form($db);
|
||||||
|
|
||||||
if (! ($contactid > 0)) {
|
$source=GETPOST("source", 'aZ09');
|
||||||
$error++;
|
|
||||||
$langs->load("errors");
|
$taskstatic = new Task($db);
|
||||||
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Contact")), null, 'errors');
|
$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;
|
// Add new contact
|
||||||
$result = $object->fetch($id);
|
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) {
|
if (! ($contactid > 0)) {
|
||||||
$result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));
|
$error++;
|
||||||
|
|
||||||
if ($result == 0) {
|
|
||||||
$langs->load("errors");
|
$langs->load("errors");
|
||||||
setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors');
|
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Contact")), 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');
|
$result = 0;
|
||||||
if (!empty($affecttotask)) {
|
$result = $object->fetch($id);
|
||||||
require_once DOL_DOCUMENT_ROOT.'/projet/class/task.class.php';
|
|
||||||
$task_to_affect = explode(',', $affecttotask);
|
if (!$error && $result > 0 && $id > 0) {
|
||||||
if (!empty($task_to_affect)) {
|
$result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));
|
||||||
foreach ($task_to_affect as $task_id) {
|
|
||||||
if (GETPOSTISSET('person_'.$task_id) && GETPOST('person_'.$task_id, 'san_alpha')) {
|
if ($result == 0) {
|
||||||
$tasksToAffect = new Task($db);
|
$langs->load("errors");
|
||||||
$result=$tasksToAffect->fetch($task_id);
|
setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors');
|
||||||
if ($result < 0) {
|
} elseif ($result < 0) {
|
||||||
setEventMessages($tasksToAffect->error, null, 'errors');
|
if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
|
||||||
} else {
|
$langs->load("errors");
|
||||||
$result = $tasksToAffect->add_contact($contactid, GETPOST('person_role_'.$task_id), GETPOST("source", 'aZ09'));
|
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 ($result < 0) {
|
||||||
if ($tasksToAffect->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
|
setEventMessages($tasksToAffect->error, null, 'errors');
|
||||||
$langs->load("errors");
|
} else {
|
||||||
setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors');
|
$result = $tasksToAffect->add_contact($contactid, GETPOST('person_role_'.$task_id), GETPOST("source", 'aZ09'));
|
||||||
} else {
|
if ($result < 0) {
|
||||||
setEventMessages($tasksToAffect->error, $tasksToAffect->errors, 'errors');
|
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) {
|
// Change contact's status
|
||||||
header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
|
if ($action == 'swapstatut' && $user->rights->projet->creer) {
|
||||||
exit;
|
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
|
* View
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user