* Copyright (C) 2004-2015 Laurent Destailleur * Copyright (C) 2005-2012 Regis Houssin * Copyright (C) 2015 Jean-François Ferry * * 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 settlements/settlementsindex.php * \ingroup settlements * \brief Home page of settlements top menu */ // 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"); } use Luracast\Restler\RestException; require_once DOL_DOCUMENT_ROOT . '/core/class/html.formfile.class.php'; require_once DOL_DOCUMENT_ROOT . '/user/class/usergroup.class.php'; require_once DOL_DOCUMENT_ROOT . '/custom/settlements/class/groupusers.class.php'; require_once DOL_DOCUMENT_ROOT . '/custom/settlements/class/usernaplo.class.php'; require_once DOL_DOCUMENT_ROOT . '/custom/settlements/class/helper.class.php'; require_once DOL_DOCUMENT_ROOT . '/custom/settlements/class/grouptoolstools.class.php'; require_once DOL_DOCUMENT_ROOT . '/custom/settlements/class/toolnaplo.class.php'; require_once DOL_DOCUMENT_ROOT . '/custom/settlements/class/package.class.php'; require_once DOL_DOCUMENT_ROOT . '/custom/settlements/class/grouptoolspackages.class.php'; require_once DOL_DOCUMENT_ROOT . '/custom/settlements/core/tpl/printPDF_szisz.php'; // Include the main TCPDF library (search for installation path). require_once DOL_DOCUMENT_ROOT . '/includes/tecnickcom/tcpdf/examples/tcpdf_include.php'; require_once DOL_DOCUMENT_ROOT . '/includes/tecnickcom/tcpdf/tcpdf.php'; // create new PDF document // Load translation files required by the page $langs->loadLangs(array("settlements@settlements")); $massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists) $massactionadd = GETPOST('massactionadd', 'alpha'); // The bulk action (combo box choice into lists) $action = GETPOST('action', 'aZ09'); $cancel = GETPOST('cancel', 'int'); $id = GETPOST('id', 'int'); $idmenu = GETPOST('idmenu', 'int'); $toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list $toselectnewpackage = GETPOST('toselectnewpackage', 'array'); // Array of ids of elements selected into a list $search_package_name = GETPOST('search_package_name', 'alpha'); $search_group_title = GETPOST('search_group_title', 'alpha'); $confirmbutton = GETPOST('confirmbutton', 'int'); $printbutton = GETPOST('printbutton', 'alpha'); $confirm = GETPOST('confirm', 'alpha'); $confirmtools = GETPOST('confirmtools', 'alpha'); $delete = GETPOST('delete', 'int'); $toolclearall = GETPOST('toolclearall', 'int'); $confirmUserAndPackageAssignment = GETPOST('confirmUserAndPackageAssignment', 'int'); $packageuser = GETPOST('packageuser', 'array'); $nopackageuser = GETPOST('nopackageuser', 'int'); $confirmUsersButton = GETPOST('confirmUsersButton', 'int'); $groupuser_id = GETPOST('groupuser_id', 'int'); if ($nopackageuser == 1) { $packageuser = []; } $socid = GETPOST('socid', 'int'); if (isset($user->socid) && $user->socid > 0) { $action = ''; $socid = $user->socid; } $max = 5; $now = dol_now(); $form = new Form($db); $formfile = new FormFile($db); $toolNaplo = new ToolNaplo($db); $helper = new Helper($db); $entities = $helper->getAllEntities(); $entitiesArray = []; $selectedEntities = ''; //$entitiesArrayIsEmpty = true; # get all emtity_ variable foreach ($entities as $key => $value) { $val = GETPOST('entity_' . $key, 'int'); $entitiesArray[$key] = $val; /* if ($val != '') { $entitiesArrayIsEmpty = false; } */ } if (empty(array_filter($entitiesArray))) { $entitiesArray[1] = 1; } $selectedEntities = $helper->getEntities($entitiesArrayIsEmpty, $entities, $entitiesArray); //$groups = $helper->getGroupsFromGroupToolsClass($db, $selectedEntities); $groups = $helper->getFilteredpackageGroups($search_group_title, $selectedEntities); if (empty($id) || $id == 0) { foreach ($groups as $group) { $keys[] = $group['rowid']; } unset($_SESSION['package_array']); $id = $keys[0]; } if ($delete == 1) { unset($_SESSION['package_array']); } # # Confirm # # # Massactions # if ($confirm == 'delete') { $grouptoolsPackages = new GroupToolsPackages($db); $PackageNaplo = new PackageNaplo($db); foreach ($toselect as $packageid) { $moredata = explode('_', $packageid); $grouptoolsPackages->deleteLine($user, $moredata[0]); $data = $helper->createDataToolArray($id, 0, $moredata[1]); $PackageNaplo->createNaplo($user, $data); dol_syslog("A {$moredata[1]} szamu csomag torlesre kerult.", LOG_DEBUG | LOG_INFO | LOG_WARNING | LOG_ERR); } $url = $_SERVER["PHP_SELF"] . '?id=' . $id; header("Location: " . $url); $confirm = ''; } if ($massactionadd == 'add') { if ($helper->checkEquality($id)) { setEventMessage($langs->trans("equalNumbers"), 'warnings'); unset($_SESSION['package_array']); $hideConfirmBoolean = true; } else { if ((!isset($toselectnewpackage) || empty($toselectnewpackage)) && isset($_SESSION['package_array'])) { $toselectnewpackage = array_filter($_SESSION['package_array'], function ($elem) { return !empty($elem); }); } if (!empty($toselectnewpackage)) { $userCounter = $helper->getNumberOfUsers(); if ((count($toselectnewpackage) > $userCounter[$id][0]) || $helper->checkSumAndUsers($toselectnewpackage, $id)) { setEventMessage($langs->trans("TooManyPackages"), 'warnings'); unset($_SESSION['package_array']); } else { $assignedPackageObj = new Package($db); $grouptoolsPackages = new GroupToolsPackages($db); foreach ($_SESSION['package_array'] as $newtool) { $assignedPackageObj->fetch($newtool); $helper->savePackageData($grouptoolsPackages, $id, $newtool, $langs); } setEventMessage($langs->trans("tooladded")); unset($_SESSION['package_array']); } } } } if ($confirmtools == 'confirm') { foreach ($toselect as $selected) { $moredata = explode('_', $selected); $data = $helper->createDataToolArray($id, 'add', $moredata[1]); $toolNaplo->createToolsNaplo($user, $data); } $url = $_SERVER["PHP_SELF"] . '?id=' . $id; header("Location: " . $url); } if ($confirmUsersButton) { //print $confirmUsersButton;exit; $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?groupuser_id=' . $confirmUsersButton . '&id=' . $id, $langs->trans('UserConfirm'), $langs->trans('UserConfirmObject', $userString), 'confirm_users_settlement', '', 0, 1); } $assignementIsReady = $helper->checkPackageUserAssignement($id); $eztHasznalomAzosszerendelesekre = empty($assignementIsReady) ? $packageuser : $assignementIsReady; $newUserDetected = array_diff_assoc($eztHasznalomAzosszerendelesekre, $assignementIsReady); if (!empty($id)) { $PackagesOfGroups = $helper->getPackagesById($id); // The devices have to change packages $allPackages = $helper->getAllPackagesFromSelectedEntity($id, $selectedEntities); $confirmButtonDisplay = empty($helper->getToolsFromNaploToday($db, $id)) && !empty($PackagesOfGroups) ? "display:block;" : "display:none;"; $PrintButtonDisplay = !empty($helper->getToolsFromNaploToday($db, $id)) && !empty($PackagesOfGroups) ? "display:block;" : "display:none;"; $buttonContent = $helper->createButtonContent($db, $id, $PackagesOfGroups, $confirmButtonDisplay, $PrintButtonDisplay); } $permissiontoclearall = $user->hasRight('settlements', 'settlementsgroup', 'clearall'); $title = ''; $help_url = ''; $morejs = ''; $morecss = ''; llxHeader('', $title, $help_url, '', 0, 0, $morejs, $morecss, '', 'classforhorizontalscrolloftabs'); include DOL_DOCUMENT_ROOT . '/custom/settlements/core/actions_addupdatedelete.inc.php'; //print_r($_REQUEST); $url = $_SERVER["PHP_SELF"] . '?idmenu=' . $idmenu . '&mainmenu=settlements&leftmenu=&id=' . $id; print '
' . "\n"; print ''; print ''; print ''; /*print ''; print ''; print ''; print '';*/ print ''; print ''; print ''; if ($permissiontoclearall) { if ($helper->packageGroupsAreEmpty()) { $clearAllButton = '
' . $langs->trans('EmptyToolsGroup') . '
'; } else { $clearAllButton = include DOL_DOCUMENT_ROOT . '/custom/settlements/core/tpl/packageclearall.tpl.php'; } } print load_fiche_titre($langs->trans("AssociationGroupAndTools"), '', 'settlements.png@settlements'); if ($confirmUsersButton) { print $formconfirm; } if ($massaction == 'delete') { $hideConfirmBoolean = true; print $helper->massactionDelete(); } if ($confirmbutton) { print $helper->confirmButtonConfirmeText(); } include DOL_DOCUMENT_ROOT . '/custom/settlements/core/tpl/packagecheckboxes.tpl.php'; print '
'; $columnWidth = 100 / count($entities); foreach ($entities as $key => $value) { if (!$entitiesArrayIsEmpty) { $checked = $entitiesArray[$key] == $key ? 'checked' : ''; } else { $checked = 'checked'; } print '
'; } print '
'; print '
'; print ''; print ''; print ''; if (!empty($groups)) { $stringLine .= '
' . $langs->trans("groupname") . '

Empty groups
'; $groupsString = ''; $groupsStringEmpty = ''; print '
'; $userCounter = $helper->getNumberOfUsers(); foreach ($groups as $group) { $confirmedGroup = $helper->checkConfirmation($group['rowid']); $coloredLine = $id == $group['rowid'] ? ' background-color: #b0c4de' : ''; $checker = $confirmedGroup ? '' : ''; $numberOfUsers = ''; $usersArray = []; if (isset($userCounter[$group['rowid']][0])) { $peopleOrPerson = intval($userCounter[$group['rowid']][0]) > 1 ? $langs->trans('people') : $langs->trans('person'); $numberOfUsers = '(' . $userCounter[$group['rowid']][0] . ' ' . $peopleOrPerson . ')'; $usersArray = $helper->getUsersById($db, $userCounter[$group['rowid']][1]); } $popupBox = $helper->createPopoupBox($numberOfUsers, $usersArray, $group['rowid']); if (!empty($usersArray)) { $groupsString .= ''; //print ''; //print ''; $groupsString .= ''; //print ''; $groupsString .= ''; }else{ $groupsStringEmpty .= ''; $groupsStringEmpty .= ''; } } print $groupsString; print $stringLine; print $groupsStringEmpty; print '
' . $popupBox . '
' . $popupBox . '' . $checker . '
' . $popupBox . '
'; print '
'; } else { print '' . $langs->trans('nogroup') . ''; } print ''; //--------------------------------------------- #2 //--------------------------------------------- $groupName = $helper->getGroupLabelById($id); $DeviceCounter = $helper->getNumberOfDevices(); $group_id = $helper->getGroupIdBygroupToolId($id); print '
'; print ''; print ''; if (!empty($PackagesOfGroups)) { print ''; $packageAssigned = false; foreach ($PackagesOfGroups as $package) { $popupBox2 = $helper->createPopupBox($package, $DeviceCounter); #-------------------- # Checkbox #-------------------- $selected = in_array($package['rowid'] . '_' . $package['fk_package'], $toselect) ? 'checked' : ''; $chkCol2Disabled = ""; $recordClosed = ""; $assignementsOfThisPackage = $helper->getAssignementsOfThisPackage($id, $package['fk_package']); if (!empty($assignementsOfThisPackage)) { foreach ($assignementsOfThisPackage as $record) { if (!$record['status']) { $chkCol2Disabled = "disabled"; } } } print ''; foreach ($assignementsOfThisPackage as $listRecord) { $packageHistoryId = $listRecord['rowid']; $sql = "SELECT * FROM " . MAIN_DB_PREFIX . "user WHERE rowid = {$listRecord['user_id']}"; $userData = $db->query($sql); while ($row = $db->fetch_object($userData)) { $userObj = $row; } //$userObj = new User($db); //$userObj->fetch($listRecord['user_id']); if ($listRecord['status']) { $recordClosed = 'Closed'; } else { $recordClosed = ''; } print ''; } print ''; } //$confirmedGroup = $helper->checkConfirmation($id); $confirmedGroup = true; if (!$confirmedGroup) { if ($userCounter[$id][0] > 0) { print ''; print ''; } } } else { print ''; } print '
' . $langs->trans('selectAll') . '
' . $package['ref'] . '' . $popupBox2 . '
' . $langs->trans('PackageHistoryRecord') . ' ' . $recordClosed . ' ' . $userObj->firstname . ' ' . $userObj->lastname . '
 
' . $langs->trans('nopackageassigned') . '
'; //--------------------------------------------- #3 //--------------------------------------------- print '
'; print ''; print ''; print ''; if (is_array($allPackages)) { print ''; } print ''; print '' . "\n"; // End of page llxFooter(); $db->close(); ?>
' . $langs->trans("freepackages") . '
'; $deviceCounter = $helper->getNumberOfDevices(); if (!empty($allPackages['freePackages'])) { foreach ($allPackages['freePackages'] as $freePackage) { $numberOfDevices3 = ''; $devicesArray3 = []; if (isset($DeviceCounter[$freePackage['rowid']])) { $numberOfDevices3 = '(' . $DeviceCounter[$freePackage['rowid']] . ' ' . $langs->trans('device') . ')'; $devicesArray3 = $helper->getDevicesById($db, $freePackage['rowid']); } $popupBox3Text = $helper->createPopoupBoxForDeviceList($numberOfDevices3, $devicesArray3); $popupBox3 = $popupBox3Text != '' ? $popupBox3Text : '' . $langs->trans('emptyPackage') . ''; print ''; } } print '
' . $freePackage['ref'] . ' ' . $popupBox3 . '
'; if (is_array($allPackages['addedPackages'])) { $helper->addedPackageDiv($allPackages, $DeviceCounter); } print '
'; print '