| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308 |
- <?php
- /* Copyright (C) 2001-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
- * Copyright (C) 2004-2015 Laurent Destailleur <eldy@users.sourceforge.net>
- * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
- * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
- *
- * 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 <https://www.gnu.org/licenses/>.
- */
- /**
- * \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/financialreport/class/helper.class.php';
- $helper = new Helper($db);
- $userInvoiceHelper = new HelperUserInvoice($db);
- // 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');
- $id = GETPOST('id', 'int');
- $idmenu = GETPOST('idmenu', 'int');
- $toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list
- $toselectnewuser = GETPOST('toselectnewuser', 'array'); // Array of ids of elements selected into a list
- $search_title = GETPOST('search_title', 'alpha');
- $confirmbutton = GETPOST('confirmbutton', 'int');
- // Security check
- // if (! $user->rights->settlements->myobject->read) {
- // accessforbidden();
- // }
- $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);
- $userNaplo = new UserNaplo($db);
- $groups = $helper->getSingleUserGroupsFromGroupClass($db);
- if (empty($id)) {
- $keys = array_keys($groups);
- $id = $keys[0];
- }
- if ($confirmbutton) {
- foreach ($toselect as $selected) {
- $moredata = explode('_', $selected);
- $data = $helper->createDataArray($id, 'add', $moredata[1]);
- $userNaplo->createUserNaplo($user, $data);
- }
- setEventMessage($langs->trans("usersconfirmed"));
- }
- $usersOfGroups = $helper->getUsersById($db, $id);
- $allUsers = $helper->getAllUsers($db);
- $confirmButtonDisplay = empty($helper->getUsersOfGroupsFromNaploToday($db, $id)) && !empty($usersOfGroups) ? "display:block;" : "display:none;";
- $entities = $helper->getAllEntities();
- llxHeader('', $title, $help_url, '', 0, 0, $morejs, $morecss, '', 'classforhorizontalscrolloftabs');
- //print_r($_REQUEST);
- $url = $_SERVER["PHP_SELF"] . '?idmenu=' . $idmenu . '&mainmenu=settlements&leftmenu=';
- if (isset($massaction) || isset($massactionadd)) {
- $url .= "&id={$id}";
- }
- print '<form method="POST" id="searchFormList" action="' . $url . '" onkeyup="submitForm()">' . "\n";
- print '<input type="hidden" name="token" value="' . newToken() . '">';
- print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
- print '<input type="hidden" name="action" value="list">';
- /*print '<input type="hidden" name="sortfield" value="' . $sortfield . '">';
- print '<input type="hidden" name="sortorder" value="' . $sortorder . '">';
- print '<input type="hidden" name="page" value="' . $page . '">';
- print '<input type="hidden" name="contextpage" value="' . $contextpage . '">';*/
- print load_fiche_titre($langs->trans("SettlementsSingleUser"), '', 'settlements.png@settlements');
- //include DOL_DOCUMENT_ROOT . '/custom/settlements/core/tpl/usercheckboxes.tpl.php';
- //---------------------------------------------
- # 1
- //---------------------------------------------
- print '<div class=""><div class="" style="width:60%;float:left;">';
- print '<table style="width:100%;">';
- print '<tr style="width: 100%; height: 40px; text-align: center; background-color: lightgrey;"><td>' . $langs->trans("groupname") . '</td></tr>';
- foreach ($groups as $key => $val) {
- $coloredLine = $id == $key ? ' background-color: #b0c4de' : '';
- print '<tr style="height:30px;' . $coloredLine . '">
- <td>
- <div>
- <a href="' . $_SERVER['PHP_SELF'] . '?id=' . $key . '"><span class="fa fa-group pictofixedwidth"></span> ' . $val . '</a>
- </div>
- <div class="groupColumn2ndLine" style="float:left;">
- ' . $entities[$userInvoiceHelper->getGroupEntityId($key)] . '
- </div>
- </td>
- </tr>';
- }
- print '</table>';
- print '</div>';
- //---------------------------------------------
- # 2
- //---------------------------------------------
- print '<div class="" style="width:40%;float:left;">';
- print '<table style="width:100%;">';
- print '<tr style="width: 100%; height: 40px; text-align: center; background-color: lightgrey;"><td colspan="2">' . $langs->trans("usersofgroup", $groups[$id]) . '</td></tr>';
- print '<tr style="width=100%; height:40px;"><td colspan="2" class="center"><button class="btn" name="confirmbutton" value="1" onclick="groupconfirm()"
- style="width:100%; height:40px; cursor:pointer; background-color: #98FB98; ' . $confirmButtonDisplay . '">' . $langs->trans("confirm") . '</button></td></tr>';
- if (!empty($usersOfGroups)) {
- foreach ($usersOfGroups as $user) {
- print '<tr style="height:30px;">
- <td><span class="fa fa-user pictofixedwidth"></span> ' . $user['lastname'] . ' ' . $user['firstname'] . ' (' . $user['login'] . ')</td>
- <td class="nowrap center" style="display: none;"><input id="cb911" class="flat checkforselect" type="checkbox" name="toselect[]" value="' . $user['rowid'] . '_' . $user['fk_user'] . '"></td>
- </tr>';
- }
- } else {
- print '<tr style="height: 60px; text-align: center; color:red;"><td>' . $langs->trans('nouser') . '</td></tr>';
- }
- print '</table>';
- print '</div>';
- print '</form>' . "\n";
- // End of page
- llxFooter();
- $db->close();
- ?>
- <style>
- .groupColumn2ndLine {
- color: grey !important;
- }
- </style>
- <script>
- function groupconfirm() {
- $('.checkforselect').prop('checked', true);
- console.log('Confirm');
- }
- $('.checkforallselect').click(function () {
- if ($(this).is(':checked')) {
- // A checkbox be van pipálva
- $('.checkforselect').prop('checked', true);
- $('#massaction').css('display', 'inline-block');
- $('.massactionselect ').css('display', '');
- $('.massactionconfirmed ').css('display', '');
- } else {
- // A checkbox nincs bepipálva
- $('.checkforselect').prop('checked', false);
- $('#massaction').css('display', 'none');
- $('.massactionselect ').css('display', 'none');
- $('.massactionconfirmed ').css('display', 'none');
- }
- })
- $('.checkforselectadd').click(function () {
- console.log('click');
- if ($(this).is(':checked')) {
- // A checkbox be van pipálva
- $('#massactionadd').css('display', 'inline-block');
- $('.massactionaddselect ').css('display', '');
- $('.massactionaddconfirmed ').css('display', '');
- } else {
- // A checkbox nincs bepipálva
- $('#massactionadd').css('display', 'none');
- $('.massactionaddselect ').css('display', 'none');
- $('.massactionaddconfirmed ').css('display', 'none');
- }
- })
- function deleteFunction() {
- $("#name_search").val('');
- document.getElementById("searchFormList").submit();
- }
- function submitForm() {
- //document.getElementById("searchFormList").submit();
- var input = document.getElementById("name_search");
- var checkboxes = document.querySelectorAll('.checkforselectadd:checked');
- var values = Array.from(checkboxes).map(function (checkbox) {
- return checkbox.value;
- });
- var xhr = new XMLHttpRequest();
- xhr.open("GET", "test.php?search_title=" + input.value + "&toselectnewuser=" + values, true);
- xhr.onreadystatechange = function () {
- if (xhr.readyState === 4 && xhr.status === 200) {
- $("#searchedUsersDiv").html(xhr.responseText);
- }
- };
- xhr.send();
- }
- function submitForm2(event) {
- var checkbox = event.target;
- if (checkbox.checked) {
- console.log('A checkbox be van jelölve.');
- var input = document.getElementById("name_search");
- var checkboxes = document.querySelectorAll('.checkforselectadd:checked');
- var values = Array.from(checkboxes).map(function (checkbox1) {
- return checkbox1.value;
- });
- var xhr = new XMLHttpRequest();
- xhr.open("GET", "test.php?search_title=" + input.value + "&toselectnewuser=" + values, true);
- xhr.onreadystatechange = function () {
- if (xhr.readyState === 4 && xhr.status === 200) {
- $("#searchedUsersDiv").html(xhr.responseText);
- }
- };
- xhr.send();
- } else {
- console.log('A checkbox nincs jelölve.');
- var input = document.getElementById("name_search");
- var checkboxes = document.querySelectorAll('.checkforselectadd:checked');
- var values = Array.from(checkboxes).map(function (checkbox1) {
- return checkbox1.value;
- });
- console.log(values);
- //if (values.length !== 0) {
- var xhr = new XMLHttpRequest();
- xhr.open("GET", "test.php?search_title=" + input.value + "&reduction=" + values, true);
- xhr.onreadystatechange = function () {
- if (xhr.readyState === 4 && xhr.status === 200) {
- $("#searchedUsersDiv").html(xhr.responseText);
- }
- };
- xhr.send();
- //}
- }
- }
- var input = document.getElementById("name_search");
- input.focus();
- input.setSelectionRange(input.value.length, input.value.length);
- </script>
|