* Copyright (C) 2012-2015 Laurent Destailleur * Copyright (C) 2024 MDW * Copyright (C) 2024 Frédéric France * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ /** * \file htdocs/projet/contact.php * \ingroup project * \brief List of all contacts of a project */ // Load Dolibarr environment 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'; if (isModEnabled('category')) { require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; } /** * @var Conf $conf * @var DoliDB $db * @var HookManager $hookmanager * @var Translate $langs * @var User $user */ // Load translation files required by the page $langsLoad = array('projects', 'companies'); if (isModEnabled('eventorganization')) { $langsLoad[] = 'eventorganization'; } $langs->loadLangs($langsLoad); $id = GETPOSTINT('id'); $ref = GETPOST('ref', 'alpha'); $lineid = GETPOSTINT('lineid'); $socid = GETPOSTINT('socid'); $action = GETPOST('action', 'aZ09'); $mine = GETPOST('mode') == 'mine' ? 1 : 0; //if (! $user->rights->projet->all->lire) $mine=1; // Special for projects $object = new Project($db); include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be 'include', not 'include_once' if (getDolGlobalString('PROJECT_ALLOW_COMMENT_ON_PROJECT') && method_exists($object, 'fetchComments') && empty($object->comments)) { $object->fetchComments(); } // Security check $socid = 0; $hookmanager->initHooks(array('projectcontactcard', 'globalcard')); //if ($user->socid > 0) $socid = $user->socid; // For external user, no check is done on company because readability is managed by public status of project and assignment. $result = restrictedArea($user, 'projet', $id, 'projet&project'); $permissiontoadd = $user->hasRight('projet', 'creer'); /* * Actions */ $error = 0; $parameters = array('id' => $id); $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); if ($reshook < 0) { setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); } 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' && $permissiontoadd) { $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 available, redirec to to add confirm $type_to = (GETPOST('typecontact') ? 'typecontact='.GETPOST('typecontact') : 'type='.GETPOST('type')); $personToAffect = (GETPOST('userid') ? GETPOSTINT('userid') : GETPOSTINT('contactid')); $affect_to = (GETPOST('userid') ? 'userid='.$personToAffect : 'contactid='.$personToAffect); $url_redirect = '?id='.$object->id.'&'.$affect_to.'&'.$type_to.'&source='.$source; if ($personToAffect > 0 && (!getDolGlobalString('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)) { // When liste_contact() does not return an array, it's an error. 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' => '