From a9521b13f90b49e6a2fb4ace40aadef50f12d1de Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 17 Oct 2020 19:52:23 +0200 Subject: [PATCH] FIX Assignement of event to create when created from view per user. --- htdocs/comm/action/card.php | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/htdocs/comm/action/card.php b/htdocs/comm/action/card.php index cda1d54b38b..74958b35333 100644 --- a/htdocs/comm/action/card.php +++ b/htdocs/comm/action/card.php @@ -71,8 +71,6 @@ $offsetunit = GETPOST('offsetunittype_duration', 'aZ09'); $remindertype = GETPOST('selectremindertype', 'aZ09'); $modelmail = GETPOST('actioncommsendmodel_mail', 'int'); -//var_dump($_POST); exit; - $datep = dol_mktime($fulldayevent ? '00' : $aphour, $fulldayevent ? '00' : $apmin, 0, GETPOST("apmonth", 'int'), GETPOST("apday", 'int'), GETPOST("apyear", 'int')); $datef = dol_mktime($fulldayevent ? '23' : $p2hour, $fulldayevent ? '59' : $p2min, $fulldayevent ? '59' : '0', GETPOST("p2month", 'int'), GETPOST("p2day", 'int'), GETPOST("p2year", 'int')); @@ -111,8 +109,6 @@ if ($id > 0 && $action != 'add') { // fetch optionals attributes and labels $extrafields->fetch_name_optionals_label($object->table_element); -//var_dump($_POST); - // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context $hookmanager->initHooks(array('actioncard', 'globalcard')); @@ -144,7 +140,7 @@ if (empty($reshook) && (GETPOST('removedassigned') || GETPOST('removedassigned') { if ($val['id'] == $idtoremove || $val['id'] == -1) unset($tmpassigneduserids[$key]); } - //var_dump($_POST['removedassigned']);exit; + $_SESSION['assignedtouser'] = json_encode($tmpassigneduserids); $donotclearsession = 1; if ($action == 'add') $action = 'create'; @@ -1076,18 +1072,21 @@ if ($action == 'create') $listofuserid = array(); $listofcontactid = array(); $listofotherid = array(); + if (empty($donotclearsession)) { $assignedtouser = GETPOST("assignedtouser") ?GETPOST("assignedtouser") : (!empty($object->userownerid) && $object->userownerid > 0 ? $object->userownerid : $user->id); if ($assignedtouser) $listofuserid[$assignedtouser] = array('id'=>$assignedtouser, 'mandatory'=>0, 'transparency'=>$object->transparency); // Owner first - $listofuserid[$user->id]['transparency'] = GETPOSTISSET('transparency') ?GETPOST('transparency', 'alpha') : 1; // 1 by default at first init + //$listofuserid[$user->id] = array('id'=>$user->id, 'mandatory'=>0, 'transparency'=>(GETPOSTISSET('transparency') ? GETPOST('transparency', 'alpha') : 1)); // 1 by default at first init + $listofuserid[$assignedtouser]['transparency'] = (GETPOSTISSET('transparency') ? GETPOST('transparency', 'alpha') : 1); // 1 by default at first init $_SESSION['assignedtouser'] = json_encode($listofuserid); } else { if (!empty($_SESSION['assignedtouser'])) { $listofuserid = json_decode($_SESSION['assignedtouser'], true); } - $listofuserid[$user->id]['transparency'] = GETPOSTISSET('transparency') ?GETPOST('transparency', 'alpha') : 0; // 0 by default when refreshing + $firstelem = reset($listofuserid); + if (isset($listofuserid[$firstelem['id']])) $listofuserid[$firstelem['id']]['transparency'] = (GETPOSTISSET('transparency') ? GETPOST('transparency', 'alpha') : 0); // 0 by default when refreshing } print '
'; print $form->select_dolusers_forevent(($action == 'create' ? 'add' : 'update'), 'assignedtouser', 1, '', 0, '', '', 0, 0, 0, 'AND u.statut != 0', 1, $listofuserid, $listofcontactid, $listofotherid); @@ -1950,8 +1949,6 @@ if ($id > 0) /* if ($object->datep != $object->datef && in_array($user->id,array_keys($listofuserid))) { - //var_dump($object->userassigned); - //var_dump($listofuserid); print '
'; print $langs->trans("MyAvailability").': '.(($object->userassigned[$user->id]['transparency'] > 0)?$langs->trans("Busy"):$langs->trans("Available")); // We show nothing if event is assigned to nobody print '
';