NEW: When add contact/user to Project, ask to also affect on project task
This commit is contained in:
parent
6a24da54a1
commit
0ed084d585
@ -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 '<select class="flat valignmiddle'.($morecss ? ' '.$morecss : '').'" name="'.$htmlname.'" id="'.$htmlname.'">';
|
||||
if ($showempty) print '<option value="0"></option>';
|
||||
$out .= '<select class="flat valignmiddle'.($morecss ? ' '.$morecss : '').'" name="'.$htmlname.'" id="'.$htmlname.'">';
|
||||
if ($showempty) $out .= '<option value="0"></option>';
|
||||
foreach ($lesTypes as $key=>$value)
|
||||
{
|
||||
print '<option value="'.$key.'"';
|
||||
if ($key == $selected) print ' selected';
|
||||
print '>'.$value.'</option>';
|
||||
$out .= '<option value="'.$key.'"';
|
||||
if ($key == $selected) $out .= ' selected';
|
||||
$out .= '>'.$value.'</option>';
|
||||
}
|
||||
print "</select>";
|
||||
if ($user->admin) print ' '.info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
|
||||
$out .= "</select>";
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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
|
||||
ProfitIsCalculatedWith=Profit is calculated using
|
||||
AddPersonToTask=Add also to tasks
|
||||
|
||||
@ -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' => '<input type="hidden" id="tasksavailable" name="tasksavailable" value="'.implode(',',array_keys($task_to_affect)).'">');
|
||||
}
|
||||
|
||||
$formconfirm = $form->formconfirm($_SERVER['PHP_SELF'] . $url_redirect, $text, '', 'addcontact_confirm', $formquestion, '', 1, 300, 590);
|
||||
$formconfirm .='
|
||||
<script>
|
||||
$(document).ready(function(){
|
||||
$("input:checkbox[name^=\'person_\']").change(function(){
|
||||
let taskid=$(this).attr("name").replace("person_","");
|
||||
$("#person_role_"+taskid).parents("div.tagtr").toggle();
|
||||
});
|
||||
});
|
||||
</script>';
|
||||
} 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
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user