diff --git a/ajax/event_creation.php b/ajax/event_creation.php new file mode 100644 index 0000000..97c02f3 --- /dev/null +++ b/ajax/event_creation.php @@ -0,0 +1,312 @@ + + * + * 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 dolipad/ajax/event_creation.php + * \brief manage event_creation + */ + +if (!defined('NOTOKENRENEWAL')) { + define('NOTOKENRENEWAL', '1'); // Disables token renewal +} +if (!defined('NOREQUIREMENU')) { + define('NOREQUIREMENU', '1'); +} +if (!defined('NOREQUIREHTML')) { + define('NOREQUIREHTML', '1'); +} +if (!defined('NOREQUIREAJAX')) { + define('NOREQUIREAJAX', '1'); +} + + +// Load Dolibarr environment +$res = 0; +// Try main.inc.php into web root known defined into CONTEXT_DOCUMENT_ROOT (not always defined) +if (!$res && !empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) { + $res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"] . "/main.inc.php"; +} +// Try main.inc.php into web root detected using web root calculated from SCRIPT_FILENAME +$tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME']; +$tmp2 = realpath(__FILE__); +$i = strlen($tmp) - 1; +$j = strlen($tmp2) - 1; +while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) { + $i--; + $j--; +} +if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1)) . "/main.inc.php")) { + $res = @include substr($tmp, 0, ($i + 1)) . "/main.inc.php"; +} +if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1))) . "/main.inc.php")) { + $res = @include dirname(substr($tmp, 0, ($i + 1))) . "/main.inc.php"; +} +// Try main.inc.php using relative path +if (!$res && file_exists("../main.inc.php")) { + $res = @include "../main.inc.php"; +} +if (!$res && file_exists("../../main.inc.php")) { + $res = @include "../../main.inc.php"; +} +if (!$res && file_exists("../../../main.inc.php")) { + $res = @include "../../../main.inc.php"; +} +if (!$res) { + die("Include of main fails"); +} + +require_once DOL_DOCUMENT_ROOT . '/comm/action/class/actioncomm.class.php'; +require_once DOL_DOCUMENT_ROOT . '/comm/action/class/cactioncomm.class.php'; +require_once DOL_DOCUMENT_ROOT . '/fichinter/class/fichinter.class.php'; + +$action = GETPOST('action', 'aZ09'); +$createFromElementId = GETPOST('createFromElementId', 'int'); +$createFromElementType = GETPOST('createFromElementType', 'alpha'); +$typeEvent = GETPOST('typeEvent', 'alpha'); +$evtId = GETPOST('evtId', 'int'); +$userAffected = GETPOST('userAffected', 'none'); +$userOwnerId = GETPOST('userOwnerId', 'int'); +$dtStYear = GETPOST('dtStYear', 'int'); +$dtStMonth = GETPOST('dtStMonth', 'int'); +$dtStDay = GETPOST('dtStDay', 'int'); +$dtStHour = GETPOST('dtStHour', 'int'); +$dtStMin = GETPOST('dtStMin', 'int'); +$dtEndYear = GETPOST('dtEndYear', 'int'); +$dtEndMonth = GETPOST('dtEndMonth', 'int'); +$dtEndDay = GETPOST('dtEndDay', 'int'); +$dtEndHour = GETPOST('dtEndHour', 'int'); +$dtEndMin = GETPOST('dtEndMin', 'int'); + +$userAffected=json_decode(urldecode($userAffected), true); +$userAffectedIds=[]; +if (!empty($userAffected)) { + foreach ($userAffected as $valu) { + if ($valu!==$userOwnerId) { + $userAffectedIds[$valu] = array('id' => $valu, 'transparency' => 0); + } + } +} + +$datep = dol_mktime($dtStHour, $dtStMin, 0, $dtStMonth, $dtStDay, $dtStYear); +$datef = dol_mktime($dtEndHour, $dtEndMin, 0, $dtEndMonth, $dtEndDay, $dtEndYear); + +$langs->load('dolipad@dolipad'); + +// Security check +if (!empty($user->socid)) { + $socid = $user->socid; +} +dol_syslog(__FILE__ . ' action=' . $action, LOG_DEBUG); + +top_httphead(); +$ret = []; +$errors = []; + +$actionLog = ' Ajax baes action:' . $action; +$actionLog .= ' createFromElementType:' . $createFromElementType; +$actionLog .= ' createFromElementId:' . $createFromElementId; +$actionLog .= ' typeEvent:' . $typeEvent; +$actionLog .= ' evtId:' . $evtId; +$actionLog .= ' $user->id:' . $user->id; +$actionLog .= ' userAffected:' . $userAffected; +$actionLog .= ' userOwnerId:' . $userOwnerId; + + +if ($action == 'createEvent') { + $evtDescription=''; + $evtSocId=''; + + if (empty($typeEvent)) { + $typeEvent = dol_getIdFromCode($db, 'AC_OTH', 'c_actioncomm'); + } + + if ($createFromElementType=="fichinter") { + $inter = new Fichinter($db); + $result = $inter->fetch($createFromElementId); + if ($result < 0) { + setEventMessages($inter->error, $inter->errors, 'errors'); + } + $result = $inter->fetch_thirdparty(); + if ($result < 0) { + setEventMessages($inter->error, $inter->errors, 'errors'); + } + + if (!$user->hasRight('agenda', 'allactions', 'create') || empty($inter->id)) { + print json_encode(array($langs->transnoentities('DlpdHowDoYouGetHere'))); + dol_syslog($actionLog . '$inter->id=' . $inter->id . ' Error=DlpdHowDoYouGetHere', LOG_ERR); + print json_encode($errors); + header('HTTP/1.1 500 Internal Server Error'); + exit(); + } + + $evtDescription=$inter->description; + $evtSocId=$inter->socid; + } else { + $langs->load('commercial'); + $cactioncomm = new CActionComm($db); + $result = $cactioncomm->fetch($typeEvent); + if ($result<0) { + $errors[] = $cactioncomm->error; + dol_syslog($actionLog . ' Error=' . var_export($errors, true), LOG_ERR); + print json_encode($errors); + header('HTTP/1.1 500 Internal Server Error'); + exit(); + } + $evtDescription=$langs->trans("Action".$cactioncomm->code); + } + + $event = new ActionComm($db); + $event->userownerid = $userOwnerId; + $event->userassigned = $userAffectedIds; + $event->label = $evtDescription; + $event->type_code = $typeEvent; + $event->percentage = 0; + $event->socid = $evtSocId; + $event->datep = $datep; + $event->datef = $datef; + $event->fk_element = $createFromElementId; + $event->elementtype = $createFromElementType; + $result = $event->create($user); + if ($result < 0) { + $errors = array_merge($errors, $event->errors); + $errors[] = $event->error; + dol_syslog($actionLog . ' Error=' . var_export($errors, true), LOG_ERR); + print json_encode($errors); + header('HTTP/1.1 500 Internal Server Error'); + exit(); + } + $ret = [$event->id]; + $_SESSION["multi_evt"][]=$event->id; + + dol_include_once('/buildingmanagement/class/buildingmanagementhelpers.class.php'); + if (!empty($event->id) && class_exists('BuildingManagementHelpers') && $createFromElementType=="fichinter") { + $bmHelpers = new BuildingManagementHelpers($db); + $resultBuilding = $bmHelpers->getResidenceAndBuilding($inter->element, $inter->id); + if (!is_array($result) && $result < 0) { + $errors = array_merge($errors, $bmHelpers->errors); + $errors[] = $bmHelpers->error; + dol_syslog($actionLog . ' Error=' . var_export($errors, true), LOG_ERR); + print json_encode($errors); + header('HTTP/1.1 500 Internal Server Error'); + exit(); + } + + $result = $bmHelpers->setResidenceAndBuilding($event, $resultBuilding['residenceid'], $resultBuilding['buildingid']); + if ($result < 0) { + $errors = array_merge($errors, $bmHelpers->errors); + $errors[] = $bmHelpers->error; + dol_syslog($actionLog . ' Error=' . var_export($errors, true), LOG_ERR); + print json_encode($errors); + header('HTTP/1.1 500 Internal Server Error'); + exit(); + } + } +} + +if ($action=='checkAvailability') { + if (!empty($userAffectedIds)) { + $warningOccupy = []; + + foreach ($userAffectedIds as $uid => $data) { + $sql = 'SELECT DISTINCT a.id as evtid, a.datep as dtst, a.datep2 as dtend, a.label as evtlabel'; + $sql .= ' FROM ' . $db->prefix() . 'actioncomm as a'; + $sql .= ' LEFT JOIN ' . $db->prefix() . 'actioncomm_resources as ar ON a.id=ar.fk_actioncomm'; + $sql .= ' WHERE ((a.fk_user_action=' . (int) $uid . ')'; + $sql .= ' OR (ar.element_type="user" AND ar.fk_element=' . (int) $uid . '))'; + $sql .= ' AND "' . $db->idate($datep) . '"<=a.datep2 '; + $sql .= ' AND a.datep<="' . $db->idate($datef) . '"'; + $sql .= ' AND a.fk_action<>' . (int) dol_getIdFromCode($db, 'AC_OTH_AUTO', 'c_actioncomm'); + //In case where we were call + if (!empty($evtId)) { + $sql .= ' AND a.id<>' . (int) $evtId; + } + + $resql = $db->query($sql); + if (!$resql) { + $errors = array_merge($errors, $db->lasterror); + $errors[] = $db->lasterror; + dol_syslog($actionLog . ' Error=' . var_export($errors, true), LOG_ERR); + print json_encode($errors); + header('HTTP/1.1 500 Internal Server Error'); + exit(); + } else { + while ($obj = $db->fetch_object($resql)) { + $usrTgt = new User($db); + $usrTgt->fetch($uid); + $evtTgt = new ActionComm($db); + $evtTgt->fetch($obj->evtid); + $warningOccupy[] = $langs->transnoentities('DldpUserOccupyByEvent', $usrTgt->getFullName($langs), $evtTgt->getNomUrl(0, 0, '', '', 0, 1)); + } + $ret = $warningOccupy; + } + } + } +} + +if ($action=='getMultiEvtData') { + if (!empty($_SESSION['multi_evt'])) { + foreach ($_SESSION['multi_evt'] as $idEvent) { + $event = new ActionComm($db); + $resultFetch=$event->fetch($idEvent); + if ($resultFetch<0) { + $errors = array_merge($errors, $event->errors); + $errors[] = $event->error; + dol_syslog($actionLog . ' Error=' . var_export($errors, true), LOG_ERR); + print json_encode($errors); + header('HTTP/1.1 500 Internal Server Error'); + exit(); + } + unset($event->db); + $userOwner = new User($db); + $resultFetch = $userOwner->fetch($event->userownerid); + if ($resultFetch < 0) { + $errors = array_merge($errors, $userOwner->errors); + $errors[] = $userOwner->error; + dol_syslog($actionLog . ' Error=' . var_export($errors, true), LOG_ERR); + print json_encode($errors); + header('HTTP/1.1 500 Internal Server Error'); + exit(); + } + $ret[$event->id]=array( + 'id'=>$event->id, + 'dated'=>dol_print_date($event->datep, 'dayhour'), + 'datef'=>dol_print_date($event->datef, 'dayhour'), + 'usersAssign'=>array(), + 'userOwner'=>$userOwner->getFullName($langs) + ); + if (!empty($event->userassigned)) { + foreach ($event->userassigned as $userAssignId=>$dataUsrAssign) { + if ($dataUsrAssign['id']!=$event->userownerid) { + $userAssign = new User($db); + $resultFetch = $userAssign->fetch($userAssignId); + if ($resultFetch < 0) { + $errors = array_merge($errors, $userAssign->errors); + $errors[] = $userAssign->error; + dol_syslog($actionLog . ' Error=' . var_export($errors, true), LOG_ERR); + print json_encode($errors); + header('HTTP/1.1 500 Internal Server Error'); + exit(); + } + $ret[$event->id]['usersAssign'][$userAssign->id] = $userAssign->getFullName($langs); + } + } + } + } + } +} + +print json_encode($ret); diff --git a/comm/action/confirm_eventmulticreation.php b/comm/action/confirm_eventmulticreation.php new file mode 100644 index 0000000..46e973f --- /dev/null +++ b/comm/action/confirm_eventmulticreation.php @@ -0,0 +1,562 @@ + + * Copyright (C) 2003 Eric Seigne + * Copyright (C) 2004-2014 Laurent Destailleur + * Copyright (C) 2005-2012 Regis Houssin + * Copyright (C) 2011 Juanjo Menent + * Copyright (C) 2014 Cedric GROSS + * Copyright (C) 2018-2019 Frédéric France + * Copyright (C) 2023 Florian HENRY + * + * 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 /dolipad/comm/action/confirrm_eventmulticreation.php + * \ingroup dolipad + * \brief manage MultiEvent Création + */ + +//if (! defined('NOREQUIREDB')) define('NOREQUIREDB', '1'); // Do not create database handler $db +//if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER', '1'); // Do not load object $user +//if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC', '1'); // Do not load object $mysoc +//if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN', '1'); // Do not load object $langs +//if (! defined('NOSCANGETFORINJECTION')) define('NOSCANGETFORINJECTION', '1'); // Do not check injection attack on GET parameters +//if (! defined('NOSCANPOSTFORINJECTION')) define('NOSCANPOSTFORINJECTION', '1'); // Do not check injection attack on POST parameters +//if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK', '1'); // Do not check CSRF attack (test on referer + on token). +//if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', '1'); // Do not roll the Anti CSRF token (used if MAIN_SECURITY_CSRF_WITH_TOKEN is on) +//if (! defined('NOSTYLECHECK')) define('NOSTYLECHECK', '1'); // Do not check style html tag into posted data +//if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU', '1'); // If there is no need to load and show top and left menu +//if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML', '1'); // If we don't need to load the html.form.class.php +//if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX', '1'); // Do not load ajax.lib.php library +//if (! defined("NOLOGIN")) define("NOLOGIN", '1'); // If this page is public (can be called outside logged session). This include the NOIPCHECK too. +//if (! defined('NOIPCHECK')) define('NOIPCHECK', '1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip +//if (! defined("MAIN_LANG_DEFAULT")) define('MAIN_LANG_DEFAULT', 'auto'); // Force lang to a particular value +//if (! defined("MAIN_AUTHENTICATION_MODE")) define('MAIN_AUTHENTICATION_MODE', 'aloginmodule'); // Force authentication handler +//if (! defined("NOREDIRECTBYMAINTOLOGIN")) define('NOREDIRECTBYMAINTOLOGIN', 1); // The main.inc.php does not make a redirect if not logged, instead show simple error message +//if (! defined("FORCECSP")) define('FORCECSP', 'none'); // Disable all Content Security Policies +//if (! defined('CSRFCHECK_WITH_TOKEN')) define('CSRFCHECK_WITH_TOKEN', '1'); // Force use of CSRF protection with tokens even for GET +//if (! defined('NOBROWSERNOTIF')) define('NOBROWSERNOTIF', '1'); // Disable browser notification +//if (! defined('NOSESSION')) define('NOSESSION', '1'); // Disable session + + +// Load Dolibarr environment +$res = 0; +// Try main.inc.php into web root known defined into CONTEXT_DOCUMENT_ROOT (not always defined) +if (!$res && !empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) { + $res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"] . "/main.inc.php"; +} +// Try main.inc.php into web root detected using web root calculated from SCRIPT_FILENAME +$tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME']; +$tmp2 = realpath(__FILE__); +$i = strlen($tmp) - 1; +$j = strlen($tmp2) - 1; +while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) { + $i--; + $j--; +} +if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1)) . "/main.inc.php")) { + $res = @include substr($tmp, 0, ($i + 1)) . "/main.inc.php"; +} +if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1))) . "/main.inc.php")) { + $res = @include dirname(substr($tmp, 0, ($i + 1))) . "/main.inc.php"; +} +// Try main.inc.php using relative path +if (!$res && file_exists("../main.inc.php")) { + $res = @include "../main.inc.php"; +} +if (!$res && file_exists("../../main.inc.php")) { + $res = @include "../../main.inc.php"; +} +if (!$res && file_exists("../../../main.inc.php")) { + $res = @include "../../../main.inc.php"; +} +if (!$res && file_exists("../../../../main.inc.php")) { + $res = @include "../../../../main.inc.php"; +} +if (!$res && file_exists("../../../../main.inc.php")) { + $res = @include "../../../../main.inc.php"; +} +if (!$res) { + die("Include of main fails"); +} + +require_once DOL_DOCUMENT_ROOT . '/comm/action/class/actioncomm.class.php'; +require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php'; +require_once DOL_DOCUMENT_ROOT . '/user/class/usergroup.class.php'; +require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php'; +require_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php'; +dol_include_once('/buildingmanagement/class/buildingmanagementhelpers.class.php'); + +$event = new ActionComm($db); + +$extrafields = new ExtraFields($db); +$extrafields->fetch_name_optionals_label($event->table_element); + + +$action = GETPOST('action', 'aZ09'); + +$create_from_element_id = GETPOST('create_from_element_id', 'int'); +$create_from_element_type = GETPOST('create_from_element_type', 'alpha'); + +if ($create_from_element_type == "fichinter") { + require_once DOL_DOCUMENT_ROOT . '/fichinter/class/fichinter.class.php'; + $inter = new Fichinter($db); + $result = $inter->fetch($create_from_element_id); + if ($result < 0) { + setEventMessages($inter->error, $inter->errors, 'errors'); + } + if (empty($label) && !empty($inter->id)) { + $label = $inter->description; + } +} + +if (empty(isModEnabled('dolipad'))) accessforbidden(); +if (empty($user->hasRight('agenda', 'myactions', 'read'))) { + accessforbidden(); +} +$result = restrictedArea($user, 'agenda', 0, '', 'myactions'); + +$optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print') + +// Load translation files required by the page +$langs->loadLangs(array('users', 'agenda', 'other', 'commercial')); + +// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context +$hookmanager->initHooks(array('dolipad_multievt_confirm')); + +$eventArray = _getAndSortEventArray($create_from_element_type, $create_from_element_id); + +$allEmployeesArray = array(); +$userGroupTech = new UserGroup($db); +$userGroupTech->id = getDolGlobalInt('DOLIPAD_USERGROUP_TECH'); +$resultUsersTech = $userGroupTech->listUsersForGroup('u.statut=1'); +if (!is_array($resultUsersTech) && $resultUsersTech < 0) { + setEventMessages($userGroupTech->error, $userGroupTech->errors, 'errors'); +} else { + if (!empty($resultUsersTech)) { + foreach ($resultUsersTech as $userTech) { + $allEmployeesArray[$userTech->id] = $userTech->getFullName($langs); + } + } +} + +/* + * Actions + */ +$parameters = array(); +$parameters['eventArray'] = $eventArray; +$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks +if ($reshook < 0) { + setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); +} +if (empty($reshook)) { + $error = 0; + if ($action == 'update') { + $eventArray = _getAndSortEventArray($create_from_element_type, $create_from_element_id); + foreach ($eventArray as $index => $dataEvent) { + $evtUpd = new ActionComm($db); + $evtUpd->fetch($dataEvent->id); + + $cactioncomm = new CActionComm($db); + $resultFetch = $cactioncomm->fetch(GETPOST("actioncode", 'alpha')); + if ($resultFetch < 0) { + setEventMessages($cactioncomm->error, $cactioncomm->errors, 'errors'); + } + $evtUpd->type_id = $cactioncomm->id; + $evtUpd->type_code = $cactioncomm->code; + $evtUpd->label = GETPOST('label_' . $evtUpd->id, 'alpha'); + + $evtUpd->datep = dol_mktime( + GETPOST('eventdtstart_' . $evtUpd->id . 'hour', 'int'), + GETPOST('eventdtstart_' . $evtUpd->id . 'min', 'int'), + GETPOST('eventdtstart_' . $evtUpd->id . 'sec', 'int'), + GETPOST('eventdtstart_' . $evtUpd->id . 'month', 'int'), + GETPOST('eventdtstart_' . $evtUpd->id . 'day', 'int'), + GETPOST('eventdtstart_' . $evtUpd->id . 'year', 'int')); + $evtUpd->datef = dol_mktime( + GETPOST('eventdtend_' . $evtUpd->id . 'hour', 'int'), + GETPOST('eventdtend_' . $evtUpd->id . 'min', 'int'), + GETPOST('eventdtend_' . $evtUpd->id . 'sec', 'int'), + GETPOST('eventdtend_' . $evtUpd->id . 'month', 'int'), + GETPOST('eventdtend_' . $evtUpd->id . 'day', 'int'), + GETPOST('eventdtend_' . $evtUpd->id . 'year', 'int')); + $evtUpd->userownerid = GETPOST('usrownerid_' . $evtUpd->id, 'int'); + $userAssign = GETPOST('employees_' . $evtUpd->id, 'array'); + $evtUpd->userassigned = array(); + if (!empty($userAssign)) { + foreach ($userAssign as $userIdAssign) { + $evtUpd->userassigned[$userIdAssign] = array('id' => $userIdAssign); + } + } + $evtUpd->array_options['options_dolipad_note_tech'] = GETPOST('dolipad_note_tech_' . $evtUpd->id, 'alpha'); + if (GETPOST('dolipad_tech_close_force_' . $evtUpd->id)) { + $evtUpd->array_options['options_dolipad_tech_close'] = GETPOST('close_technik_' . $evtUpd->id, 'int'); + $evtUpd->array_options['options_dolipad_tech_close_force'] = 1; + } else { + $evtUpd->array_options['options_dolipad_tech_close_force'] = 0; + } + if (GETPOST('dolipad_is_intercombi_' . $evtUpd->id)) { + $evtUpd->array_options['options_dolipad_is_intercombi'] = 1; + $evtUpd->array_options['options_dolipad_intercombi_place'] = GETPOST('dolipad_intercombi_place_' . $evtUpd->id, 'int');; + } else { + $evtUpd->array_options['options_dolipad_is_intercombi'] = 0; + $evtUpd->array_options['options_dolipad_intercombi_place'] = 0; + } + if (GETPOST('dolipad_is_baes_' . $evtUpd->id)) { + $evtUpd->array_options['options_dolipad_is_baes'] = 1; + } else { + $evtUpd->array_options['options_dolipad_is_baes'] = 0; + } + + $resultUpd = $evtUpd->update($user); + if ($resultUpd < 0) { + setEventMessages($evtUpd->error, $evtUpd->errors, 'errors'); + } + } + //We resort the event array arrocding date to apply close technic "all first lines are Partiel last is Total) if not force to something else + $eventArray = _getAndSortEventArray($create_from_element_type, $create_from_element_id); + $evtCntUseForCloseTechnik = 0; + foreach ($eventArray as $index => $dataEvent) { + $evtCntUseForCloseTechnik++; + $evtUpd = new ActionComm($db); + $evtUpd->fetch($dataEvent->id); + $force_close = GETPOST('dolipad_tech_close_force_' . $evtUpd->id); + if (empty($force_close)) { + $evtUpd->array_options['options_dolipad_tech_close'] = ($evtCntUseForCloseTechnik == count($eventArray) ? 2 : 1); + } + + $resultUpd = $evtUpd->update($user); + if ($resultUpd < 0) { + setEventMessages($evtUpd->error, $evtUpd->errors, 'errors'); + } + } + + if (GETPOSTISSET('endplannif')) { + $_SESSION["multi_evt"] = array(); + if ($create_from_element_type == "fichinter") { + header("Location: " . dol_buildpath('fichinter/card.php', 1) . '?id=' . $create_from_element_id); + exit; + } else { + header("Location: " . dol_buildpath('dolipad/comm/action/peruser_eventcreation.php', 1)); + exit; + } + } + } +} + +$reshook = $hookmanager->executeHooks('beforeConfirmMultiEvtCreation', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks +if ($reshook < 0) { + setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); +} + +$form = new Form($db); +$formactions = new FormActions($db); + +$help_url = ''; +llxHeader('', $langs->trans("DlpdMultiEvtCreation"), $help_url, '', 0, 0, array(), array()); + +$placesInterCombi = []; +if (class_exists('BuildingManagementHelpers')) { + $bmHelpers = new BuildingManagementHelpers($db); + $resultInfoBuilding = $bmHelpers->getResidenceAndBuilding($create_from_element_type, $create_from_element_id); + if (!is_array($resultInfoBuilding) && $resultInfoBuilding < 0) { + setEventMessages($bmHelpers->error, $bmHelpers->errors, 'errors'); + } else { + if (!empty($resultInfoBuilding['residenceid'])) { + dol_include_once('/dolipad/class/dolipadintercombiplace.class.php'); + $combiPlace = new DolipadInterCombiPlace($db); + dol_include_once('/dolipad/class/dolipadintercombilisting.class.php'); + $listing = new DolipadInterCombiListing($db); + $sqlListRes = 'SELECT p.rowid,p.label FROM ' . $db->prefix() . $combiPlace->table_element . ' as p'; + $sqlListRes .= ' INNER JOIN ' . $db->prefix() . $listing->table_element . ' as l ON l.fk_dolipadintercombiplace=p.rowid '; + $sqlListRes .= ' AND l.status=' . $listing::STATUS_ONPLAN; + $sqlListRes .= ' WHERE p.element_id=' . $resultInfoBuilding['residenceid'] . ' AND p.element_type=\'residence\''; + $resqlListRes = $db->query($sqlListRes); + if (!$resqlListRes) { + setEventMessage($db->lasterror, 'errors'); + } else { + while ($objListRes = $db->fetch_object($resqlListRes)) { + $placesInterCombi[$objListRes->rowid] = $objListRes->label; + } + } + } + } +} + +print ''; + + +if (empty(getDolGlobalString('DOLIPAD_TYPE_EVENT_CREATION_INTER_MULTI')) && $create_from_element_type == "fichinter") { + setEventMessages(null, $langs->trans('DlpdConfNotCompleteEventCreationMulti'), 'errors'); +} + +//$param .= "&maxprint=" . urlencode($maxprint); + +print load_fiche_titre($langs->trans("DlpdMultiEvtCreation"), '', 'title_agenda'); + +print '
'; +print ''; +print ''; + +if (!empty($create_from_element_id)) { + print ''; +} +if (!empty($create_from_element_type)) { + print ''; +} + +print '' . "\n"; + +if (!empty(getDolGlobalString('DOLIPAD_USERGROUP_TECH'))) { + print ''; +} + +print '
' . $langs->trans("Type") . ''; + $default = getDolGlobalString('DOLIPAD_TYPE_EVENT_CREATION_INTER_MULTI'); + print img_picto($langs->trans("ActionType"), 'square', 'class="fawidth30 inline-block" style="color: #ddd;"'); + print $formactions->select_type_actions(GETPOSTISSET("actioncode") ? GETPOST("actioncode", 'aZ09') : $default, "actioncode", "systemauto", 0, -1, 0, 1); + print '
' . "\n"; + +print '' . "\n"; +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; +if (!empty($placesInterCombi)) { + print ''; +} +print ''; +print ''; + + +$evtCntUseForCloseTechnik = 0; + +//TODO may be use to manage disabled user selection in employees selector for now not manage +//$multievtselectuser='multievtselectuser'; +$multievtselectuser = ''; + +foreach ($eventArray as $index => $dataEvent) { + $evtCntUseForCloseTechnik++; + + print ''; + + print ''; + + print ''; + + print ''; + + print ''; + + print ''; + + print ''; + + print ''; + + print ''; + + if (!empty($placesInterCombi)) { + print ''; + } + + print ''; + + print ''; +} + +print '
'; +print $langs->trans('Ref'); +print ''; +print $langs->trans('Label'); +print ''; +print $langs->trans("DateActionStart"); +print ''; +print $langs->trans("DateActionEnd"); +print ''; +print $langs->trans("Owner"); +print ''; +print $langs->trans("DlpdTeam"); +print ''; +print $langs->trans("DlpdNoteTech"); +print ''; +print $langs->trans("DlpdTechCloseForce") . '/' . $langs->trans("DlpdTechClose"); +print ''; + print $langs->trans("DlpdInterCombi"); + print ''; +print $langs->trans("DlpdBAES"); +print '
'; + print $dataEvent->getNomUrl(1, -1); + print ''; + print $form->selectDate($dataEvent->datep, "eventdtstart_" . $dataEvent->id, 1, 1); + print ''; + print $form->selectDate($dataEvent->datef, "eventdtend_" . $dataEvent->id, 1, 1); + print ''; + print $form->select_dolusers($dataEvent->userownerid, 'usrownerid_' . $dataEvent->id, 0, null, 0, array_keys($allEmployeesArray), '', 0, 0, 0, '', 0, '', $multievtselectuser); + print ''; + $usersTeam = []; + if (!empty($dataEvent->userassigned)) { + foreach ($dataEvent->userassigned as $userAssignId => $dataUsrAssign) { + if ($dataUsrAssign['id'] != $dataEvent->userownerid) { + $usersTeam[$dataUsrAssign['id']] = $dataUsrAssign['id']; + } + } + } + print $form->multiselectarray('employees_' . $dataEvent->id, $allEmployeesArray, $usersTeam, '', 0, '', 0, '100%'); + print ''; + print ''; + print ''; + $checked = ''; + if (!empty($dataEvent->array_options['options_dolipad_tech_close_force'])) { + $checked = 'checked="checked"'; + $defaultValue = $dataEvent->array_options['options_dolipad_tech_close']; + } else { + $defaultValue = ($evtCntUseForCloseTechnik == count($eventArray) ? 2 : 1); + } + print ''; + + + print $form->selectarray("close_technik_" . $dataEvent->id, $extrafields->attributes[$dataEvent->table_element]['param']['dolipad_tech_close']['options'], $defaultValue, 0, 0, 0, '', 0, 0, (empty($dataEvent->array_options['options_dolipad_tech_close_force'])), '', 'minwidth200'); + print ''; + $checked = ''; + if (!empty($dataEvent->array_options['options_dolipad_is_intercombi'])) { + $checked = 'checked="checked"'; + $defaultValue = $dataEvent->array_options['dolipad_intercombi_place']; + } else { + $placesInterCombiKeys = array_keys($placesInterCombi); + $defaultValue = reset($placesInterCombiKeys); + } + print ''; + print $form->selectarray("dolipad_intercombi_place_" . $dataEvent->id, $placesInterCombi, $defaultValue, 0, 0, 0, '', 0, 0, (empty($dataEvent->array_options['options_dolipad_is_intercombi'])), '', 'minwidth200 ', 0); + print ''; + $checked = ''; + if (!empty($dataEvent->array_options['options_dolipad_is_baes'])) { + $checked = 'checked="checked"'; + } + print ''; + print '
'; + +print dol_get_fiche_end(); +print '
'; +print''; +print''; +print '
'; + +print '
'; + +// End of page +llxFooter(); +$db->close(); + + +/** + * Sort Method for event display + * @param $evt1 ActionComm Evt + * @param $evt2 ActionComm Evt + * @return int + */ +function _sortByDateStart($evt1, $evt2) +{ + if ($evt1->datep == $evt2->datep) { + return 0; + } + return ($evt1->datep < $evt2->datep) ? -1 : 1; +} + +/** + * Get Event data from session + * @param $create_from_element_type String Element type + * @param $create_from_element_id Int Element Id + * @return array + */ +function _getAndSortEventArray($create_from_element_type = '', $create_from_element_id = 0) +{ + global $db; + + $eventArray = []; + + foreach ($_SESSION["multi_evt"] as $idEvent) { + $event = new ActionComm($db); + $resultFetch = $event->fetch($idEvent); + if ($resultFetch < 0) { + setEventMessages($event->error, $event->errors, 'errors'); + } + if (!empty($create_from_element_type) && !empty($create_from_element_id)) { + if ($create_from_element_type == $event->elementtype + && $create_from_element_id == $event->elementid) { + $eventArray[] = $event; + } + } else { + $eventArray[] = $event; + } + } + + usort($eventArray, "_sortByDateStart"); + + return $eventArray; +} diff --git a/comm/action/peruser_eventcreation.php b/comm/action/peruser_eventcreation.php new file mode 100644 index 0000000..64fd5fe --- /dev/null +++ b/comm/action/peruser_eventcreation.php @@ -0,0 +1,2384 @@ + + * Copyright (C) 2003 Eric Seigne + * Copyright (C) 2004-2014 Laurent Destailleur + * Copyright (C) 2005-2012 Regis Houssin + * Copyright (C) 2011 Juanjo Menent + * Copyright (C) 2014 Cedric GROSS + * Copyright (C) 2018-2019 Frédéric France + * Copyright (C) 2023 Florian HENRY + * + * 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 /dolipad/comm/action/peruser_eventcreation.php + * \ingroup dolipad + * \brief Copy of peruser comm/action/peruser.php to manage 4 case per days cell and manage event creation on cell selection + */ + +//if (! defined('NOREQUIREDB')) define('NOREQUIREDB', '1'); // Do not create database handler $db +//if (! defined('NOREQUIREUSER')) define('NOREQUIREUSER', '1'); // Do not load object $user +//if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC', '1'); // Do not load object $mysoc +//if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN', '1'); // Do not load object $langs +//if (! defined('NOSCANGETFORINJECTION')) define('NOSCANGETFORINJECTION', '1'); // Do not check injection attack on GET parameters +//if (! defined('NOSCANPOSTFORINJECTION')) define('NOSCANPOSTFORINJECTION', '1'); // Do not check injection attack on POST parameters +//if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK', '1'); // Do not check CSRF attack (test on referer + on token). +//if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', '1'); // Do not roll the Anti CSRF token (used if MAIN_SECURITY_CSRF_WITH_TOKEN is on) +//if (! defined('NOSTYLECHECK')) define('NOSTYLECHECK', '1'); // Do not check style html tag into posted data +//if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU', '1'); // If there is no need to load and show top and left menu +//if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML', '1'); // If we don't need to load the html.form.class.php +//if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX', '1'); // Do not load ajax.lib.php library +//if (! defined("NOLOGIN")) define("NOLOGIN", '1'); // If this page is public (can be called outside logged session). This include the NOIPCHECK too. +//if (! defined('NOIPCHECK')) define('NOIPCHECK', '1'); // Do not check IP defined into conf $dolibarr_main_restrict_ip +//if (! defined("MAIN_LANG_DEFAULT")) define('MAIN_LANG_DEFAULT', 'auto'); // Force lang to a particular value +//if (! defined("MAIN_AUTHENTICATION_MODE")) define('MAIN_AUTHENTICATION_MODE', 'aloginmodule'); // Force authentication handler +//if (! defined("NOREDIRECTBYMAINTOLOGIN")) define('NOREDIRECTBYMAINTOLOGIN', 1); // The main.inc.php does not make a redirect if not logged, instead show simple error message +//if (! defined("FORCECSP")) define('FORCECSP', 'none'); // Disable all Content Security Policies +//if (! defined('CSRFCHECK_WITH_TOKEN')) define('CSRFCHECK_WITH_TOKEN', '1'); // Force use of CSRF protection with tokens even for GET +//if (! defined('NOBROWSERNOTIF')) define('NOBROWSERNOTIF', '1'); // Disable browser notification +//if (! defined('NOSESSION')) define('NOSESSION', '1'); // Disable session + + +// Load Dolibarr environment +$res = 0; +// Try main.inc.php into web root known defined into CONTEXT_DOCUMENT_ROOT (not always defined) +if (!$res && !empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) { + $res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"] . "/main.inc.php"; +} +// Try main.inc.php into web root detected using web root calculated from SCRIPT_FILENAME +$tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME']; +$tmp2 = realpath(__FILE__); +$i = strlen($tmp) - 1; +$j = strlen($tmp2) - 1; +while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) { + $i--; + $j--; +} +if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1)) . "/main.inc.php")) { + $res = @include substr($tmp, 0, ($i + 1)) . "/main.inc.php"; +} +if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1))) . "/main.inc.php")) { + $res = @include dirname(substr($tmp, 0, ($i + 1))) . "/main.inc.php"; +} +// Try main.inc.php using relative path +if (!$res && file_exists("../main.inc.php")) { + $res = @include "../main.inc.php"; +} +if (!$res && file_exists("../../main.inc.php")) { + $res = @include "../../main.inc.php"; +} +if (!$res && file_exists("../../../main.inc.php")) { + $res = @include "../../../main.inc.php"; +} +if (!$res && file_exists("../../../../main.inc.php")) { + $res = @include "../../../../main.inc.php"; +} +if (!$res && file_exists("../../../../main.inc.php")) { + $res = @include "../../../../main.inc.php"; +} +if (!$res) { + die("Include of main fails"); +} + +require_once DOL_DOCUMENT_ROOT . '/comm/action/class/actioncomm.class.php'; +require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php'; +require_once DOL_DOCUMENT_ROOT . '/contact/class/contact.class.php'; +require_once DOL_DOCUMENT_ROOT . '/user/class/usergroup.class.php'; +require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php'; +require_once DOL_DOCUMENT_ROOT . '/core/lib/agenda.lib.php'; +require_once DOL_DOCUMENT_ROOT . '/core/class/html.formprojet.class.php'; +require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php'; +require_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php'; + + +if (!getDolGlobalInt('AGENDA_MAX_EVENTS_DAY_VIEW')) { + $conf->global->AGENDA_MAX_EVENTS_DAY_VIEW = 3; +} + +$action = GETPOST('action', 'aZ09'); + +$filter = GETPOST("search_filter", 'alpha', 3) ? GETPOST("search_filter", 'alpha', 3) : GETPOST("filter", 'alpha', 3); +$filtert = GETPOST("search_filtert", "int", 3) ? GETPOST("search_filtert", "int", 3) : GETPOST("filtert", "int", 3); +$usergroup = GETPOST("search_usergroup", "int", 3) ? GETPOST("search_usergroup", "int", 3) : GETPOST("usergroup", "int", 3); +//if (! ($usergroup > 0) && ! ($filtert > 0)) $filtert = $user->id; +//$showbirthday = empty($conf->use_javascript_ajax)?GETPOST("showbirthday","int"):1; +$showbirthday = 0; + + +$create_from_element_id = GETPOST('create_from_element_id', 'int'); +$create_from_element_type = GETPOST('create_from_element_type', 'alpha'); + +$sortfield = GETPOST('sortfield', 'aZ09comma'); +$sortorder = GETPOST('sortorder', 'aZ09comma'); +$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); +if (empty($page) || $page == -1) { + $page = 0; +} // If $page is not defined, or '' or -1 +$limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit; +$offset = $limit * $page; +if (!$sortorder) { + $sortorder = "ASC"; +} +if (!$sortfield) { + $sortfield = "a.datec"; +} + +$socid = GETPOST("search_socid", "int") ? GETPOST("search_socid", "int") : GETPOST("socid", "int"); +if ($user->socid) { + $socid = $user->socid; +} +if ($socid < 0) { + $socid = ''; +} + +if (empty(isModEnabled("dolimeet"))) accessforbidden(); +$canedit = 1; +if (empty($user->hasRight('agenda', 'myactions', 'read'))) { + accessforbidden(); +} +if (empty($user->hasRight('agenda', 'allactions', 'read'))) { + $canedit = 0; +} +if (empty($user->hasRight('agenda', 'allactions', 'read')) || $filter == 'mine') { // If no permission to see all, we show only affected to me + $filtert = $user->id; +} + +$mode = 'show_peruser'; +$resourceid = GETPOST("search_resourceid", "int") ? GETPOST("search_resourceid", "int") : GETPOST("resourceid", "int"); +$year = GETPOST("year", "int") ? GETPOST("year", "int") : date("Y"); +$month = GETPOST("month", "int") ? GETPOST("month", "int") : date("m"); +$week = GETPOST("week", "int") ? GETPOST("week", "int") : date("W"); +$day = GETPOST("day", "int") ? GETPOST("day", "int") : date("d"); +$pid = GETPOST("search_projectid", "int", 3) ? GETPOST("search_projectid", "int", 3) : GETPOST("projectid", "int", 3); +$status = GETPOSTISSET("search_status") ? GETPOST("search_status", 'aZ09') : GETPOST("status", 'aZ09'); // status may be 0, 50, 100, 'todo', 'na' or -1 +$type = GETPOST("search_type", 'alpha') ? GETPOST("search_type", 'alpha') : GETPOST("type", 'alpha'); +$maxprint = ((GETPOST("maxprint", 'int') != '') ? GETPOST("maxprint", 'int') : getDolGlobalInt('AGENDA_MAX_EVENTS_DAY_VIEW')); +$optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print') +// Set actioncode (this code must be same for setting actioncode into peruser, listacton and index) +if (GETPOST('search_actioncode', 'array:aZ09')) { + $actioncode = GETPOST('search_actioncode', 'array:aZ09', 3); + if (!count($actioncode)) { + $actioncode = '0'; + } +} else { + $actioncode = GETPOST("search_actioncode", "alpha", 3) ? GETPOST("search_actioncode", "alpha", 3) : (GETPOST("search_actioncode", "alpha") == '0' ? '0' : getDolGlobalString('AGENDA_DEFAULT_FILTER_TYPE')); +} +if ($actioncode == '' && empty($actioncodearray)) { + $actioncode = getDolGlobalString('AGENDA_DEFAULT_FILTER_TYPE'); +} +$multievt = GETPOST('multievt', 'int'); +$clean_session_multievt = GETPOST('clean_session_multievt', 'int'); +if (!empty($multievt) && !empty($clean_session_multievt)) { + $_SESSION["multi_evt"] = array(); +} + +$dateselect = dol_mktime(0, 0, 0, GETPOST('dateselectmonth', 'int'), GETPOST('dateselectday', 'int'), GETPOST('dateselectyear', 'int')); +if ($dateselect > 0) { + $day = GETPOST('dateselectday', 'int'); + $month = GETPOST('dateselectmonth', 'int'); + $year = GETPOST('dateselectyear', 'int'); +} + +$tmp = !getDolGlobalString('MAIN_DEFAULT_WORKING_HOURS') ? '9-18' : getDolGlobalString('MAIN_DEFAULT_WORKING_HOURS'); +$tmp = str_replace(' ', '', $tmp); // FIX 7533 +$tmparray = explode('-', $tmp); +$begin_h = GETPOST('begin_h', 'int') != '' ? GETPOST('begin_h', 'int') : ($tmparray[0] != '' ? $tmparray[0] : 9); +$end_h = GETPOST('end_h', 'int') ? GETPOST('end_h', 'int') : ($tmparray[1] != '' ? $tmparray[1] : 18); +if ($begin_h < 0 || $begin_h > 23) { + $begin_h = 9; +} +if ($end_h < 1 || $end_h > 24) { + $end_h = 18; +} +if ($end_h <= $begin_h) { + $end_h = $begin_h + 1; +} + +$tmp = !getDolGlobalString('MAIN_DEFAULT_WORKING_DAYS') ? '1-5' : getDolGlobalString('MAIN_DEFAULT_WORKING_DAYS'); +$tmp = str_replace(' ', '', $tmp); // FIX 7533 +$tmparray = explode('-', $tmp); +$begin_d = GETPOST('begin_d', 'int') ? GETPOST('begin_d', 'int') : ($tmparray[0] != '' ? $tmparray[0] : 1); +$end_d = GETPOST('end_d', 'int') ? GETPOST('end_d', 'int') : ($tmparray[1] != '' ? $tmparray[1] : 5); +if ($begin_d < 1 || $begin_d > 7) { + $begin_d = 1; +} +if ($end_d < 1 || $end_d > 7) { + $end_d = 7; +} +if ($end_d < $begin_d) { + $end_d = $begin_d + 1; +} + +if ($status == '' && !GETPOSTISSET('search_status')) { + $status = getDolGlobalString('AGENDA_DEFAULT_FILTER_STATUS'); +} + +if (empty($mode) && !GETPOSTISSET('mode')) { + $mode = (!getDolGlobalString('AGENDA_DEFAULT_VIEW') ? 'show_month' : getDolGlobalString('AGENDA_DEFAULT_VIEW')); +} + +if (GETPOST('viewcal', 'alpha') && $mode != 'show_day' && $mode != 'show_week' && $mode != 'show_peruser') { + $mode = 'show_month'; + $day = ''; +} // View by month +if (GETPOST('viewweek', 'alpha') || $mode == 'show_week') { + $mode = 'show_week'; + $week = ($week ? $week : date("W")); + $day = ($day ? $day : date("d")); +} // View by week +if (GETPOST('viewday', 'alpha') || $mode == 'show_day') { + $mode = 'show_day'; + $day = ($day ? $day : date("d")); +} // View by day + +// Load translation files required by the page +$langs->loadLangs(array('users', 'agenda', 'other', 'commercial')); + +// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context +$hookmanager->initHooks(array('dolimeet_agenda')); + +$result = restrictedArea($user, 'agenda', 0, '', 'myactions'); +if ($user->socid && $socid) { + $result = restrictedArea($user, 'societe', $socid); +} + + +/* + * Actions + */ + + +if ($action == 'confirm_delete_action') { + $event = new ActionComm($db); + $res = $event->fetch(GETPOST('actionid', 'int')); + if ($res < 0) { + setEventMessages($event->error, $event->errors, 'errors'); + } else { + $permissiondelete = ($user->hasRight('agenda', 'allactions', 'delete') || + (($event->authorid == $user->id || $event->userownerid == $user->id) + && $user->hasRight('agenda', 'myactions', 'delete'))); + if ($permissiondelete) { + $event->fetch_optionals(); + $event->fetch_userassigned(); + $event->oldcopy = clone $event; + $result = $event->delete(); + if ($result < 0) { + setEventMessages($event->error, $event->errors, 'errors'); + } + $queryStrParam[] = 'token=' . newToken(); + if (getDolGlobalString('DOLIPAD_USERGROUP_TECH')) { + $queryStrParam[] = "usergroup=" . getDolGlobalString('DOLIPAD_USERGROUP_TECH'); + } + if (GETPOST('create_from_element_id', 'int')) { + $queryStrParam[] = 'create_from_element_id=' . GETPOST('create_from_element_id', 'int'); + } + if (GETPOST('create_from_element_type', 'alpha')) { + $queryStrParam[] = 'create_from_element_type=' . GETPOST('create_from_element_type', 'alpha'); + } + header('Location:' . dol_buildpath('/dolipad/comm/action/peruser_eventcreation.php', 2) . '?' . implode('&', $queryStrParam)); + exit(); + } + } +} + + +/* + * View + */ + +$parameters = array( + 'socid' => $socid, + 'status' => $status, + 'year' => $year, + 'month' => $month, + 'day' => $day, + 'type' => $type, + 'maxprint' => $maxprint, + 'filter' => $filter, + 'filtert' => $filtert, + 'showbirthday' => $showbirthday, + 'canedit' => $canedit, + 'optioncss' => $optioncss, + 'actioncode' => $actioncode, + 'pid' => $pid, + 'resourceid' => $resourceid, + 'usergroup' => $usergroup, +); +$reshook = $hookmanager->executeHooks('beforeAgendaPerUser', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks +if ($reshook < 0) { + setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); +} + +$form = new Form($db); +$companystatic = new Societe($db); +$formactions = new FormActions($db); + +$help_url = 'EN:Module_Agenda_En|FR:Module_Agenda|ES:Módulo_Agenda'; +llxHeader('', $langs->trans("Agenda"), $help_url, '', 0, 0, array(), array(dol_buildpath('/dolimeet/css/dolimeet_eventcreation.css', 2))); + +$now = dol_now(); +$nowarray = dol_getdate($now); +$nowyear = $nowarray['year']; +$nowmonth = $nowarray['mon']; +$nowday = $nowarray['mday']; + + +// Define list of all external calendars (global setup) +$listofextcals = array(); + +$prev = dol_get_first_day_week($day, $month, $year); +$first_day = $prev['first_day']; +$first_month = $prev['first_month']; +$first_year = $prev['first_year']; + +$week = $prev['week']; + +$day = (int) $day; +$next = dol_get_next_week($day, $week, $month, $year); +$next_year = $next['year']; +$next_month = $next['month']; +$next_day = $next['day']; + +$max_day_in_month = date("t", dol_mktime(0, 0, 0, $month, 1, $year)); + +$tmpday = $first_day; +//print 'xx'.$prev_year.'-'.$prev_month.'-'.$prev_day; +//print 'xx'.$next_year.'-'.$next_month.'-'.$next_day; + +$title = $langs->trans("DoneAndToDoActions"); +if ($status == 'done') { + $title = $langs->trans("DoneActions"); +} +if ($status == 'todo') { + $title = $langs->trans("ToDoActions"); +} + +$param = ''; +if ($actioncode || GETPOSTISSET('search_actioncode')) { + if (is_array($actioncode)) { + foreach ($actioncode as $str_action) { + $param .= "&search_actioncode[]=" . urlencode($str_action); + } + } else { + $param .= "&search_actioncode=" . urlencode($actioncode); + } +} +if ($resourceid > 0) { + $param .= "&search_resourceid=" . urlencode($resourceid); +} +if ($status || GETPOSTISSET('status')) { + $param .= "&search_status=" . urlencode($status); +} +if ($filter) { + $param .= "&search_filter=" . urlencode($filter); +} +if ($filtert) { + $param .= "&search_filtert=" . urlencode($filtert); +} +if ($usergroup > 0) { + $param .= "&search_usergroup=" . urlencode($usergroup); +} +if ($socid > 0) { + $param .= "&search_socid=" . urlencode($socid); +} +if ($showbirthday) { + $param .= "&search_showbirthday=1"; +} +if ($pid) { + $param .= "&search_projectid=" . urlencode($pid); +} +if ($type) { + $param .= "&search_type=" . urlencode($type); +} +if ($mode != 'show_peruser') { + $param .= '&mode=' . urlencode($mode); +} +if ($begin_h != '') { + $param .= '&begin_h=' . urlencode($begin_h); +} +if ($end_h != '') { + $param .= '&end_h=' . urlencode($end_h); +} +if ($begin_d != '') { + $param .= '&begin_d=' . urlencode($begin_d); +} +if ($end_d != '') { + $param .= '&end_d=' . urlencode($end_d); +} +if (!empty($create_from_element_id)) { + $param .= '&create_from_element_id=' . urlencode($create_from_element_id); +} +if (!empty($create_from_element_type)) { + $param .= '&create_from_element_type=' . urlencode($create_from_element_type); +} +if (!empty($multievt)) { + $param .= '&multievt=' . urlencode($multievt); +} +$param .= "&maxprint=" . urlencode($maxprint); + +$paramnoactionodate = $param; + +$prev = dol_get_first_day_week($day, $month, $year); +//print "day=".$day." month=".$month." year=".$year; +//var_dump($prev); exit; +$prev_year = $prev['prev_year']; +$prev_month = $prev['prev_month']; +$prev_day = $prev['prev_day']; +$first_day = $prev['first_day']; +$first_month = $prev['first_month']; +$first_year = $prev['first_year']; + +$week = $prev['week']; + +$day = (int) $day; +$next = dol_get_next_week($first_day, $week, $first_month, $first_year); +$next_year = $next['year']; +$next_month = $next['month']; +$next_day = $next['day']; + +// Define firstdaytoshow and lastdaytoshow (warning: lastdaytoshow is last second to show + 1) +$firstdaytoshow = dol_mktime(0, 0, 0, $first_month, $first_day, $first_year, 'gmt'); + +$nb_weeks_to_show = (getDolGlobalString('AGENDA_NB_WEEKS_IN_VIEW_PER_USER')) ? ((int) getDolGlobalString('AGENDA_NB_WEEKS_IN_VIEW_PER_USER') * 7) : 7; +$lastdaytoshow = dol_time_plus_duree($firstdaytoshow, $nb_weeks_to_show, 'd'); +//print $firstday.'-'.$first_month.'-'.$first_year; +//print dol_print_date($firstdaytoshow,'dayhour'); +//print dol_print_date($lastdaytoshow,'dayhour'); + +$max_day_in_month = date("t", dol_mktime(0, 0, 0, $month, 1, $year, 'gmt')); + +$tmpday = $first_day; +$picto = 'calendarweek'; + +$nav = "trans("Previous")) . "\">   \n"; +$nav .= " " . dol_print_date(dol_mktime(0, 0, 0, $first_month, $first_day, $first_year), "%Y") . ", " . $langs->trans("Week") . " " . $week; +$nav .= " \n"; +$nav .= "   trans("Next")) . "\">\n"; +if (empty($conf->dol_optimize_smallscreen)) { + $nav .= "   " . $langs->trans("Today") . " "; +} +$nav .= $form->selectDate($dateselect, 'dateselect', 0, 0, 1, '', 1, 0); +$nav .= ' '; + +// Must be after the nav definition +$param .= '&year=' . urlencode($year) . '&month=' . urlencode($month) . ($day ? '&day=' . urlencode($day) : ''); +//print 'x'.$param; + + +$paramnoaction = preg_replace('/action=[a-z_]+/', '', $param); + +$head = calendars_prepare_head($paramnoaction); +echo "
" . $langs->trans('DlpdLoading') . "
"; +if (!getDolGlobalString('DOLIPAD_TYPE_EVENT_CREATION_INTER') && $create_from_element_type == "fichinter" && empty($multievt)) { + setEventMessages(null, $langs->trans('DlpdConfNotCompleteEventCreationSimple'), 'errors'); +} +if (!getDolGlobalString('DOLIPAD_TYPE_EVENT_CREATION_INTER_MULTI') && $create_from_element_type == "fichinter" && !empty($multievt)) { + setEventMessages(null, $langs->trans('DlpdConfNotCompleteEventCreationMulti'), 'errors'); +} + + +print ''; + +print ''; + +print "\n"; + +?> + + + +
" style="display: none;"> +
+
trans("ConfirmAddAction"); ?>
+
+close(); + + +/** + * Show event line of a particular day for a user + * + * @param User $username Login + * @param int $day Day + * @param int $month Month + * @param int $year Year + * @param int $monthshown Current month shown in calendar view + * @param string $style Style to use for this day + * @param array $eventarray Array of events + * @param int $maxprint Nb of actions to show each day on month view (0 means no limit) + * @param int $maxnbofchar Nb of characters to show for event line + * @param string $newparam Parameters on current URL + * @param int $showinfo Add extended information (used by day view) + * @param int $minheight Minimum height for each event. 60px by default. + * @param boolean $showheader Show header + * @param array $colorsbytype Array with colors by type + * @param bool $var true or false for alternat style on tr/td + * @return void + */ +function show_day_events2($username, $day, $month, $year, $monthshown, $style, &$eventarray, $maxprint = 0, $maxnbofchar = 16, $newparam = '', $showinfo = 0, $minheight = 60, $showheader = false, $colorsbytype = array(), $var = false) +{ + global $db; + global $user, $conf, $langs, $hookmanager, $action; + global $filter, $filtert, $status, $actioncode; // Filters used into search form + global $theme_datacolor; // Array with a list of different we can use (come from theme) + global $cachethirdparties, $cachecontacts, $cacheusers, $cacheprojects, $colorindexused; + global $begin_h, $end_h; + + $cases1 = array(); // Color first half hour + $cases2 = array(); // Color second half hour + $cases3 = array(); // Color third half hour + $cases4 = array(); // Color 4th half hour + + $i = 0; + $numother = 0; + $numbirthday = 0; + $numical = 0; + $numicals = array(); + //$ymd = sprintf("%04d", $year).sprintf("%02d", $month).sprintf("%02d", $day); + + $colorindexused[$user->id] = 0; // Color index for current user (user->id) is always 0 + $nextindextouse = count($colorindexused); // At first run this is 0, so first user has 0, next 1, ... + //if ($username->id && $day==1) var_dump($eventarray); + + // We are in a particular day for $username, now we scan all events + foreach ($eventarray as $daykey => $notused) { + $annee = dol_print_date($daykey, '%Y'); + $mois = dol_print_date($daykey, '%m'); + $jour = dol_print_date($daykey, '%d'); + + if ($day == $jour && $month == $mois && $year == $annee) { // Is it the day we are looking for when calling function ? + // Scan all event for this date + foreach ($eventarray[$daykey] as $index => $event) { + //print $daykey.' '.dol_print_date($daykey, 'dayhour', 'gmt').' '.$year.'-'.$month.'-'.$day.' -> '.$event->id.' '.$index.' '.$annee.'-'.$mois.'-'.$jour."
\n"; + //var_dump($event); + + $keysofuserassigned = array_keys($event->userassigned); + $ponct = ($event->date_start_in_calendar == $event->date_end_in_calendar); + + if (!in_array($username->id, $keysofuserassigned)) { + continue; // We discard record if event is from another user than user we want to show + } + //if ($username->id != $event->userownerid) continue; // We discard record if event is from another user than user we want to show + + $parameters = array(); + $reshook = $hookmanager->executeHooks('formatEvent', $parameters, $event, $action); // Note that $action and $object may have been modified by some hooks + if ($reshook < 0) { + setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); + } + + // Define $color (Hex string like '0088FF') and $cssclass of event + $color = -1; + $cssclass = ''; + $colorindex = -1; + if (in_array($user->id, $keysofuserassigned)) { + $cssclass = 'family_mytasks'; + + if (empty($cacheusers[$event->userownerid])) { + $newuser = new User($db); + $newuser->fetch($event->userownerid); + $cacheusers[$event->userownerid] = $newuser; + } + //var_dump($cacheusers[$event->userownerid]->color); + + // We decide to choose color of owner of event (event->userownerid is user id of owner, event->userassigned contains all users assigned to event) + if (!empty($cacheusers[$event->userownerid]->color)) { + $color = $cacheusers[$event->userownerid]->color; + } + + if (getDolGlobalString('AGENDA_USE_COLOR_PER_EVENT_TYPE')) { + $color = $event->type_color; + } + } elseif ($event->type_code == 'ICALEVENT') { + $numical++; + if (!empty($event->icalname)) { + if (!isset($numicals[dol_string_nospecial($event->icalname)])) { + $numicals[dol_string_nospecial($event->icalname)] = 0; + } + $numicals[dol_string_nospecial($event->icalname)]++; + } + + $color = $event->icalcolor; + $cssclass = (!empty($event->icalname) ? 'family_ext' . md5($event->icalname) : 'family_other unsortable'); + } elseif ($event->type_code == 'BIRTHDAY') { + $numbirthday++; + $colorindex = 2; + $cssclass = 'family_birthday unsortable'; + $color = sprintf("%02x%02x%02x", $theme_datacolor[$colorindex][0], $theme_datacolor[$colorindex][1], $theme_datacolor[$colorindex][2]); + } else { + $numother++; + $color = ($event->icalcolor ? $event->icalcolor : -1); + $cssclass = (!empty($event->icalname) ? 'family_ext' . md5($event->icalname) : 'family_other'); + + if (empty($cacheusers[$event->userownerid])) { + $newuser = new User($db); + $newuser->fetch($event->userownerid); + $cacheusers[$event->userownerid] = $newuser; + } + //var_dump($cacheusers[$event->userownerid]->color); + + // We decide to choose color of owner of event (event->userownerid is user id of owner, event->userassigned contains all users assigned to event) + if (!empty($cacheusers[$event->userownerid]->color)) { + $color = $cacheusers[$event->userownerid]->color; + } + + if (getDolGlobalString('AGENDA_USE_COLOR_PER_EVENT_TYPE')) { + $color = $event->type_color; + } + } + + if ($color < 0) { // Color was not set on user card. Set color according to color index. + // Define color index if not yet defined + $idusertouse = ($event->userownerid ? $event->userownerid : 0); + if (isset($colorindexused[$idusertouse])) { + $colorindex = $colorindexused[$idusertouse]; // Color already assigned to this user + } else { + $colorindex = $nextindextouse; + $colorindexused[$idusertouse] = $colorindex; + if (!empty($theme_datacolor[$nextindextouse + 1])) { + $nextindextouse++; // Prepare to use next color + } + } + // Define color + $color = sprintf("%02x%02x%02x", $theme_datacolor[$colorindex][0], $theme_datacolor[$colorindex][1], $theme_datacolor[$colorindex][2]); + } + + // Define all rects with event (cases1 is first quarter hour, cases2 is second quarter hour, cases3 is second thirds hour, cases4 is 4th quarter hour) + for ($h = $begin_h; $h < $end_h; $h++) { + //if ($username->id == 1 && $day==1) print 'h='.$h; + $newcolor = ''; //init + if (empty($event->fulldayevent)) { + $a = dol_mktime((int) $h, 0, 0, $month, $day, $year, 'tzuserrel', 0); + $b = dol_mktime((int) $h, 15, 0, $month, $day, $year, 'tzuserrel', 0); + $b1 = dol_mktime((int) $h, 30, 0, $month, $day, $year, 'tzuserrel', 0); + $b2 = dol_mktime((int) $h, 45, 0, $month, $day, $year, 'tzuserrel', 0); + $c = dol_mktime((int) $h + 1, 0, 0, $month, $day, $year, 'tzuserrel', 0); + + $dateendtouse = $event->date_end_in_calendar; + if ($dateendtouse == $event->date_start_in_calendar) { + $dateendtouse++; + } + + //print dol_print_date($event->date_start_in_calendar,'dayhour').'-'.dol_print_date($a,'dayhour').'-'.dol_print_date($b,'dayhour').'
'; + + if ($event->date_start_in_calendar < $b && $dateendtouse > $a) { + $busy = $event->transparency; + $cases1[$h][$event->id]['busy'] = $busy; + $cases1[$h][$event->id]['string'] = dol_print_date($event->date_start_in_calendar, 'dayhour', 'tzuserrel'); + if ($event->date_end_in_calendar && $event->date_end_in_calendar != $event->date_start_in_calendar) { + $tmpa = dol_getdate($event->date_start_in_calendar, true); + $tmpb = dol_getdate($event->date_end_in_calendar, true); + if ($tmpa['mday'] == $tmpb['mday'] && $tmpa['mon'] == $tmpb['mon'] && $tmpa['year'] == $tmpb['year']) { + $cases1[$h][$event->id]['string'] .= '-' . dol_print_date($event->date_end_in_calendar, 'hour', 'tzuserrel'); + } else { + $cases1[$h][$event->id]['string'] .= '-' . dol_print_date($event->date_end_in_calendar, 'dayhour', 'tzuserrel'); + } + } + if ($event->label) { + $cases1[$h][$event->id]['string'] .= ' - ' . $event->label; + } + $cases1[$h][$event->id]['typecode'] = $event->type_code; + $cases1[$h][$event->id]['color'] = $color; + if ($event->fk_project > 0) { + if (empty($cacheprojects[$event->fk_project])) { + $tmpproj = new Project($db); + $tmpproj->fetch($event->fk_project); + $cacheprojects[$event->fk_project] = $tmpproj; + } + $cases1[$h][$event->id]['string'] .= ', ' . $langs->trans("Project") . ': ' . $cacheprojects[$event->fk_project]->ref . ' - ' . $cacheprojects[$event->fk_project]->title; + } + if ($event->socid > 0) { + if (empty($cachethirdparties[$event->socid])) { + $tmpthirdparty = new Societe($db); + $tmpthirdparty->fetch($event->socid); + $cachethirdparties[$event->socid] = $tmpthirdparty; + } + $cases1[$h][$event->id]['string'] .= ', ' . $cachethirdparties[$event->socid]->name; + } + if ($event->contact_id > 0) { + if (empty($cachecontacts[$event->contact_id])) { + $tmpcontact = new Contact($db); + $tmpcontact->fetch($event->contact_id); + $cachecontacts[$event->contact_id] = $tmpcontact; + } + $cases1[$h][$event->id]['string'] .= ', ' . $cachecontacts[$event->contact_id]->getFullName($langs); + } + } + if ($event->date_start_in_calendar < $b1 && $dateendtouse > $b) { + $busy = $event->transparency; + $cases2[$h][$event->id]['busy'] = $busy; + $cases2[$h][$event->id]['string'] = dol_print_date($event->date_start_in_calendar, 'dayhour', 'tzuserrel'); + if ($event->date_end_in_calendar && $event->date_end_in_calendar != $event->date_start_in_calendar) { + $tmpa = dol_getdate($event->date_start_in_calendar, true); + $tmpb = dol_getdate($event->date_end_in_calendar, true); + if ($tmpa['mday'] == $tmpb['mday'] && $tmpa['mon'] == $tmpb['mon'] && $tmpa['year'] == $tmpb['year']) { + $cases2[$h][$event->id]['string'] .= '-' . dol_print_date($event->date_end_in_calendar, 'hour', 'tzuserrel'); + } else { + $cases2[$h][$event->id]['string'] .= '-' . dol_print_date($event->date_end_in_calendar, 'dayhour', 'tzuserrel'); + } + } + if ($event->label) { + $cases2[$h][$event->id]['string'] .= ' - ' . $event->label; + } + $cases2[$h][$event->id]['typecode'] = $event->type_code; + $cases2[$h][$event->id]['color'] = $color; + if ($event->fk_project > 0) { + if (empty($cacheprojects[$event->fk_project])) { + $tmpproj = new Project($db); + $tmpproj->fetch($event->fk_project); + $cacheprojects[$event->fk_project] = $tmpproj; + } + $cases2[$h][$event->id]['string'] .= ', ' . $langs->trans("Project") . ': ' . $cacheprojects[$event->fk_project]->ref . ' - ' . $cacheprojects[$event->fk_project]->title; + } + if ($event->socid > 0) { + if (empty($cachethirdparties[$event->socid])) { + $tmpthirdparty = new Societe($db); + $tmpthirdparty->fetch($event->socid); + $cachethirdparties[$event->socid] = $tmpthirdparty; + } + $cases2[$h][$event->id]['string'] .= ', ' . $cachethirdparties[$event->socid]->name; + } + if ($event->contact_id > 0) { + if (empty($cachecontacts[$event->contact_id])) { + $tmpcontact = new Contact($db); + $tmpcontact->fetch($event->contact_id); + $cachecontacts[$event->contact_id] = $tmpcontact; + } + $cases2[$h][$event->id]['string'] .= ', ' . $cachecontacts[$event->contact_id]->getFullName($langs); + } + } + if ($event->date_start_in_calendar < $b2 && $dateendtouse > $b1) { + $busy = $event->transparency; + $cases3[$h][$event->id]['busy'] = $busy; + $cases3[$h][$event->id]['string'] = dol_print_date($event->date_start_in_calendar, 'dayhour', 'tzuserrel'); + if ($event->date_end_in_calendar && $event->date_end_in_calendar != $event->date_start_in_calendar) { + $tmpa = dol_getdate($event->date_start_in_calendar, true); + $tmpb = dol_getdate($event->date_end_in_calendar, true); + if ($tmpa['mday'] == $tmpb['mday'] && $tmpa['mon'] == $tmpb['mon'] && $tmpa['year'] == $tmpb['year']) { + $cases3[$h][$event->id]['string'] .= '-' . dol_print_date($event->date_end_in_calendar, 'hour', 'tzuserrel'); + } else { + $cases3[$h][$event->id]['string'] .= '-' . dol_print_date($event->date_end_in_calendar, 'dayhour', 'tzuserrel'); + } + } + if ($event->label) { + $cases3[$h][$event->id]['string'] .= ' - ' . $event->label; + } + $cases3[$h][$event->id]['typecode'] = $event->type_code; + $cases3[$h][$event->id]['color'] = $color; + if ($event->fk_project > 0) { + if (empty($cacheprojects[$event->fk_project])) { + $tmpproj = new Project($db); + $tmpproj->fetch($event->fk_project); + $cacheprojects[$event->fk_project] = $tmpproj; + } + $cases3[$h][$event->id]['string'] .= ', ' . $langs->trans("Project") . ': ' . $cacheprojects[$event->fk_project]->ref . ' - ' . $cacheprojects[$event->fk_project]->title; + } + if ($event->socid > 0) { + if (empty($cachethirdparties[$event->socid])) { + $tmpthirdparty = new Societe($db); + $tmpthirdparty->fetch($event->socid); + $cachethirdparties[$event->socid] = $tmpthirdparty; + } + $cases3[$h][$event->id]['string'] .= ', ' . $cachethirdparties[$event->socid]->name; + } + if ($event->contact_id > 0) { + if (empty($cachecontacts[$event->contact_id])) { + $tmpcontact = new Contact($db); + $tmpcontact->fetch($event->contact_id); + $cachecontacts[$event->contact_id] = $tmpcontact; + } + $cases2[$h][$event->id]['string'] .= ', ' . $cachecontacts[$event->contact_id]->getFullName($langs); + } + } + if ($event->date_start_in_calendar < $c && $dateendtouse > $b2) { + $busy = $event->transparency; + $cases4[$h][$event->id]['busy'] = $busy; + $cases4[$h][$event->id]['string'] = dol_print_date($event->date_start_in_calendar, 'dayhour', 'tzuserrel'); + if ($event->date_end_in_calendar && $event->date_end_in_calendar != $event->date_start_in_calendar) { + $tmpa = dol_getdate($event->date_start_in_calendar, true); + $tmpb = dol_getdate($event->date_end_in_calendar, true); + if ($tmpa['mday'] == $tmpb['mday'] && $tmpa['mon'] == $tmpb['mon'] && $tmpa['year'] == $tmpb['year']) { + $cases4[$h][$event->id]['string'] .= '-' . dol_print_date($event->date_end_in_calendar, 'hour', 'tzuserrel'); + } else { + $cases4[$h][$event->id]['string'] .= '-' . dol_print_date($event->date_end_in_calendar, 'dayhour', 'tzuserrel'); + } + } + if ($event->label) { + $cases4[$h][$event->id]['string'] .= ' - ' . $event->label; + } + $cases4[$h][$event->id]['typecode'] = $event->type_code; + $cases4[$h][$event->id]['color'] = $color; + if ($event->fk_project > 0) { + if (empty($cacheprojects[$event->fk_project])) { + $tmpproj = new Project($db); + $tmpproj->fetch($event->fk_project); + $cacheprojects[$event->fk_project] = $tmpproj; + } + $cases4[$h][$event->id]['string'] .= ', ' . $langs->trans("Project") . ': ' . $cacheprojects[$event->fk_project]->ref . ' - ' . $cacheprojects[$event->fk_project]->title; + } + if ($event->socid > 0) { + if (empty($cachethirdparties[$event->socid])) { + $tmpthirdparty = new Societe($db); + $tmpthirdparty->fetch($event->socid); + $cachethirdparties[$event->socid] = $tmpthirdparty; + } + $cases4[$h][$event->id]['string'] .= ', ' . $cachethirdparties[$event->socid]->name; + } + if ($event->contact_id > 0) { + if (empty($cachecontacts[$event->contact_id])) { + $tmpcontact = new Contact($db); + $tmpcontact->fetch($event->contact_id); + $cachecontacts[$event->contact_id] = $tmpcontact; + } + $cases4[$h][$event->id]['string'] .= ', ' . $cachecontacts[$event->contact_id]->getFullName($langs); + } + } + } else { + $busy = $event->transparency; + $cases1[$h][$event->id]['busy'] = $busy; + $cases2[$h][$event->id]['busy'] = $busy; + $cases3[$h][$event->id]['busy'] = $busy; + $cases4[$h][$event->id]['busy'] = $busy; + $cases1[$h][$event->id]['string'] = $event->label; + $cases2[$h][$event->id]['string'] = $event->label; + $cases3[$h][$event->id]['string'] = $event->label; + $cases4[$h][$event->id]['string'] = $event->label; + $cases1[$h][$event->id]['typecode'] = $event->type_code; + $cases2[$h][$event->id]['typecode'] = $event->type_code; + $cases3[$h][$event->id]['typecode'] = $event->type_code; + $cases4[$h][$event->id]['typecode'] = $event->type_code; + $cases1[$h][$event->id]['color'] = $color; + $cases2[$h][$event->id]['color'] = $color; + $cases3[$h][$event->id]['color'] = $color; + $cases4[$h][$event->id]['color'] = $color; + } + } + $i++; + } + + break; // We found the date we were looking for. No need to search anymore. + } + } + + // Now output $casesX + for ($h = $begin_h; $h < $end_h; $h++) { + $color1 = ''; + $color2 = ''; + $color3 = ''; + $color4 = ''; + $style1 = ''; + $style2 = ''; + $style3 = ''; + $style4 = ''; + $string1 = ' '; + $string2 = ' '; + $string3 = ' '; + $string4 = ' '; + $title1 = ''; + $title2 = ''; + $title3 = ''; + $title4 = ''; + if (isset($cases1[$h]) && $cases1[$h] != '') { + //$title1.=count($cases1[$h]).' '.(count($cases1[$h])==1?$langs->trans("Event"):$langs->trans("Events")); + if (count($cases1[$h]) > 1) { + $title1 .= count($cases1[$h]) . ' ' . (count($cases1[$h]) == 1 ? $langs->trans("Event") : $langs->trans("Events")); + } + $string1 = ' '; + if (!getDolGlobalString('AGENDA_NO_TRANSPARENT_ON_NOT_BUSY')) { + $style1 = 'peruser_notbusy'; + } else { + $style1 = 'peruser_busy'; + } + foreach ($cases1[$h] as $id => $ev) { + if ($ev['busy']) { + $style1 = 'peruser_busy'; + } + } + } + if (isset($cases2[$h]) && $cases2[$h] != '') { + //$title2.=count($cases2[$h]).' '.(count($cases2[$h])==1?$langs->trans("Event"):$langs->trans("Events")); + if (count($cases2[$h]) > 1) { + $title2 .= count($cases2[$h]) . ' ' . (count($cases2[$h]) == 1 ? $langs->trans("Event") : $langs->trans("Events")); + } + $string2 = ' '; + if (!getDolGlobalString('AGENDA_NO_TRANSPARENT_ON_NOT_BUSY')) { + $style2 = 'peruser_notbusy'; + } else { + $style2 = 'peruser_busy'; + } + foreach ($cases2[$h] as $id => $ev) { + if ($ev['busy']) { + $style2 = 'peruser_busy'; + } + } + } + if (isset($cases3[$h]) && $cases3[$h] != '') { + //$title3.=count($cases3[$h]).' '.(count($cases3[$h])==1?$langs->trans("Event"):$langs->trans("Events")); + if (count($cases3[$h]) > 1) { + $title3 .= count($cases3[$h]) . ' ' . (count($cases3[$h]) == 1 ? $langs->trans("Event") : $langs->trans("Events")); + } + $string3 = ' '; + if (!getDolGlobalString('AGENDA_NO_TRANSPARENT_ON_NOT_BUSY')) { + $style3 = 'peruser_notbusy'; + } else { + $style3 = 'peruser_busy'; + } + foreach ($cases3[$h] as $id => $ev) { + if ($ev['busy']) { + $style3 = 'peruser_busy'; + } + } + } + if (isset($cases4[$h]) && $cases4[$h] != '') { + //$title4.=count($cases3[$h]).' '.(count($cases3[$h])==1?$langs->trans("Event"):$langs->trans("Events")); + if (count($cases4[$h]) > 1) { + $title4 .= count($cases4[$h]) . ' ' . (count($cases4[$h]) == 1 ? $langs->trans("Event") : $langs->trans("Events")); + } + $string4 = ' '; + if (!getDolGlobalString('AGENDA_NO_TRANSPARENT_ON_NOT_BUSY')) { + $style4 = 'peruser_notbusy'; + } else { + $style4 = 'peruser_busy'; + } + foreach ($cases4[$h] as $id => $ev) { + if ($ev['busy']) { + $style4 = 'peruser_busy'; + } + } + } + + $ids1 = ''; + $ids2 = ''; + $ids3 = ''; + $ids4 = ''; + if (!empty($cases1[$h]) && is_array($cases1[$h]) && count($cases1[$h]) && array_keys($cases1[$h])) { + $ids1 = join(',', array_keys($cases1[$h])); + } + if (!empty($cases2[$h]) && is_array($cases2[$h]) && count($cases2[$h]) && array_keys($cases2[$h])) { + $ids2 = join(',', array_keys($cases2[$h])); + } + if (!empty($cases3[$h]) && is_array($cases3[$h]) && count($cases3[$h]) && array_keys($cases3[$h])) { + $ids3 = join(',', array_keys($cases3[$h])); + } + if (!empty($cases4[$h]) && is_array($cases4[$h]) && count($cases4[$h]) && array_keys($cases4[$h])) { + $ids4 = join(',', array_keys($cases4[$h])); + } + + if ($h == $begin_h) { + echo ''; + } else { + echo ''; + } + + + if (!empty($cases1[$h]) && is_array($cases1[$h]) && count($cases1[$h]) == 1) { + $output = array_slice($cases1[$h], 0, 1); + $title1 = $langs->trans("Ref") . ' ' . $ids1 . ($title1 ? ' - ' . $title1 : ''); + if ($output[0]['string']) { + $title1 .= ($title1 ? ' - ' : '') . $output[0]['string']; + } + if ($output[0]['color']) { + $color1 = $output[0]['color']; + } + } elseif (!empty($cases1[$h]) && is_array($cases1[$h]) && count($cases1[$h]) > 1) { + $title1 = $langs->trans("Ref") . ' ' . $ids1 . ($title1 ? ' - ' . $title1 : ''); + $color1 = '222222'; + } + + + if (!empty($cases2[$h]) && is_array($cases2[$h]) && count($cases2[$h]) == 1) { + $output = array_slice($cases2[$h], 0, 1); + $title2 = $langs->trans("Ref") . ' ' . $ids2 . ($title2 ? ' - ' . $title2 : ''); + if ($output[0]['string']) { + $title2 .= ($title2 ? ' - ' : '') . $output[0]['string']; + } + if ($output[0]['color']) { + $color2 = $output[0]['color']; + } + } elseif (!empty($cases2[$h]) && is_array($cases2[$h]) && count($cases2[$h]) > 1) { + $title2 = $langs->trans("Ref") . ' ' . $ids2 . ($title2 ? ' - ' . $title2 : ''); + $color2 = '222222'; + } + + + if (!empty($cases3[$h]) && is_array($cases3[$h]) && count($cases3[$h]) == 1) { + $output = array_slice($cases3[$h], 0, 1); + $title3 = $langs->trans("Ref") . ' ' . $ids3 . ($title3 ? ' - ' . $title3 : ''); + if ($output[0]['string']) { + $title3 .= ($title3 ? ' - ' : '') . $output[0]['string']; + } + if ($output[0]['color']) { + $color3 = $output[0]['color']; + } + } elseif (!empty($cases3[$h]) && is_array($cases3[$h]) && count($cases3[$h]) > 1) { + $title3 = $langs->trans("Ref") . ' ' . $ids3 . ($title3 ? ' - ' . $title3 : ''); + $color3 = '222222'; + } + + + if (!empty($cases4[$h]) && is_array($cases4[$h]) && count($cases4[$h]) == 1) { + $output = array_slice($cases4[$h], 0, 1); + $title4 = $langs->trans("Ref") . ' ' . $ids3 . ($title4 ? ' - ' . $title4 : ''); + if ($output[0]['string']) { + $title4 .= ($title4 ? ' - ' : '') . $output[0]['string']; + } + if ($output[0]['color']) { + $color4 = $output[0]['color']; + } + } elseif (!empty($cases4[$h]) && is_array($cases4[$h]) && count($cases4[$h]) > 1) { + $title4 = $langs->trans("Ref") . ' ' . $ids4 . ($title4 ? ' - ' . $title4 : ''); + $color4 = '222222'; + } + + $date_info = sprintf("%04d", $year) . '_' . sprintf("%02d", $month) . '_' . sprintf("%02d", $day) . '_' . sprintf("%02d", $h); + + print ''; + print ''; + print ''; + + print ''; + + print ''; + + print ''; + + print ''; + print '
'; + print $string1; + print ''; + print $string2; + print ''; + print $string3; + print ''; + print $string4; + print '
'; + print ''; + } +} diff --git a/css/dolimeet_eventcreation.css b/css/dolimeet_eventcreation.css new file mode 100644 index 0000000..8039f77 --- /dev/null +++ b/css/dolimeet_eventcreation.css @@ -0,0 +1,2 @@ +td.selectedtimeslot {background: red} +td.selectedtimeslotmulti {background: #990000} diff --git a/view/session/session_card.php b/view/session/session_card.php index f369789..a44a5c4 100644 --- a/view/session/session_card.php +++ b/view/session/session_card.php @@ -350,6 +350,23 @@ // Part to show record. if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'create'))) { $res = $object->fetch_optionals(); +$filterTech=''; +print ' + '; + $linkback = '' . $langs->trans('BackToList') . ''; saturne_get_fiche_head($object, 'card', $title);